2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * Copyright (c) 2003-2004, Jouni Malinen <jkmaline@cc.hut.fi>
8 * Sun elects to license this software under the BSD license.
9 * See README for more details.
16 #include <netinet/in.h>
17 #include <sys/ethernet.h>
25 #include "l2_packet.h"
27 static void pmksa_cache_set_expiration(struct wpa_supplicant
*);
32 static const int WPA_SELECTOR_LEN
= 4;
33 static const uint8_t WPA_OUI_AND_TYPE
[] = { 0x00, 0x50, 0xf2, 1 };
35 WPA_AUTH_KEY_MGMT_UNSPEC_802_1X
[] = { 0x00, 0x50, 0xf2, 1 };
37 WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X
[] = { 0x00, 0x50, 0xf2, 2 };
38 static const uint8_t WPA_CIPHER_SUITE_NONE
[] = { 0x00, 0x50, 0xf2, 0 };
39 static const uint8_t WPA_CIPHER_SUITE_WEP40
[] = { 0x00, 0x50, 0xf2, 1 };
40 static const uint8_t WPA_CIPHER_SUITE_TKIP
[] = { 0x00, 0x50, 0xf2, 2 };
41 static const uint8_t WPA_CIPHER_SUITE_CCMP
[] = { 0x00, 0x50, 0xf2, 4 };
42 static const uint8_t WPA_CIPHER_SUITE_WEP104
[] = { 0x00, 0x50, 0xf2, 5 };
46 * 00-50-f2:1 (OUI:OUI type)
47 * 0x01 0x00 (version; little endian)
48 * (all following fields are optional:)
49 * Group Suite Selector (4 octets) (default: TKIP)
50 * Pairwise Suite Count (2 octets, little endian) (default: 1)
51 * Pairwise Suite List (4 * n octets) (default: TKIP)
52 * Authenticated Key Management Suite Count (2 octets, little endian)
54 * Authenticated Key Management Suite List (4 * n octets)
55 * (default: unspec 802.1x)
56 * WPA Capabilities (2 octets, little endian) (default: 0)
71 static const int RSN_SELECTOR_LEN
= 4;
72 static const uint16_t RSN_VERSION
= 1;
74 RSN_AUTH_KEY_MGMT_UNSPEC_802_1X
[] = { 0x00, 0x0f, 0xac, 1 };
76 RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X
[] = { 0x00, 0x0f, 0xac, 2 };
77 static const uint8_t RSN_CIPHER_SUITE_NONE
[] = { 0x00, 0x0f, 0xac, 0 };
78 static const uint8_t RSN_CIPHER_SUITE_WEP40
[] = { 0x00, 0x0f, 0xac, 1 };
79 static const uint8_t RSN_CIPHER_SUITE_TKIP
[] = { 0x00, 0x0f, 0xac, 2 };
80 static const uint8_t RSN_CIPHER_SUITE_CCMP
[] = { 0x00, 0x0f, 0xac, 4 };
81 static const uint8_t RSN_CIPHER_SUITE_WEP104
[] = { 0x00, 0x0f, 0xac, 5 };
84 * EAPOL-Key Key Data Encapsulation
85 * GroupKey and STAKey require encryption, otherwise, encryption is optional.
87 static const uint8_t RSN_KEY_DATA_GROUPKEY
[] = { 0x00, 0x0f, 0xac, 1 };
88 static const uint8_t RSN_KEY_DATA_PMKID
[] = { 0x00, 0x0f, 0xac, 4 };
93 * 3/4: one or two RSN IEs + GTK IE (encrypted)
95 * 1/2: GTK IE (encrypted)
101 * 0x01 0x00 (version; little endian)
102 * (all following fields are optional:)
103 * Group Suite Selector (4 octets) (default: CCMP)
104 * Pairwise Suite Count (2 octets, little endian) (default: 1)
105 * Pairwise Suite List (4 * n octets) (default: CCMP)
106 * Authenticated Key Management Suite Count (2 octets, little endian)
108 * Authenticated Key Management Suite List (4 * n octets)
109 * (default: unspec 802.1x)
110 * RSN Capabilities (2 octets, little endian) (default: 0)
111 * PMKID Count (2 octets) (default: 0)
112 * PMKID List (16 * n octets)
116 uint8_t elem_id
; /* WLAN_EID_RSN */
123 random_get_pseudo_bytes(uint8_t *ptr
, size_t len
)
129 fd
= open("/dev/urandom", O_RDONLY
);
131 wpa_printf(MSG_ERROR
, "Could not open /dev/urandom.\n");
136 bytes
= read(fd
, ptr
, resid
);
147 inc_byte_array(uint8_t *counter
, size_t len
)
152 if (counter
[pos
] != 0)
159 wpa_selector_to_bitfield(uint8_t *s
)
161 if (memcmp(s
, WPA_CIPHER_SUITE_NONE
, WPA_SELECTOR_LEN
) == 0)
162 return (WPA_CIPHER_NONE
);
163 if (memcmp(s
, WPA_CIPHER_SUITE_WEP40
, WPA_SELECTOR_LEN
) == 0)
164 return (WPA_CIPHER_WEP40
);
165 if (memcmp(s
, WPA_CIPHER_SUITE_TKIP
, WPA_SELECTOR_LEN
) == 0)
166 return (WPA_CIPHER_TKIP
);
167 if (memcmp(s
, WPA_CIPHER_SUITE_CCMP
, WPA_SELECTOR_LEN
) == 0)
168 return (WPA_CIPHER_CCMP
);
169 if (memcmp(s
, WPA_CIPHER_SUITE_WEP104
, WPA_SELECTOR_LEN
) == 0)
170 return (WPA_CIPHER_WEP104
);
175 wpa_key_mgmt_to_bitfield(uint8_t *s
)
177 if (memcmp(s
, WPA_AUTH_KEY_MGMT_UNSPEC_802_1X
, WPA_SELECTOR_LEN
) == 0)
178 return (WPA_KEY_MGMT_IEEE8021X
);
179 if (memcmp(s
, WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X
, WPA_SELECTOR_LEN
) ==
181 return (WPA_KEY_MGMT_PSK
);
186 rsn_selector_to_bitfield(uint8_t *s
)
188 if (memcmp(s
, RSN_CIPHER_SUITE_NONE
, RSN_SELECTOR_LEN
) == 0)
189 return (WPA_CIPHER_NONE
);
190 if (memcmp(s
, RSN_CIPHER_SUITE_WEP40
, RSN_SELECTOR_LEN
) == 0)
191 return (WPA_CIPHER_WEP40
);
192 if (memcmp(s
, RSN_CIPHER_SUITE_TKIP
, RSN_SELECTOR_LEN
) == 0)
193 return (WPA_CIPHER_TKIP
);
194 if (memcmp(s
, RSN_CIPHER_SUITE_CCMP
, RSN_SELECTOR_LEN
) == 0)
195 return (WPA_CIPHER_CCMP
);
196 if (memcmp(s
, RSN_CIPHER_SUITE_WEP104
, RSN_SELECTOR_LEN
) == 0)
197 return (WPA_CIPHER_WEP104
);
202 rsn_key_mgmt_to_bitfield(uint8_t *s
)
204 if (memcmp(s
, RSN_AUTH_KEY_MGMT_UNSPEC_802_1X
, RSN_SELECTOR_LEN
) == 0)
205 return (WPA_KEY_MGMT_IEEE8021X
);
206 if (memcmp(s
, RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X
, RSN_SELECTOR_LEN
) ==
208 return (WPA_KEY_MGMT_PSK
);
213 pmksa_cache_free_entry(struct wpa_supplicant
*wpa_s
,
214 struct rsn_pmksa_cache
*entry
)
216 wpa_s
->pmksa_count
--;
217 if (wpa_s
->cur_pmksa
== entry
) {
218 wpa_printf(MSG_DEBUG
, "RSN: removed current PMKSA entry");
219 wpa_s
->cur_pmksa
= NULL
;
226 pmksa_cache_expire(void *eloop_ctx
, void *timeout_ctx
)
228 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
232 while (wpa_s
->pmksa
&& wpa_s
->pmksa
->expiration
<= now
) {
233 struct rsn_pmksa_cache
*entry
= wpa_s
->pmksa
;
234 wpa_s
->pmksa
= entry
->next
;
235 wpa_printf(MSG_DEBUG
, "RSN: expired PMKSA cache entry for "
236 MACSTR
, MAC2STR(entry
->aa
));
237 pmksa_cache_free_entry(wpa_s
, entry
);
240 pmksa_cache_set_expiration(wpa_s
);
244 pmksa_cache_set_expiration(struct wpa_supplicant
*wpa_s
)
247 eloop_cancel_timeout(pmksa_cache_expire
, wpa_s
, NULL
);
248 if (wpa_s
->pmksa
== NULL
)
250 sec
= wpa_s
->pmksa
->expiration
- time(NULL
);
253 (void) eloop_register_timeout(sec
+ 1, 0, pmksa_cache_expire
,
258 pmksa_cache_free(struct wpa_supplicant
*wpa_s
)
260 struct rsn_pmksa_cache
*entry
, *prev
;
262 entry
= wpa_s
->pmksa
;
269 pmksa_cache_set_expiration(wpa_s
);
270 wpa_s
->cur_pmksa
= NULL
;
273 struct rsn_pmksa_cache
*
274 pmksa_cache_get(struct wpa_supplicant
*wpa_s
,
275 uint8_t *aa
, uint8_t *pmkid
)
277 struct rsn_pmksa_cache
*entry
= wpa_s
->pmksa
;
280 memcmp(entry
->aa
, aa
, IEEE80211_ADDR_LEN
) == 0) &&
282 memcmp(entry
->pmkid
, pmkid
, PMKID_LEN
) == 0))
290 pmksa_cache_list(struct wpa_supplicant
*wpa_s
, char *buf
, size_t len
)
294 struct rsn_pmksa_cache
*entry
;
298 pos
+= snprintf(pos
, buf
+ len
- pos
,
299 "Index / AA / PMKID / expiration (in seconds)\n");
301 entry
= wpa_s
->pmksa
;
304 pos
+= snprintf(pos
, buf
+ len
- pos
, "%d " MACSTR
" ",
305 i
, MAC2STR(entry
->aa
));
306 for (j
= 0; j
< PMKID_LEN
; j
++)
307 pos
+= snprintf(pos
, buf
+ len
- pos
, "%02x",
309 pos
+= snprintf(pos
, buf
+ len
- pos
, " %d\n",
310 (int)(entry
->expiration
- now
));
317 pmksa_candidate_free(struct wpa_supplicant
*wpa_s
)
319 struct rsn_pmksa_candidate
*entry
, *prev
;
321 entry
= wpa_s
->pmksa_candidates
;
322 wpa_s
->pmksa_candidates
= NULL
;
332 wpa_parse_wpa_ie_wpa(struct wpa_supplicant
*wpa_s
, uint8_t *wpa_ie
,
333 size_t wpa_ie_len
, struct wpa_ie_data
*data
)
335 struct wpa_ie_hdr
*hdr
;
340 data
->proto
= WPA_PROTO_WPA
;
341 data
->pairwise_cipher
= WPA_CIPHER_TKIP
;
342 data
->group_cipher
= WPA_CIPHER_TKIP
;
343 data
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
344 data
->capabilities
= 0;
346 if (wpa_ie_len
== 0) {
347 /* No WPA IE - fail silently */
351 if (wpa_ie_len
< sizeof (struct wpa_ie_hdr
)) {
352 wpa_printf(MSG_DEBUG
, "%s: ie len too short %u",
353 "wpa_parse_wpa_ie_wpa", wpa_ie_len
);
357 hdr
= (struct wpa_ie_hdr
*)wpa_ie
;
359 if (hdr
->elem_id
!= GENERIC_INFO_ELEM
||
360 hdr
->len
!= wpa_ie_len
- 2 ||
361 memcmp(&hdr
->oui
, WPA_OUI_AND_TYPE
, WPA_SELECTOR_LEN
) != 0 ||
362 LE_16(hdr
->version
) != WPA_VERSION
) {
363 wpa_printf(MSG_DEBUG
, "%s: malformed ie or unknown version",
364 "wpa_parse_wpa_ie_wpa");
368 pos
= (uint8_t *)(hdr
+ 1);
369 left
= wpa_ie_len
- sizeof (*hdr
);
371 if (left
>= WPA_SELECTOR_LEN
) {
372 data
->group_cipher
= wpa_selector_to_bitfield(pos
);
373 pos
+= WPA_SELECTOR_LEN
;
374 left
-= WPA_SELECTOR_LEN
;
375 } else if (left
> 0) {
376 wpa_printf(MSG_DEBUG
, "%s: ie length mismatch, %u too much",
377 "wpa_parse_wpa_ie_wpa", left
);
382 data
->pairwise_cipher
= 0;
383 count
= pos
[0] | (pos
[1] << 8);
386 if (count
== 0 || left
< count
* WPA_SELECTOR_LEN
) {
387 wpa_printf(MSG_DEBUG
, "%s: ie count botch (pairwise), "
389 "wpa_parse_wpa_ie_wpa", count
, left
);
392 for (i
= 0; i
< count
; i
++) {
393 data
->pairwise_cipher
|= wpa_selector_to_bitfield(pos
);
394 pos
+= WPA_SELECTOR_LEN
;
395 left
-= WPA_SELECTOR_LEN
;
397 } else if (left
== 1) {
398 wpa_printf(MSG_DEBUG
, "%s: ie too short (for key mgmt)",
399 "wpa_parse_wpa_ie_wpa");
405 count
= pos
[0] | (pos
[1] << 8);
408 if (count
== 0 || left
< count
* WPA_SELECTOR_LEN
) {
409 wpa_printf(MSG_DEBUG
, "%s: ie count botch (key mgmt), "
411 "wpa_parse_wpa_ie_wpa", count
, left
);
414 for (i
= 0; i
< count
; i
++) {
415 data
->key_mgmt
|= wpa_key_mgmt_to_bitfield(pos
);
416 pos
+= WPA_SELECTOR_LEN
;
417 left
-= WPA_SELECTOR_LEN
;
419 } else if (left
== 1) {
420 wpa_printf(MSG_DEBUG
, "%s: ie too short (for capabilities)",
421 "wpa_parse_wpa_ie_wpa");
426 data
->capabilities
= pos
[0] | (pos
[1] << 8);
432 wpa_printf(MSG_DEBUG
, "%s: ie has %u trailing bytes",
433 "wpa_parse_wpa_ie_wpa", left
);
442 wpa_parse_wpa_ie_rsn(struct wpa_supplicant
*wpa_s
, uint8_t *rsn_ie
,
443 size_t rsn_ie_len
, struct wpa_ie_data
*data
)
445 struct rsn_ie_hdr
*hdr
;
450 data
->proto
= WPA_PROTO_RSN
;
451 data
->pairwise_cipher
= WPA_CIPHER_CCMP
;
452 data
->group_cipher
= WPA_CIPHER_CCMP
;
453 data
->key_mgmt
= WPA_KEY_MGMT_IEEE8021X
;
454 data
->capabilities
= 0;
456 if (rsn_ie_len
== 0) {
457 /* No RSN IE - fail silently */
461 if (rsn_ie_len
< sizeof (struct rsn_ie_hdr
)) {
462 wpa_printf(MSG_DEBUG
, "%s: ie len too short %u",
463 "wpa_parse_wpa_ie_rsn", rsn_ie_len
);
467 hdr
= (struct rsn_ie_hdr
*)rsn_ie
;
469 if (hdr
->elem_id
!= RSN_INFO_ELEM
||
470 hdr
->len
!= rsn_ie_len
- 2 ||
471 LE_16(hdr
->version
) != RSN_VERSION
) {
472 wpa_printf(MSG_DEBUG
, "%s: malformed ie or unknown version",
473 "wpa_parse_wpa_ie_rsn");
477 pos
= (uint8_t *)(hdr
+ 1);
478 left
= rsn_ie_len
- sizeof (*hdr
);
480 if (left
>= RSN_SELECTOR_LEN
) {
481 data
->group_cipher
= rsn_selector_to_bitfield(pos
);
482 pos
+= RSN_SELECTOR_LEN
;
483 left
-= RSN_SELECTOR_LEN
;
484 } else if (left
> 0) {
485 wpa_printf(MSG_DEBUG
, "%s: ie length mismatch, %u too much",
486 "wpa_parse_wpa_ie_rsn", left
);
491 data
->pairwise_cipher
= 0;
492 count
= pos
[0] | (pos
[1] << 8);
495 if (count
== 0 || left
< count
* RSN_SELECTOR_LEN
) {
496 wpa_printf(MSG_DEBUG
, "%s: ie count botch (pairwise), "
498 "wpa_parse_wpa_ie_rsn", count
, left
);
501 for (i
= 0; i
< count
; i
++) {
502 data
->pairwise_cipher
|= rsn_selector_to_bitfield(pos
);
503 pos
+= RSN_SELECTOR_LEN
;
504 left
-= RSN_SELECTOR_LEN
;
506 } else if (left
== 1) {
507 wpa_printf(MSG_DEBUG
, "%s: ie too short (for key mgmt)",
508 "wpa_parse_wpa_ie_rsn");
514 count
= pos
[0] | (pos
[1] << 8);
517 if (count
== 0 || left
< count
* RSN_SELECTOR_LEN
) {
518 wpa_printf(MSG_DEBUG
, "%s: ie count botch (key mgmt), "
520 "wpa_parse_wpa_ie_rsn", count
, left
);
523 for (i
= 0; i
< count
; i
++) {
524 data
->key_mgmt
|= rsn_key_mgmt_to_bitfield(pos
);
525 pos
+= RSN_SELECTOR_LEN
;
526 left
-= RSN_SELECTOR_LEN
;
528 } else if (left
== 1) {
529 wpa_printf(MSG_DEBUG
, "%s: ie too short (for capabilities)",
530 "wpa_parse_wpa_ie_rsn");
535 data
->capabilities
= pos
[0] | (pos
[1] << 8);
542 * RSN IE could include PMKID data, but Authenticator should
543 * never include it, so no need to parse it in the Supplicant.
545 wpa_printf(MSG_DEBUG
, "%s: ie has %u trailing bytes - ignored",
546 "wpa_parse_wpa_ie_rsn", left
);
553 wpa_parse_wpa_ie(struct wpa_supplicant
*wpa_s
, uint8_t *wpa_ie
,
554 size_t wpa_ie_len
, struct wpa_ie_data
*data
)
556 if (wpa_ie_len
>= 1 && wpa_ie
[0] == RSN_INFO_ELEM
)
557 return (wpa_parse_wpa_ie_rsn(wpa_s
, wpa_ie
, wpa_ie_len
, data
));
559 return (wpa_parse_wpa_ie_wpa(wpa_s
, wpa_ie
, wpa_ie_len
, data
));
563 wpa_gen_wpa_ie_wpa(struct wpa_supplicant
*wpa_s
, uint8_t *wpa_ie
)
566 struct wpa_ie_hdr
*hdr
;
568 hdr
= (struct wpa_ie_hdr
*)wpa_ie
;
569 hdr
->elem_id
= GENERIC_INFO_ELEM
;
570 (void) memcpy(&hdr
->oui
, WPA_OUI_AND_TYPE
, WPA_SELECTOR_LEN
);
571 hdr
->version
= LE_16(WPA_VERSION
);
572 pos
= (uint8_t *)(hdr
+ 1);
574 if (wpa_s
->group_cipher
== WPA_CIPHER_CCMP
) {
575 (void) memcpy(pos
, WPA_CIPHER_SUITE_CCMP
, WPA_SELECTOR_LEN
);
576 } else if (wpa_s
->group_cipher
== WPA_CIPHER_TKIP
) {
577 (void) memcpy(pos
, WPA_CIPHER_SUITE_TKIP
, WPA_SELECTOR_LEN
);
578 } else if (wpa_s
->group_cipher
== WPA_CIPHER_WEP104
) {
579 (void) memcpy(pos
, WPA_CIPHER_SUITE_WEP104
, WPA_SELECTOR_LEN
);
580 } else if (wpa_s
->group_cipher
== WPA_CIPHER_WEP40
) {
581 (void) memcpy(pos
, WPA_CIPHER_SUITE_WEP40
, WPA_SELECTOR_LEN
);
583 wpa_printf(MSG_WARNING
, "Invalid group cipher (%d).",
584 wpa_s
->group_cipher
);
587 pos
+= WPA_SELECTOR_LEN
;
591 if (wpa_s
->pairwise_cipher
== WPA_CIPHER_CCMP
) {
592 (void) memcpy(pos
, WPA_CIPHER_SUITE_CCMP
, WPA_SELECTOR_LEN
);
593 } else if (wpa_s
->pairwise_cipher
== WPA_CIPHER_TKIP
) {
594 (void) memcpy(pos
, WPA_CIPHER_SUITE_TKIP
, WPA_SELECTOR_LEN
);
595 } else if (wpa_s
->pairwise_cipher
== WPA_CIPHER_NONE
) {
596 (void) memcpy(pos
, WPA_CIPHER_SUITE_NONE
, WPA_SELECTOR_LEN
);
598 wpa_printf(MSG_WARNING
, "Invalid pairwise cipher (%d).",
599 wpa_s
->pairwise_cipher
);
602 pos
+= WPA_SELECTOR_LEN
;
606 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X
) {
607 (void) memcpy(pos
, WPA_AUTH_KEY_MGMT_UNSPEC_802_1X
,
609 } else if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_PSK
) {
610 (void) memcpy(pos
, WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X
,
613 wpa_printf(MSG_WARNING
, "Invalid key management type (%d).",
617 pos
+= WPA_SELECTOR_LEN
;
620 * WPA Capabilities; use defaults, so no need to include it
622 hdr
->len
= (pos
- wpa_ie
) - 2;
624 return (pos
- wpa_ie
);
628 wpa_gen_wpa_ie_rsn(struct wpa_supplicant
*wpa_s
, uint8_t *rsn_ie
)
631 struct rsn_ie_hdr
*hdr
;
633 hdr
= (struct rsn_ie_hdr
*)rsn_ie
;
634 hdr
->elem_id
= RSN_INFO_ELEM
;
635 hdr
->version
= LE_16(RSN_VERSION
);
636 pos
= (uint8_t *)(hdr
+ 1);
638 if (wpa_s
->group_cipher
== WPA_CIPHER_CCMP
) {
639 (void) memcpy(pos
, RSN_CIPHER_SUITE_CCMP
, RSN_SELECTOR_LEN
);
640 } else if (wpa_s
->group_cipher
== WPA_CIPHER_TKIP
) {
641 (void) memcpy(pos
, RSN_CIPHER_SUITE_TKIP
, RSN_SELECTOR_LEN
);
642 } else if (wpa_s
->group_cipher
== WPA_CIPHER_WEP104
) {
643 (void) memcpy(pos
, RSN_CIPHER_SUITE_WEP104
, RSN_SELECTOR_LEN
);
644 } else if (wpa_s
->group_cipher
== WPA_CIPHER_WEP40
) {
645 (void) memcpy(pos
, RSN_CIPHER_SUITE_WEP40
, RSN_SELECTOR_LEN
);
647 wpa_printf(MSG_WARNING
, "Invalid group cipher (%d).",
648 wpa_s
->group_cipher
);
651 pos
+= RSN_SELECTOR_LEN
;
655 if (wpa_s
->pairwise_cipher
== WPA_CIPHER_CCMP
) {
656 (void) memcpy(pos
, RSN_CIPHER_SUITE_CCMP
, RSN_SELECTOR_LEN
);
657 } else if (wpa_s
->pairwise_cipher
== WPA_CIPHER_TKIP
) {
658 (void) memcpy(pos
, RSN_CIPHER_SUITE_TKIP
, RSN_SELECTOR_LEN
);
659 } else if (wpa_s
->pairwise_cipher
== WPA_CIPHER_NONE
) {
660 (void) memcpy(pos
, RSN_CIPHER_SUITE_NONE
, RSN_SELECTOR_LEN
);
662 wpa_printf(MSG_WARNING
, "Invalid pairwise cipher (%d).",
663 wpa_s
->pairwise_cipher
);
666 pos
+= RSN_SELECTOR_LEN
;
670 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X
) {
671 (void) memcpy(pos
, RSN_AUTH_KEY_MGMT_UNSPEC_802_1X
,
673 } else if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_PSK
) {
674 (void) memcpy(pos
, RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X
,
677 wpa_printf(MSG_WARNING
, "Invalid key management type (%d).",
681 pos
+= RSN_SELECTOR_LEN
;
683 /* RSN Capabilities */
687 if (wpa_s
->cur_pmksa
) {
688 /* PMKID Count (2 octets, little endian) */
692 (void) memcpy(pos
, wpa_s
->cur_pmksa
->pmkid
, PMKID_LEN
);
696 hdr
->len
= (pos
- rsn_ie
) - 2;
698 return (pos
- rsn_ie
);
702 wpa_gen_wpa_ie(struct wpa_supplicant
*wpa_s
, uint8_t *wpa_ie
)
704 if (wpa_s
->proto
== WPA_PROTO_RSN
)
705 return (wpa_gen_wpa_ie_rsn(wpa_s
, wpa_ie
));
707 return (wpa_gen_wpa_ie_wpa(wpa_s
, wpa_ie
));
711 wpa_pmk_to_ptk(uint8_t *pmk
, uint8_t *addr1
, uint8_t *addr2
,
712 uint8_t *nonce1
, uint8_t *nonce2
, uint8_t *ptk
, size_t ptk_len
)
714 uint8_t data
[2 * IEEE80211_ADDR_LEN
+ 2 * WPA_PMK_LEN
];
717 * PTK = PRF-X(PMK, "Pairwise key expansion",
718 * Min(AA, SA) || Max(AA, SA) ||
719 * Min(ANonce, SNonce) || Max(ANonce, SNonce))
722 if (memcmp(addr1
, addr2
, IEEE80211_ADDR_LEN
) < 0) {
723 (void) memcpy(data
, addr1
, IEEE80211_ADDR_LEN
);
724 (void) memcpy(data
+ IEEE80211_ADDR_LEN
, addr2
,
727 (void) memcpy(data
, addr2
, IEEE80211_ADDR_LEN
);
728 (void) memcpy(data
+ IEEE80211_ADDR_LEN
, addr1
,
732 if (memcmp(nonce1
, nonce2
, WPA_PMK_LEN
) < 0) {
733 (void) memcpy(data
+ 2 * IEEE80211_ADDR_LEN
, nonce1
,
735 (void) memcpy(data
+ 2 * IEEE80211_ADDR_LEN
+ WPA_PMK_LEN
,
736 nonce2
, WPA_PMK_LEN
);
738 (void) memcpy(data
+ 2 * IEEE80211_ADDR_LEN
, nonce2
,
740 (void) memcpy(data
+ 2 * IEEE80211_ADDR_LEN
+ WPA_PMK_LEN
,
741 nonce1
, WPA_PMK_LEN
);
744 sha1_prf(pmk
, WPA_PMK_LEN
, "Pairwise key expansion", data
,
745 sizeof (data
), ptk
, ptk_len
);
747 wpa_hexdump(MSG_DEBUG
, "WPA: PMK", pmk
, WPA_PMK_LEN
);
748 wpa_hexdump(MSG_DEBUG
, "WPA: PTK", ptk
, ptk_len
);
752 wpa_supplicant_get_ssid(struct wpa_supplicant
*wpa_s
)
754 struct wpa_ssid
*entry
;
755 uint8_t ssid
[MAX_ESSID_LENGTH
];
757 uint8_t bssid
[IEEE80211_ADDR_LEN
];
759 (void) memset(ssid
, 0, MAX_ESSID_LENGTH
);
760 ssid_len
= wpa_s
->driver
->get_ssid(wpa_s
->handle
, wpa_s
->linkid
,
763 wpa_printf(MSG_WARNING
, "Could not read SSID from driver.");
767 if (wpa_s
->driver
->get_bssid(wpa_s
->handle
, wpa_s
->linkid
,
768 (char *)bssid
) < 0) {
769 wpa_printf(MSG_WARNING
, "Could not read BSSID from driver.");
773 entry
= wpa_s
->conf
->ssid
;
774 wpa_printf(MSG_DEBUG
, "entry len=%d ssid=%s,"
775 " driver len=%d ssid=%s",
776 entry
->ssid_len
, entry
->ssid
, ssid_len
, ssid
);
778 if (ssid_len
== entry
->ssid_len
&&
779 memcmp(ssid
, entry
->ssid
, ssid_len
) == 0 &&
780 (!entry
->bssid_set
||
781 memcmp(bssid
, entry
->bssid
, IEEE80211_ADDR_LEN
) == 0))
788 wpa_eapol_key_mic(uint8_t *key
, int ver
, uint8_t *buf
, size_t len
, uint8_t *mic
)
790 if (ver
== WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
) {
791 hmac_md5(key
, 16, buf
, len
, mic
);
792 } else if (ver
== WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
) {
793 uint8_t hash
[SHA1_MAC_LEN
];
794 hmac_sha1(key
, 16, buf
, len
, hash
);
795 (void) memcpy(mic
, hash
, MD5_MAC_LEN
);
800 wpa_supplicant_key_request(struct wpa_supplicant
*wpa_s
,
801 int error
, int pairwise
)
804 struct ieee802_1x_hdr
*hdr
;
805 struct wpa_eapol_key
*reply
;
807 struct l2_ethhdr
*ethhdr
;
809 uint8_t bssid
[IEEE80211_ADDR_LEN
];
811 if (wpa_s
->pairwise_cipher
== WPA_CIPHER_CCMP
)
812 ver
= WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
;
814 ver
= WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
;
816 if (wpa_s
->driver
->get_bssid(wpa_s
->handle
, wpa_s
->linkid
,
817 (char *)bssid
) < 0) {
818 wpa_printf(MSG_WARNING
, "Failed to read BSSID for EAPOL-Key "
823 rlen
= sizeof (*ethhdr
) + sizeof (*hdr
) + sizeof (*reply
);
828 (void) memset(rbuf
, 0, rlen
);
829 ethhdr
= (struct l2_ethhdr
*)rbuf
;
830 (void) memcpy(ethhdr
->h_dest
, bssid
, IEEE80211_ADDR_LEN
);
831 (void) memcpy(ethhdr
->h_source
, wpa_s
->own_addr
, IEEE80211_ADDR_LEN
);
832 ethhdr
->h_proto
= htons(ETHERTYPE_EAPOL
);
834 hdr
= (struct ieee802_1x_hdr
*)(ethhdr
+ 1);
835 hdr
->version
= wpa_s
->conf
->eapol_version
;
836 hdr
->type
= IEEE802_1X_TYPE_EAPOL_KEY
;
837 hdr
->length
= htons(sizeof (*reply
));
839 reply
= (struct wpa_eapol_key
*)(hdr
+ 1);
840 reply
->type
= wpa_s
->proto
== WPA_PROTO_RSN
?
841 EAPOL_KEY_TYPE_RSN
: EAPOL_KEY_TYPE_WPA
;
842 key_info
= WPA_KEY_INFO_REQUEST
| ver
;
844 key_info
|= WPA_KEY_INFO_MIC
;
846 key_info
|= WPA_KEY_INFO_ERROR
;
848 key_info
|= WPA_KEY_INFO_KEY_TYPE
;
849 reply
->key_info
= BE_16(key_info
);
850 reply
->key_length
= 0;
851 (void) memcpy(reply
->replay_counter
, wpa_s
->request_counter
,
852 WPA_REPLAY_COUNTER_LEN
);
853 inc_byte_array(wpa_s
->request_counter
, WPA_REPLAY_COUNTER_LEN
);
855 reply
->key_data_length
= BE_16(0);
857 if (key_info
& WPA_KEY_INFO_MIC
) {
858 wpa_eapol_key_mic(wpa_s
->ptk
.mic_key
, ver
, (uint8_t *)hdr
,
859 rlen
- sizeof (*ethhdr
), reply
->key_mic
);
862 wpa_printf(MSG_INFO
, "WPA: Sending EAPOL-Key Request (error=%d "
863 "pairwise=%d ptk_set=%d len=%d)",
864 error
, pairwise
, wpa_s
->ptk_set
, rlen
);
865 wpa_hexdump(MSG_MSGDUMP
, "WPA: TX EAPOL-Key Request", rbuf
, rlen
);
866 (void) l2_packet_send(wpa_s
->l2
, rbuf
, rlen
);
871 wpa_supplicant_process_1_of_4(struct wpa_supplicant
*wpa_s
,
872 unsigned char *src_addr
, struct wpa_eapol_key
*key
, int ver
)
875 struct ieee802_1x_hdr
*hdr
;
876 struct wpa_eapol_key
*reply
;
878 struct l2_ethhdr
*ethhdr
;
879 struct wpa_ssid
*ssid
;
881 uint8_t buf
[8], wpa_ie_buf
[80], *wpa_ie
, *pmkid
= NULL
;
884 wpa_s
->wpa_state
= WPA_4WAY_HANDSHAKE
;
885 wpa_printf(MSG_DEBUG
, "WPA: RX message 1 of 4-Way Handshake from "
886 MACSTR
" (ver=%d)", MAC2STR(src_addr
), ver
);
888 ssid
= wpa_supplicant_get_ssid(wpa_s
);
890 wpa_printf(MSG_WARNING
,
891 "WPA: No SSID info found (msg 1 of 4).");
895 if (wpa_s
->proto
== WPA_PROTO_RSN
) {
896 /* RSN: msg 1/4 should contain PMKID for the selected PMK */
897 uint8_t *pos
= (uint8_t *)(key
+ 1);
898 uint8_t *end
= pos
+ BE_16(key
->key_data_length
);
900 wpa_hexdump(MSG_DEBUG
, "RSN: msg 1/4 key data",
901 pos
, BE_16(key
->key_data_length
));
903 while (pos
+ 1 < end
) {
904 if (pos
+ 2 + pos
[1] > end
) {
905 wpa_printf(MSG_DEBUG
, "RSN: key data "
906 "underflow (ie=%d len=%d)",
910 if (pos
[0] == GENERIC_INFO_ELEM
&&
911 pos
+ 1 + RSN_SELECTOR_LEN
< end
&&
912 pos
[1] >= RSN_SELECTOR_LEN
+ PMKID_LEN
&&
913 memcmp(pos
+ 2, RSN_KEY_DATA_PMKID
,
914 RSN_SELECTOR_LEN
) == 0) {
915 pmkid
= pos
+ 2 + RSN_SELECTOR_LEN
;
916 wpa_hexdump(MSG_DEBUG
, "RSN: PMKID from "
917 "Authenticator", pmkid
, PMKID_LEN
);
919 } else if (pos
[0] == GENERIC_INFO_ELEM
&& pos
[1] == 0)
926 wpa_ie_len
= wpa_gen_wpa_ie(wpa_s
, wpa_ie
);
927 if (wpa_ie_len
< 0) {
928 wpa_printf(MSG_WARNING
, "WPA: Failed to generate "
929 "WPA IE (for msg 2 of 4).");
932 wpa_hexdump(MSG_DEBUG
, "WPA: WPA IE for msg 2/4", wpa_ie
, wpa_ie_len
);
934 rlen
= sizeof (*ethhdr
) + sizeof (*hdr
) + sizeof (*reply
) + wpa_ie_len
;
939 (void) memset(rbuf
, 0, rlen
);
940 ethhdr
= (struct l2_ethhdr
*)rbuf
;
941 (void) memcpy(ethhdr
->h_dest
, src_addr
, IEEE80211_ADDR_LEN
);
942 (void) memcpy(ethhdr
->h_source
, wpa_s
->own_addr
, IEEE80211_ADDR_LEN
);
943 ethhdr
->h_proto
= htons(ETHERTYPE_EAPOL
);
945 hdr
= (struct ieee802_1x_hdr
*)(ethhdr
+ 1);
946 hdr
->version
= wpa_s
->conf
->eapol_version
;
947 hdr
->type
= IEEE802_1X_TYPE_EAPOL_KEY
;
948 hdr
->length
= htons(sizeof (*reply
) + wpa_ie_len
);
950 reply
= (struct wpa_eapol_key
*)(hdr
+ 1);
951 reply
->type
= wpa_s
->proto
== WPA_PROTO_RSN
?
952 EAPOL_KEY_TYPE_RSN
: EAPOL_KEY_TYPE_WPA
;
953 reply
->key_info
= BE_16(ver
| WPA_KEY_INFO_KEY_TYPE
| WPA_KEY_INFO_MIC
);
954 reply
->key_length
= key
->key_length
;
955 (void) memcpy(reply
->replay_counter
, key
->replay_counter
,
956 WPA_REPLAY_COUNTER_LEN
);
958 reply
->key_data_length
= BE_16(wpa_ie_len
);
959 (void) memcpy(reply
+ 1, wpa_ie
, wpa_ie_len
);
961 if (wpa_s
->renew_snonce
) {
962 if (random_get_pseudo_bytes(wpa_s
->snonce
, WPA_NONCE_LEN
)) {
963 wpa_printf(MSG_WARNING
, "WPA: Failed to get "
964 "random data for SNonce");
969 wpa_s
->renew_snonce
= 0;
970 wpa_hexdump(MSG_DEBUG
, "WPA: Renewed SNonce",
971 wpa_s
->snonce
, WPA_NONCE_LEN
);
973 (void) memcpy(reply
->key_nonce
, wpa_s
->snonce
, WPA_NONCE_LEN
);
975 (void) memcpy(wpa_s
->anonce
, key
->key_nonce
, WPA_NONCE_LEN
);
977 wpa_pmk_to_ptk(wpa_s
->pmk
, wpa_s
->own_addr
, src_addr
,
978 wpa_s
->snonce
, key
->key_nonce
, (uint8_t *)ptk
, sizeof (*ptk
));
981 * Supplicant: swap tx/rx Mic keys
983 (void) memcpy(buf
, ptk
->u
.auth
.tx_mic_key
, 8);
984 (void) memcpy(ptk
->u
.auth
.tx_mic_key
, ptk
->u
.auth
.rx_mic_key
, 8);
985 (void) memcpy(ptk
->u
.auth
.rx_mic_key
, buf
, 8);
987 wpa_eapol_key_mic(wpa_s
->tptk
.mic_key
, ver
, (uint8_t *)hdr
,
988 rlen
- sizeof (*ethhdr
), reply
->key_mic
);
989 wpa_hexdump(MSG_DEBUG
, "WPA: EAPOL-Key MIC", reply
->key_mic
, 16);
991 wpa_printf(MSG_DEBUG
, "WPA: Sending EAPOL-Key 2/4");
992 wpa_hexdump(MSG_MSGDUMP
, "WPA: TX EAPOL-Key 2/4", rbuf
, rlen
);
993 (void) l2_packet_send(wpa_s
->l2
, rbuf
, rlen
);
999 wpa_supplicant_process_3_of_4_gtk(struct wpa_supplicant
*wpa_s
,
1000 unsigned char *src_addr
, struct wpa_eapol_key
*key
,
1001 uint8_t *gtk
, int gtk_len
)
1003 int keyidx
, tx
, key_rsc_len
= 0, alg
;
1005 wpa_hexdump(MSG_DEBUG
,
1006 "WPA: received GTK in pairwise handshake", gtk
, gtk_len
);
1008 keyidx
= gtk
[0] & 0x3;
1009 tx
= !!(gtk
[0] & BIT(2));
1010 if (tx
&& wpa_s
->pairwise_cipher
!= WPA_CIPHER_NONE
) {
1012 * Ignore Tx bit in GTK IE if a pairwise key is used.
1013 * One AP seemed to set this bit (incorrectly, since Tx
1014 * is only when doing Group Key only APs) and without
1015 * this workaround, the data connection does not work
1016 * because wpa_supplicant configured non-zero keyidx to
1017 * be used for unicast.
1019 wpa_printf(MSG_INFO
, "RSN: Tx bit set for GTK IE, but "
1020 "pairwise keys are used - ignore Tx bit");
1026 wpa_hexdump(MSG_DEBUG
, "WPA: Group Key", gtk
, gtk_len
);
1028 switch (wpa_s
->group_cipher
) {
1029 case WPA_CIPHER_CCMP
:
1030 if (gtk_len
!= 16) {
1031 wpa_printf(MSG_WARNING
, "WPA: Unsupported CCMP"
1032 " Group Cipher key length %d.", gtk_len
);
1038 case WPA_CIPHER_TKIP
:
1039 if (gtk_len
!= 32) {
1040 wpa_printf(MSG_WARNING
, "WPA: Unsupported TKIP"
1041 " Group Cipher key length %d.", gtk_len
);
1047 case WPA_CIPHER_WEP104
:
1048 if (gtk_len
!= 13) {
1049 wpa_printf(MSG_WARNING
, "WPA: Unsupported "
1050 "WEP104 Group Cipher key length " "%d.", gtk_len
);
1055 case WPA_CIPHER_WEP40
:
1057 wpa_printf(MSG_WARNING
, "WPA: Unsupported "
1058 "WEP40 Group Cipher key length %d.", gtk_len
);
1064 wpa_printf(MSG_WARNING
, "WPA: Unsupport Group Cipher "
1065 "%d", wpa_s
->group_cipher
);
1069 wpa_printf(MSG_DEBUG
, "WPA: Installing GTK to the driver "
1070 "(keyidx=%d tx=%d).", keyidx
, tx
);
1071 wpa_hexdump(MSG_DEBUG
, "WPA: RSC", key
->key_rsc
, key_rsc_len
);
1072 if (wpa_s
->group_cipher
== WPA_CIPHER_TKIP
) {
1075 * Swap Tx/Rx keys for Michael MIC
1077 (void) memcpy(tmpbuf
, gtk
+ 16, 8);
1078 (void) memcpy(gtk
+ 16, gtk
+ 24, 8);
1079 (void) memcpy(gtk
+ 24, tmpbuf
, 8);
1081 if (wpa_s
->pairwise_cipher
== WPA_CIPHER_NONE
) {
1082 if (wpa_s
->driver
->set_key(wpa_s
->handle
, wpa_s
->linkid
, alg
,
1083 (uint8_t *)"\xff\xff\xff\xff\xff\xff",
1084 keyidx
, 1, key
->key_rsc
,
1085 key_rsc_len
, gtk
, gtk_len
) < 0)
1086 wpa_printf(MSG_WARNING
, "WPA: Failed to set "
1087 "GTK to the driver (Group only).");
1088 } else if (wpa_s
->driver
->set_key(wpa_s
->handle
, wpa_s
->linkid
, alg
,
1089 (uint8_t *)"\xff\xff\xff\xff\xff\xff", keyidx
, tx
,
1090 key
->key_rsc
, key_rsc_len
, gtk
, gtk_len
) < 0) {
1091 wpa_printf(MSG_WARNING
, "WPA: Failed to set GTK to "
1095 wpa_printf(MSG_INFO
, "WPA: Key negotiation completed with "
1096 MACSTR
, MAC2STR(src_addr
));
1097 eloop_cancel_timeout(wpa_supplicant_scan
, wpa_s
, NULL
);
1098 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1099 wpa_s
->wpa_state
= WPA_COMPLETED
;
1103 wpa_supplicant_process_3_of_4(struct wpa_supplicant
*wpa_s
,
1104 unsigned char *src_addr
, struct wpa_eapol_key
*key
,
1105 int extra_len
, int ver
)
1108 struct ieee802_1x_hdr
*hdr
;
1109 struct wpa_eapol_key
*reply
;
1110 unsigned char *rbuf
;
1111 struct l2_ethhdr
*ethhdr
;
1112 int key_info
, ie_len
= 0, keylen
, gtk_len
= 0;
1113 uint8_t *ie
= NULL
, *gtk
= NULL
, *key_rsc
;
1114 uint8_t null_rsc
[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1116 wpa_s
->wpa_state
= WPA_4WAY_HANDSHAKE
;
1117 wpa_printf(MSG_DEBUG
, "WPA: RX message 3 of 4-Way Handshake from "
1118 MACSTR
" (ver=%d)", MAC2STR(src_addr
), ver
);
1120 key_info
= BE_16(key
->key_info
);
1122 if (wpa_s
->proto
== WPA_PROTO_RSN
) {
1123 uint8_t *pos
= (uint8_t *)(key
+ 1);
1124 uint8_t *end
= pos
+ BE_16(key
->key_data_length
);
1125 while (pos
+ 1 < end
) {
1126 if (pos
+ 2 + pos
[1] > end
) {
1127 wpa_printf(MSG_DEBUG
, "RSN: key data "
1128 "underflow (ie=%d len=%d)",
1132 if (*pos
== RSN_INFO_ELEM
) {
1134 ie_len
= pos
[1] + 2;
1135 } else if (pos
[0] == GENERIC_INFO_ELEM
&&
1136 pos
+ 1 + RSN_SELECTOR_LEN
< end
&&
1137 pos
[1] > RSN_SELECTOR_LEN
+ 2 &&
1138 memcmp(pos
+ 2, RSN_KEY_DATA_GROUPKEY
,
1139 RSN_SELECTOR_LEN
) == 0) {
1140 if (!(key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
)) {
1141 wpa_printf(MSG_WARNING
, "WPA: GTK IE "
1142 "in unencrypted key data");
1145 gtk
= pos
+ 2 + RSN_SELECTOR_LEN
;
1146 gtk_len
= pos
[1] - RSN_SELECTOR_LEN
;
1147 } else if (pos
[0] == GENERIC_INFO_ELEM
&& pos
[1] == 0)
1153 ie
= (uint8_t *)(key
+ 1);
1154 ie_len
= BE_16(key
->key_data_length
);
1155 if (ie_len
> extra_len
) {
1156 wpa_printf(MSG_INFO
, "WPA: Truncated EAPOL-Key packet:"
1157 " ie_len=%d > extra_len=%d",
1163 if (wpa_s
->ap_wpa_ie
&&
1164 (wpa_s
->ap_wpa_ie_len
!= ie_len
||
1165 memcmp(wpa_s
->ap_wpa_ie
, ie
, ie_len
) != 0)) {
1166 wpa_printf(MSG_WARNING
, "WPA: WPA IE in 3/4 msg does not match"
1167 " with WPA IE in Beacon/ProbeResp (src=" MACSTR
")",
1169 wpa_hexdump(MSG_INFO
, "WPA: WPA IE in Beacon/ProbeResp",
1170 wpa_s
->ap_wpa_ie
, wpa_s
->ap_wpa_ie_len
);
1171 wpa_hexdump(MSG_INFO
, "WPA: WPA IE in 3/4 msg", ie
, ie_len
);
1172 wpa_supplicant_disassociate(wpa_s
, REASON_IE_IN_4WAY_DIFFERS
);
1173 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1177 if (memcmp(wpa_s
->anonce
, key
->key_nonce
, WPA_NONCE_LEN
) != 0) {
1178 wpa_printf(MSG_WARNING
, "WPA: ANonce from message 1 of 4-Way "
1179 "Handshake differs from 3 of 4-Way Handshake - drop"
1180 " packet (src=" MACSTR
")", MAC2STR(src_addr
));
1184 keylen
= BE_16(key
->key_length
);
1185 switch (wpa_s
->pairwise_cipher
) {
1186 case WPA_CIPHER_CCMP
:
1188 wpa_printf(MSG_WARNING
, "WPA: Invalid CCMP key length "
1189 "%d (src=" MACSTR
")",
1190 keylen
, MAC2STR(src_addr
));
1194 case WPA_CIPHER_TKIP
:
1196 wpa_printf(MSG_WARNING
, "WPA: Invalid TKIP key length "
1197 "%d (src=" MACSTR
")",
1198 keylen
, MAC2STR(src_addr
));
1204 rlen
= sizeof (*ethhdr
) + sizeof (*hdr
) + sizeof (*reply
);
1205 rbuf
= malloc(rlen
);
1209 (void) memset(rbuf
, 0, rlen
);
1210 ethhdr
= (struct l2_ethhdr
*)rbuf
;
1211 (void) memcpy(ethhdr
->h_dest
, src_addr
, IEEE80211_ADDR_LEN
);
1212 (void) memcpy(ethhdr
->h_source
, wpa_s
->own_addr
, IEEE80211_ADDR_LEN
);
1213 ethhdr
->h_proto
= htons(ETHERTYPE_EAPOL
);
1215 hdr
= (struct ieee802_1x_hdr
*)(ethhdr
+ 1);
1216 hdr
->version
= wpa_s
->conf
->eapol_version
;
1217 hdr
->type
= IEEE802_1X_TYPE_EAPOL_KEY
;
1218 hdr
->length
= htons(sizeof (*reply
));
1220 reply
= (struct wpa_eapol_key
*)(hdr
+ 1);
1221 reply
->type
= wpa_s
->proto
== WPA_PROTO_RSN
?
1222 EAPOL_KEY_TYPE_RSN
: EAPOL_KEY_TYPE_WPA
;
1223 reply
->key_info
= BE_16(ver
| WPA_KEY_INFO_KEY_TYPE
|
1224 WPA_KEY_INFO_MIC
| (key_info
& WPA_KEY_INFO_SECURE
));
1225 reply
->key_length
= key
->key_length
;
1226 (void) memcpy(reply
->replay_counter
, key
->replay_counter
,
1227 WPA_REPLAY_COUNTER_LEN
);
1229 reply
->key_data_length
= BE_16(0);
1231 (void) memcpy(reply
->key_nonce
, wpa_s
->snonce
, WPA_NONCE_LEN
);
1232 wpa_eapol_key_mic(wpa_s
->ptk
.mic_key
, ver
, (uint8_t *)hdr
,
1233 rlen
- sizeof (*ethhdr
), reply
->key_mic
);
1235 wpa_printf(MSG_DEBUG
, "WPA: Sending EAPOL-Key 4/4");
1236 wpa_hexdump(MSG_MSGDUMP
, "WPA: TX EAPOL-Key 4/4", rbuf
, rlen
);
1237 (void) l2_packet_send(wpa_s
->l2
, rbuf
, rlen
);
1242 * SNonce was successfully used in msg 3/4, so mark it to be renewed
1243 * for the next 4-Way Handshake. If msg 3 is received again, the old
1244 * SNonce will still be used to avoid changing PTK.
1246 wpa_s
->renew_snonce
= 1;
1248 if (key_info
& WPA_KEY_INFO_INSTALL
) {
1249 int alg
, keylen
, rsclen
;
1250 wpa_printf(MSG_DEBUG
, "WPA: Installing PTK to the driver.");
1251 switch (wpa_s
->pairwise_cipher
) {
1252 case WPA_CIPHER_CCMP
:
1257 case WPA_CIPHER_TKIP
:
1262 case WPA_CIPHER_NONE
:
1263 wpa_printf(MSG_DEBUG
, "WPA: Pairwise Cipher Suite: "
1264 "NONE - do not use pairwise keys");
1267 wpa_printf(MSG_WARNING
, "WPA: Unsupported pairwise "
1268 "cipher %d", wpa_s
->pairwise_cipher
);
1271 if (wpa_s
->proto
== WPA_PROTO_RSN
) {
1274 key_rsc
= key
->key_rsc
;
1275 wpa_hexdump(MSG_DEBUG
, "WPA: RSC", key_rsc
, rsclen
);
1278 if (wpa_s
->driver
->set_key(wpa_s
->handle
, wpa_s
->linkid
, alg
,
1279 src_addr
, 0, 1, key_rsc
, rsclen
,
1280 (uint8_t *)&wpa_s
->ptk
.tk1
, keylen
) < 0) {
1281 wpa_printf(MSG_WARNING
, "WPA: Failed to set PTK to the"
1286 wpa_printf(MSG_DEBUG
, "%s: key_info=%x gtk=%p\n",
1287 "wpa_supplicant_process_3_of_4", key_info
, gtk
);
1288 wpa_s
->wpa_state
= WPA_GROUP_HANDSHAKE
;
1291 wpa_supplicant_process_3_of_4_gtk(wpa_s
,
1292 src_addr
, key
, gtk
, gtk_len
);
1296 wpa_supplicant_process_1_of_2(struct wpa_supplicant
*wpa_s
,
1297 unsigned char *src_addr
, struct wpa_eapol_key
*key
,
1298 int extra_len
, int ver
)
1301 struct ieee802_1x_hdr
*hdr
;
1302 struct wpa_eapol_key
*reply
;
1303 unsigned char *rbuf
;
1304 struct l2_ethhdr
*ethhdr
;
1305 int key_info
, keylen
, keydatalen
, maxkeylen
, keyidx
, key_rsc_len
= 0;
1307 uint8_t ek
[32], tmpbuf
[8], gtk
[32];
1308 uint8_t *gtk_ie
= NULL
;
1309 size_t gtk_ie_len
= 0;
1311 wpa_s
->wpa_state
= WPA_GROUP_HANDSHAKE
;
1312 wpa_printf(MSG_DEBUG
, "WPA: RX message 1 of Group Key Handshake from "
1313 MACSTR
" (ver=%d)", MAC2STR(src_addr
), ver
);
1315 key_info
= BE_16(key
->key_info
);
1316 keydatalen
= BE_16(key
->key_data_length
);
1318 if (wpa_s
->proto
== WPA_PROTO_RSN
) {
1319 uint8_t *pos
= (uint8_t *)(key
+ 1);
1320 uint8_t *end
= pos
+ keydatalen
;
1321 while (pos
+ 1 < end
) {
1322 if (pos
+ 2 + pos
[1] > end
) {
1323 wpa_printf(MSG_DEBUG
, "RSN: key data "
1324 "underflow (ie=%d len=%d)",
1328 if (pos
[0] == GENERIC_INFO_ELEM
&&
1329 pos
+ 1 + RSN_SELECTOR_LEN
< end
&&
1330 pos
[1] > RSN_SELECTOR_LEN
+ 2 &&
1331 memcmp(pos
+ 2, RSN_KEY_DATA_GROUPKEY
,
1332 RSN_SELECTOR_LEN
) == 0) {
1333 if (!(key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
)) {
1334 wpa_printf(MSG_WARNING
, "WPA: GTK IE "
1335 "in unencrypted key data");
1338 gtk_ie
= pos
+ 2 + RSN_SELECTOR_LEN
;
1339 gtk_ie_len
= pos
[1] - RSN_SELECTOR_LEN
;
1341 } else if (pos
[0] == GENERIC_INFO_ELEM
&& pos
[1] == 0) {
1348 if (gtk_ie
== NULL
) {
1349 wpa_printf(MSG_INFO
, "WPA: No GTK IE in Group Key "
1353 maxkeylen
= keylen
= gtk_ie_len
- 2;
1355 keylen
= BE_16(key
->key_length
);
1356 maxkeylen
= keydatalen
;
1357 if (keydatalen
> extra_len
) {
1358 wpa_printf(MSG_INFO
, "WPA: Truncated EAPOL-Key packet:"
1359 " key_data_length=%d > extra_len=%d",
1360 keydatalen
, extra_len
);
1363 if (ver
== WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
)
1367 switch (wpa_s
->group_cipher
) {
1368 case WPA_CIPHER_CCMP
:
1369 if (keylen
!= 16 || maxkeylen
< 16) {
1370 wpa_printf(MSG_WARNING
, "WPA: Unsupported CCMP Group "
1371 "Cipher key length %d (%d).", keylen
, maxkeylen
);
1377 case WPA_CIPHER_TKIP
:
1378 if (keylen
!= 32 || maxkeylen
< 32) {
1379 wpa_printf(MSG_WARNING
, "WPA: Unsupported TKIP Group "
1380 "Cipher key length %d (%d).", keylen
, maxkeylen
);
1383 key_rsc_len
= 6; /* key->key_data; */
1386 case WPA_CIPHER_WEP104
:
1387 if (keylen
!= 13 || maxkeylen
< 13) {
1388 wpa_printf(MSG_WARNING
, "WPA: Unsupported WEP104 Group"
1389 " Cipher key length %d (%d).", keylen
, maxkeylen
);
1394 case WPA_CIPHER_WEP40
:
1395 if (keylen
!= 5 || maxkeylen
< 5) {
1396 wpa_printf(MSG_WARNING
, "WPA: Unsupported WEP40 Group "
1397 "Cipher key length %d (%d).", keylen
, maxkeylen
);
1403 wpa_printf(MSG_WARNING
, "WPA: Unsupport Group Cipher %d",
1404 wpa_s
->group_cipher
);
1408 if (wpa_s
->proto
== WPA_PROTO_RSN
) {
1409 wpa_hexdump(MSG_DEBUG
,
1410 "WPA: received GTK in group key handshake",
1411 gtk_ie
, gtk_ie_len
);
1412 keyidx
= gtk_ie
[0] & 0x3;
1413 tx
= !!(gtk_ie
[0] & BIT(2));
1414 if (gtk_ie_len
- 2 > sizeof (gtk
)) {
1415 wpa_printf(MSG_INFO
, "WPA: Too long GTK in GTK IE "
1416 "(len=%d)", gtk_ie_len
- 2);
1419 (void) memcpy(gtk
, gtk_ie
+ 2, gtk_ie_len
- 2);
1421 keyidx
= (key_info
& WPA_KEY_INFO_KEY_INDEX_MASK
) >>
1422 WPA_KEY_INFO_KEY_INDEX_SHIFT
;
1423 if (ver
== WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
) {
1424 (void) memcpy(ek
, key
->key_iv
, 16);
1425 (void) memcpy(ek
+ 16, wpa_s
->ptk
.encr_key
, 16);
1426 rc4_skip(ek
, 32, 256, (uint8_t *)(key
+ 1), keydatalen
);
1427 (void) memcpy(gtk
, key
+ 1, keylen
);
1428 } else if (ver
== WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
) {
1429 if (keydatalen
% 8) {
1430 wpa_printf(MSG_WARNING
, "WPA: Unsupported "
1431 "AES-WRAP len %d", keydatalen
);
1434 if (aes_unwrap(wpa_s
->ptk
.encr_key
, maxkeylen
/ 8,
1435 (uint8_t *)(key
+ 1), gtk
)) {
1436 wpa_printf(MSG_WARNING
, "WPA: AES unwrap "
1437 "failed - could not decrypt GTK");
1441 tx
= !!(key_info
& WPA_KEY_INFO_TXRX
);
1442 if (tx
&& wpa_s
->pairwise_cipher
!= WPA_CIPHER_NONE
) {
1444 * Ignore Tx bit in Group Key message if a pairwise key
1445 * is used. Some APs seem to setting this bit
1446 * (incorrectly, since Tx is only when doing Group Key
1447 * only APs) and without this workaround, the data
1448 * connection does not work because wpa_supplicant
1449 * configured non-zero keyidx to be used for unicast.
1451 wpa_printf(MSG_INFO
, "WPA: Tx bit set for GTK, but "
1452 "pairwise keys are used - ignore Tx bit");
1456 wpa_hexdump(MSG_DEBUG
, "WPA: Group Key", gtk
, keylen
);
1457 wpa_printf(MSG_DEBUG
, "WPA: Installing GTK to the driver (keyidx=%d "
1458 "tx=%d).", keyidx
, tx
);
1459 wpa_hexdump(MSG_DEBUG
, "WPA: RSC", key
->key_rsc
, key_rsc_len
);
1460 if (wpa_s
->group_cipher
== WPA_CIPHER_TKIP
) {
1462 * Swap Tx/Rx keys for Michael MIC
1464 (void) memcpy(tmpbuf
, gtk
+ 16, 8);
1465 (void) memcpy(gtk
+ 16, gtk
+ 24, 8);
1466 (void) memcpy(gtk
+ 24, tmpbuf
, 8);
1468 if (wpa_s
->pairwise_cipher
== WPA_CIPHER_NONE
) {
1469 if (wpa_s
->driver
->set_key(wpa_s
->handle
, wpa_s
->linkid
, alg
,
1470 (uint8_t *)"\xff\xff\xff\xff\xff\xff",
1471 keyidx
, 1, key
->key_rsc
,
1472 key_rsc_len
, gtk
, keylen
) < 0)
1473 wpa_printf(MSG_WARNING
, "WPA: Failed to set GTK to the"
1474 " driver (Group only).");
1475 } else if (wpa_s
->driver
->set_key(wpa_s
->handle
, wpa_s
->linkid
, alg
,
1476 (uint8_t *)"\xff\xff\xff\xff\xff\xff",
1478 key
->key_rsc
, key_rsc_len
,
1480 wpa_printf(MSG_WARNING
, "WPA: Failed to set GTK to the "
1484 rlen
= sizeof (*ethhdr
) + sizeof (*hdr
) + sizeof (*reply
);
1485 rbuf
= malloc(rlen
);
1489 (void) memset(rbuf
, 0, rlen
);
1490 ethhdr
= (struct l2_ethhdr
*)rbuf
;
1491 (void) memcpy(ethhdr
->h_dest
, src_addr
, IEEE80211_ADDR_LEN
);
1492 (void) memcpy(ethhdr
->h_source
, wpa_s
->own_addr
, IEEE80211_ADDR_LEN
);
1493 ethhdr
->h_proto
= htons(ETHERTYPE_EAPOL
);
1495 hdr
= (struct ieee802_1x_hdr
*)(ethhdr
+ 1);
1496 hdr
->version
= wpa_s
->conf
->eapol_version
;
1497 hdr
->type
= IEEE802_1X_TYPE_EAPOL_KEY
;
1498 hdr
->length
= htons(sizeof (*reply
));
1500 reply
= (struct wpa_eapol_key
*)(hdr
+ 1);
1501 reply
->type
= wpa_s
->proto
== WPA_PROTO_RSN
?
1502 EAPOL_KEY_TYPE_RSN
: EAPOL_KEY_TYPE_WPA
;
1504 BE_16(ver
| WPA_KEY_INFO_MIC
| WPA_KEY_INFO_SECURE
|
1505 (key_info
& WPA_KEY_INFO_KEY_INDEX_MASK
));
1506 reply
->key_length
= key
->key_length
;
1507 (void) memcpy(reply
->replay_counter
, key
->replay_counter
,
1508 WPA_REPLAY_COUNTER_LEN
);
1510 reply
->key_data_length
= BE_16(0);
1512 wpa_eapol_key_mic(wpa_s
->ptk
.mic_key
, ver
, (uint8_t *)hdr
,
1513 rlen
- sizeof (*ethhdr
), reply
->key_mic
);
1515 wpa_printf(MSG_DEBUG
, "WPA: Sending EAPOL-Key 2/2");
1516 wpa_hexdump(MSG_MSGDUMP
, "WPA: TX EAPOL-Key 2/2", rbuf
, rlen
);
1517 (void) l2_packet_send(wpa_s
->l2
, rbuf
, rlen
);
1520 wpa_printf(MSG_INFO
, "WPA: Key negotiation completed with " MACSTR
,
1522 eloop_cancel_timeout(wpa_supplicant_scan
, wpa_s
, NULL
);
1523 wpa_supplicant_cancel_auth_timeout(wpa_s
);
1524 wpa_s
->wpa_state
= WPA_COMPLETED
;
1525 wpa_printf(MSG_INFO
, "-----------------------------------\n");
1529 wpa_supplicant_verify_eapol_key_mic(struct wpa_supplicant
*wpa_s
,
1530 struct wpa_eapol_key
*key
, int ver
, uint8_t *buf
, size_t len
)
1535 (void) memcpy(mic
, key
->key_mic
, 16);
1536 if (wpa_s
->tptk_set
) {
1537 (void) memset(key
->key_mic
, 0, 16);
1538 wpa_eapol_key_mic(wpa_s
->tptk
.mic_key
, ver
, buf
, len
,
1540 if (memcmp(mic
, key
->key_mic
, 16) != 0) {
1541 wpa_printf(MSG_WARNING
, "WPA: Invalid EAPOL-Key MIC "
1542 "when using TPTK - ignoring TPTK");
1545 wpa_s
->tptk_set
= 0;
1547 (void) memcpy(&wpa_s
->ptk
, &wpa_s
->tptk
,
1548 sizeof (wpa_s
->ptk
));
1552 if (!ok
&& wpa_s
->ptk_set
) {
1553 (void) memset(key
->key_mic
, 0, 16);
1554 wpa_eapol_key_mic(wpa_s
->ptk
.mic_key
, ver
, buf
, len
,
1556 if (memcmp(mic
, key
->key_mic
, 16) != 0) {
1557 wpa_printf(MSG_WARNING
, "WPA: Invalid EAPOL-Key MIC "
1558 "- dropping packet");
1565 wpa_printf(MSG_WARNING
, "WPA: Could not verify EAPOL-Key MIC "
1566 "- dropping packet");
1570 (void) memcpy(wpa_s
->rx_replay_counter
, key
->replay_counter
,
1571 WPA_REPLAY_COUNTER_LEN
);
1572 wpa_s
->rx_replay_counter_set
= 1;
1577 /* Decrypt RSN EAPOL-Key key data (RC4 or AES-WRAP) */
1579 wpa_supplicant_decrypt_key_data(struct wpa_supplicant
*wpa_s
,
1580 struct wpa_eapol_key
*key
, int ver
)
1582 int keydatalen
= BE_16(key
->key_data_length
);
1584 wpa_hexdump(MSG_DEBUG
, "RSN: encrypted key data",
1585 (uint8_t *)(key
+ 1), keydatalen
);
1586 if (!wpa_s
->ptk_set
) {
1587 wpa_printf(MSG_WARNING
, "WPA: PTK not available, "
1588 "cannot decrypt EAPOL-Key key data.");
1593 * Decrypt key data here so that this operation does not need
1594 * to be implemented separately for each message type.
1596 if (ver
== WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
) {
1598 (void) memcpy(ek
, key
->key_iv
, 16);
1599 (void) memcpy(ek
+ 16, wpa_s
->ptk
.encr_key
, 16);
1600 rc4_skip(ek
, 32, 256, (uint8_t *)(key
+ 1), keydatalen
);
1601 } else if (ver
== WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
) {
1603 if (keydatalen
% 8) {
1604 wpa_printf(MSG_WARNING
, "WPA: Unsupported "
1605 "AES-WRAP len %d", keydatalen
);
1608 keydatalen
-= 8; /* AES-WRAP adds 8 bytes */
1609 buf
= malloc(keydatalen
);
1611 wpa_printf(MSG_WARNING
, "WPA: No memory for "
1612 "AES-UNWRAP buffer");
1615 if (aes_unwrap(wpa_s
->ptk
.encr_key
, keydatalen
/ 8,
1616 (uint8_t *)(key
+ 1), buf
)) {
1618 wpa_printf(MSG_WARNING
, "WPA: AES unwrap failed - "
1619 "could not decrypt EAPOL-Key key data");
1622 (void) memcpy(key
+ 1, buf
, keydatalen
);
1624 key
->key_data_length
= BE_16(keydatalen
);
1626 wpa_hexdump(MSG_DEBUG
, "WPA: decrypted EAPOL-Key key data",
1627 (uint8_t *)(key
+ 1), keydatalen
);
1633 wpa_sm_rx_eapol(struct wpa_supplicant
*wpa_s
,
1634 unsigned char *src_addr
, unsigned char *buf
, size_t len
)
1636 size_t plen
, data_len
, extra_len
;
1637 struct ieee802_1x_hdr
*hdr
;
1638 struct wpa_eapol_key
*key
;
1641 wpa_printf(MSG_DEBUG
, "WPA: EAPOL frame len %u\n ", len
);
1643 hdr
= (struct ieee802_1x_hdr
*)buf
;
1644 key
= (struct wpa_eapol_key
*)(hdr
+ 1);
1645 wpa_printf(MSG_DEBUG
, "hdr_len=%u, key_len=%u",
1646 sizeof (*hdr
), sizeof (*key
));
1647 if (len
< sizeof (*hdr
) + sizeof (*key
)) {
1648 wpa_printf(MSG_DEBUG
, "WPA: EAPOL frame too short, len %u, "
1649 "expecting at least %u",
1650 len
, sizeof (*hdr
) + sizeof (*key
));
1653 plen
= ntohs(hdr
->length
);
1654 data_len
= plen
+ sizeof (*hdr
);
1655 wpa_printf(MSG_DEBUG
, "IEEE 802.1X RX: version=%d type=%d length=%d",
1656 hdr
->version
, hdr
->type
, plen
);
1658 if (hdr
->type
!= IEEE802_1X_TYPE_EAPOL_KEY
) {
1659 wpa_printf(MSG_DEBUG
, "WPA: EAPOL frame (type %u) discarded, "
1660 "not a Key frame", hdr
->type
);
1663 if (plen
> len
- sizeof (*hdr
) || plen
< sizeof (*key
)) {
1664 wpa_printf(MSG_DEBUG
, "WPA: EAPOL frame payload size %u "
1665 "invalid (frame size %u)", plen
, len
);
1669 wpa_printf(MSG_DEBUG
, " EAPOL-Key type=%d", key
->type
);
1670 if (key
->type
!= EAPOL_KEY_TYPE_WPA
&& key
->type
!=
1671 EAPOL_KEY_TYPE_RSN
) {
1672 wpa_printf(MSG_DEBUG
, "WPA: EAPOL-Key type (%d) unknown, "
1673 "discarded", key
->type
);
1677 wpa_hexdump(MSG_MSGDUMP
, "WPA: RX EAPOL-Key", buf
, len
);
1678 if (data_len
< len
) {
1679 wpa_printf(MSG_DEBUG
, "WPA: ignoring %d bytes after the IEEE "
1680 "802.1X data", len
- data_len
);
1682 key_info
= BE_16(key
->key_info
);
1683 ver
= key_info
& WPA_KEY_INFO_TYPE_MASK
;
1684 if (ver
!= WPA_KEY_INFO_TYPE_HMAC_MD5_RC4
&&
1685 ver
!= WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
) {
1686 wpa_printf(MSG_INFO
, "WPA: Unsupported EAPOL-Key descriptor "
1687 "version %d.", ver
);
1691 if (wpa_s
->pairwise_cipher
== WPA_CIPHER_CCMP
&&
1692 ver
!= WPA_KEY_INFO_TYPE_HMAC_SHA1_AES
) {
1693 wpa_printf(MSG_INFO
, "WPA: CCMP is used, but EAPOL-Key "
1694 "descriptor version (%d) is not 2.", ver
);
1695 if (wpa_s
->group_cipher
!= WPA_CIPHER_CCMP
&&
1696 !(key_info
& WPA_KEY_INFO_KEY_TYPE
)) {
1698 * Earlier versions of IEEE 802.11i did not explicitly
1699 * require version 2 descriptor for all EAPOL-Key
1700 * packets, so allow group keys to use version 1 if
1701 * CCMP is not used for them.
1703 wpa_printf(MSG_INFO
, "WPA: Backwards compatibility: "
1704 "allow invalid version for non-CCMP group keys");
1709 if (wpa_s
->rx_replay_counter_set
&&
1710 memcmp(key
->replay_counter
, wpa_s
->rx_replay_counter
,
1711 WPA_REPLAY_COUNTER_LEN
) <= 0) {
1712 wpa_printf(MSG_WARNING
, "WPA: EAPOL-Key Replay Counter did not"
1713 " increase - dropping packet");
1717 if (!(key_info
& WPA_KEY_INFO_ACK
)) {
1718 wpa_printf(MSG_INFO
, "WPA: No Ack bit in key_info");
1722 if (key_info
& WPA_KEY_INFO_REQUEST
) {
1723 wpa_printf(MSG_INFO
, "WPA: EAPOL-Key with Request bit - "
1728 if ((key_info
& WPA_KEY_INFO_MIC
) &&
1729 wpa_supplicant_verify_eapol_key_mic(wpa_s
, key
, ver
, buf
,
1734 extra_len
= data_len
- sizeof (*hdr
) - sizeof (*key
);
1736 if (wpa_s
->proto
== WPA_PROTO_RSN
&&
1737 (key_info
& WPA_KEY_INFO_ENCR_KEY_DATA
) &&
1738 wpa_supplicant_decrypt_key_data(wpa_s
, key
, ver
))
1741 if (key_info
& WPA_KEY_INFO_KEY_TYPE
) {
1742 if (key_info
& WPA_KEY_INFO_KEY_INDEX_MASK
) {
1743 wpa_printf(MSG_WARNING
, "WPA: Ignored EAPOL-Key "
1744 "(Pairwise) with non-zero key index");
1747 if (key_info
& WPA_KEY_INFO_MIC
) {
1748 /* 3/4 4-Way Handshake */
1749 wpa_supplicant_process_3_of_4(wpa_s
, src_addr
, key
,
1752 /* 1/4 4-Way Handshake */
1753 wpa_supplicant_process_1_of_4(wpa_s
, src_addr
, key
,
1757 if (key_info
& WPA_KEY_INFO_MIC
) {
1758 /* 1/2 Group Key Handshake */
1759 wpa_supplicant_process_1_of_2(wpa_s
, src_addr
, key
,
1762 wpa_printf(MSG_WARNING
, "WPA: EAPOL-Key (Group) "
1763 "without Mic bit - dropped");
1769 wpa_supplicant_rx_eapol(void *ctx
, unsigned char *src_addr
,
1770 unsigned char *buf
, size_t len
)
1772 struct wpa_supplicant
*wpa_s
= ctx
;
1774 wpa_printf(MSG_DEBUG
, "RX EAPOL from " MACSTR
, MAC2STR(src_addr
));
1775 wpa_hexdump(MSG_MSGDUMP
, "RX EAPOL", buf
, len
);
1777 if (wpa_s
->eapol_received
== 0) {
1778 /* Timeout for completing IEEE 802.1X and WPA authentication */
1779 wpa_supplicant_req_auth_timeout(
1780 wpa_s
, wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X
?
1783 wpa_s
->eapol_received
++;
1786 * Source address of the incoming EAPOL frame could be compared to the
1787 * current BSSID. However, it is possible that a centralized
1788 * Authenticator could be using another MAC address than the BSSID of
1789 * an AP, so just allow any address to be used for now. The replies are
1790 * still sent to the current BSSID (if available), though.
1792 wpa_sm_rx_eapol(wpa_s
, src_addr
, buf
, len
);