blob: daf29b519a448a04b7239a1c26a2865995212ec5 [file] [log] [blame]
Amar Singhale4f28ee2015-10-21 14:36:56 -07001/*
2 * Copyright (c) 2014-2016 The Linux Foundation. All rights reserved.
3 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_regulatory.c
30 *
31 * hdd regulatory implementation
32 */
33
34#include "qdf_types.h"
Amar Singhal5f997862016-08-24 13:17:50 -070035#include "qdf_trace.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -070036#include "cds_reg_service.h"
Amar Singhal604ba6cf2016-07-27 15:29:51 -070037#include "cds_regdomain.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -070038#include "sme_api.h"
39#include "wlan_hdd_main.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -070040#include "wlan_hdd_regulatory.h"
41
Amar Singhale4f28ee2015-10-21 14:36:56 -070042#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
43#define IEEE80211_CHAN_PASSIVE_SCAN IEEE80211_CHAN_NO_IR
44#define IEEE80211_CHAN_NO_IBSS IEEE80211_CHAN_NO_IR
45#endif
46
47#define REG_RULE_2412_2462 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0)
48
49#define REG_RULE_2467_2472 REG_RULE(2467-10, 2472+10, 40, 0, 20, \
Amar Singhale4f28ee2015-10-21 14:36:56 -070050 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
51
Amar Singhal1c944922016-03-23 18:46:49 -070052#define REG_RULE_2484 REG_RULE(2484-10, 2484+10, 20, 0, 20, \
53 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS | \
54 NL80211_RRF_NO_OFDM)
55
56#define REG_RULE_5180_5320 REG_RULE(5180-10, 5320+10, 160, 0, 20, \
57 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
58
59#define REG_RULE_5500_5720 REG_RULE(5500-10, 5720+10, 160, 0, 20, \
Amar Singhale4f28ee2015-10-21 14:36:56 -070060 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
61
62#define REG_RULE_5745_5925 REG_RULE(5745-10, 5925+10, 80, 0, 20, \
63 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
64
65static bool init_by_driver;
66static bool init_by_reg_core;
67
68static const struct ieee80211_regdomain
69hdd_world_regrules_60_61_62 = {
70 .n_reg_rules = 6,
71 .alpha2 = "00",
72 .reg_rules = {
73 REG_RULE_2412_2462,
74 REG_RULE_2467_2472,
75 REG_RULE_2484,
76 REG_RULE_5180_5320,
77 REG_RULE_5500_5720,
78 REG_RULE_5745_5925,
79 }
80};
81
82static const struct ieee80211_regdomain
83hdd_world_regrules_63_65 = {
84 .n_reg_rules = 4,
85 .alpha2 = "00",
86 .reg_rules = {
87 REG_RULE_2412_2462,
88 REG_RULE_2467_2472,
89 REG_RULE_5180_5320,
90 REG_RULE_5745_5925,
91 }
92};
93
94static const struct ieee80211_regdomain
95hdd_world_regrules_64 = {
96 .n_reg_rules = 3,
97 .alpha2 = "00",
98 .reg_rules = {
99 REG_RULE_2412_2462,
100 REG_RULE_5180_5320,
101 REG_RULE_5745_5925,
102 }
103};
104
105static const struct ieee80211_regdomain
106hdd_world_regrules_66_69 = {
107 .n_reg_rules = 4,
108 .alpha2 = "00",
109 .reg_rules = {
110 REG_RULE_2412_2462,
111 REG_RULE_5180_5320,
112 REG_RULE_5500_5720,
113 REG_RULE_5745_5925,
114 }
115};
116
117static const struct ieee80211_regdomain
118hdd_world_regrules_67_68_6A_6C = {
119 .n_reg_rules = 5,
120 .alpha2 = "00",
121 .reg_rules = {
122 REG_RULE_2412_2462,
123 REG_RULE_2467_2472,
124 REG_RULE_5180_5320,
125 REG_RULE_5500_5720,
126 REG_RULE_5745_5925,
127 }
128};
129
130/**
131 * hdd_get_world_regrules() - get the appropriate world regrules
132 * @reg: regulatory data
133 *
134 * Return: regulatory rules ptr
135 */
136static const struct ieee80211_regdomain *hdd_get_world_regrules(
137struct regulatory *reg)
138{
Amar Singhal22995112016-01-22 10:42:33 -0800139 struct reg_dmn_pair *regpair =
140 (struct reg_dmn_pair *)reg->regpair;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700141
Amar Singhala7bb01b2016-01-27 11:31:59 -0800142 switch (regpair->reg_dmn_pair) {
Amar Singhale4f28ee2015-10-21 14:36:56 -0700143 case 0x60:
144 case 0x61:
145 case 0x62:
146 return &hdd_world_regrules_60_61_62;
147 case 0x63:
148 case 0x65:
149 return &hdd_world_regrules_63_65;
150 case 0x64:
151 return &hdd_world_regrules_64;
152 case 0x66:
153 case 0x69:
154 return &hdd_world_regrules_66_69;
155 case 0x67:
156 case 0x68:
157 case 0x6A:
158 case 0x6C:
159 return &hdd_world_regrules_67_68_6A_6C;
160 default:
161 hdd_warn("invalid world mode in BDF");
162 return &hdd_world_regrules_60_61_62;
163 }
164}
165
166/**
167 * hdd_is_world_regdomain() - whether world regdomain
168 * @reg_domain: integer regulatory domain
169 *
170 * Return: bool
171 */
Jeff Johnson87a24252016-10-05 16:20:52 -0700172static bool hdd_is_world_regdomain(uint32_t reg_domain)
Amar Singhale4f28ee2015-10-21 14:36:56 -0700173{
Amar Singhal5f997862016-08-24 13:17:50 -0700174 uint32_t temp_regd = reg_domain & ~WORLD_ROAMING_FLAG;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700175
Amar Singhal5f997862016-08-24 13:17:50 -0700176 return ((temp_regd & CTRY_FLAG) != CTRY_FLAG) &&
177 ((temp_regd & WORLD_ROAMING_MASK) ==
178 WORLD_ROAMING_PREFIX);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700179}
180
181
182/**
183 * hdd_update_regulatory_info() - update regulatory info
184 * @hdd_ctx: hdd context
185 *
186 * Return: void
187 */
188static void hdd_update_regulatory_info(hdd_context_t *hdd_ctx)
189{
190 uint32_t country_code;
191
192 country_code = cds_get_country_from_alpha2(hdd_ctx->reg.alpha2);
193
Amar Singhal5f997862016-08-24 13:17:50 -0700194 hdd_ctx->reg.reg_domain = CTRY_FLAG;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700195 hdd_ctx->reg.reg_domain |= country_code;
196
197 cds_fill_some_regulatory_info(&hdd_ctx->reg);
198
199}
200
201/**
Abhishek Singh3e6172f2016-05-04 16:56:48 +0530202 * hdd_reset_global_reg_params - Reset global static reg params
203 *
204 * This function is helpful in static driver to reset
205 * the global params.
206 *
207 * Return: void
208 */
209void hdd_reset_global_reg_params(void)
210{
211 init_by_driver = false;
212 init_by_reg_core = false;
213}
214
215/**
Amar Singhale4f28ee2015-10-21 14:36:56 -0700216 * hdd_regulatory_wiphy_init() - regulatory wiphy init
217 * @hdd_ctx: hdd context
218 * @reg: regulatory data
219 * @wiphy: wiphy structure
220 *
221 * Return: void
222 */
223#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
224static void hdd_regulatory_wiphy_init(hdd_context_t *hdd_ctx,
225 struct regulatory *reg,
226 struct wiphy *wiphy)
227{
228 const struct ieee80211_regdomain *reg_rules;
Amar Singhalb7fe2612016-10-19 10:49:58 -0700229 int chan_num;
230 struct ieee80211_channel chan;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700231
232 if (hdd_is_world_regdomain(reg->reg_domain)) {
233 reg_rules = hdd_get_world_regrules(reg);
234 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
235 } else if (hdd_ctx->config->fRegChangeDefCountry) {
236 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
237 reg_rules = &hdd_world_regrules_60_61_62;
238 } else {
239 wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
240 reg_rules = &hdd_world_regrules_60_61_62;
241 }
242
243 /*
244 * save the original driver regulatory flags
245 */
246 hdd_ctx->reg.reg_flags = wiphy->regulatory_flags;
247 wiphy_apply_custom_regulatory(wiphy, reg_rules);
248
249 /*
Amar Singhalb7fe2612016-10-19 10:49:58 -0700250 * disable 2.4 Ghz channels that dont have 20 mhz bw
251 */
252 for (chan_num = 0;
253 chan_num < wiphy->bands[IEEE80211_BAND_2GHZ]->n_channels;
254 chan_num++) {
255 chan = wiphy->bands[IEEE80211_BAND_2GHZ]->channels[chan_num];
256 if (chan.flags & IEEE80211_CHAN_NO_20MHZ)
257 chan.flags |= IEEE80211_CHAN_DISABLED;
258 }
259
260 /*
Amar Singhale4f28ee2015-10-21 14:36:56 -0700261 * restore the driver regulatory flags since
262 * wiphy_apply_custom_regulatory may have
263 * changed them
264 */
265 wiphy->regulatory_flags = hdd_ctx->reg.reg_flags;
266
267}
268#else
269static void hdd_regulatory_wiphy_init(hdd_context_t *hdd_ctx,
270 struct regulatory *reg,
271 struct wiphy *wiphy)
272{
273 const struct ieee80211_regdomain *reg_rules;
274
275 if (hdd_is_world_regdomain(reg->reg_domain)) {
276 reg_rules = hdd_get_world_regrules(reg);
277 wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
278 } else if (hdd_ctx->config->fRegChangeDefCountry) {
279 wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
280 reg_rules = &hdd_world_regrules_60_61_62;
281 } else {
282 wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
283 reg_rules = &hdd_world_regrules_60_61_62;
284 }
285
286 /*
287 * save the original driver regulatory flags
288 */
289 hdd_ctx->reg.reg_flags = wiphy->flags;
290 wiphy_apply_custom_regulatory(wiphy, reg_rules);
291
292 /*
293 * restore the driver regulatory flags since
294 * wiphy_apply_custom_regulatory may have
295 * changed them
296 */
297 wiphy->flags = hdd_ctx->reg.reg_flags;
298
299}
300#endif
301
302/**
Amar Singhale4f28ee2015-10-21 14:36:56 -0700303 * is_wiphy_custom_regulatory() - is custom regulatory defined
304 * @wiphy: wiphy
305 *
306 * Return: int
307 */
308#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
309static int is_wiphy_custom_regulatory(struct wiphy *wiphy)
310{
311
312 return wiphy->regulatory_flags & REGULATORY_CUSTOM_REG;
313}
314#else
315static int is_wiphy_custom_regulatory(struct wiphy *wiphy)
316{
317 return wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY;
318}
319#endif
320
321
322/**
323 * hdd_modify_wiphy() - modify wiphy
324 * @wiphy: wiphy
325 * @chan: channel structure
326 *
327 * Return: void
328 */
329static void hdd_modify_wiphy(struct wiphy *wiphy,
330 struct ieee80211_channel *chan)
331{
332 const struct ieee80211_reg_rule *reg_rule;
333
334 if (is_wiphy_custom_regulatory(wiphy)) {
335 reg_rule = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
336 if (!IS_ERR(reg_rule)) {
337 chan->flags &= ~IEEE80211_CHAN_DISABLED;
338
339 if (!(reg_rule->flags & NL80211_RRF_DFS)) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530340 hdd_info("Remove dfs restriction for %u",
341 chan->center_freq);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700342 chan->flags &= ~IEEE80211_CHAN_RADAR;
343 }
344
345 if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530346 hdd_info("Remove passive restriction for %u",
347 chan->center_freq);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700348 chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
349 }
350
351 if (!(reg_rule->flags & NL80211_RRF_NO_IBSS)) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530352 hdd_info("Remove no ibss restriction for %u",
353 chan->center_freq);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700354 chan->flags &= ~IEEE80211_CHAN_NO_IBSS;
355 }
356
357 chan->max_power =
358 MBM_TO_DBM(reg_rule->power_rule.max_eirp);
359 }
360 }
361}
362
363/**
364 * hdd_process_regulatory_data() - process regulatory data
365 * @hdd_ctx: hdd context
366 * @wiphy: wiphy
367 * @reset: whether to reset channel data
368 *
369 * Return: void
370 */
371static void hdd_process_regulatory_data(hdd_context_t *hdd_ctx,
372 struct wiphy *wiphy,
373 bool reset)
374{
Amar Singhal388b3f02016-02-10 13:37:18 -0800375 int band_num;
376 int chan_num;
Amar Singhalb2cb3002016-08-11 16:10:36 -0700377 enum channel_enum chan_enum = CHAN_ENUM_1;
378 struct ieee80211_channel *wiphy_chan, *wiphy_chan_144 = NULL;
Amar Singhal388b3f02016-02-10 13:37:18 -0800379 struct regulatory_channel *cds_chan;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700380 uint8_t band_capability;
381
382 band_capability = hdd_ctx->config->nBandCapability;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700383
Dustin Browna30892e2016-10-12 17:28:36 -0700384 for (band_num = 0; band_num < NUM_NL80211_BANDS; band_num++) {
Amar Singhale4f28ee2015-10-21 14:36:56 -0700385
Amar Singhal388b3f02016-02-10 13:37:18 -0800386 if (wiphy->bands[band_num] == NULL)
Amar Singhale4f28ee2015-10-21 14:36:56 -0700387 continue;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700388
Amar Singhal388b3f02016-02-10 13:37:18 -0800389 for (chan_num = 0;
390 chan_num < wiphy->bands[band_num]->n_channels;
391 chan_num++) {
Amar Singhale4f28ee2015-10-21 14:36:56 -0700392
Amar Singhal388b3f02016-02-10 13:37:18 -0800393 wiphy_chan =
394 &(wiphy->bands[band_num]->channels[chan_num]);
395 cds_chan = &(reg_channels[chan_enum]);
Amar Singhalb2cb3002016-08-11 16:10:36 -0700396 if (CHAN_ENUM_144 == chan_enum)
397 wiphy_chan_144 = wiphy_chan;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700398
Amar Singhal388b3f02016-02-10 13:37:18 -0800399 chan_enum++;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700400
401 if (!reset)
Amar Singhal388b3f02016-02-10 13:37:18 -0800402 hdd_modify_wiphy(wiphy, wiphy_chan);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700403
Amar Singhal388b3f02016-02-10 13:37:18 -0800404 if (wiphy_chan->flags & IEEE80211_CHAN_DISABLED) {
405 cds_chan->state = CHANNEL_STATE_DISABLE;
Amar Singhal18517882016-08-08 12:26:20 -0700406 } else if ((wiphy_chan->flags &
407 (IEEE80211_CHAN_RADAR |
408 IEEE80211_CHAN_PASSIVE_SCAN)) ||
409 ((hdd_ctx->config->indoor_channel_support
410 == false) &&
411 (wiphy_chan->flags &
412 IEEE80211_CHAN_INDOOR_ONLY))) {
413 if ((wiphy_chan->flags &
414 IEEE80211_CHAN_INDOOR_ONLY) &&
415 (false ==
416 hdd_ctx->config->indoor_channel_support))
Amar Singhal388b3f02016-02-10 13:37:18 -0800417 wiphy_chan->flags |=
Amar Singhale4f28ee2015-10-21 14:36:56 -0700418 IEEE80211_CHAN_PASSIVE_SCAN;
Amar Singhal388b3f02016-02-10 13:37:18 -0800419 cds_chan->state = CHANNEL_STATE_DFS;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700420 } else {
Amar Singhal388b3f02016-02-10 13:37:18 -0800421 cds_chan->state = CHANNEL_STATE_ENABLE;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700422 }
Amar Singhal388b3f02016-02-10 13:37:18 -0800423 cds_chan->pwr_limit = wiphy_chan->max_power;
424 cds_chan->flags = wiphy_chan->flags;
Amar Singhal1c944922016-03-23 18:46:49 -0700425
Amar Singhale4f28ee2015-10-21 14:36:56 -0700426 }
427 }
428
429 if (0 == (hdd_ctx->reg.eeprom_rd_ext &
430 (1 << WHAL_REG_EXT_FCC_CH_144))) {
Amar Singhal388b3f02016-02-10 13:37:18 -0800431 cds_chan = &(reg_channels[CHAN_ENUM_144]);
432 cds_chan->state = CHANNEL_STATE_DISABLE;
Amar Singhalb2cb3002016-08-11 16:10:36 -0700433 if (NULL != wiphy_chan_144)
434 wiphy_chan_144->flags |= IEEE80211_CHAN_DISABLED;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700435 }
Amar Singhal6842e8f2016-02-23 16:30:32 -0800436
437 wlan_hdd_cfg80211_update_band(wiphy, band_capability);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700438}
439
Amar Singhal604ba6cf2016-07-27 15:29:51 -0700440/**
441 * hdd_set_dfs_region() - set the dfs_region
442 * @dfs_region: the dfs_region to set
443 *
444 * Return: void
445 */
446#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
447static void hdd_set_dfs_region(hdd_context_t *hdd_ctx,
448 enum dfs_region dfs_reg)
449{
450 cds_put_dfs_region(dfs_reg);
451}
452#else
453static void hdd_set_dfs_region(hdd_context_t *hdd_ctx,
454 enum dfs_region dfs_reg)
455{
456
457 /* remap the ctl code to dfs region code */
458 switch (hdd_ctx->reg.ctl_5g) {
459 case FCC:
460 cds_put_dfs_region(DFS_FCC_REGION);
461 break;
462 case ETSI:
463 cds_put_dfs_region(DFS_ETSI_REGION);
464 break;
465 case MKK:
466 cds_put_dfs_region(DFS_MKK_REGION);
467 break;
468 default:
469 /* set default dfs_region to FCC */
470 cds_put_dfs_region(DFS_FCC_REGION);
471 break;
472 }
473
474}
475#endif
476
Amar Singhale4f28ee2015-10-21 14:36:56 -0700477
478/**
479 * hdd_regulatory_init() - regulatory_init
480 * @hdd_ctx: hdd context
481 * @wiphy: wiphy
482 *
483 * Return: int
484 */
485int hdd_regulatory_init(hdd_context_t *hdd_ctx, struct wiphy *wiphy)
486{
487 int ret_val;
488 struct regulatory *reg_info;
Amar Singhal604ba6cf2016-07-27 15:29:51 -0700489 enum dfs_region dfs_reg;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700490
491 reg_info = &hdd_ctx->reg;
492
Amar Singhale4f28ee2015-10-21 14:36:56 -0700493 ret_val = cds_fill_some_regulatory_info(reg_info);
494 if (ret_val) {
495 hdd_err("incorrect BDF regulatory data");
496 return ret_val;
497 }
498
Dustin Brown38f2b552016-10-04 13:57:46 -0700499 hdd_regulatory_wiphy_init(hdd_ctx, reg_info, wiphy);
500
501 hdd_process_regulatory_data(hdd_ctx, wiphy, true);
502
503 reg_info->cc_src = SOURCE_DRIVER;
504
Amar Singhale4f28ee2015-10-21 14:36:56 -0700505 cds_put_default_country(reg_info->alpha2);
506
Amar Singhale4f28ee2015-10-21 14:36:56 -0700507 cds_fill_and_send_ctl_to_fw(reg_info);
508
Amar Singhal604ba6cf2016-07-27 15:29:51 -0700509 hdd_set_dfs_region(hdd_ctx, DFS_FCC_REGION);
510 cds_get_dfs_region(&dfs_reg);
511 cds_set_wma_dfs_region(dfs_reg);
512
Amar Singhale4f28ee2015-10-21 14:36:56 -0700513 return 0;
514}
515
516/**
517 * hdd_program_country_code() - process channel information from country code
518 * @hdd_ctx: hddc context
519 *
520 * Return: void
521 */
522void hdd_program_country_code(hdd_context_t *hdd_ctx)
523{
524 struct wiphy *wiphy = hdd_ctx->wiphy;
525 uint8_t *country_alpha2 = hdd_ctx->reg.alpha2;
526
527 if (false == init_by_reg_core) {
528 init_by_driver = true;
529 if (('0' != country_alpha2[0]) ||
Amar Singhal38c5eeb2016-08-22 16:50:01 -0700530 ('0' != country_alpha2[1]))
Amar Singhale4f28ee2015-10-21 14:36:56 -0700531 regulatory_hint(wiphy, country_alpha2);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700532 }
533}
534
535
536/**
Amar Singhale4f28ee2015-10-21 14:36:56 -0700537 * hdd_restore_custom_reg_settings() - restore custom reg settings
538 * @wiphy: wiphy structure
539 * @country_alpha2: alpha2 of the country
540 * @reset: whether wiphy is reset
541 *
542 * Return: void
543 */
544#if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
545static void hdd_restore_custom_reg_settings(struct wiphy *wiphy,
546 uint8_t *country_alpha2,
547 bool *reset)
548{
549}
550#else
551static void hdd_restore_custom_reg_settings(struct wiphy *wiphy,
552 uint8_t *country_alpha2,
553 bool *reset)
554{
555 struct ieee80211_supported_band *sband;
Dustin Browna30892e2016-10-12 17:28:36 -0700556 enum nl80211_band band;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700557 struct ieee80211_channel *chan;
558 int i;
559
560 if ((country_alpha2[0] == '0') &&
561 (country_alpha2[1] == '0') &&
562 (wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)) {
563
Dustin Browna30892e2016-10-12 17:28:36 -0700564 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Amar Singhale4f28ee2015-10-21 14:36:56 -0700565 sband = wiphy->bands[band];
566 if (!sband)
567 continue;
568 for (i = 0; i < sband->n_channels; i++) {
569 chan = &sband->channels[i];
570 chan->flags = chan->orig_flags;
571 chan->max_antenna_gain = chan->orig_mag;
572 chan->max_power = chan->orig_mpwr;
573 }
574 }
575 *reset = true;
576 }
577}
578#endif
579
580
581/**
582 * hdd_restore_reg_flags() - restore regulatory flags
583 * @flags: regulatory flags
584 *
585 * Return: void
586 */
587#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
588static void hdd_restore_reg_flags(struct wiphy *wiphy, uint32_t flags)
589{
590 wiphy->regulatory_flags = flags;
591}
592#else
593static void hdd_restore_reg_flags(struct wiphy *wiphy, uint32_t flags)
594{
595 wiphy->flags = flags;
596}
597#endif
598
599
600/**
601 * hdd_reg_notifier() - regulatory notifier
602 * @wiphy: wiphy
603 * @request: regulatory request
604 *
605 * Return: void
606 */
607void hdd_reg_notifier(struct wiphy *wiphy,
608 struct regulatory_request *request)
609{
610 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700611 bool reset = false;
Amar Singhal604ba6cf2016-07-27 15:29:51 -0700612 enum dfs_region dfs_reg;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700613
614 hdd_info("country: %c%c, initiator %d, dfs_region: %d",
615 request->alpha2[0],
616 request->alpha2[1],
617 request->initiator,
618 request->dfs_region);
619
620 if (NULL == hdd_ctx) {
621 hdd_err("invalid hdd_ctx pointer");
622 return;
623 }
624
625 if (cds_is_driver_unloading() || cds_is_driver_recovering()) {
626 hdd_err("%s: unloading or ssr in progress, ignore",
627 __func__);
628 return;
629 }
630
Amar Singhal604ba6cf2016-07-27 15:29:51 -0700631 if (('K' == request->alpha2[0]) &&
632 ('R' == request->alpha2[1]))
633 request->dfs_region = DFS_KR_REGION;
634
635 if (('C' == request->alpha2[0]) &&
636 ('N' == request->alpha2[1]))
637 request->dfs_region = DFS_CN_REGION;
638
Amar Singhale4f28ee2015-10-21 14:36:56 -0700639 /* first check if this callback is in response to the driver callback */
640
641 switch (request->initiator) {
642 case NL80211_REGDOM_SET_BY_DRIVER:
643 case NL80211_REGDOM_SET_BY_CORE:
644 case NL80211_REGDOM_SET_BY_USER:
645
646 if ((false == init_by_driver) &&
647 (false == init_by_reg_core)) {
648
649 if (NL80211_REGDOM_SET_BY_CORE == request->initiator)
650 return;
651 init_by_reg_core = true;
652 }
653
654 if ((NL80211_REGDOM_SET_BY_DRIVER == request->initiator) &&
655 (true == init_by_driver)) {
656
657 /*
658 * restore the driver regulatory flags since
659 * regulatory_hint may have
660 * changed them
661 */
662 hdd_restore_reg_flags(wiphy, hdd_ctx->reg.reg_flags);
663 }
664
665 if (NL80211_REGDOM_SET_BY_CORE == request->initiator) {
666 hdd_ctx->reg.cc_src = SOURCE_CORE;
667 if (is_wiphy_custom_regulatory(wiphy))
668 reset = true;
669 } else if (NL80211_REGDOM_SET_BY_DRIVER == request->initiator)
670 hdd_ctx->reg.cc_src = SOURCE_DRIVER;
671 else {
672 hdd_ctx->reg.cc_src = SOURCE_USERSPACE;
673 hdd_restore_custom_reg_settings(wiphy,
674 request->alpha2,
675 &reset);
676 }
677
678 hdd_ctx->reg.alpha2[0] = request->alpha2[0];
679 hdd_ctx->reg.alpha2[1] = request->alpha2[1];
680
681 hdd_update_regulatory_info(hdd_ctx);
682
Amar Singhale4f28ee2015-10-21 14:36:56 -0700683 hdd_process_regulatory_data(hdd_ctx, wiphy, reset);
684
Amar Singhale4f28ee2015-10-21 14:36:56 -0700685 sme_generic_change_country_code(hdd_ctx->hHal,
686 hdd_ctx->reg.alpha2);
687
688 cds_fill_and_send_ctl_to_fw(&hdd_ctx->reg);
689
690 hdd_set_dfs_region(hdd_ctx, request->dfs_region);
691
692 cds_get_dfs_region(&dfs_reg);
693 cds_set_wma_dfs_region(dfs_reg);
694 break;
695
696 default:
697 break;
698 }
699}