]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/net/regulatory.h
ath: fix warning on usage of REGULATORY_CUSTOM_REG
[mirror_ubuntu-bionic-kernel.git] / include / net / regulatory.h
CommitLineData
d3236553
JB
1#ifndef __NET_REGULATORY_H
2#define __NET_REGULATORY_H
3/*
4 * regulatory support structures
5 *
dde88b73 6 * Copyright 2008-2009 Luis R. Rodriguez <mcgrof@qca.qualcomm.com>
d3236553 7 *
dde88b73
LR
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.
d3236553
JB
19 */
20
458f4f9e 21#include <linux/rcupdate.h>
d3236553
JB
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 */
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 *
c492db37 39 * @rcu_head: RCU head struct used to free the request
d3236553 40 * @wiphy_idx: this is set if this request's initiator is
a2f73b6c
LR
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.
d3236553 45 * @initiator: indicates who sent this request, could be any of
a2f73b6c 46 * of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*)
d3236553 47 * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
a2f73b6c
LR
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
09d989d1 52 * 97 - regulatory domain has not yet been configured
b68e6b3b
LR
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.
57b5ce07
LR
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.
d3236553 61 * @intersect: indicates whether the wireless core should intersect
a2f73b6c
LR
62 * the requested regulatory domain with the presently set regulatory
63 * domain.
b2e253cf
LR
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.
d3236553 70 * @country_ie_checksum: checksum of the last processed and accepted
a2f73b6c 71 * country IE
d3236553 72 * @country_ie_env: lets us know if the AP is telling us we are outdoor,
a2f73b6c 73 * indoor, or if it doesn't matter
d3236553
JB
74 * @list: used to insert into the reg_requests_list linked list
75 */
76struct regulatory_request {
c492db37 77 struct rcu_head rcu_head;
d3236553
JB
78 int wiphy_idx;
79 enum nl80211_reg_initiator initiator;
57b5ce07 80 enum nl80211_user_reg_hint_type user_reg_hint_type;
d3236553 81 char alpha2[2];
4c7d3982 82 enum nl80211_dfs_regions dfs_region;
d3236553 83 bool intersect;
b2e253cf 84 bool processed;
d3236553
JB
85 enum environment_cap country_ie_env;
86 struct list_head list;
87};
88
a2f73b6c
LR
89/**
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.
a09a85a0
LR
99 * @REGULATORY_STRICT_REG: tells us that the wiphy for this device
100 * has regulatory domain that it wishes to be considered as the
101 * superset for regulatory rules. After this device gets its regulatory
102 * domain programmed further regulatory hints shall only be considered
103 * for this device to enhance regulatory compliance, forcing the
104 * device to only possibly use subsets of the original regulatory
105 * rules. For example if channel 13 and 14 are disabled by this
106 * device's regulatory domain no user specified regulatory hint which
107 * has these channels enabled would enable them for this wiphy,
108 * the device's original regulatory domain will be trusted as the
109 * base. You can program the superset of regulatory rules for this
110 * wiphy with regulatory_hint() for cards programmed with an
111 * ISO3166-alpha2 country code. wiphys that use regulatory_hint()
112 * will have their wiphy->regd programmed once the regulatory
113 * domain is set, and all other regulatory hints will be ignored
114 * until their own regulatory domain gets programmed.
a2f73b6c
LR
115 * @REGULATORY_DISABLE_BEACON_HINTS: enable this if your driver needs to
116 * ensure that passive scan flags and beaconing flags may not be lifted by
117 * cfg80211 due to regulatory beacon hints. For more information on beacon
118 * hints read the documenation for regulatory_hint_found_beacon()
a09a85a0
LR
119 * @REGULATORY_COUNTRY_IE_FOLLOW_POWER: for devices that have a preference
120 * that even though they may have programmed their own custom power
121 * setting prior to wiphy registration, they want to ensure their channel
122 * power settings are updated for this connection with the power settings
123 * derived from the regulatory domain. The regulatory domain used will be
124 * based on the ISO3166-alpha2 from country IE provided through
125 * regulatory_hint_country_ie()
2a901468
LR
126 * @REGULATORY_COUNTRY_IE_IGNORE: for devices that have a preference to ignore
127 * all country IE information processed by the regulatory core. This will
128 * override %REGULATORY_COUNTRY_IE_FOLLOW_POWER as all country IEs will
129 * be ignored.
a2f73b6c
LR
130 */
131enum ieee80211_regulatory_flags {
132 REGULATORY_CUSTOM_REG = BIT(0),
133 REGULATORY_STRICT_REG = BIT(1),
134 REGULATORY_DISABLE_BEACON_HINTS = BIT(2),
a09a85a0 135 REGULATORY_COUNTRY_IE_FOLLOW_POWER = BIT(3),
2a901468 136 REGULATORY_COUNTRY_IE_IGNORE = BIT(4),
a2f73b6c
LR
137};
138
d3236553
JB
139struct ieee80211_freq_range {
140 u32 start_freq_khz;
141 u32 end_freq_khz;
142 u32 max_bandwidth_khz;
143};
144
145struct ieee80211_power_rule {
146 u32 max_antenna_gain;
147 u32 max_eirp;
148};
149
150struct ieee80211_reg_rule {
151 struct ieee80211_freq_range freq_range;
152 struct ieee80211_power_rule power_rule;
153 u32 flags;
154};
155
156struct ieee80211_regdomain {
458f4f9e 157 struct rcu_head rcu_head;
d3236553
JB
158 u32 n_reg_rules;
159 char alpha2[2];
4c7d3982 160 enum nl80211_dfs_regions dfs_region;
d3236553
JB
161 struct ieee80211_reg_rule reg_rules[];
162};
163
164#define MHZ_TO_KHZ(freq) ((freq) * 1000)
165#define KHZ_TO_MHZ(freq) ((freq) / 1000)
166#define DBI_TO_MBI(gain) ((gain) * 100)
167#define MBI_TO_DBI(gain) ((gain) / 100)
168#define DBM_TO_MBM(gain) ((gain) * 100)
169#define MBM_TO_DBM(gain) ((gain) / 100)
170
171#define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
172{ \
173 .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
174 .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
175 .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
176 .power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
177 .power_rule.max_eirp = DBM_TO_MBM(eirp), \
178 .flags = reg_flags, \
179}
180
181#endif