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