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