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