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