1 /* 2 * WPA Supplicant - Driver event processing 3 * Copyright (c) 2003-2012, Jouni Malinen <j (at) 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 "includes.h" 10 11 #include "common.h" 12 #include "eapol_supp/eapol_supp_sm.h" 13 #include "rsn_supp/wpa.h" 14 #include "eloop.h" 15 #include "config.h" 16 #include "l2_packet/l2_packet.h" 17 #include "wpa_supplicant_i.h" 18 #include "driver_i.h" 19 #include "pcsc_funcs.h" 20 #include "rsn_supp/preauth.h" 21 #include "rsn_supp/pmksa_cache.h" 22 #include "common/wpa_ctrl.h" 23 #include "eap_peer/eap.h" 24 #include "ap/hostapd.h" 25 #include "p2p/p2p.h" 26 #include "wnm_sta.h" 27 #include "notify.h" 28 #include "common/ieee802_11_defs.h" 29 #include "common/ieee802_11_common.h" 30 #include "crypto/random.h" 31 #include "blacklist.h" 32 #include "wpas_glue.h" 33 #include "wps_supplicant.h" 34 #include "ibss_rsn.h" 35 #include "sme.h" 36 #include "gas_query.h" 37 #include "p2p_supplicant.h" 38 #include "bgscan.h" 39 #include "autoscan.h" 40 #include "ap.h" 41 #include "bss.h" 42 #include "scan.h" 43 #include "offchannel.h" 44 #include "interworking.h" 45 46 47 #ifndef CONFIG_NO_SCAN_PROCESSING 48 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, 49 int new_scan); 50 #endif /* CONFIG_NO_SCAN_PROCESSING */ 51 52 53 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s, 54 struct wpa_ssid *ssid) 55 { 56 struct os_time now; 57 58 if (ssid == NULL || ssid->disabled_until.sec == 0) 59 return 0; 60 61 os_get_time(&now); 62 if (ssid->disabled_until.sec > now.sec) 63 return ssid->disabled_until.sec - now.sec; 64 65 wpas_clear_temp_disabled(wpa_s, ssid, 0); 66 67 return 0; 68 } 69 70 71 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s) 72 { 73 struct wpa_ssid *ssid, *old_ssid; 74 int res; 75 76 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) 77 return 0; 78 79 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association " 80 "information"); 81 ssid = wpa_supplicant_get_ssid(wpa_s); 82 if (ssid == NULL) { 83 wpa_msg(wpa_s, MSG_INFO, 84 "No network configuration found for the current AP"); 85 return -1; 86 } 87 88 if (wpas_network_disabled(wpa_s, ssid)) { 89 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled"); 90 return -1; 91 } 92 93 if (disallowed_bssid(wpa_s, wpa_s->bssid) || 94 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) { 95 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed"); 96 return -1; 97 } 98 99 res = wpas_temp_disabled(wpa_s, ssid); 100 if (res > 0) { 101 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily " 102 "disabled for %d second(s)", res); 103 return -1; 104 } 105 106 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the " 107 "current AP"); 108 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { 109 u8 wpa_ie[80]; 110 size_t wpa_ie_len = sizeof(wpa_ie); 111 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid, 112 wpa_ie, &wpa_ie_len) < 0) 113 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites"); 114 } else { 115 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); 116 } 117 118 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) 119 eapol_sm_invalidate_cached_session(wpa_s->eapol); 120 old_ssid = wpa_s->current_ssid; 121 wpa_s->current_ssid = ssid; 122 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); 123 wpa_supplicant_initiate_eapol(wpa_s); 124 if (old_ssid != wpa_s->current_ssid) 125 wpas_notify_network_changed(wpa_s); 126 127 return 0; 128 } 129 130 131 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx) 132 { 133 struct wpa_supplicant *wpa_s = eloop_ctx; 134 135 if (wpa_s->countermeasures) { 136 wpa_s->countermeasures = 0; 137 wpa_drv_set_countermeasures(wpa_s, 0); 138 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped"); 139 wpa_supplicant_req_scan(wpa_s, 0, 0); 140 } 141 } 142 143 144 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) 145 { 146 int bssid_changed; 147 148 wnm_bss_keep_alive_deinit(wpa_s); 149 150 #ifdef CONFIG_IBSS_RSN 151 ibss_rsn_deinit(wpa_s->ibss_rsn); 152 wpa_s->ibss_rsn = NULL; 153 #endif /* CONFIG_IBSS_RSN */ 154 155 #ifdef CONFIG_AP 156 wpa_supplicant_ap_deinit(wpa_s); 157 #endif /* CONFIG_AP */ 158 159 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) 160 return; 161 162 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); 163 #ifdef ANDROID 164 wpa_s->conf->ap_scan = DEFAULT_AP_SCAN; 165 #endif 166 bssid_changed = !is_zero_ether_addr(wpa_s->bssid); 167 os_memset(wpa_s->bssid, 0, ETH_ALEN); 168 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); 169 #ifdef CONFIG_SME 170 wpa_s->sme.prev_bssid_set = 0; 171 #endif /* CONFIG_SME */ 172 #ifdef CONFIG_P2P 173 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); 174 #endif /* CONFIG_P2P */ 175 wpa_s->current_bss = NULL; 176 wpa_s->assoc_freq = 0; 177 #ifdef CONFIG_IEEE80211R 178 #ifdef CONFIG_SME 179 if (wpa_s->sme.ft_ies) 180 sme_update_ft_ies(wpa_s, NULL, NULL, 0); 181 #endif /* CONFIG_SME */ 182 #endif /* CONFIG_IEEE80211R */ 183 184 if (bssid_changed) 185 wpas_notify_bssid_changed(wpa_s); 186 187 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); 188 eapol_sm_notify_portValid(wpa_s->eapol, FALSE); 189 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) 190 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); 191 wpa_s->ap_ies_from_associnfo = 0; 192 wpa_s->current_ssid = NULL; 193 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); 194 wpa_s->key_mgmt = 0; 195 } 196 197 198 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s) 199 { 200 struct wpa_ie_data ie; 201 int pmksa_set = -1; 202 size_t i; 203 204 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 || 205 ie.pmkid == NULL) 206 return; 207 208 for (i = 0; i < ie.num_pmkid; i++) { 209 pmksa_set = pmksa_cache_set_current(wpa_s->wpa, 210 ie.pmkid + i * PMKID_LEN, 211 NULL, NULL, 0); 212 if (pmksa_set == 0) { 213 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1); 214 break; 215 } 216 } 217 218 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from " 219 "PMKSA cache", pmksa_set == 0 ? "" : "not "); 220 } 221 222 223 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s, 224 union wpa_event_data *data) 225 { 226 if (data == NULL) { 227 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate " 228 "event"); 229 return; 230 } 231 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR 232 " index=%d preauth=%d", 233 MAC2STR(data->pmkid_candidate.bssid), 234 data->pmkid_candidate.index, 235 data->pmkid_candidate.preauth); 236 237 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid, 238 data->pmkid_candidate.index, 239 data->pmkid_candidate.preauth); 240 } 241 242 243 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s) 244 { 245 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || 246 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) 247 return 0; 248 249 #ifdef IEEE8021X_EAPOL 250 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA && 251 wpa_s->current_ssid && 252 !(wpa_s->current_ssid->eapol_flags & 253 (EAPOL_FLAG_REQUIRE_KEY_UNICAST | 254 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) { 255 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either 256 * plaintext or static WEP keys). */ 257 return 0; 258 } 259 #endif /* IEEE8021X_EAPOL */ 260 261 return 1; 262 } 263 264 265 /** 266 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC 267 * @wpa_s: pointer to wpa_supplicant data 268 * @ssid: Configuration data for the network 269 * Returns: 0 on success, -1 on failure 270 * 271 * This function is called when starting authentication with a network that is 272 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA). 273 */ 274 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s, 275 struct wpa_ssid *ssid) 276 { 277 #ifdef IEEE8021X_EAPOL 278 #ifdef PCSC_FUNCS 279 int aka = 0, sim = 0; 280 281 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL) 282 return 0; 283 284 if (ssid->eap.eap_methods == NULL) { 285 sim = 1; 286 aka = 1; 287 } else { 288 struct eap_method_type *eap = ssid->eap.eap_methods; 289 while (eap->vendor != EAP_VENDOR_IETF || 290 eap->method != EAP_TYPE_NONE) { 291 if (eap->vendor == EAP_VENDOR_IETF) { 292 if (eap->method == EAP_TYPE_SIM) 293 sim = 1; 294 else if (eap->method == EAP_TYPE_AKA || 295 eap->method == EAP_TYPE_AKA_PRIME) 296 aka = 1; 297 } 298 eap++; 299 } 300 } 301 302 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL) 303 sim = 0; 304 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL && 305 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) == 306 NULL) 307 aka = 0; 308 309 if (!sim && !aka) { 310 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to " 311 "use SIM, but neither EAP-SIM nor EAP-AKA are " 312 "enabled"); 313 return 0; 314 } 315 316 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM " 317 "(sim=%d aka=%d) - initialize PCSC", sim, aka); 318 319 wpa_s->scard = scard_init((!sim && aka) ? SCARD_USIM_ONLY : 320 SCARD_TRY_BOTH, NULL); 321 if (wpa_s->scard == NULL) { 322 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM " 323 "(pcsc-lite)"); 324 return -1; 325 } 326 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); 327 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); 328 #endif /* PCSC_FUNCS */ 329 #endif /* IEEE8021X_EAPOL */ 330 331 return 0; 332 } 333 334 335 #ifndef CONFIG_NO_SCAN_PROCESSING 336 337 static int has_wep_key(struct wpa_ssid *ssid) 338 { 339 int i; 340 341 for (i = 0; i < NUM_WEP_KEYS; i++) { 342 if (ssid->wep_key_len[i]) 343 return 1; 344 } 345 346 return 0; 347 } 348 349 350 static int wpa_supplicant_match_privacy(struct wpa_bss *bss, 351 struct wpa_ssid *ssid) 352 { 353 int privacy = 0; 354 355 if (ssid->mixed_cell) 356 return 1; 357 358 #ifdef CONFIG_WPS 359 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) 360 return 1; 361 #endif /* CONFIG_WPS */ 362 363 if (has_wep_key(ssid)) 364 privacy = 1; 365 366 #ifdef IEEE8021X_EAPOL 367 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && 368 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST | 369 EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) 370 privacy = 1; 371 #endif /* IEEE8021X_EAPOL */ 372 373 if (wpa_key_mgmt_wpa(ssid->key_mgmt)) 374 privacy = 1; 375 376 if (bss->caps & IEEE80211_CAP_PRIVACY) 377 return privacy; 378 return !privacy; 379 } 380 381 382 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, 383 struct wpa_ssid *ssid, 384 struct wpa_bss *bss) 385 { 386 struct wpa_ie_data ie; 387 int proto_match = 0; 388 const u8 *rsn_ie, *wpa_ie; 389 int ret; 390 int wep_ok; 391 392 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); 393 if (ret >= 0) 394 return ret; 395 396 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */ 397 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) && 398 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) && 399 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) || 400 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)); 401 402 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); 403 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) { 404 proto_match++; 405 406 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { 407 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse " 408 "failed"); 409 break; 410 } 411 412 if (wep_ok && 413 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) 414 { 415 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " 416 "in RSN IE"); 417 return 1; 418 } 419 420 if (!(ie.proto & ssid->proto)) { 421 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto " 422 "mismatch"); 423 break; 424 } 425 426 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { 427 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK " 428 "cipher mismatch"); 429 break; 430 } 431 432 if (!(ie.group_cipher & ssid->group_cipher)) { 433 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK " 434 "cipher mismatch"); 435 break; 436 } 437 438 if (!(ie.key_mgmt & ssid->key_mgmt)) { 439 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt " 440 "mismatch"); 441 break; 442 } 443 444 #ifdef CONFIG_IEEE80211W 445 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && 446 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ? 447 wpa_s->conf->pmf : ssid->ieee80211w) == 448 MGMT_FRAME_PROTECTION_REQUIRED) { 449 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt " 450 "frame protection"); 451 break; 452 } 453 #endif /* CONFIG_IEEE80211W */ 454 455 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE"); 456 return 1; 457 } 458 459 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); 460 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { 461 proto_match++; 462 463 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { 464 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse " 465 "failed"); 466 break; 467 } 468 469 if (wep_ok && 470 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) 471 { 472 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " 473 "in WPA IE"); 474 return 1; 475 } 476 477 if (!(ie.proto & ssid->proto)) { 478 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto " 479 "mismatch"); 480 break; 481 } 482 483 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { 484 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK " 485 "cipher mismatch"); 486 break; 487 } 488 489 if (!(ie.group_cipher & ssid->group_cipher)) { 490 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK " 491 "cipher mismatch"); 492 break; 493 } 494 495 if (!(ie.key_mgmt & ssid->key_mgmt)) { 496 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt " 497 "mismatch"); 498 break; 499 } 500 501 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE"); 502 return 1; 503 } 504 505 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie && 506 !rsn_ie) { 507 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X"); 508 return 1; 509 } 510 511 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) && 512 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) { 513 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match"); 514 return 0; 515 } 516 517 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) { 518 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2"); 519 return 1; 520 } 521 522 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with " 523 "WPA/WPA2"); 524 525 return 0; 526 } 527 528 529 static int freq_allowed(int *freqs, int freq) 530 { 531 int i; 532 533 if (freqs == NULL) 534 return 1; 535 536 for (i = 0; freqs[i]; i++) 537 if (freqs[i] == freq) 538 return 1; 539 return 0; 540 } 541 542 543 static int ht_supported(const struct hostapd_hw_modes *mode) 544 { 545 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) { 546 /* 547 * The driver did not indicate whether it supports HT. Assume 548 * it does to avoid connection issues. 549 */ 550 return 1; 551 } 552 553 /* 554 * IEEE Std 802.11n-2009 20.1.1: 555 * An HT non-AP STA shall support all EQM rates for one spatial stream. 556 */ 557 return mode->mcs_set[0] == 0xff; 558 } 559 560 561 static int vht_supported(const struct hostapd_hw_modes *mode) 562 { 563 if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) { 564 /* 565 * The driver did not indicate whether it supports VHT. Assume 566 * it does to avoid connection issues. 567 */ 568 return 1; 569 } 570 571 /* 572 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream. 573 * TODO: Verify if this complies with the standard 574 */ 575 return (mode->vht_mcs_set[0] & 0x3) != 3; 576 } 577 578 579 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) 580 { 581 const struct hostapd_hw_modes *mode = NULL, *modes; 582 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES }; 583 const u8 *rate_ie; 584 int i, j, k; 585 586 if (bss->freq == 0) 587 return 1; /* Cannot do matching without knowing band */ 588 589 modes = wpa_s->hw.modes; 590 if (modes == NULL) { 591 /* 592 * The driver does not provide any additional information 593 * about the utilized hardware, so allow the connection attempt 594 * to continue. 595 */ 596 return 1; 597 } 598 599 for (i = 0; i < wpa_s->hw.num_modes; i++) { 600 for (j = 0; j < modes[i].num_channels; j++) { 601 int freq = modes[i].channels[j].freq; 602 if (freq == bss->freq) { 603 if (mode && 604 mode->mode == HOSTAPD_MODE_IEEE80211G) 605 break; /* do not allow 802.11b replace 606 * 802.11g */ 607 mode = &modes[i]; 608 break; 609 } 610 } 611 } 612 613 if (mode == NULL) 614 return 0; 615 616 for (i = 0; i < (int) sizeof(scan_ie); i++) { 617 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]); 618 if (rate_ie == NULL) 619 continue; 620 621 for (j = 2; j < rate_ie[1] + 2; j++) { 622 int flagged = !!(rate_ie[j] & 0x80); 623 int r = (rate_ie[j] & 0x7f) * 5; 624 625 /* 626 * IEEE Std 802.11n-2009 7.3.2.2: 627 * The new BSS Membership selector value is encoded 628 * like a legacy basic rate, but it is not a rate and 629 * only indicates if the BSS members are required to 630 * support the mandatory features of Clause 20 [HT PHY] 631 * in order to join the BSS. 632 */ 633 if (flagged && ((rate_ie[j] & 0x7f) == 634 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) { 635 if (!ht_supported(mode)) { 636 wpa_dbg(wpa_s, MSG_DEBUG, 637 " hardware does not support " 638 "HT PHY"); 639 return 0; 640 } 641 continue; 642 } 643 644 /* There's also a VHT selector for 802.11ac */ 645 if (flagged && ((rate_ie[j] & 0x7f) == 646 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) { 647 if (!vht_supported(mode)) { 648 wpa_dbg(wpa_s, MSG_DEBUG, 649 " hardware does not support " 650 "VHT PHY"); 651 return 0; 652 } 653 continue; 654 } 655 656 if (!flagged) 657 continue; 658 659 /* check for legacy basic rates */ 660 for (k = 0; k < mode->num_rates; k++) { 661 if (mode->rates[k] == r) 662 break; 663 } 664 if (k == mode->num_rates) { 665 /* 666 * IEEE Std 802.11-2007 7.3.2.2 demands that in 667 * order to join a BSS all required rates 668 * have to be supported by the hardware. 669 */ 670 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does " 671 "not support required rate %d.%d Mbps", 672 r / 10, r % 10); 673 return 0; 674 } 675 } 676 } 677 678 return 1; 679 } 680 681 682 static int bss_is_dmg(struct wpa_bss *bss) 683 { 684 return bss->freq > 45000; 685 } 686 687 688 /* 689 * Test whether BSS is in an ESS. 690 * This is done differently in DMG (60 GHz) and non-DMG bands 691 */ 692 static int bss_is_ess(struct wpa_bss *bss) 693 { 694 if (bss_is_dmg(bss)) { 695 return (bss->caps & IEEE80211_CAP_DMG_MASK) == 696 IEEE80211_CAP_DMG_AP; 697 } 698 699 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) == 700 IEEE80211_CAP_ESS); 701 } 702 703 704 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s, 705 int i, struct wpa_bss *bss, 706 struct wpa_ssid *group) 707 { 708 u8 wpa_ie_len, rsn_ie_len; 709 int wpa; 710 struct wpa_blacklist *e; 711 const u8 *ie; 712 struct wpa_ssid *ssid; 713 714 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); 715 wpa_ie_len = ie ? ie[1] : 0; 716 717 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); 718 rsn_ie_len = ie ? ie[1] : 0; 719 720 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' " 721 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s", 722 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len), 723 wpa_ie_len, rsn_ie_len, bss->caps, bss->level, 724 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : ""); 725 726 e = wpa_blacklist_get(wpa_s, bss->bssid); 727 if (e) { 728 int limit = 1; 729 if (wpa_supplicant_enabled_networks(wpa_s) == 1) { 730 /* 731 * When only a single network is enabled, we can 732 * trigger blacklisting on the first failure. This 733 * should not be done with multiple enabled networks to 734 * avoid getting forced to move into a worse ESS on 735 * single error if there are no other BSSes of the 736 * current ESS. 737 */ 738 limit = 0; 739 } 740 if (e->count > limit) { 741 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " 742 "(count=%d limit=%d)", e->count, limit); 743 return NULL; 744 } 745 } 746 747 if (bss->ssid_len == 0) { 748 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known"); 749 return NULL; 750 } 751 752 if (disallowed_bssid(wpa_s, bss->bssid)) { 753 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed"); 754 return NULL; 755 } 756 757 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) { 758 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed"); 759 return NULL; 760 } 761 762 wpa = wpa_ie_len > 0 || rsn_ie_len > 0; 763 764 for (ssid = group; ssid; ssid = ssid->pnext) { 765 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0); 766 int res; 767 768 if (wpas_network_disabled(wpa_s, ssid)) { 769 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled"); 770 continue; 771 } 772 773 res = wpas_temp_disabled(wpa_s, ssid); 774 if (res > 0) { 775 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled " 776 "temporarily for %d second(s)", res); 777 continue; 778 } 779 780 #ifdef CONFIG_WPS 781 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) { 782 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " 783 "(WPS)"); 784 continue; 785 } 786 787 if (wpa && ssid->ssid_len == 0 && 788 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) 789 check_ssid = 0; 790 791 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { 792 /* Only allow wildcard SSID match if an AP 793 * advertises active WPS operation that matches 794 * with our mode. */ 795 check_ssid = 1; 796 if (ssid->ssid_len == 0 && 797 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) 798 check_ssid = 0; 799 } 800 #endif /* CONFIG_WPS */ 801 802 if (ssid->bssid_set && ssid->ssid_len == 0 && 803 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0) 804 check_ssid = 0; 805 806 if (check_ssid && 807 (bss->ssid_len != ssid->ssid_len || 808 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) { 809 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch"); 810 continue; 811 } 812 813 if (ssid->bssid_set && 814 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) { 815 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch"); 816 continue; 817 } 818 819 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss)) 820 continue; 821 822 if (!wpa && 823 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) && 824 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) && 825 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) { 826 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network " 827 "not allowed"); 828 continue; 829 } 830 831 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && 832 has_wep_key(ssid)) { 833 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block"); 834 continue; 835 } 836 837 if (!wpa_supplicant_match_privacy(bss, ssid)) { 838 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy " 839 "mismatch"); 840 continue; 841 } 842 843 if (!bss_is_ess(bss)) { 844 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network"); 845 continue; 846 } 847 848 if (!freq_allowed(ssid->freq_list, bss->freq)) { 849 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not " 850 "allowed"); 851 continue; 852 } 853 854 if (!rate_match(wpa_s, bss)) { 855 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do " 856 "not match"); 857 continue; 858 } 859 860 #ifdef CONFIG_P2P 861 /* 862 * TODO: skip the AP if its P2P IE has Group Formation 863 * bit set in the P2P Group Capability Bitmap and we 864 * are not in Group Formation with that device. 865 */ 866 #endif /* CONFIG_P2P */ 867 868 /* Matching configuration found */ 869 return ssid; 870 } 871 872 /* No matching configuration found */ 873 return NULL; 874 } 875 876 877 static struct wpa_bss * 878 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, 879 struct wpa_ssid *group, 880 struct wpa_ssid **selected_ssid) 881 { 882 unsigned int i; 883 884 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d", 885 group->priority); 886 887 for (i = 0; i < wpa_s->last_scan_res_used; i++) { 888 struct wpa_bss *bss = wpa_s->last_scan_res[i]; 889 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group); 890 if (!*selected_ssid) 891 continue; 892 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR 893 " ssid='%s'", 894 MAC2STR(bss->bssid), 895 wpa_ssid_txt(bss->ssid, bss->ssid_len)); 896 return bss; 897 } 898 899 return NULL; 900 } 901 902 903 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s, 904 struct wpa_ssid **selected_ssid) 905 { 906 struct wpa_bss *selected = NULL; 907 int prio; 908 909 if (wpa_s->last_scan_res == NULL || 910 wpa_s->last_scan_res_used == 0) 911 return NULL; /* no scan results from last update */ 912 913 while (selected == NULL) { 914 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { 915 selected = wpa_supplicant_select_bss( 916 wpa_s, wpa_s->conf->pssid[prio], 917 selected_ssid); 918 if (selected) 919 break; 920 } 921 922 if (selected == NULL && wpa_s->blacklist && 923 !wpa_s->countermeasures) { 924 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear " 925 "blacklist and try again"); 926 wpa_blacklist_clear(wpa_s); 927 wpa_s->blacklist_cleared++; 928 } else if (selected == NULL) 929 break; 930 } 931 932 return selected; 933 } 934 935 936 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s, 937 int timeout_sec, int timeout_usec) 938 { 939 if (!wpa_supplicant_enabled_networks(wpa_s)) { 940 /* 941 * No networks are enabled; short-circuit request so 942 * we don't wait timeout seconds before transitioning 943 * to INACTIVE state. 944 */ 945 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request " 946 "since there are no enabled networks"); 947 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); 948 #ifdef CONFIG_P2P 949 wpa_s->sta_scan_pending = 0; 950 #endif /* CONFIG_P2P */ 951 return; 952 } 953 954 wpa_s->scan_for_connection = 1; 955 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec); 956 } 957 958 959 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s, 960 struct wpa_bss *selected, 961 struct wpa_ssid *ssid) 962 { 963 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) { 964 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP 965 "PBC session overlap"); 966 #ifdef CONFIG_P2P 967 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1) 968 return -1; 969 #endif /* CONFIG_P2P */ 970 971 #ifdef CONFIG_WPS 972 wpas_wps_cancel(wpa_s); 973 #endif /* CONFIG_WPS */ 974 return -1; 975 } 976 977 wpa_msg(wpa_s, MSG_DEBUG, 978 "Considering connect request: reassociate: %d selected: " 979 MACSTR " bssid: " MACSTR " pending: " MACSTR 980 " wpa_state: %s ssid=%p current_ssid=%p", 981 wpa_s->reassociate, MAC2STR(selected->bssid), 982 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), 983 wpa_supplicant_state_txt(wpa_s->wpa_state), 984 ssid, wpa_s->current_ssid); 985 986 /* 987 * Do not trigger new association unless the BSSID has changed or if 988 * reassociation is requested. If we are in process of associating with 989 * the selected BSSID, do not trigger new attempt. 990 */ 991 if (wpa_s->reassociate || 992 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 && 993 ((wpa_s->wpa_state != WPA_ASSOCIATING && 994 wpa_s->wpa_state != WPA_AUTHENTICATING) || 995 (!is_zero_ether_addr(wpa_s->pending_bssid) && 996 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) != 997 0) || 998 (is_zero_ether_addr(wpa_s->pending_bssid) && 999 ssid != wpa_s->current_ssid)))) { 1000 if (wpa_supplicant_scard_init(wpa_s, ssid)) { 1001 wpa_supplicant_req_new_scan(wpa_s, 10, 0); 1002 return 0; 1003 } 1004 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR, 1005 MAC2STR(selected->bssid)); 1006 wpa_supplicant_associate(wpa_s, selected, ssid); 1007 } else { 1008 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to " 1009 "connect with the selected AP"); 1010 } 1011 1012 return 0; 1013 } 1014 1015 1016 static struct wpa_ssid * 1017 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s) 1018 { 1019 int prio; 1020 struct wpa_ssid *ssid; 1021 1022 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { 1023 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) 1024 { 1025 if (wpas_network_disabled(wpa_s, ssid)) 1026 continue; 1027 if (ssid->mode == IEEE80211_MODE_IBSS || 1028 ssid->mode == IEEE80211_MODE_AP) 1029 return ssid; 1030 } 1031 } 1032 return NULL; 1033 } 1034 1035 1036 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based 1037 * on BSS added and BSS changed events */ 1038 static void wpa_supplicant_rsn_preauth_scan_results( 1039 struct wpa_supplicant *wpa_s) 1040 { 1041 struct wpa_bss *bss; 1042 1043 if (rsn_preauth_scan_results(wpa_s->wpa) < 0) 1044 return; 1045 1046 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { 1047 const u8 *ssid, *rsn; 1048 1049 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID); 1050 if (ssid == NULL) 1051 continue; 1052 1053 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); 1054 if (rsn == NULL) 1055 continue; 1056 1057 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn); 1058 } 1059 1060 } 1061 1062 1063 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, 1064 struct wpa_bss *selected, 1065 struct wpa_ssid *ssid) 1066 { 1067 struct wpa_bss *current_bss = NULL; 1068 int min_diff; 1069 1070 if (wpa_s->reassociate) 1071 return 1; /* explicit request to reassociate */ 1072 if (wpa_s->wpa_state < WPA_ASSOCIATED) 1073 return 1; /* we are not associated; continue */ 1074 if (wpa_s->current_ssid == NULL) 1075 return 1; /* unknown current SSID */ 1076 if (wpa_s->current_ssid != ssid) 1077 return 1; /* different network block */ 1078 1079 if (wpas_driver_bss_selection(wpa_s)) 1080 return 0; /* Driver-based roaming */ 1081 1082 if (wpa_s->current_ssid->ssid) 1083 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid, 1084 wpa_s->current_ssid->ssid, 1085 wpa_s->current_ssid->ssid_len); 1086 if (!current_bss) 1087 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid); 1088 1089 if (!current_bss) 1090 return 1; /* current BSS not seen in scan results */ 1091 1092 if (current_bss == selected) 1093 return 0; 1094 1095 if (selected->last_update_idx > current_bss->last_update_idx) 1096 return 1; /* current BSS not seen in the last scan */ 1097 1098 #ifndef CONFIG_NO_ROAMING 1099 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation"); 1100 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d", 1101 MAC2STR(current_bss->bssid), current_bss->level); 1102 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d", 1103 MAC2STR(selected->bssid), selected->level); 1104 1105 if (wpa_s->current_ssid->bssid_set && 1106 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) == 1107 0) { 1108 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS " 1109 "has preferred BSSID"); 1110 return 1; 1111 } 1112 1113 if (current_bss->level < 0 && current_bss->level > selected->level) { 1114 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better " 1115 "signal level"); 1116 return 0; 1117 } 1118 1119 min_diff = 2; 1120 if (current_bss->level < 0) { 1121 if (current_bss->level < -85) 1122 min_diff = 1; 1123 else if (current_bss->level < -80) 1124 min_diff = 2; 1125 else if (current_bss->level < -75) 1126 min_diff = 3; 1127 else if (current_bss->level < -70) 1128 min_diff = 4; 1129 else 1130 min_diff = 5; 1131 } 1132 if (abs(current_bss->level - selected->level) < min_diff) { 1133 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference " 1134 "in signal level"); 1135 return 0; 1136 } 1137 1138 return 1; 1139 #else /* CONFIG_NO_ROAMING */ 1140 return 0; 1141 #endif /* CONFIG_NO_ROAMING */ 1142 } 1143 1144 1145 /* Return != 0 if no scan results could be fetched or if scan results should not 1146 * be shared with other virtual interfaces. */ 1147 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, 1148 union wpa_event_data *data, 1149 int own_request) 1150 { 1151 struct wpa_scan_results *scan_res; 1152 int ap = 0; 1153 #ifndef CONFIG_NO_RANDOM_POOL 1154 size_t i, num; 1155 #endif /* CONFIG_NO_RANDOM_POOL */ 1156 1157 #ifdef CONFIG_AP 1158 if (wpa_s->ap_iface) 1159 ap = 1; 1160 #endif /* CONFIG_AP */ 1161 1162 wpa_supplicant_notify_scanning(wpa_s, 0); 1163 1164 #ifdef CONFIG_P2P 1165 if (own_request && wpa_s->global->p2p_cb_on_scan_complete && 1166 !wpa_s->global->p2p_disabled && 1167 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending && 1168 !wpa_s->scan_res_handler) { 1169 wpa_s->global->p2p_cb_on_scan_complete = 0; 1170 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) { 1171 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation " 1172 "stopped scan processing"); 1173 wpa_s->sta_scan_pending = 1; 1174 wpa_supplicant_req_scan(wpa_s, 5, 0); 1175 return -1; 1176 } 1177 } 1178 wpa_s->sta_scan_pending = 0; 1179 #endif /* CONFIG_P2P */ 1180 1181 scan_res = wpa_supplicant_get_scan_results(wpa_s, 1182 data ? &data->scan_info : 1183 NULL, 1); 1184 if (scan_res == NULL) { 1185 if (wpa_s->conf->ap_scan == 2 || ap || 1186 wpa_s->scan_res_handler == scan_only_handler) 1187 return -1; 1188 if (!own_request) 1189 return -1; 1190 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try " 1191 "scanning again"); 1192 wpa_supplicant_req_new_scan(wpa_s, 1, 0); 1193 return -1; 1194 } 1195 1196 #ifndef CONFIG_NO_RANDOM_POOL 1197 num = scan_res->num; 1198 if (num > 10) 1199 num = 10; 1200 for (i = 0; i < num; i++) { 1201 u8 buf[5]; 1202 struct wpa_scan_res *res = scan_res->res[i]; 1203 buf[0] = res->bssid[5]; 1204 buf[1] = res->qual & 0xff; 1205 buf[2] = res->noise & 0xff; 1206 buf[3] = res->level & 0xff; 1207 buf[4] = res->tsf & 0xff; 1208 random_add_randomness(buf, sizeof(buf)); 1209 } 1210 #endif /* CONFIG_NO_RANDOM_POOL */ 1211 1212 if (own_request && wpa_s->scan_res_handler) { 1213 void (*scan_res_handler)(struct wpa_supplicant *wpa_s, 1214 struct wpa_scan_results *scan_res); 1215 1216 scan_res_handler = wpa_s->scan_res_handler; 1217 wpa_s->scan_res_handler = NULL; 1218 scan_res_handler(wpa_s, scan_res); 1219 1220 wpa_scan_results_free(scan_res); 1221 return -2; 1222 } 1223 1224 if (ap) { 1225 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode"); 1226 #ifdef CONFIG_AP 1227 if (wpa_s->ap_iface->scan_cb) 1228 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface); 1229 #endif /* CONFIG_AP */ 1230 wpa_scan_results_free(scan_res); 1231 return 0; 1232 } 1233 1234 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available"); 1235 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); 1236 wpas_notify_scan_results(wpa_s); 1237 1238 wpas_notify_scan_done(wpa_s, 1); 1239 1240 if (sme_proc_obss_scan(wpa_s) > 0) { 1241 wpa_scan_results_free(scan_res); 1242 return 0; 1243 } 1244 1245 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) { 1246 wpa_scan_results_free(scan_res); 1247 return 0; 1248 } 1249 1250 if (autoscan_notify_scan(wpa_s, scan_res)) { 1251 wpa_scan_results_free(scan_res); 1252 return 0; 1253 } 1254 1255 if (wpa_s->disconnected) { 1256 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); 1257 wpa_scan_results_free(scan_res); 1258 return 0; 1259 } 1260 1261 if (!wpas_driver_bss_selection(wpa_s) && 1262 bgscan_notify_scan(wpa_s, scan_res) == 1) { 1263 wpa_scan_results_free(scan_res); 1264 return 0; 1265 } 1266 1267 wpas_wps_update_ap_info(wpa_s, scan_res); 1268 1269 wpa_scan_results_free(scan_res); 1270 1271 return wpas_select_network_from_last_scan(wpa_s, 1); 1272 } 1273 1274 1275 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, 1276 int new_scan) 1277 { 1278 struct wpa_bss *selected; 1279 struct wpa_ssid *ssid = NULL; 1280 1281 selected = wpa_supplicant_pick_network(wpa_s, &ssid); 1282 1283 if (selected) { 1284 int skip; 1285 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid); 1286 if (skip) { 1287 if (new_scan) 1288 wpa_supplicant_rsn_preauth_scan_results(wpa_s); 1289 return 0; 1290 } 1291 1292 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) { 1293 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed"); 1294 return -1; 1295 } 1296 if (new_scan) 1297 wpa_supplicant_rsn_preauth_scan_results(wpa_s); 1298 /* 1299 * Do not notify other virtual radios of scan results since we do not 1300 * want them to start other associations at the same time. 1301 */ 1302 return 1; 1303 } else { 1304 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found"); 1305 ssid = wpa_supplicant_pick_new_network(wpa_s); 1306 if (ssid) { 1307 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network"); 1308 wpa_supplicant_associate(wpa_s, NULL, ssid); 1309 if (new_scan) 1310 wpa_supplicant_rsn_preauth_scan_results(wpa_s); 1311 } else { 1312 int timeout_sec = wpa_s->scan_interval; 1313 int timeout_usec = 0; 1314 #ifdef CONFIG_P2P 1315 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1) 1316 return 0; 1317 1318 if (wpa_s->p2p_in_provisioning) { 1319 /* 1320 * Use shorter wait during P2P Provisioning 1321 * state to speed up group formation. 1322 */ 1323 timeout_sec = 0; 1324 timeout_usec = 250000; 1325 wpa_supplicant_req_new_scan(wpa_s, timeout_sec, 1326 timeout_usec); 1327 return 0; 1328 } 1329 #endif /* CONFIG_P2P */ 1330 #ifdef CONFIG_INTERWORKING 1331 if (wpa_s->conf->auto_interworking && 1332 wpa_s->conf->interworking && 1333 wpa_s->conf->cred) { 1334 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: " 1335 "start ANQP fetch since no matching " 1336 "networks found"); 1337 wpa_s->network_select = 1; 1338 wpa_s->auto_network_select = 1; 1339 interworking_start_fetch_anqp(wpa_s); 1340 return 1; 1341 } 1342 #endif /* CONFIG_INTERWORKING */ 1343 if (wpa_supplicant_req_sched_scan(wpa_s)) 1344 wpa_supplicant_req_new_scan(wpa_s, timeout_sec, 1345 timeout_usec); 1346 } 1347 } 1348 return 0; 1349 } 1350 1351 1352 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, 1353 union wpa_event_data *data) 1354 { 1355 const char *rn, *rn2; 1356 struct wpa_supplicant *ifs; 1357 1358 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) { 1359 /* 1360 * If no scan results could be fetched, then no need to 1361 * notify those interfaces that did not actually request 1362 * this scan. Similarly, if scan results started a new operation on this 1363 * interface, do not notify other interfaces to avoid concurrent 1364 * operations during a connection attempt. 1365 */ 1366 return; 1367 } 1368 1369 /* 1370 * Check other interfaces to see if they have the same radio-name. If 1371 * so, they get updated with this same scan info. 1372 */ 1373 if (!wpa_s->driver->get_radio_name) 1374 return; 1375 1376 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv); 1377 if (rn == NULL || rn[0] == '\0') 1378 return; 1379 1380 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces " 1381 "sharing same radio (%s) in event_scan_results", rn); 1382 1383 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { 1384 if (ifs == wpa_s || !ifs->driver->get_radio_name) 1385 continue; 1386 1387 rn2 = ifs->driver->get_radio_name(ifs->drv_priv); 1388 if (rn2 && os_strcmp(rn, rn2) == 0) { 1389 wpa_printf(MSG_DEBUG, "%s: Updating scan results from " 1390 "sibling", ifs->ifname); 1391 _wpa_supplicant_event_scan_results(ifs, data, 0); 1392 } 1393 } 1394 } 1395 1396 #endif /* CONFIG_NO_SCAN_PROCESSING */ 1397 1398 1399 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s) 1400 { 1401 #ifdef CONFIG_NO_SCAN_PROCESSING 1402 return -1; 1403 #else /* CONFIG_NO_SCAN_PROCESSING */ 1404 struct os_time now; 1405 1406 if (wpa_s->last_scan_res_used <= 0) 1407 return -1; 1408 1409 os_get_time(&now); 1410 if (now.sec - wpa_s->last_scan.sec > 5) { 1411 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results"); 1412 return -1; 1413 } 1414 1415 return wpas_select_network_from_last_scan(wpa_s, 0); 1416 #endif /* CONFIG_NO_SCAN_PROCESSING */ 1417 } 1418 1419 #ifdef CONFIG_WNM 1420 1421 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx) 1422 { 1423 struct wpa_supplicant *wpa_s = eloop_ctx; 1424 1425 if (wpa_s->wpa_state < WPA_ASSOCIATED) 1426 return; 1427 1428 if (!wpa_s->no_keep_alive) { 1429 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR, 1430 MAC2STR(wpa_s->bssid)); 1431 /* TODO: could skip this if normal data traffic has been sent */ 1432 /* TODO: Consider using some more appropriate data frame for 1433 * this */ 1434 if (wpa_s->l2) 1435 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, 1436 (u8 *) "", 0); 1437 } 1438 1439 #ifdef CONFIG_SME 1440 if (wpa_s->sme.bss_max_idle_period) { 1441 unsigned int msec; 1442 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */ 1443 if (msec > 100) 1444 msec -= 100; 1445 eloop_register_timeout(msec / 1000, msec % 1000 * 1000, 1446 wnm_bss_keep_alive, wpa_s, NULL); 1447 } 1448 #endif /* CONFIG_SME */ 1449 } 1450 1451 1452 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s, 1453 const u8 *ies, size_t ies_len) 1454 { 1455 struct ieee802_11_elems elems; 1456 1457 if (ies == NULL) 1458 return; 1459 1460 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) 1461 return; 1462 1463 #ifdef CONFIG_SME 1464 if (elems.bss_max_idle_period) { 1465 unsigned int msec; 1466 wpa_s->sme.bss_max_idle_period = 1467 WPA_GET_LE16(elems.bss_max_idle_period); 1468 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 " 1469 "TU)%s", wpa_s->sme.bss_max_idle_period, 1470 (elems.bss_max_idle_period[2] & 0x01) ? 1471 " (protected keep-live required)" : ""); 1472 if (wpa_s->sme.bss_max_idle_period == 0) 1473 wpa_s->sme.bss_max_idle_period = 1; 1474 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) { 1475 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); 1476 /* msec times 1000 */ 1477 msec = wpa_s->sme.bss_max_idle_period * 1024; 1478 if (msec > 100) 1479 msec -= 100; 1480 eloop_register_timeout(msec / 1000, msec % 1000 * 1000, 1481 wnm_bss_keep_alive, wpa_s, 1482 NULL); 1483 } 1484 } 1485 #endif /* CONFIG_SME */ 1486 } 1487 1488 #endif /* CONFIG_WNM */ 1489 1490 1491 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s) 1492 { 1493 #ifdef CONFIG_WNM 1494 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); 1495 #endif /* CONFIG_WNM */ 1496 } 1497 1498 1499 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, 1500 union wpa_event_data *data) 1501 { 1502 int l, len, found = 0, wpa_found, rsn_found; 1503 const u8 *p; 1504 #ifdef CONFIG_IEEE80211R 1505 u8 bssid[ETH_ALEN]; 1506 #endif /* CONFIG_IEEE80211R */ 1507 1508 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event"); 1509 if (data->assoc_info.req_ies) 1510 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, 1511 data->assoc_info.req_ies_len); 1512 if (data->assoc_info.resp_ies) { 1513 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, 1514 data->assoc_info.resp_ies_len); 1515 #ifdef CONFIG_TDLS 1516 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies, 1517 data->assoc_info.resp_ies_len); 1518 #endif /* CONFIG_TDLS */ 1519 #ifdef CONFIG_WNM 1520 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, 1521 data->assoc_info.resp_ies_len); 1522 #endif /* CONFIG_WNM */ 1523 } 1524 if (data->assoc_info.beacon_ies) 1525 wpa_hexdump(MSG_DEBUG, "beacon_ies", 1526 data->assoc_info.beacon_ies, 1527 data->assoc_info.beacon_ies_len); 1528 if (data->assoc_info.freq) 1529 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz", 1530 data->assoc_info.freq); 1531 1532 p = data->assoc_info.req_ies; 1533 l = data->assoc_info.req_ies_len; 1534 1535 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ 1536 while (p && l >= 2) { 1537 len = p[1] + 2; 1538 if (len > l) { 1539 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", 1540 p, l); 1541 break; 1542 } 1543 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && 1544 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || 1545 (p[0] == WLAN_EID_RSN && p[1] >= 2)) { 1546 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) 1547 break; 1548 found = 1; 1549 wpa_find_assoc_pmkid(wpa_s); 1550 break; 1551 } 1552 l -= len; 1553 p += len; 1554 } 1555 if (!found && data->assoc_info.req_ies) 1556 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); 1557 1558 #ifdef CONFIG_IEEE80211R 1559 #ifdef CONFIG_SME 1560 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) { 1561 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || 1562 wpa_ft_validate_reassoc_resp(wpa_s->wpa, 1563 data->assoc_info.resp_ies, 1564 data->assoc_info.resp_ies_len, 1565 bssid) < 0) { 1566 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " 1567 "Reassociation Response failed"); 1568 wpa_supplicant_deauthenticate( 1569 wpa_s, WLAN_REASON_INVALID_IE); 1570 return -1; 1571 } 1572 } 1573 1574 p = data->assoc_info.resp_ies; 1575 l = data->assoc_info.resp_ies_len; 1576 1577 #ifdef CONFIG_WPS_STRICT 1578 if (p && wpa_s->current_ssid && 1579 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) { 1580 struct wpabuf *wps; 1581 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE); 1582 if (wps == NULL) { 1583 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not " 1584 "include WPS IE in (Re)Association Response"); 1585 return -1; 1586 } 1587 1588 if (wps_validate_assoc_resp(wps) < 0) { 1589 wpabuf_free(wps); 1590 wpa_supplicant_deauthenticate( 1591 wpa_s, WLAN_REASON_INVALID_IE); 1592 return -1; 1593 } 1594 wpabuf_free(wps); 1595 } 1596 #endif /* CONFIG_WPS_STRICT */ 1597 1598 /* Go through the IEs and make a copy of the MDIE, if present. */ 1599 while (p && l >= 2) { 1600 len = p[1] + 2; 1601 if (len > l) { 1602 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", 1603 p, l); 1604 break; 1605 } 1606 if (p[0] == WLAN_EID_MOBILITY_DOMAIN && 1607 p[1] >= MOBILITY_DOMAIN_ID_LEN) { 1608 wpa_s->sme.ft_used = 1; 1609 os_memcpy(wpa_s->sme.mobility_domain, p + 2, 1610 MOBILITY_DOMAIN_ID_LEN); 1611 break; 1612 } 1613 l -= len; 1614 p += len; 1615 } 1616 #endif /* CONFIG_SME */ 1617 1618 /* Process FT when SME is in the driver */ 1619 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && 1620 wpa_ft_is_completed(wpa_s->wpa)) { 1621 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || 1622 wpa_ft_validate_reassoc_resp(wpa_s->wpa, 1623 data->assoc_info.resp_ies, 1624 data->assoc_info.resp_ies_len, 1625 bssid) < 0) { 1626 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " 1627 "Reassociation Response failed"); 1628 wpa_supplicant_deauthenticate( 1629 wpa_s, WLAN_REASON_INVALID_IE); 1630 return -1; 1631 } 1632 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done"); 1633 } 1634 1635 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies, 1636 data->assoc_info.resp_ies_len); 1637 #endif /* CONFIG_IEEE80211R */ 1638 1639 /* WPA/RSN IE from Beacon/ProbeResp */ 1640 p = data->assoc_info.beacon_ies; 1641 l = data->assoc_info.beacon_ies_len; 1642 1643 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. 1644 */ 1645 wpa_found = rsn_found = 0; 1646 while (p && l >= 2) { 1647 len = p[1] + 2; 1648 if (len > l) { 1649 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", 1650 p, l); 1651 break; 1652 } 1653 if (!wpa_found && 1654 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && 1655 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { 1656 wpa_found = 1; 1657 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); 1658 } 1659 1660 if (!rsn_found && 1661 p[0] == WLAN_EID_RSN && p[1] >= 2) { 1662 rsn_found = 1; 1663 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); 1664 } 1665 1666 l -= len; 1667 p += len; 1668 } 1669 1670 if (!wpa_found && data->assoc_info.beacon_ies) 1671 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); 1672 if (!rsn_found && data->assoc_info.beacon_ies) 1673 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); 1674 if (wpa_found || rsn_found) 1675 wpa_s->ap_ies_from_associnfo = 1; 1676 1677 if (wpa_s->assoc_freq && data->assoc_info.freq && 1678 wpa_s->assoc_freq != data->assoc_info.freq) { 1679 wpa_printf(MSG_DEBUG, "Operating frequency changed from " 1680 "%u to %u MHz", 1681 wpa_s->assoc_freq, data->assoc_info.freq); 1682 wpa_supplicant_update_scan_results(wpa_s); 1683 } 1684 1685 wpa_s->assoc_freq = data->assoc_info.freq; 1686 1687 return 0; 1688 } 1689 1690 1691 static struct wpa_bss * wpa_supplicant_get_new_bss( 1692 struct wpa_supplicant *wpa_s, const u8 *bssid) 1693 { 1694 struct wpa_bss *bss = NULL; 1695 struct wpa_ssid *ssid = wpa_s->current_ssid; 1696 1697 if (ssid->ssid_len > 0) 1698 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); 1699 if (!bss) 1700 bss = wpa_bss_get_bssid(wpa_s, bssid); 1701 1702 return bss; 1703 } 1704 1705 1706 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s) 1707 { 1708 const u8 *bss_wpa = NULL, *bss_rsn = NULL; 1709 1710 if (!wpa_s->current_bss || !wpa_s->current_ssid) 1711 return -1; 1712 1713 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt)) 1714 return 0; 1715 1716 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss, 1717 WPA_IE_VENDOR_TYPE); 1718 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN); 1719 1720 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa, 1721 bss_wpa ? 2 + bss_wpa[1] : 0) || 1722 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn, 1723 bss_rsn ? 2 + bss_rsn[1] : 0)) 1724 return -1; 1725 1726 return 0; 1727 } 1728 1729 1730 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, 1731 union wpa_event_data *data) 1732 { 1733 u8 bssid[ETH_ALEN]; 1734 int ft_completed; 1735 1736 #ifdef CONFIG_AP 1737 if (wpa_s->ap_iface) { 1738 hostapd_notif_assoc(wpa_s->ap_iface->bss[0], 1739 data->assoc_info.addr, 1740 data->assoc_info.req_ies, 1741 data->assoc_info.req_ies_len, 1742 data->assoc_info.reassoc); 1743 return; 1744 } 1745 #endif /* CONFIG_AP */ 1746 1747 ft_completed = wpa_ft_is_completed(wpa_s->wpa); 1748 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0) 1749 return; 1750 1751 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { 1752 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID"); 1753 wpa_supplicant_deauthenticate( 1754 wpa_s, WLAN_REASON_DEAUTH_LEAVING); 1755 return; 1756 } 1757 1758 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); 1759 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) { 1760 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" 1761 MACSTR, MAC2STR(bssid)); 1762 random_add_randomness(bssid, ETH_ALEN); 1763 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); 1764 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); 1765 wpas_notify_bssid_changed(wpa_s); 1766 1767 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { 1768 wpa_clear_keys(wpa_s, bssid); 1769 } 1770 if (wpa_supplicant_select_config(wpa_s) < 0) { 1771 wpa_supplicant_deauthenticate( 1772 wpa_s, WLAN_REASON_DEAUTH_LEAVING); 1773 return; 1774 } 1775 if (wpa_s->current_ssid) { 1776 struct wpa_bss *bss = NULL; 1777 1778 bss = wpa_supplicant_get_new_bss(wpa_s, bssid); 1779 if (!bss) { 1780 wpa_supplicant_update_scan_results(wpa_s); 1781 1782 /* Get the BSS from the new scan results */ 1783 bss = wpa_supplicant_get_new_bss(wpa_s, bssid); 1784 } 1785 1786 if (bss) 1787 wpa_s->current_bss = bss; 1788 } 1789 1790 #ifdef ANDROID 1791 if (wpa_s->conf->ap_scan == 1) { 1792 #else 1793 if (wpa_s->conf->ap_scan == 1 && 1794 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) { 1795 #endif 1796 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0) 1797 wpa_msg(wpa_s, MSG_WARNING, 1798 "WPA/RSN IEs not updated"); 1799 } 1800 } 1801 1802 #ifdef CONFIG_SME 1803 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN); 1804 wpa_s->sme.prev_bssid_set = 1; 1805 #endif /* CONFIG_SME */ 1806 1807 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); 1808 if (wpa_s->current_ssid) { 1809 /* When using scanning (ap_scan=1), SIM PC/SC interface can be 1810 * initialized before association, but for other modes, 1811 * initialize PC/SC here, if the current configuration needs 1812 * smartcard or SIM/USIM. */ 1813 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); 1814 } 1815 wpa_sm_notify_assoc(wpa_s->wpa, bssid); 1816 if (wpa_s->l2) 1817 l2_packet_notify_auth_start(wpa_s->l2); 1818 1819 /* 1820 * Set portEnabled first to FALSE in order to get EAP state machine out 1821 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE 1822 * state machine may transit to AUTHENTICATING state based on obsolete 1823 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to 1824 * AUTHENTICATED without ever giving chance to EAP state machine to 1825 * reset the state. 1826 */ 1827 if (!ft_completed) { 1828 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); 1829 eapol_sm_notify_portValid(wpa_s->eapol, FALSE); 1830 } 1831 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed) 1832 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); 1833 /* 802.1X::portControl = Auto */ 1834 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE); 1835 wpa_s->eapol_received = 0; 1836 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || 1837 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || 1838 (wpa_s->current_ssid && 1839 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) { 1840 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE && 1841 (wpa_s->drv_flags & 1842 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { 1843 /* 1844 * Set the key after having received joined-IBSS event 1845 * from the driver. 1846 */ 1847 wpa_supplicant_set_wpa_none_key(wpa_s, 1848 wpa_s->current_ssid); 1849 } 1850 wpa_supplicant_cancel_auth_timeout(wpa_s); 1851 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); 1852 } else if (!ft_completed) { 1853 /* Timeout for receiving the first EAPOL packet */ 1854 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); 1855 } 1856 wpa_supplicant_cancel_scan(wpa_s); 1857 1858 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && 1859 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { 1860 /* 1861 * We are done; the driver will take care of RSN 4-way 1862 * handshake. 1863 */ 1864 wpa_supplicant_cancel_auth_timeout(wpa_s); 1865 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); 1866 eapol_sm_notify_portValid(wpa_s->eapol, TRUE); 1867 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); 1868 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && 1869 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { 1870 /* 1871 * The driver will take care of RSN 4-way handshake, so we need 1872 * to allow EAPOL supplicant to complete its work without 1873 * waiting for WPA supplicant. 1874 */ 1875 eapol_sm_notify_portValid(wpa_s->eapol, TRUE); 1876 } else if (ft_completed) { 1877 /* 1878 * FT protocol completed - make sure EAPOL state machine ends 1879 * up in authenticated. 1880 */ 1881 wpa_supplicant_cancel_auth_timeout(wpa_s); 1882 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); 1883 eapol_sm_notify_portValid(wpa_s->eapol, TRUE); 1884 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); 1885 } 1886 1887 wpa_s->last_eapol_matches_bssid = 0; 1888 1889 if (wpa_s->pending_eapol_rx) { 1890 struct os_time now, age; 1891 os_get_time(&now); 1892 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age); 1893 if (age.sec == 0 && age.usec < 100000 && 1894 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) == 1895 0) { 1896 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL " 1897 "frame that was received just before " 1898 "association notification"); 1899 wpa_supplicant_rx_eapol( 1900 wpa_s, wpa_s->pending_eapol_rx_src, 1901 wpabuf_head(wpa_s->pending_eapol_rx), 1902 wpabuf_len(wpa_s->pending_eapol_rx)); 1903 } 1904 wpabuf_free(wpa_s->pending_eapol_rx); 1905 wpa_s->pending_eapol_rx = NULL; 1906 } 1907 1908 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || 1909 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && 1910 wpa_s->current_ssid && 1911 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { 1912 /* Set static WEP keys again */ 1913 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); 1914 } 1915 1916 #ifdef CONFIG_IBSS_RSN 1917 if (wpa_s->current_ssid && 1918 wpa_s->current_ssid->mode == WPAS_MODE_IBSS && 1919 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && 1920 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE && 1921 wpa_s->ibss_rsn == NULL) { 1922 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s); 1923 if (!wpa_s->ibss_rsn) { 1924 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN"); 1925 wpa_supplicant_deauthenticate( 1926 wpa_s, WLAN_REASON_DEAUTH_LEAVING); 1927 return; 1928 } 1929 1930 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk); 1931 } 1932 #endif /* CONFIG_IBSS_RSN */ 1933 1934 wpas_wps_notify_assoc(wpa_s, bssid); 1935 } 1936 1937 1938 static int disconnect_reason_recoverable(u16 reason_code) 1939 { 1940 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY || 1941 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA || 1942 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA; 1943 } 1944 1945 1946 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, 1947 u16 reason_code, 1948 int locally_generated) 1949 { 1950 const u8 *bssid; 1951 1952 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { 1953 /* 1954 * At least Host AP driver and a Prism3 card seemed to be 1955 * generating streams of disconnected events when configuring 1956 * IBSS for WPA-None. Ignore them for now. 1957 */ 1958 return; 1959 } 1960 1961 bssid = wpa_s->bssid; 1962 if (is_zero_ether_addr(bssid)) 1963 bssid = wpa_s->pending_bssid; 1964 1965 if (!is_zero_ether_addr(bssid) || 1966 wpa_s->wpa_state >= WPA_AUTHENTICATING) { 1967 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR 1968 " reason=%d%s", 1969 MAC2STR(bssid), reason_code, 1970 locally_generated ? " locally_generated=1" : ""); 1971 } 1972 } 1973 1974 1975 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code, 1976 int locally_generated) 1977 { 1978 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE || 1979 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) 1980 return 0; /* Not in 4-way handshake with PSK */ 1981 1982 /* 1983 * It looks like connection was lost while trying to go through PSK 1984 * 4-way handshake. Filter out known disconnection cases that are caused 1985 * by something else than PSK mismatch to avoid confusing reports. 1986 */ 1987 1988 if (locally_generated) { 1989 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS) 1990 return 0; 1991 } 1992 1993 return 1; 1994 } 1995 1996 1997 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s, 1998 u16 reason_code, 1999 int locally_generated) 2000 { 2001 const u8 *bssid; 2002 int authenticating; 2003 u8 prev_pending_bssid[ETH_ALEN]; 2004 struct wpa_bss *fast_reconnect = NULL; 2005 #ifndef CONFIG_NO_SCAN_PROCESSING 2006 struct wpa_ssid *fast_reconnect_ssid = NULL; 2007 #endif /* CONFIG_NO_SCAN_PROCESSING */ 2008 struct wpa_ssid *last_ssid; 2009 2010 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING; 2011 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN); 2012 2013 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { 2014 /* 2015 * At least Host AP driver and a Prism3 card seemed to be 2016 * generating streams of disconnected events when configuring 2017 * IBSS for WPA-None. Ignore them for now. 2018 */ 2019 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in " 2020 "IBSS/WPA-None mode"); 2021 return; 2022 } 2023 2024 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) { 2025 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " 2026 "pre-shared key may be incorrect"); 2027 if (wpas_p2p_4way_hs_failed(wpa_s) > 0) 2028 return; /* P2P group removed */ 2029 wpas_auth_failed(wpa_s); 2030 } 2031 if (!wpa_s->disconnected && 2032 (!wpa_s->auto_reconnect_disabled || 2033 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) { 2034 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to " 2035 "reconnect (wps=%d wpa_state=%d)", 2036 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS, 2037 wpa_s->wpa_state); 2038 if (wpa_s->wpa_state == WPA_COMPLETED && 2039 wpa_s->current_ssid && 2040 wpa_s->current_ssid->mode == WPAS_MODE_INFRA && 2041 !locally_generated && 2042 disconnect_reason_recoverable(reason_code)) { 2043 /* 2044 * It looks like the AP has dropped association with 2045 * us, but could allow us to get back in. Try to 2046 * reconnect to the same BSS without full scan to save 2047 * time for some common cases. 2048 */ 2049 fast_reconnect = wpa_s->current_bss; 2050 #ifndef CONFIG_NO_SCAN_PROCESSING 2051 fast_reconnect_ssid = wpa_s->current_ssid; 2052 #endif /* CONFIG_NO_SCAN_PROCESSING */ 2053 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) 2054 #ifdef ANDROID 2055 wpa_supplicant_req_scan(wpa_s, 0, 500000); 2056 #else 2057 wpa_supplicant_req_scan(wpa_s, 0, 100000); 2058 #endif 2059 else 2060 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new " 2061 "immediate scan"); 2062 } else { 2063 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not " 2064 "try to re-connect"); 2065 wpa_s->reassociate = 0; 2066 wpa_s->disconnected = 1; 2067 wpa_supplicant_cancel_sched_scan(wpa_s); 2068 } 2069 bssid = wpa_s->bssid; 2070 if (is_zero_ether_addr(bssid)) 2071 bssid = wpa_s->pending_bssid; 2072 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) 2073 wpas_connection_failed(wpa_s, bssid); 2074 wpa_sm_notify_disassoc(wpa_s->wpa); 2075 if (locally_generated) 2076 wpa_s->disconnect_reason = -reason_code; 2077 else 2078 wpa_s->disconnect_reason = reason_code; 2079 wpas_notify_disconnect_reason(wpa_s); 2080 if (wpa_supplicant_dynamic_keys(wpa_s)) { 2081 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys"); 2082 wpa_s->keys_cleared = 0; 2083 wpa_clear_keys(wpa_s, wpa_s->bssid); 2084 } 2085 last_ssid = wpa_s->current_ssid; 2086 wpa_supplicant_mark_disassoc(wpa_s); 2087 2088 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) { 2089 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid); 2090 wpa_s->current_ssid = last_ssid; 2091 } 2092 2093 if (fast_reconnect) { 2094 #ifndef CONFIG_NO_SCAN_PROCESSING 2095 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS"); 2096 if (wpa_supplicant_connect(wpa_s, fast_reconnect, 2097 fast_reconnect_ssid) < 0) { 2098 /* Recover through full scan */ 2099 wpa_supplicant_req_scan(wpa_s, 0, 100000); 2100 } 2101 #endif /* CONFIG_NO_SCAN_PROCESSING */ 2102 } 2103 } 2104 2105 2106 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT 2107 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx) 2108 { 2109 struct wpa_supplicant *wpa_s = eloop_ctx; 2110 2111 if (!wpa_s->pending_mic_error_report) 2112 return; 2113 2114 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report"); 2115 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); 2116 wpa_s->pending_mic_error_report = 0; 2117 } 2118 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ 2119 2120 2121 static void 2122 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, 2123 union wpa_event_data *data) 2124 { 2125 int pairwise; 2126 struct os_time t; 2127 2128 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); 2129 pairwise = (data && data->michael_mic_failure.unicast); 2130 os_get_time(&t); 2131 if ((wpa_s->last_michael_mic_error && 2132 t.sec - wpa_s->last_michael_mic_error <= 60) || 2133 wpa_s->pending_mic_error_report) { 2134 if (wpa_s->pending_mic_error_report) { 2135 /* 2136 * Send the pending MIC error report immediately since 2137 * we are going to start countermeasures and AP better 2138 * do the same. 2139 */ 2140 wpa_sm_key_request(wpa_s->wpa, 1, 2141 wpa_s->pending_mic_error_pairwise); 2142 } 2143 2144 /* Send the new MIC error report immediately since we are going 2145 * to start countermeasures and AP better do the same. 2146 */ 2147 wpa_sm_key_request(wpa_s->wpa, 1, pairwise); 2148 2149 /* initialize countermeasures */ 2150 wpa_s->countermeasures = 1; 2151 2152 wpa_blacklist_add(wpa_s, wpa_s->bssid); 2153 2154 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); 2155 2156 /* 2157 * Need to wait for completion of request frame. We do not get 2158 * any callback for the message completion, so just wait a 2159 * short while and hope for the best. */ 2160 os_sleep(0, 10000); 2161 2162 wpa_drv_set_countermeasures(wpa_s, 1); 2163 wpa_supplicant_deauthenticate(wpa_s, 2164 WLAN_REASON_MICHAEL_MIC_FAILURE); 2165 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, 2166 wpa_s, NULL); 2167 eloop_register_timeout(60, 0, 2168 wpa_supplicant_stop_countermeasures, 2169 wpa_s, NULL); 2170 /* TODO: mark the AP rejected for 60 second. STA is 2171 * allowed to associate with another AP.. */ 2172 } else { 2173 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT 2174 if (wpa_s->mic_errors_seen) { 2175 /* 2176 * Reduce the effectiveness of Michael MIC error 2177 * reports as a means for attacking against TKIP if 2178 * more than one MIC failure is noticed with the same 2179 * PTK. We delay the transmission of the reports by a 2180 * random time between 0 and 60 seconds in order to 2181 * force the attacker wait 60 seconds before getting 2182 * the information on whether a frame resulted in a MIC 2183 * failure. 2184 */ 2185 u8 rval[4]; 2186 int sec; 2187 2188 if (os_get_random(rval, sizeof(rval)) < 0) 2189 sec = os_random() % 60; 2190 else 2191 sec = WPA_GET_BE32(rval) % 60; 2192 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error " 2193 "report %d seconds", sec); 2194 wpa_s->pending_mic_error_report = 1; 2195 wpa_s->pending_mic_error_pairwise = pairwise; 2196 eloop_cancel_timeout( 2197 wpa_supplicant_delayed_mic_error_report, 2198 wpa_s, NULL); 2199 eloop_register_timeout( 2200 sec, os_random() % 1000000, 2201 wpa_supplicant_delayed_mic_error_report, 2202 wpa_s, NULL); 2203 } else { 2204 wpa_sm_key_request(wpa_s->wpa, 1, pairwise); 2205 } 2206 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ 2207 wpa_sm_key_request(wpa_s->wpa, 1, pairwise); 2208 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ 2209 } 2210 wpa_s->last_michael_mic_error = t.sec; 2211 wpa_s->mic_errors_seen++; 2212 } 2213 2214 2215 #ifdef CONFIG_TERMINATE_ONLASTIF 2216 static int any_interfaces(struct wpa_supplicant *head) 2217 { 2218 struct wpa_supplicant *wpa_s; 2219 2220 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) 2221 if (!wpa_s->interface_removed) 2222 return 1; 2223 return 0; 2224 } 2225 #endif /* CONFIG_TERMINATE_ONLASTIF */ 2226 2227 2228 static void 2229 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, 2230 union wpa_event_data *data) 2231 { 2232 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) 2233 return; 2234 2235 switch (data->interface_status.ievent) { 2236 case EVENT_INTERFACE_ADDED: 2237 if (!wpa_s->interface_removed) 2238 break; 2239 wpa_s->interface_removed = 0; 2240 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added"); 2241 if (wpa_supplicant_driver_init(wpa_s) < 0) { 2242 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the " 2243 "driver after interface was added"); 2244 } 2245 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); 2246 break; 2247 case EVENT_INTERFACE_REMOVED: 2248 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed"); 2249 wpa_s->interface_removed = 1; 2250 wpa_supplicant_mark_disassoc(wpa_s); 2251 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); 2252 l2_packet_deinit(wpa_s->l2); 2253 wpa_s->l2 = NULL; 2254 #ifdef CONFIG_IBSS_RSN 2255 ibss_rsn_deinit(wpa_s->ibss_rsn); 2256 wpa_s->ibss_rsn = NULL; 2257 #endif /* CONFIG_IBSS_RSN */ 2258 #ifdef CONFIG_TERMINATE_ONLASTIF 2259 /* check if last interface */ 2260 if (!any_interfaces(wpa_s->global->ifaces)) 2261 eloop_terminate(); 2262 #endif /* CONFIG_TERMINATE_ONLASTIF */ 2263 break; 2264 } 2265 } 2266 2267 2268 #ifdef CONFIG_PEERKEY 2269 static void 2270 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s, 2271 union wpa_event_data *data) 2272 { 2273 if (data == NULL) 2274 return; 2275 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer); 2276 } 2277 #endif /* CONFIG_PEERKEY */ 2278 2279 2280 #ifdef CONFIG_TDLS 2281 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s, 2282 union wpa_event_data *data) 2283 { 2284 if (data == NULL) 2285 return; 2286 switch (data->tdls.oper) { 2287 case TDLS_REQUEST_SETUP: 2288 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer); 2289 if (wpa_tdls_is_external_setup(wpa_s->wpa)) 2290 wpa_tdls_start(wpa_s->wpa, data->tdls.peer); 2291 else 2292 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer); 2293 break; 2294 case TDLS_REQUEST_TEARDOWN: 2295 if (wpa_tdls_is_external_setup(wpa_s->wpa)) 2296 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer, 2297 data->tdls.reason_code); 2298 else 2299 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, 2300 data->tdls.peer); 2301 break; 2302 } 2303 } 2304 #endif /* CONFIG_TDLS */ 2305 2306 2307 #ifdef CONFIG_WNM 2308 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s, 2309 union wpa_event_data *data) 2310 { 2311 if (data == NULL) 2312 return; 2313 switch (data->wnm.oper) { 2314 case WNM_OPER_SLEEP: 2315 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request " 2316 "(action=%d, intval=%d)", 2317 data->wnm.sleep_action, data->wnm.sleep_intval); 2318 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action, 2319 data->wnm.sleep_intval, NULL); 2320 break; 2321 } 2322 } 2323 #endif /* CONFIG_WNM */ 2324 2325 2326 #ifdef CONFIG_IEEE80211R 2327 static void 2328 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s, 2329 union wpa_event_data *data) 2330 { 2331 if (data == NULL) 2332 return; 2333 2334 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies, 2335 data->ft_ies.ies_len, 2336 data->ft_ies.ft_action, 2337 data->ft_ies.target_ap, 2338 data->ft_ies.ric_ies, 2339 data->ft_ies.ric_ies_len) < 0) { 2340 /* TODO: prevent MLME/driver from trying to associate? */ 2341 } 2342 } 2343 #endif /* CONFIG_IEEE80211R */ 2344 2345 2346 #ifdef CONFIG_IBSS_RSN 2347 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s, 2348 union wpa_event_data *data) 2349 { 2350 struct wpa_ssid *ssid; 2351 if (wpa_s->wpa_state < WPA_ASSOCIATED) 2352 return; 2353 if (data == NULL) 2354 return; 2355 ssid = wpa_s->current_ssid; 2356 if (ssid == NULL) 2357 return; 2358 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) 2359 return; 2360 2361 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); 2362 } 2363 2364 2365 static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s, 2366 union wpa_event_data *data) 2367 { 2368 struct wpa_ssid *ssid = wpa_s->current_ssid; 2369 2370 if (ssid == NULL) 2371 return; 2372 2373 /* check if the ssid is correctly configured as IBSS/RSN */ 2374 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) 2375 return; 2376 2377 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame, 2378 data->rx_mgmt.frame_len); 2379 } 2380 #endif /* CONFIG_IBSS_RSN */ 2381 2382 2383 #ifdef CONFIG_IEEE80211R 2384 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data, 2385 size_t len) 2386 { 2387 const u8 *sta_addr, *target_ap_addr; 2388 u16 status; 2389 2390 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len); 2391 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) 2392 return; /* only SME case supported for now */ 2393 if (len < 1 + 2 * ETH_ALEN + 2) 2394 return; 2395 if (data[0] != 2) 2396 return; /* Only FT Action Response is supported for now */ 2397 sta_addr = data + 1; 2398 target_ap_addr = data + 1 + ETH_ALEN; 2399 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN); 2400 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA " 2401 MACSTR " TargetAP " MACSTR " status %u", 2402 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status); 2403 2404 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) { 2405 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR 2406 " in FT Action Response", MAC2STR(sta_addr)); 2407 return; 2408 } 2409 2410 if (status) { 2411 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates " 2412 "failure (status code %d)", status); 2413 /* TODO: report error to FT code(?) */ 2414 return; 2415 } 2416 2417 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2, 2418 len - (1 + 2 * ETH_ALEN + 2), 1, 2419 target_ap_addr, NULL, 0) < 0) 2420 return; 2421 2422 #ifdef CONFIG_SME 2423 { 2424 struct wpa_bss *bss; 2425 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr); 2426 if (bss) 2427 wpa_s->sme.freq = bss->freq; 2428 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT; 2429 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr, 2430 WLAN_AUTH_FT); 2431 } 2432 #endif /* CONFIG_SME */ 2433 } 2434 #endif /* CONFIG_IEEE80211R */ 2435 2436 2437 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s, 2438 struct unprot_deauth *e) 2439 { 2440 #ifdef CONFIG_IEEE80211W 2441 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame " 2442 "dropped: " MACSTR " -> " MACSTR 2443 " (reason code %u)", 2444 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); 2445 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); 2446 #endif /* CONFIG_IEEE80211W */ 2447 } 2448 2449 2450 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s, 2451 struct unprot_disassoc *e) 2452 { 2453 #ifdef CONFIG_IEEE80211W 2454 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame " 2455 "dropped: " MACSTR " -> " MACSTR 2456 " (reason code %u)", 2457 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); 2458 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); 2459 #endif /* CONFIG_IEEE80211W */ 2460 } 2461 2462 2463 static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr, 2464 u16 reason_code, int locally_generated, 2465 const u8 *ie, size_t ie_len, int deauth) 2466 { 2467 #ifdef CONFIG_AP 2468 if (wpa_s->ap_iface && addr) { 2469 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr); 2470 return; 2471 } 2472 2473 if (wpa_s->ap_iface) { 2474 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode"); 2475 return; 2476 } 2477 #endif /* CONFIG_AP */ 2478 2479 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated); 2480 2481 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED || 2482 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || 2483 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) && 2484 eapol_sm_failed(wpa_s->eapol))) 2485 wpas_auth_failed(wpa_s); 2486 2487 #ifdef CONFIG_P2P 2488 if (deauth && reason_code > 0) { 2489 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len, 2490 locally_generated) > 0) { 2491 /* 2492 * The interface was removed, so cannot continue 2493 * processing any additional operations after this. 2494 */ 2495 return; 2496 } 2497 } 2498 #endif /* CONFIG_P2P */ 2499 2500 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code, 2501 locally_generated); 2502 } 2503 2504 2505 static void wpas_event_disassoc(struct wpa_supplicant *wpa_s, 2506 struct disassoc_info *info) 2507 { 2508 u16 reason_code = 0; 2509 int locally_generated = 0; 2510 const u8 *addr = NULL; 2511 const u8 *ie = NULL; 2512 size_t ie_len = 0; 2513 2514 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification"); 2515 2516 if (info) { 2517 addr = info->addr; 2518 ie = info->ie; 2519 ie_len = info->ie_len; 2520 reason_code = info->reason_code; 2521 locally_generated = info->locally_generated; 2522 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code, 2523 locally_generated ? " (locally generated)" : ""); 2524 if (addr) 2525 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, 2526 MAC2STR(addr)); 2527 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)", 2528 ie, ie_len); 2529 } 2530 2531 #ifdef CONFIG_AP 2532 if (wpa_s->ap_iface && info && info->addr) { 2533 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr); 2534 return; 2535 } 2536 2537 if (wpa_s->ap_iface) { 2538 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode"); 2539 return; 2540 } 2541 #endif /* CONFIG_AP */ 2542 2543 #ifdef CONFIG_P2P 2544 if (info) { 2545 wpas_p2p_disassoc_notif( 2546 wpa_s, info->addr, reason_code, info->ie, info->ie_len, 2547 locally_generated); 2548 } 2549 #endif /* CONFIG_P2P */ 2550 2551 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) 2552 sme_event_disassoc(wpa_s, info); 2553 2554 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated, 2555 ie, ie_len, 0); 2556 } 2557 2558 2559 static void wpas_event_deauth(struct wpa_supplicant *wpa_s, 2560 struct deauth_info *info) 2561 { 2562 u16 reason_code = 0; 2563 int locally_generated = 0; 2564 const u8 *addr = NULL; 2565 const u8 *ie = NULL; 2566 size_t ie_len = 0; 2567 2568 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification"); 2569 2570 if (info) { 2571 addr = info->addr; 2572 ie = info->ie; 2573 ie_len = info->ie_len; 2574 reason_code = info->reason_code; 2575 locally_generated = info->locally_generated; 2576 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", 2577 reason_code, 2578 locally_generated ? " (locally generated)" : ""); 2579 if (addr) { 2580 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, 2581 MAC2STR(addr)); 2582 } 2583 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)", 2584 ie, ie_len); 2585 } 2586 2587 wpa_reset_ft_completed(wpa_s->wpa); 2588 2589 wpas_event_disconnect(wpa_s, addr, reason_code, 2590 locally_generated, ie, ie_len, 1); 2591 } 2592 2593 2594 void wpa_supplicant_event(void *ctx, enum wpa_event_type event, 2595 union wpa_event_data *data) 2596 { 2597 struct wpa_supplicant *wpa_s = ctx; 2598 2599 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED && 2600 event != EVENT_INTERFACE_ENABLED && 2601 event != EVENT_INTERFACE_STATUS && 2602 event != EVENT_SCHED_SCAN_STOPPED) { 2603 wpa_dbg(wpa_s, MSG_DEBUG, 2604 "Ignore event %s (%d) while interface is disabled", 2605 event_to_string(event), event); 2606 return; 2607 } 2608 2609 #ifndef CONFIG_NO_STDOUT_DEBUG 2610 { 2611 int level = MSG_DEBUG; 2612 2613 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) { 2614 const struct ieee80211_hdr *hdr; 2615 u16 fc; 2616 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; 2617 fc = le_to_host16(hdr->frame_control); 2618 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && 2619 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) 2620 level = MSG_EXCESSIVE; 2621 } 2622 2623 wpa_dbg(wpa_s, level, "Event %s (%d) received", 2624 event_to_string(event), event); 2625 } 2626 #endif /* CONFIG_NO_STDOUT_DEBUG */ 2627 2628 switch (event) { 2629 case EVENT_AUTH: 2630 sme_event_auth(wpa_s, data); 2631 break; 2632 case EVENT_ASSOC: 2633 wpa_supplicant_event_assoc(wpa_s, data); 2634 break; 2635 case EVENT_DISASSOC: 2636 wpas_event_disassoc(wpa_s, 2637 data ? &data->disassoc_info : NULL); 2638 break; 2639 case EVENT_DEAUTH: 2640 wpas_event_deauth(wpa_s, 2641 data ? &data->deauth_info : NULL); 2642 break; 2643 case EVENT_MICHAEL_MIC_FAILURE: 2644 wpa_supplicant_event_michael_mic_failure(wpa_s, data); 2645 break; 2646 #ifndef CONFIG_NO_SCAN_PROCESSING 2647 case EVENT_SCAN_RESULTS: 2648 wpa_supplicant_event_scan_results(wpa_s, data); 2649 if (wpa_s->wpa_state != WPA_AUTHENTICATING && 2650 wpa_s->wpa_state != WPA_ASSOCIATING) 2651 wpas_p2p_continue_after_scan(wpa_s); 2652 break; 2653 #endif /* CONFIG_NO_SCAN_PROCESSING */ 2654 case EVENT_ASSOCINFO: 2655 wpa_supplicant_event_associnfo(wpa_s, data); 2656 break; 2657 case EVENT_INTERFACE_STATUS: 2658 wpa_supplicant_event_interface_status(wpa_s, data); 2659 break; 2660 case EVENT_PMKID_CANDIDATE: 2661 wpa_supplicant_event_pmkid_candidate(wpa_s, data); 2662 break; 2663 #ifdef CONFIG_PEERKEY 2664 case EVENT_STKSTART: 2665 wpa_supplicant_event_stkstart(wpa_s, data); 2666 break; 2667 #endif /* CONFIG_PEERKEY */ 2668 #ifdef CONFIG_TDLS 2669 case EVENT_TDLS: 2670 wpa_supplicant_event_tdls(wpa_s, data); 2671 break; 2672 #endif /* CONFIG_TDLS */ 2673 #ifdef CONFIG_WNM 2674 case EVENT_WNM: 2675 wpa_supplicant_event_wnm(wpa_s, data); 2676 break; 2677 #endif /* CONFIG_WNM */ 2678 #ifdef CONFIG_IEEE80211R 2679 case EVENT_FT_RESPONSE: 2680 wpa_supplicant_event_ft_response(wpa_s, data); 2681 break; 2682 #endif /* CONFIG_IEEE80211R */ 2683 #ifdef CONFIG_IBSS_RSN 2684 case EVENT_IBSS_RSN_START: 2685 wpa_supplicant_event_ibss_rsn_start(wpa_s, data); 2686 break; 2687 #endif /* CONFIG_IBSS_RSN */ 2688 case EVENT_ASSOC_REJECT: 2689 if (data->assoc_reject.bssid) 2690 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT 2691 "bssid=" MACSTR " status_code=%u", 2692 MAC2STR(data->assoc_reject.bssid), 2693 data->assoc_reject.status_code); 2694 else 2695 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT 2696 "status_code=%u", 2697 data->assoc_reject.status_code); 2698 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) 2699 sme_event_assoc_reject(wpa_s, data); 2700 else { 2701 #ifdef ANDROID_P2P 2702 if(!wpa_s->current_ssid) { 2703 wpa_printf(MSG_ERROR, "current_ssid == NULL"); 2704 break; 2705 } 2706 /* If assoc reject is reported by the driver, then avoid 2707 * waiting for the authentication timeout. Cancel the 2708 * authentication timeout and retry the assoc. 2709 */ 2710 if(wpa_s->current_ssid->assoc_retry++ < 10) { 2711 wpa_printf(MSG_ERROR, "Retrying assoc: %d ", 2712 wpa_s->current_ssid->assoc_retry); 2713 2714 wpa_supplicant_cancel_auth_timeout(wpa_s); 2715 2716 /* Clear the states */ 2717 wpa_sm_notify_disassoc(wpa_s->wpa); 2718 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); 2719 2720 wpa_s->reassociate = 1; 2721 if (wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) { 2722 const u8 *bl_bssid = data->assoc_reject.bssid; 2723 if (!bl_bssid || is_zero_ether_addr(bl_bssid)) 2724 bl_bssid = wpa_s->pending_bssid; 2725 wpa_blacklist_add(wpa_s, bl_bssid); 2726 wpa_supplicant_req_scan(wpa_s, 0, 0); 2727 } else { 2728 wpa_supplicant_req_scan(wpa_s, 1, 0); 2729 } 2730 } else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { 2731 /* If we ASSOC_REJECT's hits threshold, disable the 2732 * network 2733 */ 2734 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. " 2735 "Disabling the network"); 2736 wpa_s->current_ssid->assoc_retry = 0; 2737 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid); 2738 wpas_p2p_group_remove(wpa_s, wpa_s->ifname); 2739 } 2740 #else 2741 const u8 *bssid = data->assoc_reject.bssid; 2742 if (bssid == NULL || is_zero_ether_addr(bssid)) 2743 bssid = wpa_s->pending_bssid; 2744 wpas_connection_failed(wpa_s, bssid); 2745 wpa_supplicant_mark_disassoc(wpa_s); 2746 #endif /* ANDROID_P2P */ 2747 } 2748 break; 2749 case EVENT_AUTH_TIMED_OUT: 2750 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) 2751 sme_event_auth_timed_out(wpa_s, data); 2752 break; 2753 case EVENT_ASSOC_TIMED_OUT: 2754 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) 2755 sme_event_assoc_timed_out(wpa_s, data); 2756 break; 2757 case EVENT_TX_STATUS: 2758 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR 2759 " type=%d stype=%d", 2760 MAC2STR(data->tx_status.dst), 2761 data->tx_status.type, data->tx_status.stype); 2762 #ifdef CONFIG_AP 2763 if (wpa_s->ap_iface == NULL) { 2764 #ifdef CONFIG_OFFCHANNEL 2765 if (data->tx_status.type == WLAN_FC_TYPE_MGMT && 2766 data->tx_status.stype == WLAN_FC_STYPE_ACTION) 2767 offchannel_send_action_tx_status( 2768 wpa_s, data->tx_status.dst, 2769 data->tx_status.data, 2770 data->tx_status.data_len, 2771 data->tx_status.ack ? 2772 OFFCHANNEL_SEND_ACTION_SUCCESS : 2773 OFFCHANNEL_SEND_ACTION_NO_ACK); 2774 #endif /* CONFIG_OFFCHANNEL */ 2775 break; 2776 } 2777 #endif /* CONFIG_AP */ 2778 #ifdef CONFIG_OFFCHANNEL 2779 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst=" 2780 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst)); 2781 /* 2782 * Catch TX status events for Action frames we sent via group 2783 * interface in GO mode. 2784 */ 2785 if (data->tx_status.type == WLAN_FC_TYPE_MGMT && 2786 data->tx_status.stype == WLAN_FC_STYPE_ACTION && 2787 os_memcmp(wpa_s->parent->pending_action_dst, 2788 data->tx_status.dst, ETH_ALEN) == 0) { 2789 offchannel_send_action_tx_status( 2790 wpa_s->parent, data->tx_status.dst, 2791 data->tx_status.data, 2792 data->tx_status.data_len, 2793 data->tx_status.ack ? 2794 OFFCHANNEL_SEND_ACTION_SUCCESS : 2795 OFFCHANNEL_SEND_ACTION_NO_ACK); 2796 break; 2797 } 2798 #endif /* CONFIG_OFFCHANNEL */ 2799 #ifdef CONFIG_AP 2800 switch (data->tx_status.type) { 2801 case WLAN_FC_TYPE_MGMT: 2802 ap_mgmt_tx_cb(wpa_s, data->tx_status.data, 2803 data->tx_status.data_len, 2804 data->tx_status.stype, 2805 data->tx_status.ack); 2806 break; 2807 case WLAN_FC_TYPE_DATA: 2808 ap_tx_status(wpa_s, data->tx_status.dst, 2809 data->tx_status.data, 2810 data->tx_status.data_len, 2811 data->tx_status.ack); 2812 break; 2813 } 2814 #endif /* CONFIG_AP */ 2815 break; 2816 #ifdef CONFIG_AP 2817 case EVENT_EAPOL_TX_STATUS: 2818 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst, 2819 data->eapol_tx_status.data, 2820 data->eapol_tx_status.data_len, 2821 data->eapol_tx_status.ack); 2822 break; 2823 case EVENT_DRIVER_CLIENT_POLL_OK: 2824 ap_client_poll_ok(wpa_s, data->client_poll.addr); 2825 break; 2826 case EVENT_RX_FROM_UNKNOWN: 2827 if (wpa_s->ap_iface == NULL) 2828 break; 2829 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr, 2830 data->rx_from_unknown.wds); 2831 break; 2832 case EVENT_CH_SWITCH: 2833 if (!data) 2834 break; 2835 if (!wpa_s->ap_iface) { 2836 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch " 2837 "event in non-AP mode"); 2838 break; 2839 } 2840 2841 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq, 2842 data->ch_switch.ht_enabled, 2843 data->ch_switch.ch_offset); 2844 break; 2845 #endif /* CONFIG_AP */ 2846 #if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN) 2847 case EVENT_RX_MGMT: { 2848 u16 fc, stype; 2849 const struct ieee80211_mgmt *mgmt; 2850 2851 mgmt = (const struct ieee80211_mgmt *) 2852 data->rx_mgmt.frame; 2853 fc = le_to_host16(mgmt->frame_control); 2854 stype = WLAN_FC_GET_STYPE(fc); 2855 2856 #ifdef CONFIG_AP 2857 if (wpa_s->ap_iface == NULL) { 2858 #endif /* CONFIG_AP */ 2859 #ifdef CONFIG_P2P 2860 if (stype == WLAN_FC_STYPE_PROBE_REQ && 2861 data->rx_mgmt.frame_len > 24) { 2862 const u8 *src = mgmt->sa; 2863 const u8 *ie = mgmt->u.probe_req.variable; 2864 size_t ie_len = data->rx_mgmt.frame_len - 2865 (mgmt->u.probe_req.variable - 2866 data->rx_mgmt.frame); 2867 wpas_p2p_probe_req_rx( 2868 wpa_s, src, mgmt->da, 2869 mgmt->bssid, ie, ie_len, 2870 data->rx_mgmt.ssi_signal); 2871 break; 2872 } 2873 #endif /* CONFIG_P2P */ 2874 #ifdef CONFIG_IBSS_RSN 2875 if (stype == WLAN_FC_STYPE_AUTH && 2876 data->rx_mgmt.frame_len >= 30) { 2877 wpa_supplicant_event_ibss_auth(wpa_s, data); 2878 break; 2879 } 2880 #endif /* CONFIG_IBSS_RSN */ 2881 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received " 2882 "management frame in non-AP mode"); 2883 break; 2884 #ifdef CONFIG_AP 2885 } 2886 2887 if (stype == WLAN_FC_STYPE_PROBE_REQ && 2888 data->rx_mgmt.frame_len > 24) { 2889 const u8 *ie = mgmt->u.probe_req.variable; 2890 size_t ie_len = data->rx_mgmt.frame_len - 2891 (mgmt->u.probe_req.variable - 2892 data->rx_mgmt.frame); 2893 2894 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da, 2895 mgmt->bssid, ie, ie_len, 2896 data->rx_mgmt.ssi_signal); 2897 } 2898 2899 ap_mgmt_rx(wpa_s, &data->rx_mgmt); 2900 #endif /* CONFIG_AP */ 2901 break; 2902 } 2903 #endif /* CONFIG_AP || CONFIG_IBSS_RSN */ 2904 case EVENT_RX_ACTION: 2905 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR 2906 " Category=%u DataLen=%d freq=%d MHz", 2907 MAC2STR(data->rx_action.sa), 2908 data->rx_action.category, (int) data->rx_action.len, 2909 data->rx_action.freq); 2910 #ifdef CONFIG_IEEE80211R 2911 if (data->rx_action.category == WLAN_ACTION_FT) { 2912 ft_rx_action(wpa_s, data->rx_action.data, 2913 data->rx_action.len); 2914 break; 2915 } 2916 #endif /* CONFIG_IEEE80211R */ 2917 #ifdef CONFIG_IEEE80211W 2918 #ifdef CONFIG_SME 2919 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) { 2920 sme_sa_query_rx(wpa_s, data->rx_action.sa, 2921 data->rx_action.data, 2922 data->rx_action.len); 2923 break; 2924 } 2925 #endif /* CONFIG_SME */ 2926 #endif /* CONFIG_IEEE80211W */ 2927 #ifdef CONFIG_WNM 2928 if (data->rx_action.category == WLAN_ACTION_WNM) { 2929 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action); 2930 break; 2931 } 2932 #endif /* CONFIG_WNM */ 2933 #ifdef CONFIG_GAS 2934 if (data->rx_action.category == WLAN_ACTION_PUBLIC && 2935 gas_query_rx(wpa_s->gas, data->rx_action.da, 2936 data->rx_action.sa, data->rx_action.bssid, 2937 data->rx_action.data, data->rx_action.len, 2938 data->rx_action.freq) == 0) 2939 break; 2940 #endif /* CONFIG_GAS */ 2941 #ifdef CONFIG_TDLS 2942 if (data->rx_action.category == WLAN_ACTION_PUBLIC && 2943 data->rx_action.len >= 4 && 2944 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) { 2945 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery " 2946 "Response from " MACSTR, 2947 MAC2STR(data->rx_action.sa)); 2948 break; 2949 } 2950 #endif /* CONFIG_TDLS */ 2951 #ifdef CONFIG_P2P 2952 wpas_p2p_rx_action(wpa_s, data->rx_action.da, 2953 data->rx_action.sa, 2954 data->rx_action.bssid, 2955 data->rx_action.category, 2956 data->rx_action.data, 2957 data->rx_action.len, data->rx_action.freq); 2958 #endif /* CONFIG_P2P */ 2959 break; 2960 case EVENT_RX_PROBE_REQ: 2961 if (data->rx_probe_req.sa == NULL || 2962 data->rx_probe_req.ie == NULL) 2963 break; 2964 #ifdef CONFIG_AP 2965 if (wpa_s->ap_iface) { 2966 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0], 2967 data->rx_probe_req.sa, 2968 data->rx_probe_req.da, 2969 data->rx_probe_req.bssid, 2970 data->rx_probe_req.ie, 2971 data->rx_probe_req.ie_len, 2972 data->rx_probe_req.ssi_signal); 2973 break; 2974 } 2975 #endif /* CONFIG_AP */ 2976 #ifdef CONFIG_P2P 2977 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa, 2978 data->rx_probe_req.da, 2979 data->rx_probe_req.bssid, 2980 data->rx_probe_req.ie, 2981 data->rx_probe_req.ie_len, 2982 data->rx_probe_req.ssi_signal); 2983 #endif /* CONFIG_P2P */ 2984 break; 2985 case EVENT_REMAIN_ON_CHANNEL: 2986 #ifdef CONFIG_OFFCHANNEL 2987 offchannel_remain_on_channel_cb( 2988 wpa_s, data->remain_on_channel.freq, 2989 data->remain_on_channel.duration); 2990 #endif /* CONFIG_OFFCHANNEL */ 2991 #ifdef CONFIG_P2P 2992 wpas_p2p_remain_on_channel_cb( 2993 wpa_s, data->remain_on_channel.freq, 2994 data->remain_on_channel.duration); 2995 #endif /* CONFIG_P2P */ 2996 break; 2997 case EVENT_CANCEL_REMAIN_ON_CHANNEL: 2998 #ifdef CONFIG_OFFCHANNEL 2999 offchannel_cancel_remain_on_channel_cb( 3000 wpa_s, data->remain_on_channel.freq); 3001 #endif /* CONFIG_OFFCHANNEL */ 3002 #ifdef CONFIG_P2P 3003 wpas_p2p_cancel_remain_on_channel_cb( 3004 wpa_s, data->remain_on_channel.freq); 3005 #endif /* CONFIG_P2P */ 3006 break; 3007 #ifdef CONFIG_P2P 3008 case EVENT_P2P_DEV_FOUND: { 3009 struct p2p_peer_info peer_info; 3010 3011 os_memset(&peer_info, 0, sizeof(peer_info)); 3012 if (data->p2p_dev_found.dev_addr) 3013 os_memcpy(peer_info.p2p_device_addr, 3014 data->p2p_dev_found.dev_addr, ETH_ALEN); 3015 if (data->p2p_dev_found.pri_dev_type) 3016 os_memcpy(peer_info.pri_dev_type, 3017 data->p2p_dev_found.pri_dev_type, 3018 sizeof(peer_info.pri_dev_type)); 3019 if (data->p2p_dev_found.dev_name) 3020 os_strlcpy(peer_info.device_name, 3021 data->p2p_dev_found.dev_name, 3022 sizeof(peer_info.device_name)); 3023 peer_info.config_methods = data->p2p_dev_found.config_methods; 3024 peer_info.dev_capab = data->p2p_dev_found.dev_capab; 3025 peer_info.group_capab = data->p2p_dev_found.group_capab; 3026 3027 /* 3028 * FIX: new_device=1 is not necessarily correct. We should 3029 * maintain a P2P peer database in wpa_supplicant and update 3030 * this information based on whether the peer is truly new. 3031 */ 3032 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1); 3033 break; 3034 } 3035 case EVENT_P2P_GO_NEG_REQ_RX: 3036 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src, 3037 data->p2p_go_neg_req_rx.dev_passwd_id); 3038 break; 3039 case EVENT_P2P_GO_NEG_COMPLETED: 3040 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res); 3041 break; 3042 case EVENT_P2P_PROV_DISC_REQUEST: 3043 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer, 3044 data->p2p_prov_disc_req.config_methods, 3045 data->p2p_prov_disc_req.dev_addr, 3046 data->p2p_prov_disc_req.pri_dev_type, 3047 data->p2p_prov_disc_req.dev_name, 3048 data->p2p_prov_disc_req.supp_config_methods, 3049 data->p2p_prov_disc_req.dev_capab, 3050 data->p2p_prov_disc_req.group_capab, 3051 NULL, 0); 3052 break; 3053 case EVENT_P2P_PROV_DISC_RESPONSE: 3054 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer, 3055 data->p2p_prov_disc_resp.config_methods); 3056 break; 3057 case EVENT_P2P_SD_REQUEST: 3058 wpas_sd_request(wpa_s, data->p2p_sd_req.freq, 3059 data->p2p_sd_req.sa, 3060 data->p2p_sd_req.dialog_token, 3061 data->p2p_sd_req.update_indic, 3062 data->p2p_sd_req.tlvs, 3063 data->p2p_sd_req.tlvs_len); 3064 break; 3065 case EVENT_P2P_SD_RESPONSE: 3066 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa, 3067 data->p2p_sd_resp.update_indic, 3068 data->p2p_sd_resp.tlvs, 3069 data->p2p_sd_resp.tlvs_len); 3070 break; 3071 #endif /* CONFIG_P2P */ 3072 case EVENT_EAPOL_RX: 3073 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src, 3074 data->eapol_rx.data, 3075 data->eapol_rx.data_len); 3076 break; 3077 case EVENT_SIGNAL_CHANGE: 3078 bgscan_notify_signal_change( 3079 wpa_s, data->signal_change.above_threshold, 3080 data->signal_change.current_signal, 3081 data->signal_change.current_noise, 3082 data->signal_change.current_txrate); 3083 break; 3084 case EVENT_INTERFACE_ENABLED: 3085 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled"); 3086 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { 3087 wpa_supplicant_update_mac_addr(wpa_s); 3088 #ifdef CONFIG_AP 3089 if (!wpa_s->ap_iface) { 3090 wpa_supplicant_set_state(wpa_s, 3091 WPA_DISCONNECTED); 3092 wpa_supplicant_req_scan(wpa_s, 0, 0); 3093 } else 3094 wpa_supplicant_set_state(wpa_s, 3095 WPA_COMPLETED); 3096 #else /* CONFIG_AP */ 3097 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); 3098 wpa_supplicant_req_scan(wpa_s, 0, 0); 3099 #endif /* CONFIG_AP */ 3100 } 3101 break; 3102 case EVENT_INTERFACE_DISABLED: 3103 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled"); 3104 wpa_supplicant_mark_disassoc(wpa_s); 3105 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); 3106 break; 3107 case EVENT_CHANNEL_LIST_CHANGED: 3108 if (wpa_s->drv_priv == NULL) 3109 break; /* Ignore event during drv initialization */ 3110 3111 free_hw_features(wpa_s); 3112 wpa_s->hw.modes = wpa_drv_get_hw_feature_data( 3113 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags); 3114 3115 #ifdef CONFIG_P2P 3116 wpas_p2p_update_channel_list(wpa_s); 3117 #endif /* CONFIG_P2P */ 3118 break; 3119 case EVENT_INTERFACE_UNAVAILABLE: 3120 #ifdef CONFIG_P2P 3121 wpas_p2p_interface_unavailable(wpa_s); 3122 #endif /* CONFIG_P2P */ 3123 break; 3124 case EVENT_BEST_CHANNEL: 3125 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received " 3126 "(%d %d %d)", 3127 data->best_chan.freq_24, data->best_chan.freq_5, 3128 data->best_chan.freq_overall); 3129 wpa_s->best_24_freq = data->best_chan.freq_24; 3130 wpa_s->best_5_freq = data->best_chan.freq_5; 3131 wpa_s->best_overall_freq = data->best_chan.freq_overall; 3132 #ifdef CONFIG_P2P 3133 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24, 3134 data->best_chan.freq_5, 3135 data->best_chan.freq_overall); 3136 #endif /* CONFIG_P2P */ 3137 break; 3138 case EVENT_UNPROT_DEAUTH: 3139 wpa_supplicant_event_unprot_deauth(wpa_s, 3140 &data->unprot_deauth); 3141 break; 3142 case EVENT_UNPROT_DISASSOC: 3143 wpa_supplicant_event_unprot_disassoc(wpa_s, 3144 &data->unprot_disassoc); 3145 break; 3146 case EVENT_STATION_LOW_ACK: 3147 #ifdef CONFIG_AP 3148 if (wpa_s->ap_iface && data) 3149 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0], 3150 data->low_ack.addr); 3151 #endif /* CONFIG_AP */ 3152 #ifdef CONFIG_TDLS 3153 if (data) 3154 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr); 3155 #endif /* CONFIG_TDLS */ 3156 break; 3157 case EVENT_IBSS_PEER_LOST: 3158 #ifdef CONFIG_IBSS_RSN 3159 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer); 3160 #endif /* CONFIG_IBSS_RSN */ 3161 break; 3162 case EVENT_DRIVER_GTK_REKEY: 3163 if (os_memcmp(data->driver_gtk_rekey.bssid, 3164 wpa_s->bssid, ETH_ALEN)) 3165 break; 3166 if (!wpa_s->wpa) 3167 break; 3168 wpa_sm_update_replay_ctr(wpa_s->wpa, 3169 data->driver_gtk_rekey.replay_ctr); 3170 break; 3171 case EVENT_SCHED_SCAN_STOPPED: 3172 wpa_s->sched_scanning = 0; 3173 wpa_supplicant_notify_scanning(wpa_s, 0); 3174 3175 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) 3176 break; 3177 3178 /* 3179 * If we timed out, start a new sched scan to continue 3180 * searching for more SSIDs. 3181 */ 3182 if (wpa_s->sched_scan_timed_out) 3183 wpa_supplicant_req_sched_scan(wpa_s); 3184 break; 3185 case EVENT_WPS_BUTTON_PUSHED: 3186 #ifdef CONFIG_WPS 3187 wpas_wps_start_pbc(wpa_s, NULL, 0); 3188 #endif /* CONFIG_WPS */ 3189 break; 3190 case EVENT_CONNECT_FAILED_REASON: 3191 #ifdef CONFIG_AP 3192 if (!wpa_s->ap_iface || !data) 3193 break; 3194 hostapd_event_connect_failed_reason( 3195 wpa_s->ap_iface->bss[0], 3196 data->connect_failed_reason.addr, 3197 data->connect_failed_reason.code); 3198 #endif /* CONFIG_AP */ 3199 break; 3200 default: 3201 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event); 3202 break; 3203 } 3204 } 3205