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