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