blob: 335e1d9040a20b2d0dd4c2ce33fdb10d77d60367 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * wpa_supplicant - TDLS
3 * Copyright (c) 2010-2011, Atheros Communications
4 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "utils/eloop.h"
13#include "utils/os.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"
23
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)
36unsigned int tdls_testing = 0;
37#endif /* CONFIG_TDLS_TESTING */
38
39#define TPK_LIFETIME 43200 /* 12 hours */
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -070040#define TPK_M1_RETRY_COUNT 3
41#define TPK_M1_TIMEOUT 5000 /* in milliseconds */
42#define TPK_M2_RETRY_COUNT 10
43#define TPK_M2_TIMEOUT 500 /* in milliseconds */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044
45#define TDLS_MIC_LEN 16
46
47#define TDLS_TIMEOUT_LEN 4
48
49struct wpa_tdls_ftie {
50 u8 ie_type; /* FTIE */
51 u8 ie_len;
52 u8 mic_ctrl[2];
53 u8 mic[TDLS_MIC_LEN];
54 u8 Anonce[WPA_NONCE_LEN]; /* Responder Nonce in TDLS */
55 u8 Snonce[WPA_NONCE_LEN]; /* Initiator Nonce in TDLS */
56 /* followed by optional elements */
57} STRUCT_PACKED;
58
59struct wpa_tdls_timeoutie {
60 u8 ie_type; /* Timeout IE */
61 u8 ie_len;
62 u8 interval_type;
63 u8 value[TDLS_TIMEOUT_LEN];
64} STRUCT_PACKED;
65
66struct wpa_tdls_lnkid {
67 u8 ie_type; /* Link Identifier IE */
68 u8 ie_len;
69 u8 bssid[ETH_ALEN];
70 u8 init_sta[ETH_ALEN];
71 u8 resp_sta[ETH_ALEN];
72} STRUCT_PACKED;
73
74/* TDLS frame headers as per IEEE Std 802.11z-2010 */
75struct wpa_tdls_frame {
76 u8 payloadtype; /* IEEE80211_TDLS_RFTYPE */
77 u8 category; /* Category */
78 u8 action; /* Action (enum tdls_frame_type) */
79} STRUCT_PACKED;
80
81static u8 * wpa_add_tdls_timeoutie(u8 *pos, u8 *ie, size_t ie_len, u32 tsecs);
82static void wpa_tdls_tpk_retry_timeout(void *eloop_ctx, void *timeout_ctx);
83static void wpa_tdls_peer_free(struct wpa_sm *sm, struct wpa_tdls_peer *peer);
84
85
86#define TDLS_MAX_IE_LEN 80
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080087#define IEEE80211_MAX_SUPP_RATES 32
88
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089struct wpa_tdls_peer {
90 struct wpa_tdls_peer *next;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070091 unsigned int reconfig_key:1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070092 int initiator; /* whether this end was initiator for TDLS setup */
93 u8 addr[ETH_ALEN]; /* other end MAC address */
94 u8 inonce[WPA_NONCE_LEN]; /* Initiator Nonce */
95 u8 rnonce[WPA_NONCE_LEN]; /* Responder Nonce */
96 u8 rsnie_i[TDLS_MAX_IE_LEN]; /* Initiator RSN IE */
97 size_t rsnie_i_len;
98 u8 rsnie_p[TDLS_MAX_IE_LEN]; /* Peer RSN IE */
99 size_t rsnie_p_len;
100 u32 lifetime;
101 int cipher; /* Selected cipher (WPA_CIPHER_*) */
102 u8 dtoken;
103
104 struct tpk {
105 u8 kck[16]; /* TPK-KCK */
106 u8 tk[16]; /* TPK-TK; assuming only CCMP will be used */
107 } tpk;
108 int tpk_set;
109 int tpk_success;
110
111 struct tpk_timer {
112 u8 dest[ETH_ALEN];
113 int count; /* Retry Count */
114 int timer; /* Timeout in milliseconds */
115 u8 action_code; /* TDLS frame type */
116 u8 dialog_token;
117 u16 status_code;
118 int buf_len; /* length of TPK message for retransmission */
119 u8 *buf; /* buffer for TPK message */
120 } sm_tmr;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800121
122 u16 capability;
123
124 u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
125 size_t supp_rates_len;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800126
127 struct ieee80211_ht_capabilities *ht_capabilities;
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -0800128 struct ieee80211_vht_capabilities *vht_capabilities;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800129
130 u8 qos_info;
131
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700132 u16 aid;
133
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800134 u8 *ext_capab;
135 size_t ext_capab_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700136};
137
138
139static int wpa_tdls_get_privacy(struct wpa_sm *sm)
140{
141 /*
142 * Get info needed from supplicant to check if the current BSS supports
143 * security. Other than OPEN mode, rest are considered secured
144 * WEP/WPA/WPA2 hence TDLS frames are processed for TPK handshake.
145 */
146 return sm->pairwise_cipher != WPA_CIPHER_NONE;
147}
148
149
150static u8 * wpa_add_ie(u8 *pos, const u8 *ie, size_t ie_len)
151{
152 os_memcpy(pos, ie, ie_len);
153 return pos + ie_len;
154}
155
156
157static int wpa_tdls_del_key(struct wpa_sm *sm, struct wpa_tdls_peer *peer)
158{
159 if (wpa_sm_set_key(sm, WPA_ALG_NONE, peer->addr,
160 0, 0, NULL, 0, NULL, 0) < 0) {
161 wpa_printf(MSG_WARNING, "TDLS: Failed to delete TPK-TK from "
162 "the driver");
163 return -1;
164 }
165
166 return 0;
167}
168
169
170static int wpa_tdls_set_key(struct wpa_sm *sm, struct wpa_tdls_peer *peer)
171{
172 u8 key_len;
173 u8 rsc[6];
174 enum wpa_alg alg;
175
176 os_memset(rsc, 0, 6);
177
178 switch (peer->cipher) {
179 case WPA_CIPHER_CCMP:
180 alg = WPA_ALG_CCMP;
181 key_len = 16;
182 break;
183 case WPA_CIPHER_NONE:
184 wpa_printf(MSG_DEBUG, "TDLS: Pairwise Cipher Suite: "
185 "NONE - do not use pairwise keys");
186 return -1;
187 default:
188 wpa_printf(MSG_WARNING, "TDLS: Unsupported pairwise cipher %d",
189 sm->pairwise_cipher);
190 return -1;
191 }
192
193 if (wpa_sm_set_key(sm, alg, peer->addr, -1, 1,
194 rsc, sizeof(rsc), peer->tpk.tk, key_len) < 0) {
195 wpa_printf(MSG_WARNING, "TDLS: Failed to set TPK to the "
196 "driver");
197 return -1;
198 }
199 return 0;
200}
201
202
203static int wpa_tdls_send_tpk_msg(struct wpa_sm *sm, const u8 *dst,
204 u8 action_code, u8 dialog_token,
205 u16 status_code, const u8 *buf, size_t len)
206{
207 return wpa_sm_send_tdls_mgmt(sm, dst, action_code, dialog_token,
208 status_code, buf, len);
209}
210
211
212static int wpa_tdls_tpk_send(struct wpa_sm *sm, const u8 *dest, u8 action_code,
213 u8 dialog_token, u16 status_code,
214 const u8 *msg, size_t msg_len)
215{
216 struct wpa_tdls_peer *peer;
217
218 wpa_printf(MSG_DEBUG, "TDLS: TPK send dest=" MACSTR " action_code=%u "
219 "dialog_token=%u status_code=%u msg_len=%u",
220 MAC2STR(dest), action_code, dialog_token, status_code,
221 (unsigned int) msg_len);
222
223 if (wpa_tdls_send_tpk_msg(sm, dest, action_code, dialog_token,
224 status_code, msg, msg_len)) {
225 wpa_printf(MSG_INFO, "TDLS: Failed to send message "
226 "(action_code=%u)", action_code);
227 return -1;
228 }
229
230 if (action_code == WLAN_TDLS_SETUP_CONFIRM ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800231 action_code == WLAN_TDLS_TEARDOWN ||
232 action_code == WLAN_TDLS_DISCOVERY_REQUEST ||
233 action_code == WLAN_TDLS_DISCOVERY_RESPONSE)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700234 return 0; /* No retries */
235
236 for (peer = sm->tdls; peer; peer = peer->next) {
237 if (os_memcmp(peer->addr, dest, ETH_ALEN) == 0)
238 break;
239 }
240
241 if (peer == NULL) {
242 wpa_printf(MSG_INFO, "TDLS: No matching entry found for "
243 "retry " MACSTR, MAC2STR(dest));
244 return 0;
245 }
246
247 eloop_cancel_timeout(wpa_tdls_tpk_retry_timeout, sm, peer);
248
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -0700249 if (action_code == WLAN_TDLS_SETUP_RESPONSE) {
250 peer->sm_tmr.count = TPK_M2_RETRY_COUNT;
251 peer->sm_tmr.timer = TPK_M2_TIMEOUT;
252 } else {
253 peer->sm_tmr.count = TPK_M1_RETRY_COUNT;
254 peer->sm_tmr.timer = TPK_M1_TIMEOUT;
255 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700256
257 /* Copy message to resend on timeout */
258 os_memcpy(peer->sm_tmr.dest, dest, ETH_ALEN);
259 peer->sm_tmr.action_code = action_code;
260 peer->sm_tmr.dialog_token = dialog_token;
261 peer->sm_tmr.status_code = status_code;
262 peer->sm_tmr.buf_len = msg_len;
263 os_free(peer->sm_tmr.buf);
264 peer->sm_tmr.buf = os_malloc(msg_len);
265 if (peer->sm_tmr.buf == NULL)
266 return -1;
267 os_memcpy(peer->sm_tmr.buf, msg, msg_len);
268
269 wpa_printf(MSG_DEBUG, "TDLS: Retry timeout registered "
270 "(action_code=%u)", action_code);
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -0700271 eloop_register_timeout(peer->sm_tmr.timer / 1000,
272 (peer->sm_tmr.timer % 1000) * 1000,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700273 wpa_tdls_tpk_retry_timeout, sm, peer);
274 return 0;
275}
276
277
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800278static int wpa_tdls_do_teardown(struct wpa_sm *sm, struct wpa_tdls_peer *peer,
279 u16 reason_code, int free_peer)
280{
281 int ret;
282
283 if (sm->tdls_external_setup) {
284 ret = wpa_tdls_send_teardown(sm, peer->addr, reason_code);
285
286 /* disable the link after teardown was sent */
287 wpa_sm_tdls_oper(sm, TDLS_DISABLE_LINK, peer->addr);
288 } else {
289 ret = wpa_sm_tdls_oper(sm, TDLS_TEARDOWN, peer->addr);
290 }
291
292 if (sm->tdls_external_setup || free_peer)
293 wpa_tdls_peer_free(sm, peer);
294
295 return ret;
296}
297
298
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299static void wpa_tdls_tpk_retry_timeout(void *eloop_ctx, void *timeout_ctx)
300{
301
302 struct wpa_sm *sm = eloop_ctx;
303 struct wpa_tdls_peer *peer = timeout_ctx;
304
305 if (peer->sm_tmr.count) {
306 peer->sm_tmr.count--;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307
308 wpa_printf(MSG_INFO, "TDLS: Retrying sending of message "
309 "(action_code=%u)",
310 peer->sm_tmr.action_code);
311
312 if (peer->sm_tmr.buf == NULL) {
313 wpa_printf(MSG_INFO, "TDLS: No retry buffer available "
314 "for action_code=%u",
315 peer->sm_tmr.action_code);
316 eloop_cancel_timeout(wpa_tdls_tpk_retry_timeout, sm,
317 peer);
318 return;
319 }
320
321 /* resend TPK Handshake Message to Peer */
322 if (wpa_tdls_send_tpk_msg(sm, peer->sm_tmr.dest,
323 peer->sm_tmr.action_code,
324 peer->sm_tmr.dialog_token,
325 peer->sm_tmr.status_code,
326 peer->sm_tmr.buf,
327 peer->sm_tmr.buf_len)) {
328 wpa_printf(MSG_INFO, "TDLS: Failed to retry "
329 "transmission");
330 }
331
332 eloop_cancel_timeout(wpa_tdls_tpk_retry_timeout, sm, peer);
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -0700333 eloop_register_timeout(peer->sm_tmr.timer / 1000,
334 (peer->sm_tmr.timer % 1000) * 1000,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700335 wpa_tdls_tpk_retry_timeout, sm, peer);
336 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700337 eloop_cancel_timeout(wpa_tdls_tpk_retry_timeout, sm, peer);
338
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800339 wpa_printf(MSG_DEBUG, "TDLS: Sending Teardown Request");
340 wpa_tdls_do_teardown(sm, peer,
341 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342 }
343}
344
345
346static void wpa_tdls_tpk_retry_timeout_cancel(struct wpa_sm *sm,
347 struct wpa_tdls_peer *peer,
348 u8 action_code)
349{
350 if (action_code == peer->sm_tmr.action_code) {
351 wpa_printf(MSG_DEBUG, "TDLS: Retry timeout cancelled for "
352 "action_code=%u", action_code);
353
354 /* Cancel Timeout registered */
355 eloop_cancel_timeout(wpa_tdls_tpk_retry_timeout, sm, peer);
356
357 /* free all resources meant for retry */
358 os_free(peer->sm_tmr.buf);
359 peer->sm_tmr.buf = NULL;
360
361 peer->sm_tmr.count = 0;
362 peer->sm_tmr.timer = 0;
363 peer->sm_tmr.buf_len = 0;
364 peer->sm_tmr.action_code = 0xff;
365 } else {
366 wpa_printf(MSG_INFO, "TDLS: Error in cancelling retry timeout "
367 "(Unknown action_code=%u)", action_code);
368 }
369}
370
371
372static void wpa_tdls_generate_tpk(struct wpa_tdls_peer *peer,
373 const u8 *own_addr, const u8 *bssid)
374{
375 u8 key_input[SHA256_MAC_LEN];
376 const u8 *nonce[2];
377 size_t len[2];
378 u8 data[3 * ETH_ALEN];
379
380 /* IEEE Std 802.11z-2010 8.5.9.1:
381 * TPK-Key-Input = SHA-256(min(SNonce, ANonce) || max(SNonce, ANonce))
382 */
383 len[0] = WPA_NONCE_LEN;
384 len[1] = WPA_NONCE_LEN;
385 if (os_memcmp(peer->inonce, peer->rnonce, WPA_NONCE_LEN) < 0) {
386 nonce[0] = peer->inonce;
387 nonce[1] = peer->rnonce;
388 } else {
389 nonce[0] = peer->rnonce;
390 nonce[1] = peer->inonce;
391 }
392 wpa_hexdump(MSG_DEBUG, "TDLS: min(Nonce)", nonce[0], WPA_NONCE_LEN);
393 wpa_hexdump(MSG_DEBUG, "TDLS: max(Nonce)", nonce[1], WPA_NONCE_LEN);
394 sha256_vector(2, nonce, len, key_input);
395 wpa_hexdump_key(MSG_DEBUG, "TDLS: TPK-Key-Input",
396 key_input, SHA256_MAC_LEN);
397
398 /*
399 * TPK-Key-Data = KDF-N_KEY(TPK-Key-Input, "TDLS PMK",
400 * min(MAC_I, MAC_R) || max(MAC_I, MAC_R) || BSSID || N_KEY)
401 * TODO: is N_KEY really included in KDF Context and if so, in which
402 * presentation format (little endian 16-bit?) is it used? It gets
403 * added by the KDF anyway..
404 */
405
406 if (os_memcmp(own_addr, peer->addr, ETH_ALEN) < 0) {
407 os_memcpy(data, own_addr, ETH_ALEN);
408 os_memcpy(data + ETH_ALEN, peer->addr, ETH_ALEN);
409 } else {
410 os_memcpy(data, peer->addr, ETH_ALEN);
411 os_memcpy(data + ETH_ALEN, own_addr, ETH_ALEN);
412 }
413 os_memcpy(data + 2 * ETH_ALEN, bssid, ETH_ALEN);
414 wpa_hexdump(MSG_DEBUG, "TDLS: KDF Context", data, sizeof(data));
415
416 sha256_prf(key_input, SHA256_MAC_LEN, "TDLS PMK", data, sizeof(data),
417 (u8 *) &peer->tpk, sizeof(peer->tpk));
418 wpa_hexdump_key(MSG_DEBUG, "TDLS: TPK-KCK",
419 peer->tpk.kck, sizeof(peer->tpk.kck));
420 wpa_hexdump_key(MSG_DEBUG, "TDLS: TPK-TK",
421 peer->tpk.tk, sizeof(peer->tpk.tk));
422 peer->tpk_set = 1;
423}
424
425
426/**
427 * wpa_tdls_ftie_mic - Calculate TDLS FTIE MIC
428 * @kck: TPK-KCK
429 * @lnkid: Pointer to the beginning of Link Identifier IE
430 * @rsnie: Pointer to the beginning of RSN IE used for handshake
431 * @timeoutie: Pointer to the beginning of Timeout IE used for handshake
432 * @ftie: Pointer to the beginning of FT IE
433 * @mic: Pointer for writing MIC
434 *
435 * Calculate MIC for TDLS frame.
436 */
437static int wpa_tdls_ftie_mic(const u8 *kck, u8 trans_seq, const u8 *lnkid,
438 const u8 *rsnie, const u8 *timeoutie,
439 const u8 *ftie, u8 *mic)
440{
441 u8 *buf, *pos;
442 struct wpa_tdls_ftie *_ftie;
443 const struct wpa_tdls_lnkid *_lnkid;
444 int ret;
445 int len = 2 * ETH_ALEN + 1 + 2 + lnkid[1] + 2 + rsnie[1] +
446 2 + timeoutie[1] + 2 + ftie[1];
447 buf = os_zalloc(len);
448 if (!buf) {
449 wpa_printf(MSG_WARNING, "TDLS: No memory for MIC calculation");
450 return -1;
451 }
452
453 pos = buf;
454 _lnkid = (const struct wpa_tdls_lnkid *) lnkid;
455 /* 1) TDLS initiator STA MAC address */
456 os_memcpy(pos, _lnkid->init_sta, ETH_ALEN);
457 pos += ETH_ALEN;
458 /* 2) TDLS responder STA MAC address */
459 os_memcpy(pos, _lnkid->resp_sta, ETH_ALEN);
460 pos += ETH_ALEN;
461 /* 3) Transaction Sequence number */
462 *pos++ = trans_seq;
463 /* 4) Link Identifier IE */
464 os_memcpy(pos, lnkid, 2 + lnkid[1]);
465 pos += 2 + lnkid[1];
466 /* 5) RSN IE */
467 os_memcpy(pos, rsnie, 2 + rsnie[1]);
468 pos += 2 + rsnie[1];
469 /* 6) Timeout Interval IE */
470 os_memcpy(pos, timeoutie, 2 + timeoutie[1]);
471 pos += 2 + timeoutie[1];
472 /* 7) FTIE, with the MIC field of the FTIE set to 0 */
473 os_memcpy(pos, ftie, 2 + ftie[1]);
474 _ftie = (struct wpa_tdls_ftie *) pos;
475 os_memset(_ftie->mic, 0, TDLS_MIC_LEN);
476 pos += 2 + ftie[1];
477
478 wpa_hexdump(MSG_DEBUG, "TDLS: Data for FTIE MIC", buf, pos - buf);
479 wpa_hexdump_key(MSG_DEBUG, "TDLS: KCK", kck, 16);
480 ret = omac1_aes_128(kck, buf, pos - buf, mic);
481 os_free(buf);
482 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE MIC", mic, 16);
483 return ret;
484}
485
486
487/**
488 * wpa_tdls_key_mic_teardown - Calculate TDLS FTIE MIC for Teardown frame
489 * @kck: TPK-KCK
490 * @trans_seq: Transaction Sequence Number (4 - Teardown)
491 * @rcode: Reason code for Teardown
492 * @dtoken: Dialog Token used for that particular link
493 * @lnkid: Pointer to the beginning of Link Identifier IE
494 * @ftie: Pointer to the beginning of FT IE
495 * @mic: Pointer for writing MIC
496 *
497 * Calculate MIC for TDLS frame.
498 */
499static int wpa_tdls_key_mic_teardown(const u8 *kck, u8 trans_seq, u16 rcode,
500 u8 dtoken, const u8 *lnkid,
501 const u8 *ftie, u8 *mic)
502{
503 u8 *buf, *pos;
504 struct wpa_tdls_ftie *_ftie;
505 int ret;
506 int len;
507
508 if (lnkid == NULL)
509 return -1;
510
511 len = 2 + lnkid[1] + sizeof(rcode) + sizeof(dtoken) +
512 sizeof(trans_seq) + 2 + ftie[1];
513
514 buf = os_zalloc(len);
515 if (!buf) {
516 wpa_printf(MSG_WARNING, "TDLS: No memory for MIC calculation");
517 return -1;
518 }
519
520 pos = buf;
521 /* 1) Link Identifier IE */
522 os_memcpy(pos, lnkid, 2 + lnkid[1]);
523 pos += 2 + lnkid[1];
524 /* 2) Reason Code */
525 WPA_PUT_LE16(pos, rcode);
526 pos += sizeof(rcode);
527 /* 3) Dialog token */
528 *pos++ = dtoken;
529 /* 4) Transaction Sequence number */
530 *pos++ = trans_seq;
531 /* 7) FTIE, with the MIC field of the FTIE set to 0 */
532 os_memcpy(pos, ftie, 2 + ftie[1]);
533 _ftie = (struct wpa_tdls_ftie *) pos;
534 os_memset(_ftie->mic, 0, TDLS_MIC_LEN);
535 pos += 2 + ftie[1];
536
537 wpa_hexdump(MSG_DEBUG, "TDLS: Data for FTIE MIC", buf, pos - buf);
538 wpa_hexdump_key(MSG_DEBUG, "TDLS: KCK", kck, 16);
539 ret = omac1_aes_128(kck, buf, pos - buf, mic);
540 os_free(buf);
541 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE MIC", mic, 16);
542 return ret;
543}
544
545
546static int wpa_supplicant_verify_tdls_mic(u8 trans_seq,
547 struct wpa_tdls_peer *peer,
548 const u8 *lnkid, const u8 *timeoutie,
549 const struct wpa_tdls_ftie *ftie)
550{
551 u8 mic[16];
552
553 if (peer->tpk_set) {
554 wpa_tdls_ftie_mic(peer->tpk.kck, trans_seq, lnkid,
555 peer->rsnie_p, timeoutie, (u8 *) ftie,
556 mic);
557 if (os_memcmp(mic, ftie->mic, 16) != 0) {
558 wpa_printf(MSG_INFO, "TDLS: Invalid MIC in FTIE - "
559 "dropping packet");
560 wpa_hexdump(MSG_DEBUG, "TDLS: Received MIC",
561 ftie->mic, 16);
562 wpa_hexdump(MSG_DEBUG, "TDLS: Calculated MIC",
563 mic, 16);
564 return -1;
565 }
566 } else {
567 wpa_printf(MSG_WARNING, "TDLS: Could not verify TDLS MIC, "
568 "TPK not set - dropping packet");
569 return -1;
570 }
571 return 0;
572}
573
574
575static int wpa_supplicant_verify_tdls_mic_teardown(
576 u8 trans_seq, u16 rcode, u8 dtoken, struct wpa_tdls_peer *peer,
577 const u8 *lnkid, const struct wpa_tdls_ftie *ftie)
578{
579 u8 mic[16];
580
581 if (peer->tpk_set) {
582 wpa_tdls_key_mic_teardown(peer->tpk.kck, trans_seq, rcode,
583 dtoken, lnkid, (u8 *) ftie, mic);
584 if (os_memcmp(mic, ftie->mic, 16) != 0) {
585 wpa_printf(MSG_INFO, "TDLS: Invalid MIC in Teardown - "
586 "dropping packet");
587 return -1;
588 }
589 } else {
590 wpa_printf(MSG_INFO, "TDLS: Could not verify TDLS Teardown "
591 "MIC, TPK not set - dropping packet");
592 return -1;
593 }
594 return 0;
595}
596
597
598static void wpa_tdls_tpk_timeout(void *eloop_ctx, void *timeout_ctx)
599{
600 struct wpa_sm *sm = eloop_ctx;
601 struct wpa_tdls_peer *peer = timeout_ctx;
602
603 /*
604 * On TPK lifetime expiration, we have an option of either tearing down
605 * the direct link or trying to re-initiate it. The selection of what
606 * to do is not strictly speaking controlled by our role in the expired
607 * link, but for now, use that to select whether to renew or tear down
608 * the link.
609 */
610
611 if (peer->initiator) {
612 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime expired for " MACSTR
613 " - try to renew", MAC2STR(peer->addr));
614 wpa_tdls_start(sm, peer->addr);
615 } else {
616 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime expired for " MACSTR
617 " - tear down", MAC2STR(peer->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800618 wpa_tdls_do_teardown(sm, peer,
619 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700620 }
621}
622
623
624static void wpa_tdls_peer_free(struct wpa_sm *sm, struct wpa_tdls_peer *peer)
625{
626 wpa_printf(MSG_DEBUG, "TDLS: Clear state for peer " MACSTR,
627 MAC2STR(peer->addr));
628 eloop_cancel_timeout(wpa_tdls_tpk_timeout, sm, peer);
629 eloop_cancel_timeout(wpa_tdls_tpk_retry_timeout, sm, peer);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700630 peer->reconfig_key = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700631 peer->initiator = 0;
632 os_free(peer->sm_tmr.buf);
633 peer->sm_tmr.buf = NULL;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800634 os_free(peer->ht_capabilities);
635 peer->ht_capabilities = NULL;
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -0800636 os_free(peer->vht_capabilities);
637 peer->vht_capabilities = NULL;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800638 os_free(peer->ext_capab);
639 peer->ext_capab = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700640 peer->rsnie_i_len = peer->rsnie_p_len = 0;
641 peer->cipher = 0;
642 peer->tpk_set = peer->tpk_success = 0;
643 os_memset(&peer->tpk, 0, sizeof(peer->tpk));
644 os_memset(peer->inonce, 0, WPA_NONCE_LEN);
645 os_memset(peer->rnonce, 0, WPA_NONCE_LEN);
646}
647
648
649static void wpa_tdls_linkid(struct wpa_sm *sm, struct wpa_tdls_peer *peer,
650 struct wpa_tdls_lnkid *lnkid)
651{
652 lnkid->ie_type = WLAN_EID_LINK_ID;
653 lnkid->ie_len = 3 * ETH_ALEN;
654 os_memcpy(lnkid->bssid, sm->bssid, ETH_ALEN);
655 if (peer->initiator) {
656 os_memcpy(lnkid->init_sta, sm->own_addr, ETH_ALEN);
657 os_memcpy(lnkid->resp_sta, peer->addr, ETH_ALEN);
658 } else {
659 os_memcpy(lnkid->init_sta, peer->addr, ETH_ALEN);
660 os_memcpy(lnkid->resp_sta, sm->own_addr, ETH_ALEN);
661 }
662}
663
664
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800665int wpa_tdls_send_teardown(struct wpa_sm *sm, const u8 *addr, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700666{
667 struct wpa_tdls_peer *peer;
668 struct wpa_tdls_ftie *ftie;
669 struct wpa_tdls_lnkid lnkid;
670 u8 dialog_token;
671 u8 *rbuf, *pos;
672 int ielen;
673
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800674 if (sm->tdls_disabled || !sm->tdls_supported)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700675 return -1;
676
677 /* Find the node and free from the list */
678 for (peer = sm->tdls; peer; peer = peer->next) {
679 if (os_memcmp(peer->addr, addr, ETH_ALEN) == 0)
680 break;
681 }
682
683 if (peer == NULL) {
684 wpa_printf(MSG_INFO, "TDLS: No matching entry found for "
685 "Teardown " MACSTR, MAC2STR(addr));
686 return 0;
687 }
688
689 dialog_token = peer->dtoken;
690
691 wpa_printf(MSG_DEBUG, "TDLS: TDLS Teardown for " MACSTR,
692 MAC2STR(addr));
693
694 ielen = 0;
695 if (wpa_tdls_get_privacy(sm) && peer->tpk_set && peer->tpk_success) {
696 /* To add FTIE for Teardown request and compute MIC */
697 ielen += sizeof(*ftie);
698#ifdef CONFIG_TDLS_TESTING
699 if (tdls_testing & TDLS_TESTING_LONG_FRAME)
700 ielen += 170;
701#endif /* CONFIG_TDLS_TESTING */
702 }
703
704 rbuf = os_zalloc(ielen + 1);
705 if (rbuf == NULL)
706 return -1;
707 pos = rbuf;
708
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700709 if (!wpa_tdls_get_privacy(sm) || !peer->tpk_set || !peer->tpk_success)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700710 goto skip_ies;
711
712 ftie = (struct wpa_tdls_ftie *) pos;
713 ftie->ie_type = WLAN_EID_FAST_BSS_TRANSITION;
714 /* Using the recent nonce which should be for CONFIRM frame */
715 os_memcpy(ftie->Anonce, peer->rnonce, WPA_NONCE_LEN);
716 os_memcpy(ftie->Snonce, peer->inonce, WPA_NONCE_LEN);
717 ftie->ie_len = sizeof(struct wpa_tdls_ftie) - 2;
718 pos = (u8 *) (ftie + 1);
719#ifdef CONFIG_TDLS_TESTING
720 if (tdls_testing & TDLS_TESTING_LONG_FRAME) {
721 wpa_printf(MSG_DEBUG, "TDLS: Testing - add extra subelem to "
722 "FTIE");
723 ftie->ie_len += 170;
724 *pos++ = 255; /* FTIE subelem */
725 *pos++ = 168; /* FTIE subelem length */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800726 pos += 168;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700727 }
728#endif /* CONFIG_TDLS_TESTING */
729 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE for TDLS Teardown handshake",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800730 (u8 *) ftie, pos - (u8 *) ftie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700731
732 /* compute MIC before sending */
733 wpa_tdls_linkid(sm, peer, &lnkid);
734 wpa_tdls_key_mic_teardown(peer->tpk.kck, 4, reason_code,
735 dialog_token, (u8 *) &lnkid, (u8 *) ftie,
736 ftie->mic);
737
738skip_ies:
739 /* TODO: register for a Timeout handler, if Teardown is not received at
740 * the other end, then try again another time */
741
742 /* request driver to send Teardown using this FTIE */
743 wpa_tdls_tpk_send(sm, addr, WLAN_TDLS_TEARDOWN, 0,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800744 reason_code, rbuf, pos - rbuf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700745 os_free(rbuf);
746
747 /* clear the Peerkey statemachine */
748 wpa_tdls_peer_free(sm, peer);
749
750 return 0;
751}
752
753
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800754int wpa_tdls_teardown_link(struct wpa_sm *sm, const u8 *addr, u16 reason_code)
755{
756 struct wpa_tdls_peer *peer;
757
758 if (sm->tdls_disabled || !sm->tdls_supported)
759 return -1;
760
761 for (peer = sm->tdls; peer; peer = peer->next) {
762 if (os_memcmp(peer->addr, addr, ETH_ALEN) == 0)
763 break;
764 }
765
766 if (peer == NULL) {
767 wpa_printf(MSG_DEBUG, "TDLS: Could not find peer " MACSTR
768 " for link Teardown", MAC2STR(addr));
769 return -1;
770 }
771
772 if (!peer->tpk_success) {
773 wpa_printf(MSG_DEBUG, "TDLS: Peer " MACSTR
774 " not connected - cannot Teardown link", MAC2STR(addr));
775 return -1;
776 }
777
778 return wpa_tdls_do_teardown(sm, peer, reason_code, 0);
779}
780
781
782void wpa_tdls_disable_link(struct wpa_sm *sm, const u8 *addr)
783{
784 struct wpa_tdls_peer *peer;
785
786 for (peer = sm->tdls; peer; peer = peer->next) {
787 if (os_memcmp(peer->addr, addr, ETH_ALEN) == 0)
788 break;
789 }
790
791 if (peer) {
792 wpa_sm_tdls_oper(sm, TDLS_DISABLE_LINK, addr);
793 wpa_tdls_peer_free(sm, peer);
794 }
795}
796
797
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700798static int wpa_tdls_recv_teardown(struct wpa_sm *sm, const u8 *src_addr,
799 const u8 *buf, size_t len)
800{
801 struct wpa_tdls_peer *peer = NULL;
802 struct wpa_tdls_ftie *ftie;
803 struct wpa_tdls_lnkid *lnkid;
804 struct wpa_eapol_ie_parse kde;
805 u16 reason_code;
806 const u8 *pos;
807 int ielen;
808
809 /* Find the node and free from the list */
810 for (peer = sm->tdls; peer; peer = peer->next) {
811 if (os_memcmp(peer->addr, src_addr, ETH_ALEN) == 0)
812 break;
813 }
814
815 if (peer == NULL) {
816 wpa_printf(MSG_INFO, "TDLS: No matching entry found for "
817 "Teardown " MACSTR, MAC2STR(src_addr));
818 return 0;
819 }
820
821 pos = buf;
822 pos += 1 /* pkt_type */ + 1 /* Category */ + 1 /* Action */;
823
824 reason_code = WPA_GET_LE16(pos);
825 pos += 2;
826
827 wpa_printf(MSG_DEBUG, "TDLS: TDLS Teardown Request from " MACSTR
828 " (reason code %u)", MAC2STR(src_addr), reason_code);
829
830 ielen = len - (pos - buf); /* start of IE in buf */
831 if (wpa_supplicant_parse_ies((const u8 *) pos, ielen, &kde) < 0) {
832 wpa_printf(MSG_INFO, "TDLS: Failed to parse IEs in Teardown");
833 return -1;
834 }
835
836 if (kde.lnkid == NULL || kde.lnkid_len < 3 * ETH_ALEN) {
837 wpa_printf(MSG_INFO, "TDLS: No Link Identifier IE in TDLS "
838 "Teardown");
839 return -1;
840 }
841 lnkid = (struct wpa_tdls_lnkid *) kde.lnkid;
842
843 if (!wpa_tdls_get_privacy(sm) || !peer->tpk_set || !peer->tpk_success)
844 goto skip_ftie;
845
846 if (kde.ftie == NULL || kde.ftie_len < sizeof(*ftie)) {
847 wpa_printf(MSG_INFO, "TDLS: No FTIE in TDLS Teardown");
848 return -1;
849 }
850
851 ftie = (struct wpa_tdls_ftie *) kde.ftie;
852
853 /* Process MIC check to see if TDLS Teardown is right */
854 if (wpa_supplicant_verify_tdls_mic_teardown(4, reason_code,
855 peer->dtoken, peer,
856 (u8 *) lnkid, ftie) < 0) {
857 wpa_printf(MSG_DEBUG, "TDLS: MIC failure for TDLS "
858 "Teardown Request from " MACSTR, MAC2STR(src_addr));
859 return -1;
860 }
861
862skip_ftie:
863 /*
864 * Request the driver to disable the direct link and clear associated
865 * keys.
866 */
867 wpa_sm_tdls_oper(sm, TDLS_DISABLE_LINK, src_addr);
868
869 /* clear the Peerkey statemachine */
870 wpa_tdls_peer_free(sm, peer);
871
872 return 0;
873}
874
875
876/**
877 * wpa_tdls_send_error - To send suitable TDLS status response with
878 * appropriate status code mentioning reason for error/failure.
879 * @dst - MAC addr of Peer station
880 * @tdls_action - TDLS frame type for which error code is sent
881 * @status - status code mentioning reason
882 */
883
884static int wpa_tdls_send_error(struct wpa_sm *sm, const u8 *dst,
885 u8 tdls_action, u8 dialog_token, u16 status)
886{
887 wpa_printf(MSG_DEBUG, "TDLS: Sending error to " MACSTR
888 " (action=%u status=%u)",
889 MAC2STR(dst), tdls_action, status);
890 return wpa_tdls_tpk_send(sm, dst, tdls_action, dialog_token, status,
891 NULL, 0);
892}
893
894
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800895static struct wpa_tdls_peer *
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800896wpa_tdls_add_peer(struct wpa_sm *sm, const u8 *addr, int *existing)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800897{
898 struct wpa_tdls_peer *peer;
899
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800900 if (existing)
901 *existing = 0;
902 for (peer = sm->tdls; peer; peer = peer->next) {
903 if (os_memcmp(peer->addr, addr, ETH_ALEN) == 0) {
904 if (existing)
905 *existing = 1;
906 return peer; /* re-use existing entry */
907 }
908 }
909
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800910 wpa_printf(MSG_INFO, "TDLS: Creating peer entry for " MACSTR,
911 MAC2STR(addr));
912
913 peer = os_zalloc(sizeof(*peer));
914 if (peer == NULL)
915 return NULL;
916
917 os_memcpy(peer->addr, addr, ETH_ALEN);
918 peer->next = sm->tdls;
919 sm->tdls = peer;
920
921 return peer;
922}
923
924
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700925static int wpa_tdls_send_tpk_m1(struct wpa_sm *sm,
926 struct wpa_tdls_peer *peer)
927{
928 size_t buf_len;
929 struct wpa_tdls_timeoutie timeoutie;
930 u16 rsn_capab;
931 struct wpa_tdls_ftie *ftie;
932 u8 *rbuf, *pos, *count_pos;
933 u16 count;
934 struct rsn_ie_hdr *hdr;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700935 int status;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700936
937 if (!wpa_tdls_get_privacy(sm)) {
938 wpa_printf(MSG_DEBUG, "TDLS: No security used on the link");
939 peer->rsnie_i_len = 0;
940 goto skip_rsnie;
941 }
942
943 /*
944 * TPK Handshake Message 1:
945 * FTIE: ANonce=0, SNonce=initiator nonce MIC=0, DataKDs=(RSNIE_I,
946 * Timeout Interval IE))
947 */
948
949 /* Filling RSN IE */
950 hdr = (struct rsn_ie_hdr *) peer->rsnie_i;
951 hdr->elem_id = WLAN_EID_RSN;
952 WPA_PUT_LE16(hdr->version, RSN_VERSION);
953
954 pos = (u8 *) (hdr + 1);
955 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED);
956 pos += RSN_SELECTOR_LEN;
957 count_pos = pos;
958 pos += 2;
959
960 count = 0;
961
962 /*
963 * AES-CCMP is the default Encryption preferred for TDLS, so
964 * RSN IE is filled only with CCMP CIPHER
965 * Note: TKIP is not used to encrypt TDLS link.
966 *
967 * Regardless of the cipher used on the AP connection, select CCMP
968 * here.
969 */
970 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
971 pos += RSN_SELECTOR_LEN;
972 count++;
973
974 WPA_PUT_LE16(count_pos, count);
975
976 WPA_PUT_LE16(pos, 1);
977 pos += 2;
978 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_TPK_HANDSHAKE);
979 pos += RSN_SELECTOR_LEN;
980
981 rsn_capab = WPA_CAPABILITY_PEERKEY_ENABLED;
982 rsn_capab |= RSN_NUM_REPLAY_COUNTERS_16 << 2;
983#ifdef CONFIG_TDLS_TESTING
984 if (tdls_testing & TDLS_TESTING_ALT_RSN_IE) {
985 wpa_printf(MSG_DEBUG, "TDLS: Use alternative RSN IE for "
986 "testing");
987 rsn_capab = WPA_CAPABILITY_PEERKEY_ENABLED;
988 }
989#endif /* CONFIG_TDLS_TESTING */
990 WPA_PUT_LE16(pos, rsn_capab);
991 pos += 2;
992#ifdef CONFIG_TDLS_TESTING
993 if (tdls_testing & TDLS_TESTING_ALT_RSN_IE) {
994 /* Number of PMKIDs */
995 *pos++ = 0x00;
996 *pos++ = 0x00;
997 }
998#endif /* CONFIG_TDLS_TESTING */
999
1000 hdr->len = (pos - peer->rsnie_i) - 2;
1001 peer->rsnie_i_len = pos - peer->rsnie_i;
1002 wpa_hexdump(MSG_DEBUG, "TDLS: RSN IE for TPK handshake",
1003 peer->rsnie_i, peer->rsnie_i_len);
1004
1005skip_rsnie:
1006 buf_len = 0;
1007 if (wpa_tdls_get_privacy(sm))
1008 buf_len += peer->rsnie_i_len + sizeof(struct wpa_tdls_ftie) +
1009 sizeof(struct wpa_tdls_timeoutie);
1010#ifdef CONFIG_TDLS_TESTING
1011 if (wpa_tdls_get_privacy(sm) &&
1012 (tdls_testing & TDLS_TESTING_LONG_FRAME))
1013 buf_len += 170;
1014 if (tdls_testing & TDLS_TESTING_DIFF_BSSID)
1015 buf_len += sizeof(struct wpa_tdls_lnkid);
1016#endif /* CONFIG_TDLS_TESTING */
1017 rbuf = os_zalloc(buf_len + 1);
1018 if (rbuf == NULL) {
1019 wpa_tdls_peer_free(sm, peer);
1020 return -1;
1021 }
1022 pos = rbuf;
1023
1024 if (!wpa_tdls_get_privacy(sm))
1025 goto skip_ies;
1026
1027 /* Initiator RSN IE */
1028 pos = wpa_add_ie(pos, peer->rsnie_i, peer->rsnie_i_len);
1029
1030 ftie = (struct wpa_tdls_ftie *) pos;
1031 ftie->ie_type = WLAN_EID_FAST_BSS_TRANSITION;
1032 ftie->ie_len = sizeof(struct wpa_tdls_ftie) - 2;
1033
1034 if (os_get_random(peer->inonce, WPA_NONCE_LEN)) {
1035 wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
1036 "TDLS: Failed to get random data for initiator Nonce");
1037 os_free(rbuf);
1038 wpa_tdls_peer_free(sm, peer);
1039 return -1;
1040 }
1041 wpa_hexdump(MSG_DEBUG, "TDLS: Initiator Nonce for TPK handshake",
1042 peer->inonce, WPA_NONCE_LEN);
1043 os_memcpy(ftie->Snonce, peer->inonce, WPA_NONCE_LEN);
1044
1045 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE for TPK Handshake M1",
1046 (u8 *) ftie, sizeof(struct wpa_tdls_ftie));
1047
1048 pos = (u8 *) (ftie + 1);
1049
1050#ifdef CONFIG_TDLS_TESTING
1051 if (tdls_testing & TDLS_TESTING_LONG_FRAME) {
1052 wpa_printf(MSG_DEBUG, "TDLS: Testing - add extra subelem to "
1053 "FTIE");
1054 ftie->ie_len += 170;
1055 *pos++ = 255; /* FTIE subelem */
1056 *pos++ = 168; /* FTIE subelem length */
1057 pos += 168;
1058 }
1059#endif /* CONFIG_TDLS_TESTING */
1060
1061 /* Lifetime */
1062 peer->lifetime = TPK_LIFETIME;
1063#ifdef CONFIG_TDLS_TESTING
1064 if (tdls_testing & TDLS_TESTING_SHORT_LIFETIME) {
1065 wpa_printf(MSG_DEBUG, "TDLS: Testing - use short TPK "
1066 "lifetime");
1067 peer->lifetime = 301;
1068 }
1069 if (tdls_testing & TDLS_TESTING_LONG_LIFETIME) {
1070 wpa_printf(MSG_DEBUG, "TDLS: Testing - use long TPK "
1071 "lifetime");
1072 peer->lifetime = 0xffffffff;
1073 }
1074#endif /* CONFIG_TDLS_TESTING */
1075 pos = wpa_add_tdls_timeoutie(pos, (u8 *) &timeoutie,
1076 sizeof(timeoutie), peer->lifetime);
1077 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime %u seconds", peer->lifetime);
1078
1079skip_ies:
1080
1081#ifdef CONFIG_TDLS_TESTING
1082 if (tdls_testing & TDLS_TESTING_DIFF_BSSID) {
1083 wpa_printf(MSG_DEBUG, "TDLS: Testing - use incorrect BSSID in "
1084 "Link Identifier");
1085 struct wpa_tdls_lnkid *l = (struct wpa_tdls_lnkid *) pos;
1086 wpa_tdls_linkid(sm, peer, l);
1087 l->bssid[5] ^= 0x01;
1088 pos += sizeof(*l);
1089 }
1090#endif /* CONFIG_TDLS_TESTING */
1091
1092 wpa_printf(MSG_DEBUG, "TDLS: Sending TDLS Setup Request / TPK "
1093 "Handshake Message 1 (peer " MACSTR ")",
1094 MAC2STR(peer->addr));
1095
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001096 status = wpa_tdls_tpk_send(sm, peer->addr, WLAN_TDLS_SETUP_REQUEST,
1097 1, 0, rbuf, pos - rbuf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001098 os_free(rbuf);
1099
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001100 return status;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001101}
1102
1103
1104static int wpa_tdls_send_tpk_m2(struct wpa_sm *sm,
1105 const unsigned char *src_addr, u8 dtoken,
1106 struct wpa_tdls_lnkid *lnkid,
1107 const struct wpa_tdls_peer *peer)
1108{
1109 u8 *rbuf, *pos;
1110 size_t buf_len;
1111 u32 lifetime;
1112 struct wpa_tdls_timeoutie timeoutie;
1113 struct wpa_tdls_ftie *ftie;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001114 int status;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001115
1116 buf_len = 0;
1117 if (wpa_tdls_get_privacy(sm)) {
1118 /* Peer RSN IE, FTIE(Initiator Nonce, Responder Nonce),
1119 * Lifetime */
1120 buf_len += peer->rsnie_i_len + sizeof(struct wpa_tdls_ftie) +
1121 sizeof(struct wpa_tdls_timeoutie);
1122#ifdef CONFIG_TDLS_TESTING
1123 if (tdls_testing & TDLS_TESTING_LONG_FRAME)
1124 buf_len += 170;
1125#endif /* CONFIG_TDLS_TESTING */
1126 }
1127
1128 rbuf = os_zalloc(buf_len + 1);
1129 if (rbuf == NULL)
1130 return -1;
1131 pos = rbuf;
1132
1133 if (!wpa_tdls_get_privacy(sm))
1134 goto skip_ies;
1135
1136 /* Peer RSN IE */
1137 pos = wpa_add_ie(pos, peer->rsnie_p, peer->rsnie_p_len);
1138
1139 ftie = (struct wpa_tdls_ftie *) pos;
1140 ftie->ie_type = WLAN_EID_FAST_BSS_TRANSITION;
1141 /* TODO: ftie->mic_control to set 2-RESPONSE */
1142 os_memcpy(ftie->Anonce, peer->rnonce, WPA_NONCE_LEN);
1143 os_memcpy(ftie->Snonce, peer->inonce, WPA_NONCE_LEN);
1144 ftie->ie_len = sizeof(struct wpa_tdls_ftie) - 2;
1145 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE for TPK M2",
1146 (u8 *) ftie, sizeof(*ftie));
1147
1148 pos = (u8 *) (ftie + 1);
1149
1150#ifdef CONFIG_TDLS_TESTING
1151 if (tdls_testing & TDLS_TESTING_LONG_FRAME) {
1152 wpa_printf(MSG_DEBUG, "TDLS: Testing - add extra subelem to "
1153 "FTIE");
1154 ftie->ie_len += 170;
1155 *pos++ = 255; /* FTIE subelem */
1156 *pos++ = 168; /* FTIE subelem length */
1157 pos += 168;
1158 }
1159#endif /* CONFIG_TDLS_TESTING */
1160
1161 /* Lifetime */
1162 lifetime = peer->lifetime;
1163#ifdef CONFIG_TDLS_TESTING
1164 if (tdls_testing & TDLS_TESTING_WRONG_LIFETIME_RESP) {
1165 wpa_printf(MSG_DEBUG, "TDLS: Testing - use wrong TPK "
1166 "lifetime in response");
1167 lifetime++;
1168 }
1169#endif /* CONFIG_TDLS_TESTING */
1170 pos = wpa_add_tdls_timeoutie(pos, (u8 *) &timeoutie,
1171 sizeof(timeoutie), lifetime);
1172 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime %u seconds from initiator",
1173 lifetime);
1174
1175 /* compute MIC before sending */
1176 wpa_tdls_ftie_mic(peer->tpk.kck, 2, (u8 *) lnkid, peer->rsnie_p,
1177 (u8 *) &timeoutie, (u8 *) ftie, ftie->mic);
1178
1179skip_ies:
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001180 status = wpa_tdls_tpk_send(sm, src_addr, WLAN_TDLS_SETUP_RESPONSE,
1181 dtoken, 0, rbuf, pos - rbuf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001182 os_free(rbuf);
1183
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001184 return status;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001185}
1186
1187
1188static int wpa_tdls_send_tpk_m3(struct wpa_sm *sm,
1189 const unsigned char *src_addr, u8 dtoken,
1190 struct wpa_tdls_lnkid *lnkid,
1191 const struct wpa_tdls_peer *peer)
1192{
1193 u8 *rbuf, *pos;
1194 size_t buf_len;
1195 struct wpa_tdls_ftie *ftie;
1196 struct wpa_tdls_timeoutie timeoutie;
1197 u32 lifetime;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001198 int status;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199
1200 buf_len = 0;
1201 if (wpa_tdls_get_privacy(sm)) {
1202 /* Peer RSN IE, FTIE(Initiator Nonce, Responder Nonce),
1203 * Lifetime */
1204 buf_len += peer->rsnie_i_len + sizeof(struct wpa_tdls_ftie) +
1205 sizeof(struct wpa_tdls_timeoutie);
1206#ifdef CONFIG_TDLS_TESTING
1207 if (tdls_testing & TDLS_TESTING_LONG_FRAME)
1208 buf_len += 170;
1209#endif /* CONFIG_TDLS_TESTING */
1210 }
1211
1212 rbuf = os_zalloc(buf_len + 1);
1213 if (rbuf == NULL)
1214 return -1;
1215 pos = rbuf;
1216
1217 if (!wpa_tdls_get_privacy(sm))
1218 goto skip_ies;
1219
1220 /* Peer RSN IE */
1221 pos = wpa_add_ie(pos, peer->rsnie_p, peer->rsnie_p_len);
1222
1223 ftie = (struct wpa_tdls_ftie *) pos;
1224 ftie->ie_type = WLAN_EID_FAST_BSS_TRANSITION;
1225 /*TODO: ftie->mic_control to set 3-CONFIRM */
1226 os_memcpy(ftie->Anonce, peer->rnonce, WPA_NONCE_LEN);
1227 os_memcpy(ftie->Snonce, peer->inonce, WPA_NONCE_LEN);
1228 ftie->ie_len = sizeof(struct wpa_tdls_ftie) - 2;
1229
1230 pos = (u8 *) (ftie + 1);
1231
1232#ifdef CONFIG_TDLS_TESTING
1233 if (tdls_testing & TDLS_TESTING_LONG_FRAME) {
1234 wpa_printf(MSG_DEBUG, "TDLS: Testing - add extra subelem to "
1235 "FTIE");
1236 ftie->ie_len += 170;
1237 *pos++ = 255; /* FTIE subelem */
1238 *pos++ = 168; /* FTIE subelem length */
1239 pos += 168;
1240 }
1241#endif /* CONFIG_TDLS_TESTING */
1242
1243 /* Lifetime */
1244 lifetime = peer->lifetime;
1245#ifdef CONFIG_TDLS_TESTING
1246 if (tdls_testing & TDLS_TESTING_WRONG_LIFETIME_CONF) {
1247 wpa_printf(MSG_DEBUG, "TDLS: Testing - use wrong TPK "
1248 "lifetime in confirm");
1249 lifetime++;
1250 }
1251#endif /* CONFIG_TDLS_TESTING */
1252 pos = wpa_add_tdls_timeoutie(pos, (u8 *) &timeoutie,
1253 sizeof(timeoutie), lifetime);
1254 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime %u seconds",
1255 lifetime);
1256
1257 /* compute MIC before sending */
1258 wpa_tdls_ftie_mic(peer->tpk.kck, 3, (u8 *) lnkid, peer->rsnie_p,
1259 (u8 *) &timeoutie, (u8 *) ftie, ftie->mic);
1260
1261skip_ies:
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001262 status = wpa_tdls_tpk_send(sm, src_addr, WLAN_TDLS_SETUP_CONFIRM,
1263 dtoken, 0, rbuf, pos - rbuf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001264 os_free(rbuf);
1265
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001266 return status;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001267}
1268
1269
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001270static int wpa_tdls_send_discovery_response(struct wpa_sm *sm,
1271 struct wpa_tdls_peer *peer,
1272 u8 dialog_token)
1273{
1274 wpa_printf(MSG_DEBUG, "TDLS: Sending TDLS Discovery Response "
1275 "(peer " MACSTR ")", MAC2STR(peer->addr));
1276
1277 return wpa_tdls_tpk_send(sm, peer->addr, WLAN_TDLS_DISCOVERY_RESPONSE,
1278 dialog_token, 0, NULL, 0);
1279}
1280
1281
1282static int
1283wpa_tdls_process_discovery_request(struct wpa_sm *sm, const u8 *addr,
1284 const u8 *buf, size_t len)
1285{
1286 struct wpa_eapol_ie_parse kde;
1287 const struct wpa_tdls_lnkid *lnkid;
1288 struct wpa_tdls_peer *peer;
1289 size_t min_req_len = sizeof(struct wpa_tdls_frame) +
1290 1 /* dialog token */ + sizeof(struct wpa_tdls_lnkid);
1291 u8 dialog_token;
1292
1293 wpa_printf(MSG_DEBUG, "TDLS: Discovery Request from " MACSTR,
1294 MAC2STR(addr));
1295
1296 if (len < min_req_len) {
1297 wpa_printf(MSG_DEBUG, "TDLS Discovery Request is too short: "
1298 "%d", (int) len);
1299 return -1;
1300 }
1301
1302 dialog_token = buf[sizeof(struct wpa_tdls_frame)];
1303
1304 if (wpa_supplicant_parse_ies(buf + sizeof(struct wpa_tdls_frame) + 1,
1305 len - (sizeof(struct wpa_tdls_frame) + 1),
1306 &kde) < 0)
1307 return -1;
1308
1309 if (!kde.lnkid) {
1310 wpa_printf(MSG_DEBUG, "TDLS: Link ID not found in Discovery "
1311 "Request");
1312 return -1;
1313 }
1314
1315 lnkid = (const struct wpa_tdls_lnkid *) kde.lnkid;
1316
1317 if (os_memcmp(sm->bssid, lnkid->bssid, ETH_ALEN) != 0) {
1318 wpa_printf(MSG_DEBUG, "TDLS: Discovery Request from different "
1319 " BSS " MACSTR, MAC2STR(lnkid->bssid));
1320 return -1;
1321 }
1322
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001323 peer = wpa_tdls_add_peer(sm, addr, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001324 if (peer == NULL)
1325 return -1;
1326
1327 return wpa_tdls_send_discovery_response(sm, peer, dialog_token);
1328}
1329
1330
1331int wpa_tdls_send_discovery_request(struct wpa_sm *sm, const u8 *addr)
1332{
1333 if (sm->tdls_disabled || !sm->tdls_supported)
1334 return -1;
1335
1336 wpa_printf(MSG_DEBUG, "TDLS: Sending Discovery Request to peer "
1337 MACSTR, MAC2STR(addr));
1338 return wpa_tdls_tpk_send(sm, addr, WLAN_TDLS_DISCOVERY_REQUEST,
1339 1, 0, NULL, 0);
1340}
1341
1342
1343static int copy_supp_rates(const struct wpa_eapol_ie_parse *kde,
1344 struct wpa_tdls_peer *peer)
1345{
1346 if (!kde->supp_rates) {
1347 wpa_printf(MSG_DEBUG, "TDLS: No supported rates received");
1348 return -1;
1349 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001350 peer->supp_rates_len = merge_byte_arrays(
1351 peer->supp_rates, sizeof(peer->supp_rates),
1352 kde->supp_rates + 2, kde->supp_rates_len - 2,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001353 kde->ext_supp_rates ? kde->ext_supp_rates + 2 : NULL,
1354 kde->ext_supp_rates_len - 2);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001355 return 0;
1356}
1357
1358
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001359static int copy_peer_ht_capab(const struct wpa_eapol_ie_parse *kde,
1360 struct wpa_tdls_peer *peer)
1361{
1362 if (!kde->ht_capabilities ||
1363 kde->ht_capabilities_len <
1364 sizeof(struct ieee80211_ht_capabilities) ) {
1365 wpa_printf(MSG_DEBUG, "TDLS: No supported ht capabilities "
1366 "received");
1367 return 0;
1368 }
1369
1370 if (!peer->ht_capabilities) {
1371 peer->ht_capabilities =
1372 os_zalloc(sizeof(struct ieee80211_ht_capabilities));
1373 if (peer->ht_capabilities == NULL)
1374 return -1;
1375 }
1376
1377 os_memcpy(peer->ht_capabilities, kde->ht_capabilities,
1378 sizeof(struct ieee80211_ht_capabilities));
1379 wpa_hexdump(MSG_DEBUG, "TDLS: Peer HT capabilities",
1380 (u8 *) peer->ht_capabilities,
1381 sizeof(struct ieee80211_ht_capabilities));
1382
1383 return 0;
1384}
1385
1386
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001387static int copy_peer_vht_capab(const struct wpa_eapol_ie_parse *kde,
1388 struct wpa_tdls_peer *peer)
1389{
1390 if (!kde->vht_capabilities ||
1391 kde->vht_capabilities_len <
1392 sizeof(struct ieee80211_vht_capabilities) ) {
1393 wpa_printf(MSG_DEBUG, "TDLS: No supported vht capabilities "
1394 "received");
1395 return 0;
1396 }
1397
1398 if (!peer->vht_capabilities) {
1399 peer->vht_capabilities =
1400 os_zalloc(sizeof(struct ieee80211_vht_capabilities));
1401 if (peer->vht_capabilities == NULL)
1402 return -1;
1403 }
1404
1405 os_memcpy(peer->vht_capabilities, kde->vht_capabilities,
1406 sizeof(struct ieee80211_vht_capabilities));
1407 wpa_hexdump(MSG_DEBUG, "TDLS: Peer VHT capabilities",
1408 (u8 *) peer->vht_capabilities,
1409 sizeof(struct ieee80211_vht_capabilities));
1410
1411 return 0;
1412}
1413
1414
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001415static int copy_peer_ext_capab(const struct wpa_eapol_ie_parse *kde,
1416 struct wpa_tdls_peer *peer)
1417{
1418 if (!kde->ext_capab) {
1419 wpa_printf(MSG_DEBUG, "TDLS: No extended capabilities "
1420 "received");
1421 return 0;
1422 }
1423
1424 if (!peer->ext_capab || peer->ext_capab_len < kde->ext_capab_len - 2) {
1425 /* Need to allocate buffer to fit the new information */
1426 os_free(peer->ext_capab);
1427 peer->ext_capab = os_zalloc(kde->ext_capab_len - 2);
1428 if (peer->ext_capab == NULL)
1429 return -1;
1430 }
1431
1432 peer->ext_capab_len = kde->ext_capab_len - 2;
1433 os_memcpy(peer->ext_capab, kde->ext_capab + 2, peer->ext_capab_len);
1434
1435 return 0;
1436}
1437
1438
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001439static int wpa_tdls_process_tpk_m1(struct wpa_sm *sm, const u8 *src_addr,
1440 const u8 *buf, size_t len)
1441{
1442 struct wpa_tdls_peer *peer;
1443 struct wpa_eapol_ie_parse kde;
1444 struct wpa_ie_data ie;
1445 int cipher;
1446 const u8 *cpos;
1447 struct wpa_tdls_ftie *ftie = NULL;
1448 struct wpa_tdls_timeoutie *timeoutie;
1449 struct wpa_tdls_lnkid *lnkid;
1450 u32 lifetime = 0;
1451#if 0
1452 struct rsn_ie_hdr *hdr;
1453 u8 *pos;
1454 u16 rsn_capab;
1455 u16 rsn_ver;
1456#endif
1457 u8 dtoken;
1458 u16 ielen;
1459 u16 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1460 int tdls_prohibited = sm->tdls_prohibited;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001461 int existing_peer = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001462
1463 if (len < 3 + 3)
1464 return -1;
1465
1466 cpos = buf;
1467 cpos += 1 /* pkt_type */ + 1 /* Category */ + 1 /* Action */;
1468
1469 /* driver had already verified the frame format */
1470 dtoken = *cpos++; /* dialog token */
1471
1472 wpa_printf(MSG_INFO, "TDLS: Dialog Token in TPK M1 %d", dtoken);
1473
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001474 peer = wpa_tdls_add_peer(sm, src_addr, &existing_peer);
1475 if (peer == NULL)
1476 goto error;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001477
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07001478 /* If found, use existing entry instead of adding a new one;
1479 * how to handle the case where both ends initiate at the
1480 * same time? */
1481 if (existing_peer) {
1482 if (peer->tpk_success) {
1483 wpa_printf(MSG_DEBUG, "TDLS: TDLS Setup Request while "
1484 "direct link is enabled - tear down the "
1485 "old link first");
1486#if 0
1487 /* TODO: Disabling the link would be more proper
1488 * operation here, but it seems to trigger a race with
1489 * some drivers handling the new request frame. */
1490 wpa_sm_tdls_oper(sm, TDLS_DISABLE_LINK, src_addr);
1491#else
1492 if (sm->tdls_external_setup)
1493 wpa_sm_tdls_oper(sm, TDLS_DISABLE_LINK,
1494 src_addr);
1495 else
1496 wpa_tdls_del_key(sm, peer);
1497#endif
1498 wpa_tdls_peer_free(sm, peer);
1499 }
1500
1501 /*
1502 * An entry is already present, so check if we already sent a
1503 * TDLS Setup Request. If so, compare MAC addresses and let the
1504 * STA with the lower MAC address continue as the initiator.
1505 * The other negotiation is terminated.
1506 */
1507 if (peer->initiator) {
1508 if (os_memcmp(sm->own_addr, src_addr, ETH_ALEN) < 0) {
1509 wpa_printf(MSG_DEBUG, "TDLS: Discard request "
1510 "from peer with higher address "
1511 MACSTR, MAC2STR(src_addr));
1512 return -1;
1513 } else {
1514 wpa_printf(MSG_DEBUG, "TDLS: Accept request "
1515 "from peer with lower address "
1516 MACSTR " (terminate previously "
1517 "initiated negotiation",
1518 MAC2STR(src_addr));
1519 if (sm->tdls_external_setup)
1520 wpa_sm_tdls_oper(sm, TDLS_DISABLE_LINK,
1521 src_addr);
1522 else
1523 wpa_tdls_del_key(sm, peer);
1524 wpa_tdls_peer_free(sm, peer);
1525 }
1526 }
1527 }
1528
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001529 /* capability information */
1530 peer->capability = WPA_GET_LE16(cpos);
1531 cpos += 2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001532
1533 ielen = len - (cpos - buf); /* start of IE in buf */
1534 if (wpa_supplicant_parse_ies(cpos, ielen, &kde) < 0) {
1535 wpa_printf(MSG_INFO, "TDLS: Failed to parse IEs in TPK M1");
1536 goto error;
1537 }
1538
1539 if (kde.lnkid == NULL || kde.lnkid_len < 3 * ETH_ALEN) {
1540 wpa_printf(MSG_INFO, "TDLS: No valid Link Identifier IE in "
1541 "TPK M1");
1542 goto error;
1543 }
1544 wpa_hexdump(MSG_DEBUG, "TDLS: Link ID Received from TPK M1",
1545 kde.lnkid, kde.lnkid_len);
1546 lnkid = (struct wpa_tdls_lnkid *) kde.lnkid;
1547 if (os_memcmp(sm->bssid, lnkid->bssid, ETH_ALEN) != 0) {
1548 wpa_printf(MSG_INFO, "TDLS: TPK M1 from diff BSS");
1549 status = WLAN_STATUS_NOT_IN_SAME_BSS;
1550 goto error;
1551 }
1552
1553 wpa_printf(MSG_DEBUG, "TDLS: TPK M1 - TPK initiator " MACSTR,
1554 MAC2STR(src_addr));
1555
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001556 if (copy_supp_rates(&kde, peer) < 0)
1557 goto error;
1558
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001559 if (copy_peer_ht_capab(&kde, peer) < 0)
1560 goto error;
1561
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001562 if (copy_peer_vht_capab(&kde, peer) < 0)
1563 goto error;
1564
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001565 if (copy_peer_ext_capab(&kde, peer) < 0)
1566 goto error;
1567
1568 peer->qos_info = kde.qosinfo;
1569
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001570 peer->aid = kde.aid;
1571
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001572#ifdef CONFIG_TDLS_TESTING
1573 if (tdls_testing & TDLS_TESTING_CONCURRENT_INIT) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001574 peer = wpa_tdls_add_peer(sm, src_addr, NULL);
1575 if (peer == NULL)
1576 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001577 wpa_printf(MSG_DEBUG, "TDLS: Testing concurrent initiation of "
1578 "TDLS setup - send own request");
1579 peer->initiator = 1;
1580 wpa_tdls_send_tpk_m1(sm, peer);
1581 }
1582
1583 if ((tdls_testing & TDLS_TESTING_IGNORE_AP_PROHIBIT) &&
1584 tdls_prohibited) {
1585 wpa_printf(MSG_DEBUG, "TDLS: Testing - ignore AP prohibition "
1586 "on TDLS");
1587 tdls_prohibited = 0;
1588 }
1589#endif /* CONFIG_TDLS_TESTING */
1590
1591 if (tdls_prohibited) {
1592 wpa_printf(MSG_INFO, "TDLS: TDLS prohibited in this BSS");
1593 status = WLAN_STATUS_REQUEST_DECLINED;
1594 goto error;
1595 }
1596
1597 if (!wpa_tdls_get_privacy(sm)) {
1598 if (kde.rsn_ie) {
1599 wpa_printf(MSG_INFO, "TDLS: RSN IE in TPK M1 while "
1600 "security is disabled");
1601 status = WLAN_STATUS_SECURITY_DISABLED;
1602 goto error;
1603 }
1604 goto skip_rsn;
1605 }
1606
1607 if (kde.ftie == NULL || kde.ftie_len < sizeof(*ftie) ||
1608 kde.rsn_ie == NULL) {
1609 wpa_printf(MSG_INFO, "TDLS: No FTIE or RSN IE in TPK M1");
1610 status = WLAN_STATUS_INVALID_PARAMETERS;
1611 goto error;
1612 }
1613
1614 if (kde.rsn_ie_len > TDLS_MAX_IE_LEN) {
1615 wpa_printf(MSG_INFO, "TDLS: Too long Initiator RSN IE in "
1616 "TPK M1");
1617 status = WLAN_STATUS_INVALID_RSNIE;
1618 goto error;
1619 }
1620
1621 if (wpa_parse_wpa_ie_rsn(kde.rsn_ie, kde.rsn_ie_len, &ie) < 0) {
1622 wpa_printf(MSG_INFO, "TDLS: Failed to parse RSN IE in TPK M1");
1623 status = WLAN_STATUS_INVALID_RSNIE;
1624 goto error;
1625 }
1626
1627 cipher = ie.pairwise_cipher;
1628 if (cipher & WPA_CIPHER_CCMP) {
1629 wpa_printf(MSG_DEBUG, "TDLS: Using CCMP for direct link");
1630 cipher = WPA_CIPHER_CCMP;
1631 } else {
1632 wpa_printf(MSG_INFO, "TDLS: No acceptable cipher in TPK M1");
1633 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1634 goto error;
1635 }
1636
1637 if ((ie.capabilities &
1638 (WPA_CAPABILITY_NO_PAIRWISE | WPA_CAPABILITY_PEERKEY_ENABLED)) !=
1639 WPA_CAPABILITY_PEERKEY_ENABLED) {
1640 wpa_printf(MSG_INFO, "TDLS: Invalid RSN Capabilities in "
1641 "TPK M1");
1642 status = WLAN_STATUS_INVALID_RSN_IE_CAPAB;
1643 goto error;
1644 }
1645
1646 /* Lifetime */
1647 if (kde.key_lifetime == NULL) {
1648 wpa_printf(MSG_INFO, "TDLS: No Key Lifetime IE in TPK M1");
1649 status = WLAN_STATUS_UNACCEPTABLE_LIFETIME;
1650 goto error;
1651 }
1652 timeoutie = (struct wpa_tdls_timeoutie *) kde.key_lifetime;
1653 lifetime = WPA_GET_LE32(timeoutie->value);
1654 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime %u seconds", lifetime);
1655 if (lifetime < 300) {
1656 wpa_printf(MSG_INFO, "TDLS: Too short TPK lifetime");
1657 status = WLAN_STATUS_UNACCEPTABLE_LIFETIME;
1658 goto error;
1659 }
1660
1661skip_rsn:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001662#ifdef CONFIG_TDLS_TESTING
1663 if (tdls_testing & TDLS_TESTING_CONCURRENT_INIT) {
1664 if (os_memcmp(sm->own_addr, peer->addr, ETH_ALEN) < 0) {
1665 /*
1666 * The request frame from us is going to win, so do not
1667 * replace information based on this request frame from
1668 * the peer.
1669 */
1670 goto skip_rsn_check;
1671 }
1672 }
1673#endif /* CONFIG_TDLS_TESTING */
1674
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001675 peer->initiator = 0; /* Need to check */
1676 peer->dtoken = dtoken;
1677
1678 if (!wpa_tdls_get_privacy(sm)) {
1679 peer->rsnie_i_len = 0;
1680 peer->rsnie_p_len = 0;
1681 peer->cipher = WPA_CIPHER_NONE;
1682 goto skip_rsn_check;
1683 }
1684
1685 ftie = (struct wpa_tdls_ftie *) kde.ftie;
1686 os_memcpy(peer->inonce, ftie->Snonce, WPA_NONCE_LEN);
1687 os_memcpy(peer->rsnie_i, kde.rsn_ie, kde.rsn_ie_len);
1688 peer->rsnie_i_len = kde.rsn_ie_len;
1689 peer->cipher = cipher;
1690
1691 if (os_get_random(peer->rnonce, WPA_NONCE_LEN)) {
1692 wpa_msg(sm->ctx->ctx, MSG_WARNING,
1693 "TDLS: Failed to get random data for responder nonce");
1694 wpa_tdls_peer_free(sm, peer);
1695 goto error;
1696 }
1697
1698#if 0
1699 /* get version info from RSNIE received from Peer */
1700 hdr = (struct rsn_ie_hdr *) kde.rsn_ie;
1701 rsn_ver = WPA_GET_LE16(hdr->version);
1702
1703 /* use min(peer's version, out version) */
1704 if (rsn_ver > RSN_VERSION)
1705 rsn_ver = RSN_VERSION;
1706
1707 hdr = (struct rsn_ie_hdr *) peer->rsnie_p;
1708
1709 hdr->elem_id = WLAN_EID_RSN;
1710 WPA_PUT_LE16(hdr->version, rsn_ver);
1711 pos = (u8 *) (hdr + 1);
1712
1713 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED);
1714 pos += RSN_SELECTOR_LEN;
1715 /* Include only the selected cipher in pairwise cipher suite */
1716 WPA_PUT_LE16(pos, 1);
1717 pos += 2;
1718 if (cipher == WPA_CIPHER_CCMP)
1719 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
1720 pos += RSN_SELECTOR_LEN;
1721
1722 WPA_PUT_LE16(pos, 1);
1723 pos += 2;
1724 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_TPK_HANDSHAKE);
1725 pos += RSN_SELECTOR_LEN;
1726
1727 rsn_capab = WPA_CAPABILITY_PEERKEY_ENABLED;
1728 rsn_capab |= RSN_NUM_REPLAY_COUNTERS_16 << 2;
1729 WPA_PUT_LE16(pos, rsn_capab);
1730 pos += 2;
1731
1732 hdr->len = (pos - peer->rsnie_p) - 2;
1733 peer->rsnie_p_len = pos - peer->rsnie_p;
1734#endif
1735
1736 /* temp fix: validation of RSNIE later */
1737 os_memcpy(peer->rsnie_p, peer->rsnie_i, peer->rsnie_i_len);
1738 peer->rsnie_p_len = peer->rsnie_i_len;
1739
1740 wpa_hexdump(MSG_DEBUG, "TDLS: RSN IE for TPK handshake",
1741 peer->rsnie_p, peer->rsnie_p_len);
1742
1743 peer->lifetime = lifetime;
1744
1745 wpa_tdls_generate_tpk(peer, sm->own_addr, sm->bssid);
1746
1747skip_rsn_check:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001748 /* add the peer to the driver as a "setup in progress" peer */
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001749 wpa_sm_tdls_peer_addset(sm, peer->addr, 1, 0, 0, NULL, 0, NULL, NULL, 0,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001750 NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001751
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001752 wpa_printf(MSG_DEBUG, "TDLS: Sending TDLS Setup Response / TPK M2");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001753 if (wpa_tdls_send_tpk_m2(sm, src_addr, dtoken, lnkid, peer) < 0) {
1754 wpa_tdls_disable_link(sm, peer->addr);
1755 goto error;
1756 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001757
1758 return 0;
1759
1760error:
1761 wpa_tdls_send_error(sm, src_addr, WLAN_TDLS_SETUP_RESPONSE, dtoken,
1762 status);
1763 return -1;
1764}
1765
1766
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001767static int wpa_tdls_enable_link(struct wpa_sm *sm, struct wpa_tdls_peer *peer)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001768{
1769 peer->tpk_success = 1;
1770 eloop_cancel_timeout(wpa_tdls_tpk_timeout, sm, peer);
1771 if (wpa_tdls_get_privacy(sm)) {
1772 u32 lifetime = peer->lifetime;
1773 /*
1774 * Start the initiator process a bit earlier to avoid race
1775 * condition with the responder sending teardown request.
1776 */
1777 if (lifetime > 3 && peer->initiator)
1778 lifetime -= 3;
1779 eloop_register_timeout(lifetime, 0, wpa_tdls_tpk_timeout,
1780 sm, peer);
1781#ifdef CONFIG_TDLS_TESTING
1782 if (tdls_testing & TDLS_TESTING_NO_TPK_EXPIRATION) {
1783 wpa_printf(MSG_DEBUG, "TDLS: Testing - disable TPK "
1784 "expiration");
1785 eloop_cancel_timeout(wpa_tdls_tpk_timeout, sm, peer);
1786 }
1787#endif /* CONFIG_TDLS_TESTING */
1788 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001789
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001790 /* add supported rates, capabilities, and qos_info to the TDLS peer */
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001791 if (wpa_sm_tdls_peer_addset(sm, peer->addr, 0, peer->aid,
1792 peer->capability,
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001793 peer->supp_rates, peer->supp_rates_len,
1794 peer->ht_capabilities,
1795 peer->vht_capabilities,
1796 peer->qos_info, peer->ext_capab,
1797 peer->ext_capab_len) < 0)
1798 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001799
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001800 if (peer->reconfig_key && wpa_tdls_set_key(sm, peer) < 0) {
1801 wpa_printf(MSG_INFO, "TDLS: Could not configure key to the "
1802 "driver");
1803 return -1;
1804 }
1805 peer->reconfig_key = 0;
1806
1807 return wpa_sm_tdls_oper(sm, TDLS_ENABLE_LINK, peer->addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001808}
1809
1810
1811static int wpa_tdls_process_tpk_m2(struct wpa_sm *sm, const u8 *src_addr,
1812 const u8 *buf, size_t len)
1813{
1814 struct wpa_tdls_peer *peer;
1815 struct wpa_eapol_ie_parse kde;
1816 struct wpa_ie_data ie;
1817 int cipher;
1818 struct wpa_tdls_ftie *ftie;
1819 struct wpa_tdls_timeoutie *timeoutie;
1820 struct wpa_tdls_lnkid *lnkid;
1821 u32 lifetime;
1822 u8 dtoken;
1823 int ielen;
1824 u16 status;
1825 const u8 *pos;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001826 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001827
1828 wpa_printf(MSG_DEBUG, "TDLS: Received TDLS Setup Response / TPK M2 "
1829 "(Peer " MACSTR ")", MAC2STR(src_addr));
1830 for (peer = sm->tdls; peer; peer = peer->next) {
1831 if (os_memcmp(peer->addr, src_addr, ETH_ALEN) == 0)
1832 break;
1833 }
1834 if (peer == NULL) {
1835 wpa_printf(MSG_INFO, "TDLS: No matching peer found for "
1836 "TPK M2: " MACSTR, MAC2STR(src_addr));
1837 return -1;
1838 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07001839 if (!peer->initiator) {
1840 /*
1841 * This may happen if both devices try to initiate TDLS at the
1842 * same time and we accept the TPK M1 from the peer in
1843 * wpa_tdls_process_tpk_m1() and clear our previous state.
1844 */
1845 wpa_printf(MSG_INFO, "TDLS: We were not the initiator, so "
1846 "ignore TPK M2 from " MACSTR, MAC2STR(src_addr));
1847 return -1;
1848 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001849 wpa_tdls_tpk_retry_timeout_cancel(sm, peer, WLAN_TDLS_SETUP_REQUEST);
1850
Sunil Duttadce9cf2013-09-15 11:51:00 -07001851 if (len < 3 + 2 + 1) {
1852 wpa_tdls_disable_link(sm, src_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001853 return -1;
Sunil Duttadce9cf2013-09-15 11:51:00 -07001854 }
1855
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001856 pos = buf;
1857 pos += 1 /* pkt_type */ + 1 /* Category */ + 1 /* Action */;
1858 status = WPA_GET_LE16(pos);
1859 pos += 2 /* status code */;
1860
1861 if (status != WLAN_STATUS_SUCCESS) {
1862 wpa_printf(MSG_INFO, "TDLS: Status code in TPK M2: %u",
1863 status);
Sunil Duttadce9cf2013-09-15 11:51:00 -07001864 wpa_tdls_disable_link(sm, src_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001865 return -1;
1866 }
1867
1868 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1869
1870 /* TODO: need to verify dialog token matches here or in kernel */
1871 dtoken = *pos++; /* dialog token */
1872
1873 wpa_printf(MSG_DEBUG, "TDLS: Dialog Token in TPK M2 %d", dtoken);
1874
Sunil Duttadce9cf2013-09-15 11:51:00 -07001875 if (len < 3 + 2 + 1 + 2) {
1876 wpa_tdls_disable_link(sm, src_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001877 return -1;
Sunil Duttadce9cf2013-09-15 11:51:00 -07001878 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001879
1880 /* capability information */
1881 peer->capability = WPA_GET_LE16(pos);
1882 pos += 2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001883
1884 ielen = len - (pos - buf); /* start of IE in buf */
1885 if (wpa_supplicant_parse_ies(pos, ielen, &kde) < 0) {
1886 wpa_printf(MSG_INFO, "TDLS: Failed to parse IEs in TPK M2");
1887 goto error;
1888 }
1889
1890#ifdef CONFIG_TDLS_TESTING
1891 if (tdls_testing & TDLS_TESTING_DECLINE_RESP) {
1892 wpa_printf(MSG_DEBUG, "TDLS: Testing - decline response");
1893 status = WLAN_STATUS_REQUEST_DECLINED;
1894 goto error;
1895 }
1896#endif /* CONFIG_TDLS_TESTING */
1897
1898 if (kde.lnkid == NULL || kde.lnkid_len < 3 * ETH_ALEN) {
1899 wpa_printf(MSG_INFO, "TDLS: No valid Link Identifier IE in "
1900 "TPK M2");
1901 goto error;
1902 }
1903 wpa_hexdump(MSG_DEBUG, "TDLS: Link ID Received from TPK M2",
1904 kde.lnkid, kde.lnkid_len);
1905 lnkid = (struct wpa_tdls_lnkid *) kde.lnkid;
1906
1907 if (os_memcmp(sm->bssid, lnkid->bssid, ETH_ALEN) != 0) {
1908 wpa_printf(MSG_INFO, "TDLS: TPK M2 from different BSS");
1909 status = WLAN_STATUS_NOT_IN_SAME_BSS;
1910 goto error;
1911 }
1912
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001913 if (copy_supp_rates(&kde, peer) < 0)
1914 goto error;
1915
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001916 if (copy_peer_ht_capab(&kde, peer) < 0)
1917 goto error;
1918
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001919 if (copy_peer_vht_capab(&kde, peer) < 0)
1920 goto error;
1921
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001922 if (copy_peer_ext_capab(&kde, peer) < 0)
1923 goto error;
1924
1925 peer->qos_info = kde.qosinfo;
1926
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001927 peer->aid = kde.aid;
1928
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001929 if (!wpa_tdls_get_privacy(sm)) {
1930 peer->rsnie_p_len = 0;
1931 peer->cipher = WPA_CIPHER_NONE;
1932 goto skip_rsn;
1933 }
1934
1935 if (kde.ftie == NULL || kde.ftie_len < sizeof(*ftie) ||
1936 kde.rsn_ie == NULL) {
1937 wpa_printf(MSG_INFO, "TDLS: No FTIE or RSN IE in TPK M2");
1938 status = WLAN_STATUS_INVALID_PARAMETERS;
1939 goto error;
1940 }
1941 wpa_hexdump(MSG_DEBUG, "TDLS: RSN IE Received from TPK M2",
1942 kde.rsn_ie, kde.rsn_ie_len);
1943
1944 /*
1945 * FIX: bitwise comparison of RSN IE is not the correct way of
1946 * validation this. It can be different, but certain fields must
1947 * match. Since we list only a single pairwise cipher in TPK M1, the
1948 * memcmp is likely to work in most cases, though.
1949 */
1950 if (kde.rsn_ie_len != peer->rsnie_i_len ||
1951 os_memcmp(peer->rsnie_i, kde.rsn_ie, peer->rsnie_i_len) != 0) {
1952 wpa_printf(MSG_INFO, "TDLS: RSN IE in TPK M2 does "
1953 "not match with RSN IE used in TPK M1");
1954 wpa_hexdump(MSG_DEBUG, "TDLS: RSN IE Sent in TPK M1",
1955 peer->rsnie_i, peer->rsnie_i_len);
1956 wpa_hexdump(MSG_DEBUG, "TDLS: RSN IE Received from TPK M2",
1957 kde.rsn_ie, kde.rsn_ie_len);
1958 status = WLAN_STATUS_INVALID_RSNIE;
1959 goto error;
1960 }
1961
1962 if (wpa_parse_wpa_ie_rsn(kde.rsn_ie, kde.rsn_ie_len, &ie) < 0) {
1963 wpa_printf(MSG_INFO, "TDLS: Failed to parse RSN IE in TPK M2");
1964 status = WLAN_STATUS_INVALID_RSNIE;
1965 goto error;
1966 }
1967
1968 cipher = ie.pairwise_cipher;
1969 if (cipher == WPA_CIPHER_CCMP) {
1970 wpa_printf(MSG_DEBUG, "TDLS: Using CCMP for direct link");
1971 cipher = WPA_CIPHER_CCMP;
1972 } else {
1973 wpa_printf(MSG_INFO, "TDLS: No acceptable cipher in TPK M2");
1974 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1975 goto error;
1976 }
1977
1978 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE Received from TPK M2",
1979 kde.ftie, sizeof(*ftie));
1980 ftie = (struct wpa_tdls_ftie *) kde.ftie;
1981
1982 if (!os_memcmp(peer->inonce, ftie->Snonce, WPA_NONCE_LEN) == 0) {
1983 wpa_printf(MSG_INFO, "TDLS: FTIE SNonce in TPK M2 does "
1984 "not match with FTIE SNonce used in TPK M1");
1985 /* Silently discard the frame */
1986 return -1;
1987 }
1988
1989 /* Responder Nonce and RSN IE */
1990 os_memcpy(peer->rnonce, ftie->Anonce, WPA_NONCE_LEN);
1991 os_memcpy(peer->rsnie_p, kde.rsn_ie, kde.rsn_ie_len);
1992 peer->rsnie_p_len = kde.rsn_ie_len;
1993 peer->cipher = cipher;
1994
1995 /* Lifetime */
1996 if (kde.key_lifetime == NULL) {
1997 wpa_printf(MSG_INFO, "TDLS: No Key Lifetime IE in TPK M2");
1998 status = WLAN_STATUS_UNACCEPTABLE_LIFETIME;
1999 goto error;
2000 }
2001 timeoutie = (struct wpa_tdls_timeoutie *) kde.key_lifetime;
2002 lifetime = WPA_GET_LE32(timeoutie->value);
2003 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime %u seconds in TPK M2",
2004 lifetime);
2005 if (lifetime != peer->lifetime) {
2006 wpa_printf(MSG_INFO, "TDLS: Unexpected TPK lifetime %u in "
2007 "TPK M2 (expected %u)", lifetime, peer->lifetime);
2008 status = WLAN_STATUS_UNACCEPTABLE_LIFETIME;
2009 goto error;
2010 }
2011
2012 wpa_tdls_generate_tpk(peer, sm->own_addr, sm->bssid);
2013
2014 /* Process MIC check to see if TPK M2 is right */
2015 if (wpa_supplicant_verify_tdls_mic(2, peer, (u8 *) lnkid,
2016 (u8 *) timeoutie, ftie) < 0) {
2017 /* Discard the frame */
2018 wpa_tdls_del_key(sm, peer);
2019 wpa_tdls_peer_free(sm, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002020 if (sm->tdls_external_setup)
2021 wpa_sm_tdls_oper(sm, TDLS_DISABLE_LINK, src_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002022 return -1;
2023 }
2024
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002025 if (wpa_tdls_set_key(sm, peer) < 0) {
2026 /*
2027 * Some drivers may not be able to config the key prior to full
2028 * STA entry having been configured.
2029 */
2030 wpa_printf(MSG_DEBUG, "TDLS: Try to configure TPK again after "
2031 "STA entry is complete");
2032 peer->reconfig_key = 1;
2033 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002034
2035skip_rsn:
2036 peer->dtoken = dtoken;
2037
2038 wpa_printf(MSG_DEBUG, "TDLS: Sending TDLS Setup Confirm / "
2039 "TPK Handshake Message 3");
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002040 if (wpa_tdls_send_tpk_m3(sm, src_addr, dtoken, lnkid, peer) < 0) {
2041 wpa_tdls_disable_link(sm, peer->addr);
2042 return -1;
2043 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002044
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002045 ret = wpa_tdls_enable_link(sm, peer);
2046 if (ret < 0) {
2047 wpa_printf(MSG_DEBUG, "TDLS: Could not enable link");
2048 wpa_tdls_do_teardown(sm, peer,
2049 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED, 1);
2050 }
2051 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002052
2053error:
2054 wpa_tdls_send_error(sm, src_addr, WLAN_TDLS_SETUP_CONFIRM, dtoken,
2055 status);
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002056 wpa_tdls_disable_link(sm, peer->addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002057 return -1;
2058}
2059
2060
2061static int wpa_tdls_process_tpk_m3(struct wpa_sm *sm, const u8 *src_addr,
2062 const u8 *buf, size_t len)
2063{
2064 struct wpa_tdls_peer *peer;
2065 struct wpa_eapol_ie_parse kde;
2066 struct wpa_tdls_ftie *ftie;
2067 struct wpa_tdls_timeoutie *timeoutie;
2068 struct wpa_tdls_lnkid *lnkid;
2069 int ielen;
2070 u16 status;
2071 const u8 *pos;
2072 u32 lifetime;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002073 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002074
2075 wpa_printf(MSG_DEBUG, "TDLS: Received TDLS Setup Confirm / TPK M3 "
2076 "(Peer " MACSTR ")", MAC2STR(src_addr));
2077 for (peer = sm->tdls; peer; peer = peer->next) {
2078 if (os_memcmp(peer->addr, src_addr, ETH_ALEN) == 0)
2079 break;
2080 }
2081 if (peer == NULL) {
2082 wpa_printf(MSG_INFO, "TDLS: No matching peer found for "
2083 "TPK M3: " MACSTR, MAC2STR(src_addr));
2084 return -1;
2085 }
2086 wpa_tdls_tpk_retry_timeout_cancel(sm, peer, WLAN_TDLS_SETUP_RESPONSE);
2087
2088 if (len < 3 + 3)
Sunil Duttadce9cf2013-09-15 11:51:00 -07002089 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002090 pos = buf;
2091 pos += 1 /* pkt_type */ + 1 /* Category */ + 1 /* Action */;
2092
2093 status = WPA_GET_LE16(pos);
2094
2095 if (status != 0) {
2096 wpa_printf(MSG_INFO, "TDLS: Status code in TPK M3: %u",
2097 status);
Sunil Duttadce9cf2013-09-15 11:51:00 -07002098 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002099 }
2100 pos += 2 /* status code */ + 1 /* dialog token */;
2101
2102 ielen = len - (pos - buf); /* start of IE in buf */
2103 if (wpa_supplicant_parse_ies((const u8 *) pos, ielen, &kde) < 0) {
2104 wpa_printf(MSG_INFO, "TDLS: Failed to parse KDEs in TPK M3");
Sunil Duttadce9cf2013-09-15 11:51:00 -07002105 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002106 }
2107
2108 if (kde.lnkid == NULL || kde.lnkid_len < 3 * ETH_ALEN) {
2109 wpa_printf(MSG_INFO, "TDLS: No Link Identifier IE in TPK M3");
Sunil Duttadce9cf2013-09-15 11:51:00 -07002110 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002111 }
2112 wpa_hexdump(MSG_DEBUG, "TDLS: Link ID Received from TPK M3",
2113 (u8 *) kde.lnkid, kde.lnkid_len);
2114 lnkid = (struct wpa_tdls_lnkid *) kde.lnkid;
2115
2116 if (os_memcmp(sm->bssid, lnkid->bssid, ETH_ALEN) != 0) {
2117 wpa_printf(MSG_INFO, "TDLS: TPK M3 from diff BSS");
Sunil Duttadce9cf2013-09-15 11:51:00 -07002118 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002119 }
2120
2121 if (!wpa_tdls_get_privacy(sm))
2122 goto skip_rsn;
2123
2124 if (kde.ftie == NULL || kde.ftie_len < sizeof(*ftie)) {
2125 wpa_printf(MSG_INFO, "TDLS: No FTIE in TPK M3");
Sunil Duttadce9cf2013-09-15 11:51:00 -07002126 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002127 }
2128 wpa_hexdump(MSG_DEBUG, "TDLS: FTIE Received from TPK M3",
2129 kde.ftie, sizeof(*ftie));
2130 ftie = (struct wpa_tdls_ftie *) kde.ftie;
2131
2132 if (kde.rsn_ie == NULL) {
2133 wpa_printf(MSG_INFO, "TDLS: No RSN IE in TPK M3");
Sunil Duttadce9cf2013-09-15 11:51:00 -07002134 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002135 }
2136 wpa_hexdump(MSG_DEBUG, "TDLS: RSN IE Received from TPK M3",
2137 kde.rsn_ie, kde.rsn_ie_len);
2138 if (kde.rsn_ie_len != peer->rsnie_p_len ||
2139 os_memcmp(kde.rsn_ie, peer->rsnie_p, peer->rsnie_p_len) != 0) {
2140 wpa_printf(MSG_INFO, "TDLS: RSN IE in TPK M3 does not match "
2141 "with the one sent in TPK M2");
Sunil Duttadce9cf2013-09-15 11:51:00 -07002142 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002143 }
2144
2145 if (!os_memcmp(peer->rnonce, ftie->Anonce, WPA_NONCE_LEN) == 0) {
2146 wpa_printf(MSG_INFO, "TDLS: FTIE ANonce in TPK M3 does "
2147 "not match with FTIE ANonce used in TPK M2");
Sunil Duttadce9cf2013-09-15 11:51:00 -07002148 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002149 }
2150
2151 if (!os_memcmp(peer->inonce, ftie->Snonce, WPA_NONCE_LEN) == 0) {
2152 wpa_printf(MSG_INFO, "TDLS: FTIE SNonce in TPK M3 does not "
2153 "match with FTIE SNonce used in TPK M1");
Sunil Duttadce9cf2013-09-15 11:51:00 -07002154 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002155 }
2156
2157 if (kde.key_lifetime == NULL) {
2158 wpa_printf(MSG_INFO, "TDLS: No Key Lifetime IE in TPK M3");
Sunil Duttadce9cf2013-09-15 11:51:00 -07002159 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002160 }
2161 timeoutie = (struct wpa_tdls_timeoutie *) kde.key_lifetime;
2162 wpa_hexdump(MSG_DEBUG, "TDLS: Timeout IE Received from TPK M3",
2163 (u8 *) timeoutie, sizeof(*timeoutie));
2164 lifetime = WPA_GET_LE32(timeoutie->value);
2165 wpa_printf(MSG_DEBUG, "TDLS: TPK lifetime %u seconds in TPK M3",
2166 lifetime);
2167 if (lifetime != peer->lifetime) {
2168 wpa_printf(MSG_INFO, "TDLS: Unexpected TPK lifetime %u in "
2169 "TPK M3 (expected %u)", lifetime, peer->lifetime);
Sunil Duttadce9cf2013-09-15 11:51:00 -07002170 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002171 }
2172
2173 if (wpa_supplicant_verify_tdls_mic(3, peer, (u8 *) lnkid,
2174 (u8 *) timeoutie, ftie) < 0) {
2175 wpa_tdls_del_key(sm, peer);
Sunil Duttadce9cf2013-09-15 11:51:00 -07002176 goto error;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002177 }
2178
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002179 if (wpa_tdls_set_key(sm, peer) < 0) {
2180 /*
2181 * Some drivers may not be able to config the key prior to full
2182 * STA entry having been configured.
2183 */
2184 wpa_printf(MSG_DEBUG, "TDLS: Try to configure TPK again after "
2185 "STA entry is complete");
2186 peer->reconfig_key = 1;
2187 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002188
2189skip_rsn:
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002190 ret = wpa_tdls_enable_link(sm, peer);
2191 if (ret < 0) {
2192 wpa_printf(MSG_DEBUG, "TDLS: Could not enable link");
2193 wpa_tdls_do_teardown(sm, peer,
2194 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED, 1);
2195 }
2196 return ret;
Sunil Duttadce9cf2013-09-15 11:51:00 -07002197error:
2198 wpa_tdls_disable_link(sm, peer->addr);
2199 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002200}
2201
2202
2203static u8 * wpa_add_tdls_timeoutie(u8 *pos, u8 *ie, size_t ie_len, u32 tsecs)
2204{
2205 struct wpa_tdls_timeoutie *lifetime = (struct wpa_tdls_timeoutie *) ie;
2206
2207 os_memset(lifetime, 0, ie_len);
2208 lifetime->ie_type = WLAN_EID_TIMEOUT_INTERVAL;
2209 lifetime->ie_len = sizeof(struct wpa_tdls_timeoutie) - 2;
2210 lifetime->interval_type = WLAN_TIMEOUT_KEY_LIFETIME;
2211 WPA_PUT_LE32(lifetime->value, tsecs);
2212 os_memcpy(pos, ie, ie_len);
2213 return pos + ie_len;
2214}
2215
2216
2217/**
2218 * wpa_tdls_start - Initiate TDLS handshake (send TPK Handshake Message 1)
2219 * @sm: Pointer to WPA state machine data from wpa_sm_init()
2220 * @peer: MAC address of the peer STA
2221 * Returns: 0 on success, or -1 on failure
2222 *
2223 * Send TPK Handshake Message 1 info to driver to start TDLS
2224 * handshake with the peer.
2225 */
2226int wpa_tdls_start(struct wpa_sm *sm, const u8 *addr)
2227{
2228 struct wpa_tdls_peer *peer;
2229 int tdls_prohibited = sm->tdls_prohibited;
2230
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002231 if (sm->tdls_disabled || !sm->tdls_supported)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002232 return -1;
2233
2234#ifdef CONFIG_TDLS_TESTING
2235 if ((tdls_testing & TDLS_TESTING_IGNORE_AP_PROHIBIT) &&
2236 tdls_prohibited) {
2237 wpa_printf(MSG_DEBUG, "TDLS: Testing - ignore AP prohibition "
2238 "on TDLS");
2239 tdls_prohibited = 0;
2240 }
2241#endif /* CONFIG_TDLS_TESTING */
2242
2243 if (tdls_prohibited) {
2244 wpa_printf(MSG_DEBUG, "TDLS: TDLS is prohibited in this BSS - "
2245 "reject request to start setup");
2246 return -1;
2247 }
2248
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002249 peer = wpa_tdls_add_peer(sm, addr, NULL);
2250 if (peer == NULL)
2251 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002252
2253 peer->initiator = 1;
2254
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002255 /* add the peer to the driver as a "setup in progress" peer */
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002256 wpa_sm_tdls_peer_addset(sm, peer->addr, 1, 0, 0, NULL, 0, NULL, NULL, 0,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002257 NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002258
2259 if (wpa_tdls_send_tpk_m1(sm, peer) < 0) {
2260 wpa_tdls_disable_link(sm, peer->addr);
2261 return -1;
2262 }
2263
2264 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002265}
2266
2267
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002268void wpa_tdls_remove(struct wpa_sm *sm, const u8 *addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002269{
2270 struct wpa_tdls_peer *peer;
2271
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002272 if (sm->tdls_disabled || !sm->tdls_supported)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002273 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002274
2275 for (peer = sm->tdls; peer; peer = peer->next) {
2276 if (os_memcmp(peer->addr, addr, ETH_ALEN) == 0)
2277 break;
2278 }
2279
2280 if (peer == NULL || !peer->tpk_success)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002281 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002282
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002283 if (sm->tdls_external_setup) {
2284 /*
2285 * Disable previous link to allow renegotiation to be completed
2286 * on AP path.
2287 */
2288 wpa_sm_tdls_oper(sm, TDLS_DISABLE_LINK, peer->addr);
2289 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002290}
2291
2292
2293/**
2294 * wpa_supplicant_rx_tdls - Receive TDLS data frame
2295 *
2296 * This function is called to receive TDLS (ethertype = 0x890d) data frames.
2297 */
2298static void wpa_supplicant_rx_tdls(void *ctx, const u8 *src_addr,
2299 const u8 *buf, size_t len)
2300{
2301 struct wpa_sm *sm = ctx;
2302 struct wpa_tdls_frame *tf;
2303
2304 wpa_hexdump(MSG_DEBUG, "TDLS: Received Data frame encapsulation",
2305 buf, len);
2306
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002307 if (sm->tdls_disabled || !sm->tdls_supported) {
2308 wpa_printf(MSG_DEBUG, "TDLS: Discard message - TDLS disabled "
2309 "or unsupported by driver");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002310 return;
2311 }
2312
2313 if (os_memcmp(src_addr, sm->own_addr, ETH_ALEN) == 0) {
2314 wpa_printf(MSG_DEBUG, "TDLS: Discard copy of own message");
2315 return;
2316 }
2317
2318 if (len < sizeof(*tf)) {
2319 wpa_printf(MSG_INFO, "TDLS: Drop too short frame");
2320 return;
2321 }
2322
2323 /* Check to make sure its a valid encapsulated TDLS frame */
2324 tf = (struct wpa_tdls_frame *) buf;
2325 if (tf->payloadtype != 2 /* TDLS_RFTYPE */ ||
2326 tf->category != WLAN_ACTION_TDLS) {
2327 wpa_printf(MSG_INFO, "TDLS: Invalid frame - payloadtype=%u "
2328 "category=%u action=%u",
2329 tf->payloadtype, tf->category, tf->action);
2330 return;
2331 }
2332
2333 switch (tf->action) {
2334 case WLAN_TDLS_SETUP_REQUEST:
2335 wpa_tdls_process_tpk_m1(sm, src_addr, buf, len);
2336 break;
2337 case WLAN_TDLS_SETUP_RESPONSE:
2338 wpa_tdls_process_tpk_m2(sm, src_addr, buf, len);
2339 break;
2340 case WLAN_TDLS_SETUP_CONFIRM:
2341 wpa_tdls_process_tpk_m3(sm, src_addr, buf, len);
2342 break;
2343 case WLAN_TDLS_TEARDOWN:
2344 wpa_tdls_recv_teardown(sm, src_addr, buf, len);
2345 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002346 case WLAN_TDLS_DISCOVERY_REQUEST:
2347 wpa_tdls_process_discovery_request(sm, src_addr, buf, len);
2348 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002349 default:
2350 /* Kernel code will process remaining frames */
2351 wpa_printf(MSG_DEBUG, "TDLS: Ignore TDLS frame action code %u",
2352 tf->action);
2353 break;
2354 }
2355}
2356
2357
2358/**
2359 * wpa_tdls_init - Initialize driver interface parameters for TDLS
2360 * @wpa_s: Pointer to wpa_supplicant data
2361 * Returns: 0 on success, -1 on failure
2362 *
2363 * This function is called to initialize driver interface parameters for TDLS.
2364 * wpa_drv_init() must have been called before this function to initialize the
2365 * driver interface.
2366 */
2367int wpa_tdls_init(struct wpa_sm *sm)
2368{
2369 if (sm == NULL)
2370 return -1;
2371
Dmitry Shmidt04949592012-07-19 12:16:46 -07002372 sm->l2_tdls = l2_packet_init(sm->bridge_ifname ? sm->bridge_ifname :
2373 sm->ifname,
2374 sm->own_addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002375 ETH_P_80211_ENCAP, wpa_supplicant_rx_tdls,
2376 sm, 0);
2377 if (sm->l2_tdls == NULL) {
2378 wpa_printf(MSG_ERROR, "TDLS: Failed to open l2_packet "
2379 "connection");
2380 return -1;
2381 }
2382
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002383 /*
2384 * Drivers that support TDLS but don't implement the get_capa callback
2385 * are assumed to perform everything internally
2386 */
2387 if (wpa_sm_tdls_get_capa(sm, &sm->tdls_supported,
2388 &sm->tdls_external_setup) < 0) {
2389 sm->tdls_supported = 1;
2390 sm->tdls_external_setup = 0;
2391 }
2392
2393 wpa_printf(MSG_DEBUG, "TDLS: TDLS operation%s supported by "
2394 "driver", sm->tdls_supported ? "" : " not");
2395 wpa_printf(MSG_DEBUG, "TDLS: Driver uses %s link setup",
2396 sm->tdls_external_setup ? "external" : "internal");
2397
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002398 return 0;
2399}
2400
2401
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002402void wpa_tdls_teardown_peers(struct wpa_sm *sm)
2403{
2404 struct wpa_tdls_peer *peer;
2405
2406 peer = sm->tdls;
2407
2408 wpa_printf(MSG_DEBUG, "TDLS: Tear down peers");
2409
2410 while (peer) {
2411 wpa_printf(MSG_DEBUG, "TDLS: Tear down peer " MACSTR,
2412 MAC2STR(peer->addr));
2413 if (sm->tdls_external_setup)
2414 wpa_tdls_send_teardown(sm, peer->addr,
2415 WLAN_REASON_DEAUTH_LEAVING);
2416 else
2417 wpa_sm_tdls_oper(sm, TDLS_TEARDOWN, peer->addr);
2418
2419 peer = peer->next;
2420 }
2421}
2422
2423
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002424static void wpa_tdls_remove_peers(struct wpa_sm *sm)
2425{
2426 struct wpa_tdls_peer *peer, *tmp;
2427
2428 peer = sm->tdls;
2429 sm->tdls = NULL;
2430
2431 while (peer) {
2432 int res;
2433 tmp = peer->next;
2434 res = wpa_sm_tdls_oper(sm, TDLS_DISABLE_LINK, peer->addr);
2435 wpa_printf(MSG_DEBUG, "TDLS: Remove peer " MACSTR " (res=%d)",
2436 MAC2STR(peer->addr), res);
2437 wpa_tdls_peer_free(sm, peer);
2438 os_free(peer);
2439 peer = tmp;
2440 }
2441}
2442
2443
2444/**
2445 * wpa_tdls_deinit - Deinitialize driver interface parameters for TDLS
2446 *
2447 * This function is called to recover driver interface parameters for TDLS
2448 * and frees resources allocated for it.
2449 */
2450void wpa_tdls_deinit(struct wpa_sm *sm)
2451{
2452 if (sm == NULL)
2453 return;
2454
2455 if (sm->l2_tdls)
2456 l2_packet_deinit(sm->l2_tdls);
2457 sm->l2_tdls = NULL;
2458
2459 wpa_tdls_remove_peers(sm);
2460}
2461
2462
2463void wpa_tdls_assoc(struct wpa_sm *sm)
2464{
2465 wpa_printf(MSG_DEBUG, "TDLS: Remove peers on association");
2466 wpa_tdls_remove_peers(sm);
2467}
2468
2469
2470void wpa_tdls_disassoc(struct wpa_sm *sm)
2471{
2472 wpa_printf(MSG_DEBUG, "TDLS: Remove peers on disassociation");
2473 wpa_tdls_remove_peers(sm);
2474}
2475
2476
2477static int wpa_tdls_prohibited(const u8 *ies, size_t len)
2478{
2479 struct wpa_eapol_ie_parse elems;
2480
2481 if (ies == NULL)
2482 return 0;
2483
2484 if (wpa_supplicant_parse_ies(ies, len, &elems) < 0)
2485 return 0;
2486
2487 if (elems.ext_capab == NULL || elems.ext_capab_len < 2 + 5)
2488 return 0;
2489
2490 /* bit 38 - TDLS Prohibited */
2491 return !!(elems.ext_capab[2 + 4] & 0x40);
2492}
2493
2494
2495void wpa_tdls_ap_ies(struct wpa_sm *sm, const u8 *ies, size_t len)
2496{
2497 sm->tdls_prohibited = wpa_tdls_prohibited(ies, len);
2498 wpa_printf(MSG_DEBUG, "TDLS: TDLS is %s in the target BSS",
2499 sm->tdls_prohibited ? "prohibited" : "allowed");
2500}
2501
2502
2503void wpa_tdls_assoc_resp_ies(struct wpa_sm *sm, const u8 *ies, size_t len)
2504{
2505 if (!sm->tdls_prohibited && wpa_tdls_prohibited(ies, len)) {
2506 wpa_printf(MSG_DEBUG, "TDLS: TDLS prohibited based on "
2507 "(Re)Association Response IEs");
2508 sm->tdls_prohibited = 1;
2509 }
2510}
2511
2512
2513void wpa_tdls_enable(struct wpa_sm *sm, int enabled)
2514{
2515 wpa_printf(MSG_DEBUG, "TDLS: %s", enabled ? "enabled" : "disabled");
2516 sm->tdls_disabled = !enabled;
2517}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002518
2519
2520int wpa_tdls_is_external_setup(struct wpa_sm *sm)
2521{
2522 return sm->tdls_external_setup;
2523}