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