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