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