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;
52 ieee80211_tdls_add_subband(struct ieee80211_sub_if_data *sdata,
53 struct sk_buff *skb, u16 start, u16 end,
56 u8 subband_cnt = 0, ch_cnt = 0;
57 struct ieee80211_channel *ch;
58 struct cfg80211_chan_def chandef;
61 for (i = start; i <= end; i += spacing) {
65 ch = ieee80211_get_channel(sdata->local->hw.wiphy, i);
67 /* we will be active on the channel */
68 u32 flags = IEEE80211_CHAN_DISABLED |
70 cfg80211_chandef_create(&chandef, ch,
72 if (cfg80211_chandef_usable(sdata->local->hw.wiphy,
80 u8 *pos = skb_put(skb, 2);
81 *pos++ = ieee80211_frequency_to_channel(subband_start);
93 ieee80211_tdls_add_supp_channels(struct ieee80211_sub_if_data *sdata,
97 * Add possible channels for TDLS. These are channels that are allowed
101 u8 *pos = skb_put(skb, 2);
103 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
106 * 5GHz and 2GHz channels numbers can overlap. Ignore this for now, as
107 * this doesn't happen in real world scenarios.
110 /* 2GHz, with 5MHz spacing */
111 subband_cnt = ieee80211_tdls_add_subband(sdata, skb, 2412, 2472, 5);
113 /* 5GHz, with 20MHz spacing */
114 subband_cnt += ieee80211_tdls_add_subband(sdata, skb, 5000, 5825, 20);
117 *pos = 2 * subband_cnt;
120 static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata,
123 struct ieee80211_local *local = sdata->local;
126 /* The capability will be 0 when sending a failure code */
127 if (status_code != 0)
131 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
134 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
135 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
136 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
137 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
142 static void ieee80211_tdls_add_link_ie(struct ieee80211_sub_if_data *sdata,
143 struct sk_buff *skb, const u8 *peer,
146 struct ieee80211_tdls_lnkie *lnkid;
147 const u8 *init_addr, *rsp_addr;
150 init_addr = sdata->vif.addr;
154 rsp_addr = sdata->vif.addr;
157 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
159 lnkid->ie_type = WLAN_EID_LINK_ID;
160 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
162 memcpy(lnkid->bssid, sdata->u.mgd.bssid, ETH_ALEN);
163 memcpy(lnkid->init_sta, init_addr, ETH_ALEN);
164 memcpy(lnkid->resp_sta, rsp_addr, ETH_ALEN);
167 /* translate numbering in the WMM parameter IE to the mac80211 notation */
168 static enum ieee80211_ac_numbers ieee80211_ac_from_wmm(int ac)
174 return IEEE80211_AC_BE;
176 return IEEE80211_AC_BK;
178 return IEEE80211_AC_VI;
180 return IEEE80211_AC_VO;
184 static u8 ieee80211_wmm_aci_aifsn(int aifsn, bool acm, int aci)
191 ret |= (aci << 5) & 0x60;
195 static u8 ieee80211_wmm_ecw(u16 cw_min, u16 cw_max)
197 return ((ilog2(cw_min + 1) << 0x0) & 0x0f) |
198 ((ilog2(cw_max + 1) << 0x4) & 0xf0);
201 static void ieee80211_tdls_add_wmm_param_ie(struct ieee80211_sub_if_data *sdata,
204 struct ieee80211_wmm_param_ie *wmm;
205 struct ieee80211_tx_queue_params *txq;
208 wmm = (void *)skb_put(skb, sizeof(*wmm));
209 memset(wmm, 0, sizeof(*wmm));
211 wmm->element_id = WLAN_EID_VENDOR_SPECIFIC;
212 wmm->len = sizeof(*wmm) - 2;
214 wmm->oui[0] = 0x00; /* Microsoft OUI 00:50:F2 */
217 wmm->oui_type = 2; /* WME */
218 wmm->oui_subtype = 1; /* WME param */
219 wmm->version = 1; /* WME ver */
220 wmm->qos_info = 0; /* U-APSD not in use */
223 * Use the EDCA parameters defined for the BSS, or default if the AP
224 * doesn't support it, as mandated by 802.11-2012 section 10.22.4
226 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
227 txq = &sdata->tx_conf[ieee80211_ac_from_wmm(i)];
228 wmm->ac[i].aci_aifsn = ieee80211_wmm_aci_aifsn(txq->aifs,
230 wmm->ac[i].cw = ieee80211_wmm_ecw(txq->cw_min, txq->cw_max);
231 wmm->ac[i].txop_limit = cpu_to_le16(txq->txop);
236 ieee80211_tdls_add_setup_start_ies(struct ieee80211_sub_if_data *sdata,
237 struct sk_buff *skb, const u8 *peer,
238 u8 action_code, bool initiator,
239 const u8 *extra_ies, size_t extra_ies_len)
241 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
242 struct ieee80211_local *local = sdata->local;
243 struct ieee80211_supported_band *sband;
244 struct ieee80211_sta_ht_cap ht_cap;
245 struct sta_info *sta = NULL;
246 size_t offset = 0, noffset;
251 /* we should have the peer STA if we're already responding */
252 if (action_code == WLAN_TDLS_SETUP_RESPONSE) {
253 sta = sta_info_get(sdata, peer);
254 if (WARN_ON_ONCE(!sta)) {
260 ieee80211_add_srates_ie(sdata, skb, false, band);
261 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
262 ieee80211_tdls_add_supp_channels(sdata, skb);
264 /* add any custom IEs that go before Extended Capabilities */
266 static const u8 before_ext_cap[] = {
269 WLAN_EID_EXT_SUPP_RATES,
270 WLAN_EID_SUPPORTED_CHANNELS,
273 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
275 ARRAY_SIZE(before_ext_cap),
277 pos = skb_put(skb, noffset - offset);
278 memcpy(pos, extra_ies + offset, noffset - offset);
282 ieee80211_tdls_add_ext_capab(skb);
284 /* add the QoS element if we support it */
285 if (local->hw.queues >= IEEE80211_NUM_ACS &&
286 action_code != WLAN_PUB_ACTION_TDLS_DISCOVER_RES)
287 ieee80211_add_wmm_info_ie(skb_put(skb, 9), 0); /* no U-APSD */
289 /* add any custom IEs that go before HT capabilities */
291 static const u8 before_ht_cap[] = {
294 WLAN_EID_EXT_SUPP_RATES,
295 WLAN_EID_SUPPORTED_CHANNELS,
297 WLAN_EID_EXT_CAPABILITY,
299 WLAN_EID_FAST_BSS_TRANSITION,
300 WLAN_EID_TIMEOUT_INTERVAL,
301 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
303 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
305 ARRAY_SIZE(before_ht_cap),
307 pos = skb_put(skb, noffset - offset);
308 memcpy(pos, extra_ies + offset, noffset - offset);
313 * with TDLS we can switch channels, and HT-caps are not necessarily
314 * the same on all bands. The specification limits the setup to a
315 * single HT-cap, so use the current band for now.
317 sband = local->hw.wiphy->bands[band];
318 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
319 if ((action_code == WLAN_TDLS_SETUP_REQUEST ||
320 action_code == WLAN_TDLS_SETUP_RESPONSE) &&
321 ht_cap.ht_supported && (!sta || sta->sta.ht_cap.ht_supported)) {
322 if (action_code == WLAN_TDLS_SETUP_REQUEST) {
323 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
325 /* disable SMPS in TDLS initiator */
326 ht_cap.cap |= (WLAN_HT_CAP_SM_PS_DISABLED
327 << IEEE80211_HT_CAP_SM_PS_SHIFT);
329 /* disable SMPS in TDLS responder */
330 sta->sta.ht_cap.cap |=
331 (WLAN_HT_CAP_SM_PS_DISABLED
332 << IEEE80211_HT_CAP_SM_PS_SHIFT);
334 /* the peer caps are already intersected with our own */
335 memcpy(&ht_cap, &sta->sta.ht_cap, sizeof(ht_cap));
338 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
339 ieee80211_ie_build_ht_cap(pos, &ht_cap, ht_cap.cap);
344 /* add any remaining IEs */
346 noffset = extra_ies_len;
347 pos = skb_put(skb, noffset - offset);
348 memcpy(pos, extra_ies + offset, noffset - offset);
351 ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator);
355 ieee80211_tdls_add_setup_cfm_ies(struct ieee80211_sub_if_data *sdata,
356 struct sk_buff *skb, const u8 *peer,
357 bool initiator, const u8 *extra_ies,
358 size_t extra_ies_len)
360 struct ieee80211_local *local = sdata->local;
361 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
362 size_t offset = 0, noffset;
363 struct sta_info *sta, *ap_sta;
368 sta = sta_info_get(sdata, peer);
369 ap_sta = sta_info_get(sdata, ifmgd->bssid);
370 if (WARN_ON_ONCE(!sta || !ap_sta)) {
375 /* add any custom IEs that go before the QoS IE */
377 static const u8 before_qos[] = {
380 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
382 ARRAY_SIZE(before_qos),
384 pos = skb_put(skb, noffset - offset);
385 memcpy(pos, extra_ies + offset, noffset - offset);
389 /* add the QoS param IE if both the peer and we support it */
390 if (local->hw.queues >= IEEE80211_NUM_ACS && sta->sta.wme)
391 ieee80211_tdls_add_wmm_param_ie(sdata, skb);
393 /* add any custom IEs that go before HT operation */
395 static const u8 before_ht_op[] = {
398 WLAN_EID_FAST_BSS_TRANSITION,
399 WLAN_EID_TIMEOUT_INTERVAL,
401 noffset = ieee80211_ie_split(extra_ies, extra_ies_len,
403 ARRAY_SIZE(before_ht_op),
405 pos = skb_put(skb, noffset - offset);
406 memcpy(pos, extra_ies + offset, noffset - offset);
410 /* if HT support is only added in TDLS, we need an HT-operation IE */
411 if (!ap_sta->sta.ht_cap.ht_supported && sta->sta.ht_cap.ht_supported) {
412 struct ieee80211_chanctx_conf *chanctx_conf =
413 rcu_dereference(sdata->vif.chanctx_conf);
414 if (!WARN_ON(!chanctx_conf)) {
415 pos = skb_put(skb, 2 +
416 sizeof(struct ieee80211_ht_operation));
417 /* send an empty HT operation IE */
418 ieee80211_ie_build_ht_oper(pos, &sta->sta.ht_cap,
419 &chanctx_conf->def, 0);
425 /* add any remaining IEs */
427 noffset = extra_ies_len;
428 pos = skb_put(skb, noffset - offset);
429 memcpy(pos, extra_ies + offset, noffset - offset);
432 ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator);
435 static void ieee80211_tdls_add_ies(struct ieee80211_sub_if_data *sdata,
436 struct sk_buff *skb, const u8 *peer,
437 u8 action_code, u16 status_code,
438 bool initiator, const u8 *extra_ies,
439 size_t extra_ies_len)
441 switch (action_code) {
442 case WLAN_TDLS_SETUP_REQUEST:
443 case WLAN_TDLS_SETUP_RESPONSE:
444 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
445 if (status_code == 0)
446 ieee80211_tdls_add_setup_start_ies(sdata, skb, peer,
452 case WLAN_TDLS_SETUP_CONFIRM:
453 if (status_code == 0)
454 ieee80211_tdls_add_setup_cfm_ies(sdata, skb, peer,
455 initiator, extra_ies,
458 case WLAN_TDLS_TEARDOWN:
459 case WLAN_TDLS_DISCOVERY_REQUEST:
461 memcpy(skb_put(skb, extra_ies_len), extra_ies,
463 if (status_code == 0 || action_code == WLAN_TDLS_TEARDOWN)
464 ieee80211_tdls_add_link_ie(sdata, skb, peer, initiator);
471 ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
472 const u8 *peer, u8 action_code, u8 dialog_token,
473 u16 status_code, struct sk_buff *skb)
475 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
476 struct ieee80211_tdls_data *tf;
478 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
480 memcpy(tf->da, peer, ETH_ALEN);
481 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
482 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
483 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
485 /* network header is after the ethernet header */
486 skb_set_network_header(skb, ETH_HLEN);
488 switch (action_code) {
489 case WLAN_TDLS_SETUP_REQUEST:
490 tf->category = WLAN_CATEGORY_TDLS;
491 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
493 skb_put(skb, sizeof(tf->u.setup_req));
494 tf->u.setup_req.dialog_token = dialog_token;
495 tf->u.setup_req.capability =
496 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata,
499 case WLAN_TDLS_SETUP_RESPONSE:
500 tf->category = WLAN_CATEGORY_TDLS;
501 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
503 skb_put(skb, sizeof(tf->u.setup_resp));
504 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
505 tf->u.setup_resp.dialog_token = dialog_token;
506 tf->u.setup_resp.capability =
507 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata,
510 case WLAN_TDLS_SETUP_CONFIRM:
511 tf->category = WLAN_CATEGORY_TDLS;
512 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
514 skb_put(skb, sizeof(tf->u.setup_cfm));
515 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
516 tf->u.setup_cfm.dialog_token = dialog_token;
518 case WLAN_TDLS_TEARDOWN:
519 tf->category = WLAN_CATEGORY_TDLS;
520 tf->action_code = WLAN_TDLS_TEARDOWN;
522 skb_put(skb, sizeof(tf->u.teardown));
523 tf->u.teardown.reason_code = cpu_to_le16(status_code);
525 case WLAN_TDLS_DISCOVERY_REQUEST:
526 tf->category = WLAN_CATEGORY_TDLS;
527 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
529 skb_put(skb, sizeof(tf->u.discover_req));
530 tf->u.discover_req.dialog_token = dialog_token;
540 ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
541 const u8 *peer, u8 action_code, u8 dialog_token,
542 u16 status_code, struct sk_buff *skb)
544 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
545 struct ieee80211_mgmt *mgmt;
547 mgmt = (void *)skb_put(skb, 24);
549 memcpy(mgmt->da, peer, ETH_ALEN);
550 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
551 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
553 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
554 IEEE80211_STYPE_ACTION);
556 switch (action_code) {
557 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
558 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
559 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
560 mgmt->u.action.u.tdls_discover_resp.action_code =
561 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
562 mgmt->u.action.u.tdls_discover_resp.dialog_token =
564 mgmt->u.action.u.tdls_discover_resp.capability =
565 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata,
576 ieee80211_tdls_prep_mgmt_packet(struct wiphy *wiphy, struct net_device *dev,
577 const u8 *peer, u8 action_code,
578 u8 dialog_token, u16 status_code,
579 u32 peer_capability, bool initiator,
580 const u8 *extra_ies, size_t extra_ies_len)
582 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
583 struct ieee80211_local *local = sdata->local;
584 struct sk_buff *skb = NULL;
587 struct sta_info *sta;
590 skb = netdev_alloc_skb(dev,
591 local->hw.extra_tx_headroom +
592 max(sizeof(struct ieee80211_mgmt),
593 sizeof(struct ieee80211_tdls_data)) +
594 50 + /* supported rates */
596 26 + /* max(WMM-info, WMM-param) */
597 2 + max(sizeof(struct ieee80211_ht_cap),
598 sizeof(struct ieee80211_ht_operation)) +
599 50 + /* supported channels */
601 sizeof(struct ieee80211_tdls_lnkie));
605 skb_reserve(skb, local->hw.extra_tx_headroom);
607 switch (action_code) {
608 case WLAN_TDLS_SETUP_REQUEST:
609 case WLAN_TDLS_SETUP_RESPONSE:
610 case WLAN_TDLS_SETUP_CONFIRM:
611 case WLAN_TDLS_TEARDOWN:
612 case WLAN_TDLS_DISCOVERY_REQUEST:
613 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
614 action_code, dialog_token,
618 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
619 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
620 dialog_token, status_code,
633 sta = sta_info_get(sdata, peer);
635 /* infer the initiator if we can, to support old userspace */
636 switch (action_code) {
637 case WLAN_TDLS_SETUP_REQUEST:
639 set_sta_flag(sta, WLAN_STA_TDLS_INITIATOR);
640 sta->sta.tdls_initiator = false;
643 case WLAN_TDLS_SETUP_CONFIRM:
644 case WLAN_TDLS_DISCOVERY_REQUEST:
647 case WLAN_TDLS_SETUP_RESPONSE:
649 * In some testing scenarios, we send a request and response.
650 * Make the last packet sent take effect for the initiator
654 clear_sta_flag(sta, WLAN_STA_TDLS_INITIATOR);
655 sta->sta.tdls_initiator = true;
658 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
661 case WLAN_TDLS_TEARDOWN:
662 /* any value is ok */
669 if (sta && test_sta_flag(sta, WLAN_STA_TDLS_INITIATOR))
676 ieee80211_tdls_add_ies(sdata, skb, peer, action_code, status_code,
677 initiator, extra_ies, extra_ies_len);
679 ieee80211_tx_skb(sdata, skb);
684 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
685 * we should default to AC_VI.
687 switch (action_code) {
688 case WLAN_TDLS_SETUP_REQUEST:
689 case WLAN_TDLS_SETUP_RESPONSE:
690 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
694 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
700 * Set the WLAN_TDLS_TEARDOWN flag to indicate a teardown in progress.
701 * Later, if no ACK is returned from peer, we will re-send the teardown
702 * packet through the AP.
704 if ((action_code == WLAN_TDLS_TEARDOWN) &&
705 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) {
706 struct sta_info *sta = NULL;
707 bool try_resend; /* Should we keep skb for possible resend */
709 /* If not sending directly to peer - no point in keeping skb */
711 sta = sta_info_get(sdata, peer);
712 try_resend = sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
715 spin_lock_bh(&sdata->u.mgd.teardown_lock);
716 if (try_resend && !sdata->u.mgd.teardown_skb) {
717 /* Mark it as requiring TX status callback */
718 flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
719 IEEE80211_TX_INTFL_MLME_CONN_TX;
722 * skb is copied since mac80211 will later set
723 * properties that might not be the same as the AP,
724 * such as encryption, QoS, addresses, etc.
726 * No problem if skb_copy() fails, so no need to check.
728 sdata->u.mgd.teardown_skb = skb_copy(skb, GFP_ATOMIC);
729 sdata->u.mgd.orig_teardown_skb = skb;
731 spin_unlock_bh(&sdata->u.mgd.teardown_lock);
734 /* disable bottom halves when entering the Tx path */
736 __ieee80211_subif_start_xmit(skb, dev, flags);
747 ieee80211_tdls_mgmt_setup(struct wiphy *wiphy, struct net_device *dev,
748 const u8 *peer, u8 action_code, u8 dialog_token,
749 u16 status_code, u32 peer_capability, bool initiator,
750 const u8 *extra_ies, size_t extra_ies_len)
752 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
753 struct ieee80211_local *local = sdata->local;
756 mutex_lock(&local->mtx);
758 /* we don't support concurrent TDLS peer setups */
759 if (!is_zero_ether_addr(sdata->u.mgd.tdls_peer) &&
760 !ether_addr_equal(sdata->u.mgd.tdls_peer, peer)) {
766 * make sure we have a STA representing the peer so we drop or buffer
767 * non-TDLS-setup frames to the peer. We can't send other packets
768 * during setup through the AP path.
769 * Allow error packets to be sent - sometimes we don't even add a STA
770 * before failing the setup.
772 if (status_code == 0) {
774 if (!sta_info_get(sdata, peer)) {
782 ieee80211_flush_queues(local, sdata);
784 ret = ieee80211_tdls_prep_mgmt_packet(wiphy, dev, peer, action_code,
785 dialog_token, status_code,
786 peer_capability, initiator,
787 extra_ies, extra_ies_len);
791 memcpy(sdata->u.mgd.tdls_peer, peer, ETH_ALEN);
792 ieee80211_queue_delayed_work(&sdata->local->hw,
793 &sdata->u.mgd.tdls_peer_del_work,
794 TDLS_PEER_SETUP_TIMEOUT);
797 mutex_unlock(&local->mtx);
802 ieee80211_tdls_mgmt_teardown(struct wiphy *wiphy, struct net_device *dev,
803 const u8 *peer, u8 action_code, u8 dialog_token,
804 u16 status_code, u32 peer_capability,
805 bool initiator, const u8 *extra_ies,
806 size_t extra_ies_len)
808 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
809 struct ieee80211_local *local = sdata->local;
810 struct sta_info *sta;
814 * No packets can be transmitted to the peer via the AP during setup -
815 * the STA is set as a TDLS peer, but is not authorized.
816 * During teardown, we prevent direct transmissions by stopping the
817 * queues and flushing all direct packets.
819 ieee80211_stop_vif_queues(local, sdata,
820 IEEE80211_QUEUE_STOP_REASON_TDLS_TEARDOWN);
821 ieee80211_flush_queues(local, sdata);
823 ret = ieee80211_tdls_prep_mgmt_packet(wiphy, dev, peer, action_code,
824 dialog_token, status_code,
825 peer_capability, initiator,
826 extra_ies, extra_ies_len);
828 sdata_err(sdata, "Failed sending TDLS teardown packet %d\n",
832 * Remove the STA AUTH flag to force further traffic through the AP. If
833 * the STA was unreachable, it was already removed.
836 sta = sta_info_get(sdata, peer);
838 clear_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
841 ieee80211_wake_vif_queues(local, sdata,
842 IEEE80211_QUEUE_STOP_REASON_TDLS_TEARDOWN);
847 int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
848 const u8 *peer, u8 action_code, u8 dialog_token,
849 u16 status_code, u32 peer_capability,
850 bool initiator, const u8 *extra_ies,
851 size_t extra_ies_len)
853 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
856 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
859 /* make sure we are in managed mode, and associated */
860 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
861 !sdata->u.mgd.associated)
864 switch (action_code) {
865 case WLAN_TDLS_SETUP_REQUEST:
866 case WLAN_TDLS_SETUP_RESPONSE:
867 ret = ieee80211_tdls_mgmt_setup(wiphy, dev, peer, action_code,
868 dialog_token, status_code,
869 peer_capability, initiator,
870 extra_ies, extra_ies_len);
872 case WLAN_TDLS_TEARDOWN:
873 ret = ieee80211_tdls_mgmt_teardown(wiphy, dev, peer,
874 action_code, dialog_token,
876 peer_capability, initiator,
877 extra_ies, extra_ies_len);
879 case WLAN_TDLS_DISCOVERY_REQUEST:
881 * Protect the discovery so we can hear the TDLS discovery
882 * response frame. It is transmitted directly and not buffered
885 drv_mgd_protect_tdls_discover(sdata->local, sdata);
887 case WLAN_TDLS_SETUP_CONFIRM:
888 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
889 /* no special handling */
890 ret = ieee80211_tdls_prep_mgmt_packet(wiphy, dev, peer,
895 initiator, extra_ies,
903 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM status %d\n",
904 action_code, peer, ret);
908 int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
909 const u8 *peer, enum nl80211_tdls_operation oper)
911 struct sta_info *sta;
912 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
913 struct ieee80211_local *local = sdata->local;
916 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
919 if (sdata->vif.type != NL80211_IFTYPE_STATION)
923 case NL80211_TDLS_ENABLE_LINK:
924 case NL80211_TDLS_DISABLE_LINK:
926 case NL80211_TDLS_TEARDOWN:
927 case NL80211_TDLS_SETUP:
928 case NL80211_TDLS_DISCOVERY_REQ:
929 /* We don't support in-driver setup/teardown/discovery */
933 mutex_lock(&local->mtx);
934 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
937 case NL80211_TDLS_ENABLE_LINK:
939 sta = sta_info_get(sdata, peer);
946 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
949 WARN_ON_ONCE(is_zero_ether_addr(sdata->u.mgd.tdls_peer) ||
950 !ether_addr_equal(sdata->u.mgd.tdls_peer, peer));
953 case NL80211_TDLS_DISABLE_LINK:
955 * The teardown message in ieee80211_tdls_mgmt_teardown() was
956 * created while the queues were stopped, so it might still be
957 * pending. Before flushing the queues we need to be sure the
958 * message is handled by the tasklet handling pending messages,
959 * otherwise we might start destroying the station before
960 * sending the teardown packet.
961 * Note that this only forces the tasklet to flush pendings -
962 * not to stop the tasklet from rescheduling itself.
964 tasklet_kill(&local->tx_pending_tasklet);
965 /* flush a potentially queued teardown packet */
966 ieee80211_flush_queues(local, sdata);
968 ret = sta_info_destroy_addr(sdata, peer);
975 if (ret == 0 && ether_addr_equal(sdata->u.mgd.tdls_peer, peer)) {
976 cancel_delayed_work(&sdata->u.mgd.tdls_peer_del_work);
977 eth_zero_addr(sdata->u.mgd.tdls_peer);
980 mutex_unlock(&local->mtx);
984 void ieee80211_tdls_oper_request(struct ieee80211_vif *vif, const u8 *peer,
985 enum nl80211_tdls_operation oper,
986 u16 reason_code, gfp_t gfp)
988 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
990 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc) {
991 sdata_err(sdata, "Discarding TDLS oper %d - not STA or disconnected\n",
996 cfg80211_tdls_oper_request(sdata->dev, peer, oper, reason_code, gfp);
998 EXPORT_SYMBOL(ieee80211_tdls_oper_request);