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