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