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