xref: /openbmc/linux/include/net/regulatory.h (revision d323655372590c533c275b1d798f9d1221efb5c6)
1*d3236553SJohannes Berg #ifndef __NET_REGULATORY_H
2*d3236553SJohannes Berg #define __NET_REGULATORY_H
3*d3236553SJohannes Berg /*
4*d3236553SJohannes Berg  * regulatory support structures
5*d3236553SJohannes Berg  *
6*d3236553SJohannes Berg  * Copyright 2008-2009	Luis R. Rodriguez <lrodriguez@atheros.com>
7*d3236553SJohannes Berg  *
8*d3236553SJohannes Berg  * This program is free software; you can redistribute it and/or modify
9*d3236553SJohannes Berg  * it under the terms of the GNU General Public License version 2 as
10*d3236553SJohannes Berg  * published by the Free Software Foundation.
11*d3236553SJohannes Berg  */
12*d3236553SJohannes Berg 
13*d3236553SJohannes Berg 
14*d3236553SJohannes Berg /**
15*d3236553SJohannes Berg  * enum environment_cap - Environment parsed from country IE
16*d3236553SJohannes Berg  * @ENVIRON_ANY: indicates country IE applies to both indoor and
17*d3236553SJohannes Berg  *	outdoor operation.
18*d3236553SJohannes Berg  * @ENVIRON_INDOOR: indicates country IE applies only to indoor operation
19*d3236553SJohannes Berg  * @ENVIRON_OUTDOOR: indicates country IE applies only to outdoor operation
20*d3236553SJohannes Berg  */
21*d3236553SJohannes Berg enum environment_cap {
22*d3236553SJohannes Berg 	ENVIRON_ANY,
23*d3236553SJohannes Berg 	ENVIRON_INDOOR,
24*d3236553SJohannes Berg 	ENVIRON_OUTDOOR,
25*d3236553SJohannes Berg };
26*d3236553SJohannes Berg 
27*d3236553SJohannes Berg /**
28*d3236553SJohannes Berg  * struct regulatory_request - used to keep track of regulatory requests
29*d3236553SJohannes Berg  *
30*d3236553SJohannes Berg  * @wiphy_idx: this is set if this request's initiator is
31*d3236553SJohannes Berg  * 	%REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
32*d3236553SJohannes Berg  * 	can be used by the wireless core to deal with conflicts
33*d3236553SJohannes Berg  * 	and potentially inform users of which devices specifically
34*d3236553SJohannes Berg  * 	cased the conflicts.
35*d3236553SJohannes Berg  * @initiator: indicates who sent this request, could be any of
36*d3236553SJohannes Berg  * 	of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*)
37*d3236553SJohannes Berg  * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
38*d3236553SJohannes Berg  * 	regulatory domain. We have a few special codes:
39*d3236553SJohannes Berg  * 	00 - World regulatory domain
40*d3236553SJohannes Berg  * 	99 - built by driver but a specific alpha2 cannot be determined
41*d3236553SJohannes Berg  * 	98 - result of an intersection between two regulatory domains
42*d3236553SJohannes Berg  * @intersect: indicates whether the wireless core should intersect
43*d3236553SJohannes Berg  * 	the requested regulatory domain with the presently set regulatory
44*d3236553SJohannes Berg  * 	domain.
45*d3236553SJohannes Berg  * @country_ie_checksum: checksum of the last processed and accepted
46*d3236553SJohannes Berg  * 	country IE
47*d3236553SJohannes Berg  * @country_ie_env: lets us know if the AP is telling us we are outdoor,
48*d3236553SJohannes Berg  * 	indoor, or if it doesn't matter
49*d3236553SJohannes Berg  * @list: used to insert into the reg_requests_list linked list
50*d3236553SJohannes Berg  */
51*d3236553SJohannes Berg struct regulatory_request {
52*d3236553SJohannes Berg 	int wiphy_idx;
53*d3236553SJohannes Berg 	enum nl80211_reg_initiator initiator;
54*d3236553SJohannes Berg 	char alpha2[2];
55*d3236553SJohannes Berg 	bool intersect;
56*d3236553SJohannes Berg 	u32 country_ie_checksum;
57*d3236553SJohannes Berg 	enum environment_cap country_ie_env;
58*d3236553SJohannes Berg 	struct list_head list;
59*d3236553SJohannes Berg };
60*d3236553SJohannes Berg 
61*d3236553SJohannes Berg struct ieee80211_freq_range {
62*d3236553SJohannes Berg 	u32 start_freq_khz;
63*d3236553SJohannes Berg 	u32 end_freq_khz;
64*d3236553SJohannes Berg 	u32 max_bandwidth_khz;
65*d3236553SJohannes Berg };
66*d3236553SJohannes Berg 
67*d3236553SJohannes Berg struct ieee80211_power_rule {
68*d3236553SJohannes Berg 	u32 max_antenna_gain;
69*d3236553SJohannes Berg 	u32 max_eirp;
70*d3236553SJohannes Berg };
71*d3236553SJohannes Berg 
72*d3236553SJohannes Berg struct ieee80211_reg_rule {
73*d3236553SJohannes Berg 	struct ieee80211_freq_range freq_range;
74*d3236553SJohannes Berg 	struct ieee80211_power_rule power_rule;
75*d3236553SJohannes Berg 	u32 flags;
76*d3236553SJohannes Berg };
77*d3236553SJohannes Berg 
78*d3236553SJohannes Berg struct ieee80211_regdomain {
79*d3236553SJohannes Berg 	u32 n_reg_rules;
80*d3236553SJohannes Berg 	char alpha2[2];
81*d3236553SJohannes Berg 	struct ieee80211_reg_rule reg_rules[];
82*d3236553SJohannes Berg };
83*d3236553SJohannes Berg 
84*d3236553SJohannes Berg #define MHZ_TO_KHZ(freq) ((freq) * 1000)
85*d3236553SJohannes Berg #define KHZ_TO_MHZ(freq) ((freq) / 1000)
86*d3236553SJohannes Berg #define DBI_TO_MBI(gain) ((gain) * 100)
87*d3236553SJohannes Berg #define MBI_TO_DBI(gain) ((gain) / 100)
88*d3236553SJohannes Berg #define DBM_TO_MBM(gain) ((gain) * 100)
89*d3236553SJohannes Berg #define MBM_TO_DBM(gain) ((gain) / 100)
90*d3236553SJohannes Berg 
91*d3236553SJohannes Berg #define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
92*d3236553SJohannes Berg {							\
93*d3236553SJohannes Berg 	.freq_range.start_freq_khz = MHZ_TO_KHZ(start),	\
94*d3236553SJohannes Berg 	.freq_range.end_freq_khz = MHZ_TO_KHZ(end),	\
95*d3236553SJohannes Berg 	.freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw),	\
96*d3236553SJohannes Berg 	.power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
97*d3236553SJohannes Berg 	.power_rule.max_eirp = DBM_TO_MBM(eirp),	\
98*d3236553SJohannes Berg 	.flags = reg_flags,				\
99*d3236553SJohannes Berg }
100*d3236553SJohannes Berg 
101*d3236553SJohannes Berg #endif
102