blob: 61698095e1ad1eb36763faed73b72a14e9328de1 [file] [log] [blame]
Johannes Berg8318d782008-01-24 19:38:38 +01001/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005 * Copyright 2008 Luis R. Rodriguez <lrodriguz@atheros.com>
Johannes Berg8318d782008-01-24 19:38:38 +01006 *
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.
10 */
11
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070012/**
13 * DOC: Wireless regulatory infrastructure
Johannes Berg8318d782008-01-24 19:38:38 +010014 *
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.
19 *
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070020 * 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.
23 *
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.
29 *
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.
33 *
Johannes Berg8318d782008-01-24 19:38:38 +010034 */
35#include <linux/kernel.h>
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070036#include <linux/list.h>
37#include <linux/random.h>
38#include <linux/nl80211.h>
39#include <linux/platform_device.h>
Johannes Berg8318d782008-01-24 19:38:38 +010040#include <net/wireless.h>
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070041#include <net/cfg80211.h>
Johannes Berg8318d782008-01-24 19:38:38 +010042#include "core.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070043#include "reg.h"
Johannes Berg8318d782008-01-24 19:38:38 +010044
Luis R. Rodriguez5166ccd2008-10-30 13:33:56 -070045/**
46 * struct regulatory_request - receipt of last regulatory request
47 *
48 * @wiphy: this is set if this request's initiator is
49 * %REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
50 * can be used by the wireless core to deal with conflicts
51 * and potentially inform users of which devices specifically
52 * cased the conflicts.
53 * @initiator: indicates who sent this request, could be any of
54 * of those set in reg_set_by, %REGDOM_SET_BY_*
55 * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
56 * regulatory domain. We have a few special codes:
57 * 00 - World regulatory domain
58 * 99 - built by driver but a specific alpha2 cannot be determined
59 * 98 - result of an intersection between two regulatory domains
60 * @intersect: indicates whether the wireless core should intersect
61 * the requested regulatory domain with the presently set regulatory
62 * domain.
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -080063 * @country_ie_checksum: checksum of the last processed and accepted
64 * country IE
65 * @country_ie_env: lets us know if the AP is telling us we are outdoor,
66 * indoor, or if it doesn't matter
Johannes Bergbe3d4812008-10-24 20:32:21 +020067 */
Johannes Berg734366d2008-09-15 10:56:48 +020068struct regulatory_request {
Johannes Berg734366d2008-09-15 10:56:48 +020069 struct wiphy *wiphy;
Johannes Berg734366d2008-09-15 10:56:48 +020070 enum reg_set_by initiator;
71 char alpha2[2];
Luis R. Rodriguez9c964772008-10-30 13:33:53 -070072 bool intersect;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -080073 u32 country_ie_checksum;
74 enum environment_cap country_ie_env;
Johannes Berg734366d2008-09-15 10:56:48 +020075};
76
Luis R. Rodriguez5166ccd2008-10-30 13:33:56 -070077/* Receipt of information from last regulatory request */
Johannes Bergf6037d02008-10-21 11:01:33 +020078static struct regulatory_request *last_request;
Johannes Berg734366d2008-09-15 10:56:48 +020079
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070080/* To trigger userspace events */
81static struct platform_device *reg_pdev;
Johannes Berg8318d782008-01-24 19:38:38 +010082
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070083/* Keep the ordering from large to small */
84static u32 supported_bandwidths[] = {
85 MHZ_TO_KHZ(40),
86 MHZ_TO_KHZ(20),
Johannes Berg8318d782008-01-24 19:38:38 +010087};
88
Johannes Berg734366d2008-09-15 10:56:48 +020089/* Central wireless core regulatory domains, we only need two,
90 * the current one and a world regulatory domain in case we have no
91 * information to give us an alpha2 */
Johannes Berga3d2eaf2008-09-15 11:10:52 +020092static const struct ieee80211_regdomain *cfg80211_regdomain;
Johannes Berg734366d2008-09-15 10:56:48 +020093
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -080094/* We use this as a place for the rd structure built from the
95 * last parsed country IE to rest until CRDA gets back to us with
96 * what it thinks should apply for the same country */
97static const struct ieee80211_regdomain *country_ie_regdomain;
98
Johannes Berg734366d2008-09-15 10:56:48 +020099/* We keep a static world regulatory domain in case of the absence of CRDA */
100static const struct ieee80211_regdomain world_regdom = {
101 .n_reg_rules = 1,
102 .alpha2 = "00",
103 .reg_rules = {
104 REG_RULE(2412-10, 2462+10, 40, 6, 20,
105 NL80211_RRF_PASSIVE_SCAN |
106 NL80211_RRF_NO_IBSS),
107 }
108};
109
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200110static const struct ieee80211_regdomain *cfg80211_world_regdom =
111 &world_regdom;
Johannes Berg734366d2008-09-15 10:56:48 +0200112
113#ifdef CONFIG_WIRELESS_OLD_REGULATORY
114static char *ieee80211_regdom = "US";
115module_param(ieee80211_regdom, charp, 0444);
116MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
117
118/* We assume 40 MHz bandwidth for the old regulatory work.
119 * We make emphasis we are using the exact same frequencies
120 * as before */
121
122static const struct ieee80211_regdomain us_regdom = {
123 .n_reg_rules = 6,
124 .alpha2 = "US",
125 .reg_rules = {
126 /* IEEE 802.11b/g, channels 1..11 */
127 REG_RULE(2412-10, 2462+10, 40, 6, 27, 0),
128 /* IEEE 802.11a, channel 36 */
129 REG_RULE(5180-10, 5180+10, 40, 6, 23, 0),
130 /* IEEE 802.11a, channel 40 */
131 REG_RULE(5200-10, 5200+10, 40, 6, 23, 0),
132 /* IEEE 802.11a, channel 44 */
133 REG_RULE(5220-10, 5220+10, 40, 6, 23, 0),
134 /* IEEE 802.11a, channels 48..64 */
135 REG_RULE(5240-10, 5320+10, 40, 6, 23, 0),
136 /* IEEE 802.11a, channels 149..165, outdoor */
137 REG_RULE(5745-10, 5825+10, 40, 6, 30, 0),
138 }
139};
140
141static const struct ieee80211_regdomain jp_regdom = {
142 .n_reg_rules = 3,
143 .alpha2 = "JP",
144 .reg_rules = {
145 /* IEEE 802.11b/g, channels 1..14 */
146 REG_RULE(2412-10, 2484+10, 40, 6, 20, 0),
147 /* IEEE 802.11a, channels 34..48 */
148 REG_RULE(5170-10, 5240+10, 40, 6, 20,
149 NL80211_RRF_PASSIVE_SCAN),
150 /* IEEE 802.11a, channels 52..64 */
151 REG_RULE(5260-10, 5320+10, 40, 6, 20,
152 NL80211_RRF_NO_IBSS |
153 NL80211_RRF_DFS),
154 }
155};
156
157static const struct ieee80211_regdomain eu_regdom = {
158 .n_reg_rules = 6,
159 /* This alpha2 is bogus, we leave it here just for stupid
160 * backward compatibility */
161 .alpha2 = "EU",
162 .reg_rules = {
163 /* IEEE 802.11b/g, channels 1..13 */
164 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
165 /* IEEE 802.11a, channel 36 */
166 REG_RULE(5180-10, 5180+10, 40, 6, 23,
167 NL80211_RRF_PASSIVE_SCAN),
168 /* IEEE 802.11a, channel 40 */
169 REG_RULE(5200-10, 5200+10, 40, 6, 23,
170 NL80211_RRF_PASSIVE_SCAN),
171 /* IEEE 802.11a, channel 44 */
172 REG_RULE(5220-10, 5220+10, 40, 6, 23,
173 NL80211_RRF_PASSIVE_SCAN),
174 /* IEEE 802.11a, channels 48..64 */
175 REG_RULE(5240-10, 5320+10, 40, 6, 20,
176 NL80211_RRF_NO_IBSS |
177 NL80211_RRF_DFS),
178 /* IEEE 802.11a, channels 100..140 */
179 REG_RULE(5500-10, 5700+10, 40, 6, 30,
180 NL80211_RRF_NO_IBSS |
181 NL80211_RRF_DFS),
182 }
183};
184
185static const struct ieee80211_regdomain *static_regdom(char *alpha2)
186{
187 if (alpha2[0] == 'U' && alpha2[1] == 'S')
188 return &us_regdom;
189 if (alpha2[0] == 'J' && alpha2[1] == 'P')
190 return &jp_regdom;
191 if (alpha2[0] == 'E' && alpha2[1] == 'U')
192 return &eu_regdom;
193 /* Default, as per the old rules */
194 return &us_regdom;
195}
196
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200197static bool is_old_static_regdom(const struct ieee80211_regdomain *rd)
Johannes Berg734366d2008-09-15 10:56:48 +0200198{
199 if (rd == &us_regdom || rd == &jp_regdom || rd == &eu_regdom)
200 return true;
201 return false;
202}
Johannes Berg734366d2008-09-15 10:56:48 +0200203#else
Johannes Berg942b25c2008-09-15 11:26:47 +0200204static inline bool is_old_static_regdom(const struct ieee80211_regdomain *rd)
205{
206 return false;
207}
208#endif
209
Johannes Berg734366d2008-09-15 10:56:48 +0200210static void reset_regdomains(void)
211{
Johannes Berg942b25c2008-09-15 11:26:47 +0200212 /* avoid freeing static information or freeing something twice */
213 if (cfg80211_regdomain == cfg80211_world_regdom)
214 cfg80211_regdomain = NULL;
215 if (cfg80211_world_regdom == &world_regdom)
216 cfg80211_world_regdom = NULL;
217 if (cfg80211_regdomain == &world_regdom)
218 cfg80211_regdomain = NULL;
219 if (is_old_static_regdom(cfg80211_regdomain))
220 cfg80211_regdomain = NULL;
221
222 kfree(cfg80211_regdomain);
223 kfree(cfg80211_world_regdom);
Johannes Berg734366d2008-09-15 10:56:48 +0200224
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200225 cfg80211_world_regdom = &world_regdom;
Johannes Berg734366d2008-09-15 10:56:48 +0200226 cfg80211_regdomain = NULL;
227}
228
229/* Dynamic world regulatory domain requested by the wireless
230 * core upon initialization */
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200231static void update_world_regdomain(const struct ieee80211_regdomain *rd)
Johannes Berg734366d2008-09-15 10:56:48 +0200232{
Johannes Bergf6037d02008-10-21 11:01:33 +0200233 BUG_ON(!last_request);
Johannes Berg734366d2008-09-15 10:56:48 +0200234
235 reset_regdomains();
236
237 cfg80211_world_regdom = rd;
238 cfg80211_regdomain = rd;
239}
Johannes Berg734366d2008-09-15 10:56:48 +0200240
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200241bool is_world_regdom(const char *alpha2)
Johannes Berg8318d782008-01-24 19:38:38 +0100242{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700243 if (!alpha2)
244 return false;
245 if (alpha2[0] == '0' && alpha2[1] == '0')
246 return true;
247 return false;
Johannes Berg8318d782008-01-24 19:38:38 +0100248}
249
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200250static bool is_alpha2_set(const char *alpha2)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700251{
252 if (!alpha2)
253 return false;
254 if (alpha2[0] != 0 && alpha2[1] != 0)
255 return true;
256 return false;
257}
Johannes Berg8318d782008-01-24 19:38:38 +0100258
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700259static bool is_alpha_upper(char letter)
260{
261 /* ASCII A - Z */
262 if (letter >= 65 && letter <= 90)
263 return true;
264 return false;
265}
266
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200267static bool is_unknown_alpha2(const char *alpha2)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700268{
269 if (!alpha2)
270 return false;
271 /* Special case where regulatory domain was built by driver
272 * but a specific alpha2 cannot be determined */
273 if (alpha2[0] == '9' && alpha2[1] == '9')
274 return true;
275 return false;
276}
277
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800278static bool is_intersected_alpha2(const char *alpha2)
279{
280 if (!alpha2)
281 return false;
282 /* Special case where regulatory domain is the
283 * result of an intersection between two regulatory domain
284 * structures */
285 if (alpha2[0] == '9' && alpha2[1] == '8')
286 return true;
287 return false;
288}
289
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200290static bool is_an_alpha2(const char *alpha2)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700291{
292 if (!alpha2)
293 return false;
294 if (is_alpha_upper(alpha2[0]) && is_alpha_upper(alpha2[1]))
295 return true;
296 return false;
297}
298
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200299static bool alpha2_equal(const char *alpha2_x, const char *alpha2_y)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700300{
301 if (!alpha2_x || !alpha2_y)
302 return false;
303 if (alpha2_x[0] == alpha2_y[0] &&
304 alpha2_x[1] == alpha2_y[1])
305 return true;
306 return false;
307}
308
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200309static bool regdom_changed(const char *alpha2)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700310{
311 if (!cfg80211_regdomain)
312 return true;
313 if (alpha2_equal(cfg80211_regdomain->alpha2, alpha2))
314 return false;
315 return true;
316}
317
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800318/**
319 * country_ie_integrity_changes - tells us if the country IE has changed
320 * @checksum: checksum of country IE of fields we are interested in
321 *
322 * If the country IE has not changed you can ignore it safely. This is
323 * useful to determine if two devices are seeing two different country IEs
324 * even on the same alpha2. Note that this will return false if no IE has
325 * been set on the wireless core yet.
326 */
327static bool country_ie_integrity_changes(u32 checksum)
328{
329 /* If no IE has been set then the checksum doesn't change */
330 if (unlikely(!last_request->country_ie_checksum))
331 return false;
332 if (unlikely(last_request->country_ie_checksum != checksum))
333 return true;
334 return false;
335}
336
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700337/* This lets us keep regulatory code which is updated on a regulatory
338 * basis in userspace. */
339static int call_crda(const char *alpha2)
340{
341 char country_env[9 + 2] = "COUNTRY=";
342 char *envp[] = {
343 country_env,
344 NULL
345 };
346
347 if (!is_world_regdom((char *) alpha2))
348 printk(KERN_INFO "cfg80211: Calling CRDA for country: %c%c\n",
349 alpha2[0], alpha2[1]);
350 else
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700351 printk(KERN_INFO "cfg80211: Calling CRDA to update world "
352 "regulatory domain\n");
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700353
354 country_env[8] = alpha2[0];
355 country_env[9] = alpha2[1];
356
357 return kobject_uevent_env(&reg_pdev->dev.kobj, KOBJ_CHANGE, envp);
358}
359
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700360/* Used by nl80211 before kmalloc'ing our regulatory domain */
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200361bool reg_is_valid_request(const char *alpha2)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700362{
Johannes Bergf6037d02008-10-21 11:01:33 +0200363 if (!last_request)
364 return false;
365
366 return alpha2_equal(last_request->alpha2, alpha2);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700367}
368
369/* Sanity check on a regulatory rule */
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200370static bool is_valid_reg_rule(const struct ieee80211_reg_rule *rule)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700371{
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200372 const struct ieee80211_freq_range *freq_range = &rule->freq_range;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700373 u32 freq_diff;
374
Luis R. Rodriguez91e99002008-11-12 14:21:55 -0800375 if (freq_range->start_freq_khz <= 0 || freq_range->end_freq_khz <= 0)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700376 return false;
377
378 if (freq_range->start_freq_khz > freq_range->end_freq_khz)
379 return false;
380
381 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
382
Luis R. Rodriguezd71aaf62008-10-30 13:33:52 -0700383 if (freq_diff <= 0 || freq_range->max_bandwidth_khz > freq_diff)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700384 return false;
385
386 return true;
387}
388
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200389static bool is_valid_rd(const struct ieee80211_regdomain *rd)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700390{
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200391 const struct ieee80211_reg_rule *reg_rule = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700392 unsigned int i;
393
394 if (!rd->n_reg_rules)
395 return false;
396
Luis R. Rodriguez88dc1c32008-11-12 14:22:01 -0800397 if (WARN_ON(rd->n_reg_rules > NL80211_MAX_SUPP_REG_RULES))
398 return false;
399
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700400 for (i = 0; i < rd->n_reg_rules; i++) {
401 reg_rule = &rd->reg_rules[i];
402 if (!is_valid_reg_rule(reg_rule))
403 return false;
404 }
405
406 return true;
407}
408
409/* Returns value in KHz */
410static u32 freq_max_bandwidth(const struct ieee80211_freq_range *freq_range,
411 u32 freq)
412{
413 unsigned int i;
414 for (i = 0; i < ARRAY_SIZE(supported_bandwidths); i++) {
415 u32 start_freq_khz = freq - supported_bandwidths[i]/2;
416 u32 end_freq_khz = freq + supported_bandwidths[i]/2;
417 if (start_freq_khz >= freq_range->start_freq_khz &&
418 end_freq_khz <= freq_range->end_freq_khz)
419 return supported_bandwidths[i];
420 }
421 return 0;
422}
423
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800424/**
425 * freq_in_rule_band - tells us if a frequency is in a frequency band
426 * @freq_range: frequency rule we want to query
427 * @freq_khz: frequency we are inquiring about
428 *
429 * This lets us know if a specific frequency rule is or is not relevant to
430 * a specific frequency's band. Bands are device specific and artificial
431 * definitions (the "2.4 GHz band" and the "5 GHz band"), however it is
432 * safe for now to assume that a frequency rule should not be part of a
433 * frequency's band if the start freq or end freq are off by more than 2 GHz.
434 * This resolution can be lowered and should be considered as we add
435 * regulatory rule support for other "bands".
436 **/
437static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range,
438 u32 freq_khz)
439{
440#define ONE_GHZ_IN_KHZ 1000000
441 if (abs(freq_khz - freq_range->start_freq_khz) <= (2 * ONE_GHZ_IN_KHZ))
442 return true;
443 if (abs(freq_khz - freq_range->end_freq_khz) <= (2 * ONE_GHZ_IN_KHZ))
444 return true;
445 return false;
446#undef ONE_GHZ_IN_KHZ
447}
448
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800449/* Converts a country IE to a regulatory domain. A regulatory domain
450 * structure has a lot of information which the IE doesn't yet have,
451 * so for the other values we use upper max values as we will intersect
452 * with our userspace regulatory agent to get lower bounds. */
453static struct ieee80211_regdomain *country_ie_2_rd(
454 u8 *country_ie,
455 u8 country_ie_len,
456 u32 *checksum)
457{
458 struct ieee80211_regdomain *rd = NULL;
459 unsigned int i = 0;
460 char alpha2[2];
461 u32 flags = 0;
462 u32 num_rules = 0, size_of_regd = 0;
463 u8 *triplets_start = NULL;
464 u8 len_at_triplet = 0;
465 /* the last channel we have registered in a subband (triplet) */
466 int last_sub_max_channel = 0;
467
468 *checksum = 0xDEADBEEF;
469
470 /* Country IE requirements */
471 BUG_ON(country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN ||
472 country_ie_len & 0x01);
473
474 alpha2[0] = country_ie[0];
475 alpha2[1] = country_ie[1];
476
477 /*
478 * Third octet can be:
479 * 'I' - Indoor
480 * 'O' - Outdoor
481 *
482 * anything else we assume is no restrictions
483 */
484 if (country_ie[2] == 'I')
485 flags = NL80211_RRF_NO_OUTDOOR;
486 else if (country_ie[2] == 'O')
487 flags = NL80211_RRF_NO_INDOOR;
488
489 country_ie += 3;
490 country_ie_len -= 3;
491
492 triplets_start = country_ie;
493 len_at_triplet = country_ie_len;
494
495 *checksum ^= ((flags ^ alpha2[0] ^ alpha2[1]) << 8);
496
497 /* We need to build a reg rule for each triplet, but first we must
498 * calculate the number of reg rules we will need. We will need one
499 * for each channel subband */
500 while (country_ie_len >= 3) {
Luis R. Rodriguez615aab42009-01-22 15:05:46 -0800501 int end_channel = 0;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800502 struct ieee80211_country_ie_triplet *triplet =
503 (struct ieee80211_country_ie_triplet *) country_ie;
504 int cur_sub_max_channel = 0, cur_channel = 0;
505
506 if (triplet->ext.reg_extension_id >=
507 IEEE80211_COUNTRY_EXTENSION_ID) {
508 country_ie += 3;
509 country_ie_len -= 3;
510 continue;
511 }
512
Luis R. Rodriguez615aab42009-01-22 15:05:46 -0800513 /* 2 GHz */
514 if (triplet->chans.first_channel <= 14)
515 end_channel = triplet->chans.first_channel +
516 triplet->chans.num_channels;
517 else
518 /*
519 * 5 GHz -- For example in country IEs if the first
520 * channel given is 36 and the number of channels is 4
521 * then the individual channel numbers defined for the
522 * 5 GHz PHY by these parameters are: 36, 40, 44, and 48
523 * and not 36, 37, 38, 39.
524 *
525 * See: http://tinyurl.com/11d-clarification
526 */
527 end_channel = triplet->chans.first_channel +
528 (4 * (triplet->chans.num_channels - 1));
529
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800530 cur_channel = triplet->chans.first_channel;
Luis R. Rodriguez615aab42009-01-22 15:05:46 -0800531 cur_sub_max_channel = end_channel;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800532
533 /* Basic sanity check */
534 if (cur_sub_max_channel < cur_channel)
535 return NULL;
536
537 /* Do not allow overlapping channels. Also channels
538 * passed in each subband must be monotonically
539 * increasing */
540 if (last_sub_max_channel) {
541 if (cur_channel <= last_sub_max_channel)
542 return NULL;
543 if (cur_sub_max_channel <= last_sub_max_channel)
544 return NULL;
545 }
546
547 /* When dot11RegulatoryClassesRequired is supported
548 * we can throw ext triplets as part of this soup,
549 * for now we don't care when those change as we
550 * don't support them */
551 *checksum ^= ((cur_channel ^ cur_sub_max_channel) << 8) |
552 ((cur_sub_max_channel ^ cur_sub_max_channel) << 16) |
553 ((triplet->chans.max_power ^ cur_sub_max_channel) << 24);
554
555 last_sub_max_channel = cur_sub_max_channel;
556
557 country_ie += 3;
558 country_ie_len -= 3;
559 num_rules++;
560
561 /* Note: this is not a IEEE requirement but
562 * simply a memory requirement */
563 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
564 return NULL;
565 }
566
567 country_ie = triplets_start;
568 country_ie_len = len_at_triplet;
569
570 size_of_regd = sizeof(struct ieee80211_regdomain) +
571 (num_rules * sizeof(struct ieee80211_reg_rule));
572
573 rd = kzalloc(size_of_regd, GFP_KERNEL);
574 if (!rd)
575 return NULL;
576
577 rd->n_reg_rules = num_rules;
578 rd->alpha2[0] = alpha2[0];
579 rd->alpha2[1] = alpha2[1];
580
581 /* This time around we fill in the rd */
582 while (country_ie_len >= 3) {
Luis R. Rodriguez02e68a32009-01-07 17:43:37 -0800583 int end_channel = 0;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800584 struct ieee80211_country_ie_triplet *triplet =
585 (struct ieee80211_country_ie_triplet *) country_ie;
586 struct ieee80211_reg_rule *reg_rule = NULL;
587 struct ieee80211_freq_range *freq_range = NULL;
588 struct ieee80211_power_rule *power_rule = NULL;
589
590 /* Must parse if dot11RegulatoryClassesRequired is true,
591 * we don't support this yet */
592 if (triplet->ext.reg_extension_id >=
593 IEEE80211_COUNTRY_EXTENSION_ID) {
594 country_ie += 3;
595 country_ie_len -= 3;
596 continue;
597 }
598
599 reg_rule = &rd->reg_rules[i];
600 freq_range = &reg_rule->freq_range;
601 power_rule = &reg_rule->power_rule;
602
603 reg_rule->flags = flags;
604
Luis R. Rodriguez02e68a32009-01-07 17:43:37 -0800605 /* 2 GHz */
606 if (triplet->chans.first_channel <= 14)
607 end_channel = triplet->chans.first_channel +
608 triplet->chans.num_channels;
609 else
Luis R. Rodriguez02e68a32009-01-07 17:43:37 -0800610 end_channel = triplet->chans.first_channel +
611 (4 * (triplet->chans.num_channels - 1));
612
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800613 /* The +10 is since the regulatory domain expects
614 * the actual band edge, not the center of freq for
615 * its start and end freqs, assuming 20 MHz bandwidth on
616 * the channels passed */
617 freq_range->start_freq_khz =
618 MHZ_TO_KHZ(ieee80211_channel_to_frequency(
619 triplet->chans.first_channel) - 10);
620 freq_range->end_freq_khz =
621 MHZ_TO_KHZ(ieee80211_channel_to_frequency(
Luis R. Rodriguez02e68a32009-01-07 17:43:37 -0800622 end_channel) + 10);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800623
624 /* Large arbitrary values, we intersect later */
625 /* Increment this if we ever support >= 40 MHz channels
626 * in IEEE 802.11 */
627 freq_range->max_bandwidth_khz = MHZ_TO_KHZ(40);
628 power_rule->max_antenna_gain = DBI_TO_MBI(100);
629 power_rule->max_eirp = DBM_TO_MBM(100);
630
631 country_ie += 3;
632 country_ie_len -= 3;
633 i++;
634
635 BUG_ON(i > NL80211_MAX_SUPP_REG_RULES);
636 }
637
638 return rd;
639}
640
641
Luis R. Rodriguez9c964772008-10-30 13:33:53 -0700642/* Helper for regdom_intersect(), this does the real
643 * mathematical intersection fun */
644static int reg_rules_intersect(
645 const struct ieee80211_reg_rule *rule1,
646 const struct ieee80211_reg_rule *rule2,
647 struct ieee80211_reg_rule *intersected_rule)
648{
649 const struct ieee80211_freq_range *freq_range1, *freq_range2;
650 struct ieee80211_freq_range *freq_range;
651 const struct ieee80211_power_rule *power_rule1, *power_rule2;
652 struct ieee80211_power_rule *power_rule;
653 u32 freq_diff;
654
655 freq_range1 = &rule1->freq_range;
656 freq_range2 = &rule2->freq_range;
657 freq_range = &intersected_rule->freq_range;
658
659 power_rule1 = &rule1->power_rule;
660 power_rule2 = &rule2->power_rule;
661 power_rule = &intersected_rule->power_rule;
662
663 freq_range->start_freq_khz = max(freq_range1->start_freq_khz,
664 freq_range2->start_freq_khz);
665 freq_range->end_freq_khz = min(freq_range1->end_freq_khz,
666 freq_range2->end_freq_khz);
667 freq_range->max_bandwidth_khz = min(freq_range1->max_bandwidth_khz,
668 freq_range2->max_bandwidth_khz);
669
670 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
671 if (freq_range->max_bandwidth_khz > freq_diff)
672 freq_range->max_bandwidth_khz = freq_diff;
673
674 power_rule->max_eirp = min(power_rule1->max_eirp,
675 power_rule2->max_eirp);
676 power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain,
677 power_rule2->max_antenna_gain);
678
679 intersected_rule->flags = (rule1->flags | rule2->flags);
680
681 if (!is_valid_reg_rule(intersected_rule))
682 return -EINVAL;
683
684 return 0;
685}
686
687/**
688 * regdom_intersect - do the intersection between two regulatory domains
689 * @rd1: first regulatory domain
690 * @rd2: second regulatory domain
691 *
692 * Use this function to get the intersection between two regulatory domains.
693 * Once completed we will mark the alpha2 for the rd as intersected, "98",
694 * as no one single alpha2 can represent this regulatory domain.
695 *
696 * Returns a pointer to the regulatory domain structure which will hold the
697 * resulting intersection of rules between rd1 and rd2. We will
698 * kzalloc() this structure for you.
699 */
700static struct ieee80211_regdomain *regdom_intersect(
701 const struct ieee80211_regdomain *rd1,
702 const struct ieee80211_regdomain *rd2)
703{
704 int r, size_of_regd;
705 unsigned int x, y;
706 unsigned int num_rules = 0, rule_idx = 0;
707 const struct ieee80211_reg_rule *rule1, *rule2;
708 struct ieee80211_reg_rule *intersected_rule;
709 struct ieee80211_regdomain *rd;
710 /* This is just a dummy holder to help us count */
711 struct ieee80211_reg_rule irule;
712
713 /* Uses the stack temporarily for counter arithmetic */
714 intersected_rule = &irule;
715
716 memset(intersected_rule, 0, sizeof(struct ieee80211_reg_rule));
717
718 if (!rd1 || !rd2)
719 return NULL;
720
721 /* First we get a count of the rules we'll need, then we actually
722 * build them. This is to so we can malloc() and free() a
723 * regdomain once. The reason we use reg_rules_intersect() here
724 * is it will return -EINVAL if the rule computed makes no sense.
725 * All rules that do check out OK are valid. */
726
727 for (x = 0; x < rd1->n_reg_rules; x++) {
728 rule1 = &rd1->reg_rules[x];
729 for (y = 0; y < rd2->n_reg_rules; y++) {
730 rule2 = &rd2->reg_rules[y];
731 if (!reg_rules_intersect(rule1, rule2,
732 intersected_rule))
733 num_rules++;
734 memset(intersected_rule, 0,
735 sizeof(struct ieee80211_reg_rule));
736 }
737 }
738
739 if (!num_rules)
740 return NULL;
741
742 size_of_regd = sizeof(struct ieee80211_regdomain) +
743 ((num_rules + 1) * sizeof(struct ieee80211_reg_rule));
744
745 rd = kzalloc(size_of_regd, GFP_KERNEL);
746 if (!rd)
747 return NULL;
748
749 for (x = 0; x < rd1->n_reg_rules; x++) {
750 rule1 = &rd1->reg_rules[x];
751 for (y = 0; y < rd2->n_reg_rules; y++) {
752 rule2 = &rd2->reg_rules[y];
753 /* This time around instead of using the stack lets
754 * write to the target rule directly saving ourselves
755 * a memcpy() */
756 intersected_rule = &rd->reg_rules[rule_idx];
757 r = reg_rules_intersect(rule1, rule2,
758 intersected_rule);
759 /* No need to memset here the intersected rule here as
760 * we're not using the stack anymore */
761 if (r)
762 continue;
763 rule_idx++;
764 }
765 }
766
767 if (rule_idx != num_rules) {
768 kfree(rd);
769 return NULL;
770 }
771
772 rd->n_reg_rules = num_rules;
773 rd->alpha2[0] = '9';
774 rd->alpha2[1] = '8';
775
776 return rd;
777}
778
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700779/* XXX: add support for the rest of enum nl80211_reg_rule_flags, we may
780 * want to just have the channel structure use these */
781static u32 map_regdom_flags(u32 rd_flags)
782{
783 u32 channel_flags = 0;
784 if (rd_flags & NL80211_RRF_PASSIVE_SCAN)
785 channel_flags |= IEEE80211_CHAN_PASSIVE_SCAN;
786 if (rd_flags & NL80211_RRF_NO_IBSS)
787 channel_flags |= IEEE80211_CHAN_NO_IBSS;
788 if (rd_flags & NL80211_RRF_DFS)
789 channel_flags |= IEEE80211_CHAN_RADAR;
790 return channel_flags;
791}
792
793/**
794 * freq_reg_info - get regulatory information for the given frequency
795 * @center_freq: Frequency in KHz for which we want regulatory information for
796 * @bandwidth: the bandwidth requirement you have in KHz, if you do not have one
797 * you can set this to 0. If this frequency is allowed we then set
798 * this value to the maximum allowed bandwidth.
799 * @reg_rule: the regulatory rule which we have for this frequency
800 *
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800801 * Use this function to get the regulatory rule for a specific frequency on
802 * a given wireless device. If the device has a specific regulatory domain
803 * it wants to follow we respect that unless a country IE has been received
804 * and processed already.
805 *
806 * Returns 0 if it was able to find a valid regulatory rule which does
807 * apply to the given center_freq otherwise it returns non-zero. It will
808 * also return -ERANGE if we determine the given center_freq does not even have
809 * a regulatory rule for a frequency range in the center_freq's band. See
810 * freq_in_rule_band() for our current definition of a band -- this is purely
811 * subjective and right now its 802.11 specific.
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700812 */
813static int freq_reg_info(u32 center_freq, u32 *bandwidth,
814 const struct ieee80211_reg_rule **reg_rule)
Johannes Berg8318d782008-01-24 19:38:38 +0100815{
816 int i;
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800817 bool band_rule_found = false;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700818 u32 max_bandwidth = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100819
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700820 if (!cfg80211_regdomain)
821 return -EINVAL;
822
823 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
824 const struct ieee80211_reg_rule *rr;
825 const struct ieee80211_freq_range *fr = NULL;
826 const struct ieee80211_power_rule *pr = NULL;
827
828 rr = &cfg80211_regdomain->reg_rules[i];
829 fr = &rr->freq_range;
830 pr = &rr->power_rule;
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800831
832 /* We only need to know if one frequency rule was
833 * was in center_freq's band, that's enough, so lets
834 * not overwrite it once found */
835 if (!band_rule_found)
836 band_rule_found = freq_in_rule_band(fr, center_freq);
837
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700838 max_bandwidth = freq_max_bandwidth(fr, center_freq);
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800839
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700840 if (max_bandwidth && *bandwidth <= max_bandwidth) {
841 *reg_rule = rr;
842 *bandwidth = max_bandwidth;
Johannes Berg8318d782008-01-24 19:38:38 +0100843 break;
844 }
845 }
846
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800847 if (!band_rule_found)
848 return -ERANGE;
849
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700850 return !max_bandwidth;
851}
852
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -0800853static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
854 unsigned int chan_idx)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700855{
856 int r;
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -0800857 u32 flags;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700858 u32 max_bandwidth = 0;
859 const struct ieee80211_reg_rule *reg_rule = NULL;
860 const struct ieee80211_power_rule *power_rule = NULL;
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -0800861 struct ieee80211_supported_band *sband;
862 struct ieee80211_channel *chan;
863
864 sband = wiphy->bands[band];
865 BUG_ON(chan_idx >= sband->n_channels);
866 chan = &sband->channels[chan_idx];
867
868 flags = chan->orig_flags;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700869
870 r = freq_reg_info(MHZ_TO_KHZ(chan->center_freq),
871 &max_bandwidth, &reg_rule);
872
873 if (r) {
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800874 /* This means no regulatory rule was found in the country IE
875 * with a frequency range on the center_freq's band, since
876 * IEEE-802.11 allows for a country IE to have a subset of the
877 * regulatory information provided in a country we ignore
878 * disabling the channel unless at least one reg rule was
879 * found on the center_freq's band. For details see this
880 * clarification:
881 *
882 * http://tinyurl.com/11d-clarification
883 */
884 if (r == -ERANGE &&
885 last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) {
886#ifdef CONFIG_CFG80211_REG_DEBUG
887 printk(KERN_DEBUG "cfg80211: Leaving channel %d MHz "
888 "intact on %s - no rule found in band on "
889 "Country IE\n",
890 chan->center_freq, wiphy_name(wiphy));
891#endif
892 } else {
893 /* In this case we know the country IE has at least one reg rule
894 * for the band so we respect its band definitions */
895#ifdef CONFIG_CFG80211_REG_DEBUG
896 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE)
897 printk(KERN_DEBUG "cfg80211: Disabling "
898 "channel %d MHz on %s due to "
899 "Country IE\n",
900 chan->center_freq, wiphy_name(wiphy));
901#endif
902 flags |= IEEE80211_CHAN_DISABLED;
903 chan->flags = flags;
904 }
Johannes Berg8318d782008-01-24 19:38:38 +0100905 return;
906 }
907
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700908 power_rule = &reg_rule->power_rule;
909
910 chan->flags = flags | map_regdom_flags(reg_rule->flags);
Johannes Berg8318d782008-01-24 19:38:38 +0100911 chan->max_antenna_gain = min(chan->orig_mag,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700912 (int) MBI_TO_DBI(power_rule->max_antenna_gain));
913 chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth);
John W. Linville253898c2008-04-03 15:32:54 -0400914 if (chan->orig_mpwr)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700915 chan->max_power = min(chan->orig_mpwr,
916 (int) MBM_TO_DBM(power_rule->max_eirp));
John W. Linville253898c2008-04-03 15:32:54 -0400917 else
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700918 chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp);
Johannes Berg8318d782008-01-24 19:38:38 +0100919}
920
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -0800921static void handle_band(struct wiphy *wiphy, enum ieee80211_band band)
Johannes Berg8318d782008-01-24 19:38:38 +0100922{
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -0800923 unsigned int i;
924 struct ieee80211_supported_band *sband;
925
926 BUG_ON(!wiphy->bands[band]);
927 sband = wiphy->bands[band];
Johannes Berg8318d782008-01-24 19:38:38 +0100928
929 for (i = 0; i < sband->n_channels; i++)
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -0800930 handle_channel(wiphy, band, i);
Johannes Berg8318d782008-01-24 19:38:38 +0100931}
932
Luis R. Rodriguez14b98152008-11-12 14:22:03 -0800933static bool ignore_reg_update(struct wiphy *wiphy, enum reg_set_by setby)
934{
935 if (!last_request)
936 return true;
937 if (setby == REGDOM_SET_BY_CORE &&
938 wiphy->fw_handles_regulatory)
939 return true;
940 return false;
941}
942
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700943static void update_all_wiphy_regulatory(enum reg_set_by setby)
944{
945 struct cfg80211_registered_device *drv;
946
947 list_for_each_entry(drv, &cfg80211_drv_list, list)
Luis R. Rodriguez14b98152008-11-12 14:22:03 -0800948 if (!ignore_reg_update(&drv->wiphy, setby))
949 wiphy_update_regulatory(&drv->wiphy, setby);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700950}
951
952void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby)
Johannes Berg8318d782008-01-24 19:38:38 +0100953{
954 enum ieee80211_band band;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700955 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg8318d782008-01-24 19:38:38 +0100956 if (wiphy->bands[band])
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -0800957 handle_band(wiphy, band);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700958 if (wiphy->reg_notifier)
959 wiphy->reg_notifier(wiphy, setby);
960 }
961}
962
Luis R. Rodriguez9c964772008-10-30 13:33:53 -0700963/* Return value which can be used by ignore_request() to indicate
964 * it has been determined we should intersect two regulatory domains */
965#define REG_INTERSECT 1
966
Johannes Berg84fa4f42008-10-24 20:32:23 +0200967/* This has the logic which determines when a new request
968 * should be ignored. */
969static int ignore_request(struct wiphy *wiphy, enum reg_set_by set_by,
970 const char *alpha2)
971{
972 /* All initial requests are respected */
973 if (!last_request)
974 return 0;
975
976 switch (set_by) {
977 case REGDOM_SET_BY_INIT:
978 return -EINVAL;
979 case REGDOM_SET_BY_CORE:
980 /*
981 * Always respect new wireless core hints, should only happen
982 * when updating the world regulatory domain at init.
983 */
984 return 0;
985 case REGDOM_SET_BY_COUNTRY_IE:
986 if (unlikely(!is_an_alpha2(alpha2)))
987 return -EINVAL;
988 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) {
989 if (last_request->wiphy != wiphy) {
990 /*
991 * Two cards with two APs claiming different
992 * different Country IE alpha2s. We could
993 * intersect them, but that seems unlikely
994 * to be correct. Reject second one for now.
995 */
996 if (!alpha2_equal(alpha2,
997 cfg80211_regdomain->alpha2))
998 return -EOPNOTSUPP;
999 return -EALREADY;
1000 }
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001001 /* Two consecutive Country IE hints on the same wiphy.
1002 * This should be picked up early by the driver/stack */
1003 if (WARN_ON(!alpha2_equal(cfg80211_regdomain->alpha2,
1004 alpha2)))
Johannes Berg84fa4f42008-10-24 20:32:23 +02001005 return 0;
1006 return -EALREADY;
1007 }
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001008 return REG_INTERSECT;
Johannes Berg84fa4f42008-10-24 20:32:23 +02001009 case REGDOM_SET_BY_DRIVER:
1010 if (last_request->initiator == REGDOM_SET_BY_DRIVER)
1011 return -EALREADY;
1012 return 0;
1013 case REGDOM_SET_BY_USER:
Johannes Berg84fa4f42008-10-24 20:32:23 +02001014 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE)
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001015 return REG_INTERSECT;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001016 /* If the user knows better the user should set the regdom
1017 * to their country before the IE is picked up */
1018 if (last_request->initiator == REGDOM_SET_BY_USER &&
1019 last_request->intersect)
1020 return -EOPNOTSUPP;
Johannes Berg84fa4f42008-10-24 20:32:23 +02001021 return 0;
1022 }
1023
1024 return -EINVAL;
1025}
1026
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001027/* Caller must hold &cfg80211_drv_mutex */
1028int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by,
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001029 const char *alpha2,
1030 u32 country_ie_checksum,
1031 enum environment_cap env)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001032{
1033 struct regulatory_request *request;
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001034 bool intersect = false;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001035 int r = 0;
1036
Johannes Bergbe3d4812008-10-24 20:32:21 +02001037 r = ignore_request(wiphy, set_by, alpha2);
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001038
1039 if (r == REG_INTERSECT)
1040 intersect = true;
1041 else if (r)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001042 return r;
1043
Luis R. Rodriguez5203cdb2008-11-12 14:21:56 -08001044 request = kzalloc(sizeof(struct regulatory_request),
1045 GFP_KERNEL);
1046 if (!request)
1047 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001048
Luis R. Rodriguez5203cdb2008-11-12 14:21:56 -08001049 request->alpha2[0] = alpha2[0];
1050 request->alpha2[1] = alpha2[1];
1051 request->initiator = set_by;
1052 request->wiphy = wiphy;
1053 request->intersect = intersect;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001054 request->country_ie_checksum = country_ie_checksum;
1055 request->country_ie_env = env;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001056
Luis R. Rodriguez5203cdb2008-11-12 14:21:56 -08001057 kfree(last_request);
1058 last_request = request;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001059 /*
1060 * Note: When CONFIG_WIRELESS_OLD_REGULATORY is enabled
1061 * AND if CRDA is NOT present nothing will happen, if someone
1062 * wants to bother with 11d with OLD_REG you can add a timer.
1063 * If after x amount of time nothing happens you can call:
1064 *
1065 * return set_regdom(country_ie_regdomain);
1066 *
1067 * to intersect with the static rd
1068 */
Luis R. Rodriguez02ba0b32008-11-12 14:22:00 -08001069 return call_crda(alpha2);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001070}
1071
Johannes Bergbe3d4812008-10-24 20:32:21 +02001072void regulatory_hint(struct wiphy *wiphy, const char *alpha2)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001073{
Johannes Bergbe3d4812008-10-24 20:32:21 +02001074 BUG_ON(!alpha2);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001075
1076 mutex_lock(&cfg80211_drv_mutex);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001077 __regulatory_hint(wiphy, REGDOM_SET_BY_DRIVER, alpha2, 0, ENVIRON_ANY);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001078 mutex_unlock(&cfg80211_drv_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001079}
1080EXPORT_SYMBOL(regulatory_hint);
1081
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001082static bool reg_same_country_ie_hint(struct wiphy *wiphy,
1083 u32 country_ie_checksum)
1084{
1085 if (!last_request->wiphy)
1086 return false;
1087 if (likely(last_request->wiphy != wiphy))
1088 return !country_ie_integrity_changes(country_ie_checksum);
1089 /* We should not have let these through at this point, they
1090 * should have been picked up earlier by the first alpha2 check
1091 * on the device */
1092 if (WARN_ON(!country_ie_integrity_changes(country_ie_checksum)))
1093 return true;
1094 return false;
1095}
1096
1097void regulatory_hint_11d(struct wiphy *wiphy,
1098 u8 *country_ie,
1099 u8 country_ie_len)
1100{
1101 struct ieee80211_regdomain *rd = NULL;
1102 char alpha2[2];
1103 u32 checksum = 0;
1104 enum environment_cap env = ENVIRON_ANY;
1105
Johannes Berg0f70f392008-12-01 18:13:05 +01001106 if (!last_request)
1107 return;
1108
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001109 mutex_lock(&cfg80211_drv_mutex);
1110
1111 /* IE len must be evenly divisible by 2 */
1112 if (country_ie_len & 0x01)
1113 goto out;
1114
1115 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1116 goto out;
1117
1118 /* Pending country IE processing, this can happen after we
1119 * call CRDA and wait for a response if a beacon was received before
1120 * we were able to process the last regulatory_hint_11d() call */
1121 if (country_ie_regdomain)
1122 goto out;
1123
1124 alpha2[0] = country_ie[0];
1125 alpha2[1] = country_ie[1];
1126
1127 if (country_ie[2] == 'I')
1128 env = ENVIRON_INDOOR;
1129 else if (country_ie[2] == 'O')
1130 env = ENVIRON_OUTDOOR;
1131
1132 /* We will run this for *every* beacon processed for the BSSID, so
1133 * we optimize an early check to exit out early if we don't have to
1134 * do anything */
1135 if (likely(last_request->wiphy)) {
1136 struct cfg80211_registered_device *drv_last_ie;
1137
1138 drv_last_ie = wiphy_to_dev(last_request->wiphy);
1139
1140 /* Lets keep this simple -- we trust the first AP
1141 * after we intersect with CRDA */
1142 if (likely(last_request->wiphy == wiphy)) {
1143 /* Ignore IEs coming in on this wiphy with
1144 * the same alpha2 and environment cap */
1145 if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2,
1146 alpha2) &&
1147 env == drv_last_ie->env)) {
1148 goto out;
1149 }
1150 /* the wiphy moved on to another BSSID or the AP
1151 * was reconfigured. XXX: We need to deal with the
1152 * case where the user suspends and goes to goes
1153 * to another country, and then gets IEs from an
1154 * AP with different settings */
1155 goto out;
1156 } else {
1157 /* Ignore IEs coming in on two separate wiphys with
1158 * the same alpha2 and environment cap */
1159 if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2,
1160 alpha2) &&
1161 env == drv_last_ie->env)) {
1162 goto out;
1163 }
1164 /* We could potentially intersect though */
1165 goto out;
1166 }
1167 }
1168
1169 rd = country_ie_2_rd(country_ie, country_ie_len, &checksum);
1170 if (!rd)
1171 goto out;
1172
1173 /* This will not happen right now but we leave it here for the
1174 * the future when we want to add suspend/resume support and having
1175 * the user move to another country after doing so, or having the user
1176 * move to another AP. Right now we just trust the first AP. This is why
1177 * this is marked as likley(). If we hit this before we add this support
1178 * we want to be informed of it as it would indicate a mistake in the
1179 * current design */
1180 if (likely(WARN_ON(reg_same_country_ie_hint(wiphy, checksum))))
1181 goto out;
1182
1183 /* We keep this around for when CRDA comes back with a response so
1184 * we can intersect with that */
1185 country_ie_regdomain = rd;
1186
1187 __regulatory_hint(wiphy, REGDOM_SET_BY_COUNTRY_IE,
1188 country_ie_regdomain->alpha2, checksum, env);
1189
1190out:
1191 mutex_unlock(&cfg80211_drv_mutex);
1192}
1193EXPORT_SYMBOL(regulatory_hint_11d);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001194
Johannes Berga3d2eaf2008-09-15 11:10:52 +02001195static void print_rd_rules(const struct ieee80211_regdomain *rd)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001196{
1197 unsigned int i;
Johannes Berga3d2eaf2008-09-15 11:10:52 +02001198 const struct ieee80211_reg_rule *reg_rule = NULL;
1199 const struct ieee80211_freq_range *freq_range = NULL;
1200 const struct ieee80211_power_rule *power_rule = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001201
1202 printk(KERN_INFO "\t(start_freq - end_freq @ bandwidth), "
1203 "(max_antenna_gain, max_eirp)\n");
1204
1205 for (i = 0; i < rd->n_reg_rules; i++) {
1206 reg_rule = &rd->reg_rules[i];
1207 freq_range = &reg_rule->freq_range;
1208 power_rule = &reg_rule->power_rule;
1209
1210 /* There may not be documentation for max antenna gain
1211 * in certain regions */
1212 if (power_rule->max_antenna_gain)
1213 printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), "
1214 "(%d mBi, %d mBm)\n",
1215 freq_range->start_freq_khz,
1216 freq_range->end_freq_khz,
1217 freq_range->max_bandwidth_khz,
1218 power_rule->max_antenna_gain,
1219 power_rule->max_eirp);
1220 else
1221 printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), "
1222 "(N/A, %d mBm)\n",
1223 freq_range->start_freq_khz,
1224 freq_range->end_freq_khz,
1225 freq_range->max_bandwidth_khz,
1226 power_rule->max_eirp);
1227 }
1228}
1229
Johannes Berga3d2eaf2008-09-15 11:10:52 +02001230static void print_regdomain(const struct ieee80211_regdomain *rd)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001231{
1232
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001233 if (is_intersected_alpha2(rd->alpha2)) {
1234 struct wiphy *wiphy = NULL;
1235 struct cfg80211_registered_device *drv;
1236
1237 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) {
1238 if (last_request->wiphy) {
1239 wiphy = last_request->wiphy;
1240 drv = wiphy_to_dev(wiphy);
1241 printk(KERN_INFO "cfg80211: Current regulatory "
1242 "domain updated by AP to: %c%c\n",
1243 drv->country_ie_alpha2[0],
1244 drv->country_ie_alpha2[1]);
1245 } else
1246 printk(KERN_INFO "cfg80211: Current regulatory "
1247 "domain intersected: \n");
1248 } else
1249 printk(KERN_INFO "cfg80211: Current regulatory "
1250 "intersected: \n");
1251 } else if (is_world_regdom(rd->alpha2))
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001252 printk(KERN_INFO "cfg80211: World regulatory "
1253 "domain updated:\n");
1254 else {
1255 if (is_unknown_alpha2(rd->alpha2))
1256 printk(KERN_INFO "cfg80211: Regulatory domain "
1257 "changed to driver built-in settings "
1258 "(unknown country)\n");
1259 else
1260 printk(KERN_INFO "cfg80211: Regulatory domain "
1261 "changed to country: %c%c\n",
1262 rd->alpha2[0], rd->alpha2[1]);
1263 }
1264 print_rd_rules(rd);
1265}
1266
Johannes Berg2df78162008-10-28 16:49:41 +01001267static void print_regdomain_info(const struct ieee80211_regdomain *rd)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001268{
1269 printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n",
1270 rd->alpha2[0], rd->alpha2[1]);
1271 print_rd_rules(rd);
1272}
1273
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001274#ifdef CONFIG_CFG80211_REG_DEBUG
1275static void reg_country_ie_process_debug(
1276 const struct ieee80211_regdomain *rd,
1277 const struct ieee80211_regdomain *country_ie_regdomain,
1278 const struct ieee80211_regdomain *intersected_rd)
1279{
1280 printk(KERN_DEBUG "cfg80211: Received country IE:\n");
1281 print_regdomain_info(country_ie_regdomain);
1282 printk(KERN_DEBUG "cfg80211: CRDA thinks this should applied:\n");
1283 print_regdomain_info(rd);
1284 if (intersected_rd) {
1285 printk(KERN_DEBUG "cfg80211: We intersect both of these "
1286 "and get:\n");
1287 print_regdomain_info(rd);
1288 return;
1289 }
1290 printk(KERN_DEBUG "cfg80211: Intersection between both failed\n");
1291}
1292#else
1293static inline void reg_country_ie_process_debug(
1294 const struct ieee80211_regdomain *rd,
1295 const struct ieee80211_regdomain *country_ie_regdomain,
1296 const struct ieee80211_regdomain *intersected_rd)
1297{
1298}
1299#endif
1300
Johannes Bergd2372b32008-10-24 20:32:20 +02001301/* Takes ownership of rd only if it doesn't fail */
Johannes Berga3d2eaf2008-09-15 11:10:52 +02001302static int __set_regdom(const struct ieee80211_regdomain *rd)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001303{
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001304 const struct ieee80211_regdomain *intersected_rd = NULL;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001305 struct cfg80211_registered_device *drv = NULL;
1306 struct wiphy *wiphy = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001307 /* Some basic sanity checks first */
1308
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001309 if (is_world_regdom(rd->alpha2)) {
Johannes Bergf6037d02008-10-21 11:01:33 +02001310 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001311 return -EINVAL;
1312 update_world_regdomain(rd);
1313 return 0;
1314 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001315
1316 if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) &&
1317 !is_unknown_alpha2(rd->alpha2))
1318 return -EINVAL;
1319
Johannes Bergf6037d02008-10-21 11:01:33 +02001320 if (!last_request)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001321 return -EINVAL;
1322
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001323 /* Lets only bother proceeding on the same alpha2 if the current
1324 * rd is non static (it means CRDA was present and was used last)
1325 * and the pending request came in from a country IE */
1326 if (last_request->initiator != REGDOM_SET_BY_COUNTRY_IE) {
1327 /* If someone else asked us to change the rd lets only bother
1328 * checking if the alpha2 changes if CRDA was already called */
1329 if (!is_old_static_regdom(cfg80211_regdomain) &&
1330 !regdom_changed(rd->alpha2))
1331 return -EINVAL;
1332 }
1333
1334 wiphy = last_request->wiphy;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001335
1336 /* Now lets set the regulatory domain, update all driver channels
1337 * and finally inform them of what we have done, in case they want
1338 * to review or adjust their own settings based on their own
1339 * internal EEPROM data */
1340
Johannes Bergf6037d02008-10-21 11:01:33 +02001341 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001342 return -EINVAL;
1343
Luis R. Rodriguez8375af32008-11-12 14:21:57 -08001344 if (!is_valid_rd(rd)) {
1345 printk(KERN_ERR "cfg80211: Invalid "
1346 "regulatory domain detected:\n");
1347 print_regdomain_info(rd);
1348 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001349 }
1350
Luis R. Rodriguezb8295ac2008-11-12 14:21:58 -08001351 if (!last_request->intersect) {
1352 reset_regdomains();
1353 cfg80211_regdomain = rd;
1354 return 0;
1355 }
1356
1357 /* Intersection requires a bit more work */
1358
1359 if (last_request->initiator != REGDOM_SET_BY_COUNTRY_IE) {
1360
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001361 intersected_rd = regdom_intersect(rd, cfg80211_regdomain);
1362 if (!intersected_rd)
1363 return -EINVAL;
Luis R. Rodriguezb8295ac2008-11-12 14:21:58 -08001364
1365 /* We can trash what CRDA provided now */
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001366 kfree(rd);
Luis R. Rodriguezb8295ac2008-11-12 14:21:58 -08001367 rd = NULL;
1368
1369 reset_regdomains();
1370 cfg80211_regdomain = intersected_rd;
1371
1372 return 0;
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001373 }
1374
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001375 /*
1376 * Country IE requests are handled a bit differently, we intersect
1377 * the country IE rd with what CRDA believes that country should have
1378 */
1379
1380 BUG_ON(!country_ie_regdomain);
1381
1382 if (rd != country_ie_regdomain) {
1383 /* Intersect what CRDA returned and our what we
1384 * had built from the Country IE received */
1385
1386 intersected_rd = regdom_intersect(rd, country_ie_regdomain);
1387
1388 reg_country_ie_process_debug(rd, country_ie_regdomain,
1389 intersected_rd);
1390
1391 kfree(country_ie_regdomain);
1392 country_ie_regdomain = NULL;
1393 } else {
1394 /* This would happen when CRDA was not present and
1395 * OLD_REGULATORY was enabled. We intersect our Country
1396 * IE rd and what was set on cfg80211 originally */
1397 intersected_rd = regdom_intersect(rd, cfg80211_regdomain);
1398 }
1399
1400 if (!intersected_rd)
1401 return -EINVAL;
1402
1403 drv = wiphy_to_dev(wiphy);
1404
1405 drv->country_ie_alpha2[0] = rd->alpha2[0];
1406 drv->country_ie_alpha2[1] = rd->alpha2[1];
1407 drv->env = last_request->country_ie_env;
1408
1409 BUG_ON(intersected_rd == rd);
1410
1411 kfree(rd);
1412 rd = NULL;
1413
Luis R. Rodriguezb8295ac2008-11-12 14:21:58 -08001414 reset_regdomains();
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001415 cfg80211_regdomain = intersected_rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001416
1417 return 0;
1418}
1419
1420
1421/* Use this call to set the current regulatory domain. Conflicts with
1422 * multiple drivers can be ironed out later. Caller must've already
Johannes Bergd2372b32008-10-24 20:32:20 +02001423 * kmalloc'd the rd structure. Caller must hold cfg80211_drv_mutex */
Johannes Berga3d2eaf2008-09-15 11:10:52 +02001424int set_regdom(const struct ieee80211_regdomain *rd)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001425{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001426 int r;
1427
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001428 /* Note that this doesn't update the wiphys, this is done below */
1429 r = __set_regdom(rd);
Johannes Bergd2372b32008-10-24 20:32:20 +02001430 if (r) {
1431 kfree(rd);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001432 return r;
Johannes Bergd2372b32008-10-24 20:32:20 +02001433 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001434
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001435 /* This would make this whole thing pointless */
Luis R. Rodrigueza01ddaf2008-11-12 14:21:59 -08001436 if (!last_request->intersect)
1437 BUG_ON(rd != cfg80211_regdomain);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001438
1439 /* update all wiphys now with the new established regulatory domain */
Johannes Bergf6037d02008-10-21 11:01:33 +02001440 update_all_wiphy_regulatory(last_request->initiator);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001441
Luis R. Rodrigueza01ddaf2008-11-12 14:21:59 -08001442 print_regdomain(cfg80211_regdomain);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001443
1444 return r;
1445}
1446
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001447/* Caller must hold cfg80211_drv_mutex */
1448void reg_device_remove(struct wiphy *wiphy)
1449{
Johannes Berg4a4f4d82008-12-01 12:07:56 +01001450 if (!last_request || !last_request->wiphy)
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001451 return;
1452 if (last_request->wiphy != wiphy)
1453 return;
1454 last_request->wiphy = NULL;
1455 last_request->country_ie_env = ENVIRON_ANY;
1456}
1457
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001458int regulatory_init(void)
1459{
Johannes Berg734366d2008-09-15 10:56:48 +02001460 int err;
1461
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001462 reg_pdev = platform_device_register_simple("regulatory", 0, NULL, 0);
1463 if (IS_ERR(reg_pdev))
1464 return PTR_ERR(reg_pdev);
Johannes Berg734366d2008-09-15 10:56:48 +02001465
1466#ifdef CONFIG_WIRELESS_OLD_REGULATORY
Johannes Berga3d2eaf2008-09-15 11:10:52 +02001467 cfg80211_regdomain = static_regdom(ieee80211_regdom);
Johannes Berg734366d2008-09-15 10:56:48 +02001468
Johannes Berg942b25c2008-09-15 11:26:47 +02001469 printk(KERN_INFO "cfg80211: Using static regulatory domain info\n");
Johannes Berg734366d2008-09-15 10:56:48 +02001470 print_regdomain_info(cfg80211_regdomain);
1471 /* The old code still requests for a new regdomain and if
1472 * you have CRDA you get it updated, otherwise you get
1473 * stuck with the static values. We ignore "EU" code as
1474 * that is not a valid ISO / IEC 3166 alpha2 */
Johannes Bergac9440a2008-10-21 11:08:27 +02001475 if (ieee80211_regdom[0] != 'E' || ieee80211_regdom[1] != 'U')
Johannes Berg734366d2008-09-15 10:56:48 +02001476 err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE,
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001477 ieee80211_regdom, 0, ENVIRON_ANY);
Johannes Berg734366d2008-09-15 10:56:48 +02001478#else
Johannes Berga3d2eaf2008-09-15 11:10:52 +02001479 cfg80211_regdomain = cfg80211_world_regdom;
Johannes Berg734366d2008-09-15 10:56:48 +02001480
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001481 err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE, "00", 0, ENVIRON_ANY);
Johannes Berg734366d2008-09-15 10:56:48 +02001482 if (err)
1483 printk(KERN_ERR "cfg80211: calling CRDA failed - "
1484 "unable to update world regulatory domain, "
1485 "using static definition\n");
1486#endif
1487
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001488 return 0;
1489}
1490
1491void regulatory_exit(void)
1492{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001493 mutex_lock(&cfg80211_drv_mutex);
Johannes Berg734366d2008-09-15 10:56:48 +02001494
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001495 reset_regdomains();
Johannes Berg734366d2008-09-15 10:56:48 +02001496
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001497 kfree(country_ie_regdomain);
1498 country_ie_regdomain = NULL;
1499
Johannes Bergf6037d02008-10-21 11:01:33 +02001500 kfree(last_request);
1501
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001502 platform_device_unregister(reg_pdev);
Johannes Berg734366d2008-09-15 10:56:48 +02001503
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001504 mutex_unlock(&cfg80211_drv_mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01001505}