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