2 * mac80211 TDLS handling code
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2014, Intel Corporation
6 * Copyright 2014 Intel Mobile Communications GmbH
8 * This file is GPLv2 as found in COPYING.
11 #include <linux/ieee80211.h>
12 #include <linux/log2.h>
13 #include <net/cfg80211.h>
14 #include "ieee80211_i.h"
15 #include "driver-ops.h"
17 /* give usermode some time for retries in setting up the TDLS session */
18 #define TDLS_PEER_SETUP_TIMEOUT (15 * HZ)
20 void ieee80211_tdls_peer_del_work(struct work_struct
*wk
)
22 struct ieee80211_sub_if_data
*sdata
;
23 struct ieee80211_local
*local
;
25 sdata
= container_of(wk
, struct ieee80211_sub_if_data
,
26 u
.mgd
.tdls_peer_del_work
.work
);
29 mutex_lock(&local
->mtx
);
30 if (!is_zero_ether_addr(sdata
->u
.mgd
.tdls_peer
)) {
31 tdls_dbg(sdata
, "TDLS del peer %pM\n", sdata
->u
.mgd
.tdls_peer
);
32 sta_info_destroy_addr(sdata
, sdata
->u
.mgd
.tdls_peer
);
33 eth_zero_addr(sdata
->u
.mgd
.tdls_peer
);
35 mutex_unlock(&local
->mtx
);
38 static void ieee80211_tdls_add_ext_capab(struct sk_buff
*skb
)
40 u8
*pos
= (void *)skb_put(skb
, 7);
42 *pos
++ = WLAN_EID_EXT_CAPABILITY
;
48 *pos
++ = WLAN_EXT_CAPA5_TDLS_ENABLED
;
51 static u16
ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data
*sdata
,
54 struct ieee80211_local
*local
= sdata
->local
;
57 /* The capability will be 0 when sending a failure code */
62 if (ieee80211_get_sdata_band(sdata
) != IEEE80211_BAND_2GHZ
)
65 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
))
66 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
67 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
))
68 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
73 static void ieee80211_tdls_add_link_ie(struct ieee80211_sub_if_data
*sdata
,
74 struct sk_buff
*skb
, const u8
*peer
,
77 struct ieee80211_tdls_lnkie
*lnkid
;
78 const u8
*init_addr
, *rsp_addr
;
81 init_addr
= sdata
->vif
.addr
;
85 rsp_addr
= sdata
->vif
.addr
;
88 lnkid
= (void *)skb_put(skb
, sizeof(struct ieee80211_tdls_lnkie
));
90 lnkid
->ie_type
= WLAN_EID_LINK_ID
;
91 lnkid
->ie_len
= sizeof(struct ieee80211_tdls_lnkie
) - 2;
93 memcpy(lnkid
->bssid
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
94 memcpy(lnkid
->init_sta
, init_addr
, ETH_ALEN
);
95 memcpy(lnkid
->resp_sta
, rsp_addr
, ETH_ALEN
);
98 /* translate numbering in the WMM parameter IE to the mac80211 notation */
99 static enum ieee80211_ac_numbers
ieee80211_ac_from_wmm(int ac
)
105 return IEEE80211_AC_BE
;
107 return IEEE80211_AC_BK
;
109 return IEEE80211_AC_VI
;
111 return IEEE80211_AC_VO
;
115 static u8
ieee80211_wmm_aci_aifsn(int aifsn
, bool acm
, int aci
)
122 ret
|= (aci
<< 5) & 0x60;
126 static u8
ieee80211_wmm_ecw(u16 cw_min
, u16 cw_max
)
128 return ((ilog2(cw_min
+ 1) << 0x0) & 0x0f) |
129 ((ilog2(cw_max
+ 1) << 0x4) & 0xf0);
132 static void ieee80211_tdls_add_wmm_param_ie(struct ieee80211_sub_if_data
*sdata
,
135 struct ieee80211_wmm_param_ie
*wmm
;
136 struct ieee80211_tx_queue_params
*txq
;
139 wmm
= (void *)skb_put(skb
, sizeof(*wmm
));
140 memset(wmm
, 0, sizeof(*wmm
));
142 wmm
->element_id
= WLAN_EID_VENDOR_SPECIFIC
;
143 wmm
->len
= sizeof(*wmm
) - 2;
145 wmm
->oui
[0] = 0x00; /* Microsoft OUI 00:50:F2 */
148 wmm
->oui_type
= 2; /* WME */
149 wmm
->oui_subtype
= 1; /* WME param */
150 wmm
->version
= 1; /* WME ver */
151 wmm
->qos_info
= 0; /* U-APSD not in use */
154 * Use the EDCA parameters defined for the BSS, or default if the AP
155 * doesn't support it, as mandated by 802.11-2012 section 10.22.4
157 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++) {
158 txq
= &sdata
->tx_conf
[ieee80211_ac_from_wmm(i
)];
159 wmm
->ac
[i
].aci_aifsn
= ieee80211_wmm_aci_aifsn(txq
->aifs
,
161 wmm
->ac
[i
].cw
= ieee80211_wmm_ecw(txq
->cw_min
, txq
->cw_max
);
162 wmm
->ac
[i
].txop_limit
= cpu_to_le16(txq
->txop
);
167 ieee80211_tdls_add_setup_start_ies(struct ieee80211_sub_if_data
*sdata
,
168 struct sk_buff
*skb
, const u8
*peer
,
169 u8 action_code
, bool initiator
,
170 const u8
*extra_ies
, size_t extra_ies_len
)
172 enum ieee80211_band band
= ieee80211_get_sdata_band(sdata
);
173 struct ieee80211_local
*local
= sdata
->local
;
174 struct ieee80211_supported_band
*sband
;
175 struct ieee80211_sta_ht_cap ht_cap
;
176 struct sta_info
*sta
= NULL
;
177 size_t offset
= 0, noffset
;
182 /* we should have the peer STA if we're already responding */
183 if (action_code
== WLAN_TDLS_SETUP_RESPONSE
) {
184 sta
= sta_info_get(sdata
, peer
);
185 if (WARN_ON_ONCE(!sta
)) {
191 ieee80211_add_srates_ie(sdata
, skb
, false, band
);
192 ieee80211_add_ext_srates_ie(sdata
, skb
, false, band
);
194 /* add any custom IEs that go before Extended Capabilities */
196 static const u8 before_ext_cap
[] = {
199 WLAN_EID_EXT_SUPP_RATES
,
200 WLAN_EID_SUPPORTED_CHANNELS
,
203 noffset
= ieee80211_ie_split(extra_ies
, extra_ies_len
,
205 ARRAY_SIZE(before_ext_cap
),
207 pos
= skb_put(skb
, noffset
- offset
);
208 memcpy(pos
, extra_ies
+ offset
, noffset
- offset
);
212 ieee80211_tdls_add_ext_capab(skb
);
214 /* add the QoS element if we support it */
215 if (local
->hw
.queues
>= IEEE80211_NUM_ACS
&&
216 action_code
!= WLAN_PUB_ACTION_TDLS_DISCOVER_RES
)
217 ieee80211_add_wmm_info_ie(skb_put(skb
, 9), 0); /* no U-APSD */
219 /* add any custom IEs that go before HT capabilities */
221 static const u8 before_ht_cap
[] = {
224 WLAN_EID_EXT_SUPP_RATES
,
225 WLAN_EID_SUPPORTED_CHANNELS
,
227 WLAN_EID_EXT_CAPABILITY
,
229 WLAN_EID_FAST_BSS_TRANSITION
,
230 WLAN_EID_TIMEOUT_INTERVAL
,
231 WLAN_EID_SUPPORTED_REGULATORY_CLASSES
,
233 noffset
= ieee80211_ie_split(extra_ies
, extra_ies_len
,
235 ARRAY_SIZE(before_ht_cap
),
237 pos
= skb_put(skb
, noffset
- offset
);
238 memcpy(pos
, extra_ies
+ offset
, noffset
- offset
);
243 * with TDLS we can switch channels, and HT-caps are not necessarily
244 * the same on all bands. The specification limits the setup to a
245 * single HT-cap, so use the current band for now.
247 sband
= local
->hw
.wiphy
->bands
[band
];
248 memcpy(&ht_cap
, &sband
->ht_cap
, sizeof(ht_cap
));
249 if ((action_code
== WLAN_TDLS_SETUP_REQUEST
||
250 action_code
== WLAN_TDLS_SETUP_RESPONSE
) &&
251 ht_cap
.ht_supported
&& (!sta
|| sta
->sta
.ht_cap
.ht_supported
)) {
252 if (action_code
== WLAN_TDLS_SETUP_REQUEST
) {
253 ieee80211_apply_htcap_overrides(sdata
, &ht_cap
);
255 /* disable SMPS in TDLS initiator */
256 ht_cap
.cap
|= (WLAN_HT_CAP_SM_PS_DISABLED
257 << IEEE80211_HT_CAP_SM_PS_SHIFT
);
259 /* disable SMPS in TDLS responder */
260 sta
->sta
.ht_cap
.cap
|=
261 (WLAN_HT_CAP_SM_PS_DISABLED
262 << IEEE80211_HT_CAP_SM_PS_SHIFT
);
264 /* the peer caps are already intersected with our own */
265 memcpy(&ht_cap
, &sta
->sta
.ht_cap
, sizeof(ht_cap
));
268 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
) + 2);
269 ieee80211_ie_build_ht_cap(pos
, &ht_cap
, ht_cap
.cap
);
274 /* add any remaining IEs */
276 noffset
= extra_ies_len
;
277 pos
= skb_put(skb
, noffset
- offset
);
278 memcpy(pos
, extra_ies
+ offset
, noffset
- offset
);
281 ieee80211_tdls_add_link_ie(sdata
, skb
, peer
, initiator
);
285 ieee80211_tdls_add_setup_cfm_ies(struct ieee80211_sub_if_data
*sdata
,
286 struct sk_buff
*skb
, const u8
*peer
,
287 bool initiator
, const u8
*extra_ies
,
288 size_t extra_ies_len
)
290 struct ieee80211_local
*local
= sdata
->local
;
291 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
292 size_t offset
= 0, noffset
;
293 struct sta_info
*sta
, *ap_sta
;
298 sta
= sta_info_get(sdata
, peer
);
299 ap_sta
= sta_info_get(sdata
, ifmgd
->bssid
);
300 if (WARN_ON_ONCE(!sta
|| !ap_sta
)) {
305 /* add any custom IEs that go before the QoS IE */
307 static const u8 before_qos
[] = {
310 noffset
= ieee80211_ie_split(extra_ies
, extra_ies_len
,
312 ARRAY_SIZE(before_qos
),
314 pos
= skb_put(skb
, noffset
- offset
);
315 memcpy(pos
, extra_ies
+ offset
, noffset
- offset
);
319 /* add the QoS param IE if both the peer and we support it */
320 if (local
->hw
.queues
>= IEEE80211_NUM_ACS
&& sta
->sta
.wme
)
321 ieee80211_tdls_add_wmm_param_ie(sdata
, skb
);
323 /* add any custom IEs that go before HT operation */
325 static const u8 before_ht_op
[] = {
328 WLAN_EID_FAST_BSS_TRANSITION
,
329 WLAN_EID_TIMEOUT_INTERVAL
,
331 noffset
= ieee80211_ie_split(extra_ies
, extra_ies_len
,
333 ARRAY_SIZE(before_ht_op
),
335 pos
= skb_put(skb
, noffset
- offset
);
336 memcpy(pos
, extra_ies
+ offset
, noffset
- offset
);
340 /* if HT support is only added in TDLS, we need an HT-operation IE */
341 if (!ap_sta
->sta
.ht_cap
.ht_supported
&& sta
->sta
.ht_cap
.ht_supported
) {
342 struct ieee80211_chanctx_conf
*chanctx_conf
=
343 rcu_dereference(sdata
->vif
.chanctx_conf
);
344 if (!WARN_ON(!chanctx_conf
)) {
345 pos
= skb_put(skb
, 2 +
346 sizeof(struct ieee80211_ht_operation
));
347 /* send an empty HT operation IE */
348 ieee80211_ie_build_ht_oper(pos
, &sta
->sta
.ht_cap
,
349 &chanctx_conf
->def
, 0);
355 /* add any remaining IEs */
357 noffset
= extra_ies_len
;
358 pos
= skb_put(skb
, noffset
- offset
);
359 memcpy(pos
, extra_ies
+ offset
, noffset
- offset
);
362 ieee80211_tdls_add_link_ie(sdata
, skb
, peer
, initiator
);
365 static void ieee80211_tdls_add_ies(struct ieee80211_sub_if_data
*sdata
,
366 struct sk_buff
*skb
, const u8
*peer
,
367 u8 action_code
, u16 status_code
,
368 bool initiator
, const u8
*extra_ies
,
369 size_t extra_ies_len
)
371 switch (action_code
) {
372 case WLAN_TDLS_SETUP_REQUEST
:
373 case WLAN_TDLS_SETUP_RESPONSE
:
374 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
375 if (status_code
== 0)
376 ieee80211_tdls_add_setup_start_ies(sdata
, skb
, peer
,
382 case WLAN_TDLS_SETUP_CONFIRM
:
383 if (status_code
== 0)
384 ieee80211_tdls_add_setup_cfm_ies(sdata
, skb
, peer
,
385 initiator
, extra_ies
,
388 case WLAN_TDLS_TEARDOWN
:
389 case WLAN_TDLS_DISCOVERY_REQUEST
:
391 memcpy(skb_put(skb
, extra_ies_len
), extra_ies
,
393 if (status_code
== 0 || action_code
== WLAN_TDLS_TEARDOWN
)
394 ieee80211_tdls_add_link_ie(sdata
, skb
, peer
, initiator
);
401 ieee80211_prep_tdls_encap_data(struct wiphy
*wiphy
, struct net_device
*dev
,
402 const u8
*peer
, u8 action_code
, u8 dialog_token
,
403 u16 status_code
, struct sk_buff
*skb
)
405 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
406 struct ieee80211_tdls_data
*tf
;
408 tf
= (void *)skb_put(skb
, offsetof(struct ieee80211_tdls_data
, u
));
410 memcpy(tf
->da
, peer
, ETH_ALEN
);
411 memcpy(tf
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
412 tf
->ether_type
= cpu_to_be16(ETH_P_TDLS
);
413 tf
->payload_type
= WLAN_TDLS_SNAP_RFTYPE
;
415 /* network header is after the ethernet header */
416 skb_set_network_header(skb
, ETH_HLEN
);
418 switch (action_code
) {
419 case WLAN_TDLS_SETUP_REQUEST
:
420 tf
->category
= WLAN_CATEGORY_TDLS
;
421 tf
->action_code
= WLAN_TDLS_SETUP_REQUEST
;
423 skb_put(skb
, sizeof(tf
->u
.setup_req
));
424 tf
->u
.setup_req
.dialog_token
= dialog_token
;
425 tf
->u
.setup_req
.capability
=
426 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata
,
429 case WLAN_TDLS_SETUP_RESPONSE
:
430 tf
->category
= WLAN_CATEGORY_TDLS
;
431 tf
->action_code
= WLAN_TDLS_SETUP_RESPONSE
;
433 skb_put(skb
, sizeof(tf
->u
.setup_resp
));
434 tf
->u
.setup_resp
.status_code
= cpu_to_le16(status_code
);
435 tf
->u
.setup_resp
.dialog_token
= dialog_token
;
436 tf
->u
.setup_resp
.capability
=
437 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata
,
440 case WLAN_TDLS_SETUP_CONFIRM
:
441 tf
->category
= WLAN_CATEGORY_TDLS
;
442 tf
->action_code
= WLAN_TDLS_SETUP_CONFIRM
;
444 skb_put(skb
, sizeof(tf
->u
.setup_cfm
));
445 tf
->u
.setup_cfm
.status_code
= cpu_to_le16(status_code
);
446 tf
->u
.setup_cfm
.dialog_token
= dialog_token
;
448 case WLAN_TDLS_TEARDOWN
:
449 tf
->category
= WLAN_CATEGORY_TDLS
;
450 tf
->action_code
= WLAN_TDLS_TEARDOWN
;
452 skb_put(skb
, sizeof(tf
->u
.teardown
));
453 tf
->u
.teardown
.reason_code
= cpu_to_le16(status_code
);
455 case WLAN_TDLS_DISCOVERY_REQUEST
:
456 tf
->category
= WLAN_CATEGORY_TDLS
;
457 tf
->action_code
= WLAN_TDLS_DISCOVERY_REQUEST
;
459 skb_put(skb
, sizeof(tf
->u
.discover_req
));
460 tf
->u
.discover_req
.dialog_token
= dialog_token
;
470 ieee80211_prep_tdls_direct(struct wiphy
*wiphy
, struct net_device
*dev
,
471 const u8
*peer
, u8 action_code
, u8 dialog_token
,
472 u16 status_code
, struct sk_buff
*skb
)
474 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
475 struct ieee80211_mgmt
*mgmt
;
477 mgmt
= (void *)skb_put(skb
, 24);
479 memcpy(mgmt
->da
, peer
, ETH_ALEN
);
480 memcpy(mgmt
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
481 memcpy(mgmt
->bssid
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
483 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
484 IEEE80211_STYPE_ACTION
);
486 switch (action_code
) {
487 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
488 skb_put(skb
, 1 + sizeof(mgmt
->u
.action
.u
.tdls_discover_resp
));
489 mgmt
->u
.action
.category
= WLAN_CATEGORY_PUBLIC
;
490 mgmt
->u
.action
.u
.tdls_discover_resp
.action_code
=
491 WLAN_PUB_ACTION_TDLS_DISCOVER_RES
;
492 mgmt
->u
.action
.u
.tdls_discover_resp
.dialog_token
=
494 mgmt
->u
.action
.u
.tdls_discover_resp
.capability
=
495 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata
,
506 ieee80211_tdls_prep_mgmt_packet(struct wiphy
*wiphy
, struct net_device
*dev
,
507 const u8
*peer
, u8 action_code
,
508 u8 dialog_token
, u16 status_code
,
509 u32 peer_capability
, bool initiator
,
510 const u8
*extra_ies
, size_t extra_ies_len
)
512 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
513 struct ieee80211_local
*local
= sdata
->local
;
514 struct sk_buff
*skb
= NULL
;
517 struct sta_info
*sta
;
520 skb
= netdev_alloc_skb(dev
,
521 local
->hw
.extra_tx_headroom
+
522 max(sizeof(struct ieee80211_mgmt
),
523 sizeof(struct ieee80211_tdls_data
)) +
524 50 + /* supported rates */
526 26 + /* max(WMM-info, WMM-param) */
527 2 + max(sizeof(struct ieee80211_ht_cap
),
528 sizeof(struct ieee80211_ht_operation
)) +
530 sizeof(struct ieee80211_tdls_lnkie
));
534 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
536 switch (action_code
) {
537 case WLAN_TDLS_SETUP_REQUEST
:
538 case WLAN_TDLS_SETUP_RESPONSE
:
539 case WLAN_TDLS_SETUP_CONFIRM
:
540 case WLAN_TDLS_TEARDOWN
:
541 case WLAN_TDLS_DISCOVERY_REQUEST
:
542 ret
= ieee80211_prep_tdls_encap_data(wiphy
, dev
, peer
,
543 action_code
, dialog_token
,
547 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
548 ret
= ieee80211_prep_tdls_direct(wiphy
, dev
, peer
, action_code
,
549 dialog_token
, status_code
,
562 sta
= sta_info_get(sdata
, peer
);
564 /* infer the initiator if we can, to support old userspace */
565 switch (action_code
) {
566 case WLAN_TDLS_SETUP_REQUEST
:
568 set_sta_flag(sta
, WLAN_STA_TDLS_INITIATOR
);
569 sta
->sta
.tdls_initiator
= false;
572 case WLAN_TDLS_SETUP_CONFIRM
:
573 case WLAN_TDLS_DISCOVERY_REQUEST
:
576 case WLAN_TDLS_SETUP_RESPONSE
:
578 * In some testing scenarios, we send a request and response.
579 * Make the last packet sent take effect for the initiator
583 clear_sta_flag(sta
, WLAN_STA_TDLS_INITIATOR
);
584 sta
->sta
.tdls_initiator
= true;
587 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
590 case WLAN_TDLS_TEARDOWN
:
591 /* any value is ok */
598 if (sta
&& test_sta_flag(sta
, WLAN_STA_TDLS_INITIATOR
))
605 ieee80211_tdls_add_ies(sdata
, skb
, peer
, action_code
, status_code
,
606 initiator
, extra_ies
, extra_ies_len
);
608 ieee80211_tx_skb(sdata
, skb
);
613 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
614 * we should default to AC_VI.
616 switch (action_code
) {
617 case WLAN_TDLS_SETUP_REQUEST
:
618 case WLAN_TDLS_SETUP_RESPONSE
:
619 skb_set_queue_mapping(skb
, IEEE80211_AC_BK
);
623 skb_set_queue_mapping(skb
, IEEE80211_AC_VI
);
629 * Set the WLAN_TDLS_TEARDOWN flag to indicate a teardown in progress.
630 * Later, if no ACK is returned from peer, we will re-send the teardown
631 * packet through the AP.
633 if ((action_code
== WLAN_TDLS_TEARDOWN
) &&
634 (local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
)) {
635 struct sta_info
*sta
= NULL
;
636 bool try_resend
; /* Should we keep skb for possible resend */
638 /* If not sending directly to peer - no point in keeping skb */
640 sta
= sta_info_get(sdata
, peer
);
641 try_resend
= sta
&& test_sta_flag(sta
, WLAN_STA_TDLS_PEER_AUTH
);
644 spin_lock_bh(&sdata
->u
.mgd
.teardown_lock
);
645 if (try_resend
&& !sdata
->u
.mgd
.teardown_skb
) {
646 /* Mark it as requiring TX status callback */
647 flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
|
648 IEEE80211_TX_INTFL_MLME_CONN_TX
;
651 * skb is copied since mac80211 will later set
652 * properties that might not be the same as the AP,
653 * such as encryption, QoS, addresses, etc.
655 * No problem if skb_copy() fails, so no need to check.
657 sdata
->u
.mgd
.teardown_skb
= skb_copy(skb
, GFP_ATOMIC
);
658 sdata
->u
.mgd
.orig_teardown_skb
= skb
;
660 spin_unlock_bh(&sdata
->u
.mgd
.teardown_lock
);
663 /* disable bottom halves when entering the Tx path */
665 __ieee80211_subif_start_xmit(skb
, dev
, flags
);
676 ieee80211_tdls_mgmt_setup(struct wiphy
*wiphy
, struct net_device
*dev
,
677 const u8
*peer
, u8 action_code
, u8 dialog_token
,
678 u16 status_code
, u32 peer_capability
, bool initiator
,
679 const u8
*extra_ies
, size_t extra_ies_len
)
681 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
682 struct ieee80211_local
*local
= sdata
->local
;
685 mutex_lock(&local
->mtx
);
687 /* we don't support concurrent TDLS peer setups */
688 if (!is_zero_ether_addr(sdata
->u
.mgd
.tdls_peer
) &&
689 !ether_addr_equal(sdata
->u
.mgd
.tdls_peer
, peer
)) {
695 * make sure we have a STA representing the peer so we drop or buffer
696 * non-TDLS-setup frames to the peer. We can't send other packets
697 * during setup through the AP path.
698 * Allow error packets to be sent - sometimes we don't even add a STA
699 * before failing the setup.
701 if (status_code
== 0) {
703 if (!sta_info_get(sdata
, peer
)) {
711 ieee80211_flush_queues(local
, sdata
);
713 ret
= ieee80211_tdls_prep_mgmt_packet(wiphy
, dev
, peer
, action_code
,
714 dialog_token
, status_code
,
715 peer_capability
, initiator
,
716 extra_ies
, extra_ies_len
);
720 memcpy(sdata
->u
.mgd
.tdls_peer
, peer
, ETH_ALEN
);
721 ieee80211_queue_delayed_work(&sdata
->local
->hw
,
722 &sdata
->u
.mgd
.tdls_peer_del_work
,
723 TDLS_PEER_SETUP_TIMEOUT
);
726 mutex_unlock(&local
->mtx
);
731 ieee80211_tdls_mgmt_teardown(struct wiphy
*wiphy
, struct net_device
*dev
,
732 const u8
*peer
, u8 action_code
, u8 dialog_token
,
733 u16 status_code
, u32 peer_capability
,
734 bool initiator
, const u8
*extra_ies
,
735 size_t extra_ies_len
)
737 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
738 struct ieee80211_local
*local
= sdata
->local
;
739 struct sta_info
*sta
;
743 * No packets can be transmitted to the peer via the AP during setup -
744 * the STA is set as a TDLS peer, but is not authorized.
745 * During teardown, we prevent direct transmissions by stopping the
746 * queues and flushing all direct packets.
748 ieee80211_stop_vif_queues(local
, sdata
,
749 IEEE80211_QUEUE_STOP_REASON_TDLS_TEARDOWN
);
750 ieee80211_flush_queues(local
, sdata
);
752 ret
= ieee80211_tdls_prep_mgmt_packet(wiphy
, dev
, peer
, action_code
,
753 dialog_token
, status_code
,
754 peer_capability
, initiator
,
755 extra_ies
, extra_ies_len
);
757 sdata_err(sdata
, "Failed sending TDLS teardown packet %d\n",
761 * Remove the STA AUTH flag to force further traffic through the AP. If
762 * the STA was unreachable, it was already removed.
765 sta
= sta_info_get(sdata
, peer
);
767 clear_sta_flag(sta
, WLAN_STA_TDLS_PEER_AUTH
);
770 ieee80211_wake_vif_queues(local
, sdata
,
771 IEEE80211_QUEUE_STOP_REASON_TDLS_TEARDOWN
);
776 int ieee80211_tdls_mgmt(struct wiphy
*wiphy
, struct net_device
*dev
,
777 const u8
*peer
, u8 action_code
, u8 dialog_token
,
778 u16 status_code
, u32 peer_capability
,
779 bool initiator
, const u8
*extra_ies
,
780 size_t extra_ies_len
)
782 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
785 if (!(wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
788 /* make sure we are in managed mode, and associated */
789 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
||
790 !sdata
->u
.mgd
.associated
)
793 switch (action_code
) {
794 case WLAN_TDLS_SETUP_REQUEST
:
795 case WLAN_TDLS_SETUP_RESPONSE
:
796 ret
= ieee80211_tdls_mgmt_setup(wiphy
, dev
, peer
, action_code
,
797 dialog_token
, status_code
,
798 peer_capability
, initiator
,
799 extra_ies
, extra_ies_len
);
801 case WLAN_TDLS_TEARDOWN
:
802 ret
= ieee80211_tdls_mgmt_teardown(wiphy
, dev
, peer
,
803 action_code
, dialog_token
,
805 peer_capability
, initiator
,
806 extra_ies
, extra_ies_len
);
808 case WLAN_TDLS_DISCOVERY_REQUEST
:
810 * Protect the discovery so we can hear the TDLS discovery
811 * response frame. It is transmitted directly and not buffered
814 drv_mgd_protect_tdls_discover(sdata
->local
, sdata
);
816 case WLAN_TDLS_SETUP_CONFIRM
:
817 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES
:
818 /* no special handling */
819 ret
= ieee80211_tdls_prep_mgmt_packet(wiphy
, dev
, peer
,
824 initiator
, extra_ies
,
832 tdls_dbg(sdata
, "TDLS mgmt action %d peer %pM status %d\n",
833 action_code
, peer
, ret
);
837 int ieee80211_tdls_oper(struct wiphy
*wiphy
, struct net_device
*dev
,
838 const u8
*peer
, enum nl80211_tdls_operation oper
)
840 struct sta_info
*sta
;
841 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
842 struct ieee80211_local
*local
= sdata
->local
;
845 if (!(wiphy
->flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
848 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
852 case NL80211_TDLS_ENABLE_LINK
:
853 case NL80211_TDLS_DISABLE_LINK
:
855 case NL80211_TDLS_TEARDOWN
:
856 case NL80211_TDLS_SETUP
:
857 case NL80211_TDLS_DISCOVERY_REQ
:
858 /* We don't support in-driver setup/teardown/discovery */
862 mutex_lock(&local
->mtx
);
863 tdls_dbg(sdata
, "TDLS oper %d peer %pM\n", oper
, peer
);
866 case NL80211_TDLS_ENABLE_LINK
:
868 sta
= sta_info_get(sdata
, peer
);
875 set_sta_flag(sta
, WLAN_STA_TDLS_PEER_AUTH
);
878 WARN_ON_ONCE(is_zero_ether_addr(sdata
->u
.mgd
.tdls_peer
) ||
879 !ether_addr_equal(sdata
->u
.mgd
.tdls_peer
, peer
));
882 case NL80211_TDLS_DISABLE_LINK
:
884 * The teardown message in ieee80211_tdls_mgmt_teardown() was
885 * created while the queues were stopped, so it might still be
886 * pending. Before flushing the queues we need to be sure the
887 * message is handled by the tasklet handling pending messages,
888 * otherwise we might start destroying the station before
889 * sending the teardown packet.
890 * Note that this only forces the tasklet to flush pendings -
891 * not to stop the tasklet from rescheduling itself.
893 tasklet_kill(&local
->tx_pending_tasklet
);
894 /* flush a potentially queued teardown packet */
895 ieee80211_flush_queues(local
, sdata
);
897 ret
= sta_info_destroy_addr(sdata
, peer
);
904 if (ret
== 0 && ether_addr_equal(sdata
->u
.mgd
.tdls_peer
, peer
)) {
905 cancel_delayed_work(&sdata
->u
.mgd
.tdls_peer_del_work
);
906 eth_zero_addr(sdata
->u
.mgd
.tdls_peer
);
909 mutex_unlock(&local
->mtx
);
913 void ieee80211_tdls_oper_request(struct ieee80211_vif
*vif
, const u8
*peer
,
914 enum nl80211_tdls_operation oper
,
915 u16 reason_code
, gfp_t gfp
)
917 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
919 if (vif
->type
!= NL80211_IFTYPE_STATION
|| !vif
->bss_conf
.assoc
) {
920 sdata_err(sdata
, "Discarding TDLS oper %d - not STA or disconnected\n",
925 cfg80211_tdls_oper_request(sdata
->dev
, peer
, oper
, reason_code
, gfp
);
927 EXPORT_SYMBOL(ieee80211_tdls_oper_request
);