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_r1_name
[WPA_PMK_NAME_LEN
];
105 u8 ptk_name
[WPA_PMK_NAME_LEN
];
107 if (wpa_derive_pmk_r0(pmk
->pmk
, PMK_LEN
,
108 bss
->ssid
, bss
->ssid_len
, bss
->mdid
,
109 bss
->r0kh_id
, bss
->r0kh_id_len
,
110 sta
->addr
, sta
->pmk_r0
, sta
->pmk_r0_name
,
113 wpa_hexdump(MSG_DEBUG
, "FT: PMK-R0", sta
->pmk_r0
, PMK_LEN
);
114 wpa_hexdump(MSG_DEBUG
, "FT: PMKR0Name", sta
->pmk_r0_name
,
116 if (wpa_derive_pmk_r1(sta
->pmk_r0
, PMK_LEN
, sta
->pmk_r0_name
,
117 bss
->r1kh_id
, sta
->addr
,
118 pmk_r1
, pmk_r1_name
) < 0)
120 wpa_hexdump_key(MSG_DEBUG
, "FT: PMK-R1", pmk_r1
, PMK_LEN
);
121 wpa_hexdump(MSG_DEBUG
, "FT: PMKR1Name", pmk_r1_name
,
123 if (wpa_pmk_r1_to_ptk(pmk_r1
, PMK_LEN
, sta
->snonce
, sta
->anonce
,
125 bss
->bssid
, pmk_r1_name
, &ptk
, ptk_name
,
127 sta
->pairwise_cipher
) < 0 ||
128 check_mic(ptk
.kck
, ptk
.kck_len
, sta
->key_mgmt
, ver
, data
,
131 } else if (wpa_pmk_to_ptk(pmk
->pmk
, PMK_LEN
,
132 "Pairwise key expansion",
133 bss
->bssid
, sta
->addr
, sta
->anonce
,
134 sta
->snonce
, &ptk
, sta
->key_mgmt
,
135 sta
->pairwise_cipher
, NULL
, 0) < 0 ||
136 check_mic(ptk
.kck
, ptk
.kck_len
, sta
->key_mgmt
, ver
, data
,
141 wpa_printf(MSG_INFO
, "Derived PTK for STA " MACSTR
" BSSID " MACSTR
,
142 MAC2STR(sta
->addr
), MAC2STR(bss
->bssid
));
143 sta
->counters
[WLANTEST_STA_COUNTER_PTK_LEARNED
]++;
146 * Rekeying - use new PTK for EAPOL-Key frames, but continue
147 * using the old PTK for frame decryption.
149 add_note(wt
, MSG_DEBUG
, "Derived PTK during rekeying");
150 os_memcpy(&sta
->tptk
, &ptk
, sizeof(ptk
));
151 wpa_hexdump(MSG_DEBUG
, "TPTK:KCK",
152 sta
->tptk
.kck
, sta
->tptk
.kck_len
);
153 wpa_hexdump(MSG_DEBUG
, "TPTK:KEK",
154 sta
->tptk
.kek
, sta
->tptk
.kek_len
);
155 wpa_hexdump(MSG_DEBUG
, "TPTK:TK",
156 sta
->tptk
.tk
, sta
->tptk
.tk_len
);
160 add_note(wt
, MSG_DEBUG
, "Derived new PTK");
161 os_memcpy(&sta
->ptk
, &ptk
, sizeof(ptk
));
162 wpa_hexdump(MSG_DEBUG
, "PTK:KCK", sta
->ptk
.kck
, sta
->ptk
.kck_len
);
163 wpa_hexdump(MSG_DEBUG
, "PTK:KEK", sta
->ptk
.kek
, sta
->ptk
.kek_len
);
164 wpa_hexdump(MSG_DEBUG
, "PTK:TK", sta
->ptk
.tk
, sta
->ptk
.tk_len
);
166 os_memset(sta
->rsc_tods
, 0, sizeof(sta
->rsc_tods
));
167 os_memset(sta
->rsc_fromds
, 0, sizeof(sta
->rsc_fromds
));
172 static void derive_ptk(struct wlantest
*wt
, struct wlantest_bss
*bss
,
173 struct wlantest_sta
*sta
, u16 ver
,
174 const u8
*data
, size_t len
)
176 struct wlantest_pmk
*pmk
;
178 wpa_printf(MSG_DEBUG
, "Trying to derive PTK for " MACSTR
" (ver %u)",
179 MAC2STR(sta
->addr
), ver
);
180 dl_list_for_each(pmk
, &bss
->pmk
, struct wlantest_pmk
, list
) {
181 wpa_printf(MSG_DEBUG
, "Try per-BSS PMK");
182 if (try_pmk(wt
, bss
, sta
, ver
, data
, len
, pmk
) == 0)
186 dl_list_for_each(pmk
, &wt
->pmk
, struct wlantest_pmk
, list
) {
187 wpa_printf(MSG_DEBUG
, "Try global PMK");
188 if (try_pmk(wt
, bss
, sta
, ver
, data
, len
, pmk
) == 0)
193 struct wlantest_ptk
*ptk
;
194 int prev_level
= wpa_debug_level
;
196 wpa_debug_level
= MSG_WARNING
;
197 dl_list_for_each(ptk
, &wt
->ptk
, struct wlantest_ptk
, list
) {
198 if (check_mic(ptk
->ptk
.kck
, ptk
->ptk
.kck_len
,
199 sta
->key_mgmt
, ver
, data
, len
) < 0)
201 wpa_printf(MSG_INFO
, "Pre-set PTK matches for STA "
202 MACSTR
" BSSID " MACSTR
,
203 MAC2STR(sta
->addr
), MAC2STR(bss
->bssid
));
204 add_note(wt
, MSG_DEBUG
, "Using pre-set PTK");
206 wpa_cipher_key_len(sta
->pairwise_cipher
);
207 os_memcpy(&sta
->ptk
, &ptk
->ptk
, sizeof(ptk
->ptk
));
208 wpa_hexdump(MSG_DEBUG
, "PTK:KCK",
209 sta
->ptk
.kck
, sta
->ptk
.kck_len
);
210 wpa_hexdump(MSG_DEBUG
, "PTK:KEK",
211 sta
->ptk
.kek
, sta
->ptk
.kek_len
);
212 wpa_hexdump(MSG_DEBUG
, "PTK:TK",
213 sta
->ptk
.tk
, sta
->ptk
.tk_len
);
215 os_memset(sta
->rsc_tods
, 0, sizeof(sta
->rsc_tods
));
216 os_memset(sta
->rsc_fromds
, 0, sizeof(sta
->rsc_fromds
));
218 wpa_debug_level
= prev_level
;
221 add_note(wt
, MSG_DEBUG
, "No matching PMK found to derive PTK");
225 static void rx_data_eapol_key_2_of_4(struct wlantest
*wt
, const u8
*dst
,
226 const u8
*src
, const u8
*data
, size_t len
)
228 struct wlantest_bss
*bss
;
229 struct wlantest_sta
*sta
;
230 const struct ieee802_1x_hdr
*eapol
;
231 const struct wpa_eapol_key
*hdr
;
232 const u8
*key_data
, *kck
, *mic
;
233 size_t kck_len
, mic_len
;
234 u16 key_info
, key_data_len
;
235 struct wpa_eapol_ie_parse ie
;
237 wpa_printf(MSG_DEBUG
, "EAPOL-Key 2/4 " MACSTR
" -> " MACSTR
,
238 MAC2STR(src
), MAC2STR(dst
));
239 bss
= bss_get(wt
, dst
);
242 sta
= sta_get(bss
, src
);
246 eapol
= (const struct ieee802_1x_hdr
*) data
;
247 hdr
= (const struct wpa_eapol_key
*) (eapol
+ 1);
248 mic_len
= wpa_mic_len(sta
->key_mgmt
, PMK_LEN
);
249 mic
= (const u8
*) (hdr
+ 1);
250 if (is_zero(hdr
->key_nonce
, WPA_NONCE_LEN
)) {
251 add_note(wt
, MSG_INFO
, "EAPOL-Key 2/4 from " MACSTR
252 " used zero nonce", MAC2STR(src
));
254 if (!is_zero(hdr
->key_rsc
, 8)) {
255 add_note(wt
, MSG_INFO
, "EAPOL-Key 2/4 from " MACSTR
256 " used non-zero Key RSC", MAC2STR(src
));
258 os_memcpy(sta
->snonce
, hdr
->key_nonce
, WPA_NONCE_LEN
);
259 key_info
= WPA_GET_BE16(hdr
->key_info
);
260 key_data_len
= WPA_GET_BE16(mic
+ mic_len
);
261 derive_ptk(wt
, bss
, sta
, key_info
& WPA_KEY_INFO_TYPE_MASK
, data
, len
);
263 if (!sta
->ptk_set
&& !sta
->tptk_set
) {
264 add_note(wt
, MSG_DEBUG
,
265 "No PTK known to process EAPOL-Key 2/4");
270 kck_len
= sta
->ptk
.kck_len
;
272 add_note(wt
, MSG_DEBUG
,
273 "Use TPTK for validation EAPOL-Key MIC");
275 kck_len
= sta
->tptk
.kck_len
;
277 if (check_mic(kck
, kck_len
, sta
->key_mgmt
,
278 key_info
& WPA_KEY_INFO_TYPE_MASK
, data
, len
) < 0) {
279 add_note(wt
, MSG_INFO
, "Mismatch in EAPOL-Key 2/4 MIC");
282 add_note(wt
, MSG_DEBUG
, "Valid MIC found in EAPOL-Key 2/4");
284 key_data
= mic
+ mic_len
+ 2;
286 if (wpa_supplicant_parse_ies(key_data
, key_data_len
, &ie
) < 0) {
287 add_note(wt
, MSG_INFO
, "Failed to parse EAPOL-Key Key Data");
292 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data - WPA IE",
293 ie
.wpa_ie
, ie
.wpa_ie_len
);
294 if (os_memcmp(ie
.wpa_ie
, sta
->rsnie
, ie
.wpa_ie_len
) != 0) {
295 struct ieee802_11_elems elems
;
296 add_note(wt
, MSG_INFO
,
297 "Mismatch in WPA IE between EAPOL-Key 2/4 "
298 "and (Re)Association Request from " MACSTR
,
300 wpa_hexdump(MSG_INFO
, "WPA IE in EAPOL-Key",
301 ie
.wpa_ie
, ie
.wpa_ie_len
);
302 wpa_hexdump(MSG_INFO
, "WPA IE in (Re)Association "
305 sta
->rsnie
[0] ? 2 + sta
->rsnie
[1] : 0);
307 * The sniffer may have missed (Re)Association
308 * Request, so try to survive with the information from
311 os_memset(&elems
, 0, sizeof(elems
));
312 elems
.wpa_ie
= ie
.wpa_ie
+ 2;
313 elems
.wpa_ie_len
= ie
.wpa_ie_len
- 2;
314 wpa_printf(MSG_DEBUG
, "Update STA data based on WPA "
315 "IE in EAPOL-Key 2/4");
316 sta_update_assoc(sta
, &elems
);
321 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data - RSN IE",
322 ie
.rsn_ie
, ie
.rsn_ie_len
);
323 if (os_memcmp(ie
.rsn_ie
, sta
->rsnie
, ie
.rsn_ie_len
) != 0) {
324 struct ieee802_11_elems elems
;
325 add_note(wt
, MSG_INFO
,
326 "Mismatch in RSN IE between EAPOL-Key 2/4 "
327 "and (Re)Association Request from " MACSTR
,
329 wpa_hexdump(MSG_INFO
, "RSN IE in EAPOL-Key",
330 ie
.rsn_ie
, ie
.rsn_ie_len
);
331 wpa_hexdump(MSG_INFO
, "RSN IE in (Re)Association "
334 sta
->rsnie
[0] ? 2 + sta
->rsnie
[1] : 0);
336 * The sniffer may have missed (Re)Association
337 * Request, so try to survive with the information from
340 os_memset(&elems
, 0, sizeof(elems
));
341 elems
.rsn_ie
= ie
.rsn_ie
+ 2;
342 elems
.rsn_ie_len
= ie
.rsn_ie_len
- 2;
343 wpa_printf(MSG_DEBUG
, "Update STA data based on RSN "
344 "IE in EAPOL-Key 2/4");
345 sta_update_assoc(sta
, &elems
);
351 static u8
* decrypt_eapol_key_data_rc4(struct wlantest
*wt
, const u8
*kek
,
352 const struct wpa_eapol_key
*hdr
,
353 const u8
*keydata
, u16 keydatalen
,
358 buf
= os_memdup(keydata
, keydatalen
);
362 os_memcpy(ek
, hdr
->key_iv
, 16);
363 os_memcpy(ek
+ 16, kek
, 16);
364 if (rc4_skip(ek
, 32, 256, buf
, keydatalen
)) {
365 add_note(wt
, MSG_INFO
, "RC4 failed");
375 static u8
* decrypt_eapol_key_data_aes(struct wlantest
*wt
, const u8
*kek
,
376 const struct wpa_eapol_key
*hdr
,
377 const u8
*keydata
, u16 keydatalen
,
382 if (keydatalen
% 8) {
383 add_note(wt
, MSG_INFO
, "Unsupported AES-WRAP len %d",
387 keydatalen
-= 8; /* AES-WRAP adds 8 bytes */
388 buf
= os_malloc(keydatalen
);
391 if (aes_unwrap(kek
, 16, keydatalen
/ 8, keydata
, buf
)) {
393 add_note(wt
, MSG_INFO
,
394 "AES unwrap failed - could not decrypt EAPOL-Key "
404 static u8
* decrypt_eapol_key_data(struct wlantest
*wt
, int akmp
, const u8
*kek
,
405 size_t kek_len
, u16 ver
,
406 const struct wpa_eapol_key
*hdr
,
411 const u8
*mic
, *keydata
;
416 mic
= (const u8
*) (hdr
+ 1);
417 mic_len
= wpa_mic_len(akmp
, PMK_LEN
);
418 keydata
= mic
+ mic_len
+ 2;
419 keydatalen
= WPA_GET_BE16(mic
+ mic_len
);
422 case WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
:
423 return decrypt_eapol_key_data_rc4(wt
, kek
, hdr
, keydata
,
425 case WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
:
426 case WPA_KEY_INFO_TYPE_AES_128_CMAC
:
427 return decrypt_eapol_key_data_aes(wt
, kek
, hdr
, keydata
,
429 case WPA_KEY_INFO_TYPE_AKM_DEFINED
:
430 /* For now, assume this is OSEN */
431 return decrypt_eapol_key_data_aes(wt
, kek
, hdr
, keydata
,
434 add_note(wt
, MSG_INFO
,
435 "Unsupported EAPOL-Key Key Descriptor Version %u",
442 static void learn_kde_keys(struct wlantest
*wt
, struct wlantest_bss
*bss
,
443 struct wlantest_sta
*sta
,
444 const u8
*buf
, size_t len
, const u8
*rsc
)
446 struct wpa_eapol_ie_parse ie
;
448 if (wpa_supplicant_parse_ies(buf
, len
, &ie
) < 0) {
449 add_note(wt
, MSG_INFO
, "Failed to parse EAPOL-Key Key Data");
454 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data - WPA IE",
455 ie
.wpa_ie
, ie
.wpa_ie_len
);
459 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data - RSN IE",
460 ie
.rsn_ie
, ie
.rsn_ie_len
);
464 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data - GTK KDE",
466 if (ie
.gtk_len
>= 2 && ie
.gtk_len
<= 2 + 32) {
468 id
= ie
.gtk
[0] & 0x03;
469 add_note(wt
, MSG_DEBUG
, "GTK KeyID=%u tx=%u",
470 id
, !!(ie
.gtk
[0] & 0x04));
471 if ((ie
.gtk
[0] & 0xf8) || ie
.gtk
[1]) {
472 add_note(wt
, MSG_INFO
,
473 "GTK KDE: Reserved field set: "
474 "%02x %02x", ie
.gtk
[0], ie
.gtk
[1]);
476 wpa_hexdump(MSG_DEBUG
, "GTK", ie
.gtk
+ 2,
478 bss
->gtk_len
[id
] = ie
.gtk_len
- 2;
479 sta
->gtk_len
= ie
.gtk_len
- 2;
480 os_memcpy(bss
->gtk
[id
], ie
.gtk
+ 2, ie
.gtk_len
- 2);
481 os_memcpy(sta
->gtk
, ie
.gtk
+ 2, ie
.gtk_len
- 2);
482 bss
->rsc
[id
][0] = rsc
[5];
483 bss
->rsc
[id
][1] = rsc
[4];
484 bss
->rsc
[id
][2] = rsc
[3];
485 bss
->rsc
[id
][3] = rsc
[2];
486 bss
->rsc
[id
][4] = rsc
[1];
487 bss
->rsc
[id
][5] = rsc
[0];
490 wpa_hexdump(MSG_DEBUG
, "RSC", bss
->rsc
[id
], 6);
492 add_note(wt
, MSG_INFO
, "Invalid GTK KDE length %u",
493 (unsigned) ie
.gtk_len
);
498 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data - IGTK KDE",
499 ie
.igtk
, ie
.igtk_len
);
500 if (ie
.igtk_len
== 24) {
502 id
= WPA_GET_LE16(ie
.igtk
);
504 add_note(wt
, MSG_INFO
,
505 "Unexpected IGTK KeyID %u", id
);
508 add_note(wt
, MSG_DEBUG
, "IGTK KeyID %u", id
);
509 wpa_hexdump(MSG_DEBUG
, "IPN", ie
.igtk
+ 2, 6);
510 wpa_hexdump(MSG_DEBUG
, "IGTK", ie
.igtk
+ 8,
512 os_memcpy(bss
->igtk
[id
], ie
.igtk
+ 8, 16);
513 bss
->igtk_len
[id
] = 16;
515 bss
->ipn
[id
][0] = ipn
[5];
516 bss
->ipn
[id
][1] = ipn
[4];
517 bss
->ipn
[id
][2] = ipn
[3];
518 bss
->ipn
[id
][3] = ipn
[2];
519 bss
->ipn
[id
][4] = ipn
[1];
520 bss
->ipn
[id
][5] = ipn
[0];
523 } else if (ie
.igtk_len
== 40) {
525 id
= WPA_GET_LE16(ie
.igtk
);
527 add_note(wt
, MSG_INFO
,
528 "Unexpected IGTK KeyID %u", id
);
531 add_note(wt
, MSG_DEBUG
, "IGTK KeyID %u", id
);
532 wpa_hexdump(MSG_DEBUG
, "IPN", ie
.igtk
+ 2, 6);
533 wpa_hexdump(MSG_DEBUG
, "IGTK", ie
.igtk
+ 8,
535 os_memcpy(bss
->igtk
[id
], ie
.igtk
+ 8, 32);
536 bss
->igtk_len
[id
] = 32;
538 bss
->ipn
[id
][0] = ipn
[5];
539 bss
->ipn
[id
][1] = ipn
[4];
540 bss
->ipn
[id
][2] = ipn
[3];
541 bss
->ipn
[id
][3] = ipn
[2];
542 bss
->ipn
[id
][4] = ipn
[1];
543 bss
->ipn
[id
][5] = ipn
[0];
547 add_note(wt
, MSG_INFO
, "Invalid IGTK KDE length %u",
548 (unsigned) ie
.igtk_len
);
554 static void rx_data_eapol_key_3_of_4(struct wlantest
*wt
, const u8
*dst
,
555 const u8
*src
, const u8
*data
, size_t len
)
557 struct wlantest_bss
*bss
;
558 struct wlantest_sta
*sta
;
559 const struct ieee802_1x_hdr
*eapol
;
560 const struct wpa_eapol_key
*hdr
;
561 const u8
*key_data
, *kck
, *kek
, *mic
;
562 size_t kck_len
, kek_len
, mic_len
;
565 u8
*decrypted_buf
= NULL
;
567 size_t decrypted_len
= 0;
568 struct wpa_eapol_ie_parse ie
;
570 wpa_printf(MSG_DEBUG
, "EAPOL-Key 3/4 " MACSTR
" -> " MACSTR
,
571 MAC2STR(src
), MAC2STR(dst
));
572 bss
= bss_get(wt
, src
);
575 sta
= sta_get(bss
, dst
);
578 mic_len
= wpa_mic_len(sta
->key_mgmt
, PMK_LEN
);
580 eapol
= (const struct ieee802_1x_hdr
*) data
;
581 hdr
= (const struct wpa_eapol_key
*) (eapol
+ 1);
582 mic
= (const u8
*) (hdr
+ 1);
583 key_info
= WPA_GET_BE16(hdr
->key_info
);
585 if (os_memcmp(sta
->anonce
, hdr
->key_nonce
, WPA_NONCE_LEN
) != 0) {
586 add_note(wt
, MSG_INFO
,
587 "EAPOL-Key ANonce mismatch between 1/4 and 3/4");
590 os_memcpy(sta
->anonce
, hdr
->key_nonce
, WPA_NONCE_LEN
);
592 derive_ptk(wt
, bss
, sta
, key_info
& WPA_KEY_INFO_TYPE_MASK
,
596 if (!sta
->ptk_set
&& !sta
->tptk_set
) {
597 add_note(wt
, MSG_DEBUG
,
598 "No PTK known to process EAPOL-Key 3/4");
603 kek_len
= sta
->ptk
.kek_len
;
605 kck_len
= sta
->ptk
.kck_len
;
607 add_note(wt
, MSG_DEBUG
,
608 "Use TPTK for validation EAPOL-Key MIC");
610 kck_len
= sta
->tptk
.kck_len
;
612 kek_len
= sta
->tptk
.kek_len
;
614 if (check_mic(kck
, kck_len
, sta
->key_mgmt
,
615 key_info
& WPA_KEY_INFO_TYPE_MASK
, data
, len
) < 0) {
616 add_note(wt
, MSG_INFO
, "Mismatch in EAPOL-Key 3/4 MIC");
619 add_note(wt
, MSG_DEBUG
, "Valid MIC found in EAPOL-Key 3/4");
621 key_data
= mic
+ mic_len
+ 2;
622 if (!(key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
)) {
623 if (sta
->proto
& WPA_PROTO_RSN
)
624 add_note(wt
, MSG_INFO
,
625 "EAPOL-Key 3/4 without EncrKeyData bit");
626 decrypted
= key_data
;
627 decrypted_len
= WPA_GET_BE16(mic
+ mic_len
);
629 ver
= key_info
& WPA_KEY_INFO_TYPE_MASK
;
630 decrypted_buf
= decrypt_eapol_key_data(wt
, sta
->key_mgmt
,
632 hdr
, &decrypted_len
);
633 if (decrypted_buf
== NULL
) {
634 add_note(wt
, MSG_INFO
,
635 "Failed to decrypt EAPOL-Key Key Data");
638 decrypted
= decrypted_buf
;
639 wpa_hexdump(MSG_DEBUG
, "Decrypted EAPOL-Key Key Data",
640 decrypted
, decrypted_len
);
642 if ((wt
->write_pcap_dumper
|| wt
->pcapng
) && decrypted
!= key_data
) {
643 /* Fill in a dummy Data frame header */
644 u8 buf
[24 + 8 + sizeof(*eapol
) + sizeof(*hdr
) + 64];
645 struct ieee80211_hdr
*h
;
646 struct wpa_eapol_key
*k
;
651 plain_len
= decrypted_len
;
653 while (p
+ 1 < decrypted
+ decrypted_len
) {
654 if (p
[0] == 0xdd && p
[1] == 0x00) {
656 plain_len
= p
- decrypted
;
662 if (p
&& p
> decrypted
&& *p
== 0xdd &&
663 p
+ 1 == decrypted
+ decrypted_len
) {
666 plain_len
= p
- decrypted
;
669 os_memset(buf
, 0, sizeof(buf
));
670 h
= (struct ieee80211_hdr
*) buf
;
671 h
->frame_control
= host_to_le16(0x0208);
672 os_memcpy(h
->addr1
, dst
, ETH_ALEN
);
673 os_memcpy(h
->addr2
, src
, ETH_ALEN
);
674 os_memcpy(h
->addr3
, src
, ETH_ALEN
);
675 pos
= (u8
*) (h
+ 1);
676 os_memcpy(pos
, "\xaa\xaa\x03\x00\x00\x00\x88\x8e", 8);
678 os_memcpy(pos
, eapol
, sizeof(*eapol
));
679 pos
+= sizeof(*eapol
);
680 os_memcpy(pos
, hdr
, sizeof(*hdr
) + mic_len
);
681 k
= (struct wpa_eapol_key
*) pos
;
682 pos
+= sizeof(struct wpa_eapol_key
) + mic_len
;
683 WPA_PUT_BE16(k
->key_info
,
684 key_info
& ~WPA_KEY_INFO_ENCR_KEY_DATA
);
685 WPA_PUT_BE16(pos
, plain_len
);
686 write_pcap_decrypted(wt
, buf
, 24 + 8 + sizeof(*eapol
) +
687 sizeof(*hdr
) + mic_len
+ 2,
688 decrypted
, plain_len
);
691 if (wpa_supplicant_parse_ies(decrypted
, decrypted_len
, &ie
) < 0) {
692 add_note(wt
, MSG_INFO
, "Failed to parse EAPOL-Key Key Data");
693 os_free(decrypted_buf
);
698 os_memcmp(ie
.wpa_ie
, bss
->wpaie
, ie
.wpa_ie_len
) != 0) ||
699 (ie
.wpa_ie
== NULL
&& bss
->wpaie
[0])) {
700 add_note(wt
, MSG_INFO
,
701 "Mismatch in WPA IE between EAPOL-Key 3/4 and "
702 "Beacon/Probe Response from " MACSTR
,
703 MAC2STR(bss
->bssid
));
704 wpa_hexdump(MSG_INFO
, "WPA IE in EAPOL-Key",
705 ie
.wpa_ie
, ie
.wpa_ie_len
);
706 wpa_hexdump(MSG_INFO
, "WPA IE in Beacon/Probe "
709 bss
->wpaie
[0] ? 2 + bss
->wpaie
[1] : 0);
713 os_memcmp(ie
.rsn_ie
, bss
->rsnie
, ie
.rsn_ie_len
) != 0) ||
714 (ie
.rsn_ie
== NULL
&& bss
->rsnie
[0])) {
715 add_note(wt
, MSG_INFO
, "Mismatch in RSN IE between EAPOL-Key "
716 "3/4 and Beacon/Probe Response from " MACSTR
,
717 MAC2STR(bss
->bssid
));
718 wpa_hexdump(MSG_INFO
, "RSN IE in EAPOL-Key",
719 ie
.rsn_ie
, ie
.rsn_ie_len
);
720 wpa_hexdump(MSG_INFO
, "RSN IE in Beacon/Probe Response",
722 bss
->rsnie
[0] ? 2 + bss
->rsnie
[1] : 0);
725 learn_kde_keys(wt
, bss
, sta
, decrypted
, decrypted_len
, hdr
->key_rsc
);
726 os_free(decrypted_buf
);
730 static void rx_data_eapol_key_4_of_4(struct wlantest
*wt
, const u8
*dst
,
731 const u8
*src
, const u8
*data
, size_t len
)
733 struct wlantest_bss
*bss
;
734 struct wlantest_sta
*sta
;
735 const struct ieee802_1x_hdr
*eapol
;
736 const struct wpa_eapol_key
*hdr
;
741 wpa_printf(MSG_DEBUG
, "EAPOL-Key 4/4 " MACSTR
" -> " MACSTR
,
742 MAC2STR(src
), MAC2STR(dst
));
743 bss
= bss_get(wt
, dst
);
746 sta
= sta_get(bss
, src
);
750 eapol
= (const struct ieee802_1x_hdr
*) data
;
751 hdr
= (const struct wpa_eapol_key
*) (eapol
+ 1);
752 if (!is_zero(hdr
->key_rsc
, 8)) {
753 add_note(wt
, MSG_INFO
, "EAPOL-Key 4/4 from " MACSTR
" used "
754 "non-zero Key RSC", MAC2STR(src
));
756 key_info
= WPA_GET_BE16(hdr
->key_info
);
758 if (!sta
->ptk_set
&& !sta
->tptk_set
) {
759 add_note(wt
, MSG_DEBUG
,
760 "No PTK known to process EAPOL-Key 4/4");
765 kck_len
= sta
->ptk
.kck_len
;
767 add_note(wt
, MSG_DEBUG
,
768 "Use TPTK for validation EAPOL-Key MIC");
770 kck_len
= sta
->tptk
.kck_len
;
772 if (check_mic(kck
, kck_len
, sta
->key_mgmt
,
773 key_info
& WPA_KEY_INFO_TYPE_MASK
, data
, len
) < 0) {
774 add_note(wt
, MSG_INFO
, "Mismatch in EAPOL-Key 4/4 MIC");
777 add_note(wt
, MSG_DEBUG
, "Valid MIC found in EAPOL-Key 4/4");
779 add_note(wt
, MSG_DEBUG
, "Update PTK (rekeying)");
780 os_memcpy(&sta
->ptk
, &sta
->tptk
, sizeof(sta
->ptk
));
783 os_memset(sta
->rsc_tods
, 0, sizeof(sta
->rsc_tods
));
784 os_memset(sta
->rsc_fromds
, 0, sizeof(sta
->rsc_fromds
));
789 static void rx_data_eapol_key_1_of_2(struct wlantest
*wt
, const u8
*dst
,
790 const u8
*src
, const u8
*data
, size_t len
)
792 struct wlantest_bss
*bss
;
793 struct wlantest_sta
*sta
;
794 const struct ieee802_1x_hdr
*eapol
;
795 const struct wpa_eapol_key
*hdr
;
798 size_t decrypted_len
= 0;
801 wpa_printf(MSG_DEBUG
, "EAPOL-Key 1/2 " MACSTR
" -> " MACSTR
,
802 MAC2STR(src
), MAC2STR(dst
));
803 bss
= bss_get(wt
, src
);
806 sta
= sta_get(bss
, dst
);
809 mic_len
= wpa_mic_len(sta
->key_mgmt
, PMK_LEN
);
811 eapol
= (const struct ieee802_1x_hdr
*) data
;
812 hdr
= (const struct wpa_eapol_key
*) (eapol
+ 1);
813 key_info
= WPA_GET_BE16(hdr
->key_info
);
816 add_note(wt
, MSG_DEBUG
,
817 "No PTK known to process EAPOL-Key 1/2");
822 check_mic(sta
->ptk
.kck
, sta
->ptk
.kck_len
, sta
->key_mgmt
,
823 key_info
& WPA_KEY_INFO_TYPE_MASK
,
825 add_note(wt
, MSG_INFO
, "Mismatch in EAPOL-Key 1/2 MIC");
828 add_note(wt
, MSG_DEBUG
, "Valid MIC found in EAPOL-Key 1/2");
830 if (sta
->proto
& WPA_PROTO_RSN
&&
831 !(key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
)) {
832 add_note(wt
, MSG_INFO
, "EAPOL-Key 1/2 without EncrKeyData bit");
835 ver
= key_info
& WPA_KEY_INFO_TYPE_MASK
;
836 decrypted
= decrypt_eapol_key_data(wt
, sta
->key_mgmt
,
837 sta
->ptk
.kek
, sta
->ptk
.kek_len
,
838 ver
, hdr
, &decrypted_len
);
839 if (decrypted
== NULL
) {
840 add_note(wt
, MSG_INFO
, "Failed to decrypt EAPOL-Key Key Data");
843 wpa_hexdump(MSG_DEBUG
, "Decrypted EAPOL-Key Key Data",
844 decrypted
, decrypted_len
);
845 if (wt
->write_pcap_dumper
|| wt
->pcapng
) {
846 /* Fill in a dummy Data frame header */
847 u8 buf
[24 + 8 + sizeof(*eapol
) + sizeof(*hdr
) + 64];
848 struct ieee80211_hdr
*h
;
849 struct wpa_eapol_key
*k
;
853 plain_len
= decrypted_len
;
855 while (pos
+ 1 < decrypted
+ decrypted_len
) {
856 if (pos
[0] == 0xdd && pos
[1] == 0x00) {
858 plain_len
= pos
- decrypted
;
864 os_memset(buf
, 0, sizeof(buf
));
865 h
= (struct ieee80211_hdr
*) buf
;
866 h
->frame_control
= host_to_le16(0x0208);
867 os_memcpy(h
->addr1
, dst
, ETH_ALEN
);
868 os_memcpy(h
->addr2
, src
, ETH_ALEN
);
869 os_memcpy(h
->addr3
, src
, ETH_ALEN
);
870 pos
= (u8
*) (h
+ 1);
871 os_memcpy(pos
, "\xaa\xaa\x03\x00\x00\x00\x88\x8e", 8);
873 os_memcpy(pos
, eapol
, sizeof(*eapol
));
874 pos
+= sizeof(*eapol
);
875 os_memcpy(pos
, hdr
, sizeof(*hdr
) + mic_len
);
876 k
= (struct wpa_eapol_key
*) pos
;
877 pos
+= sizeof(struct wpa_eapol_key
) + mic_len
;
878 WPA_PUT_BE16(k
->key_info
,
879 key_info
& ~WPA_KEY_INFO_ENCR_KEY_DATA
);
880 WPA_PUT_BE16(pos
, plain_len
);
881 write_pcap_decrypted(wt
, buf
, 24 + 8 + sizeof(*eapol
) +
882 sizeof(*hdr
) + mic_len
+ 2,
883 decrypted
, plain_len
);
885 if (sta
->proto
& WPA_PROTO_RSN
)
886 learn_kde_keys(wt
, bss
, sta
, decrypted
, decrypted_len
,
889 int klen
= bss
->group_cipher
== WPA_CIPHER_TKIP
? 32 : 16;
890 if (decrypted_len
== klen
) {
891 const u8
*rsc
= hdr
->key_rsc
;
893 id
= (key_info
& WPA_KEY_INFO_KEY_INDEX_MASK
) >>
894 WPA_KEY_INFO_KEY_INDEX_SHIFT
;
895 add_note(wt
, MSG_DEBUG
, "GTK key index %d", id
);
896 wpa_hexdump(MSG_DEBUG
, "GTK", decrypted
,
898 bss
->gtk_len
[id
] = decrypted_len
;
899 os_memcpy(bss
->gtk
[id
], decrypted
, decrypted_len
);
900 bss
->rsc
[id
][0] = rsc
[5];
901 bss
->rsc
[id
][1] = rsc
[4];
902 bss
->rsc
[id
][2] = rsc
[3];
903 bss
->rsc
[id
][3] = rsc
[2];
904 bss
->rsc
[id
][4] = rsc
[1];
905 bss
->rsc
[id
][5] = rsc
[0];
906 wpa_hexdump(MSG_DEBUG
, "RSC", bss
->rsc
[id
], 6);
908 add_note(wt
, MSG_INFO
, "Unexpected WPA Key Data length "
909 "in Group Key msg 1/2 from " MACSTR
,
917 static void rx_data_eapol_key_2_of_2(struct wlantest
*wt
, const u8
*dst
,
918 const u8
*src
, const u8
*data
, size_t len
)
920 struct wlantest_bss
*bss
;
921 struct wlantest_sta
*sta
;
922 const struct ieee802_1x_hdr
*eapol
;
923 const struct wpa_eapol_key
*hdr
;
926 wpa_printf(MSG_DEBUG
, "EAPOL-Key 2/2 " MACSTR
" -> " MACSTR
,
927 MAC2STR(src
), MAC2STR(dst
));
928 bss
= bss_get(wt
, dst
);
931 sta
= sta_get(bss
, src
);
935 eapol
= (const struct ieee802_1x_hdr
*) data
;
936 hdr
= (const struct wpa_eapol_key
*) (eapol
+ 1);
937 if (!is_zero(hdr
->key_rsc
, 8)) {
938 add_note(wt
, MSG_INFO
, "EAPOL-Key 2/2 from " MACSTR
" used "
939 "non-zero Key RSC", MAC2STR(src
));
941 key_info
= WPA_GET_BE16(hdr
->key_info
);
944 add_note(wt
, MSG_DEBUG
,
945 "No PTK known to process EAPOL-Key 2/2");
950 check_mic(sta
->ptk
.kck
, sta
->ptk
.kck_len
, sta
->key_mgmt
,
951 key_info
& WPA_KEY_INFO_TYPE_MASK
,
953 add_note(wt
, MSG_INFO
, "Mismatch in EAPOL-Key 2/2 MIC");
956 add_note(wt
, MSG_DEBUG
, "Valid MIC found in EAPOL-Key 2/2");
960 static void rx_data_eapol_key(struct wlantest
*wt
, const u8
*bssid
,
961 const u8
*sta_addr
, const u8
*dst
,
962 const u8
*src
, const u8
*data
, size_t len
,
965 const struct ieee802_1x_hdr
*eapol
;
966 const struct wpa_eapol_key
*hdr
;
968 u16 key_info
, key_length
, ver
, key_data_length
;
971 struct wlantest_bss
*bss
;
972 struct wlantest_sta
*sta
;
974 bss
= bss_get(wt
, bssid
);
976 sta
= sta_get(bss
, sta_addr
);
978 mic_len
= wpa_mic_len(sta
->key_mgmt
, PMK_LEN
);
981 eapol
= (const struct ieee802_1x_hdr
*) data
;
982 hdr
= (const struct wpa_eapol_key
*) (eapol
+ 1);
984 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key",
985 (const u8
*) hdr
, len
- sizeof(*eapol
));
986 if (len
< sizeof(*hdr
) + mic_len
+ 2) {
987 add_note(wt
, MSG_INFO
, "Too short EAPOL-Key frame from " MACSTR
,
991 mic
= (const u8
*) (hdr
+ 1);
993 if (hdr
->type
== EAPOL_KEY_TYPE_RC4
) {
994 /* TODO: EAPOL-Key RC4 for WEP */
995 wpa_printf(MSG_INFO
, "EAPOL-Key Descriptor Type RC4 from "
996 MACSTR
, MAC2STR(src
));
1000 if (hdr
->type
!= EAPOL_KEY_TYPE_RSN
&&
1001 hdr
->type
!= EAPOL_KEY_TYPE_WPA
) {
1002 wpa_printf(MSG_INFO
, "Unsupported EAPOL-Key Descriptor Type "
1003 "%u from " MACSTR
, hdr
->type
, MAC2STR(src
));
1007 key_info
= WPA_GET_BE16(hdr
->key_info
);
1008 key_length
= WPA_GET_BE16(hdr
->key_length
);
1009 key_data_length
= WPA_GET_BE16(mic
+ mic_len
);
1010 key_data
= mic
+ mic_len
+ 2;
1011 if (key_data
+ key_data_length
> data
+ len
) {
1012 add_note(wt
, MSG_INFO
, "Truncated EAPOL-Key from " MACSTR
,
1016 if (key_data
+ key_data_length
< data
+ len
) {
1017 wpa_hexdump(MSG_DEBUG
, "Extra data after EAPOL-Key Key Data "
1018 "field", key_data
+ key_data_length
,
1019 data
+ len
- key_data
- key_data_length
);
1023 ver
= key_info
& WPA_KEY_INFO_TYPE_MASK
;
1024 wpa_printf(MSG_DEBUG
, "EAPOL-Key ver=%u %c idx=%u%s%s%s%s%s%s%s%s "
1026 ver
, key_info
& WPA_KEY_INFO_KEY_TYPE
? 'P' : 'G',
1027 (key_info
& WPA_KEY_INFO_KEY_INDEX_MASK
) >>
1028 WPA_KEY_INFO_KEY_INDEX_SHIFT
,
1029 (key_info
& WPA_KEY_INFO_INSTALL
) ? " Install" : "",
1030 (key_info
& WPA_KEY_INFO_ACK
) ? " ACK" : "",
1031 (key_info
& WPA_KEY_INFO_MIC
) ? " MIC" : "",
1032 (key_info
& WPA_KEY_INFO_SECURE
) ? " Secure" : "",
1033 (key_info
& WPA_KEY_INFO_ERROR
) ? " Error" : "",
1034 (key_info
& WPA_KEY_INFO_REQUEST
) ? " Request" : "",
1035 (key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
) ? " Encr" : "",
1036 (key_info
& WPA_KEY_INFO_SMK_MESSAGE
) ? " SMK" : "",
1039 if (ver
!= WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
&&
1040 ver
!= WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
&&
1041 ver
!= WPA_KEY_INFO_TYPE_AES_128_CMAC
&&
1042 ver
!= WPA_KEY_INFO_TYPE_AKM_DEFINED
) {
1043 wpa_printf(MSG_INFO
, "Unsupported EAPOL-Key Key Descriptor "
1044 "Version %u from " MACSTR
, ver
, MAC2STR(src
));
1048 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Replay Counter",
1049 hdr
->replay_counter
, WPA_REPLAY_COUNTER_LEN
);
1050 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Nonce",
1051 hdr
->key_nonce
, WPA_NONCE_LEN
);
1052 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key IV",
1054 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key RSC",
1055 hdr
->key_rsc
, WPA_KEY_RSC_LEN
);
1056 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key MIC",
1058 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Key Key Data",
1059 key_data
, key_data_length
);
1061 if (hdr
->type
== EAPOL_KEY_TYPE_RSN
&&
1062 (key_info
& (WPA_KEY_INFO_KEY_INDEX_MASK
| BIT(14) | BIT(15))) !=
1064 wpa_printf(MSG_INFO
, "RSN EAPOL-Key with non-zero reserved "
1065 "Key Info bits 0x%x from " MACSTR
,
1066 key_info
, MAC2STR(src
));
1069 if (hdr
->type
== EAPOL_KEY_TYPE_WPA
&&
1070 (key_info
& (WPA_KEY_INFO_ENCR_KEY_DATA
|
1071 WPA_KEY_INFO_SMK_MESSAGE
|BIT(14) | BIT(15))) != 0) {
1072 wpa_printf(MSG_INFO
, "WPA EAPOL-Key with non-zero reserved "
1073 "Key Info bits 0x%x from " MACSTR
,
1074 key_info
, MAC2STR(src
));
1077 if (key_length
> 32) {
1078 wpa_printf(MSG_INFO
, "EAPOL-Key with invalid Key Length %d "
1079 "from " MACSTR
, key_length
, MAC2STR(src
));
1082 if (ver
!= WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
&&
1083 !is_zero(hdr
->key_iv
, 16)) {
1084 wpa_printf(MSG_INFO
, "EAPOL-Key with non-zero Key IV "
1085 "(reserved with ver=%d) field from " MACSTR
,
1087 wpa_hexdump(MSG_INFO
, "EAPOL-Key Key IV (reserved)",
1091 if (!is_zero(hdr
->key_id
, 8)) {
1092 wpa_printf(MSG_INFO
, "EAPOL-Key with non-zero Key ID "
1093 "(reserved) field from " MACSTR
, MAC2STR(src
));
1094 wpa_hexdump(MSG_INFO
, "EAPOL-Key Key ID (reserved)",
1098 if (hdr
->key_rsc
[6] || hdr
->key_rsc
[7]) {
1099 wpa_printf(MSG_INFO
, "EAPOL-Key with non-zero Key RSC octets "
1100 "(last two are unused)" MACSTR
, MAC2STR(src
));
1103 if (key_info
& (WPA_KEY_INFO_ERROR
| WPA_KEY_INFO_REQUEST
))
1106 if (key_info
& WPA_KEY_INFO_SMK_MESSAGE
)
1109 if (key_info
& WPA_KEY_INFO_KEY_TYPE
) {
1110 /* 4-Way Handshake */
1111 switch (key_info
& (WPA_KEY_INFO_SECURE
|
1114 WPA_KEY_INFO_INSTALL
)) {
1115 case WPA_KEY_INFO_ACK
:
1116 rx_data_eapol_key_1_of_4(wt
, dst
, src
, data
, len
);
1118 case WPA_KEY_INFO_MIC
:
1119 if (key_data_length
== 0)
1120 rx_data_eapol_key_4_of_4(wt
, dst
, src
, data
,
1123 rx_data_eapol_key_2_of_4(wt
, dst
, src
, data
,
1126 case WPA_KEY_INFO_MIC
| WPA_KEY_INFO_ACK
|
1127 WPA_KEY_INFO_INSTALL
:
1128 /* WPA does not include Secure bit in 3/4 */
1129 rx_data_eapol_key_3_of_4(wt
, dst
, src
, data
, len
);
1131 case WPA_KEY_INFO_SECURE
| WPA_KEY_INFO_MIC
|
1132 WPA_KEY_INFO_ACK
| WPA_KEY_INFO_INSTALL
:
1133 case WPA_KEY_INFO_SECURE
|
1134 WPA_KEY_INFO_ACK
| WPA_KEY_INFO_INSTALL
:
1135 rx_data_eapol_key_3_of_4(wt
, dst
, src
, data
, len
);
1137 case WPA_KEY_INFO_SECURE
| WPA_KEY_INFO_MIC
:
1138 case WPA_KEY_INFO_SECURE
:
1139 if (key_data_length
== 0)
1140 rx_data_eapol_key_4_of_4(wt
, dst
, src
, data
,
1143 rx_data_eapol_key_2_of_4(wt
, dst
, src
, data
,
1147 wpa_printf(MSG_DEBUG
, "Unsupported EAPOL-Key frame");
1151 /* Group Key Handshake */
1152 switch (key_info
& (WPA_KEY_INFO_SECURE
|
1154 WPA_KEY_INFO_ACK
)) {
1155 case WPA_KEY_INFO_SECURE
| WPA_KEY_INFO_MIC
|
1157 case WPA_KEY_INFO_SECURE
| WPA_KEY_INFO_ACK
:
1158 rx_data_eapol_key_1_of_2(wt
, dst
, src
, data
, len
);
1160 case WPA_KEY_INFO_SECURE
| WPA_KEY_INFO_MIC
:
1161 case WPA_KEY_INFO_SECURE
:
1162 rx_data_eapol_key_2_of_2(wt
, dst
, src
, data
, len
);
1165 wpa_printf(MSG_DEBUG
, "Unsupported EAPOL-Key frame");
1172 void rx_data_eapol(struct wlantest
*wt
, const u8
*bssid
, const u8
*sta_addr
,
1173 const u8
*dst
, const u8
*src
,
1174 const u8
*data
, size_t len
, int prot
)
1176 const struct ieee802_1x_hdr
*hdr
;
1180 wpa_hexdump(MSG_EXCESSIVE
, "EAPOL", data
, len
);
1181 if (len
< sizeof(*hdr
)) {
1182 wpa_printf(MSG_INFO
, "Too short EAPOL frame from " MACSTR
,
1187 hdr
= (const struct ieee802_1x_hdr
*) data
;
1188 length
= be_to_host16(hdr
->length
);
1189 wpa_printf(MSG_DEBUG
, "RX EAPOL: " MACSTR
" -> " MACSTR
"%s ver=%u "
1191 MAC2STR(src
), MAC2STR(dst
), prot
? " Prot" : "",
1192 hdr
->version
, hdr
->type
, length
);
1193 if (hdr
->version
< 1 || hdr
->version
> 3) {
1194 wpa_printf(MSG_INFO
, "Unexpected EAPOL version %u from "
1195 MACSTR
, hdr
->version
, MAC2STR(src
));
1197 if (sizeof(*hdr
) + length
> len
) {
1198 wpa_printf(MSG_INFO
, "Truncated EAPOL frame from " MACSTR
,
1203 if (sizeof(*hdr
) + length
< len
) {
1204 wpa_printf(MSG_INFO
, "EAPOL frame with %d extra bytes",
1205 (int) (len
- sizeof(*hdr
) - length
));
1207 p
= (const u8
*) (hdr
+ 1);
1209 switch (hdr
->type
) {
1210 case IEEE802_1X_TYPE_EAP_PACKET
:
1211 wpa_hexdump(MSG_MSGDUMP
, "EAPOL - EAP packet", p
, length
);
1213 case IEEE802_1X_TYPE_EAPOL_START
:
1214 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Start", p
, length
);
1216 case IEEE802_1X_TYPE_EAPOL_LOGOFF
:
1217 wpa_hexdump(MSG_MSGDUMP
, "EAPOL-Logoff", p
, length
);
1219 case IEEE802_1X_TYPE_EAPOL_KEY
:
1220 rx_data_eapol_key(wt
, bssid
, sta_addr
, dst
, src
, data
,
1221 sizeof(*hdr
) + length
, prot
);
1223 case IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT
:
1224 wpa_hexdump(MSG_MSGDUMP
, "EAPOL - Encapsulated ASF alert",
1228 wpa_hexdump(MSG_MSGDUMP
, "Unknown EAPOL payload", p
, length
);