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