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
)) {
77 * Prohibit MONITOR_FLAG_COOK_FRAMES to be
78 * changed while the interface is up.
79 * Else we would need to add a lot of cruft
80 * to update everything:
81 * cooked_mntrs, monitor and all fif_* counters
82 * reconfigure hardware
84 if ((*flags
& MONITOR_FLAG_COOK_FRAMES
) !=
85 (sdata
->u
.mntr_flags
& MONITOR_FLAG_COOK_FRAMES
))
88 ieee80211_adjust_monitor_flags(sdata
, -1);
89 sdata
->u
.mntr_flags
= *flags
;
90 ieee80211_adjust_monitor_flags(sdata
, 1);
92 ieee80211_configure_filter(local
);
95 * Because the interface is down, ieee80211_do_stop
96 * and ieee80211_do_open take care of "everything"
97 * mentioned in the comment above.
99 sdata
->u
.mntr_flags
= *flags
;
106 static int ieee80211_start_p2p_device(struct wiphy
*wiphy
,
107 struct wireless_dev
*wdev
)
109 return ieee80211_do_open(wdev
, true);
112 static void ieee80211_stop_p2p_device(struct wiphy
*wiphy
,
113 struct wireless_dev
*wdev
)
115 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev
));
118 static int ieee80211_set_noack_map(struct wiphy
*wiphy
,
119 struct net_device
*dev
,
122 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
124 sdata
->noack_map
= noack_map
;
128 static int ieee80211_add_key(struct wiphy
*wiphy
, struct net_device
*dev
,
129 u8 key_idx
, bool pairwise
, const u8
*mac_addr
,
130 struct key_params
*params
)
132 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
133 struct sta_info
*sta
= NULL
;
134 struct ieee80211_key
*key
;
137 if (!ieee80211_sdata_running(sdata
))
140 /* reject WEP and TKIP keys if WEP failed to initialize */
141 switch (params
->cipher
) {
142 case WLAN_CIPHER_SUITE_WEP40
:
143 case WLAN_CIPHER_SUITE_TKIP
:
144 case WLAN_CIPHER_SUITE_WEP104
:
145 if (IS_ERR(sdata
->local
->wep_tx_tfm
))
152 key
= ieee80211_key_alloc(params
->cipher
, key_idx
, params
->key_len
,
153 params
->key
, params
->seq_len
, params
->seq
);
158 key
->conf
.flags
|= IEEE80211_KEY_FLAG_PAIRWISE
;
160 mutex_lock(&sdata
->local
->sta_mtx
);
163 if (ieee80211_vif_is_mesh(&sdata
->vif
))
164 sta
= sta_info_get(sdata
, mac_addr
);
166 sta
= sta_info_get_bss(sdata
, mac_addr
);
168 * The ASSOC test makes sure the driver is ready to
169 * receive the key. When wpa_supplicant has roamed
170 * using FT, it attempts to set the key before
171 * association has completed, this rejects that attempt
172 * so it will set the key again after assocation.
174 * TODO: accept the key if we have a station entry and
175 * add it to the device after the station.
177 if (!sta
|| !test_sta_flag(sta
, WLAN_STA_ASSOC
)) {
178 ieee80211_key_free(sdata
->local
, key
);
184 switch (sdata
->vif
.type
) {
185 case NL80211_IFTYPE_STATION
:
186 if (sdata
->u
.mgd
.mfp
!= IEEE80211_MFP_DISABLED
)
187 key
->conf
.flags
|= IEEE80211_KEY_FLAG_RX_MGMT
;
189 case NL80211_IFTYPE_AP
:
190 case NL80211_IFTYPE_AP_VLAN
:
191 /* Keys without a station are used for TX only */
192 if (key
->sta
&& test_sta_flag(key
->sta
, WLAN_STA_MFP
))
193 key
->conf
.flags
|= IEEE80211_KEY_FLAG_RX_MGMT
;
195 case NL80211_IFTYPE_ADHOC
:
198 case NL80211_IFTYPE_MESH_POINT
:
199 #ifdef CONFIG_MAC80211_MESH
200 if (sdata
->u
.mesh
.security
!= IEEE80211_MESH_SEC_NONE
)
201 key
->conf
.flags
|= IEEE80211_KEY_FLAG_RX_MGMT
;
204 case NL80211_IFTYPE_WDS
:
205 case NL80211_IFTYPE_MONITOR
:
206 case NL80211_IFTYPE_P2P_DEVICE
:
207 case NL80211_IFTYPE_UNSPECIFIED
:
208 case NUM_NL80211_IFTYPES
:
209 case NL80211_IFTYPE_P2P_CLIENT
:
210 case NL80211_IFTYPE_P2P_GO
:
211 /* shouldn't happen */
216 err
= ieee80211_key_link(key
, sdata
, sta
);
218 ieee80211_key_free(sdata
->local
, key
);
221 mutex_unlock(&sdata
->local
->sta_mtx
);
226 static int ieee80211_del_key(struct wiphy
*wiphy
, struct net_device
*dev
,
227 u8 key_idx
, bool pairwise
, const u8
*mac_addr
)
229 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
230 struct ieee80211_local
*local
= sdata
->local
;
231 struct sta_info
*sta
;
232 struct ieee80211_key
*key
= NULL
;
235 mutex_lock(&local
->sta_mtx
);
236 mutex_lock(&local
->key_mtx
);
241 sta
= sta_info_get_bss(sdata
, mac_addr
);
246 key
= key_mtx_dereference(local
, sta
->ptk
);
248 key
= key_mtx_dereference(local
, sta
->gtk
[key_idx
]);
250 key
= key_mtx_dereference(local
, sdata
->keys
[key_idx
]);
257 __ieee80211_key_free(key
);
261 mutex_unlock(&local
->key_mtx
);
262 mutex_unlock(&local
->sta_mtx
);
267 static int ieee80211_get_key(struct wiphy
*wiphy
, struct net_device
*dev
,
268 u8 key_idx
, bool pairwise
, const u8
*mac_addr
,
270 void (*callback
)(void *cookie
,
271 struct key_params
*params
))
273 struct ieee80211_sub_if_data
*sdata
;
274 struct sta_info
*sta
= NULL
;
276 struct key_params params
;
277 struct ieee80211_key
*key
= NULL
;
283 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
288 sta
= sta_info_get_bss(sdata
, mac_addr
);
293 key
= rcu_dereference(sta
->ptk
);
294 else if (key_idx
< NUM_DEFAULT_KEYS
)
295 key
= rcu_dereference(sta
->gtk
[key_idx
]);
297 key
= rcu_dereference(sdata
->keys
[key_idx
]);
302 memset(¶ms
, 0, sizeof(params
));
304 params
.cipher
= key
->conf
.cipher
;
306 switch (key
->conf
.cipher
) {
307 case WLAN_CIPHER_SUITE_TKIP
:
308 iv32
= key
->u
.tkip
.tx
.iv32
;
309 iv16
= key
->u
.tkip
.tx
.iv16
;
311 if (key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
)
312 drv_get_tkip_seq(sdata
->local
,
313 key
->conf
.hw_key_idx
,
316 seq
[0] = iv16
& 0xff;
317 seq
[1] = (iv16
>> 8) & 0xff;
318 seq
[2] = iv32
& 0xff;
319 seq
[3] = (iv32
>> 8) & 0xff;
320 seq
[4] = (iv32
>> 16) & 0xff;
321 seq
[5] = (iv32
>> 24) & 0xff;
325 case WLAN_CIPHER_SUITE_CCMP
:
326 pn64
= atomic64_read(&key
->u
.ccmp
.tx_pn
);
336 case WLAN_CIPHER_SUITE_AES_CMAC
:
337 pn64
= atomic64_read(&key
->u
.aes_cmac
.tx_pn
);
349 params
.key
= key
->conf
.key
;
350 params
.key_len
= key
->conf
.keylen
;
352 callback(cookie
, ¶ms
);
360 static int ieee80211_config_default_key(struct wiphy
*wiphy
,
361 struct net_device
*dev
,
362 u8 key_idx
, bool uni
,
365 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
367 ieee80211_set_default_key(sdata
, key_idx
, uni
, multi
);
372 static int ieee80211_config_default_mgmt_key(struct wiphy
*wiphy
,
373 struct net_device
*dev
,
376 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
378 ieee80211_set_default_mgmt_key(sdata
, key_idx
);
383 void sta_set_rate_info_tx(struct sta_info
*sta
,
384 const struct ieee80211_tx_rate
*rate
,
385 struct rate_info
*rinfo
)
388 if (rate
->flags
& IEEE80211_TX_RC_MCS
) {
389 rinfo
->flags
|= RATE_INFO_FLAGS_MCS
;
390 rinfo
->mcs
= rate
->idx
;
391 } else if (rate
->flags
& IEEE80211_TX_RC_VHT_MCS
) {
392 rinfo
->flags
|= RATE_INFO_FLAGS_VHT_MCS
;
393 rinfo
->mcs
= ieee80211_rate_get_vht_mcs(rate
);
394 rinfo
->nss
= ieee80211_rate_get_vht_nss(rate
);
396 struct ieee80211_supported_band
*sband
;
397 sband
= sta
->local
->hw
.wiphy
->bands
[
398 ieee80211_get_sdata_band(sta
->sdata
)];
399 rinfo
->legacy
= sband
->bitrates
[rate
->idx
].bitrate
;
401 if (rate
->flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
)
402 rinfo
->flags
|= RATE_INFO_FLAGS_40_MHZ_WIDTH
;
403 if (rate
->flags
& IEEE80211_TX_RC_80_MHZ_WIDTH
)
404 rinfo
->flags
|= RATE_INFO_FLAGS_80_MHZ_WIDTH
;
405 if (rate
->flags
& IEEE80211_TX_RC_160_MHZ_WIDTH
)
406 rinfo
->flags
|= RATE_INFO_FLAGS_160_MHZ_WIDTH
;
407 if (rate
->flags
& IEEE80211_TX_RC_SHORT_GI
)
408 rinfo
->flags
|= RATE_INFO_FLAGS_SHORT_GI
;
411 void sta_set_rate_info_rx(struct sta_info
*sta
, struct rate_info
*rinfo
)
415 if (sta
->last_rx_rate_flag
& RX_FLAG_HT
) {
416 rinfo
->flags
|= RATE_INFO_FLAGS_MCS
;
417 rinfo
->mcs
= sta
->last_rx_rate_idx
;
418 } else if (sta
->last_rx_rate_flag
& RX_FLAG_VHT
) {
419 rinfo
->flags
|= RATE_INFO_FLAGS_VHT_MCS
;
420 rinfo
->nss
= sta
->last_rx_rate_vht_nss
;
421 rinfo
->mcs
= sta
->last_rx_rate_idx
;
423 struct ieee80211_supported_band
*sband
;
425 sband
= sta
->local
->hw
.wiphy
->bands
[
426 ieee80211_get_sdata_band(sta
->sdata
)];
428 sband
->bitrates
[sta
->last_rx_rate_idx
].bitrate
;
431 if (sta
->last_rx_rate_flag
& RX_FLAG_40MHZ
)
432 rinfo
->flags
|= RATE_INFO_FLAGS_40_MHZ_WIDTH
;
433 if (sta
->last_rx_rate_flag
& RX_FLAG_SHORT_GI
)
434 rinfo
->flags
|= RATE_INFO_FLAGS_SHORT_GI
;
435 if (sta
->last_rx_rate_flag
& RX_FLAG_80MHZ
)
436 rinfo
->flags
|= RATE_INFO_FLAGS_80_MHZ_WIDTH
;
437 if (sta
->last_rx_rate_flag
& RX_FLAG_80P80MHZ
)
438 rinfo
->flags
|= RATE_INFO_FLAGS_80P80_MHZ_WIDTH
;
439 if (sta
->last_rx_rate_flag
& RX_FLAG_160MHZ
)
440 rinfo
->flags
|= RATE_INFO_FLAGS_160_MHZ_WIDTH
;
443 static void sta_set_sinfo(struct sta_info
*sta
, struct station_info
*sinfo
)
445 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
446 struct ieee80211_local
*local
= sdata
->local
;
447 struct timespec uptime
;
449 sinfo
->generation
= sdata
->local
->sta_generation
;
451 sinfo
->filled
= STATION_INFO_INACTIVE_TIME
|
452 STATION_INFO_RX_BYTES
|
453 STATION_INFO_TX_BYTES
|
454 STATION_INFO_RX_PACKETS
|
455 STATION_INFO_TX_PACKETS
|
456 STATION_INFO_TX_RETRIES
|
457 STATION_INFO_TX_FAILED
|
458 STATION_INFO_TX_BITRATE
|
459 STATION_INFO_RX_BITRATE
|
460 STATION_INFO_RX_DROP_MISC
|
461 STATION_INFO_BSS_PARAM
|
462 STATION_INFO_CONNECTED_TIME
|
463 STATION_INFO_STA_FLAGS
|
464 STATION_INFO_BEACON_LOSS_COUNT
;
466 do_posix_clock_monotonic_gettime(&uptime
);
467 sinfo
->connected_time
= uptime
.tv_sec
- sta
->last_connected
;
469 sinfo
->inactive_time
= jiffies_to_msecs(jiffies
- sta
->last_rx
);
470 sinfo
->rx_bytes
= sta
->rx_bytes
;
471 sinfo
->tx_bytes
= sta
->tx_bytes
;
472 sinfo
->rx_packets
= sta
->rx_packets
;
473 sinfo
->tx_packets
= sta
->tx_packets
;
474 sinfo
->tx_retries
= sta
->tx_retry_count
;
475 sinfo
->tx_failed
= sta
->tx_retry_failed
;
476 sinfo
->rx_dropped_misc
= sta
->rx_dropped
;
477 sinfo
->beacon_loss_count
= sta
->beacon_loss_count
;
479 if ((sta
->local
->hw
.flags
& IEEE80211_HW_SIGNAL_DBM
) ||
480 (sta
->local
->hw
.flags
& IEEE80211_HW_SIGNAL_UNSPEC
)) {
481 sinfo
->filled
|= STATION_INFO_SIGNAL
| STATION_INFO_SIGNAL_AVG
;
482 if (!local
->ops
->get_rssi
||
483 drv_get_rssi(local
, sdata
, &sta
->sta
, &sinfo
->signal
))
484 sinfo
->signal
= (s8
)sta
->last_signal
;
485 sinfo
->signal_avg
= (s8
) -ewma_read(&sta
->avg_signal
);
488 sta_set_rate_info_tx(sta
, &sta
->last_tx_rate
, &sinfo
->txrate
);
489 sta_set_rate_info_rx(sta
, &sinfo
->rxrate
);
491 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
492 #ifdef CONFIG_MAC80211_MESH
493 sinfo
->filled
|= STATION_INFO_LLID
|
495 STATION_INFO_PLINK_STATE
;
497 sinfo
->llid
= le16_to_cpu(sta
->llid
);
498 sinfo
->plid
= le16_to_cpu(sta
->plid
);
499 sinfo
->plink_state
= sta
->plink_state
;
500 if (test_sta_flag(sta
, WLAN_STA_TOFFSET_KNOWN
)) {
501 sinfo
->filled
|= STATION_INFO_T_OFFSET
;
502 sinfo
->t_offset
= sta
->t_offset
;
507 sinfo
->bss_param
.flags
= 0;
508 if (sdata
->vif
.bss_conf
.use_cts_prot
)
509 sinfo
->bss_param
.flags
|= BSS_PARAM_FLAGS_CTS_PROT
;
510 if (sdata
->vif
.bss_conf
.use_short_preamble
)
511 sinfo
->bss_param
.flags
|= BSS_PARAM_FLAGS_SHORT_PREAMBLE
;
512 if (sdata
->vif
.bss_conf
.use_short_slot
)
513 sinfo
->bss_param
.flags
|= BSS_PARAM_FLAGS_SHORT_SLOT_TIME
;
514 sinfo
->bss_param
.dtim_period
= sdata
->local
->hw
.conf
.ps_dtim_period
;
515 sinfo
->bss_param
.beacon_interval
= sdata
->vif
.bss_conf
.beacon_int
;
517 sinfo
->sta_flags
.set
= 0;
518 sinfo
->sta_flags
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
519 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
520 BIT(NL80211_STA_FLAG_WME
) |
521 BIT(NL80211_STA_FLAG_MFP
) |
522 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
523 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
524 BIT(NL80211_STA_FLAG_TDLS_PEER
);
525 if (test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
526 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
527 if (test_sta_flag(sta
, WLAN_STA_SHORT_PREAMBLE
))
528 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
529 if (test_sta_flag(sta
, WLAN_STA_WME
))
530 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_WME
);
531 if (test_sta_flag(sta
, WLAN_STA_MFP
))
532 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_MFP
);
533 if (test_sta_flag(sta
, WLAN_STA_AUTH
))
534 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
);
535 if (test_sta_flag(sta
, WLAN_STA_ASSOC
))
536 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
537 if (test_sta_flag(sta
, WLAN_STA_TDLS_PEER
))
538 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
541 static const char ieee80211_gstrings_sta_stats
[][ETH_GSTRING_LEN
] = {
542 "rx_packets", "rx_bytes", "wep_weak_iv_count",
543 "rx_duplicates", "rx_fragments", "rx_dropped",
544 "tx_packets", "tx_bytes", "tx_fragments",
545 "tx_filtered", "tx_retry_failed", "tx_retries",
546 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
547 "channel", "noise", "ch_time", "ch_time_busy",
548 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
550 #define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
552 static int ieee80211_get_et_sset_count(struct wiphy
*wiphy
,
553 struct net_device
*dev
,
556 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
559 if (sset
== ETH_SS_STATS
)
562 rv
+= drv_get_et_sset_count(sdata
, sset
);
569 static void ieee80211_get_et_stats(struct wiphy
*wiphy
,
570 struct net_device
*dev
,
571 struct ethtool_stats
*stats
,
574 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
575 struct ieee80211_chanctx_conf
*chanctx_conf
;
576 struct ieee80211_channel
*channel
;
577 struct sta_info
*sta
;
578 struct ieee80211_local
*local
= sdata
->local
;
579 struct station_info sinfo
;
580 struct survey_info survey
;
582 #define STA_STATS_SURVEY_LEN 7
584 memset(data
, 0, sizeof(u64
) * STA_STATS_LEN
);
586 #define ADD_STA_STATS(sta) \
588 data[i++] += sta->rx_packets; \
589 data[i++] += sta->rx_bytes; \
590 data[i++] += sta->wep_weak_iv_count; \
591 data[i++] += sta->num_duplicates; \
592 data[i++] += sta->rx_fragments; \
593 data[i++] += sta->rx_dropped; \
595 data[i++] += sta->tx_packets; \
596 data[i++] += sta->tx_bytes; \
597 data[i++] += sta->tx_fragments; \
598 data[i++] += sta->tx_filtered_count; \
599 data[i++] += sta->tx_retry_failed; \
600 data[i++] += sta->tx_retry_count; \
601 data[i++] += sta->beacon_loss_count; \
604 /* For Managed stations, find the single station based on BSSID
605 * and use that. For interface types, iterate through all available
606 * stations and add stats for any station that is assigned to this
610 mutex_lock(&local
->sta_mtx
);
612 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
613 sta
= sta_info_get_bss(sdata
, sdata
->u
.mgd
.bssid
);
615 if (!(sta
&& !WARN_ON(sta
->sdata
->dev
!= dev
)))
621 data
[i
++] = sta
->sta_state
;
624 sta_set_sinfo(sta
, &sinfo
);
626 if (sinfo
.filled
& STATION_INFO_TX_BITRATE
)
628 cfg80211_calculate_bitrate(&sinfo
.txrate
);
630 if (sinfo
.filled
& STATION_INFO_RX_BITRATE
)
632 cfg80211_calculate_bitrate(&sinfo
.rxrate
);
635 if (sinfo
.filled
& STATION_INFO_SIGNAL_AVG
)
636 data
[i
] = (u8
)sinfo
.signal_avg
;
639 list_for_each_entry(sta
, &local
->sta_list
, list
) {
640 /* Make sure this station belongs to the proper dev */
641 if (sta
->sdata
->dev
!= dev
)
650 i
= STA_STATS_LEN
- STA_STATS_SURVEY_LEN
;
651 /* Get survey stats for current channel */
655 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
657 channel
= chanctx_conf
->def
.chan
;
666 if (drv_get_survey(local
, q
, &survey
) != 0) {
671 } while (channel
!= survey
.channel
);
675 data
[i
++] = survey
.channel
->center_freq
;
678 if (survey
.filled
& SURVEY_INFO_NOISE_DBM
)
679 data
[i
++] = (u8
)survey
.noise
;
682 if (survey
.filled
& SURVEY_INFO_CHANNEL_TIME
)
683 data
[i
++] = survey
.channel_time
;
686 if (survey
.filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
)
687 data
[i
++] = survey
.channel_time_busy
;
690 if (survey
.filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
)
691 data
[i
++] = survey
.channel_time_ext_busy
;
694 if (survey
.filled
& SURVEY_INFO_CHANNEL_TIME_RX
)
695 data
[i
++] = survey
.channel_time_rx
;
698 if (survey
.filled
& SURVEY_INFO_CHANNEL_TIME_TX
)
699 data
[i
++] = survey
.channel_time_tx
;
703 mutex_unlock(&local
->sta_mtx
);
705 if (WARN_ON(i
!= STA_STATS_LEN
))
708 drv_get_et_stats(sdata
, stats
, &(data
[STA_STATS_LEN
]));
711 static void ieee80211_get_et_strings(struct wiphy
*wiphy
,
712 struct net_device
*dev
,
715 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
716 int sz_sta_stats
= 0;
718 if (sset
== ETH_SS_STATS
) {
719 sz_sta_stats
= sizeof(ieee80211_gstrings_sta_stats
);
720 memcpy(data
, *ieee80211_gstrings_sta_stats
, sz_sta_stats
);
722 drv_get_et_strings(sdata
, sset
, &(data
[sz_sta_stats
]));
725 static int ieee80211_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
726 int idx
, u8
*mac
, struct station_info
*sinfo
)
728 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
729 struct ieee80211_local
*local
= sdata
->local
;
730 struct sta_info
*sta
;
733 mutex_lock(&local
->sta_mtx
);
735 sta
= sta_info_get_by_idx(sdata
, idx
);
738 memcpy(mac
, sta
->sta
.addr
, ETH_ALEN
);
739 sta_set_sinfo(sta
, sinfo
);
742 mutex_unlock(&local
->sta_mtx
);
747 static int ieee80211_dump_survey(struct wiphy
*wiphy
, struct net_device
*dev
,
748 int idx
, struct survey_info
*survey
)
750 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
752 return drv_get_survey(local
, idx
, survey
);
755 static int ieee80211_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
756 u8
*mac
, struct station_info
*sinfo
)
758 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
759 struct ieee80211_local
*local
= sdata
->local
;
760 struct sta_info
*sta
;
763 mutex_lock(&local
->sta_mtx
);
765 sta
= sta_info_get_bss(sdata
, mac
);
768 sta_set_sinfo(sta
, sinfo
);
771 mutex_unlock(&local
->sta_mtx
);
776 static int ieee80211_set_monitor_channel(struct wiphy
*wiphy
,
777 struct cfg80211_chan_def
*chandef
)
779 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
780 struct ieee80211_sub_if_data
*sdata
;
783 if (cfg80211_chandef_identical(&local
->monitor_chandef
, chandef
))
786 mutex_lock(&local
->iflist_mtx
);
787 if (local
->use_chanctx
) {
788 sdata
= rcu_dereference_protected(
789 local
->monitor_sdata
,
790 lockdep_is_held(&local
->iflist_mtx
));
792 ieee80211_vif_release_channel(sdata
);
793 ret
= ieee80211_vif_use_channel(sdata
, chandef
,
794 IEEE80211_CHANCTX_EXCLUSIVE
);
796 } else if (local
->open_count
== local
->monitors
) {
797 local
->_oper_channel
= chandef
->chan
;
798 local
->_oper_channel_type
= cfg80211_get_chandef_type(chandef
);
799 ieee80211_hw_config(local
, 0);
803 local
->monitor_chandef
= *chandef
;
804 mutex_unlock(&local
->iflist_mtx
);
809 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data
*sdata
,
810 const u8
*resp
, size_t resp_len
)
812 struct probe_resp
*new, *old
;
814 if (!resp
|| !resp_len
)
817 old
= rtnl_dereference(sdata
->u
.ap
.probe_resp
);
819 new = kzalloc(sizeof(struct probe_resp
) + resp_len
, GFP_KERNEL
);
824 memcpy(new->data
, resp
, resp_len
);
826 rcu_assign_pointer(sdata
->u
.ap
.probe_resp
, new);
828 kfree_rcu(old
, rcu_head
);
833 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data
*sdata
,
834 struct cfg80211_beacon_data
*params
)
836 struct beacon_data
*new, *old
;
837 int new_head_len
, new_tail_len
;
839 u32 changed
= BSS_CHANGED_BEACON
;
841 old
= rtnl_dereference(sdata
->u
.ap
.beacon
);
843 /* Need to have a beacon head if we don't have one yet */
844 if (!params
->head
&& !old
)
847 /* new or old head? */
849 new_head_len
= params
->head_len
;
851 new_head_len
= old
->head_len
;
853 /* new or old tail? */
854 if (params
->tail
|| !old
)
855 /* params->tail_len will be zero for !params->tail */
856 new_tail_len
= params
->tail_len
;
858 new_tail_len
= old
->tail_len
;
860 size
= sizeof(*new) + new_head_len
+ new_tail_len
;
862 new = kzalloc(size
, GFP_KERNEL
);
866 /* start filling the new info now */
869 * pointers go into the block we allocated,
870 * memory is | beacon_data | head | tail |
872 new->head
= ((u8
*) new) + sizeof(*new);
873 new->tail
= new->head
+ new_head_len
;
874 new->head_len
= new_head_len
;
875 new->tail_len
= new_tail_len
;
879 memcpy(new->head
, params
->head
, new_head_len
);
881 memcpy(new->head
, old
->head
, new_head_len
);
883 /* copy in optional tail */
885 memcpy(new->tail
, params
->tail
, new_tail_len
);
888 memcpy(new->tail
, old
->tail
, new_tail_len
);
890 err
= ieee80211_set_probe_resp(sdata
, params
->probe_resp
,
891 params
->probe_resp_len
);
895 changed
|= BSS_CHANGED_AP_PROBE_RESP
;
897 rcu_assign_pointer(sdata
->u
.ap
.beacon
, new);
900 kfree_rcu(old
, rcu_head
);
905 static int ieee80211_start_ap(struct wiphy
*wiphy
, struct net_device
*dev
,
906 struct cfg80211_ap_settings
*params
)
908 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
909 struct beacon_data
*old
;
910 struct ieee80211_sub_if_data
*vlan
;
911 u32 changed
= BSS_CHANGED_BEACON_INT
|
912 BSS_CHANGED_BEACON_ENABLED
|
918 old
= rtnl_dereference(sdata
->u
.ap
.beacon
);
922 /* TODO: make hostapd tell us what it wants */
923 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
924 sdata
->needed_rx_chains
= sdata
->local
->rx_chains
;
926 err
= ieee80211_vif_use_channel(sdata
, ¶ms
->chandef
,
927 IEEE80211_CHANCTX_SHARED
);
932 * Apply control port protocol, this allows us to
933 * not encrypt dynamic WEP control frames.
935 sdata
->control_port_protocol
= params
->crypto
.control_port_ethertype
;
936 sdata
->control_port_no_encrypt
= params
->crypto
.control_port_no_encrypt
;
937 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
) {
938 vlan
->control_port_protocol
=
939 params
->crypto
.control_port_ethertype
;
940 vlan
->control_port_no_encrypt
=
941 params
->crypto
.control_port_no_encrypt
;
944 sdata
->vif
.bss_conf
.beacon_int
= params
->beacon_interval
;
945 sdata
->vif
.bss_conf
.dtim_period
= params
->dtim_period
;
946 sdata
->vif
.bss_conf
.enable_beacon
= true;
948 sdata
->vif
.bss_conf
.ssid_len
= params
->ssid_len
;
949 if (params
->ssid_len
)
950 memcpy(sdata
->vif
.bss_conf
.ssid
, params
->ssid
,
952 sdata
->vif
.bss_conf
.hidden_ssid
=
953 (params
->hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
);
955 sdata
->vif
.bss_conf
.p2p_ctwindow
= params
->p2p_ctwindow
;
956 sdata
->vif
.bss_conf
.p2p_oppps
= params
->p2p_opp_ps
;
958 err
= ieee80211_assign_beacon(sdata
, ¶ms
->beacon
);
963 err
= drv_start_ap(sdata
->local
, sdata
);
965 old
= rtnl_dereference(sdata
->u
.ap
.beacon
);
967 kfree_rcu(old
, rcu_head
);
968 RCU_INIT_POINTER(sdata
->u
.ap
.beacon
, NULL
);
972 ieee80211_bss_info_change_notify(sdata
, changed
);
974 netif_carrier_on(dev
);
975 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
)
976 netif_carrier_on(vlan
->dev
);
981 static int ieee80211_change_beacon(struct wiphy
*wiphy
, struct net_device
*dev
,
982 struct cfg80211_beacon_data
*params
)
984 struct ieee80211_sub_if_data
*sdata
;
985 struct beacon_data
*old
;
988 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
990 old
= rtnl_dereference(sdata
->u
.ap
.beacon
);
994 err
= ieee80211_assign_beacon(sdata
, params
);
997 ieee80211_bss_info_change_notify(sdata
, err
);
1001 static int ieee80211_stop_ap(struct wiphy
*wiphy
, struct net_device
*dev
)
1003 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1004 struct ieee80211_sub_if_data
*vlan
;
1005 struct ieee80211_local
*local
= sdata
->local
;
1006 struct beacon_data
*old_beacon
;
1007 struct probe_resp
*old_probe_resp
;
1009 old_beacon
= rtnl_dereference(sdata
->u
.ap
.beacon
);
1012 old_probe_resp
= rtnl_dereference(sdata
->u
.ap
.probe_resp
);
1014 /* turn off carrier for this interface and dependent VLANs */
1015 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
)
1016 netif_carrier_off(vlan
->dev
);
1017 netif_carrier_off(dev
);
1019 /* remove beacon and probe response */
1020 RCU_INIT_POINTER(sdata
->u
.ap
.beacon
, NULL
);
1021 RCU_INIT_POINTER(sdata
->u
.ap
.probe_resp
, NULL
);
1022 kfree_rcu(old_beacon
, rcu_head
);
1024 kfree_rcu(old_probe_resp
, rcu_head
);
1026 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
)
1027 sta_info_flush_defer(vlan
);
1028 sta_info_flush_defer(sdata
);
1030 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
)
1031 sta_info_flush_cleanup(vlan
);
1032 sta_info_flush_cleanup(sdata
);
1034 sdata
->vif
.bss_conf
.enable_beacon
= false;
1035 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED
, &sdata
->state
);
1036 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BEACON_ENABLED
);
1038 drv_stop_ap(sdata
->local
, sdata
);
1040 /* free all potentially still buffered bcast frames */
1041 local
->total_ps_buffered
-= skb_queue_len(&sdata
->u
.ap
.ps
.bc_buf
);
1042 skb_queue_purge(&sdata
->u
.ap
.ps
.bc_buf
);
1044 ieee80211_vif_release_channel(sdata
);
1049 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1050 struct iapp_layer2_update
{
1051 u8 da
[ETH_ALEN
]; /* broadcast */
1052 u8 sa
[ETH_ALEN
]; /* STA addr */
1060 static void ieee80211_send_layer2_update(struct sta_info
*sta
)
1062 struct iapp_layer2_update
*msg
;
1063 struct sk_buff
*skb
;
1065 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1068 skb
= dev_alloc_skb(sizeof(*msg
));
1071 msg
= (struct iapp_layer2_update
*)skb_put(skb
, sizeof(*msg
));
1073 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1074 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1076 eth_broadcast_addr(msg
->da
);
1077 memcpy(msg
->sa
, sta
->sta
.addr
, ETH_ALEN
);
1078 msg
->len
= htons(6);
1080 msg
->ssap
= 0x01; /* NULL LSAP, CR Bit: Response */
1081 msg
->control
= 0xaf; /* XID response lsb.1111F101.
1082 * F=0 (no poll command; unsolicited frame) */
1083 msg
->xid_info
[0] = 0x81; /* XID format identifier */
1084 msg
->xid_info
[1] = 1; /* LLC types/classes: Type 1 LLC */
1085 msg
->xid_info
[2] = 0; /* XID sender's receive window size (RW) */
1087 skb
->dev
= sta
->sdata
->dev
;
1088 skb
->protocol
= eth_type_trans(skb
, sta
->sdata
->dev
);
1089 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1093 static int sta_apply_auth_flags(struct ieee80211_local
*local
,
1094 struct sta_info
*sta
,
1099 if (mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
) &&
1100 set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
) &&
1101 !test_sta_flag(sta
, WLAN_STA_AUTH
)) {
1102 ret
= sta_info_move_state(sta
, IEEE80211_STA_AUTH
);
1107 if (mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
) &&
1108 set
& BIT(NL80211_STA_FLAG_ASSOCIATED
) &&
1109 !test_sta_flag(sta
, WLAN_STA_ASSOC
)) {
1110 ret
= sta_info_move_state(sta
, IEEE80211_STA_ASSOC
);
1115 if (mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
1116 if (set
& BIT(NL80211_STA_FLAG_AUTHORIZED
))
1117 ret
= sta_info_move_state(sta
, IEEE80211_STA_AUTHORIZED
);
1118 else if (test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
1119 ret
= sta_info_move_state(sta
, IEEE80211_STA_ASSOC
);
1126 if (mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
) &&
1127 !(set
& BIT(NL80211_STA_FLAG_ASSOCIATED
)) &&
1128 test_sta_flag(sta
, WLAN_STA_ASSOC
)) {
1129 ret
= sta_info_move_state(sta
, IEEE80211_STA_AUTH
);
1134 if (mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
) &&
1135 !(set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
)) &&
1136 test_sta_flag(sta
, WLAN_STA_AUTH
)) {
1137 ret
= sta_info_move_state(sta
, IEEE80211_STA_NONE
);
1145 static int sta_apply_parameters(struct ieee80211_local
*local
,
1146 struct sta_info
*sta
,
1147 struct station_parameters
*params
)
1152 struct ieee80211_supported_band
*sband
;
1153 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
1154 enum ieee80211_band band
= ieee80211_get_sdata_band(sdata
);
1157 sband
= local
->hw
.wiphy
->bands
[band
];
1159 mask
= params
->sta_flags_mask
;
1160 set
= params
->sta_flags_set
;
1162 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
1164 * In mesh mode, ASSOCIATED isn't part of the nl80211
1165 * API but must follow AUTHENTICATED for driver state.
1167 if (mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
))
1168 mask
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
1169 if (set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
))
1170 set
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
1173 ret
= sta_apply_auth_flags(local
, sta
, mask
, set
);
1177 if (mask
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
)) {
1178 if (set
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
))
1179 set_sta_flag(sta
, WLAN_STA_SHORT_PREAMBLE
);
1181 clear_sta_flag(sta
, WLAN_STA_SHORT_PREAMBLE
);
1184 if (mask
& BIT(NL80211_STA_FLAG_WME
)) {
1185 if (set
& BIT(NL80211_STA_FLAG_WME
)) {
1186 set_sta_flag(sta
, WLAN_STA_WME
);
1187 sta
->sta
.wme
= true;
1189 clear_sta_flag(sta
, WLAN_STA_WME
);
1190 sta
->sta
.wme
= false;
1194 if (mask
& BIT(NL80211_STA_FLAG_MFP
)) {
1195 if (set
& BIT(NL80211_STA_FLAG_MFP
))
1196 set_sta_flag(sta
, WLAN_STA_MFP
);
1198 clear_sta_flag(sta
, WLAN_STA_MFP
);
1201 if (mask
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) {
1202 if (set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
1203 set_sta_flag(sta
, WLAN_STA_TDLS_PEER
);
1205 clear_sta_flag(sta
, WLAN_STA_TDLS_PEER
);
1208 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
) {
1209 sta
->sta
.uapsd_queues
= params
->uapsd_queues
;
1210 sta
->sta
.max_sp
= params
->max_sp
;
1214 * cfg80211 validates this (1-2007) and allows setting the AID
1215 * only when creating a new station entry
1218 sta
->sta
.aid
= params
->aid
;
1221 * Some of the following updates would be racy if called on an
1222 * existing station, via ieee80211_change_station(). However,
1223 * all such changes are rejected by cfg80211 except for updates
1224 * changing the supported rates on an existing but not yet used
1228 if (params
->listen_interval
>= 0)
1229 sta
->listen_interval
= params
->listen_interval
;
1231 if (params
->supported_rates
) {
1234 for (i
= 0; i
< params
->supported_rates_len
; i
++) {
1235 int rate
= (params
->supported_rates
[i
] & 0x7f) * 5;
1236 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1237 if (sband
->bitrates
[j
].bitrate
== rate
)
1241 sta
->sta
.supp_rates
[band
] = rates
;
1244 if (params
->ht_capa
)
1245 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata
, sband
,
1249 if (params
->vht_capa
)
1250 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata
, sband
,
1254 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
1255 #ifdef CONFIG_MAC80211_MESH
1256 if (sdata
->u
.mesh
.security
& IEEE80211_MESH_SEC_SECURED
) {
1259 switch (params
->plink_state
) {
1260 case NL80211_PLINK_ESTAB
:
1261 if (sta
->plink_state
!= NL80211_PLINK_ESTAB
)
1262 changed
= mesh_plink_inc_estab_count(
1264 sta
->plink_state
= params
->plink_state
;
1266 case NL80211_PLINK_LISTEN
:
1267 case NL80211_PLINK_BLOCKED
:
1268 case NL80211_PLINK_OPN_SNT
:
1269 case NL80211_PLINK_OPN_RCVD
:
1270 case NL80211_PLINK_CNF_RCVD
:
1271 case NL80211_PLINK_HOLDING
:
1272 if (sta
->plink_state
== NL80211_PLINK_ESTAB
)
1273 changed
= mesh_plink_dec_estab_count(
1275 sta
->plink_state
= params
->plink_state
;
1281 ieee80211_bss_info_change_notify(sdata
, changed
);
1283 switch (params
->plink_action
) {
1284 case PLINK_ACTION_OPEN
:
1285 mesh_plink_open(sta
);
1287 case PLINK_ACTION_BLOCK
:
1288 mesh_plink_block(sta
);
1298 static int ieee80211_add_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1299 u8
*mac
, struct station_parameters
*params
)
1301 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1302 struct sta_info
*sta
;
1303 struct ieee80211_sub_if_data
*sdata
;
1308 sdata
= IEEE80211_DEV_TO_SUB_IF(params
->vlan
);
1310 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
1311 sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
1314 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1316 if (ether_addr_equal(mac
, sdata
->vif
.addr
))
1319 if (is_multicast_ether_addr(mac
))
1322 sta
= sta_info_alloc(sdata
, mac
, GFP_KERNEL
);
1327 * defaults -- if userspace wants something else we'll
1328 * change it accordingly in sta_apply_parameters()
1330 sta_info_pre_move_state(sta
, IEEE80211_STA_AUTH
);
1331 sta_info_pre_move_state(sta
, IEEE80211_STA_ASSOC
);
1333 err
= sta_apply_parameters(local
, sta
, params
);
1335 sta_info_free(local
, sta
);
1340 * for TDLS, rate control should be initialized only when supported
1343 if (!test_sta_flag(sta
, WLAN_STA_TDLS_PEER
))
1344 rate_control_rate_init(sta
);
1346 layer2_update
= sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
||
1347 sdata
->vif
.type
== NL80211_IFTYPE_AP
;
1349 err
= sta_info_insert_rcu(sta
);
1356 ieee80211_send_layer2_update(sta
);
1363 static int ieee80211_del_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1366 struct ieee80211_sub_if_data
*sdata
;
1368 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1371 return sta_info_destroy_addr_bss(sdata
, mac
);
1373 sta_info_flush(sdata
);
1377 static int ieee80211_change_station(struct wiphy
*wiphy
,
1378 struct net_device
*dev
,
1380 struct station_parameters
*params
)
1382 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1383 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1384 struct sta_info
*sta
;
1385 struct ieee80211_sub_if_data
*vlansdata
;
1388 mutex_lock(&local
->sta_mtx
);
1390 sta
= sta_info_get_bss(sdata
, mac
);
1392 mutex_unlock(&local
->sta_mtx
);
1396 /* in station mode, supported rates are only valid with TDLS */
1397 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
&&
1398 params
->supported_rates
&&
1399 !test_sta_flag(sta
, WLAN_STA_TDLS_PEER
)) {
1400 mutex_unlock(&local
->sta_mtx
);
1404 if (params
->vlan
&& params
->vlan
!= sta
->sdata
->dev
) {
1405 bool prev_4addr
= false;
1406 bool new_4addr
= false;
1408 vlansdata
= IEEE80211_DEV_TO_SUB_IF(params
->vlan
);
1410 if (vlansdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
1411 vlansdata
->vif
.type
!= NL80211_IFTYPE_AP
) {
1412 mutex_unlock(&local
->sta_mtx
);
1416 if (params
->vlan
->ieee80211_ptr
->use_4addr
) {
1417 if (vlansdata
->u
.vlan
.sta
) {
1418 mutex_unlock(&local
->sta_mtx
);
1422 rcu_assign_pointer(vlansdata
->u
.vlan
.sta
, sta
);
1426 if (sta
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&&
1427 sta
->sdata
->u
.vlan
.sta
) {
1428 rcu_assign_pointer(sta
->sdata
->u
.vlan
.sta
, NULL
);
1432 sta
->sdata
= vlansdata
;
1434 if (sta
->sta_state
== IEEE80211_STA_AUTHORIZED
&&
1435 prev_4addr
!= new_4addr
) {
1437 atomic_dec(&sta
->sdata
->bss
->num_mcast_sta
);
1439 atomic_inc(&sta
->sdata
->bss
->num_mcast_sta
);
1442 ieee80211_send_layer2_update(sta
);
1445 err
= sta_apply_parameters(local
, sta
, params
);
1447 mutex_unlock(&local
->sta_mtx
);
1451 if (test_sta_flag(sta
, WLAN_STA_TDLS_PEER
) && params
->supported_rates
)
1452 rate_control_rate_init(sta
);
1454 mutex_unlock(&local
->sta_mtx
);
1456 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
&&
1457 params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
1458 ieee80211_recalc_ps(local
, -1);
1459 ieee80211_recalc_ps_vif(sdata
);
1464 #ifdef CONFIG_MAC80211_MESH
1465 static int ieee80211_add_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1466 u8
*dst
, u8
*next_hop
)
1468 struct ieee80211_sub_if_data
*sdata
;
1469 struct mesh_path
*mpath
;
1470 struct sta_info
*sta
;
1473 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1476 sta
= sta_info_get(sdata
, next_hop
);
1482 err
= mesh_path_add(dst
, sdata
);
1488 mpath
= mesh_path_lookup(dst
, sdata
);
1493 mesh_path_fix_nexthop(mpath
, sta
);
1499 static int ieee80211_del_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1502 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1505 return mesh_path_del(dst
, sdata
);
1507 mesh_path_flush_by_iface(sdata
);
1511 static int ieee80211_change_mpath(struct wiphy
*wiphy
,
1512 struct net_device
*dev
,
1513 u8
*dst
, u8
*next_hop
)
1515 struct ieee80211_sub_if_data
*sdata
;
1516 struct mesh_path
*mpath
;
1517 struct sta_info
*sta
;
1519 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1523 sta
= sta_info_get(sdata
, next_hop
);
1529 mpath
= mesh_path_lookup(dst
, sdata
);
1535 mesh_path_fix_nexthop(mpath
, sta
);
1541 static void mpath_set_pinfo(struct mesh_path
*mpath
, u8
*next_hop
,
1542 struct mpath_info
*pinfo
)
1544 struct sta_info
*next_hop_sta
= rcu_dereference(mpath
->next_hop
);
1547 memcpy(next_hop
, next_hop_sta
->sta
.addr
, ETH_ALEN
);
1549 memset(next_hop
, 0, ETH_ALEN
);
1551 memset(pinfo
, 0, sizeof(*pinfo
));
1553 pinfo
->generation
= mesh_paths_generation
;
1555 pinfo
->filled
= MPATH_INFO_FRAME_QLEN
|
1558 MPATH_INFO_EXPTIME
|
1559 MPATH_INFO_DISCOVERY_TIMEOUT
|
1560 MPATH_INFO_DISCOVERY_RETRIES
|
1563 pinfo
->frame_qlen
= mpath
->frame_queue
.qlen
;
1564 pinfo
->sn
= mpath
->sn
;
1565 pinfo
->metric
= mpath
->metric
;
1566 if (time_before(jiffies
, mpath
->exp_time
))
1567 pinfo
->exptime
= jiffies_to_msecs(mpath
->exp_time
- jiffies
);
1568 pinfo
->discovery_timeout
=
1569 jiffies_to_msecs(mpath
->discovery_timeout
);
1570 pinfo
->discovery_retries
= mpath
->discovery_retries
;
1571 if (mpath
->flags
& MESH_PATH_ACTIVE
)
1572 pinfo
->flags
|= NL80211_MPATH_FLAG_ACTIVE
;
1573 if (mpath
->flags
& MESH_PATH_RESOLVING
)
1574 pinfo
->flags
|= NL80211_MPATH_FLAG_RESOLVING
;
1575 if (mpath
->flags
& MESH_PATH_SN_VALID
)
1576 pinfo
->flags
|= NL80211_MPATH_FLAG_SN_VALID
;
1577 if (mpath
->flags
& MESH_PATH_FIXED
)
1578 pinfo
->flags
|= NL80211_MPATH_FLAG_FIXED
;
1579 if (mpath
->flags
& MESH_PATH_RESOLVED
)
1580 pinfo
->flags
|= NL80211_MPATH_FLAG_RESOLVED
;
1583 static int ieee80211_get_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1584 u8
*dst
, u8
*next_hop
, struct mpath_info
*pinfo
)
1587 struct ieee80211_sub_if_data
*sdata
;
1588 struct mesh_path
*mpath
;
1590 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1593 mpath
= mesh_path_lookup(dst
, sdata
);
1598 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
1599 mpath_set_pinfo(mpath
, next_hop
, pinfo
);
1604 static int ieee80211_dump_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1605 int idx
, u8
*dst
, u8
*next_hop
,
1606 struct mpath_info
*pinfo
)
1608 struct ieee80211_sub_if_data
*sdata
;
1609 struct mesh_path
*mpath
;
1611 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1614 mpath
= mesh_path_lookup_by_idx(idx
, sdata
);
1619 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
1620 mpath_set_pinfo(mpath
, next_hop
, pinfo
);
1625 static int ieee80211_get_mesh_config(struct wiphy
*wiphy
,
1626 struct net_device
*dev
,
1627 struct mesh_config
*conf
)
1629 struct ieee80211_sub_if_data
*sdata
;
1630 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1632 memcpy(conf
, &(sdata
->u
.mesh
.mshcfg
), sizeof(struct mesh_config
));
1636 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm
, u32 mask
)
1638 return (mask
>> (parm
-1)) & 0x1;
1641 static int copy_mesh_setup(struct ieee80211_if_mesh
*ifmsh
,
1642 const struct mesh_setup
*setup
)
1646 struct ieee80211_sub_if_data
*sdata
= container_of(ifmsh
,
1647 struct ieee80211_sub_if_data
, u
.mesh
);
1649 /* allocate information elements */
1653 if (setup
->ie_len
) {
1654 new_ie
= kmemdup(setup
->ie
, setup
->ie_len
,
1659 ifmsh
->ie_len
= setup
->ie_len
;
1663 /* now copy the rest of the setup parameters */
1664 ifmsh
->mesh_id_len
= setup
->mesh_id_len
;
1665 memcpy(ifmsh
->mesh_id
, setup
->mesh_id
, ifmsh
->mesh_id_len
);
1666 ifmsh
->mesh_sp_id
= setup
->sync_method
;
1667 ifmsh
->mesh_pp_id
= setup
->path_sel_proto
;
1668 ifmsh
->mesh_pm_id
= setup
->path_metric
;
1669 ifmsh
->security
= IEEE80211_MESH_SEC_NONE
;
1670 if (setup
->is_authenticated
)
1671 ifmsh
->security
|= IEEE80211_MESH_SEC_AUTHED
;
1672 if (setup
->is_secure
)
1673 ifmsh
->security
|= IEEE80211_MESH_SEC_SECURED
;
1675 /* mcast rate setting in Mesh Node */
1676 memcpy(sdata
->vif
.bss_conf
.mcast_rate
, setup
->mcast_rate
,
1677 sizeof(setup
->mcast_rate
));
1679 sdata
->vif
.bss_conf
.beacon_int
= setup
->beacon_interval
;
1680 sdata
->vif
.bss_conf
.dtim_period
= setup
->dtim_period
;
1685 static int ieee80211_update_mesh_config(struct wiphy
*wiphy
,
1686 struct net_device
*dev
, u32 mask
,
1687 const struct mesh_config
*nconf
)
1689 struct mesh_config
*conf
;
1690 struct ieee80211_sub_if_data
*sdata
;
1691 struct ieee80211_if_mesh
*ifmsh
;
1693 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1694 ifmsh
= &sdata
->u
.mesh
;
1696 /* Set the config options which we are interested in setting */
1697 conf
= &(sdata
->u
.mesh
.mshcfg
);
1698 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT
, mask
))
1699 conf
->dot11MeshRetryTimeout
= nconf
->dot11MeshRetryTimeout
;
1700 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT
, mask
))
1701 conf
->dot11MeshConfirmTimeout
= nconf
->dot11MeshConfirmTimeout
;
1702 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT
, mask
))
1703 conf
->dot11MeshHoldingTimeout
= nconf
->dot11MeshHoldingTimeout
;
1704 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS
, mask
))
1705 conf
->dot11MeshMaxPeerLinks
= nconf
->dot11MeshMaxPeerLinks
;
1706 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES
, mask
))
1707 conf
->dot11MeshMaxRetries
= nconf
->dot11MeshMaxRetries
;
1708 if (_chg_mesh_attr(NL80211_MESHCONF_TTL
, mask
))
1709 conf
->dot11MeshTTL
= nconf
->dot11MeshTTL
;
1710 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL
, mask
))
1711 conf
->element_ttl
= nconf
->element_ttl
;
1712 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS
, mask
))
1713 conf
->auto_open_plinks
= nconf
->auto_open_plinks
;
1714 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
, mask
))
1715 conf
->dot11MeshNbrOffsetMaxNeighbor
=
1716 nconf
->dot11MeshNbrOffsetMaxNeighbor
;
1717 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
, mask
))
1718 conf
->dot11MeshHWMPmaxPREQretries
=
1719 nconf
->dot11MeshHWMPmaxPREQretries
;
1720 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME
, mask
))
1721 conf
->path_refresh_time
= nconf
->path_refresh_time
;
1722 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
, mask
))
1723 conf
->min_discovery_timeout
= nconf
->min_discovery_timeout
;
1724 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
, mask
))
1725 conf
->dot11MeshHWMPactivePathTimeout
=
1726 nconf
->dot11MeshHWMPactivePathTimeout
;
1727 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
, mask
))
1728 conf
->dot11MeshHWMPpreqMinInterval
=
1729 nconf
->dot11MeshHWMPpreqMinInterval
;
1730 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
, mask
))
1731 conf
->dot11MeshHWMPperrMinInterval
=
1732 nconf
->dot11MeshHWMPperrMinInterval
;
1733 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
1735 conf
->dot11MeshHWMPnetDiameterTraversalTime
=
1736 nconf
->dot11MeshHWMPnetDiameterTraversalTime
;
1737 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE
, mask
)) {
1738 conf
->dot11MeshHWMPRootMode
= nconf
->dot11MeshHWMPRootMode
;
1739 ieee80211_mesh_root_setup(ifmsh
);
1741 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS
, mask
)) {
1742 /* our current gate announcement implementation rides on root
1743 * announcements, so require this ifmsh to also be a root node
1745 if (nconf
->dot11MeshGateAnnouncementProtocol
&&
1746 !(conf
->dot11MeshHWMPRootMode
> IEEE80211_ROOTMODE_ROOT
)) {
1747 conf
->dot11MeshHWMPRootMode
= IEEE80211_PROACTIVE_RANN
;
1748 ieee80211_mesh_root_setup(ifmsh
);
1750 conf
->dot11MeshGateAnnouncementProtocol
=
1751 nconf
->dot11MeshGateAnnouncementProtocol
;
1753 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL
, mask
))
1754 conf
->dot11MeshHWMPRannInterval
=
1755 nconf
->dot11MeshHWMPRannInterval
;
1756 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING
, mask
))
1757 conf
->dot11MeshForwarding
= nconf
->dot11MeshForwarding
;
1758 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD
, mask
)) {
1759 /* our RSSI threshold implementation is supported only for
1760 * devices that report signal in dBm.
1762 if (!(sdata
->local
->hw
.flags
& IEEE80211_HW_SIGNAL_DBM
))
1764 conf
->rssi_threshold
= nconf
->rssi_threshold
;
1766 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE
, mask
)) {
1767 conf
->ht_opmode
= nconf
->ht_opmode
;
1768 sdata
->vif
.bss_conf
.ht_operation_mode
= nconf
->ht_opmode
;
1769 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_HT
);
1771 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
, mask
))
1772 conf
->dot11MeshHWMPactivePathToRootTimeout
=
1773 nconf
->dot11MeshHWMPactivePathToRootTimeout
;
1774 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL
, mask
))
1775 conf
->dot11MeshHWMProotInterval
=
1776 nconf
->dot11MeshHWMProotInterval
;
1777 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
, mask
))
1778 conf
->dot11MeshHWMPconfirmationInterval
=
1779 nconf
->dot11MeshHWMPconfirmationInterval
;
1783 static int ieee80211_join_mesh(struct wiphy
*wiphy
, struct net_device
*dev
,
1784 const struct mesh_config
*conf
,
1785 const struct mesh_setup
*setup
)
1787 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1788 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
1791 memcpy(&ifmsh
->mshcfg
, conf
, sizeof(struct mesh_config
));
1792 err
= copy_mesh_setup(ifmsh
, setup
);
1796 /* can mesh use other SMPS modes? */
1797 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
1798 sdata
->needed_rx_chains
= sdata
->local
->rx_chains
;
1800 err
= ieee80211_vif_use_channel(sdata
, &setup
->chandef
,
1801 IEEE80211_CHANCTX_SHARED
);
1805 ieee80211_start_mesh(sdata
);
1810 static int ieee80211_leave_mesh(struct wiphy
*wiphy
, struct net_device
*dev
)
1812 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1814 ieee80211_stop_mesh(sdata
);
1815 ieee80211_vif_release_channel(sdata
);
1821 static int ieee80211_change_bss(struct wiphy
*wiphy
,
1822 struct net_device
*dev
,
1823 struct bss_parameters
*params
)
1825 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1826 enum ieee80211_band band
;
1829 if (!rtnl_dereference(sdata
->u
.ap
.beacon
))
1832 band
= ieee80211_get_sdata_band(sdata
);
1834 if (params
->use_cts_prot
>= 0) {
1835 sdata
->vif
.bss_conf
.use_cts_prot
= params
->use_cts_prot
;
1836 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
1838 if (params
->use_short_preamble
>= 0) {
1839 sdata
->vif
.bss_conf
.use_short_preamble
=
1840 params
->use_short_preamble
;
1841 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
1844 if (!sdata
->vif
.bss_conf
.use_short_slot
&&
1845 band
== IEEE80211_BAND_5GHZ
) {
1846 sdata
->vif
.bss_conf
.use_short_slot
= true;
1847 changed
|= BSS_CHANGED_ERP_SLOT
;
1850 if (params
->use_short_slot_time
>= 0) {
1851 sdata
->vif
.bss_conf
.use_short_slot
=
1852 params
->use_short_slot_time
;
1853 changed
|= BSS_CHANGED_ERP_SLOT
;
1856 if (params
->basic_rates
) {
1859 struct ieee80211_supported_band
*sband
= wiphy
->bands
[band
];
1861 for (i
= 0; i
< params
->basic_rates_len
; i
++) {
1862 int rate
= (params
->basic_rates
[i
] & 0x7f) * 5;
1863 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1864 if (sband
->bitrates
[j
].bitrate
== rate
)
1868 sdata
->vif
.bss_conf
.basic_rates
= rates
;
1869 changed
|= BSS_CHANGED_BASIC_RATES
;
1872 if (params
->ap_isolate
>= 0) {
1873 if (params
->ap_isolate
)
1874 sdata
->flags
|= IEEE80211_SDATA_DONT_BRIDGE_PACKETS
;
1876 sdata
->flags
&= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS
;
1879 if (params
->ht_opmode
>= 0) {
1880 sdata
->vif
.bss_conf
.ht_operation_mode
=
1881 (u16
) params
->ht_opmode
;
1882 changed
|= BSS_CHANGED_HT
;
1885 if (params
->p2p_ctwindow
>= 0) {
1886 sdata
->vif
.bss_conf
.p2p_ctwindow
= params
->p2p_ctwindow
;
1887 changed
|= BSS_CHANGED_P2P_PS
;
1890 if (params
->p2p_opp_ps
>= 0) {
1891 sdata
->vif
.bss_conf
.p2p_oppps
= params
->p2p_opp_ps
;
1892 changed
|= BSS_CHANGED_P2P_PS
;
1895 ieee80211_bss_info_change_notify(sdata
, changed
);
1900 static int ieee80211_set_txq_params(struct wiphy
*wiphy
,
1901 struct net_device
*dev
,
1902 struct ieee80211_txq_params
*params
)
1904 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1905 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1906 struct ieee80211_tx_queue_params p
;
1908 if (!local
->ops
->conf_tx
)
1911 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
1914 memset(&p
, 0, sizeof(p
));
1915 p
.aifs
= params
->aifs
;
1916 p
.cw_max
= params
->cwmax
;
1917 p
.cw_min
= params
->cwmin
;
1918 p
.txop
= params
->txop
;
1921 * Setting tx queue params disables u-apsd because it's only
1922 * called in master mode.
1926 sdata
->tx_conf
[params
->ac
] = p
;
1927 if (drv_conf_tx(local
, sdata
, params
->ac
, &p
)) {
1928 wiphy_debug(local
->hw
.wiphy
,
1929 "failed to set TX queue parameters for AC %d\n",
1934 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_QOS
);
1940 static int ieee80211_suspend(struct wiphy
*wiphy
,
1941 struct cfg80211_wowlan
*wowlan
)
1943 return __ieee80211_suspend(wiphy_priv(wiphy
), wowlan
);
1946 static int ieee80211_resume(struct wiphy
*wiphy
)
1948 return __ieee80211_resume(wiphy_priv(wiphy
));
1951 #define ieee80211_suspend NULL
1952 #define ieee80211_resume NULL
1955 static int ieee80211_scan(struct wiphy
*wiphy
,
1956 struct cfg80211_scan_request
*req
)
1958 struct ieee80211_sub_if_data
*sdata
;
1960 sdata
= IEEE80211_WDEV_TO_SUB_IF(req
->wdev
);
1962 switch (ieee80211_vif_type_p2p(&sdata
->vif
)) {
1963 case NL80211_IFTYPE_STATION
:
1964 case NL80211_IFTYPE_ADHOC
:
1965 case NL80211_IFTYPE_MESH_POINT
:
1966 case NL80211_IFTYPE_P2P_CLIENT
:
1967 case NL80211_IFTYPE_P2P_DEVICE
:
1969 case NL80211_IFTYPE_P2P_GO
:
1970 if (sdata
->local
->ops
->hw_scan
)
1973 * FIXME: implement NoA while scanning in software,
1974 * for now fall through to allow scanning only when
1975 * beaconing hasn't been configured yet
1977 case NL80211_IFTYPE_AP
:
1979 * If the scan has been forced (and the driver supports
1980 * forcing), don't care about being beaconing already.
1981 * This will create problems to the attached stations (e.g. all
1982 * the frames sent while scanning on other channel will be
1985 if (sdata
->u
.ap
.beacon
&&
1986 (!(wiphy
->features
& NL80211_FEATURE_AP_SCAN
) ||
1987 !(req
->flags
& NL80211_SCAN_FLAG_AP
)))
1994 return ieee80211_request_scan(sdata
, req
);
1998 ieee80211_sched_scan_start(struct wiphy
*wiphy
,
1999 struct net_device
*dev
,
2000 struct cfg80211_sched_scan_request
*req
)
2002 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2004 if (!sdata
->local
->ops
->sched_scan_start
)
2007 return ieee80211_request_sched_scan_start(sdata
, req
);
2011 ieee80211_sched_scan_stop(struct wiphy
*wiphy
, struct net_device
*dev
)
2013 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2015 if (!sdata
->local
->ops
->sched_scan_stop
)
2018 return ieee80211_request_sched_scan_stop(sdata
);
2021 static int ieee80211_auth(struct wiphy
*wiphy
, struct net_device
*dev
,
2022 struct cfg80211_auth_request
*req
)
2024 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
2027 static int ieee80211_assoc(struct wiphy
*wiphy
, struct net_device
*dev
,
2028 struct cfg80211_assoc_request
*req
)
2030 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
2033 static int ieee80211_deauth(struct wiphy
*wiphy
, struct net_device
*dev
,
2034 struct cfg80211_deauth_request
*req
)
2036 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
2039 static int ieee80211_disassoc(struct wiphy
*wiphy
, struct net_device
*dev
,
2040 struct cfg80211_disassoc_request
*req
)
2042 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
2045 static int ieee80211_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
2046 struct cfg80211_ibss_params
*params
)
2048 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev
), params
);
2051 static int ieee80211_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
2053 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev
));
2056 static int ieee80211_set_mcast_rate(struct wiphy
*wiphy
, struct net_device
*dev
,
2057 int rate
[IEEE80211_NUM_BANDS
])
2059 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2061 memcpy(sdata
->vif
.bss_conf
.mcast_rate
, rate
,
2062 sizeof(int) * IEEE80211_NUM_BANDS
);
2067 static int ieee80211_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
2069 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2072 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
2073 err
= drv_set_frag_threshold(local
, wiphy
->frag_threshold
);
2079 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
) {
2080 err
= drv_set_coverage_class(local
, wiphy
->coverage_class
);
2086 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
2087 err
= drv_set_rts_threshold(local
, wiphy
->rts_threshold
);
2093 if (changed
& WIPHY_PARAM_RETRY_SHORT
) {
2094 if (wiphy
->retry_short
> IEEE80211_MAX_TX_RETRY
)
2096 local
->hw
.conf
.short_frame_max_tx_count
= wiphy
->retry_short
;
2098 if (changed
& WIPHY_PARAM_RETRY_LONG
) {
2099 if (wiphy
->retry_long
> IEEE80211_MAX_TX_RETRY
)
2101 local
->hw
.conf
.long_frame_max_tx_count
= wiphy
->retry_long
;
2104 (WIPHY_PARAM_RETRY_SHORT
| WIPHY_PARAM_RETRY_LONG
))
2105 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_RETRY_LIMITS
);
2110 static int ieee80211_set_tx_power(struct wiphy
*wiphy
,
2111 struct wireless_dev
*wdev
,
2112 enum nl80211_tx_power_setting type
, int mbm
)
2114 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2115 struct ieee80211_sub_if_data
*sdata
;
2118 sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2121 case NL80211_TX_POWER_AUTOMATIC
:
2122 sdata
->user_power_level
= IEEE80211_UNSET_POWER_LEVEL
;
2124 case NL80211_TX_POWER_LIMITED
:
2125 case NL80211_TX_POWER_FIXED
:
2126 if (mbm
< 0 || (mbm
% 100))
2128 sdata
->user_power_level
= MBM_TO_DBM(mbm
);
2132 ieee80211_recalc_txpower(sdata
);
2138 case NL80211_TX_POWER_AUTOMATIC
:
2139 local
->user_power_level
= IEEE80211_UNSET_POWER_LEVEL
;
2141 case NL80211_TX_POWER_LIMITED
:
2142 case NL80211_TX_POWER_FIXED
:
2143 if (mbm
< 0 || (mbm
% 100))
2145 local
->user_power_level
= MBM_TO_DBM(mbm
);
2149 mutex_lock(&local
->iflist_mtx
);
2150 list_for_each_entry(sdata
, &local
->interfaces
, list
)
2151 sdata
->user_power_level
= local
->user_power_level
;
2152 list_for_each_entry(sdata
, &local
->interfaces
, list
)
2153 ieee80211_recalc_txpower(sdata
);
2154 mutex_unlock(&local
->iflist_mtx
);
2159 static int ieee80211_get_tx_power(struct wiphy
*wiphy
,
2160 struct wireless_dev
*wdev
,
2163 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2164 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2166 if (!local
->use_chanctx
)
2167 *dbm
= local
->hw
.conf
.power_level
;
2169 *dbm
= sdata
->vif
.bss_conf
.txpower
;
2174 static int ieee80211_set_wds_peer(struct wiphy
*wiphy
, struct net_device
*dev
,
2177 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2179 memcpy(&sdata
->u
.wds
.remote_addr
, addr
, ETH_ALEN
);
2184 static void ieee80211_rfkill_poll(struct wiphy
*wiphy
)
2186 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2188 drv_rfkill_poll(local
);
2191 #ifdef CONFIG_NL80211_TESTMODE
2192 static int ieee80211_testmode_cmd(struct wiphy
*wiphy
, void *data
, int len
)
2194 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2196 if (!local
->ops
->testmode_cmd
)
2199 return local
->ops
->testmode_cmd(&local
->hw
, data
, len
);
2202 static int ieee80211_testmode_dump(struct wiphy
*wiphy
,
2203 struct sk_buff
*skb
,
2204 struct netlink_callback
*cb
,
2205 void *data
, int len
)
2207 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2209 if (!local
->ops
->testmode_dump
)
2212 return local
->ops
->testmode_dump(&local
->hw
, skb
, cb
, data
, len
);
2216 int __ieee80211_request_smps(struct ieee80211_sub_if_data
*sdata
,
2217 enum ieee80211_smps_mode smps_mode
)
2220 enum ieee80211_smps_mode old_req
;
2223 lockdep_assert_held(&sdata
->u
.mgd
.mtx
);
2225 old_req
= sdata
->u
.mgd
.req_smps
;
2226 sdata
->u
.mgd
.req_smps
= smps_mode
;
2228 if (old_req
== smps_mode
&&
2229 smps_mode
!= IEEE80211_SMPS_AUTOMATIC
)
2233 * If not associated, or current association is not an HT
2234 * association, there's no need to do anything, just store
2235 * the new value until we associate.
2237 if (!sdata
->u
.mgd
.associated
||
2238 sdata
->vif
.bss_conf
.chandef
.width
== NL80211_CHAN_WIDTH_20_NOHT
)
2241 ap
= sdata
->u
.mgd
.associated
->bssid
;
2243 if (smps_mode
== IEEE80211_SMPS_AUTOMATIC
) {
2244 if (sdata
->u
.mgd
.powersave
)
2245 smps_mode
= IEEE80211_SMPS_DYNAMIC
;
2247 smps_mode
= IEEE80211_SMPS_OFF
;
2250 /* send SM PS frame to AP */
2251 err
= ieee80211_send_smps_action(sdata
, smps_mode
,
2254 sdata
->u
.mgd
.req_smps
= old_req
;
2259 static int ieee80211_set_power_mgmt(struct wiphy
*wiphy
, struct net_device
*dev
,
2260 bool enabled
, int timeout
)
2262 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2263 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2265 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
&&
2266 sdata
->vif
.type
!= NL80211_IFTYPE_MESH_POINT
)
2269 if (!(local
->hw
.flags
& IEEE80211_HW_SUPPORTS_PS
))
2272 if (enabled
== sdata
->u
.mgd
.powersave
&&
2273 timeout
== local
->dynamic_ps_forced_timeout
)
2276 sdata
->u
.mgd
.powersave
= enabled
;
2277 local
->dynamic_ps_forced_timeout
= timeout
;
2279 /* no change, but if automatic follow powersave */
2280 mutex_lock(&sdata
->u
.mgd
.mtx
);
2281 __ieee80211_request_smps(sdata
, sdata
->u
.mgd
.req_smps
);
2282 mutex_unlock(&sdata
->u
.mgd
.mtx
);
2284 if (local
->hw
.flags
& IEEE80211_HW_SUPPORTS_DYNAMIC_PS
)
2285 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
2287 ieee80211_recalc_ps(local
, -1);
2288 ieee80211_recalc_ps_vif(sdata
);
2293 static int ieee80211_set_cqm_rssi_config(struct wiphy
*wiphy
,
2294 struct net_device
*dev
,
2295 s32 rssi_thold
, u32 rssi_hyst
)
2297 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2298 struct ieee80211_vif
*vif
= &sdata
->vif
;
2299 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
2301 if (rssi_thold
== bss_conf
->cqm_rssi_thold
&&
2302 rssi_hyst
== bss_conf
->cqm_rssi_hyst
)
2305 bss_conf
->cqm_rssi_thold
= rssi_thold
;
2306 bss_conf
->cqm_rssi_hyst
= rssi_hyst
;
2308 /* tell the driver upon association, unless already associated */
2309 if (sdata
->u
.mgd
.associated
&&
2310 sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
)
2311 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_CQM
);
2316 static int ieee80211_set_bitrate_mask(struct wiphy
*wiphy
,
2317 struct net_device
*dev
,
2319 const struct cfg80211_bitrate_mask
*mask
)
2321 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2322 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2325 if (!ieee80211_sdata_running(sdata
))
2328 if (local
->hw
.flags
& IEEE80211_HW_HAS_RATE_CONTROL
) {
2329 ret
= drv_set_bitrate_mask(local
, sdata
, mask
);
2334 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
2335 sdata
->rc_rateidx_mask
[i
] = mask
->control
[i
].legacy
;
2336 memcpy(sdata
->rc_rateidx_mcs_mask
[i
], mask
->control
[i
].mcs
,
2337 sizeof(mask
->control
[i
].mcs
));
2343 static int ieee80211_start_roc_work(struct ieee80211_local
*local
,
2344 struct ieee80211_sub_if_data
*sdata
,
2345 struct ieee80211_channel
*channel
,
2346 unsigned int duration
, u64
*cookie
,
2347 struct sk_buff
*txskb
)
2349 struct ieee80211_roc_work
*roc
, *tmp
;
2350 bool queued
= false;
2353 lockdep_assert_held(&local
->mtx
);
2355 if (local
->use_chanctx
&& !local
->ops
->remain_on_channel
)
2358 roc
= kzalloc(sizeof(*roc
), GFP_KERNEL
);
2362 roc
->chan
= channel
;
2363 roc
->duration
= duration
;
2364 roc
->req_duration
= duration
;
2366 roc
->mgmt_tx_cookie
= (unsigned long)txskb
;
2368 INIT_DELAYED_WORK(&roc
->work
, ieee80211_sw_roc_work
);
2369 INIT_LIST_HEAD(&roc
->dependents
);
2371 /* if there's one pending or we're scanning, queue this one */
2372 if (!list_empty(&local
->roc_list
) || local
->scanning
)
2373 goto out_check_combine
;
2375 /* if not HW assist, just queue & schedule work */
2376 if (!local
->ops
->remain_on_channel
) {
2377 ieee80211_queue_delayed_work(&local
->hw
, &roc
->work
, 0);
2381 /* otherwise actually kick it off here (for error handling) */
2384 * If the duration is zero, then the driver
2385 * wouldn't actually do anything. Set it to
2388 * TODO: cancel the off-channel operation
2389 * when we get the SKB's TX status and
2390 * the wait time was zero before.
2395 ret
= drv_remain_on_channel(local
, sdata
, channel
, duration
);
2401 roc
->started
= true;
2405 list_for_each_entry(tmp
, &local
->roc_list
, list
) {
2406 if (tmp
->chan
!= channel
|| tmp
->sdata
!= sdata
)
2410 * Extend this ROC if possible:
2412 * If it hasn't started yet, just increase the duration
2413 * and add the new one to the list of dependents.
2415 if (!tmp
->started
) {
2416 list_add_tail(&roc
->list
, &tmp
->dependents
);
2417 tmp
->duration
= max(tmp
->duration
, roc
->duration
);
2422 /* If it has already started, it's more difficult ... */
2423 if (local
->ops
->remain_on_channel
) {
2424 unsigned long j
= jiffies
;
2427 * In the offloaded ROC case, if it hasn't begun, add
2428 * this new one to the dependent list to be handled
2429 * when the the master one begins. If it has begun,
2430 * check that there's still a minimum time left and
2431 * if so, start this one, transmitting the frame, but
2432 * add it to the list directly after this one with a
2433 * a reduced time so we'll ask the driver to execute
2434 * it right after finishing the previous one, in the
2435 * hope that it'll also be executed right afterwards,
2436 * effectively extending the old one.
2437 * If there's no minimum time left, just add it to the
2440 if (!tmp
->hw_begun
) {
2441 list_add_tail(&roc
->list
, &tmp
->dependents
);
2446 if (time_before(j
+ IEEE80211_ROC_MIN_LEFT
,
2447 tmp
->hw_start_time
+
2448 msecs_to_jiffies(tmp
->duration
))) {
2451 ieee80211_handle_roc_started(roc
);
2453 new_dur
= roc
->duration
-
2454 jiffies_to_msecs(tmp
->hw_start_time
+
2460 /* add right after tmp */
2461 list_add(&roc
->list
, &tmp
->list
);
2463 list_add_tail(&roc
->list
,
2468 } else if (del_timer_sync(&tmp
->work
.timer
)) {
2469 unsigned long new_end
;
2472 * In the software ROC case, cancel the timer, if
2473 * that fails then the finish work is already
2474 * queued/pending and thus we queue the new ROC
2475 * normally, if that succeeds then we can extend
2476 * the timer duration and TX the frame (if any.)
2479 list_add_tail(&roc
->list
, &tmp
->dependents
);
2482 new_end
= jiffies
+ msecs_to_jiffies(roc
->duration
);
2484 /* ok, it was started & we canceled timer */
2485 if (time_after(new_end
, tmp
->work
.timer
.expires
))
2486 mod_timer(&tmp
->work
.timer
, new_end
);
2488 add_timer(&tmp
->work
.timer
);
2490 ieee80211_handle_roc_started(roc
);
2497 list_add_tail(&roc
->list
, &local
->roc_list
);
2500 * cookie is either the roc cookie (for normal roc)
2501 * or the SKB (for mgmt TX)
2504 /* local->mtx protects this */
2505 local
->roc_cookie_counter
++;
2506 roc
->cookie
= local
->roc_cookie_counter
;
2507 /* wow, you wrapped 64 bits ... more likely a bug */
2508 if (WARN_ON(roc
->cookie
== 0)) {
2510 local
->roc_cookie_counter
++;
2512 *cookie
= roc
->cookie
;
2514 *cookie
= (unsigned long)txskb
;
2520 static int ieee80211_remain_on_channel(struct wiphy
*wiphy
,
2521 struct wireless_dev
*wdev
,
2522 struct ieee80211_channel
*chan
,
2523 unsigned int duration
,
2526 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2527 struct ieee80211_local
*local
= sdata
->local
;
2530 mutex_lock(&local
->mtx
);
2531 ret
= ieee80211_start_roc_work(local
, sdata
, chan
,
2532 duration
, cookie
, NULL
);
2533 mutex_unlock(&local
->mtx
);
2538 static int ieee80211_cancel_roc(struct ieee80211_local
*local
,
2539 u64 cookie
, bool mgmt_tx
)
2541 struct ieee80211_roc_work
*roc
, *tmp
, *found
= NULL
;
2544 mutex_lock(&local
->mtx
);
2545 list_for_each_entry_safe(roc
, tmp
, &local
->roc_list
, list
) {
2546 struct ieee80211_roc_work
*dep
, *tmp2
;
2548 list_for_each_entry_safe(dep
, tmp2
, &roc
->dependents
, list
) {
2549 if (!mgmt_tx
&& dep
->cookie
!= cookie
)
2551 else if (mgmt_tx
&& dep
->mgmt_tx_cookie
!= cookie
)
2553 /* found dependent item -- just remove it */
2554 list_del(&dep
->list
);
2555 mutex_unlock(&local
->mtx
);
2557 ieee80211_roc_notify_destroy(dep
);
2561 if (!mgmt_tx
&& roc
->cookie
!= cookie
)
2563 else if (mgmt_tx
&& roc
->mgmt_tx_cookie
!= cookie
)
2571 mutex_unlock(&local
->mtx
);
2576 * We found the item to cancel, so do that. Note that it
2577 * may have dependents, which we also cancel (and send
2578 * the expired signal for.) Not doing so would be quite
2579 * tricky here, but we may need to fix it later.
2582 if (local
->ops
->remain_on_channel
) {
2583 if (found
->started
) {
2584 ret
= drv_cancel_remain_on_channel(local
);
2585 if (WARN_ON_ONCE(ret
)) {
2586 mutex_unlock(&local
->mtx
);
2591 list_del(&found
->list
);
2594 ieee80211_start_next_roc(local
);
2595 mutex_unlock(&local
->mtx
);
2597 ieee80211_roc_notify_destroy(found
);
2599 /* work may be pending so use it all the time */
2600 found
->abort
= true;
2601 ieee80211_queue_delayed_work(&local
->hw
, &found
->work
, 0);
2603 mutex_unlock(&local
->mtx
);
2605 /* work will clean up etc */
2606 flush_delayed_work(&found
->work
);
2612 static int ieee80211_cancel_remain_on_channel(struct wiphy
*wiphy
,
2613 struct wireless_dev
*wdev
,
2616 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2617 struct ieee80211_local
*local
= sdata
->local
;
2619 return ieee80211_cancel_roc(local
, cookie
, false);
2622 static int ieee80211_mgmt_tx(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
2623 struct ieee80211_channel
*chan
, bool offchan
,
2624 unsigned int wait
, const u8
*buf
, size_t len
,
2625 bool no_cck
, bool dont_wait_for_ack
, u64
*cookie
)
2627 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2628 struct ieee80211_local
*local
= sdata
->local
;
2629 struct sk_buff
*skb
;
2630 struct sta_info
*sta
;
2631 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
2632 bool need_offchan
= false;
2636 if (dont_wait_for_ack
)
2637 flags
= IEEE80211_TX_CTL_NO_ACK
;
2639 flags
= IEEE80211_TX_INTFL_NL80211_FRAME_TX
|
2640 IEEE80211_TX_CTL_REQ_TX_STATUS
;
2643 flags
|= IEEE80211_TX_CTL_NO_CCK_RATE
;
2645 switch (sdata
->vif
.type
) {
2646 case NL80211_IFTYPE_ADHOC
:
2647 if (!sdata
->vif
.bss_conf
.ibss_joined
)
2648 need_offchan
= true;
2650 #ifdef CONFIG_MAC80211_MESH
2651 case NL80211_IFTYPE_MESH_POINT
:
2652 if (ieee80211_vif_is_mesh(&sdata
->vif
) &&
2653 !sdata
->u
.mesh
.mesh_id_len
)
2654 need_offchan
= true;
2657 case NL80211_IFTYPE_AP
:
2658 case NL80211_IFTYPE_AP_VLAN
:
2659 case NL80211_IFTYPE_P2P_GO
:
2660 if (sdata
->vif
.type
!= NL80211_IFTYPE_ADHOC
&&
2661 !ieee80211_vif_is_mesh(&sdata
->vif
) &&
2662 !rcu_access_pointer(sdata
->bss
->beacon
))
2663 need_offchan
= true;
2664 if (!ieee80211_is_action(mgmt
->frame_control
) ||
2665 mgmt
->u
.action
.category
== WLAN_CATEGORY_PUBLIC
)
2668 sta
= sta_info_get(sdata
, mgmt
->da
);
2673 case NL80211_IFTYPE_STATION
:
2674 case NL80211_IFTYPE_P2P_CLIENT
:
2675 if (!sdata
->u
.mgd
.associated
)
2676 need_offchan
= true;
2678 case NL80211_IFTYPE_P2P_DEVICE
:
2679 need_offchan
= true;
2685 mutex_lock(&local
->mtx
);
2687 /* Check if the operating channel is the requested channel */
2688 if (!need_offchan
) {
2689 struct ieee80211_chanctx_conf
*chanctx_conf
;
2692 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2695 need_offchan
= chan
!= chanctx_conf
->def
.chan
;
2697 need_offchan
= true;
2701 if (need_offchan
&& !offchan
) {
2706 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ len
);
2711 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2713 memcpy(skb_put(skb
, len
), buf
, len
);
2715 IEEE80211_SKB_CB(skb
)->flags
= flags
;
2717 skb
->dev
= sdata
->dev
;
2719 if (!need_offchan
) {
2720 *cookie
= (unsigned long) skb
;
2721 ieee80211_tx_skb(sdata
, skb
);
2726 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_TX_OFFCHAN
;
2727 if (local
->hw
.flags
& IEEE80211_HW_QUEUE_CONTROL
)
2728 IEEE80211_SKB_CB(skb
)->hw_queue
=
2729 local
->hw
.offchannel_tx_hw_queue
;
2731 /* This will handle all kinds of coalescing and immediate TX */
2732 ret
= ieee80211_start_roc_work(local
, sdata
, chan
,
2737 mutex_unlock(&local
->mtx
);
2741 static int ieee80211_mgmt_tx_cancel_wait(struct wiphy
*wiphy
,
2742 struct wireless_dev
*wdev
,
2745 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2747 return ieee80211_cancel_roc(local
, cookie
, true);
2750 static void ieee80211_mgmt_frame_register(struct wiphy
*wiphy
,
2751 struct wireless_dev
*wdev
,
2752 u16 frame_type
, bool reg
)
2754 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2755 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2757 switch (frame_type
) {
2758 case IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_AUTH
:
2759 if (sdata
->vif
.type
== NL80211_IFTYPE_ADHOC
) {
2760 struct ieee80211_if_ibss
*ifibss
= &sdata
->u
.ibss
;
2763 ifibss
->auth_frame_registrations
++;
2765 ifibss
->auth_frame_registrations
--;
2768 case IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_PROBE_REQ
:
2770 local
->probe_req_reg
++;
2772 local
->probe_req_reg
--;
2774 if (!local
->open_count
)
2777 ieee80211_queue_work(&local
->hw
, &local
->reconfig_filter
);
2784 static int ieee80211_set_antenna(struct wiphy
*wiphy
, u32 tx_ant
, u32 rx_ant
)
2786 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2791 return drv_set_antenna(local
, tx_ant
, rx_ant
);
2794 static int ieee80211_get_antenna(struct wiphy
*wiphy
, u32
*tx_ant
, u32
*rx_ant
)
2796 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2798 return drv_get_antenna(local
, tx_ant
, rx_ant
);
2801 static int ieee80211_set_ringparam(struct wiphy
*wiphy
, u32 tx
, u32 rx
)
2803 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2805 return drv_set_ringparam(local
, tx
, rx
);
2808 static void ieee80211_get_ringparam(struct wiphy
*wiphy
,
2809 u32
*tx
, u32
*tx_max
, u32
*rx
, u32
*rx_max
)
2811 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2813 drv_get_ringparam(local
, tx
, tx_max
, rx
, rx_max
);
2816 static int ieee80211_set_rekey_data(struct wiphy
*wiphy
,
2817 struct net_device
*dev
,
2818 struct cfg80211_gtk_rekey_data
*data
)
2820 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2821 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2823 if (!local
->ops
->set_rekey_data
)
2826 drv_set_rekey_data(local
, sdata
, data
);
2831 static void ieee80211_tdls_add_ext_capab(struct sk_buff
*skb
)
2833 u8
*pos
= (void *)skb_put(skb
, 7);
2835 *pos
++ = WLAN_EID_EXT_CAPABILITY
;
2836 *pos
++ = 5; /* len */
2841 *pos
++ = WLAN_EXT_CAPA5_TDLS_ENABLED
;
2844 static u16
ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data
*sdata
)
2846 struct ieee80211_local
*local
= sdata
->local
;
2850 if (ieee80211_get_sdata_band(sdata
) != IEEE80211_BAND_2GHZ
)
2853 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
))
2854 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
2855 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
))
2856 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
2861 static void ieee80211_tdls_add_link_ie(struct sk_buff
*skb
, u8
*src_addr
,
2862 u8
*peer
, u8
*bssid
)
2864 struct ieee80211_tdls_lnkie
*lnkid
;
2866 lnkid
= (void *)skb_put(skb
, sizeof(struct ieee80211_tdls_lnkie
));
2868 lnkid
->ie_type
= WLAN_EID_LINK_ID
;
2869 lnkid
->ie_len
= sizeof(struct ieee80211_tdls_lnkie
) - 2;
2871 memcpy(lnkid
->bssid
, bssid
, ETH_ALEN
);
2872 memcpy(lnkid
->init_sta
, src_addr
, ETH_ALEN
);
2873 memcpy(lnkid
->resp_sta
, peer
, ETH_ALEN
);
2877 ieee80211_prep_tdls_encap_data(struct wiphy
*wiphy
, struct net_device
*dev
,
2878 u8
*peer
, u8 action_code
, u8 dialog_token
,
2879 u16 status_code
, struct sk_buff
*skb
)
2881 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2882 enum ieee80211_band band
= ieee80211_get_sdata_band(sdata
);
2883 struct ieee80211_tdls_data
*tf
;
2885 tf
= (void *)skb_put(skb
, offsetof(struct ieee80211_tdls_data
, u
));
2887 memcpy(tf
->da
, peer
, ETH_ALEN
);
2888 memcpy(tf
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
2889 tf
->ether_type
= cpu_to_be16(ETH_P_TDLS
);
2890 tf
->payload_type
= WLAN_TDLS_SNAP_RFTYPE
;
2892 switch (action_code
) {
2893 case WLAN_TDLS_SETUP_REQUEST
:
2894 tf
->category
= WLAN_CATEGORY_TDLS
;
2895 tf
->action_code
= WLAN_TDLS_SETUP_REQUEST
;
2897 skb_put(skb
, sizeof(tf
->u
.setup_req
));
2898 tf
->u
.setup_req
.dialog_token
= dialog_token
;
2899 tf
->u
.setup_req
.capability
=
2900 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata
));
2902 ieee80211_add_srates_ie(sdata
, skb
, false, band
);
2903 ieee80211_add_ext_srates_ie(sdata
, skb
, false, band
);
2904 ieee80211_tdls_add_ext_capab(skb
);
2906 case WLAN_TDLS_SETUP_RESPONSE
:
2907 tf
->category
= WLAN_CATEGORY_TDLS
;
2908 tf
->action_code
= WLAN_TDLS_SETUP_RESPONSE
;
2910 skb_put(skb
, sizeof(tf
->u
.setup_resp
));
2911 tf
->u
.setup_resp
.status_code
= cpu_to_le16(status_code
);
2912 tf
->u
.setup_resp
.dialog_token
= dialog_token
;
2913 tf
->u
.setup_resp
.capability
=
2914 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata
));
2916 ieee80211_add_srates_ie(sdata
, skb
, false, band
);
2917 ieee80211_add_ext_srates_ie(sdata
, skb
, false, band
);
2918 ieee80211_tdls_add_ext_capab(skb
);
2920 case WLAN_TDLS_SETUP_CONFIRM
:
2921 tf
->category
= WLAN_CATEGORY_TDLS
;
2922 tf
->action_code
= WLAN_TDLS_SETUP_CONFIRM
;
2924 skb_put(skb
, sizeof(tf
->u
.setup_cfm
));
2925 tf
->u
.setup_cfm
.status_code
= cpu_to_le16(status_code
);
2926 tf
->u
.setup_cfm
.dialog_token
= dialog_token
;
2928 case WLAN_TDLS_TEARDOWN
:
2929 tf
->category
= WLAN_CATEGORY_TDLS
;
2930 tf
->action_code
= WLAN_TDLS_TEARDOWN
;
2932 skb_put(skb
, sizeof(tf
->u
.teardown
));
2933 tf
->u
.teardown
.reason_code
= cpu_to_le16(status_code
);
2935 case WLAN_TDLS_DISCOVERY_REQUEST
:
2936 tf
->category
= WLAN_CATEGORY_TDLS
;
2937 tf
->action_code
= WLAN_TDLS_DISCOVERY_REQUEST
;
2939 skb_put(skb
, sizeof(tf
->u
.discover_req
));
2940 tf
->u
.discover_req
.dialog_token
= dialog_token
;
2950 ieee80211_prep_tdls_direct(struct wiphy
*wiphy
, struct net_device
*dev
,
2951 u8
*peer
, u8 action_code
, u8 dialog_token
,
2952 u16 status_code
, struct sk_buff
*skb
)
2954 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2955 enum ieee80211_band band
= ieee80211_get_sdata_band(sdata
);
2956 struct ieee80211_mgmt
*mgmt
;
2958 mgmt
= (void *)skb_put(skb
, 24);
2959 memset(mgmt
, 0, 24);
2960 memcpy(mgmt
->da
, peer
, ETH_ALEN
);
2961 memcpy(mgmt
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
2962 memcpy(mgmt
->bssid
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2964 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
2965 IEEE80211_STYPE_ACTION
);
2967 switch (action_code
) {
2968 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
2969 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.tdls_discover_resp
));
2970 mgmt
->u
.action
.category
= WLAN_CATEGORY_PUBLIC
;
2971 mgmt
->u
.action
.u
.tdls_discover_resp
.action_code
=
2972 WLAN_PUB_ACTION_TDLS_DISCOVER_RES
;
2973 mgmt
->u
.action
.u
.tdls_discover_resp
.dialog_token
=
2975 mgmt
->u
.action
.u
.tdls_discover_resp
.capability
=
2976 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata
));
2978 ieee80211_add_srates_ie(sdata
, skb
, false, band
);
2979 ieee80211_add_ext_srates_ie(sdata
, skb
, false, band
);
2980 ieee80211_tdls_add_ext_capab(skb
);
2989 static int ieee80211_tdls_mgmt(struct wiphy
*wiphy
, struct net_device
*dev
,
2990 u8
*peer
, u8 action_code
, u8 dialog_token
,
2991 u16 status_code
, const u8
*extra_ies
,
2992 size_t extra_ies_len
)
2994 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2995 struct ieee80211_local
*local
= sdata
->local
;
2996 struct sk_buff
*skb
= NULL
;
3000 if (!(wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3003 /* make sure we are in managed mode, and associated */
3004 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
||
3005 !sdata
->u
.mgd
.associated
)
3008 tdls_dbg(sdata
, "TDLS mgmt action %d peer %pM\n",
3011 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
3012 max(sizeof(struct ieee80211_mgmt
),
3013 sizeof(struct ieee80211_tdls_data
)) +
3014 50 + /* supported rates */
3017 sizeof(struct ieee80211_tdls_lnkie
));
3021 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3023 switch (action_code
) {
3024 case WLAN_TDLS_SETUP_REQUEST
:
3025 case WLAN_TDLS_SETUP_RESPONSE
:
3026 case WLAN_TDLS_SETUP_CONFIRM
:
3027 case WLAN_TDLS_TEARDOWN
:
3028 case WLAN_TDLS_DISCOVERY_REQUEST
:
3029 ret
= ieee80211_prep_tdls_encap_data(wiphy
, dev
, peer
,
3030 action_code
, dialog_token
,
3032 send_direct
= false;
3034 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
3035 ret
= ieee80211_prep_tdls_direct(wiphy
, dev
, peer
, action_code
,
3036 dialog_token
, status_code
,
3049 memcpy(skb_put(skb
, extra_ies_len
), extra_ies
, extra_ies_len
);
3051 /* the TDLS link IE is always added last */
3052 switch (action_code
) {
3053 case WLAN_TDLS_SETUP_REQUEST
:
3054 case WLAN_TDLS_SETUP_CONFIRM
:
3055 case WLAN_TDLS_TEARDOWN
:
3056 case WLAN_TDLS_DISCOVERY_REQUEST
:
3057 /* we are the initiator */
3058 ieee80211_tdls_add_link_ie(skb
, sdata
->vif
.addr
, peer
,
3059 sdata
->u
.mgd
.bssid
);
3061 case WLAN_TDLS_SETUP_RESPONSE
:
3062 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
3063 /* we are the responder */
3064 ieee80211_tdls_add_link_ie(skb
, peer
, sdata
->vif
.addr
,
3065 sdata
->u
.mgd
.bssid
);
3073 ieee80211_tx_skb(sdata
, skb
);
3078 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3079 * we should default to AC_VI.
3081 switch (action_code
) {
3082 case WLAN_TDLS_SETUP_REQUEST
:
3083 case WLAN_TDLS_SETUP_RESPONSE
:
3084 skb_set_queue_mapping(skb
, IEEE80211_AC_BK
);
3088 skb_set_queue_mapping(skb
, IEEE80211_AC_VI
);
3093 /* disable bottom halves when entering the Tx path */
3095 ret
= ieee80211_subif_start_xmit(skb
, dev
);
3105 static int ieee80211_tdls_oper(struct wiphy
*wiphy
, struct net_device
*dev
,
3106 u8
*peer
, enum nl80211_tdls_operation oper
)
3108 struct sta_info
*sta
;
3109 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3111 if (!(wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3114 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3117 tdls_dbg(sdata
, "TDLS oper %d peer %pM\n", oper
, peer
);
3120 case NL80211_TDLS_ENABLE_LINK
:
3122 sta
= sta_info_get(sdata
, peer
);
3128 set_sta_flag(sta
, WLAN_STA_TDLS_PEER_AUTH
);
3131 case NL80211_TDLS_DISABLE_LINK
:
3132 return sta_info_destroy_addr(sdata
, peer
);
3133 case NL80211_TDLS_TEARDOWN
:
3134 case NL80211_TDLS_SETUP
:
3135 case NL80211_TDLS_DISCOVERY_REQ
:
3136 /* We don't support in-driver setup/teardown/discovery */
3145 static int ieee80211_probe_client(struct wiphy
*wiphy
, struct net_device
*dev
,
3146 const u8
*peer
, u64
*cookie
)
3148 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3149 struct ieee80211_local
*local
= sdata
->local
;
3150 struct ieee80211_qos_hdr
*nullfunc
;
3151 struct sk_buff
*skb
;
3152 int size
= sizeof(*nullfunc
);
3155 struct ieee80211_tx_info
*info
;
3156 struct sta_info
*sta
;
3157 struct ieee80211_chanctx_conf
*chanctx_conf
;
3158 enum ieee80211_band band
;
3161 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
3162 if (WARN_ON(!chanctx_conf
)) {
3166 band
= chanctx_conf
->def
.chan
->band
;
3167 sta
= sta_info_get(sdata
, peer
);
3169 qos
= test_sta_flag(sta
, WLAN_STA_WME
);
3176 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
3177 IEEE80211_STYPE_QOS_NULLFUNC
|
3178 IEEE80211_FCTL_FROMDS
);
3181 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
3182 IEEE80211_STYPE_NULLFUNC
|
3183 IEEE80211_FCTL_FROMDS
);
3186 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ size
);
3194 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3196 nullfunc
= (void *) skb_put(skb
, size
);
3197 nullfunc
->frame_control
= fc
;
3198 nullfunc
->duration_id
= 0;
3199 memcpy(nullfunc
->addr1
, sta
->sta
.addr
, ETH_ALEN
);
3200 memcpy(nullfunc
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
3201 memcpy(nullfunc
->addr3
, sdata
->vif
.addr
, ETH_ALEN
);
3202 nullfunc
->seq_ctrl
= 0;
3204 info
= IEEE80211_SKB_CB(skb
);
3206 info
->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
|
3207 IEEE80211_TX_INTFL_NL80211_FRAME_TX
;
3209 skb_set_queue_mapping(skb
, IEEE80211_AC_VO
);
3212 nullfunc
->qos_ctrl
= cpu_to_le16(7);
3215 ieee80211_xmit(sdata
, skb
, band
);
3219 *cookie
= (unsigned long) skb
;
3223 static int ieee80211_cfg_get_channel(struct wiphy
*wiphy
,
3224 struct wireless_dev
*wdev
,
3225 struct cfg80211_chan_def
*chandef
)
3227 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
3228 struct ieee80211_chanctx_conf
*chanctx_conf
;
3232 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
3234 *chandef
= chanctx_conf
->def
;
3243 static void ieee80211_set_wakeup(struct wiphy
*wiphy
, bool enabled
)
3245 drv_set_wakeup(wiphy_priv(wiphy
), enabled
);
3249 struct cfg80211_ops mac80211_config_ops
= {
3250 .add_virtual_intf
= ieee80211_add_iface
,
3251 .del_virtual_intf
= ieee80211_del_iface
,
3252 .change_virtual_intf
= ieee80211_change_iface
,
3253 .start_p2p_device
= ieee80211_start_p2p_device
,
3254 .stop_p2p_device
= ieee80211_stop_p2p_device
,
3255 .add_key
= ieee80211_add_key
,
3256 .del_key
= ieee80211_del_key
,
3257 .get_key
= ieee80211_get_key
,
3258 .set_default_key
= ieee80211_config_default_key
,
3259 .set_default_mgmt_key
= ieee80211_config_default_mgmt_key
,
3260 .start_ap
= ieee80211_start_ap
,
3261 .change_beacon
= ieee80211_change_beacon
,
3262 .stop_ap
= ieee80211_stop_ap
,
3263 .add_station
= ieee80211_add_station
,
3264 .del_station
= ieee80211_del_station
,
3265 .change_station
= ieee80211_change_station
,
3266 .get_station
= ieee80211_get_station
,
3267 .dump_station
= ieee80211_dump_station
,
3268 .dump_survey
= ieee80211_dump_survey
,
3269 #ifdef CONFIG_MAC80211_MESH
3270 .add_mpath
= ieee80211_add_mpath
,
3271 .del_mpath
= ieee80211_del_mpath
,
3272 .change_mpath
= ieee80211_change_mpath
,
3273 .get_mpath
= ieee80211_get_mpath
,
3274 .dump_mpath
= ieee80211_dump_mpath
,
3275 .update_mesh_config
= ieee80211_update_mesh_config
,
3276 .get_mesh_config
= ieee80211_get_mesh_config
,
3277 .join_mesh
= ieee80211_join_mesh
,
3278 .leave_mesh
= ieee80211_leave_mesh
,
3280 .change_bss
= ieee80211_change_bss
,
3281 .set_txq_params
= ieee80211_set_txq_params
,
3282 .set_monitor_channel
= ieee80211_set_monitor_channel
,
3283 .suspend
= ieee80211_suspend
,
3284 .resume
= ieee80211_resume
,
3285 .scan
= ieee80211_scan
,
3286 .sched_scan_start
= ieee80211_sched_scan_start
,
3287 .sched_scan_stop
= ieee80211_sched_scan_stop
,
3288 .auth
= ieee80211_auth
,
3289 .assoc
= ieee80211_assoc
,
3290 .deauth
= ieee80211_deauth
,
3291 .disassoc
= ieee80211_disassoc
,
3292 .join_ibss
= ieee80211_join_ibss
,
3293 .leave_ibss
= ieee80211_leave_ibss
,
3294 .set_mcast_rate
= ieee80211_set_mcast_rate
,
3295 .set_wiphy_params
= ieee80211_set_wiphy_params
,
3296 .set_tx_power
= ieee80211_set_tx_power
,
3297 .get_tx_power
= ieee80211_get_tx_power
,
3298 .set_wds_peer
= ieee80211_set_wds_peer
,
3299 .rfkill_poll
= ieee80211_rfkill_poll
,
3300 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd
)
3301 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump
)
3302 .set_power_mgmt
= ieee80211_set_power_mgmt
,
3303 .set_bitrate_mask
= ieee80211_set_bitrate_mask
,
3304 .remain_on_channel
= ieee80211_remain_on_channel
,
3305 .cancel_remain_on_channel
= ieee80211_cancel_remain_on_channel
,
3306 .mgmt_tx
= ieee80211_mgmt_tx
,
3307 .mgmt_tx_cancel_wait
= ieee80211_mgmt_tx_cancel_wait
,
3308 .set_cqm_rssi_config
= ieee80211_set_cqm_rssi_config
,
3309 .mgmt_frame_register
= ieee80211_mgmt_frame_register
,
3310 .set_antenna
= ieee80211_set_antenna
,
3311 .get_antenna
= ieee80211_get_antenna
,
3312 .set_ringparam
= ieee80211_set_ringparam
,
3313 .get_ringparam
= ieee80211_get_ringparam
,
3314 .set_rekey_data
= ieee80211_set_rekey_data
,
3315 .tdls_oper
= ieee80211_tdls_oper
,
3316 .tdls_mgmt
= ieee80211_tdls_mgmt
,
3317 .probe_client
= ieee80211_probe_client
,
3318 .set_noack_map
= ieee80211_set_noack_map
,
3320 .set_wakeup
= ieee80211_set_wakeup
,
3322 .get_et_sset_count
= ieee80211_get_et_sset_count
,
3323 .get_et_stats
= ieee80211_get_et_stats
,
3324 .get_et_strings
= ieee80211_get_et_strings
,
3325 .get_channel
= ieee80211_cfg_get_channel
,