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