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