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 net_device
*ieee80211_add_iface(struct wiphy
*wiphy
, char *name
,
24 enum nl80211_iftype type
,
26 struct vif_params
*params
)
28 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
29 struct net_device
*dev
;
30 struct ieee80211_sub_if_data
*sdata
;
33 err
= ieee80211_if_add(local
, name
, &dev
, type
, params
);
37 if (type
== NL80211_IFTYPE_MONITOR
&& flags
) {
38 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
39 sdata
->u
.mntr_flags
= *flags
;
45 static int ieee80211_del_iface(struct wiphy
*wiphy
, struct net_device
*dev
)
47 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev
));
52 static int ieee80211_change_iface(struct wiphy
*wiphy
,
53 struct net_device
*dev
,
54 enum nl80211_iftype type
, u32
*flags
,
55 struct vif_params
*params
)
57 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
60 ret
= ieee80211_if_change_type(sdata
, type
);
64 if (type
== NL80211_IFTYPE_AP_VLAN
&&
65 params
&& params
->use_4addr
== 0)
66 RCU_INIT_POINTER(sdata
->u
.vlan
.sta
, NULL
);
67 else if (type
== NL80211_IFTYPE_STATION
&&
68 params
&& params
->use_4addr
>= 0)
69 sdata
->u
.mgd
.use_4addr
= params
->use_4addr
;
71 if (sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
&& flags
) {
72 struct ieee80211_local
*local
= sdata
->local
;
74 if (ieee80211_sdata_running(sdata
)) {
76 * Prohibit MONITOR_FLAG_COOK_FRAMES to be
77 * changed while the interface is up.
78 * Else we would need to add a lot of cruft
79 * to update everything:
80 * cooked_mntrs, monitor and all fif_* counters
81 * reconfigure hardware
83 if ((*flags
& MONITOR_FLAG_COOK_FRAMES
) !=
84 (sdata
->u
.mntr_flags
& MONITOR_FLAG_COOK_FRAMES
))
87 ieee80211_adjust_monitor_flags(sdata
, -1);
88 sdata
->u
.mntr_flags
= *flags
;
89 ieee80211_adjust_monitor_flags(sdata
, 1);
91 ieee80211_configure_filter(local
);
94 * Because the interface is down, ieee80211_do_stop
95 * and ieee80211_do_open take care of "everything"
96 * mentioned in the comment above.
98 sdata
->u
.mntr_flags
= *flags
;
105 static int ieee80211_add_key(struct wiphy
*wiphy
, struct net_device
*dev
,
106 u8 key_idx
, bool pairwise
, const u8
*mac_addr
,
107 struct key_params
*params
)
109 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
110 struct sta_info
*sta
= NULL
;
111 struct ieee80211_key
*key
;
114 if (!ieee80211_sdata_running(sdata
))
117 /* reject WEP and TKIP keys if WEP failed to initialize */
118 switch (params
->cipher
) {
119 case WLAN_CIPHER_SUITE_WEP40
:
120 case WLAN_CIPHER_SUITE_TKIP
:
121 case WLAN_CIPHER_SUITE_WEP104
:
122 if (IS_ERR(sdata
->local
->wep_tx_tfm
))
129 key
= ieee80211_key_alloc(params
->cipher
, key_idx
, params
->key_len
,
130 params
->key
, params
->seq_len
, params
->seq
);
135 key
->conf
.flags
|= IEEE80211_KEY_FLAG_PAIRWISE
;
137 mutex_lock(&sdata
->local
->sta_mtx
);
140 if (ieee80211_vif_is_mesh(&sdata
->vif
))
141 sta
= sta_info_get(sdata
, mac_addr
);
143 sta
= sta_info_get_bss(sdata
, mac_addr
);
145 ieee80211_key_free(sdata
->local
, key
);
151 err
= ieee80211_key_link(key
, sdata
, sta
);
153 ieee80211_key_free(sdata
->local
, key
);
156 mutex_unlock(&sdata
->local
->sta_mtx
);
161 static int ieee80211_del_key(struct wiphy
*wiphy
, struct net_device
*dev
,
162 u8 key_idx
, bool pairwise
, const u8
*mac_addr
)
164 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
165 struct ieee80211_local
*local
= sdata
->local
;
166 struct sta_info
*sta
;
167 struct ieee80211_key
*key
= NULL
;
170 mutex_lock(&local
->sta_mtx
);
171 mutex_lock(&local
->key_mtx
);
176 sta
= sta_info_get_bss(sdata
, mac_addr
);
181 key
= key_mtx_dereference(local
, sta
->ptk
);
183 key
= key_mtx_dereference(local
, sta
->gtk
[key_idx
]);
185 key
= key_mtx_dereference(local
, sdata
->keys
[key_idx
]);
192 __ieee80211_key_free(key
);
196 mutex_unlock(&local
->key_mtx
);
197 mutex_unlock(&local
->sta_mtx
);
202 static int ieee80211_get_key(struct wiphy
*wiphy
, struct net_device
*dev
,
203 u8 key_idx
, bool pairwise
, const u8
*mac_addr
,
205 void (*callback
)(void *cookie
,
206 struct key_params
*params
))
208 struct ieee80211_sub_if_data
*sdata
;
209 struct sta_info
*sta
= NULL
;
211 struct key_params params
;
212 struct ieee80211_key
*key
= NULL
;
218 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
223 sta
= sta_info_get_bss(sdata
, mac_addr
);
228 key
= rcu_dereference(sta
->ptk
);
229 else if (key_idx
< NUM_DEFAULT_KEYS
)
230 key
= rcu_dereference(sta
->gtk
[key_idx
]);
232 key
= rcu_dereference(sdata
->keys
[key_idx
]);
237 memset(¶ms
, 0, sizeof(params
));
239 params
.cipher
= key
->conf
.cipher
;
241 switch (key
->conf
.cipher
) {
242 case WLAN_CIPHER_SUITE_TKIP
:
243 iv32
= key
->u
.tkip
.tx
.iv32
;
244 iv16
= key
->u
.tkip
.tx
.iv16
;
246 if (key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
)
247 drv_get_tkip_seq(sdata
->local
,
248 key
->conf
.hw_key_idx
,
251 seq
[0] = iv16
& 0xff;
252 seq
[1] = (iv16
>> 8) & 0xff;
253 seq
[2] = iv32
& 0xff;
254 seq
[3] = (iv32
>> 8) & 0xff;
255 seq
[4] = (iv32
>> 16) & 0xff;
256 seq
[5] = (iv32
>> 24) & 0xff;
260 case WLAN_CIPHER_SUITE_CCMP
:
261 pn64
= atomic64_read(&key
->u
.ccmp
.tx_pn
);
271 case WLAN_CIPHER_SUITE_AES_CMAC
:
272 pn64
= atomic64_read(&key
->u
.aes_cmac
.tx_pn
);
284 params
.key
= key
->conf
.key
;
285 params
.key_len
= key
->conf
.keylen
;
287 callback(cookie
, ¶ms
);
295 static int ieee80211_config_default_key(struct wiphy
*wiphy
,
296 struct net_device
*dev
,
297 u8 key_idx
, bool uni
,
300 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
302 ieee80211_set_default_key(sdata
, key_idx
, uni
, multi
);
307 static int ieee80211_config_default_mgmt_key(struct wiphy
*wiphy
,
308 struct net_device
*dev
,
311 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
313 ieee80211_set_default_mgmt_key(sdata
, key_idx
);
318 static void rate_idx_to_bitrate(struct rate_info
*rate
, struct sta_info
*sta
, int idx
)
320 if (!(rate
->flags
& RATE_INFO_FLAGS_MCS
)) {
321 struct ieee80211_supported_band
*sband
;
322 sband
= sta
->local
->hw
.wiphy
->bands
[
323 sta
->local
->hw
.conf
.channel
->band
];
324 rate
->legacy
= sband
->bitrates
[idx
].bitrate
;
329 static void sta_set_sinfo(struct sta_info
*sta
, struct station_info
*sinfo
)
331 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
332 struct timespec uptime
;
334 sinfo
->generation
= sdata
->local
->sta_generation
;
336 sinfo
->filled
= STATION_INFO_INACTIVE_TIME
|
337 STATION_INFO_RX_BYTES
|
338 STATION_INFO_TX_BYTES
|
339 STATION_INFO_RX_PACKETS
|
340 STATION_INFO_TX_PACKETS
|
341 STATION_INFO_TX_RETRIES
|
342 STATION_INFO_TX_FAILED
|
343 STATION_INFO_TX_BITRATE
|
344 STATION_INFO_RX_BITRATE
|
345 STATION_INFO_RX_DROP_MISC
|
346 STATION_INFO_BSS_PARAM
|
347 STATION_INFO_CONNECTED_TIME
|
348 STATION_INFO_STA_FLAGS
;
350 do_posix_clock_monotonic_gettime(&uptime
);
351 sinfo
->connected_time
= uptime
.tv_sec
- sta
->last_connected
;
353 sinfo
->inactive_time
= jiffies_to_msecs(jiffies
- sta
->last_rx
);
354 sinfo
->rx_bytes
= sta
->rx_bytes
;
355 sinfo
->tx_bytes
= sta
->tx_bytes
;
356 sinfo
->rx_packets
= sta
->rx_packets
;
357 sinfo
->tx_packets
= sta
->tx_packets
;
358 sinfo
->tx_retries
= sta
->tx_retry_count
;
359 sinfo
->tx_failed
= sta
->tx_retry_failed
;
360 sinfo
->rx_dropped_misc
= sta
->rx_dropped
;
362 if ((sta
->local
->hw
.flags
& IEEE80211_HW_SIGNAL_DBM
) ||
363 (sta
->local
->hw
.flags
& IEEE80211_HW_SIGNAL_UNSPEC
)) {
364 sinfo
->filled
|= STATION_INFO_SIGNAL
| STATION_INFO_SIGNAL_AVG
;
365 sinfo
->signal
= (s8
)sta
->last_signal
;
366 sinfo
->signal_avg
= (s8
) -ewma_read(&sta
->avg_signal
);
369 sinfo
->txrate
.flags
= 0;
370 if (sta
->last_tx_rate
.flags
& IEEE80211_TX_RC_MCS
)
371 sinfo
->txrate
.flags
|= RATE_INFO_FLAGS_MCS
;
372 if (sta
->last_tx_rate
.flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
)
373 sinfo
->txrate
.flags
|= RATE_INFO_FLAGS_40_MHZ_WIDTH
;
374 if (sta
->last_tx_rate
.flags
& IEEE80211_TX_RC_SHORT_GI
)
375 sinfo
->txrate
.flags
|= RATE_INFO_FLAGS_SHORT_GI
;
376 rate_idx_to_bitrate(&sinfo
->txrate
, sta
, sta
->last_tx_rate
.idx
);
378 sinfo
->rxrate
.flags
= 0;
379 if (sta
->last_rx_rate_flag
& RX_FLAG_HT
)
380 sinfo
->rxrate
.flags
|= RATE_INFO_FLAGS_MCS
;
381 if (sta
->last_rx_rate_flag
& RX_FLAG_40MHZ
)
382 sinfo
->rxrate
.flags
|= RATE_INFO_FLAGS_40_MHZ_WIDTH
;
383 if (sta
->last_rx_rate_flag
& RX_FLAG_SHORT_GI
)
384 sinfo
->rxrate
.flags
|= RATE_INFO_FLAGS_SHORT_GI
;
385 rate_idx_to_bitrate(&sinfo
->rxrate
, sta
, sta
->last_rx_rate_idx
);
387 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
388 #ifdef CONFIG_MAC80211_MESH
389 sinfo
->filled
|= STATION_INFO_LLID
|
391 STATION_INFO_PLINK_STATE
;
393 sinfo
->llid
= le16_to_cpu(sta
->llid
);
394 sinfo
->plid
= le16_to_cpu(sta
->plid
);
395 sinfo
->plink_state
= sta
->plink_state
;
399 sinfo
->bss_param
.flags
= 0;
400 if (sdata
->vif
.bss_conf
.use_cts_prot
)
401 sinfo
->bss_param
.flags
|= BSS_PARAM_FLAGS_CTS_PROT
;
402 if (sdata
->vif
.bss_conf
.use_short_preamble
)
403 sinfo
->bss_param
.flags
|= BSS_PARAM_FLAGS_SHORT_PREAMBLE
;
404 if (sdata
->vif
.bss_conf
.use_short_slot
)
405 sinfo
->bss_param
.flags
|= BSS_PARAM_FLAGS_SHORT_SLOT_TIME
;
406 sinfo
->bss_param
.dtim_period
= sdata
->local
->hw
.conf
.ps_dtim_period
;
407 sinfo
->bss_param
.beacon_interval
= sdata
->vif
.bss_conf
.beacon_int
;
409 sinfo
->sta_flags
.set
= 0;
410 sinfo
->sta_flags
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
411 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
412 BIT(NL80211_STA_FLAG_WME
) |
413 BIT(NL80211_STA_FLAG_MFP
) |
414 BIT(NL80211_STA_FLAG_AUTHENTICATED
);
415 if (test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
416 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
417 if (test_sta_flag(sta
, WLAN_STA_SHORT_PREAMBLE
))
418 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
419 if (test_sta_flag(sta
, WLAN_STA_WME
))
420 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_WME
);
421 if (test_sta_flag(sta
, WLAN_STA_MFP
))
422 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_MFP
);
423 if (test_sta_flag(sta
, WLAN_STA_AUTH
))
424 sinfo
->sta_flags
.set
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
);
428 static int ieee80211_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
429 int idx
, u8
*mac
, struct station_info
*sinfo
)
431 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
432 struct sta_info
*sta
;
437 sta
= sta_info_get_by_idx(sdata
, idx
);
440 memcpy(mac
, sta
->sta
.addr
, ETH_ALEN
);
441 sta_set_sinfo(sta
, sinfo
);
449 static int ieee80211_dump_survey(struct wiphy
*wiphy
, struct net_device
*dev
,
450 int idx
, struct survey_info
*survey
)
452 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
454 return drv_get_survey(local
, idx
, survey
);
457 static int ieee80211_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
458 u8
*mac
, struct station_info
*sinfo
)
460 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
461 struct sta_info
*sta
;
466 sta
= sta_info_get_bss(sdata
, mac
);
469 sta_set_sinfo(sta
, sinfo
);
477 static void ieee80211_config_ap_ssid(struct ieee80211_sub_if_data
*sdata
,
478 struct beacon_parameters
*params
)
480 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
482 bss_conf
->ssid_len
= params
->ssid_len
;
484 if (params
->ssid_len
)
485 memcpy(bss_conf
->ssid
, params
->ssid
, params
->ssid_len
);
487 bss_conf
->hidden_ssid
=
488 (params
->hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
);
492 * This handles both adding a beacon and setting new beacon info
494 static int ieee80211_config_beacon(struct ieee80211_sub_if_data
*sdata
,
495 struct beacon_parameters
*params
)
497 struct beacon_data
*new, *old
;
498 int new_head_len
, new_tail_len
;
502 old
= rtnl_dereference(sdata
->u
.ap
.beacon
);
504 /* head must not be zero-length */
505 if (params
->head
&& !params
->head_len
)
509 * This is a kludge. beacon interval should really be part
510 * of the beacon information.
512 if (params
->interval
&&
513 (sdata
->vif
.bss_conf
.beacon_int
!= params
->interval
)) {
514 sdata
->vif
.bss_conf
.beacon_int
= params
->interval
;
515 ieee80211_bss_info_change_notify(sdata
,
516 BSS_CHANGED_BEACON_INT
);
519 /* Need to have a beacon head if we don't have one yet */
520 if (!params
->head
&& !old
)
523 /* sorry, no way to start beaconing without dtim period */
524 if (!params
->dtim_period
&& !old
)
527 /* new or old head? */
529 new_head_len
= params
->head_len
;
531 new_head_len
= old
->head_len
;
533 /* new or old tail? */
534 if (params
->tail
|| !old
)
535 /* params->tail_len will be zero for !params->tail */
536 new_tail_len
= params
->tail_len
;
538 new_tail_len
= old
->tail_len
;
540 size
= sizeof(*new) + new_head_len
+ new_tail_len
;
542 new = kzalloc(size
, GFP_KERNEL
);
546 /* start filling the new info now */
548 /* new or old dtim period? */
549 if (params
->dtim_period
)
550 new->dtim_period
= params
->dtim_period
;
552 new->dtim_period
= old
->dtim_period
;
555 * pointers go into the block we allocated,
556 * memory is | beacon_data | head | tail |
558 new->head
= ((u8
*) new) + sizeof(*new);
559 new->tail
= new->head
+ new_head_len
;
560 new->head_len
= new_head_len
;
561 new->tail_len
= new_tail_len
;
565 memcpy(new->head
, params
->head
, new_head_len
);
567 memcpy(new->head
, old
->head
, new_head_len
);
569 /* copy in optional tail */
571 memcpy(new->tail
, params
->tail
, new_tail_len
);
574 memcpy(new->tail
, old
->tail
, new_tail_len
);
576 sdata
->vif
.bss_conf
.dtim_period
= new->dtim_period
;
578 RCU_INIT_POINTER(sdata
->u
.ap
.beacon
, new);
584 ieee80211_config_ap_ssid(sdata
, params
);
586 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BEACON_ENABLED
|
592 static int ieee80211_add_beacon(struct wiphy
*wiphy
, struct net_device
*dev
,
593 struct beacon_parameters
*params
)
595 struct ieee80211_sub_if_data
*sdata
;
596 struct beacon_data
*old
;
597 struct ieee80211_sub_if_data
*vlan
;
600 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
602 old
= rtnl_dereference(sdata
->u
.ap
.beacon
);
606 ret
= ieee80211_config_beacon(sdata
, params
);
611 * Apply control port protocol, this allows us to
612 * not encrypt dynamic WEP control frames.
614 sdata
->control_port_protocol
= params
->crypto
.control_port_ethertype
;
615 sdata
->control_port_no_encrypt
= params
->crypto
.control_port_no_encrypt
;
616 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
) {
617 vlan
->control_port_protocol
=
618 params
->crypto
.control_port_ethertype
;
619 vlan
->control_port_no_encrypt
=
620 params
->crypto
.control_port_no_encrypt
;
626 static int ieee80211_set_beacon(struct wiphy
*wiphy
, struct net_device
*dev
,
627 struct beacon_parameters
*params
)
629 struct ieee80211_sub_if_data
*sdata
;
630 struct beacon_data
*old
;
632 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
634 old
= rtnl_dereference(sdata
->u
.ap
.beacon
);
638 return ieee80211_config_beacon(sdata
, params
);
641 static int ieee80211_del_beacon(struct wiphy
*wiphy
, struct net_device
*dev
)
643 struct ieee80211_sub_if_data
*sdata
;
644 struct beacon_data
*old
;
646 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
648 old
= rtnl_dereference(sdata
->u
.ap
.beacon
);
652 RCU_INIT_POINTER(sdata
->u
.ap
.beacon
, NULL
);
656 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BEACON_ENABLED
);
660 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
661 struct iapp_layer2_update
{
662 u8 da
[ETH_ALEN
]; /* broadcast */
663 u8 sa
[ETH_ALEN
]; /* STA addr */
671 static void ieee80211_send_layer2_update(struct sta_info
*sta
)
673 struct iapp_layer2_update
*msg
;
676 /* Send Level 2 Update Frame to update forwarding tables in layer 2
679 skb
= dev_alloc_skb(sizeof(*msg
));
682 msg
= (struct iapp_layer2_update
*)skb_put(skb
, sizeof(*msg
));
684 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
685 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
687 memset(msg
->da
, 0xff, ETH_ALEN
);
688 memcpy(msg
->sa
, sta
->sta
.addr
, ETH_ALEN
);
691 msg
->ssap
= 0x01; /* NULL LSAP, CR Bit: Response */
692 msg
->control
= 0xaf; /* XID response lsb.1111F101.
693 * F=0 (no poll command; unsolicited frame) */
694 msg
->xid_info
[0] = 0x81; /* XID format identifier */
695 msg
->xid_info
[1] = 1; /* LLC types/classes: Type 1 LLC */
696 msg
->xid_info
[2] = 0; /* XID sender's receive window size (RW) */
698 skb
->dev
= sta
->sdata
->dev
;
699 skb
->protocol
= eth_type_trans(skb
, sta
->sdata
->dev
);
700 memset(skb
->cb
, 0, sizeof(skb
->cb
));
704 static void sta_apply_parameters(struct ieee80211_local
*local
,
705 struct sta_info
*sta
,
706 struct station_parameters
*params
)
710 struct ieee80211_supported_band
*sband
;
711 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
714 sband
= local
->hw
.wiphy
->bands
[local
->oper_channel
->band
];
716 mask
= params
->sta_flags_mask
;
717 set
= params
->sta_flags_set
;
719 if (mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
720 if (set
& BIT(NL80211_STA_FLAG_AUTHORIZED
))
721 set_sta_flag(sta
, WLAN_STA_AUTHORIZED
);
723 clear_sta_flag(sta
, WLAN_STA_AUTHORIZED
);
726 if (mask
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
)) {
727 if (set
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
))
728 set_sta_flag(sta
, WLAN_STA_SHORT_PREAMBLE
);
730 clear_sta_flag(sta
, WLAN_STA_SHORT_PREAMBLE
);
733 if (mask
& BIT(NL80211_STA_FLAG_WME
)) {
734 if (set
& BIT(NL80211_STA_FLAG_WME
)) {
735 set_sta_flag(sta
, WLAN_STA_WME
);
738 clear_sta_flag(sta
, WLAN_STA_WME
);
739 sta
->sta
.wme
= false;
743 if (mask
& BIT(NL80211_STA_FLAG_MFP
)) {
744 if (set
& BIT(NL80211_STA_FLAG_MFP
))
745 set_sta_flag(sta
, WLAN_STA_MFP
);
747 clear_sta_flag(sta
, WLAN_STA_MFP
);
750 if (mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
)) {
751 if (set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
))
752 set_sta_flag(sta
, WLAN_STA_AUTH
);
754 clear_sta_flag(sta
, WLAN_STA_AUTH
);
757 if (mask
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) {
758 if (set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
759 set_sta_flag(sta
, WLAN_STA_TDLS_PEER
);
761 clear_sta_flag(sta
, WLAN_STA_TDLS_PEER
);
764 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
) {
765 sta
->sta
.uapsd_queues
= params
->uapsd_queues
;
766 sta
->sta
.max_sp
= params
->max_sp
;
770 * cfg80211 validates this (1-2007) and allows setting the AID
771 * only when creating a new station entry
774 sta
->sta
.aid
= params
->aid
;
777 * FIXME: updating the following information is racy when this
778 * function is called from ieee80211_change_station().
779 * However, all this information should be static so
780 * maybe we should just reject attemps to change it.
783 if (params
->listen_interval
>= 0)
784 sta
->listen_interval
= params
->listen_interval
;
786 if (params
->supported_rates
) {
789 for (i
= 0; i
< params
->supported_rates_len
; i
++) {
790 int rate
= (params
->supported_rates
[i
] & 0x7f) * 5;
791 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
792 if (sband
->bitrates
[j
].bitrate
== rate
)
796 sta
->sta
.supp_rates
[local
->oper_channel
->band
] = rates
;
800 ieee80211_ht_cap_ie_to_sta_ht_cap(sband
,
804 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
805 #ifdef CONFIG_MAC80211_MESH
806 if (sdata
->u
.mesh
.security
& IEEE80211_MESH_SEC_SECURED
)
807 switch (params
->plink_state
) {
808 case NL80211_PLINK_LISTEN
:
809 case NL80211_PLINK_ESTAB
:
810 case NL80211_PLINK_BLOCKED
:
811 sta
->plink_state
= params
->plink_state
;
818 switch (params
->plink_action
) {
819 case PLINK_ACTION_OPEN
:
820 mesh_plink_open(sta
);
822 case PLINK_ACTION_BLOCK
:
823 mesh_plink_block(sta
);
830 static int ieee80211_add_station(struct wiphy
*wiphy
, struct net_device
*dev
,
831 u8
*mac
, struct station_parameters
*params
)
833 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
834 struct sta_info
*sta
;
835 struct ieee80211_sub_if_data
*sdata
;
840 sdata
= IEEE80211_DEV_TO_SUB_IF(params
->vlan
);
842 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
843 sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
846 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
848 if (compare_ether_addr(mac
, sdata
->vif
.addr
) == 0)
851 if (is_multicast_ether_addr(mac
))
854 /* Only TDLS-supporting stations can add TDLS peers */
855 if ((params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
856 !((wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
857 sdata
->vif
.type
== NL80211_IFTYPE_STATION
))
860 sta
= sta_info_alloc(sdata
, mac
, GFP_KERNEL
);
864 set_sta_flag(sta
, WLAN_STA_AUTH
);
865 set_sta_flag(sta
, WLAN_STA_ASSOC
);
867 sta_apply_parameters(local
, sta
, params
);
869 rate_control_rate_init(sta
);
871 layer2_update
= sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
||
872 sdata
->vif
.type
== NL80211_IFTYPE_AP
;
874 err
= sta_info_insert_rcu(sta
);
881 ieee80211_send_layer2_update(sta
);
888 static int ieee80211_del_station(struct wiphy
*wiphy
, struct net_device
*dev
,
891 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
892 struct ieee80211_sub_if_data
*sdata
;
894 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
897 return sta_info_destroy_addr_bss(sdata
, mac
);
899 sta_info_flush(local
, sdata
);
903 static int ieee80211_change_station(struct wiphy
*wiphy
,
904 struct net_device
*dev
,
906 struct station_parameters
*params
)
908 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
909 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
910 struct sta_info
*sta
;
911 struct ieee80211_sub_if_data
*vlansdata
;
915 sta
= sta_info_get_bss(sdata
, mac
);
921 /* The TDLS bit cannot be toggled after the STA was added */
922 if ((params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
923 !!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) !=
924 !!test_sta_flag(sta
, WLAN_STA_TDLS_PEER
)) {
929 if (params
->vlan
&& params
->vlan
!= sta
->sdata
->dev
) {
930 vlansdata
= IEEE80211_DEV_TO_SUB_IF(params
->vlan
);
932 if (vlansdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
933 vlansdata
->vif
.type
!= NL80211_IFTYPE_AP
) {
938 if (params
->vlan
->ieee80211_ptr
->use_4addr
) {
939 if (vlansdata
->u
.vlan
.sta
) {
944 RCU_INIT_POINTER(vlansdata
->u
.vlan
.sta
, sta
);
947 sta
->sdata
= vlansdata
;
948 ieee80211_send_layer2_update(sta
);
951 sta_apply_parameters(local
, sta
, params
);
955 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
&&
956 params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
))
957 ieee80211_recalc_ps(local
, -1);
962 #ifdef CONFIG_MAC80211_MESH
963 static int ieee80211_add_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
964 u8
*dst
, u8
*next_hop
)
966 struct ieee80211_sub_if_data
*sdata
;
967 struct mesh_path
*mpath
;
968 struct sta_info
*sta
;
971 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
974 sta
= sta_info_get(sdata
, next_hop
);
980 err
= mesh_path_add(dst
, sdata
);
986 mpath
= mesh_path_lookup(dst
, sdata
);
991 mesh_path_fix_nexthop(mpath
, sta
);
997 static int ieee80211_del_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1000 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1003 return mesh_path_del(dst
, sdata
);
1005 mesh_path_flush_by_iface(sdata
);
1009 static int ieee80211_change_mpath(struct wiphy
*wiphy
,
1010 struct net_device
*dev
,
1011 u8
*dst
, u8
*next_hop
)
1013 struct ieee80211_sub_if_data
*sdata
;
1014 struct mesh_path
*mpath
;
1015 struct sta_info
*sta
;
1017 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1021 sta
= sta_info_get(sdata
, next_hop
);
1027 mpath
= mesh_path_lookup(dst
, sdata
);
1033 mesh_path_fix_nexthop(mpath
, sta
);
1039 static void mpath_set_pinfo(struct mesh_path
*mpath
, u8
*next_hop
,
1040 struct mpath_info
*pinfo
)
1042 struct sta_info
*next_hop_sta
= rcu_dereference(mpath
->next_hop
);
1045 memcpy(next_hop
, next_hop_sta
->sta
.addr
, ETH_ALEN
);
1047 memset(next_hop
, 0, ETH_ALEN
);
1049 pinfo
->generation
= mesh_paths_generation
;
1051 pinfo
->filled
= MPATH_INFO_FRAME_QLEN
|
1054 MPATH_INFO_EXPTIME
|
1055 MPATH_INFO_DISCOVERY_TIMEOUT
|
1056 MPATH_INFO_DISCOVERY_RETRIES
|
1059 pinfo
->frame_qlen
= mpath
->frame_queue
.qlen
;
1060 pinfo
->sn
= mpath
->sn
;
1061 pinfo
->metric
= mpath
->metric
;
1062 if (time_before(jiffies
, mpath
->exp_time
))
1063 pinfo
->exptime
= jiffies_to_msecs(mpath
->exp_time
- jiffies
);
1064 pinfo
->discovery_timeout
=
1065 jiffies_to_msecs(mpath
->discovery_timeout
);
1066 pinfo
->discovery_retries
= mpath
->discovery_retries
;
1068 if (mpath
->flags
& MESH_PATH_ACTIVE
)
1069 pinfo
->flags
|= NL80211_MPATH_FLAG_ACTIVE
;
1070 if (mpath
->flags
& MESH_PATH_RESOLVING
)
1071 pinfo
->flags
|= NL80211_MPATH_FLAG_RESOLVING
;
1072 if (mpath
->flags
& MESH_PATH_SN_VALID
)
1073 pinfo
->flags
|= NL80211_MPATH_FLAG_SN_VALID
;
1074 if (mpath
->flags
& MESH_PATH_FIXED
)
1075 pinfo
->flags
|= NL80211_MPATH_FLAG_FIXED
;
1076 if (mpath
->flags
& MESH_PATH_RESOLVING
)
1077 pinfo
->flags
|= NL80211_MPATH_FLAG_RESOLVING
;
1079 pinfo
->flags
= mpath
->flags
;
1082 static int ieee80211_get_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1083 u8
*dst
, u8
*next_hop
, struct mpath_info
*pinfo
)
1086 struct ieee80211_sub_if_data
*sdata
;
1087 struct mesh_path
*mpath
;
1089 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1092 mpath
= mesh_path_lookup(dst
, sdata
);
1097 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
1098 mpath_set_pinfo(mpath
, next_hop
, pinfo
);
1103 static int ieee80211_dump_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1104 int idx
, u8
*dst
, u8
*next_hop
,
1105 struct mpath_info
*pinfo
)
1107 struct ieee80211_sub_if_data
*sdata
;
1108 struct mesh_path
*mpath
;
1110 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1113 mpath
= mesh_path_lookup_by_idx(idx
, sdata
);
1118 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
1119 mpath_set_pinfo(mpath
, next_hop
, pinfo
);
1124 static int ieee80211_get_mesh_config(struct wiphy
*wiphy
,
1125 struct net_device
*dev
,
1126 struct mesh_config
*conf
)
1128 struct ieee80211_sub_if_data
*sdata
;
1129 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1131 memcpy(conf
, &(sdata
->u
.mesh
.mshcfg
), sizeof(struct mesh_config
));
1135 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm
, u32 mask
)
1137 return (mask
>> (parm
-1)) & 0x1;
1140 static int copy_mesh_setup(struct ieee80211_if_mesh
*ifmsh
,
1141 const struct mesh_setup
*setup
)
1146 /* allocate information elements */
1150 if (setup
->ie_len
) {
1151 new_ie
= kmemdup(setup
->ie
, setup
->ie_len
,
1156 ifmsh
->ie_len
= setup
->ie_len
;
1160 /* now copy the rest of the setup parameters */
1161 ifmsh
->mesh_id_len
= setup
->mesh_id_len
;
1162 memcpy(ifmsh
->mesh_id
, setup
->mesh_id
, ifmsh
->mesh_id_len
);
1163 ifmsh
->mesh_pp_id
= setup
->path_sel_proto
;
1164 ifmsh
->mesh_pm_id
= setup
->path_metric
;
1165 ifmsh
->security
= IEEE80211_MESH_SEC_NONE
;
1166 if (setup
->is_authenticated
)
1167 ifmsh
->security
|= IEEE80211_MESH_SEC_AUTHED
;
1168 if (setup
->is_secure
)
1169 ifmsh
->security
|= IEEE80211_MESH_SEC_SECURED
;
1174 static int ieee80211_update_mesh_config(struct wiphy
*wiphy
,
1175 struct net_device
*dev
, u32 mask
,
1176 const struct mesh_config
*nconf
)
1178 struct mesh_config
*conf
;
1179 struct ieee80211_sub_if_data
*sdata
;
1180 struct ieee80211_if_mesh
*ifmsh
;
1182 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1183 ifmsh
= &sdata
->u
.mesh
;
1185 /* Set the config options which we are interested in setting */
1186 conf
= &(sdata
->u
.mesh
.mshcfg
);
1187 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT
, mask
))
1188 conf
->dot11MeshRetryTimeout
= nconf
->dot11MeshRetryTimeout
;
1189 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT
, mask
))
1190 conf
->dot11MeshConfirmTimeout
= nconf
->dot11MeshConfirmTimeout
;
1191 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT
, mask
))
1192 conf
->dot11MeshHoldingTimeout
= nconf
->dot11MeshHoldingTimeout
;
1193 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS
, mask
))
1194 conf
->dot11MeshMaxPeerLinks
= nconf
->dot11MeshMaxPeerLinks
;
1195 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES
, mask
))
1196 conf
->dot11MeshMaxRetries
= nconf
->dot11MeshMaxRetries
;
1197 if (_chg_mesh_attr(NL80211_MESHCONF_TTL
, mask
))
1198 conf
->dot11MeshTTL
= nconf
->dot11MeshTTL
;
1199 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL
, mask
))
1200 conf
->dot11MeshTTL
= nconf
->element_ttl
;
1201 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS
, mask
))
1202 conf
->auto_open_plinks
= nconf
->auto_open_plinks
;
1203 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
, mask
))
1204 conf
->dot11MeshHWMPmaxPREQretries
=
1205 nconf
->dot11MeshHWMPmaxPREQretries
;
1206 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME
, mask
))
1207 conf
->path_refresh_time
= nconf
->path_refresh_time
;
1208 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
, mask
))
1209 conf
->min_discovery_timeout
= nconf
->min_discovery_timeout
;
1210 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
, mask
))
1211 conf
->dot11MeshHWMPactivePathTimeout
=
1212 nconf
->dot11MeshHWMPactivePathTimeout
;
1213 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
, mask
))
1214 conf
->dot11MeshHWMPpreqMinInterval
=
1215 nconf
->dot11MeshHWMPpreqMinInterval
;
1216 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
1218 conf
->dot11MeshHWMPnetDiameterTraversalTime
=
1219 nconf
->dot11MeshHWMPnetDiameterTraversalTime
;
1220 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE
, mask
)) {
1221 conf
->dot11MeshHWMPRootMode
= nconf
->dot11MeshHWMPRootMode
;
1222 ieee80211_mesh_root_setup(ifmsh
);
1224 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS
, mask
)) {
1225 /* our current gate announcement implementation rides on root
1226 * announcements, so require this ifmsh to also be a root node
1228 if (nconf
->dot11MeshGateAnnouncementProtocol
&&
1229 !conf
->dot11MeshHWMPRootMode
) {
1230 conf
->dot11MeshHWMPRootMode
= 1;
1231 ieee80211_mesh_root_setup(ifmsh
);
1233 conf
->dot11MeshGateAnnouncementProtocol
=
1234 nconf
->dot11MeshGateAnnouncementProtocol
;
1236 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL
, mask
)) {
1237 conf
->dot11MeshHWMPRannInterval
=
1238 nconf
->dot11MeshHWMPRannInterval
;
1243 static int ieee80211_join_mesh(struct wiphy
*wiphy
, struct net_device
*dev
,
1244 const struct mesh_config
*conf
,
1245 const struct mesh_setup
*setup
)
1247 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1248 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
1251 memcpy(&ifmsh
->mshcfg
, conf
, sizeof(struct mesh_config
));
1252 err
= copy_mesh_setup(ifmsh
, setup
);
1255 ieee80211_start_mesh(sdata
);
1260 static int ieee80211_leave_mesh(struct wiphy
*wiphy
, struct net_device
*dev
)
1262 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1264 ieee80211_stop_mesh(sdata
);
1270 static int ieee80211_change_bss(struct wiphy
*wiphy
,
1271 struct net_device
*dev
,
1272 struct bss_parameters
*params
)
1274 struct ieee80211_sub_if_data
*sdata
;
1277 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1279 if (params
->use_cts_prot
>= 0) {
1280 sdata
->vif
.bss_conf
.use_cts_prot
= params
->use_cts_prot
;
1281 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
1283 if (params
->use_short_preamble
>= 0) {
1284 sdata
->vif
.bss_conf
.use_short_preamble
=
1285 params
->use_short_preamble
;
1286 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
1289 if (!sdata
->vif
.bss_conf
.use_short_slot
&&
1290 sdata
->local
->hw
.conf
.channel
->band
== IEEE80211_BAND_5GHZ
) {
1291 sdata
->vif
.bss_conf
.use_short_slot
= true;
1292 changed
|= BSS_CHANGED_ERP_SLOT
;
1295 if (params
->use_short_slot_time
>= 0) {
1296 sdata
->vif
.bss_conf
.use_short_slot
=
1297 params
->use_short_slot_time
;
1298 changed
|= BSS_CHANGED_ERP_SLOT
;
1301 if (params
->basic_rates
) {
1304 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1305 struct ieee80211_supported_band
*sband
=
1306 wiphy
->bands
[local
->oper_channel
->band
];
1308 for (i
= 0; i
< params
->basic_rates_len
; i
++) {
1309 int rate
= (params
->basic_rates
[i
] & 0x7f) * 5;
1310 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1311 if (sband
->bitrates
[j
].bitrate
== rate
)
1315 sdata
->vif
.bss_conf
.basic_rates
= rates
;
1316 changed
|= BSS_CHANGED_BASIC_RATES
;
1319 if (params
->ap_isolate
>= 0) {
1320 if (params
->ap_isolate
)
1321 sdata
->flags
|= IEEE80211_SDATA_DONT_BRIDGE_PACKETS
;
1323 sdata
->flags
&= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS
;
1326 if (params
->ht_opmode
>= 0) {
1327 sdata
->vif
.bss_conf
.ht_operation_mode
=
1328 (u16
) params
->ht_opmode
;
1329 changed
|= BSS_CHANGED_HT
;
1332 ieee80211_bss_info_change_notify(sdata
, changed
);
1337 static int ieee80211_set_txq_params(struct wiphy
*wiphy
,
1338 struct net_device
*dev
,
1339 struct ieee80211_txq_params
*params
)
1341 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1342 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1343 struct ieee80211_tx_queue_params p
;
1345 if (!local
->ops
->conf_tx
)
1348 memset(&p
, 0, sizeof(p
));
1349 p
.aifs
= params
->aifs
;
1350 p
.cw_max
= params
->cwmax
;
1351 p
.cw_min
= params
->cwmin
;
1352 p
.txop
= params
->txop
;
1355 * Setting tx queue params disables u-apsd because it's only
1356 * called in master mode.
1360 if (params
->queue
>= local
->hw
.queues
)
1363 sdata
->tx_conf
[params
->queue
] = p
;
1364 if (drv_conf_tx(local
, sdata
, params
->queue
, &p
)) {
1365 wiphy_debug(local
->hw
.wiphy
,
1366 "failed to set TX queue parameters for queue %d\n",
1374 static int ieee80211_set_channel(struct wiphy
*wiphy
,
1375 struct net_device
*netdev
,
1376 struct ieee80211_channel
*chan
,
1377 enum nl80211_channel_type channel_type
)
1379 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1380 struct ieee80211_sub_if_data
*sdata
= NULL
;
1381 struct ieee80211_channel
*old_oper
;
1382 enum nl80211_channel_type old_oper_type
;
1383 enum nl80211_channel_type old_vif_oper_type
= NL80211_CHAN_NO_HT
;
1386 sdata
= IEEE80211_DEV_TO_SUB_IF(netdev
);
1388 switch (ieee80211_get_channel_mode(local
, NULL
)) {
1389 case CHAN_MODE_HOPPING
:
1391 case CHAN_MODE_FIXED
:
1392 if (local
->oper_channel
!= chan
)
1394 if (!sdata
&& local
->_oper_channel_type
== channel_type
)
1397 case CHAN_MODE_UNDEFINED
:
1402 old_vif_oper_type
= sdata
->vif
.bss_conf
.channel_type
;
1403 old_oper_type
= local
->_oper_channel_type
;
1405 if (!ieee80211_set_channel_type(local
, sdata
, channel_type
))
1408 old_oper
= local
->oper_channel
;
1409 local
->oper_channel
= chan
;
1411 /* Update driver if changes were actually made. */
1412 if ((old_oper
!= local
->oper_channel
) ||
1413 (old_oper_type
!= local
->_oper_channel_type
))
1414 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_CHANNEL
);
1416 if (sdata
&& sdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
&&
1417 old_vif_oper_type
!= sdata
->vif
.bss_conf
.channel_type
)
1418 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_HT
);
1424 static int ieee80211_suspend(struct wiphy
*wiphy
,
1425 struct cfg80211_wowlan
*wowlan
)
1427 return __ieee80211_suspend(wiphy_priv(wiphy
), wowlan
);
1430 static int ieee80211_resume(struct wiphy
*wiphy
)
1432 return __ieee80211_resume(wiphy_priv(wiphy
));
1435 #define ieee80211_suspend NULL
1436 #define ieee80211_resume NULL
1439 static int ieee80211_scan(struct wiphy
*wiphy
,
1440 struct net_device
*dev
,
1441 struct cfg80211_scan_request
*req
)
1443 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1445 switch (ieee80211_vif_type_p2p(&sdata
->vif
)) {
1446 case NL80211_IFTYPE_STATION
:
1447 case NL80211_IFTYPE_ADHOC
:
1448 case NL80211_IFTYPE_MESH_POINT
:
1449 case NL80211_IFTYPE_P2P_CLIENT
:
1451 case NL80211_IFTYPE_P2P_GO
:
1452 if (sdata
->local
->ops
->hw_scan
)
1455 * FIXME: implement NoA while scanning in software,
1456 * for now fall through to allow scanning only when
1457 * beaconing hasn't been configured yet
1459 case NL80211_IFTYPE_AP
:
1460 if (sdata
->u
.ap
.beacon
)
1467 return ieee80211_request_scan(sdata
, req
);
1471 ieee80211_sched_scan_start(struct wiphy
*wiphy
,
1472 struct net_device
*dev
,
1473 struct cfg80211_sched_scan_request
*req
)
1475 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1477 if (!sdata
->local
->ops
->sched_scan_start
)
1480 return ieee80211_request_sched_scan_start(sdata
, req
);
1484 ieee80211_sched_scan_stop(struct wiphy
*wiphy
, struct net_device
*dev
)
1486 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1488 if (!sdata
->local
->ops
->sched_scan_stop
)
1491 return ieee80211_request_sched_scan_stop(sdata
);
1494 static int ieee80211_auth(struct wiphy
*wiphy
, struct net_device
*dev
,
1495 struct cfg80211_auth_request
*req
)
1497 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
1500 static int ieee80211_assoc(struct wiphy
*wiphy
, struct net_device
*dev
,
1501 struct cfg80211_assoc_request
*req
)
1503 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1504 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1506 switch (ieee80211_get_channel_mode(local
, sdata
)) {
1507 case CHAN_MODE_HOPPING
:
1509 case CHAN_MODE_FIXED
:
1510 if (local
->oper_channel
== req
->bss
->channel
)
1513 case CHAN_MODE_UNDEFINED
:
1517 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
1520 static int ieee80211_deauth(struct wiphy
*wiphy
, struct net_device
*dev
,
1521 struct cfg80211_deauth_request
*req
,
1524 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev
),
1528 static int ieee80211_disassoc(struct wiphy
*wiphy
, struct net_device
*dev
,
1529 struct cfg80211_disassoc_request
*req
,
1532 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev
),
1536 static int ieee80211_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
1537 struct cfg80211_ibss_params
*params
)
1539 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1540 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1542 switch (ieee80211_get_channel_mode(local
, sdata
)) {
1543 case CHAN_MODE_HOPPING
:
1545 case CHAN_MODE_FIXED
:
1546 if (!params
->channel_fixed
)
1548 if (local
->oper_channel
== params
->channel
)
1551 case CHAN_MODE_UNDEFINED
:
1555 return ieee80211_ibss_join(sdata
, params
);
1558 static int ieee80211_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
1560 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1562 return ieee80211_ibss_leave(sdata
);
1565 static int ieee80211_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
1567 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1570 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
1571 err
= drv_set_frag_threshold(local
, wiphy
->frag_threshold
);
1577 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
) {
1578 err
= drv_set_coverage_class(local
, wiphy
->coverage_class
);
1584 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
1585 err
= drv_set_rts_threshold(local
, wiphy
->rts_threshold
);
1591 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1592 local
->hw
.conf
.short_frame_max_tx_count
= wiphy
->retry_short
;
1593 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1594 local
->hw
.conf
.long_frame_max_tx_count
= wiphy
->retry_long
;
1596 (WIPHY_PARAM_RETRY_SHORT
| WIPHY_PARAM_RETRY_LONG
))
1597 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_RETRY_LIMITS
);
1602 static int ieee80211_set_tx_power(struct wiphy
*wiphy
,
1603 enum nl80211_tx_power_setting type
, int mbm
)
1605 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1606 struct ieee80211_channel
*chan
= local
->hw
.conf
.channel
;
1610 case NL80211_TX_POWER_AUTOMATIC
:
1611 local
->user_power_level
= -1;
1613 case NL80211_TX_POWER_LIMITED
:
1614 if (mbm
< 0 || (mbm
% 100))
1616 local
->user_power_level
= MBM_TO_DBM(mbm
);
1618 case NL80211_TX_POWER_FIXED
:
1619 if (mbm
< 0 || (mbm
% 100))
1621 /* TODO: move to cfg80211 when it knows the channel */
1622 if (MBM_TO_DBM(mbm
) > chan
->max_power
)
1624 local
->user_power_level
= MBM_TO_DBM(mbm
);
1628 ieee80211_hw_config(local
, changes
);
1633 static int ieee80211_get_tx_power(struct wiphy
*wiphy
, int *dbm
)
1635 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1637 *dbm
= local
->hw
.conf
.power_level
;
1642 static int ieee80211_set_wds_peer(struct wiphy
*wiphy
, struct net_device
*dev
,
1645 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1647 memcpy(&sdata
->u
.wds
.remote_addr
, addr
, ETH_ALEN
);
1652 static void ieee80211_rfkill_poll(struct wiphy
*wiphy
)
1654 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1656 drv_rfkill_poll(local
);
1659 #ifdef CONFIG_NL80211_TESTMODE
1660 static int ieee80211_testmode_cmd(struct wiphy
*wiphy
, void *data
, int len
)
1662 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1664 if (!local
->ops
->testmode_cmd
)
1667 return local
->ops
->testmode_cmd(&local
->hw
, data
, len
);
1670 static int ieee80211_testmode_dump(struct wiphy
*wiphy
,
1671 struct sk_buff
*skb
,
1672 struct netlink_callback
*cb
,
1673 void *data
, int len
)
1675 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1677 if (!local
->ops
->testmode_dump
)
1680 return local
->ops
->testmode_dump(&local
->hw
, skb
, cb
, data
, len
);
1684 int __ieee80211_request_smps(struct ieee80211_sub_if_data
*sdata
,
1685 enum ieee80211_smps_mode smps_mode
)
1688 enum ieee80211_smps_mode old_req
;
1691 lockdep_assert_held(&sdata
->u
.mgd
.mtx
);
1693 old_req
= sdata
->u
.mgd
.req_smps
;
1694 sdata
->u
.mgd
.req_smps
= smps_mode
;
1696 if (old_req
== smps_mode
&&
1697 smps_mode
!= IEEE80211_SMPS_AUTOMATIC
)
1701 * If not associated, or current association is not an HT
1702 * association, there's no need to send an action frame.
1704 if (!sdata
->u
.mgd
.associated
||
1705 sdata
->vif
.bss_conf
.channel_type
== NL80211_CHAN_NO_HT
) {
1706 mutex_lock(&sdata
->local
->iflist_mtx
);
1707 ieee80211_recalc_smps(sdata
->local
);
1708 mutex_unlock(&sdata
->local
->iflist_mtx
);
1712 ap
= sdata
->u
.mgd
.associated
->bssid
;
1714 if (smps_mode
== IEEE80211_SMPS_AUTOMATIC
) {
1715 if (sdata
->u
.mgd
.powersave
)
1716 smps_mode
= IEEE80211_SMPS_DYNAMIC
;
1718 smps_mode
= IEEE80211_SMPS_OFF
;
1721 /* send SM PS frame to AP */
1722 err
= ieee80211_send_smps_action(sdata
, smps_mode
,
1725 sdata
->u
.mgd
.req_smps
= old_req
;
1730 static int ieee80211_set_power_mgmt(struct wiphy
*wiphy
, struct net_device
*dev
,
1731 bool enabled
, int timeout
)
1733 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1734 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1736 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
1739 if (!(local
->hw
.flags
& IEEE80211_HW_SUPPORTS_PS
))
1742 if (enabled
== sdata
->u
.mgd
.powersave
&&
1743 timeout
== local
->dynamic_ps_forced_timeout
)
1746 sdata
->u
.mgd
.powersave
= enabled
;
1747 local
->dynamic_ps_forced_timeout
= timeout
;
1749 /* no change, but if automatic follow powersave */
1750 mutex_lock(&sdata
->u
.mgd
.mtx
);
1751 __ieee80211_request_smps(sdata
, sdata
->u
.mgd
.req_smps
);
1752 mutex_unlock(&sdata
->u
.mgd
.mtx
);
1754 if (local
->hw
.flags
& IEEE80211_HW_SUPPORTS_DYNAMIC_PS
)
1755 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1757 ieee80211_recalc_ps(local
, -1);
1762 static int ieee80211_set_cqm_rssi_config(struct wiphy
*wiphy
,
1763 struct net_device
*dev
,
1764 s32 rssi_thold
, u32 rssi_hyst
)
1766 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1767 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1768 struct ieee80211_vif
*vif
= &sdata
->vif
;
1769 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
1771 if (rssi_thold
== bss_conf
->cqm_rssi_thold
&&
1772 rssi_hyst
== bss_conf
->cqm_rssi_hyst
)
1775 bss_conf
->cqm_rssi_thold
= rssi_thold
;
1776 bss_conf
->cqm_rssi_hyst
= rssi_hyst
;
1778 if (!(local
->hw
.flags
& IEEE80211_HW_SUPPORTS_CQM_RSSI
)) {
1779 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
1784 /* tell the driver upon association, unless already associated */
1785 if (sdata
->u
.mgd
.associated
)
1786 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_CQM
);
1791 static int ieee80211_set_bitrate_mask(struct wiphy
*wiphy
,
1792 struct net_device
*dev
,
1794 const struct cfg80211_bitrate_mask
*mask
)
1796 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1797 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
1800 if (local
->hw
.flags
& IEEE80211_HW_HAS_RATE_CONTROL
) {
1801 ret
= drv_set_bitrate_mask(local
, sdata
, mask
);
1806 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
1807 sdata
->rc_rateidx_mask
[i
] = mask
->control
[i
].legacy
;
1812 static int ieee80211_remain_on_channel_hw(struct ieee80211_local
*local
,
1813 struct net_device
*dev
,
1814 struct ieee80211_channel
*chan
,
1815 enum nl80211_channel_type chantype
,
1816 unsigned int duration
, u64
*cookie
)
1821 lockdep_assert_held(&local
->mtx
);
1823 if (local
->hw_roc_cookie
)
1825 /* must be nonzero */
1826 random_cookie
= random32() | 1;
1828 *cookie
= random_cookie
;
1829 local
->hw_roc_dev
= dev
;
1830 local
->hw_roc_cookie
= random_cookie
;
1831 local
->hw_roc_channel
= chan
;
1832 local
->hw_roc_channel_type
= chantype
;
1833 local
->hw_roc_duration
= duration
;
1834 ret
= drv_remain_on_channel(local
, chan
, chantype
, duration
);
1836 local
->hw_roc_channel
= NULL
;
1837 local
->hw_roc_cookie
= 0;
1843 static int ieee80211_remain_on_channel(struct wiphy
*wiphy
,
1844 struct net_device
*dev
,
1845 struct ieee80211_channel
*chan
,
1846 enum nl80211_channel_type channel_type
,
1847 unsigned int duration
,
1850 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1851 struct ieee80211_local
*local
= sdata
->local
;
1853 if (local
->ops
->remain_on_channel
) {
1856 mutex_lock(&local
->mtx
);
1857 ret
= ieee80211_remain_on_channel_hw(local
, dev
,
1860 local
->hw_roc_for_tx
= false;
1861 mutex_unlock(&local
->mtx
);
1866 return ieee80211_wk_remain_on_channel(sdata
, chan
, channel_type
,
1870 static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local
*local
,
1875 lockdep_assert_held(&local
->mtx
);
1877 if (local
->hw_roc_cookie
!= cookie
)
1880 ret
= drv_cancel_remain_on_channel(local
);
1884 local
->hw_roc_cookie
= 0;
1885 local
->hw_roc_channel
= NULL
;
1887 ieee80211_recalc_idle(local
);
1892 static int ieee80211_cancel_remain_on_channel(struct wiphy
*wiphy
,
1893 struct net_device
*dev
,
1896 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1897 struct ieee80211_local
*local
= sdata
->local
;
1899 if (local
->ops
->cancel_remain_on_channel
) {
1902 mutex_lock(&local
->mtx
);
1903 ret
= ieee80211_cancel_remain_on_channel_hw(local
, cookie
);
1904 mutex_unlock(&local
->mtx
);
1909 return ieee80211_wk_cancel_remain_on_channel(sdata
, cookie
);
1912 static enum work_done_result
1913 ieee80211_offchan_tx_done(struct ieee80211_work
*wk
, struct sk_buff
*skb
)
1916 * Use the data embedded in the work struct for reporting
1917 * here so if the driver mangled the SKB before dropping
1918 * it (which is the only way we really should get here)
1919 * then we don't report mangled data.
1921 * If there was no wait time, then by the time we get here
1922 * the driver will likely not have reported the status yet,
1923 * so in that case userspace will have to deal with it.
1926 if (wk
->offchan_tx
.wait
&& !wk
->offchan_tx
.status
)
1927 cfg80211_mgmt_tx_status(wk
->sdata
->dev
,
1928 (unsigned long) wk
->offchan_tx
.frame
,
1929 wk
->ie
, wk
->ie_len
, false, GFP_KERNEL
);
1931 return WORK_DONE_DESTROY
;
1934 static int ieee80211_mgmt_tx(struct wiphy
*wiphy
, struct net_device
*dev
,
1935 struct ieee80211_channel
*chan
, bool offchan
,
1936 enum nl80211_channel_type channel_type
,
1937 bool channel_type_valid
, unsigned int wait
,
1938 const u8
*buf
, size_t len
, bool no_cck
,
1941 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1942 struct ieee80211_local
*local
= sdata
->local
;
1943 struct sk_buff
*skb
;
1944 struct sta_info
*sta
;
1945 struct ieee80211_work
*wk
;
1946 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
1947 u32 flags
= IEEE80211_TX_INTFL_NL80211_FRAME_TX
|
1948 IEEE80211_TX_CTL_REQ_TX_STATUS
;
1949 bool is_offchan
= false;
1951 /* Check that we are on the requested channel for transmission */
1952 if (chan
!= local
->tmp_channel
&&
1953 chan
!= local
->oper_channel
)
1955 if (channel_type_valid
&&
1956 (channel_type
!= local
->tmp_channel_type
&&
1957 channel_type
!= local
->_oper_channel_type
))
1960 if (chan
== local
->hw_roc_channel
) {
1961 /* TODO: check channel type? */
1963 flags
|= IEEE80211_TX_CTL_TX_OFFCHAN
;
1967 flags
|= IEEE80211_TX_CTL_NO_CCK_RATE
;
1969 if (is_offchan
&& !offchan
)
1972 switch (sdata
->vif
.type
) {
1973 case NL80211_IFTYPE_ADHOC
:
1974 case NL80211_IFTYPE_AP
:
1975 case NL80211_IFTYPE_AP_VLAN
:
1976 case NL80211_IFTYPE_P2P_GO
:
1977 case NL80211_IFTYPE_MESH_POINT
:
1978 if (!ieee80211_is_action(mgmt
->frame_control
) ||
1979 mgmt
->u
.action
.category
== WLAN_CATEGORY_PUBLIC
)
1982 sta
= sta_info_get(sdata
, mgmt
->da
);
1987 case NL80211_IFTYPE_STATION
:
1988 case NL80211_IFTYPE_P2P_CLIENT
:
1994 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ len
);
1997 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1999 memcpy(skb_put(skb
, len
), buf
, len
);
2001 IEEE80211_SKB_CB(skb
)->flags
= flags
;
2003 skb
->dev
= sdata
->dev
;
2005 *cookie
= (unsigned long) skb
;
2007 if (is_offchan
&& local
->ops
->remain_on_channel
) {
2008 unsigned int duration
;
2011 mutex_lock(&local
->mtx
);
2013 * If the duration is zero, then the driver
2014 * wouldn't actually do anything. Set it to
2017 * TODO: cancel the off-channel operation
2018 * when we get the SKB's TX status and
2019 * the wait time was zero before.
2024 ret
= ieee80211_remain_on_channel_hw(local
, dev
, chan
,
2029 mutex_unlock(&local
->mtx
);
2033 local
->hw_roc_for_tx
= true;
2034 local
->hw_roc_duration
= wait
;
2037 * queue up frame for transmission after
2038 * ieee80211_ready_on_channel call
2041 /* modify cookie to prevent API mismatches */
2043 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_TX_OFFCHAN
;
2044 local
->hw_roc_skb
= skb
;
2045 local
->hw_roc_skb_for_status
= skb
;
2046 mutex_unlock(&local
->mtx
);
2052 * Can transmit right away if the channel was the
2053 * right one and there's no wait involved... If a
2054 * wait is involved, we might otherwise not be on
2055 * the right channel for long enough!
2057 if (!is_offchan
&& !wait
&& !sdata
->vif
.bss_conf
.idle
) {
2058 ieee80211_tx_skb(sdata
, skb
);
2062 wk
= kzalloc(sizeof(*wk
) + len
, GFP_KERNEL
);
2068 wk
->type
= IEEE80211_WORK_OFFCHANNEL_TX
;
2070 wk
->chan_type
= channel_type
;
2072 wk
->done
= ieee80211_offchan_tx_done
;
2073 wk
->offchan_tx
.frame
= skb
;
2074 wk
->offchan_tx
.wait
= wait
;
2076 memcpy(wk
->ie
, buf
, len
);
2078 ieee80211_add_work(wk
);
2082 static int ieee80211_mgmt_tx_cancel_wait(struct wiphy
*wiphy
,
2083 struct net_device
*dev
,
2086 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2087 struct ieee80211_local
*local
= sdata
->local
;
2088 struct ieee80211_work
*wk
;
2091 mutex_lock(&local
->mtx
);
2093 if (local
->ops
->cancel_remain_on_channel
) {
2095 ret
= ieee80211_cancel_remain_on_channel_hw(local
, cookie
);
2098 kfree_skb(local
->hw_roc_skb
);
2099 local
->hw_roc_skb
= NULL
;
2100 local
->hw_roc_skb_for_status
= NULL
;
2103 mutex_unlock(&local
->mtx
);
2108 list_for_each_entry(wk
, &local
->work_list
, list
) {
2109 if (wk
->sdata
!= sdata
)
2112 if (wk
->type
!= IEEE80211_WORK_OFFCHANNEL_TX
)
2115 if (cookie
!= (unsigned long) wk
->offchan_tx
.frame
)
2118 wk
->timeout
= jiffies
;
2120 ieee80211_queue_work(&local
->hw
, &local
->work_work
);
2124 mutex_unlock(&local
->mtx
);
2129 static void ieee80211_mgmt_frame_register(struct wiphy
*wiphy
,
2130 struct net_device
*dev
,
2131 u16 frame_type
, bool reg
)
2133 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2135 if (frame_type
!= (IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_PROBE_REQ
))
2139 local
->probe_req_reg
++;
2141 local
->probe_req_reg
--;
2143 ieee80211_queue_work(&local
->hw
, &local
->reconfig_filter
);
2146 static int ieee80211_set_antenna(struct wiphy
*wiphy
, u32 tx_ant
, u32 rx_ant
)
2148 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2153 return drv_set_antenna(local
, tx_ant
, rx_ant
);
2156 static int ieee80211_get_antenna(struct wiphy
*wiphy
, u32
*tx_ant
, u32
*rx_ant
)
2158 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2160 return drv_get_antenna(local
, tx_ant
, rx_ant
);
2163 static int ieee80211_set_ringparam(struct wiphy
*wiphy
, u32 tx
, u32 rx
)
2165 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2167 return drv_set_ringparam(local
, tx
, rx
);
2170 static void ieee80211_get_ringparam(struct wiphy
*wiphy
,
2171 u32
*tx
, u32
*tx_max
, u32
*rx
, u32
*rx_max
)
2173 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2175 drv_get_ringparam(local
, tx
, tx_max
, rx
, rx_max
);
2178 static int ieee80211_set_rekey_data(struct wiphy
*wiphy
,
2179 struct net_device
*dev
,
2180 struct cfg80211_gtk_rekey_data
*data
)
2182 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2183 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2185 if (!local
->ops
->set_rekey_data
)
2188 drv_set_rekey_data(local
, sdata
, data
);
2193 static void ieee80211_tdls_add_ext_capab(struct sk_buff
*skb
)
2195 u8
*pos
= (void *)skb_put(skb
, 7);
2197 *pos
++ = WLAN_EID_EXT_CAPABILITY
;
2198 *pos
++ = 5; /* len */
2203 *pos
++ = WLAN_EXT_CAPA5_TDLS_ENABLED
;
2206 static u16
ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data
*sdata
)
2208 struct ieee80211_local
*local
= sdata
->local
;
2212 if (local
->oper_channel
->band
!= IEEE80211_BAND_2GHZ
)
2215 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
))
2216 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
2217 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
))
2218 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
2223 static void ieee80211_tdls_add_link_ie(struct sk_buff
*skb
, u8
*src_addr
,
2224 u8
*peer
, u8
*bssid
)
2226 struct ieee80211_tdls_lnkie
*lnkid
;
2228 lnkid
= (void *)skb_put(skb
, sizeof(struct ieee80211_tdls_lnkie
));
2230 lnkid
->ie_type
= WLAN_EID_LINK_ID
;
2231 lnkid
->ie_len
= sizeof(struct ieee80211_tdls_lnkie
) - 2;
2233 memcpy(lnkid
->bssid
, bssid
, ETH_ALEN
);
2234 memcpy(lnkid
->init_sta
, src_addr
, ETH_ALEN
);
2235 memcpy(lnkid
->resp_sta
, peer
, ETH_ALEN
);
2239 ieee80211_prep_tdls_encap_data(struct wiphy
*wiphy
, struct net_device
*dev
,
2240 u8
*peer
, u8 action_code
, u8 dialog_token
,
2241 u16 status_code
, struct sk_buff
*skb
)
2243 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2244 struct ieee80211_tdls_data
*tf
;
2246 tf
= (void *)skb_put(skb
, offsetof(struct ieee80211_tdls_data
, u
));
2248 memcpy(tf
->da
, peer
, ETH_ALEN
);
2249 memcpy(tf
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
2250 tf
->ether_type
= cpu_to_be16(ETH_P_TDLS
);
2251 tf
->payload_type
= WLAN_TDLS_SNAP_RFTYPE
;
2253 switch (action_code
) {
2254 case WLAN_TDLS_SETUP_REQUEST
:
2255 tf
->category
= WLAN_CATEGORY_TDLS
;
2256 tf
->action_code
= WLAN_TDLS_SETUP_REQUEST
;
2258 skb_put(skb
, sizeof(tf
->u
.setup_req
));
2259 tf
->u
.setup_req
.dialog_token
= dialog_token
;
2260 tf
->u
.setup_req
.capability
=
2261 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata
));
2263 ieee80211_add_srates_ie(&sdata
->vif
, skb
);
2264 ieee80211_add_ext_srates_ie(&sdata
->vif
, skb
);
2265 ieee80211_tdls_add_ext_capab(skb
);
2267 case WLAN_TDLS_SETUP_RESPONSE
:
2268 tf
->category
= WLAN_CATEGORY_TDLS
;
2269 tf
->action_code
= WLAN_TDLS_SETUP_RESPONSE
;
2271 skb_put(skb
, sizeof(tf
->u
.setup_resp
));
2272 tf
->u
.setup_resp
.status_code
= cpu_to_le16(status_code
);
2273 tf
->u
.setup_resp
.dialog_token
= dialog_token
;
2274 tf
->u
.setup_resp
.capability
=
2275 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata
));
2277 ieee80211_add_srates_ie(&sdata
->vif
, skb
);
2278 ieee80211_add_ext_srates_ie(&sdata
->vif
, skb
);
2279 ieee80211_tdls_add_ext_capab(skb
);
2281 case WLAN_TDLS_SETUP_CONFIRM
:
2282 tf
->category
= WLAN_CATEGORY_TDLS
;
2283 tf
->action_code
= WLAN_TDLS_SETUP_CONFIRM
;
2285 skb_put(skb
, sizeof(tf
->u
.setup_cfm
));
2286 tf
->u
.setup_cfm
.status_code
= cpu_to_le16(status_code
);
2287 tf
->u
.setup_cfm
.dialog_token
= dialog_token
;
2289 case WLAN_TDLS_TEARDOWN
:
2290 tf
->category
= WLAN_CATEGORY_TDLS
;
2291 tf
->action_code
= WLAN_TDLS_TEARDOWN
;
2293 skb_put(skb
, sizeof(tf
->u
.teardown
));
2294 tf
->u
.teardown
.reason_code
= cpu_to_le16(status_code
);
2296 case WLAN_TDLS_DISCOVERY_REQUEST
:
2297 tf
->category
= WLAN_CATEGORY_TDLS
;
2298 tf
->action_code
= WLAN_TDLS_DISCOVERY_REQUEST
;
2300 skb_put(skb
, sizeof(tf
->u
.discover_req
));
2301 tf
->u
.discover_req
.dialog_token
= dialog_token
;
2311 ieee80211_prep_tdls_direct(struct wiphy
*wiphy
, struct net_device
*dev
,
2312 u8
*peer
, u8 action_code
, u8 dialog_token
,
2313 u16 status_code
, struct sk_buff
*skb
)
2315 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2316 struct ieee80211_mgmt
*mgmt
;
2318 mgmt
= (void *)skb_put(skb
, 24);
2319 memset(mgmt
, 0, 24);
2320 memcpy(mgmt
->da
, peer
, ETH_ALEN
);
2321 memcpy(mgmt
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
2322 memcpy(mgmt
->bssid
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
2324 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
2325 IEEE80211_STYPE_ACTION
);
2327 switch (action_code
) {
2328 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
2329 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.tdls_discover_resp
));
2330 mgmt
->u
.action
.category
= WLAN_CATEGORY_PUBLIC
;
2331 mgmt
->u
.action
.u
.tdls_discover_resp
.action_code
=
2332 WLAN_PUB_ACTION_TDLS_DISCOVER_RES
;
2333 mgmt
->u
.action
.u
.tdls_discover_resp
.dialog_token
=
2335 mgmt
->u
.action
.u
.tdls_discover_resp
.capability
=
2336 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata
));
2338 ieee80211_add_srates_ie(&sdata
->vif
, skb
);
2339 ieee80211_add_ext_srates_ie(&sdata
->vif
, skb
);
2340 ieee80211_tdls_add_ext_capab(skb
);
2349 static int ieee80211_tdls_mgmt(struct wiphy
*wiphy
, struct net_device
*dev
,
2350 u8
*peer
, u8 action_code
, u8 dialog_token
,
2351 u16 status_code
, const u8
*extra_ies
,
2352 size_t extra_ies_len
)
2354 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2355 struct ieee80211_local
*local
= sdata
->local
;
2356 struct ieee80211_tx_info
*info
;
2357 struct sk_buff
*skb
= NULL
;
2361 if (!(wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
2364 /* make sure we are in managed mode, and associated */
2365 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
||
2366 !sdata
->u
.mgd
.associated
)
2369 #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2370 printk(KERN_DEBUG
"TDLS mgmt action %d peer %pM\n", action_code
, peer
);
2373 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+
2374 max(sizeof(struct ieee80211_mgmt
),
2375 sizeof(struct ieee80211_tdls_data
)) +
2376 50 + /* supported rates */
2379 sizeof(struct ieee80211_tdls_lnkie
));
2383 info
= IEEE80211_SKB_CB(skb
);
2384 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2386 switch (action_code
) {
2387 case WLAN_TDLS_SETUP_REQUEST
:
2388 case WLAN_TDLS_SETUP_RESPONSE
:
2389 case WLAN_TDLS_SETUP_CONFIRM
:
2390 case WLAN_TDLS_TEARDOWN
:
2391 case WLAN_TDLS_DISCOVERY_REQUEST
:
2392 ret
= ieee80211_prep_tdls_encap_data(wiphy
, dev
, peer
,
2393 action_code
, dialog_token
,
2395 send_direct
= false;
2397 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
2398 ret
= ieee80211_prep_tdls_direct(wiphy
, dev
, peer
, action_code
,
2399 dialog_token
, status_code
,
2412 memcpy(skb_put(skb
, extra_ies_len
), extra_ies
, extra_ies_len
);
2414 /* the TDLS link IE is always added last */
2415 switch (action_code
) {
2416 case WLAN_TDLS_SETUP_REQUEST
:
2417 case WLAN_TDLS_SETUP_CONFIRM
:
2418 case WLAN_TDLS_TEARDOWN
:
2419 case WLAN_TDLS_DISCOVERY_REQUEST
:
2420 /* we are the initiator */
2421 ieee80211_tdls_add_link_ie(skb
, sdata
->vif
.addr
, peer
,
2422 sdata
->u
.mgd
.bssid
);
2424 case WLAN_TDLS_SETUP_RESPONSE
:
2425 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
2426 /* we are the responder */
2427 ieee80211_tdls_add_link_ie(skb
, peer
, sdata
->vif
.addr
,
2428 sdata
->u
.mgd
.bssid
);
2436 ieee80211_tx_skb(sdata
, skb
);
2441 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2442 * we should default to AC_VI.
2444 switch (action_code
) {
2445 case WLAN_TDLS_SETUP_REQUEST
:
2446 case WLAN_TDLS_SETUP_RESPONSE
:
2447 skb_set_queue_mapping(skb
, IEEE80211_AC_BK
);
2451 skb_set_queue_mapping(skb
, IEEE80211_AC_VI
);
2456 /* disable bottom halves when entering the Tx path */
2458 ret
= ieee80211_subif_start_xmit(skb
, dev
);
2468 static int ieee80211_tdls_oper(struct wiphy
*wiphy
, struct net_device
*dev
,
2469 u8
*peer
, enum nl80211_tdls_operation oper
)
2471 struct sta_info
*sta
;
2472 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2474 if (!(wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
2477 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
2480 #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2481 printk(KERN_DEBUG
"TDLS oper %d peer %pM\n", oper
, peer
);
2485 case NL80211_TDLS_ENABLE_LINK
:
2487 sta
= sta_info_get(sdata
, peer
);
2493 set_sta_flag(sta
, WLAN_STA_TDLS_PEER_AUTH
);
2496 case NL80211_TDLS_DISABLE_LINK
:
2497 return sta_info_destroy_addr(sdata
, peer
);
2498 case NL80211_TDLS_TEARDOWN
:
2499 case NL80211_TDLS_SETUP
:
2500 case NL80211_TDLS_DISCOVERY_REQ
:
2501 /* We don't support in-driver setup/teardown/discovery */
2510 static int ieee80211_probe_client(struct wiphy
*wiphy
, struct net_device
*dev
,
2511 const u8
*peer
, u64
*cookie
)
2513 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2514 struct ieee80211_local
*local
= sdata
->local
;
2515 struct ieee80211_qos_hdr
*nullfunc
;
2516 struct sk_buff
*skb
;
2517 int size
= sizeof(*nullfunc
);
2520 struct ieee80211_tx_info
*info
;
2521 struct sta_info
*sta
;
2524 sta
= sta_info_get(sdata
, peer
);
2526 qos
= test_sta_flag(sta
, WLAN_STA_WME
);
2533 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
2534 IEEE80211_STYPE_QOS_NULLFUNC
|
2535 IEEE80211_FCTL_FROMDS
);
2538 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
2539 IEEE80211_STYPE_NULLFUNC
|
2540 IEEE80211_FCTL_FROMDS
);
2543 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ size
);
2549 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
2551 nullfunc
= (void *) skb_put(skb
, size
);
2552 nullfunc
->frame_control
= fc
;
2553 nullfunc
->duration_id
= 0;
2554 memcpy(nullfunc
->addr1
, sta
->sta
.addr
, ETH_ALEN
);
2555 memcpy(nullfunc
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
2556 memcpy(nullfunc
->addr3
, sdata
->vif
.addr
, ETH_ALEN
);
2557 nullfunc
->seq_ctrl
= 0;
2559 info
= IEEE80211_SKB_CB(skb
);
2561 info
->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
|
2562 IEEE80211_TX_INTFL_NL80211_FRAME_TX
;
2564 skb_set_queue_mapping(skb
, IEEE80211_AC_VO
);
2567 nullfunc
->qos_ctrl
= cpu_to_le16(7);
2570 ieee80211_xmit(sdata
, skb
);
2573 *cookie
= (unsigned long) skb
;
2577 struct cfg80211_ops mac80211_config_ops
= {
2578 .add_virtual_intf
= ieee80211_add_iface
,
2579 .del_virtual_intf
= ieee80211_del_iface
,
2580 .change_virtual_intf
= ieee80211_change_iface
,
2581 .add_key
= ieee80211_add_key
,
2582 .del_key
= ieee80211_del_key
,
2583 .get_key
= ieee80211_get_key
,
2584 .set_default_key
= ieee80211_config_default_key
,
2585 .set_default_mgmt_key
= ieee80211_config_default_mgmt_key
,
2586 .add_beacon
= ieee80211_add_beacon
,
2587 .set_beacon
= ieee80211_set_beacon
,
2588 .del_beacon
= ieee80211_del_beacon
,
2589 .add_station
= ieee80211_add_station
,
2590 .del_station
= ieee80211_del_station
,
2591 .change_station
= ieee80211_change_station
,
2592 .get_station
= ieee80211_get_station
,
2593 .dump_station
= ieee80211_dump_station
,
2594 .dump_survey
= ieee80211_dump_survey
,
2595 #ifdef CONFIG_MAC80211_MESH
2596 .add_mpath
= ieee80211_add_mpath
,
2597 .del_mpath
= ieee80211_del_mpath
,
2598 .change_mpath
= ieee80211_change_mpath
,
2599 .get_mpath
= ieee80211_get_mpath
,
2600 .dump_mpath
= ieee80211_dump_mpath
,
2601 .update_mesh_config
= ieee80211_update_mesh_config
,
2602 .get_mesh_config
= ieee80211_get_mesh_config
,
2603 .join_mesh
= ieee80211_join_mesh
,
2604 .leave_mesh
= ieee80211_leave_mesh
,
2606 .change_bss
= ieee80211_change_bss
,
2607 .set_txq_params
= ieee80211_set_txq_params
,
2608 .set_channel
= ieee80211_set_channel
,
2609 .suspend
= ieee80211_suspend
,
2610 .resume
= ieee80211_resume
,
2611 .scan
= ieee80211_scan
,
2612 .sched_scan_start
= ieee80211_sched_scan_start
,
2613 .sched_scan_stop
= ieee80211_sched_scan_stop
,
2614 .auth
= ieee80211_auth
,
2615 .assoc
= ieee80211_assoc
,
2616 .deauth
= ieee80211_deauth
,
2617 .disassoc
= ieee80211_disassoc
,
2618 .join_ibss
= ieee80211_join_ibss
,
2619 .leave_ibss
= ieee80211_leave_ibss
,
2620 .set_wiphy_params
= ieee80211_set_wiphy_params
,
2621 .set_tx_power
= ieee80211_set_tx_power
,
2622 .get_tx_power
= ieee80211_get_tx_power
,
2623 .set_wds_peer
= ieee80211_set_wds_peer
,
2624 .rfkill_poll
= ieee80211_rfkill_poll
,
2625 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd
)
2626 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump
)
2627 .set_power_mgmt
= ieee80211_set_power_mgmt
,
2628 .set_bitrate_mask
= ieee80211_set_bitrate_mask
,
2629 .remain_on_channel
= ieee80211_remain_on_channel
,
2630 .cancel_remain_on_channel
= ieee80211_cancel_remain_on_channel
,
2631 .mgmt_tx
= ieee80211_mgmt_tx
,
2632 .mgmt_tx_cancel_wait
= ieee80211_mgmt_tx_cancel_wait
,
2633 .set_cqm_rssi_config
= ieee80211_set_cqm_rssi_config
,
2634 .mgmt_frame_register
= ieee80211_mgmt_frame_register
,
2635 .set_antenna
= ieee80211_set_antenna
,
2636 .get_antenna
= ieee80211_get_antenna
,
2637 .set_ringparam
= ieee80211_set_ringparam
,
2638 .get_ringparam
= ieee80211_get_ringparam
,
2639 .set_rekey_data
= ieee80211_set_rekey_data
,
2640 .tdls_oper
= ieee80211_tdls_oper
,
2641 .tdls_mgmt
= ieee80211_tdls_mgmt
,
2642 .probe_client
= ieee80211_probe_client
,