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