xref: /openbmc/linux/include/net/regulatory.h (revision dde88b736f228be8bb2a831a4c373910d0b950fa)
1d3236553SJohannes Berg #ifndef __NET_REGULATORY_H
2d3236553SJohannes Berg #define __NET_REGULATORY_H
3d3236553SJohannes Berg /*
4d3236553SJohannes Berg  * regulatory support structures
5d3236553SJohannes Berg  *
6*dde88b73SLuis R. Rodriguez  * Copyright 2008-2009	Luis R. Rodriguez <mcgrof@qca.qualcomm.com>
7d3236553SJohannes Berg  *
8*dde88b73SLuis R. Rodriguez  * Permission to use, copy, modify, and/or distribute this software for any
9*dde88b73SLuis R. Rodriguez  * purpose with or without fee is hereby granted, provided that the above
10*dde88b73SLuis R. Rodriguez  * copyright notice and this permission notice appear in all copies.
11*dde88b73SLuis R. Rodriguez  *
12*dde88b73SLuis R. Rodriguez  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13*dde88b73SLuis R. Rodriguez  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14*dde88b73SLuis R. Rodriguez  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15*dde88b73SLuis R. Rodriguez  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16*dde88b73SLuis R. Rodriguez  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17*dde88b73SLuis R. Rodriguez  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18*dde88b73SLuis R. Rodriguez  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19d3236553SJohannes Berg  */
20d3236553SJohannes Berg 
21d3236553SJohannes Berg 
22d3236553SJohannes Berg /**
23d3236553SJohannes Berg  * enum environment_cap - Environment parsed from country IE
24d3236553SJohannes Berg  * @ENVIRON_ANY: indicates country IE applies to both indoor and
25d3236553SJohannes Berg  *	outdoor operation.
26d3236553SJohannes Berg  * @ENVIRON_INDOOR: indicates country IE applies only to indoor operation
27d3236553SJohannes Berg  * @ENVIRON_OUTDOOR: indicates country IE applies only to outdoor operation
28d3236553SJohannes Berg  */
29d3236553SJohannes Berg enum environment_cap {
30d3236553SJohannes Berg 	ENVIRON_ANY,
31d3236553SJohannes Berg 	ENVIRON_INDOOR,
32d3236553SJohannes Berg 	ENVIRON_OUTDOOR,
33d3236553SJohannes Berg };
34d3236553SJohannes Berg 
35d3236553SJohannes Berg /**
36d3236553SJohannes Berg  * struct regulatory_request - used to keep track of regulatory requests
37d3236553SJohannes Berg  *
38d3236553SJohannes Berg  * @wiphy_idx: this is set if this request's initiator is
39d3236553SJohannes Berg  * 	%REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
40d3236553SJohannes Berg  * 	can be used by the wireless core to deal with conflicts
41d3236553SJohannes Berg  * 	and potentially inform users of which devices specifically
42d3236553SJohannes Berg  * 	cased the conflicts.
43d3236553SJohannes Berg  * @initiator: indicates who sent this request, could be any of
44d3236553SJohannes Berg  * 	of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*)
45d3236553SJohannes Berg  * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
46d3236553SJohannes Berg  * 	regulatory domain. We have a few special codes:
47d3236553SJohannes Berg  * 	00 - World regulatory domain
48d3236553SJohannes Berg  * 	99 - built by driver but a specific alpha2 cannot be determined
49d3236553SJohannes Berg  * 	98 - result of an intersection between two regulatory domains
5009d989d1SLuis R. Rodriguez  *	97 - regulatory domain has not yet been configured
51d3236553SJohannes Berg  * @intersect: indicates whether the wireless core should intersect
52d3236553SJohannes Berg  * 	the requested regulatory domain with the presently set regulatory
53d3236553SJohannes Berg  * 	domain.
54b2e253cfSLuis R. Rodriguez  * @processed: indicates whether or not this requests has already been
55b2e253cfSLuis R. Rodriguez  *	processed. When the last request is processed it means that the
56b2e253cfSLuis R. Rodriguez  *	currently regulatory domain set on cfg80211 is updated from
57b2e253cfSLuis R. Rodriguez  *	CRDA and can be used by other regulatory requests. When a
58b2e253cfSLuis R. Rodriguez  *	the last request is not yet processed we must yield until it
59b2e253cfSLuis R. Rodriguez  *	is processed before processing any new requests.
60d3236553SJohannes Berg  * @country_ie_checksum: checksum of the last processed and accepted
61d3236553SJohannes Berg  * 	country IE
62d3236553SJohannes Berg  * @country_ie_env: lets us know if the AP is telling us we are outdoor,
63d3236553SJohannes Berg  * 	indoor, or if it doesn't matter
64d3236553SJohannes Berg  * @list: used to insert into the reg_requests_list linked list
65d3236553SJohannes Berg  */
66d3236553SJohannes Berg struct regulatory_request {
67d3236553SJohannes Berg 	int wiphy_idx;
68d3236553SJohannes Berg 	enum nl80211_reg_initiator initiator;
69d3236553SJohannes Berg 	char alpha2[2];
70d3236553SJohannes Berg 	bool intersect;
71b2e253cfSLuis R. Rodriguez 	bool processed;
72d3236553SJohannes Berg 	enum environment_cap country_ie_env;
73d3236553SJohannes Berg 	struct list_head list;
74d3236553SJohannes Berg };
75d3236553SJohannes Berg 
76d3236553SJohannes Berg struct ieee80211_freq_range {
77d3236553SJohannes Berg 	u32 start_freq_khz;
78d3236553SJohannes Berg 	u32 end_freq_khz;
79d3236553SJohannes Berg 	u32 max_bandwidth_khz;
80d3236553SJohannes Berg };
81d3236553SJohannes Berg 
82d3236553SJohannes Berg struct ieee80211_power_rule {
83d3236553SJohannes Berg 	u32 max_antenna_gain;
84d3236553SJohannes Berg 	u32 max_eirp;
85d3236553SJohannes Berg };
86d3236553SJohannes Berg 
87d3236553SJohannes Berg struct ieee80211_reg_rule {
88d3236553SJohannes Berg 	struct ieee80211_freq_range freq_range;
89d3236553SJohannes Berg 	struct ieee80211_power_rule power_rule;
90d3236553SJohannes Berg 	u32 flags;
91d3236553SJohannes Berg };
92d3236553SJohannes Berg 
93d3236553SJohannes Berg struct ieee80211_regdomain {
94d3236553SJohannes Berg 	u32 n_reg_rules;
95d3236553SJohannes Berg 	char alpha2[2];
96d3236553SJohannes Berg 	struct ieee80211_reg_rule reg_rules[];
97d3236553SJohannes Berg };
98d3236553SJohannes Berg 
99d3236553SJohannes Berg #define MHZ_TO_KHZ(freq) ((freq) * 1000)
100d3236553SJohannes Berg #define KHZ_TO_MHZ(freq) ((freq) / 1000)
101d3236553SJohannes Berg #define DBI_TO_MBI(gain) ((gain) * 100)
102d3236553SJohannes Berg #define MBI_TO_DBI(gain) ((gain) / 100)
103d3236553SJohannes Berg #define DBM_TO_MBM(gain) ((gain) * 100)
104d3236553SJohannes Berg #define MBM_TO_DBM(gain) ((gain) / 100)
105d3236553SJohannes Berg 
106d3236553SJohannes Berg #define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
107d3236553SJohannes Berg {							\
108d3236553SJohannes Berg 	.freq_range.start_freq_khz = MHZ_TO_KHZ(start),	\
109d3236553SJohannes Berg 	.freq_range.end_freq_khz = MHZ_TO_KHZ(end),	\
110d3236553SJohannes Berg 	.freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw),	\
111d3236553SJohannes Berg 	.power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
112d3236553SJohannes Berg 	.power_rule.max_eirp = DBM_TO_MBM(eirp),	\
113d3236553SJohannes Berg 	.flags = reg_flags,				\
114d3236553SJohannes Berg }
115d3236553SJohannes Berg 
116d3236553SJohannes Berg #endif
117