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.c1034
1 files changed, 801 insertions, 233 deletions
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 2323644330cd..eb8b8ed16155 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -41,6 +41,7 @@
41#include <net/cfg80211.h> 41#include <net/cfg80211.h>
42#include "core.h" 42#include "core.h"
43#include "reg.h" 43#include "reg.h"
44#include "nl80211.h"
44 45
45/* Receipt of information from last regulatory request */ 46/* Receipt of information from last regulatory request */
46static struct regulatory_request *last_request; 47static struct regulatory_request *last_request;
@@ -54,22 +55,63 @@ static u32 supported_bandwidths[] = {
54 MHZ_TO_KHZ(20), 55 MHZ_TO_KHZ(20),
55}; 56};
56 57
57/* Central wireless core regulatory domains, we only need two, 58/*
59 * Central wireless core regulatory domains, we only need two,
58 * the current one and a world regulatory domain in case we have no 60 * the current one and a world regulatory domain in case we have no
59 * information to give us an alpha2 */ 61 * information to give us an alpha2
62 */
60const struct ieee80211_regdomain *cfg80211_regdomain; 63const struct ieee80211_regdomain *cfg80211_regdomain;
61 64
62/* We use this as a place for the rd structure built from the 65/*
66 * We use this as a place for the rd structure built from the
63 * last parsed country IE to rest until CRDA gets back to us with 67 * last parsed country IE to rest until CRDA gets back to us with
64 * what it thinks should apply for the same country */ 68 * what it thinks should apply for the same country
69 */
65static const struct ieee80211_regdomain *country_ie_regdomain; 70static const struct ieee80211_regdomain *country_ie_regdomain;
66 71
72/* Used to queue up regulatory hints */
73static LIST_HEAD(reg_requests_list);
74static spinlock_t reg_requests_lock;
75
76/* Used to queue up beacon hints for review */
77static LIST_HEAD(reg_pending_beacons);
78static spinlock_t reg_pending_beacons_lock;
79
80/* Used to keep track of processed beacon hints */
81static LIST_HEAD(reg_beacon_list);
82
83struct reg_beacon {
84 struct list_head list;
85 struct ieee80211_channel chan;
86};
87
67/* We keep a static world regulatory domain in case of the absence of CRDA */ 88/* We keep a static world regulatory domain in case of the absence of CRDA */
68static const struct ieee80211_regdomain world_regdom = { 89static const struct ieee80211_regdomain world_regdom = {
69 .n_reg_rules = 1, 90 .n_reg_rules = 5,
70 .alpha2 = "00", 91 .alpha2 = "00",
71 .reg_rules = { 92 .reg_rules = {
72 REG_RULE(2412-10, 2462+10, 40, 6, 20, 93 /* IEEE 802.11b/g, channels 1..11 */
94 REG_RULE(2412-10, 2462+10, 40, 6, 20, 0),
95 /* IEEE 802.11b/g, channels 12..13. No HT40
96 * channel fits here. */
97 REG_RULE(2467-10, 2472+10, 20, 6, 20,
98 NL80211_RRF_PASSIVE_SCAN |
99 NL80211_RRF_NO_IBSS),
100 /* IEEE 802.11 channel 14 - Only JP enables
101 * this and for 802.11b only */
102 REG_RULE(2484-10, 2484+10, 20, 6, 20,
103 NL80211_RRF_PASSIVE_SCAN |
104 NL80211_RRF_NO_IBSS |
105 NL80211_RRF_NO_OFDM),
106 /* IEEE 802.11a, channel 36..48 */
107 REG_RULE(5180-10, 5240+10, 40, 6, 20,
108 NL80211_RRF_PASSIVE_SCAN |
109 NL80211_RRF_NO_IBSS),
110
111 /* NB: 5260 MHz - 5700 MHz requies DFS */
112
113 /* IEEE 802.11a, channel 149..165 */
114 REG_RULE(5745-10, 5825+10, 40, 6, 20,
73 NL80211_RRF_PASSIVE_SCAN | 115 NL80211_RRF_PASSIVE_SCAN |
74 NL80211_RRF_NO_IBSS), 116 NL80211_RRF_NO_IBSS),
75 } 117 }
@@ -83,9 +125,11 @@ static char *ieee80211_regdom = "US";
83module_param(ieee80211_regdom, charp, 0444); 125module_param(ieee80211_regdom, charp, 0444);
84MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code"); 126MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
85 127
86/* We assume 40 MHz bandwidth for the old regulatory work. 128/*
129 * We assume 40 MHz bandwidth for the old regulatory work.
87 * We make emphasis we are using the exact same frequencies 130 * We make emphasis we are using the exact same frequencies
88 * as before */ 131 * as before
132 */
89 133
90static const struct ieee80211_regdomain us_regdom = { 134static const struct ieee80211_regdomain us_regdom = {
91 .n_reg_rules = 6, 135 .n_reg_rules = 6,
@@ -124,8 +168,10 @@ static const struct ieee80211_regdomain jp_regdom = {
124 168
125static const struct ieee80211_regdomain eu_regdom = { 169static const struct ieee80211_regdomain eu_regdom = {
126 .n_reg_rules = 6, 170 .n_reg_rules = 6,
127 /* This alpha2 is bogus, we leave it here just for stupid 171 /*
128 * backward compatibility */ 172 * This alpha2 is bogus, we leave it here just for stupid
173 * backward compatibility
174 */
129 .alpha2 = "EU", 175 .alpha2 = "EU",
130 .reg_rules = { 176 .reg_rules = {
131 /* IEEE 802.11b/g, channels 1..13 */ 177 /* IEEE 802.11b/g, channels 1..13 */
@@ -194,8 +240,10 @@ static void reset_regdomains(void)
194 cfg80211_regdomain = NULL; 240 cfg80211_regdomain = NULL;
195} 241}
196 242
197/* Dynamic world regulatory domain requested by the wireless 243/*
198 * core upon initialization */ 244 * Dynamic world regulatory domain requested by the wireless
245 * core upon initialization
246 */
199static void update_world_regdomain(const struct ieee80211_regdomain *rd) 247static void update_world_regdomain(const struct ieee80211_regdomain *rd)
200{ 248{
201 BUG_ON(!last_request); 249 BUG_ON(!last_request);
@@ -236,8 +284,10 @@ static bool is_unknown_alpha2(const char *alpha2)
236{ 284{
237 if (!alpha2) 285 if (!alpha2)
238 return false; 286 return false;
239 /* Special case where regulatory domain was built by driver 287 /*
240 * but a specific alpha2 cannot be determined */ 288 * Special case where regulatory domain was built by driver
289 * but a specific alpha2 cannot be determined
290 */
241 if (alpha2[0] == '9' && alpha2[1] == '9') 291 if (alpha2[0] == '9' && alpha2[1] == '9')
242 return true; 292 return true;
243 return false; 293 return false;
@@ -247,9 +297,11 @@ static bool is_intersected_alpha2(const char *alpha2)
247{ 297{
248 if (!alpha2) 298 if (!alpha2)
249 return false; 299 return false;
250 /* Special case where regulatory domain is the 300 /*
301 * Special case where regulatory domain is the
251 * result of an intersection between two regulatory domain 302 * result of an intersection between two regulatory domain
252 * structures */ 303 * structures
304 */
253 if (alpha2[0] == '9' && alpha2[1] == '8') 305 if (alpha2[0] == '9' && alpha2[1] == '8')
254 return true; 306 return true;
255 return false; 307 return false;
@@ -274,8 +326,10 @@ static bool alpha2_equal(const char *alpha2_x, const char *alpha2_y)
274 return false; 326 return false;
275} 327}
276 328
277static bool regdom_changed(const char *alpha2) 329static bool regdom_changes(const char *alpha2)
278{ 330{
331 assert_cfg80211_lock();
332
279 if (!cfg80211_regdomain) 333 if (!cfg80211_regdomain)
280 return true; 334 return true;
281 if (alpha2_equal(cfg80211_regdomain->alpha2, alpha2)) 335 if (alpha2_equal(cfg80211_regdomain->alpha2, alpha2))
@@ -302,8 +356,10 @@ static bool country_ie_integrity_changes(u32 checksum)
302 return false; 356 return false;
303} 357}
304 358
305/* This lets us keep regulatory code which is updated on a regulatory 359/*
306 * basis in userspace. */ 360 * This lets us keep regulatory code which is updated on a regulatory
361 * basis in userspace.
362 */
307static int call_crda(const char *alpha2) 363static int call_crda(const char *alpha2)
308{ 364{
309 char country_env[9 + 2] = "COUNTRY="; 365 char country_env[9 + 2] = "COUNTRY=";
@@ -348,7 +404,8 @@ static bool is_valid_reg_rule(const struct ieee80211_reg_rule *rule)
348 404
349 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; 405 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
350 406
351 if (freq_diff <= 0 || freq_range->max_bandwidth_khz > freq_diff) 407 if (freq_range->end_freq_khz <= freq_range->start_freq_khz ||
408 freq_range->max_bandwidth_khz > freq_diff)
352 return false; 409 return false;
353 410
354 return true; 411 return true;
@@ -414,10 +471,12 @@ static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range,
414#undef ONE_GHZ_IN_KHZ 471#undef ONE_GHZ_IN_KHZ
415} 472}
416 473
417/* Converts a country IE to a regulatory domain. A regulatory domain 474/*
475 * Converts a country IE to a regulatory domain. A regulatory domain
418 * structure has a lot of information which the IE doesn't yet have, 476 * structure has a lot of information which the IE doesn't yet have,
419 * so for the other values we use upper max values as we will intersect 477 * so for the other values we use upper max values as we will intersect
420 * with our userspace regulatory agent to get lower bounds. */ 478 * with our userspace regulatory agent to get lower bounds.
479 */
421static struct ieee80211_regdomain *country_ie_2_rd( 480static struct ieee80211_regdomain *country_ie_2_rd(
422 u8 *country_ie, 481 u8 *country_ie,
423 u8 country_ie_len, 482 u8 country_ie_len,
@@ -462,9 +521,11 @@ static struct ieee80211_regdomain *country_ie_2_rd(
462 521
463 *checksum ^= ((flags ^ alpha2[0] ^ alpha2[1]) << 8); 522 *checksum ^= ((flags ^ alpha2[0] ^ alpha2[1]) << 8);
464 523
465 /* We need to build a reg rule for each triplet, but first we must 524 /*
525 * We need to build a reg rule for each triplet, but first we must
466 * calculate the number of reg rules we will need. We will need one 526 * calculate the number of reg rules we will need. We will need one
467 * for each channel subband */ 527 * for each channel subband
528 */
468 while (country_ie_len >= 3) { 529 while (country_ie_len >= 3) {
469 int end_channel = 0; 530 int end_channel = 0;
470 struct ieee80211_country_ie_triplet *triplet = 531 struct ieee80211_country_ie_triplet *triplet =
@@ -502,9 +563,11 @@ static struct ieee80211_regdomain *country_ie_2_rd(
502 if (cur_sub_max_channel < cur_channel) 563 if (cur_sub_max_channel < cur_channel)
503 return NULL; 564 return NULL;
504 565
505 /* Do not allow overlapping channels. Also channels 566 /*
567 * Do not allow overlapping channels. Also channels
506 * passed in each subband must be monotonically 568 * passed in each subband must be monotonically
507 * increasing */ 569 * increasing
570 */
508 if (last_sub_max_channel) { 571 if (last_sub_max_channel) {
509 if (cur_channel <= last_sub_max_channel) 572 if (cur_channel <= last_sub_max_channel)
510 return NULL; 573 return NULL;
@@ -512,10 +575,12 @@ static struct ieee80211_regdomain *country_ie_2_rd(
512 return NULL; 575 return NULL;
513 } 576 }
514 577
515 /* When dot11RegulatoryClassesRequired is supported 578 /*
579 * When dot11RegulatoryClassesRequired is supported
516 * we can throw ext triplets as part of this soup, 580 * we can throw ext triplets as part of this soup,
517 * for now we don't care when those change as we 581 * for now we don't care when those change as we
518 * don't support them */ 582 * don't support them
583 */
519 *checksum ^= ((cur_channel ^ cur_sub_max_channel) << 8) | 584 *checksum ^= ((cur_channel ^ cur_sub_max_channel) << 8) |
520 ((cur_sub_max_channel ^ cur_sub_max_channel) << 16) | 585 ((cur_sub_max_channel ^ cur_sub_max_channel) << 16) |
521 ((triplet->chans.max_power ^ cur_sub_max_channel) << 24); 586 ((triplet->chans.max_power ^ cur_sub_max_channel) << 24);
@@ -526,8 +591,10 @@ static struct ieee80211_regdomain *country_ie_2_rd(
526 country_ie_len -= 3; 591 country_ie_len -= 3;
527 num_rules++; 592 num_rules++;
528 593
529 /* Note: this is not a IEEE requirement but 594 /*
530 * simply a memory requirement */ 595 * Note: this is not a IEEE requirement but
596 * simply a memory requirement
597 */
531 if (num_rules > NL80211_MAX_SUPP_REG_RULES) 598 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
532 return NULL; 599 return NULL;
533 } 600 }
@@ -555,8 +622,10 @@ static struct ieee80211_regdomain *country_ie_2_rd(
555 struct ieee80211_freq_range *freq_range = NULL; 622 struct ieee80211_freq_range *freq_range = NULL;
556 struct ieee80211_power_rule *power_rule = NULL; 623 struct ieee80211_power_rule *power_rule = NULL;
557 624
558 /* Must parse if dot11RegulatoryClassesRequired is true, 625 /*
559 * we don't support this yet */ 626 * Must parse if dot11RegulatoryClassesRequired is true,
627 * we don't support this yet
628 */
560 if (triplet->ext.reg_extension_id >= 629 if (triplet->ext.reg_extension_id >=
561 IEEE80211_COUNTRY_EXTENSION_ID) { 630 IEEE80211_COUNTRY_EXTENSION_ID) {
562 country_ie += 3; 631 country_ie += 3;
@@ -578,10 +647,12 @@ static struct ieee80211_regdomain *country_ie_2_rd(
578 end_channel = triplet->chans.first_channel + 647 end_channel = triplet->chans.first_channel +
579 (4 * (triplet->chans.num_channels - 1)); 648 (4 * (triplet->chans.num_channels - 1));
580 649
581 /* The +10 is since the regulatory domain expects 650 /*
651 * The +10 is since the regulatory domain expects
582 * the actual band edge, not the center of freq for 652 * the actual band edge, not the center of freq for
583 * its start and end freqs, assuming 20 MHz bandwidth on 653 * its start and end freqs, assuming 20 MHz bandwidth on
584 * the channels passed */ 654 * the channels passed
655 */
585 freq_range->start_freq_khz = 656 freq_range->start_freq_khz =
586 MHZ_TO_KHZ(ieee80211_channel_to_frequency( 657 MHZ_TO_KHZ(ieee80211_channel_to_frequency(
587 triplet->chans.first_channel) - 10); 658 triplet->chans.first_channel) - 10);
@@ -589,9 +660,11 @@ static struct ieee80211_regdomain *country_ie_2_rd(
589 MHZ_TO_KHZ(ieee80211_channel_to_frequency( 660 MHZ_TO_KHZ(ieee80211_channel_to_frequency(
590 end_channel) + 10); 661 end_channel) + 10);
591 662
592 /* Large arbitrary values, we intersect later */ 663 /*
593 /* Increment this if we ever support >= 40 MHz channels 664 * These are large arbitrary values we use to intersect later.
594 * in IEEE 802.11 */ 665 * Increment this if we ever support >= 40 MHz channels
666 * in IEEE 802.11
667 */
595 freq_range->max_bandwidth_khz = MHZ_TO_KHZ(40); 668 freq_range->max_bandwidth_khz = MHZ_TO_KHZ(40);
596 power_rule->max_antenna_gain = DBI_TO_MBI(100); 669 power_rule->max_antenna_gain = DBI_TO_MBI(100);
597 power_rule->max_eirp = DBM_TO_MBM(100); 670 power_rule->max_eirp = DBM_TO_MBM(100);
@@ -607,8 +680,10 @@ static struct ieee80211_regdomain *country_ie_2_rd(
607} 680}
608 681
609 682
610/* Helper for regdom_intersect(), this does the real 683/*
611 * mathematical intersection fun */ 684 * Helper for regdom_intersect(), this does the real
685 * mathematical intersection fun
686 */
612static int reg_rules_intersect( 687static int reg_rules_intersect(
613 const struct ieee80211_reg_rule *rule1, 688 const struct ieee80211_reg_rule *rule1,
614 const struct ieee80211_reg_rule *rule2, 689 const struct ieee80211_reg_rule *rule2,
@@ -686,11 +761,13 @@ static struct ieee80211_regdomain *regdom_intersect(
686 if (!rd1 || !rd2) 761 if (!rd1 || !rd2)
687 return NULL; 762 return NULL;
688 763
689 /* First we get a count of the rules we'll need, then we actually 764 /*
765 * First we get a count of the rules we'll need, then we actually
690 * build them. This is to so we can malloc() and free() a 766 * build them. This is to so we can malloc() and free() a
691 * regdomain once. The reason we use reg_rules_intersect() here 767 * regdomain once. The reason we use reg_rules_intersect() here
692 * is it will return -EINVAL if the rule computed makes no sense. 768 * is it will return -EINVAL if the rule computed makes no sense.
693 * All rules that do check out OK are valid. */ 769 * All rules that do check out OK are valid.
770 */
694 771
695 for (x = 0; x < rd1->n_reg_rules; x++) { 772 for (x = 0; x < rd1->n_reg_rules; x++) {
696 rule1 = &rd1->reg_rules[x]; 773 rule1 = &rd1->reg_rules[x];
@@ -718,14 +795,18 @@ static struct ieee80211_regdomain *regdom_intersect(
718 rule1 = &rd1->reg_rules[x]; 795 rule1 = &rd1->reg_rules[x];
719 for (y = 0; y < rd2->n_reg_rules; y++) { 796 for (y = 0; y < rd2->n_reg_rules; y++) {
720 rule2 = &rd2->reg_rules[y]; 797 rule2 = &rd2->reg_rules[y];
721 /* This time around instead of using the stack lets 798 /*
799 * This time around instead of using the stack lets
722 * write to the target rule directly saving ourselves 800 * write to the target rule directly saving ourselves
723 * a memcpy() */ 801 * a memcpy()
802 */
724 intersected_rule = &rd->reg_rules[rule_idx]; 803 intersected_rule = &rd->reg_rules[rule_idx];
725 r = reg_rules_intersect(rule1, rule2, 804 r = reg_rules_intersect(rule1, rule2,
726 intersected_rule); 805 intersected_rule);
727 /* No need to memset here the intersected rule here as 806 /*
728 * we're not using the stack anymore */ 807 * No need to memset here the intersected rule here as
808 * we're not using the stack anymore
809 */
729 if (r) 810 if (r)
730 continue; 811 continue;
731 rule_idx++; 812 rule_idx++;
@@ -744,8 +825,10 @@ static struct ieee80211_regdomain *regdom_intersect(
744 return rd; 825 return rd;
745} 826}
746 827
747/* XXX: add support for the rest of enum nl80211_reg_rule_flags, we may 828/*
748 * want to just have the channel structure use these */ 829 * XXX: add support for the rest of enum nl80211_reg_rule_flags, we may
830 * want to just have the channel structure use these
831 */
749static u32 map_regdom_flags(u32 rd_flags) 832static u32 map_regdom_flags(u32 rd_flags)
750{ 833{
751 u32 channel_flags = 0; 834 u32 channel_flags = 0;
@@ -771,10 +854,12 @@ static int freq_reg_info_regd(struct wiphy *wiphy,
771 854
772 regd = custom_regd ? custom_regd : cfg80211_regdomain; 855 regd = custom_regd ? custom_regd : cfg80211_regdomain;
773 856
774 /* Follow the driver's regulatory domain, if present, unless a country 857 /*
775 * IE has been processed or a user wants to help complaince further */ 858 * Follow the driver's regulatory domain, if present, unless a country
776 if (last_request->initiator != REGDOM_SET_BY_COUNTRY_IE && 859 * IE has been processed or a user wants to help complaince further
777 last_request->initiator != REGDOM_SET_BY_USER && 860 */
861 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
862 last_request->initiator != NL80211_REGDOM_SET_BY_USER &&
778 wiphy->regd) 863 wiphy->regd)
779 regd = wiphy->regd; 864 regd = wiphy->regd;
780 865
@@ -790,9 +875,11 @@ static int freq_reg_info_regd(struct wiphy *wiphy,
790 fr = &rr->freq_range; 875 fr = &rr->freq_range;
791 pr = &rr->power_rule; 876 pr = &rr->power_rule;
792 877
793 /* We only need to know if one frequency rule was 878 /*
879 * We only need to know if one frequency rule was
794 * was in center_freq's band, that's enough, so lets 880 * was in center_freq's band, that's enough, so lets
795 * not overwrite it once found */ 881 * not overwrite it once found
882 */
796 if (!band_rule_found) 883 if (!band_rule_found)
797 band_rule_found = freq_in_rule_band(fr, center_freq); 884 band_rule_found = freq_in_rule_band(fr, center_freq);
798 885
@@ -829,6 +916,11 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
829 const struct ieee80211_power_rule *power_rule = NULL; 916 const struct ieee80211_power_rule *power_rule = NULL;
830 struct ieee80211_supported_band *sband; 917 struct ieee80211_supported_band *sband;
831 struct ieee80211_channel *chan; 918 struct ieee80211_channel *chan;
919 struct wiphy *request_wiphy = NULL;
920
921 assert_cfg80211_lock();
922
923 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
832 924
833 sband = wiphy->bands[band]; 925 sband = wiphy->bands[band];
834 BUG_ON(chan_idx >= sband->n_channels); 926 BUG_ON(chan_idx >= sband->n_channels);
@@ -840,7 +932,8 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
840 &max_bandwidth, &reg_rule); 932 &max_bandwidth, &reg_rule);
841 933
842 if (r) { 934 if (r) {
843 /* This means no regulatory rule was found in the country IE 935 /*
936 * This means no regulatory rule was found in the country IE
844 * with a frequency range on the center_freq's band, since 937 * with a frequency range on the center_freq's band, since
845 * IEEE-802.11 allows for a country IE to have a subset of the 938 * IEEE-802.11 allows for a country IE to have a subset of the
846 * regulatory information provided in a country we ignore 939 * regulatory information provided in a country we ignore
@@ -851,7 +944,8 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
851 * http://tinyurl.com/11d-clarification 944 * http://tinyurl.com/11d-clarification
852 */ 945 */
853 if (r == -ERANGE && 946 if (r == -ERANGE &&
854 last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) { 947 last_request->initiator ==
948 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
855#ifdef CONFIG_CFG80211_REG_DEBUG 949#ifdef CONFIG_CFG80211_REG_DEBUG
856 printk(KERN_DEBUG "cfg80211: Leaving channel %d MHz " 950 printk(KERN_DEBUG "cfg80211: Leaving channel %d MHz "
857 "intact on %s - no rule found in band on " 951 "intact on %s - no rule found in band on "
@@ -859,10 +953,13 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
859 chan->center_freq, wiphy_name(wiphy)); 953 chan->center_freq, wiphy_name(wiphy));
860#endif 954#endif
861 } else { 955 } else {
862 /* In this case we know the country IE has at least one reg rule 956 /*
863 * for the band so we respect its band definitions */ 957 * In this case we know the country IE has at least one reg rule
958 * for the band so we respect its band definitions
959 */
864#ifdef CONFIG_CFG80211_REG_DEBUG 960#ifdef CONFIG_CFG80211_REG_DEBUG
865 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) 961 if (last_request->initiator ==
962 NL80211_REGDOM_SET_BY_COUNTRY_IE)
866 printk(KERN_DEBUG "cfg80211: Disabling " 963 printk(KERN_DEBUG "cfg80211: Disabling "
867 "channel %d MHz on %s due to " 964 "channel %d MHz on %s due to "
868 "Country IE\n", 965 "Country IE\n",
@@ -876,12 +973,14 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
876 973
877 power_rule = &reg_rule->power_rule; 974 power_rule = &reg_rule->power_rule;
878 975
879 if (last_request->initiator == REGDOM_SET_BY_DRIVER && 976 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
880 last_request->wiphy && last_request->wiphy == wiphy && 977 request_wiphy && request_wiphy == wiphy &&
881 last_request->wiphy->strict_regulatory) { 978 request_wiphy->strict_regulatory) {
882 /* This gaurantees the driver's requested regulatory domain 979 /*
980 * This gaurantees the driver's requested regulatory domain
883 * will always be used as a base for further regulatory 981 * will always be used as a base for further regulatory
884 * settings */ 982 * settings
983 */
885 chan->flags = chan->orig_flags = 984 chan->flags = chan->orig_flags =
886 map_regdom_flags(reg_rule->flags); 985 map_regdom_flags(reg_rule->flags);
887 chan->max_antenna_gain = chan->orig_mag = 986 chan->max_antenna_gain = chan->orig_mag =
@@ -915,39 +1014,147 @@ static void handle_band(struct wiphy *wiphy, enum ieee80211_band band)
915 handle_channel(wiphy, band, i); 1014 handle_channel(wiphy, band, i);
916} 1015}
917 1016
918static bool ignore_reg_update(struct wiphy *wiphy, enum reg_set_by setby) 1017static bool ignore_reg_update(struct wiphy *wiphy,
1018 enum nl80211_reg_initiator initiator)
919{ 1019{
920 if (!last_request) 1020 if (!last_request)
921 return true; 1021 return true;
922 if (setby == REGDOM_SET_BY_CORE && 1022 if (initiator == NL80211_REGDOM_SET_BY_CORE &&
923 wiphy->custom_regulatory) 1023 wiphy->custom_regulatory)
924 return true; 1024 return true;
925 /* wiphy->regd will be set once the device has its own 1025 /*
926 * desired regulatory domain set */ 1026 * wiphy->regd will be set once the device has its own
1027 * desired regulatory domain set
1028 */
927 if (wiphy->strict_regulatory && !wiphy->regd && 1029 if (wiphy->strict_regulatory && !wiphy->regd &&
928 !is_world_regdom(last_request->alpha2)) 1030 !is_world_regdom(last_request->alpha2))
929 return true; 1031 return true;
930 return false; 1032 return false;
931} 1033}
932 1034
933static void update_all_wiphy_regulatory(enum reg_set_by setby) 1035static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator)
934{ 1036{
935 struct cfg80211_registered_device *drv; 1037 struct cfg80211_registered_device *drv;
936 1038
937 list_for_each_entry(drv, &cfg80211_drv_list, list) 1039 list_for_each_entry(drv, &cfg80211_drv_list, list)
938 wiphy_update_regulatory(&drv->wiphy, setby); 1040 wiphy_update_regulatory(&drv->wiphy, initiator);
939} 1041}
940 1042
941void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby) 1043static void handle_reg_beacon(struct wiphy *wiphy,
1044 unsigned int chan_idx,
1045 struct reg_beacon *reg_beacon)
942{ 1046{
943 enum ieee80211_band band; 1047#ifdef CONFIG_CFG80211_REG_DEBUG
1048#define REG_DEBUG_BEACON_FLAG(desc) \
1049 printk(KERN_DEBUG "cfg80211: Enabling " desc " on " \
1050 "frequency: %d MHz (Ch %d) on %s\n", \
1051 reg_beacon->chan.center_freq, \
1052 ieee80211_frequency_to_channel(reg_beacon->chan.center_freq), \
1053 wiphy_name(wiphy));
1054#else
1055#define REG_DEBUG_BEACON_FLAG(desc) do {} while (0)
1056#endif
1057 struct ieee80211_supported_band *sband;
1058 struct ieee80211_channel *chan;
1059
1060 assert_cfg80211_lock();
1061
1062 sband = wiphy->bands[reg_beacon->chan.band];
1063 chan = &sband->channels[chan_idx];
1064
1065 if (likely(chan->center_freq != reg_beacon->chan.center_freq))
1066 return;
1067
1068 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) {
1069 chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
1070 REG_DEBUG_BEACON_FLAG("active scanning");
1071 }
1072
1073 if (chan->flags & IEEE80211_CHAN_NO_IBSS) {
1074 chan->flags &= ~IEEE80211_CHAN_NO_IBSS;
1075 REG_DEBUG_BEACON_FLAG("beaconing");
1076 }
1077
1078 chan->beacon_found = true;
1079#undef REG_DEBUG_BEACON_FLAG
1080}
1081
1082/*
1083 * Called when a scan on a wiphy finds a beacon on
1084 * new channel
1085 */
1086static void wiphy_update_new_beacon(struct wiphy *wiphy,
1087 struct reg_beacon *reg_beacon)
1088{
1089 unsigned int i;
1090 struct ieee80211_supported_band *sband;
1091
1092 assert_cfg80211_lock();
944 1093
945 if (ignore_reg_update(wiphy, setby)) 1094 if (!wiphy->bands[reg_beacon->chan.band])
946 return; 1095 return;
1096
1097 sband = wiphy->bands[reg_beacon->chan.band];
1098
1099 for (i = 0; i < sband->n_channels; i++)
1100 handle_reg_beacon(wiphy, i, reg_beacon);
1101}
1102
1103/*
1104 * Called upon reg changes or a new wiphy is added
1105 */
1106static void wiphy_update_beacon_reg(struct wiphy *wiphy)
1107{
1108 unsigned int i;
1109 struct ieee80211_supported_band *sband;
1110 struct reg_beacon *reg_beacon;
1111
1112 assert_cfg80211_lock();
1113
1114 if (list_empty(&reg_beacon_list))
1115 return;
1116
1117 list_for_each_entry(reg_beacon, &reg_beacon_list, list) {
1118 if (!wiphy->bands[reg_beacon->chan.band])
1119 continue;
1120 sband = wiphy->bands[reg_beacon->chan.band];
1121 for (i = 0; i < sband->n_channels; i++)
1122 handle_reg_beacon(wiphy, i, reg_beacon);
1123 }
1124}
1125
1126static bool reg_is_world_roaming(struct wiphy *wiphy)
1127{
1128 if (is_world_regdom(cfg80211_regdomain->alpha2) ||
1129 (wiphy->regd && is_world_regdom(wiphy->regd->alpha2)))
1130 return true;
1131 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
1132 wiphy->custom_regulatory)
1133 return true;
1134 return false;
1135}
1136
1137/* Reap the advantages of previously found beacons */
1138static void reg_process_beacons(struct wiphy *wiphy)
1139{
1140 if (!reg_is_world_roaming(wiphy))
1141 return;
1142 wiphy_update_beacon_reg(wiphy);
1143}
1144
1145void wiphy_update_regulatory(struct wiphy *wiphy,
1146 enum nl80211_reg_initiator initiator)
1147{
1148 enum ieee80211_band band;
1149
1150 if (ignore_reg_update(wiphy, initiator))
1151 goto out;
947 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 1152 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
948 if (wiphy->bands[band]) 1153 if (wiphy->bands[band])
949 handle_band(wiphy, band); 1154 handle_band(wiphy, band);
950 } 1155 }
1156out:
1157 reg_process_beacons(wiphy);
951 if (wiphy->reg_notifier) 1158 if (wiphy->reg_notifier)
952 wiphy->reg_notifier(wiphy, last_request); 1159 wiphy->reg_notifier(wiphy, last_request);
953} 1160}
@@ -1033,81 +1240,98 @@ static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd,
1033 return 0; 1240 return 0;
1034} 1241}
1035 1242
1036/* Return value which can be used by ignore_request() to indicate 1243/*
1037 * it has been determined we should intersect two regulatory domains */ 1244 * Return value which can be used by ignore_request() to indicate
1245 * it has been determined we should intersect two regulatory domains
1246 */
1038#define REG_INTERSECT 1 1247#define REG_INTERSECT 1
1039 1248
1040/* This has the logic which determines when a new request 1249/* This has the logic which determines when a new request
1041 * should be ignored. */ 1250 * should be ignored. */
1042static int ignore_request(struct wiphy *wiphy, enum reg_set_by set_by, 1251static int ignore_request(struct wiphy *wiphy,
1043 const char *alpha2) 1252 struct regulatory_request *pending_request)
1044{ 1253{
1254 struct wiphy *last_wiphy = NULL;
1255
1256 assert_cfg80211_lock();
1257
1045 /* All initial requests are respected */ 1258 /* All initial requests are respected */
1046 if (!last_request) 1259 if (!last_request)
1047 return 0; 1260 return 0;
1048 1261
1049 switch (set_by) { 1262 switch (pending_request->initiator) {
1050 case REGDOM_SET_BY_INIT: 1263 case NL80211_REGDOM_SET_BY_CORE:
1051 return -EINVAL; 1264 return -EINVAL;
1052 case REGDOM_SET_BY_CORE: 1265 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
1053 /* 1266
1054 * Always respect new wireless core hints, should only happen 1267 last_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
1055 * when updating the world regulatory domain at init. 1268
1056 */ 1269 if (unlikely(!is_an_alpha2(pending_request->alpha2)))
1057 return 0;
1058 case REGDOM_SET_BY_COUNTRY_IE:
1059 if (unlikely(!is_an_alpha2(alpha2)))
1060 return -EINVAL; 1270 return -EINVAL;
1061 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) { 1271 if (last_request->initiator ==
1062 if (last_request->wiphy != wiphy) { 1272 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
1273 if (last_wiphy != wiphy) {
1063 /* 1274 /*
1064 * Two cards with two APs claiming different 1275 * Two cards with two APs claiming different
1065 * different Country IE alpha2s. We could 1276 * different Country IE alpha2s. We could
1066 * intersect them, but that seems unlikely 1277 * intersect them, but that seems unlikely
1067 * to be correct. Reject second one for now. 1278 * to be correct. Reject second one for now.
1068 */ 1279 */
1069 if (!alpha2_equal(alpha2, 1280 if (regdom_changes(pending_request->alpha2))
1070 cfg80211_regdomain->alpha2))
1071 return -EOPNOTSUPP; 1281 return -EOPNOTSUPP;
1072 return -EALREADY; 1282 return -EALREADY;
1073 } 1283 }
1074 /* Two consecutive Country IE hints on the same wiphy. 1284 /*
1075 * This should be picked up early by the driver/stack */ 1285 * Two consecutive Country IE hints on the same wiphy.
1076 if (WARN_ON(!alpha2_equal(cfg80211_regdomain->alpha2, 1286 * This should be picked up early by the driver/stack
1077 alpha2))) 1287 */
1288 if (WARN_ON(regdom_changes(pending_request->alpha2)))
1078 return 0; 1289 return 0;
1079 return -EALREADY; 1290 return -EALREADY;
1080 } 1291 }
1081 return REG_INTERSECT; 1292 return REG_INTERSECT;
1082 case REGDOM_SET_BY_DRIVER: 1293 case NL80211_REGDOM_SET_BY_DRIVER:
1083 if (last_request->initiator == REGDOM_SET_BY_CORE) { 1294 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE) {
1084 if (is_old_static_regdom(cfg80211_regdomain)) 1295 if (is_old_static_regdom(cfg80211_regdomain))
1085 return 0; 1296 return 0;
1086 if (!alpha2_equal(cfg80211_regdomain->alpha2, alpha2)) 1297 if (regdom_changes(pending_request->alpha2))
1087 return 0; 1298 return 0;
1088 return -EALREADY; 1299 return -EALREADY;
1089 } 1300 }
1301
1302 /*
1303 * This would happen if you unplug and plug your card
1304 * back in or if you add a new device for which the previously
1305 * loaded card also agrees on the regulatory domain.
1306 */
1307 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
1308 !regdom_changes(pending_request->alpha2))
1309 return -EALREADY;
1310
1090 return REG_INTERSECT; 1311 return REG_INTERSECT;
1091 case REGDOM_SET_BY_USER: 1312 case NL80211_REGDOM_SET_BY_USER:
1092 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) 1313 if (last_request->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE)
1093 return REG_INTERSECT; 1314 return REG_INTERSECT;
1094 /* If the user knows better the user should set the regdom 1315 /*
1095 * to their country before the IE is picked up */ 1316 * If the user knows better the user should set the regdom
1096 if (last_request->initiator == REGDOM_SET_BY_USER && 1317 * to their country before the IE is picked up
1318 */
1319 if (last_request->initiator == NL80211_REGDOM_SET_BY_USER &&
1097 last_request->intersect) 1320 last_request->intersect)
1098 return -EOPNOTSUPP; 1321 return -EOPNOTSUPP;
1099 /* Process user requests only after previous user/driver/core 1322 /*
1100 * requests have been processed */ 1323 * Process user requests only after previous user/driver/core
1101 if (last_request->initiator == REGDOM_SET_BY_CORE || 1324 * requests have been processed
1102 last_request->initiator == REGDOM_SET_BY_DRIVER || 1325 */
1103 last_request->initiator == REGDOM_SET_BY_USER) { 1326 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE ||
1104 if (!alpha2_equal(last_request->alpha2, 1327 last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER ||
1105 cfg80211_regdomain->alpha2)) 1328 last_request->initiator == NL80211_REGDOM_SET_BY_USER) {
1329 if (regdom_changes(last_request->alpha2))
1106 return -EAGAIN; 1330 return -EAGAIN;
1107 } 1331 }
1108 1332
1109 if (!is_old_static_regdom(cfg80211_regdomain) && 1333 if (!is_old_static_regdom(cfg80211_regdomain) &&
1110 alpha2_equal(cfg80211_regdomain->alpha2, alpha2)) 1334 !regdom_changes(pending_request->alpha2))
1111 return -EALREADY; 1335 return -EALREADY;
1112 1336
1113 return 0; 1337 return 0;
@@ -1116,59 +1340,80 @@ static int ignore_request(struct wiphy *wiphy, enum reg_set_by set_by,
1116 return -EINVAL; 1340 return -EINVAL;
1117} 1341}
1118 1342
1119/* Caller must hold &cfg80211_drv_mutex */ 1343/**
1120int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by, 1344 * __regulatory_hint - hint to the wireless core a regulatory domain
1121 const char *alpha2, 1345 * @wiphy: if the hint comes from country information from an AP, this
1122 u32 country_ie_checksum, 1346 * is required to be set to the wiphy that received the information
1123 enum environment_cap env) 1347 * @pending_request: the regulatory request currently being processed
1348 *
1349 * The Wireless subsystem can use this function to hint to the wireless core
1350 * what it believes should be the current regulatory domain.
1351 *
1352 * Returns zero if all went fine, %-EALREADY if a regulatory domain had
1353 * already been set or other standard error codes.
1354 *
1355 * Caller must hold &cfg80211_mutex
1356 */
1357static int __regulatory_hint(struct wiphy *wiphy,
1358 struct regulatory_request *pending_request)
1124{ 1359{
1125 struct regulatory_request *request;
1126 bool intersect = false; 1360 bool intersect = false;
1127 int r = 0; 1361 int r = 0;
1128 1362
1129 r = ignore_request(wiphy, set_by, alpha2); 1363 assert_cfg80211_lock();
1364
1365 r = ignore_request(wiphy, pending_request);
1130 1366
1131 if (r == REG_INTERSECT) { 1367 if (r == REG_INTERSECT) {
1132 if (set_by == REGDOM_SET_BY_DRIVER) { 1368 if (pending_request->initiator ==
1369 NL80211_REGDOM_SET_BY_DRIVER) {
1133 r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain); 1370 r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain);
1134 if (r) 1371 if (r) {
1372 kfree(pending_request);
1135 return r; 1373 return r;
1374 }
1136 } 1375 }
1137 intersect = true; 1376 intersect = true;
1138 } else if (r) { 1377 } else if (r) {
1139 /* If the regulatory domain being requested by the 1378 /*
1379 * If the regulatory domain being requested by the
1140 * driver has already been set just copy it to the 1380 * driver has already been set just copy it to the
1141 * wiphy */ 1381 * wiphy
1142 if (r == -EALREADY && set_by == REGDOM_SET_BY_DRIVER) { 1382 */
1383 if (r == -EALREADY &&
1384 pending_request->initiator ==
1385 NL80211_REGDOM_SET_BY_DRIVER) {
1143 r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain); 1386 r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain);
1144 if (r) 1387 if (r) {
1388 kfree(pending_request);
1145 return r; 1389 return r;
1390 }
1146 r = -EALREADY; 1391 r = -EALREADY;
1147 goto new_request; 1392 goto new_request;
1148 } 1393 }
1394 kfree(pending_request);
1149 return r; 1395 return r;
1150 } 1396 }
1151 1397
1152new_request: 1398new_request:
1153 request = kzalloc(sizeof(struct regulatory_request), 1399 kfree(last_request);
1154 GFP_KERNEL);
1155 if (!request)
1156 return -ENOMEM;
1157 1400
1158 request->alpha2[0] = alpha2[0]; 1401 last_request = pending_request;
1159 request->alpha2[1] = alpha2[1]; 1402 last_request->intersect = intersect;
1160 request->initiator = set_by;
1161 request->wiphy = wiphy;
1162 request->intersect = intersect;
1163 request->country_ie_checksum = country_ie_checksum;
1164 request->country_ie_env = env;
1165 1403
1166 kfree(last_request); 1404 pending_request = NULL;
1167 last_request = request;
1168 1405
1169 /* When r == REG_INTERSECT we do need to call CRDA */ 1406 /* When r == REG_INTERSECT we do need to call CRDA */
1170 if (r < 0) 1407 if (r < 0) {
1408 /*
1409 * Since CRDA will not be called in this case as we already
1410 * have applied the requested regulatory domain before we just
1411 * inform userspace we have processed the request
1412 */
1413 if (r == -EALREADY)
1414 nl80211_send_reg_change_event(last_request);
1171 return r; 1415 return r;
1416 }
1172 1417
1173 /* 1418 /*
1174 * Note: When CONFIG_WIRELESS_OLD_REGULATORY is enabled 1419 * Note: When CONFIG_WIRELESS_OLD_REGULATORY is enabled
@@ -1180,34 +1425,194 @@ new_request:
1180 * 1425 *
1181 * to intersect with the static rd 1426 * to intersect with the static rd
1182 */ 1427 */
1183 return call_crda(alpha2); 1428 return call_crda(last_request->alpha2);
1184} 1429}
1185 1430
1186void regulatory_hint(struct wiphy *wiphy, const char *alpha2) 1431/* This currently only processes user and driver regulatory hints */
1432static void reg_process_hint(struct regulatory_request *reg_request)
1187{ 1433{
1188 int r; 1434 int r = 0;
1189 BUG_ON(!alpha2); 1435 struct wiphy *wiphy = NULL;
1436
1437 BUG_ON(!reg_request->alpha2);
1438
1439 mutex_lock(&cfg80211_mutex);
1440
1441 if (wiphy_idx_valid(reg_request->wiphy_idx))
1442 wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx);
1443
1444 if (reg_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
1445 !wiphy) {
1446 kfree(reg_request);
1447 goto out;
1448 }
1190 1449
1191 mutex_lock(&cfg80211_drv_mutex); 1450 r = __regulatory_hint(wiphy, reg_request);
1192 r = __regulatory_hint(wiphy, REGDOM_SET_BY_DRIVER,
1193 alpha2, 0, ENVIRON_ANY);
1194 /* This is required so that the orig_* parameters are saved */ 1451 /* This is required so that the orig_* parameters are saved */
1195 if (r == -EALREADY && wiphy->strict_regulatory) 1452 if (r == -EALREADY && wiphy && wiphy->strict_regulatory)
1196 wiphy_update_regulatory(wiphy, REGDOM_SET_BY_DRIVER); 1453 wiphy_update_regulatory(wiphy, reg_request->initiator);
1197 mutex_unlock(&cfg80211_drv_mutex); 1454out:
1455 mutex_unlock(&cfg80211_mutex);
1456}
1457
1458/* Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_* */
1459static void reg_process_pending_hints(void)
1460 {
1461 struct regulatory_request *reg_request;
1462
1463 spin_lock(&reg_requests_lock);
1464 while (!list_empty(&reg_requests_list)) {
1465 reg_request = list_first_entry(&reg_requests_list,
1466 struct regulatory_request,
1467 list);
1468 list_del_init(&reg_request->list);
1469
1470 spin_unlock(&reg_requests_lock);
1471 reg_process_hint(reg_request);
1472 spin_lock(&reg_requests_lock);
1473 }
1474 spin_unlock(&reg_requests_lock);
1475}
1476
1477/* Processes beacon hints -- this has nothing to do with country IEs */
1478static void reg_process_pending_beacon_hints(void)
1479{
1480 struct cfg80211_registered_device *drv;
1481 struct reg_beacon *pending_beacon, *tmp;
1482
1483 mutex_lock(&cfg80211_mutex);
1484
1485 /* This goes through the _pending_ beacon list */
1486 spin_lock_bh(&reg_pending_beacons_lock);
1487
1488 if (list_empty(&reg_pending_beacons)) {
1489 spin_unlock_bh(&reg_pending_beacons_lock);
1490 goto out;
1491 }
1492
1493 list_for_each_entry_safe(pending_beacon, tmp,
1494 &reg_pending_beacons, list) {
1495
1496 list_del_init(&pending_beacon->list);
1497
1498 /* Applies the beacon hint to current wiphys */
1499 list_for_each_entry(drv, &cfg80211_drv_list, list)
1500 wiphy_update_new_beacon(&drv->wiphy, pending_beacon);
1501
1502 /* Remembers the beacon hint for new wiphys or reg changes */
1503 list_add_tail(&pending_beacon->list, &reg_beacon_list);
1504 }
1505
1506 spin_unlock_bh(&reg_pending_beacons_lock);
1507out:
1508 mutex_unlock(&cfg80211_mutex);
1509}
1510
1511static void reg_todo(struct work_struct *work)
1512{
1513 reg_process_pending_hints();
1514 reg_process_pending_beacon_hints();
1515}
1516
1517static DECLARE_WORK(reg_work, reg_todo);
1518
1519static void queue_regulatory_request(struct regulatory_request *request)
1520{
1521 spin_lock(&reg_requests_lock);
1522 list_add_tail(&request->list, &reg_requests_list);
1523 spin_unlock(&reg_requests_lock);
1524
1525 schedule_work(&reg_work);
1526}
1527
1528/* Core regulatory hint -- happens once during cfg80211_init() */
1529static int regulatory_hint_core(const char *alpha2)
1530{
1531 struct regulatory_request *request;
1532
1533 BUG_ON(last_request);
1534
1535 request = kzalloc(sizeof(struct regulatory_request),
1536 GFP_KERNEL);
1537 if (!request)
1538 return -ENOMEM;
1539
1540 request->alpha2[0] = alpha2[0];
1541 request->alpha2[1] = alpha2[1];
1542 request->initiator = NL80211_REGDOM_SET_BY_CORE;
1543
1544 queue_regulatory_request(request);
1545
1546 return 0;
1547}
1548
1549/* User hints */
1550int regulatory_hint_user(const char *alpha2)
1551{
1552 struct regulatory_request *request;
1553
1554 BUG_ON(!alpha2);
1555
1556 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1557 if (!request)
1558 return -ENOMEM;
1559
1560 request->wiphy_idx = WIPHY_IDX_STALE;
1561 request->alpha2[0] = alpha2[0];
1562 request->alpha2[1] = alpha2[1];
1563 request->initiator = NL80211_REGDOM_SET_BY_USER,
1564
1565 queue_regulatory_request(request);
1566
1567 return 0;
1568}
1569
1570/* Driver hints */
1571int regulatory_hint(struct wiphy *wiphy, const char *alpha2)
1572{
1573 struct regulatory_request *request;
1574
1575 BUG_ON(!alpha2);
1576 BUG_ON(!wiphy);
1577
1578 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1579 if (!request)
1580 return -ENOMEM;
1581
1582 request->wiphy_idx = get_wiphy_idx(wiphy);
1583
1584 /* Must have registered wiphy first */
1585 BUG_ON(!wiphy_idx_valid(request->wiphy_idx));
1586
1587 request->alpha2[0] = alpha2[0];
1588 request->alpha2[1] = alpha2[1];
1589 request->initiator = NL80211_REGDOM_SET_BY_DRIVER;
1590
1591 queue_regulatory_request(request);
1592
1593 return 0;
1198} 1594}
1199EXPORT_SYMBOL(regulatory_hint); 1595EXPORT_SYMBOL(regulatory_hint);
1200 1596
1201static bool reg_same_country_ie_hint(struct wiphy *wiphy, 1597static bool reg_same_country_ie_hint(struct wiphy *wiphy,
1202 u32 country_ie_checksum) 1598 u32 country_ie_checksum)
1203{ 1599{
1204 if (!last_request->wiphy) 1600 struct wiphy *request_wiphy;
1601
1602 assert_cfg80211_lock();
1603
1604 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
1605
1606 if (!request_wiphy)
1205 return false; 1607 return false;
1206 if (likely(last_request->wiphy != wiphy)) 1608
1609 if (likely(request_wiphy != wiphy))
1207 return !country_ie_integrity_changes(country_ie_checksum); 1610 return !country_ie_integrity_changes(country_ie_checksum);
1208 /* We should not have let these through at this point, they 1611 /*
1612 * We should not have let these through at this point, they
1209 * should have been picked up earlier by the first alpha2 check 1613 * should have been picked up earlier by the first alpha2 check
1210 * on the device */ 1614 * on the device
1615 */
1211 if (WARN_ON(!country_ie_integrity_changes(country_ie_checksum))) 1616 if (WARN_ON(!country_ie_integrity_changes(country_ie_checksum)))
1212 return true; 1617 return true;
1213 return false; 1618 return false;
@@ -1221,11 +1626,14 @@ void regulatory_hint_11d(struct wiphy *wiphy,
1221 char alpha2[2]; 1626 char alpha2[2];
1222 u32 checksum = 0; 1627 u32 checksum = 0;
1223 enum environment_cap env = ENVIRON_ANY; 1628 enum environment_cap env = ENVIRON_ANY;
1629 struct regulatory_request *request;
1224 1630
1225 if (!last_request) 1631 mutex_lock(&cfg80211_mutex);
1226 return;
1227 1632
1228 mutex_lock(&cfg80211_drv_mutex); 1633 if (unlikely(!last_request)) {
1634 mutex_unlock(&cfg80211_mutex);
1635 return;
1636 }
1229 1637
1230 /* IE len must be evenly divisible by 2 */ 1638 /* IE len must be evenly divisible by 2 */
1231 if (country_ie_len & 0x01) 1639 if (country_ie_len & 0x01)
@@ -1234,9 +1642,11 @@ void regulatory_hint_11d(struct wiphy *wiphy,
1234 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) 1642 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1235 goto out; 1643 goto out;
1236 1644
1237 /* Pending country IE processing, this can happen after we 1645 /*
1646 * Pending country IE processing, this can happen after we
1238 * call CRDA and wait for a response if a beacon was received before 1647 * call CRDA and wait for a response if a beacon was received before
1239 * we were able to process the last regulatory_hint_11d() call */ 1648 * we were able to process the last regulatory_hint_11d() call
1649 */
1240 if (country_ie_regdomain) 1650 if (country_ie_regdomain)
1241 goto out; 1651 goto out;
1242 1652
@@ -1248,33 +1658,44 @@ void regulatory_hint_11d(struct wiphy *wiphy,
1248 else if (country_ie[2] == 'O') 1658 else if (country_ie[2] == 'O')
1249 env = ENVIRON_OUTDOOR; 1659 env = ENVIRON_OUTDOOR;
1250 1660
1251 /* We will run this for *every* beacon processed for the BSSID, so 1661 /*
1662 * We will run this for *every* beacon processed for the BSSID, so
1252 * we optimize an early check to exit out early if we don't have to 1663 * we optimize an early check to exit out early if we don't have to
1253 * do anything */ 1664 * do anything
1254 if (likely(last_request->wiphy)) { 1665 */
1666 if (likely(wiphy_idx_valid(last_request->wiphy_idx))) {
1255 struct cfg80211_registered_device *drv_last_ie; 1667 struct cfg80211_registered_device *drv_last_ie;
1256 1668
1257 drv_last_ie = wiphy_to_dev(last_request->wiphy); 1669 drv_last_ie =
1670 cfg80211_drv_by_wiphy_idx(last_request->wiphy_idx);
1258 1671
1259 /* Lets keep this simple -- we trust the first AP 1672 /*
1260 * after we intersect with CRDA */ 1673 * Lets keep this simple -- we trust the first AP
1261 if (likely(last_request->wiphy == wiphy)) { 1674 * after we intersect with CRDA
1262 /* Ignore IEs coming in on this wiphy with 1675 */
1263 * the same alpha2 and environment cap */ 1676 if (likely(&drv_last_ie->wiphy == wiphy)) {
1677 /*
1678 * Ignore IEs coming in on this wiphy with
1679 * the same alpha2 and environment cap
1680 */
1264 if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2, 1681 if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2,
1265 alpha2) && 1682 alpha2) &&
1266 env == drv_last_ie->env)) { 1683 env == drv_last_ie->env)) {
1267 goto out; 1684 goto out;
1268 } 1685 }
1269 /* the wiphy moved on to another BSSID or the AP 1686 /*
1687 * the wiphy moved on to another BSSID or the AP
1270 * was reconfigured. XXX: We need to deal with the 1688 * was reconfigured. XXX: We need to deal with the
1271 * case where the user suspends and goes to goes 1689 * case where the user suspends and goes to goes
1272 * to another country, and then gets IEs from an 1690 * to another country, and then gets IEs from an
1273 * AP with different settings */ 1691 * AP with different settings
1692 */
1274 goto out; 1693 goto out;
1275 } else { 1694 } else {
1276 /* Ignore IEs coming in on two separate wiphys with 1695 /*
1277 * the same alpha2 and environment cap */ 1696 * Ignore IEs coming in on two separate wiphys with
1697 * the same alpha2 and environment cap
1698 */
1278 if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2, 1699 if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2,
1279 alpha2) && 1700 alpha2) &&
1280 env == drv_last_ie->env)) { 1701 env == drv_last_ie->env)) {
@@ -1289,28 +1710,97 @@ void regulatory_hint_11d(struct wiphy *wiphy,
1289 if (!rd) 1710 if (!rd)
1290 goto out; 1711 goto out;
1291 1712
1292 /* This will not happen right now but we leave it here for the 1713 /*
1714 * This will not happen right now but we leave it here for the
1293 * the future when we want to add suspend/resume support and having 1715 * the future when we want to add suspend/resume support and having
1294 * the user move to another country after doing so, or having the user 1716 * the user move to another country after doing so, or having the user
1295 * move to another AP. Right now we just trust the first AP. This is why 1717 * move to another AP. Right now we just trust the first AP.
1296 * this is marked as likley(). If we hit this before we add this support 1718 *
1297 * we want to be informed of it as it would indicate a mistake in the 1719 * If we hit this before we add this support we want to be informed of
1298 * current design */ 1720 * it as it would indicate a mistake in the current design
1299 if (likely(WARN_ON(reg_same_country_ie_hint(wiphy, checksum)))) 1721 */
1300 goto out; 1722 if (WARN_ON(reg_same_country_ie_hint(wiphy, checksum)))
1723 goto free_rd_out;
1724
1725 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1726 if (!request)
1727 goto free_rd_out;
1301 1728
1302 /* We keep this around for when CRDA comes back with a response so 1729 /*
1303 * we can intersect with that */ 1730 * We keep this around for when CRDA comes back with a response so
1731 * we can intersect with that
1732 */
1304 country_ie_regdomain = rd; 1733 country_ie_regdomain = rd;
1305 1734
1306 __regulatory_hint(wiphy, REGDOM_SET_BY_COUNTRY_IE, 1735 request->wiphy_idx = get_wiphy_idx(wiphy);
1307 country_ie_regdomain->alpha2, checksum, env); 1736 request->alpha2[0] = rd->alpha2[0];
1737 request->alpha2[1] = rd->alpha2[1];
1738 request->initiator = NL80211_REGDOM_SET_BY_COUNTRY_IE;
1739 request->country_ie_checksum = checksum;
1740 request->country_ie_env = env;
1308 1741
1742 mutex_unlock(&cfg80211_mutex);
1743
1744 queue_regulatory_request(request);
1745
1746 return;
1747
1748free_rd_out:
1749 kfree(rd);
1309out: 1750out:
1310 mutex_unlock(&cfg80211_drv_mutex); 1751 mutex_unlock(&cfg80211_mutex);
1311} 1752}
1312EXPORT_SYMBOL(regulatory_hint_11d); 1753EXPORT_SYMBOL(regulatory_hint_11d);
1313 1754
1755static bool freq_is_chan_12_13_14(u16 freq)
1756{
1757 if (freq == ieee80211_channel_to_frequency(12) ||
1758 freq == ieee80211_channel_to_frequency(13) ||
1759 freq == ieee80211_channel_to_frequency(14))
1760 return true;
1761 return false;
1762}
1763
1764int regulatory_hint_found_beacon(struct wiphy *wiphy,
1765 struct ieee80211_channel *beacon_chan,
1766 gfp_t gfp)
1767{
1768 struct reg_beacon *reg_beacon;
1769
1770 if (likely((beacon_chan->beacon_found ||
1771 (beacon_chan->flags & IEEE80211_CHAN_RADAR) ||
1772 (beacon_chan->band == IEEE80211_BAND_2GHZ &&
1773 !freq_is_chan_12_13_14(beacon_chan->center_freq)))))
1774 return 0;
1775
1776 reg_beacon = kzalloc(sizeof(struct reg_beacon), gfp);
1777 if (!reg_beacon)
1778 return -ENOMEM;
1779
1780#ifdef CONFIG_CFG80211_REG_DEBUG
1781 printk(KERN_DEBUG "cfg80211: Found new beacon on "
1782 "frequency: %d MHz (Ch %d) on %s\n",
1783 beacon_chan->center_freq,
1784 ieee80211_frequency_to_channel(beacon_chan->center_freq),
1785 wiphy_name(wiphy));
1786#endif
1787 memcpy(&reg_beacon->chan, beacon_chan,
1788 sizeof(struct ieee80211_channel));
1789
1790
1791 /*
1792 * Since we can be called from BH or and non-BH context
1793 * we must use spin_lock_bh()
1794 */
1795 spin_lock_bh(&reg_pending_beacons_lock);
1796 list_add_tail(&reg_beacon->list, &reg_pending_beacons);
1797 spin_unlock_bh(&reg_pending_beacons_lock);
1798
1799 schedule_work(&reg_work);
1800
1801 return 0;
1802}
1803
1314static void print_rd_rules(const struct ieee80211_regdomain *rd) 1804static void print_rd_rules(const struct ieee80211_regdomain *rd)
1315{ 1805{
1316 unsigned int i; 1806 unsigned int i;
@@ -1326,8 +1816,10 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
1326 freq_range = &reg_rule->freq_range; 1816 freq_range = &reg_rule->freq_range;
1327 power_rule = &reg_rule->power_rule; 1817 power_rule = &reg_rule->power_rule;
1328 1818
1329 /* There may not be documentation for max antenna gain 1819 /*
1330 * in certain regions */ 1820 * There may not be documentation for max antenna gain
1821 * in certain regions
1822 */
1331 if (power_rule->max_antenna_gain) 1823 if (power_rule->max_antenna_gain)
1332 printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), " 1824 printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), "
1333 "(%d mBi, %d mBm)\n", 1825 "(%d mBi, %d mBm)\n",
@@ -1350,13 +1842,13 @@ static void print_regdomain(const struct ieee80211_regdomain *rd)
1350{ 1842{
1351 1843
1352 if (is_intersected_alpha2(rd->alpha2)) { 1844 if (is_intersected_alpha2(rd->alpha2)) {
1353 struct wiphy *wiphy = NULL;
1354 struct cfg80211_registered_device *drv;
1355 1845
1356 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) { 1846 if (last_request->initiator ==
1357 if (last_request->wiphy) { 1847 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
1358 wiphy = last_request->wiphy; 1848 struct cfg80211_registered_device *drv;
1359 drv = wiphy_to_dev(wiphy); 1849 drv = cfg80211_drv_by_wiphy_idx(
1850 last_request->wiphy_idx);
1851 if (drv) {
1360 printk(KERN_INFO "cfg80211: Current regulatory " 1852 printk(KERN_INFO "cfg80211: Current regulatory "
1361 "domain updated by AP to: %c%c\n", 1853 "domain updated by AP to: %c%c\n",
1362 drv->country_ie_alpha2[0], 1854 drv->country_ie_alpha2[0],
@@ -1422,7 +1914,7 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
1422{ 1914{
1423 const struct ieee80211_regdomain *intersected_rd = NULL; 1915 const struct ieee80211_regdomain *intersected_rd = NULL;
1424 struct cfg80211_registered_device *drv = NULL; 1916 struct cfg80211_registered_device *drv = NULL;
1425 struct wiphy *wiphy = NULL; 1917 struct wiphy *request_wiphy;
1426 /* Some basic sanity checks first */ 1918 /* Some basic sanity checks first */
1427 1919
1428 if (is_world_regdom(rd->alpha2)) { 1920 if (is_world_regdom(rd->alpha2)) {
@@ -1439,23 +1931,27 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
1439 if (!last_request) 1931 if (!last_request)
1440 return -EINVAL; 1932 return -EINVAL;
1441 1933
1442 /* Lets only bother proceeding on the same alpha2 if the current 1934 /*
1935 * Lets only bother proceeding on the same alpha2 if the current
1443 * rd is non static (it means CRDA was present and was used last) 1936 * rd is non static (it means CRDA was present and was used last)
1444 * and the pending request came in from a country IE */ 1937 * and the pending request came in from a country IE
1445 if (last_request->initiator != REGDOM_SET_BY_COUNTRY_IE) { 1938 */
1446 /* If someone else asked us to change the rd lets only bother 1939 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
1447 * checking if the alpha2 changes if CRDA was already called */ 1940 /*
1941 * If someone else asked us to change the rd lets only bother
1942 * checking if the alpha2 changes if CRDA was already called
1943 */
1448 if (!is_old_static_regdom(cfg80211_regdomain) && 1944 if (!is_old_static_regdom(cfg80211_regdomain) &&
1449 !regdom_changed(rd->alpha2)) 1945 !regdom_changes(rd->alpha2))
1450 return -EINVAL; 1946 return -EINVAL;
1451 } 1947 }
1452 1948
1453 wiphy = last_request->wiphy; 1949 /*
1454 1950 * Now lets set the regulatory domain, update all driver channels
1455 /* Now lets set the regulatory domain, update all driver channels
1456 * and finally inform them of what we have done, in case they want 1951 * and finally inform them of what we have done, in case they want
1457 * to review or adjust their own settings based on their own 1952 * to review or adjust their own settings based on their own
1458 * internal EEPROM data */ 1953 * internal EEPROM data
1954 */
1459 1955
1460 if (WARN_ON(!reg_is_valid_request(rd->alpha2))) 1956 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
1461 return -EINVAL; 1957 return -EINVAL;
@@ -1467,21 +1963,25 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
1467 return -EINVAL; 1963 return -EINVAL;
1468 } 1964 }
1469 1965
1966 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
1967
1470 if (!last_request->intersect) { 1968 if (!last_request->intersect) {
1471 int r; 1969 int r;
1472 1970
1473 if (last_request->initiator != REGDOM_SET_BY_DRIVER) { 1971 if (last_request->initiator != NL80211_REGDOM_SET_BY_DRIVER) {
1474 reset_regdomains(); 1972 reset_regdomains();
1475 cfg80211_regdomain = rd; 1973 cfg80211_regdomain = rd;
1476 return 0; 1974 return 0;
1477 } 1975 }
1478 1976
1479 /* For a driver hint, lets copy the regulatory domain the 1977 /*
1480 * driver wanted to the wiphy to deal with conflicts */ 1978 * For a driver hint, lets copy the regulatory domain the
1979 * driver wanted to the wiphy to deal with conflicts
1980 */
1481 1981
1482 BUG_ON(last_request->wiphy->regd); 1982 BUG_ON(request_wiphy->regd);
1483 1983
1484 r = reg_copy_regd(&last_request->wiphy->regd, rd); 1984 r = reg_copy_regd(&request_wiphy->regd, rd);
1485 if (r) 1985 if (r)
1486 return r; 1986 return r;
1487 1987
@@ -1492,17 +1992,19 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
1492 1992
1493 /* Intersection requires a bit more work */ 1993 /* Intersection requires a bit more work */
1494 1994
1495 if (last_request->initiator != REGDOM_SET_BY_COUNTRY_IE) { 1995 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
1496 1996
1497 intersected_rd = regdom_intersect(rd, cfg80211_regdomain); 1997 intersected_rd = regdom_intersect(rd, cfg80211_regdomain);
1498 if (!intersected_rd) 1998 if (!intersected_rd)
1499 return -EINVAL; 1999 return -EINVAL;
1500 2000
1501 /* We can trash what CRDA provided now. 2001 /*
2002 * We can trash what CRDA provided now.
1502 * However if a driver requested this specific regulatory 2003 * However if a driver requested this specific regulatory
1503 * domain we keep it for its private use */ 2004 * domain we keep it for its private use
1504 if (last_request->initiator == REGDOM_SET_BY_DRIVER) 2005 */
1505 last_request->wiphy->regd = rd; 2006 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER)
2007 request_wiphy->regd = rd;
1506 else 2008 else
1507 kfree(rd); 2009 kfree(rd);
1508 2010
@@ -1522,8 +2024,10 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
1522 BUG_ON(!country_ie_regdomain); 2024 BUG_ON(!country_ie_regdomain);
1523 2025
1524 if (rd != country_ie_regdomain) { 2026 if (rd != country_ie_regdomain) {
1525 /* Intersect what CRDA returned and our what we 2027 /*
1526 * had built from the Country IE received */ 2028 * Intersect what CRDA returned and our what we
2029 * had built from the Country IE received
2030 */
1527 2031
1528 intersected_rd = regdom_intersect(rd, country_ie_regdomain); 2032 intersected_rd = regdom_intersect(rd, country_ie_regdomain);
1529 2033
@@ -1533,16 +2037,18 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
1533 kfree(country_ie_regdomain); 2037 kfree(country_ie_regdomain);
1534 country_ie_regdomain = NULL; 2038 country_ie_regdomain = NULL;
1535 } else { 2039 } else {
1536 /* This would happen when CRDA was not present and 2040 /*
2041 * This would happen when CRDA was not present and
1537 * OLD_REGULATORY was enabled. We intersect our Country 2042 * OLD_REGULATORY was enabled. We intersect our Country
1538 * IE rd and what was set on cfg80211 originally */ 2043 * IE rd and what was set on cfg80211 originally
2044 */
1539 intersected_rd = regdom_intersect(rd, cfg80211_regdomain); 2045 intersected_rd = regdom_intersect(rd, cfg80211_regdomain);
1540 } 2046 }
1541 2047
1542 if (!intersected_rd) 2048 if (!intersected_rd)
1543 return -EINVAL; 2049 return -EINVAL;
1544 2050
1545 drv = wiphy_to_dev(wiphy); 2051 drv = wiphy_to_dev(request_wiphy);
1546 2052
1547 drv->country_ie_alpha2[0] = rd->alpha2[0]; 2053 drv->country_ie_alpha2[0] = rd->alpha2[0];
1548 drv->country_ie_alpha2[1] = rd->alpha2[1]; 2054 drv->country_ie_alpha2[1] = rd->alpha2[1];
@@ -1560,13 +2066,17 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
1560} 2066}
1561 2067
1562 2068
1563/* Use this call to set the current regulatory domain. Conflicts with 2069/*
2070 * Use this call to set the current regulatory domain. Conflicts with
1564 * multiple drivers can be ironed out later. Caller must've already 2071 * multiple drivers can be ironed out later. Caller must've already
1565 * kmalloc'd the rd structure. Caller must hold cfg80211_drv_mutex */ 2072 * kmalloc'd the rd structure. Caller must hold cfg80211_mutex
2073 */
1566int set_regdom(const struct ieee80211_regdomain *rd) 2074int set_regdom(const struct ieee80211_regdomain *rd)
1567{ 2075{
1568 int r; 2076 int r;
1569 2077
2078 assert_cfg80211_lock();
2079
1570 /* Note that this doesn't update the wiphys, this is done below */ 2080 /* Note that this doesn't update the wiphys, this is done below */
1571 r = __set_regdom(rd); 2081 r = __set_regdom(rd);
1572 if (r) { 2082 if (r) {
@@ -1583,57 +2093,87 @@ int set_regdom(const struct ieee80211_regdomain *rd)
1583 2093
1584 print_regdomain(cfg80211_regdomain); 2094 print_regdomain(cfg80211_regdomain);
1585 2095
2096 nl80211_send_reg_change_event(last_request);
2097
1586 return r; 2098 return r;
1587} 2099}
1588 2100
1589/* Caller must hold cfg80211_drv_mutex */ 2101/* Caller must hold cfg80211_mutex */
1590void reg_device_remove(struct wiphy *wiphy) 2102void reg_device_remove(struct wiphy *wiphy)
1591{ 2103{
2104 struct wiphy *request_wiphy;
2105
2106 assert_cfg80211_lock();
2107
2108 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
2109
1592 kfree(wiphy->regd); 2110 kfree(wiphy->regd);
1593 if (!last_request || !last_request->wiphy) 2111 if (!last_request || !request_wiphy)
1594 return; 2112 return;
1595 if (last_request->wiphy != wiphy) 2113 if (request_wiphy != wiphy)
1596 return; 2114 return;
1597 last_request->wiphy = NULL; 2115 last_request->wiphy_idx = WIPHY_IDX_STALE;
1598 last_request->country_ie_env = ENVIRON_ANY; 2116 last_request->country_ie_env = ENVIRON_ANY;
1599} 2117}
1600 2118
1601int regulatory_init(void) 2119int regulatory_init(void)
1602{ 2120{
1603 int err; 2121 int err = 0;
1604 2122
1605 reg_pdev = platform_device_register_simple("regulatory", 0, NULL, 0); 2123 reg_pdev = platform_device_register_simple("regulatory", 0, NULL, 0);
1606 if (IS_ERR(reg_pdev)) 2124 if (IS_ERR(reg_pdev))
1607 return PTR_ERR(reg_pdev); 2125 return PTR_ERR(reg_pdev);
1608 2126
2127 spin_lock_init(&reg_requests_lock);
2128 spin_lock_init(&reg_pending_beacons_lock);
2129
1609#ifdef CONFIG_WIRELESS_OLD_REGULATORY 2130#ifdef CONFIG_WIRELESS_OLD_REGULATORY
1610 cfg80211_regdomain = static_regdom(ieee80211_regdom); 2131 cfg80211_regdomain = static_regdom(ieee80211_regdom);
1611 2132
1612 printk(KERN_INFO "cfg80211: Using static regulatory domain info\n"); 2133 printk(KERN_INFO "cfg80211: Using static regulatory domain info\n");
1613 print_regdomain_info(cfg80211_regdomain); 2134 print_regdomain_info(cfg80211_regdomain);
1614 /* The old code still requests for a new regdomain and if 2135 /*
2136 * The old code still requests for a new regdomain and if
1615 * you have CRDA you get it updated, otherwise you get 2137 * you have CRDA you get it updated, otherwise you get
1616 * stuck with the static values. We ignore "EU" code as 2138 * stuck with the static values. We ignore "EU" code as
1617 * that is not a valid ISO / IEC 3166 alpha2 */ 2139 * that is not a valid ISO / IEC 3166 alpha2
2140 */
1618 if (ieee80211_regdom[0] != 'E' || ieee80211_regdom[1] != 'U') 2141 if (ieee80211_regdom[0] != 'E' || ieee80211_regdom[1] != 'U')
1619 err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE, 2142 err = regulatory_hint_core(ieee80211_regdom);
1620 ieee80211_regdom, 0, ENVIRON_ANY);
1621#else 2143#else
1622 cfg80211_regdomain = cfg80211_world_regdom; 2144 cfg80211_regdomain = cfg80211_world_regdom;
1623 2145
1624 err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE, "00", 0, ENVIRON_ANY); 2146 err = regulatory_hint_core("00");
1625 if (err)
1626 printk(KERN_ERR "cfg80211: calling CRDA failed - "
1627 "unable to update world regulatory domain, "
1628 "using static definition\n");
1629#endif 2147#endif
2148 if (err) {
2149 if (err == -ENOMEM)
2150 return err;
2151 /*
2152 * N.B. kobject_uevent_env() can fail mainly for when we're out
2153 * memory which is handled and propagated appropriately above
2154 * but it can also fail during a netlink_broadcast() or during
2155 * early boot for call_usermodehelper(). For now treat these
2156 * errors as non-fatal.
2157 */
2158 printk(KERN_ERR "cfg80211: kobject_uevent_env() was unable "
2159 "to call CRDA during init");
2160#ifdef CONFIG_CFG80211_REG_DEBUG
2161 /* We want to find out exactly why when debugging */
2162 WARN_ON(err);
2163#endif
2164 }
1630 2165
1631 return 0; 2166 return 0;
1632} 2167}
1633 2168
1634void regulatory_exit(void) 2169void regulatory_exit(void)
1635{ 2170{
1636 mutex_lock(&cfg80211_drv_mutex); 2171 struct regulatory_request *reg_request, *tmp;
2172 struct reg_beacon *reg_beacon, *btmp;
2173
2174 cancel_work_sync(&reg_work);
2175
2176 mutex_lock(&cfg80211_mutex);
1637 2177
1638 reset_regdomains(); 2178 reset_regdomains();
1639 2179
@@ -1644,5 +2184,33 @@ void regulatory_exit(void)
1644 2184
1645 platform_device_unregister(reg_pdev); 2185 platform_device_unregister(reg_pdev);
1646 2186
1647 mutex_unlock(&cfg80211_drv_mutex); 2187 spin_lock_bh(&reg_pending_beacons_lock);
2188 if (!list_empty(&reg_pending_beacons)) {
2189 list_for_each_entry_safe(reg_beacon, btmp,
2190 &reg_pending_beacons, list) {
2191 list_del(&reg_beacon->list);
2192 kfree(reg_beacon);
2193 }
2194 }
2195 spin_unlock_bh(&reg_pending_beacons_lock);
2196
2197 if (!list_empty(&reg_beacon_list)) {
2198 list_for_each_entry_safe(reg_beacon, btmp,
2199 &reg_beacon_list, list) {
2200 list_del(&reg_beacon->list);
2201 kfree(reg_beacon);
2202 }
2203 }
2204
2205 spin_lock(&reg_requests_lock);
2206 if (!list_empty(&reg_requests_list)) {
2207 list_for_each_entry_safe(reg_request, tmp,
2208 &reg_requests_list, list) {
2209 list_del(&reg_request->list);
2210 kfree(reg_request);
2211 }
2212 }
2213 spin_unlock(&reg_requests_lock);
2214
2215 mutex_unlock(&cfg80211_mutex);
1648} 2216}