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