Regulatory.hh
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 #ifndef HH_SENF_Ext_NetEmu_WLAN_Regulatory_
18 #define HH_SENF_Ext_NetEmu_WLAN_Regulatory_ 1
19 
20 // Custom includes
21 #include <cstdint>
22 #include <boost/operators.hpp>
24 
25 extern "C" {
26 #include "nl80211-new.h"
27 }
28 
29 //-/////////////////////////////////////////////////////////////////////////////////////////////////
30 namespace senf {
31 namespace emu {
32 
34  : public boost::equality_comparable<RegulatoryRule>,
35  public boost::less_than_comparable<RegulatoryRule>
36  {
37  public:
38  enum Flags : std::uint32_t {
39  None = 0,
48  NoIBSS = __NL80211_RRF_NO_IBSS, // still seems to be reported by some kernels
50  };
51 
53 
54  RegulatoryRule & frequencyRange(std::uint32_t lower, std::uint32_t upper);
55  RegulatoryRule & maxBandwidth(std::uint32_t bandwidth);
56  RegulatoryRule & maxAntennaGain(std::int32_t gain);
57  RegulatoryRule & maxEIRP(std::int32_t eirp);
58  RegulatoryRule & cacTime(std::uint32_t cac);
59 
60  RegulatoryRule & noOFDM(bool flag = true);
61  RegulatoryRule & noCCK(bool flag = true);
62  RegulatoryRule & noIndoor(bool flag = true);
63  RegulatoryRule & noOutdoor(bool flag = true);
64  RegulatoryRule & dfsRequired(bool flag = true);
65  RegulatoryRule & ptpOnly(bool flag = true);
66  RegulatoryRule & ptmpOnly(bool flag = true);
67  RegulatoryRule & noIR(bool flag = true);
68  RegulatoryRule & autoBw(bool flag = true);
69  RegulatoryRule & flags(std::uint32_t f);
70 
71  std::uint32_t frequencyRangeBegin() const;
72  std::uint32_t frequencyRangeEnd() const;
73  std::uint32_t maxBandwidth() const;
74  std::int32_t maxAntennaGain() const;
75  std::int32_t maxEIRP() const;
76  std::uint32_t cacTime() const;
77 
78  bool noOFDM() const;
79  bool noCCK() const;
80  bool noIndoor() const;
81  bool noOutdoor() const;
82  bool dfsRequired() const;
83  bool ptpOnly() const;
84  bool ptmpOnly() const;
85  bool noIR() const;
86  bool autoBw() const;
87  std::uint32_t flags() const;
88 
89  bool operator==(RegulatoryRule const & other) const;
90  bool operator<(RegulatoryRule const & other) const;
91  bool isEqualKernel(RegulatoryRule const & other) const;
92 
93  private:
94  // starting frequency for the regulatory rule in KHz;
95  // this is *not* a center of frequency but an actual regulatory band edge:
96  std::uint32_t frequencyRangeBegin_;
97  // ending frequency for the regulatory rule in KHz;
98  // this is *not* a center a frequency but an actual regulatory band edge:
99  std::uint32_t frequencyRangeEnd_;
100  // maximum allowed bandwidth for this frequency range, in KHz.
101  std::uint32_t maxBandwidth_;
102  // maximum allowed antenna gain in mBi (100 * dBi).
103  std::int32_t maxAntennaGain_;
104  // maximum allowed EIRP in mBm (100 * dBm).
105  std::int32_t maxEIRP_;
106  std::uint32_t flags_;
107  // the required CAC time
108  std::uint32_t cacTime_;
109 
110  SENF_CONSOLE_PARSE_FRIEND( RegulatoryRule );
111  };
112 
113  std::ostream & operator<<(std::ostream & os, RegulatoryRule const & rule);
114 
117 
118 
120  : public boost::equality_comparable<RegulatoryDomain>,
121  public boost::less_than_comparable<RegulatoryDomain>
122  {
123  enum struct DFSRegion : std::uint8_t {
124  Unset = NL80211_DFS_UNSET,
125  FCC = NL80211_DFS_FCC,
126  ETSI = NL80211_DFS_ETSI,
127  JP = NL80211_DFS_JP
128  };
129 
130  std::string alpha2Country;
132  std::set<RegulatoryRule> rules;
133 
135  : dfsRegion(DFSRegion::Unset)
136  {};
137 
138  explicit operator bool() const;
139 
140  bool operator<(RegulatoryDomain const & other) const;
141  bool operator==(RegulatoryDomain const & other) const;
142  bool isEqualKernel(RegulatoryDomain const & other) const;
143  };
144 
145  std::ostream & operator<<(std::ostream & os, RegulatoryDomain const & regDomain);
146 
148  (key("DFS_Unset", Unset))(key("DFS_FCC", FCC))(key("DFS_ETSI", ETSI))(key("DFS_JP", JP)) );
149 }
150 
151 namespace console {
152 
153  template <>
155  {
157  static bool const singleToken = false;
158 
159  static void parse(ParseCommandInfo::TokensRange const & tokens, type & out);
160  static std::string description();
161  static std::string str(type const & value);
162  };
163 
164  template <>
166  {
168 
169  static void format(type const & info, std::ostream & os);
170  };
171 
172 }}
173 
174 SENF_CONSOLE_PARSE_AND_FORMAT_AS_TUPLE( senf::emu::RegulatoryDomain, (alpha2Country)(dfsRegion)(rules) );
175 
176 //-/////////////////////////////////////////////////////////////////////////////////////////////////
177 //#include "Regulatory.cci"
178 //#include "Regulatory.ct"
179 //#include "Regulatory.cti"
180 #endif
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
std::string str(T const &t)
SENF_CONSOLE_REGISTER_STRONG_ENUM_MEMBER(RegulatoryDomain, DFSRegion,(key("DFS_Unset", Unset))(key("DFS_FCC", FCC))(key("DFS_ETSI", ETSI))(key("DFS_JP", JP)))
bool operator<(RegulatoryRule const &other) const
Definition: Regulatory.cc:157
std::int32_t maxEIRP() const
Definition: Regulatory.cc:50
SENF_CONSOLE_REGISTER_ENUM_MEMBER(DVBModulationParameter, fec_rate_t,(FEC_NONE)(FEC_1_2)(FEC_2_3)(FEC_3_4)(FEC_4_5)(FEC_5_6)(FEC_6_7)(FEC_7_8)(FEC_8_9)(FEC_AUTO)(FEC_3_5)(FEC_9_10))
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
void parse(ParseCommandInfo::TokensRange const &tokens, Type &out)
SENF_CONSOLE_PARSE_AND_FORMAT_AS_TUPLE(senf::emu::RegulatoryDomain,(alpha2Country)(dfsRegion)(rules))
std::uint32_t frequencyRangeBegin() const
Definition: Regulatory.cc:32
std::uint32_t maxBandwidth() const
Definition: Regulatory.cc:44
std::uint32_t flags() const
Definition: Regulatory.cc:93
unspecified_keyword_type description
std::ostream & operator<<(std::ostream &os, InterfaceDeviceId const &id)
Definition: InterfaceId.cc:105
boost::iterator_range< token_iterator > TokensRange
void format(Type const &value, std::ostream &os)
bool isEqualKernel(RegulatoryRule const &other) const
Definition: Regulatory.cc:173