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