2 * Received Data frame processing for EAPOL messages
3 * Copyright (c) 2010-2015, Jouni Malinen <j@w1.fi>
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 "crypto/aes_wrap.h"
13 #include "crypto/crypto.h"
14 #include "common/defs.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/ieee802_11_common.h"
17 #include "common/eapol_common.h"
18 #include "common/wpa_common.h"
19 #include "rsn_supp/wpa_ie.h"
23 static int is_zero(const u8
*buf
, size_t len
)
26 for (i
= 0; i
< len
; i
++) {
34 static int check_mic(const u8
*kck
, size_t kck_len
, int akmp
, int ver
,
35 const u8
*data
, size_t len
)
39 struct ieee802_1x_hdr
*hdr
;
40 struct wpa_eapol_key
*key
;
41 u8 rx_mic
[WPA_EAPOL_KEY_MIC_MAX_LEN
];
42 size_t mic_len
= wpa_mic_len(akmp
, PMK_LEN
);
44 buf
= os_memdup(data
, len
);
47 hdr
= (struct ieee802_1x_hdr
*) buf
;
48 key
= (struct wpa_eapol_key
*) (hdr
+ 1);
50 os_memcpy(rx_mic
, key
+ 1, mic_len
);
51 os_memset(key
+ 1, 0, mic_len
);
53 if (wpa_eapol_key_mic(kck
, kck_len
, akmp
, ver
, buf
, len
,
54 (u8
*) (key
+ 1)) == 0 &&
55 os_memcmp(rx_mic
, key
+ 1, mic_len
) == 0)
64 static void rx_data_eapol_key_1_of_4(struct wlantest
*wt
, const u8
*dst
,
65 const u8
*src
, const u8
*data
, size_t len
)
67 struct wlantest_bss
*bss
;
68 struct wlantest_sta
*sta
;
69 const struct ieee802_1x_hdr
*eapol
;
70 const struct wpa_eapol_key
*hdr
;
72 wpa_printf(MSG_DEBUG
, "EAPOL-Key 1/4 " MACSTR
" -> " MACSTR
,
73 MAC2STR(src
), MAC2STR(dst
));
74 bss
= bss_get(wt
, src
);
77 sta
= sta_get(bss
, dst
);
81 eapol
= (const struct ieee802_1x_hdr
*) data
;
82 hdr
= (const struct wpa_eapol_key
*) (eapol
+ 1);
83 if (is_zero(hdr
->key_nonce
, WPA_NONCE_LEN
)) {
84 add_note(wt
, MSG_INFO
, "EAPOL-Key 1/4 from " MACSTR
85 " used zero nonce", MAC2STR(src
));
87 if (!is_zero(hdr
->key_rsc
, 8)) {
88 add_note(wt
, MSG_INFO
, "EAPOL-Key 1/4 from " MACSTR
89 " used non-zero Key RSC", MAC2STR(src
));
91 os_memcpy(sta
->anonce
, hdr
->key_nonce
, WPA_NONCE_LEN
);
95 static int try_pmk(struct wlantest
*wt
, struct wlantest_bss
*bss
,
96 struct wlantest_sta
*sta
, u16 ver
,
97 const u8
*data
, size_t len
,
98 struct wlantest_pmk
*pmk
)
102 if (wpa_key_mgmt_ft(sta
->key_mgmt
)) {
104 u8 pmk_r0_name
[WPA_PMK_NAME_LEN
];
106 u8 pmk_r1_name
[WPA_PMK_NAME_LEN
];
107 u8 ptk_name
[WPA_PMK_NAME_LEN
];
109 wpa_derive_pmk_r0(pmk
->pmk
, PMK_LEN
,
110 bss
->ssid
, bss
->ssid_len
, bss
->mdid
,
111 bss
->r0kh_id
, bss
->r0kh_id_len
,
112 sta
->addr
, pmk_r0
, pmk_r0_name
, 0);
113 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R0", pmk_r0
, PMK_LEN
);
114 wpa_hexdump(MSG_DEBUG
, "FT: PMKR0Name", pmk_r0_name
,
116 wpa_derive_pmk_r1(pmk_r0
, PMK_LEN
, pmk_r0_name
, bss
->r1kh_id
,
117 sta
->addr
, pmk_r1
, pmk_r1_name
);
118 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", pmk_r1
, PMK_LEN
);
119 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", pmk_r1_name
,
121 if (wpa_pmk_r1_to_ptk(pmk_r1
, PMK_LEN
, sta
->snonce
, sta
->anonce
,
123 bss
->bssid
, pmk_r1_name
, &ptk
, ptk_name
,
125 sta
->pairwise_cipher
) < 0 ||
126 check_mic(ptk
.kck
, ptk
.kck_len
, sta
->key_mgmt
, ver
, data
,
129 } else if (wpa_pmk_to_ptk(pmk
->pmk
, PMK_LEN
,
130 "Pairwise key expansion",
131 bss
->bssid
, sta
->addr
, sta
->anonce
,
132 sta
->snonce
, &ptk
, sta
->key_mgmt
,
133 sta
->pairwise_cipher
, NULL
, 0) < 0 ||
134 check_mic(ptk
.kck
, ptk
.kck_len
, sta
->key_mgmt
, ver
, data
,
139 wpa_printf(MSG_INFO
, "Derived PTK for STA " MACSTR
" BSSID " MACSTR
,
140 MAC2STR(sta
->addr
), MAC2STR(bss
->bssid
));
141 sta
->counters
[WLANTEST_STA_COUNTER_PTK_LEARNED
]++;
144 * Rekeying - use new PTK for EAPOL-Key frames, but continue
145 * using the old PTK for frame decryption.
147 add_note(wt
, MSG_DEBUG
, "Derived PTK during rekeying");
148 os_memcpy(&sta
->tptk
, &ptk
, sizeof(ptk
));
149 wpa_hexdump(MSG_DEBUG
, "TPTK:KCK",
150 sta
->tptk
.kck
, sta
->tptk
.kck_len
);
151 wpa_hexdump(MSG_DEBUG
, "TPTK:KEK",
152 sta
->tptk
.kek
, sta
->tptk
.kek_len
);
153 wpa_hexdump(MSG_DEBUG
, "TPTK:TK",
154 sta
->tptk
.tk
, sta
->tptk
.tk_len
);
158 add_note(wt
, MSG_DEBUG
, "Derived new PTK");
159 os_memcpy(&sta
->ptk
, &ptk
, sizeof(ptk
));
160 wpa_hexdump(MSG_DEBUG
, "PTK:KCK", sta
->ptk
.kck
, sta
->ptk
.kck_len
);
161 wpa_hexdump(MSG_DEBUG
, "PTK:KEK", sta
->ptk
.kek
, sta
->ptk
.kek_len
);
162 wpa_hexdump(MSG_DEBUG
, "PTK:TK", sta
->ptk
.tk
, sta
->ptk
.tk_len
);
164 os_memset(sta
->rsc_tods
, 0, sizeof(sta
->rsc_tods
));
165 os_memset(sta
->rsc_fromds
, 0, sizeof(sta
->rsc_fromds
));
170 static void derive_ptk(struct wlantest
*wt
, struct wlantest_bss
*bss
,
171 struct wlantest_sta
*sta
, u16 ver
,
172 const u8
*data
, size_t len
)
174 struct wlantest_pmk
*pmk
;
176 wpa_printf(MSG_DEBUG
, "Trying to derive PTK for " MACSTR
" (ver %u)",
177 MAC2STR(sta
->addr
), ver
);
178 dl_list_for_each(pmk
, &bss
->pmk
, struct wlantest_pmk
, list
) {
179 wpa_printf(MSG_DEBUG
, "Try per-BSS PMK");
180 if (try_pmk(wt
, bss
, sta
, ver
, data
, len
, pmk
) == 0)
184 dl_list_for_each(pmk
, &wt
->pmk
, struct wlantest_pmk
, list
) {
185 wpa_printf(MSG_DEBUG
, "Try global PMK");
186 if (try_pmk(wt
, bss
, sta
, ver
, data
, len
, pmk
) == 0)
191 struct wlantest_ptk
*ptk
;
192 int prev_level
= wpa_debug_level
;
194 wpa_debug_level
= MSG_WARNING
;
195 dl_list_for_each(ptk
, &wt
->ptk
, struct wlantest_ptk
, list
) {
196 if (check_mic(ptk
->ptk
.kck
, ptk
->ptk
.kck_len
,
197 sta
->key_mgmt
, ver
, data
, len
) < 0)
199 wpa_printf(MSG_INFO
, "Pre-set PTK matches for STA "
200 MACSTR
" BSSID " MACSTR
,
201 MAC2STR(sta
->addr
), MAC2STR(bss
->bssid
));
202 add_note(wt
, MSG_DEBUG
, "Using pre-set PTK");
204 wpa_cipher_key_len(sta
->pairwise_cipher
);
205 os_memcpy(&sta
->ptk
, &ptk
->ptk
, sizeof(ptk
->ptk
));
206 wpa_hexdump(MSG_DEBUG
, "PTK:KCK",
207 sta
->ptk
.kck
, sta
->ptk
.kck_len
);
208 wpa_hexdump(MSG_DEBUG
, "PTK:KEK",
209 sta
->ptk
.kek
, sta
->ptk
.kek_len
);
210 wpa_hexdump(MSG_DEBUG
, "PTK:TK",
211 sta
->ptk
.tk
, sta
->ptk
.tk_len
);
213 os_memset(sta
->rsc_tods
, 0, sizeof(sta
->rsc_tods
));
214 os_memset(sta
->rsc_fromds
, 0, sizeof(sta
->rsc_fromds
));
216 wpa_debug_level
= prev_level
;
219 add_note(wt
, MSG_DEBUG
, "No matching PMK found to derive PTK");
223 static void rx_data_eapol_key_2_of_4(struct wlantest
*wt
, const u8
*dst
,
224 const u8
*src
, const u8
*data
, size_t len
)
226 struct wlantest_bss
*bss
;
227 struct wlantest_sta
*sta
;
228 const struct ieee802_1x_hdr
*eapol
;
229 const struct wpa_eapol_key
*hdr
;
230 const u8
*key_data
, *kck
, *mic
;
231 size_t kck_len
, mic_len
;
232 u16 key_info
, key_data_len
;
233 struct wpa_eapol_ie_parse ie
;
235 wpa_printf(MSG_DEBUG
, "EAPOL-Key 2/4 " MACSTR
" -> " MACSTR
,
236 MAC2STR(src
), MAC2STR(dst
));
237 bss
= bss_get(wt
, dst
);
240 sta
= sta_get(bss
, src
);
244 eapol
= (const struct ieee802_1x_hdr
*) data
;
245 hdr
= (const struct wpa_eapol_key
*) (eapol
+ 1);
246 mic_len
= wpa_mic_len(sta
->key_mgmt
, PMK_LEN
);
247 mic
= (const u8
*) (hdr
+ 1);
248 if (is_zero(hdr
->key_nonce
, WPA_NONCE_LEN
)) {
249 add_note(wt
, MSG_INFO
, "EAPOL-Key 2/4 from " MACSTR
250 " used zero nonce", MAC2STR(src
));
252 if (!is_zero(hdr
->key_rsc
, 8)) {
253 add_note(wt
, MSG_INFO
, "EAPOL-Key 2/4 from " MACSTR
254 " used non-zero Key RSC", MAC2STR(src
));
256 os_memcpy(sta
->snonce
, hdr
->key_nonce
, WPA_NONCE_LEN
);
257 key_info
= WPA_GET_BE16(hdr
->key_info
);
258 key_data_len
= WPA_GET_BE16(mic
+ mic_len
);
259 derive_ptk(wt
, bss
, sta
, key_info
& WPA_KEY_INFO_TYPE_MASK
, data
, len
);
261 if (!sta
->ptk_set
&& !sta
->tptk_set
) {
262 add_note(wt
, MSG_DEBUG
,
263 "No PTK known to process EAPOL-Key 2/4");
268 kck_len
= sta
->ptk
.kck_len
;
270 add_note(wt
, MSG_DEBUG
,
271 "Use TPTK for validation EAPOL-Key MIC");
273 kck_len
= sta
->tptk
.kck_len
;
275 if (check_mic(kck
, kck_len
, sta
->key_mgmt
,
276 key_info
& WPA_KEY_INFO_TYPE_MASK
, data
, len
) < 0) {
277 add_note(wt
, MSG_INFO
, "Mismatch in EAPOL-Key 2/4 MIC");
280 add_note(wt
, MSG_DEBUG
, "Valid MIC found in EAPOL-Key 2/4");
282 key_data
= mic
+ mic_len
+ 2;
284 if (wpa_supplicant_parse_ies(key_data
, key_data_len
, &ie
) < 0) {
285 add_note(wt
, MSG_INFO
, "Failed to parse EAPOL-Key Key Data");
290 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data - WPA IE",
291 ie
.wpa_ie
, ie
.wpa_ie_len
);
292 if (os_memcmp(ie
.wpa_ie
, sta
->rsnie
, ie
.wpa_ie_len
) != 0) {
293 struct ieee802_11_elems elems
;
294 add_note(wt
, MSG_INFO
,
295 "Mismatch in WPA IE between EAPOL-Key 2/4 "
296 "and (Re)Association Request from " MACSTR
,
298 wpa_hexdump(MSG_INFO
, "WPA IE in EAPOL-Key",
299 ie
.wpa_ie
, ie
.wpa_ie_len
);
300 wpa_hexdump(MSG_INFO
, "WPA IE in (Re)Association "
303 sta
->rsnie
[0] ? 2 + sta
->rsnie
[1] : 0);
305 * The sniffer may have missed (Re)Association
306 * Request, so try to survive with the information from
309 os_memset(&elems
, 0, sizeof(elems
));
310 elems
.wpa_ie
= ie
.wpa_ie
+ 2;
311 elems
.wpa_ie_len
= ie
.wpa_ie_len
- 2;
312 wpa_printf(MSG_DEBUG
, "Update STA data based on WPA "
313 "IE in EAPOL-Key 2/4");
314 sta_update_assoc(sta
, &elems
);
319 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data - RSN IE",
320 ie
.rsn_ie
, ie
.rsn_ie_len
);
321 if (os_memcmp(ie
.rsn_ie
, sta
->rsnie
, ie
.rsn_ie_len
) != 0) {
322 struct ieee802_11_elems elems
;
323 add_note(wt
, MSG_INFO
,
324 "Mismatch in RSN IE between EAPOL-Key 2/4 "
325 "and (Re)Association Request from " MACSTR
,
327 wpa_hexdump(MSG_INFO
, "RSN IE in EAPOL-Key",
328 ie
.rsn_ie
, ie
.rsn_ie_len
);
329 wpa_hexdump(MSG_INFO
, "RSN IE in (Re)Association "
332 sta
->rsnie
[0] ? 2 + sta
->rsnie
[1] : 0);
334 * The sniffer may have missed (Re)Association
335 * Request, so try to survive with the information from
338 os_memset(&elems
, 0, sizeof(elems
));
339 elems
.rsn_ie
= ie
.rsn_ie
+ 2;
340 elems
.rsn_ie_len
= ie
.rsn_ie_len
- 2;
341 wpa_printf(MSG_DEBUG
, "Update STA data based on RSN "
342 "IE in EAPOL-Key 2/4");
343 sta_update_assoc(sta
, &elems
);
349 static u8
* decrypt_eapol_key_data_rc4(struct wlantest
*wt
, const u8
*kek
,
350 const struct wpa_eapol_key
*hdr
,
351 const u8
*keydata
, u16 keydatalen
,
356 buf
= os_memdup(keydata
, keydatalen
);
360 os_memcpy(ek
, hdr
->key_iv
, 16);
361 os_memcpy(ek
+ 16, kek
, 16);
362 if (rc4_skip(ek
, 32, 256, buf
, keydatalen
)) {
363 add_note(wt
, MSG_INFO
, "RC4 failed");
373 static u8
* decrypt_eapol_key_data_aes(struct wlantest
*wt
, const u8
*kek
,
374 const struct wpa_eapol_key
*hdr
,
375 const u8
*keydata
, u16 keydatalen
,
380 if (keydatalen
% 8) {
381 add_note(wt
, MSG_INFO
, "Unsupported AES-WRAP len %d",
385 keydatalen
-= 8; /* AES-WRAP adds 8 bytes */
386 buf
= os_malloc(keydatalen
);
389 if (aes_unwrap(kek
, 16, keydatalen
/ 8, keydata
, buf
)) {
391 add_note(wt
, MSG_INFO
,
392 "AES unwrap failed - could not decrypt EAPOL-Key "
402 static u8
* decrypt_eapol_key_data(struct wlantest
*wt
, int akmp
, const u8
*kek
,
403 size_t kek_len
, u16 ver
,
404 const struct wpa_eapol_key
*hdr
,
409 const u8
*mic
, *keydata
;
414 mic
= (const u8
*) (hdr
+ 1);
415 mic_len
= wpa_mic_len(akmp
, PMK_LEN
);
416 keydata
= mic
+ mic_len
+ 2;
417 keydatalen
= WPA_GET_BE16(mic
+ mic_len
);
420 case WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
:
421 return decrypt_eapol_key_data_rc4(wt
, kek
, hdr
, keydata
,
423 case WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
:
424 case WPA_KEY_INFO_TYPE_AES_128_CMAC
:
425 return decrypt_eapol_key_data_aes(wt
, kek
, hdr
, keydata
,
427 case WPA_KEY_INFO_TYPE_AKM_DEFINED
:
428 /* For now, assume this is OSEN */
429 return decrypt_eapol_key_data_aes(wt
, kek
, hdr
, keydata
,
432 add_note(wt
, MSG_INFO
,
433 "Unsupported EAPOL-Key Key Descriptor Version %u",
440 static void learn_kde_keys(struct wlantest
*wt
, struct wlantest_bss
*bss
,
441 struct wlantest_sta
*sta
,
442 const u8
*buf
, size_t len
, const u8
*rsc
)
444 struct wpa_eapol_ie_parse ie
;
446 if (wpa_supplicant_parse_ies(buf
, len
, &ie
) < 0) {
447 add_note(wt
, MSG_INFO
, "Failed to parse EAPOL-Key Key Data");
452 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data - WPA IE",
453 ie
.wpa_ie
, ie
.wpa_ie_len
);
457 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data - RSN IE",
458 ie
.rsn_ie
, ie
.rsn_ie_len
);
462 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data - GTK KDE",
464 if (ie
.gtk_len
>= 2 && ie
.gtk_len
<= 2 + 32) {
466 id
= ie
.gtk
[0] & 0x03;
467 add_note(wt
, MSG_DEBUG
, "GTK KeyID=%u tx=%u",
468 id
, !!(ie
.gtk
[0] & 0x04));
469 if ((ie
.gtk
[0] & 0xf8) || ie
.gtk
[1]) {
470 add_note(wt
, MSG_INFO
,
471 "GTK KDE: Reserved field set: "
472 "%02x %02x", ie
.gtk
[0], ie
.gtk
[1]);
474 wpa_hexdump(MSG_DEBUG
, "GTK", ie
.gtk
+ 2,
476 bss
->gtk_len
[id
] = ie
.gtk_len
- 2;
477 sta
->gtk_len
= ie
.gtk_len
- 2;
478 os_memcpy(bss
->gtk
[id
], ie
.gtk
+ 2, ie
.gtk_len
- 2);
479 os_memcpy(sta
->gtk
, ie
.gtk
+ 2, ie
.gtk_len
- 2);
480 bss
->rsc
[id
][0] = rsc
[5];
481 bss
->rsc
[id
][1] = rsc
[4];
482 bss
->rsc
[id
][2] = rsc
[3];
483 bss
->rsc
[id
][3] = rsc
[2];
484 bss
->rsc
[id
][4] = rsc
[1];
485 bss
->rsc
[id
][5] = rsc
[0];
488 wpa_hexdump(MSG_DEBUG
, "RSC", bss
->rsc
[id
], 6);
490 add_note(wt
, MSG_INFO
, "Invalid GTK KDE length %u",
491 (unsigned) ie
.gtk_len
);
496 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data - IGTK KDE",
497 ie
.igtk
, ie
.igtk_len
);
498 if (ie
.igtk_len
== 24) {
500 id
= WPA_GET_LE16(ie
.igtk
);
502 add_note(wt
, MSG_INFO
,
503 "Unexpected IGTK KeyID %u", id
);
506 add_note(wt
, MSG_DEBUG
, "IGTK KeyID %u", id
);
507 wpa_hexdump(MSG_DEBUG
, "IPN", ie
.igtk
+ 2, 6);
508 wpa_hexdump(MSG_DEBUG
, "IGTK", ie
.igtk
+ 8,
510 os_memcpy(bss
->igtk
[id
], ie
.igtk
+ 8, 16);
511 bss
->igtk_len
[id
] = 16;
513 bss
->ipn
[id
][0] = ipn
[5];
514 bss
->ipn
[id
][1] = ipn
[4];
515 bss
->ipn
[id
][2] = ipn
[3];
516 bss
->ipn
[id
][3] = ipn
[2];
517 bss
->ipn
[id
][4] = ipn
[1];
518 bss
->ipn
[id
][5] = ipn
[0];
521 } else if (ie
.igtk_len
== 40) {
523 id
= WPA_GET_LE16(ie
.igtk
);
525 add_note(wt
, MSG_INFO
,
526 "Unexpected IGTK KeyID %u", id
);
529 add_note(wt
, MSG_DEBUG
, "IGTK KeyID %u", id
);
530 wpa_hexdump(MSG_DEBUG
, "IPN", ie
.igtk
+ 2, 6);
531 wpa_hexdump(MSG_DEBUG
, "IGTK", ie
.igtk
+ 8,
533 os_memcpy(bss
->igtk
[id
], ie
.igtk
+ 8, 32);
534 bss
->igtk_len
[id
] = 32;
536 bss
->ipn
[id
][0] = ipn
[5];
537 bss
->ipn
[id
][1] = ipn
[4];
538 bss
->ipn
[id
][2] = ipn
[3];
539 bss
->ipn
[id
][3] = ipn
[2];
540 bss
->ipn
[id
][4] = ipn
[1];
541 bss
->ipn
[id
][5] = ipn
[0];
545 add_note(wt
, MSG_INFO
, "Invalid IGTK KDE length %u",
546 (unsigned) ie
.igtk_len
);
552 static void rx_data_eapol_key_3_of_4(struct wlantest
*wt
, const u8
*dst
,
553 const u8
*src
, const u8
*data
, size_t len
)
555 struct wlantest_bss
*bss
;
556 struct wlantest_sta
*sta
;
557 const struct ieee802_1x_hdr
*eapol
;
558 const struct wpa_eapol_key
*hdr
;
559 const u8
*key_data
, *kck
, *kek
, *mic
;
560 size_t kck_len
, kek_len
, mic_len
;
563 u8
*decrypted_buf
= NULL
;
565 size_t decrypted_len
= 0;
566 struct wpa_eapol_ie_parse ie
;
568 wpa_printf(MSG_DEBUG
, "EAPOL-Key 3/4 " MACSTR
" -> " MACSTR
,
569 MAC2STR(src
), MAC2STR(dst
));
570 bss
= bss_get(wt
, src
);
573 sta
= sta_get(bss
, dst
);
576 mic_len
= wpa_mic_len(sta
->key_mgmt
, PMK_LEN
);
578 eapol
= (const struct ieee802_1x_hdr
*) data
;
579 hdr
= (const struct wpa_eapol_key
*) (eapol
+ 1);
580 mic
= (const u8
*) (hdr
+ 1);
581 key_info
= WPA_GET_BE16(hdr
->key_info
);
583 if (os_memcmp(sta
->anonce
, hdr
->key_nonce
, WPA_NONCE_LEN
) != 0) {
584 add_note(wt
, MSG_INFO
,
585 "EAPOL-Key ANonce mismatch between 1/4 and 3/4");
588 os_memcpy(sta
->anonce
, hdr
->key_nonce
, WPA_NONCE_LEN
);
590 derive_ptk(wt
, bss
, sta
, key_info
& WPA_KEY_INFO_TYPE_MASK
,
594 if (!sta
->ptk_set
&& !sta
->tptk_set
) {
595 add_note(wt
, MSG_DEBUG
,
596 "No PTK known to process EAPOL-Key 3/4");
601 kek_len
= sta
->ptk
.kek_len
;
603 kck_len
= sta
->ptk
.kck_len
;
605 add_note(wt
, MSG_DEBUG
,
606 "Use TPTK for validation EAPOL-Key MIC");
608 kck_len
= sta
->tptk
.kck_len
;
610 kek_len
= sta
->tptk
.kek_len
;
612 if (check_mic(kck
, kck_len
, sta
->key_mgmt
,
613 key_info
& WPA_KEY_INFO_TYPE_MASK
, data
, len
) < 0) {
614 add_note(wt
, MSG_INFO
, "Mismatch in EAPOL-Key 3/4 MIC");
617 add_note(wt
, MSG_DEBUG
, "Valid MIC found in EAPOL-Key 3/4");
619 key_data
= mic
+ mic_len
+ 2;
620 if (!(key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
)) {
621 if (sta
->proto
& WPA_PROTO_RSN
)
622 add_note(wt
, MSG_INFO
,
623 "EAPOL-Key 3/4 without EncrKeyData bit");
624 decrypted
= key_data
;
625 decrypted_len
= WPA_GET_BE16(mic
+ mic_len
);
627 ver
= key_info
& WPA_KEY_INFO_TYPE_MASK
;
628 decrypted_buf
= decrypt_eapol_key_data(wt
, sta
->key_mgmt
,
630 hdr
, &decrypted_len
);
631 if (decrypted_buf
== NULL
) {
632 add_note(wt
, MSG_INFO
,
633 "Failed to decrypt EAPOL-Key Key Data");
636 decrypted
= decrypted_buf
;
637 wpa_hexdump(MSG_DEBUG
, "Decrypted EAPOL-Key Key Data",
638 decrypted
, decrypted_len
);
640 if ((wt
->write_pcap_dumper
|| wt
->pcapng
) && decrypted
!= key_data
) {
641 /* Fill in a dummy Data frame header */
642 u8 buf
[24 + 8 + sizeof(*eapol
) + sizeof(*hdr
) + 64];
643 struct ieee80211_hdr
*h
;
644 struct wpa_eapol_key
*k
;
649 plain_len
= decrypted_len
;
651 while (p
+ 1 < decrypted
+ decrypted_len
) {
652 if (p
[0] == 0xdd && p
[1] == 0x00) {
654 plain_len
= p
- decrypted
;
660 if (p
&& p
> decrypted
&& *p
== 0xdd &&
661 p
+ 1 == decrypted
+ decrypted_len
) {
664 plain_len
= p
- decrypted
;
667 os_memset(buf
, 0, sizeof(buf
));
668 h
= (struct ieee80211_hdr
*) buf
;
669 h
->frame_control
= host_to_le16(0x0208);
670 os_memcpy(h
->addr1
, dst
, ETH_ALEN
);
671 os_memcpy(h
->addr2
, src
, ETH_ALEN
);
672 os_memcpy(h
->addr3
, src
, ETH_ALEN
);
673 pos
= (u8
*) (h
+ 1);
674 os_memcpy(pos
, "\xaa\xaa\x03\x00\x00\x00\x88\x8e", 8);
676 os_memcpy(pos
, eapol
, sizeof(*eapol
));
677 pos
+= sizeof(*eapol
);
678 os_memcpy(pos
, hdr
, sizeof(*hdr
) + mic_len
);
679 k
= (struct wpa_eapol_key
*) pos
;
680 pos
+= sizeof(struct wpa_eapol_key
) + mic_len
;
681 WPA_PUT_BE16(k
->key_info
,
682 key_info
& ~WPA_KEY_INFO_ENCR_KEY_DATA
);
683 WPA_PUT_BE16(pos
, plain_len
);
684 write_pcap_decrypted(wt
, buf
, 24 + 8 + sizeof(*eapol
) +
685 sizeof(*hdr
) + mic_len
+ 2,
686 decrypted
, plain_len
);
689 if (wpa_supplicant_parse_ies(decrypted
, decrypted_len
, &ie
) < 0) {
690 add_note(wt
, MSG_INFO
, "Failed to parse EAPOL-Key Key Data");
691 os_free(decrypted_buf
);
696 os_memcmp(ie
.wpa_ie
, bss
->wpaie
, ie
.wpa_ie_len
) != 0) ||
697 (ie
.wpa_ie
== NULL
&& bss
->wpaie
[0])) {
698 add_note(wt
, MSG_INFO
,
699 "Mismatch in WPA IE between EAPOL-Key 3/4 and "
700 "Beacon/Probe Response from " MACSTR
,
701 MAC2STR(bss
->bssid
));
702 wpa_hexdump(MSG_INFO
, "WPA IE in EAPOL-Key",
703 ie
.wpa_ie
, ie
.wpa_ie_len
);
704 wpa_hexdump(MSG_INFO
, "WPA IE in Beacon/Probe "
707 bss
->wpaie
[0] ? 2 + bss
->wpaie
[1] : 0);
711 os_memcmp(ie
.rsn_ie
, bss
->rsnie
, ie
.rsn_ie_len
) != 0) ||
712 (ie
.rsn_ie
== NULL
&& bss
->rsnie
[0])) {
713 add_note(wt
, MSG_INFO
, "Mismatch in RSN IE between EAPOL-Key "
714 "3/4 and Beacon/Probe Response from " MACSTR
,
715 MAC2STR(bss
->bssid
));
716 wpa_hexdump(MSG_INFO
, "RSN IE in EAPOL-Key",
717 ie
.rsn_ie
, ie
.rsn_ie_len
);
718 wpa_hexdump(MSG_INFO
, "RSN IE in Beacon/Probe Response",
720 bss
->rsnie
[0] ? 2 + bss
->rsnie
[1] : 0);
723 learn_kde_keys(wt
, bss
, sta
, decrypted
, decrypted_len
, hdr
->key_rsc
);
724 os_free(decrypted_buf
);
728 static void rx_data_eapol_key_4_of_4(struct wlantest
*wt
, const u8
*dst
,
729 const u8
*src
, const u8
*data
, size_t len
)
731 struct wlantest_bss
*bss
;
732 struct wlantest_sta
*sta
;
733 const struct ieee802_1x_hdr
*eapol
;
734 const struct wpa_eapol_key
*hdr
;
739 wpa_printf(MSG_DEBUG
, "EAPOL-Key 4/4 " MACSTR
" -> " MACSTR
,
740 MAC2STR(src
), MAC2STR(dst
));
741 bss
= bss_get(wt
, dst
);
744 sta
= sta_get(bss
, src
);
748 eapol
= (const struct ieee802_1x_hdr
*) data
;
749 hdr
= (const struct wpa_eapol_key
*) (eapol
+ 1);
750 if (!is_zero(hdr
->key_rsc
, 8)) {
751 add_note(wt
, MSG_INFO
, "EAPOL-Key 4/4 from " MACSTR
" used "
752 "non-zero Key RSC", MAC2STR(src
));
754 key_info
= WPA_GET_BE16(hdr
->key_info
);
756 if (!sta
->ptk_set
&& !sta
->tptk_set
) {
757 add_note(wt
, MSG_DEBUG
,
758 "No PTK known to process EAPOL-Key 4/4");
763 kck_len
= sta
->ptk
.kck_len
;
765 add_note(wt
, MSG_DEBUG
,
766 "Use TPTK for validation EAPOL-Key MIC");
768 kck_len
= sta
->tptk
.kck_len
;
770 if (check_mic(kck
, kck_len
, sta
->key_mgmt
,
771 key_info
& WPA_KEY_INFO_TYPE_MASK
, data
, len
) < 0) {
772 add_note(wt
, MSG_INFO
, "Mismatch in EAPOL-Key 4/4 MIC");
775 add_note(wt
, MSG_DEBUG
, "Valid MIC found in EAPOL-Key 4/4");
777 add_note(wt
, MSG_DEBUG
, "Update PTK (rekeying)");
778 os_memcpy(&sta
->ptk
, &sta
->tptk
, sizeof(sta
->ptk
));
781 os_memset(sta
->rsc_tods
, 0, sizeof(sta
->rsc_tods
));
782 os_memset(sta
->rsc_fromds
, 0, sizeof(sta
->rsc_fromds
));
787 static void rx_data_eapol_key_1_of_2(struct wlantest
*wt
, const u8
*dst
,
788 const u8
*src
, const u8
*data
, size_t len
)
790 struct wlantest_bss
*bss
;
791 struct wlantest_sta
*sta
;
792 const struct ieee802_1x_hdr
*eapol
;
793 const struct wpa_eapol_key
*hdr
;
796 size_t decrypted_len
= 0;
799 wpa_printf(MSG_DEBUG
, "EAPOL-Key 1/2 " MACSTR
" -> " MACSTR
,
800 MAC2STR(src
), MAC2STR(dst
));
801 bss
= bss_get(wt
, src
);
804 sta
= sta_get(bss
, dst
);
807 mic_len
= wpa_mic_len(sta
->key_mgmt
, PMK_LEN
);
809 eapol
= (const struct ieee802_1x_hdr
*) data
;
810 hdr
= (const struct wpa_eapol_key
*) (eapol
+ 1);
811 key_info
= WPA_GET_BE16(hdr
->key_info
);
814 add_note(wt
, MSG_DEBUG
,
815 "No PTK known to process EAPOL-Key 1/2");
820 check_mic(sta
->ptk
.kck
, sta
->ptk
.kck_len
, sta
->key_mgmt
,
821 key_info
& WPA_KEY_INFO_TYPE_MASK
,
823 add_note(wt
, MSG_INFO
, "Mismatch in EAPOL-Key 1/2 MIC");
826 add_note(wt
, MSG_DEBUG
, "Valid MIC found in EAPOL-Key 1/2");
828 if (sta
->proto
& WPA_PROTO_RSN
&&
829 !(key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
)) {
830 add_note(wt
, MSG_INFO
, "EAPOL-Key 1/2 without EncrKeyData bit");
833 ver
= key_info
& WPA_KEY_INFO_TYPE_MASK
;
834 decrypted
= decrypt_eapol_key_data(wt
, sta
->key_mgmt
,
835 sta
->ptk
.kek
, sta
->ptk
.kek_len
,
836 ver
, hdr
, &decrypted_len
);
837 if (decrypted
== NULL
) {
838 add_note(wt
, MSG_INFO
, "Failed to decrypt EAPOL-Key Key Data");
841 wpa_hexdump(MSG_DEBUG
, "Decrypted EAPOL-Key Key Data",
842 decrypted
, decrypted_len
);
843 if (wt
->write_pcap_dumper
|| wt
->pcapng
) {
844 /* Fill in a dummy Data frame header */
845 u8 buf
[24 + 8 + sizeof(*eapol
) + sizeof(*hdr
) + 64];
846 struct ieee80211_hdr
*h
;
847 struct wpa_eapol_key
*k
;
851 plain_len
= decrypted_len
;
853 while (pos
+ 1 < decrypted
+ decrypted_len
) {
854 if (pos
[0] == 0xdd && pos
[1] == 0x00) {
856 plain_len
= pos
- decrypted
;
862 os_memset(buf
, 0, sizeof(buf
));
863 h
= (struct ieee80211_hdr
*) buf
;
864 h
->frame_control
= host_to_le16(0x0208);
865 os_memcpy(h
->addr1
, dst
, ETH_ALEN
);
866 os_memcpy(h
->addr2
, src
, ETH_ALEN
);
867 os_memcpy(h
->addr3
, src
, ETH_ALEN
);
868 pos
= (u8
*) (h
+ 1);
869 os_memcpy(pos
, "\xaa\xaa\x03\x00\x00\x00\x88\x8e", 8);
871 os_memcpy(pos
, eapol
, sizeof(*eapol
));
872 pos
+= sizeof(*eapol
);
873 os_memcpy(pos
, hdr
, sizeof(*hdr
) + mic_len
);
874 k
= (struct wpa_eapol_key
*) pos
;
875 pos
+= sizeof(struct wpa_eapol_key
) + mic_len
;
876 WPA_PUT_BE16(k
->key_info
,
877 key_info
& ~WPA_KEY_INFO_ENCR_KEY_DATA
);
878 WPA_PUT_BE16(pos
, plain_len
);
879 write_pcap_decrypted(wt
, buf
, 24 + 8 + sizeof(*eapol
) +
880 sizeof(*hdr
) + mic_len
+ 2,
881 decrypted
, plain_len
);
883 if (sta
->proto
& WPA_PROTO_RSN
)
884 learn_kde_keys(wt
, bss
, sta
, decrypted
, decrypted_len
,
887 int klen
= bss
->group_cipher
== WPA_CIPHER_TKIP
? 32 : 16;
888 if (decrypted_len
== klen
) {
889 const u8
*rsc
= hdr
->key_rsc
;
891 id
= (key_info
& WPA_KEY_INFO_KEY_INDEX_MASK
) >>
892 WPA_KEY_INFO_KEY_INDEX_SHIFT
;
893 add_note(wt
, MSG_DEBUG
, "GTK key index %d", id
);
894 wpa_hexdump(MSG_DEBUG
, "GTK", decrypted
,
896 bss
->gtk_len
[id
] = decrypted_len
;
897 os_memcpy(bss
->gtk
[id
], decrypted
, decrypted_len
);
898 bss
->rsc
[id
][0] = rsc
[5];
899 bss
->rsc
[id
][1] = rsc
[4];
900 bss
->rsc
[id
][2] = rsc
[3];
901 bss
->rsc
[id
][3] = rsc
[2];
902 bss
->rsc
[id
][4] = rsc
[1];
903 bss
->rsc
[id
][5] = rsc
[0];
904 wpa_hexdump(MSG_DEBUG
, "RSC", bss
->rsc
[id
], 6);
906 add_note(wt
, MSG_INFO
, "Unexpected WPA Key Data length "
907 "in Group Key msg 1/2 from " MACSTR
,
915 static void rx_data_eapol_key_2_of_2(struct wlantest
*wt
, const u8
*dst
,
916 const u8
*src
, const u8
*data
, size_t len
)
918 struct wlantest_bss
*bss
;
919 struct wlantest_sta
*sta
;
920 const struct ieee802_1x_hdr
*eapol
;
921 const struct wpa_eapol_key
*hdr
;
924 wpa_printf(MSG_DEBUG
, "EAPOL-Key 2/2 " MACSTR
" -> " MACSTR
,
925 MAC2STR(src
), MAC2STR(dst
));
926 bss
= bss_get(wt
, dst
);
929 sta
= sta_get(bss
, src
);
933 eapol
= (const struct ieee802_1x_hdr
*) data
;
934 hdr
= (const struct wpa_eapol_key
*) (eapol
+ 1);
935 if (!is_zero(hdr
->key_rsc
, 8)) {
936 add_note(wt
, MSG_INFO
, "EAPOL-Key 2/2 from " MACSTR
" used "
937 "non-zero Key RSC", MAC2STR(src
));
939 key_info
= WPA_GET_BE16(hdr
->key_info
);
942 add_note(wt
, MSG_DEBUG
,
943 "No PTK known to process EAPOL-Key 2/2");
948 check_mic(sta
->ptk
.kck
, sta
->ptk
.kck_len
, sta
->key_mgmt
,
949 key_info
& WPA_KEY_INFO_TYPE_MASK
,
951 add_note(wt
, MSG_INFO
, "Mismatch in EAPOL-Key 2/2 MIC");
954 add_note(wt
, MSG_DEBUG
, "Valid MIC found in EAPOL-Key 2/2");
958 static void rx_data_eapol_key(struct wlantest
*wt
, const u8
*bssid
,
959 const u8
*sta_addr
, const u8
*dst
,
960 const u8
*src
, const u8
*data
, size_t len
,
963 const struct ieee802_1x_hdr
*eapol
;
964 const struct wpa_eapol_key
*hdr
;
966 u16 key_info
, key_length
, ver
, key_data_length
;
969 struct wlantest_bss
*bss
;
970 struct wlantest_sta
*sta
;
972 bss
= bss_get(wt
, bssid
);
974 sta
= sta_get(bss
, sta_addr
);
976 mic_len
= wpa_mic_len(sta
->key_mgmt
, PMK_LEN
);
979 eapol
= (const struct ieee802_1x_hdr
*) data
;
980 hdr
= (const struct wpa_eapol_key
*) (eapol
+ 1);
982 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key",
983 (const u8
*) hdr
, len
- sizeof(*eapol
));
984 if (len
< sizeof(*hdr
) + mic_len
+ 2) {
985 add_note(wt
, MSG_INFO
, "Too short EAPOL-Key frame from " MACSTR
,
989 mic
= (const u8
*) (hdr
+ 1);
991 if (hdr
->type
== EAPOL_KEY_TYPE_RC4
) {
992 /* TODO: EAPOL-Key RC4 for WEP */
993 wpa_printf(MSG_INFO
, "EAPOL-Key Descriptor Type RC4 from "
994 MACSTR
, MAC2STR(src
));
998 if (hdr
->type
!= EAPOL_KEY_TYPE_RSN
&&
999 hdr
->type
!= EAPOL_KEY_TYPE_WPA
) {
1000 wpa_printf(MSG_INFO
, "Unsupported EAPOL-Key Descriptor Type "
1001 "%u from " MACSTR
, hdr
->type
, MAC2STR(src
));
1005 key_info
= WPA_GET_BE16(hdr
->key_info
);
1006 key_length
= WPA_GET_BE16(hdr
->key_length
);
1007 key_data_length
= WPA_GET_BE16(mic
+ mic_len
);
1008 key_data
= mic
+ mic_len
+ 2;
1009 if (key_data
+ key_data_length
> data
+ len
) {
1010 add_note(wt
, MSG_INFO
, "Truncated EAPOL-Key from " MACSTR
,
1014 if (key_data
+ key_data_length
< data
+ len
) {
1015 wpa_hexdump(MSG_DEBUG
, "Extra data after EAPOL-Key Key Data "
1016 "field", key_data
+ key_data_length
,
1017 data
+ len
- key_data
- key_data_length
);
1021 ver
= key_info
& WPA_KEY_INFO_TYPE_MASK
;
1022 wpa_printf(MSG_DEBUG
, "EAPOL-Key ver=%u %c idx=%u%s%s%s%s%s%s%s%s "
1024 ver
, key_info
& WPA_KEY_INFO_KEY_TYPE
? 'P' : 'G',
1025 (key_info
& WPA_KEY_INFO_KEY_INDEX_MASK
) >>
1026 WPA_KEY_INFO_KEY_INDEX_SHIFT
,
1027 (key_info
& WPA_KEY_INFO_INSTALL
) ? " Install" : "",
1028 (key_info
& WPA_KEY_INFO_ACK
) ? " ACK" : "",
1029 (key_info
& WPA_KEY_INFO_MIC
) ? " MIC" : "",
1030 (key_info
& WPA_KEY_INFO_SECURE
) ? " Secure" : "",
1031 (key_info
& WPA_KEY_INFO_ERROR
) ? " Error" : "",
1032 (key_info
& WPA_KEY_INFO_REQUEST
) ? " Request" : "",
1033 (key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
) ? " Encr" : "",
1034 (key_info
& WPA_KEY_INFO_SMK_MESSAGE
) ? " SMK" : "",
1037 if (ver
!= WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
&&
1038 ver
!= WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
&&
1039 ver
!= WPA_KEY_INFO_TYPE_AES_128_CMAC
&&
1040 ver
!= WPA_KEY_INFO_TYPE_AKM_DEFINED
) {
1041 wpa_printf(MSG_INFO
, "Unsupported EAPOL-Key Key Descriptor "
1042 "Version %u from " MACSTR
, ver
, MAC2STR(src
));
1046 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Replay Counter",
1047 hdr
->replay_counter
, WPA_REPLAY_COUNTER_LEN
);
1048 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Nonce",
1049 hdr
->key_nonce
, WPA_NONCE_LEN
);
1050 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key IV",
1052 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key RSC",
1053 hdr
->key_rsc
, WPA_KEY_RSC_LEN
);
1054 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key MIC",
1056 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data",
1057 key_data
, key_data_length
);
1059 if (hdr
->type
== EAPOL_KEY_TYPE_RSN
&&
1060 (key_info
& (WPA_KEY_INFO_KEY_INDEX_MASK
| BIT(14) | BIT(15))) !=
1062 wpa_printf(MSG_INFO
, "RSN EAPOL-Key with non-zero reserved "
1063 "Key Info bits 0x%x from " MACSTR
,
1064 key_info
, MAC2STR(src
));
1067 if (hdr
->type
== EAPOL_KEY_TYPE_WPA
&&
1068 (key_info
& (WPA_KEY_INFO_ENCR_KEY_DATA
|
1069 WPA_KEY_INFO_SMK_MESSAGE
|BIT(14) | BIT(15))) != 0) {
1070 wpa_printf(MSG_INFO
, "WPA EAPOL-Key with non-zero reserved "
1071 "Key Info bits 0x%x from " MACSTR
,
1072 key_info
, MAC2STR(src
));
1075 if (key_length
> 32) {
1076 wpa_printf(MSG_INFO
, "EAPOL-Key with invalid Key Length %d "
1077 "from " MACSTR
, key_length
, MAC2STR(src
));
1080 if (ver
!= WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
&&
1081 !is_zero(hdr
->key_iv
, 16)) {
1082 wpa_printf(MSG_INFO
, "EAPOL-Key with non-zero Key IV "
1083 "(reserved with ver=%d) field from " MACSTR
,
1085 wpa_hexdump(MSG_INFO
, "EAPOL-Key Key IV (reserved)",
1089 if (!is_zero(hdr
->key_id
, 8)) {
1090 wpa_printf(MSG_INFO
, "EAPOL-Key with non-zero Key ID "
1091 "(reserved) field from " MACSTR
, MAC2STR(src
));
1092 wpa_hexdump(MSG_INFO
, "EAPOL-Key Key ID (reserved)",
1096 if (hdr
->key_rsc
[6] || hdr
->key_rsc
[7]) {
1097 wpa_printf(MSG_INFO
, "EAPOL-Key with non-zero Key RSC octets "
1098 "(last two are unused)" MACSTR
, MAC2STR(src
));
1101 if (key_info
& (WPA_KEY_INFO_ERROR
| WPA_KEY_INFO_REQUEST
))
1104 if (key_info
& WPA_KEY_INFO_SMK_MESSAGE
)
1107 if (key_info
& WPA_KEY_INFO_KEY_TYPE
) {
1108 /* 4-Way Handshake */
1109 switch (key_info
& (WPA_KEY_INFO_SECURE
|
1112 WPA_KEY_INFO_INSTALL
)) {
1113 case WPA_KEY_INFO_ACK
:
1114 rx_data_eapol_key_1_of_4(wt
, dst
, src
, data
, len
);
1116 case WPA_KEY_INFO_MIC
:
1117 if (key_data_length
== 0)
1118 rx_data_eapol_key_4_of_4(wt
, dst
, src
, data
,
1121 rx_data_eapol_key_2_of_4(wt
, dst
, src
, data
,
1124 case WPA_KEY_INFO_MIC
| WPA_KEY_INFO_ACK
|
1125 WPA_KEY_INFO_INSTALL
:
1126 /* WPA does not include Secure bit in 3/4 */
1127 rx_data_eapol_key_3_of_4(wt
, dst
, src
, data
, len
);
1129 case WPA_KEY_INFO_SECURE
| WPA_KEY_INFO_MIC
|
1130 WPA_KEY_INFO_ACK
| WPA_KEY_INFO_INSTALL
:
1131 case WPA_KEY_INFO_SECURE
|
1132 WPA_KEY_INFO_ACK
| WPA_KEY_INFO_INSTALL
:
1133 rx_data_eapol_key_3_of_4(wt
, dst
, src
, data
, len
);
1135 case WPA_KEY_INFO_SECURE
| WPA_KEY_INFO_MIC
:
1136 case WPA_KEY_INFO_SECURE
:
1137 if (key_data_length
== 0)
1138 rx_data_eapol_key_4_of_4(wt
, dst
, src
, data
,
1141 rx_data_eapol_key_2_of_4(wt
, dst
, src
, data
,
1145 wpa_printf(MSG_DEBUG
, "Unsupported EAPOL-Key frame");
1149 /* Group Key Handshake */
1150 switch (key_info
& (WPA_KEY_INFO_SECURE
|
1152 WPA_KEY_INFO_ACK
)) {
1153 case WPA_KEY_INFO_SECURE
| WPA_KEY_INFO_MIC
|
1155 case WPA_KEY_INFO_SECURE
| WPA_KEY_INFO_ACK
:
1156 rx_data_eapol_key_1_of_2(wt
, dst
, src
, data
, len
);
1158 case WPA_KEY_INFO_SECURE
| WPA_KEY_INFO_MIC
:
1159 case WPA_KEY_INFO_SECURE
:
1160 rx_data_eapol_key_2_of_2(wt
, dst
, src
, data
, len
);
1163 wpa_printf(MSG_DEBUG
, "Unsupported EAPOL-Key frame");
1170 void rx_data_eapol(struct wlantest
*wt
, const u8
*bssid
, const u8
*sta_addr
,
1171 const u8
*dst
, const u8
*src
,
1172 const u8
*data
, size_t len
, int prot
)
1174 const struct ieee802_1x_hdr
*hdr
;
1178 wpa_hexdump(MSG_EXCESSIVE
, "EAPOL", data
, len
);
1179 if (len
< sizeof(*hdr
)) {
1180 wpa_printf(MSG_INFO
, "Too short EAPOL frame from " MACSTR
,
1185 hdr
= (const struct ieee802_1x_hdr
*) data
;
1186 length
= be_to_host16(hdr
->length
);
1187 wpa_printf(MSG_DEBUG
, "RX EAPOL: " MACSTR
" -> " MACSTR
"%s ver=%u "
1189 MAC2STR(src
), MAC2STR(dst
), prot
? " Prot" : "",
1190 hdr
->version
, hdr
->type
, length
);
1191 if (hdr
->version
< 1 || hdr
->version
> 3) {
1192 wpa_printf(MSG_INFO
, "Unexpected EAPOL version %u from "
1193 MACSTR
, hdr
->version
, MAC2STR(src
));
1195 if (sizeof(*hdr
) + length
> len
) {
1196 wpa_printf(MSG_INFO
, "Truncated EAPOL frame from " MACSTR
,
1201 if (sizeof(*hdr
) + length
< len
) {
1202 wpa_printf(MSG_INFO
, "EAPOL frame with %d extra bytes",
1203 (int) (len
- sizeof(*hdr
) - length
));
1205 p
= (const u8
*) (hdr
+ 1);
1207 switch (hdr
->type
) {
1208 case IEEE802_1X_TYPE_EAP_PACKET
:
1209 wpa_hexdump(MSG_MSGDUMP
, "EAPOL - EAP packet", p
, length
);
1211 case IEEE802_1X_TYPE_EAPOL_START
:
1212 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Start", p
, length
);
1214 case IEEE802_1X_TYPE_EAPOL_LOGOFF
:
1215 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Logoff", p
, length
);
1217 case IEEE802_1X_TYPE_EAPOL_KEY
:
1218 rx_data_eapol_key(wt
, bssid
, sta_addr
, dst
, src
, data
,
1219 sizeof(*hdr
) + length
, prot
);
1221 case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT
:
1222 wpa_hexdump(MSG_MSGDUMP
, "EAPOL - Encapsulated ASF alert",
1226 wpa_hexdump(MSG_MSGDUMP
, "Unknown EAPOL payload", p
, length
);