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