xref: /linux/net/wireless/reg.h (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 #ifndef __NET_WIRELESS_REG_H
2 #define __NET_WIRELESS_REG_H
3 
4 #include <net/cfg80211.h>
5 
6 /*
7  * Copyright 2008-2011	Luis R. Rodriguez <mcgrof@qca.qualcomm.com>
8  * Copyright (C) 2019 Intel Corporation
9  *
10  * Permission to use, copy, modify, and/or distribute this software for any
11  * purpose with or without fee is hereby granted, provided that the above
12  * copyright notice and this permission notice appear in all copies.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22 
23 enum ieee80211_regd_source {
24 	REGD_SOURCE_INTERNAL_DB,
25 	REGD_SOURCE_CRDA,
26 	REGD_SOURCE_CACHED,
27 };
28 
29 extern const struct ieee80211_regdomain __rcu *cfg80211_regdomain;
30 
31 bool reg_is_valid_request(const char *alpha2);
32 bool is_world_regdom(const char *alpha2);
33 bool reg_supported_dfs_region(enum nl80211_dfs_regions dfs_region);
34 enum nl80211_dfs_regions reg_get_dfs_region(struct wiphy *wiphy);
35 
36 int regulatory_hint_user(const char *alpha2,
37 			 enum nl80211_user_reg_hint_type user_reg_hint_type);
38 
39 /**
40  * regulatory_hint_indoor - hint operation in indoor env. or not
41  * @is_indoor: if true indicates that user space thinks that the
42  * device is operating in an indoor environment.
43  * @portid: the netlink port ID on which the hint was given.
44  */
45 int regulatory_hint_indoor(bool is_indoor, u32 portid);
46 
47 /**
48  * regulatory_netlink_notify - notify on released netlink socket
49  * @portid: the netlink socket port ID
50  */
51 void regulatory_netlink_notify(u32 portid);
52 
53 void wiphy_regulatory_register(struct wiphy *wiphy);
54 void wiphy_regulatory_deregister(struct wiphy *wiphy);
55 
56 int __init regulatory_init(void);
57 void regulatory_exit(void);
58 
59 int set_regdom(const struct ieee80211_regdomain *rd,
60 	       enum ieee80211_regd_source regd_src);
61 
62 unsigned int reg_get_max_bandwidth(const struct ieee80211_regdomain *rd,
63 				   const struct ieee80211_reg_rule *rule);
64 
65 bool reg_last_request_cell_base(void);
66 
67 /**
68  * regulatory_hint_found_beacon - hints a beacon was found on a channel
69  * @wiphy: the wireless device where the beacon was found on
70  * @beacon_chan: the channel on which the beacon was found on
71  * @gfp: context flags
72  *
73  * This informs the wireless core that a beacon from an AP was found on
74  * the channel provided. This allows the wireless core to make educated
75  * guesses on regulatory to help with world roaming. This is only used for
76  * world roaming -- when we do not know our current location. This is
77  * only useful on channels 12, 13 and 14 on the 2 GHz band as channels
78  * 1-11 are already enabled by the world regulatory domain; and on
79  * non-radar 5 GHz channels.
80  *
81  * Drivers do not need to call this, cfg80211 will do it for after a scan
82  * on a newly found BSS. If you cannot make use of this feature you can
83  * set the wiphy->disable_beacon_hints to true.
84  */
85 int regulatory_hint_found_beacon(struct wiphy *wiphy,
86 				 struct ieee80211_channel *beacon_chan,
87 				 gfp_t gfp);
88 
89 /**
90  * regulatory_hint_country_ie - hints a country IE as a regulatory domain
91  * @wiphy: the wireless device giving the hint (used only for reporting
92  *	conflicts)
93  * @band: the band on which the country IE was received on. This determines
94  *	the band we'll process the country IE channel triplets for.
95  * @country_ie: pointer to the country IE
96  * @country_ie_len: length of the country IE
97  *
98  * We will intersect the rd with the what CRDA tells us should apply
99  * for the alpha2 this country IE belongs to, this prevents APs from
100  * sending us incorrect or outdated information against a country.
101  *
102  * The AP is expected to provide Country IE channel triplets for the
103  * band it is on. It is technically possible for APs to send channel
104  * country IE triplets even for channels outside of the band they are
105  * in but for that they would have to use the regulatory extension
106  * in combination with a triplet but this behaviour is currently
107  * not observed. For this reason if a triplet is seen with channel
108  * information for a band the BSS is not present in it will be ignored.
109  */
110 void regulatory_hint_country_ie(struct wiphy *wiphy,
111 			 enum nl80211_band band,
112 			 const u8 *country_ie,
113 			 u8 country_ie_len);
114 
115 /**
116  * regulatory_hint_disconnect - informs all devices have been disconnected
117  *
118  * Regulotory rules can be enhanced further upon scanning and upon
119  * connection to an AP. These rules become stale if we disconnect
120  * and go to another country, whether or not we suspend and resume.
121  * If we suspend, go to another country and resume we'll automatically
122  * get disconnected shortly after resuming and things will be reset as well.
123  * This routine is a helper to restore regulatory settings to how they were
124  * prior to our first connect attempt. This includes ignoring country IE and
125  * beacon regulatory hints. The ieee80211_regdom module parameter will always
126  * be respected but if a user had set the regulatory domain that will take
127  * precedence.
128  *
129  * Must be called from process context.
130  */
131 void regulatory_hint_disconnect(void);
132 
133 /**
134  * cfg80211_get_unii - get the U-NII band for the frequency
135  * @freq: the frequency for which we want to get the UNII band.
136 
137  * Get a value specifying the U-NII band frequency belongs to.
138  * U-NII bands are defined by the FCC in C.F.R 47 part 15.
139  *
140  * Returns -EINVAL if freq is invalid, 0 for UNII-1, 1 for UNII-2A,
141  * 2 for UNII-2B, 3 for UNII-2C and 4 for UNII-3.
142  */
143 int cfg80211_get_unii(int freq);
144 
145 /**
146  * regulatory_indoor_allowed - is indoor operation allowed
147  */
148 bool regulatory_indoor_allowed(void);
149 
150 /*
151  * Grace period to timeout pre-CAC results on the dfs channels. This timeout
152  * value is used for Non-ETSI domain.
153  * TODO: May be make this timeout available through regdb?
154  */
155 #define REG_PRE_CAC_EXPIRY_GRACE_MS 2000
156 
157 /**
158  * regulatory_propagate_dfs_state - Propagate DFS channel state to other wiphys
159  * @wiphy - wiphy on which radar is detected and the event will be propagated
160  *	to other available wiphys having the same DFS domain
161  * @chandef - Channel definition of radar detected channel
162  * @dfs_state - DFS channel state to be set
163  * @event - Type of radar event which triggered this DFS state change
164  *
165  * This function should be called with rtnl lock held.
166  */
167 void regulatory_propagate_dfs_state(struct wiphy *wiphy,
168 				    struct cfg80211_chan_def *chandef,
169 				    enum nl80211_dfs_state dfs_state,
170 				    enum nl80211_radar_event event);
171 
172 /**
173  * reg_dfs_domain_same - Checks if both wiphy have same DFS domain configured
174  * @wiphy1 - wiphy it's dfs_region to be checked against that of wiphy2
175  * @wiphy2 - wiphy it's dfs_region to be checked against that of wiphy1
176  */
177 bool reg_dfs_domain_same(struct wiphy *wiphy1, struct wiphy *wiphy2);
178 
179 /**
180  * reg_reload_regdb - reload the regulatory.db firmware file
181  */
182 int reg_reload_regdb(void);
183 
184 extern const u8 shipped_regdb_certs[];
185 extern unsigned int shipped_regdb_certs_len;
186 extern const u8 extra_regdb_certs[];
187 extern unsigned int extra_regdb_certs_len;
188 
189 #endif  /* __NET_WIRELESS_REG_H */
190