Thomas Gleixner | 28c61a6 | 2019-06-01 10:08:46 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2 | /* |
| 3 | * mac80211 configuration hooks for cfg80211 |
| 4 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | b2eb0ee | 2015-06-01 22:54:13 +0200 | [diff] [blame] | 6 | * Copyright 2013-2015 Intel Mobile Communications GmbH |
Johannes Berg | e8e4f52 | 2017-03-08 11:12:10 +0100 | [diff] [blame] | 7 | * Copyright (C) 2015-2017 Intel Deutschland GmbH |
Nathan Errera | 6d50176 | 2021-11-29 15:32:38 +0200 | [diff] [blame] | 8 | * Copyright (C) 2018-2021 Intel Corporation |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 11 | #include <linux/ieee80211.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 12 | #include <linux/nl80211.h> |
| 13 | #include <linux/rtnetlink.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 15 | #include <net/net_namespace.h> |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 16 | #include <linux/rcupdate.h> |
Ard Biesheuvel | 5fdb373 | 2019-06-12 18:19:54 +0200 | [diff] [blame] | 17 | #include <linux/fips.h> |
Arik Nemtsov | dfe018b | 2011-09-28 14:12:52 +0300 | [diff] [blame] | 18 | #include <linux/if_ether.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 19 | #include <net/cfg80211.h> |
| 20 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 21 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 22 | #include "rate.h" |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 23 | #include "mesh.h" |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 24 | #include "wme.h" |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 25 | |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 26 | static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata, |
| 27 | struct vif_params *params) |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 28 | { |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 29 | bool mu_mimo_groups = false; |
| 30 | bool mu_mimo_follow = false; |
| 31 | |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 32 | if (params->vht_mumimo_groups) { |
| 33 | u64 membership; |
| 34 | |
| 35 | BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN); |
| 36 | |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 37 | memcpy(sdata->vif.bss_conf.mu_group.membership, |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 38 | params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN); |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 39 | memcpy(sdata->vif.bss_conf.mu_group.position, |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 40 | params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN, |
| 41 | WLAN_USER_POSITION_LEN); |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 42 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS); |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 43 | /* don't care about endianness - just check for 0 */ |
| 44 | memcpy(&membership, params->vht_mumimo_groups, |
| 45 | WLAN_MEMBERSHIP_LEN); |
| 46 | mu_mimo_groups = membership != 0; |
| 47 | } |
| 48 | |
| 49 | if (params->vht_mumimo_follow_addr) { |
| 50 | mu_mimo_follow = |
| 51 | is_valid_ether_addr(params->vht_mumimo_follow_addr); |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 52 | ether_addr_copy(sdata->u.mntr.mu_follow_addr, |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 53 | params->vht_mumimo_follow_addr); |
| 54 | } |
| 55 | |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 56 | sdata->vif.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow; |
| 57 | } |
| 58 | |
| 59 | static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata, |
| 60 | struct vif_params *params) |
| 61 | { |
| 62 | struct ieee80211_local *local = sdata->local; |
| 63 | struct ieee80211_sub_if_data *monitor_sdata; |
| 64 | |
| 65 | /* check flags first */ |
| 66 | if (params->flags && ieee80211_sdata_running(sdata)) { |
| 67 | u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE; |
| 68 | |
| 69 | /* |
| 70 | * Prohibit MONITOR_FLAG_COOK_FRAMES and |
| 71 | * MONITOR_FLAG_ACTIVE to be changed while the |
| 72 | * interface is up. |
| 73 | * Else we would need to add a lot of cruft |
| 74 | * to update everything: |
| 75 | * cooked_mntrs, monitor and all fif_* counters |
| 76 | * reconfigure hardware |
| 77 | */ |
| 78 | if ((params->flags & mask) != (sdata->u.mntr.flags & mask)) |
| 79 | return -EBUSY; |
| 80 | } |
| 81 | |
| 82 | /* also validate MU-MIMO change */ |
Johannes Berg | 6dd23603 | 2021-11-12 13:51:44 +0100 | [diff] [blame] | 83 | monitor_sdata = wiphy_dereference(local->hw.wiphy, |
| 84 | local->monitor_sdata); |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 85 | |
| 86 | if (!monitor_sdata && |
| 87 | (params->vht_mumimo_groups || params->vht_mumimo_follow_addr)) |
| 88 | return -EOPNOTSUPP; |
| 89 | |
| 90 | /* apply all changes now - no failures allowed */ |
| 91 | |
| 92 | if (monitor_sdata) |
| 93 | ieee80211_set_mu_mimo_follow(monitor_sdata, params); |
| 94 | |
| 95 | if (params->flags) { |
| 96 | if (ieee80211_sdata_running(sdata)) { |
| 97 | ieee80211_adjust_monitor_flags(sdata, -1); |
| 98 | sdata->u.mntr.flags = params->flags; |
| 99 | ieee80211_adjust_monitor_flags(sdata, 1); |
| 100 | |
| 101 | ieee80211_configure_filter(local); |
| 102 | } else { |
| 103 | /* |
| 104 | * Because the interface is down, ieee80211_do_stop |
| 105 | * and ieee80211_do_open take care of "everything" |
| 106 | * mentioned in the comment above. |
| 107 | */ |
| 108 | sdata->u.mntr.flags = params->flags; |
| 109 | } |
| 110 | } |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
John Crispin | 1719642 | 2021-09-15 19:54:35 -0700 | [diff] [blame] | 115 | static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata, |
| 116 | struct cfg80211_mbssid_config params) |
| 117 | { |
| 118 | struct ieee80211_sub_if_data *tx_sdata; |
| 119 | |
| 120 | sdata->vif.mbssid_tx_vif = NULL; |
| 121 | sdata->vif.bss_conf.bssid_index = 0; |
| 122 | sdata->vif.bss_conf.nontransmitted = false; |
| 123 | sdata->vif.bss_conf.ema_ap = false; |
| 124 | |
| 125 | if (sdata->vif.type != NL80211_IFTYPE_AP || !params.tx_wdev) |
| 126 | return -EINVAL; |
| 127 | |
| 128 | tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params.tx_wdev); |
| 129 | if (!tx_sdata) |
| 130 | return -EINVAL; |
| 131 | |
| 132 | if (tx_sdata == sdata) { |
| 133 | sdata->vif.mbssid_tx_vif = &sdata->vif; |
| 134 | } else { |
| 135 | sdata->vif.mbssid_tx_vif = &tx_sdata->vif; |
| 136 | sdata->vif.bss_conf.nontransmitted = true; |
| 137 | sdata->vif.bss_conf.bssid_index = params.index; |
| 138 | } |
| 139 | if (params.ema) |
| 140 | sdata->vif.bss_conf.ema_ap = true; |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
Johannes Berg | 552bff0 | 2012-09-19 09:26:06 +0200 | [diff] [blame] | 145 | static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy, |
| 146 | const char *name, |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 147 | unsigned char name_assign_type, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 148 | enum nl80211_iftype type, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 149 | struct vif_params *params) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 150 | { |
| 151 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 152 | struct wireless_dev *wdev; |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 153 | struct ieee80211_sub_if_data *sdata; |
| 154 | int err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 155 | |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 156 | err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 157 | if (err) |
| 158 | return ERR_PTR(err); |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 159 | |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 160 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 161 | |
| 162 | if (type == NL80211_IFTYPE_MONITOR) { |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 163 | err = ieee80211_set_mon_options(sdata, params); |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 164 | if (err) { |
| 165 | ieee80211_if_remove(sdata); |
| 166 | return NULL; |
| 167 | } |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 168 | } |
| 169 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 170 | return wdev; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 173 | static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 174 | { |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 175 | ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 176 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 177 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 180 | static int ieee80211_change_iface(struct wiphy *wiphy, |
| 181 | struct net_device *dev, |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 182 | enum nl80211_iftype type, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 183 | struct vif_params *params) |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 184 | { |
Johannes Berg | 9607e6b66 | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 185 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Felix Fietkau | a5d3cbd | 2021-07-02 07:01:11 +0200 | [diff] [blame] | 186 | struct ieee80211_local *local = sdata->local; |
| 187 | struct sta_info *sta; |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 188 | int ret; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 189 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 190 | ret = ieee80211_if_change_type(sdata, type); |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 191 | if (ret) |
| 192 | return ret; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 193 | |
Johannes Berg | 6f52728 | 2018-08-31 11:31:05 +0300 | [diff] [blame] | 194 | if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) { |
Stephen Hemminger | a9b3cd7 | 2011-08-01 16:19:00 +0000 | [diff] [blame] | 195 | RCU_INIT_POINTER(sdata->u.vlan.sta, NULL); |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 196 | ieee80211_check_fast_rx_iface(sdata); |
Johannes Berg | 6f52728 | 2018-08-31 11:31:05 +0300 | [diff] [blame] | 197 | } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) { |
Felix Fietkau | a5d3cbd | 2021-07-02 07:01:11 +0200 | [diff] [blame] | 198 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 199 | |
| 200 | if (params->use_4addr == ifmgd->use_4addr) |
| 201 | return 0; |
| 202 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 203 | sdata->u.mgd.use_4addr = params->use_4addr; |
Felix Fietkau | a5d3cbd | 2021-07-02 07:01:11 +0200 | [diff] [blame] | 204 | if (!ifmgd->associated) |
| 205 | return 0; |
| 206 | |
| 207 | mutex_lock(&local->sta_mtx); |
| 208 | sta = sta_info_get(sdata, ifmgd->bssid); |
| 209 | if (sta) |
| 210 | drv_sta_set_4addr(local, sdata, &sta->sta, |
| 211 | params->use_4addr); |
| 212 | mutex_unlock(&local->sta_mtx); |
| 213 | |
| 214 | if (params->use_4addr) |
| 215 | ieee80211_send_4addr_nullfunc(local, sdata); |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 216 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 217 | |
Aviya Erenfeld | 42bd20d | 2016-08-29 23:25:16 +0300 | [diff] [blame] | 218 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 219 | ret = ieee80211_set_mon_options(sdata, params); |
| 220 | if (ret) |
| 221 | return ret; |
Christian Lamparter | 85416a4 | 2010-10-02 13:17:07 +0200 | [diff] [blame] | 222 | } |
Felix Fietkau | f7917af | 2010-04-27 00:26:34 +0200 | [diff] [blame] | 223 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 224 | return 0; |
| 225 | } |
| 226 | |
Johannes Berg | f142c6b | 2012-06-18 20:07:15 +0200 | [diff] [blame] | 227 | static int ieee80211_start_p2p_device(struct wiphy *wiphy, |
| 228 | struct wireless_dev *wdev) |
| 229 | { |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 230 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 231 | int ret; |
| 232 | |
| 233 | mutex_lock(&sdata->local->chanctx_mtx); |
| 234 | ret = ieee80211_check_combinations(sdata, NULL, 0, 0); |
| 235 | mutex_unlock(&sdata->local->chanctx_mtx); |
| 236 | if (ret < 0) |
| 237 | return ret; |
| 238 | |
Johannes Berg | f142c6b | 2012-06-18 20:07:15 +0200 | [diff] [blame] | 239 | return ieee80211_do_open(wdev, true); |
| 240 | } |
| 241 | |
| 242 | static void ieee80211_stop_p2p_device(struct wiphy *wiphy, |
| 243 | struct wireless_dev *wdev) |
| 244 | { |
| 245 | ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev)); |
| 246 | } |
| 247 | |
Ayala Beker | 708d50e | 2016-09-20 17:31:14 +0300 | [diff] [blame] | 248 | static int ieee80211_start_nan(struct wiphy *wiphy, |
| 249 | struct wireless_dev *wdev, |
| 250 | struct cfg80211_nan_conf *conf) |
| 251 | { |
| 252 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 253 | int ret; |
| 254 | |
| 255 | mutex_lock(&sdata->local->chanctx_mtx); |
| 256 | ret = ieee80211_check_combinations(sdata, NULL, 0, 0); |
| 257 | mutex_unlock(&sdata->local->chanctx_mtx); |
| 258 | if (ret < 0) |
| 259 | return ret; |
| 260 | |
| 261 | ret = ieee80211_do_open(wdev, true); |
| 262 | if (ret) |
| 263 | return ret; |
| 264 | |
| 265 | ret = drv_start_nan(sdata->local, sdata, conf); |
| 266 | if (ret) |
| 267 | ieee80211_sdata_stop(sdata); |
| 268 | |
Ayala Beker | 167e33f | 2016-09-20 17:31:20 +0300 | [diff] [blame] | 269 | sdata->u.nan.conf = *conf; |
| 270 | |
Ayala Beker | 708d50e | 2016-09-20 17:31:14 +0300 | [diff] [blame] | 271 | return ret; |
| 272 | } |
| 273 | |
| 274 | static void ieee80211_stop_nan(struct wiphy *wiphy, |
| 275 | struct wireless_dev *wdev) |
| 276 | { |
| 277 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 278 | |
| 279 | drv_stop_nan(sdata->local, sdata); |
| 280 | ieee80211_sdata_stop(sdata); |
| 281 | } |
| 282 | |
Ayala Beker | 5953ff6 | 2016-09-20 17:31:19 +0300 | [diff] [blame] | 283 | static int ieee80211_nan_change_conf(struct wiphy *wiphy, |
| 284 | struct wireless_dev *wdev, |
| 285 | struct cfg80211_nan_conf *conf, |
| 286 | u32 changes) |
| 287 | { |
| 288 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 289 | struct cfg80211_nan_conf new_conf; |
| 290 | int ret = 0; |
| 291 | |
| 292 | if (sdata->vif.type != NL80211_IFTYPE_NAN) |
| 293 | return -EOPNOTSUPP; |
| 294 | |
| 295 | if (!ieee80211_sdata_running(sdata)) |
| 296 | return -ENETDOWN; |
| 297 | |
| 298 | new_conf = sdata->u.nan.conf; |
| 299 | |
| 300 | if (changes & CFG80211_NAN_CONF_CHANGED_PREF) |
| 301 | new_conf.master_pref = conf->master_pref; |
| 302 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 303 | if (changes & CFG80211_NAN_CONF_CHANGED_BANDS) |
| 304 | new_conf.bands = conf->bands; |
Ayala Beker | 5953ff6 | 2016-09-20 17:31:19 +0300 | [diff] [blame] | 305 | |
| 306 | ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes); |
| 307 | if (!ret) |
| 308 | sdata->u.nan.conf = new_conf; |
| 309 | |
| 310 | return ret; |
| 311 | } |
| 312 | |
Ayala Beker | 167e33f | 2016-09-20 17:31:20 +0300 | [diff] [blame] | 313 | static int ieee80211_add_nan_func(struct wiphy *wiphy, |
| 314 | struct wireless_dev *wdev, |
| 315 | struct cfg80211_nan_func *nan_func) |
| 316 | { |
| 317 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 318 | int ret; |
| 319 | |
| 320 | if (sdata->vif.type != NL80211_IFTYPE_NAN) |
| 321 | return -EOPNOTSUPP; |
| 322 | |
| 323 | if (!ieee80211_sdata_running(sdata)) |
| 324 | return -ENETDOWN; |
| 325 | |
| 326 | spin_lock_bh(&sdata->u.nan.func_lock); |
| 327 | |
| 328 | ret = idr_alloc(&sdata->u.nan.function_inst_ids, |
| 329 | nan_func, 1, sdata->local->hw.max_nan_de_entries + 1, |
| 330 | GFP_ATOMIC); |
| 331 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 332 | |
| 333 | if (ret < 0) |
| 334 | return ret; |
| 335 | |
| 336 | nan_func->instance_id = ret; |
| 337 | |
| 338 | WARN_ON(nan_func->instance_id == 0); |
| 339 | |
| 340 | ret = drv_add_nan_func(sdata->local, sdata, nan_func); |
| 341 | if (ret) { |
| 342 | spin_lock_bh(&sdata->u.nan.func_lock); |
| 343 | idr_remove(&sdata->u.nan.function_inst_ids, |
| 344 | nan_func->instance_id); |
| 345 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 346 | } |
| 347 | |
| 348 | return ret; |
| 349 | } |
| 350 | |
| 351 | static struct cfg80211_nan_func * |
| 352 | ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata, |
| 353 | u64 cookie) |
| 354 | { |
| 355 | struct cfg80211_nan_func *func; |
| 356 | int id; |
| 357 | |
| 358 | lockdep_assert_held(&sdata->u.nan.func_lock); |
| 359 | |
| 360 | idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) { |
| 361 | if (func->cookie == cookie) |
| 362 | return func; |
| 363 | } |
| 364 | |
| 365 | return NULL; |
| 366 | } |
| 367 | |
| 368 | static void ieee80211_del_nan_func(struct wiphy *wiphy, |
| 369 | struct wireless_dev *wdev, u64 cookie) |
| 370 | { |
| 371 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 372 | struct cfg80211_nan_func *func; |
| 373 | u8 instance_id = 0; |
| 374 | |
| 375 | if (sdata->vif.type != NL80211_IFTYPE_NAN || |
| 376 | !ieee80211_sdata_running(sdata)) |
| 377 | return; |
| 378 | |
| 379 | spin_lock_bh(&sdata->u.nan.func_lock); |
| 380 | |
| 381 | func = ieee80211_find_nan_func_by_cookie(sdata, cookie); |
| 382 | if (func) |
| 383 | instance_id = func->instance_id; |
| 384 | |
| 385 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 386 | |
| 387 | if (instance_id) |
| 388 | drv_del_nan_func(sdata->local, sdata, instance_id); |
| 389 | } |
| 390 | |
Simon Wunderlich | b53be79 | 2011-11-18 14:20:44 +0100 | [diff] [blame] | 391 | static int ieee80211_set_noack_map(struct wiphy *wiphy, |
| 392 | struct net_device *dev, |
| 393 | u16 noack_map) |
| 394 | { |
| 395 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 396 | |
| 397 | sdata->noack_map = noack_map; |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 398 | |
| 399 | ieee80211_check_fast_xmit_iface(sdata); |
| 400 | |
Simon Wunderlich | b53be79 | 2011-11-18 14:20:44 +0100 | [diff] [blame] | 401 | return 0; |
| 402 | } |
| 403 | |
Alexander Wetzel | 96fc6ef | 2019-03-19 21:34:08 +0100 | [diff] [blame] | 404 | static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata, |
| 405 | const u8 *mac_addr, u8 key_idx) |
| 406 | { |
| 407 | struct ieee80211_local *local = sdata->local; |
| 408 | struct ieee80211_key *key; |
| 409 | struct sta_info *sta; |
| 410 | int ret = -EINVAL; |
| 411 | |
| 412 | if (!wiphy_ext_feature_isset(local->hw.wiphy, |
| 413 | NL80211_EXT_FEATURE_EXT_KEY_ID)) |
| 414 | return -EINVAL; |
| 415 | |
| 416 | sta = sta_info_get_bss(sdata, mac_addr); |
| 417 | |
| 418 | if (!sta) |
| 419 | return -EINVAL; |
| 420 | |
| 421 | if (sta->ptk_idx == key_idx) |
| 422 | return 0; |
| 423 | |
| 424 | mutex_lock(&local->key_mtx); |
| 425 | key = key_mtx_dereference(local, sta->ptk[key_idx]); |
| 426 | |
| 427 | if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX) |
| 428 | ret = ieee80211_set_tx_key(key); |
| 429 | |
| 430 | mutex_unlock(&local->key_mtx); |
| 431 | return ret; |
| 432 | } |
| 433 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 434 | static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 435 | u8 key_idx, bool pairwise, const u8 *mac_addr, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 436 | struct key_params *params) |
| 437 | { |
Johannes Berg | 26a5845 | 2010-08-27 12:35:55 +0200 | [diff] [blame] | 438 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 439 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 440 | struct sta_info *sta = NULL; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 441 | const struct ieee80211_cipher_scheme *cs = NULL; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 442 | struct ieee80211_key *key; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 443 | int err; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 444 | |
Johannes Berg | 26a5845 | 2010-08-27 12:35:55 +0200 | [diff] [blame] | 445 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 446 | return -ENETDOWN; |
| 447 | |
Alexander Wetzel | 96fc6ef | 2019-03-19 21:34:08 +0100 | [diff] [blame] | 448 | if (pairwise && params->mode == NL80211_KEY_SET_TX) |
| 449 | return ieee80211_set_tx(sdata, mac_addr, key_idx); |
| 450 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 451 | /* reject WEP and TKIP keys if WEP failed to initialize */ |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 452 | switch (params->cipher) { |
| 453 | case WLAN_CIPHER_SUITE_WEP40: |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 454 | case WLAN_CIPHER_SUITE_TKIP: |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 455 | case WLAN_CIPHER_SUITE_WEP104: |
Ard Biesheuvel | 5fdb373 | 2019-06-12 18:19:54 +0200 | [diff] [blame] | 456 | if (WARN_ON_ONCE(fips_enabled)) |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 457 | return -EINVAL; |
Gustavo A. R. Silva | aaaee2d | 2020-11-20 12:36:45 -0600 | [diff] [blame] | 458 | break; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 459 | case WLAN_CIPHER_SUITE_CCMP: |
Jouni Malinen | 2b2ba0d | 2015-01-24 19:52:07 +0200 | [diff] [blame] | 460 | case WLAN_CIPHER_SUITE_CCMP_256: |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 461 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Jouni Malinen | 56c52da | 2015-01-24 19:52:08 +0200 | [diff] [blame] | 462 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
Jouni Malinen | 8ade538 | 2015-01-24 19:52:09 +0200 | [diff] [blame] | 463 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 464 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 465 | case WLAN_CIPHER_SUITE_GCMP: |
Jouni Malinen | 00b9cfa | 2015-01-24 19:52:06 +0200 | [diff] [blame] | 466 | case WLAN_CIPHER_SUITE_GCMP_256: |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 467 | break; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 468 | default: |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 469 | cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type); |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 470 | break; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 471 | } |
| 472 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 473 | key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len, |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 474 | params->key, params->seq_len, params->seq, |
| 475 | cs); |
Ben Hutchings | 1ac62ba | 2010-08-01 17:37:03 +0100 | [diff] [blame] | 476 | if (IS_ERR(key)) |
| 477 | return PTR_ERR(key); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 478 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 479 | if (pairwise) |
| 480 | key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE; |
| 481 | |
Alexander Wetzel | 96fc6ef | 2019-03-19 21:34:08 +0100 | [diff] [blame] | 482 | if (params->mode == NL80211_KEY_NO_TX) |
| 483 | key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX; |
| 484 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 485 | mutex_lock(&local->sta_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 486 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 487 | if (mac_addr) { |
Johannes Berg | 850092d | 2016-10-04 15:32:16 +0200 | [diff] [blame] | 488 | sta = sta_info_get_bss(sdata, mac_addr); |
Johannes Berg | 1626e0f | 2013-01-11 14:34:25 +0100 | [diff] [blame] | 489 | /* |
| 490 | * The ASSOC test makes sure the driver is ready to |
| 491 | * receive the key. When wpa_supplicant has roamed |
| 492 | * using FT, it attempts to set the key before |
| 493 | * association has completed, this rejects that attempt |
Stephen Hemminger | d070f91 | 2014-10-29 22:55:58 -0700 | [diff] [blame] | 494 | * so it will set the key again after association. |
Johannes Berg | 1626e0f | 2013-01-11 14:34:25 +0100 | [diff] [blame] | 495 | * |
| 496 | * TODO: accept the key if we have a station entry and |
| 497 | * add it to the device after the station. |
| 498 | */ |
| 499 | if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) { |
Johannes Berg | 79cf2df | 2013-03-06 22:53:52 +0100 | [diff] [blame] | 500 | ieee80211_key_free_unused(key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 501 | err = -ENOENT; |
| 502 | goto out_unlock; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 503 | } |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 504 | } |
| 505 | |
Johannes Berg | e548c49 | 2012-09-04 17:08:23 +0200 | [diff] [blame] | 506 | switch (sdata->vif.type) { |
| 507 | case NL80211_IFTYPE_STATION: |
| 508 | if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED) |
| 509 | key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; |
| 510 | break; |
| 511 | case NL80211_IFTYPE_AP: |
| 512 | case NL80211_IFTYPE_AP_VLAN: |
| 513 | /* Keys without a station are used for TX only */ |
Felix Fietkau | 211710c | 2018-09-29 16:01:58 +0200 | [diff] [blame] | 514 | if (sta && test_sta_flag(sta, WLAN_STA_MFP)) |
Johannes Berg | e548c49 | 2012-09-04 17:08:23 +0200 | [diff] [blame] | 515 | key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; |
| 516 | break; |
| 517 | case NL80211_IFTYPE_ADHOC: |
| 518 | /* no MFP (yet) */ |
| 519 | break; |
| 520 | case NL80211_IFTYPE_MESH_POINT: |
| 521 | #ifdef CONFIG_MAC80211_MESH |
| 522 | if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE) |
| 523 | key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; |
| 524 | break; |
| 525 | #endif |
| 526 | case NL80211_IFTYPE_WDS: |
| 527 | case NL80211_IFTYPE_MONITOR: |
| 528 | case NL80211_IFTYPE_P2P_DEVICE: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 529 | case NL80211_IFTYPE_NAN: |
Johannes Berg | e548c49 | 2012-09-04 17:08:23 +0200 | [diff] [blame] | 530 | case NL80211_IFTYPE_UNSPECIFIED: |
| 531 | case NUM_NL80211_IFTYPES: |
| 532 | case NL80211_IFTYPE_P2P_CLIENT: |
| 533 | case NL80211_IFTYPE_P2P_GO: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 534 | case NL80211_IFTYPE_OCB: |
Johannes Berg | e548c49 | 2012-09-04 17:08:23 +0200 | [diff] [blame] | 535 | /* shouldn't happen */ |
| 536 | WARN_ON_ONCE(1); |
| 537 | break; |
| 538 | } |
| 539 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 540 | if (sta) |
| 541 | sta->cipher_scheme = cs; |
| 542 | |
Johannes Berg | 3ffc2a9 | 2010-08-27 14:26:52 +0300 | [diff] [blame] | 543 | err = ieee80211_key_link(key, sdata, sta); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 544 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 545 | out_unlock: |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 546 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 547 | |
| 548 | return err; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 552 | u8 key_idx, bool pairwise, const u8 *mac_addr) |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 553 | { |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 554 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 555 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 556 | struct sta_info *sta; |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 557 | struct ieee80211_key *key = NULL; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 558 | int ret; |
| 559 | |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 560 | mutex_lock(&local->sta_mtx); |
| 561 | mutex_lock(&local->key_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 562 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 563 | if (mac_addr) { |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 564 | ret = -ENOENT; |
| 565 | |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 566 | sta = sta_info_get_bss(sdata, mac_addr); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 567 | if (!sta) |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 568 | goto out_unlock; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 569 | |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 570 | if (pairwise) |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 571 | key = key_mtx_dereference(local, sta->ptk[key_idx]); |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 572 | else |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 573 | key = key_mtx_dereference(local, sta->gtk[key_idx]); |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 574 | } else |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 575 | key = key_mtx_dereference(local, sdata->keys[key_idx]); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 576 | |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 577 | if (!key) { |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 578 | ret = -ENOENT; |
| 579 | goto out_unlock; |
| 580 | } |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 581 | |
Manikanta Pubbisetty | 133bf90 | 2018-07-10 16:48:27 +0530 | [diff] [blame] | 582 | ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 583 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 584 | ret = 0; |
| 585 | out_unlock: |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 586 | mutex_unlock(&local->key_mtx); |
| 587 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 588 | |
| 589 | return ret; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 590 | } |
| 591 | |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 592 | static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 593 | u8 key_idx, bool pairwise, const u8 *mac_addr, |
| 594 | void *cookie, |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 595 | void (*callback)(void *cookie, |
| 596 | struct key_params *params)) |
| 597 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 598 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 599 | struct sta_info *sta = NULL; |
| 600 | u8 seq[6] = {0}; |
| 601 | struct key_params params; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 602 | struct ieee80211_key *key = NULL; |
Johannes Berg | aba83a0b | 2011-07-06 21:59:39 +0200 | [diff] [blame] | 603 | u64 pn64; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 604 | u32 iv32; |
| 605 | u16 iv16; |
| 606 | int err = -ENOENT; |
Johannes Berg | 9352c19 | 2015-04-20 18:12:41 +0200 | [diff] [blame] | 607 | struct ieee80211_key_seq kseq = {}; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 608 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 609 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 610 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 611 | rcu_read_lock(); |
| 612 | |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 613 | if (mac_addr) { |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 614 | sta = sta_info_get_bss(sdata, mac_addr); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 615 | if (!sta) |
| 616 | goto out; |
| 617 | |
Max Stepanov | 354e159 | 2013-12-08 13:30:52 +0200 | [diff] [blame] | 618 | if (pairwise && key_idx < NUM_DEFAULT_KEYS) |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 619 | key = rcu_dereference(sta->ptk[key_idx]); |
Max Stepanov | 31f1f4e | 2013-12-08 13:31:29 +0200 | [diff] [blame] | 620 | else if (!pairwise && |
Jouni Malinen | e5473e8 | 2020-02-22 15:25:44 +0200 | [diff] [blame] | 621 | key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS + |
| 622 | NUM_DEFAULT_BEACON_KEYS) |
Johannes Berg | a3836e0 | 2011-05-12 15:11:37 +0200 | [diff] [blame] | 623 | key = rcu_dereference(sta->gtk[key_idx]); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 624 | } else |
Johannes Berg | a3836e0 | 2011-05-12 15:11:37 +0200 | [diff] [blame] | 625 | key = rcu_dereference(sdata->keys[key_idx]); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 626 | |
| 627 | if (!key) |
| 628 | goto out; |
| 629 | |
| 630 | memset(¶ms, 0, sizeof(params)); |
| 631 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 632 | params.cipher = key->conf.cipher; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 633 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 634 | switch (key->conf.cipher) { |
| 635 | case WLAN_CIPHER_SUITE_TKIP: |
Eliad Peller | f8079d4 | 2016-02-14 13:56:35 +0200 | [diff] [blame] | 636 | pn64 = atomic64_read(&key->conf.tx_pn); |
| 637 | iv32 = TKIP_PN_TO_IV32(pn64); |
| 638 | iv16 = TKIP_PN_TO_IV16(pn64); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 639 | |
Johannes Berg | 9352c19 | 2015-04-20 18:12:41 +0200 | [diff] [blame] | 640 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && |
| 641 | !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { |
| 642 | drv_get_key_seq(sdata->local, key, &kseq); |
| 643 | iv32 = kseq.tkip.iv32; |
| 644 | iv16 = kseq.tkip.iv16; |
| 645 | } |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 646 | |
| 647 | seq[0] = iv16 & 0xff; |
| 648 | seq[1] = (iv16 >> 8) & 0xff; |
| 649 | seq[2] = iv32 & 0xff; |
| 650 | seq[3] = (iv32 >> 8) & 0xff; |
| 651 | seq[4] = (iv32 >> 16) & 0xff; |
| 652 | seq[5] = (iv32 >> 24) & 0xff; |
| 653 | params.seq = seq; |
| 654 | params.seq_len = 6; |
| 655 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 656 | case WLAN_CIPHER_SUITE_CCMP: |
Jouni Malinen | 2b2ba0d | 2015-01-24 19:52:07 +0200 | [diff] [blame] | 657 | case WLAN_CIPHER_SUITE_CCMP_256: |
Johannes Berg | db388a5 | 2015-06-01 15:36:51 +0200 | [diff] [blame] | 658 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 659 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
| 660 | BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) != |
| 661 | offsetof(typeof(kseq), aes_cmac)); |
Gustavo A. R. Silva | fc0561d | 2020-07-07 15:45:48 -0500 | [diff] [blame] | 662 | fallthrough; |
Johannes Berg | db388a5 | 2015-06-01 15:36:51 +0200 | [diff] [blame] | 663 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 664 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 665 | BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) != |
| 666 | offsetof(typeof(kseq), aes_gmac)); |
Gustavo A. R. Silva | fc0561d | 2020-07-07 15:45:48 -0500 | [diff] [blame] | 667 | fallthrough; |
Johannes Berg | db388a5 | 2015-06-01 15:36:51 +0200 | [diff] [blame] | 668 | case WLAN_CIPHER_SUITE_GCMP: |
| 669 | case WLAN_CIPHER_SUITE_GCMP_256: |
| 670 | BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) != |
| 671 | offsetof(typeof(kseq), gcmp)); |
| 672 | |
Johannes Berg | 9352c19 | 2015-04-20 18:12:41 +0200 | [diff] [blame] | 673 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && |
| 674 | !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { |
| 675 | drv_get_key_seq(sdata->local, key, &kseq); |
| 676 | memcpy(seq, kseq.ccmp.pn, 6); |
| 677 | } else { |
Johannes Berg | db388a5 | 2015-06-01 15:36:51 +0200 | [diff] [blame] | 678 | pn64 = atomic64_read(&key->conf.tx_pn); |
Johannes Berg | 9352c19 | 2015-04-20 18:12:41 +0200 | [diff] [blame] | 679 | seq[0] = pn64; |
| 680 | seq[1] = pn64 >> 8; |
| 681 | seq[2] = pn64 >> 16; |
| 682 | seq[3] = pn64 >> 24; |
| 683 | seq[4] = pn64 >> 32; |
| 684 | seq[5] = pn64 >> 40; |
| 685 | } |
Jouni Malinen | 00b9cfa | 2015-01-24 19:52:06 +0200 | [diff] [blame] | 686 | params.seq = seq; |
| 687 | params.seq_len = 6; |
| 688 | break; |
Johannes Berg | a31cf1c | 2015-04-20 18:21:58 +0200 | [diff] [blame] | 689 | default: |
| 690 | if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) |
| 691 | break; |
| 692 | if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) |
| 693 | break; |
| 694 | drv_get_key_seq(sdata->local, key, &kseq); |
| 695 | params.seq = kseq.hw.seq; |
| 696 | params.seq_len = kseq.hw.seq_len; |
| 697 | break; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | params.key = key->conf.key; |
| 701 | params.key_len = key->conf.keylen; |
| 702 | |
| 703 | callback(cookie, ¶ms); |
| 704 | err = 0; |
| 705 | |
| 706 | out: |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 707 | rcu_read_unlock(); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 708 | return err; |
| 709 | } |
| 710 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 711 | static int ieee80211_config_default_key(struct wiphy *wiphy, |
| 712 | struct net_device *dev, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 713 | u8 key_idx, bool uni, |
| 714 | bool multi) |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 715 | { |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 716 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 717 | |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 718 | ieee80211_set_default_key(sdata, key_idx, uni, multi); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 719 | |
| 720 | return 0; |
| 721 | } |
| 722 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 723 | static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy, |
| 724 | struct net_device *dev, |
| 725 | u8 key_idx) |
| 726 | { |
Johannes Berg | 66c5242 | 2010-07-22 13:58:51 +0200 | [diff] [blame] | 727 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 728 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 729 | ieee80211_set_default_mgmt_key(sdata, key_idx); |
| 730 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 731 | return 0; |
| 732 | } |
| 733 | |
Jouni Malinen | e5473e8 | 2020-02-22 15:25:44 +0200 | [diff] [blame] | 734 | static int ieee80211_config_default_beacon_key(struct wiphy *wiphy, |
| 735 | struct net_device *dev, |
| 736 | u8 key_idx) |
| 737 | { |
| 738 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 739 | |
| 740 | ieee80211_set_default_beacon_key(sdata, key_idx); |
| 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | |
Thomas Pedersen | 6b62bf3 | 2012-03-05 15:31:48 -0800 | [diff] [blame] | 745 | void sta_set_rate_info_tx(struct sta_info *sta, |
| 746 | const struct ieee80211_tx_rate *rate, |
| 747 | struct rate_info *rinfo) |
| 748 | { |
| 749 | rinfo->flags = 0; |
Johannes Berg | 8bc83c2 | 2012-11-09 18:38:32 +0100 | [diff] [blame] | 750 | if (rate->flags & IEEE80211_TX_RC_MCS) { |
Thomas Pedersen | 6b62bf3 | 2012-03-05 15:31:48 -0800 | [diff] [blame] | 751 | rinfo->flags |= RATE_INFO_FLAGS_MCS; |
Johannes Berg | 8bc83c2 | 2012-11-09 18:38:32 +0100 | [diff] [blame] | 752 | rinfo->mcs = rate->idx; |
| 753 | } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) { |
| 754 | rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS; |
| 755 | rinfo->mcs = ieee80211_rate_get_vht_mcs(rate); |
| 756 | rinfo->nss = ieee80211_rate_get_vht_nss(rate); |
| 757 | } else { |
| 758 | struct ieee80211_supported_band *sband; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 759 | int shift = ieee80211_vif_get_shift(&sta->sdata->vif); |
| 760 | u16 brate; |
| 761 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 762 | sband = ieee80211_get_sband(sta->sdata); |
Thomas Pedersen | 8b783d1 | 2020-10-05 09:45:21 -0700 | [diff] [blame] | 763 | WARN_ON_ONCE(sband && !sband->bitrates); |
| 764 | if (sband && sband->bitrates) { |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 765 | brate = sband->bitrates[rate->idx].bitrate; |
| 766 | rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift); |
| 767 | } |
Johannes Berg | 8bc83c2 | 2012-11-09 18:38:32 +0100 | [diff] [blame] | 768 | } |
Thomas Pedersen | 6b62bf3 | 2012-03-05 15:31:48 -0800 | [diff] [blame] | 769 | if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 770 | rinfo->bw = RATE_INFO_BW_40; |
| 771 | else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH) |
| 772 | rinfo->bw = RATE_INFO_BW_80; |
| 773 | else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH) |
| 774 | rinfo->bw = RATE_INFO_BW_160; |
| 775 | else |
| 776 | rinfo->bw = RATE_INFO_BW_20; |
Thomas Pedersen | 6b62bf3 | 2012-03-05 15:31:48 -0800 | [diff] [blame] | 777 | if (rate->flags & IEEE80211_TX_RC_SHORT_GI) |
| 778 | rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI; |
Thomas Pedersen | 6b62bf3 | 2012-03-05 15:31:48 -0800 | [diff] [blame] | 779 | } |
| 780 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 781 | static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 782 | int idx, u8 *mac, struct station_info *sinfo) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 783 | { |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 784 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Victor Goldenshtein | 66572cf | 2012-06-21 10:56:46 +0300 | [diff] [blame] | 785 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 786 | struct sta_info *sta; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 787 | int ret = -ENOENT; |
| 788 | |
Victor Goldenshtein | 66572cf | 2012-06-21 10:56:46 +0300 | [diff] [blame] | 789 | mutex_lock(&local->sta_mtx); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 790 | |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 791 | sta = sta_info_get_by_idx(sdata, idx); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 792 | if (sta) { |
| 793 | ret = 0; |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 794 | memcpy(mac, sta->sta.addr, ETH_ALEN); |
Johannes Berg | 0fdf149 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 795 | sta_set_sinfo(sta, sinfo, true); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 796 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 797 | |
Victor Goldenshtein | 66572cf | 2012-06-21 10:56:46 +0300 | [diff] [blame] | 798 | mutex_unlock(&local->sta_mtx); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 799 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 800 | return ret; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 801 | } |
| 802 | |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 803 | static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev, |
| 804 | int idx, struct survey_info *survey) |
| 805 | { |
| 806 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 807 | |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 808 | return drv_get_survey(local, idx, survey); |
| 809 | } |
| 810 | |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 811 | static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 812 | const u8 *mac, struct station_info *sinfo) |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 813 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 814 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Victor Goldenshtein | 66572cf | 2012-06-21 10:56:46 +0300 | [diff] [blame] | 815 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 816 | struct sta_info *sta; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 817 | int ret = -ENOENT; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 818 | |
Victor Goldenshtein | 66572cf | 2012-06-21 10:56:46 +0300 | [diff] [blame] | 819 | mutex_lock(&local->sta_mtx); |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 820 | |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 821 | sta = sta_info_get_bss(sdata, mac); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 822 | if (sta) { |
| 823 | ret = 0; |
Johannes Berg | 0fdf149 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 824 | sta_set_sinfo(sta, sinfo, true); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 825 | } |
| 826 | |
Victor Goldenshtein | 66572cf | 2012-06-21 10:56:46 +0300 | [diff] [blame] | 827 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 828 | |
| 829 | return ret; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 830 | } |
| 831 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 832 | static int ieee80211_set_monitor_channel(struct wiphy *wiphy, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 833 | struct cfg80211_chan_def *chandef) |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 834 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 835 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 836 | struct ieee80211_sub_if_data *sdata; |
| 837 | int ret = 0; |
| 838 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 839 | if (cfg80211_chandef_identical(&local->monitor_chandef, chandef)) |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 840 | return 0; |
| 841 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 842 | mutex_lock(&local->mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 843 | if (local->use_chanctx) { |
Johannes Berg | 6dd23603 | 2021-11-12 13:51:44 +0100 | [diff] [blame] | 844 | sdata = wiphy_dereference(local->hw.wiphy, |
| 845 | local->monitor_sdata); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 846 | if (sdata) { |
| 847 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 848 | ret = ieee80211_vif_use_channel(sdata, chandef, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 849 | IEEE80211_CHANCTX_EXCLUSIVE); |
| 850 | } |
| 851 | } else if (local->open_count == local->monitors) { |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 852 | local->_oper_chandef = *chandef; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 853 | ieee80211_hw_config(local, 0); |
| 854 | } |
| 855 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 856 | if (ret == 0) |
| 857 | local->monitor_chandef = *chandef; |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 858 | mutex_unlock(&local->mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 859 | |
| 860 | return ret; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 861 | } |
| 862 | |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 863 | static int |
| 864 | ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata, |
| 865 | const u8 *resp, size_t resp_len, |
| 866 | const struct ieee80211_csa_settings *csa, |
| 867 | const struct ieee80211_color_change_settings *cca) |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 868 | { |
Eyal Shapira | aa7a008 | 2012-08-06 14:26:16 +0300 | [diff] [blame] | 869 | struct probe_resp *new, *old; |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 870 | |
| 871 | if (!resp || !resp_len) |
Sujith Manoharan | aba4e6f | 2012-08-22 14:21:07 +0530 | [diff] [blame] | 872 | return 1; |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 873 | |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 874 | old = sdata_dereference(sdata->u.ap.probe_resp, sdata); |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 875 | |
Eyal Shapira | aa7a008 | 2012-08-06 14:26:16 +0300 | [diff] [blame] | 876 | new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL); |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 877 | if (!new) |
| 878 | return -ENOMEM; |
| 879 | |
Eyal Shapira | aa7a008 | 2012-08-06 14:26:16 +0300 | [diff] [blame] | 880 | new->len = resp_len; |
| 881 | memcpy(new->data, resp, resp_len); |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 882 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 883 | if (csa) |
John Crispin | 8552a43 | 2020-08-11 10:01:04 +0200 | [diff] [blame] | 884 | memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp, |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 885 | csa->n_counter_offsets_presp * |
John Crispin | 8552a43 | 2020-08-11 10:01:04 +0200 | [diff] [blame] | 886 | sizeof(new->cntdwn_counter_offsets[0])); |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 887 | else if (cca) |
| 888 | new->cntdwn_counter_offsets[0] = cca->counter_offset_presp; |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 889 | |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 890 | rcu_assign_pointer(sdata->u.ap.probe_resp, new); |
Eyal Shapira | aa7a008 | 2012-08-06 14:26:16 +0300 | [diff] [blame] | 891 | if (old) |
| 892 | kfree_rcu(old, rcu_head); |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
Aloka Dixit | 295b02c | 2020-09-11 00:05:31 +0000 | [diff] [blame] | 897 | static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata, |
| 898 | struct cfg80211_fils_discovery *params) |
| 899 | { |
| 900 | struct fils_discovery_data *new, *old = NULL; |
| 901 | struct ieee80211_fils_discovery *fd; |
| 902 | |
| 903 | if (!params->tmpl || !params->tmpl_len) |
| 904 | return -EINVAL; |
| 905 | |
| 906 | fd = &sdata->vif.bss_conf.fils_discovery; |
| 907 | fd->min_interval = params->min_interval; |
| 908 | fd->max_interval = params->max_interval; |
| 909 | |
| 910 | old = sdata_dereference(sdata->u.ap.fils_discovery, sdata); |
| 911 | new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL); |
| 912 | if (!new) |
| 913 | return -ENOMEM; |
| 914 | new->len = params->tmpl_len; |
| 915 | memcpy(new->data, params->tmpl, params->tmpl_len); |
| 916 | rcu_assign_pointer(sdata->u.ap.fils_discovery, new); |
| 917 | |
| 918 | if (old) |
| 919 | kfree_rcu(old, rcu_head); |
| 920 | |
| 921 | return 0; |
| 922 | } |
| 923 | |
Aloka Dixit | 632189a | 2020-09-11 00:33:01 +0000 | [diff] [blame] | 924 | static int |
| 925 | ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata, |
| 926 | struct cfg80211_unsol_bcast_probe_resp *params) |
| 927 | { |
| 928 | struct unsol_bcast_probe_resp_data *new, *old = NULL; |
| 929 | |
| 930 | if (!params->tmpl || !params->tmpl_len) |
| 931 | return -EINVAL; |
| 932 | |
| 933 | old = sdata_dereference(sdata->u.ap.unsol_bcast_probe_resp, sdata); |
| 934 | new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL); |
| 935 | if (!new) |
| 936 | return -ENOMEM; |
| 937 | new->len = params->tmpl_len; |
| 938 | memcpy(new->data, params->tmpl, params->tmpl_len); |
| 939 | rcu_assign_pointer(sdata->u.ap.unsol_bcast_probe_resp, new); |
| 940 | |
| 941 | if (old) |
| 942 | kfree_rcu(old, rcu_head); |
| 943 | |
| 944 | sdata->vif.bss_conf.unsol_bcast_probe_resp_interval = |
| 945 | params->interval; |
| 946 | |
| 947 | return 0; |
| 948 | } |
| 949 | |
Pradeep Kumar Chitrapu | bc84797 | 2018-10-03 20:19:20 -0700 | [diff] [blame] | 950 | static int ieee80211_set_ftm_responder_params( |
| 951 | struct ieee80211_sub_if_data *sdata, |
| 952 | const u8 *lci, size_t lci_len, |
| 953 | const u8 *civicloc, size_t civicloc_len) |
| 954 | { |
| 955 | struct ieee80211_ftm_responder_params *new, *old; |
| 956 | struct ieee80211_bss_conf *bss_conf; |
| 957 | u8 *pos; |
| 958 | int len; |
| 959 | |
Johannes Berg | 554be83 | 2018-12-15 11:03:24 +0200 | [diff] [blame] | 960 | if (!lci_len && !civicloc_len) |
| 961 | return 0; |
Pradeep Kumar Chitrapu | bc84797 | 2018-10-03 20:19:20 -0700 | [diff] [blame] | 962 | |
| 963 | bss_conf = &sdata->vif.bss_conf; |
| 964 | old = bss_conf->ftmr_params; |
| 965 | len = lci_len + civicloc_len; |
| 966 | |
| 967 | new = kzalloc(sizeof(*new) + len, GFP_KERNEL); |
| 968 | if (!new) |
| 969 | return -ENOMEM; |
| 970 | |
| 971 | pos = (u8 *)(new + 1); |
| 972 | if (lci_len) { |
| 973 | new->lci_len = lci_len; |
| 974 | new->lci = pos; |
| 975 | memcpy(pos, lci, lci_len); |
| 976 | pos += lci_len; |
| 977 | } |
| 978 | |
| 979 | if (civicloc_len) { |
| 980 | new->civicloc_len = civicloc_len; |
| 981 | new->civicloc = pos; |
| 982 | memcpy(pos, civicloc, civicloc_len); |
| 983 | pos += civicloc_len; |
| 984 | } |
| 985 | |
| 986 | bss_conf->ftmr_params = new; |
| 987 | kfree(old); |
| 988 | |
| 989 | return 0; |
| 990 | } |
| 991 | |
Luciano Coelho | 0ae0796 | 2013-12-08 09:42:25 +0200 | [diff] [blame] | 992 | static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 993 | struct cfg80211_beacon_data *params, |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 994 | const struct ieee80211_csa_settings *csa, |
| 995 | const struct ieee80211_color_change_settings *cca) |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 996 | { |
| 997 | struct beacon_data *new, *old; |
| 998 | int new_head_len, new_tail_len; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 999 | int size, err; |
| 1000 | u32 changed = BSS_CHANGED_BEACON; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1001 | |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 1002 | old = sdata_dereference(sdata->u.ap.beacon, sdata); |
| 1003 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1004 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1005 | /* Need to have a beacon head if we don't have one yet */ |
| 1006 | if (!params->head && !old) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1007 | return -EINVAL; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1008 | |
| 1009 | /* new or old head? */ |
| 1010 | if (params->head) |
| 1011 | new_head_len = params->head_len; |
| 1012 | else |
| 1013 | new_head_len = old->head_len; |
| 1014 | |
| 1015 | /* new or old tail? */ |
| 1016 | if (params->tail || !old) |
| 1017 | /* params->tail_len will be zero for !params->tail */ |
| 1018 | new_tail_len = params->tail_len; |
| 1019 | else |
| 1020 | new_tail_len = old->tail_len; |
| 1021 | |
| 1022 | size = sizeof(*new) + new_head_len + new_tail_len; |
| 1023 | |
| 1024 | new = kzalloc(size, GFP_KERNEL); |
| 1025 | if (!new) |
| 1026 | return -ENOMEM; |
| 1027 | |
| 1028 | /* start filling the new info now */ |
| 1029 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1030 | /* |
| 1031 | * pointers go into the block we allocated, |
| 1032 | * memory is | beacon_data | head | tail | |
| 1033 | */ |
| 1034 | new->head = ((u8 *) new) + sizeof(*new); |
| 1035 | new->tail = new->head + new_head_len; |
| 1036 | new->head_len = new_head_len; |
| 1037 | new->tail_len = new_tail_len; |
| 1038 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 1039 | if (csa) { |
John Crispin | 8552a43 | 2020-08-11 10:01:04 +0200 | [diff] [blame] | 1040 | new->cntdwn_current_counter = csa->count; |
| 1041 | memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon, |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 1042 | csa->n_counter_offsets_beacon * |
John Crispin | 8552a43 | 2020-08-11 10:01:04 +0200 | [diff] [blame] | 1043 | sizeof(new->cntdwn_counter_offsets[0])); |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 1044 | } else if (cca) { |
| 1045 | new->cntdwn_current_counter = cca->count; |
| 1046 | new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon; |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 1047 | } |
| 1048 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1049 | /* copy in head */ |
| 1050 | if (params->head) |
| 1051 | memcpy(new->head, params->head, new_head_len); |
| 1052 | else |
| 1053 | memcpy(new->head, old->head, new_head_len); |
| 1054 | |
| 1055 | /* copy in optional tail */ |
| 1056 | if (params->tail) |
| 1057 | memcpy(new->tail, params->tail, new_tail_len); |
| 1058 | else |
| 1059 | if (old) |
| 1060 | memcpy(new->tail, old->tail, new_tail_len); |
| 1061 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1062 | err = ieee80211_set_probe_resp(sdata, params->probe_resp, |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 1063 | params->probe_resp_len, csa, cca); |
Lorenzo Bianconi | bcc27fa | 2019-07-03 00:29:47 +0200 | [diff] [blame] | 1064 | if (err < 0) { |
| 1065 | kfree(new); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1066 | return err; |
Lorenzo Bianconi | bcc27fa | 2019-07-03 00:29:47 +0200 | [diff] [blame] | 1067 | } |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1068 | if (err == 0) |
| 1069 | changed |= BSS_CHANGED_AP_PROBE_RESP; |
Johannes Berg | 19885c4 | 2010-02-05 11:45:06 +0100 | [diff] [blame] | 1070 | |
Pradeep Kumar Chitrapu | bc84797 | 2018-10-03 20:19:20 -0700 | [diff] [blame] | 1071 | if (params->ftm_responder != -1) { |
| 1072 | sdata->vif.bss_conf.ftm_responder = params->ftm_responder; |
| 1073 | err = ieee80211_set_ftm_responder_params(sdata, |
| 1074 | params->lci, |
| 1075 | params->lci_len, |
| 1076 | params->civicloc, |
| 1077 | params->civicloc_len); |
| 1078 | |
Lorenzo Bianconi | bcc27fa | 2019-07-03 00:29:47 +0200 | [diff] [blame] | 1079 | if (err < 0) { |
| 1080 | kfree(new); |
Pradeep Kumar Chitrapu | bc84797 | 2018-10-03 20:19:20 -0700 | [diff] [blame] | 1081 | return err; |
Lorenzo Bianconi | bcc27fa | 2019-07-03 00:29:47 +0200 | [diff] [blame] | 1082 | } |
Pradeep Kumar Chitrapu | bc84797 | 2018-10-03 20:19:20 -0700 | [diff] [blame] | 1083 | |
| 1084 | changed |= BSS_CHANGED_FTM_RESPONDER; |
| 1085 | } |
| 1086 | |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 1087 | rcu_assign_pointer(sdata->u.ap.beacon, new); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1088 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1089 | if (old) |
| 1090 | kfree_rcu(old, rcu_head); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1091 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1092 | return changed; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1093 | } |
| 1094 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1095 | static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, |
| 1096 | struct cfg80211_ap_settings *params) |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1097 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1098 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 1099 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1100 | struct beacon_data *old; |
Johannes Berg | 665c93a | 2011-11-04 11:18:11 +0100 | [diff] [blame] | 1101 | struct ieee80211_sub_if_data *vlan; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1102 | u32 changed = BSS_CHANGED_BEACON_INT | |
| 1103 | BSS_CHANGED_BEACON_ENABLED | |
| 1104 | BSS_CHANGED_BEACON | |
Johannes Berg | 339afbf | 2012-11-14 15:21:17 +0100 | [diff] [blame] | 1105 | BSS_CHANGED_SSID | |
Johannes Berg | 4bcc56b | 2014-11-13 11:23:53 +0100 | [diff] [blame] | 1106 | BSS_CHANGED_P2P_PS | |
John Crispin | a0de1ca3 | 2019-05-28 13:49:48 +0200 | [diff] [blame] | 1107 | BSS_CHANGED_TXPOWER | |
P Praneesh | 322cd27 | 2020-07-09 08:16:21 +0530 | [diff] [blame] | 1108 | BSS_CHANGED_TWT; |
Jouni Malinen | 08fad43 | 2020-04-25 18:57:12 +0300 | [diff] [blame] | 1109 | int i, err; |
Rakesh Pillai | 83e37e0 | 2019-02-15 14:16:02 +0530 | [diff] [blame] | 1110 | int prev_beacon_int; |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1111 | |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 1112 | old = sdata_dereference(sdata->u.ap.beacon, sdata); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1113 | if (old) |
| 1114 | return -EALREADY; |
| 1115 | |
Ilan Peer | 52b4810 | 2020-01-31 13:12:56 +0200 | [diff] [blame] | 1116 | if (params->smps_mode != NL80211_SMPS_OFF) |
| 1117 | return -ENOTSUPP; |
| 1118 | |
| 1119 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
Emmanuel Grumbach | b3dd827 | 2017-06-10 13:52:45 +0300 | [diff] [blame] | 1120 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 1121 | sdata->needed_rx_chains = sdata->local->rx_chains; |
| 1122 | |
Rakesh Pillai | 83e37e0 | 2019-02-15 14:16:02 +0530 | [diff] [blame] | 1123 | prev_beacon_int = sdata->vif.bss_conf.beacon_int; |
Johannes Berg | ac668af | 2016-10-21 14:25:14 +0200 | [diff] [blame] | 1124 | sdata->vif.bss_conf.beacon_int = params->beacon_interval; |
| 1125 | |
Shaul Triebitz | 03efb86 | 2020-01-31 13:12:55 +0200 | [diff] [blame] | 1126 | if (params->he_cap && params->he_oper) { |
Shaul Triebitz | 34fb190 | 2018-08-31 11:31:15 +0300 | [diff] [blame] | 1127 | sdata->vif.bss_conf.he_support = true; |
Shaul Triebitz | 03efb86 | 2020-01-31 13:12:55 +0200 | [diff] [blame] | 1128 | sdata->vif.bss_conf.htc_trig_based_pkt_ext = |
| 1129 | le32_get_bits(params->he_oper->he_oper_params, |
| 1130 | IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK); |
| 1131 | sdata->vif.bss_conf.frame_time_rts_th = |
| 1132 | le32_get_bits(params->he_oper->he_oper_params, |
| 1133 | IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK); |
P Praneesh | 322cd27 | 2020-07-09 08:16:21 +0530 | [diff] [blame] | 1134 | changed |= BSS_CHANGED_HE_OBSS_PD; |
| 1135 | |
Johannes Berg | 75e6b59 | 2020-07-30 13:00:52 +0200 | [diff] [blame] | 1136 | if (params->he_bss_color.enabled) |
P Praneesh | 322cd27 | 2020-07-09 08:16:21 +0530 | [diff] [blame] | 1137 | changed |= BSS_CHANGED_HE_BSS_COLOR; |
Shaul Triebitz | 03efb86 | 2020-01-31 13:12:55 +0200 | [diff] [blame] | 1138 | } |
Shaul Triebitz | 34fb190 | 2018-08-31 11:31:15 +0300 | [diff] [blame] | 1139 | |
John Crispin | 1719642 | 2021-09-15 19:54:35 -0700 | [diff] [blame] | 1140 | if (sdata->vif.type == NL80211_IFTYPE_AP && |
| 1141 | params->mbssid_config.tx_wdev) { |
| 1142 | err = ieee80211_set_ap_mbssid_options(sdata, |
| 1143 | params->mbssid_config); |
| 1144 | if (err) |
| 1145 | return err; |
| 1146 | } |
| 1147 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 1148 | mutex_lock(&local->mtx); |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 1149 | err = ieee80211_vif_use_channel(sdata, ¶ms->chandef, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1150 | IEEE80211_CHANCTX_SHARED); |
Michal Kazior | 4e141da | 2014-03-05 13:14:08 +0100 | [diff] [blame] | 1151 | if (!err) |
| 1152 | ieee80211_vif_copy_chanctx_to_vlans(sdata, false); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 1153 | mutex_unlock(&local->mtx); |
Rakesh Pillai | 83e37e0 | 2019-02-15 14:16:02 +0530 | [diff] [blame] | 1154 | if (err) { |
| 1155 | sdata->vif.bss_conf.beacon_int = prev_beacon_int; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1156 | return err; |
Rakesh Pillai | 83e37e0 | 2019-02-15 14:16:02 +0530 | [diff] [blame] | 1157 | } |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1158 | |
Johannes Berg | 665c93a | 2011-11-04 11:18:11 +0100 | [diff] [blame] | 1159 | /* |
| 1160 | * Apply control port protocol, this allows us to |
| 1161 | * not encrypt dynamic WEP control frames. |
| 1162 | */ |
| 1163 | sdata->control_port_protocol = params->crypto.control_port_ethertype; |
| 1164 | sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt; |
Denis Kenzior | 018f6fb | 2018-03-26 12:52:51 -0500 | [diff] [blame] | 1165 | sdata->control_port_over_nl80211 = |
| 1166 | params->crypto.control_port_over_nl80211; |
Markus Theil | 7f3f96c | 2020-03-12 10:10:54 +0100 | [diff] [blame] | 1167 | sdata->control_port_no_preauth = |
| 1168 | params->crypto.control_port_no_preauth; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 1169 | sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local, |
| 1170 | ¶ms->crypto, |
| 1171 | sdata->vif.type); |
| 1172 | |
Johannes Berg | 665c93a | 2011-11-04 11:18:11 +0100 | [diff] [blame] | 1173 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) { |
| 1174 | vlan->control_port_protocol = |
| 1175 | params->crypto.control_port_ethertype; |
| 1176 | vlan->control_port_no_encrypt = |
| 1177 | params->crypto.control_port_no_encrypt; |
Denis Kenzior | 018f6fb | 2018-03-26 12:52:51 -0500 | [diff] [blame] | 1178 | vlan->control_port_over_nl80211 = |
| 1179 | params->crypto.control_port_over_nl80211; |
Markus Theil | 7f3f96c | 2020-03-12 10:10:54 +0100 | [diff] [blame] | 1180 | vlan->control_port_no_preauth = |
| 1181 | params->crypto.control_port_no_preauth; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 1182 | vlan->encrypt_headroom = |
| 1183 | ieee80211_cs_headroom(sdata->local, |
| 1184 | ¶ms->crypto, |
| 1185 | vlan->vif.type); |
Johannes Berg | 665c93a | 2011-11-04 11:18:11 +0100 | [diff] [blame] | 1186 | } |
| 1187 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1188 | sdata->vif.bss_conf.dtim_period = params->dtim_period; |
Johannes Berg | d6a8322 | 2012-12-14 14:06:28 +0100 | [diff] [blame] | 1189 | sdata->vif.bss_conf.enable_beacon = true; |
Ayala Beker | 52cfa1d | 2016-03-17 15:41:39 +0200 | [diff] [blame] | 1190 | sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p; |
John Crispin | a0de1ca3 | 2019-05-28 13:49:48 +0200 | [diff] [blame] | 1191 | sdata->vif.bss_conf.twt_responder = params->twt_responder; |
Johannes Berg | a5a5503 | 2020-12-06 14:54:41 +0200 | [diff] [blame] | 1192 | sdata->vif.bss_conf.he_obss_pd = params->he_obss_pd; |
Johannes Berg | 539a36b | 2020-12-06 14:54:40 +0200 | [diff] [blame] | 1193 | sdata->vif.bss_conf.he_bss_color = params->he_bss_color; |
Thomas Pedersen | 1d00ce8 | 2020-09-21 19:28:15 -0700 | [diff] [blame] | 1194 | sdata->vif.bss_conf.s1g = params->chandef.chan->band == |
| 1195 | NL80211_BAND_S1GHZ; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1196 | |
| 1197 | sdata->vif.bss_conf.ssid_len = params->ssid_len; |
| 1198 | if (params->ssid_len) |
| 1199 | memcpy(sdata->vif.bss_conf.ssid, params->ssid, |
| 1200 | params->ssid_len); |
| 1201 | sdata->vif.bss_conf.hidden_ssid = |
| 1202 | (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE); |
| 1203 | |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 1204 | memset(&sdata->vif.bss_conf.p2p_noa_attr, 0, |
| 1205 | sizeof(sdata->vif.bss_conf.p2p_noa_attr)); |
| 1206 | sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow = |
| 1207 | params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK; |
| 1208 | if (params->p2p_opp_ps) |
| 1209 | sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |= |
| 1210 | IEEE80211_P2P_OPPPS_ENABLE_BIT; |
Johannes Berg | 339afbf | 2012-11-14 15:21:17 +0100 | [diff] [blame] | 1211 | |
Jouni Malinen | 08fad43 | 2020-04-25 18:57:12 +0300 | [diff] [blame] | 1212 | sdata->beacon_rate_set = false; |
| 1213 | if (wiphy_ext_feature_isset(local->hw.wiphy, |
| 1214 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) { |
| 1215 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 1216 | sdata->beacon_rateidx_mask[i] = |
| 1217 | params->beacon_rate.control[i].legacy; |
| 1218 | if (sdata->beacon_rateidx_mask[i]) |
| 1219 | sdata->beacon_rate_set = true; |
| 1220 | } |
| 1221 | } |
| 1222 | |
Rajkumar Manoharan | ba6ff70 | 2020-10-03 15:04:18 -0700 | [diff] [blame] | 1223 | if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) |
| 1224 | sdata->vif.bss_conf.beacon_tx_rate = params->beacon_rate; |
| 1225 | |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 1226 | err = ieee80211_assign_beacon(sdata, ¶ms->beacon, NULL, NULL); |
Aloka Dixit | 295b02c | 2020-09-11 00:05:31 +0000 | [diff] [blame] | 1227 | if (err < 0) |
| 1228 | goto error; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1229 | changed |= err; |
| 1230 | |
Aloka Dixit | 295b02c | 2020-09-11 00:05:31 +0000 | [diff] [blame] | 1231 | if (params->fils_discovery.max_interval) { |
| 1232 | err = ieee80211_set_fils_discovery(sdata, |
| 1233 | ¶ms->fils_discovery); |
| 1234 | if (err < 0) |
| 1235 | goto error; |
| 1236 | changed |= BSS_CHANGED_FILS_DISCOVERY; |
| 1237 | } |
| 1238 | |
Aloka Dixit | 632189a | 2020-09-11 00:33:01 +0000 | [diff] [blame] | 1239 | if (params->unsol_bcast_probe_resp.interval) { |
| 1240 | err = ieee80211_set_unsol_bcast_probe_resp(sdata, |
| 1241 | ¶ms->unsol_bcast_probe_resp); |
| 1242 | if (err < 0) |
| 1243 | goto error; |
| 1244 | changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP; |
| 1245 | } |
| 1246 | |
Johannes Berg | 1041638 | 2012-10-19 15:44:42 +0200 | [diff] [blame] | 1247 | err = drv_start_ap(sdata->local, sdata); |
| 1248 | if (err) { |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 1249 | old = sdata_dereference(sdata->u.ap.beacon, sdata); |
| 1250 | |
Johannes Berg | 1041638 | 2012-10-19 15:44:42 +0200 | [diff] [blame] | 1251 | if (old) |
| 1252 | kfree_rcu(old, rcu_head); |
| 1253 | RCU_INIT_POINTER(sdata->u.ap.beacon, NULL); |
Aloka Dixit | 295b02c | 2020-09-11 00:05:31 +0000 | [diff] [blame] | 1254 | goto error; |
Johannes Berg | 1041638 | 2012-10-19 15:44:42 +0200 | [diff] [blame] | 1255 | } |
| 1256 | |
Thomas Pedersen | 057d5f4 | 2013-12-19 10:25:15 -0800 | [diff] [blame] | 1257 | ieee80211_recalc_dtim(local, sdata); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1258 | ieee80211_bss_info_change_notify(sdata, changed); |
| 1259 | |
Johannes Berg | 3edaf3e | 2012-04-03 10:24:00 +0200 | [diff] [blame] | 1260 | netif_carrier_on(dev); |
| 1261 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) |
| 1262 | netif_carrier_on(vlan->dev); |
| 1263 | |
Johannes Berg | 665c93a | 2011-11-04 11:18:11 +0100 | [diff] [blame] | 1264 | return 0; |
Aloka Dixit | 295b02c | 2020-09-11 00:05:31 +0000 | [diff] [blame] | 1265 | |
| 1266 | error: |
Johannes Berg | 87a2706 | 2021-12-20 10:22:40 +0100 | [diff] [blame] | 1267 | mutex_lock(&local->mtx); |
Aloka Dixit | 295b02c | 2020-09-11 00:05:31 +0000 | [diff] [blame] | 1268 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 87a2706 | 2021-12-20 10:22:40 +0100 | [diff] [blame] | 1269 | mutex_unlock(&local->mtx); |
| 1270 | |
Aloka Dixit | 295b02c | 2020-09-11 00:05:31 +0000 | [diff] [blame] | 1271 | return err; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1272 | } |
| 1273 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1274 | static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev, |
| 1275 | struct cfg80211_beacon_data *params) |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1276 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1277 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1278 | struct beacon_data *old; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1279 | int err; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1280 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1281 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Michal Kazior | dbd7285 | 2014-01-29 07:56:21 +0100 | [diff] [blame] | 1282 | sdata_assert_lock(sdata); |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1283 | |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 1284 | /* don't allow changing the beacon while a countdown is in place - offset |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 1285 | * of channel switch counter may change |
| 1286 | */ |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 1287 | if (sdata->vif.csa_active || sdata->vif.color_change_active) |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 1288 | return -EBUSY; |
| 1289 | |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 1290 | old = sdata_dereference(sdata->u.ap.beacon, sdata); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1291 | if (!old) |
| 1292 | return -ENOENT; |
| 1293 | |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 1294 | err = ieee80211_assign_beacon(sdata, params, NULL, NULL); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1295 | if (err < 0) |
| 1296 | return err; |
| 1297 | ieee80211_bss_info_change_notify(sdata, err); |
| 1298 | return 0; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1299 | } |
| 1300 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1301 | static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev) |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1302 | { |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1303 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1304 | struct ieee80211_sub_if_data *vlan; |
| 1305 | struct ieee80211_local *local = sdata->local; |
| 1306 | struct beacon_data *old_beacon; |
| 1307 | struct probe_resp *old_probe_resp; |
Aloka Dixit | 295b02c | 2020-09-11 00:05:31 +0000 | [diff] [blame] | 1308 | struct fils_discovery_data *old_fils_discovery; |
Aloka Dixit | 632189a | 2020-09-11 00:33:01 +0000 | [diff] [blame] | 1309 | struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp; |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 1310 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1311 | |
Michal Kazior | dbd7285 | 2014-01-29 07:56:21 +0100 | [diff] [blame] | 1312 | sdata_assert_lock(sdata); |
| 1313 | |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 1314 | old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata); |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1315 | if (!old_beacon) |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1316 | return -ENOENT; |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 1317 | old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata); |
Aloka Dixit | 295b02c | 2020-09-11 00:05:31 +0000 | [diff] [blame] | 1318 | old_fils_discovery = sdata_dereference(sdata->u.ap.fils_discovery, |
| 1319 | sdata); |
Aloka Dixit | 632189a | 2020-09-11 00:33:01 +0000 | [diff] [blame] | 1320 | old_unsol_bcast_probe_resp = |
| 1321 | sdata_dereference(sdata->u.ap.unsol_bcast_probe_resp, |
| 1322 | sdata); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1323 | |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 1324 | /* abort any running channel switch */ |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1325 | mutex_lock(&local->mtx); |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 1326 | sdata->vif.csa_active = false; |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 1327 | if (sdata->csa_block_tx) { |
| 1328 | ieee80211_wake_vif_queues(local, sdata, |
| 1329 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 1330 | sdata->csa_block_tx = false; |
| 1331 | } |
| 1332 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1333 | mutex_unlock(&local->mtx); |
| 1334 | |
Simon Wunderlich | 1f3b8a2 | 2013-11-21 18:19:53 +0100 | [diff] [blame] | 1335 | kfree(sdata->u.ap.next_beacon); |
| 1336 | sdata->u.ap.next_beacon = NULL; |
| 1337 | |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1338 | /* turn off carrier for this interface and dependent VLANs */ |
Johannes Berg | 3edaf3e | 2012-04-03 10:24:00 +0200 | [diff] [blame] | 1339 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) |
| 1340 | netif_carrier_off(vlan->dev); |
| 1341 | netif_carrier_off(dev); |
| 1342 | |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1343 | /* remove beacon and probe response */ |
Stephen Hemminger | a9b3cd7 | 2011-08-01 16:19:00 +0000 | [diff] [blame] | 1344 | RCU_INIT_POINTER(sdata->u.ap.beacon, NULL); |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1345 | RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL); |
Aloka Dixit | 295b02c | 2020-09-11 00:05:31 +0000 | [diff] [blame] | 1346 | RCU_INIT_POINTER(sdata->u.ap.fils_discovery, NULL); |
Aloka Dixit | 632189a | 2020-09-11 00:33:01 +0000 | [diff] [blame] | 1347 | RCU_INIT_POINTER(sdata->u.ap.unsol_bcast_probe_resp, NULL); |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1348 | kfree_rcu(old_beacon, rcu_head); |
| 1349 | if (old_probe_resp) |
| 1350 | kfree_rcu(old_probe_resp, rcu_head); |
Aloka Dixit | 295b02c | 2020-09-11 00:05:31 +0000 | [diff] [blame] | 1351 | if (old_fils_discovery) |
| 1352 | kfree_rcu(old_fils_discovery, rcu_head); |
Aloka Dixit | 632189a | 2020-09-11 00:33:01 +0000 | [diff] [blame] | 1353 | if (old_unsol_bcast_probe_resp) |
| 1354 | kfree_rcu(old_unsol_bcast_probe_resp, rcu_head); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1355 | |
Pradeep Kumar Chitrapu | bc84797 | 2018-10-03 20:19:20 -0700 | [diff] [blame] | 1356 | kfree(sdata->vif.bss_conf.ftmr_params); |
| 1357 | sdata->vif.bss_conf.ftmr_params = NULL; |
| 1358 | |
Johannes Berg | e716251 | 2013-12-04 23:18:37 +0100 | [diff] [blame] | 1359 | __sta_info_flush(sdata, true); |
Johannes Berg | 7907c7d | 2013-12-04 23:47:09 +0100 | [diff] [blame] | 1360 | ieee80211_free_keys(sdata, true); |
Johannes Berg | 75de911 | 2012-12-14 14:56:03 +0100 | [diff] [blame] | 1361 | |
Johannes Berg | d6a8322 | 2012-12-14 14:06:28 +0100 | [diff] [blame] | 1362 | sdata->vif.bss_conf.enable_beacon = false; |
Jouni Malinen | 08fad43 | 2020-04-25 18:57:12 +0300 | [diff] [blame] | 1363 | sdata->beacon_rate_set = false; |
Marek Puzyniak | 0eabccd | 2013-04-10 13:47:45 +0200 | [diff] [blame] | 1364 | sdata->vif.bss_conf.ssid_len = 0; |
Johannes Berg | d6a8322 | 2012-12-14 14:06:28 +0100 | [diff] [blame] | 1365 | clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1366 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1367 | |
Simon Wunderlich | a6b368f | 2013-06-11 10:44:39 +0200 | [diff] [blame] | 1368 | if (sdata->wdev.cac_started) { |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 1369 | chandef = sdata->vif.bss_conf.chandef; |
Simon Wunderlich | a6b368f | 2013-06-11 10:44:39 +0200 | [diff] [blame] | 1370 | cancel_delayed_work_sync(&sdata->dfs_cac_timer_work); |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 1371 | cfg80211_cac_event(sdata->dev, &chandef, |
| 1372 | NL80211_RADAR_CAC_ABORTED, |
Simon Wunderlich | a6b368f | 2013-06-11 10:44:39 +0200 | [diff] [blame] | 1373 | GFP_KERNEL); |
| 1374 | } |
| 1375 | |
Johannes Berg | 1041638 | 2012-10-19 15:44:42 +0200 | [diff] [blame] | 1376 | drv_stop_ap(sdata->local, sdata); |
| 1377 | |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1378 | /* free all potentially still buffered bcast frames */ |
| 1379 | local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf); |
Felix Fietkau | 6b07d9c | 2016-08-02 11:13:41 +0200 | [diff] [blame] | 1380 | ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf); |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1381 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 1382 | mutex_lock(&local->mtx); |
Michal Kazior | 4e141da | 2014-03-05 13:14:08 +0100 | [diff] [blame] | 1383 | ieee80211_vif_copy_chanctx_to_vlans(sdata, true); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1384 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 1385 | mutex_unlock(&local->mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1386 | |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1387 | return 0; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1388 | } |
| 1389 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 1390 | static int sta_apply_auth_flags(struct ieee80211_local *local, |
| 1391 | struct sta_info *sta, |
| 1392 | u32 mask, u32 set) |
| 1393 | { |
| 1394 | int ret; |
| 1395 | |
| 1396 | if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) && |
| 1397 | set & BIT(NL80211_STA_FLAG_AUTHENTICATED) && |
| 1398 | !test_sta_flag(sta, WLAN_STA_AUTH)) { |
| 1399 | ret = sta_info_move_state(sta, IEEE80211_STA_AUTH); |
| 1400 | if (ret) |
| 1401 | return ret; |
| 1402 | } |
| 1403 | |
| 1404 | if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) && |
| 1405 | set & BIT(NL80211_STA_FLAG_ASSOCIATED) && |
| 1406 | !test_sta_flag(sta, WLAN_STA_ASSOC)) { |
Marek Puzyniak | c23e31c | 2015-03-08 18:04:22 +0200 | [diff] [blame] | 1407 | /* |
| 1408 | * When peer becomes associated, init rate control as |
| 1409 | * well. Some drivers require rate control initialized |
| 1410 | * before drv_sta_state() is called. |
| 1411 | */ |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1412 | if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) |
Marek Puzyniak | c23e31c | 2015-03-08 18:04:22 +0200 | [diff] [blame] | 1413 | rate_control_rate_init(sta); |
| 1414 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 1415 | ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC); |
| 1416 | if (ret) |
| 1417 | return ret; |
| 1418 | } |
| 1419 | |
| 1420 | if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { |
| 1421 | if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 1422 | ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); |
| 1423 | else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
| 1424 | ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC); |
| 1425 | else |
| 1426 | ret = 0; |
| 1427 | if (ret) |
| 1428 | return ret; |
| 1429 | } |
| 1430 | |
| 1431 | if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) && |
| 1432 | !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) && |
| 1433 | test_sta_flag(sta, WLAN_STA_ASSOC)) { |
| 1434 | ret = sta_info_move_state(sta, IEEE80211_STA_AUTH); |
| 1435 | if (ret) |
| 1436 | return ret; |
| 1437 | } |
| 1438 | |
| 1439 | if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) && |
| 1440 | !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) && |
| 1441 | test_sta_flag(sta, WLAN_STA_AUTH)) { |
| 1442 | ret = sta_info_move_state(sta, IEEE80211_STA_NONE); |
| 1443 | if (ret) |
| 1444 | return ret; |
| 1445 | } |
| 1446 | |
| 1447 | return 0; |
| 1448 | } |
| 1449 | |
Johannes Berg | 1365770 | 2015-06-17 10:34:54 +0200 | [diff] [blame] | 1450 | static void sta_apply_mesh_params(struct ieee80211_local *local, |
| 1451 | struct sta_info *sta, |
| 1452 | struct station_parameters *params) |
| 1453 | { |
| 1454 | #ifdef CONFIG_MAC80211_MESH |
| 1455 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 1456 | u32 changed = 0; |
| 1457 | |
| 1458 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) { |
| 1459 | switch (params->plink_state) { |
| 1460 | case NL80211_PLINK_ESTAB: |
| 1461 | if (sta->mesh->plink_state != NL80211_PLINK_ESTAB) |
| 1462 | changed = mesh_plink_inc_estab_count(sdata); |
| 1463 | sta->mesh->plink_state = params->plink_state; |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 1464 | sta->mesh->aid = params->peer_aid; |
Johannes Berg | 1365770 | 2015-06-17 10:34:54 +0200 | [diff] [blame] | 1465 | |
| 1466 | ieee80211_mps_sta_status_update(sta); |
| 1467 | changed |= ieee80211_mps_set_sta_local_pm(sta, |
| 1468 | sdata->u.mesh.mshcfg.power_mode); |
Julan Hsu | 67fc055 | 2019-01-15 15:31:56 -0800 | [diff] [blame] | 1469 | |
| 1470 | ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg); |
| 1471 | /* init at low value */ |
| 1472 | ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10); |
| 1473 | |
Johannes Berg | 1365770 | 2015-06-17 10:34:54 +0200 | [diff] [blame] | 1474 | break; |
| 1475 | case NL80211_PLINK_LISTEN: |
| 1476 | case NL80211_PLINK_BLOCKED: |
| 1477 | case NL80211_PLINK_OPN_SNT: |
| 1478 | case NL80211_PLINK_OPN_RCVD: |
| 1479 | case NL80211_PLINK_CNF_RCVD: |
| 1480 | case NL80211_PLINK_HOLDING: |
| 1481 | if (sta->mesh->plink_state == NL80211_PLINK_ESTAB) |
| 1482 | changed = mesh_plink_dec_estab_count(sdata); |
| 1483 | sta->mesh->plink_state = params->plink_state; |
| 1484 | |
| 1485 | ieee80211_mps_sta_status_update(sta); |
| 1486 | changed |= ieee80211_mps_set_sta_local_pm(sta, |
| 1487 | NL80211_MESH_POWER_UNKNOWN); |
| 1488 | break; |
| 1489 | default: |
| 1490 | /* nothing */ |
| 1491 | break; |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 1495 | switch (params->plink_action) { |
| 1496 | case NL80211_PLINK_ACTION_NO_ACTION: |
| 1497 | /* nothing */ |
| 1498 | break; |
| 1499 | case NL80211_PLINK_ACTION_OPEN: |
| 1500 | changed |= mesh_plink_open(sta); |
| 1501 | break; |
| 1502 | case NL80211_PLINK_ACTION_BLOCK: |
| 1503 | changed |= mesh_plink_block(sta); |
| 1504 | break; |
| 1505 | } |
| 1506 | |
| 1507 | if (params->local_pm) |
| 1508 | changed |= ieee80211_mps_set_sta_local_pm(sta, |
| 1509 | params->local_pm); |
| 1510 | |
| 1511 | ieee80211_mbss_info_change_notify(sdata, changed); |
| 1512 | #endif |
| 1513 | } |
| 1514 | |
Toke Høiland-Jørgensen | 2433647 | 2021-06-23 15:47:55 +0200 | [diff] [blame] | 1515 | static void sta_apply_airtime_params(struct ieee80211_local *local, |
| 1516 | struct sta_info *sta, |
| 1517 | struct station_parameters *params) |
| 1518 | { |
| 1519 | u8 ac; |
| 1520 | |
| 1521 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 1522 | struct airtime_sched_info *air_sched = &local->airtime[ac]; |
| 1523 | struct airtime_info *air_info = &sta->airtime[ac]; |
| 1524 | struct txq_info *txqi; |
| 1525 | u8 tid; |
| 1526 | |
| 1527 | spin_lock_bh(&air_sched->lock); |
| 1528 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 1529 | if (air_info->weight == params->airtime_weight || |
| 1530 | !sta->sta.txq[tid] || |
| 1531 | ac != ieee80211_ac_from_tid(tid)) |
| 1532 | continue; |
| 1533 | |
| 1534 | airtime_weight_set(air_info, params->airtime_weight); |
| 1535 | |
| 1536 | txqi = to_txq_info(sta->sta.txq[tid]); |
| 1537 | if (RB_EMPTY_NODE(&txqi->schedule_order)) |
| 1538 | continue; |
| 1539 | |
| 1540 | ieee80211_update_airtime_weight(local, air_sched, |
| 1541 | 0, true); |
| 1542 | } |
| 1543 | spin_unlock_bh(&air_sched->lock); |
| 1544 | } |
| 1545 | } |
| 1546 | |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1547 | static int sta_apply_parameters(struct ieee80211_local *local, |
| 1548 | struct sta_info *sta, |
| 1549 | struct station_parameters *params) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1550 | { |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1551 | int ret = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1552 | struct ieee80211_supported_band *sband; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1553 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1554 | u32 mask, set; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1555 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 1556 | sband = ieee80211_get_sband(sdata); |
| 1557 | if (!sband) |
| 1558 | return -EINVAL; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1559 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1560 | mask = params->sta_flags_mask; |
| 1561 | set = params->sta_flags_set; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1562 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 1563 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
| 1564 | /* |
| 1565 | * In mesh mode, ASSOCIATED isn't part of the nl80211 |
| 1566 | * API but must follow AUTHENTICATED for driver state. |
| 1567 | */ |
| 1568 | if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) |
| 1569 | mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 1570 | if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) |
| 1571 | set |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1572 | } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { |
| 1573 | /* |
| 1574 | * TDLS -- everything follows authorized, but |
| 1575 | * only becoming authorized is possible, not |
| 1576 | * going back |
| 1577 | */ |
| 1578 | if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) { |
| 1579 | set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 1580 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 1581 | mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 1582 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 1583 | } |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1584 | } |
| 1585 | |
Johannes Berg | 2c44be8 | 2015-03-30 15:09:20 +0200 | [diff] [blame] | 1586 | if (mask & BIT(NL80211_STA_FLAG_WME) && |
| 1587 | local->hw.queues >= IEEE80211_NUM_ACS) |
| 1588 | sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME); |
| 1589 | |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1590 | /* auth flags will be set later for TDLS, |
Bhaskar Chowdhury | b18daca | 2021-03-27 04:42:45 +0530 | [diff] [blame] | 1591 | * and for unassociated stations that move to associated */ |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1592 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
| 1593 | !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) && |
| 1594 | (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) { |
Arik Nemtsov | 68885a5 | 2014-06-11 17:18:19 +0300 | [diff] [blame] | 1595 | ret = sta_apply_auth_flags(local, sta, mask, set); |
| 1596 | if (ret) |
| 1597 | return ret; |
| 1598 | } |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1599 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1600 | if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1601 | if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1602 | set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE); |
| 1603 | else |
| 1604 | clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE); |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1605 | } |
| 1606 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1607 | if (mask & BIT(NL80211_STA_FLAG_MFP)) { |
Tamizh chelvam | 93f0490 | 2015-10-07 10:40:04 +0530 | [diff] [blame] | 1608 | sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP)); |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1609 | if (set & BIT(NL80211_STA_FLAG_MFP)) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1610 | set_sta_flag(sta, WLAN_STA_MFP); |
| 1611 | else |
| 1612 | clear_sta_flag(sta, WLAN_STA_MFP); |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1613 | } |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 1614 | |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 1615 | if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 1616 | if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1617 | set_sta_flag(sta, WLAN_STA_TDLS_PEER); |
| 1618 | else |
| 1619 | clear_sta_flag(sta, WLAN_STA_TDLS_PEER); |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 1620 | } |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1621 | |
Arik Nemtsov | 9041c1f | 2014-11-09 18:50:15 +0200 | [diff] [blame] | 1622 | /* mark TDLS channel switch support, if the AP allows it */ |
| 1623 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
| 1624 | !sdata->u.mgd.tdls_chan_switch_prohibited && |
| 1625 | params->ext_capab_len >= 4 && |
| 1626 | params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH) |
| 1627 | set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH); |
| 1628 | |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 1629 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
Arik Nemtsov | 82c0cc90d | 2015-08-15 22:39:46 +0300 | [diff] [blame] | 1630 | !sdata->u.mgd.tdls_wider_bw_prohibited && |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 1631 | ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) && |
| 1632 | params->ext_capab_len >= 8 && |
| 1633 | params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED) |
| 1634 | set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW); |
| 1635 | |
Johannes Berg | 3b9ce80 | 2011-09-27 20:56:12 +0200 | [diff] [blame] | 1636 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) { |
| 1637 | sta->sta.uapsd_queues = params->uapsd_queues; |
| 1638 | sta->sta.max_sp = params->max_sp; |
| 1639 | } |
Eliad Peller | 9533b4a | 2011-08-23 14:37:47 +0300 | [diff] [blame] | 1640 | |
Emmanuel Grumbach | 506bcfa | 2015-12-13 15:41:05 +0200 | [diff] [blame] | 1641 | /* The sender might not have sent the last bit, consider it to be 0 */ |
| 1642 | if (params->ext_capab_len >= 8) { |
| 1643 | u8 val = (params->ext_capab[7] & |
| 1644 | WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7; |
| 1645 | |
| 1646 | /* we did get all the bits, take the MSB as well */ |
| 1647 | if (params->ext_capab_len >= 9) { |
| 1648 | u8 val_msb = params->ext_capab[8] & |
| 1649 | WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB; |
| 1650 | val_msb <<= 1; |
| 1651 | val |= val_msb; |
| 1652 | } |
| 1653 | |
| 1654 | switch (val) { |
| 1655 | case 1: |
| 1656 | sta->sta.max_amsdu_subframes = 32; |
| 1657 | break; |
| 1658 | case 2: |
| 1659 | sta->sta.max_amsdu_subframes = 16; |
| 1660 | break; |
| 1661 | case 3: |
| 1662 | sta->sta.max_amsdu_subframes = 8; |
| 1663 | break; |
| 1664 | default: |
| 1665 | sta->sta.max_amsdu_subframes = 0; |
| 1666 | } |
| 1667 | } |
| 1668 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1669 | /* |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 1670 | * cfg80211 validates this (1-2007) and allows setting the AID |
| 1671 | * only when creating a new station entry |
| 1672 | */ |
| 1673 | if (params->aid) |
| 1674 | sta->sta.aid = params->aid; |
| 1675 | |
| 1676 | /* |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 1677 | * Some of the following updates would be racy if called on an |
| 1678 | * existing station, via ieee80211_change_station(). However, |
| 1679 | * all such changes are rejected by cfg80211 except for updates |
| 1680 | * changing the supported rates on an existing but not yet used |
| 1681 | * TDLS peer. |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1682 | */ |
| 1683 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1684 | if (params->listen_interval >= 0) |
| 1685 | sta->listen_interval = params->listen_interval; |
| 1686 | |
Ashok Raj Nagarajan | ba905bf | 2019-03-29 16:19:09 +0530 | [diff] [blame] | 1687 | if (params->sta_modify_mask & STATION_PARAM_APPLY_STA_TXPOWER) { |
| 1688 | sta->sta.txpwr.type = params->txpwr.type; |
| 1689 | if (params->txpwr.type == NL80211_TX_POWER_LIMITED) |
| 1690 | sta->sta.txpwr.power = params->txpwr.power; |
| 1691 | ret = drv_sta_set_txpwr(local, sdata, sta); |
| 1692 | if (ret) |
| 1693 | return ret; |
| 1694 | } |
| 1695 | |
Johannes Berg | bd718fc | 2019-05-29 15:25:35 +0300 | [diff] [blame] | 1696 | if (params->supported_rates && params->supported_rates_len) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 1697 | ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef, |
| 1698 | sband, params->supported_rates, |
| 1699 | params->supported_rates_len, |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 1700 | &sta->sta.supp_rates[sband->band]); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1701 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1702 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 1703 | if (params->ht_capa) |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 1704 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 1705 | params->ht_capa, sta); |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 1706 | |
Emmanuel Grumbach | 506bcfa | 2015-12-13 15:41:05 +0200 | [diff] [blame] | 1707 | /* VHT can override some HT caps such as the A-MSDU max length */ |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 1708 | if (params->vht_capa) |
| 1709 | ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, |
Johannes Berg | 4a34215 | 2013-02-07 11:58:58 +0100 | [diff] [blame] | 1710 | params->vht_capa, sta); |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 1711 | |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 1712 | if (params->he_capa) |
| 1713 | ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband, |
| 1714 | (void *)params->he_capa, |
Johannes Berg | 1bb9a8a | 2020-05-28 21:34:38 +0200 | [diff] [blame] | 1715 | params->he_capa_len, |
| 1716 | (void *)params->he_6ghz_capa, |
| 1717 | sta); |
Luca Coelho | 41cbb0f | 2018-06-09 09:14:44 +0300 | [diff] [blame] | 1718 | |
Marek Kwaczynski | b1bce14a | 2014-02-03 14:44:44 +0100 | [diff] [blame] | 1719 | if (params->opmode_notif_used) { |
Marek Kwaczynski | b1bce14a | 2014-02-03 14:44:44 +0100 | [diff] [blame] | 1720 | /* returned value is only needed for rc update, but the |
| 1721 | * rc isn't initialized here yet, so ignore it |
| 1722 | */ |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 1723 | __ieee80211_vht_handle_opmode(sdata, sta, params->opmode_notif, |
| 1724 | sband->band); |
Marek Kwaczynski | b1bce14a | 2014-02-03 14:44:44 +0100 | [diff] [blame] | 1725 | } |
| 1726 | |
Ayala Beker | 52cfa1d | 2016-03-17 15:41:39 +0200 | [diff] [blame] | 1727 | if (params->support_p2p_ps >= 0) |
| 1728 | sta->sta.support_p2p_ps = params->support_p2p_ps; |
| 1729 | |
Johannes Berg | 1365770 | 2015-06-17 10:34:54 +0200 | [diff] [blame] | 1730 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 1731 | sta_apply_mesh_params(local, sta, params); |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1732 | |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 1733 | if (params->airtime_weight) |
Toke Høiland-Jørgensen | 2433647 | 2021-06-23 15:47:55 +0200 | [diff] [blame] | 1734 | sta_apply_airtime_params(local, sta, params); |
| 1735 | |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 1736 | |
Arik Nemtsov | 68885a5 | 2014-06-11 17:18:19 +0300 | [diff] [blame] | 1737 | /* set the STA state after all sta info from usermode has been set */ |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1738 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) || |
| 1739 | set & BIT(NL80211_STA_FLAG_ASSOCIATED)) { |
Arik Nemtsov | 68885a5 | 2014-06-11 17:18:19 +0300 | [diff] [blame] | 1740 | ret = sta_apply_auth_flags(local, sta, mask, set); |
| 1741 | if (ret) |
| 1742 | return ret; |
| 1743 | } |
| 1744 | |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1745 | return 0; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 1749 | const u8 *mac, |
| 1750 | struct station_parameters *params) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1751 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1752 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1753 | struct sta_info *sta; |
| 1754 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1755 | int err; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1756 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1757 | if (params->vlan) { |
| 1758 | sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
| 1759 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1760 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 1761 | sdata->vif.type != NL80211_IFTYPE_AP) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1762 | return -EINVAL; |
| 1763 | } else |
| 1764 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1765 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 1766 | if (ether_addr_equal(mac, sdata->vif.addr)) |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 1767 | return -EINVAL; |
| 1768 | |
Karthikeyan Periyasamy | 52dba8d | 2019-07-24 14:46:10 +0530 | [diff] [blame] | 1769 | if (!is_valid_ether_addr(mac)) |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 1770 | return -EINVAL; |
| 1771 | |
Johannes Berg | 5fd2f91a | 2019-08-01 09:30:33 +0200 | [diff] [blame] | 1772 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) && |
| 1773 | sdata->vif.type == NL80211_IFTYPE_STATION && |
| 1774 | !sdata->u.mgd.associated) |
| 1775 | return -EINVAL; |
| 1776 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 1777 | sta = sta_info_alloc(sdata, mac, GFP_KERNEL); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1778 | if (!sta) |
| 1779 | return -ENOMEM; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1780 | |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1781 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 1782 | sta->sta.tdls = true; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1783 | |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1784 | err = sta_apply_parameters(local, sta, params); |
| 1785 | if (err) { |
| 1786 | sta_info_free(local, sta); |
| 1787 | return err; |
| 1788 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1789 | |
Arik Nemtsov | d64cf63 | 2011-11-07 23:24:39 +0200 | [diff] [blame] | 1790 | /* |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1791 | * for TDLS and for unassociated station, rate control should be |
| 1792 | * initialized only when rates are known and station is marked |
| 1793 | * authorized/associated |
Arik Nemtsov | d64cf63 | 2011-11-07 23:24:39 +0200 | [diff] [blame] | 1794 | */ |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1795 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
| 1796 | test_sta_flag(sta, WLAN_STA_ASSOC)) |
Arik Nemtsov | d64cf63 | 2011-11-07 23:24:39 +0200 | [diff] [blame] | 1797 | rate_control_rate_init(sta); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1798 | |
Johannes Berg | 4ebdce1 | 2021-05-17 23:07:57 +0200 | [diff] [blame] | 1799 | return sta_info_insert(sta); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 1803 | struct station_del_parameters *params) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1804 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1805 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1806 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1807 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1808 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 1809 | if (params->mac) |
| 1810 | return sta_info_destroy_addr_bss(sdata, params->mac); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 1811 | |
Johannes Berg | b998e8b | 2012-12-13 23:07:46 +0100 | [diff] [blame] | 1812 | sta_info_flush(sdata); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1813 | return 0; |
| 1814 | } |
| 1815 | |
| 1816 | static int ieee80211_change_station(struct wiphy *wiphy, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 1817 | struct net_device *dev, const u8 *mac, |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1818 | struct station_parameters *params) |
| 1819 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 1820 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1821 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1822 | struct sta_info *sta; |
| 1823 | struct ieee80211_sub_if_data *vlansdata; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1824 | enum cfg80211_station_type statype; |
Eliad Peller | 35b8862 | 2011-12-29 14:41:39 +0200 | [diff] [blame] | 1825 | int err; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1826 | |
Johannes Berg | 87be1e1 | 2011-12-14 12:20:29 +0100 | [diff] [blame] | 1827 | mutex_lock(&local->sta_mtx); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 1828 | |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 1829 | sta = sta_info_get_bss(sdata, mac); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 1830 | if (!sta) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1831 | err = -ENOENT; |
| 1832 | goto out_err; |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 1833 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1834 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1835 | switch (sdata->vif.type) { |
| 1836 | case NL80211_IFTYPE_MESH_POINT: |
Thomas Pedersen | a6dad6a | 2013-03-04 13:06:12 -0800 | [diff] [blame] | 1837 | if (sdata->u.mesh.user_mpm) |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 1838 | statype = CFG80211_STA_MESH_PEER_USER; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1839 | else |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 1840 | statype = CFG80211_STA_MESH_PEER_KERNEL; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1841 | break; |
| 1842 | case NL80211_IFTYPE_ADHOC: |
| 1843 | statype = CFG80211_STA_IBSS; |
| 1844 | break; |
| 1845 | case NL80211_IFTYPE_STATION: |
| 1846 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { |
| 1847 | statype = CFG80211_STA_AP_STA; |
| 1848 | break; |
| 1849 | } |
| 1850 | if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
| 1851 | statype = CFG80211_STA_TDLS_PEER_ACTIVE; |
| 1852 | else |
| 1853 | statype = CFG80211_STA_TDLS_PEER_SETUP; |
| 1854 | break; |
| 1855 | case NL80211_IFTYPE_AP: |
| 1856 | case NL80211_IFTYPE_AP_VLAN: |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1857 | if (test_sta_flag(sta, WLAN_STA_ASSOC)) |
| 1858 | statype = CFG80211_STA_AP_CLIENT; |
| 1859 | else |
| 1860 | statype = CFG80211_STA_AP_CLIENT_UNASSOC; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1861 | break; |
| 1862 | default: |
| 1863 | err = -EOPNOTSUPP; |
| 1864 | goto out_err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 1865 | } |
| 1866 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1867 | err = cfg80211_check_station_change(wiphy, params, statype); |
| 1868 | if (err) |
| 1869 | goto out_err; |
| 1870 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1871 | if (params->vlan && params->vlan != sta->sdata->dev) { |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1872 | vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
| 1873 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1874 | if (params->vlan->ieee80211_ptr->use_4addr) { |
Johannes Berg | 3305443 | 2009-11-20 10:09:14 +0100 | [diff] [blame] | 1875 | if (vlansdata->u.vlan.sta) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1876 | err = -EBUSY; |
| 1877 | goto out_err; |
Johannes Berg | 3305443 | 2009-11-20 10:09:14 +0100 | [diff] [blame] | 1878 | } |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 1879 | |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 1880 | rcu_assign_pointer(vlansdata->u.vlan.sta, sta); |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 1881 | __ieee80211_check_fast_rx_iface(vlansdata); |
Felix Fietkau | 1ff4e8f | 2020-09-08 14:37:01 +0200 | [diff] [blame] | 1882 | drv_sta_set_4addr(local, sta->sdata, &sta->sta, true); |
Felix Fietkau | 7e3ed02 | 2012-04-23 19:49:03 +0200 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && |
Seevalamuthu Mariappan | dd0b455 | 2021-03-19 19:48:52 +0530 | [diff] [blame] | 1886 | sta->sdata->u.vlan.sta) { |
| 1887 | ieee80211_clear_fast_rx(sta); |
Monam Agarwal | 0c2bef46 | 2014-03-24 00:51:43 +0530 | [diff] [blame] | 1888 | RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL); |
Seevalamuthu Mariappan | dd0b455 | 2021-03-19 19:48:52 +0530 | [diff] [blame] | 1889 | } |
Michael Braun | 72f15d5 | 2016-10-10 19:12:21 +0200 | [diff] [blame] | 1890 | |
| 1891 | if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
| 1892 | ieee80211_vif_dec_num_mcast(sta->sdata); |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 1893 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1894 | sta->sdata = vlansdata; |
Michal Kazior | 464daaf | 2015-05-19 14:13:36 +0200 | [diff] [blame] | 1895 | ieee80211_check_fast_xmit(sta); |
Felix Fietkau | 7e3ed02 | 2012-04-23 19:49:03 +0200 | [diff] [blame] | 1896 | |
Jouni Malinen | 3e49317 | 2019-09-11 16:03:05 +0300 | [diff] [blame] | 1897 | if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) { |
Michael Braun | 72f15d5 | 2016-10-10 19:12:21 +0200 | [diff] [blame] | 1898 | ieee80211_vif_inc_num_mcast(sta->sdata); |
Jouni Malinen | 3e49317 | 2019-09-11 16:03:05 +0300 | [diff] [blame] | 1899 | cfg80211_send_layer2_update(sta->sdata->dev, |
| 1900 | sta->sta.addr); |
| 1901 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1902 | } |
| 1903 | |
Eliad Peller | 35b8862 | 2011-12-29 14:41:39 +0200 | [diff] [blame] | 1904 | err = sta_apply_parameters(local, sta, params); |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1905 | if (err) |
| 1906 | goto out_err; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1907 | |
Johannes Berg | 87be1e1 | 2011-12-14 12:20:29 +0100 | [diff] [blame] | 1908 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 1909 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1910 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1911 | params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1912 | ieee80211_recalc_ps(local); |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1913 | ieee80211_recalc_ps_vif(sdata); |
| 1914 | } |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1915 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1916 | return 0; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1917 | out_err: |
| 1918 | mutex_unlock(&local->sta_mtx); |
| 1919 | return err; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1920 | } |
| 1921 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1922 | #ifdef CONFIG_MAC80211_MESH |
| 1923 | static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 1924 | const u8 *dst, const u8 *next_hop) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1925 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1926 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1927 | struct mesh_path *mpath; |
| 1928 | struct sta_info *sta; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1929 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1930 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1931 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1932 | rcu_read_lock(); |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 1933 | sta = sta_info_get(sdata, next_hop); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1934 | if (!sta) { |
| 1935 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1936 | return -ENOENT; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1937 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1938 | |
Bob Copeland | ae76eef | 2013-03-29 09:38:39 -0400 | [diff] [blame] | 1939 | mpath = mesh_path_add(sdata, dst); |
| 1940 | if (IS_ERR(mpath)) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1941 | rcu_read_unlock(); |
Bob Copeland | ae76eef | 2013-03-29 09:38:39 -0400 | [diff] [blame] | 1942 | return PTR_ERR(mpath); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1943 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1944 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1945 | mesh_path_fix_nexthop(mpath, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1946 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1947 | rcu_read_unlock(); |
| 1948 | return 0; |
| 1949 | } |
| 1950 | |
| 1951 | static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 1952 | const u8 *dst) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1953 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1954 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1955 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1956 | if (dst) |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 1957 | return mesh_path_del(sdata, dst); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1958 | |
Javier Cardona | ece1a2e | 2011-08-29 13:23:04 -0700 | [diff] [blame] | 1959 | mesh_path_flush_by_iface(sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1960 | return 0; |
| 1961 | } |
| 1962 | |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 1963 | static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 1964 | const u8 *dst, const u8 *next_hop) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1965 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1966 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1967 | struct mesh_path *mpath; |
| 1968 | struct sta_info *sta; |
| 1969 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1970 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1971 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1972 | rcu_read_lock(); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1973 | |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 1974 | sta = sta_info_get(sdata, next_hop); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1975 | if (!sta) { |
| 1976 | rcu_read_unlock(); |
| 1977 | return -ENOENT; |
| 1978 | } |
| 1979 | |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 1980 | mpath = mesh_path_lookup(sdata, dst); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1981 | if (!mpath) { |
| 1982 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1983 | return -ENOENT; |
| 1984 | } |
| 1985 | |
| 1986 | mesh_path_fix_nexthop(mpath, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1987 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1988 | rcu_read_unlock(); |
| 1989 | return 0; |
| 1990 | } |
| 1991 | |
| 1992 | static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop, |
| 1993 | struct mpath_info *pinfo) |
| 1994 | { |
Johannes Berg | a3836e0 | 2011-05-12 15:11:37 +0200 | [diff] [blame] | 1995 | struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop); |
| 1996 | |
| 1997 | if (next_hop_sta) |
| 1998 | memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1999 | else |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 2000 | eth_zero_addr(next_hop); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2001 | |
LEO Airwarosu Yoichi Shinoda | 7ce8c7a | 2012-08-27 22:28:16 +0900 | [diff] [blame] | 2002 | memset(pinfo, 0, sizeof(*pinfo)); |
| 2003 | |
Bob Copeland | 2bdaf38 | 2016-02-28 20:03:56 -0500 | [diff] [blame] | 2004 | pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2005 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2006 | pinfo->filled = MPATH_INFO_FRAME_QLEN | |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2007 | MPATH_INFO_SN | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2008 | MPATH_INFO_METRIC | |
| 2009 | MPATH_INFO_EXPTIME | |
| 2010 | MPATH_INFO_DISCOVERY_TIMEOUT | |
| 2011 | MPATH_INFO_DISCOVERY_RETRIES | |
Julan Hsu | cc24163 | 2019-01-15 15:28:42 -0800 | [diff] [blame] | 2012 | MPATH_INFO_FLAGS | |
Julan Hsu | 540bbcb | 2019-01-15 15:28:43 -0800 | [diff] [blame] | 2013 | MPATH_INFO_HOP_COUNT | |
| 2014 | MPATH_INFO_PATH_CHANGE; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2015 | |
| 2016 | pinfo->frame_qlen = mpath->frame_queue.qlen; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2017 | pinfo->sn = mpath->sn; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2018 | pinfo->metric = mpath->metric; |
| 2019 | if (time_before(jiffies, mpath->exp_time)) |
| 2020 | pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); |
| 2021 | pinfo->discovery_timeout = |
| 2022 | jiffies_to_msecs(mpath->discovery_timeout); |
| 2023 | pinfo->discovery_retries = mpath->discovery_retries; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2024 | if (mpath->flags & MESH_PATH_ACTIVE) |
| 2025 | pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; |
| 2026 | if (mpath->flags & MESH_PATH_RESOLVING) |
| 2027 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2028 | if (mpath->flags & MESH_PATH_SN_VALID) |
| 2029 | pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2030 | if (mpath->flags & MESH_PATH_FIXED) |
| 2031 | pinfo->flags |= NL80211_MPATH_FLAG_FIXED; |
LEO Airwarosu Yoichi Shinoda | 7ce8c7a | 2012-08-27 22:28:16 +0900 | [diff] [blame] | 2032 | if (mpath->flags & MESH_PATH_RESOLVED) |
| 2033 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED; |
Julan Hsu | cc24163 | 2019-01-15 15:28:42 -0800 | [diff] [blame] | 2034 | pinfo->hop_count = mpath->hop_count; |
Julan Hsu | 540bbcb | 2019-01-15 15:28:43 -0800 | [diff] [blame] | 2035 | pinfo->path_change_count = mpath->path_change_count; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 2039 | u8 *dst, u8 *next_hop, struct mpath_info *pinfo) |
| 2040 | |
| 2041 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 2042 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2043 | struct mesh_path *mpath; |
| 2044 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 2045 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2046 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2047 | rcu_read_lock(); |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 2048 | mpath = mesh_path_lookup(sdata, dst); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2049 | if (!mpath) { |
| 2050 | rcu_read_unlock(); |
| 2051 | return -ENOENT; |
| 2052 | } |
| 2053 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 2054 | mpath_set_pinfo(mpath, next_hop, pinfo); |
| 2055 | rcu_read_unlock(); |
| 2056 | return 0; |
| 2057 | } |
| 2058 | |
| 2059 | static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 2060 | int idx, u8 *dst, u8 *next_hop, |
| 2061 | struct mpath_info *pinfo) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2062 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 2063 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2064 | struct mesh_path *mpath; |
| 2065 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 2066 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2067 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2068 | rcu_read_lock(); |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 2069 | mpath = mesh_path_lookup_by_idx(sdata, idx); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2070 | if (!mpath) { |
| 2071 | rcu_read_unlock(); |
| 2072 | return -ENOENT; |
| 2073 | } |
| 2074 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 2075 | mpath_set_pinfo(mpath, next_hop, pinfo); |
| 2076 | rcu_read_unlock(); |
| 2077 | return 0; |
| 2078 | } |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2079 | |
Henning Rogge | a2db2ed | 2014-09-12 08:58:50 +0200 | [diff] [blame] | 2080 | static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp, |
| 2081 | struct mpath_info *pinfo) |
| 2082 | { |
| 2083 | memset(pinfo, 0, sizeof(*pinfo)); |
| 2084 | memcpy(mpp, mpath->mpp, ETH_ALEN); |
| 2085 | |
Bob Copeland | 2bdaf38 | 2016-02-28 20:03:56 -0500 | [diff] [blame] | 2086 | pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation; |
Henning Rogge | a2db2ed | 2014-09-12 08:58:50 +0200 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev, |
| 2090 | u8 *dst, u8 *mpp, struct mpath_info *pinfo) |
| 2091 | |
| 2092 | { |
| 2093 | struct ieee80211_sub_if_data *sdata; |
| 2094 | struct mesh_path *mpath; |
| 2095 | |
| 2096 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2097 | |
| 2098 | rcu_read_lock(); |
| 2099 | mpath = mpp_path_lookup(sdata, dst); |
| 2100 | if (!mpath) { |
| 2101 | rcu_read_unlock(); |
| 2102 | return -ENOENT; |
| 2103 | } |
| 2104 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 2105 | mpp_set_pinfo(mpath, mpp, pinfo); |
| 2106 | rcu_read_unlock(); |
| 2107 | return 0; |
| 2108 | } |
| 2109 | |
| 2110 | static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev, |
| 2111 | int idx, u8 *dst, u8 *mpp, |
| 2112 | struct mpath_info *pinfo) |
| 2113 | { |
| 2114 | struct ieee80211_sub_if_data *sdata; |
| 2115 | struct mesh_path *mpath; |
| 2116 | |
| 2117 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2118 | |
| 2119 | rcu_read_lock(); |
| 2120 | mpath = mpp_path_lookup_by_idx(sdata, idx); |
| 2121 | if (!mpath) { |
| 2122 | rcu_read_unlock(); |
| 2123 | return -ENOENT; |
| 2124 | } |
| 2125 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 2126 | mpp_set_pinfo(mpath, mpp, pinfo); |
| 2127 | rcu_read_unlock(); |
| 2128 | return 0; |
| 2129 | } |
| 2130 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2131 | static int ieee80211_get_mesh_config(struct wiphy *wiphy, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2132 | struct net_device *dev, |
| 2133 | struct mesh_config *conf) |
| 2134 | { |
| 2135 | struct ieee80211_sub_if_data *sdata; |
| 2136 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2137 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2138 | memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config)); |
| 2139 | return 0; |
| 2140 | } |
| 2141 | |
| 2142 | static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask) |
| 2143 | { |
| 2144 | return (mask >> (parm-1)) & 0x1; |
| 2145 | } |
| 2146 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2147 | static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh, |
| 2148 | const struct mesh_setup *setup) |
| 2149 | { |
| 2150 | u8 *new_ie; |
| 2151 | const u8 *old_ie; |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 2152 | struct ieee80211_sub_if_data *sdata = container_of(ifmsh, |
| 2153 | struct ieee80211_sub_if_data, u.mesh); |
Jouni Malinen | 08fad43 | 2020-04-25 18:57:12 +0300 | [diff] [blame] | 2154 | int i; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2155 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2156 | /* allocate information elements */ |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2157 | new_ie = NULL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2158 | old_ie = ifmsh->ie; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2159 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2160 | if (setup->ie_len) { |
| 2161 | new_ie = kmemdup(setup->ie, setup->ie_len, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2162 | GFP_KERNEL); |
| 2163 | if (!new_ie) |
| 2164 | return -ENOMEM; |
| 2165 | } |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 2166 | ifmsh->ie_len = setup->ie_len; |
| 2167 | ifmsh->ie = new_ie; |
| 2168 | kfree(old_ie); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2169 | |
| 2170 | /* now copy the rest of the setup parameters */ |
| 2171 | ifmsh->mesh_id_len = setup->mesh_id_len; |
| 2172 | memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len); |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 2173 | ifmsh->mesh_sp_id = setup->sync_method; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2174 | ifmsh->mesh_pp_id = setup->path_sel_proto; |
| 2175 | ifmsh->mesh_pm_id = setup->path_metric; |
Thomas Pedersen | a6dad6a | 2013-03-04 13:06:12 -0800 | [diff] [blame] | 2176 | ifmsh->user_mpm = setup->user_mpm; |
Colleen Twitty | 0d4261a | 2013-05-08 11:46:00 -0700 | [diff] [blame] | 2177 | ifmsh->mesh_auth_id = setup->auth_id; |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 2178 | ifmsh->security = IEEE80211_MESH_SEC_NONE; |
Benjamin Berg | 0ab2e55 | 2017-05-16 11:23:13 +0200 | [diff] [blame] | 2179 | ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs; |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 2180 | if (setup->is_authenticated) |
| 2181 | ifmsh->security |= IEEE80211_MESH_SEC_AUTHED; |
| 2182 | if (setup->is_secure) |
| 2183 | ifmsh->security |= IEEE80211_MESH_SEC_SECURED; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2184 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 2185 | /* mcast rate setting in Mesh Node */ |
| 2186 | memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate, |
| 2187 | sizeof(setup->mcast_rate)); |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 2188 | sdata->vif.bss_conf.basic_rates = setup->basic_rates; |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 2189 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 2190 | sdata->vif.bss_conf.beacon_int = setup->beacon_interval; |
| 2191 | sdata->vif.bss_conf.dtim_period = setup->dtim_period; |
| 2192 | |
Jouni Malinen | 08fad43 | 2020-04-25 18:57:12 +0300 | [diff] [blame] | 2193 | sdata->beacon_rate_set = false; |
| 2194 | if (wiphy_ext_feature_isset(sdata->local->hw.wiphy, |
| 2195 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) { |
| 2196 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 2197 | sdata->beacon_rateidx_mask[i] = |
| 2198 | setup->beacon_rate.control[i].legacy; |
| 2199 | if (sdata->beacon_rateidx_mask[i]) |
| 2200 | sdata->beacon_rate_set = true; |
| 2201 | } |
| 2202 | } |
| 2203 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2204 | return 0; |
| 2205 | } |
| 2206 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 2207 | static int ieee80211_update_mesh_config(struct wiphy *wiphy, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2208 | struct net_device *dev, u32 mask, |
| 2209 | const struct mesh_config *nconf) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2210 | { |
| 2211 | struct mesh_config *conf; |
| 2212 | struct ieee80211_sub_if_data *sdata; |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2213 | struct ieee80211_if_mesh *ifmsh; |
| 2214 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2215 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2216 | ifmsh = &sdata->u.mesh; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2217 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2218 | /* Set the config options which we are interested in setting */ |
| 2219 | conf = &(sdata->u.mesh.mshcfg); |
| 2220 | if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask)) |
| 2221 | conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout; |
| 2222 | if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask)) |
| 2223 | conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout; |
| 2224 | if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask)) |
| 2225 | conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout; |
| 2226 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask)) |
| 2227 | conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks; |
| 2228 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask)) |
| 2229 | conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries; |
| 2230 | if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask)) |
| 2231 | conf->dot11MeshTTL = nconf->dot11MeshTTL; |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 2232 | if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask)) |
Chun-Yeow Yeoh | 58886a9 | 2012-06-15 00:23:53 +0800 | [diff] [blame] | 2233 | conf->element_ttl = nconf->element_ttl; |
Thomas Pedersen | 146bb48 | 2013-03-04 13:06:14 -0800 | [diff] [blame] | 2234 | if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) { |
| 2235 | if (ifmsh->user_mpm) |
| 2236 | return -EBUSY; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2237 | conf->auto_open_plinks = nconf->auto_open_plinks; |
Thomas Pedersen | 146bb48 | 2013-03-04 13:06:14 -0800 | [diff] [blame] | 2238 | } |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 2239 | if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask)) |
| 2240 | conf->dot11MeshNbrOffsetMaxNeighbor = |
| 2241 | nconf->dot11MeshNbrOffsetMaxNeighbor; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2242 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask)) |
| 2243 | conf->dot11MeshHWMPmaxPREQretries = |
| 2244 | nconf->dot11MeshHWMPmaxPREQretries; |
| 2245 | if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask)) |
| 2246 | conf->path_refresh_time = nconf->path_refresh_time; |
| 2247 | if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask)) |
| 2248 | conf->min_discovery_timeout = nconf->min_discovery_timeout; |
| 2249 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask)) |
| 2250 | conf->dot11MeshHWMPactivePathTimeout = |
| 2251 | nconf->dot11MeshHWMPactivePathTimeout; |
| 2252 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask)) |
| 2253 | conf->dot11MeshHWMPpreqMinInterval = |
| 2254 | nconf->dot11MeshHWMPpreqMinInterval; |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 2255 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask)) |
| 2256 | conf->dot11MeshHWMPperrMinInterval = |
| 2257 | nconf->dot11MeshHWMPperrMinInterval; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2258 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2259 | mask)) |
| 2260 | conf->dot11MeshHWMPnetDiameterTraversalTime = |
| 2261 | nconf->dot11MeshHWMPnetDiameterTraversalTime; |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2262 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) { |
| 2263 | conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode; |
| 2264 | ieee80211_mesh_root_setup(ifmsh); |
| 2265 | } |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 2266 | if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) { |
Thomas Pedersen | c6133661 | 2011-08-25 10:36:14 -0700 | [diff] [blame] | 2267 | /* our current gate announcement implementation rides on root |
| 2268 | * announcements, so require this ifmsh to also be a root node |
| 2269 | * */ |
| 2270 | if (nconf->dot11MeshGateAnnouncementProtocol && |
Chun-Yeow Yeoh | dbb912c | 2012-06-14 02:06:09 +0800 | [diff] [blame] | 2271 | !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) { |
| 2272 | conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN; |
Thomas Pedersen | c6133661 | 2011-08-25 10:36:14 -0700 | [diff] [blame] | 2273 | ieee80211_mesh_root_setup(ifmsh); |
| 2274 | } |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 2275 | conf->dot11MeshGateAnnouncementProtocol = |
| 2276 | nconf->dot11MeshGateAnnouncementProtocol; |
| 2277 | } |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 2278 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 2279 | conf->dot11MeshHWMPRannInterval = |
| 2280 | nconf->dot11MeshHWMPRannInterval; |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 2281 | if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask)) |
| 2282 | conf->dot11MeshForwarding = nconf->dot11MeshForwarding; |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 2283 | if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) { |
| 2284 | /* our RSSI threshold implementation is supported only for |
| 2285 | * devices that report signal in dBm. |
| 2286 | */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2287 | if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM)) |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 2288 | return -ENOTSUPP; |
| 2289 | conf->rssi_threshold = nconf->rssi_threshold; |
| 2290 | } |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 2291 | if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) { |
| 2292 | conf->ht_opmode = nconf->ht_opmode; |
| 2293 | sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode; |
| 2294 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT); |
| 2295 | } |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 2296 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask)) |
| 2297 | conf->dot11MeshHWMPactivePathToRootTimeout = |
| 2298 | nconf->dot11MeshHWMPactivePathToRootTimeout; |
| 2299 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask)) |
| 2300 | conf->dot11MeshHWMProotInterval = |
| 2301 | nconf->dot11MeshHWMProotInterval; |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 2302 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask)) |
| 2303 | conf->dot11MeshHWMPconfirmationInterval = |
| 2304 | nconf->dot11MeshHWMPconfirmationInterval; |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 2305 | if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) { |
| 2306 | conf->power_mode = nconf->power_mode; |
| 2307 | ieee80211_mps_local_status_update(sdata); |
| 2308 | } |
Thomas Pedersen | 2b5e196 | 2013-02-14 11:20:13 -0800 | [diff] [blame] | 2309 | if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask)) |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 2310 | conf->dot11MeshAwakeWindowDuration = |
| 2311 | nconf->dot11MeshAwakeWindowDuration; |
Colleen Twitty | 66de671 | 2013-06-03 09:53:40 -0700 | [diff] [blame] | 2312 | if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask)) |
| 2313 | conf->plink_timeout = nconf->plink_timeout; |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 2314 | if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask)) |
| 2315 | conf->dot11MeshConnectedToMeshGate = |
| 2316 | nconf->dot11MeshConnectedToMeshGate; |
Linus Lüssing | e3718a6 | 2020-06-17 09:30:33 +0200 | [diff] [blame] | 2317 | if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask)) |
| 2318 | conf->dot11MeshNolearn = nconf->dot11MeshNolearn; |
Markus Theil | 184eebe | 2020-06-11 16:02:37 +0200 | [diff] [blame] | 2319 | if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask)) |
| 2320 | conf->dot11MeshConnectedToAuthServer = |
| 2321 | nconf->dot11MeshConnectedToAuthServer; |
Thomas Pedersen | 2b5e196 | 2013-02-14 11:20:13 -0800 | [diff] [blame] | 2322 | ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2323 | return 0; |
| 2324 | } |
| 2325 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2326 | static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev, |
| 2327 | const struct mesh_config *conf, |
| 2328 | const struct mesh_setup *setup) |
| 2329 | { |
| 2330 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2331 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2332 | int err; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2333 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2334 | memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config)); |
| 2335 | err = copy_mesh_setup(ifmsh, setup); |
| 2336 | if (err) |
| 2337 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2338 | |
Denis Kenzior | 018f6fb | 2018-03-26 12:52:51 -0500 | [diff] [blame] | 2339 | sdata->control_port_over_nl80211 = setup->control_port_over_nl80211; |
| 2340 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 2341 | /* can mesh use other SMPS modes? */ |
| 2342 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
| 2343 | sdata->needed_rx_chains = sdata->local->rx_chains; |
| 2344 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2345 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 2346 | err = ieee80211_vif_use_channel(sdata, &setup->chandef, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2347 | IEEE80211_CHANCTX_SHARED); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2348 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2349 | if (err) |
| 2350 | return err; |
| 2351 | |
Thomas Pedersen | 2b5e196 | 2013-02-14 11:20:13 -0800 | [diff] [blame] | 2352 | return ieee80211_start_mesh(sdata); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev) |
| 2356 | { |
| 2357 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2358 | |
| 2359 | ieee80211_stop_mesh(sdata); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2360 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2361 | ieee80211_vif_release_channel(sdata); |
Remi Pommarel | 6a01afc | 2020-07-04 15:50:07 +0200 | [diff] [blame] | 2362 | kfree(sdata->u.mesh.ie); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2363 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2364 | |
| 2365 | return 0; |
| 2366 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2367 | #endif |
| 2368 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2369 | static int ieee80211_change_bss(struct wiphy *wiphy, |
| 2370 | struct net_device *dev, |
| 2371 | struct bss_parameters *params) |
| 2372 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2373 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2374 | struct ieee80211_supported_band *sband; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2375 | u32 changed = 0; |
| 2376 | |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 2377 | if (!sdata_dereference(sdata->u.ap.beacon, sdata)) |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2378 | return -ENOENT; |
| 2379 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2380 | sband = ieee80211_get_sband(sdata); |
| 2381 | if (!sband) |
| 2382 | return -EINVAL; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2383 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2384 | if (params->use_cts_prot >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 2385 | sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2386 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
| 2387 | } |
| 2388 | if (params->use_short_preamble >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 2389 | sdata->vif.bss_conf.use_short_preamble = |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2390 | params->use_short_preamble; |
| 2391 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
| 2392 | } |
Felix Fietkau | 43d3534 | 2010-01-15 03:00:48 +0100 | [diff] [blame] | 2393 | |
| 2394 | if (!sdata->vif.bss_conf.use_short_slot && |
Tova Mussai | 07c12d6 | 2020-05-28 21:34:46 +0200 | [diff] [blame] | 2395 | (sband->band == NL80211_BAND_5GHZ || |
| 2396 | sband->band == NL80211_BAND_6GHZ)) { |
Felix Fietkau | 43d3534 | 2010-01-15 03:00:48 +0100 | [diff] [blame] | 2397 | sdata->vif.bss_conf.use_short_slot = true; |
| 2398 | changed |= BSS_CHANGED_ERP_SLOT; |
| 2399 | } |
| 2400 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2401 | if (params->use_short_slot_time >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 2402 | sdata->vif.bss_conf.use_short_slot = |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2403 | params->use_short_slot_time; |
| 2404 | changed |= BSS_CHANGED_ERP_SLOT; |
| 2405 | } |
| 2406 | |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2407 | if (params->basic_rates) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 2408 | ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef, |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2409 | wiphy->bands[sband->band], |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 2410 | params->basic_rates, |
| 2411 | params->basic_rates_len, |
| 2412 | &sdata->vif.bss_conf.basic_rates); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2413 | changed |= BSS_CHANGED_BASIC_RATES; |
Johannes Berg | e8e4f52 | 2017-03-08 11:12:10 +0100 | [diff] [blame] | 2414 | ieee80211_check_rate_mask(sdata); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2415 | } |
| 2416 | |
Felix Fietkau | 7b7b5e5 | 2010-04-27 01:23:36 +0200 | [diff] [blame] | 2417 | if (params->ap_isolate >= 0) { |
| 2418 | if (params->ap_isolate) |
| 2419 | sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS; |
| 2420 | else |
| 2421 | sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS; |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 2422 | ieee80211_check_fast_rx_iface(sdata); |
Felix Fietkau | 7b7b5e5 | 2010-04-27 01:23:36 +0200 | [diff] [blame] | 2423 | } |
| 2424 | |
Helmut Schaa | 80d7e40 | 2010-11-19 12:40:26 +0100 | [diff] [blame] | 2425 | if (params->ht_opmode >= 0) { |
| 2426 | sdata->vif.bss_conf.ht_operation_mode = |
| 2427 | (u16) params->ht_opmode; |
| 2428 | changed |= BSS_CHANGED_HT; |
| 2429 | } |
| 2430 | |
Johannes Berg | 339afbf | 2012-11-14 15:21:17 +0100 | [diff] [blame] | 2431 | if (params->p2p_ctwindow >= 0) { |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2432 | sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &= |
| 2433 | ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK; |
| 2434 | sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |= |
| 2435 | params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK; |
Johannes Berg | 339afbf | 2012-11-14 15:21:17 +0100 | [diff] [blame] | 2436 | changed |= BSS_CHANGED_P2P_PS; |
| 2437 | } |
| 2438 | |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2439 | if (params->p2p_opp_ps > 0) { |
| 2440 | sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |= |
| 2441 | IEEE80211_P2P_OPPPS_ENABLE_BIT; |
| 2442 | changed |= BSS_CHANGED_P2P_PS; |
| 2443 | } else if (params->p2p_opp_ps == 0) { |
| 2444 | sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &= |
| 2445 | ~IEEE80211_P2P_OPPPS_ENABLE_BIT; |
Johannes Berg | 339afbf | 2012-11-14 15:21:17 +0100 | [diff] [blame] | 2446 | changed |= BSS_CHANGED_P2P_PS; |
| 2447 | } |
| 2448 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2449 | ieee80211_bss_info_change_notify(sdata, changed); |
| 2450 | |
| 2451 | return 0; |
| 2452 | } |
| 2453 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2454 | static int ieee80211_set_txq_params(struct wiphy *wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2455 | struct net_device *dev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2456 | struct ieee80211_txq_params *params) |
| 2457 | { |
| 2458 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Eliad Peller | f6f3def | 2011-09-25 20:06:54 +0300 | [diff] [blame] | 2459 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2460 | struct ieee80211_tx_queue_params p; |
| 2461 | |
| 2462 | if (!local->ops->conf_tx) |
| 2463 | return -EOPNOTSUPP; |
| 2464 | |
Johannes Berg | 54bcbc6 | 2012-03-28 11:04:25 +0200 | [diff] [blame] | 2465 | if (local->hw.queues < IEEE80211_NUM_ACS) |
| 2466 | return -EOPNOTSUPP; |
| 2467 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2468 | memset(&p, 0, sizeof(p)); |
| 2469 | p.aifs = params->aifs; |
| 2470 | p.cw_max = params->cwmax; |
| 2471 | p.cw_min = params->cwmin; |
| 2472 | p.txop = params->txop; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2473 | |
| 2474 | /* |
| 2475 | * Setting tx queue params disables u-apsd because it's only |
| 2476 | * called in master mode. |
| 2477 | */ |
| 2478 | p.uapsd = false; |
| 2479 | |
Haim Dreyfuss | e552af0 | 2018-03-28 13:24:10 +0300 | [diff] [blame] | 2480 | ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac); |
| 2481 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2482 | sdata->tx_conf[params->ac] = p; |
| 2483 | if (drv_conf_tx(local, sdata, params->ac, &p)) { |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 2484 | wiphy_debug(local->hw.wiphy, |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2485 | "failed to set TX queue parameters for AC %d\n", |
| 2486 | params->ac); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2487 | return -EINVAL; |
| 2488 | } |
| 2489 | |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2490 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS); |
| 2491 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2492 | return 0; |
| 2493 | } |
| 2494 | |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 2495 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2496 | static int ieee80211_suspend(struct wiphy *wiphy, |
| 2497 | struct cfg80211_wowlan *wowlan) |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 2498 | { |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 2499 | return __ieee80211_suspend(wiphy_priv(wiphy), wowlan); |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 2500 | } |
| 2501 | |
| 2502 | static int ieee80211_resume(struct wiphy *wiphy) |
| 2503 | { |
| 2504 | return __ieee80211_resume(wiphy_priv(wiphy)); |
| 2505 | } |
| 2506 | #else |
| 2507 | #define ieee80211_suspend NULL |
| 2508 | #define ieee80211_resume NULL |
| 2509 | #endif |
| 2510 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2511 | static int ieee80211_scan(struct wiphy *wiphy, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2512 | struct cfg80211_scan_request *req) |
| 2513 | { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 2514 | struct ieee80211_sub_if_data *sdata; |
| 2515 | |
| 2516 | sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2517 | |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 2518 | switch (ieee80211_vif_type_p2p(&sdata->vif)) { |
| 2519 | case NL80211_IFTYPE_STATION: |
| 2520 | case NL80211_IFTYPE_ADHOC: |
| 2521 | case NL80211_IFTYPE_MESH_POINT: |
| 2522 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | f142c6b | 2012-06-18 20:07:15 +0200 | [diff] [blame] | 2523 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 2524 | break; |
| 2525 | case NL80211_IFTYPE_P2P_GO: |
| 2526 | if (sdata->local->ops->hw_scan) |
| 2527 | break; |
Johannes Berg | e9d7732 | 2011-02-01 15:35:36 +0100 | [diff] [blame] | 2528 | /* |
| 2529 | * FIXME: implement NoA while scanning in software, |
| 2530 | * for now fall through to allow scanning only when |
| 2531 | * beaconing hasn't been configured yet |
| 2532 | */ |
Gustavo A. R. Silva | fc0561d | 2020-07-07 15:45:48 -0500 | [diff] [blame] | 2533 | fallthrough; |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 2534 | case NL80211_IFTYPE_AP: |
Antonio Quartulli | 5c95b94 | 2012-10-16 08:39:22 +0200 | [diff] [blame] | 2535 | /* |
| 2536 | * If the scan has been forced (and the driver supports |
| 2537 | * forcing), don't care about being beaconing already. |
| 2538 | * This will create problems to the attached stations (e.g. all |
| 2539 | * the frames sent while scanning on other channel will be |
| 2540 | * lost) |
| 2541 | */ |
| 2542 | if (sdata->u.ap.beacon && |
| 2543 | (!(wiphy->features & NL80211_FEATURE_AP_SCAN) || |
| 2544 | !(req->flags & NL80211_SCAN_FLAG_AP))) |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 2545 | return -EOPNOTSUPP; |
| 2546 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2547 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 2548 | default: |
| 2549 | return -EOPNOTSUPP; |
| 2550 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2551 | |
| 2552 | return ieee80211_request_scan(sdata, req); |
| 2553 | } |
| 2554 | |
Vidyullatha Kanchanapally | 91f123f | 2015-10-30 19:14:50 +0530 | [diff] [blame] | 2555 | static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 2556 | { |
| 2557 | ieee80211_scan_cancel(wiphy_priv(wiphy)); |
| 2558 | } |
| 2559 | |
Luciano Coelho | 79f460c | 2011-05-11 17:09:36 +0300 | [diff] [blame] | 2560 | static int |
| 2561 | ieee80211_sched_scan_start(struct wiphy *wiphy, |
| 2562 | struct net_device *dev, |
| 2563 | struct cfg80211_sched_scan_request *req) |
| 2564 | { |
| 2565 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2566 | |
| 2567 | if (!sdata->local->ops->sched_scan_start) |
| 2568 | return -EOPNOTSUPP; |
| 2569 | |
| 2570 | return ieee80211_request_sched_scan_start(sdata, req); |
| 2571 | } |
| 2572 | |
| 2573 | static int |
Arend Van Spriel | 3a3ecf1 | 2017-04-21 13:05:02 +0100 | [diff] [blame] | 2574 | ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev, |
| 2575 | u64 reqid) |
Luciano Coelho | 79f460c | 2011-05-11 17:09:36 +0300 | [diff] [blame] | 2576 | { |
Eliad Peller | 0d440ea | 2015-10-25 10:59:33 +0200 | [diff] [blame] | 2577 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Luciano Coelho | 79f460c | 2011-05-11 17:09:36 +0300 | [diff] [blame] | 2578 | |
Eliad Peller | 0d440ea | 2015-10-25 10:59:33 +0200 | [diff] [blame] | 2579 | if (!local->ops->sched_scan_stop) |
Luciano Coelho | 79f460c | 2011-05-11 17:09:36 +0300 | [diff] [blame] | 2580 | return -EOPNOTSUPP; |
| 2581 | |
Eliad Peller | 0d440ea | 2015-10-25 10:59:33 +0200 | [diff] [blame] | 2582 | return ieee80211_request_sched_scan_stop(local); |
Luciano Coelho | 79f460c | 2011-05-11 17:09:36 +0300 | [diff] [blame] | 2583 | } |
| 2584 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2585 | static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev, |
| 2586 | struct cfg80211_auth_request *req) |
| 2587 | { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2588 | return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, |
| 2592 | struct cfg80211_assoc_request *req) |
| 2593 | { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2594 | return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 2598 | struct cfg80211_deauth_request *req) |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2599 | { |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 2600 | return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 2604 | struct cfg80211_disassoc_request *req) |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2605 | { |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 2606 | return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2607 | } |
| 2608 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 2609 | static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, |
| 2610 | struct cfg80211_ibss_params *params) |
| 2611 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2612 | return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) |
| 2616 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2617 | return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev)); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 2618 | } |
| 2619 | |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 2620 | static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev, |
| 2621 | struct ocb_setup *setup) |
| 2622 | { |
| 2623 | return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup); |
| 2624 | } |
| 2625 | |
| 2626 | static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev) |
| 2627 | { |
| 2628 | return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev)); |
| 2629 | } |
| 2630 | |
Antonio Quartulli | 391e53e | 2012-11-02 13:27:49 +0100 | [diff] [blame] | 2631 | static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2632 | int rate[NUM_NL80211_BANDS]) |
Antonio Quartulli | 391e53e | 2012-11-02 13:27:49 +0100 | [diff] [blame] | 2633 | { |
| 2634 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2635 | |
Cong Ding | 9887dbf | 2013-02-06 17:23:45 +0100 | [diff] [blame] | 2636 | memcpy(sdata->vif.bss_conf.mcast_rate, rate, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2637 | sizeof(int) * NUM_NL80211_BANDS); |
Antonio Quartulli | 391e53e | 2012-11-02 13:27:49 +0100 | [diff] [blame] | 2638 | |
Pradeep Kumar Chitrapu | dcbe73c | 2018-03-22 12:18:03 -0700 | [diff] [blame] | 2639 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MCAST_RATE); |
| 2640 | |
Antonio Quartulli | 391e53e | 2012-11-02 13:27:49 +0100 | [diff] [blame] | 2641 | return 0; |
| 2642 | } |
| 2643 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2644 | static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
| 2645 | { |
| 2646 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 2647 | int err; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2648 | |
Arik Nemtsov | f23a478 | 2010-11-08 11:51:06 +0200 | [diff] [blame] | 2649 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) { |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 2650 | ieee80211_check_fast_xmit_all(local); |
| 2651 | |
Arik Nemtsov | f23a478 | 2010-11-08 11:51:06 +0200 | [diff] [blame] | 2652 | err = drv_set_frag_threshold(local, wiphy->frag_threshold); |
| 2653 | |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 2654 | if (err) { |
| 2655 | ieee80211_check_fast_xmit_all(local); |
Arik Nemtsov | f23a478 | 2010-11-08 11:51:06 +0200 | [diff] [blame] | 2656 | return err; |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 2657 | } |
Arik Nemtsov | f23a478 | 2010-11-08 11:51:06 +0200 | [diff] [blame] | 2658 | } |
| 2659 | |
Lorenzo Bianconi | a4bcaf5 | 2014-09-04 23:57:41 +0200 | [diff] [blame] | 2660 | if ((changed & WIPHY_PARAM_COVERAGE_CLASS) || |
| 2661 | (changed & WIPHY_PARAM_DYN_ACK)) { |
| 2662 | s16 coverage_class; |
| 2663 | |
| 2664 | coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ? |
| 2665 | wiphy->coverage_class : -1; |
| 2666 | err = drv_set_coverage_class(local, coverage_class); |
Lukáš Turek | 310bc67 | 2009-12-21 22:50:48 +0100 | [diff] [blame] | 2667 | |
| 2668 | if (err) |
| 2669 | return err; |
| 2670 | } |
| 2671 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2672 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) { |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 2673 | err = drv_set_rts_threshold(local, wiphy->rts_threshold); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2674 | |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 2675 | if (err) |
| 2676 | return err; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2677 | } |
| 2678 | |
Johannes Berg | 8bc83c2 | 2012-11-09 18:38:32 +0100 | [diff] [blame] | 2679 | if (changed & WIPHY_PARAM_RETRY_SHORT) { |
| 2680 | if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY) |
| 2681 | return -EINVAL; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2682 | local->hw.conf.short_frame_max_tx_count = wiphy->retry_short; |
Johannes Berg | 8bc83c2 | 2012-11-09 18:38:32 +0100 | [diff] [blame] | 2683 | } |
| 2684 | if (changed & WIPHY_PARAM_RETRY_LONG) { |
| 2685 | if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY) |
| 2686 | return -EINVAL; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2687 | local->hw.conf.long_frame_max_tx_count = wiphy->retry_long; |
Johannes Berg | 8bc83c2 | 2012-11-09 18:38:32 +0100 | [diff] [blame] | 2688 | } |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2689 | if (changed & |
| 2690 | (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG)) |
| 2691 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS); |
| 2692 | |
Toke Høiland-Jørgensen | 2fe4a29 | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2693 | if (changed & (WIPHY_PARAM_TXQ_LIMIT | |
| 2694 | WIPHY_PARAM_TXQ_MEMORY_LIMIT | |
| 2695 | WIPHY_PARAM_TXQ_QUANTUM)) |
| 2696 | ieee80211_txq_set_params(local); |
| 2697 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2698 | return 0; |
| 2699 | } |
| 2700 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2701 | static int ieee80211_set_tx_power(struct wiphy *wiphy, |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2702 | struct wireless_dev *wdev, |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 2703 | enum nl80211_tx_power_setting type, int mbm) |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2704 | { |
| 2705 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2706 | struct ieee80211_sub_if_data *sdata; |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2707 | enum nl80211_tx_power_setting txp_type = type; |
| 2708 | bool update_txp_type = false; |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2709 | bool has_monitor = false; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2710 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2711 | if (wdev) { |
| 2712 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 2713 | |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2714 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
Johannes Berg | 6dd23603 | 2021-11-12 13:51:44 +0100 | [diff] [blame] | 2715 | sdata = wiphy_dereference(local->hw.wiphy, |
| 2716 | local->monitor_sdata); |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2717 | if (!sdata) |
| 2718 | return -EOPNOTSUPP; |
| 2719 | } |
| 2720 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2721 | switch (type) { |
| 2722 | case NL80211_TX_POWER_AUTOMATIC: |
| 2723 | sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL; |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2724 | txp_type = NL80211_TX_POWER_LIMITED; |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2725 | break; |
| 2726 | case NL80211_TX_POWER_LIMITED: |
| 2727 | case NL80211_TX_POWER_FIXED: |
| 2728 | if (mbm < 0 || (mbm % 100)) |
| 2729 | return -EOPNOTSUPP; |
| 2730 | sdata->user_power_level = MBM_TO_DBM(mbm); |
| 2731 | break; |
| 2732 | } |
| 2733 | |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2734 | if (txp_type != sdata->vif.bss_conf.txpower_type) { |
| 2735 | update_txp_type = true; |
| 2736 | sdata->vif.bss_conf.txpower_type = txp_type; |
| 2737 | } |
| 2738 | |
| 2739 | ieee80211_recalc_txpower(sdata, update_txp_type); |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2740 | |
| 2741 | return 0; |
| 2742 | } |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2743 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2744 | switch (type) { |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 2745 | case NL80211_TX_POWER_AUTOMATIC: |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2746 | local->user_power_level = IEEE80211_UNSET_POWER_LEVEL; |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2747 | txp_type = NL80211_TX_POWER_LIMITED; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2748 | break; |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 2749 | case NL80211_TX_POWER_LIMITED: |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 2750 | case NL80211_TX_POWER_FIXED: |
| 2751 | if (mbm < 0 || (mbm % 100)) |
| 2752 | return -EOPNOTSUPP; |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 2753 | local->user_power_level = MBM_TO_DBM(mbm); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2754 | break; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2755 | } |
| 2756 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2757 | mutex_lock(&local->iflist_mtx); |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2758 | list_for_each_entry(sdata, &local->interfaces, list) { |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2759 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
| 2760 | has_monitor = true; |
| 2761 | continue; |
| 2762 | } |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2763 | sdata->user_power_level = local->user_power_level; |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2764 | if (txp_type != sdata->vif.bss_conf.txpower_type) |
| 2765 | update_txp_type = true; |
| 2766 | sdata->vif.bss_conf.txpower_type = txp_type; |
| 2767 | } |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2768 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 2769 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) |
| 2770 | continue; |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2771 | ieee80211_recalc_txpower(sdata, update_txp_type); |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2772 | } |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2773 | mutex_unlock(&local->iflist_mtx); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2774 | |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2775 | if (has_monitor) { |
Johannes Berg | 6dd23603 | 2021-11-12 13:51:44 +0100 | [diff] [blame] | 2776 | sdata = wiphy_dereference(local->hw.wiphy, |
| 2777 | local->monitor_sdata); |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2778 | if (sdata) { |
| 2779 | sdata->user_power_level = local->user_power_level; |
| 2780 | if (txp_type != sdata->vif.bss_conf.txpower_type) |
| 2781 | update_txp_type = true; |
| 2782 | sdata->vif.bss_conf.txpower_type = txp_type; |
| 2783 | |
| 2784 | ieee80211_recalc_txpower(sdata, update_txp_type); |
| 2785 | } |
| 2786 | } |
| 2787 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2788 | return 0; |
| 2789 | } |
| 2790 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2791 | static int ieee80211_get_tx_power(struct wiphy *wiphy, |
| 2792 | struct wireless_dev *wdev, |
| 2793 | int *dbm) |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2794 | { |
| 2795 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2796 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2797 | |
Felix Fietkau | 5b3dc42 | 2014-10-26 00:32:53 +0200 | [diff] [blame] | 2798 | if (local->ops->get_txpower) |
| 2799 | return drv_get_txpower(local, sdata, dbm); |
| 2800 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2801 | if (!local->use_chanctx) |
| 2802 | *dbm = local->hw.conf.power_level; |
| 2803 | else |
| 2804 | *dbm = sdata->vif.bss_conf.txpower; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2805 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2806 | return 0; |
| 2807 | } |
| 2808 | |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 2809 | static void ieee80211_rfkill_poll(struct wiphy *wiphy) |
| 2810 | { |
| 2811 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 2812 | |
| 2813 | drv_rfkill_poll(local); |
| 2814 | } |
| 2815 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 2816 | #ifdef CONFIG_NL80211_TESTMODE |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 2817 | static int ieee80211_testmode_cmd(struct wiphy *wiphy, |
| 2818 | struct wireless_dev *wdev, |
| 2819 | void *data, int len) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 2820 | { |
| 2821 | struct ieee80211_local *local = wiphy_priv(wiphy); |
David Spinadel | 52981cd | 2013-07-31 18:06:22 +0300 | [diff] [blame] | 2822 | struct ieee80211_vif *vif = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 2823 | |
| 2824 | if (!local->ops->testmode_cmd) |
| 2825 | return -EOPNOTSUPP; |
| 2826 | |
David Spinadel | 52981cd | 2013-07-31 18:06:22 +0300 | [diff] [blame] | 2827 | if (wdev) { |
| 2828 | struct ieee80211_sub_if_data *sdata; |
| 2829 | |
| 2830 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 2831 | if (sdata->flags & IEEE80211_SDATA_IN_DRIVER) |
| 2832 | vif = &sdata->vif; |
| 2833 | } |
| 2834 | |
| 2835 | return local->ops->testmode_cmd(&local->hw, vif, data, len); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 2836 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 2837 | |
| 2838 | static int ieee80211_testmode_dump(struct wiphy *wiphy, |
| 2839 | struct sk_buff *skb, |
| 2840 | struct netlink_callback *cb, |
| 2841 | void *data, int len) |
| 2842 | { |
| 2843 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 2844 | |
| 2845 | if (!local->ops->testmode_dump) |
| 2846 | return -EOPNOTSUPP; |
| 2847 | |
| 2848 | return local->ops->testmode_dump(&local->hw, skb, cb, data, len); |
| 2849 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 2850 | #endif |
| 2851 | |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 2852 | int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata, |
| 2853 | enum ieee80211_smps_mode smps_mode) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2854 | { |
| 2855 | const u8 *ap; |
| 2856 | enum ieee80211_smps_mode old_req; |
| 2857 | int err; |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 2858 | struct sta_info *sta; |
| 2859 | bool tdls_peer_found = false; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2860 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2861 | lockdep_assert_held(&sdata->wdev.mtx); |
Johannes Berg | 243e6df | 2011-04-19 20:44:04 +0200 | [diff] [blame] | 2862 | |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 2863 | if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 2864 | return -EINVAL; |
| 2865 | |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2866 | old_req = sdata->u.mgd.req_smps; |
| 2867 | sdata->u.mgd.req_smps = smps_mode; |
| 2868 | |
| 2869 | if (old_req == smps_mode && |
| 2870 | smps_mode != IEEE80211_SMPS_AUTOMATIC) |
| 2871 | return 0; |
| 2872 | |
| 2873 | /* |
| 2874 | * If not associated, or current association is not an HT |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 2875 | * association, there's no need to do anything, just store |
| 2876 | * the new value until we associate. |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2877 | */ |
| 2878 | if (!sdata->u.mgd.associated || |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 2879 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2880 | return 0; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2881 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2882 | ap = sdata->u.mgd.associated->bssid; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2883 | |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 2884 | rcu_read_lock(); |
| 2885 | list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) { |
| 2886 | if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded || |
| 2887 | !test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
| 2888 | continue; |
| 2889 | |
| 2890 | tdls_peer_found = true; |
| 2891 | break; |
| 2892 | } |
| 2893 | rcu_read_unlock(); |
| 2894 | |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2895 | if (smps_mode == IEEE80211_SMPS_AUTOMATIC) { |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 2896 | if (tdls_peer_found || !sdata->u.mgd.powersave) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2897 | smps_mode = IEEE80211_SMPS_OFF; |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 2898 | else |
| 2899 | smps_mode = IEEE80211_SMPS_DYNAMIC; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | /* send SM PS frame to AP */ |
| 2903 | err = ieee80211_send_smps_action(sdata, smps_mode, |
| 2904 | ap, ap); |
| 2905 | if (err) |
| 2906 | sdata->u.mgd.req_smps = old_req; |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 2907 | else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found) |
| 2908 | ieee80211_teardown_tdls_peers(sdata); |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2909 | |
| 2910 | return err; |
| 2911 | } |
| 2912 | |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2913 | static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev, |
| 2914 | bool enabled, int timeout) |
| 2915 | { |
| 2916 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2917 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2918 | |
Bob Copeland | 2d3db21 | 2013-10-29 18:11:59 -0400 | [diff] [blame] | 2919 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Benoit Papillault | e5de30c | 2010-01-15 12:21:37 +0100 | [diff] [blame] | 2920 | return -EOPNOTSUPP; |
| 2921 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2922 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2923 | return -EOPNOTSUPP; |
| 2924 | |
| 2925 | if (enabled == sdata->u.mgd.powersave && |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 2926 | timeout == local->dynamic_ps_forced_timeout) |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2927 | return 0; |
| 2928 | |
| 2929 | sdata->u.mgd.powersave = enabled; |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 2930 | local->dynamic_ps_forced_timeout = timeout; |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2931 | |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2932 | /* no change, but if automatic follow powersave */ |
Johannes Berg | ed405be | 2013-06-03 13:51:59 +0200 | [diff] [blame] | 2933 | sdata_lock(sdata); |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 2934 | __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps); |
Johannes Berg | ed405be | 2013-06-03 13:51:59 +0200 | [diff] [blame] | 2935 | sdata_unlock(sdata); |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2936 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2937 | if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2938 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 2939 | |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2940 | ieee80211_recalc_ps(local); |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 2941 | ieee80211_recalc_ps_vif(sdata); |
Felix Fietkau | 1d87016 | 2018-02-23 10:06:05 +0100 | [diff] [blame] | 2942 | ieee80211_check_fast_rx_iface(sdata); |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2943 | |
| 2944 | return 0; |
| 2945 | } |
| 2946 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2947 | static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy, |
| 2948 | struct net_device *dev, |
| 2949 | s32 rssi_thold, u32 rssi_hyst) |
| 2950 | { |
| 2951 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2952 | struct ieee80211_vif *vif = &sdata->vif; |
| 2953 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
| 2954 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2955 | if (rssi_thold == bss_conf->cqm_rssi_thold && |
| 2956 | rssi_hyst == bss_conf->cqm_rssi_hyst) |
| 2957 | return 0; |
| 2958 | |
Johannes Berg | ef9be10 | 2015-08-28 10:44:20 +0200 | [diff] [blame] | 2959 | if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER && |
| 2960 | !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) |
| 2961 | return -EOPNOTSUPP; |
| 2962 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2963 | bss_conf->cqm_rssi_thold = rssi_thold; |
| 2964 | bss_conf->cqm_rssi_hyst = rssi_hyst; |
Andrew Zaborowski | 2c3c5f8c | 2017-02-10 04:50:22 +0100 | [diff] [blame] | 2965 | bss_conf->cqm_rssi_low = 0; |
| 2966 | bss_conf->cqm_rssi_high = 0; |
| 2967 | sdata->u.mgd.last_cqm_event_signal = 0; |
| 2968 | |
| 2969 | /* tell the driver upon association, unless already associated */ |
| 2970 | if (sdata->u.mgd.associated && |
| 2971 | sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI) |
| 2972 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM); |
| 2973 | |
| 2974 | return 0; |
| 2975 | } |
| 2976 | |
| 2977 | static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy, |
| 2978 | struct net_device *dev, |
| 2979 | s32 rssi_low, s32 rssi_high) |
| 2980 | { |
| 2981 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2982 | struct ieee80211_vif *vif = &sdata->vif; |
| 2983 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
| 2984 | |
| 2985 | if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) |
| 2986 | return -EOPNOTSUPP; |
| 2987 | |
| 2988 | bss_conf->cqm_rssi_low = rssi_low; |
| 2989 | bss_conf->cqm_rssi_high = rssi_high; |
| 2990 | bss_conf->cqm_rssi_thold = 0; |
| 2991 | bss_conf->cqm_rssi_hyst = 0; |
Sara Sharon | babc305e2 | 2015-09-21 15:47:40 +0300 | [diff] [blame] | 2992 | sdata->u.mgd.last_cqm_event_signal = 0; |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2993 | |
| 2994 | /* tell the driver upon association, unless already associated */ |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 2995 | if (sdata->u.mgd.associated && |
| 2996 | sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI) |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2997 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM); |
| 2998 | |
| 2999 | return 0; |
| 3000 | } |
| 3001 | |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 3002 | static int ieee80211_set_bitrate_mask(struct wiphy *wiphy, |
| 3003 | struct net_device *dev, |
| 3004 | const u8 *addr, |
| 3005 | const struct cfg80211_bitrate_mask *mask) |
| 3006 | { |
| 3007 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3008 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Sujith Manoharan | bdbfd6b | 2011-04-27 16:56:51 +0530 | [diff] [blame] | 3009 | int i, ret; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 3010 | |
Eliad Peller | 554a43d | 2012-06-12 12:41:15 +0300 | [diff] [blame] | 3011 | if (!ieee80211_sdata_running(sdata)) |
| 3012 | return -ENETDOWN; |
| 3013 | |
Johannes Berg | e8e4f52 | 2017-03-08 11:12:10 +0100 | [diff] [blame] | 3014 | /* |
| 3015 | * If active validate the setting and reject it if it doesn't leave |
| 3016 | * at least one basic rate usable, since we really have to be able |
| 3017 | * to send something, and if we're an AP we have to be able to do |
| 3018 | * so at a basic rate so that all clients can receive it. |
| 3019 | */ |
| 3020 | if (rcu_access_pointer(sdata->vif.chanctx_conf) && |
| 3021 | sdata->vif.bss_conf.chandef.chan) { |
| 3022 | u32 basic_rates = sdata->vif.bss_conf.basic_rates; |
| 3023 | enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band; |
| 3024 | |
| 3025 | if (!(mask->control[band].legacy & basic_rates)) |
| 3026 | return -EINVAL; |
| 3027 | } |
| 3028 | |
Johannes Berg | e5f5ce3 | 2017-10-18 09:36:51 +0200 | [diff] [blame] | 3029 | if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) { |
| 3030 | ret = drv_set_bitrate_mask(local, sdata, mask); |
| 3031 | if (ret) |
| 3032 | return ret; |
| 3033 | } |
| 3034 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3035 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
Felix Fietkau | 2ffbe6d | 2013-04-16 13:38:42 +0200 | [diff] [blame] | 3036 | struct ieee80211_supported_band *sband = wiphy->bands[i]; |
| 3037 | int j; |
| 3038 | |
Jouni Malinen | 37eb0b1 | 2010-01-06 13:09:08 +0200 | [diff] [blame] | 3039 | sdata->rc_rateidx_mask[i] = mask->control[i].legacy; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 3040 | memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs, |
| 3041 | sizeof(mask->control[i].ht_mcs)); |
Lorenzo Bianconi | b119ad6 | 2015-08-06 23:47:33 +0200 | [diff] [blame] | 3042 | memcpy(sdata->rc_rateidx_vht_mcs_mask[i], |
| 3043 | mask->control[i].vht_mcs, |
| 3044 | sizeof(mask->control[i].vht_mcs)); |
Felix Fietkau | 2ffbe6d | 2013-04-16 13:38:42 +0200 | [diff] [blame] | 3045 | |
| 3046 | sdata->rc_has_mcs_mask[i] = false; |
Lorenzo Bianconi | b119ad6 | 2015-08-06 23:47:33 +0200 | [diff] [blame] | 3047 | sdata->rc_has_vht_mcs_mask[i] = false; |
Felix Fietkau | 2ffbe6d | 2013-04-16 13:38:42 +0200 | [diff] [blame] | 3048 | if (!sband) |
| 3049 | continue; |
| 3050 | |
Lorenzo Bianconi | b119ad6 | 2015-08-06 23:47:33 +0200 | [diff] [blame] | 3051 | for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) { |
Johannes Berg | 1944015 | 2021-02-12 11:22:14 +0100 | [diff] [blame] | 3052 | if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) { |
Felix Fietkau | 2ffbe6d | 2013-04-16 13:38:42 +0200 | [diff] [blame] | 3053 | sdata->rc_has_mcs_mask[i] = true; |
| 3054 | break; |
Johannes Berg | 2df1b13 | 2015-08-21 14:07:13 +0200 | [diff] [blame] | 3055 | } |
| 3056 | } |
| 3057 | |
| 3058 | for (j = 0; j < NL80211_VHT_NSS_MAX; j++) { |
Johannes Berg | 1944015 | 2021-02-12 11:22:14 +0100 | [diff] [blame] | 3059 | if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) { |
Johannes Berg | 2df1b13 | 2015-08-21 14:07:13 +0200 | [diff] [blame] | 3060 | sdata->rc_has_vht_mcs_mask[i] = true; |
| 3061 | break; |
| 3062 | } |
Lorenzo Bianconi | b119ad6 | 2015-08-06 23:47:33 +0200 | [diff] [blame] | 3063 | } |
Simon Wunderlich | 1946841 | 2012-01-28 17:25:33 +0100 | [diff] [blame] | 3064 | } |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 3065 | |
Jouni Malinen | 37eb0b1 | 2010-01-06 13:09:08 +0200 | [diff] [blame] | 3066 | return 0; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 3067 | } |
| 3068 | |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 3069 | static int ieee80211_start_radar_detection(struct wiphy *wiphy, |
| 3070 | struct net_device *dev, |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 3071 | struct cfg80211_chan_def *chandef, |
| 3072 | u32 cac_time_ms) |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 3073 | { |
| 3074 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3075 | struct ieee80211_local *local = sdata->local; |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 3076 | int err; |
| 3077 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 3078 | mutex_lock(&local->mtx); |
| 3079 | if (!list_empty(&local->roc_list) || local->scanning) { |
| 3080 | err = -EBUSY; |
| 3081 | goto out_unlock; |
| 3082 | } |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 3083 | |
| 3084 | /* whatever, but channel contexts should not complain about that one */ |
| 3085 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
| 3086 | sdata->needed_rx_chains = local->rx_chains; |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 3087 | |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 3088 | err = ieee80211_vif_use_channel(sdata, chandef, |
| 3089 | IEEE80211_CHANCTX_SHARED); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 3090 | if (err) |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 3091 | goto out_unlock; |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 3092 | |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 3093 | ieee80211_queue_delayed_work(&sdata->local->hw, |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 3094 | &sdata->dfs_cac_timer_work, |
| 3095 | msecs_to_jiffies(cac_time_ms)); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 3096 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 3097 | out_unlock: |
| 3098 | mutex_unlock(&local->mtx); |
| 3099 | return err; |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 3100 | } |
| 3101 | |
Orr Mazor | 26ec17a | 2019-12-22 14:55:31 +0000 | [diff] [blame] | 3102 | static void ieee80211_end_cac(struct wiphy *wiphy, |
| 3103 | struct net_device *dev) |
| 3104 | { |
| 3105 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3106 | struct ieee80211_local *local = sdata->local; |
| 3107 | |
| 3108 | mutex_lock(&local->mtx); |
| 3109 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 3110 | /* it might be waiting for the local->mtx, but then |
| 3111 | * by the time it gets it, sdata->wdev.cac_started |
| 3112 | * will no longer be true |
| 3113 | */ |
| 3114 | cancel_delayed_work(&sdata->dfs_cac_timer_work); |
| 3115 | |
| 3116 | if (sdata->wdev.cac_started) { |
| 3117 | ieee80211_vif_release_channel(sdata); |
| 3118 | sdata->wdev.cac_started = false; |
| 3119 | } |
| 3120 | } |
| 3121 | mutex_unlock(&local->mtx); |
| 3122 | } |
| 3123 | |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3124 | static struct cfg80211_beacon_data * |
| 3125 | cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon) |
| 3126 | { |
| 3127 | struct cfg80211_beacon_data *new_beacon; |
| 3128 | u8 *pos; |
| 3129 | int len; |
| 3130 | |
| 3131 | len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len + |
| 3132 | beacon->proberesp_ies_len + beacon->assocresp_ies_len + |
Johannes Berg | 03b7386 | 2018-10-30 09:17:45 +0100 | [diff] [blame] | 3133 | beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3134 | |
| 3135 | new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL); |
| 3136 | if (!new_beacon) |
| 3137 | return NULL; |
| 3138 | |
| 3139 | pos = (u8 *)(new_beacon + 1); |
| 3140 | if (beacon->head_len) { |
| 3141 | new_beacon->head_len = beacon->head_len; |
| 3142 | new_beacon->head = pos; |
| 3143 | memcpy(pos, beacon->head, beacon->head_len); |
| 3144 | pos += beacon->head_len; |
| 3145 | } |
| 3146 | if (beacon->tail_len) { |
| 3147 | new_beacon->tail_len = beacon->tail_len; |
| 3148 | new_beacon->tail = pos; |
| 3149 | memcpy(pos, beacon->tail, beacon->tail_len); |
| 3150 | pos += beacon->tail_len; |
| 3151 | } |
| 3152 | if (beacon->beacon_ies_len) { |
| 3153 | new_beacon->beacon_ies_len = beacon->beacon_ies_len; |
| 3154 | new_beacon->beacon_ies = pos; |
| 3155 | memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len); |
| 3156 | pos += beacon->beacon_ies_len; |
| 3157 | } |
| 3158 | if (beacon->proberesp_ies_len) { |
| 3159 | new_beacon->proberesp_ies_len = beacon->proberesp_ies_len; |
| 3160 | new_beacon->proberesp_ies = pos; |
| 3161 | memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len); |
| 3162 | pos += beacon->proberesp_ies_len; |
| 3163 | } |
| 3164 | if (beacon->assocresp_ies_len) { |
| 3165 | new_beacon->assocresp_ies_len = beacon->assocresp_ies_len; |
| 3166 | new_beacon->assocresp_ies = pos; |
| 3167 | memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len); |
| 3168 | pos += beacon->assocresp_ies_len; |
| 3169 | } |
| 3170 | if (beacon->probe_resp_len) { |
| 3171 | new_beacon->probe_resp_len = beacon->probe_resp_len; |
Arnd Bergmann | bee92d0 | 2018-02-02 16:31:23 +0100 | [diff] [blame] | 3172 | new_beacon->probe_resp = pos; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3173 | memcpy(pos, beacon->probe_resp, beacon->probe_resp_len); |
| 3174 | pos += beacon->probe_resp_len; |
| 3175 | } |
Johannes Berg | 03b7386 | 2018-10-30 09:17:45 +0100 | [diff] [blame] | 3176 | |
| 3177 | /* might copy -1, meaning no changes requested */ |
| 3178 | new_beacon->ftm_responder = beacon->ftm_responder; |
Pradeep Kumar Chitrapu | bc84797 | 2018-10-03 20:19:20 -0700 | [diff] [blame] | 3179 | if (beacon->lci) { |
| 3180 | new_beacon->lci_len = beacon->lci_len; |
| 3181 | new_beacon->lci = pos; |
| 3182 | memcpy(pos, beacon->lci, beacon->lci_len); |
| 3183 | pos += beacon->lci_len; |
| 3184 | } |
| 3185 | if (beacon->civicloc) { |
| 3186 | new_beacon->civicloc_len = beacon->civicloc_len; |
| 3187 | new_beacon->civicloc = pos; |
| 3188 | memcpy(pos, beacon->civicloc, beacon->civicloc_len); |
| 3189 | pos += beacon->civicloc_len; |
| 3190 | } |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3191 | |
| 3192 | return new_beacon; |
| 3193 | } |
| 3194 | |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 3195 | void ieee80211_csa_finish(struct ieee80211_vif *vif) |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3196 | { |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 3197 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 3198 | |
| 3199 | ieee80211_queue_work(&sdata->local->hw, |
| 3200 | &sdata->csa_finalize_work); |
| 3201 | } |
| 3202 | EXPORT_SYMBOL(ieee80211_csa_finish); |
| 3203 | |
Nathan Errera | 6d50176 | 2021-11-29 15:32:38 +0200 | [diff] [blame] | 3204 | void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif, bool block_tx) |
| 3205 | { |
| 3206 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 3207 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3208 | struct ieee80211_local *local = sdata->local; |
| 3209 | |
| 3210 | sdata->csa_block_tx = block_tx; |
| 3211 | sdata_info(sdata, "channel switch failed, disconnecting\n"); |
| 3212 | ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work); |
| 3213 | } |
| 3214 | EXPORT_SYMBOL(ieee80211_channel_switch_disconnect); |
| 3215 | |
Michal Kazior | 6619950 | 2014-04-09 15:11:00 +0200 | [diff] [blame] | 3216 | static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata, |
| 3217 | u32 *changed) |
| 3218 | { |
| 3219 | int err; |
| 3220 | |
| 3221 | switch (sdata->vif.type) { |
| 3222 | case NL80211_IFTYPE_AP: |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 3223 | err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon, |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 3224 | NULL, NULL); |
Michal Kazior | 6619950 | 2014-04-09 15:11:00 +0200 | [diff] [blame] | 3225 | kfree(sdata->u.ap.next_beacon); |
| 3226 | sdata->u.ap.next_beacon = NULL; |
| 3227 | |
| 3228 | if (err < 0) |
| 3229 | return err; |
| 3230 | *changed |= err; |
| 3231 | break; |
| 3232 | case NL80211_IFTYPE_ADHOC: |
| 3233 | err = ieee80211_ibss_finish_csa(sdata); |
| 3234 | if (err < 0) |
| 3235 | return err; |
| 3236 | *changed |= err; |
| 3237 | break; |
| 3238 | #ifdef CONFIG_MAC80211_MESH |
| 3239 | case NL80211_IFTYPE_MESH_POINT: |
| 3240 | err = ieee80211_mesh_finish_csa(sdata); |
| 3241 | if (err < 0) |
| 3242 | return err; |
| 3243 | *changed |= err; |
| 3244 | break; |
| 3245 | #endif |
| 3246 | default: |
| 3247 | WARN_ON(1); |
| 3248 | return -EINVAL; |
| 3249 | } |
| 3250 | |
| 3251 | return 0; |
| 3252 | } |
| 3253 | |
Michal Kazior | cf8767d | 2014-05-08 09:10:02 +0200 | [diff] [blame] | 3254 | static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata) |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 3255 | { |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3256 | struct ieee80211_local *local = sdata->local; |
Michal Kazior | 6619950 | 2014-04-09 15:11:00 +0200 | [diff] [blame] | 3257 | u32 changed = 0; |
| 3258 | int err; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3259 | |
Michal Kazior | dbd7285 | 2014-01-29 07:56:21 +0100 | [diff] [blame] | 3260 | sdata_assert_lock(sdata); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3261 | lockdep_assert_held(&local->mtx); |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3262 | lockdep_assert_held(&local->chanctx_mtx); |
Michal Kazior | dbd7285 | 2014-01-29 07:56:21 +0100 | [diff] [blame] | 3263 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3264 | /* |
| 3265 | * using reservation isn't immediate as it may be deferred until later |
| 3266 | * with multi-vif. once reservation is complete it will re-schedule the |
| 3267 | * work with no reserved_chanctx so verify chandef to check if it |
| 3268 | * completed successfully |
| 3269 | */ |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3270 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3271 | if (sdata->reserved_chanctx) { |
| 3272 | /* |
| 3273 | * with multi-vif csa driver may call ieee80211_csa_finish() |
| 3274 | * many times while waiting for other interfaces to use their |
| 3275 | * reservations |
| 3276 | */ |
| 3277 | if (sdata->reserved_ready) |
| 3278 | return 0; |
| 3279 | |
Fabian Frederick | 408b18a | 2014-10-09 20:36:22 +0200 | [diff] [blame] | 3280 | return ieee80211_vif_use_reserved_context(sdata); |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 3281 | } |
| 3282 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3283 | if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef, |
| 3284 | &sdata->csa_chandef)) |
| 3285 | return -EINVAL; |
| 3286 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 3287 | sdata->vif.csa_active = false; |
Michal Kazior | 97518af1 | 2014-01-29 07:56:18 +0100 | [diff] [blame] | 3288 | |
Michal Kazior | 6619950 | 2014-04-09 15:11:00 +0200 | [diff] [blame] | 3289 | err = ieee80211_set_after_csa_beacon(sdata, &changed); |
| 3290 | if (err) |
Michal Kazior | cf8767d | 2014-05-08 09:10:02 +0200 | [diff] [blame] | 3291 | return err; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3292 | |
Michal Kazior | faf046e | 2014-01-29 07:56:17 +0100 | [diff] [blame] | 3293 | ieee80211_bss_info_change_notify(sdata, changed); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3294 | |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 3295 | if (sdata->csa_block_tx) { |
| 3296 | ieee80211_wake_vif_queues(local, sdata, |
| 3297 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 3298 | sdata->csa_block_tx = false; |
| 3299 | } |
Michal Kazior | cf8767d | 2014-05-08 09:10:02 +0200 | [diff] [blame] | 3300 | |
Luciano Coelho | f1d6558 | 2014-10-08 09:48:38 +0300 | [diff] [blame] | 3301 | err = drv_post_channel_switch(sdata); |
| 3302 | if (err) |
| 3303 | return err; |
| 3304 | |
| 3305 | cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef); |
| 3306 | |
Michal Kazior | cf8767d | 2014-05-08 09:10:02 +0200 | [diff] [blame] | 3307 | return 0; |
| 3308 | } |
| 3309 | |
| 3310 | static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata) |
| 3311 | { |
| 3312 | if (__ieee80211_csa_finalize(sdata)) { |
| 3313 | sdata_info(sdata, "failed to finalize CSA, disconnecting\n"); |
| 3314 | cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev, |
| 3315 | GFP_KERNEL); |
| 3316 | } |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | void ieee80211_csa_finalize_work(struct work_struct *work) |
| 3320 | { |
| 3321 | struct ieee80211_sub_if_data *sdata = |
| 3322 | container_of(work, struct ieee80211_sub_if_data, |
| 3323 | csa_finalize_work); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3324 | struct ieee80211_local *local = sdata->local; |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 3325 | |
| 3326 | sdata_lock(sdata); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3327 | mutex_lock(&local->mtx); |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3328 | mutex_lock(&local->chanctx_mtx); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3329 | |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 3330 | /* AP might have been stopped while waiting for the lock. */ |
| 3331 | if (!sdata->vif.csa_active) |
| 3332 | goto unlock; |
| 3333 | |
| 3334 | if (!ieee80211_sdata_running(sdata)) |
| 3335 | goto unlock; |
| 3336 | |
| 3337 | ieee80211_csa_finalize(sdata); |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 3338 | |
| 3339 | unlock: |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3340 | mutex_unlock(&local->chanctx_mtx); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3341 | mutex_unlock(&local->mtx); |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 3342 | sdata_unlock(sdata); |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3343 | } |
| 3344 | |
Michal Kazior | 37fa2bd | 2014-02-28 15:59:06 +0100 | [diff] [blame] | 3345 | static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata, |
| 3346 | struct cfg80211_csa_settings *params, |
| 3347 | u32 *changed) |
| 3348 | { |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 3349 | struct ieee80211_csa_settings csa = {}; |
Michal Kazior | 37fa2bd | 2014-02-28 15:59:06 +0100 | [diff] [blame] | 3350 | int err; |
| 3351 | |
| 3352 | switch (sdata->vif.type) { |
| 3353 | case NL80211_IFTYPE_AP: |
| 3354 | sdata->u.ap.next_beacon = |
| 3355 | cfg80211_beacon_dup(¶ms->beacon_after); |
| 3356 | if (!sdata->u.ap.next_beacon) |
| 3357 | return -ENOMEM; |
| 3358 | |
| 3359 | /* |
| 3360 | * With a count of 0, we don't have to wait for any |
| 3361 | * TBTT before switching, so complete the CSA |
| 3362 | * immediately. In theory, with a count == 1 we |
| 3363 | * should delay the switch until just before the next |
| 3364 | * TBTT, but that would complicate things so we switch |
| 3365 | * immediately too. If we would delay the switch |
| 3366 | * until the next TBTT, we would have to set the probe |
| 3367 | * response here. |
| 3368 | * |
| 3369 | * TODO: A channel switch with count <= 1 without |
| 3370 | * sending a CSA action frame is kind of useless, |
| 3371 | * because the clients won't know we're changing |
| 3372 | * channels. The action frame must be implemented |
| 3373 | * either here or in the userspace. |
| 3374 | */ |
| 3375 | if (params->count <= 1) |
| 3376 | break; |
| 3377 | |
Andrei Otcheretianski | 0d06d9b | 2014-05-09 14:11:47 +0300 | [diff] [blame] | 3378 | if ((params->n_counter_offsets_beacon > |
John Crispin | 8552a43 | 2020-08-11 10:01:04 +0200 | [diff] [blame] | 3379 | IEEE80211_MAX_CNTDWN_COUNTERS_NUM) || |
Andrei Otcheretianski | 0d06d9b | 2014-05-09 14:11:47 +0300 | [diff] [blame] | 3380 | (params->n_counter_offsets_presp > |
John Crispin | 8552a43 | 2020-08-11 10:01:04 +0200 | [diff] [blame] | 3381 | IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) |
Andrei Otcheretianski | 0d06d9b | 2014-05-09 14:11:47 +0300 | [diff] [blame] | 3382 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 3383 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 3384 | csa.counter_offsets_beacon = params->counter_offsets_beacon; |
| 3385 | csa.counter_offsets_presp = params->counter_offsets_presp; |
| 3386 | csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon; |
| 3387 | csa.n_counter_offsets_presp = params->n_counter_offsets_presp; |
| 3388 | csa.count = params->count; |
Andrei Otcheretianski | 0d06d9b | 2014-05-09 14:11:47 +0300 | [diff] [blame] | 3389 | |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 3390 | err = ieee80211_assign_beacon(sdata, ¶ms->beacon_csa, &csa, NULL); |
Michal Kazior | 37fa2bd | 2014-02-28 15:59:06 +0100 | [diff] [blame] | 3391 | if (err < 0) { |
| 3392 | kfree(sdata->u.ap.next_beacon); |
| 3393 | return err; |
| 3394 | } |
| 3395 | *changed |= err; |
| 3396 | |
| 3397 | break; |
| 3398 | case NL80211_IFTYPE_ADHOC: |
| 3399 | if (!sdata->vif.bss_conf.ibss_joined) |
| 3400 | return -EINVAL; |
| 3401 | |
| 3402 | if (params->chandef.width != sdata->u.ibss.chandef.width) |
| 3403 | return -EINVAL; |
| 3404 | |
| 3405 | switch (params->chandef.width) { |
| 3406 | case NL80211_CHAN_WIDTH_40: |
| 3407 | if (cfg80211_get_chandef_type(¶ms->chandef) != |
| 3408 | cfg80211_get_chandef_type(&sdata->u.ibss.chandef)) |
| 3409 | return -EINVAL; |
Gustavo A. R. Silva | aaaee2d | 2020-11-20 12:36:45 -0600 | [diff] [blame] | 3410 | break; |
Michal Kazior | 37fa2bd | 2014-02-28 15:59:06 +0100 | [diff] [blame] | 3411 | case NL80211_CHAN_WIDTH_5: |
| 3412 | case NL80211_CHAN_WIDTH_10: |
| 3413 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 3414 | case NL80211_CHAN_WIDTH_20: |
| 3415 | break; |
| 3416 | default: |
| 3417 | return -EINVAL; |
| 3418 | } |
| 3419 | |
| 3420 | /* changes into another band are not supported */ |
| 3421 | if (sdata->u.ibss.chandef.chan->band != |
| 3422 | params->chandef.chan->band) |
| 3423 | return -EINVAL; |
| 3424 | |
| 3425 | /* see comments in the NL80211_IFTYPE_AP block */ |
| 3426 | if (params->count > 1) { |
| 3427 | err = ieee80211_ibss_csa_beacon(sdata, params); |
| 3428 | if (err < 0) |
| 3429 | return err; |
| 3430 | *changed |= err; |
| 3431 | } |
| 3432 | |
| 3433 | ieee80211_send_action_csa(sdata, params); |
| 3434 | |
| 3435 | break; |
| 3436 | #ifdef CONFIG_MAC80211_MESH |
| 3437 | case NL80211_IFTYPE_MESH_POINT: { |
| 3438 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
| 3439 | |
| 3440 | if (params->chandef.width != sdata->vif.bss_conf.chandef.width) |
| 3441 | return -EINVAL; |
| 3442 | |
| 3443 | /* changes into another band are not supported */ |
| 3444 | if (sdata->vif.bss_conf.chandef.chan->band != |
| 3445 | params->chandef.chan->band) |
| 3446 | return -EINVAL; |
| 3447 | |
| 3448 | if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) { |
| 3449 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT; |
| 3450 | if (!ifmsh->pre_value) |
| 3451 | ifmsh->pre_value = 1; |
| 3452 | else |
| 3453 | ifmsh->pre_value++; |
| 3454 | } |
| 3455 | |
| 3456 | /* see comments in the NL80211_IFTYPE_AP block */ |
| 3457 | if (params->count > 1) { |
| 3458 | err = ieee80211_mesh_csa_beacon(sdata, params); |
| 3459 | if (err < 0) { |
| 3460 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE; |
| 3461 | return err; |
| 3462 | } |
| 3463 | *changed |= err; |
| 3464 | } |
| 3465 | |
| 3466 | if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT) |
| 3467 | ieee80211_send_action_csa(sdata, params); |
| 3468 | |
| 3469 | break; |
| 3470 | } |
| 3471 | #endif |
| 3472 | default: |
| 3473 | return -EOPNOTSUPP; |
| 3474 | } |
| 3475 | |
| 3476 | return 0; |
| 3477 | } |
| 3478 | |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 3479 | static void ieee80211_color_change_abort(struct ieee80211_sub_if_data *sdata) |
| 3480 | { |
| 3481 | sdata->vif.color_change_active = false; |
| 3482 | kfree(sdata->u.ap.next_beacon); |
| 3483 | sdata->u.ap.next_beacon = NULL; |
| 3484 | |
| 3485 | cfg80211_color_change_aborted_notify(sdata->dev); |
| 3486 | } |
| 3487 | |
Luciano Coelho | f29f58a | 2014-05-07 20:05:12 +0300 | [diff] [blame] | 3488 | static int |
| 3489 | __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, |
| 3490 | struct cfg80211_csa_settings *params) |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3491 | { |
| 3492 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3493 | struct ieee80211_local *local = sdata->local; |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 3494 | struct ieee80211_channel_switch ch_switch; |
Michal Kazior | 2b32713 | 2014-04-09 15:29:32 +0200 | [diff] [blame] | 3495 | struct ieee80211_chanctx_conf *conf; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3496 | struct ieee80211_chanctx *chanctx; |
Johannes Berg | b08cc24 | 2014-10-20 21:36:04 +0200 | [diff] [blame] | 3497 | u32 changed = 0; |
| 3498 | int err; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3499 | |
Michal Kazior | dbd7285 | 2014-01-29 07:56:21 +0100 | [diff] [blame] | 3500 | sdata_assert_lock(sdata); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3501 | lockdep_assert_held(&local->mtx); |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 3502 | |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3503 | if (!list_empty(&local->roc_list) || local->scanning) |
| 3504 | return -EBUSY; |
| 3505 | |
| 3506 | if (sdata->wdev.cac_started) |
| 3507 | return -EBUSY; |
| 3508 | |
| 3509 | if (cfg80211_chandef_identical(¶ms->chandef, |
| 3510 | &sdata->vif.bss_conf.chandef)) |
| 3511 | return -EINVAL; |
| 3512 | |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3513 | /* don't allow another channel switch if one is already active. */ |
| 3514 | if (sdata->vif.csa_active) |
| 3515 | return -EBUSY; |
| 3516 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3517 | mutex_lock(&local->chanctx_mtx); |
| 3518 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
| 3519 | lockdep_is_held(&local->chanctx_mtx)); |
| 3520 | if (!conf) { |
| 3521 | err = -EBUSY; |
| 3522 | goto out; |
| 3523 | } |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3524 | |
Thomas Pedersen | b6011960 | 2020-04-01 18:18:04 -0700 | [diff] [blame] | 3525 | if (params->chandef.chan->freq_offset) { |
| 3526 | /* this may work, but is untested */ |
| 3527 | err = -EOPNOTSUPP; |
| 3528 | goto out; |
| 3529 | } |
| 3530 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3531 | chanctx = container_of(conf, struct ieee80211_chanctx, conf); |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3532 | |
Luciano Coelho | 000baa5 | 2014-11-07 15:28:33 +0200 | [diff] [blame] | 3533 | ch_switch.timestamp = 0; |
| 3534 | ch_switch.device_timestamp = 0; |
| 3535 | ch_switch.block_tx = params->block_tx; |
| 3536 | ch_switch.chandef = params->chandef; |
| 3537 | ch_switch.count = params->count; |
| 3538 | |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 3539 | err = drv_pre_channel_switch(sdata, &ch_switch); |
| 3540 | if (err) |
| 3541 | goto out; |
| 3542 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3543 | err = ieee80211_vif_reserve_chanctx(sdata, ¶ms->chandef, |
| 3544 | chanctx->mode, |
| 3545 | params->radar_required); |
| 3546 | if (err) |
| 3547 | goto out; |
| 3548 | |
| 3549 | /* if reservation is invalid then this will fail */ |
| 3550 | err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0); |
| 3551 | if (err) { |
| 3552 | ieee80211_vif_unreserve_chanctx(sdata); |
| 3553 | goto out; |
| 3554 | } |
| 3555 | |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 3556 | /* if there is a color change in progress, abort it */ |
| 3557 | if (sdata->vif.color_change_active) |
| 3558 | ieee80211_color_change_abort(sdata); |
| 3559 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3560 | err = ieee80211_set_csa_beacon(sdata, params, &changed); |
| 3561 | if (err) { |
| 3562 | ieee80211_vif_unreserve_chanctx(sdata); |
| 3563 | goto out; |
| 3564 | } |
| 3565 | |
Luciano Coelho | 33787fc | 2013-11-11 20:34:54 +0200 | [diff] [blame] | 3566 | sdata->csa_chandef = params->chandef; |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3567 | sdata->csa_block_tx = params->block_tx; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3568 | sdata->vif.csa_active = true; |
| 3569 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3570 | if (sdata->csa_block_tx) |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 3571 | ieee80211_stop_vif_queues(local, sdata, |
| 3572 | IEEE80211_QUEUE_STOP_REASON_CSA); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3573 | |
Luciano Coelho | 2f45729 | 2014-11-07 14:31:36 +0200 | [diff] [blame] | 3574 | cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef, |
Johannes Berg | 669b841 | 2020-11-29 17:30:55 +0200 | [diff] [blame] | 3575 | params->count, params->block_tx); |
Luciano Coelho | 2f45729 | 2014-11-07 14:31:36 +0200 | [diff] [blame] | 3576 | |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 3577 | if (changed) { |
| 3578 | ieee80211_bss_info_change_notify(sdata, changed); |
| 3579 | drv_channel_switch_beacon(sdata, ¶ms->chandef); |
| 3580 | } else { |
| 3581 | /* if the beacon didn't change, we can finalize immediately */ |
| 3582 | ieee80211_csa_finalize(sdata); |
| 3583 | } |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3584 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3585 | out: |
| 3586 | mutex_unlock(&local->chanctx_mtx); |
| 3587 | return err; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3588 | } |
| 3589 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3590 | int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, |
| 3591 | struct cfg80211_csa_settings *params) |
| 3592 | { |
| 3593 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3594 | struct ieee80211_local *local = sdata->local; |
| 3595 | int err; |
| 3596 | |
| 3597 | mutex_lock(&local->mtx); |
| 3598 | err = __ieee80211_channel_switch(wiphy, dev, params); |
| 3599 | mutex_unlock(&local->mtx); |
| 3600 | |
| 3601 | return err; |
| 3602 | } |
| 3603 | |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 3604 | u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local) |
| 3605 | { |
| 3606 | lockdep_assert_held(&local->mtx); |
| 3607 | |
| 3608 | local->roc_cookie_counter++; |
| 3609 | |
| 3610 | /* wow, you wrapped 64 bits ... more likely a bug */ |
| 3611 | if (WARN_ON(local->roc_cookie_counter == 0)) |
| 3612 | local->roc_cookie_counter++; |
| 3613 | |
| 3614 | return local->roc_cookie_counter; |
| 3615 | } |
| 3616 | |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 3617 | int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb, |
| 3618 | u64 *cookie, gfp_t gfp) |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3619 | { |
| 3620 | unsigned long spin_flags; |
| 3621 | struct sk_buff *ack_skb; |
| 3622 | int id; |
| 3623 | |
| 3624 | ack_skb = skb_copy(skb, gfp); |
| 3625 | if (!ack_skb) |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 3626 | return -ENOMEM; |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3627 | |
| 3628 | spin_lock_irqsave(&local->ack_status_lock, spin_flags); |
| 3629 | id = idr_alloc(&local->ack_status_frames, ack_skb, |
Johannes Berg | f2b18ba | 2020-01-15 12:25:50 +0100 | [diff] [blame] | 3630 | 1, 0x2000, GFP_ATOMIC); |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3631 | spin_unlock_irqrestore(&local->ack_status_lock, spin_flags); |
| 3632 | |
| 3633 | if (id < 0) { |
| 3634 | kfree_skb(ack_skb); |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 3635 | return -ENOMEM; |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3636 | } |
| 3637 | |
| 3638 | IEEE80211_SKB_CB(skb)->ack_frame_id = id; |
| 3639 | |
| 3640 | *cookie = ieee80211_mgmt_tx_cookie(local); |
| 3641 | IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie; |
| 3642 | |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 3643 | return 0; |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3644 | } |
| 3645 | |
Johannes Berg | 6cd536f | 2020-04-17 12:43:01 +0200 | [diff] [blame] | 3646 | static void |
| 3647 | ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 3648 | struct wireless_dev *wdev, |
Johannes Berg | 6cd536f | 2020-04-17 12:43:01 +0200 | [diff] [blame] | 3649 | struct mgmt_frame_regs *upd) |
Johannes Berg | 7be5086 | 2010-10-13 12:06:24 +0200 | [diff] [blame] | 3650 | { |
| 3651 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Andrei Otcheretianski | 1b09b55 | 2015-08-15 22:39:50 +0300 | [diff] [blame] | 3652 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
Johannes Berg | 6cd536f | 2020-04-17 12:43:01 +0200 | [diff] [blame] | 3653 | u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4); |
Jouni Malinen | 873b1cf | 2020-04-21 17:48:15 +0300 | [diff] [blame] | 3654 | u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4); |
Johannes Berg | 6cd536f | 2020-04-17 12:43:01 +0200 | [diff] [blame] | 3655 | bool global_change, intf_change; |
Johannes Berg | 7be5086 | 2010-10-13 12:06:24 +0200 | [diff] [blame] | 3656 | |
Johannes Berg | 6cd536f | 2020-04-17 12:43:01 +0200 | [diff] [blame] | 3657 | global_change = |
Jouni Malinen | 873b1cf | 2020-04-21 17:48:15 +0300 | [diff] [blame] | 3658 | (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) || |
| 3659 | (local->rx_mcast_action_reg != |
| 3660 | !!(upd->global_mcast_stypes & action_mask)); |
Johannes Berg | 6cd536f | 2020-04-17 12:43:01 +0200 | [diff] [blame] | 3661 | local->probe_req_reg = upd->global_stypes & preq_mask; |
Jouni Malinen | 873b1cf | 2020-04-21 17:48:15 +0300 | [diff] [blame] | 3662 | local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask; |
Andrei Otcheretianski | 1b09b55 | 2015-08-15 22:39:50 +0300 | [diff] [blame] | 3663 | |
Jouni Malinen | 873b1cf | 2020-04-21 17:48:15 +0300 | [diff] [blame] | 3664 | intf_change = (sdata->vif.probe_req_reg != |
| 3665 | !!(upd->interface_stypes & preq_mask)) || |
| 3666 | (sdata->vif.rx_mcast_action_reg != |
| 3667 | !!(upd->interface_mcast_stypes & action_mask)); |
Johannes Berg | 6cd536f | 2020-04-17 12:43:01 +0200 | [diff] [blame] | 3668 | sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask; |
Jouni Malinen | 873b1cf | 2020-04-21 17:48:15 +0300 | [diff] [blame] | 3669 | sdata->vif.rx_mcast_action_reg = |
| 3670 | upd->interface_mcast_stypes & action_mask; |
Johannes Berg | 7be5086 | 2010-10-13 12:06:24 +0200 | [diff] [blame] | 3671 | |
Johannes Berg | 6cd536f | 2020-04-17 12:43:01 +0200 | [diff] [blame] | 3672 | if (!local->open_count) |
| 3673 | return; |
Felix Fietkau | 35f5149 | 2012-10-31 15:50:34 +0100 | [diff] [blame] | 3674 | |
Johannes Berg | 6cd536f | 2020-04-17 12:43:01 +0200 | [diff] [blame] | 3675 | if (intf_change && ieee80211_sdata_running(sdata)) |
| 3676 | drv_config_iface_filter(local, sdata, |
| 3677 | sdata->vif.probe_req_reg ? |
| 3678 | FIF_PROBE_REQ : 0, |
| 3679 | FIF_PROBE_REQ); |
Andrei Otcheretianski | 1b09b55 | 2015-08-15 22:39:50 +0300 | [diff] [blame] | 3680 | |
Johannes Berg | 6cd536f | 2020-04-17 12:43:01 +0200 | [diff] [blame] | 3681 | if (global_change) |
Andrei Otcheretianski | 1b09b55 | 2015-08-15 22:39:50 +0300 | [diff] [blame] | 3682 | ieee80211_configure_filter(local); |
Johannes Berg | 7be5086 | 2010-10-13 12:06:24 +0200 | [diff] [blame] | 3683 | } |
| 3684 | |
Bruno Randolf | 15d9675 | 2010-11-10 12:50:56 +0900 | [diff] [blame] | 3685 | static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant) |
| 3686 | { |
| 3687 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 3688 | |
| 3689 | if (local->started) |
| 3690 | return -EOPNOTSUPP; |
| 3691 | |
| 3692 | return drv_set_antenna(local, tx_ant, rx_ant); |
| 3693 | } |
| 3694 | |
| 3695 | static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant) |
| 3696 | { |
| 3697 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 3698 | |
| 3699 | return drv_get_antenna(local, tx_ant, rx_ant); |
| 3700 | } |
| 3701 | |
Johannes Berg | c68f4b8 | 2011-07-05 16:35:41 +0200 | [diff] [blame] | 3702 | static int ieee80211_set_rekey_data(struct wiphy *wiphy, |
| 3703 | struct net_device *dev, |
| 3704 | struct cfg80211_gtk_rekey_data *data) |
| 3705 | { |
| 3706 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 3707 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3708 | |
| 3709 | if (!local->ops->set_rekey_data) |
| 3710 | return -EOPNOTSUPP; |
| 3711 | |
| 3712 | drv_set_rekey_data(local, sdata, data); |
| 3713 | |
| 3714 | return 0; |
| 3715 | } |
| 3716 | |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3717 | static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev, |
| 3718 | const u8 *peer, u64 *cookie) |
| 3719 | { |
| 3720 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3721 | struct ieee80211_local *local = sdata->local; |
| 3722 | struct ieee80211_qos_hdr *nullfunc; |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 3723 | struct sk_buff *skb; |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3724 | int size = sizeof(*nullfunc); |
| 3725 | __le16 fc; |
| 3726 | bool qos; |
| 3727 | struct ieee80211_tx_info *info; |
| 3728 | struct sta_info *sta; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3729 | struct ieee80211_chanctx_conf *chanctx_conf; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3730 | enum nl80211_band band; |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3731 | int ret; |
| 3732 | |
| 3733 | /* the lock is needed to assign the cookie later */ |
| 3734 | mutex_lock(&local->mtx); |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3735 | |
| 3736 | rcu_read_lock(); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3737 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 3738 | if (WARN_ON(!chanctx_conf)) { |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3739 | ret = -EINVAL; |
| 3740 | goto unlock; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3741 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 3742 | band = chanctx_conf->def.chan->band; |
Felix Fietkau | 03bb7f4 | 2013-09-29 21:39:33 +0200 | [diff] [blame] | 3743 | sta = sta_info_get_bss(sdata, peer); |
Johannes Berg | b4487c2 | 2011-11-11 20:22:30 +0100 | [diff] [blame] | 3744 | if (sta) { |
Johannes Berg | a74a8c8 | 2014-07-22 14:50:47 +0200 | [diff] [blame] | 3745 | qos = sta->sta.wme; |
Johannes Berg | b4487c2 | 2011-11-11 20:22:30 +0100 | [diff] [blame] | 3746 | } else { |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3747 | ret = -ENOLINK; |
| 3748 | goto unlock; |
Johannes Berg | b4487c2 | 2011-11-11 20:22:30 +0100 | [diff] [blame] | 3749 | } |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3750 | |
| 3751 | if (qos) { |
| 3752 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 3753 | IEEE80211_STYPE_QOS_NULLFUNC | |
| 3754 | IEEE80211_FCTL_FROMDS); |
| 3755 | } else { |
| 3756 | size -= 2; |
| 3757 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 3758 | IEEE80211_STYPE_NULLFUNC | |
| 3759 | IEEE80211_FCTL_FROMDS); |
| 3760 | } |
| 3761 | |
| 3762 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + size); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3763 | if (!skb) { |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3764 | ret = -ENOMEM; |
| 3765 | goto unlock; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3766 | } |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3767 | |
| 3768 | skb->dev = dev; |
| 3769 | |
| 3770 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 3771 | |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 3772 | nullfunc = skb_put(skb, size); |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3773 | nullfunc->frame_control = fc; |
| 3774 | nullfunc->duration_id = 0; |
| 3775 | memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); |
| 3776 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); |
| 3777 | memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN); |
| 3778 | nullfunc->seq_ctrl = 0; |
| 3779 | |
| 3780 | info = IEEE80211_SKB_CB(skb); |
| 3781 | |
| 3782 | info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 3783 | IEEE80211_TX_INTFL_NL80211_FRAME_TX; |
Johannes Berg | 73c4e19 | 2014-11-09 18:50:09 +0200 | [diff] [blame] | 3784 | info->band = band; |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3785 | |
| 3786 | skb_set_queue_mapping(skb, IEEE80211_AC_VO); |
| 3787 | skb->priority = 7; |
| 3788 | if (qos) |
| 3789 | nullfunc->qos_ctrl = cpu_to_le16(7); |
| 3790 | |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 3791 | ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC); |
| 3792 | if (ret) { |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3793 | kfree_skb(skb); |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3794 | goto unlock; |
| 3795 | } |
| 3796 | |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3797 | local_bh_disable(); |
Mathy Vanhoef | 08aca29 | 2020-07-23 14:01:52 +0400 | [diff] [blame] | 3798 | ieee80211_xmit(sdata, sta, skb); |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3799 | local_bh_enable(); |
| 3800 | |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3801 | ret = 0; |
| 3802 | unlock: |
| 3803 | rcu_read_unlock(); |
| 3804 | mutex_unlock(&local->mtx); |
| 3805 | |
| 3806 | return ret; |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3807 | } |
| 3808 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3809 | static int ieee80211_cfg_get_channel(struct wiphy *wiphy, |
| 3810 | struct wireless_dev *wdev, |
| 3811 | struct cfg80211_chan_def *chandef) |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3812 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3813 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
Felix Fietkau | cb601ff | 2013-02-23 19:02:14 +0100 | [diff] [blame] | 3814 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3815 | struct ieee80211_chanctx_conf *chanctx_conf; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3816 | int ret = -ENODATA; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3817 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3818 | rcu_read_lock(); |
Johannes Berg | feda302 | 2013-02-28 09:59:22 +0100 | [diff] [blame] | 3819 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 3820 | if (chanctx_conf) { |
Luciano Coelho | c12bc48 | 2014-09-30 07:08:02 +0300 | [diff] [blame] | 3821 | *chandef = sdata->vif.bss_conf.chandef; |
Johannes Berg | feda302 | 2013-02-28 09:59:22 +0100 | [diff] [blame] | 3822 | ret = 0; |
| 3823 | } else if (local->open_count > 0 && |
| 3824 | local->open_count == local->monitors && |
| 3825 | sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
| 3826 | if (local->use_chanctx) |
| 3827 | *chandef = local->monitor_chandef; |
| 3828 | else |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 3829 | *chandef = local->_oper_chandef; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3830 | ret = 0; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3831 | } |
| 3832 | rcu_read_unlock(); |
| 3833 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3834 | return ret; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3835 | } |
| 3836 | |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 3837 | #ifdef CONFIG_PM |
| 3838 | static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled) |
| 3839 | { |
| 3840 | drv_set_wakeup(wiphy_priv(wiphy), enabled); |
| 3841 | } |
| 3842 | #endif |
| 3843 | |
Kyeyoon Park | 32db6b5 | 2013-12-16 23:04:43 -0800 | [diff] [blame] | 3844 | static int ieee80211_set_qos_map(struct wiphy *wiphy, |
| 3845 | struct net_device *dev, |
| 3846 | struct cfg80211_qos_map *qos_map) |
| 3847 | { |
| 3848 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3849 | struct mac80211_qos_map *new_qos_map, *old_qos_map; |
| 3850 | |
| 3851 | if (qos_map) { |
| 3852 | new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL); |
| 3853 | if (!new_qos_map) |
| 3854 | return -ENOMEM; |
| 3855 | memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map)); |
| 3856 | } else { |
| 3857 | /* A NULL qos_map was passed to disable QoS mapping */ |
| 3858 | new_qos_map = NULL; |
| 3859 | } |
| 3860 | |
Johannes Berg | 194ff52 | 2013-12-30 23:12:37 +0100 | [diff] [blame] | 3861 | old_qos_map = sdata_dereference(sdata->qos_map, sdata); |
Kyeyoon Park | 32db6b5 | 2013-12-16 23:04:43 -0800 | [diff] [blame] | 3862 | rcu_assign_pointer(sdata->qos_map, new_qos_map); |
| 3863 | if (old_qos_map) |
| 3864 | kfree_rcu(old_qos_map, rcu_head); |
| 3865 | |
| 3866 | return 0; |
| 3867 | } |
| 3868 | |
Jouni Malinen | 3b1700b | 2014-04-28 11:22:25 +0300 | [diff] [blame] | 3869 | static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy, |
| 3870 | struct net_device *dev, |
| 3871 | struct cfg80211_chan_def *chandef) |
| 3872 | { |
| 3873 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3874 | int ret; |
| 3875 | u32 changed = 0; |
| 3876 | |
| 3877 | ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed); |
| 3878 | if (ret == 0) |
| 3879 | ieee80211_bss_info_change_notify(sdata, changed); |
| 3880 | |
| 3881 | return ret; |
| 3882 | } |
| 3883 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 3884 | static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev, |
| 3885 | u8 tsid, const u8 *peer, u8 up, |
| 3886 | u16 admitted_time) |
| 3887 | { |
| 3888 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3889 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3890 | int ac = ieee802_1d_to_ac[up]; |
| 3891 | |
| 3892 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 3893 | return -EOPNOTSUPP; |
| 3894 | |
| 3895 | if (!(sdata->wmm_acm & BIT(up))) |
| 3896 | return -EINVAL; |
| 3897 | |
| 3898 | if (ifmgd->tx_tspec[ac].admitted_time) |
| 3899 | return -EBUSY; |
| 3900 | |
| 3901 | if (admitted_time) { |
| 3902 | ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time; |
| 3903 | ifmgd->tx_tspec[ac].tsid = tsid; |
| 3904 | ifmgd->tx_tspec[ac].up = up; |
| 3905 | } |
| 3906 | |
| 3907 | return 0; |
| 3908 | } |
| 3909 | |
| 3910 | static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev, |
| 3911 | u8 tsid, const u8 *peer) |
| 3912 | { |
| 3913 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3914 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3915 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 3916 | int ac; |
| 3917 | |
| 3918 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 3919 | struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; |
| 3920 | |
| 3921 | /* skip unused entries */ |
| 3922 | if (!tx_tspec->admitted_time) |
| 3923 | continue; |
| 3924 | |
| 3925 | if (tx_tspec->tsid != tsid) |
| 3926 | continue; |
| 3927 | |
| 3928 | /* due to this new packets will be reassigned to non-ACM ACs */ |
| 3929 | tx_tspec->up = -1; |
| 3930 | |
| 3931 | /* Make sure that all packets have been sent to avoid to |
| 3932 | * restore the QoS params on packets that are still on the |
| 3933 | * queues. |
| 3934 | */ |
| 3935 | synchronize_net(); |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 3936 | ieee80211_flush_queues(local, sdata, false); |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 3937 | |
| 3938 | /* restore the normal QoS parameters |
| 3939 | * (unconditionally to avoid races) |
| 3940 | */ |
| 3941 | tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE; |
| 3942 | tx_tspec->downgraded = false; |
| 3943 | ieee80211_sta_handle_tspec_ac_params(sdata); |
| 3944 | |
| 3945 | /* finally clear all the data */ |
| 3946 | memset(tx_tspec, 0, sizeof(*tx_tspec)); |
| 3947 | |
| 3948 | return 0; |
| 3949 | } |
| 3950 | |
| 3951 | return -ENOENT; |
| 3952 | } |
| 3953 | |
Ayala Beker | 167e33f | 2016-09-20 17:31:20 +0300 | [diff] [blame] | 3954 | void ieee80211_nan_func_terminated(struct ieee80211_vif *vif, |
| 3955 | u8 inst_id, |
| 3956 | enum nl80211_nan_func_term_reason reason, |
| 3957 | gfp_t gfp) |
| 3958 | { |
| 3959 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 3960 | struct cfg80211_nan_func *func; |
| 3961 | u64 cookie; |
| 3962 | |
| 3963 | if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) |
| 3964 | return; |
| 3965 | |
| 3966 | spin_lock_bh(&sdata->u.nan.func_lock); |
| 3967 | |
| 3968 | func = idr_find(&sdata->u.nan.function_inst_ids, inst_id); |
| 3969 | if (WARN_ON(!func)) { |
| 3970 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 3971 | return; |
| 3972 | } |
| 3973 | |
| 3974 | cookie = func->cookie; |
| 3975 | idr_remove(&sdata->u.nan.function_inst_ids, inst_id); |
| 3976 | |
| 3977 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 3978 | |
| 3979 | cfg80211_free_nan_func(func); |
| 3980 | |
| 3981 | cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id, |
| 3982 | reason, cookie, gfp); |
| 3983 | } |
| 3984 | EXPORT_SYMBOL(ieee80211_nan_func_terminated); |
| 3985 | |
Ayala Beker | 92bc43b | 2016-09-20 17:31:21 +0300 | [diff] [blame] | 3986 | void ieee80211_nan_func_match(struct ieee80211_vif *vif, |
| 3987 | struct cfg80211_nan_match_params *match, |
| 3988 | gfp_t gfp) |
| 3989 | { |
| 3990 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 3991 | struct cfg80211_nan_func *func; |
| 3992 | |
| 3993 | if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) |
| 3994 | return; |
| 3995 | |
| 3996 | spin_lock_bh(&sdata->u.nan.func_lock); |
| 3997 | |
| 3998 | func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id); |
| 3999 | if (WARN_ON(!func)) { |
| 4000 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 4001 | return; |
| 4002 | } |
| 4003 | match->cookie = func->cookie; |
| 4004 | |
| 4005 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 4006 | |
| 4007 | cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp); |
| 4008 | } |
| 4009 | EXPORT_SYMBOL(ieee80211_nan_func_match); |
| 4010 | |
Michael Braun | ebceec8 | 2016-11-22 11:52:18 +0100 | [diff] [blame] | 4011 | static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy, |
| 4012 | struct net_device *dev, |
| 4013 | const bool enabled) |
| 4014 | { |
| 4015 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 4016 | |
| 4017 | sdata->u.ap.multicast_to_unicast = enabled; |
| 4018 | |
| 4019 | return 0; |
| 4020 | } |
| 4021 | |
Toke Høiland-Jørgensen | 2fe4a29 | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 4022 | void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats, |
| 4023 | struct txq_info *txqi) |
| 4024 | { |
| 4025 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) { |
| 4026 | txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES); |
| 4027 | txqstats->backlog_bytes = txqi->tin.backlog_bytes; |
| 4028 | } |
| 4029 | |
| 4030 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) { |
| 4031 | txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS); |
| 4032 | txqstats->backlog_packets = txqi->tin.backlog_packets; |
| 4033 | } |
| 4034 | |
| 4035 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) { |
| 4036 | txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS); |
| 4037 | txqstats->flows = txqi->tin.flows; |
| 4038 | } |
| 4039 | |
| 4040 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) { |
| 4041 | txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS); |
| 4042 | txqstats->drops = txqi->cstats.drop_count; |
| 4043 | } |
| 4044 | |
| 4045 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) { |
| 4046 | txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS); |
| 4047 | txqstats->ecn_marks = txqi->cstats.ecn_mark; |
| 4048 | } |
| 4049 | |
| 4050 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) { |
| 4051 | txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT); |
| 4052 | txqstats->overlimit = txqi->tin.overlimit; |
| 4053 | } |
| 4054 | |
| 4055 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) { |
| 4056 | txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS); |
| 4057 | txqstats->collisions = txqi->tin.collisions; |
| 4058 | } |
| 4059 | |
| 4060 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) { |
| 4061 | txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES); |
| 4062 | txqstats->tx_bytes = txqi->tin.tx_bytes; |
| 4063 | } |
| 4064 | |
| 4065 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) { |
| 4066 | txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS); |
| 4067 | txqstats->tx_packets = txqi->tin.tx_packets; |
| 4068 | } |
| 4069 | } |
| 4070 | |
| 4071 | static int ieee80211_get_txq_stats(struct wiphy *wiphy, |
| 4072 | struct wireless_dev *wdev, |
| 4073 | struct cfg80211_txq_stats *txqstats) |
| 4074 | { |
| 4075 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 4076 | struct ieee80211_sub_if_data *sdata; |
| 4077 | int ret = 0; |
| 4078 | |
| 4079 | if (!local->ops->wake_tx_queue) |
| 4080 | return 1; |
| 4081 | |
| 4082 | spin_lock_bh(&local->fq.lock); |
| 4083 | rcu_read_lock(); |
| 4084 | |
| 4085 | if (wdev) { |
| 4086 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 4087 | if (!sdata->vif.txq) { |
| 4088 | ret = 1; |
| 4089 | goto out; |
| 4090 | } |
| 4091 | ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq)); |
| 4092 | } else { |
| 4093 | /* phy stats */ |
| 4094 | txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) | |
| 4095 | BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) | |
| 4096 | BIT(NL80211_TXQ_STATS_OVERLIMIT) | |
| 4097 | BIT(NL80211_TXQ_STATS_OVERMEMORY) | |
| 4098 | BIT(NL80211_TXQ_STATS_COLLISIONS) | |
| 4099 | BIT(NL80211_TXQ_STATS_MAX_FLOWS); |
| 4100 | txqstats->backlog_packets = local->fq.backlog; |
| 4101 | txqstats->backlog_bytes = local->fq.memory_usage; |
| 4102 | txqstats->overlimit = local->fq.overlimit; |
| 4103 | txqstats->overmemory = local->fq.overmemory; |
| 4104 | txqstats->collisions = local->fq.collisions; |
| 4105 | txqstats->max_flows = local->fq.flows_cnt; |
| 4106 | } |
| 4107 | |
| 4108 | out: |
| 4109 | rcu_read_unlock(); |
| 4110 | spin_unlock_bh(&local->fq.lock); |
| 4111 | |
| 4112 | return ret; |
| 4113 | } |
| 4114 | |
Pradeep Kumar Chitrapu | bc84797 | 2018-10-03 20:19:20 -0700 | [diff] [blame] | 4115 | static int |
| 4116 | ieee80211_get_ftm_responder_stats(struct wiphy *wiphy, |
| 4117 | struct net_device *dev, |
| 4118 | struct cfg80211_ftm_responder_stats *ftm_stats) |
| 4119 | { |
| 4120 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 4121 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 4122 | |
| 4123 | return drv_get_ftm_responder_stats(local, sdata, ftm_stats); |
| 4124 | } |
| 4125 | |
Johannes Berg | cee7013 | 2018-10-16 11:24:47 +0200 | [diff] [blame] | 4126 | static int |
| 4127 | ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev, |
| 4128 | struct cfg80211_pmsr_request *request) |
| 4129 | { |
| 4130 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 4131 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev); |
| 4132 | |
| 4133 | return drv_start_pmsr(local, sdata, request); |
| 4134 | } |
| 4135 | |
| 4136 | static void |
| 4137 | ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev, |
| 4138 | struct cfg80211_pmsr_request *request) |
| 4139 | { |
| 4140 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 4141 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev); |
| 4142 | |
| 4143 | return drv_abort_pmsr(local, sdata, request); |
| 4144 | } |
| 4145 | |
Tamizh chelvam | 370f51d | 2020-01-20 13:21:27 +0530 | [diff] [blame] | 4146 | static int ieee80211_set_tid_config(struct wiphy *wiphy, |
| 4147 | struct net_device *dev, |
| 4148 | struct cfg80211_tid_config *tid_conf) |
| 4149 | { |
| 4150 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 4151 | struct sta_info *sta; |
| 4152 | int ret; |
| 4153 | |
| 4154 | if (!sdata->local->ops->set_tid_config) |
| 4155 | return -EOPNOTSUPP; |
| 4156 | |
| 4157 | if (!tid_conf->peer) |
| 4158 | return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf); |
| 4159 | |
| 4160 | mutex_lock(&sdata->local->sta_mtx); |
| 4161 | sta = sta_info_get_bss(sdata, tid_conf->peer); |
| 4162 | if (!sta) { |
| 4163 | mutex_unlock(&sdata->local->sta_mtx); |
| 4164 | return -ENOENT; |
| 4165 | } |
| 4166 | |
| 4167 | ret = drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf); |
| 4168 | mutex_unlock(&sdata->local->sta_mtx); |
| 4169 | |
| 4170 | return ret; |
| 4171 | } |
| 4172 | |
| 4173 | static int ieee80211_reset_tid_config(struct wiphy *wiphy, |
| 4174 | struct net_device *dev, |
Sergey Matyukevich | 60c2ef0 | 2020-04-24 14:29:02 +0300 | [diff] [blame] | 4175 | const u8 *peer, u8 tids) |
Tamizh chelvam | 370f51d | 2020-01-20 13:21:27 +0530 | [diff] [blame] | 4176 | { |
| 4177 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 4178 | struct sta_info *sta; |
| 4179 | int ret; |
| 4180 | |
| 4181 | if (!sdata->local->ops->reset_tid_config) |
| 4182 | return -EOPNOTSUPP; |
| 4183 | |
| 4184 | if (!peer) |
Sergey Matyukevich | 60c2ef0 | 2020-04-24 14:29:02 +0300 | [diff] [blame] | 4185 | return drv_reset_tid_config(sdata->local, sdata, NULL, tids); |
Tamizh chelvam | 370f51d | 2020-01-20 13:21:27 +0530 | [diff] [blame] | 4186 | |
| 4187 | mutex_lock(&sdata->local->sta_mtx); |
| 4188 | sta = sta_info_get_bss(sdata, peer); |
| 4189 | if (!sta) { |
| 4190 | mutex_unlock(&sdata->local->sta_mtx); |
| 4191 | return -ENOENT; |
| 4192 | } |
| 4193 | |
Sergey Matyukevich | 60c2ef0 | 2020-04-24 14:29:02 +0300 | [diff] [blame] | 4194 | ret = drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids); |
Tamizh chelvam | 370f51d | 2020-01-20 13:21:27 +0530 | [diff] [blame] | 4195 | mutex_unlock(&sdata->local->sta_mtx); |
| 4196 | |
| 4197 | return ret; |
| 4198 | } |
| 4199 | |
Carl Huang | c534e09 | 2020-12-03 05:37:27 -0500 | [diff] [blame] | 4200 | static int ieee80211_set_sar_specs(struct wiphy *wiphy, |
| 4201 | struct cfg80211_sar_specs *sar) |
| 4202 | { |
| 4203 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 4204 | |
| 4205 | if (!local->ops->set_sar_specs) |
| 4206 | return -EOPNOTSUPP; |
| 4207 | |
| 4208 | return local->ops->set_sar_specs(&local->hw, sar); |
| 4209 | } |
| 4210 | |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 4211 | static int |
| 4212 | ieee80211_set_after_color_change_beacon(struct ieee80211_sub_if_data *sdata, |
| 4213 | u32 *changed) |
| 4214 | { |
| 4215 | switch (sdata->vif.type) { |
| 4216 | case NL80211_IFTYPE_AP: { |
| 4217 | int ret; |
| 4218 | |
| 4219 | ret = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon, |
| 4220 | NULL, NULL); |
| 4221 | kfree(sdata->u.ap.next_beacon); |
| 4222 | sdata->u.ap.next_beacon = NULL; |
| 4223 | |
| 4224 | if (ret < 0) |
| 4225 | return ret; |
| 4226 | |
| 4227 | *changed |= ret; |
| 4228 | break; |
| 4229 | } |
| 4230 | default: |
| 4231 | WARN_ON_ONCE(1); |
| 4232 | return -EINVAL; |
| 4233 | } |
| 4234 | |
| 4235 | return 0; |
| 4236 | } |
| 4237 | |
| 4238 | static int |
| 4239 | ieee80211_set_color_change_beacon(struct ieee80211_sub_if_data *sdata, |
| 4240 | struct cfg80211_color_change_settings *params, |
| 4241 | u32 *changed) |
| 4242 | { |
| 4243 | struct ieee80211_color_change_settings color_change = {}; |
| 4244 | int err; |
| 4245 | |
| 4246 | switch (sdata->vif.type) { |
| 4247 | case NL80211_IFTYPE_AP: |
| 4248 | sdata->u.ap.next_beacon = |
| 4249 | cfg80211_beacon_dup(¶ms->beacon_next); |
| 4250 | if (!sdata->u.ap.next_beacon) |
| 4251 | return -ENOMEM; |
| 4252 | |
| 4253 | if (params->count <= 1) |
| 4254 | break; |
| 4255 | |
| 4256 | color_change.counter_offset_beacon = |
| 4257 | params->counter_offset_beacon; |
| 4258 | color_change.counter_offset_presp = |
| 4259 | params->counter_offset_presp; |
| 4260 | color_change.count = params->count; |
| 4261 | |
| 4262 | err = ieee80211_assign_beacon(sdata, ¶ms->beacon_color_change, |
| 4263 | NULL, &color_change); |
| 4264 | if (err < 0) { |
| 4265 | kfree(sdata->u.ap.next_beacon); |
| 4266 | return err; |
| 4267 | } |
| 4268 | *changed |= err; |
| 4269 | break; |
| 4270 | default: |
| 4271 | return -EOPNOTSUPP; |
| 4272 | } |
| 4273 | |
| 4274 | return 0; |
| 4275 | } |
| 4276 | |
| 4277 | static void |
| 4278 | ieee80211_color_change_bss_config_notify(struct ieee80211_sub_if_data *sdata, |
| 4279 | u8 color, int enable, u32 changed) |
| 4280 | { |
| 4281 | sdata->vif.bss_conf.he_bss_color.color = color; |
| 4282 | sdata->vif.bss_conf.he_bss_color.enabled = enable; |
| 4283 | changed |= BSS_CHANGED_HE_BSS_COLOR; |
| 4284 | |
| 4285 | ieee80211_bss_info_change_notify(sdata, changed); |
John Crispin | eb87d3e | 2021-11-17 16:27:27 +0530 | [diff] [blame] | 4286 | |
| 4287 | if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) { |
| 4288 | struct ieee80211_sub_if_data *child; |
| 4289 | |
| 4290 | mutex_lock(&sdata->local->iflist_mtx); |
| 4291 | list_for_each_entry(child, &sdata->local->interfaces, list) { |
| 4292 | if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) { |
| 4293 | child->vif.bss_conf.he_bss_color.color = color; |
| 4294 | child->vif.bss_conf.he_bss_color.enabled = enable; |
| 4295 | ieee80211_bss_info_change_notify(child, |
| 4296 | BSS_CHANGED_HE_BSS_COLOR); |
| 4297 | } |
| 4298 | } |
| 4299 | mutex_unlock(&sdata->local->iflist_mtx); |
| 4300 | } |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 4301 | } |
| 4302 | |
| 4303 | static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata) |
| 4304 | { |
| 4305 | struct ieee80211_local *local = sdata->local; |
| 4306 | u32 changed = 0; |
| 4307 | int err; |
| 4308 | |
| 4309 | sdata_assert_lock(sdata); |
| 4310 | lockdep_assert_held(&local->mtx); |
| 4311 | |
| 4312 | sdata->vif.color_change_active = false; |
| 4313 | |
| 4314 | err = ieee80211_set_after_color_change_beacon(sdata, &changed); |
| 4315 | if (err) { |
| 4316 | cfg80211_color_change_aborted_notify(sdata->dev); |
| 4317 | return err; |
| 4318 | } |
| 4319 | |
| 4320 | ieee80211_color_change_bss_config_notify(sdata, |
| 4321 | sdata->vif.color_change_color, |
| 4322 | 1, changed); |
| 4323 | cfg80211_color_change_notify(sdata->dev); |
| 4324 | |
| 4325 | return 0; |
| 4326 | } |
| 4327 | |
| 4328 | void ieee80211_color_change_finalize_work(struct work_struct *work) |
| 4329 | { |
| 4330 | struct ieee80211_sub_if_data *sdata = |
| 4331 | container_of(work, struct ieee80211_sub_if_data, |
| 4332 | color_change_finalize_work); |
| 4333 | struct ieee80211_local *local = sdata->local; |
| 4334 | |
| 4335 | sdata_lock(sdata); |
| 4336 | mutex_lock(&local->mtx); |
| 4337 | |
| 4338 | /* AP might have been stopped while waiting for the lock. */ |
| 4339 | if (!sdata->vif.color_change_active) |
| 4340 | goto unlock; |
| 4341 | |
| 4342 | if (!ieee80211_sdata_running(sdata)) |
| 4343 | goto unlock; |
| 4344 | |
| 4345 | ieee80211_color_change_finalize(sdata); |
| 4346 | |
| 4347 | unlock: |
| 4348 | mutex_unlock(&local->mtx); |
| 4349 | sdata_unlock(sdata); |
| 4350 | } |
| 4351 | |
| 4352 | void ieee80211_color_change_finish(struct ieee80211_vif *vif) |
| 4353 | { |
| 4354 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 4355 | |
| 4356 | ieee80211_queue_work(&sdata->local->hw, |
| 4357 | &sdata->color_change_finalize_work); |
| 4358 | } |
| 4359 | EXPORT_SYMBOL_GPL(ieee80211_color_change_finish); |
| 4360 | |
| 4361 | void |
| 4362 | ieeee80211_obss_color_collision_notify(struct ieee80211_vif *vif, |
| 4363 | u64 color_bitmap) |
| 4364 | { |
| 4365 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 4366 | |
| 4367 | if (sdata->vif.color_change_active || sdata->vif.csa_active) |
| 4368 | return; |
| 4369 | |
| 4370 | cfg80211_obss_color_collision_notify(sdata->dev, color_bitmap); |
| 4371 | } |
| 4372 | EXPORT_SYMBOL_GPL(ieeee80211_obss_color_collision_notify); |
| 4373 | |
| 4374 | static int |
| 4375 | ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev, |
| 4376 | struct cfg80211_color_change_settings *params) |
| 4377 | { |
| 4378 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 4379 | struct ieee80211_local *local = sdata->local; |
| 4380 | u32 changed = 0; |
| 4381 | int err; |
| 4382 | |
| 4383 | sdata_assert_lock(sdata); |
| 4384 | |
John Crispin | eb87d3e | 2021-11-17 16:27:27 +0530 | [diff] [blame] | 4385 | if (sdata->vif.bss_conf.nontransmitted) |
| 4386 | return -EINVAL; |
| 4387 | |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 4388 | mutex_lock(&local->mtx); |
| 4389 | |
| 4390 | /* don't allow another color change if one is already active or if csa |
| 4391 | * is active |
| 4392 | */ |
| 4393 | if (sdata->vif.color_change_active || sdata->vif.csa_active) { |
| 4394 | err = -EBUSY; |
| 4395 | goto out; |
| 4396 | } |
| 4397 | |
| 4398 | err = ieee80211_set_color_change_beacon(sdata, params, &changed); |
| 4399 | if (err) |
| 4400 | goto out; |
| 4401 | |
| 4402 | sdata->vif.color_change_active = true; |
| 4403 | sdata->vif.color_change_color = params->color; |
| 4404 | |
| 4405 | cfg80211_color_change_started_notify(sdata->dev, params->count); |
| 4406 | |
| 4407 | if (changed) |
| 4408 | ieee80211_color_change_bss_config_notify(sdata, 0, 0, changed); |
| 4409 | else |
| 4410 | /* if the beacon didn't change, we can finalize immediately */ |
| 4411 | ieee80211_color_change_finalize(sdata); |
| 4412 | |
| 4413 | out: |
| 4414 | mutex_unlock(&local->mtx); |
| 4415 | |
| 4416 | return err; |
| 4417 | } |
| 4418 | |
Lorenzo Bianconi | 237337c2 | 2021-10-23 11:10:51 +0200 | [diff] [blame] | 4419 | static int |
Lorenzo Bianconi | a95bfb8 | 2021-11-29 14:11:24 +0100 | [diff] [blame] | 4420 | ieee80211_set_radar_background(struct wiphy *wiphy, |
| 4421 | struct cfg80211_chan_def *chandef) |
Lorenzo Bianconi | 237337c2 | 2021-10-23 11:10:51 +0200 | [diff] [blame] | 4422 | { |
| 4423 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 4424 | |
Lorenzo Bianconi | a95bfb8 | 2021-11-29 14:11:24 +0100 | [diff] [blame] | 4425 | if (!local->ops->set_radar_background) |
Lorenzo Bianconi | 237337c2 | 2021-10-23 11:10:51 +0200 | [diff] [blame] | 4426 | return -EOPNOTSUPP; |
| 4427 | |
Lorenzo Bianconi | a95bfb8 | 2021-11-29 14:11:24 +0100 | [diff] [blame] | 4428 | return local->ops->set_radar_background(&local->hw, chandef); |
Lorenzo Bianconi | 237337c2 | 2021-10-23 11:10:51 +0200 | [diff] [blame] | 4429 | } |
| 4430 | |
Johannes Berg | 8a47cea | 2014-01-20 23:55:44 +0100 | [diff] [blame] | 4431 | const struct cfg80211_ops mac80211_config_ops = { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4432 | .add_virtual_intf = ieee80211_add_iface, |
| 4433 | .del_virtual_intf = ieee80211_del_iface, |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 4434 | .change_virtual_intf = ieee80211_change_iface, |
Johannes Berg | f142c6b | 2012-06-18 20:07:15 +0200 | [diff] [blame] | 4435 | .start_p2p_device = ieee80211_start_p2p_device, |
| 4436 | .stop_p2p_device = ieee80211_stop_p2p_device, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 4437 | .add_key = ieee80211_add_key, |
| 4438 | .del_key = ieee80211_del_key, |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 4439 | .get_key = ieee80211_get_key, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 4440 | .set_default_key = ieee80211_config_default_key, |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 4441 | .set_default_mgmt_key = ieee80211_config_default_mgmt_key, |
Jouni Malinen | e5473e8 | 2020-02-22 15:25:44 +0200 | [diff] [blame] | 4442 | .set_default_beacon_key = ieee80211_config_default_beacon_key, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4443 | .start_ap = ieee80211_start_ap, |
| 4444 | .change_beacon = ieee80211_change_beacon, |
| 4445 | .stop_ap = ieee80211_stop_ap, |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 4446 | .add_station = ieee80211_add_station, |
| 4447 | .del_station = ieee80211_del_station, |
| 4448 | .change_station = ieee80211_change_station, |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 4449 | .get_station = ieee80211_get_station, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 4450 | .dump_station = ieee80211_dump_station, |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 4451 | .dump_survey = ieee80211_dump_survey, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 4452 | #ifdef CONFIG_MAC80211_MESH |
| 4453 | .add_mpath = ieee80211_add_mpath, |
| 4454 | .del_mpath = ieee80211_del_mpath, |
| 4455 | .change_mpath = ieee80211_change_mpath, |
| 4456 | .get_mpath = ieee80211_get_mpath, |
| 4457 | .dump_mpath = ieee80211_dump_mpath, |
Henning Rogge | a2db2ed | 2014-09-12 08:58:50 +0200 | [diff] [blame] | 4458 | .get_mpp = ieee80211_get_mpp, |
| 4459 | .dump_mpp = ieee80211_dump_mpp, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4460 | .update_mesh_config = ieee80211_update_mesh_config, |
| 4461 | .get_mesh_config = ieee80211_get_mesh_config, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4462 | .join_mesh = ieee80211_join_mesh, |
| 4463 | .leave_mesh = ieee80211_leave_mesh, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 4464 | #endif |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 4465 | .join_ocb = ieee80211_join_ocb, |
| 4466 | .leave_ocb = ieee80211_leave_ocb, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4467 | .change_bss = ieee80211_change_bss, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 4468 | .set_txq_params = ieee80211_set_txq_params, |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 4469 | .set_monitor_channel = ieee80211_set_monitor_channel, |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 4470 | .suspend = ieee80211_suspend, |
| 4471 | .resume = ieee80211_resume, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4472 | .scan = ieee80211_scan, |
Vidyullatha Kanchanapally | 91f123f | 2015-10-30 19:14:50 +0530 | [diff] [blame] | 4473 | .abort_scan = ieee80211_abort_scan, |
Luciano Coelho | 79f460c | 2011-05-11 17:09:36 +0300 | [diff] [blame] | 4474 | .sched_scan_start = ieee80211_sched_scan_start, |
| 4475 | .sched_scan_stop = ieee80211_sched_scan_stop, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4476 | .auth = ieee80211_auth, |
| 4477 | .assoc = ieee80211_assoc, |
| 4478 | .deauth = ieee80211_deauth, |
| 4479 | .disassoc = ieee80211_disassoc, |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 4480 | .join_ibss = ieee80211_join_ibss, |
| 4481 | .leave_ibss = ieee80211_leave_ibss, |
Antonio Quartulli | 391e53e | 2012-11-02 13:27:49 +0100 | [diff] [blame] | 4482 | .set_mcast_rate = ieee80211_set_mcast_rate, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 4483 | .set_wiphy_params = ieee80211_set_wiphy_params, |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 4484 | .set_tx_power = ieee80211_set_tx_power, |
| 4485 | .get_tx_power = ieee80211_get_tx_power, |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 4486 | .rfkill_poll = ieee80211_rfkill_poll, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4487 | CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd) |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4488 | CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump) |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 4489 | .set_power_mgmt = ieee80211_set_power_mgmt, |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 4490 | .set_bitrate_mask = ieee80211_set_bitrate_mask, |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 4491 | .remain_on_channel = ieee80211_remain_on_channel, |
| 4492 | .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4493 | .mgmt_tx = ieee80211_mgmt_tx, |
Johannes Berg | f30221e | 2010-11-25 10:02:30 +0100 | [diff] [blame] | 4494 | .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait, |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 4495 | .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config, |
Andrew Zaborowski | 2c3c5f8c | 2017-02-10 04:50:22 +0100 | [diff] [blame] | 4496 | .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config, |
Johannes Berg | 6cd536f | 2020-04-17 12:43:01 +0200 | [diff] [blame] | 4497 | .update_mgmt_frame_registrations = |
| 4498 | ieee80211_update_mgmt_frame_registrations, |
Bruno Randolf | 15d9675 | 2010-11-10 12:50:56 +0900 | [diff] [blame] | 4499 | .set_antenna = ieee80211_set_antenna, |
| 4500 | .get_antenna = ieee80211_get_antenna, |
Johannes Berg | c68f4b8 | 2011-07-05 16:35:41 +0200 | [diff] [blame] | 4501 | .set_rekey_data = ieee80211_set_rekey_data, |
Arik Nemtsov | dfe018b | 2011-09-28 14:12:52 +0300 | [diff] [blame] | 4502 | .tdls_oper = ieee80211_tdls_oper, |
| 4503 | .tdls_mgmt = ieee80211_tdls_mgmt, |
Arik Nemtsov | a7a6bdd | 2014-11-09 18:50:19 +0200 | [diff] [blame] | 4504 | .tdls_channel_switch = ieee80211_tdls_channel_switch, |
| 4505 | .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch, |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 4506 | .probe_client = ieee80211_probe_client, |
Simon Wunderlich | b53be79 | 2011-11-18 14:20:44 +0100 | [diff] [blame] | 4507 | .set_noack_map = ieee80211_set_noack_map, |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 4508 | #ifdef CONFIG_PM |
| 4509 | .set_wakeup = ieee80211_set_wakeup, |
| 4510 | #endif |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 4511 | .get_channel = ieee80211_cfg_get_channel, |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 4512 | .start_radar_detection = ieee80211_start_radar_detection, |
Orr Mazor | 26ec17a | 2019-12-22 14:55:31 +0000 | [diff] [blame] | 4513 | .end_cac = ieee80211_end_cac, |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 4514 | .channel_switch = ieee80211_channel_switch, |
Kyeyoon Park | 32db6b5 | 2013-12-16 23:04:43 -0800 | [diff] [blame] | 4515 | .set_qos_map = ieee80211_set_qos_map, |
Jouni Malinen | 3b1700b | 2014-04-28 11:22:25 +0300 | [diff] [blame] | 4516 | .set_ap_chanwidth = ieee80211_set_ap_chanwidth, |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 4517 | .add_tx_ts = ieee80211_add_tx_ts, |
| 4518 | .del_tx_ts = ieee80211_del_tx_ts, |
Ayala Beker | 708d50e | 2016-09-20 17:31:14 +0300 | [diff] [blame] | 4519 | .start_nan = ieee80211_start_nan, |
| 4520 | .stop_nan = ieee80211_stop_nan, |
Ayala Beker | 5953ff6 | 2016-09-20 17:31:19 +0300 | [diff] [blame] | 4521 | .nan_change_conf = ieee80211_nan_change_conf, |
Ayala Beker | 167e33f | 2016-09-20 17:31:20 +0300 | [diff] [blame] | 4522 | .add_nan_func = ieee80211_add_nan_func, |
| 4523 | .del_nan_func = ieee80211_del_nan_func, |
Michael Braun | ebceec8 | 2016-11-22 11:52:18 +0100 | [diff] [blame] | 4524 | .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast, |
Denis Kenzior | 9118064 | 2018-03-26 12:52:50 -0500 | [diff] [blame] | 4525 | .tx_control_port = ieee80211_tx_control_port, |
Toke Høiland-Jørgensen | 2fe4a29 | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 4526 | .get_txq_stats = ieee80211_get_txq_stats, |
Pradeep Kumar Chitrapu | bc84797 | 2018-10-03 20:19:20 -0700 | [diff] [blame] | 4527 | .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats, |
Johannes Berg | cee7013 | 2018-10-16 11:24:47 +0200 | [diff] [blame] | 4528 | .start_pmsr = ieee80211_start_pmsr, |
| 4529 | .abort_pmsr = ieee80211_abort_pmsr, |
Rajkumar Manoharan | 8828f81 | 2019-04-11 13:47:26 -0700 | [diff] [blame] | 4530 | .probe_mesh_link = ieee80211_probe_mesh_link, |
Tamizh chelvam | 370f51d | 2020-01-20 13:21:27 +0530 | [diff] [blame] | 4531 | .set_tid_config = ieee80211_set_tid_config, |
| 4532 | .reset_tid_config = ieee80211_reset_tid_config, |
Carl Huang | c534e09 | 2020-12-03 05:37:27 -0500 | [diff] [blame] | 4533 | .set_sar_specs = ieee80211_set_sar_specs, |
John Crispin | 5f9404a | 2021-07-02 19:44:08 +0200 | [diff] [blame] | 4534 | .color_change = ieee80211_color_change, |
Lorenzo Bianconi | a95bfb8 | 2021-11-29 14:11:24 +0100 | [diff] [blame] | 4535 | .set_radar_background = ieee80211_set_radar_background, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4536 | }; |