2 * mac80211 configuration hooks for cfg80211
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
6 * This file is GPLv2 as found in COPYING.
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"
23 static struct wireless_dev
*ieee80211_add_iface(struct wiphy
*wiphy
,
25 enum nl80211_iftype type
,
27 struct vif_params
*params
)
29 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
30 struct wireless_dev
*wdev
;
31 struct ieee80211_sub_if_data
*sdata
;
34 err
= ieee80211_if_add(local
, name
, &wdev
, type
, params
);
38 if (type
== NL80211_IFTYPE_MONITOR
&& flags
) {
39 sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
40 sdata
->u
.mntr_flags
= *flags
;
46 static int ieee80211_del_iface(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
48 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev
));
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
)
58 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
61 ret
= ieee80211_if_change_type(sdata
, type
);
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
;
72 if (sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
&& flags
) {
73 struct ieee80211_local
*local
= sdata
->local
;
75 if (ieee80211_sdata_running(sdata
)) {
76 u32 mask
= MONITOR_FLAG_COOK_FRAMES
|
80 * Prohibit MONITOR_FLAG_COOK_FRAMES and
81 * MONITOR_FLAG_ACTIVE to be changed while the
83 * Else we would need to add a lot of cruft
84 * to update everything:
85 * cooked_mntrs, monitor and all fif_* counters
86 * reconfigure hardware
88 if ((*flags
& mask
) != (sdata
->u
.mntr_flags
& mask
))
91 ieee80211_adjust_monitor_flags(sdata
, -1);
92 sdata
->u
.mntr_flags
= *flags
;
93 ieee80211_adjust_monitor_flags(sdata
, 1);
95 ieee80211_configure_filter(local
);
98 * Because the interface is down, ieee80211_do_stop
99 * and ieee80211_do_open take care of "everything"
100 * mentioned in the comment above.
102 sdata
->u
.mntr_flags
= *flags
;
109 static int ieee80211_start_p2p_device(struct wiphy
*wiphy
,
110 struct wireless_dev
*wdev
)
112 return ieee80211_do_open(wdev
, true);
115 static void ieee80211_stop_p2p_device(struct wiphy
*wiphy
,
116 struct wireless_dev
*wdev
)
118 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev
));
121 static int ieee80211_set_noack_map(struct wiphy
*wiphy
,
122 struct net_device
*dev
,
125 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
127 sdata
->noack_map
= noack_map
;
131 static int ieee80211_add_key(struct wiphy
*wiphy
, struct net_device
*dev
,
132 u8 key_idx
, bool pairwise
, const u8
*mac_addr
,
133 struct key_params
*params
)
135 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
136 struct sta_info
*sta
= NULL
;
137 struct ieee80211_key
*key
;
140 if (!ieee80211_sdata_running(sdata
))
143 /* reject WEP and TKIP keys if WEP failed to initialize */
144 switch (params
->cipher
) {
145 case WLAN_CIPHER_SUITE_WEP40
:
146 case WLAN_CIPHER_SUITE_TKIP
:
147 case WLAN_CIPHER_SUITE_WEP104
:
148 if (IS_ERR(sdata
->local
->wep_tx_tfm
))
155 key
= ieee80211_key_alloc(params
->cipher
, key_idx
, params
->key_len
,
156 params
->key
, params
->seq_len
, params
->seq
);
161 key
->conf
.flags
|= IEEE80211_KEY_FLAG_PAIRWISE
;
163 mutex_lock(&sdata
->local
->sta_mtx
);
166 if (ieee80211_vif_is_mesh(&sdata
->vif
))
167 sta
= sta_info_get(sdata
, mac_addr
);
169 sta
= sta_info_get_bss(sdata
, mac_addr
);
171 * The ASSOC test makes sure the driver is ready to
172 * receive the key. When wpa_supplicant has roamed
173 * using FT, it attempts to set the key before
174 * association has completed, this rejects that attempt
175 * so it will set the key again after assocation.
177 * TODO: accept the key if we have a station entry and
178 * add it to the device after the station.
180 if (!sta
|| !test_sta_flag(sta
, WLAN_STA_ASSOC
)) {
181 ieee80211_key_free_unused(key
);
187 switch (sdata
->vif
.type
) {
188 case NL80211_IFTYPE_STATION
:
189 if (sdata
->u
.mgd
.mfp
!= IEEE80211_MFP_DISABLED
)
190 key
->conf
.flags
|= IEEE80211_KEY_FLAG_RX_MGMT
;
192 case NL80211_IFTYPE_AP
:
193 case NL80211_IFTYPE_AP_VLAN
:
194 /* Keys without a station are used for TX only */
195 if (key
->sta
&& test_sta_flag(key
->sta
, WLAN_STA_MFP
))
196 key
->conf
.flags
|= IEEE80211_KEY_FLAG_RX_MGMT
;
198 case NL80211_IFTYPE_ADHOC
:
201 case NL80211_IFTYPE_MESH_POINT
:
202 #ifdef CONFIG_MAC80211_MESH
203 if (sdata
->u
.mesh
.security
!= IEEE80211_MESH_SEC_NONE
)
204 key
->conf
.flags
|= IEEE80211_KEY_FLAG_RX_MGMT
;
207 case NL80211_IFTYPE_WDS
:
208 case NL80211_IFTYPE_MONITOR
:
209 case NL80211_IFTYPE_P2P_DEVICE
:
210 case NL80211_IFTYPE_UNSPECIFIED
:
211 case NUM_NL80211_IFTYPES
:
212 case NL80211_IFTYPE_P2P_CLIENT
:
213 case NL80211_IFTYPE_P2P_GO
:
214 /* shouldn't happen */
219 err
= ieee80211_key_link(key
, sdata
, sta
);
222 mutex_unlock(&sdata
->local
->sta_mtx
);
227 static int ieee80211_del_key(struct wiphy
*wiphy
, struct net_device
*dev
,
228 u8 key_idx
, bool pairwise
, const u8
*mac_addr
)
230 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
231 struct ieee80211_local
*local
= sdata
->local
;
232 struct sta_info
*sta
;
233 struct ieee80211_key
*key
= NULL
;
236 mutex_lock(&local
->sta_mtx
);
237 mutex_lock(&local
->key_mtx
);
242 sta
= sta_info_get_bss(sdata
, mac_addr
);
247 key
= key_mtx_dereference(local
, sta
->ptk
);
249 key
= key_mtx_dereference(local
, sta
->gtk
[key_idx
]);
251 key
= key_mtx_dereference(local
, sdata
->keys
[key_idx
]);
258 ieee80211_key_free(key
, true);
262 mutex_unlock(&local
->key_mtx
);
263 mutex_unlock(&local
->sta_mtx
);
268 static int ieee80211_get_key(struct wiphy
*wiphy
, struct net_device
*dev
,
269 u8 key_idx
, bool pairwise
, const u8
*mac_addr
,
271 void (*callback
)(void *cookie
,
272 struct key_params
*params
))
274 struct ieee80211_sub_if_data
*sdata
;
275 struct sta_info
*sta
= NULL
;
277 struct key_params params
;
278 struct ieee80211_key
*key
= NULL
;
284 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
289 sta
= sta_info_get_bss(sdata
, mac_addr
);
294 key
= rcu_dereference(sta
->ptk
);
295 else if (key_idx
< NUM_DEFAULT_KEYS
)
296 key
= rcu_dereference(sta
->gtk
[key_idx
]);
298 key
= rcu_dereference(sdata
->keys
[key_idx
]);
303 memset(¶ms
, 0, sizeof(params
));
305 params
.cipher
= key
->conf
.cipher
;
307 switch (key
->conf
.cipher
) {
308 case WLAN_CIPHER_SUITE_TKIP
:
309 iv32
= key
->u
.tkip
.tx
.iv32
;
310 iv16
= key
->u
.tkip
.tx
.iv16
;
312 if (key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
)
313 drv_get_tkip_seq(sdata
->local
,
314 key
->conf
.hw_key_idx
,
317 seq
[0] = iv16
& 0xff;
318 seq
[1] = (iv16
>> 8) & 0xff;
319 seq
[2] = iv32
& 0xff;
320 seq
[3] = (iv32
>> 8) & 0xff;
321 seq
[4] = (iv32
>> 16) & 0xff;
322 seq
[5] = (iv32
>> 24) & 0xff;
326 case WLAN_CIPHER_SUITE_CCMP
:
327 pn64
= atomic64_read(&key
->u
.ccmp
.tx_pn
);
337 case WLAN_CIPHER_SUITE_AES_CMAC
:
338 pn64
= atomic64_read(&key
->u
.aes_cmac
.tx_pn
);
350 params
.key
= key
->conf
.key
;
351 params
.key_len
= key
->conf
.keylen
;
353 callback(cookie
, ¶ms
);
361 static int ieee80211_config_default_key(struct wiphy
*wiphy
,
362 struct net_device
*dev
,
363 u8 key_idx
, bool uni
,
366 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
368 ieee80211_set_default_key(sdata
, key_idx
, uni
, multi
);
373 static int ieee80211_config_default_mgmt_key(struct wiphy
*wiphy
,
374 struct net_device
*dev
,
377 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
379 ieee80211_set_default_mgmt_key(sdata
, key_idx
);
384 void sta_set_rate_info_tx(struct sta_info
*sta
,
385 const struct ieee80211_tx_rate
*rate
,
386 struct rate_info
*rinfo
)
389 if (rate
->flags
& IEEE80211_TX_RC_MCS
) {
390 rinfo
->flags
|= RATE_INFO_FLAGS_MCS
;
391 rinfo
->mcs
= rate
->idx
;
392 } else if (rate
->flags
& IEEE80211_TX_RC_VHT_MCS
) {
393 rinfo
->flags
|= RATE_INFO_FLAGS_VHT_MCS
;
394 rinfo
->mcs
= ieee80211_rate_get_vht_mcs(rate
);
395 rinfo
->nss
= ieee80211_rate_get_vht_nss(rate
);
397 struct ieee80211_supported_band
*sband
;
398 int shift
= ieee80211_vif_get_shift(&sta
->sdata
->vif
);
401 sband
= sta
->local
->hw
.wiphy
->bands
[
402 ieee80211_get_sdata_band(sta
->sdata
)];
403 brate
= sband
->bitrates
[rate
->idx
].bitrate
;
404 rinfo
->legacy
= DIV_ROUND_UP(brate
, 1 << shift
);
406 if (rate
->flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
)
407 rinfo
->flags
|= RATE_INFO_FLAGS_40_MHZ_WIDTH
;
408 if (rate
->flags
& IEEE80211_TX_RC_80_MHZ_WIDTH
)
409 rinfo
->flags
|= RATE_INFO_FLAGS_80_MHZ_WIDTH
;
410 if (rate
->flags
& IEEE80211_TX_RC_160_MHZ_WIDTH
)
411 rinfo
->flags
|= RATE_INFO_FLAGS_160_MHZ_WIDTH
;
412 if (rate
->flags
& IEEE80211_TX_RC_SHORT_GI
)
413 rinfo
->flags
|= RATE_INFO_FLAGS_SHORT_GI
;
416 void sta_set_rate_info_rx(struct sta_info
*sta
, struct rate_info
*rinfo
)
420 if (sta
->last_rx_rate_flag
& RX_FLAG_HT
) {
421 rinfo
->flags
|= RATE_INFO_FLAGS_MCS
;
422 rinfo
->mcs
= sta
->last_rx_rate_idx
;
423 } else if (sta
->last_rx_rate_flag
& RX_FLAG_VHT
) {
424 rinfo
->flags
|= RATE_INFO_FLAGS_VHT_MCS
;
425 rinfo
->nss
= sta
->last_rx_rate_vht_nss
;
426 rinfo
->mcs
= sta
->last_rx_rate_idx
;
428 struct ieee80211_supported_band
*sband
;
429 int shift
= ieee80211_vif_get_shift(&sta
->sdata
->vif
);
432 sband
= sta
->local
->hw
.wiphy
->bands
[
433 ieee80211_get_sdata_band(sta
->sdata
)];
434 brate
= sband
->bitrates
[sta
->last_rx_rate_idx
].bitrate
;
435 rinfo
->legacy
= DIV_ROUND_UP(brate
, 1 << shift
);
438 if (sta
->last_rx_rate_flag
& RX_FLAG_40MHZ
)
439 rinfo
->flags
|= RATE_INFO_FLAGS_40_MHZ_WIDTH
;
440 if (sta
->last_rx_rate_flag
& RX_FLAG_SHORT_GI
)
441 rinfo
->flags
|= RATE_INFO_FLAGS_SHORT_GI
;
442 if (sta
->last_rx_rate_flag
& RX_FLAG_80MHZ
)
443 rinfo
->flags
|= RATE_INFO_FLAGS_80_MHZ_WIDTH
;
444 if (sta
->last_rx_rate_flag
& RX_FLAG_80P80MHZ
)
445 rinfo
->flags
|= RATE_INFO_FLAGS_80P80_MHZ_WIDTH
;
446 if (sta
->last_rx_rate_flag
& RX_FLAG_160MHZ
)
447 rinfo
->flags
|= RATE_INFO_FLAGS_160_MHZ_WIDTH
;
450 static void sta_set_sinfo(struct sta_info
*sta
, struct station_info
*sinfo
)
452 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
453 struct ieee80211_local
*local
= sdata
->local
;
454 struct timespec uptime
;
458 sinfo
->generation
= sdata
->local
->sta_generation
;
460 sinfo
->filled
= STATION_INFO_INACTIVE_TIME
|
461 STATION_INFO_RX_BYTES64
|
462 STATION_INFO_TX_BYTES64
|
463 STATION_INFO_RX_PACKETS
|
464 STATION_INFO_TX_PACKETS
|
465 STATION_INFO_TX_RETRIES
|
466 STATION_INFO_TX_FAILED
|
467 STATION_INFO_TX_BITRATE
|
468 STATION_INFO_RX_BITRATE
|
469 STATION_INFO_RX_DROP_MISC
|
470 STATION_INFO_BSS_PARAM
|
471 STATION_INFO_CONNECTED_TIME
|
472 STATION_INFO_STA_FLAGS
|
473 STATION_INFO_BEACON_LOSS_COUNT
;
475 do_posix_clock_monotonic_gettime(&uptime
);
476 sinfo
->connected_time
= uptime
.tv_sec
- sta
->last_connected
;
478 sinfo
->inactive_time
= jiffies_to_msecs(jiffies
- sta
->last_rx
);
480 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
481 sinfo
->tx_bytes
+= sta
->tx_bytes
[ac
];
482 packets
+= sta
->tx_packets
[ac
];
484 sinfo
->tx_packets
= packets
;
485 sinfo
->rx_bytes
= sta
->rx_bytes
;
486 sinfo
->rx_packets
= sta
->rx_packets
;
487 sinfo
->tx_retries
= sta
->tx_retry_count
;
488 sinfo
->tx_failed
= sta
->tx_retry_failed
;
489 sinfo
->rx_dropped_misc
= sta
->rx_dropped
;
490 sinfo
->beacon_loss_count
= sta
->beacon_loss_count
;
492 if ((sta
->local
->hw
.flags
& IEEE80211_HW_SIGNAL_DBM
) ||
493 (sta
->local
->hw
.flags
& IEEE80211_HW_SIGNAL_UNSPEC
)) {
494 sinfo
->filled
|= STATION_INFO_SIGNAL
| STATION_INFO_SIGNAL_AVG
;
495 if (!local
->ops
->get_rssi
||
496 drv_get_rssi(local
, sdata
, &sta
->sta
, &sinfo
->signal
))
497 sinfo
->signal
= (s8
)sta
->last_signal
;
498 sinfo
->signal_avg
= (s8
) -ewma_read(&sta
->avg_signal
);
501 sinfo
->filled
|= STATION_INFO_CHAIN_SIGNAL
|
502 STATION_INFO_CHAIN_SIGNAL_AVG
;
504 sinfo
->chains
= sta
->chains
;
505 for (i
= 0; i
< ARRAY_SIZE(sinfo
->chain_signal
); i
++) {
506 sinfo
->chain_signal
[i
] = sta
->chain_signal_last
[i
];
507 sinfo
->chain_signal_avg
[i
] =
508 (s8
) -ewma_read(&sta
->chain_signal_avg
[i
]);
512 sta_set_rate_info_tx(sta
, &sta
->last_tx_rate
, &sinfo
->txrate
);
513 sta_set_rate_info_rx(sta
, &sinfo
->rxrate
);
515 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
516 #ifdef CONFIG_MAC80211_MESH
517 sinfo
->filled
|= STATION_INFO_LLID
|
519 STATION_INFO_PLINK_STATE
|
520 STATION_INFO_LOCAL_PM
|
521 STATION_INFO_PEER_PM
|
522 STATION_INFO_NONPEER_PM
;
524 sinfo
->llid
= le16_to_cpu(sta
->llid
);
525 sinfo
->plid
= le16_to_cpu(sta
->plid
);
526 sinfo
->plink_state
= sta
->plink_state
;
527 if (test_sta_flag(sta
, WLAN_STA_TOFFSET_KNOWN
)) {
528 sinfo
->filled
|= STATION_INFO_T_OFFSET
;
529 sinfo
->t_offset
= sta
->t_offset
;
531 sinfo
->local_pm
= sta
->local_pm
;
532 sinfo
->peer_pm
= sta
->peer_pm
;
533 sinfo
->nonpeer_pm
= sta
->nonpeer_pm
;
537 sinfo
->bss_param
.flags
= 0;
538 if (sdata
->vif
.bss_conf
.use_cts_prot
)
539 sinfo
->bss_param
.flags
|= BSS_PARAM_FLAGS_CTS_PROT
;
540 if (sdata
->vif
.bss_conf
.use_short_preamble
)
541 sinfo
->bss_param
.flags
|= BSS_PARAM_FLAGS_SHORT_PREAMBLE
;
542 if (sdata
->vif
.bss_conf
.use_short_slot
)
543 sinfo
->bss_param
.flags
|= BSS_PARAM_FLAGS_SHORT_SLOT_TIME
;
544 sinfo
->bss_param
.dtim_period
= sdata
->local
->hw
.conf
.ps_dtim_period
;
545 sinfo
->bss_param
.beacon_interval
= sdata
->vif
.bss_conf
.beacon_int
;
547 sinfo
->sta_flags
.set
= 0;
548 sinfo
->sta_flags
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
549 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
550 BIT(NL80211_STA_FLAG_WME
) |
551 BIT(NL80211_STA_FLAG_MFP
) |
552 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
553 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
554 BIT(NL80211_STA_FLAG_TDLS_PEER
);
555 if (test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
556 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
557 if (test_sta_flag(sta
, WLAN_STA_SHORT_PREAMBLE
))
558 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
559 if (test_sta_flag(sta
, WLAN_STA_WME
))
560 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_WME
);
561 if (test_sta_flag(sta
, WLAN_STA_MFP
))
562 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_MFP
);
563 if (test_sta_flag(sta
, WLAN_STA_AUTH
))
564 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
);
565 if (test_sta_flag(sta
, WLAN_STA_ASSOC
))
566 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
567 if (test_sta_flag(sta
, WLAN_STA_TDLS_PEER
))
568 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
571 static const char ieee80211_gstrings_sta_stats
[][ETH_GSTRING_LEN
] = {
572 "rx_packets", "rx_bytes", "wep_weak_iv_count",
573 "rx_duplicates", "rx_fragments", "rx_dropped",
574 "tx_packets", "tx_bytes", "tx_fragments",
575 "tx_filtered", "tx_retry_failed", "tx_retries",
576 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
577 "channel", "noise", "ch_time", "ch_time_busy",
578 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
580 #define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
582 static int ieee80211_get_et_sset_count(struct wiphy
*wiphy
,
583 struct net_device
*dev
,
586 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
589 if (sset
== ETH_SS_STATS
)
592 rv
+= drv_get_et_sset_count(sdata
, sset
);
599 static void ieee80211_get_et_stats(struct wiphy
*wiphy
,
600 struct net_device
*dev
,
601 struct ethtool_stats
*stats
,
604 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
605 struct ieee80211_chanctx_conf
*chanctx_conf
;
606 struct ieee80211_channel
*channel
;
607 struct sta_info
*sta
;
608 struct ieee80211_local
*local
= sdata
->local
;
609 struct station_info sinfo
;
610 struct survey_info survey
;
612 #define STA_STATS_SURVEY_LEN 7
614 memset(data
, 0, sizeof(u64
) * STA_STATS_LEN
);
616 #define ADD_STA_STATS(sta) \
618 data[i++] += sta->rx_packets; \
619 data[i++] += sta->rx_bytes; \
620 data[i++] += sta->wep_weak_iv_count; \
621 data[i++] += sta->num_duplicates; \
622 data[i++] += sta->rx_fragments; \
623 data[i++] += sta->rx_dropped; \
625 data[i++] += sinfo.tx_packets; \
626 data[i++] += sinfo.tx_bytes; \
627 data[i++] += sta->tx_fragments; \
628 data[i++] += sta->tx_filtered_count; \
629 data[i++] += sta->tx_retry_failed; \
630 data[i++] += sta->tx_retry_count; \
631 data[i++] += sta->beacon_loss_count; \
634 /* For Managed stations, find the single station based on BSSID
635 * and use that. For interface types, iterate through all available
636 * stations and add stats for any station that is assigned to this
640 mutex_lock(&local
->sta_mtx
);
642 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
643 sta
= sta_info_get_bss(sdata
, sdata
->u
.mgd
.bssid
);
645 if (!(sta
&& !WARN_ON(sta
->sdata
->dev
!= dev
)))
649 sta_set_sinfo(sta
, &sinfo
);
654 data
[i
++] = sta
->sta_state
;
657 if (sinfo
.filled
& STATION_INFO_TX_BITRATE
)
659 cfg80211_calculate_bitrate(&sinfo
.txrate
);
661 if (sinfo
.filled
& STATION_INFO_RX_BITRATE
)
663 cfg80211_calculate_bitrate(&sinfo
.rxrate
);
666 if (sinfo
.filled
& STATION_INFO_SIGNAL_AVG
)
667 data
[i
] = (u8
)sinfo
.signal_avg
;
670 list_for_each_entry(sta
, &local
->sta_list
, list
) {
671 /* Make sure this station belongs to the proper dev */
672 if (sta
->sdata
->dev
!= dev
)
676 sta_set_sinfo(sta
, &sinfo
);
683 i
= STA_STATS_LEN
- STA_STATS_SURVEY_LEN
;
684 /* Get survey stats for current channel */
688 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
690 channel
= chanctx_conf
->def
.chan
;
699 if (drv_get_survey(local
, q
, &survey
) != 0) {
704 } while (channel
!= survey
.channel
);
708 data
[i
++] = survey
.channel
->center_freq
;
711 if (survey
.filled
& SURVEY_INFO_NOISE_DBM
)
712 data
[i
++] = (u8
)survey
.noise
;
715 if (survey
.filled
& SURVEY_INFO_CHANNEL_TIME
)
716 data
[i
++] = survey
.channel_time
;
719 if (survey
.filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
)
720 data
[i
++] = survey
.channel_time_busy
;
723 if (survey
.filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
)
724 data
[i
++] = survey
.channel_time_ext_busy
;
727 if (survey
.filled
& SURVEY_INFO_CHANNEL_TIME_RX
)
728 data
[i
++] = survey
.channel_time_rx
;
731 if (survey
.filled
& SURVEY_INFO_CHANNEL_TIME_TX
)
732 data
[i
++] = survey
.channel_time_tx
;
736 mutex_unlock(&local
->sta_mtx
);
738 if (WARN_ON(i
!= STA_STATS_LEN
))
741 drv_get_et_stats(sdata
, stats
, &(data
[STA_STATS_LEN
]));
744 static void ieee80211_get_et_strings(struct wiphy
*wiphy
,
745 struct net_device
*dev
,
748 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
749 int sz_sta_stats
= 0;
751 if (sset
== ETH_SS_STATS
) {
752 sz_sta_stats
= sizeof(ieee80211_gstrings_sta_stats
);
753 memcpy(data
, ieee80211_gstrings_sta_stats
, sz_sta_stats
);
755 drv_get_et_strings(sdata
, sset
, &(data
[sz_sta_stats
]));
758 static int ieee80211_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
759 int idx
, u8
*mac
, struct station_info
*sinfo
)
761 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
762 struct ieee80211_local
*local
= sdata
->local
;
763 struct sta_info
*sta
;
766 mutex_lock(&local
->sta_mtx
);
768 sta
= sta_info_get_by_idx(sdata
, idx
);
771 memcpy(mac
, sta
->sta
.addr
, ETH_ALEN
);
772 sta_set_sinfo(sta
, sinfo
);
775 mutex_unlock(&local
->sta_mtx
);
780 static int ieee80211_dump_survey(struct wiphy
*wiphy
, struct net_device
*dev
,
781 int idx
, struct survey_info
*survey
)
783 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
785 return drv_get_survey(local
, idx
, survey
);
788 static int ieee80211_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
789 u8
*mac
, struct station_info
*sinfo
)
791 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
792 struct ieee80211_local
*local
= sdata
->local
;
793 struct sta_info
*sta
;
796 mutex_lock(&local
->sta_mtx
);
798 sta
= sta_info_get_bss(sdata
, mac
);
801 sta_set_sinfo(sta
, sinfo
);
804 mutex_unlock(&local
->sta_mtx
);
809 static int ieee80211_set_monitor_channel(struct wiphy
*wiphy
,
810 struct cfg80211_chan_def
*chandef
)
812 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
813 struct ieee80211_sub_if_data
*sdata
;
816 if (cfg80211_chandef_identical(&local
->monitor_chandef
, chandef
))
819 mutex_lock(&local
->iflist_mtx
);
820 if (local
->use_chanctx
) {
821 sdata
= rcu_dereference_protected(
822 local
->monitor_sdata
,
823 lockdep_is_held(&local
->iflist_mtx
));
825 ieee80211_vif_release_channel(sdata
);
826 ret
= ieee80211_vif_use_channel(sdata
, chandef
,
827 IEEE80211_CHANCTX_EXCLUSIVE
);
829 } else if (local
->open_count
== local
->monitors
) {
830 local
->_oper_chandef
= *chandef
;
831 ieee80211_hw_config(local
, 0);
835 local
->monitor_chandef
= *chandef
;
836 mutex_unlock(&local
->iflist_mtx
);
841 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data
*sdata
,
842 const u8
*resp
, size_t resp_len
)
844 struct probe_resp
*new, *old
;
846 if (!resp
|| !resp_len
)
849 old
= rtnl_dereference(sdata
->u
.ap
.probe_resp
);
851 new = kzalloc(sizeof(struct probe_resp
) + resp_len
, GFP_KERNEL
);
856 memcpy(new->data
, resp
, resp_len
);
858 rcu_assign_pointer(sdata
->u
.ap
.probe_resp
, new);
860 kfree_rcu(old
, rcu_head
);
865 int ieee80211_assign_beacon(struct ieee80211_sub_if_data
*sdata
,
866 struct cfg80211_beacon_data
*params
)
868 struct beacon_data
*new, *old
;
869 int new_head_len
, new_tail_len
;
871 u32 changed
= BSS_CHANGED_BEACON
;
873 old
= rtnl_dereference(sdata
->u
.ap
.beacon
);
875 /* Need to have a beacon head if we don't have one yet */
876 if (!params
->head
&& !old
)
879 /* new or old head? */
881 new_head_len
= params
->head_len
;
883 new_head_len
= old
->head_len
;
885 /* new or old tail? */
886 if (params
->tail
|| !old
)
887 /* params->tail_len will be zero for !params->tail */
888 new_tail_len
= params
->tail_len
;
890 new_tail_len
= old
->tail_len
;
892 size
= sizeof(*new) + new_head_len
+ new_tail_len
;
894 new = kzalloc(size
, GFP_KERNEL
);
898 /* start filling the new info now */
901 * pointers go into the block we allocated,
902 * memory is | beacon_data | head | tail |
904 new->head
= ((u8
*) new) + sizeof(*new);
905 new->tail
= new->head
+ new_head_len
;
906 new->head_len
= new_head_len
;
907 new->tail_len
= new_tail_len
;
911 memcpy(new->head
, params
->head
, new_head_len
);
913 memcpy(new->head
, old
->head
, new_head_len
);
915 /* copy in optional tail */
917 memcpy(new->tail
, params
->tail
, new_tail_len
);
920 memcpy(new->tail
, old
->tail
, new_tail_len
);
922 err
= ieee80211_set_probe_resp(sdata
, params
->probe_resp
,
923 params
->probe_resp_len
);
927 changed
|= BSS_CHANGED_AP_PROBE_RESP
;
929 rcu_assign_pointer(sdata
->u
.ap
.beacon
, new);
932 kfree_rcu(old
, rcu_head
);
937 static int ieee80211_start_ap(struct wiphy
*wiphy
, struct net_device
*dev
,
938 struct cfg80211_ap_settings
*params
)
940 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
941 struct beacon_data
*old
;
942 struct ieee80211_sub_if_data
*vlan
;
943 u32 changed
= BSS_CHANGED_BEACON_INT
|
944 BSS_CHANGED_BEACON_ENABLED
|
950 old
= rtnl_dereference(sdata
->u
.ap
.beacon
);
954 /* TODO: make hostapd tell us what it wants */
955 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
956 sdata
->needed_rx_chains
= sdata
->local
->rx_chains
;
957 sdata
->radar_required
= params
->radar_required
;
959 err
= ieee80211_vif_use_channel(sdata
, ¶ms
->chandef
,
960 IEEE80211_CHANCTX_SHARED
);
963 ieee80211_vif_copy_chanctx_to_vlans(sdata
, false);
966 * Apply control port protocol, this allows us to
967 * not encrypt dynamic WEP control frames.
969 sdata
->control_port_protocol
= params
->crypto
.control_port_ethertype
;
970 sdata
->control_port_no_encrypt
= params
->crypto
.control_port_no_encrypt
;
971 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
) {
972 vlan
->control_port_protocol
=
973 params
->crypto
.control_port_ethertype
;
974 vlan
->control_port_no_encrypt
=
975 params
->crypto
.control_port_no_encrypt
;
978 sdata
->vif
.bss_conf
.beacon_int
= params
->beacon_interval
;
979 sdata
->vif
.bss_conf
.dtim_period
= params
->dtim_period
;
980 sdata
->vif
.bss_conf
.enable_beacon
= true;
982 sdata
->vif
.bss_conf
.ssid_len
= params
->ssid_len
;
983 if (params
->ssid_len
)
984 memcpy(sdata
->vif
.bss_conf
.ssid
, params
->ssid
,
986 sdata
->vif
.bss_conf
.hidden_ssid
=
987 (params
->hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
);
989 memset(&sdata
->vif
.bss_conf
.p2p_noa_attr
, 0,
990 sizeof(sdata
->vif
.bss_conf
.p2p_noa_attr
));
991 sdata
->vif
.bss_conf
.p2p_noa_attr
.oppps_ctwindow
=
992 params
->p2p_ctwindow
& IEEE80211_P2P_OPPPS_CTWINDOW_MASK
;
993 if (params
->p2p_opp_ps
)
994 sdata
->vif
.bss_conf
.p2p_noa_attr
.oppps_ctwindow
|=
995 IEEE80211_P2P_OPPPS_ENABLE_BIT
;
997 err
= ieee80211_assign_beacon(sdata
, ¶ms
->beacon
);
1002 err
= drv_start_ap(sdata
->local
, sdata
);
1004 old
= rtnl_dereference(sdata
->u
.ap
.beacon
);
1006 kfree_rcu(old
, rcu_head
);
1007 RCU_INIT_POINTER(sdata
->u
.ap
.beacon
, NULL
);
1011 ieee80211_bss_info_change_notify(sdata
, changed
);
1013 netif_carrier_on(dev
);
1014 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
)
1015 netif_carrier_on(vlan
->dev
);
1020 static int ieee80211_change_beacon(struct wiphy
*wiphy
, struct net_device
*dev
,
1021 struct cfg80211_beacon_data
*params
)
1023 struct ieee80211_sub_if_data
*sdata
;
1024 struct beacon_data
*old
;
1027 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1029 /* don't allow changing the beacon while CSA is in place - offset
1030 * of channel switch counter may change
1032 if (sdata
->vif
.csa_active
)
1035 old
= rtnl_dereference(sdata
->u
.ap
.beacon
);
1039 err
= ieee80211_assign_beacon(sdata
, params
);
1042 ieee80211_bss_info_change_notify(sdata
, err
);
1046 static int ieee80211_stop_ap(struct wiphy
*wiphy
, struct net_device
*dev
)
1048 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1049 struct ieee80211_sub_if_data
*vlan
;
1050 struct ieee80211_local
*local
= sdata
->local
;
1051 struct beacon_data
*old_beacon
;
1052 struct probe_resp
*old_probe_resp
;
1054 old_beacon
= rtnl_dereference(sdata
->u
.ap
.beacon
);
1057 old_probe_resp
= rtnl_dereference(sdata
->u
.ap
.probe_resp
);
1059 /* abort any running channel switch */
1060 sdata
->vif
.csa_active
= false;
1061 cancel_work_sync(&sdata
->csa_finalize_work
);
1062 cancel_work_sync(&sdata
->u
.ap
.request_smps_work
);
1064 /* turn off carrier for this interface and dependent VLANs */
1065 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
)
1066 netif_carrier_off(vlan
->dev
);
1067 netif_carrier_off(dev
);
1069 /* remove beacon and probe response */
1070 RCU_INIT_POINTER(sdata
->u
.ap
.beacon
, NULL
);
1071 RCU_INIT_POINTER(sdata
->u
.ap
.probe_resp
, NULL
);
1072 kfree_rcu(old_beacon
, rcu_head
);
1074 kfree_rcu(old_probe_resp
, rcu_head
);
1076 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
)
1077 sta_info_flush_defer(vlan
);
1078 sta_info_flush_defer(sdata
);
1081 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
) {
1082 sta_info_flush_cleanup(vlan
);
1083 ieee80211_free_keys(vlan
);
1085 sta_info_flush_cleanup(sdata
);
1086 ieee80211_free_keys(sdata
);
1088 sdata
->vif
.bss_conf
.enable_beacon
= false;
1089 sdata
->vif
.bss_conf
.ssid_len
= 0;
1090 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED
, &sdata
->state
);
1091 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BEACON_ENABLED
);
1093 if (sdata
->wdev
.cac_started
) {
1094 cancel_delayed_work_sync(&sdata
->dfs_cac_timer_work
);
1095 cfg80211_cac_event(sdata
->dev
, NL80211_RADAR_CAC_ABORTED
,
1099 drv_stop_ap(sdata
->local
, sdata
);
1101 /* free all potentially still buffered bcast frames */
1102 local
->total_ps_buffered
-= skb_queue_len(&sdata
->u
.ap
.ps
.bc_buf
);
1103 skb_queue_purge(&sdata
->u
.ap
.ps
.bc_buf
);
1105 ieee80211_vif_copy_chanctx_to_vlans(sdata
, true);
1106 ieee80211_vif_release_channel(sdata
);
1111 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1112 struct iapp_layer2_update
{
1113 u8 da
[ETH_ALEN
]; /* broadcast */
1114 u8 sa
[ETH_ALEN
]; /* STA addr */
1122 static void ieee80211_send_layer2_update(struct sta_info
*sta
)
1124 struct iapp_layer2_update
*msg
;
1125 struct sk_buff
*skb
;
1127 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1130 skb
= dev_alloc_skb(sizeof(*msg
));
1133 msg
= (struct iapp_layer2_update
*)skb_put(skb
, sizeof(*msg
));
1135 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1136 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1138 eth_broadcast_addr(msg
->da
);
1139 memcpy(msg
->sa
, sta
->sta
.addr
, ETH_ALEN
);
1140 msg
->len
= htons(6);
1142 msg
->ssap
= 0x01; /* NULL LSAP, CR Bit: Response */
1143 msg
->control
= 0xaf; /* XID response lsb.1111F101.
1144 * F=0 (no poll command; unsolicited frame) */
1145 msg
->xid_info
[0] = 0x81; /* XID format identifier */
1146 msg
->xid_info
[1] = 1; /* LLC types/classes: Type 1 LLC */
1147 msg
->xid_info
[2] = 0; /* XID sender's receive window size (RW) */
1149 skb
->dev
= sta
->sdata
->dev
;
1150 skb
->protocol
= eth_type_trans(skb
, sta
->sdata
->dev
);
1151 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1155 static int sta_apply_auth_flags(struct ieee80211_local
*local
,
1156 struct sta_info
*sta
,
1161 if (mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
) &&
1162 set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
) &&
1163 !test_sta_flag(sta
, WLAN_STA_AUTH
)) {
1164 ret
= sta_info_move_state(sta
, IEEE80211_STA_AUTH
);
1169 if (mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
) &&
1170 set
& BIT(NL80211_STA_FLAG_ASSOCIATED
) &&
1171 !test_sta_flag(sta
, WLAN_STA_ASSOC
)) {
1172 ret
= sta_info_move_state(sta
, IEEE80211_STA_ASSOC
);
1177 if (mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
1178 if (set
& BIT(NL80211_STA_FLAG_AUTHORIZED
))
1179 ret
= sta_info_move_state(sta
, IEEE80211_STA_AUTHORIZED
);
1180 else if (test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
1181 ret
= sta_info_move_state(sta
, IEEE80211_STA_ASSOC
);
1188 if (mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
) &&
1189 !(set
& BIT(NL80211_STA_FLAG_ASSOCIATED
)) &&
1190 test_sta_flag(sta
, WLAN_STA_ASSOC
)) {
1191 ret
= sta_info_move_state(sta
, IEEE80211_STA_AUTH
);
1196 if (mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
) &&
1197 !(set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
)) &&
1198 test_sta_flag(sta
, WLAN_STA_AUTH
)) {
1199 ret
= sta_info_move_state(sta
, IEEE80211_STA_NONE
);
1207 static int sta_apply_parameters(struct ieee80211_local
*local
,
1208 struct sta_info
*sta
,
1209 struct station_parameters
*params
)
1212 struct ieee80211_supported_band
*sband
;
1213 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
1214 enum ieee80211_band band
= ieee80211_get_sdata_band(sdata
);
1217 sband
= local
->hw
.wiphy
->bands
[band
];
1219 mask
= params
->sta_flags_mask
;
1220 set
= params
->sta_flags_set
;
1222 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
1224 * In mesh mode, ASSOCIATED isn't part of the nl80211
1225 * API but must follow AUTHENTICATED for driver state.
1227 if (mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
))
1228 mask
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
1229 if (set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
))
1230 set
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
1231 } else if (test_sta_flag(sta
, WLAN_STA_TDLS_PEER
)) {
1233 * TDLS -- everything follows authorized, but
1234 * only becoming authorized is possible, not
1237 if (set
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
1238 set
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
1239 BIT(NL80211_STA_FLAG_ASSOCIATED
);
1240 mask
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
1241 BIT(NL80211_STA_FLAG_ASSOCIATED
);
1245 ret
= sta_apply_auth_flags(local
, sta
, mask
, set
);
1249 if (mask
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
)) {
1250 if (set
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
))
1251 set_sta_flag(sta
, WLAN_STA_SHORT_PREAMBLE
);
1253 clear_sta_flag(sta
, WLAN_STA_SHORT_PREAMBLE
);
1256 if (mask
& BIT(NL80211_STA_FLAG_WME
)) {
1257 if (set
& BIT(NL80211_STA_FLAG_WME
)) {
1258 set_sta_flag(sta
, WLAN_STA_WME
);
1259 sta
->sta
.wme
= true;
1261 clear_sta_flag(sta
, WLAN_STA_WME
);
1262 sta
->sta
.wme
= false;
1266 if (mask
& BIT(NL80211_STA_FLAG_MFP
)) {
1267 if (set
& BIT(NL80211_STA_FLAG_MFP
))
1268 set_sta_flag(sta
, WLAN_STA_MFP
);
1270 clear_sta_flag(sta
, WLAN_STA_MFP
);
1273 if (mask
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) {
1274 if (set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
1275 set_sta_flag(sta
, WLAN_STA_TDLS_PEER
);
1277 clear_sta_flag(sta
, WLAN_STA_TDLS_PEER
);
1280 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
) {
1281 sta
->sta
.uapsd_queues
= params
->uapsd_queues
;
1282 sta
->sta
.max_sp
= params
->max_sp
;
1286 * cfg80211 validates this (1-2007) and allows setting the AID
1287 * only when creating a new station entry
1290 sta
->sta
.aid
= params
->aid
;
1293 * Some of the following updates would be racy if called on an
1294 * existing station, via ieee80211_change_station(). However,
1295 * all such changes are rejected by cfg80211 except for updates
1296 * changing the supported rates on an existing but not yet used
1300 if (params
->listen_interval
>= 0)
1301 sta
->listen_interval
= params
->listen_interval
;
1303 if (params
->supported_rates
) {
1304 ieee80211_parse_bitrates(&sdata
->vif
.bss_conf
.chandef
,
1305 sband
, params
->supported_rates
,
1306 params
->supported_rates_len
,
1307 &sta
->sta
.supp_rates
[band
]);
1310 if (params
->ht_capa
)
1311 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata
, sband
,
1312 params
->ht_capa
, sta
);
1314 if (params
->vht_capa
)
1315 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata
, sband
,
1316 params
->vht_capa
, sta
);
1318 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
1319 #ifdef CONFIG_MAC80211_MESH
1322 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
) {
1323 switch (params
->plink_state
) {
1324 case NL80211_PLINK_ESTAB
:
1325 if (sta
->plink_state
!= NL80211_PLINK_ESTAB
)
1326 changed
= mesh_plink_inc_estab_count(
1328 sta
->plink_state
= params
->plink_state
;
1330 ieee80211_mps_sta_status_update(sta
);
1331 changed
|= ieee80211_mps_set_sta_local_pm(sta
,
1332 sdata
->u
.mesh
.mshcfg
.power_mode
);
1334 case NL80211_PLINK_LISTEN
:
1335 case NL80211_PLINK_BLOCKED
:
1336 case NL80211_PLINK_OPN_SNT
:
1337 case NL80211_PLINK_OPN_RCVD
:
1338 case NL80211_PLINK_CNF_RCVD
:
1339 case NL80211_PLINK_HOLDING
:
1340 if (sta
->plink_state
== NL80211_PLINK_ESTAB
)
1341 changed
= mesh_plink_dec_estab_count(
1343 sta
->plink_state
= params
->plink_state
;
1345 ieee80211_mps_sta_status_update(sta
);
1346 changed
|= ieee80211_mps_set_sta_local_pm(sta
,
1347 NL80211_MESH_POWER_UNKNOWN
);
1355 switch (params
->plink_action
) {
1356 case NL80211_PLINK_ACTION_NO_ACTION
:
1359 case NL80211_PLINK_ACTION_OPEN
:
1360 changed
|= mesh_plink_open(sta
);
1362 case NL80211_PLINK_ACTION_BLOCK
:
1363 changed
|= mesh_plink_block(sta
);
1367 if (params
->local_pm
)
1369 ieee80211_mps_set_sta_local_pm(sta
,
1371 ieee80211_mbss_info_change_notify(sdata
, changed
);
1378 static int ieee80211_add_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1379 u8
*mac
, struct station_parameters
*params
)
1381 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1382 struct sta_info
*sta
;
1383 struct ieee80211_sub_if_data
*sdata
;
1388 sdata
= IEEE80211_DEV_TO_SUB_IF(params
->vlan
);
1390 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
1391 sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
1394 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1396 if (ether_addr_equal(mac
, sdata
->vif
.addr
))
1399 if (is_multicast_ether_addr(mac
))
1402 sta
= sta_info_alloc(sdata
, mac
, GFP_KERNEL
);
1407 * defaults -- if userspace wants something else we'll
1408 * change it accordingly in sta_apply_parameters()
1410 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))) {
1411 sta_info_pre_move_state(sta
, IEEE80211_STA_AUTH
);
1412 sta_info_pre_move_state(sta
, IEEE80211_STA_ASSOC
);
1415 err
= sta_apply_parameters(local
, sta
, params
);
1417 sta_info_free(local
, sta
);
1422 * for TDLS, rate control should be initialized only when
1423 * rates are known and station is marked authorized
1425 if (!test_sta_flag(sta
, WLAN_STA_TDLS_PEER
))
1426 rate_control_rate_init(sta
);
1428 layer2_update
= sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
||
1429 sdata
->vif
.type
== NL80211_IFTYPE_AP
;
1431 err
= sta_info_insert_rcu(sta
);
1438 ieee80211_send_layer2_update(sta
);
1445 static int ieee80211_del_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1448 struct ieee80211_sub_if_data
*sdata
;
1450 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1453 return sta_info_destroy_addr_bss(sdata
, mac
);
1455 sta_info_flush(sdata
);
1459 static int ieee80211_change_station(struct wiphy
*wiphy
,
1460 struct net_device
*dev
, u8
*mac
,
1461 struct station_parameters
*params
)
1463 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1464 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1465 struct sta_info
*sta
;
1466 struct ieee80211_sub_if_data
*vlansdata
;
1467 enum cfg80211_station_type statype
;
1470 mutex_lock(&local
->sta_mtx
);
1472 sta
= sta_info_get_bss(sdata
, mac
);
1478 switch (sdata
->vif
.type
) {
1479 case NL80211_IFTYPE_MESH_POINT
:
1480 if (sdata
->u
.mesh
.user_mpm
)
1481 statype
= CFG80211_STA_MESH_PEER_USER
;
1483 statype
= CFG80211_STA_MESH_PEER_KERNEL
;
1485 case NL80211_IFTYPE_ADHOC
:
1486 statype
= CFG80211_STA_IBSS
;
1488 case NL80211_IFTYPE_STATION
:
1489 if (!test_sta_flag(sta
, WLAN_STA_TDLS_PEER
)) {
1490 statype
= CFG80211_STA_AP_STA
;
1493 if (test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
1494 statype
= CFG80211_STA_TDLS_PEER_ACTIVE
;
1496 statype
= CFG80211_STA_TDLS_PEER_SETUP
;
1498 case NL80211_IFTYPE_AP
:
1499 case NL80211_IFTYPE_AP_VLAN
:
1500 statype
= CFG80211_STA_AP_CLIENT
;
1507 err
= cfg80211_check_station_change(wiphy
, params
, statype
);
1511 if (params
->vlan
&& params
->vlan
!= sta
->sdata
->dev
) {
1512 bool prev_4addr
= false;
1513 bool new_4addr
= false;
1515 vlansdata
= IEEE80211_DEV_TO_SUB_IF(params
->vlan
);
1517 if (params
->vlan
->ieee80211_ptr
->use_4addr
) {
1518 if (vlansdata
->u
.vlan
.sta
) {
1523 rcu_assign_pointer(vlansdata
->u
.vlan
.sta
, sta
);
1527 if (sta
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&&
1528 sta
->sdata
->u
.vlan
.sta
) {
1529 rcu_assign_pointer(sta
->sdata
->u
.vlan
.sta
, NULL
);
1533 sta
->sdata
= vlansdata
;
1535 if (sta
->sta_state
== IEEE80211_STA_AUTHORIZED
&&
1536 prev_4addr
!= new_4addr
) {
1538 atomic_dec(&sta
->sdata
->bss
->num_mcast_sta
);
1540 atomic_inc(&sta
->sdata
->bss
->num_mcast_sta
);
1543 ieee80211_send_layer2_update(sta
);
1546 err
= sta_apply_parameters(local
, sta
, params
);
1550 /* When peer becomes authorized, init rate control as well */
1551 if (test_sta_flag(sta
, WLAN_STA_TDLS_PEER
) &&
1552 test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
1553 rate_control_rate_init(sta
);
1555 mutex_unlock(&local
->sta_mtx
);
1557 if ((sdata
->vif
.type
== NL80211_IFTYPE_AP
||
1558 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
) &&
1559 sta
->known_smps_mode
!= sta
->sdata
->bss
->req_smps
&&
1560 test_sta_flag(sta
, WLAN_STA_AUTHORIZED
) &&
1561 sta_info_tx_streams(sta
) != 1) {
1563 "%pM just authorized and MIMO capable - update SMPS\n",
1565 ieee80211_send_smps_action(sta
->sdata
,
1566 sta
->sdata
->bss
->req_smps
,
1568 sta
->sdata
->vif
.bss_conf
.bssid
);
1571 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
&&
1572 params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
1573 ieee80211_recalc_ps(local
, -1);
1574 ieee80211_recalc_ps_vif(sdata
);
1579 mutex_unlock(&local
->sta_mtx
);
1583 #ifdef CONFIG_MAC80211_MESH
1584 static int ieee80211_add_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1585 u8
*dst
, u8
*next_hop
)
1587 struct ieee80211_sub_if_data
*sdata
;
1588 struct mesh_path
*mpath
;
1589 struct sta_info
*sta
;
1591 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1594 sta
= sta_info_get(sdata
, next_hop
);
1600 mpath
= mesh_path_add(sdata
, dst
);
1601 if (IS_ERR(mpath
)) {
1603 return PTR_ERR(mpath
);
1606 mesh_path_fix_nexthop(mpath
, sta
);
1612 static int ieee80211_del_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1615 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1618 return mesh_path_del(sdata
, dst
);
1620 mesh_path_flush_by_iface(sdata
);
1624 static int ieee80211_change_mpath(struct wiphy
*wiphy
,
1625 struct net_device
*dev
,
1626 u8
*dst
, u8
*next_hop
)
1628 struct ieee80211_sub_if_data
*sdata
;
1629 struct mesh_path
*mpath
;
1630 struct sta_info
*sta
;
1632 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1636 sta
= sta_info_get(sdata
, next_hop
);
1642 mpath
= mesh_path_lookup(sdata
, dst
);
1648 mesh_path_fix_nexthop(mpath
, sta
);
1654 static void mpath_set_pinfo(struct mesh_path
*mpath
, u8
*next_hop
,
1655 struct mpath_info
*pinfo
)
1657 struct sta_info
*next_hop_sta
= rcu_dereference(mpath
->next_hop
);
1660 memcpy(next_hop
, next_hop_sta
->sta
.addr
, ETH_ALEN
);
1662 memset(next_hop
, 0, ETH_ALEN
);
1664 memset(pinfo
, 0, sizeof(*pinfo
));
1666 pinfo
->generation
= mesh_paths_generation
;
1668 pinfo
->filled
= MPATH_INFO_FRAME_QLEN
|
1671 MPATH_INFO_EXPTIME
|
1672 MPATH_INFO_DISCOVERY_TIMEOUT
|
1673 MPATH_INFO_DISCOVERY_RETRIES
|
1676 pinfo
->frame_qlen
= mpath
->frame_queue
.qlen
;
1677 pinfo
->sn
= mpath
->sn
;
1678 pinfo
->metric
= mpath
->metric
;
1679 if (time_before(jiffies
, mpath
->exp_time
))
1680 pinfo
->exptime
= jiffies_to_msecs(mpath
->exp_time
- jiffies
);
1681 pinfo
->discovery_timeout
=
1682 jiffies_to_msecs(mpath
->discovery_timeout
);
1683 pinfo
->discovery_retries
= mpath
->discovery_retries
;
1684 if (mpath
->flags
& MESH_PATH_ACTIVE
)
1685 pinfo
->flags
|= NL80211_MPATH_FLAG_ACTIVE
;
1686 if (mpath
->flags
& MESH_PATH_RESOLVING
)
1687 pinfo
->flags
|= NL80211_MPATH_FLAG_RESOLVING
;
1688 if (mpath
->flags
& MESH_PATH_SN_VALID
)
1689 pinfo
->flags
|= NL80211_MPATH_FLAG_SN_VALID
;
1690 if (mpath
->flags
& MESH_PATH_FIXED
)
1691 pinfo
->flags
|= NL80211_MPATH_FLAG_FIXED
;
1692 if (mpath
->flags
& MESH_PATH_RESOLVED
)
1693 pinfo
->flags
|= NL80211_MPATH_FLAG_RESOLVED
;
1696 static int ieee80211_get_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1697 u8
*dst
, u8
*next_hop
, struct mpath_info
*pinfo
)
1700 struct ieee80211_sub_if_data
*sdata
;
1701 struct mesh_path
*mpath
;
1703 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1706 mpath
= mesh_path_lookup(sdata
, dst
);
1711 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
1712 mpath_set_pinfo(mpath
, next_hop
, pinfo
);
1717 static int ieee80211_dump_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1718 int idx
, u8
*dst
, u8
*next_hop
,
1719 struct mpath_info
*pinfo
)
1721 struct ieee80211_sub_if_data
*sdata
;
1722 struct mesh_path
*mpath
;
1724 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1727 mpath
= mesh_path_lookup_by_idx(sdata
, idx
);
1732 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
1733 mpath_set_pinfo(mpath
, next_hop
, pinfo
);
1738 static int ieee80211_get_mesh_config(struct wiphy
*wiphy
,
1739 struct net_device
*dev
,
1740 struct mesh_config
*conf
)
1742 struct ieee80211_sub_if_data
*sdata
;
1743 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1745 memcpy(conf
, &(sdata
->u
.mesh
.mshcfg
), sizeof(struct mesh_config
));
1749 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm
, u32 mask
)
1751 return (mask
>> (parm
-1)) & 0x1;
1754 static int copy_mesh_setup(struct ieee80211_if_mesh
*ifmsh
,
1755 const struct mesh_setup
*setup
)
1759 struct ieee80211_sub_if_data
*sdata
= container_of(ifmsh
,
1760 struct ieee80211_sub_if_data
, u
.mesh
);
1762 /* allocate information elements */
1766 if (setup
->ie_len
) {
1767 new_ie
= kmemdup(setup
->ie
, setup
->ie_len
,
1772 ifmsh
->ie_len
= setup
->ie_len
;
1776 /* now copy the rest of the setup parameters */
1777 ifmsh
->mesh_id_len
= setup
->mesh_id_len
;
1778 memcpy(ifmsh
->mesh_id
, setup
->mesh_id
, ifmsh
->mesh_id_len
);
1779 ifmsh
->mesh_sp_id
= setup
->sync_method
;
1780 ifmsh
->mesh_pp_id
= setup
->path_sel_proto
;
1781 ifmsh
->mesh_pm_id
= setup
->path_metric
;
1782 ifmsh
->user_mpm
= setup
->user_mpm
;
1783 ifmsh
->mesh_auth_id
= setup
->auth_id
;
1784 ifmsh
->security
= IEEE80211_MESH_SEC_NONE
;
1785 if (setup
->is_authenticated
)
1786 ifmsh
->security
|= IEEE80211_MESH_SEC_AUTHED
;
1787 if (setup
->is_secure
)
1788 ifmsh
->security
|= IEEE80211_MESH_SEC_SECURED
;
1790 /* mcast rate setting in Mesh Node */
1791 memcpy(sdata
->vif
.bss_conf
.mcast_rate
, setup
->mcast_rate
,
1792 sizeof(setup
->mcast_rate
));
1793 sdata
->vif
.bss_conf
.basic_rates
= setup
->basic_rates
;
1795 sdata
->vif
.bss_conf
.beacon_int
= setup
->beacon_interval
;
1796 sdata
->vif
.bss_conf
.dtim_period
= setup
->dtim_period
;
1801 static int ieee80211_update_mesh_config(struct wiphy
*wiphy
,
1802 struct net_device
*dev
, u32 mask
,
1803 const struct mesh_config
*nconf
)
1805 struct mesh_config
*conf
;
1806 struct ieee80211_sub_if_data
*sdata
;
1807 struct ieee80211_if_mesh
*ifmsh
;
1809 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1810 ifmsh
= &sdata
->u
.mesh
;
1812 /* Set the config options which we are interested in setting */
1813 conf
= &(sdata
->u
.mesh
.mshcfg
);
1814 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT
, mask
))
1815 conf
->dot11MeshRetryTimeout
= nconf
->dot11MeshRetryTimeout
;
1816 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT
, mask
))
1817 conf
->dot11MeshConfirmTimeout
= nconf
->dot11MeshConfirmTimeout
;
1818 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT
, mask
))
1819 conf
->dot11MeshHoldingTimeout
= nconf
->dot11MeshHoldingTimeout
;
1820 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS
, mask
))
1821 conf
->dot11MeshMaxPeerLinks
= nconf
->dot11MeshMaxPeerLinks
;
1822 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES
, mask
))
1823 conf
->dot11MeshMaxRetries
= nconf
->dot11MeshMaxRetries
;
1824 if (_chg_mesh_attr(NL80211_MESHCONF_TTL
, mask
))
1825 conf
->dot11MeshTTL
= nconf
->dot11MeshTTL
;
1826 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL
, mask
))
1827 conf
->element_ttl
= nconf
->element_ttl
;
1828 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS
, mask
)) {
1829 if (ifmsh
->user_mpm
)
1831 conf
->auto_open_plinks
= nconf
->auto_open_plinks
;
1833 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
, mask
))
1834 conf
->dot11MeshNbrOffsetMaxNeighbor
=
1835 nconf
->dot11MeshNbrOffsetMaxNeighbor
;
1836 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
, mask
))
1837 conf
->dot11MeshHWMPmaxPREQretries
=
1838 nconf
->dot11MeshHWMPmaxPREQretries
;
1839 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME
, mask
))
1840 conf
->path_refresh_time
= nconf
->path_refresh_time
;
1841 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
, mask
))
1842 conf
->min_discovery_timeout
= nconf
->min_discovery_timeout
;
1843 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
, mask
))
1844 conf
->dot11MeshHWMPactivePathTimeout
=
1845 nconf
->dot11MeshHWMPactivePathTimeout
;
1846 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
, mask
))
1847 conf
->dot11MeshHWMPpreqMinInterval
=
1848 nconf
->dot11MeshHWMPpreqMinInterval
;
1849 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
, mask
))
1850 conf
->dot11MeshHWMPperrMinInterval
=
1851 nconf
->dot11MeshHWMPperrMinInterval
;
1852 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
1854 conf
->dot11MeshHWMPnetDiameterTraversalTime
=
1855 nconf
->dot11MeshHWMPnetDiameterTraversalTime
;
1856 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE
, mask
)) {
1857 conf
->dot11MeshHWMPRootMode
= nconf
->dot11MeshHWMPRootMode
;
1858 ieee80211_mesh_root_setup(ifmsh
);
1860 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS
, mask
)) {
1861 /* our current gate announcement implementation rides on root
1862 * announcements, so require this ifmsh to also be a root node
1864 if (nconf
->dot11MeshGateAnnouncementProtocol
&&
1865 !(conf
->dot11MeshHWMPRootMode
> IEEE80211_ROOTMODE_ROOT
)) {
1866 conf
->dot11MeshHWMPRootMode
= IEEE80211_PROACTIVE_RANN
;
1867 ieee80211_mesh_root_setup(ifmsh
);
1869 conf
->dot11MeshGateAnnouncementProtocol
=
1870 nconf
->dot11MeshGateAnnouncementProtocol
;
1872 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL
, mask
))
1873 conf
->dot11MeshHWMPRannInterval
=
1874 nconf
->dot11MeshHWMPRannInterval
;
1875 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING
, mask
))
1876 conf
->dot11MeshForwarding
= nconf
->dot11MeshForwarding
;
1877 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD
, mask
)) {
1878 /* our RSSI threshold implementation is supported only for
1879 * devices that report signal in dBm.
1881 if (!(sdata
->local
->hw
.flags
& IEEE80211_HW_SIGNAL_DBM
))
1883 conf
->rssi_threshold
= nconf
->rssi_threshold
;
1885 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE
, mask
)) {
1886 conf
->ht_opmode
= nconf
->ht_opmode
;
1887 sdata
->vif
.bss_conf
.ht_operation_mode
= nconf
->ht_opmode
;
1888 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_HT
);
1890 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
, mask
))
1891 conf
->dot11MeshHWMPactivePathToRootTimeout
=
1892 nconf
->dot11MeshHWMPactivePathToRootTimeout
;
1893 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL
, mask
))
1894 conf
->dot11MeshHWMProotInterval
=
1895 nconf
->dot11MeshHWMProotInterval
;
1896 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
, mask
))
1897 conf
->dot11MeshHWMPconfirmationInterval
=
1898 nconf
->dot11MeshHWMPconfirmationInterval
;
1899 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE
, mask
)) {
1900 conf
->power_mode
= nconf
->power_mode
;
1901 ieee80211_mps_local_status_update(sdata
);
1903 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW
, mask
))
1904 conf
->dot11MeshAwakeWindowDuration
=
1905 nconf
->dot11MeshAwakeWindowDuration
;
1906 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT
, mask
))
1907 conf
->plink_timeout
= nconf
->plink_timeout
;
1908 ieee80211_mbss_info_change_notify(sdata
, BSS_CHANGED_BEACON
);
1912 static int ieee80211_join_mesh(struct wiphy
*wiphy
, struct net_device
*dev
,
1913 const struct mesh_config
*conf
,
1914 const struct mesh_setup
*setup
)
1916 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1917 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
1920 memcpy(&ifmsh
->mshcfg
, conf
, sizeof(struct mesh_config
));
1921 err
= copy_mesh_setup(ifmsh
, setup
);
1925 /* can mesh use other SMPS modes? */
1926 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
1927 sdata
->needed_rx_chains
= sdata
->local
->rx_chains
;
1929 err
= ieee80211_vif_use_channel(sdata
, &setup
->chandef
,
1930 IEEE80211_CHANCTX_SHARED
);
1934 return ieee80211_start_mesh(sdata
);
1937 static int ieee80211_leave_mesh(struct wiphy
*wiphy
, struct net_device
*dev
)
1939 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1941 ieee80211_stop_mesh(sdata
);
1942 ieee80211_vif_release_channel(sdata
);
1948 static int ieee80211_change_bss(struct wiphy
*wiphy
,
1949 struct net_device
*dev
,
1950 struct bss_parameters
*params
)
1952 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1953 enum ieee80211_band band
;
1956 if (!rtnl_dereference(sdata
->u
.ap
.beacon
))
1959 band
= ieee80211_get_sdata_band(sdata
);
1961 if (params
->use_cts_prot
>= 0) {
1962 sdata
->vif
.bss_conf
.use_cts_prot
= params
->use_cts_prot
;
1963 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
1965 if (params
->use_short_preamble
>= 0) {
1966 sdata
->vif
.bss_conf
.use_short_preamble
=
1967 params
->use_short_preamble
;
1968 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
1971 if (!sdata
->vif
.bss_conf
.use_short_slot
&&
1972 band
== IEEE80211_BAND_5GHZ
) {
1973 sdata
->vif
.bss_conf
.use_short_slot
= true;
1974 changed
|= BSS_CHANGED_ERP_SLOT
;
1977 if (params
->use_short_slot_time
>= 0) {
1978 sdata
->vif
.bss_conf
.use_short_slot
=
1979 params
->use_short_slot_time
;
1980 changed
|= BSS_CHANGED_ERP_SLOT
;
1983 if (params
->basic_rates
) {
1984 ieee80211_parse_bitrates(&sdata
->vif
.bss_conf
.chandef
,
1986 params
->basic_rates
,
1987 params
->basic_rates_len
,
1988 &sdata
->vif
.bss_conf
.basic_rates
);
1989 changed
|= BSS_CHANGED_BASIC_RATES
;
1992 if (params
->ap_isolate
>= 0) {
1993 if (params
->ap_isolate
)
1994 sdata
->flags
|= IEEE80211_SDATA_DONT_BRIDGE_PACKETS
;
1996 sdata
->flags
&= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS
;
1999 if (params
->ht_opmode
>= 0) {
2000 sdata
->vif
.bss_conf
.ht_operation_mode
=
2001 (u16
) params
->ht_opmode
;
2002 changed
|= BSS_CHANGED_HT
;
2005 if (params
->p2p_ctwindow
>= 0) {
2006 sdata
->vif
.bss_conf
.p2p_noa_attr
.oppps_ctwindow
&=
2007 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK
;
2008 sdata
->vif
.bss_conf
.p2p_noa_attr
.oppps_ctwindow
|=
2009 params
->p2p_ctwindow
& IEEE80211_P2P_OPPPS_CTWINDOW_MASK
;
2010 changed
|= BSS_CHANGED_P2P_PS
;
2013 if (params
->p2p_opp_ps
> 0) {
2014 sdata
->vif
.bss_conf
.p2p_noa_attr
.oppps_ctwindow
|=
2015 IEEE80211_P2P_OPPPS_ENABLE_BIT
;
2016 changed
|= BSS_CHANGED_P2P_PS
;
2017 } else if (params
->p2p_opp_ps
== 0) {
2018 sdata
->vif
.bss_conf
.p2p_noa_attr
.oppps_ctwindow
&=
2019 ~IEEE80211_P2P_OPPPS_ENABLE_BIT
;
2020 changed
|= BSS_CHANGED_P2P_PS
;
2023 ieee80211_bss_info_change_notify(sdata
, changed
);
2028 static int ieee80211_set_txq_params(struct wiphy
*wiphy
,
2029 struct net_device
*dev
,
2030 struct ieee80211_txq_params
*params
)
2032 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2033 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2034 struct ieee80211_tx_queue_params p
;
2036 if (!local
->ops
->conf_tx
)
2039 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
2042 memset(&p
, 0, sizeof(p
));
2043 p
.aifs
= params
->aifs
;
2044 p
.cw_max
= params
->cwmax
;
2045 p
.cw_min
= params
->cwmin
;
2046 p
.txop
= params
->txop
;
2049 * Setting tx queue params disables u-apsd because it's only
2050 * called in master mode.
2054 sdata
->tx_conf
[params
->ac
] = p
;
2055 if (drv_conf_tx(local
, sdata
, params
->ac
, &p
)) {
2056 wiphy_debug(local
->hw
.wiphy
,
2057 "failed to set TX queue parameters for AC %d\n",
2062 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_QOS
);
2068 static int ieee80211_suspend(struct wiphy
*wiphy
,
2069 struct cfg80211_wowlan
*wowlan
)
2071 return __ieee80211_suspend(wiphy_priv(wiphy
), wowlan
);
2074 static int ieee80211_resume(struct wiphy
*wiphy
)
2076 return __ieee80211_resume(wiphy_priv(wiphy
));
2079 #define ieee80211_suspend NULL
2080 #define ieee80211_resume NULL
2083 static int ieee80211_scan(struct wiphy
*wiphy
,
2084 struct cfg80211_scan_request
*req
)
2086 struct ieee80211_sub_if_data
*sdata
;
2088 sdata
= IEEE80211_WDEV_TO_SUB_IF(req
->wdev
);
2090 switch (ieee80211_vif_type_p2p(&sdata
->vif
)) {
2091 case NL80211_IFTYPE_STATION
:
2092 case NL80211_IFTYPE_ADHOC
:
2093 case NL80211_IFTYPE_MESH_POINT
:
2094 case NL80211_IFTYPE_P2P_CLIENT
:
2095 case NL80211_IFTYPE_P2P_DEVICE
:
2097 case NL80211_IFTYPE_P2P_GO
:
2098 if (sdata
->local
->ops
->hw_scan
)
2101 * FIXME: implement NoA while scanning in software,
2102 * for now fall through to allow scanning only when
2103 * beaconing hasn't been configured yet
2105 case NL80211_IFTYPE_AP
:
2107 * If the scan has been forced (and the driver supports
2108 * forcing), don't care about being beaconing already.
2109 * This will create problems to the attached stations (e.g. all
2110 * the frames sent while scanning on other channel will be
2113 if (sdata
->u
.ap
.beacon
&&
2114 (!(wiphy
->features
& NL80211_FEATURE_AP_SCAN
) ||
2115 !(req
->flags
& NL80211_SCAN_FLAG_AP
)))
2122 return ieee80211_request_scan(sdata
, req
);
2126 ieee80211_sched_scan_start(struct wiphy
*wiphy
,
2127 struct net_device
*dev
,
2128 struct cfg80211_sched_scan_request
*req
)
2130 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2132 if (!sdata
->local
->ops
->sched_scan_start
)
2135 return ieee80211_request_sched_scan_start(sdata
, req
);
2139 ieee80211_sched_scan_stop(struct wiphy
*wiphy
, struct net_device
*dev
)
2141 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2143 if (!sdata
->local
->ops
->sched_scan_stop
)
2146 return ieee80211_request_sched_scan_stop(sdata
);
2149 static int ieee80211_auth(struct wiphy
*wiphy
, struct net_device
*dev
,
2150 struct cfg80211_auth_request
*req
)
2152 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
2155 static int ieee80211_assoc(struct wiphy
*wiphy
, struct net_device
*dev
,
2156 struct cfg80211_assoc_request
*req
)
2158 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
2161 static int ieee80211_deauth(struct wiphy
*wiphy
, struct net_device
*dev
,
2162 struct cfg80211_deauth_request
*req
)
2164 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
2167 static int ieee80211_disassoc(struct wiphy
*wiphy
, struct net_device
*dev
,
2168 struct cfg80211_disassoc_request
*req
)
2170 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
2173 static int ieee80211_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
2174 struct cfg80211_ibss_params
*params
)
2176 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev
), params
);
2179 static int ieee80211_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
2181 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev
));
2184 static int ieee80211_set_mcast_rate(struct wiphy
*wiphy
, struct net_device
*dev
,
2185 int rate
[IEEE80211_NUM_BANDS
])
2187 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2189 memcpy(sdata
->vif
.bss_conf
.mcast_rate
, rate
,
2190 sizeof(int) * IEEE80211_NUM_BANDS
);
2195 static int ieee80211_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
2197 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2200 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
2201 err
= drv_set_frag_threshold(local
, wiphy
->frag_threshold
);
2207 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
) {
2208 err
= drv_set_coverage_class(local
, wiphy
->coverage_class
);
2214 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
2215 err
= drv_set_rts_threshold(local
, wiphy
->rts_threshold
);
2221 if (changed
& WIPHY_PARAM_RETRY_SHORT
) {
2222 if (wiphy
->retry_short
> IEEE80211_MAX_TX_RETRY
)
2224 local
->hw
.conf
.short_frame_max_tx_count
= wiphy
->retry_short
;
2226 if (changed
& WIPHY_PARAM_RETRY_LONG
) {
2227 if (wiphy
->retry_long
> IEEE80211_MAX_TX_RETRY
)
2229 local
->hw
.conf
.long_frame_max_tx_count
= wiphy
->retry_long
;
2232 (WIPHY_PARAM_RETRY_SHORT
| WIPHY_PARAM_RETRY_LONG
))
2233 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_RETRY_LIMITS
);
2238 static int ieee80211_set_tx_power(struct wiphy
*wiphy
,
2239 struct wireless_dev
*wdev
,
2240 enum nl80211_tx_power_setting type
, int mbm
)
2242 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2243 struct ieee80211_sub_if_data
*sdata
;
2246 sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2249 case NL80211_TX_POWER_AUTOMATIC
:
2250 sdata
->user_power_level
= IEEE80211_UNSET_POWER_LEVEL
;
2252 case NL80211_TX_POWER_LIMITED
:
2253 case NL80211_TX_POWER_FIXED
:
2254 if (mbm
< 0 || (mbm
% 100))
2256 sdata
->user_power_level
= MBM_TO_DBM(mbm
);
2260 ieee80211_recalc_txpower(sdata
);
2266 case NL80211_TX_POWER_AUTOMATIC
:
2267 local
->user_power_level
= IEEE80211_UNSET_POWER_LEVEL
;
2269 case NL80211_TX_POWER_LIMITED
:
2270 case NL80211_TX_POWER_FIXED
:
2271 if (mbm
< 0 || (mbm
% 100))
2273 local
->user_power_level
= MBM_TO_DBM(mbm
);
2277 mutex_lock(&local
->iflist_mtx
);
2278 list_for_each_entry(sdata
, &local
->interfaces
, list
)
2279 sdata
->user_power_level
= local
->user_power_level
;
2280 list_for_each_entry(sdata
, &local
->interfaces
, list
)
2281 ieee80211_recalc_txpower(sdata
);
2282 mutex_unlock(&local
->iflist_mtx
);
2287 static int ieee80211_get_tx_power(struct wiphy
*wiphy
,
2288 struct wireless_dev
*wdev
,
2291 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2292 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2294 if (!local
->use_chanctx
)
2295 *dbm
= local
->hw
.conf
.power_level
;
2297 *dbm
= sdata
->vif
.bss_conf
.txpower
;
2302 static int ieee80211_set_wds_peer(struct wiphy
*wiphy
, struct net_device
*dev
,
2305 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2307 memcpy(&sdata
->u
.wds
.remote_addr
, addr
, ETH_ALEN
);
2312 static void ieee80211_rfkill_poll(struct wiphy
*wiphy
)
2314 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2316 drv_rfkill_poll(local
);
2319 #ifdef CONFIG_NL80211_TESTMODE
2320 static int ieee80211_testmode_cmd(struct wiphy
*wiphy
,
2321 struct wireless_dev
*wdev
,
2322 void *data
, int len
)
2324 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2325 struct ieee80211_vif
*vif
= NULL
;
2327 if (!local
->ops
->testmode_cmd
)
2331 struct ieee80211_sub_if_data
*sdata
;
2333 sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2334 if (sdata
->flags
& IEEE80211_SDATA_IN_DRIVER
)
2338 return local
->ops
->testmode_cmd(&local
->hw
, vif
, data
, len
);
2341 static int ieee80211_testmode_dump(struct wiphy
*wiphy
,
2342 struct sk_buff
*skb
,
2343 struct netlink_callback
*cb
,
2344 void *data
, int len
)
2346 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2348 if (!local
->ops
->testmode_dump
)
2351 return local
->ops
->testmode_dump(&local
->hw
, skb
, cb
, data
, len
);
2355 int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data
*sdata
,
2356 enum ieee80211_smps_mode smps_mode
)
2358 struct sta_info
*sta
;
2359 enum ieee80211_smps_mode old_req
;
2362 if (WARN_ON_ONCE(sdata
->vif
.type
!= NL80211_IFTYPE_AP
))
2365 if (sdata
->vif
.bss_conf
.chandef
.width
== NL80211_CHAN_WIDTH_20_NOHT
)
2368 old_req
= sdata
->u
.ap
.req_smps
;
2369 sdata
->u
.ap
.req_smps
= smps_mode
;
2371 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2372 if (old_req
== smps_mode
||
2373 smps_mode
== IEEE80211_SMPS_AUTOMATIC
)
2376 /* If no associated stations, there's no need to do anything */
2377 if (!atomic_read(&sdata
->u
.ap
.num_mcast_sta
)) {
2378 sdata
->smps_mode
= smps_mode
;
2379 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->recalc_smps
);
2384 "SMSP %d requested in AP mode, sending Action frame to %d stations\n",
2385 smps_mode
, atomic_read(&sdata
->u
.ap
.num_mcast_sta
));
2387 mutex_lock(&sdata
->local
->sta_mtx
);
2388 for (i
= 0; i
< STA_HASH_SIZE
; i
++) {
2389 for (sta
= rcu_dereference_protected(sdata
->local
->sta_hash
[i
],
2390 lockdep_is_held(&sdata
->local
->sta_mtx
));
2392 sta
= rcu_dereference_protected(sta
->hnext
,
2393 lockdep_is_held(&sdata
->local
->sta_mtx
))) {
2395 * Only stations associated to our AP and
2398 if (sta
->sdata
->bss
!= &sdata
->u
.ap
)
2401 /* This station doesn't support MIMO - skip it */
2402 if (sta_info_tx_streams(sta
) == 1)
2406 * Don't wake up a STA just to send the action frame
2407 * unless we are getting more restrictive.
2409 if (test_sta_flag(sta
, WLAN_STA_PS_STA
) &&
2410 !ieee80211_smps_is_restrictive(sta
->known_smps_mode
,
2413 "Won't send SMPS to sleeping STA %pM\n",
2419 * If the STA is not authorized, wait until it gets
2420 * authorized and the action frame will be sent then.
2422 if (!test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
2425 ht_dbg(sdata
, "Sending SMPS to %pM\n", sta
->sta
.addr
);
2426 ieee80211_send_smps_action(sdata
, smps_mode
,
2428 sdata
->vif
.bss_conf
.bssid
);
2431 mutex_unlock(&sdata
->local
->sta_mtx
);
2433 sdata
->smps_mode
= smps_mode
;
2434 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->recalc_smps
);
2439 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data
*sdata
,
2440 enum ieee80211_smps_mode smps_mode
)
2443 enum ieee80211_smps_mode old_req
;
2446 lockdep_assert_held(&sdata
->wdev
.mtx
);
2448 if (WARN_ON_ONCE(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
2451 old_req
= sdata
->u
.mgd
.req_smps
;
2452 sdata
->u
.mgd
.req_smps
= smps_mode
;
2454 if (old_req
== smps_mode
&&
2455 smps_mode
!= IEEE80211_SMPS_AUTOMATIC
)
2459 * If not associated, or current association is not an HT
2460 * association, there's no need to do anything, just store
2461 * the new value until we associate.
2463 if (!sdata
->u
.mgd
.associated
||
2464 sdata
->vif
.bss_conf
.chandef
.width
== NL80211_CHAN_WIDTH_20_NOHT
)
2467 ap
= sdata
->u
.mgd
.associated
->bssid
;
2469 if (smps_mode
== IEEE80211_SMPS_AUTOMATIC
) {
2470 if (sdata
->u
.mgd
.powersave
)
2471 smps_mode
= IEEE80211_SMPS_DYNAMIC
;
2473 smps_mode
= IEEE80211_SMPS_OFF
;
2476 /* send SM PS frame to AP */
2477 err
= ieee80211_send_smps_action(sdata
, smps_mode
,
2480 sdata
->u
.mgd
.req_smps
= old_req
;
2485 static int ieee80211_set_power_mgmt(struct wiphy
*wiphy
, struct net_device
*dev
,
2486 bool enabled
, int timeout
)
2488 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2489 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2491 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
2494 if (!(local
->hw
.flags
& IEEE80211_HW_SUPPORTS_PS
))
2497 if (enabled
== sdata
->u
.mgd
.powersave
&&
2498 timeout
== local
->dynamic_ps_forced_timeout
)
2501 sdata
->u
.mgd
.powersave
= enabled
;
2502 local
->dynamic_ps_forced_timeout
= timeout
;
2504 /* no change, but if automatic follow powersave */
2506 __ieee80211_request_smps_mgd(sdata
, sdata
->u
.mgd
.req_smps
);
2507 sdata_unlock(sdata
);
2509 if (local
->hw
.flags
& IEEE80211_HW_SUPPORTS_DYNAMIC_PS
)
2510 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
2512 ieee80211_recalc_ps(local
, -1);
2513 ieee80211_recalc_ps_vif(sdata
);
2518 static int ieee80211_set_cqm_rssi_config(struct wiphy
*wiphy
,
2519 struct net_device
*dev
,
2520 s32 rssi_thold
, u32 rssi_hyst
)
2522 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2523 struct ieee80211_vif
*vif
= &sdata
->vif
;
2524 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
2526 if (rssi_thold
== bss_conf
->cqm_rssi_thold
&&
2527 rssi_hyst
== bss_conf
->cqm_rssi_hyst
)
2530 bss_conf
->cqm_rssi_thold
= rssi_thold
;
2531 bss_conf
->cqm_rssi_hyst
= rssi_hyst
;
2533 /* tell the driver upon association, unless already associated */
2534 if (sdata
->u
.mgd
.associated
&&
2535 sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
)
2536 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_CQM
);
2541 static int ieee80211_set_bitrate_mask(struct wiphy
*wiphy
,
2542 struct net_device
*dev
,
2544 const struct cfg80211_bitrate_mask
*mask
)
2546 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2547 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2550 if (!ieee80211_sdata_running(sdata
))
2553 if (local
->hw
.flags
& IEEE80211_HW_HAS_RATE_CONTROL
) {
2554 ret
= drv_set_bitrate_mask(local
, sdata
, mask
);
2559 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
2560 struct ieee80211_supported_band
*sband
= wiphy
->bands
[i
];
2563 sdata
->rc_rateidx_mask
[i
] = mask
->control
[i
].legacy
;
2564 memcpy(sdata
->rc_rateidx_mcs_mask
[i
], mask
->control
[i
].mcs
,
2565 sizeof(mask
->control
[i
].mcs
));
2567 sdata
->rc_has_mcs_mask
[i
] = false;
2571 for (j
= 0; j
< IEEE80211_HT_MCS_MASK_LEN
; j
++)
2572 if (~sdata
->rc_rateidx_mcs_mask
[i
][j
]) {
2573 sdata
->rc_has_mcs_mask
[i
] = true;
2581 static int ieee80211_start_roc_work(struct ieee80211_local
*local
,
2582 struct ieee80211_sub_if_data
*sdata
,
2583 struct ieee80211_channel
*channel
,
2584 unsigned int duration
, u64
*cookie
,
2585 struct sk_buff
*txskb
,
2586 enum ieee80211_roc_type type
)
2588 struct ieee80211_roc_work
*roc
, *tmp
;
2589 bool queued
= false;
2592 lockdep_assert_held(&local
->mtx
);
2594 if (local
->use_chanctx
&& !local
->ops
->remain_on_channel
)
2597 roc
= kzalloc(sizeof(*roc
), GFP_KERNEL
);
2601 roc
->chan
= channel
;
2602 roc
->duration
= duration
;
2603 roc
->req_duration
= duration
;
2606 roc
->mgmt_tx_cookie
= (unsigned long)txskb
;
2608 INIT_DELAYED_WORK(&roc
->work
, ieee80211_sw_roc_work
);
2609 INIT_LIST_HEAD(&roc
->dependents
);
2611 /* if there's one pending or we're scanning, queue this one */
2612 if (!list_empty(&local
->roc_list
) ||
2613 local
->scanning
|| local
->radar_detect_enabled
)
2614 goto out_check_combine
;
2616 /* if not HW assist, just queue & schedule work */
2617 if (!local
->ops
->remain_on_channel
) {
2618 ieee80211_queue_delayed_work(&local
->hw
, &roc
->work
, 0);
2622 /* otherwise actually kick it off here (for error handling) */
2625 * If the duration is zero, then the driver
2626 * wouldn't actually do anything. Set it to
2629 * TODO: cancel the off-channel operation
2630 * when we get the SKB's TX status and
2631 * the wait time was zero before.
2636 ret
= drv_remain_on_channel(local
, sdata
, channel
, duration
, type
);
2642 roc
->started
= true;
2646 list_for_each_entry(tmp
, &local
->roc_list
, list
) {
2647 if (tmp
->chan
!= channel
|| tmp
->sdata
!= sdata
)
2651 * Extend this ROC if possible:
2653 * If it hasn't started yet, just increase the duration
2654 * and add the new one to the list of dependents.
2655 * If the type of the new ROC has higher priority, modify the
2656 * type of the previous one to match that of the new one.
2658 if (!tmp
->started
) {
2659 list_add_tail(&roc
->list
, &tmp
->dependents
);
2660 tmp
->duration
= max(tmp
->duration
, roc
->duration
);
2661 tmp
->type
= max(tmp
->type
, roc
->type
);
2666 /* If it has already started, it's more difficult ... */
2667 if (local
->ops
->remain_on_channel
) {
2668 unsigned long j
= jiffies
;
2671 * In the offloaded ROC case, if it hasn't begun, add
2672 * this new one to the dependent list to be handled
2673 * when the master one begins. If it has begun,
2674 * check that there's still a minimum time left and
2675 * if so, start this one, transmitting the frame, but
2676 * add it to the list directly after this one with
2677 * a reduced time so we'll ask the driver to execute
2678 * it right after finishing the previous one, in the
2679 * hope that it'll also be executed right afterwards,
2680 * effectively extending the old one.
2681 * If there's no minimum time left, just add it to the
2683 * TODO: the ROC type is ignored here, assuming that it
2684 * is better to immediately use the current ROC.
2686 if (!tmp
->hw_begun
) {
2687 list_add_tail(&roc
->list
, &tmp
->dependents
);
2692 if (time_before(j
+ IEEE80211_ROC_MIN_LEFT
,
2693 tmp
->hw_start_time
+
2694 msecs_to_jiffies(tmp
->duration
))) {
2697 ieee80211_handle_roc_started(roc
);
2699 new_dur
= roc
->duration
-
2700 jiffies_to_msecs(tmp
->hw_start_time
+
2706 /* add right after tmp */
2707 list_add(&roc
->list
, &tmp
->list
);
2709 list_add_tail(&roc
->list
,
2714 } else if (del_timer_sync(&tmp
->work
.timer
)) {
2715 unsigned long new_end
;
2718 * In the software ROC case, cancel the timer, if
2719 * that fails then the finish work is already
2720 * queued/pending and thus we queue the new ROC
2721 * normally, if that succeeds then we can extend
2722 * the timer duration and TX the frame (if any.)
2725 list_add_tail(&roc
->list
, &tmp
->dependents
);
2728 new_end
= jiffies
+ msecs_to_jiffies(roc
->duration
);
2730 /* ok, it was started & we canceled timer */
2731 if (time_after(new_end
, tmp
->work
.timer
.expires
))
2732 mod_timer(&tmp
->work
.timer
, new_end
);
2734 add_timer(&tmp
->work
.timer
);
2736 ieee80211_handle_roc_started(roc
);
2743 list_add_tail(&roc
->list
, &local
->roc_list
);
2746 * cookie is either the roc cookie (for normal roc)
2747 * or the SKB (for mgmt TX)
2750 /* local->mtx protects this */
2751 local
->roc_cookie_counter
++;
2752 roc
->cookie
= local
->roc_cookie_counter
;
2753 /* wow, you wrapped 64 bits ... more likely a bug */
2754 if (WARN_ON(roc
->cookie
== 0)) {
2756 local
->roc_cookie_counter
++;
2758 *cookie
= roc
->cookie
;
2760 *cookie
= (unsigned long)txskb
;
2766 static int ieee80211_remain_on_channel(struct wiphy
*wiphy
,
2767 struct wireless_dev
*wdev
,
2768 struct ieee80211_channel
*chan
,
2769 unsigned int duration
,
2772 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2773 struct ieee80211_local
*local
= sdata
->local
;
2776 mutex_lock(&local
->mtx
);
2777 ret
= ieee80211_start_roc_work(local
, sdata
, chan
,
2778 duration
, cookie
, NULL
,
2779 IEEE80211_ROC_TYPE_NORMAL
);
2780 mutex_unlock(&local
->mtx
);
2785 static int ieee80211_cancel_roc(struct ieee80211_local
*local
,
2786 u64 cookie
, bool mgmt_tx
)
2788 struct ieee80211_roc_work
*roc
, *tmp
, *found
= NULL
;
2791 mutex_lock(&local
->mtx
);
2792 list_for_each_entry_safe(roc
, tmp
, &local
->roc_list
, list
) {
2793 struct ieee80211_roc_work
*dep
, *tmp2
;
2795 list_for_each_entry_safe(dep
, tmp2
, &roc
->dependents
, list
) {
2796 if (!mgmt_tx
&& dep
->cookie
!= cookie
)
2798 else if (mgmt_tx
&& dep
->mgmt_tx_cookie
!= cookie
)
2800 /* found dependent item -- just remove it */
2801 list_del(&dep
->list
);
2802 mutex_unlock(&local
->mtx
);
2804 ieee80211_roc_notify_destroy(dep
, true);
2808 if (!mgmt_tx
&& roc
->cookie
!= cookie
)
2810 else if (mgmt_tx
&& roc
->mgmt_tx_cookie
!= cookie
)
2818 mutex_unlock(&local
->mtx
);
2823 * We found the item to cancel, so do that. Note that it
2824 * may have dependents, which we also cancel (and send
2825 * the expired signal for.) Not doing so would be quite
2826 * tricky here, but we may need to fix it later.
2829 if (local
->ops
->remain_on_channel
) {
2830 if (found
->started
) {
2831 ret
= drv_cancel_remain_on_channel(local
);
2832 if (WARN_ON_ONCE(ret
)) {
2833 mutex_unlock(&local
->mtx
);
2838 list_del(&found
->list
);
2841 ieee80211_start_next_roc(local
);
2842 mutex_unlock(&local
->mtx
);
2844 ieee80211_roc_notify_destroy(found
, true);
2846 /* work may be pending so use it all the time */
2847 found
->abort
= true;
2848 ieee80211_queue_delayed_work(&local
->hw
, &found
->work
, 0);
2850 mutex_unlock(&local
->mtx
);
2852 /* work will clean up etc */
2853 flush_delayed_work(&found
->work
);
2854 WARN_ON(!found
->to_be_freed
);
2861 static int ieee80211_cancel_remain_on_channel(struct wiphy
*wiphy
,
2862 struct wireless_dev
*wdev
,
2865 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2866 struct ieee80211_local
*local
= sdata
->local
;
2868 return ieee80211_cancel_roc(local
, cookie
, false);
2871 static int ieee80211_start_radar_detection(struct wiphy
*wiphy
,
2872 struct net_device
*dev
,
2873 struct cfg80211_chan_def
*chandef
)
2875 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2876 struct ieee80211_local
*local
= sdata
->local
;
2877 unsigned long timeout
;
2880 if (!list_empty(&local
->roc_list
) || local
->scanning
)
2883 /* whatever, but channel contexts should not complain about that one */
2884 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
2885 sdata
->needed_rx_chains
= local
->rx_chains
;
2886 sdata
->radar_required
= true;
2888 mutex_lock(&local
->iflist_mtx
);
2889 err
= ieee80211_vif_use_channel(sdata
, chandef
,
2890 IEEE80211_CHANCTX_SHARED
);
2891 mutex_unlock(&local
->iflist_mtx
);
2895 timeout
= msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS
);
2896 ieee80211_queue_delayed_work(&sdata
->local
->hw
,
2897 &sdata
->dfs_cac_timer_work
, timeout
);
2902 static struct cfg80211_beacon_data
*
2903 cfg80211_beacon_dup(struct cfg80211_beacon_data
*beacon
)
2905 struct cfg80211_beacon_data
*new_beacon
;
2909 len
= beacon
->head_len
+ beacon
->tail_len
+ beacon
->beacon_ies_len
+
2910 beacon
->proberesp_ies_len
+ beacon
->assocresp_ies_len
+
2911 beacon
->probe_resp_len
;
2913 new_beacon
= kzalloc(sizeof(*new_beacon
) + len
, GFP_KERNEL
);
2917 pos
= (u8
*)(new_beacon
+ 1);
2918 if (beacon
->head_len
) {
2919 new_beacon
->head_len
= beacon
->head_len
;
2920 new_beacon
->head
= pos
;
2921 memcpy(pos
, beacon
->head
, beacon
->head_len
);
2922 pos
+= beacon
->head_len
;
2924 if (beacon
->tail_len
) {
2925 new_beacon
->tail_len
= beacon
->tail_len
;
2926 new_beacon
->tail
= pos
;
2927 memcpy(pos
, beacon
->tail
, beacon
->tail_len
);
2928 pos
+= beacon
->tail_len
;
2930 if (beacon
->beacon_ies_len
) {
2931 new_beacon
->beacon_ies_len
= beacon
->beacon_ies_len
;
2932 new_beacon
->beacon_ies
= pos
;
2933 memcpy(pos
, beacon
->beacon_ies
, beacon
->beacon_ies_len
);
2934 pos
+= beacon
->beacon_ies_len
;
2936 if (beacon
->proberesp_ies_len
) {
2937 new_beacon
->proberesp_ies_len
= beacon
->proberesp_ies_len
;
2938 new_beacon
->proberesp_ies
= pos
;
2939 memcpy(pos
, beacon
->proberesp_ies
, beacon
->proberesp_ies_len
);
2940 pos
+= beacon
->proberesp_ies_len
;
2942 if (beacon
->assocresp_ies_len
) {
2943 new_beacon
->assocresp_ies_len
= beacon
->assocresp_ies_len
;
2944 new_beacon
->assocresp_ies
= pos
;
2945 memcpy(pos
, beacon
->assocresp_ies
, beacon
->assocresp_ies_len
);
2946 pos
+= beacon
->assocresp_ies_len
;
2948 if (beacon
->probe_resp_len
) {
2949 new_beacon
->probe_resp_len
= beacon
->probe_resp_len
;
2950 beacon
->probe_resp
= pos
;
2951 memcpy(pos
, beacon
->probe_resp
, beacon
->probe_resp_len
);
2952 pos
+= beacon
->probe_resp_len
;
2958 void ieee80211_csa_finalize_work(struct work_struct
*work
)
2960 struct ieee80211_sub_if_data
*sdata
=
2961 container_of(work
, struct ieee80211_sub_if_data
,
2963 struct ieee80211_local
*local
= sdata
->local
;
2964 int err
, changed
= 0;
2966 if (!ieee80211_sdata_running(sdata
))
2969 sdata
->radar_required
= sdata
->csa_radar_required
;
2970 err
= ieee80211_vif_change_channel(sdata
, &local
->csa_chandef
,
2972 if (WARN_ON(err
< 0))
2975 if (!local
->use_chanctx
) {
2976 local
->_oper_chandef
= local
->csa_chandef
;
2977 ieee80211_hw_config(local
, 0);
2980 ieee80211_bss_info_change_notify(sdata
, changed
);
2982 switch (sdata
->vif
.type
) {
2983 case NL80211_IFTYPE_AP
:
2984 err
= ieee80211_assign_beacon(sdata
, sdata
->u
.ap
.next_beacon
);
2988 kfree(sdata
->u
.ap
.next_beacon
);
2989 sdata
->u
.ap
.next_beacon
= NULL
;
2991 ieee80211_bss_info_change_notify(sdata
, err
);
2993 case NL80211_IFTYPE_ADHOC
:
2994 ieee80211_ibss_finish_csa(sdata
);
2996 #ifdef CONFIG_MAC80211_MESH
2997 case NL80211_IFTYPE_MESH_POINT
:
2998 err
= ieee80211_mesh_finish_csa(sdata
);
3007 sdata
->vif
.csa_active
= false;
3009 ieee80211_wake_queues_by_reason(&sdata
->local
->hw
,
3010 IEEE80211_MAX_QUEUE_MAP
,
3011 IEEE80211_QUEUE_STOP_REASON_CSA
);
3013 cfg80211_ch_switch_notify(sdata
->dev
, &local
->csa_chandef
);
3016 static int ieee80211_channel_switch(struct wiphy
*wiphy
, struct net_device
*dev
,
3017 struct cfg80211_csa_settings
*params
)
3019 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3020 struct ieee80211_local
*local
= sdata
->local
;
3021 struct ieee80211_chanctx_conf
*chanctx_conf
;
3022 struct ieee80211_chanctx
*chanctx
;
3023 struct ieee80211_if_mesh __maybe_unused
*ifmsh
;
3024 int err
, num_chanctx
;
3026 if (!list_empty(&local
->roc_list
) || local
->scanning
)
3029 if (sdata
->wdev
.cac_started
)
3032 if (cfg80211_chandef_identical(¶ms
->chandef
,
3033 &sdata
->vif
.bss_conf
.chandef
))
3037 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
3038 if (!chanctx_conf
) {
3043 /* don't handle for multi-VIF cases */
3044 chanctx
= container_of(chanctx_conf
, struct ieee80211_chanctx
, conf
);
3045 if (chanctx
->refcount
> 1) {
3050 list_for_each_entry_rcu(chanctx
, &local
->chanctx_list
, list
)
3054 if (num_chanctx
> 1)
3057 /* don't allow another channel switch if one is already active. */
3058 if (sdata
->vif
.csa_active
)
3061 switch (sdata
->vif
.type
) {
3062 case NL80211_IFTYPE_AP
:
3063 sdata
->csa_counter_offset_beacon
=
3064 params
->counter_offset_beacon
;
3065 sdata
->csa_counter_offset_presp
= params
->counter_offset_presp
;
3066 sdata
->u
.ap
.next_beacon
=
3067 cfg80211_beacon_dup(¶ms
->beacon_after
);
3068 if (!sdata
->u
.ap
.next_beacon
)
3071 err
= ieee80211_assign_beacon(sdata
, ¶ms
->beacon_csa
);
3073 kfree(sdata
->u
.ap
.next_beacon
);
3077 case NL80211_IFTYPE_ADHOC
:
3078 if (!sdata
->vif
.bss_conf
.ibss_joined
)
3081 if (params
->chandef
.width
!= sdata
->u
.ibss
.chandef
.width
)
3084 switch (params
->chandef
.width
) {
3085 case NL80211_CHAN_WIDTH_40
:
3086 if (cfg80211_get_chandef_type(¶ms
->chandef
) !=
3087 cfg80211_get_chandef_type(&sdata
->u
.ibss
.chandef
))
3089 case NL80211_CHAN_WIDTH_5
:
3090 case NL80211_CHAN_WIDTH_10
:
3091 case NL80211_CHAN_WIDTH_20_NOHT
:
3092 case NL80211_CHAN_WIDTH_20
:
3098 /* changes into another band are not supported */
3099 if (sdata
->u
.ibss
.chandef
.chan
->band
!=
3100 params
->chandef
.chan
->band
)
3103 err
= ieee80211_ibss_csa_beacon(sdata
, params
);
3107 #ifdef CONFIG_MAC80211_MESH
3108 case NL80211_IFTYPE_MESH_POINT
:
3109 ifmsh
= &sdata
->u
.mesh
;
3111 if (!ifmsh
->mesh_id
)
3114 if (params
->chandef
.width
!= sdata
->vif
.bss_conf
.chandef
.width
)
3117 /* changes into another band are not supported */
3118 if (sdata
->vif
.bss_conf
.chandef
.chan
->band
!=
3119 params
->chandef
.chan
->band
)
3122 ifmsh
->chsw_init
= true;
3123 if (!ifmsh
->pre_value
)
3124 ifmsh
->pre_value
= 1;
3128 err
= ieee80211_mesh_csa_beacon(sdata
, params
, true);
3130 ifmsh
->chsw_init
= false;
3139 sdata
->csa_radar_required
= params
->radar_required
;
3141 if (params
->block_tx
)
3142 ieee80211_stop_queues_by_reason(&local
->hw
,
3143 IEEE80211_MAX_QUEUE_MAP
,
3144 IEEE80211_QUEUE_STOP_REASON_CSA
);
3146 local
->csa_chandef
= params
->chandef
;
3147 sdata
->vif
.csa_active
= true;
3149 ieee80211_bss_info_change_notify(sdata
, err
);
3150 drv_channel_switch_beacon(sdata
, ¶ms
->chandef
);
3155 static int ieee80211_mgmt_tx(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
3156 struct ieee80211_channel
*chan
, bool offchan
,
3157 unsigned int wait
, const u8
*buf
, size_t len
,
3158 bool no_cck
, bool dont_wait_for_ack
, u64
*cookie
)
3160 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
3161 struct ieee80211_local
*local
= sdata
->local
;
3162 struct sk_buff
*skb
;
3163 struct sta_info
*sta
;
3164 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
3165 bool need_offchan
= false;
3169 if (dont_wait_for_ack
)
3170 flags
= IEEE80211_TX_CTL_NO_ACK
;
3172 flags
= IEEE80211_TX_INTFL_NL80211_FRAME_TX
|
3173 IEEE80211_TX_CTL_REQ_TX_STATUS
;
3176 flags
|= IEEE80211_TX_CTL_NO_CCK_RATE
;
3178 switch (sdata
->vif
.type
) {
3179 case NL80211_IFTYPE_ADHOC
:
3180 if (!sdata
->vif
.bss_conf
.ibss_joined
)
3181 need_offchan
= true;
3183 #ifdef CONFIG_MAC80211_MESH
3184 case NL80211_IFTYPE_MESH_POINT
:
3185 if (ieee80211_vif_is_mesh(&sdata
->vif
) &&
3186 !sdata
->u
.mesh
.mesh_id_len
)
3187 need_offchan
= true;
3190 case NL80211_IFTYPE_AP
:
3191 case NL80211_IFTYPE_AP_VLAN
:
3192 case NL80211_IFTYPE_P2P_GO
:
3193 if (sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
&&
3194 !ieee80211_vif_is_mesh(&sdata
->vif
) &&
3195 !rcu_access_pointer(sdata
->bss
->beacon
))
3196 need_offchan
= true;
3197 if (!ieee80211_is_action(mgmt
->frame_control
) ||
3198 mgmt
->u
.action
.category
== WLAN_CATEGORY_PUBLIC
||
3199 mgmt
->u
.action
.category
== WLAN_CATEGORY_SELF_PROTECTED
||
3200 mgmt
->u
.action
.category
== WLAN_CATEGORY_SPECTRUM_MGMT
)
3203 sta
= sta_info_get(sdata
, mgmt
->da
);
3208 case NL80211_IFTYPE_STATION
:
3209 case NL80211_IFTYPE_P2P_CLIENT
:
3210 if (!sdata
->u
.mgd
.associated
)
3211 need_offchan
= true;
3213 case NL80211_IFTYPE_P2P_DEVICE
:
3214 need_offchan
= true;
3220 /* configurations requiring offchan cannot work if no channel has been
3223 if (need_offchan
&& !chan
)
3226 mutex_lock(&local
->mtx
);
3228 /* Check if the operating channel is the requested channel */
3229 if (!need_offchan
) {
3230 struct ieee80211_chanctx_conf
*chanctx_conf
;
3233 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
3236 need_offchan
= chan
&& (chan
!= chanctx_conf
->def
.chan
);
3242 need_offchan
= true;
3247 if (need_offchan
&& !offchan
) {
3252 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ len
);
3257 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3259 memcpy(skb_put(skb
, len
), buf
, len
);
3261 IEEE80211_SKB_CB(skb
)->flags
= flags
;
3263 skb
->dev
= sdata
->dev
;
3265 if (!need_offchan
) {
3266 *cookie
= (unsigned long) skb
;
3267 ieee80211_tx_skb(sdata
, skb
);
3272 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_TX_OFFCHAN
|
3273 IEEE80211_TX_INTFL_OFFCHAN_TX_OK
;
3274 if (local
->hw
.flags
& IEEE80211_HW_QUEUE_CONTROL
)
3275 IEEE80211_SKB_CB(skb
)->hw_queue
=
3276 local
->hw
.offchannel_tx_hw_queue
;
3278 /* This will handle all kinds of coalescing and immediate TX */
3279 ret
= ieee80211_start_roc_work(local
, sdata
, chan
,
3281 IEEE80211_ROC_TYPE_MGMT_TX
);
3285 mutex_unlock(&local
->mtx
);
3289 static int ieee80211_mgmt_tx_cancel_wait(struct wiphy
*wiphy
,
3290 struct wireless_dev
*wdev
,
3293 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3295 return ieee80211_cancel_roc(local
, cookie
, true);
3298 static void ieee80211_mgmt_frame_register(struct wiphy
*wiphy
,
3299 struct wireless_dev
*wdev
,
3300 u16 frame_type
, bool reg
)
3302 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3304 switch (frame_type
) {
3305 case IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_PROBE_REQ
:
3307 local
->probe_req_reg
++;
3309 local
->probe_req_reg
--;
3311 if (!local
->open_count
)
3314 ieee80211_queue_work(&local
->hw
, &local
->reconfig_filter
);
3321 static int ieee80211_set_antenna(struct wiphy
*wiphy
, u32 tx_ant
, u32 rx_ant
)
3323 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3328 return drv_set_antenna(local
, tx_ant
, rx_ant
);
3331 static int ieee80211_get_antenna(struct wiphy
*wiphy
, u32
*tx_ant
, u32
*rx_ant
)
3333 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3335 return drv_get_antenna(local
, tx_ant
, rx_ant
);
3338 static int ieee80211_set_ringparam(struct wiphy
*wiphy
, u32 tx
, u32 rx
)
3340 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3342 return drv_set_ringparam(local
, tx
, rx
);
3345 static void ieee80211_get_ringparam(struct wiphy
*wiphy
,
3346 u32
*tx
, u32
*tx_max
, u32
*rx
, u32
*rx_max
)
3348 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3350 drv_get_ringparam(local
, tx
, tx_max
, rx
, rx_max
);
3353 static int ieee80211_set_rekey_data(struct wiphy
*wiphy
,
3354 struct net_device
*dev
,
3355 struct cfg80211_gtk_rekey_data
*data
)
3357 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3358 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3360 if (!local
->ops
->set_rekey_data
)
3363 drv_set_rekey_data(local
, sdata
, data
);
3368 static void ieee80211_tdls_add_ext_capab(struct sk_buff
*skb
)
3370 u8
*pos
= (void *)skb_put(skb
, 7);
3372 *pos
++ = WLAN_EID_EXT_CAPABILITY
;
3373 *pos
++ = 5; /* len */
3378 *pos
++ = WLAN_EXT_CAPA5_TDLS_ENABLED
;
3381 static u16
ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data
*sdata
)
3383 struct ieee80211_local
*local
= sdata
->local
;
3387 if (ieee80211_get_sdata_band(sdata
) != IEEE80211_BAND_2GHZ
)
3390 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
))
3391 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
3392 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
))
3393 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
3398 static void ieee80211_tdls_add_link_ie(struct sk_buff
*skb
, u8
*src_addr
,
3399 u8
*peer
, u8
*bssid
)
3401 struct ieee80211_tdls_lnkie
*lnkid
;
3403 lnkid
= (void *)skb_put(skb
, sizeof(struct ieee80211_tdls_lnkie
));
3405 lnkid
->ie_type
= WLAN_EID_LINK_ID
;
3406 lnkid
->ie_len
= sizeof(struct ieee80211_tdls_lnkie
) - 2;
3408 memcpy(lnkid
->bssid
, bssid
, ETH_ALEN
);
3409 memcpy(lnkid
->init_sta
, src_addr
, ETH_ALEN
);
3410 memcpy(lnkid
->resp_sta
, peer
, ETH_ALEN
);
3414 ieee80211_prep_tdls_encap_data(struct wiphy
*wiphy
, struct net_device
*dev
,
3415 u8
*peer
, u8 action_code
, u8 dialog_token
,
3416 u16 status_code
, struct sk_buff
*skb
)
3418 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3419 enum ieee80211_band band
= ieee80211_get_sdata_band(sdata
);
3420 struct ieee80211_tdls_data
*tf
;
3422 tf
= (void *)skb_put(skb
, offsetof(struct ieee80211_tdls_data
, u
));
3424 memcpy(tf
->da
, peer
, ETH_ALEN
);
3425 memcpy(tf
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
3426 tf
->ether_type
= cpu_to_be16(ETH_P_TDLS
);
3427 tf
->payload_type
= WLAN_TDLS_SNAP_RFTYPE
;
3429 switch (action_code
) {
3430 case WLAN_TDLS_SETUP_REQUEST
:
3431 tf
->category
= WLAN_CATEGORY_TDLS
;
3432 tf
->action_code
= WLAN_TDLS_SETUP_REQUEST
;
3434 skb_put(skb
, sizeof(tf
->u
.setup_req
));
3435 tf
->u
.setup_req
.dialog_token
= dialog_token
;
3436 tf
->u
.setup_req
.capability
=
3437 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata
));
3439 ieee80211_add_srates_ie(sdata
, skb
, false, band
);
3440 ieee80211_add_ext_srates_ie(sdata
, skb
, false, band
);
3441 ieee80211_tdls_add_ext_capab(skb
);
3443 case WLAN_TDLS_SETUP_RESPONSE
:
3444 tf
->category
= WLAN_CATEGORY_TDLS
;
3445 tf
->action_code
= WLAN_TDLS_SETUP_RESPONSE
;
3447 skb_put(skb
, sizeof(tf
->u
.setup_resp
));
3448 tf
->u
.setup_resp
.status_code
= cpu_to_le16(status_code
);
3449 tf
->u
.setup_resp
.dialog_token
= dialog_token
;
3450 tf
->u
.setup_resp
.capability
=
3451 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata
));
3453 ieee80211_add_srates_ie(sdata
, skb
, false, band
);
3454 ieee80211_add_ext_srates_ie(sdata
, skb
, false, band
);
3455 ieee80211_tdls_add_ext_capab(skb
);
3457 case WLAN_TDLS_SETUP_CONFIRM
:
3458 tf
->category
= WLAN_CATEGORY_TDLS
;
3459 tf
->action_code
= WLAN_TDLS_SETUP_CONFIRM
;
3461 skb_put(skb
, sizeof(tf
->u
.setup_cfm
));
3462 tf
->u
.setup_cfm
.status_code
= cpu_to_le16(status_code
);
3463 tf
->u
.setup_cfm
.dialog_token
= dialog_token
;
3465 case WLAN_TDLS_TEARDOWN
:
3466 tf
->category
= WLAN_CATEGORY_TDLS
;
3467 tf
->action_code
= WLAN_TDLS_TEARDOWN
;
3469 skb_put(skb
, sizeof(tf
->u
.teardown
));
3470 tf
->u
.teardown
.reason_code
= cpu_to_le16(status_code
);
3472 case WLAN_TDLS_DISCOVERY_REQUEST
:
3473 tf
->category
= WLAN_CATEGORY_TDLS
;
3474 tf
->action_code
= WLAN_TDLS_DISCOVERY_REQUEST
;
3476 skb_put(skb
, sizeof(tf
->u
.discover_req
));
3477 tf
->u
.discover_req
.dialog_token
= dialog_token
;
3487 ieee80211_prep_tdls_direct(struct wiphy
*wiphy
, struct net_device
*dev
,
3488 u8
*peer
, u8 action_code
, u8 dialog_token
,
3489 u16 status_code
, struct sk_buff
*skb
)
3491 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3492 enum ieee80211_band band
= ieee80211_get_sdata_band(sdata
);
3493 struct ieee80211_mgmt
*mgmt
;
3495 mgmt
= (void *)skb_put(skb
, 24);
3496 memset(mgmt
, 0, 24);
3497 memcpy(mgmt
->da
, peer
, ETH_ALEN
);
3498 memcpy(mgmt
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
3499 memcpy(mgmt
->bssid
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
3501 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
3502 IEEE80211_STYPE_ACTION
);
3504 switch (action_code
) {
3505 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
3506 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.tdls_discover_resp
));
3507 mgmt
->u
.action
.category
= WLAN_CATEGORY_PUBLIC
;
3508 mgmt
->u
.action
.u
.tdls_discover_resp
.action_code
=
3509 WLAN_PUB_ACTION_TDLS_DISCOVER_RES
;
3510 mgmt
->u
.action
.u
.tdls_discover_resp
.dialog_token
=
3512 mgmt
->u
.action
.u
.tdls_discover_resp
.capability
=
3513 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata
));
3515 ieee80211_add_srates_ie(sdata
, skb
, false, band
);
3516 ieee80211_add_ext_srates_ie(sdata
, skb
, false, band
);
3517 ieee80211_tdls_add_ext_capab(skb
);
3526 static int ieee80211_tdls_mgmt(struct wiphy
*wiphy
, struct net_device
*dev
,
3527 u8
*peer
, u8 action_code
, u8 dialog_token
,
3528 u16 status_code
, const u8
*extra_ies
,
3529 size_t extra_ies_len
)
3531 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3532 struct ieee80211_local
*local
= sdata
->local
;
3533 struct sk_buff
*skb
= NULL
;
3537 if (!(wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3540 /* make sure we are in managed mode, and associated */
3541 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
||
3542 !sdata
->u
.mgd
.associated
)
3545 tdls_dbg(sdata
, "TDLS mgmt action %d peer %pM\n",
3548 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
3549 max(sizeof(struct ieee80211_mgmt
),
3550 sizeof(struct ieee80211_tdls_data
)) +
3551 50 + /* supported rates */
3554 sizeof(struct ieee80211_tdls_lnkie
));
3558 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3560 switch (action_code
) {
3561 case WLAN_TDLS_SETUP_REQUEST
:
3562 case WLAN_TDLS_SETUP_RESPONSE
:
3563 case WLAN_TDLS_SETUP_CONFIRM
:
3564 case WLAN_TDLS_TEARDOWN
:
3565 case WLAN_TDLS_DISCOVERY_REQUEST
:
3566 ret
= ieee80211_prep_tdls_encap_data(wiphy
, dev
, peer
,
3567 action_code
, dialog_token
,
3569 send_direct
= false;
3571 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
3572 ret
= ieee80211_prep_tdls_direct(wiphy
, dev
, peer
, action_code
,
3573 dialog_token
, status_code
,
3586 memcpy(skb_put(skb
, extra_ies_len
), extra_ies
, extra_ies_len
);
3588 /* the TDLS link IE is always added last */
3589 switch (action_code
) {
3590 case WLAN_TDLS_SETUP_REQUEST
:
3591 case WLAN_TDLS_SETUP_CONFIRM
:
3592 case WLAN_TDLS_TEARDOWN
:
3593 case WLAN_TDLS_DISCOVERY_REQUEST
:
3594 /* we are the initiator */
3595 ieee80211_tdls_add_link_ie(skb
, sdata
->vif
.addr
, peer
,
3596 sdata
->u
.mgd
.bssid
);
3598 case WLAN_TDLS_SETUP_RESPONSE
:
3599 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
3600 /* we are the responder */
3601 ieee80211_tdls_add_link_ie(skb
, peer
, sdata
->vif
.addr
,
3602 sdata
->u
.mgd
.bssid
);
3610 ieee80211_tx_skb(sdata
, skb
);
3615 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3616 * we should default to AC_VI.
3618 switch (action_code
) {
3619 case WLAN_TDLS_SETUP_REQUEST
:
3620 case WLAN_TDLS_SETUP_RESPONSE
:
3621 skb_set_queue_mapping(skb
, IEEE80211_AC_BK
);
3625 skb_set_queue_mapping(skb
, IEEE80211_AC_VI
);
3630 /* disable bottom halves when entering the Tx path */
3632 ret
= ieee80211_subif_start_xmit(skb
, dev
);
3642 static int ieee80211_tdls_oper(struct wiphy
*wiphy
, struct net_device
*dev
,
3643 u8
*peer
, enum nl80211_tdls_operation oper
)
3645 struct sta_info
*sta
;
3646 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3648 if (!(wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3651 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3654 tdls_dbg(sdata
, "TDLS oper %d peer %pM\n", oper
, peer
);
3657 case NL80211_TDLS_ENABLE_LINK
:
3659 sta
= sta_info_get(sdata
, peer
);
3665 set_sta_flag(sta
, WLAN_STA_TDLS_PEER_AUTH
);
3668 case NL80211_TDLS_DISABLE_LINK
:
3669 return sta_info_destroy_addr(sdata
, peer
);
3670 case NL80211_TDLS_TEARDOWN
:
3671 case NL80211_TDLS_SETUP
:
3672 case NL80211_TDLS_DISCOVERY_REQ
:
3673 /* We don't support in-driver setup/teardown/discovery */
3682 static int ieee80211_probe_client(struct wiphy
*wiphy
, struct net_device
*dev
,
3683 const u8
*peer
, u64
*cookie
)
3685 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3686 struct ieee80211_local
*local
= sdata
->local
;
3687 struct ieee80211_qos_hdr
*nullfunc
;
3688 struct sk_buff
*skb
;
3689 int size
= sizeof(*nullfunc
);
3692 struct ieee80211_tx_info
*info
;
3693 struct sta_info
*sta
;
3694 struct ieee80211_chanctx_conf
*chanctx_conf
;
3695 enum ieee80211_band band
;
3698 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
3699 if (WARN_ON(!chanctx_conf
)) {
3703 band
= chanctx_conf
->def
.chan
->band
;
3704 sta
= sta_info_get_bss(sdata
, peer
);
3706 qos
= test_sta_flag(sta
, WLAN_STA_WME
);
3713 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
3714 IEEE80211_STYPE_QOS_NULLFUNC
|
3715 IEEE80211_FCTL_FROMDS
);
3718 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
3719 IEEE80211_STYPE_NULLFUNC
|
3720 IEEE80211_FCTL_FROMDS
);
3723 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ size
);
3731 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3733 nullfunc
= (void *) skb_put(skb
, size
);
3734 nullfunc
->frame_control
= fc
;
3735 nullfunc
->duration_id
= 0;
3736 memcpy(nullfunc
->addr1
, sta
->sta
.addr
, ETH_ALEN
);
3737 memcpy(nullfunc
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
3738 memcpy(nullfunc
->addr3
, sdata
->vif
.addr
, ETH_ALEN
);
3739 nullfunc
->seq_ctrl
= 0;
3741 info
= IEEE80211_SKB_CB(skb
);
3743 info
->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
|
3744 IEEE80211_TX_INTFL_NL80211_FRAME_TX
;
3746 skb_set_queue_mapping(skb
, IEEE80211_AC_VO
);
3749 nullfunc
->qos_ctrl
= cpu_to_le16(7);
3752 ieee80211_xmit(sdata
, skb
, band
);
3756 *cookie
= (unsigned long) skb
;
3760 static int ieee80211_cfg_get_channel(struct wiphy
*wiphy
,
3761 struct wireless_dev
*wdev
,
3762 struct cfg80211_chan_def
*chandef
)
3764 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
3765 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3766 struct ieee80211_chanctx_conf
*chanctx_conf
;
3770 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
3772 *chandef
= chanctx_conf
->def
;
3774 } else if (local
->open_count
> 0 &&
3775 local
->open_count
== local
->monitors
&&
3776 sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
) {
3777 if (local
->use_chanctx
)
3778 *chandef
= local
->monitor_chandef
;
3780 *chandef
= local
->_oper_chandef
;
3789 static void ieee80211_set_wakeup(struct wiphy
*wiphy
, bool enabled
)
3791 drv_set_wakeup(wiphy_priv(wiphy
), enabled
);
3795 struct cfg80211_ops mac80211_config_ops
= {
3796 .add_virtual_intf
= ieee80211_add_iface
,
3797 .del_virtual_intf
= ieee80211_del_iface
,
3798 .change_virtual_intf
= ieee80211_change_iface
,
3799 .start_p2p_device
= ieee80211_start_p2p_device
,
3800 .stop_p2p_device
= ieee80211_stop_p2p_device
,
3801 .add_key
= ieee80211_add_key
,
3802 .del_key
= ieee80211_del_key
,
3803 .get_key
= ieee80211_get_key
,
3804 .set_default_key
= ieee80211_config_default_key
,
3805 .set_default_mgmt_key
= ieee80211_config_default_mgmt_key
,
3806 .start_ap
= ieee80211_start_ap
,
3807 .change_beacon
= ieee80211_change_beacon
,
3808 .stop_ap
= ieee80211_stop_ap
,
3809 .add_station
= ieee80211_add_station
,
3810 .del_station
= ieee80211_del_station
,
3811 .change_station
= ieee80211_change_station
,
3812 .get_station
= ieee80211_get_station
,
3813 .dump_station
= ieee80211_dump_station
,
3814 .dump_survey
= ieee80211_dump_survey
,
3815 #ifdef CONFIG_MAC80211_MESH
3816 .add_mpath
= ieee80211_add_mpath
,
3817 .del_mpath
= ieee80211_del_mpath
,
3818 .change_mpath
= ieee80211_change_mpath
,
3819 .get_mpath
= ieee80211_get_mpath
,
3820 .dump_mpath
= ieee80211_dump_mpath
,
3821 .update_mesh_config
= ieee80211_update_mesh_config
,
3822 .get_mesh_config
= ieee80211_get_mesh_config
,
3823 .join_mesh
= ieee80211_join_mesh
,
3824 .leave_mesh
= ieee80211_leave_mesh
,
3826 .change_bss
= ieee80211_change_bss
,
3827 .set_txq_params
= ieee80211_set_txq_params
,
3828 .set_monitor_channel
= ieee80211_set_monitor_channel
,
3829 .suspend
= ieee80211_suspend
,
3830 .resume
= ieee80211_resume
,
3831 .scan
= ieee80211_scan
,
3832 .sched_scan_start
= ieee80211_sched_scan_start
,
3833 .sched_scan_stop
= ieee80211_sched_scan_stop
,
3834 .auth
= ieee80211_auth
,
3835 .assoc
= ieee80211_assoc
,
3836 .deauth
= ieee80211_deauth
,
3837 .disassoc
= ieee80211_disassoc
,
3838 .join_ibss
= ieee80211_join_ibss
,
3839 .leave_ibss
= ieee80211_leave_ibss
,
3840 .set_mcast_rate
= ieee80211_set_mcast_rate
,
3841 .set_wiphy_params
= ieee80211_set_wiphy_params
,
3842 .set_tx_power
= ieee80211_set_tx_power
,
3843 .get_tx_power
= ieee80211_get_tx_power
,
3844 .set_wds_peer
= ieee80211_set_wds_peer
,
3845 .rfkill_poll
= ieee80211_rfkill_poll
,
3846 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd
)
3847 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump
)
3848 .set_power_mgmt
= ieee80211_set_power_mgmt
,
3849 .set_bitrate_mask
= ieee80211_set_bitrate_mask
,
3850 .remain_on_channel
= ieee80211_remain_on_channel
,
3851 .cancel_remain_on_channel
= ieee80211_cancel_remain_on_channel
,
3852 .mgmt_tx
= ieee80211_mgmt_tx
,
3853 .mgmt_tx_cancel_wait
= ieee80211_mgmt_tx_cancel_wait
,
3854 .set_cqm_rssi_config
= ieee80211_set_cqm_rssi_config
,
3855 .mgmt_frame_register
= ieee80211_mgmt_frame_register
,
3856 .set_antenna
= ieee80211_set_antenna
,
3857 .get_antenna
= ieee80211_get_antenna
,
3858 .set_ringparam
= ieee80211_set_ringparam
,
3859 .get_ringparam
= ieee80211_get_ringparam
,
3860 .set_rekey_data
= ieee80211_set_rekey_data
,
3861 .tdls_oper
= ieee80211_tdls_oper
,
3862 .tdls_mgmt
= ieee80211_tdls_mgmt
,
3863 .probe_client
= ieee80211_probe_client
,
3864 .set_noack_map
= ieee80211_set_noack_map
,
3866 .set_wakeup
= ieee80211_set_wakeup
,
3868 .get_et_sset_count
= ieee80211_get_et_sset_count
,
3869 .get_et_stats
= ieee80211_get_et_stats
,
3870 .get_et_strings
= ieee80211_get_et_strings
,
3871 .get_channel
= ieee80211_cfg_get_channel
,
3872 .start_radar_detection
= ieee80211_start_radar_detection
,
3873 .channel_switch
= ieee80211_channel_switch
,