regulatory.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #ifndef __NET_REGULATORY_H
  2. #define __NET_REGULATORY_H
  3. /*
  4. * regulatory support structures
  5. *
  6. * Copyright 2008-2009 Luis R. Rodriguez <mcgrof@qca.qualcomm.com>
  7. * Copyright (C) 2018 Intel Corporation
  8. *
  9. * Permission to use, copy, modify, and/or distribute this software for any
  10. * purpose with or without fee is hereby granted, provided that the above
  11. * copyright notice and this permission notice appear in all copies.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  14. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  16. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  18. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  19. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20. */
  21. #include <linux/rcupdate.h>
  22. /**
  23. * enum environment_cap - Environment parsed from country IE
  24. * @ENVIRON_ANY: indicates country IE applies to both indoor and
  25. * outdoor operation.
  26. * @ENVIRON_INDOOR: indicates country IE applies only to indoor operation
  27. * @ENVIRON_OUTDOOR: indicates country IE applies only to outdoor operation
  28. */
  29. enum environment_cap {
  30. ENVIRON_ANY,
  31. ENVIRON_INDOOR,
  32. ENVIRON_OUTDOOR,
  33. };
  34. /**
  35. * struct regulatory_request - used to keep track of regulatory requests
  36. *
  37. * @rcu_head: RCU head struct used to free the request
  38. * @wiphy_idx: this is set if this request's initiator is
  39. * %REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
  40. * can be used by the wireless core to deal with conflicts
  41. * and potentially inform users of which devices specifically
  42. * cased the conflicts.
  43. * @initiator: indicates who sent this request, could be any of
  44. * of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*)
  45. * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
  46. * regulatory domain. We have a few special codes:
  47. * 00 - World regulatory domain
  48. * 99 - built by driver but a specific alpha2 cannot be determined
  49. * 98 - result of an intersection between two regulatory domains
  50. * 97 - regulatory domain has not yet been configured
  51. * @dfs_region: If CRDA responded with a regulatory domain that requires
  52. * DFS master operation on a known DFS region (NL80211_DFS_*),
  53. * dfs_region represents that region. Drivers can use this and the
  54. * @alpha2 to adjust their device's DFS parameters as required.
  55. * @user_reg_hint_type: if the @initiator was of type
  56. * %NL80211_REGDOM_SET_BY_USER, this classifies the type
  57. * of hint passed. This could be any of the %NL80211_USER_REG_HINT_*
  58. * types.
  59. * @intersect: indicates whether the wireless core should intersect
  60. * the requested regulatory domain with the presently set regulatory
  61. * domain.
  62. * @processed: indicates whether or not this requests has already been
  63. * processed. When the last request is processed it means that the
  64. * currently regulatory domain set on cfg80211 is updated from
  65. * CRDA and can be used by other regulatory requests. When a
  66. * the last request is not yet processed we must yield until it
  67. * is processed before processing any new requests.
  68. * @country_ie_checksum: checksum of the last processed and accepted
  69. * country IE
  70. * @country_ie_env: lets us know if the AP is telling us we are outdoor,
  71. * indoor, or if it doesn't matter
  72. * @list: used to insert into the reg_requests_list linked list
  73. */
  74. struct regulatory_request {
  75. struct rcu_head rcu_head;
  76. int wiphy_idx;
  77. enum nl80211_reg_initiator initiator;
  78. enum nl80211_user_reg_hint_type user_reg_hint_type;
  79. char alpha2[3];
  80. enum nl80211_dfs_regions dfs_region;
  81. bool intersect;
  82. bool processed;
  83. enum environment_cap country_ie_env;
  84. struct list_head list;
  85. };
  86. /**
  87. * enum ieee80211_regulatory_flags - device regulatory flags
  88. *
  89. * @REGULATORY_CUSTOM_REG: tells us the driver for this device
  90. * has its own custom regulatory domain and cannot identify the
  91. * ISO / IEC 3166 alpha2 it belongs to. When this is enabled
  92. * we will disregard the first regulatory hint (when the
  93. * initiator is %REGDOM_SET_BY_CORE). Drivers that use
  94. * wiphy_apply_custom_regulatory() should have this flag set
  95. * or the regulatory core will set it for the wiphy.
  96. * If you use regulatory_hint() *after* using
  97. * wiphy_apply_custom_regulatory() the wireless core will
  98. * clear the REGULATORY_CUSTOM_REG for your wiphy as it would be
  99. * implied that the device somehow gained knowledge of its region.
  100. * @REGULATORY_STRICT_REG: tells us that the wiphy for this device
  101. * has regulatory domain that it wishes to be considered as the
  102. * superset for regulatory rules. After this device gets its regulatory
  103. * domain programmed further regulatory hints shall only be considered
  104. * for this device to enhance regulatory compliance, forcing the
  105. * device to only possibly use subsets of the original regulatory
  106. * rules. For example if channel 13 and 14 are disabled by this
  107. * device's regulatory domain no user specified regulatory hint which
  108. * has these channels enabled would enable them for this wiphy,
  109. * the device's original regulatory domain will be trusted as the
  110. * base. You can program the superset of regulatory rules for this
  111. * wiphy with regulatory_hint() for cards programmed with an
  112. * ISO3166-alpha2 country code. wiphys that use regulatory_hint()
  113. * will have their wiphy->regd programmed once the regulatory
  114. * domain is set, and all other regulatory hints will be ignored
  115. * until their own regulatory domain gets programmed.
  116. * @REGULATORY_DISABLE_BEACON_HINTS: enable this if your driver needs to
  117. * ensure that passive scan flags and beaconing flags may not be lifted by
  118. * cfg80211 due to regulatory beacon hints. For more information on beacon
  119. * hints read the documenation for regulatory_hint_found_beacon()
  120. * @REGULATORY_COUNTRY_IE_FOLLOW_POWER: for devices that have a preference
  121. * that even though they may have programmed their own custom power
  122. * setting prior to wiphy registration, they want to ensure their channel
  123. * power settings are updated for this connection with the power settings
  124. * derived from the regulatory domain. The regulatory domain used will be
  125. * based on the ISO3166-alpha2 from country IE provided through
  126. * regulatory_hint_country_ie()
  127. * @REGULATORY_COUNTRY_IE_IGNORE: for devices that have a preference to ignore
  128. * all country IE information processed by the regulatory core. This will
  129. * override %REGULATORY_COUNTRY_IE_FOLLOW_POWER as all country IEs will
  130. * be ignored.
  131. * @REGULATORY_ENABLE_RELAX_NO_IR: for devices that wish to allow the
  132. * NO_IR relaxation, which enables transmissions on channels on which
  133. * otherwise initiating radiation is not allowed. This will enable the
  134. * relaxations enabled under the CFG80211_REG_RELAX_NO_IR configuration
  135. * option
  136. * @REGULATORY_IGNORE_STALE_KICKOFF: the regulatory core will _not_ make sure
  137. * all interfaces on this wiphy reside on allowed channels. If this flag
  138. * is not set, upon a regdomain change, the interfaces are given a grace
  139. * period (currently 60 seconds) to disconnect or move to an allowed
  140. * channel. Interfaces on forbidden channels are forcibly disconnected.
  141. * Currently these types of interfaces are supported for enforcement:
  142. * NL80211_IFTYPE_ADHOC, NL80211_IFTYPE_STATION, NL80211_IFTYPE_AP,
  143. * NL80211_IFTYPE_AP_VLAN, NL80211_IFTYPE_MONITOR,
  144. * NL80211_IFTYPE_P2P_CLIENT, NL80211_IFTYPE_P2P_GO,
  145. * NL80211_IFTYPE_P2P_DEVICE. The flag will be set by default if a device
  146. * includes any modes unsupported for enforcement checking.
  147. * @REGULATORY_WIPHY_SELF_MANAGED: for devices that employ wiphy-specific
  148. * regdom management. These devices will ignore all regdom changes not
  149. * originating from their own wiphy.
  150. * A self-managed wiphys only employs regulatory information obtained from
  151. * the FW and driver and does not use other cfg80211 sources like
  152. * beacon-hints, country-code IEs and hints from other devices on the same
  153. * system. Conversely, a self-managed wiphy does not share its regulatory
  154. * hints with other devices in the system. If a system contains several
  155. * devices, one or more of which are self-managed, there might be
  156. * contradictory regulatory settings between them. Usage of flag is
  157. * generally discouraged. Only use it if the FW/driver is incompatible
  158. * with non-locally originated hints.
  159. * This flag is incompatible with the flags: %REGULATORY_CUSTOM_REG,
  160. * %REGULATORY_STRICT_REG, %REGULATORY_COUNTRY_IE_FOLLOW_POWER,
  161. * %REGULATORY_COUNTRY_IE_IGNORE and %REGULATORY_DISABLE_BEACON_HINTS.
  162. * Mixing any of the above flags with this flag will result in a failure
  163. * to register the wiphy. This flag implies
  164. * %REGULATORY_DISABLE_BEACON_HINTS and %REGULATORY_COUNTRY_IE_IGNORE.
  165. */
  166. enum ieee80211_regulatory_flags {
  167. REGULATORY_CUSTOM_REG = BIT(0),
  168. REGULATORY_STRICT_REG = BIT(1),
  169. REGULATORY_DISABLE_BEACON_HINTS = BIT(2),
  170. REGULATORY_COUNTRY_IE_FOLLOW_POWER = BIT(3),
  171. REGULATORY_COUNTRY_IE_IGNORE = BIT(4),
  172. REGULATORY_ENABLE_RELAX_NO_IR = BIT(5),
  173. REGULATORY_IGNORE_STALE_KICKOFF = BIT(6),
  174. REGULATORY_WIPHY_SELF_MANAGED = BIT(7),
  175. };
  176. struct ieee80211_freq_range {
  177. u32 start_freq_khz;
  178. u32 end_freq_khz;
  179. u32 max_bandwidth_khz;
  180. };
  181. struct ieee80211_power_rule {
  182. u32 max_antenna_gain;
  183. u32 max_eirp;
  184. };
  185. /**
  186. * struct ieee80211_wmm_ac - used to store per ac wmm regulatory limitation
  187. *
  188. * The information provided in this structure is required for QoS
  189. * transmit queue configuration. Cf. IEEE 802.11 7.3.2.29.
  190. *
  191. * @cw_min: minimum contention window [a value of the form
  192. * 2^n-1 in the range 1..32767]
  193. * @cw_max: maximum contention window [like @cw_min]
  194. * @cot: maximum burst time in units of 32 usecs, 0 meaning disabled
  195. * @aifsn: arbitration interframe space [0..255]
  196. *
  197. */
  198. struct ieee80211_wmm_ac {
  199. u16 cw_min;
  200. u16 cw_max;
  201. u16 cot;
  202. u8 aifsn;
  203. };
  204. struct ieee80211_wmm_rule {
  205. struct ieee80211_wmm_ac client[IEEE80211_NUM_ACS];
  206. struct ieee80211_wmm_ac ap[IEEE80211_NUM_ACS];
  207. };
  208. struct ieee80211_reg_rule {
  209. struct ieee80211_freq_range freq_range;
  210. struct ieee80211_power_rule power_rule;
  211. struct ieee80211_wmm_rule wmm_rule;
  212. u32 flags;
  213. u32 dfs_cac_ms;
  214. bool has_wmm;
  215. };
  216. struct ieee80211_regdomain {
  217. struct rcu_head rcu_head;
  218. u32 n_reg_rules;
  219. char alpha2[3];
  220. enum nl80211_dfs_regions dfs_region;
  221. struct ieee80211_reg_rule reg_rules[];
  222. };
  223. #define MHZ_TO_KHZ(freq) ((freq) * 1000)
  224. #define KHZ_TO_MHZ(freq) ((freq) / 1000)
  225. #define DBI_TO_MBI(gain) ((gain) * 100)
  226. #define MBI_TO_DBI(gain) ((gain) / 100)
  227. #define DBM_TO_MBM(gain) ((gain) * 100)
  228. #define MBM_TO_DBM(gain) ((gain) / 100)
  229. #define REG_RULE_EXT(start, end, bw, gain, eirp, dfs_cac, reg_flags) \
  230. { \
  231. .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
  232. .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
  233. .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
  234. .power_rule.max_antenna_gain = DBI_TO_MBI(gain), \
  235. .power_rule.max_eirp = DBM_TO_MBM(eirp), \
  236. .flags = reg_flags, \
  237. .dfs_cac_ms = dfs_cac, \
  238. }
  239. #define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
  240. REG_RULE_EXT(start, end, bw, gain, eirp, 0, reg_flags)
  241. #endif