Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 1 | #ifndef __NET_REGULATORY_H |
| 2 | #define __NET_REGULATORY_H |
| 3 | /* |
| 4 | * regulatory support structures |
| 5 | * |
Luis R. Rodriguez | dde88b7 | 2011-08-23 15:03:34 -0700 | [diff] [blame] | 6 | * Copyright 2008-2009 Luis R. Rodriguez <mcgrof@qca.qualcomm.com> |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 7 | * |
Luis R. Rodriguez | dde88b7 | 2011-08-23 15:03:34 -0700 | [diff] [blame] | 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. |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 19 | */ |
| 20 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 21 | #include <linux/rcupdate.h> |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * enum environment_cap - Environment parsed from country IE |
| 25 | * @ENVIRON_ANY: indicates country IE applies to both indoor and |
| 26 | * outdoor operation. |
| 27 | * @ENVIRON_INDOOR: indicates country IE applies only to indoor operation |
| 28 | * @ENVIRON_OUTDOOR: indicates country IE applies only to outdoor operation |
| 29 | */ |
| 30 | enum environment_cap { |
| 31 | ENVIRON_ANY, |
| 32 | ENVIRON_INDOOR, |
| 33 | ENVIRON_OUTDOOR, |
| 34 | }; |
| 35 | |
| 36 | /** |
| 37 | * struct regulatory_request - used to keep track of regulatory requests |
| 38 | * |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 39 | * @rcu_head: RCU head struct used to free the request |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 40 | * @wiphy_idx: this is set if this request's initiator is |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 41 | * %REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This |
| 42 | * can be used by the wireless core to deal with conflicts |
| 43 | * and potentially inform users of which devices specifically |
| 44 | * cased the conflicts. |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 45 | * @initiator: indicates who sent this request, could be any of |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 46 | * of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*) |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 47 | * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 48 | * regulatory domain. We have a few special codes: |
| 49 | * 00 - World regulatory domain |
| 50 | * 99 - built by driver but a specific alpha2 cannot be determined |
| 51 | * 98 - result of an intersection between two regulatory domains |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 52 | * 97 - regulatory domain has not yet been configured |
Luis R. Rodriguez | b68e6b3 | 2011-10-11 10:59:03 -0700 | [diff] [blame] | 53 | * @dfs_region: If CRDA responded with a regulatory domain that requires |
| 54 | * DFS master operation on a known DFS region (NL80211_DFS_*), |
| 55 | * dfs_region represents that region. Drivers can use this and the |
| 56 | * @alpha2 to adjust their device's DFS parameters as required. |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 57 | * @user_reg_hint_type: if the @initiator was of type |
| 58 | * %NL80211_REGDOM_SET_BY_USER, this classifies the type |
| 59 | * of hint passed. This could be any of the %NL80211_USER_REG_HINT_* |
| 60 | * types. |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 61 | * @intersect: indicates whether the wireless core should intersect |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 62 | * the requested regulatory domain with the presently set regulatory |
| 63 | * domain. |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 64 | * @processed: indicates whether or not this requests has already been |
| 65 | * processed. When the last request is processed it means that the |
| 66 | * currently regulatory domain set on cfg80211 is updated from |
| 67 | * CRDA and can be used by other regulatory requests. When a |
| 68 | * the last request is not yet processed we must yield until it |
| 69 | * is processed before processing any new requests. |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 70 | * @country_ie_checksum: checksum of the last processed and accepted |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 71 | * country IE |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 72 | * @country_ie_env: lets us know if the AP is telling us we are outdoor, |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 73 | * indoor, or if it doesn't matter |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 74 | * @list: used to insert into the reg_requests_list linked list |
| 75 | */ |
| 76 | struct regulatory_request { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 77 | struct rcu_head rcu_head; |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 78 | int wiphy_idx; |
| 79 | enum nl80211_reg_initiator initiator; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 80 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 81 | char alpha2[2]; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 82 | enum nl80211_dfs_regions dfs_region; |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 83 | bool intersect; |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 84 | bool processed; |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 85 | enum environment_cap country_ie_env; |
| 86 | struct list_head list; |
| 87 | }; |
| 88 | |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 89 | /** |
| 90 | * enum ieee80211_regulatory_flags - device regulatory flags |
| 91 | * |
| 92 | * @REGULATORY_CUSTOM_REG: tells us the driver for this device |
| 93 | * has its own custom regulatory domain and cannot identify the |
| 94 | * ISO / IEC 3166 alpha2 it belongs to. When this is enabled |
| 95 | * we will disregard the first regulatory hint (when the |
| 96 | * initiator is %REGDOM_SET_BY_CORE). Drivers that use |
| 97 | * wiphy_apply_custom_regulatory() should have this flag set |
| 98 | * or the regulatory core will set it for the wiphy. |
Luis R. Rodriguez | 4f7b914 | 2013-12-14 20:09:06 +0100 | [diff] [blame] | 99 | * If you use regulatory_hint() *after* using |
| 100 | * wiphy_apply_custom_regulatory() the wireless core will |
| 101 | * clear the REGULATORY_CUSTOM_REG for your wiphy as it would be |
| 102 | * implied that the device somehow gained knowledge of its region. |
Luis R. Rodriguez | a09a85a | 2013-11-11 22:15:30 +0100 | [diff] [blame] | 103 | * @REGULATORY_STRICT_REG: tells us that the wiphy for this device |
| 104 | * has regulatory domain that it wishes to be considered as the |
| 105 | * superset for regulatory rules. After this device gets its regulatory |
| 106 | * domain programmed further regulatory hints shall only be considered |
| 107 | * for this device to enhance regulatory compliance, forcing the |
| 108 | * device to only possibly use subsets of the original regulatory |
| 109 | * rules. For example if channel 13 and 14 are disabled by this |
| 110 | * device's regulatory domain no user specified regulatory hint which |
| 111 | * has these channels enabled would enable them for this wiphy, |
| 112 | * the device's original regulatory domain will be trusted as the |
| 113 | * base. You can program the superset of regulatory rules for this |
| 114 | * wiphy with regulatory_hint() for cards programmed with an |
| 115 | * ISO3166-alpha2 country code. wiphys that use regulatory_hint() |
| 116 | * will have their wiphy->regd programmed once the regulatory |
| 117 | * domain is set, and all other regulatory hints will be ignored |
| 118 | * until their own regulatory domain gets programmed. |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 119 | * @REGULATORY_DISABLE_BEACON_HINTS: enable this if your driver needs to |
| 120 | * ensure that passive scan flags and beaconing flags may not be lifted by |
| 121 | * cfg80211 due to regulatory beacon hints. For more information on beacon |
| 122 | * hints read the documenation for regulatory_hint_found_beacon() |
Luis R. Rodriguez | a09a85a | 2013-11-11 22:15:30 +0100 | [diff] [blame] | 123 | * @REGULATORY_COUNTRY_IE_FOLLOW_POWER: for devices that have a preference |
| 124 | * that even though they may have programmed their own custom power |
| 125 | * setting prior to wiphy registration, they want to ensure their channel |
| 126 | * power settings are updated for this connection with the power settings |
| 127 | * derived from the regulatory domain. The regulatory domain used will be |
| 128 | * based on the ISO3166-alpha2 from country IE provided through |
| 129 | * regulatory_hint_country_ie() |
Luis R. Rodriguez | 2a90146 | 2013-11-11 22:15:31 +0100 | [diff] [blame] | 130 | * @REGULATORY_COUNTRY_IE_IGNORE: for devices that have a preference to ignore |
| 131 | * all country IE information processed by the regulatory core. This will |
| 132 | * override %REGULATORY_COUNTRY_IE_FOLLOW_POWER as all country IEs will |
| 133 | * be ignored. |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 134 | */ |
| 135 | enum ieee80211_regulatory_flags { |
| 136 | REGULATORY_CUSTOM_REG = BIT(0), |
| 137 | REGULATORY_STRICT_REG = BIT(1), |
| 138 | REGULATORY_DISABLE_BEACON_HINTS = BIT(2), |
Luis R. Rodriguez | a09a85a | 2013-11-11 22:15:30 +0100 | [diff] [blame] | 139 | REGULATORY_COUNTRY_IE_FOLLOW_POWER = BIT(3), |
Luis R. Rodriguez | 2a90146 | 2013-11-11 22:15:31 +0100 | [diff] [blame] | 140 | REGULATORY_COUNTRY_IE_IGNORE = BIT(4), |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 141 | }; |
| 142 | |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 143 | struct ieee80211_freq_range { |
| 144 | u32 start_freq_khz; |
| 145 | u32 end_freq_khz; |
| 146 | u32 max_bandwidth_khz; |
| 147 | }; |
| 148 | |
| 149 | struct ieee80211_power_rule { |
| 150 | u32 max_antenna_gain; |
| 151 | u32 max_eirp; |
| 152 | }; |
| 153 | |
| 154 | struct ieee80211_reg_rule { |
| 155 | struct ieee80211_freq_range freq_range; |
| 156 | struct ieee80211_power_rule power_rule; |
| 157 | u32 flags; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame^] | 158 | u32 dfs_cac_ms; |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | struct ieee80211_regdomain { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 162 | struct rcu_head rcu_head; |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 163 | u32 n_reg_rules; |
| 164 | char alpha2[2]; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 165 | enum nl80211_dfs_regions dfs_region; |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 166 | struct ieee80211_reg_rule reg_rules[]; |
| 167 | }; |
| 168 | |
| 169 | #define MHZ_TO_KHZ(freq) ((freq) * 1000) |
| 170 | #define KHZ_TO_MHZ(freq) ((freq) / 1000) |
| 171 | #define DBI_TO_MBI(gain) ((gain) * 100) |
| 172 | #define MBI_TO_DBI(gain) ((gain) / 100) |
| 173 | #define DBM_TO_MBM(gain) ((gain) * 100) |
| 174 | #define MBM_TO_DBM(gain) ((gain) / 100) |
| 175 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame^] | 176 | #define REG_RULE_EXT(start, end, bw, gain, eirp, dfs_cac, reg_flags) \ |
| 177 | { \ |
| 178 | .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \ |
| 179 | .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \ |
| 180 | .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \ |
| 181 | .power_rule.max_antenna_gain = DBI_TO_MBI(gain), \ |
| 182 | .power_rule.max_eirp = DBM_TO_MBM(eirp), \ |
| 183 | .flags = reg_flags, \ |
| 184 | .dfs_cac_ms = dfs_cac, \ |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 185 | } |
| 186 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame^] | 187 | #define REG_RULE(start, end, bw, gain, eirp, reg_flags) \ |
| 188 | REG_RULE_EXT(start, end, bw, gain, eirp, 0, reg_flags) |
| 189 | |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 190 | #endif |