2 * hostapd - WPA/RSN IE and KDE definitions
3 * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
19 #include "ieee802_11.h"
22 #include "pmksa_cache.h"
23 #include "wpa_auth_ie.h"
24 #include "wpa_auth_i.h"
27 static int wpa_write_wpa_ie(struct wpa_auth_config *conf, u8 *buf, size_t len)
29 struct wpa_ie_hdr *hdr;
33 hdr = (struct wpa_ie_hdr *) buf;
34 hdr->elem_id = WLAN_EID_VENDOR_SPECIFIC;
35 RSN_SELECTOR_PUT(hdr->oui, WPA_OUI_TYPE);
36 WPA_PUT_LE16(hdr->version, WPA_VERSION);
37 pos = (u8 *) (hdr + 1);
39 if (conf->wpa_group == WPA_CIPHER_CCMP) {
40 RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_CCMP);
41 } else if (conf->wpa_group == WPA_CIPHER_TKIP) {
42 RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_TKIP);
43 } else if (conf->wpa_group == WPA_CIPHER_WEP104) {
44 RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_WEP104);
45 } else if (conf->wpa_group == WPA_CIPHER_WEP40) {
46 RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_WEP40);
48 wpa_printf(MSG_DEBUG, "Invalid group cipher (%d).",
52 pos += WPA_SELECTOR_LEN;
58 if (conf->wpa_pairwise & WPA_CIPHER_CCMP) {
59 RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_CCMP);
60 pos += WPA_SELECTOR_LEN;
63 if (conf->wpa_pairwise & WPA_CIPHER_TKIP) {
64 RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_TKIP);
65 pos += WPA_SELECTOR_LEN;
68 if (conf->wpa_pairwise & WPA_CIPHER_NONE) {
69 RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_NONE);
70 pos += WPA_SELECTOR_LEN;
74 if (num_suites == 0) {
75 wpa_printf(MSG_DEBUG, "Invalid pairwise cipher (%d).",
79 WPA_PUT_LE16(count, num_suites);
85 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
86 RSN_SELECTOR_PUT(pos, WPA_AUTH_KEY_MGMT_UNSPEC_802_1X);
87 pos += WPA_SELECTOR_LEN;
90 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) {
91 RSN_SELECTOR_PUT(pos, WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X);
92 pos += WPA_SELECTOR_LEN;
96 if (num_suites == 0) {
97 wpa_printf(MSG_DEBUG, "Invalid key management type (%d).",
101 WPA_PUT_LE16(count, num_suites);
103 /* WPA Capabilities; use defaults, so no need to include it */
105 hdr->len = (pos - buf) - 2;
111 int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
114 struct rsn_ie_hdr *hdr;
119 hdr = (struct rsn_ie_hdr *) buf;
120 hdr->elem_id = WLAN_EID_RSN;
121 WPA_PUT_LE16(hdr->version, RSN_VERSION);
122 pos = (u8 *) (hdr + 1);
124 if (conf->wpa_group == WPA_CIPHER_CCMP) {
125 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
126 } else if (conf->wpa_group == WPA_CIPHER_TKIP) {
127 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
128 } else if (conf->wpa_group == WPA_CIPHER_WEP104) {
129 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_WEP104);
130 } else if (conf->wpa_group == WPA_CIPHER_WEP40) {
131 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_WEP40);
133 wpa_printf(MSG_DEBUG, "Invalid group cipher (%d).",
137 pos += RSN_SELECTOR_LEN;
143 if (conf->rsn_pairwise & WPA_CIPHER_CCMP) {
144 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
145 pos += RSN_SELECTOR_LEN;
148 if (conf->rsn_pairwise & WPA_CIPHER_TKIP) {
149 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
150 pos += RSN_SELECTOR_LEN;
153 if (conf->rsn_pairwise & WPA_CIPHER_NONE) {
154 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_NONE);
155 pos += RSN_SELECTOR_LEN;
159 if (num_suites == 0) {
160 wpa_printf(MSG_DEBUG, "Invalid pairwise cipher (%d).",
164 WPA_PUT_LE16(count, num_suites);
170 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
171 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_UNSPEC_802_1X);
172 pos += RSN_SELECTOR_LEN;
175 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) {
176 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X);
177 pos += RSN_SELECTOR_LEN;
180 #ifdef CONFIG_IEEE80211R
181 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
182 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_802_1X);
183 pos += RSN_SELECTOR_LEN;
186 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_PSK) {
187 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_PSK);
188 pos += RSN_SELECTOR_LEN;
191 #endif /* CONFIG_IEEE80211R */
192 #ifdef CONFIG_IEEE80211W
193 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
194 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_802_1X_SHA256);
195 pos += RSN_SELECTOR_LEN;
198 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
199 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_PSK_SHA256);
200 pos += RSN_SELECTOR_LEN;
203 #endif /* CONFIG_IEEE80211W */
205 if (num_suites == 0) {
206 wpa_printf(MSG_DEBUG, "Invalid key management type (%d).",
210 WPA_PUT_LE16(count, num_suites);
212 /* RSN Capabilities */
214 if (conf->rsn_preauth)
215 capab |= WPA_CAPABILITY_PREAUTH;
217 capab |= WPA_CAPABILITY_PEERKEY_ENABLED;
218 if (conf->wme_enabled) {
219 /* 4 PTKSA replay counters when using WME */
220 capab |= (RSN_NUM_REPLAY_COUNTERS_16 << 2);
222 #ifdef CONFIG_IEEE80211W
223 if (conf->ieee80211w != WPA_NO_IEEE80211W) {
224 capab |= WPA_CAPABILITY_MFPC;
225 if (conf->ieee80211w == IEEE80211W_REQUIRED)
226 capab |= WPA_CAPABILITY_MFPR;
228 #endif /* CONFIG_IEEE80211W */
229 WPA_PUT_LE16(pos, capab);
233 if (pos + 2 + PMKID_LEN > buf + len)
236 WPA_PUT_LE16(pos, 1);
238 os_memcpy(pos, pmkid, PMKID_LEN);
242 #ifdef CONFIG_IEEE80211W
243 if (conf->ieee80211w != WPA_NO_IEEE80211W) {
244 if (pos + 2 + 4 > buf + len)
248 WPA_PUT_LE16(pos, 0);
252 /* Management Group Cipher Suite */
253 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_AES_128_CMAC);
254 pos += RSN_SELECTOR_LEN;
256 #endif /* CONFIG_IEEE80211W */
258 hdr->len = (pos - buf) - 2;
264 int wpa_auth_gen_wpa_ie(struct wpa_authenticator *wpa_auth)
271 if (wpa_auth->conf.wpa & WPA_PROTO_RSN) {
272 res = wpa_write_rsn_ie(&wpa_auth->conf,
273 pos, buf + sizeof(buf) - pos, NULL);
278 #ifdef CONFIG_IEEE80211R
279 if (wpa_auth->conf.wpa_key_mgmt &
280 (WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK)) {
281 res = wpa_write_mdie(&wpa_auth->conf, pos,
282 buf + sizeof(buf) - pos);
287 #endif /* CONFIG_IEEE80211R */
288 if (wpa_auth->conf.wpa & WPA_PROTO_WPA) {
289 res = wpa_write_wpa_ie(&wpa_auth->conf,
290 pos, buf + sizeof(buf) - pos);
296 os_free(wpa_auth->wpa_ie);
297 wpa_auth->wpa_ie = os_malloc(pos - buf);
298 if (wpa_auth->wpa_ie == NULL)
300 os_memcpy(wpa_auth->wpa_ie, buf, pos - buf);
301 wpa_auth->wpa_ie_len = pos - buf;
307 u8 * wpa_add_kde(u8 *pos, u32 kde, const u8 *data, size_t data_len,
308 const u8 *data2, size_t data2_len)
310 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
311 *pos++ = RSN_SELECTOR_LEN + data_len + data2_len;
312 RSN_SELECTOR_PUT(pos, kde);
313 pos += RSN_SELECTOR_LEN;
314 os_memcpy(pos, data, data_len);
317 os_memcpy(pos, data2, data2_len);
324 static int wpa_selector_to_bitfield(const u8 *s)
326 if (RSN_SELECTOR_GET(s) == WPA_CIPHER_SUITE_NONE)
327 return WPA_CIPHER_NONE;
328 if (RSN_SELECTOR_GET(s) == WPA_CIPHER_SUITE_WEP40)
329 return WPA_CIPHER_WEP40;
330 if (RSN_SELECTOR_GET(s) == WPA_CIPHER_SUITE_TKIP)
331 return WPA_CIPHER_TKIP;
332 if (RSN_SELECTOR_GET(s) == WPA_CIPHER_SUITE_CCMP)
333 return WPA_CIPHER_CCMP;
334 if (RSN_SELECTOR_GET(s) == WPA_CIPHER_SUITE_WEP104)
335 return WPA_CIPHER_WEP104;
340 static int wpa_key_mgmt_to_bitfield(const u8 *s)
342 if (RSN_SELECTOR_GET(s) == WPA_AUTH_KEY_MGMT_UNSPEC_802_1X)
343 return WPA_KEY_MGMT_IEEE8021X;
344 if (RSN_SELECTOR_GET(s) == WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X)
345 return WPA_KEY_MGMT_PSK;
346 if (RSN_SELECTOR_GET(s) == WPA_AUTH_KEY_MGMT_NONE)
347 return WPA_KEY_MGMT_WPA_NONE;
352 static int wpa_parse_wpa_ie_wpa(const u8 *wpa_ie, size_t wpa_ie_len,
353 struct wpa_ie_data *data)
355 const struct wpa_ie_hdr *hdr;
360 os_memset(data, 0, sizeof(*data));
361 data->pairwise_cipher = WPA_CIPHER_TKIP;
362 data->group_cipher = WPA_CIPHER_TKIP;
363 data->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
364 data->mgmt_group_cipher = 0;
366 if (wpa_ie_len < sizeof(struct wpa_ie_hdr))
369 hdr = (const struct wpa_ie_hdr *) wpa_ie;
371 if (hdr->elem_id != WLAN_EID_VENDOR_SPECIFIC ||
372 hdr->len != wpa_ie_len - 2 ||
373 RSN_SELECTOR_GET(hdr->oui) != WPA_OUI_TYPE ||
374 WPA_GET_LE16(hdr->version) != WPA_VERSION) {
378 pos = (const u8 *) (hdr + 1);
379 left = wpa_ie_len - sizeof(*hdr);
381 if (left >= WPA_SELECTOR_LEN) {
382 data->group_cipher = wpa_selector_to_bitfield(pos);
383 pos += WPA_SELECTOR_LEN;
384 left -= WPA_SELECTOR_LEN;
389 data->pairwise_cipher = 0;
390 count = WPA_GET_LE16(pos);
393 if (count == 0 || left < count * WPA_SELECTOR_LEN)
395 for (i = 0; i < count; i++) {
396 data->pairwise_cipher |= wpa_selector_to_bitfield(pos);
397 pos += WPA_SELECTOR_LEN;
398 left -= WPA_SELECTOR_LEN;
400 } else if (left == 1)
405 count = WPA_GET_LE16(pos);
408 if (count == 0 || left < count * WPA_SELECTOR_LEN)
410 for (i = 0; i < count; i++) {
411 data->key_mgmt |= wpa_key_mgmt_to_bitfield(pos);
412 pos += WPA_SELECTOR_LEN;
413 left -= WPA_SELECTOR_LEN;
415 } else if (left == 1)
419 data->capabilities = WPA_GET_LE16(pos);
432 struct wpa_auth_okc_iter_data {
433 struct rsn_pmksa_cache_entry *pmksa;
440 static int wpa_auth_okc_iter(struct wpa_authenticator *a, void *ctx)
442 struct wpa_auth_okc_iter_data *data = ctx;
443 data->pmksa = pmksa_cache_get_okc(a->pmksa, data->aa, data->spa,
451 int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
452 struct wpa_state_machine *sm,
453 const u8 *wpa_ie, size_t wpa_ie_len,
454 const u8 *mdie, size_t mdie_len)
456 struct wpa_ie_data data;
457 int ciphers, key_mgmt, res, version;
460 const u8 *pmkid = NULL;
462 if (wpa_auth == NULL || sm == NULL)
463 return WPA_NOT_ENABLED;
465 if (wpa_ie == NULL || wpa_ie_len < 1)
466 return WPA_INVALID_IE;
468 if (wpa_ie[0] == WLAN_EID_RSN)
469 version = WPA_PROTO_RSN;
471 version = WPA_PROTO_WPA;
473 if (version == WPA_PROTO_RSN) {
474 res = wpa_parse_wpa_ie_rsn(wpa_ie, wpa_ie_len, &data);
476 selector = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X;
479 #ifdef CONFIG_IEEE80211R
480 else if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
481 selector = RSN_AUTH_KEY_MGMT_FT_802_1X;
482 else if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK)
483 selector = RSN_AUTH_KEY_MGMT_FT_PSK;
484 #endif /* CONFIG_IEEE80211R */
485 #ifdef CONFIG_IEEE80211W
486 else if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
487 selector = RSN_AUTH_KEY_MGMT_802_1X_SHA256;
488 else if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
489 selector = RSN_AUTH_KEY_MGMT_PSK_SHA256;
490 #endif /* CONFIG_IEEE80211W */
491 else if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X)
492 selector = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X;
493 else if (data.key_mgmt & WPA_KEY_MGMT_PSK)
494 selector = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
495 wpa_auth->dot11RSNAAuthenticationSuiteSelected = selector;
497 selector = RSN_CIPHER_SUITE_CCMP;
498 if (data.pairwise_cipher & WPA_CIPHER_CCMP)
499 selector = RSN_CIPHER_SUITE_CCMP;
500 else if (data.pairwise_cipher & WPA_CIPHER_TKIP)
501 selector = RSN_CIPHER_SUITE_TKIP;
502 else if (data.pairwise_cipher & WPA_CIPHER_WEP104)
503 selector = RSN_CIPHER_SUITE_WEP104;
504 else if (data.pairwise_cipher & WPA_CIPHER_WEP40)
505 selector = RSN_CIPHER_SUITE_WEP40;
506 else if (data.pairwise_cipher & WPA_CIPHER_NONE)
507 selector = RSN_CIPHER_SUITE_NONE;
508 wpa_auth->dot11RSNAPairwiseCipherSelected = selector;
510 selector = RSN_CIPHER_SUITE_CCMP;
511 if (data.group_cipher & WPA_CIPHER_CCMP)
512 selector = RSN_CIPHER_SUITE_CCMP;
513 else if (data.group_cipher & WPA_CIPHER_TKIP)
514 selector = RSN_CIPHER_SUITE_TKIP;
515 else if (data.group_cipher & WPA_CIPHER_WEP104)
516 selector = RSN_CIPHER_SUITE_WEP104;
517 else if (data.group_cipher & WPA_CIPHER_WEP40)
518 selector = RSN_CIPHER_SUITE_WEP40;
519 else if (data.group_cipher & WPA_CIPHER_NONE)
520 selector = RSN_CIPHER_SUITE_NONE;
521 wpa_auth->dot11RSNAGroupCipherSelected = selector;
523 res = wpa_parse_wpa_ie_wpa(wpa_ie, wpa_ie_len, &data);
525 selector = WPA_AUTH_KEY_MGMT_UNSPEC_802_1X;
526 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X)
527 selector = WPA_AUTH_KEY_MGMT_UNSPEC_802_1X;
528 else if (data.key_mgmt & WPA_KEY_MGMT_PSK)
529 selector = WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X;
530 wpa_auth->dot11RSNAAuthenticationSuiteSelected = selector;
532 selector = WPA_CIPHER_SUITE_TKIP;
533 if (data.pairwise_cipher & WPA_CIPHER_CCMP)
534 selector = WPA_CIPHER_SUITE_CCMP;
535 else if (data.pairwise_cipher & WPA_CIPHER_TKIP)
536 selector = WPA_CIPHER_SUITE_TKIP;
537 else if (data.pairwise_cipher & WPA_CIPHER_WEP104)
538 selector = WPA_CIPHER_SUITE_WEP104;
539 else if (data.pairwise_cipher & WPA_CIPHER_WEP40)
540 selector = WPA_CIPHER_SUITE_WEP40;
541 else if (data.pairwise_cipher & WPA_CIPHER_NONE)
542 selector = WPA_CIPHER_SUITE_NONE;
543 wpa_auth->dot11RSNAPairwiseCipherSelected = selector;
545 selector = WPA_CIPHER_SUITE_TKIP;
546 if (data.group_cipher & WPA_CIPHER_CCMP)
547 selector = WPA_CIPHER_SUITE_CCMP;
548 else if (data.group_cipher & WPA_CIPHER_TKIP)
549 selector = WPA_CIPHER_SUITE_TKIP;
550 else if (data.group_cipher & WPA_CIPHER_WEP104)
551 selector = WPA_CIPHER_SUITE_WEP104;
552 else if (data.group_cipher & WPA_CIPHER_WEP40)
553 selector = WPA_CIPHER_SUITE_WEP40;
554 else if (data.group_cipher & WPA_CIPHER_NONE)
555 selector = WPA_CIPHER_SUITE_NONE;
556 wpa_auth->dot11RSNAGroupCipherSelected = selector;
559 wpa_printf(MSG_DEBUG, "Failed to parse WPA/RSN IE from "
560 MACSTR " (res=%d)", MAC2STR(sm->addr), res);
561 wpa_hexdump(MSG_DEBUG, "WPA/RSN IE", wpa_ie, wpa_ie_len);
562 return WPA_INVALID_IE;
565 if (data.group_cipher != wpa_auth->conf.wpa_group) {
566 wpa_printf(MSG_DEBUG, "Invalid WPA group cipher (0x%x) from "
567 MACSTR, data.group_cipher, MAC2STR(sm->addr));
568 return WPA_INVALID_GROUP;
571 key_mgmt = data.key_mgmt & wpa_auth->conf.wpa_key_mgmt;
573 wpa_printf(MSG_DEBUG, "Invalid WPA key mgmt (0x%x) from "
574 MACSTR, data.key_mgmt, MAC2STR(sm->addr));
575 return WPA_INVALID_AKMP;
579 #ifdef CONFIG_IEEE80211R
580 else if (key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X)
581 sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X;
582 else if (key_mgmt & WPA_KEY_MGMT_FT_PSK)
583 sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_PSK;
584 #endif /* CONFIG_IEEE80211R */
585 #ifdef CONFIG_IEEE80211W
586 else if (key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
587 sm->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA256;
588 else if (key_mgmt & WPA_KEY_MGMT_PSK_SHA256)
589 sm->wpa_key_mgmt = WPA_KEY_MGMT_PSK_SHA256;
590 #endif /* CONFIG_IEEE80211W */
591 else if (key_mgmt & WPA_KEY_MGMT_IEEE8021X)
592 sm->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X;
594 sm->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
596 if (version == WPA_PROTO_RSN)
597 ciphers = data.pairwise_cipher & wpa_auth->conf.rsn_pairwise;
599 ciphers = data.pairwise_cipher & wpa_auth->conf.wpa_pairwise;
601 wpa_printf(MSG_DEBUG, "Invalid %s pairwise cipher (0x%x) "
603 version == WPA_PROTO_RSN ? "RSN" : "WPA",
604 data.pairwise_cipher, MAC2STR(sm->addr));
605 return WPA_INVALID_PAIRWISE;
608 #ifdef CONFIG_IEEE80211W
609 if (wpa_auth->conf.ieee80211w == WPA_IEEE80211W_REQUIRED) {
610 if (!(data.capabilities & WPA_CAPABILITY_MFPC)) {
611 wpa_printf(MSG_DEBUG, "Management frame protection "
612 "required, but client did not enable it");
613 return WPA_MGMT_FRAME_PROTECTION_VIOLATION;
616 if (ciphers & WPA_CIPHER_TKIP) {
617 wpa_printf(MSG_DEBUG, "Management frame protection "
619 return WPA_MGMT_FRAME_PROTECTION_VIOLATION;
622 if (data.mgmt_group_cipher != WPA_CIPHER_AES_128_CMAC) {
623 wpa_printf(MSG_DEBUG, "Unsupported management group "
624 "cipher %d", data.mgmt_group_cipher);
625 return WPA_INVALID_MGMT_GROUP_CIPHER;
629 if (wpa_auth->conf.ieee80211w == WPA_NO_IEEE80211W ||
630 !(data.capabilities & WPA_CAPABILITY_MFPC))
631 sm->mgmt_frame_prot = 0;
633 sm->mgmt_frame_prot = 1;
634 #endif /* CONFIG_IEEE80211W */
636 #ifdef CONFIG_IEEE80211R
637 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) {
638 if (mdie == NULL || mdie_len < MOBILITY_DOMAIN_ID_LEN + 1) {
639 wpa_printf(MSG_DEBUG, "RSN: Trying to use FT, but "
640 "MDIE not included");
641 return WPA_INVALID_MDIE;
643 if (os_memcmp(mdie, wpa_auth->conf.mobility_domain,
644 MOBILITY_DOMAIN_ID_LEN) != 0) {
645 wpa_hexdump(MSG_DEBUG, "RSN: Attempted to use unknown "
646 "MDIE", mdie, MOBILITY_DOMAIN_ID_LEN);
647 return WPA_INVALID_MDIE;
650 #endif /* CONFIG_IEEE80211R */
652 if (ciphers & WPA_CIPHER_CCMP)
653 sm->pairwise = WPA_CIPHER_CCMP;
655 sm->pairwise = WPA_CIPHER_TKIP;
657 /* TODO: clear WPA/WPA2 state if STA changes from one to another */
658 if (wpa_ie[0] == WLAN_EID_RSN)
659 sm->wpa = WPA_VERSION_WPA2;
661 sm->wpa = WPA_VERSION_WPA;
664 for (i = 0; i < data.num_pmkid; i++) {
665 wpa_hexdump(MSG_DEBUG, "RSN IE: STA PMKID",
666 &data.pmkid[i * PMKID_LEN], PMKID_LEN);
667 sm->pmksa = pmksa_cache_get(wpa_auth->pmksa, sm->addr,
668 &data.pmkid[i * PMKID_LEN]);
670 pmkid = sm->pmksa->pmkid;
674 for (i = 0; sm->pmksa == NULL && wpa_auth->conf.okc &&
675 i < data.num_pmkid; i++) {
676 struct wpa_auth_okc_iter_data idata;
678 idata.aa = wpa_auth->addr;
679 idata.spa = sm->addr;
680 idata.pmkid = &data.pmkid[i * PMKID_LEN];
681 wpa_auth_for_each_auth(wpa_auth, wpa_auth_okc_iter, &idata);
683 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
684 "OKC match for PMKID");
685 sm->pmksa = pmksa_cache_add_okc(wpa_auth->pmksa,
694 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG,
695 "PMKID found from PMKSA cache "
696 "eap_type=%d vlan_id=%d",
697 sm->pmksa->eap_type_authsrv,
699 os_memcpy(wpa_auth->dot11RSNAPMKIDUsed, pmkid, PMKID_LEN);
702 if (sm->wpa_ie == NULL || sm->wpa_ie_len < wpa_ie_len) {
704 sm->wpa_ie = os_malloc(wpa_ie_len);
705 if (sm->wpa_ie == NULL)
706 return WPA_ALLOC_FAIL;
708 os_memcpy(sm->wpa_ie, wpa_ie, wpa_ie_len);
709 sm->wpa_ie_len = wpa_ie_len;
716 * wpa_parse_generic - Parse EAPOL-Key Key Data Generic IEs
717 * @pos: Pointer to the IE header
718 * @end: Pointer to the end of the Key Data buffer
719 * @ie: Pointer to parsed IE data
720 * Returns: 0 on success, 1 if end mark is found, -1 on failure
722 static int wpa_parse_generic(const u8 *pos, const u8 *end,
723 struct wpa_eapol_ie_parse *ie)
729 RSN_SELECTOR_GET(pos + 2) == WPA_OUI_TYPE &&
730 pos[2 + WPA_SELECTOR_LEN] == 1 &&
731 pos[2 + WPA_SELECTOR_LEN + 1] == 0) {
733 ie->wpa_ie_len = pos[1] + 2;
737 if (pos + 1 + RSN_SELECTOR_LEN < end &&
738 pos[1] >= RSN_SELECTOR_LEN + PMKID_LEN &&
739 RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_PMKID) {
740 ie->pmkid = pos + 2 + RSN_SELECTOR_LEN;
744 if (pos[1] > RSN_SELECTOR_LEN + 2 &&
745 RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_GROUPKEY) {
746 ie->gtk = pos + 2 + RSN_SELECTOR_LEN;
747 ie->gtk_len = pos[1] - RSN_SELECTOR_LEN;
751 if (pos[1] > RSN_SELECTOR_LEN + 2 &&
752 RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_MAC_ADDR) {
753 ie->mac_addr = pos + 2 + RSN_SELECTOR_LEN;
754 ie->mac_addr_len = pos[1] - RSN_SELECTOR_LEN;
758 #ifdef CONFIG_PEERKEY
759 if (pos[1] > RSN_SELECTOR_LEN + 2 &&
760 RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_SMK) {
761 ie->smk = pos + 2 + RSN_SELECTOR_LEN;
762 ie->smk_len = pos[1] - RSN_SELECTOR_LEN;
766 if (pos[1] > RSN_SELECTOR_LEN + 2 &&
767 RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_NONCE) {
768 ie->nonce = pos + 2 + RSN_SELECTOR_LEN;
769 ie->nonce_len = pos[1] - RSN_SELECTOR_LEN;
773 if (pos[1] > RSN_SELECTOR_LEN + 2 &&
774 RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_LIFETIME) {
775 ie->lifetime = pos + 2 + RSN_SELECTOR_LEN;
776 ie->lifetime_len = pos[1] - RSN_SELECTOR_LEN;
780 if (pos[1] > RSN_SELECTOR_LEN + 2 &&
781 RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_ERROR) {
782 ie->error = pos + 2 + RSN_SELECTOR_LEN;
783 ie->error_len = pos[1] - RSN_SELECTOR_LEN;
786 #endif /* CONFIG_PEERKEY */
788 #ifdef CONFIG_IEEE80211W
789 if (pos[1] > RSN_SELECTOR_LEN + 2 &&
790 RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_IGTK) {
791 ie->igtk = pos + 2 + RSN_SELECTOR_LEN;
792 ie->igtk_len = pos[1] - RSN_SELECTOR_LEN;
795 #endif /* CONFIG_IEEE80211W */
802 * wpa_parse_kde_ies - Parse EAPOL-Key Key Data IEs
803 * @buf: Pointer to the Key Data buffer
804 * @len: Key Data Length
805 * @ie: Pointer to parsed IE data
806 * Returns: 0 on success, -1 on failure
808 int wpa_parse_kde_ies(const u8 *buf, size_t len, struct wpa_eapol_ie_parse *ie)
813 os_memset(ie, 0, sizeof(*ie));
814 for (pos = buf, end = pos + len; pos + 1 < end; pos += 2 + pos[1]) {
815 if (pos[0] == 0xdd &&
816 ((pos == buf + len - 1) || pos[1] == 0)) {
820 if (pos + 2 + pos[1] > end) {
821 wpa_printf(MSG_DEBUG, "WPA: EAPOL-Key Key Data "
822 "underflow (ie=%d len=%d pos=%d)",
823 pos[0], pos[1], (int) (pos - buf));
824 wpa_hexdump_key(MSG_DEBUG, "WPA: Key Data",
829 if (*pos == WLAN_EID_RSN) {
831 ie->rsn_ie_len = pos[1] + 2;
832 #ifdef CONFIG_IEEE80211R
833 } else if (*pos == WLAN_EID_MOBILITY_DOMAIN) {
835 ie->mdie_len = pos[1] + 2;
836 #endif /* CONFIG_IEEE80211R */
837 } else if (*pos == WLAN_EID_VENDOR_SPECIFIC) {
838 ret = wpa_parse_generic(pos, end, ie);
846 wpa_hexdump(MSG_DEBUG, "WPA: Unrecognized EAPOL-Key "
847 "Key Data IE", pos, 2 + pos[1]);
855 int wpa_auth_uses_mfp(struct wpa_state_machine *sm)
857 return sm ? sm->mgmt_frame_prot : 0;