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