regulatory.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. *
  8. * Permission to use, copy, modify, and/or distribute this software for any
  9. * purpose with or without fee is hereby granted, provided that the above
  10. * copyright notice and this permission notice appear in all copies.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  13. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  15. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  16. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  17. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  18. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19. */
  20. #include <linux/rcupdate.h>
  21. /**
  22. * enum environment_cap - Environment parsed from country IE
  23. * @ENVIRON_ANY: indicates country IE applies to both indoor and
  24. * outdoor operation.
  25. * @ENVIRON_INDOOR: indicates country IE applies only to indoor operation
  26. * @ENVIRON_OUTDOOR: indicates country IE applies only to outdoor operation
  27. */
  28. enum environment_cap {
  29. ENVIRON_ANY,
  30. ENVIRON_INDOOR,
  31. ENVIRON_OUTDOOR,
  32. };
  33. /**
  34. * struct regulatory_request - used to keep track of regulatory requests
  35. *
  36. * @rcu_head: RCU head struct used to free the request
  37. * @wiphy_idx: this is set if this request's initiator is
  38. * %REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
  39. * can be used by the wireless core to deal with conflicts
  40. * and potentially inform users of which devices specifically
  41. * cased the conflicts.
  42. * @initiator: indicates who sent this request, could be any of
  43. * of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*)
  44. * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
  45. * regulatory domain. We have a few special codes:
  46. * 00 - World regulatory domain
  47. * 99 - built by driver but a specific alpha2 cannot be determined
  48. * 98 - result of an intersection between two regulatory domains
  49. * 97 - regulatory domain has not yet been configured
  50. * @dfs_region: If CRDA responded with a regulatory domain that requires
  51. * DFS master operation on a known DFS region (NL80211_DFS_*),
  52. * dfs_region represents that region. Drivers can use this and the
  53. * @alpha2 to adjust their device's DFS parameters as required.
  54. * @user_reg_hint_type: if the @initiator was of type
  55. * %NL80211_REGDOM_SET_BY_USER, this classifies the type
  56. * of hint passed. This could be any of the %NL80211_USER_REG_HINT_*
  57. * types.
  58. * @intersect: indicates whether the wireless core should intersect
  59. * the requested regulatory domain with the presently set regulatory
  60. * domain.
  61. * @processed: indicates whether or not this requests has already been
  62. * processed. When the last request is processed it means that the
  63. * currently regulatory domain set on cfg80211 is updated from
  64. * CRDA and can be used by other regulatory requests. When a
  65. * the last request is not yet processed we must yield until it
  66. * is processed before processing any new requests.
  67. * @country_ie_checksum: checksum of the last processed and accepted
  68. * country IE
  69. * @country_ie_env: lets us know if the AP is telling us we are outdoor,
  70. * indoor, or if it doesn't matter
  71. * @list: used to insert into the reg_requests_list linked list
  72. */
  73. struct regulatory_request {
  74. struct rcu_head rcu_head;
  75. int wiphy_idx;
  76. enum nl80211_reg_initiator initiator;
  77. enum nl80211_user_reg_hint_type user_reg_hint_type;
  78. char alpha2[2];
  79. enum nl80211_dfs_regions dfs_region;
  80. bool intersect;
  81. bool processed;
  82. enum environment_cap country_ie_env;
  83. struct list_head list;
  84. };
  85. /**
  86. * enum ieee80211_regulatory_flags - device regulatory flags
  87. *
  88. * @REGULATORY_CUSTOM_REG: tells us the driver for this device
  89. * has its own custom regulatory domain and cannot identify the
  90. * ISO / IEC 3166 alpha2 it belongs to. When this is enabled
  91. * we will disregard the first regulatory hint (when the
  92. * initiator is %REGDOM_SET_BY_CORE). Drivers that use
  93. * wiphy_apply_custom_regulatory() should have this flag set
  94. * or the regulatory core will set it for the wiphy.
  95. * If you use regulatory_hint() *after* using
  96. * wiphy_apply_custom_regulatory() the wireless core will
  97. * clear the REGULATORY_CUSTOM_REG for your wiphy as it would be
  98. * implied that the device somehow gained knowledge of its region.
  99. * @REGULATORY_STRICT_REG: tells us that the wiphy for this device
  100. * has regulatory domain that it wishes to be considered as the
  101. * superset for regulatory rules. After this device gets its regulatory
  102. * domain programmed further regulatory hints shall only be considered
  103. * for this device to enhance regulatory compliance, forcing the
  104. * device to only possibly use subsets of the original regulatory
  105. * rules. For example if channel 13 and 14 are disabled by this
  106. * device's regulatory domain no user specified regulatory hint which
  107. * has these channels enabled would enable them for this wiphy,
  108. * the device's original regulatory domain will be trusted as the
  109. * base. You can program the superset of regulatory rules for this
  110. * wiphy with regulatory_hint() for cards programmed with an
  111. * ISO3166-alpha2 country code. wiphys that use regulatory_hint()
  112. * will have their wiphy->regd programmed once the regulatory
  113. * domain is set, and all other regulatory hints will be ignored
  114. * until their own regulatory domain gets programmed.
  115. * @REGULATORY_DISABLE_BEACON_HINTS: enable this if your driver needs to
  116. * ensure that passive scan flags and beaconing flags may not be lifted by
  117. * cfg80211 due to regulatory beacon hints. For more information on beacon
  118. * hints read the documenation for regulatory_hint_found_beacon()
  119. * @REGULATORY_COUNTRY_IE_FOLLOW_POWER: for devices that have a preference
  120. * that even though they may have programmed their own custom power
  121. * setting prior to wiphy registration, they want to ensure their channel
  122. * power settings are updated for this connection with the power settings
  123. * derived from the regulatory domain. The regulatory domain used will be
  124. * based on the ISO3166-alpha2 from country IE provided through
  125. * regulatory_hint_country_ie()
  126. * @REGULATORY_COUNTRY_IE_IGNORE: for devices that have a preference to ignore
  127. * all country IE information processed by the regulatory core. This will
  128. * override %REGULATORY_COUNTRY_IE_FOLLOW_POWER as all country IEs will
  129. * be ignored.
  130. * @REGULATORY_ENABLE_RELAX_NO_IR: for devices that wish to allow the
  131. * NO_IR relaxation, which enables transmissions on channels on which
  132. * otherwise initiating radiation is not allowed. This will enable the
  133. * relaxations enabled under the CFG80211_REG_RELAX_NO_IR configuration
  134. * option
  135. */
  136. enum ieee80211_regulatory_flags {
  137. REGULATORY_CUSTOM_REG = BIT(0),
  138. REGULATORY_STRICT_REG = BIT(1),
  139. REGULATORY_DISABLE_BEACON_HINTS = BIT(2),
  140. REGULATORY_COUNTRY_IE_FOLLOW_POWER = BIT(3),
  141. REGULATORY_COUNTRY_IE_IGNORE = BIT(4),
  142. REGULATORY_ENABLE_RELAX_NO_IR = BIT(5),
  143. };
  144. struct ieee80211_freq_range {
  145. u32 start_freq_khz;
  146. u32 end_freq_khz;
  147. u32 max_bandwidth_khz;
  148. };
  149. struct ieee80211_power_rule {
  150. u32 max_antenna_gain;
  151. u32 max_eirp;
  152. };
  153. struct ieee80211_reg_rule {
  154. struct ieee80211_freq_range freq_range;
  155. struct ieee80211_power_rule power_rule;
  156. u32 flags;
  157. u32 dfs_cac_ms;
  158. };
  159. struct ieee80211_regdomain {
  160. struct rcu_head rcu_head;
  161. u32 n_reg_rules;
  162. char alpha2[2];
  163. enum nl80211_dfs_regions dfs_region;
  164. struct ieee80211_reg_rule reg_rules[];
  165. };
  166. #define MHZ_TO_KHZ(freq) ((freq) * 1000)
  167. #define KHZ_TO_MHZ(freq) ((freq) / 1000)
  168. #define DBI_TO_MBI(gain) ((gain) * 100)
  169. #define MBI_TO_DBI(gain) ((gain) / 100)
  170. #define DBM_TO_MBM(gain) ((gain) * 100)
  171. #define MBM_TO_DBM(gain) ((gain) / 100)
  172. #define REG_RULE_EXT(start, end, bw, gain, eirp, dfs_cac, reg_flags) \
  173. { \
  174. .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
  175. .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
  176. .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
  177. .power_rule.max_antenna_gain = DBI_TO_MBI(gain), \
  178. .power_rule.max_eirp = DBM_TO_MBM(eirp), \
  179. .flags = reg_flags, \
  180. .dfs_cac_ms = dfs_cac, \
  181. }
  182. #define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
  183. REG_RULE_EXT(start, end, bw, gain, eirp, 0, reg_flags)
  184. #endif