xref: /openbmc/linux/include/net/regulatory.h (revision 458f4f9e960b9a3b674c4b87d996eef186b1fe83)
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 
21*458f4f9eSJohannes 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  *
39d3236553SJohannes Berg  * @wiphy_idx: this is set if this request's initiator is
40d3236553SJohannes Berg  * 	%REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
41d3236553SJohannes Berg  * 	can be used by the wireless core to deal with conflicts
42d3236553SJohannes Berg  * 	and potentially inform users of which devices specifically
43d3236553SJohannes Berg  * 	cased the conflicts.
44d3236553SJohannes Berg  * @initiator: indicates who sent this request, could be any of
45d3236553SJohannes Berg  * 	of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*)
46d3236553SJohannes Berg  * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
47d3236553SJohannes Berg  * 	regulatory domain. We have a few special codes:
48d3236553SJohannes Berg  * 	00 - World regulatory domain
49d3236553SJohannes Berg  * 	99 - built by driver but a specific alpha2 cannot be determined
50d3236553SJohannes Berg  * 	98 - result of an intersection between two regulatory domains
5109d989d1SLuis R. Rodriguez  *	97 - regulatory domain has not yet been configured
52b68e6b3bSLuis R. Rodriguez  * @dfs_region: If CRDA responded with a regulatory domain that requires
53b68e6b3bSLuis R. Rodriguez  *	DFS master operation on a known DFS region (NL80211_DFS_*),
54b68e6b3bSLuis R. Rodriguez  *	dfs_region represents that region. Drivers can use this and the
55b68e6b3bSLuis R. Rodriguez  *	@alpha2 to adjust their device's DFS parameters as required.
5657b5ce07SLuis R. Rodriguez  * @user_reg_hint_type: if the @initiator was of type
5757b5ce07SLuis R. Rodriguez  *	%NL80211_REGDOM_SET_BY_USER, this classifies the type
5857b5ce07SLuis R. Rodriguez  *	of hint passed. This could be any of the %NL80211_USER_REG_HINT_*
5957b5ce07SLuis R. Rodriguez  *	types.
60d3236553SJohannes Berg  * @intersect: indicates whether the wireless core should intersect
61d3236553SJohannes Berg  * 	the requested regulatory domain with the presently set regulatory
62d3236553SJohannes Berg  * 	domain.
63b2e253cfSLuis R. Rodriguez  * @processed: indicates whether or not this requests has already been
64b2e253cfSLuis R. Rodriguez  *	processed. When the last request is processed it means that the
65b2e253cfSLuis R. Rodriguez  *	currently regulatory domain set on cfg80211 is updated from
66b2e253cfSLuis R. Rodriguez  *	CRDA and can be used by other regulatory requests. When a
67b2e253cfSLuis R. Rodriguez  *	the last request is not yet processed we must yield until it
68b2e253cfSLuis R. Rodriguez  *	is processed before processing any new requests.
69d3236553SJohannes Berg  * @country_ie_checksum: checksum of the last processed and accepted
70d3236553SJohannes Berg  * 	country IE
71d3236553SJohannes Berg  * @country_ie_env: lets us know if the AP is telling us we are outdoor,
72d3236553SJohannes Berg  * 	indoor, or if it doesn't matter
73d3236553SJohannes Berg  * @list: used to insert into the reg_requests_list linked list
74d3236553SJohannes Berg  */
75d3236553SJohannes Berg struct regulatory_request {
76d3236553SJohannes Berg 	int wiphy_idx;
77d3236553SJohannes Berg 	enum nl80211_reg_initiator initiator;
7857b5ce07SLuis R. Rodriguez 	enum nl80211_user_reg_hint_type user_reg_hint_type;
79d3236553SJohannes Berg 	char alpha2[2];
80b68e6b3bSLuis R. Rodriguez 	u8 dfs_region;
81d3236553SJohannes Berg 	bool intersect;
82b2e253cfSLuis R. Rodriguez 	bool processed;
83d3236553SJohannes Berg 	enum environment_cap country_ie_env;
84d3236553SJohannes Berg 	struct list_head list;
85d3236553SJohannes Berg };
86d3236553SJohannes Berg 
87d3236553SJohannes Berg struct ieee80211_freq_range {
88d3236553SJohannes Berg 	u32 start_freq_khz;
89d3236553SJohannes Berg 	u32 end_freq_khz;
90d3236553SJohannes Berg 	u32 max_bandwidth_khz;
91d3236553SJohannes Berg };
92d3236553SJohannes Berg 
93d3236553SJohannes Berg struct ieee80211_power_rule {
94d3236553SJohannes Berg 	u32 max_antenna_gain;
95d3236553SJohannes Berg 	u32 max_eirp;
96d3236553SJohannes Berg };
97d3236553SJohannes Berg 
98d3236553SJohannes Berg struct ieee80211_reg_rule {
99d3236553SJohannes Berg 	struct ieee80211_freq_range freq_range;
100d3236553SJohannes Berg 	struct ieee80211_power_rule power_rule;
101d3236553SJohannes Berg 	u32 flags;
102d3236553SJohannes Berg };
103d3236553SJohannes Berg 
104d3236553SJohannes Berg struct ieee80211_regdomain {
105*458f4f9eSJohannes Berg 	struct rcu_head rcu_head;
106d3236553SJohannes Berg 	u32 n_reg_rules;
107d3236553SJohannes Berg 	char alpha2[2];
1088b60b078SLuis R. Rodriguez 	u8 dfs_region;
109d3236553SJohannes Berg 	struct ieee80211_reg_rule reg_rules[];
110d3236553SJohannes Berg };
111d3236553SJohannes Berg 
112d3236553SJohannes Berg #define MHZ_TO_KHZ(freq) ((freq) * 1000)
113d3236553SJohannes Berg #define KHZ_TO_MHZ(freq) ((freq) / 1000)
114d3236553SJohannes Berg #define DBI_TO_MBI(gain) ((gain) * 100)
115d3236553SJohannes Berg #define MBI_TO_DBI(gain) ((gain) / 100)
116d3236553SJohannes Berg #define DBM_TO_MBM(gain) ((gain) * 100)
117d3236553SJohannes Berg #define MBM_TO_DBM(gain) ((gain) / 100)
118d3236553SJohannes Berg 
119d3236553SJohannes Berg #define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
120d3236553SJohannes Berg {							\
121d3236553SJohannes Berg 	.freq_range.start_freq_khz = MHZ_TO_KHZ(start),	\
122d3236553SJohannes Berg 	.freq_range.end_freq_khz = MHZ_TO_KHZ(end),	\
123d3236553SJohannes Berg 	.freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw),	\
124d3236553SJohannes Berg 	.power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
125d3236553SJohannes Berg 	.power_rule.max_eirp = DBM_TO_MBM(eirp),	\
126d3236553SJohannes Berg 	.flags = reg_flags,				\
127d3236553SJohannes Berg }
128d3236553SJohannes Berg 
129d3236553SJohannes Berg #endif
130