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/list.h>
37 #include <linux/random.h>
38 #include <linux/nl80211.h>
39 #include <linux/platform_device.h>
40 #include <net/cfg80211.h>
46 /* Receipt of information from last regulatory request */
47 static struct regulatory_request
*last_request
;
49 /* To trigger userspace events */
50 static struct platform_device
*reg_pdev
;
53 * Central wireless core regulatory domains, we only need two,
54 * the current one and a world regulatory domain in case we have no
55 * information to give us an alpha2
57 const struct ieee80211_regdomain
*cfg80211_regdomain
;
60 * We use this as a place for the rd structure built from the
61 * last parsed country IE to rest until CRDA gets back to us with
62 * what it thinks should apply for the same country
64 static const struct ieee80211_regdomain
*country_ie_regdomain
;
67 * Protects static reg.c components:
68 * - cfg80211_world_regdom
70 * - country_ie_regdomain
73 DEFINE_MUTEX(reg_mutex
);
74 #define assert_reg_lock() WARN_ON(!mutex_is_locked(®_mutex))
76 /* Used to queue up regulatory hints */
77 static LIST_HEAD(reg_requests_list
);
78 static spinlock_t reg_requests_lock
;
80 /* Used to queue up beacon hints for review */
81 static LIST_HEAD(reg_pending_beacons
);
82 static spinlock_t reg_pending_beacons_lock
;
84 /* Used to keep track of processed beacon hints */
85 static LIST_HEAD(reg_beacon_list
);
88 struct list_head list
;
89 struct ieee80211_channel chan
;
92 /* We keep a static world regulatory domain in case of the absence of CRDA */
93 static const struct ieee80211_regdomain world_regdom
= {
97 /* IEEE 802.11b/g, channels 1..11 */
98 REG_RULE(2412-10, 2462+10, 40, 6, 20, 0),
99 /* IEEE 802.11b/g, channels 12..13. No HT40
100 * channel fits here. */
101 REG_RULE(2467-10, 2472+10, 20, 6, 20,
102 NL80211_RRF_PASSIVE_SCAN
|
103 NL80211_RRF_NO_IBSS
),
104 /* IEEE 802.11 channel 14 - Only JP enables
105 * this and for 802.11b only */
106 REG_RULE(2484-10, 2484+10, 20, 6, 20,
107 NL80211_RRF_PASSIVE_SCAN
|
108 NL80211_RRF_NO_IBSS
|
109 NL80211_RRF_NO_OFDM
),
110 /* IEEE 802.11a, channel 36..48 */
111 REG_RULE(5180-10, 5240+10, 40, 6, 20,
112 NL80211_RRF_PASSIVE_SCAN
|
113 NL80211_RRF_NO_IBSS
),
115 /* NB: 5260 MHz - 5700 MHz requies DFS */
117 /* IEEE 802.11a, channel 149..165 */
118 REG_RULE(5745-10, 5825+10, 40, 6, 20,
119 NL80211_RRF_PASSIVE_SCAN
|
120 NL80211_RRF_NO_IBSS
),
124 static const struct ieee80211_regdomain
*cfg80211_world_regdom
=
127 static char *ieee80211_regdom
= "00";
129 module_param(ieee80211_regdom
, charp
, 0444);
130 MODULE_PARM_DESC(ieee80211_regdom
, "IEEE 802.11 regulatory domain code");
132 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
134 * We assume 40 MHz bandwidth for the old regulatory work.
135 * We make emphasis we are using the exact same frequencies
139 static const struct ieee80211_regdomain us_regdom
= {
143 /* IEEE 802.11b/g, channels 1..11 */
144 REG_RULE(2412-10, 2462+10, 40, 6, 27, 0),
145 /* IEEE 802.11a, channel 36 */
146 REG_RULE(5180-10, 5180+10, 40, 6, 23, 0),
147 /* IEEE 802.11a, channel 40 */
148 REG_RULE(5200-10, 5200+10, 40, 6, 23, 0),
149 /* IEEE 802.11a, channel 44 */
150 REG_RULE(5220-10, 5220+10, 40, 6, 23, 0),
151 /* IEEE 802.11a, channels 48..64 */
152 REG_RULE(5240-10, 5320+10, 40, 6, 23, 0),
153 /* IEEE 802.11a, channels 149..165, outdoor */
154 REG_RULE(5745-10, 5825+10, 40, 6, 30, 0),
158 static const struct ieee80211_regdomain jp_regdom
= {
162 /* IEEE 802.11b/g, channels 1..14 */
163 REG_RULE(2412-10, 2484+10, 40, 6, 20, 0),
164 /* IEEE 802.11a, channels 34..48 */
165 REG_RULE(5170-10, 5240+10, 40, 6, 20,
166 NL80211_RRF_PASSIVE_SCAN
),
167 /* IEEE 802.11a, channels 52..64 */
168 REG_RULE(5260-10, 5320+10, 40, 6, 20,
169 NL80211_RRF_NO_IBSS
|
174 static const struct ieee80211_regdomain eu_regdom
= {
177 * This alpha2 is bogus, we leave it here just for stupid
178 * backward compatibility
182 /* IEEE 802.11b/g, channels 1..13 */
183 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
184 /* IEEE 802.11a, channel 36 */
185 REG_RULE(5180-10, 5180+10, 40, 6, 23,
186 NL80211_RRF_PASSIVE_SCAN
),
187 /* IEEE 802.11a, channel 40 */
188 REG_RULE(5200-10, 5200+10, 40, 6, 23,
189 NL80211_RRF_PASSIVE_SCAN
),
190 /* IEEE 802.11a, channel 44 */
191 REG_RULE(5220-10, 5220+10, 40, 6, 23,
192 NL80211_RRF_PASSIVE_SCAN
),
193 /* IEEE 802.11a, channels 48..64 */
194 REG_RULE(5240-10, 5320+10, 40, 6, 20,
195 NL80211_RRF_NO_IBSS
|
197 /* IEEE 802.11a, channels 100..140 */
198 REG_RULE(5500-10, 5700+10, 40, 6, 30,
199 NL80211_RRF_NO_IBSS
|
204 static const struct ieee80211_regdomain
*static_regdom(char *alpha2
)
206 if (alpha2
[0] == 'U' && alpha2
[1] == 'S')
208 if (alpha2
[0] == 'J' && alpha2
[1] == 'P')
210 if (alpha2
[0] == 'E' && alpha2
[1] == 'U')
212 /* Default, as per the old rules */
216 static bool is_old_static_regdom(const struct ieee80211_regdomain
*rd
)
218 if (rd
== &us_regdom
|| rd
== &jp_regdom
|| rd
== &eu_regdom
)
223 static inline bool is_old_static_regdom(const struct ieee80211_regdomain
*rd
)
229 static void reset_regdomains(void)
231 /* avoid freeing static information or freeing something twice */
232 if (cfg80211_regdomain
== cfg80211_world_regdom
)
233 cfg80211_regdomain
= NULL
;
234 if (cfg80211_world_regdom
== &world_regdom
)
235 cfg80211_world_regdom
= NULL
;
236 if (cfg80211_regdomain
== &world_regdom
)
237 cfg80211_regdomain
= NULL
;
238 if (is_old_static_regdom(cfg80211_regdomain
))
239 cfg80211_regdomain
= NULL
;
241 kfree(cfg80211_regdomain
);
242 kfree(cfg80211_world_regdom
);
244 cfg80211_world_regdom
= &world_regdom
;
245 cfg80211_regdomain
= NULL
;
249 * Dynamic world regulatory domain requested by the wireless
250 * core upon initialization
252 static void update_world_regdomain(const struct ieee80211_regdomain
*rd
)
254 BUG_ON(!last_request
);
258 cfg80211_world_regdom
= rd
;
259 cfg80211_regdomain
= rd
;
262 bool is_world_regdom(const char *alpha2
)
266 if (alpha2
[0] == '0' && alpha2
[1] == '0')
271 static bool is_alpha2_set(const char *alpha2
)
275 if (alpha2
[0] != 0 && alpha2
[1] != 0)
280 static bool is_alpha_upper(char letter
)
283 if (letter
>= 65 && letter
<= 90)
288 static bool is_unknown_alpha2(const char *alpha2
)
293 * Special case where regulatory domain was built by driver
294 * but a specific alpha2 cannot be determined
296 if (alpha2
[0] == '9' && alpha2
[1] == '9')
301 static bool is_intersected_alpha2(const char *alpha2
)
306 * Special case where regulatory domain is the
307 * result of an intersection between two regulatory domain
310 if (alpha2
[0] == '9' && alpha2
[1] == '8')
315 static bool is_an_alpha2(const char *alpha2
)
319 if (is_alpha_upper(alpha2
[0]) && is_alpha_upper(alpha2
[1]))
324 static bool alpha2_equal(const char *alpha2_x
, const char *alpha2_y
)
326 if (!alpha2_x
|| !alpha2_y
)
328 if (alpha2_x
[0] == alpha2_y
[0] &&
329 alpha2_x
[1] == alpha2_y
[1])
334 static bool regdom_changes(const char *alpha2
)
336 assert_cfg80211_lock();
338 if (!cfg80211_regdomain
)
340 if (alpha2_equal(cfg80211_regdomain
->alpha2
, alpha2
))
346 * country_ie_integrity_changes - tells us if the country IE has changed
347 * @checksum: checksum of country IE of fields we are interested in
349 * If the country IE has not changed you can ignore it safely. This is
350 * useful to determine if two devices are seeing two different country IEs
351 * even on the same alpha2. Note that this will return false if no IE has
352 * been set on the wireless core yet.
354 static bool country_ie_integrity_changes(u32 checksum
)
356 /* If no IE has been set then the checksum doesn't change */
357 if (unlikely(!last_request
->country_ie_checksum
))
359 if (unlikely(last_request
->country_ie_checksum
!= checksum
))
364 static int reg_copy_regd(const struct ieee80211_regdomain
**dst_regd
,
365 const struct ieee80211_regdomain
*src_regd
)
367 struct ieee80211_regdomain
*regd
;
368 int size_of_regd
= 0;
371 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
372 ((src_regd
->n_reg_rules
+ 1) * sizeof(struct ieee80211_reg_rule
));
374 regd
= kzalloc(size_of_regd
, GFP_KERNEL
);
378 memcpy(regd
, src_regd
, sizeof(struct ieee80211_regdomain
));
380 for (i
= 0; i
< src_regd
->n_reg_rules
; i
++)
381 memcpy(®d
->reg_rules
[i
], &src_regd
->reg_rules
[i
],
382 sizeof(struct ieee80211_reg_rule
));
388 #ifdef CONFIG_CFG80211_INTERNAL_REGDB
389 struct reg_regdb_search_request
{
391 struct list_head list
;
394 static LIST_HEAD(reg_regdb_search_list
);
395 static DEFINE_SPINLOCK(reg_regdb_search_lock
);
397 static void reg_regdb_search(struct work_struct
*work
)
399 struct reg_regdb_search_request
*request
;
400 const struct ieee80211_regdomain
*curdom
, *regdom
;
403 spin_lock(®_regdb_search_lock
);
404 while (!list_empty(®_regdb_search_list
)) {
405 request
= list_first_entry(®_regdb_search_list
,
406 struct reg_regdb_search_request
,
408 list_del(&request
->list
);
410 for (i
=0; i
<reg_regdb_size
; i
++) {
411 curdom
= reg_regdb
[i
];
413 if (!memcmp(request
->alpha2
, curdom
->alpha2
, 2)) {
414 r
= reg_copy_regd(®dom
, curdom
);
417 spin_unlock(®_regdb_search_lock
);
418 mutex_lock(&cfg80211_mutex
);
420 mutex_unlock(&cfg80211_mutex
);
421 spin_lock(®_regdb_search_lock
);
428 spin_unlock(®_regdb_search_lock
);
431 static DECLARE_WORK(reg_regdb_work
, reg_regdb_search
);
433 static void reg_regdb_query(const char *alpha2
)
435 struct reg_regdb_search_request
*request
;
440 request
= kzalloc(sizeof(struct reg_regdb_search_request
), GFP_KERNEL
);
444 memcpy(request
->alpha2
, alpha2
, 2);
446 spin_lock(®_regdb_search_lock
);
447 list_add_tail(&request
->list
, ®_regdb_search_list
);
448 spin_unlock(®_regdb_search_lock
);
450 schedule_work(®_regdb_work
);
453 static inline void reg_regdb_query(const char *alpha2
) {}
454 #endif /* CONFIG_CFG80211_INTERNAL_REGDB */
457 * This lets us keep regulatory code which is updated on a regulatory
458 * basis in userspace.
460 static int call_crda(const char *alpha2
)
462 char country_env
[9 + 2] = "COUNTRY=";
468 if (!is_world_regdom((char *) alpha2
))
469 printk(KERN_INFO
"cfg80211: Calling CRDA for country: %c%c\n",
470 alpha2
[0], alpha2
[1]);
472 printk(KERN_INFO
"cfg80211: Calling CRDA to update world "
473 "regulatory domain\n");
475 /* query internal regulatory database (if it exists) */
476 reg_regdb_query(alpha2
);
478 country_env
[8] = alpha2
[0];
479 country_env
[9] = alpha2
[1];
481 return kobject_uevent_env(®_pdev
->dev
.kobj
, KOBJ_CHANGE
, envp
);
484 /* Used by nl80211 before kmalloc'ing our regulatory domain */
485 bool reg_is_valid_request(const char *alpha2
)
487 assert_cfg80211_lock();
492 return alpha2_equal(last_request
->alpha2
, alpha2
);
495 /* Sanity check on a regulatory rule */
496 static bool is_valid_reg_rule(const struct ieee80211_reg_rule
*rule
)
498 const struct ieee80211_freq_range
*freq_range
= &rule
->freq_range
;
501 if (freq_range
->start_freq_khz
<= 0 || freq_range
->end_freq_khz
<= 0)
504 if (freq_range
->start_freq_khz
> freq_range
->end_freq_khz
)
507 freq_diff
= freq_range
->end_freq_khz
- freq_range
->start_freq_khz
;
509 if (freq_range
->end_freq_khz
<= freq_range
->start_freq_khz
||
510 freq_range
->max_bandwidth_khz
> freq_diff
)
516 static bool is_valid_rd(const struct ieee80211_regdomain
*rd
)
518 const struct ieee80211_reg_rule
*reg_rule
= NULL
;
521 if (!rd
->n_reg_rules
)
524 if (WARN_ON(rd
->n_reg_rules
> NL80211_MAX_SUPP_REG_RULES
))
527 for (i
= 0; i
< rd
->n_reg_rules
; i
++) {
528 reg_rule
= &rd
->reg_rules
[i
];
529 if (!is_valid_reg_rule(reg_rule
))
536 static bool reg_does_bw_fit(const struct ieee80211_freq_range
*freq_range
,
540 u32 start_freq_khz
, end_freq_khz
;
542 start_freq_khz
= center_freq_khz
- (bw_khz
/2);
543 end_freq_khz
= center_freq_khz
+ (bw_khz
/2);
545 if (start_freq_khz
>= freq_range
->start_freq_khz
&&
546 end_freq_khz
<= freq_range
->end_freq_khz
)
553 * freq_in_rule_band - tells us if a frequency is in a frequency band
554 * @freq_range: frequency rule we want to query
555 * @freq_khz: frequency we are inquiring about
557 * This lets us know if a specific frequency rule is or is not relevant to
558 * a specific frequency's band. Bands are device specific and artificial
559 * definitions (the "2.4 GHz band" and the "5 GHz band"), however it is
560 * safe for now to assume that a frequency rule should not be part of a
561 * frequency's band if the start freq or end freq are off by more than 2 GHz.
562 * This resolution can be lowered and should be considered as we add
563 * regulatory rule support for other "bands".
565 static bool freq_in_rule_band(const struct ieee80211_freq_range
*freq_range
,
568 #define ONE_GHZ_IN_KHZ 1000000
569 if (abs(freq_khz
- freq_range
->start_freq_khz
) <= (2 * ONE_GHZ_IN_KHZ
))
571 if (abs(freq_khz
- freq_range
->end_freq_khz
) <= (2 * ONE_GHZ_IN_KHZ
))
574 #undef ONE_GHZ_IN_KHZ
578 * Converts a country IE to a regulatory domain. A regulatory domain
579 * structure has a lot of information which the IE doesn't yet have,
580 * so for the other values we use upper max values as we will intersect
581 * with our userspace regulatory agent to get lower bounds.
583 static struct ieee80211_regdomain
*country_ie_2_rd(
588 struct ieee80211_regdomain
*rd
= NULL
;
592 u32 num_rules
= 0, size_of_regd
= 0;
593 u8
*triplets_start
= NULL
;
594 u8 len_at_triplet
= 0;
595 /* the last channel we have registered in a subband (triplet) */
596 int last_sub_max_channel
= 0;
598 *checksum
= 0xDEADBEEF;
600 /* Country IE requirements */
601 BUG_ON(country_ie_len
< IEEE80211_COUNTRY_IE_MIN_LEN
||
602 country_ie_len
& 0x01);
604 alpha2
[0] = country_ie
[0];
605 alpha2
[1] = country_ie
[1];
608 * Third octet can be:
612 * anything else we assume is no restrictions
614 if (country_ie
[2] == 'I')
615 flags
= NL80211_RRF_NO_OUTDOOR
;
616 else if (country_ie
[2] == 'O')
617 flags
= NL80211_RRF_NO_INDOOR
;
622 triplets_start
= country_ie
;
623 len_at_triplet
= country_ie_len
;
625 *checksum
^= ((flags
^ alpha2
[0] ^ alpha2
[1]) << 8);
628 * We need to build a reg rule for each triplet, but first we must
629 * calculate the number of reg rules we will need. We will need one
630 * for each channel subband
632 while (country_ie_len
>= 3) {
634 struct ieee80211_country_ie_triplet
*triplet
=
635 (struct ieee80211_country_ie_triplet
*) country_ie
;
636 int cur_sub_max_channel
= 0, cur_channel
= 0;
638 if (triplet
->ext
.reg_extension_id
>=
639 IEEE80211_COUNTRY_EXTENSION_ID
) {
646 if (triplet
->chans
.first_channel
<= 14)
647 end_channel
= triplet
->chans
.first_channel
+
648 triplet
->chans
.num_channels
;
651 * 5 GHz -- For example in country IEs if the first
652 * channel given is 36 and the number of channels is 4
653 * then the individual channel numbers defined for the
654 * 5 GHz PHY by these parameters are: 36, 40, 44, and 48
655 * and not 36, 37, 38, 39.
657 * See: http://tinyurl.com/11d-clarification
659 end_channel
= triplet
->chans
.first_channel
+
660 (4 * (triplet
->chans
.num_channels
- 1));
662 cur_channel
= triplet
->chans
.first_channel
;
663 cur_sub_max_channel
= end_channel
;
665 /* Basic sanity check */
666 if (cur_sub_max_channel
< cur_channel
)
670 * Do not allow overlapping channels. Also channels
671 * passed in each subband must be monotonically
674 if (last_sub_max_channel
) {
675 if (cur_channel
<= last_sub_max_channel
)
677 if (cur_sub_max_channel
<= last_sub_max_channel
)
682 * When dot11RegulatoryClassesRequired is supported
683 * we can throw ext triplets as part of this soup,
684 * for now we don't care when those change as we
687 *checksum
^= ((cur_channel
^ cur_sub_max_channel
) << 8) |
688 ((cur_sub_max_channel
^ cur_sub_max_channel
) << 16) |
689 ((triplet
->chans
.max_power
^ cur_sub_max_channel
) << 24);
691 last_sub_max_channel
= cur_sub_max_channel
;
698 * Note: this is not a IEEE requirement but
699 * simply a memory requirement
701 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
705 country_ie
= triplets_start
;
706 country_ie_len
= len_at_triplet
;
708 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
709 (num_rules
* sizeof(struct ieee80211_reg_rule
));
711 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
715 rd
->n_reg_rules
= num_rules
;
716 rd
->alpha2
[0] = alpha2
[0];
717 rd
->alpha2
[1] = alpha2
[1];
719 /* This time around we fill in the rd */
720 while (country_ie_len
>= 3) {
722 struct ieee80211_country_ie_triplet
*triplet
=
723 (struct ieee80211_country_ie_triplet
*) country_ie
;
724 struct ieee80211_reg_rule
*reg_rule
= NULL
;
725 struct ieee80211_freq_range
*freq_range
= NULL
;
726 struct ieee80211_power_rule
*power_rule
= NULL
;
729 * Must parse if dot11RegulatoryClassesRequired is true,
730 * we don't support this yet
732 if (triplet
->ext
.reg_extension_id
>=
733 IEEE80211_COUNTRY_EXTENSION_ID
) {
739 reg_rule
= &rd
->reg_rules
[i
];
740 freq_range
= ®_rule
->freq_range
;
741 power_rule
= ®_rule
->power_rule
;
743 reg_rule
->flags
= flags
;
746 if (triplet
->chans
.first_channel
<= 14)
747 end_channel
= triplet
->chans
.first_channel
+
748 triplet
->chans
.num_channels
;
750 end_channel
= triplet
->chans
.first_channel
+
751 (4 * (triplet
->chans
.num_channels
- 1));
754 * The +10 is since the regulatory domain expects
755 * the actual band edge, not the center of freq for
756 * its start and end freqs, assuming 20 MHz bandwidth on
757 * the channels passed
759 freq_range
->start_freq_khz
=
760 MHZ_TO_KHZ(ieee80211_channel_to_frequency(
761 triplet
->chans
.first_channel
) - 10);
762 freq_range
->end_freq_khz
=
763 MHZ_TO_KHZ(ieee80211_channel_to_frequency(
767 * These are large arbitrary values we use to intersect later.
768 * Increment this if we ever support >= 40 MHz channels
771 freq_range
->max_bandwidth_khz
= MHZ_TO_KHZ(40);
772 power_rule
->max_antenna_gain
= DBI_TO_MBI(100);
773 power_rule
->max_eirp
= DBM_TO_MBM(100);
779 BUG_ON(i
> NL80211_MAX_SUPP_REG_RULES
);
787 * Helper for regdom_intersect(), this does the real
788 * mathematical intersection fun
790 static int reg_rules_intersect(
791 const struct ieee80211_reg_rule
*rule1
,
792 const struct ieee80211_reg_rule
*rule2
,
793 struct ieee80211_reg_rule
*intersected_rule
)
795 const struct ieee80211_freq_range
*freq_range1
, *freq_range2
;
796 struct ieee80211_freq_range
*freq_range
;
797 const struct ieee80211_power_rule
*power_rule1
, *power_rule2
;
798 struct ieee80211_power_rule
*power_rule
;
801 freq_range1
= &rule1
->freq_range
;
802 freq_range2
= &rule2
->freq_range
;
803 freq_range
= &intersected_rule
->freq_range
;
805 power_rule1
= &rule1
->power_rule
;
806 power_rule2
= &rule2
->power_rule
;
807 power_rule
= &intersected_rule
->power_rule
;
809 freq_range
->start_freq_khz
= max(freq_range1
->start_freq_khz
,
810 freq_range2
->start_freq_khz
);
811 freq_range
->end_freq_khz
= min(freq_range1
->end_freq_khz
,
812 freq_range2
->end_freq_khz
);
813 freq_range
->max_bandwidth_khz
= min(freq_range1
->max_bandwidth_khz
,
814 freq_range2
->max_bandwidth_khz
);
816 freq_diff
= freq_range
->end_freq_khz
- freq_range
->start_freq_khz
;
817 if (freq_range
->max_bandwidth_khz
> freq_diff
)
818 freq_range
->max_bandwidth_khz
= freq_diff
;
820 power_rule
->max_eirp
= min(power_rule1
->max_eirp
,
821 power_rule2
->max_eirp
);
822 power_rule
->max_antenna_gain
= min(power_rule1
->max_antenna_gain
,
823 power_rule2
->max_antenna_gain
);
825 intersected_rule
->flags
= (rule1
->flags
| rule2
->flags
);
827 if (!is_valid_reg_rule(intersected_rule
))
834 * regdom_intersect - do the intersection between two regulatory domains
835 * @rd1: first regulatory domain
836 * @rd2: second regulatory domain
838 * Use this function to get the intersection between two regulatory domains.
839 * Once completed we will mark the alpha2 for the rd as intersected, "98",
840 * as no one single alpha2 can represent this regulatory domain.
842 * Returns a pointer to the regulatory domain structure which will hold the
843 * resulting intersection of rules between rd1 and rd2. We will
844 * kzalloc() this structure for you.
846 static struct ieee80211_regdomain
*regdom_intersect(
847 const struct ieee80211_regdomain
*rd1
,
848 const struct ieee80211_regdomain
*rd2
)
852 unsigned int num_rules
= 0, rule_idx
= 0;
853 const struct ieee80211_reg_rule
*rule1
, *rule2
;
854 struct ieee80211_reg_rule
*intersected_rule
;
855 struct ieee80211_regdomain
*rd
;
856 /* This is just a dummy holder to help us count */
857 struct ieee80211_reg_rule irule
;
859 /* Uses the stack temporarily for counter arithmetic */
860 intersected_rule
= &irule
;
862 memset(intersected_rule
, 0, sizeof(struct ieee80211_reg_rule
));
868 * First we get a count of the rules we'll need, then we actually
869 * build them. This is to so we can malloc() and free() a
870 * regdomain once. The reason we use reg_rules_intersect() here
871 * is it will return -EINVAL if the rule computed makes no sense.
872 * All rules that do check out OK are valid.
875 for (x
= 0; x
< rd1
->n_reg_rules
; x
++) {
876 rule1
= &rd1
->reg_rules
[x
];
877 for (y
= 0; y
< rd2
->n_reg_rules
; y
++) {
878 rule2
= &rd2
->reg_rules
[y
];
879 if (!reg_rules_intersect(rule1
, rule2
,
882 memset(intersected_rule
, 0,
883 sizeof(struct ieee80211_reg_rule
));
890 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
891 ((num_rules
+ 1) * sizeof(struct ieee80211_reg_rule
));
893 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
897 for (x
= 0; x
< rd1
->n_reg_rules
; x
++) {
898 rule1
= &rd1
->reg_rules
[x
];
899 for (y
= 0; y
< rd2
->n_reg_rules
; y
++) {
900 rule2
= &rd2
->reg_rules
[y
];
902 * This time around instead of using the stack lets
903 * write to the target rule directly saving ourselves
906 intersected_rule
= &rd
->reg_rules
[rule_idx
];
907 r
= reg_rules_intersect(rule1
, rule2
,
910 * No need to memset here the intersected rule here as
911 * we're not using the stack anymore
919 if (rule_idx
!= num_rules
) {
924 rd
->n_reg_rules
= num_rules
;
932 * XXX: add support for the rest of enum nl80211_reg_rule_flags, we may
933 * want to just have the channel structure use these
935 static u32
map_regdom_flags(u32 rd_flags
)
937 u32 channel_flags
= 0;
938 if (rd_flags
& NL80211_RRF_PASSIVE_SCAN
)
939 channel_flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
940 if (rd_flags
& NL80211_RRF_NO_IBSS
)
941 channel_flags
|= IEEE80211_CHAN_NO_IBSS
;
942 if (rd_flags
& NL80211_RRF_DFS
)
943 channel_flags
|= IEEE80211_CHAN_RADAR
;
944 return channel_flags
;
947 static int freq_reg_info_regd(struct wiphy
*wiphy
,
950 const struct ieee80211_reg_rule
**reg_rule
,
951 const struct ieee80211_regdomain
*custom_regd
)
954 bool band_rule_found
= false;
955 const struct ieee80211_regdomain
*regd
;
956 bool bw_fits
= false;
959 desired_bw_khz
= MHZ_TO_KHZ(20);
961 regd
= custom_regd
? custom_regd
: cfg80211_regdomain
;
964 * Follow the driver's regulatory domain, if present, unless a country
965 * IE has been processed or a user wants to help complaince further
967 if (last_request
->initiator
!= NL80211_REGDOM_SET_BY_COUNTRY_IE
&&
968 last_request
->initiator
!= NL80211_REGDOM_SET_BY_USER
&&
975 for (i
= 0; i
< regd
->n_reg_rules
; i
++) {
976 const struct ieee80211_reg_rule
*rr
;
977 const struct ieee80211_freq_range
*fr
= NULL
;
978 const struct ieee80211_power_rule
*pr
= NULL
;
980 rr
= ®d
->reg_rules
[i
];
981 fr
= &rr
->freq_range
;
982 pr
= &rr
->power_rule
;
985 * We only need to know if one frequency rule was
986 * was in center_freq's band, that's enough, so lets
987 * not overwrite it once found
989 if (!band_rule_found
)
990 band_rule_found
= freq_in_rule_band(fr
, center_freq
);
992 bw_fits
= reg_does_bw_fit(fr
,
996 if (band_rule_found
&& bw_fits
) {
1002 if (!band_rule_found
)
1007 EXPORT_SYMBOL(freq_reg_info
);
1009 int freq_reg_info(struct wiphy
*wiphy
,
1012 const struct ieee80211_reg_rule
**reg_rule
)
1014 assert_cfg80211_lock();
1015 return freq_reg_info_regd(wiphy
,
1023 * Note that right now we assume the desired channel bandwidth
1024 * is always 20 MHz for each individual channel (HT40 uses 20 MHz
1025 * per channel, the primary and the extension channel). To support
1026 * smaller custom bandwidths such as 5 MHz or 10 MHz we'll need a
1027 * new ieee80211_channel.target_bw and re run the regulatory check
1028 * on the wiphy with the target_bw specified. Then we can simply use
1029 * that below for the desired_bw_khz below.
1031 static void handle_channel(struct wiphy
*wiphy
, enum ieee80211_band band
,
1032 unsigned int chan_idx
)
1035 u32 flags
, bw_flags
= 0;
1036 u32 desired_bw_khz
= MHZ_TO_KHZ(20);
1037 const struct ieee80211_reg_rule
*reg_rule
= NULL
;
1038 const struct ieee80211_power_rule
*power_rule
= NULL
;
1039 const struct ieee80211_freq_range
*freq_range
= NULL
;
1040 struct ieee80211_supported_band
*sband
;
1041 struct ieee80211_channel
*chan
;
1042 struct wiphy
*request_wiphy
= NULL
;
1044 assert_cfg80211_lock();
1046 request_wiphy
= wiphy_idx_to_wiphy(last_request
->wiphy_idx
);
1048 sband
= wiphy
->bands
[band
];
1049 BUG_ON(chan_idx
>= sband
->n_channels
);
1050 chan
= &sband
->channels
[chan_idx
];
1052 flags
= chan
->orig_flags
;
1054 r
= freq_reg_info(wiphy
,
1055 MHZ_TO_KHZ(chan
->center_freq
),
1061 * This means no regulatory rule was found in the country IE
1062 * with a frequency range on the center_freq's band, since
1063 * IEEE-802.11 allows for a country IE to have a subset of the
1064 * regulatory information provided in a country we ignore
1065 * disabling the channel unless at least one reg rule was
1066 * found on the center_freq's band. For details see this
1069 * http://tinyurl.com/11d-clarification
1072 last_request
->initiator
==
1073 NL80211_REGDOM_SET_BY_COUNTRY_IE
) {
1074 #ifdef CONFIG_CFG80211_REG_DEBUG
1075 printk(KERN_DEBUG
"cfg80211: Leaving channel %d MHz "
1076 "intact on %s - no rule found in band on "
1078 chan
->center_freq
, wiphy_name(wiphy
));
1082 * In this case we know the country IE has at least one reg rule
1083 * for the band so we respect its band definitions
1085 #ifdef CONFIG_CFG80211_REG_DEBUG
1086 if (last_request
->initiator
==
1087 NL80211_REGDOM_SET_BY_COUNTRY_IE
)
1088 printk(KERN_DEBUG
"cfg80211: Disabling "
1089 "channel %d MHz on %s due to "
1091 chan
->center_freq
, wiphy_name(wiphy
));
1093 flags
|= IEEE80211_CHAN_DISABLED
;
1094 chan
->flags
= flags
;
1099 power_rule
= ®_rule
->power_rule
;
1100 freq_range
= ®_rule
->freq_range
;
1102 if (freq_range
->max_bandwidth_khz
< MHZ_TO_KHZ(40))
1103 bw_flags
= IEEE80211_CHAN_NO_HT40
;
1105 if (last_request
->initiator
== NL80211_REGDOM_SET_BY_DRIVER
&&
1106 request_wiphy
&& request_wiphy
== wiphy
&&
1107 request_wiphy
->flags
& WIPHY_FLAG_STRICT_REGULATORY
) {
1109 * This gaurantees the driver's requested regulatory domain
1110 * will always be used as a base for further regulatory
1113 chan
->flags
= chan
->orig_flags
=
1114 map_regdom_flags(reg_rule
->flags
) | bw_flags
;
1115 chan
->max_antenna_gain
= chan
->orig_mag
=
1116 (int) MBI_TO_DBI(power_rule
->max_antenna_gain
);
1117 chan
->max_power
= chan
->orig_mpwr
=
1118 (int) MBM_TO_DBM(power_rule
->max_eirp
);
1122 chan
->flags
= flags
| bw_flags
| map_regdom_flags(reg_rule
->flags
);
1123 chan
->max_antenna_gain
= min(chan
->orig_mag
,
1124 (int) MBI_TO_DBI(power_rule
->max_antenna_gain
));
1125 if (chan
->orig_mpwr
)
1126 chan
->max_power
= min(chan
->orig_mpwr
,
1127 (int) MBM_TO_DBM(power_rule
->max_eirp
));
1129 chan
->max_power
= (int) MBM_TO_DBM(power_rule
->max_eirp
);
1132 static void handle_band(struct wiphy
*wiphy
, enum ieee80211_band band
)
1135 struct ieee80211_supported_band
*sband
;
1137 BUG_ON(!wiphy
->bands
[band
]);
1138 sband
= wiphy
->bands
[band
];
1140 for (i
= 0; i
< sband
->n_channels
; i
++)
1141 handle_channel(wiphy
, band
, i
);
1144 static bool ignore_reg_update(struct wiphy
*wiphy
,
1145 enum nl80211_reg_initiator initiator
)
1149 if (initiator
== NL80211_REGDOM_SET_BY_CORE
&&
1150 wiphy
->flags
& WIPHY_FLAG_CUSTOM_REGULATORY
)
1153 * wiphy->regd will be set once the device has its own
1154 * desired regulatory domain set
1156 if (wiphy
->flags
& WIPHY_FLAG_STRICT_REGULATORY
&& !wiphy
->regd
&&
1157 !is_world_regdom(last_request
->alpha2
))
1162 static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator
)
1164 struct cfg80211_registered_device
*rdev
;
1166 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
)
1167 wiphy_update_regulatory(&rdev
->wiphy
, initiator
);
1170 static void handle_reg_beacon(struct wiphy
*wiphy
,
1171 unsigned int chan_idx
,
1172 struct reg_beacon
*reg_beacon
)
1174 struct ieee80211_supported_band
*sband
;
1175 struct ieee80211_channel
*chan
;
1176 bool channel_changed
= false;
1177 struct ieee80211_channel chan_before
;
1179 assert_cfg80211_lock();
1181 sband
= wiphy
->bands
[reg_beacon
->chan
.band
];
1182 chan
= &sband
->channels
[chan_idx
];
1184 if (likely(chan
->center_freq
!= reg_beacon
->chan
.center_freq
))
1187 if (chan
->beacon_found
)
1190 chan
->beacon_found
= true;
1192 if (wiphy
->flags
& WIPHY_FLAG_DISABLE_BEACON_HINTS
)
1195 chan_before
.center_freq
= chan
->center_freq
;
1196 chan_before
.flags
= chan
->flags
;
1198 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) {
1199 chan
->flags
&= ~IEEE80211_CHAN_PASSIVE_SCAN
;
1200 channel_changed
= true;
1203 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
) {
1204 chan
->flags
&= ~IEEE80211_CHAN_NO_IBSS
;
1205 channel_changed
= true;
1208 if (channel_changed
)
1209 nl80211_send_beacon_hint_event(wiphy
, &chan_before
, chan
);
1213 * Called when a scan on a wiphy finds a beacon on
1216 static void wiphy_update_new_beacon(struct wiphy
*wiphy
,
1217 struct reg_beacon
*reg_beacon
)
1220 struct ieee80211_supported_band
*sband
;
1222 assert_cfg80211_lock();
1224 if (!wiphy
->bands
[reg_beacon
->chan
.band
])
1227 sband
= wiphy
->bands
[reg_beacon
->chan
.band
];
1229 for (i
= 0; i
< sband
->n_channels
; i
++)
1230 handle_reg_beacon(wiphy
, i
, reg_beacon
);
1234 * Called upon reg changes or a new wiphy is added
1236 static void wiphy_update_beacon_reg(struct wiphy
*wiphy
)
1239 struct ieee80211_supported_band
*sband
;
1240 struct reg_beacon
*reg_beacon
;
1242 assert_cfg80211_lock();
1244 if (list_empty(®_beacon_list
))
1247 list_for_each_entry(reg_beacon
, ®_beacon_list
, list
) {
1248 if (!wiphy
->bands
[reg_beacon
->chan
.band
])
1250 sband
= wiphy
->bands
[reg_beacon
->chan
.band
];
1251 for (i
= 0; i
< sband
->n_channels
; i
++)
1252 handle_reg_beacon(wiphy
, i
, reg_beacon
);
1256 static bool reg_is_world_roaming(struct wiphy
*wiphy
)
1258 if (is_world_regdom(cfg80211_regdomain
->alpha2
) ||
1259 (wiphy
->regd
&& is_world_regdom(wiphy
->regd
->alpha2
)))
1262 last_request
->initiator
!= NL80211_REGDOM_SET_BY_COUNTRY_IE
&&
1263 wiphy
->flags
& WIPHY_FLAG_CUSTOM_REGULATORY
)
1268 /* Reap the advantages of previously found beacons */
1269 static void reg_process_beacons(struct wiphy
*wiphy
)
1272 * Means we are just firing up cfg80211, so no beacons would
1273 * have been processed yet.
1277 if (!reg_is_world_roaming(wiphy
))
1279 wiphy_update_beacon_reg(wiphy
);
1282 static bool is_ht40_not_allowed(struct ieee80211_channel
*chan
)
1286 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
1288 /* This would happen when regulatory rules disallow HT40 completely */
1289 if (IEEE80211_CHAN_NO_HT40
== (chan
->flags
& (IEEE80211_CHAN_NO_HT40
)))
1294 static void reg_process_ht_flags_channel(struct wiphy
*wiphy
,
1295 enum ieee80211_band band
,
1296 unsigned int chan_idx
)
1298 struct ieee80211_supported_band
*sband
;
1299 struct ieee80211_channel
*channel
;
1300 struct ieee80211_channel
*channel_before
= NULL
, *channel_after
= NULL
;
1303 assert_cfg80211_lock();
1305 sband
= wiphy
->bands
[band
];
1306 BUG_ON(chan_idx
>= sband
->n_channels
);
1307 channel
= &sband
->channels
[chan_idx
];
1309 if (is_ht40_not_allowed(channel
)) {
1310 channel
->flags
|= IEEE80211_CHAN_NO_HT40
;
1315 * We need to ensure the extension channels exist to
1316 * be able to use HT40- or HT40+, this finds them (or not)
1318 for (i
= 0; i
< sband
->n_channels
; i
++) {
1319 struct ieee80211_channel
*c
= &sband
->channels
[i
];
1320 if (c
->center_freq
== (channel
->center_freq
- 20))
1322 if (c
->center_freq
== (channel
->center_freq
+ 20))
1327 * Please note that this assumes target bandwidth is 20 MHz,
1328 * if that ever changes we also need to change the below logic
1329 * to include that as well.
1331 if (is_ht40_not_allowed(channel_before
))
1332 channel
->flags
|= IEEE80211_CHAN_NO_HT40MINUS
;
1334 channel
->flags
&= ~IEEE80211_CHAN_NO_HT40MINUS
;
1336 if (is_ht40_not_allowed(channel_after
))
1337 channel
->flags
|= IEEE80211_CHAN_NO_HT40PLUS
;
1339 channel
->flags
&= ~IEEE80211_CHAN_NO_HT40PLUS
;
1342 static void reg_process_ht_flags_band(struct wiphy
*wiphy
,
1343 enum ieee80211_band band
)
1346 struct ieee80211_supported_band
*sband
;
1348 BUG_ON(!wiphy
->bands
[band
]);
1349 sband
= wiphy
->bands
[band
];
1351 for (i
= 0; i
< sband
->n_channels
; i
++)
1352 reg_process_ht_flags_channel(wiphy
, band
, i
);
1355 static void reg_process_ht_flags(struct wiphy
*wiphy
)
1357 enum ieee80211_band band
;
1362 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1363 if (wiphy
->bands
[band
])
1364 reg_process_ht_flags_band(wiphy
, band
);
1369 void wiphy_update_regulatory(struct wiphy
*wiphy
,
1370 enum nl80211_reg_initiator initiator
)
1372 enum ieee80211_band band
;
1374 if (ignore_reg_update(wiphy
, initiator
))
1376 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1377 if (wiphy
->bands
[band
])
1378 handle_band(wiphy
, band
);
1381 reg_process_beacons(wiphy
);
1382 reg_process_ht_flags(wiphy
);
1383 if (wiphy
->reg_notifier
)
1384 wiphy
->reg_notifier(wiphy
, last_request
);
1387 static void handle_channel_custom(struct wiphy
*wiphy
,
1388 enum ieee80211_band band
,
1389 unsigned int chan_idx
,
1390 const struct ieee80211_regdomain
*regd
)
1393 u32 desired_bw_khz
= MHZ_TO_KHZ(20);
1395 const struct ieee80211_reg_rule
*reg_rule
= NULL
;
1396 const struct ieee80211_power_rule
*power_rule
= NULL
;
1397 const struct ieee80211_freq_range
*freq_range
= NULL
;
1398 struct ieee80211_supported_band
*sband
;
1399 struct ieee80211_channel
*chan
;
1403 sband
= wiphy
->bands
[band
];
1404 BUG_ON(chan_idx
>= sband
->n_channels
);
1405 chan
= &sband
->channels
[chan_idx
];
1407 r
= freq_reg_info_regd(wiphy
,
1408 MHZ_TO_KHZ(chan
->center_freq
),
1414 chan
->flags
= IEEE80211_CHAN_DISABLED
;
1418 power_rule
= ®_rule
->power_rule
;
1419 freq_range
= ®_rule
->freq_range
;
1421 if (freq_range
->max_bandwidth_khz
< MHZ_TO_KHZ(40))
1422 bw_flags
= IEEE80211_CHAN_NO_HT40
;
1424 chan
->flags
|= map_regdom_flags(reg_rule
->flags
) | bw_flags
;
1425 chan
->max_antenna_gain
= (int) MBI_TO_DBI(power_rule
->max_antenna_gain
);
1426 chan
->max_power
= (int) MBM_TO_DBM(power_rule
->max_eirp
);
1429 static void handle_band_custom(struct wiphy
*wiphy
, enum ieee80211_band band
,
1430 const struct ieee80211_regdomain
*regd
)
1433 struct ieee80211_supported_band
*sband
;
1435 BUG_ON(!wiphy
->bands
[band
]);
1436 sband
= wiphy
->bands
[band
];
1438 for (i
= 0; i
< sband
->n_channels
; i
++)
1439 handle_channel_custom(wiphy
, band
, i
, regd
);
1442 /* Used by drivers prior to wiphy registration */
1443 void wiphy_apply_custom_regulatory(struct wiphy
*wiphy
,
1444 const struct ieee80211_regdomain
*regd
)
1446 enum ieee80211_band band
;
1447 unsigned int bands_set
= 0;
1449 mutex_lock(®_mutex
);
1450 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1451 if (!wiphy
->bands
[band
])
1453 handle_band_custom(wiphy
, band
, regd
);
1456 mutex_unlock(®_mutex
);
1459 * no point in calling this if it won't have any effect
1460 * on your device's supportd bands.
1462 WARN_ON(!bands_set
);
1464 EXPORT_SYMBOL(wiphy_apply_custom_regulatory
);
1467 * Return value which can be used by ignore_request() to indicate
1468 * it has been determined we should intersect two regulatory domains
1470 #define REG_INTERSECT 1
1472 /* This has the logic which determines when a new request
1473 * should be ignored. */
1474 static int ignore_request(struct wiphy
*wiphy
,
1475 struct regulatory_request
*pending_request
)
1477 struct wiphy
*last_wiphy
= NULL
;
1479 assert_cfg80211_lock();
1481 /* All initial requests are respected */
1485 switch (pending_request
->initiator
) {
1486 case NL80211_REGDOM_SET_BY_CORE
:
1488 case NL80211_REGDOM_SET_BY_COUNTRY_IE
:
1490 last_wiphy
= wiphy_idx_to_wiphy(last_request
->wiphy_idx
);
1492 if (unlikely(!is_an_alpha2(pending_request
->alpha2
)))
1494 if (last_request
->initiator
==
1495 NL80211_REGDOM_SET_BY_COUNTRY_IE
) {
1496 if (last_wiphy
!= wiphy
) {
1498 * Two cards with two APs claiming different
1499 * Country IE alpha2s. We could
1500 * intersect them, but that seems unlikely
1501 * to be correct. Reject second one for now.
1503 if (regdom_changes(pending_request
->alpha2
))
1508 * Two consecutive Country IE hints on the same wiphy.
1509 * This should be picked up early by the driver/stack
1511 if (WARN_ON(regdom_changes(pending_request
->alpha2
)))
1515 return REG_INTERSECT
;
1516 case NL80211_REGDOM_SET_BY_DRIVER
:
1517 if (last_request
->initiator
== NL80211_REGDOM_SET_BY_CORE
) {
1518 if (is_old_static_regdom(cfg80211_regdomain
))
1520 if (regdom_changes(pending_request
->alpha2
))
1526 * This would happen if you unplug and plug your card
1527 * back in or if you add a new device for which the previously
1528 * loaded card also agrees on the regulatory domain.
1530 if (last_request
->initiator
== NL80211_REGDOM_SET_BY_DRIVER
&&
1531 !regdom_changes(pending_request
->alpha2
))
1534 return REG_INTERSECT
;
1535 case NL80211_REGDOM_SET_BY_USER
:
1536 if (last_request
->initiator
== NL80211_REGDOM_SET_BY_COUNTRY_IE
)
1537 return REG_INTERSECT
;
1539 * If the user knows better the user should set the regdom
1540 * to their country before the IE is picked up
1542 if (last_request
->initiator
== NL80211_REGDOM_SET_BY_USER
&&
1543 last_request
->intersect
)
1546 * Process user requests only after previous user/driver/core
1547 * requests have been processed
1549 if (last_request
->initiator
== NL80211_REGDOM_SET_BY_CORE
||
1550 last_request
->initiator
== NL80211_REGDOM_SET_BY_DRIVER
||
1551 last_request
->initiator
== NL80211_REGDOM_SET_BY_USER
) {
1552 if (regdom_changes(last_request
->alpha2
))
1556 if (!is_old_static_regdom(cfg80211_regdomain
) &&
1557 !regdom_changes(pending_request
->alpha2
))
1567 * __regulatory_hint - hint to the wireless core a regulatory domain
1568 * @wiphy: if the hint comes from country information from an AP, this
1569 * is required to be set to the wiphy that received the information
1570 * @pending_request: the regulatory request currently being processed
1572 * The Wireless subsystem can use this function to hint to the wireless core
1573 * what it believes should be the current regulatory domain.
1575 * Returns zero if all went fine, %-EALREADY if a regulatory domain had
1576 * already been set or other standard error codes.
1578 * Caller must hold &cfg80211_mutex and ®_mutex
1580 static int __regulatory_hint(struct wiphy
*wiphy
,
1581 struct regulatory_request
*pending_request
)
1583 bool intersect
= false;
1586 assert_cfg80211_lock();
1588 r
= ignore_request(wiphy
, pending_request
);
1590 if (r
== REG_INTERSECT
) {
1591 if (pending_request
->initiator
==
1592 NL80211_REGDOM_SET_BY_DRIVER
) {
1593 r
= reg_copy_regd(&wiphy
->regd
, cfg80211_regdomain
);
1595 kfree(pending_request
);
1602 * If the regulatory domain being requested by the
1603 * driver has already been set just copy it to the
1606 if (r
== -EALREADY
&&
1607 pending_request
->initiator
==
1608 NL80211_REGDOM_SET_BY_DRIVER
) {
1609 r
= reg_copy_regd(&wiphy
->regd
, cfg80211_regdomain
);
1611 kfree(pending_request
);
1617 kfree(pending_request
);
1622 kfree(last_request
);
1624 last_request
= pending_request
;
1625 last_request
->intersect
= intersect
;
1627 pending_request
= NULL
;
1629 /* When r == REG_INTERSECT we do need to call CRDA */
1632 * Since CRDA will not be called in this case as we already
1633 * have applied the requested regulatory domain before we just
1634 * inform userspace we have processed the request
1637 nl80211_send_reg_change_event(last_request
);
1641 return call_crda(last_request
->alpha2
);
1644 /* This processes *all* regulatory hints */
1645 static void reg_process_hint(struct regulatory_request
*reg_request
)
1648 struct wiphy
*wiphy
= NULL
;
1650 BUG_ON(!reg_request
->alpha2
);
1652 mutex_lock(&cfg80211_mutex
);
1653 mutex_lock(®_mutex
);
1655 if (wiphy_idx_valid(reg_request
->wiphy_idx
))
1656 wiphy
= wiphy_idx_to_wiphy(reg_request
->wiphy_idx
);
1658 if (reg_request
->initiator
== NL80211_REGDOM_SET_BY_DRIVER
&&
1664 r
= __regulatory_hint(wiphy
, reg_request
);
1665 /* This is required so that the orig_* parameters are saved */
1666 if (r
== -EALREADY
&& wiphy
&&
1667 wiphy
->flags
& WIPHY_FLAG_STRICT_REGULATORY
)
1668 wiphy_update_regulatory(wiphy
, reg_request
->initiator
);
1670 mutex_unlock(®_mutex
);
1671 mutex_unlock(&cfg80211_mutex
);
1674 /* Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_* */
1675 static void reg_process_pending_hints(void)
1677 struct regulatory_request
*reg_request
;
1679 spin_lock(®_requests_lock
);
1680 while (!list_empty(®_requests_list
)) {
1681 reg_request
= list_first_entry(®_requests_list
,
1682 struct regulatory_request
,
1684 list_del_init(®_request
->list
);
1686 spin_unlock(®_requests_lock
);
1687 reg_process_hint(reg_request
);
1688 spin_lock(®_requests_lock
);
1690 spin_unlock(®_requests_lock
);
1693 /* Processes beacon hints -- this has nothing to do with country IEs */
1694 static void reg_process_pending_beacon_hints(void)
1696 struct cfg80211_registered_device
*rdev
;
1697 struct reg_beacon
*pending_beacon
, *tmp
;
1700 * No need to hold the reg_mutex here as we just touch wiphys
1701 * and do not read or access regulatory variables.
1703 mutex_lock(&cfg80211_mutex
);
1705 /* This goes through the _pending_ beacon list */
1706 spin_lock_bh(®_pending_beacons_lock
);
1708 if (list_empty(®_pending_beacons
)) {
1709 spin_unlock_bh(®_pending_beacons_lock
);
1713 list_for_each_entry_safe(pending_beacon
, tmp
,
1714 ®_pending_beacons
, list
) {
1716 list_del_init(&pending_beacon
->list
);
1718 /* Applies the beacon hint to current wiphys */
1719 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
)
1720 wiphy_update_new_beacon(&rdev
->wiphy
, pending_beacon
);
1722 /* Remembers the beacon hint for new wiphys or reg changes */
1723 list_add_tail(&pending_beacon
->list
, ®_beacon_list
);
1726 spin_unlock_bh(®_pending_beacons_lock
);
1728 mutex_unlock(&cfg80211_mutex
);
1731 static void reg_todo(struct work_struct
*work
)
1733 reg_process_pending_hints();
1734 reg_process_pending_beacon_hints();
1737 static DECLARE_WORK(reg_work
, reg_todo
);
1739 static void queue_regulatory_request(struct regulatory_request
*request
)
1741 spin_lock(®_requests_lock
);
1742 list_add_tail(&request
->list
, ®_requests_list
);
1743 spin_unlock(®_requests_lock
);
1745 schedule_work(®_work
);
1748 /* Core regulatory hint -- happens once during cfg80211_init() */
1749 static int regulatory_hint_core(const char *alpha2
)
1751 struct regulatory_request
*request
;
1753 BUG_ON(last_request
);
1755 request
= kzalloc(sizeof(struct regulatory_request
),
1760 request
->alpha2
[0] = alpha2
[0];
1761 request
->alpha2
[1] = alpha2
[1];
1762 request
->initiator
= NL80211_REGDOM_SET_BY_CORE
;
1764 queue_regulatory_request(request
);
1767 * This ensures last_request is populated once modules
1768 * come swinging in and calling regulatory hints and
1769 * wiphy_apply_custom_regulatory().
1771 flush_scheduled_work();
1777 int regulatory_hint_user(const char *alpha2
)
1779 struct regulatory_request
*request
;
1783 request
= kzalloc(sizeof(struct regulatory_request
), GFP_KERNEL
);
1787 request
->wiphy_idx
= WIPHY_IDX_STALE
;
1788 request
->alpha2
[0] = alpha2
[0];
1789 request
->alpha2
[1] = alpha2
[1];
1790 request
->initiator
= NL80211_REGDOM_SET_BY_USER
,
1792 queue_regulatory_request(request
);
1798 int regulatory_hint(struct wiphy
*wiphy
, const char *alpha2
)
1800 struct regulatory_request
*request
;
1805 request
= kzalloc(sizeof(struct regulatory_request
), GFP_KERNEL
);
1809 request
->wiphy_idx
= get_wiphy_idx(wiphy
);
1811 /* Must have registered wiphy first */
1812 BUG_ON(!wiphy_idx_valid(request
->wiphy_idx
));
1814 request
->alpha2
[0] = alpha2
[0];
1815 request
->alpha2
[1] = alpha2
[1];
1816 request
->initiator
= NL80211_REGDOM_SET_BY_DRIVER
;
1818 queue_regulatory_request(request
);
1822 EXPORT_SYMBOL(regulatory_hint
);
1824 /* Caller must hold reg_mutex */
1825 static bool reg_same_country_ie_hint(struct wiphy
*wiphy
,
1826 u32 country_ie_checksum
)
1828 struct wiphy
*request_wiphy
;
1832 if (unlikely(last_request
->initiator
!=
1833 NL80211_REGDOM_SET_BY_COUNTRY_IE
))
1836 request_wiphy
= wiphy_idx_to_wiphy(last_request
->wiphy_idx
);
1841 if (likely(request_wiphy
!= wiphy
))
1842 return !country_ie_integrity_changes(country_ie_checksum
);
1844 * We should not have let these through at this point, they
1845 * should have been picked up earlier by the first alpha2 check
1848 if (WARN_ON(!country_ie_integrity_changes(country_ie_checksum
)))
1854 * We hold wdev_lock() here so we cannot hold cfg80211_mutex() and
1855 * therefore cannot iterate over the rdev list here.
1857 void regulatory_hint_11d(struct wiphy
*wiphy
,
1861 struct ieee80211_regdomain
*rd
= NULL
;
1864 enum environment_cap env
= ENVIRON_ANY
;
1865 struct regulatory_request
*request
;
1867 mutex_lock(®_mutex
);
1869 if (unlikely(!last_request
))
1872 /* IE len must be evenly divisible by 2 */
1873 if (country_ie_len
& 0x01)
1876 if (country_ie_len
< IEEE80211_COUNTRY_IE_MIN_LEN
)
1880 * Pending country IE processing, this can happen after we
1881 * call CRDA and wait for a response if a beacon was received before
1882 * we were able to process the last regulatory_hint_11d() call
1884 if (country_ie_regdomain
)
1887 alpha2
[0] = country_ie
[0];
1888 alpha2
[1] = country_ie
[1];
1890 if (country_ie
[2] == 'I')
1891 env
= ENVIRON_INDOOR
;
1892 else if (country_ie
[2] == 'O')
1893 env
= ENVIRON_OUTDOOR
;
1896 * We will run this only upon a successful connection on cfg80211.
1897 * We leave conflict resolution to the workqueue, where can hold
1900 if (likely(last_request
->initiator
==
1901 NL80211_REGDOM_SET_BY_COUNTRY_IE
&&
1902 wiphy_idx_valid(last_request
->wiphy_idx
)))
1905 rd
= country_ie_2_rd(country_ie
, country_ie_len
, &checksum
);
1910 * This will not happen right now but we leave it here for the
1911 * the future when we want to add suspend/resume support and having
1912 * the user move to another country after doing so, or having the user
1913 * move to another AP. Right now we just trust the first AP.
1915 * If we hit this before we add this support we want to be informed of
1916 * it as it would indicate a mistake in the current design
1918 if (WARN_ON(reg_same_country_ie_hint(wiphy
, checksum
)))
1921 request
= kzalloc(sizeof(struct regulatory_request
), GFP_KERNEL
);
1926 * We keep this around for when CRDA comes back with a response so
1927 * we can intersect with that
1929 country_ie_regdomain
= rd
;
1931 request
->wiphy_idx
= get_wiphy_idx(wiphy
);
1932 request
->alpha2
[0] = rd
->alpha2
[0];
1933 request
->alpha2
[1] = rd
->alpha2
[1];
1934 request
->initiator
= NL80211_REGDOM_SET_BY_COUNTRY_IE
;
1935 request
->country_ie_checksum
= checksum
;
1936 request
->country_ie_env
= env
;
1938 mutex_unlock(®_mutex
);
1940 queue_regulatory_request(request
);
1947 mutex_unlock(®_mutex
);
1950 static bool freq_is_chan_12_13_14(u16 freq
)
1952 if (freq
== ieee80211_channel_to_frequency(12) ||
1953 freq
== ieee80211_channel_to_frequency(13) ||
1954 freq
== ieee80211_channel_to_frequency(14))
1959 int regulatory_hint_found_beacon(struct wiphy
*wiphy
,
1960 struct ieee80211_channel
*beacon_chan
,
1963 struct reg_beacon
*reg_beacon
;
1965 if (likely((beacon_chan
->beacon_found
||
1966 (beacon_chan
->flags
& IEEE80211_CHAN_RADAR
) ||
1967 (beacon_chan
->band
== IEEE80211_BAND_2GHZ
&&
1968 !freq_is_chan_12_13_14(beacon_chan
->center_freq
)))))
1971 reg_beacon
= kzalloc(sizeof(struct reg_beacon
), gfp
);
1975 #ifdef CONFIG_CFG80211_REG_DEBUG
1976 printk(KERN_DEBUG
"cfg80211: Found new beacon on "
1977 "frequency: %d MHz (Ch %d) on %s\n",
1978 beacon_chan
->center_freq
,
1979 ieee80211_frequency_to_channel(beacon_chan
->center_freq
),
1982 memcpy(®_beacon
->chan
, beacon_chan
,
1983 sizeof(struct ieee80211_channel
));
1987 * Since we can be called from BH or and non-BH context
1988 * we must use spin_lock_bh()
1990 spin_lock_bh(®_pending_beacons_lock
);
1991 list_add_tail(®_beacon
->list
, ®_pending_beacons
);
1992 spin_unlock_bh(®_pending_beacons_lock
);
1994 schedule_work(®_work
);
1999 static void print_rd_rules(const struct ieee80211_regdomain
*rd
)
2002 const struct ieee80211_reg_rule
*reg_rule
= NULL
;
2003 const struct ieee80211_freq_range
*freq_range
= NULL
;
2004 const struct ieee80211_power_rule
*power_rule
= NULL
;
2006 printk(KERN_INFO
" (start_freq - end_freq @ bandwidth), "
2007 "(max_antenna_gain, max_eirp)\n");
2009 for (i
= 0; i
< rd
->n_reg_rules
; i
++) {
2010 reg_rule
= &rd
->reg_rules
[i
];
2011 freq_range
= ®_rule
->freq_range
;
2012 power_rule
= ®_rule
->power_rule
;
2015 * There may not be documentation for max antenna gain
2016 * in certain regions
2018 if (power_rule
->max_antenna_gain
)
2019 printk(KERN_INFO
" (%d KHz - %d KHz @ %d KHz), "
2020 "(%d mBi, %d mBm)\n",
2021 freq_range
->start_freq_khz
,
2022 freq_range
->end_freq_khz
,
2023 freq_range
->max_bandwidth_khz
,
2024 power_rule
->max_antenna_gain
,
2025 power_rule
->max_eirp
);
2027 printk(KERN_INFO
" (%d KHz - %d KHz @ %d KHz), "
2029 freq_range
->start_freq_khz
,
2030 freq_range
->end_freq_khz
,
2031 freq_range
->max_bandwidth_khz
,
2032 power_rule
->max_eirp
);
2036 static void print_regdomain(const struct ieee80211_regdomain
*rd
)
2039 if (is_intersected_alpha2(rd
->alpha2
)) {
2041 if (last_request
->initiator
==
2042 NL80211_REGDOM_SET_BY_COUNTRY_IE
) {
2043 struct cfg80211_registered_device
*rdev
;
2044 rdev
= cfg80211_rdev_by_wiphy_idx(
2045 last_request
->wiphy_idx
);
2047 printk(KERN_INFO
"cfg80211: Current regulatory "
2048 "domain updated by AP to: %c%c\n",
2049 rdev
->country_ie_alpha2
[0],
2050 rdev
->country_ie_alpha2
[1]);
2052 printk(KERN_INFO
"cfg80211: Current regulatory "
2053 "domain intersected: \n");
2055 printk(KERN_INFO
"cfg80211: Current regulatory "
2056 "domain intersected: \n");
2057 } else if (is_world_regdom(rd
->alpha2
))
2058 printk(KERN_INFO
"cfg80211: World regulatory "
2059 "domain updated:\n");
2061 if (is_unknown_alpha2(rd
->alpha2
))
2062 printk(KERN_INFO
"cfg80211: Regulatory domain "
2063 "changed to driver built-in settings "
2064 "(unknown country)\n");
2066 printk(KERN_INFO
"cfg80211: Regulatory domain "
2067 "changed to country: %c%c\n",
2068 rd
->alpha2
[0], rd
->alpha2
[1]);
2073 static void print_regdomain_info(const struct ieee80211_regdomain
*rd
)
2075 printk(KERN_INFO
"cfg80211: Regulatory domain: %c%c\n",
2076 rd
->alpha2
[0], rd
->alpha2
[1]);
2080 #ifdef CONFIG_CFG80211_REG_DEBUG
2081 static void reg_country_ie_process_debug(
2082 const struct ieee80211_regdomain
*rd
,
2083 const struct ieee80211_regdomain
*country_ie_regdomain
,
2084 const struct ieee80211_regdomain
*intersected_rd
)
2086 printk(KERN_DEBUG
"cfg80211: Received country IE:\n");
2087 print_regdomain_info(country_ie_regdomain
);
2088 printk(KERN_DEBUG
"cfg80211: CRDA thinks this should applied:\n");
2089 print_regdomain_info(rd
);
2090 if (intersected_rd
) {
2091 printk(KERN_DEBUG
"cfg80211: We intersect both of these "
2093 print_regdomain_info(intersected_rd
);
2096 printk(KERN_DEBUG
"cfg80211: Intersection between both failed\n");
2099 static inline void reg_country_ie_process_debug(
2100 const struct ieee80211_regdomain
*rd
,
2101 const struct ieee80211_regdomain
*country_ie_regdomain
,
2102 const struct ieee80211_regdomain
*intersected_rd
)
2107 /* Takes ownership of rd only if it doesn't fail */
2108 static int __set_regdom(const struct ieee80211_regdomain
*rd
)
2110 const struct ieee80211_regdomain
*intersected_rd
= NULL
;
2111 struct cfg80211_registered_device
*rdev
= NULL
;
2112 struct wiphy
*request_wiphy
;
2113 /* Some basic sanity checks first */
2115 if (is_world_regdom(rd
->alpha2
)) {
2116 if (WARN_ON(!reg_is_valid_request(rd
->alpha2
)))
2118 update_world_regdomain(rd
);
2122 if (!is_alpha2_set(rd
->alpha2
) && !is_an_alpha2(rd
->alpha2
) &&
2123 !is_unknown_alpha2(rd
->alpha2
))
2130 * Lets only bother proceeding on the same alpha2 if the current
2131 * rd is non static (it means CRDA was present and was used last)
2132 * and the pending request came in from a country IE
2134 if (last_request
->initiator
!= NL80211_REGDOM_SET_BY_COUNTRY_IE
) {
2136 * If someone else asked us to change the rd lets only bother
2137 * checking if the alpha2 changes if CRDA was already called
2139 if (!is_old_static_regdom(cfg80211_regdomain
) &&
2140 !regdom_changes(rd
->alpha2
))
2145 * Now lets set the regulatory domain, update all driver channels
2146 * and finally inform them of what we have done, in case they want
2147 * to review or adjust their own settings based on their own
2148 * internal EEPROM data
2151 if (WARN_ON(!reg_is_valid_request(rd
->alpha2
)))
2154 if (!is_valid_rd(rd
)) {
2155 printk(KERN_ERR
"cfg80211: Invalid "
2156 "regulatory domain detected:\n");
2157 print_regdomain_info(rd
);
2161 request_wiphy
= wiphy_idx_to_wiphy(last_request
->wiphy_idx
);
2163 if (!last_request
->intersect
) {
2166 if (last_request
->initiator
!= NL80211_REGDOM_SET_BY_DRIVER
) {
2168 cfg80211_regdomain
= rd
;
2173 * For a driver hint, lets copy the regulatory domain the
2174 * driver wanted to the wiphy to deal with conflicts
2178 * Userspace could have sent two replies with only
2179 * one kernel request.
2181 if (request_wiphy
->regd
)
2184 r
= reg_copy_regd(&request_wiphy
->regd
, rd
);
2189 cfg80211_regdomain
= rd
;
2193 /* Intersection requires a bit more work */
2195 if (last_request
->initiator
!= NL80211_REGDOM_SET_BY_COUNTRY_IE
) {
2197 intersected_rd
= regdom_intersect(rd
, cfg80211_regdomain
);
2198 if (!intersected_rd
)
2202 * We can trash what CRDA provided now.
2203 * However if a driver requested this specific regulatory
2204 * domain we keep it for its private use
2206 if (last_request
->initiator
== NL80211_REGDOM_SET_BY_DRIVER
)
2207 request_wiphy
->regd
= rd
;
2214 cfg80211_regdomain
= intersected_rd
;
2220 * Country IE requests are handled a bit differently, we intersect
2221 * the country IE rd with what CRDA believes that country should have
2225 * Userspace could have sent two replies with only
2226 * one kernel request. By the second reply we would have
2227 * already processed and consumed the country_ie_regdomain.
2229 if (!country_ie_regdomain
)
2231 BUG_ON(rd
== country_ie_regdomain
);
2234 * Intersect what CRDA returned and our what we
2235 * had built from the Country IE received
2238 intersected_rd
= regdom_intersect(rd
, country_ie_regdomain
);
2240 reg_country_ie_process_debug(rd
,
2241 country_ie_regdomain
,
2244 kfree(country_ie_regdomain
);
2245 country_ie_regdomain
= NULL
;
2247 if (!intersected_rd
)
2250 rdev
= wiphy_to_dev(request_wiphy
);
2252 rdev
->country_ie_alpha2
[0] = rd
->alpha2
[0];
2253 rdev
->country_ie_alpha2
[1] = rd
->alpha2
[1];
2254 rdev
->env
= last_request
->country_ie_env
;
2256 BUG_ON(intersected_rd
== rd
);
2262 cfg80211_regdomain
= intersected_rd
;
2269 * Use this call to set the current regulatory domain. Conflicts with
2270 * multiple drivers can be ironed out later. Caller must've already
2271 * kmalloc'd the rd structure. Caller must hold cfg80211_mutex
2273 int set_regdom(const struct ieee80211_regdomain
*rd
)
2277 assert_cfg80211_lock();
2279 mutex_lock(®_mutex
);
2281 /* Note that this doesn't update the wiphys, this is done below */
2282 r
= __set_regdom(rd
);
2285 mutex_unlock(®_mutex
);
2289 /* This would make this whole thing pointless */
2290 if (!last_request
->intersect
)
2291 BUG_ON(rd
!= cfg80211_regdomain
);
2293 /* update all wiphys now with the new established regulatory domain */
2294 update_all_wiphy_regulatory(last_request
->initiator
);
2296 print_regdomain(cfg80211_regdomain
);
2298 nl80211_send_reg_change_event(last_request
);
2300 mutex_unlock(®_mutex
);
2305 /* Caller must hold cfg80211_mutex */
2306 void reg_device_remove(struct wiphy
*wiphy
)
2308 struct wiphy
*request_wiphy
= NULL
;
2310 assert_cfg80211_lock();
2312 mutex_lock(®_mutex
);
2317 request_wiphy
= wiphy_idx_to_wiphy(last_request
->wiphy_idx
);
2319 if (!request_wiphy
|| request_wiphy
!= wiphy
)
2322 last_request
->wiphy_idx
= WIPHY_IDX_STALE
;
2323 last_request
->country_ie_env
= ENVIRON_ANY
;
2325 mutex_unlock(®_mutex
);
2328 int regulatory_init(void)
2332 reg_pdev
= platform_device_register_simple("regulatory", 0, NULL
, 0);
2333 if (IS_ERR(reg_pdev
))
2334 return PTR_ERR(reg_pdev
);
2336 spin_lock_init(®_requests_lock
);
2337 spin_lock_init(®_pending_beacons_lock
);
2339 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2340 cfg80211_regdomain
= static_regdom(ieee80211_regdom
);
2342 printk(KERN_INFO
"cfg80211: Using static regulatory domain info\n");
2343 print_regdomain_info(cfg80211_regdomain
);
2345 cfg80211_regdomain
= cfg80211_world_regdom
;
2348 /* We always try to get an update for the static regdomain */
2349 err
= regulatory_hint_core(cfg80211_regdomain
->alpha2
);
2354 * N.B. kobject_uevent_env() can fail mainly for when we're out
2355 * memory which is handled and propagated appropriately above
2356 * but it can also fail during a netlink_broadcast() or during
2357 * early boot for call_usermodehelper(). For now treat these
2358 * errors as non-fatal.
2360 printk(KERN_ERR
"cfg80211: kobject_uevent_env() was unable "
2361 "to call CRDA during init");
2362 #ifdef CONFIG_CFG80211_REG_DEBUG
2363 /* We want to find out exactly why when debugging */
2369 * Finally, if the user set the module parameter treat it
2372 if (!is_world_regdom(ieee80211_regdom
))
2373 regulatory_hint_user(ieee80211_regdom
);
2378 void regulatory_exit(void)
2380 struct regulatory_request
*reg_request
, *tmp
;
2381 struct reg_beacon
*reg_beacon
, *btmp
;
2383 cancel_work_sync(®_work
);
2385 mutex_lock(&cfg80211_mutex
);
2386 mutex_lock(®_mutex
);
2390 kfree(country_ie_regdomain
);
2391 country_ie_regdomain
= NULL
;
2393 kfree(last_request
);
2395 platform_device_unregister(reg_pdev
);
2397 spin_lock_bh(®_pending_beacons_lock
);
2398 if (!list_empty(®_pending_beacons
)) {
2399 list_for_each_entry_safe(reg_beacon
, btmp
,
2400 ®_pending_beacons
, list
) {
2401 list_del(®_beacon
->list
);
2405 spin_unlock_bh(®_pending_beacons_lock
);
2407 if (!list_empty(®_beacon_list
)) {
2408 list_for_each_entry_safe(reg_beacon
, btmp
,
2409 ®_beacon_list
, list
) {
2410 list_del(®_beacon
->list
);
2415 spin_lock(®_requests_lock
);
2416 if (!list_empty(®_requests_list
)) {
2417 list_for_each_entry_safe(reg_request
, tmp
,
2418 ®_requests_list
, list
) {
2419 list_del(®_request
->list
);
2423 spin_unlock(®_requests_lock
);
2425 mutex_unlock(®_mutex
);
2426 mutex_unlock(&cfg80211_mutex
);