blob: a6a20e2a54c4cfe65958673eb8a60e5a33f87a07 [file] [log] [blame]
Johannes Bergd3236552009-04-20 14:31:42 +02001#ifndef __NET_REGULATORY_H
2#define __NET_REGULATORY_H
3/*
4 * regulatory support structures
5 *
Luis R. Rodriguezdde88b72011-08-23 15:03:34 -07006 * Copyright 2008-2009 Luis R. Rodriguez <mcgrof@qca.qualcomm.com>
Johannes Bergd3236552009-04-20 14:31:42 +02007 *
Luis R. Rodriguezdde88b72011-08-23 15:03:34 -07008 * 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.
Johannes Bergd3236552009-04-20 14:31:42 +020019 */
20
Johannes Berg458f4f92012-12-06 15:47:38 +010021#include <linux/rcupdate.h>
Johannes Bergd3236552009-04-20 14:31:42 +020022
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 */
30enum 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 *
Johannes Bergc492db32012-12-06 16:29:25 +010039 * @rcu_head: RCU head struct used to free the request
Johannes Bergd3236552009-04-20 14:31:42 +020040 * @wiphy_idx: this is set if this request's initiator is
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +010041 * %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.
Johannes Bergd3236552009-04-20 14:31:42 +020045 * @initiator: indicates who sent this request, could be any of
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +010046 * of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*)
Johannes Bergd3236552009-04-20 14:31:42 +020047 * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +010048 * 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
Luis R. Rodriguez09d989d2010-01-29 19:58:57 -050052 * 97 - regulatory domain has not yet been configured
Luis R. Rodriguezb68e6b32011-10-11 10:59:03 -070053 * @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.
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -070057 * @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.
Johannes Bergd3236552009-04-20 14:31:42 +020061 * @intersect: indicates whether the wireless core should intersect
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +010062 * the requested regulatory domain with the presently set regulatory
63 * domain.
Luis R. Rodriguezb2e253c2010-11-17 21:46:09 -080064 * @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.
Johannes Bergd3236552009-04-20 14:31:42 +020070 * @country_ie_checksum: checksum of the last processed and accepted
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +010071 * country IE
Johannes Bergd3236552009-04-20 14:31:42 +020072 * @country_ie_env: lets us know if the AP is telling us we are outdoor,
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +010073 * indoor, or if it doesn't matter
Johannes Bergd3236552009-04-20 14:31:42 +020074 * @list: used to insert into the reg_requests_list linked list
75 */
76struct regulatory_request {
Johannes Bergc492db32012-12-06 16:29:25 +010077 struct rcu_head rcu_head;
Johannes Bergd3236552009-04-20 14:31:42 +020078 int wiphy_idx;
79 enum nl80211_reg_initiator initiator;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -070080 enum nl80211_user_reg_hint_type user_reg_hint_type;
Johannes Bergd3236552009-04-20 14:31:42 +020081 char alpha2[2];
Luis R. Rodriguezb68e6b32011-10-11 10:59:03 -070082 u8 dfs_region;
Johannes Bergd3236552009-04-20 14:31:42 +020083 bool intersect;
Luis R. Rodriguezb2e253c2010-11-17 21:46:09 -080084 bool processed;
Johannes Bergd3236552009-04-20 14:31:42 +020085 enum environment_cap country_ie_env;
86 struct list_head list;
87};
88
Luis R. Rodrigueza2f73b62013-11-11 22:15:29 +010089/**
90 * enum ieee80211_regulatory_flags - device regulatory flags
91 *
92 * @REGULATORY_CUSTOM_REG: tells us the driver for this device
93 * has its own custom regulatory domain and cannot identify the
94 * ISO / IEC 3166 alpha2 it belongs to. When this is enabled
95 * we will disregard the first regulatory hint (when the
96 * initiator is %REGDOM_SET_BY_CORE). Drivers that use
97 * wiphy_apply_custom_regulatory() should have this flag set
98 * or the regulatory core will set it for the wiphy.
99 * @REGULATORY_STRICT_REG: tells us the driver for this device will
100 * ignore regulatory domain settings until it gets its own regulatory
101 * domain via its regulatory_hint() unless the regulatory hint is
102 * from a country IE. After its gets its own regulatory domain it will
103 * only allow further regulatory domain settings to further enhance
104 * compliance. For example if channel 13 and 14 are disabled by this
105 * regulatory domain no user regulatory domain can enable these channels
106 * at a later time. This can be used for devices which do not have
107 * calibration information guaranteed for frequencies or settings
108 * outside of its regulatory domain. If used in combination with
109 * REGULATORY_FLAG_CUSTOM_REG the inspected country IE power settings
110 * will be followed.
111 * @REGULATORY_DISABLE_BEACON_HINTS: enable this if your driver needs to
112 * ensure that passive scan flags and beaconing flags may not be lifted by
113 * cfg80211 due to regulatory beacon hints. For more information on beacon
114 * hints read the documenation for regulatory_hint_found_beacon()
115 */
116enum ieee80211_regulatory_flags {
117 REGULATORY_CUSTOM_REG = BIT(0),
118 REGULATORY_STRICT_REG = BIT(1),
119 REGULATORY_DISABLE_BEACON_HINTS = BIT(2),
120};
121
Johannes Bergd3236552009-04-20 14:31:42 +0200122struct ieee80211_freq_range {
123 u32 start_freq_khz;
124 u32 end_freq_khz;
125 u32 max_bandwidth_khz;
126};
127
128struct ieee80211_power_rule {
129 u32 max_antenna_gain;
130 u32 max_eirp;
131};
132
133struct ieee80211_reg_rule {
134 struct ieee80211_freq_range freq_range;
135 struct ieee80211_power_rule power_rule;
136 u32 flags;
137};
138
139struct ieee80211_regdomain {
Johannes Berg458f4f92012-12-06 15:47:38 +0100140 struct rcu_head rcu_head;
Johannes Bergd3236552009-04-20 14:31:42 +0200141 u32 n_reg_rules;
142 char alpha2[2];
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700143 u8 dfs_region;
Johannes Bergd3236552009-04-20 14:31:42 +0200144 struct ieee80211_reg_rule reg_rules[];
145};
146
147#define MHZ_TO_KHZ(freq) ((freq) * 1000)
148#define KHZ_TO_MHZ(freq) ((freq) / 1000)
149#define DBI_TO_MBI(gain) ((gain) * 100)
150#define MBI_TO_DBI(gain) ((gain) / 100)
151#define DBM_TO_MBM(gain) ((gain) * 100)
152#define MBM_TO_DBM(gain) ((gain) / 100)
153
154#define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
155{ \
156 .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
157 .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
158 .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
159 .power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
160 .power_rule.max_eirp = DBM_TO_MBM(eirp), \
161 .flags = reg_flags, \
162}
163
164#endif