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 |
Emmanuel Grumbach | 4e0854a | 2017-09-06 13:45:40 +0300 | [diff] [blame] | 7 | * Copyright 2017 Intel Deutschland GmbH |
Ilan Peer | 51d62f2 | 2021-01-05 16:56:57 +0200 | [diff] [blame] | 8 | * Copyright (C) 2018 - 2021 Intel Corporation |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 9 | * |
Luis R. Rodriguez | 3b77d5e | 2011-12-20 12:23:38 -0800 | [diff] [blame] | 10 | * Permission to use, copy, modify, and/or distribute this software for any |
| 11 | * purpose with or without fee is hereby granted, provided that the above |
| 12 | * copyright notice and this permission notice appear in all copies. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 15 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 16 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 17 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 18 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 19 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 20 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 21 | */ |
| 22 | |
Luis R. Rodriguez | 3b77d5e | 2011-12-20 12:23:38 -0800 | [diff] [blame] | 23 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 24 | /** |
| 25 | * DOC: Wireless regulatory infrastructure |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 26 | * |
| 27 | * The usual implementation is for a driver to read a device EEPROM to |
| 28 | * determine which regulatory domain it should be operating under, then |
| 29 | * looking up the allowable channels in a driver-local table and finally |
| 30 | * registering those channels in the wiphy structure. |
| 31 | * |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 32 | * Another set of compliance enforcement is for drivers to use their |
| 33 | * own compliance limits which can be stored on the EEPROM. The host |
| 34 | * driver or firmware may ensure these are used. |
| 35 | * |
| 36 | * In addition to all this we provide an extra layer of regulatory |
| 37 | * conformance. For drivers which do not have any regulatory |
| 38 | * information CRDA provides the complete regulatory solution. |
| 39 | * For others it provides a community effort on further restrictions |
| 40 | * to enhance compliance. |
| 41 | * |
| 42 | * Note: When number of rules --> infinity we will not be able to |
| 43 | * index on alpha2 any more, instead we'll probably have to |
| 44 | * rely on some SHA1 checksum of the regdomain for example. |
| 45 | * |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 46 | */ |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 47 | |
| 48 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 49 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 50 | #include <linux/kernel.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 51 | #include <linux/export.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 52 | #include <linux/slab.h> |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 53 | #include <linux/list.h> |
John W. Linville | c61029c | 2010-08-05 14:26:24 -0400 | [diff] [blame] | 54 | #include <linux/ctype.h> |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 55 | #include <linux/nl80211.h> |
| 56 | #include <linux/platform_device.h> |
Johannes Berg | 90a53e4 | 2017-09-13 22:21:08 +0200 | [diff] [blame] | 57 | #include <linux/verification.h> |
Paul Gortmaker | d9b9384 | 2011-09-18 13:21:27 -0400 | [diff] [blame] | 58 | #include <linux/moduleparam.h> |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 59 | #include <linux/firmware.h> |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 60 | #include <net/cfg80211.h> |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 61 | #include "core.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 62 | #include "reg.h" |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 63 | #include "rdev-ops.h" |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 64 | #include "nl80211.h" |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 65 | |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 66 | /* |
| 67 | * Grace period we give before making sure all current interfaces reside on |
| 68 | * channels allowed by the current regulatory domain. |
| 69 | */ |
| 70 | #define REG_ENFORCE_GRACE_MS 60000 |
| 71 | |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 72 | /** |
| 73 | * enum reg_request_treatment - regulatory request treatment |
| 74 | * |
| 75 | * @REG_REQ_OK: continue processing the regulatory request |
| 76 | * @REG_REQ_IGNORE: ignore the regulatory request |
| 77 | * @REG_REQ_INTERSECT: the regulatory domain resulting from this request should |
| 78 | * be intersected with the current one. |
| 79 | * @REG_REQ_ALREADY_SET: the regulatory request will not change the current |
| 80 | * regulatory settings, and no further processing is required. |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 81 | */ |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 82 | enum reg_request_treatment { |
| 83 | REG_REQ_OK, |
| 84 | REG_REQ_IGNORE, |
| 85 | REG_REQ_INTERSECT, |
| 86 | REG_REQ_ALREADY_SET, |
| 87 | }; |
| 88 | |
Luis R. Rodriguez | a042994 | 2011-11-28 16:47:15 -0500 | [diff] [blame] | 89 | static struct regulatory_request core_request_world = { |
| 90 | .initiator = NL80211_REGDOM_SET_BY_CORE, |
| 91 | .alpha2[0] = '0', |
| 92 | .alpha2[1] = '0', |
| 93 | .intersect = false, |
| 94 | .processed = true, |
| 95 | .country_ie_env = ENVIRON_ANY, |
| 96 | }; |
| 97 | |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 98 | /* |
| 99 | * Receipt of information from last regulatory request, |
| 100 | * protected by RTNL (and can be accessed with RCU protection) |
| 101 | */ |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 102 | static struct regulatory_request __rcu *last_request = |
Johannes Berg | cec3f0e | 2014-12-12 12:26:25 +0100 | [diff] [blame] | 103 | (void __force __rcu *)&core_request_world; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 104 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 105 | /* To trigger userspace events and load firmware */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 106 | static struct platform_device *reg_pdev; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 107 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 108 | /* |
| 109 | * Central wireless core regulatory domains, we only need two, |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 110 | * 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] | 111 | * information to give us an alpha2. |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 112 | * (protected by RTNL, can be read under RCU) |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 113 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 114 | const struct ieee80211_regdomain __rcu *cfg80211_regdomain; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 115 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 116 | /* |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 117 | * Number of devices that registered to the core |
| 118 | * that support cellular base station regulatory hints |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 119 | * (protected by RTNL) |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 120 | */ |
| 121 | static int reg_num_devs_support_basehint; |
| 122 | |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 123 | /* |
| 124 | * State variable indicating if the platform on which the devices |
| 125 | * are attached is operating in an indoor environment. The state variable |
| 126 | * is relevant for all registered devices. |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 127 | */ |
| 128 | static bool reg_is_indoor; |
Qiheng Lin | 81d94f4 | 2021-03-25 22:38:54 +0800 | [diff] [blame] | 129 | static DEFINE_SPINLOCK(reg_indoor_lock); |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 130 | |
| 131 | /* Used to track the userspace process controlling the indoor setting */ |
| 132 | static u32 reg_is_indoor_portid; |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 133 | |
Johannes Berg | e646a02 | 2019-02-05 21:08:29 +0100 | [diff] [blame] | 134 | static void restore_regulatory_settings(bool reset_user, bool cached); |
| 135 | static void print_regdomain(const struct ieee80211_regdomain *rd); |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 136 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 137 | static const struct ieee80211_regdomain *get_cfg80211_regdom(void) |
| 138 | { |
Johannes Berg | 5bf16a1 | 2018-02-27 11:22:15 +0100 | [diff] [blame] | 139 | return rcu_dereference_rtnl(cfg80211_regdomain); |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Ilan Peer | 51d62f2 | 2021-01-05 16:56:57 +0200 | [diff] [blame] | 142 | /* |
| 143 | * Returns the regulatory domain associated with the wiphy. |
| 144 | * |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 145 | * Requires any of RTNL, wiphy mutex or RCU protection. |
Ilan Peer | 51d62f2 | 2021-01-05 16:56:57 +0200 | [diff] [blame] | 146 | */ |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 147 | const struct ieee80211_regdomain *get_wiphy_regdom(struct wiphy *wiphy) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 148 | { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 149 | return rcu_dereference_check(wiphy->regd, |
| 150 | lockdep_is_held(&wiphy->mtx) || |
| 151 | lockdep_rtnl_is_held()); |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 152 | } |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 153 | EXPORT_SYMBOL(get_wiphy_regdom); |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 154 | |
Luis R. Rodriguez | 3ef121b | 2013-11-13 18:54:05 +0100 | [diff] [blame] | 155 | static const char *reg_dfs_region_str(enum nl80211_dfs_regions dfs_region) |
| 156 | { |
| 157 | switch (dfs_region) { |
| 158 | case NL80211_DFS_UNSET: |
| 159 | return "unset"; |
| 160 | case NL80211_DFS_FCC: |
| 161 | return "FCC"; |
| 162 | case NL80211_DFS_ETSI: |
| 163 | return "ETSI"; |
| 164 | case NL80211_DFS_JP: |
| 165 | return "JP"; |
| 166 | } |
| 167 | return "Unknown"; |
| 168 | } |
| 169 | |
Luis R. Rodriguez | 6c47479 | 2013-11-25 20:56:09 +0100 | [diff] [blame] | 170 | enum nl80211_dfs_regions reg_get_dfs_region(struct wiphy *wiphy) |
| 171 | { |
| 172 | const struct ieee80211_regdomain *regd = NULL; |
| 173 | const struct ieee80211_regdomain *wiphy_regd = NULL; |
Sriram R | 90bd5be | 2021-08-26 05:08:50 +0530 | [diff] [blame] | 174 | enum nl80211_dfs_regions dfs_region; |
Luis R. Rodriguez | 6c47479 | 2013-11-25 20:56:09 +0100 | [diff] [blame] | 175 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 176 | rcu_read_lock(); |
Luis R. Rodriguez | 6c47479 | 2013-11-25 20:56:09 +0100 | [diff] [blame] | 177 | regd = get_cfg80211_regdom(); |
Sriram R | 90bd5be | 2021-08-26 05:08:50 +0530 | [diff] [blame] | 178 | dfs_region = regd->dfs_region; |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 179 | |
Luis R. Rodriguez | 6c47479 | 2013-11-25 20:56:09 +0100 | [diff] [blame] | 180 | if (!wiphy) |
| 181 | goto out; |
| 182 | |
| 183 | wiphy_regd = get_wiphy_regdom(wiphy); |
| 184 | if (!wiphy_regd) |
| 185 | goto out; |
| 186 | |
Sriram R | 90bd5be | 2021-08-26 05:08:50 +0530 | [diff] [blame] | 187 | if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { |
| 188 | dfs_region = wiphy_regd->dfs_region; |
| 189 | goto out; |
| 190 | } |
| 191 | |
Luis R. Rodriguez | 6c47479 | 2013-11-25 20:56:09 +0100 | [diff] [blame] | 192 | if (wiphy_regd->dfs_region == regd->dfs_region) |
| 193 | goto out; |
| 194 | |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 195 | pr_debug("%s: device specific dfs_region (%s) disagrees with cfg80211's central dfs_region (%s)\n", |
| 196 | dev_name(&wiphy->dev), |
| 197 | reg_dfs_region_str(wiphy_regd->dfs_region), |
| 198 | reg_dfs_region_str(regd->dfs_region)); |
Luis R. Rodriguez | 6c47479 | 2013-11-25 20:56:09 +0100 | [diff] [blame] | 199 | |
| 200 | out: |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 201 | rcu_read_unlock(); |
| 202 | |
Sriram R | 90bd5be | 2021-08-26 05:08:50 +0530 | [diff] [blame] | 203 | return dfs_region; |
Luis R. Rodriguez | 6c47479 | 2013-11-25 20:56:09 +0100 | [diff] [blame] | 204 | } |
| 205 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 206 | static void rcu_free_regdom(const struct ieee80211_regdomain *r) |
| 207 | { |
| 208 | if (!r) |
| 209 | return; |
| 210 | kfree_rcu((struct ieee80211_regdomain *)r, rcu_head); |
| 211 | } |
| 212 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 213 | static struct regulatory_request *get_last_request(void) |
| 214 | { |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 215 | return rcu_dereference_rtnl(last_request); |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 216 | } |
| 217 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 218 | /* Used to queue up regulatory hints */ |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 219 | static LIST_HEAD(reg_requests_list); |
Qiheng Lin | 81d94f4 | 2021-03-25 22:38:54 +0800 | [diff] [blame] | 220 | static DEFINE_SPINLOCK(reg_requests_lock); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 221 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 222 | /* Used to queue up beacon hints for review */ |
| 223 | static LIST_HEAD(reg_pending_beacons); |
Qiheng Lin | 81d94f4 | 2021-03-25 22:38:54 +0800 | [diff] [blame] | 224 | static DEFINE_SPINLOCK(reg_pending_beacons_lock); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 225 | |
| 226 | /* Used to keep track of processed beacon hints */ |
| 227 | static LIST_HEAD(reg_beacon_list); |
| 228 | |
| 229 | struct reg_beacon { |
| 230 | struct list_head list; |
| 231 | struct ieee80211_channel chan; |
| 232 | }; |
| 233 | |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 234 | static void reg_check_chans_work(struct work_struct *work); |
| 235 | static DECLARE_DELAYED_WORK(reg_check_chans, reg_check_chans_work); |
| 236 | |
Luis R. Rodriguez | f333a7a | 2010-11-17 21:46:07 -0800 | [diff] [blame] | 237 | static void reg_todo(struct work_struct *work); |
| 238 | static DECLARE_WORK(reg_work, reg_todo); |
| 239 | |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 240 | /* We keep a static world regulatory domain in case of the absence of CRDA */ |
| 241 | static const struct ieee80211_regdomain world_regdom = { |
Jason Abele | 28981e5 | 2015-02-17 16:10:41 -0800 | [diff] [blame] | 242 | .n_reg_rules = 8, |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 243 | .alpha2 = "00", |
| 244 | .reg_rules = { |
Luis R. Rodriguez | 68798a6 | 2009-02-21 00:20:37 -0500 | [diff] [blame] | 245 | /* IEEE 802.11b/g, channels 1..11 */ |
| 246 | REG_RULE(2412-10, 2462+10, 40, 6, 20, 0), |
Johannes Berg | 43c771a | 2012-11-12 10:51:34 +0100 | [diff] [blame] | 247 | /* IEEE 802.11b/g, channels 12..13. */ |
Johannes Berg | c382680 | 2015-12-11 17:35:50 +0100 | [diff] [blame] | 248 | REG_RULE(2467-10, 2472+10, 20, 6, 20, |
| 249 | NL80211_RRF_NO_IR | NL80211_RRF_AUTO_BW), |
Luis R. Rodriguez | 611b6a8 | 2009-03-05 21:19:21 -0800 | [diff] [blame] | 250 | /* IEEE 802.11 channel 14 - Only JP enables |
| 251 | * this and for 802.11b only */ |
| 252 | REG_RULE(2484-10, 2484+10, 20, 6, 20, |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 253 | NL80211_RRF_NO_IR | |
Luis R. Rodriguez | 611b6a8 | 2009-03-05 21:19:21 -0800 | [diff] [blame] | 254 | NL80211_RRF_NO_OFDM), |
| 255 | /* IEEE 802.11a, channel 36..48 */ |
Johannes Berg | c382680 | 2015-12-11 17:35:50 +0100 | [diff] [blame] | 256 | REG_RULE(5180-10, 5240+10, 80, 6, 20, |
| 257 | NL80211_RRF_NO_IR | |
| 258 | NL80211_RRF_AUTO_BW), |
Luis R. Rodriguez | 3fc71f7 | 2009-02-21 00:20:38 -0500 | [diff] [blame] | 259 | |
Johannes Berg | 131a19b | 2013-03-04 20:54:46 +0100 | [diff] [blame] | 260 | /* IEEE 802.11a, channel 52..64 - DFS required */ |
Johannes Berg | c382680 | 2015-12-11 17:35:50 +0100 | [diff] [blame] | 261 | REG_RULE(5260-10, 5320+10, 80, 6, 20, |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 262 | NL80211_RRF_NO_IR | |
Johannes Berg | c382680 | 2015-12-11 17:35:50 +0100 | [diff] [blame] | 263 | NL80211_RRF_AUTO_BW | |
Johannes Berg | 131a19b | 2013-03-04 20:54:46 +0100 | [diff] [blame] | 264 | NL80211_RRF_DFS), |
| 265 | |
| 266 | /* IEEE 802.11a, channel 100..144 - DFS required */ |
| 267 | REG_RULE(5500-10, 5720+10, 160, 6, 20, |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 268 | NL80211_RRF_NO_IR | |
Johannes Berg | 131a19b | 2013-03-04 20:54:46 +0100 | [diff] [blame] | 269 | NL80211_RRF_DFS), |
Luis R. Rodriguez | 3fc71f7 | 2009-02-21 00:20:38 -0500 | [diff] [blame] | 270 | |
| 271 | /* IEEE 802.11a, channel 149..165 */ |
Johannes Berg | 8ab9d85 | 2012-12-03 22:09:22 +0100 | [diff] [blame] | 272 | REG_RULE(5745-10, 5825+10, 80, 6, 20, |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 273 | NL80211_RRF_NO_IR), |
Vladimir Kondratiev | 90cdc6d | 2012-07-02 09:32:34 +0300 | [diff] [blame] | 274 | |
Johannes Berg | 8047d26 | 2015-10-15 16:16:09 +0200 | [diff] [blame] | 275 | /* IEEE 802.11ad (60GHz), channels 1..3 */ |
Vladimir Kondratiev | 90cdc6d | 2012-07-02 09:32:34 +0300 | [diff] [blame] | 276 | 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] | 277 | } |
| 278 | }; |
| 279 | |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 280 | /* protected by RTNL */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 281 | static const struct ieee80211_regdomain *cfg80211_world_regdom = |
| 282 | &world_regdom; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 283 | |
Luis R. Rodriguez | 6ee7d33 | 2009-03-20 23:53:06 -0400 | [diff] [blame] | 284 | static char *ieee80211_regdom = "00"; |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 285 | static char user_alpha2[2]; |
Johannes Berg | e646a02 | 2019-02-05 21:08:29 +0100 | [diff] [blame] | 286 | static const struct ieee80211_regdomain *cfg80211_user_regdom; |
Luis R. Rodriguez | 6ee7d33 | 2009-03-20 23:53:06 -0400 | [diff] [blame] | 287 | |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 288 | module_param(ieee80211_regdom, charp, 0444); |
| 289 | MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code"); |
| 290 | |
Arik Nemtsov | c888393 | 2014-04-21 20:39:34 -0700 | [diff] [blame] | 291 | static void reg_free_request(struct regulatory_request *request) |
Luis R. Rodriguez | 5ad6ef5 | 2013-11-05 09:18:08 -0800 | [diff] [blame] | 292 | { |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 293 | if (request == &core_request_world) |
| 294 | return; |
| 295 | |
Arik Nemtsov | c888393 | 2014-04-21 20:39:34 -0700 | [diff] [blame] | 296 | if (request != get_last_request()) |
| 297 | kfree(request); |
| 298 | } |
| 299 | |
| 300 | static void reg_free_last_request(void) |
| 301 | { |
| 302 | struct regulatory_request *lr = get_last_request(); |
| 303 | |
Luis R. Rodriguez | 5ad6ef5 | 2013-11-05 09:18:08 -0800 | [diff] [blame] | 304 | if (lr != &core_request_world && lr) |
| 305 | kfree_rcu(lr, rcu_head); |
| 306 | } |
| 307 | |
Luis R. Rodriguez | 05f1a3e | 2013-11-05 09:18:09 -0800 | [diff] [blame] | 308 | static void reg_update_last_request(struct regulatory_request *request) |
| 309 | { |
Luis R. Rodriguez | 255e25b | 2014-02-25 17:09:40 -0800 | [diff] [blame] | 310 | struct regulatory_request *lr; |
| 311 | |
| 312 | lr = get_last_request(); |
| 313 | if (lr == request) |
| 314 | return; |
| 315 | |
Arik Nemtsov | c888393 | 2014-04-21 20:39:34 -0700 | [diff] [blame] | 316 | reg_free_last_request(); |
Luis R. Rodriguez | 05f1a3e | 2013-11-05 09:18:09 -0800 | [diff] [blame] | 317 | rcu_assign_pointer(last_request, request); |
| 318 | } |
| 319 | |
Johannes Berg | 379b82f | 2012-12-06 15:44:07 +0100 | [diff] [blame] | 320 | static void reset_regdomains(bool full_reset, |
| 321 | const struct ieee80211_regdomain *new_regdom) |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 322 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 323 | const struct ieee80211_regdomain *r; |
| 324 | |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 325 | ASSERT_RTNL(); |
Johannes Berg | e8da2bb | 2012-12-03 23:00:08 +0100 | [diff] [blame] | 326 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 327 | r = get_cfg80211_regdom(); |
| 328 | |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 329 | /* avoid freeing static information or freeing something twice */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 330 | if (r == cfg80211_world_regdom) |
| 331 | r = NULL; |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 332 | if (cfg80211_world_regdom == &world_regdom) |
| 333 | cfg80211_world_regdom = NULL; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 334 | if (r == &world_regdom) |
| 335 | r = NULL; |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 336 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 337 | rcu_free_regdom(r); |
| 338 | rcu_free_regdom(cfg80211_world_regdom); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 339 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 340 | cfg80211_world_regdom = &world_regdom; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 341 | rcu_assign_pointer(cfg80211_regdomain, new_regdom); |
Luis R. Rodriguez | a042994 | 2011-11-28 16:47:15 -0500 | [diff] [blame] | 342 | |
| 343 | if (!full_reset) |
| 344 | return; |
| 345 | |
Luis R. Rodriguez | 05f1a3e | 2013-11-05 09:18:09 -0800 | [diff] [blame] | 346 | reg_update_last_request(&core_request_world); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 347 | } |
| 348 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 349 | /* |
| 350 | * Dynamic world regulatory domain requested by the wireless |
| 351 | * core upon initialization |
| 352 | */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 353 | static void update_world_regdomain(const struct ieee80211_regdomain *rd) |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 354 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 355 | struct regulatory_request *lr; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 356 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 357 | lr = get_last_request(); |
| 358 | |
| 359 | WARN_ON(!lr); |
Johannes Berg | e8da2bb | 2012-12-03 23:00:08 +0100 | [diff] [blame] | 360 | |
Johannes Berg | 379b82f | 2012-12-06 15:44:07 +0100 | [diff] [blame] | 361 | reset_regdomains(false, rd); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 362 | |
| 363 | cfg80211_world_regdom = rd; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 364 | } |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 365 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 366 | bool is_world_regdom(const char *alpha2) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 367 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 368 | if (!alpha2) |
| 369 | return false; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 370 | return alpha2[0] == '0' && alpha2[1] == '0'; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 371 | } |
| 372 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 373 | static bool is_alpha2_set(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 374 | { |
| 375 | if (!alpha2) |
| 376 | return false; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 377 | return alpha2[0] && alpha2[1]; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 378 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 379 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 380 | static bool is_unknown_alpha2(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 381 | { |
| 382 | if (!alpha2) |
| 383 | return false; |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 384 | /* |
| 385 | * Special case where regulatory domain was built by driver |
| 386 | * but a specific alpha2 cannot be determined |
| 387 | */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 388 | return alpha2[0] == '9' && alpha2[1] == '9'; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 391 | static bool is_intersected_alpha2(const char *alpha2) |
| 392 | { |
| 393 | if (!alpha2) |
| 394 | return false; |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 395 | /* |
| 396 | * Special case where regulatory domain is the |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 397 | * result of an intersection between two regulatory domain |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 398 | * structures |
| 399 | */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 400 | return alpha2[0] == '9' && alpha2[1] == '8'; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 401 | } |
| 402 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 403 | static bool is_an_alpha2(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 404 | { |
| 405 | if (!alpha2) |
| 406 | return false; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 407 | return isalpha(alpha2[0]) && isalpha(alpha2[1]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 410 | 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] | 411 | { |
| 412 | if (!alpha2_x || !alpha2_y) |
| 413 | return false; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 414 | 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] | 415 | } |
| 416 | |
Luis R. Rodriguez | 69b1572 | 2009-02-21 00:04:33 -0500 | [diff] [blame] | 417 | static bool regdom_changes(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 418 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 419 | const struct ieee80211_regdomain *r = get_cfg80211_regdom(); |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 420 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 421 | if (!r) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 422 | return true; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 423 | return !alpha2_equal(r->alpha2, alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 426 | /* |
| 427 | * The NL80211_REGDOM_SET_BY_USER regdom alpha2 is cached, this lets |
| 428 | * you know if a valid regulatory hint with NL80211_REGDOM_SET_BY_USER |
| 429 | * has ever been issued. |
| 430 | */ |
| 431 | static bool is_user_regdom_saved(void) |
| 432 | { |
| 433 | if (user_alpha2[0] == '9' && user_alpha2[1] == '7') |
| 434 | return false; |
| 435 | |
| 436 | /* This would indicate a mistake on the design */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 437 | 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] | 438 | "Unexpected user alpha2: %c%c\n", |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 439 | user_alpha2[0], user_alpha2[1])) |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 440 | return false; |
| 441 | |
| 442 | return true; |
| 443 | } |
| 444 | |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 445 | static const struct ieee80211_regdomain * |
| 446 | reg_copy_regd(const struct ieee80211_regdomain *src_regd) |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 447 | { |
| 448 | struct ieee80211_regdomain *regd; |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 449 | unsigned int i; |
| 450 | |
Gustavo A. R. Silva | 9f8c713 | 2019-04-03 10:31:51 -0500 | [diff] [blame] | 451 | regd = kzalloc(struct_size(regd, reg_rules, src_regd->n_reg_rules), |
| 452 | GFP_KERNEL); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 453 | if (!regd) |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 454 | return ERR_PTR(-ENOMEM); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 455 | |
| 456 | memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain)); |
| 457 | |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 458 | for (i = 0; i < src_regd->n_reg_rules; i++) |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 459 | memcpy(®d->reg_rules[i], &src_regd->reg_rules[i], |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 460 | sizeof(struct ieee80211_reg_rule)); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 461 | |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 462 | return regd; |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 463 | } |
| 464 | |
Johannes Berg | e646a02 | 2019-02-05 21:08:29 +0100 | [diff] [blame] | 465 | static void cfg80211_save_user_regdom(const struct ieee80211_regdomain *rd) |
| 466 | { |
| 467 | ASSERT_RTNL(); |
| 468 | |
| 469 | if (!IS_ERR(cfg80211_user_regdom)) |
| 470 | kfree(cfg80211_user_regdom); |
| 471 | cfg80211_user_regdom = reg_copy_regd(rd); |
| 472 | } |
| 473 | |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 474 | struct reg_regdb_apply_request { |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 475 | struct list_head list; |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 476 | const struct ieee80211_regdomain *regdom; |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 477 | }; |
| 478 | |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 479 | static LIST_HEAD(reg_regdb_apply_list); |
| 480 | static DEFINE_MUTEX(reg_regdb_apply_mutex); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 481 | |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 482 | static void reg_regdb_apply(struct work_struct *work) |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 483 | { |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 484 | struct reg_regdb_apply_request *request; |
Luis R. Rodriguez | a85d0d7 | 2012-09-14 15:36:57 -0700 | [diff] [blame] | 485 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 486 | rtnl_lock(); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 487 | |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 488 | mutex_lock(®_regdb_apply_mutex); |
| 489 | while (!list_empty(®_regdb_apply_list)) { |
| 490 | request = list_first_entry(®_regdb_apply_list, |
| 491 | struct reg_regdb_apply_request, |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 492 | list); |
| 493 | list_del(&request->list); |
| 494 | |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 495 | set_regdom(request->regdom, REGD_SOURCE_INTERNAL_DB); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 496 | kfree(request); |
| 497 | } |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 498 | mutex_unlock(®_regdb_apply_mutex); |
Luis R. Rodriguez | a85d0d7 | 2012-09-14 15:36:57 -0700 | [diff] [blame] | 499 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 500 | rtnl_unlock(); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 501 | } |
| 502 | |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 503 | static DECLARE_WORK(reg_regdb_work, reg_regdb_apply); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 504 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 505 | static int reg_schedule_apply(const struct ieee80211_regdomain *regdom) |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 506 | { |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 507 | struct reg_regdb_apply_request *request; |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 508 | |
| 509 | request = kzalloc(sizeof(struct reg_regdb_apply_request), GFP_KERNEL); |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 510 | if (!request) { |
| 511 | kfree(regdom); |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 512 | return -ENOMEM; |
| 513 | } |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 514 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 515 | request->regdom = regdom; |
| 516 | |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 517 | mutex_lock(®_regdb_apply_mutex); |
| 518 | list_add_tail(&request->list, ®_regdb_apply_list); |
| 519 | mutex_unlock(®_regdb_apply_mutex); |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 520 | |
| 521 | schedule_work(®_regdb_work); |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 522 | return 0; |
John W. Linville | 3b377ea | 2009-12-18 17:59:01 -0500 | [diff] [blame] | 523 | } |
Luis R. Rodriguez | 80007ef | 2012-03-23 07:23:31 -0700 | [diff] [blame] | 524 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 525 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 526 | /* Max number of consecutive attempts to communicate with CRDA */ |
| 527 | #define REG_MAX_CRDA_TIMEOUTS 10 |
| 528 | |
| 529 | static u32 reg_crda_timeouts; |
| 530 | |
| 531 | static void crda_timeout_work(struct work_struct *work); |
| 532 | static DECLARE_DELAYED_WORK(crda_timeout, crda_timeout_work); |
| 533 | |
| 534 | static void crda_timeout_work(struct work_struct *work) |
| 535 | { |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 536 | pr_debug("Timeout while waiting for CRDA to reply, restoring regulatory settings\n"); |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 537 | rtnl_lock(); |
| 538 | reg_crda_timeouts++; |
Johannes Berg | e646a02 | 2019-02-05 21:08:29 +0100 | [diff] [blame] | 539 | restore_regulatory_settings(true, false); |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 540 | rtnl_unlock(); |
| 541 | } |
| 542 | |
| 543 | static void cancel_crda_timeout(void) |
| 544 | { |
| 545 | cancel_delayed_work(&crda_timeout); |
| 546 | } |
| 547 | |
| 548 | static void cancel_crda_timeout_sync(void) |
| 549 | { |
| 550 | cancel_delayed_work_sync(&crda_timeout); |
| 551 | } |
| 552 | |
| 553 | static void reset_crda_timeouts(void) |
| 554 | { |
| 555 | reg_crda_timeouts = 0; |
| 556 | } |
| 557 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 558 | /* |
| 559 | * This lets us keep regulatory code which is updated on a regulatory |
Johannes Berg | 1226d25 | 2014-02-25 15:43:36 +0100 | [diff] [blame] | 560 | * basis in userspace. |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 561 | */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 562 | static int call_crda(const char *alpha2) |
| 563 | { |
Johannes Berg | 1226d25 | 2014-02-25 15:43:36 +0100 | [diff] [blame] | 564 | char country[12]; |
| 565 | char *env[] = { country, NULL }; |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 566 | int ret; |
Johannes Berg | 1226d25 | 2014-02-25 15:43:36 +0100 | [diff] [blame] | 567 | |
| 568 | snprintf(country, sizeof(country), "COUNTRY=%c%c", |
| 569 | alpha2[0], alpha2[1]); |
| 570 | |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 571 | if (reg_crda_timeouts > REG_MAX_CRDA_TIMEOUTS) { |
Thomas Petazzoni | 042ab5f | 2015-07-09 15:35:15 +0200 | [diff] [blame] | 572 | pr_debug("Exceeded CRDA call max attempts. Not calling CRDA\n"); |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 573 | return -EINVAL; |
| 574 | } |
| 575 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 576 | if (!is_world_regdom((char *) alpha2)) |
Thomas Petazzoni | 042ab5f | 2015-07-09 15:35:15 +0200 | [diff] [blame] | 577 | pr_debug("Calling CRDA for country: %c%c\n", |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 578 | alpha2[0], alpha2[1]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 579 | else |
Thomas Petazzoni | 042ab5f | 2015-07-09 15:35:15 +0200 | [diff] [blame] | 580 | pr_debug("Calling CRDA to update world regulatory domain\n"); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 581 | |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 582 | ret = kobject_uevent_env(®_pdev->dev.kobj, KOBJ_CHANGE, env); |
| 583 | if (ret) |
| 584 | return ret; |
| 585 | |
| 586 | queue_delayed_work(system_power_efficient_wq, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 587 | &crda_timeout, msecs_to_jiffies(3142)); |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 588 | return 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 589 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 590 | #else |
| 591 | static inline void cancel_crda_timeout(void) {} |
| 592 | static inline void cancel_crda_timeout_sync(void) {} |
| 593 | static inline void reset_crda_timeouts(void) {} |
| 594 | static inline int call_crda(const char *alpha2) |
| 595 | { |
| 596 | return -ENODATA; |
| 597 | } |
| 598 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 599 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 600 | /* code to directly load a firmware database through request_firmware */ |
| 601 | static const struct fwdb_header *regdb; |
| 602 | |
| 603 | struct fwdb_country { |
| 604 | u8 alpha2[2]; |
| 605 | __be16 coll_ptr; |
| 606 | /* this struct cannot be extended */ |
| 607 | } __packed __aligned(4); |
| 608 | |
| 609 | struct fwdb_collection { |
| 610 | u8 len; |
| 611 | u8 n_rules; |
| 612 | u8 dfs_region; |
| 613 | /* no optional data yet */ |
| 614 | /* aligned to 2, then followed by __be16 array of rule pointers */ |
| 615 | } __packed __aligned(4); |
| 616 | |
| 617 | enum fwdb_flags { |
| 618 | FWDB_FLAG_NO_OFDM = BIT(0), |
| 619 | FWDB_FLAG_NO_OUTDOOR = BIT(1), |
| 620 | FWDB_FLAG_DFS = BIT(2), |
| 621 | FWDB_FLAG_NO_IR = BIT(3), |
| 622 | FWDB_FLAG_AUTO_BW = BIT(4), |
| 623 | }; |
| 624 | |
Haim Dreyfuss | 230ebaa | 2018-03-28 13:24:09 +0300 | [diff] [blame] | 625 | struct fwdb_wmm_ac { |
| 626 | u8 ecw; |
| 627 | u8 aifsn; |
| 628 | __be16 cot; |
| 629 | } __packed; |
| 630 | |
| 631 | struct fwdb_wmm_rule { |
| 632 | struct fwdb_wmm_ac client[IEEE80211_NUM_ACS]; |
| 633 | struct fwdb_wmm_ac ap[IEEE80211_NUM_ACS]; |
| 634 | } __packed; |
| 635 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 636 | struct fwdb_rule { |
| 637 | u8 len; |
| 638 | u8 flags; |
| 639 | __be16 max_eirp; |
| 640 | __be32 start, end, max_bw; |
| 641 | /* start of optional data */ |
| 642 | __be16 cac_timeout; |
Haim Dreyfuss | 230ebaa | 2018-03-28 13:24:09 +0300 | [diff] [blame] | 643 | __be16 wmm_ptr; |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 644 | } __packed __aligned(4); |
| 645 | |
| 646 | #define FWDB_MAGIC 0x52474442 |
| 647 | #define FWDB_VERSION 20 |
| 648 | |
| 649 | struct fwdb_header { |
| 650 | __be32 magic; |
| 651 | __be32 version; |
| 652 | struct fwdb_country country[]; |
| 653 | } __packed __aligned(4); |
| 654 | |
Haim Dreyfuss | 230ebaa | 2018-03-28 13:24:09 +0300 | [diff] [blame] | 655 | static int ecw2cw(int ecw) |
| 656 | { |
| 657 | return (1 << ecw) - 1; |
| 658 | } |
| 659 | |
| 660 | static bool valid_wmm(struct fwdb_wmm_rule *rule) |
| 661 | { |
| 662 | struct fwdb_wmm_ac *ac = (struct fwdb_wmm_ac *)rule; |
| 663 | int i; |
| 664 | |
| 665 | for (i = 0; i < IEEE80211_NUM_ACS * 2; i++) { |
| 666 | u16 cw_min = ecw2cw((ac[i].ecw & 0xf0) >> 4); |
| 667 | u16 cw_max = ecw2cw(ac[i].ecw & 0x0f); |
| 668 | u8 aifsn = ac[i].aifsn; |
| 669 | |
| 670 | if (cw_min >= cw_max) |
| 671 | return false; |
| 672 | |
| 673 | if (aifsn < 1) |
| 674 | return false; |
| 675 | } |
| 676 | |
| 677 | return true; |
| 678 | } |
| 679 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 680 | static bool valid_rule(const u8 *data, unsigned int size, u16 rule_ptr) |
| 681 | { |
| 682 | struct fwdb_rule *rule = (void *)(data + (rule_ptr << 2)); |
| 683 | |
| 684 | if ((u8 *)rule + sizeof(rule->len) > data + size) |
| 685 | return false; |
| 686 | |
| 687 | /* mandatory fields */ |
| 688 | if (rule->len < offsetofend(struct fwdb_rule, max_bw)) |
| 689 | return false; |
Haim Dreyfuss | 230ebaa | 2018-03-28 13:24:09 +0300 | [diff] [blame] | 690 | if (rule->len >= offsetofend(struct fwdb_rule, wmm_ptr)) { |
| 691 | u32 wmm_ptr = be16_to_cpu(rule->wmm_ptr) << 2; |
| 692 | struct fwdb_wmm_rule *wmm; |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 693 | |
Haim Dreyfuss | 230ebaa | 2018-03-28 13:24:09 +0300 | [diff] [blame] | 694 | if (wmm_ptr + sizeof(struct fwdb_wmm_rule) > size) |
| 695 | return false; |
| 696 | |
| 697 | wmm = (void *)(data + wmm_ptr); |
| 698 | |
| 699 | if (!valid_wmm(wmm)) |
| 700 | return false; |
| 701 | } |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 702 | return true; |
| 703 | } |
| 704 | |
| 705 | static bool valid_country(const u8 *data, unsigned int size, |
| 706 | const struct fwdb_country *country) |
| 707 | { |
| 708 | unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2; |
| 709 | struct fwdb_collection *coll = (void *)(data + ptr); |
| 710 | __be16 *rules_ptr; |
| 711 | unsigned int i; |
| 712 | |
| 713 | /* make sure we can read len/n_rules */ |
| 714 | if ((u8 *)coll + offsetofend(typeof(*coll), n_rules) > data + size) |
| 715 | return false; |
| 716 | |
| 717 | /* make sure base struct and all rules fit */ |
| 718 | if ((u8 *)coll + ALIGN(coll->len, 2) + |
| 719 | (coll->n_rules * 2) > data + size) |
| 720 | return false; |
| 721 | |
| 722 | /* mandatory fields must exist */ |
| 723 | if (coll->len < offsetofend(struct fwdb_collection, dfs_region)) |
| 724 | return false; |
| 725 | |
| 726 | rules_ptr = (void *)((u8 *)coll + ALIGN(coll->len, 2)); |
| 727 | |
| 728 | for (i = 0; i < coll->n_rules; i++) { |
| 729 | u16 rule_ptr = be16_to_cpu(rules_ptr[i]); |
| 730 | |
| 731 | if (!valid_rule(data, size, rule_ptr)) |
| 732 | return false; |
| 733 | } |
| 734 | |
| 735 | return true; |
| 736 | } |
| 737 | |
Johannes Berg | 90a53e4 | 2017-09-13 22:21:08 +0200 | [diff] [blame] | 738 | #ifdef CONFIG_CFG80211_REQUIRE_SIGNED_REGDB |
| 739 | static struct key *builtin_regdb_keys; |
| 740 | |
| 741 | static void __init load_keys_from_buffer(const u8 *p, unsigned int buflen) |
| 742 | { |
| 743 | const u8 *end = p + buflen; |
| 744 | size_t plen; |
| 745 | key_ref_t key; |
| 746 | |
| 747 | while (p < end) { |
| 748 | /* Each cert begins with an ASN.1 SEQUENCE tag and must be more |
| 749 | * than 256 bytes in size. |
| 750 | */ |
| 751 | if (end - p < 4) |
| 752 | goto dodgy_cert; |
| 753 | if (p[0] != 0x30 && |
| 754 | p[1] != 0x82) |
| 755 | goto dodgy_cert; |
| 756 | plen = (p[2] << 8) | p[3]; |
| 757 | plen += 4; |
| 758 | if (plen > end - p) |
| 759 | goto dodgy_cert; |
| 760 | |
| 761 | key = key_create_or_update(make_key_ref(builtin_regdb_keys, 1), |
| 762 | "asymmetric", NULL, p, plen, |
Linus Torvalds | 028db3e | 2019-07-10 18:43:43 -0700 | [diff] [blame] | 763 | ((KEY_POS_ALL & ~KEY_POS_SETATTR) | |
| 764 | KEY_USR_VIEW | KEY_USR_READ), |
Johannes Berg | 90a53e4 | 2017-09-13 22:21:08 +0200 | [diff] [blame] | 765 | KEY_ALLOC_NOT_IN_QUOTA | |
| 766 | KEY_ALLOC_BUILT_IN | |
| 767 | KEY_ALLOC_BYPASS_RESTRICTION); |
| 768 | if (IS_ERR(key)) { |
| 769 | pr_err("Problem loading in-kernel X.509 certificate (%ld)\n", |
| 770 | PTR_ERR(key)); |
| 771 | } else { |
| 772 | pr_notice("Loaded X.509 cert '%s'\n", |
| 773 | key_ref_to_ptr(key)->description); |
| 774 | key_ref_put(key); |
| 775 | } |
| 776 | p += plen; |
| 777 | } |
| 778 | |
| 779 | return; |
| 780 | |
| 781 | dodgy_cert: |
| 782 | pr_err("Problem parsing in-kernel X.509 certificate list\n"); |
| 783 | } |
| 784 | |
| 785 | static int __init load_builtin_regdb_keys(void) |
| 786 | { |
| 787 | builtin_regdb_keys = |
| 788 | keyring_alloc(".builtin_regdb_keys", |
| 789 | KUIDT_INIT(0), KGIDT_INIT(0), current_cred(), |
Linus Torvalds | 028db3e | 2019-07-10 18:43:43 -0700 | [diff] [blame] | 790 | ((KEY_POS_ALL & ~KEY_POS_SETATTR) | |
| 791 | KEY_USR_VIEW | KEY_USR_READ | KEY_USR_SEARCH), |
Johannes Berg | 90a53e4 | 2017-09-13 22:21:08 +0200 | [diff] [blame] | 792 | KEY_ALLOC_NOT_IN_QUOTA, NULL, NULL); |
| 793 | if (IS_ERR(builtin_regdb_keys)) |
| 794 | return PTR_ERR(builtin_regdb_keys); |
| 795 | |
| 796 | pr_notice("Loading compiled-in X.509 certificates for regulatory database\n"); |
| 797 | |
| 798 | #ifdef CONFIG_CFG80211_USE_KERNEL_REGDB_KEYS |
| 799 | load_keys_from_buffer(shipped_regdb_certs, shipped_regdb_certs_len); |
| 800 | #endif |
Arnd Bergmann | 88230ef | 2017-10-13 14:04:31 +0200 | [diff] [blame] | 801 | #ifdef CONFIG_CFG80211_EXTRA_REGDB_KEYDIR |
Johannes Berg | 90a53e4 | 2017-09-13 22:21:08 +0200 | [diff] [blame] | 802 | if (CONFIG_CFG80211_EXTRA_REGDB_KEYDIR[0] != '\0') |
| 803 | load_keys_from_buffer(extra_regdb_certs, extra_regdb_certs_len); |
| 804 | #endif |
| 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | static bool regdb_has_valid_signature(const u8 *data, unsigned int size) |
| 810 | { |
| 811 | const struct firmware *sig; |
| 812 | bool result; |
| 813 | |
| 814 | if (request_firmware(&sig, "regulatory.db.p7s", ®_pdev->dev)) |
| 815 | return false; |
| 816 | |
| 817 | result = verify_pkcs7_signature(data, size, sig->data, sig->size, |
| 818 | builtin_regdb_keys, |
| 819 | VERIFYING_UNSPECIFIED_SIGNATURE, |
| 820 | NULL, NULL) == 0; |
| 821 | |
| 822 | release_firmware(sig); |
| 823 | |
| 824 | return result; |
| 825 | } |
| 826 | |
| 827 | static void free_regdb_keyring(void) |
| 828 | { |
| 829 | key_put(builtin_regdb_keys); |
| 830 | } |
| 831 | #else |
| 832 | static int load_builtin_regdb_keys(void) |
| 833 | { |
| 834 | return 0; |
| 835 | } |
| 836 | |
| 837 | static bool regdb_has_valid_signature(const u8 *data, unsigned int size) |
| 838 | { |
| 839 | return true; |
| 840 | } |
| 841 | |
| 842 | static void free_regdb_keyring(void) |
| 843 | { |
| 844 | } |
| 845 | #endif /* CONFIG_CFG80211_REQUIRE_SIGNED_REGDB */ |
| 846 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 847 | static bool valid_regdb(const u8 *data, unsigned int size) |
| 848 | { |
| 849 | const struct fwdb_header *hdr = (void *)data; |
| 850 | const struct fwdb_country *country; |
| 851 | |
| 852 | if (size < sizeof(*hdr)) |
| 853 | return false; |
| 854 | |
| 855 | if (hdr->magic != cpu_to_be32(FWDB_MAGIC)) |
| 856 | return false; |
| 857 | |
| 858 | if (hdr->version != cpu_to_be32(FWDB_VERSION)) |
| 859 | return false; |
| 860 | |
Johannes Berg | 90a53e4 | 2017-09-13 22:21:08 +0200 | [diff] [blame] | 861 | if (!regdb_has_valid_signature(data, size)) |
| 862 | return false; |
| 863 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 864 | country = &hdr->country[0]; |
| 865 | while ((u8 *)(country + 1) <= data + size) { |
| 866 | if (!country->coll_ptr) |
| 867 | break; |
| 868 | if (!valid_country(data, size, country)) |
| 869 | return false; |
| 870 | country++; |
| 871 | } |
| 872 | |
| 873 | return true; |
| 874 | } |
| 875 | |
Stanislaw Gruszka | 014f5a2 | 2018-08-22 13:52:22 +0200 | [diff] [blame] | 876 | static void set_wmm_rule(const struct fwdb_header *db, |
| 877 | const struct fwdb_country *country, |
| 878 | const struct fwdb_rule *rule, |
| 879 | struct ieee80211_reg_rule *rrule) |
Haim Dreyfuss | 230ebaa | 2018-03-28 13:24:09 +0300 | [diff] [blame] | 880 | { |
Stanislaw Gruszka | 014f5a2 | 2018-08-22 13:52:22 +0200 | [diff] [blame] | 881 | struct ieee80211_wmm_rule *wmm_rule = &rrule->wmm_rule; |
| 882 | struct fwdb_wmm_rule *wmm; |
| 883 | unsigned int i, wmm_ptr; |
| 884 | |
| 885 | wmm_ptr = be16_to_cpu(rule->wmm_ptr) << 2; |
| 886 | wmm = (void *)((u8 *)db + wmm_ptr); |
| 887 | |
| 888 | if (!valid_wmm(wmm)) { |
| 889 | pr_err("Invalid regulatory WMM rule %u-%u in domain %c%c\n", |
| 890 | be32_to_cpu(rule->start), be32_to_cpu(rule->end), |
| 891 | country->alpha2[0], country->alpha2[1]); |
| 892 | return; |
| 893 | } |
Haim Dreyfuss | 230ebaa | 2018-03-28 13:24:09 +0300 | [diff] [blame] | 894 | |
| 895 | for (i = 0; i < IEEE80211_NUM_ACS; i++) { |
Stanislaw Gruszka | 014f5a2 | 2018-08-22 13:52:22 +0200 | [diff] [blame] | 896 | wmm_rule->client[i].cw_min = |
Haim Dreyfuss | 230ebaa | 2018-03-28 13:24:09 +0300 | [diff] [blame] | 897 | ecw2cw((wmm->client[i].ecw & 0xf0) >> 4); |
Stanislaw Gruszka | 014f5a2 | 2018-08-22 13:52:22 +0200 | [diff] [blame] | 898 | wmm_rule->client[i].cw_max = ecw2cw(wmm->client[i].ecw & 0x0f); |
| 899 | wmm_rule->client[i].aifsn = wmm->client[i].aifsn; |
| 900 | wmm_rule->client[i].cot = |
| 901 | 1000 * be16_to_cpu(wmm->client[i].cot); |
| 902 | wmm_rule->ap[i].cw_min = ecw2cw((wmm->ap[i].ecw & 0xf0) >> 4); |
| 903 | wmm_rule->ap[i].cw_max = ecw2cw(wmm->ap[i].ecw & 0x0f); |
| 904 | wmm_rule->ap[i].aifsn = wmm->ap[i].aifsn; |
| 905 | wmm_rule->ap[i].cot = 1000 * be16_to_cpu(wmm->ap[i].cot); |
Haim Dreyfuss | 230ebaa | 2018-03-28 13:24:09 +0300 | [diff] [blame] | 906 | } |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 907 | |
| 908 | rrule->has_wmm = true; |
Haim Dreyfuss | 230ebaa | 2018-03-28 13:24:09 +0300 | [diff] [blame] | 909 | } |
| 910 | |
Haim Dreyfuss | 19d3577 | 2018-03-28 13:24:11 +0300 | [diff] [blame] | 911 | static int __regdb_query_wmm(const struct fwdb_header *db, |
| 912 | const struct fwdb_country *country, int freq, |
Stanislaw Gruszka | 014f5a2 | 2018-08-22 13:52:22 +0200 | [diff] [blame] | 913 | struct ieee80211_reg_rule *rrule) |
Haim Dreyfuss | 19d3577 | 2018-03-28 13:24:11 +0300 | [diff] [blame] | 914 | { |
| 915 | unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2; |
| 916 | struct fwdb_collection *coll = (void *)((u8 *)db + ptr); |
| 917 | int i; |
| 918 | |
| 919 | for (i = 0; i < coll->n_rules; i++) { |
| 920 | __be16 *rules_ptr = (void *)((u8 *)coll + ALIGN(coll->len, 2)); |
| 921 | unsigned int rule_ptr = be16_to_cpu(rules_ptr[i]) << 2; |
Stanislaw Gruszka | 014f5a2 | 2018-08-22 13:52:22 +0200 | [diff] [blame] | 922 | struct fwdb_rule *rule = (void *)((u8 *)db + rule_ptr); |
Haim Dreyfuss | 19d3577 | 2018-03-28 13:24:11 +0300 | [diff] [blame] | 923 | |
Stanislaw Gruszka | 014f5a2 | 2018-08-22 13:52:22 +0200 | [diff] [blame] | 924 | if (rule->len < offsetofend(struct fwdb_rule, wmm_ptr)) |
Haim Dreyfuss | 19d3577 | 2018-03-28 13:24:11 +0300 | [diff] [blame] | 925 | continue; |
| 926 | |
Stanislaw Gruszka | 014f5a2 | 2018-08-22 13:52:22 +0200 | [diff] [blame] | 927 | if (freq >= KHZ_TO_MHZ(be32_to_cpu(rule->start)) && |
| 928 | freq <= KHZ_TO_MHZ(be32_to_cpu(rule->end))) { |
| 929 | set_wmm_rule(db, country, rule, rrule); |
Haim Dreyfuss | 19d3577 | 2018-03-28 13:24:11 +0300 | [diff] [blame] | 930 | return 0; |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | return -ENODATA; |
| 935 | } |
| 936 | |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 937 | int reg_query_regdb_wmm(char *alpha2, int freq, struct ieee80211_reg_rule *rule) |
Haim Dreyfuss | 19d3577 | 2018-03-28 13:24:11 +0300 | [diff] [blame] | 938 | { |
| 939 | const struct fwdb_header *hdr = regdb; |
| 940 | const struct fwdb_country *country; |
| 941 | |
Haim Dreyfuss | 5247a77 | 2018-05-21 23:34:57 +0300 | [diff] [blame] | 942 | if (!regdb) |
| 943 | return -ENODATA; |
| 944 | |
Haim Dreyfuss | 19d3577 | 2018-03-28 13:24:11 +0300 | [diff] [blame] | 945 | if (IS_ERR(regdb)) |
| 946 | return PTR_ERR(regdb); |
| 947 | |
| 948 | country = &hdr->country[0]; |
| 949 | while (country->coll_ptr) { |
| 950 | if (alpha2_equal(alpha2, country->alpha2)) |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 951 | return __regdb_query_wmm(regdb, country, freq, rule); |
Haim Dreyfuss | 19d3577 | 2018-03-28 13:24:11 +0300 | [diff] [blame] | 952 | |
| 953 | country++; |
| 954 | } |
| 955 | |
| 956 | return -ENODATA; |
| 957 | } |
| 958 | EXPORT_SYMBOL(reg_query_regdb_wmm); |
| 959 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 960 | static int regdb_query_country(const struct fwdb_header *db, |
| 961 | const struct fwdb_country *country) |
| 962 | { |
| 963 | unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2; |
| 964 | struct fwdb_collection *coll = (void *)((u8 *)db + ptr); |
| 965 | struct ieee80211_regdomain *regdom; |
Gustavo A. R. Silva | 9f8c713 | 2019-04-03 10:31:51 -0500 | [diff] [blame] | 966 | unsigned int i; |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 967 | |
Gustavo A. R. Silva | 9f8c713 | 2019-04-03 10:31:51 -0500 | [diff] [blame] | 968 | regdom = kzalloc(struct_size(regdom, reg_rules, coll->n_rules), |
| 969 | GFP_KERNEL); |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 970 | if (!regdom) |
| 971 | return -ENOMEM; |
| 972 | |
| 973 | regdom->n_reg_rules = coll->n_rules; |
| 974 | regdom->alpha2[0] = country->alpha2[0]; |
| 975 | regdom->alpha2[1] = country->alpha2[1]; |
| 976 | regdom->dfs_region = coll->dfs_region; |
| 977 | |
| 978 | for (i = 0; i < regdom->n_reg_rules; i++) { |
| 979 | __be16 *rules_ptr = (void *)((u8 *)coll + ALIGN(coll->len, 2)); |
| 980 | unsigned int rule_ptr = be16_to_cpu(rules_ptr[i]) << 2; |
| 981 | struct fwdb_rule *rule = (void *)((u8 *)db + rule_ptr); |
| 982 | struct ieee80211_reg_rule *rrule = ®dom->reg_rules[i]; |
| 983 | |
| 984 | rrule->freq_range.start_freq_khz = be32_to_cpu(rule->start); |
| 985 | rrule->freq_range.end_freq_khz = be32_to_cpu(rule->end); |
| 986 | rrule->freq_range.max_bandwidth_khz = be32_to_cpu(rule->max_bw); |
| 987 | |
| 988 | rrule->power_rule.max_antenna_gain = 0; |
| 989 | rrule->power_rule.max_eirp = be16_to_cpu(rule->max_eirp); |
| 990 | |
| 991 | rrule->flags = 0; |
| 992 | if (rule->flags & FWDB_FLAG_NO_OFDM) |
| 993 | rrule->flags |= NL80211_RRF_NO_OFDM; |
| 994 | if (rule->flags & FWDB_FLAG_NO_OUTDOOR) |
| 995 | rrule->flags |= NL80211_RRF_NO_OUTDOOR; |
| 996 | if (rule->flags & FWDB_FLAG_DFS) |
| 997 | rrule->flags |= NL80211_RRF_DFS; |
| 998 | if (rule->flags & FWDB_FLAG_NO_IR) |
| 999 | rrule->flags |= NL80211_RRF_NO_IR; |
| 1000 | if (rule->flags & FWDB_FLAG_AUTO_BW) |
| 1001 | rrule->flags |= NL80211_RRF_AUTO_BW; |
| 1002 | |
| 1003 | rrule->dfs_cac_ms = 0; |
| 1004 | |
| 1005 | /* handle optional data */ |
| 1006 | if (rule->len >= offsetofend(struct fwdb_rule, cac_timeout)) |
| 1007 | rrule->dfs_cac_ms = |
| 1008 | 1000 * be16_to_cpu(rule->cac_timeout); |
Stanislaw Gruszka | 014f5a2 | 2018-08-22 13:52:22 +0200 | [diff] [blame] | 1009 | if (rule->len >= offsetofend(struct fwdb_rule, wmm_ptr)) |
| 1010 | set_wmm_rule(db, country, rule, rrule); |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | return reg_schedule_apply(regdom); |
| 1014 | } |
| 1015 | |
| 1016 | static int query_regdb(const char *alpha2) |
| 1017 | { |
| 1018 | const struct fwdb_header *hdr = regdb; |
| 1019 | const struct fwdb_country *country; |
| 1020 | |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 1021 | ASSERT_RTNL(); |
| 1022 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 1023 | if (IS_ERR(regdb)) |
| 1024 | return PTR_ERR(regdb); |
| 1025 | |
| 1026 | country = &hdr->country[0]; |
| 1027 | while (country->coll_ptr) { |
| 1028 | if (alpha2_equal(alpha2, country->alpha2)) |
| 1029 | return regdb_query_country(regdb, country); |
| 1030 | country++; |
| 1031 | } |
| 1032 | |
| 1033 | return -ENODATA; |
| 1034 | } |
| 1035 | |
| 1036 | static void regdb_fw_cb(const struct firmware *fw, void *context) |
| 1037 | { |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 1038 | int set_error = 0; |
| 1039 | bool restore = true; |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 1040 | void *db; |
| 1041 | |
| 1042 | if (!fw) { |
| 1043 | pr_info("failed to load regulatory.db\n"); |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 1044 | set_error = -ENODATA; |
| 1045 | } else if (!valid_regdb(fw->data, fw->size)) { |
Johannes Berg | 90a53e4 | 2017-09-13 22:21:08 +0200 | [diff] [blame] | 1046 | pr_info("loaded regulatory.db is malformed or signature is missing/invalid\n"); |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 1047 | set_error = -EINVAL; |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 1048 | } |
| 1049 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 1050 | rtnl_lock(); |
Chaitanya Tata | faae54a | 2019-01-24 16:13:02 +0530 | [diff] [blame] | 1051 | if (regdb && !IS_ERR(regdb)) { |
| 1052 | /* negative case - a bug |
| 1053 | * positive case - can happen due to race in case of multiple cb's in |
| 1054 | * queue, due to usage of asynchronous callback |
| 1055 | * |
| 1056 | * Either case, just restore and free new db. |
| 1057 | */ |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 1058 | } else if (set_error) { |
| 1059 | regdb = ERR_PTR(set_error); |
| 1060 | } else if (fw) { |
| 1061 | db = kmemdup(fw->data, fw->size, GFP_KERNEL); |
| 1062 | if (db) { |
| 1063 | regdb = db; |
| 1064 | restore = context && query_regdb(context); |
| 1065 | } else { |
| 1066 | restore = true; |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | if (restore) |
Johannes Berg | e646a02 | 2019-02-05 21:08:29 +0100 | [diff] [blame] | 1071 | restore_regulatory_settings(true, false); |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 1072 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 1073 | rtnl_unlock(); |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 1074 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 1075 | kfree(context); |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 1076 | |
| 1077 | release_firmware(fw); |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | static int query_regdb_file(const char *alpha2) |
| 1081 | { |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 1082 | ASSERT_RTNL(); |
| 1083 | |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 1084 | if (regdb) |
| 1085 | return query_regdb(alpha2); |
| 1086 | |
| 1087 | alpha2 = kmemdup(alpha2, 2, GFP_KERNEL); |
| 1088 | if (!alpha2) |
| 1089 | return -ENOMEM; |
| 1090 | |
| 1091 | return request_firmware_nowait(THIS_MODULE, true, "regulatory.db", |
| 1092 | ®_pdev->dev, GFP_KERNEL, |
| 1093 | (void *)alpha2, regdb_fw_cb); |
| 1094 | } |
| 1095 | |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 1096 | int reg_reload_regdb(void) |
| 1097 | { |
| 1098 | const struct firmware *fw; |
| 1099 | void *db; |
| 1100 | int err; |
| 1101 | |
| 1102 | err = request_firmware(&fw, "regulatory.db", ®_pdev->dev); |
| 1103 | if (err) |
| 1104 | return err; |
| 1105 | |
| 1106 | if (!valid_regdb(fw->data, fw->size)) { |
| 1107 | err = -ENODATA; |
| 1108 | goto out; |
| 1109 | } |
| 1110 | |
| 1111 | db = kmemdup(fw->data, fw->size, GFP_KERNEL); |
| 1112 | if (!db) { |
| 1113 | err = -ENOMEM; |
| 1114 | goto out; |
| 1115 | } |
| 1116 | |
| 1117 | rtnl_lock(); |
| 1118 | if (!IS_ERR_OR_NULL(regdb)) |
| 1119 | kfree(regdb); |
| 1120 | regdb = db; |
| 1121 | rtnl_unlock(); |
| 1122 | |
| 1123 | out: |
| 1124 | release_firmware(fw); |
| 1125 | return err; |
| 1126 | } |
| 1127 | |
Johannes Berg | cecbb06 | 2015-10-15 08:47:34 +0200 | [diff] [blame] | 1128 | static bool reg_query_database(struct regulatory_request *request) |
Luis R. Rodriguez | fe6631f | 2013-11-05 09:18:10 -0800 | [diff] [blame] | 1129 | { |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 1130 | if (query_regdb_file(request->alpha2) == 0) |
| 1131 | return true; |
| 1132 | |
Johannes Berg | c7d319e5 | 2015-10-15 09:03:05 +0200 | [diff] [blame] | 1133 | if (call_crda(request->alpha2) == 0) |
| 1134 | return true; |
| 1135 | |
| 1136 | return false; |
Luis R. Rodriguez | fe6631f | 2013-11-05 09:18:10 -0800 | [diff] [blame] | 1137 | } |
| 1138 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 1139 | bool reg_is_valid_request(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1140 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1141 | struct regulatory_request *lr = get_last_request(); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 1142 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1143 | if (!lr || lr->processed) |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 1144 | return false; |
| 1145 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1146 | return alpha2_equal(lr->alpha2, alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
Janusz Dziedzic | e3961af | 2014-01-25 11:24:11 +0100 | [diff] [blame] | 1149 | static const struct ieee80211_regdomain *reg_get_regdomain(struct wiphy *wiphy) |
| 1150 | { |
| 1151 | struct regulatory_request *lr = get_last_request(); |
| 1152 | |
| 1153 | /* |
| 1154 | * Follow the driver's regulatory domain, if present, unless a country |
| 1155 | * IE has been processed or a user wants to help complaince further |
| 1156 | */ |
| 1157 | if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && |
| 1158 | lr->initiator != NL80211_REGDOM_SET_BY_USER && |
| 1159 | wiphy->regd) |
| 1160 | return get_wiphy_regdom(wiphy); |
| 1161 | |
| 1162 | return get_cfg80211_regdom(); |
| 1163 | } |
| 1164 | |
Arik Nemtsov | a6d4a53 | 2014-10-23 09:37:33 +0300 | [diff] [blame] | 1165 | static unsigned int |
| 1166 | reg_get_max_bandwidth_from_range(const struct ieee80211_regdomain *rd, |
| 1167 | const struct ieee80211_reg_rule *rule) |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1168 | { |
| 1169 | const struct ieee80211_freq_range *freq_range = &rule->freq_range; |
| 1170 | const struct ieee80211_freq_range *freq_range_tmp; |
| 1171 | const struct ieee80211_reg_rule *tmp; |
| 1172 | u32 start_freq, end_freq, idx, no; |
| 1173 | |
| 1174 | for (idx = 0; idx < rd->n_reg_rules; idx++) |
| 1175 | if (rule == &rd->reg_rules[idx]) |
| 1176 | break; |
| 1177 | |
| 1178 | if (idx == rd->n_reg_rules) |
| 1179 | return 0; |
| 1180 | |
| 1181 | /* get start_freq */ |
| 1182 | no = idx; |
| 1183 | |
| 1184 | while (no) { |
| 1185 | tmp = &rd->reg_rules[--no]; |
| 1186 | freq_range_tmp = &tmp->freq_range; |
| 1187 | |
| 1188 | if (freq_range_tmp->end_freq_khz < freq_range->start_freq_khz) |
| 1189 | break; |
| 1190 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1191 | freq_range = freq_range_tmp; |
| 1192 | } |
| 1193 | |
| 1194 | start_freq = freq_range->start_freq_khz; |
| 1195 | |
| 1196 | /* get end_freq */ |
| 1197 | freq_range = &rule->freq_range; |
| 1198 | no = idx; |
| 1199 | |
| 1200 | while (no < rd->n_reg_rules - 1) { |
| 1201 | tmp = &rd->reg_rules[++no]; |
| 1202 | freq_range_tmp = &tmp->freq_range; |
| 1203 | |
| 1204 | if (freq_range_tmp->start_freq_khz > freq_range->end_freq_khz) |
| 1205 | break; |
| 1206 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1207 | freq_range = freq_range_tmp; |
| 1208 | } |
| 1209 | |
| 1210 | end_freq = freq_range->end_freq_khz; |
| 1211 | |
| 1212 | return end_freq - start_freq; |
| 1213 | } |
| 1214 | |
Arik Nemtsov | a6d4a53 | 2014-10-23 09:37:33 +0300 | [diff] [blame] | 1215 | unsigned int reg_get_max_bandwidth(const struct ieee80211_regdomain *rd, |
| 1216 | const struct ieee80211_reg_rule *rule) |
| 1217 | { |
| 1218 | unsigned int bw = reg_get_max_bandwidth_from_range(rd, rule); |
| 1219 | |
| 1220 | if (rule->flags & NL80211_RRF_NO_160MHZ) |
| 1221 | bw = min_t(unsigned int, bw, MHZ_TO_KHZ(80)); |
| 1222 | if (rule->flags & NL80211_RRF_NO_80MHZ) |
| 1223 | bw = min_t(unsigned int, bw, MHZ_TO_KHZ(40)); |
| 1224 | |
| 1225 | /* |
| 1226 | * HT40+/HT40- limits are handled per-channel. Only limit BW if both |
| 1227 | * are not allowed. |
| 1228 | */ |
| 1229 | if (rule->flags & NL80211_RRF_NO_HT40MINUS && |
| 1230 | rule->flags & NL80211_RRF_NO_HT40PLUS) |
| 1231 | bw = min_t(unsigned int, bw, MHZ_TO_KHZ(20)); |
| 1232 | |
| 1233 | return bw; |
| 1234 | } |
| 1235 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1236 | /* Sanity check on a regulatory rule */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1237 | 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] | 1238 | { |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1239 | const struct ieee80211_freq_range *freq_range = &rule->freq_range; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1240 | u32 freq_diff; |
| 1241 | |
Luis R. Rodriguez | 91e9900 | 2008-11-12 14:21:55 -0800 | [diff] [blame] | 1242 | 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] | 1243 | return false; |
| 1244 | |
| 1245 | if (freq_range->start_freq_khz > freq_range->end_freq_khz) |
| 1246 | return false; |
| 1247 | |
| 1248 | freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; |
| 1249 | |
Roel Kluin | bd05f28 | 2009-03-03 22:55:21 +0100 | [diff] [blame] | 1250 | if (freq_range->end_freq_khz <= freq_range->start_freq_khz || |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1251 | freq_range->max_bandwidth_khz > freq_diff) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1252 | return false; |
| 1253 | |
| 1254 | return true; |
| 1255 | } |
| 1256 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1257 | static bool is_valid_rd(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1258 | { |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1259 | const struct ieee80211_reg_rule *reg_rule = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1260 | unsigned int i; |
| 1261 | |
| 1262 | if (!rd->n_reg_rules) |
| 1263 | return false; |
| 1264 | |
Luis R. Rodriguez | 88dc1c3 | 2008-11-12 14:22:01 -0800 | [diff] [blame] | 1265 | if (WARN_ON(rd->n_reg_rules > NL80211_MAX_SUPP_REG_RULES)) |
| 1266 | return false; |
| 1267 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1268 | for (i = 0; i < rd->n_reg_rules; i++) { |
| 1269 | reg_rule = &rd->reg_rules[i]; |
| 1270 | if (!is_valid_reg_rule(reg_rule)) |
| 1271 | return false; |
| 1272 | } |
| 1273 | |
| 1274 | return true; |
| 1275 | } |
| 1276 | |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 1277 | /** |
| 1278 | * freq_in_rule_band - tells us if a frequency is in a frequency band |
| 1279 | * @freq_range: frequency rule we want to query |
| 1280 | * @freq_khz: frequency we are inquiring about |
| 1281 | * |
| 1282 | * This lets us know if a specific frequency rule is or is not relevant to |
| 1283 | * a specific frequency's band. Bands are device specific and artificial |
Vladimir Kondratiev | 64629b9 | 2012-09-23 09:49:54 +0200 | [diff] [blame] | 1284 | * definitions (the "2.4 GHz band", the "5 GHz band" and the "60GHz band"), |
| 1285 | * however it is safe for now to assume that a frequency rule should not be |
| 1286 | * part of a frequency's band if the start freq or end freq are off by more |
Chaitanya Tata | 93183bd | 2019-01-19 03:17:47 +0530 | [diff] [blame] | 1287 | * than 2 GHz for the 2.4 and 5 GHz bands, and by more than 20 GHz for the |
Vladimir Kondratiev | 64629b9 | 2012-09-23 09:49:54 +0200 | [diff] [blame] | 1288 | * 60 GHz band. |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 1289 | * This resolution can be lowered and should be considered as we add |
| 1290 | * regulatory rule support for other "bands". |
| 1291 | **/ |
| 1292 | 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] | 1293 | u32 freq_khz) |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 1294 | { |
| 1295 | #define ONE_GHZ_IN_KHZ 1000000 |
Vladimir Kondratiev | 64629b9 | 2012-09-23 09:49:54 +0200 | [diff] [blame] | 1296 | /* |
| 1297 | * From 802.11ad: directional multi-gigabit (DMG): |
| 1298 | * Pertaining to operation in a frequency band containing a channel |
| 1299 | * with the Channel starting frequency above 45 GHz. |
| 1300 | */ |
| 1301 | u32 limit = freq_khz > 45 * ONE_GHZ_IN_KHZ ? |
Chaitanya Tata | 93183bd | 2019-01-19 03:17:47 +0530 | [diff] [blame] | 1302 | 20 * ONE_GHZ_IN_KHZ : 2 * ONE_GHZ_IN_KHZ; |
Vladimir Kondratiev | 64629b9 | 2012-09-23 09:49:54 +0200 | [diff] [blame] | 1303 | if (abs(freq_khz - freq_range->start_freq_khz) <= limit) |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 1304 | return true; |
Vladimir Kondratiev | 64629b9 | 2012-09-23 09:49:54 +0200 | [diff] [blame] | 1305 | if (abs(freq_khz - freq_range->end_freq_khz) <= limit) |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 1306 | return true; |
| 1307 | return false; |
| 1308 | #undef ONE_GHZ_IN_KHZ |
| 1309 | } |
| 1310 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1311 | /* |
Luis R. Rodriguez | adbfb05 | 2013-11-13 18:54:03 +0100 | [diff] [blame] | 1312 | * Later on we can perhaps use the more restrictive DFS |
| 1313 | * region but we don't have information for that yet so |
| 1314 | * for now simply disallow conflicts. |
| 1315 | */ |
| 1316 | static enum nl80211_dfs_regions |
| 1317 | reg_intersect_dfs_region(const enum nl80211_dfs_regions dfs_region1, |
| 1318 | const enum nl80211_dfs_regions dfs_region2) |
| 1319 | { |
| 1320 | if (dfs_region1 != dfs_region2) |
| 1321 | return NL80211_DFS_UNSET; |
| 1322 | return dfs_region1; |
| 1323 | } |
| 1324 | |
Ilan Peer | 08a75a8 | 2019-03-15 17:39:00 +0200 | [diff] [blame] | 1325 | static void reg_wmm_rules_intersect(const struct ieee80211_wmm_ac *wmm_ac1, |
| 1326 | const struct ieee80211_wmm_ac *wmm_ac2, |
| 1327 | struct ieee80211_wmm_ac *intersect) |
| 1328 | { |
| 1329 | intersect->cw_min = max_t(u16, wmm_ac1->cw_min, wmm_ac2->cw_min); |
| 1330 | intersect->cw_max = max_t(u16, wmm_ac1->cw_max, wmm_ac2->cw_max); |
| 1331 | intersect->cot = min_t(u16, wmm_ac1->cot, wmm_ac2->cot); |
| 1332 | intersect->aifsn = max_t(u8, wmm_ac1->aifsn, wmm_ac2->aifsn); |
| 1333 | } |
| 1334 | |
Luis R. Rodriguez | adbfb05 | 2013-11-13 18:54:03 +0100 | [diff] [blame] | 1335 | /* |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1336 | * Helper for regdom_intersect(), this does the real |
| 1337 | * mathematical intersection fun |
| 1338 | */ |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1339 | static int reg_rules_intersect(const struct ieee80211_regdomain *rd1, |
| 1340 | const struct ieee80211_regdomain *rd2, |
| 1341 | const struct ieee80211_reg_rule *rule1, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1342 | const struct ieee80211_reg_rule *rule2, |
| 1343 | struct ieee80211_reg_rule *intersected_rule) |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1344 | { |
| 1345 | const struct ieee80211_freq_range *freq_range1, *freq_range2; |
| 1346 | struct ieee80211_freq_range *freq_range; |
| 1347 | const struct ieee80211_power_rule *power_rule1, *power_rule2; |
| 1348 | struct ieee80211_power_rule *power_rule; |
Ilan Peer | 08a75a8 | 2019-03-15 17:39:00 +0200 | [diff] [blame] | 1349 | const struct ieee80211_wmm_rule *wmm_rule1, *wmm_rule2; |
| 1350 | struct ieee80211_wmm_rule *wmm_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1351 | u32 freq_diff, max_bandwidth1, max_bandwidth2; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1352 | |
| 1353 | freq_range1 = &rule1->freq_range; |
| 1354 | freq_range2 = &rule2->freq_range; |
| 1355 | freq_range = &intersected_rule->freq_range; |
| 1356 | |
| 1357 | power_rule1 = &rule1->power_rule; |
| 1358 | power_rule2 = &rule2->power_rule; |
| 1359 | power_rule = &intersected_rule->power_rule; |
| 1360 | |
Ilan Peer | 08a75a8 | 2019-03-15 17:39:00 +0200 | [diff] [blame] | 1361 | wmm_rule1 = &rule1->wmm_rule; |
| 1362 | wmm_rule2 = &rule2->wmm_rule; |
| 1363 | wmm_rule = &intersected_rule->wmm_rule; |
| 1364 | |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1365 | freq_range->start_freq_khz = max(freq_range1->start_freq_khz, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1366 | freq_range2->start_freq_khz); |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1367 | freq_range->end_freq_khz = min(freq_range1->end_freq_khz, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1368 | freq_range2->end_freq_khz); |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1369 | |
| 1370 | max_bandwidth1 = freq_range1->max_bandwidth_khz; |
| 1371 | max_bandwidth2 = freq_range2->max_bandwidth_khz; |
| 1372 | |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 1373 | if (rule1->flags & NL80211_RRF_AUTO_BW) |
| 1374 | max_bandwidth1 = reg_get_max_bandwidth(rd1, rule1); |
| 1375 | if (rule2->flags & NL80211_RRF_AUTO_BW) |
| 1376 | max_bandwidth2 = reg_get_max_bandwidth(rd2, rule2); |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1377 | |
| 1378 | freq_range->max_bandwidth_khz = min(max_bandwidth1, max_bandwidth2); |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1379 | |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 1380 | intersected_rule->flags = rule1->flags | rule2->flags; |
| 1381 | |
| 1382 | /* |
| 1383 | * In case NL80211_RRF_AUTO_BW requested for both rules |
| 1384 | * set AUTO_BW in intersected rule also. Next we will |
| 1385 | * calculate BW correctly in handle_channel function. |
| 1386 | * In other case remove AUTO_BW flag while we calculate |
| 1387 | * maximum bandwidth correctly and auto calculation is |
| 1388 | * not required. |
| 1389 | */ |
| 1390 | if ((rule1->flags & NL80211_RRF_AUTO_BW) && |
| 1391 | (rule2->flags & NL80211_RRF_AUTO_BW)) |
| 1392 | intersected_rule->flags |= NL80211_RRF_AUTO_BW; |
| 1393 | else |
| 1394 | intersected_rule->flags &= ~NL80211_RRF_AUTO_BW; |
| 1395 | |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1396 | freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; |
| 1397 | if (freq_range->max_bandwidth_khz > freq_diff) |
| 1398 | freq_range->max_bandwidth_khz = freq_diff; |
| 1399 | |
| 1400 | power_rule->max_eirp = min(power_rule1->max_eirp, |
| 1401 | power_rule2->max_eirp); |
| 1402 | power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain, |
| 1403 | power_rule2->max_antenna_gain); |
| 1404 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 1405 | intersected_rule->dfs_cac_ms = max(rule1->dfs_cac_ms, |
| 1406 | rule2->dfs_cac_ms); |
| 1407 | |
Ilan Peer | 08a75a8 | 2019-03-15 17:39:00 +0200 | [diff] [blame] | 1408 | if (rule1->has_wmm && rule2->has_wmm) { |
| 1409 | u8 ac; |
| 1410 | |
| 1411 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 1412 | reg_wmm_rules_intersect(&wmm_rule1->client[ac], |
| 1413 | &wmm_rule2->client[ac], |
| 1414 | &wmm_rule->client[ac]); |
| 1415 | reg_wmm_rules_intersect(&wmm_rule1->ap[ac], |
| 1416 | &wmm_rule2->ap[ac], |
| 1417 | &wmm_rule->ap[ac]); |
| 1418 | } |
| 1419 | |
| 1420 | intersected_rule->has_wmm = true; |
| 1421 | } else if (rule1->has_wmm) { |
| 1422 | *wmm_rule = *wmm_rule1; |
| 1423 | intersected_rule->has_wmm = true; |
| 1424 | } else if (rule2->has_wmm) { |
| 1425 | *wmm_rule = *wmm_rule2; |
| 1426 | intersected_rule->has_wmm = true; |
| 1427 | } else { |
| 1428 | intersected_rule->has_wmm = false; |
| 1429 | } |
| 1430 | |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1431 | if (!is_valid_reg_rule(intersected_rule)) |
| 1432 | return -EINVAL; |
| 1433 | |
| 1434 | return 0; |
| 1435 | } |
| 1436 | |
Eliad Peller | a62a1ae | 2014-09-03 15:25:03 +0300 | [diff] [blame] | 1437 | /* check whether old rule contains new rule */ |
| 1438 | static bool rule_contains(struct ieee80211_reg_rule *r1, |
| 1439 | struct ieee80211_reg_rule *r2) |
| 1440 | { |
| 1441 | /* for simplicity, currently consider only same flags */ |
| 1442 | if (r1->flags != r2->flags) |
| 1443 | return false; |
| 1444 | |
| 1445 | /* verify r1 is more restrictive */ |
| 1446 | if ((r1->power_rule.max_antenna_gain > |
| 1447 | r2->power_rule.max_antenna_gain) || |
| 1448 | r1->power_rule.max_eirp > r2->power_rule.max_eirp) |
| 1449 | return false; |
| 1450 | |
| 1451 | /* make sure r2's range is contained within r1 */ |
| 1452 | if (r1->freq_range.start_freq_khz > r2->freq_range.start_freq_khz || |
| 1453 | r1->freq_range.end_freq_khz < r2->freq_range.end_freq_khz) |
| 1454 | return false; |
| 1455 | |
| 1456 | /* and finally verify that r1.max_bw >= r2.max_bw */ |
| 1457 | if (r1->freq_range.max_bandwidth_khz < |
| 1458 | r2->freq_range.max_bandwidth_khz) |
| 1459 | return false; |
| 1460 | |
| 1461 | return true; |
| 1462 | } |
| 1463 | |
| 1464 | /* add or extend current rules. do nothing if rule is already contained */ |
| 1465 | static void add_rule(struct ieee80211_reg_rule *rule, |
| 1466 | struct ieee80211_reg_rule *reg_rules, u32 *n_rules) |
| 1467 | { |
| 1468 | struct ieee80211_reg_rule *tmp_rule; |
| 1469 | int i; |
| 1470 | |
| 1471 | for (i = 0; i < *n_rules; i++) { |
| 1472 | tmp_rule = ®_rules[i]; |
| 1473 | /* rule is already contained - do nothing */ |
| 1474 | if (rule_contains(tmp_rule, rule)) |
| 1475 | return; |
| 1476 | |
| 1477 | /* extend rule if possible */ |
| 1478 | if (rule_contains(rule, tmp_rule)) { |
| 1479 | memcpy(tmp_rule, rule, sizeof(*rule)); |
| 1480 | return; |
| 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | memcpy(®_rules[*n_rules], rule, sizeof(*rule)); |
| 1485 | (*n_rules)++; |
| 1486 | } |
| 1487 | |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1488 | /** |
| 1489 | * regdom_intersect - do the intersection between two regulatory domains |
| 1490 | * @rd1: first regulatory domain |
| 1491 | * @rd2: second regulatory domain |
| 1492 | * |
| 1493 | * Use this function to get the intersection between two regulatory domains. |
| 1494 | * Once completed we will mark the alpha2 for the rd as intersected, "98", |
| 1495 | * as no one single alpha2 can represent this regulatory domain. |
| 1496 | * |
| 1497 | * Returns a pointer to the regulatory domain structure which will hold the |
| 1498 | * resulting intersection of rules between rd1 and rd2. We will |
| 1499 | * kzalloc() this structure for you. |
| 1500 | */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1501 | static struct ieee80211_regdomain * |
| 1502 | regdom_intersect(const struct ieee80211_regdomain *rd1, |
| 1503 | const struct ieee80211_regdomain *rd2) |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1504 | { |
Gustavo A. R. Silva | 9f8c713 | 2019-04-03 10:31:51 -0500 | [diff] [blame] | 1505 | int r; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1506 | unsigned int x, y; |
Eliad Peller | a62a1ae | 2014-09-03 15:25:03 +0300 | [diff] [blame] | 1507 | unsigned int num_rules = 0; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1508 | const struct ieee80211_reg_rule *rule1, *rule2; |
Eliad Peller | a62a1ae | 2014-09-03 15:25:03 +0300 | [diff] [blame] | 1509 | struct ieee80211_reg_rule intersected_rule; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1510 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1511 | |
| 1512 | if (!rd1 || !rd2) |
| 1513 | return NULL; |
| 1514 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1515 | /* |
| 1516 | * 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] | 1517 | * build them. This is to so we can malloc() and free() a |
| 1518 | * regdomain once. The reason we use reg_rules_intersect() here |
| 1519 | * 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] | 1520 | * All rules that do check out OK are valid. |
| 1521 | */ |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1522 | |
| 1523 | for (x = 0; x < rd1->n_reg_rules; x++) { |
| 1524 | rule1 = &rd1->reg_rules[x]; |
| 1525 | for (y = 0; y < rd2->n_reg_rules; y++) { |
| 1526 | rule2 = &rd2->reg_rules[y]; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1527 | if (!reg_rules_intersect(rd1, rd2, rule1, rule2, |
Eliad Peller | a62a1ae | 2014-09-03 15:25:03 +0300 | [diff] [blame] | 1528 | &intersected_rule)) |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1529 | num_rules++; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | if (!num_rules) |
| 1534 | return NULL; |
| 1535 | |
Gustavo A. R. Silva | 9f8c713 | 2019-04-03 10:31:51 -0500 | [diff] [blame] | 1536 | rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1537 | if (!rd) |
| 1538 | return NULL; |
| 1539 | |
Eliad Peller | a62a1ae | 2014-09-03 15:25:03 +0300 | [diff] [blame] | 1540 | for (x = 0; x < rd1->n_reg_rules; x++) { |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1541 | rule1 = &rd1->reg_rules[x]; |
Eliad Peller | a62a1ae | 2014-09-03 15:25:03 +0300 | [diff] [blame] | 1542 | for (y = 0; y < rd2->n_reg_rules; y++) { |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1543 | rule2 = &rd2->reg_rules[y]; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1544 | r = reg_rules_intersect(rd1, rd2, rule1, rule2, |
Eliad Peller | a62a1ae | 2014-09-03 15:25:03 +0300 | [diff] [blame] | 1545 | &intersected_rule); |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1546 | /* |
| 1547 | * No need to memset here the intersected rule here as |
| 1548 | * we're not using the stack anymore |
| 1549 | */ |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1550 | if (r) |
| 1551 | continue; |
Eliad Peller | a62a1ae | 2014-09-03 15:25:03 +0300 | [diff] [blame] | 1552 | |
| 1553 | add_rule(&intersected_rule, rd->reg_rules, |
| 1554 | &rd->n_reg_rules); |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1555 | } |
| 1556 | } |
| 1557 | |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1558 | rd->alpha2[0] = '9'; |
| 1559 | rd->alpha2[1] = '8'; |
Luis R. Rodriguez | adbfb05 | 2013-11-13 18:54:03 +0100 | [diff] [blame] | 1560 | rd->dfs_region = reg_intersect_dfs_region(rd1->dfs_region, |
| 1561 | rd2->dfs_region); |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1562 | |
| 1563 | return rd; |
| 1564 | } |
| 1565 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1566 | /* |
| 1567 | * XXX: add support for the rest of enum nl80211_reg_rule_flags, we may |
| 1568 | * want to just have the channel structure use these |
| 1569 | */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1570 | static u32 map_regdom_flags(u32 rd_flags) |
| 1571 | { |
| 1572 | u32 channel_flags = 0; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 1573 | if (rd_flags & NL80211_RRF_NO_IR_ALL) |
| 1574 | channel_flags |= IEEE80211_CHAN_NO_IR; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1575 | if (rd_flags & NL80211_RRF_DFS) |
| 1576 | channel_flags |= IEEE80211_CHAN_RADAR; |
Seth Forshee | 03f6b08 | 2012-08-01 15:58:42 -0500 | [diff] [blame] | 1577 | if (rd_flags & NL80211_RRF_NO_OFDM) |
| 1578 | channel_flags |= IEEE80211_CHAN_NO_OFDM; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 1579 | if (rd_flags & NL80211_RRF_NO_OUTDOOR) |
| 1580 | channel_flags |= IEEE80211_CHAN_INDOOR_ONLY; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 1581 | if (rd_flags & NL80211_RRF_IR_CONCURRENT) |
| 1582 | channel_flags |= IEEE80211_CHAN_IR_CONCURRENT; |
Arik Nemtsov | a6d4a53 | 2014-10-23 09:37:33 +0300 | [diff] [blame] | 1583 | if (rd_flags & NL80211_RRF_NO_HT40MINUS) |
| 1584 | channel_flags |= IEEE80211_CHAN_NO_HT40MINUS; |
| 1585 | if (rd_flags & NL80211_RRF_NO_HT40PLUS) |
| 1586 | channel_flags |= IEEE80211_CHAN_NO_HT40PLUS; |
| 1587 | if (rd_flags & NL80211_RRF_NO_80MHZ) |
| 1588 | channel_flags |= IEEE80211_CHAN_NO_80MHZ; |
| 1589 | if (rd_flags & NL80211_RRF_NO_160MHZ) |
| 1590 | channel_flags |= IEEE80211_CHAN_NO_160MHZ; |
Haim Dreyfuss | 1e61d82 | 2020-01-21 10:12:13 +0200 | [diff] [blame] | 1591 | if (rd_flags & NL80211_RRF_NO_HE) |
| 1592 | channel_flags |= IEEE80211_CHAN_NO_HE; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1593 | return channel_flags; |
| 1594 | } |
| 1595 | |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 1596 | static const struct ieee80211_reg_rule * |
Michal Sojka | 4917287 | 2015-11-23 19:27:14 +0100 | [diff] [blame] | 1597 | freq_reg_info_regd(u32 center_freq, |
Matthias May | 4edd569 | 2015-07-17 15:28:39 +0200 | [diff] [blame] | 1598 | const struct ieee80211_regdomain *regd, u32 bw) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1599 | { |
| 1600 | int i; |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 1601 | bool band_rule_found = false; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1602 | bool bw_fits = false; |
| 1603 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1604 | if (!regd) |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 1605 | return ERR_PTR(-EINVAL); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1606 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1607 | for (i = 0; i < regd->n_reg_rules; i++) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1608 | const struct ieee80211_reg_rule *rr; |
| 1609 | const struct ieee80211_freq_range *fr = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1610 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1611 | rr = ®d->reg_rules[i]; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1612 | fr = &rr->freq_range; |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 1613 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1614 | /* |
| 1615 | * We only need to know if one frequency rule was |
Randy Dunlap | cc5a639b | 2020-08-22 16:19:50 -0700 | [diff] [blame] | 1616 | * in center_freq's band, that's enough, so let's |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1617 | * not overwrite it once found |
| 1618 | */ |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 1619 | if (!band_rule_found) |
| 1620 | band_rule_found = freq_in_rule_band(fr, center_freq); |
| 1621 | |
Rafał Miłecki | 4787cfa | 2017-01-04 18:58:30 +0100 | [diff] [blame] | 1622 | bw_fits = cfg80211_does_bw_fit_range(fr, center_freq, bw); |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 1623 | |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 1624 | if (band_rule_found && bw_fits) |
| 1625 | return rr; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1626 | } |
| 1627 | |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 1628 | if (!band_rule_found) |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 1629 | return ERR_PTR(-ERANGE); |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 1630 | |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 1631 | return ERR_PTR(-EINVAL); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
Johannes Berg | 8de1c63 | 2015-08-21 14:13:06 +0200 | [diff] [blame] | 1634 | static const struct ieee80211_reg_rule * |
| 1635 | __freq_reg_info(struct wiphy *wiphy, u32 center_freq, u32 min_bw) |
Matthias May | 4edd569 | 2015-07-17 15:28:39 +0200 | [diff] [blame] | 1636 | { |
| 1637 | const struct ieee80211_regdomain *regd = reg_get_regdomain(wiphy); |
Colin Ian King | c7ed0e6 | 2020-11-16 18:16:36 +0000 | [diff] [blame] | 1638 | static const u32 bws[] = {0, 1, 2, 4, 5, 8, 10, 16, 20}; |
Luca Coelho | 9e6d512 | 2021-02-04 15:44:39 +0200 | [diff] [blame] | 1639 | const struct ieee80211_reg_rule *reg_rule = ERR_PTR(-ERANGE); |
Thomas Pedersen | 68dbad8 | 2020-09-08 12:03:04 -0700 | [diff] [blame] | 1640 | int i = ARRAY_SIZE(bws) - 1; |
Matthias May | 4edd569 | 2015-07-17 15:28:39 +0200 | [diff] [blame] | 1641 | u32 bw; |
| 1642 | |
Thomas Pedersen | 68dbad8 | 2020-09-08 12:03:04 -0700 | [diff] [blame] | 1643 | for (bw = MHZ_TO_KHZ(bws[i]); bw >= min_bw; bw = MHZ_TO_KHZ(bws[i--])) { |
Michal Sojka | 4917287 | 2015-11-23 19:27:14 +0100 | [diff] [blame] | 1644 | reg_rule = freq_reg_info_regd(center_freq, regd, bw); |
Matthias May | 4edd569 | 2015-07-17 15:28:39 +0200 | [diff] [blame] | 1645 | if (!IS_ERR(reg_rule)) |
| 1646 | return reg_rule; |
| 1647 | } |
| 1648 | |
| 1649 | return reg_rule; |
| 1650 | } |
| 1651 | |
Johannes Berg | 361c9c8 | 2012-12-06 15:57:14 +0100 | [diff] [blame] | 1652 | const struct ieee80211_reg_rule *freq_reg_info(struct wiphy *wiphy, |
| 1653 | u32 center_freq) |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1654 | { |
Thomas Pedersen | 68dbad8 | 2020-09-08 12:03:04 -0700 | [diff] [blame] | 1655 | u32 min_bw = center_freq < MHZ_TO_KHZ(1000) ? 1 : 20; |
| 1656 | |
| 1657 | return __freq_reg_info(wiphy, center_freq, MHZ_TO_KHZ(min_bw)); |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 1658 | } |
John W. Linville | 4f366c5 | 2010-07-15 14:57:33 -0400 | [diff] [blame] | 1659 | EXPORT_SYMBOL(freq_reg_info); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1660 | |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 1661 | const char *reg_initiator_name(enum nl80211_reg_initiator initiator) |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 1662 | { |
| 1663 | switch (initiator) { |
| 1664 | case NL80211_REGDOM_SET_BY_CORE: |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 1665 | return "core"; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 1666 | case NL80211_REGDOM_SET_BY_USER: |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 1667 | return "user"; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 1668 | case NL80211_REGDOM_SET_BY_DRIVER: |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 1669 | return "driver"; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 1670 | case NL80211_REGDOM_SET_BY_COUNTRY_IE: |
Toke Høiland-Jørgensen | 8db0c433 | 2018-04-19 11:17:38 +0200 | [diff] [blame] | 1671 | return "country element"; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 1672 | default: |
| 1673 | WARN_ON(1); |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 1674 | return "bug"; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 1675 | } |
| 1676 | } |
Luis R. Rodriguez | 034c6d6 | 2013-10-14 17:42:06 -0700 | [diff] [blame] | 1677 | EXPORT_SYMBOL(reg_initiator_name); |
Luis R. Rodriguez | e702d3c | 2010-10-21 19:17:04 +0530 | [diff] [blame] | 1678 | |
Michal Sojka | 1aeb135 | 2015-11-23 19:27:16 +0100 | [diff] [blame] | 1679 | static uint32_t reg_rule_to_chan_bw_flags(const struct ieee80211_regdomain *regd, |
| 1680 | const struct ieee80211_reg_rule *reg_rule, |
| 1681 | const struct ieee80211_channel *chan) |
| 1682 | { |
| 1683 | const struct ieee80211_freq_range *freq_range = NULL; |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 1684 | u32 max_bandwidth_khz, center_freq_khz, bw_flags = 0; |
Thomas Pedersen | 68dbad8 | 2020-09-08 12:03:04 -0700 | [diff] [blame] | 1685 | bool is_s1g = chan->band == NL80211_BAND_S1GHZ; |
Michal Sojka | 1aeb135 | 2015-11-23 19:27:16 +0100 | [diff] [blame] | 1686 | |
| 1687 | freq_range = ®_rule->freq_range; |
| 1688 | |
| 1689 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 1690 | center_freq_khz = ieee80211_channel_to_khz(chan); |
Michal Sojka | 1aeb135 | 2015-11-23 19:27:16 +0100 | [diff] [blame] | 1691 | /* Check if auto calculation requested */ |
| 1692 | if (reg_rule->flags & NL80211_RRF_AUTO_BW) |
| 1693 | max_bandwidth_khz = reg_get_max_bandwidth(regd, reg_rule); |
| 1694 | |
| 1695 | /* If we get a reg_rule we can assume that at least 5Mhz fit */ |
Rafał Miłecki | 4787cfa | 2017-01-04 18:58:30 +0100 | [diff] [blame] | 1696 | if (!cfg80211_does_bw_fit_range(freq_range, |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 1697 | center_freq_khz, |
Rafał Miłecki | 4787cfa | 2017-01-04 18:58:30 +0100 | [diff] [blame] | 1698 | MHZ_TO_KHZ(10))) |
Michal Sojka | 1aeb135 | 2015-11-23 19:27:16 +0100 | [diff] [blame] | 1699 | bw_flags |= IEEE80211_CHAN_NO_10MHZ; |
Rafał Miłecki | 4787cfa | 2017-01-04 18:58:30 +0100 | [diff] [blame] | 1700 | if (!cfg80211_does_bw_fit_range(freq_range, |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 1701 | center_freq_khz, |
Rafał Miłecki | 4787cfa | 2017-01-04 18:58:30 +0100 | [diff] [blame] | 1702 | MHZ_TO_KHZ(20))) |
Michal Sojka | 1aeb135 | 2015-11-23 19:27:16 +0100 | [diff] [blame] | 1703 | bw_flags |= IEEE80211_CHAN_NO_20MHZ; |
| 1704 | |
Thomas Pedersen | 68dbad8 | 2020-09-08 12:03:04 -0700 | [diff] [blame] | 1705 | if (is_s1g) { |
| 1706 | /* S1G is strict about non overlapping channels. We can |
| 1707 | * calculate which bandwidth is allowed per channel by finding |
| 1708 | * the largest bandwidth which cleanly divides the freq_range. |
| 1709 | */ |
| 1710 | int edge_offset; |
| 1711 | int ch_bw = max_bandwidth_khz; |
| 1712 | |
| 1713 | while (ch_bw) { |
| 1714 | edge_offset = (center_freq_khz - ch_bw / 2) - |
| 1715 | freq_range->start_freq_khz; |
| 1716 | if (edge_offset % ch_bw == 0) { |
| 1717 | switch (KHZ_TO_MHZ(ch_bw)) { |
| 1718 | case 1: |
| 1719 | bw_flags |= IEEE80211_CHAN_1MHZ; |
| 1720 | break; |
| 1721 | case 2: |
| 1722 | bw_flags |= IEEE80211_CHAN_2MHZ; |
| 1723 | break; |
| 1724 | case 4: |
| 1725 | bw_flags |= IEEE80211_CHAN_4MHZ; |
| 1726 | break; |
| 1727 | case 8: |
| 1728 | bw_flags |= IEEE80211_CHAN_8MHZ; |
| 1729 | break; |
| 1730 | case 16: |
| 1731 | bw_flags |= IEEE80211_CHAN_16MHZ; |
| 1732 | break; |
| 1733 | default: |
| 1734 | /* If we got here, no bandwidths fit on |
| 1735 | * this frequency, ie. band edge. |
| 1736 | */ |
| 1737 | bw_flags |= IEEE80211_CHAN_DISABLED; |
| 1738 | break; |
| 1739 | } |
| 1740 | break; |
| 1741 | } |
| 1742 | ch_bw /= 2; |
| 1743 | } |
| 1744 | } else { |
| 1745 | if (max_bandwidth_khz < MHZ_TO_KHZ(10)) |
| 1746 | bw_flags |= IEEE80211_CHAN_NO_10MHZ; |
| 1747 | if (max_bandwidth_khz < MHZ_TO_KHZ(20)) |
| 1748 | bw_flags |= IEEE80211_CHAN_NO_20MHZ; |
| 1749 | if (max_bandwidth_khz < MHZ_TO_KHZ(40)) |
| 1750 | bw_flags |= IEEE80211_CHAN_NO_HT40; |
| 1751 | if (max_bandwidth_khz < MHZ_TO_KHZ(80)) |
| 1752 | bw_flags |= IEEE80211_CHAN_NO_80MHZ; |
| 1753 | if (max_bandwidth_khz < MHZ_TO_KHZ(160)) |
| 1754 | bw_flags |= IEEE80211_CHAN_NO_160MHZ; |
| 1755 | } |
Michal Sojka | 1aeb135 | 2015-11-23 19:27:16 +0100 | [diff] [blame] | 1756 | return bw_flags; |
| 1757 | } |
| 1758 | |
Markus Theil | 7c9ff7e | 2020-08-03 16:43:52 +0200 | [diff] [blame] | 1759 | static void handle_channel_single_rule(struct wiphy *wiphy, |
| 1760 | enum nl80211_reg_initiator initiator, |
| 1761 | struct ieee80211_channel *chan, |
| 1762 | u32 flags, |
| 1763 | struct regulatory_request *lr, |
| 1764 | struct wiphy *request_wiphy, |
| 1765 | const struct ieee80211_reg_rule *reg_rule) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1766 | { |
Markus Theil | 7c9ff7e | 2020-08-03 16:43:52 +0200 | [diff] [blame] | 1767 | u32 bw_flags = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1768 | const struct ieee80211_power_rule *power_rule = NULL; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 1769 | const struct ieee80211_regdomain *regd; |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 1770 | |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 1771 | regd = reg_get_regdomain(wiphy); |
Luis R. Rodriguez | e702d3c | 2010-10-21 19:17:04 +0530 | [diff] [blame] | 1772 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1773 | power_rule = ®_rule->power_rule; |
Michal Sojka | 1aeb135 | 2015-11-23 19:27:16 +0100 | [diff] [blame] | 1774 | bw_flags = reg_rule_to_chan_bw_flags(regd, reg_rule, chan); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1775 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 1776 | if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1777 | request_wiphy && request_wiphy == wiphy && |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 1778 | request_wiphy->regulatory_flags & REGULATORY_STRICT_REG) { |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1779 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1780 | * This guarantees the driver's requested regulatory domain |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 1781 | * will always be used as a base for further regulatory |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 1782 | * settings |
| 1783 | */ |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 1784 | chan->flags = chan->orig_flags = |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1785 | map_regdom_flags(reg_rule->flags) | bw_flags; |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 1786 | chan->max_antenna_gain = chan->orig_mag = |
| 1787 | (int) MBI_TO_DBI(power_rule->max_antenna_gain); |
Felix Fietkau | 279f0f5 | 2012-10-17 13:56:20 +0200 | [diff] [blame] | 1788 | chan->max_reg_power = chan->max_power = chan->orig_mpwr = |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 1789 | (int) MBM_TO_DBM(power_rule->max_eirp); |
Janusz Dziedzic | 4f267c1 | 2014-04-09 13:47:12 +0200 | [diff] [blame] | 1790 | |
| 1791 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 1792 | chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 1793 | if (reg_rule->dfs_cac_ms) |
| 1794 | chan->dfs_cac_ms = reg_rule->dfs_cac_ms; |
| 1795 | } |
| 1796 | |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 1797 | return; |
| 1798 | } |
| 1799 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 1800 | chan->dfs_state = NL80211_DFS_USABLE; |
| 1801 | chan->dfs_state_entered = jiffies; |
| 1802 | |
Rajkumar Manoharan | aa3d7ee | 2011-09-14 14:28:17 +0530 | [diff] [blame] | 1803 | chan->beacon_found = false; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 1804 | chan->flags = flags | bw_flags | map_regdom_flags(reg_rule->flags); |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 1805 | chan->max_antenna_gain = |
| 1806 | min_t(int, chan->orig_mag, |
| 1807 | MBI_TO_DBI(power_rule->max_antenna_gain)); |
Hong Wu | eccc068 | 2012-01-11 20:33:39 +0200 | [diff] [blame] | 1808 | chan->max_reg_power = (int) MBM_TO_DBM(power_rule->max_eirp); |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 1809 | |
| 1810 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 1811 | if (reg_rule->dfs_cac_ms) |
| 1812 | chan->dfs_cac_ms = reg_rule->dfs_cac_ms; |
| 1813 | else |
| 1814 | chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 1815 | } |
| 1816 | |
Stanislaw Gruszka | 5e31fc0 | 2012-07-24 08:35:39 +0200 | [diff] [blame] | 1817 | if (chan->orig_mpwr) { |
| 1818 | /* |
Luis R. Rodriguez | a09a85a | 2013-11-11 22:15:30 +0100 | [diff] [blame] | 1819 | * Devices that use REGULATORY_COUNTRY_IE_FOLLOW_POWER |
| 1820 | * will always follow the passed country IE power settings. |
Stanislaw Gruszka | 5e31fc0 | 2012-07-24 08:35:39 +0200 | [diff] [blame] | 1821 | */ |
| 1822 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && |
Luis R. Rodriguez | a09a85a | 2013-11-11 22:15:30 +0100 | [diff] [blame] | 1823 | wiphy->regulatory_flags & REGULATORY_COUNTRY_IE_FOLLOW_POWER) |
Stanislaw Gruszka | 5e31fc0 | 2012-07-24 08:35:39 +0200 | [diff] [blame] | 1824 | chan->max_power = chan->max_reg_power; |
| 1825 | else |
| 1826 | chan->max_power = min(chan->orig_mpwr, |
| 1827 | chan->max_reg_power); |
| 1828 | } else |
| 1829 | chan->max_power = chan->max_reg_power; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1830 | } |
| 1831 | |
Markus Theil | 12adee3 | 2020-08-03 16:43:53 +0200 | [diff] [blame] | 1832 | static void handle_channel_adjacent_rules(struct wiphy *wiphy, |
| 1833 | enum nl80211_reg_initiator initiator, |
| 1834 | struct ieee80211_channel *chan, |
| 1835 | u32 flags, |
| 1836 | struct regulatory_request *lr, |
| 1837 | struct wiphy *request_wiphy, |
| 1838 | const struct ieee80211_reg_rule *rrule1, |
| 1839 | const struct ieee80211_reg_rule *rrule2, |
| 1840 | struct ieee80211_freq_range *comb_range) |
| 1841 | { |
| 1842 | u32 bw_flags1 = 0; |
| 1843 | u32 bw_flags2 = 0; |
| 1844 | const struct ieee80211_power_rule *power_rule1 = NULL; |
| 1845 | const struct ieee80211_power_rule *power_rule2 = NULL; |
| 1846 | const struct ieee80211_regdomain *regd; |
| 1847 | |
| 1848 | regd = reg_get_regdomain(wiphy); |
| 1849 | |
| 1850 | power_rule1 = &rrule1->power_rule; |
| 1851 | power_rule2 = &rrule2->power_rule; |
| 1852 | bw_flags1 = reg_rule_to_chan_bw_flags(regd, rrule1, chan); |
| 1853 | bw_flags2 = reg_rule_to_chan_bw_flags(regd, rrule2, chan); |
| 1854 | |
| 1855 | if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && |
| 1856 | request_wiphy && request_wiphy == wiphy && |
| 1857 | request_wiphy->regulatory_flags & REGULATORY_STRICT_REG) { |
| 1858 | /* This guarantees the driver's requested regulatory domain |
| 1859 | * will always be used as a base for further regulatory |
| 1860 | * settings |
| 1861 | */ |
| 1862 | chan->flags = |
| 1863 | map_regdom_flags(rrule1->flags) | |
| 1864 | map_regdom_flags(rrule2->flags) | |
| 1865 | bw_flags1 | |
| 1866 | bw_flags2; |
| 1867 | chan->orig_flags = chan->flags; |
| 1868 | chan->max_antenna_gain = |
| 1869 | min_t(int, MBI_TO_DBI(power_rule1->max_antenna_gain), |
| 1870 | MBI_TO_DBI(power_rule2->max_antenna_gain)); |
| 1871 | chan->orig_mag = chan->max_antenna_gain; |
| 1872 | chan->max_reg_power = |
| 1873 | min_t(int, MBM_TO_DBM(power_rule1->max_eirp), |
| 1874 | MBM_TO_DBM(power_rule2->max_eirp)); |
| 1875 | chan->max_power = chan->max_reg_power; |
| 1876 | chan->orig_mpwr = chan->max_reg_power; |
| 1877 | |
| 1878 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 1879 | chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 1880 | if (rrule1->dfs_cac_ms || rrule2->dfs_cac_ms) |
| 1881 | chan->dfs_cac_ms = max_t(unsigned int, |
| 1882 | rrule1->dfs_cac_ms, |
| 1883 | rrule2->dfs_cac_ms); |
| 1884 | } |
| 1885 | |
| 1886 | return; |
| 1887 | } |
| 1888 | |
| 1889 | chan->dfs_state = NL80211_DFS_USABLE; |
| 1890 | chan->dfs_state_entered = jiffies; |
| 1891 | |
| 1892 | chan->beacon_found = false; |
| 1893 | chan->flags = flags | bw_flags1 | bw_flags2 | |
| 1894 | map_regdom_flags(rrule1->flags) | |
| 1895 | map_regdom_flags(rrule2->flags); |
| 1896 | |
| 1897 | /* reg_rule_to_chan_bw_flags may forbids 10 and forbids 20 MHz |
| 1898 | * (otherwise no adj. rule case), recheck therefore |
| 1899 | */ |
| 1900 | if (cfg80211_does_bw_fit_range(comb_range, |
| 1901 | ieee80211_channel_to_khz(chan), |
| 1902 | MHZ_TO_KHZ(10))) |
| 1903 | chan->flags &= ~IEEE80211_CHAN_NO_10MHZ; |
| 1904 | if (cfg80211_does_bw_fit_range(comb_range, |
| 1905 | ieee80211_channel_to_khz(chan), |
| 1906 | MHZ_TO_KHZ(20))) |
| 1907 | chan->flags &= ~IEEE80211_CHAN_NO_20MHZ; |
| 1908 | |
| 1909 | chan->max_antenna_gain = |
| 1910 | min_t(int, chan->orig_mag, |
| 1911 | min_t(int, |
| 1912 | MBI_TO_DBI(power_rule1->max_antenna_gain), |
| 1913 | MBI_TO_DBI(power_rule2->max_antenna_gain))); |
| 1914 | chan->max_reg_power = min_t(int, |
| 1915 | MBM_TO_DBM(power_rule1->max_eirp), |
| 1916 | MBM_TO_DBM(power_rule2->max_eirp)); |
| 1917 | |
| 1918 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 1919 | if (rrule1->dfs_cac_ms || rrule2->dfs_cac_ms) |
| 1920 | chan->dfs_cac_ms = max_t(unsigned int, |
| 1921 | rrule1->dfs_cac_ms, |
| 1922 | rrule2->dfs_cac_ms); |
| 1923 | else |
| 1924 | chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 1925 | } |
| 1926 | |
| 1927 | if (chan->orig_mpwr) { |
| 1928 | /* Devices that use REGULATORY_COUNTRY_IE_FOLLOW_POWER |
| 1929 | * will always follow the passed country IE power settings. |
| 1930 | */ |
| 1931 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && |
| 1932 | wiphy->regulatory_flags & REGULATORY_COUNTRY_IE_FOLLOW_POWER) |
| 1933 | chan->max_power = chan->max_reg_power; |
| 1934 | else |
| 1935 | chan->max_power = min(chan->orig_mpwr, |
| 1936 | chan->max_reg_power); |
| 1937 | } else { |
| 1938 | chan->max_power = chan->max_reg_power; |
| 1939 | } |
| 1940 | } |
| 1941 | |
Markus Theil | 7c9ff7e | 2020-08-03 16:43:52 +0200 | [diff] [blame] | 1942 | /* Note that right now we assume the desired channel bandwidth |
| 1943 | * is always 20 MHz for each individual channel (HT40 uses 20 MHz |
| 1944 | * per channel, the primary and the extension channel). |
| 1945 | */ |
| 1946 | static void handle_channel(struct wiphy *wiphy, |
| 1947 | enum nl80211_reg_initiator initiator, |
| 1948 | struct ieee80211_channel *chan) |
| 1949 | { |
Markus Theil | 12adee3 | 2020-08-03 16:43:53 +0200 | [diff] [blame] | 1950 | const u32 orig_chan_freq = ieee80211_channel_to_khz(chan); |
Markus Theil | 7c9ff7e | 2020-08-03 16:43:52 +0200 | [diff] [blame] | 1951 | struct regulatory_request *lr = get_last_request(); |
Markus Theil | 12adee3 | 2020-08-03 16:43:53 +0200 | [diff] [blame] | 1952 | struct wiphy *request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); |
| 1953 | const struct ieee80211_reg_rule *rrule = NULL; |
| 1954 | const struct ieee80211_reg_rule *rrule1 = NULL; |
| 1955 | const struct ieee80211_reg_rule *rrule2 = NULL; |
Markus Theil | 7c9ff7e | 2020-08-03 16:43:52 +0200 | [diff] [blame] | 1956 | |
Markus Theil | 12adee3 | 2020-08-03 16:43:53 +0200 | [diff] [blame] | 1957 | u32 flags = chan->orig_flags; |
Markus Theil | 7c9ff7e | 2020-08-03 16:43:52 +0200 | [diff] [blame] | 1958 | |
Markus Theil | 12adee3 | 2020-08-03 16:43:53 +0200 | [diff] [blame] | 1959 | rrule = freq_reg_info(wiphy, orig_chan_freq); |
| 1960 | if (IS_ERR(rrule)) { |
| 1961 | /* check for adjacent match, therefore get rules for |
| 1962 | * chan - 20 MHz and chan + 20 MHz and test |
| 1963 | * if reg rules are adjacent |
| 1964 | */ |
| 1965 | rrule1 = freq_reg_info(wiphy, |
| 1966 | orig_chan_freq - MHZ_TO_KHZ(20)); |
| 1967 | rrule2 = freq_reg_info(wiphy, |
| 1968 | orig_chan_freq + MHZ_TO_KHZ(20)); |
| 1969 | if (!IS_ERR(rrule1) && !IS_ERR(rrule2)) { |
| 1970 | struct ieee80211_freq_range comb_range; |
Markus Theil | 7c9ff7e | 2020-08-03 16:43:52 +0200 | [diff] [blame] | 1971 | |
Markus Theil | 12adee3 | 2020-08-03 16:43:53 +0200 | [diff] [blame] | 1972 | if (rrule1->freq_range.end_freq_khz != |
| 1973 | rrule2->freq_range.start_freq_khz) |
| 1974 | goto disable_chan; |
| 1975 | |
| 1976 | comb_range.start_freq_khz = |
| 1977 | rrule1->freq_range.start_freq_khz; |
| 1978 | comb_range.end_freq_khz = |
| 1979 | rrule2->freq_range.end_freq_khz; |
| 1980 | comb_range.max_bandwidth_khz = |
| 1981 | min_t(u32, |
| 1982 | rrule1->freq_range.max_bandwidth_khz, |
| 1983 | rrule2->freq_range.max_bandwidth_khz); |
| 1984 | |
| 1985 | if (!cfg80211_does_bw_fit_range(&comb_range, |
| 1986 | orig_chan_freq, |
| 1987 | MHZ_TO_KHZ(20))) |
| 1988 | goto disable_chan; |
| 1989 | |
| 1990 | handle_channel_adjacent_rules(wiphy, initiator, chan, |
| 1991 | flags, lr, request_wiphy, |
| 1992 | rrule1, rrule2, |
| 1993 | &comb_range); |
| 1994 | return; |
| 1995 | } |
| 1996 | |
| 1997 | disable_chan: |
Markus Theil | 7c9ff7e | 2020-08-03 16:43:52 +0200 | [diff] [blame] | 1998 | /* We will disable all channels that do not match our |
| 1999 | * received regulatory rule unless the hint is coming |
| 2000 | * from a Country IE and the Country IE had no information |
| 2001 | * about a band. The IEEE 802.11 spec allows for an AP |
| 2002 | * to send only a subset of the regulatory rules allowed, |
| 2003 | * so an AP in the US that only supports 2.4 GHz may only send |
| 2004 | * a country IE with information for the 2.4 GHz band |
| 2005 | * while 5 GHz is still supported. |
| 2006 | */ |
| 2007 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && |
Markus Theil | 12adee3 | 2020-08-03 16:43:53 +0200 | [diff] [blame] | 2008 | PTR_ERR(rrule) == -ERANGE) |
Markus Theil | 7c9ff7e | 2020-08-03 16:43:52 +0200 | [diff] [blame] | 2009 | return; |
| 2010 | |
| 2011 | if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && |
| 2012 | request_wiphy && request_wiphy == wiphy && |
| 2013 | request_wiphy->regulatory_flags & REGULATORY_STRICT_REG) { |
| 2014 | pr_debug("Disabling freq %d.%03d MHz for good\n", |
| 2015 | chan->center_freq, chan->freq_offset); |
| 2016 | chan->orig_flags |= IEEE80211_CHAN_DISABLED; |
| 2017 | chan->flags = chan->orig_flags; |
| 2018 | } else { |
| 2019 | pr_debug("Disabling freq %d.%03d MHz\n", |
| 2020 | chan->center_freq, chan->freq_offset); |
| 2021 | chan->flags |= IEEE80211_CHAN_DISABLED; |
| 2022 | } |
| 2023 | return; |
| 2024 | } |
| 2025 | |
| 2026 | handle_channel_single_rule(wiphy, initiator, chan, flags, lr, |
Markus Theil | 12adee3 | 2020-08-03 16:43:53 +0200 | [diff] [blame] | 2027 | request_wiphy, rrule); |
Markus Theil | 7c9ff7e | 2020-08-03 16:43:52 +0200 | [diff] [blame] | 2028 | } |
| 2029 | |
Luis R. Rodriguez | 7ca43d0 | 2010-10-20 10:18:53 -0700 | [diff] [blame] | 2030 | static void handle_band(struct wiphy *wiphy, |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2031 | enum nl80211_reg_initiator initiator, |
| 2032 | struct ieee80211_supported_band *sband) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2033 | { |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 2034 | unsigned int i; |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 2035 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2036 | if (!sband) |
| 2037 | return; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2038 | |
| 2039 | for (i = 0; i < sband->n_channels; i++) |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2040 | handle_channel(wiphy, initiator, &sband->channels[i]); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2041 | } |
| 2042 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2043 | static bool reg_request_cell_base(struct regulatory_request *request) |
| 2044 | { |
| 2045 | if (request->initiator != NL80211_REGDOM_SET_BY_USER) |
| 2046 | return false; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2047 | 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] | 2048 | } |
| 2049 | |
| 2050 | bool reg_last_request_cell_base(void) |
| 2051 | { |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 2052 | return reg_request_cell_base(get_last_request()); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2053 | } |
| 2054 | |
Ilan Peer | 94fc661 | 2014-02-23 09:13:00 +0200 | [diff] [blame] | 2055 | #ifdef CONFIG_CFG80211_REG_CELLULAR_HINTS |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2056 | /* Core specific check */ |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 2057 | static enum reg_request_treatment |
| 2058 | reg_ignore_cell_hint(struct regulatory_request *pending_request) |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2059 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2060 | struct regulatory_request *lr = get_last_request(); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2061 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2062 | if (!reg_num_devs_support_basehint) |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 2063 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2064 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2065 | if (reg_request_cell_base(lr) && |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2066 | !regdom_changes(pending_request->alpha2)) |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 2067 | return REG_REQ_ALREADY_SET; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2068 | |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 2069 | return REG_REQ_OK; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | /* Device specific check */ |
| 2073 | static bool reg_dev_ignore_cell_hint(struct wiphy *wiphy) |
| 2074 | { |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2075 | return !(wiphy->features & NL80211_FEATURE_CELL_BASE_REG_HINTS); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2076 | } |
| 2077 | #else |
Johannes Berg | a515de6 | 2015-10-15 14:28:56 +0200 | [diff] [blame] | 2078 | static enum reg_request_treatment |
| 2079 | reg_ignore_cell_hint(struct regulatory_request *pending_request) |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2080 | { |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 2081 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2082 | } |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2083 | |
| 2084 | static bool reg_dev_ignore_cell_hint(struct wiphy *wiphy) |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2085 | { |
| 2086 | return true; |
| 2087 | } |
| 2088 | #endif |
| 2089 | |
Luis R. Rodriguez | fa1fb9c | 2013-10-02 18:33:10 -0700 | [diff] [blame] | 2090 | static bool wiphy_strict_alpha2_regd(struct wiphy *wiphy) |
| 2091 | { |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 2092 | if (wiphy->regulatory_flags & REGULATORY_STRICT_REG && |
| 2093 | !(wiphy->regulatory_flags & REGULATORY_CUSTOM_REG)) |
Luis R. Rodriguez | fa1fb9c | 2013-10-02 18:33:10 -0700 | [diff] [blame] | 2094 | return true; |
| 2095 | return false; |
| 2096 | } |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2097 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 2098 | static bool ignore_reg_update(struct wiphy *wiphy, |
| 2099 | enum nl80211_reg_initiator initiator) |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 2100 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2101 | struct regulatory_request *lr = get_last_request(); |
| 2102 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 2103 | if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) |
| 2104 | return true; |
| 2105 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2106 | if (!lr) { |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 2107 | pr_debug("Ignoring regulatory request set by %s since last_request is not set\n", |
| 2108 | reg_initiator_name(initiator)); |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 2109 | return true; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 2110 | } |
| 2111 | |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 2112 | if (initiator == NL80211_REGDOM_SET_BY_CORE && |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 2113 | wiphy->regulatory_flags & REGULATORY_CUSTOM_REG) { |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 2114 | pr_debug("Ignoring regulatory request set by %s since the driver uses its own custom regulatory domain\n", |
| 2115 | reg_initiator_name(initiator)); |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 2116 | return true; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 2117 | } |
| 2118 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 2119 | /* |
| 2120 | * wiphy->regd will be set once the device has its own |
| 2121 | * desired regulatory domain set |
| 2122 | */ |
Luis R. Rodriguez | fa1fb9c | 2013-10-02 18:33:10 -0700 | [diff] [blame] | 2123 | if (wiphy_strict_alpha2_regd(wiphy) && !wiphy->regd && |
Luis R. Rodriguez | 749b527 | 2010-10-20 10:18:54 -0700 | [diff] [blame] | 2124 | initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2125 | !is_world_regdom(lr->alpha2)) { |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 2126 | pr_debug("Ignoring regulatory request set by %s since the driver requires its own regulatory domain to be set first\n", |
| 2127 | reg_initiator_name(initiator)); |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 2128 | return true; |
Luis R. Rodriguez | 926a0a0 | 2010-10-21 19:17:03 +0530 | [diff] [blame] | 2129 | } |
| 2130 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2131 | if (reg_request_cell_base(lr)) |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 2132 | return reg_dev_ignore_cell_hint(wiphy); |
| 2133 | |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 2134 | return false; |
| 2135 | } |
| 2136 | |
Luis R. Rodriguez | 3195e48 | 2012-12-19 10:53:03 -0800 | [diff] [blame] | 2137 | static bool reg_is_world_roaming(struct wiphy *wiphy) |
| 2138 | { |
| 2139 | const struct ieee80211_regdomain *cr = get_cfg80211_regdom(); |
| 2140 | const struct ieee80211_regdomain *wr = get_wiphy_regdom(wiphy); |
| 2141 | struct regulatory_request *lr = get_last_request(); |
| 2142 | |
| 2143 | if (is_world_regdom(cr->alpha2) || (wr && is_world_regdom(wr->alpha2))) |
| 2144 | return true; |
| 2145 | |
| 2146 | if (lr && lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 2147 | wiphy->regulatory_flags & REGULATORY_CUSTOM_REG) |
Luis R. Rodriguez | 3195e48 | 2012-12-19 10:53:03 -0800 | [diff] [blame] | 2148 | return true; |
| 2149 | |
| 2150 | return false; |
| 2151 | } |
| 2152 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2153 | 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] | 2154 | struct reg_beacon *reg_beacon) |
| 2155 | { |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2156 | struct ieee80211_supported_band *sband; |
| 2157 | struct ieee80211_channel *chan; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 2158 | bool channel_changed = false; |
| 2159 | struct ieee80211_channel chan_before; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2160 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2161 | sband = wiphy->bands[reg_beacon->chan.band]; |
| 2162 | chan = &sband->channels[chan_idx]; |
| 2163 | |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 2164 | if (likely(!ieee80211_channel_equal(chan, ®_beacon->chan))) |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2165 | return; |
| 2166 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 2167 | if (chan->beacon_found) |
| 2168 | return; |
| 2169 | |
| 2170 | chan->beacon_found = true; |
| 2171 | |
Luis R. Rodriguez | 0f500a5 | 2012-12-19 10:53:04 -0800 | [diff] [blame] | 2172 | if (!reg_is_world_roaming(wiphy)) |
| 2173 | return; |
| 2174 | |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 2175 | if (wiphy->regulatory_flags & REGULATORY_DISABLE_BEACON_HINTS) |
Luis R. Rodriguez | 3718424 | 2009-07-30 17:43:48 -0700 | [diff] [blame] | 2176 | return; |
| 2177 | |
Johannes Berg | a48a52b | 2018-01-15 09:12:05 +0100 | [diff] [blame] | 2178 | chan_before = *chan; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 2179 | |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 2180 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 2181 | chan->flags &= ~IEEE80211_CHAN_NO_IR; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 2182 | channel_changed = true; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2183 | } |
| 2184 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 2185 | if (channel_changed) |
| 2186 | nl80211_send_beacon_hint_event(wiphy, &chan_before, chan); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | /* |
| 2190 | * Called when a scan on a wiphy finds a beacon on |
| 2191 | * new channel |
| 2192 | */ |
| 2193 | static void wiphy_update_new_beacon(struct wiphy *wiphy, |
| 2194 | struct reg_beacon *reg_beacon) |
| 2195 | { |
| 2196 | unsigned int i; |
| 2197 | struct ieee80211_supported_band *sband; |
| 2198 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2199 | if (!wiphy->bands[reg_beacon->chan.band]) |
| 2200 | return; |
| 2201 | |
| 2202 | sband = wiphy->bands[reg_beacon->chan.band]; |
| 2203 | |
| 2204 | for (i = 0; i < sband->n_channels; i++) |
| 2205 | handle_reg_beacon(wiphy, i, reg_beacon); |
| 2206 | } |
| 2207 | |
| 2208 | /* |
| 2209 | * Called upon reg changes or a new wiphy is added |
| 2210 | */ |
| 2211 | static void wiphy_update_beacon_reg(struct wiphy *wiphy) |
| 2212 | { |
| 2213 | unsigned int i; |
| 2214 | struct ieee80211_supported_band *sband; |
| 2215 | struct reg_beacon *reg_beacon; |
| 2216 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2217 | list_for_each_entry(reg_beacon, ®_beacon_list, list) { |
| 2218 | if (!wiphy->bands[reg_beacon->chan.band]) |
| 2219 | continue; |
| 2220 | sband = wiphy->bands[reg_beacon->chan.band]; |
| 2221 | for (i = 0; i < sband->n_channels; i++) |
| 2222 | handle_reg_beacon(wiphy, i, reg_beacon); |
| 2223 | } |
| 2224 | } |
| 2225 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2226 | /* Reap the advantages of previously found beacons */ |
| 2227 | static void reg_process_beacons(struct wiphy *wiphy) |
| 2228 | { |
Luis R. Rodriguez | b1ed8dd | 2009-05-02 00:34:15 -0400 | [diff] [blame] | 2229 | /* |
| 2230 | * Means we are just firing up cfg80211, so no beacons would |
| 2231 | * have been processed yet. |
| 2232 | */ |
| 2233 | if (!last_request) |
| 2234 | return; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2235 | wiphy_update_beacon_reg(wiphy); |
| 2236 | } |
| 2237 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2238 | static bool is_ht40_allowed(struct ieee80211_channel *chan) |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2239 | { |
| 2240 | if (!chan) |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2241 | return false; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2242 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2243 | return false; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2244 | /* This would happen when regulatory rules disallow HT40 completely */ |
Felix Fietkau | 55b183a | 2013-01-11 14:22:58 +0100 | [diff] [blame] | 2245 | if ((chan->flags & IEEE80211_CHAN_NO_HT40) == IEEE80211_CHAN_NO_HT40) |
| 2246 | return false; |
| 2247 | return true; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | static void reg_process_ht_flags_channel(struct wiphy *wiphy, |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2251 | struct ieee80211_channel *channel) |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2252 | { |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2253 | struct ieee80211_supported_band *sband = wiphy->bands[channel->band]; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2254 | struct ieee80211_channel *channel_before = NULL, *channel_after = NULL; |
Emmanuel Grumbach | 4e0854a | 2017-09-06 13:45:40 +0300 | [diff] [blame] | 2255 | const struct ieee80211_regdomain *regd; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2256 | unsigned int i; |
Emmanuel Grumbach | 4e0854a | 2017-09-06 13:45:40 +0300 | [diff] [blame] | 2257 | u32 flags; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2258 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2259 | if (!is_ht40_allowed(channel)) { |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2260 | channel->flags |= IEEE80211_CHAN_NO_HT40; |
| 2261 | return; |
| 2262 | } |
| 2263 | |
| 2264 | /* |
| 2265 | * We need to ensure the extension channels exist to |
| 2266 | * be able to use HT40- or HT40+, this finds them (or not) |
| 2267 | */ |
| 2268 | for (i = 0; i < sband->n_channels; i++) { |
| 2269 | struct ieee80211_channel *c = &sband->channels[i]; |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2270 | |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2271 | if (c->center_freq == (channel->center_freq - 20)) |
| 2272 | channel_before = c; |
| 2273 | if (c->center_freq == (channel->center_freq + 20)) |
| 2274 | channel_after = c; |
| 2275 | } |
| 2276 | |
Emmanuel Grumbach | 4e0854a | 2017-09-06 13:45:40 +0300 | [diff] [blame] | 2277 | flags = 0; |
| 2278 | regd = get_wiphy_regdom(wiphy); |
| 2279 | if (regd) { |
| 2280 | const struct ieee80211_reg_rule *reg_rule = |
| 2281 | freq_reg_info_regd(MHZ_TO_KHZ(channel->center_freq), |
| 2282 | regd, MHZ_TO_KHZ(20)); |
| 2283 | |
| 2284 | if (!IS_ERR(reg_rule)) |
| 2285 | flags = reg_rule->flags; |
| 2286 | } |
| 2287 | |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2288 | /* |
| 2289 | * Please note that this assumes target bandwidth is 20 MHz, |
| 2290 | * if that ever changes we also need to change the below logic |
| 2291 | * to include that as well. |
| 2292 | */ |
Emmanuel Grumbach | 4e0854a | 2017-09-06 13:45:40 +0300 | [diff] [blame] | 2293 | if (!is_ht40_allowed(channel_before) || |
| 2294 | flags & NL80211_RRF_NO_HT40MINUS) |
Luis R. Rodriguez | 689da1b | 2009-05-02 00:37:18 -0400 | [diff] [blame] | 2295 | channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2296 | else |
Luis R. Rodriguez | 689da1b | 2009-05-02 00:37:18 -0400 | [diff] [blame] | 2297 | channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2298 | |
Emmanuel Grumbach | 4e0854a | 2017-09-06 13:45:40 +0300 | [diff] [blame] | 2299 | if (!is_ht40_allowed(channel_after) || |
| 2300 | flags & NL80211_RRF_NO_HT40PLUS) |
Luis R. Rodriguez | 689da1b | 2009-05-02 00:37:18 -0400 | [diff] [blame] | 2301 | channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2302 | else |
Luis R. Rodriguez | 689da1b | 2009-05-02 00:37:18 -0400 | [diff] [blame] | 2303 | channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | static void reg_process_ht_flags_band(struct wiphy *wiphy, |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2307 | struct ieee80211_supported_band *sband) |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2308 | { |
| 2309 | unsigned int i; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2310 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2311 | if (!sband) |
| 2312 | return; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2313 | |
| 2314 | for (i = 0; i < sband->n_channels; i++) |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2315 | reg_process_ht_flags_channel(wiphy, &sband->channels[i]); |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2316 | } |
| 2317 | |
| 2318 | static void reg_process_ht_flags(struct wiphy *wiphy) |
| 2319 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2320 | enum nl80211_band band; |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2321 | |
| 2322 | if (!wiphy) |
| 2323 | return; |
| 2324 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2325 | for (band = 0; band < NUM_NL80211_BANDS; band++) |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2326 | reg_process_ht_flags_band(wiphy, wiphy->bands[band]); |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2327 | } |
| 2328 | |
Luis R. Rodriguez | 0e3802d | 2013-11-05 09:18:12 -0800 | [diff] [blame] | 2329 | static void reg_call_notifier(struct wiphy *wiphy, |
| 2330 | struct regulatory_request *request) |
| 2331 | { |
| 2332 | if (wiphy->reg_notifier) |
| 2333 | wiphy->reg_notifier(wiphy, request); |
| 2334 | } |
| 2335 | |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2336 | static bool reg_wdev_chan_valid(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 2337 | { |
Johannes Berg | f43e521 | 2019-09-23 13:51:16 +0200 | [diff] [blame] | 2338 | struct cfg80211_chan_def chandef = {}; |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2339 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Arik Nemtsov | 2065870 | 2014-12-29 11:59:59 +0200 | [diff] [blame] | 2340 | enum nl80211_iftype iftype; |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2341 | |
| 2342 | wdev_lock(wdev); |
Arik Nemtsov | 2065870 | 2014-12-29 11:59:59 +0200 | [diff] [blame] | 2343 | iftype = wdev->iftype; |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2344 | |
Arik Nemtsov | 2065870 | 2014-12-29 11:59:59 +0200 | [diff] [blame] | 2345 | /* make sure the interface is active */ |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2346 | if (!wdev->netdev || !netif_running(wdev->netdev)) |
Arik Nemtsov | 2065870 | 2014-12-29 11:59:59 +0200 | [diff] [blame] | 2347 | goto wdev_inactive_unlock; |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2348 | |
Arik Nemtsov | 2065870 | 2014-12-29 11:59:59 +0200 | [diff] [blame] | 2349 | switch (iftype) { |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2350 | case NL80211_IFTYPE_AP: |
| 2351 | case NL80211_IFTYPE_P2P_GO: |
| 2352 | if (!wdev->beacon_interval) |
Arik Nemtsov | 2065870 | 2014-12-29 11:59:59 +0200 | [diff] [blame] | 2353 | goto wdev_inactive_unlock; |
| 2354 | chandef = wdev->chandef; |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2355 | break; |
Arik Nemtsov | 185076d | 2014-12-03 18:08:17 +0200 | [diff] [blame] | 2356 | case NL80211_IFTYPE_ADHOC: |
| 2357 | if (!wdev->ssid_len) |
Arik Nemtsov | 2065870 | 2014-12-29 11:59:59 +0200 | [diff] [blame] | 2358 | goto wdev_inactive_unlock; |
| 2359 | chandef = wdev->chandef; |
Arik Nemtsov | 185076d | 2014-12-03 18:08:17 +0200 | [diff] [blame] | 2360 | break; |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2361 | case NL80211_IFTYPE_STATION: |
| 2362 | case NL80211_IFTYPE_P2P_CLIENT: |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2363 | if (!wdev->current_bss || |
| 2364 | !wdev->current_bss->pub.channel) |
Arik Nemtsov | 2065870 | 2014-12-29 11:59:59 +0200 | [diff] [blame] | 2365 | goto wdev_inactive_unlock; |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2366 | |
Arik Nemtsov | 2065870 | 2014-12-29 11:59:59 +0200 | [diff] [blame] | 2367 | if (!rdev->ops->get_channel || |
| 2368 | rdev_get_channel(rdev, wdev, &chandef)) |
| 2369 | cfg80211_chandef_create(&chandef, |
| 2370 | wdev->current_bss->pub.channel, |
| 2371 | NL80211_CHAN_NO_HT); |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2372 | break; |
| 2373 | case NL80211_IFTYPE_MONITOR: |
| 2374 | case NL80211_IFTYPE_AP_VLAN: |
| 2375 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2376 | /* no enforcement required */ |
| 2377 | break; |
| 2378 | default: |
| 2379 | /* others not implemented for now */ |
| 2380 | WARN_ON(1); |
| 2381 | break; |
| 2382 | } |
| 2383 | |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2384 | wdev_unlock(wdev); |
Arik Nemtsov | 2065870 | 2014-12-29 11:59:59 +0200 | [diff] [blame] | 2385 | |
| 2386 | switch (iftype) { |
| 2387 | case NL80211_IFTYPE_AP: |
| 2388 | case NL80211_IFTYPE_P2P_GO: |
| 2389 | case NL80211_IFTYPE_ADHOC: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2390 | return cfg80211_reg_can_beacon_relax(wiphy, &chandef, iftype); |
Arik Nemtsov | 2065870 | 2014-12-29 11:59:59 +0200 | [diff] [blame] | 2391 | case NL80211_IFTYPE_STATION: |
| 2392 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2393 | return cfg80211_chandef_usable(wiphy, &chandef, |
| 2394 | IEEE80211_CHAN_DISABLED); |
| 2395 | default: |
| 2396 | break; |
| 2397 | } |
| 2398 | |
| 2399 | return true; |
| 2400 | |
| 2401 | wdev_inactive_unlock: |
| 2402 | wdev_unlock(wdev); |
| 2403 | return true; |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | static void reg_leave_invalid_chans(struct wiphy *wiphy) |
| 2407 | { |
| 2408 | struct wireless_dev *wdev; |
| 2409 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 2410 | |
| 2411 | ASSERT_RTNL(); |
| 2412 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2413 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2414 | if (!reg_wdev_chan_valid(wiphy, wdev)) |
| 2415 | cfg80211_leave(rdev, wdev); |
| 2416 | } |
| 2417 | |
| 2418 | static void reg_check_chans_work(struct work_struct *work) |
| 2419 | { |
| 2420 | struct cfg80211_registered_device *rdev; |
| 2421 | |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 2422 | pr_debug("Verifying active interfaces after reg change\n"); |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2423 | rtnl_lock(); |
| 2424 | |
| 2425 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) |
| 2426 | if (!(rdev->wiphy.regulatory_flags & |
| 2427 | REGULATORY_IGNORE_STALE_KICKOFF)) |
| 2428 | reg_leave_invalid_chans(&rdev->wiphy); |
| 2429 | |
| 2430 | rtnl_unlock(); |
| 2431 | } |
| 2432 | |
| 2433 | static void reg_check_channels(void) |
| 2434 | { |
| 2435 | /* |
| 2436 | * Give usermode a chance to do something nicer (move to another |
| 2437 | * channel, orderly disconnection), before forcing a disconnection. |
| 2438 | */ |
| 2439 | mod_delayed_work(system_power_efficient_wq, |
| 2440 | ®_check_chans, |
| 2441 | msecs_to_jiffies(REG_ENFORCE_GRACE_MS)); |
| 2442 | } |
| 2443 | |
Sven Neumann | eac03e3 | 2011-08-30 23:38:53 +0200 | [diff] [blame] | 2444 | static void wiphy_update_regulatory(struct wiphy *wiphy, |
| 2445 | enum nl80211_reg_initiator initiator) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2446 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2447 | enum nl80211_band band; |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2448 | struct regulatory_request *lr = get_last_request(); |
Sven Neumann | eac03e3 | 2011-08-30 23:38:53 +0200 | [diff] [blame] | 2449 | |
Luis R. Rodriguez | 0e3802d | 2013-11-05 09:18:12 -0800 | [diff] [blame] | 2450 | if (ignore_reg_update(wiphy, initiator)) { |
| 2451 | /* |
| 2452 | * Regulatory updates set by CORE are ignored for custom |
| 2453 | * regulatory cards. Let us notify the changes to the driver, |
| 2454 | * as some drivers used this to restore its orig_* reg domain. |
| 2455 | */ |
| 2456 | if (initiator == NL80211_REGDOM_SET_BY_CORE && |
Amar Singhal | e31f645 | 2018-07-20 12:15:18 -0700 | [diff] [blame] | 2457 | wiphy->regulatory_flags & REGULATORY_CUSTOM_REG && |
| 2458 | !(wiphy->regulatory_flags & |
| 2459 | REGULATORY_WIPHY_SELF_MANAGED)) |
Luis R. Rodriguez | 0e3802d | 2013-11-05 09:18:12 -0800 | [diff] [blame] | 2460 | reg_call_notifier(wiphy, lr); |
Sven Neumann | a203c2a | 2011-07-12 15:52:07 +0200 | [diff] [blame] | 2461 | return; |
Luis R. Rodriguez | 0e3802d | 2013-11-05 09:18:12 -0800 | [diff] [blame] | 2462 | } |
Sven Neumann | a203c2a | 2011-07-12 15:52:07 +0200 | [diff] [blame] | 2463 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2464 | lr->dfs_region = get_cfg80211_regdom()->dfs_region; |
Luis R. Rodriguez | b68e6b3 | 2011-10-11 10:59:03 -0700 | [diff] [blame] | 2465 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2466 | for (band = 0; band < NUM_NL80211_BANDS; band++) |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2467 | handle_band(wiphy, initiator, wiphy->bands[band]); |
Sven Neumann | a203c2a | 2011-07-12 15:52:07 +0200 | [diff] [blame] | 2468 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 2469 | reg_process_beacons(wiphy); |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2470 | reg_process_ht_flags(wiphy); |
Luis R. Rodriguez | 0e3802d | 2013-11-05 09:18:12 -0800 | [diff] [blame] | 2471 | reg_call_notifier(wiphy, lr); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
Sven Neumann | d7549cb | 2011-08-30 23:38:54 +0200 | [diff] [blame] | 2474 | static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator) |
| 2475 | { |
| 2476 | struct cfg80211_registered_device *rdev; |
Rajkumar Manoharan | 4a38994 | 2011-12-08 23:59:26 +0530 | [diff] [blame] | 2477 | struct wiphy *wiphy; |
Sven Neumann | d7549cb | 2011-08-30 23:38:54 +0200 | [diff] [blame] | 2478 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2479 | ASSERT_RTNL(); |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 2480 | |
Rajkumar Manoharan | 4a38994 | 2011-12-08 23:59:26 +0530 | [diff] [blame] | 2481 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2482 | wiphy = &rdev->wiphy; |
| 2483 | wiphy_update_regulatory(wiphy, initiator); |
Rajkumar Manoharan | 4a38994 | 2011-12-08 23:59:26 +0530 | [diff] [blame] | 2484 | } |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 2485 | |
| 2486 | reg_check_channels(); |
Sven Neumann | d7549cb | 2011-08-30 23:38:54 +0200 | [diff] [blame] | 2487 | } |
| 2488 | |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2489 | static void handle_channel_custom(struct wiphy *wiphy, |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2490 | struct ieee80211_channel *chan, |
Ganapathi Bhat | c4b9d65 | 2019-12-20 10:14:32 +0000 | [diff] [blame] | 2491 | const struct ieee80211_regdomain *regd, |
| 2492 | u32 min_bw) |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2493 | { |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2494 | u32 bw_flags = 0; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2495 | const struct ieee80211_reg_rule *reg_rule = NULL; |
| 2496 | const struct ieee80211_power_rule *power_rule = NULL; |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 2497 | u32 bw, center_freq_khz; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2498 | |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 2499 | center_freq_khz = ieee80211_channel_to_khz(chan); |
Ganapathi Bhat | c4b9d65 | 2019-12-20 10:14:32 +0000 | [diff] [blame] | 2500 | for (bw = MHZ_TO_KHZ(20); bw >= min_bw; bw = bw / 2) { |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 2501 | reg_rule = freq_reg_info_regd(center_freq_khz, regd, bw); |
Matthias May | 4edd569 | 2015-07-17 15:28:39 +0200 | [diff] [blame] | 2502 | if (!IS_ERR(reg_rule)) |
| 2503 | break; |
| 2504 | } |
Luis R. Rodriguez | ac46d48 | 2009-05-01 18:44:50 -0400 | [diff] [blame] | 2505 | |
Johannes Berg | a7ee7d4 | 2020-02-21 10:44:50 +0100 | [diff] [blame] | 2506 | if (IS_ERR_OR_NULL(reg_rule)) { |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 2507 | pr_debug("Disabling freq %d.%03d MHz as custom regd has no rule that fits it\n", |
| 2508 | chan->center_freq, chan->freq_offset); |
Arik Nemtsov | db8dfee | 2014-12-15 19:26:02 +0200 | [diff] [blame] | 2509 | if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { |
| 2510 | chan->flags |= IEEE80211_CHAN_DISABLED; |
| 2511 | } else { |
| 2512 | chan->orig_flags |= IEEE80211_CHAN_DISABLED; |
| 2513 | chan->flags = chan->orig_flags; |
| 2514 | } |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2515 | return; |
| 2516 | } |
| 2517 | |
| 2518 | power_rule = ®_rule->power_rule; |
Michal Sojka | 1aeb135 | 2015-11-23 19:27:16 +0100 | [diff] [blame] | 2519 | bw_flags = reg_rule_to_chan_bw_flags(regd, reg_rule, chan); |
Luis R. Rodriguez | 038659e | 2009-05-02 00:37:17 -0400 | [diff] [blame] | 2520 | |
Arik Nemtsov | 2e18b38 | 2014-11-16 16:37:46 +0200 | [diff] [blame] | 2521 | chan->dfs_state_entered = jiffies; |
Arik Nemtsov | c7ab508 | 2014-11-16 16:37:47 +0200 | [diff] [blame] | 2522 | chan->dfs_state = NL80211_DFS_USABLE; |
| 2523 | |
| 2524 | chan->beacon_found = false; |
Arik Nemtsov | db8dfee | 2014-12-15 19:26:02 +0200 | [diff] [blame] | 2525 | |
| 2526 | if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) |
| 2527 | chan->flags = chan->orig_flags | bw_flags | |
| 2528 | map_regdom_flags(reg_rule->flags); |
| 2529 | else |
| 2530 | chan->flags |= map_regdom_flags(reg_rule->flags) | bw_flags; |
| 2531 | |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2532 | 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] | 2533 | chan->max_reg_power = chan->max_power = |
| 2534 | (int) MBM_TO_DBM(power_rule->max_eirp); |
Arik Nemtsov | 2e18b38 | 2014-11-16 16:37:46 +0200 | [diff] [blame] | 2535 | |
| 2536 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 2537 | if (reg_rule->dfs_cac_ms) |
| 2538 | chan->dfs_cac_ms = reg_rule->dfs_cac_ms; |
| 2539 | else |
| 2540 | chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 2541 | } |
| 2542 | |
| 2543 | chan->max_power = chan->max_reg_power; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2544 | } |
| 2545 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2546 | static void handle_band_custom(struct wiphy *wiphy, |
| 2547 | struct ieee80211_supported_band *sband, |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2548 | const struct ieee80211_regdomain *regd) |
| 2549 | { |
| 2550 | unsigned int i; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2551 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2552 | if (!sband) |
| 2553 | return; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2554 | |
Ganapathi Bhat | c4b9d65 | 2019-12-20 10:14:32 +0000 | [diff] [blame] | 2555 | /* |
| 2556 | * We currently assume that you always want at least 20 MHz, |
| 2557 | * otherwise channel 12 might get enabled if this rule is |
| 2558 | * compatible to US, which permits 2402 - 2472 MHz. |
| 2559 | */ |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2560 | for (i = 0; i < sband->n_channels; i++) |
Ganapathi Bhat | c4b9d65 | 2019-12-20 10:14:32 +0000 | [diff] [blame] | 2561 | handle_channel_custom(wiphy, &sband->channels[i], regd, |
| 2562 | MHZ_TO_KHZ(20)); |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | /* Used by drivers prior to wiphy registration */ |
| 2566 | void wiphy_apply_custom_regulatory(struct wiphy *wiphy, |
| 2567 | const struct ieee80211_regdomain *regd) |
| 2568 | { |
Ilan Peer | beee246 | 2020-11-29 17:30:51 +0200 | [diff] [blame] | 2569 | const struct ieee80211_regdomain *new_regd, *tmp; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2570 | enum nl80211_band band; |
Luis R. Rodriguez | bbcf3f0 | 2009-05-19 17:49:47 -0400 | [diff] [blame] | 2571 | unsigned int bands_set = 0; |
Luis R. Rodriguez | ac46d48 | 2009-05-01 18:44:50 -0400 | [diff] [blame] | 2572 | |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 2573 | WARN(!(wiphy->regulatory_flags & REGULATORY_CUSTOM_REG), |
| 2574 | "wiphy should have REGULATORY_CUSTOM_REG\n"); |
| 2575 | wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; |
Luis R. Rodriguez | 222ea58 | 2013-11-05 09:18:00 -0800 | [diff] [blame] | 2576 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2577 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luis R. Rodriguez | bbcf3f0 | 2009-05-19 17:49:47 -0400 | [diff] [blame] | 2578 | if (!wiphy->bands[band]) |
| 2579 | continue; |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 2580 | handle_band_custom(wiphy, wiphy->bands[band], regd); |
Luis R. Rodriguez | bbcf3f0 | 2009-05-19 17:49:47 -0400 | [diff] [blame] | 2581 | bands_set++; |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2582 | } |
Luis R. Rodriguez | bbcf3f0 | 2009-05-19 17:49:47 -0400 | [diff] [blame] | 2583 | |
| 2584 | /* |
| 2585 | * no point in calling this if it won't have any effect |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 2586 | * on your device's supported bands. |
Luis R. Rodriguez | bbcf3f0 | 2009-05-19 17:49:47 -0400 | [diff] [blame] | 2587 | */ |
| 2588 | WARN_ON(!bands_set); |
Ilan Peer | beee246 | 2020-11-29 17:30:51 +0200 | [diff] [blame] | 2589 | new_regd = reg_copy_regd(regd); |
| 2590 | if (IS_ERR(new_regd)) |
| 2591 | return; |
| 2592 | |
Ilan Peer | 51d62f2 | 2021-01-05 16:56:57 +0200 | [diff] [blame] | 2593 | rtnl_lock(); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 2594 | wiphy_lock(wiphy); |
Ilan Peer | 51d62f2 | 2021-01-05 16:56:57 +0200 | [diff] [blame] | 2595 | |
Ilan Peer | beee246 | 2020-11-29 17:30:51 +0200 | [diff] [blame] | 2596 | tmp = get_wiphy_regdom(wiphy); |
| 2597 | rcu_assign_pointer(wiphy->regd, new_regd); |
| 2598 | rcu_free_regdom(tmp); |
Ilan Peer | 51d62f2 | 2021-01-05 16:56:57 +0200 | [diff] [blame] | 2599 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 2600 | wiphy_unlock(wiphy); |
Ilan Peer | 51d62f2 | 2021-01-05 16:56:57 +0200 | [diff] [blame] | 2601 | rtnl_unlock(); |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 2602 | } |
| 2603 | EXPORT_SYMBOL(wiphy_apply_custom_regulatory); |
| 2604 | |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 2605 | static void reg_set_request_processed(void) |
| 2606 | { |
| 2607 | bool need_more_processing = false; |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2608 | struct regulatory_request *lr = get_last_request(); |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 2609 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 2610 | lr->processed = true; |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 2611 | |
| 2612 | spin_lock(®_requests_lock); |
| 2613 | if (!list_empty(®_requests_list)) |
| 2614 | need_more_processing = true; |
| 2615 | spin_unlock(®_requests_lock); |
| 2616 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 2617 | cancel_crda_timeout(); |
Luis R. Rodriguez | a90c7a3 | 2011-04-05 10:49:04 -0700 | [diff] [blame] | 2618 | |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 2619 | if (need_more_processing) |
| 2620 | schedule_work(®_work); |
| 2621 | } |
| 2622 | |
Luis R. Rodriguez | d1c96a9 | 2009-02-21 00:24:13 -0500 | [diff] [blame] | 2623 | /** |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 2624 | * reg_process_hint_core - process core regulatory requests |
Andrew Lunn | 726e6af | 2020-07-13 01:15:15 +0200 | [diff] [blame] | 2625 | * @core_request: a pending core regulatory request |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 2626 | * |
| 2627 | * The wireless subsystem can use this function to process |
| 2628 | * a regulatory request issued by the regulatory core. |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 2629 | */ |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2630 | static enum reg_request_treatment |
| 2631 | reg_process_hint_core(struct regulatory_request *core_request) |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 2632 | { |
Johannes Berg | cecbb06 | 2015-10-15 08:47:34 +0200 | [diff] [blame] | 2633 | if (reg_query_database(core_request)) { |
Johannes Berg | 25b20db | 2015-10-15 12:05:05 +0200 | [diff] [blame] | 2634 | core_request->intersect = false; |
| 2635 | core_request->processed = false; |
| 2636 | reg_update_last_request(core_request); |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2637 | return REG_REQ_OK; |
Johannes Berg | 25b20db | 2015-10-15 12:05:05 +0200 | [diff] [blame] | 2638 | } |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2639 | |
| 2640 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 2641 | } |
| 2642 | |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 2643 | static enum reg_request_treatment |
| 2644 | __reg_process_hint_user(struct regulatory_request *user_request) |
| 2645 | { |
| 2646 | struct regulatory_request *lr = get_last_request(); |
| 2647 | |
| 2648 | if (reg_request_cell_base(user_request)) |
| 2649 | return reg_ignore_cell_hint(user_request); |
| 2650 | |
| 2651 | if (reg_request_cell_base(lr)) |
| 2652 | return REG_REQ_IGNORE; |
| 2653 | |
| 2654 | if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) |
| 2655 | return REG_REQ_INTERSECT; |
| 2656 | /* |
| 2657 | * If the user knows better the user should set the regdom |
| 2658 | * to their country before the IE is picked up |
| 2659 | */ |
| 2660 | if (lr->initiator == NL80211_REGDOM_SET_BY_USER && |
| 2661 | lr->intersect) |
| 2662 | return REG_REQ_IGNORE; |
| 2663 | /* |
| 2664 | * Process user requests only after previous user/driver/core |
| 2665 | * requests have been processed |
| 2666 | */ |
| 2667 | if ((lr->initiator == NL80211_REGDOM_SET_BY_CORE || |
| 2668 | lr->initiator == NL80211_REGDOM_SET_BY_DRIVER || |
| 2669 | lr->initiator == NL80211_REGDOM_SET_BY_USER) && |
| 2670 | regdom_changes(lr->alpha2)) |
| 2671 | return REG_REQ_IGNORE; |
| 2672 | |
| 2673 | if (!regdom_changes(user_request->alpha2)) |
| 2674 | return REG_REQ_ALREADY_SET; |
| 2675 | |
| 2676 | return REG_REQ_OK; |
| 2677 | } |
| 2678 | |
| 2679 | /** |
| 2680 | * reg_process_hint_user - process user regulatory requests |
| 2681 | * @user_request: a pending user regulatory request |
| 2682 | * |
| 2683 | * The wireless subsystem can use this function to process |
| 2684 | * a regulatory request initiated by userspace. |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 2685 | */ |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2686 | static enum reg_request_treatment |
| 2687 | reg_process_hint_user(struct regulatory_request *user_request) |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 2688 | { |
| 2689 | enum reg_request_treatment treatment; |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 2690 | |
| 2691 | treatment = __reg_process_hint_user(user_request); |
| 2692 | if (treatment == REG_REQ_IGNORE || |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2693 | treatment == REG_REQ_ALREADY_SET) |
| 2694 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 2695 | |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 2696 | user_request->intersect = treatment == REG_REQ_INTERSECT; |
| 2697 | user_request->processed = false; |
Luis R. Rodriguez | 5ad6ef5 | 2013-11-05 09:18:08 -0800 | [diff] [blame] | 2698 | |
Johannes Berg | cecbb06 | 2015-10-15 08:47:34 +0200 | [diff] [blame] | 2699 | if (reg_query_database(user_request)) { |
Johannes Berg | 25b20db | 2015-10-15 12:05:05 +0200 | [diff] [blame] | 2700 | reg_update_last_request(user_request); |
| 2701 | user_alpha2[0] = user_request->alpha2[0]; |
| 2702 | user_alpha2[1] = user_request->alpha2[1]; |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2703 | return REG_REQ_OK; |
Johannes Berg | 25b20db | 2015-10-15 12:05:05 +0200 | [diff] [blame] | 2704 | } |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2705 | |
| 2706 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | 0d97a61 | 2013-11-05 09:18:04 -0800 | [diff] [blame] | 2707 | } |
| 2708 | |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2709 | static enum reg_request_treatment |
| 2710 | __reg_process_hint_driver(struct regulatory_request *driver_request) |
| 2711 | { |
| 2712 | struct regulatory_request *lr = get_last_request(); |
| 2713 | |
| 2714 | if (lr->initiator == NL80211_REGDOM_SET_BY_CORE) { |
| 2715 | if (regdom_changes(driver_request->alpha2)) |
| 2716 | return REG_REQ_OK; |
| 2717 | return REG_REQ_ALREADY_SET; |
| 2718 | } |
| 2719 | |
| 2720 | /* |
| 2721 | * This would happen if you unplug and plug your card |
| 2722 | * back in or if you add a new device for which the previously |
| 2723 | * loaded card also agrees on the regulatory domain. |
| 2724 | */ |
| 2725 | if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && |
| 2726 | !regdom_changes(driver_request->alpha2)) |
| 2727 | return REG_REQ_ALREADY_SET; |
| 2728 | |
| 2729 | return REG_REQ_INTERSECT; |
| 2730 | } |
| 2731 | |
| 2732 | /** |
| 2733 | * reg_process_hint_driver - process driver regulatory requests |
Andrew Lunn | 726e6af | 2020-07-13 01:15:15 +0200 | [diff] [blame] | 2734 | * @wiphy: the wireless device for the regulatory request |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2735 | * @driver_request: a pending driver regulatory request |
| 2736 | * |
| 2737 | * The wireless subsystem can use this function to process |
| 2738 | * a regulatory request issued by an 802.11 driver. |
| 2739 | * |
| 2740 | * Returns one of the different reg request treatment values. |
| 2741 | */ |
| 2742 | static enum reg_request_treatment |
| 2743 | reg_process_hint_driver(struct wiphy *wiphy, |
| 2744 | struct regulatory_request *driver_request) |
| 2745 | { |
Arik Nemtsov | 34f05f5 | 2014-12-04 12:22:16 +0200 | [diff] [blame] | 2746 | const struct ieee80211_regdomain *regd, *tmp; |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2747 | enum reg_request_treatment treatment; |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2748 | |
| 2749 | treatment = __reg_process_hint_driver(driver_request); |
| 2750 | |
| 2751 | switch (treatment) { |
| 2752 | case REG_REQ_OK: |
| 2753 | break; |
| 2754 | case REG_REQ_IGNORE: |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2755 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2756 | case REG_REQ_INTERSECT: |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2757 | case REG_REQ_ALREADY_SET: |
| 2758 | regd = reg_copy_regd(get_cfg80211_regdom()); |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2759 | if (IS_ERR(regd)) |
| 2760 | return REG_REQ_IGNORE; |
Arik Nemtsov | 34f05f5 | 2014-12-04 12:22:16 +0200 | [diff] [blame] | 2761 | |
| 2762 | tmp = get_wiphy_regdom(wiphy); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 2763 | ASSERT_RTNL(); |
| 2764 | wiphy_lock(wiphy); |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2765 | rcu_assign_pointer(wiphy->regd, regd); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 2766 | wiphy_unlock(wiphy); |
Arik Nemtsov | 34f05f5 | 2014-12-04 12:22:16 +0200 | [diff] [blame] | 2767 | rcu_free_regdom(tmp); |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2768 | } |
| 2769 | |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2770 | |
| 2771 | driver_request->intersect = treatment == REG_REQ_INTERSECT; |
| 2772 | driver_request->processed = false; |
Luis R. Rodriguez | 5ad6ef5 | 2013-11-05 09:18:08 -0800 | [diff] [blame] | 2773 | |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2774 | /* |
| 2775 | * Since CRDA will not be called in this case as we already |
| 2776 | * have applied the requested regulatory domain before we just |
| 2777 | * inform userspace we have processed the request |
| 2778 | */ |
| 2779 | if (treatment == REG_REQ_ALREADY_SET) { |
| 2780 | nl80211_send_reg_change_event(driver_request); |
Johannes Berg | 25b20db | 2015-10-15 12:05:05 +0200 | [diff] [blame] | 2781 | reg_update_last_request(driver_request); |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2782 | reg_set_request_processed(); |
Johannes Berg | 480908a | 2015-10-15 12:58:58 +0200 | [diff] [blame] | 2783 | return REG_REQ_ALREADY_SET; |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2784 | } |
| 2785 | |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2786 | if (reg_query_database(driver_request)) { |
Johannes Berg | 25b20db | 2015-10-15 12:05:05 +0200 | [diff] [blame] | 2787 | reg_update_last_request(driver_request); |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2788 | return REG_REQ_OK; |
| 2789 | } |
Johannes Berg | 25b20db | 2015-10-15 12:05:05 +0200 | [diff] [blame] | 2790 | |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2791 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2792 | } |
| 2793 | |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2794 | static enum reg_request_treatment |
| 2795 | __reg_process_hint_country_ie(struct wiphy *wiphy, |
| 2796 | struct regulatory_request *country_ie_request) |
| 2797 | { |
| 2798 | struct wiphy *last_wiphy = NULL; |
| 2799 | struct regulatory_request *lr = get_last_request(); |
| 2800 | |
| 2801 | if (reg_request_cell_base(lr)) { |
| 2802 | /* Trust a Cell base station over the AP's country IE */ |
| 2803 | if (regdom_changes(country_ie_request->alpha2)) |
| 2804 | return REG_REQ_IGNORE; |
| 2805 | return REG_REQ_ALREADY_SET; |
Luis R. Rodriguez | 2a90146 | 2013-11-11 22:15:31 +0100 | [diff] [blame] | 2806 | } else { |
| 2807 | if (wiphy->regulatory_flags & REGULATORY_COUNTRY_IE_IGNORE) |
| 2808 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2809 | } |
| 2810 | |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2811 | if (unlikely(!is_an_alpha2(country_ie_request->alpha2))) |
| 2812 | return -EINVAL; |
Luis R. Rodriguez | 2f1c6c5 | 2013-11-05 09:18:07 -0800 | [diff] [blame] | 2813 | |
| 2814 | if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) |
| 2815 | return REG_REQ_OK; |
| 2816 | |
| 2817 | last_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); |
| 2818 | |
| 2819 | if (last_wiphy != wiphy) { |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2820 | /* |
Luis R. Rodriguez | 2f1c6c5 | 2013-11-05 09:18:07 -0800 | [diff] [blame] | 2821 | * Two cards with two APs claiming different |
| 2822 | * Country IE alpha2s. We could |
| 2823 | * intersect them, but that seems unlikely |
| 2824 | * to be correct. Reject second one for now. |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2825 | */ |
Luis R. Rodriguez | 2f1c6c5 | 2013-11-05 09:18:07 -0800 | [diff] [blame] | 2826 | if (regdom_changes(country_ie_request->alpha2)) |
| 2827 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2828 | return REG_REQ_ALREADY_SET; |
| 2829 | } |
Emmanuel Grumbach | 70dcec5 | 2014-12-02 09:53:25 +0200 | [diff] [blame] | 2830 | |
| 2831 | if (regdom_changes(country_ie_request->alpha2)) |
Luis R. Rodriguez | 2f1c6c5 | 2013-11-05 09:18:07 -0800 | [diff] [blame] | 2832 | return REG_REQ_OK; |
| 2833 | return REG_REQ_ALREADY_SET; |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2834 | } |
| 2835 | |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 2836 | /** |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2837 | * reg_process_hint_country_ie - process regulatory requests from country IEs |
Andrew Lunn | 726e6af | 2020-07-13 01:15:15 +0200 | [diff] [blame] | 2838 | * @wiphy: the wireless device for the regulatory request |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2839 | * @country_ie_request: a regulatory request from a country IE |
Luis R. Rodriguez | d1c96a9 | 2009-02-21 00:24:13 -0500 | [diff] [blame] | 2840 | * |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2841 | * The wireless subsystem can use this function to process |
| 2842 | * a regulatory request issued by a country Information Element. |
Luis R. Rodriguez | d1c96a9 | 2009-02-21 00:24:13 -0500 | [diff] [blame] | 2843 | * |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 2844 | * Returns one of the different reg request treatment values. |
Luis R. Rodriguez | d1c96a9 | 2009-02-21 00:24:13 -0500 | [diff] [blame] | 2845 | */ |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 2846 | static enum reg_request_treatment |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2847 | reg_process_hint_country_ie(struct wiphy *wiphy, |
| 2848 | struct regulatory_request *country_ie_request) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2849 | { |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 2850 | enum reg_request_treatment treatment; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2851 | |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2852 | treatment = __reg_process_hint_country_ie(wiphy, country_ie_request); |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 2853 | |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 2854 | switch (treatment) { |
Johannes Berg | 2f92212 | 2012-12-03 17:54:55 +0100 | [diff] [blame] | 2855 | case REG_REQ_OK: |
| 2856 | break; |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2857 | case REG_REQ_IGNORE: |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2858 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2859 | case REG_REQ_ALREADY_SET: |
Arik Nemtsov | c888393 | 2014-04-21 20:39:34 -0700 | [diff] [blame] | 2860 | reg_free_request(country_ie_request); |
Johannes Berg | 480908a | 2015-10-15 12:58:58 +0200 | [diff] [blame] | 2861 | return REG_REQ_ALREADY_SET; |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2862 | case REG_REQ_INTERSECT: |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2863 | /* |
| 2864 | * This doesn't happen yet, not sure we |
| 2865 | * ever want to support it for this case. |
| 2866 | */ |
Toke Høiland-Jørgensen | 8db0c433 | 2018-04-19 11:17:38 +0200 | [diff] [blame] | 2867 | WARN_ONCE(1, "Unexpected intersection for country elements"); |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2868 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 2869 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2870 | |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2871 | country_ie_request->intersect = false; |
| 2872 | country_ie_request->processed = false; |
Luis R. Rodriguez | 5ad6ef5 | 2013-11-05 09:18:08 -0800 | [diff] [blame] | 2873 | |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2874 | if (reg_query_database(country_ie_request)) { |
Johannes Berg | 25b20db | 2015-10-15 12:05:05 +0200 | [diff] [blame] | 2875 | reg_update_last_request(country_ie_request); |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2876 | return REG_REQ_OK; |
| 2877 | } |
Luis R. Rodriguez | d951c1d | 2009-02-21 00:24:15 -0500 | [diff] [blame] | 2878 | |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2879 | return REG_REQ_IGNORE; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2880 | } |
| 2881 | |
Vasanthakumar Thiagarajan | 8976672 | 2017-02-27 17:04:35 +0530 | [diff] [blame] | 2882 | bool reg_dfs_domain_same(struct wiphy *wiphy1, struct wiphy *wiphy2) |
| 2883 | { |
| 2884 | const struct ieee80211_regdomain *wiphy1_regd = NULL; |
| 2885 | const struct ieee80211_regdomain *wiphy2_regd = NULL; |
| 2886 | const struct ieee80211_regdomain *cfg80211_regd = NULL; |
| 2887 | bool dfs_domain_same; |
| 2888 | |
| 2889 | rcu_read_lock(); |
| 2890 | |
| 2891 | cfg80211_regd = rcu_dereference(cfg80211_regdomain); |
| 2892 | wiphy1_regd = rcu_dereference(wiphy1->regd); |
| 2893 | if (!wiphy1_regd) |
| 2894 | wiphy1_regd = cfg80211_regd; |
| 2895 | |
| 2896 | wiphy2_regd = rcu_dereference(wiphy2->regd); |
| 2897 | if (!wiphy2_regd) |
| 2898 | wiphy2_regd = cfg80211_regd; |
| 2899 | |
| 2900 | dfs_domain_same = wiphy1_regd->dfs_region == wiphy2_regd->dfs_region; |
| 2901 | |
| 2902 | rcu_read_unlock(); |
| 2903 | |
| 2904 | return dfs_domain_same; |
| 2905 | } |
| 2906 | |
| 2907 | static void reg_copy_dfs_chan_state(struct ieee80211_channel *dst_chan, |
| 2908 | struct ieee80211_channel *src_chan) |
| 2909 | { |
| 2910 | if (!(dst_chan->flags & IEEE80211_CHAN_RADAR) || |
| 2911 | !(src_chan->flags & IEEE80211_CHAN_RADAR)) |
| 2912 | return; |
| 2913 | |
| 2914 | if (dst_chan->flags & IEEE80211_CHAN_DISABLED || |
| 2915 | src_chan->flags & IEEE80211_CHAN_DISABLED) |
| 2916 | return; |
| 2917 | |
| 2918 | if (src_chan->center_freq == dst_chan->center_freq && |
| 2919 | dst_chan->dfs_state == NL80211_DFS_USABLE) { |
| 2920 | dst_chan->dfs_state = src_chan->dfs_state; |
| 2921 | dst_chan->dfs_state_entered = src_chan->dfs_state_entered; |
| 2922 | } |
| 2923 | } |
| 2924 | |
| 2925 | static void wiphy_share_dfs_chan_state(struct wiphy *dst_wiphy, |
| 2926 | struct wiphy *src_wiphy) |
| 2927 | { |
| 2928 | struct ieee80211_supported_band *src_sband, *dst_sband; |
| 2929 | struct ieee80211_channel *src_chan, *dst_chan; |
| 2930 | int i, j, band; |
| 2931 | |
| 2932 | if (!reg_dfs_domain_same(dst_wiphy, src_wiphy)) |
| 2933 | return; |
| 2934 | |
| 2935 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
| 2936 | dst_sband = dst_wiphy->bands[band]; |
| 2937 | src_sband = src_wiphy->bands[band]; |
| 2938 | if (!dst_sband || !src_sband) |
| 2939 | continue; |
| 2940 | |
| 2941 | for (i = 0; i < dst_sband->n_channels; i++) { |
| 2942 | dst_chan = &dst_sband->channels[i]; |
| 2943 | for (j = 0; j < src_sband->n_channels; j++) { |
| 2944 | src_chan = &src_sband->channels[j]; |
| 2945 | reg_copy_dfs_chan_state(dst_chan, src_chan); |
| 2946 | } |
| 2947 | } |
| 2948 | } |
| 2949 | } |
| 2950 | |
| 2951 | static void wiphy_all_share_dfs_chan_state(struct wiphy *wiphy) |
| 2952 | { |
| 2953 | struct cfg80211_registered_device *rdev; |
| 2954 | |
| 2955 | ASSERT_RTNL(); |
| 2956 | |
| 2957 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2958 | if (wiphy == &rdev->wiphy) |
| 2959 | continue; |
| 2960 | wiphy_share_dfs_chan_state(wiphy, &rdev->wiphy); |
| 2961 | } |
| 2962 | } |
| 2963 | |
Luis R. Rodriguez | 30a548c | 2009-05-02 01:17:27 -0400 | [diff] [blame] | 2964 | /* This processes *all* regulatory hints */ |
Luis R. Rodriguez | 1daa37c | 2013-11-05 09:18:02 -0800 | [diff] [blame] | 2965 | static void reg_process_hint(struct regulatory_request *reg_request) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2966 | { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2967 | struct wiphy *wiphy = NULL; |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 2968 | enum reg_request_treatment treatment; |
Yu Zhao | 1db5852 | 2018-09-27 17:05:04 -0600 | [diff] [blame] | 2969 | enum nl80211_reg_initiator initiator = reg_request->initiator; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2970 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 2971 | if (reg_request->wiphy_idx != WIPHY_IDX_INVALID) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2972 | wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx); |
| 2973 | |
Yu Zhao | 1db5852 | 2018-09-27 17:05:04 -0600 | [diff] [blame] | 2974 | switch (initiator) { |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 2975 | case NL80211_REGDOM_SET_BY_CORE: |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2976 | treatment = reg_process_hint_core(reg_request); |
| 2977 | break; |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 2978 | case NL80211_REGDOM_SET_BY_USER: |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2979 | treatment = reg_process_hint_user(reg_request); |
| 2980 | break; |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 2981 | case NL80211_REGDOM_SET_BY_DRIVER: |
Ilan Peer | 772f038 | 2014-01-14 15:17:23 +0200 | [diff] [blame] | 2982 | if (!wiphy) |
| 2983 | goto out_free; |
Luis R. Rodriguez | 21636c7 | 2013-11-05 09:18:05 -0800 | [diff] [blame] | 2984 | treatment = reg_process_hint_driver(wiphy, reg_request); |
| 2985 | break; |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 2986 | case NL80211_REGDOM_SET_BY_COUNTRY_IE: |
Ilan Peer | 772f038 | 2014-01-14 15:17:23 +0200 | [diff] [blame] | 2987 | if (!wiphy) |
| 2988 | goto out_free; |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 2989 | treatment = reg_process_hint_country_ie(wiphy, reg_request); |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 2990 | break; |
| 2991 | default: |
Yu Zhao | 1db5852 | 2018-09-27 17:05:04 -0600 | [diff] [blame] | 2992 | WARN(1, "invalid initiator %d\n", initiator); |
Ilan Peer | 772f038 | 2014-01-14 15:17:23 +0200 | [diff] [blame] | 2993 | goto out_free; |
Luis R. Rodriguez | b3eb7f3 | 2013-11-05 09:18:03 -0800 | [diff] [blame] | 2994 | } |
| 2995 | |
Johannes Berg | d34265a | 2015-10-15 13:05:55 +0200 | [diff] [blame] | 2996 | if (treatment == REG_REQ_IGNORE) |
| 2997 | goto out_free; |
| 2998 | |
Johannes Berg | 480908a | 2015-10-15 12:58:58 +0200 | [diff] [blame] | 2999 | WARN(treatment != REG_REQ_OK && treatment != REG_REQ_ALREADY_SET, |
| 3000 | "unexpected treatment value %d\n", treatment); |
| 3001 | |
John Linville | 841b351 | 2015-06-24 11:42:25 -0400 | [diff] [blame] | 3002 | /* This is required so that the orig_* parameters are saved. |
| 3003 | * NOTE: treatment must be set for any case that reaches here! |
| 3004 | */ |
Luis R. Rodriguez | b23e7a9 | 2013-11-05 09:18:06 -0800 | [diff] [blame] | 3005 | if (treatment == REG_REQ_ALREADY_SET && wiphy && |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 3006 | wiphy->regulatory_flags & REGULATORY_STRICT_REG) { |
Yu Zhao | 1db5852 | 2018-09-27 17:05:04 -0600 | [diff] [blame] | 3007 | wiphy_update_regulatory(wiphy, initiator); |
Vasanthakumar Thiagarajan | 8976672 | 2017-02-27 17:04:35 +0530 | [diff] [blame] | 3008 | wiphy_all_share_dfs_chan_state(wiphy); |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 3009 | reg_check_channels(); |
| 3010 | } |
Ilan Peer | 772f038 | 2014-01-14 15:17:23 +0200 | [diff] [blame] | 3011 | |
| 3012 | return; |
| 3013 | |
| 3014 | out_free: |
Arik Nemtsov | c888393 | 2014-04-21 20:39:34 -0700 | [diff] [blame] | 3015 | reg_free_request(reg_request); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3016 | } |
| 3017 | |
Amar Singhal | aced43ce | 2018-04-26 20:13:07 +0300 | [diff] [blame] | 3018 | static void notify_self_managed_wiphys(struct regulatory_request *request) |
| 3019 | { |
| 3020 | struct cfg80211_registered_device *rdev; |
| 3021 | struct wiphy *wiphy; |
| 3022 | |
| 3023 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 3024 | wiphy = &rdev->wiphy; |
| 3025 | if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
Sriram R | c82c06c | 2018-12-06 15:34:57 +0530 | [diff] [blame] | 3026 | request->initiator == NL80211_REGDOM_SET_BY_USER) |
Amar Singhal | aced43ce | 2018-04-26 20:13:07 +0300 | [diff] [blame] | 3027 | reg_call_notifier(wiphy, request); |
| 3028 | } |
| 3029 | } |
| 3030 | |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 3031 | /* |
| 3032 | * Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_* |
| 3033 | * Regulatory hints come on a first come first serve basis and we |
| 3034 | * must process each one atomically. |
| 3035 | */ |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3036 | static void reg_process_pending_hints(void) |
Luis R. Rodriguez | b0e2880 | 2010-11-17 21:46:08 -0800 | [diff] [blame] | 3037 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 3038 | struct regulatory_request *reg_request, *lr; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3039 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 3040 | lr = get_last_request(); |
Luis R. Rodriguez | b0e2880 | 2010-11-17 21:46:08 -0800 | [diff] [blame] | 3041 | |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 3042 | /* When last_request->processed becomes true this will be rescheduled */ |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 3043 | if (lr && !lr->processed) { |
Hodaszi, Robert | 0d31d4d | 2019-06-14 13:16:01 +0000 | [diff] [blame] | 3044 | pr_debug("Pending regulatory request, waiting for it to be processed...\n"); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3045 | return; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3046 | } |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 3047 | |
| 3048 | spin_lock(®_requests_lock); |
| 3049 | |
| 3050 | if (list_empty(®_requests_list)) { |
| 3051 | spin_unlock(®_requests_lock); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3052 | return; |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 3053 | } |
| 3054 | |
| 3055 | reg_request = list_first_entry(®_requests_list, |
| 3056 | struct regulatory_request, |
| 3057 | list); |
| 3058 | list_del_init(®_request->list); |
| 3059 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3060 | spin_unlock(®_requests_lock); |
Luis R. Rodriguez | b0e2880 | 2010-11-17 21:46:08 -0800 | [diff] [blame] | 3061 | |
Amar Singhal | aced43ce | 2018-04-26 20:13:07 +0300 | [diff] [blame] | 3062 | notify_self_managed_wiphys(reg_request); |
Arik Nemtsov | ef51fb1 | 2015-01-07 16:47:20 +0200 | [diff] [blame] | 3063 | |
Luis R. Rodriguez | 1daa37c | 2013-11-05 09:18:02 -0800 | [diff] [blame] | 3064 | reg_process_hint(reg_request); |
Ben | 2e54a68 | 2015-03-12 09:37:34 -0400 | [diff] [blame] | 3065 | |
| 3066 | lr = get_last_request(); |
| 3067 | |
| 3068 | spin_lock(®_requests_lock); |
| 3069 | if (!list_empty(®_requests_list) && lr && lr->processed) |
| 3070 | schedule_work(®_work); |
| 3071 | spin_unlock(®_requests_lock); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3072 | } |
| 3073 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3074 | /* Processes beacon hints -- this has nothing to do with country IEs */ |
| 3075 | static void reg_process_pending_beacon_hints(void) |
| 3076 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3077 | struct cfg80211_registered_device *rdev; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3078 | struct reg_beacon *pending_beacon, *tmp; |
| 3079 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3080 | /* This goes through the _pending_ beacon list */ |
| 3081 | spin_lock_bh(®_pending_beacons_lock); |
| 3082 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3083 | list_for_each_entry_safe(pending_beacon, tmp, |
| 3084 | ®_pending_beacons, list) { |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3085 | list_del_init(&pending_beacon->list); |
| 3086 | |
| 3087 | /* Applies the beacon hint to current wiphys */ |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3088 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) |
| 3089 | wiphy_update_new_beacon(&rdev->wiphy, pending_beacon); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3090 | |
| 3091 | /* Remembers the beacon hint for new wiphys or reg changes */ |
| 3092 | list_add_tail(&pending_beacon->list, ®_beacon_list); |
| 3093 | } |
| 3094 | |
| 3095 | spin_unlock_bh(®_pending_beacons_lock); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3096 | } |
| 3097 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3098 | static void reg_process_self_managed_hint(struct wiphy *wiphy) |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 3099 | { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3100 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 3101 | const struct ieee80211_regdomain *tmp; |
| 3102 | const struct ieee80211_regdomain *regd; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3103 | enum nl80211_band band; |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 3104 | struct regulatory_request request = {}; |
| 3105 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3106 | ASSERT_RTNL(); |
| 3107 | lockdep_assert_wiphy(wiphy); |
| 3108 | |
| 3109 | spin_lock(®_requests_lock); |
| 3110 | regd = rdev->requested_regd; |
| 3111 | rdev->requested_regd = NULL; |
| 3112 | spin_unlock(®_requests_lock); |
| 3113 | |
| 3114 | if (!regd) |
| 3115 | return; |
| 3116 | |
| 3117 | tmp = get_wiphy_regdom(wiphy); |
| 3118 | rcu_assign_pointer(wiphy->regd, regd); |
| 3119 | rcu_free_regdom(tmp); |
| 3120 | |
| 3121 | for (band = 0; band < NUM_NL80211_BANDS; band++) |
| 3122 | handle_band_custom(wiphy, wiphy->bands[band], regd); |
| 3123 | |
| 3124 | reg_process_ht_flags(wiphy); |
| 3125 | |
| 3126 | request.wiphy_idx = get_wiphy_idx(wiphy); |
| 3127 | request.alpha2[0] = regd->alpha2[0]; |
| 3128 | request.alpha2[1] = regd->alpha2[1]; |
| 3129 | request.initiator = NL80211_REGDOM_SET_BY_DRIVER; |
| 3130 | |
| 3131 | nl80211_send_wiphy_reg_change_event(&request); |
| 3132 | } |
| 3133 | |
| 3134 | static void reg_process_self_managed_hints(void) |
| 3135 | { |
| 3136 | struct cfg80211_registered_device *rdev; |
| 3137 | |
| 3138 | ASSERT_RTNL(); |
| 3139 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 3140 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3141 | wiphy_lock(&rdev->wiphy); |
| 3142 | reg_process_self_managed_hint(&rdev->wiphy); |
| 3143 | wiphy_unlock(&rdev->wiphy); |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 3144 | } |
| 3145 | |
| 3146 | reg_check_channels(); |
| 3147 | } |
| 3148 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3149 | static void reg_todo(struct work_struct *work) |
| 3150 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3151 | rtnl_lock(); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3152 | reg_process_pending_hints(); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3153 | reg_process_pending_beacon_hints(); |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 3154 | reg_process_self_managed_hints(); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3155 | rtnl_unlock(); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3156 | } |
| 3157 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3158 | static void queue_regulatory_request(struct regulatory_request *request) |
| 3159 | { |
Johannes Berg | d4f2c88 | 2012-12-03 18:59:58 +0100 | [diff] [blame] | 3160 | request->alpha2[0] = toupper(request->alpha2[0]); |
| 3161 | request->alpha2[1] = toupper(request->alpha2[1]); |
John W. Linville | c61029c | 2010-08-05 14:26:24 -0400 | [diff] [blame] | 3162 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3163 | spin_lock(®_requests_lock); |
| 3164 | list_add_tail(&request->list, ®_requests_list); |
| 3165 | spin_unlock(®_requests_lock); |
| 3166 | |
| 3167 | schedule_work(®_work); |
| 3168 | } |
| 3169 | |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3170 | /* |
| 3171 | * Core regulatory hint -- happens during cfg80211_init() |
| 3172 | * and when we restore regulatory settings. |
| 3173 | */ |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 3174 | static int regulatory_hint_core(const char *alpha2) |
| 3175 | { |
| 3176 | struct regulatory_request *request; |
| 3177 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 3178 | request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 3179 | if (!request) |
| 3180 | return -ENOMEM; |
| 3181 | |
| 3182 | request->alpha2[0] = alpha2[0]; |
| 3183 | request->alpha2[1] = alpha2[1]; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 3184 | request->initiator = NL80211_REGDOM_SET_BY_CORE; |
Andrei Otcheretianski | 24f33e6 | 2018-09-05 08:06:12 +0300 | [diff] [blame] | 3185 | request->wiphy_idx = WIPHY_IDX_INVALID; |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 3186 | |
Luis R. Rodriguez | 31e9972 | 2010-11-17 21:46:06 -0800 | [diff] [blame] | 3187 | queue_regulatory_request(request); |
Luis R. Rodriguez | 5078b2e | 2009-05-13 17:04:42 -0400 | [diff] [blame] | 3188 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3189 | return 0; |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 3190 | } |
| 3191 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3192 | /* User hints */ |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3193 | int regulatory_hint_user(const char *alpha2, |
| 3194 | enum nl80211_user_reg_hint_type user_reg_hint_type) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3195 | { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3196 | struct regulatory_request *request; |
| 3197 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 3198 | if (WARN_ON(!alpha2)) |
| 3199 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3200 | |
Johannes Berg | 47caf68 | 2020-08-19 10:46:48 +0200 | [diff] [blame] | 3201 | if (!is_world_regdom(alpha2) && !is_an_alpha2(alpha2)) |
| 3202 | return -EINVAL; |
| 3203 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3204 | request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); |
| 3205 | if (!request) |
| 3206 | return -ENOMEM; |
| 3207 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 3208 | request->wiphy_idx = WIPHY_IDX_INVALID; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3209 | request->alpha2[0] = alpha2[0]; |
| 3210 | request->alpha2[1] = alpha2[1]; |
Luis R. Rodriguez | e12822e | 2010-01-04 11:37:39 -0500 | [diff] [blame] | 3211 | request->initiator = NL80211_REGDOM_SET_BY_USER; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3212 | request->user_reg_hint_type = user_reg_hint_type; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3213 | |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 3214 | /* Allow calling CRDA again */ |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 3215 | reset_crda_timeouts(); |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 3216 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3217 | queue_regulatory_request(request); |
| 3218 | |
| 3219 | return 0; |
| 3220 | } |
| 3221 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 3222 | int regulatory_hint_indoor(bool is_indoor, u32 portid) |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 3223 | { |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 3224 | spin_lock(®_indoor_lock); |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 3225 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 3226 | /* It is possible that more than one user space process is trying to |
| 3227 | * configure the indoor setting. To handle such cases, clear the indoor |
| 3228 | * setting in case that some process does not think that the device |
| 3229 | * is operating in an indoor environment. In addition, if a user space |
| 3230 | * process indicates that it is controlling the indoor setting, save its |
| 3231 | * portid, i.e., make it the owner. |
| 3232 | */ |
| 3233 | reg_is_indoor = is_indoor; |
| 3234 | if (reg_is_indoor) { |
| 3235 | if (!reg_is_indoor_portid) |
| 3236 | reg_is_indoor_portid = portid; |
| 3237 | } else { |
| 3238 | reg_is_indoor_portid = 0; |
| 3239 | } |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 3240 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 3241 | spin_unlock(®_indoor_lock); |
| 3242 | |
| 3243 | if (!is_indoor) |
| 3244 | reg_check_channels(); |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 3245 | |
| 3246 | return 0; |
| 3247 | } |
| 3248 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 3249 | void regulatory_netlink_notify(u32 portid) |
| 3250 | { |
| 3251 | spin_lock(®_indoor_lock); |
| 3252 | |
| 3253 | if (reg_is_indoor_portid != portid) { |
| 3254 | spin_unlock(®_indoor_lock); |
| 3255 | return; |
| 3256 | } |
| 3257 | |
| 3258 | reg_is_indoor = false; |
| 3259 | reg_is_indoor_portid = 0; |
| 3260 | |
| 3261 | spin_unlock(®_indoor_lock); |
| 3262 | |
| 3263 | reg_check_channels(); |
| 3264 | } |
| 3265 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3266 | /* Driver hints */ |
| 3267 | int regulatory_hint(struct wiphy *wiphy, const char *alpha2) |
| 3268 | { |
| 3269 | struct regulatory_request *request; |
| 3270 | |
Johannes Berg | fdc9d7b | 2012-12-03 18:36:09 +0100 | [diff] [blame] | 3271 | if (WARN_ON(!alpha2 || !wiphy)) |
| 3272 | return -EINVAL; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3273 | |
Luis R. Rodriguez | 4f7b914 | 2013-12-14 20:09:06 +0100 | [diff] [blame] | 3274 | wiphy->regulatory_flags &= ~REGULATORY_CUSTOM_REG; |
| 3275 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3276 | request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); |
| 3277 | if (!request) |
| 3278 | return -ENOMEM; |
| 3279 | |
| 3280 | request->wiphy_idx = get_wiphy_idx(wiphy); |
| 3281 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3282 | request->alpha2[0] = alpha2[0]; |
| 3283 | request->alpha2[1] = alpha2[1]; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 3284 | request->initiator = NL80211_REGDOM_SET_BY_DRIVER; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3285 | |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 3286 | /* Allow calling CRDA again */ |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 3287 | reset_crda_timeouts(); |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 3288 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3289 | queue_regulatory_request(request); |
| 3290 | |
| 3291 | return 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3292 | } |
| 3293 | EXPORT_SYMBOL(regulatory_hint); |
| 3294 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3295 | void regulatory_hint_country_ie(struct wiphy *wiphy, enum nl80211_band band, |
Luis R. Rodriguez | 789fd03 | 2013-10-04 18:07:24 -0700 | [diff] [blame] | 3296 | const u8 *country_ie, u8 country_ie_len) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3297 | { |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3298 | char alpha2[2]; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3299 | enum environment_cap env = ENVIRON_ANY; |
Johannes Berg | db2424c | 2013-05-10 19:07:52 +0200 | [diff] [blame] | 3300 | struct regulatory_request *request = NULL, *lr; |
Luis R. Rodriguez | d335fe6 | 2009-02-21 00:04:27 -0500 | [diff] [blame] | 3301 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3302 | /* IE len must be evenly divisible by 2 */ |
| 3303 | if (country_ie_len & 0x01) |
Johannes Berg | db2424c | 2013-05-10 19:07:52 +0200 | [diff] [blame] | 3304 | return; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3305 | |
| 3306 | if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) |
Johannes Berg | db2424c | 2013-05-10 19:07:52 +0200 | [diff] [blame] | 3307 | return; |
| 3308 | |
| 3309 | request = kzalloc(sizeof(*request), GFP_KERNEL); |
| 3310 | if (!request) |
| 3311 | return; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3312 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3313 | alpha2[0] = country_ie[0]; |
| 3314 | alpha2[1] = country_ie[1]; |
| 3315 | |
| 3316 | if (country_ie[2] == 'I') |
| 3317 | env = ENVIRON_INDOOR; |
| 3318 | else if (country_ie[2] == 'O') |
| 3319 | env = ENVIRON_OUTDOOR; |
| 3320 | |
Johannes Berg | db2424c | 2013-05-10 19:07:52 +0200 | [diff] [blame] | 3321 | rcu_read_lock(); |
| 3322 | lr = get_last_request(); |
| 3323 | |
| 3324 | if (unlikely(!lr)) |
| 3325 | goto out; |
| 3326 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 3327 | /* |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 3328 | * We will run this only upon a successful connection on cfg80211. |
Luis R. Rodriguez | 4b44c8b | 2009-07-30 17:38:07 -0700 | [diff] [blame] | 3329 | * We leave conflict resolution to the workqueue, where can hold |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3330 | * the RTNL. |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 3331 | */ |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 3332 | if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && |
| 3333 | lr->wiphy_idx != WIPHY_IDX_INVALID) |
Luis R. Rodriguez | 4b44c8b | 2009-07-30 17:38:07 -0700 | [diff] [blame] | 3334 | goto out; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3335 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3336 | request->wiphy_idx = get_wiphy_idx(wiphy); |
John W. Linville | 4f366c5 | 2010-07-15 14:57:33 -0400 | [diff] [blame] | 3337 | request->alpha2[0] = alpha2[0]; |
| 3338 | request->alpha2[1] = alpha2[1]; |
Luis R. Rodriguez | 7db90f4 | 2009-03-09 22:07:41 -0400 | [diff] [blame] | 3339 | request->initiator = NL80211_REGDOM_SET_BY_COUNTRY_IE; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3340 | request->country_ie_env = env; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3341 | |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 3342 | /* Allow calling CRDA again */ |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 3343 | reset_crda_timeouts(); |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 3344 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3345 | queue_regulatory_request(request); |
Johannes Berg | db2424c | 2013-05-10 19:07:52 +0200 | [diff] [blame] | 3346 | request = NULL; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3347 | out: |
Johannes Berg | db2424c | 2013-05-10 19:07:52 +0200 | [diff] [blame] | 3348 | kfree(request); |
| 3349 | rcu_read_unlock(); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3350 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3351 | |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3352 | static void restore_alpha2(char *alpha2, bool reset_user) |
| 3353 | { |
| 3354 | /* indicates there is no alpha2 to consider for restoration */ |
| 3355 | alpha2[0] = '9'; |
| 3356 | alpha2[1] = '7'; |
| 3357 | |
| 3358 | /* The user setting has precedence over the module parameter */ |
| 3359 | if (is_user_regdom_saved()) { |
| 3360 | /* Unless we're asked to ignore it and reset it */ |
| 3361 | if (reset_user) { |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 3362 | pr_debug("Restoring regulatory settings including user preference\n"); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3363 | user_alpha2[0] = '9'; |
| 3364 | user_alpha2[1] = '7'; |
| 3365 | |
| 3366 | /* |
| 3367 | * If we're ignoring user settings, we still need to |
| 3368 | * check the module parameter to ensure we put things |
| 3369 | * back as they were for a full restore. |
| 3370 | */ |
| 3371 | if (!is_world_regdom(ieee80211_regdom)) { |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 3372 | pr_debug("Keeping preference on module parameter ieee80211_regdom: %c%c\n", |
| 3373 | ieee80211_regdom[0], ieee80211_regdom[1]); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3374 | alpha2[0] = ieee80211_regdom[0]; |
| 3375 | alpha2[1] = ieee80211_regdom[1]; |
| 3376 | } |
| 3377 | } else { |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 3378 | pr_debug("Restoring regulatory settings while preserving user preference for: %c%c\n", |
| 3379 | user_alpha2[0], user_alpha2[1]); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3380 | alpha2[0] = user_alpha2[0]; |
| 3381 | alpha2[1] = user_alpha2[1]; |
| 3382 | } |
| 3383 | } else if (!is_world_regdom(ieee80211_regdom)) { |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 3384 | pr_debug("Keeping preference on module parameter ieee80211_regdom: %c%c\n", |
| 3385 | ieee80211_regdom[0], ieee80211_regdom[1]); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3386 | alpha2[0] = ieee80211_regdom[0]; |
| 3387 | alpha2[1] = ieee80211_regdom[1]; |
| 3388 | } else |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 3389 | pr_debug("Restoring regulatory settings\n"); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3390 | } |
| 3391 | |
Rajkumar Manoharan | 5ce543d | 2011-12-07 21:50:08 +0530 | [diff] [blame] | 3392 | static void restore_custom_reg_settings(struct wiphy *wiphy) |
| 3393 | { |
| 3394 | struct ieee80211_supported_band *sband; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3395 | enum nl80211_band band; |
Rajkumar Manoharan | 5ce543d | 2011-12-07 21:50:08 +0530 | [diff] [blame] | 3396 | struct ieee80211_channel *chan; |
| 3397 | int i; |
| 3398 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3399 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Rajkumar Manoharan | 5ce543d | 2011-12-07 21:50:08 +0530 | [diff] [blame] | 3400 | sband = wiphy->bands[band]; |
| 3401 | if (!sband) |
| 3402 | continue; |
| 3403 | for (i = 0; i < sband->n_channels; i++) { |
| 3404 | chan = &sband->channels[i]; |
| 3405 | chan->flags = chan->orig_flags; |
| 3406 | chan->max_antenna_gain = chan->orig_mag; |
| 3407 | chan->max_power = chan->orig_mpwr; |
Paul Stewart | 899852a | 2012-08-01 16:54:42 -0700 | [diff] [blame] | 3408 | chan->beacon_found = false; |
Rajkumar Manoharan | 5ce543d | 2011-12-07 21:50:08 +0530 | [diff] [blame] | 3409 | } |
| 3410 | } |
| 3411 | } |
| 3412 | |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3413 | /* |
Bhaskar Chowdhury | f2e3093 | 2021-03-27 04:42:51 +0530 | [diff] [blame] | 3414 | * Restoring regulatory settings involves ignoring any |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3415 | * possibly stale country IE information and user regulatory |
| 3416 | * settings if so desired, this includes any beacon hints |
| 3417 | * learned as we could have traveled outside to another country |
| 3418 | * after disconnection. To restore regulatory settings we do |
| 3419 | * exactly what we did at bootup: |
| 3420 | * |
| 3421 | * - send a core regulatory hint |
| 3422 | * - send a user regulatory hint if applicable |
| 3423 | * |
| 3424 | * Device drivers that send a regulatory hint for a specific country |
Randy Dunlap | cc5a639b | 2020-08-22 16:19:50 -0700 | [diff] [blame] | 3425 | * keep their own regulatory domain on wiphy->regd so that does |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3426 | * not need to be remembered. |
| 3427 | */ |
Johannes Berg | e646a02 | 2019-02-05 21:08:29 +0100 | [diff] [blame] | 3428 | static void restore_regulatory_settings(bool reset_user, bool cached) |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3429 | { |
| 3430 | char alpha2[2]; |
Dmitry Shmidt | cee0bec | 2011-12-19 12:32:21 -0800 | [diff] [blame] | 3431 | char world_alpha2[2]; |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3432 | struct reg_beacon *reg_beacon, *btmp; |
Luis R. Rodriguez | 1460955 | 2011-04-05 10:49:03 -0700 | [diff] [blame] | 3433 | LIST_HEAD(tmp_reg_req_list); |
Rajkumar Manoharan | 5ce543d | 2011-12-07 21:50:08 +0530 | [diff] [blame] | 3434 | struct cfg80211_registered_device *rdev; |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3435 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3436 | ASSERT_RTNL(); |
| 3437 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 3438 | /* |
| 3439 | * Clear the indoor setting in case that it is not controlled by user |
| 3440 | * space, as otherwise there is no guarantee that the device is still |
| 3441 | * operating in an indoor environment. |
| 3442 | */ |
| 3443 | spin_lock(®_indoor_lock); |
| 3444 | if (reg_is_indoor && !reg_is_indoor_portid) { |
| 3445 | reg_is_indoor = false; |
| 3446 | reg_check_channels(); |
| 3447 | } |
| 3448 | spin_unlock(®_indoor_lock); |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 3449 | |
Johannes Berg | 2d31986 | 2013-01-09 12:01:38 +0100 | [diff] [blame] | 3450 | reset_regdomains(true, &world_regdom); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3451 | restore_alpha2(alpha2, reset_user); |
| 3452 | |
Luis R. Rodriguez | 1460955 | 2011-04-05 10:49:03 -0700 | [diff] [blame] | 3453 | /* |
| 3454 | * If there's any pending requests we simply |
| 3455 | * stash them to a temporary pending queue and |
| 3456 | * add then after we've restored regulatory |
| 3457 | * settings. |
| 3458 | */ |
| 3459 | spin_lock(®_requests_lock); |
Ilan peer | eeca9fc | 2015-03-04 00:32:07 -0500 | [diff] [blame] | 3460 | list_splice_tail_init(®_requests_list, &tmp_reg_req_list); |
Luis R. Rodriguez | 1460955 | 2011-04-05 10:49:03 -0700 | [diff] [blame] | 3461 | spin_unlock(®_requests_lock); |
| 3462 | |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3463 | /* Clear beacon hints */ |
| 3464 | spin_lock_bh(®_pending_beacons_lock); |
Johannes Berg | fea9bce | 2012-12-03 17:32:01 +0100 | [diff] [blame] | 3465 | list_for_each_entry_safe(reg_beacon, btmp, ®_pending_beacons, list) { |
| 3466 | list_del(®_beacon->list); |
| 3467 | kfree(reg_beacon); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3468 | } |
| 3469 | spin_unlock_bh(®_pending_beacons_lock); |
| 3470 | |
Johannes Berg | fea9bce | 2012-12-03 17:32:01 +0100 | [diff] [blame] | 3471 | list_for_each_entry_safe(reg_beacon, btmp, ®_beacon_list, list) { |
| 3472 | list_del(®_beacon->list); |
| 3473 | kfree(reg_beacon); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | /* First restore to the basic regulatory settings */ |
Johannes Berg | 379b82f | 2012-12-06 15:44:07 +0100 | [diff] [blame] | 3477 | world_alpha2[0] = cfg80211_world_regdom->alpha2[0]; |
| 3478 | world_alpha2[1] = cfg80211_world_regdom->alpha2[1]; |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3479 | |
Rajkumar Manoharan | 5ce543d | 2011-12-07 21:50:08 +0530 | [diff] [blame] | 3480 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 3481 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) |
| 3482 | continue; |
Luis R. Rodriguez | a2f73b6 | 2013-11-11 22:15:29 +0100 | [diff] [blame] | 3483 | if (rdev->wiphy.regulatory_flags & REGULATORY_CUSTOM_REG) |
Rajkumar Manoharan | 5ce543d | 2011-12-07 21:50:08 +0530 | [diff] [blame] | 3484 | restore_custom_reg_settings(&rdev->wiphy); |
| 3485 | } |
| 3486 | |
Johannes Berg | e646a02 | 2019-02-05 21:08:29 +0100 | [diff] [blame] | 3487 | if (cached && (!is_an_alpha2(alpha2) || |
| 3488 | !IS_ERR_OR_NULL(cfg80211_user_regdom))) { |
| 3489 | reset_regdomains(false, cfg80211_world_regdom); |
| 3490 | update_all_wiphy_regulatory(NL80211_REGDOM_SET_BY_CORE); |
| 3491 | print_regdomain(get_cfg80211_regdom()); |
| 3492 | nl80211_send_reg_change_event(&core_request_world); |
| 3493 | reg_set_request_processed(); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3494 | |
Johannes Berg | e646a02 | 2019-02-05 21:08:29 +0100 | [diff] [blame] | 3495 | if (is_an_alpha2(alpha2) && |
| 3496 | !regulatory_hint_user(alpha2, NL80211_USER_REG_HINT_USER)) { |
| 3497 | struct regulatory_request *ureq; |
| 3498 | |
| 3499 | spin_lock(®_requests_lock); |
| 3500 | ureq = list_last_entry(®_requests_list, |
| 3501 | struct regulatory_request, |
| 3502 | list); |
| 3503 | list_del(&ureq->list); |
| 3504 | spin_unlock(®_requests_lock); |
| 3505 | |
| 3506 | notify_self_managed_wiphys(ureq); |
| 3507 | reg_update_last_request(ureq); |
| 3508 | set_regdom(reg_copy_regd(cfg80211_user_regdom), |
| 3509 | REGD_SOURCE_CACHED); |
| 3510 | } |
| 3511 | } else { |
| 3512 | regulatory_hint_core(world_alpha2); |
| 3513 | |
| 3514 | /* |
| 3515 | * This restores the ieee80211_regdom module parameter |
| 3516 | * preference or the last user requested regulatory |
| 3517 | * settings, user regulatory settings takes precedence. |
| 3518 | */ |
| 3519 | if (is_an_alpha2(alpha2)) |
| 3520 | regulatory_hint_user(alpha2, NL80211_USER_REG_HINT_USER); |
| 3521 | } |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3522 | |
Luis R. Rodriguez | 1460955 | 2011-04-05 10:49:03 -0700 | [diff] [blame] | 3523 | spin_lock(®_requests_lock); |
Johannes Berg | 11cff96 | 2012-12-03 18:56:41 +0100 | [diff] [blame] | 3524 | list_splice_tail_init(&tmp_reg_req_list, ®_requests_list); |
Luis R. Rodriguez | 1460955 | 2011-04-05 10:49:03 -0700 | [diff] [blame] | 3525 | spin_unlock(®_requests_lock); |
| 3526 | |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 3527 | pr_debug("Kicking the queue\n"); |
Luis R. Rodriguez | 1460955 | 2011-04-05 10:49:03 -0700 | [diff] [blame] | 3528 | |
| 3529 | schedule_work(®_work); |
| 3530 | } |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3531 | |
Rajeev Kumar Sirasanagandla | 7417844 | 2018-07-10 18:46:13 +0530 | [diff] [blame] | 3532 | static bool is_wiphy_all_set_reg_flag(enum ieee80211_regulatory_flags flag) |
| 3533 | { |
| 3534 | struct cfg80211_registered_device *rdev; |
| 3535 | struct wireless_dev *wdev; |
| 3536 | |
| 3537 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 3538 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
| 3539 | wdev_lock(wdev); |
| 3540 | if (!(wdev->wiphy->regulatory_flags & flag)) { |
| 3541 | wdev_unlock(wdev); |
| 3542 | return false; |
| 3543 | } |
| 3544 | wdev_unlock(wdev); |
| 3545 | } |
| 3546 | } |
| 3547 | |
| 3548 | return true; |
| 3549 | } |
| 3550 | |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3551 | void regulatory_hint_disconnect(void) |
| 3552 | { |
Rajeev Kumar Sirasanagandla | 7417844 | 2018-07-10 18:46:13 +0530 | [diff] [blame] | 3553 | /* Restore of regulatory settings is not required when wiphy(s) |
| 3554 | * ignore IE from connected access point but clearance of beacon hints |
| 3555 | * is required when wiphy(s) supports beacon hints. |
| 3556 | */ |
| 3557 | if (is_wiphy_all_set_reg_flag(REGULATORY_COUNTRY_IE_IGNORE)) { |
| 3558 | struct reg_beacon *reg_beacon, *btmp; |
| 3559 | |
| 3560 | if (is_wiphy_all_set_reg_flag(REGULATORY_DISABLE_BEACON_HINTS)) |
| 3561 | return; |
| 3562 | |
| 3563 | spin_lock_bh(®_pending_beacons_lock); |
| 3564 | list_for_each_entry_safe(reg_beacon, btmp, |
| 3565 | ®_pending_beacons, list) { |
| 3566 | list_del(®_beacon->list); |
| 3567 | kfree(reg_beacon); |
| 3568 | } |
| 3569 | spin_unlock_bh(®_pending_beacons_lock); |
| 3570 | |
| 3571 | list_for_each_entry_safe(reg_beacon, btmp, |
| 3572 | ®_beacon_list, list) { |
| 3573 | list_del(®_beacon->list); |
| 3574 | kfree(reg_beacon); |
| 3575 | } |
| 3576 | |
| 3577 | return; |
| 3578 | } |
| 3579 | |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 3580 | pr_debug("All devices are disconnected, going to restore regulatory settings\n"); |
Johannes Berg | e646a02 | 2019-02-05 21:08:29 +0100 | [diff] [blame] | 3581 | restore_regulatory_settings(false, true); |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 3582 | } |
| 3583 | |
Alexei Avshalom Lazar | 9cf0a0b | 2018-08-13 15:33:00 +0300 | [diff] [blame] | 3584 | static bool freq_is_chan_12_13_14(u32 freq) |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3585 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3586 | if (freq == ieee80211_channel_to_frequency(12, NL80211_BAND_2GHZ) || |
| 3587 | freq == ieee80211_channel_to_frequency(13, NL80211_BAND_2GHZ) || |
| 3588 | freq == ieee80211_channel_to_frequency(14, NL80211_BAND_2GHZ)) |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3589 | return true; |
| 3590 | return false; |
| 3591 | } |
| 3592 | |
Luis R. Rodriguez | 3ebfa6e | 2012-12-19 10:53:02 -0800 | [diff] [blame] | 3593 | static bool pending_reg_beacon(struct ieee80211_channel *beacon_chan) |
| 3594 | { |
| 3595 | struct reg_beacon *pending_beacon; |
| 3596 | |
| 3597 | list_for_each_entry(pending_beacon, ®_pending_beacons, list) |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 3598 | if (ieee80211_channel_equal(beacon_chan, |
| 3599 | &pending_beacon->chan)) |
Luis R. Rodriguez | 3ebfa6e | 2012-12-19 10:53:02 -0800 | [diff] [blame] | 3600 | return true; |
| 3601 | return false; |
| 3602 | } |
| 3603 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3604 | int regulatory_hint_found_beacon(struct wiphy *wiphy, |
| 3605 | struct ieee80211_channel *beacon_chan, |
| 3606 | gfp_t gfp) |
| 3607 | { |
| 3608 | struct reg_beacon *reg_beacon; |
Luis R. Rodriguez | 3ebfa6e | 2012-12-19 10:53:02 -0800 | [diff] [blame] | 3609 | bool processing; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3610 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 3611 | if (beacon_chan->beacon_found || |
| 3612 | beacon_chan->flags & IEEE80211_CHAN_RADAR || |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3613 | (beacon_chan->band == NL80211_BAND_2GHZ && |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 3614 | !freq_is_chan_12_13_14(beacon_chan->center_freq))) |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3615 | return 0; |
| 3616 | |
Luis R. Rodriguez | 3ebfa6e | 2012-12-19 10:53:02 -0800 | [diff] [blame] | 3617 | spin_lock_bh(®_pending_beacons_lock); |
| 3618 | processing = pending_reg_beacon(beacon_chan); |
| 3619 | spin_unlock_bh(®_pending_beacons_lock); |
| 3620 | |
| 3621 | if (processing) |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3622 | return 0; |
| 3623 | |
| 3624 | reg_beacon = kzalloc(sizeof(struct reg_beacon), gfp); |
| 3625 | if (!reg_beacon) |
| 3626 | return -ENOMEM; |
| 3627 | |
Thomas Pedersen | 934f4c7 | 2020-04-01 18:18:03 -0700 | [diff] [blame] | 3628 | pr_debug("Found new beacon on frequency: %d.%03d MHz (Ch %d) on %s\n", |
| 3629 | beacon_chan->center_freq, beacon_chan->freq_offset, |
| 3630 | ieee80211_freq_khz_to_channel( |
| 3631 | ieee80211_channel_to_khz(beacon_chan)), |
Johannes Berg | c799ba6 | 2015-12-11 15:31:10 +0100 | [diff] [blame] | 3632 | wiphy_name(wiphy)); |
Luis R. Rodriguez | 4113f75 | 2010-01-04 11:50:11 -0500 | [diff] [blame] | 3633 | |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3634 | memcpy(®_beacon->chan, beacon_chan, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 3635 | sizeof(struct ieee80211_channel)); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 3636 | |
| 3637 | /* |
| 3638 | * Since we can be called from BH or and non-BH context |
| 3639 | * we must use spin_lock_bh() |
| 3640 | */ |
| 3641 | spin_lock_bh(®_pending_beacons_lock); |
| 3642 | list_add_tail(®_beacon->list, ®_pending_beacons); |
| 3643 | spin_unlock_bh(®_pending_beacons_lock); |
| 3644 | |
| 3645 | schedule_work(®_work); |
| 3646 | |
| 3647 | return 0; |
| 3648 | } |
| 3649 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 3650 | static void print_rd_rules(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3651 | { |
| 3652 | unsigned int i; |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 3653 | const struct ieee80211_reg_rule *reg_rule = NULL; |
| 3654 | const struct ieee80211_freq_range *freq_range = NULL; |
| 3655 | const struct ieee80211_power_rule *power_rule = NULL; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 3656 | char bw[32], cac_time[32]; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3657 | |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3658 | pr_debug(" (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] | 3659 | |
| 3660 | for (i = 0; i < rd->n_reg_rules; i++) { |
| 3661 | reg_rule = &rd->reg_rules[i]; |
| 3662 | freq_range = ®_rule->freq_range; |
| 3663 | power_rule = ®_rule->power_rule; |
| 3664 | |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 3665 | if (reg_rule->flags & NL80211_RRF_AUTO_BW) |
Ye Bin | db18d20 | 2020-10-09 15:02:15 +0800 | [diff] [blame] | 3666 | snprintf(bw, sizeof(bw), "%d KHz, %u KHz AUTO", |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 3667 | freq_range->max_bandwidth_khz, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 3668 | reg_get_max_bandwidth(rd, reg_rule)); |
| 3669 | else |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 3670 | snprintf(bw, sizeof(bw), "%d KHz", |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 3671 | freq_range->max_bandwidth_khz); |
| 3672 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 3673 | if (reg_rule->flags & NL80211_RRF_DFS) |
| 3674 | scnprintf(cac_time, sizeof(cac_time), "%u s", |
| 3675 | reg_rule->dfs_cac_ms/1000); |
| 3676 | else |
| 3677 | scnprintf(cac_time, sizeof(cac_time), "N/A"); |
| 3678 | |
| 3679 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 3680 | /* |
| 3681 | * There may not be documentation for max antenna gain |
| 3682 | * in certain regions |
| 3683 | */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3684 | if (power_rule->max_antenna_gain) |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3685 | pr_debug(" (%d KHz - %d KHz @ %s), (%d mBi, %d mBm), (%s)\n", |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3686 | freq_range->start_freq_khz, |
| 3687 | freq_range->end_freq_khz, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 3688 | bw, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3689 | power_rule->max_antenna_gain, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 3690 | power_rule->max_eirp, |
| 3691 | cac_time); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3692 | else |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3693 | pr_debug(" (%d KHz - %d KHz @ %s), (N/A, %d mBm), (%s)\n", |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3694 | freq_range->start_freq_khz, |
| 3695 | freq_range->end_freq_khz, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 3696 | bw, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 3697 | power_rule->max_eirp, |
| 3698 | cac_time); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3699 | } |
| 3700 | } |
| 3701 | |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 3702 | bool reg_supported_dfs_region(enum nl80211_dfs_regions dfs_region) |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3703 | { |
| 3704 | switch (dfs_region) { |
| 3705 | case NL80211_DFS_UNSET: |
| 3706 | case NL80211_DFS_FCC: |
| 3707 | case NL80211_DFS_ETSI: |
| 3708 | case NL80211_DFS_JP: |
| 3709 | return true; |
| 3710 | default: |
Colin Ian King | 4a22b00 | 2018-05-11 14:25:42 +0100 | [diff] [blame] | 3711 | pr_debug("Ignoring unknown DFS master region: %d\n", dfs_region); |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3712 | return false; |
| 3713 | } |
| 3714 | } |
| 3715 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 3716 | static void print_regdomain(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3717 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 3718 | struct regulatory_request *lr = get_last_request(); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3719 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3720 | if (is_intersected_alpha2(rd->alpha2)) { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 3721 | if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3722 | struct cfg80211_registered_device *rdev; |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 3723 | rdev = cfg80211_rdev_by_wiphy_idx(lr->wiphy_idx); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3724 | if (rdev) { |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3725 | pr_debug("Current regulatory domain updated by AP to: %c%c\n", |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3726 | rdev->country_ie_alpha2[0], |
| 3727 | rdev->country_ie_alpha2[1]); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3728 | } else |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3729 | pr_debug("Current regulatory domain intersected:\n"); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 3730 | } else |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3731 | pr_debug("Current regulatory domain intersected:\n"); |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 3732 | } else if (is_world_regdom(rd->alpha2)) { |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3733 | pr_debug("World regulatory domain updated:\n"); |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 3734 | } else { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3735 | if (is_unknown_alpha2(rd->alpha2)) |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3736 | pr_debug("Regulatory domain changed to driver built-in settings (unknown country)\n"); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3737 | else { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 3738 | if (reg_request_cell_base(lr)) |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3739 | pr_debug("Regulatory domain changed to country: %c%c by Cell Station\n", |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3740 | rd->alpha2[0], rd->alpha2[1]); |
| 3741 | else |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3742 | pr_debug("Regulatory domain changed to country: %c%c\n", |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 3743 | rd->alpha2[0], rd->alpha2[1]); |
| 3744 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3745 | } |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 3746 | |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3747 | pr_debug(" DFS Master region: %s", reg_dfs_region_str(rd->dfs_region)); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3748 | print_rd_rules(rd); |
| 3749 | } |
| 3750 | |
Johannes Berg | 2df7816 | 2008-10-28 16:49:41 +0100 | [diff] [blame] | 3751 | static void print_regdomain_info(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3752 | { |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3753 | pr_debug("Regulatory domain: %c%c\n", rd->alpha2[0], rd->alpha2[1]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3754 | print_rd_rules(rd); |
| 3755 | } |
| 3756 | |
Luis R. Rodriguez | 3b9e5ac | 2013-11-05 09:18:14 -0800 | [diff] [blame] | 3757 | static int reg_set_rd_core(const struct ieee80211_regdomain *rd) |
| 3758 | { |
| 3759 | if (!is_world_regdom(rd->alpha2)) |
| 3760 | return -EINVAL; |
| 3761 | update_world_regdomain(rd); |
| 3762 | return 0; |
| 3763 | } |
| 3764 | |
Luis R. Rodriguez | 84721d4 | 2013-11-05 09:18:15 -0800 | [diff] [blame] | 3765 | static int reg_set_rd_user(const struct ieee80211_regdomain *rd, |
| 3766 | struct regulatory_request *user_request) |
| 3767 | { |
| 3768 | const struct ieee80211_regdomain *intersected_rd = NULL; |
| 3769 | |
Luis R. Rodriguez | 84721d4 | 2013-11-05 09:18:15 -0800 | [diff] [blame] | 3770 | if (!regdom_changes(rd->alpha2)) |
| 3771 | return -EALREADY; |
| 3772 | |
| 3773 | if (!is_valid_rd(rd)) { |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3774 | pr_err("Invalid regulatory domain detected: %c%c\n", |
| 3775 | rd->alpha2[0], rd->alpha2[1]); |
Luis R. Rodriguez | 84721d4 | 2013-11-05 09:18:15 -0800 | [diff] [blame] | 3776 | print_regdomain_info(rd); |
| 3777 | return -EINVAL; |
| 3778 | } |
| 3779 | |
| 3780 | if (!user_request->intersect) { |
| 3781 | reset_regdomains(false, rd); |
| 3782 | return 0; |
| 3783 | } |
| 3784 | |
| 3785 | intersected_rd = regdom_intersect(rd, get_cfg80211_regdom()); |
| 3786 | if (!intersected_rd) |
| 3787 | return -EINVAL; |
| 3788 | |
| 3789 | kfree(rd); |
| 3790 | rd = NULL; |
| 3791 | reset_regdomains(false, intersected_rd); |
| 3792 | |
| 3793 | return 0; |
| 3794 | } |
| 3795 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3796 | static int reg_set_rd_driver(const struct ieee80211_regdomain *rd, |
| 3797 | struct regulatory_request *driver_request) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3798 | { |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 3799 | const struct ieee80211_regdomain *regd; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 3800 | const struct ieee80211_regdomain *intersected_rd = NULL; |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3801 | const struct ieee80211_regdomain *tmp; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 3802 | struct wiphy *request_wiphy; |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 3803 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3804 | if (is_world_regdom(rd->alpha2)) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3805 | return -EINVAL; |
| 3806 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3807 | if (!regdom_changes(rd->alpha2)) |
| 3808 | return -EALREADY; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3809 | |
Luis R. Rodriguez | 8375af3 | 2008-11-12 14:21:57 -0800 | [diff] [blame] | 3810 | if (!is_valid_rd(rd)) { |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3811 | pr_err("Invalid regulatory domain detected: %c%c\n", |
| 3812 | rd->alpha2[0], rd->alpha2[1]); |
Luis R. Rodriguez | 8375af3 | 2008-11-12 14:21:57 -0800 | [diff] [blame] | 3813 | print_regdomain_info(rd); |
| 3814 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3815 | } |
| 3816 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3817 | request_wiphy = wiphy_idx_to_wiphy(driver_request->wiphy_idx); |
Johannes Berg | 922ec58 | 2015-10-15 09:12:49 +0200 | [diff] [blame] | 3818 | if (!request_wiphy) |
Johannes Berg | de3584b | 2011-11-21 10:44:00 +0100 | [diff] [blame] | 3819 | return -ENODEV; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 3820 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3821 | if (!driver_request->intersect) { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3822 | ASSERT_RTNL(); |
| 3823 | wiphy_lock(request_wiphy); |
| 3824 | if (request_wiphy->regd) { |
| 3825 | wiphy_unlock(request_wiphy); |
Luis R. Rodriguez | 558f6d3 | 2009-06-08 18:54:37 -0700 | [diff] [blame] | 3826 | return -EALREADY; |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3827 | } |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 3828 | |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 3829 | regd = reg_copy_regd(rd); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3830 | if (IS_ERR(regd)) { |
| 3831 | wiphy_unlock(request_wiphy); |
Johannes Berg | e9763c3 | 2012-12-03 16:59:46 +0100 | [diff] [blame] | 3832 | return PTR_ERR(regd); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3833 | } |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 3834 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 3835 | rcu_assign_pointer(request_wiphy->regd, regd); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3836 | wiphy_unlock(request_wiphy); |
Johannes Berg | 379b82f | 2012-12-06 15:44:07 +0100 | [diff] [blame] | 3837 | reset_regdomains(false, rd); |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 3838 | return 0; |
| 3839 | } |
| 3840 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3841 | intersected_rd = regdom_intersect(rd, get_cfg80211_regdom()); |
| 3842 | if (!intersected_rd) |
| 3843 | return -EINVAL; |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 3844 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3845 | /* |
| 3846 | * We can trash what CRDA provided now. |
| 3847 | * However if a driver requested this specific regulatory |
| 3848 | * domain we keep it for its private use |
| 3849 | */ |
| 3850 | tmp = get_wiphy_regdom(request_wiphy); |
| 3851 | rcu_assign_pointer(request_wiphy->regd, rd); |
| 3852 | rcu_free_regdom(tmp); |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 3853 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3854 | rd = NULL; |
Larry Finger | b7566fc | 2013-02-04 15:33:44 -0600 | [diff] [blame] | 3855 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3856 | reset_regdomains(false, intersected_rd); |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 3857 | |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3858 | return 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3859 | } |
| 3860 | |
Luis R. Rodriguez | 0199240 | 2013-11-05 09:18:17 -0800 | [diff] [blame] | 3861 | static int reg_set_rd_country_ie(const struct ieee80211_regdomain *rd, |
| 3862 | struct regulatory_request *country_ie_request) |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3863 | { |
| 3864 | struct wiphy *request_wiphy; |
| 3865 | |
| 3866 | if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) && |
| 3867 | !is_unknown_alpha2(rd->alpha2)) |
| 3868 | return -EINVAL; |
| 3869 | |
| 3870 | /* |
| 3871 | * Lets only bother proceeding on the same alpha2 if the current |
| 3872 | * rd is non static (it means CRDA was present and was used last) |
| 3873 | * and the pending request came in from a country IE |
| 3874 | */ |
| 3875 | |
| 3876 | if (!is_valid_rd(rd)) { |
Dave Young | 94c4fd6 | 2015-11-15 15:31:05 +0800 | [diff] [blame] | 3877 | pr_err("Invalid regulatory domain detected: %c%c\n", |
| 3878 | rd->alpha2[0], rd->alpha2[1]); |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3879 | print_regdomain_info(rd); |
| 3880 | return -EINVAL; |
| 3881 | } |
| 3882 | |
Luis R. Rodriguez | 0199240 | 2013-11-05 09:18:17 -0800 | [diff] [blame] | 3883 | request_wiphy = wiphy_idx_to_wiphy(country_ie_request->wiphy_idx); |
Johannes Berg | 922ec58 | 2015-10-15 09:12:49 +0200 | [diff] [blame] | 3884 | if (!request_wiphy) |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3885 | return -ENODEV; |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3886 | |
Luis R. Rodriguez | 0199240 | 2013-11-05 09:18:17 -0800 | [diff] [blame] | 3887 | if (country_ie_request->intersect) |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3888 | return -EINVAL; |
| 3889 | |
| 3890 | reset_regdomains(false, rd); |
| 3891 | return 0; |
| 3892 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3893 | |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 3894 | /* |
| 3895 | * Use this call to set the current regulatory domain. Conflicts with |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3896 | * multiple drivers can be ironed out later. Caller must've already |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 3897 | * kmalloc'd the rd structure. |
Luis R. Rodriguez | fb1fc7a | 2009-02-21 00:04:31 -0500 | [diff] [blame] | 3898 | */ |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 3899 | int set_regdom(const struct ieee80211_regdomain *rd, |
| 3900 | enum ieee80211_regd_source regd_src) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3901 | { |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 3902 | struct regulatory_request *lr; |
Janusz Dziedzic | 092008a | 2014-02-14 08:54:00 +0100 | [diff] [blame] | 3903 | bool user_reset = false; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3904 | int r; |
| 3905 | |
Johannes Berg | e646a02 | 2019-02-05 21:08:29 +0100 | [diff] [blame] | 3906 | if (IS_ERR_OR_NULL(rd)) |
| 3907 | return -ENODATA; |
| 3908 | |
Luis R. Rodriguez | 3b9e5ac | 2013-11-05 09:18:14 -0800 | [diff] [blame] | 3909 | if (!reg_is_valid_request(rd->alpha2)) { |
| 3910 | kfree(rd); |
| 3911 | return -EINVAL; |
| 3912 | } |
| 3913 | |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 3914 | if (regd_src == REGD_SOURCE_CRDA) |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 3915 | reset_crda_timeouts(); |
Ilan peer | c37722b | 2015-03-30 15:15:49 +0300 | [diff] [blame] | 3916 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 3917 | lr = get_last_request(); |
Luis R. Rodriguez | abc7381 | 2009-07-30 17:38:08 -0700 | [diff] [blame] | 3918 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3919 | /* 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] | 3920 | switch (lr->initiator) { |
| 3921 | case NL80211_REGDOM_SET_BY_CORE: |
| 3922 | r = reg_set_rd_core(rd); |
| 3923 | break; |
| 3924 | case NL80211_REGDOM_SET_BY_USER: |
Johannes Berg | e646a02 | 2019-02-05 21:08:29 +0100 | [diff] [blame] | 3925 | cfg80211_save_user_regdom(rd); |
Luis R. Rodriguez | 84721d4 | 2013-11-05 09:18:15 -0800 | [diff] [blame] | 3926 | r = reg_set_rd_user(rd, lr); |
Janusz Dziedzic | 092008a | 2014-02-14 08:54:00 +0100 | [diff] [blame] | 3927 | user_reset = true; |
Luis R. Rodriguez | 84721d4 | 2013-11-05 09:18:15 -0800 | [diff] [blame] | 3928 | break; |
Luis R. Rodriguez | 3b9e5ac | 2013-11-05 09:18:14 -0800 | [diff] [blame] | 3929 | case NL80211_REGDOM_SET_BY_DRIVER: |
Luis R. Rodriguez | f5fe324 | 2013-11-05 09:18:16 -0800 | [diff] [blame] | 3930 | r = reg_set_rd_driver(rd, lr); |
| 3931 | break; |
Luis R. Rodriguez | 3b9e5ac | 2013-11-05 09:18:14 -0800 | [diff] [blame] | 3932 | case NL80211_REGDOM_SET_BY_COUNTRY_IE: |
Luis R. Rodriguez | 0199240 | 2013-11-05 09:18:17 -0800 | [diff] [blame] | 3933 | r = reg_set_rd_country_ie(rd, lr); |
Luis R. Rodriguez | 3b9e5ac | 2013-11-05 09:18:14 -0800 | [diff] [blame] | 3934 | break; |
| 3935 | default: |
| 3936 | WARN(1, "invalid initiator %d\n", lr->initiator); |
Ola Olsson | 09d1180 | 2015-12-13 19:12:03 +0100 | [diff] [blame] | 3937 | kfree(rd); |
Luis R. Rodriguez | 3b9e5ac | 2013-11-05 09:18:14 -0800 | [diff] [blame] | 3938 | return -EINVAL; |
| 3939 | } |
| 3940 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3941 | if (r) { |
Janusz Dziedzic | 092008a | 2014-02-14 08:54:00 +0100 | [diff] [blame] | 3942 | switch (r) { |
| 3943 | case -EALREADY: |
Kalle Valo | 9590853 | 2012-07-12 15:33:58 +0300 | [diff] [blame] | 3944 | reg_set_request_processed(); |
Janusz Dziedzic | 092008a | 2014-02-14 08:54:00 +0100 | [diff] [blame] | 3945 | break; |
| 3946 | default: |
| 3947 | /* Back to world regulatory in case of errors */ |
Johannes Berg | e646a02 | 2019-02-05 21:08:29 +0100 | [diff] [blame] | 3948 | restore_regulatory_settings(user_reset, false); |
Janusz Dziedzic | 092008a | 2014-02-14 08:54:00 +0100 | [diff] [blame] | 3949 | } |
Kalle Valo | 9590853 | 2012-07-12 15:33:58 +0300 | [diff] [blame] | 3950 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3951 | kfree(rd); |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 3952 | return r; |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3953 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3954 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3955 | /* This would make this whole thing pointless */ |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 3956 | if (WARN_ON(!lr->intersect && rd != get_cfg80211_regdom())) |
| 3957 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3958 | |
| 3959 | /* update all wiphys now with the new established regulatory domain */ |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 3960 | update_all_wiphy_regulatory(lr->initiator); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3961 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 3962 | print_regdomain(get_cfg80211_regdom()); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3963 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 3964 | nl80211_send_reg_change_event(lr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 3965 | |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 3966 | reg_set_request_processed(); |
| 3967 | |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 3968 | return 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3969 | } |
| 3970 | |
Arik Nemtsov | 2c3e861 | 2015-01-07 16:47:19 +0200 | [diff] [blame] | 3971 | static int __regulatory_set_wiphy_regd(struct wiphy *wiphy, |
| 3972 | struct ieee80211_regdomain *rd) |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 3973 | { |
| 3974 | const struct ieee80211_regdomain *regd; |
| 3975 | const struct ieee80211_regdomain *prev_regd; |
| 3976 | struct cfg80211_registered_device *rdev; |
| 3977 | |
| 3978 | if (WARN_ON(!wiphy || !rd)) |
| 3979 | return -EINVAL; |
| 3980 | |
| 3981 | if (WARN(!(wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED), |
| 3982 | "wiphy should have REGULATORY_WIPHY_SELF_MANAGED\n")) |
| 3983 | return -EPERM; |
| 3984 | |
Johannes Berg | b767ecd | 2021-06-18 13:41:56 +0300 | [diff] [blame] | 3985 | if (WARN(!is_valid_rd(rd), |
| 3986 | "Invalid regulatory domain detected: %c%c\n", |
| 3987 | rd->alpha2[0], rd->alpha2[1])) { |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 3988 | print_regdomain_info(rd); |
| 3989 | return -EINVAL; |
| 3990 | } |
| 3991 | |
| 3992 | regd = reg_copy_regd(rd); |
| 3993 | if (IS_ERR(regd)) |
| 3994 | return PTR_ERR(regd); |
| 3995 | |
| 3996 | rdev = wiphy_to_rdev(wiphy); |
| 3997 | |
| 3998 | spin_lock(®_requests_lock); |
| 3999 | prev_regd = rdev->requested_regd; |
| 4000 | rdev->requested_regd = regd; |
| 4001 | spin_unlock(®_requests_lock); |
| 4002 | |
| 4003 | kfree(prev_regd); |
Arik Nemtsov | 2c3e861 | 2015-01-07 16:47:19 +0200 | [diff] [blame] | 4004 | return 0; |
| 4005 | } |
| 4006 | |
| 4007 | int regulatory_set_wiphy_regd(struct wiphy *wiphy, |
| 4008 | struct ieee80211_regdomain *rd) |
| 4009 | { |
| 4010 | int ret = __regulatory_set_wiphy_regd(wiphy, rd); |
| 4011 | |
| 4012 | if (ret) |
| 4013 | return ret; |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 4014 | |
| 4015 | schedule_work(®_work); |
| 4016 | return 0; |
| 4017 | } |
| 4018 | EXPORT_SYMBOL(regulatory_set_wiphy_regd); |
| 4019 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 4020 | int regulatory_set_wiphy_regd_sync(struct wiphy *wiphy, |
| 4021 | struct ieee80211_regdomain *rd) |
Arik Nemtsov | 2c3e861 | 2015-01-07 16:47:19 +0200 | [diff] [blame] | 4022 | { |
| 4023 | int ret; |
| 4024 | |
| 4025 | ASSERT_RTNL(); |
| 4026 | |
| 4027 | ret = __regulatory_set_wiphy_regd(wiphy, rd); |
| 4028 | if (ret) |
| 4029 | return ret; |
| 4030 | |
| 4031 | /* process the request immediately */ |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 4032 | reg_process_self_managed_hint(wiphy); |
| 4033 | reg_check_channels(); |
Arik Nemtsov | 2c3e861 | 2015-01-07 16:47:19 +0200 | [diff] [blame] | 4034 | return 0; |
| 4035 | } |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 4036 | EXPORT_SYMBOL(regulatory_set_wiphy_regd_sync); |
Arik Nemtsov | 2c3e861 | 2015-01-07 16:47:19 +0200 | [diff] [blame] | 4037 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4038 | void wiphy_regulatory_register(struct wiphy *wiphy) |
| 4039 | { |
Amar Singhal | aced43ce | 2018-04-26 20:13:07 +0300 | [diff] [blame] | 4040 | struct regulatory_request *lr = get_last_request(); |
Arik Nemtsov | 23df0b7 | 2013-07-21 16:36:48 +0300 | [diff] [blame] | 4041 | |
Amar Singhal | aced43ce | 2018-04-26 20:13:07 +0300 | [diff] [blame] | 4042 | /* self-managed devices ignore beacon hints and country IE */ |
| 4043 | if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 4044 | wiphy->regulatory_flags |= REGULATORY_DISABLE_BEACON_HINTS | |
| 4045 | REGULATORY_COUNTRY_IE_IGNORE; |
| 4046 | |
Amar Singhal | aced43ce | 2018-04-26 20:13:07 +0300 | [diff] [blame] | 4047 | /* |
| 4048 | * The last request may have been received before this |
| 4049 | * registration call. Call the driver notifier if |
Sriram R | 8772eed | 2019-04-16 11:16:33 +0530 | [diff] [blame] | 4050 | * initiator is USER. |
Amar Singhal | aced43ce | 2018-04-26 20:13:07 +0300 | [diff] [blame] | 4051 | */ |
Sriram R | 8772eed | 2019-04-16 11:16:33 +0530 | [diff] [blame] | 4052 | if (lr->initiator == NL80211_REGDOM_SET_BY_USER) |
Amar Singhal | aced43ce | 2018-04-26 20:13:07 +0300 | [diff] [blame] | 4053 | reg_call_notifier(wiphy, lr); |
| 4054 | } |
| 4055 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4056 | if (!reg_dev_ignore_cell_hint(wiphy)) |
| 4057 | reg_num_devs_support_basehint++; |
| 4058 | |
Arik Nemtsov | 23df0b7 | 2013-07-21 16:36:48 +0300 | [diff] [blame] | 4059 | wiphy_update_regulatory(wiphy, lr->initiator); |
Vasanthakumar Thiagarajan | 8976672 | 2017-02-27 17:04:35 +0530 | [diff] [blame] | 4060 | wiphy_all_share_dfs_chan_state(wiphy); |
Miri Korenblit | 1b7b3ac | 2021-06-18 13:41:46 +0300 | [diff] [blame] | 4061 | reg_process_self_managed_hints(); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4062 | } |
| 4063 | |
Luis R. Rodriguez | bfead08 | 2012-07-12 11:49:19 -0700 | [diff] [blame] | 4064 | void wiphy_regulatory_deregister(struct wiphy *wiphy) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 4065 | { |
Luis R. Rodriguez | 0ad8aca | 2009-03-24 21:21:08 -0400 | [diff] [blame] | 4066 | struct wiphy *request_wiphy = NULL; |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 4067 | struct regulatory_request *lr; |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 4068 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 4069 | lr = get_last_request(); |
Luis R. Rodriguez | abc7381 | 2009-07-30 17:38:08 -0700 | [diff] [blame] | 4070 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4071 | if (!reg_dev_ignore_cell_hint(wiphy)) |
| 4072 | reg_num_devs_support_basehint--; |
| 4073 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4074 | rcu_free_regdom(get_wiphy_regdom(wiphy)); |
Monam Agarwal | 34dd886 | 2014-03-24 00:53:40 +0530 | [diff] [blame] | 4075 | RCU_INIT_POINTER(wiphy->regd, NULL); |
Chris Wright | 0ef9ccd | 2009-04-24 14:09:31 -0700 | [diff] [blame] | 4076 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 4077 | if (lr) |
| 4078 | request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 4079 | |
Chris Wright | 0ef9ccd | 2009-04-24 14:09:31 -0700 | [diff] [blame] | 4080 | if (!request_wiphy || request_wiphy != wiphy) |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 4081 | return; |
Chris Wright | 0ef9ccd | 2009-04-24 14:09:31 -0700 | [diff] [blame] | 4082 | |
Johannes Berg | c492db3 | 2012-12-06 16:29:25 +0100 | [diff] [blame] | 4083 | lr->wiphy_idx = WIPHY_IDX_INVALID; |
| 4084 | lr->country_ie_env = ENVIRON_ANY; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 4085 | } |
| 4086 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 4087 | /* |
Arend van Spriel | f89769c | 2019-08-02 13:30:59 +0200 | [diff] [blame] | 4088 | * See FCC notices for UNII band definitions |
| 4089 | * 5GHz: https://www.fcc.gov/document/5-ghz-unlicensed-spectrum-unii |
| 4090 | * 6GHz: https://www.fcc.gov/document/fcc-proposes-more-spectrum-unlicensed-use-0 |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 4091 | */ |
| 4092 | int cfg80211_get_unii(int freq) |
| 4093 | { |
| 4094 | /* UNII-1 */ |
| 4095 | if (freq >= 5150 && freq <= 5250) |
| 4096 | return 0; |
| 4097 | |
| 4098 | /* UNII-2A */ |
| 4099 | if (freq > 5250 && freq <= 5350) |
| 4100 | return 1; |
| 4101 | |
| 4102 | /* UNII-2B */ |
| 4103 | if (freq > 5350 && freq <= 5470) |
| 4104 | return 2; |
| 4105 | |
| 4106 | /* UNII-2C */ |
| 4107 | if (freq > 5470 && freq <= 5725) |
| 4108 | return 3; |
| 4109 | |
| 4110 | /* UNII-3 */ |
| 4111 | if (freq > 5725 && freq <= 5825) |
| 4112 | return 4; |
| 4113 | |
Arend van Spriel | f89769c | 2019-08-02 13:30:59 +0200 | [diff] [blame] | 4114 | /* UNII-5 */ |
| 4115 | if (freq > 5925 && freq <= 6425) |
| 4116 | return 5; |
| 4117 | |
| 4118 | /* UNII-6 */ |
| 4119 | if (freq > 6425 && freq <= 6525) |
| 4120 | return 6; |
| 4121 | |
| 4122 | /* UNII-7 */ |
| 4123 | if (freq > 6525 && freq <= 6875) |
| 4124 | return 7; |
| 4125 | |
| 4126 | /* UNII-8 */ |
| 4127 | if (freq > 6875 && freq <= 7125) |
| 4128 | return 8; |
| 4129 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 4130 | return -EINVAL; |
| 4131 | } |
| 4132 | |
Ilan Peer | c8866e5 | 2014-02-23 09:13:03 +0200 | [diff] [blame] | 4133 | bool regulatory_indoor_allowed(void) |
| 4134 | { |
| 4135 | return reg_is_indoor; |
| 4136 | } |
| 4137 | |
Vasanthakumar Thiagarajan | b35a51c | 2017-02-27 17:04:33 +0530 | [diff] [blame] | 4138 | bool regulatory_pre_cac_allowed(struct wiphy *wiphy) |
| 4139 | { |
| 4140 | const struct ieee80211_regdomain *regd = NULL; |
| 4141 | const struct ieee80211_regdomain *wiphy_regd = NULL; |
| 4142 | bool pre_cac_allowed = false; |
| 4143 | |
| 4144 | rcu_read_lock(); |
| 4145 | |
| 4146 | regd = rcu_dereference(cfg80211_regdomain); |
| 4147 | wiphy_regd = rcu_dereference(wiphy->regd); |
| 4148 | if (!wiphy_regd) { |
| 4149 | if (regd->dfs_region == NL80211_DFS_ETSI) |
| 4150 | pre_cac_allowed = true; |
| 4151 | |
| 4152 | rcu_read_unlock(); |
| 4153 | |
| 4154 | return pre_cac_allowed; |
| 4155 | } |
| 4156 | |
| 4157 | if (regd->dfs_region == wiphy_regd->dfs_region && |
| 4158 | wiphy_regd->dfs_region == NL80211_DFS_ETSI) |
| 4159 | pre_cac_allowed = true; |
| 4160 | |
| 4161 | rcu_read_unlock(); |
| 4162 | |
| 4163 | return pre_cac_allowed; |
| 4164 | } |
Aaron Komisar | dc0c18e | 2019-10-02 13:59:07 +0000 | [diff] [blame] | 4165 | EXPORT_SYMBOL(regulatory_pre_cac_allowed); |
Vasanthakumar Thiagarajan | b35a51c | 2017-02-27 17:04:33 +0530 | [diff] [blame] | 4166 | |
Orr Mazor | 26ec17a | 2019-12-22 14:55:31 +0000 | [diff] [blame] | 4167 | static void cfg80211_check_and_end_cac(struct cfg80211_registered_device *rdev) |
| 4168 | { |
| 4169 | struct wireless_dev *wdev; |
| 4170 | /* If we finished CAC or received radar, we should end any |
| 4171 | * CAC running on the same channels. |
| 4172 | * the check !cfg80211_chandef_dfs_usable contain 2 options: |
| 4173 | * either all channels are available - those the CAC_FINISHED |
| 4174 | * event has effected another wdev state, or there is a channel |
| 4175 | * in unavailable state in wdev chandef - those the RADAR_DETECTED |
| 4176 | * event has effected another wdev state. |
| 4177 | * In both cases we should end the CAC on the wdev. |
| 4178 | */ |
| 4179 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
| 4180 | if (wdev->cac_started && |
| 4181 | !cfg80211_chandef_dfs_usable(&rdev->wiphy, &wdev->chandef)) |
| 4182 | rdev_end_cac(rdev, wdev->netdev); |
| 4183 | } |
| 4184 | } |
| 4185 | |
Vasanthakumar Thiagarajan | 8976672 | 2017-02-27 17:04:35 +0530 | [diff] [blame] | 4186 | void regulatory_propagate_dfs_state(struct wiphy *wiphy, |
| 4187 | struct cfg80211_chan_def *chandef, |
| 4188 | enum nl80211_dfs_state dfs_state, |
| 4189 | enum nl80211_radar_event event) |
| 4190 | { |
| 4191 | struct cfg80211_registered_device *rdev; |
| 4192 | |
| 4193 | ASSERT_RTNL(); |
| 4194 | |
| 4195 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 4196 | return; |
| 4197 | |
Vasanthakumar Thiagarajan | 8976672 | 2017-02-27 17:04:35 +0530 | [diff] [blame] | 4198 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 4199 | if (wiphy == &rdev->wiphy) |
| 4200 | continue; |
| 4201 | |
| 4202 | if (!reg_dfs_domain_same(wiphy, &rdev->wiphy)) |
| 4203 | continue; |
| 4204 | |
| 4205 | if (!ieee80211_get_channel(&rdev->wiphy, |
| 4206 | chandef->chan->center_freq)) |
| 4207 | continue; |
| 4208 | |
| 4209 | cfg80211_set_dfs_state(&rdev->wiphy, chandef, dfs_state); |
| 4210 | |
| 4211 | if (event == NL80211_RADAR_DETECTED || |
Orr Mazor | 26ec17a | 2019-12-22 14:55:31 +0000 | [diff] [blame] | 4212 | event == NL80211_RADAR_CAC_FINISHED) { |
Vasanthakumar Thiagarajan | 8976672 | 2017-02-27 17:04:35 +0530 | [diff] [blame] | 4213 | cfg80211_sched_dfs_chan_update(rdev); |
Orr Mazor | 26ec17a | 2019-12-22 14:55:31 +0000 | [diff] [blame] | 4214 | cfg80211_check_and_end_cac(rdev); |
| 4215 | } |
Vasanthakumar Thiagarajan | 8976672 | 2017-02-27 17:04:35 +0530 | [diff] [blame] | 4216 | |
| 4217 | nl80211_radar_notify(rdev, chandef, event, NULL, GFP_KERNEL); |
| 4218 | } |
| 4219 | } |
| 4220 | |
Johannes Berg | d7be102 | 2017-10-26 11:24:27 +0200 | [diff] [blame] | 4221 | static int __init regulatory_init_db(void) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4222 | { |
Johannes Berg | d7be102 | 2017-10-26 11:24:27 +0200 | [diff] [blame] | 4223 | int err; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 4224 | |
Johannes Berg | 71e5e886 | 2018-10-01 11:43:00 +0200 | [diff] [blame] | 4225 | /* |
| 4226 | * It's possible that - due to other bugs/issues - cfg80211 |
| 4227 | * never called regulatory_init() below, or that it failed; |
| 4228 | * in that case, don't try to do any further work here as |
| 4229 | * it's doomed to lead to crashes. |
| 4230 | */ |
| 4231 | if (IS_ERR_OR_NULL(reg_pdev)) |
| 4232 | return -EINVAL; |
| 4233 | |
Johannes Berg | 90a53e4 | 2017-09-13 22:21:08 +0200 | [diff] [blame] | 4234 | err = load_builtin_regdb_keys(); |
| 4235 | if (err) |
| 4236 | return err; |
| 4237 | |
Luis R. Rodriguez | ae9e4b0 | 2009-07-14 20:23:15 -0400 | [diff] [blame] | 4238 | /* We always try to get an update for the static regdomain */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4239 | err = regulatory_hint_core(cfg80211_world_regdom->alpha2); |
Luis R. Rodriguez | bcf4f99 | 2009-02-21 00:04:24 -0500 | [diff] [blame] | 4240 | if (err) { |
Ola Olsson | 09d1180 | 2015-12-13 19:12:03 +0100 | [diff] [blame] | 4241 | if (err == -ENOMEM) { |
| 4242 | platform_device_unregister(reg_pdev); |
Luis R. Rodriguez | bcf4f99 | 2009-02-21 00:04:24 -0500 | [diff] [blame] | 4243 | return err; |
Ola Olsson | 09d1180 | 2015-12-13 19:12:03 +0100 | [diff] [blame] | 4244 | } |
Luis R. Rodriguez | bcf4f99 | 2009-02-21 00:04:24 -0500 | [diff] [blame] | 4245 | /* |
| 4246 | * N.B. kobject_uevent_env() can fail mainly for when we're out |
| 4247 | * memory which is handled and propagated appropriately above |
| 4248 | * but it can also fail during a netlink_broadcast() or during |
| 4249 | * early boot for call_usermodehelper(). For now treat these |
| 4250 | * errors as non-fatal. |
| 4251 | */ |
Joe Perches | e9c0268 | 2010-11-16 19:56:49 -0800 | [diff] [blame] | 4252 | 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] | 4253 | } |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 4254 | |
Luis R. Rodriguez | ae9e4b0 | 2009-07-14 20:23:15 -0400 | [diff] [blame] | 4255 | /* |
| 4256 | * Finally, if the user set the module parameter treat it |
| 4257 | * as a user hint. |
| 4258 | */ |
| 4259 | if (!is_world_regdom(ieee80211_regdom)) |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4260 | regulatory_hint_user(ieee80211_regdom, |
| 4261 | NL80211_USER_REG_HINT_USER); |
Luis R. Rodriguez | ae9e4b0 | 2009-07-14 20:23:15 -0400 | [diff] [blame] | 4262 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4263 | return 0; |
| 4264 | } |
Johannes Berg | d7be102 | 2017-10-26 11:24:27 +0200 | [diff] [blame] | 4265 | #ifndef MODULE |
| 4266 | late_initcall(regulatory_init_db); |
| 4267 | #endif |
| 4268 | |
| 4269 | int __init regulatory_init(void) |
| 4270 | { |
| 4271 | reg_pdev = platform_device_register_simple("regulatory", 0, NULL, 0); |
| 4272 | if (IS_ERR(reg_pdev)) |
| 4273 | return PTR_ERR(reg_pdev); |
| 4274 | |
Johannes Berg | d7be102 | 2017-10-26 11:24:27 +0200 | [diff] [blame] | 4275 | rcu_assign_pointer(cfg80211_regdomain, cfg80211_world_regdom); |
| 4276 | |
| 4277 | user_alpha2[0] = '9'; |
| 4278 | user_alpha2[1] = '7'; |
| 4279 | |
| 4280 | #ifdef MODULE |
| 4281 | return regulatory_init_db(); |
| 4282 | #else |
| 4283 | return 0; |
| 4284 | #endif |
| 4285 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4286 | |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4287 | void regulatory_exit(void) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4288 | { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4289 | struct regulatory_request *reg_request, *tmp; |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 4290 | struct reg_beacon *reg_beacon, *btmp; |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4291 | |
| 4292 | cancel_work_sync(®_work); |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 4293 | cancel_crda_timeout_sync(); |
Arik Nemtsov | ad932f0 | 2014-11-27 09:44:55 +0200 | [diff] [blame] | 4294 | cancel_delayed_work_sync(®_check_chans); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4295 | |
Johannes Berg | 9027b14 | 2012-12-03 17:59:24 +0100 | [diff] [blame] | 4296 | /* Lock to suppress warnings */ |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 4297 | rtnl_lock(); |
Johannes Berg | 379b82f | 2012-12-06 15:44:07 +0100 | [diff] [blame] | 4298 | reset_regdomains(true, NULL); |
Johannes Berg | 38fd214 | 2013-05-10 19:17:17 +0200 | [diff] [blame] | 4299 | rtnl_unlock(); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 4300 | |
Luis R. Rodriguez | 58ebacc | 2011-11-08 14:28:06 -0800 | [diff] [blame] | 4301 | dev_set_uevent_suppress(®_pdev->dev, true); |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 4302 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4303 | platform_device_unregister(reg_pdev); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 4304 | |
Johannes Berg | fea9bce | 2012-12-03 17:32:01 +0100 | [diff] [blame] | 4305 | list_for_each_entry_safe(reg_beacon, btmp, ®_pending_beacons, list) { |
| 4306 | list_del(®_beacon->list); |
| 4307 | kfree(reg_beacon); |
Luis R. Rodriguez | e38f8a7 | 2009-02-21 00:20:39 -0500 | [diff] [blame] | 4308 | } |
| 4309 | |
Johannes Berg | fea9bce | 2012-12-03 17:32:01 +0100 | [diff] [blame] | 4310 | list_for_each_entry_safe(reg_beacon, btmp, ®_beacon_list, list) { |
| 4311 | list_del(®_beacon->list); |
| 4312 | kfree(reg_beacon); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4313 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4314 | |
Johannes Berg | fea9bce | 2012-12-03 17:32:01 +0100 | [diff] [blame] | 4315 | list_for_each_entry_safe(reg_request, tmp, ®_requests_list, list) { |
| 4316 | list_del(®_request->list); |
| 4317 | kfree(reg_request); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4318 | } |
Johannes Berg | 007f6c5 | 2015-10-15 11:22:58 +0200 | [diff] [blame] | 4319 | |
| 4320 | if (!IS_ERR_OR_NULL(regdb)) |
| 4321 | kfree(regdb); |
Johannes Berg | e646a02 | 2019-02-05 21:08:29 +0100 | [diff] [blame] | 4322 | if (!IS_ERR_OR_NULL(cfg80211_user_regdom)) |
| 4323 | kfree(cfg80211_user_regdom); |
Johannes Berg | 90a53e4 | 2017-09-13 22:21:08 +0200 | [diff] [blame] | 4324 | |
| 4325 | free_regdb_keyring(); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4326 | } |