18c2ecf20Sopenharmony_ci#ifndef __NET_REGULATORY_H 28c2ecf20Sopenharmony_ci#define __NET_REGULATORY_H 38c2ecf20Sopenharmony_ci/* 48c2ecf20Sopenharmony_ci * regulatory support structures 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright 2008-2009 Luis R. Rodriguez <mcgrof@qca.qualcomm.com> 78c2ecf20Sopenharmony_ci * Copyright (C) 2018 Intel Corporation 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 108c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 118c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 148c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 158c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 168c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 178c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 188c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 198c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 208c2ecf20Sopenharmony_ci */ 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#include <linux/rcupdate.h> 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/** 258c2ecf20Sopenharmony_ci * enum environment_cap - Environment parsed from country IE 268c2ecf20Sopenharmony_ci * @ENVIRON_ANY: indicates country IE applies to both indoor and 278c2ecf20Sopenharmony_ci * outdoor operation. 288c2ecf20Sopenharmony_ci * @ENVIRON_INDOOR: indicates country IE applies only to indoor operation 298c2ecf20Sopenharmony_ci * @ENVIRON_OUTDOOR: indicates country IE applies only to outdoor operation 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_cienum environment_cap { 328c2ecf20Sopenharmony_ci ENVIRON_ANY, 338c2ecf20Sopenharmony_ci ENVIRON_INDOOR, 348c2ecf20Sopenharmony_ci ENVIRON_OUTDOOR, 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/** 388c2ecf20Sopenharmony_ci * struct regulatory_request - used to keep track of regulatory requests 398c2ecf20Sopenharmony_ci * 408c2ecf20Sopenharmony_ci * @rcu_head: RCU head struct used to free the request 418c2ecf20Sopenharmony_ci * @wiphy_idx: this is set if this request's initiator is 428c2ecf20Sopenharmony_ci * %REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This 438c2ecf20Sopenharmony_ci * can be used by the wireless core to deal with conflicts 448c2ecf20Sopenharmony_ci * and potentially inform users of which devices specifically 458c2ecf20Sopenharmony_ci * cased the conflicts. 468c2ecf20Sopenharmony_ci * @initiator: indicates who sent this request, could be any of 478c2ecf20Sopenharmony_ci * those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*) 488c2ecf20Sopenharmony_ci * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested 498c2ecf20Sopenharmony_ci * regulatory domain. We have a few special codes: 508c2ecf20Sopenharmony_ci * 00 - World regulatory domain 518c2ecf20Sopenharmony_ci * 99 - built by driver but a specific alpha2 cannot be determined 528c2ecf20Sopenharmony_ci * 98 - result of an intersection between two regulatory domains 538c2ecf20Sopenharmony_ci * 97 - regulatory domain has not yet been configured 548c2ecf20Sopenharmony_ci * @dfs_region: If CRDA responded with a regulatory domain that requires 558c2ecf20Sopenharmony_ci * DFS master operation on a known DFS region (NL80211_DFS_*), 568c2ecf20Sopenharmony_ci * dfs_region represents that region. Drivers can use this and the 578c2ecf20Sopenharmony_ci * @alpha2 to adjust their device's DFS parameters as required. 588c2ecf20Sopenharmony_ci * @user_reg_hint_type: if the @initiator was of type 598c2ecf20Sopenharmony_ci * %NL80211_REGDOM_SET_BY_USER, this classifies the type 608c2ecf20Sopenharmony_ci * of hint passed. This could be any of the %NL80211_USER_REG_HINT_* 618c2ecf20Sopenharmony_ci * types. 628c2ecf20Sopenharmony_ci * @intersect: indicates whether the wireless core should intersect 638c2ecf20Sopenharmony_ci * the requested regulatory domain with the presently set regulatory 648c2ecf20Sopenharmony_ci * domain. 658c2ecf20Sopenharmony_ci * @processed: indicates whether or not this requests has already been 668c2ecf20Sopenharmony_ci * processed. When the last request is processed it means that the 678c2ecf20Sopenharmony_ci * currently regulatory domain set on cfg80211 is updated from 688c2ecf20Sopenharmony_ci * CRDA and can be used by other regulatory requests. When a 698c2ecf20Sopenharmony_ci * the last request is not yet processed we must yield until it 708c2ecf20Sopenharmony_ci * is processed before processing any new requests. 718c2ecf20Sopenharmony_ci * @country_ie_checksum: checksum of the last processed and accepted 728c2ecf20Sopenharmony_ci * country IE 738c2ecf20Sopenharmony_ci * @country_ie_env: lets us know if the AP is telling us we are outdoor, 748c2ecf20Sopenharmony_ci * indoor, or if it doesn't matter 758c2ecf20Sopenharmony_ci * @list: used to insert into the reg_requests_list linked list 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_cistruct regulatory_request { 788c2ecf20Sopenharmony_ci struct rcu_head rcu_head; 798c2ecf20Sopenharmony_ci int wiphy_idx; 808c2ecf20Sopenharmony_ci enum nl80211_reg_initiator initiator; 818c2ecf20Sopenharmony_ci enum nl80211_user_reg_hint_type user_reg_hint_type; 828c2ecf20Sopenharmony_ci char alpha2[3]; 838c2ecf20Sopenharmony_ci enum nl80211_dfs_regions dfs_region; 848c2ecf20Sopenharmony_ci bool intersect; 858c2ecf20Sopenharmony_ci bool processed; 868c2ecf20Sopenharmony_ci enum environment_cap country_ie_env; 878c2ecf20Sopenharmony_ci struct list_head list; 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci/** 918c2ecf20Sopenharmony_ci * enum ieee80211_regulatory_flags - device regulatory flags 928c2ecf20Sopenharmony_ci * 938c2ecf20Sopenharmony_ci * @REGULATORY_CUSTOM_REG: tells us the driver for this device 948c2ecf20Sopenharmony_ci * has its own custom regulatory domain and cannot identify the 958c2ecf20Sopenharmony_ci * ISO / IEC 3166 alpha2 it belongs to. When this is enabled 968c2ecf20Sopenharmony_ci * we will disregard the first regulatory hint (when the 978c2ecf20Sopenharmony_ci * initiator is %REGDOM_SET_BY_CORE). Drivers that use 988c2ecf20Sopenharmony_ci * wiphy_apply_custom_regulatory() should have this flag set 998c2ecf20Sopenharmony_ci * or the regulatory core will set it for the wiphy. 1008c2ecf20Sopenharmony_ci * If you use regulatory_hint() *after* using 1018c2ecf20Sopenharmony_ci * wiphy_apply_custom_regulatory() the wireless core will 1028c2ecf20Sopenharmony_ci * clear the REGULATORY_CUSTOM_REG for your wiphy as it would be 1038c2ecf20Sopenharmony_ci * implied that the device somehow gained knowledge of its region. 1048c2ecf20Sopenharmony_ci * @REGULATORY_STRICT_REG: tells us that the wiphy for this device 1058c2ecf20Sopenharmony_ci * has regulatory domain that it wishes to be considered as the 1068c2ecf20Sopenharmony_ci * superset for regulatory rules. After this device gets its regulatory 1078c2ecf20Sopenharmony_ci * domain programmed further regulatory hints shall only be considered 1088c2ecf20Sopenharmony_ci * for this device to enhance regulatory compliance, forcing the 1098c2ecf20Sopenharmony_ci * device to only possibly use subsets of the original regulatory 1108c2ecf20Sopenharmony_ci * rules. For example if channel 13 and 14 are disabled by this 1118c2ecf20Sopenharmony_ci * device's regulatory domain no user specified regulatory hint which 1128c2ecf20Sopenharmony_ci * has these channels enabled would enable them for this wiphy, 1138c2ecf20Sopenharmony_ci * the device's original regulatory domain will be trusted as the 1148c2ecf20Sopenharmony_ci * base. You can program the superset of regulatory rules for this 1158c2ecf20Sopenharmony_ci * wiphy with regulatory_hint() for cards programmed with an 1168c2ecf20Sopenharmony_ci * ISO3166-alpha2 country code. wiphys that use regulatory_hint() 1178c2ecf20Sopenharmony_ci * will have their wiphy->regd programmed once the regulatory 1188c2ecf20Sopenharmony_ci * domain is set, and all other regulatory hints will be ignored 1198c2ecf20Sopenharmony_ci * until their own regulatory domain gets programmed. 1208c2ecf20Sopenharmony_ci * @REGULATORY_DISABLE_BEACON_HINTS: enable this if your driver needs to 1218c2ecf20Sopenharmony_ci * ensure that passive scan flags and beaconing flags may not be lifted by 1228c2ecf20Sopenharmony_ci * cfg80211 due to regulatory beacon hints. For more information on beacon 1238c2ecf20Sopenharmony_ci * hints read the documenation for regulatory_hint_found_beacon() 1248c2ecf20Sopenharmony_ci * @REGULATORY_COUNTRY_IE_FOLLOW_POWER: for devices that have a preference 1258c2ecf20Sopenharmony_ci * that even though they may have programmed their own custom power 1268c2ecf20Sopenharmony_ci * setting prior to wiphy registration, they want to ensure their channel 1278c2ecf20Sopenharmony_ci * power settings are updated for this connection with the power settings 1288c2ecf20Sopenharmony_ci * derived from the regulatory domain. The regulatory domain used will be 1298c2ecf20Sopenharmony_ci * based on the ISO3166-alpha2 from country IE provided through 1308c2ecf20Sopenharmony_ci * regulatory_hint_country_ie() 1318c2ecf20Sopenharmony_ci * @REGULATORY_COUNTRY_IE_IGNORE: for devices that have a preference to ignore 1328c2ecf20Sopenharmony_ci * all country IE information processed by the regulatory core. This will 1338c2ecf20Sopenharmony_ci * override %REGULATORY_COUNTRY_IE_FOLLOW_POWER as all country IEs will 1348c2ecf20Sopenharmony_ci * be ignored. 1358c2ecf20Sopenharmony_ci * @REGULATORY_ENABLE_RELAX_NO_IR: for devices that wish to allow the 1368c2ecf20Sopenharmony_ci * NO_IR relaxation, which enables transmissions on channels on which 1378c2ecf20Sopenharmony_ci * otherwise initiating radiation is not allowed. This will enable the 1388c2ecf20Sopenharmony_ci * relaxations enabled under the CFG80211_REG_RELAX_NO_IR configuration 1398c2ecf20Sopenharmony_ci * option 1408c2ecf20Sopenharmony_ci * @REGULATORY_IGNORE_STALE_KICKOFF: the regulatory core will _not_ make sure 1418c2ecf20Sopenharmony_ci * all interfaces on this wiphy reside on allowed channels. If this flag 1428c2ecf20Sopenharmony_ci * is not set, upon a regdomain change, the interfaces are given a grace 1438c2ecf20Sopenharmony_ci * period (currently 60 seconds) to disconnect or move to an allowed 1448c2ecf20Sopenharmony_ci * channel. Interfaces on forbidden channels are forcibly disconnected. 1458c2ecf20Sopenharmony_ci * Currently these types of interfaces are supported for enforcement: 1468c2ecf20Sopenharmony_ci * NL80211_IFTYPE_ADHOC, NL80211_IFTYPE_STATION, NL80211_IFTYPE_AP, 1478c2ecf20Sopenharmony_ci * NL80211_IFTYPE_AP_VLAN, NL80211_IFTYPE_MONITOR, 1488c2ecf20Sopenharmony_ci * NL80211_IFTYPE_P2P_CLIENT, NL80211_IFTYPE_P2P_GO, 1498c2ecf20Sopenharmony_ci * NL80211_IFTYPE_P2P_DEVICE. The flag will be set by default if a device 1508c2ecf20Sopenharmony_ci * includes any modes unsupported for enforcement checking. 1518c2ecf20Sopenharmony_ci * @REGULATORY_WIPHY_SELF_MANAGED: for devices that employ wiphy-specific 1528c2ecf20Sopenharmony_ci * regdom management. These devices will ignore all regdom changes not 1538c2ecf20Sopenharmony_ci * originating from their own wiphy. 1548c2ecf20Sopenharmony_ci * A self-managed wiphys only employs regulatory information obtained from 1558c2ecf20Sopenharmony_ci * the FW and driver and does not use other cfg80211 sources like 1568c2ecf20Sopenharmony_ci * beacon-hints, country-code IEs and hints from other devices on the same 1578c2ecf20Sopenharmony_ci * system. Conversely, a self-managed wiphy does not share its regulatory 1588c2ecf20Sopenharmony_ci * hints with other devices in the system. If a system contains several 1598c2ecf20Sopenharmony_ci * devices, one or more of which are self-managed, there might be 1608c2ecf20Sopenharmony_ci * contradictory regulatory settings between them. Usage of flag is 1618c2ecf20Sopenharmony_ci * generally discouraged. Only use it if the FW/driver is incompatible 1628c2ecf20Sopenharmony_ci * with non-locally originated hints. 1638c2ecf20Sopenharmony_ci * This flag is incompatible with the flags: %REGULATORY_CUSTOM_REG, 1648c2ecf20Sopenharmony_ci * %REGULATORY_STRICT_REG, %REGULATORY_COUNTRY_IE_FOLLOW_POWER, 1658c2ecf20Sopenharmony_ci * %REGULATORY_COUNTRY_IE_IGNORE and %REGULATORY_DISABLE_BEACON_HINTS. 1668c2ecf20Sopenharmony_ci * Mixing any of the above flags with this flag will result in a failure 1678c2ecf20Sopenharmony_ci * to register the wiphy. This flag implies 1688c2ecf20Sopenharmony_ci * %REGULATORY_DISABLE_BEACON_HINTS and %REGULATORY_COUNTRY_IE_IGNORE. 1698c2ecf20Sopenharmony_ci */ 1708c2ecf20Sopenharmony_cienum ieee80211_regulatory_flags { 1718c2ecf20Sopenharmony_ci REGULATORY_CUSTOM_REG = BIT(0), 1728c2ecf20Sopenharmony_ci REGULATORY_STRICT_REG = BIT(1), 1738c2ecf20Sopenharmony_ci REGULATORY_DISABLE_BEACON_HINTS = BIT(2), 1748c2ecf20Sopenharmony_ci REGULATORY_COUNTRY_IE_FOLLOW_POWER = BIT(3), 1758c2ecf20Sopenharmony_ci REGULATORY_COUNTRY_IE_IGNORE = BIT(4), 1768c2ecf20Sopenharmony_ci REGULATORY_ENABLE_RELAX_NO_IR = BIT(5), 1778c2ecf20Sopenharmony_ci REGULATORY_IGNORE_STALE_KICKOFF = BIT(6), 1788c2ecf20Sopenharmony_ci REGULATORY_WIPHY_SELF_MANAGED = BIT(7), 1798c2ecf20Sopenharmony_ci}; 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_cistruct ieee80211_freq_range { 1828c2ecf20Sopenharmony_ci u32 start_freq_khz; 1838c2ecf20Sopenharmony_ci u32 end_freq_khz; 1848c2ecf20Sopenharmony_ci u32 max_bandwidth_khz; 1858c2ecf20Sopenharmony_ci}; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cistruct ieee80211_power_rule { 1888c2ecf20Sopenharmony_ci u32 max_antenna_gain; 1898c2ecf20Sopenharmony_ci u32 max_eirp; 1908c2ecf20Sopenharmony_ci}; 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci/** 1938c2ecf20Sopenharmony_ci * struct ieee80211_wmm_ac - used to store per ac wmm regulatory limitation 1948c2ecf20Sopenharmony_ci * 1958c2ecf20Sopenharmony_ci * The information provided in this structure is required for QoS 1968c2ecf20Sopenharmony_ci * transmit queue configuration. Cf. IEEE 802.11 7.3.2.29. 1978c2ecf20Sopenharmony_ci * 1988c2ecf20Sopenharmony_ci * @cw_min: minimum contention window [a value of the form 1998c2ecf20Sopenharmony_ci * 2^n-1 in the range 1..32767] 2008c2ecf20Sopenharmony_ci * @cw_max: maximum contention window [like @cw_min] 2018c2ecf20Sopenharmony_ci * @cot: maximum burst time in units of 32 usecs, 0 meaning disabled 2028c2ecf20Sopenharmony_ci * @aifsn: arbitration interframe space [0..255] 2038c2ecf20Sopenharmony_ci * 2048c2ecf20Sopenharmony_ci */ 2058c2ecf20Sopenharmony_cistruct ieee80211_wmm_ac { 2068c2ecf20Sopenharmony_ci u16 cw_min; 2078c2ecf20Sopenharmony_ci u16 cw_max; 2088c2ecf20Sopenharmony_ci u16 cot; 2098c2ecf20Sopenharmony_ci u8 aifsn; 2108c2ecf20Sopenharmony_ci}; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_cistruct ieee80211_wmm_rule { 2138c2ecf20Sopenharmony_ci struct ieee80211_wmm_ac client[IEEE80211_NUM_ACS]; 2148c2ecf20Sopenharmony_ci struct ieee80211_wmm_ac ap[IEEE80211_NUM_ACS]; 2158c2ecf20Sopenharmony_ci}; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_cistruct ieee80211_reg_rule { 2188c2ecf20Sopenharmony_ci struct ieee80211_freq_range freq_range; 2198c2ecf20Sopenharmony_ci struct ieee80211_power_rule power_rule; 2208c2ecf20Sopenharmony_ci struct ieee80211_wmm_rule wmm_rule; 2218c2ecf20Sopenharmony_ci u32 flags; 2228c2ecf20Sopenharmony_ci u32 dfs_cac_ms; 2238c2ecf20Sopenharmony_ci bool has_wmm; 2248c2ecf20Sopenharmony_ci}; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_cistruct ieee80211_regdomain { 2278c2ecf20Sopenharmony_ci struct rcu_head rcu_head; 2288c2ecf20Sopenharmony_ci u32 n_reg_rules; 2298c2ecf20Sopenharmony_ci char alpha2[3]; 2308c2ecf20Sopenharmony_ci enum nl80211_dfs_regions dfs_region; 2318c2ecf20Sopenharmony_ci struct ieee80211_reg_rule reg_rules[]; 2328c2ecf20Sopenharmony_ci}; 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci#define REG_RULE_EXT(start, end, bw, gain, eirp, dfs_cac, reg_flags) \ 2358c2ecf20Sopenharmony_ci{ \ 2368c2ecf20Sopenharmony_ci .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \ 2378c2ecf20Sopenharmony_ci .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \ 2388c2ecf20Sopenharmony_ci .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \ 2398c2ecf20Sopenharmony_ci .power_rule.max_antenna_gain = DBI_TO_MBI(gain), \ 2408c2ecf20Sopenharmony_ci .power_rule.max_eirp = DBM_TO_MBM(eirp), \ 2418c2ecf20Sopenharmony_ci .flags = reg_flags, \ 2428c2ecf20Sopenharmony_ci .dfs_cac_ms = dfs_cac, \ 2438c2ecf20Sopenharmony_ci} 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci#define REG_RULE(start, end, bw, gain, eirp, reg_flags) \ 2468c2ecf20Sopenharmony_ci REG_RULE_EXT(start, end, bw, gain, eirp, 0, reg_flags) 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci#endif 249