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 | 3b77d5e | 2011-12-20 12:23:38 -0800 | [diff] [blame] | 5 | * Copyright 2008-2011 Luis R. Rodriguez <mcgrof@qca.qualcomm.com> |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6 | * |
Luis R. Rodriguez | 3b77d5e | 2011-12-20 12:23:38 -0800 | [diff] [blame] | 7 | * Permission to use, copy, modify, and/or distribute this software for any |
| 8 | * purpose with or without fee is hereby granted, provided that the above |
| 9 | * copyright notice and this permission notice appear in all copies. |
| 10 | * |
| 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 18 | */ |
| 19 | |
Luis R. Rodriguez | 3b77d5e | 2011-12-20 12:23:38 -0800 | [diff] [blame] | 20 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 21 | /** |
| 22 | * DOC: Wireless regulatory infrastructure |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 23 | * |
| 24 | * The usual implementation is for a driver to read a device EEPROM to |
| 25 | * determine which regulatory domain it should be operating under, then |
| 26 | * looking up the allowable channels in a driver-local table and finally |
| 27 | * registering those channels in the wiphy structure. |
| 28 | * |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 29 | * Another set of compliance enforcement is for drivers to use their |
| 30 | * own compliance limits which can be stored on the EEPROM. The host |
| 31 | * driver or firmware may ensure these are used. |
| 32 | * |
| 33 | * In addition to all this we provide an extra layer of regulatory |
| 34 | * conformance. For drivers which do not have any regulatory |
| 35 | * information CRDA provides the complete regulatory solution. |
| 36 | * For others it provides a community effort on further restrictions |
| 37 | * to enhance compliance. |
| 38 | * |
| 39 | * Note: When number of rules --> infinity we will not be able to |
| 40 | * index on alpha2 any more, instead we'll probably have to |
| 41 | * rely on some SHA1 checksum of the regdomain for example. |
| 42 | * |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 43 | */ |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 44 | |
| 45 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 46 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 47 | #include <linux/kernel.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 48 | #include <linux/export.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 49 | #include <linux/slab.h> |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 50 | #include <linux/list.h> |
John W. Linville | c61029c | 2010-08-05 14:26:24 -0400 | [diff] [blame] | 51 | #include <linux/ctype.h> |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 52 | #include <linux/nl80211.h> |
| 53 | #include <linux/platform_device.h> |
Paul Gortmaker | d9b9384 | 2011-09-18 13:21:27 -0400 | [diff] [blame] | 54 | #include <linux/moduleparam.h> |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 55 | #include <net/cfg80211.h> |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 56 | #include "core.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 57 | #include "reg.h" |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 58 | #include "regdb.h" |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 59 | #include "nl80211.h" |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 60 | |
Luis R. Rodriguez | 4113f75 | 2010-01-04 11:50:11 -0500 | [diff] [blame] | 61 | #ifdef CONFIG_CFG80211_REG_DEBUG |
Joe Perches | 12c5ffb | 2011-07-29 14:51:25 -0700 | [diff] [blame] | 62 | #define REG_DBG_PRINT(format, args...) \ |
| 63 | printk(KERN_DEBUG pr_fmt(format), ##args) |
Luis R. Rodriguez | 4113f75 | 2010-01-04 11:50:11 -0500 | [diff] [blame] | 64 | #else |
John W. Linville | 8271195 | 2010-01-05 17:57:20 -0500 | [diff] [blame] | 65 | #define REG_DBG_PRINT(args...) |
Luis R. Rodriguez | 4113f75 | 2010-01-04 11:50:11 -0500 | [diff] [blame] | 66 | #endif |
| 67 | |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 68 | /** |
| 69 | * enum reg_request_treatment - regulatory request treatment |
| 70 | * |
| 71 | * @REG_REQ_OK: continue processing the regulatory request |
| 72 | * @REG_REQ_IGNORE: ignore the regulatory request |
| 73 | * @REG_REQ_INTERSECT: the regulatory domain resulting from this request should |
| 74 | * be intersected with the current one. |
| 75 | * @REG_REQ_ALREADY_SET: the regulatory request will not change the current |
| 76 | * regulatory settings, and no further processing is required. |
| 77 | * @REG_REQ_USER_HINT_HANDLED: a non alpha2 user hint was handled and no |
| 78 | * further processing is required, i.e., not need to update last_request |
| 79 | * etc. This should be used for user hints that do not provide an alpha2 |
| 80 | * but some other type of regulatory hint, i.e., indoor operation. |
| 81 | */ |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 82 | enum reg_request_treatment { |
| 83 | REG_REQ_OK, |
| 84 | REG_REQ_IGNORE, |
| 85 | REG_REQ_INTERSECT, |
| 86 | REG_REQ_ALREADY_SET, |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 87 | REG_REQ_USER_HINT_HANDLED, |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
Luis R. Rodriguez | a042994 | 2011-11-28 16:47:15 -0500 | [diff] [blame] | 90 | static struct regulatory_request core_request_world = { |
| 91 | .initiator = NL80211_REGDOM_SET_BY_CORE, |
| 92 | .alpha2[0] = '0', |
| 93 | .alpha2[1] = '0', |
| 94 | .intersect = false, |
| 95 | .processed = true, |
| 96 | .country_ie_env = ENVIRON_ANY, |
| 97 | }; |
| 98 | |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 99 | /* |
| 100 | * Receipt of information from last regulatory request, |
| 101 | * protected by RTNL (and can be accessed with RCU protection) |
| 102 | */ |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 103 | static struct regulatory_request __rcu *last_request = |
| 104 | (void __rcu *)&core_request_world; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 105 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 106 | /* To trigger userspace events */ |
| 107 | static struct platform_device *reg_pdev; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 108 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 109 | /* |
| 110 | * Central wireless core regulatory domains, we only need two, |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 111 | * the current one and a world regulatory domain in case we have no |
Johannes Berg | e8da2bb | 2012-12-03 23:00:08 +0100 | [diff] [blame] | 112 | * information to give us an alpha2. |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 113 | * (protected by RTNL, can be read under RCU) |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 114 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 115 | const struct ieee80211_regdomain __rcu *cfg80211_regdomain; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 116 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 117 | /* |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 118 | * Number of devices that registered to the core |
| 119 | * that support cellular base station regulatory hints |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 120 | * (protected by RTNL) |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 121 | */ |
| 122 | static int reg_num_devs_support_basehint; |
| 123 | |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 124 | /* |
| 125 | * State variable indicating if the platform on which the devices |
| 126 | * are attached is operating in an indoor environment. The state variable |
| 127 | * is relevant for all registered devices. |
| 128 | * (protected by RTNL) |
| 129 | */ |
| 130 | static bool reg_is_indoor; |
| 131 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 132 | static const struct ieee80211_regdomain *get_cfg80211_regdom(void) |
| 133 | { |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 134 | return rtnl_dereference(cfg80211_regdomain); |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static const struct ieee80211_regdomain *get_wiphy_regdom(struct wiphy *wiphy) |
| 138 | { |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 139 | return rtnl_dereference(wiphy->regd); |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Luis R. Rodriguez | 3ef121b | 2013-11-13 18:54:05 +0100 | [diff] [blame] | 142 | static const char *reg_dfs_region_str(enum nl80211_dfs_regions dfs_region) |
| 143 | { |
| 144 | switch (dfs_region) { |
| 145 | case NL80211_DFS_UNSET: |
| 146 | return "unset"; |
| 147 | case NL80211_DFS_FCC: |
| 148 | return "FCC"; |
| 149 | case NL80211_DFS_ETSI: |
| 150 | return "ETSI"; |
| 151 | case NL80211_DFS_JP: |
| 152 | return "JP"; |
| 153 | } |
| 154 | return "Unknown"; |
| 155 | } |
| 156 | |
Luis R. Rodriguez | 6c47479 | 2013-11-25 20:56:09 +0100 | [diff] [blame] | 157 | enum nl80211_dfs_regions reg_get_dfs_region(struct wiphy *wiphy) |
| 158 | { |
| 159 | const struct ieee80211_regdomain *regd = NULL; |
| 160 | const struct ieee80211_regdomain *wiphy_regd = NULL; |
| 161 | |
| 162 | regd = get_cfg80211_regdom(); |
| 163 | if (!wiphy) |
| 164 | goto out; |
| 165 | |
| 166 | wiphy_regd = get_wiphy_regdom(wiphy); |
| 167 | if (!wiphy_regd) |
| 168 | goto out; |
| 169 | |
| 170 | if (wiphy_regd->dfs_region == regd->dfs_region) |
| 171 | goto out; |
| 172 | |
| 173 | REG_DBG_PRINT("%s: device specific dfs_region " |
| 174 | "(%s) disagrees with cfg80211's " |
| 175 | "central dfs_region (%s)\n", |
| 176 | dev_name(&wiphy->dev), |
| 177 | reg_dfs_region_str(wiphy_regd->dfs_region), |
| 178 | reg_dfs_region_str(regd->dfs_region)); |
| 179 | |
| 180 | out: |
| 181 | return regd->dfs_region; |
| 182 | } |
| 183 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 184 | static void rcu_free_regdom(const struct ieee80211_regdomain *r) |
| 185 | { |
| 186 | if (!r) |
| 187 | return; |
| 188 | kfree_rcu((struct ieee80211_regdomain *)r, rcu_head); |
| 189 | } |
| 190 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 191 | static struct regulatory_request *get_last_request(void) |
| 192 | { |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 193 | return rcu_dereference_rtnl(last_request); |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 194 | } |
| 195 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 196 | /* Used to queue up regulatory hints */ |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 197 | static LIST_HEAD(reg_requests_list); |
| 198 | static spinlock_t reg_requests_lock; |
| 199 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 200 | /* Used to queue up beacon hints for review */ |
| 201 | static LIST_HEAD(reg_pending_beacons); |
| 202 | static spinlock_t reg_pending_beacons_lock; |
| 203 | |
| 204 | /* Used to keep track of processed beacon hints */ |
| 205 | static LIST_HEAD(reg_beacon_list); |
| 206 | |
| 207 | struct reg_beacon { |
| 208 | struct list_head list; |
| 209 | struct ieee80211_channel chan; |
| 210 | }; |
| 211 | |
Luis R. Rodriguez | f333a7a | 2010-11-17 21:46:07 -0800 | [diff] [blame] | 212 | static void reg_todo(struct work_struct *work); |
| 213 | static DECLARE_WORK(reg_work, reg_todo); |
| 214 | |
Luis R. Rodriguez | a90c7a3 | 2011-04-05 10:49:04 -0700 | [diff] [blame] | 215 | static void reg_timeout_work(struct work_struct *work); |
| 216 | static DECLARE_DELAYED_WORK(reg_timeout, reg_timeout_work); |
| 217 | |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 218 | /* We keep a static world regulatory domain in case of the absence of CRDA */ |
| 219 | static const struct ieee80211_regdomain world_regdom = { |
Vladimir Kondratiev | 90cdc6d | 2012-07-02 09:32:34 +0300 | [diff] [blame] | 220 | .n_reg_rules = 6, |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 221 | .alpha2 = "00", |
| 222 | .reg_rules = { |
Luis R. Rodriguez | 68798a6 | 2009-02-21 00:20:37 -0500 | [diff] [blame] | 223 | /* IEEE 802.11b/g, channels 1..11 */ |
| 224 | REG_RULE(2412-10, 2462+10, 40, 6, 20, 0), |
Johannes Berg | 43c771a | 2012-11-12 10:51:34 +0100 | [diff] [blame] | 225 | /* IEEE 802.11b/g, channels 12..13. */ |
| 226 | REG_RULE(2467-10, 2472+10, 40, 6, 20, |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 227 | NL80211_RRF_NO_IR), |
Luis R. Rodriguez | 611b6a8 | 2009-03-05 21:19:21 -0800 | [diff] [blame] | 228 | /* IEEE 802.11 channel 14 - Only JP enables |
| 229 | * this and for 802.11b only */ |
| 230 | REG_RULE(2484-10, 2484+10, 20, 6, 20, |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 231 | NL80211_RRF_NO_IR | |
Luis R. Rodriguez | 611b6a8 | 2009-03-05 21:19:21 -0800 | [diff] [blame] | 232 | NL80211_RRF_NO_OFDM), |
| 233 | /* IEEE 802.11a, channel 36..48 */ |
Johannes Berg | 131a19b | 2013-03-04 20:54:46 +0100 | [diff] [blame] | 234 | REG_RULE(5180-10, 5240+10, 160, 6, 20, |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 235 | NL80211_RRF_NO_IR), |
Luis R. Rodriguez | 3fc71f7 | 2009-02-21 00:20:38 -0500 | [diff] [blame] | 236 | |
Johannes Berg | 131a19b | 2013-03-04 20:54:46 +0100 | [diff] [blame] | 237 | /* IEEE 802.11a, channel 52..64 - DFS required */ |
| 238 | REG_RULE(5260-10, 5320+10, 160, 6, 20, |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 239 | NL80211_RRF_NO_IR | |
Johannes Berg | 131a19b | 2013-03-04 20:54:46 +0100 | [diff] [blame] | 240 | NL80211_RRF_DFS), |
| 241 | |
| 242 | /* IEEE 802.11a, channel 100..144 - DFS required */ |
| 243 | REG_RULE(5500-10, 5720+10, 160, 6, 20, |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 244 | NL80211_RRF_NO_IR | |
Johannes Berg | 131a19b | 2013-03-04 20:54:46 +0100 | [diff] [blame] | 245 | NL80211_RRF_DFS), |
Luis R. Rodriguez | 3fc71f7 | 2009-02-21 00:20:38 -0500 | [diff] [blame] | 246 | |
| 247 | /* IEEE 802.11a, channel 149..165 */ |
Johannes Berg | 8ab9d85 | 2012-12-03 22:09:22 +0100 | [diff] [blame] | 248 | REG_RULE(5745-10, 5825+10, 80, 6, 20, |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 249 | NL80211_RRF_NO_IR), |
Vladimir Kondratiev | 90cdc6d | 2012-07-02 09:32:34 +0300 | [diff] [blame] | 250 | |
| 251 | /* IEEE 802.11ad (60gHz), channels 1..3 */ |
| 252 | REG_RULE(56160+2160*1-1080, 56160+2160*3+1080, 2160, 0, 0, 0), |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 253 | } |
| 254 | }; |
| 255 | |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 256 | /* protected by RTNL */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 257 | static const struct ieee80211_regdomain *cfg80211_world_regdom = |
| 258 | &world_regdom; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 259 | |
Luis R. Rodriguez | 6ee7d33 | 2009-03-20 23:53:06 -0400 | [diff] [blame] | 260 | static char *ieee80211_regdom = "00"; |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 261 | static char user_alpha2[2]; |
Luis R. Rodriguez | 6ee7d33 | 2009-03-20 23:53:06 -0400 | [diff] [blame] | 262 | |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 263 | module_param(ieee80211_regdom, charp, 0444); |
| 264 | MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code"); |
| 265 | |
Luis R. Rodriguez | 255e25b | 2014-02-25 17:09:40 -0800 | [diff] [blame] | 266 | static void reg_free_request(struct regulatory_request *lr) |
Luis R. Rodriguez | 5ad6ef5 | 2013-11-05 09:18:08 -0800 | [diff] [blame] | 267 | { |
Luis R. Rodriguez | 5ad6ef5 | 2013-11-05 09:18:08 -0800 | [diff] [blame] | 268 | if (lr != &core_request_world && lr) |
| 269 | kfree_rcu(lr, rcu_head); |
| 270 | } |
| 271 | |
Luis R. Rodriguez | 05f1a3e | 2013-11-05 09:18:09 -0800 | [diff] [blame] | 272 | static void reg_update_last_request(struct regulatory_request *request) |
| 273 | { |
Luis R. Rodriguez | 255e25b | 2014-02-25 17:09:40 -0800 | [diff] [blame] | 274 | struct regulatory_request *lr; |
| 275 | |
| 276 | lr = get_last_request(); |
| 277 | if (lr == request) |
| 278 | return; |
| 279 | |
| 280 | reg_free_request(lr); |
Luis R. Rodriguez | 05f1a3e | 2013-11-05 09:18:09 -0800 | [diff] [blame] | 281 | rcu_assign_pointer(last_request, request); |
| 282 | } |
| 283 | |
Johannes Berg | 379b82f | 2012-12-06 15:44:07 +0100 | [diff] [blame] | 284 | static void reset_regdomains(bool full_reset, |
| 285 | const struct ieee80211_regdomain *new_regdom) |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 286 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 287 | const struct ieee80211_regdomain *r; |
| 288 | |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 289 | ASSERT_RTNL(); |
Johannes Berg | e8da2bb | 2012-12-03 23:00:08 +0100 | [diff] [blame] | 290 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 291 | r = get_cfg80211_regdom(); |
| 292 | |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 293 | /* avoid freeing static information or freeing something twice */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 294 | if (r == cfg80211_world_regdom) |
| 295 | r = NULL; |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 296 | if (cfg80211_world_regdom == &world_regdom) |
| 297 | cfg80211_world_regdom = NULL; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 298 | if (r == &world_regdom) |
| 299 | r = NULL; |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 300 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 301 | rcu_free_regdom(r); |
| 302 | rcu_free_regdom(cfg80211_world_regdom); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 303 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 304 | cfg80211_world_regdom = &world_regdom; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 305 | rcu_assign_pointer(cfg80211_regdomain, new_regdom); |
Luis R. Rodriguez | a042994 | 2011-11-28 16:47:15 -0500 | [diff] [blame] | 306 | |
| 307 | if (!full_reset) |
| 308 | return; |
| 309 | |
Luis R. Rodriguez | 05f1a3e | 2013-11-05 09:18:09 -0800 | [diff] [blame] | 310 | reg_update_last_request(&core_request_world); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 311 | } |
| 312 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 313 | /* |
| 314 | * Dynamic world regulatory domain requested by the wireless |
| 315 | * core upon initialization |
| 316 | */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 317 | static void update_world_regdomain(const struct ieee80211_regdomain *rd) |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 318 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 319 | struct regulatory_request *lr; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 320 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 321 | lr = get_last_request(); |
| 322 | |
| 323 | WARN_ON(!lr); |
Johannes Berg | e8da2bb | 2012-12-03 23:00:08 +0100 | [diff] [blame] | 324 | |
Johannes Berg | 379b82f | 2012-12-06 15:44:07 +0100 | [diff] [blame] | 325 | reset_regdomains(false, rd); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 326 | |
| 327 | cfg80211_world_regdom = rd; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 328 | } |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 329 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 330 | bool is_world_regdom(const char *alpha2) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 331 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 332 | if (!alpha2) |
| 333 | return false; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 334 | return alpha2[0] == '0' && alpha2[1] == '0'; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 335 | } |
| 336 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 337 | static bool is_alpha2_set(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 338 | { |
| 339 | if (!alpha2) |
| 340 | return false; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 341 | return alpha2[0] && alpha2[1]; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 342 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 343 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 344 | static bool is_unknown_alpha2(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 345 | { |
| 346 | if (!alpha2) |
| 347 | return false; |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 348 | /* |
| 349 | * Special case where regulatory domain was built by driver |
| 350 | * but a specific alpha2 cannot be determined |
| 351 | */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 352 | return alpha2[0] == '9' && alpha2[1] == '9'; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 355 | static bool is_intersected_alpha2(const char *alpha2) |
| 356 | { |
| 357 | if (!alpha2) |
| 358 | return false; |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 359 | /* |
| 360 | * Special case where regulatory domain is the |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 361 | * result of an intersection between two regulatory domain |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 362 | * structures |
| 363 | */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 364 | return alpha2[0] == '9' && alpha2[1] == '8'; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 367 | static bool is_an_alpha2(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 368 | { |
| 369 | if (!alpha2) |
| 370 | return false; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 371 | return isalpha(alpha2[0]) && isalpha(alpha2[1]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 374 | 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] | 375 | { |
| 376 | if (!alpha2_x || !alpha2_y) |
| 377 | return false; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 378 | return alpha2_x[0] == alpha2_y[0] && alpha2_x[1] == alpha2_y[1]; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Luis R. Rodriguez | 69b1572 | 2009-02-21 00:04:33 -0500 | [diff] [blame] | 381 | static bool regdom_changes(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 382 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 383 | const struct ieee80211_regdomain *r = get_cfg80211_regdom(); |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 384 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 385 | if (!r) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 386 | return true; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 387 | return !alpha2_equal(r->alpha2, alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 390 | /* |
| 391 | * The NL80211_REGDOM_SET_BY_USER regdom alpha2 is cached, this lets |
| 392 | * you know if a valid regulatory hint with NL80211_REGDOM_SET_BY_USER |
| 393 | * has ever been issued. |
| 394 | */ |
| 395 | static bool is_user_regdom_saved(void) |
| 396 | { |
| 397 | if (user_alpha2[0] == '9' && user_alpha2[1] == '7') |
| 398 | return false; |
| 399 | |
| 400 | /* This would indicate a mistake on the design */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 401 | if (WARN(!is_world_regdom(user_alpha2) && !is_an_alpha2(user_alpha2), |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 402 | "Unexpected user alpha2: %c%c\n", |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 403 | user_alpha2[0], user_alpha2[1])) |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 404 | return false; |
| 405 | |
| 406 | return true; |
| 407 | } |
| 408 | |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 409 | static const struct ieee80211_regdomain * |
| 410 | reg_copy_regd(const struct ieee80211_regdomain *src_regd) |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 411 | { |
| 412 | struct ieee80211_regdomain *regd; |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 413 | int size_of_regd; |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 414 | unsigned int i; |
| 415 | |
Johannes Berg | 82f2085 | 2012-12-04 12:49:16 +0100 | [diff] [blame] | 416 | size_of_regd = |
| 417 | sizeof(struct ieee80211_regdomain) + |
| 418 | src_regd->n_reg_rules * sizeof(struct ieee80211_reg_rule); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 419 | |
| 420 | regd = kzalloc(size_of_regd, GFP_KERNEL); |
| 421 | if (!regd) |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 422 | return ERR_PTR(-ENOMEM); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 423 | |
| 424 | memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain)); |
| 425 | |
| 426 | for (i = 0; i < src_regd->n_reg_rules; i++) |
| 427 | memcpy(®d->reg_rules[i], &src_regd->reg_rules[i], |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 428 | sizeof(struct ieee80211_reg_rule)); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 429 | |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 430 | return regd; |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | #ifdef CONFIG_CFG80211_INTERNAL_REGDB |
| 434 | struct reg_regdb_search_request { |
| 435 | char alpha2[2]; |
| 436 | struct list_head list; |
| 437 | }; |
| 438 | |
| 439 | static LIST_HEAD(reg_regdb_search_list); |
John W. Linville | 368d06f | 2010-03-16 15:40:59 -0400 | [diff] [blame] | 440 | static DEFINE_MUTEX(reg_regdb_search_mutex); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 441 | |
| 442 | static void reg_regdb_search(struct work_struct *work) |
| 443 | { |
| 444 | struct reg_regdb_search_request *request; |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 445 | const struct ieee80211_regdomain *curdom, *regdom = NULL; |
| 446 | int i; |
Luis R. Rodriguez | a85d0d7 | 2012-09-14 15:36:57 -0700 | [diff] [blame] | 447 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 448 | rtnl_lock(); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 449 | |
John W. Linville | 368d06f | 2010-03-16 15:40:59 -0400 | [diff] [blame] | 450 | mutex_lock(®_regdb_search_mutex); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 451 | while (!list_empty(®_regdb_search_list)) { |
| 452 | request = list_first_entry(®_regdb_search_list, |
| 453 | struct reg_regdb_search_request, |
| 454 | list); |
| 455 | list_del(&request->list); |
| 456 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 457 | for (i = 0; i < reg_regdb_size; i++) { |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 458 | curdom = reg_regdb[i]; |
| 459 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 460 | if (alpha2_equal(request->alpha2, curdom->alpha2)) { |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 461 | regdom = reg_copy_regd(curdom); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 462 | break; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | kfree(request); |
| 467 | } |
John W. Linville | 368d06f | 2010-03-16 15:40:59 -0400 | [diff] [blame] | 468 | mutex_unlock(®_regdb_search_mutex); |
Luis R. Rodriguez | a85d0d7 | 2012-09-14 15:36:57 -0700 | [diff] [blame] | 469 | |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 470 | if (!IS_ERR_OR_NULL(regdom)) |
Luis R. Rodriguez | a85d0d7 | 2012-09-14 15:36:57 -0700 | [diff] [blame] | 471 | set_regdom(regdom); |
| 472 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 473 | rtnl_unlock(); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static DECLARE_WORK(reg_regdb_work, reg_regdb_search); |
| 477 | |
| 478 | static void reg_regdb_query(const char *alpha2) |
| 479 | { |
| 480 | struct reg_regdb_search_request *request; |
| 481 | |
| 482 | if (!alpha2) |
| 483 | return; |
| 484 | |
| 485 | request = kzalloc(sizeof(struct reg_regdb_search_request), GFP_KERNEL); |
| 486 | if (!request) |
| 487 | return; |
| 488 | |
| 489 | memcpy(request->alpha2, alpha2, 2); |
| 490 | |
John W. Linville | 368d06f | 2010-03-16 15:40:59 -0400 | [diff] [blame] | 491 | mutex_lock(®_regdb_search_mutex); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 492 | list_add_tail(&request->list, ®_regdb_search_list); |
John W. Linville | 368d06f | 2010-03-16 15:40:59 -0400 | [diff] [blame] | 493 | mutex_unlock(®_regdb_search_mutex); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 494 | |
| 495 | schedule_work(®_regdb_work); |
| 496 | } |
Luis R. Rodriguez | 80007ef | 2012-03-23 07:23:31 -0700 | [diff] [blame] | 497 | |
| 498 | /* Feel free to add any other sanity checks here */ |
| 499 | static void reg_regdb_size_check(void) |
| 500 | { |
| 501 | /* We should ideally BUILD_BUG_ON() but then random builds would fail */ |
| 502 | WARN_ONCE(!reg_regdb_size, "db.txt is empty, you should update it..."); |
| 503 | } |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 504 | #else |
Luis R. Rodriguez | 80007ef | 2012-03-23 07:23:31 -0700 | [diff] [blame] | 505 | static inline void reg_regdb_size_check(void) {} |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 506 | static inline void reg_regdb_query(const char *alpha2) {} |
| 507 | #endif /* CONFIG_CFG80211_INTERNAL_REGDB */ |
| 508 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 509 | /* |
| 510 | * This lets us keep regulatory code which is updated on a regulatory |
Johannes Berg | 1226d25 | 2014-02-25 15:43:36 +0100 | [diff] [blame] | 511 | * basis in userspace. |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 512 | */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 513 | static int call_crda(const char *alpha2) |
| 514 | { |
Johannes Berg | 1226d25 | 2014-02-25 15:43:36 +0100 | [diff] [blame] | 515 | char country[12]; |
| 516 | char *env[] = { country, NULL }; |
| 517 | |
| 518 | snprintf(country, sizeof(country), "COUNTRY=%c%c", |
| 519 | alpha2[0], alpha2[1]); |
| 520 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 521 | if (!is_world_regdom((char *) alpha2)) |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 522 | pr_info("Calling CRDA for country: %c%c\n", |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 523 | alpha2[0], alpha2[1]); |
| 524 | else |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 525 | pr_info("Calling CRDA to update world regulatory domain\n"); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 526 | |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 527 | /* query internal regulatory database (if it exists) */ |
| 528 | reg_regdb_query(alpha2); |
| 529 | |
Johannes Berg | 1226d25 | 2014-02-25 15:43:36 +0100 | [diff] [blame] | 530 | return kobject_uevent_env(®_pdev->dev.kobj, KOBJ_CHANGE, env); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Luis R. Rodriguez | fe6631f | 2013-11-05 09:18:10 -0800 | [diff] [blame] | 533 | static enum reg_request_treatment |
| 534 | reg_call_crda(struct regulatory_request *request) |
| 535 | { |
| 536 | if (call_crda(request->alpha2)) |
| 537 | return REG_REQ_IGNORE; |
| 538 | return REG_REQ_OK; |
| 539 | } |
| 540 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 541 | bool reg_is_valid_request(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 542 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 543 | struct regulatory_request *lr = get_last_request(); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 544 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 545 | if (!lr || lr->processed) |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 546 | return false; |
| 547 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 548 | return alpha2_equal(lr->alpha2, alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Janusz Dziedzic | e3961af | 2014-01-25 11:24:11 +0100 | [diff] [blame] | 551 | static const struct ieee80211_regdomain *reg_get_regdomain(struct wiphy *wiphy) |
| 552 | { |
| 553 | struct regulatory_request *lr = get_last_request(); |
| 554 | |
| 555 | /* |
| 556 | * Follow the driver's regulatory domain, if present, unless a country |
| 557 | * IE has been processed or a user wants to help complaince further |
| 558 | */ |
| 559 | if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && |
| 560 | lr->initiator != NL80211_REGDOM_SET_BY_USER && |
| 561 | wiphy->regd) |
| 562 | return get_wiphy_regdom(wiphy); |
| 563 | |
| 564 | return get_cfg80211_regdom(); |
| 565 | } |
| 566 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 567 | unsigned int reg_get_max_bandwidth(const struct ieee80211_regdomain *rd, |
| 568 | const struct ieee80211_reg_rule *rule) |
| 569 | { |
| 570 | const struct ieee80211_freq_range *freq_range = &rule->freq_range; |
| 571 | const struct ieee80211_freq_range *freq_range_tmp; |
| 572 | const struct ieee80211_reg_rule *tmp; |
| 573 | u32 start_freq, end_freq, idx, no; |
| 574 | |
| 575 | for (idx = 0; idx < rd->n_reg_rules; idx++) |
| 576 | if (rule == &rd->reg_rules[idx]) |
| 577 | break; |
| 578 | |
| 579 | if (idx == rd->n_reg_rules) |
| 580 | return 0; |
| 581 | |
| 582 | /* get start_freq */ |
| 583 | no = idx; |
| 584 | |
| 585 | while (no) { |
| 586 | tmp = &rd->reg_rules[--no]; |
| 587 | freq_range_tmp = &tmp->freq_range; |
| 588 | |
| 589 | if (freq_range_tmp->end_freq_khz < freq_range->start_freq_khz) |
| 590 | break; |
| 591 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 592 | freq_range = freq_range_tmp; |
| 593 | } |
| 594 | |
| 595 | start_freq = freq_range->start_freq_khz; |
| 596 | |
| 597 | /* get end_freq */ |
| 598 | freq_range = &rule->freq_range; |
| 599 | no = idx; |
| 600 | |
| 601 | while (no < rd->n_reg_rules - 1) { |
| 602 | tmp = &rd->reg_rules[++no]; |
| 603 | freq_range_tmp = &tmp->freq_range; |
| 604 | |
| 605 | if (freq_range_tmp->start_freq_khz > freq_range->end_freq_khz) |
| 606 | break; |
| 607 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 608 | freq_range = freq_range_tmp; |
| 609 | } |
| 610 | |
| 611 | end_freq = freq_range->end_freq_khz; |
| 612 | |
| 613 | return end_freq - start_freq; |
| 614 | } |
| 615 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 616 | /* Sanity check on a regulatory rule */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 617 | 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] | 618 | { |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 619 | const struct ieee80211_freq_range *freq_range = &rule->freq_range; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 620 | u32 freq_diff; |
| 621 | |
Luis R. Rodriguez | 91e9900 | 2008-11-12 14:21:55 -0800 | [diff] [blame] | 622 | 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] | 623 | return false; |
| 624 | |
| 625 | if (freq_range->start_freq_khz > freq_range->end_freq_khz) |
| 626 | return false; |
| 627 | |
| 628 | freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; |
| 629 | |
Roel Kluin | bd05f28 | 2009-03-03 22:55:21 +0100 | [diff] [blame] | 630 | if (freq_range->end_freq_khz <= freq_range->start_freq_khz || |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 631 | freq_range->max_bandwidth_khz > freq_diff) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 632 | return false; |
| 633 | |
| 634 | return true; |
| 635 | } |
| 636 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 637 | static bool is_valid_rd(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 638 | { |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 639 | const struct ieee80211_reg_rule *reg_rule = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 640 | unsigned int i; |
| 641 | |
| 642 | if (!rd->n_reg_rules) |
| 643 | return false; |
| 644 | |
Luis R. Rodriguez | 88dc1c3 | 2008-11-12 14:22:01 -0800 | [diff] [blame] | 645 | if (WARN_ON(rd->n_reg_rules > NL80211_MAX_SUPP_REG_RULES)) |
| 646 | return false; |
| 647 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 648 | for (i = 0; i < rd->n_reg_rules; i++) { |
| 649 | reg_rule = &rd->reg_rules[i]; |
| 650 | if (!is_valid_reg_rule(reg_rule)) |
| 651 | return false; |
| 652 | } |
| 653 | |
| 654 | return true; |
| 655 | } |
| 656 | |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 657 | static bool reg_does_bw_fit(const struct ieee80211_freq_range *freq_range, |
Johannes Berg | fe7ef5e | 2012-12-04 15:07:34 +0100 | [diff] [blame] | 658 | u32 center_freq_khz, u32 bw_khz) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 659 | { |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 660 | u32 start_freq_khz, end_freq_khz; |
| 661 | |
| 662 | start_freq_khz = center_freq_khz - (bw_khz/2); |
| 663 | end_freq_khz = center_freq_khz + (bw_khz/2); |
| 664 | |
| 665 | if (start_freq_khz >= freq_range->start_freq_khz && |
| 666 | end_freq_khz <= freq_range->end_freq_khz) |
| 667 | return true; |
| 668 | |
| 669 | return false; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 672 | /** |
| 673 | * freq_in_rule_band - tells us if a frequency is in a frequency band |
| 674 | * @freq_range: frequency rule we want to query |
| 675 | * @freq_khz: frequency we are inquiring about |
| 676 | * |
| 677 | * This lets us know if a specific frequency rule is or is not relevant to |
| 678 | * a specific frequency's band. Bands are device specific and artificial |
Vladimir Kondratiev | 64629b9 | 2012-09-23 09:49:54 +0200 | [diff] [blame] | 679 | * definitions (the "2.4 GHz band", the "5 GHz band" and the "60GHz band"), |
| 680 | * however it is safe for now to assume that a frequency rule should not be |
| 681 | * part of a frequency's band if the start freq or end freq are off by more |
| 682 | * than 2 GHz for the 2.4 and 5 GHz bands, and by more than 10 GHz for the |
| 683 | * 60 GHz band. |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 684 | * This resolution can be lowered and should be considered as we add |
| 685 | * regulatory rule support for other "bands". |
| 686 | **/ |
| 687 | static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 688 | u32 freq_khz) |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 689 | { |
| 690 | #define ONE_GHZ_IN_KHZ 1000000 |
Vladimir Kondratiev | 64629b9 | 2012-09-23 09:49:54 +0200 | [diff] [blame] | 691 | /* |
| 692 | * From 802.11ad: directional multi-gigabit (DMG): |
| 693 | * Pertaining to operation in a frequency band containing a channel |
| 694 | * with the Channel starting frequency above 45 GHz. |
| 695 | */ |
| 696 | u32 limit = freq_khz > 45 * ONE_GHZ_IN_KHZ ? |
| 697 | 10 * ONE_GHZ_IN_KHZ : 2 * ONE_GHZ_IN_KHZ; |
| 698 | if (abs(freq_khz - freq_range->start_freq_khz) <= limit) |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 699 | return true; |
Vladimir Kondratiev | 64629b9 | 2012-09-23 09:49:54 +0200 | [diff] [blame] | 700 | if (abs(freq_khz - freq_range->end_freq_khz) <= limit) |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 701 | return true; |
| 702 | return false; |
| 703 | #undef ONE_GHZ_IN_KHZ |
| 704 | } |
| 705 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 706 | /* |
Luis R. Rodriguez | adbfb05 | 2013-11-13 18:54:03 +0100 | [diff] [blame] | 707 | * Later on we can perhaps use the more restrictive DFS |
| 708 | * region but we don't have information for that yet so |
| 709 | * for now simply disallow conflicts. |
| 710 | */ |
| 711 | static enum nl80211_dfs_regions |
| 712 | reg_intersect_dfs_region(const enum nl80211_dfs_regions dfs_region1, |
| 713 | const enum nl80211_dfs_regions dfs_region2) |
| 714 | { |
| 715 | if (dfs_region1 != dfs_region2) |
| 716 | return NL80211_DFS_UNSET; |
| 717 | return dfs_region1; |
| 718 | } |
| 719 | |
| 720 | /* |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 721 | * Helper for regdom_intersect(), this does the real |
| 722 | * mathematical intersection fun |
| 723 | */ |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 724 | static int reg_rules_intersect(const struct ieee80211_regdomain *rd1, |
| 725 | const struct ieee80211_regdomain *rd2, |
| 726 | const struct ieee80211_reg_rule *rule1, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 727 | const struct ieee80211_reg_rule *rule2, |
| 728 | struct ieee80211_reg_rule *intersected_rule) |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 729 | { |
| 730 | const struct ieee80211_freq_range *freq_range1, *freq_range2; |
| 731 | struct ieee80211_freq_range *freq_range; |
| 732 | const struct ieee80211_power_rule *power_rule1, *power_rule2; |
| 733 | struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 734 | u32 freq_diff, max_bandwidth1, max_bandwidth2; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 735 | |
| 736 | freq_range1 = &rule1->freq_range; |
| 737 | freq_range2 = &rule2->freq_range; |
| 738 | freq_range = &intersected_rule->freq_range; |
| 739 | |
| 740 | power_rule1 = &rule1->power_rule; |
| 741 | power_rule2 = &rule2->power_rule; |
| 742 | power_rule = &intersected_rule->power_rule; |
| 743 | |
| 744 | freq_range->start_freq_khz = max(freq_range1->start_freq_khz, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 745 | freq_range2->start_freq_khz); |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 746 | freq_range->end_freq_khz = min(freq_range1->end_freq_khz, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 747 | freq_range2->end_freq_khz); |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 748 | |
| 749 | max_bandwidth1 = freq_range1->max_bandwidth_khz; |
| 750 | max_bandwidth2 = freq_range2->max_bandwidth_khz; |
| 751 | |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 752 | if (rule1->flags & NL80211_RRF_AUTO_BW) |
| 753 | max_bandwidth1 = reg_get_max_bandwidth(rd1, rule1); |
| 754 | if (rule2->flags & NL80211_RRF_AUTO_BW) |
| 755 | max_bandwidth2 = reg_get_max_bandwidth(rd2, rule2); |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 756 | |
| 757 | freq_range->max_bandwidth_khz = min(max_bandwidth1, max_bandwidth2); |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 758 | |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 759 | intersected_rule->flags = rule1->flags | rule2->flags; |
| 760 | |
| 761 | /* |
| 762 | * In case NL80211_RRF_AUTO_BW requested for both rules |
| 763 | * set AUTO_BW in intersected rule also. Next we will |
| 764 | * calculate BW correctly in handle_channel function. |
| 765 | * In other case remove AUTO_BW flag while we calculate |
| 766 | * maximum bandwidth correctly and auto calculation is |
| 767 | * not required. |
| 768 | */ |
| 769 | if ((rule1->flags & NL80211_RRF_AUTO_BW) && |
| 770 | (rule2->flags & NL80211_RRF_AUTO_BW)) |
| 771 | intersected_rule->flags |= NL80211_RRF_AUTO_BW; |
| 772 | else |
| 773 | intersected_rule->flags &= ~NL80211_RRF_AUTO_BW; |
| 774 | |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 775 | freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; |
| 776 | if (freq_range->max_bandwidth_khz > freq_diff) |
| 777 | freq_range->max_bandwidth_khz = freq_diff; |
| 778 | |
| 779 | power_rule->max_eirp = min(power_rule1->max_eirp, |
| 780 | power_rule2->max_eirp); |
| 781 | power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain, |
| 782 | power_rule2->max_antenna_gain); |
| 783 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 784 | intersected_rule->dfs_cac_ms = max(rule1->dfs_cac_ms, |
| 785 | rule2->dfs_cac_ms); |
| 786 | |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 787 | if (!is_valid_reg_rule(intersected_rule)) |
| 788 | return -EINVAL; |
| 789 | |
| 790 | return 0; |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * regdom_intersect - do the intersection between two regulatory domains |
| 795 | * @rd1: first regulatory domain |
| 796 | * @rd2: second regulatory domain |
| 797 | * |
| 798 | * Use this function to get the intersection between two regulatory domains. |
| 799 | * Once completed we will mark the alpha2 for the rd as intersected, "98", |
| 800 | * as no one single alpha2 can represent this regulatory domain. |
| 801 | * |
| 802 | * Returns a pointer to the regulatory domain structure which will hold the |
| 803 | * resulting intersection of rules between rd1 and rd2. We will |
| 804 | * kzalloc() this structure for you. |
| 805 | */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 806 | static struct ieee80211_regdomain * |
| 807 | regdom_intersect(const struct ieee80211_regdomain *rd1, |
| 808 | const struct ieee80211_regdomain *rd2) |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 809 | { |
| 810 | int r, size_of_regd; |
| 811 | unsigned int x, y; |
| 812 | unsigned int num_rules = 0, rule_idx = 0; |
| 813 | const struct ieee80211_reg_rule *rule1, *rule2; |
| 814 | struct ieee80211_reg_rule *intersected_rule; |
| 815 | struct ieee80211_regdomain *rd; |
| 816 | /* This is just a dummy holder to help us count */ |
Johannes Berg | 74f53cd | 2012-12-06 17:26:17 +0100 | [diff] [blame] | 817 | struct ieee80211_reg_rule dummy_rule; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 818 | |
| 819 | if (!rd1 || !rd2) |
| 820 | return NULL; |
| 821 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 822 | /* |
| 823 | * 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] | 824 | * build them. This is to so we can malloc() and free() a |
| 825 | * regdomain once. The reason we use reg_rules_intersect() here |
| 826 | * 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] | 827 | * All rules that do check out OK are valid. |
| 828 | */ |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 829 | |
| 830 | for (x = 0; x < rd1->n_reg_rules; x++) { |
| 831 | rule1 = &rd1->reg_rules[x]; |
| 832 | for (y = 0; y < rd2->n_reg_rules; y++) { |
| 833 | rule2 = &rd2->reg_rules[y]; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 834 | if (!reg_rules_intersect(rd1, rd2, rule1, rule2, |
| 835 | &dummy_rule)) |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 836 | num_rules++; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | |
| 840 | if (!num_rules) |
| 841 | return NULL; |
| 842 | |
| 843 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 82f2085 | 2012-12-04 12:49:16 +0100 | [diff] [blame] | 844 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 845 | |
| 846 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
| 847 | if (!rd) |
| 848 | return NULL; |
| 849 | |
Johannes Berg | 8a57fff | 2012-12-06 17:03:17 +0100 | [diff] [blame] | 850 | for (x = 0; x < rd1->n_reg_rules && rule_idx < num_rules; x++) { |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 851 | rule1 = &rd1->reg_rules[x]; |
Johannes Berg | 8a57fff | 2012-12-06 17:03:17 +0100 | [diff] [blame] | 852 | for (y = 0; y < rd2->n_reg_rules && rule_idx < num_rules; y++) { |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 853 | rule2 = &rd2->reg_rules[y]; |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 854 | /* |
| 855 | * This time around instead of using the stack lets |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 856 | * write to the target rule directly saving ourselves |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 857 | * a memcpy() |
| 858 | */ |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 859 | intersected_rule = &rd->reg_rules[rule_idx]; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 860 | r = reg_rules_intersect(rd1, rd2, rule1, rule2, |
| 861 | intersected_rule); |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 862 | /* |
| 863 | * No need to memset here the intersected rule here as |
| 864 | * we're not using the stack anymore |
| 865 | */ |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 866 | if (r) |
| 867 | continue; |
| 868 | rule_idx++; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | if (rule_idx != num_rules) { |
| 873 | kfree(rd); |
| 874 | return NULL; |
| 875 | } |
| 876 | |
| 877 | rd->n_reg_rules = num_rules; |
| 878 | rd->alpha2[0] = '9'; |
| 879 | rd->alpha2[1] = '8'; |
Luis R. Rodriguez | adbfb05 | 2013-11-13 18:54:03 +0100 | [diff] [blame] | 880 | rd->dfs_region = reg_intersect_dfs_region(rd1->dfs_region, |
| 881 | rd2->dfs_region); |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 882 | |
| 883 | return rd; |
| 884 | } |
| 885 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 886 | /* |
| 887 | * XXX: add support for the rest of enum nl80211_reg_rule_flags, we may |
| 888 | * want to just have the channel structure use these |
| 889 | */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 890 | static u32 map_regdom_flags(u32 rd_flags) |
| 891 | { |
| 892 | u32 channel_flags = 0; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 893 | if (rd_flags & NL80211_RRF_NO_IR_ALL) |
| 894 | channel_flags |= IEEE80211_CHAN_NO_IR; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 895 | if (rd_flags & NL80211_RRF_DFS) |
| 896 | channel_flags |= IEEE80211_CHAN_RADAR; |
Seth Forshee | 03f6b08 | 2012-08-01 15:58:42 -0500 | [diff] [blame] | 897 | if (rd_flags & NL80211_RRF_NO_OFDM) |
| 898 | channel_flags |= IEEE80211_CHAN_NO_OFDM; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 899 | if (rd_flags & NL80211_RRF_NO_OUTDOOR) |
| 900 | channel_flags |= IEEE80211_CHAN_INDOOR_ONLY; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 901 | return channel_flags; |
| 902 | } |
| 903 | |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 904 | static const struct ieee80211_reg_rule * |
| 905 | freq_reg_info_regd(struct wiphy *wiphy, u32 center_freq, |
| 906 | const struct ieee80211_regdomain *regd) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 907 | { |
| 908 | int i; |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 909 | bool band_rule_found = false; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 910 | bool bw_fits = false; |
| 911 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 912 | if (!regd) |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 913 | return ERR_PTR(-EINVAL); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 914 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 915 | for (i = 0; i < regd->n_reg_rules; i++) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 916 | const struct ieee80211_reg_rule *rr; |
| 917 | const struct ieee80211_freq_range *fr = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 918 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 919 | rr = ®d->reg_rules[i]; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 920 | fr = &rr->freq_range; |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 921 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 922 | /* |
| 923 | * We only need to know if one frequency rule was |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 924 | * was in center_freq's band, that's enough, so lets |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 925 | * not overwrite it once found |
| 926 | */ |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 927 | if (!band_rule_found) |
| 928 | band_rule_found = freq_in_rule_band(fr, center_freq); |
| 929 | |
Johannes Berg | fe7ef5e | 2012-12-04 15:07:34 +0100 | [diff] [blame] | 930 | bw_fits = reg_does_bw_fit(fr, center_freq, MHZ_TO_KHZ(20)); |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 931 | |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 932 | if (band_rule_found && bw_fits) |
| 933 | return rr; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 934 | } |
| 935 | |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 936 | if (!band_rule_found) |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 937 | return ERR_PTR(-ERANGE); |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 938 | |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 939 | return ERR_PTR(-EINVAL); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 940 | } |
| 941 | |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 942 | const struct ieee80211_reg_rule *freq_reg_info(struct wiphy *wiphy, |
| 943 | u32 center_freq) |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 944 | { |
Johannes Berg | 5d885b9 | 2012-12-04 00:14:17 +0100 | [diff] [blame] | 945 | const struct ieee80211_regdomain *regd; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 946 | |
Janusz Dziedzic | e3961af | 2014-01-25 11:24:11 +0100 | [diff] [blame] | 947 | regd = reg_get_regdomain(wiphy); |
Johannes Berg | 5d885b9 | 2012-12-04 00:14:17 +0100 | [diff] [blame] | 948 | |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 949 | return freq_reg_info_regd(wiphy, center_freq, regd); |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 950 | } |
John W. Linville | 4f366c5 | 2010-07-15 14:57:33 -0400 | [diff] [blame] | 951 | EXPORT_SYMBOL(freq_reg_info); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 952 | |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 953 | const char *reg_initiator_name(enum nl80211_reg_initiator initiator) |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 954 | { |
| 955 | switch (initiator) { |
| 956 | case NL80211_REGDOM_SET_BY_CORE: |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 957 | return "core"; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 958 | case NL80211_REGDOM_SET_BY_USER: |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 959 | return "user"; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 960 | case NL80211_REGDOM_SET_BY_DRIVER: |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 961 | return "driver"; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 962 | case NL80211_REGDOM_SET_BY_COUNTRY_IE: |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 963 | return "country IE"; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 964 | default: |
| 965 | WARN_ON(1); |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 966 | return "bug"; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 967 | } |
| 968 | } |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 969 | EXPORT_SYMBOL(reg_initiator_name); |
Luis R. Rodriguez | e702d3c | 2010-10-21 19:17:04 +0530 | [diff] [blame] | 970 | |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 971 | #ifdef CONFIG_CFG80211_REG_DEBUG |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 972 | static void chan_reg_rule_print_dbg(const struct ieee80211_regdomain *regd, |
| 973 | struct ieee80211_channel *chan, |
Luis R. Rodriguez | e702d3c | 2010-10-21 19:17:04 +0530 | [diff] [blame] | 974 | const struct ieee80211_reg_rule *reg_rule) |
| 975 | { |
| 976 | const struct ieee80211_power_rule *power_rule; |
| 977 | const struct ieee80211_freq_range *freq_range; |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 978 | char max_antenna_gain[32], bw[32]; |
Luis R. Rodriguez | e702d3c | 2010-10-21 19:17:04 +0530 | [diff] [blame] | 979 | |
| 980 | power_rule = ®_rule->power_rule; |
| 981 | freq_range = ®_rule->freq_range; |
| 982 | |
| 983 | if (!power_rule->max_antenna_gain) |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 984 | snprintf(max_antenna_gain, sizeof(max_antenna_gain), "N/A"); |
Luis R. Rodriguez | e702d3c | 2010-10-21 19:17:04 +0530 | [diff] [blame] | 985 | else |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 986 | snprintf(max_antenna_gain, sizeof(max_antenna_gain), "%d", |
| 987 | power_rule->max_antenna_gain); |
| 988 | |
| 989 | if (reg_rule->flags & NL80211_RRF_AUTO_BW) |
| 990 | snprintf(bw, sizeof(bw), "%d KHz, %d KHz AUTO", |
| 991 | freq_range->max_bandwidth_khz, |
| 992 | reg_get_max_bandwidth(regd, reg_rule)); |
| 993 | else |
| 994 | snprintf(bw, sizeof(bw), "%d KHz", |
| 995 | freq_range->max_bandwidth_khz); |
Luis R. Rodriguez | e702d3c | 2010-10-21 19:17:04 +0530 | [diff] [blame] | 996 | |
Johannes Berg | fe7ef5e | 2012-12-04 15:07:34 +0100 | [diff] [blame] | 997 | REG_DBG_PRINT("Updating information on frequency %d MHz with regulatory rule:\n", |
| 998 | chan->center_freq); |
Luis R. Rodriguez | e702d3c | 2010-10-21 19:17:04 +0530 | [diff] [blame] | 999 | |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 1000 | REG_DBG_PRINT("%d KHz - %d KHz @ %s), (%s mBi, %d mBm)\n", |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1001 | freq_range->start_freq_khz, freq_range->end_freq_khz, |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 1002 | bw, max_antenna_gain, |
Luis R. Rodriguez | e702d3c | 2010-10-21 19:17:04 +0530 | [diff] [blame] | 1003 | power_rule->max_eirp); |
| 1004 | } |
| 1005 | #else |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 1006 | static void chan_reg_rule_print_dbg(const struct ieee80211_regdomain *regd, |
| 1007 | struct ieee80211_channel *chan, |
Luis R. Rodriguez | e702d3c | 2010-10-21 19:17:04 +0530 | [diff] [blame] | 1008 | const struct ieee80211_reg_rule *reg_rule) |
| 1009 | { |
| 1010 | return; |
| 1011 | } |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 1012 | #endif |
| 1013 | |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1014 | /* |
| 1015 | * Note that right now we assume the desired channel bandwidth |
| 1016 | * is always 20 MHz for each individual channel (HT40 uses 20 MHz |
Johannes Berg | fe7ef5e | 2012-12-04 15:07:34 +0100 | [diff] [blame] | 1017 | * per channel, the primary and the extension channel). |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1018 | */ |
Luis R. Rodriguez | 7ca43d0 | 2010-10-20 10:18:53 -0700 | [diff] [blame] | 1019 | static void handle_channel(struct wiphy *wiphy, |
| 1020 | enum nl80211_reg_initiator initiator, |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1021 | struct ieee80211_channel *chan) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1022 | { |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1023 | u32 flags, bw_flags = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1024 | const struct ieee80211_reg_rule *reg_rule = NULL; |
| 1025 | const struct ieee80211_power_rule *power_rule = NULL; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1026 | const struct ieee80211_freq_range *freq_range = NULL; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1027 | struct wiphy *request_wiphy = NULL; |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1028 | struct regulatory_request *lr = get_last_request(); |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1029 | const struct ieee80211_regdomain *regd; |
| 1030 | u32 max_bandwidth_khz; |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 1031 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1032 | request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 1033 | |
| 1034 | flags = chan->orig_flags; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1035 | |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 1036 | reg_rule = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); |
| 1037 | if (IS_ERR(reg_rule)) { |
Luis R. Rodriguez | ca4ffe8 | 2010-10-20 10:18:55 -0700 | [diff] [blame] | 1038 | /* |
| 1039 | * We will disable all channels that do not match our |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1040 | * received regulatory rule unless the hint is coming |
Luis R. Rodriguez | ca4ffe8 | 2010-10-20 10:18:55 -0700 | [diff] [blame] | 1041 | * from a Country IE and the Country IE had no information |
| 1042 | * about a band. The IEEE 802.11 spec allows for an AP |
| 1043 | * to send only a subset of the regulatory rules allowed, |
| 1044 | * so an AP in the US that only supports 2.4 GHz may only send |
| 1045 | * a country IE with information for the 2.4 GHz band |
| 1046 | * while 5 GHz is still supported. |
| 1047 | */ |
| 1048 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 1049 | PTR_ERR(reg_rule) == -ERANGE) |
Luis R. Rodriguez | ca4ffe8 | 2010-10-20 10:18:55 -0700 | [diff] [blame] | 1050 | return; |
| 1051 | |
Luis R. Rodriguez | cc493e4f | 2013-11-06 17:54:44 +0100 | [diff] [blame] | 1052 | if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && |
| 1053 | request_wiphy && request_wiphy == wiphy && |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 1054 | request_wiphy->regulatory_flags & REGULATORY_STRICT_REG) { |
Luis R. Rodriguez | cc493e4f | 2013-11-06 17:54:44 +0100 | [diff] [blame] | 1055 | REG_DBG_PRINT("Disabling freq %d MHz for good\n", |
| 1056 | chan->center_freq); |
| 1057 | chan->orig_flags |= IEEE80211_CHAN_DISABLED; |
| 1058 | chan->flags = chan->orig_flags; |
| 1059 | } else { |
| 1060 | REG_DBG_PRINT("Disabling freq %d MHz\n", |
| 1061 | chan->center_freq); |
| 1062 | chan->flags |= IEEE80211_CHAN_DISABLED; |
| 1063 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1064 | return; |
Luis R. Rodriguez | ca4ffe8 | 2010-10-20 10:18:55 -0700 | [diff] [blame] | 1065 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1066 | |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 1067 | regd = reg_get_regdomain(wiphy); |
| 1068 | chan_reg_rule_print_dbg(regd, chan, reg_rule); |
Luis R. Rodriguez | e702d3c | 2010-10-21 19:17:04 +0530 | [diff] [blame] | 1069 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1070 | power_rule = ®_rule->power_rule; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1071 | freq_range = ®_rule->freq_range; |
| 1072 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1073 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 1074 | /* Check if auto calculation requested */ |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 1075 | if (reg_rule->flags & NL80211_RRF_AUTO_BW) |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1076 | max_bandwidth_khz = reg_get_max_bandwidth(regd, reg_rule); |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1077 | |
| 1078 | if (max_bandwidth_khz < MHZ_TO_KHZ(40)) |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1079 | bw_flags = IEEE80211_CHAN_NO_HT40; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1080 | if (max_bandwidth_khz < MHZ_TO_KHZ(80)) |
Johannes Berg | c7a6ee2 | 2012-12-12 17:50:39 +0100 | [diff] [blame] | 1081 | bw_flags |= IEEE80211_CHAN_NO_80MHZ; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1082 | if (max_bandwidth_khz < MHZ_TO_KHZ(160)) |
Johannes Berg | c7a6ee2 | 2012-12-12 17:50:39 +0100 | [diff] [blame] | 1083 | bw_flags |= IEEE80211_CHAN_NO_160MHZ; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1084 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1085 | if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1086 | request_wiphy && request_wiphy == wiphy && |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 1087 | request_wiphy->regulatory_flags & REGULATORY_STRICT_REG) { |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1088 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1089 | * This guarantees the driver's requested regulatory domain |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 1090 | * will always be used as a base for further regulatory |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1091 | * settings |
| 1092 | */ |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 1093 | chan->flags = chan->orig_flags = |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1094 | map_regdom_flags(reg_rule->flags) | bw_flags; |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 1095 | chan->max_antenna_gain = chan->orig_mag = |
| 1096 | (int) MBI_TO_DBI(power_rule->max_antenna_gain); |
Felix Fietkau | 279f0f5 | 2012-10-17 13:56:20 +0200 | [diff] [blame] | 1097 | chan->max_reg_power = chan->max_power = chan->orig_mpwr = |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 1098 | (int) MBM_TO_DBM(power_rule->max_eirp); |
Janusz Dziedzic | 4f267c1 | 2014-04-09 13:47:12 +0200 | [diff] [blame^] | 1099 | |
| 1100 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 1101 | chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 1102 | if (reg_rule->dfs_cac_ms) |
| 1103 | chan->dfs_cac_ms = reg_rule->dfs_cac_ms; |
| 1104 | } |
| 1105 | |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 1106 | return; |
| 1107 | } |
| 1108 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 1109 | chan->dfs_state = NL80211_DFS_USABLE; |
| 1110 | chan->dfs_state_entered = jiffies; |
| 1111 | |
Rajkumar Manoharan | aa3d7ee | 2011-09-14 14:28:17 +0530 | [diff] [blame] | 1112 | chan->beacon_found = false; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1113 | chan->flags = flags | bw_flags | map_regdom_flags(reg_rule->flags); |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1114 | chan->max_antenna_gain = |
| 1115 | min_t(int, chan->orig_mag, |
| 1116 | MBI_TO_DBI(power_rule->max_antenna_gain)); |
Hong Wu | eccc068 | 2012-01-11 20:33:39 +0200 | [diff] [blame] | 1117 | chan->max_reg_power = (int) MBM_TO_DBM(power_rule->max_eirp); |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 1118 | |
| 1119 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 1120 | if (reg_rule->dfs_cac_ms) |
| 1121 | chan->dfs_cac_ms = reg_rule->dfs_cac_ms; |
| 1122 | else |
| 1123 | chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 1124 | } |
| 1125 | |
Stanislaw Gruszka | 5e31fc0 | 2012-07-24 08:35:39 +0200 | [diff] [blame] | 1126 | if (chan->orig_mpwr) { |
| 1127 | /* |
Luis R. Rodriguez | a09a85a | 2013-11-11 22:15:30 +0100 | [diff] [blame] | 1128 | * Devices that use REGULATORY_COUNTRY_IE_FOLLOW_POWER |
| 1129 | * will always follow the passed country IE power settings. |
Stanislaw Gruszka | 5e31fc0 | 2012-07-24 08:35:39 +0200 | [diff] [blame] | 1130 | */ |
| 1131 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && |
Luis R. Rodriguez | a09a85a | 2013-11-11 22:15:30 +0100 | [diff] [blame] | 1132 | wiphy->regulatory_flags & REGULATORY_COUNTRY_IE_FOLLOW_POWER) |
Stanislaw Gruszka | 5e31fc0 | 2012-07-24 08:35:39 +0200 | [diff] [blame] | 1133 | chan->max_power = chan->max_reg_power; |
| 1134 | else |
| 1135 | chan->max_power = min(chan->orig_mpwr, |
| 1136 | chan->max_reg_power); |
| 1137 | } else |
| 1138 | chan->max_power = chan->max_reg_power; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1139 | } |
| 1140 | |
Luis R. Rodriguez | 7ca43d0 | 2010-10-20 10:18:53 -0700 | [diff] [blame] | 1141 | static void handle_band(struct wiphy *wiphy, |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1142 | enum nl80211_reg_initiator initiator, |
| 1143 | struct ieee80211_supported_band *sband) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1144 | { |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 1145 | unsigned int i; |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 1146 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1147 | if (!sband) |
| 1148 | return; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1149 | |
| 1150 | for (i = 0; i < sband->n_channels; i++) |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1151 | handle_channel(wiphy, initiator, &sband->channels[i]); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1152 | } |
| 1153 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1154 | static bool reg_request_cell_base(struct regulatory_request *request) |
| 1155 | { |
| 1156 | if (request->initiator != NL80211_REGDOM_SET_BY_USER) |
| 1157 | return false; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1158 | return request->user_reg_hint_type == NL80211_USER_REG_HINT_CELL_BASE; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 1161 | static bool reg_request_indoor(struct regulatory_request *request) |
| 1162 | { |
| 1163 | if (request->initiator != NL80211_REGDOM_SET_BY_USER) |
| 1164 | return false; |
| 1165 | return request->user_reg_hint_type == NL80211_USER_REG_HINT_INDOOR; |
| 1166 | } |
| 1167 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1168 | bool reg_last_request_cell_base(void) |
| 1169 | { |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 1170 | return reg_request_cell_base(get_last_request()); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Ilan Peer | 94fc661 | 2014-02-23 09:13:00 +0200 | [diff] [blame] | 1173 | #ifdef CONFIG_CFG80211_REG_CELLULAR_HINTS |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1174 | /* Core specific check */ |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 1175 | static enum reg_request_treatment |
| 1176 | reg_ignore_cell_hint(struct regulatory_request *pending_request) |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1177 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1178 | struct regulatory_request *lr = get_last_request(); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1179 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1180 | if (!reg_num_devs_support_basehint) |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 1181 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1182 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1183 | if (reg_request_cell_base(lr) && |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1184 | !regdom_changes(pending_request->alpha2)) |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 1185 | return REG_REQ_ALREADY_SET; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1186 | |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 1187 | return REG_REQ_OK; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | /* Device specific check */ |
| 1191 | static bool reg_dev_ignore_cell_hint(struct wiphy *wiphy) |
| 1192 | { |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1193 | return !(wiphy->features & NL80211_FEATURE_CELL_BASE_REG_HINTS); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1194 | } |
| 1195 | #else |
| 1196 | static int reg_ignore_cell_hint(struct regulatory_request *pending_request) |
| 1197 | { |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 1198 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1199 | } |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1200 | |
| 1201 | static bool reg_dev_ignore_cell_hint(struct wiphy *wiphy) |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1202 | { |
| 1203 | return true; |
| 1204 | } |
| 1205 | #endif |
| 1206 | |
Luis R. Rodriguez | fa1fb9c | 2013-10-02 18:33:10 -0700 | [diff] [blame] | 1207 | static bool wiphy_strict_alpha2_regd(struct wiphy *wiphy) |
| 1208 | { |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 1209 | if (wiphy->regulatory_flags & REGULATORY_STRICT_REG && |
| 1210 | !(wiphy->regulatory_flags & REGULATORY_CUSTOM_REG)) |
Luis R. Rodriguez | fa1fb9c | 2013-10-02 18:33:10 -0700 | [diff] [blame] | 1211 | return true; |
| 1212 | return false; |
| 1213 | } |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1214 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1215 | static bool ignore_reg_update(struct wiphy *wiphy, |
| 1216 | enum nl80211_reg_initiator initiator) |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 1217 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1218 | struct regulatory_request *lr = get_last_request(); |
| 1219 | |
| 1220 | if (!lr) { |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 1221 | REG_DBG_PRINT("Ignoring regulatory request set by %s " |
| 1222 | "since last_request is not set\n", |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 1223 | reg_initiator_name(initiator)); |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 1224 | return true; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 1225 | } |
| 1226 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1227 | if (initiator == NL80211_REGDOM_SET_BY_CORE && |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 1228 | wiphy->regulatory_flags & REGULATORY_CUSTOM_REG) { |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 1229 | REG_DBG_PRINT("Ignoring regulatory request set by %s " |
| 1230 | "since the driver uses its own custom " |
| 1231 | "regulatory domain\n", |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 1232 | reg_initiator_name(initiator)); |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 1233 | return true; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 1234 | } |
| 1235 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1236 | /* |
| 1237 | * wiphy->regd will be set once the device has its own |
| 1238 | * desired regulatory domain set |
| 1239 | */ |
Luis R. Rodriguez | fa1fb9c | 2013-10-02 18:33:10 -0700 | [diff] [blame] | 1240 | if (wiphy_strict_alpha2_regd(wiphy) && !wiphy->regd && |
Luis R. Rodriguez | 749b527 | 2010-10-20 10:18:54 -0700 | [diff] [blame] | 1241 | initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1242 | !is_world_regdom(lr->alpha2)) { |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 1243 | REG_DBG_PRINT("Ignoring regulatory request set by %s " |
| 1244 | "since the driver requires its own regulatory " |
| 1245 | "domain to be set first\n", |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 1246 | reg_initiator_name(initiator)); |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 1247 | return true; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 1248 | } |
| 1249 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1250 | if (reg_request_cell_base(lr)) |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1251 | return reg_dev_ignore_cell_hint(wiphy); |
| 1252 | |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 1253 | return false; |
| 1254 | } |
| 1255 | |
Luis R. Rodriguez | 3195e48 | 2012-12-19 10:53:03 -0800 | [diff] [blame] | 1256 | static bool reg_is_world_roaming(struct wiphy *wiphy) |
| 1257 | { |
| 1258 | const struct ieee80211_regdomain *cr = get_cfg80211_regdom(); |
| 1259 | const struct ieee80211_regdomain *wr = get_wiphy_regdom(wiphy); |
| 1260 | struct regulatory_request *lr = get_last_request(); |
| 1261 | |
| 1262 | if (is_world_regdom(cr->alpha2) || (wr && is_world_regdom(wr->alpha2))) |
| 1263 | return true; |
| 1264 | |
| 1265 | if (lr && lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 1266 | wiphy->regulatory_flags & REGULATORY_CUSTOM_REG) |
Luis R. Rodriguez | 3195e48 | 2012-12-19 10:53:03 -0800 | [diff] [blame] | 1267 | return true; |
| 1268 | |
| 1269 | return false; |
| 1270 | } |
| 1271 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1272 | static void handle_reg_beacon(struct wiphy *wiphy, unsigned int chan_idx, |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1273 | struct reg_beacon *reg_beacon) |
| 1274 | { |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1275 | struct ieee80211_supported_band *sband; |
| 1276 | struct ieee80211_channel *chan; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 1277 | bool channel_changed = false; |
| 1278 | struct ieee80211_channel chan_before; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1279 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1280 | sband = wiphy->bands[reg_beacon->chan.band]; |
| 1281 | chan = &sband->channels[chan_idx]; |
| 1282 | |
| 1283 | if (likely(chan->center_freq != reg_beacon->chan.center_freq)) |
| 1284 | return; |
| 1285 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 1286 | if (chan->beacon_found) |
| 1287 | return; |
| 1288 | |
| 1289 | chan->beacon_found = true; |
| 1290 | |
Luis R. Rodriguez | 0f500a5 | 2012-12-19 10:53:04 -0800 | [diff] [blame] | 1291 | if (!reg_is_world_roaming(wiphy)) |
| 1292 | return; |
| 1293 | |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 1294 | if (wiphy->regulatory_flags & REGULATORY_DISABLE_BEACON_HINTS) |
Luis R. Rodriguez | 3718424 | 2009-07-30 17:43:48 -0700 | [diff] [blame] | 1295 | return; |
| 1296 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 1297 | chan_before.center_freq = chan->center_freq; |
| 1298 | chan_before.flags = chan->flags; |
| 1299 | |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 1300 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 1301 | chan->flags &= ~IEEE80211_CHAN_NO_IR; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 1302 | channel_changed = true; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1303 | } |
| 1304 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 1305 | if (channel_changed) |
| 1306 | nl80211_send_beacon_hint_event(wiphy, &chan_before, chan); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | /* |
| 1310 | * Called when a scan on a wiphy finds a beacon on |
| 1311 | * new channel |
| 1312 | */ |
| 1313 | static void wiphy_update_new_beacon(struct wiphy *wiphy, |
| 1314 | struct reg_beacon *reg_beacon) |
| 1315 | { |
| 1316 | unsigned int i; |
| 1317 | struct ieee80211_supported_band *sband; |
| 1318 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1319 | if (!wiphy->bands[reg_beacon->chan.band]) |
| 1320 | return; |
| 1321 | |
| 1322 | sband = wiphy->bands[reg_beacon->chan.band]; |
| 1323 | |
| 1324 | for (i = 0; i < sband->n_channels; i++) |
| 1325 | handle_reg_beacon(wiphy, i, reg_beacon); |
| 1326 | } |
| 1327 | |
| 1328 | /* |
| 1329 | * Called upon reg changes or a new wiphy is added |
| 1330 | */ |
| 1331 | static void wiphy_update_beacon_reg(struct wiphy *wiphy) |
| 1332 | { |
| 1333 | unsigned int i; |
| 1334 | struct ieee80211_supported_band *sband; |
| 1335 | struct reg_beacon *reg_beacon; |
| 1336 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1337 | list_for_each_entry(reg_beacon, ®_beacon_list, list) { |
| 1338 | if (!wiphy->bands[reg_beacon->chan.band]) |
| 1339 | continue; |
| 1340 | sband = wiphy->bands[reg_beacon->chan.band]; |
| 1341 | for (i = 0; i < sband->n_channels; i++) |
| 1342 | handle_reg_beacon(wiphy, i, reg_beacon); |
| 1343 | } |
| 1344 | } |
| 1345 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1346 | /* Reap the advantages of previously found beacons */ |
| 1347 | static void reg_process_beacons(struct wiphy *wiphy) |
| 1348 | { |
Luis R. Rodriguez | b1ed8dd | 2009-05-02 00:34:15 -0400 | [diff] [blame] | 1349 | /* |
| 1350 | * Means we are just firing up cfg80211, so no beacons would |
| 1351 | * have been processed yet. |
| 1352 | */ |
| 1353 | if (!last_request) |
| 1354 | return; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1355 | wiphy_update_beacon_reg(wiphy); |
| 1356 | } |
| 1357 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1358 | static bool is_ht40_allowed(struct ieee80211_channel *chan) |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1359 | { |
| 1360 | if (!chan) |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1361 | return false; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1362 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1363 | return false; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1364 | /* This would happen when regulatory rules disallow HT40 completely */ |
Felix Fietkau | 55b183a | 2013-01-11 14:22:58 +0100 | [diff] [blame] | 1365 | if ((chan->flags & IEEE80211_CHAN_NO_HT40) == IEEE80211_CHAN_NO_HT40) |
| 1366 | return false; |
| 1367 | return true; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | static void reg_process_ht_flags_channel(struct wiphy *wiphy, |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1371 | struct ieee80211_channel *channel) |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1372 | { |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1373 | struct ieee80211_supported_band *sband = wiphy->bands[channel->band]; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1374 | struct ieee80211_channel *channel_before = NULL, *channel_after = NULL; |
| 1375 | unsigned int i; |
| 1376 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1377 | if (!is_ht40_allowed(channel)) { |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1378 | channel->flags |= IEEE80211_CHAN_NO_HT40; |
| 1379 | return; |
| 1380 | } |
| 1381 | |
| 1382 | /* |
| 1383 | * We need to ensure the extension channels exist to |
| 1384 | * be able to use HT40- or HT40+, this finds them (or not) |
| 1385 | */ |
| 1386 | for (i = 0; i < sband->n_channels; i++) { |
| 1387 | struct ieee80211_channel *c = &sband->channels[i]; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1388 | |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1389 | if (c->center_freq == (channel->center_freq - 20)) |
| 1390 | channel_before = c; |
| 1391 | if (c->center_freq == (channel->center_freq + 20)) |
| 1392 | channel_after = c; |
| 1393 | } |
| 1394 | |
| 1395 | /* |
| 1396 | * Please note that this assumes target bandwidth is 20 MHz, |
| 1397 | * if that ever changes we also need to change the below logic |
| 1398 | * to include that as well. |
| 1399 | */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1400 | if (!is_ht40_allowed(channel_before)) |
Luis R. Rodriguez | 689da1b | 2009-05-02 00:37:18 -0400 | [diff] [blame] | 1401 | channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1402 | else |
Luis R. Rodriguez | 689da1b | 2009-05-02 00:37:18 -0400 | [diff] [blame] | 1403 | channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1404 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1405 | if (!is_ht40_allowed(channel_after)) |
Luis R. Rodriguez | 689da1b | 2009-05-02 00:37:18 -0400 | [diff] [blame] | 1406 | channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1407 | else |
Luis R. Rodriguez | 689da1b | 2009-05-02 00:37:18 -0400 | [diff] [blame] | 1408 | channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | static void reg_process_ht_flags_band(struct wiphy *wiphy, |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1412 | struct ieee80211_supported_band *sband) |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1413 | { |
| 1414 | unsigned int i; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1415 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1416 | if (!sband) |
| 1417 | return; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1418 | |
| 1419 | for (i = 0; i < sband->n_channels; i++) |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1420 | reg_process_ht_flags_channel(wiphy, &sband->channels[i]); |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | static void reg_process_ht_flags(struct wiphy *wiphy) |
| 1424 | { |
| 1425 | enum ieee80211_band band; |
| 1426 | |
| 1427 | if (!wiphy) |
| 1428 | return; |
| 1429 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1430 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 1431 | reg_process_ht_flags_band(wiphy, wiphy->bands[band]); |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1432 | } |
| 1433 | |
Luis R. Rodriguez | 0e3802d | 2013-11-05 09:18:12 -0800 | [diff] [blame] | 1434 | static void reg_call_notifier(struct wiphy *wiphy, |
| 1435 | struct regulatory_request *request) |
| 1436 | { |
| 1437 | if (wiphy->reg_notifier) |
| 1438 | wiphy->reg_notifier(wiphy, request); |
| 1439 | } |
| 1440 | |
Sven Neumann | eac03e3 | 2011-08-30 23:38:53 +0200 | [diff] [blame] | 1441 | static void wiphy_update_regulatory(struct wiphy *wiphy, |
| 1442 | enum nl80211_reg_initiator initiator) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1443 | { |
| 1444 | enum ieee80211_band band; |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1445 | struct regulatory_request *lr = get_last_request(); |
Sven Neumann | eac03e3 | 2011-08-30 23:38:53 +0200 | [diff] [blame] | 1446 | |
Luis R. Rodriguez | 0e3802d | 2013-11-05 09:18:12 -0800 | [diff] [blame] | 1447 | if (ignore_reg_update(wiphy, initiator)) { |
| 1448 | /* |
| 1449 | * Regulatory updates set by CORE are ignored for custom |
| 1450 | * regulatory cards. Let us notify the changes to the driver, |
| 1451 | * as some drivers used this to restore its orig_* reg domain. |
| 1452 | */ |
| 1453 | if (initiator == NL80211_REGDOM_SET_BY_CORE && |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 1454 | wiphy->regulatory_flags & REGULATORY_CUSTOM_REG) |
Luis R. Rodriguez | 0e3802d | 2013-11-05 09:18:12 -0800 | [diff] [blame] | 1455 | reg_call_notifier(wiphy, lr); |
Sven Neumann | a203c2a | 2011-07-12 15:52:07 +0200 | [diff] [blame] | 1456 | return; |
Luis R. Rodriguez | 0e3802d | 2013-11-05 09:18:12 -0800 | [diff] [blame] | 1457 | } |
Sven Neumann | a203c2a | 2011-07-12 15:52:07 +0200 | [diff] [blame] | 1458 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1459 | lr->dfs_region = get_cfg80211_regdom()->dfs_region; |
Luis R. Rodriguez | b68e6b3 | 2011-10-11 10:59:03 -0700 | [diff] [blame] | 1460 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1461 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 1462 | handle_band(wiphy, initiator, wiphy->bands[band]); |
Sven Neumann | a203c2a | 2011-07-12 15:52:07 +0200 | [diff] [blame] | 1463 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1464 | reg_process_beacons(wiphy); |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1465 | reg_process_ht_flags(wiphy); |
Luis R. Rodriguez | 0e3802d | 2013-11-05 09:18:12 -0800 | [diff] [blame] | 1466 | reg_call_notifier(wiphy, lr); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Sven Neumann | d7549cb | 2011-08-30 23:38:54 +0200 | [diff] [blame] | 1469 | static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator) |
| 1470 | { |
| 1471 | struct cfg80211_registered_device *rdev; |
Rajkumar Manoharan | 4a38994 | 2011-12-08 23:59:26 +0530 | [diff] [blame] | 1472 | struct wiphy *wiphy; |
Sven Neumann | d7549cb | 2011-08-30 23:38:54 +0200 | [diff] [blame] | 1473 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1474 | ASSERT_RTNL(); |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 1475 | |
Rajkumar Manoharan | 4a38994 | 2011-12-08 23:59:26 +0530 | [diff] [blame] | 1476 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1477 | wiphy = &rdev->wiphy; |
| 1478 | wiphy_update_regulatory(wiphy, initiator); |
Rajkumar Manoharan | 4a38994 | 2011-12-08 23:59:26 +0530 | [diff] [blame] | 1479 | } |
Sven Neumann | d7549cb | 2011-08-30 23:38:54 +0200 | [diff] [blame] | 1480 | } |
| 1481 | |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1482 | static void handle_channel_custom(struct wiphy *wiphy, |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1483 | struct ieee80211_channel *chan, |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1484 | const struct ieee80211_regdomain *regd) |
| 1485 | { |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1486 | u32 bw_flags = 0; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1487 | const struct ieee80211_reg_rule *reg_rule = NULL; |
| 1488 | const struct ieee80211_power_rule *power_rule = NULL; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1489 | const struct ieee80211_freq_range *freq_range = NULL; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1490 | u32 max_bandwidth_khz; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1491 | |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 1492 | reg_rule = freq_reg_info_regd(wiphy, MHZ_TO_KHZ(chan->center_freq), |
| 1493 | regd); |
Luis R. Rodriguez | ac46d48 | 2009-05-01 18:44:50 -0400 | [diff] [blame] | 1494 | |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 1495 | if (IS_ERR(reg_rule)) { |
Johannes Berg | fe7ef5e | 2012-12-04 15:07:34 +0100 | [diff] [blame] | 1496 | REG_DBG_PRINT("Disabling freq %d MHz as custom regd has no rule that fits it\n", |
| 1497 | chan->center_freq); |
Luis R. Rodriguez | cc493e4f | 2013-11-06 17:54:44 +0100 | [diff] [blame] | 1498 | chan->orig_flags |= IEEE80211_CHAN_DISABLED; |
| 1499 | chan->flags = chan->orig_flags; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1500 | return; |
| 1501 | } |
| 1502 | |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 1503 | chan_reg_rule_print_dbg(regd, chan, reg_rule); |
Luis R. Rodriguez | e702d3c | 2010-10-21 19:17:04 +0530 | [diff] [blame] | 1504 | |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1505 | power_rule = ®_rule->power_rule; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1506 | freq_range = ®_rule->freq_range; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1507 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1508 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 1509 | /* Check if auto calculation requested */ |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 1510 | if (reg_rule->flags & NL80211_RRF_AUTO_BW) |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1511 | max_bandwidth_khz = reg_get_max_bandwidth(regd, reg_rule); |
| 1512 | |
| 1513 | if (max_bandwidth_khz < MHZ_TO_KHZ(40)) |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1514 | bw_flags = IEEE80211_CHAN_NO_HT40; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1515 | if (max_bandwidth_khz < MHZ_TO_KHZ(80)) |
Johannes Berg | c7a6ee2 | 2012-12-12 17:50:39 +0100 | [diff] [blame] | 1516 | bw_flags |= IEEE80211_CHAN_NO_80MHZ; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1517 | if (max_bandwidth_khz < MHZ_TO_KHZ(160)) |
Johannes Berg | c7a6ee2 | 2012-12-12 17:50:39 +0100 | [diff] [blame] | 1518 | bw_flags |= IEEE80211_CHAN_NO_160MHZ; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1519 | |
| 1520 | chan->flags |= map_regdom_flags(reg_rule->flags) | bw_flags; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1521 | chan->max_antenna_gain = (int) MBI_TO_DBI(power_rule->max_antenna_gain); |
Felix Fietkau | 279f0f5 | 2012-10-17 13:56:20 +0200 | [diff] [blame] | 1522 | chan->max_reg_power = chan->max_power = |
| 1523 | (int) MBM_TO_DBM(power_rule->max_eirp); |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1524 | } |
| 1525 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1526 | static void handle_band_custom(struct wiphy *wiphy, |
| 1527 | struct ieee80211_supported_band *sband, |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1528 | const struct ieee80211_regdomain *regd) |
| 1529 | { |
| 1530 | unsigned int i; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1531 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1532 | if (!sband) |
| 1533 | return; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1534 | |
| 1535 | for (i = 0; i < sband->n_channels; i++) |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1536 | handle_channel_custom(wiphy, &sband->channels[i], regd); |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | /* Used by drivers prior to wiphy registration */ |
| 1540 | void wiphy_apply_custom_regulatory(struct wiphy *wiphy, |
| 1541 | const struct ieee80211_regdomain *regd) |
| 1542 | { |
| 1543 | enum ieee80211_band band; |
Luis R. Rodriguez | bbcf3f0 | 2009-05-19 17:49:47 -0400 | [diff] [blame] | 1544 | unsigned int bands_set = 0; |
Luis R. Rodriguez | ac46d48 | 2009-05-01 18:44:50 -0400 | [diff] [blame] | 1545 | |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 1546 | WARN(!(wiphy->regulatory_flags & REGULATORY_CUSTOM_REG), |
| 1547 | "wiphy should have REGULATORY_CUSTOM_REG\n"); |
| 1548 | wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; |
Luis R. Rodriguez | 222ea58 | 2013-11-05 09:18:00 -0800 | [diff] [blame] | 1549 | |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1550 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
Luis R. Rodriguez | bbcf3f0 | 2009-05-19 17:49:47 -0400 | [diff] [blame] | 1551 | if (!wiphy->bands[band]) |
| 1552 | continue; |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1553 | handle_band_custom(wiphy, wiphy->bands[band], regd); |
Luis R. Rodriguez | bbcf3f0 | 2009-05-19 17:49:47 -0400 | [diff] [blame] | 1554 | bands_set++; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1555 | } |
Luis R. Rodriguez | bbcf3f0 | 2009-05-19 17:49:47 -0400 | [diff] [blame] | 1556 | |
| 1557 | /* |
| 1558 | * no point in calling this if it won't have any effect |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1559 | * on your device's supported bands. |
Luis R. Rodriguez | bbcf3f0 | 2009-05-19 17:49:47 -0400 | [diff] [blame] | 1560 | */ |
| 1561 | WARN_ON(!bands_set); |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1562 | } |
| 1563 | EXPORT_SYMBOL(wiphy_apply_custom_regulatory); |
| 1564 | |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 1565 | static void reg_set_request_processed(void) |
| 1566 | { |
| 1567 | bool need_more_processing = false; |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1568 | struct regulatory_request *lr = get_last_request(); |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 1569 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1570 | lr->processed = true; |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 1571 | |
| 1572 | spin_lock(®_requests_lock); |
| 1573 | if (!list_empty(®_requests_list)) |
| 1574 | need_more_processing = true; |
| 1575 | spin_unlock(®_requests_lock); |
| 1576 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1577 | if (lr->initiator == NL80211_REGDOM_SET_BY_USER) |
Eliad Peller | fe20b39 | 2012-06-12 12:53:13 +0300 | [diff] [blame] | 1578 | cancel_delayed_work(®_timeout); |
Luis R. Rodriguez | a90c7a3 | 2011-04-05 10:49:04 -0700 | [diff] [blame] | 1579 | |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 1580 | if (need_more_processing) |
| 1581 | schedule_work(®_work); |
| 1582 | } |
| 1583 | |
Luis R. Rodriguez | d1c96a9 | 2009-02-21 00:24:13 -0500 | [diff] [blame] | 1584 | /** |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 1585 | * reg_process_hint_core - process core regulatory requests |
| 1586 | * @pending_request: a pending core regulatory request |
| 1587 | * |
| 1588 | * The wireless subsystem can use this function to process |
| 1589 | * a regulatory request issued by the regulatory core. |
| 1590 | * |
| 1591 | * Returns one of the different reg request treatment values. |
| 1592 | */ |
| 1593 | static enum reg_request_treatment |
| 1594 | reg_process_hint_core(struct regulatory_request *core_request) |
| 1595 | { |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 1596 | |
| 1597 | core_request->intersect = false; |
| 1598 | core_request->processed = false; |
Luis R. Rodriguez | 5ad6ef5 | 2013-11-05 09:18:08 -0800 | [diff] [blame] | 1599 | |
Luis R. Rodriguez | 05f1a3e | 2013-11-05 09:18:09 -0800 | [diff] [blame] | 1600 | reg_update_last_request(core_request); |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 1601 | |
Luis R. Rodriguez | fe6631f | 2013-11-05 09:18:10 -0800 | [diff] [blame] | 1602 | return reg_call_crda(core_request); |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 1603 | } |
| 1604 | |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 1605 | static enum reg_request_treatment |
| 1606 | __reg_process_hint_user(struct regulatory_request *user_request) |
| 1607 | { |
| 1608 | struct regulatory_request *lr = get_last_request(); |
| 1609 | |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 1610 | if (reg_request_indoor(user_request)) { |
| 1611 | reg_is_indoor = true; |
| 1612 | return REG_REQ_USER_HINT_HANDLED; |
| 1613 | } |
| 1614 | |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 1615 | if (reg_request_cell_base(user_request)) |
| 1616 | return reg_ignore_cell_hint(user_request); |
| 1617 | |
| 1618 | if (reg_request_cell_base(lr)) |
| 1619 | return REG_REQ_IGNORE; |
| 1620 | |
| 1621 | if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) |
| 1622 | return REG_REQ_INTERSECT; |
| 1623 | /* |
| 1624 | * If the user knows better the user should set the regdom |
| 1625 | * to their country before the IE is picked up |
| 1626 | */ |
| 1627 | if (lr->initiator == NL80211_REGDOM_SET_BY_USER && |
| 1628 | lr->intersect) |
| 1629 | return REG_REQ_IGNORE; |
| 1630 | /* |
| 1631 | * Process user requests only after previous user/driver/core |
| 1632 | * requests have been processed |
| 1633 | */ |
| 1634 | if ((lr->initiator == NL80211_REGDOM_SET_BY_CORE || |
| 1635 | lr->initiator == NL80211_REGDOM_SET_BY_DRIVER || |
| 1636 | lr->initiator == NL80211_REGDOM_SET_BY_USER) && |
| 1637 | regdom_changes(lr->alpha2)) |
| 1638 | return REG_REQ_IGNORE; |
| 1639 | |
| 1640 | if (!regdom_changes(user_request->alpha2)) |
| 1641 | return REG_REQ_ALREADY_SET; |
| 1642 | |
| 1643 | return REG_REQ_OK; |
| 1644 | } |
| 1645 | |
| 1646 | /** |
| 1647 | * reg_process_hint_user - process user regulatory requests |
| 1648 | * @user_request: a pending user regulatory request |
| 1649 | * |
| 1650 | * The wireless subsystem can use this function to process |
| 1651 | * a regulatory request initiated by userspace. |
| 1652 | * |
| 1653 | * Returns one of the different reg request treatment values. |
| 1654 | */ |
| 1655 | static enum reg_request_treatment |
| 1656 | reg_process_hint_user(struct regulatory_request *user_request) |
| 1657 | { |
| 1658 | enum reg_request_treatment treatment; |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 1659 | |
| 1660 | treatment = __reg_process_hint_user(user_request); |
| 1661 | if (treatment == REG_REQ_IGNORE || |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 1662 | treatment == REG_REQ_ALREADY_SET || |
| 1663 | treatment == REG_REQ_USER_HINT_HANDLED) { |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 1664 | kfree(user_request); |
| 1665 | return treatment; |
| 1666 | } |
| 1667 | |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 1668 | user_request->intersect = treatment == REG_REQ_INTERSECT; |
| 1669 | user_request->processed = false; |
Luis R. Rodriguez | 5ad6ef5 | 2013-11-05 09:18:08 -0800 | [diff] [blame] | 1670 | |
Luis R. Rodriguez | 05f1a3e | 2013-11-05 09:18:09 -0800 | [diff] [blame] | 1671 | reg_update_last_request(user_request); |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 1672 | |
| 1673 | user_alpha2[0] = user_request->alpha2[0]; |
| 1674 | user_alpha2[1] = user_request->alpha2[1]; |
| 1675 | |
Luis R. Rodriguez | fe6631f | 2013-11-05 09:18:10 -0800 | [diff] [blame] | 1676 | return reg_call_crda(user_request); |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 1677 | } |
| 1678 | |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 1679 | static enum reg_request_treatment |
| 1680 | __reg_process_hint_driver(struct regulatory_request *driver_request) |
| 1681 | { |
| 1682 | struct regulatory_request *lr = get_last_request(); |
| 1683 | |
| 1684 | if (lr->initiator == NL80211_REGDOM_SET_BY_CORE) { |
| 1685 | if (regdom_changes(driver_request->alpha2)) |
| 1686 | return REG_REQ_OK; |
| 1687 | return REG_REQ_ALREADY_SET; |
| 1688 | } |
| 1689 | |
| 1690 | /* |
| 1691 | * This would happen if you unplug and plug your card |
| 1692 | * back in or if you add a new device for which the previously |
| 1693 | * loaded card also agrees on the regulatory domain. |
| 1694 | */ |
| 1695 | if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && |
| 1696 | !regdom_changes(driver_request->alpha2)) |
| 1697 | return REG_REQ_ALREADY_SET; |
| 1698 | |
| 1699 | return REG_REQ_INTERSECT; |
| 1700 | } |
| 1701 | |
| 1702 | /** |
| 1703 | * reg_process_hint_driver - process driver regulatory requests |
| 1704 | * @driver_request: a pending driver regulatory request |
| 1705 | * |
| 1706 | * The wireless subsystem can use this function to process |
| 1707 | * a regulatory request issued by an 802.11 driver. |
| 1708 | * |
| 1709 | * Returns one of the different reg request treatment values. |
| 1710 | */ |
| 1711 | static enum reg_request_treatment |
| 1712 | reg_process_hint_driver(struct wiphy *wiphy, |
| 1713 | struct regulatory_request *driver_request) |
| 1714 | { |
| 1715 | const struct ieee80211_regdomain *regd; |
| 1716 | enum reg_request_treatment treatment; |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 1717 | |
| 1718 | treatment = __reg_process_hint_driver(driver_request); |
| 1719 | |
| 1720 | switch (treatment) { |
| 1721 | case REG_REQ_OK: |
| 1722 | break; |
| 1723 | case REG_REQ_IGNORE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 1724 | case REG_REQ_USER_HINT_HANDLED: |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 1725 | kfree(driver_request); |
| 1726 | return treatment; |
| 1727 | case REG_REQ_INTERSECT: |
| 1728 | /* fall through */ |
| 1729 | case REG_REQ_ALREADY_SET: |
| 1730 | regd = reg_copy_regd(get_cfg80211_regdom()); |
| 1731 | if (IS_ERR(regd)) { |
| 1732 | kfree(driver_request); |
| 1733 | return REG_REQ_IGNORE; |
| 1734 | } |
| 1735 | rcu_assign_pointer(wiphy->regd, regd); |
| 1736 | } |
| 1737 | |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 1738 | |
| 1739 | driver_request->intersect = treatment == REG_REQ_INTERSECT; |
| 1740 | driver_request->processed = false; |
Luis R. Rodriguez | 5ad6ef5 | 2013-11-05 09:18:08 -0800 | [diff] [blame] | 1741 | |
Luis R. Rodriguez | 05f1a3e | 2013-11-05 09:18:09 -0800 | [diff] [blame] | 1742 | reg_update_last_request(driver_request); |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 1743 | |
| 1744 | /* |
| 1745 | * Since CRDA will not be called in this case as we already |
| 1746 | * have applied the requested regulatory domain before we just |
| 1747 | * inform userspace we have processed the request |
| 1748 | */ |
| 1749 | if (treatment == REG_REQ_ALREADY_SET) { |
| 1750 | nl80211_send_reg_change_event(driver_request); |
| 1751 | reg_set_request_processed(); |
| 1752 | return treatment; |
| 1753 | } |
| 1754 | |
Luis R. Rodriguez | fe6631f | 2013-11-05 09:18:10 -0800 | [diff] [blame] | 1755 | return reg_call_crda(driver_request); |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 1756 | } |
| 1757 | |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1758 | static enum reg_request_treatment |
| 1759 | __reg_process_hint_country_ie(struct wiphy *wiphy, |
| 1760 | struct regulatory_request *country_ie_request) |
| 1761 | { |
| 1762 | struct wiphy *last_wiphy = NULL; |
| 1763 | struct regulatory_request *lr = get_last_request(); |
| 1764 | |
| 1765 | if (reg_request_cell_base(lr)) { |
| 1766 | /* Trust a Cell base station over the AP's country IE */ |
| 1767 | if (regdom_changes(country_ie_request->alpha2)) |
| 1768 | return REG_REQ_IGNORE; |
| 1769 | return REG_REQ_ALREADY_SET; |
Luis R. Rodriguez | 2a90146 | 2013-11-11 22:15:31 +0100 | [diff] [blame] | 1770 | } else { |
| 1771 | if (wiphy->regulatory_flags & REGULATORY_COUNTRY_IE_IGNORE) |
| 1772 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1773 | } |
| 1774 | |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1775 | if (unlikely(!is_an_alpha2(country_ie_request->alpha2))) |
| 1776 | return -EINVAL; |
Luis R. Rodriguez | 2f1c6c5 | 2013-11-05 09:18:07 -0800 | [diff] [blame] | 1777 | |
| 1778 | if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) |
| 1779 | return REG_REQ_OK; |
| 1780 | |
| 1781 | last_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); |
| 1782 | |
| 1783 | if (last_wiphy != wiphy) { |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1784 | /* |
Luis R. Rodriguez | 2f1c6c5 | 2013-11-05 09:18:07 -0800 | [diff] [blame] | 1785 | * Two cards with two APs claiming different |
| 1786 | * Country IE alpha2s. We could |
| 1787 | * intersect them, but that seems unlikely |
| 1788 | * to be correct. Reject second one for now. |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1789 | */ |
Luis R. Rodriguez | 2f1c6c5 | 2013-11-05 09:18:07 -0800 | [diff] [blame] | 1790 | if (regdom_changes(country_ie_request->alpha2)) |
| 1791 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1792 | return REG_REQ_ALREADY_SET; |
| 1793 | } |
Luis R. Rodriguez | 2f1c6c5 | 2013-11-05 09:18:07 -0800 | [diff] [blame] | 1794 | /* |
| 1795 | * Two consecutive Country IE hints on the same wiphy. |
| 1796 | * This should be picked up early by the driver/stack |
| 1797 | */ |
| 1798 | if (WARN_ON(regdom_changes(country_ie_request->alpha2))) |
| 1799 | return REG_REQ_OK; |
| 1800 | return REG_REQ_ALREADY_SET; |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1801 | } |
| 1802 | |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 1803 | /** |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1804 | * reg_process_hint_country_ie - process regulatory requests from country IEs |
| 1805 | * @country_ie_request: a regulatory request from a country IE |
Luis R. Rodriguez | d1c96a9 | 2009-02-21 00:24:13 -0500 | [diff] [blame] | 1806 | * |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1807 | * The wireless subsystem can use this function to process |
| 1808 | * a regulatory request issued by a country Information Element. |
Luis R. Rodriguez | d1c96a9 | 2009-02-21 00:24:13 -0500 | [diff] [blame] | 1809 | * |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 1810 | * Returns one of the different reg request treatment values. |
Luis R. Rodriguez | d1c96a9 | 2009-02-21 00:24:13 -0500 | [diff] [blame] | 1811 | */ |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 1812 | static enum reg_request_treatment |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1813 | reg_process_hint_country_ie(struct wiphy *wiphy, |
| 1814 | struct regulatory_request *country_ie_request) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1815 | { |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 1816 | enum reg_request_treatment treatment; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1817 | |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1818 | treatment = __reg_process_hint_country_ie(wiphy, country_ie_request); |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 1819 | |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 1820 | switch (treatment) { |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 1821 | case REG_REQ_OK: |
| 1822 | break; |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1823 | case REG_REQ_IGNORE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 1824 | case REG_REQ_USER_HINT_HANDLED: |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1825 | /* fall through */ |
| 1826 | case REG_REQ_ALREADY_SET: |
| 1827 | kfree(country_ie_request); |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 1828 | return treatment; |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1829 | case REG_REQ_INTERSECT: |
| 1830 | kfree(country_ie_request); |
| 1831 | /* |
| 1832 | * This doesn't happen yet, not sure we |
| 1833 | * ever want to support it for this case. |
| 1834 | */ |
| 1835 | WARN_ONCE(1, "Unexpected intersection for country IEs"); |
| 1836 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1837 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1838 | |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1839 | country_ie_request->intersect = false; |
| 1840 | country_ie_request->processed = false; |
Luis R. Rodriguez | 5ad6ef5 | 2013-11-05 09:18:08 -0800 | [diff] [blame] | 1841 | |
Luis R. Rodriguez | 05f1a3e | 2013-11-05 09:18:09 -0800 | [diff] [blame] | 1842 | reg_update_last_request(country_ie_request); |
Luis R. Rodriguez | d951c1d | 2009-02-21 00:24:15 -0500 | [diff] [blame] | 1843 | |
Luis R. Rodriguez | fe6631f | 2013-11-05 09:18:10 -0800 | [diff] [blame] | 1844 | return reg_call_crda(country_ie_request); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
Luis R. Rodriguez | 30a548c | 2009-05-02 01:17:27 -0400 | [diff] [blame] | 1847 | /* This processes *all* regulatory hints */ |
Luis R. Rodriguez | 1daa37c | 2013-11-05 09:18:02 -0800 | [diff] [blame] | 1848 | static void reg_process_hint(struct regulatory_request *reg_request) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1849 | { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1850 | struct wiphy *wiphy = NULL; |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 1851 | enum reg_request_treatment treatment; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1852 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 1853 | if (reg_request->wiphy_idx != WIPHY_IDX_INVALID) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1854 | wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx); |
| 1855 | |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 1856 | switch (reg_request->initiator) { |
| 1857 | case NL80211_REGDOM_SET_BY_CORE: |
| 1858 | reg_process_hint_core(reg_request); |
| 1859 | return; |
| 1860 | case NL80211_REGDOM_SET_BY_USER: |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 1861 | treatment = reg_process_hint_user(reg_request); |
Inbal Hacohen | 50c11eb | 2014-02-12 09:32:27 +0200 | [diff] [blame] | 1862 | if (treatment == REG_REQ_IGNORE || |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 1863 | treatment == REG_REQ_ALREADY_SET) |
| 1864 | return; |
Shaibal Dutta | 845f335 | 2014-01-30 15:08:30 -0800 | [diff] [blame] | 1865 | queue_delayed_work(system_power_efficient_wq, |
| 1866 | ®_timeout, msecs_to_jiffies(3142)); |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 1867 | return; |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 1868 | case NL80211_REGDOM_SET_BY_DRIVER: |
Ilan Peer | 772f038 | 2014-01-14 15:17:23 +0200 | [diff] [blame] | 1869 | if (!wiphy) |
| 1870 | goto out_free; |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 1871 | treatment = reg_process_hint_driver(wiphy, reg_request); |
| 1872 | break; |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 1873 | case NL80211_REGDOM_SET_BY_COUNTRY_IE: |
Ilan Peer | 772f038 | 2014-01-14 15:17:23 +0200 | [diff] [blame] | 1874 | if (!wiphy) |
| 1875 | goto out_free; |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1876 | treatment = reg_process_hint_country_ie(wiphy, reg_request); |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 1877 | break; |
| 1878 | default: |
| 1879 | WARN(1, "invalid initiator %d\n", reg_request->initiator); |
Ilan Peer | 772f038 | 2014-01-14 15:17:23 +0200 | [diff] [blame] | 1880 | goto out_free; |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 1881 | } |
| 1882 | |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1883 | /* This is required so that the orig_* parameters are saved */ |
| 1884 | if (treatment == REG_REQ_ALREADY_SET && wiphy && |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 1885 | wiphy->regulatory_flags & REGULATORY_STRICT_REG) |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 1886 | wiphy_update_regulatory(wiphy, reg_request->initiator); |
Ilan Peer | 772f038 | 2014-01-14 15:17:23 +0200 | [diff] [blame] | 1887 | |
| 1888 | return; |
| 1889 | |
| 1890 | out_free: |
| 1891 | kfree(reg_request); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1892 | } |
| 1893 | |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 1894 | /* |
| 1895 | * Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_* |
| 1896 | * Regulatory hints come on a first come first serve basis and we |
| 1897 | * must process each one atomically. |
| 1898 | */ |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1899 | static void reg_process_pending_hints(void) |
Luis R. Rodriguez | b0e2880 | 2010-11-17 21:46:08 -0800 | [diff] [blame] | 1900 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1901 | struct regulatory_request *reg_request, *lr; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1902 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1903 | lr = get_last_request(); |
Luis R. Rodriguez | b0e2880 | 2010-11-17 21:46:08 -0800 | [diff] [blame] | 1904 | |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 1905 | /* When last_request->processed becomes true this will be rescheduled */ |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1906 | if (lr && !lr->processed) { |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1907 | REG_DBG_PRINT("Pending regulatory request, waiting for it to be processed...\n"); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1908 | return; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1909 | } |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 1910 | |
| 1911 | spin_lock(®_requests_lock); |
| 1912 | |
| 1913 | if (list_empty(®_requests_list)) { |
| 1914 | spin_unlock(®_requests_lock); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1915 | return; |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | reg_request = list_first_entry(®_requests_list, |
| 1919 | struct regulatory_request, |
| 1920 | list); |
| 1921 | list_del_init(®_request->list); |
| 1922 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1923 | spin_unlock(®_requests_lock); |
Luis R. Rodriguez | b0e2880 | 2010-11-17 21:46:08 -0800 | [diff] [blame] | 1924 | |
Luis R. Rodriguez | 1daa37c | 2013-11-05 09:18:02 -0800 | [diff] [blame] | 1925 | reg_process_hint(reg_request); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1926 | } |
| 1927 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1928 | /* Processes beacon hints -- this has nothing to do with country IEs */ |
| 1929 | static void reg_process_pending_beacon_hints(void) |
| 1930 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1931 | struct cfg80211_registered_device *rdev; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1932 | struct reg_beacon *pending_beacon, *tmp; |
| 1933 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1934 | /* This goes through the _pending_ beacon list */ |
| 1935 | spin_lock_bh(®_pending_beacons_lock); |
| 1936 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1937 | list_for_each_entry_safe(pending_beacon, tmp, |
| 1938 | ®_pending_beacons, list) { |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1939 | list_del_init(&pending_beacon->list); |
| 1940 | |
| 1941 | /* Applies the beacon hint to current wiphys */ |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1942 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) |
| 1943 | wiphy_update_new_beacon(&rdev->wiphy, pending_beacon); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1944 | |
| 1945 | /* Remembers the beacon hint for new wiphys or reg changes */ |
| 1946 | list_add_tail(&pending_beacon->list, ®_beacon_list); |
| 1947 | } |
| 1948 | |
| 1949 | spin_unlock_bh(®_pending_beacons_lock); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1950 | } |
| 1951 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1952 | static void reg_todo(struct work_struct *work) |
| 1953 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1954 | rtnl_lock(); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1955 | reg_process_pending_hints(); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 1956 | reg_process_pending_beacon_hints(); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1957 | rtnl_unlock(); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1958 | } |
| 1959 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1960 | static void queue_regulatory_request(struct regulatory_request *request) |
| 1961 | { |
Johannes Berg | d4f2c88 | 2012-12-03 18:59:58 +0100 | [diff] [blame] | 1962 | request->alpha2[0] = toupper(request->alpha2[0]); |
| 1963 | request->alpha2[1] = toupper(request->alpha2[1]); |
John W. Linville | c61029c | 2010-08-05 14:26:24 -0400 | [diff] [blame] | 1964 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1965 | spin_lock(®_requests_lock); |
| 1966 | list_add_tail(&request->list, ®_requests_list); |
| 1967 | spin_unlock(®_requests_lock); |
| 1968 | |
| 1969 | schedule_work(®_work); |
| 1970 | } |
| 1971 | |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 1972 | /* |
| 1973 | * Core regulatory hint -- happens during cfg80211_init() |
| 1974 | * and when we restore regulatory settings. |
| 1975 | */ |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 1976 | static int regulatory_hint_core(const char *alpha2) |
| 1977 | { |
| 1978 | struct regulatory_request *request; |
| 1979 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1980 | request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 1981 | if (!request) |
| 1982 | return -ENOMEM; |
| 1983 | |
| 1984 | request->alpha2[0] = alpha2[0]; |
| 1985 | request->alpha2[1] = alpha2[1]; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 1986 | request->initiator = NL80211_REGDOM_SET_BY_CORE; |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 1987 | |
Luis R. Rodriguez | 31e9972 | 2010-11-17 21:46:06 -0800 | [diff] [blame] | 1988 | queue_regulatory_request(request); |
Luis R. Rodriguez | 5078b2e | 2009-05-13 17:04:42 -0400 | [diff] [blame] | 1989 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1990 | return 0; |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 1991 | } |
| 1992 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1993 | /* User hints */ |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 1994 | int regulatory_hint_user(const char *alpha2, |
| 1995 | enum nl80211_user_reg_hint_type user_reg_hint_type) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1996 | { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 1997 | struct regulatory_request *request; |
| 1998 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 1999 | if (WARN_ON(!alpha2)) |
| 2000 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2001 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2002 | request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); |
| 2003 | if (!request) |
| 2004 | return -ENOMEM; |
| 2005 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 2006 | request->wiphy_idx = WIPHY_IDX_INVALID; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2007 | request->alpha2[0] = alpha2[0]; |
| 2008 | request->alpha2[1] = alpha2[1]; |
Luis R. Rodriguez | e12822e | 2010-01-04 11:37:39 -0500 | [diff] [blame] | 2009 | request->initiator = NL80211_REGDOM_SET_BY_USER; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2010 | request->user_reg_hint_type = user_reg_hint_type; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2011 | |
| 2012 | queue_regulatory_request(request); |
| 2013 | |
| 2014 | return 0; |
| 2015 | } |
| 2016 | |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 2017 | int regulatory_hint_indoor_user(void) |
| 2018 | { |
| 2019 | struct regulatory_request *request; |
| 2020 | |
| 2021 | request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); |
| 2022 | if (!request) |
| 2023 | return -ENOMEM; |
| 2024 | |
| 2025 | request->wiphy_idx = WIPHY_IDX_INVALID; |
| 2026 | request->initiator = NL80211_REGDOM_SET_BY_USER; |
| 2027 | request->user_reg_hint_type = NL80211_USER_REG_HINT_INDOOR; |
| 2028 | queue_regulatory_request(request); |
| 2029 | |
| 2030 | return 0; |
| 2031 | } |
| 2032 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2033 | /* Driver hints */ |
| 2034 | int regulatory_hint(struct wiphy *wiphy, const char *alpha2) |
| 2035 | { |
| 2036 | struct regulatory_request *request; |
| 2037 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2038 | if (WARN_ON(!alpha2 || !wiphy)) |
| 2039 | return -EINVAL; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2040 | |
Luis R. Rodriguez | 4f7b914 | 2013-12-14 20:09:06 +0100 | [diff] [blame] | 2041 | wiphy->regulatory_flags &= ~REGULATORY_CUSTOM_REG; |
| 2042 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2043 | request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); |
| 2044 | if (!request) |
| 2045 | return -ENOMEM; |
| 2046 | |
| 2047 | request->wiphy_idx = get_wiphy_idx(wiphy); |
| 2048 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2049 | request->alpha2[0] = alpha2[0]; |
| 2050 | request->alpha2[1] = alpha2[1]; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 2051 | request->initiator = NL80211_REGDOM_SET_BY_DRIVER; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2052 | |
| 2053 | queue_regulatory_request(request); |
| 2054 | |
| 2055 | return 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2056 | } |
| 2057 | EXPORT_SYMBOL(regulatory_hint); |
| 2058 | |
Luis R. Rodriguez | 789fd03 | 2013-10-04 18:07:24 -0700 | [diff] [blame] | 2059 | void regulatory_hint_country_ie(struct wiphy *wiphy, enum ieee80211_band band, |
| 2060 | const u8 *country_ie, u8 country_ie_len) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2061 | { |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2062 | char alpha2[2]; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2063 | enum environment_cap env = ENVIRON_ANY; |
Johannes Berg | db2424c | 2013-05-10 19:07:52 +0200 | [diff] [blame] | 2064 | struct regulatory_request *request = NULL, *lr; |
Luis R. Rodriguez | d335fe6 | 2009-02-21 00:04:27 -0500 | [diff] [blame] | 2065 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2066 | /* IE len must be evenly divisible by 2 */ |
| 2067 | if (country_ie_len & 0x01) |
Johannes Berg | db2424c | 2013-05-10 19:07:52 +0200 | [diff] [blame] | 2068 | return; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2069 | |
| 2070 | if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) |
Johannes Berg | db2424c | 2013-05-10 19:07:52 +0200 | [diff] [blame] | 2071 | return; |
| 2072 | |
| 2073 | request = kzalloc(sizeof(*request), GFP_KERNEL); |
| 2074 | if (!request) |
| 2075 | return; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2076 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2077 | alpha2[0] = country_ie[0]; |
| 2078 | alpha2[1] = country_ie[1]; |
| 2079 | |
| 2080 | if (country_ie[2] == 'I') |
| 2081 | env = ENVIRON_INDOOR; |
| 2082 | else if (country_ie[2] == 'O') |
| 2083 | env = ENVIRON_OUTDOOR; |
| 2084 | |
Johannes Berg | db2424c | 2013-05-10 19:07:52 +0200 | [diff] [blame] | 2085 | rcu_read_lock(); |
| 2086 | lr = get_last_request(); |
| 2087 | |
| 2088 | if (unlikely(!lr)) |
| 2089 | goto out; |
| 2090 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 2091 | /* |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 2092 | * We will run this only upon a successful connection on cfg80211. |
Luis R. Rodriguez | 4b44c8b | 2009-07-30 17:38:07 -0700 | [diff] [blame] | 2093 | * We leave conflict resolution to the workqueue, where can hold |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2094 | * the RTNL. |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 2095 | */ |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2096 | if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && |
| 2097 | lr->wiphy_idx != WIPHY_IDX_INVALID) |
Luis R. Rodriguez | 4b44c8b | 2009-07-30 17:38:07 -0700 | [diff] [blame] | 2098 | goto out; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2099 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2100 | request->wiphy_idx = get_wiphy_idx(wiphy); |
John W. Linville | 4f366c5 | 2010-07-15 14:57:33 -0400 | [diff] [blame] | 2101 | request->alpha2[0] = alpha2[0]; |
| 2102 | request->alpha2[1] = alpha2[1]; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 2103 | request->initiator = NL80211_REGDOM_SET_BY_COUNTRY_IE; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2104 | request->country_ie_env = env; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2105 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2106 | queue_regulatory_request(request); |
Johannes Berg | db2424c | 2013-05-10 19:07:52 +0200 | [diff] [blame] | 2107 | request = NULL; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2108 | out: |
Johannes Berg | db2424c | 2013-05-10 19:07:52 +0200 | [diff] [blame] | 2109 | kfree(request); |
| 2110 | rcu_read_unlock(); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2111 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2112 | |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2113 | static void restore_alpha2(char *alpha2, bool reset_user) |
| 2114 | { |
| 2115 | /* indicates there is no alpha2 to consider for restoration */ |
| 2116 | alpha2[0] = '9'; |
| 2117 | alpha2[1] = '7'; |
| 2118 | |
| 2119 | /* The user setting has precedence over the module parameter */ |
| 2120 | if (is_user_regdom_saved()) { |
| 2121 | /* Unless we're asked to ignore it and reset it */ |
| 2122 | if (reset_user) { |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2123 | REG_DBG_PRINT("Restoring regulatory settings including user preference\n"); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2124 | user_alpha2[0] = '9'; |
| 2125 | user_alpha2[1] = '7'; |
| 2126 | |
| 2127 | /* |
| 2128 | * If we're ignoring user settings, we still need to |
| 2129 | * check the module parameter to ensure we put things |
| 2130 | * back as they were for a full restore. |
| 2131 | */ |
| 2132 | if (!is_world_regdom(ieee80211_regdom)) { |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2133 | REG_DBG_PRINT("Keeping preference on module parameter ieee80211_regdom: %c%c\n", |
| 2134 | ieee80211_regdom[0], ieee80211_regdom[1]); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2135 | alpha2[0] = ieee80211_regdom[0]; |
| 2136 | alpha2[1] = ieee80211_regdom[1]; |
| 2137 | } |
| 2138 | } else { |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2139 | REG_DBG_PRINT("Restoring regulatory settings while preserving user preference for: %c%c\n", |
| 2140 | user_alpha2[0], user_alpha2[1]); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2141 | alpha2[0] = user_alpha2[0]; |
| 2142 | alpha2[1] = user_alpha2[1]; |
| 2143 | } |
| 2144 | } else if (!is_world_regdom(ieee80211_regdom)) { |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2145 | REG_DBG_PRINT("Keeping preference on module parameter ieee80211_regdom: %c%c\n", |
| 2146 | ieee80211_regdom[0], ieee80211_regdom[1]); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2147 | alpha2[0] = ieee80211_regdom[0]; |
| 2148 | alpha2[1] = ieee80211_regdom[1]; |
| 2149 | } else |
Luis R. Rodriguez | d91e41b | 2010-10-20 10:18:59 -0700 | [diff] [blame] | 2150 | REG_DBG_PRINT("Restoring regulatory settings\n"); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2151 | } |
| 2152 | |
Rajkumar Manoharan | 5ce543d | 2011-12-07 21:50:08 +0530 | [diff] [blame] | 2153 | static void restore_custom_reg_settings(struct wiphy *wiphy) |
| 2154 | { |
| 2155 | struct ieee80211_supported_band *sband; |
| 2156 | enum ieee80211_band band; |
| 2157 | struct ieee80211_channel *chan; |
| 2158 | int i; |
| 2159 | |
| 2160 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 2161 | sband = wiphy->bands[band]; |
| 2162 | if (!sband) |
| 2163 | continue; |
| 2164 | for (i = 0; i < sband->n_channels; i++) { |
| 2165 | chan = &sband->channels[i]; |
| 2166 | chan->flags = chan->orig_flags; |
| 2167 | chan->max_antenna_gain = chan->orig_mag; |
| 2168 | chan->max_power = chan->orig_mpwr; |
Paul Stewart | 899852a | 2012-08-01 16:54:42 -0700 | [diff] [blame] | 2169 | chan->beacon_found = false; |
Rajkumar Manoharan | 5ce543d | 2011-12-07 21:50:08 +0530 | [diff] [blame] | 2170 | } |
| 2171 | } |
| 2172 | } |
| 2173 | |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2174 | /* |
| 2175 | * Restoring regulatory settings involves ingoring any |
| 2176 | * possibly stale country IE information and user regulatory |
| 2177 | * settings if so desired, this includes any beacon hints |
| 2178 | * learned as we could have traveled outside to another country |
| 2179 | * after disconnection. To restore regulatory settings we do |
| 2180 | * exactly what we did at bootup: |
| 2181 | * |
| 2182 | * - send a core regulatory hint |
| 2183 | * - send a user regulatory hint if applicable |
| 2184 | * |
| 2185 | * Device drivers that send a regulatory hint for a specific country |
| 2186 | * keep their own regulatory domain on wiphy->regd so that does does |
| 2187 | * not need to be remembered. |
| 2188 | */ |
| 2189 | static void restore_regulatory_settings(bool reset_user) |
| 2190 | { |
| 2191 | char alpha2[2]; |
Dmitry Shmidt | cee0bec | 2011-12-19 12:32:21 -0800 | [diff] [blame] | 2192 | char world_alpha2[2]; |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2193 | struct reg_beacon *reg_beacon, *btmp; |
Luis R. Rodriguez | 1460955 | 2011-04-05 10:49:03 -0700 | [diff] [blame] | 2194 | struct regulatory_request *reg_request, *tmp; |
| 2195 | LIST_HEAD(tmp_reg_req_list); |
Rajkumar Manoharan | 5ce543d | 2011-12-07 21:50:08 +0530 | [diff] [blame] | 2196 | struct cfg80211_registered_device *rdev; |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2197 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2198 | ASSERT_RTNL(); |
| 2199 | |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 2200 | reg_is_indoor = false; |
| 2201 | |
Johannes Berg | 2d31986 | 2013-01-09 12:01:38 +0100 | [diff] [blame] | 2202 | reset_regdomains(true, &world_regdom); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2203 | restore_alpha2(alpha2, reset_user); |
| 2204 | |
Luis R. Rodriguez | 1460955 | 2011-04-05 10:49:03 -0700 | [diff] [blame] | 2205 | /* |
| 2206 | * If there's any pending requests we simply |
| 2207 | * stash them to a temporary pending queue and |
| 2208 | * add then after we've restored regulatory |
| 2209 | * settings. |
| 2210 | */ |
| 2211 | spin_lock(®_requests_lock); |
Johannes Berg | fea9bce | 2012-12-03 17:32:01 +0100 | [diff] [blame] | 2212 | list_for_each_entry_safe(reg_request, tmp, ®_requests_list, list) { |
| 2213 | if (reg_request->initiator != NL80211_REGDOM_SET_BY_USER) |
| 2214 | continue; |
| 2215 | list_move_tail(®_request->list, &tmp_reg_req_list); |
Luis R. Rodriguez | 1460955 | 2011-04-05 10:49:03 -0700 | [diff] [blame] | 2216 | } |
| 2217 | spin_unlock(®_requests_lock); |
| 2218 | |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2219 | /* Clear beacon hints */ |
| 2220 | spin_lock_bh(®_pending_beacons_lock); |
Johannes Berg | fea9bce | 2012-12-03 17:32:01 +0100 | [diff] [blame] | 2221 | list_for_each_entry_safe(reg_beacon, btmp, ®_pending_beacons, list) { |
| 2222 | list_del(®_beacon->list); |
| 2223 | kfree(reg_beacon); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2224 | } |
| 2225 | spin_unlock_bh(®_pending_beacons_lock); |
| 2226 | |
Johannes Berg | fea9bce | 2012-12-03 17:32:01 +0100 | [diff] [blame] | 2227 | list_for_each_entry_safe(reg_beacon, btmp, ®_beacon_list, list) { |
| 2228 | list_del(®_beacon->list); |
| 2229 | kfree(reg_beacon); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | /* First restore to the basic regulatory settings */ |
Johannes Berg | 379b82f | 2012-12-06 15:44:07 +0100 | [diff] [blame] | 2233 | world_alpha2[0] = cfg80211_world_regdom->alpha2[0]; |
| 2234 | world_alpha2[1] = cfg80211_world_regdom->alpha2[1]; |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2235 | |
Rajkumar Manoharan | 5ce543d | 2011-12-07 21:50:08 +0530 | [diff] [blame] | 2236 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 2237 | if (rdev->wiphy.regulatory_flags & REGULATORY_CUSTOM_REG) |
Rajkumar Manoharan | 5ce543d | 2011-12-07 21:50:08 +0530 | [diff] [blame] | 2238 | restore_custom_reg_settings(&rdev->wiphy); |
| 2239 | } |
| 2240 | |
Dmitry Shmidt | cee0bec | 2011-12-19 12:32:21 -0800 | [diff] [blame] | 2241 | regulatory_hint_core(world_alpha2); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2242 | |
| 2243 | /* |
| 2244 | * This restores the ieee80211_regdom module parameter |
| 2245 | * preference or the last user requested regulatory |
| 2246 | * settings, user regulatory settings takes precedence. |
| 2247 | */ |
| 2248 | if (is_an_alpha2(alpha2)) |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2249 | regulatory_hint_user(user_alpha2, NL80211_USER_REG_HINT_USER); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2250 | |
Luis R. Rodriguez | 1460955 | 2011-04-05 10:49:03 -0700 | [diff] [blame] | 2251 | spin_lock(®_requests_lock); |
Johannes Berg | 11cff96 | 2012-12-03 18:56:41 +0100 | [diff] [blame] | 2252 | list_splice_tail_init(&tmp_reg_req_list, ®_requests_list); |
Luis R. Rodriguez | 1460955 | 2011-04-05 10:49:03 -0700 | [diff] [blame] | 2253 | spin_unlock(®_requests_lock); |
| 2254 | |
Luis R. Rodriguez | 1460955 | 2011-04-05 10:49:03 -0700 | [diff] [blame] | 2255 | REG_DBG_PRINT("Kicking the queue\n"); |
| 2256 | |
| 2257 | schedule_work(®_work); |
| 2258 | } |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2259 | |
| 2260 | void regulatory_hint_disconnect(void) |
| 2261 | { |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2262 | REG_DBG_PRINT("All devices are disconnected, going to restore regulatory settings\n"); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2263 | restore_regulatory_settings(false); |
| 2264 | } |
| 2265 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2266 | static bool freq_is_chan_12_13_14(u16 freq) |
| 2267 | { |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 2268 | if (freq == ieee80211_channel_to_frequency(12, IEEE80211_BAND_2GHZ) || |
| 2269 | freq == ieee80211_channel_to_frequency(13, IEEE80211_BAND_2GHZ) || |
| 2270 | freq == ieee80211_channel_to_frequency(14, IEEE80211_BAND_2GHZ)) |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2271 | return true; |
| 2272 | return false; |
| 2273 | } |
| 2274 | |
Luis R. Rodriguez | 3ebfa6e | 2012-12-19 10:53:02 -0800 | [diff] [blame] | 2275 | static bool pending_reg_beacon(struct ieee80211_channel *beacon_chan) |
| 2276 | { |
| 2277 | struct reg_beacon *pending_beacon; |
| 2278 | |
| 2279 | list_for_each_entry(pending_beacon, ®_pending_beacons, list) |
| 2280 | if (beacon_chan->center_freq == |
| 2281 | pending_beacon->chan.center_freq) |
| 2282 | return true; |
| 2283 | return false; |
| 2284 | } |
| 2285 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2286 | int regulatory_hint_found_beacon(struct wiphy *wiphy, |
| 2287 | struct ieee80211_channel *beacon_chan, |
| 2288 | gfp_t gfp) |
| 2289 | { |
| 2290 | struct reg_beacon *reg_beacon; |
Luis R. Rodriguez | 3ebfa6e | 2012-12-19 10:53:02 -0800 | [diff] [blame] | 2291 | bool processing; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2292 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2293 | if (beacon_chan->beacon_found || |
| 2294 | beacon_chan->flags & IEEE80211_CHAN_RADAR || |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2295 | (beacon_chan->band == IEEE80211_BAND_2GHZ && |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2296 | !freq_is_chan_12_13_14(beacon_chan->center_freq))) |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2297 | return 0; |
| 2298 | |
Luis R. Rodriguez | 3ebfa6e | 2012-12-19 10:53:02 -0800 | [diff] [blame] | 2299 | spin_lock_bh(®_pending_beacons_lock); |
| 2300 | processing = pending_reg_beacon(beacon_chan); |
| 2301 | spin_unlock_bh(®_pending_beacons_lock); |
| 2302 | |
| 2303 | if (processing) |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2304 | return 0; |
| 2305 | |
| 2306 | reg_beacon = kzalloc(sizeof(struct reg_beacon), gfp); |
| 2307 | if (!reg_beacon) |
| 2308 | return -ENOMEM; |
| 2309 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2310 | REG_DBG_PRINT("Found new beacon on frequency: %d MHz (Ch %d) on %s\n", |
Luis R. Rodriguez | 4113f75 | 2010-01-04 11:50:11 -0500 | [diff] [blame] | 2311 | beacon_chan->center_freq, |
| 2312 | ieee80211_frequency_to_channel(beacon_chan->center_freq), |
| 2313 | wiphy_name(wiphy)); |
| 2314 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2315 | memcpy(®_beacon->chan, beacon_chan, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2316 | sizeof(struct ieee80211_channel)); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2317 | |
| 2318 | /* |
| 2319 | * Since we can be called from BH or and non-BH context |
| 2320 | * we must use spin_lock_bh() |
| 2321 | */ |
| 2322 | spin_lock_bh(®_pending_beacons_lock); |
| 2323 | list_add_tail(®_beacon->list, ®_pending_beacons); |
| 2324 | spin_unlock_bh(®_pending_beacons_lock); |
| 2325 | |
| 2326 | schedule_work(®_work); |
| 2327 | |
| 2328 | return 0; |
| 2329 | } |
| 2330 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 2331 | static void print_rd_rules(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2332 | { |
| 2333 | unsigned int i; |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 2334 | const struct ieee80211_reg_rule *reg_rule = NULL; |
| 2335 | const struct ieee80211_freq_range *freq_range = NULL; |
| 2336 | const struct ieee80211_power_rule *power_rule = NULL; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 2337 | char bw[32], cac_time[32]; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2338 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 2339 | pr_info(" (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp), (dfs_cac_time)\n"); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2340 | |
| 2341 | for (i = 0; i < rd->n_reg_rules; i++) { |
| 2342 | reg_rule = &rd->reg_rules[i]; |
| 2343 | freq_range = ®_rule->freq_range; |
| 2344 | power_rule = ®_rule->power_rule; |
| 2345 | |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 2346 | if (reg_rule->flags & NL80211_RRF_AUTO_BW) |
| 2347 | snprintf(bw, sizeof(bw), "%d KHz, %d KHz AUTO", |
| 2348 | freq_range->max_bandwidth_khz, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 2349 | reg_get_max_bandwidth(rd, reg_rule)); |
| 2350 | else |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 2351 | snprintf(bw, sizeof(bw), "%d KHz", |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 2352 | freq_range->max_bandwidth_khz); |
| 2353 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 2354 | if (reg_rule->flags & NL80211_RRF_DFS) |
| 2355 | scnprintf(cac_time, sizeof(cac_time), "%u s", |
| 2356 | reg_rule->dfs_cac_ms/1000); |
| 2357 | else |
| 2358 | scnprintf(cac_time, sizeof(cac_time), "N/A"); |
| 2359 | |
| 2360 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 2361 | /* |
| 2362 | * There may not be documentation for max antenna gain |
| 2363 | * in certain regions |
| 2364 | */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2365 | if (power_rule->max_antenna_gain) |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 2366 | pr_info(" (%d KHz - %d KHz @ %s), (%d mBi, %d mBm), (%s)\n", |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2367 | freq_range->start_freq_khz, |
| 2368 | freq_range->end_freq_khz, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 2369 | bw, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2370 | power_rule->max_antenna_gain, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 2371 | power_rule->max_eirp, |
| 2372 | cac_time); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2373 | else |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 2374 | pr_info(" (%d KHz - %d KHz @ %s), (N/A, %d mBm), (%s)\n", |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2375 | freq_range->start_freq_khz, |
| 2376 | freq_range->end_freq_khz, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 2377 | bw, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 2378 | power_rule->max_eirp, |
| 2379 | cac_time); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2380 | } |
| 2381 | } |
| 2382 | |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 2383 | bool reg_supported_dfs_region(enum nl80211_dfs_regions dfs_region) |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 2384 | { |
| 2385 | switch (dfs_region) { |
| 2386 | case NL80211_DFS_UNSET: |
| 2387 | case NL80211_DFS_FCC: |
| 2388 | case NL80211_DFS_ETSI: |
| 2389 | case NL80211_DFS_JP: |
| 2390 | return true; |
| 2391 | default: |
| 2392 | REG_DBG_PRINT("Ignoring uknown DFS master region: %d\n", |
| 2393 | dfs_region); |
| 2394 | return false; |
| 2395 | } |
| 2396 | } |
| 2397 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 2398 | static void print_regdomain(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2399 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2400 | struct regulatory_request *lr = get_last_request(); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2401 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2402 | if (is_intersected_alpha2(rd->alpha2)) { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2403 | if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2404 | struct cfg80211_registered_device *rdev; |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2405 | rdev = cfg80211_rdev_by_wiphy_idx(lr->wiphy_idx); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2406 | if (rdev) { |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 2407 | pr_info("Current regulatory domain updated by AP to: %c%c\n", |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2408 | rdev->country_ie_alpha2[0], |
| 2409 | rdev->country_ie_alpha2[1]); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2410 | } else |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 2411 | pr_info("Current regulatory domain intersected:\n"); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2412 | } else |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 2413 | pr_info("Current regulatory domain intersected:\n"); |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2414 | } else if (is_world_regdom(rd->alpha2)) { |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 2415 | pr_info("World regulatory domain updated:\n"); |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2416 | } else { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2417 | if (is_unknown_alpha2(rd->alpha2)) |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 2418 | pr_info("Regulatory domain changed to driver built-in settings (unknown country)\n"); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2419 | else { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2420 | if (reg_request_cell_base(lr)) |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2421 | pr_info("Regulatory domain changed to country: %c%c by Cell Station\n", |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2422 | rd->alpha2[0], rd->alpha2[1]); |
| 2423 | else |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2424 | pr_info("Regulatory domain changed to country: %c%c\n", |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2425 | rd->alpha2[0], rd->alpha2[1]); |
| 2426 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2427 | } |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2428 | |
Luis R. Rodriguez | 3ef121b | 2013-11-13 18:54:05 +0100 | [diff] [blame] | 2429 | pr_info(" DFS Master region: %s", reg_dfs_region_str(rd->dfs_region)); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2430 | print_rd_rules(rd); |
| 2431 | } |
| 2432 | |
Johannes Berg | 2df7816 | 2008-10-28 16:49:41 +0100 | [diff] [blame] | 2433 | static void print_regdomain_info(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2434 | { |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 2435 | 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] | 2436 | print_rd_rules(rd); |
| 2437 | } |
| 2438 | |
Luis R. Rodriguez | 3b9e5ac | 2013-11-05 09:18:14 -0800 | [diff] [blame] | 2439 | static int reg_set_rd_core(const struct ieee80211_regdomain *rd) |
| 2440 | { |
| 2441 | if (!is_world_regdom(rd->alpha2)) |
| 2442 | return -EINVAL; |
| 2443 | update_world_regdomain(rd); |
| 2444 | return 0; |
| 2445 | } |
| 2446 | |
Luis R. Rodriguez | 84721d4 | 2013-11-05 09:18:15 -0800 | [diff] [blame] | 2447 | static int reg_set_rd_user(const struct ieee80211_regdomain *rd, |
| 2448 | struct regulatory_request *user_request) |
| 2449 | { |
| 2450 | const struct ieee80211_regdomain *intersected_rd = NULL; |
| 2451 | |
Luis R. Rodriguez | 84721d4 | 2013-11-05 09:18:15 -0800 | [diff] [blame] | 2452 | if (!regdom_changes(rd->alpha2)) |
| 2453 | return -EALREADY; |
| 2454 | |
| 2455 | if (!is_valid_rd(rd)) { |
| 2456 | pr_err("Invalid regulatory domain detected:\n"); |
| 2457 | print_regdomain_info(rd); |
| 2458 | return -EINVAL; |
| 2459 | } |
| 2460 | |
| 2461 | if (!user_request->intersect) { |
| 2462 | reset_regdomains(false, rd); |
| 2463 | return 0; |
| 2464 | } |
| 2465 | |
| 2466 | intersected_rd = regdom_intersect(rd, get_cfg80211_regdom()); |
| 2467 | if (!intersected_rd) |
| 2468 | return -EINVAL; |
| 2469 | |
| 2470 | kfree(rd); |
| 2471 | rd = NULL; |
| 2472 | reset_regdomains(false, intersected_rd); |
| 2473 | |
| 2474 | return 0; |
| 2475 | } |
| 2476 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2477 | static int reg_set_rd_driver(const struct ieee80211_regdomain *rd, |
| 2478 | struct regulatory_request *driver_request) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2479 | { |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 2480 | const struct ieee80211_regdomain *regd; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 2481 | const struct ieee80211_regdomain *intersected_rd = NULL; |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2482 | const struct ieee80211_regdomain *tmp; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 2483 | struct wiphy *request_wiphy; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 2484 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2485 | if (is_world_regdom(rd->alpha2)) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2486 | return -EINVAL; |
| 2487 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2488 | if (!regdom_changes(rd->alpha2)) |
| 2489 | return -EALREADY; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2490 | |
Luis R. Rodriguez | 8375af3 | 2008-11-12 14:21:57 -0800 | [diff] [blame] | 2491 | if (!is_valid_rd(rd)) { |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 2492 | pr_err("Invalid regulatory domain detected:\n"); |
Luis R. Rodriguez | 8375af3 | 2008-11-12 14:21:57 -0800 | [diff] [blame] | 2493 | print_regdomain_info(rd); |
| 2494 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2495 | } |
| 2496 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2497 | request_wiphy = wiphy_idx_to_wiphy(driver_request->wiphy_idx); |
| 2498 | if (!request_wiphy) { |
Shaibal Dutta | 845f335 | 2014-01-30 15:08:30 -0800 | [diff] [blame] | 2499 | queue_delayed_work(system_power_efficient_wq, |
| 2500 | ®_timeout, 0); |
Johannes Berg | de3584b | 2011-11-21 10:44:00 +0100 | [diff] [blame] | 2501 | return -ENODEV; |
| 2502 | } |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 2503 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2504 | if (!driver_request->intersect) { |
Luis R. Rodriguez | 558f6d3 | 2009-06-08 18:54:37 -0700 | [diff] [blame] | 2505 | if (request_wiphy->regd) |
| 2506 | return -EALREADY; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 2507 | |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 2508 | regd = reg_copy_regd(rd); |
| 2509 | if (IS_ERR(regd)) |
| 2510 | return PTR_ERR(regd); |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 2511 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 2512 | rcu_assign_pointer(request_wiphy->regd, regd); |
Johannes Berg | 379b82f | 2012-12-06 15:44:07 +0100 | [diff] [blame] | 2513 | reset_regdomains(false, rd); |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 2514 | return 0; |
| 2515 | } |
| 2516 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2517 | intersected_rd = regdom_intersect(rd, get_cfg80211_regdom()); |
| 2518 | if (!intersected_rd) |
| 2519 | return -EINVAL; |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 2520 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2521 | /* |
| 2522 | * We can trash what CRDA provided now. |
| 2523 | * However if a driver requested this specific regulatory |
| 2524 | * domain we keep it for its private use |
| 2525 | */ |
| 2526 | tmp = get_wiphy_regdom(request_wiphy); |
| 2527 | rcu_assign_pointer(request_wiphy->regd, rd); |
| 2528 | rcu_free_regdom(tmp); |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 2529 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2530 | rd = NULL; |
Larry Finger | b7566fc | 2013-02-04 15:33:44 -0600 | [diff] [blame] | 2531 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2532 | reset_regdomains(false, intersected_rd); |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 2533 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2534 | return 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2535 | } |
| 2536 | |
Luis R. Rodriguez | 0199240 | 2013-11-05 09:18:17 -0800 | [diff] [blame] | 2537 | static int reg_set_rd_country_ie(const struct ieee80211_regdomain *rd, |
| 2538 | struct regulatory_request *country_ie_request) |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2539 | { |
| 2540 | struct wiphy *request_wiphy; |
| 2541 | |
| 2542 | if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) && |
| 2543 | !is_unknown_alpha2(rd->alpha2)) |
| 2544 | return -EINVAL; |
| 2545 | |
| 2546 | /* |
| 2547 | * Lets only bother proceeding on the same alpha2 if the current |
| 2548 | * rd is non static (it means CRDA was present and was used last) |
| 2549 | * and the pending request came in from a country IE |
| 2550 | */ |
| 2551 | |
| 2552 | if (!is_valid_rd(rd)) { |
| 2553 | pr_err("Invalid regulatory domain detected:\n"); |
| 2554 | print_regdomain_info(rd); |
| 2555 | return -EINVAL; |
| 2556 | } |
| 2557 | |
Luis R. Rodriguez | 0199240 | 2013-11-05 09:18:17 -0800 | [diff] [blame] | 2558 | request_wiphy = wiphy_idx_to_wiphy(country_ie_request->wiphy_idx); |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2559 | if (!request_wiphy) { |
Shaibal Dutta | 845f335 | 2014-01-30 15:08:30 -0800 | [diff] [blame] | 2560 | queue_delayed_work(system_power_efficient_wq, |
| 2561 | ®_timeout, 0); |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2562 | return -ENODEV; |
| 2563 | } |
| 2564 | |
Luis R. Rodriguez | 0199240 | 2013-11-05 09:18:17 -0800 | [diff] [blame] | 2565 | if (country_ie_request->intersect) |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2566 | return -EINVAL; |
| 2567 | |
| 2568 | reset_regdomains(false, rd); |
| 2569 | return 0; |
| 2570 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2571 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 2572 | /* |
| 2573 | * Use this call to set the current regulatory domain. Conflicts with |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2574 | * multiple drivers can be ironed out later. Caller must've already |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 2575 | * kmalloc'd the rd structure. |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 2576 | */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 2577 | int set_regdom(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2578 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2579 | struct regulatory_request *lr; |
Janusz Dziedzic | 092008a | 2014-02-14 08:54:00 +0100 | [diff] [blame] | 2580 | bool user_reset = false; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2581 | int r; |
| 2582 | |
Luis R. Rodriguez | 3b9e5ac | 2013-11-05 09:18:14 -0800 | [diff] [blame] | 2583 | if (!reg_is_valid_request(rd->alpha2)) { |
| 2584 | kfree(rd); |
| 2585 | return -EINVAL; |
| 2586 | } |
| 2587 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2588 | lr = get_last_request(); |
Luis R. Rodriguez | abc7381 | 2009-07-30 17:38:08 -0700 | [diff] [blame] | 2589 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2590 | /* Note that this doesn't update the wiphys, this is done below */ |
Luis R. Rodriguez | 3b9e5ac | 2013-11-05 09:18:14 -0800 | [diff] [blame] | 2591 | switch (lr->initiator) { |
| 2592 | case NL80211_REGDOM_SET_BY_CORE: |
| 2593 | r = reg_set_rd_core(rd); |
| 2594 | break; |
| 2595 | case NL80211_REGDOM_SET_BY_USER: |
Luis R. Rodriguez | 84721d4 | 2013-11-05 09:18:15 -0800 | [diff] [blame] | 2596 | r = reg_set_rd_user(rd, lr); |
Janusz Dziedzic | 092008a | 2014-02-14 08:54:00 +0100 | [diff] [blame] | 2597 | user_reset = true; |
Luis R. Rodriguez | 84721d4 | 2013-11-05 09:18:15 -0800 | [diff] [blame] | 2598 | break; |
Luis R. Rodriguez | 3b9e5ac | 2013-11-05 09:18:14 -0800 | [diff] [blame] | 2599 | case NL80211_REGDOM_SET_BY_DRIVER: |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 2600 | r = reg_set_rd_driver(rd, lr); |
| 2601 | break; |
Luis R. Rodriguez | 3b9e5ac | 2013-11-05 09:18:14 -0800 | [diff] [blame] | 2602 | case NL80211_REGDOM_SET_BY_COUNTRY_IE: |
Luis R. Rodriguez | 0199240 | 2013-11-05 09:18:17 -0800 | [diff] [blame] | 2603 | r = reg_set_rd_country_ie(rd, lr); |
Luis R. Rodriguez | 3b9e5ac | 2013-11-05 09:18:14 -0800 | [diff] [blame] | 2604 | break; |
| 2605 | default: |
| 2606 | WARN(1, "invalid initiator %d\n", lr->initiator); |
| 2607 | return -EINVAL; |
| 2608 | } |
| 2609 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 2610 | if (r) { |
Janusz Dziedzic | 092008a | 2014-02-14 08:54:00 +0100 | [diff] [blame] | 2611 | switch (r) { |
| 2612 | case -EALREADY: |
Kalle Valo | 9590853 | 2012-07-12 15:33:58 +0300 | [diff] [blame] | 2613 | reg_set_request_processed(); |
Janusz Dziedzic | 092008a | 2014-02-14 08:54:00 +0100 | [diff] [blame] | 2614 | break; |
| 2615 | default: |
| 2616 | /* Back to world regulatory in case of errors */ |
| 2617 | restore_regulatory_settings(user_reset); |
| 2618 | } |
Kalle Valo | 9590853 | 2012-07-12 15:33:58 +0300 | [diff] [blame] | 2619 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 2620 | kfree(rd); |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 2621 | return r; |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 2622 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2623 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2624 | /* This would make this whole thing pointless */ |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 2625 | if (WARN_ON(!lr->intersect && rd != get_cfg80211_regdom())) |
| 2626 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2627 | |
| 2628 | /* update all wiphys now with the new established regulatory domain */ |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2629 | update_all_wiphy_regulatory(lr->initiator); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2630 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 2631 | print_regdomain(get_cfg80211_regdom()); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2632 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2633 | nl80211_send_reg_change_event(lr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 2634 | |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 2635 | reg_set_request_processed(); |
| 2636 | |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 2637 | return 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2638 | } |
| 2639 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2640 | void wiphy_regulatory_register(struct wiphy *wiphy) |
| 2641 | { |
Arik Nemtsov | 23df0b7 | 2013-07-21 16:36:48 +0300 | [diff] [blame] | 2642 | struct regulatory_request *lr; |
| 2643 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2644 | if (!reg_dev_ignore_cell_hint(wiphy)) |
| 2645 | reg_num_devs_support_basehint++; |
| 2646 | |
Arik Nemtsov | 23df0b7 | 2013-07-21 16:36:48 +0300 | [diff] [blame] | 2647 | lr = get_last_request(); |
| 2648 | wiphy_update_regulatory(wiphy, lr->initiator); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2649 | } |
| 2650 | |
Luis R. Rodriguez | bfead08 | 2012-07-12 11:49:19 -0700 | [diff] [blame] | 2651 | void wiphy_regulatory_deregister(struct wiphy *wiphy) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2652 | { |
Luis R. Rodriguez | 0ad8aca | 2009-03-24 21:21:08 -0400 | [diff] [blame] | 2653 | struct wiphy *request_wiphy = NULL; |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2654 | struct regulatory_request *lr; |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 2655 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2656 | lr = get_last_request(); |
Luis R. Rodriguez | abc7381 | 2009-07-30 17:38:08 -0700 | [diff] [blame] | 2657 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2658 | if (!reg_dev_ignore_cell_hint(wiphy)) |
| 2659 | reg_num_devs_support_basehint--; |
| 2660 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 2661 | rcu_free_regdom(get_wiphy_regdom(wiphy)); |
Monam Agarwal | 34dd886 | 2014-03-24 00:53:40 +0530 | [diff] [blame] | 2662 | RCU_INIT_POINTER(wiphy->regd, NULL); |
Chris Wright | 0ef9ccd | 2009-04-24 14:09:31 -0700 | [diff] [blame] | 2663 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2664 | if (lr) |
| 2665 | request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 2666 | |
Chris Wright | 0ef9ccd | 2009-04-24 14:09:31 -0700 | [diff] [blame] | 2667 | if (!request_wiphy || request_wiphy != wiphy) |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 2668 | return; |
Chris Wright | 0ef9ccd | 2009-04-24 14:09:31 -0700 | [diff] [blame] | 2669 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2670 | lr->wiphy_idx = WIPHY_IDX_INVALID; |
| 2671 | lr->country_ie_env = ENVIRON_ANY; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2672 | } |
| 2673 | |
Luis R. Rodriguez | a90c7a3 | 2011-04-05 10:49:04 -0700 | [diff] [blame] | 2674 | static void reg_timeout_work(struct work_struct *work) |
| 2675 | { |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2676 | REG_DBG_PRINT("Timeout while waiting for CRDA to reply, restoring regulatory settings\n"); |
Johannes Berg | f77b86d | 2013-06-24 15:43:38 +0200 | [diff] [blame] | 2677 | rtnl_lock(); |
Luis R. Rodriguez | a90c7a3 | 2011-04-05 10:49:04 -0700 | [diff] [blame] | 2678 | restore_regulatory_settings(true); |
Johannes Berg | f77b86d | 2013-06-24 15:43:38 +0200 | [diff] [blame] | 2679 | rtnl_unlock(); |
Luis R. Rodriguez | a90c7a3 | 2011-04-05 10:49:04 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 2682 | /* |
| 2683 | * See http://www.fcc.gov/document/5-ghz-unlicensed-spectrum-unii, for |
| 2684 | * UNII band definitions |
| 2685 | */ |
| 2686 | int cfg80211_get_unii(int freq) |
| 2687 | { |
| 2688 | /* UNII-1 */ |
| 2689 | if (freq >= 5150 && freq <= 5250) |
| 2690 | return 0; |
| 2691 | |
| 2692 | /* UNII-2A */ |
| 2693 | if (freq > 5250 && freq <= 5350) |
| 2694 | return 1; |
| 2695 | |
| 2696 | /* UNII-2B */ |
| 2697 | if (freq > 5350 && freq <= 5470) |
| 2698 | return 2; |
| 2699 | |
| 2700 | /* UNII-2C */ |
| 2701 | if (freq > 5470 && freq <= 5725) |
| 2702 | return 3; |
| 2703 | |
| 2704 | /* UNII-3 */ |
| 2705 | if (freq > 5725 && freq <= 5825) |
| 2706 | return 4; |
| 2707 | |
| 2708 | return -EINVAL; |
| 2709 | } |
| 2710 | |
Ilan Peer | c8866e5 | 2014-02-23 09:13:03 +0200 | [diff] [blame] | 2711 | bool regulatory_indoor_allowed(void) |
| 2712 | { |
| 2713 | return reg_is_indoor; |
| 2714 | } |
| 2715 | |
Uwe Kleine-König | 2fcc9f7 | 2010-06-18 09:38:55 +0200 | [diff] [blame] | 2716 | int __init regulatory_init(void) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2717 | { |
Luis R. Rodriguez | bcf4f99 | 2009-02-21 00:04:24 -0500 | [diff] [blame] | 2718 | int err = 0; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2719 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2720 | reg_pdev = platform_device_register_simple("regulatory", 0, NULL, 0); |
| 2721 | if (IS_ERR(reg_pdev)) |
| 2722 | return PTR_ERR(reg_pdev); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2723 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2724 | spin_lock_init(®_requests_lock); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2725 | spin_lock_init(®_pending_beacons_lock); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2726 | |
Luis R. Rodriguez | 80007ef | 2012-03-23 07:23:31 -0700 | [diff] [blame] | 2727 | reg_regdb_size_check(); |
| 2728 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 2729 | rcu_assign_pointer(cfg80211_regdomain, cfg80211_world_regdom); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2730 | |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 2731 | user_alpha2[0] = '9'; |
| 2732 | user_alpha2[1] = '7'; |
| 2733 | |
Luis R. Rodriguez | ae9e4b0 | 2009-07-14 20:23:15 -0400 | [diff] [blame] | 2734 | /* We always try to get an update for the static regdomain */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 2735 | err = regulatory_hint_core(cfg80211_world_regdom->alpha2); |
Luis R. Rodriguez | bcf4f99 | 2009-02-21 00:04:24 -0500 | [diff] [blame] | 2736 | if (err) { |
| 2737 | if (err == -ENOMEM) |
| 2738 | return err; |
| 2739 | /* |
| 2740 | * N.B. kobject_uevent_env() can fail mainly for when we're out |
| 2741 | * memory which is handled and propagated appropriately above |
| 2742 | * but it can also fail during a netlink_broadcast() or during |
| 2743 | * early boot for call_usermodehelper(). For now treat these |
| 2744 | * errors as non-fatal. |
| 2745 | */ |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 2746 | 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] | 2747 | } |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2748 | |
Luis R. Rodriguez | ae9e4b0 | 2009-07-14 20:23:15 -0400 | [diff] [blame] | 2749 | /* |
| 2750 | * Finally, if the user set the module parameter treat it |
| 2751 | * as a user hint. |
| 2752 | */ |
| 2753 | if (!is_world_regdom(ieee80211_regdom)) |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2754 | regulatory_hint_user(ieee80211_regdom, |
| 2755 | NL80211_USER_REG_HINT_USER); |
Luis R. Rodriguez | ae9e4b0 | 2009-07-14 20:23:15 -0400 | [diff] [blame] | 2756 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2757 | return 0; |
| 2758 | } |
| 2759 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2760 | void regulatory_exit(void) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2761 | { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2762 | struct regulatory_request *reg_request, *tmp; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2763 | struct reg_beacon *reg_beacon, *btmp; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2764 | |
| 2765 | cancel_work_sync(®_work); |
Luis R. Rodriguez | a90c7a3 | 2011-04-05 10:49:04 -0700 | [diff] [blame] | 2766 | cancel_delayed_work_sync(®_timeout); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2767 | |
Johannes Berg | 9027b14 | 2012-12-03 17:59:24 +0100 | [diff] [blame] | 2768 | /* Lock to suppress warnings */ |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 2769 | rtnl_lock(); |
Johannes Berg | 379b82f | 2012-12-06 15:44:07 +0100 | [diff] [blame] | 2770 | reset_regdomains(true, NULL); |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 2771 | rtnl_unlock(); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2772 | |
Luis R. Rodriguez | 58ebacc | 2011-11-08 14:28:06 -0800 | [diff] [blame] | 2773 | dev_set_uevent_suppress(®_pdev->dev, true); |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 2774 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2775 | platform_device_unregister(reg_pdev); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 2776 | |
Johannes Berg | fea9bce | 2012-12-03 17:32:01 +0100 | [diff] [blame] | 2777 | list_for_each_entry_safe(reg_beacon, btmp, ®_pending_beacons, list) { |
| 2778 | list_del(®_beacon->list); |
| 2779 | kfree(reg_beacon); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2780 | } |
| 2781 | |
Johannes Berg | fea9bce | 2012-12-03 17:32:01 +0100 | [diff] [blame] | 2782 | list_for_each_entry_safe(reg_beacon, btmp, ®_beacon_list, list) { |
| 2783 | list_del(®_beacon->list); |
| 2784 | kfree(reg_beacon); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2785 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2786 | |
Johannes Berg | fea9bce | 2012-12-03 17:32:01 +0100 | [diff] [blame] | 2787 | list_for_each_entry_safe(reg_request, tmp, ®_requests_list, list) { |
| 2788 | list_del(®_request->list); |
| 2789 | kfree(reg_request); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2790 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2791 | } |