Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 3 | * Copyright 2005-2006, Devicescape Software, Inc. |
| 4 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5 | * Copyright 2008 Luis R. Rodriguez <lrodriguz@atheros.com> |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6 | * |
| 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. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12 | /** |
| 13 | * DOC: Wireless regulatory infrastructure |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 14 | * |
| 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. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 20 | * Another set of compliance enforcement is for drivers to use their |
| 21 | * own compliance limits which can be stored on the EEPROM. The host |
| 22 | * driver or firmware may ensure these are used. |
| 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 Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 34 | */ |
| 35 | #include <linux/kernel.h> |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 36 | #include <linux/list.h> |
| 37 | #include <linux/random.h> |
| 38 | #include <linux/nl80211.h> |
| 39 | #include <linux/platform_device.h> |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 40 | #include <net/wireless.h> |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 41 | #include <net/cfg80211.h> |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 42 | #include "core.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 43 | #include "reg.h" |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 44 | #include "nl80211.h" |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 45 | |
Luis R. Rodriguez | 5166ccd | 2008-10-30 13:33:56 -0700 | [diff] [blame] | 46 | /* Receipt of information from last regulatory request */ |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 47 | static struct regulatory_request *last_request; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 48 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 49 | /* To trigger userspace events */ |
| 50 | static struct platform_device *reg_pdev; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 51 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 52 | /* Keep the ordering from large to small */ |
| 53 | static u32 supported_bandwidths[] = { |
| 54 | MHZ_TO_KHZ(40), |
| 55 | MHZ_TO_KHZ(20), |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 58 | /* |
| 59 | * Central wireless core regulatory domains, we only need two, |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 60 | * the current one and a world regulatory domain in case we have no |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 61 | * information to give us an alpha2 |
| 62 | */ |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 63 | const struct ieee80211_regdomain *cfg80211_regdomain; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 64 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 65 | /* |
| 66 | * We use this as a place for the rd structure built from the |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 67 | * last parsed country IE to rest until CRDA gets back to us with |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 68 | * what it thinks should apply for the same country |
| 69 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 70 | static const struct ieee80211_regdomain *country_ie_regdomain; |
| 71 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 72 | /* Used to queue up regulatory hints */ |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 73 | static LIST_HEAD(reg_requests_list); |
| 74 | static spinlock_t reg_requests_lock; |
| 75 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 76 | /* Used to queue up beacon hints for review */ |
| 77 | static LIST_HEAD(reg_pending_beacons); |
| 78 | static spinlock_t reg_pending_beacons_lock; |
| 79 | |
| 80 | /* Used to keep track of processed beacon hints */ |
| 81 | static LIST_HEAD(reg_beacon_list); |
| 82 | |
| 83 | struct reg_beacon { |
| 84 | struct list_head list; |
| 85 | struct ieee80211_channel chan; |
| 86 | }; |
| 87 | |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 88 | /* We keep a static world regulatory domain in case of the absence of CRDA */ |
| 89 | static const struct ieee80211_regdomain world_regdom = { |
Luis R. Rodriguez | 611b6a8 | 2009-03-05 21:19:21 -0800 | [diff] [blame] | 90 | .n_reg_rules = 5, |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 91 | .alpha2 = "00", |
| 92 | .reg_rules = { |
Luis R. Rodriguez | 68798a6 | 2009-02-21 00:20:37 -0500 | [diff] [blame] | 93 | /* IEEE 802.11b/g, channels 1..11 */ |
| 94 | REG_RULE(2412-10, 2462+10, 40, 6, 20, 0), |
Luis R. Rodriguez | 611b6a8 | 2009-03-05 21:19:21 -0800 | [diff] [blame] | 95 | /* IEEE 802.11b/g, channels 12..13. No HT40 |
| 96 | * channel fits here. */ |
| 97 | REG_RULE(2467-10, 2472+10, 20, 6, 20, |
Luis R. Rodriguez | 3fc71f7 | 2009-02-21 00:20:38 -0500 | [diff] [blame] | 98 | NL80211_RRF_PASSIVE_SCAN | |
| 99 | NL80211_RRF_NO_IBSS), |
Luis R. Rodriguez | 611b6a8 | 2009-03-05 21:19:21 -0800 | [diff] [blame] | 100 | /* IEEE 802.11 channel 14 - Only JP enables |
| 101 | * this and for 802.11b only */ |
| 102 | REG_RULE(2484-10, 2484+10, 20, 6, 20, |
| 103 | NL80211_RRF_PASSIVE_SCAN | |
| 104 | NL80211_RRF_NO_IBSS | |
| 105 | NL80211_RRF_NO_OFDM), |
| 106 | /* IEEE 802.11a, channel 36..48 */ |
Luis R. Rodriguez | ec329ac | 2009-03-05 21:19:22 -0800 | [diff] [blame] | 107 | REG_RULE(5180-10, 5240+10, 40, 6, 20, |
Luis R. Rodriguez | 611b6a8 | 2009-03-05 21:19:21 -0800 | [diff] [blame] | 108 | NL80211_RRF_PASSIVE_SCAN | |
| 109 | NL80211_RRF_NO_IBSS), |
Luis R. Rodriguez | 3fc71f7 | 2009-02-21 00:20:38 -0500 | [diff] [blame] | 110 | |
| 111 | /* NB: 5260 MHz - 5700 MHz requies DFS */ |
| 112 | |
| 113 | /* IEEE 802.11a, channel 149..165 */ |
Luis R. Rodriguez | ec329ac | 2009-03-05 21:19:22 -0800 | [diff] [blame] | 114 | REG_RULE(5745-10, 5825+10, 40, 6, 20, |
Luis R. Rodriguez | 3fc71f7 | 2009-02-21 00:20:38 -0500 | [diff] [blame] | 115 | NL80211_RRF_PASSIVE_SCAN | |
| 116 | NL80211_RRF_NO_IBSS), |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 117 | } |
| 118 | }; |
| 119 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 120 | static const struct ieee80211_regdomain *cfg80211_world_regdom = |
| 121 | &world_regdom; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 122 | |
| 123 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY |
| 124 | static char *ieee80211_regdom = "US"; |
Luis R. Rodriguez | 6ee7d33 | 2009-03-20 23:53:06 -0400 | [diff] [blame] | 125 | #else |
| 126 | static char *ieee80211_regdom = "00"; |
| 127 | #endif |
| 128 | |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 129 | module_param(ieee80211_regdom, charp, 0444); |
| 130 | MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code"); |
| 131 | |
Luis R. Rodriguez | 6ee7d33 | 2009-03-20 23:53:06 -0400 | [diff] [blame] | 132 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 133 | /* |
| 134 | * We assume 40 MHz bandwidth for the old regulatory work. |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 135 | * We make emphasis we are using the exact same frequencies |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 136 | * as before |
| 137 | */ |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 138 | |
| 139 | static const struct ieee80211_regdomain us_regdom = { |
| 140 | .n_reg_rules = 6, |
| 141 | .alpha2 = "US", |
| 142 | .reg_rules = { |
| 143 | /* IEEE 802.11b/g, channels 1..11 */ |
| 144 | REG_RULE(2412-10, 2462+10, 40, 6, 27, 0), |
| 145 | /* IEEE 802.11a, channel 36 */ |
| 146 | REG_RULE(5180-10, 5180+10, 40, 6, 23, 0), |
| 147 | /* IEEE 802.11a, channel 40 */ |
| 148 | REG_RULE(5200-10, 5200+10, 40, 6, 23, 0), |
| 149 | /* IEEE 802.11a, channel 44 */ |
| 150 | REG_RULE(5220-10, 5220+10, 40, 6, 23, 0), |
| 151 | /* IEEE 802.11a, channels 48..64 */ |
| 152 | REG_RULE(5240-10, 5320+10, 40, 6, 23, 0), |
| 153 | /* IEEE 802.11a, channels 149..165, outdoor */ |
| 154 | REG_RULE(5745-10, 5825+10, 40, 6, 30, 0), |
| 155 | } |
| 156 | }; |
| 157 | |
| 158 | static const struct ieee80211_regdomain jp_regdom = { |
| 159 | .n_reg_rules = 3, |
| 160 | .alpha2 = "JP", |
| 161 | .reg_rules = { |
| 162 | /* IEEE 802.11b/g, channels 1..14 */ |
| 163 | REG_RULE(2412-10, 2484+10, 40, 6, 20, 0), |
| 164 | /* IEEE 802.11a, channels 34..48 */ |
| 165 | REG_RULE(5170-10, 5240+10, 40, 6, 20, |
| 166 | NL80211_RRF_PASSIVE_SCAN), |
| 167 | /* IEEE 802.11a, channels 52..64 */ |
| 168 | REG_RULE(5260-10, 5320+10, 40, 6, 20, |
| 169 | NL80211_RRF_NO_IBSS | |
| 170 | NL80211_RRF_DFS), |
| 171 | } |
| 172 | }; |
| 173 | |
| 174 | static const struct ieee80211_regdomain eu_regdom = { |
| 175 | .n_reg_rules = 6, |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 176 | /* |
| 177 | * This alpha2 is bogus, we leave it here just for stupid |
| 178 | * backward compatibility |
| 179 | */ |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 180 | .alpha2 = "EU", |
| 181 | .reg_rules = { |
| 182 | /* IEEE 802.11b/g, channels 1..13 */ |
| 183 | REG_RULE(2412-10, 2472+10, 40, 6, 20, 0), |
| 184 | /* IEEE 802.11a, channel 36 */ |
| 185 | REG_RULE(5180-10, 5180+10, 40, 6, 23, |
| 186 | NL80211_RRF_PASSIVE_SCAN), |
| 187 | /* IEEE 802.11a, channel 40 */ |
| 188 | REG_RULE(5200-10, 5200+10, 40, 6, 23, |
| 189 | NL80211_RRF_PASSIVE_SCAN), |
| 190 | /* IEEE 802.11a, channel 44 */ |
| 191 | REG_RULE(5220-10, 5220+10, 40, 6, 23, |
| 192 | NL80211_RRF_PASSIVE_SCAN), |
| 193 | /* IEEE 802.11a, channels 48..64 */ |
| 194 | REG_RULE(5240-10, 5320+10, 40, 6, 20, |
| 195 | NL80211_RRF_NO_IBSS | |
| 196 | NL80211_RRF_DFS), |
| 197 | /* IEEE 802.11a, channels 100..140 */ |
| 198 | REG_RULE(5500-10, 5700+10, 40, 6, 30, |
| 199 | NL80211_RRF_NO_IBSS | |
| 200 | NL80211_RRF_DFS), |
| 201 | } |
| 202 | }; |
| 203 | |
| 204 | static const struct ieee80211_regdomain *static_regdom(char *alpha2) |
| 205 | { |
| 206 | if (alpha2[0] == 'U' && alpha2[1] == 'S') |
| 207 | return &us_regdom; |
| 208 | if (alpha2[0] == 'J' && alpha2[1] == 'P') |
| 209 | return &jp_regdom; |
| 210 | if (alpha2[0] == 'E' && alpha2[1] == 'U') |
| 211 | return &eu_regdom; |
| 212 | /* Default, as per the old rules */ |
| 213 | return &us_regdom; |
| 214 | } |
| 215 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 216 | static bool is_old_static_regdom(const struct ieee80211_regdomain *rd) |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 217 | { |
| 218 | if (rd == &us_regdom || rd == &jp_regdom || rd == &eu_regdom) |
| 219 | return true; |
| 220 | return false; |
| 221 | } |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 222 | #else |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 223 | static inline bool is_old_static_regdom(const struct ieee80211_regdomain *rd) |
| 224 | { |
| 225 | return false; |
| 226 | } |
| 227 | #endif |
| 228 | |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 229 | static void reset_regdomains(void) |
| 230 | { |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 231 | /* avoid freeing static information or freeing something twice */ |
| 232 | if (cfg80211_regdomain == cfg80211_world_regdom) |
| 233 | cfg80211_regdomain = NULL; |
| 234 | if (cfg80211_world_regdom == &world_regdom) |
| 235 | cfg80211_world_regdom = NULL; |
| 236 | if (cfg80211_regdomain == &world_regdom) |
| 237 | cfg80211_regdomain = NULL; |
| 238 | if (is_old_static_regdom(cfg80211_regdomain)) |
| 239 | cfg80211_regdomain = NULL; |
| 240 | |
| 241 | kfree(cfg80211_regdomain); |
| 242 | kfree(cfg80211_world_regdom); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 243 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 244 | cfg80211_world_regdom = &world_regdom; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 245 | cfg80211_regdomain = NULL; |
| 246 | } |
| 247 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 248 | /* |
| 249 | * Dynamic world regulatory domain requested by the wireless |
| 250 | * core upon initialization |
| 251 | */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 252 | static void update_world_regdomain(const struct ieee80211_regdomain *rd) |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 253 | { |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 254 | BUG_ON(!last_request); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 255 | |
| 256 | reset_regdomains(); |
| 257 | |
| 258 | cfg80211_world_regdom = rd; |
| 259 | cfg80211_regdomain = rd; |
| 260 | } |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 261 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 262 | bool is_world_regdom(const char *alpha2) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 263 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 264 | if (!alpha2) |
| 265 | return false; |
| 266 | if (alpha2[0] == '0' && alpha2[1] == '0') |
| 267 | return true; |
| 268 | return false; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 269 | } |
| 270 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 271 | static bool is_alpha2_set(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 272 | { |
| 273 | if (!alpha2) |
| 274 | return false; |
| 275 | if (alpha2[0] != 0 && alpha2[1] != 0) |
| 276 | return true; |
| 277 | return false; |
| 278 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 279 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 280 | static bool is_alpha_upper(char letter) |
| 281 | { |
| 282 | /* ASCII A - Z */ |
| 283 | if (letter >= 65 && letter <= 90) |
| 284 | return true; |
| 285 | return false; |
| 286 | } |
| 287 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 288 | static bool is_unknown_alpha2(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 289 | { |
| 290 | if (!alpha2) |
| 291 | return false; |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 292 | /* |
| 293 | * Special case where regulatory domain was built by driver |
| 294 | * but a specific alpha2 cannot be determined |
| 295 | */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 296 | if (alpha2[0] == '9' && alpha2[1] == '9') |
| 297 | return true; |
| 298 | return false; |
| 299 | } |
| 300 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 301 | static bool is_intersected_alpha2(const char *alpha2) |
| 302 | { |
| 303 | if (!alpha2) |
| 304 | return false; |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 305 | /* |
| 306 | * Special case where regulatory domain is the |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 307 | * result of an intersection between two regulatory domain |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 308 | * structures |
| 309 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 310 | if (alpha2[0] == '9' && alpha2[1] == '8') |
| 311 | return true; |
| 312 | return false; |
| 313 | } |
| 314 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 315 | static bool is_an_alpha2(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 316 | { |
| 317 | if (!alpha2) |
| 318 | return false; |
| 319 | if (is_alpha_upper(alpha2[0]) && is_alpha_upper(alpha2[1])) |
| 320 | return true; |
| 321 | return false; |
| 322 | } |
| 323 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 324 | static bool alpha2_equal(const char *alpha2_x, const char *alpha2_y) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 325 | { |
| 326 | if (!alpha2_x || !alpha2_y) |
| 327 | return false; |
| 328 | if (alpha2_x[0] == alpha2_y[0] && |
| 329 | alpha2_x[1] == alpha2_y[1]) |
| 330 | return true; |
| 331 | return false; |
| 332 | } |
| 333 | |
Luis R. Rodriguez | 69b1572 | 2009-02-21 00:04:33 -0500 | [diff] [blame] | 334 | static bool regdom_changes(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 335 | { |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 336 | assert_cfg80211_lock(); |
| 337 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 338 | if (!cfg80211_regdomain) |
| 339 | return true; |
| 340 | if (alpha2_equal(cfg80211_regdomain->alpha2, alpha2)) |
| 341 | return false; |
| 342 | return true; |
| 343 | } |
| 344 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 345 | /** |
| 346 | * country_ie_integrity_changes - tells us if the country IE has changed |
| 347 | * @checksum: checksum of country IE of fields we are interested in |
| 348 | * |
| 349 | * If the country IE has not changed you can ignore it safely. This is |
| 350 | * useful to determine if two devices are seeing two different country IEs |
| 351 | * even on the same alpha2. Note that this will return false if no IE has |
| 352 | * been set on the wireless core yet. |
| 353 | */ |
| 354 | static bool country_ie_integrity_changes(u32 checksum) |
| 355 | { |
| 356 | /* If no IE has been set then the checksum doesn't change */ |
| 357 | if (unlikely(!last_request->country_ie_checksum)) |
| 358 | return false; |
| 359 | if (unlikely(last_request->country_ie_checksum != checksum)) |
| 360 | return true; |
| 361 | return false; |
| 362 | } |
| 363 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 364 | /* |
| 365 | * This lets us keep regulatory code which is updated on a regulatory |
| 366 | * basis in userspace. |
| 367 | */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 368 | static int call_crda(const char *alpha2) |
| 369 | { |
| 370 | char country_env[9 + 2] = "COUNTRY="; |
| 371 | char *envp[] = { |
| 372 | country_env, |
| 373 | NULL |
| 374 | }; |
| 375 | |
| 376 | if (!is_world_regdom((char *) alpha2)) |
| 377 | printk(KERN_INFO "cfg80211: Calling CRDA for country: %c%c\n", |
| 378 | alpha2[0], alpha2[1]); |
| 379 | else |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 380 | printk(KERN_INFO "cfg80211: Calling CRDA to update world " |
| 381 | "regulatory domain\n"); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 382 | |
| 383 | country_env[8] = alpha2[0]; |
| 384 | country_env[9] = alpha2[1]; |
| 385 | |
| 386 | return kobject_uevent_env(®_pdev->dev.kobj, KOBJ_CHANGE, envp); |
| 387 | } |
| 388 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 389 | /* Used by nl80211 before kmalloc'ing our regulatory domain */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 390 | bool reg_is_valid_request(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 391 | { |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 392 | if (!last_request) |
| 393 | return false; |
| 394 | |
| 395 | return alpha2_equal(last_request->alpha2, alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /* Sanity check on a regulatory rule */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 399 | static bool is_valid_reg_rule(const struct ieee80211_reg_rule *rule) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 400 | { |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 401 | const struct ieee80211_freq_range *freq_range = &rule->freq_range; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 402 | u32 freq_diff; |
| 403 | |
Luis R. Rodriguez | 91e9900 | 2008-11-12 14:21:55 -0800 | [diff] [blame] | 404 | if (freq_range->start_freq_khz <= 0 || freq_range->end_freq_khz <= 0) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 405 | return false; |
| 406 | |
| 407 | if (freq_range->start_freq_khz > freq_range->end_freq_khz) |
| 408 | return false; |
| 409 | |
| 410 | freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; |
| 411 | |
Roel Kluin | bd05f28 | 2009-03-03 22:55:21 +0100 | [diff] [blame] | 412 | if (freq_range->end_freq_khz <= freq_range->start_freq_khz || |
| 413 | freq_range->max_bandwidth_khz > freq_diff) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 414 | return false; |
| 415 | |
| 416 | return true; |
| 417 | } |
| 418 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 419 | static bool is_valid_rd(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 420 | { |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 421 | const struct ieee80211_reg_rule *reg_rule = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 422 | unsigned int i; |
| 423 | |
| 424 | if (!rd->n_reg_rules) |
| 425 | return false; |
| 426 | |
Luis R. Rodriguez | 88dc1c3 | 2008-11-12 14:22:01 -0800 | [diff] [blame] | 427 | if (WARN_ON(rd->n_reg_rules > NL80211_MAX_SUPP_REG_RULES)) |
| 428 | return false; |
| 429 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 430 | for (i = 0; i < rd->n_reg_rules; i++) { |
| 431 | reg_rule = &rd->reg_rules[i]; |
| 432 | if (!is_valid_reg_rule(reg_rule)) |
| 433 | return false; |
| 434 | } |
| 435 | |
| 436 | return true; |
| 437 | } |
| 438 | |
| 439 | /* Returns value in KHz */ |
| 440 | static u32 freq_max_bandwidth(const struct ieee80211_freq_range *freq_range, |
| 441 | u32 freq) |
| 442 | { |
| 443 | unsigned int i; |
| 444 | for (i = 0; i < ARRAY_SIZE(supported_bandwidths); i++) { |
| 445 | u32 start_freq_khz = freq - supported_bandwidths[i]/2; |
| 446 | u32 end_freq_khz = freq + supported_bandwidths[i]/2; |
| 447 | if (start_freq_khz >= freq_range->start_freq_khz && |
| 448 | end_freq_khz <= freq_range->end_freq_khz) |
| 449 | return supported_bandwidths[i]; |
| 450 | } |
| 451 | return 0; |
| 452 | } |
| 453 | |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 454 | /** |
| 455 | * freq_in_rule_band - tells us if a frequency is in a frequency band |
| 456 | * @freq_range: frequency rule we want to query |
| 457 | * @freq_khz: frequency we are inquiring about |
| 458 | * |
| 459 | * This lets us know if a specific frequency rule is or is not relevant to |
| 460 | * a specific frequency's band. Bands are device specific and artificial |
| 461 | * definitions (the "2.4 GHz band" and the "5 GHz band"), however it is |
| 462 | * safe for now to assume that a frequency rule should not be part of a |
| 463 | * frequency's band if the start freq or end freq are off by more than 2 GHz. |
| 464 | * This resolution can be lowered and should be considered as we add |
| 465 | * regulatory rule support for other "bands". |
| 466 | **/ |
| 467 | static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range, |
| 468 | u32 freq_khz) |
| 469 | { |
| 470 | #define ONE_GHZ_IN_KHZ 1000000 |
| 471 | if (abs(freq_khz - freq_range->start_freq_khz) <= (2 * ONE_GHZ_IN_KHZ)) |
| 472 | return true; |
| 473 | if (abs(freq_khz - freq_range->end_freq_khz) <= (2 * ONE_GHZ_IN_KHZ)) |
| 474 | return true; |
| 475 | return false; |
| 476 | #undef ONE_GHZ_IN_KHZ |
| 477 | } |
| 478 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 479 | /* |
| 480 | * Converts a country IE to a regulatory domain. A regulatory domain |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 481 | * structure has a lot of information which the IE doesn't yet have, |
| 482 | * so for the other values we use upper max values as we will intersect |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 483 | * with our userspace regulatory agent to get lower bounds. |
| 484 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 485 | static struct ieee80211_regdomain *country_ie_2_rd( |
| 486 | u8 *country_ie, |
| 487 | u8 country_ie_len, |
| 488 | u32 *checksum) |
| 489 | { |
| 490 | struct ieee80211_regdomain *rd = NULL; |
| 491 | unsigned int i = 0; |
| 492 | char alpha2[2]; |
| 493 | u32 flags = 0; |
| 494 | u32 num_rules = 0, size_of_regd = 0; |
| 495 | u8 *triplets_start = NULL; |
| 496 | u8 len_at_triplet = 0; |
| 497 | /* the last channel we have registered in a subband (triplet) */ |
| 498 | int last_sub_max_channel = 0; |
| 499 | |
| 500 | *checksum = 0xDEADBEEF; |
| 501 | |
| 502 | /* Country IE requirements */ |
| 503 | BUG_ON(country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN || |
| 504 | country_ie_len & 0x01); |
| 505 | |
| 506 | alpha2[0] = country_ie[0]; |
| 507 | alpha2[1] = country_ie[1]; |
| 508 | |
| 509 | /* |
| 510 | * Third octet can be: |
| 511 | * 'I' - Indoor |
| 512 | * 'O' - Outdoor |
| 513 | * |
| 514 | * anything else we assume is no restrictions |
| 515 | */ |
| 516 | if (country_ie[2] == 'I') |
| 517 | flags = NL80211_RRF_NO_OUTDOOR; |
| 518 | else if (country_ie[2] == 'O') |
| 519 | flags = NL80211_RRF_NO_INDOOR; |
| 520 | |
| 521 | country_ie += 3; |
| 522 | country_ie_len -= 3; |
| 523 | |
| 524 | triplets_start = country_ie; |
| 525 | len_at_triplet = country_ie_len; |
| 526 | |
| 527 | *checksum ^= ((flags ^ alpha2[0] ^ alpha2[1]) << 8); |
| 528 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 529 | /* |
| 530 | * We need to build a reg rule for each triplet, but first we must |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 531 | * calculate the number of reg rules we will need. We will need one |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 532 | * for each channel subband |
| 533 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 534 | while (country_ie_len >= 3) { |
Luis R. Rodriguez | 615aab4 | 2009-01-22 15:05:46 -0800 | [diff] [blame] | 535 | int end_channel = 0; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 536 | struct ieee80211_country_ie_triplet *triplet = |
| 537 | (struct ieee80211_country_ie_triplet *) country_ie; |
| 538 | int cur_sub_max_channel = 0, cur_channel = 0; |
| 539 | |
| 540 | if (triplet->ext.reg_extension_id >= |
| 541 | IEEE80211_COUNTRY_EXTENSION_ID) { |
| 542 | country_ie += 3; |
| 543 | country_ie_len -= 3; |
| 544 | continue; |
| 545 | } |
| 546 | |
Luis R. Rodriguez | 615aab4 | 2009-01-22 15:05:46 -0800 | [diff] [blame] | 547 | /* 2 GHz */ |
| 548 | if (triplet->chans.first_channel <= 14) |
| 549 | end_channel = triplet->chans.first_channel + |
| 550 | triplet->chans.num_channels; |
| 551 | else |
| 552 | /* |
| 553 | * 5 GHz -- For example in country IEs if the first |
| 554 | * channel given is 36 and the number of channels is 4 |
| 555 | * then the individual channel numbers defined for the |
| 556 | * 5 GHz PHY by these parameters are: 36, 40, 44, and 48 |
| 557 | * and not 36, 37, 38, 39. |
| 558 | * |
| 559 | * See: http://tinyurl.com/11d-clarification |
| 560 | */ |
| 561 | end_channel = triplet->chans.first_channel + |
| 562 | (4 * (triplet->chans.num_channels - 1)); |
| 563 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 564 | cur_channel = triplet->chans.first_channel; |
Luis R. Rodriguez | 615aab4 | 2009-01-22 15:05:46 -0800 | [diff] [blame] | 565 | cur_sub_max_channel = end_channel; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 566 | |
| 567 | /* Basic sanity check */ |
| 568 | if (cur_sub_max_channel < cur_channel) |
| 569 | return NULL; |
| 570 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 571 | /* |
| 572 | * Do not allow overlapping channels. Also channels |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 573 | * passed in each subband must be monotonically |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 574 | * increasing |
| 575 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 576 | if (last_sub_max_channel) { |
| 577 | if (cur_channel <= last_sub_max_channel) |
| 578 | return NULL; |
| 579 | if (cur_sub_max_channel <= last_sub_max_channel) |
| 580 | return NULL; |
| 581 | } |
| 582 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 583 | /* |
| 584 | * When dot11RegulatoryClassesRequired is supported |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 585 | * we can throw ext triplets as part of this soup, |
| 586 | * for now we don't care when those change as we |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 587 | * don't support them |
| 588 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 589 | *checksum ^= ((cur_channel ^ cur_sub_max_channel) << 8) | |
| 590 | ((cur_sub_max_channel ^ cur_sub_max_channel) << 16) | |
| 591 | ((triplet->chans.max_power ^ cur_sub_max_channel) << 24); |
| 592 | |
| 593 | last_sub_max_channel = cur_sub_max_channel; |
| 594 | |
| 595 | country_ie += 3; |
| 596 | country_ie_len -= 3; |
| 597 | num_rules++; |
| 598 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 599 | /* |
| 600 | * Note: this is not a IEEE requirement but |
| 601 | * simply a memory requirement |
| 602 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 603 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
| 604 | return NULL; |
| 605 | } |
| 606 | |
| 607 | country_ie = triplets_start; |
| 608 | country_ie_len = len_at_triplet; |
| 609 | |
| 610 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 611 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 612 | |
| 613 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
| 614 | if (!rd) |
| 615 | return NULL; |
| 616 | |
| 617 | rd->n_reg_rules = num_rules; |
| 618 | rd->alpha2[0] = alpha2[0]; |
| 619 | rd->alpha2[1] = alpha2[1]; |
| 620 | |
| 621 | /* This time around we fill in the rd */ |
| 622 | while (country_ie_len >= 3) { |
Luis R. Rodriguez | 02e68a3 | 2009-01-07 17:43:37 -0800 | [diff] [blame] | 623 | int end_channel = 0; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 624 | struct ieee80211_country_ie_triplet *triplet = |
| 625 | (struct ieee80211_country_ie_triplet *) country_ie; |
| 626 | struct ieee80211_reg_rule *reg_rule = NULL; |
| 627 | struct ieee80211_freq_range *freq_range = NULL; |
| 628 | struct ieee80211_power_rule *power_rule = NULL; |
| 629 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 630 | /* |
| 631 | * Must parse if dot11RegulatoryClassesRequired is true, |
| 632 | * we don't support this yet |
| 633 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 634 | if (triplet->ext.reg_extension_id >= |
| 635 | IEEE80211_COUNTRY_EXTENSION_ID) { |
| 636 | country_ie += 3; |
| 637 | country_ie_len -= 3; |
| 638 | continue; |
| 639 | } |
| 640 | |
| 641 | reg_rule = &rd->reg_rules[i]; |
| 642 | freq_range = ®_rule->freq_range; |
| 643 | power_rule = ®_rule->power_rule; |
| 644 | |
| 645 | reg_rule->flags = flags; |
| 646 | |
Luis R. Rodriguez | 02e68a3 | 2009-01-07 17:43:37 -0800 | [diff] [blame] | 647 | /* 2 GHz */ |
| 648 | if (triplet->chans.first_channel <= 14) |
| 649 | end_channel = triplet->chans.first_channel + |
| 650 | triplet->chans.num_channels; |
| 651 | else |
Luis R. Rodriguez | 02e68a3 | 2009-01-07 17:43:37 -0800 | [diff] [blame] | 652 | end_channel = triplet->chans.first_channel + |
| 653 | (4 * (triplet->chans.num_channels - 1)); |
| 654 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 655 | /* |
| 656 | * The +10 is since the regulatory domain expects |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 657 | * the actual band edge, not the center of freq for |
| 658 | * its start and end freqs, assuming 20 MHz bandwidth on |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 659 | * the channels passed |
| 660 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 661 | freq_range->start_freq_khz = |
| 662 | MHZ_TO_KHZ(ieee80211_channel_to_frequency( |
| 663 | triplet->chans.first_channel) - 10); |
| 664 | freq_range->end_freq_khz = |
| 665 | MHZ_TO_KHZ(ieee80211_channel_to_frequency( |
Luis R. Rodriguez | 02e68a3 | 2009-01-07 17:43:37 -0800 | [diff] [blame] | 666 | end_channel) + 10); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 667 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 668 | /* |
| 669 | * These are large arbitrary values we use to intersect later. |
| 670 | * Increment this if we ever support >= 40 MHz channels |
| 671 | * in IEEE 802.11 |
| 672 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 673 | freq_range->max_bandwidth_khz = MHZ_TO_KHZ(40); |
| 674 | power_rule->max_antenna_gain = DBI_TO_MBI(100); |
| 675 | power_rule->max_eirp = DBM_TO_MBM(100); |
| 676 | |
| 677 | country_ie += 3; |
| 678 | country_ie_len -= 3; |
| 679 | i++; |
| 680 | |
| 681 | BUG_ON(i > NL80211_MAX_SUPP_REG_RULES); |
| 682 | } |
| 683 | |
| 684 | return rd; |
| 685 | } |
| 686 | |
| 687 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 688 | /* |
| 689 | * Helper for regdom_intersect(), this does the real |
| 690 | * mathematical intersection fun |
| 691 | */ |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 692 | static int reg_rules_intersect( |
| 693 | const struct ieee80211_reg_rule *rule1, |
| 694 | const struct ieee80211_reg_rule *rule2, |
| 695 | struct ieee80211_reg_rule *intersected_rule) |
| 696 | { |
| 697 | const struct ieee80211_freq_range *freq_range1, *freq_range2; |
| 698 | struct ieee80211_freq_range *freq_range; |
| 699 | const struct ieee80211_power_rule *power_rule1, *power_rule2; |
| 700 | struct ieee80211_power_rule *power_rule; |
| 701 | u32 freq_diff; |
| 702 | |
| 703 | freq_range1 = &rule1->freq_range; |
| 704 | freq_range2 = &rule2->freq_range; |
| 705 | freq_range = &intersected_rule->freq_range; |
| 706 | |
| 707 | power_rule1 = &rule1->power_rule; |
| 708 | power_rule2 = &rule2->power_rule; |
| 709 | power_rule = &intersected_rule->power_rule; |
| 710 | |
| 711 | freq_range->start_freq_khz = max(freq_range1->start_freq_khz, |
| 712 | freq_range2->start_freq_khz); |
| 713 | freq_range->end_freq_khz = min(freq_range1->end_freq_khz, |
| 714 | freq_range2->end_freq_khz); |
| 715 | freq_range->max_bandwidth_khz = min(freq_range1->max_bandwidth_khz, |
| 716 | freq_range2->max_bandwidth_khz); |
| 717 | |
| 718 | freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; |
| 719 | if (freq_range->max_bandwidth_khz > freq_diff) |
| 720 | freq_range->max_bandwidth_khz = freq_diff; |
| 721 | |
| 722 | power_rule->max_eirp = min(power_rule1->max_eirp, |
| 723 | power_rule2->max_eirp); |
| 724 | power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain, |
| 725 | power_rule2->max_antenna_gain); |
| 726 | |
| 727 | intersected_rule->flags = (rule1->flags | rule2->flags); |
| 728 | |
| 729 | if (!is_valid_reg_rule(intersected_rule)) |
| 730 | return -EINVAL; |
| 731 | |
| 732 | return 0; |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * regdom_intersect - do the intersection between two regulatory domains |
| 737 | * @rd1: first regulatory domain |
| 738 | * @rd2: second regulatory domain |
| 739 | * |
| 740 | * Use this function to get the intersection between two regulatory domains. |
| 741 | * Once completed we will mark the alpha2 for the rd as intersected, "98", |
| 742 | * as no one single alpha2 can represent this regulatory domain. |
| 743 | * |
| 744 | * Returns a pointer to the regulatory domain structure which will hold the |
| 745 | * resulting intersection of rules between rd1 and rd2. We will |
| 746 | * kzalloc() this structure for you. |
| 747 | */ |
| 748 | static struct ieee80211_regdomain *regdom_intersect( |
| 749 | const struct ieee80211_regdomain *rd1, |
| 750 | const struct ieee80211_regdomain *rd2) |
| 751 | { |
| 752 | int r, size_of_regd; |
| 753 | unsigned int x, y; |
| 754 | unsigned int num_rules = 0, rule_idx = 0; |
| 755 | const struct ieee80211_reg_rule *rule1, *rule2; |
| 756 | struct ieee80211_reg_rule *intersected_rule; |
| 757 | struct ieee80211_regdomain *rd; |
| 758 | /* This is just a dummy holder to help us count */ |
| 759 | struct ieee80211_reg_rule irule; |
| 760 | |
| 761 | /* Uses the stack temporarily for counter arithmetic */ |
| 762 | intersected_rule = &irule; |
| 763 | |
| 764 | memset(intersected_rule, 0, sizeof(struct ieee80211_reg_rule)); |
| 765 | |
| 766 | if (!rd1 || !rd2) |
| 767 | return NULL; |
| 768 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 769 | /* |
| 770 | * First we get a count of the rules we'll need, then we actually |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 771 | * build them. This is to so we can malloc() and free() a |
| 772 | * regdomain once. The reason we use reg_rules_intersect() here |
| 773 | * is it will return -EINVAL if the rule computed makes no sense. |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 774 | * All rules that do check out OK are valid. |
| 775 | */ |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 776 | |
| 777 | for (x = 0; x < rd1->n_reg_rules; x++) { |
| 778 | rule1 = &rd1->reg_rules[x]; |
| 779 | for (y = 0; y < rd2->n_reg_rules; y++) { |
| 780 | rule2 = &rd2->reg_rules[y]; |
| 781 | if (!reg_rules_intersect(rule1, rule2, |
| 782 | intersected_rule)) |
| 783 | num_rules++; |
| 784 | memset(intersected_rule, 0, |
| 785 | sizeof(struct ieee80211_reg_rule)); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | if (!num_rules) |
| 790 | return NULL; |
| 791 | |
| 792 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 793 | ((num_rules + 1) * sizeof(struct ieee80211_reg_rule)); |
| 794 | |
| 795 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
| 796 | if (!rd) |
| 797 | return NULL; |
| 798 | |
| 799 | for (x = 0; x < rd1->n_reg_rules; x++) { |
| 800 | rule1 = &rd1->reg_rules[x]; |
| 801 | for (y = 0; y < rd2->n_reg_rules; y++) { |
| 802 | rule2 = &rd2->reg_rules[y]; |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 803 | /* |
| 804 | * This time around instead of using the stack lets |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 805 | * write to the target rule directly saving ourselves |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 806 | * a memcpy() |
| 807 | */ |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 808 | intersected_rule = &rd->reg_rules[rule_idx]; |
| 809 | r = reg_rules_intersect(rule1, rule2, |
| 810 | intersected_rule); |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 811 | /* |
| 812 | * No need to memset here the intersected rule here as |
| 813 | * we're not using the stack anymore |
| 814 | */ |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 815 | if (r) |
| 816 | continue; |
| 817 | rule_idx++; |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | if (rule_idx != num_rules) { |
| 822 | kfree(rd); |
| 823 | return NULL; |
| 824 | } |
| 825 | |
| 826 | rd->n_reg_rules = num_rules; |
| 827 | rd->alpha2[0] = '9'; |
| 828 | rd->alpha2[1] = '8'; |
| 829 | |
| 830 | return rd; |
| 831 | } |
| 832 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 833 | /* |
| 834 | * XXX: add support for the rest of enum nl80211_reg_rule_flags, we may |
| 835 | * want to just have the channel structure use these |
| 836 | */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 837 | static u32 map_regdom_flags(u32 rd_flags) |
| 838 | { |
| 839 | u32 channel_flags = 0; |
| 840 | if (rd_flags & NL80211_RRF_PASSIVE_SCAN) |
| 841 | channel_flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
| 842 | if (rd_flags & NL80211_RRF_NO_IBSS) |
| 843 | channel_flags |= IEEE80211_CHAN_NO_IBSS; |
| 844 | if (rd_flags & NL80211_RRF_DFS) |
| 845 | channel_flags |= IEEE80211_CHAN_RADAR; |
| 846 | return channel_flags; |
| 847 | } |
| 848 | |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 849 | static int freq_reg_info_regd(struct wiphy *wiphy, |
| 850 | u32 center_freq, |
| 851 | u32 *bandwidth, |
| 852 | const struct ieee80211_reg_rule **reg_rule, |
| 853 | const struct ieee80211_regdomain *custom_regd) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 854 | { |
| 855 | int i; |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 856 | bool band_rule_found = false; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 857 | const struct ieee80211_regdomain *regd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 858 | u32 max_bandwidth = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 859 | |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 860 | regd = custom_regd ? custom_regd : cfg80211_regdomain; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 861 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 862 | /* |
| 863 | * Follow the driver's regulatory domain, if present, unless a country |
| 864 | * IE has been processed or a user wants to help complaince further |
| 865 | */ |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 866 | if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && |
| 867 | last_request->initiator != NL80211_REGDOM_SET_BY_USER && |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 868 | wiphy->regd) |
| 869 | regd = wiphy->regd; |
| 870 | |
| 871 | if (!regd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 872 | return -EINVAL; |
| 873 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 874 | for (i = 0; i < regd->n_reg_rules; i++) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 875 | const struct ieee80211_reg_rule *rr; |
| 876 | const struct ieee80211_freq_range *fr = NULL; |
| 877 | const struct ieee80211_power_rule *pr = NULL; |
| 878 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 879 | rr = ®d->reg_rules[i]; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 880 | fr = &rr->freq_range; |
| 881 | pr = &rr->power_rule; |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 882 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 883 | /* |
| 884 | * We only need to know if one frequency rule was |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 885 | * was in center_freq's band, that's enough, so lets |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 886 | * not overwrite it once found |
| 887 | */ |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 888 | if (!band_rule_found) |
| 889 | band_rule_found = freq_in_rule_band(fr, center_freq); |
| 890 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 891 | max_bandwidth = freq_max_bandwidth(fr, center_freq); |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 892 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 893 | if (max_bandwidth && *bandwidth <= max_bandwidth) { |
| 894 | *reg_rule = rr; |
| 895 | *bandwidth = max_bandwidth; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 896 | break; |
| 897 | } |
| 898 | } |
| 899 | |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 900 | if (!band_rule_found) |
| 901 | return -ERANGE; |
| 902 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 903 | return !max_bandwidth; |
| 904 | } |
Luis R. Rodriguez | 34f5734 | 2009-01-22 15:05:45 -0800 | [diff] [blame] | 905 | EXPORT_SYMBOL(freq_reg_info); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 906 | |
Luis R. Rodriguez | 34f5734 | 2009-01-22 15:05:45 -0800 | [diff] [blame] | 907 | int freq_reg_info(struct wiphy *wiphy, u32 center_freq, u32 *bandwidth, |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 908 | const struct ieee80211_reg_rule **reg_rule) |
| 909 | { |
Luis R. Rodriguez | ac46d48 | 2009-05-01 18:44:50 -0400 | [diff] [blame] | 910 | assert_cfg80211_lock(); |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 911 | return freq_reg_info_regd(wiphy, center_freq, |
| 912 | bandwidth, reg_rule, NULL); |
| 913 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 914 | |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 915 | static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band, |
| 916 | unsigned int chan_idx) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 917 | { |
| 918 | int r; |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 919 | u32 flags; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 920 | u32 max_bandwidth = 0; |
| 921 | const struct ieee80211_reg_rule *reg_rule = NULL; |
| 922 | const struct ieee80211_power_rule *power_rule = NULL; |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 923 | struct ieee80211_supported_band *sband; |
| 924 | struct ieee80211_channel *chan; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 925 | struct wiphy *request_wiphy = NULL; |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 926 | |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 927 | assert_cfg80211_lock(); |
| 928 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 929 | request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); |
| 930 | |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 931 | sband = wiphy->bands[band]; |
| 932 | BUG_ON(chan_idx >= sband->n_channels); |
| 933 | chan = &sband->channels[chan_idx]; |
| 934 | |
| 935 | flags = chan->orig_flags; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 936 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 937 | r = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq), |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 938 | &max_bandwidth, ®_rule); |
| 939 | |
| 940 | if (r) { |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 941 | /* |
| 942 | * This means no regulatory rule was found in the country IE |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 943 | * with a frequency range on the center_freq's band, since |
| 944 | * IEEE-802.11 allows for a country IE to have a subset of the |
| 945 | * regulatory information provided in a country we ignore |
| 946 | * disabling the channel unless at least one reg rule was |
| 947 | * found on the center_freq's band. For details see this |
| 948 | * clarification: |
| 949 | * |
| 950 | * http://tinyurl.com/11d-clarification |
| 951 | */ |
| 952 | if (r == -ERANGE && |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 953 | last_request->initiator == |
| 954 | NL80211_REGDOM_SET_BY_COUNTRY_IE) { |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 955 | #ifdef CONFIG_CFG80211_REG_DEBUG |
| 956 | printk(KERN_DEBUG "cfg80211: Leaving channel %d MHz " |
| 957 | "intact on %s - no rule found in band on " |
| 958 | "Country IE\n", |
| 959 | chan->center_freq, wiphy_name(wiphy)); |
| 960 | #endif |
| 961 | } else { |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 962 | /* |
| 963 | * In this case we know the country IE has at least one reg rule |
| 964 | * for the band so we respect its band definitions |
| 965 | */ |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 966 | #ifdef CONFIG_CFG80211_REG_DEBUG |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 967 | if (last_request->initiator == |
| 968 | NL80211_REGDOM_SET_BY_COUNTRY_IE) |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 969 | printk(KERN_DEBUG "cfg80211: Disabling " |
| 970 | "channel %d MHz on %s due to " |
| 971 | "Country IE\n", |
| 972 | chan->center_freq, wiphy_name(wiphy)); |
| 973 | #endif |
| 974 | flags |= IEEE80211_CHAN_DISABLED; |
| 975 | chan->flags = flags; |
| 976 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 977 | return; |
| 978 | } |
| 979 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 980 | power_rule = ®_rule->power_rule; |
| 981 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 982 | if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER && |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 983 | request_wiphy && request_wiphy == wiphy && |
| 984 | request_wiphy->strict_regulatory) { |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 985 | /* |
| 986 | * This gaurantees the driver's requested regulatory domain |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 987 | * will always be used as a base for further regulatory |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 988 | * settings |
| 989 | */ |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 990 | chan->flags = chan->orig_flags = |
| 991 | map_regdom_flags(reg_rule->flags); |
| 992 | chan->max_antenna_gain = chan->orig_mag = |
| 993 | (int) MBI_TO_DBI(power_rule->max_antenna_gain); |
| 994 | chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth); |
| 995 | chan->max_power = chan->orig_mpwr = |
| 996 | (int) MBM_TO_DBM(power_rule->max_eirp); |
| 997 | return; |
| 998 | } |
| 999 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1000 | chan->flags = flags | map_regdom_flags(reg_rule->flags); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1001 | chan->max_antenna_gain = min(chan->orig_mag, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1002 | (int) MBI_TO_DBI(power_rule->max_antenna_gain)); |
| 1003 | chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth); |
John W. Linville | 253898c | 2008-04-03 15:32:54 -0400 | [diff] [blame] | 1004 | if (chan->orig_mpwr) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1005 | chan->max_power = min(chan->orig_mpwr, |
| 1006 | (int) MBM_TO_DBM(power_rule->max_eirp)); |
John W. Linville | 253898c | 2008-04-03 15:32:54 -0400 | [diff] [blame] | 1007 | else |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1008 | chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1009 | } |
| 1010 | |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 1011 | static void handle_band(struct wiphy *wiphy, enum ieee80211_band band) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1012 | { |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 1013 | unsigned int i; |
| 1014 | struct ieee80211_supported_band *sband; |
| 1015 | |
| 1016 | BUG_ON(!wiphy->bands[band]); |
| 1017 | sband = wiphy->bands[band]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1018 | |
| 1019 | for (i = 0; i < sband->n_channels; i++) |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 1020 | handle_channel(wiphy, band, i); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1021 | } |
| 1022 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1023 | static bool ignore_reg_update(struct wiphy *wiphy, |
| 1024 | enum nl80211_reg_initiator initiator) |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 1025 | { |
| 1026 | if (!last_request) |
| 1027 | return true; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1028 | if (initiator == NL80211_REGDOM_SET_BY_CORE && |
Luis R. Rodriguez | 2a44f91 | 2009-01-22 15:05:49 -0800 | [diff] [blame] | 1029 | wiphy->custom_regulatory) |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 1030 | return true; |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1031 | /* |
| 1032 | * wiphy->regd will be set once the device has its own |
| 1033 | * desired regulatory domain set |
| 1034 | */ |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 1035 | if (wiphy->strict_regulatory && !wiphy->regd && |
| 1036 | !is_world_regdom(last_request->alpha2)) |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 1037 | return true; |
| 1038 | return false; |
| 1039 | } |
| 1040 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1041 | static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1042 | { |
| 1043 | struct cfg80211_registered_device *drv; |
| 1044 | |
| 1045 | list_for_each_entry(drv, &cfg80211_drv_list, list) |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1046 | wiphy_update_regulatory(&drv->wiphy, initiator); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1049 | static void handle_reg_beacon(struct wiphy *wiphy, |
| 1050 | unsigned int chan_idx, |
| 1051 | struct reg_beacon *reg_beacon) |
| 1052 | { |
| 1053 | #ifdef CONFIG_CFG80211_REG_DEBUG |
| 1054 | #define REG_DEBUG_BEACON_FLAG(desc) \ |
| 1055 | printk(KERN_DEBUG "cfg80211: Enabling " desc " on " \ |
| 1056 | "frequency: %d MHz (Ch %d) on %s\n", \ |
| 1057 | reg_beacon->chan.center_freq, \ |
| 1058 | ieee80211_frequency_to_channel(reg_beacon->chan.center_freq), \ |
| 1059 | wiphy_name(wiphy)); |
| 1060 | #else |
| 1061 | #define REG_DEBUG_BEACON_FLAG(desc) do {} while (0) |
| 1062 | #endif |
| 1063 | struct ieee80211_supported_band *sband; |
| 1064 | struct ieee80211_channel *chan; |
| 1065 | |
| 1066 | assert_cfg80211_lock(); |
| 1067 | |
| 1068 | sband = wiphy->bands[reg_beacon->chan.band]; |
| 1069 | chan = &sband->channels[chan_idx]; |
| 1070 | |
| 1071 | if (likely(chan->center_freq != reg_beacon->chan.center_freq)) |
| 1072 | return; |
| 1073 | |
| 1074 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) { |
| 1075 | chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
| 1076 | REG_DEBUG_BEACON_FLAG("active scanning"); |
| 1077 | } |
| 1078 | |
| 1079 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) { |
| 1080 | chan->flags &= ~IEEE80211_CHAN_NO_IBSS; |
| 1081 | REG_DEBUG_BEACON_FLAG("beaconing"); |
| 1082 | } |
| 1083 | |
| 1084 | chan->beacon_found = true; |
| 1085 | #undef REG_DEBUG_BEACON_FLAG |
| 1086 | } |
| 1087 | |
| 1088 | /* |
| 1089 | * Called when a scan on a wiphy finds a beacon on |
| 1090 | * new channel |
| 1091 | */ |
| 1092 | static void wiphy_update_new_beacon(struct wiphy *wiphy, |
| 1093 | struct reg_beacon *reg_beacon) |
| 1094 | { |
| 1095 | unsigned int i; |
| 1096 | struct ieee80211_supported_band *sband; |
| 1097 | |
| 1098 | assert_cfg80211_lock(); |
| 1099 | |
| 1100 | if (!wiphy->bands[reg_beacon->chan.band]) |
| 1101 | return; |
| 1102 | |
| 1103 | sband = wiphy->bands[reg_beacon->chan.band]; |
| 1104 | |
| 1105 | for (i = 0; i < sband->n_channels; i++) |
| 1106 | handle_reg_beacon(wiphy, i, reg_beacon); |
| 1107 | } |
| 1108 | |
| 1109 | /* |
| 1110 | * Called upon reg changes or a new wiphy is added |
| 1111 | */ |
| 1112 | static void wiphy_update_beacon_reg(struct wiphy *wiphy) |
| 1113 | { |
| 1114 | unsigned int i; |
| 1115 | struct ieee80211_supported_band *sband; |
| 1116 | struct reg_beacon *reg_beacon; |
| 1117 | |
| 1118 | assert_cfg80211_lock(); |
| 1119 | |
| 1120 | if (list_empty(®_beacon_list)) |
| 1121 | return; |
| 1122 | |
| 1123 | list_for_each_entry(reg_beacon, ®_beacon_list, list) { |
| 1124 | if (!wiphy->bands[reg_beacon->chan.band]) |
| 1125 | continue; |
| 1126 | sband = wiphy->bands[reg_beacon->chan.band]; |
| 1127 | for (i = 0; i < sband->n_channels; i++) |
| 1128 | handle_reg_beacon(wiphy, i, reg_beacon); |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | static bool reg_is_world_roaming(struct wiphy *wiphy) |
| 1133 | { |
| 1134 | if (is_world_regdom(cfg80211_regdomain->alpha2) || |
| 1135 | (wiphy->regd && is_world_regdom(wiphy->regd->alpha2))) |
| 1136 | return true; |
Luis R. Rodriguez | b1ed8dd | 2009-05-02 00:34:15 -0400 | [diff] [blame^] | 1137 | if (last_request && |
| 1138 | last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1139 | wiphy->custom_regulatory) |
| 1140 | return true; |
| 1141 | return false; |
| 1142 | } |
| 1143 | |
| 1144 | /* Reap the advantages of previously found beacons */ |
| 1145 | static void reg_process_beacons(struct wiphy *wiphy) |
| 1146 | { |
Luis R. Rodriguez | b1ed8dd | 2009-05-02 00:34:15 -0400 | [diff] [blame^] | 1147 | /* |
| 1148 | * Means we are just firing up cfg80211, so no beacons would |
| 1149 | * have been processed yet. |
| 1150 | */ |
| 1151 | if (!last_request) |
| 1152 | return; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1153 | if (!reg_is_world_roaming(wiphy)) |
| 1154 | return; |
| 1155 | wiphy_update_beacon_reg(wiphy); |
| 1156 | } |
| 1157 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1158 | void wiphy_update_regulatory(struct wiphy *wiphy, |
| 1159 | enum nl80211_reg_initiator initiator) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1160 | { |
| 1161 | enum ieee80211_band band; |
Luis R. Rodriguez | d46e5b1 | 2009-01-22 15:05:50 -0800 | [diff] [blame] | 1162 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1163 | if (ignore_reg_update(wiphy, initiator)) |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1164 | goto out; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1165 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1166 | if (wiphy->bands[band]) |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 1167 | handle_band(wiphy, band); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1168 | } |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1169 | out: |
| 1170 | reg_process_beacons(wiphy); |
Luis R. Rodriguez | 560e28e | 2009-01-07 17:43:32 -0800 | [diff] [blame] | 1171 | if (wiphy->reg_notifier) |
Luis R. Rodriguez | 716f939 | 2009-01-22 15:05:51 -0800 | [diff] [blame] | 1172 | wiphy->reg_notifier(wiphy, last_request); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1175 | static void handle_channel_custom(struct wiphy *wiphy, |
| 1176 | enum ieee80211_band band, |
| 1177 | unsigned int chan_idx, |
| 1178 | const struct ieee80211_regdomain *regd) |
| 1179 | { |
| 1180 | int r; |
| 1181 | u32 max_bandwidth = 0; |
| 1182 | const struct ieee80211_reg_rule *reg_rule = NULL; |
| 1183 | const struct ieee80211_power_rule *power_rule = NULL; |
| 1184 | struct ieee80211_supported_band *sband; |
| 1185 | struct ieee80211_channel *chan; |
| 1186 | |
Luis R. Rodriguez | ac46d48 | 2009-05-01 18:44:50 -0400 | [diff] [blame] | 1187 | assert_cfg80211_lock(); |
| 1188 | |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1189 | sband = wiphy->bands[band]; |
| 1190 | BUG_ON(chan_idx >= sband->n_channels); |
| 1191 | chan = &sband->channels[chan_idx]; |
| 1192 | |
| 1193 | r = freq_reg_info_regd(wiphy, MHZ_TO_KHZ(chan->center_freq), |
| 1194 | &max_bandwidth, ®_rule, regd); |
| 1195 | |
| 1196 | if (r) { |
| 1197 | chan->flags = IEEE80211_CHAN_DISABLED; |
| 1198 | return; |
| 1199 | } |
| 1200 | |
| 1201 | power_rule = ®_rule->power_rule; |
| 1202 | |
| 1203 | chan->flags |= map_regdom_flags(reg_rule->flags); |
| 1204 | chan->max_antenna_gain = (int) MBI_TO_DBI(power_rule->max_antenna_gain); |
| 1205 | chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth); |
| 1206 | chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp); |
| 1207 | } |
| 1208 | |
| 1209 | static void handle_band_custom(struct wiphy *wiphy, enum ieee80211_band band, |
| 1210 | const struct ieee80211_regdomain *regd) |
| 1211 | { |
| 1212 | unsigned int i; |
| 1213 | struct ieee80211_supported_band *sband; |
| 1214 | |
| 1215 | BUG_ON(!wiphy->bands[band]); |
| 1216 | sband = wiphy->bands[band]; |
| 1217 | |
| 1218 | for (i = 0; i < sband->n_channels; i++) |
| 1219 | handle_channel_custom(wiphy, band, i, regd); |
| 1220 | } |
| 1221 | |
| 1222 | /* Used by drivers prior to wiphy registration */ |
| 1223 | void wiphy_apply_custom_regulatory(struct wiphy *wiphy, |
| 1224 | const struct ieee80211_regdomain *regd) |
| 1225 | { |
| 1226 | enum ieee80211_band band; |
Luis R. Rodriguez | ac46d48 | 2009-05-01 18:44:50 -0400 | [diff] [blame] | 1227 | |
| 1228 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1229 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 1230 | if (wiphy->bands[band]) |
| 1231 | handle_band_custom(wiphy, band, regd); |
| 1232 | } |
Luis R. Rodriguez | ac46d48 | 2009-05-01 18:44:50 -0400 | [diff] [blame] | 1233 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1234 | } |
| 1235 | EXPORT_SYMBOL(wiphy_apply_custom_regulatory); |
| 1236 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1237 | static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd, |
| 1238 | const struct ieee80211_regdomain *src_regd) |
| 1239 | { |
| 1240 | struct ieee80211_regdomain *regd; |
| 1241 | int size_of_regd = 0; |
| 1242 | unsigned int i; |
| 1243 | |
| 1244 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 1245 | ((src_regd->n_reg_rules + 1) * sizeof(struct ieee80211_reg_rule)); |
| 1246 | |
| 1247 | regd = kzalloc(size_of_regd, GFP_KERNEL); |
| 1248 | if (!regd) |
| 1249 | return -ENOMEM; |
| 1250 | |
| 1251 | memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain)); |
| 1252 | |
| 1253 | for (i = 0; i < src_regd->n_reg_rules; i++) |
| 1254 | memcpy(®d->reg_rules[i], &src_regd->reg_rules[i], |
| 1255 | sizeof(struct ieee80211_reg_rule)); |
| 1256 | |
| 1257 | *dst_regd = regd; |
| 1258 | return 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1261 | /* |
| 1262 | * Return value which can be used by ignore_request() to indicate |
| 1263 | * it has been determined we should intersect two regulatory domains |
| 1264 | */ |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1265 | #define REG_INTERSECT 1 |
| 1266 | |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1267 | /* This has the logic which determines when a new request |
| 1268 | * should be ignored. */ |
Luis R. Rodriguez | 2f92cd2 | 2009-02-21 00:24:16 -0500 | [diff] [blame] | 1269 | static int ignore_request(struct wiphy *wiphy, |
| 1270 | struct regulatory_request *pending_request) |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1271 | { |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1272 | struct wiphy *last_wiphy = NULL; |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 1273 | |
| 1274 | assert_cfg80211_lock(); |
| 1275 | |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1276 | /* All initial requests are respected */ |
| 1277 | if (!last_request) |
| 1278 | return 0; |
| 1279 | |
Luis R. Rodriguez | 2f92cd2 | 2009-02-21 00:24:16 -0500 | [diff] [blame] | 1280 | switch (pending_request->initiator) { |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1281 | case NL80211_REGDOM_SET_BY_CORE: |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 1282 | return -EINVAL; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1283 | case NL80211_REGDOM_SET_BY_COUNTRY_IE: |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1284 | |
| 1285 | last_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); |
| 1286 | |
Luis R. Rodriguez | 2f92cd2 | 2009-02-21 00:24:16 -0500 | [diff] [blame] | 1287 | if (unlikely(!is_an_alpha2(pending_request->alpha2))) |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1288 | return -EINVAL; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1289 | if (last_request->initiator == |
| 1290 | NL80211_REGDOM_SET_BY_COUNTRY_IE) { |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1291 | if (last_wiphy != wiphy) { |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1292 | /* |
| 1293 | * Two cards with two APs claiming different |
| 1294 | * different Country IE alpha2s. We could |
| 1295 | * intersect them, but that seems unlikely |
| 1296 | * to be correct. Reject second one for now. |
| 1297 | */ |
Luis R. Rodriguez | 2f92cd2 | 2009-02-21 00:24:16 -0500 | [diff] [blame] | 1298 | if (regdom_changes(pending_request->alpha2)) |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1299 | return -EOPNOTSUPP; |
| 1300 | return -EALREADY; |
| 1301 | } |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1302 | /* |
| 1303 | * Two consecutive Country IE hints on the same wiphy. |
| 1304 | * This should be picked up early by the driver/stack |
| 1305 | */ |
Luis R. Rodriguez | 2f92cd2 | 2009-02-21 00:24:16 -0500 | [diff] [blame] | 1306 | if (WARN_ON(regdom_changes(pending_request->alpha2))) |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1307 | return 0; |
| 1308 | return -EALREADY; |
| 1309 | } |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1310 | return REG_INTERSECT; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1311 | case NL80211_REGDOM_SET_BY_DRIVER: |
| 1312 | if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE) { |
Luis R. Rodriguez | e74b1e7 | 2009-01-22 15:05:48 -0800 | [diff] [blame] | 1313 | if (is_old_static_regdom(cfg80211_regdomain)) |
| 1314 | return 0; |
Luis R. Rodriguez | 2f92cd2 | 2009-02-21 00:24:16 -0500 | [diff] [blame] | 1315 | if (regdom_changes(pending_request->alpha2)) |
Luis R. Rodriguez | e74b1e7 | 2009-01-22 15:05:48 -0800 | [diff] [blame] | 1316 | return 0; |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1317 | return -EALREADY; |
Luis R. Rodriguez | e74b1e7 | 2009-01-22 15:05:48 -0800 | [diff] [blame] | 1318 | } |
Luis R. Rodriguez | fff32c0 | 2009-02-21 00:04:32 -0500 | [diff] [blame] | 1319 | |
| 1320 | /* |
| 1321 | * This would happen if you unplug and plug your card |
| 1322 | * back in or if you add a new device for which the previously |
| 1323 | * loaded card also agrees on the regulatory domain. |
| 1324 | */ |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1325 | if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER && |
Luis R. Rodriguez | 2f92cd2 | 2009-02-21 00:24:16 -0500 | [diff] [blame] | 1326 | !regdom_changes(pending_request->alpha2)) |
Luis R. Rodriguez | fff32c0 | 2009-02-21 00:04:32 -0500 | [diff] [blame] | 1327 | return -EALREADY; |
| 1328 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1329 | return REG_INTERSECT; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1330 | case NL80211_REGDOM_SET_BY_USER: |
| 1331 | if (last_request->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1332 | return REG_INTERSECT; |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1333 | /* |
| 1334 | * If the user knows better the user should set the regdom |
| 1335 | * to their country before the IE is picked up |
| 1336 | */ |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1337 | if (last_request->initiator == NL80211_REGDOM_SET_BY_USER && |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1338 | last_request->intersect) |
| 1339 | return -EOPNOTSUPP; |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1340 | /* |
| 1341 | * Process user requests only after previous user/driver/core |
| 1342 | * requests have been processed |
| 1343 | */ |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1344 | if (last_request->initiator == NL80211_REGDOM_SET_BY_CORE || |
| 1345 | last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER || |
| 1346 | last_request->initiator == NL80211_REGDOM_SET_BY_USER) { |
Luis R. Rodriguez | 69b1572 | 2009-02-21 00:04:33 -0500 | [diff] [blame] | 1347 | if (regdom_changes(last_request->alpha2)) |
Luis R. Rodriguez | 5eebade | 2009-01-22 15:05:47 -0800 | [diff] [blame] | 1348 | return -EAGAIN; |
| 1349 | } |
| 1350 | |
Luis R. Rodriguez | e74b1e7 | 2009-01-22 15:05:48 -0800 | [diff] [blame] | 1351 | if (!is_old_static_regdom(cfg80211_regdomain) && |
Luis R. Rodriguez | 2f92cd2 | 2009-02-21 00:24:16 -0500 | [diff] [blame] | 1352 | !regdom_changes(pending_request->alpha2)) |
Luis R. Rodriguez | e74b1e7 | 2009-01-22 15:05:48 -0800 | [diff] [blame] | 1353 | return -EALREADY; |
| 1354 | |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1355 | return 0; |
| 1356 | } |
| 1357 | |
| 1358 | return -EINVAL; |
| 1359 | } |
| 1360 | |
Luis R. Rodriguez | d1c96a9 | 2009-02-21 00:24:13 -0500 | [diff] [blame] | 1361 | /** |
| 1362 | * __regulatory_hint - hint to the wireless core a regulatory domain |
| 1363 | * @wiphy: if the hint comes from country information from an AP, this |
| 1364 | * is required to be set to the wiphy that received the information |
Luis R. Rodriguez | 28da32d | 2009-02-21 00:24:14 -0500 | [diff] [blame] | 1365 | * @pending_request: the regulatory request currently being processed |
Luis R. Rodriguez | d1c96a9 | 2009-02-21 00:24:13 -0500 | [diff] [blame] | 1366 | * |
| 1367 | * The Wireless subsystem can use this function to hint to the wireless core |
Luis R. Rodriguez | 28da32d | 2009-02-21 00:24:14 -0500 | [diff] [blame] | 1368 | * what it believes should be the current regulatory domain. |
Luis R. Rodriguez | d1c96a9 | 2009-02-21 00:24:13 -0500 | [diff] [blame] | 1369 | * |
| 1370 | * Returns zero if all went fine, %-EALREADY if a regulatory domain had |
| 1371 | * already been set or other standard error codes. |
| 1372 | * |
| 1373 | * Caller must hold &cfg80211_mutex |
| 1374 | */ |
Luis R. Rodriguez | 28da32d | 2009-02-21 00:24:14 -0500 | [diff] [blame] | 1375 | static int __regulatory_hint(struct wiphy *wiphy, |
| 1376 | struct regulatory_request *pending_request) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1377 | { |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1378 | bool intersect = false; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1379 | int r = 0; |
| 1380 | |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 1381 | assert_cfg80211_lock(); |
| 1382 | |
Luis R. Rodriguez | 2f92cd2 | 2009-02-21 00:24:16 -0500 | [diff] [blame] | 1383 | r = ignore_request(wiphy, pending_request); |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1384 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1385 | if (r == REG_INTERSECT) { |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1386 | if (pending_request->initiator == |
| 1387 | NL80211_REGDOM_SET_BY_DRIVER) { |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1388 | r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain); |
Luis R. Rodriguez | d951c1d | 2009-02-21 00:24:15 -0500 | [diff] [blame] | 1389 | if (r) { |
| 1390 | kfree(pending_request); |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1391 | return r; |
Luis R. Rodriguez | d951c1d | 2009-02-21 00:24:15 -0500 | [diff] [blame] | 1392 | } |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1393 | } |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1394 | intersect = true; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1395 | } else if (r) { |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1396 | /* |
| 1397 | * If the regulatory domain being requested by the |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1398 | * driver has already been set just copy it to the |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1399 | * wiphy |
| 1400 | */ |
Luis R. Rodriguez | 28da32d | 2009-02-21 00:24:14 -0500 | [diff] [blame] | 1401 | if (r == -EALREADY && |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1402 | pending_request->initiator == |
| 1403 | NL80211_REGDOM_SET_BY_DRIVER) { |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1404 | r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain); |
Luis R. Rodriguez | d951c1d | 2009-02-21 00:24:15 -0500 | [diff] [blame] | 1405 | if (r) { |
| 1406 | kfree(pending_request); |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1407 | return r; |
Luis R. Rodriguez | d951c1d | 2009-02-21 00:24:15 -0500 | [diff] [blame] | 1408 | } |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1409 | r = -EALREADY; |
| 1410 | goto new_request; |
| 1411 | } |
Luis R. Rodriguez | d951c1d | 2009-02-21 00:24:15 -0500 | [diff] [blame] | 1412 | kfree(pending_request); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1413 | return r; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1414 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1415 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1416 | new_request: |
Luis R. Rodriguez | 5203cdb | 2008-11-12 14:21:56 -0800 | [diff] [blame] | 1417 | kfree(last_request); |
Luis R. Rodriguez | d951c1d | 2009-02-21 00:24:15 -0500 | [diff] [blame] | 1418 | |
| 1419 | last_request = pending_request; |
| 1420 | last_request->intersect = intersect; |
| 1421 | |
| 1422 | pending_request = NULL; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1423 | |
| 1424 | /* When r == REG_INTERSECT we do need to call CRDA */ |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 1425 | if (r < 0) { |
| 1426 | /* |
| 1427 | * Since CRDA will not be called in this case as we already |
| 1428 | * have applied the requested regulatory domain before we just |
| 1429 | * inform userspace we have processed the request |
| 1430 | */ |
| 1431 | if (r == -EALREADY) |
| 1432 | nl80211_send_reg_change_event(last_request); |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1433 | return r; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 1434 | } |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1435 | |
Luis R. Rodriguez | d951c1d | 2009-02-21 00:24:15 -0500 | [diff] [blame] | 1436 | return call_crda(last_request->alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1437 | } |
| 1438 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1439 | /* This currently only processes user and driver regulatory hints */ |
Luis R. Rodriguez | d951c1d | 2009-02-21 00:24:15 -0500 | [diff] [blame] | 1440 | static void reg_process_hint(struct regulatory_request *reg_request) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1441 | { |
| 1442 | int r = 0; |
| 1443 | struct wiphy *wiphy = NULL; |
| 1444 | |
| 1445 | BUG_ON(!reg_request->alpha2); |
| 1446 | |
| 1447 | mutex_lock(&cfg80211_mutex); |
| 1448 | |
| 1449 | if (wiphy_idx_valid(reg_request->wiphy_idx)) |
| 1450 | wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx); |
| 1451 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1452 | if (reg_request->initiator == NL80211_REGDOM_SET_BY_DRIVER && |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1453 | !wiphy) { |
Luis R. Rodriguez | d951c1d | 2009-02-21 00:24:15 -0500 | [diff] [blame] | 1454 | kfree(reg_request); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1455 | goto out; |
| 1456 | } |
| 1457 | |
Luis R. Rodriguez | 28da32d | 2009-02-21 00:24:14 -0500 | [diff] [blame] | 1458 | r = __regulatory_hint(wiphy, reg_request); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1459 | /* This is required so that the orig_* parameters are saved */ |
| 1460 | if (r == -EALREADY && wiphy && wiphy->strict_regulatory) |
| 1461 | wiphy_update_regulatory(wiphy, reg_request->initiator); |
| 1462 | out: |
| 1463 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1464 | } |
| 1465 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1466 | /* Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_* */ |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1467 | static void reg_process_pending_hints(void) |
| 1468 | { |
| 1469 | struct regulatory_request *reg_request; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1470 | |
| 1471 | spin_lock(®_requests_lock); |
| 1472 | while (!list_empty(®_requests_list)) { |
| 1473 | reg_request = list_first_entry(®_requests_list, |
| 1474 | struct regulatory_request, |
| 1475 | list); |
| 1476 | list_del_init(®_request->list); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1477 | |
Luis R. Rodriguez | d951c1d | 2009-02-21 00:24:15 -0500 | [diff] [blame] | 1478 | spin_unlock(®_requests_lock); |
| 1479 | reg_process_hint(reg_request); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1480 | spin_lock(®_requests_lock); |
| 1481 | } |
| 1482 | spin_unlock(®_requests_lock); |
| 1483 | } |
| 1484 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1485 | /* Processes beacon hints -- this has nothing to do with country IEs */ |
| 1486 | static void reg_process_pending_beacon_hints(void) |
| 1487 | { |
| 1488 | struct cfg80211_registered_device *drv; |
| 1489 | struct reg_beacon *pending_beacon, *tmp; |
| 1490 | |
| 1491 | mutex_lock(&cfg80211_mutex); |
| 1492 | |
| 1493 | /* This goes through the _pending_ beacon list */ |
| 1494 | spin_lock_bh(®_pending_beacons_lock); |
| 1495 | |
| 1496 | if (list_empty(®_pending_beacons)) { |
| 1497 | spin_unlock_bh(®_pending_beacons_lock); |
| 1498 | goto out; |
| 1499 | } |
| 1500 | |
| 1501 | list_for_each_entry_safe(pending_beacon, tmp, |
| 1502 | ®_pending_beacons, list) { |
| 1503 | |
| 1504 | list_del_init(&pending_beacon->list); |
| 1505 | |
| 1506 | /* Applies the beacon hint to current wiphys */ |
| 1507 | list_for_each_entry(drv, &cfg80211_drv_list, list) |
| 1508 | wiphy_update_new_beacon(&drv->wiphy, pending_beacon); |
| 1509 | |
| 1510 | /* Remembers the beacon hint for new wiphys or reg changes */ |
| 1511 | list_add_tail(&pending_beacon->list, ®_beacon_list); |
| 1512 | } |
| 1513 | |
| 1514 | spin_unlock_bh(®_pending_beacons_lock); |
| 1515 | out: |
| 1516 | mutex_unlock(&cfg80211_mutex); |
| 1517 | } |
| 1518 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1519 | static void reg_todo(struct work_struct *work) |
| 1520 | { |
| 1521 | reg_process_pending_hints(); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1522 | reg_process_pending_beacon_hints(); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | static DECLARE_WORK(reg_work, reg_todo); |
| 1526 | |
| 1527 | static void queue_regulatory_request(struct regulatory_request *request) |
| 1528 | { |
| 1529 | spin_lock(®_requests_lock); |
| 1530 | list_add_tail(&request->list, ®_requests_list); |
| 1531 | spin_unlock(®_requests_lock); |
| 1532 | |
| 1533 | schedule_work(®_work); |
| 1534 | } |
| 1535 | |
| 1536 | /* Core regulatory hint -- happens once during cfg80211_init() */ |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 1537 | static int regulatory_hint_core(const char *alpha2) |
| 1538 | { |
| 1539 | struct regulatory_request *request; |
| 1540 | |
| 1541 | BUG_ON(last_request); |
| 1542 | |
| 1543 | request = kzalloc(sizeof(struct regulatory_request), |
| 1544 | GFP_KERNEL); |
| 1545 | if (!request) |
| 1546 | return -ENOMEM; |
| 1547 | |
| 1548 | request->alpha2[0] = alpha2[0]; |
| 1549 | request->alpha2[1] = alpha2[1]; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1550 | request->initiator = NL80211_REGDOM_SET_BY_CORE; |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 1551 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1552 | queue_regulatory_request(request); |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 1553 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1554 | return 0; |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 1555 | } |
| 1556 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1557 | /* User hints */ |
| 1558 | int regulatory_hint_user(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1559 | { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1560 | struct regulatory_request *request; |
| 1561 | |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 1562 | BUG_ON(!alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1563 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1564 | request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); |
| 1565 | if (!request) |
| 1566 | return -ENOMEM; |
| 1567 | |
| 1568 | request->wiphy_idx = WIPHY_IDX_STALE; |
| 1569 | request->alpha2[0] = alpha2[0]; |
| 1570 | request->alpha2[1] = alpha2[1]; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1571 | request->initiator = NL80211_REGDOM_SET_BY_USER, |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1572 | |
| 1573 | queue_regulatory_request(request); |
| 1574 | |
| 1575 | return 0; |
| 1576 | } |
| 1577 | |
| 1578 | /* Driver hints */ |
| 1579 | int regulatory_hint(struct wiphy *wiphy, const char *alpha2) |
| 1580 | { |
| 1581 | struct regulatory_request *request; |
| 1582 | |
| 1583 | BUG_ON(!alpha2); |
| 1584 | BUG_ON(!wiphy); |
| 1585 | |
| 1586 | request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); |
| 1587 | if (!request) |
| 1588 | return -ENOMEM; |
| 1589 | |
| 1590 | request->wiphy_idx = get_wiphy_idx(wiphy); |
| 1591 | |
| 1592 | /* Must have registered wiphy first */ |
| 1593 | BUG_ON(!wiphy_idx_valid(request->wiphy_idx)); |
| 1594 | |
| 1595 | request->alpha2[0] = alpha2[0]; |
| 1596 | request->alpha2[1] = alpha2[1]; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1597 | request->initiator = NL80211_REGDOM_SET_BY_DRIVER; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1598 | |
| 1599 | queue_regulatory_request(request); |
| 1600 | |
| 1601 | return 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1602 | } |
| 1603 | EXPORT_SYMBOL(regulatory_hint); |
| 1604 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1605 | static bool reg_same_country_ie_hint(struct wiphy *wiphy, |
| 1606 | u32 country_ie_checksum) |
| 1607 | { |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1608 | struct wiphy *request_wiphy; |
| 1609 | |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 1610 | assert_cfg80211_lock(); |
| 1611 | |
Luis R. Rodriguez | cc0b6fe | 2009-03-20 23:53:05 -0400 | [diff] [blame] | 1612 | if (unlikely(last_request->initiator != |
| 1613 | NL80211_REGDOM_SET_BY_COUNTRY_IE)) |
| 1614 | return false; |
| 1615 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1616 | request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); |
| 1617 | |
| 1618 | if (!request_wiphy) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1619 | return false; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1620 | |
| 1621 | if (likely(request_wiphy != wiphy)) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1622 | return !country_ie_integrity_changes(country_ie_checksum); |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1623 | /* |
| 1624 | * We should not have let these through at this point, they |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1625 | * should have been picked up earlier by the first alpha2 check |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1626 | * on the device |
| 1627 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1628 | if (WARN_ON(!country_ie_integrity_changes(country_ie_checksum))) |
| 1629 | return true; |
| 1630 | return false; |
| 1631 | } |
| 1632 | |
| 1633 | void regulatory_hint_11d(struct wiphy *wiphy, |
| 1634 | u8 *country_ie, |
| 1635 | u8 country_ie_len) |
| 1636 | { |
| 1637 | struct ieee80211_regdomain *rd = NULL; |
| 1638 | char alpha2[2]; |
| 1639 | u32 checksum = 0; |
| 1640 | enum environment_cap env = ENVIRON_ANY; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1641 | struct regulatory_request *request; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1642 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1643 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1644 | |
Luis R. Rodriguez | d335fe6 | 2009-02-21 00:04:27 -0500 | [diff] [blame] | 1645 | if (unlikely(!last_request)) { |
| 1646 | mutex_unlock(&cfg80211_mutex); |
| 1647 | return; |
| 1648 | } |
| 1649 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1650 | /* IE len must be evenly divisible by 2 */ |
| 1651 | if (country_ie_len & 0x01) |
| 1652 | goto out; |
| 1653 | |
| 1654 | if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) |
| 1655 | goto out; |
| 1656 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1657 | /* |
| 1658 | * Pending country IE processing, this can happen after we |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1659 | * call CRDA and wait for a response if a beacon was received before |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1660 | * we were able to process the last regulatory_hint_11d() call |
| 1661 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1662 | if (country_ie_regdomain) |
| 1663 | goto out; |
| 1664 | |
| 1665 | alpha2[0] = country_ie[0]; |
| 1666 | alpha2[1] = country_ie[1]; |
| 1667 | |
| 1668 | if (country_ie[2] == 'I') |
| 1669 | env = ENVIRON_INDOOR; |
| 1670 | else if (country_ie[2] == 'O') |
| 1671 | env = ENVIRON_OUTDOOR; |
| 1672 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1673 | /* |
| 1674 | * We will run this for *every* beacon processed for the BSSID, so |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1675 | * we optimize an early check to exit out early if we don't have to |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1676 | * do anything |
| 1677 | */ |
Luis R. Rodriguez | cc0b6fe | 2009-03-20 23:53:05 -0400 | [diff] [blame] | 1678 | if (likely(last_request->initiator == |
| 1679 | NL80211_REGDOM_SET_BY_COUNTRY_IE && |
| 1680 | wiphy_idx_valid(last_request->wiphy_idx))) { |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1681 | struct cfg80211_registered_device *drv_last_ie; |
| 1682 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1683 | drv_last_ie = |
| 1684 | cfg80211_drv_by_wiphy_idx(last_request->wiphy_idx); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1685 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1686 | /* |
| 1687 | * Lets keep this simple -- we trust the first AP |
| 1688 | * after we intersect with CRDA |
| 1689 | */ |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1690 | if (likely(&drv_last_ie->wiphy == wiphy)) { |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1691 | /* |
| 1692 | * Ignore IEs coming in on this wiphy with |
| 1693 | * the same alpha2 and environment cap |
| 1694 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1695 | if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2, |
| 1696 | alpha2) && |
| 1697 | env == drv_last_ie->env)) { |
| 1698 | goto out; |
| 1699 | } |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1700 | /* |
| 1701 | * the wiphy moved on to another BSSID or the AP |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1702 | * was reconfigured. XXX: We need to deal with the |
| 1703 | * case where the user suspends and goes to goes |
| 1704 | * to another country, and then gets IEs from an |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1705 | * AP with different settings |
| 1706 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1707 | goto out; |
| 1708 | } else { |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1709 | /* |
| 1710 | * Ignore IEs coming in on two separate wiphys with |
| 1711 | * the same alpha2 and environment cap |
| 1712 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1713 | if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2, |
| 1714 | alpha2) && |
| 1715 | env == drv_last_ie->env)) { |
| 1716 | goto out; |
| 1717 | } |
| 1718 | /* We could potentially intersect though */ |
| 1719 | goto out; |
| 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | rd = country_ie_2_rd(country_ie, country_ie_len, &checksum); |
| 1724 | if (!rd) |
| 1725 | goto out; |
| 1726 | |
Luis R. Rodriguez | 915278e | 2009-02-21 00:04:28 -0500 | [diff] [blame] | 1727 | /* |
| 1728 | * This will not happen right now but we leave it here for the |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1729 | * the future when we want to add suspend/resume support and having |
| 1730 | * the user move to another country after doing so, or having the user |
Luis R. Rodriguez | 915278e | 2009-02-21 00:04:28 -0500 | [diff] [blame] | 1731 | * move to another AP. Right now we just trust the first AP. |
| 1732 | * |
| 1733 | * If we hit this before we add this support we want to be informed of |
| 1734 | * it as it would indicate a mistake in the current design |
| 1735 | */ |
| 1736 | if (WARN_ON(reg_same_country_ie_hint(wiphy, checksum))) |
Luis R. Rodriguez | 0441d6f | 2009-02-21 00:04:29 -0500 | [diff] [blame] | 1737 | goto free_rd_out; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1738 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1739 | request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); |
| 1740 | if (!request) |
| 1741 | goto free_rd_out; |
| 1742 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1743 | /* |
| 1744 | * We keep this around for when CRDA comes back with a response so |
| 1745 | * we can intersect with that |
| 1746 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1747 | country_ie_regdomain = rd; |
| 1748 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1749 | request->wiphy_idx = get_wiphy_idx(wiphy); |
| 1750 | request->alpha2[0] = rd->alpha2[0]; |
| 1751 | request->alpha2[1] = rd->alpha2[1]; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1752 | request->initiator = NL80211_REGDOM_SET_BY_COUNTRY_IE; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1753 | request->country_ie_checksum = checksum; |
| 1754 | request->country_ie_env = env; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1755 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1756 | mutex_unlock(&cfg80211_mutex); |
| 1757 | |
| 1758 | queue_regulatory_request(request); |
| 1759 | |
| 1760 | return; |
Luis R. Rodriguez | 0441d6f | 2009-02-21 00:04:29 -0500 | [diff] [blame] | 1761 | |
| 1762 | free_rd_out: |
| 1763 | kfree(rd); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1764 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1765 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1766 | } |
| 1767 | EXPORT_SYMBOL(regulatory_hint_11d); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1768 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1769 | static bool freq_is_chan_12_13_14(u16 freq) |
| 1770 | { |
| 1771 | if (freq == ieee80211_channel_to_frequency(12) || |
| 1772 | freq == ieee80211_channel_to_frequency(13) || |
| 1773 | freq == ieee80211_channel_to_frequency(14)) |
| 1774 | return true; |
| 1775 | return false; |
| 1776 | } |
| 1777 | |
| 1778 | int regulatory_hint_found_beacon(struct wiphy *wiphy, |
| 1779 | struct ieee80211_channel *beacon_chan, |
| 1780 | gfp_t gfp) |
| 1781 | { |
| 1782 | struct reg_beacon *reg_beacon; |
| 1783 | |
| 1784 | if (likely((beacon_chan->beacon_found || |
| 1785 | (beacon_chan->flags & IEEE80211_CHAN_RADAR) || |
| 1786 | (beacon_chan->band == IEEE80211_BAND_2GHZ && |
| 1787 | !freq_is_chan_12_13_14(beacon_chan->center_freq))))) |
| 1788 | return 0; |
| 1789 | |
| 1790 | reg_beacon = kzalloc(sizeof(struct reg_beacon), gfp); |
| 1791 | if (!reg_beacon) |
| 1792 | return -ENOMEM; |
| 1793 | |
| 1794 | #ifdef CONFIG_CFG80211_REG_DEBUG |
| 1795 | printk(KERN_DEBUG "cfg80211: Found new beacon on " |
| 1796 | "frequency: %d MHz (Ch %d) on %s\n", |
| 1797 | beacon_chan->center_freq, |
| 1798 | ieee80211_frequency_to_channel(beacon_chan->center_freq), |
| 1799 | wiphy_name(wiphy)); |
| 1800 | #endif |
| 1801 | memcpy(®_beacon->chan, beacon_chan, |
| 1802 | sizeof(struct ieee80211_channel)); |
| 1803 | |
| 1804 | |
| 1805 | /* |
| 1806 | * Since we can be called from BH or and non-BH context |
| 1807 | * we must use spin_lock_bh() |
| 1808 | */ |
| 1809 | spin_lock_bh(®_pending_beacons_lock); |
| 1810 | list_add_tail(®_beacon->list, ®_pending_beacons); |
| 1811 | spin_unlock_bh(®_pending_beacons_lock); |
| 1812 | |
| 1813 | schedule_work(®_work); |
| 1814 | |
| 1815 | return 0; |
| 1816 | } |
| 1817 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1818 | static void print_rd_rules(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1819 | { |
| 1820 | unsigned int i; |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1821 | const struct ieee80211_reg_rule *reg_rule = NULL; |
| 1822 | const struct ieee80211_freq_range *freq_range = NULL; |
| 1823 | const struct ieee80211_power_rule *power_rule = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1824 | |
| 1825 | printk(KERN_INFO "\t(start_freq - end_freq @ bandwidth), " |
| 1826 | "(max_antenna_gain, max_eirp)\n"); |
| 1827 | |
| 1828 | for (i = 0; i < rd->n_reg_rules; i++) { |
| 1829 | reg_rule = &rd->reg_rules[i]; |
| 1830 | freq_range = ®_rule->freq_range; |
| 1831 | power_rule = ®_rule->power_rule; |
| 1832 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1833 | /* |
| 1834 | * There may not be documentation for max antenna gain |
| 1835 | * in certain regions |
| 1836 | */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1837 | if (power_rule->max_antenna_gain) |
| 1838 | printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), " |
| 1839 | "(%d mBi, %d mBm)\n", |
| 1840 | freq_range->start_freq_khz, |
| 1841 | freq_range->end_freq_khz, |
| 1842 | freq_range->max_bandwidth_khz, |
| 1843 | power_rule->max_antenna_gain, |
| 1844 | power_rule->max_eirp); |
| 1845 | else |
| 1846 | printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), " |
| 1847 | "(N/A, %d mBm)\n", |
| 1848 | freq_range->start_freq_khz, |
| 1849 | freq_range->end_freq_khz, |
| 1850 | freq_range->max_bandwidth_khz, |
| 1851 | power_rule->max_eirp); |
| 1852 | } |
| 1853 | } |
| 1854 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1855 | static void print_regdomain(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1856 | { |
| 1857 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1858 | if (is_intersected_alpha2(rd->alpha2)) { |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1859 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1860 | if (last_request->initiator == |
| 1861 | NL80211_REGDOM_SET_BY_COUNTRY_IE) { |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1862 | struct cfg80211_registered_device *drv; |
| 1863 | drv = cfg80211_drv_by_wiphy_idx( |
| 1864 | last_request->wiphy_idx); |
| 1865 | if (drv) { |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1866 | printk(KERN_INFO "cfg80211: Current regulatory " |
| 1867 | "domain updated by AP to: %c%c\n", |
| 1868 | drv->country_ie_alpha2[0], |
| 1869 | drv->country_ie_alpha2[1]); |
| 1870 | } else |
| 1871 | printk(KERN_INFO "cfg80211: Current regulatory " |
| 1872 | "domain intersected: \n"); |
| 1873 | } else |
| 1874 | printk(KERN_INFO "cfg80211: Current regulatory " |
Luis R. Rodriguez | 039498c | 2009-01-07 17:43:35 -0800 | [diff] [blame] | 1875 | "domain intersected: \n"); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1876 | } else if (is_world_regdom(rd->alpha2)) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1877 | printk(KERN_INFO "cfg80211: World regulatory " |
| 1878 | "domain updated:\n"); |
| 1879 | else { |
| 1880 | if (is_unknown_alpha2(rd->alpha2)) |
| 1881 | printk(KERN_INFO "cfg80211: Regulatory domain " |
| 1882 | "changed to driver built-in settings " |
| 1883 | "(unknown country)\n"); |
| 1884 | else |
| 1885 | printk(KERN_INFO "cfg80211: Regulatory domain " |
| 1886 | "changed to country: %c%c\n", |
| 1887 | rd->alpha2[0], rd->alpha2[1]); |
| 1888 | } |
| 1889 | print_rd_rules(rd); |
| 1890 | } |
| 1891 | |
Johannes Berg | 2df7816 | 2008-10-28 16:49:41 +0100 | [diff] [blame] | 1892 | static void print_regdomain_info(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1893 | { |
| 1894 | printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n", |
| 1895 | rd->alpha2[0], rd->alpha2[1]); |
| 1896 | print_rd_rules(rd); |
| 1897 | } |
| 1898 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1899 | #ifdef CONFIG_CFG80211_REG_DEBUG |
| 1900 | static void reg_country_ie_process_debug( |
| 1901 | const struct ieee80211_regdomain *rd, |
| 1902 | const struct ieee80211_regdomain *country_ie_regdomain, |
| 1903 | const struct ieee80211_regdomain *intersected_rd) |
| 1904 | { |
| 1905 | printk(KERN_DEBUG "cfg80211: Received country IE:\n"); |
| 1906 | print_regdomain_info(country_ie_regdomain); |
| 1907 | printk(KERN_DEBUG "cfg80211: CRDA thinks this should applied:\n"); |
| 1908 | print_regdomain_info(rd); |
| 1909 | if (intersected_rd) { |
| 1910 | printk(KERN_DEBUG "cfg80211: We intersect both of these " |
| 1911 | "and get:\n"); |
Luis R. Rodriguez | 667ecd0 | 2009-01-22 15:05:43 -0800 | [diff] [blame] | 1912 | print_regdomain_info(intersected_rd); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1913 | return; |
| 1914 | } |
| 1915 | printk(KERN_DEBUG "cfg80211: Intersection between both failed\n"); |
| 1916 | } |
| 1917 | #else |
| 1918 | static inline void reg_country_ie_process_debug( |
| 1919 | const struct ieee80211_regdomain *rd, |
| 1920 | const struct ieee80211_regdomain *country_ie_regdomain, |
| 1921 | const struct ieee80211_regdomain *intersected_rd) |
| 1922 | { |
| 1923 | } |
| 1924 | #endif |
| 1925 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 1926 | /* Takes ownership of rd only if it doesn't fail */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1927 | static int __set_regdom(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1928 | { |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1929 | const struct ieee80211_regdomain *intersected_rd = NULL; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1930 | struct cfg80211_registered_device *drv = NULL; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1931 | struct wiphy *request_wiphy; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1932 | /* Some basic sanity checks first */ |
| 1933 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1934 | if (is_world_regdom(rd->alpha2)) { |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 1935 | if (WARN_ON(!reg_is_valid_request(rd->alpha2))) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1936 | return -EINVAL; |
| 1937 | update_world_regdomain(rd); |
| 1938 | return 0; |
| 1939 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1940 | |
| 1941 | if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) && |
| 1942 | !is_unknown_alpha2(rd->alpha2)) |
| 1943 | return -EINVAL; |
| 1944 | |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 1945 | if (!last_request) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1946 | return -EINVAL; |
| 1947 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1948 | /* |
| 1949 | * Lets only bother proceeding on the same alpha2 if the current |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1950 | * rd is non static (it means CRDA was present and was used last) |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1951 | * and the pending request came in from a country IE |
| 1952 | */ |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1953 | if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) { |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1954 | /* |
| 1955 | * If someone else asked us to change the rd lets only bother |
| 1956 | * checking if the alpha2 changes if CRDA was already called |
| 1957 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1958 | if (!is_old_static_regdom(cfg80211_regdomain) && |
Luis R. Rodriguez | 69b1572 | 2009-02-21 00:04:33 -0500 | [diff] [blame] | 1959 | !regdom_changes(rd->alpha2)) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1960 | return -EINVAL; |
| 1961 | } |
| 1962 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1963 | /* |
| 1964 | * Now lets set the regulatory domain, update all driver channels |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1965 | * and finally inform them of what we have done, in case they want |
| 1966 | * to review or adjust their own settings based on their own |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1967 | * internal EEPROM data |
| 1968 | */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1969 | |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 1970 | if (WARN_ON(!reg_is_valid_request(rd->alpha2))) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1971 | return -EINVAL; |
| 1972 | |
Luis R. Rodriguez | 8375af3 | 2008-11-12 14:21:57 -0800 | [diff] [blame] | 1973 | if (!is_valid_rd(rd)) { |
| 1974 | printk(KERN_ERR "cfg80211: Invalid " |
| 1975 | "regulatory domain detected:\n"); |
| 1976 | print_regdomain_info(rd); |
| 1977 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1980 | request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); |
| 1981 | |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 1982 | if (!last_request->intersect) { |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1983 | int r; |
| 1984 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1985 | if (last_request->initiator != NL80211_REGDOM_SET_BY_DRIVER) { |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1986 | reset_regdomains(); |
| 1987 | cfg80211_regdomain = rd; |
| 1988 | return 0; |
| 1989 | } |
| 1990 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1991 | /* |
| 1992 | * For a driver hint, lets copy the regulatory domain the |
| 1993 | * driver wanted to the wiphy to deal with conflicts |
| 1994 | */ |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1995 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1996 | BUG_ON(request_wiphy->regd); |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1997 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1998 | r = reg_copy_regd(&request_wiphy->regd, rd); |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1999 | if (r) |
| 2000 | return r; |
| 2001 | |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 2002 | reset_regdomains(); |
| 2003 | cfg80211_regdomain = rd; |
| 2004 | return 0; |
| 2005 | } |
| 2006 | |
| 2007 | /* Intersection requires a bit more work */ |
| 2008 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 2009 | if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) { |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 2010 | |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 2011 | intersected_rd = regdom_intersect(rd, cfg80211_regdomain); |
| 2012 | if (!intersected_rd) |
| 2013 | return -EINVAL; |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 2014 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 2015 | /* |
| 2016 | * We can trash what CRDA provided now. |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 2017 | * However if a driver requested this specific regulatory |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 2018 | * domain we keep it for its private use |
| 2019 | */ |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 2020 | if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER) |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 2021 | request_wiphy->regd = rd; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 2022 | else |
| 2023 | kfree(rd); |
| 2024 | |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 2025 | rd = NULL; |
| 2026 | |
| 2027 | reset_regdomains(); |
| 2028 | cfg80211_regdomain = intersected_rd; |
| 2029 | |
| 2030 | return 0; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 2031 | } |
| 2032 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2033 | /* |
| 2034 | * Country IE requests are handled a bit differently, we intersect |
| 2035 | * the country IE rd with what CRDA believes that country should have |
| 2036 | */ |
| 2037 | |
| 2038 | BUG_ON(!country_ie_regdomain); |
Luis R. Rodriguez | 86f0468 | 2009-03-20 23:53:07 -0400 | [diff] [blame] | 2039 | BUG_ON(rd == country_ie_regdomain); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2040 | |
Luis R. Rodriguez | 86f0468 | 2009-03-20 23:53:07 -0400 | [diff] [blame] | 2041 | /* |
| 2042 | * Intersect what CRDA returned and our what we |
| 2043 | * had built from the Country IE received |
| 2044 | */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2045 | |
Luis R. Rodriguez | 86f0468 | 2009-03-20 23:53:07 -0400 | [diff] [blame] | 2046 | intersected_rd = regdom_intersect(rd, country_ie_regdomain); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2047 | |
Luis R. Rodriguez | 86f0468 | 2009-03-20 23:53:07 -0400 | [diff] [blame] | 2048 | reg_country_ie_process_debug(rd, |
| 2049 | country_ie_regdomain, |
| 2050 | intersected_rd); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2051 | |
Luis R. Rodriguez | 86f0468 | 2009-03-20 23:53:07 -0400 | [diff] [blame] | 2052 | kfree(country_ie_regdomain); |
| 2053 | country_ie_regdomain = NULL; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2054 | |
| 2055 | if (!intersected_rd) |
| 2056 | return -EINVAL; |
| 2057 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 2058 | drv = wiphy_to_dev(request_wiphy); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2059 | |
| 2060 | drv->country_ie_alpha2[0] = rd->alpha2[0]; |
| 2061 | drv->country_ie_alpha2[1] = rd->alpha2[1]; |
| 2062 | drv->env = last_request->country_ie_env; |
| 2063 | |
| 2064 | BUG_ON(intersected_rd == rd); |
| 2065 | |
| 2066 | kfree(rd); |
| 2067 | rd = NULL; |
| 2068 | |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 2069 | reset_regdomains(); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2070 | cfg80211_regdomain = intersected_rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2071 | |
| 2072 | return 0; |
| 2073 | } |
| 2074 | |
| 2075 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 2076 | /* |
| 2077 | * Use this call to set the current regulatory domain. Conflicts with |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2078 | * multiple drivers can be ironed out later. Caller must've already |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 2079 | * kmalloc'd the rd structure. Caller must hold cfg80211_mutex |
| 2080 | */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 2081 | int set_regdom(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2082 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2083 | int r; |
| 2084 | |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 2085 | assert_cfg80211_lock(); |
| 2086 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2087 | /* Note that this doesn't update the wiphys, this is done below */ |
| 2088 | r = __set_regdom(rd); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 2089 | if (r) { |
| 2090 | kfree(rd); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2091 | return r; |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 2092 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2093 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2094 | /* This would make this whole thing pointless */ |
Luis R. Rodriguez | a01ddaf | 2008-11-12 14:21:59 -0800 | [diff] [blame] | 2095 | if (!last_request->intersect) |
| 2096 | BUG_ON(rd != cfg80211_regdomain); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2097 | |
| 2098 | /* update all wiphys now with the new established regulatory domain */ |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 2099 | update_all_wiphy_regulatory(last_request->initiator); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2100 | |
Luis R. Rodriguez | a01ddaf | 2008-11-12 14:21:59 -0800 | [diff] [blame] | 2101 | print_regdomain(cfg80211_regdomain); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2102 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 2103 | nl80211_send_reg_change_event(last_request); |
| 2104 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2105 | return r; |
| 2106 | } |
| 2107 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2108 | /* Caller must hold cfg80211_mutex */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2109 | void reg_device_remove(struct wiphy *wiphy) |
| 2110 | { |
Luis R. Rodriguez | 0ad8aca | 2009-03-24 21:21:08 -0400 | [diff] [blame] | 2111 | struct wiphy *request_wiphy = NULL; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 2112 | |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 2113 | assert_cfg80211_lock(); |
| 2114 | |
Luis R. Rodriguez | 0ad8aca | 2009-03-24 21:21:08 -0400 | [diff] [blame] | 2115 | if (last_request) |
| 2116 | request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 2117 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 2118 | kfree(wiphy->regd); |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 2119 | if (!last_request || !request_wiphy) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2120 | return; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 2121 | if (request_wiphy != wiphy) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2122 | return; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 2123 | last_request->wiphy_idx = WIPHY_IDX_STALE; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2124 | last_request->country_ie_env = ENVIRON_ANY; |
| 2125 | } |
| 2126 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2127 | int regulatory_init(void) |
| 2128 | { |
Luis R. Rodriguez | bcf4f99 | 2009-02-21 00:04:24 -0500 | [diff] [blame] | 2129 | int err = 0; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2130 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2131 | reg_pdev = platform_device_register_simple("regulatory", 0, NULL, 0); |
| 2132 | if (IS_ERR(reg_pdev)) |
| 2133 | return PTR_ERR(reg_pdev); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2134 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2135 | spin_lock_init(®_requests_lock); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2136 | spin_lock_init(®_pending_beacons_lock); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2137 | |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2138 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 2139 | cfg80211_regdomain = static_regdom(ieee80211_regdom); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2140 | |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 2141 | printk(KERN_INFO "cfg80211: Using static regulatory domain info\n"); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2142 | print_regdomain_info(cfg80211_regdomain); |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 2143 | /* |
| 2144 | * The old code still requests for a new regdomain and if |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2145 | * you have CRDA you get it updated, otherwise you get |
Luis R. Rodriguez | 2e097dc | 2009-03-20 23:53:04 -0400 | [diff] [blame] | 2146 | * stuck with the static values. Since "EU" is not a valid |
| 2147 | * ISO / IEC 3166 alpha2 code we can't expect userpace to |
| 2148 | * give us a regulatory domain for it. We need last_request |
| 2149 | * iniitalized though so lets just send a request which we |
| 2150 | * know will be ignored... this crap will be removed once |
| 2151 | * OLD_REG dies. |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 2152 | */ |
Luis R. Rodriguez | 2e097dc | 2009-03-20 23:53:04 -0400 | [diff] [blame] | 2153 | err = regulatory_hint_core(ieee80211_regdom); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2154 | #else |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 2155 | cfg80211_regdomain = cfg80211_world_regdom; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2156 | |
Luis R. Rodriguez | 6ee7d33 | 2009-03-20 23:53:06 -0400 | [diff] [blame] | 2157 | err = regulatory_hint_core(ieee80211_regdom); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2158 | #endif |
Luis R. Rodriguez | bcf4f99 | 2009-02-21 00:04:24 -0500 | [diff] [blame] | 2159 | if (err) { |
| 2160 | if (err == -ENOMEM) |
| 2161 | return err; |
| 2162 | /* |
| 2163 | * N.B. kobject_uevent_env() can fail mainly for when we're out |
| 2164 | * memory which is handled and propagated appropriately above |
| 2165 | * but it can also fail during a netlink_broadcast() or during |
| 2166 | * early boot for call_usermodehelper(). For now treat these |
| 2167 | * errors as non-fatal. |
| 2168 | */ |
| 2169 | printk(KERN_ERR "cfg80211: kobject_uevent_env() was unable " |
| 2170 | "to call CRDA during init"); |
| 2171 | #ifdef CONFIG_CFG80211_REG_DEBUG |
| 2172 | /* We want to find out exactly why when debugging */ |
| 2173 | WARN_ON(err); |
| 2174 | #endif |
| 2175 | } |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2176 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2177 | return 0; |
| 2178 | } |
| 2179 | |
| 2180 | void regulatory_exit(void) |
| 2181 | { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2182 | struct regulatory_request *reg_request, *tmp; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2183 | struct reg_beacon *reg_beacon, *btmp; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2184 | |
| 2185 | cancel_work_sync(®_work); |
| 2186 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2187 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2188 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2189 | reset_regdomains(); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2190 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2191 | kfree(country_ie_regdomain); |
| 2192 | country_ie_regdomain = NULL; |
| 2193 | |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 2194 | kfree(last_request); |
| 2195 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2196 | platform_device_unregister(reg_pdev); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2197 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2198 | spin_lock_bh(®_pending_beacons_lock); |
| 2199 | if (!list_empty(®_pending_beacons)) { |
| 2200 | list_for_each_entry_safe(reg_beacon, btmp, |
| 2201 | ®_pending_beacons, list) { |
| 2202 | list_del(®_beacon->list); |
| 2203 | kfree(reg_beacon); |
| 2204 | } |
| 2205 | } |
| 2206 | spin_unlock_bh(®_pending_beacons_lock); |
| 2207 | |
| 2208 | if (!list_empty(®_beacon_list)) { |
| 2209 | list_for_each_entry_safe(reg_beacon, btmp, |
| 2210 | ®_beacon_list, list) { |
| 2211 | list_del(®_beacon->list); |
| 2212 | kfree(reg_beacon); |
| 2213 | } |
| 2214 | } |
| 2215 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2216 | spin_lock(®_requests_lock); |
| 2217 | if (!list_empty(®_requests_list)) { |
| 2218 | list_for_each_entry_safe(reg_request, tmp, |
| 2219 | ®_requests_list, list) { |
| 2220 | list_del(®_request->list); |
| 2221 | kfree(reg_request); |
| 2222 | } |
| 2223 | } |
| 2224 | spin_unlock(®_requests_lock); |
| 2225 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2226 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2227 | } |