2 * wpa_supplicant - TDLS
3 * Copyright (c) 2010-2011, Atheros Communications
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
14 #include "common/ieee802_11_defs.h"
15 #include "crypto/sha256.h"
16 #include "crypto/crypto.h"
17 #include "crypto/aes_wrap.h"
18 #include "rsn_supp/wpa.h"
19 #include "rsn_supp/wpa_ie.h"
20 #include "rsn_supp/wpa_i.h"
21 #include "drivers/driver.h"
22 #include "l2_packet/l2_packet.h"
24 #ifdef CONFIG_TDLS_TESTING
25 #define TDLS_TESTING_LONG_FRAME BIT(0)
26 #define TDLS_TESTING_ALT_RSN_IE BIT(1)
27 #define TDLS_TESTING_DIFF_BSSID BIT(2)
28 #define TDLS_TESTING_SHORT_LIFETIME BIT(3)
29 #define TDLS_TESTING_WRONG_LIFETIME_RESP BIT(4)
30 #define TDLS_TESTING_WRONG_LIFETIME_CONF BIT(5)
31 #define TDLS_TESTING_LONG_LIFETIME BIT(6)
32 #define TDLS_TESTING_CONCURRENT_INIT BIT(7)
33 #define TDLS_TESTING_NO_TPK_EXPIRATION BIT(8)
34 #define TDLS_TESTING_DECLINE_RESP BIT(9)
35 #define TDLS_TESTING_IGNORE_AP_PROHIBIT BIT(10)
36 #define TDLS_TESTING_WRONG_MIC BIT(11)
37 unsigned int tdls_testing = 0;
38 #endif /* CONFIG_TDLS_TESTING */
40 #define TPK_LIFETIME 43200 /* 12 hours */
41 #define TPK_M1_RETRY_COUNT 3
42 #define TPK_M1_TIMEOUT 5000 /* in milliseconds */
43 #define TPK_M2_RETRY_COUNT 10
44 #define TPK_M2_TIMEOUT 500 /* in milliseconds */
46 #define TDLS_MIC_LEN 16
48 #define TDLS_TIMEOUT_LEN 4
50 struct wpa_tdls_ftie {
51 u8 ie_type; /* FTIE */
55 u8 Anonce[WPA_NONCE_LEN]; /* Responder Nonce in TDLS */
56 u8 Snonce[WPA_NONCE_LEN]; /* Initiator Nonce in TDLS */
57 /* followed by optional elements */
60 struct wpa_tdls_timeoutie {
61 u8 ie_type; /* Timeout IE */
64 u8 value[TDLS_TIMEOUT_LEN];
67 struct wpa_tdls_lnkid {
68 u8 ie_type; /* Link Identifier IE */
71 u8 init_sta[ETH_ALEN];
72 u8 resp_sta[ETH_ALEN];
75 /* TDLS frame headers as per IEEE Std 802.11z-2010 */
76 struct wpa_tdls_frame {
77 u8 payloadtype; /* IEEE80211_TDLS_RFTYPE */
78 u8 category; /* Category */
79 u8 action; /* Action (enum tdls_frame_type) */
82 static u8 * wpa_add_tdls_timeoutie(u8 *pos, u8 *ie, size_t ie_len, u32 tsecs);
83 static void wpa_tdls_tpk_retry_timeout(void *eloop_ctx, void *timeout_ctx);
84 static void wpa_tdls_peer_free(struct wpa_sm *sm, struct wpa_tdls_peer *peer);
85 static void wpa_tdls_disable_peer_link(struct wpa_sm *sm,
86 struct wpa_tdls_peer *peer);
87 static int wpa_tdls_send_teardown(struct wpa_sm *sm, const u8 *addr,
91 #define TDLS_MAX_IE_LEN 80
92 #define IEEE80211_MAX_SUPP_RATES 32
94 struct wpa_tdls_peer {
95 struct wpa_tdls_peer *next;
96 unsigned int reconfig_key:1;
97 int initiator; /* whether this end was initiator for TDLS setup */
98 u8 addr[ETH_ALEN]; /* other end MAC address */
99 u8 inonce[WPA_NONCE_LEN]; /* Initiator Nonce */
100 u8 rnonce[WPA_NONCE_LEN]; /* Responder Nonce */
101 u8 rsnie_i[TDLS_MAX_IE_LEN]; /* Initiator RSN IE */
103 u8 rsnie_p[TDLS_MAX_IE_LEN]; /* Peer RSN IE */
106 int cipher; /* Selected cipher (WPA_CIPHER_*) */
110 u8 kck[16]; /* TPK-KCK */
111 u8 tk[16]; /* TPK-TK; assuming only CCMP will be used */
119 int count; /* Retry Count */
120 int timer; /* Timeout in milliseconds */
121 u8 action_code; /* TDLS frame type */
125 int buf_len; /* length of TPK message for retransmission */
126 u8 *buf; /* buffer for TPK message */
131 u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
132 size_t supp_rates_len;
134 struct ieee80211_ht_capabilities *ht_capabilities;
135 struct ieee80211_vht_capabilities *vht_capabilities;
142 size_t ext_capab_len;
145 size_t supp_channels_len;
147 u8 *supp_oper_classes;
148 size_t supp_oper_classes_len;
154 static int wpa_tdls_get_privacy(struct wpa_sm *sm)
157 * Get info needed from supplicant to check if the current BSS supports
158 * security. Other than OPEN mode, rest are considered secured
159 * WEP/WPA/WPA2 hence TDLS frames are processed for TPK handshake.
161 return sm->pairwise_cipher != WPA_CIPHER_NONE;
165 static u8 * wpa_add_ie(u8 *pos, const u8 *ie, size_t ie_len)
167 os_memcpy(pos, ie, ie_len);
172 static int wpa_tdls_del_key(struct wpa_sm *sm, struct wpa_tdls_peer *peer)
174 if (wpa_sm_set_key(sm, WPA_ALG_NONE, peer->addr,
175 0, 0, NULL, 0, NULL, 0) < 0) {
176 wpa_printf(MSG_WARNING, "TDLS: Failed to delete TPK-TK from "
185 static int wpa_tdls_set_key(struct wpa_sm *sm, struct wpa_tdls_peer *peer)
191 os_memset(rsc, 0, 6);
193 switch (peer->cipher) {
194 case WPA_CIPHER_CCMP:
198 case WPA_CIPHER_NONE:
199 wpa_printf(MSG_DEBUG, "TDLS: Pairwise Cipher Suite: "
200 "NONE - do not use pairwise keys");
203 wpa_printf(MSG_WARNING, "TDLS: Unsupported pairwise cipher %d",
204 sm->pairwise_cipher);
208 if (wpa_sm_set_key(sm, alg, peer->addr, -1, 1,
209 rsc, sizeof(rsc), peer->tpk.tk, key_len) < 0) {
210 wpa_printf(MSG_WARNING, "TDLS: Failed to set TPK to the "
218 static int wpa_tdls_send_tpk_msg(struct wpa_sm *sm, const u8 *dst,
219 u8 action_code, u8 dialog_token,
220 u16 status_code, u32 peer_capab,
221 const u8 *buf, size_t len)
223 return wpa_sm_send_tdls_mgmt(sm, dst, action_code, dialog_token,
224 status_code, peer_capab, buf, len);
228 static int wpa_tdls_tpk_send(struct wpa_sm *sm, const u8 *dest, u8 action_code,
229 u8 dialog_token, u16 status_code, u32 peer_capab,
230 const u8 *msg, size_t msg_len)
232 struct wpa_tdls_peer *peer;
234 wpa_printf(MSG_DEBUG, "TDLS: TPK send dest=" MACSTR " action_code=%u "
235 "dialog_token=%u status_code=%u peer_capab=%u msg_len=%u",
236 MAC2STR(dest), action_code, dialog_token, status_code,
237 peer_capab, (unsigned int) msg_len);
239 if (wpa_tdls_send_tpk_msg(sm, dest, action_code, dialog_token,
240 status_code, peer_capab, msg, msg_len)) {
241 wpa_printf(MSG_INFO, "TDLS: Failed to send message "
242 "(action_code=%u)", action_code);
246 if (action_code == WLAN_TDLS_SETUP_CONFIRM ||
247 action_code == WLAN_TDLS_TEARDOWN ||
248 action_code == WLAN_TDLS_DISCOVERY_REQUEST ||
249 action_code == WLAN_TDLS_DISCOVERY_RESPONSE)
250 return 0; /* No retries */
252 for (peer = sm->tdls; peer; peer = peer->next) {
253 if (os_memcmp(peer->addr, dest, ETH_ALEN) == 0)
258 wpa_printf(MSG_INFO, "TDLS: No matching entry found for "
259 "retry " MACSTR, MAC2STR(dest));
263 eloop_cancel_timeout(wpa_tdls_tpk_retry_timeout, sm, peer);
265 if (action_code == WLAN_TDLS_SETUP_RESPONSE) {
266 peer->sm_tmr.count = TPK_M2_RETRY_COUNT;
267 peer->sm_tmr.timer = TPK_M2_TIMEOUT;
269 peer->sm_tmr.count = TPK_M1_RETRY_COUNT;
270 peer->sm_tmr.timer = TPK_M1_TIMEOUT;
273 /* Copy message to resend on timeout */
274 os_memcpy(peer->sm_tmr.dest, dest, ETH_ALEN);
275 peer->sm_tmr.action_code = action_code;
276 peer->sm_tmr.dialog_token = dialog_token;
277 peer->sm_tmr.status_code = status_code;
278 peer->sm_tmr.peer_capab = peer_capab;
279 peer->sm_tmr.buf_len = msg_len;
280 os_free(peer->sm_tmr.buf);
281 peer->sm_tmr.buf = os_malloc(msg_len);
282 if (peer->sm_tmr.buf == NULL)
284 os_memcpy(peer->sm_tmr.buf, msg, msg_len);
286 wpa_printf(MSG_DEBUG, "TDLS: Retry timeout registered "
287 "(action_code=%u)", action_code);
288 eloop_register_timeout(peer->sm_tmr.timer / 1000,
289 (peer->sm_tmr.timer % 1000) * 1000,
290 wpa_tdls_tpk_retry_timeout, sm, peer);
295 static int wpa_tdls_do_teardown(struct wpa_sm *sm, struct wpa_tdls_peer *peer,
300 ret = wpa_tdls_send_teardown(sm, peer->addr, reason_code);
301 /* disable the link after teardown was sent */
302 wpa_tdls_disable_peer_link(sm, peer);
308 static void wpa_tdls_tpk_retry_timeout(void *eloop_ctx, void *timeout_ctx)
311 struct wpa_sm *sm = eloop_ctx;
312 struct wpa_tdls_peer *peer = timeout_ctx;
314 if (peer->sm_tmr.count) {
315 peer->sm_tmr.count--;
317 wpa_printf(MSG_INFO, "TDLS: Retrying sending of message "
319 peer->sm_tmr.action_code);
321 if (peer->sm_tmr.buf == NULL) {
322 wpa_printf(MSG_INFO, "TDLS: No retry buffer available "
323 "for action_code=%u",
324 peer->sm_tmr.action_code);
325 eloop_cancel_timeout(wpa_tdls_tpk_retry_timeout, sm,
330 /* resend TPK Handshake Message to Peer */
331 if (wpa_tdls_send_tpk_msg(sm, peer->sm_tmr.dest,
332 peer->sm_tmr.action_code,
333 peer->sm_tmr.dialog_token,
334 peer->sm_tmr.status_code,
335 peer->sm_tmr.peer_capab,
337 peer->sm_tmr.buf_len)) {
338 wpa_printf(MSG_INFO, "TDLS: Failed to retry "
342 eloop_cancel_timeout(wpa_tdls_tpk_retry_timeout, sm, peer);
343 eloop_register_timeout(peer->sm_tmr.timer / 1000,
344 (peer->sm_tmr.timer % 1000) * 1000,
345 wpa_tdls_tpk_retry_timeout, sm, peer);
347 eloop_cancel_timeout(wpa_tdls_tpk_retry_timeout, sm, peer);
349 wpa_printf(MSG_DEBUG, "TDLS: Sending Teardown Request");
350 wpa_tdls_do_teardown(sm, peer,
351 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
356 static void wpa_tdls_tpk_retry_timeout_cancel(struct wpa_sm *sm,
357 struct wpa_tdls_peer *peer,
360 if (action_code == peer->sm_tmr.action_code) {
361 wpa_printf(MSG_DEBUG, "TDLS: Retry timeout cancelled for "
362 "action_code=%u", action_code);
364 /* Cancel Timeout registered */
365 eloop_cancel_timeout(wpa_tdls_tpk_retry_timeout, sm, peer);
367 /* free all resources meant for retry */
368 os_free(peer->sm_tmr.buf);
369 peer->sm_tmr.buf = NULL;
371 peer->sm_tmr.count = 0;
372 peer->sm_tmr.timer = 0;
373 peer->sm_tmr.buf_len = 0;
374 peer->sm_tmr.action_code = 0xff;
376 wpa_printf(MSG_INFO, "TDLS: Error in cancelling retry timeout "
377 "(Unknown action_code=%u)", action_code);
382 static void wpa_tdls_generate_tpk(struct wpa_tdls_peer *peer,
383 const u8 *own_addr, const u8 *bssid)
385 u8 key_input[SHA256_MAC_LEN];
388 u8 data[3 * ETH_ALEN];
390 /* IEEE Std 802.11z-2010 8.5.9.1:
391 * TPK-Key-Input = SHA-256(min(SNonce, ANonce) || max(SNonce, ANonce))
393 len[0] = WPA_NONCE_LEN;
394 len[1] = WPA_NONCE_LEN;
395 if (os_memcmp(peer->inonce, peer->rnonce, WPA_NONCE_LEN) < 0) {
396 nonce[0] = peer->inonce;
397 nonce[1] = peer->rnonce;
399 nonce[0] = peer->rnonce;
400 nonce[1] = peer->inonce;
402 wpa_hexdump(MSG_DEBUG, "TDLS: min(Nonce)", nonce[0], WPA_NONCE_LEN);
403 wpa_hexdump(MSG_DEBUG, "TDLS: max(Nonce)", nonce[1], WPA_NONCE_LEN);
404 sha256_vector(2, nonce, len, key_input);
405 wpa_hexdump_key(MSG_DEBUG, "TDLS: TPK-Key-Input",
406 key_input, SHA256_MAC_LEN);
409 * TPK-Key-Data = KDF-N_KEY(TPK-Key-Input, "TDLS PMK",
410 * min(MAC_I, MAC_R) || max(MAC_I, MAC_R) || BSSID || N_KEY)
411 * TODO: is N_KEY really included in KDF Context and if so, in which
412 * presentation format (little endian 16-bit?) is it used? It gets
413 * added by the KDF anyway..
416 if (os_memcmp(own_addr, peer->addr, ETH_ALEN) < 0) {
417 os_memcpy(data, own_addr, ETH_ALEN);
418 os_memcpy(data + ETH_ALEN, peer->addr, ETH_ALEN);
420 os_memcpy(data, peer->addr, ETH_ALEN);
421 os_memcpy(data + ETH_ALEN, own_addr, ETH_ALEN);
423 os_memcpy(data + 2 * ETH_ALEN, bssid, ETH_ALEN);
424 wpa_hexdump(MSG_DEBUG, "TDLS: KDF Context", data, sizeof(data));
426 sha256_prf(key_input, SHA256_MAC_LEN, "TDLS PMK", data, sizeof(data),
427 (u8 *) &peer->tpk, sizeof(peer->tpk));
428 wpa_hexdump_key(MSG_DEBUG, "TDLS: TPK-KCK",
429 peer->tpk.kck, sizeof(peer->tpk.kck));
430 wpa_hexdump_key(MSG_DEBUG, "TDLS: TPK-TK",
431 peer->tpk.tk, sizeof(peer->tpk.tk));
437 * wpa_tdls_ftie_mic - Calculate TDLS FTIE MIC
439 * @lnkid: Pointer to the beginning of Link Identifier IE
440 * @rsnie: Pointer to the beginning of RSN IE used for handshake
441 * @timeoutie: Pointer to the beginning of Timeout IE used for handshake
442 * @ftie: Pointer to the beginning of FT IE
443 * @mic: Pointer for writing MIC
445 * Calculate MIC for TDLS frame.
447 static int wpa_tdls_ftie_mic(const u8 *kck, u8 trans_seq, const u8 *lnkid,
448 const u8 *rsnie, const u8 *timeoutie,
449 const u8 *ftie, u8 *mic)
452 struct wpa_tdls_ftie *_ftie;
453 const struct wpa_tdls_lnkid *_lnkid;
455 int len = 2 * ETH_ALEN + 1 + 2 + lnkid[1] + 2 + rsnie[1] +
456 2 + timeoutie[1] + 2 + ftie[1];
457 buf = os_zalloc(len);
459 wpa_printf(MSG_WARNING, "TDLS: No memory for MIC calculation");
464 _lnkid = (const struct wpa_tdls_lnkid *) lnkid;
465 /* 1) TDLS initiator STA MAC address */
466 os_memcpy(pos, _lnkid->init_sta, ETH_ALEN);
468 /* 2) TDLS responder STA MAC address */
469 os_memcpy(pos, _lnkid->resp_sta, ETH_ALEN);
471 /* 3) Transaction Sequence number */
473 /* 4) Link Identifier IE */
474 os_memcpy(pos, lnkid, 2 + lnkid[1]);
477 os_memcpy(pos, rsnie, 2 + rsnie[1]);
479 /* 6) Timeout Interval IE */
480 os_memcpy(pos, timeoutie, 2 + timeoutie[1]);
481 pos += 2 + timeoutie[1];
482 /* 7) FTIE, with the MIC field of the FTIE set to 0 */
483 os_memcpy(pos, ftie, 2 + ftie[1]);
484 _ftie = (struct wpa_tdls_ftie *) pos;
485 os_memset(_ftie->mic, 0, TDLS_MIC_LEN);
488 wpa_hexdump(MSG_DEBUG, "TDLS: Data for FTIE MIC", buf, pos - buf);
489 wpa_hexdump_key(MSG_DEBUG, "TDLS: KCK", kck, 16);
490 ret = omac1_aes_128(kck, buf, pos - buf, mic);
492 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE MIC", mic, 16);
498 * wpa_tdls_key_mic_teardown - Calculate TDLS FTIE MIC for Teardown frame
500 * @trans_seq: Transaction Sequence Number (4 - Teardown)
501 * @rcode: Reason code for Teardown
502 * @dtoken: Dialog Token used for that particular link
503 * @lnkid: Pointer to the beginning of Link Identifier IE
504 * @ftie: Pointer to the beginning of FT IE
505 * @mic: Pointer for writing MIC
507 * Calculate MIC for TDLS frame.
509 static int wpa_tdls_key_mic_teardown(const u8 *kck, u8 trans_seq, u16 rcode,
510 u8 dtoken, const u8 *lnkid,
511 const u8 *ftie, u8 *mic)
514 struct wpa_tdls_ftie *_ftie;
521 len = 2 + lnkid[1] + sizeof(rcode) + sizeof(dtoken) +
522 sizeof(trans_seq) + 2 + ftie[1];
524 buf = os_zalloc(len);
526 wpa_printf(MSG_WARNING, "TDLS: No memory for MIC calculation");
531 /* 1) Link Identifier IE */
532 os_memcpy(pos, lnkid, 2 + lnkid[1]);
535 WPA_PUT_LE16(pos, rcode);
536 pos += sizeof(rcode);
537 /* 3) Dialog token */
539 /* 4) Transaction Sequence number */
541 /* 7) FTIE, with the MIC field of the FTIE set to 0 */
542 os_memcpy(pos, ftie, 2 + ftie[1]);
543 _ftie = (struct wpa_tdls_ftie *) pos;
544 os_memset(_ftie->mic, 0, TDLS_MIC_LEN);
547 wpa_hexdump(MSG_DEBUG, "TDLS: Data for FTIE MIC", buf, pos - buf);
548 wpa_hexdump_key(MSG_DEBUG, "TDLS: KCK", kck, 16);
549 ret = omac1_aes_128(kck, buf, pos - buf, mic);
551 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE MIC", mic, 16);
556 static int wpa_supplicant_verify_tdls_mic(u8 trans_seq,
557 struct wpa_tdls_peer *peer,
558 const u8 *lnkid, const u8 *timeoutie,
559 const struct wpa_tdls_ftie *ftie)
564 wpa_tdls_ftie_mic(peer->tpk.kck, trans_seq, lnkid,
565 peer->rsnie_p, timeoutie, (u8 *) ftie,
567 if (os_memcmp(mic, ftie->mic, 16) != 0) {
568 wpa_printf(MSG_INFO, "TDLS: Invalid MIC in FTIE - "
570 wpa_hexdump(MSG_DEBUG, "TDLS: Received MIC",
572 wpa_hexdump(MSG_DEBUG, "TDLS: Calculated MIC",
577 wpa_printf(MSG_WARNING, "TDLS: Could not verify TDLS MIC, "
578 "TPK not set - dropping packet");
585 static int wpa_supplicant_verify_tdls_mic_teardown(
586 u8 trans_seq, u16 rcode, u8 dtoken, struct wpa_tdls_peer *peer,
587 const u8 *lnkid, const struct wpa_tdls_ftie *ftie)
592 wpa_tdls_key_mic_teardown(peer->tpk.kck, trans_seq, rcode,
593 dtoken, lnkid, (u8 *) ftie, mic);
594 if (os_memcmp(mic, ftie->mic, 16) != 0) {
595 wpa_printf(MSG_INFO, "TDLS: Invalid MIC in Teardown - "
600 wpa_printf(MSG_INFO, "TDLS: Could not verify TDLS Teardown "
601 "MIC, TPK not set - dropping packet");
608 static void wpa_tdls_tpk_timeout(void *eloop_ctx, void *timeout_ctx)
610 struct wpa_sm *sm = eloop_ctx;
611 struct wpa_tdls_peer *peer = timeout_ctx;
614 * On TPK lifetime expiration, we have an option of either tearing down
615 * the direct link or trying to re-initiate it. The selection of what
616 * to do is not strictly speaking controlled by our role in the expired
617 * link, but for now, use that to select whether to renew or tear down
621 if (peer->initiator) {
622 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime expired for " MACSTR
623 " - try to renew", MAC2STR(peer->addr));
624 wpa_tdls_start(sm, peer->addr);
626 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime expired for " MACSTR
627 " - tear down", MAC2STR(peer->addr));
628 wpa_tdls_do_teardown(sm, peer,
629 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
634 static void wpa_tdls_peer_free(struct wpa_sm *sm, struct wpa_tdls_peer *peer)
636 wpa_printf(MSG_DEBUG, "TDLS: Clear state for peer " MACSTR,
637 MAC2STR(peer->addr));
638 eloop_cancel_timeout(wpa_tdls_tpk_timeout, sm, peer);
639 eloop_cancel_timeout(wpa_tdls_tpk_retry_timeout, sm, peer);
640 peer->reconfig_key = 0;
642 peer->tpk_in_progress = 0;
643 os_free(peer->sm_tmr.buf);
644 peer->sm_tmr.buf = NULL;
645 os_free(peer->ht_capabilities);
646 peer->ht_capabilities = NULL;
647 os_free(peer->vht_capabilities);
648 peer->vht_capabilities = NULL;
649 os_free(peer->ext_capab);
650 peer->ext_capab = NULL;
651 os_free(peer->supp_channels);
652 peer->supp_channels = NULL;
653 os_free(peer->supp_oper_classes);
654 peer->supp_oper_classes = NULL;
655 peer->rsnie_i_len = peer->rsnie_p_len = 0;
658 peer->wmm_capable = 0;
659 peer->tpk_set = peer->tpk_success = 0;
660 os_memset(&peer->tpk, 0, sizeof(peer->tpk));
661 os_memset(peer->inonce, 0, WPA_NONCE_LEN);
662 os_memset(peer->rnonce, 0, WPA_NONCE_LEN);
666 static void wpa_tdls_linkid(struct wpa_sm *sm, struct wpa_tdls_peer *peer,
667 struct wpa_tdls_lnkid *lnkid)
669 lnkid->ie_type = WLAN_EID_LINK_ID;
670 lnkid->ie_len = 3 * ETH_ALEN;
671 os_memcpy(lnkid->bssid, sm->bssid, ETH_ALEN);
672 if (peer->initiator) {
673 os_memcpy(lnkid->init_sta, sm->own_addr, ETH_ALEN);
674 os_memcpy(lnkid->resp_sta, peer->addr, ETH_ALEN);
676 os_memcpy(lnkid->init_sta, peer->addr, ETH_ALEN);
677 os_memcpy(lnkid->resp_sta, sm->own_addr, ETH_ALEN);
682 static int wpa_tdls_send_teardown(struct wpa_sm *sm, const u8 *addr,
685 struct wpa_tdls_peer *peer;
686 struct wpa_tdls_ftie *ftie;
687 struct wpa_tdls_lnkid lnkid;
692 if (sm->tdls_disabled || !sm->tdls_supported)
695 /* Find the node and free from the list */
696 for (peer = sm->tdls; peer; peer = peer->next) {
697 if (os_memcmp(peer->addr, addr, ETH_ALEN) == 0)
702 wpa_printf(MSG_INFO, "TDLS: No matching entry found for "
703 "Teardown " MACSTR, MAC2STR(addr));
707 dialog_token = peer->dtoken;
709 wpa_printf(MSG_DEBUG, "TDLS: TDLS Teardown for " MACSTR,
713 if (wpa_tdls_get_privacy(sm) && peer->tpk_set && peer->tpk_success) {
714 /* To add FTIE for Teardown request and compute MIC */
715 ielen += sizeof(*ftie);
716 #ifdef CONFIG_TDLS_TESTING
717 if (tdls_testing & TDLS_TESTING_LONG_FRAME)
719 #endif /* CONFIG_TDLS_TESTING */
722 rbuf = os_zalloc(ielen + 1);
727 if (!wpa_tdls_get_privacy(sm) || !peer->tpk_set || !peer->tpk_success)
730 ftie = (struct wpa_tdls_ftie *) pos;
731 ftie->ie_type = WLAN_EID_FAST_BSS_TRANSITION;
732 /* Using the recent nonce which should be for CONFIRM frame */
733 os_memcpy(ftie->Anonce, peer->rnonce, WPA_NONCE_LEN);
734 os_memcpy(ftie->Snonce, peer->inonce, WPA_NONCE_LEN);
735 ftie->ie_len = sizeof(struct wpa_tdls_ftie) - 2;
736 pos = (u8 *) (ftie + 1);
737 #ifdef CONFIG_TDLS_TESTING
738 if (tdls_testing & TDLS_TESTING_LONG_FRAME) {
739 wpa_printf(MSG_DEBUG, "TDLS: Testing - add extra subelem to "
742 *pos++ = 255; /* FTIE subelem */
743 *pos++ = 168; /* FTIE subelem length */
746 #endif /* CONFIG_TDLS_TESTING */
747 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE for TDLS Teardown handshake",
748 (u8 *) ftie, pos - (u8 *) ftie);
750 /* compute MIC before sending */
751 wpa_tdls_linkid(sm, peer, &lnkid);
752 wpa_tdls_key_mic_teardown(peer->tpk.kck, 4, reason_code,
753 dialog_token, (u8 *) &lnkid, (u8 *) ftie,
757 /* TODO: register for a Timeout handler, if Teardown is not received at
758 * the other end, then try again another time */
760 /* request driver to send Teardown using this FTIE */
761 wpa_tdls_tpk_send(sm, addr, WLAN_TDLS_TEARDOWN, 0,
762 reason_code, 0, rbuf, pos - rbuf);
769 int wpa_tdls_teardown_link(struct wpa_sm *sm, const u8 *addr, u16 reason_code)
771 struct wpa_tdls_peer *peer;
773 if (sm->tdls_disabled || !sm->tdls_supported)
776 for (peer = sm->tdls; peer; peer = peer->next) {
777 if (os_memcmp(peer->addr, addr, ETH_ALEN) == 0)
782 wpa_printf(MSG_DEBUG, "TDLS: Could not find peer " MACSTR
783 " for link Teardown", MAC2STR(addr));
787 if (!peer->tpk_success) {
788 wpa_printf(MSG_DEBUG, "TDLS: Peer " MACSTR
789 " not connected - cannot Teardown link", MAC2STR(addr));
793 return wpa_tdls_do_teardown(sm, peer, reason_code);
797 static void wpa_tdls_disable_peer_link(struct wpa_sm *sm,
798 struct wpa_tdls_peer *peer)
800 wpa_sm_tdls_oper(sm, TDLS_DISABLE_LINK, peer->addr);
801 wpa_tdls_peer_free(sm, peer);
805 void wpa_tdls_disable_unreachable_link(struct wpa_sm *sm, const u8 *addr)
807 struct wpa_tdls_peer *peer;
809 for (peer = sm->tdls; peer; peer = peer->next) {
810 if (os_memcmp(peer->addr, addr, ETH_ALEN) == 0)
814 if (!peer || !peer->tpk_success) {
815 wpa_printf(MSG_DEBUG, "TDLS: Peer " MACSTR
816 " not connected - cannot teardown unreachable link",
821 if (wpa_tdls_is_external_setup(sm)) {
823 * Disable the link, send a teardown packet through the
824 * AP, and then reset link data.
826 wpa_sm_tdls_oper(sm, TDLS_DISABLE_LINK, addr);
827 wpa_tdls_send_teardown(sm, addr,
828 WLAN_REASON_TDLS_TEARDOWN_UNREACHABLE);
829 wpa_tdls_peer_free(sm, peer);
831 wpa_tdls_disable_peer_link(sm, peer);
836 const char * wpa_tdls_get_link_status(struct wpa_sm *sm, const u8 *addr)
838 struct wpa_tdls_peer *peer;
840 if (sm->tdls_disabled || !sm->tdls_supported)
843 for (peer = sm->tdls; peer; peer = peer->next) {
844 if (os_memcmp(peer->addr, addr, ETH_ALEN) == 0)
849 return "peer does not exist";
851 if (!peer->tpk_success)
852 return "peer not connected";
858 static int wpa_tdls_recv_teardown(struct wpa_sm *sm, const u8 *src_addr,
859 const u8 *buf, size_t len)
861 struct wpa_tdls_peer *peer = NULL;
862 struct wpa_tdls_ftie *ftie;
863 struct wpa_tdls_lnkid *lnkid;
864 struct wpa_eapol_ie_parse kde;
869 /* Find the node and free from the list */
870 for (peer = sm->tdls; peer; peer = peer->next) {
871 if (os_memcmp(peer->addr, src_addr, ETH_ALEN) == 0)
876 wpa_printf(MSG_INFO, "TDLS: No matching entry found for "
877 "Teardown " MACSTR, MAC2STR(src_addr));
882 pos += 1 /* pkt_type */ + 1 /* Category */ + 1 /* Action */;
884 reason_code = WPA_GET_LE16(pos);
887 wpa_printf(MSG_DEBUG, "TDLS: TDLS Teardown Request from " MACSTR
888 " (reason code %u)", MAC2STR(src_addr), reason_code);
890 ielen = len - (pos - buf); /* start of IE in buf */
891 if (wpa_supplicant_parse_ies((const u8 *) pos, ielen, &kde) < 0) {
892 wpa_printf(MSG_INFO, "TDLS: Failed to parse IEs in Teardown");
896 if (kde.lnkid == NULL || kde.lnkid_len < 3 * ETH_ALEN) {
897 wpa_printf(MSG_INFO, "TDLS: No Link Identifier IE in TDLS "
901 lnkid = (struct wpa_tdls_lnkid *) kde.lnkid;
903 if (!wpa_tdls_get_privacy(sm) || !peer->tpk_set || !peer->tpk_success)
906 if (kde.ftie == NULL || kde.ftie_len < sizeof(*ftie)) {
907 wpa_printf(MSG_INFO, "TDLS: No FTIE in TDLS Teardown");
911 ftie = (struct wpa_tdls_ftie *) kde.ftie;
913 /* Process MIC check to see if TDLS Teardown is right */
914 if (wpa_supplicant_verify_tdls_mic_teardown(4, reason_code,
916 (u8 *) lnkid, ftie) < 0) {
917 wpa_printf(MSG_DEBUG, "TDLS: MIC failure for TDLS "
918 "Teardown Request from " MACSTR, MAC2STR(src_addr));
924 * Request the driver to disable the direct link and clear associated
927 wpa_tdls_disable_peer_link(sm, peer);
933 * wpa_tdls_send_error - To send suitable TDLS status response with
934 * appropriate status code mentioning reason for error/failure.
935 * @dst - MAC addr of Peer station
936 * @tdls_action - TDLS frame type for which error code is sent
937 * @status - status code mentioning reason
940 static int wpa_tdls_send_error(struct wpa_sm *sm, const u8 *dst,
941 u8 tdls_action, u8 dialog_token, u16 status)
943 wpa_printf(MSG_DEBUG, "TDLS: Sending error to " MACSTR
944 " (action=%u status=%u)",
945 MAC2STR(dst), tdls_action, status);
946 return wpa_tdls_tpk_send(sm, dst, tdls_action, dialog_token, status,
951 static struct wpa_tdls_peer *
952 wpa_tdls_add_peer(struct wpa_sm *sm, const u8 *addr, int *existing)
954 struct wpa_tdls_peer *peer;
958 for (peer = sm->tdls; peer; peer = peer->next) {
959 if (os_memcmp(peer->addr, addr, ETH_ALEN) == 0) {
962 return peer; /* re-use existing entry */
966 wpa_printf(MSG_INFO, "TDLS: Creating peer entry for " MACSTR,
969 peer = os_zalloc(sizeof(*peer));
973 os_memcpy(peer->addr, addr, ETH_ALEN);
974 peer->next = sm->tdls;
981 static int wpa_tdls_send_tpk_m1(struct wpa_sm *sm,
982 struct wpa_tdls_peer *peer)
985 struct wpa_tdls_timeoutie timeoutie;
987 struct wpa_tdls_ftie *ftie;
988 u8 *rbuf, *pos, *count_pos;
990 struct rsn_ie_hdr *hdr;
993 if (!wpa_tdls_get_privacy(sm)) {
994 wpa_printf(MSG_DEBUG, "TDLS: No security used on the link");
995 peer->rsnie_i_len = 0;
1000 * TPK Handshake Message 1:
1001 * FTIE: ANonce=0, SNonce=initiator nonce MIC=0, DataKDs=(RSNIE_I,
1002 * Timeout Interval IE))
1005 /* Filling RSN IE */
1006 hdr = (struct rsn_ie_hdr *) peer->rsnie_i;
1007 hdr->elem_id = WLAN_EID_RSN;
1008 WPA_PUT_LE16(hdr->version, RSN_VERSION);
1010 pos = (u8 *) (hdr + 1);
1011 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED);
1012 pos += RSN_SELECTOR_LEN;
1019 * AES-CCMP is the default Encryption preferred for TDLS, so
1020 * RSN IE is filled only with CCMP CIPHER
1021 * Note: TKIP is not used to encrypt TDLS link.
1023 * Regardless of the cipher used on the AP connection, select CCMP
1026 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
1027 pos += RSN_SELECTOR_LEN;
1030 WPA_PUT_LE16(count_pos, count);
1032 WPA_PUT_LE16(pos, 1);
1034 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_TPK_HANDSHAKE);
1035 pos += RSN_SELECTOR_LEN;
1037 rsn_capab = WPA_CAPABILITY_PEERKEY_ENABLED;
1038 rsn_capab |= RSN_NUM_REPLAY_COUNTERS_16 << 2;
1039 #ifdef CONFIG_TDLS_TESTING
1040 if (tdls_testing & TDLS_TESTING_ALT_RSN_IE) {
1041 wpa_printf(MSG_DEBUG, "TDLS: Use alternative RSN IE for "
1043 rsn_capab = WPA_CAPABILITY_PEERKEY_ENABLED;
1045 #endif /* CONFIG_TDLS_TESTING */
1046 WPA_PUT_LE16(pos, rsn_capab);
1048 #ifdef CONFIG_TDLS_TESTING
1049 if (tdls_testing & TDLS_TESTING_ALT_RSN_IE) {
1050 /* Number of PMKIDs */
1054 #endif /* CONFIG_TDLS_TESTING */
1056 hdr->len = (pos - peer->rsnie_i) - 2;
1057 peer->rsnie_i_len = pos - peer->rsnie_i;
1058 wpa_hexdump(MSG_DEBUG, "TDLS: RSN IE for TPK handshake",
1059 peer->rsnie_i, peer->rsnie_i_len);
1063 if (wpa_tdls_get_privacy(sm))
1064 buf_len += peer->rsnie_i_len + sizeof(struct wpa_tdls_ftie) +
1065 sizeof(struct wpa_tdls_timeoutie);
1066 #ifdef CONFIG_TDLS_TESTING
1067 if (wpa_tdls_get_privacy(sm) &&
1068 (tdls_testing & TDLS_TESTING_LONG_FRAME))
1070 if (tdls_testing & TDLS_TESTING_DIFF_BSSID)
1071 buf_len += sizeof(struct wpa_tdls_lnkid);
1072 #endif /* CONFIG_TDLS_TESTING */
1073 rbuf = os_zalloc(buf_len + 1);
1075 wpa_tdls_peer_free(sm, peer);
1080 if (!wpa_tdls_get_privacy(sm))
1083 /* Initiator RSN IE */
1084 pos = wpa_add_ie(pos, peer->rsnie_i, peer->rsnie_i_len);
1086 ftie = (struct wpa_tdls_ftie *) pos;
1087 ftie->ie_type = WLAN_EID_FAST_BSS_TRANSITION;
1088 ftie->ie_len = sizeof(struct wpa_tdls_ftie) - 2;
1090 if (os_get_random(peer->inonce, WPA_NONCE_LEN)) {
1091 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1092 "TDLS: Failed to get random data for initiator Nonce");
1094 wpa_tdls_peer_free(sm, peer);
1097 wpa_hexdump(MSG_DEBUG, "TDLS: Initiator Nonce for TPK handshake",
1098 peer->inonce, WPA_NONCE_LEN);
1099 os_memcpy(ftie->Snonce, peer->inonce, WPA_NONCE_LEN);
1101 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE for TPK Handshake M1",
1102 (u8 *) ftie, sizeof(struct wpa_tdls_ftie));
1104 pos = (u8 *) (ftie + 1);
1106 #ifdef CONFIG_TDLS_TESTING
1107 if (tdls_testing & TDLS_TESTING_LONG_FRAME) {
1108 wpa_printf(MSG_DEBUG, "TDLS: Testing - add extra subelem to "
1110 ftie->ie_len += 170;
1111 *pos++ = 255; /* FTIE subelem */
1112 *pos++ = 168; /* FTIE subelem length */
1115 #endif /* CONFIG_TDLS_TESTING */
1118 peer->lifetime = TPK_LIFETIME;
1119 #ifdef CONFIG_TDLS_TESTING
1120 if (tdls_testing & TDLS_TESTING_SHORT_LIFETIME) {
1121 wpa_printf(MSG_DEBUG, "TDLS: Testing - use short TPK "
1123 peer->lifetime = 301;
1125 if (tdls_testing & TDLS_TESTING_LONG_LIFETIME) {
1126 wpa_printf(MSG_DEBUG, "TDLS: Testing - use long TPK "
1128 peer->lifetime = 0xffffffff;
1130 #endif /* CONFIG_TDLS_TESTING */
1131 pos = wpa_add_tdls_timeoutie(pos, (u8 *) &timeoutie,
1132 sizeof(timeoutie), peer->lifetime);
1133 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime %u seconds", peer->lifetime);
1137 #ifdef CONFIG_TDLS_TESTING
1138 if (tdls_testing & TDLS_TESTING_DIFF_BSSID) {
1139 wpa_printf(MSG_DEBUG, "TDLS: Testing - use incorrect BSSID in "
1141 struct wpa_tdls_lnkid *l = (struct wpa_tdls_lnkid *) pos;
1142 wpa_tdls_linkid(sm, peer, l);
1143 l->bssid[5] ^= 0x01;
1146 #endif /* CONFIG_TDLS_TESTING */
1148 wpa_printf(MSG_DEBUG, "TDLS: Sending TDLS Setup Request / TPK "
1149 "Handshake Message 1 (peer " MACSTR ")",
1150 MAC2STR(peer->addr));
1152 status = wpa_tdls_tpk_send(sm, peer->addr, WLAN_TDLS_SETUP_REQUEST,
1153 1, 0, 0, rbuf, pos - rbuf);
1160 static int wpa_tdls_send_tpk_m2(struct wpa_sm *sm,
1161 const unsigned char *src_addr, u8 dtoken,
1162 struct wpa_tdls_lnkid *lnkid,
1163 const struct wpa_tdls_peer *peer)
1168 struct wpa_tdls_timeoutie timeoutie;
1169 struct wpa_tdls_ftie *ftie;
1173 if (wpa_tdls_get_privacy(sm)) {
1174 /* Peer RSN IE, FTIE(Initiator Nonce, Responder Nonce),
1176 buf_len += peer->rsnie_i_len + sizeof(struct wpa_tdls_ftie) +
1177 sizeof(struct wpa_tdls_timeoutie);
1178 #ifdef CONFIG_TDLS_TESTING
1179 if (tdls_testing & TDLS_TESTING_LONG_FRAME)
1181 #endif /* CONFIG_TDLS_TESTING */
1184 rbuf = os_zalloc(buf_len + 1);
1189 if (!wpa_tdls_get_privacy(sm))
1193 pos = wpa_add_ie(pos, peer->rsnie_p, peer->rsnie_p_len);
1195 ftie = (struct wpa_tdls_ftie *) pos;
1196 ftie->ie_type = WLAN_EID_FAST_BSS_TRANSITION;
1197 /* TODO: ftie->mic_control to set 2-RESPONSE */
1198 os_memcpy(ftie->Anonce, peer->rnonce, WPA_NONCE_LEN);
1199 os_memcpy(ftie->Snonce, peer->inonce, WPA_NONCE_LEN);
1200 ftie->ie_len = sizeof(struct wpa_tdls_ftie) - 2;
1201 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE for TPK M2",
1202 (u8 *) ftie, sizeof(*ftie));
1204 pos = (u8 *) (ftie + 1);
1206 #ifdef CONFIG_TDLS_TESTING
1207 if (tdls_testing & TDLS_TESTING_LONG_FRAME) {
1208 wpa_printf(MSG_DEBUG, "TDLS: Testing - add extra subelem to "
1210 ftie->ie_len += 170;
1211 *pos++ = 255; /* FTIE subelem */
1212 *pos++ = 168; /* FTIE subelem length */
1215 #endif /* CONFIG_TDLS_TESTING */
1218 lifetime = peer->lifetime;
1219 #ifdef CONFIG_TDLS_TESTING
1220 if (tdls_testing & TDLS_TESTING_WRONG_LIFETIME_RESP) {
1221 wpa_printf(MSG_DEBUG, "TDLS: Testing - use wrong TPK "
1222 "lifetime in response");
1225 #endif /* CONFIG_TDLS_TESTING */
1226 pos = wpa_add_tdls_timeoutie(pos, (u8 *) &timeoutie,
1227 sizeof(timeoutie), lifetime);
1228 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime %u seconds from initiator",
1231 /* compute MIC before sending */
1232 wpa_tdls_ftie_mic(peer->tpk.kck, 2, (u8 *) lnkid, peer->rsnie_p,
1233 (u8 *) &timeoutie, (u8 *) ftie, ftie->mic);
1234 #ifdef CONFIG_TDLS_TESTING
1235 if (tdls_testing & TDLS_TESTING_WRONG_MIC) {
1236 wpa_printf(MSG_DEBUG, "TDLS: Testing - use wrong MIC");
1237 ftie->mic[0] ^= 0x01;
1239 #endif /* CONFIG_TDLS_TESTING */
1242 status = wpa_tdls_tpk_send(sm, src_addr, WLAN_TDLS_SETUP_RESPONSE,
1243 dtoken, 0, 0, rbuf, pos - rbuf);
1250 static int wpa_tdls_send_tpk_m3(struct wpa_sm *sm,
1251 const unsigned char *src_addr, u8 dtoken,
1252 struct wpa_tdls_lnkid *lnkid,
1253 const struct wpa_tdls_peer *peer)
1257 struct wpa_tdls_ftie *ftie;
1258 struct wpa_tdls_timeoutie timeoutie;
1264 if (wpa_tdls_get_privacy(sm)) {
1265 /* Peer RSN IE, FTIE(Initiator Nonce, Responder Nonce),
1267 buf_len += peer->rsnie_i_len + sizeof(struct wpa_tdls_ftie) +
1268 sizeof(struct wpa_tdls_timeoutie);
1269 #ifdef CONFIG_TDLS_TESTING
1270 if (tdls_testing & TDLS_TESTING_LONG_FRAME)
1272 #endif /* CONFIG_TDLS_TESTING */
1275 rbuf = os_zalloc(buf_len + 1);
1280 if (!wpa_tdls_get_privacy(sm))
1284 pos = wpa_add_ie(pos, peer->rsnie_p, peer->rsnie_p_len);
1286 ftie = (struct wpa_tdls_ftie *) pos;
1287 ftie->ie_type = WLAN_EID_FAST_BSS_TRANSITION;
1288 /*TODO: ftie->mic_control to set 3-CONFIRM */
1289 os_memcpy(ftie->Anonce, peer->rnonce, WPA_NONCE_LEN);
1290 os_memcpy(ftie->Snonce, peer->inonce, WPA_NONCE_LEN);
1291 ftie->ie_len = sizeof(struct wpa_tdls_ftie) - 2;
1293 pos = (u8 *) (ftie + 1);
1295 #ifdef CONFIG_TDLS_TESTING
1296 if (tdls_testing & TDLS_TESTING_LONG_FRAME) {
1297 wpa_printf(MSG_DEBUG, "TDLS: Testing - add extra subelem to "
1299 ftie->ie_len += 170;
1300 *pos++ = 255; /* FTIE subelem */
1301 *pos++ = 168; /* FTIE subelem length */
1304 #endif /* CONFIG_TDLS_TESTING */
1307 lifetime = peer->lifetime;
1308 #ifdef CONFIG_TDLS_TESTING
1309 if (tdls_testing & TDLS_TESTING_WRONG_LIFETIME_CONF) {
1310 wpa_printf(MSG_DEBUG, "TDLS: Testing - use wrong TPK "
1311 "lifetime in confirm");
1314 #endif /* CONFIG_TDLS_TESTING */
1315 pos = wpa_add_tdls_timeoutie(pos, (u8 *) &timeoutie,
1316 sizeof(timeoutie), lifetime);
1317 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime %u seconds",
1320 /* compute MIC before sending */
1321 wpa_tdls_ftie_mic(peer->tpk.kck, 3, (u8 *) lnkid, peer->rsnie_p,
1322 (u8 *) &timeoutie, (u8 *) ftie, ftie->mic);
1323 #ifdef CONFIG_TDLS_TESTING
1324 if (tdls_testing & TDLS_TESTING_WRONG_MIC) {
1325 wpa_printf(MSG_DEBUG, "TDLS: Testing - use wrong MIC");
1326 ftie->mic[0] ^= 0x01;
1328 #endif /* CONFIG_TDLS_TESTING */
1332 if (peer->vht_capabilities)
1333 peer_capab |= TDLS_PEER_VHT;
1334 if (peer->ht_capabilities)
1335 peer_capab |= TDLS_PEER_HT;
1336 if (peer->wmm_capable)
1337 peer_capab |= TDLS_PEER_WMM;
1339 status = wpa_tdls_tpk_send(sm, src_addr, WLAN_TDLS_SETUP_CONFIRM,
1340 dtoken, 0, peer_capab, rbuf, pos - rbuf);
1347 static int wpa_tdls_send_discovery_response(struct wpa_sm *sm,
1348 struct wpa_tdls_peer *peer,
1351 wpa_printf(MSG_DEBUG, "TDLS: Sending TDLS Discovery Response "
1352 "(peer " MACSTR ")", MAC2STR(peer->addr));
1354 return wpa_tdls_tpk_send(sm, peer->addr, WLAN_TDLS_DISCOVERY_RESPONSE,
1355 dialog_token, 0, 0, NULL, 0);
1360 wpa_tdls_process_discovery_request(struct wpa_sm *sm, const u8 *addr,
1361 const u8 *buf, size_t len)
1363 struct wpa_eapol_ie_parse kde;
1364 const struct wpa_tdls_lnkid *lnkid;
1365 struct wpa_tdls_peer *peer;
1366 size_t min_req_len = sizeof(struct wpa_tdls_frame) +
1367 1 /* dialog token */ + sizeof(struct wpa_tdls_lnkid);
1370 wpa_printf(MSG_DEBUG, "TDLS: Discovery Request from " MACSTR,
1373 if (len < min_req_len) {
1374 wpa_printf(MSG_DEBUG, "TDLS Discovery Request is too short: "
1379 dialog_token = buf[sizeof(struct wpa_tdls_frame)];
1382 * Some APs will tack on a weird IE to the end of a TDLS
1383 * discovery request packet. This needn't fail the response,
1384 * since the required IE are verified separately.
1386 if (wpa_supplicant_parse_ies(buf + sizeof(struct wpa_tdls_frame) + 1,
1387 len - (sizeof(struct wpa_tdls_frame) + 1),
1389 wpa_printf(MSG_DEBUG,
1390 "TDLS: Failed to parse IEs in Discovery Request - ignore as an interop workaround");
1394 wpa_printf(MSG_DEBUG, "TDLS: Link ID not found in Discovery "
1399 lnkid = (const struct wpa_tdls_lnkid *) kde.lnkid;
1401 if (os_memcmp(sm->bssid, lnkid->bssid, ETH_ALEN) != 0) {
1402 wpa_printf(MSG_DEBUG, "TDLS: Discovery Request from different "
1403 " BSS " MACSTR, MAC2STR(lnkid->bssid));
1407 peer = wpa_tdls_add_peer(sm, addr, NULL);
1411 return wpa_tdls_send_discovery_response(sm, peer, dialog_token);
1415 int wpa_tdls_send_discovery_request(struct wpa_sm *sm, const u8 *addr)
1417 if (sm->tdls_disabled || !sm->tdls_supported)
1420 wpa_printf(MSG_DEBUG, "TDLS: Sending Discovery Request to peer "
1421 MACSTR, MAC2STR(addr));
1422 return wpa_tdls_tpk_send(sm, addr, WLAN_TDLS_DISCOVERY_REQUEST,
1427 static int copy_supp_rates(const struct wpa_eapol_ie_parse *kde,
1428 struct wpa_tdls_peer *peer)
1430 if (!kde->supp_rates) {
1431 wpa_printf(MSG_DEBUG, "TDLS: No supported rates received");
1434 peer->supp_rates_len = merge_byte_arrays(
1435 peer->supp_rates, sizeof(peer->supp_rates),
1436 kde->supp_rates + 2, kde->supp_rates_len - 2,
1437 kde->ext_supp_rates ? kde->ext_supp_rates + 2 : NULL,
1438 kde->ext_supp_rates_len - 2);
1443 static int copy_peer_ht_capab(const struct wpa_eapol_ie_parse *kde,
1444 struct wpa_tdls_peer *peer)
1446 if (!kde->ht_capabilities ||
1447 kde->ht_capabilities_len <
1448 sizeof(struct ieee80211_ht_capabilities) ) {
1449 wpa_printf(MSG_DEBUG, "TDLS: No supported ht capabilities "
1454 if (!peer->ht_capabilities) {
1455 peer->ht_capabilities =
1456 os_zalloc(sizeof(struct ieee80211_ht_capabilities));
1457 if (peer->ht_capabilities == NULL)
1461 os_memcpy(peer->ht_capabilities, kde->ht_capabilities,
1462 sizeof(struct ieee80211_ht_capabilities));
1463 wpa_hexdump(MSG_DEBUG, "TDLS: Peer HT capabilities",
1464 (u8 *) peer->ht_capabilities,
1465 sizeof(struct ieee80211_ht_capabilities));
1471 static int copy_peer_vht_capab(const struct wpa_eapol_ie_parse *kde,
1472 struct wpa_tdls_peer *peer)
1474 if (!kde->vht_capabilities ||
1475 kde->vht_capabilities_len <
1476 sizeof(struct ieee80211_vht_capabilities) ) {
1477 wpa_printf(MSG_DEBUG, "TDLS: No supported vht capabilities "
1482 if (!peer->vht_capabilities) {
1483 peer->vht_capabilities =
1484 os_zalloc(sizeof(struct ieee80211_vht_capabilities));
1485 if (peer->vht_capabilities == NULL)
1489 os_memcpy(peer->vht_capabilities, kde->vht_capabilities,
1490 sizeof(struct ieee80211_vht_capabilities));
1491 wpa_hexdump(MSG_DEBUG, "TDLS: Peer VHT capabilities",
1492 (u8 *) peer->vht_capabilities,
1493 sizeof(struct ieee80211_vht_capabilities));
1499 static int copy_peer_ext_capab(const struct wpa_eapol_ie_parse *kde,
1500 struct wpa_tdls_peer *peer)
1502 if (!kde->ext_capab) {
1503 wpa_printf(MSG_DEBUG, "TDLS: No extended capabilities "
1508 if (!peer->ext_capab || peer->ext_capab_len < kde->ext_capab_len - 2) {
1509 /* Need to allocate buffer to fit the new information */
1510 os_free(peer->ext_capab);
1511 peer->ext_capab = os_zalloc(kde->ext_capab_len - 2);
1512 if (peer->ext_capab == NULL)
1516 peer->ext_capab_len = kde->ext_capab_len - 2;
1517 os_memcpy(peer->ext_capab, kde->ext_capab + 2, peer->ext_capab_len);
1523 static int copy_peer_wmm_capab(const struct wpa_eapol_ie_parse *kde,
1524 struct wpa_tdls_peer *peer)
1526 struct wmm_information_element *wmm;
1529 wpa_printf(MSG_DEBUG, "TDLS: No supported WMM capabilities received");
1533 if (kde->wmm_len < sizeof(struct wmm_information_element)) {
1534 wpa_printf(MSG_DEBUG, "TDLS: Invalid supported WMM capabilities received");
1538 wmm = (struct wmm_information_element *) kde->wmm;
1539 peer->qos_info = wmm->qos_info;
1541 peer->wmm_capable = 1;
1543 wpa_printf(MSG_DEBUG, "TDLS: Peer WMM QOS Info 0x%x", peer->qos_info);
1548 static int copy_peer_supp_channels(const struct wpa_eapol_ie_parse *kde,
1549 struct wpa_tdls_peer *peer)
1551 if (!kde->supp_channels) {
1552 wpa_printf(MSG_DEBUG, "TDLS: No supported channels received");
1556 if (!peer->supp_channels ||
1557 peer->supp_channels_len < kde->supp_channels_len) {
1558 os_free(peer->supp_channels);
1559 peer->supp_channels = os_zalloc(kde->supp_channels_len);
1560 if (peer->supp_channels == NULL)
1564 peer->supp_channels_len = kde->supp_channels_len;
1566 os_memcpy(peer->supp_channels, kde->supp_channels,
1567 peer->supp_channels_len);
1568 wpa_hexdump(MSG_DEBUG, "TDLS: Peer Supported Channels",
1569 (u8 *) peer->supp_channels, peer->supp_channels_len);
1574 static int copy_peer_supp_oper_classes(const struct wpa_eapol_ie_parse *kde,
1575 struct wpa_tdls_peer *peer)
1577 if (!kde->supp_oper_classes) {
1578 wpa_printf(MSG_DEBUG, "TDLS: No supported operating classes received");
1582 if (!peer->supp_oper_classes ||
1583 peer->supp_oper_classes_len < kde->supp_oper_classes_len) {
1584 os_free(peer->supp_oper_classes);
1585 peer->supp_oper_classes = os_zalloc(kde->supp_oper_classes_len);
1586 if (peer->supp_oper_classes == NULL)
1590 peer->supp_oper_classes_len = kde->supp_oper_classes_len;
1591 os_memcpy(peer->supp_oper_classes, kde->supp_oper_classes,
1592 peer->supp_oper_classes_len);
1593 wpa_hexdump(MSG_DEBUG, "TDLS: Peer Supported Operating Classes",
1594 (u8 *) peer->supp_oper_classes,
1595 peer->supp_oper_classes_len);
1600 static int wpa_tdls_process_tpk_m1(struct wpa_sm *sm, const u8 *src_addr,
1601 const u8 *buf, size_t len)
1603 struct wpa_tdls_peer *peer;
1604 struct wpa_eapol_ie_parse kde;
1605 struct wpa_ie_data ie;
1608 struct wpa_tdls_ftie *ftie = NULL;
1609 struct wpa_tdls_timeoutie *timeoutie;
1610 struct wpa_tdls_lnkid *lnkid;
1613 struct rsn_ie_hdr *hdr;
1620 u16 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1621 int tdls_prohibited = sm->tdls_prohibited;
1622 int existing_peer = 0;
1628 cpos += 1 /* pkt_type */ + 1 /* Category */ + 1 /* Action */;
1630 /* driver had already verified the frame format */
1631 dtoken = *cpos++; /* dialog token */
1633 wpa_printf(MSG_INFO, "TDLS: Dialog Token in TPK M1 %d", dtoken);
1635 peer = wpa_tdls_add_peer(sm, src_addr, &existing_peer);
1639 /* If found, use existing entry instead of adding a new one;
1640 * how to handle the case where both ends initiate at the
1642 if (existing_peer) {
1643 if (peer->tpk_success) {
1644 wpa_printf(MSG_DEBUG, "TDLS: TDLS Setup Request while "
1645 "direct link is enabled - tear down the "
1647 wpa_tdls_disable_peer_link(sm, peer);
1651 * An entry is already present, so check if we already sent a
1652 * TDLS Setup Request. If so, compare MAC addresses and let the
1653 * STA with the lower MAC address continue as the initiator.
1654 * The other negotiation is terminated.
1656 if (peer->initiator) {
1657 if (os_memcmp(sm->own_addr, src_addr, ETH_ALEN) < 0) {
1658 wpa_printf(MSG_DEBUG, "TDLS: Discard request "
1659 "from peer with higher address "
1660 MACSTR, MAC2STR(src_addr));
1663 wpa_printf(MSG_DEBUG, "TDLS: Accept request "
1664 "from peer with lower address "
1665 MACSTR " (terminate previously "
1666 "initiated negotiation",
1668 wpa_tdls_disable_peer_link(sm, peer);
1673 /* capability information */
1674 peer->capability = WPA_GET_LE16(cpos);
1677 ielen = len - (cpos - buf); /* start of IE in buf */
1678 if (wpa_supplicant_parse_ies(cpos, ielen, &kde) < 0) {
1679 wpa_printf(MSG_INFO, "TDLS: Failed to parse IEs in TPK M1");
1683 if (kde.lnkid == NULL || kde.lnkid_len < 3 * ETH_ALEN) {
1684 wpa_printf(MSG_INFO, "TDLS: No valid Link Identifier IE in "
1688 wpa_hexdump(MSG_DEBUG, "TDLS: Link ID Received from TPK M1",
1689 kde.lnkid, kde.lnkid_len);
1690 lnkid = (struct wpa_tdls_lnkid *) kde.lnkid;
1691 if (os_memcmp(sm->bssid, lnkid->bssid, ETH_ALEN) != 0) {
1692 wpa_printf(MSG_INFO, "TDLS: TPK M1 from diff BSS");
1693 status = WLAN_STATUS_NOT_IN_SAME_BSS;
1697 wpa_printf(MSG_DEBUG, "TDLS: TPK M1 - TPK initiator " MACSTR,
1700 if (copy_supp_rates(&kde, peer) < 0)
1703 if (copy_peer_ht_capab(&kde, peer) < 0)
1706 if (copy_peer_vht_capab(&kde, peer) < 0)
1709 if (copy_peer_ext_capab(&kde, peer) < 0)
1712 if (copy_peer_supp_channels(&kde, peer) < 0)
1715 if (copy_peer_supp_oper_classes(&kde, peer) < 0)
1718 peer->qos_info = kde.qosinfo;
1720 /* Overwrite with the qos_info obtained in WMM IE */
1721 if (copy_peer_wmm_capab(&kde, peer) < 0)
1724 peer->aid = kde.aid;
1726 #ifdef CONFIG_TDLS_TESTING
1727 if (tdls_testing & TDLS_TESTING_CONCURRENT_INIT) {
1728 peer = wpa_tdls_add_peer(sm, src_addr, NULL);
1731 wpa_printf(MSG_DEBUG, "TDLS: Testing concurrent initiation of "
1732 "TDLS setup - send own request");
1733 peer->initiator = 1;
1734 wpa_tdls_send_tpk_m1(sm, peer);
1737 if ((tdls_testing & TDLS_TESTING_IGNORE_AP_PROHIBIT) &&
1739 wpa_printf(MSG_DEBUG, "TDLS: Testing - ignore AP prohibition "
1741 tdls_prohibited = 0;
1743 #endif /* CONFIG_TDLS_TESTING */
1745 if (tdls_prohibited) {
1746 wpa_printf(MSG_INFO, "TDLS: TDLS prohibited in this BSS");
1747 status = WLAN_STATUS_REQUEST_DECLINED;
1751 if (!wpa_tdls_get_privacy(sm)) {
1753 wpa_printf(MSG_INFO, "TDLS: RSN IE in TPK M1 while "
1754 "security is disabled");
1755 status = WLAN_STATUS_SECURITY_DISABLED;
1761 if (kde.ftie == NULL || kde.ftie_len < sizeof(*ftie) ||
1762 kde.rsn_ie == NULL) {
1763 wpa_printf(MSG_INFO, "TDLS: No FTIE or RSN IE in TPK M1");
1764 status = WLAN_STATUS_INVALID_PARAMETERS;
1768 if (kde.rsn_ie_len > TDLS_MAX_IE_LEN) {
1769 wpa_printf(MSG_INFO, "TDLS: Too long Initiator RSN IE in "
1771 status = WLAN_STATUS_INVALID_RSNIE;
1775 if (wpa_parse_wpa_ie_rsn(kde.rsn_ie, kde.rsn_ie_len, &ie) < 0) {
1776 wpa_printf(MSG_INFO, "TDLS: Failed to parse RSN IE in TPK M1");
1777 status = WLAN_STATUS_INVALID_RSNIE;
1781 cipher = ie.pairwise_cipher;
1782 if (cipher & WPA_CIPHER_CCMP) {
1783 wpa_printf(MSG_DEBUG, "TDLS: Using CCMP for direct link");
1784 cipher = WPA_CIPHER_CCMP;
1786 wpa_printf(MSG_INFO, "TDLS: No acceptable cipher in TPK M1");
1787 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1791 if ((ie.capabilities &
1792 (WPA_CAPABILITY_NO_PAIRWISE | WPA_CAPABILITY_PEERKEY_ENABLED)) !=
1793 WPA_CAPABILITY_PEERKEY_ENABLED) {
1794 wpa_printf(MSG_INFO, "TDLS: Invalid RSN Capabilities in "
1796 status = WLAN_STATUS_INVALID_RSN_IE_CAPAB;
1801 if (kde.key_lifetime == NULL) {
1802 wpa_printf(MSG_INFO, "TDLS: No Key Lifetime IE in TPK M1");
1803 status = WLAN_STATUS_UNACCEPTABLE_LIFETIME;
1806 timeoutie = (struct wpa_tdls_timeoutie *) kde.key_lifetime;
1807 lifetime = WPA_GET_LE32(timeoutie->value);
1808 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime %u seconds", lifetime);
1809 if (lifetime < 300) {
1810 wpa_printf(MSG_INFO, "TDLS: Too short TPK lifetime");
1811 status = WLAN_STATUS_UNACCEPTABLE_LIFETIME;
1816 #ifdef CONFIG_TDLS_TESTING
1817 if (tdls_testing & TDLS_TESTING_CONCURRENT_INIT) {
1818 if (os_memcmp(sm->own_addr, peer->addr, ETH_ALEN) < 0) {
1820 * The request frame from us is going to win, so do not
1821 * replace information based on this request frame from
1824 goto skip_rsn_check;
1827 #endif /* CONFIG_TDLS_TESTING */
1829 peer->initiator = 0; /* Need to check */
1830 peer->dtoken = dtoken;
1832 if (!wpa_tdls_get_privacy(sm)) {
1833 peer->rsnie_i_len = 0;
1834 peer->rsnie_p_len = 0;
1835 peer->cipher = WPA_CIPHER_NONE;
1836 goto skip_rsn_check;
1839 ftie = (struct wpa_tdls_ftie *) kde.ftie;
1840 os_memcpy(peer->rsnie_i, kde.rsn_ie, kde.rsn_ie_len);
1841 peer->rsnie_i_len = kde.rsn_ie_len;
1842 peer->cipher = cipher;
1844 if (os_memcmp(peer->inonce, ftie->Snonce, WPA_NONCE_LEN) != 0) {
1846 * There is no point in updating the RNonce for every obtained
1847 * TPK M1 frame (e.g., retransmission due to timeout) with the
1848 * same INonce (SNonce in FTIE). However, if the TPK M1 is
1849 * retransmitted with a different INonce, update the RNonce
1850 * since this is for a new TDLS session.
1852 wpa_printf(MSG_DEBUG,
1853 "TDLS: New TPK M1 INonce - generate new RNonce");
1854 os_memcpy(peer->inonce, ftie->Snonce, WPA_NONCE_LEN);
1855 if (os_get_random(peer->rnonce, WPA_NONCE_LEN)) {
1856 wpa_msg(sm->ctx->ctx, MSG_WARNING,
1857 "TDLS: Failed to get random data for responder nonce");
1863 /* get version info from RSNIE received from Peer */
1864 hdr = (struct rsn_ie_hdr *) kde.rsn_ie;
1865 rsn_ver = WPA_GET_LE16(hdr->version);
1867 /* use min(peer's version, out version) */
1868 if (rsn_ver > RSN_VERSION)
1869 rsn_ver = RSN_VERSION;
1871 hdr = (struct rsn_ie_hdr *) peer->rsnie_p;
1873 hdr->elem_id = WLAN_EID_RSN;
1874 WPA_PUT_LE16(hdr->version, rsn_ver);
1875 pos = (u8 *) (hdr + 1);
1877 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED);
1878 pos += RSN_SELECTOR_LEN;
1879 /* Include only the selected cipher in pairwise cipher suite */
1880 WPA_PUT_LE16(pos, 1);
1882 if (cipher == WPA_CIPHER_CCMP)
1883 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
1884 pos += RSN_SELECTOR_LEN;
1886 WPA_PUT_LE16(pos, 1);
1888 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_TPK_HANDSHAKE);
1889 pos += RSN_SELECTOR_LEN;
1891 rsn_capab = WPA_CAPABILITY_PEERKEY_ENABLED;
1892 rsn_capab |= RSN_NUM_REPLAY_COUNTERS_16 << 2;
1893 WPA_PUT_LE16(pos, rsn_capab);
1896 hdr->len = (pos - peer->rsnie_p) - 2;
1897 peer->rsnie_p_len = pos - peer->rsnie_p;
1900 /* temp fix: validation of RSNIE later */
1901 os_memcpy(peer->rsnie_p, peer->rsnie_i, peer->rsnie_i_len);
1902 peer->rsnie_p_len = peer->rsnie_i_len;
1904 wpa_hexdump(MSG_DEBUG, "TDLS: RSN IE for TPK handshake",
1905 peer->rsnie_p, peer->rsnie_p_len);
1907 peer->lifetime = lifetime;
1909 wpa_tdls_generate_tpk(peer, sm->own_addr, sm->bssid);
1912 /* add the peer to the driver as a "setup in progress" peer */
1913 if (wpa_sm_tdls_peer_addset(sm, peer->addr, 1, 0, 0, NULL, 0, NULL,
1914 NULL, 0, NULL, 0, NULL, 0, NULL, 0))
1917 peer->tpk_in_progress = 1;
1919 wpa_printf(MSG_DEBUG, "TDLS: Sending TDLS Setup Response / TPK M2");
1920 if (wpa_tdls_send_tpk_m2(sm, src_addr, dtoken, lnkid, peer) < 0) {
1921 wpa_tdls_disable_peer_link(sm, peer);
1928 wpa_tdls_send_error(sm, src_addr, WLAN_TDLS_SETUP_RESPONSE, dtoken,
1931 wpa_tdls_peer_free(sm, peer);
1936 static int wpa_tdls_enable_link(struct wpa_sm *sm, struct wpa_tdls_peer *peer)
1938 peer->tpk_success = 1;
1939 peer->tpk_in_progress = 0;
1940 eloop_cancel_timeout(wpa_tdls_tpk_timeout, sm, peer);
1941 if (wpa_tdls_get_privacy(sm)) {
1942 u32 lifetime = peer->lifetime;
1944 * Start the initiator process a bit earlier to avoid race
1945 * condition with the responder sending teardown request.
1947 if (lifetime > 3 && peer->initiator)
1949 eloop_register_timeout(lifetime, 0, wpa_tdls_tpk_timeout,
1951 #ifdef CONFIG_TDLS_TESTING
1952 if (tdls_testing & TDLS_TESTING_NO_TPK_EXPIRATION) {
1953 wpa_printf(MSG_DEBUG, "TDLS: Testing - disable TPK "
1955 eloop_cancel_timeout(wpa_tdls_tpk_timeout, sm, peer);
1957 #endif /* CONFIG_TDLS_TESTING */
1960 /* add supported rates, capabilities, and qos_info to the TDLS peer */
1961 if (wpa_sm_tdls_peer_addset(sm, peer->addr, 0, peer->aid,
1963 peer->supp_rates, peer->supp_rates_len,
1964 peer->ht_capabilities,
1965 peer->vht_capabilities,
1966 peer->qos_info, peer->ext_capab,
1967 peer->ext_capab_len,
1968 peer->supp_channels,
1969 peer->supp_channels_len,
1970 peer->supp_oper_classes,
1971 peer->supp_oper_classes_len) < 0)
1974 if (peer->reconfig_key && wpa_tdls_set_key(sm, peer) < 0) {
1975 wpa_printf(MSG_INFO, "TDLS: Could not configure key to the "
1979 peer->reconfig_key = 0;
1981 return wpa_sm_tdls_oper(sm, TDLS_ENABLE_LINK, peer->addr);
1985 static int wpa_tdls_process_tpk_m2(struct wpa_sm *sm, const u8 *src_addr,
1986 const u8 *buf, size_t len)
1988 struct wpa_tdls_peer *peer;
1989 struct wpa_eapol_ie_parse kde;
1990 struct wpa_ie_data ie;
1992 struct wpa_tdls_ftie *ftie;
1993 struct wpa_tdls_timeoutie *timeoutie;
1994 struct wpa_tdls_lnkid *lnkid;
2002 wpa_printf(MSG_DEBUG, "TDLS: Received TDLS Setup Response / TPK M2 "
2003 "(Peer " MACSTR ")", MAC2STR(src_addr));
2004 for (peer = sm->tdls; peer; peer = peer->next) {
2005 if (os_memcmp(peer->addr, src_addr, ETH_ALEN) == 0)
2009 wpa_printf(MSG_INFO, "TDLS: No matching peer found for "
2010 "TPK M2: " MACSTR, MAC2STR(src_addr));
2013 if (!peer->initiator) {
2015 * This may happen if both devices try to initiate TDLS at the
2016 * same time and we accept the TPK M1 from the peer in
2017 * wpa_tdls_process_tpk_m1() and clear our previous state.
2019 wpa_printf(MSG_INFO, "TDLS: We were not the initiator, so "
2020 "ignore TPK M2 from " MACSTR, MAC2STR(src_addr));
2023 wpa_tdls_tpk_retry_timeout_cancel(sm, peer, WLAN_TDLS_SETUP_REQUEST);
2025 if (len < 3 + 2 + 1) {
2026 wpa_tdls_disable_peer_link(sm, peer);
2031 pos += 1 /* pkt_type */ + 1 /* Category */ + 1 /* Action */;
2032 status = WPA_GET_LE16(pos);
2033 pos += 2 /* status code */;
2035 if (status != WLAN_STATUS_SUCCESS) {
2036 wpa_printf(MSG_INFO, "TDLS: Status code in TPK M2: %u",
2038 wpa_tdls_disable_peer_link(sm, peer);
2042 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
2044 /* TODO: need to verify dialog token matches here or in kernel */
2045 dtoken = *pos++; /* dialog token */
2047 wpa_printf(MSG_DEBUG, "TDLS: Dialog Token in TPK M2 %d", dtoken);
2049 if (len < 3 + 2 + 1 + 2) {
2050 wpa_tdls_disable_peer_link(sm, peer);
2054 /* capability information */
2055 peer->capability = WPA_GET_LE16(pos);
2058 ielen = len - (pos - buf); /* start of IE in buf */
2059 if (wpa_supplicant_parse_ies(pos, ielen, &kde) < 0) {
2060 wpa_printf(MSG_INFO, "TDLS: Failed to parse IEs in TPK M2");
2064 #ifdef CONFIG_TDLS_TESTING
2065 if (tdls_testing & TDLS_TESTING_DECLINE_RESP) {
2066 wpa_printf(MSG_DEBUG, "TDLS: Testing - decline response");
2067 status = WLAN_STATUS_REQUEST_DECLINED;
2070 #endif /* CONFIG_TDLS_TESTING */
2072 if (kde.lnkid == NULL || kde.lnkid_len < 3 * ETH_ALEN) {
2073 wpa_printf(MSG_INFO, "TDLS: No valid Link Identifier IE in "
2077 wpa_hexdump(MSG_DEBUG, "TDLS: Link ID Received from TPK M2",
2078 kde.lnkid, kde.lnkid_len);
2079 lnkid = (struct wpa_tdls_lnkid *) kde.lnkid;
2081 if (os_memcmp(sm->bssid, lnkid->bssid, ETH_ALEN) != 0) {
2082 wpa_printf(MSG_INFO, "TDLS: TPK M2 from different BSS");
2083 status = WLAN_STATUS_NOT_IN_SAME_BSS;
2087 if (copy_supp_rates(&kde, peer) < 0)
2090 if (copy_peer_ht_capab(&kde, peer) < 0)
2093 if (copy_peer_vht_capab(&kde, peer) < 0)
2096 if (copy_peer_ext_capab(&kde, peer) < 0)
2099 if (copy_peer_supp_channels(&kde, peer) < 0)
2102 if (copy_peer_supp_oper_classes(&kde, peer) < 0)
2105 peer->qos_info = kde.qosinfo;
2107 /* Overwrite with the qos_info obtained in WMM IE */
2108 if (copy_peer_wmm_capab(&kde, peer) < 0)
2111 peer->aid = kde.aid;
2113 if (!wpa_tdls_get_privacy(sm)) {
2114 peer->rsnie_p_len = 0;
2115 peer->cipher = WPA_CIPHER_NONE;
2119 if (kde.ftie == NULL || kde.ftie_len < sizeof(*ftie) ||
2120 kde.rsn_ie == NULL) {
2121 wpa_printf(MSG_INFO, "TDLS: No FTIE or RSN IE in TPK M2");
2122 status = WLAN_STATUS_INVALID_PARAMETERS;
2125 wpa_hexdump(MSG_DEBUG, "TDLS: RSN IE Received from TPK M2",
2126 kde.rsn_ie, kde.rsn_ie_len);
2128 if (kde.rsn_ie_len > TDLS_MAX_IE_LEN) {
2129 wpa_printf(MSG_INFO,
2130 "TDLS: Too long Responder RSN IE in TPK M2");
2131 status = WLAN_STATUS_INVALID_RSNIE;
2136 * FIX: bitwise comparison of RSN IE is not the correct way of
2137 * validation this. It can be different, but certain fields must
2138 * match. Since we list only a single pairwise cipher in TPK M1, the
2139 * memcmp is likely to work in most cases, though.
2141 if (kde.rsn_ie_len != peer->rsnie_i_len ||
2142 os_memcmp(peer->rsnie_i, kde.rsn_ie, peer->rsnie_i_len) != 0) {
2143 wpa_printf(MSG_INFO, "TDLS: RSN IE in TPK M2 does "
2144 "not match with RSN IE used in TPK M1");
2145 wpa_hexdump(MSG_DEBUG, "TDLS: RSN IE Sent in TPK M1",
2146 peer->rsnie_i, peer->rsnie_i_len);
2147 wpa_hexdump(MSG_DEBUG, "TDLS: RSN IE Received from TPK M2",
2148 kde.rsn_ie, kde.rsn_ie_len);
2149 status = WLAN_STATUS_INVALID_RSNIE;
2153 if (wpa_parse_wpa_ie_rsn(kde.rsn_ie, kde.rsn_ie_len, &ie) < 0) {
2154 wpa_printf(MSG_INFO, "TDLS: Failed to parse RSN IE in TPK M2");
2155 status = WLAN_STATUS_INVALID_RSNIE;
2159 cipher = ie.pairwise_cipher;
2160 if (cipher == WPA_CIPHER_CCMP) {
2161 wpa_printf(MSG_DEBUG, "TDLS: Using CCMP for direct link");
2162 cipher = WPA_CIPHER_CCMP;
2164 wpa_printf(MSG_INFO, "TDLS: No acceptable cipher in TPK M2");
2165 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
2169 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE Received from TPK M2",
2170 kde.ftie, sizeof(*ftie));
2171 ftie = (struct wpa_tdls_ftie *) kde.ftie;
2173 if (!os_memcmp(peer->inonce, ftie->Snonce, WPA_NONCE_LEN) == 0) {
2174 wpa_printf(MSG_INFO, "TDLS: FTIE SNonce in TPK M2 does "
2175 "not match with FTIE SNonce used in TPK M1");
2176 /* Silently discard the frame */
2180 /* Responder Nonce and RSN IE */
2181 os_memcpy(peer->rnonce, ftie->Anonce, WPA_NONCE_LEN);
2182 os_memcpy(peer->rsnie_p, kde.rsn_ie, kde.rsn_ie_len);
2183 peer->rsnie_p_len = kde.rsn_ie_len;
2184 peer->cipher = cipher;
2187 if (kde.key_lifetime == NULL) {
2188 wpa_printf(MSG_INFO, "TDLS: No Key Lifetime IE in TPK M2");
2189 status = WLAN_STATUS_UNACCEPTABLE_LIFETIME;
2192 timeoutie = (struct wpa_tdls_timeoutie *) kde.key_lifetime;
2193 lifetime = WPA_GET_LE32(timeoutie->value);
2194 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime %u seconds in TPK M2",
2196 if (lifetime != peer->lifetime) {
2197 wpa_printf(MSG_INFO, "TDLS: Unexpected TPK lifetime %u in "
2198 "TPK M2 (expected %u)", lifetime, peer->lifetime);
2199 status = WLAN_STATUS_UNACCEPTABLE_LIFETIME;
2203 wpa_tdls_generate_tpk(peer, sm->own_addr, sm->bssid);
2205 /* Process MIC check to see if TPK M2 is right */
2206 if (wpa_supplicant_verify_tdls_mic(2, peer, (u8 *) lnkid,
2207 (u8 *) timeoutie, ftie) < 0) {
2208 /* Discard the frame */
2209 wpa_tdls_del_key(sm, peer);
2210 wpa_tdls_disable_peer_link(sm, peer);
2214 if (wpa_tdls_set_key(sm, peer) < 0) {
2216 * Some drivers may not be able to config the key prior to full
2217 * STA entry having been configured.
2219 wpa_printf(MSG_DEBUG, "TDLS: Try to configure TPK again after "
2220 "STA entry is complete");
2221 peer->reconfig_key = 1;
2225 peer->dtoken = dtoken;
2227 wpa_printf(MSG_DEBUG, "TDLS: Sending TDLS Setup Confirm / "
2228 "TPK Handshake Message 3");
2229 if (wpa_tdls_send_tpk_m3(sm, src_addr, dtoken, lnkid, peer) < 0) {
2230 wpa_tdls_disable_peer_link(sm, peer);
2234 if (!peer->tpk_success) {
2236 * Enable Link only when tpk_success is 0, signifying that this
2237 * processing of TPK M2 frame is not because of a retransmission
2238 * during TDLS setup handshake.
2240 ret = wpa_tdls_enable_link(sm, peer);
2242 wpa_printf(MSG_DEBUG, "TDLS: Could not enable link");
2243 wpa_tdls_do_teardown(
2245 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
2251 wpa_tdls_send_error(sm, src_addr, WLAN_TDLS_SETUP_CONFIRM, dtoken,
2253 wpa_tdls_disable_peer_link(sm, peer);
2258 static int wpa_tdls_process_tpk_m3(struct wpa_sm *sm, const u8 *src_addr,
2259 const u8 *buf, size_t len)
2261 struct wpa_tdls_peer *peer;
2262 struct wpa_eapol_ie_parse kde;
2263 struct wpa_tdls_ftie *ftie;
2264 struct wpa_tdls_timeoutie *timeoutie;
2265 struct wpa_tdls_lnkid *lnkid;
2272 wpa_printf(MSG_DEBUG, "TDLS: Received TDLS Setup Confirm / TPK M3 "
2273 "(Peer " MACSTR ")", MAC2STR(src_addr));
2274 for (peer = sm->tdls; peer; peer = peer->next) {
2275 if (os_memcmp(peer->addr, src_addr, ETH_ALEN) == 0)
2279 wpa_printf(MSG_INFO, "TDLS: No matching peer found for "
2280 "TPK M3: " MACSTR, MAC2STR(src_addr));
2283 wpa_tdls_tpk_retry_timeout_cancel(sm, peer, WLAN_TDLS_SETUP_RESPONSE);
2288 pos += 1 /* pkt_type */ + 1 /* Category */ + 1 /* Action */;
2290 status = WPA_GET_LE16(pos);
2293 wpa_printf(MSG_INFO, "TDLS: Status code in TPK M3: %u",
2297 pos += 2 /* status code */ + 1 /* dialog token */;
2299 ielen = len - (pos - buf); /* start of IE in buf */
2302 * Don't reject the message if failing to parse IEs. The IEs we need are
2303 * explicitly checked below. Some APs piggy-back broken IEs to the end
2304 * of a TDLS Confirm packet, which will fail the link if we don't ignore
2307 if (wpa_supplicant_parse_ies((const u8 *) pos, ielen, &kde) < 0) {
2308 wpa_printf(MSG_DEBUG,
2309 "TDLS: Failed to parse KDEs in TPK M3 - ignore as an interop workaround");
2312 if (kde.lnkid == NULL || kde.lnkid_len < 3 * ETH_ALEN) {
2313 wpa_printf(MSG_INFO, "TDLS: No Link Identifier IE in TPK M3");
2316 wpa_hexdump(MSG_DEBUG, "TDLS: Link ID Received from TPK M3",
2317 (u8 *) kde.lnkid, kde.lnkid_len);
2318 lnkid = (struct wpa_tdls_lnkid *) kde.lnkid;
2320 if (os_memcmp(sm->bssid, lnkid->bssid, ETH_ALEN) != 0) {
2321 wpa_printf(MSG_INFO, "TDLS: TPK M3 from diff BSS");
2325 if (!wpa_tdls_get_privacy(sm))
2328 if (kde.ftie == NULL || kde.ftie_len < sizeof(*ftie)) {
2329 wpa_printf(MSG_INFO, "TDLS: No FTIE in TPK M3");
2332 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE Received from TPK M3",
2333 kde.ftie, sizeof(*ftie));
2334 ftie = (struct wpa_tdls_ftie *) kde.ftie;
2336 if (kde.rsn_ie == NULL) {
2337 wpa_printf(MSG_INFO, "TDLS: No RSN IE in TPK M3");
2340 wpa_hexdump(MSG_DEBUG, "TDLS: RSN IE Received from TPK M3",
2341 kde.rsn_ie, kde.rsn_ie_len);
2342 if (kde.rsn_ie_len != peer->rsnie_p_len ||
2343 os_memcmp(kde.rsn_ie, peer->rsnie_p, peer->rsnie_p_len) != 0) {
2344 wpa_printf(MSG_INFO, "TDLS: RSN IE in TPK M3 does not match "
2345 "with the one sent in TPK M2");
2349 if (!os_memcmp(peer->rnonce, ftie->Anonce, WPA_NONCE_LEN) == 0) {
2350 wpa_printf(MSG_INFO, "TDLS: FTIE ANonce in TPK M3 does "
2351 "not match with FTIE ANonce used in TPK M2");
2355 if (!os_memcmp(peer->inonce, ftie->Snonce, WPA_NONCE_LEN) == 0) {
2356 wpa_printf(MSG_INFO, "TDLS: FTIE SNonce in TPK M3 does not "
2357 "match with FTIE SNonce used in TPK M1");
2361 if (kde.key_lifetime == NULL) {
2362 wpa_printf(MSG_INFO, "TDLS: No Key Lifetime IE in TPK M3");
2365 timeoutie = (struct wpa_tdls_timeoutie *) kde.key_lifetime;
2366 wpa_hexdump(MSG_DEBUG, "TDLS: Timeout IE Received from TPK M3",
2367 (u8 *) timeoutie, sizeof(*timeoutie));
2368 lifetime = WPA_GET_LE32(timeoutie->value);
2369 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime %u seconds in TPK M3",
2371 if (lifetime != peer->lifetime) {
2372 wpa_printf(MSG_INFO, "TDLS: Unexpected TPK lifetime %u in "
2373 "TPK M3 (expected %u)", lifetime, peer->lifetime);
2377 if (wpa_supplicant_verify_tdls_mic(3, peer, (u8 *) lnkid,
2378 (u8 *) timeoutie, ftie) < 0) {
2379 wpa_tdls_del_key(sm, peer);
2383 if (wpa_tdls_set_key(sm, peer) < 0) {
2385 * Some drivers may not be able to config the key prior to full
2386 * STA entry having been configured.
2388 wpa_printf(MSG_DEBUG, "TDLS: Try to configure TPK again after "
2389 "STA entry is complete");
2390 peer->reconfig_key = 1;
2394 if (!peer->tpk_success) {
2396 * Enable Link only when tpk_success is 0, signifying that this
2397 * processing of TPK M3 frame is not because of a retransmission
2398 * during TDLS setup handshake.
2400 ret = wpa_tdls_enable_link(sm, peer);
2402 wpa_printf(MSG_DEBUG, "TDLS: Could not enable link");
2403 wpa_tdls_do_teardown(
2405 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
2410 wpa_tdls_disable_peer_link(sm, peer);
2415 static u8 * wpa_add_tdls_timeoutie(u8 *pos, u8 *ie, size_t ie_len, u32 tsecs)
2417 struct wpa_tdls_timeoutie *lifetime = (struct wpa_tdls_timeoutie *) ie;
2419 os_memset(lifetime, 0, ie_len);
2420 lifetime->ie_type = WLAN_EID_TIMEOUT_INTERVAL;
2421 lifetime->ie_len = sizeof(struct wpa_tdls_timeoutie) - 2;
2422 lifetime->interval_type = WLAN_TIMEOUT_KEY_LIFETIME;
2423 WPA_PUT_LE32(lifetime->value, tsecs);
2424 os_memcpy(pos, ie, ie_len);
2425 return pos + ie_len;
2430 * wpa_tdls_start - Initiate TDLS handshake (send TPK Handshake Message 1)
2431 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2432 * @peer: MAC address of the peer STA
2433 * Returns: 0 on success, or -1 on failure
2435 * Send TPK Handshake Message 1 info to driver to start TDLS
2436 * handshake with the peer.
2438 int wpa_tdls_start(struct wpa_sm *sm, const u8 *addr)
2440 struct wpa_tdls_peer *peer;
2441 int tdls_prohibited = sm->tdls_prohibited;
2443 if (sm->tdls_disabled || !sm->tdls_supported)
2446 #ifdef CONFIG_TDLS_TESTING
2447 if ((tdls_testing & TDLS_TESTING_IGNORE_AP_PROHIBIT) &&
2449 wpa_printf(MSG_DEBUG, "TDLS: Testing - ignore AP prohibition "
2451 tdls_prohibited = 0;
2453 #endif /* CONFIG_TDLS_TESTING */
2455 if (tdls_prohibited) {
2456 wpa_printf(MSG_DEBUG, "TDLS: TDLS is prohibited in this BSS - "
2457 "reject request to start setup");
2461 peer = wpa_tdls_add_peer(sm, addr, NULL);
2465 if (peer->tpk_in_progress) {
2466 wpa_printf(MSG_DEBUG, "TDLS: Setup is already in progress with the peer");
2470 peer->initiator = 1;
2472 /* add the peer to the driver as a "setup in progress" peer */
2473 wpa_sm_tdls_peer_addset(sm, peer->addr, 1, 0, 0, NULL, 0, NULL, NULL, 0,
2474 NULL, 0, NULL, 0, NULL, 0);
2476 peer->tpk_in_progress = 1;
2478 if (wpa_tdls_send_tpk_m1(sm, peer) < 0) {
2479 wpa_tdls_disable_peer_link(sm, peer);
2487 void wpa_tdls_remove(struct wpa_sm *sm, const u8 *addr)
2489 struct wpa_tdls_peer *peer;
2491 if (sm->tdls_disabled || !sm->tdls_supported)
2494 for (peer = sm->tdls; peer; peer = peer->next) {
2495 if (os_memcmp(peer->addr, addr, ETH_ALEN) == 0)
2499 if (peer == NULL || !peer->tpk_success)
2502 if (sm->tdls_external_setup) {
2504 * Disable previous link to allow renegotiation to be completed
2507 wpa_tdls_do_teardown(sm, peer,
2508 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
2514 * wpa_supplicant_rx_tdls - Receive TDLS data frame
2516 * This function is called to receive TDLS (ethertype = 0x890d) data frames.
2518 static void wpa_supplicant_rx_tdls(void *ctx, const u8 *src_addr,
2519 const u8 *buf, size_t len)
2521 struct wpa_sm *sm = ctx;
2522 struct wpa_tdls_frame *tf;
2524 wpa_hexdump(MSG_DEBUG, "TDLS: Received Data frame encapsulation",
2527 if (sm->tdls_disabled || !sm->tdls_supported) {
2528 wpa_printf(MSG_DEBUG, "TDLS: Discard message - TDLS disabled "
2529 "or unsupported by driver");
2533 if (os_memcmp(src_addr, sm->own_addr, ETH_ALEN) == 0) {
2534 wpa_printf(MSG_DEBUG, "TDLS: Discard copy of own message");
2538 if (len < sizeof(*tf)) {
2539 wpa_printf(MSG_INFO, "TDLS: Drop too short frame");
2543 /* Check to make sure its a valid encapsulated TDLS frame */
2544 tf = (struct wpa_tdls_frame *) buf;
2545 if (tf->payloadtype != 2 /* TDLS_RFTYPE */ ||
2546 tf->category != WLAN_ACTION_TDLS) {
2547 wpa_printf(MSG_INFO, "TDLS: Invalid frame - payloadtype=%u "
2548 "category=%u action=%u",
2549 tf->payloadtype, tf->category, tf->action);
2553 switch (tf->action) {
2554 case WLAN_TDLS_SETUP_REQUEST:
2555 wpa_tdls_process_tpk_m1(sm, src_addr, buf, len);
2557 case WLAN_TDLS_SETUP_RESPONSE:
2558 wpa_tdls_process_tpk_m2(sm, src_addr, buf, len);
2560 case WLAN_TDLS_SETUP_CONFIRM:
2561 wpa_tdls_process_tpk_m3(sm, src_addr, buf, len);
2563 case WLAN_TDLS_TEARDOWN:
2564 wpa_tdls_recv_teardown(sm, src_addr, buf, len);
2566 case WLAN_TDLS_DISCOVERY_REQUEST:
2567 wpa_tdls_process_discovery_request(sm, src_addr, buf, len);
2570 /* Kernel code will process remaining frames */
2571 wpa_printf(MSG_DEBUG, "TDLS: Ignore TDLS frame action code %u",
2579 * wpa_tdls_init - Initialize driver interface parameters for TDLS
2580 * @wpa_s: Pointer to wpa_supplicant data
2581 * Returns: 0 on success, -1 on failure
2583 * This function is called to initialize driver interface parameters for TDLS.
2584 * wpa_drv_init() must have been called before this function to initialize the
2587 int wpa_tdls_init(struct wpa_sm *sm)
2592 sm->l2_tdls = l2_packet_init(sm->bridge_ifname ? sm->bridge_ifname :
2595 ETH_P_80211_ENCAP, wpa_supplicant_rx_tdls,
2597 if (sm->l2_tdls == NULL) {
2598 wpa_printf(MSG_ERROR, "TDLS: Failed to open l2_packet "
2604 * Drivers that support TDLS but don't implement the get_capa callback
2605 * are assumed to perform everything internally
2607 if (wpa_sm_tdls_get_capa(sm, &sm->tdls_supported,
2608 &sm->tdls_external_setup) < 0) {
2609 sm->tdls_supported = 1;
2610 sm->tdls_external_setup = 0;
2613 wpa_printf(MSG_DEBUG, "TDLS: TDLS operation%s supported by "
2614 "driver", sm->tdls_supported ? "" : " not");
2615 wpa_printf(MSG_DEBUG, "TDLS: Driver uses %s link setup",
2616 sm->tdls_external_setup ? "external" : "internal");
2622 void wpa_tdls_teardown_peers(struct wpa_sm *sm)
2624 struct wpa_tdls_peer *peer;
2628 wpa_printf(MSG_DEBUG, "TDLS: Tear down peers");
2631 wpa_printf(MSG_DEBUG, "TDLS: Tear down peer " MACSTR,
2632 MAC2STR(peer->addr));
2633 if (sm->tdls_external_setup)
2634 wpa_tdls_do_teardown(sm, peer,
2635 WLAN_REASON_DEAUTH_LEAVING);
2637 wpa_sm_tdls_oper(sm, TDLS_TEARDOWN, peer->addr);
2644 static void wpa_tdls_remove_peers(struct wpa_sm *sm)
2646 struct wpa_tdls_peer *peer, *tmp;
2654 res = wpa_sm_tdls_oper(sm, TDLS_DISABLE_LINK, peer->addr);
2655 wpa_printf(MSG_DEBUG, "TDLS: Remove peer " MACSTR " (res=%d)",
2656 MAC2STR(peer->addr), res);
2657 wpa_tdls_peer_free(sm, peer);
2665 * wpa_tdls_deinit - Deinitialize driver interface parameters for TDLS
2667 * This function is called to recover driver interface parameters for TDLS
2668 * and frees resources allocated for it.
2670 void wpa_tdls_deinit(struct wpa_sm *sm)
2676 l2_packet_deinit(sm->l2_tdls);
2679 wpa_tdls_remove_peers(sm);
2683 void wpa_tdls_assoc(struct wpa_sm *sm)
2685 wpa_printf(MSG_DEBUG, "TDLS: Remove peers on association");
2686 wpa_tdls_remove_peers(sm);
2690 void wpa_tdls_disassoc(struct wpa_sm *sm)
2692 wpa_printf(MSG_DEBUG, "TDLS: Remove peers on disassociation");
2693 wpa_tdls_remove_peers(sm);
2697 static int wpa_tdls_prohibited(const u8 *ies, size_t len)
2699 struct wpa_eapol_ie_parse elems;
2704 if (wpa_supplicant_parse_ies(ies, len, &elems) < 0)
2707 if (elems.ext_capab == NULL || elems.ext_capab_len < 2 + 5)
2710 /* bit 38 - TDLS Prohibited */
2711 return !!(elems.ext_capab[2 + 4] & 0x40);
2715 void wpa_tdls_ap_ies(struct wpa_sm *sm, const u8 *ies, size_t len)
2717 sm->tdls_prohibited = wpa_tdls_prohibited(ies, len);
2718 wpa_printf(MSG_DEBUG, "TDLS: TDLS is %s in the target BSS",
2719 sm->tdls_prohibited ? "prohibited" : "allowed");
2723 void wpa_tdls_assoc_resp_ies(struct wpa_sm *sm, const u8 *ies, size_t len)
2725 if (!sm->tdls_prohibited && wpa_tdls_prohibited(ies, len)) {
2726 wpa_printf(MSG_DEBUG, "TDLS: TDLS prohibited based on "
2727 "(Re)Association Response IEs");
2728 sm->tdls_prohibited = 1;
2733 void wpa_tdls_enable(struct wpa_sm *sm, int enabled)
2735 wpa_printf(MSG_DEBUG, "TDLS: %s", enabled ? "enabled" : "disabled");
2736 sm->tdls_disabled = !enabled;
2740 int wpa_tdls_is_external_setup(struct wpa_sm *sm)
2742 return sm->tdls_external_setup;