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