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