blob: 68fde6d33dc36c1f0c48c41435df059802bc27dc [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/* Receipt of information from last regulatory request */
Johannes Bergf6037d02008-10-21 11:01:33 +020046static struct regulatory_request *last_request;
Johannes Berg734366d2008-09-15 10:56:48 +020047
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070048/* To trigger userspace events */
49static struct platform_device *reg_pdev;
Johannes Berg8318d782008-01-24 19:38:38 +010050
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070051/* Keep the ordering from large to small */
52static u32 supported_bandwidths[] = {
53 MHZ_TO_KHZ(40),
54 MHZ_TO_KHZ(20),
Johannes Berg8318d782008-01-24 19:38:38 +010055};
56
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -050057/*
58 * Central wireless core regulatory domains, we only need two,
Johannes Berg734366d2008-09-15 10:56:48 +020059 * the current one and a world regulatory domain in case we have no
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -050060 * information to give us an alpha2
61 */
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080062const struct ieee80211_regdomain *cfg80211_regdomain;
Johannes Berg734366d2008-09-15 10:56:48 +020063
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -050064/*
65 * We use this as a place for the rd structure built from the
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -080066 * last parsed country IE to rest until CRDA gets back to us with
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -050067 * what it thinks should apply for the same country
68 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -080069static const struct ieee80211_regdomain *country_ie_regdomain;
70
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -050071/* Used to queue up regulatory hints */
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -050072static LIST_HEAD(reg_requests_list);
73static spinlock_t reg_requests_lock;
74
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -050075/* Used to queue up beacon hints for review */
76static LIST_HEAD(reg_pending_beacons);
77static spinlock_t reg_pending_beacons_lock;
78
79/* Used to keep track of processed beacon hints */
80static LIST_HEAD(reg_beacon_list);
81
82struct reg_beacon {
83 struct list_head list;
84 struct ieee80211_channel chan;
85};
86
Johannes Berg734366d2008-09-15 10:56:48 +020087/* We keep a static world regulatory domain in case of the absence of CRDA */
88static const struct ieee80211_regdomain world_regdom = {
Luis R. Rodriguez611b6a82009-03-05 21:19:21 -080089 .n_reg_rules = 5,
Johannes Berg734366d2008-09-15 10:56:48 +020090 .alpha2 = "00",
91 .reg_rules = {
Luis R. Rodriguez68798a62009-02-21 00:20:37 -050092 /* IEEE 802.11b/g, channels 1..11 */
93 REG_RULE(2412-10, 2462+10, 40, 6, 20, 0),
Luis R. Rodriguez611b6a82009-03-05 21:19:21 -080094 /* IEEE 802.11b/g, channels 12..13. No HT40
95 * channel fits here. */
96 REG_RULE(2467-10, 2472+10, 20, 6, 20,
Luis R. Rodriguez3fc71f72009-02-21 00:20:38 -050097 NL80211_RRF_PASSIVE_SCAN |
98 NL80211_RRF_NO_IBSS),
Luis R. Rodriguez611b6a82009-03-05 21:19:21 -080099 /* IEEE 802.11 channel 14 - Only JP enables
100 * this and for 802.11b only */
101 REG_RULE(2484-10, 2484+10, 20, 6, 20,
102 NL80211_RRF_PASSIVE_SCAN |
103 NL80211_RRF_NO_IBSS |
104 NL80211_RRF_NO_OFDM),
105 /* IEEE 802.11a, channel 36..48 */
Luis R. Rodriguezec329ac2009-03-05 21:19:22 -0800106 REG_RULE(5180-10, 5240+10, 40, 6, 20,
Luis R. Rodriguez611b6a82009-03-05 21:19:21 -0800107 NL80211_RRF_PASSIVE_SCAN |
108 NL80211_RRF_NO_IBSS),
Luis R. Rodriguez3fc71f72009-02-21 00:20:38 -0500109
110 /* NB: 5260 MHz - 5700 MHz requies DFS */
111
112 /* IEEE 802.11a, channel 149..165 */
Luis R. Rodriguezec329ac2009-03-05 21:19:22 -0800113 REG_RULE(5745-10, 5825+10, 40, 6, 20,
Luis R. Rodriguez3fc71f72009-02-21 00:20:38 -0500114 NL80211_RRF_PASSIVE_SCAN |
115 NL80211_RRF_NO_IBSS),
Johannes Berg734366d2008-09-15 10:56:48 +0200116 }
117};
118
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200119static const struct ieee80211_regdomain *cfg80211_world_regdom =
120 &world_regdom;
Johannes Berg734366d2008-09-15 10:56:48 +0200121
122#ifdef CONFIG_WIRELESS_OLD_REGULATORY
123static char *ieee80211_regdom = "US";
124module_param(ieee80211_regdom, charp, 0444);
125MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
126
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500127/*
128 * We assume 40 MHz bandwidth for the old regulatory work.
Johannes Berg734366d2008-09-15 10:56:48 +0200129 * We make emphasis we are using the exact same frequencies
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500130 * as before
131 */
Johannes Berg734366d2008-09-15 10:56:48 +0200132
133static const struct ieee80211_regdomain us_regdom = {
134 .n_reg_rules = 6,
135 .alpha2 = "US",
136 .reg_rules = {
137 /* IEEE 802.11b/g, channels 1..11 */
138 REG_RULE(2412-10, 2462+10, 40, 6, 27, 0),
139 /* IEEE 802.11a, channel 36 */
140 REG_RULE(5180-10, 5180+10, 40, 6, 23, 0),
141 /* IEEE 802.11a, channel 40 */
142 REG_RULE(5200-10, 5200+10, 40, 6, 23, 0),
143 /* IEEE 802.11a, channel 44 */
144 REG_RULE(5220-10, 5220+10, 40, 6, 23, 0),
145 /* IEEE 802.11a, channels 48..64 */
146 REG_RULE(5240-10, 5320+10, 40, 6, 23, 0),
147 /* IEEE 802.11a, channels 149..165, outdoor */
148 REG_RULE(5745-10, 5825+10, 40, 6, 30, 0),
149 }
150};
151
152static const struct ieee80211_regdomain jp_regdom = {
153 .n_reg_rules = 3,
154 .alpha2 = "JP",
155 .reg_rules = {
156 /* IEEE 802.11b/g, channels 1..14 */
157 REG_RULE(2412-10, 2484+10, 40, 6, 20, 0),
158 /* IEEE 802.11a, channels 34..48 */
159 REG_RULE(5170-10, 5240+10, 40, 6, 20,
160 NL80211_RRF_PASSIVE_SCAN),
161 /* IEEE 802.11a, channels 52..64 */
162 REG_RULE(5260-10, 5320+10, 40, 6, 20,
163 NL80211_RRF_NO_IBSS |
164 NL80211_RRF_DFS),
165 }
166};
167
168static const struct ieee80211_regdomain eu_regdom = {
169 .n_reg_rules = 6,
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500170 /*
171 * This alpha2 is bogus, we leave it here just for stupid
172 * backward compatibility
173 */
Johannes Berg734366d2008-09-15 10:56:48 +0200174 .alpha2 = "EU",
175 .reg_rules = {
176 /* IEEE 802.11b/g, channels 1..13 */
177 REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
178 /* IEEE 802.11a, channel 36 */
179 REG_RULE(5180-10, 5180+10, 40, 6, 23,
180 NL80211_RRF_PASSIVE_SCAN),
181 /* IEEE 802.11a, channel 40 */
182 REG_RULE(5200-10, 5200+10, 40, 6, 23,
183 NL80211_RRF_PASSIVE_SCAN),
184 /* IEEE 802.11a, channel 44 */
185 REG_RULE(5220-10, 5220+10, 40, 6, 23,
186 NL80211_RRF_PASSIVE_SCAN),
187 /* IEEE 802.11a, channels 48..64 */
188 REG_RULE(5240-10, 5320+10, 40, 6, 20,
189 NL80211_RRF_NO_IBSS |
190 NL80211_RRF_DFS),
191 /* IEEE 802.11a, channels 100..140 */
192 REG_RULE(5500-10, 5700+10, 40, 6, 30,
193 NL80211_RRF_NO_IBSS |
194 NL80211_RRF_DFS),
195 }
196};
197
198static const struct ieee80211_regdomain *static_regdom(char *alpha2)
199{
200 if (alpha2[0] == 'U' && alpha2[1] == 'S')
201 return &us_regdom;
202 if (alpha2[0] == 'J' && alpha2[1] == 'P')
203 return &jp_regdom;
204 if (alpha2[0] == 'E' && alpha2[1] == 'U')
205 return &eu_regdom;
206 /* Default, as per the old rules */
207 return &us_regdom;
208}
209
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200210static bool is_old_static_regdom(const struct ieee80211_regdomain *rd)
Johannes Berg734366d2008-09-15 10:56:48 +0200211{
212 if (rd == &us_regdom || rd == &jp_regdom || rd == &eu_regdom)
213 return true;
214 return false;
215}
Johannes Berg734366d2008-09-15 10:56:48 +0200216#else
Johannes Berg942b25c2008-09-15 11:26:47 +0200217static inline bool is_old_static_regdom(const struct ieee80211_regdomain *rd)
218{
219 return false;
220}
221#endif
222
Johannes Berg734366d2008-09-15 10:56:48 +0200223static void reset_regdomains(void)
224{
Johannes Berg942b25c2008-09-15 11:26:47 +0200225 /* avoid freeing static information or freeing something twice */
226 if (cfg80211_regdomain == cfg80211_world_regdom)
227 cfg80211_regdomain = NULL;
228 if (cfg80211_world_regdom == &world_regdom)
229 cfg80211_world_regdom = NULL;
230 if (cfg80211_regdomain == &world_regdom)
231 cfg80211_regdomain = NULL;
232 if (is_old_static_regdom(cfg80211_regdomain))
233 cfg80211_regdomain = NULL;
234
235 kfree(cfg80211_regdomain);
236 kfree(cfg80211_world_regdom);
Johannes Berg734366d2008-09-15 10:56:48 +0200237
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200238 cfg80211_world_regdom = &world_regdom;
Johannes Berg734366d2008-09-15 10:56:48 +0200239 cfg80211_regdomain = NULL;
240}
241
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500242/*
243 * Dynamic world regulatory domain requested by the wireless
244 * core upon initialization
245 */
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200246static void update_world_regdomain(const struct ieee80211_regdomain *rd)
Johannes Berg734366d2008-09-15 10:56:48 +0200247{
Johannes Bergf6037d02008-10-21 11:01:33 +0200248 BUG_ON(!last_request);
Johannes Berg734366d2008-09-15 10:56:48 +0200249
250 reset_regdomains();
251
252 cfg80211_world_regdom = rd;
253 cfg80211_regdomain = rd;
254}
Johannes Berg734366d2008-09-15 10:56:48 +0200255
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200256bool is_world_regdom(const char *alpha2)
Johannes Berg8318d782008-01-24 19:38:38 +0100257{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700258 if (!alpha2)
259 return false;
260 if (alpha2[0] == '0' && alpha2[1] == '0')
261 return true;
262 return false;
Johannes Berg8318d782008-01-24 19:38:38 +0100263}
264
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200265static bool is_alpha2_set(const char *alpha2)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700266{
267 if (!alpha2)
268 return false;
269 if (alpha2[0] != 0 && alpha2[1] != 0)
270 return true;
271 return false;
272}
Johannes Berg8318d782008-01-24 19:38:38 +0100273
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700274static bool is_alpha_upper(char letter)
275{
276 /* ASCII A - Z */
277 if (letter >= 65 && letter <= 90)
278 return true;
279 return false;
280}
281
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200282static bool is_unknown_alpha2(const char *alpha2)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700283{
284 if (!alpha2)
285 return false;
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500286 /*
287 * Special case where regulatory domain was built by driver
288 * but a specific alpha2 cannot be determined
289 */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700290 if (alpha2[0] == '9' && alpha2[1] == '9')
291 return true;
292 return false;
293}
294
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800295static bool is_intersected_alpha2(const char *alpha2)
296{
297 if (!alpha2)
298 return false;
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500299 /*
300 * Special case where regulatory domain is the
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800301 * result of an intersection between two regulatory domain
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500302 * structures
303 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800304 if (alpha2[0] == '9' && alpha2[1] == '8')
305 return true;
306 return false;
307}
308
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200309static bool is_an_alpha2(const char *alpha2)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700310{
311 if (!alpha2)
312 return false;
313 if (is_alpha_upper(alpha2[0]) && is_alpha_upper(alpha2[1]))
314 return true;
315 return false;
316}
317
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200318static bool alpha2_equal(const char *alpha2_x, const char *alpha2_y)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700319{
320 if (!alpha2_x || !alpha2_y)
321 return false;
322 if (alpha2_x[0] == alpha2_y[0] &&
323 alpha2_x[1] == alpha2_y[1])
324 return true;
325 return false;
326}
327
Luis R. Rodriguez69b15722009-02-21 00:04:33 -0500328static bool regdom_changes(const char *alpha2)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700329{
Luis R. Rodriguez761cf7e2009-02-21 00:04:25 -0500330 assert_cfg80211_lock();
331
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700332 if (!cfg80211_regdomain)
333 return true;
334 if (alpha2_equal(cfg80211_regdomain->alpha2, alpha2))
335 return false;
336 return true;
337}
338
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800339/**
340 * country_ie_integrity_changes - tells us if the country IE has changed
341 * @checksum: checksum of country IE of fields we are interested in
342 *
343 * If the country IE has not changed you can ignore it safely. This is
344 * useful to determine if two devices are seeing two different country IEs
345 * even on the same alpha2. Note that this will return false if no IE has
346 * been set on the wireless core yet.
347 */
348static bool country_ie_integrity_changes(u32 checksum)
349{
350 /* If no IE has been set then the checksum doesn't change */
351 if (unlikely(!last_request->country_ie_checksum))
352 return false;
353 if (unlikely(last_request->country_ie_checksum != checksum))
354 return true;
355 return false;
356}
357
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500358/*
359 * This lets us keep regulatory code which is updated on a regulatory
360 * basis in userspace.
361 */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700362static int call_crda(const char *alpha2)
363{
364 char country_env[9 + 2] = "COUNTRY=";
365 char *envp[] = {
366 country_env,
367 NULL
368 };
369
370 if (!is_world_regdom((char *) alpha2))
371 printk(KERN_INFO "cfg80211: Calling CRDA for country: %c%c\n",
372 alpha2[0], alpha2[1]);
373 else
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700374 printk(KERN_INFO "cfg80211: Calling CRDA to update world "
375 "regulatory domain\n");
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700376
377 country_env[8] = alpha2[0];
378 country_env[9] = alpha2[1];
379
380 return kobject_uevent_env(&reg_pdev->dev.kobj, KOBJ_CHANGE, envp);
381}
382
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700383/* Used by nl80211 before kmalloc'ing our regulatory domain */
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200384bool reg_is_valid_request(const char *alpha2)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700385{
Johannes Bergf6037d02008-10-21 11:01:33 +0200386 if (!last_request)
387 return false;
388
389 return alpha2_equal(last_request->alpha2, alpha2);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700390}
391
392/* Sanity check on a regulatory rule */
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200393static bool is_valid_reg_rule(const struct ieee80211_reg_rule *rule)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700394{
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200395 const struct ieee80211_freq_range *freq_range = &rule->freq_range;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700396 u32 freq_diff;
397
Luis R. Rodriguez91e99002008-11-12 14:21:55 -0800398 if (freq_range->start_freq_khz <= 0 || freq_range->end_freq_khz <= 0)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700399 return false;
400
401 if (freq_range->start_freq_khz > freq_range->end_freq_khz)
402 return false;
403
404 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
405
Roel Kluinbd05f282009-03-03 22:55:21 +0100406 if (freq_range->end_freq_khz <= freq_range->start_freq_khz ||
407 freq_range->max_bandwidth_khz > freq_diff)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700408 return false;
409
410 return true;
411}
412
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200413static bool is_valid_rd(const struct ieee80211_regdomain *rd)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700414{
Johannes Berga3d2eaf2008-09-15 11:10:52 +0200415 const struct ieee80211_reg_rule *reg_rule = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700416 unsigned int i;
417
418 if (!rd->n_reg_rules)
419 return false;
420
Luis R. Rodriguez88dc1c32008-11-12 14:22:01 -0800421 if (WARN_ON(rd->n_reg_rules > NL80211_MAX_SUPP_REG_RULES))
422 return false;
423
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700424 for (i = 0; i < rd->n_reg_rules; i++) {
425 reg_rule = &rd->reg_rules[i];
426 if (!is_valid_reg_rule(reg_rule))
427 return false;
428 }
429
430 return true;
431}
432
433/* Returns value in KHz */
434static u32 freq_max_bandwidth(const struct ieee80211_freq_range *freq_range,
435 u32 freq)
436{
437 unsigned int i;
438 for (i = 0; i < ARRAY_SIZE(supported_bandwidths); i++) {
439 u32 start_freq_khz = freq - supported_bandwidths[i]/2;
440 u32 end_freq_khz = freq + supported_bandwidths[i]/2;
441 if (start_freq_khz >= freq_range->start_freq_khz &&
442 end_freq_khz <= freq_range->end_freq_khz)
443 return supported_bandwidths[i];
444 }
445 return 0;
446}
447
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800448/**
449 * freq_in_rule_band - tells us if a frequency is in a frequency band
450 * @freq_range: frequency rule we want to query
451 * @freq_khz: frequency we are inquiring about
452 *
453 * This lets us know if a specific frequency rule is or is not relevant to
454 * a specific frequency's band. Bands are device specific and artificial
455 * definitions (the "2.4 GHz band" and the "5 GHz band"), however it is
456 * safe for now to assume that a frequency rule should not be part of a
457 * frequency's band if the start freq or end freq are off by more than 2 GHz.
458 * This resolution can be lowered and should be considered as we add
459 * regulatory rule support for other "bands".
460 **/
461static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range,
462 u32 freq_khz)
463{
464#define ONE_GHZ_IN_KHZ 1000000
465 if (abs(freq_khz - freq_range->start_freq_khz) <= (2 * ONE_GHZ_IN_KHZ))
466 return true;
467 if (abs(freq_khz - freq_range->end_freq_khz) <= (2 * ONE_GHZ_IN_KHZ))
468 return true;
469 return false;
470#undef ONE_GHZ_IN_KHZ
471}
472
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500473/*
474 * Converts a country IE to a regulatory domain. A regulatory domain
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800475 * structure has a lot of information which the IE doesn't yet have,
476 * so for the other values we use upper max values as we will intersect
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500477 * with our userspace regulatory agent to get lower bounds.
478 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800479static struct ieee80211_regdomain *country_ie_2_rd(
480 u8 *country_ie,
481 u8 country_ie_len,
482 u32 *checksum)
483{
484 struct ieee80211_regdomain *rd = NULL;
485 unsigned int i = 0;
486 char alpha2[2];
487 u32 flags = 0;
488 u32 num_rules = 0, size_of_regd = 0;
489 u8 *triplets_start = NULL;
490 u8 len_at_triplet = 0;
491 /* the last channel we have registered in a subband (triplet) */
492 int last_sub_max_channel = 0;
493
494 *checksum = 0xDEADBEEF;
495
496 /* Country IE requirements */
497 BUG_ON(country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN ||
498 country_ie_len & 0x01);
499
500 alpha2[0] = country_ie[0];
501 alpha2[1] = country_ie[1];
502
503 /*
504 * Third octet can be:
505 * 'I' - Indoor
506 * 'O' - Outdoor
507 *
508 * anything else we assume is no restrictions
509 */
510 if (country_ie[2] == 'I')
511 flags = NL80211_RRF_NO_OUTDOOR;
512 else if (country_ie[2] == 'O')
513 flags = NL80211_RRF_NO_INDOOR;
514
515 country_ie += 3;
516 country_ie_len -= 3;
517
518 triplets_start = country_ie;
519 len_at_triplet = country_ie_len;
520
521 *checksum ^= ((flags ^ alpha2[0] ^ alpha2[1]) << 8);
522
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500523 /*
524 * We need to build a reg rule for each triplet, but first we must
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800525 * calculate the number of reg rules we will need. We will need one
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500526 * for each channel subband
527 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800528 while (country_ie_len >= 3) {
Luis R. Rodriguez615aab42009-01-22 15:05:46 -0800529 int end_channel = 0;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800530 struct ieee80211_country_ie_triplet *triplet =
531 (struct ieee80211_country_ie_triplet *) country_ie;
532 int cur_sub_max_channel = 0, cur_channel = 0;
533
534 if (triplet->ext.reg_extension_id >=
535 IEEE80211_COUNTRY_EXTENSION_ID) {
536 country_ie += 3;
537 country_ie_len -= 3;
538 continue;
539 }
540
Luis R. Rodriguez615aab42009-01-22 15:05:46 -0800541 /* 2 GHz */
542 if (triplet->chans.first_channel <= 14)
543 end_channel = triplet->chans.first_channel +
544 triplet->chans.num_channels;
545 else
546 /*
547 * 5 GHz -- For example in country IEs if the first
548 * channel given is 36 and the number of channels is 4
549 * then the individual channel numbers defined for the
550 * 5 GHz PHY by these parameters are: 36, 40, 44, and 48
551 * and not 36, 37, 38, 39.
552 *
553 * See: http://tinyurl.com/11d-clarification
554 */
555 end_channel = triplet->chans.first_channel +
556 (4 * (triplet->chans.num_channels - 1));
557
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800558 cur_channel = triplet->chans.first_channel;
Luis R. Rodriguez615aab42009-01-22 15:05:46 -0800559 cur_sub_max_channel = end_channel;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800560
561 /* Basic sanity check */
562 if (cur_sub_max_channel < cur_channel)
563 return NULL;
564
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500565 /*
566 * Do not allow overlapping channels. Also channels
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800567 * passed in each subband must be monotonically
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500568 * increasing
569 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800570 if (last_sub_max_channel) {
571 if (cur_channel <= last_sub_max_channel)
572 return NULL;
573 if (cur_sub_max_channel <= last_sub_max_channel)
574 return NULL;
575 }
576
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500577 /*
578 * When dot11RegulatoryClassesRequired is supported
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800579 * we can throw ext triplets as part of this soup,
580 * for now we don't care when those change as we
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500581 * don't support them
582 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800583 *checksum ^= ((cur_channel ^ cur_sub_max_channel) << 8) |
584 ((cur_sub_max_channel ^ cur_sub_max_channel) << 16) |
585 ((triplet->chans.max_power ^ cur_sub_max_channel) << 24);
586
587 last_sub_max_channel = cur_sub_max_channel;
588
589 country_ie += 3;
590 country_ie_len -= 3;
591 num_rules++;
592
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500593 /*
594 * Note: this is not a IEEE requirement but
595 * simply a memory requirement
596 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800597 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
598 return NULL;
599 }
600
601 country_ie = triplets_start;
602 country_ie_len = len_at_triplet;
603
604 size_of_regd = sizeof(struct ieee80211_regdomain) +
605 (num_rules * sizeof(struct ieee80211_reg_rule));
606
607 rd = kzalloc(size_of_regd, GFP_KERNEL);
608 if (!rd)
609 return NULL;
610
611 rd->n_reg_rules = num_rules;
612 rd->alpha2[0] = alpha2[0];
613 rd->alpha2[1] = alpha2[1];
614
615 /* This time around we fill in the rd */
616 while (country_ie_len >= 3) {
Luis R. Rodriguez02e68a32009-01-07 17:43:37 -0800617 int end_channel = 0;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800618 struct ieee80211_country_ie_triplet *triplet =
619 (struct ieee80211_country_ie_triplet *) country_ie;
620 struct ieee80211_reg_rule *reg_rule = NULL;
621 struct ieee80211_freq_range *freq_range = NULL;
622 struct ieee80211_power_rule *power_rule = NULL;
623
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500624 /*
625 * Must parse if dot11RegulatoryClassesRequired is true,
626 * we don't support this yet
627 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800628 if (triplet->ext.reg_extension_id >=
629 IEEE80211_COUNTRY_EXTENSION_ID) {
630 country_ie += 3;
631 country_ie_len -= 3;
632 continue;
633 }
634
635 reg_rule = &rd->reg_rules[i];
636 freq_range = &reg_rule->freq_range;
637 power_rule = &reg_rule->power_rule;
638
639 reg_rule->flags = flags;
640
Luis R. Rodriguez02e68a32009-01-07 17:43:37 -0800641 /* 2 GHz */
642 if (triplet->chans.first_channel <= 14)
643 end_channel = triplet->chans.first_channel +
644 triplet->chans.num_channels;
645 else
Luis R. Rodriguez02e68a32009-01-07 17:43:37 -0800646 end_channel = triplet->chans.first_channel +
647 (4 * (triplet->chans.num_channels - 1));
648
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500649 /*
650 * The +10 is since the regulatory domain expects
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800651 * the actual band edge, not the center of freq for
652 * its start and end freqs, assuming 20 MHz bandwidth on
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500653 * the channels passed
654 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800655 freq_range->start_freq_khz =
656 MHZ_TO_KHZ(ieee80211_channel_to_frequency(
657 triplet->chans.first_channel) - 10);
658 freq_range->end_freq_khz =
659 MHZ_TO_KHZ(ieee80211_channel_to_frequency(
Luis R. Rodriguez02e68a32009-01-07 17:43:37 -0800660 end_channel) + 10);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800661
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500662 /*
663 * These are large arbitrary values we use to intersect later.
664 * Increment this if we ever support >= 40 MHz channels
665 * in IEEE 802.11
666 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800667 freq_range->max_bandwidth_khz = MHZ_TO_KHZ(40);
668 power_rule->max_antenna_gain = DBI_TO_MBI(100);
669 power_rule->max_eirp = DBM_TO_MBM(100);
670
671 country_ie += 3;
672 country_ie_len -= 3;
673 i++;
674
675 BUG_ON(i > NL80211_MAX_SUPP_REG_RULES);
676 }
677
678 return rd;
679}
680
681
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500682/*
683 * Helper for regdom_intersect(), this does the real
684 * mathematical intersection fun
685 */
Luis R. Rodriguez9c964772008-10-30 13:33:53 -0700686static int reg_rules_intersect(
687 const struct ieee80211_reg_rule *rule1,
688 const struct ieee80211_reg_rule *rule2,
689 struct ieee80211_reg_rule *intersected_rule)
690{
691 const struct ieee80211_freq_range *freq_range1, *freq_range2;
692 struct ieee80211_freq_range *freq_range;
693 const struct ieee80211_power_rule *power_rule1, *power_rule2;
694 struct ieee80211_power_rule *power_rule;
695 u32 freq_diff;
696
697 freq_range1 = &rule1->freq_range;
698 freq_range2 = &rule2->freq_range;
699 freq_range = &intersected_rule->freq_range;
700
701 power_rule1 = &rule1->power_rule;
702 power_rule2 = &rule2->power_rule;
703 power_rule = &intersected_rule->power_rule;
704
705 freq_range->start_freq_khz = max(freq_range1->start_freq_khz,
706 freq_range2->start_freq_khz);
707 freq_range->end_freq_khz = min(freq_range1->end_freq_khz,
708 freq_range2->end_freq_khz);
709 freq_range->max_bandwidth_khz = min(freq_range1->max_bandwidth_khz,
710 freq_range2->max_bandwidth_khz);
711
712 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
713 if (freq_range->max_bandwidth_khz > freq_diff)
714 freq_range->max_bandwidth_khz = freq_diff;
715
716 power_rule->max_eirp = min(power_rule1->max_eirp,
717 power_rule2->max_eirp);
718 power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain,
719 power_rule2->max_antenna_gain);
720
721 intersected_rule->flags = (rule1->flags | rule2->flags);
722
723 if (!is_valid_reg_rule(intersected_rule))
724 return -EINVAL;
725
726 return 0;
727}
728
729/**
730 * regdom_intersect - do the intersection between two regulatory domains
731 * @rd1: first regulatory domain
732 * @rd2: second regulatory domain
733 *
734 * Use this function to get the intersection between two regulatory domains.
735 * Once completed we will mark the alpha2 for the rd as intersected, "98",
736 * as no one single alpha2 can represent this regulatory domain.
737 *
738 * Returns a pointer to the regulatory domain structure which will hold the
739 * resulting intersection of rules between rd1 and rd2. We will
740 * kzalloc() this structure for you.
741 */
742static struct ieee80211_regdomain *regdom_intersect(
743 const struct ieee80211_regdomain *rd1,
744 const struct ieee80211_regdomain *rd2)
745{
746 int r, size_of_regd;
747 unsigned int x, y;
748 unsigned int num_rules = 0, rule_idx = 0;
749 const struct ieee80211_reg_rule *rule1, *rule2;
750 struct ieee80211_reg_rule *intersected_rule;
751 struct ieee80211_regdomain *rd;
752 /* This is just a dummy holder to help us count */
753 struct ieee80211_reg_rule irule;
754
755 /* Uses the stack temporarily for counter arithmetic */
756 intersected_rule = &irule;
757
758 memset(intersected_rule, 0, sizeof(struct ieee80211_reg_rule));
759
760 if (!rd1 || !rd2)
761 return NULL;
762
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500763 /*
764 * First we get a count of the rules we'll need, then we actually
Luis R. Rodriguez9c964772008-10-30 13:33:53 -0700765 * build them. This is to so we can malloc() and free() a
766 * regdomain once. The reason we use reg_rules_intersect() here
767 * is it will return -EINVAL if the rule computed makes no sense.
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500768 * All rules that do check out OK are valid.
769 */
Luis R. Rodriguez9c964772008-10-30 13:33:53 -0700770
771 for (x = 0; x < rd1->n_reg_rules; x++) {
772 rule1 = &rd1->reg_rules[x];
773 for (y = 0; y < rd2->n_reg_rules; y++) {
774 rule2 = &rd2->reg_rules[y];
775 if (!reg_rules_intersect(rule1, rule2,
776 intersected_rule))
777 num_rules++;
778 memset(intersected_rule, 0,
779 sizeof(struct ieee80211_reg_rule));
780 }
781 }
782
783 if (!num_rules)
784 return NULL;
785
786 size_of_regd = sizeof(struct ieee80211_regdomain) +
787 ((num_rules + 1) * sizeof(struct ieee80211_reg_rule));
788
789 rd = kzalloc(size_of_regd, GFP_KERNEL);
790 if (!rd)
791 return NULL;
792
793 for (x = 0; x < rd1->n_reg_rules; x++) {
794 rule1 = &rd1->reg_rules[x];
795 for (y = 0; y < rd2->n_reg_rules; y++) {
796 rule2 = &rd2->reg_rules[y];
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500797 /*
798 * This time around instead of using the stack lets
Luis R. Rodriguez9c964772008-10-30 13:33:53 -0700799 * write to the target rule directly saving ourselves
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500800 * a memcpy()
801 */
Luis R. Rodriguez9c964772008-10-30 13:33:53 -0700802 intersected_rule = &rd->reg_rules[rule_idx];
803 r = reg_rules_intersect(rule1, rule2,
804 intersected_rule);
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500805 /*
806 * No need to memset here the intersected rule here as
807 * we're not using the stack anymore
808 */
Luis R. Rodriguez9c964772008-10-30 13:33:53 -0700809 if (r)
810 continue;
811 rule_idx++;
812 }
813 }
814
815 if (rule_idx != num_rules) {
816 kfree(rd);
817 return NULL;
818 }
819
820 rd->n_reg_rules = num_rules;
821 rd->alpha2[0] = '9';
822 rd->alpha2[1] = '8';
823
824 return rd;
825}
826
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500827/*
828 * XXX: add support for the rest of enum nl80211_reg_rule_flags, we may
829 * want to just have the channel structure use these
830 */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700831static u32 map_regdom_flags(u32 rd_flags)
832{
833 u32 channel_flags = 0;
834 if (rd_flags & NL80211_RRF_PASSIVE_SCAN)
835 channel_flags |= IEEE80211_CHAN_PASSIVE_SCAN;
836 if (rd_flags & NL80211_RRF_NO_IBSS)
837 channel_flags |= IEEE80211_CHAN_NO_IBSS;
838 if (rd_flags & NL80211_RRF_DFS)
839 channel_flags |= IEEE80211_CHAN_RADAR;
840 return channel_flags;
841}
842
Luis R. Rodriguez1fa25e42009-01-22 15:05:44 -0800843static int freq_reg_info_regd(struct wiphy *wiphy,
844 u32 center_freq,
845 u32 *bandwidth,
846 const struct ieee80211_reg_rule **reg_rule,
847 const struct ieee80211_regdomain *custom_regd)
Johannes Berg8318d782008-01-24 19:38:38 +0100848{
849 int i;
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800850 bool band_rule_found = false;
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -0800851 const struct ieee80211_regdomain *regd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700852 u32 max_bandwidth = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100853
Luis R. Rodriguez1fa25e42009-01-22 15:05:44 -0800854 regd = custom_regd ? custom_regd : cfg80211_regdomain;
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -0800855
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500856 /*
857 * Follow the driver's regulatory domain, if present, unless a country
858 * IE has been processed or a user wants to help complaince further
859 */
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400860 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
861 last_request->initiator != NL80211_REGDOM_SET_BY_USER &&
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -0800862 wiphy->regd)
863 regd = wiphy->regd;
864
865 if (!regd)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700866 return -EINVAL;
867
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -0800868 for (i = 0; i < regd->n_reg_rules; i++) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700869 const struct ieee80211_reg_rule *rr;
870 const struct ieee80211_freq_range *fr = NULL;
871 const struct ieee80211_power_rule *pr = NULL;
872
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -0800873 rr = &regd->reg_rules[i];
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700874 fr = &rr->freq_range;
875 pr = &rr->power_rule;
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800876
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500877 /*
878 * We only need to know if one frequency rule was
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800879 * was in center_freq's band, that's enough, so lets
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500880 * not overwrite it once found
881 */
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800882 if (!band_rule_found)
883 band_rule_found = freq_in_rule_band(fr, center_freq);
884
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700885 max_bandwidth = freq_max_bandwidth(fr, center_freq);
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800886
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700887 if (max_bandwidth && *bandwidth <= max_bandwidth) {
888 *reg_rule = rr;
889 *bandwidth = max_bandwidth;
Johannes Berg8318d782008-01-24 19:38:38 +0100890 break;
891 }
892 }
893
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800894 if (!band_rule_found)
895 return -ERANGE;
896
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700897 return !max_bandwidth;
898}
Luis R. Rodriguez34f57342009-01-22 15:05:45 -0800899EXPORT_SYMBOL(freq_reg_info);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700900
Luis R. Rodriguez34f57342009-01-22 15:05:45 -0800901int freq_reg_info(struct wiphy *wiphy, u32 center_freq, u32 *bandwidth,
Luis R. Rodriguez1fa25e42009-01-22 15:05:44 -0800902 const struct ieee80211_reg_rule **reg_rule)
903{
904 return freq_reg_info_regd(wiphy, center_freq,
905 bandwidth, reg_rule, NULL);
906}
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700907
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -0800908static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
909 unsigned int chan_idx)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700910{
911 int r;
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -0800912 u32 flags;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700913 u32 max_bandwidth = 0;
914 const struct ieee80211_reg_rule *reg_rule = NULL;
915 const struct ieee80211_power_rule *power_rule = NULL;
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -0800916 struct ieee80211_supported_band *sband;
917 struct ieee80211_channel *chan;
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -0500918 struct wiphy *request_wiphy = NULL;
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -0800919
Luis R. Rodriguez761cf7e2009-02-21 00:04:25 -0500920 assert_cfg80211_lock();
921
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -0500922 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
923
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -0800924 sband = wiphy->bands[band];
925 BUG_ON(chan_idx >= sband->n_channels);
926 chan = &sband->channels[chan_idx];
927
928 flags = chan->orig_flags;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700929
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -0800930 r = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq),
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700931 &max_bandwidth, &reg_rule);
932
933 if (r) {
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500934 /*
935 * This means no regulatory rule was found in the country IE
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800936 * with a frequency range on the center_freq's band, since
937 * IEEE-802.11 allows for a country IE to have a subset of the
938 * regulatory information provided in a country we ignore
939 * disabling the channel unless at least one reg rule was
940 * found on the center_freq's band. For details see this
941 * clarification:
942 *
943 * http://tinyurl.com/11d-clarification
944 */
945 if (r == -ERANGE &&
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400946 last_request->initiator ==
947 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800948#ifdef CONFIG_CFG80211_REG_DEBUG
949 printk(KERN_DEBUG "cfg80211: Leaving channel %d MHz "
950 "intact on %s - no rule found in band on "
951 "Country IE\n",
952 chan->center_freq, wiphy_name(wiphy));
953#endif
954 } else {
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500955 /*
956 * In this case we know the country IE has at least one reg rule
957 * for the band so we respect its band definitions
958 */
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800959#ifdef CONFIG_CFG80211_REG_DEBUG
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400960 if (last_request->initiator ==
961 NL80211_REGDOM_SET_BY_COUNTRY_IE)
Luis R. Rodriguez0c7dc452009-01-07 17:43:36 -0800962 printk(KERN_DEBUG "cfg80211: Disabling "
963 "channel %d MHz on %s due to "
964 "Country IE\n",
965 chan->center_freq, wiphy_name(wiphy));
966#endif
967 flags |= IEEE80211_CHAN_DISABLED;
968 chan->flags = flags;
969 }
Johannes Berg8318d782008-01-24 19:38:38 +0100970 return;
971 }
972
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700973 power_rule = &reg_rule->power_rule;
974
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -0400975 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -0500976 request_wiphy && request_wiphy == wiphy &&
977 request_wiphy->strict_regulatory) {
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500978 /*
979 * This gaurantees the driver's requested regulatory domain
Luis R. Rodriguezf9763762009-01-22 15:05:52 -0800980 * will always be used as a base for further regulatory
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -0500981 * settings
982 */
Luis R. Rodriguezf9763762009-01-22 15:05:52 -0800983 chan->flags = chan->orig_flags =
984 map_regdom_flags(reg_rule->flags);
985 chan->max_antenna_gain = chan->orig_mag =
986 (int) MBI_TO_DBI(power_rule->max_antenna_gain);
987 chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth);
988 chan->max_power = chan->orig_mpwr =
989 (int) MBM_TO_DBM(power_rule->max_eirp);
990 return;
991 }
992
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700993 chan->flags = flags | map_regdom_flags(reg_rule->flags);
Johannes Berg8318d782008-01-24 19:38:38 +0100994 chan->max_antenna_gain = min(chan->orig_mag,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700995 (int) MBI_TO_DBI(power_rule->max_antenna_gain));
996 chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth);
John W. Linville253898c2008-04-03 15:32:54 -0400997 if (chan->orig_mpwr)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700998 chan->max_power = min(chan->orig_mpwr,
999 (int) MBM_TO_DBM(power_rule->max_eirp));
John W. Linville253898c2008-04-03 15:32:54 -04001000 else
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001001 chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp);
Johannes Berg8318d782008-01-24 19:38:38 +01001002}
1003
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -08001004static void handle_band(struct wiphy *wiphy, enum ieee80211_band band)
Johannes Berg8318d782008-01-24 19:38:38 +01001005{
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -08001006 unsigned int i;
1007 struct ieee80211_supported_band *sband;
1008
1009 BUG_ON(!wiphy->bands[band]);
1010 sband = wiphy->bands[band];
Johannes Berg8318d782008-01-24 19:38:38 +01001011
1012 for (i = 0; i < sband->n_channels; i++)
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -08001013 handle_channel(wiphy, band, i);
Johannes Berg8318d782008-01-24 19:38:38 +01001014}
1015
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001016static bool ignore_reg_update(struct wiphy *wiphy,
1017 enum nl80211_reg_initiator initiator)
Luis R. Rodriguez14b98152008-11-12 14:22:03 -08001018{
1019 if (!last_request)
1020 return true;
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001021 if (initiator == NL80211_REGDOM_SET_BY_CORE &&
Luis R. Rodriguez2a44f912009-01-22 15:05:49 -08001022 wiphy->custom_regulatory)
Luis R. Rodriguez14b98152008-11-12 14:22:03 -08001023 return true;
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001024 /*
1025 * wiphy->regd will be set once the device has its own
1026 * desired regulatory domain set
1027 */
Luis R. Rodriguezf9763762009-01-22 15:05:52 -08001028 if (wiphy->strict_regulatory && !wiphy->regd &&
1029 !is_world_regdom(last_request->alpha2))
Luis R. Rodriguez14b98152008-11-12 14:22:03 -08001030 return true;
1031 return false;
1032}
1033
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001034static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001035{
1036 struct cfg80211_registered_device *drv;
1037
1038 list_for_each_entry(drv, &cfg80211_drv_list, list)
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001039 wiphy_update_regulatory(&drv->wiphy, initiator);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001040}
1041
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -05001042static void handle_reg_beacon(struct wiphy *wiphy,
1043 unsigned int chan_idx,
1044 struct reg_beacon *reg_beacon)
1045{
1046#ifdef CONFIG_CFG80211_REG_DEBUG
1047#define REG_DEBUG_BEACON_FLAG(desc) \
1048 printk(KERN_DEBUG "cfg80211: Enabling " desc " on " \
1049 "frequency: %d MHz (Ch %d) on %s\n", \
1050 reg_beacon->chan.center_freq, \
1051 ieee80211_frequency_to_channel(reg_beacon->chan.center_freq), \
1052 wiphy_name(wiphy));
1053#else
1054#define REG_DEBUG_BEACON_FLAG(desc) do {} while (0)
1055#endif
1056 struct ieee80211_supported_band *sband;
1057 struct ieee80211_channel *chan;
1058
1059 assert_cfg80211_lock();
1060
1061 sband = wiphy->bands[reg_beacon->chan.band];
1062 chan = &sband->channels[chan_idx];
1063
1064 if (likely(chan->center_freq != reg_beacon->chan.center_freq))
1065 return;
1066
1067 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) {
1068 chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
1069 REG_DEBUG_BEACON_FLAG("active scanning");
1070 }
1071
1072 if (chan->flags & IEEE80211_CHAN_NO_IBSS) {
1073 chan->flags &= ~IEEE80211_CHAN_NO_IBSS;
1074 REG_DEBUG_BEACON_FLAG("beaconing");
1075 }
1076
1077 chan->beacon_found = true;
1078#undef REG_DEBUG_BEACON_FLAG
1079}
1080
1081/*
1082 * Called when a scan on a wiphy finds a beacon on
1083 * new channel
1084 */
1085static void wiphy_update_new_beacon(struct wiphy *wiphy,
1086 struct reg_beacon *reg_beacon)
1087{
1088 unsigned int i;
1089 struct ieee80211_supported_band *sband;
1090
1091 assert_cfg80211_lock();
1092
1093 if (!wiphy->bands[reg_beacon->chan.band])
1094 return;
1095
1096 sband = wiphy->bands[reg_beacon->chan.band];
1097
1098 for (i = 0; i < sband->n_channels; i++)
1099 handle_reg_beacon(wiphy, i, reg_beacon);
1100}
1101
1102/*
1103 * Called upon reg changes or a new wiphy is added
1104 */
1105static void wiphy_update_beacon_reg(struct wiphy *wiphy)
1106{
1107 unsigned int i;
1108 struct ieee80211_supported_band *sband;
1109 struct reg_beacon *reg_beacon;
1110
1111 assert_cfg80211_lock();
1112
1113 if (list_empty(&reg_beacon_list))
1114 return;
1115
1116 list_for_each_entry(reg_beacon, &reg_beacon_list, list) {
1117 if (!wiphy->bands[reg_beacon->chan.band])
1118 continue;
1119 sband = wiphy->bands[reg_beacon->chan.band];
1120 for (i = 0; i < sband->n_channels; i++)
1121 handle_reg_beacon(wiphy, i, reg_beacon);
1122 }
1123}
1124
1125static bool reg_is_world_roaming(struct wiphy *wiphy)
1126{
1127 if (is_world_regdom(cfg80211_regdomain->alpha2) ||
1128 (wiphy->regd && is_world_regdom(wiphy->regd->alpha2)))
1129 return true;
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001130 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -05001131 wiphy->custom_regulatory)
1132 return true;
1133 return false;
1134}
1135
1136/* Reap the advantages of previously found beacons */
1137static void reg_process_beacons(struct wiphy *wiphy)
1138{
1139 if (!reg_is_world_roaming(wiphy))
1140 return;
1141 wiphy_update_beacon_reg(wiphy);
1142}
1143
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001144void wiphy_update_regulatory(struct wiphy *wiphy,
1145 enum nl80211_reg_initiator initiator)
Johannes Berg8318d782008-01-24 19:38:38 +01001146{
1147 enum ieee80211_band band;
Luis R. Rodriguezd46e5b12009-01-22 15:05:50 -08001148
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001149 if (ignore_reg_update(wiphy, initiator))
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -05001150 goto out;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001151 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg8318d782008-01-24 19:38:38 +01001152 if (wiphy->bands[band])
Luis R. Rodrigueza92a3ce2009-01-07 17:43:33 -08001153 handle_band(wiphy, band);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001154 }
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -05001155out:
1156 reg_process_beacons(wiphy);
Luis R. Rodriguez560e28e2009-01-07 17:43:32 -08001157 if (wiphy->reg_notifier)
Luis R. Rodriguez716f9392009-01-22 15:05:51 -08001158 wiphy->reg_notifier(wiphy, last_request);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001159}
1160
Luis R. Rodriguez1fa25e42009-01-22 15:05:44 -08001161static void handle_channel_custom(struct wiphy *wiphy,
1162 enum ieee80211_band band,
1163 unsigned int chan_idx,
1164 const struct ieee80211_regdomain *regd)
1165{
1166 int r;
1167 u32 max_bandwidth = 0;
1168 const struct ieee80211_reg_rule *reg_rule = NULL;
1169 const struct ieee80211_power_rule *power_rule = NULL;
1170 struct ieee80211_supported_band *sband;
1171 struct ieee80211_channel *chan;
1172
1173 sband = wiphy->bands[band];
1174 BUG_ON(chan_idx >= sband->n_channels);
1175 chan = &sband->channels[chan_idx];
1176
1177 r = freq_reg_info_regd(wiphy, MHZ_TO_KHZ(chan->center_freq),
1178 &max_bandwidth, &reg_rule, regd);
1179
1180 if (r) {
1181 chan->flags = IEEE80211_CHAN_DISABLED;
1182 return;
1183 }
1184
1185 power_rule = &reg_rule->power_rule;
1186
1187 chan->flags |= map_regdom_flags(reg_rule->flags);
1188 chan->max_antenna_gain = (int) MBI_TO_DBI(power_rule->max_antenna_gain);
1189 chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth);
1190 chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp);
1191}
1192
1193static void handle_band_custom(struct wiphy *wiphy, enum ieee80211_band band,
1194 const struct ieee80211_regdomain *regd)
1195{
1196 unsigned int i;
1197 struct ieee80211_supported_band *sband;
1198
1199 BUG_ON(!wiphy->bands[band]);
1200 sband = wiphy->bands[band];
1201
1202 for (i = 0; i < sband->n_channels; i++)
1203 handle_channel_custom(wiphy, band, i, regd);
1204}
1205
1206/* Used by drivers prior to wiphy registration */
1207void wiphy_apply_custom_regulatory(struct wiphy *wiphy,
1208 const struct ieee80211_regdomain *regd)
1209{
1210 enum ieee80211_band band;
1211 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1212 if (wiphy->bands[band])
1213 handle_band_custom(wiphy, band, regd);
1214 }
1215}
1216EXPORT_SYMBOL(wiphy_apply_custom_regulatory);
1217
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001218static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd,
1219 const struct ieee80211_regdomain *src_regd)
1220{
1221 struct ieee80211_regdomain *regd;
1222 int size_of_regd = 0;
1223 unsigned int i;
1224
1225 size_of_regd = sizeof(struct ieee80211_regdomain) +
1226 ((src_regd->n_reg_rules + 1) * sizeof(struct ieee80211_reg_rule));
1227
1228 regd = kzalloc(size_of_regd, GFP_KERNEL);
1229 if (!regd)
1230 return -ENOMEM;
1231
1232 memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain));
1233
1234 for (i = 0; i < src_regd->n_reg_rules; i++)
1235 memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i],
1236 sizeof(struct ieee80211_reg_rule));
1237
1238 *dst_regd = regd;
1239 return 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001240}
1241
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001242/*
1243 * Return value which can be used by ignore_request() to indicate
1244 * it has been determined we should intersect two regulatory domains
1245 */
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001246#define REG_INTERSECT 1
1247
Johannes Berg84fa4f42008-10-24 20:32:23 +02001248/* This has the logic which determines when a new request
1249 * should be ignored. */
Luis R. Rodriguez2f92cd22009-02-21 00:24:16 -05001250static int ignore_request(struct wiphy *wiphy,
1251 struct regulatory_request *pending_request)
Johannes Berg84fa4f42008-10-24 20:32:23 +02001252{
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001253 struct wiphy *last_wiphy = NULL;
Luis R. Rodriguez761cf7e2009-02-21 00:04:25 -05001254
1255 assert_cfg80211_lock();
1256
Johannes Berg84fa4f42008-10-24 20:32:23 +02001257 /* All initial requests are respected */
1258 if (!last_request)
1259 return 0;
1260
Luis R. Rodriguez2f92cd22009-02-21 00:24:16 -05001261 switch (pending_request->initiator) {
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001262 case NL80211_REGDOM_SET_BY_CORE:
Luis R. Rodriguezba25c142009-02-21 00:04:23 -05001263 return -EINVAL;
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001264 case NL80211_REGDOM_SET_BY_COUNTRY_IE:
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001265
1266 last_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
1267
Luis R. Rodriguez2f92cd22009-02-21 00:24:16 -05001268 if (unlikely(!is_an_alpha2(pending_request->alpha2)))
Johannes Berg84fa4f42008-10-24 20:32:23 +02001269 return -EINVAL;
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001270 if (last_request->initiator ==
1271 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001272 if (last_wiphy != wiphy) {
Johannes Berg84fa4f42008-10-24 20:32:23 +02001273 /*
1274 * Two cards with two APs claiming different
1275 * different Country IE alpha2s. We could
1276 * intersect them, but that seems unlikely
1277 * to be correct. Reject second one for now.
1278 */
Luis R. Rodriguez2f92cd22009-02-21 00:24:16 -05001279 if (regdom_changes(pending_request->alpha2))
Johannes Berg84fa4f42008-10-24 20:32:23 +02001280 return -EOPNOTSUPP;
1281 return -EALREADY;
1282 }
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001283 /*
1284 * Two consecutive Country IE hints on the same wiphy.
1285 * This should be picked up early by the driver/stack
1286 */
Luis R. Rodriguez2f92cd22009-02-21 00:24:16 -05001287 if (WARN_ON(regdom_changes(pending_request->alpha2)))
Johannes Berg84fa4f42008-10-24 20:32:23 +02001288 return 0;
1289 return -EALREADY;
1290 }
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001291 return REG_INTERSECT;
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001292 case NL80211_REGDOM_SET_BY_DRIVER:
1293 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE) {
Luis R. Rodrigueze74b1e72009-01-22 15:05:48 -08001294 if (is_old_static_regdom(cfg80211_regdomain))
1295 return 0;
Luis R. Rodriguez2f92cd22009-02-21 00:24:16 -05001296 if (regdom_changes(pending_request->alpha2))
Luis R. Rodrigueze74b1e72009-01-22 15:05:48 -08001297 return 0;
Johannes Berg84fa4f42008-10-24 20:32:23 +02001298 return -EALREADY;
Luis R. Rodrigueze74b1e72009-01-22 15:05:48 -08001299 }
Luis R. Rodriguezfff32c02009-02-21 00:04:32 -05001300
1301 /*
1302 * This would happen if you unplug and plug your card
1303 * back in or if you add a new device for which the previously
1304 * loaded card also agrees on the regulatory domain.
1305 */
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001306 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
Luis R. Rodriguez2f92cd22009-02-21 00:24:16 -05001307 !regdom_changes(pending_request->alpha2))
Luis R. Rodriguezfff32c02009-02-21 00:04:32 -05001308 return -EALREADY;
1309
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001310 return REG_INTERSECT;
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001311 case NL80211_REGDOM_SET_BY_USER:
1312 if (last_request->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE)
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001313 return REG_INTERSECT;
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001314 /*
1315 * If the user knows better the user should set the regdom
1316 * to their country before the IE is picked up
1317 */
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001318 if (last_request->initiator == NL80211_REGDOM_SET_BY_USER &&
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001319 last_request->intersect)
1320 return -EOPNOTSUPP;
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001321 /*
1322 * Process user requests only after previous user/driver/core
1323 * requests have been processed
1324 */
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001325 if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE ||
1326 last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER ||
1327 last_request->initiator == NL80211_REGDOM_SET_BY_USER) {
Luis R. Rodriguez69b15722009-02-21 00:04:33 -05001328 if (regdom_changes(last_request->alpha2))
Luis R. Rodriguez5eebade2009-01-22 15:05:47 -08001329 return -EAGAIN;
1330 }
1331
Luis R. Rodrigueze74b1e72009-01-22 15:05:48 -08001332 if (!is_old_static_regdom(cfg80211_regdomain) &&
Luis R. Rodriguez2f92cd22009-02-21 00:24:16 -05001333 !regdom_changes(pending_request->alpha2))
Luis R. Rodrigueze74b1e72009-01-22 15:05:48 -08001334 return -EALREADY;
1335
Johannes Berg84fa4f42008-10-24 20:32:23 +02001336 return 0;
1337 }
1338
1339 return -EINVAL;
1340}
1341
Luis R. Rodriguezd1c96a92009-02-21 00:24:13 -05001342/**
1343 * __regulatory_hint - hint to the wireless core a regulatory domain
1344 * @wiphy: if the hint comes from country information from an AP, this
1345 * is required to be set to the wiphy that received the information
Luis R. Rodriguez28da32d2009-02-21 00:24:14 -05001346 * @pending_request: the regulatory request currently being processed
Luis R. Rodriguezd1c96a92009-02-21 00:24:13 -05001347 *
1348 * The Wireless subsystem can use this function to hint to the wireless core
Luis R. Rodriguez28da32d2009-02-21 00:24:14 -05001349 * what it believes should be the current regulatory domain.
Luis R. Rodriguezd1c96a92009-02-21 00:24:13 -05001350 *
1351 * Returns zero if all went fine, %-EALREADY if a regulatory domain had
1352 * already been set or other standard error codes.
1353 *
1354 * Caller must hold &cfg80211_mutex
1355 */
Luis R. Rodriguez28da32d2009-02-21 00:24:14 -05001356static int __regulatory_hint(struct wiphy *wiphy,
1357 struct regulatory_request *pending_request)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001358{
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001359 bool intersect = false;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001360 int r = 0;
1361
Luis R. Rodriguez761cf7e2009-02-21 00:04:25 -05001362 assert_cfg80211_lock();
1363
Luis R. Rodriguez2f92cd22009-02-21 00:24:16 -05001364 r = ignore_request(wiphy, pending_request);
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001365
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001366 if (r == REG_INTERSECT) {
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001367 if (pending_request->initiator ==
1368 NL80211_REGDOM_SET_BY_DRIVER) {
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001369 r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain);
Luis R. Rodriguezd951c1d2009-02-21 00:24:15 -05001370 if (r) {
1371 kfree(pending_request);
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001372 return r;
Luis R. Rodriguezd951c1d2009-02-21 00:24:15 -05001373 }
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001374 }
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001375 intersect = true;
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001376 } else if (r) {
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001377 /*
1378 * If the regulatory domain being requested by the
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001379 * driver has already been set just copy it to the
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001380 * wiphy
1381 */
Luis R. Rodriguez28da32d2009-02-21 00:24:14 -05001382 if (r == -EALREADY &&
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001383 pending_request->initiator ==
1384 NL80211_REGDOM_SET_BY_DRIVER) {
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001385 r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain);
Luis R. Rodriguezd951c1d2009-02-21 00:24:15 -05001386 if (r) {
1387 kfree(pending_request);
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001388 return r;
Luis R. Rodriguezd951c1d2009-02-21 00:24:15 -05001389 }
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001390 r = -EALREADY;
1391 goto new_request;
1392 }
Luis R. Rodriguezd951c1d2009-02-21 00:24:15 -05001393 kfree(pending_request);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001394 return r;
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001395 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001396
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001397new_request:
Luis R. Rodriguez5203cdb2008-11-12 14:21:56 -08001398 kfree(last_request);
Luis R. Rodriguezd951c1d2009-02-21 00:24:15 -05001399
1400 last_request = pending_request;
1401 last_request->intersect = intersect;
1402
1403 pending_request = NULL;
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001404
1405 /* When r == REG_INTERSECT we do need to call CRDA */
1406 if (r < 0)
1407 return r;
1408
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001409 /*
1410 * Note: When CONFIG_WIRELESS_OLD_REGULATORY is enabled
1411 * AND if CRDA is NOT present nothing will happen, if someone
1412 * wants to bother with 11d with OLD_REG you can add a timer.
1413 * If after x amount of time nothing happens you can call:
1414 *
1415 * return set_regdom(country_ie_regdomain);
1416 *
1417 * to intersect with the static rd
1418 */
Luis R. Rodriguezd951c1d2009-02-21 00:24:15 -05001419 return call_crda(last_request->alpha2);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001420}
1421
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001422/* This currently only processes user and driver regulatory hints */
Luis R. Rodriguezd951c1d2009-02-21 00:24:15 -05001423static void reg_process_hint(struct regulatory_request *reg_request)
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001424{
1425 int r = 0;
1426 struct wiphy *wiphy = NULL;
1427
1428 BUG_ON(!reg_request->alpha2);
1429
1430 mutex_lock(&cfg80211_mutex);
1431
1432 if (wiphy_idx_valid(reg_request->wiphy_idx))
1433 wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx);
1434
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001435 if (reg_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001436 !wiphy) {
Luis R. Rodriguezd951c1d2009-02-21 00:24:15 -05001437 kfree(reg_request);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001438 goto out;
1439 }
1440
Luis R. Rodriguez28da32d2009-02-21 00:24:14 -05001441 r = __regulatory_hint(wiphy, reg_request);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001442 /* This is required so that the orig_* parameters are saved */
1443 if (r == -EALREADY && wiphy && wiphy->strict_regulatory)
1444 wiphy_update_regulatory(wiphy, reg_request->initiator);
1445out:
1446 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001447}
1448
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001449/* Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_* */
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001450static void reg_process_pending_hints(void)
1451 {
1452 struct regulatory_request *reg_request;
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001453
1454 spin_lock(&reg_requests_lock);
1455 while (!list_empty(&reg_requests_list)) {
1456 reg_request = list_first_entry(&reg_requests_list,
1457 struct regulatory_request,
1458 list);
1459 list_del_init(&reg_request->list);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001460
Luis R. Rodriguezd951c1d2009-02-21 00:24:15 -05001461 spin_unlock(&reg_requests_lock);
1462 reg_process_hint(reg_request);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001463 spin_lock(&reg_requests_lock);
1464 }
1465 spin_unlock(&reg_requests_lock);
1466}
1467
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -05001468/* Processes beacon hints -- this has nothing to do with country IEs */
1469static void reg_process_pending_beacon_hints(void)
1470{
1471 struct cfg80211_registered_device *drv;
1472 struct reg_beacon *pending_beacon, *tmp;
1473
1474 mutex_lock(&cfg80211_mutex);
1475
1476 /* This goes through the _pending_ beacon list */
1477 spin_lock_bh(&reg_pending_beacons_lock);
1478
1479 if (list_empty(&reg_pending_beacons)) {
1480 spin_unlock_bh(&reg_pending_beacons_lock);
1481 goto out;
1482 }
1483
1484 list_for_each_entry_safe(pending_beacon, tmp,
1485 &reg_pending_beacons, list) {
1486
1487 list_del_init(&pending_beacon->list);
1488
1489 /* Applies the beacon hint to current wiphys */
1490 list_for_each_entry(drv, &cfg80211_drv_list, list)
1491 wiphy_update_new_beacon(&drv->wiphy, pending_beacon);
1492
1493 /* Remembers the beacon hint for new wiphys or reg changes */
1494 list_add_tail(&pending_beacon->list, &reg_beacon_list);
1495 }
1496
1497 spin_unlock_bh(&reg_pending_beacons_lock);
1498out:
1499 mutex_unlock(&cfg80211_mutex);
1500}
1501
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001502static void reg_todo(struct work_struct *work)
1503{
1504 reg_process_pending_hints();
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -05001505 reg_process_pending_beacon_hints();
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001506}
1507
1508static DECLARE_WORK(reg_work, reg_todo);
1509
1510static void queue_regulatory_request(struct regulatory_request *request)
1511{
1512 spin_lock(&reg_requests_lock);
1513 list_add_tail(&request->list, &reg_requests_list);
1514 spin_unlock(&reg_requests_lock);
1515
1516 schedule_work(&reg_work);
1517}
1518
1519/* Core regulatory hint -- happens once during cfg80211_init() */
Luis R. Rodriguezba25c142009-02-21 00:04:23 -05001520static int regulatory_hint_core(const char *alpha2)
1521{
1522 struct regulatory_request *request;
1523
1524 BUG_ON(last_request);
1525
1526 request = kzalloc(sizeof(struct regulatory_request),
1527 GFP_KERNEL);
1528 if (!request)
1529 return -ENOMEM;
1530
1531 request->alpha2[0] = alpha2[0];
1532 request->alpha2[1] = alpha2[1];
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001533 request->initiator = NL80211_REGDOM_SET_BY_CORE;
Luis R. Rodriguezba25c142009-02-21 00:04:23 -05001534
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001535 queue_regulatory_request(request);
Luis R. Rodriguezba25c142009-02-21 00:04:23 -05001536
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001537 return 0;
Luis R. Rodriguezba25c142009-02-21 00:04:23 -05001538}
1539
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001540/* User hints */
1541int regulatory_hint_user(const char *alpha2)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001542{
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001543 struct regulatory_request *request;
1544
Johannes Bergbe3d4812008-10-24 20:32:21 +02001545 BUG_ON(!alpha2);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001546
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001547 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1548 if (!request)
1549 return -ENOMEM;
1550
1551 request->wiphy_idx = WIPHY_IDX_STALE;
1552 request->alpha2[0] = alpha2[0];
1553 request->alpha2[1] = alpha2[1];
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001554 request->initiator = NL80211_REGDOM_SET_BY_USER,
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001555
1556 queue_regulatory_request(request);
1557
1558 return 0;
1559}
1560
1561/* Driver hints */
1562int regulatory_hint(struct wiphy *wiphy, const char *alpha2)
1563{
1564 struct regulatory_request *request;
1565
1566 BUG_ON(!alpha2);
1567 BUG_ON(!wiphy);
1568
1569 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1570 if (!request)
1571 return -ENOMEM;
1572
1573 request->wiphy_idx = get_wiphy_idx(wiphy);
1574
1575 /* Must have registered wiphy first */
1576 BUG_ON(!wiphy_idx_valid(request->wiphy_idx));
1577
1578 request->alpha2[0] = alpha2[0];
1579 request->alpha2[1] = alpha2[1];
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001580 request->initiator = NL80211_REGDOM_SET_BY_DRIVER;
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001581
1582 queue_regulatory_request(request);
1583
1584 return 0;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001585}
1586EXPORT_SYMBOL(regulatory_hint);
1587
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001588static bool reg_same_country_ie_hint(struct wiphy *wiphy,
1589 u32 country_ie_checksum)
1590{
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001591 struct wiphy *request_wiphy;
1592
Luis R. Rodriguez761cf7e2009-02-21 00:04:25 -05001593 assert_cfg80211_lock();
1594
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001595 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
1596
1597 if (!request_wiphy)
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001598 return false;
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001599
1600 if (likely(request_wiphy != wiphy))
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001601 return !country_ie_integrity_changes(country_ie_checksum);
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001602 /*
1603 * We should not have let these through at this point, they
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001604 * should have been picked up earlier by the first alpha2 check
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001605 * on the device
1606 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001607 if (WARN_ON(!country_ie_integrity_changes(country_ie_checksum)))
1608 return true;
1609 return false;
1610}
1611
1612void regulatory_hint_11d(struct wiphy *wiphy,
1613 u8 *country_ie,
1614 u8 country_ie_len)
1615{
1616 struct ieee80211_regdomain *rd = NULL;
1617 char alpha2[2];
1618 u32 checksum = 0;
1619 enum environment_cap env = ENVIRON_ANY;
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001620 struct regulatory_request *request;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001621
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001622 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001623
Luis R. Rodriguezd335fe62009-02-21 00:04:27 -05001624 if (unlikely(!last_request)) {
1625 mutex_unlock(&cfg80211_mutex);
1626 return;
1627 }
1628
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001629 /* IE len must be evenly divisible by 2 */
1630 if (country_ie_len & 0x01)
1631 goto out;
1632
1633 if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1634 goto out;
1635
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001636 /*
1637 * Pending country IE processing, this can happen after we
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001638 * call CRDA and wait for a response if a beacon was received before
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001639 * we were able to process the last regulatory_hint_11d() call
1640 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001641 if (country_ie_regdomain)
1642 goto out;
1643
1644 alpha2[0] = country_ie[0];
1645 alpha2[1] = country_ie[1];
1646
1647 if (country_ie[2] == 'I')
1648 env = ENVIRON_INDOOR;
1649 else if (country_ie[2] == 'O')
1650 env = ENVIRON_OUTDOOR;
1651
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001652 /*
1653 * We will run this for *every* beacon processed for the BSSID, so
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001654 * we optimize an early check to exit out early if we don't have to
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001655 * do anything
1656 */
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001657 if (likely(wiphy_idx_valid(last_request->wiphy_idx))) {
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001658 struct cfg80211_registered_device *drv_last_ie;
1659
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001660 drv_last_ie =
1661 cfg80211_drv_by_wiphy_idx(last_request->wiphy_idx);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001662
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001663 /*
1664 * Lets keep this simple -- we trust the first AP
1665 * after we intersect with CRDA
1666 */
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001667 if (likely(&drv_last_ie->wiphy == wiphy)) {
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001668 /*
1669 * Ignore IEs coming in on this wiphy with
1670 * the same alpha2 and environment cap
1671 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001672 if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2,
1673 alpha2) &&
1674 env == drv_last_ie->env)) {
1675 goto out;
1676 }
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001677 /*
1678 * the wiphy moved on to another BSSID or the AP
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001679 * was reconfigured. XXX: We need to deal with the
1680 * case where the user suspends and goes to goes
1681 * to another country, and then gets IEs from an
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001682 * AP with different settings
1683 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001684 goto out;
1685 } else {
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001686 /*
1687 * Ignore IEs coming in on two separate wiphys with
1688 * the same alpha2 and environment cap
1689 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001690 if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2,
1691 alpha2) &&
1692 env == drv_last_ie->env)) {
1693 goto out;
1694 }
1695 /* We could potentially intersect though */
1696 goto out;
1697 }
1698 }
1699
1700 rd = country_ie_2_rd(country_ie, country_ie_len, &checksum);
1701 if (!rd)
1702 goto out;
1703
Luis R. Rodriguez915278e2009-02-21 00:04:28 -05001704 /*
1705 * This will not happen right now but we leave it here for the
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001706 * the future when we want to add suspend/resume support and having
1707 * the user move to another country after doing so, or having the user
Luis R. Rodriguez915278e2009-02-21 00:04:28 -05001708 * move to another AP. Right now we just trust the first AP.
1709 *
1710 * If we hit this before we add this support we want to be informed of
1711 * it as it would indicate a mistake in the current design
1712 */
1713 if (WARN_ON(reg_same_country_ie_hint(wiphy, checksum)))
Luis R. Rodriguez0441d6f2009-02-21 00:04:29 -05001714 goto free_rd_out;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001715
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001716 request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
1717 if (!request)
1718 goto free_rd_out;
1719
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001720 /*
1721 * We keep this around for when CRDA comes back with a response so
1722 * we can intersect with that
1723 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001724 country_ie_regdomain = rd;
1725
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001726 request->wiphy_idx = get_wiphy_idx(wiphy);
1727 request->alpha2[0] = rd->alpha2[0];
1728 request->alpha2[1] = rd->alpha2[1];
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001729 request->initiator = NL80211_REGDOM_SET_BY_COUNTRY_IE;
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001730 request->country_ie_checksum = checksum;
1731 request->country_ie_env = env;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001732
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001733 mutex_unlock(&cfg80211_mutex);
1734
1735 queue_regulatory_request(request);
1736
1737 return;
Luis R. Rodriguez0441d6f2009-02-21 00:04:29 -05001738
1739free_rd_out:
1740 kfree(rd);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001741out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05001742 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001743}
1744EXPORT_SYMBOL(regulatory_hint_11d);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001745
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -05001746static bool freq_is_chan_12_13_14(u16 freq)
1747{
1748 if (freq == ieee80211_channel_to_frequency(12) ||
1749 freq == ieee80211_channel_to_frequency(13) ||
1750 freq == ieee80211_channel_to_frequency(14))
1751 return true;
1752 return false;
1753}
1754
1755int regulatory_hint_found_beacon(struct wiphy *wiphy,
1756 struct ieee80211_channel *beacon_chan,
1757 gfp_t gfp)
1758{
1759 struct reg_beacon *reg_beacon;
1760
1761 if (likely((beacon_chan->beacon_found ||
1762 (beacon_chan->flags & IEEE80211_CHAN_RADAR) ||
1763 (beacon_chan->band == IEEE80211_BAND_2GHZ &&
1764 !freq_is_chan_12_13_14(beacon_chan->center_freq)))))
1765 return 0;
1766
1767 reg_beacon = kzalloc(sizeof(struct reg_beacon), gfp);
1768 if (!reg_beacon)
1769 return -ENOMEM;
1770
1771#ifdef CONFIG_CFG80211_REG_DEBUG
1772 printk(KERN_DEBUG "cfg80211: Found new beacon on "
1773 "frequency: %d MHz (Ch %d) on %s\n",
1774 beacon_chan->center_freq,
1775 ieee80211_frequency_to_channel(beacon_chan->center_freq),
1776 wiphy_name(wiphy));
1777#endif
1778 memcpy(&reg_beacon->chan, beacon_chan,
1779 sizeof(struct ieee80211_channel));
1780
1781
1782 /*
1783 * Since we can be called from BH or and non-BH context
1784 * we must use spin_lock_bh()
1785 */
1786 spin_lock_bh(&reg_pending_beacons_lock);
1787 list_add_tail(&reg_beacon->list, &reg_pending_beacons);
1788 spin_unlock_bh(&reg_pending_beacons_lock);
1789
1790 schedule_work(&reg_work);
1791
1792 return 0;
1793}
1794
Johannes Berga3d2eaf2008-09-15 11:10:52 +02001795static void print_rd_rules(const struct ieee80211_regdomain *rd)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001796{
1797 unsigned int i;
Johannes Berga3d2eaf2008-09-15 11:10:52 +02001798 const struct ieee80211_reg_rule *reg_rule = NULL;
1799 const struct ieee80211_freq_range *freq_range = NULL;
1800 const struct ieee80211_power_rule *power_rule = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001801
1802 printk(KERN_INFO "\t(start_freq - end_freq @ bandwidth), "
1803 "(max_antenna_gain, max_eirp)\n");
1804
1805 for (i = 0; i < rd->n_reg_rules; i++) {
1806 reg_rule = &rd->reg_rules[i];
1807 freq_range = &reg_rule->freq_range;
1808 power_rule = &reg_rule->power_rule;
1809
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001810 /*
1811 * There may not be documentation for max antenna gain
1812 * in certain regions
1813 */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001814 if (power_rule->max_antenna_gain)
1815 printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), "
1816 "(%d mBi, %d mBm)\n",
1817 freq_range->start_freq_khz,
1818 freq_range->end_freq_khz,
1819 freq_range->max_bandwidth_khz,
1820 power_rule->max_antenna_gain,
1821 power_rule->max_eirp);
1822 else
1823 printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), "
1824 "(N/A, %d mBm)\n",
1825 freq_range->start_freq_khz,
1826 freq_range->end_freq_khz,
1827 freq_range->max_bandwidth_khz,
1828 power_rule->max_eirp);
1829 }
1830}
1831
Johannes Berga3d2eaf2008-09-15 11:10:52 +02001832static void print_regdomain(const struct ieee80211_regdomain *rd)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001833{
1834
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001835 if (is_intersected_alpha2(rd->alpha2)) {
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001836
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001837 if (last_request->initiator ==
1838 NL80211_REGDOM_SET_BY_COUNTRY_IE) {
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001839 struct cfg80211_registered_device *drv;
1840 drv = cfg80211_drv_by_wiphy_idx(
1841 last_request->wiphy_idx);
1842 if (drv) {
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001843 printk(KERN_INFO "cfg80211: Current regulatory "
1844 "domain updated by AP to: %c%c\n",
1845 drv->country_ie_alpha2[0],
1846 drv->country_ie_alpha2[1]);
1847 } else
1848 printk(KERN_INFO "cfg80211: Current regulatory "
1849 "domain intersected: \n");
1850 } else
1851 printk(KERN_INFO "cfg80211: Current regulatory "
Luis R. Rodriguez039498c2009-01-07 17:43:35 -08001852 "domain intersected: \n");
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001853 } else if (is_world_regdom(rd->alpha2))
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001854 printk(KERN_INFO "cfg80211: World regulatory "
1855 "domain updated:\n");
1856 else {
1857 if (is_unknown_alpha2(rd->alpha2))
1858 printk(KERN_INFO "cfg80211: Regulatory domain "
1859 "changed to driver built-in settings "
1860 "(unknown country)\n");
1861 else
1862 printk(KERN_INFO "cfg80211: Regulatory domain "
1863 "changed to country: %c%c\n",
1864 rd->alpha2[0], rd->alpha2[1]);
1865 }
1866 print_rd_rules(rd);
1867}
1868
Johannes Berg2df78162008-10-28 16:49:41 +01001869static void print_regdomain_info(const struct ieee80211_regdomain *rd)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001870{
1871 printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n",
1872 rd->alpha2[0], rd->alpha2[1]);
1873 print_rd_rules(rd);
1874}
1875
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001876#ifdef CONFIG_CFG80211_REG_DEBUG
1877static void reg_country_ie_process_debug(
1878 const struct ieee80211_regdomain *rd,
1879 const struct ieee80211_regdomain *country_ie_regdomain,
1880 const struct ieee80211_regdomain *intersected_rd)
1881{
1882 printk(KERN_DEBUG "cfg80211: Received country IE:\n");
1883 print_regdomain_info(country_ie_regdomain);
1884 printk(KERN_DEBUG "cfg80211: CRDA thinks this should applied:\n");
1885 print_regdomain_info(rd);
1886 if (intersected_rd) {
1887 printk(KERN_DEBUG "cfg80211: We intersect both of these "
1888 "and get:\n");
Luis R. Rodriguez667ecd02009-01-22 15:05:43 -08001889 print_regdomain_info(intersected_rd);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001890 return;
1891 }
1892 printk(KERN_DEBUG "cfg80211: Intersection between both failed\n");
1893}
1894#else
1895static inline void reg_country_ie_process_debug(
1896 const struct ieee80211_regdomain *rd,
1897 const struct ieee80211_regdomain *country_ie_regdomain,
1898 const struct ieee80211_regdomain *intersected_rd)
1899{
1900}
1901#endif
1902
Johannes Bergd2372b32008-10-24 20:32:20 +02001903/* Takes ownership of rd only if it doesn't fail */
Johannes Berga3d2eaf2008-09-15 11:10:52 +02001904static int __set_regdom(const struct ieee80211_regdomain *rd)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001905{
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001906 const struct ieee80211_regdomain *intersected_rd = NULL;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001907 struct cfg80211_registered_device *drv = NULL;
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001908 struct wiphy *request_wiphy;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001909 /* Some basic sanity checks first */
1910
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001911 if (is_world_regdom(rd->alpha2)) {
Johannes Bergf6037d02008-10-21 11:01:33 +02001912 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001913 return -EINVAL;
1914 update_world_regdomain(rd);
1915 return 0;
1916 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001917
1918 if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) &&
1919 !is_unknown_alpha2(rd->alpha2))
1920 return -EINVAL;
1921
Johannes Bergf6037d02008-10-21 11:01:33 +02001922 if (!last_request)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001923 return -EINVAL;
1924
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001925 /*
1926 * Lets only bother proceeding on the same alpha2 if the current
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001927 * rd is non static (it means CRDA was present and was used last)
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001928 * and the pending request came in from a country IE
1929 */
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001930 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001931 /*
1932 * If someone else asked us to change the rd lets only bother
1933 * checking if the alpha2 changes if CRDA was already called
1934 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001935 if (!is_old_static_regdom(cfg80211_regdomain) &&
Luis R. Rodriguez69b15722009-02-21 00:04:33 -05001936 !regdom_changes(rd->alpha2))
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001937 return -EINVAL;
1938 }
1939
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001940 /*
1941 * Now lets set the regulatory domain, update all driver channels
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001942 * and finally inform them of what we have done, in case they want
1943 * to review or adjust their own settings based on their own
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001944 * internal EEPROM data
1945 */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001946
Johannes Bergf6037d02008-10-21 11:01:33 +02001947 if (WARN_ON(!reg_is_valid_request(rd->alpha2)))
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001948 return -EINVAL;
1949
Luis R. Rodriguez8375af32008-11-12 14:21:57 -08001950 if (!is_valid_rd(rd)) {
1951 printk(KERN_ERR "cfg80211: Invalid "
1952 "regulatory domain detected:\n");
1953 print_regdomain_info(rd);
1954 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07001955 }
1956
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001957 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
1958
Luis R. Rodriguezb8295ac2008-11-12 14:21:58 -08001959 if (!last_request->intersect) {
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001960 int r;
1961
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001962 if (last_request->initiator != NL80211_REGDOM_SET_BY_DRIVER) {
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001963 reset_regdomains();
1964 cfg80211_regdomain = rd;
1965 return 0;
1966 }
1967
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001968 /*
1969 * For a driver hint, lets copy the regulatory domain the
1970 * driver wanted to the wiphy to deal with conflicts
1971 */
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001972
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001973 BUG_ON(request_wiphy->regd);
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001974
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001975 r = reg_copy_regd(&request_wiphy->regd, rd);
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001976 if (r)
1977 return r;
1978
Luis R. Rodriguezb8295ac2008-11-12 14:21:58 -08001979 reset_regdomains();
1980 cfg80211_regdomain = rd;
1981 return 0;
1982 }
1983
1984 /* Intersection requires a bit more work */
1985
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001986 if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) {
Luis R. Rodriguezb8295ac2008-11-12 14:21:58 -08001987
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07001988 intersected_rd = regdom_intersect(rd, cfg80211_regdomain);
1989 if (!intersected_rd)
1990 return -EINVAL;
Luis R. Rodriguezb8295ac2008-11-12 14:21:58 -08001991
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001992 /*
1993 * We can trash what CRDA provided now.
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001994 * However if a driver requested this specific regulatory
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05001995 * domain we keep it for its private use
1996 */
Luis R. Rodriguez7db90f42009-03-09 22:07:41 -04001997 if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER)
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05001998 request_wiphy->regd = rd;
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08001999 else
2000 kfree(rd);
2001
Luis R. Rodriguezb8295ac2008-11-12 14:21:58 -08002002 rd = NULL;
2003
2004 reset_regdomains();
2005 cfg80211_regdomain = intersected_rd;
2006
2007 return 0;
Luis R. Rodriguez9c964772008-10-30 13:33:53 -07002008 }
2009
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002010 /*
2011 * Country IE requests are handled a bit differently, we intersect
2012 * the country IE rd with what CRDA believes that country should have
2013 */
2014
2015 BUG_ON(!country_ie_regdomain);
2016
2017 if (rd != country_ie_regdomain) {
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05002018 /*
2019 * Intersect what CRDA returned and our what we
2020 * had built from the Country IE received
2021 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002022
2023 intersected_rd = regdom_intersect(rd, country_ie_regdomain);
2024
2025 reg_country_ie_process_debug(rd, country_ie_regdomain,
2026 intersected_rd);
2027
2028 kfree(country_ie_regdomain);
2029 country_ie_regdomain = NULL;
2030 } else {
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05002031 /*
2032 * This would happen when CRDA was not present and
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002033 * OLD_REGULATORY was enabled. We intersect our Country
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05002034 * IE rd and what was set on cfg80211 originally
2035 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002036 intersected_rd = regdom_intersect(rd, cfg80211_regdomain);
2037 }
2038
2039 if (!intersected_rd)
2040 return -EINVAL;
2041
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05002042 drv = wiphy_to_dev(request_wiphy);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002043
2044 drv->country_ie_alpha2[0] = rd->alpha2[0];
2045 drv->country_ie_alpha2[1] = rd->alpha2[1];
2046 drv->env = last_request->country_ie_env;
2047
2048 BUG_ON(intersected_rd == rd);
2049
2050 kfree(rd);
2051 rd = NULL;
2052
Luis R. Rodriguezb8295ac2008-11-12 14:21:58 -08002053 reset_regdomains();
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002054 cfg80211_regdomain = intersected_rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002055
2056 return 0;
2057}
2058
2059
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05002060/*
2061 * Use this call to set the current regulatory domain. Conflicts with
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002062 * multiple drivers can be ironed out later. Caller must've already
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05002063 * kmalloc'd the rd structure. Caller must hold cfg80211_mutex
2064 */
Johannes Berga3d2eaf2008-09-15 11:10:52 +02002065int set_regdom(const struct ieee80211_regdomain *rd)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002066{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002067 int r;
2068
Luis R. Rodriguez761cf7e2009-02-21 00:04:25 -05002069 assert_cfg80211_lock();
2070
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002071 /* Note that this doesn't update the wiphys, this is done below */
2072 r = __set_regdom(rd);
Johannes Bergd2372b32008-10-24 20:32:20 +02002073 if (r) {
2074 kfree(rd);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002075 return r;
Johannes Bergd2372b32008-10-24 20:32:20 +02002076 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002077
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002078 /* This would make this whole thing pointless */
Luis R. Rodrigueza01ddaf2008-11-12 14:21:59 -08002079 if (!last_request->intersect)
2080 BUG_ON(rd != cfg80211_regdomain);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002081
2082 /* update all wiphys now with the new established regulatory domain */
Johannes Bergf6037d02008-10-21 11:01:33 +02002083 update_all_wiphy_regulatory(last_request->initiator);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002084
Luis R. Rodrigueza01ddaf2008-11-12 14:21:59 -08002085 print_regdomain(cfg80211_regdomain);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002086
2087 return r;
2088}
2089
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002090/* Caller must hold cfg80211_mutex */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002091void reg_device_remove(struct wiphy *wiphy)
2092{
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05002093 struct wiphy *request_wiphy;
2094
Luis R. Rodriguez761cf7e2009-02-21 00:04:25 -05002095 assert_cfg80211_lock();
2096
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05002097 request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
2098
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -08002099 kfree(wiphy->regd);
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05002100 if (!last_request || !request_wiphy)
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002101 return;
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05002102 if (request_wiphy != wiphy)
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002103 return;
Luis R. Rodriguez806a9e32009-02-21 00:04:26 -05002104 last_request->wiphy_idx = WIPHY_IDX_STALE;
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002105 last_request->country_ie_env = ENVIRON_ANY;
2106}
2107
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002108int regulatory_init(void)
2109{
Luis R. Rodriguezbcf4f992009-02-21 00:04:24 -05002110 int err = 0;
Johannes Berg734366d2008-09-15 10:56:48 +02002111
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002112 reg_pdev = platform_device_register_simple("regulatory", 0, NULL, 0);
2113 if (IS_ERR(reg_pdev))
2114 return PTR_ERR(reg_pdev);
Johannes Berg734366d2008-09-15 10:56:48 +02002115
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002116 spin_lock_init(&reg_requests_lock);
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -05002117 spin_lock_init(&reg_pending_beacons_lock);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002118
Johannes Berg734366d2008-09-15 10:56:48 +02002119#ifdef CONFIG_WIRELESS_OLD_REGULATORY
Johannes Berga3d2eaf2008-09-15 11:10:52 +02002120 cfg80211_regdomain = static_regdom(ieee80211_regdom);
Johannes Berg734366d2008-09-15 10:56:48 +02002121
Johannes Berg942b25c2008-09-15 11:26:47 +02002122 printk(KERN_INFO "cfg80211: Using static regulatory domain info\n");
Johannes Berg734366d2008-09-15 10:56:48 +02002123 print_regdomain_info(cfg80211_regdomain);
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05002124 /*
2125 * The old code still requests for a new regdomain and if
Johannes Berg734366d2008-09-15 10:56:48 +02002126 * you have CRDA you get it updated, otherwise you get
2127 * stuck with the static values. We ignore "EU" code as
Luis R. Rodriguezfb1fc7a2009-02-21 00:04:31 -05002128 * that is not a valid ISO / IEC 3166 alpha2
2129 */
Johannes Bergac9440a2008-10-21 11:08:27 +02002130 if (ieee80211_regdom[0] != 'E' || ieee80211_regdom[1] != 'U')
Luis R. Rodriguezba25c142009-02-21 00:04:23 -05002131 err = regulatory_hint_core(ieee80211_regdom);
Johannes Berg734366d2008-09-15 10:56:48 +02002132#else
Johannes Berga3d2eaf2008-09-15 11:10:52 +02002133 cfg80211_regdomain = cfg80211_world_regdom;
Johannes Berg734366d2008-09-15 10:56:48 +02002134
Luis R. Rodriguezba25c142009-02-21 00:04:23 -05002135 err = regulatory_hint_core("00");
Johannes Berg734366d2008-09-15 10:56:48 +02002136#endif
Luis R. Rodriguezbcf4f992009-02-21 00:04:24 -05002137 if (err) {
2138 if (err == -ENOMEM)
2139 return err;
2140 /*
2141 * N.B. kobject_uevent_env() can fail mainly for when we're out
2142 * memory which is handled and propagated appropriately above
2143 * but it can also fail during a netlink_broadcast() or during
2144 * early boot for call_usermodehelper(). For now treat these
2145 * errors as non-fatal.
2146 */
2147 printk(KERN_ERR "cfg80211: kobject_uevent_env() was unable "
2148 "to call CRDA during init");
2149#ifdef CONFIG_CFG80211_REG_DEBUG
2150 /* We want to find out exactly why when debugging */
2151 WARN_ON(err);
2152#endif
2153 }
Johannes Berg734366d2008-09-15 10:56:48 +02002154
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002155 return 0;
2156}
2157
2158void regulatory_exit(void)
2159{
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002160 struct regulatory_request *reg_request, *tmp;
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -05002161 struct reg_beacon *reg_beacon, *btmp;
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002162
2163 cancel_work_sync(&reg_work);
2164
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002165 mutex_lock(&cfg80211_mutex);
Johannes Berg734366d2008-09-15 10:56:48 +02002166
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002167 reset_regdomains();
Johannes Berg734366d2008-09-15 10:56:48 +02002168
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08002169 kfree(country_ie_regdomain);
2170 country_ie_regdomain = NULL;
2171
Johannes Bergf6037d02008-10-21 11:01:33 +02002172 kfree(last_request);
2173
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002174 platform_device_unregister(reg_pdev);
Johannes Berg734366d2008-09-15 10:56:48 +02002175
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -05002176 spin_lock_bh(&reg_pending_beacons_lock);
2177 if (!list_empty(&reg_pending_beacons)) {
2178 list_for_each_entry_safe(reg_beacon, btmp,
2179 &reg_pending_beacons, list) {
2180 list_del(&reg_beacon->list);
2181 kfree(reg_beacon);
2182 }
2183 }
2184 spin_unlock_bh(&reg_pending_beacons_lock);
2185
2186 if (!list_empty(&reg_beacon_list)) {
2187 list_for_each_entry_safe(reg_beacon, btmp,
2188 &reg_beacon_list, list) {
2189 list_del(&reg_beacon->list);
2190 kfree(reg_beacon);
2191 }
2192 }
2193
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002194 spin_lock(&reg_requests_lock);
2195 if (!list_empty(&reg_requests_list)) {
2196 list_for_each_entry_safe(reg_request, tmp,
2197 &reg_requests_list, list) {
2198 list_del(&reg_request->list);
2199 kfree(reg_request);
2200 }
2201 }
2202 spin_unlock(&reg_requests_lock);
2203
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002204 mutex_unlock(&cfg80211_mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01002205}