aboutsummaryrefslogtreecommitdiffstats
path: root/net/wireless/reg.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/wireless/reg.c')
-rw-r--r--net/wireless/reg.c1142
1 files changed, 514 insertions, 628 deletions
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 82c4fc7c994c..98532c00242d 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -48,7 +48,6 @@
48#include <linux/export.h> 48#include <linux/export.h>
49#include <linux/slab.h> 49#include <linux/slab.h>
50#include <linux/list.h> 50#include <linux/list.h>
51#include <linux/random.h>
52#include <linux/ctype.h> 51#include <linux/ctype.h>
53#include <linux/nl80211.h> 52#include <linux/nl80211.h>
54#include <linux/platform_device.h> 53#include <linux/platform_device.h>
@@ -66,6 +65,13 @@
66#define REG_DBG_PRINT(args...) 65#define REG_DBG_PRINT(args...)
67#endif 66#endif
68 67
68enum reg_request_treatment {
69 REG_REQ_OK,
70 REG_REQ_IGNORE,
71 REG_REQ_INTERSECT,
72 REG_REQ_ALREADY_SET,
73};
74
69static struct regulatory_request core_request_world = { 75static struct regulatory_request core_request_world = {
70 .initiator = NL80211_REGDOM_SET_BY_CORE, 76 .initiator = NL80211_REGDOM_SET_BY_CORE,
71 .alpha2[0] = '0', 77 .alpha2[0] = '0',
@@ -76,7 +82,8 @@ static struct regulatory_request core_request_world = {
76}; 82};
77 83
78/* Receipt of information from last regulatory request */ 84/* Receipt of information from last regulatory request */
79static struct regulatory_request *last_request = &core_request_world; 85static struct regulatory_request __rcu *last_request =
86 (void __rcu *)&core_request_world;
80 87
81/* To trigger userspace events */ 88/* To trigger userspace events */
82static struct platform_device *reg_pdev; 89static struct platform_device *reg_pdev;
@@ -88,16 +95,16 @@ static struct device_type reg_device_type = {
88/* 95/*
89 * Central wireless core regulatory domains, we only need two, 96 * Central wireless core regulatory domains, we only need two,
90 * the current one and a world regulatory domain in case we have no 97 * the current one and a world regulatory domain in case we have no
91 * information to give us an alpha2 98 * information to give us an alpha2.
92 */ 99 */
93const struct ieee80211_regdomain *cfg80211_regdomain; 100const struct ieee80211_regdomain __rcu *cfg80211_regdomain;
94 101
95/* 102/*
96 * Protects static reg.c components: 103 * Protects static reg.c components:
97 * - cfg80211_world_regdom 104 * - cfg80211_regdomain (if not used with RCU)
98 * - cfg80211_regdom 105 * - cfg80211_world_regdom
99 * - last_request 106 * - last_request (if not used with RCU)
100 * - reg_num_devs_support_basehint 107 * - reg_num_devs_support_basehint
101 */ 108 */
102static DEFINE_MUTEX(reg_mutex); 109static DEFINE_MUTEX(reg_mutex);
103 110
@@ -112,6 +119,31 @@ static inline void assert_reg_lock(void)
112 lockdep_assert_held(&reg_mutex); 119 lockdep_assert_held(&reg_mutex);
113} 120}
114 121
122static const struct ieee80211_regdomain *get_cfg80211_regdom(void)
123{
124 return rcu_dereference_protected(cfg80211_regdomain,
125 lockdep_is_held(&reg_mutex));
126}
127
128static const struct ieee80211_regdomain *get_wiphy_regdom(struct wiphy *wiphy)
129{
130 return rcu_dereference_protected(wiphy->regd,
131 lockdep_is_held(&reg_mutex));
132}
133
134static void rcu_free_regdom(const struct ieee80211_regdomain *r)
135{
136 if (!r)
137 return;
138 kfree_rcu((struct ieee80211_regdomain *)r, rcu_head);
139}
140
141static struct regulatory_request *get_last_request(void)
142{
143 return rcu_dereference_check(last_request,
144 lockdep_is_held(&reg_mutex));
145}
146
115/* Used to queue up regulatory hints */ 147/* Used to queue up regulatory hints */
116static LIST_HEAD(reg_requests_list); 148static LIST_HEAD(reg_requests_list);
117static spinlock_t reg_requests_lock; 149static spinlock_t reg_requests_lock;
@@ -177,28 +209,37 @@ static char user_alpha2[2];
177module_param(ieee80211_regdom, charp, 0444); 209module_param(ieee80211_regdom, charp, 0444);
178MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code"); 210MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
179 211
180static void reset_regdomains(bool full_reset) 212static void reset_regdomains(bool full_reset,
213 const struct ieee80211_regdomain *new_regdom)
181{ 214{
215 const struct ieee80211_regdomain *r;
216 struct regulatory_request *lr;
217
218 assert_reg_lock();
219
220 r = get_cfg80211_regdom();
221
182 /* avoid freeing static information or freeing something twice */ 222 /* avoid freeing static information or freeing something twice */
183 if (cfg80211_regdomain == cfg80211_world_regdom) 223 if (r == cfg80211_world_regdom)
184 cfg80211_regdomain = NULL; 224 r = NULL;
185 if (cfg80211_world_regdom == &world_regdom) 225 if (cfg80211_world_regdom == &world_regdom)
186 cfg80211_world_regdom = NULL; 226 cfg80211_world_regdom = NULL;
187 if (cfg80211_regdomain == &world_regdom) 227 if (r == &world_regdom)
188 cfg80211_regdomain = NULL; 228 r = NULL;
189 229
190 kfree(cfg80211_regdomain); 230 rcu_free_regdom(r);
191 kfree(cfg80211_world_regdom); 231 rcu_free_regdom(cfg80211_world_regdom);
192 232
193 cfg80211_world_regdom = &world_regdom; 233 cfg80211_world_regdom = &world_regdom;
194 cfg80211_regdomain = NULL; 234 rcu_assign_pointer(cfg80211_regdomain, new_regdom);
195 235
196 if (!full_reset) 236 if (!full_reset)
197 return; 237 return;
198 238
199 if (last_request != &core_request_world) 239 lr = get_last_request();
200 kfree(last_request); 240 if (lr != &core_request_world && lr)
201 last_request = &core_request_world; 241 kfree_rcu(lr, rcu_head);
242 rcu_assign_pointer(last_request, &core_request_world);
202} 243}
203 244
204/* 245/*
@@ -207,30 +248,29 @@ static void reset_regdomains(bool full_reset)
207 */ 248 */
208static void update_world_regdomain(const struct ieee80211_regdomain *rd) 249static void update_world_regdomain(const struct ieee80211_regdomain *rd)
209{ 250{
210 BUG_ON(!last_request); 251 struct regulatory_request *lr;
252
253 lr = get_last_request();
254
255 WARN_ON(!lr);
211 256
212 reset_regdomains(false); 257 reset_regdomains(false, rd);
213 258
214 cfg80211_world_regdom = rd; 259 cfg80211_world_regdom = rd;
215 cfg80211_regdomain = rd;
216} 260}
217 261
218bool is_world_regdom(const char *alpha2) 262bool is_world_regdom(const char *alpha2)
219{ 263{
220 if (!alpha2) 264 if (!alpha2)
221 return false; 265 return false;
222 if (alpha2[0] == '0' && alpha2[1] == '0') 266 return alpha2[0] == '0' && alpha2[1] == '0';
223 return true;
224 return false;
225} 267}
226 268
227static bool is_alpha2_set(const char *alpha2) 269static bool is_alpha2_set(const char *alpha2)
228{ 270{
229 if (!alpha2) 271 if (!alpha2)
230 return false; 272 return false;
231 if (alpha2[0] != 0 && alpha2[1] != 0) 273 return alpha2[0] && alpha2[1];
232 return true;
233 return false;
234} 274}
235 275
236static bool is_unknown_alpha2(const char *alpha2) 276static bool is_unknown_alpha2(const char *alpha2)
@@ -241,9 +281,7 @@ static bool is_unknown_alpha2(const char *alpha2)
241 * Special case where regulatory domain was built by driver 281 * Special case where regulatory domain was built by driver
242 * but a specific alpha2 cannot be determined 282 * but a specific alpha2 cannot be determined
243 */ 283 */
244 if (alpha2[0] == '9' && alpha2[1] == '9') 284 return alpha2[0] == '9' && alpha2[1] == '9';
245 return true;
246 return false;
247} 285}
248 286
249static bool is_intersected_alpha2(const char *alpha2) 287static bool is_intersected_alpha2(const char *alpha2)
@@ -255,39 +293,30 @@ static bool is_intersected_alpha2(const char *alpha2)
255 * result of an intersection between two regulatory domain 293 * result of an intersection between two regulatory domain
256 * structures 294 * structures
257 */ 295 */
258 if (alpha2[0] == '9' && alpha2[1] == '8') 296 return alpha2[0] == '9' && alpha2[1] == '8';
259 return true;
260 return false;
261} 297}
262 298
263static bool is_an_alpha2(const char *alpha2) 299static bool is_an_alpha2(const char *alpha2)
264{ 300{
265 if (!alpha2) 301 if (!alpha2)
266 return false; 302 return false;
267 if (isalpha(alpha2[0]) && isalpha(alpha2[1])) 303 return isalpha(alpha2[0]) && isalpha(alpha2[1]);
268 return true;
269 return false;
270} 304}
271 305
272static bool alpha2_equal(const char *alpha2_x, const char *alpha2_y) 306static bool alpha2_equal(const char *alpha2_x, const char *alpha2_y)
273{ 307{
274 if (!alpha2_x || !alpha2_y) 308 if (!alpha2_x || !alpha2_y)
275 return false; 309 return false;
276 if (alpha2_x[0] == alpha2_y[0] && 310 return alpha2_x[0] == alpha2_y[0] && alpha2_x[1] == alpha2_y[1];
277 alpha2_x[1] == alpha2_y[1])
278 return true;
279 return false;
280} 311}
281 312
282static bool regdom_changes(const char *alpha2) 313static bool regdom_changes(const char *alpha2)
283{ 314{
284 assert_cfg80211_lock(); 315 const struct ieee80211_regdomain *r = get_cfg80211_regdom();
285 316
286 if (!cfg80211_regdomain) 317 if (!r)
287 return true; 318 return true;
288 if (alpha2_equal(cfg80211_regdomain->alpha2, alpha2)) 319 return !alpha2_equal(r->alpha2, alpha2);
289 return false;
290 return true;
291} 320}
292 321
293/* 322/*
@@ -301,38 +330,36 @@ static bool is_user_regdom_saved(void)
301 return false; 330 return false;
302 331
303 /* This would indicate a mistake on the design */ 332 /* This would indicate a mistake on the design */
304 if (WARN((!is_world_regdom(user_alpha2) && 333 if (WARN(!is_world_regdom(user_alpha2) && !is_an_alpha2(user_alpha2),
305 !is_an_alpha2(user_alpha2)),
306 "Unexpected user alpha2: %c%c\n", 334 "Unexpected user alpha2: %c%c\n",
307 user_alpha2[0], 335 user_alpha2[0], user_alpha2[1]))
308 user_alpha2[1]))
309 return false; 336 return false;
310 337
311 return true; 338 return true;
312} 339}
313 340
314static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd, 341static const struct ieee80211_regdomain *
315 const struct ieee80211_regdomain *src_regd) 342reg_copy_regd(const struct ieee80211_regdomain *src_regd)
316{ 343{
317 struct ieee80211_regdomain *regd; 344 struct ieee80211_regdomain *regd;
318 int size_of_regd = 0; 345 int size_of_regd;
319 unsigned int i; 346 unsigned int i;
320 347
321 size_of_regd = sizeof(struct ieee80211_regdomain) + 348 size_of_regd =
322 ((src_regd->n_reg_rules + 1) * sizeof(struct ieee80211_reg_rule)); 349 sizeof(struct ieee80211_regdomain) +
350 src_regd->n_reg_rules * sizeof(struct ieee80211_reg_rule);
323 351
324 regd = kzalloc(size_of_regd, GFP_KERNEL); 352 regd = kzalloc(size_of_regd, GFP_KERNEL);
325 if (!regd) 353 if (!regd)
326 return -ENOMEM; 354 return ERR_PTR(-ENOMEM);
327 355
328 memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain)); 356 memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain));
329 357
330 for (i = 0; i < src_regd->n_reg_rules; i++) 358 for (i = 0; i < src_regd->n_reg_rules; i++)
331 memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i], 359 memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i],
332 sizeof(struct ieee80211_reg_rule)); 360 sizeof(struct ieee80211_reg_rule));
333 361
334 *dst_regd = regd; 362 return regd;
335 return 0;
336} 363}
337 364
338#ifdef CONFIG_CFG80211_INTERNAL_REGDB 365#ifdef CONFIG_CFG80211_INTERNAL_REGDB
@@ -347,9 +374,8 @@ static DEFINE_MUTEX(reg_regdb_search_mutex);
347static void reg_regdb_search(struct work_struct *work) 374static void reg_regdb_search(struct work_struct *work)
348{ 375{
349 struct reg_regdb_search_request *request; 376 struct reg_regdb_search_request *request;
350 const struct ieee80211_regdomain *curdom, *regdom; 377 const struct ieee80211_regdomain *curdom, *regdom = NULL;
351 int i, r; 378 int i;
352 bool set_reg = false;
353 379
354 mutex_lock(&cfg80211_mutex); 380 mutex_lock(&cfg80211_mutex);
355 381
@@ -360,14 +386,11 @@ static void reg_regdb_search(struct work_struct *work)
360 list); 386 list);
361 list_del(&request->list); 387 list_del(&request->list);
362 388
363 for (i=0; i<reg_regdb_size; i++) { 389 for (i = 0; i < reg_regdb_size; i++) {
364 curdom = reg_regdb[i]; 390 curdom = reg_regdb[i];
365 391
366 if (!memcmp(request->alpha2, curdom->alpha2, 2)) { 392 if (alpha2_equal(request->alpha2, curdom->alpha2)) {
367 r = reg_copy_regd(&regdom, curdom); 393 regdom = reg_copy_regd(curdom);
368 if (r)
369 break;
370 set_reg = true;
371 break; 394 break;
372 } 395 }
373 } 396 }
@@ -376,7 +399,7 @@ static void reg_regdb_search(struct work_struct *work)
376 } 399 }
377 mutex_unlock(&reg_regdb_search_mutex); 400 mutex_unlock(&reg_regdb_search_mutex);
378 401
379 if (set_reg) 402 if (!IS_ERR_OR_NULL(regdom))
380 set_regdom(regdom); 403 set_regdom(regdom);
381 404
382 mutex_unlock(&cfg80211_mutex); 405 mutex_unlock(&cfg80211_mutex);
@@ -434,15 +457,14 @@ static int call_crda(const char *alpha2)
434 return kobject_uevent(&reg_pdev->dev.kobj, KOBJ_CHANGE); 457 return kobject_uevent(&reg_pdev->dev.kobj, KOBJ_CHANGE);
435} 458}
436 459
437/* Used by nl80211 before kmalloc'ing our regulatory domain */ 460static bool reg_is_valid_request(const char *alpha2)
438bool reg_is_valid_request(const char *alpha2)
439{ 461{
440 assert_cfg80211_lock(); 462 struct regulatory_request *lr = get_last_request();
441 463
442 if (!last_request) 464 if (!lr || lr->processed)
443 return false; 465 return false;
444 466
445 return alpha2_equal(last_request->alpha2, alpha2); 467 return alpha2_equal(lr->alpha2, alpha2);
446} 468}
447 469
448/* Sanity check on a regulatory rule */ 470/* Sanity check on a regulatory rule */
@@ -460,7 +482,7 @@ static bool is_valid_reg_rule(const struct ieee80211_reg_rule *rule)
460 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; 482 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
461 483
462 if (freq_range->end_freq_khz <= freq_range->start_freq_khz || 484 if (freq_range->end_freq_khz <= freq_range->start_freq_khz ||
463 freq_range->max_bandwidth_khz > freq_diff) 485 freq_range->max_bandwidth_khz > freq_diff)
464 return false; 486 return false;
465 487
466 return true; 488 return true;
@@ -487,8 +509,7 @@ static bool is_valid_rd(const struct ieee80211_regdomain *rd)
487} 509}
488 510
489static bool reg_does_bw_fit(const struct ieee80211_freq_range *freq_range, 511static bool reg_does_bw_fit(const struct ieee80211_freq_range *freq_range,
490 u32 center_freq_khz, 512 u32 center_freq_khz, u32 bw_khz)
491 u32 bw_khz)
492{ 513{
493 u32 start_freq_khz, end_freq_khz; 514 u32 start_freq_khz, end_freq_khz;
494 515
@@ -518,7 +539,7 @@ static bool reg_does_bw_fit(const struct ieee80211_freq_range *freq_range,
518 * regulatory rule support for other "bands". 539 * regulatory rule support for other "bands".
519 **/ 540 **/
520static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range, 541static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range,
521 u32 freq_khz) 542 u32 freq_khz)
522{ 543{
523#define ONE_GHZ_IN_KHZ 1000000 544#define ONE_GHZ_IN_KHZ 1000000
524 /* 545 /*
@@ -540,10 +561,9 @@ static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range,
540 * Helper for regdom_intersect(), this does the real 561 * Helper for regdom_intersect(), this does the real
541 * mathematical intersection fun 562 * mathematical intersection fun
542 */ 563 */
543static int reg_rules_intersect( 564static int reg_rules_intersect(const struct ieee80211_reg_rule *rule1,
544 const struct ieee80211_reg_rule *rule1, 565 const struct ieee80211_reg_rule *rule2,
545 const struct ieee80211_reg_rule *rule2, 566 struct ieee80211_reg_rule *intersected_rule)
546 struct ieee80211_reg_rule *intersected_rule)
547{ 567{
548 const struct ieee80211_freq_range *freq_range1, *freq_range2; 568 const struct ieee80211_freq_range *freq_range1, *freq_range2;
549 struct ieee80211_freq_range *freq_range; 569 struct ieee80211_freq_range *freq_range;
@@ -560,11 +580,11 @@ static int reg_rules_intersect(
560 power_rule = &intersected_rule->power_rule; 580 power_rule = &intersected_rule->power_rule;
561 581
562 freq_range->start_freq_khz = max(freq_range1->start_freq_khz, 582 freq_range->start_freq_khz = max(freq_range1->start_freq_khz,
563 freq_range2->start_freq_khz); 583 freq_range2->start_freq_khz);
564 freq_range->end_freq_khz = min(freq_range1->end_freq_khz, 584 freq_range->end_freq_khz = min(freq_range1->end_freq_khz,
565 freq_range2->end_freq_khz); 585 freq_range2->end_freq_khz);
566 freq_range->max_bandwidth_khz = min(freq_range1->max_bandwidth_khz, 586 freq_range->max_bandwidth_khz = min(freq_range1->max_bandwidth_khz,
567 freq_range2->max_bandwidth_khz); 587 freq_range2->max_bandwidth_khz);
568 588
569 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; 589 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
570 if (freq_range->max_bandwidth_khz > freq_diff) 590 if (freq_range->max_bandwidth_khz > freq_diff)
@@ -575,7 +595,7 @@ static int reg_rules_intersect(
575 power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain, 595 power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain,
576 power_rule2->max_antenna_gain); 596 power_rule2->max_antenna_gain);
577 597
578 intersected_rule->flags = (rule1->flags | rule2->flags); 598 intersected_rule->flags = rule1->flags | rule2->flags;
579 599
580 if (!is_valid_reg_rule(intersected_rule)) 600 if (!is_valid_reg_rule(intersected_rule))
581 return -EINVAL; 601 return -EINVAL;
@@ -596,9 +616,9 @@ static int reg_rules_intersect(
596 * resulting intersection of rules between rd1 and rd2. We will 616 * resulting intersection of rules between rd1 and rd2. We will
597 * kzalloc() this structure for you. 617 * kzalloc() this structure for you.
598 */ 618 */
599static struct ieee80211_regdomain *regdom_intersect( 619static struct ieee80211_regdomain *
600 const struct ieee80211_regdomain *rd1, 620regdom_intersect(const struct ieee80211_regdomain *rd1,
601 const struct ieee80211_regdomain *rd2) 621 const struct ieee80211_regdomain *rd2)
602{ 622{
603 int r, size_of_regd; 623 int r, size_of_regd;
604 unsigned int x, y; 624 unsigned int x, y;
@@ -607,12 +627,7 @@ static struct ieee80211_regdomain *regdom_intersect(
607 struct ieee80211_reg_rule *intersected_rule; 627 struct ieee80211_reg_rule *intersected_rule;
608 struct ieee80211_regdomain *rd; 628 struct ieee80211_regdomain *rd;
609 /* This is just a dummy holder to help us count */ 629 /* This is just a dummy holder to help us count */
610 struct ieee80211_reg_rule irule; 630 struct ieee80211_reg_rule dummy_rule;
611
612 /* Uses the stack temporarily for counter arithmetic */
613 intersected_rule = &irule;
614
615 memset(intersected_rule, 0, sizeof(struct ieee80211_reg_rule));
616 631
617 if (!rd1 || !rd2) 632 if (!rd1 || !rd2)
618 return NULL; 633 return NULL;
@@ -629,11 +644,8 @@ static struct ieee80211_regdomain *regdom_intersect(
629 rule1 = &rd1->reg_rules[x]; 644 rule1 = &rd1->reg_rules[x];
630 for (y = 0; y < rd2->n_reg_rules; y++) { 645 for (y = 0; y < rd2->n_reg_rules; y++) {
631 rule2 = &rd2->reg_rules[y]; 646 rule2 = &rd2->reg_rules[y];
632 if (!reg_rules_intersect(rule1, rule2, 647 if (!reg_rules_intersect(rule1, rule2, &dummy_rule))
633 intersected_rule))
634 num_rules++; 648 num_rules++;
635 memset(intersected_rule, 0,
636 sizeof(struct ieee80211_reg_rule));
637 } 649 }
638 } 650 }
639 651
@@ -641,15 +653,15 @@ static struct ieee80211_regdomain *regdom_intersect(
641 return NULL; 653 return NULL;
642 654
643 size_of_regd = sizeof(struct ieee80211_regdomain) + 655 size_of_regd = sizeof(struct ieee80211_regdomain) +
644 ((num_rules + 1) * sizeof(struct ieee80211_reg_rule)); 656 num_rules * sizeof(struct ieee80211_reg_rule);
645 657
646 rd = kzalloc(size_of_regd, GFP_KERNEL); 658 rd = kzalloc(size_of_regd, GFP_KERNEL);
647 if (!rd) 659 if (!rd)
648 return NULL; 660 return NULL;
649 661
650 for (x = 0; x < rd1->n_reg_rules; x++) { 662 for (x = 0; x < rd1->n_reg_rules && rule_idx < num_rules; x++) {
651 rule1 = &rd1->reg_rules[x]; 663 rule1 = &rd1->reg_rules[x];
652 for (y = 0; y < rd2->n_reg_rules; y++) { 664 for (y = 0; y < rd2->n_reg_rules && rule_idx < num_rules; y++) {
653 rule2 = &rd2->reg_rules[y]; 665 rule2 = &rd2->reg_rules[y];
654 /* 666 /*
655 * This time around instead of using the stack lets 667 * This time around instead of using the stack lets
@@ -657,8 +669,7 @@ static struct ieee80211_regdomain *regdom_intersect(
657 * a memcpy() 669 * a memcpy()
658 */ 670 */
659 intersected_rule = &rd->reg_rules[rule_idx]; 671 intersected_rule = &rd->reg_rules[rule_idx];
660 r = reg_rules_intersect(rule1, rule2, 672 r = reg_rules_intersect(rule1, rule2, intersected_rule);
661 intersected_rule);
662 /* 673 /*
663 * No need to memset here the intersected rule here as 674 * No need to memset here the intersected rule here as
664 * we're not using the stack anymore 675 * we're not using the stack anymore
@@ -699,34 +710,16 @@ static u32 map_regdom_flags(u32 rd_flags)
699 return channel_flags; 710 return channel_flags;
700} 711}
701 712
702static int freq_reg_info_regd(struct wiphy *wiphy, 713static const struct ieee80211_reg_rule *
703 u32 center_freq, 714freq_reg_info_regd(struct wiphy *wiphy, u32 center_freq,
704 u32 desired_bw_khz, 715 const struct ieee80211_regdomain *regd)
705 const struct ieee80211_reg_rule **reg_rule,
706 const struct ieee80211_regdomain *custom_regd)
707{ 716{
708 int i; 717 int i;
709 bool band_rule_found = false; 718 bool band_rule_found = false;
710 const struct ieee80211_regdomain *regd;
711 bool bw_fits = false; 719 bool bw_fits = false;
712 720
713 if (!desired_bw_khz)
714 desired_bw_khz = MHZ_TO_KHZ(20);
715
716 regd = custom_regd ? custom_regd : cfg80211_regdomain;
717
718 /*
719 * Follow the driver's regulatory domain, if present, unless a country
720 * IE has been processed or a user wants to help complaince further
721 */
722 if (!custom_regd &&
723 last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
724 last_request->initiator != NL80211_REGDOM_SET_BY_USER &&
725 wiphy->regd)
726 regd = wiphy->regd;
727
728 if (!regd) 721 if (!regd)
729 return -EINVAL; 722 return ERR_PTR(-EINVAL);
730 723
731 for (i = 0; i < regd->n_reg_rules; i++) { 724 for (i = 0; i < regd->n_reg_rules; i++) {
732 const struct ieee80211_reg_rule *rr; 725 const struct ieee80211_reg_rule *rr;
@@ -743,33 +736,36 @@ static int freq_reg_info_regd(struct wiphy *wiphy,
743 if (!band_rule_found) 736 if (!band_rule_found)
744 band_rule_found = freq_in_rule_band(fr, center_freq); 737 band_rule_found = freq_in_rule_band(fr, center_freq);
745 738
746 bw_fits = reg_does_bw_fit(fr, 739 bw_fits = reg_does_bw_fit(fr, center_freq, MHZ_TO_KHZ(20));
747 center_freq,
748 desired_bw_khz);
749 740
750 if (band_rule_found && bw_fits) { 741 if (band_rule_found && bw_fits)
751 *reg_rule = rr; 742 return rr;
752 return 0;
753 }
754 } 743 }
755 744
756 if (!band_rule_found) 745 if (!band_rule_found)
757 return -ERANGE; 746 return ERR_PTR(-ERANGE);
758 747
759 return -EINVAL; 748 return ERR_PTR(-EINVAL);
760} 749}
761 750
762int freq_reg_info(struct wiphy *wiphy, 751const struct ieee80211_reg_rule *freq_reg_info(struct wiphy *wiphy,
763 u32 center_freq, 752 u32 center_freq)
764 u32 desired_bw_khz,
765 const struct ieee80211_reg_rule **reg_rule)
766{ 753{
767 assert_cfg80211_lock(); 754 const struct ieee80211_regdomain *regd;
768 return freq_reg_info_regd(wiphy, 755 struct regulatory_request *lr = get_last_request();
769 center_freq, 756
770 desired_bw_khz, 757 /*
771 reg_rule, 758 * Follow the driver's regulatory domain, if present, unless a country
772 NULL); 759 * IE has been processed or a user wants to help complaince further
760 */
761 if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
762 lr->initiator != NL80211_REGDOM_SET_BY_USER &&
763 wiphy->regd)
764 regd = get_wiphy_regdom(wiphy);
765 else
766 regd = get_cfg80211_regdom();
767
768 return freq_reg_info_regd(wiphy, center_freq, regd);
773} 769}
774EXPORT_SYMBOL(freq_reg_info); 770EXPORT_SYMBOL(freq_reg_info);
775 771
@@ -792,7 +788,6 @@ static const char *reg_initiator_name(enum nl80211_reg_initiator initiator)
792} 788}
793 789
794static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan, 790static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan,
795 u32 desired_bw_khz,
796 const struct ieee80211_reg_rule *reg_rule) 791 const struct ieee80211_reg_rule *reg_rule)
797{ 792{
798 const struct ieee80211_power_rule *power_rule; 793 const struct ieee80211_power_rule *power_rule;
@@ -807,21 +802,16 @@ static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan,
807 else 802 else
808 snprintf(max_antenna_gain, 32, "%d", power_rule->max_antenna_gain); 803 snprintf(max_antenna_gain, 32, "%d", power_rule->max_antenna_gain);
809 804
810 REG_DBG_PRINT("Updating information on frequency %d MHz " 805 REG_DBG_PRINT("Updating information on frequency %d MHz with regulatory rule:\n",
811 "for a %d MHz width channel with regulatory rule:\n", 806 chan->center_freq);
812 chan->center_freq,
813 KHZ_TO_MHZ(desired_bw_khz));
814 807
815 REG_DBG_PRINT("%d KHz - %d KHz @ %d KHz), (%s mBi, %d mBm)\n", 808 REG_DBG_PRINT("%d KHz - %d KHz @ %d KHz), (%s mBi, %d mBm)\n",
816 freq_range->start_freq_khz, 809 freq_range->start_freq_khz, freq_range->end_freq_khz,
817 freq_range->end_freq_khz, 810 freq_range->max_bandwidth_khz, max_antenna_gain,
818 freq_range->max_bandwidth_khz,
819 max_antenna_gain,
820 power_rule->max_eirp); 811 power_rule->max_eirp);
821} 812}
822#else 813#else
823static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan, 814static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan,
824 u32 desired_bw_khz,
825 const struct ieee80211_reg_rule *reg_rule) 815 const struct ieee80211_reg_rule *reg_rule)
826{ 816{
827 return; 817 return;
@@ -831,43 +821,25 @@ static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan,
831/* 821/*
832 * Note that right now we assume the desired channel bandwidth 822 * Note that right now we assume the desired channel bandwidth
833 * is always 20 MHz for each individual channel (HT40 uses 20 MHz 823 * is always 20 MHz for each individual channel (HT40 uses 20 MHz
834 * per channel, the primary and the extension channel). To support 824 * per channel, the primary and the extension channel).
835 * smaller custom bandwidths such as 5 MHz or 10 MHz we'll need a
836 * new ieee80211_channel.target_bw and re run the regulatory check
837 * on the wiphy with the target_bw specified. Then we can simply use
838 * that below for the desired_bw_khz below.
839 */ 825 */
840static void handle_channel(struct wiphy *wiphy, 826static void handle_channel(struct wiphy *wiphy,
841 enum nl80211_reg_initiator initiator, 827 enum nl80211_reg_initiator initiator,
842 enum ieee80211_band band, 828 struct ieee80211_channel *chan)
843 unsigned int chan_idx)
844{ 829{
845 int r;
846 u32 flags, bw_flags = 0; 830 u32 flags, bw_flags = 0;
847 u32 desired_bw_khz = MHZ_TO_KHZ(20);
848 const struct ieee80211_reg_rule *reg_rule = NULL; 831 const struct ieee80211_reg_rule *reg_rule = NULL;
849 const struct ieee80211_power_rule *power_rule = NULL; 832 const struct ieee80211_power_rule *power_rule = NULL;
850 const struct ieee80211_freq_range *freq_range = NULL; 833 const struct ieee80211_freq_range *freq_range = NULL;
851 struct ieee80211_supported_band *sband;
852 struct ieee80211_channel *chan;
853 struct wiphy *request_wiphy = NULL; 834 struct wiphy *request_wiphy = NULL;
835 struct regulatory_request *lr = get_last_request();
854 836
855 assert_cfg80211_lock(); 837 request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx);
856
857 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
858
859 sband = wiphy->bands[band];
860 BUG_ON(chan_idx >= sband->n_channels);
861 chan = &sband->channels[chan_idx];
862 838
863 flags = chan->orig_flags; 839 flags = chan->orig_flags;
864 840
865 r = freq_reg_info(wiphy, 841 reg_rule = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
866 MHZ_TO_KHZ(chan->center_freq), 842 if (IS_ERR(reg_rule)) {
867 desired_bw_khz,
868 &reg_rule);
869
870 if (r) {
871 /* 843 /*
872 * We will disable all channels that do not match our 844 * We will disable all channels that do not match our
873 * received regulatory rule unless the hint is coming 845 * received regulatory rule unless the hint is coming
@@ -879,7 +851,7 @@ static void handle_channel(struct wiphy *wiphy,
879 * while 5 GHz is still supported. 851 * while 5 GHz is still supported.
880 */ 852 */
881 if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && 853 if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE &&
882 r == -ERANGE) 854 PTR_ERR(reg_rule) == -ERANGE)
883 return; 855 return;
884 856
885 REG_DBG_PRINT("Disabling freq %d MHz\n", chan->center_freq); 857 REG_DBG_PRINT("Disabling freq %d MHz\n", chan->center_freq);
@@ -887,15 +859,19 @@ static void handle_channel(struct wiphy *wiphy,
887 return; 859 return;
888 } 860 }
889 861
890 chan_reg_rule_print_dbg(chan, desired_bw_khz, reg_rule); 862 chan_reg_rule_print_dbg(chan, reg_rule);
891 863
892 power_rule = &reg_rule->power_rule; 864 power_rule = &reg_rule->power_rule;
893 freq_range = &reg_rule->freq_range; 865 freq_range = &reg_rule->freq_range;
894 866
895 if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(40)) 867 if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(40))
896 bw_flags = IEEE80211_CHAN_NO_HT40; 868 bw_flags = IEEE80211_CHAN_NO_HT40;
869 if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(80))
870 bw_flags |= IEEE80211_CHAN_NO_80MHZ;
871 if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(160))
872 bw_flags |= IEEE80211_CHAN_NO_160MHZ;
897 873
898 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER && 874 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
899 request_wiphy && request_wiphy == wiphy && 875 request_wiphy && request_wiphy == wiphy &&
900 request_wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) { 876 request_wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) {
901 /* 877 /*
@@ -912,10 +888,14 @@ static void handle_channel(struct wiphy *wiphy,
912 return; 888 return;
913 } 889 }
914 890
891 chan->dfs_state = NL80211_DFS_USABLE;
892 chan->dfs_state_entered = jiffies;
893
915 chan->beacon_found = false; 894 chan->beacon_found = false;
916 chan->flags = flags | bw_flags | map_regdom_flags(reg_rule->flags); 895 chan->flags = flags | bw_flags | map_regdom_flags(reg_rule->flags);
917 chan->max_antenna_gain = min(chan->orig_mag, 896 chan->max_antenna_gain =
918 (int) MBI_TO_DBI(power_rule->max_antenna_gain)); 897 min_t(int, chan->orig_mag,
898 MBI_TO_DBI(power_rule->max_antenna_gain));
919 chan->max_reg_power = (int) MBM_TO_DBM(power_rule->max_eirp); 899 chan->max_reg_power = (int) MBM_TO_DBM(power_rule->max_eirp);
920 if (chan->orig_mpwr) { 900 if (chan->orig_mpwr) {
921 /* 901 /*
@@ -935,68 +915,65 @@ static void handle_channel(struct wiphy *wiphy,
935} 915}
936 916
937static void handle_band(struct wiphy *wiphy, 917static void handle_band(struct wiphy *wiphy,
938 enum ieee80211_band band, 918 enum nl80211_reg_initiator initiator,
939 enum nl80211_reg_initiator initiator) 919 struct ieee80211_supported_band *sband)
940{ 920{
941 unsigned int i; 921 unsigned int i;
942 struct ieee80211_supported_band *sband;
943 922
944 BUG_ON(!wiphy->bands[band]); 923 if (!sband)
945 sband = wiphy->bands[band]; 924 return;
946 925
947 for (i = 0; i < sband->n_channels; i++) 926 for (i = 0; i < sband->n_channels; i++)
948 handle_channel(wiphy, initiator, band, i); 927 handle_channel(wiphy, initiator, &sband->channels[i]);
949} 928}
950 929
951static bool reg_request_cell_base(struct regulatory_request *request) 930static bool reg_request_cell_base(struct regulatory_request *request)
952{ 931{
953 if (request->initiator != NL80211_REGDOM_SET_BY_USER) 932 if (request->initiator != NL80211_REGDOM_SET_BY_USER)
954 return false; 933 return false;
955 if (request->user_reg_hint_type != NL80211_USER_REG_HINT_CELL_BASE) 934 return request->user_reg_hint_type == NL80211_USER_REG_HINT_CELL_BASE;
956 return false;
957 return true;
958} 935}
959 936
960bool reg_last_request_cell_base(void) 937bool reg_last_request_cell_base(void)
961{ 938{
962 bool val; 939 bool val;
963 assert_cfg80211_lock();
964 940
965 mutex_lock(&reg_mutex); 941 mutex_lock(&reg_mutex);
966 val = reg_request_cell_base(last_request); 942 val = reg_request_cell_base(get_last_request());
967 mutex_unlock(&reg_mutex); 943 mutex_unlock(&reg_mutex);
944
968 return val; 945 return val;
969} 946}
970 947
971#ifdef CONFIG_CFG80211_CERTIFICATION_ONUS 948#ifdef CONFIG_CFG80211_CERTIFICATION_ONUS
972
973/* Core specific check */ 949/* Core specific check */
974static int reg_ignore_cell_hint(struct regulatory_request *pending_request) 950static enum reg_request_treatment
951reg_ignore_cell_hint(struct regulatory_request *pending_request)
975{ 952{
953 struct regulatory_request *lr = get_last_request();
954
976 if (!reg_num_devs_support_basehint) 955 if (!reg_num_devs_support_basehint)
977 return -EOPNOTSUPP; 956 return REG_REQ_IGNORE;
978 957
979 if (reg_request_cell_base(last_request)) { 958 if (reg_request_cell_base(lr) &&
980 if (!regdom_changes(pending_request->alpha2)) 959 !regdom_changes(pending_request->alpha2))
981 return -EALREADY; 960 return REG_REQ_ALREADY_SET;
982 return 0; 961
983 } 962 return REG_REQ_OK;
984 return 0;
985} 963}
986 964
987/* Device specific check */ 965/* Device specific check */
988static bool reg_dev_ignore_cell_hint(struct wiphy *wiphy) 966static bool reg_dev_ignore_cell_hint(struct wiphy *wiphy)
989{ 967{
990 if (!(wiphy->features & NL80211_FEATURE_CELL_BASE_REG_HINTS)) 968 return !(wiphy->features & NL80211_FEATURE_CELL_BASE_REG_HINTS);
991 return true;
992 return false;
993} 969}
994#else 970#else
995static int reg_ignore_cell_hint(struct regulatory_request *pending_request) 971static int reg_ignore_cell_hint(struct regulatory_request *pending_request)
996{ 972{
997 return -EOPNOTSUPP; 973 return REG_REQ_IGNORE;
998} 974}
999static int reg_dev_ignore_cell_hint(struct wiphy *wiphy) 975
976static bool reg_dev_ignore_cell_hint(struct wiphy *wiphy)
1000{ 977{
1001 return true; 978 return true;
1002} 979}
@@ -1006,18 +983,17 @@ static int reg_dev_ignore_cell_hint(struct wiphy *wiphy)
1006static bool ignore_reg_update(struct wiphy *wiphy, 983static bool ignore_reg_update(struct wiphy *wiphy,
1007 enum nl80211_reg_initiator initiator) 984 enum nl80211_reg_initiator initiator)
1008{ 985{
1009 if (!last_request) { 986 struct regulatory_request *lr = get_last_request();
1010 REG_DBG_PRINT("Ignoring regulatory request %s since " 987
1011 "last_request is not set\n", 988 if (!lr) {
989 REG_DBG_PRINT("Ignoring regulatory request %s since last_request is not set\n",
1012 reg_initiator_name(initiator)); 990 reg_initiator_name(initiator));
1013 return true; 991 return true;
1014 } 992 }
1015 993
1016 if (initiator == NL80211_REGDOM_SET_BY_CORE && 994 if (initiator == NL80211_REGDOM_SET_BY_CORE &&
1017 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY) { 995 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY) {
1018 REG_DBG_PRINT("Ignoring regulatory request %s " 996 REG_DBG_PRINT("Ignoring regulatory request %s since the driver uses its own custom regulatory domain\n",
1019 "since the driver uses its own custom "
1020 "regulatory domain\n",
1021 reg_initiator_name(initiator)); 997 reg_initiator_name(initiator));
1022 return true; 998 return true;
1023 } 999 }
@@ -1028,22 +1004,35 @@ static bool ignore_reg_update(struct wiphy *wiphy,
1028 */ 1004 */
1029 if (wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY && !wiphy->regd && 1005 if (wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY && !wiphy->regd &&
1030 initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && 1006 initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
1031 !is_world_regdom(last_request->alpha2)) { 1007 !is_world_regdom(lr->alpha2)) {
1032 REG_DBG_PRINT("Ignoring regulatory request %s " 1008 REG_DBG_PRINT("Ignoring regulatory request %s since the driver requires its own regulatory domain to be set first\n",
1033 "since the driver requires its own regulatory "
1034 "domain to be set first\n",
1035 reg_initiator_name(initiator)); 1009 reg_initiator_name(initiator));
1036 return true; 1010 return true;
1037 } 1011 }
1038 1012
1039 if (reg_request_cell_base(last_request)) 1013 if (reg_request_cell_base(lr))
1040 return reg_dev_ignore_cell_hint(wiphy); 1014 return reg_dev_ignore_cell_hint(wiphy);
1041 1015
1042 return false; 1016 return false;
1043} 1017}
1044 1018
1045static void handle_reg_beacon(struct wiphy *wiphy, 1019static bool reg_is_world_roaming(struct wiphy *wiphy)
1046 unsigned int chan_idx, 1020{
1021 const struct ieee80211_regdomain *cr = get_cfg80211_regdom();
1022 const struct ieee80211_regdomain *wr = get_wiphy_regdom(wiphy);
1023 struct regulatory_request *lr = get_last_request();
1024
1025 if (is_world_regdom(cr->alpha2) || (wr && is_world_regdom(wr->alpha2)))
1026 return true;
1027
1028 if (lr && lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
1029 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)
1030 return true;
1031
1032 return false;
1033}
1034
1035static void handle_reg_beacon(struct wiphy *wiphy, unsigned int chan_idx,
1047 struct reg_beacon *reg_beacon) 1036 struct reg_beacon *reg_beacon)
1048{ 1037{
1049 struct ieee80211_supported_band *sband; 1038 struct ieee80211_supported_band *sband;
@@ -1051,8 +1040,6 @@ static void handle_reg_beacon(struct wiphy *wiphy,
1051 bool channel_changed = false; 1040 bool channel_changed = false;
1052 struct ieee80211_channel chan_before; 1041 struct ieee80211_channel chan_before;
1053 1042
1054 assert_cfg80211_lock();
1055
1056 sband = wiphy->bands[reg_beacon->chan.band]; 1043 sband = wiphy->bands[reg_beacon->chan.band];
1057 chan = &sband->channels[chan_idx]; 1044 chan = &sband->channels[chan_idx];
1058 1045
@@ -1064,6 +1051,9 @@ static void handle_reg_beacon(struct wiphy *wiphy,
1064 1051
1065 chan->beacon_found = true; 1052 chan->beacon_found = true;
1066 1053
1054 if (!reg_is_world_roaming(wiphy))
1055 return;
1056
1067 if (wiphy->flags & WIPHY_FLAG_DISABLE_BEACON_HINTS) 1057 if (wiphy->flags & WIPHY_FLAG_DISABLE_BEACON_HINTS)
1068 return; 1058 return;
1069 1059
@@ -1094,8 +1084,6 @@ static void wiphy_update_new_beacon(struct wiphy *wiphy,
1094 unsigned int i; 1084 unsigned int i;
1095 struct ieee80211_supported_band *sband; 1085 struct ieee80211_supported_band *sband;
1096 1086
1097 assert_cfg80211_lock();
1098
1099 if (!wiphy->bands[reg_beacon->chan.band]) 1087 if (!wiphy->bands[reg_beacon->chan.band])
1100 return; 1088 return;
1101 1089
@@ -1114,11 +1102,6 @@ static void wiphy_update_beacon_reg(struct wiphy *wiphy)
1114 struct ieee80211_supported_band *sband; 1102 struct ieee80211_supported_band *sband;
1115 struct reg_beacon *reg_beacon; 1103 struct reg_beacon *reg_beacon;
1116 1104
1117 assert_cfg80211_lock();
1118
1119 if (list_empty(&reg_beacon_list))
1120 return;
1121
1122 list_for_each_entry(reg_beacon, &reg_beacon_list, list) { 1105 list_for_each_entry(reg_beacon, &reg_beacon_list, list) {
1123 if (!wiphy->bands[reg_beacon->chan.band]) 1106 if (!wiphy->bands[reg_beacon->chan.band])
1124 continue; 1107 continue;
@@ -1128,18 +1111,6 @@ static void wiphy_update_beacon_reg(struct wiphy *wiphy)
1128 } 1111 }
1129} 1112}
1130 1113
1131static bool reg_is_world_roaming(struct wiphy *wiphy)
1132{
1133 if (is_world_regdom(cfg80211_regdomain->alpha2) ||
1134 (wiphy->regd && is_world_regdom(wiphy->regd->alpha2)))
1135 return true;
1136 if (last_request &&
1137 last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
1138 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)
1139 return true;
1140 return false;
1141}
1142
1143/* Reap the advantages of previously found beacons */ 1114/* Reap the advantages of previously found beacons */
1144static void reg_process_beacons(struct wiphy *wiphy) 1115static void reg_process_beacons(struct wiphy *wiphy)
1145{ 1116{
@@ -1149,39 +1120,29 @@ static void reg_process_beacons(struct wiphy *wiphy)
1149 */ 1120 */
1150 if (!last_request) 1121 if (!last_request)
1151 return; 1122 return;
1152 if (!reg_is_world_roaming(wiphy))
1153 return;
1154 wiphy_update_beacon_reg(wiphy); 1123 wiphy_update_beacon_reg(wiphy);
1155} 1124}
1156 1125
1157static bool is_ht40_not_allowed(struct ieee80211_channel *chan) 1126static bool is_ht40_allowed(struct ieee80211_channel *chan)
1158{ 1127{
1159 if (!chan) 1128 if (!chan)
1160 return true; 1129 return false;
1161 if (chan->flags & IEEE80211_CHAN_DISABLED) 1130 if (chan->flags & IEEE80211_CHAN_DISABLED)
1162 return true; 1131 return false;
1163 /* This would happen when regulatory rules disallow HT40 completely */ 1132 /* This would happen when regulatory rules disallow HT40 completely */
1164 if (IEEE80211_CHAN_NO_HT40 == (chan->flags & (IEEE80211_CHAN_NO_HT40))) 1133 if ((chan->flags & IEEE80211_CHAN_NO_HT40) == IEEE80211_CHAN_NO_HT40)
1165 return true; 1134 return false;
1166 return false; 1135 return true;
1167} 1136}
1168 1137
1169static void reg_process_ht_flags_channel(struct wiphy *wiphy, 1138static void reg_process_ht_flags_channel(struct wiphy *wiphy,
1170 enum ieee80211_band band, 1139 struct ieee80211_channel *channel)
1171 unsigned int chan_idx)
1172{ 1140{
1173 struct ieee80211_supported_band *sband; 1141 struct ieee80211_supported_band *sband = wiphy->bands[channel->band];
1174 struct ieee80211_channel *channel;
1175 struct ieee80211_channel *channel_before = NULL, *channel_after = NULL; 1142 struct ieee80211_channel *channel_before = NULL, *channel_after = NULL;
1176 unsigned int i; 1143 unsigned int i;
1177 1144
1178 assert_cfg80211_lock(); 1145 if (!is_ht40_allowed(channel)) {
1179
1180 sband = wiphy->bands[band];
1181 BUG_ON(chan_idx >= sband->n_channels);
1182 channel = &sband->channels[chan_idx];
1183
1184 if (is_ht40_not_allowed(channel)) {
1185 channel->flags |= IEEE80211_CHAN_NO_HT40; 1146 channel->flags |= IEEE80211_CHAN_NO_HT40;
1186 return; 1147 return;
1187 } 1148 }
@@ -1192,6 +1153,7 @@ static void reg_process_ht_flags_channel(struct wiphy *wiphy,
1192 */ 1153 */
1193 for (i = 0; i < sband->n_channels; i++) { 1154 for (i = 0; i < sband->n_channels; i++) {
1194 struct ieee80211_channel *c = &sband->channels[i]; 1155 struct ieee80211_channel *c = &sband->channels[i];
1156
1195 if (c->center_freq == (channel->center_freq - 20)) 1157 if (c->center_freq == (channel->center_freq - 20))
1196 channel_before = c; 1158 channel_before = c;
1197 if (c->center_freq == (channel->center_freq + 20)) 1159 if (c->center_freq == (channel->center_freq + 20))
@@ -1203,28 +1165,27 @@ static void reg_process_ht_flags_channel(struct wiphy *wiphy,
1203 * if that ever changes we also need to change the below logic 1165 * if that ever changes we also need to change the below logic
1204 * to include that as well. 1166 * to include that as well.
1205 */ 1167 */
1206 if (is_ht40_not_allowed(channel_before)) 1168 if (!is_ht40_allowed(channel_before))
1207 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; 1169 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
1208 else 1170 else
1209 channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS; 1171 channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
1210 1172
1211 if (is_ht40_not_allowed(channel_after)) 1173 if (!is_ht40_allowed(channel_after))
1212 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; 1174 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
1213 else 1175 else
1214 channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS; 1176 channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
1215} 1177}
1216 1178
1217static void reg_process_ht_flags_band(struct wiphy *wiphy, 1179static void reg_process_ht_flags_band(struct wiphy *wiphy,
1218 enum ieee80211_band band) 1180 struct ieee80211_supported_band *sband)
1219{ 1181{
1220 unsigned int i; 1182 unsigned int i;
1221 struct ieee80211_supported_band *sband;
1222 1183
1223 BUG_ON(!wiphy->bands[band]); 1184 if (!sband)
1224 sband = wiphy->bands[band]; 1185 return;
1225 1186
1226 for (i = 0; i < sband->n_channels; i++) 1187 for (i = 0; i < sband->n_channels; i++)
1227 reg_process_ht_flags_channel(wiphy, band, i); 1188 reg_process_ht_flags_channel(wiphy, &sband->channels[i]);
1228} 1189}
1229 1190
1230static void reg_process_ht_flags(struct wiphy *wiphy) 1191static void reg_process_ht_flags(struct wiphy *wiphy)
@@ -1234,34 +1195,29 @@ static void reg_process_ht_flags(struct wiphy *wiphy)
1234 if (!wiphy) 1195 if (!wiphy)
1235 return; 1196 return;
1236 1197
1237 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 1198 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
1238 if (wiphy->bands[band]) 1199 reg_process_ht_flags_band(wiphy, wiphy->bands[band]);
1239 reg_process_ht_flags_band(wiphy, band);
1240 }
1241
1242} 1200}
1243 1201
1244static void wiphy_update_regulatory(struct wiphy *wiphy, 1202static void wiphy_update_regulatory(struct wiphy *wiphy,
1245 enum nl80211_reg_initiator initiator) 1203 enum nl80211_reg_initiator initiator)
1246{ 1204{
1247 enum ieee80211_band band; 1205 enum ieee80211_band band;
1248 1206 struct regulatory_request *lr = get_last_request();
1249 assert_reg_lock();
1250 1207
1251 if (ignore_reg_update(wiphy, initiator)) 1208 if (ignore_reg_update(wiphy, initiator))
1252 return; 1209 return;
1253 1210
1254 last_request->dfs_region = cfg80211_regdomain->dfs_region; 1211 lr->dfs_region = get_cfg80211_regdom()->dfs_region;
1255 1212
1256 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 1213 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
1257 if (wiphy->bands[band]) 1214 handle_band(wiphy, initiator, wiphy->bands[band]);
1258 handle_band(wiphy, band, initiator);
1259 }
1260 1215
1261 reg_process_beacons(wiphy); 1216 reg_process_beacons(wiphy);
1262 reg_process_ht_flags(wiphy); 1217 reg_process_ht_flags(wiphy);
1218
1263 if (wiphy->reg_notifier) 1219 if (wiphy->reg_notifier)
1264 wiphy->reg_notifier(wiphy, last_request); 1220 wiphy->reg_notifier(wiphy, lr);
1265} 1221}
1266 1222
1267static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator) 1223static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator)
@@ -1269,6 +1225,8 @@ static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator)
1269 struct cfg80211_registered_device *rdev; 1225 struct cfg80211_registered_device *rdev;
1270 struct wiphy *wiphy; 1226 struct wiphy *wiphy;
1271 1227
1228 assert_cfg80211_lock();
1229
1272 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 1230 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1273 wiphy = &rdev->wiphy; 1231 wiphy = &rdev->wiphy;
1274 wiphy_update_regulatory(wiphy, initiator); 1232 wiphy_update_regulatory(wiphy, initiator);
@@ -1280,53 +1238,40 @@ static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator)
1280 if (initiator == NL80211_REGDOM_SET_BY_CORE && 1238 if (initiator == NL80211_REGDOM_SET_BY_CORE &&
1281 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY && 1239 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY &&
1282 wiphy->reg_notifier) 1240 wiphy->reg_notifier)
1283 wiphy->reg_notifier(wiphy, last_request); 1241 wiphy->reg_notifier(wiphy, get_last_request());
1284 } 1242 }
1285} 1243}
1286 1244
1287static void handle_channel_custom(struct wiphy *wiphy, 1245static void handle_channel_custom(struct wiphy *wiphy,
1288 enum ieee80211_band band, 1246 struct ieee80211_channel *chan,
1289 unsigned int chan_idx,
1290 const struct ieee80211_regdomain *regd) 1247 const struct ieee80211_regdomain *regd)
1291{ 1248{
1292 int r;
1293 u32 desired_bw_khz = MHZ_TO_KHZ(20);
1294 u32 bw_flags = 0; 1249 u32 bw_flags = 0;
1295 const struct ieee80211_reg_rule *reg_rule = NULL; 1250 const struct ieee80211_reg_rule *reg_rule = NULL;
1296 const struct ieee80211_power_rule *power_rule = NULL; 1251 const struct ieee80211_power_rule *power_rule = NULL;
1297 const struct ieee80211_freq_range *freq_range = NULL; 1252 const struct ieee80211_freq_range *freq_range = NULL;
1298 struct ieee80211_supported_band *sband;
1299 struct ieee80211_channel *chan;
1300
1301 assert_reg_lock();
1302
1303 sband = wiphy->bands[band];
1304 BUG_ON(chan_idx >= sband->n_channels);
1305 chan = &sband->channels[chan_idx];
1306 1253
1307 r = freq_reg_info_regd(wiphy, 1254 reg_rule = freq_reg_info_regd(wiphy, MHZ_TO_KHZ(chan->center_freq),
1308 MHZ_TO_KHZ(chan->center_freq), 1255 regd);
1309 desired_bw_khz,
1310 &reg_rule,
1311 regd);
1312 1256
1313 if (r) { 1257 if (IS_ERR(reg_rule)) {
1314 REG_DBG_PRINT("Disabling freq %d MHz as custom " 1258 REG_DBG_PRINT("Disabling freq %d MHz as custom regd has no rule that fits it\n",
1315 "regd has no rule that fits a %d MHz " 1259 chan->center_freq);
1316 "wide channel\n",
1317 chan->center_freq,
1318 KHZ_TO_MHZ(desired_bw_khz));
1319 chan->flags = IEEE80211_CHAN_DISABLED; 1260 chan->flags = IEEE80211_CHAN_DISABLED;
1320 return; 1261 return;
1321 } 1262 }
1322 1263
1323 chan_reg_rule_print_dbg(chan, desired_bw_khz, reg_rule); 1264 chan_reg_rule_print_dbg(chan, reg_rule);
1324 1265
1325 power_rule = &reg_rule->power_rule; 1266 power_rule = &reg_rule->power_rule;
1326 freq_range = &reg_rule->freq_range; 1267 freq_range = &reg_rule->freq_range;
1327 1268
1328 if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(40)) 1269 if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(40))
1329 bw_flags = IEEE80211_CHAN_NO_HT40; 1270 bw_flags = IEEE80211_CHAN_NO_HT40;
1271 if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(80))
1272 bw_flags |= IEEE80211_CHAN_NO_80MHZ;
1273 if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(160))
1274 bw_flags |= IEEE80211_CHAN_NO_160MHZ;
1330 1275
1331 chan->flags |= map_regdom_flags(reg_rule->flags) | bw_flags; 1276 chan->flags |= map_regdom_flags(reg_rule->flags) | bw_flags;
1332 chan->max_antenna_gain = (int) MBI_TO_DBI(power_rule->max_antenna_gain); 1277 chan->max_antenna_gain = (int) MBI_TO_DBI(power_rule->max_antenna_gain);
@@ -1334,17 +1279,17 @@ static void handle_channel_custom(struct wiphy *wiphy,
1334 (int) MBM_TO_DBM(power_rule->max_eirp); 1279 (int) MBM_TO_DBM(power_rule->max_eirp);
1335} 1280}
1336 1281
1337static void handle_band_custom(struct wiphy *wiphy, enum ieee80211_band band, 1282static void handle_band_custom(struct wiphy *wiphy,
1283 struct ieee80211_supported_band *sband,
1338 const struct ieee80211_regdomain *regd) 1284 const struct ieee80211_regdomain *regd)
1339{ 1285{
1340 unsigned int i; 1286 unsigned int i;
1341 struct ieee80211_supported_band *sband;
1342 1287
1343 BUG_ON(!wiphy->bands[band]); 1288 if (!sband)
1344 sband = wiphy->bands[band]; 1289 return;
1345 1290
1346 for (i = 0; i < sband->n_channels; i++) 1291 for (i = 0; i < sband->n_channels; i++)
1347 handle_channel_custom(wiphy, band, i, regd); 1292 handle_channel_custom(wiphy, &sband->channels[i], regd);
1348} 1293}
1349 1294
1350/* Used by drivers prior to wiphy registration */ 1295/* Used by drivers prior to wiphy registration */
@@ -1354,60 +1299,50 @@ void wiphy_apply_custom_regulatory(struct wiphy *wiphy,
1354 enum ieee80211_band band; 1299 enum ieee80211_band band;
1355 unsigned int bands_set = 0; 1300 unsigned int bands_set = 0;
1356 1301
1357 mutex_lock(&reg_mutex);
1358 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 1302 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1359 if (!wiphy->bands[band]) 1303 if (!wiphy->bands[band])
1360 continue; 1304 continue;
1361 handle_band_custom(wiphy, band, regd); 1305 handle_band_custom(wiphy, wiphy->bands[band], regd);
1362 bands_set++; 1306 bands_set++;
1363 } 1307 }
1364 mutex_unlock(&reg_mutex);
1365 1308
1366 /* 1309 /*
1367 * no point in calling this if it won't have any effect 1310 * no point in calling this if it won't have any effect
1368 * on your device's supportd bands. 1311 * on your device's supported bands.
1369 */ 1312 */
1370 WARN_ON(!bands_set); 1313 WARN_ON(!bands_set);
1371} 1314}
1372EXPORT_SYMBOL(wiphy_apply_custom_regulatory); 1315EXPORT_SYMBOL(wiphy_apply_custom_regulatory);
1373 1316
1374/*
1375 * Return value which can be used by ignore_request() to indicate
1376 * it has been determined we should intersect two regulatory domains
1377 */
1378#define REG_INTERSECT 1
1379
1380/* This has the logic which determines when a new request 1317/* This has the logic which determines when a new request
1381 * should be ignored. */ 1318 * should be ignored. */
1382static int ignore_request(struct wiphy *wiphy, 1319static enum reg_request_treatment
1320get_reg_request_treatment(struct wiphy *wiphy,
1383 struct regulatory_request *pending_request) 1321 struct regulatory_request *pending_request)
1384{ 1322{
1385 struct wiphy *last_wiphy = NULL; 1323 struct wiphy *last_wiphy = NULL;
1386 1324 struct regulatory_request *lr = get_last_request();
1387 assert_cfg80211_lock();
1388 1325
1389 /* All initial requests are respected */ 1326 /* All initial requests are respected */
1390 if (!last_request) 1327 if (!lr)
1391 return 0; 1328 return REG_REQ_OK;
1392 1329
1393 switch (pending_request->initiator) { 1330 switch (pending_request->initiator) {
1394 case NL80211_REGDOM_SET_BY_CORE: 1331 case NL80211_REGDOM_SET_BY_CORE:
1395 return 0; 1332 return REG_REQ_OK;
1396 case NL80211_REGDOM_SET_BY_COUNTRY_IE: 1333 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
1397 1334 if (reg_request_cell_base(lr)) {
1398 if (reg_request_cell_base(last_request)) {
1399 /* Trust a Cell base station over the AP's country IE */ 1335 /* Trust a Cell base station over the AP's country IE */
1400 if (regdom_changes(pending_request->alpha2)) 1336 if (regdom_changes(pending_request->alpha2))
1401 return -EOPNOTSUPP; 1337 return REG_REQ_IGNORE;
1402 return -EALREADY; 1338 return REG_REQ_ALREADY_SET;
1403 } 1339 }
1404 1340
1405 last_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); 1341 last_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx);
1406 1342
1407 if (unlikely(!is_an_alpha2(pending_request->alpha2))) 1343 if (unlikely(!is_an_alpha2(pending_request->alpha2)))
1408 return -EINVAL; 1344 return -EINVAL;
1409 if (last_request->initiator == 1345 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) {
1410 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
1411 if (last_wiphy != wiphy) { 1346 if (last_wiphy != wiphy) {
1412 /* 1347 /*
1413 * Two cards with two APs claiming different 1348 * Two cards with two APs claiming different
@@ -1416,23 +1351,23 @@ static int ignore_request(struct wiphy *wiphy,
1416 * to be correct. Reject second one for now. 1351 * to be correct. Reject second one for now.
1417 */ 1352 */
1418 if (regdom_changes(pending_request->alpha2)) 1353 if (regdom_changes(pending_request->alpha2))
1419 return -EOPNOTSUPP; 1354 return REG_REQ_IGNORE;
1420 return -EALREADY; 1355 return REG_REQ_ALREADY_SET;
1421 } 1356 }
1422 /* 1357 /*
1423 * Two consecutive Country IE hints on the same wiphy. 1358 * Two consecutive Country IE hints on the same wiphy.
1424 * This should be picked up early by the driver/stack 1359 * This should be picked up early by the driver/stack
1425 */ 1360 */
1426 if (WARN_ON(regdom_changes(pending_request->alpha2))) 1361 if (WARN_ON(regdom_changes(pending_request->alpha2)))
1427 return 0; 1362 return REG_REQ_OK;
1428 return -EALREADY; 1363 return REG_REQ_ALREADY_SET;
1429 } 1364 }
1430 return 0; 1365 return 0;
1431 case NL80211_REGDOM_SET_BY_DRIVER: 1366 case NL80211_REGDOM_SET_BY_DRIVER:
1432 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE) { 1367 if (lr->initiator == NL80211_REGDOM_SET_BY_CORE) {
1433 if (regdom_changes(pending_request->alpha2)) 1368 if (regdom_changes(pending_request->alpha2))
1434 return 0; 1369 return REG_REQ_OK;
1435 return -EALREADY; 1370 return REG_REQ_ALREADY_SET;
1436 } 1371 }
1437 1372
1438 /* 1373 /*
@@ -1440,59 +1375,59 @@ static int ignore_request(struct wiphy *wiphy,
1440 * back in or if you add a new device for which the previously 1375 * back in or if you add a new device for which the previously
1441 * loaded card also agrees on the regulatory domain. 1376 * loaded card also agrees on the regulatory domain.
1442 */ 1377 */
1443 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER && 1378 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
1444 !regdom_changes(pending_request->alpha2)) 1379 !regdom_changes(pending_request->alpha2))
1445 return -EALREADY; 1380 return REG_REQ_ALREADY_SET;
1446 1381
1447 return REG_INTERSECT; 1382 return REG_REQ_INTERSECT;
1448 case NL80211_REGDOM_SET_BY_USER: 1383 case NL80211_REGDOM_SET_BY_USER:
1449 if (reg_request_cell_base(pending_request)) 1384 if (reg_request_cell_base(pending_request))
1450 return reg_ignore_cell_hint(pending_request); 1385 return reg_ignore_cell_hint(pending_request);
1451 1386
1452 if (reg_request_cell_base(last_request)) 1387 if (reg_request_cell_base(lr))
1453 return -EOPNOTSUPP; 1388 return REG_REQ_IGNORE;
1454 1389
1455 if (last_request->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) 1390 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE)
1456 return REG_INTERSECT; 1391 return REG_REQ_INTERSECT;
1457 /* 1392 /*
1458 * If the user knows better the user should set the regdom 1393 * If the user knows better the user should set the regdom
1459 * to their country before the IE is picked up 1394 * to their country before the IE is picked up
1460 */ 1395 */
1461 if (last_request->initiator == NL80211_REGDOM_SET_BY_USER && 1396 if (lr->initiator == NL80211_REGDOM_SET_BY_USER &&
1462 last_request->intersect) 1397 lr->intersect)
1463 return -EOPNOTSUPP; 1398 return REG_REQ_IGNORE;
1464 /* 1399 /*
1465 * Process user requests only after previous user/driver/core 1400 * Process user requests only after previous user/driver/core
1466 * requests have been processed 1401 * requests have been processed
1467 */ 1402 */
1468 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE || 1403 if ((lr->initiator == NL80211_REGDOM_SET_BY_CORE ||
1469 last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER || 1404 lr->initiator == NL80211_REGDOM_SET_BY_DRIVER ||
1470 last_request->initiator == NL80211_REGDOM_SET_BY_USER) { 1405 lr->initiator == NL80211_REGDOM_SET_BY_USER) &&
1471 if (regdom_changes(last_request->alpha2)) 1406 regdom_changes(lr->alpha2))
1472 return -EAGAIN; 1407 return REG_REQ_IGNORE;
1473 }
1474 1408
1475 if (!regdom_changes(pending_request->alpha2)) 1409 if (!regdom_changes(pending_request->alpha2))
1476 return -EALREADY; 1410 return REG_REQ_ALREADY_SET;
1477 1411
1478 return 0; 1412 return REG_REQ_OK;
1479 } 1413 }
1480 1414
1481 return -EINVAL; 1415 return REG_REQ_IGNORE;
1482} 1416}
1483 1417
1484static void reg_set_request_processed(void) 1418static void reg_set_request_processed(void)
1485{ 1419{
1486 bool need_more_processing = false; 1420 bool need_more_processing = false;
1421 struct regulatory_request *lr = get_last_request();
1487 1422
1488 last_request->processed = true; 1423 lr->processed = true;
1489 1424
1490 spin_lock(&reg_requests_lock); 1425 spin_lock(&reg_requests_lock);
1491 if (!list_empty(&reg_requests_list)) 1426 if (!list_empty(&reg_requests_list))
1492 need_more_processing = true; 1427 need_more_processing = true;
1493 spin_unlock(&reg_requests_lock); 1428 spin_unlock(&reg_requests_lock);
1494 1429
1495 if (last_request->initiator == NL80211_REGDOM_SET_BY_USER) 1430 if (lr->initiator == NL80211_REGDOM_SET_BY_USER)
1496 cancel_delayed_work(&reg_timeout); 1431 cancel_delayed_work(&reg_timeout);
1497 1432
1498 if (need_more_processing) 1433 if (need_more_processing)
@@ -1508,116 +1443,122 @@ static void reg_set_request_processed(void)
1508 * The Wireless subsystem can use this function to hint to the wireless core 1443 * The Wireless subsystem can use this function to hint to the wireless core
1509 * what it believes should be the current regulatory domain. 1444 * what it believes should be the current regulatory domain.
1510 * 1445 *
1511 * Returns zero if all went fine, %-EALREADY if a regulatory domain had 1446 * Returns one of the different reg request treatment values.
1512 * already been set or other standard error codes.
1513 * 1447 *
1514 * Caller must hold &cfg80211_mutex and &reg_mutex 1448 * Caller must hold &reg_mutex
1515 */ 1449 */
1516static int __regulatory_hint(struct wiphy *wiphy, 1450static enum reg_request_treatment
1517 struct regulatory_request *pending_request) 1451__regulatory_hint(struct wiphy *wiphy,
1452 struct regulatory_request *pending_request)
1518{ 1453{
1454 const struct ieee80211_regdomain *regd;
1519 bool intersect = false; 1455 bool intersect = false;
1520 int r = 0; 1456 enum reg_request_treatment treatment;
1521 1457 struct regulatory_request *lr;
1522 assert_cfg80211_lock();
1523 1458
1524 r = ignore_request(wiphy, pending_request); 1459 treatment = get_reg_request_treatment(wiphy, pending_request);
1525 1460
1526 if (r == REG_INTERSECT) { 1461 switch (treatment) {
1462 case REG_REQ_INTERSECT:
1527 if (pending_request->initiator == 1463 if (pending_request->initiator ==
1528 NL80211_REGDOM_SET_BY_DRIVER) { 1464 NL80211_REGDOM_SET_BY_DRIVER) {
1529 r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain); 1465 regd = reg_copy_regd(get_cfg80211_regdom());
1530 if (r) { 1466 if (IS_ERR(regd)) {
1531 kfree(pending_request); 1467 kfree(pending_request);
1532 return r; 1468 return PTR_ERR(regd);
1533 } 1469 }
1470 rcu_assign_pointer(wiphy->regd, regd);
1534 } 1471 }
1535 intersect = true; 1472 intersect = true;
1536 } else if (r) { 1473 break;
1474 case REG_REQ_OK:
1475 break;
1476 default:
1537 /* 1477 /*
1538 * If the regulatory domain being requested by the 1478 * If the regulatory domain being requested by the
1539 * driver has already been set just copy it to the 1479 * driver has already been set just copy it to the
1540 * wiphy 1480 * wiphy
1541 */ 1481 */
1542 if (r == -EALREADY && 1482 if (treatment == REG_REQ_ALREADY_SET &&
1543 pending_request->initiator == 1483 pending_request->initiator == NL80211_REGDOM_SET_BY_DRIVER) {
1544 NL80211_REGDOM_SET_BY_DRIVER) { 1484 regd = reg_copy_regd(get_cfg80211_regdom());
1545 r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain); 1485 if (IS_ERR(regd)) {
1546 if (r) {
1547 kfree(pending_request); 1486 kfree(pending_request);
1548 return r; 1487 return REG_REQ_IGNORE;
1549 } 1488 }
1550 r = -EALREADY; 1489 treatment = REG_REQ_ALREADY_SET;
1490 rcu_assign_pointer(wiphy->regd, regd);
1551 goto new_request; 1491 goto new_request;
1552 } 1492 }
1553 kfree(pending_request); 1493 kfree(pending_request);
1554 return r; 1494 return treatment;
1555 } 1495 }
1556 1496
1557new_request: 1497new_request:
1558 if (last_request != &core_request_world) 1498 lr = get_last_request();
1559 kfree(last_request); 1499 if (lr != &core_request_world && lr)
1500 kfree_rcu(lr, rcu_head);
1560 1501
1561 last_request = pending_request; 1502 pending_request->intersect = intersect;
1562 last_request->intersect = intersect; 1503 pending_request->processed = false;
1504 rcu_assign_pointer(last_request, pending_request);
1505 lr = pending_request;
1563 1506
1564 pending_request = NULL; 1507 pending_request = NULL;
1565 1508
1566 if (last_request->initiator == NL80211_REGDOM_SET_BY_USER) { 1509 if (lr->initiator == NL80211_REGDOM_SET_BY_USER) {
1567 user_alpha2[0] = last_request->alpha2[0]; 1510 user_alpha2[0] = lr->alpha2[0];
1568 user_alpha2[1] = last_request->alpha2[1]; 1511 user_alpha2[1] = lr->alpha2[1];
1569 } 1512 }
1570 1513
1571 /* When r == REG_INTERSECT we do need to call CRDA */ 1514 /* When r == REG_REQ_INTERSECT we do need to call CRDA */
1572 if (r < 0) { 1515 if (treatment != REG_REQ_OK && treatment != REG_REQ_INTERSECT) {
1573 /* 1516 /*
1574 * Since CRDA will not be called in this case as we already 1517 * Since CRDA will not be called in this case as we already
1575 * have applied the requested regulatory domain before we just 1518 * have applied the requested regulatory domain before we just
1576 * inform userspace we have processed the request 1519 * inform userspace we have processed the request
1577 */ 1520 */
1578 if (r == -EALREADY) { 1521 if (treatment == REG_REQ_ALREADY_SET) {
1579 nl80211_send_reg_change_event(last_request); 1522 nl80211_send_reg_change_event(lr);
1580 reg_set_request_processed(); 1523 reg_set_request_processed();
1581 } 1524 }
1582 return r; 1525 return treatment;
1583 } 1526 }
1584 1527
1585 return call_crda(last_request->alpha2); 1528 if (call_crda(lr->alpha2))
1529 return REG_REQ_IGNORE;
1530 return REG_REQ_OK;
1586} 1531}
1587 1532
1588/* This processes *all* regulatory hints */ 1533/* This processes *all* regulatory hints */
1589static void reg_process_hint(struct regulatory_request *reg_request, 1534static void reg_process_hint(struct regulatory_request *reg_request,
1590 enum nl80211_reg_initiator reg_initiator) 1535 enum nl80211_reg_initiator reg_initiator)
1591{ 1536{
1592 int r = 0;
1593 struct wiphy *wiphy = NULL; 1537 struct wiphy *wiphy = NULL;
1594 1538
1595 BUG_ON(!reg_request->alpha2); 1539 if (WARN_ON(!reg_request->alpha2))
1540 return;
1596 1541
1597 if (wiphy_idx_valid(reg_request->wiphy_idx)) 1542 if (reg_request->wiphy_idx != WIPHY_IDX_INVALID)
1598 wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx); 1543 wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx);
1599 1544
1600 if (reg_initiator == NL80211_REGDOM_SET_BY_DRIVER && 1545 if (reg_initiator == NL80211_REGDOM_SET_BY_DRIVER && !wiphy) {
1601 !wiphy) {
1602 kfree(reg_request); 1546 kfree(reg_request);
1603 return; 1547 return;
1604 } 1548 }
1605 1549
1606 r = __regulatory_hint(wiphy, reg_request); 1550 switch (__regulatory_hint(wiphy, reg_request)) {
1607 /* This is required so that the orig_* parameters are saved */ 1551 case REG_REQ_ALREADY_SET:
1608 if (r == -EALREADY && wiphy && 1552 /* This is required so that the orig_* parameters are saved */
1609 wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) { 1553 if (wiphy && wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY)
1610 wiphy_update_regulatory(wiphy, reg_initiator); 1554 wiphy_update_regulatory(wiphy, reg_initiator);
1611 return; 1555 break;
1556 default:
1557 if (reg_initiator == NL80211_REGDOM_SET_BY_USER)
1558 schedule_delayed_work(&reg_timeout,
1559 msecs_to_jiffies(3142));
1560 break;
1612 } 1561 }
1613
1614 /*
1615 * We only time out user hints, given that they should be the only
1616 * source of bogus requests.
1617 */
1618 if (r != -EALREADY &&
1619 reg_initiator == NL80211_REGDOM_SET_BY_USER)
1620 schedule_delayed_work(&reg_timeout, msecs_to_jiffies(3142));
1621} 1562}
1622 1563
1623/* 1564/*
@@ -1627,15 +1568,15 @@ static void reg_process_hint(struct regulatory_request *reg_request,
1627 */ 1568 */
1628static void reg_process_pending_hints(void) 1569static void reg_process_pending_hints(void)
1629{ 1570{
1630 struct regulatory_request *reg_request; 1571 struct regulatory_request *reg_request, *lr;
1631 1572
1632 mutex_lock(&cfg80211_mutex); 1573 mutex_lock(&cfg80211_mutex);
1633 mutex_lock(&reg_mutex); 1574 mutex_lock(&reg_mutex);
1575 lr = get_last_request();
1634 1576
1635 /* When last_request->processed becomes true this will be rescheduled */ 1577 /* When last_request->processed becomes true this will be rescheduled */
1636 if (last_request && !last_request->processed) { 1578 if (lr && !lr->processed) {
1637 REG_DBG_PRINT("Pending regulatory request, waiting " 1579 REG_DBG_PRINT("Pending regulatory request, waiting for it to be processed...\n");
1638 "for it to be processed...\n");
1639 goto out; 1580 goto out;
1640 } 1581 }
1641 1582
@@ -1666,23 +1607,14 @@ static void reg_process_pending_beacon_hints(void)
1666 struct cfg80211_registered_device *rdev; 1607 struct cfg80211_registered_device *rdev;
1667 struct reg_beacon *pending_beacon, *tmp; 1608 struct reg_beacon *pending_beacon, *tmp;
1668 1609
1669 /*
1670 * No need to hold the reg_mutex here as we just touch wiphys
1671 * and do not read or access regulatory variables.
1672 */
1673 mutex_lock(&cfg80211_mutex); 1610 mutex_lock(&cfg80211_mutex);
1611 mutex_lock(&reg_mutex);
1674 1612
1675 /* This goes through the _pending_ beacon list */ 1613 /* This goes through the _pending_ beacon list */
1676 spin_lock_bh(&reg_pending_beacons_lock); 1614 spin_lock_bh(&reg_pending_beacons_lock);
1677 1615
1678 if (list_empty(&reg_pending_beacons)) {
1679 spin_unlock_bh(&reg_pending_beacons_lock);
1680 goto out;
1681 }
1682
1683 list_for_each_entry_safe(pending_beacon, tmp, 1616 list_for_each_entry_safe(pending_beacon, tmp,
1684 &reg_pending_beacons, list) { 1617 &reg_pending_beacons, list) {
1685
1686 list_del_init(&pending_beacon->list); 1618 list_del_init(&pending_beacon->list);
1687 1619
1688 /* Applies the beacon hint to current wiphys */ 1620 /* Applies the beacon hint to current wiphys */
@@ -1694,7 +1626,7 @@ static void reg_process_pending_beacon_hints(void)
1694 } 1626 }
1695 1627
1696 spin_unlock_bh(&reg_pending_beacons_lock); 1628 spin_unlock_bh(&reg_pending_beacons_lock);
1697out: 1629 mutex_unlock(&reg_mutex);
1698 mutex_unlock(&cfg80211_mutex); 1630 mutex_unlock(&cfg80211_mutex);
1699} 1631}
1700 1632
@@ -1706,10 +1638,8 @@ static void reg_todo(struct work_struct *work)
1706 1638
1707static void queue_regulatory_request(struct regulatory_request *request) 1639static void queue_regulatory_request(struct regulatory_request *request)
1708{ 1640{
1709 if (isalpha(request->alpha2[0])) 1641 request->alpha2[0] = toupper(request->alpha2[0]);
1710 request->alpha2[0] = toupper(request->alpha2[0]); 1642 request->alpha2[1] = toupper(request->alpha2[1]);
1711 if (isalpha(request->alpha2[1]))
1712 request->alpha2[1] = toupper(request->alpha2[1]);
1713 1643
1714 spin_lock(&reg_requests_lock); 1644 spin_lock(&reg_requests_lock);
1715 list_add_tail(&request->list, &reg_requests_list); 1645 list_add_tail(&request->list, &reg_requests_list);
@@ -1726,8 +1656,7 @@ static int regulatory_hint_core(const char *alpha2)
1726{ 1656{
1727 struct regulatory_request *request; 1657 struct regulatory_request *request;
1728 1658
1729 request = kzalloc(sizeof(struct regulatory_request), 1659 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1730 GFP_KERNEL);
1731 if (!request) 1660 if (!request)
1732 return -ENOMEM; 1661 return -ENOMEM;
1733 1662
@@ -1746,13 +1675,14 @@ int regulatory_hint_user(const char *alpha2,
1746{ 1675{
1747 struct regulatory_request *request; 1676 struct regulatory_request *request;
1748 1677
1749 BUG_ON(!alpha2); 1678 if (WARN_ON(!alpha2))
1679 return -EINVAL;
1750 1680
1751 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); 1681 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1752 if (!request) 1682 if (!request)
1753 return -ENOMEM; 1683 return -ENOMEM;
1754 1684
1755 request->wiphy_idx = WIPHY_IDX_STALE; 1685 request->wiphy_idx = WIPHY_IDX_INVALID;
1756 request->alpha2[0] = alpha2[0]; 1686 request->alpha2[0] = alpha2[0];
1757 request->alpha2[1] = alpha2[1]; 1687 request->alpha2[1] = alpha2[1];
1758 request->initiator = NL80211_REGDOM_SET_BY_USER; 1688 request->initiator = NL80211_REGDOM_SET_BY_USER;
@@ -1768,8 +1698,8 @@ int regulatory_hint(struct wiphy *wiphy, const char *alpha2)
1768{ 1698{
1769 struct regulatory_request *request; 1699 struct regulatory_request *request;
1770 1700
1771 BUG_ON(!alpha2); 1701 if (WARN_ON(!alpha2 || !wiphy))
1772 BUG_ON(!wiphy); 1702 return -EINVAL;
1773 1703
1774 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); 1704 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1775 if (!request) 1705 if (!request)
@@ -1777,9 +1707,6 @@ int regulatory_hint(struct wiphy *wiphy, const char *alpha2)
1777 1707
1778 request->wiphy_idx = get_wiphy_idx(wiphy); 1708 request->wiphy_idx = get_wiphy_idx(wiphy);
1779 1709
1780 /* Must have registered wiphy first */
1781 BUG_ON(!wiphy_idx_valid(request->wiphy_idx));
1782
1783 request->alpha2[0] = alpha2[0]; 1710 request->alpha2[0] = alpha2[0];
1784 request->alpha2[1] = alpha2[1]; 1711 request->alpha2[1] = alpha2[1];
1785 request->initiator = NL80211_REGDOM_SET_BY_DRIVER; 1712 request->initiator = NL80211_REGDOM_SET_BY_DRIVER;
@@ -1794,18 +1721,17 @@ EXPORT_SYMBOL(regulatory_hint);
1794 * We hold wdev_lock() here so we cannot hold cfg80211_mutex() and 1721 * We hold wdev_lock() here so we cannot hold cfg80211_mutex() and
1795 * therefore cannot iterate over the rdev list here. 1722 * therefore cannot iterate over the rdev list here.
1796 */ 1723 */
1797void regulatory_hint_11d(struct wiphy *wiphy, 1724void regulatory_hint_11d(struct wiphy *wiphy, enum ieee80211_band band,
1798 enum ieee80211_band band, 1725 const u8 *country_ie, u8 country_ie_len)
1799 const u8 *country_ie,
1800 u8 country_ie_len)
1801{ 1726{
1802 char alpha2[2]; 1727 char alpha2[2];
1803 enum environment_cap env = ENVIRON_ANY; 1728 enum environment_cap env = ENVIRON_ANY;
1804 struct regulatory_request *request; 1729 struct regulatory_request *request, *lr;
1805 1730
1806 mutex_lock(&reg_mutex); 1731 mutex_lock(&reg_mutex);
1732 lr = get_last_request();
1807 1733
1808 if (unlikely(!last_request)) 1734 if (unlikely(!lr))
1809 goto out; 1735 goto out;
1810 1736
1811 /* IE len must be evenly divisible by 2 */ 1737 /* IE len must be evenly divisible by 2 */
@@ -1828,9 +1754,8 @@ void regulatory_hint_11d(struct wiphy *wiphy,
1828 * We leave conflict resolution to the workqueue, where can hold 1754 * We leave conflict resolution to the workqueue, where can hold
1829 * cfg80211_mutex. 1755 * cfg80211_mutex.
1830 */ 1756 */
1831 if (likely(last_request->initiator == 1757 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE &&
1832 NL80211_REGDOM_SET_BY_COUNTRY_IE && 1758 lr->wiphy_idx != WIPHY_IDX_INVALID)
1833 wiphy_idx_valid(last_request->wiphy_idx)))
1834 goto out; 1759 goto out;
1835 1760
1836 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); 1761 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
@@ -1843,12 +1768,7 @@ void regulatory_hint_11d(struct wiphy *wiphy,
1843 request->initiator = NL80211_REGDOM_SET_BY_COUNTRY_IE; 1768 request->initiator = NL80211_REGDOM_SET_BY_COUNTRY_IE;
1844 request->country_ie_env = env; 1769 request->country_ie_env = env;
1845 1770
1846 mutex_unlock(&reg_mutex);
1847
1848 queue_regulatory_request(request); 1771 queue_regulatory_request(request);
1849
1850 return;
1851
1852out: 1772out:
1853 mutex_unlock(&reg_mutex); 1773 mutex_unlock(&reg_mutex);
1854} 1774}
@@ -1863,8 +1783,7 @@ static void restore_alpha2(char *alpha2, bool reset_user)
1863 if (is_user_regdom_saved()) { 1783 if (is_user_regdom_saved()) {
1864 /* Unless we're asked to ignore it and reset it */ 1784 /* Unless we're asked to ignore it and reset it */
1865 if (reset_user) { 1785 if (reset_user) {
1866 REG_DBG_PRINT("Restoring regulatory settings " 1786 REG_DBG_PRINT("Restoring regulatory settings including user preference\n");
1867 "including user preference\n");
1868 user_alpha2[0] = '9'; 1787 user_alpha2[0] = '9';
1869 user_alpha2[1] = '7'; 1788 user_alpha2[1] = '7';
1870 1789
@@ -1874,26 +1793,20 @@ static void restore_alpha2(char *alpha2, bool reset_user)
1874 * back as they were for a full restore. 1793 * back as they were for a full restore.
1875 */ 1794 */
1876 if (!is_world_regdom(ieee80211_regdom)) { 1795 if (!is_world_regdom(ieee80211_regdom)) {
1877 REG_DBG_PRINT("Keeping preference on " 1796 REG_DBG_PRINT("Keeping preference on module parameter ieee80211_regdom: %c%c\n",
1878 "module parameter ieee80211_regdom: %c%c\n", 1797 ieee80211_regdom[0], ieee80211_regdom[1]);
1879 ieee80211_regdom[0],
1880 ieee80211_regdom[1]);
1881 alpha2[0] = ieee80211_regdom[0]; 1798 alpha2[0] = ieee80211_regdom[0];
1882 alpha2[1] = ieee80211_regdom[1]; 1799 alpha2[1] = ieee80211_regdom[1];
1883 } 1800 }
1884 } else { 1801 } else {
1885 REG_DBG_PRINT("Restoring regulatory settings " 1802 REG_DBG_PRINT("Restoring regulatory settings while preserving user preference for: %c%c\n",
1886 "while preserving user preference for: %c%c\n", 1803 user_alpha2[0], user_alpha2[1]);
1887 user_alpha2[0],
1888 user_alpha2[1]);
1889 alpha2[0] = user_alpha2[0]; 1804 alpha2[0] = user_alpha2[0];
1890 alpha2[1] = user_alpha2[1]; 1805 alpha2[1] = user_alpha2[1];
1891 } 1806 }
1892 } else if (!is_world_regdom(ieee80211_regdom)) { 1807 } else if (!is_world_regdom(ieee80211_regdom)) {
1893 REG_DBG_PRINT("Keeping preference on " 1808 REG_DBG_PRINT("Keeping preference on module parameter ieee80211_regdom: %c%c\n",
1894 "module parameter ieee80211_regdom: %c%c\n", 1809 ieee80211_regdom[0], ieee80211_regdom[1]);
1895 ieee80211_regdom[0],
1896 ieee80211_regdom[1]);
1897 alpha2[0] = ieee80211_regdom[0]; 1810 alpha2[0] = ieee80211_regdom[0];
1898 alpha2[1] = ieee80211_regdom[1]; 1811 alpha2[1] = ieee80211_regdom[1];
1899 } else 1812 } else
@@ -1948,7 +1861,7 @@ static void restore_regulatory_settings(bool reset_user)
1948 mutex_lock(&cfg80211_mutex); 1861 mutex_lock(&cfg80211_mutex);
1949 mutex_lock(&reg_mutex); 1862 mutex_lock(&reg_mutex);
1950 1863
1951 reset_regdomains(true); 1864 reset_regdomains(true, &world_regdom);
1952 restore_alpha2(alpha2, reset_user); 1865 restore_alpha2(alpha2, reset_user);
1953 1866
1954 /* 1867 /*
@@ -1958,49 +1871,35 @@ static void restore_regulatory_settings(bool reset_user)
1958 * settings. 1871 * settings.
1959 */ 1872 */
1960 spin_lock(&reg_requests_lock); 1873 spin_lock(&reg_requests_lock);
1961 if (!list_empty(&reg_requests_list)) { 1874 list_for_each_entry_safe(reg_request, tmp, &reg_requests_list, list) {
1962 list_for_each_entry_safe(reg_request, tmp, 1875 if (reg_request->initiator != NL80211_REGDOM_SET_BY_USER)
1963 &reg_requests_list, list) { 1876 continue;
1964 if (reg_request->initiator != 1877 list_move_tail(&reg_request->list, &tmp_reg_req_list);
1965 NL80211_REGDOM_SET_BY_USER)
1966 continue;
1967 list_move_tail(&reg_request->list, &tmp_reg_req_list);
1968 }
1969 } 1878 }
1970 spin_unlock(&reg_requests_lock); 1879 spin_unlock(&reg_requests_lock);
1971 1880
1972 /* Clear beacon hints */ 1881 /* Clear beacon hints */
1973 spin_lock_bh(&reg_pending_beacons_lock); 1882 spin_lock_bh(&reg_pending_beacons_lock);
1974 if (!list_empty(&reg_pending_beacons)) { 1883 list_for_each_entry_safe(reg_beacon, btmp, &reg_pending_beacons, list) {
1975 list_for_each_entry_safe(reg_beacon, btmp, 1884 list_del(&reg_beacon->list);
1976 &reg_pending_beacons, list) { 1885 kfree(reg_beacon);
1977 list_del(&reg_beacon->list);
1978 kfree(reg_beacon);
1979 }
1980 } 1886 }
1981 spin_unlock_bh(&reg_pending_beacons_lock); 1887 spin_unlock_bh(&reg_pending_beacons_lock);
1982 1888
1983 if (!list_empty(&reg_beacon_list)) { 1889 list_for_each_entry_safe(reg_beacon, btmp, &reg_beacon_list, list) {
1984 list_for_each_entry_safe(reg_beacon, btmp, 1890 list_del(&reg_beacon->list);
1985 &reg_beacon_list, list) { 1891 kfree(reg_beacon);
1986 list_del(&reg_beacon->list);
1987 kfree(reg_beacon);
1988 }
1989 } 1892 }
1990 1893
1991 /* First restore to the basic regulatory settings */ 1894 /* First restore to the basic regulatory settings */
1992 cfg80211_regdomain = cfg80211_world_regdom; 1895 world_alpha2[0] = cfg80211_world_regdom->alpha2[0];
1993 world_alpha2[0] = cfg80211_regdomain->alpha2[0]; 1896 world_alpha2[1] = cfg80211_world_regdom->alpha2[1];
1994 world_alpha2[1] = cfg80211_regdomain->alpha2[1];
1995 1897
1996 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 1898 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1997 if (rdev->wiphy.flags & WIPHY_FLAG_CUSTOM_REGULATORY) 1899 if (rdev->wiphy.flags & WIPHY_FLAG_CUSTOM_REGULATORY)
1998 restore_custom_reg_settings(&rdev->wiphy); 1900 restore_custom_reg_settings(&rdev->wiphy);
1999 } 1901 }
2000 1902
2001 mutex_unlock(&reg_mutex);
2002 mutex_unlock(&cfg80211_mutex);
2003
2004 regulatory_hint_core(world_alpha2); 1903 regulatory_hint_core(world_alpha2);
2005 1904
2006 /* 1905 /*
@@ -2011,20 +1910,8 @@ static void restore_regulatory_settings(bool reset_user)
2011 if (is_an_alpha2(alpha2)) 1910 if (is_an_alpha2(alpha2))
2012 regulatory_hint_user(user_alpha2, NL80211_USER_REG_HINT_USER); 1911 regulatory_hint_user(user_alpha2, NL80211_USER_REG_HINT_USER);
2013 1912
2014 if (list_empty(&tmp_reg_req_list))
2015 return;
2016
2017 mutex_lock(&cfg80211_mutex);
2018 mutex_lock(&reg_mutex);
2019
2020 spin_lock(&reg_requests_lock); 1913 spin_lock(&reg_requests_lock);
2021 list_for_each_entry_safe(reg_request, tmp, &tmp_reg_req_list, list) { 1914 list_splice_tail_init(&tmp_reg_req_list, &reg_requests_list);
2022 REG_DBG_PRINT("Adding request for country %c%c back "
2023 "into the queue\n",
2024 reg_request->alpha2[0],
2025 reg_request->alpha2[1]);
2026 list_move_tail(&reg_request->list, &reg_requests_list);
2027 }
2028 spin_unlock(&reg_requests_lock); 1915 spin_unlock(&reg_requests_lock);
2029 1916
2030 mutex_unlock(&reg_mutex); 1917 mutex_unlock(&reg_mutex);
@@ -2037,8 +1924,7 @@ static void restore_regulatory_settings(bool reset_user)
2037 1924
2038void regulatory_hint_disconnect(void) 1925void regulatory_hint_disconnect(void)
2039{ 1926{
2040 REG_DBG_PRINT("All devices are disconnected, going to " 1927 REG_DBG_PRINT("All devices are disconnected, going to restore regulatory settings\n");
2041 "restore regulatory settings\n");
2042 restore_regulatory_settings(false); 1928 restore_regulatory_settings(false);
2043} 1929}
2044 1930
@@ -2051,31 +1937,48 @@ static bool freq_is_chan_12_13_14(u16 freq)
2051 return false; 1937 return false;
2052} 1938}
2053 1939
1940static bool pending_reg_beacon(struct ieee80211_channel *beacon_chan)
1941{
1942 struct reg_beacon *pending_beacon;
1943
1944 list_for_each_entry(pending_beacon, &reg_pending_beacons, list)
1945 if (beacon_chan->center_freq ==
1946 pending_beacon->chan.center_freq)
1947 return true;
1948 return false;
1949}
1950
2054int regulatory_hint_found_beacon(struct wiphy *wiphy, 1951int regulatory_hint_found_beacon(struct wiphy *wiphy,
2055 struct ieee80211_channel *beacon_chan, 1952 struct ieee80211_channel *beacon_chan,
2056 gfp_t gfp) 1953 gfp_t gfp)
2057{ 1954{
2058 struct reg_beacon *reg_beacon; 1955 struct reg_beacon *reg_beacon;
1956 bool processing;
2059 1957
2060 if (likely((beacon_chan->beacon_found || 1958 if (beacon_chan->beacon_found ||
2061 (beacon_chan->flags & IEEE80211_CHAN_RADAR) || 1959 beacon_chan->flags & IEEE80211_CHAN_RADAR ||
2062 (beacon_chan->band == IEEE80211_BAND_2GHZ && 1960 (beacon_chan->band == IEEE80211_BAND_2GHZ &&
2063 !freq_is_chan_12_13_14(beacon_chan->center_freq))))) 1961 !freq_is_chan_12_13_14(beacon_chan->center_freq)))
1962 return 0;
1963
1964 spin_lock_bh(&reg_pending_beacons_lock);
1965 processing = pending_reg_beacon(beacon_chan);
1966 spin_unlock_bh(&reg_pending_beacons_lock);
1967
1968 if (processing)
2064 return 0; 1969 return 0;
2065 1970
2066 reg_beacon = kzalloc(sizeof(struct reg_beacon), gfp); 1971 reg_beacon = kzalloc(sizeof(struct reg_beacon), gfp);
2067 if (!reg_beacon) 1972 if (!reg_beacon)
2068 return -ENOMEM; 1973 return -ENOMEM;
2069 1974
2070 REG_DBG_PRINT("Found new beacon on " 1975 REG_DBG_PRINT("Found new beacon on frequency: %d MHz (Ch %d) on %s\n",
2071 "frequency: %d MHz (Ch %d) on %s\n",
2072 beacon_chan->center_freq, 1976 beacon_chan->center_freq,
2073 ieee80211_frequency_to_channel(beacon_chan->center_freq), 1977 ieee80211_frequency_to_channel(beacon_chan->center_freq),
2074 wiphy_name(wiphy)); 1978 wiphy_name(wiphy));
2075 1979
2076 memcpy(&reg_beacon->chan, beacon_chan, 1980 memcpy(&reg_beacon->chan, beacon_chan,
2077 sizeof(struct ieee80211_channel)); 1981 sizeof(struct ieee80211_channel));
2078
2079 1982
2080 /* 1983 /*
2081 * Since we can be called from BH or and non-BH context 1984 * Since we can be called from BH or and non-BH context
@@ -2155,21 +2058,19 @@ static void print_dfs_region(u8 dfs_region)
2155 pr_info(" DFS Master region JP"); 2058 pr_info(" DFS Master region JP");
2156 break; 2059 break;
2157 default: 2060 default:
2158 pr_info(" DFS Master region Uknown"); 2061 pr_info(" DFS Master region Unknown");
2159 break; 2062 break;
2160 } 2063 }
2161} 2064}
2162 2065
2163static void print_regdomain(const struct ieee80211_regdomain *rd) 2066static void print_regdomain(const struct ieee80211_regdomain *rd)
2164{ 2067{
2068 struct regulatory_request *lr = get_last_request();
2165 2069
2166 if (is_intersected_alpha2(rd->alpha2)) { 2070 if (is_intersected_alpha2(rd->alpha2)) {
2167 2071 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2168 if (last_request->initiator ==
2169 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2170 struct cfg80211_registered_device *rdev; 2072 struct cfg80211_registered_device *rdev;
2171 rdev = cfg80211_rdev_by_wiphy_idx( 2073 rdev = cfg80211_rdev_by_wiphy_idx(lr->wiphy_idx);
2172 last_request->wiphy_idx);
2173 if (rdev) { 2074 if (rdev) {
2174 pr_info("Current regulatory domain updated by AP to: %c%c\n", 2075 pr_info("Current regulatory domain updated by AP to: %c%c\n",
2175 rdev->country_ie_alpha2[0], 2076 rdev->country_ie_alpha2[0],
@@ -2178,22 +2079,21 @@ static void print_regdomain(const struct ieee80211_regdomain *rd)
2178 pr_info("Current regulatory domain intersected:\n"); 2079 pr_info("Current regulatory domain intersected:\n");
2179 } else 2080 } else
2180 pr_info("Current regulatory domain intersected:\n"); 2081 pr_info("Current regulatory domain intersected:\n");
2181 } else if (is_world_regdom(rd->alpha2)) 2082 } else if (is_world_regdom(rd->alpha2)) {
2182 pr_info("World regulatory domain updated:\n"); 2083 pr_info("World regulatory domain updated:\n");
2183 else { 2084 } else {
2184 if (is_unknown_alpha2(rd->alpha2)) 2085 if (is_unknown_alpha2(rd->alpha2))
2185 pr_info("Regulatory domain changed to driver built-in settings (unknown country)\n"); 2086 pr_info("Regulatory domain changed to driver built-in settings (unknown country)\n");
2186 else { 2087 else {
2187 if (reg_request_cell_base(last_request)) 2088 if (reg_request_cell_base(lr))
2188 pr_info("Regulatory domain changed " 2089 pr_info("Regulatory domain changed to country: %c%c by Cell Station\n",
2189 "to country: %c%c by Cell Station\n",
2190 rd->alpha2[0], rd->alpha2[1]); 2090 rd->alpha2[0], rd->alpha2[1]);
2191 else 2091 else
2192 pr_info("Regulatory domain changed " 2092 pr_info("Regulatory domain changed to country: %c%c\n",
2193 "to country: %c%c\n",
2194 rd->alpha2[0], rd->alpha2[1]); 2093 rd->alpha2[0], rd->alpha2[1]);
2195 } 2094 }
2196 } 2095 }
2096
2197 print_dfs_region(rd->dfs_region); 2097 print_dfs_region(rd->dfs_region);
2198 print_rd_rules(rd); 2098 print_rd_rules(rd);
2199} 2099}
@@ -2207,22 +2107,23 @@ static void print_regdomain_info(const struct ieee80211_regdomain *rd)
2207/* Takes ownership of rd only if it doesn't fail */ 2107/* Takes ownership of rd only if it doesn't fail */
2208static int __set_regdom(const struct ieee80211_regdomain *rd) 2108static int __set_regdom(const struct ieee80211_regdomain *rd)
2209{ 2109{
2110 const struct ieee80211_regdomain *regd;
2210 const struct ieee80211_regdomain *intersected_rd = NULL; 2111 const struct ieee80211_regdomain *intersected_rd = NULL;
2211 struct wiphy *request_wiphy; 2112 struct wiphy *request_wiphy;
2113 struct regulatory_request *lr = get_last_request();
2114
2212 /* Some basic sanity checks first */ 2115 /* Some basic sanity checks first */
2213 2116
2117 if (!reg_is_valid_request(rd->alpha2))
2118 return -EINVAL;
2119
2214 if (is_world_regdom(rd->alpha2)) { 2120 if (is_world_regdom(rd->alpha2)) {
2215 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
2216 return -EINVAL;
2217 update_world_regdomain(rd); 2121 update_world_regdomain(rd);
2218 return 0; 2122 return 0;
2219 } 2123 }
2220 2124
2221 if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) && 2125 if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) &&
2222 !is_unknown_alpha2(rd->alpha2)) 2126 !is_unknown_alpha2(rd->alpha2))
2223 return -EINVAL;
2224
2225 if (!last_request)
2226 return -EINVAL; 2127 return -EINVAL;
2227 2128
2228 /* 2129 /*
@@ -2230,7 +2131,7 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
2230 * rd is non static (it means CRDA was present and was used last) 2131 * rd is non static (it means CRDA was present and was used last)
2231 * and the pending request came in from a country IE 2132 * and the pending request came in from a country IE
2232 */ 2133 */
2233 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) { 2134 if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2234 /* 2135 /*
2235 * If someone else asked us to change the rd lets only bother 2136 * If someone else asked us to change the rd lets only bother
2236 * checking if the alpha2 changes if CRDA was already called 2137 * checking if the alpha2 changes if CRDA was already called
@@ -2246,29 +2147,23 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
2246 * internal EEPROM data 2147 * internal EEPROM data
2247 */ 2148 */
2248 2149
2249 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
2250 return -EINVAL;
2251
2252 if (!is_valid_rd(rd)) { 2150 if (!is_valid_rd(rd)) {
2253 pr_err("Invalid regulatory domain detected:\n"); 2151 pr_err("Invalid regulatory domain detected:\n");
2254 print_regdomain_info(rd); 2152 print_regdomain_info(rd);
2255 return -EINVAL; 2153 return -EINVAL;
2256 } 2154 }
2257 2155
2258 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); 2156 request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx);
2259 if (!request_wiphy && 2157 if (!request_wiphy &&
2260 (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER || 2158 (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER ||
2261 last_request->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE)) { 2159 lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE)) {
2262 schedule_delayed_work(&reg_timeout, 0); 2160 schedule_delayed_work(&reg_timeout, 0);
2263 return -ENODEV; 2161 return -ENODEV;
2264 } 2162 }
2265 2163
2266 if (!last_request->intersect) { 2164 if (!lr->intersect) {
2267 int r; 2165 if (lr->initiator != NL80211_REGDOM_SET_BY_DRIVER) {
2268 2166 reset_regdomains(false, rd);
2269 if (last_request->initiator != NL80211_REGDOM_SET_BY_DRIVER) {
2270 reset_regdomains(false);
2271 cfg80211_regdomain = rd;
2272 return 0; 2167 return 0;
2273 } 2168 }
2274 2169
@@ -2284,20 +2179,19 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
2284 if (request_wiphy->regd) 2179 if (request_wiphy->regd)
2285 return -EALREADY; 2180 return -EALREADY;
2286 2181
2287 r = reg_copy_regd(&request_wiphy->regd, rd); 2182 regd = reg_copy_regd(rd);
2288 if (r) 2183 if (IS_ERR(regd))
2289 return r; 2184 return PTR_ERR(regd);
2290 2185
2291 reset_regdomains(false); 2186 rcu_assign_pointer(request_wiphy->regd, regd);
2292 cfg80211_regdomain = rd; 2187 reset_regdomains(false, rd);
2293 return 0; 2188 return 0;
2294 } 2189 }
2295 2190
2296 /* Intersection requires a bit more work */ 2191 /* Intersection requires a bit more work */
2297 2192
2298 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) { 2193 if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2299 2194 intersected_rd = regdom_intersect(rd, get_cfg80211_regdom());
2300 intersected_rd = regdom_intersect(rd, cfg80211_regdomain);
2301 if (!intersected_rd) 2195 if (!intersected_rd)
2302 return -EINVAL; 2196 return -EINVAL;
2303 2197
@@ -2306,15 +2200,19 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
2306 * However if a driver requested this specific regulatory 2200 * However if a driver requested this specific regulatory
2307 * domain we keep it for its private use 2201 * domain we keep it for its private use
2308 */ 2202 */
2309 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER) 2203 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER) {
2310 request_wiphy->regd = rd; 2204 const struct ieee80211_regdomain *tmp;
2311 else 2205
2206 tmp = get_wiphy_regdom(request_wiphy);
2207 rcu_assign_pointer(request_wiphy->regd, rd);
2208 rcu_free_regdom(tmp);
2209 } else {
2312 kfree(rd); 2210 kfree(rd);
2211 }
2313 2212
2314 rd = NULL; 2213 rd = NULL;
2315 2214
2316 reset_regdomains(false); 2215 reset_regdomains(false, intersected_rd);
2317 cfg80211_regdomain = intersected_rd;
2318 2216
2319 return 0; 2217 return 0;
2320 } 2218 }
@@ -2326,15 +2224,15 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
2326/* 2224/*
2327 * Use this call to set the current regulatory domain. Conflicts with 2225 * Use this call to set the current regulatory domain. Conflicts with
2328 * multiple drivers can be ironed out later. Caller must've already 2226 * multiple drivers can be ironed out later. Caller must've already
2329 * kmalloc'd the rd structure. Caller must hold cfg80211_mutex 2227 * kmalloc'd the rd structure.
2330 */ 2228 */
2331int set_regdom(const struct ieee80211_regdomain *rd) 2229int set_regdom(const struct ieee80211_regdomain *rd)
2332{ 2230{
2231 struct regulatory_request *lr;
2333 int r; 2232 int r;
2334 2233
2335 assert_cfg80211_lock();
2336
2337 mutex_lock(&reg_mutex); 2234 mutex_lock(&reg_mutex);
2235 lr = get_last_request();
2338 2236
2339 /* Note that this doesn't update the wiphys, this is done below */ 2237 /* Note that this doesn't update the wiphys, this is done below */
2340 r = __set_regdom(rd); 2238 r = __set_regdom(rd);
@@ -2343,23 +2241,25 @@ int set_regdom(const struct ieee80211_regdomain *rd)
2343 reg_set_request_processed(); 2241 reg_set_request_processed();
2344 2242
2345 kfree(rd); 2243 kfree(rd);
2346 mutex_unlock(&reg_mutex); 2244 goto out;
2347 return r;
2348 } 2245 }
2349 2246
2350 /* This would make this whole thing pointless */ 2247 /* This would make this whole thing pointless */
2351 if (!last_request->intersect) 2248 if (WARN_ON(!lr->intersect && rd != get_cfg80211_regdom())) {
2352 BUG_ON(rd != cfg80211_regdomain); 2249 r = -EINVAL;
2250 goto out;
2251 }
2353 2252
2354 /* update all wiphys now with the new established regulatory domain */ 2253 /* update all wiphys now with the new established regulatory domain */
2355 update_all_wiphy_regulatory(last_request->initiator); 2254 update_all_wiphy_regulatory(lr->initiator);
2356 2255
2357 print_regdomain(cfg80211_regdomain); 2256 print_regdomain(get_cfg80211_regdom());
2358 2257
2359 nl80211_send_reg_change_event(last_request); 2258 nl80211_send_reg_change_event(lr);
2360 2259
2361 reg_set_request_processed(); 2260 reg_set_request_processed();
2362 2261
2262 out:
2363 mutex_unlock(&reg_mutex); 2263 mutex_unlock(&reg_mutex);
2364 2264
2365 return r; 2265 return r;
@@ -2367,20 +2267,26 @@ int set_regdom(const struct ieee80211_regdomain *rd)
2367 2267
2368int reg_device_uevent(struct device *dev, struct kobj_uevent_env *env) 2268int reg_device_uevent(struct device *dev, struct kobj_uevent_env *env)
2369{ 2269{
2370 if (last_request && !last_request->processed) { 2270 struct regulatory_request *lr;
2371 if (add_uevent_var(env, "COUNTRY=%c%c", 2271 u8 alpha2[2];
2372 last_request->alpha2[0], 2272 bool add = false;
2373 last_request->alpha2[1])) 2273
2374 return -ENOMEM; 2274 rcu_read_lock();
2275 lr = get_last_request();
2276 if (lr && !lr->processed) {
2277 memcpy(alpha2, lr->alpha2, 2);
2278 add = true;
2375 } 2279 }
2280 rcu_read_unlock();
2376 2281
2282 if (add)
2283 return add_uevent_var(env, "COUNTRY=%c%c",
2284 alpha2[0], alpha2[1]);
2377 return 0; 2285 return 0;
2378} 2286}
2379 2287
2380void wiphy_regulatory_register(struct wiphy *wiphy) 2288void wiphy_regulatory_register(struct wiphy *wiphy)
2381{ 2289{
2382 assert_cfg80211_lock();
2383
2384 mutex_lock(&reg_mutex); 2290 mutex_lock(&reg_mutex);
2385 2291
2386 if (!reg_dev_ignore_cell_hint(wiphy)) 2292 if (!reg_dev_ignore_cell_hint(wiphy))
@@ -2395,32 +2301,32 @@ void wiphy_regulatory_register(struct wiphy *wiphy)
2395void wiphy_regulatory_deregister(struct wiphy *wiphy) 2301void wiphy_regulatory_deregister(struct wiphy *wiphy)
2396{ 2302{
2397 struct wiphy *request_wiphy = NULL; 2303 struct wiphy *request_wiphy = NULL;
2398 2304 struct regulatory_request *lr;
2399 assert_cfg80211_lock();
2400 2305
2401 mutex_lock(&reg_mutex); 2306 mutex_lock(&reg_mutex);
2307 lr = get_last_request();
2402 2308
2403 if (!reg_dev_ignore_cell_hint(wiphy)) 2309 if (!reg_dev_ignore_cell_hint(wiphy))
2404 reg_num_devs_support_basehint--; 2310 reg_num_devs_support_basehint--;
2405 2311
2406 kfree(wiphy->regd); 2312 rcu_free_regdom(get_wiphy_regdom(wiphy));
2313 rcu_assign_pointer(wiphy->regd, NULL);
2407 2314
2408 if (last_request) 2315 if (lr)
2409 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); 2316 request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx);
2410 2317
2411 if (!request_wiphy || request_wiphy != wiphy) 2318 if (!request_wiphy || request_wiphy != wiphy)
2412 goto out; 2319 goto out;
2413 2320
2414 last_request->wiphy_idx = WIPHY_IDX_STALE; 2321 lr->wiphy_idx = WIPHY_IDX_INVALID;
2415 last_request->country_ie_env = ENVIRON_ANY; 2322 lr->country_ie_env = ENVIRON_ANY;
2416out: 2323out:
2417 mutex_unlock(&reg_mutex); 2324 mutex_unlock(&reg_mutex);
2418} 2325}
2419 2326
2420static void reg_timeout_work(struct work_struct *work) 2327static void reg_timeout_work(struct work_struct *work)
2421{ 2328{
2422 REG_DBG_PRINT("Timeout while waiting for CRDA to reply, " 2329 REG_DBG_PRINT("Timeout while waiting for CRDA to reply, restoring regulatory settings\n");
2423 "restoring regulatory settings\n");
2424 restore_regulatory_settings(true); 2330 restore_regulatory_settings(true);
2425} 2331}
2426 2332
@@ -2439,13 +2345,13 @@ int __init regulatory_init(void)
2439 2345
2440 reg_regdb_size_check(); 2346 reg_regdb_size_check();
2441 2347
2442 cfg80211_regdomain = cfg80211_world_regdom; 2348 rcu_assign_pointer(cfg80211_regdomain, cfg80211_world_regdom);
2443 2349
2444 user_alpha2[0] = '9'; 2350 user_alpha2[0] = '9';
2445 user_alpha2[1] = '7'; 2351 user_alpha2[1] = '7';
2446 2352
2447 /* We always try to get an update for the static regdomain */ 2353 /* We always try to get an update for the static regdomain */
2448 err = regulatory_hint_core(cfg80211_regdomain->alpha2); 2354 err = regulatory_hint_core(cfg80211_world_regdom->alpha2);
2449 if (err) { 2355 if (err) {
2450 if (err == -ENOMEM) 2356 if (err == -ENOMEM)
2451 return err; 2357 return err;
@@ -2457,10 +2363,6 @@ int __init regulatory_init(void)
2457 * errors as non-fatal. 2363 * errors as non-fatal.
2458 */ 2364 */
2459 pr_err("kobject_uevent_env() was unable to call CRDA during init\n"); 2365 pr_err("kobject_uevent_env() was unable to call CRDA during init\n");
2460#ifdef CONFIG_CFG80211_REG_DEBUG
2461 /* We want to find out exactly why when debugging */
2462 WARN_ON(err);
2463#endif
2464 } 2366 }
2465 2367
2466 /* 2368 /*
@@ -2474,7 +2376,7 @@ int __init regulatory_init(void)
2474 return 0; 2376 return 0;
2475} 2377}
2476 2378
2477void /* __init_or_exit */ regulatory_exit(void) 2379void regulatory_exit(void)
2478{ 2380{
2479 struct regulatory_request *reg_request, *tmp; 2381 struct regulatory_request *reg_request, *tmp;
2480 struct reg_beacon *reg_beacon, *btmp; 2382 struct reg_beacon *reg_beacon, *btmp;
@@ -2482,43 +2384,27 @@ void /* __init_or_exit */ regulatory_exit(void)
2482 cancel_work_sync(&reg_work); 2384 cancel_work_sync(&reg_work);
2483 cancel_delayed_work_sync(&reg_timeout); 2385 cancel_delayed_work_sync(&reg_timeout);
2484 2386
2485 mutex_lock(&cfg80211_mutex); 2387 /* Lock to suppress warnings */
2486 mutex_lock(&reg_mutex); 2388 mutex_lock(&reg_mutex);
2487 2389 reset_regdomains(true, NULL);
2488 reset_regdomains(true); 2390 mutex_unlock(&reg_mutex);
2489 2391
2490 dev_set_uevent_suppress(&reg_pdev->dev, true); 2392 dev_set_uevent_suppress(&reg_pdev->dev, true);
2491 2393
2492 platform_device_unregister(reg_pdev); 2394 platform_device_unregister(reg_pdev);
2493 2395
2494 spin_lock_bh(&reg_pending_beacons_lock); 2396 list_for_each_entry_safe(reg_beacon, btmp, &reg_pending_beacons, list) {
2495 if (!list_empty(&reg_pending_beacons)) { 2397 list_del(&reg_beacon->list);
2496 list_for_each_entry_safe(reg_beacon, btmp, 2398 kfree(reg_beacon);
2497 &reg_pending_beacons, list) {
2498 list_del(&reg_beacon->list);
2499 kfree(reg_beacon);
2500 }
2501 } 2399 }
2502 spin_unlock_bh(&reg_pending_beacons_lock);
2503 2400
2504 if (!list_empty(&reg_beacon_list)) { 2401 list_for_each_entry_safe(reg_beacon, btmp, &reg_beacon_list, list) {
2505 list_for_each_entry_safe(reg_beacon, btmp, 2402 list_del(&reg_beacon->list);
2506 &reg_beacon_list, list) { 2403 kfree(reg_beacon);
2507 list_del(&reg_beacon->list);
2508 kfree(reg_beacon);
2509 }
2510 } 2404 }
2511 2405
2512 spin_lock(&reg_requests_lock); 2406 list_for_each_entry_safe(reg_request, tmp, &reg_requests_list, list) {
2513 if (!list_empty(&reg_requests_list)) { 2407 list_del(&reg_request->list);
2514 list_for_each_entry_safe(reg_request, tmp, 2408 kfree(reg_request);
2515 &reg_requests_list, list) {
2516 list_del(&reg_request->list);
2517 kfree(reg_request);
2518 }
2519 } 2409 }
2520 spin_unlock(&reg_requests_lock);
2521
2522 mutex_unlock(&reg_mutex);
2523 mutex_unlock(&cfg80211_mutex);
2524} 2410}