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