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