Regulatory.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #include "Regulatory.hh"
18 
19 // Custom includes
21 
22 #define prefix_
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 // senf::emu::RegulatoryRule
27 
29  : frequencyRangeBegin_(0), frequencyRangeEnd_(0), maxBandwidth_(0), maxAntennaGain_(0), maxEIRP_(0), flags_(0), cacTime_(0)
30 {}
31 
33  const
34 {
35  return frequencyRangeBegin_;
36 }
37 
39  const
40 {
41  return frequencyRangeEnd_;
42 }
43 
45  const
46 {
47  return maxBandwidth_;
48 }
49 
51  const
52 {
53  return maxEIRP_;
54 }
55 
57  const
58 {
59  return cacTime_;
60 }
61 
63  const
64 {
65  return maxAntennaGain_;
66 }
67 
68 #define FLAG_GETSET_IMPL( member, flag) \
69  prefix_ bool senf::emu::RegulatoryRule::member() \
70  const \
71  { \
72  return flags_ & Flags::flag; \
73  } \
74  prefix_ senf::emu::RegulatoryRule & senf::emu::RegulatoryRule::member(bool f) \
75  { \
76  if (f) flags_ |= Flags::flag; \
77  else flags_ &= ~Flags::flag; \
78  return *this; \
79  }
80 
90 
91 #undef FLAG_GETSET_IMPL
92 
94  const
95 {
96  return flags_;
97 }
98 
100 {
101  frequencyRangeBegin_ = begin;
102  frequencyRangeEnd_ = end;
103  return *this;
104 }
105 
107 {
108  maxBandwidth_ = bandwidth;
109  return *this;
110 }
111 
113 {
114  maxEIRP_ = eirp;
115  return *this;
116 }
117 
119 {
120  cacTime_ = cac;
121  return *this;
122 }
123 
125 {
126  maxAntennaGain_ = gain;
127  return *this;
128 }
129 
131 {
132  flags_ = f;
133  return *this;
134 }
135 
137  const
138 {
139  return frequencyRangeBegin_ == other.frequencyRangeBegin_ &&
140  frequencyRangeEnd_ == other.frequencyRangeEnd_ &&
141  maxBandwidth_ == other.maxBandwidth_ &&
142  maxAntennaGain_ == other.maxAntennaGain_ &&
143  maxEIRP_ == other.maxEIRP_ &&
144  cacTime_ == other.cacTime_ &&
145  flags_ == other.flags_;
146 }
147 
148 //prefix_ bool senf::emu::RegulatoryRule::operator<(RegulatoryRule const & other)
149 // const
150 //{
151 // if (frequencyRangeBegin_ < other.frequencyRangeBegin_)
152 // return true;
153 //
154 // return false;
155 //}
156 
158  const
159 {
160 #define GTLT( a) if (a < other.a) return true; if (other.a < a) return false;
161 
162  GTLT( frequencyRangeBegin_);
163  GTLT( frequencyRangeEnd_);
164  GTLT( maxBandwidth_);
165  GTLT( maxAntennaGain_);
166  GTLT( maxEIRP_);
167  GTLT( cacTime_);
168  GTLT( flags_);
169  // its equal
170  return false;
171 }
172 
174  const
175 {
176  //
177  // The kernel (at least 3.16.x) does not set/report CAC time and maxAntennaGain properly.
178  // Hence we skip those in the comparison
179  //
180  return frequencyRangeBegin_ == other.frequencyRangeBegin_ &&
181  frequencyRangeEnd_ == other.frequencyRangeEnd_ &&
182  maxBandwidth_ == other.maxBandwidth_ &&
183  maxEIRP_ == other.maxEIRP_ &&
184  flags_ == other.flags_;
185 }
186 
187 prefix_ senf::emu::RegulatoryDomain::operator bool()
188  const
189 {
190  return !rules.empty();
191 }
192 
194  const
195 {
196  if (dfsRegion != other.dfsRegion)
197  return false;
198 
199  if (rules.size() != other.rules.size())
200  return false;
201 
202  for(auto const & r: rules) {
203  if (other.rules.find(r) == other.rules.end())
204  return false;
205  }
206 
207  return true;
208 }
209 
211  const
212 {
213  //
214  // It's not quite clear what '<' means for this object, but std::set requires this operator
215  //
216 
217  if (rules.size() < other.rules.size())
218  return true;
219  if (other.rules.size() < rules.size())
220  return false;
221 
222  if (int(dfsRegion) < int(other.dfsRegion))
223  return true;
224  if (int(other.dfsRegion) < int(dfsRegion))
225  return false;
226 
227  auto left (rules.begin());
228  auto right (other.rules.begin());
229  while ((left != rules.end()) && (right != other.rules.end())) {
230  if (*left < *right)
231  return true;
232  if (*right < *left)
233  return false;
234  left++;
235  right++;
236  }
237 
238  return false;
239 }
240 
242  const
243 {
244  if (dfsRegion != other.dfsRegion)
245  return false;
246 
247  if (rules.size() != other.rules.size())
248  return false;
249 
250  for(auto const & r: rules) {
251  bool match (false);
252  for(auto const & o: other.rules) {
253  if (r.isEqualKernel(o)){
254  match = true;
255  break;
256  }
257  }
258  if (!match)
259  return false;
260  }
261 
262  return true;
263 }
264 
265 prefix_ std::ostream & senf::emu::operator<<(std::ostream & os, RegulatoryDomain const & regDomain)
266 {
267  senf::console::format(regDomain, os);
268  return os;
269 }
270 
271 prefix_ std::ostream & senf::emu::operator<<(std::ostream & os, RegulatoryRule const & rule)
272 {
273  os << '(' << rule.frequencyRangeBegin() << ' ' << rule.frequencyRangeEnd() << ' '
274  << rule.maxBandwidth() << ' ' << rule.maxEIRP() << ' ' << rule.cacTime() << ' ';
276  senf::console::format(flags, os);
277  os << ')';
278  return os;
279 }
280 
283 {
285  senf::console::parse( *(arg++), rule.frequencyRangeBegin_ );
286  senf::console::parse( *(arg++), rule.frequencyRangeEnd_ );
287  senf::console::parse( *(arg++), rule.maxBandwidth_ );
288  senf::console::parse( *(arg++), rule.maxEIRP_ );
289  senf::console::parse( *(arg++), rule.cacTime_ );
291  senf::console::parse( *(arg++), flags );
292  rule.flags_ = flags;
293 }
294 
296 {
297  return "RegulatoryRule";
298 };
299 
301 {
302  std::stringstream ss;
303  ss << info;
304  return ss.str();
305 };
306 
308  type const & info, std::ostream & os)
309 {
310  os << info;
311 };
312 
313 //-/////////////////////////////////////////////////////////////////////////////////////////////////
314 #undef prefix_
bool isEqualKernel(RegulatoryDomain const &other) const
Definition: Regulatory.cc:241
RegulatoryRule & maxEIRP(std::int32_t eirp)
Definition: Regulatory.cc:112
RegulatoryRule & frequencyRange(std::uint32_t lower, std::uint32_t upper)
Definition: Regulatory.cc:99
std::uint32_t cacTime() const
Definition: Regulatory.cc:56
std::int32_t maxAntennaGain() const
Definition: Regulatory.cc:62
bool operator==(RegulatoryDomain const &other) const
Definition: Regulatory.cc:193
u8 type
Regulatory header.
bool operator<(RegulatoryDomain const &other) const
Definition: Regulatory.cc:210
bool operator<(RegulatoryRule const &other) const
Definition: Regulatory.cc:157
std::int32_t maxEIRP() const
Definition: Regulatory.cc:50
#define GTLT(a)
std::set< RegulatoryRule > rules
Definition: Regulatory.hh:132
std::uint32_t frequencyRangeEnd() const
Definition: Regulatory.cc:38
bool operator==(RegulatoryRule const &other) const
Definition: Regulatory.cc:136
static std::string str(Type const &value)
Definition: Regulatory.cc:300
static void parse(ParseCommandInfo::TokensRange const &tokens, Type &out)
Definition: Regulatory.cc:281
static std::string description()
Definition: Regulatory.cc:295
#define FLAG_GETSET_IMPL(member, flag)
Definition: Regulatory.cc:68
RegulatoryRule & cacTime(std::uint32_t cac)
Definition: Regulatory.cc:118
std::uint32_t frequencyRangeBegin() const
Definition: Regulatory.cc:32
RegulatoryRule & flags(std::uint32_t f)
Definition: Regulatory.cc:130
std::uint32_t maxBandwidth() const
Definition: Regulatory.cc:44
RegulatoryRule & maxBandwidth(std::uint32_t bandwidth)
Definition: Regulatory.cc:106
std::uint32_t flags() const
Definition: Regulatory.cc:93
std::ostream & operator<<(std::ostream &os, InterfaceDeviceId const &id)
Definition: InterfaceId.cc:105
boost::iterator_range< token_iterator > TokensRange
static void format(Type const &value, std::ostream &os)
Definition: Regulatory.cc:307
#define prefix_
Definition: Regulatory.cc:22
bool isEqualKernel(RegulatoryRule const &other) const
Definition: Regulatory.cc:173