events.c revision 9bce59c7fef20e34a05f04d1e33a4076083dca0c
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->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled && 1061 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending) { 1062 wpa_s->p2p_cb_on_scan_complete = 0; 1063 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) { 1064 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation " 1065 "stopped scan processing"); 1066 return -1; 1067 } 1068 } 1069 wpa_s->sta_scan_pending = 0; 1070#endif /* CONFIG_P2P */ 1071 1072 scan_res = wpa_supplicant_get_scan_results(wpa_s, 1073 data ? &data->scan_info : 1074 NULL, 1); 1075 if (scan_res == NULL) { 1076 if (wpa_s->conf->ap_scan == 2 || ap) 1077 return -1; 1078 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try " 1079 "scanning again"); 1080 wpa_supplicant_req_new_scan(wpa_s, 1, 0); 1081 return -1; 1082 } 1083 1084#ifndef CONFIG_NO_RANDOM_POOL 1085 num = scan_res->num; 1086 if (num > 10) 1087 num = 10; 1088 for (i = 0; i < num; i++) { 1089 u8 buf[5]; 1090 struct wpa_scan_res *res = scan_res->res[i]; 1091 buf[0] = res->bssid[5]; 1092 buf[1] = res->qual & 0xff; 1093 buf[2] = res->noise & 0xff; 1094 buf[3] = res->level & 0xff; 1095 buf[4] = res->tsf & 0xff; 1096 random_add_randomness(buf, sizeof(buf)); 1097 } 1098#endif /* CONFIG_NO_RANDOM_POOL */ 1099 1100 if (wpa_s->scan_res_handler) { 1101 void (*scan_res_handler)(struct wpa_supplicant *wpa_s, 1102 struct wpa_scan_results *scan_res); 1103 1104 scan_res_handler = wpa_s->scan_res_handler; 1105 wpa_s->scan_res_handler = NULL; 1106 scan_res_handler(wpa_s, scan_res); 1107 1108 wpa_scan_results_free(scan_res); 1109 return -2; 1110 } 1111 1112 if (ap) { 1113 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode"); 1114#ifdef CONFIG_AP 1115 if (wpa_s->ap_iface->scan_cb) 1116 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface); 1117#endif /* CONFIG_AP */ 1118 wpa_scan_results_free(scan_res); 1119 return 0; 1120 } 1121#ifdef ANDROID_P2P 1122 if(!suppress_event) 1123 { 1124 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available"); 1125 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); 1126 wpas_notify_scan_results(wpa_s); 1127 } 1128#else 1129 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available"); 1130 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); 1131 wpas_notify_scan_results(wpa_s); 1132#endif 1133 1134 wpas_notify_scan_done(wpa_s, 1); 1135 1136 if (sme_proc_obss_scan(wpa_s) > 0) { 1137 wpa_scan_results_free(scan_res); 1138 return 0; 1139 } 1140 1141 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) { 1142 wpa_scan_results_free(scan_res); 1143 return 0; 1144 } 1145 1146 if (autoscan_notify_scan(wpa_s, scan_res)) { 1147 wpa_scan_results_free(scan_res); 1148 return 0; 1149 } 1150 1151 if (wpa_s->disconnected) { 1152 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); 1153 wpa_scan_results_free(scan_res); 1154 return 0; 1155 } 1156 1157 if (!wpas_driver_bss_selection(wpa_s) && 1158 bgscan_notify_scan(wpa_s, scan_res) == 1) { 1159 wpa_scan_results_free(scan_res); 1160 return 0; 1161 } 1162 1163 wpas_wps_update_ap_info(wpa_s, scan_res); 1164 1165 wpa_scan_results_free(scan_res); 1166 1167 return wpas_select_network_from_last_scan(wpa_s); 1168} 1169 1170 1171int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s) 1172{ 1173 struct wpa_bss *selected; 1174 struct wpa_ssid *ssid = NULL; 1175 1176 selected = wpa_supplicant_pick_network(wpa_s, &ssid); 1177 1178 if (selected) { 1179 int skip; 1180 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid); 1181 if (skip) { 1182 wpa_supplicant_rsn_preauth_scan_results(wpa_s); 1183 return 0; 1184 } 1185 1186 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) { 1187 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed"); 1188 return -1; 1189 } 1190 wpa_supplicant_rsn_preauth_scan_results(wpa_s); 1191 } else { 1192 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found"); 1193 ssid = wpa_supplicant_pick_new_network(wpa_s); 1194 if (ssid) { 1195 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network"); 1196 wpa_supplicant_associate(wpa_s, NULL, ssid); 1197 wpa_supplicant_rsn_preauth_scan_results(wpa_s); 1198 } else { 1199 int timeout_sec = wpa_s->scan_interval; 1200 int timeout_usec = 0; 1201#ifdef CONFIG_P2P 1202 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1) 1203 return 0; 1204 1205 if (wpa_s->p2p_in_provisioning) { 1206 /* 1207 * Use shorter wait during P2P Provisioning 1208 * state to speed up group formation. 1209 */ 1210 timeout_sec = 0; 1211 timeout_usec = 250000; 1212 wpa_supplicant_req_new_scan(wpa_s, timeout_sec, 1213 timeout_usec); 1214 return 0; 1215 } 1216#endif /* CONFIG_P2P */ 1217#ifdef CONFIG_INTERWORKING 1218 if (wpa_s->conf->auto_interworking && 1219 wpa_s->conf->interworking && 1220 wpa_s->conf->cred) { 1221 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: " 1222 "start ANQP fetch since no matching " 1223 "networks found"); 1224 wpa_s->network_select = 1; 1225 wpa_s->auto_network_select = 1; 1226 interworking_start_fetch_anqp(wpa_s); 1227 return 0; 1228 } 1229#endif /* CONFIG_INTERWORKING */ 1230 if (wpa_supplicant_req_sched_scan(wpa_s)) 1231 wpa_supplicant_req_new_scan(wpa_s, timeout_sec, 1232 timeout_usec); 1233 } 1234 } 1235 return 0; 1236} 1237 1238 1239static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, 1240 union wpa_event_data *data) 1241{ 1242 const char *rn, *rn2; 1243 struct wpa_supplicant *ifs; 1244#ifdef ANDROID_P2P 1245 if (_wpa_supplicant_event_scan_results(wpa_s, data, 0) < 0) { 1246#else 1247 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) { 1248#endif 1249 /* 1250 * If no scan results could be fetched, then no need to 1251 * notify those interfaces that did not actually request 1252 * this scan. 1253 */ 1254 return; 1255 } 1256 1257 /* 1258 * Check other interfaces to see if they have the same radio-name. If 1259 * so, they get updated with this same scan info. 1260 */ 1261 if (!wpa_s->driver->get_radio_name) 1262 return; 1263 1264 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv); 1265 if (rn == NULL || rn[0] == '\0') 1266 return; 1267 1268 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces " 1269 "sharing same radio (%s) in event_scan_results", rn); 1270 1271 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { 1272 if (ifs == wpa_s || !ifs->driver->get_radio_name) 1273 continue; 1274 1275 rn2 = ifs->driver->get_radio_name(ifs->drv_priv); 1276 if (rn2 && os_strcmp(rn, rn2) == 0) { 1277 wpa_printf(MSG_DEBUG, "%s: Updating scan results from " 1278 "sibling", ifs->ifname); 1279#ifdef ANDROID_P2P 1280 if ( (ifs->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) || (ifs->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)) { 1281 /* Do not update the scan results from STA interface to p2p interfaces */ 1282 wpa_printf(MSG_DEBUG, "Not Updating scan results on interface %s from " 1283 "sibling %s", ifs->ifname, wpa_s->ifname); 1284 continue; 1285 } 1286 else { 1287 /* P2P_FIND will result in too many SCAN_RESULT_EVENTS within 1288 * no time. Avoid announcing it to application as it may not 1289 * be that useful (since results will be that of only 1,6,11). 1290 * over to any other interface as it 1291 */ 1292 if(p2p_search_in_progress(wpa_s->global->p2p)) 1293 _wpa_supplicant_event_scan_results(ifs, data, 1); 1294 else 1295 _wpa_supplicant_event_scan_results(ifs, data, 0); 1296 } 1297#else 1298 _wpa_supplicant_event_scan_results(ifs, data); 1299#endif 1300 } 1301 } 1302} 1303 1304#endif /* CONFIG_NO_SCAN_PROCESSING */ 1305 1306 1307#ifdef CONFIG_WNM 1308 1309static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx) 1310{ 1311 struct wpa_supplicant *wpa_s = eloop_ctx; 1312 1313 if (wpa_s->wpa_state < WPA_ASSOCIATED) 1314 return; 1315 1316 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR, 1317 MAC2STR(wpa_s->bssid)); 1318 /* TODO: could skip this if normal data traffic has been sent */ 1319 /* TODO: Consider using some more appropriate data frame for this */ 1320 if (wpa_s->l2) 1321 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0); 1322 1323#ifdef CONFIG_SME 1324 if (wpa_s->sme.bss_max_idle_period) { 1325 unsigned int msec; 1326 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */ 1327 if (msec > 100) 1328 msec -= 100; 1329 eloop_register_timeout(msec / 1000, msec % 1000 * 1000, 1330 wnm_bss_keep_alive, wpa_s, NULL); 1331 } 1332#endif /* CONFIG_SME */ 1333} 1334 1335 1336static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s, 1337 const u8 *ies, size_t ies_len) 1338{ 1339 struct ieee802_11_elems elems; 1340 1341 if (ies == NULL) 1342 return; 1343 1344 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) 1345 return; 1346 1347#ifdef CONFIG_SME 1348 if (elems.bss_max_idle_period) { 1349 unsigned int msec; 1350 wpa_s->sme.bss_max_idle_period = 1351 WPA_GET_LE16(elems.bss_max_idle_period); 1352 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 " 1353 "TU)%s", wpa_s->sme.bss_max_idle_period, 1354 (elems.bss_max_idle_period[2] & 0x01) ? 1355 " (protected keep-live required)" : ""); 1356 if (wpa_s->sme.bss_max_idle_period == 0) 1357 wpa_s->sme.bss_max_idle_period = 1; 1358 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) { 1359 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); 1360 /* msec times 1000 */ 1361 msec = wpa_s->sme.bss_max_idle_period * 1024; 1362 if (msec > 100) 1363 msec -= 100; 1364 eloop_register_timeout(msec / 1000, msec % 1000 * 1000, 1365 wnm_bss_keep_alive, wpa_s, 1366 NULL); 1367 } 1368 } 1369#endif /* CONFIG_SME */ 1370} 1371 1372#endif /* CONFIG_WNM */ 1373 1374 1375void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s) 1376{ 1377#ifdef CONFIG_WNM 1378 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); 1379#endif /* CONFIG_WNM */ 1380} 1381 1382 1383static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, 1384 union wpa_event_data *data) 1385{ 1386 int l, len, found = 0, wpa_found, rsn_found; 1387 const u8 *p; 1388 1389 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event"); 1390 if (data->assoc_info.req_ies) 1391 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, 1392 data->assoc_info.req_ies_len); 1393 if (data->assoc_info.resp_ies) { 1394 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, 1395 data->assoc_info.resp_ies_len); 1396#ifdef CONFIG_TDLS 1397 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies, 1398 data->assoc_info.resp_ies_len); 1399#endif /* CONFIG_TDLS */ 1400#ifdef CONFIG_WNM 1401 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, 1402 data->assoc_info.resp_ies_len); 1403#endif /* CONFIG_WNM */ 1404 } 1405 if (data->assoc_info.beacon_ies) 1406 wpa_hexdump(MSG_DEBUG, "beacon_ies", 1407 data->assoc_info.beacon_ies, 1408 data->assoc_info.beacon_ies_len); 1409 if (data->assoc_info.freq) 1410 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz", 1411 data->assoc_info.freq); 1412 1413 p = data->assoc_info.req_ies; 1414 l = data->assoc_info.req_ies_len; 1415 1416 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ 1417 while (p && l >= 2) { 1418 len = p[1] + 2; 1419 if (len > l) { 1420 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", 1421 p, l); 1422 break; 1423 } 1424 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && 1425 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || 1426 (p[0] == WLAN_EID_RSN && p[1] >= 2)) { 1427 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) 1428 break; 1429 found = 1; 1430 wpa_find_assoc_pmkid(wpa_s); 1431 break; 1432 } 1433 l -= len; 1434 p += len; 1435 } 1436 if (!found && data->assoc_info.req_ies) 1437 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); 1438 1439#ifdef CONFIG_IEEE80211R 1440#ifdef CONFIG_SME 1441 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) { 1442 u8 bssid[ETH_ALEN]; 1443 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || 1444 wpa_ft_validate_reassoc_resp(wpa_s->wpa, 1445 data->assoc_info.resp_ies, 1446 data->assoc_info.resp_ies_len, 1447 bssid) < 0) { 1448 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " 1449 "Reassociation Response failed"); 1450 wpa_supplicant_deauthenticate( 1451 wpa_s, WLAN_REASON_INVALID_IE); 1452 return -1; 1453 } 1454 } 1455 1456 p = data->assoc_info.resp_ies; 1457 l = data->assoc_info.resp_ies_len; 1458 1459#ifdef CONFIG_WPS_STRICT 1460 if (p && wpa_s->current_ssid && 1461 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) { 1462 struct wpabuf *wps; 1463 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE); 1464 if (wps == NULL) { 1465 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not " 1466 "include WPS IE in (Re)Association Response"); 1467 return -1; 1468 } 1469 1470 if (wps_validate_assoc_resp(wps) < 0) { 1471 wpabuf_free(wps); 1472 wpa_supplicant_deauthenticate( 1473 wpa_s, WLAN_REASON_INVALID_IE); 1474 return -1; 1475 } 1476 wpabuf_free(wps); 1477 } 1478#endif /* CONFIG_WPS_STRICT */ 1479 1480 /* Go through the IEs and make a copy of the MDIE, if present. */ 1481 while (p && l >= 2) { 1482 len = p[1] + 2; 1483 if (len > l) { 1484 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", 1485 p, l); 1486 break; 1487 } 1488 if (p[0] == WLAN_EID_MOBILITY_DOMAIN && 1489 p[1] >= MOBILITY_DOMAIN_ID_LEN) { 1490 wpa_s->sme.ft_used = 1; 1491 os_memcpy(wpa_s->sme.mobility_domain, p + 2, 1492 MOBILITY_DOMAIN_ID_LEN); 1493 break; 1494 } 1495 l -= len; 1496 p += len; 1497 } 1498#endif /* CONFIG_SME */ 1499 1500 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies, 1501 data->assoc_info.resp_ies_len); 1502#endif /* CONFIG_IEEE80211R */ 1503 1504 /* WPA/RSN IE from Beacon/ProbeResp */ 1505 p = data->assoc_info.beacon_ies; 1506 l = data->assoc_info.beacon_ies_len; 1507 1508 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. 1509 */ 1510 wpa_found = rsn_found = 0; 1511 while (p && l >= 2) { 1512 len = p[1] + 2; 1513 if (len > l) { 1514 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", 1515 p, l); 1516 break; 1517 } 1518 if (!wpa_found && 1519 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && 1520 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { 1521 wpa_found = 1; 1522 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); 1523 } 1524 1525 if (!rsn_found && 1526 p[0] == WLAN_EID_RSN && p[1] >= 2) { 1527 rsn_found = 1; 1528 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); 1529 } 1530 1531 l -= len; 1532 p += len; 1533 } 1534 1535 if (!wpa_found && data->assoc_info.beacon_ies) 1536 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); 1537 if (!rsn_found && data->assoc_info.beacon_ies) 1538 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); 1539 if (wpa_found || rsn_found) 1540 wpa_s->ap_ies_from_associnfo = 1; 1541 1542 if (wpa_s->assoc_freq && data->assoc_info.freq && 1543 wpa_s->assoc_freq != data->assoc_info.freq) { 1544 wpa_printf(MSG_DEBUG, "Operating frequency changed from " 1545 "%u to %u MHz", 1546 wpa_s->assoc_freq, data->assoc_info.freq); 1547 wpa_supplicant_update_scan_results(wpa_s); 1548 } 1549 1550 wpa_s->assoc_freq = data->assoc_info.freq; 1551 1552 return 0; 1553} 1554 1555 1556static struct wpa_bss * wpa_supplicant_get_new_bss( 1557 struct wpa_supplicant *wpa_s, const u8 *bssid) 1558{ 1559 struct wpa_bss *bss = NULL; 1560 struct wpa_ssid *ssid = wpa_s->current_ssid; 1561 1562 if (ssid->ssid_len > 0) 1563 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); 1564 if (!bss) 1565 bss = wpa_bss_get_bssid(wpa_s, bssid); 1566 1567 return bss; 1568} 1569 1570 1571static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s) 1572{ 1573 const u8 *bss_wpa = NULL, *bss_rsn = NULL; 1574 1575 if (!wpa_s->current_bss || !wpa_s->current_ssid) 1576 return -1; 1577 1578 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt)) 1579 return 0; 1580 1581 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss, 1582 WPA_IE_VENDOR_TYPE); 1583 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN); 1584 1585 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa, 1586 bss_wpa ? 2 + bss_wpa[1] : 0) || 1587 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn, 1588 bss_rsn ? 2 + bss_rsn[1] : 0)) 1589 return -1; 1590 1591 return 0; 1592} 1593 1594 1595static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, 1596 union wpa_event_data *data) 1597{ 1598 u8 bssid[ETH_ALEN]; 1599 int ft_completed; 1600 struct wpa_driver_capa capa; 1601 1602#ifdef CONFIG_AP 1603 if (wpa_s->ap_iface) { 1604 hostapd_notif_assoc(wpa_s->ap_iface->bss[0], 1605 data->assoc_info.addr, 1606 data->assoc_info.req_ies, 1607 data->assoc_info.req_ies_len, 1608 data->assoc_info.reassoc); 1609 return; 1610 } 1611#endif /* CONFIG_AP */ 1612 1613 ft_completed = wpa_ft_is_completed(wpa_s->wpa); 1614 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0) 1615 return; 1616 1617 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { 1618 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID"); 1619 wpa_supplicant_disassociate( 1620 wpa_s, WLAN_REASON_DEAUTH_LEAVING); 1621 return; 1622 } 1623 1624 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); 1625 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) { 1626 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" 1627 MACSTR, MAC2STR(bssid)); 1628 random_add_randomness(bssid, ETH_ALEN); 1629 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); 1630 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); 1631 wpas_notify_bssid_changed(wpa_s); 1632 1633 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { 1634 wpa_clear_keys(wpa_s, bssid); 1635 } 1636 if (wpa_supplicant_select_config(wpa_s) < 0) { 1637 wpa_supplicant_disassociate( 1638 wpa_s, WLAN_REASON_DEAUTH_LEAVING); 1639 return; 1640 } 1641 if (wpa_s->current_ssid) { 1642 struct wpa_bss *bss = NULL; 1643 1644 bss = wpa_supplicant_get_new_bss(wpa_s, bssid); 1645 if (!bss) { 1646 wpa_supplicant_update_scan_results(wpa_s); 1647 1648 /* Get the BSS from the new scan results */ 1649 bss = wpa_supplicant_get_new_bss(wpa_s, bssid); 1650 } 1651 1652 if (bss) 1653 wpa_s->current_bss = bss; 1654 } 1655 1656 if (wpa_s->conf->ap_scan == 1 && 1657 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) { 1658 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0) 1659 wpa_msg(wpa_s, MSG_WARNING, 1660 "WPA/RSN IEs not updated"); 1661 } 1662 } 1663 1664#ifdef CONFIG_SME 1665 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN); 1666 wpa_s->sme.prev_bssid_set = 1; 1667#endif /* CONFIG_SME */ 1668 1669 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); 1670 if (wpa_s->current_ssid) { 1671 /* When using scanning (ap_scan=1), SIM PC/SC interface can be 1672 * initialized before association, but for other modes, 1673 * initialize PC/SC here, if the current configuration needs 1674 * smartcard or SIM/USIM. */ 1675 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); 1676 } 1677 wpa_sm_notify_assoc(wpa_s->wpa, bssid); 1678 if (wpa_s->l2) 1679 l2_packet_notify_auth_start(wpa_s->l2); 1680 1681 /* 1682 * Set portEnabled first to FALSE in order to get EAP state machine out 1683 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE 1684 * state machine may transit to AUTHENTICATING state based on obsolete 1685 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to 1686 * AUTHENTICATED without ever giving chance to EAP state machine to 1687 * reset the state. 1688 */ 1689 if (!ft_completed) { 1690 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); 1691 eapol_sm_notify_portValid(wpa_s->eapol, FALSE); 1692 } 1693 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed) 1694 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); 1695 /* 802.1X::portControl = Auto */ 1696 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE); 1697 wpa_s->eapol_received = 0; 1698 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || 1699 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || 1700 (wpa_s->current_ssid && 1701 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) { 1702 wpa_supplicant_cancel_auth_timeout(wpa_s); 1703 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); 1704 } else if (!ft_completed) { 1705 /* Timeout for receiving the first EAPOL packet */ 1706 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); 1707 } 1708 wpa_supplicant_cancel_scan(wpa_s); 1709 1710 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && 1711 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { 1712 /* 1713 * We are done; the driver will take care of RSN 4-way 1714 * handshake. 1715 */ 1716 wpa_supplicant_cancel_auth_timeout(wpa_s); 1717 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); 1718 eapol_sm_notify_portValid(wpa_s->eapol, TRUE); 1719 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); 1720 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && 1721 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { 1722 /* 1723 * The driver will take care of RSN 4-way handshake, so we need 1724 * to allow EAPOL supplicant to complete its work without 1725 * waiting for WPA supplicant. 1726 */ 1727 eapol_sm_notify_portValid(wpa_s->eapol, TRUE); 1728 } else if (ft_completed) { 1729 /* 1730 * FT protocol completed - make sure EAPOL state machine ends 1731 * up in authenticated. 1732 */ 1733 wpa_supplicant_cancel_auth_timeout(wpa_s); 1734 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); 1735 eapol_sm_notify_portValid(wpa_s->eapol, TRUE); 1736 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); 1737 } 1738 1739 if (wpa_s->pending_eapol_rx) { 1740 struct os_time now, age; 1741 os_get_time(&now); 1742 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age); 1743 if (age.sec == 0 && age.usec < 100000 && 1744 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) == 1745 0) { 1746 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL " 1747 "frame that was received just before " 1748 "association notification"); 1749 wpa_supplicant_rx_eapol( 1750 wpa_s, wpa_s->pending_eapol_rx_src, 1751 wpabuf_head(wpa_s->pending_eapol_rx), 1752 wpabuf_len(wpa_s->pending_eapol_rx)); 1753 } 1754 wpabuf_free(wpa_s->pending_eapol_rx); 1755 wpa_s->pending_eapol_rx = NULL; 1756 } 1757 1758 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || 1759 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && 1760 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 && 1761 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) { 1762 /* Set static WEP keys again */ 1763 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); 1764 } 1765 1766#ifdef CONFIG_IBSS_RSN 1767 if (wpa_s->current_ssid && 1768 wpa_s->current_ssid->mode == WPAS_MODE_IBSS && 1769 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && 1770 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE && 1771 wpa_s->ibss_rsn == NULL) { 1772 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s); 1773 if (!wpa_s->ibss_rsn) { 1774 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN"); 1775 wpa_supplicant_deauthenticate( 1776 wpa_s, WLAN_REASON_DEAUTH_LEAVING); 1777 return; 1778 } 1779 1780 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk); 1781 } 1782#endif /* CONFIG_IBSS_RSN */ 1783 1784 wpas_wps_notify_assoc(wpa_s, bssid); 1785} 1786 1787 1788static int disconnect_reason_recoverable(u16 reason_code) 1789{ 1790 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY || 1791 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA || 1792 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA; 1793} 1794 1795 1796static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, 1797 u16 reason_code, 1798 int locally_generated) 1799{ 1800 const u8 *bssid; 1801 1802 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { 1803 /* 1804 * At least Host AP driver and a Prism3 card seemed to be 1805 * generating streams of disconnected events when configuring 1806 * IBSS for WPA-None. Ignore them for now. 1807 */ 1808 return; 1809 } 1810 1811 bssid = wpa_s->bssid; 1812 if (is_zero_ether_addr(bssid)) 1813 bssid = wpa_s->pending_bssid; 1814 1815 if (!is_zero_ether_addr(bssid) || 1816 wpa_s->wpa_state >= WPA_AUTHENTICATING) { 1817 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR 1818 " reason=%d%s", 1819 MAC2STR(bssid), reason_code, 1820 locally_generated ? " locally_generated=1" : ""); 1821 } 1822} 1823 1824 1825static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s, 1826 u16 reason_code, 1827 int locally_generated) 1828{ 1829 const u8 *bssid; 1830 int authenticating; 1831 u8 prev_pending_bssid[ETH_ALEN]; 1832 struct wpa_bss *fast_reconnect = NULL; 1833 struct wpa_ssid *fast_reconnect_ssid = NULL; 1834 struct wpa_ssid *last_ssid; 1835 1836 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING; 1837 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN); 1838 1839 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { 1840 /* 1841 * At least Host AP driver and a Prism3 card seemed to be 1842 * generating streams of disconnected events when configuring 1843 * IBSS for WPA-None. Ignore them for now. 1844 */ 1845 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in " 1846 "IBSS/WPA-None mode"); 1847 return; 1848 } 1849 1850 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE && 1851 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { 1852 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " 1853 "pre-shared key may be incorrect"); 1854 wpas_auth_failed(wpa_s); 1855 } 1856 if (!wpa_s->auto_reconnect_disabled || 1857 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { 1858 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to " 1859 "reconnect (wps=%d wpa_state=%d)", 1860 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS, 1861 wpa_s->wpa_state); 1862 if (wpa_s->wpa_state == WPA_COMPLETED && 1863 wpa_s->current_ssid && 1864 wpa_s->current_ssid->mode == WPAS_MODE_INFRA && 1865 !locally_generated && 1866 disconnect_reason_recoverable(reason_code)) { 1867 /* 1868 * It looks like the AP has dropped association with 1869 * us, but could allow us to get back in. Try to 1870 * reconnect to the same BSS without full scan to save 1871 * time for some common cases. 1872 */ 1873 fast_reconnect = wpa_s->current_bss; 1874 fast_reconnect_ssid = wpa_s->current_ssid; 1875 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) 1876#ifdef ANDROID 1877 wpa_supplicant_req_scan(wpa_s, 0, 500000); 1878#else 1879 wpa_supplicant_req_scan(wpa_s, 0, 100000); 1880#endif 1881 else 1882 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new " 1883 "immediate scan"); 1884 } else { 1885 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not " 1886 "try to re-connect"); 1887 wpa_s->reassociate = 0; 1888 wpa_s->disconnected = 1; 1889 wpa_supplicant_cancel_sched_scan(wpa_s); 1890 } 1891 bssid = wpa_s->bssid; 1892 if (is_zero_ether_addr(bssid)) 1893 bssid = wpa_s->pending_bssid; 1894 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) 1895 wpas_connection_failed(wpa_s, bssid); 1896 wpa_sm_notify_disassoc(wpa_s->wpa); 1897 if (locally_generated) 1898 wpa_s->disconnect_reason = -reason_code; 1899 else 1900 wpa_s->disconnect_reason = reason_code; 1901 wpas_notify_disconnect_reason(wpa_s); 1902 if (wpa_supplicant_dynamic_keys(wpa_s)) { 1903 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys"); 1904 wpa_s->keys_cleared = 0; 1905 wpa_clear_keys(wpa_s, wpa_s->bssid); 1906 } 1907 last_ssid = wpa_s->current_ssid; 1908 wpa_supplicant_mark_disassoc(wpa_s); 1909 1910 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) { 1911 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid); 1912 wpa_s->current_ssid = last_ssid; 1913 } 1914 1915 if (fast_reconnect) { 1916#ifndef CONFIG_NO_SCAN_PROCESSING 1917 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS"); 1918 if (wpa_supplicant_connect(wpa_s, fast_reconnect, 1919 fast_reconnect_ssid) < 0) { 1920 /* Recover through full scan */ 1921 wpa_supplicant_req_scan(wpa_s, 0, 100000); 1922 } 1923#endif /* CONFIG_NO_SCAN_PROCESSING */ 1924 } 1925} 1926 1927 1928#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT 1929void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx) 1930{ 1931 struct wpa_supplicant *wpa_s = eloop_ctx; 1932 1933 if (!wpa_s->pending_mic_error_report) 1934 return; 1935 1936 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report"); 1937 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); 1938 wpa_s->pending_mic_error_report = 0; 1939} 1940#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ 1941 1942 1943static void 1944wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, 1945 union wpa_event_data *data) 1946{ 1947 int pairwise; 1948 struct os_time t; 1949 1950 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); 1951 pairwise = (data && data->michael_mic_failure.unicast); 1952 os_get_time(&t); 1953 if ((wpa_s->last_michael_mic_error && 1954 t.sec - wpa_s->last_michael_mic_error <= 60) || 1955 wpa_s->pending_mic_error_report) { 1956 if (wpa_s->pending_mic_error_report) { 1957 /* 1958 * Send the pending MIC error report immediately since 1959 * we are going to start countermeasures and AP better 1960 * do the same. 1961 */ 1962 wpa_sm_key_request(wpa_s->wpa, 1, 1963 wpa_s->pending_mic_error_pairwise); 1964 } 1965 1966 /* Send the new MIC error report immediately since we are going 1967 * to start countermeasures and AP better do the same. 1968 */ 1969 wpa_sm_key_request(wpa_s->wpa, 1, pairwise); 1970 1971 /* initialize countermeasures */ 1972 wpa_s->countermeasures = 1; 1973 1974 wpa_blacklist_add(wpa_s, wpa_s->bssid); 1975 1976 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); 1977 1978 /* 1979 * Need to wait for completion of request frame. We do not get 1980 * any callback for the message completion, so just wait a 1981 * short while and hope for the best. */ 1982 os_sleep(0, 10000); 1983 1984 wpa_drv_set_countermeasures(wpa_s, 1); 1985 wpa_supplicant_deauthenticate(wpa_s, 1986 WLAN_REASON_MICHAEL_MIC_FAILURE); 1987 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, 1988 wpa_s, NULL); 1989 eloop_register_timeout(60, 0, 1990 wpa_supplicant_stop_countermeasures, 1991 wpa_s, NULL); 1992 /* TODO: mark the AP rejected for 60 second. STA is 1993 * allowed to associate with another AP.. */ 1994 } else { 1995#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT 1996 if (wpa_s->mic_errors_seen) { 1997 /* 1998 * Reduce the effectiveness of Michael MIC error 1999 * reports as a means for attacking against TKIP if 2000 * more than one MIC failure is noticed with the same 2001 * PTK. We delay the transmission of the reports by a 2002 * random time between 0 and 60 seconds in order to 2003 * force the attacker wait 60 seconds before getting 2004 * the information on whether a frame resulted in a MIC 2005 * failure. 2006 */ 2007 u8 rval[4]; 2008 int sec; 2009 2010 if (os_get_random(rval, sizeof(rval)) < 0) 2011 sec = os_random() % 60; 2012 else 2013 sec = WPA_GET_BE32(rval) % 60; 2014 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error " 2015 "report %d seconds", sec); 2016 wpa_s->pending_mic_error_report = 1; 2017 wpa_s->pending_mic_error_pairwise = pairwise; 2018 eloop_cancel_timeout( 2019 wpa_supplicant_delayed_mic_error_report, 2020 wpa_s, NULL); 2021 eloop_register_timeout( 2022 sec, os_random() % 1000000, 2023 wpa_supplicant_delayed_mic_error_report, 2024 wpa_s, NULL); 2025 } else { 2026 wpa_sm_key_request(wpa_s->wpa, 1, pairwise); 2027 } 2028#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ 2029 wpa_sm_key_request(wpa_s->wpa, 1, pairwise); 2030#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ 2031 } 2032 wpa_s->last_michael_mic_error = t.sec; 2033 wpa_s->mic_errors_seen++; 2034} 2035 2036 2037#ifdef CONFIG_TERMINATE_ONLASTIF 2038static int any_interfaces(struct wpa_supplicant *head) 2039{ 2040 struct wpa_supplicant *wpa_s; 2041 2042 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) 2043 if (!wpa_s->interface_removed) 2044 return 1; 2045 return 0; 2046} 2047#endif /* CONFIG_TERMINATE_ONLASTIF */ 2048 2049 2050static void 2051wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, 2052 union wpa_event_data *data) 2053{ 2054 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) 2055 return; 2056 2057 switch (data->interface_status.ievent) { 2058 case EVENT_INTERFACE_ADDED: 2059 if (!wpa_s->interface_removed) 2060 break; 2061 wpa_s->interface_removed = 0; 2062 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added"); 2063 if (wpa_supplicant_driver_init(wpa_s) < 0) { 2064 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the " 2065 "driver after interface was added"); 2066 } 2067 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); 2068 break; 2069 case EVENT_INTERFACE_REMOVED: 2070 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed"); 2071 wpa_s->interface_removed = 1; 2072 wpa_supplicant_mark_disassoc(wpa_s); 2073 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); 2074 l2_packet_deinit(wpa_s->l2); 2075 wpa_s->l2 = NULL; 2076#ifdef CONFIG_IBSS_RSN 2077 ibss_rsn_deinit(wpa_s->ibss_rsn); 2078 wpa_s->ibss_rsn = NULL; 2079#endif /* CONFIG_IBSS_RSN */ 2080#ifdef CONFIG_TERMINATE_ONLASTIF 2081 /* check if last interface */ 2082 if (!any_interfaces(wpa_s->global->ifaces)) 2083 eloop_terminate(); 2084#endif /* CONFIG_TERMINATE_ONLASTIF */ 2085 break; 2086 } 2087} 2088 2089 2090#ifdef CONFIG_PEERKEY 2091static void 2092wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s, 2093 union wpa_event_data *data) 2094{ 2095 if (data == NULL) 2096 return; 2097 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer); 2098} 2099#endif /* CONFIG_PEERKEY */ 2100 2101 2102#ifdef CONFIG_TDLS 2103static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s, 2104 union wpa_event_data *data) 2105{ 2106 if (data == NULL) 2107 return; 2108 switch (data->tdls.oper) { 2109 case TDLS_REQUEST_SETUP: 2110 wpa_tdls_start(wpa_s->wpa, data->tdls.peer); 2111 break; 2112 case TDLS_REQUEST_TEARDOWN: 2113 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer, 2114 data->tdls.reason_code); 2115 break; 2116 } 2117} 2118#endif /* CONFIG_TDLS */ 2119 2120 2121#ifdef CONFIG_IEEE80211V 2122static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s, 2123 union wpa_event_data *data) 2124{ 2125 if (data == NULL) 2126 return; 2127 switch (data->wnm.oper) { 2128 case WNM_OPER_SLEEP: 2129 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request " 2130 "(action=%d, intval=%d)", 2131 data->wnm.sleep_action, data->wnm.sleep_intval); 2132 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action, 2133 data->wnm.sleep_intval); 2134 break; 2135 } 2136} 2137#endif /* CONFIG_IEEE80211V */ 2138 2139 2140#ifdef CONFIG_IEEE80211R 2141static void 2142wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s, 2143 union wpa_event_data *data) 2144{ 2145 if (data == NULL) 2146 return; 2147 2148 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies, 2149 data->ft_ies.ies_len, 2150 data->ft_ies.ft_action, 2151 data->ft_ies.target_ap, 2152 data->ft_ies.ric_ies, 2153 data->ft_ies.ric_ies_len) < 0) { 2154 /* TODO: prevent MLME/driver from trying to associate? */ 2155 } 2156} 2157#endif /* CONFIG_IEEE80211R */ 2158 2159 2160#ifdef CONFIG_IBSS_RSN 2161static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s, 2162 union wpa_event_data *data) 2163{ 2164 struct wpa_ssid *ssid; 2165 if (wpa_s->wpa_state < WPA_ASSOCIATED) 2166 return; 2167 if (data == NULL) 2168 return; 2169 ssid = wpa_s->current_ssid; 2170 if (ssid == NULL) 2171 return; 2172 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) 2173 return; 2174 2175 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); 2176} 2177#endif /* CONFIG_IBSS_RSN */ 2178 2179 2180#ifdef CONFIG_IEEE80211R 2181static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data, 2182 size_t len) 2183{ 2184 const u8 *sta_addr, *target_ap_addr; 2185 u16 status; 2186 2187 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len); 2188 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) 2189 return; /* only SME case supported for now */ 2190 if (len < 1 + 2 * ETH_ALEN + 2) 2191 return; 2192 if (data[0] != 2) 2193 return; /* Only FT Action Response is supported for now */ 2194 sta_addr = data + 1; 2195 target_ap_addr = data + 1 + ETH_ALEN; 2196 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN); 2197 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA " 2198 MACSTR " TargetAP " MACSTR " status %u", 2199 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status); 2200 2201 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) { 2202 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR 2203 " in FT Action Response", MAC2STR(sta_addr)); 2204 return; 2205 } 2206 2207 if (status) { 2208 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates " 2209 "failure (status code %d)", status); 2210 /* TODO: report error to FT code(?) */ 2211 return; 2212 } 2213 2214 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2, 2215 len - (1 + 2 * ETH_ALEN + 2), 1, 2216 target_ap_addr, NULL, 0) < 0) 2217 return; 2218 2219#ifdef CONFIG_SME 2220 { 2221 struct wpa_bss *bss; 2222 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr); 2223 if (bss) 2224 wpa_s->sme.freq = bss->freq; 2225 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT; 2226 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr, 2227 WLAN_AUTH_FT); 2228 } 2229#endif /* CONFIG_SME */ 2230} 2231#endif /* CONFIG_IEEE80211R */ 2232 2233 2234static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s, 2235 struct unprot_deauth *e) 2236{ 2237#ifdef CONFIG_IEEE80211W 2238 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame " 2239 "dropped: " MACSTR " -> " MACSTR 2240 " (reason code %u)", 2241 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); 2242 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); 2243#endif /* CONFIG_IEEE80211W */ 2244} 2245 2246 2247static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s, 2248 struct unprot_disassoc *e) 2249{ 2250#ifdef CONFIG_IEEE80211W 2251 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame " 2252 "dropped: " MACSTR " -> " MACSTR 2253 " (reason code %u)", 2254 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); 2255 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); 2256#endif /* CONFIG_IEEE80211W */ 2257} 2258 2259 2260static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx) 2261{ 2262 u8 action, mode; 2263 const u8 *pos, *end; 2264 2265 if (rx->data == NULL || rx->len == 0) 2266 return; 2267 2268 pos = rx->data; 2269 end = pos + rx->len; 2270 action = *pos++; 2271 2272 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR, 2273 action, MAC2STR(rx->sa)); 2274 switch (action) { 2275 case WNM_BSS_TRANS_MGMT_REQ: 2276 if (pos + 5 > end) 2277 break; 2278 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management " 2279 "Request: dialog_token=%u request_mode=0x%x " 2280 "disassoc_timer=%u validity_interval=%u", 2281 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]); 2282 mode = pos[1]; 2283 pos += 5; 2284 if (mode & 0x08) 2285 pos += 12; /* BSS Termination Duration */ 2286 if (mode & 0x10) { 2287 char url[256]; 2288 if (pos + 1 > end || pos + 1 + pos[0] > end) { 2289 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS " 2290 "Transition Management Request " 2291 "(URL)"); 2292 break; 2293 } 2294 os_memcpy(url, pos + 1, pos[0]); 2295 url[pos[0]] = '\0'; 2296 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation " 2297 "Imminent - session_info_url=%s", url); 2298 } 2299 break; 2300 } 2301} 2302 2303 2304void wpa_supplicant_event(void *ctx, enum wpa_event_type event, 2305 union wpa_event_data *data) 2306{ 2307 struct wpa_supplicant *wpa_s = ctx; 2308 u16 reason_code = 0; 2309 int locally_generated = 0; 2310 2311 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED && 2312 event != EVENT_INTERFACE_ENABLED && 2313 event != EVENT_INTERFACE_STATUS && 2314 event != EVENT_SCHED_SCAN_STOPPED) { 2315 wpa_dbg(wpa_s, MSG_DEBUG, 2316 "Ignore event %s (%d) while interface is disabled", 2317 event_to_string(event), event); 2318 return; 2319 } 2320 2321#ifndef CONFIG_NO_STDOUT_DEBUG 2322{ 2323 int level = MSG_DEBUG; 2324 2325 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) { 2326 const struct ieee80211_hdr *hdr; 2327 u16 fc; 2328 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; 2329 fc = le_to_host16(hdr->frame_control); 2330 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && 2331 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) 2332 level = MSG_EXCESSIVE; 2333 } 2334 2335 wpa_dbg(wpa_s, level, "Event %s (%d) received", 2336 event_to_string(event), event); 2337} 2338#endif /* CONFIG_NO_STDOUT_DEBUG */ 2339 2340 switch (event) { 2341 case EVENT_AUTH: 2342 sme_event_auth(wpa_s, data); 2343 break; 2344 case EVENT_ASSOC: 2345 wpa_supplicant_event_assoc(wpa_s, data); 2346 break; 2347 case EVENT_DISASSOC: 2348 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification"); 2349 if (data) { 2350 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", 2351 data->disassoc_info.reason_code, 2352 data->disassoc_info.locally_generated ? 2353 " (locally generated)" : ""); 2354 if (data->disassoc_info.addr) 2355 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, 2356 MAC2STR(data->disassoc_info.addr)); 2357 } 2358#ifdef CONFIG_AP 2359 if (wpa_s->ap_iface && data && data->disassoc_info.addr) { 2360 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], 2361 data->disassoc_info.addr); 2362 break; 2363 } 2364 if (wpa_s->ap_iface) { 2365 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in " 2366 "AP mode"); 2367 break; 2368 } 2369#endif /* CONFIG_AP */ 2370 if (data) { 2371 reason_code = data->disassoc_info.reason_code; 2372 locally_generated = 2373 data->disassoc_info.locally_generated; 2374 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)", 2375 data->disassoc_info.ie, 2376 data->disassoc_info.ie_len); 2377#ifdef CONFIG_P2P 2378 wpas_p2p_disassoc_notif( 2379 wpa_s, data->disassoc_info.addr, reason_code, 2380 data->disassoc_info.ie, 2381 data->disassoc_info.ie_len, 2382 locally_generated); 2383#endif /* CONFIG_P2P */ 2384 } 2385 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) 2386 sme_event_disassoc(wpa_s, data); 2387 /* fall through */ 2388 case EVENT_DEAUTH: 2389 if (event == EVENT_DEAUTH) { 2390 wpa_dbg(wpa_s, MSG_DEBUG, 2391 "Deauthentication notification"); 2392 if (data) { 2393 reason_code = data->deauth_info.reason_code; 2394 locally_generated = 2395 data->deauth_info.locally_generated; 2396 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", 2397 data->deauth_info.reason_code, 2398 data->deauth_info.locally_generated ? 2399 " (locally generated)" : ""); 2400 if (data->deauth_info.addr) { 2401 wpa_dbg(wpa_s, MSG_DEBUG, " * address " 2402 MACSTR, 2403 MAC2STR(data->deauth_info. 2404 addr)); 2405 } 2406 wpa_hexdump(MSG_DEBUG, 2407 "Deauthentication frame IE(s)", 2408 data->deauth_info.ie, 2409 data->deauth_info.ie_len); 2410 } 2411 } 2412#ifdef CONFIG_AP 2413 if (wpa_s->ap_iface && data && data->deauth_info.addr) { 2414 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], 2415 data->deauth_info.addr); 2416 break; 2417 } 2418 if (wpa_s->ap_iface) { 2419 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in " 2420 "AP mode"); 2421 break; 2422 } 2423#endif /* CONFIG_AP */ 2424 wpa_supplicant_event_disassoc(wpa_s, reason_code, 2425 locally_generated); 2426 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED || 2427 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || 2428 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) && 2429 eapol_sm_failed(wpa_s->eapol))) 2430 wpas_auth_failed(wpa_s); 2431#ifdef CONFIG_P2P 2432 if (event == EVENT_DEAUTH && data) { 2433 if (wpas_p2p_deauth_notif(wpa_s, 2434 data->deauth_info.addr, 2435 reason_code, 2436 data->deauth_info.ie, 2437 data->deauth_info.ie_len, 2438 locally_generated) > 0) { 2439 /* 2440 * The interface was removed, so cannot 2441 * continue processing any additional 2442 * operations after this. 2443 */ 2444 break; 2445 } 2446 } 2447#endif /* CONFIG_P2P */ 2448 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code, 2449 locally_generated); 2450 break; 2451 case EVENT_MICHAEL_MIC_FAILURE: 2452 wpa_supplicant_event_michael_mic_failure(wpa_s, data); 2453 break; 2454#ifndef CONFIG_NO_SCAN_PROCESSING 2455 case EVENT_SCAN_RESULTS: 2456 wpa_supplicant_event_scan_results(wpa_s, data); 2457#ifdef CONFIG_P2P 2458 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled && 2459 wpa_s->global->p2p != NULL && 2460 wpa_s->wpa_state != WPA_AUTHENTICATING && 2461 wpa_s->wpa_state != WPA_ASSOCIATING) { 2462 wpa_s->p2p_cb_on_scan_complete = 0; 2463 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) { 2464 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation " 2465 "continued after scan result processing"); 2466 } 2467 } 2468#endif /* CONFIG_P2P */ 2469 break; 2470#endif /* CONFIG_NO_SCAN_PROCESSING */ 2471 case EVENT_ASSOCINFO: 2472 wpa_supplicant_event_associnfo(wpa_s, data); 2473 break; 2474 case EVENT_INTERFACE_STATUS: 2475 wpa_supplicant_event_interface_status(wpa_s, data); 2476 break; 2477 case EVENT_PMKID_CANDIDATE: 2478 wpa_supplicant_event_pmkid_candidate(wpa_s, data); 2479 break; 2480#ifdef CONFIG_PEERKEY 2481 case EVENT_STKSTART: 2482 wpa_supplicant_event_stkstart(wpa_s, data); 2483 break; 2484#endif /* CONFIG_PEERKEY */ 2485#ifdef CONFIG_TDLS 2486 case EVENT_TDLS: 2487 wpa_supplicant_event_tdls(wpa_s, data); 2488 break; 2489#endif /* CONFIG_TDLS */ 2490#ifdef CONFIG_IEEE80211V 2491 case EVENT_WNM: 2492 wpa_supplicant_event_wnm(wpa_s, data); 2493 break; 2494#endif /* CONFIG_IEEE80211V */ 2495#ifdef CONFIG_IEEE80211R 2496 case EVENT_FT_RESPONSE: 2497 wpa_supplicant_event_ft_response(wpa_s, data); 2498 break; 2499#endif /* CONFIG_IEEE80211R */ 2500#ifdef CONFIG_IBSS_RSN 2501 case EVENT_IBSS_RSN_START: 2502 wpa_supplicant_event_ibss_rsn_start(wpa_s, data); 2503 break; 2504#endif /* CONFIG_IBSS_RSN */ 2505 case EVENT_ASSOC_REJECT: 2506 if (data->assoc_reject.bssid) 2507 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT 2508 "bssid=" MACSTR " status_code=%u", 2509 MAC2STR(data->assoc_reject.bssid), 2510 data->assoc_reject.status_code); 2511 else 2512 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT 2513 "status_code=%u", 2514 data->assoc_reject.status_code); 2515 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) 2516 sme_event_assoc_reject(wpa_s, data); 2517#ifdef ANDROID_P2P 2518#ifdef CONFIG_P2P 2519 else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) { 2520 if(!wpa_s->current_ssid) { 2521 wpa_printf(MSG_ERROR, "current_ssid == NULL"); 2522 break; 2523 } 2524 /* If assoc reject is reported by the driver, then avoid 2525 * waiting for the authentication timeout. Cancel the 2526 * authentication timeout and retry the assoc. 2527 */ 2528 if(wpa_s->current_ssid->assoc_retry++ < 5) { 2529 wpa_printf(MSG_ERROR, "Retrying assoc: %d ", 2530 wpa_s->current_ssid->assoc_retry); 2531 wpa_supplicant_cancel_auth_timeout(wpa_s); 2532 2533 /* Clear the states */ 2534 wpa_sm_notify_disassoc(wpa_s->wpa); 2535 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); 2536 2537 wpa_s->reassociate = 1; 2538 wpa_supplicant_req_scan(wpa_s, 1, 0); 2539 } else { 2540 /* If we ASSOC_REJECT's hits threshold, disable the 2541 * network 2542 */ 2543 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. " 2544 "Disabling the network"); 2545 wpa_s->current_ssid->assoc_retry = 0; 2546 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid); 2547 wpas_p2p_group_remove(wpa_s, wpa_s->ifname); 2548 } 2549 } 2550#endif 2551#endif /* ANDROID_P2P */ 2552 break; 2553 case EVENT_AUTH_TIMED_OUT: 2554 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) 2555 sme_event_auth_timed_out(wpa_s, data); 2556 break; 2557 case EVENT_ASSOC_TIMED_OUT: 2558 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) 2559 sme_event_assoc_timed_out(wpa_s, data); 2560 break; 2561 case EVENT_TX_STATUS: 2562 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR 2563 " type=%d stype=%d", 2564 MAC2STR(data->tx_status.dst), 2565 data->tx_status.type, data->tx_status.stype); 2566#ifdef CONFIG_AP 2567 if (wpa_s->ap_iface == NULL) { 2568#ifdef CONFIG_OFFCHANNEL 2569 if (data->tx_status.type == WLAN_FC_TYPE_MGMT && 2570 data->tx_status.stype == WLAN_FC_STYPE_ACTION) 2571 offchannel_send_action_tx_status( 2572 wpa_s, data->tx_status.dst, 2573 data->tx_status.data, 2574 data->tx_status.data_len, 2575 data->tx_status.ack ? 2576 OFFCHANNEL_SEND_ACTION_SUCCESS : 2577 OFFCHANNEL_SEND_ACTION_NO_ACK); 2578#endif /* CONFIG_OFFCHANNEL */ 2579 break; 2580 } 2581#endif /* CONFIG_AP */ 2582#ifdef CONFIG_OFFCHANNEL 2583 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst=" 2584 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst)); 2585 /* 2586 * Catch TX status events for Action frames we sent via group 2587 * interface in GO mode. 2588 */ 2589 if (data->tx_status.type == WLAN_FC_TYPE_MGMT && 2590 data->tx_status.stype == WLAN_FC_STYPE_ACTION && 2591 os_memcmp(wpa_s->parent->pending_action_dst, 2592 data->tx_status.dst, ETH_ALEN) == 0) { 2593 offchannel_send_action_tx_status( 2594 wpa_s->parent, data->tx_status.dst, 2595 data->tx_status.data, 2596 data->tx_status.data_len, 2597 data->tx_status.ack ? 2598 OFFCHANNEL_SEND_ACTION_SUCCESS : 2599 OFFCHANNEL_SEND_ACTION_NO_ACK); 2600 break; 2601 } 2602#endif /* CONFIG_OFFCHANNEL */ 2603#ifdef CONFIG_AP 2604 switch (data->tx_status.type) { 2605 case WLAN_FC_TYPE_MGMT: 2606 ap_mgmt_tx_cb(wpa_s, data->tx_status.data, 2607 data->tx_status.data_len, 2608 data->tx_status.stype, 2609 data->tx_status.ack); 2610 break; 2611 case WLAN_FC_TYPE_DATA: 2612 ap_tx_status(wpa_s, data->tx_status.dst, 2613 data->tx_status.data, 2614 data->tx_status.data_len, 2615 data->tx_status.ack); 2616 break; 2617 } 2618#endif /* CONFIG_AP */ 2619 break; 2620#ifdef CONFIG_AP 2621 case EVENT_EAPOL_TX_STATUS: 2622 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst, 2623 data->eapol_tx_status.data, 2624 data->eapol_tx_status.data_len, 2625 data->eapol_tx_status.ack); 2626 break; 2627 case EVENT_DRIVER_CLIENT_POLL_OK: 2628 ap_client_poll_ok(wpa_s, data->client_poll.addr); 2629 break; 2630 case EVENT_RX_FROM_UNKNOWN: 2631 if (wpa_s->ap_iface == NULL) 2632 break; 2633 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr, 2634 data->rx_from_unknown.wds); 2635 break; 2636 case EVENT_CH_SWITCH: 2637 if (!data) 2638 break; 2639 if (!wpa_s->ap_iface) { 2640 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch " 2641 "event in non-AP mode"); 2642 break; 2643 } 2644 2645#ifdef CONFIG_AP 2646 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq, 2647 data->ch_switch.ht_enabled, 2648 data->ch_switch.ch_offset); 2649#endif /* CONFIG_AP */ 2650 break; 2651 case EVENT_RX_MGMT: { 2652 u16 fc, stype; 2653 const struct ieee80211_mgmt *mgmt; 2654 2655 mgmt = (const struct ieee80211_mgmt *) 2656 data->rx_mgmt.frame; 2657 fc = le_to_host16(mgmt->frame_control); 2658 stype = WLAN_FC_GET_STYPE(fc); 2659 2660 if (wpa_s->ap_iface == NULL) { 2661#ifdef CONFIG_P2P 2662 if (stype == WLAN_FC_STYPE_PROBE_REQ && 2663 data->rx_mgmt.frame_len > 24) { 2664 const u8 *src = mgmt->sa; 2665 const u8 *ie = mgmt->u.probe_req.variable; 2666 size_t ie_len = data->rx_mgmt.frame_len - 2667 (mgmt->u.probe_req.variable - 2668 data->rx_mgmt.frame); 2669 wpas_p2p_probe_req_rx( 2670 wpa_s, src, mgmt->da, 2671 mgmt->bssid, ie, ie_len, 2672 data->rx_mgmt.ssi_signal); 2673 break; 2674 } 2675#endif /* CONFIG_P2P */ 2676 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received " 2677 "management frame in non-AP mode"); 2678 break; 2679 } 2680 2681 if (stype == WLAN_FC_STYPE_PROBE_REQ && 2682 data->rx_mgmt.frame_len > 24) { 2683 const u8 *ie = mgmt->u.probe_req.variable; 2684 size_t ie_len = data->rx_mgmt.frame_len - 2685 (mgmt->u.probe_req.variable - 2686 data->rx_mgmt.frame); 2687 2688 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da, 2689 mgmt->bssid, ie, ie_len, 2690 data->rx_mgmt.ssi_signal); 2691 } 2692 2693 ap_mgmt_rx(wpa_s, &data->rx_mgmt); 2694 break; 2695 } 2696#endif /* CONFIG_AP */ 2697 case EVENT_RX_ACTION: 2698 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR 2699 " Category=%u DataLen=%d freq=%d MHz", 2700 MAC2STR(data->rx_action.sa), 2701 data->rx_action.category, (int) data->rx_action.len, 2702 data->rx_action.freq); 2703#ifdef CONFIG_IEEE80211R 2704 if (data->rx_action.category == WLAN_ACTION_FT) { 2705 ft_rx_action(wpa_s, data->rx_action.data, 2706 data->rx_action.len); 2707 break; 2708 } 2709#endif /* CONFIG_IEEE80211R */ 2710#ifdef CONFIG_IEEE80211W 2711#ifdef CONFIG_SME 2712 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) { 2713 sme_sa_query_rx(wpa_s, data->rx_action.sa, 2714 data->rx_action.data, 2715 data->rx_action.len); 2716 break; 2717 } 2718#endif /* CONFIG_SME */ 2719#endif /* CONFIG_IEEE80211W */ 2720#ifdef CONFIG_IEEE80211V 2721 if (data->rx_action.category == WLAN_ACTION_WNM) { 2722 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action); 2723 break; 2724 } 2725#endif /* CONFIG_IEEE80211V */ 2726#ifdef CONFIG_GAS 2727 if (data->rx_action.category == WLAN_ACTION_PUBLIC && 2728 gas_query_rx(wpa_s->gas, data->rx_action.da, 2729 data->rx_action.sa, data->rx_action.bssid, 2730 data->rx_action.data, data->rx_action.len, 2731 data->rx_action.freq) == 0) 2732 break; 2733#endif /* CONFIG_GAS */ 2734 if (data->rx_action.category == WLAN_ACTION_WNM) { 2735 wnm_action_rx(wpa_s, &data->rx_action); 2736 break; 2737 } 2738#ifdef CONFIG_TDLS 2739 if (data->rx_action.category == WLAN_ACTION_PUBLIC && 2740 data->rx_action.len >= 4 && 2741 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) { 2742 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery " 2743 "Response from " MACSTR, 2744 MAC2STR(data->rx_action.sa)); 2745 break; 2746 } 2747#endif /* CONFIG_TDLS */ 2748#ifdef CONFIG_P2P 2749 wpas_p2p_rx_action(wpa_s, data->rx_action.da, 2750 data->rx_action.sa, 2751 data->rx_action.bssid, 2752 data->rx_action.category, 2753 data->rx_action.data, 2754 data->rx_action.len, data->rx_action.freq); 2755#endif /* CONFIG_P2P */ 2756 break; 2757 case EVENT_RX_PROBE_REQ: 2758 if (data->rx_probe_req.sa == NULL || 2759 data->rx_probe_req.ie == NULL) 2760 break; 2761#ifdef CONFIG_AP 2762 if (wpa_s->ap_iface) { 2763 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0], 2764 data->rx_probe_req.sa, 2765 data->rx_probe_req.da, 2766 data->rx_probe_req.bssid, 2767 data->rx_probe_req.ie, 2768 data->rx_probe_req.ie_len, 2769 data->rx_probe_req.ssi_signal); 2770 break; 2771 } 2772#endif /* CONFIG_AP */ 2773#ifdef CONFIG_P2P 2774 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa, 2775 data->rx_probe_req.da, 2776 data->rx_probe_req.bssid, 2777 data->rx_probe_req.ie, 2778 data->rx_probe_req.ie_len, 2779 data->rx_probe_req.ssi_signal); 2780#endif /* CONFIG_P2P */ 2781 break; 2782 case EVENT_REMAIN_ON_CHANNEL: 2783#ifdef CONFIG_OFFCHANNEL 2784 offchannel_remain_on_channel_cb( 2785 wpa_s, data->remain_on_channel.freq, 2786 data->remain_on_channel.duration); 2787#endif /* CONFIG_OFFCHANNEL */ 2788#ifdef CONFIG_P2P 2789 wpas_p2p_remain_on_channel_cb( 2790 wpa_s, data->remain_on_channel.freq, 2791 data->remain_on_channel.duration); 2792#endif /* CONFIG_P2P */ 2793 break; 2794 case EVENT_CANCEL_REMAIN_ON_CHANNEL: 2795#ifdef CONFIG_OFFCHANNEL 2796 offchannel_cancel_remain_on_channel_cb( 2797 wpa_s, data->remain_on_channel.freq); 2798#endif /* CONFIG_OFFCHANNEL */ 2799#ifdef CONFIG_P2P 2800 wpas_p2p_cancel_remain_on_channel_cb( 2801 wpa_s, data->remain_on_channel.freq); 2802#endif /* CONFIG_P2P */ 2803 break; 2804#ifdef CONFIG_P2P 2805 case EVENT_P2P_DEV_FOUND: { 2806 struct p2p_peer_info peer_info; 2807 2808 os_memset(&peer_info, 0, sizeof(peer_info)); 2809 if (data->p2p_dev_found.dev_addr) 2810 os_memcpy(peer_info.p2p_device_addr, 2811 data->p2p_dev_found.dev_addr, ETH_ALEN); 2812 if (data->p2p_dev_found.pri_dev_type) 2813 os_memcpy(peer_info.pri_dev_type, 2814 data->p2p_dev_found.pri_dev_type, 2815 sizeof(peer_info.pri_dev_type)); 2816 if (data->p2p_dev_found.dev_name) 2817 os_strlcpy(peer_info.device_name, 2818 data->p2p_dev_found.dev_name, 2819 sizeof(peer_info.device_name)); 2820 peer_info.config_methods = data->p2p_dev_found.config_methods; 2821 peer_info.dev_capab = data->p2p_dev_found.dev_capab; 2822 peer_info.group_capab = data->p2p_dev_found.group_capab; 2823 2824 /* 2825 * FIX: new_device=1 is not necessarily correct. We should 2826 * maintain a P2P peer database in wpa_supplicant and update 2827 * this information based on whether the peer is truly new. 2828 */ 2829 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1); 2830 break; 2831 } 2832 case EVENT_P2P_GO_NEG_REQ_RX: 2833 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src, 2834 data->p2p_go_neg_req_rx.dev_passwd_id); 2835 break; 2836 case EVENT_P2P_GO_NEG_COMPLETED: 2837 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res); 2838 break; 2839 case EVENT_P2P_PROV_DISC_REQUEST: 2840 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer, 2841 data->p2p_prov_disc_req.config_methods, 2842 data->p2p_prov_disc_req.dev_addr, 2843 data->p2p_prov_disc_req.pri_dev_type, 2844 data->p2p_prov_disc_req.dev_name, 2845 data->p2p_prov_disc_req.supp_config_methods, 2846 data->p2p_prov_disc_req.dev_capab, 2847 data->p2p_prov_disc_req.group_capab, 2848 NULL, 0); 2849 break; 2850 case EVENT_P2P_PROV_DISC_RESPONSE: 2851 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer, 2852 data->p2p_prov_disc_resp.config_methods); 2853 break; 2854 case EVENT_P2P_SD_REQUEST: 2855 wpas_sd_request(wpa_s, data->p2p_sd_req.freq, 2856 data->p2p_sd_req.sa, 2857 data->p2p_sd_req.dialog_token, 2858 data->p2p_sd_req.update_indic, 2859 data->p2p_sd_req.tlvs, 2860 data->p2p_sd_req.tlvs_len); 2861 break; 2862 case EVENT_P2P_SD_RESPONSE: 2863 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa, 2864 data->p2p_sd_resp.update_indic, 2865 data->p2p_sd_resp.tlvs, 2866 data->p2p_sd_resp.tlvs_len); 2867 break; 2868#endif /* CONFIG_P2P */ 2869 case EVENT_EAPOL_RX: 2870 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src, 2871 data->eapol_rx.data, 2872 data->eapol_rx.data_len); 2873 break; 2874 case EVENT_SIGNAL_CHANGE: 2875 bgscan_notify_signal_change( 2876 wpa_s, data->signal_change.above_threshold, 2877 data->signal_change.current_signal, 2878 data->signal_change.current_noise, 2879 data->signal_change.current_txrate); 2880 break; 2881 case EVENT_INTERFACE_ENABLED: 2882 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled"); 2883 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { 2884 wpa_supplicant_update_mac_addr(wpa_s); 2885#ifdef CONFIG_AP 2886 if (!wpa_s->ap_iface) { 2887 wpa_supplicant_set_state(wpa_s, 2888 WPA_DISCONNECTED); 2889 wpa_supplicant_req_scan(wpa_s, 0, 0); 2890 } else 2891 wpa_supplicant_set_state(wpa_s, 2892 WPA_COMPLETED); 2893#else /* CONFIG_AP */ 2894 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); 2895 wpa_supplicant_req_scan(wpa_s, 0, 0); 2896#endif /* CONFIG_AP */ 2897 } 2898 break; 2899 case EVENT_INTERFACE_DISABLED: 2900 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled"); 2901 wpa_supplicant_mark_disassoc(wpa_s); 2902 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); 2903 break; 2904 case EVENT_CHANNEL_LIST_CHANGED: 2905 if (wpa_s->drv_priv == NULL) 2906 break; /* Ignore event during drv initialization */ 2907 2908 free_hw_features(wpa_s); 2909 wpa_s->hw.modes = wpa_drv_get_hw_feature_data( 2910 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags); 2911 2912#ifdef CONFIG_P2P 2913 wpas_p2p_update_channel_list(wpa_s); 2914#endif /* CONFIG_P2P */ 2915 break; 2916 case EVENT_INTERFACE_UNAVAILABLE: 2917#ifdef CONFIG_P2P 2918 wpas_p2p_interface_unavailable(wpa_s); 2919#endif /* CONFIG_P2P */ 2920 break; 2921 case EVENT_BEST_CHANNEL: 2922 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received " 2923 "(%d %d %d)", 2924 data->best_chan.freq_24, data->best_chan.freq_5, 2925 data->best_chan.freq_overall); 2926 wpa_s->best_24_freq = data->best_chan.freq_24; 2927 wpa_s->best_5_freq = data->best_chan.freq_5; 2928 wpa_s->best_overall_freq = data->best_chan.freq_overall; 2929#ifdef CONFIG_P2P 2930 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24, 2931 data->best_chan.freq_5, 2932 data->best_chan.freq_overall); 2933#endif /* CONFIG_P2P */ 2934 break; 2935 case EVENT_UNPROT_DEAUTH: 2936 wpa_supplicant_event_unprot_deauth(wpa_s, 2937 &data->unprot_deauth); 2938 break; 2939 case EVENT_UNPROT_DISASSOC: 2940 wpa_supplicant_event_unprot_disassoc(wpa_s, 2941 &data->unprot_disassoc); 2942 break; 2943 case EVENT_STATION_LOW_ACK: 2944#ifdef CONFIG_AP 2945 if (wpa_s->ap_iface && data) 2946 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0], 2947 data->low_ack.addr); 2948#endif /* CONFIG_AP */ 2949#ifdef CONFIG_TDLS 2950 if (data) 2951 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr); 2952#endif /* CONFIG_TDLS */ 2953 break; 2954 case EVENT_IBSS_PEER_LOST: 2955#ifdef CONFIG_IBSS_RSN 2956 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer); 2957#endif /* CONFIG_IBSS_RSN */ 2958 break; 2959 case EVENT_DRIVER_GTK_REKEY: 2960 if (os_memcmp(data->driver_gtk_rekey.bssid, 2961 wpa_s->bssid, ETH_ALEN)) 2962 break; 2963 if (!wpa_s->wpa) 2964 break; 2965 wpa_sm_update_replay_ctr(wpa_s->wpa, 2966 data->driver_gtk_rekey.replay_ctr); 2967 break; 2968 case EVENT_SCHED_SCAN_STOPPED: 2969 wpa_s->sched_scanning = 0; 2970 wpa_supplicant_notify_scanning(wpa_s, 0); 2971 2972 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) 2973 break; 2974 2975 /* 2976 * If we timed out, start a new sched scan to continue 2977 * searching for more SSIDs. 2978 */ 2979 if (wpa_s->sched_scan_timed_out) 2980 wpa_supplicant_req_sched_scan(wpa_s); 2981 break; 2982 case EVENT_WPS_BUTTON_PUSHED: 2983#ifdef CONFIG_WPS 2984 wpas_wps_start_pbc(wpa_s, NULL, 0); 2985#endif /* CONFIG_WPS */ 2986 break; 2987 default: 2988 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event); 2989 break; 2990 } 2991} 2992