blob: 4487d5dd25000ca5dac99d8a0530c6ef2716ce25 [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"
35#include "cds_reg_service.h"
Amar Singhal604ba6cf2016-07-27 15:29:51 -070036#include "cds_regdomain.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -070037#include "qdf_trace.h"
38#include "sme_api.h"
39#include "wlan_hdd_main.h"
Amar Singhale4f28ee2015-10-21 14:36:56 -070040#include "wlan_hdd_regulatory.h"
41
42#define WORLD_SKU_MASK 0x00F0
43#define WORLD_SKU_PREFIX 0x0060
44#define REG_WAIT_TIME 50
45
46#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
47#define IEEE80211_CHAN_PASSIVE_SCAN IEEE80211_CHAN_NO_IR
48#define IEEE80211_CHAN_NO_IBSS IEEE80211_CHAN_NO_IR
49#endif
50
51#define REG_RULE_2412_2462 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0)
52
53#define REG_RULE_2467_2472 REG_RULE(2467-10, 2472+10, 40, 0, 20, \
Amar Singhale4f28ee2015-10-21 14:36:56 -070054 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
55
Amar Singhal1c944922016-03-23 18:46:49 -070056#define REG_RULE_2484 REG_RULE(2484-10, 2484+10, 20, 0, 20, \
57 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS | \
58 NL80211_RRF_NO_OFDM)
59
60#define REG_RULE_5180_5320 REG_RULE(5180-10, 5320+10, 160, 0, 20, \
61 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
62
63#define REG_RULE_5500_5720 REG_RULE(5500-10, 5720+10, 160, 0, 20, \
Amar Singhale4f28ee2015-10-21 14:36:56 -070064 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
65
66#define REG_RULE_5745_5925 REG_RULE(5745-10, 5925+10, 80, 0, 20, \
67 NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS)
68
69static bool init_by_driver;
70static bool init_by_reg_core;
71
72static const struct ieee80211_regdomain
73hdd_world_regrules_60_61_62 = {
74 .n_reg_rules = 6,
75 .alpha2 = "00",
76 .reg_rules = {
77 REG_RULE_2412_2462,
78 REG_RULE_2467_2472,
79 REG_RULE_2484,
80 REG_RULE_5180_5320,
81 REG_RULE_5500_5720,
82 REG_RULE_5745_5925,
83 }
84};
85
86static const struct ieee80211_regdomain
87hdd_world_regrules_63_65 = {
88 .n_reg_rules = 4,
89 .alpha2 = "00",
90 .reg_rules = {
91 REG_RULE_2412_2462,
92 REG_RULE_2467_2472,
93 REG_RULE_5180_5320,
94 REG_RULE_5745_5925,
95 }
96};
97
98static const struct ieee80211_regdomain
99hdd_world_regrules_64 = {
100 .n_reg_rules = 3,
101 .alpha2 = "00",
102 .reg_rules = {
103 REG_RULE_2412_2462,
104 REG_RULE_5180_5320,
105 REG_RULE_5745_5925,
106 }
107};
108
109static const struct ieee80211_regdomain
110hdd_world_regrules_66_69 = {
111 .n_reg_rules = 4,
112 .alpha2 = "00",
113 .reg_rules = {
114 REG_RULE_2412_2462,
115 REG_RULE_5180_5320,
116 REG_RULE_5500_5720,
117 REG_RULE_5745_5925,
118 }
119};
120
121static const struct ieee80211_regdomain
122hdd_world_regrules_67_68_6A_6C = {
123 .n_reg_rules = 5,
124 .alpha2 = "00",
125 .reg_rules = {
126 REG_RULE_2412_2462,
127 REG_RULE_2467_2472,
128 REG_RULE_5180_5320,
129 REG_RULE_5500_5720,
130 REG_RULE_5745_5925,
131 }
132};
133
134/**
135 * hdd_get_world_regrules() - get the appropriate world regrules
136 * @reg: regulatory data
137 *
138 * Return: regulatory rules ptr
139 */
140static const struct ieee80211_regdomain *hdd_get_world_regrules(
141struct regulatory *reg)
142{
Amar Singhal22995112016-01-22 10:42:33 -0800143 struct reg_dmn_pair *regpair =
144 (struct reg_dmn_pair *)reg->regpair;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700145
Amar Singhala7bb01b2016-01-27 11:31:59 -0800146 switch (regpair->reg_dmn_pair) {
Amar Singhale4f28ee2015-10-21 14:36:56 -0700147 case 0x60:
148 case 0x61:
149 case 0x62:
150 return &hdd_world_regrules_60_61_62;
151 case 0x63:
152 case 0x65:
153 return &hdd_world_regrules_63_65;
154 case 0x64:
155 return &hdd_world_regrules_64;
156 case 0x66:
157 case 0x69:
158 return &hdd_world_regrules_66_69;
159 case 0x67:
160 case 0x68:
161 case 0x6A:
162 case 0x6C:
163 return &hdd_world_regrules_67_68_6A_6C;
164 default:
165 hdd_warn("invalid world mode in BDF");
166 return &hdd_world_regrules_60_61_62;
167 }
168}
169
170/**
171 * hdd_is_world_regdomain() - whether world regdomain
172 * @reg_domain: integer regulatory domain
173 *
174 * Return: bool
175 */
Jeff Johnson87a24252016-10-05 16:20:52 -0700176static bool hdd_is_world_regdomain(uint32_t reg_domain)
Amar Singhale4f28ee2015-10-21 14:36:56 -0700177{
178 uint32_t temp_regd = reg_domain & ~WORLDWIDE_ROAMING_FLAG;
179
180 return ((temp_regd & COUNTRY_ERD_FLAG) != COUNTRY_ERD_FLAG) &&
181 (((temp_regd & WORLD_SKU_MASK) == WORLD_SKU_PREFIX) ||
182 (temp_regd == WORLD));
183}
184
185
186/**
187 * hdd_update_regulatory_info() - update regulatory info
188 * @hdd_ctx: hdd context
189 *
190 * Return: void
191 */
192static void hdd_update_regulatory_info(hdd_context_t *hdd_ctx)
193{
194 uint32_t country_code;
195
196 country_code = cds_get_country_from_alpha2(hdd_ctx->reg.alpha2);
197
198 hdd_ctx->reg.reg_domain = COUNTRY_ERD_FLAG;
199 hdd_ctx->reg.reg_domain |= country_code;
200
201 cds_fill_some_regulatory_info(&hdd_ctx->reg);
202
203}
204
205/**
Abhishek Singh3e6172f2016-05-04 16:56:48 +0530206 * hdd_reset_global_reg_params - Reset global static reg params
207 *
208 * This function is helpful in static driver to reset
209 * the global params.
210 *
211 * Return: void
212 */
213void hdd_reset_global_reg_params(void)
214{
215 init_by_driver = false;
216 init_by_reg_core = false;
217}
218
219/**
Amar Singhale4f28ee2015-10-21 14:36:56 -0700220 * hdd_regulatory_wiphy_init() - regulatory wiphy init
221 * @hdd_ctx: hdd context
222 * @reg: regulatory data
223 * @wiphy: wiphy structure
224 *
225 * Return: void
226 */
227#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
228static void hdd_regulatory_wiphy_init(hdd_context_t *hdd_ctx,
229 struct regulatory *reg,
230 struct wiphy *wiphy)
231{
232 const struct ieee80211_regdomain *reg_rules;
233
234 if (hdd_is_world_regdomain(reg->reg_domain)) {
235 reg_rules = hdd_get_world_regrules(reg);
236 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
237 } else if (hdd_ctx->config->fRegChangeDefCountry) {
238 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
239 reg_rules = &hdd_world_regrules_60_61_62;
240 } else {
241 wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
242 reg_rules = &hdd_world_regrules_60_61_62;
243 }
244
245 /*
246 * save the original driver regulatory flags
247 */
248 hdd_ctx->reg.reg_flags = wiphy->regulatory_flags;
249 wiphy_apply_custom_regulatory(wiphy, reg_rules);
250
251 /*
252 * restore the driver regulatory flags since
253 * wiphy_apply_custom_regulatory may have
254 * changed them
255 */
256 wiphy->regulatory_flags = hdd_ctx->reg.reg_flags;
257
258}
259#else
260static void hdd_regulatory_wiphy_init(hdd_context_t *hdd_ctx,
261 struct regulatory *reg,
262 struct wiphy *wiphy)
263{
264 const struct ieee80211_regdomain *reg_rules;
265
266 if (hdd_is_world_regdomain(reg->reg_domain)) {
267 reg_rules = hdd_get_world_regrules(reg);
268 wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
269 } else if (hdd_ctx->config->fRegChangeDefCountry) {
270 wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
271 reg_rules = &hdd_world_regrules_60_61_62;
272 } else {
273 wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY;
274 reg_rules = &hdd_world_regrules_60_61_62;
275 }
276
277 /*
278 * save the original driver regulatory flags
279 */
280 hdd_ctx->reg.reg_flags = wiphy->flags;
281 wiphy_apply_custom_regulatory(wiphy, reg_rules);
282
283 /*
284 * restore the driver regulatory flags since
285 * wiphy_apply_custom_regulatory may have
286 * changed them
287 */
288 wiphy->flags = hdd_ctx->reg.reg_flags;
289
290}
291#endif
292
293/**
Amar Singhale4f28ee2015-10-21 14:36:56 -0700294 * is_wiphy_custom_regulatory() - is custom regulatory defined
295 * @wiphy: wiphy
296 *
297 * Return: int
298 */
299#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
300static int is_wiphy_custom_regulatory(struct wiphy *wiphy)
301{
302
303 return wiphy->regulatory_flags & REGULATORY_CUSTOM_REG;
304}
305#else
306static int is_wiphy_custom_regulatory(struct wiphy *wiphy)
307{
308 return wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY;
309}
310#endif
311
312
313/**
314 * hdd_modify_wiphy() - modify wiphy
315 * @wiphy: wiphy
316 * @chan: channel structure
317 *
318 * Return: void
319 */
320static void hdd_modify_wiphy(struct wiphy *wiphy,
321 struct ieee80211_channel *chan)
322{
323 const struct ieee80211_reg_rule *reg_rule;
324
325 if (is_wiphy_custom_regulatory(wiphy)) {
326 reg_rule = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
327 if (!IS_ERR(reg_rule)) {
328 chan->flags &= ~IEEE80211_CHAN_DISABLED;
329
330 if (!(reg_rule->flags & NL80211_RRF_DFS)) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530331 hdd_info("Remove dfs restriction for %u",
332 chan->center_freq);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700333 chan->flags &= ~IEEE80211_CHAN_RADAR;
334 }
335
336 if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530337 hdd_info("Remove passive restriction for %u",
338 chan->center_freq);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700339 chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
340 }
341
342 if (!(reg_rule->flags & NL80211_RRF_NO_IBSS)) {
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530343 hdd_info("Remove no ibss restriction for %u",
344 chan->center_freq);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700345 chan->flags &= ~IEEE80211_CHAN_NO_IBSS;
346 }
347
348 chan->max_power =
349 MBM_TO_DBM(reg_rule->power_rule.max_eirp);
350 }
351 }
352}
353
354/**
355 * hdd_process_regulatory_data() - process regulatory data
356 * @hdd_ctx: hdd context
357 * @wiphy: wiphy
358 * @reset: whether to reset channel data
359 *
360 * Return: void
361 */
362static void hdd_process_regulatory_data(hdd_context_t *hdd_ctx,
363 struct wiphy *wiphy,
364 bool reset)
365{
Amar Singhal388b3f02016-02-10 13:37:18 -0800366 int band_num;
367 int chan_num;
Amar Singhalb2cb3002016-08-11 16:10:36 -0700368 enum channel_enum chan_enum = CHAN_ENUM_1;
369 struct ieee80211_channel *wiphy_chan, *wiphy_chan_144 = NULL;
Amar Singhal388b3f02016-02-10 13:37:18 -0800370 struct regulatory_channel *cds_chan;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700371 uint8_t band_capability;
372
373 band_capability = hdd_ctx->config->nBandCapability;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700374 hdd_ctx->isVHT80Allowed = 0;
375
Amar Singhal388b3f02016-02-10 13:37:18 -0800376 for (band_num = 0; band_num < IEEE80211_NUM_BANDS; band_num++) {
Amar Singhale4f28ee2015-10-21 14:36:56 -0700377
Amar Singhal388b3f02016-02-10 13:37:18 -0800378 if (wiphy->bands[band_num] == NULL)
Amar Singhale4f28ee2015-10-21 14:36:56 -0700379 continue;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700380
Amar Singhal388b3f02016-02-10 13:37:18 -0800381 for (chan_num = 0;
382 chan_num < wiphy->bands[band_num]->n_channels;
383 chan_num++) {
Amar Singhale4f28ee2015-10-21 14:36:56 -0700384
Amar Singhal388b3f02016-02-10 13:37:18 -0800385 wiphy_chan =
386 &(wiphy->bands[band_num]->channels[chan_num]);
387 cds_chan = &(reg_channels[chan_enum]);
Amar Singhalb2cb3002016-08-11 16:10:36 -0700388 if (CHAN_ENUM_144 == chan_enum)
389 wiphy_chan_144 = wiphy_chan;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700390
Amar Singhal388b3f02016-02-10 13:37:18 -0800391 chan_enum++;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700392
393 if (!reset)
Amar Singhal388b3f02016-02-10 13:37:18 -0800394 hdd_modify_wiphy(wiphy, wiphy_chan);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700395
Amar Singhal388b3f02016-02-10 13:37:18 -0800396 if (wiphy_chan->flags & IEEE80211_CHAN_DISABLED) {
397 cds_chan->state = CHANNEL_STATE_DISABLE;
Amar Singhal18517882016-08-08 12:26:20 -0700398 } else if ((wiphy_chan->flags &
399 (IEEE80211_CHAN_RADAR |
400 IEEE80211_CHAN_PASSIVE_SCAN)) ||
401 ((hdd_ctx->config->indoor_channel_support
402 == false) &&
403 (wiphy_chan->flags &
404 IEEE80211_CHAN_INDOOR_ONLY))) {
405 if ((wiphy_chan->flags &
406 IEEE80211_CHAN_INDOOR_ONLY) &&
407 (false ==
408 hdd_ctx->config->indoor_channel_support))
Amar Singhal388b3f02016-02-10 13:37:18 -0800409 wiphy_chan->flags |=
Amar Singhale4f28ee2015-10-21 14:36:56 -0700410 IEEE80211_CHAN_PASSIVE_SCAN;
Amar Singhal388b3f02016-02-10 13:37:18 -0800411 cds_chan->state = CHANNEL_STATE_DFS;
412 if ((wiphy_chan->flags &
Amar Singhale4f28ee2015-10-21 14:36:56 -0700413 IEEE80211_CHAN_NO_80MHZ) == 0)
414 hdd_ctx->isVHT80Allowed = 1;
415 } else {
Amar Singhal388b3f02016-02-10 13:37:18 -0800416 cds_chan->state = CHANNEL_STATE_ENABLE;
417 if ((wiphy_chan->flags &
Amar Singhale4f28ee2015-10-21 14:36:56 -0700418 IEEE80211_CHAN_NO_80MHZ) == 0)
419 hdd_ctx->isVHT80Allowed = 1;
420 }
Amar Singhal388b3f02016-02-10 13:37:18 -0800421 cds_chan->pwr_limit = wiphy_chan->max_power;
422 cds_chan->flags = wiphy_chan->flags;
Amar Singhal1c944922016-03-23 18:46:49 -0700423
Amar Singhale4f28ee2015-10-21 14:36:56 -0700424 }
425 }
426
427 if (0 == (hdd_ctx->reg.eeprom_rd_ext &
428 (1 << WHAL_REG_EXT_FCC_CH_144))) {
Amar Singhal388b3f02016-02-10 13:37:18 -0800429 cds_chan = &(reg_channels[CHAN_ENUM_144]);
430 cds_chan->state = CHANNEL_STATE_DISABLE;
Amar Singhalb2cb3002016-08-11 16:10:36 -0700431 if (NULL != wiphy_chan_144)
432 wiphy_chan_144->flags |= IEEE80211_CHAN_DISABLED;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700433 }
Amar Singhal6842e8f2016-02-23 16:30:32 -0800434
435 wlan_hdd_cfg80211_update_band(wiphy, band_capability);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700436}
437
Amar Singhal604ba6cf2016-07-27 15:29:51 -0700438/**
439 * hdd_set_dfs_region() - set the dfs_region
440 * @dfs_region: the dfs_region to set
441 *
442 * Return: void
443 */
444#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
445static void hdd_set_dfs_region(hdd_context_t *hdd_ctx,
446 enum dfs_region dfs_reg)
447{
448 cds_put_dfs_region(dfs_reg);
449}
450#else
451static void hdd_set_dfs_region(hdd_context_t *hdd_ctx,
452 enum dfs_region dfs_reg)
453{
454
455 /* remap the ctl code to dfs region code */
456 switch (hdd_ctx->reg.ctl_5g) {
457 case FCC:
458 cds_put_dfs_region(DFS_FCC_REGION);
459 break;
460 case ETSI:
461 cds_put_dfs_region(DFS_ETSI_REGION);
462 break;
463 case MKK:
464 cds_put_dfs_region(DFS_MKK_REGION);
465 break;
466 default:
467 /* set default dfs_region to FCC */
468 cds_put_dfs_region(DFS_FCC_REGION);
469 break;
470 }
471
472}
473#endif
474
Amar Singhale4f28ee2015-10-21 14:36:56 -0700475
476/**
477 * hdd_regulatory_init() - regulatory_init
478 * @hdd_ctx: hdd context
479 * @wiphy: wiphy
480 *
481 * Return: int
482 */
483int hdd_regulatory_init(hdd_context_t *hdd_ctx, struct wiphy *wiphy)
484{
485 int ret_val;
486 struct regulatory *reg_info;
Amar Singhal604ba6cf2016-07-27 15:29:51 -0700487 enum dfs_region dfs_reg;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700488
489 reg_info = &hdd_ctx->reg;
490
Amar Singhale4f28ee2015-10-21 14:36:56 -0700491 ret_val = cds_fill_some_regulatory_info(reg_info);
492 if (ret_val) {
493 hdd_err("incorrect BDF regulatory data");
494 return ret_val;
495 }
496
Dustin Brown38f2b552016-10-04 13:57:46 -0700497 hdd_regulatory_wiphy_init(hdd_ctx, reg_info, wiphy);
498
499 hdd_process_regulatory_data(hdd_ctx, wiphy, true);
500
501 reg_info->cc_src = SOURCE_DRIVER;
502
Amar Singhale4f28ee2015-10-21 14:36:56 -0700503 cds_put_default_country(reg_info->alpha2);
504
505 init_completion(&hdd_ctx->reg_init);
506
507 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]) ||
530 ('0' != country_alpha2[1])) {
531 INIT_COMPLETION(hdd_ctx->reg_init);
532 regulatory_hint(wiphy, country_alpha2);
533 wait_for_completion_timeout(&hdd_ctx->reg_init,
534 msecs_to_jiffies(REG_WAIT_TIME));
535 }
536 }
537}
538
539
540/**
Amar Singhale4f28ee2015-10-21 14:36:56 -0700541 * hdd_restore_custom_reg_settings() - restore custom reg settings
542 * @wiphy: wiphy structure
543 * @country_alpha2: alpha2 of the country
544 * @reset: whether wiphy is reset
545 *
546 * Return: void
547 */
548#if (LINUX_VERSION_CODE > KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
549static void hdd_restore_custom_reg_settings(struct wiphy *wiphy,
550 uint8_t *country_alpha2,
551 bool *reset)
552{
553}
554#else
555static void hdd_restore_custom_reg_settings(struct wiphy *wiphy,
556 uint8_t *country_alpha2,
557 bool *reset)
558{
559 struct ieee80211_supported_band *sband;
560 enum ieee80211_band band;
561 struct ieee80211_channel *chan;
562 int i;
563
564 if ((country_alpha2[0] == '0') &&
565 (country_alpha2[1] == '0') &&
566 (wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)) {
567
568 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
569 sband = wiphy->bands[band];
570 if (!sband)
571 continue;
572 for (i = 0; i < sband->n_channels; i++) {
573 chan = &sband->channels[i];
574 chan->flags = chan->orig_flags;
575 chan->max_antenna_gain = chan->orig_mag;
576 chan->max_power = chan->orig_mpwr;
577 }
578 }
579 *reset = true;
580 }
581}
582#endif
583
584
585/**
586 * hdd_restore_reg_flags() - restore regulatory flags
587 * @flags: regulatory flags
588 *
589 * Return: void
590 */
591#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(WITH_BACKPORTS)
592static void hdd_restore_reg_flags(struct wiphy *wiphy, uint32_t flags)
593{
594 wiphy->regulatory_flags = flags;
595}
596#else
597static void hdd_restore_reg_flags(struct wiphy *wiphy, uint32_t flags)
598{
599 wiphy->flags = flags;
600}
601#endif
602
603
604/**
605 * hdd_reg_notifier() - regulatory notifier
606 * @wiphy: wiphy
607 * @request: regulatory request
608 *
609 * Return: void
610 */
611void hdd_reg_notifier(struct wiphy *wiphy,
612 struct regulatory_request *request)
613{
614 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
Amar Singhale4f28ee2015-10-21 14:36:56 -0700615 bool vht80_allowed;
616 bool reset = false;
Amar Singhal604ba6cf2016-07-27 15:29:51 -0700617 enum dfs_region dfs_reg;
Amar Singhale4f28ee2015-10-21 14:36:56 -0700618
619 hdd_info("country: %c%c, initiator %d, dfs_region: %d",
620 request->alpha2[0],
621 request->alpha2[1],
622 request->initiator,
623 request->dfs_region);
624
625 if (NULL == hdd_ctx) {
626 hdd_err("invalid hdd_ctx pointer");
627 return;
628 }
629
630 if (cds_is_driver_unloading() || cds_is_driver_recovering()) {
631 hdd_err("%s: unloading or ssr in progress, ignore",
632 __func__);
633 return;
634 }
635
Amar Singhal604ba6cf2016-07-27 15:29:51 -0700636 if (('K' == request->alpha2[0]) &&
637 ('R' == request->alpha2[1]))
638 request->dfs_region = DFS_KR_REGION;
639
640 if (('C' == request->alpha2[0]) &&
641 ('N' == request->alpha2[1]))
642 request->dfs_region = DFS_CN_REGION;
643
Amar Singhale4f28ee2015-10-21 14:36:56 -0700644 /* first check if this callback is in response to the driver callback */
645
646 switch (request->initiator) {
647 case NL80211_REGDOM_SET_BY_DRIVER:
648 case NL80211_REGDOM_SET_BY_CORE:
649 case NL80211_REGDOM_SET_BY_USER:
650
651 if ((false == init_by_driver) &&
652 (false == init_by_reg_core)) {
653
654 if (NL80211_REGDOM_SET_BY_CORE == request->initiator)
655 return;
656 init_by_reg_core = true;
657 }
658
659 if ((NL80211_REGDOM_SET_BY_DRIVER == request->initiator) &&
660 (true == init_by_driver)) {
661
662 /*
663 * restore the driver regulatory flags since
664 * regulatory_hint may have
665 * changed them
666 */
667 hdd_restore_reg_flags(wiphy, hdd_ctx->reg.reg_flags);
668 }
669
670 if (NL80211_REGDOM_SET_BY_CORE == request->initiator) {
671 hdd_ctx->reg.cc_src = SOURCE_CORE;
672 if (is_wiphy_custom_regulatory(wiphy))
673 reset = true;
674 } else if (NL80211_REGDOM_SET_BY_DRIVER == request->initiator)
675 hdd_ctx->reg.cc_src = SOURCE_DRIVER;
676 else {
677 hdd_ctx->reg.cc_src = SOURCE_USERSPACE;
678 hdd_restore_custom_reg_settings(wiphy,
679 request->alpha2,
680 &reset);
681 }
682
683 hdd_ctx->reg.alpha2[0] = request->alpha2[0];
684 hdd_ctx->reg.alpha2[1] = request->alpha2[1];
685
686 hdd_update_regulatory_info(hdd_ctx);
687
688 vht80_allowed = hdd_ctx->isVHT80Allowed;
689
690 hdd_process_regulatory_data(hdd_ctx, wiphy, reset);
691
692 if (hdd_ctx->isVHT80Allowed != vht80_allowed)
693 hdd_checkandupdate_phymode(hdd_ctx);
694
695 if (NL80211_REGDOM_SET_BY_DRIVER == request->initiator)
696 complete(&hdd_ctx->reg_init);
697
698 sme_generic_change_country_code(hdd_ctx->hHal,
699 hdd_ctx->reg.alpha2);
700
701 cds_fill_and_send_ctl_to_fw(&hdd_ctx->reg);
702
703 hdd_set_dfs_region(hdd_ctx, request->dfs_region);
704
705 cds_get_dfs_region(&dfs_reg);
706 cds_set_wma_dfs_region(dfs_reg);
707 break;
708
709 default:
710 break;
711 }
712}