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