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/wireless.h>
41 #include <net/cfg80211.h>
45 /* wiphy is set if this request's initiator is REGDOM_SET_BY_DRIVER */
46 struct regulatory_request
{
47 struct list_head list
;
50 enum reg_set_by initiator
;
54 static LIST_HEAD(regulatory_requests
);
55 DEFINE_MUTEX(cfg80211_reg_mutex
);
57 /* To trigger userspace events */
58 static struct platform_device
*reg_pdev
;
60 /* Keep the ordering from large to small */
61 static u32 supported_bandwidths
[] = {
66 static struct list_head regulatory_requests
;
68 /* Central wireless core regulatory domains, we only need two,
69 * the current one and a world regulatory domain in case we have no
70 * information to give us an alpha2 */
71 static struct ieee80211_regdomain
*cfg80211_regdomain
;
73 /* We keep a static world regulatory domain in case of the absence of CRDA */
74 static const struct ieee80211_regdomain world_regdom
= {
78 REG_RULE(2412-10, 2462+10, 40, 6, 20,
79 NL80211_RRF_PASSIVE_SCAN
|
84 static struct ieee80211_regdomain
*cfg80211_world_regdom
=
85 (struct ieee80211_regdomain
*) &world_regdom
;
87 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
88 static char *ieee80211_regdom
= "US";
89 module_param(ieee80211_regdom
, charp
, 0444);
90 MODULE_PARM_DESC(ieee80211_regdom
, "IEEE 802.11 regulatory domain code");
92 /* We assume 40 MHz bandwidth for the old regulatory work.
93 * We make emphasis we are using the exact same frequencies
96 static const struct ieee80211_regdomain us_regdom
= {
100 /* IEEE 802.11b/g, channels 1..11 */
101 REG_RULE(2412-10, 2462+10, 40, 6, 27, 0),
102 /* IEEE 802.11a, channel 36 */
103 REG_RULE(5180-10, 5180+10, 40, 6, 23, 0),
104 /* IEEE 802.11a, channel 40 */
105 REG_RULE(5200-10, 5200+10, 40, 6, 23, 0),
106 /* IEEE 802.11a, channel 44 */
107 REG_RULE(5220-10, 5220+10, 40, 6, 23, 0),
108 /* IEEE 802.11a, channels 48..64 */
109 REG_RULE(5240-10, 5320+10, 40, 6, 23, 0),
110 /* IEEE 802.11a, channels 149..165, outdoor */
111 REG_RULE(5745-10, 5825+10, 40, 6, 30, 0),
115 static const struct ieee80211_regdomain jp_regdom
= {
119 /* IEEE 802.11b/g, channels 1..14 */
120 REG_RULE(2412-10, 2484+10, 40, 6, 20, 0),
121 /* IEEE 802.11a, channels 34..48 */
122 REG_RULE(5170-10, 5240+10, 40, 6, 20,
123 NL80211_RRF_PASSIVE_SCAN
),
124 /* IEEE 802.11a, channels 52..64 */
125 REG_RULE(5260-10, 5320+10, 40, 6, 20,
126 NL80211_RRF_NO_IBSS
|
131 static const struct ieee80211_regdomain eu_regdom
= {
133 /* This alpha2 is bogus, we leave it here just for stupid
134 * backward compatibility */
137 /* IEEE 802.11b/g, channels 1..13 */
138 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
139 /* IEEE 802.11a, channel 36 */
140 REG_RULE(5180-10, 5180+10, 40, 6, 23,
141 NL80211_RRF_PASSIVE_SCAN
),
142 /* IEEE 802.11a, channel 40 */
143 REG_RULE(5200-10, 5200+10, 40, 6, 23,
144 NL80211_RRF_PASSIVE_SCAN
),
145 /* IEEE 802.11a, channel 44 */
146 REG_RULE(5220-10, 5220+10, 40, 6, 23,
147 NL80211_RRF_PASSIVE_SCAN
),
148 /* IEEE 802.11a, channels 48..64 */
149 REG_RULE(5240-10, 5320+10, 40, 6, 20,
150 NL80211_RRF_NO_IBSS
|
152 /* IEEE 802.11a, channels 100..140 */
153 REG_RULE(5500-10, 5700+10, 40, 6, 30,
154 NL80211_RRF_NO_IBSS
|
159 static const struct ieee80211_regdomain
*static_regdom(char *alpha2
)
161 if (alpha2
[0] == 'U' && alpha2
[1] == 'S')
163 if (alpha2
[0] == 'J' && alpha2
[1] == 'P')
165 if (alpha2
[0] == 'E' && alpha2
[1] == 'U')
167 /* Default, as per the old rules */
171 static bool is_old_static_regdom(struct ieee80211_regdomain
*rd
)
173 if (rd
== &us_regdom
|| rd
== &jp_regdom
|| rd
== &eu_regdom
)
178 /* The old crap never deals with a world regulatory domain, it only
179 * deals with the static regulatory domain passed and if possible
180 * an updated "US" or "JP" regulatory domain. We do however store the
181 * old static regulatory domain in cfg80211_world_regdom for convenience
183 static void reset_regdomains_static(void)
185 if (!is_old_static_regdom(cfg80211_regdomain
))
186 kfree(cfg80211_regdomain
);
187 /* This is setting the regdom to the old static regdom */
189 (struct ieee80211_regdomain
*) cfg80211_world_regdom
;
192 static void reset_regdomains(void)
194 if (cfg80211_world_regdom
&& cfg80211_world_regdom
!= &world_regdom
) {
195 if (cfg80211_world_regdom
== cfg80211_regdomain
) {
196 kfree(cfg80211_regdomain
);
198 kfree(cfg80211_world_regdom
);
199 kfree(cfg80211_regdomain
);
201 } else if (cfg80211_regdomain
&& cfg80211_regdomain
!= &world_regdom
)
202 kfree(cfg80211_regdomain
);
204 cfg80211_world_regdom
= (struct ieee80211_regdomain
*) &world_regdom
;
205 cfg80211_regdomain
= NULL
;
208 /* Dynamic world regulatory domain requested by the wireless
209 * core upon initialization */
210 static void update_world_regdomain(struct ieee80211_regdomain
*rd
)
212 BUG_ON(list_empty(®ulatory_requests
));
216 cfg80211_world_regdom
= rd
;
217 cfg80211_regdomain
= rd
;
221 bool is_world_regdom(char *alpha2
)
225 if (alpha2
[0] == '0' && alpha2
[1] == '0')
230 static bool is_alpha2_set(char *alpha2
)
234 if (alpha2
[0] != 0 && alpha2
[1] != 0)
239 static bool is_alpha_upper(char letter
)
242 if (letter
>= 65 && letter
<= 90)
247 static bool is_unknown_alpha2(char *alpha2
)
251 /* Special case where regulatory domain was built by driver
252 * but a specific alpha2 cannot be determined */
253 if (alpha2
[0] == '9' && alpha2
[1] == '9')
258 static bool is_an_alpha2(char *alpha2
)
262 if (is_alpha_upper(alpha2
[0]) && is_alpha_upper(alpha2
[1]))
267 static bool alpha2_equal(char *alpha2_x
, char *alpha2_y
)
269 if (!alpha2_x
|| !alpha2_y
)
271 if (alpha2_x
[0] == alpha2_y
[0] &&
272 alpha2_x
[1] == alpha2_y
[1])
277 static bool regdom_changed(char *alpha2
)
279 if (!cfg80211_regdomain
)
281 if (alpha2_equal(cfg80211_regdomain
->alpha2
, alpha2
))
286 /* This lets us keep regulatory code which is updated on a regulatory
287 * basis in userspace. */
288 static int call_crda(const char *alpha2
)
290 char country_env
[9 + 2] = "COUNTRY=";
296 if (!is_world_regdom((char *) alpha2
))
297 printk(KERN_INFO
"cfg80211: Calling CRDA for country: %c%c\n",
298 alpha2
[0], alpha2
[1]);
300 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
303 printk(KERN_INFO
"cfg80211: Calling CRDA to update world "
304 "regulatory domain\n");
307 country_env
[8] = alpha2
[0];
308 country_env
[9] = alpha2
[1];
310 return kobject_uevent_env(®_pdev
->dev
.kobj
, KOBJ_CHANGE
, envp
);
313 /* This has the logic which determines when a new request
314 * should be ignored. */
315 static int ignore_request(struct wiphy
*wiphy
, enum reg_set_by set_by
,
316 char *alpha2
, struct ieee80211_regdomain
*rd
)
318 struct regulatory_request
*last_request
= NULL
;
320 /* All initial requests are respected */
321 if (list_empty(®ulatory_requests
))
324 last_request
= list_first_entry(®ulatory_requests
,
325 struct regulatory_request
, list
);
328 case REGDOM_SET_BY_INIT
:
330 case REGDOM_SET_BY_CORE
:
331 /* Always respect new wireless core hints, should only
332 * come in for updating the world regulatory domain at init
335 case REGDOM_SET_BY_COUNTRY_IE
:
336 if (last_request
->initiator
== set_by
) {
337 if (last_request
->wiphy
!= wiphy
) {
338 /* Two cards with two APs claiming different
339 * different Country IE alpha2s!
340 * You're special!! */
341 if (!alpha2_equal(last_request
->alpha2
,
342 cfg80211_regdomain
->alpha2
)) {
343 /* XXX: Deal with conflict, consider
344 * building a new one out of the
351 /* Two consecutive Country IE hints on the same wiphy */
352 if (!alpha2_equal(cfg80211_regdomain
->alpha2
, alpha2
))
356 if (WARN_ON(!is_alpha2_set(alpha2
) || !is_an_alpha2(alpha2
)),
357 "Invalid Country IE regulatory hint passed "
358 "to the wireless core\n")
360 /* We ignore Country IE hints for now, as we haven't yet
361 * added the dot11MultiDomainCapabilityEnabled flag
364 case REGDOM_SET_BY_DRIVER
:
366 if (last_request
->initiator
== set_by
) {
367 /* Two separate drivers hinting different things,
368 * this is possible if you have two devices present
369 * on a system with different EEPROM regulatory
370 * readings. XXX: Do intersection, we support only
371 * the first regulatory hint for now */
372 if (last_request
->wiphy
!= wiphy
)
376 /* Driver should not be trying to hint different
377 * regulatory domains! */
378 BUG_ON(!alpha2_equal(alpha2
,
379 cfg80211_regdomain
->alpha2
));
382 if (last_request
->initiator
== REGDOM_SET_BY_CORE
)
384 /* XXX: Handle intersection, and add the
385 * dot11MultiDomainCapabilityEnabled flag to wiphy. For now
386 * we assume the driver has this set to false, following the
387 * 802.11d dot11MultiDomainCapabilityEnabled documentation */
388 if (last_request
->initiator
== REGDOM_SET_BY_COUNTRY_IE
)
391 case REGDOM_SET_BY_USER
:
392 if (last_request
->initiator
== set_by
||
393 last_request
->initiator
== REGDOM_SET_BY_CORE
)
395 /* Drivers can use their wiphy's reg_notifier()
396 * to override any information */
397 if (last_request
->initiator
== REGDOM_SET_BY_DRIVER
)
399 /* XXX: Handle intersection */
400 if (last_request
->initiator
== REGDOM_SET_BY_COUNTRY_IE
)
408 static bool __reg_is_valid_request(char *alpha2
,
409 struct regulatory_request
**request
)
411 struct regulatory_request
*req
;
412 if (list_empty(®ulatory_requests
))
414 list_for_each_entry(req
, ®ulatory_requests
, list
) {
415 if (alpha2_equal(req
->alpha2
, alpha2
)) {
423 /* Used by nl80211 before kmalloc'ing our regulatory domain */
424 bool reg_is_valid_request(char *alpha2
)
426 struct regulatory_request
*request
= NULL
;
427 return __reg_is_valid_request(alpha2
, &request
);
430 /* Sanity check on a regulatory rule */
431 static bool is_valid_reg_rule(struct ieee80211_reg_rule
*rule
)
433 struct ieee80211_freq_range
*freq_range
= &rule
->freq_range
;
436 if (freq_range
->start_freq_khz
== 0 || freq_range
->end_freq_khz
== 0)
439 if (freq_range
->start_freq_khz
> freq_range
->end_freq_khz
)
442 freq_diff
= freq_range
->end_freq_khz
- freq_range
->start_freq_khz
;
444 if (freq_range
->max_bandwidth_khz
> freq_diff
)
450 static bool is_valid_rd(struct ieee80211_regdomain
*rd
)
452 struct ieee80211_reg_rule
*reg_rule
= NULL
;
455 if (!rd
->n_reg_rules
)
458 for (i
= 0; i
< rd
->n_reg_rules
; i
++) {
459 reg_rule
= &rd
->reg_rules
[i
];
460 if (!is_valid_reg_rule(reg_rule
))
467 /* Returns value in KHz */
468 static u32
freq_max_bandwidth(const struct ieee80211_freq_range
*freq_range
,
472 for (i
= 0; i
< ARRAY_SIZE(supported_bandwidths
); i
++) {
473 u32 start_freq_khz
= freq
- supported_bandwidths
[i
]/2;
474 u32 end_freq_khz
= freq
+ supported_bandwidths
[i
]/2;
475 if (start_freq_khz
>= freq_range
->start_freq_khz
&&
476 end_freq_khz
<= freq_range
->end_freq_khz
)
477 return supported_bandwidths
[i
];
482 /* XXX: add support for the rest of enum nl80211_reg_rule_flags, we may
483 * want to just have the channel structure use these */
484 static u32
map_regdom_flags(u32 rd_flags
)
486 u32 channel_flags
= 0;
487 if (rd_flags
& NL80211_RRF_PASSIVE_SCAN
)
488 channel_flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
489 if (rd_flags
& NL80211_RRF_NO_IBSS
)
490 channel_flags
|= IEEE80211_CHAN_NO_IBSS
;
491 if (rd_flags
& NL80211_RRF_DFS
)
492 channel_flags
|= IEEE80211_CHAN_RADAR
;
493 return channel_flags
;
497 * freq_reg_info - get regulatory information for the given frequency
498 * @center_freq: Frequency in KHz for which we want regulatory information for
499 * @bandwidth: the bandwidth requirement you have in KHz, if you do not have one
500 * you can set this to 0. If this frequency is allowed we then set
501 * this value to the maximum allowed bandwidth.
502 * @reg_rule: the regulatory rule which we have for this frequency
504 * Use this function to get the regulatory rule for a specific frequency.
506 static int freq_reg_info(u32 center_freq
, u32
*bandwidth
,
507 const struct ieee80211_reg_rule
**reg_rule
)
510 u32 max_bandwidth
= 0;
512 if (!cfg80211_regdomain
)
515 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
516 const struct ieee80211_reg_rule
*rr
;
517 const struct ieee80211_freq_range
*fr
= NULL
;
518 const struct ieee80211_power_rule
*pr
= NULL
;
520 rr
= &cfg80211_regdomain
->reg_rules
[i
];
521 fr
= &rr
->freq_range
;
522 pr
= &rr
->power_rule
;
523 max_bandwidth
= freq_max_bandwidth(fr
, center_freq
);
524 if (max_bandwidth
&& *bandwidth
<= max_bandwidth
) {
526 *bandwidth
= max_bandwidth
;
531 return !max_bandwidth
;
534 static void handle_channel(struct ieee80211_channel
*chan
)
537 u32 flags
= chan
->orig_flags
;
538 u32 max_bandwidth
= 0;
539 const struct ieee80211_reg_rule
*reg_rule
= NULL
;
540 const struct ieee80211_power_rule
*power_rule
= NULL
;
542 r
= freq_reg_info(MHZ_TO_KHZ(chan
->center_freq
),
543 &max_bandwidth
, ®_rule
);
546 flags
|= IEEE80211_CHAN_DISABLED
;
551 power_rule
= ®_rule
->power_rule
;
553 chan
->flags
= flags
| map_regdom_flags(reg_rule
->flags
);
554 chan
->max_antenna_gain
= min(chan
->orig_mag
,
555 (int) MBI_TO_DBI(power_rule
->max_antenna_gain
));
556 chan
->max_bandwidth
= KHZ_TO_MHZ(max_bandwidth
);
558 chan
->max_power
= min(chan
->orig_mpwr
,
559 (int) MBM_TO_DBM(power_rule
->max_eirp
));
561 chan
->max_power
= (int) MBM_TO_DBM(power_rule
->max_eirp
);
564 static void handle_band(struct ieee80211_supported_band
*sband
)
568 for (i
= 0; i
< sband
->n_channels
; i
++)
569 handle_channel(&sband
->channels
[i
]);
572 static void update_all_wiphy_regulatory(enum reg_set_by setby
)
574 struct cfg80211_registered_device
*drv
;
576 list_for_each_entry(drv
, &cfg80211_drv_list
, list
)
577 wiphy_update_regulatory(&drv
->wiphy
, setby
);
580 void wiphy_update_regulatory(struct wiphy
*wiphy
, enum reg_set_by setby
)
582 enum ieee80211_band band
;
583 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
584 if (wiphy
->bands
[band
])
585 handle_band(wiphy
->bands
[band
]);
586 if (wiphy
->reg_notifier
)
587 wiphy
->reg_notifier(wiphy
, setby
);
591 /* Caller must hold &cfg80211_drv_mutex */
592 int __regulatory_hint(struct wiphy
*wiphy
, enum reg_set_by set_by
,
593 const char *alpha2
, struct ieee80211_regdomain
*rd
)
595 struct regulatory_request
*request
;
599 r
= ignore_request(wiphy
, set_by
, (char *) alpha2
, rd
);
604 rd_alpha2
= rd
->alpha2
;
606 rd_alpha2
= (char *) alpha2
;
609 case REGDOM_SET_BY_CORE
:
610 case REGDOM_SET_BY_COUNTRY_IE
:
611 case REGDOM_SET_BY_DRIVER
:
612 case REGDOM_SET_BY_USER
:
613 request
= kzalloc(sizeof(struct regulatory_request
),
618 request
->alpha2
[0] = rd_alpha2
[0];
619 request
->alpha2
[1] = rd_alpha2
[1];
620 request
->initiator
= set_by
;
621 request
->wiphy
= wiphy
;
623 list_add_tail(&request
->list
, ®ulatory_requests
);
626 r
= call_crda(alpha2
);
627 #ifndef CONFIG_WIRELESS_OLD_REGULATORY
629 printk(KERN_ERR
"cfg80211: Failed calling CRDA\n");
640 /* If rd is not NULL and if this call fails the caller must free it */
641 int regulatory_hint(struct wiphy
*wiphy
, const char *alpha2
,
642 struct ieee80211_regdomain
*rd
)
645 BUG_ON(!rd
&& !alpha2
);
647 mutex_lock(&cfg80211_drv_mutex
);
649 r
= __regulatory_hint(wiphy
, REGDOM_SET_BY_DRIVER
, alpha2
, rd
);
651 goto unlock_and_exit
;
653 /* If the driver passed a regulatory domain we skipped asking
654 * userspace for one so we can now go ahead and set it */
658 mutex_unlock(&cfg80211_drv_mutex
);
661 EXPORT_SYMBOL(regulatory_hint
);
664 static void print_rd_rules(struct ieee80211_regdomain
*rd
)
667 struct ieee80211_reg_rule
*reg_rule
= NULL
;
668 struct ieee80211_freq_range
*freq_range
= NULL
;
669 struct ieee80211_power_rule
*power_rule
= NULL
;
671 printk(KERN_INFO
"\t(start_freq - end_freq @ bandwidth), "
672 "(max_antenna_gain, max_eirp)\n");
674 for (i
= 0; i
< rd
->n_reg_rules
; i
++) {
675 reg_rule
= &rd
->reg_rules
[i
];
676 freq_range
= ®_rule
->freq_range
;
677 power_rule
= ®_rule
->power_rule
;
679 /* There may not be documentation for max antenna gain
680 * in certain regions */
681 if (power_rule
->max_antenna_gain
)
682 printk(KERN_INFO
"\t(%d KHz - %d KHz @ %d KHz), "
683 "(%d mBi, %d mBm)\n",
684 freq_range
->start_freq_khz
,
685 freq_range
->end_freq_khz
,
686 freq_range
->max_bandwidth_khz
,
687 power_rule
->max_antenna_gain
,
688 power_rule
->max_eirp
);
690 printk(KERN_INFO
"\t(%d KHz - %d KHz @ %d KHz), "
692 freq_range
->start_freq_khz
,
693 freq_range
->end_freq_khz
,
694 freq_range
->max_bandwidth_khz
,
695 power_rule
->max_eirp
);
699 static void print_regdomain(struct ieee80211_regdomain
*rd
)
702 if (is_world_regdom(rd
->alpha2
))
703 printk(KERN_INFO
"cfg80211: World regulatory "
704 "domain updated:\n");
706 if (is_unknown_alpha2(rd
->alpha2
))
707 printk(KERN_INFO
"cfg80211: Regulatory domain "
708 "changed to driver built-in settings "
709 "(unknown country)\n");
711 printk(KERN_INFO
"cfg80211: Regulatory domain "
712 "changed to country: %c%c\n",
713 rd
->alpha2
[0], rd
->alpha2
[1]);
718 void print_regdomain_info(struct ieee80211_regdomain
*rd
)
720 printk(KERN_INFO
"cfg80211: Regulatory domain: %c%c\n",
721 rd
->alpha2
[0], rd
->alpha2
[1]);
725 static int __set_regdom(struct ieee80211_regdomain
*rd
)
727 struct regulatory_request
*request
= NULL
;
729 /* Some basic sanity checks first */
731 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
732 /* We ignore the world regdom with the old static regdomains setup
733 * as there is no point to it with static regulatory definitions :(
734 * Don't worry this shit will be removed soon... */
735 if (is_world_regdom(rd
->alpha2
))
738 if (is_world_regdom(rd
->alpha2
)) {
739 if (WARN_ON(!__reg_is_valid_request(rd
->alpha2
, &request
)))
741 update_world_regdomain(rd
);
746 if (!is_alpha2_set(rd
->alpha2
) && !is_an_alpha2(rd
->alpha2
) &&
747 !is_unknown_alpha2(rd
->alpha2
))
750 if (list_empty(®ulatory_requests
))
753 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
754 /* Static "US" and "JP" will be overridden, but just once */
755 if (!is_old_static_regdom(cfg80211_regdomain
) &&
756 !regdom_changed(rd
->alpha2
))
759 if (!regdom_changed(rd
->alpha2
))
763 /* Now lets set the regulatory domain, update all driver channels
764 * and finally inform them of what we have done, in case they want
765 * to review or adjust their own settings based on their own
766 * internal EEPROM data */
768 if (WARN_ON(!__reg_is_valid_request(rd
->alpha2
, &request
)))
771 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
772 reset_regdomains_static();
777 /* Country IE parsing coming soon */
778 switch (request
->initiator
) {
779 case REGDOM_SET_BY_CORE
:
780 case REGDOM_SET_BY_DRIVER
:
781 case REGDOM_SET_BY_USER
:
782 if (!is_valid_rd(rd
)) {
783 printk(KERN_ERR
"cfg80211: Invalid "
784 "regulatory domain detected:\n");
785 print_regdomain_info(rd
);
789 case REGDOM_SET_BY_COUNTRY_IE
: /* Not yet */
796 cfg80211_regdomain
= rd
;
797 request
->granted
= 1;
803 /* Use this call to set the current regulatory domain. Conflicts with
804 * multiple drivers can be ironed out later. Caller must've already
805 * kmalloc'd the rd structure. If this calls fails you should kfree()
806 * the passed rd. Caller must hold cfg80211_drv_mutex */
807 int set_regdom(struct ieee80211_regdomain
*rd
)
809 struct regulatory_request
*this_request
= NULL
, *prev_request
= NULL
;
812 if (!list_empty(®ulatory_requests
))
813 prev_request
= list_first_entry(®ulatory_requests
,
814 struct regulatory_request
, list
);
816 /* Note that this doesn't update the wiphys, this is done below */
817 r
= __set_regdom(rd
);
821 BUG_ON((!__reg_is_valid_request(rd
->alpha2
, &this_request
)));
823 /* The initial standard core update of the world regulatory domain, no
824 * need to keep that request info around if it didn't fail. */
825 if (is_world_regdom(rd
->alpha2
) &&
826 this_request
->initiator
== REGDOM_SET_BY_CORE
&&
827 this_request
->granted
) {
828 list_del(&this_request
->list
);
833 /* Remove old requests, we only leave behind the last one */
835 list_del(&prev_request
->list
);
840 /* This would make this whole thing pointless */
841 BUG_ON(rd
!= cfg80211_regdomain
);
843 /* update all wiphys now with the new established regulatory domain */
844 update_all_wiphy_regulatory(this_request
->initiator
);
851 int regulatory_init(void)
855 reg_pdev
= platform_device_register_simple("regulatory", 0, NULL
, 0);
856 if (IS_ERR(reg_pdev
))
857 return PTR_ERR(reg_pdev
);
859 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
861 (struct ieee80211_regdomain
*) static_regdom(ieee80211_regdom
);
862 /* Used during reset_regdomains_static() */
863 cfg80211_world_regdom
= cfg80211_regdomain
;
865 printk(KERN_INFO
"cfg80211: Using old static regulatory domain:\n");
866 print_regdomain_info(cfg80211_regdomain
);
867 /* The old code still requests for a new regdomain and if
868 * you have CRDA you get it updated, otherwise you get
869 * stuck with the static values. We ignore "EU" code as
870 * that is not a valid ISO / IEC 3166 alpha2 */
871 if (ieee80211_regdom
[0] != 'E' && ieee80211_regdom
[1] != 'U')
872 err
= __regulatory_hint(NULL
, REGDOM_SET_BY_CORE
,
873 ieee80211_regdom
, NULL
);
876 (struct ieee80211_regdomain
*) cfg80211_world_regdom
;
878 err
= __regulatory_hint(NULL
, REGDOM_SET_BY_CORE
, "00", NULL
);
880 printk(KERN_ERR
"cfg80211: calling CRDA failed - "
881 "unable to update world regulatory domain, "
882 "using static definition\n");
888 void regulatory_exit(void)
890 struct regulatory_request
*req
, *req_tmp
;
892 mutex_lock(&cfg80211_drv_mutex
);
894 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
895 reset_regdomains_static();
900 list_for_each_entry_safe(req
, req_tmp
, ®ulatory_requests
, list
) {
901 list_del(&req
->list
);
904 platform_device_unregister(reg_pdev
);
906 mutex_unlock(&cfg80211_drv_mutex
);