xref: /openbmc/linux/include/net/regulatory.h (revision a2f73b6c5db3c272d87eaebb5bed355d75a0f25f)
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>
7d3236553SJohannes Berg  *
8dde88b73SLuis R. Rodriguez  * Permission to use, copy, modify, and/or distribute this software for any
9dde88b73SLuis R. Rodriguez  * purpose with or without fee is hereby granted, provided that the above
10dde88b73SLuis R. Rodriguez  * copyright notice and this permission notice appear in all copies.
11dde88b73SLuis R. Rodriguez  *
12dde88b73SLuis R. Rodriguez  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13dde88b73SLuis R. Rodriguez  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14dde88b73SLuis R. Rodriguez  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15dde88b73SLuis R. Rodriguez  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16dde88b73SLuis R. Rodriguez  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17dde88b73SLuis R. Rodriguez  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18dde88b73SLuis R. Rodriguez  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19d3236553SJohannes Berg  */
20d3236553SJohannes Berg 
21458f4f9eSJohannes Berg #include <linux/rcupdate.h>
22d3236553SJohannes Berg 
23d3236553SJohannes Berg /**
24d3236553SJohannes Berg  * enum environment_cap - Environment parsed from country IE
25d3236553SJohannes Berg  * @ENVIRON_ANY: indicates country IE applies to both indoor and
26d3236553SJohannes Berg  *	outdoor operation.
27d3236553SJohannes Berg  * @ENVIRON_INDOOR: indicates country IE applies only to indoor operation
28d3236553SJohannes Berg  * @ENVIRON_OUTDOOR: indicates country IE applies only to outdoor operation
29d3236553SJohannes Berg  */
30d3236553SJohannes Berg enum environment_cap {
31d3236553SJohannes Berg 	ENVIRON_ANY,
32d3236553SJohannes Berg 	ENVIRON_INDOOR,
33d3236553SJohannes Berg 	ENVIRON_OUTDOOR,
34d3236553SJohannes Berg };
35d3236553SJohannes Berg 
36d3236553SJohannes Berg /**
37d3236553SJohannes Berg  * struct regulatory_request - used to keep track of regulatory requests
38d3236553SJohannes Berg  *
39c492db37SJohannes Berg  * @rcu_head: RCU head struct used to free the request
40d3236553SJohannes Berg  * @wiphy_idx: this is set if this request's initiator is
41d3236553SJohannes Berg  *	%REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
42d3236553SJohannes Berg  *	can be used by the wireless core to deal with conflicts
43d3236553SJohannes Berg  *	and potentially inform users of which devices specifically
44d3236553SJohannes Berg  *	cased the conflicts.
45d3236553SJohannes Berg  * @initiator: indicates who sent this request, could be any of
46d3236553SJohannes Berg  *	of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*)
47d3236553SJohannes Berg  * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
48d3236553SJohannes Berg  *	regulatory domain. We have a few special codes:
49d3236553SJohannes Berg  *	00 - World regulatory domain
50d3236553SJohannes Berg  *	99 - built by driver but a specific alpha2 cannot be determined
51d3236553SJohannes Berg  *	98 - result of an intersection between two regulatory domains
5209d989d1SLuis R. Rodriguez  *	97 - regulatory domain has not yet been configured
53b68e6b3bSLuis R. Rodriguez  * @dfs_region: If CRDA responded with a regulatory domain that requires
54b68e6b3bSLuis R. Rodriguez  *	DFS master operation on a known DFS region (NL80211_DFS_*),
55b68e6b3bSLuis R. Rodriguez  *	dfs_region represents that region. Drivers can use this and the
56b68e6b3bSLuis R. Rodriguez  *	@alpha2 to adjust their device's DFS parameters as required.
5757b5ce07SLuis R. Rodriguez  * @user_reg_hint_type: if the @initiator was of type
5857b5ce07SLuis R. Rodriguez  *	%NL80211_REGDOM_SET_BY_USER, this classifies the type
5957b5ce07SLuis R. Rodriguez  *	of hint passed. This could be any of the %NL80211_USER_REG_HINT_*
6057b5ce07SLuis R. Rodriguez  *	types.
61d3236553SJohannes Berg  * @intersect: indicates whether the wireless core should intersect
62d3236553SJohannes Berg  *	the requested regulatory domain with the presently set regulatory
63d3236553SJohannes Berg  *	domain.
64b2e253cfSLuis R. Rodriguez  * @processed: indicates whether or not this requests has already been
65b2e253cfSLuis R. Rodriguez  *	processed. When the last request is processed it means that the
66b2e253cfSLuis R. Rodriguez  *	currently regulatory domain set on cfg80211 is updated from
67b2e253cfSLuis R. Rodriguez  *	CRDA and can be used by other regulatory requests. When a
68b2e253cfSLuis R. Rodriguez  *	the last request is not yet processed we must yield until it
69b2e253cfSLuis R. Rodriguez  *	is processed before processing any new requests.
70d3236553SJohannes Berg  * @country_ie_checksum: checksum of the last processed and accepted
71d3236553SJohannes Berg  *	country IE
72d3236553SJohannes Berg  * @country_ie_env: lets us know if the AP is telling us we are outdoor,
73d3236553SJohannes Berg  *	indoor, or if it doesn't matter
74d3236553SJohannes Berg  * @list: used to insert into the reg_requests_list linked list
75d3236553SJohannes Berg  */
76d3236553SJohannes Berg struct regulatory_request {
77c492db37SJohannes Berg 	struct rcu_head rcu_head;
78d3236553SJohannes Berg 	int wiphy_idx;
79d3236553SJohannes Berg 	enum nl80211_reg_initiator initiator;
8057b5ce07SLuis R. Rodriguez 	enum nl80211_user_reg_hint_type user_reg_hint_type;
81d3236553SJohannes Berg 	char alpha2[2];
82b68e6b3bSLuis R. Rodriguez 	u8 dfs_region;
83d3236553SJohannes Berg 	bool intersect;
84b2e253cfSLuis R. Rodriguez 	bool processed;
85d3236553SJohannes Berg 	enum environment_cap country_ie_env;
86d3236553SJohannes Berg 	struct list_head list;
87*a2f73b6cSLuis R. Rodriguez };
88*a2f73b6cSLuis R. Rodriguez 
89*a2f73b6cSLuis R. Rodriguez /**
90*a2f73b6cSLuis R. Rodriguez  * enum ieee80211_regulatory_flags - device regulatory flags
91*a2f73b6cSLuis R. Rodriguez  *
92*a2f73b6cSLuis R. Rodriguez  * @REGULATORY_CUSTOM_REG: tells us the driver for this device
93*a2f73b6cSLuis R. Rodriguez  *	has its own custom regulatory domain and cannot identify the
94*a2f73b6cSLuis R. Rodriguez  *	ISO / IEC 3166 alpha2 it belongs to. When this is enabled
95*a2f73b6cSLuis R. Rodriguez  *	we will disregard the first regulatory hint (when the
96*a2f73b6cSLuis R. Rodriguez  *	initiator is %REGDOM_SET_BY_CORE). Drivers that use
97*a2f73b6cSLuis R. Rodriguez  *	wiphy_apply_custom_regulatory() should have this flag set
98*a2f73b6cSLuis R. Rodriguez  *	or the regulatory core will set it for the wiphy.
99*a2f73b6cSLuis R. Rodriguez  * @REGULATORY_STRICT_REG: tells us the driver for this device will
100*a2f73b6cSLuis R. Rodriguez  *	ignore regulatory domain settings until it gets its own regulatory
101*a2f73b6cSLuis R. Rodriguez  *	domain via its regulatory_hint() unless the regulatory hint is
102*a2f73b6cSLuis R. Rodriguez  *	from a country IE. After its gets its own regulatory domain it will
103*a2f73b6cSLuis R. Rodriguez  *	only allow further regulatory domain settings to further enhance
104*a2f73b6cSLuis R. Rodriguez  *	compliance. For example if channel 13 and 14 are disabled by this
105*a2f73b6cSLuis R. Rodriguez  *	regulatory domain no user regulatory domain can enable these channels
106*a2f73b6cSLuis R. Rodriguez  *	at a later time. This can be used for devices which do not have
107*a2f73b6cSLuis R. Rodriguez  *	calibration information guaranteed for frequencies or settings
108*a2f73b6cSLuis R. Rodriguez  *	outside of its regulatory domain. If used in combination with
109*a2f73b6cSLuis R. Rodriguez  *	REGULATORY_FLAG_CUSTOM_REG the inspected country IE power settings
110*a2f73b6cSLuis R. Rodriguez  *	will be followed.
111*a2f73b6cSLuis R. Rodriguez  * @REGULATORY_DISABLE_BEACON_HINTS: enable this if your driver needs to
112*a2f73b6cSLuis R. Rodriguez  *	ensure that passive scan flags and beaconing flags may not be lifted by
113*a2f73b6cSLuis R. Rodriguez  *	cfg80211 due to regulatory beacon hints. For more information on beacon
114*a2f73b6cSLuis R. Rodriguez  *	hints read the documenation for regulatory_hint_found_beacon()
115*a2f73b6cSLuis R. Rodriguez  */
116*a2f73b6cSLuis R. Rodriguez enum ieee80211_regulatory_flags {
117*a2f73b6cSLuis R. Rodriguez 	REGULATORY_CUSTOM_REG			= BIT(0),
118*a2f73b6cSLuis R. Rodriguez 	REGULATORY_STRICT_REG			= BIT(1),
119*a2f73b6cSLuis R. Rodriguez 	REGULATORY_DISABLE_BEACON_HINTS		= BIT(2),
120d3236553SJohannes Berg };
121d3236553SJohannes Berg 
122d3236553SJohannes Berg struct ieee80211_freq_range {
123d3236553SJohannes Berg 	u32 start_freq_khz;
124d3236553SJohannes Berg 	u32 end_freq_khz;
125d3236553SJohannes Berg 	u32 max_bandwidth_khz;
126d3236553SJohannes Berg };
127d3236553SJohannes Berg 
128d3236553SJohannes Berg struct ieee80211_power_rule {
129d3236553SJohannes Berg 	u32 max_antenna_gain;
130d3236553SJohannes Berg 	u32 max_eirp;
131d3236553SJohannes Berg };
132d3236553SJohannes Berg 
133d3236553SJohannes Berg struct ieee80211_reg_rule {
134d3236553SJohannes Berg 	struct ieee80211_freq_range freq_range;
135d3236553SJohannes Berg 	struct ieee80211_power_rule power_rule;
136d3236553SJohannes Berg 	u32 flags;
137d3236553SJohannes Berg };
138d3236553SJohannes Berg 
139d3236553SJohannes Berg struct ieee80211_regdomain {
140458f4f9eSJohannes Berg 	struct rcu_head rcu_head;
141d3236553SJohannes Berg 	u32 n_reg_rules;
142d3236553SJohannes Berg 	char alpha2[2];
1438b60b078SLuis R. Rodriguez 	u8 dfs_region;
144d3236553SJohannes Berg 	struct ieee80211_reg_rule reg_rules[];
145d3236553SJohannes Berg };
146d3236553SJohannes Berg 
147d3236553SJohannes Berg #define MHZ_TO_KHZ(freq) ((freq) * 1000)
148d3236553SJohannes Berg #define KHZ_TO_MHZ(freq) ((freq) / 1000)
149d3236553SJohannes Berg #define DBI_TO_MBI(gain) ((gain) * 100)
150d3236553SJohannes Berg #define MBI_TO_DBI(gain) ((gain) / 100)
151d3236553SJohannes Berg #define DBM_TO_MBM(gain) ((gain) * 100)
152d3236553SJohannes Berg #define MBM_TO_DBM(gain) ((gain) / 100)
153d3236553SJohannes Berg 
154d3236553SJohannes Berg #define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
155d3236553SJohannes Berg {							\
156d3236553SJohannes Berg 	.freq_range.start_freq_khz = MHZ_TO_KHZ(start),	\
157d3236553SJohannes Berg 	.freq_range.end_freq_khz = MHZ_TO_KHZ(end),	\
158d3236553SJohannes Berg 	.freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw),	\
159d3236553SJohannes Berg 	.power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
160d3236553SJohannes Berg 	.power_rule.max_eirp = DBM_TO_MBM(eirp),	\
161d3236553SJohannes Berg 	.flags = reg_flags,				\
162d3236553SJohannes Berg }
163d3236553SJohannes Berg 
164d3236553SJohannes Berg #endif
165