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