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>
46 * wiphy is set if this request's initiator is
47 * REGDOM_SET_BY_COUNTRY_IE or _DRIVER
49 struct regulatory_request {
51 enum reg_set_by initiator;
56 static struct regulatory_request *last_request;
58 /* To trigger userspace events */
59 static struct platform_device *reg_pdev;
61 /* Keep the ordering from large to small */
62 static u32 supported_bandwidths[] = {
67 /* Central wireless core regulatory domains, we only need two,
68 * the current one and a world regulatory domain in case we have no
69 * information to give us an alpha2 */
70 static const struct ieee80211_regdomain *cfg80211_regdomain;
72 /* We keep a static world regulatory domain in case of the absence of CRDA */
73 static const struct ieee80211_regdomain world_regdom = {
77 REG_RULE(2412-10, 2462+10, 40, 6, 20,
78 NL80211_RRF_PASSIVE_SCAN |
83 static const struct ieee80211_regdomain *cfg80211_world_regdom =
86 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
87 static char *ieee80211_regdom = "US";
88 module_param(ieee80211_regdom, charp, 0444);
89 MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
91 /* We assume 40 MHz bandwidth for the old regulatory work.
92 * We make emphasis we are using the exact same frequencies
95 static const struct ieee80211_regdomain us_regdom = {
99 /* IEEE 802.11b/g, channels 1..11 */
100 REG_RULE(2412-10, 2462+10, 40, 6, 27, 0),
101 /* IEEE 802.11a, channel 36 */
102 REG_RULE(5180-10, 5180+10, 40, 6, 23, 0),
103 /* IEEE 802.11a, channel 40 */
104 REG_RULE(5200-10, 5200+10, 40, 6, 23, 0),
105 /* IEEE 802.11a, channel 44 */
106 REG_RULE(5220-10, 5220+10, 40, 6, 23, 0),
107 /* IEEE 802.11a, channels 48..64 */
108 REG_RULE(5240-10, 5320+10, 40, 6, 23, 0),
109 /* IEEE 802.11a, channels 149..165, outdoor */
110 REG_RULE(5745-10, 5825+10, 40, 6, 30, 0),
114 static const struct ieee80211_regdomain jp_regdom = {
118 /* IEEE 802.11b/g, channels 1..14 */
119 REG_RULE(2412-10, 2484+10, 40, 6, 20, 0),
120 /* IEEE 802.11a, channels 34..48 */
121 REG_RULE(5170-10, 5240+10, 40, 6, 20,
122 NL80211_RRF_PASSIVE_SCAN),
123 /* IEEE 802.11a, channels 52..64 */
124 REG_RULE(5260-10, 5320+10, 40, 6, 20,
125 NL80211_RRF_NO_IBSS |
130 static const struct ieee80211_regdomain eu_regdom = {
132 /* This alpha2 is bogus, we leave it here just for stupid
133 * backward compatibility */
136 /* IEEE 802.11b/g, channels 1..13 */
137 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
138 /* IEEE 802.11a, channel 36 */
139 REG_RULE(5180-10, 5180+10, 40, 6, 23,
140 NL80211_RRF_PASSIVE_SCAN),
141 /* IEEE 802.11a, channel 40 */
142 REG_RULE(5200-10, 5200+10, 40, 6, 23,
143 NL80211_RRF_PASSIVE_SCAN),
144 /* IEEE 802.11a, channel 44 */
145 REG_RULE(5220-10, 5220+10, 40, 6, 23,
146 NL80211_RRF_PASSIVE_SCAN),
147 /* IEEE 802.11a, channels 48..64 */
148 REG_RULE(5240-10, 5320+10, 40, 6, 20,
149 NL80211_RRF_NO_IBSS |
151 /* IEEE 802.11a, channels 100..140 */
152 REG_RULE(5500-10, 5700+10, 40, 6, 30,
153 NL80211_RRF_NO_IBSS |
158 static const struct ieee80211_regdomain *static_regdom(char *alpha2)
160 if (alpha2[0] == 'U' && alpha2[1] == 'S')
162 if (alpha2[0] == 'J' && alpha2[1] == 'P')
164 if (alpha2[0] == 'E' && alpha2[1] == 'U')
166 /* Default, as per the old rules */
170 static bool is_old_static_regdom(const struct ieee80211_regdomain *rd)
172 if (rd == &us_regdom || rd == &jp_regdom || rd == &eu_regdom)
177 static inline bool is_old_static_regdom(const struct ieee80211_regdomain *rd)
183 static void reset_regdomains(void)
185 /* avoid freeing static information or freeing something twice */
186 if (cfg80211_regdomain == cfg80211_world_regdom)
187 cfg80211_regdomain = NULL;
188 if (cfg80211_world_regdom == &world_regdom)
189 cfg80211_world_regdom = NULL;
190 if (cfg80211_regdomain == &world_regdom)
191 cfg80211_regdomain = NULL;
192 if (is_old_static_regdom(cfg80211_regdomain))
193 cfg80211_regdomain = NULL;
195 kfree(cfg80211_regdomain);
196 kfree(cfg80211_world_regdom);
198 cfg80211_world_regdom = &world_regdom;
199 cfg80211_regdomain = NULL;
202 /* Dynamic world regulatory domain requested by the wireless
203 * core upon initialization */
204 static void update_world_regdomain(const struct ieee80211_regdomain *rd)
206 BUG_ON(!last_request);
210 cfg80211_world_regdom = rd;
211 cfg80211_regdomain = rd;
214 bool is_world_regdom(const char *alpha2)
218 if (alpha2[0] == '0' && alpha2[1] == '0')
223 static bool is_alpha2_set(const char *alpha2)
227 if (alpha2[0] != 0 && alpha2[1] != 0)
232 static bool is_alpha_upper(char letter)
235 if (letter >= 65 && letter <= 90)
240 static bool is_unknown_alpha2(const char *alpha2)
244 /* Special case where regulatory domain was built by driver
245 * but a specific alpha2 cannot be determined */
246 if (alpha2[0] == '9' && alpha2[1] == '9')
251 static bool is_an_alpha2(const char *alpha2)
255 if (is_alpha_upper(alpha2[0]) && is_alpha_upper(alpha2[1]))
260 static bool alpha2_equal(const char *alpha2_x, const char *alpha2_y)
262 if (!alpha2_x || !alpha2_y)
264 if (alpha2_x[0] == alpha2_y[0] &&
265 alpha2_x[1] == alpha2_y[1])
270 static bool regdom_changed(const char *alpha2)
272 if (!cfg80211_regdomain)
274 if (alpha2_equal(cfg80211_regdomain->alpha2, alpha2))
279 /* This lets us keep regulatory code which is updated on a regulatory
280 * basis in userspace. */
281 static int call_crda(const char *alpha2)
283 char country_env[9 + 2] = "COUNTRY=";
289 if (!is_world_regdom((char *) alpha2))
290 printk(KERN_INFO "cfg80211: Calling CRDA for country: %c%c\n",
291 alpha2[0], alpha2[1]);
293 printk(KERN_INFO "cfg80211: Calling CRDA to update world "
294 "regulatory domain\n");
296 country_env[8] = alpha2[0];
297 country_env[9] = alpha2[1];
299 return kobject_uevent_env(®_pdev->dev.kobj, KOBJ_CHANGE, envp);
302 /* Used by nl80211 before kmalloc'ing our regulatory domain */
303 bool reg_is_valid_request(const char *alpha2)
308 return alpha2_equal(last_request->alpha2, alpha2);
311 /* Sanity check on a regulatory rule */
312 static bool is_valid_reg_rule(const struct ieee80211_reg_rule *rule)
314 const struct ieee80211_freq_range *freq_range = &rule->freq_range;
317 if (freq_range->start_freq_khz == 0 || freq_range->end_freq_khz == 0)
320 if (freq_range->start_freq_khz > freq_range->end_freq_khz)
323 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
325 if (freq_diff <= 0 || freq_range->max_bandwidth_khz > freq_diff)
331 static bool is_valid_rd(const struct ieee80211_regdomain *rd)
333 const struct ieee80211_reg_rule *reg_rule = NULL;
336 if (!rd->n_reg_rules)
339 for (i = 0; i < rd->n_reg_rules; i++) {
340 reg_rule = &rd->reg_rules[i];
341 if (!is_valid_reg_rule(reg_rule))
348 /* Returns value in KHz */
349 static u32 freq_max_bandwidth(const struct ieee80211_freq_range *freq_range,
353 for (i = 0; i < ARRAY_SIZE(supported_bandwidths); i++) {
354 u32 start_freq_khz = freq - supported_bandwidths[i]/2;
355 u32 end_freq_khz = freq + supported_bandwidths[i]/2;
356 if (start_freq_khz >= freq_range->start_freq_khz &&
357 end_freq_khz <= freq_range->end_freq_khz)
358 return supported_bandwidths[i];
363 /* Helper for regdom_intersect(), this does the real
364 * mathematical intersection fun */
365 static int reg_rules_intersect(
366 const struct ieee80211_reg_rule *rule1,
367 const struct ieee80211_reg_rule *rule2,
368 struct ieee80211_reg_rule *intersected_rule)
370 const struct ieee80211_freq_range *freq_range1, *freq_range2;
371 struct ieee80211_freq_range *freq_range;
372 const struct ieee80211_power_rule *power_rule1, *power_rule2;
373 struct ieee80211_power_rule *power_rule;
376 freq_range1 = &rule1->freq_range;
377 freq_range2 = &rule2->freq_range;
378 freq_range = &intersected_rule->freq_range;
380 power_rule1 = &rule1->power_rule;
381 power_rule2 = &rule2->power_rule;
382 power_rule = &intersected_rule->power_rule;
384 freq_range->start_freq_khz = max(freq_range1->start_freq_khz,
385 freq_range2->start_freq_khz);
386 freq_range->end_freq_khz = min(freq_range1->end_freq_khz,
387 freq_range2->end_freq_khz);
388 freq_range->max_bandwidth_khz = min(freq_range1->max_bandwidth_khz,
389 freq_range2->max_bandwidth_khz);
391 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
392 if (freq_range->max_bandwidth_khz > freq_diff)
393 freq_range->max_bandwidth_khz = freq_diff;
395 power_rule->max_eirp = min(power_rule1->max_eirp,
396 power_rule2->max_eirp);
397 power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain,
398 power_rule2->max_antenna_gain);
400 intersected_rule->flags = (rule1->flags | rule2->flags);
402 if (!is_valid_reg_rule(intersected_rule))
409 * regdom_intersect - do the intersection between two regulatory domains
410 * @rd1: first regulatory domain
411 * @rd2: second regulatory domain
413 * Use this function to get the intersection between two regulatory domains.
414 * Once completed we will mark the alpha2 for the rd as intersected, "98",
415 * as no one single alpha2 can represent this regulatory domain.
417 * Returns a pointer to the regulatory domain structure which will hold the
418 * resulting intersection of rules between rd1 and rd2. We will
419 * kzalloc() this structure for you.
421 static struct ieee80211_regdomain *regdom_intersect(
422 const struct ieee80211_regdomain *rd1,
423 const struct ieee80211_regdomain *rd2)
427 unsigned int num_rules = 0, rule_idx = 0;
428 const struct ieee80211_reg_rule *rule1, *rule2;
429 struct ieee80211_reg_rule *intersected_rule;
430 struct ieee80211_regdomain *rd;
431 /* This is just a dummy holder to help us count */
432 struct ieee80211_reg_rule irule;
434 /* Uses the stack temporarily for counter arithmetic */
435 intersected_rule = &irule;
437 memset(intersected_rule, 0, sizeof(struct ieee80211_reg_rule));
442 /* First we get a count of the rules we'll need, then we actually
443 * build them. This is to so we can malloc() and free() a
444 * regdomain once. The reason we use reg_rules_intersect() here
445 * is it will return -EINVAL if the rule computed makes no sense.
446 * All rules that do check out OK are valid. */
448 for (x = 0; x < rd1->n_reg_rules; x++) {
449 rule1 = &rd1->reg_rules[x];
450 for (y = 0; y < rd2->n_reg_rules; y++) {
451 rule2 = &rd2->reg_rules[y];
452 if (!reg_rules_intersect(rule1, rule2,
455 memset(intersected_rule, 0,
456 sizeof(struct ieee80211_reg_rule));
463 size_of_regd = sizeof(struct ieee80211_regdomain) +
464 ((num_rules + 1) * sizeof(struct ieee80211_reg_rule));
466 rd = kzalloc(size_of_regd, GFP_KERNEL);
470 for (x = 0; x < rd1->n_reg_rules; x++) {
471 rule1 = &rd1->reg_rules[x];
472 for (y = 0; y < rd2->n_reg_rules; y++) {
473 rule2 = &rd2->reg_rules[y];
474 /* This time around instead of using the stack lets
475 * write to the target rule directly saving ourselves
477 intersected_rule = &rd->reg_rules[rule_idx];
478 r = reg_rules_intersect(rule1, rule2,
480 /* No need to memset here the intersected rule here as
481 * we're not using the stack anymore */
488 if (rule_idx != num_rules) {
493 rd->n_reg_rules = num_rules;
500 /* XXX: add support for the rest of enum nl80211_reg_rule_flags, we may
501 * want to just have the channel structure use these */
502 static u32 map_regdom_flags(u32 rd_flags)
504 u32 channel_flags = 0;
505 if (rd_flags & NL80211_RRF_PASSIVE_SCAN)
506 channel_flags |= IEEE80211_CHAN_PASSIVE_SCAN;
507 if (rd_flags & NL80211_RRF_NO_IBSS)
508 channel_flags |= IEEE80211_CHAN_NO_IBSS;
509 if (rd_flags & NL80211_RRF_DFS)
510 channel_flags |= IEEE80211_CHAN_RADAR;
511 return channel_flags;
515 * freq_reg_info - get regulatory information for the given frequency
516 * @center_freq: Frequency in KHz for which we want regulatory information for
517 * @bandwidth: the bandwidth requirement you have in KHz, if you do not have one
518 * you can set this to 0. If this frequency is allowed we then set
519 * this value to the maximum allowed bandwidth.
520 * @reg_rule: the regulatory rule which we have for this frequency
522 * Use this function to get the regulatory rule for a specific frequency.
524 static int freq_reg_info(u32 center_freq, u32 *bandwidth,
525 const struct ieee80211_reg_rule **reg_rule)
528 u32 max_bandwidth = 0;
530 if (!cfg80211_regdomain)
533 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
534 const struct ieee80211_reg_rule *rr;
535 const struct ieee80211_freq_range *fr = NULL;
536 const struct ieee80211_power_rule *pr = NULL;
538 rr = &cfg80211_regdomain->reg_rules[i];
539 fr = &rr->freq_range;
540 pr = &rr->power_rule;
541 max_bandwidth = freq_max_bandwidth(fr, center_freq);
542 if (max_bandwidth && *bandwidth <= max_bandwidth) {
544 *bandwidth = max_bandwidth;
549 return !max_bandwidth;
552 static void handle_channel(struct ieee80211_channel *chan)
555 u32 flags = chan->orig_flags;
556 u32 max_bandwidth = 0;
557 const struct ieee80211_reg_rule *reg_rule = NULL;
558 const struct ieee80211_power_rule *power_rule = NULL;
560 r = freq_reg_info(MHZ_TO_KHZ(chan->center_freq),
561 &max_bandwidth, ®_rule);
564 flags |= IEEE80211_CHAN_DISABLED;
569 power_rule = ®_rule->power_rule;
571 chan->flags = flags | map_regdom_flags(reg_rule->flags);
572 chan->max_antenna_gain = min(chan->orig_mag,
573 (int) MBI_TO_DBI(power_rule->max_antenna_gain));
574 chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth);
576 chan->max_power = min(chan->orig_mpwr,
577 (int) MBM_TO_DBM(power_rule->max_eirp));
579 chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp);
582 static void handle_band(struct ieee80211_supported_band *sband)
586 for (i = 0; i < sband->n_channels; i++)
587 handle_channel(&sband->channels[i]);
590 static void update_all_wiphy_regulatory(enum reg_set_by setby)
592 struct cfg80211_registered_device *drv;
594 list_for_each_entry(drv, &cfg80211_drv_list, list)
595 wiphy_update_regulatory(&drv->wiphy, setby);
598 void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby)
600 enum ieee80211_band band;
601 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
602 if (wiphy->bands[band])
603 handle_band(wiphy->bands[band]);
604 if (wiphy->reg_notifier)
605 wiphy->reg_notifier(wiphy, setby);
609 /* Return value which can be used by ignore_request() to indicate
610 * it has been determined we should intersect two regulatory domains */
611 #define REG_INTERSECT 1
613 /* This has the logic which determines when a new request
614 * should be ignored. */
615 static int ignore_request(struct wiphy *wiphy, enum reg_set_by set_by,
618 /* All initial requests are respected */
623 case REGDOM_SET_BY_INIT:
625 case REGDOM_SET_BY_CORE:
627 * Always respect new wireless core hints, should only happen
628 * when updating the world regulatory domain at init.
631 case REGDOM_SET_BY_COUNTRY_IE:
632 if (unlikely(!is_an_alpha2(alpha2)))
634 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) {
635 if (last_request->wiphy != wiphy) {
637 * Two cards with two APs claiming different
638 * different Country IE alpha2s. We could
639 * intersect them, but that seems unlikely
640 * to be correct. Reject second one for now.
642 if (!alpha2_equal(alpha2,
643 cfg80211_regdomain->alpha2))
647 /* Two consecutive Country IE hints on the same wiphy */
648 if (!alpha2_equal(cfg80211_regdomain->alpha2, alpha2))
653 * Ignore Country IE hints for now, need to think about
654 * what we need to do to support multi-domain operation.
657 case REGDOM_SET_BY_DRIVER:
658 if (last_request->initiator == REGDOM_SET_BY_DRIVER)
661 case REGDOM_SET_BY_USER:
662 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE)
663 return REG_INTERSECT;
670 /* Caller must hold &cfg80211_drv_mutex */
671 int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by,
674 struct regulatory_request *request;
675 bool intersect = false;
678 r = ignore_request(wiphy, set_by, alpha2);
680 if (r == REG_INTERSECT)
686 case REGDOM_SET_BY_CORE:
687 case REGDOM_SET_BY_COUNTRY_IE:
688 case REGDOM_SET_BY_DRIVER:
689 case REGDOM_SET_BY_USER:
690 request = kzalloc(sizeof(struct regulatory_request),
695 request->alpha2[0] = alpha2[0];
696 request->alpha2[1] = alpha2[1];
697 request->initiator = set_by;
698 request->wiphy = wiphy;
699 request->intersect = intersect;
702 last_request = request;
703 r = call_crda(alpha2);
704 #ifndef CONFIG_WIRELESS_OLD_REGULATORY
706 printk(KERN_ERR "cfg80211: Failed calling CRDA\n");
717 void regulatory_hint(struct wiphy *wiphy, const char *alpha2)
721 mutex_lock(&cfg80211_drv_mutex);
722 __regulatory_hint(wiphy, REGDOM_SET_BY_DRIVER, alpha2);
723 mutex_unlock(&cfg80211_drv_mutex);
725 EXPORT_SYMBOL(regulatory_hint);
728 static void print_rd_rules(const struct ieee80211_regdomain *rd)
731 const struct ieee80211_reg_rule *reg_rule = NULL;
732 const struct ieee80211_freq_range *freq_range = NULL;
733 const struct ieee80211_power_rule *power_rule = NULL;
735 printk(KERN_INFO "\t(start_freq - end_freq @ bandwidth), "
736 "(max_antenna_gain, max_eirp)\n");
738 for (i = 0; i < rd->n_reg_rules; i++) {
739 reg_rule = &rd->reg_rules[i];
740 freq_range = ®_rule->freq_range;
741 power_rule = ®_rule->power_rule;
743 /* There may not be documentation for max antenna gain
744 * in certain regions */
745 if (power_rule->max_antenna_gain)
746 printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), "
747 "(%d mBi, %d mBm)\n",
748 freq_range->start_freq_khz,
749 freq_range->end_freq_khz,
750 freq_range->max_bandwidth_khz,
751 power_rule->max_antenna_gain,
752 power_rule->max_eirp);
754 printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), "
756 freq_range->start_freq_khz,
757 freq_range->end_freq_khz,
758 freq_range->max_bandwidth_khz,
759 power_rule->max_eirp);
763 static void print_regdomain(const struct ieee80211_regdomain *rd)
766 if (is_world_regdom(rd->alpha2))
767 printk(KERN_INFO "cfg80211: World regulatory "
768 "domain updated:\n");
770 if (is_unknown_alpha2(rd->alpha2))
771 printk(KERN_INFO "cfg80211: Regulatory domain "
772 "changed to driver built-in settings "
773 "(unknown country)\n");
775 printk(KERN_INFO "cfg80211: Regulatory domain "
776 "changed to country: %c%c\n",
777 rd->alpha2[0], rd->alpha2[1]);
782 static void print_regdomain_info(const struct ieee80211_regdomain *rd)
784 printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n",
785 rd->alpha2[0], rd->alpha2[1]);
789 /* Takes ownership of rd only if it doesn't fail */
790 static int __set_regdom(const struct ieee80211_regdomain *rd)
792 const struct ieee80211_regdomain *intersected_rd = NULL;
793 /* Some basic sanity checks first */
795 if (is_world_regdom(rd->alpha2)) {
796 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
798 update_world_regdomain(rd);
802 if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) &&
803 !is_unknown_alpha2(rd->alpha2))
809 /* allow overriding the static definitions if CRDA is present */
810 if (!is_old_static_regdom(cfg80211_regdomain) &&
811 !regdom_changed(rd->alpha2))
814 /* Now lets set the regulatory domain, update all driver channels
815 * and finally inform them of what we have done, in case they want
816 * to review or adjust their own settings based on their own
817 * internal EEPROM data */
819 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
824 /* Country IE parsing coming soon */
825 switch (last_request->initiator) {
826 case REGDOM_SET_BY_CORE:
827 case REGDOM_SET_BY_DRIVER:
828 case REGDOM_SET_BY_USER:
829 if (!is_valid_rd(rd)) {
830 printk(KERN_ERR "cfg80211: Invalid "
831 "regulatory domain detected:\n");
832 print_regdomain_info(rd);
836 case REGDOM_SET_BY_COUNTRY_IE: /* Not yet */
842 if (unlikely(last_request->intersect)) {
843 intersected_rd = regdom_intersect(rd, cfg80211_regdomain);
851 cfg80211_regdomain = rd;
857 /* Use this call to set the current regulatory domain. Conflicts with
858 * multiple drivers can be ironed out later. Caller must've already
859 * kmalloc'd the rd structure. Caller must hold cfg80211_drv_mutex */
860 int set_regdom(const struct ieee80211_regdomain *rd)
864 /* Note that this doesn't update the wiphys, this is done below */
865 r = __set_regdom(rd);
871 /* This would make this whole thing pointless */
872 BUG_ON(rd != cfg80211_regdomain);
874 /* update all wiphys now with the new established regulatory domain */
875 update_all_wiphy_regulatory(last_request->initiator);
882 int regulatory_init(void)
886 reg_pdev = platform_device_register_simple("regulatory", 0, NULL, 0);
887 if (IS_ERR(reg_pdev))
888 return PTR_ERR(reg_pdev);
890 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
891 cfg80211_regdomain = static_regdom(ieee80211_regdom);
893 printk(KERN_INFO "cfg80211: Using static regulatory domain info\n");
894 print_regdomain_info(cfg80211_regdomain);
895 /* The old code still requests for a new regdomain and if
896 * you have CRDA you get it updated, otherwise you get
897 * stuck with the static values. We ignore "EU" code as
898 * that is not a valid ISO / IEC 3166 alpha2 */
899 if (ieee80211_regdom[0] != 'E' || ieee80211_regdom[1] != 'U')
900 err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE,
903 cfg80211_regdomain = cfg80211_world_regdom;
905 err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE, "00");
907 printk(KERN_ERR "cfg80211: calling CRDA failed - "
908 "unable to update world regulatory domain, "
909 "using static definition\n");
915 void regulatory_exit(void)
917 mutex_lock(&cfg80211_drv_mutex);
923 platform_device_unregister(reg_pdev);
925 mutex_unlock(&cfg80211_drv_mutex);