wifi: mac80211: move DFS CAC work to wiphy work
[linux-block.git] / net / mac80211 / cfg.c
CommitLineData
28c61a66 1// SPDX-License-Identifier: GPL-2.0-only
f0706e82
JB
2/*
3 * mac80211 configuration hooks for cfg80211
4 *
026331c4 5 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
b2eb0ee6 6 * Copyright 2013-2015 Intel Mobile Communications GmbH
e8e4f528 7 * Copyright (C) 2015-2017 Intel Deutschland GmbH
23a5f0af 8 * Copyright (C) 2018-2022 Intel Corporation
f0706e82
JB
9 */
10
e8cbb4cb 11#include <linux/ieee80211.h>
f0706e82
JB
12#include <linux/nl80211.h>
13#include <linux/rtnetlink.h>
5a0e3ad6 14#include <linux/slab.h>
881d966b 15#include <net/net_namespace.h>
5dfdaf58 16#include <linux/rcupdate.h>
5fdb3735 17#include <linux/fips.h>
dfe018bf 18#include <linux/if_ether.h>
f0706e82
JB
19#include <net/cfg80211.h>
20#include "ieee80211_i.h"
24487981 21#include "driver-ops.h"
2c8dccc7 22#include "rate.h"
c5dd9c2b 23#include "mesh.h"
02219b3a 24#include "wme.h"
c5dd9c2b 25
c88f1542 26static struct ieee80211_link_data *
ccdde7c7
JB
27ieee80211_link_or_deflink(struct ieee80211_sub_if_data *sdata, int link_id,
28 bool require_valid)
c88f1542
ST
29{
30 struct ieee80211_link_data *link;
31
32 if (link_id < 0) {
ccdde7c7
JB
33 /*
34 * For keys, if sdata is not an MLD, we might not use
35 * the return value at all (if it's not a pairwise key),
36 * so in that case (require_valid==false) don't error.
37 */
f1871abd 38 if (require_valid && ieee80211_vif_is_mld(&sdata->vif))
c88f1542
ST
39 return ERR_PTR(-EINVAL);
40
41 return &sdata->deflink;
42 }
43
44 link = sdata_dereference(sdata->link[link_id], sdata);
45 if (!link)
46 return ERR_PTR(-ENOLINK);
47 return link;
48}
49
65f1d600
JB
50static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata,
51 struct vif_params *params)
8c5e6889 52{
8c5e6889
JB
53 bool mu_mimo_groups = false;
54 bool mu_mimo_follow = false;
55
8c5e6889
JB
56 if (params->vht_mumimo_groups) {
57 u64 membership;
58
59 BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN);
60
65f1d600 61 memcpy(sdata->vif.bss_conf.mu_group.membership,
8c5e6889 62 params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
65f1d600 63 memcpy(sdata->vif.bss_conf.mu_group.position,
8c5e6889
JB
64 params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
65 WLAN_USER_POSITION_LEN);
d8675a63 66 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
7b7090b4 67 BSS_CHANGED_MU_GROUPS);
8c5e6889
JB
68 /* don't care about endianness - just check for 0 */
69 memcpy(&membership, params->vht_mumimo_groups,
70 WLAN_MEMBERSHIP_LEN);
71 mu_mimo_groups = membership != 0;
72 }
73
74 if (params->vht_mumimo_follow_addr) {
75 mu_mimo_follow =
76 is_valid_ether_addr(params->vht_mumimo_follow_addr);
65f1d600 77 ether_addr_copy(sdata->u.mntr.mu_follow_addr,
8c5e6889
JB
78 params->vht_mumimo_follow_addr);
79 }
80
d0a9123e 81 sdata->vif.bss_conf.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
65f1d600
JB
82}
83
84static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
85 struct vif_params *params)
86{
87 struct ieee80211_local *local = sdata->local;
88 struct ieee80211_sub_if_data *monitor_sdata;
89
90 /* check flags first */
91 if (params->flags && ieee80211_sdata_running(sdata)) {
92 u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE;
93
94 /*
95 * Prohibit MONITOR_FLAG_COOK_FRAMES and
96 * MONITOR_FLAG_ACTIVE to be changed while the
97 * interface is up.
98 * Else we would need to add a lot of cruft
99 * to update everything:
100 * cooked_mntrs, monitor and all fif_* counters
101 * reconfigure hardware
102 */
103 if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
104 return -EBUSY;
105 }
106
107 /* also validate MU-MIMO change */
6dd23603
JB
108 monitor_sdata = wiphy_dereference(local->hw.wiphy,
109 local->monitor_sdata);
65f1d600
JB
110
111 if (!monitor_sdata &&
112 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
113 return -EOPNOTSUPP;
114
115 /* apply all changes now - no failures allowed */
116
117 if (monitor_sdata)
118 ieee80211_set_mu_mimo_follow(monitor_sdata, params);
119
120 if (params->flags) {
121 if (ieee80211_sdata_running(sdata)) {
122 ieee80211_adjust_monitor_flags(sdata, -1);
123 sdata->u.mntr.flags = params->flags;
124 ieee80211_adjust_monitor_flags(sdata, 1);
125
126 ieee80211_configure_filter(local);
127 } else {
128 /*
129 * Because the interface is down, ieee80211_do_stop
130 * and ieee80211_do_open take care of "everything"
131 * mentioned in the comment above.
132 */
133 sdata->u.mntr.flags = params->flags;
134 }
135 }
8c5e6889
JB
136
137 return 0;
138}
139
17196425 140static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata,
d9f83f22
ST
141 struct cfg80211_mbssid_config params,
142 struct ieee80211_bss_conf *link_conf)
17196425
JC
143{
144 struct ieee80211_sub_if_data *tx_sdata;
145
146 sdata->vif.mbssid_tx_vif = NULL;
d9f83f22
ST
147 link_conf->bssid_index = 0;
148 link_conf->nontransmitted = false;
149 link_conf->ema_ap = false;
0eb38842 150 link_conf->bssid_indicator = 0;
17196425
JC
151
152 if (sdata->vif.type != NL80211_IFTYPE_AP || !params.tx_wdev)
153 return -EINVAL;
154
155 tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params.tx_wdev);
156 if (!tx_sdata)
157 return -EINVAL;
158
159 if (tx_sdata == sdata) {
160 sdata->vif.mbssid_tx_vif = &sdata->vif;
161 } else {
162 sdata->vif.mbssid_tx_vif = &tx_sdata->vif;
d9f83f22
ST
163 link_conf->nontransmitted = true;
164 link_conf->bssid_index = params.index;
17196425
JC
165 }
166 if (params.ema)
d9f83f22 167 link_conf->ema_ap = true;
17196425
JC
168
169 return 0;
170}
171
552bff0c
JB
172static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
173 const char *name,
6bab2e19 174 unsigned char name_assign_type,
84efbb84 175 enum nl80211_iftype type,
84efbb84 176 struct vif_params *params)
f0706e82
JB
177{
178 struct ieee80211_local *local = wiphy_priv(wiphy);
84efbb84 179 struct wireless_dev *wdev;
8cc9a739
MW
180 struct ieee80211_sub_if_data *sdata;
181 int err;
f0706e82 182
6bab2e19 183 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
f9e10ce4
JB
184 if (err)
185 return ERR_PTR(err);
8cc9a739 186
8c5e6889
JB
187 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
188
189 if (type == NL80211_IFTYPE_MONITOR) {
65f1d600 190 err = ieee80211_set_mon_options(sdata, params);
8c5e6889
JB
191 if (err) {
192 ieee80211_if_remove(sdata);
193 return NULL;
194 }
f9e10ce4
JB
195 }
196
84efbb84 197 return wdev;
f0706e82
JB
198}
199
84efbb84 200static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
f0706e82 201{
84efbb84 202 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
f0706e82 203
75636525 204 return 0;
f0706e82
JB
205}
206
e36d56b6
JB
207static int ieee80211_change_iface(struct wiphy *wiphy,
208 struct net_device *dev,
818a986e 209 enum nl80211_iftype type,
2ec600d6 210 struct vif_params *params)
42613db7 211{
9607e6b6 212 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
a5d3cbdb
FF
213 struct ieee80211_local *local = sdata->local;
214 struct sta_info *sta;
f3947e2d 215 int ret;
42613db7 216
05c914fe 217 ret = ieee80211_if_change_type(sdata, type);
f3947e2d
JB
218 if (ret)
219 return ret;
42613db7 220
6f527287 221 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
a9b3cd7f 222 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
49ddf8e6 223 ieee80211_check_fast_rx_iface(sdata);
6f527287 224 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
a5d3cbdb
FF
225 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
226
227 if (params->use_4addr == ifmgd->use_4addr)
228 return 0;
229
90703ba9 230 /* FIXME: no support for 4-addr MLO yet */
f1871abd 231 if (ieee80211_vif_is_mld(&sdata->vif))
90703ba9
JB
232 return -EOPNOTSUPP;
233
9bc383de 234 sdata->u.mgd.use_4addr = params->use_4addr;
a5d3cbdb
FF
235 if (!ifmgd->associated)
236 return 0;
237
238 mutex_lock(&local->sta_mtx);
bfd8403a 239 sta = sta_info_get(sdata, sdata->deflink.u.mgd.bssid);
a5d3cbdb
FF
240 if (sta)
241 drv_sta_set_4addr(local, sdata, &sta->sta,
242 params->use_4addr);
243 mutex_unlock(&local->sta_mtx);
244
245 if (params->use_4addr)
246 ieee80211_send_4addr_nullfunc(local, sdata);
49ddf8e6 247 }
9bc383de 248
42bd20d9 249 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
65f1d600
JB
250 ret = ieee80211_set_mon_options(sdata, params);
251 if (ret)
252 return ret;
85416a4f 253 }
f7917af9 254
42613db7
JB
255 return 0;
256}
257
f142c6b9
JB
258static int ieee80211_start_p2p_device(struct wiphy *wiphy,
259 struct wireless_dev *wdev)
260{
b6a55015
LC
261 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
262 int ret;
263
264 mutex_lock(&sdata->local->chanctx_mtx);
265 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
266 mutex_unlock(&sdata->local->chanctx_mtx);
267 if (ret < 0)
268 return ret;
269
f142c6b9
JB
270 return ieee80211_do_open(wdev, true);
271}
272
273static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
274 struct wireless_dev *wdev)
275{
276 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
277}
278
708d50ed
AB
279static int ieee80211_start_nan(struct wiphy *wiphy,
280 struct wireless_dev *wdev,
281 struct cfg80211_nan_conf *conf)
282{
283 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
284 int ret;
285
286 mutex_lock(&sdata->local->chanctx_mtx);
287 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
288 mutex_unlock(&sdata->local->chanctx_mtx);
289 if (ret < 0)
290 return ret;
291
292 ret = ieee80211_do_open(wdev, true);
293 if (ret)
294 return ret;
295
296 ret = drv_start_nan(sdata->local, sdata, conf);
297 if (ret)
298 ieee80211_sdata_stop(sdata);
299
167e33f4
AB
300 sdata->u.nan.conf = *conf;
301
708d50ed
AB
302 return ret;
303}
304
305static void ieee80211_stop_nan(struct wiphy *wiphy,
306 struct wireless_dev *wdev)
307{
308 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
309
310 drv_stop_nan(sdata->local, sdata);
311 ieee80211_sdata_stop(sdata);
312}
313
5953ff6d
AB
314static int ieee80211_nan_change_conf(struct wiphy *wiphy,
315 struct wireless_dev *wdev,
316 struct cfg80211_nan_conf *conf,
317 u32 changes)
318{
319 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
320 struct cfg80211_nan_conf new_conf;
321 int ret = 0;
322
323 if (sdata->vif.type != NL80211_IFTYPE_NAN)
324 return -EOPNOTSUPP;
325
326 if (!ieee80211_sdata_running(sdata))
327 return -ENETDOWN;
328
329 new_conf = sdata->u.nan.conf;
330
331 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
332 new_conf.master_pref = conf->master_pref;
333
8585989d
LC
334 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
335 new_conf.bands = conf->bands;
5953ff6d
AB
336
337 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
338 if (!ret)
339 sdata->u.nan.conf = new_conf;
340
341 return ret;
342}
343
167e33f4
AB
344static int ieee80211_add_nan_func(struct wiphy *wiphy,
345 struct wireless_dev *wdev,
346 struct cfg80211_nan_func *nan_func)
347{
348 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
349 int ret;
350
351 if (sdata->vif.type != NL80211_IFTYPE_NAN)
352 return -EOPNOTSUPP;
353
354 if (!ieee80211_sdata_running(sdata))
355 return -ENETDOWN;
356
357 spin_lock_bh(&sdata->u.nan.func_lock);
358
359 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
360 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
361 GFP_ATOMIC);
362 spin_unlock_bh(&sdata->u.nan.func_lock);
363
364 if (ret < 0)
365 return ret;
366
367 nan_func->instance_id = ret;
368
369 WARN_ON(nan_func->instance_id == 0);
370
371 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
372 if (ret) {
373 spin_lock_bh(&sdata->u.nan.func_lock);
374 idr_remove(&sdata->u.nan.function_inst_ids,
375 nan_func->instance_id);
376 spin_unlock_bh(&sdata->u.nan.func_lock);
377 }
378
379 return ret;
380}
381
382static struct cfg80211_nan_func *
383ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
384 u64 cookie)
385{
386 struct cfg80211_nan_func *func;
387 int id;
388
389 lockdep_assert_held(&sdata->u.nan.func_lock);
390
391 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
392 if (func->cookie == cookie)
393 return func;
394 }
395
396 return NULL;
397}
398
399static void ieee80211_del_nan_func(struct wiphy *wiphy,
400 struct wireless_dev *wdev, u64 cookie)
401{
402 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
403 struct cfg80211_nan_func *func;
404 u8 instance_id = 0;
405
406 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
407 !ieee80211_sdata_running(sdata))
408 return;
409
410 spin_lock_bh(&sdata->u.nan.func_lock);
411
412 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
413 if (func)
414 instance_id = func->instance_id;
415
416 spin_unlock_bh(&sdata->u.nan.func_lock);
417
418 if (instance_id)
419 drv_del_nan_func(sdata->local, sdata, instance_id);
420}
421
b53be792
SW
422static int ieee80211_set_noack_map(struct wiphy *wiphy,
423 struct net_device *dev,
424 u16 noack_map)
425{
426 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
427
428 sdata->noack_map = noack_map;
17c18bf8
JB
429
430 ieee80211_check_fast_xmit_iface(sdata);
431
b53be792
SW
432 return 0;
433}
434
96fc6efb
AW
435static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata,
436 const u8 *mac_addr, u8 key_idx)
437{
438 struct ieee80211_local *local = sdata->local;
439 struct ieee80211_key *key;
440 struct sta_info *sta;
441 int ret = -EINVAL;
442
443 if (!wiphy_ext_feature_isset(local->hw.wiphy,
444 NL80211_EXT_FEATURE_EXT_KEY_ID))
445 return -EINVAL;
446
447 sta = sta_info_get_bss(sdata, mac_addr);
448
449 if (!sta)
450 return -EINVAL;
451
452 if (sta->ptk_idx == key_idx)
453 return 0;
454
455 mutex_lock(&local->key_mtx);
456 key = key_mtx_dereference(local, sta->ptk[key_idx]);
457
458 if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)
459 ret = ieee80211_set_tx_key(key);
460
461 mutex_unlock(&local->key_mtx);
462 return ret;
463}
464
e8cbb4cb 465static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
e7a7b84e
VJ
466 int link_id, u8 key_idx, bool pairwise,
467 const u8 *mac_addr, struct key_params *params)
e8cbb4cb 468{
26a58456 469 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
ccdde7c7
JB
470 struct ieee80211_link_data *link =
471 ieee80211_link_or_deflink(sdata, link_id, false);
2475b1cc 472 struct ieee80211_local *local = sdata->local;
e8cbb4cb 473 struct sta_info *sta = NULL;
db4d1169 474 struct ieee80211_key *key;
3b96766f 475 int err;
e8cbb4cb 476
26a58456 477 if (!ieee80211_sdata_running(sdata))
ad0e2b5a
JB
478 return -ENETDOWN;
479
ccdde7c7
JB
480 if (IS_ERR(link))
481 return PTR_ERR(link);
482
96fc6efb
AW
483 if (pairwise && params->mode == NL80211_KEY_SET_TX)
484 return ieee80211_set_tx(sdata, mac_addr, key_idx);
485
97359d12 486 /* reject WEP and TKIP keys if WEP failed to initialize */
e8cbb4cb
JB
487 switch (params->cipher) {
488 case WLAN_CIPHER_SUITE_WEP40:
e8cbb4cb 489 case WLAN_CIPHER_SUITE_TKIP:
97359d12 490 case WLAN_CIPHER_SUITE_WEP104:
ccdde7c7
JB
491 if (link_id >= 0)
492 return -EINVAL;
5fdb3735 493 if (WARN_ON_ONCE(fips_enabled))
97359d12 494 return -EINVAL;
aaaee2d6 495 break;
e8cbb4cb 496 default:
97359d12 497 break;
e8cbb4cb
JB
498 }
499
97359d12 500 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
23a5f0af 501 params->key, params->seq_len, params->seq);
1ac62ba7
BH
502 if (IS_ERR(key))
503 return PTR_ERR(key);
db4d1169 504
ccdde7c7
JB
505 key->conf.link_id = link_id;
506
e31b8213
JB
507 if (pairwise)
508 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
509
96fc6efb
AW
510 if (params->mode == NL80211_KEY_NO_TX)
511 key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX;
512
2475b1cc 513 mutex_lock(&local->sta_mtx);
3b96766f 514
e8cbb4cb 515 if (mac_addr) {
850092db 516 sta = sta_info_get_bss(sdata, mac_addr);
1626e0fa
JB
517 /*
518 * The ASSOC test makes sure the driver is ready to
519 * receive the key. When wpa_supplicant has roamed
520 * using FT, it attempts to set the key before
521 * association has completed, this rejects that attempt
d070f913 522 * so it will set the key again after association.
1626e0fa
JB
523 *
524 * TODO: accept the key if we have a station entry and
525 * add it to the device after the station.
526 */
527 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
79cf2dfa 528 ieee80211_key_free_unused(key);
3b96766f
JB
529 err = -ENOENT;
530 goto out_unlock;
db4d1169 531 }
e8cbb4cb
JB
532 }
533
e548c49e
JB
534 switch (sdata->vif.type) {
535 case NL80211_IFTYPE_STATION:
536 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
537 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
538 break;
539 case NL80211_IFTYPE_AP:
540 case NL80211_IFTYPE_AP_VLAN:
541 /* Keys without a station are used for TX only */
211710ca 542 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
e548c49e
JB
543 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
544 break;
545 case NL80211_IFTYPE_ADHOC:
546 /* no MFP (yet) */
547 break;
548 case NL80211_IFTYPE_MESH_POINT:
549#ifdef CONFIG_MAC80211_MESH
550 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
551 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
552 break;
553#endif
554 case NL80211_IFTYPE_WDS:
555 case NL80211_IFTYPE_MONITOR:
556 case NL80211_IFTYPE_P2P_DEVICE:
cb3b7d87 557 case NL80211_IFTYPE_NAN:
e548c49e
JB
558 case NL80211_IFTYPE_UNSPECIFIED:
559 case NUM_NL80211_IFTYPES:
560 case NL80211_IFTYPE_P2P_CLIENT:
561 case NL80211_IFTYPE_P2P_GO:
6e0bd6c3 562 case NL80211_IFTYPE_OCB:
e548c49e
JB
563 /* shouldn't happen */
564 WARN_ON_ONCE(1);
565 break;
566 }
567
ccdde7c7 568 err = ieee80211_key_link(key, link, sta);
db4d1169 569
3b96766f 570 out_unlock:
2475b1cc 571 mutex_unlock(&local->sta_mtx);
3b96766f
JB
572
573 return err;
e8cbb4cb
JB
574}
575
8cbf0c2a 576static struct ieee80211_key *
ccdde7c7 577ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id,
8cbf0c2a
JB
578 u8 key_idx, bool pairwise, const u8 *mac_addr)
579{
09d838a4 580 struct ieee80211_local *local __maybe_unused = sdata->local;
ccdde7c7 581 struct ieee80211_link_data *link = &sdata->deflink;
bfd8403a 582 struct ieee80211_key *key;
ccdde7c7
JB
583
584 if (link_id >= 0) {
585 link = rcu_dereference_check(sdata->link[link_id],
586 lockdep_is_held(&sdata->wdev.mtx));
587 if (!link)
588 return NULL;
589 }
8cbf0c2a
JB
590
591 if (mac_addr) {
ccdde7c7
JB
592 struct sta_info *sta;
593 struct link_sta_info *link_sta;
594
8cbf0c2a
JB
595 sta = sta_info_get_bss(sdata, mac_addr);
596 if (!sta)
597 return NULL;
598
ccdde7c7
JB
599 if (link_id >= 0) {
600 link_sta = rcu_dereference_check(sta->link[link_id],
601 lockdep_is_held(&local->sta_mtx));
602 if (!link_sta)
603 return NULL;
604 } else {
605 link_sta = &sta->deflink;
606 }
607
8cbf0c2a
JB
608 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
609 return rcu_dereference_check_key_mtx(local,
610 sta->ptk[key_idx]);
611
612 if (!pairwise &&
613 key_idx < NUM_DEFAULT_KEYS +
614 NUM_DEFAULT_MGMT_KEYS +
615 NUM_DEFAULT_BEACON_KEYS)
616 return rcu_dereference_check_key_mtx(local,
ccdde7c7 617 link_sta->gtk[key_idx]);
8cbf0c2a
JB
618
619 return NULL;
620 }
621
bfd8403a 622 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
8cbf0c2a
JB
623 return rcu_dereference_check_key_mtx(local,
624 sdata->keys[key_idx]);
625
ccdde7c7 626 key = rcu_dereference_check_key_mtx(local, link->gtk[key_idx]);
bfd8403a
JB
627 if (key)
628 return key;
629
e2722d27
JB
630 /* or maybe it was a WEP key */
631 if (key_idx < NUM_DEFAULT_KEYS)
632 return rcu_dereference_check_key_mtx(local, sdata->keys[key_idx]);
633
8cbf0c2a
JB
634 return NULL;
635}
636
e8cbb4cb 637static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
e7a7b84e
VJ
638 int link_id, u8 key_idx, bool pairwise,
639 const u8 *mac_addr)
e8cbb4cb 640{
5c0c3641
JB
641 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
642 struct ieee80211_local *local = sdata->local;
8cbf0c2a 643 struct ieee80211_key *key;
e8cbb4cb
JB
644 int ret;
645
5c0c3641
JB
646 mutex_lock(&local->sta_mtx);
647 mutex_lock(&local->key_mtx);
3b96766f 648
ccdde7c7 649 key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr);
5c0c3641 650 if (!key) {
3b96766f
JB
651 ret = -ENOENT;
652 goto out_unlock;
653 }
e8cbb4cb 654
133bf90d 655 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
e8cbb4cb 656
3b96766f
JB
657 ret = 0;
658 out_unlock:
5c0c3641
JB
659 mutex_unlock(&local->key_mtx);
660 mutex_unlock(&local->sta_mtx);
3b96766f
JB
661
662 return ret;
e8cbb4cb
JB
663}
664
62da92fb 665static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
e7a7b84e
VJ
666 int link_id, u8 key_idx, bool pairwise,
667 const u8 *mac_addr, void *cookie,
62da92fb
JB
668 void (*callback)(void *cookie,
669 struct key_params *params))
670{
14db74bc 671 struct ieee80211_sub_if_data *sdata;
62da92fb
JB
672 u8 seq[6] = {0};
673 struct key_params params;
8cbf0c2a 674 struct ieee80211_key *key;
aba83a0b 675 u64 pn64;
62da92fb
JB
676 u32 iv32;
677 u16 iv16;
678 int err = -ENOENT;
9352c19f 679 struct ieee80211_key_seq kseq = {};
62da92fb 680
14db74bc
JB
681 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
682
3b96766f
JB
683 rcu_read_lock();
684
ccdde7c7 685 key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr);
62da92fb
JB
686 if (!key)
687 goto out;
688
689 memset(&params, 0, sizeof(params));
690
97359d12 691 params.cipher = key->conf.cipher;
62da92fb 692
97359d12
JB
693 switch (key->conf.cipher) {
694 case WLAN_CIPHER_SUITE_TKIP:
f8079d43
EP
695 pn64 = atomic64_read(&key->conf.tx_pn);
696 iv32 = TKIP_PN_TO_IV32(pn64);
697 iv16 = TKIP_PN_TO_IV16(pn64);
62da92fb 698
9352c19f
JB
699 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
700 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
701 drv_get_key_seq(sdata->local, key, &kseq);
702 iv32 = kseq.tkip.iv32;
703 iv16 = kseq.tkip.iv16;
704 }
62da92fb
JB
705
706 seq[0] = iv16 & 0xff;
707 seq[1] = (iv16 >> 8) & 0xff;
708 seq[2] = iv32 & 0xff;
709 seq[3] = (iv32 >> 8) & 0xff;
710 seq[4] = (iv32 >> 16) & 0xff;
711 seq[5] = (iv32 >> 24) & 0xff;
712 params.seq = seq;
713 params.seq_len = 6;
714 break;
97359d12 715 case WLAN_CIPHER_SUITE_CCMP:
2b2ba0db 716 case WLAN_CIPHER_SUITE_CCMP_256:
97359d12 717 case WLAN_CIPHER_SUITE_AES_CMAC:
56c52da2 718 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
db388a56
JB
719 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
720 offsetof(typeof(kseq), aes_cmac));
fc0561dc 721 fallthrough;
8ade538b
JM
722 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
723 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
db388a56
JB
724 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
725 offsetof(typeof(kseq), aes_gmac));
fc0561dc 726 fallthrough;
00b9cfa3
JM
727 case WLAN_CIPHER_SUITE_GCMP:
728 case WLAN_CIPHER_SUITE_GCMP_256:
db388a56
JB
729 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
730 offsetof(typeof(kseq), gcmp));
731
9352c19f
JB
732 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
733 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
734 drv_get_key_seq(sdata->local, key, &kseq);
db388a56 735 memcpy(seq, kseq.ccmp.pn, 6);
9352c19f 736 } else {
db388a56 737 pn64 = atomic64_read(&key->conf.tx_pn);
9352c19f
JB
738 seq[0] = pn64;
739 seq[1] = pn64 >> 8;
740 seq[2] = pn64 >> 16;
741 seq[3] = pn64 >> 24;
742 seq[4] = pn64 >> 32;
743 seq[5] = pn64 >> 40;
744 }
00b9cfa3
JM
745 params.seq = seq;
746 params.seq_len = 6;
747 break;
a31cf1c6
JB
748 default:
749 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
750 break;
751 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
752 break;
753 drv_get_key_seq(sdata->local, key, &kseq);
754 params.seq = kseq.hw.seq;
755 params.seq_len = kseq.hw.seq_len;
756 break;
62da92fb
JB
757 }
758
759 params.key = key->conf.key;
760 params.key_len = key->conf.keylen;
761
762 callback(cookie, &params);
763 err = 0;
764
765 out:
3b96766f 766 rcu_read_unlock();
62da92fb
JB
767 return err;
768}
769
e8cbb4cb
JB
770static int ieee80211_config_default_key(struct wiphy *wiphy,
771 struct net_device *dev,
e7a7b84e 772 int link_id, u8 key_idx, bool uni,
dbd2fd65 773 bool multi)
e8cbb4cb 774{
ad0e2b5a 775 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
ccdde7c7
JB
776 struct ieee80211_link_data *link =
777 ieee80211_link_or_deflink(sdata, link_id, false);
3b96766f 778
ccdde7c7
JB
779 if (IS_ERR(link))
780 return PTR_ERR(link);
781
782 ieee80211_set_default_key(link, key_idx, uni, multi);
e8cbb4cb
JB
783
784 return 0;
785}
786
3cfcf6ac
JM
787static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
788 struct net_device *dev,
e7a7b84e 789 int link_id, u8 key_idx)
3cfcf6ac 790{
66c52421 791 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
ccdde7c7
JB
792 struct ieee80211_link_data *link =
793 ieee80211_link_or_deflink(sdata, link_id, true);
3cfcf6ac 794
ccdde7c7
JB
795 if (IS_ERR(link))
796 return PTR_ERR(link);
797
798 ieee80211_set_default_mgmt_key(link, key_idx);
3cfcf6ac 799
3cfcf6ac
JM
800 return 0;
801}
802
e5473e80
JM
803static int ieee80211_config_default_beacon_key(struct wiphy *wiphy,
804 struct net_device *dev,
e7a7b84e 805 int link_id, u8 key_idx)
e5473e80
JM
806{
807 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
ccdde7c7
JB
808 struct ieee80211_link_data *link =
809 ieee80211_link_or_deflink(sdata, link_id, true);
810
811 if (IS_ERR(link))
812 return PTR_ERR(link);
e5473e80 813
ccdde7c7 814 ieee80211_set_default_beacon_key(link, key_idx);
e5473e80
JM
815
816 return 0;
817}
818
6b62bf32
TP
819void sta_set_rate_info_tx(struct sta_info *sta,
820 const struct ieee80211_tx_rate *rate,
821 struct rate_info *rinfo)
822{
823 rinfo->flags = 0;
8bc83c24 824 if (rate->flags & IEEE80211_TX_RC_MCS) {
6b62bf32 825 rinfo->flags |= RATE_INFO_FLAGS_MCS;
8bc83c24
JB
826 rinfo->mcs = rate->idx;
827 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
828 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
829 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
830 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
831 } else {
832 struct ieee80211_supported_band *sband;
2103dec1
SW
833 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
834 u16 brate;
835
21a8e9dd 836 sband = ieee80211_get_sband(sta->sdata);
8b783d10
TP
837 WARN_ON_ONCE(sband && !sband->bitrates);
838 if (sband && sband->bitrates) {
21a8e9dd
MSS
839 brate = sband->bitrates[rate->idx].bitrate;
840 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
841 }
8bc83c24 842 }
6b62bf32 843 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
b51f3bee
JB
844 rinfo->bw = RATE_INFO_BW_40;
845 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
846 rinfo->bw = RATE_INFO_BW_80;
847 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
848 rinfo->bw = RATE_INFO_BW_160;
849 else
850 rinfo->bw = RATE_INFO_BW_20;
6b62bf32
TP
851 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
852 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
6b62bf32
TP
853}
854
c5dd9c2b 855static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 856 int idx, u8 *mac, struct station_info *sinfo)
c5dd9c2b 857{
3b53fde8 858 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
66572cfc 859 struct ieee80211_local *local = sdata->local;
c5dd9c2b 860 struct sta_info *sta;
d0709a65
JB
861 int ret = -ENOENT;
862
66572cfc 863 mutex_lock(&local->sta_mtx);
c5dd9c2b 864
3b53fde8 865 sta = sta_info_get_by_idx(sdata, idx);
d0709a65
JB
866 if (sta) {
867 ret = 0;
17741cdc 868 memcpy(mac, sta->sta.addr, ETH_ALEN);
0fdf1493 869 sta_set_sinfo(sta, sinfo, true);
d0709a65 870 }
c5dd9c2b 871
66572cfc 872 mutex_unlock(&local->sta_mtx);
c5dd9c2b 873
d0709a65 874 return ret;
c5dd9c2b
LCC
875}
876
1289723e
HS
877static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
878 int idx, struct survey_info *survey)
879{
880 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
881
1289723e
HS
882 return drv_get_survey(local, idx, survey);
883}
884
7bbdd2d9 885static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 886 const u8 *mac, struct station_info *sinfo)
7bbdd2d9 887{
abe60632 888 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
66572cfc 889 struct ieee80211_local *local = sdata->local;
7bbdd2d9 890 struct sta_info *sta;
d0709a65 891 int ret = -ENOENT;
7bbdd2d9 892
66572cfc 893 mutex_lock(&local->sta_mtx);
7bbdd2d9 894
0e5ded5a 895 sta = sta_info_get_bss(sdata, mac);
d0709a65
JB
896 if (sta) {
897 ret = 0;
0fdf1493 898 sta_set_sinfo(sta, sinfo, true);
d0709a65
JB
899 }
900
66572cfc 901 mutex_unlock(&local->sta_mtx);
d0709a65
JB
902
903 return ret;
7bbdd2d9
JB
904}
905
55de908a 906static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
683b6d3b 907 struct cfg80211_chan_def *chandef)
3d9e6e12
JB
908{
909 struct ieee80211_local *local = wiphy_priv(wiphy);
55de908a
JB
910 struct ieee80211_sub_if_data *sdata;
911 int ret = 0;
3d9e6e12 912
4bf88530 913 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
55de908a 914 return 0;
3d9e6e12 915
55de908a 916 if (local->use_chanctx) {
6dd23603
JB
917 sdata = wiphy_dereference(local->hw.wiphy,
918 local->monitor_sdata);
55de908a 919 if (sdata) {
4484de23
JB
920 sdata_lock(sdata);
921 mutex_lock(&local->mtx);
d8675a63
JB
922 ieee80211_link_release_channel(&sdata->deflink);
923 ret = ieee80211_link_use_channel(&sdata->deflink,
b4f85443
JB
924 chandef,
925 IEEE80211_CHANCTX_EXCLUSIVE);
4484de23
JB
926 mutex_unlock(&local->mtx);
927 sdata_unlock(sdata);
55de908a 928 }
4484de23
JB
929 } else {
930 mutex_lock(&local->mtx);
931 if (local->open_count == local->monitors) {
932 local->_oper_chandef = *chandef;
933 ieee80211_hw_config(local, 0);
934 }
935 mutex_unlock(&local->mtx);
55de908a 936 }
3d9e6e12 937
4bf88530
JB
938 if (ret == 0)
939 local->monitor_chandef = *chandef;
3d9e6e12 940
55de908a 941 return ret;
e8c9bd5b
JB
942}
943
5f9404ab
JC
944static int
945ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
946 const u8 *resp, size_t resp_len,
947 const struct ieee80211_csa_settings *csa,
d9f83f22
ST
948 const struct ieee80211_color_change_settings *cca,
949 struct ieee80211_link_data *link)
02945821 950{
aa7a0080 951 struct probe_resp *new, *old;
02945821
AN
952
953 if (!resp || !resp_len)
aba4e6ff 954 return 1;
02945821 955
d9f83f22 956 old = sdata_dereference(link->u.ap.probe_resp, sdata);
02945821 957
aa7a0080 958 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
02945821
AN
959 if (!new)
960 return -ENOMEM;
961
aa7a0080
ES
962 new->len = resp_len;
963 memcpy(new->data, resp, resp_len);
02945821 964
af296bdb 965 if (csa)
8552a434 966 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp,
af296bdb 967 csa->n_counter_offsets_presp *
8552a434 968 sizeof(new->cntdwn_counter_offsets[0]));
5f9404ab
JC
969 else if (cca)
970 new->cntdwn_counter_offsets[0] = cca->counter_offset_presp;
af296bdb 971
d9f83f22 972 rcu_assign_pointer(link->u.ap.probe_resp, new);
aa7a0080
ES
973 if (old)
974 kfree_rcu(old, rcu_head);
02945821
AN
975
976 return 0;
977}
978
295b02c4 979static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata,
d9f83f22
ST
980 struct cfg80211_fils_discovery *params,
981 struct ieee80211_link_data *link,
982 struct ieee80211_bss_conf *link_conf)
295b02c4
AD
983{
984 struct fils_discovery_data *new, *old = NULL;
985 struct ieee80211_fils_discovery *fd;
986
987 if (!params->tmpl || !params->tmpl_len)
988 return -EINVAL;
989
d9f83f22 990 fd = &link_conf->fils_discovery;
295b02c4
AD
991 fd->min_interval = params->min_interval;
992 fd->max_interval = params->max_interval;
993
d9f83f22 994 old = sdata_dereference(link->u.ap.fils_discovery, sdata);
295b02c4
AD
995 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
996 if (!new)
997 return -ENOMEM;
998 new->len = params->tmpl_len;
999 memcpy(new->data, params->tmpl, params->tmpl_len);
d9f83f22 1000 rcu_assign_pointer(link->u.ap.fils_discovery, new);
295b02c4
AD
1001
1002 if (old)
1003 kfree_rcu(old, rcu_head);
1004
1005 return 0;
1006}
1007
632189a0
AD
1008static int
1009ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata,
d9f83f22
ST
1010 struct cfg80211_unsol_bcast_probe_resp *params,
1011 struct ieee80211_link_data *link,
1012 struct ieee80211_bss_conf *link_conf)
632189a0
AD
1013{
1014 struct unsol_bcast_probe_resp_data *new, *old = NULL;
1015
1016 if (!params->tmpl || !params->tmpl_len)
1017 return -EINVAL;
1018
d9f83f22 1019 old = sdata_dereference(link->u.ap.unsol_bcast_probe_resp, sdata);
632189a0
AD
1020 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
1021 if (!new)
1022 return -ENOMEM;
1023 new->len = params->tmpl_len;
1024 memcpy(new->data, params->tmpl, params->tmpl_len);
d9f83f22 1025 rcu_assign_pointer(link->u.ap.unsol_bcast_probe_resp, new);
632189a0
AD
1026
1027 if (old)
1028 kfree_rcu(old, rcu_head);
1029
d9f83f22 1030 link_conf->unsol_bcast_probe_resp_interval = params->interval;
632189a0
AD
1031
1032 return 0;
1033}
1034
bc847970
PKC
1035static int ieee80211_set_ftm_responder_params(
1036 struct ieee80211_sub_if_data *sdata,
1037 const u8 *lci, size_t lci_len,
d9f83f22
ST
1038 const u8 *civicloc, size_t civicloc_len,
1039 struct ieee80211_bss_conf *link_conf)
bc847970
PKC
1040{
1041 struct ieee80211_ftm_responder_params *new, *old;
bc847970
PKC
1042 u8 *pos;
1043 int len;
1044
554be833
JB
1045 if (!lci_len && !civicloc_len)
1046 return 0;
bc847970 1047
d9f83f22 1048 old = link_conf->ftmr_params;
bc847970
PKC
1049 len = lci_len + civicloc_len;
1050
1051 new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
1052 if (!new)
1053 return -ENOMEM;
1054
1055 pos = (u8 *)(new + 1);
1056 if (lci_len) {
1057 new->lci_len = lci_len;
1058 new->lci = pos;
1059 memcpy(pos, lci, lci_len);
1060 pos += lci_len;
1061 }
1062
1063 if (civicloc_len) {
1064 new->civicloc_len = civicloc_len;
1065 new->civicloc = pos;
1066 memcpy(pos, civicloc, civicloc_len);
1067 pos += civicloc_len;
1068 }
1069
d9f83f22 1070 link_conf->ftmr_params = new;
bc847970
PKC
1071 kfree(old);
1072
1073 return 0;
1074}
1075
2b3171c6
LB
1076static int
1077ieee80211_copy_mbssid_beacon(u8 *pos, struct cfg80211_mbssid_elems *dst,
1078 struct cfg80211_mbssid_elems *src)
1079{
1080 int i, offset = 0;
1081
1082 for (i = 0; i < src->cnt; i++) {
1083 memcpy(pos + offset, src->elem[i].data, src->elem[i].len);
1084 dst->elem[i].len = src->elem[i].len;
1085 dst->elem[i].data = pos + offset;
1086 offset += dst->elem[i].len;
1087 }
1088 dst->cnt = src->cnt;
1089
1090 return offset;
1091}
1092
68b9bea2
AD
1093static int
1094ieee80211_copy_rnr_beacon(u8 *pos, struct cfg80211_rnr_elems *dst,
1095 struct cfg80211_rnr_elems *src)
1096{
1097 int i, offset = 0;
1098
1099 for (i = 0; i < src->cnt; i++) {
1100 memcpy(pos + offset, src->elem[i].data, src->elem[i].len);
1101 dst->elem[i].len = src->elem[i].len;
1102 dst->elem[i].data = pos + offset;
1103 offset += dst->elem[i].len;
1104 }
1105 dst->cnt = src->cnt;
1106
1107 return offset;
1108}
1109
15ddba5f
A
1110static int
1111ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
1112 struct ieee80211_link_data *link,
1113 struct cfg80211_beacon_data *params,
1114 const struct ieee80211_csa_settings *csa,
1115 const struct ieee80211_color_change_settings *cca,
1116 u64 *changed)
5dfdaf58 1117{
2b3171c6 1118 struct cfg80211_mbssid_elems *mbssid = NULL;
68b9bea2 1119 struct cfg80211_rnr_elems *rnr = NULL;
5dfdaf58
JB
1120 struct beacon_data *new, *old;
1121 int new_head_len, new_tail_len;
8860020e 1122 int size, err;
15ddba5f 1123 u64 _changed = BSS_CHANGED_BEACON;
d8675a63 1124 struct ieee80211_bss_conf *link_conf = link->conf;
5dfdaf58 1125
d9f83f22 1126 old = sdata_dereference(link->u.ap.beacon, sdata);
5dfdaf58 1127
5dfdaf58
JB
1128 /* Need to have a beacon head if we don't have one yet */
1129 if (!params->head && !old)
8860020e 1130 return -EINVAL;
5dfdaf58
JB
1131
1132 /* new or old head? */
1133 if (params->head)
1134 new_head_len = params->head_len;
1135 else
1136 new_head_len = old->head_len;
1137
1138 /* new or old tail? */
1139 if (params->tail || !old)
1140 /* params->tail_len will be zero for !params->tail */
1141 new_tail_len = params->tail_len;
1142 else
1143 new_tail_len = old->tail_len;
1144
1145 size = sizeof(*new) + new_head_len + new_tail_len;
1146
2b3171c6
LB
1147 /* new or old multiple BSSID elements? */
1148 if (params->mbssid_ies) {
1149 mbssid = params->mbssid_ies;
1150 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
68b9bea2
AD
1151 if (params->rnr_ies) {
1152 rnr = params->rnr_ies;
1153 size += struct_size(new->rnr_ies, elem, rnr->cnt);
1154 }
1155 size += ieee80211_get_mbssid_beacon_len(mbssid, rnr,
1156 mbssid->cnt);
2b3171c6
LB
1157 } else if (old && old->mbssid_ies) {
1158 mbssid = old->mbssid_ies;
1159 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
68b9bea2
AD
1160 if (old && old->rnr_ies) {
1161 rnr = old->rnr_ies;
1162 size += struct_size(new->rnr_ies, elem, rnr->cnt);
1163 }
1164 size += ieee80211_get_mbssid_beacon_len(mbssid, rnr,
1165 mbssid->cnt);
2b3171c6
LB
1166 }
1167
5dfdaf58
JB
1168 new = kzalloc(size, GFP_KERNEL);
1169 if (!new)
1170 return -ENOMEM;
1171
1172 /* start filling the new info now */
1173
5dfdaf58
JB
1174 /*
1175 * pointers go into the block we allocated,
68b9bea2 1176 * memory is | beacon_data | head | tail | mbssid_ies | rnr_ies
5dfdaf58
JB
1177 */
1178 new->head = ((u8 *) new) + sizeof(*new);
1179 new->tail = new->head + new_head_len;
1180 new->head_len = new_head_len;
1181 new->tail_len = new_tail_len;
2b3171c6
LB
1182 /* copy in optional mbssid_ies */
1183 if (mbssid) {
1184 u8 *pos = new->tail + new->tail_len;
1185
1186 new->mbssid_ies = (void *)pos;
1187 pos += struct_size(new->mbssid_ies, elem, mbssid->cnt);
68b9bea2
AD
1188 pos += ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies,
1189 mbssid);
1190 if (rnr) {
1191 new->rnr_ies = (void *)pos;
1192 pos += struct_size(new->rnr_ies, elem, rnr->cnt);
1193 ieee80211_copy_rnr_beacon(pos, new->rnr_ies, rnr);
1194 }
dde78aa5 1195 /* update bssid_indicator */
d9f83f22 1196 link_conf->bssid_indicator =
dde78aa5 1197 ilog2(__roundup_pow_of_two(mbssid->cnt + 1));
2b3171c6 1198 }
5dfdaf58 1199
af296bdb 1200 if (csa) {
8552a434
JC
1201 new->cntdwn_current_counter = csa->count;
1202 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon,
af296bdb 1203 csa->n_counter_offsets_beacon *
8552a434 1204 sizeof(new->cntdwn_counter_offsets[0]));
5f9404ab
JC
1205 } else if (cca) {
1206 new->cntdwn_current_counter = cca->count;
1207 new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon;
af296bdb
MK
1208 }
1209
5dfdaf58
JB
1210 /* copy in head */
1211 if (params->head)
1212 memcpy(new->head, params->head, new_head_len);
1213 else
1214 memcpy(new->head, old->head, new_head_len);
1215
1216 /* copy in optional tail */
1217 if (params->tail)
1218 memcpy(new->tail, params->tail, new_tail_len);
1219 else
1220 if (old)
1221 memcpy(new->tail, old->tail, new_tail_len);
1222
02945821 1223 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
d9f83f22 1224 params->probe_resp_len, csa, cca, link);
bcc27fab
LB
1225 if (err < 0) {
1226 kfree(new);
8860020e 1227 return err;
bcc27fab 1228 }
8860020e 1229 if (err == 0)
15ddba5f 1230 _changed |= BSS_CHANGED_AP_PROBE_RESP;
02945821 1231
bc847970 1232 if (params->ftm_responder != -1) {
d9f83f22 1233 link_conf->ftm_responder = params->ftm_responder;
bc847970
PKC
1234 err = ieee80211_set_ftm_responder_params(sdata,
1235 params->lci,
1236 params->lci_len,
1237 params->civicloc,
d9f83f22
ST
1238 params->civicloc_len,
1239 link_conf);
bc847970 1240
bcc27fab
LB
1241 if (err < 0) {
1242 kfree(new);
bc847970 1243 return err;
bcc27fab 1244 }
bc847970 1245
15ddba5f 1246 _changed |= BSS_CHANGED_FTM_RESPONDER;
bc847970
PKC
1247 }
1248
d9f83f22 1249 rcu_assign_pointer(link->u.ap.beacon, new);
bfd8403a 1250 sdata->u.ap.active = true;
8860020e
JB
1251
1252 if (old)
1253 kfree_rcu(old, rcu_head);
7827493b 1254
15ddba5f
A
1255 *changed |= _changed;
1256 return 0;
5dfdaf58
JB
1257}
1258
8860020e
JB
1259static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
1260 struct cfg80211_ap_settings *params)
5dfdaf58 1261{
8860020e 1262 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
34a3740d 1263 struct ieee80211_local *local = sdata->local;
5dfdaf58 1264 struct beacon_data *old;
665c93a9 1265 struct ieee80211_sub_if_data *vlan;
2cc25e4b 1266 u64 changed = BSS_CHANGED_BEACON_INT |
8860020e
JB
1267 BSS_CHANGED_BEACON_ENABLED |
1268 BSS_CHANGED_BEACON |
4bcc56bb 1269 BSS_CHANGED_P2P_PS |
a0de1ca3 1270 BSS_CHANGED_TXPOWER |
322cd27c 1271 BSS_CHANGED_TWT;
08fad438 1272 int i, err;
83e37e0b 1273 int prev_beacon_int;
d9f83f22 1274 unsigned int link_id = params->beacon.link_id;
d8675a63
JB
1275 struct ieee80211_link_data *link;
1276 struct ieee80211_bss_conf *link_conf;
1277
1278 link = sdata_dereference(sdata->link[link_id], sdata);
1279 if (!link)
1280 return -ENOLINK;
1281
1282 link_conf = link->conf;
14db74bc 1283
d9f83f22 1284 old = sdata_dereference(link->u.ap.beacon, sdata);
5dfdaf58
JB
1285 if (old)
1286 return -EALREADY;
1287
52b4810b
IP
1288 if (params->smps_mode != NL80211_SMPS_OFF)
1289 return -ENOTSUPP;
1290
d9f83f22 1291 link->smps_mode = IEEE80211_SMPS_OFF;
b3dd8279 1292
d9f83f22 1293 link->needed_rx_chains = sdata->local->rx_chains;
04ecd257 1294
d9f83f22
ST
1295 prev_beacon_int = link_conf->beacon_int;
1296 link_conf->beacon_int = params->beacon_interval;
ac668afe 1297
2ad7dd94
RL
1298 if (params->ht_cap)
1299 link_conf->ht_ldpc =
1300 params->ht_cap->cap_info &
1301 cpu_to_le16(IEEE80211_HT_CAP_LDPC_CODING);
1302
42470fa0 1303 if (params->vht_cap) {
2ad7dd94
RL
1304 link_conf->vht_ldpc =
1305 params->vht_cap->vht_cap_info &
1306 cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC);
42470fa0
MS
1307 link_conf->vht_su_beamformer =
1308 params->vht_cap->vht_cap_info &
1309 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
1310 link_conf->vht_su_beamformee =
1311 params->vht_cap->vht_cap_info &
1312 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE);
1313 link_conf->vht_mu_beamformer =
1314 params->vht_cap->vht_cap_info &
1315 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE);
1316 link_conf->vht_mu_beamformee =
1317 params->vht_cap->vht_cap_info &
1318 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
1319 }
1320
03efb863 1321 if (params->he_cap && params->he_oper) {
d9f83f22
ST
1322 link_conf->he_support = true;
1323 link_conf->htc_trig_based_pkt_ext =
03efb863
ST
1324 le32_get_bits(params->he_oper->he_oper_params,
1325 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
d9f83f22 1326 link_conf->frame_time_rts_th =
03efb863
ST
1327 le32_get_bits(params->he_oper->he_oper_params,
1328 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
322cd27c
P
1329 changed |= BSS_CHANGED_HE_OBSS_PD;
1330
3d48cb74 1331 if (params->beacon.he_bss_color.enabled)
322cd27c 1332 changed |= BSS_CHANGED_HE_BSS_COLOR;
03efb863 1333 }
34fb190e 1334
b1b3297d 1335 if (params->he_cap) {
2ad7dd94
RL
1336 link_conf->he_ldpc =
1337 params->he_cap->phy_cap_info[1] &
1338 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD;
b1b3297d
MS
1339 link_conf->he_su_beamformer =
1340 params->he_cap->phy_cap_info[3] &
1341 IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER;
1342 link_conf->he_su_beamformee =
1343 params->he_cap->phy_cap_info[4] &
1344 IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE;
1345 link_conf->he_mu_beamformer =
1346 params->he_cap->phy_cap_info[4] &
1347 IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
1348 link_conf->he_full_ul_mumimo =
1349 params->he_cap->phy_cap_info[2] &
1350 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO;
1351 }
1352
2cc25e4b 1353 if (params->eht_cap) {
e3e0ca32
AD
1354 if (!link_conf->he_support)
1355 return -EOPNOTSUPP;
1356
1357 link_conf->eht_support = true;
2cc25e4b
AD
1358 link_conf->eht_puncturing = params->punct_bitmap;
1359 changed |= BSS_CHANGED_EHT_PUNCTURING;
f4d1181e
RL
1360
1361 link_conf->eht_su_beamformer =
1362 params->eht_cap->fixed.phy_cap_info[0] &
1363 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER;
1364 link_conf->eht_su_beamformee =
1365 params->eht_cap->fixed.phy_cap_info[0] &
1366 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE;
1367 link_conf->eht_mu_beamformer =
1368 params->eht_cap->fixed.phy_cap_info[7] &
1369 (IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
1370 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ |
1371 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ);
1372 } else {
1373 link_conf->eht_su_beamformer = false;
1374 link_conf->eht_su_beamformee = false;
1375 link_conf->eht_mu_beamformer = false;
2cc25e4b
AD
1376 }
1377
17196425
JC
1378 if (sdata->vif.type == NL80211_IFTYPE_AP &&
1379 params->mbssid_config.tx_wdev) {
1380 err = ieee80211_set_ap_mbssid_options(sdata,
d9f83f22
ST
1381 params->mbssid_config,
1382 link_conf);
17196425
JC
1383 if (err)
1384 return err;
1385 }
1386
34a3740d 1387 mutex_lock(&local->mtx);
d9f83f22 1388 err = ieee80211_link_use_channel(link, &params->chandef,
b4f85443 1389 IEEE80211_CHANCTX_SHARED);
4e141dad 1390 if (!err)
d9f83f22 1391 ieee80211_link_copy_chanctx_to_vlans(link, false);
34a3740d 1392 mutex_unlock(&local->mtx);
83e37e0b 1393 if (err) {
d9f83f22 1394 link_conf->beacon_int = prev_beacon_int;
aa430da4 1395 return err;
83e37e0b 1396 }
aa430da4 1397
665c93a9
JB
1398 /*
1399 * Apply control port protocol, this allows us to
1400 * not encrypt dynamic WEP control frames.
1401 */
1402 sdata->control_port_protocol = params->crypto.control_port_ethertype;
1403 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
018f6fbf
DK
1404 sdata->control_port_over_nl80211 =
1405 params->crypto.control_port_over_nl80211;
7f3f96ce
MT
1406 sdata->control_port_no_preauth =
1407 params->crypto.control_port_no_preauth;
2475b1cc 1408
665c93a9
JB
1409 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1410 vlan->control_port_protocol =
1411 params->crypto.control_port_ethertype;
1412 vlan->control_port_no_encrypt =
1413 params->crypto.control_port_no_encrypt;
018f6fbf
DK
1414 vlan->control_port_over_nl80211 =
1415 params->crypto.control_port_over_nl80211;
7f3f96ce
MT
1416 vlan->control_port_no_preauth =
1417 params->crypto.control_port_no_preauth;
665c93a9
JB
1418 }
1419
d9f83f22
ST
1420 link_conf->dtim_period = params->dtim_period;
1421 link_conf->enable_beacon = true;
1422 link_conf->allow_p2p_go_ps = sdata->vif.p2p;
1423 link_conf->twt_responder = params->twt_responder;
1424 link_conf->he_obss_pd = params->he_obss_pd;
1425 link_conf->he_bss_color = params->beacon.he_bss_color;
f276e20b 1426 sdata->vif.cfg.s1g = params->chandef.chan->band ==
1d00ce80 1427 NL80211_BAND_S1GHZ;
8860020e 1428
f276e20b 1429 sdata->vif.cfg.ssid_len = params->ssid_len;
8860020e 1430 if (params->ssid_len)
f276e20b 1431 memcpy(sdata->vif.cfg.ssid, params->ssid,
8860020e 1432 params->ssid_len);
d9f83f22 1433 link_conf->hidden_ssid =
8860020e
JB
1434 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1435
d9f83f22
ST
1436 memset(&link_conf->p2p_noa_attr, 0,
1437 sizeof(link_conf->p2p_noa_attr));
1438 link_conf->p2p_noa_attr.oppps_ctwindow =
67baf663
JD
1439 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1440 if (params->p2p_opp_ps)
d9f83f22 1441 link_conf->p2p_noa_attr.oppps_ctwindow |=
67baf663 1442 IEEE80211_P2P_OPPPS_ENABLE_BIT;
339afbf4 1443
08fad438
JM
1444 sdata->beacon_rate_set = false;
1445 if (wiphy_ext_feature_isset(local->hw.wiphy,
1446 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
1447 for (i = 0; i < NUM_NL80211_BANDS; i++) {
1448 sdata->beacon_rateidx_mask[i] =
1449 params->beacon_rate.control[i].legacy;
1450 if (sdata->beacon_rateidx_mask[i])
1451 sdata->beacon_rate_set = true;
1452 }
1453 }
1454
ba6ff70a 1455 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
d9f83f22 1456 link_conf->beacon_tx_rate = params->beacon_rate;
ba6ff70a 1457
15ddba5f
A
1458 err = ieee80211_assign_beacon(sdata, link, &params->beacon, NULL, NULL,
1459 &changed);
295b02c4
AD
1460 if (err < 0)
1461 goto error;
8860020e 1462
295b02c4
AD
1463 if (params->fils_discovery.max_interval) {
1464 err = ieee80211_set_fils_discovery(sdata,
d9f83f22
ST
1465 &params->fils_discovery,
1466 link, link_conf);
295b02c4
AD
1467 if (err < 0)
1468 goto error;
1469 changed |= BSS_CHANGED_FILS_DISCOVERY;
1470 }
1471
632189a0
AD
1472 if (params->unsol_bcast_probe_resp.interval) {
1473 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
d9f83f22
ST
1474 &params->unsol_bcast_probe_resp,
1475 link, link_conf);
632189a0
AD
1476 if (err < 0)
1477 goto error;
1478 changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP;
1479 }
1480
b327c84c 1481 err = drv_start_ap(sdata->local, sdata, link_conf);
1041638f 1482 if (err) {
d9f83f22 1483 old = sdata_dereference(link->u.ap.beacon, sdata);
7ca133bc 1484
1041638f
JB
1485 if (old)
1486 kfree_rcu(old, rcu_head);
d9f83f22 1487 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
bfd8403a 1488 sdata->u.ap.active = false;
295b02c4 1489 goto error;
1041638f
JB
1490 }
1491
057d5f4b 1492 ieee80211_recalc_dtim(local, sdata);
d9f83f22 1493 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_SSID);
d8675a63 1494 ieee80211_link_info_change_notify(sdata, link, changed);
8860020e 1495
3edaf3e6
JB
1496 netif_carrier_on(dev);
1497 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1498 netif_carrier_on(vlan->dev);
1499
665c93a9 1500 return 0;
295b02c4
AD
1501
1502error:
87a27062 1503 mutex_lock(&local->mtx);
d9f83f22 1504 ieee80211_link_release_channel(link);
87a27062
JB
1505 mutex_unlock(&local->mtx);
1506
295b02c4 1507 return err;
5dfdaf58
JB
1508}
1509
8860020e
JB
1510static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1511 struct cfg80211_beacon_data *params)
5dfdaf58 1512{
d9f83f22 1513 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
d8675a63 1514 struct ieee80211_link_data *link;
5dfdaf58 1515 struct beacon_data *old;
8860020e 1516 int err;
d8675a63 1517 struct ieee80211_bss_conf *link_conf;
15ddba5f 1518 u64 changed = 0;
5dfdaf58 1519
dbd72850 1520 sdata_assert_lock(sdata);
14db74bc 1521
d8675a63
JB
1522 link = sdata_dereference(sdata->link[params->link_id], sdata);
1523 if (!link)
1524 return -ENOLINK;
1525
1526 link_conf = link->conf;
1527
5f9404ab 1528 /* don't allow changing the beacon while a countdown is in place - offset
73da7d5b
SW
1529 * of channel switch counter may change
1530 */
d9f83f22 1531 if (link_conf->csa_active || link_conf->color_change_active)
73da7d5b
SW
1532 return -EBUSY;
1533
d8675a63 1534 old = sdata_dereference(link->u.ap.beacon, sdata);
5dfdaf58
JB
1535 if (!old)
1536 return -ENOENT;
1537
15ddba5f
A
1538 err = ieee80211_assign_beacon(sdata, link, params, NULL, NULL,
1539 &changed);
8860020e
JB
1540 if (err < 0)
1541 return err;
195b9a0f 1542
195b9a0f 1543 if (params->he_bss_color_valid &&
d9f83f22
ST
1544 params->he_bss_color.enabled != link_conf->he_bss_color.enabled) {
1545 link_conf->he_bss_color.enabled = params->he_bss_color.enabled;
15ddba5f 1546 changed |= BSS_CHANGED_HE_BSS_COLOR;
195b9a0f
LS
1547 }
1548
15ddba5f 1549 ieee80211_link_info_change_notify(sdata, link, changed);
8860020e 1550 return 0;
5dfdaf58
JB
1551}
1552
d9f83f22 1553static void ieee80211_free_next_beacon(struct ieee80211_link_data *link)
0baef284 1554{
d9f83f22 1555 if (!link->u.ap.next_beacon)
0baef284
JB
1556 return;
1557
d9f83f22 1558 kfree(link->u.ap.next_beacon->mbssid_ies);
68b9bea2 1559 kfree(link->u.ap.next_beacon->rnr_ies);
d9f83f22
ST
1560 kfree(link->u.ap.next_beacon);
1561 link->u.ap.next_beacon = NULL;
0baef284
JB
1562}
1563
7b0a0e3c
JB
1564static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
1565 unsigned int link_id)
5dfdaf58 1566{
7b20b8e8
JB
1567 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1568 struct ieee80211_sub_if_data *vlan;
1569 struct ieee80211_local *local = sdata->local;
1570 struct beacon_data *old_beacon;
1571 struct probe_resp *old_probe_resp;
295b02c4 1572 struct fils_discovery_data *old_fils_discovery;
632189a0 1573 struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp;
d2859df5 1574 struct cfg80211_chan_def chandef;
d8675a63
JB
1575 struct ieee80211_link_data *link =
1576 sdata_dereference(sdata->link[link_id], sdata);
1577 struct ieee80211_bss_conf *link_conf = link->conf;
14db74bc 1578
dbd72850
MK
1579 sdata_assert_lock(sdata);
1580
d9f83f22 1581 old_beacon = sdata_dereference(link->u.ap.beacon, sdata);
7b20b8e8 1582 if (!old_beacon)
5dfdaf58 1583 return -ENOENT;
d9f83f22 1584 old_probe_resp = sdata_dereference(link->u.ap.probe_resp,
bfd8403a 1585 sdata);
d9f83f22 1586 old_fils_discovery = sdata_dereference(link->u.ap.fils_discovery,
295b02c4 1587 sdata);
632189a0 1588 old_unsol_bcast_probe_resp =
d9f83f22 1589 sdata_dereference(link->u.ap.unsol_bcast_probe_resp,
632189a0 1590 sdata);
5dfdaf58 1591
a23d7f5b 1592 /* abort any running channel switch or color change */
59af6928 1593 mutex_lock(&local->mtx);
d9f83f22 1594 link_conf->csa_active = false;
a23d7f5b 1595 link_conf->color_change_active = false;
d9f83f22 1596 if (link->csa_block_tx) {
a46992b4
LC
1597 ieee80211_wake_vif_queues(local, sdata,
1598 IEEE80211_QUEUE_STOP_REASON_CSA);
d9f83f22 1599 link->csa_block_tx = false;
a46992b4
LC
1600 }
1601
59af6928
MK
1602 mutex_unlock(&local->mtx);
1603
d9f83f22 1604 ieee80211_free_next_beacon(link);
1f3b8a2b 1605
7b20b8e8 1606 /* turn off carrier for this interface and dependent VLANs */
3edaf3e6
JB
1607 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1608 netif_carrier_off(vlan->dev);
1609 netif_carrier_off(dev);
1610
7b20b8e8 1611 /* remove beacon and probe response */
bfd8403a 1612 sdata->u.ap.active = false;
d9f83f22
ST
1613 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1614 RCU_INIT_POINTER(link->u.ap.probe_resp, NULL);
1615 RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL);
1616 RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL);
7b20b8e8
JB
1617 kfree_rcu(old_beacon, rcu_head);
1618 if (old_probe_resp)
1619 kfree_rcu(old_probe_resp, rcu_head);
295b02c4
AD
1620 if (old_fils_discovery)
1621 kfree_rcu(old_fils_discovery, rcu_head);
632189a0
AD
1622 if (old_unsol_bcast_probe_resp)
1623 kfree_rcu(old_unsol_bcast_probe_resp, rcu_head);
8860020e 1624
d9f83f22
ST
1625 kfree(link_conf->ftmr_params);
1626 link_conf->ftmr_params = NULL;
bc847970 1627
0eb38842
AD
1628 sdata->vif.mbssid_tx_vif = NULL;
1629 link_conf->bssid_index = 0;
1630 link_conf->nontransmitted = false;
1631 link_conf->ema_ap = false;
1632 link_conf->bssid_indicator = 0;
1633
e716251d 1634 __sta_info_flush(sdata, true);
7907c7d3 1635 ieee80211_free_keys(sdata, true);
75de9113 1636
d9f83f22 1637 link_conf->enable_beacon = false;
08fad438 1638 sdata->beacon_rate_set = false;
f276e20b 1639 sdata->vif.cfg.ssid_len = 0;
d6a83228 1640 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
d8675a63 1641 ieee80211_link_info_change_notify(sdata, link,
7fc83a2b 1642 BSS_CHANGED_BEACON_ENABLED);
8860020e 1643
a6b368f6 1644 if (sdata->wdev.cac_started) {
d9f83f22 1645 chandef = link_conf->chandef;
766d2601 1646 wiphy_delayed_work_cancel(wiphy, &link->dfs_cac_timer_work);
d2859df5
JD
1647 cfg80211_cac_event(sdata->dev, &chandef,
1648 NL80211_RADAR_CAC_ABORTED,
a6b368f6
SW
1649 GFP_KERNEL);
1650 }
1651
b327c84c 1652 drv_stop_ap(sdata->local, sdata, link_conf);
1041638f 1653
7b20b8e8
JB
1654 /* free all potentially still buffered bcast frames */
1655 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
6b07d9ca 1656 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
7b20b8e8 1657
34a3740d 1658 mutex_lock(&local->mtx);
d9f83f22
ST
1659 ieee80211_link_copy_chanctx_to_vlans(link, true);
1660 ieee80211_link_release_channel(link);
34a3740d 1661 mutex_unlock(&local->mtx);
55de908a 1662
2d0ddec5 1663 return 0;
5dfdaf58
JB
1664}
1665
d582cffb
JB
1666static int sta_apply_auth_flags(struct ieee80211_local *local,
1667 struct sta_info *sta,
1668 u32 mask, u32 set)
1669{
1670 int ret;
1671
1672 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1673 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1674 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1675 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1676 if (ret)
1677 return ret;
1678 }
1679
1680 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1681 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1682 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
c23e31cf
MP
1683 /*
1684 * When peer becomes associated, init rate control as
1685 * well. Some drivers require rate control initialized
1686 * before drv_sta_state() is called.
1687 */
44674d9c 1688 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
c23e31cf
MP
1689 rate_control_rate_init(sta);
1690
d582cffb
JB
1691 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1692 if (ret)
1693 return ret;
1694 }
1695
1696 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1697 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1698 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1699 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1700 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1701 else
1702 ret = 0;
1703 if (ret)
1704 return ret;
1705 }
1706
1707 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1708 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1709 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1710 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1711 if (ret)
1712 return ret;
1713 }
1714
1715 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1716 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1717 test_sta_flag(sta, WLAN_STA_AUTH)) {
1718 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1719 if (ret)
1720 return ret;
1721 }
1722
1723 return 0;
1724}
1725
13657702
JB
1726static void sta_apply_mesh_params(struct ieee80211_local *local,
1727 struct sta_info *sta,
1728 struct station_parameters *params)
1729{
1730#ifdef CONFIG_MAC80211_MESH
1731 struct ieee80211_sub_if_data *sdata = sta->sdata;
15ddba5f 1732 u64 changed = 0;
13657702
JB
1733
1734 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1735 switch (params->plink_state) {
1736 case NL80211_PLINK_ESTAB:
1737 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1738 changed = mesh_plink_inc_estab_count(sdata);
1739 sta->mesh->plink_state = params->plink_state;
7d27a0ba 1740 sta->mesh->aid = params->peer_aid;
13657702
JB
1741
1742 ieee80211_mps_sta_status_update(sta);
1743 changed |= ieee80211_mps_set_sta_local_pm(sta,
1744 sdata->u.mesh.mshcfg.power_mode);
67fc0554
JH
1745
1746 ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg);
1747 /* init at low value */
1748 ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10);
1749
13657702
JB
1750 break;
1751 case NL80211_PLINK_LISTEN:
1752 case NL80211_PLINK_BLOCKED:
1753 case NL80211_PLINK_OPN_SNT:
1754 case NL80211_PLINK_OPN_RCVD:
1755 case NL80211_PLINK_CNF_RCVD:
1756 case NL80211_PLINK_HOLDING:
1757 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1758 changed = mesh_plink_dec_estab_count(sdata);
1759 sta->mesh->plink_state = params->plink_state;
1760
1761 ieee80211_mps_sta_status_update(sta);
1762 changed |= ieee80211_mps_set_sta_local_pm(sta,
1763 NL80211_MESH_POWER_UNKNOWN);
1764 break;
1765 default:
1766 /* nothing */
1767 break;
1768 }
1769 }
1770
1771 switch (params->plink_action) {
1772 case NL80211_PLINK_ACTION_NO_ACTION:
1773 /* nothing */
1774 break;
1775 case NL80211_PLINK_ACTION_OPEN:
1776 changed |= mesh_plink_open(sta);
1777 break;
1778 case NL80211_PLINK_ACTION_BLOCK:
1779 changed |= mesh_plink_block(sta);
1780 break;
1781 }
1782
1783 if (params->local_pm)
1784 changed |= ieee80211_mps_set_sta_local_pm(sta,
1785 params->local_pm);
1786
1787 ieee80211_mbss_info_change_notify(sdata, changed);
1788#endif
1789}
1790
b95eb7f0 1791static int sta_link_apply_parameters(struct ieee80211_local *local,
9aebce6c 1792 struct sta_info *sta, bool new_link,
b95eb7f0
ST
1793 struct link_station_parameters *params)
1794{
1795 int ret = 0;
1796 struct ieee80211_supported_band *sband;
1797 struct ieee80211_sub_if_data *sdata = sta->sdata;
1798 u32 link_id = params->link_id < 0 ? 0 : params->link_id;
d8675a63
JB
1799 struct ieee80211_link_data *link =
1800 sdata_dereference(sdata->link[link_id], sdata);
b95eb7f0
ST
1801 struct link_sta_info *link_sta =
1802 rcu_dereference_protected(sta->link[link_id],
1803 lockdep_is_held(&local->sta_mtx));
1804
b303835d
JB
1805 /*
1806 * If there are no changes, then accept a link that doesn't exist,
1807 * unless it's a new link.
1808 */
1809 if (params->link_id < 0 && !new_link &&
1810 !params->link_mac && !params->txpwr_set &&
1811 !params->supported_rates_len &&
1812 !params->ht_capa && !params->vht_capa &&
1813 !params->he_capa && !params->eht_capa &&
1814 !params->opmode_notif_used)
1815 return 0;
1816
d8675a63 1817 if (!link || !link_sta)
b95eb7f0
ST
1818 return -EINVAL;
1819
d8675a63 1820 sband = ieee80211_get_link_sband(link);
b95eb7f0
ST
1821 if (!sband)
1822 return -EINVAL;
1823
1824 if (params->link_mac) {
9aebce6c
JB
1825 if (new_link) {
1826 memcpy(link_sta->addr, params->link_mac, ETH_ALEN);
1827 memcpy(link_sta->pub->addr, params->link_mac, ETH_ALEN);
1828 } else if (!ether_addr_equal(link_sta->addr,
1829 params->link_mac)) {
1830 return -EINVAL;
1831 }
b303835d
JB
1832 } else if (new_link) {
1833 return -EINVAL;
b95eb7f0
ST
1834 }
1835
1836 if (params->txpwr_set) {
1837 link_sta->pub->txpwr.type = params->txpwr.type;
1838 if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
1839 link_sta->pub->txpwr.power = params->txpwr.power;
1840 ret = drv_sta_set_txpwr(local, sdata, sta);
1841 if (ret)
1842 return ret;
1843 }
1844
1845 if (params->supported_rates &&
1846 params->supported_rates_len) {
3dc05935 1847 ieee80211_parse_bitrates(link->conf->chandef.width,
b95eb7f0
ST
1848 sband, params->supported_rates,
1849 params->supported_rates_len,
1850 &link_sta->pub->supp_rates[sband->band]);
1851 }
1852
1853 if (params->ht_capa)
1854 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1855 params->ht_capa, link_sta);
1856
1857 /* VHT can override some HT caps such as the A-MSDU max length */
1858 if (params->vht_capa)
1859 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1860 params->vht_capa, link_sta);
1861
1862 if (params->he_capa)
1863 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1864 (void *)params->he_capa,
1865 params->he_capa_len,
1866 (void *)params->he_6ghz_capa,
1867 link_sta);
1868
e8edb346 1869 if (params->he_capa && params->eht_capa)
b95eb7f0
ST
1870 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
1871 (u8 *)params->he_capa,
1872 params->he_capa_len,
1873 params->eht_capa,
1874 params->eht_capa_len,
1875 link_sta);
1876
1877 if (params->opmode_notif_used) {
1878 /* returned value is only needed for rc update, but the
1879 * rc isn't initialized here yet, so ignore it
1880 */
1881 __ieee80211_vht_handle_opmode(sdata, link_sta,
1882 params->opmode_notif,
1883 sband->band);
1884 }
1885
1886 return ret;
1887}
1888
d9a7ddb0
JB
1889static int sta_apply_parameters(struct ieee80211_local *local,
1890 struct sta_info *sta,
1891 struct station_parameters *params)
4fd6931e 1892{
d0709a65 1893 struct ieee80211_sub_if_data *sdata = sta->sdata;
eccb8e8f 1894 u32 mask, set;
45b12570 1895 int ret = 0;
ae5eb026 1896
eccb8e8f
JB
1897 mask = params->sta_flags_mask;
1898 set = params->sta_flags_set;
73651ee6 1899
d582cffb
JB
1900 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1901 /*
1902 * In mesh mode, ASSOCIATED isn't part of the nl80211
1903 * API but must follow AUTHENTICATED for driver state.
1904 */
1905 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1906 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1907 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1908 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
77ee7c89
JB
1909 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1910 /*
1911 * TDLS -- everything follows authorized, but
1912 * only becoming authorized is possible, not
1913 * going back
1914 */
1915 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1916 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1917 BIT(NL80211_STA_FLAG_ASSOCIATED);
1918 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1919 BIT(NL80211_STA_FLAG_ASSOCIATED);
1920 }
eccb8e8f 1921 }
4fd6931e 1922
2c44be81
JB
1923 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1924 local->hw.queues >= IEEE80211_NUM_ACS)
1925 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1926
44674d9c 1927 /* auth flags will be set later for TDLS,
b18dacab 1928 * and for unassociated stations that move to associated */
44674d9c
AB
1929 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1930 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1931 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
68885a54
AN
1932 ret = sta_apply_auth_flags(local, sta, mask, set);
1933 if (ret)
1934 return ret;
1935 }
d9a7ddb0 1936
eccb8e8f 1937 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
eccb8e8f 1938 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
c2c98fde
JB
1939 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1940 else
1941 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
eccb8e8f 1942 }
4fd6931e 1943
eccb8e8f 1944 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
93f0490e 1945 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
eccb8e8f 1946 if (set & BIT(NL80211_STA_FLAG_MFP))
c2c98fde
JB
1947 set_sta_flag(sta, WLAN_STA_MFP);
1948 else
1949 clear_sta_flag(sta, WLAN_STA_MFP);
4fd6931e 1950 }
b39c48fa 1951
07ba55d7 1952 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
07ba55d7 1953 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
c2c98fde
JB
1954 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1955 else
1956 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
07ba55d7 1957 }
4fd6931e 1958
9041c1fa
AN
1959 /* mark TDLS channel switch support, if the AP allows it */
1960 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
ab3a830d 1961 !sdata->deflink.u.mgd.tdls_chan_switch_prohibited &&
9041c1fa
AN
1962 params->ext_capab_len >= 4 &&
1963 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1964 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1965
b98fb44f 1966 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
82c0cc90 1967 !sdata->u.mgd.tdls_wider_bw_prohibited &&
b98fb44f
AN
1968 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1969 params->ext_capab_len >= 8 &&
1970 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1971 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1972
3b9ce80c
JB
1973 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1974 sta->sta.uapsd_queues = params->uapsd_queues;
1975 sta->sta.max_sp = params->max_sp;
1976 }
9533b4ac 1977
175ad2ec
JB
1978 ieee80211_sta_set_max_amsdu_subframes(sta, params->ext_capab,
1979 params->ext_capab_len);
506bcfa8 1980
51b50fbe
JB
1981 /*
1982 * cfg80211 validates this (1-2007) and allows setting the AID
1983 * only when creating a new station entry
1984 */
1985 if (params->aid)
1986 sta->sta.aid = params->aid;
1987
73651ee6 1988 /*
ba23d206
JB
1989 * Some of the following updates would be racy if called on an
1990 * existing station, via ieee80211_change_station(). However,
1991 * all such changes are rejected by cfg80211 except for updates
1992 * changing the supported rates on an existing but not yet used
1993 * TDLS peer.
73651ee6
JB
1994 */
1995
4fd6931e
JB
1996 if (params->listen_interval >= 0)
1997 sta->listen_interval = params->listen_interval;
1998
9aebce6c
JB
1999 ret = sta_link_apply_parameters(local, sta, false,
2000 &params->link_sta_params);
b95eb7f0
ST
2001 if (ret)
2002 return ret;
b1bce14a 2003
52cfa1d6
AB
2004 if (params->support_p2p_ps >= 0)
2005 sta->sta.support_p2p_ps = params->support_p2p_ps;
2006
13657702
JB
2007 if (ieee80211_vif_is_mesh(&sdata->vif))
2008 sta_apply_mesh_params(local, sta, params);
d9a7ddb0 2009
b4809e94 2010 if (params->airtime_weight)
942741da 2011 sta->airtime_weight = params->airtime_weight;
b4809e94 2012
68885a54 2013 /* set the STA state after all sta info from usermode has been set */
44674d9c
AB
2014 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
2015 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
68885a54
AN
2016 ret = sta_apply_auth_flags(local, sta, mask, set);
2017 if (ret)
2018 return ret;
2019 }
2020
3e0278b7
AO
2021 /* Mark the STA as MLO if MLD MAC address is available */
2022 if (params->link_sta_params.mld_mac)
2023 sta->sta.mlo = true;
2024
d9a7ddb0 2025 return 0;
4fd6931e
JB
2026}
2027
2028static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
3b3a0162
JB
2029 const u8 *mac,
2030 struct station_parameters *params)
4fd6931e 2031{
14db74bc 2032 struct ieee80211_local *local = wiphy_priv(wiphy);
4fd6931e
JB
2033 struct sta_info *sta;
2034 struct ieee80211_sub_if_data *sdata;
73651ee6 2035 int err;
4fd6931e 2036
4fd6931e
JB
2037 if (params->vlan) {
2038 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
2039
05c914fe
JB
2040 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2041 sdata->vif.type != NL80211_IFTYPE_AP)
4fd6931e
JB
2042 return -EINVAL;
2043 } else
2044 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2045
b203ca39 2046 if (ether_addr_equal(mac, sdata->vif.addr))
03e4497e
JB
2047 return -EINVAL;
2048
52dba8d7 2049 if (!is_valid_ether_addr(mac))
03e4497e
JB
2050 return -EINVAL;
2051
5fd2f91a
JB
2052 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) &&
2053 sdata->vif.type == NL80211_IFTYPE_STATION &&
2054 !sdata->u.mgd.associated)
2055 return -EINVAL;
2056
206c8c06
JB
2057 /*
2058 * If we have a link ID, it can be a non-MLO station on an AP MLD,
2059 * but we need to have a link_mac in that case as well, so use the
2060 * STA's MAC address in that case.
2061 */
f36fe0a2
JB
2062 if (params->link_sta_params.link_id >= 0)
2063 sta = sta_info_alloc_with_link(sdata, mac,
2064 params->link_sta_params.link_id,
206c8c06 2065 params->link_sta_params.link_mac ?: mac,
f36fe0a2
JB
2066 GFP_KERNEL);
2067 else
2068 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
2069
73651ee6
JB
2070 if (!sta)
2071 return -ENOMEM;
4fd6931e 2072
44674d9c
AB
2073 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
2074 sta->sta.tdls = true;
4fd6931e 2075
b95eb7f0
ST
2076 /* Though the mutex is not needed here (since the station is not
2077 * visible yet), sta_apply_parameters (and inner functions) require
2078 * the mutex due to other paths.
2079 */
2080 mutex_lock(&local->sta_mtx);
d9a7ddb0 2081 err = sta_apply_parameters(local, sta, params);
b95eb7f0 2082 mutex_unlock(&local->sta_mtx);
d9a7ddb0
JB
2083 if (err) {
2084 sta_info_free(local, sta);
2085 return err;
2086 }
4fd6931e 2087
d64cf63e 2088 /*
44674d9c
AB
2089 * for TDLS and for unassociated station, rate control should be
2090 * initialized only when rates are known and station is marked
2091 * authorized/associated
d64cf63e 2092 */
44674d9c
AB
2093 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
2094 test_sta_flag(sta, WLAN_STA_ASSOC))
d64cf63e 2095 rate_control_rate_init(sta);
4fd6931e 2096
4ebdce1d 2097 return sta_info_insert(sta);
4fd6931e
JB
2098}
2099
2100static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
89c771e5 2101 struct station_del_parameters *params)
4fd6931e 2102{
14db74bc 2103 struct ieee80211_sub_if_data *sdata;
4fd6931e 2104
14db74bc
JB
2105 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2106
89c771e5
JM
2107 if (params->mac)
2108 return sta_info_destroy_addr_bss(sdata, params->mac);
4fd6931e 2109
b998e8bb 2110 sta_info_flush(sdata);
4fd6931e
JB
2111 return 0;
2112}
2113
2114static int ieee80211_change_station(struct wiphy *wiphy,
3b3a0162 2115 struct net_device *dev, const u8 *mac,
4fd6931e
JB
2116 struct station_parameters *params)
2117{
abe60632 2118 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
14db74bc 2119 struct ieee80211_local *local = wiphy_priv(wiphy);
4fd6931e
JB
2120 struct sta_info *sta;
2121 struct ieee80211_sub_if_data *vlansdata;
77ee7c89 2122 enum cfg80211_station_type statype;
35b88623 2123 int err;
4fd6931e 2124
87be1e1e 2125 mutex_lock(&local->sta_mtx);
98dd6a57 2126
0e5ded5a 2127 sta = sta_info_get_bss(sdata, mac);
98dd6a57 2128 if (!sta) {
77ee7c89
JB
2129 err = -ENOENT;
2130 goto out_err;
98dd6a57 2131 }
4fd6931e 2132
77ee7c89
JB
2133 switch (sdata->vif.type) {
2134 case NL80211_IFTYPE_MESH_POINT:
a6dad6a2 2135 if (sdata->u.mesh.user_mpm)
eef941e6 2136 statype = CFG80211_STA_MESH_PEER_USER;
77ee7c89 2137 else
eef941e6 2138 statype = CFG80211_STA_MESH_PEER_KERNEL;
77ee7c89
JB
2139 break;
2140 case NL80211_IFTYPE_ADHOC:
2141 statype = CFG80211_STA_IBSS;
2142 break;
2143 case NL80211_IFTYPE_STATION:
2144 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2145 statype = CFG80211_STA_AP_STA;
2146 break;
2147 }
2148 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2149 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
2150 else
2151 statype = CFG80211_STA_TDLS_PEER_SETUP;
2152 break;
2153 case NL80211_IFTYPE_AP:
2154 case NL80211_IFTYPE_AP_VLAN:
44674d9c
AB
2155 if (test_sta_flag(sta, WLAN_STA_ASSOC))
2156 statype = CFG80211_STA_AP_CLIENT;
2157 else
2158 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
77ee7c89
JB
2159 break;
2160 default:
2161 err = -EOPNOTSUPP;
2162 goto out_err;
bdd90d5e
JB
2163 }
2164
77ee7c89
JB
2165 err = cfg80211_check_station_change(wiphy, params, statype);
2166 if (err)
2167 goto out_err;
2168
d0709a65 2169 if (params->vlan && params->vlan != sta->sdata->dev) {
4fd6931e
JB
2170 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
2171
9bc383de 2172 if (params->vlan->ieee80211_ptr->use_4addr) {
3305443c 2173 if (vlansdata->u.vlan.sta) {
77ee7c89
JB
2174 err = -EBUSY;
2175 goto out_err;
3305443c 2176 }
f14543ee 2177
cf778b00 2178 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
49ddf8e6 2179 __ieee80211_check_fast_rx_iface(vlansdata);
1ff4e8f2 2180 drv_sta_set_4addr(local, sta->sdata, &sta->sta, true);
7e3ed02c
FF
2181 }
2182
2183 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
dd0b4553
SM
2184 sta->sdata->u.vlan.sta) {
2185 ieee80211_clear_fast_rx(sta);
0c2bef46 2186 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
dd0b4553 2187 }
72f15d53
MB
2188
2189 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2190 ieee80211_vif_dec_num_mcast(sta->sdata);
f14543ee 2191
14db74bc 2192 sta->sdata = vlansdata;
464daaf0 2193 ieee80211_check_fast_xmit(sta);
7e3ed02c 2194
3e493173 2195 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
72f15d53 2196 ieee80211_vif_inc_num_mcast(sta->sdata);
3e493173
JM
2197 cfg80211_send_layer2_update(sta->sdata->dev,
2198 sta->sta.addr);
2199 }
4fd6931e
JB
2200 }
2201
d8675a63
JB
2202 /* we use sta_info_get_bss() so this might be different */
2203 if (sdata != sta->sdata) {
2204 mutex_lock_nested(&sta->sdata->wdev.mtx, 1);
2205 err = sta_apply_parameters(local, sta, params);
2206 mutex_unlock(&sta->sdata->wdev.mtx);
2207 } else {
2208 err = sta_apply_parameters(local, sta, params);
2209 }
77ee7c89
JB
2210 if (err)
2211 goto out_err;
4fd6931e 2212
87be1e1e 2213 mutex_unlock(&local->sta_mtx);
98dd6a57 2214
808118cb 2215 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
ab095877 2216 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
4a733ef1 2217 ieee80211_recalc_ps(local);
ab095877
EP
2218 ieee80211_recalc_ps_vif(sdata);
2219 }
77ee7c89 2220
4fd6931e 2221 return 0;
77ee7c89
JB
2222out_err:
2223 mutex_unlock(&local->sta_mtx);
2224 return err;
4fd6931e
JB
2225}
2226
c5dd9c2b
LCC
2227#ifdef CONFIG_MAC80211_MESH
2228static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 2229 const u8 *dst, const u8 *next_hop)
c5dd9c2b 2230{
14db74bc 2231 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
2232 struct mesh_path *mpath;
2233 struct sta_info *sta;
c5dd9c2b 2234
14db74bc
JB
2235 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2236
d0709a65 2237 rcu_read_lock();
abe60632 2238 sta = sta_info_get(sdata, next_hop);
d0709a65
JB
2239 if (!sta) {
2240 rcu_read_unlock();
c5dd9c2b 2241 return -ENOENT;
d0709a65 2242 }
c5dd9c2b 2243
ae76eef0
BC
2244 mpath = mesh_path_add(sdata, dst);
2245 if (IS_ERR(mpath)) {
d0709a65 2246 rcu_read_unlock();
ae76eef0 2247 return PTR_ERR(mpath);
d0709a65 2248 }
c5dd9c2b 2249
c5dd9c2b 2250 mesh_path_fix_nexthop(mpath, sta);
d0709a65 2251
c5dd9c2b
LCC
2252 rcu_read_unlock();
2253 return 0;
2254}
2255
2256static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
3b3a0162 2257 const u8 *dst)
c5dd9c2b 2258{
f698d856
JBG
2259 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2260
c5dd9c2b 2261 if (dst)
bf7cd94d 2262 return mesh_path_del(sdata, dst);
c5dd9c2b 2263
ece1a2e7 2264 mesh_path_flush_by_iface(sdata);
c5dd9c2b
LCC
2265 return 0;
2266}
2267
3b3a0162
JB
2268static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
2269 const u8 *dst, const u8 *next_hop)
c5dd9c2b 2270{
14db74bc 2271 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
2272 struct mesh_path *mpath;
2273 struct sta_info *sta;
2274
14db74bc
JB
2275 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2276
d0709a65
JB
2277 rcu_read_lock();
2278
abe60632 2279 sta = sta_info_get(sdata, next_hop);
d0709a65
JB
2280 if (!sta) {
2281 rcu_read_unlock();
c5dd9c2b 2282 return -ENOENT;
d0709a65 2283 }
c5dd9c2b 2284
bf7cd94d 2285 mpath = mesh_path_lookup(sdata, dst);
c5dd9c2b
LCC
2286 if (!mpath) {
2287 rcu_read_unlock();
c5dd9c2b
LCC
2288 return -ENOENT;
2289 }
2290
2291 mesh_path_fix_nexthop(mpath, sta);
d0709a65 2292
c5dd9c2b
LCC
2293 rcu_read_unlock();
2294 return 0;
2295}
2296
2297static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
2298 struct mpath_info *pinfo)
2299{
a3836e02
JB
2300 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
2301
2302 if (next_hop_sta)
2303 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
c5dd9c2b 2304 else
c84a67a2 2305 eth_zero_addr(next_hop);
c5dd9c2b 2306
7ce8c7a3
LAYS
2307 memset(pinfo, 0, sizeof(*pinfo));
2308
2bdaf386 2309 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
f5ea9120 2310
c5dd9c2b 2311 pinfo->filled = MPATH_INFO_FRAME_QLEN |
d19b3bf6 2312 MPATH_INFO_SN |
c5dd9c2b
LCC
2313 MPATH_INFO_METRIC |
2314 MPATH_INFO_EXPTIME |
2315 MPATH_INFO_DISCOVERY_TIMEOUT |
2316 MPATH_INFO_DISCOVERY_RETRIES |
cc241636 2317 MPATH_INFO_FLAGS |
540bbcb9
JH
2318 MPATH_INFO_HOP_COUNT |
2319 MPATH_INFO_PATH_CHANGE;
c5dd9c2b
LCC
2320
2321 pinfo->frame_qlen = mpath->frame_queue.qlen;
d19b3bf6 2322 pinfo->sn = mpath->sn;
c5dd9c2b
LCC
2323 pinfo->metric = mpath->metric;
2324 if (time_before(jiffies, mpath->exp_time))
2325 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
2326 pinfo->discovery_timeout =
2327 jiffies_to_msecs(mpath->discovery_timeout);
2328 pinfo->discovery_retries = mpath->discovery_retries;
c5dd9c2b
LCC
2329 if (mpath->flags & MESH_PATH_ACTIVE)
2330 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
2331 if (mpath->flags & MESH_PATH_RESOLVING)
2332 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
d19b3bf6
RP
2333 if (mpath->flags & MESH_PATH_SN_VALID)
2334 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
c5dd9c2b
LCC
2335 if (mpath->flags & MESH_PATH_FIXED)
2336 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
7ce8c7a3
LAYS
2337 if (mpath->flags & MESH_PATH_RESOLVED)
2338 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
cc241636 2339 pinfo->hop_count = mpath->hop_count;
540bbcb9 2340 pinfo->path_change_count = mpath->path_change_count;
c5dd9c2b
LCC
2341}
2342
2343static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
2344 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
2345
2346{
14db74bc 2347 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
2348 struct mesh_path *mpath;
2349
14db74bc
JB
2350 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2351
c5dd9c2b 2352 rcu_read_lock();
bf7cd94d 2353 mpath = mesh_path_lookup(sdata, dst);
c5dd9c2b
LCC
2354 if (!mpath) {
2355 rcu_read_unlock();
2356 return -ENOENT;
2357 }
2358 memcpy(dst, mpath->dst, ETH_ALEN);
2359 mpath_set_pinfo(mpath, next_hop, pinfo);
2360 rcu_read_unlock();
2361 return 0;
2362}
2363
2364static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
3b3a0162
JB
2365 int idx, u8 *dst, u8 *next_hop,
2366 struct mpath_info *pinfo)
c5dd9c2b 2367{
14db74bc 2368 struct ieee80211_sub_if_data *sdata;
c5dd9c2b
LCC
2369 struct mesh_path *mpath;
2370
14db74bc
JB
2371 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2372
c5dd9c2b 2373 rcu_read_lock();
bf7cd94d 2374 mpath = mesh_path_lookup_by_idx(sdata, idx);
c5dd9c2b
LCC
2375 if (!mpath) {
2376 rcu_read_unlock();
2377 return -ENOENT;
2378 }
2379 memcpy(dst, mpath->dst, ETH_ALEN);
2380 mpath_set_pinfo(mpath, next_hop, pinfo);
2381 rcu_read_unlock();
2382 return 0;
2383}
93da9cc1 2384
a2db2ed3
HR
2385static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
2386 struct mpath_info *pinfo)
2387{
2388 memset(pinfo, 0, sizeof(*pinfo));
2389 memcpy(mpp, mpath->mpp, ETH_ALEN);
2390
2bdaf386 2391 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
a2db2ed3
HR
2392}
2393
2394static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
2395 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
2396
2397{
2398 struct ieee80211_sub_if_data *sdata;
2399 struct mesh_path *mpath;
2400
2401 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2402
2403 rcu_read_lock();
2404 mpath = mpp_path_lookup(sdata, dst);
2405 if (!mpath) {
2406 rcu_read_unlock();
2407 return -ENOENT;
2408 }
2409 memcpy(dst, mpath->dst, ETH_ALEN);
2410 mpp_set_pinfo(mpath, mpp, pinfo);
2411 rcu_read_unlock();
2412 return 0;
2413}
2414
2415static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
2416 int idx, u8 *dst, u8 *mpp,
2417 struct mpath_info *pinfo)
2418{
2419 struct ieee80211_sub_if_data *sdata;
2420 struct mesh_path *mpath;
2421
2422 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2423
2424 rcu_read_lock();
2425 mpath = mpp_path_lookup_by_idx(sdata, idx);
2426 if (!mpath) {
2427 rcu_read_unlock();
2428 return -ENOENT;
2429 }
2430 memcpy(dst, mpath->dst, ETH_ALEN);
2431 mpp_set_pinfo(mpath, mpp, pinfo);
2432 rcu_read_unlock();
2433 return 0;
2434}
2435
24bdd9f4 2436static int ieee80211_get_mesh_config(struct wiphy *wiphy,
93da9cc1 2437 struct net_device *dev,
2438 struct mesh_config *conf)
2439{
2440 struct ieee80211_sub_if_data *sdata;
2441 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2442
93da9cc1 2443 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
2444 return 0;
2445}
2446
2447static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
2448{
2449 return (mask >> (parm-1)) & 0x1;
2450}
2451
c80d545d
JC
2452static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
2453 const struct mesh_setup *setup)
2454{
2455 u8 *new_ie;
4bb62344
CYY
2456 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
2457 struct ieee80211_sub_if_data, u.mesh);
08fad438 2458 int i;
c80d545d 2459
581a8b0f 2460 /* allocate information elements */
c80d545d 2461 new_ie = NULL;
c80d545d 2462
581a8b0f
JC
2463 if (setup->ie_len) {
2464 new_ie = kmemdup(setup->ie, setup->ie_len,
c80d545d
JC
2465 GFP_KERNEL);
2466 if (!new_ie)
2467 return -ENOMEM;
2468 }
581a8b0f
JC
2469 ifmsh->ie_len = setup->ie_len;
2470 ifmsh->ie = new_ie;
c80d545d
JC
2471
2472 /* now copy the rest of the setup parameters */
2473 ifmsh->mesh_id_len = setup->mesh_id_len;
2474 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
d299a1f2 2475 ifmsh->mesh_sp_id = setup->sync_method;
c80d545d
JC
2476 ifmsh->mesh_pp_id = setup->path_sel_proto;
2477 ifmsh->mesh_pm_id = setup->path_metric;
a6dad6a2 2478 ifmsh->user_mpm = setup->user_mpm;
0d4261ad 2479 ifmsh->mesh_auth_id = setup->auth_id;
b130e5ce 2480 ifmsh->security = IEEE80211_MESH_SEC_NONE;
0ab2e55d 2481 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
b130e5ce
JC
2482 if (setup->is_authenticated)
2483 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
2484 if (setup->is_secure)
2485 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
c80d545d 2486
4bb62344
CYY
2487 /* mcast rate setting in Mesh Node */
2488 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
2489 sizeof(setup->mcast_rate));
ffb3cf30 2490 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
4bb62344 2491
9bdbf04d
MP
2492 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
2493 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
2494
08fad438
JM
2495 sdata->beacon_rate_set = false;
2496 if (wiphy_ext_feature_isset(sdata->local->hw.wiphy,
2497 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
2498 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2499 sdata->beacon_rateidx_mask[i] =
2500 setup->beacon_rate.control[i].legacy;
2501 if (sdata->beacon_rateidx_mask[i])
2502 sdata->beacon_rate_set = true;
2503 }
2504 }
2505
c80d545d
JC
2506 return 0;
2507}
2508
24bdd9f4 2509static int ieee80211_update_mesh_config(struct wiphy *wiphy,
29cbe68c
JB
2510 struct net_device *dev, u32 mask,
2511 const struct mesh_config *nconf)
93da9cc1 2512{
2513 struct mesh_config *conf;
2514 struct ieee80211_sub_if_data *sdata;
63c5723b
RP
2515 struct ieee80211_if_mesh *ifmsh;
2516
93da9cc1 2517 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
63c5723b 2518 ifmsh = &sdata->u.mesh;
93da9cc1 2519
93da9cc1 2520 /* Set the config options which we are interested in setting */
2521 conf = &(sdata->u.mesh.mshcfg);
2522 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
2523 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
2524 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
2525 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
2526 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
2527 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
2528 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
2529 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
2530 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
2531 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
2532 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
2533 conf->dot11MeshTTL = nconf->dot11MeshTTL;
45904f21 2534 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
58886a90 2535 conf->element_ttl = nconf->element_ttl;
146bb483
TP
2536 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
2537 if (ifmsh->user_mpm)
2538 return -EBUSY;
93da9cc1 2539 conf->auto_open_plinks = nconf->auto_open_plinks;
146bb483 2540 }
d299a1f2
JC
2541 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
2542 conf->dot11MeshNbrOffsetMaxNeighbor =
2543 nconf->dot11MeshNbrOffsetMaxNeighbor;
93da9cc1 2544 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
2545 conf->dot11MeshHWMPmaxPREQretries =
2546 nconf->dot11MeshHWMPmaxPREQretries;
2547 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
2548 conf->path_refresh_time = nconf->path_refresh_time;
2549 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
2550 conf->min_discovery_timeout = nconf->min_discovery_timeout;
2551 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
2552 conf->dot11MeshHWMPactivePathTimeout =
2553 nconf->dot11MeshHWMPactivePathTimeout;
2554 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
2555 conf->dot11MeshHWMPpreqMinInterval =
2556 nconf->dot11MeshHWMPpreqMinInterval;
dca7e943
TP
2557 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
2558 conf->dot11MeshHWMPperrMinInterval =
2559 nconf->dot11MeshHWMPperrMinInterval;
93da9cc1 2560 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2561 mask))
2562 conf->dot11MeshHWMPnetDiameterTraversalTime =
2563 nconf->dot11MeshHWMPnetDiameterTraversalTime;
63c5723b
RP
2564 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
2565 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
2566 ieee80211_mesh_root_setup(ifmsh);
2567 }
16dd7267 2568 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
c6133661
TP
2569 /* our current gate announcement implementation rides on root
2570 * announcements, so require this ifmsh to also be a root node
2571 * */
2572 if (nconf->dot11MeshGateAnnouncementProtocol &&
dbb912cd
CYY
2573 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
2574 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
c6133661
TP
2575 ieee80211_mesh_root_setup(ifmsh);
2576 }
16dd7267
JC
2577 conf->dot11MeshGateAnnouncementProtocol =
2578 nconf->dot11MeshGateAnnouncementProtocol;
2579 }
a4f606ea 2580 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
0507e159
JC
2581 conf->dot11MeshHWMPRannInterval =
2582 nconf->dot11MeshHWMPRannInterval;
94f90656
CYY
2583 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
2584 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
55335137
AN
2585 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2586 /* our RSSI threshold implementation is supported only for
2587 * devices that report signal in dBm.
2588 */
30686bf7 2589 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
55335137
AN
2590 return -ENOTSUPP;
2591 conf->rssi_threshold = nconf->rssi_threshold;
2592 }
70c33eaa
AN
2593 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2594 conf->ht_opmode = nconf->ht_opmode;
2595 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
d8675a63
JB
2596 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2597 BSS_CHANGED_HT);
70c33eaa 2598 }
ac1073a6
CYY
2599 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2600 conf->dot11MeshHWMPactivePathToRootTimeout =
2601 nconf->dot11MeshHWMPactivePathToRootTimeout;
2602 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2603 conf->dot11MeshHWMProotInterval =
2604 nconf->dot11MeshHWMProotInterval;
728b19e5
CYY
2605 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2606 conf->dot11MeshHWMPconfirmationInterval =
2607 nconf->dot11MeshHWMPconfirmationInterval;
3f52b7e3
MP
2608 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2609 conf->power_mode = nconf->power_mode;
2610 ieee80211_mps_local_status_update(sdata);
2611 }
2b5e1967 2612 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
3f52b7e3
MP
2613 conf->dot11MeshAwakeWindowDuration =
2614 nconf->dot11MeshAwakeWindowDuration;
66de6713
CT
2615 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2616 conf->plink_timeout = nconf->plink_timeout;
01d66fbd
BC
2617 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
2618 conf->dot11MeshConnectedToMeshGate =
2619 nconf->dot11MeshConnectedToMeshGate;
e3718a61
LL
2620 if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask))
2621 conf->dot11MeshNolearn = nconf->dot11MeshNolearn;
184eebe6
MT
2622 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask))
2623 conf->dot11MeshConnectedToAuthServer =
2624 nconf->dot11MeshConnectedToAuthServer;
2b5e1967 2625 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
93da9cc1 2626 return 0;
2627}
2628
29cbe68c
JB
2629static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2630 const struct mesh_config *conf,
2631 const struct mesh_setup *setup)
2632{
2633 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2634 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
c80d545d 2635 int err;
29cbe68c 2636
c80d545d
JC
2637 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2638 err = copy_mesh_setup(ifmsh, setup);
2639 if (err)
2640 return err;
cc1d2806 2641
018f6fbf
DK
2642 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2643
04ecd257 2644 /* can mesh use other SMPS modes? */
bfd8403a
JB
2645 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
2646 sdata->deflink.needed_rx_chains = sdata->local->rx_chains;
04ecd257 2647
34a3740d 2648 mutex_lock(&sdata->local->mtx);
d8675a63 2649 err = ieee80211_link_use_channel(&sdata->deflink, &setup->chandef,
b4f85443 2650 IEEE80211_CHANCTX_SHARED);
34a3740d 2651 mutex_unlock(&sdata->local->mtx);
cc1d2806
JB
2652 if (err)
2653 return err;
2654
2b5e1967 2655 return ieee80211_start_mesh(sdata);
29cbe68c
JB
2656}
2657
2658static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2659{
2660 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2661
2662 ieee80211_stop_mesh(sdata);
34a3740d 2663 mutex_lock(&sdata->local->mtx);
d8675a63 2664 ieee80211_link_release_channel(&sdata->deflink);
6a01afcf 2665 kfree(sdata->u.mesh.ie);
34a3740d 2666 mutex_unlock(&sdata->local->mtx);
29cbe68c
JB
2667
2668 return 0;
2669}
c5dd9c2b
LCC
2670#endif
2671
9f1ba906
JM
2672static int ieee80211_change_bss(struct wiphy *wiphy,
2673 struct net_device *dev,
2674 struct bss_parameters *params)
2675{
55de908a 2676 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
9a886df0 2677 struct ieee80211_link_data *link;
21a8e9dd 2678 struct ieee80211_supported_band *sband;
15ddba5f 2679 u64 changed = 0;
9f1ba906 2680
9a886df0
JB
2681 link = ieee80211_link_or_deflink(sdata, params->link_id, true);
2682 if (IS_ERR(link))
2683 return PTR_ERR(link);
2684
2685 if (!sdata_dereference(link->u.ap.beacon, sdata))
55de908a
JB
2686 return -ENOENT;
2687
9a886df0 2688 sband = ieee80211_get_link_sband(link);
21a8e9dd
MSS
2689 if (!sband)
2690 return -EINVAL;
9f1ba906 2691
ce04abc3
JB
2692 if (params->basic_rates) {
2693 if (!ieee80211_parse_bitrates(link->conf->chandef.width,
2694 wiphy->bands[sband->band],
2695 params->basic_rates,
2696 params->basic_rates_len,
2697 &link->conf->basic_rates))
2698 return -EINVAL;
2699 changed |= BSS_CHANGED_BASIC_RATES;
2700 ieee80211_check_rate_mask(link);
2701 }
2702
9f1ba906 2703 if (params->use_cts_prot >= 0) {
9a886df0 2704 link->conf->use_cts_prot = params->use_cts_prot;
9f1ba906
JM
2705 changed |= BSS_CHANGED_ERP_CTS_PROT;
2706 }
2707 if (params->use_short_preamble >= 0) {
9a886df0 2708 link->conf->use_short_preamble = params->use_short_preamble;
9f1ba906
JM
2709 changed |= BSS_CHANGED_ERP_PREAMBLE;
2710 }
43d35343 2711
9a886df0 2712 if (!link->conf->use_short_slot &&
07c12d61
TM
2713 (sband->band == NL80211_BAND_5GHZ ||
2714 sband->band == NL80211_BAND_6GHZ)) {
9a886df0 2715 link->conf->use_short_slot = true;
43d35343
FF
2716 changed |= BSS_CHANGED_ERP_SLOT;
2717 }
2718
9f1ba906 2719 if (params->use_short_slot_time >= 0) {
9a886df0 2720 link->conf->use_short_slot = params->use_short_slot_time;
9f1ba906
JM
2721 changed |= BSS_CHANGED_ERP_SLOT;
2722 }
2723
7b7b5e56
FF
2724 if (params->ap_isolate >= 0) {
2725 if (params->ap_isolate)
2726 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2727 else
2728 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
49ddf8e6 2729 ieee80211_check_fast_rx_iface(sdata);
7b7b5e56
FF
2730 }
2731
80d7e403 2732 if (params->ht_opmode >= 0) {
9a886df0 2733 link->conf->ht_operation_mode = (u16)params->ht_opmode;
80d7e403
HS
2734 changed |= BSS_CHANGED_HT;
2735 }
2736
339afbf4 2737 if (params->p2p_ctwindow >= 0) {
9a886df0 2738 link->conf->p2p_noa_attr.oppps_ctwindow &=
67baf663 2739 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
9a886df0 2740 link->conf->p2p_noa_attr.oppps_ctwindow |=
67baf663 2741 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
339afbf4
JB
2742 changed |= BSS_CHANGED_P2P_PS;
2743 }
2744
67baf663 2745 if (params->p2p_opp_ps > 0) {
9a886df0 2746 link->conf->p2p_noa_attr.oppps_ctwindow |=
67baf663
JD
2747 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2748 changed |= BSS_CHANGED_P2P_PS;
2749 } else if (params->p2p_opp_ps == 0) {
9a886df0 2750 link->conf->p2p_noa_attr.oppps_ctwindow &=
67baf663 2751 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
339afbf4
JB
2752 changed |= BSS_CHANGED_P2P_PS;
2753 }
2754
9a886df0 2755 ieee80211_link_info_change_notify(sdata, link, changed);
9f1ba906
JM
2756
2757 return 0;
2758}
2759
31888487 2760static int ieee80211_set_txq_params(struct wiphy *wiphy,
f70f01c2 2761 struct net_device *dev,
31888487
JM
2762 struct ieee80211_txq_params *params)
2763{
2764 struct ieee80211_local *local = wiphy_priv(wiphy);
f6f3def3 2765 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
c88f1542 2766 struct ieee80211_link_data *link =
ccdde7c7 2767 ieee80211_link_or_deflink(sdata, params->link_id, true);
31888487
JM
2768 struct ieee80211_tx_queue_params p;
2769
2770 if (!local->ops->conf_tx)
2771 return -EOPNOTSUPP;
2772
54bcbc69
JB
2773 if (local->hw.queues < IEEE80211_NUM_ACS)
2774 return -EOPNOTSUPP;
2775
c88f1542
ST
2776 if (IS_ERR(link))
2777 return PTR_ERR(link);
2778
31888487
JM
2779 memset(&p, 0, sizeof(p));
2780 p.aifs = params->aifs;
2781 p.cw_max = params->cwmax;
2782 p.cw_min = params->cwmin;
2783 p.txop = params->txop;
ab13315a
KV
2784
2785 /*
2786 * Setting tx queue params disables u-apsd because it's only
2787 * called in master mode.
2788 */
2789 p.uapsd = false;
2790
e552af05
HD
2791 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2792
b3e2130b
JB
2793 link->tx_conf[params->ac] = p;
2794 if (drv_conf_tx(local, link, params->ac, &p)) {
0fb9a9ec 2795 wiphy_debug(local->hw.wiphy,
a3304b0a
JB
2796 "failed to set TX queue parameters for AC %d\n",
2797 params->ac);
31888487
JM
2798 return -EINVAL;
2799 }
2800
b3e2130b 2801 ieee80211_link_info_change_notify(sdata, link,
d8675a63 2802 BSS_CHANGED_QOS);
7d25745d 2803
31888487
JM
2804 return 0;
2805}
2806
665af4fc 2807#ifdef CONFIG_PM
ff1b6e69
JB
2808static int ieee80211_suspend(struct wiphy *wiphy,
2809 struct cfg80211_wowlan *wowlan)
665af4fc 2810{
eecc4800 2811 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
665af4fc
BC
2812}
2813
2814static int ieee80211_resume(struct wiphy *wiphy)
2815{
2816 return __ieee80211_resume(wiphy_priv(wiphy));
2817}
2818#else
2819#define ieee80211_suspend NULL
2820#define ieee80211_resume NULL
2821#endif
2822
2a519311 2823static int ieee80211_scan(struct wiphy *wiphy,
2a519311
JB
2824 struct cfg80211_scan_request *req)
2825{
fd014284
JB
2826 struct ieee80211_sub_if_data *sdata;
2827
2828 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2a519311 2829
2ca27bcf
JB
2830 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2831 case NL80211_IFTYPE_STATION:
2832 case NL80211_IFTYPE_ADHOC:
2833 case NL80211_IFTYPE_MESH_POINT:
2834 case NL80211_IFTYPE_P2P_CLIENT:
f142c6b9 2835 case NL80211_IFTYPE_P2P_DEVICE:
2ca27bcf
JB
2836 break;
2837 case NL80211_IFTYPE_P2P_GO:
2838 if (sdata->local->ops->hw_scan)
2839 break;
e9d7732e
JB
2840 /*
2841 * FIXME: implement NoA while scanning in software,
2842 * for now fall through to allow scanning only when
2843 * beaconing hasn't been configured yet
2844 */
fc0561dc 2845 fallthrough;
2ca27bcf 2846 case NL80211_IFTYPE_AP:
5c95b940
AQ
2847 /*
2848 * If the scan has been forced (and the driver supports
2849 * forcing), don't care about being beaconing already.
2850 * This will create problems to the attached stations (e.g. all
71a659bf 2851 * the frames sent while scanning on other channel will be
5c95b940
AQ
2852 * lost)
2853 */
bfd8403a 2854 if (sdata->deflink.u.ap.beacon &&
5c95b940
AQ
2855 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2856 !(req->flags & NL80211_SCAN_FLAG_AP)))
2ca27bcf
JB
2857 return -EOPNOTSUPP;
2858 break;
cb3b7d87 2859 case NL80211_IFTYPE_NAN:
2ca27bcf
JB
2860 default:
2861 return -EOPNOTSUPP;
2862 }
2a519311
JB
2863
2864 return ieee80211_request_scan(sdata, req);
2865}
2866
91f123f2
VK
2867static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2868{
2869 ieee80211_scan_cancel(wiphy_priv(wiphy));
2870}
2871
79f460ca
LC
2872static int
2873ieee80211_sched_scan_start(struct wiphy *wiphy,
2874 struct net_device *dev,
2875 struct cfg80211_sched_scan_request *req)
2876{
2877 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2878
2879 if (!sdata->local->ops->sched_scan_start)
2880 return -EOPNOTSUPP;
2881
2882 return ieee80211_request_sched_scan_start(sdata, req);
2883}
2884
2885static int
3a3ecf1d
AVS
2886ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2887 u64 reqid)
79f460ca 2888{
0d440ea2 2889 struct ieee80211_local *local = wiphy_priv(wiphy);
79f460ca 2890
0d440ea2 2891 if (!local->ops->sched_scan_stop)
79f460ca
LC
2892 return -EOPNOTSUPP;
2893
0d440ea2 2894 return ieee80211_request_sched_scan_stop(local);
79f460ca
LC
2895}
2896
636a5d36
JM
2897static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2898 struct cfg80211_auth_request *req)
2899{
77fdaa12 2900 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
636a5d36
JM
2901}
2902
2903static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2904 struct cfg80211_assoc_request *req)
2905{
77fdaa12 2906 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
636a5d36
JM
2907}
2908
2909static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
63c9c5e7 2910 struct cfg80211_deauth_request *req)
636a5d36 2911{
63c9c5e7 2912 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
636a5d36
JM
2913}
2914
2915static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
63c9c5e7 2916 struct cfg80211_disassoc_request *req)
636a5d36 2917{
63c9c5e7 2918 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
636a5d36
JM
2919}
2920
af8cdcd8
JB
2921static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2922 struct cfg80211_ibss_params *params)
2923{
55de908a 2924 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
af8cdcd8
JB
2925}
2926
2927static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2928{
55de908a 2929 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
af8cdcd8
JB
2930}
2931
239281f8
RL
2932static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2933 struct ocb_setup *setup)
2934{
2935 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2936}
2937
2938static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2939{
2940 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2941}
2942
391e53e3 2943static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
57fbcce3 2944 int rate[NUM_NL80211_BANDS])
391e53e3
AQ
2945{
2946 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2947
9887dbf5 2948 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
57fbcce3 2949 sizeof(int) * NUM_NL80211_BANDS);
391e53e3 2950
d8675a63
JB
2951 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2952 BSS_CHANGED_MCAST_RATE);
dcbe73ca 2953
391e53e3
AQ
2954 return 0;
2955}
2956
b9a5f8ca
JM
2957static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2958{
2959 struct ieee80211_local *local = wiphy_priv(wiphy);
24487981 2960 int err;
b9a5f8ca 2961
f23a4780 2962 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
17c18bf8
JB
2963 ieee80211_check_fast_xmit_all(local);
2964
f23a4780
AN
2965 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2966
17c18bf8
JB
2967 if (err) {
2968 ieee80211_check_fast_xmit_all(local);
f23a4780 2969 return err;
17c18bf8 2970 }
f23a4780
AN
2971 }
2972
a4bcaf55
LB
2973 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2974 (changed & WIPHY_PARAM_DYN_ACK)) {
2975 s16 coverage_class;
2976
2977 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2978 wiphy->coverage_class : -1;
2979 err = drv_set_coverage_class(local, coverage_class);
310bc676
LT
2980
2981 if (err)
2982 return err;
2983 }
2984
b9a5f8ca 2985 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
24487981 2986 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
b9a5f8ca 2987
24487981
JB
2988 if (err)
2989 return err;
b9a5f8ca
JM
2990 }
2991
8bc83c24
JB
2992 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2993 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2994 return -EINVAL;
b9a5f8ca 2995 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
8bc83c24
JB
2996 }
2997 if (changed & WIPHY_PARAM_RETRY_LONG) {
2998 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2999 return -EINVAL;
b9a5f8ca 3000 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
8bc83c24 3001 }
b9a5f8ca
JM
3002 if (changed &
3003 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
3004 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
3005
2fe4a29a
THJ
3006 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
3007 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
3008 WIPHY_PARAM_TXQ_QUANTUM))
3009 ieee80211_txq_set_params(local);
3010
b9a5f8ca
JM
3011 return 0;
3012}
3013
7643a2c3 3014static int ieee80211_set_tx_power(struct wiphy *wiphy,
c8442118 3015 struct wireless_dev *wdev,
fa61cf70 3016 enum nl80211_tx_power_setting type, int mbm)
7643a2c3
JB
3017{
3018 struct ieee80211_local *local = wiphy_priv(wiphy);
1ea6f9c0 3019 struct ieee80211_sub_if_data *sdata;
db82d8a9
LB
3020 enum nl80211_tx_power_setting txp_type = type;
3021 bool update_txp_type = false;
3a3713ec 3022 bool has_monitor = false;
7643a2c3 3023
1ea6f9c0
JB
3024 if (wdev) {
3025 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3026
3a3713ec 3027 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
6dd23603
JB
3028 sdata = wiphy_dereference(local->hw.wiphy,
3029 local->monitor_sdata);
3a3713ec
PG
3030 if (!sdata)
3031 return -EOPNOTSUPP;
3032 }
3033
1ea6f9c0
JB
3034 switch (type) {
3035 case NL80211_TX_POWER_AUTOMATIC:
bfd8403a
JB
3036 sdata->deflink.user_power_level =
3037 IEEE80211_UNSET_POWER_LEVEL;
db82d8a9 3038 txp_type = NL80211_TX_POWER_LIMITED;
1ea6f9c0
JB
3039 break;
3040 case NL80211_TX_POWER_LIMITED:
3041 case NL80211_TX_POWER_FIXED:
3042 if (mbm < 0 || (mbm % 100))
3043 return -EOPNOTSUPP;
bfd8403a 3044 sdata->deflink.user_power_level = MBM_TO_DBM(mbm);
1ea6f9c0
JB
3045 break;
3046 }
3047
db82d8a9
LB
3048 if (txp_type != sdata->vif.bss_conf.txpower_type) {
3049 update_txp_type = true;
3050 sdata->vif.bss_conf.txpower_type = txp_type;
3051 }
3052
3053 ieee80211_recalc_txpower(sdata, update_txp_type);
1ea6f9c0
JB
3054
3055 return 0;
3056 }
55de908a 3057
7643a2c3 3058 switch (type) {
fa61cf70 3059 case NL80211_TX_POWER_AUTOMATIC:
1ea6f9c0 3060 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
db82d8a9 3061 txp_type = NL80211_TX_POWER_LIMITED;
7643a2c3 3062 break;
fa61cf70 3063 case NL80211_TX_POWER_LIMITED:
fa61cf70
JO
3064 case NL80211_TX_POWER_FIXED:
3065 if (mbm < 0 || (mbm % 100))
3066 return -EOPNOTSUPP;
fa61cf70 3067 local->user_power_level = MBM_TO_DBM(mbm);
7643a2c3 3068 break;
7643a2c3
JB
3069 }
3070
1ea6f9c0 3071 mutex_lock(&local->iflist_mtx);
db82d8a9 3072 list_for_each_entry(sdata, &local->interfaces, list) {
3a3713ec
PG
3073 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3074 has_monitor = true;
3075 continue;
3076 }
bfd8403a 3077 sdata->deflink.user_power_level = local->user_power_level;
db82d8a9
LB
3078 if (txp_type != sdata->vif.bss_conf.txpower_type)
3079 update_txp_type = true;
3080 sdata->vif.bss_conf.txpower_type = txp_type;
3081 }
3a3713ec
PG
3082 list_for_each_entry(sdata, &local->interfaces, list) {
3083 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
3084 continue;
db82d8a9 3085 ieee80211_recalc_txpower(sdata, update_txp_type);
3a3713ec 3086 }
1ea6f9c0 3087 mutex_unlock(&local->iflist_mtx);
7643a2c3 3088
3a3713ec 3089 if (has_monitor) {
6dd23603
JB
3090 sdata = wiphy_dereference(local->hw.wiphy,
3091 local->monitor_sdata);
3a3713ec 3092 if (sdata) {
bfd8403a 3093 sdata->deflink.user_power_level = local->user_power_level;
3a3713ec
PG
3094 if (txp_type != sdata->vif.bss_conf.txpower_type)
3095 update_txp_type = true;
3096 sdata->vif.bss_conf.txpower_type = txp_type;
3097
3098 ieee80211_recalc_txpower(sdata, update_txp_type);
3099 }
3100 }
3101
7643a2c3
JB
3102 return 0;
3103}
3104
c8442118
JB
3105static int ieee80211_get_tx_power(struct wiphy *wiphy,
3106 struct wireless_dev *wdev,
3107 int *dbm)
7643a2c3
JB
3108{
3109 struct ieee80211_local *local = wiphy_priv(wiphy);
1ea6f9c0 3110 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
7643a2c3 3111
5b3dc42b
FF
3112 if (local->ops->get_txpower)
3113 return drv_get_txpower(local, sdata, dbm);
3114
1ea6f9c0
JB
3115 if (!local->use_chanctx)
3116 *dbm = local->hw.conf.power_level;
3117 else
3118 *dbm = sdata->vif.bss_conf.txpower;
7643a2c3 3119
7643a2c3
JB
3120 return 0;
3121}
3122
1f87f7d3
JB
3123static void ieee80211_rfkill_poll(struct wiphy *wiphy)
3124{
3125 struct ieee80211_local *local = wiphy_priv(wiphy);
3126
3127 drv_rfkill_poll(local);
3128}
3129
aff89a9b 3130#ifdef CONFIG_NL80211_TESTMODE
fc73f11f
DS
3131static int ieee80211_testmode_cmd(struct wiphy *wiphy,
3132 struct wireless_dev *wdev,
3133 void *data, int len)
aff89a9b
JB
3134{
3135 struct ieee80211_local *local = wiphy_priv(wiphy);
52981cd7 3136 struct ieee80211_vif *vif = NULL;
aff89a9b
JB
3137
3138 if (!local->ops->testmode_cmd)
3139 return -EOPNOTSUPP;
3140
52981cd7
DS
3141 if (wdev) {
3142 struct ieee80211_sub_if_data *sdata;
3143
3144 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3145 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
3146 vif = &sdata->vif;
3147 }
3148
3149 return local->ops->testmode_cmd(&local->hw, vif, data, len);
aff89a9b 3150}
71063f0e
WYG
3151
3152static int ieee80211_testmode_dump(struct wiphy *wiphy,
3153 struct sk_buff *skb,
3154 struct netlink_callback *cb,
3155 void *data, int len)
3156{
3157 struct ieee80211_local *local = wiphy_priv(wiphy);
3158
3159 if (!local->ops->testmode_dump)
3160 return -EOPNOTSUPP;
3161
3162 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
3163}
aff89a9b
JB
3164#endif
3165
687da132 3166int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
d8675a63 3167 struct ieee80211_link_data *link,
687da132 3168 enum ieee80211_smps_mode smps_mode)
0f78231b
JB
3169{
3170 const u8 *ap;
3171 enum ieee80211_smps_mode old_req;
3172 int err;
d51c2ea3
AN
3173 struct sta_info *sta;
3174 bool tdls_peer_found = false;
0f78231b 3175
8d61ffa5 3176 lockdep_assert_held(&sdata->wdev.mtx);
243e6df4 3177
687da132
EG
3178 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
3179 return -EINVAL;
3180
e665ab9c
IP
3181 if (ieee80211_vif_is_mld(&sdata->vif) &&
3182 !(sdata->vif.active_links & BIT(link->link_id)))
3183 return 0;
3184
d8675a63
JB
3185 old_req = link->u.mgd.req_smps;
3186 link->u.mgd.req_smps = smps_mode;
0f78231b
JB
3187
3188 if (old_req == smps_mode &&
3189 smps_mode != IEEE80211_SMPS_AUTOMATIC)
3190 return 0;
3191
3192 /*
3193 * If not associated, or current association is not an HT
04ecd257
JB
3194 * association, there's no need to do anything, just store
3195 * the new value until we associate.
0f78231b
JB
3196 */
3197 if (!sdata->u.mgd.associated ||
d8675a63 3198 link->conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
0f78231b 3199 return 0;
0f78231b 3200
e665ab9c 3201 ap = sdata->vif.cfg.ap_addr;
0f78231b 3202
d51c2ea3
AN
3203 rcu_read_lock();
3204 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
3205 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
3206 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3207 continue;
3208
3209 tdls_peer_found = true;
3210 break;
3211 }
3212 rcu_read_unlock();
3213
0f78231b 3214 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
d51c2ea3 3215 if (tdls_peer_found || !sdata->u.mgd.powersave)
0f78231b 3216 smps_mode = IEEE80211_SMPS_OFF;
d51c2ea3
AN
3217 else
3218 smps_mode = IEEE80211_SMPS_DYNAMIC;
0f78231b
JB
3219 }
3220
3221 /* send SM PS frame to AP */
3222 err = ieee80211_send_smps_action(sdata, smps_mode,
e665ab9c
IP
3223 ap, ap,
3224 ieee80211_vif_is_mld(&sdata->vif) ?
3225 link->link_id : -1);
0f78231b 3226 if (err)
d8675a63 3227 link->u.mgd.req_smps = old_req;
d51c2ea3
AN
3228 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
3229 ieee80211_teardown_tdls_peers(sdata);
0f78231b
JB
3230
3231 return err;
3232}
3233
bc92afd9
JB
3234static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
3235 bool enabled, int timeout)
3236{
3237 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3238 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
e9aac179 3239 unsigned int link_id;
bc92afd9 3240
2d3db210 3241 if (sdata->vif.type != NL80211_IFTYPE_STATION)
e5de30c9
BP
3242 return -EOPNOTSUPP;
3243
30686bf7 3244 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
bc92afd9
JB
3245 return -EOPNOTSUPP;
3246
3247 if (enabled == sdata->u.mgd.powersave &&
ff616381 3248 timeout == local->dynamic_ps_forced_timeout)
bc92afd9
JB
3249 return 0;
3250
3251 sdata->u.mgd.powersave = enabled;
ff616381 3252 local->dynamic_ps_forced_timeout = timeout;
bc92afd9 3253
0f78231b 3254 /* no change, but if automatic follow powersave */
ed405be5 3255 sdata_lock(sdata);
e9aac179 3256 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
d8675a63
JB
3257 struct ieee80211_link_data *link;
3258
3259 link = sdata_dereference(sdata->link[link_id], sdata);
3260
3261 if (!link)
e9aac179 3262 continue;
d8675a63
JB
3263 __ieee80211_request_smps_mgd(sdata, link,
3264 link->u.mgd.req_smps);
e9aac179 3265 }
ed405be5 3266 sdata_unlock(sdata);
0f78231b 3267
30686bf7 3268 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
bc92afd9
JB
3269 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
3270
4a733ef1 3271 ieee80211_recalc_ps(local);
ab095877 3272 ieee80211_recalc_ps_vif(sdata);
1d870162 3273 ieee80211_check_fast_rx_iface(sdata);
bc92afd9
JB
3274
3275 return 0;
3276}
3277
a97c13c3
JO
3278static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
3279 struct net_device *dev,
3280 s32 rssi_thold, u32 rssi_hyst)
3281{
3282 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
a97c13c3
JO
3283 struct ieee80211_vif *vif = &sdata->vif;
3284 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3285
a97c13c3
JO
3286 if (rssi_thold == bss_conf->cqm_rssi_thold &&
3287 rssi_hyst == bss_conf->cqm_rssi_hyst)
3288 return 0;
3289
ef9be10c
JB
3290 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
3291 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
3292 return -EOPNOTSUPP;
3293
a97c13c3
JO
3294 bss_conf->cqm_rssi_thold = rssi_thold;
3295 bss_conf->cqm_rssi_hyst = rssi_hyst;
2c3c5f8c
AZ
3296 bss_conf->cqm_rssi_low = 0;
3297 bss_conf->cqm_rssi_high = 0;
bfd8403a 3298 sdata->deflink.u.mgd.last_cqm_event_signal = 0;
2c3c5f8c
AZ
3299
3300 /* tell the driver upon association, unless already associated */
3301 if (sdata->u.mgd.associated &&
3302 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
d8675a63
JB
3303 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3304 BSS_CHANGED_CQM);
2c3c5f8c
AZ
3305
3306 return 0;
3307}
3308
3309static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
3310 struct net_device *dev,
3311 s32 rssi_low, s32 rssi_high)
3312{
3313 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3314 struct ieee80211_vif *vif = &sdata->vif;
3315 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3316
3317 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
3318 return -EOPNOTSUPP;
3319
3320 bss_conf->cqm_rssi_low = rssi_low;
3321 bss_conf->cqm_rssi_high = rssi_high;
3322 bss_conf->cqm_rssi_thold = 0;
3323 bss_conf->cqm_rssi_hyst = 0;
bfd8403a 3324 sdata->deflink.u.mgd.last_cqm_event_signal = 0;
a97c13c3
JO
3325
3326 /* tell the driver upon association, unless already associated */
ea086359
JB
3327 if (sdata->u.mgd.associated &&
3328 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
d8675a63
JB
3329 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3330 BSS_CHANGED_CQM);
a97c13c3
JO
3331
3332 return 0;
3333}
3334
9930380f
JB
3335static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
3336 struct net_device *dev,
7b0a0e3c 3337 unsigned int link_id,
9930380f
JB
3338 const u8 *addr,
3339 const struct cfg80211_bitrate_mask *mask)
3340{
3341 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3342 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
bdbfd6b5 3343 int i, ret;
2c7e6bc9 3344
554a43d5
EP
3345 if (!ieee80211_sdata_running(sdata))
3346 return -ENETDOWN;
3347
e8e4f528
JB
3348 /*
3349 * If active validate the setting and reject it if it doesn't leave
3350 * at least one basic rate usable, since we really have to be able
3351 * to send something, and if we're an AP we have to be able to do
3352 * so at a basic rate so that all clients can receive it.
3353 */
d0a9123e 3354 if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) &&
e8e4f528
JB
3355 sdata->vif.bss_conf.chandef.chan) {
3356 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
3357 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
3358
3359 if (!(mask->control[band].legacy & basic_rates))
3360 return -EINVAL;
3361 }
3362
e5f5ce37
JB
3363 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3364 ret = drv_set_bitrate_mask(local, sdata, mask);
3365 if (ret)
3366 return ret;
3367 }
3368
57fbcce3 3369 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2ffbe6d3
FF
3370 struct ieee80211_supported_band *sband = wiphy->bands[i];
3371 int j;
3372
37eb0b16 3373 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
d1e33e65
JD
3374 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
3375 sizeof(mask->control[i].ht_mcs));
b119ad6e
LB
3376 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
3377 mask->control[i].vht_mcs,
3378 sizeof(mask->control[i].vht_mcs));
2ffbe6d3
FF
3379
3380 sdata->rc_has_mcs_mask[i] = false;
b119ad6e 3381 sdata->rc_has_vht_mcs_mask[i] = false;
2ffbe6d3
FF
3382 if (!sband)
3383 continue;
3384
b119ad6e 3385 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
1944015f 3386 if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
2ffbe6d3 3387 sdata->rc_has_mcs_mask[i] = true;
2df1b131
JB
3388 break;
3389 }
3390 }
b119ad6e 3391
2df1b131 3392 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
1944015f 3393 if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
b119ad6e 3394 sdata->rc_has_vht_mcs_mask[i] = true;
2ffbe6d3 3395 break;
2df1b131 3396 }
b119ad6e 3397 }
19468413 3398 }
9930380f 3399
37eb0b16 3400 return 0;
9930380f
JB
3401}
3402
164eb02d
SW
3403static int ieee80211_start_radar_detection(struct wiphy *wiphy,
3404 struct net_device *dev,
31559f35
JD
3405 struct cfg80211_chan_def *chandef,
3406 u32 cac_time_ms)
164eb02d
SW
3407{
3408 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3409 struct ieee80211_local *local = sdata->local;
164eb02d
SW
3410 int err;
3411
34a3740d
JB
3412 mutex_lock(&local->mtx);
3413 if (!list_empty(&local->roc_list) || local->scanning) {
3414 err = -EBUSY;
3415 goto out_unlock;
3416 }
164eb02d
SW
3417
3418 /* whatever, but channel contexts should not complain about that one */
bfd8403a
JB
3419 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
3420 sdata->deflink.needed_rx_chains = local->rx_chains;
164eb02d 3421
d8675a63 3422 err = ieee80211_link_use_channel(&sdata->deflink, chandef,
b4f85443 3423 IEEE80211_CHANCTX_SHARED);
164eb02d 3424 if (err)
34a3740d 3425 goto out_unlock;
164eb02d 3426
766d2601
JB
3427 wiphy_delayed_work_queue(wiphy, &sdata->deflink.dfs_cac_timer_work,
3428 msecs_to_jiffies(cac_time_ms));
164eb02d 3429
34a3740d
JB
3430 out_unlock:
3431 mutex_unlock(&local->mtx);
3432 return err;
164eb02d
SW
3433}
3434
26ec17a1
OM
3435static void ieee80211_end_cac(struct wiphy *wiphy,
3436 struct net_device *dev)
3437{
3438 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3439 struct ieee80211_local *local = sdata->local;
3440
3441 mutex_lock(&local->mtx);
3442 list_for_each_entry(sdata, &local->interfaces, list) {
3443 /* it might be waiting for the local->mtx, but then
3444 * by the time it gets it, sdata->wdev.cac_started
3445 * will no longer be true
3446 */
766d2601
JB
3447 wiphy_delayed_work_cancel(wiphy,
3448 &sdata->deflink.dfs_cac_timer_work);
26ec17a1
OM
3449
3450 if (sdata->wdev.cac_started) {
d8675a63 3451 ieee80211_link_release_channel(&sdata->deflink);
26ec17a1
OM
3452 sdata->wdev.cac_started = false;
3453 }
3454 }
3455 mutex_unlock(&local->mtx);
3456}
3457
73da7d5b
SW
3458static struct cfg80211_beacon_data *
3459cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
3460{
3461 struct cfg80211_beacon_data *new_beacon;
3462 u8 *pos;
3463 int len;
3464
3465 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
3466 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
bd54f3c2
AD
3467 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len;
3468
3469 if (beacon->mbssid_ies)
3470 len += ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies,
68b9bea2 3471 beacon->rnr_ies,
bd54f3c2 3472 beacon->mbssid_ies->cnt);
73da7d5b
SW
3473
3474 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
3475 if (!new_beacon)
3476 return NULL;
3477
2b3171c6
LB
3478 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
3479 new_beacon->mbssid_ies =
3480 kzalloc(struct_size(new_beacon->mbssid_ies,
3481 elem, beacon->mbssid_ies->cnt),
3482 GFP_KERNEL);
3483 if (!new_beacon->mbssid_ies) {
3484 kfree(new_beacon);
3485 return NULL;
3486 }
68b9bea2
AD
3487
3488 if (beacon->rnr_ies && beacon->rnr_ies->cnt) {
3489 new_beacon->rnr_ies =
3490 kzalloc(struct_size(new_beacon->rnr_ies,
3491 elem, beacon->rnr_ies->cnt),
3492 GFP_KERNEL);
3493 if (!new_beacon->rnr_ies) {
3494 kfree(new_beacon->mbssid_ies);
3495 kfree(new_beacon);
3496 return NULL;
3497 }
3498 }
2b3171c6
LB
3499 }
3500
73da7d5b
SW
3501 pos = (u8 *)(new_beacon + 1);
3502 if (beacon->head_len) {
3503 new_beacon->head_len = beacon->head_len;
3504 new_beacon->head = pos;
3505 memcpy(pos, beacon->head, beacon->head_len);
3506 pos += beacon->head_len;
3507 }
3508 if (beacon->tail_len) {
3509 new_beacon->tail_len = beacon->tail_len;
3510 new_beacon->tail = pos;
3511 memcpy(pos, beacon->tail, beacon->tail_len);
3512 pos += beacon->tail_len;
3513 }
3514 if (beacon->beacon_ies_len) {
3515 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
3516 new_beacon->beacon_ies = pos;
3517 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
3518 pos += beacon->beacon_ies_len;
3519 }
3520 if (beacon->proberesp_ies_len) {
3521 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
3522 new_beacon->proberesp_ies = pos;
3523 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
3524 pos += beacon->proberesp_ies_len;
3525 }
3526 if (beacon->assocresp_ies_len) {
3527 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
3528 new_beacon->assocresp_ies = pos;
3529 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
3530 pos += beacon->assocresp_ies_len;
3531 }
3532 if (beacon->probe_resp_len) {
3533 new_beacon->probe_resp_len = beacon->probe_resp_len;
bee92d06 3534 new_beacon->probe_resp = pos;
73da7d5b
SW
3535 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3536 pos += beacon->probe_resp_len;
3537 }
68b9bea2 3538 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
2b3171c6
LB
3539 pos += ieee80211_copy_mbssid_beacon(pos,
3540 new_beacon->mbssid_ies,
3541 beacon->mbssid_ies);
68b9bea2
AD
3542 if (beacon->rnr_ies && beacon->rnr_ies->cnt)
3543 pos += ieee80211_copy_rnr_beacon(pos,
3544 new_beacon->rnr_ies,
3545 beacon->rnr_ies);
3546 }
03b73862
JB
3547
3548 /* might copy -1, meaning no changes requested */
3549 new_beacon->ftm_responder = beacon->ftm_responder;
bc847970
PKC
3550 if (beacon->lci) {
3551 new_beacon->lci_len = beacon->lci_len;
3552 new_beacon->lci = pos;
3553 memcpy(pos, beacon->lci, beacon->lci_len);
3554 pos += beacon->lci_len;
3555 }
3556 if (beacon->civicloc) {
3557 new_beacon->civicloc_len = beacon->civicloc_len;
3558 new_beacon->civicloc = pos;
3559 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
3560 pos += beacon->civicloc_len;
3561 }
73da7d5b
SW
3562
3563 return new_beacon;
3564}
3565
66e01cf9 3566void ieee80211_csa_finish(struct ieee80211_vif *vif)
73da7d5b 3567{
66e01cf9 3568 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
c9eb90a5
JC
3569 struct ieee80211_local *local = sdata->local;
3570
3571 rcu_read_lock();
3572
3573 if (vif->mbssid_tx_vif == vif) {
3574 /* Trigger ieee80211_csa_finish() on the non-transmitting
3575 * interfaces when channel switch is received on
3576 * transmitting interface
3577 */
3578 struct ieee80211_sub_if_data *iter;
3579
3580 list_for_each_entry_rcu(iter, &local->interfaces, list) {
3581 if (!ieee80211_sdata_running(iter))
3582 continue;
73da7d5b 3583
c9eb90a5
JC
3584 if (iter == sdata || iter->vif.mbssid_tx_vif != vif)
3585 continue;
3586
3587 ieee80211_queue_work(&iter->local->hw,
bfd8403a 3588 &iter->deflink.csa_finalize_work);
c9eb90a5
JC
3589 }
3590 }
bfd8403a 3591 ieee80211_queue_work(&local->hw, &sdata->deflink.csa_finalize_work);
c9eb90a5
JC
3592
3593 rcu_read_unlock();
66e01cf9
LC
3594}
3595EXPORT_SYMBOL(ieee80211_csa_finish);
e487eaeb 3596
6d501764
NE
3597void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif, bool block_tx)
3598{
3599 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3600 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3601 struct ieee80211_local *local = sdata->local;
3602
bfd8403a 3603 sdata->deflink.csa_block_tx = block_tx;
6d501764 3604 sdata_info(sdata, "channel switch failed, disconnecting\n");
4b8d43f1 3605 wiphy_work_queue(local->hw.wiphy, &ifmgd->csa_connection_drop_work);
6d501764
NE
3606}
3607EXPORT_SYMBOL(ieee80211_channel_switch_disconnect);
3608
66199506 3609static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
15ddba5f 3610 u64 *changed)
66e01cf9 3611{
66199506 3612 int err;
7578d575 3613
cd7760e6
SW
3614 switch (sdata->vif.type) {
3615 case NL80211_IFTYPE_AP:
bfd8403a 3616 if (!sdata->deflink.u.ap.next_beacon)
450c271d
LB
3617 return -EINVAL;
3618
d8675a63 3619 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
bfd8403a 3620 sdata->deflink.u.ap.next_beacon,
15ddba5f 3621 NULL, NULL, changed);
d9f83f22 3622 ieee80211_free_next_beacon(&sdata->deflink);
97518af1 3623
cd7760e6 3624 if (err < 0)
66199506 3625 return err;
cd7760e6
SW
3626 break;
3627 case NL80211_IFTYPE_ADHOC:
15ddba5f 3628 err = ieee80211_ibss_finish_csa(sdata, changed);
faf046e7 3629 if (err < 0)
66199506 3630 return err;
cd7760e6 3631 break;
b8456a14
CYY
3632#ifdef CONFIG_MAC80211_MESH
3633 case NL80211_IFTYPE_MESH_POINT:
15ddba5f 3634 err = ieee80211_mesh_finish_csa(sdata, changed);
b8456a14 3635 if (err < 0)
66199506 3636 return err;
b8456a14
CYY
3637 break;
3638#endif
cd7760e6
SW
3639 default:
3640 WARN_ON(1);
66199506
MK
3641 return -EINVAL;
3642 }
3643
3644 return 0;
3645}
3646
cf8767dd 3647static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
66199506
MK
3648{
3649 struct ieee80211_local *local = sdata->local;
15ddba5f 3650 u64 changed = 0;
66199506
MK
3651 int err;
3652
3653 sdata_assert_lock(sdata);
3654 lockdep_assert_held(&local->mtx);
03078de4 3655 lockdep_assert_held(&local->chanctx_mtx);
66199506 3656
03078de4
MK
3657 /*
3658 * using reservation isn't immediate as it may be deferred until later
3659 * with multi-vif. once reservation is complete it will re-schedule the
3660 * work with no reserved_chanctx so verify chandef to check if it
3661 * completed successfully
3662 */
66199506 3663
bfd8403a 3664 if (sdata->deflink.reserved_chanctx) {
03078de4
MK
3665 /*
3666 * with multi-vif csa driver may call ieee80211_csa_finish()
3667 * many times while waiting for other interfaces to use their
3668 * reservations
3669 */
bfd8403a 3670 if (sdata->deflink.reserved_ready)
03078de4
MK
3671 return 0;
3672
d8675a63 3673 return ieee80211_link_use_reserved_context(&sdata->deflink);
cd7760e6 3674 }
73da7d5b 3675
03078de4 3676 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
bfd8403a 3677 &sdata->deflink.csa_chandef))
03078de4
MK
3678 return -EINVAL;
3679
d0a9123e 3680 sdata->vif.bss_conf.csa_active = false;
66199506
MK
3681
3682 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3683 if (err)
cf8767dd 3684 return err;
faf046e7 3685
92752117
JB
3686 if (sdata->vif.bss_conf.eht_puncturing != sdata->vif.bss_conf.csa_punct_bitmap) {
3687 sdata->vif.bss_conf.eht_puncturing =
3688 sdata->vif.bss_conf.csa_punct_bitmap;
3689 changed |= BSS_CHANGED_EHT_PUNCTURING;
3690 }
3691
d8675a63 3692 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
59af6928 3693
bfd8403a 3694 if (sdata->deflink.csa_block_tx) {
a46992b4
LC
3695 ieee80211_wake_vif_queues(local, sdata,
3696 IEEE80211_QUEUE_STOP_REASON_CSA);
bfd8403a 3697 sdata->deflink.csa_block_tx = false;
a46992b4 3698 }
cf8767dd 3699
f1d65583
LC
3700 err = drv_post_channel_switch(sdata);
3701 if (err)
3702 return err;
3703
b345f063 3704 cfg80211_ch_switch_notify(sdata->dev, &sdata->deflink.csa_chandef, 0,
2cc25e4b 3705 sdata->vif.bss_conf.eht_puncturing);
f1d65583 3706
cf8767dd
MK
3707 return 0;
3708}
3709
3710static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3711{
3712 if (__ieee80211_csa_finalize(sdata)) {
3713 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3714 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3715 GFP_KERNEL);
3716 }
66e01cf9
LC
3717}
3718
3719void ieee80211_csa_finalize_work(struct work_struct *work)
3720{
3721 struct ieee80211_sub_if_data *sdata =
3722 container_of(work, struct ieee80211_sub_if_data,
bfd8403a 3723 deflink.csa_finalize_work);
59af6928 3724 struct ieee80211_local *local = sdata->local;
66e01cf9
LC
3725
3726 sdata_lock(sdata);
59af6928 3727 mutex_lock(&local->mtx);
03078de4 3728 mutex_lock(&local->chanctx_mtx);
59af6928 3729
66e01cf9 3730 /* AP might have been stopped while waiting for the lock. */
d0a9123e 3731 if (!sdata->vif.bss_conf.csa_active)
66e01cf9
LC
3732 goto unlock;
3733
3734 if (!ieee80211_sdata_running(sdata))
3735 goto unlock;
3736
3737 ieee80211_csa_finalize(sdata);
e487eaeb
SW
3738
3739unlock:
03078de4 3740 mutex_unlock(&local->chanctx_mtx);
59af6928 3741 mutex_unlock(&local->mtx);
e487eaeb 3742 sdata_unlock(sdata);
73da7d5b
SW
3743}
3744
37fa2bdd
MK
3745static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3746 struct cfg80211_csa_settings *params,
15ddba5f 3747 u64 *changed)
73da7d5b 3748{
af296bdb 3749 struct ieee80211_csa_settings csa = {};
37fa2bdd 3750 int err;
73da7d5b 3751
73da7d5b
SW
3752 switch (sdata->vif.type) {
3753 case NL80211_IFTYPE_AP:
bfd8403a 3754 sdata->deflink.u.ap.next_beacon =
cd7760e6 3755 cfg80211_beacon_dup(&params->beacon_after);
bfd8403a 3756 if (!sdata->deflink.u.ap.next_beacon)
cd7760e6
SW
3757 return -ENOMEM;
3758
66e01cf9
LC
3759 /*
3760 * With a count of 0, we don't have to wait for any
3761 * TBTT before switching, so complete the CSA
3762 * immediately. In theory, with a count == 1 we
3763 * should delay the switch until just before the next
3764 * TBTT, but that would complicate things so we switch
3765 * immediately too. If we would delay the switch
3766 * until the next TBTT, we would have to set the probe
3767 * response here.
3768 *
3769 * TODO: A channel switch with count <= 1 without
3770 * sending a CSA action frame is kind of useless,
3771 * because the clients won't know we're changing
3772 * channels. The action frame must be implemented
3773 * either here or in the userspace.
3774 */
3775 if (params->count <= 1)
3776 break;
3777
0d06d9ba 3778 if ((params->n_counter_offsets_beacon >
8552a434 3779 IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
0d06d9ba 3780 (params->n_counter_offsets_presp >
2b3171c6 3781 IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) {
d9f83f22 3782 ieee80211_free_next_beacon(&sdata->deflink);
0d06d9ba 3783 return -EINVAL;
2b3171c6 3784 }
9a774c78 3785
af296bdb
MK
3786 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3787 csa.counter_offsets_presp = params->counter_offsets_presp;
3788 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3789 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3790 csa.count = params->count;
9a774c78 3791
d8675a63
JB
3792 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
3793 &params->beacon_csa, &csa,
15ddba5f 3794 NULL, changed);
cd7760e6 3795 if (err < 0) {
d9f83f22 3796 ieee80211_free_next_beacon(&sdata->deflink);
cd7760e6
SW
3797 return err;
3798 }
66e01cf9 3799
cd7760e6
SW
3800 break;
3801 case NL80211_IFTYPE_ADHOC:
f276e20b 3802 if (!sdata->vif.cfg.ibss_joined)
cd7760e6
SW
3803 return -EINVAL;
3804
3805 if (params->chandef.width != sdata->u.ibss.chandef.width)
3806 return -EINVAL;
3807
3808 switch (params->chandef.width) {
3809 case NL80211_CHAN_WIDTH_40:
3810 if (cfg80211_get_chandef_type(&params->chandef) !=
3811 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3812 return -EINVAL;
aaaee2d6 3813 break;
cd7760e6
SW
3814 case NL80211_CHAN_WIDTH_5:
3815 case NL80211_CHAN_WIDTH_10:
3816 case NL80211_CHAN_WIDTH_20_NOHT:
3817 case NL80211_CHAN_WIDTH_20:
3818 break;
3819 default:
3820 return -EINVAL;
3821 }
3822
3823 /* changes into another band are not supported */
3824 if (sdata->u.ibss.chandef.chan->band !=
3825 params->chandef.chan->band)
3826 return -EINVAL;
3827
66e01cf9
LC
3828 /* see comments in the NL80211_IFTYPE_AP block */
3829 if (params->count > 1) {
15ddba5f 3830 err = ieee80211_ibss_csa_beacon(sdata, params, changed);
66e01cf9
LC
3831 if (err < 0)
3832 return err;
66e01cf9
LC
3833 }
3834
3835 ieee80211_send_action_csa(sdata, params);
3836
73da7d5b 3837 break;
c6da674a 3838#ifdef CONFIG_MAC80211_MESH
37fa2bdd
MK
3839 case NL80211_IFTYPE_MESH_POINT: {
3840 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
c6da674a 3841
c6da674a
CYY
3842 /* changes into another band are not supported */
3843 if (sdata->vif.bss_conf.chandef.chan->band !=
3844 params->chandef.chan->band)
3845 return -EINVAL;
3846
c782bf8c 3847 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
0cb4d4dc 3848 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
c782bf8c
CYY
3849 if (!ifmsh->pre_value)
3850 ifmsh->pre_value = 1;
3851 else
3852 ifmsh->pre_value++;
3853 }
0cb4d4dc 3854
66e01cf9
LC
3855 /* see comments in the NL80211_IFTYPE_AP block */
3856 if (params->count > 1) {
15ddba5f 3857 err = ieee80211_mesh_csa_beacon(sdata, params, changed);
66e01cf9
LC
3858 if (err < 0) {
3859 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3860 return err;
3861 }
3f718fd8 3862 }
66e01cf9
LC
3863
3864 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3865 ieee80211_send_action_csa(sdata, params);
3866
c6da674a 3867 break;
37fa2bdd 3868 }
c6da674a 3869#endif
73da7d5b
SW
3870 default:
3871 return -EOPNOTSUPP;
3872 }
3873
37fa2bdd
MK
3874 return 0;
3875}
3876
5f9404ab
JC
3877static void ieee80211_color_change_abort(struct ieee80211_sub_if_data *sdata)
3878{
d0a9123e 3879 sdata->vif.bss_conf.color_change_active = false;
0baef284 3880
d9f83f22 3881 ieee80211_free_next_beacon(&sdata->deflink);
5f9404ab
JC
3882
3883 cfg80211_color_change_aborted_notify(sdata->dev);
3884}
3885
f29f58a9
LC
3886static int
3887__ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3888 struct cfg80211_csa_settings *params)
37fa2bdd
MK
3889{
3890 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3891 struct ieee80211_local *local = sdata->local;
6d027bcc 3892 struct ieee80211_channel_switch ch_switch;
2b32713d 3893 struct ieee80211_chanctx_conf *conf;
37fa2bdd 3894 struct ieee80211_chanctx *chanctx;
15ddba5f 3895 u64 changed = 0;
b08cc24e 3896 int err;
37fa2bdd
MK
3897
3898 sdata_assert_lock(sdata);
59af6928 3899 lockdep_assert_held(&local->mtx);
37fa2bdd
MK
3900
3901 if (!list_empty(&local->roc_list) || local->scanning)
3902 return -EBUSY;
3903
3904 if (sdata->wdev.cac_started)
3905 return -EBUSY;
3906
3907 if (cfg80211_chandef_identical(&params->chandef,
3908 &sdata->vif.bss_conf.chandef))
3909 return -EINVAL;
3910
03078de4 3911 /* don't allow another channel switch if one is already active. */
d0a9123e 3912 if (sdata->vif.bss_conf.csa_active)
03078de4
MK
3913 return -EBUSY;
3914
2b32713d 3915 mutex_lock(&local->chanctx_mtx);
d0a9123e 3916 conf = rcu_dereference_protected(sdata->vif.bss_conf.chanctx_conf,
2b32713d
MK
3917 lockdep_is_held(&local->chanctx_mtx));
3918 if (!conf) {
03078de4
MK
3919 err = -EBUSY;
3920 goto out;
37fa2bdd
MK
3921 }
3922
b6011960
TP
3923 if (params->chandef.chan->freq_offset) {
3924 /* this may work, but is untested */
3925 err = -EOPNOTSUPP;
3926 goto out;
3927 }
3928
2b32713d 3929 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
37fa2bdd 3930
000baa5d
LC
3931 ch_switch.timestamp = 0;
3932 ch_switch.device_timestamp = 0;
3933 ch_switch.block_tx = params->block_tx;
3934 ch_switch.chandef = params->chandef;
3935 ch_switch.count = params->count;
3936
6d027bcc
LC
3937 err = drv_pre_channel_switch(sdata, &ch_switch);
3938 if (err)
3939 goto out;
3940
d8675a63 3941 err = ieee80211_link_reserve_chanctx(&sdata->deflink, &params->chandef,
b4f85443
JB
3942 chanctx->mode,
3943 params->radar_required);
03078de4
MK
3944 if (err)
3945 goto out;
37fa2bdd 3946
03078de4
MK
3947 /* if reservation is invalid then this will fail */
3948 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3949 if (err) {
d8675a63 3950 ieee80211_link_unreserve_chanctx(&sdata->deflink);
03078de4
MK
3951 goto out;
3952 }
37fa2bdd 3953
5f9404ab 3954 /* if there is a color change in progress, abort it */
d0a9123e 3955 if (sdata->vif.bss_conf.color_change_active)
5f9404ab
JC
3956 ieee80211_color_change_abort(sdata);
3957
37fa2bdd 3958 err = ieee80211_set_csa_beacon(sdata, params, &changed);
03078de4 3959 if (err) {
d8675a63 3960 ieee80211_link_unreserve_chanctx(&sdata->deflink);
03078de4
MK
3961 goto out;
3962 }
37fa2bdd 3963
2cc25e4b
AD
3964 if (params->punct_bitmap && !sdata->vif.bss_conf.eht_support)
3965 goto out;
3966
bfd8403a
JB
3967 sdata->deflink.csa_chandef = params->chandef;
3968 sdata->deflink.csa_block_tx = params->block_tx;
d0a9123e 3969 sdata->vif.bss_conf.csa_active = true;
2cc25e4b 3970 sdata->vif.bss_conf.csa_punct_bitmap = params->punct_bitmap;
73da7d5b 3971
bfd8403a 3972 if (sdata->deflink.csa_block_tx)
a46992b4
LC
3973 ieee80211_stop_vif_queues(local, sdata,
3974 IEEE80211_QUEUE_STOP_REASON_CSA);
59af6928 3975
bfd8403a 3976 cfg80211_ch_switch_started_notify(sdata->dev,
b8c9024e 3977 &sdata->deflink.csa_chandef, 0,
2cc25e4b
AD
3978 params->count, params->block_tx,
3979 sdata->vif.bss_conf.csa_punct_bitmap);
2f457293 3980
66e01cf9 3981 if (changed) {
d8675a63
JB
3982 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3983 changed);
66e01cf9
LC
3984 drv_channel_switch_beacon(sdata, &params->chandef);
3985 } else {
3986 /* if the beacon didn't change, we can finalize immediately */
3987 ieee80211_csa_finalize(sdata);
3988 }
73da7d5b 3989
03078de4
MK
3990out:
3991 mutex_unlock(&local->chanctx_mtx);
3992 return err;
73da7d5b
SW
3993}
3994
59af6928
MK
3995int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3996 struct cfg80211_csa_settings *params)
3997{
3998 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3999 struct ieee80211_local *local = sdata->local;
4000 int err;
4001
4002 mutex_lock(&local->mtx);
4003 err = __ieee80211_channel_switch(wiphy, dev, params);
4004 mutex_unlock(&local->mtx);
4005
4006 return err;
4007}
4008
a2fcfccb
JB
4009u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
4010{
4011 lockdep_assert_held(&local->mtx);
4012
4013 local->roc_cookie_counter++;
4014
4015 /* wow, you wrapped 64 bits ... more likely a bug */
4016 if (WARN_ON(local->roc_cookie_counter == 0))
4017 local->roc_cookie_counter++;
4018
4019 return local->roc_cookie_counter;
4020}
4021
5ee00dbd
JB
4022int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
4023 u64 *cookie, gfp_t gfp)
3b79af97
JB
4024{
4025 unsigned long spin_flags;
4026 struct sk_buff *ack_skb;
4027 int id;
4028
4029 ack_skb = skb_copy(skb, gfp);
4030 if (!ack_skb)
5ee00dbd 4031 return -ENOMEM;
3b79af97
JB
4032
4033 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
4034 id = idr_alloc(&local->ack_status_frames, ack_skb,
f2b18bac 4035 1, 0x2000, GFP_ATOMIC);
3b79af97
JB
4036 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
4037
4038 if (id < 0) {
4039 kfree_skb(ack_skb);
5ee00dbd 4040 return -ENOMEM;
3b79af97
JB
4041 }
4042
f498f6ab
JB
4043 IEEE80211_SKB_CB(skb)->status_data_idr = 1;
4044 IEEE80211_SKB_CB(skb)->status_data = id;
3b79af97
JB
4045
4046 *cookie = ieee80211_mgmt_tx_cookie(local);
4047 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
4048
5ee00dbd 4049 return 0;
3b79af97
JB
4050}
4051
6cd536fe
JB
4052static void
4053ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
71bbc994 4054 struct wireless_dev *wdev,
6cd536fe 4055 struct mgmt_frame_regs *upd)
7be5086d
JB
4056{
4057 struct ieee80211_local *local = wiphy_priv(wiphy);
1b09b556 4058 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
6cd536fe 4059 u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
873b1cf6 4060 u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4);
6cd536fe 4061 bool global_change, intf_change;
7be5086d 4062
6cd536fe 4063 global_change =
873b1cf6
JM
4064 (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) ||
4065 (local->rx_mcast_action_reg !=
4066 !!(upd->global_mcast_stypes & action_mask));
6cd536fe 4067 local->probe_req_reg = upd->global_stypes & preq_mask;
873b1cf6 4068 local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask;
1b09b556 4069
873b1cf6
JM
4070 intf_change = (sdata->vif.probe_req_reg !=
4071 !!(upd->interface_stypes & preq_mask)) ||
4072 (sdata->vif.rx_mcast_action_reg !=
4073 !!(upd->interface_mcast_stypes & action_mask));
6cd536fe 4074 sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask;
873b1cf6
JM
4075 sdata->vif.rx_mcast_action_reg =
4076 upd->interface_mcast_stypes & action_mask;
7be5086d 4077
6cd536fe
JB
4078 if (!local->open_count)
4079 return;
35f5149e 4080
6cd536fe
JB
4081 if (intf_change && ieee80211_sdata_running(sdata))
4082 drv_config_iface_filter(local, sdata,
4083 sdata->vif.probe_req_reg ?
4084 FIF_PROBE_REQ : 0,
4085 FIF_PROBE_REQ);
1b09b556 4086
6cd536fe 4087 if (global_change)
1b09b556 4088 ieee80211_configure_filter(local);
7be5086d
JB
4089}
4090
15d96753
BR
4091static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
4092{
4093 struct ieee80211_local *local = wiphy_priv(wiphy);
4094
4095 if (local->started)
4096 return -EOPNOTSUPP;
4097
4098 return drv_set_antenna(local, tx_ant, rx_ant);
4099}
4100
4101static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
4102{
4103 struct ieee80211_local *local = wiphy_priv(wiphy);
4104
4105 return drv_get_antenna(local, tx_ant, rx_ant);
4106}
4107
c68f4b89
JB
4108static int ieee80211_set_rekey_data(struct wiphy *wiphy,
4109 struct net_device *dev,
4110 struct cfg80211_gtk_rekey_data *data)
4111{
4112 struct ieee80211_local *local = wiphy_priv(wiphy);
4113 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4114
4115 if (!local->ops->set_rekey_data)
4116 return -EOPNOTSUPP;
4117
4118 drv_set_rekey_data(local, sdata, data);
4119
4120 return 0;
4121}
4122
06500736
JB
4123static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
4124 const u8 *peer, u64 *cookie)
4125{
4126 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4127 struct ieee80211_local *local = sdata->local;
4128 struct ieee80211_qos_hdr *nullfunc;
5ee00dbd 4129 struct sk_buff *skb;
06500736
JB
4130 int size = sizeof(*nullfunc);
4131 __le16 fc;
4132 bool qos;
4133 struct ieee80211_tx_info *info;
4134 struct sta_info *sta;
55de908a 4135 struct ieee80211_chanctx_conf *chanctx_conf;
57fbcce3 4136 enum nl80211_band band;
3b79af97
JB
4137 int ret;
4138
4139 /* the lock is needed to assign the cookie later */
4140 mutex_lock(&local->mtx);
06500736
JB
4141
4142 rcu_read_lock();
67dfa589
JB
4143 sta = sta_info_get_bss(sdata, peer);
4144 if (!sta) {
4145 ret = -ENOLINK;
4146 goto unlock;
4147 }
4148
4149 qos = sta->sta.wme;
4150
d0a9123e 4151 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
55de908a 4152 if (WARN_ON(!chanctx_conf)) {
3b79af97
JB
4153 ret = -EINVAL;
4154 goto unlock;
55de908a 4155 }
4bf88530 4156 band = chanctx_conf->def.chan->band;
06500736
JB
4157
4158 if (qos) {
4159 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4160 IEEE80211_STYPE_QOS_NULLFUNC |
4161 IEEE80211_FCTL_FROMDS);
4162 } else {
4163 size -= 2;
4164 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4165 IEEE80211_STYPE_NULLFUNC |
4166 IEEE80211_FCTL_FROMDS);
4167 }
4168
4169 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
55de908a 4170 if (!skb) {
3b79af97
JB
4171 ret = -ENOMEM;
4172 goto unlock;
55de908a 4173 }
06500736
JB
4174
4175 skb->dev = dev;
4176
4177 skb_reserve(skb, local->hw.extra_tx_headroom);
4178
4df864c1 4179 nullfunc = skb_put(skb, size);
06500736
JB
4180 nullfunc->frame_control = fc;
4181 nullfunc->duration_id = 0;
4182 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
4183 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
4184 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
4185 nullfunc->seq_ctrl = 0;
4186
4187 info = IEEE80211_SKB_CB(skb);
4188
4189 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
4190 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
73c4e195 4191 info->band = band;
06500736
JB
4192
4193 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
4194 skb->priority = 7;
4195 if (qos)
4196 nullfunc->qos_ctrl = cpu_to_le16(7);
4197
5ee00dbd
JB
4198 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
4199 if (ret) {
3b79af97 4200 kfree_skb(skb);
3b79af97
JB
4201 goto unlock;
4202 }
4203
06500736 4204 local_bh_disable();
08aca29a 4205 ieee80211_xmit(sdata, sta, skb);
06500736 4206 local_bh_enable();
3b79af97
JB
4207
4208 ret = 0;
4209unlock:
55de908a 4210 rcu_read_unlock();
3b79af97 4211 mutex_unlock(&local->mtx);
06500736 4212
3b79af97 4213 return ret;
06500736
JB
4214}
4215
683b6d3b
JB
4216static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
4217 struct wireless_dev *wdev,
7b0a0e3c 4218 unsigned int link_id,
683b6d3b 4219 struct cfg80211_chan_def *chandef)
5b7ccaf3 4220{
55de908a 4221 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
cb601ffa 4222 struct ieee80211_local *local = wiphy_priv(wiphy);
55de908a 4223 struct ieee80211_chanctx_conf *chanctx_conf;
d8675a63 4224 struct ieee80211_link_data *link;
683b6d3b 4225 int ret = -ENODATA;
55de908a
JB
4226
4227 rcu_read_lock();
d8675a63
JB
4228 link = rcu_dereference(sdata->link[link_id]);
4229 if (!link) {
4230 ret = -ENOLINK;
4231 goto out;
4232 }
4233
4234 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
feda3027 4235 if (chanctx_conf) {
d8675a63 4236 *chandef = link->conf->chandef;
feda3027
JB
4237 ret = 0;
4238 } else if (local->open_count > 0 &&
4239 local->open_count == local->monitors &&
4240 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
4241 if (local->use_chanctx)
4242 *chandef = local->monitor_chandef;
4243 else
675a0b04 4244 *chandef = local->_oper_chandef;
683b6d3b 4245 ret = 0;
55de908a 4246 }
d8675a63 4247out:
55de908a 4248 rcu_read_unlock();
5b7ccaf3 4249
683b6d3b 4250 return ret;
5b7ccaf3
JB
4251}
4252
6d52563f
JB
4253#ifdef CONFIG_PM
4254static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
4255{
4256 drv_set_wakeup(wiphy_priv(wiphy), enabled);
4257}
4258#endif
4259
32db6b54
KP
4260static int ieee80211_set_qos_map(struct wiphy *wiphy,
4261 struct net_device *dev,
4262 struct cfg80211_qos_map *qos_map)
4263{
4264 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4265 struct mac80211_qos_map *new_qos_map, *old_qos_map;
4266
4267 if (qos_map) {
4268 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
4269 if (!new_qos_map)
4270 return -ENOMEM;
4271 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
4272 } else {
4273 /* A NULL qos_map was passed to disable QoS mapping */
4274 new_qos_map = NULL;
4275 }
4276
194ff52d 4277 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
32db6b54
KP
4278 rcu_assign_pointer(sdata->qos_map, new_qos_map);
4279 if (old_qos_map)
4280 kfree_rcu(old_qos_map, rcu_head);
4281
4282 return 0;
4283}
4284
3b1700bd
JM
4285static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
4286 struct net_device *dev,
7b0a0e3c 4287 unsigned int link_id,
3b1700bd
JM
4288 struct cfg80211_chan_def *chandef)
4289{
4290 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
d8675a63 4291 struct ieee80211_link_data *link;
3b1700bd 4292 int ret;
aa87cd8b 4293 u64 changed = 0;
3b1700bd 4294
d8675a63
JB
4295 link = sdata_dereference(sdata->link[link_id], sdata);
4296
4297 ret = ieee80211_link_change_bandwidth(link, chandef, &changed);
3b1700bd 4298 if (ret == 0)
d8675a63 4299 ieee80211_link_info_change_notify(sdata, link, changed);
3b1700bd
JM
4300
4301 return ret;
4302}
4303
02219b3a
JB
4304static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4305 u8 tsid, const u8 *peer, u8 up,
4306 u16 admitted_time)
4307{
4308 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4309 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4310 int ac = ieee802_1d_to_ac[up];
4311
4312 if (sdata->vif.type != NL80211_IFTYPE_STATION)
4313 return -EOPNOTSUPP;
4314
4315 if (!(sdata->wmm_acm & BIT(up)))
4316 return -EINVAL;
4317
4318 if (ifmgd->tx_tspec[ac].admitted_time)
4319 return -EBUSY;
4320
4321 if (admitted_time) {
4322 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
4323 ifmgd->tx_tspec[ac].tsid = tsid;
4324 ifmgd->tx_tspec[ac].up = up;
4325 }
4326
4327 return 0;
4328}
4329
4330static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4331 u8 tsid, const u8 *peer)
4332{
4333 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4334 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4335 struct ieee80211_local *local = wiphy_priv(wiphy);
4336 int ac;
4337
4338 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4339 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
4340
4341 /* skip unused entries */
4342 if (!tx_tspec->admitted_time)
4343 continue;
4344
4345 if (tx_tspec->tsid != tsid)
4346 continue;
4347
4348 /* due to this new packets will be reassigned to non-ACM ACs */
4349 tx_tspec->up = -1;
4350
4351 /* Make sure that all packets have been sent to avoid to
4352 * restore the QoS params on packets that are still on the
4353 * queues.
4354 */
4355 synchronize_net();
3b24f4c6 4356 ieee80211_flush_queues(local, sdata, false);
02219b3a
JB
4357
4358 /* restore the normal QoS parameters
4359 * (unconditionally to avoid races)
4360 */
4361 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
4362 tx_tspec->downgraded = false;
4363 ieee80211_sta_handle_tspec_ac_params(sdata);
4364
4365 /* finally clear all the data */
4366 memset(tx_tspec, 0, sizeof(*tx_tspec));
4367
4368 return 0;
4369 }
4370
4371 return -ENOENT;
4372}
4373
167e33f4
AB
4374void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
4375 u8 inst_id,
4376 enum nl80211_nan_func_term_reason reason,
4377 gfp_t gfp)
4378{
4379 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4380 struct cfg80211_nan_func *func;
4381 u64 cookie;
4382
4383 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4384 return;
4385
4386 spin_lock_bh(&sdata->u.nan.func_lock);
4387
4388 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
4389 if (WARN_ON(!func)) {
4390 spin_unlock_bh(&sdata->u.nan.func_lock);
4391 return;
4392 }
4393
4394 cookie = func->cookie;
4395 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
4396
4397 spin_unlock_bh(&sdata->u.nan.func_lock);
4398
4399 cfg80211_free_nan_func(func);
4400
4401 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
4402 reason, cookie, gfp);
4403}
4404EXPORT_SYMBOL(ieee80211_nan_func_terminated);
4405
92bc43bc
AB
4406void ieee80211_nan_func_match(struct ieee80211_vif *vif,
4407 struct cfg80211_nan_match_params *match,
4408 gfp_t gfp)
4409{
4410 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4411 struct cfg80211_nan_func *func;
4412
4413 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4414 return;
4415
4416 spin_lock_bh(&sdata->u.nan.func_lock);
4417
4418 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
4419 if (WARN_ON(!func)) {
4420 spin_unlock_bh(&sdata->u.nan.func_lock);
4421 return;
4422 }
4423 match->cookie = func->cookie;
4424
4425 spin_unlock_bh(&sdata->u.nan.func_lock);
4426
4427 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
4428}
4429EXPORT_SYMBOL(ieee80211_nan_func_match);
4430
ebceec86
MB
4431static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
4432 struct net_device *dev,
4433 const bool enabled)
4434{
4435 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4436
4437 sdata->u.ap.multicast_to_unicast = enabled;
4438
4439 return 0;
4440}
4441
2fe4a29a
THJ
4442void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
4443 struct txq_info *txqi)
4444{
4445 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
4446 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
4447 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
4448 }
4449
4450 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
4451 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
4452 txqstats->backlog_packets = txqi->tin.backlog_packets;
4453 }
4454
4455 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
4456 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
4457 txqstats->flows = txqi->tin.flows;
4458 }
4459
4460 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
4461 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
4462 txqstats->drops = txqi->cstats.drop_count;
4463 }
4464
4465 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
4466 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
4467 txqstats->ecn_marks = txqi->cstats.ecn_mark;
4468 }
4469
4470 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
4471 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
4472 txqstats->overlimit = txqi->tin.overlimit;
4473 }
4474
4475 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
4476 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
4477 txqstats->collisions = txqi->tin.collisions;
4478 }
4479
4480 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
4481 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
4482 txqstats->tx_bytes = txqi->tin.tx_bytes;
4483 }
4484
4485 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
4486 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
4487 txqstats->tx_packets = txqi->tin.tx_packets;
4488 }
4489}
4490
4491static int ieee80211_get_txq_stats(struct wiphy *wiphy,
4492 struct wireless_dev *wdev,
4493 struct cfg80211_txq_stats *txqstats)
4494{
4495 struct ieee80211_local *local = wiphy_priv(wiphy);
4496 struct ieee80211_sub_if_data *sdata;
4497 int ret = 0;
4498
2fe4a29a
THJ
4499 spin_lock_bh(&local->fq.lock);
4500 rcu_read_lock();
4501
4502 if (wdev) {
4503 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4504 if (!sdata->vif.txq) {
4505 ret = 1;
4506 goto out;
4507 }
4508 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
4509 } else {
4510 /* phy stats */
4511 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
4512 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
4513 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
4514 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
4515 BIT(NL80211_TXQ_STATS_COLLISIONS) |
4516 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
4517 txqstats->backlog_packets = local->fq.backlog;
4518 txqstats->backlog_bytes = local->fq.memory_usage;
4519 txqstats->overlimit = local->fq.overlimit;
4520 txqstats->overmemory = local->fq.overmemory;
4521 txqstats->collisions = local->fq.collisions;
4522 txqstats->max_flows = local->fq.flows_cnt;
4523 }
4524
4525out:
4526 rcu_read_unlock();
4527 spin_unlock_bh(&local->fq.lock);
4528
4529 return ret;
4530}
4531
bc847970
PKC
4532static int
4533ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
4534 struct net_device *dev,
4535 struct cfg80211_ftm_responder_stats *ftm_stats)
4536{
4537 struct ieee80211_local *local = wiphy_priv(wiphy);
4538 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4539
4540 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
4541}
4542
cee7013b
JB
4543static int
4544ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4545 struct cfg80211_pmsr_request *request)
4546{
4547 struct ieee80211_local *local = wiphy_priv(wiphy);
4548 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4549
4550 return drv_start_pmsr(local, sdata, request);
4551}
4552
4553static void
4554ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4555 struct cfg80211_pmsr_request *request)
4556{
4557 struct ieee80211_local *local = wiphy_priv(wiphy);
4558 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4559
4560 return drv_abort_pmsr(local, sdata, request);
4561}
4562
370f51d5
T
4563static int ieee80211_set_tid_config(struct wiphy *wiphy,
4564 struct net_device *dev,
4565 struct cfg80211_tid_config *tid_conf)
4566{
4567 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4568 struct sta_info *sta;
4569 int ret;
4570
4571 if (!sdata->local->ops->set_tid_config)
4572 return -EOPNOTSUPP;
4573
4574 if (!tid_conf->peer)
4575 return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf);
4576
4577 mutex_lock(&sdata->local->sta_mtx);
4578 sta = sta_info_get_bss(sdata, tid_conf->peer);
4579 if (!sta) {
4580 mutex_unlock(&sdata->local->sta_mtx);
4581 return -ENOENT;
4582 }
4583
4584 ret = drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf);
4585 mutex_unlock(&sdata->local->sta_mtx);
4586
4587 return ret;
4588}
4589
4590static int ieee80211_reset_tid_config(struct wiphy *wiphy,
4591 struct net_device *dev,
60c2ef0e 4592 const u8 *peer, u8 tids)
370f51d5
T
4593{
4594 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4595 struct sta_info *sta;
4596 int ret;
4597
4598 if (!sdata->local->ops->reset_tid_config)
4599 return -EOPNOTSUPP;
4600
4601 if (!peer)
60c2ef0e 4602 return drv_reset_tid_config(sdata->local, sdata, NULL, tids);
370f51d5
T
4603
4604 mutex_lock(&sdata->local->sta_mtx);
4605 sta = sta_info_get_bss(sdata, peer);
4606 if (!sta) {
4607 mutex_unlock(&sdata->local->sta_mtx);
4608 return -ENOENT;
4609 }
4610
60c2ef0e 4611 ret = drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids);
370f51d5
T
4612 mutex_unlock(&sdata->local->sta_mtx);
4613
4614 return ret;
4615}
4616
c534e093
CH
4617static int ieee80211_set_sar_specs(struct wiphy *wiphy,
4618 struct cfg80211_sar_specs *sar)
4619{
4620 struct ieee80211_local *local = wiphy_priv(wiphy);
4621
4622 if (!local->ops->set_sar_specs)
4623 return -EOPNOTSUPP;
4624
4625 return local->ops->set_sar_specs(&local->hw, sar);
4626}
4627
5f9404ab
JC
4628static int
4629ieee80211_set_after_color_change_beacon(struct ieee80211_sub_if_data *sdata,
15ddba5f 4630 u64 *changed)
5f9404ab
JC
4631{
4632 switch (sdata->vif.type) {
4633 case NL80211_IFTYPE_AP: {
4634 int ret;
4635
bfd8403a 4636 if (!sdata->deflink.u.ap.next_beacon)
450c271d
LB
4637 return -EINVAL;
4638
d8675a63 4639 ret = ieee80211_assign_beacon(sdata, &sdata->deflink,
bfd8403a 4640 sdata->deflink.u.ap.next_beacon,
15ddba5f 4641 NULL, NULL, changed);
d9f83f22 4642 ieee80211_free_next_beacon(&sdata->deflink);
5f9404ab
JC
4643
4644 if (ret < 0)
4645 return ret;
4646
5f9404ab
JC
4647 break;
4648 }
4649 default:
4650 WARN_ON_ONCE(1);
4651 return -EINVAL;
4652 }
4653
4654 return 0;
4655}
4656
4657static int
4658ieee80211_set_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4659 struct cfg80211_color_change_settings *params,
15ddba5f 4660 u64 *changed)
5f9404ab
JC
4661{
4662 struct ieee80211_color_change_settings color_change = {};
4663 int err;
4664
4665 switch (sdata->vif.type) {
4666 case NL80211_IFTYPE_AP:
bfd8403a 4667 sdata->deflink.u.ap.next_beacon =
5f9404ab 4668 cfg80211_beacon_dup(&params->beacon_next);
bfd8403a 4669 if (!sdata->deflink.u.ap.next_beacon)
5f9404ab
JC
4670 return -ENOMEM;
4671
4672 if (params->count <= 1)
4673 break;
4674
4675 color_change.counter_offset_beacon =
4676 params->counter_offset_beacon;
4677 color_change.counter_offset_presp =
4678 params->counter_offset_presp;
4679 color_change.count = params->count;
4680
d8675a63
JB
4681 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
4682 &params->beacon_color_change,
15ddba5f 4683 NULL, &color_change, changed);
5f9404ab 4684 if (err < 0) {
d9f83f22 4685 ieee80211_free_next_beacon(&sdata->deflink);
5f9404ab
JC
4686 return err;
4687 }
5f9404ab
JC
4688 break;
4689 default:
4690 return -EOPNOTSUPP;
4691 }
4692
4693 return 0;
4694}
4695
4696static void
4697ieee80211_color_change_bss_config_notify(struct ieee80211_sub_if_data *sdata,
15ddba5f 4698 u8 color, int enable, u64 changed)
5f9404ab
JC
4699{
4700 sdata->vif.bss_conf.he_bss_color.color = color;
4701 sdata->vif.bss_conf.he_bss_color.enabled = enable;
4702 changed |= BSS_CHANGED_HE_BSS_COLOR;
4703
d8675a63 4704 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
eb87d3e0
JC
4705
4706 if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) {
4707 struct ieee80211_sub_if_data *child;
4708
4709 mutex_lock(&sdata->local->iflist_mtx);
4710 list_for_each_entry(child, &sdata->local->interfaces, list) {
4711 if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) {
4712 child->vif.bss_conf.he_bss_color.color = color;
4713 child->vif.bss_conf.he_bss_color.enabled = enable;
d8675a63
JB
4714 ieee80211_link_info_change_notify(child,
4715 &child->deflink,
7b7090b4 4716 BSS_CHANGED_HE_BSS_COLOR);
eb87d3e0
JC
4717 }
4718 }
4719 mutex_unlock(&sdata->local->iflist_mtx);
4720 }
5f9404ab
JC
4721}
4722
4723static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata)
4724{
4725 struct ieee80211_local *local = sdata->local;
15ddba5f 4726 u64 changed = 0;
5f9404ab
JC
4727 int err;
4728
4729 sdata_assert_lock(sdata);
4730 lockdep_assert_held(&local->mtx);
4731
d0a9123e 4732 sdata->vif.bss_conf.color_change_active = false;
5f9404ab
JC
4733
4734 err = ieee80211_set_after_color_change_beacon(sdata, &changed);
4735 if (err) {
4736 cfg80211_color_change_aborted_notify(sdata->dev);
4737 return err;
4738 }
4739
4740 ieee80211_color_change_bss_config_notify(sdata,
d0a9123e 4741 sdata->vif.bss_conf.color_change_color,
5f9404ab
JC
4742 1, changed);
4743 cfg80211_color_change_notify(sdata->dev);
4744
4745 return 0;
4746}
4747
4748void ieee80211_color_change_finalize_work(struct work_struct *work)
4749{
4750 struct ieee80211_sub_if_data *sdata =
4751 container_of(work, struct ieee80211_sub_if_data,
bfd8403a 4752 deflink.color_change_finalize_work);
5f9404ab
JC
4753 struct ieee80211_local *local = sdata->local;
4754
4755 sdata_lock(sdata);
4756 mutex_lock(&local->mtx);
4757
4758 /* AP might have been stopped while waiting for the lock. */
d0a9123e 4759 if (!sdata->vif.bss_conf.color_change_active)
5f9404ab
JC
4760 goto unlock;
4761
4762 if (!ieee80211_sdata_running(sdata))
4763 goto unlock;
4764
4765 ieee80211_color_change_finalize(sdata);
4766
4767unlock:
4768 mutex_unlock(&local->mtx);
4769 sdata_unlock(sdata);
4770}
4771
92881884
LB
4772void ieee80211_color_collision_detection_work(struct work_struct *work)
4773{
4774 struct delayed_work *delayed_work = to_delayed_work(work);
4775 struct ieee80211_link_data *link =
4776 container_of(delayed_work, struct ieee80211_link_data,
4777 color_collision_detect_work);
4778 struct ieee80211_sub_if_data *sdata = link->sdata;
4779
4780 sdata_lock(sdata);
935ef47b 4781 cfg80211_obss_color_collision_notify(sdata->dev, link->color_bitmap);
92881884
LB
4782 sdata_unlock(sdata);
4783}
4784
5f9404ab
JC
4785void ieee80211_color_change_finish(struct ieee80211_vif *vif)
4786{
4787 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4788
4789 ieee80211_queue_work(&sdata->local->hw,
bfd8403a 4790 &sdata->deflink.color_change_finalize_work);
5f9404ab
JC
4791}
4792EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
4793
4794void
82253dda 4795ieee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
03895c84 4796 u64 color_bitmap, gfp_t gfp)
5f9404ab
JC
4797{
4798 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
92881884 4799 struct ieee80211_link_data *link = &sdata->deflink;
5f9404ab 4800
d0a9123e 4801 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active)
5f9404ab
JC
4802 return;
4803
92881884
LB
4804 if (delayed_work_pending(&link->color_collision_detect_work))
4805 return;
4806
4807 link->color_bitmap = color_bitmap;
4808 /* queue the color collision detection event every 500 ms in order to
4809 * avoid sending too much netlink messages to userspace.
4810 */
4811 ieee80211_queue_delayed_work(&sdata->local->hw,
4812 &link->color_collision_detect_work,
4813 msecs_to_jiffies(500));
5f9404ab 4814}
82253dda 4815EXPORT_SYMBOL_GPL(ieee80211_obss_color_collision_notify);
5f9404ab
JC
4816
4817static int
4818ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
4819 struct cfg80211_color_change_settings *params)
4820{
4821 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4822 struct ieee80211_local *local = sdata->local;
15ddba5f 4823 u64 changed = 0;
5f9404ab
JC
4824 int err;
4825
4826 sdata_assert_lock(sdata);
4827
eb87d3e0
JC
4828 if (sdata->vif.bss_conf.nontransmitted)
4829 return -EINVAL;
4830
5f9404ab
JC
4831 mutex_lock(&local->mtx);
4832
4833 /* don't allow another color change if one is already active or if csa
4834 * is active
4835 */
d0a9123e 4836 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active) {
5f9404ab
JC
4837 err = -EBUSY;
4838 goto out;
4839 }
4840
4841 err = ieee80211_set_color_change_beacon(sdata, params, &changed);
4842 if (err)
4843 goto out;
4844
d0a9123e
JB
4845 sdata->vif.bss_conf.color_change_active = true;
4846 sdata->vif.bss_conf.color_change_color = params->color;
5f9404ab
JC
4847
4848 cfg80211_color_change_started_notify(sdata->dev, params->count);
4849
4850 if (changed)
4851 ieee80211_color_change_bss_config_notify(sdata, 0, 0, changed);
4852 else
4853 /* if the beacon didn't change, we can finalize immediately */
4854 ieee80211_color_change_finalize(sdata);
4855
4856out:
4857 mutex_unlock(&local->mtx);
4858
4859 return err;
4860}
4861
237337c2 4862static int
a95bfb87
LB
4863ieee80211_set_radar_background(struct wiphy *wiphy,
4864 struct cfg80211_chan_def *chandef)
237337c2
LB
4865{
4866 struct ieee80211_local *local = wiphy_priv(wiphy);
4867
a95bfb87 4868 if (!local->ops->set_radar_background)
237337c2
LB
4869 return -EOPNOTSUPP;
4870
a95bfb87 4871 return local->ops->set_radar_background(&local->hw, chandef);
237337c2
LB
4872}
4873
0d8c4a3c
JB
4874static int ieee80211_add_intf_link(struct wiphy *wiphy,
4875 struct wireless_dev *wdev,
4876 unsigned int link_id)
4877{
4878 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
15846f95 4879 int res;
0d8c4a3c 4880
90703ba9
JB
4881 if (wdev->use_4addr)
4882 return -EOPNOTSUPP;
4883
15846f95 4884 mutex_lock(&sdata->local->mtx);
6d543b34 4885 res = ieee80211_vif_set_links(sdata, wdev->valid_links, 0);
15846f95
BB
4886 mutex_unlock(&sdata->local->mtx);
4887
4888 return res;
0d8c4a3c
JB
4889}
4890
4891static void ieee80211_del_intf_link(struct wiphy *wiphy,
4892 struct wireless_dev *wdev,
4893 unsigned int link_id)
4894{
4895 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4896
15846f95 4897 mutex_lock(&sdata->local->mtx);
6d543b34 4898 ieee80211_vif_set_links(sdata, wdev->valid_links, 0);
15846f95 4899 mutex_unlock(&sdata->local->mtx);
0d8c4a3c
JB
4900}
4901
21476ad1
ST
4902static int sta_add_link_station(struct ieee80211_local *local,
4903 struct ieee80211_sub_if_data *sdata,
4904 struct link_station_parameters *params)
4905{
4906 struct sta_info *sta;
4907 int ret;
4908
4909 sta = sta_info_get_bss(sdata, params->mld_mac);
4910 if (!sta)
4911 return -ENOENT;
4912
956b9613
JB
4913 if (!sta->sta.valid_links)
4914 return -EINVAL;
4915
21476ad1
ST
4916 if (sta->sta.valid_links & BIT(params->link_id))
4917 return -EALREADY;
4918
4919 ret = ieee80211_sta_allocate_link(sta, params->link_id);
4920 if (ret)
4921 return ret;
4922
9aebce6c 4923 ret = sta_link_apply_parameters(local, sta, true, params);
21476ad1
ST
4924 if (ret) {
4925 ieee80211_sta_free_link(sta, params->link_id);
4926 return ret;
4927 }
4928
4929 /* ieee80211_sta_activate_link frees the link upon failure */
4930 return ieee80211_sta_activate_link(sta, params->link_id);
4931}
4932
4933static int
4934ieee80211_add_link_station(struct wiphy *wiphy, struct net_device *dev,
4935 struct link_station_parameters *params)
4936{
4937 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4938 struct ieee80211_local *local = wiphy_priv(wiphy);
4939 int ret;
4940
4941 mutex_lock(&sdata->local->sta_mtx);
4942 ret = sta_add_link_station(local, sdata, params);
4943 mutex_unlock(&sdata->local->sta_mtx);
4944
4945 return ret;
4946}
4947
4948static int sta_mod_link_station(struct ieee80211_local *local,
4949 struct ieee80211_sub_if_data *sdata,
4950 struct link_station_parameters *params)
4951{
4952 struct sta_info *sta;
4953
4954 sta = sta_info_get_bss(sdata, params->mld_mac);
4955 if (!sta)
4956 return -ENOENT;
4957
4958 if (!(sta->sta.valid_links & BIT(params->link_id)))
4959 return -EINVAL;
4960
9aebce6c 4961 return sta_link_apply_parameters(local, sta, false, params);
21476ad1
ST
4962}
4963
4964static int
4965ieee80211_mod_link_station(struct wiphy *wiphy, struct net_device *dev,
4966 struct link_station_parameters *params)
4967{
4968 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4969 struct ieee80211_local *local = wiphy_priv(wiphy);
4970 int ret;
4971
4972 mutex_lock(&sdata->local->sta_mtx);
4973 ret = sta_mod_link_station(local, sdata, params);
4974 mutex_unlock(&sdata->local->sta_mtx);
4975
4976 return ret;
4977}
4978
4979static int sta_del_link_station(struct ieee80211_sub_if_data *sdata,
4980 struct link_station_del_parameters *params)
4981{
4982 struct sta_info *sta;
4983
4984 sta = sta_info_get_bss(sdata, params->mld_mac);
4985 if (!sta)
4986 return -ENOENT;
4987
4988 if (!(sta->sta.valid_links & BIT(params->link_id)))
4989 return -EINVAL;
4990
956b9613
JB
4991 /* must not create a STA without links */
4992 if (sta->sta.valid_links == BIT(params->link_id))
4993 return -EINVAL;
4994
21476ad1
ST
4995 ieee80211_sta_remove_link(sta, params->link_id);
4996
4997 return 0;
4998}
4999
5000static int
5001ieee80211_del_link_station(struct wiphy *wiphy, struct net_device *dev,
5002 struct link_station_del_parameters *params)
5003{
5004 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5005 int ret;
5006
5007 mutex_lock(&sdata->local->sta_mtx);
5008 ret = sta_del_link_station(sdata, params);
5009 mutex_unlock(&sdata->local->sta_mtx);
5010
5011 return ret;
5012}
5013
81202305
AS
5014static int ieee80211_set_hw_timestamp(struct wiphy *wiphy,
5015 struct net_device *dev,
5016 struct cfg80211_set_hw_timestamp *hwts)
5017{
5018 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5019 struct ieee80211_local *local = sdata->local;
5020
5021 if (!local->ops->set_hw_timestamp)
5022 return -EOPNOTSUPP;
5023
5024 if (!check_sdata_in_driver(sdata))
5025 return -EIO;
5026
5027 return local->ops->set_hw_timestamp(&local->hw, &sdata->vif, hwts);
5028}
5029
8a47cea7 5030const struct cfg80211_ops mac80211_config_ops = {
f0706e82
JB
5031 .add_virtual_intf = ieee80211_add_iface,
5032 .del_virtual_intf = ieee80211_del_iface,
42613db7 5033 .change_virtual_intf = ieee80211_change_iface,
f142c6b9
JB
5034 .start_p2p_device = ieee80211_start_p2p_device,
5035 .stop_p2p_device = ieee80211_stop_p2p_device,
e8cbb4cb
JB
5036 .add_key = ieee80211_add_key,
5037 .del_key = ieee80211_del_key,
62da92fb 5038 .get_key = ieee80211_get_key,
e8cbb4cb 5039 .set_default_key = ieee80211_config_default_key,
3cfcf6ac 5040 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
e5473e80 5041 .set_default_beacon_key = ieee80211_config_default_beacon_key,
8860020e
JB
5042 .start_ap = ieee80211_start_ap,
5043 .change_beacon = ieee80211_change_beacon,
5044 .stop_ap = ieee80211_stop_ap,
4fd6931e
JB
5045 .add_station = ieee80211_add_station,
5046 .del_station = ieee80211_del_station,
5047 .change_station = ieee80211_change_station,
7bbdd2d9 5048 .get_station = ieee80211_get_station,
c5dd9c2b 5049 .dump_station = ieee80211_dump_station,
1289723e 5050 .dump_survey = ieee80211_dump_survey,
c5dd9c2b
LCC
5051#ifdef CONFIG_MAC80211_MESH
5052 .add_mpath = ieee80211_add_mpath,
5053 .del_mpath = ieee80211_del_mpath,
5054 .change_mpath = ieee80211_change_mpath,
5055 .get_mpath = ieee80211_get_mpath,
5056 .dump_mpath = ieee80211_dump_mpath,
a2db2ed3
HR
5057 .get_mpp = ieee80211_get_mpp,
5058 .dump_mpp = ieee80211_dump_mpp,
24bdd9f4
JC
5059 .update_mesh_config = ieee80211_update_mesh_config,
5060 .get_mesh_config = ieee80211_get_mesh_config,
29cbe68c
JB
5061 .join_mesh = ieee80211_join_mesh,
5062 .leave_mesh = ieee80211_leave_mesh,
c5dd9c2b 5063#endif
239281f8
RL
5064 .join_ocb = ieee80211_join_ocb,
5065 .leave_ocb = ieee80211_leave_ocb,
9f1ba906 5066 .change_bss = ieee80211_change_bss,
108d2022 5067 .inform_bss = ieee80211_inform_bss,
31888487 5068 .set_txq_params = ieee80211_set_txq_params,
e8c9bd5b 5069 .set_monitor_channel = ieee80211_set_monitor_channel,
665af4fc
BC
5070 .suspend = ieee80211_suspend,
5071 .resume = ieee80211_resume,
2a519311 5072 .scan = ieee80211_scan,
91f123f2 5073 .abort_scan = ieee80211_abort_scan,
79f460ca
LC
5074 .sched_scan_start = ieee80211_sched_scan_start,
5075 .sched_scan_stop = ieee80211_sched_scan_stop,
636a5d36
JM
5076 .auth = ieee80211_auth,
5077 .assoc = ieee80211_assoc,
5078 .deauth = ieee80211_deauth,
5079 .disassoc = ieee80211_disassoc,
af8cdcd8
JB
5080 .join_ibss = ieee80211_join_ibss,
5081 .leave_ibss = ieee80211_leave_ibss,
391e53e3 5082 .set_mcast_rate = ieee80211_set_mcast_rate,
b9a5f8ca 5083 .set_wiphy_params = ieee80211_set_wiphy_params,
7643a2c3
JB
5084 .set_tx_power = ieee80211_set_tx_power,
5085 .get_tx_power = ieee80211_get_tx_power,
1f87f7d3 5086 .rfkill_poll = ieee80211_rfkill_poll,
aff89a9b 5087 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
71063f0e 5088 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
bc92afd9 5089 .set_power_mgmt = ieee80211_set_power_mgmt,
9930380f 5090 .set_bitrate_mask = ieee80211_set_bitrate_mask,
b8bc4b0a
JB
5091 .remain_on_channel = ieee80211_remain_on_channel,
5092 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
2e161f78 5093 .mgmt_tx = ieee80211_mgmt_tx,
f30221e4 5094 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
a97c13c3 5095 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
2c3c5f8c 5096 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
6cd536fe
JB
5097 .update_mgmt_frame_registrations =
5098 ieee80211_update_mgmt_frame_registrations,
15d96753
BR
5099 .set_antenna = ieee80211_set_antenna,
5100 .get_antenna = ieee80211_get_antenna,
c68f4b89 5101 .set_rekey_data = ieee80211_set_rekey_data,
dfe018bf
AN
5102 .tdls_oper = ieee80211_tdls_oper,
5103 .tdls_mgmt = ieee80211_tdls_mgmt,
a7a6bdd0
AN
5104 .tdls_channel_switch = ieee80211_tdls_channel_switch,
5105 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
06500736 5106 .probe_client = ieee80211_probe_client,
b53be792 5107 .set_noack_map = ieee80211_set_noack_map,
6d52563f
JB
5108#ifdef CONFIG_PM
5109 .set_wakeup = ieee80211_set_wakeup,
5110#endif
5b7ccaf3 5111 .get_channel = ieee80211_cfg_get_channel,
164eb02d 5112 .start_radar_detection = ieee80211_start_radar_detection,
26ec17a1 5113 .end_cac = ieee80211_end_cac,
73da7d5b 5114 .channel_switch = ieee80211_channel_switch,
32db6b54 5115 .set_qos_map = ieee80211_set_qos_map,
3b1700bd 5116 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
02219b3a
JB
5117 .add_tx_ts = ieee80211_add_tx_ts,
5118 .del_tx_ts = ieee80211_del_tx_ts,
708d50ed
AB
5119 .start_nan = ieee80211_start_nan,
5120 .stop_nan = ieee80211_stop_nan,
5953ff6d 5121 .nan_change_conf = ieee80211_nan_change_conf,
167e33f4
AB
5122 .add_nan_func = ieee80211_add_nan_func,
5123 .del_nan_func = ieee80211_del_nan_func,
ebceec86 5124 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
91180649 5125 .tx_control_port = ieee80211_tx_control_port,
2fe4a29a 5126 .get_txq_stats = ieee80211_get_txq_stats,
bc847970 5127 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
cee7013b
JB
5128 .start_pmsr = ieee80211_start_pmsr,
5129 .abort_pmsr = ieee80211_abort_pmsr,
8828f81a 5130 .probe_mesh_link = ieee80211_probe_mesh_link,
370f51d5
T
5131 .set_tid_config = ieee80211_set_tid_config,
5132 .reset_tid_config = ieee80211_reset_tid_config,
c534e093 5133 .set_sar_specs = ieee80211_set_sar_specs,
5f9404ab 5134 .color_change = ieee80211_color_change,
a95bfb87 5135 .set_radar_background = ieee80211_set_radar_background,
0d8c4a3c
JB
5136 .add_intf_link = ieee80211_add_intf_link,
5137 .del_intf_link = ieee80211_del_intf_link,
21476ad1
ST
5138 .add_link_station = ieee80211_add_link_station,
5139 .mod_link_station = ieee80211_mod_link_station,
5140 .del_link_station = ieee80211_del_link_station,
81202305 5141 .set_hw_timestamp = ieee80211_set_hw_timestamp,
f0706e82 5142};