2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2008 Luis R. Rodriguez <lrodriguz@atheros.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
13 * DOC: Wireless regulatory infrastructure
15 * The usual implementation is for a driver to read a device EEPROM to
16 * determine which regulatory domain it should be operating under, then
17 * looking up the allowable channels in a driver-local table and finally
18 * registering those channels in the wiphy structure.
20 * Another set of compliance enforcement is for drivers to use their
21 * own compliance limits which can be stored on the EEPROM. The host
22 * driver or firmware may ensure these are used.
24 * In addition to all this we provide an extra layer of regulatory
25 * conformance. For drivers which do not have any regulatory
26 * information CRDA provides the complete regulatory solution.
27 * For others it provides a community effort on further restrictions
28 * to enhance compliance.
30 * Note: When number of rules --> infinity we will not be able to
31 * index on alpha2 any more, instead we'll probably have to
32 * rely on some SHA1 checksum of the regdomain for example.
35 #include <linux/kernel.h>
36 #include <linux/slab.h>
37 #include <linux/list.h>
38 #include <linux/random.h>
39 #include <linux/nl80211.h>
40 #include <linux/platform_device.h>
41 #include <net/cfg80211.h>
47 #ifdef CONFIG_CFG80211_REG_DEBUG
48 #define REG_DBG_PRINT(format, args...) \
50 printk(KERN_DEBUG format , ## args); \
53 #define REG_DBG_PRINT(args...)
56 /* Receipt of information from last regulatory request */
57 static struct regulatory_request *last_request;
59 /* To trigger userspace events */
60 static struct platform_device *reg_pdev;
63 * Central wireless core regulatory domains, we only need two,
64 * the current one and a world regulatory domain in case we have no
65 * information to give us an alpha2
67 const struct ieee80211_regdomain *cfg80211_regdomain;
70 * We use this as a place for the rd structure built from the
71 * last parsed country IE to rest until CRDA gets back to us with
72 * what it thinks should apply for the same country
74 static const struct ieee80211_regdomain *country_ie_regdomain;
77 * Protects static reg.c components:
78 * - cfg80211_world_regdom
80 * - country_ie_regdomain
83 DEFINE_MUTEX(reg_mutex);
84 #define assert_reg_lock() WARN_ON(!mutex_is_locked(®_mutex))
86 /* Used to queue up regulatory hints */
87 static LIST_HEAD(reg_requests_list);
88 static spinlock_t reg_requests_lock;
90 /* Used to queue up beacon hints for review */
91 static LIST_HEAD(reg_pending_beacons);
92 static spinlock_t reg_pending_beacons_lock;
94 /* Used to keep track of processed beacon hints */
95 static LIST_HEAD(reg_beacon_list);
98 struct list_head list;
99 struct ieee80211_channel chan;
102 /* We keep a static world regulatory domain in case of the absence of CRDA */
103 static const struct ieee80211_regdomain world_regdom = {
107 /* IEEE 802.11b/g, channels 1..11 */
108 REG_RULE(2412-10, 2462+10, 40, 6, 20, 0),
109 /* IEEE 802.11b/g, channels 12..13. No HT40
110 * channel fits here. */
111 REG_RULE(2467-10, 2472+10, 20, 6, 20,
112 NL80211_RRF_PASSIVE_SCAN |
113 NL80211_RRF_NO_IBSS),
114 /* IEEE 802.11 channel 14 - Only JP enables
115 * this and for 802.11b only */
116 REG_RULE(2484-10, 2484+10, 20, 6, 20,
117 NL80211_RRF_PASSIVE_SCAN |
118 NL80211_RRF_NO_IBSS |
119 NL80211_RRF_NO_OFDM),
120 /* IEEE 802.11a, channel 36..48 */
121 REG_RULE(5180-10, 5240+10, 40, 6, 20,
122 NL80211_RRF_PASSIVE_SCAN |
123 NL80211_RRF_NO_IBSS),
125 /* NB: 5260 MHz - 5700 MHz requies DFS */
127 /* IEEE 802.11a, channel 149..165 */
128 REG_RULE(5745-10, 5825+10, 40, 6, 20,
129 NL80211_RRF_PASSIVE_SCAN |
130 NL80211_RRF_NO_IBSS),
134 static const struct ieee80211_regdomain *cfg80211_world_regdom =
137 static char *ieee80211_regdom = "00";
138 static char user_alpha2[2];
140 module_param(ieee80211_regdom, charp, 0444);
141 MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
143 static void reset_regdomains(void)
145 /* avoid freeing static information or freeing something twice */
146 if (cfg80211_regdomain == cfg80211_world_regdom)
147 cfg80211_regdomain = NULL;
148 if (cfg80211_world_regdom == &world_regdom)
149 cfg80211_world_regdom = NULL;
150 if (cfg80211_regdomain == &world_regdom)
151 cfg80211_regdomain = NULL;
153 kfree(cfg80211_regdomain);
154 kfree(cfg80211_world_regdom);
156 cfg80211_world_regdom = &world_regdom;
157 cfg80211_regdomain = NULL;
161 * Dynamic world regulatory domain requested by the wireless
162 * core upon initialization
164 static void update_world_regdomain(const struct ieee80211_regdomain *rd)
166 BUG_ON(!last_request);
170 cfg80211_world_regdom = rd;
171 cfg80211_regdomain = rd;
174 bool is_world_regdom(const char *alpha2)
178 if (alpha2[0] == '0' && alpha2[1] == '0')
183 static bool is_alpha2_set(const char *alpha2)
187 if (alpha2[0] != 0 && alpha2[1] != 0)
192 static bool is_alpha_upper(char letter)
195 if (letter >= 65 && letter <= 90)
200 static bool is_unknown_alpha2(const char *alpha2)
205 * Special case where regulatory domain was built by driver
206 * but a specific alpha2 cannot be determined
208 if (alpha2[0] == '9' && alpha2[1] == '9')
213 static bool is_intersected_alpha2(const char *alpha2)
218 * Special case where regulatory domain is the
219 * result of an intersection between two regulatory domain
222 if (alpha2[0] == '9' && alpha2[1] == '8')
227 static bool is_an_alpha2(const char *alpha2)
231 if (is_alpha_upper(alpha2[0]) && is_alpha_upper(alpha2[1]))
236 static bool alpha2_equal(const char *alpha2_x, const char *alpha2_y)
238 if (!alpha2_x || !alpha2_y)
240 if (alpha2_x[0] == alpha2_y[0] &&
241 alpha2_x[1] == alpha2_y[1])
246 static bool regdom_changes(const char *alpha2)
248 assert_cfg80211_lock();
250 if (!cfg80211_regdomain)
252 if (alpha2_equal(cfg80211_regdomain->alpha2, alpha2))
258 * The NL80211_REGDOM_SET_BY_USER regdom alpha2 is cached, this lets
259 * you know if a valid regulatory hint with NL80211_REGDOM_SET_BY_USER
260 * has ever been issued.
262 static bool is_user_regdom_saved(void)
264 if (user_alpha2[0] == '9' && user_alpha2[1] == '7')
267 /* This would indicate a mistake on the design */
268 if (WARN((!is_world_regdom(user_alpha2) &&
269 !is_an_alpha2(user_alpha2)),
270 "Unexpected user alpha2: %c%c\n",
279 * country_ie_integrity_changes - tells us if the country IE has changed
280 * @checksum: checksum of country IE of fields we are interested in
282 * If the country IE has not changed you can ignore it safely. This is
283 * useful to determine if two devices are seeing two different country IEs
284 * even on the same alpha2. Note that this will return false if no IE has
285 * been set on the wireless core yet.
287 static bool country_ie_integrity_changes(u32 checksum)
289 /* If no IE has been set then the checksum doesn't change */
290 if (unlikely(!last_request->country_ie_checksum))
292 if (unlikely(last_request->country_ie_checksum != checksum))
297 static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd,
298 const struct ieee80211_regdomain *src_regd)
300 struct ieee80211_regdomain *regd;
301 int size_of_regd = 0;
304 size_of_regd = sizeof(struct ieee80211_regdomain) +
305 ((src_regd->n_reg_rules + 1) * sizeof(struct ieee80211_reg_rule));
307 regd = kzalloc(size_of_regd, GFP_KERNEL);
311 memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain));
313 for (i = 0; i < src_regd->n_reg_rules; i++)
314 memcpy(®d->reg_rules[i], &src_regd->reg_rules[i],
315 sizeof(struct ieee80211_reg_rule));
321 #ifdef CONFIG_CFG80211_INTERNAL_REGDB
322 struct reg_regdb_search_request {
324 struct list_head list;
327 static LIST_HEAD(reg_regdb_search_list);
328 static DEFINE_SPINLOCK(reg_regdb_search_lock);
330 static void reg_regdb_search(struct work_struct *work)
332 struct reg_regdb_search_request *request;
333 const struct ieee80211_regdomain *curdom, *regdom;
336 spin_lock(®_regdb_search_lock);
337 while (!list_empty(®_regdb_search_list)) {
338 request = list_first_entry(®_regdb_search_list,
339 struct reg_regdb_search_request,
341 list_del(&request->list);
343 for (i=0; i<reg_regdb_size; i++) {
344 curdom = reg_regdb[i];
346 if (!memcmp(request->alpha2, curdom->alpha2, 2)) {
347 r = reg_copy_regd(®dom, curdom);
350 spin_unlock(®_regdb_search_lock);
351 mutex_lock(&cfg80211_mutex);
353 mutex_unlock(&cfg80211_mutex);
354 spin_lock(®_regdb_search_lock);
361 spin_unlock(®_regdb_search_lock);
364 static DECLARE_WORK(reg_regdb_work, reg_regdb_search);
366 static void reg_regdb_query(const char *alpha2)
368 struct reg_regdb_search_request *request;
373 request = kzalloc(sizeof(struct reg_regdb_search_request), GFP_KERNEL);
377 memcpy(request->alpha2, alpha2, 2);
379 spin_lock(®_regdb_search_lock);
380 list_add_tail(&request->list, ®_regdb_search_list);
381 spin_unlock(®_regdb_search_lock);
383 schedule_work(®_regdb_work);
386 static inline void reg_regdb_query(const char *alpha2) {}
387 #endif /* CONFIG_CFG80211_INTERNAL_REGDB */
390 * This lets us keep regulatory code which is updated on a regulatory
391 * basis in userspace.
393 static int call_crda(const char *alpha2)
395 char country_env[9 + 2] = "COUNTRY=";
401 if (!is_world_regdom((char *) alpha2))
402 printk(KERN_INFO "cfg80211: Calling CRDA for country: %c%c\n",
403 alpha2[0], alpha2[1]);
405 printk(KERN_INFO "cfg80211: Calling CRDA to update world "
406 "regulatory domain\n");
408 /* query internal regulatory database (if it exists) */
409 reg_regdb_query(alpha2);
411 country_env[8] = alpha2[0];
412 country_env[9] = alpha2[1];
414 return kobject_uevent_env(®_pdev->dev.kobj, KOBJ_CHANGE, envp);
417 /* Used by nl80211 before kmalloc'ing our regulatory domain */
418 bool reg_is_valid_request(const char *alpha2)
420 assert_cfg80211_lock();
425 return alpha2_equal(last_request->alpha2, alpha2);
428 /* Sanity check on a regulatory rule */
429 static bool is_valid_reg_rule(const struct ieee80211_reg_rule *rule)
431 const struct ieee80211_freq_range *freq_range = &rule->freq_range;
434 if (freq_range->start_freq_khz <= 0 || freq_range->end_freq_khz <= 0)
437 if (freq_range->start_freq_khz > freq_range->end_freq_khz)
440 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
442 if (freq_range->end_freq_khz <= freq_range->start_freq_khz ||
443 freq_range->max_bandwidth_khz > freq_diff)
449 static bool is_valid_rd(const struct ieee80211_regdomain *rd)
451 const struct ieee80211_reg_rule *reg_rule = NULL;
454 if (!rd->n_reg_rules)
457 if (WARN_ON(rd->n_reg_rules > NL80211_MAX_SUPP_REG_RULES))
460 for (i = 0; i < rd->n_reg_rules; i++) {
461 reg_rule = &rd->reg_rules[i];
462 if (!is_valid_reg_rule(reg_rule))
469 static bool reg_does_bw_fit(const struct ieee80211_freq_range *freq_range,
473 u32 start_freq_khz, end_freq_khz;
475 start_freq_khz = center_freq_khz - (bw_khz/2);
476 end_freq_khz = center_freq_khz + (bw_khz/2);
478 if (start_freq_khz >= freq_range->start_freq_khz &&
479 end_freq_khz <= freq_range->end_freq_khz)
486 * freq_in_rule_band - tells us if a frequency is in a frequency band
487 * @freq_range: frequency rule we want to query
488 * @freq_khz: frequency we are inquiring about
490 * This lets us know if a specific frequency rule is or is not relevant to
491 * a specific frequency's band. Bands are device specific and artificial
492 * definitions (the "2.4 GHz band" and the "5 GHz band"), however it is
493 * safe for now to assume that a frequency rule should not be part of a
494 * frequency's band if the start freq or end freq are off by more than 2 GHz.
495 * This resolution can be lowered and should be considered as we add
496 * regulatory rule support for other "bands".
498 static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range,
501 #define ONE_GHZ_IN_KHZ 1000000
502 if (abs(freq_khz - freq_range->start_freq_khz) <= (2 * ONE_GHZ_IN_KHZ))
504 if (abs(freq_khz - freq_range->end_freq_khz) <= (2 * ONE_GHZ_IN_KHZ))
507 #undef ONE_GHZ_IN_KHZ
511 * This is a work around for sanity checking ieee80211_channel_to_frequency()'s
512 * work. ieee80211_channel_to_frequency() can for example currently provide a
513 * 2 GHz channel when in fact a 5 GHz channel was desired. An example would be
514 * an AP providing channel 8 on a country IE triplet when it sent this on the
515 * 5 GHz band, that channel is designed to be channel 8 on 5 GHz, not a 2 GHz
518 * This can be removed once ieee80211_channel_to_frequency() takes in a band.
520 static bool chan_in_band(int chan, enum ieee80211_band band)
522 int center_freq = ieee80211_channel_to_frequency(chan);
525 case IEEE80211_BAND_2GHZ:
526 if (center_freq <= 2484)
529 case IEEE80211_BAND_5GHZ:
530 if (center_freq >= 5005)
539 * Some APs may send a country IE triplet for each channel they
540 * support and while this is completely overkill and silly we still
541 * need to support it. We avoid making a single rule for each channel
542 * though and to help us with this we use this helper to find the
543 * actual subband end channel. These type of country IE triplet
544 * scenerios are handled then, all yielding two regulaotry rules from
545 * parsing a country IE:
583 * Returns 0 if the IE has been found to be invalid in the middle
586 static int max_subband_chan(enum ieee80211_band band,
588 int orig_end_channel,
593 u8 *triplets_start = *country_ie;
594 u8 len_at_triplet = *country_ie_len;
595 int end_subband_chan = orig_end_channel;
598 * We'll deal with padding for the caller unless
599 * its not immediate and we don't process any channels
601 if (*country_ie_len == 1) {
603 *country_ie_len -= 1;
604 return orig_end_channel;
607 /* Move to the next triplet and then start search */
609 *country_ie_len -= 3;
611 if (!chan_in_band(orig_cur_chan, band))
614 while (*country_ie_len >= 3) {
616 struct ieee80211_country_ie_triplet *triplet =
617 (struct ieee80211_country_ie_triplet *) *country_ie;
618 int cur_channel = 0, next_expected_chan;
620 /* means last triplet is completely unrelated to this one */
621 if (triplet->ext.reg_extension_id >=
622 IEEE80211_COUNTRY_EXTENSION_ID) {
624 *country_ie_len += 3;
628 if (triplet->chans.first_channel == 0) {
630 *country_ie_len -= 1;
631 if (*country_ie_len != 0)
636 if (triplet->chans.num_channels == 0)
639 /* Monitonically increasing channel order */
640 if (triplet->chans.first_channel <= end_subband_chan)
643 if (!chan_in_band(triplet->chans.first_channel, band))
647 if (triplet->chans.first_channel <= 14) {
648 end_channel = triplet->chans.first_channel +
649 triplet->chans.num_channels - 1;
652 end_channel = triplet->chans.first_channel +
653 (4 * (triplet->chans.num_channels - 1));
656 if (!chan_in_band(end_channel, band))
659 if (orig_max_power != triplet->chans.max_power) {
661 *country_ie_len += 3;
665 cur_channel = triplet->chans.first_channel;
667 /* The key is finding the right next expected channel */
668 if (band == IEEE80211_BAND_2GHZ)
669 next_expected_chan = end_subband_chan + 1;
671 next_expected_chan = end_subband_chan + 4;
673 if (cur_channel != next_expected_chan) {
675 *country_ie_len += 3;
679 end_subband_chan = end_channel;
681 /* Move to the next one */
683 *country_ie_len -= 3;
686 * Padding needs to be dealt with if we processed
689 if (*country_ie_len == 1) {
691 *country_ie_len -= 1;
695 /* If seen, the IE is invalid */
696 if (*country_ie_len == 2)
700 if (end_subband_chan == orig_end_channel) {
701 *country_ie = triplets_start;
702 *country_ie_len = len_at_triplet;
703 return orig_end_channel;
706 return end_subband_chan;
710 * Converts a country IE to a regulatory domain. A regulatory domain
711 * structure has a lot of information which the IE doesn't yet have,
712 * so for the other values we use upper max values as we will intersect
713 * with our userspace regulatory agent to get lower bounds.
715 static struct ieee80211_regdomain *country_ie_2_rd(
716 enum ieee80211_band band,
721 struct ieee80211_regdomain *rd = NULL;
725 u32 num_rules = 0, size_of_regd = 0;
726 u8 *triplets_start = NULL;
727 u8 len_at_triplet = 0;
728 /* the last channel we have registered in a subband (triplet) */
729 int last_sub_max_channel = 0;
731 *checksum = 0xDEADBEEF;
733 /* Country IE requirements */
734 BUG_ON(country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN ||
735 country_ie_len & 0x01);
737 alpha2[0] = country_ie[0];
738 alpha2[1] = country_ie[1];
741 * Third octet can be:
745 * anything else we assume is no restrictions
747 if (country_ie[2] == 'I')
748 flags = NL80211_RRF_NO_OUTDOOR;
749 else if (country_ie[2] == 'O')
750 flags = NL80211_RRF_NO_INDOOR;
755 triplets_start = country_ie;
756 len_at_triplet = country_ie_len;
758 *checksum ^= ((flags ^ alpha2[0] ^ alpha2[1]) << 8);
761 * We need to build a reg rule for each triplet, but first we must
762 * calculate the number of reg rules we will need. We will need one
763 * for each channel subband
765 while (country_ie_len >= 3) {
767 struct ieee80211_country_ie_triplet *triplet =
768 (struct ieee80211_country_ie_triplet *) country_ie;
769 int cur_sub_max_channel = 0, cur_channel = 0;
771 if (triplet->ext.reg_extension_id >=
772 IEEE80211_COUNTRY_EXTENSION_ID) {
779 * APs can add padding to make length divisible
780 * by two, required by the spec.
782 if (triplet->chans.first_channel == 0) {
785 /* This is expected to be at the very end only */
786 if (country_ie_len != 0)
791 if (triplet->chans.num_channels == 0)
794 if (!chan_in_band(triplet->chans.first_channel, band))
798 if (band == IEEE80211_BAND_2GHZ)
799 end_channel = triplet->chans.first_channel +
800 triplet->chans.num_channels - 1;
803 * 5 GHz -- For example in country IEs if the first
804 * channel given is 36 and the number of channels is 4
805 * then the individual channel numbers defined for the
806 * 5 GHz PHY by these parameters are: 36, 40, 44, and 48
807 * and not 36, 37, 38, 39.
809 * See: http://tinyurl.com/11d-clarification
811 end_channel = triplet->chans.first_channel +
812 (4 * (triplet->chans.num_channels - 1));
814 cur_channel = triplet->chans.first_channel;
817 * Enhancement for APs that send a triplet for every channel
818 * or for whatever reason sends triplets with multiple channels
819 * separated when in fact they should be together.
821 end_channel = max_subband_chan(band,
824 triplet->chans.max_power,
830 if (!chan_in_band(end_channel, band))
833 cur_sub_max_channel = end_channel;
835 /* Basic sanity check */
836 if (cur_sub_max_channel < cur_channel)
840 * Do not allow overlapping channels. Also channels
841 * passed in each subband must be monotonically
844 if (last_sub_max_channel) {
845 if (cur_channel <= last_sub_max_channel)
847 if (cur_sub_max_channel <= last_sub_max_channel)
852 * When dot11RegulatoryClassesRequired is supported
853 * we can throw ext triplets as part of this soup,
854 * for now we don't care when those change as we
857 *checksum ^= ((cur_channel ^ cur_sub_max_channel) << 8) |
858 ((cur_sub_max_channel ^ cur_sub_max_channel) << 16) |
859 ((triplet->chans.max_power ^ cur_sub_max_channel) << 24);
861 last_sub_max_channel = cur_sub_max_channel;
865 if (country_ie_len >= 3) {
871 * Note: this is not a IEEE requirement but
872 * simply a memory requirement
874 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
878 country_ie = triplets_start;
879 country_ie_len = len_at_triplet;
881 size_of_regd = sizeof(struct ieee80211_regdomain) +
882 (num_rules * sizeof(struct ieee80211_reg_rule));
884 rd = kzalloc(size_of_regd, GFP_KERNEL);
888 rd->n_reg_rules = num_rules;
889 rd->alpha2[0] = alpha2[0];
890 rd->alpha2[1] = alpha2[1];
892 /* This time around we fill in the rd */
893 while (country_ie_len >= 3) {
895 struct ieee80211_country_ie_triplet *triplet =
896 (struct ieee80211_country_ie_triplet *) country_ie;
897 struct ieee80211_reg_rule *reg_rule = NULL;
898 struct ieee80211_freq_range *freq_range = NULL;
899 struct ieee80211_power_rule *power_rule = NULL;
902 * Must parse if dot11RegulatoryClassesRequired is true,
903 * we don't support this yet
905 if (triplet->ext.reg_extension_id >=
906 IEEE80211_COUNTRY_EXTENSION_ID) {
912 if (triplet->chans.first_channel == 0) {
918 reg_rule = &rd->reg_rules[i];
919 freq_range = ®_rule->freq_range;
920 power_rule = ®_rule->power_rule;
922 reg_rule->flags = flags;
925 if (band == IEEE80211_BAND_2GHZ)
926 end_channel = triplet->chans.first_channel +
927 triplet->chans.num_channels -1;
929 end_channel = triplet->chans.first_channel +
930 (4 * (triplet->chans.num_channels - 1));
932 end_channel = max_subband_chan(band,
933 triplet->chans.first_channel,
935 triplet->chans.max_power,
940 * The +10 is since the regulatory domain expects
941 * the actual band edge, not the center of freq for
942 * its start and end freqs, assuming 20 MHz bandwidth on
943 * the channels passed
945 freq_range->start_freq_khz =
946 MHZ_TO_KHZ(ieee80211_channel_to_frequency(
947 triplet->chans.first_channel) - 10);
948 freq_range->end_freq_khz =
949 MHZ_TO_KHZ(ieee80211_channel_to_frequency(
953 * These are large arbitrary values we use to intersect later.
954 * Increment this if we ever support >= 40 MHz channels
957 freq_range->max_bandwidth_khz = MHZ_TO_KHZ(40);
958 power_rule->max_antenna_gain = DBI_TO_MBI(100);
959 power_rule->max_eirp = DBM_TO_MBM(triplet->chans.max_power);
963 if (country_ie_len >= 3) {
968 BUG_ON(i > NL80211_MAX_SUPP_REG_RULES);
976 * Helper for regdom_intersect(), this does the real
977 * mathematical intersection fun
979 static int reg_rules_intersect(
980 const struct ieee80211_reg_rule *rule1,
981 const struct ieee80211_reg_rule *rule2,
982 struct ieee80211_reg_rule *intersected_rule)
984 const struct ieee80211_freq_range *freq_range1, *freq_range2;
985 struct ieee80211_freq_range *freq_range;
986 const struct ieee80211_power_rule *power_rule1, *power_rule2;
987 struct ieee80211_power_rule *power_rule;
990 freq_range1 = &rule1->freq_range;
991 freq_range2 = &rule2->freq_range;
992 freq_range = &intersected_rule->freq_range;
994 power_rule1 = &rule1->power_rule;
995 power_rule2 = &rule2->power_rule;
996 power_rule = &intersected_rule->power_rule;
998 freq_range->start_freq_khz = max(freq_range1->start_freq_khz,
999 freq_range2->start_freq_khz);
1000 freq_range->end_freq_khz = min(freq_range1->end_freq_khz,
1001 freq_range2->end_freq_khz);
1002 freq_range->max_bandwidth_khz = min(freq_range1->max_bandwidth_khz,
1003 freq_range2->max_bandwidth_khz);
1005 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
1006 if (freq_range->max_bandwidth_khz > freq_diff)
1007 freq_range->max_bandwidth_khz = freq_diff;
1009 power_rule->max_eirp = min(power_rule1->max_eirp,
1010 power_rule2->max_eirp);
1011 power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain,
1012 power_rule2->max_antenna_gain);
1014 intersected_rule->flags = (rule1->flags | rule2->flags);
1016 if (!is_valid_reg_rule(intersected_rule))
1023 * regdom_intersect - do the intersection between two regulatory domains
1024 * @rd1: first regulatory domain
1025 * @rd2: second regulatory domain
1027 * Use this function to get the intersection between two regulatory domains.
1028 * Once completed we will mark the alpha2 for the rd as intersected, "98",
1029 * as no one single alpha2 can represent this regulatory domain.
1031 * Returns a pointer to the regulatory domain structure which will hold the
1032 * resulting intersection of rules between rd1 and rd2. We will
1033 * kzalloc() this structure for you.
1035 static struct ieee80211_regdomain *regdom_intersect(
1036 const struct ieee80211_regdomain *rd1,
1037 const struct ieee80211_regdomain *rd2)
1039 int r, size_of_regd;
1041 unsigned int num_rules = 0, rule_idx = 0;
1042 const struct ieee80211_reg_rule *rule1, *rule2;
1043 struct ieee80211_reg_rule *intersected_rule;
1044 struct ieee80211_regdomain *rd;
1045 /* This is just a dummy holder to help us count */
1046 struct ieee80211_reg_rule irule;
1048 /* Uses the stack temporarily for counter arithmetic */
1049 intersected_rule = &irule;
1051 memset(intersected_rule, 0, sizeof(struct ieee80211_reg_rule));
1057 * First we get a count of the rules we'll need, then we actually
1058 * build them. This is to so we can malloc() and free() a
1059 * regdomain once. The reason we use reg_rules_intersect() here
1060 * is it will return -EINVAL if the rule computed makes no sense.
1061 * All rules that do check out OK are valid.
1064 for (x = 0; x < rd1->n_reg_rules; x++) {
1065 rule1 = &rd1->reg_rules[x];
1066 for (y = 0; y < rd2->n_reg_rules; y++) {
1067 rule2 = &rd2->reg_rules[y];
1068 if (!reg_rules_intersect(rule1, rule2,
1071 memset(intersected_rule, 0,
1072 sizeof(struct ieee80211_reg_rule));
1079 size_of_regd = sizeof(struct ieee80211_regdomain) +
1080 ((num_rules + 1) * sizeof(struct ieee80211_reg_rule));
1082 rd = kzalloc(size_of_regd, GFP_KERNEL);
1086 for (x = 0; x < rd1->n_reg_rules; x++) {
1087 rule1 = &rd1->reg_rules[x];
1088 for (y = 0; y < rd2->n_reg_rules; y++) {
1089 rule2 = &rd2->reg_rules[y];
1091 * This time around instead of using the stack lets
1092 * write to the target rule directly saving ourselves
1095 intersected_rule = &rd->reg_rules[rule_idx];
1096 r = reg_rules_intersect(rule1, rule2,
1099 * No need to memset here the intersected rule here as
1100 * we're not using the stack anymore
1108 if (rule_idx != num_rules) {
1113 rd->n_reg_rules = num_rules;
1114 rd->alpha2[0] = '9';
1115 rd->alpha2[1] = '8';
1121 * XXX: add support for the rest of enum nl80211_reg_rule_flags, we may
1122 * want to just have the channel structure use these
1124 static u32 map_regdom_flags(u32 rd_flags)
1126 u32 channel_flags = 0;
1127 if (rd_flags & NL80211_RRF_PASSIVE_SCAN)
1128 channel_flags |= IEEE80211_CHAN_PASSIVE_SCAN;
1129 if (rd_flags & NL80211_RRF_NO_IBSS)
1130 channel_flags |= IEEE80211_CHAN_NO_IBSS;
1131 if (rd_flags & NL80211_RRF_DFS)
1132 channel_flags |= IEEE80211_CHAN_RADAR;
1133 return channel_flags;
1136 static int freq_reg_info_regd(struct wiphy *wiphy,
1139 const struct ieee80211_reg_rule **reg_rule,
1140 const struct ieee80211_regdomain *custom_regd)
1143 bool band_rule_found = false;
1144 const struct ieee80211_regdomain *regd;
1145 bool bw_fits = false;
1147 if (!desired_bw_khz)
1148 desired_bw_khz = MHZ_TO_KHZ(20);
1150 regd = custom_regd ? custom_regd : cfg80211_regdomain;
1153 * Follow the driver's regulatory domain, if present, unless a country
1154 * IE has been processed or a user wants to help complaince further
1156 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
1157 last_request->initiator != NL80211_REGDOM_SET_BY_USER &&
1164 for (i = 0; i < regd->n_reg_rules; i++) {
1165 const struct ieee80211_reg_rule *rr;
1166 const struct ieee80211_freq_range *fr = NULL;
1167 const struct ieee80211_power_rule *pr = NULL;
1169 rr = ®d->reg_rules[i];
1170 fr = &rr->freq_range;
1171 pr = &rr->power_rule;
1174 * We only need to know if one frequency rule was
1175 * was in center_freq's band, that's enough, so lets
1176 * not overwrite it once found
1178 if (!band_rule_found)
1179 band_rule_found = freq_in_rule_band(fr, center_freq);
1181 bw_fits = reg_does_bw_fit(fr,
1185 if (band_rule_found && bw_fits) {
1191 if (!band_rule_found)
1196 EXPORT_SYMBOL(freq_reg_info);
1198 int freq_reg_info(struct wiphy *wiphy,
1201 const struct ieee80211_reg_rule **reg_rule)
1203 assert_cfg80211_lock();
1204 return freq_reg_info_regd(wiphy,
1212 * Note that right now we assume the desired channel bandwidth
1213 * is always 20 MHz for each individual channel (HT40 uses 20 MHz
1214 * per channel, the primary and the extension channel). To support
1215 * smaller custom bandwidths such as 5 MHz or 10 MHz we'll need a
1216 * new ieee80211_channel.target_bw and re run the regulatory check
1217 * on the wiphy with the target_bw specified. Then we can simply use
1218 * that below for the desired_bw_khz below.
1220 static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
1221 unsigned int chan_idx)
1224 u32 flags, bw_flags = 0;
1225 u32 desired_bw_khz = MHZ_TO_KHZ(20);
1226 const struct ieee80211_reg_rule *reg_rule = NULL;
1227 const struct ieee80211_power_rule *power_rule = NULL;
1228 const struct ieee80211_freq_range *freq_range = NULL;
1229 struct ieee80211_supported_band *sband;
1230 struct ieee80211_channel *chan;
1231 struct wiphy *request_wiphy = NULL;
1233 assert_cfg80211_lock();
1235 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
1237 sband = wiphy->bands[band];
1238 BUG_ON(chan_idx >= sband->n_channels);
1239 chan = &sband->channels[chan_idx];
1241 flags = chan->orig_flags;
1243 r = freq_reg_info(wiphy,
1244 MHZ_TO_KHZ(chan->center_freq),
1250 * This means no regulatory rule was found in the country IE
1251 * with a frequency range on the center_freq's band, since
1252 * IEEE-802.11 allows for a country IE to have a subset of the
1253 * regulatory information provided in a country we ignore
1254 * disabling the channel unless at least one reg rule was
1255 * found on the center_freq's band. For details see this
1258 * http://tinyurl.com/11d-clarification
1261 last_request->initiator ==
1262 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
1263 REG_DBG_PRINT("cfg80211: Leaving channel %d MHz "
1264 "intact on %s - no rule found in band on "
1266 chan->center_freq, wiphy_name(wiphy));
1269 * In this case we know the country IE has at least one reg rule
1270 * for the band so we respect its band definitions
1272 if (last_request->initiator ==
1273 NL80211_REGDOM_SET_BY_COUNTRY_IE)
1274 REG_DBG_PRINT("cfg80211: Disabling "
1275 "channel %d MHz on %s due to "
1277 chan->center_freq, wiphy_name(wiphy));
1278 flags |= IEEE80211_CHAN_DISABLED;
1279 chan->flags = flags;
1284 power_rule = ®_rule->power_rule;
1285 freq_range = ®_rule->freq_range;
1287 if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(40))
1288 bw_flags = IEEE80211_CHAN_NO_HT40;
1290 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
1291 request_wiphy && request_wiphy == wiphy &&
1292 request_wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) {
1294 * This gaurantees the driver's requested regulatory domain
1295 * will always be used as a base for further regulatory
1298 chan->flags = chan->orig_flags =
1299 map_regdom_flags(reg_rule->flags) | bw_flags;
1300 chan->max_antenna_gain = chan->orig_mag =
1301 (int) MBI_TO_DBI(power_rule->max_antenna_gain);
1302 chan->max_power = chan->orig_mpwr =
1303 (int) MBM_TO_DBM(power_rule->max_eirp);
1307 chan->flags = flags | bw_flags | map_regdom_flags(reg_rule->flags);
1308 chan->max_antenna_gain = min(chan->orig_mag,
1309 (int) MBI_TO_DBI(power_rule->max_antenna_gain));
1310 if (chan->orig_mpwr)
1311 chan->max_power = min(chan->orig_mpwr,
1312 (int) MBM_TO_DBM(power_rule->max_eirp));
1314 chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp);
1317 static void handle_band(struct wiphy *wiphy, enum ieee80211_band band)
1320 struct ieee80211_supported_band *sband;
1322 BUG_ON(!wiphy->bands[band]);
1323 sband = wiphy->bands[band];
1325 for (i = 0; i < sband->n_channels; i++)
1326 handle_channel(wiphy, band, i);
1329 static bool ignore_reg_update(struct wiphy *wiphy,
1330 enum nl80211_reg_initiator initiator)
1334 if (initiator == NL80211_REGDOM_SET_BY_CORE &&
1335 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)
1338 * wiphy->regd will be set once the device has its own
1339 * desired regulatory domain set
1341 if (wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY && !wiphy->regd &&
1342 !is_world_regdom(last_request->alpha2))
1347 static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator)
1349 struct cfg80211_registered_device *rdev;
1351 list_for_each_entry(rdev, &cfg80211_rdev_list, list)
1352 wiphy_update_regulatory(&rdev->wiphy, initiator);
1355 static void handle_reg_beacon(struct wiphy *wiphy,
1356 unsigned int chan_idx,
1357 struct reg_beacon *reg_beacon)
1359 struct ieee80211_supported_band *sband;
1360 struct ieee80211_channel *chan;
1361 bool channel_changed = false;
1362 struct ieee80211_channel chan_before;
1364 assert_cfg80211_lock();
1366 sband = wiphy->bands[reg_beacon->chan.band];
1367 chan = &sband->channels[chan_idx];
1369 if (likely(chan->center_freq != reg_beacon->chan.center_freq))
1372 if (chan->beacon_found)
1375 chan->beacon_found = true;
1377 if (wiphy->flags & WIPHY_FLAG_DISABLE_BEACON_HINTS)
1380 chan_before.center_freq = chan->center_freq;
1381 chan_before.flags = chan->flags;
1383 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) {
1384 chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
1385 channel_changed = true;
1388 if (chan->flags & IEEE80211_CHAN_NO_IBSS) {
1389 chan->flags &= ~IEEE80211_CHAN_NO_IBSS;
1390 channel_changed = true;
1393 if (channel_changed)
1394 nl80211_send_beacon_hint_event(wiphy, &chan_before, chan);
1398 * Called when a scan on a wiphy finds a beacon on
1401 static void wiphy_update_new_beacon(struct wiphy *wiphy,
1402 struct reg_beacon *reg_beacon)
1405 struct ieee80211_supported_band *sband;
1407 assert_cfg80211_lock();
1409 if (!wiphy->bands[reg_beacon->chan.band])
1412 sband = wiphy->bands[reg_beacon->chan.band];
1414 for (i = 0; i < sband->n_channels; i++)
1415 handle_reg_beacon(wiphy, i, reg_beacon);
1419 * Called upon reg changes or a new wiphy is added
1421 static void wiphy_update_beacon_reg(struct wiphy *wiphy)
1424 struct ieee80211_supported_band *sband;
1425 struct reg_beacon *reg_beacon;
1427 assert_cfg80211_lock();
1429 if (list_empty(®_beacon_list))
1432 list_for_each_entry(reg_beacon, ®_beacon_list, list) {
1433 if (!wiphy->bands[reg_beacon->chan.band])
1435 sband = wiphy->bands[reg_beacon->chan.band];
1436 for (i = 0; i < sband->n_channels; i++)
1437 handle_reg_beacon(wiphy, i, reg_beacon);
1441 static bool reg_is_world_roaming(struct wiphy *wiphy)
1443 if (is_world_regdom(cfg80211_regdomain->alpha2) ||
1444 (wiphy->regd && is_world_regdom(wiphy->regd->alpha2)))
1447 last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
1448 wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)
1453 /* Reap the advantages of previously found beacons */
1454 static void reg_process_beacons(struct wiphy *wiphy)
1457 * Means we are just firing up cfg80211, so no beacons would
1458 * have been processed yet.
1462 if (!reg_is_world_roaming(wiphy))
1464 wiphy_update_beacon_reg(wiphy);
1467 static bool is_ht40_not_allowed(struct ieee80211_channel *chan)
1471 if (chan->flags & IEEE80211_CHAN_DISABLED)
1473 /* This would happen when regulatory rules disallow HT40 completely */
1474 if (IEEE80211_CHAN_NO_HT40 == (chan->flags & (IEEE80211_CHAN_NO_HT40)))
1479 static void reg_process_ht_flags_channel(struct wiphy *wiphy,
1480 enum ieee80211_band band,
1481 unsigned int chan_idx)
1483 struct ieee80211_supported_band *sband;
1484 struct ieee80211_channel *channel;
1485 struct ieee80211_channel *channel_before = NULL, *channel_after = NULL;
1488 assert_cfg80211_lock();
1490 sband = wiphy->bands[band];
1491 BUG_ON(chan_idx >= sband->n_channels);
1492 channel = &sband->channels[chan_idx];
1494 if (is_ht40_not_allowed(channel)) {
1495 channel->flags |= IEEE80211_CHAN_NO_HT40;
1500 * We need to ensure the extension channels exist to
1501 * be able to use HT40- or HT40+, this finds them (or not)
1503 for (i = 0; i < sband->n_channels; i++) {
1504 struct ieee80211_channel *c = &sband->channels[i];
1505 if (c->center_freq == (channel->center_freq - 20))
1507 if (c->center_freq == (channel->center_freq + 20))
1512 * Please note that this assumes target bandwidth is 20 MHz,
1513 * if that ever changes we also need to change the below logic
1514 * to include that as well.
1516 if (is_ht40_not_allowed(channel_before))
1517 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
1519 channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS;
1521 if (is_ht40_not_allowed(channel_after))
1522 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
1524 channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS;
1527 static void reg_process_ht_flags_band(struct wiphy *wiphy,
1528 enum ieee80211_band band)
1531 struct ieee80211_supported_band *sband;
1533 BUG_ON(!wiphy->bands[band]);
1534 sband = wiphy->bands[band];
1536 for (i = 0; i < sband->n_channels; i++)
1537 reg_process_ht_flags_channel(wiphy, band, i);
1540 static void reg_process_ht_flags(struct wiphy *wiphy)
1542 enum ieee80211_band band;
1547 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1548 if (wiphy->bands[band])
1549 reg_process_ht_flags_band(wiphy, band);
1554 void wiphy_update_regulatory(struct wiphy *wiphy,
1555 enum nl80211_reg_initiator initiator)
1557 enum ieee80211_band band;
1559 if (ignore_reg_update(wiphy, initiator))
1561 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1562 if (wiphy->bands[band])
1563 handle_band(wiphy, band);
1566 reg_process_beacons(wiphy);
1567 reg_process_ht_flags(wiphy);
1568 if (wiphy->reg_notifier)
1569 wiphy->reg_notifier(wiphy, last_request);
1572 static void handle_channel_custom(struct wiphy *wiphy,
1573 enum ieee80211_band band,
1574 unsigned int chan_idx,
1575 const struct ieee80211_regdomain *regd)
1578 u32 desired_bw_khz = MHZ_TO_KHZ(20);
1580 const struct ieee80211_reg_rule *reg_rule = NULL;
1581 const struct ieee80211_power_rule *power_rule = NULL;
1582 const struct ieee80211_freq_range *freq_range = NULL;
1583 struct ieee80211_supported_band *sband;
1584 struct ieee80211_channel *chan;
1588 sband = wiphy->bands[band];
1589 BUG_ON(chan_idx >= sband->n_channels);
1590 chan = &sband->channels[chan_idx];
1592 r = freq_reg_info_regd(wiphy,
1593 MHZ_TO_KHZ(chan->center_freq),
1599 chan->flags = IEEE80211_CHAN_DISABLED;
1603 power_rule = ®_rule->power_rule;
1604 freq_range = ®_rule->freq_range;
1606 if (freq_range->max_bandwidth_khz < MHZ_TO_KHZ(40))
1607 bw_flags = IEEE80211_CHAN_NO_HT40;
1609 chan->flags |= map_regdom_flags(reg_rule->flags) | bw_flags;
1610 chan->max_antenna_gain = (int) MBI_TO_DBI(power_rule->max_antenna_gain);
1611 chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp);
1614 static void handle_band_custom(struct wiphy *wiphy, enum ieee80211_band band,
1615 const struct ieee80211_regdomain *regd)
1618 struct ieee80211_supported_band *sband;
1620 BUG_ON(!wiphy->bands[band]);
1621 sband = wiphy->bands[band];
1623 for (i = 0; i < sband->n_channels; i++)
1624 handle_channel_custom(wiphy, band, i, regd);
1627 /* Used by drivers prior to wiphy registration */
1628 void wiphy_apply_custom_regulatory(struct wiphy *wiphy,
1629 const struct ieee80211_regdomain *regd)
1631 enum ieee80211_band band;
1632 unsigned int bands_set = 0;
1634 mutex_lock(®_mutex);
1635 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1636 if (!wiphy->bands[band])
1638 handle_band_custom(wiphy, band, regd);
1641 mutex_unlock(®_mutex);
1644 * no point in calling this if it won't have any effect
1645 * on your device's supportd bands.
1647 WARN_ON(!bands_set);
1649 EXPORT_SYMBOL(wiphy_apply_custom_regulatory);
1652 * Return value which can be used by ignore_request() to indicate
1653 * it has been determined we should intersect two regulatory domains
1655 #define REG_INTERSECT 1
1657 /* This has the logic which determines when a new request
1658 * should be ignored. */
1659 static int ignore_request(struct wiphy *wiphy,
1660 struct regulatory_request *pending_request)
1662 struct wiphy *last_wiphy = NULL;
1664 assert_cfg80211_lock();
1666 /* All initial requests are respected */
1670 switch (pending_request->initiator) {
1671 case NL80211_REGDOM_SET_BY_CORE:
1673 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
1675 last_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
1677 if (unlikely(!is_an_alpha2(pending_request->alpha2)))
1679 if (last_request->initiator ==
1680 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
1681 if (last_wiphy != wiphy) {
1683 * Two cards with two APs claiming different
1684 * Country IE alpha2s. We could
1685 * intersect them, but that seems unlikely
1686 * to be correct. Reject second one for now.
1688 if (regdom_changes(pending_request->alpha2))
1693 * Two consecutive Country IE hints on the same wiphy.
1694 * This should be picked up early by the driver/stack
1696 if (WARN_ON(regdom_changes(pending_request->alpha2)))
1700 return REG_INTERSECT;
1701 case NL80211_REGDOM_SET_BY_DRIVER:
1702 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE) {
1703 if (regdom_changes(pending_request->alpha2))
1709 * This would happen if you unplug and plug your card
1710 * back in or if you add a new device for which the previously
1711 * loaded card also agrees on the regulatory domain.
1713 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
1714 !regdom_changes(pending_request->alpha2))
1717 return REG_INTERSECT;
1718 case NL80211_REGDOM_SET_BY_USER:
1719 if (last_request->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE)
1720 return REG_INTERSECT;
1722 * If the user knows better the user should set the regdom
1723 * to their country before the IE is picked up
1725 if (last_request->initiator == NL80211_REGDOM_SET_BY_USER &&
1726 last_request->intersect)
1729 * Process user requests only after previous user/driver/core
1730 * requests have been processed
1732 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE ||
1733 last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER ||
1734 last_request->initiator == NL80211_REGDOM_SET_BY_USER) {
1735 if (regdom_changes(last_request->alpha2))
1739 if (!regdom_changes(pending_request->alpha2))
1749 * __regulatory_hint - hint to the wireless core a regulatory domain
1750 * @wiphy: if the hint comes from country information from an AP, this
1751 * is required to be set to the wiphy that received the information
1752 * @pending_request: the regulatory request currently being processed
1754 * The Wireless subsystem can use this function to hint to the wireless core
1755 * what it believes should be the current regulatory domain.
1757 * Returns zero if all went fine, %-EALREADY if a regulatory domain had
1758 * already been set or other standard error codes.
1760 * Caller must hold &cfg80211_mutex and ®_mutex
1762 static int __regulatory_hint(struct wiphy *wiphy,
1763 struct regulatory_request *pending_request)
1765 bool intersect = false;
1768 assert_cfg80211_lock();
1770 r = ignore_request(wiphy, pending_request);
1772 if (r == REG_INTERSECT) {
1773 if (pending_request->initiator ==
1774 NL80211_REGDOM_SET_BY_DRIVER) {
1775 r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain);
1777 kfree(pending_request);
1784 * If the regulatory domain being requested by the
1785 * driver has already been set just copy it to the
1788 if (r == -EALREADY &&
1789 pending_request->initiator ==
1790 NL80211_REGDOM_SET_BY_DRIVER) {
1791 r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain);
1793 kfree(pending_request);
1799 kfree(pending_request);
1804 kfree(last_request);
1806 last_request = pending_request;
1807 last_request->intersect = intersect;
1809 pending_request = NULL;
1811 if (last_request->initiator == NL80211_REGDOM_SET_BY_USER) {
1812 user_alpha2[0] = last_request->alpha2[0];
1813 user_alpha2[1] = last_request->alpha2[1];
1816 /* When r == REG_INTERSECT we do need to call CRDA */
1819 * Since CRDA will not be called in this case as we already
1820 * have applied the requested regulatory domain before we just
1821 * inform userspace we have processed the request
1824 nl80211_send_reg_change_event(last_request);
1828 return call_crda(last_request->alpha2);
1831 /* This processes *all* regulatory hints */
1832 static void reg_process_hint(struct regulatory_request *reg_request)
1835 struct wiphy *wiphy = NULL;
1837 BUG_ON(!reg_request->alpha2);
1839 mutex_lock(&cfg80211_mutex);
1840 mutex_lock(®_mutex);
1842 if (wiphy_idx_valid(reg_request->wiphy_idx))
1843 wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx);
1845 if (reg_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
1851 r = __regulatory_hint(wiphy, reg_request);
1852 /* This is required so that the orig_* parameters are saved */
1853 if (r == -EALREADY && wiphy &&
1854 wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY)
1855 wiphy_update_regulatory(wiphy, reg_request->initiator);
1857 mutex_unlock(®_mutex);
1858 mutex_unlock(&cfg80211_mutex);
1861 /* Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_* */
1862 static void reg_process_pending_hints(void)
1864 struct regulatory_request *reg_request;
1866 spin_lock(®_requests_lock);
1867 while (!list_empty(®_requests_list)) {
1868 reg_request = list_first_entry(®_requests_list,
1869 struct regulatory_request,
1871 list_del_init(®_request->list);
1873 spin_unlock(®_requests_lock);
1874 reg_process_hint(reg_request);
1875 spin_lock(®_requests_lock);
1877 spin_unlock(®_requests_lock);
1880 /* Processes beacon hints -- this has nothing to do with country IEs */
1881 static void reg_process_pending_beacon_hints(void)
1883 struct cfg80211_registered_device *rdev;
1884 struct reg_beacon *pending_beacon, *tmp;
1887 * No need to hold the reg_mutex here as we just touch wiphys
1888 * and do not read or access regulatory variables.
1890 mutex_lock(&cfg80211_mutex);
1892 /* This goes through the _pending_ beacon list */
1893 spin_lock_bh(®_pending_beacons_lock);
1895 if (list_empty(®_pending_beacons)) {
1896 spin_unlock_bh(®_pending_beacons_lock);
1900 list_for_each_entry_safe(pending_beacon, tmp,
1901 ®_pending_beacons, list) {
1903 list_del_init(&pending_beacon->list);
1905 /* Applies the beacon hint to current wiphys */
1906 list_for_each_entry(rdev, &cfg80211_rdev_list, list)
1907 wiphy_update_new_beacon(&rdev->wiphy, pending_beacon);
1909 /* Remembers the beacon hint for new wiphys or reg changes */
1910 list_add_tail(&pending_beacon->list, ®_beacon_list);
1913 spin_unlock_bh(®_pending_beacons_lock);
1915 mutex_unlock(&cfg80211_mutex);
1918 static void reg_todo(struct work_struct *work)
1920 reg_process_pending_hints();
1921 reg_process_pending_beacon_hints();
1924 static DECLARE_WORK(reg_work, reg_todo);
1926 static void queue_regulatory_request(struct regulatory_request *request)
1928 spin_lock(®_requests_lock);
1929 list_add_tail(&request->list, ®_requests_list);
1930 spin_unlock(®_requests_lock);
1932 schedule_work(®_work);
1936 * Core regulatory hint -- happens during cfg80211_init()
1937 * and when we restore regulatory settings.
1939 static int regulatory_hint_core(const char *alpha2)
1941 struct regulatory_request *request;
1943 kfree(last_request);
1944 last_request = NULL;
1946 request = kzalloc(sizeof(struct regulatory_request),
1951 request->alpha2[0] = alpha2[0];
1952 request->alpha2[1] = alpha2[1];
1953 request->initiator = NL80211_REGDOM_SET_BY_CORE;
1956 * This ensures last_request is populated once modules
1957 * come swinging in and calling regulatory hints and
1958 * wiphy_apply_custom_regulatory().
1960 reg_process_hint(request);
1966 int regulatory_hint_user(const char *alpha2)
1968 struct regulatory_request *request;
1972 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1976 request->wiphy_idx = WIPHY_IDX_STALE;
1977 request->alpha2[0] = alpha2[0];
1978 request->alpha2[1] = alpha2[1];
1979 request->initiator = NL80211_REGDOM_SET_BY_USER;
1981 queue_regulatory_request(request);
1987 int regulatory_hint(struct wiphy *wiphy, const char *alpha2)
1989 struct regulatory_request *request;
1994 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1998 request->wiphy_idx = get_wiphy_idx(wiphy);
2000 /* Must have registered wiphy first */
2001 BUG_ON(!wiphy_idx_valid(request->wiphy_idx));
2003 request->alpha2[0] = alpha2[0];
2004 request->alpha2[1] = alpha2[1];
2005 request->initiator = NL80211_REGDOM_SET_BY_DRIVER;
2007 queue_regulatory_request(request);
2011 EXPORT_SYMBOL(regulatory_hint);
2013 /* Caller must hold reg_mutex */
2014 static bool reg_same_country_ie_hint(struct wiphy *wiphy,
2015 u32 country_ie_checksum)
2017 struct wiphy *request_wiphy;
2021 if (unlikely(last_request->initiator !=
2022 NL80211_REGDOM_SET_BY_COUNTRY_IE))
2025 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
2030 if (likely(request_wiphy != wiphy))
2031 return !country_ie_integrity_changes(country_ie_checksum);
2033 * We should not have let these through at this point, they
2034 * should have been picked up earlier by the first alpha2 check
2037 if (WARN_ON(!country_ie_integrity_changes(country_ie_checksum)))
2043 * We hold wdev_lock() here so we cannot hold cfg80211_mutex() and
2044 * therefore cannot iterate over the rdev list here.
2046 void regulatory_hint_11d(struct wiphy *wiphy,
2047 enum ieee80211_band band,
2051 struct ieee80211_regdomain *rd = NULL;
2054 enum environment_cap env = ENVIRON_ANY;
2055 struct regulatory_request *request;
2057 mutex_lock(®_mutex);
2059 if (unlikely(!last_request))
2062 /* IE len must be evenly divisible by 2 */
2063 if (country_ie_len & 0x01)
2066 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
2070 * Pending country IE processing, this can happen after we
2071 * call CRDA and wait for a response if a beacon was received before
2072 * we were able to process the last regulatory_hint_11d() call
2074 if (country_ie_regdomain)
2077 alpha2[0] = country_ie[0];
2078 alpha2[1] = country_ie[1];
2080 if (country_ie[2] == 'I')
2081 env = ENVIRON_INDOOR;
2082 else if (country_ie[2] == 'O')
2083 env = ENVIRON_OUTDOOR;
2086 * We will run this only upon a successful connection on cfg80211.
2087 * We leave conflict resolution to the workqueue, where can hold
2090 if (likely(last_request->initiator ==
2091 NL80211_REGDOM_SET_BY_COUNTRY_IE &&
2092 wiphy_idx_valid(last_request->wiphy_idx)))
2095 rd = country_ie_2_rd(band, country_ie, country_ie_len, &checksum);
2097 REG_DBG_PRINT("cfg80211: Ignoring bogus country IE\n");
2102 * This will not happen right now but we leave it here for the
2103 * the future when we want to add suspend/resume support and having
2104 * the user move to another country after doing so, or having the user
2105 * move to another AP. Right now we just trust the first AP.
2107 * If we hit this before we add this support we want to be informed of
2108 * it as it would indicate a mistake in the current design
2110 if (WARN_ON(reg_same_country_ie_hint(wiphy, checksum)))
2113 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
2118 * We keep this around for when CRDA comes back with a response so
2119 * we can intersect with that
2121 country_ie_regdomain = rd;
2123 request->wiphy_idx = get_wiphy_idx(wiphy);
2124 request->alpha2[0] = rd->alpha2[0];
2125 request->alpha2[1] = rd->alpha2[1];
2126 request->initiator = NL80211_REGDOM_SET_BY_COUNTRY_IE;
2127 request->country_ie_checksum = checksum;
2128 request->country_ie_env = env;
2130 mutex_unlock(®_mutex);
2132 queue_regulatory_request(request);
2139 mutex_unlock(®_mutex);
2142 static void restore_alpha2(char *alpha2, bool reset_user)
2144 /* indicates there is no alpha2 to consider for restoration */
2148 /* The user setting has precedence over the module parameter */
2149 if (is_user_regdom_saved()) {
2150 /* Unless we're asked to ignore it and reset it */
2152 REG_DBG_PRINT("cfg80211: Restoring regulatory settings "
2153 "including user preference\n");
2154 user_alpha2[0] = '9';
2155 user_alpha2[1] = '7';
2158 * If we're ignoring user settings, we still need to
2159 * check the module parameter to ensure we put things
2160 * back as they were for a full restore.
2162 if (!is_world_regdom(ieee80211_regdom)) {
2163 REG_DBG_PRINT("cfg80211: Keeping preference on "
2164 "module parameter ieee80211_regdom: %c%c\n",
2165 ieee80211_regdom[0],
2166 ieee80211_regdom[1]);
2167 alpha2[0] = ieee80211_regdom[0];
2168 alpha2[1] = ieee80211_regdom[1];
2171 REG_DBG_PRINT("cfg80211: Restoring regulatory settings "
2172 "while preserving user preference for: %c%c\n",
2175 alpha2[0] = user_alpha2[0];
2176 alpha2[1] = user_alpha2[1];
2178 } else if (!is_world_regdom(ieee80211_regdom)) {
2179 REG_DBG_PRINT("cfg80211: Keeping preference on "
2180 "module parameter ieee80211_regdom: %c%c\n",
2181 ieee80211_regdom[0],
2182 ieee80211_regdom[1]);
2183 alpha2[0] = ieee80211_regdom[0];
2184 alpha2[1] = ieee80211_regdom[1];
2186 REG_DBG_PRINT("cfg80211: Restoring regulatory settings\n");
2190 * Restoring regulatory settings involves ingoring any
2191 * possibly stale country IE information and user regulatory
2192 * settings if so desired, this includes any beacon hints
2193 * learned as we could have traveled outside to another country
2194 * after disconnection. To restore regulatory settings we do
2195 * exactly what we did at bootup:
2197 * - send a core regulatory hint
2198 * - send a user regulatory hint if applicable
2200 * Device drivers that send a regulatory hint for a specific country
2201 * keep their own regulatory domain on wiphy->regd so that does does
2202 * not need to be remembered.
2204 static void restore_regulatory_settings(bool reset_user)
2207 struct reg_beacon *reg_beacon, *btmp;
2209 mutex_lock(&cfg80211_mutex);
2210 mutex_lock(®_mutex);
2213 restore_alpha2(alpha2, reset_user);
2215 /* Clear beacon hints */
2216 spin_lock_bh(®_pending_beacons_lock);
2217 if (!list_empty(®_pending_beacons)) {
2218 list_for_each_entry_safe(reg_beacon, btmp,
2219 ®_pending_beacons, list) {
2220 list_del(®_beacon->list);
2224 spin_unlock_bh(®_pending_beacons_lock);
2226 if (!list_empty(®_beacon_list)) {
2227 list_for_each_entry_safe(reg_beacon, btmp,
2228 ®_beacon_list, list) {
2229 list_del(®_beacon->list);
2234 /* First restore to the basic regulatory settings */
2235 cfg80211_regdomain = cfg80211_world_regdom;
2237 mutex_unlock(®_mutex);
2238 mutex_unlock(&cfg80211_mutex);
2240 regulatory_hint_core(cfg80211_regdomain->alpha2);
2243 * This restores the ieee80211_regdom module parameter
2244 * preference or the last user requested regulatory
2245 * settings, user regulatory settings takes precedence.
2247 if (is_an_alpha2(alpha2))
2248 regulatory_hint_user(user_alpha2);
2252 void regulatory_hint_disconnect(void)
2254 REG_DBG_PRINT("cfg80211: All devices are disconnected, going to "
2255 "restore regulatory settings\n");
2256 restore_regulatory_settings(false);
2259 static bool freq_is_chan_12_13_14(u16 freq)
2261 if (freq == ieee80211_channel_to_frequency(12) ||
2262 freq == ieee80211_channel_to_frequency(13) ||
2263 freq == ieee80211_channel_to_frequency(14))
2268 int regulatory_hint_found_beacon(struct wiphy *wiphy,
2269 struct ieee80211_channel *beacon_chan,
2272 struct reg_beacon *reg_beacon;
2274 if (likely((beacon_chan->beacon_found ||
2275 (beacon_chan->flags & IEEE80211_CHAN_RADAR) ||
2276 (beacon_chan->band == IEEE80211_BAND_2GHZ &&
2277 !freq_is_chan_12_13_14(beacon_chan->center_freq)))))
2280 reg_beacon = kzalloc(sizeof(struct reg_beacon), gfp);
2284 REG_DBG_PRINT("cfg80211: Found new beacon on "
2285 "frequency: %d MHz (Ch %d) on %s\n",
2286 beacon_chan->center_freq,
2287 ieee80211_frequency_to_channel(beacon_chan->center_freq),
2290 memcpy(®_beacon->chan, beacon_chan,
2291 sizeof(struct ieee80211_channel));
2295 * Since we can be called from BH or and non-BH context
2296 * we must use spin_lock_bh()
2298 spin_lock_bh(®_pending_beacons_lock);
2299 list_add_tail(®_beacon->list, ®_pending_beacons);
2300 spin_unlock_bh(®_pending_beacons_lock);
2302 schedule_work(®_work);
2307 static void print_rd_rules(const struct ieee80211_regdomain *rd)
2310 const struct ieee80211_reg_rule *reg_rule = NULL;
2311 const struct ieee80211_freq_range *freq_range = NULL;
2312 const struct ieee80211_power_rule *power_rule = NULL;
2314 printk(KERN_INFO " (start_freq - end_freq @ bandwidth), "
2315 "(max_antenna_gain, max_eirp)\n");
2317 for (i = 0; i < rd->n_reg_rules; i++) {
2318 reg_rule = &rd->reg_rules[i];
2319 freq_range = ®_rule->freq_range;
2320 power_rule = ®_rule->power_rule;
2323 * There may not be documentation for max antenna gain
2324 * in certain regions
2326 if (power_rule->max_antenna_gain)
2327 printk(KERN_INFO " (%d KHz - %d KHz @ %d KHz), "
2328 "(%d mBi, %d mBm)\n",
2329 freq_range->start_freq_khz,
2330 freq_range->end_freq_khz,
2331 freq_range->max_bandwidth_khz,
2332 power_rule->max_antenna_gain,
2333 power_rule->max_eirp);
2335 printk(KERN_INFO " (%d KHz - %d KHz @ %d KHz), "
2337 freq_range->start_freq_khz,
2338 freq_range->end_freq_khz,
2339 freq_range->max_bandwidth_khz,
2340 power_rule->max_eirp);
2344 static void print_regdomain(const struct ieee80211_regdomain *rd)
2347 if (is_intersected_alpha2(rd->alpha2)) {
2349 if (last_request->initiator ==
2350 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2351 struct cfg80211_registered_device *rdev;
2352 rdev = cfg80211_rdev_by_wiphy_idx(
2353 last_request->wiphy_idx);
2355 printk(KERN_INFO "cfg80211: Current regulatory "
2356 "domain updated by AP to: %c%c\n",
2357 rdev->country_ie_alpha2[0],
2358 rdev->country_ie_alpha2[1]);
2360 printk(KERN_INFO "cfg80211: Current regulatory "
2361 "domain intersected: \n");
2363 printk(KERN_INFO "cfg80211: Current regulatory "
2364 "domain intersected: \n");
2365 } else if (is_world_regdom(rd->alpha2))
2366 printk(KERN_INFO "cfg80211: World regulatory "
2367 "domain updated:\n");
2369 if (is_unknown_alpha2(rd->alpha2))
2370 printk(KERN_INFO "cfg80211: Regulatory domain "
2371 "changed to driver built-in settings "
2372 "(unknown country)\n");
2374 printk(KERN_INFO "cfg80211: Regulatory domain "
2375 "changed to country: %c%c\n",
2376 rd->alpha2[0], rd->alpha2[1]);
2381 static void print_regdomain_info(const struct ieee80211_regdomain *rd)
2383 printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n",
2384 rd->alpha2[0], rd->alpha2[1]);
2388 #ifdef CONFIG_CFG80211_REG_DEBUG
2389 static void reg_country_ie_process_debug(
2390 const struct ieee80211_regdomain *rd,
2391 const struct ieee80211_regdomain *country_ie_regdomain,
2392 const struct ieee80211_regdomain *intersected_rd)
2394 printk(KERN_DEBUG "cfg80211: Received country IE:\n");
2395 print_regdomain_info(country_ie_regdomain);
2396 printk(KERN_DEBUG "cfg80211: CRDA thinks this should applied:\n");
2397 print_regdomain_info(rd);
2398 if (intersected_rd) {
2399 printk(KERN_DEBUG "cfg80211: We intersect both of these "
2401 print_regdomain_info(intersected_rd);
2404 printk(KERN_DEBUG "cfg80211: Intersection between both failed\n");
2407 static inline void reg_country_ie_process_debug(
2408 const struct ieee80211_regdomain *rd,
2409 const struct ieee80211_regdomain *country_ie_regdomain,
2410 const struct ieee80211_regdomain *intersected_rd)
2415 /* Takes ownership of rd only if it doesn't fail */
2416 static int __set_regdom(const struct ieee80211_regdomain *rd)
2418 const struct ieee80211_regdomain *intersected_rd = NULL;
2419 struct cfg80211_registered_device *rdev = NULL;
2420 struct wiphy *request_wiphy;
2421 /* Some basic sanity checks first */
2423 if (is_world_regdom(rd->alpha2)) {
2424 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
2426 update_world_regdomain(rd);
2430 if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) &&
2431 !is_unknown_alpha2(rd->alpha2))
2438 * Lets only bother proceeding on the same alpha2 if the current
2439 * rd is non static (it means CRDA was present and was used last)
2440 * and the pending request came in from a country IE
2442 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2444 * If someone else asked us to change the rd lets only bother
2445 * checking if the alpha2 changes if CRDA was already called
2447 if (!regdom_changes(rd->alpha2))
2452 * Now lets set the regulatory domain, update all driver channels
2453 * and finally inform them of what we have done, in case they want
2454 * to review or adjust their own settings based on their own
2455 * internal EEPROM data
2458 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
2461 if (!is_valid_rd(rd)) {
2462 printk(KERN_ERR "cfg80211: Invalid "
2463 "regulatory domain detected:\n");
2464 print_regdomain_info(rd);
2468 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
2470 if (!last_request->intersect) {
2473 if (last_request->initiator != NL80211_REGDOM_SET_BY_DRIVER) {
2475 cfg80211_regdomain = rd;
2480 * For a driver hint, lets copy the regulatory domain the
2481 * driver wanted to the wiphy to deal with conflicts
2485 * Userspace could have sent two replies with only
2486 * one kernel request.
2488 if (request_wiphy->regd)
2491 r = reg_copy_regd(&request_wiphy->regd, rd);
2496 cfg80211_regdomain = rd;
2500 /* Intersection requires a bit more work */
2502 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
2504 intersected_rd = regdom_intersect(rd, cfg80211_regdomain);
2505 if (!intersected_rd)
2509 * We can trash what CRDA provided now.
2510 * However if a driver requested this specific regulatory
2511 * domain we keep it for its private use
2513 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER)
2514 request_wiphy->regd = rd;
2521 cfg80211_regdomain = intersected_rd;
2527 * Country IE requests are handled a bit differently, we intersect
2528 * the country IE rd with what CRDA believes that country should have
2532 * Userspace could have sent two replies with only
2533 * one kernel request. By the second reply we would have
2534 * already processed and consumed the country_ie_regdomain.
2536 if (!country_ie_regdomain)
2538 BUG_ON(rd == country_ie_regdomain);
2541 * Intersect what CRDA returned and our what we
2542 * had built from the Country IE received
2545 intersected_rd = regdom_intersect(rd, country_ie_regdomain);
2547 reg_country_ie_process_debug(rd,
2548 country_ie_regdomain,
2551 kfree(country_ie_regdomain);
2552 country_ie_regdomain = NULL;
2554 if (!intersected_rd)
2557 rdev = wiphy_to_dev(request_wiphy);
2559 rdev->country_ie_alpha2[0] = rd->alpha2[0];
2560 rdev->country_ie_alpha2[1] = rd->alpha2[1];
2561 rdev->env = last_request->country_ie_env;
2563 BUG_ON(intersected_rd == rd);
2569 cfg80211_regdomain = intersected_rd;
2576 * Use this call to set the current regulatory domain. Conflicts with
2577 * multiple drivers can be ironed out later. Caller must've already
2578 * kmalloc'd the rd structure. Caller must hold cfg80211_mutex
2580 int set_regdom(const struct ieee80211_regdomain *rd)
2584 assert_cfg80211_lock();
2586 mutex_lock(®_mutex);
2588 /* Note that this doesn't update the wiphys, this is done below */
2589 r = __set_regdom(rd);
2592 mutex_unlock(®_mutex);
2596 /* This would make this whole thing pointless */
2597 if (!last_request->intersect)
2598 BUG_ON(rd != cfg80211_regdomain);
2600 /* update all wiphys now with the new established regulatory domain */
2601 update_all_wiphy_regulatory(last_request->initiator);
2603 print_regdomain(cfg80211_regdomain);
2605 nl80211_send_reg_change_event(last_request);
2607 mutex_unlock(®_mutex);
2612 /* Caller must hold cfg80211_mutex */
2613 void reg_device_remove(struct wiphy *wiphy)
2615 struct wiphy *request_wiphy = NULL;
2617 assert_cfg80211_lock();
2619 mutex_lock(®_mutex);
2624 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
2626 if (!request_wiphy || request_wiphy != wiphy)
2629 last_request->wiphy_idx = WIPHY_IDX_STALE;
2630 last_request->country_ie_env = ENVIRON_ANY;
2632 mutex_unlock(®_mutex);
2635 int regulatory_init(void)
2639 reg_pdev = platform_device_register_simple("regulatory", 0, NULL, 0);
2640 if (IS_ERR(reg_pdev))
2641 return PTR_ERR(reg_pdev);
2643 spin_lock_init(®_requests_lock);
2644 spin_lock_init(®_pending_beacons_lock);
2646 cfg80211_regdomain = cfg80211_world_regdom;
2648 user_alpha2[0] = '9';
2649 user_alpha2[1] = '7';
2651 /* We always try to get an update for the static regdomain */
2652 err = regulatory_hint_core(cfg80211_regdomain->alpha2);
2657 * N.B. kobject_uevent_env() can fail mainly for when we're out
2658 * memory which is handled and propagated appropriately above
2659 * but it can also fail during a netlink_broadcast() or during
2660 * early boot for call_usermodehelper(). For now treat these
2661 * errors as non-fatal.
2663 printk(KERN_ERR "cfg80211: kobject_uevent_env() was unable "
2664 "to call CRDA during init");
2665 #ifdef CONFIG_CFG80211_REG_DEBUG
2666 /* We want to find out exactly why when debugging */
2672 * Finally, if the user set the module parameter treat it
2675 if (!is_world_regdom(ieee80211_regdom))
2676 regulatory_hint_user(ieee80211_regdom);
2681 void regulatory_exit(void)
2683 struct regulatory_request *reg_request, *tmp;
2684 struct reg_beacon *reg_beacon, *btmp;
2686 cancel_work_sync(®_work);
2688 mutex_lock(&cfg80211_mutex);
2689 mutex_lock(®_mutex);
2693 kfree(country_ie_regdomain);
2694 country_ie_regdomain = NULL;
2696 kfree(last_request);
2698 platform_device_unregister(reg_pdev);
2700 spin_lock_bh(®_pending_beacons_lock);
2701 if (!list_empty(®_pending_beacons)) {
2702 list_for_each_entry_safe(reg_beacon, btmp,
2703 ®_pending_beacons, list) {
2704 list_del(®_beacon->list);
2708 spin_unlock_bh(®_pending_beacons_lock);
2710 if (!list_empty(®_beacon_list)) {
2711 list_for_each_entry_safe(reg_beacon, btmp,
2712 ®_beacon_list, list) {
2713 list_del(®_beacon->list);
2718 spin_lock(®_requests_lock);
2719 if (!list_empty(®_requests_list)) {
2720 list_for_each_entry_safe(reg_request, tmp,
2721 ®_requests_list, list) {
2722 list_del(®_request->list);
2726 spin_unlock(®_requests_lock);
2728 mutex_unlock(®_mutex);
2729 mutex_unlock(&cfg80211_mutex);