1 /* 2 * hostapd - WPA/RSN IE and KDE definitions 3 * Copyright (c) 2004-2018, Jouni Malinen <j@w1.fi> 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 9 #include "utils/includes.h" 10 11 #include "utils/common.h" 12 #include "common/ieee802_11_defs.h" 13 #include "eapol_auth/eapol_auth_sm.h" 14 #include "ap_config.h" 15 #include "ieee802_11.h" 16 #include "wpa_auth.h" 17 #include "pmksa_cache_auth.h" 18 #include "wpa_auth_ie.h" 19 #include "wpa_auth_i.h" 20 21 22 #ifdef CONFIG_RSN_TESTING 23 int rsn_testing = 0; 24 #endif /* CONFIG_RSN_TESTING */ 25 26 27 static int wpa_write_wpa_ie(struct wpa_auth_config *conf, u8 *buf, size_t len) 28 { 29 struct wpa_ie_hdr *hdr; 30 int num_suites; 31 u8 *pos, *count; 32 u32 suite; 33 34 hdr = (struct wpa_ie_hdr *) buf; 35 hdr->elem_id = WLAN_EID_VENDOR_SPECIFIC; 36 RSN_SELECTOR_PUT(hdr->oui, WPA_OUI_TYPE); 37 WPA_PUT_LE16(hdr->version, WPA_VERSION); 38 pos = (u8 *) (hdr + 1); 39 40 suite = wpa_cipher_to_suite(WPA_PROTO_WPA, conf->wpa_group); 41 if (suite == 0) { 42 wpa_printf(MSG_DEBUG, "Invalid group cipher (%d).", 43 conf->wpa_group); 44 return -1; 45 } 46 RSN_SELECTOR_PUT(pos, suite); 47 pos += WPA_SELECTOR_LEN; 48 49 count = pos; 50 pos += 2; 51 52 num_suites = wpa_cipher_put_suites(pos, conf->wpa_pairwise); 53 if (num_suites == 0) { 54 wpa_printf(MSG_DEBUG, "Invalid pairwise cipher (%d).", 55 conf->wpa_pairwise); 56 return -1; 57 } 58 pos += num_suites * WPA_SELECTOR_LEN; 59 WPA_PUT_LE16(count, num_suites); 60 61 num_suites = 0; 62 count = pos; 63 pos += 2; 64 65 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) { 66 RSN_SELECTOR_PUT(pos, WPA_AUTH_KEY_MGMT_UNSPEC_802_1X); 67 pos += WPA_SELECTOR_LEN; 68 num_suites++; 69 } 70 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) { 71 RSN_SELECTOR_PUT(pos, WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X); 72 pos += WPA_SELECTOR_LEN; 73 num_suites++; 74 } 75 76 if (num_suites == 0) { 77 wpa_printf(MSG_DEBUG, "Invalid key management type (%d).", 78 conf->wpa_key_mgmt); 79 return -1; 80 } 81 WPA_PUT_LE16(count, num_suites); 82 83 /* WPA Capabilities; use defaults, so no need to include it */ 84 85 hdr->len = (pos - buf) - 2; 86 87 return pos - buf; 88 } 89 90 91 int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len, 92 const u8 *pmkid) 93 { 94 struct rsn_ie_hdr *hdr; 95 int num_suites, res; 96 u8 *pos, *count; 97 u16 capab; 98 u32 suite; 99 100 hdr = (struct rsn_ie_hdr *) buf; 101 hdr->elem_id = WLAN_EID_RSN; 102 WPA_PUT_LE16(hdr->version, RSN_VERSION); 103 pos = (u8 *) (hdr + 1); 104 105 suite = wpa_cipher_to_suite(WPA_PROTO_RSN, conf->wpa_group); 106 if (suite == 0) { 107 wpa_printf(MSG_DEBUG, "Invalid group cipher (%d).", 108 conf->wpa_group); 109 return -1; 110 } 111 RSN_SELECTOR_PUT(pos, suite); 112 pos += RSN_SELECTOR_LEN; 113 114 num_suites = 0; 115 count = pos; 116 pos += 2; 117 118 #ifdef CONFIG_RSN_TESTING 119 if (rsn_testing) { 120 RSN_SELECTOR_PUT(pos, RSN_SELECTOR(0x12, 0x34, 0x56, 1)); 121 pos += RSN_SELECTOR_LEN; 122 num_suites++; 123 } 124 #endif /* CONFIG_RSN_TESTING */ 125 126 res = rsn_cipher_put_suites(pos, conf->rsn_pairwise); 127 num_suites += res; 128 pos += res * RSN_SELECTOR_LEN; 129 130 #ifdef CONFIG_RSN_TESTING 131 if (rsn_testing) { 132 RSN_SELECTOR_PUT(pos, RSN_SELECTOR(0x12, 0x34, 0x56, 2)); 133 pos += RSN_SELECTOR_LEN; 134 num_suites++; 135 } 136 #endif /* CONFIG_RSN_TESTING */ 137 138 if (num_suites == 0) { 139 wpa_printf(MSG_DEBUG, "Invalid pairwise cipher (%d).", 140 conf->rsn_pairwise); 141 return -1; 142 } 143 WPA_PUT_LE16(count, num_suites); 144 145 num_suites = 0; 146 count = pos; 147 pos += 2; 148 149 #ifdef CONFIG_RSN_TESTING 150 if (rsn_testing) { 151 RSN_SELECTOR_PUT(pos, RSN_SELECTOR(0x12, 0x34, 0x56, 1)); 152 pos += RSN_SELECTOR_LEN; 153 num_suites++; 154 } 155 #endif /* CONFIG_RSN_TESTING */ 156 157 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) { 158 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_UNSPEC_802_1X); 159 pos += RSN_SELECTOR_LEN; 160 num_suites++; 161 } 162 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) { 163 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X); 164 pos += RSN_SELECTOR_LEN; 165 num_suites++; 166 } 167 #ifdef CONFIG_IEEE80211R_AP 168 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) { 169 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_802_1X); 170 pos += RSN_SELECTOR_LEN; 171 num_suites++; 172 } 173 #ifdef CONFIG_SHA384 174 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) { 175 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384); 176 pos += RSN_SELECTOR_LEN; 177 num_suites++; 178 } 179 #endif /* CONFIG_SHA384 */ 180 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_PSK) { 181 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_PSK); 182 pos += RSN_SELECTOR_LEN; 183 num_suites++; 184 } 185 #endif /* CONFIG_IEEE80211R_AP */ 186 #ifdef CONFIG_IEEE80211W 187 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) { 188 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_802_1X_SHA256); 189 pos += RSN_SELECTOR_LEN; 190 num_suites++; 191 } 192 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK_SHA256) { 193 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_PSK_SHA256); 194 pos += RSN_SELECTOR_LEN; 195 num_suites++; 196 } 197 #endif /* CONFIG_IEEE80211W */ 198 #ifdef CONFIG_SAE 199 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_SAE) { 200 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_SAE); 201 pos += RSN_SELECTOR_LEN; 202 num_suites++; 203 } 204 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_SAE) { 205 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_SAE); 206 pos += RSN_SELECTOR_LEN; 207 num_suites++; 208 } 209 #endif /* CONFIG_SAE */ 210 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { 211 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_802_1X_SUITE_B); 212 pos += RSN_SELECTOR_LEN; 213 num_suites++; 214 } 215 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { 216 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192); 217 pos += RSN_SELECTOR_LEN; 218 num_suites++; 219 } 220 #ifdef CONFIG_FILS 221 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FILS_SHA256) { 222 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FILS_SHA256); 223 pos += RSN_SELECTOR_LEN; 224 num_suites++; 225 } 226 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FILS_SHA384) { 227 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FILS_SHA384); 228 pos += RSN_SELECTOR_LEN; 229 num_suites++; 230 } 231 #ifdef CONFIG_IEEE80211R_AP 232 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) { 233 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_FILS_SHA256); 234 pos += RSN_SELECTOR_LEN; 235 num_suites++; 236 } 237 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) { 238 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_FT_FILS_SHA384); 239 pos += RSN_SELECTOR_LEN; 240 num_suites++; 241 } 242 #endif /* CONFIG_IEEE80211R_AP */ 243 #endif /* CONFIG_FILS */ 244 #ifdef CONFIG_OWE 245 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) { 246 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_OWE); 247 pos += RSN_SELECTOR_LEN; 248 num_suites++; 249 } 250 #endif /* CONFIG_OWE */ 251 #ifdef CONFIG_DPP 252 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) { 253 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_DPP); 254 pos += RSN_SELECTOR_LEN; 255 num_suites++; 256 } 257 #endif /* CONFIG_DPP */ 258 #ifdef CONFIG_HS20 259 if (conf->wpa_key_mgmt & WPA_KEY_MGMT_OSEN) { 260 RSN_SELECTOR_PUT(pos, RSN_AUTH_KEY_MGMT_OSEN); 261 pos += RSN_SELECTOR_LEN; 262 num_suites++; 263 } 264 #endif /* CONFIG_HS20 */ 265 266 #ifdef CONFIG_RSN_TESTING 267 if (rsn_testing) { 268 RSN_SELECTOR_PUT(pos, RSN_SELECTOR(0x12, 0x34, 0x56, 2)); 269 pos += RSN_SELECTOR_LEN; 270 num_suites++; 271 } 272 #endif /* CONFIG_RSN_TESTING */ 273 274 if (num_suites == 0) { 275 wpa_printf(MSG_DEBUG, "Invalid key management type (%d).", 276 conf->wpa_key_mgmt); 277 return -1; 278 } 279 WPA_PUT_LE16(count, num_suites); 280 281 /* RSN Capabilities */ 282 capab = 0; 283 if (conf->rsn_preauth) 284 capab |= WPA_CAPABILITY_PREAUTH; 285 if (conf->wmm_enabled) { 286 /* 4 PTKSA replay counters when using WMM */ 287 capab |= (RSN_NUM_REPLAY_COUNTERS_16 << 2); 288 } 289 #ifdef CONFIG_IEEE80211W 290 if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) { 291 capab |= WPA_CAPABILITY_MFPC; 292 if (conf->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) 293 capab |= WPA_CAPABILITY_MFPR; 294 } 295 #endif /* CONFIG_IEEE80211W */ 296 #ifdef CONFIG_RSN_TESTING 297 if (rsn_testing) 298 capab |= BIT(8) | BIT(14) | BIT(15); 299 #endif /* CONFIG_RSN_TESTING */ 300 WPA_PUT_LE16(pos, capab); 301 pos += 2; 302 303 if (pmkid) { 304 if (2 + PMKID_LEN > buf + len - pos) 305 return -1; 306 /* PMKID Count */ 307 WPA_PUT_LE16(pos, 1); 308 pos += 2; 309 os_memcpy(pos, pmkid, PMKID_LEN); 310 pos += PMKID_LEN; 311 } 312 313 #ifdef CONFIG_IEEE80211W 314 if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION && 315 conf->group_mgmt_cipher != WPA_CIPHER_AES_128_CMAC) { 316 if (2 + 4 > buf + len - pos) 317 return -1; 318 if (pmkid == NULL) { 319 /* PMKID Count */ 320 WPA_PUT_LE16(pos, 0); 321 pos += 2; 322 } 323 324 /* Management Group Cipher Suite */ 325 switch (conf->group_mgmt_cipher) { 326 case WPA_CIPHER_AES_128_CMAC: 327 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_AES_128_CMAC); 328 break; 329 case WPA_CIPHER_BIP_GMAC_128: 330 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_BIP_GMAC_128); 331 break; 332 case WPA_CIPHER_BIP_GMAC_256: 333 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_BIP_GMAC_256); 334 break; 335 case WPA_CIPHER_BIP_CMAC_256: 336 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_BIP_CMAC_256); 337 break; 338 default: 339 wpa_printf(MSG_DEBUG, 340 "Invalid group management cipher (0x%x)", 341 conf->group_mgmt_cipher); 342 return -1; 343 } 344 pos += RSN_SELECTOR_LEN; 345 } 346 #endif /* CONFIG_IEEE80211W */ 347 348 #ifdef CONFIG_RSN_TESTING 349 if (rsn_testing) { 350 /* 351 * Fill in any defined fields and add extra data to the end of 352 * the element. 353 */ 354 int pmkid_count_set = pmkid != NULL; 355 if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) 356 pmkid_count_set = 1; 357 /* PMKID Count */ 358 WPA_PUT_LE16(pos, 0); 359 pos += 2; 360 if (conf->ieee80211w == NO_MGMT_FRAME_PROTECTION) { 361 /* Management Group Cipher Suite */ 362 RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_AES_128_CMAC); 363 pos += RSN_SELECTOR_LEN; 364 } 365 366 os_memset(pos, 0x12, 17); 367 pos += 17; 368 } 369 #endif /* CONFIG_RSN_TESTING */ 370 371 hdr->len = (pos - buf) - 2; 372 373 return pos - buf; 374 } 375 376 377 static u8 * wpa_write_osen(struct wpa_auth_config *conf, u8 *eid) 378 { 379 u8 *len; 380 u16 capab; 381 382 *eid++ = WLAN_EID_VENDOR_SPECIFIC; 383 len = eid++; /* to be filled */ 384 WPA_PUT_BE24(eid, OUI_WFA); 385 eid += 3; 386 *eid++ = HS20_OSEN_OUI_TYPE; 387 388 /* Group Data Cipher Suite */ 389 RSN_SELECTOR_PUT(eid, RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED); 390 eid += RSN_SELECTOR_LEN; 391 392 /* Pairwise Cipher Suite Count and List */ 393 WPA_PUT_LE16(eid, 1); 394 eid += 2; 395 RSN_SELECTOR_PUT(eid, RSN_CIPHER_SUITE_CCMP); 396 eid += RSN_SELECTOR_LEN; 397 398 /* AKM Suite Count and List */ 399 WPA_PUT_LE16(eid, 1); 400 eid += 2; 401 RSN_SELECTOR_PUT(eid, RSN_AUTH_KEY_MGMT_OSEN); 402 eid += RSN_SELECTOR_LEN; 403 404 /* RSN Capabilities */ 405 capab = 0; 406 if (conf->wmm_enabled) { 407 /* 4 PTKSA replay counters when using WMM */ 408 capab |= (RSN_NUM_REPLAY_COUNTERS_16 << 2); 409 } 410 #ifdef CONFIG_IEEE80211W 411 if (conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) { 412 capab |= WPA_CAPABILITY_MFPC; 413 if (conf->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) 414 capab |= WPA_CAPABILITY_MFPR; 415 } 416 #endif /* CONFIG_IEEE80211W */ 417 WPA_PUT_LE16(eid, capab); 418 eid += 2; 419 420 *len = eid - len - 1; 421 422 return eid; 423 } 424 425 426 int wpa_auth_gen_wpa_ie(struct wpa_authenticator *wpa_auth) 427 { 428 u8 *pos, buf[128]; 429 int res; 430 431 #ifdef CONFIG_TESTING_OPTIONS 432 if (wpa_auth->conf.own_ie_override_len) { 433 wpa_hexdump(MSG_DEBUG, "WPA: Forced own IE(s) for testing", 434 wpa_auth->conf.own_ie_override, 435 wpa_auth->conf.own_ie_override_len); 436 os_free(wpa_auth->wpa_ie); 437 wpa_auth->wpa_ie = 438 os_malloc(wpa_auth->conf.own_ie_override_len); 439 if (wpa_auth->wpa_ie == NULL) 440 return -1; 441 os_memcpy(wpa_auth->wpa_ie, wpa_auth->conf.own_ie_override, 442 wpa_auth->conf.own_ie_override_len); 443 wpa_auth->wpa_ie_len = wpa_auth->conf.own_ie_override_len; 444 return 0; 445 } 446 #endif /* CONFIG_TESTING_OPTIONS */ 447 448 pos = buf; 449 450 if (wpa_auth->conf.wpa == WPA_PROTO_OSEN) { 451 pos = wpa_write_osen(&wpa_auth->conf, pos); 452 } 453 if (wpa_auth->conf.wpa & WPA_PROTO_RSN) { 454 res = wpa_write_rsn_ie(&wpa_auth->conf, 455 pos, buf + sizeof(buf) - pos, NULL); 456 if (res < 0) 457 return res; 458 pos += res; 459 } 460 #ifdef CONFIG_IEEE80211R_AP 461 if (wpa_key_mgmt_ft(wpa_auth->conf.wpa_key_mgmt)) { 462 res = wpa_write_mdie(&wpa_auth->conf, pos, 463 buf + sizeof(buf) - pos); 464 if (res < 0) 465 return res; 466 pos += res; 467 } 468 #endif /* CONFIG_IEEE80211R_AP */ 469 if (wpa_auth->conf.wpa & WPA_PROTO_WPA) { 470 res = wpa_write_wpa_ie(&wpa_auth->conf, 471 pos, buf + sizeof(buf) - pos); 472 if (res < 0) 473 return res; 474 pos += res; 475 } 476 477 os_free(wpa_auth->wpa_ie); 478 wpa_auth->wpa_ie = os_malloc(pos - buf); 479 if (wpa_auth->wpa_ie == NULL) 480 return -1; 481 os_memcpy(wpa_auth->wpa_ie, buf, pos - buf); 482 wpa_auth->wpa_ie_len = pos - buf; 483 484 return 0; 485 } 486 487 488 u8 * wpa_add_kde(u8 *pos, u32 kde, const u8 *data, size_t data_len, 489 const u8 *data2, size_t data2_len) 490 { 491 *pos++ = WLAN_EID_VENDOR_SPECIFIC; 492 *pos++ = RSN_SELECTOR_LEN + data_len + data2_len; 493 RSN_SELECTOR_PUT(pos, kde); 494 pos += RSN_SELECTOR_LEN; 495 os_memcpy(pos, data, data_len); 496 pos += data_len; 497 if (data2) { 498 os_memcpy(pos, data2, data2_len); 499 pos += data2_len; 500 } 501 return pos; 502 } 503 504 505 struct wpa_auth_okc_iter_data { 506 struct rsn_pmksa_cache_entry *pmksa; 507 const u8 *aa; 508 const u8 *spa; 509 const u8 *pmkid; 510 }; 511 512 513 static int wpa_auth_okc_iter(struct wpa_authenticator *a, void *ctx) 514 { 515 struct wpa_auth_okc_iter_data *data = ctx; 516 data->pmksa = pmksa_cache_get_okc(a->pmksa, data->aa, data->spa, 517 data->pmkid); 518 if (data->pmksa) 519 return 1; 520 return 0; 521 } 522 523 524 int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth, 525 struct wpa_state_machine *sm, 526 const u8 *wpa_ie, size_t wpa_ie_len, 527 const u8 *mdie, size_t mdie_len, 528 const u8 *owe_dh, size_t owe_dh_len) 529 { 530 struct wpa_ie_data data; 531 int ciphers, key_mgmt, res, version; 532 u32 selector; 533 size_t i; 534 const u8 *pmkid = NULL; 535 536 if (wpa_auth == NULL || sm == NULL) 537 return WPA_NOT_ENABLED; 538 539 if (wpa_ie == NULL || wpa_ie_len < 1) 540 return WPA_INVALID_IE; 541 542 if (wpa_ie[0] == WLAN_EID_RSN) 543 version = WPA_PROTO_RSN; 544 else 545 version = WPA_PROTO_WPA; 546 547 if (!(wpa_auth->conf.wpa & version)) { 548 wpa_printf(MSG_DEBUG, "Invalid WPA proto (%d) from " MACSTR, 549 version, MAC2STR(sm->addr)); 550 return WPA_INVALID_PROTO; 551 } 552 553 if (version == WPA_PROTO_RSN) { 554 res = wpa_parse_wpa_ie_rsn(wpa_ie, wpa_ie_len, &data); 555 556 selector = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; 557 if (0) { 558 } 559 else if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) 560 selector = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; 561 else if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) 562 selector = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; 563 #ifdef CONFIG_FILS 564 #ifdef CONFIG_IEEE80211R_AP 565 else if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) 566 selector = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; 567 else if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) 568 selector = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; 569 #endif /* CONFIG_IEEE80211R_AP */ 570 else if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) 571 selector = RSN_AUTH_KEY_MGMT_FILS_SHA384; 572 else if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) 573 selector = RSN_AUTH_KEY_MGMT_FILS_SHA256; 574 #endif /* CONFIG_FILS */ 575 #ifdef CONFIG_IEEE80211R_AP 576 #ifdef CONFIG_SHA384 577 else if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) 578 selector = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384; 579 #endif /* CONFIG_SHA384 */ 580 else if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) 581 selector = RSN_AUTH_KEY_MGMT_FT_802_1X; 582 else if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) 583 selector = RSN_AUTH_KEY_MGMT_FT_PSK; 584 #endif /* CONFIG_IEEE80211R_AP */ 585 #ifdef CONFIG_IEEE80211W 586 else if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) 587 selector = RSN_AUTH_KEY_MGMT_802_1X_SHA256; 588 else if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) 589 selector = RSN_AUTH_KEY_MGMT_PSK_SHA256; 590 #endif /* CONFIG_IEEE80211W */ 591 #ifdef CONFIG_SAE 592 else if (data.key_mgmt & WPA_KEY_MGMT_SAE) 593 selector = RSN_AUTH_KEY_MGMT_SAE; 594 else if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) 595 selector = RSN_AUTH_KEY_MGMT_FT_SAE; 596 #endif /* CONFIG_SAE */ 597 else if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) 598 selector = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; 599 else if (data.key_mgmt & WPA_KEY_MGMT_PSK) 600 selector = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; 601 #ifdef CONFIG_OWE 602 else if (data.key_mgmt & WPA_KEY_MGMT_OWE) 603 selector = RSN_AUTH_KEY_MGMT_OWE; 604 #endif /* CONFIG_OWE */ 605 #ifdef CONFIG_DPP 606 else if (data.key_mgmt & WPA_KEY_MGMT_DPP) 607 selector = RSN_AUTH_KEY_MGMT_DPP; 608 #endif /* CONFIG_DPP */ 609 #ifdef CONFIG_HS20 610 else if (data.key_mgmt & WPA_KEY_MGMT_OSEN) 611 selector = RSN_AUTH_KEY_MGMT_OSEN; 612 #endif /* CONFIG_HS20 */ 613 wpa_auth->dot11RSNAAuthenticationSuiteSelected = selector; 614 615 selector = wpa_cipher_to_suite(WPA_PROTO_RSN, 616 data.pairwise_cipher); 617 if (!selector) 618 selector = RSN_CIPHER_SUITE_CCMP; 619 wpa_auth->dot11RSNAPairwiseCipherSelected = selector; 620 621 selector = wpa_cipher_to_suite(WPA_PROTO_RSN, 622 data.group_cipher); 623 if (!selector) 624 selector = RSN_CIPHER_SUITE_CCMP; 625 wpa_auth->dot11RSNAGroupCipherSelected = selector; 626 } else { 627 res = wpa_parse_wpa_ie_wpa(wpa_ie, wpa_ie_len, &data); 628 629 selector = WPA_AUTH_KEY_MGMT_UNSPEC_802_1X; 630 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) 631 selector = WPA_AUTH_KEY_MGMT_UNSPEC_802_1X; 632 else if (data.key_mgmt & WPA_KEY_MGMT_PSK) 633 selector = WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X; 634 wpa_auth->dot11RSNAAuthenticationSuiteSelected = selector; 635 636 selector = wpa_cipher_to_suite(WPA_PROTO_WPA, 637 data.pairwise_cipher); 638 if (!selector) 639 selector = RSN_CIPHER_SUITE_TKIP; 640 wpa_auth->dot11RSNAPairwiseCipherSelected = selector; 641 642 selector = wpa_cipher_to_suite(WPA_PROTO_WPA, 643 data.group_cipher); 644 if (!selector) 645 selector = WPA_CIPHER_SUITE_TKIP; 646 wpa_auth->dot11RSNAGroupCipherSelected = selector; 647 } 648 if (res) { 649 wpa_printf(MSG_DEBUG, "Failed to parse WPA/RSN IE from " 650 MACSTR " (res=%d)", MAC2STR(sm->addr), res); 651 wpa_hexdump(MSG_DEBUG, "WPA/RSN IE", wpa_ie, wpa_ie_len); 652 return WPA_INVALID_IE; 653 } 654 655 if (data.group_cipher != wpa_auth->conf.wpa_group) { 656 wpa_printf(MSG_DEBUG, "Invalid WPA group cipher (0x%x) from " 657 MACSTR, data.group_cipher, MAC2STR(sm->addr)); 658 return WPA_INVALID_GROUP; 659 } 660 661 key_mgmt = data.key_mgmt & wpa_auth->conf.wpa_key_mgmt; 662 if (!key_mgmt) { 663 wpa_printf(MSG_DEBUG, "Invalid WPA key mgmt (0x%x) from " 664 MACSTR, data.key_mgmt, MAC2STR(sm->addr)); 665 return WPA_INVALID_AKMP; 666 } 667 if (0) { 668 } 669 else if (key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) 670 sm->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B_192; 671 else if (key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) 672 sm->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B; 673 #ifdef CONFIG_FILS 674 #ifdef CONFIG_IEEE80211R_AP 675 else if (key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) 676 sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_FILS_SHA384; 677 else if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) 678 sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_FILS_SHA256; 679 #endif /* CONFIG_IEEE80211R_AP */ 680 else if (key_mgmt & WPA_KEY_MGMT_FILS_SHA384) 681 sm->wpa_key_mgmt = WPA_KEY_MGMT_FILS_SHA384; 682 else if (key_mgmt & WPA_KEY_MGMT_FILS_SHA256) 683 sm->wpa_key_mgmt = WPA_KEY_MGMT_FILS_SHA256; 684 #endif /* CONFIG_FILS */ 685 #ifdef CONFIG_IEEE80211R_AP 686 #ifdef CONFIG_SHA384 687 else if (key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) 688 sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X_SHA384; 689 #endif /* CONFIG_SHA384 */ 690 else if (key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) 691 sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X; 692 else if (key_mgmt & WPA_KEY_MGMT_FT_PSK) 693 sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_PSK; 694 #endif /* CONFIG_IEEE80211R_AP */ 695 #ifdef CONFIG_IEEE80211W 696 else if (key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) 697 sm->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA256; 698 else if (key_mgmt & WPA_KEY_MGMT_PSK_SHA256) 699 sm->wpa_key_mgmt = WPA_KEY_MGMT_PSK_SHA256; 700 #endif /* CONFIG_IEEE80211W */ 701 #ifdef CONFIG_SAE 702 else if (key_mgmt & WPA_KEY_MGMT_SAE) 703 sm->wpa_key_mgmt = WPA_KEY_MGMT_SAE; 704 else if (key_mgmt & WPA_KEY_MGMT_FT_SAE) 705 sm->wpa_key_mgmt = WPA_KEY_MGMT_FT_SAE; 706 #endif /* CONFIG_SAE */ 707 else if (key_mgmt & WPA_KEY_MGMT_IEEE8021X) 708 sm->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X; 709 #ifdef CONFIG_OWE 710 else if (key_mgmt & WPA_KEY_MGMT_OWE) 711 sm->wpa_key_mgmt = WPA_KEY_MGMT_OWE; 712 #endif /* CONFIG_OWE */ 713 #ifdef CONFIG_DPP 714 else if (key_mgmt & WPA_KEY_MGMT_DPP) 715 sm->wpa_key_mgmt = WPA_KEY_MGMT_DPP; 716 #endif /* CONFIG_DPP */ 717 #ifdef CONFIG_HS20 718 else if (key_mgmt & WPA_KEY_MGMT_OSEN) 719 sm->wpa_key_mgmt = WPA_KEY_MGMT_OSEN; 720 #endif /* CONFIG_HS20 */ 721 else 722 sm->wpa_key_mgmt = WPA_KEY_MGMT_PSK; 723 724 if (version == WPA_PROTO_RSN) 725 ciphers = data.pairwise_cipher & wpa_auth->conf.rsn_pairwise; 726 else 727 ciphers = data.pairwise_cipher & wpa_auth->conf.wpa_pairwise; 728 if (!ciphers) { 729 wpa_printf(MSG_DEBUG, "Invalid %s pairwise cipher (0x%x) " 730 "from " MACSTR, 731 version == WPA_PROTO_RSN ? "RSN" : "WPA", 732 data.pairwise_cipher, MAC2STR(sm->addr)); 733 return WPA_INVALID_PAIRWISE; 734 } 735 736 #ifdef CONFIG_IEEE80211W 737 if (wpa_auth->conf.ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) { 738 if (!(data.capabilities & WPA_CAPABILITY_MFPC)) { 739 wpa_printf(MSG_DEBUG, "Management frame protection " 740 "required, but client did not enable it"); 741 return WPA_MGMT_FRAME_PROTECTION_VIOLATION; 742 } 743 744 if (data.mgmt_group_cipher != wpa_auth->conf.group_mgmt_cipher) 745 { 746 wpa_printf(MSG_DEBUG, "Unsupported management group " 747 "cipher %d", data.mgmt_group_cipher); 748 return WPA_INVALID_MGMT_GROUP_CIPHER; 749 } 750 } 751 752 #ifdef CONFIG_SAE 753 if (wpa_auth->conf.ieee80211w == MGMT_FRAME_PROTECTION_OPTIONAL && 754 wpa_auth->conf.sae_require_mfp && 755 wpa_key_mgmt_sae(sm->wpa_key_mgmt) && 756 !(data.capabilities & WPA_CAPABILITY_MFPC)) { 757 wpa_printf(MSG_DEBUG, 758 "Management frame protection required with SAE, but client did not enable it"); 759 return WPA_MGMT_FRAME_PROTECTION_VIOLATION; 760 } 761 #endif /* CONFIG_SAE */ 762 763 if (wpa_auth->conf.ieee80211w == NO_MGMT_FRAME_PROTECTION || 764 !(data.capabilities & WPA_CAPABILITY_MFPC)) 765 sm->mgmt_frame_prot = 0; 766 else 767 sm->mgmt_frame_prot = 1; 768 769 if (sm->mgmt_frame_prot && (ciphers & WPA_CIPHER_TKIP)) { 770 wpa_printf(MSG_DEBUG, 771 "Management frame protection cannot use TKIP"); 772 return WPA_MGMT_FRAME_PROTECTION_VIOLATION; 773 } 774 #endif /* CONFIG_IEEE80211W */ 775 776 #ifdef CONFIG_IEEE80211R_AP 777 if (wpa_key_mgmt_ft(sm->wpa_key_mgmt)) { 778 if (mdie == NULL || mdie_len < MOBILITY_DOMAIN_ID_LEN + 1) { 779 wpa_printf(MSG_DEBUG, "RSN: Trying to use FT, but " 780 "MDIE not included"); 781 return WPA_INVALID_MDIE; 782 } 783 if (os_memcmp(mdie, wpa_auth->conf.mobility_domain, 784 MOBILITY_DOMAIN_ID_LEN) != 0) { 785 wpa_hexdump(MSG_DEBUG, "RSN: Attempted to use unknown " 786 "MDIE", mdie, MOBILITY_DOMAIN_ID_LEN); 787 return WPA_INVALID_MDIE; 788 } 789 } else if (mdie != NULL) { 790 wpa_printf(MSG_DEBUG, 791 "RSN: Trying to use non-FT AKM suite, but MDIE included"); 792 return WPA_INVALID_AKMP; 793 } 794 #endif /* CONFIG_IEEE80211R_AP */ 795 796 #ifdef CONFIG_OWE 797 if (sm->wpa_key_mgmt == WPA_KEY_MGMT_OWE && !owe_dh) { 798 wpa_printf(MSG_DEBUG, 799 "OWE: No Diffie-Hellman Parameter element"); 800 return WPA_INVALID_AKMP; 801 } 802 if (sm->wpa_key_mgmt != WPA_KEY_MGMT_OWE && owe_dh) { 803 wpa_printf(MSG_DEBUG, 804 "OWE: Unexpected Diffie-Hellman Parameter element with non-OWE AKM"); 805 return WPA_INVALID_AKMP; 806 } 807 #endif /* CONFIG_OWE */ 808 809 sm->pairwise = wpa_pick_pairwise_cipher(ciphers, 0); 810 if (sm->pairwise < 0) 811 return WPA_INVALID_PAIRWISE; 812 813 /* TODO: clear WPA/WPA2 state if STA changes from one to another */ 814 if (wpa_ie[0] == WLAN_EID_RSN) 815 sm->wpa = WPA_VERSION_WPA2; 816 else 817 sm->wpa = WPA_VERSION_WPA; 818 819 sm->pmksa = NULL; 820 for (i = 0; i < data.num_pmkid; i++) { 821 wpa_hexdump(MSG_DEBUG, "RSN IE: STA PMKID", 822 &data.pmkid[i * PMKID_LEN], PMKID_LEN); 823 sm->pmksa = pmksa_cache_auth_get(wpa_auth->pmksa, sm->addr, 824 &data.pmkid[i * PMKID_LEN]); 825 if (sm->pmksa) { 826 pmkid = sm->pmksa->pmkid; 827 break; 828 } 829 } 830 for (i = 0; sm->pmksa == NULL && wpa_auth->conf.okc && 831 i < data.num_pmkid; i++) { 832 struct wpa_auth_okc_iter_data idata; 833 idata.pmksa = NULL; 834 idata.aa = wpa_auth->addr; 835 idata.spa = sm->addr; 836 idata.pmkid = &data.pmkid[i * PMKID_LEN]; 837 wpa_auth_for_each_auth(wpa_auth, wpa_auth_okc_iter, &idata); 838 if (idata.pmksa) { 839 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG, 840 "OKC match for PMKID"); 841 sm->pmksa = pmksa_cache_add_okc(wpa_auth->pmksa, 842 idata.pmksa, 843 wpa_auth->addr, 844 idata.pmkid); 845 pmkid = idata.pmkid; 846 break; 847 } 848 } 849 if (sm->pmksa && pmkid) { 850 struct vlan_description *vlan; 851 852 vlan = sm->pmksa->vlan_desc; 853 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG, 854 "PMKID found from PMKSA cache eap_type=%d vlan=%d%s", 855 sm->pmksa->eap_type_authsrv, 856 vlan ? vlan->untagged : 0, 857 (vlan && vlan->tagged[0]) ? "+" : ""); 858 os_memcpy(wpa_auth->dot11RSNAPMKIDUsed, pmkid, PMKID_LEN); 859 } 860 861 #ifdef CONFIG_SAE 862 if (sm->wpa_key_mgmt == WPA_KEY_MGMT_SAE && data.num_pmkid && 863 !sm->pmksa) { 864 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG, 865 "No PMKSA cache entry found for SAE"); 866 return WPA_INVALID_PMKID; 867 } 868 #endif /* CONFIG_SAE */ 869 870 #ifdef CONFIG_DPP 871 if (sm->wpa_key_mgmt == WPA_KEY_MGMT_DPP && !sm->pmksa) { 872 wpa_auth_vlogger(wpa_auth, sm->addr, LOGGER_DEBUG, 873 "No PMKSA cache entry found for DPP"); 874 return WPA_INVALID_PMKID; 875 } 876 #endif /* CONFIG_DPP */ 877 878 if (sm->wpa_ie == NULL || sm->wpa_ie_len < wpa_ie_len) { 879 os_free(sm->wpa_ie); 880 sm->wpa_ie = os_malloc(wpa_ie_len); 881 if (sm->wpa_ie == NULL) 882 return WPA_ALLOC_FAIL; 883 } 884 os_memcpy(sm->wpa_ie, wpa_ie, wpa_ie_len); 885 sm->wpa_ie_len = wpa_ie_len; 886 887 return WPA_IE_OK; 888 } 889 890 891 #ifdef CONFIG_HS20 892 int wpa_validate_osen(struct wpa_authenticator *wpa_auth, 893 struct wpa_state_machine *sm, 894 const u8 *osen_ie, size_t osen_ie_len) 895 { 896 if (wpa_auth == NULL || sm == NULL) 897 return -1; 898 899 /* TODO: parse OSEN element */ 900 sm->wpa_key_mgmt = WPA_KEY_MGMT_OSEN; 901 sm->mgmt_frame_prot = 1; 902 sm->pairwise = WPA_CIPHER_CCMP; 903 sm->wpa = WPA_VERSION_WPA2; 904 905 if (sm->wpa_ie == NULL || sm->wpa_ie_len < osen_ie_len) { 906 os_free(sm->wpa_ie); 907 sm->wpa_ie = os_malloc(osen_ie_len); 908 if (sm->wpa_ie == NULL) 909 return -1; 910 } 911 912 os_memcpy(sm->wpa_ie, osen_ie, osen_ie_len); 913 sm->wpa_ie_len = osen_ie_len; 914 915 return 0; 916 } 917 918 #endif /* CONFIG_HS20 */ 919 920 921 /** 922 * wpa_parse_generic - Parse EAPOL-Key Key Data Generic IEs 923 * @pos: Pointer to the IE header 924 * @end: Pointer to the end of the Key Data buffer 925 * @ie: Pointer to parsed IE data 926 * Returns: 0 on success, 1 if end mark is found, -1 on failure 927 */ 928 static int wpa_parse_generic(const u8 *pos, const u8 *end, 929 struct wpa_eapol_ie_parse *ie) 930 { 931 if (pos[1] == 0) 932 return 1; 933 934 if (pos[1] >= 6 && 935 RSN_SELECTOR_GET(pos + 2) == WPA_OUI_TYPE && 936 pos[2 + WPA_SELECTOR_LEN] == 1 && 937 pos[2 + WPA_SELECTOR_LEN + 1] == 0) { 938 ie->wpa_ie = pos; 939 ie->wpa_ie_len = pos[1] + 2; 940 return 0; 941 } 942 943 if (pos[1] >= 4 && WPA_GET_BE32(pos + 2) == OSEN_IE_VENDOR_TYPE) { 944 ie->osen = pos; 945 ie->osen_len = pos[1] + 2; 946 return 0; 947 } 948 949 if (1 + RSN_SELECTOR_LEN < end - pos && 950 pos[1] >= RSN_SELECTOR_LEN + PMKID_LEN && 951 RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_PMKID) { 952 ie->pmkid = pos + 2 + RSN_SELECTOR_LEN; 953 return 0; 954 } 955 956 if (pos[1] > RSN_SELECTOR_LEN + 2 && 957 RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_GROUPKEY) { 958 ie->gtk = pos + 2 + RSN_SELECTOR_LEN; 959 ie->gtk_len = pos[1] - RSN_SELECTOR_LEN; 960 return 0; 961 } 962 963 if (pos[1] > RSN_SELECTOR_LEN + 2 && 964 RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_MAC_ADDR) { 965 ie->mac_addr = pos + 2 + RSN_SELECTOR_LEN; 966 ie->mac_addr_len = pos[1] - RSN_SELECTOR_LEN; 967 return 0; 968 } 969 970 #ifdef CONFIG_IEEE80211W 971 if (pos[1] > RSN_SELECTOR_LEN + 2 && 972 RSN_SELECTOR_GET(pos + 2) == RSN_KEY_DATA_IGTK) { 973 ie->igtk = pos + 2 + RSN_SELECTOR_LEN; 974 ie->igtk_len = pos[1] - RSN_SELECTOR_LEN; 975 return 0; 976 } 977 #endif /* CONFIG_IEEE80211W */ 978 979 #ifdef CONFIG_P2P 980 if (pos[1] >= RSN_SELECTOR_LEN + 1 && 981 RSN_SELECTOR_GET(pos + 2) == WFA_KEY_DATA_IP_ADDR_REQ) { 982 ie->ip_addr_req = pos + 2 + RSN_SELECTOR_LEN; 983 wpa_hexdump(MSG_DEBUG, "WPA: IP Address Request in EAPOL-Key", 984 ie->ip_addr_req, pos[1] - RSN_SELECTOR_LEN); 985 return 0; 986 } 987 988 if (pos[1] >= RSN_SELECTOR_LEN + 3 * 4 && 989 RSN_SELECTOR_GET(pos + 2) == WFA_KEY_DATA_IP_ADDR_ALLOC) { 990 ie->ip_addr_alloc = pos + 2 + RSN_SELECTOR_LEN; 991 wpa_hexdump(MSG_DEBUG, 992 "WPA: IP Address Allocation in EAPOL-Key", 993 ie->ip_addr_alloc, pos[1] - RSN_SELECTOR_LEN); 994 return 0; 995 } 996 #endif /* CONFIG_P2P */ 997 998 return 0; 999 } 1000 1001 1002 /** 1003 * wpa_parse_kde_ies - Parse EAPOL-Key Key Data IEs 1004 * @buf: Pointer to the Key Data buffer 1005 * @len: Key Data Length 1006 * @ie: Pointer to parsed IE data 1007 * Returns: 0 on success, -1 on failure 1008 */ 1009 int wpa_parse_kde_ies(const u8 *buf, size_t len, struct wpa_eapol_ie_parse *ie) 1010 { 1011 const u8 *pos, *end; 1012 int ret = 0; 1013 1014 os_memset(ie, 0, sizeof(*ie)); 1015 for (pos = buf, end = pos + len; end - pos > 1; pos += 2 + pos[1]) { 1016 if (pos[0] == 0xdd && 1017 ((pos == buf + len - 1) || pos[1] == 0)) { 1018 /* Ignore padding */ 1019 break; 1020 } 1021 if (2 + pos[1] > end - pos) { 1022 wpa_printf(MSG_DEBUG, "WPA: EAPOL-Key Key Data " 1023 "underflow (ie=%d len=%d pos=%d)", 1024 pos[0], pos[1], (int) (pos - buf)); 1025 wpa_hexdump_key(MSG_DEBUG, "WPA: Key Data", 1026 buf, len); 1027 ret = -1; 1028 break; 1029 } 1030 if (*pos == WLAN_EID_RSN) { 1031 ie->rsn_ie = pos; 1032 ie->rsn_ie_len = pos[1] + 2; 1033 #ifdef CONFIG_IEEE80211R_AP 1034 } else if (*pos == WLAN_EID_MOBILITY_DOMAIN) { 1035 ie->mdie = pos; 1036 ie->mdie_len = pos[1] + 2; 1037 } else if (*pos == WLAN_EID_FAST_BSS_TRANSITION) { 1038 ie->ftie = pos; 1039 ie->ftie_len = pos[1] + 2; 1040 #endif /* CONFIG_IEEE80211R_AP */ 1041 } else if (*pos == WLAN_EID_VENDOR_SPECIFIC) { 1042 ret = wpa_parse_generic(pos, end, ie); 1043 if (ret < 0) 1044 break; 1045 if (ret > 0) { 1046 ret = 0; 1047 break; 1048 } 1049 } else { 1050 wpa_hexdump(MSG_DEBUG, "WPA: Unrecognized EAPOL-Key " 1051 "Key Data IE", pos, 2 + pos[1]); 1052 } 1053 } 1054 1055 return ret; 1056 } 1057 1058 1059 int wpa_auth_uses_mfp(struct wpa_state_machine *sm) 1060 { 1061 return sm ? sm->mgmt_frame_prot : 0; 1062 } 1063 1064 1065 #ifdef CONFIG_OWE 1066 u8 * wpa_auth_write_assoc_resp_owe(struct wpa_state_machine *sm, 1067 u8 *pos, size_t max_len, 1068 const u8 *req_ies, size_t req_ies_len) 1069 { 1070 int res; 1071 struct wpa_auth_config *conf; 1072 1073 if (!sm) 1074 return pos; 1075 conf = &sm->wpa_auth->conf; 1076 1077 #ifdef CONFIG_TESTING_OPTIONS 1078 if (conf->own_ie_override_len) { 1079 if (max_len < conf->own_ie_override_len) 1080 return NULL; 1081 wpa_hexdump(MSG_DEBUG, "WPA: Forced own IE(s) for testing", 1082 conf->own_ie_override, conf->own_ie_override_len); 1083 os_memcpy(pos, conf->own_ie_override, 1084 conf->own_ie_override_len); 1085 return pos + conf->own_ie_override_len; 1086 } 1087 #endif /* CONFIG_TESTING_OPTIONS */ 1088 1089 res = wpa_write_rsn_ie(conf, pos, max_len, 1090 sm->pmksa ? sm->pmksa->pmkid : NULL); 1091 if (res < 0) 1092 return pos; 1093 return pos + res; 1094 } 1095 #endif /* CONFIG_OWE */ 1096