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