LCOV - code coverage report
Current view: top level - wpa_supplicant - events.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1475438200 Lines: 1505 1901 79.2 %
Date: 2016-10-02 Functions: 61 68 89.7 %

          Line data    Source code
       1             : /*
       2             :  * WPA Supplicant - Driver event processing
       3             :  * Copyright (c) 2003-2015, 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 "fst/fst.h"
      27             : #include "wnm_sta.h"
      28             : #include "notify.h"
      29             : #include "common/ieee802_11_defs.h"
      30             : #include "common/ieee802_11_common.h"
      31             : #include "crypto/random.h"
      32             : #include "blacklist.h"
      33             : #include "wpas_glue.h"
      34             : #include "wps_supplicant.h"
      35             : #include "ibss_rsn.h"
      36             : #include "sme.h"
      37             : #include "gas_query.h"
      38             : #include "p2p_supplicant.h"
      39             : #include "bgscan.h"
      40             : #include "autoscan.h"
      41             : #include "ap.h"
      42             : #include "bss.h"
      43             : #include "scan.h"
      44             : #include "offchannel.h"
      45             : #include "interworking.h"
      46             : #include "mesh.h"
      47             : #include "mesh_mpm.h"
      48             : #include "wmm_ac.h"
      49             : 
      50             : 
      51             : #ifndef CONFIG_NO_SCAN_PROCESSING
      52             : static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
      53             :                                               int new_scan, int own_request);
      54             : #endif /* CONFIG_NO_SCAN_PROCESSING */
      55             : 
      56             : 
      57       11123 : static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
      58             :                               struct wpa_ssid *ssid)
      59             : {
      60             :         struct os_reltime now;
      61             : 
      62       11123 :         if (ssid == NULL || ssid->disabled_until.sec == 0)
      63       11107 :                 return 0;
      64             : 
      65          16 :         os_get_reltime(&now);
      66          16 :         if (ssid->disabled_until.sec > now.sec)
      67          15 :                 return ssid->disabled_until.sec - now.sec;
      68             : 
      69           1 :         wpas_clear_temp_disabled(wpa_s, ssid, 0);
      70             : 
      71           1 :         return 0;
      72             : }
      73             : 
      74             : 
      75             : #ifndef CONFIG_NO_SCAN_PROCESSING
      76             : /**
      77             :  * wpas_reenabled_network_time - Time until first network is re-enabled
      78             :  * @wpa_s: Pointer to wpa_supplicant data
      79             :  * Returns: If all enabled networks are temporarily disabled, returns the time
      80             :  *      (in sec) until the first network is re-enabled. Otherwise returns 0.
      81             :  *
      82             :  * This function is used in case all enabled networks are temporarily disabled,
      83             :  * in which case it returns the time (in sec) that the first network will be
      84             :  * re-enabled. The function assumes that at least one network is enabled.
      85             :  */
      86        5831 : static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
      87             : {
      88             :         struct wpa_ssid *ssid;
      89        5831 :         int disabled_for, res = 0;
      90             : 
      91             : #ifdef CONFIG_INTERWORKING
      92        5874 :         if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
      93          43 :             wpa_s->conf->cred)
      94          43 :                 return 0;
      95             : #endif /* CONFIG_INTERWORKING */
      96             : 
      97        6329 :         for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
      98        5725 :                 if (ssid->disabled)
      99         527 :                         continue;
     100             : 
     101        5198 :                 disabled_for = wpas_temp_disabled(wpa_s, ssid);
     102        5198 :                 if (!disabled_for)
     103        5184 :                         return 0;
     104             : 
     105          14 :                 if (!res || disabled_for < res)
     106          14 :                         res = disabled_for;
     107             :         }
     108             : 
     109         604 :         return res;
     110             : }
     111             : #endif /* CONFIG_NO_SCAN_PROCESSING */
     112             : 
     113             : 
     114           1 : void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
     115             : {
     116           1 :         struct wpa_supplicant *wpa_s = eloop_ctx;
     117             : 
     118           1 :         if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
     119           1 :                 return;
     120             : 
     121           1 :         wpa_dbg(wpa_s, MSG_DEBUG,
     122             :                 "Try to associate due to network getting re-enabled");
     123           1 :         if (wpa_supplicant_fast_associate(wpa_s) != 1) {
     124           1 :                 wpa_supplicant_cancel_sched_scan(wpa_s);
     125           1 :                 wpa_supplicant_req_scan(wpa_s, 0, 0);
     126             :         }
     127             : }
     128             : 
     129             : 
     130        4795 : static struct wpa_bss * wpa_supplicant_get_new_bss(
     131             :         struct wpa_supplicant *wpa_s, const u8 *bssid)
     132             : {
     133        4795 :         struct wpa_bss *bss = NULL;
     134        4795 :         struct wpa_ssid *ssid = wpa_s->current_ssid;
     135             : 
     136        4795 :         if (ssid->ssid_len > 0)
     137        4507 :                 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
     138        4795 :         if (!bss)
     139         307 :                 bss = wpa_bss_get_bssid(wpa_s, bssid);
     140             : 
     141        4795 :         return bss;
     142             : }
     143             : 
     144             : 
     145        4776 : static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
     146             : {
     147        4776 :         struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
     148             : 
     149        4776 :         if (!bss) {
     150          19 :                 wpa_supplicant_update_scan_results(wpa_s);
     151             : 
     152             :                 /* Get the BSS from the new scan results */
     153          19 :                 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
     154             :         }
     155             : 
     156        4776 :         if (bss)
     157        4776 :                 wpa_s->current_bss = bss;
     158        4776 : }
     159             : 
     160             : 
     161        4781 : static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
     162             : {
     163             :         struct wpa_ssid *ssid, *old_ssid;
     164             :         u8 drv_ssid[SSID_MAX_LEN];
     165             :         size_t drv_ssid_len;
     166             :         int res;
     167             : 
     168        4781 :         if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
     169        4761 :                 wpa_supplicant_update_current_bss(wpa_s);
     170             : 
     171        4761 :                 if (wpa_s->current_ssid->ssid_len == 0)
     172         285 :                         return 0; /* current profile still in use */
     173        4476 :                 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
     174        4476 :                 if (res < 0) {
     175           0 :                         wpa_msg(wpa_s, MSG_INFO,
     176             :                                 "Failed to read SSID from driver");
     177           0 :                         return 0; /* try to use current profile */
     178             :                 }
     179        4476 :                 drv_ssid_len = res;
     180             : 
     181        8952 :                 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
     182        4476 :                     os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
     183             :                               drv_ssid_len) == 0)
     184        4476 :                         return 0; /* current profile still in use */
     185             : 
     186           0 :                 wpa_msg(wpa_s, MSG_DEBUG,
     187             :                         "Driver-initiated BSS selection changed the SSID to %s",
     188             :                         wpa_ssid_txt(drv_ssid, drv_ssid_len));
     189             :                 /* continue selecting a new network profile */
     190             :         }
     191             : 
     192          20 :         wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
     193             :                 "information");
     194          20 :         ssid = wpa_supplicant_get_ssid(wpa_s);
     195          20 :         if (ssid == NULL) {
     196           4 :                 wpa_msg(wpa_s, MSG_INFO,
     197             :                         "No network configuration found for the current AP");
     198           4 :                 return -1;
     199             :         }
     200             : 
     201          16 :         if (wpas_network_disabled(wpa_s, ssid)) {
     202           0 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
     203           0 :                 return -1;
     204             :         }
     205             : 
     206          31 :         if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
     207          15 :             disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
     208           1 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
     209           1 :                 return -1;
     210             :         }
     211             : 
     212          15 :         res = wpas_temp_disabled(wpa_s, ssid);
     213          15 :         if (res > 0) {
     214           0 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
     215             :                         "disabled for %d second(s)", res);
     216           0 :                 return -1;
     217             :         }
     218             : 
     219          15 :         wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
     220             :                 "current AP");
     221          15 :         if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
     222             :                 u8 wpa_ie[80];
     223           6 :                 size_t wpa_ie_len = sizeof(wpa_ie);
     224           6 :                 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
     225             :                                               wpa_ie, &wpa_ie_len) < 0)
     226           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
     227             :         } else {
     228           9 :                 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
     229             :         }
     230             : 
     231          15 :         if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
     232           0 :                 eapol_sm_invalidate_cached_session(wpa_s->eapol);
     233          15 :         old_ssid = wpa_s->current_ssid;
     234          15 :         wpa_s->current_ssid = ssid;
     235             : 
     236          15 :         wpa_supplicant_update_current_bss(wpa_s);
     237             : 
     238          15 :         wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
     239          15 :         wpa_supplicant_initiate_eapol(wpa_s);
     240          15 :         if (old_ssid != wpa_s->current_ssid)
     241           8 :                 wpas_notify_network_changed(wpa_s);
     242             : 
     243          15 :         return 0;
     244             : }
     245             : 
     246             : 
     247        6060 : void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
     248             : {
     249        6060 :         struct wpa_supplicant *wpa_s = eloop_ctx;
     250             : 
     251        6060 :         if (wpa_s->countermeasures) {
     252           1 :                 wpa_s->countermeasures = 0;
     253           1 :                 wpa_drv_set_countermeasures(wpa_s, 0);
     254           1 :                 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
     255             : 
     256             :                 /*
     257             :                  * It is possible that the device is sched scanning, which means
     258             :                  * that a connection attempt will be done only when we receive
     259             :                  * scan results. However, in this case, it would be preferable
     260             :                  * to scan and connect immediately, so cancel the sched_scan and
     261             :                  * issue a regular scan flow.
     262             :                  */
     263           1 :                 wpa_supplicant_cancel_sched_scan(wpa_s);
     264           1 :                 wpa_supplicant_req_scan(wpa_s, 0, 0);
     265             :         }
     266        6060 : }
     267             : 
     268             : 
     269       10398 : void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
     270             : {
     271             :         int bssid_changed;
     272             : 
     273       10398 :         wnm_bss_keep_alive_deinit(wpa_s);
     274             : 
     275             : #ifdef CONFIG_IBSS_RSN
     276       10398 :         ibss_rsn_deinit(wpa_s->ibss_rsn);
     277       10398 :         wpa_s->ibss_rsn = NULL;
     278             : #endif /* CONFIG_IBSS_RSN */
     279             : 
     280             : #ifdef CONFIG_AP
     281       10398 :         wpa_supplicant_ap_deinit(wpa_s);
     282             : #endif /* CONFIG_AP */
     283             : 
     284             : #ifdef CONFIG_HS20
     285             :         /* Clear possibly configured frame filters */
     286       10398 :         wpa_drv_configure_frame_filters(wpa_s, 0);
     287             : #endif /* CONFIG_HS20 */
     288             : 
     289       10398 :         if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
     290       10488 :                 return;
     291             : 
     292       10308 :         wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
     293       10308 :         bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
     294       10308 :         os_memset(wpa_s->bssid, 0, ETH_ALEN);
     295       10308 :         os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
     296       10308 :         sme_clear_on_disassoc(wpa_s);
     297       10308 :         wpa_s->current_bss = NULL;
     298       10308 :         wpa_s->assoc_freq = 0;
     299             : 
     300       10308 :         if (bssid_changed)
     301        4609 :                 wpas_notify_bssid_changed(wpa_s);
     302             : 
     303       10308 :         eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
     304       10308 :         eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
     305       10308 :         if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
     306        1162 :                 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
     307       10308 :         wpa_s->ap_ies_from_associnfo = 0;
     308       10308 :         wpa_s->current_ssid = NULL;
     309       10308 :         eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
     310       10308 :         wpa_s->key_mgmt = 0;
     311             : 
     312       10308 :         wpas_rrm_reset(wpa_s);
     313       10308 :         wpa_s->wnmsleep_used = 0;
     314             : }
     315             : 
     316             : 
     317           0 : static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
     318             : {
     319             :         struct wpa_ie_data ie;
     320           0 :         int pmksa_set = -1;
     321             :         size_t i;
     322             : 
     323           0 :         if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
     324           0 :             ie.pmkid == NULL)
     325           0 :                 return;
     326             : 
     327           0 :         for (i = 0; i < ie.num_pmkid; i++) {
     328           0 :                 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
     329           0 :                                                     ie.pmkid + i * PMKID_LEN,
     330             :                                                     NULL, NULL, 0);
     331           0 :                 if (pmksa_set == 0) {
     332           0 :                         eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
     333           0 :                         break;
     334             :                 }
     335             :         }
     336             : 
     337           0 :         wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
     338             :                 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
     339             : }
     340             : 
     341             : 
     342           0 : static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
     343             :                                                  union wpa_event_data *data)
     344             : {
     345           0 :         if (data == NULL) {
     346           0 :                 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
     347             :                         "event");
     348           0 :                 return;
     349             :         }
     350           0 :         wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
     351             :                 " index=%d preauth=%d",
     352             :                 MAC2STR(data->pmkid_candidate.bssid),
     353             :                 data->pmkid_candidate.index,
     354             :                 data->pmkid_candidate.preauth);
     355             : 
     356           0 :         pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
     357             :                             data->pmkid_candidate.index,
     358             :                             data->pmkid_candidate.preauth);
     359             : }
     360             : 
     361             : 
     362        9717 : static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
     363             : {
     364       17983 :         if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
     365        8266 :             wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
     366        1456 :                 return 0;
     367             : 
     368             : #ifdef IEEE8021X_EAPOL
     369        8302 :         if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
     370          82 :             wpa_s->current_ssid &&
     371          41 :             !(wpa_s->current_ssid->eapol_flags &
     372             :               (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
     373             :                EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
     374             :                 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
     375             :                  * plaintext or static WEP keys). */
     376          29 :                 return 0;
     377             :         }
     378             : #endif /* IEEE8021X_EAPOL */
     379             : 
     380        8232 :         return 1;
     381             : }
     382             : 
     383             : 
     384             : /**
     385             :  * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
     386             :  * @wpa_s: pointer to wpa_supplicant data
     387             :  * @ssid: Configuration data for the network
     388             :  * Returns: 0 on success, -1 on failure
     389             :  *
     390             :  * This function is called when starting authentication with a network that is
     391             :  * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
     392             :  */
     393        9718 : int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
     394             :                               struct wpa_ssid *ssid)
     395             : {
     396             : #ifdef IEEE8021X_EAPOL
     397             : #ifdef PCSC_FUNCS
     398             :         int aka = 0, sim = 0;
     399             : 
     400             :         if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
     401             :             wpa_s->scard != NULL || wpa_s->conf->external_sim)
     402             :                 return 0;
     403             : 
     404             :         if (ssid == NULL || ssid->eap.eap_methods == NULL) {
     405             :                 sim = 1;
     406             :                 aka = 1;
     407             :         } else {
     408             :                 struct eap_method_type *eap = ssid->eap.eap_methods;
     409             :                 while (eap->vendor != EAP_VENDOR_IETF ||
     410             :                        eap->method != EAP_TYPE_NONE) {
     411             :                         if (eap->vendor == EAP_VENDOR_IETF) {
     412             :                                 if (eap->method == EAP_TYPE_SIM)
     413             :                                         sim = 1;
     414             :                                 else if (eap->method == EAP_TYPE_AKA ||
     415             :                                          eap->method == EAP_TYPE_AKA_PRIME)
     416             :                                         aka = 1;
     417             :                         }
     418             :                         eap++;
     419             :                 }
     420             :         }
     421             : 
     422             :         if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
     423             :                 sim = 0;
     424             :         if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
     425             :             eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
     426             :             NULL)
     427             :                 aka = 0;
     428             : 
     429             :         if (!sim && !aka) {
     430             :                 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
     431             :                         "use SIM, but neither EAP-SIM nor EAP-AKA are "
     432             :                         "enabled");
     433             :                 return 0;
     434             :         }
     435             : 
     436             :         wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
     437             :                 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
     438             : 
     439             :         wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
     440             :         if (wpa_s->scard == NULL) {
     441             :                 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
     442             :                         "(pcsc-lite)");
     443             :                 return -1;
     444             :         }
     445             :         wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
     446             :         eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
     447             : #endif /* PCSC_FUNCS */
     448             : #endif /* IEEE8021X_EAPOL */
     449             : 
     450        9718 :         return 0;
     451             : }
     452             : 
     453             : 
     454             : #ifndef CONFIG_NO_SCAN_PROCESSING
     455             : 
     456        5183 : static int has_wep_key(struct wpa_ssid *ssid)
     457             : {
     458             :         int i;
     459             : 
     460       25807 :         for (i = 0; i < NUM_WEP_KEYS; i++) {
     461       20651 :                 if (ssid->wep_key_len[i])
     462          27 :                         return 1;
     463             :         }
     464             : 
     465        5156 :         return 0;
     466             : }
     467             : 
     468             : 
     469        5206 : static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
     470             :                                         struct wpa_ssid *ssid)
     471             : {
     472        5206 :         int privacy = 0;
     473             : 
     474        5206 :         if (ssid->mixed_cell)
     475           0 :                 return 1;
     476             : 
     477             : #ifdef CONFIG_WPS
     478        5206 :         if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
     479         544 :                 return 1;
     480             : #endif /* CONFIG_WPS */
     481             : 
     482        4662 :         if (has_wep_key(ssid))
     483          27 :                 privacy = 1;
     484             : 
     485             : #ifdef IEEE8021X_EAPOL
     486        4683 :         if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
     487          21 :             ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
     488             :                                  EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
     489           6 :                 privacy = 1;
     490             : #endif /* IEEE8021X_EAPOL */
     491             : 
     492        4662 :         if (wpa_key_mgmt_wpa(ssid->key_mgmt))
     493        3793 :                 privacy = 1;
     494             : 
     495        4662 :         if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
     496           2 :                 privacy = 1;
     497             : 
     498        4662 :         if (bss->caps & IEEE80211_CAP_PRIVACY)
     499        3829 :                 return privacy;
     500         833 :         return !privacy;
     501             : }
     502             : 
     503             : 
     504        5359 : static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
     505             :                                          struct wpa_ssid *ssid,
     506             :                                          struct wpa_bss *bss)
     507             : {
     508             :         struct wpa_ie_data ie;
     509        5359 :         int proto_match = 0;
     510             :         const u8 *rsn_ie, *wpa_ie;
     511             :         int ret;
     512             :         int wep_ok;
     513             : 
     514        5359 :         ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
     515        5359 :         if (ret >= 0)
     516         639 :                 return ret;
     517             : 
     518             :         /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
     519        5636 :         wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
     520        1717 :                 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
     521        1691 :                   ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
     522         844 :                  (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
     523             : 
     524        4720 :         rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
     525        4720 :         while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
     526        3745 :                 proto_match++;
     527             : 
     528        3745 :                 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
     529           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip RSN IE - parse "
     530             :                                 "failed");
     531           0 :                         break;
     532             :                 }
     533             : 
     534        3745 :                 if (wep_ok &&
     535           0 :                     (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
     536             :                 {
     537           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   selected based on TSN "
     538             :                                 "in RSN IE");
     539           0 :                         return 1;
     540             :                 }
     541             : 
     542        3745 :                 if (!(ie.proto & ssid->proto)) {
     543           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip RSN IE - proto "
     544             :                                 "mismatch");
     545           0 :                         break;
     546             :                 }
     547             : 
     548        3745 :                 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
     549           1 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip RSN IE - PTK "
     550             :                                 "cipher mismatch");
     551           1 :                         break;
     552             :                 }
     553             : 
     554        3744 :                 if (!(ie.group_cipher & ssid->group_cipher)) {
     555           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip RSN IE - GTK "
     556             :                                 "cipher mismatch");
     557           0 :                         break;
     558             :                 }
     559             : 
     560        3744 :                 if (!(ie.key_mgmt & ssid->key_mgmt)) {
     561           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip RSN IE - key mgmt "
     562             :                                 "mismatch");
     563           0 :                         break;
     564             :                 }
     565             : 
     566             : #ifdef CONFIG_IEEE80211W
     567        7296 :                 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
     568        3552 :                     wpas_get_ssid_pmf(wpa_s, ssid) ==
     569             :                     MGMT_FRAME_PROTECTION_REQUIRED) {
     570           2 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip RSN IE - no mgmt "
     571             :                                 "frame protection");
     572           2 :                         break;
     573             :                 }
     574             : #endif /* CONFIG_IEEE80211W */
     575        3788 :                 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
     576          46 :                     wpas_get_ssid_pmf(wpa_s, ssid) ==
     577             :                     NO_MGMT_FRAME_PROTECTION) {
     578           1 :                         wpa_dbg(wpa_s, MSG_DEBUG,
     579             :                                 "   skip RSN IE - no mgmt frame protection enabled but AP requires it");
     580           1 :                         break;
     581             :                 }
     582             : #ifdef CONFIG_MBO
     583        7291 :                 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
     584        3550 :                     wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND) &&
     585           0 :                     wpas_get_ssid_pmf(wpa_s, ssid) !=
     586             :                     NO_MGMT_FRAME_PROTECTION) {
     587           0 :                         wpa_dbg(wpa_s, MSG_DEBUG,
     588             :                                 "   skip RSN IE - no mgmt frame protection enabled on MBO AP");
     589           0 :                         break;
     590             :                 }
     591             : #endif /* CONFIG_MBO */
     592             : 
     593        3741 :                 wpa_dbg(wpa_s, MSG_DEBUG, "   selected based on RSN IE");
     594        3741 :                 return 1;
     595             :         }
     596             : 
     597             : #ifdef CONFIG_IEEE80211W
     598         979 :         if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED) {
     599           3 :                 wpa_dbg(wpa_s, MSG_DEBUG,
     600             :                         "   skip - MFP Required but network not MFP Capable");
     601           3 :                 return 0;
     602             :         }
     603             : #endif /* CONFIG_IEEE80211W */
     604             : 
     605         976 :         wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
     606         976 :         while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
     607          52 :                 proto_match++;
     608             : 
     609          52 :                 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
     610           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip WPA IE - parse "
     611             :                                 "failed");
     612           0 :                         break;
     613             :                 }
     614             : 
     615          52 :                 if (wep_ok &&
     616           0 :                     (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
     617             :                 {
     618           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   selected based on TSN "
     619             :                                 "in WPA IE");
     620           0 :                         return 1;
     621             :                 }
     622             : 
     623          52 :                 if (!(ie.proto & ssid->proto)) {
     624           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip WPA IE - proto "
     625             :                                 "mismatch");
     626           0 :                         break;
     627             :                 }
     628             : 
     629          52 :                 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
     630           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip WPA IE - PTK "
     631             :                                 "cipher mismatch");
     632           0 :                         break;
     633             :                 }
     634             : 
     635          52 :                 if (!(ie.group_cipher & ssid->group_cipher)) {
     636           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip WPA IE - GTK "
     637             :                                 "cipher mismatch");
     638           0 :                         break;
     639             :                 }
     640             : 
     641          52 :                 if (!(ie.key_mgmt & ssid->key_mgmt)) {
     642           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip WPA IE - key mgmt "
     643             :                                 "mismatch");
     644           0 :                         break;
     645             :                 }
     646             : 
     647          52 :                 wpa_dbg(wpa_s, MSG_DEBUG, "   selected based on WPA IE");
     648          52 :                 return 1;
     649             :         }
     650             : 
     651         924 :         if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
     652             :             !rsn_ie) {
     653          21 :                 wpa_dbg(wpa_s, MSG_DEBUG, "   allow for non-WPA IEEE 802.1X");
     654          21 :                 return 1;
     655             :         }
     656             : 
     657        1801 :         if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
     658         953 :             wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
     659          54 :                 wpa_dbg(wpa_s, MSG_DEBUG, "   skip - no WPA/RSN proto match");
     660          54 :                 return 0;
     661             :         }
     662             : 
     663         851 :         if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
     664           2 :             wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
     665           2 :                 wpa_dbg(wpa_s, MSG_DEBUG, "   allow in OSEN");
     666           2 :                 return 1;
     667             :         }
     668             : 
     669         847 :         if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
     670         846 :                 wpa_dbg(wpa_s, MSG_DEBUG, "   allow in non-WPA/WPA2");
     671         846 :                 return 1;
     672             :         }
     673             : 
     674           1 :         wpa_dbg(wpa_s, MSG_DEBUG, "   reject due to mismatch with "
     675             :                 "WPA/WPA2");
     676             : 
     677           1 :         return 0;
     678             : }
     679             : 
     680             : 
     681        5195 : static int freq_allowed(int *freqs, int freq)
     682             : {
     683             :         int i;
     684             : 
     685        5195 :         if (freqs == NULL)
     686        5191 :                 return 1;
     687             : 
     688           6 :         for (i = 0; freqs[i]; i++)
     689           4 :                 if (freqs[i] == freq)
     690           2 :                         return 1;
     691           2 :         return 0;
     692             : }
     693             : 
     694             : 
     695        5193 : static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
     696             : {
     697        5193 :         const struct hostapd_hw_modes *mode = NULL, *modes;
     698        5193 :         const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
     699             :         const u8 *rate_ie;
     700             :         int i, j, k;
     701             : 
     702        5193 :         if (bss->freq == 0)
     703           0 :                 return 1; /* Cannot do matching without knowing band */
     704             : 
     705        5193 :         modes = wpa_s->hw.modes;
     706        5193 :         if (modes == NULL) {
     707             :                 /*
     708             :                  * The driver does not provide any additional information
     709             :                  * about the utilized hardware, so allow the connection attempt
     710             :                  * to continue.
     711             :                  */
     712          14 :                 return 1;
     713             :         }
     714             : 
     715       20716 :         for (i = 0; i < wpa_s->hw.num_modes; i++) {
     716      148795 :                 for (j = 0; j < modes[i].num_channels; j++) {
     717      143378 :                         int freq = modes[i].channels[j].freq;
     718      143378 :                         if (freq == bss->freq) {
     719       15061 :                                 if (mode &&
     720        4941 :                                     mode->mode == HOSTAPD_MODE_IEEE80211G)
     721        4941 :                                         break; /* do not allow 802.11b replace
     722             :                                                 * 802.11g */
     723        5179 :                                 mode = &modes[i];
     724        5179 :                                 break;
     725             :                         }
     726             :                 }
     727             :         }
     728             : 
     729        5179 :         if (mode == NULL)
     730           0 :                 return 0;
     731             : 
     732       15537 :         for (i = 0; i < (int) sizeof(scan_ie); i++) {
     733       10358 :                 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
     734       10358 :                 if (rate_ie == NULL)
     735        1055 :                         continue;
     736             : 
     737       67195 :                 for (j = 2; j < rate_ie[1] + 2; j++) {
     738       57892 :                         int flagged = !!(rate_ie[j] & 0x80);
     739       57892 :                         int r = (rate_ie[j] & 0x7f) * 5;
     740             : 
     741             :                         /*
     742             :                          * IEEE Std 802.11n-2009 7.3.2.2:
     743             :                          * The new BSS Membership selector value is encoded
     744             :                          * like a legacy basic rate, but it is not a rate and
     745             :                          * only indicates if the BSS members are required to
     746             :                          * support the mandatory features of Clause 20 [HT PHY]
     747             :                          * in order to join the BSS.
     748             :                          */
     749       57892 :                         if (flagged && ((rate_ie[j] & 0x7f) ==
     750             :                                         BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
     751           7 :                                 if (!ht_supported(mode)) {
     752           0 :                                         wpa_dbg(wpa_s, MSG_DEBUG,
     753             :                                                 "   hardware does not support "
     754             :                                                 "HT PHY");
     755           0 :                                         return 0;
     756             :                                 }
     757           7 :                                 continue;
     758             :                         }
     759             : 
     760             :                         /* There's also a VHT selector for 802.11ac */
     761       57885 :                         if (flagged && ((rate_ie[j] & 0x7f) ==
     762             :                                         BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
     763           3 :                                 if (!vht_supported(mode)) {
     764           0 :                                         wpa_dbg(wpa_s, MSG_DEBUG,
     765             :                                                 "   hardware does not support "
     766             :                                                 "VHT PHY");
     767           0 :                                         return 0;
     768             :                                 }
     769           3 :                                 continue;
     770             :                         }
     771             : 
     772       57882 :                         if (!flagged)
     773       38226 :                                 continue;
     774             : 
     775             :                         /* check for legacy basic rates */
     776       60464 :                         for (k = 0; k < mode->num_rates; k++) {
     777       60464 :                                 if (mode->rates[k] == r)
     778       19656 :                                         break;
     779             :                         }
     780       19656 :                         if (k == mode->num_rates) {
     781             :                                 /*
     782             :                                  * IEEE Std 802.11-2007 7.3.2.2 demands that in
     783             :                                  * order to join a BSS all required rates
     784             :                                  * have to be supported by the hardware.
     785             :                                  */
     786           0 :                                 wpa_dbg(wpa_s, MSG_DEBUG,
     787             :                                         "   hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
     788             :                                         r / 10, r % 10,
     789             :                                         bss->freq, mode->mode, mode->num_rates);
     790           0 :                                 return 0;
     791             :                         }
     792             :                 }
     793             :         }
     794             : 
     795        5179 :         return 1;
     796             : }
     797             : 
     798             : 
     799             : /*
     800             :  * Test whether BSS is in an ESS.
     801             :  * This is done differently in DMG (60 GHz) and non-DMG bands
     802             :  */
     803        5201 : static int bss_is_ess(struct wpa_bss *bss)
     804             : {
     805        5201 :         if (bss_is_dmg(bss)) {
     806           0 :                 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
     807             :                         IEEE80211_CAP_DMG_AP;
     808             :         }
     809             : 
     810        5201 :         return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
     811             :                 IEEE80211_CAP_ESS);
     812             : }
     813             : 
     814             : 
     815          17 : static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
     816             : {
     817             :         size_t i;
     818             : 
     819          55 :         for (i = 0; i < ETH_ALEN; i++) {
     820          52 :                 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
     821          14 :                         return 0;
     822             :         }
     823           3 :         return 1;
     824             : }
     825             : 
     826             : 
     827          12 : static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
     828             : {
     829             :         size_t i;
     830             : 
     831          26 :         for (i = 0; i < num; i++) {
     832          17 :                 const u8 *a = list + i * ETH_ALEN * 2;
     833          17 :                 const u8 *m = a + ETH_ALEN;
     834             : 
     835          17 :                 if (match_mac_mask(a, addr, m))
     836           3 :                         return 1;
     837             :         }
     838           9 :         return 0;
     839             : }
     840             : 
     841             : 
     842        6300 : struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
     843             :                                      int i, struct wpa_bss *bss,
     844             :                                      struct wpa_ssid *group,
     845             :                                      int only_first_ssid)
     846             : {
     847             :         u8 wpa_ie_len, rsn_ie_len;
     848             :         int wpa;
     849             :         struct wpa_blacklist *e;
     850             :         const u8 *ie;
     851             :         struct wpa_ssid *ssid;
     852             :         int osen;
     853             : #ifdef CONFIG_MBO
     854             :         const u8 *assoc_disallow;
     855             : #endif /* CONFIG_MBO */
     856             : 
     857        6300 :         ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
     858        6300 :         wpa_ie_len = ie ? ie[1] : 0;
     859             : 
     860        6300 :         ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
     861        6300 :         rsn_ie_len = ie ? ie[1] : 0;
     862             : 
     863        6300 :         ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
     864        6300 :         osen = ie != NULL;
     865             : 
     866        6300 :         wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
     867             :                 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
     868             :                 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
     869             :                 wpa_ie_len, rsn_ie_len, bss->caps, bss->level, bss->freq,
     870             :                 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
     871             :                 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
     872             :                  wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
     873             :                 " p2p" : "",
     874             :                 osen ? " osen=1" : "");
     875             : 
     876        6300 :         e = wpa_blacklist_get(wpa_s, bss->bssid);
     877        6300 :         if (e) {
     878         363 :                 int limit = 1;
     879         363 :                 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
     880             :                         /*
     881             :                          * When only a single network is enabled, we can
     882             :                          * trigger blacklisting on the first failure. This
     883             :                          * should not be done with multiple enabled networks to
     884             :                          * avoid getting forced to move into a worse ESS on
     885             :                          * single error if there are no other BSSes of the
     886             :                          * current ESS.
     887             :                          */
     888         363 :                         limit = 0;
     889             :                 }
     890         363 :                 if (e->count > limit) {
     891         363 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - blacklisted "
     892             :                                 "(count=%d limit=%d)", e->count, limit);
     893         363 :                         return NULL;
     894             :                 }
     895             :         }
     896             : 
     897        5937 :         if (bss->ssid_len == 0) {
     898           9 :                 wpa_dbg(wpa_s, MSG_DEBUG, "   skip - SSID not known");
     899           9 :                 return NULL;
     900             :         }
     901             : 
     902        5928 :         if (disallowed_bssid(wpa_s, bss->bssid)) {
     903           1 :                 wpa_dbg(wpa_s, MSG_DEBUG, "   skip - BSSID disallowed");
     904           1 :                 return NULL;
     905             :         }
     906             : 
     907        5927 :         if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
     908           2 :                 wpa_dbg(wpa_s, MSG_DEBUG, "   skip - SSID disallowed");
     909           2 :                 return NULL;
     910             :         }
     911             : 
     912        5925 :         wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
     913             : 
     914        8711 :         for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
     915        7912 :                 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
     916             :                 int res;
     917             : 
     918        7912 :                 if (wpas_network_disabled(wpa_s, ssid)) {
     919        2008 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - disabled");
     920        2008 :                         continue;
     921             :                 }
     922             : 
     923        5904 :                 res = wpas_temp_disabled(wpa_s, ssid);
     924        5904 :                 if (res > 0) {
     925           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - disabled "
     926             :                                 "temporarily for %d second(s)", res);
     927           0 :                         continue;
     928             :                 }
     929             : 
     930             : #ifdef CONFIG_WPS
     931        5904 :                 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
     932           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - blacklisted "
     933             :                                 "(WPS)");
     934           0 :                         continue;
     935             :                 }
     936             : 
     937        6275 :                 if (wpa && ssid->ssid_len == 0 &&
     938         371 :                     wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
     939         336 :                         check_ssid = 0;
     940             : 
     941        5904 :                 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
     942             :                         /* Only allow wildcard SSID match if an AP
     943             :                          * advertises active WPS operation that matches
     944             :                          * with our mode. */
     945          39 :                         check_ssid = 1;
     946          69 :                         if (ssid->ssid_len == 0 &&
     947          30 :                             wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
     948          28 :                                 check_ssid = 0;
     949             :                 }
     950             : #endif /* CONFIG_WPS */
     951             : 
     952        6246 :                 if (ssid->bssid_set && ssid->ssid_len == 0 &&
     953         342 :                     os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
     954         339 :                         check_ssid = 0;
     955             : 
     956       11444 :                 if (check_ssid &&
     957       10794 :                     (bss->ssid_len != ssid->ssid_len ||
     958        5254 :                      os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
     959         522 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - SSID mismatch");
     960         522 :                         continue;
     961             :                 }
     962             : 
     963        6487 :                 if (ssid->bssid_set &&
     964        1105 :                     os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
     965          17 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - BSSID mismatch");
     966          17 :                         continue;
     967             :                 }
     968             : 
     969             :                 /* check blacklist */
     970        5368 :                 if (ssid->num_bssid_blacklist &&
     971           3 :                     addr_in_list(bss->bssid, ssid->bssid_blacklist,
     972             :                                  ssid->num_bssid_blacklist)) {
     973           0 :                         wpa_dbg(wpa_s, MSG_DEBUG,
     974             :                                 "   skip - BSSID blacklisted");
     975           0 :                         continue;
     976             :                 }
     977             : 
     978             :                 /* if there is a whitelist, only accept those APs */
     979        5374 :                 if (ssid->num_bssid_whitelist &&
     980           9 :                     !addr_in_list(bss->bssid, ssid->bssid_whitelist,
     981             :                                   ssid->num_bssid_whitelist)) {
     982           6 :                         wpa_dbg(wpa_s, MSG_DEBUG,
     983             :                                 "   skip - BSSID not in whitelist");
     984           6 :                         continue;
     985             :                 }
     986             : 
     987        5359 :                 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
     988         153 :                         continue;
     989             : 
     990        6095 :                 if (!osen && !wpa &&
     991         936 :                     !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
     992          68 :                     !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
     993          21 :                     !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
     994           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - non-WPA network "
     995             :                                 "not allowed");
     996           0 :                         continue;
     997             :                 }
     998             : 
     999        5727 :                 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
    1000         521 :                     has_wep_key(ssid)) {
    1001           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - ignore WPA/WPA2 AP for WEP network block");
    1002           0 :                         continue;
    1003             :                 }
    1004             : 
    1005        5206 :                 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
    1006           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - non-OSEN network "
    1007             :                                 "not allowed");
    1008           0 :                         continue;
    1009             :                 }
    1010             : 
    1011        5206 :                 if (!wpa_supplicant_match_privacy(bss, ssid)) {
    1012           4 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - privacy "
    1013             :                                 "mismatch");
    1014           4 :                         continue;
    1015             :                 }
    1016             : 
    1017        5209 :                 if (ssid->mode != IEEE80211_MODE_MESH && !bss_is_ess(bss) &&
    1018           7 :                     !bss_is_pbss(bss)) {
    1019           7 :                         wpa_dbg(wpa_s, MSG_DEBUG,
    1020             :                                 "   skip - not ESS, PBSS, or MBSS");
    1021           7 :                         continue;
    1022             :                 }
    1023             : 
    1024        5195 :                 if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) {
    1025           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - PBSS mismatch (ssid %d bss %d)",
    1026             :                                 ssid->pbss, bss_is_pbss(bss));
    1027           0 :                         continue;
    1028             :                 }
    1029             : 
    1030        5195 :                 if (!freq_allowed(ssid->freq_list, bss->freq)) {
    1031           2 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - frequency not "
    1032             :                                 "allowed");
    1033           2 :                         continue;
    1034             :                 }
    1035             : 
    1036             : #ifdef CONFIG_MESH
    1037        5194 :                 if (ssid->mode == IEEE80211_MODE_MESH && ssid->frequency > 0 &&
    1038           1 :                     ssid->frequency != bss->freq) {
    1039           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - frequency not allowed (mesh)");
    1040           0 :                         continue;
    1041             :                 }
    1042             : #endif /* CONFIG_MESH */
    1043             : 
    1044        5193 :                 if (!rate_match(wpa_s, bss)) {
    1045           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - rate sets do "
    1046             :                                 "not match");
    1047           0 :                         continue;
    1048             :                 }
    1049             : 
    1050             : #ifdef CONFIG_P2P
    1051        6018 :                 if (ssid->p2p_group &&
    1052         828 :                     !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
    1053           3 :                     !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
    1054           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "   skip - no P2P IE seen");
    1055           0 :                         continue;
    1056             :                 }
    1057             : 
    1058        5193 :                 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
    1059             :                         struct wpabuf *p2p_ie;
    1060             :                         u8 dev_addr[ETH_ALEN];
    1061             : 
    1062          51 :                         ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
    1063          51 :                         if (ie == NULL) {
    1064           0 :                                 wpa_dbg(wpa_s, MSG_DEBUG, "   skip - no P2P element");
    1065           0 :                                 continue;
    1066             :                         }
    1067          51 :                         p2p_ie = wpa_bss_get_vendor_ie_multi(
    1068             :                                 bss, P2P_IE_VENDOR_TYPE);
    1069          51 :                         if (p2p_ie == NULL) {
    1070           0 :                                 wpa_dbg(wpa_s, MSG_DEBUG, "   skip - could not fetch P2P element");
    1071           0 :                                 continue;
    1072             :                         }
    1073             : 
    1074          51 :                         if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
    1075          51 :                             || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
    1076             :                                          ETH_ALEN) != 0) {
    1077           0 :                                 wpa_dbg(wpa_s, MSG_DEBUG, "   skip - no matching GO P2P Device Address in P2P element");
    1078           0 :                                 wpabuf_free(p2p_ie);
    1079           0 :                                 continue;
    1080             :                         }
    1081          51 :                         wpabuf_free(p2p_ie);
    1082             :                 }
    1083             : 
    1084             :                 /*
    1085             :                  * TODO: skip the AP if its P2P IE has Group Formation
    1086             :                  * bit set in the P2P Group Capability Bitmap and we
    1087             :                  * are not in Group Formation with that device.
    1088             :                  */
    1089             : #endif /* CONFIG_P2P */
    1090             : 
    1091        5193 :                 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
    1092             :                 {
    1093             :                         struct os_reltime diff;
    1094             : 
    1095          59 :                         os_reltime_sub(&wpa_s->scan_min_time,
    1096             :                                        &bss->last_update, &diff);
    1097          59 :                         wpa_dbg(wpa_s, MSG_DEBUG,
    1098             :                                 "   skip - scan result not recent enough (%u.%06u seconds too old)",
    1099             :                                 (unsigned int) diff.sec,
    1100             :                                 (unsigned int) diff.usec);
    1101          59 :                         continue;
    1102             :                 }
    1103             : #ifdef CONFIG_MBO
    1104             : #ifdef CONFIG_TESTING_OPTIONS
    1105        5134 :                 if (wpa_s->ignore_assoc_disallow)
    1106           2 :                         goto skip_assoc_disallow;
    1107             : #endif /* CONFIG_TESTING_OPTIONS */
    1108        5132 :                 assoc_disallow = wpas_mbo_get_bss_attr(
    1109             :                         bss, MBO_ATTR_ID_ASSOC_DISALLOW);
    1110        5132 :                 if (assoc_disallow && assoc_disallow[1] >= 1) {
    1111           2 :                         wpa_dbg(wpa_s, MSG_DEBUG,
    1112             :                                 "   skip - MBO association disallowed (reason %u)",
    1113             :                                 assoc_disallow[2]);
    1114           2 :                         continue;
    1115             :                 }
    1116             : 
    1117        5130 :                 if (wpa_is_bss_tmp_disallowed(wpa_s, bss->bssid)) {
    1118           6 :                         wpa_dbg(wpa_s, MSG_DEBUG,
    1119             :                                 "   skip - MBO retry delay has not passed yet");
    1120           6 :                         continue;
    1121             :                 }
    1122             : #ifdef CONFIG_TESTING_OPTIONS
    1123             :         skip_assoc_disallow:
    1124             : #endif /* CONFIG_TESTING_OPTIONS */
    1125             : #endif /* CONFIG_MBO */
    1126             : 
    1127             :                 /* Matching configuration found */
    1128        5126 :                 return ssid;
    1129             :         }
    1130             : 
    1131             :         /* No matching configuration found */
    1132         799 :         return NULL;
    1133             : }
    1134             : 
    1135             : 
    1136             : static struct wpa_bss *
    1137        5808 : wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
    1138             :                           struct wpa_ssid *group,
    1139             :                           struct wpa_ssid **selected_ssid,
    1140             :                           int only_first_ssid)
    1141             : {
    1142             :         unsigned int i;
    1143             : 
    1144        5808 :         if (only_first_ssid)
    1145         121 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
    1146             :                         group->id);
    1147             :         else
    1148        5687 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
    1149             :                         group->priority);
    1150             : 
    1151       13950 :         for (i = 0; i < wpa_s->last_scan_res_used; i++) {
    1152        6260 :                 struct wpa_bss *bss = wpa_s->last_scan_res[i];
    1153        6260 :                 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
    1154             :                                                     only_first_ssid);
    1155        6260 :                 if (!*selected_ssid)
    1156        1167 :                         continue;
    1157        5093 :                 wpa_dbg(wpa_s, MSG_DEBUG, "   selected BSS " MACSTR
    1158             :                         " ssid='%s'",
    1159             :                         MAC2STR(bss->bssid),
    1160             :                         wpa_ssid_txt(bss->ssid, bss->ssid_len));
    1161        5093 :                 return bss;
    1162             :         }
    1163             : 
    1164         715 :         return NULL;
    1165             : }
    1166             : 
    1167             : 
    1168        6161 : struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
    1169             :                                              struct wpa_ssid **selected_ssid)
    1170             : {
    1171        6161 :         struct wpa_bss *selected = NULL;
    1172             :         int prio;
    1173        6161 :         struct wpa_ssid *next_ssid = NULL;
    1174             :         struct wpa_ssid *ssid;
    1175             : 
    1176       12294 :         if (wpa_s->last_scan_res == NULL ||
    1177        6133 :             wpa_s->last_scan_res_used == 0)
    1178         345 :                 return NULL; /* no scan results from last update */
    1179             : 
    1180        5816 :         if (wpa_s->next_ssid) {
    1181             :                 /* check that next_ssid is still valid */
    1182         123 :                 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
    1183         123 :                         if (ssid == wpa_s->next_ssid)
    1184         113 :                                 break;
    1185             :                 }
    1186         113 :                 next_ssid = ssid;
    1187         113 :                 wpa_s->next_ssid = NULL;
    1188             :         }
    1189             : 
    1190       17069 :         while (selected == NULL) {
    1191        6866 :                 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
    1192        5922 :                         if (next_ssid && next_ssid->priority ==
    1193         123 :                             wpa_s->conf->pssid[prio]->priority) {
    1194         121 :                                 selected = wpa_supplicant_select_bss(
    1195             :                                         wpa_s, next_ssid, selected_ssid, 1);
    1196         121 :                                 if (selected)
    1197         112 :                                         break;
    1198             :                         }
    1199        5687 :                         selected = wpa_supplicant_select_bss(
    1200        5687 :                                 wpa_s, wpa_s->conf->pssid[prio],
    1201             :                                 selected_ssid, 0);
    1202        5687 :                         if (selected)
    1203        4981 :                                 break;
    1204             :                 }
    1205             : 
    1206        6505 :                 if (selected == NULL && wpa_s->blacklist &&
    1207         345 :                     !wpa_s->countermeasures) {
    1208         344 :                         wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
    1209             :                                 "blacklist and try again");
    1210         344 :                         wpa_blacklist_clear(wpa_s);
    1211         344 :                         wpa_s->blacklist_cleared++;
    1212        5816 :                 } else if (selected == NULL)
    1213         723 :                         break;
    1214             :         }
    1215             : 
    1216        5816 :         ssid = *selected_ssid;
    1217        5819 :         if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
    1218           6 :             !ssid->passphrase && !ssid->ext_psk) {
    1219           3 :                 const char *field_name, *txt = NULL;
    1220             : 
    1221           3 :                 wpa_dbg(wpa_s, MSG_DEBUG,
    1222             :                         "PSK/passphrase not yet available for the selected network");
    1223             : 
    1224           3 :                 wpas_notify_network_request(wpa_s, ssid,
    1225             :                                             WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
    1226             : 
    1227           3 :                 field_name = wpa_supplicant_ctrl_req_to_string(
    1228             :                         WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
    1229           3 :                 if (field_name == NULL)
    1230           0 :                         return NULL;
    1231             : 
    1232           3 :                 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
    1233             : 
    1234           3 :                 selected = NULL;
    1235             :         }
    1236             : 
    1237        5816 :         return selected;
    1238             : }
    1239             : 
    1240             : 
    1241         920 : static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
    1242             :                                         int timeout_sec, int timeout_usec)
    1243             : {
    1244         920 :         if (!wpa_supplicant_enabled_networks(wpa_s)) {
    1245             :                 /*
    1246             :                  * No networks are enabled; short-circuit request so
    1247             :                  * we don't wait timeout seconds before transitioning
    1248             :                  * to INACTIVE state.
    1249             :                  */
    1250         559 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
    1251             :                         "since there are no enabled networks");
    1252         559 :                 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
    1253        1479 :                 return;
    1254             :         }
    1255             : 
    1256         361 :         wpa_s->scan_for_connection = 1;
    1257         361 :         wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
    1258             : }
    1259             : 
    1260             : 
    1261        4859 : int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
    1262             :                            struct wpa_bss *selected,
    1263             :                            struct wpa_ssid *ssid)
    1264             : {
    1265        4859 :         if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
    1266           4 :                 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
    1267             :                         "PBC session overlap");
    1268           4 :                 wpas_notify_wps_event_pbc_overlap(wpa_s);
    1269             : #ifdef CONFIG_P2P
    1270           7 :                 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
    1271           3 :                     wpa_s->p2p_in_provisioning) {
    1272           2 :                         eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
    1273             :                                                wpa_s, NULL);
    1274           2 :                         return -1;
    1275             :                 }
    1276             : #endif /* CONFIG_P2P */
    1277             : 
    1278             : #ifdef CONFIG_WPS
    1279           2 :                 wpas_wps_pbc_overlap(wpa_s);
    1280           2 :                 wpas_wps_cancel(wpa_s);
    1281             : #endif /* CONFIG_WPS */
    1282           2 :                 return -1;
    1283             :         }
    1284             : 
    1285       92245 :         wpa_msg(wpa_s, MSG_DEBUG,
    1286             :                 "Considering connect request: reassociate: %d  selected: "
    1287             :                 MACSTR "  bssid: " MACSTR "  pending: " MACSTR
    1288             :                 "  wpa_state: %s  ssid=%p  current_ssid=%p",
    1289       29130 :                 wpa_s->reassociate, MAC2STR(selected->bssid),
    1290       58260 :                 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
    1291             :                 wpa_supplicant_state_txt(wpa_s->wpa_state),
    1292             :                 ssid, wpa_s->current_ssid);
    1293             : 
    1294             :         /*
    1295             :          * Do not trigger new association unless the BSSID has changed or if
    1296             :          * reassociation is requested. If we are in process of associating with
    1297             :          * the selected BSSID, do not trigger new attempt.
    1298             :          */
    1299        5024 :         if (wpa_s->reassociate ||
    1300         338 :             (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
    1301         338 :              ((wpa_s->wpa_state != WPA_ASSOCIATING &&
    1302         169 :                wpa_s->wpa_state != WPA_AUTHENTICATING) ||
    1303           0 :               (!is_zero_ether_addr(wpa_s->pending_bssid) &&
    1304           0 :                os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
    1305           0 :                0) ||
    1306           0 :               (is_zero_ether_addr(wpa_s->pending_bssid) &&
    1307           0 :                ssid != wpa_s->current_ssid)))) {
    1308        4855 :                 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
    1309           0 :                         wpa_supplicant_req_new_scan(wpa_s, 10, 0);
    1310           0 :                         return 0;
    1311             :                 }
    1312       29130 :                 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
    1313       29130 :                         MAC2STR(selected->bssid));
    1314        4855 :                 wpa_supplicant_associate(wpa_s, selected, ssid);
    1315             :         } else {
    1316           0 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
    1317             :                         "connect with the selected AP");
    1318             :         }
    1319             : 
    1320        4855 :         return 0;
    1321             : }
    1322             : 
    1323             : 
    1324             : static struct wpa_ssid *
    1325        1050 : wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
    1326             : {
    1327             :         int prio;
    1328             :         struct wpa_ssid *ssid;
    1329             : 
    1330        1484 :         for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
    1331        1033 :                 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
    1332             :                 {
    1333         599 :                         if (wpas_network_disabled(wpa_s, ssid))
    1334         122 :                                 continue;
    1335         930 :                         if (ssid->mode == IEEE80211_MODE_IBSS ||
    1336         867 :                             ssid->mode == IEEE80211_MODE_AP ||
    1337         414 :                             ssid->mode == IEEE80211_MODE_MESH)
    1338          63 :                                 return ssid;
    1339             :                 }
    1340             :         }
    1341         987 :         return NULL;
    1342             : }
    1343             : 
    1344             : 
    1345             : /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
    1346             :  * on BSS added and BSS changed events */
    1347        2000 : static void wpa_supplicant_rsn_preauth_scan_results(
    1348             :         struct wpa_supplicant *wpa_s)
    1349             : {
    1350             :         struct wpa_bss *bss;
    1351             : 
    1352        2000 :         if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
    1353        3732 :                 return;
    1354             : 
    1355         608 :         dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
    1356             :                 const u8 *ssid, *rsn;
    1357             : 
    1358         340 :                 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
    1359         340 :                 if (ssid == NULL)
    1360           0 :                         continue;
    1361             : 
    1362         340 :                 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
    1363         340 :                 if (rsn == NULL)
    1364         111 :                         continue;
    1365             : 
    1366         229 :                 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
    1367             :         }
    1368             : 
    1369             : }
    1370             : 
    1371             : 
    1372        4750 : static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
    1373             :                                        struct wpa_bss *selected,
    1374             :                                        struct wpa_ssid *ssid)
    1375             : {
    1376        4750 :         struct wpa_bss *current_bss = NULL;
    1377             : #ifndef CONFIG_NO_ROAMING
    1378             :         int min_diff;
    1379             :         int to_5ghz;
    1380             : #endif /* CONFIG_NO_ROAMING */
    1381             : 
    1382        4750 :         if (wpa_s->reassociate)
    1383        4500 :                 return 1; /* explicit request to reassociate */
    1384         250 :         if (wpa_s->wpa_state < WPA_ASSOCIATED)
    1385         162 :                 return 1; /* we are not associated; continue */
    1386          88 :         if (wpa_s->current_ssid == NULL)
    1387           0 :                 return 1; /* unknown current SSID */
    1388          88 :         if (wpa_s->current_ssid != ssid)
    1389           0 :                 return 1; /* different network block */
    1390             : 
    1391          88 :         if (wpas_driver_bss_selection(wpa_s))
    1392           0 :                 return 0; /* Driver-based roaming */
    1393             : 
    1394          88 :         if (wpa_s->current_ssid->ssid)
    1395         176 :                 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
    1396          88 :                                           wpa_s->current_ssid->ssid,
    1397          88 :                                           wpa_s->current_ssid->ssid_len);
    1398          88 :         if (!current_bss)
    1399           0 :                 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
    1400             : 
    1401          88 :         if (!current_bss)
    1402           0 :                 return 1; /* current BSS not seen in scan results */
    1403             : 
    1404          88 :         if (current_bss == selected)
    1405          75 :                 return 0;
    1406             : 
    1407          13 :         if (selected->last_update_idx > current_bss->last_update_idx)
    1408           0 :                 return 1; /* current BSS not seen in the last scan */
    1409             : 
    1410             : #ifndef CONFIG_NO_ROAMING
    1411          13 :         wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
    1412          13 :         wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
    1413             :                 " level=%d snr=%d est_throughput=%u",
    1414             :                 MAC2STR(current_bss->bssid), current_bss->level,
    1415             :                 current_bss->snr, current_bss->est_throughput);
    1416          13 :         wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
    1417             :                 " level=%d snr=%d est_throughput=%u",
    1418             :                 MAC2STR(selected->bssid), selected->level,
    1419             :                 selected->snr, selected->est_throughput);
    1420             : 
    1421          13 :         if (wpa_s->current_ssid->bssid_set &&
    1422           0 :             os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
    1423             :             0) {
    1424           0 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
    1425             :                         "has preferred BSSID");
    1426           0 :                 return 1;
    1427             :         }
    1428             : 
    1429          13 :         if (selected->est_throughput > current_bss->est_throughput + 5000) {
    1430           1 :                 wpa_dbg(wpa_s, MSG_DEBUG,
    1431             :                         "Allow reassociation - selected BSS has better estimated throughput");
    1432           1 :                 return 1;
    1433             :         }
    1434             : 
    1435          12 :         to_5ghz = selected->freq > 4000 && current_bss->freq < 4000;
    1436             : 
    1437          24 :         if (current_bss->level < 0 &&
    1438          12 :             current_bss->level > selected->level + to_5ghz * 2) {
    1439           0 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
    1440             :                         "signal level");
    1441           0 :                 return 0;
    1442             :         }
    1443             : 
    1444          12 :         min_diff = 2;
    1445          12 :         if (current_bss->level < 0) {
    1446          12 :                 if (current_bss->level < -85)
    1447           0 :                         min_diff = 1;
    1448          12 :                 else if (current_bss->level < -80)
    1449           0 :                         min_diff = 2;
    1450          12 :                 else if (current_bss->level < -75)
    1451           0 :                         min_diff = 3;
    1452          12 :                 else if (current_bss->level < -70)
    1453           0 :                         min_diff = 4;
    1454             :                 else
    1455          12 :                         min_diff = 5;
    1456             :         }
    1457          12 :         if (to_5ghz) {
    1458             :                 /* Make it easier to move to 5 GHz band */
    1459           1 :                 if (min_diff > 2)
    1460           1 :                         min_diff -= 2;
    1461             :                 else
    1462           0 :                         min_diff = 0;
    1463             :         }
    1464          12 :         if (abs(current_bss->level - selected->level) < min_diff) {
    1465          12 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
    1466             :                         "in signal level");
    1467          12 :                 return 0;
    1468             :         }
    1469             : 
    1470           0 :         return 1;
    1471             : #else /* CONFIG_NO_ROAMING */
    1472             :         return 0;
    1473             : #endif /* CONFIG_NO_ROAMING */
    1474             : }
    1475             : 
    1476             : 
    1477             : /* Return != 0 if no scan results could be fetched or if scan results should not
    1478             :  * be shared with other virtual interfaces. */
    1479        5640 : static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
    1480             :                                               union wpa_event_data *data,
    1481             :                                               int own_request)
    1482             : {
    1483        5640 :         struct wpa_scan_results *scan_res = NULL;
    1484        5640 :         int ret = 0;
    1485        5640 :         int ap = 0;
    1486             : #ifndef CONFIG_NO_RANDOM_POOL
    1487             :         size_t i, num;
    1488             : #endif /* CONFIG_NO_RANDOM_POOL */
    1489             : 
    1490             : #ifdef CONFIG_AP
    1491        5640 :         if (wpa_s->ap_iface)
    1492          11 :                 ap = 1;
    1493             : #endif /* CONFIG_AP */
    1494             : 
    1495        5640 :         wpa_supplicant_notify_scanning(wpa_s, 0);
    1496             : 
    1497        5640 :         scan_res = wpa_supplicant_get_scan_results(wpa_s,
    1498             :                                                    data ? &data->scan_info :
    1499             :                                                    NULL, 1);
    1500        5640 :         if (scan_res == NULL) {
    1501           2 :                 if (wpa_s->conf->ap_scan == 2 || ap ||
    1502           1 :                     wpa_s->scan_res_handler == scan_only_handler)
    1503           0 :                         return -1;
    1504           1 :                 if (!own_request)
    1505           0 :                         return -1;
    1506           1 :                 if (data && data->scan_info.external_scan)
    1507           0 :                         return -1;
    1508           1 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
    1509             :                         "scanning again");
    1510           1 :                 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
    1511           1 :                 ret = -1;
    1512           1 :                 goto scan_work_done;
    1513             :         }
    1514             : 
    1515             : #ifndef CONFIG_NO_RANDOM_POOL
    1516             :         num = scan_res->num;
    1517             :         if (num > 10)
    1518             :                 num = 10;
    1519             :         for (i = 0; i < num; i++) {
    1520             :                 u8 buf[5];
    1521             :                 struct wpa_scan_res *res = scan_res->res[i];
    1522             :                 buf[0] = res->bssid[5];
    1523             :                 buf[1] = res->qual & 0xff;
    1524             :                 buf[2] = res->noise & 0xff;
    1525             :                 buf[3] = res->level & 0xff;
    1526             :                 buf[4] = res->tsf & 0xff;
    1527             :                 random_add_randomness(buf, sizeof(buf));
    1528             :         }
    1529             : #endif /* CONFIG_NO_RANDOM_POOL */
    1530             : 
    1531        5639 :         if (own_request && wpa_s->scan_res_handler &&
    1532        2546 :             !(data && data->scan_info.external_scan)) {
    1533             :                 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
    1534             :                                          struct wpa_scan_results *scan_res);
    1535             : 
    1536        2546 :                 scan_res_handler = wpa_s->scan_res_handler;
    1537        2546 :                 wpa_s->scan_res_handler = NULL;
    1538        2546 :                 scan_res_handler(wpa_s, scan_res);
    1539        2546 :                 ret = -2;
    1540        2546 :                 goto scan_work_done;
    1541             :         }
    1542             : 
    1543        3093 :         if (ap) {
    1544          11 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
    1545             : #ifdef CONFIG_AP
    1546          11 :                 if (wpa_s->ap_iface->scan_cb)
    1547          10 :                         wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
    1548             : #endif /* CONFIG_AP */
    1549          11 :                 goto scan_work_done;
    1550             :         }
    1551             : 
    1552        3082 :         wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
    1553             :                 wpa_s->own_scan_running,
    1554             :                 data ? data->scan_info.external_scan : 0);
    1555        3082 :         if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
    1556          31 :             wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
    1557          30 :             own_request && !(data && data->scan_info.external_scan)) {
    1558          30 :                 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
    1559             :                              wpa_s->manual_scan_id);
    1560          30 :                 wpa_s->manual_scan_use_id = 0;
    1561             :         } else {
    1562        3052 :                 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
    1563             :         }
    1564        3082 :         wpas_notify_scan_results(wpa_s);
    1565             : 
    1566        3082 :         wpas_notify_scan_done(wpa_s, 1);
    1567             : 
    1568        3082 :         if (data && data->scan_info.external_scan) {
    1569          13 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
    1570          13 :                 wpa_scan_results_free(scan_res);
    1571          13 :                 return 0;
    1572             :         }
    1573             : 
    1574        3069 :         if (wnm_scan_process(wpa_s, 1) > 0)
    1575           1 :                 goto scan_work_done;
    1576             : 
    1577        3068 :         if (sme_proc_obss_scan(wpa_s) > 0)
    1578           5 :                 goto scan_work_done;
    1579             : 
    1580        3063 :         if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
    1581           1 :                 goto scan_work_done;
    1582             : 
    1583        3062 :         if (autoscan_notify_scan(wpa_s, scan_res))
    1584           0 :                 goto scan_work_done;
    1585             : 
    1586        3062 :         if (wpa_s->disconnected) {
    1587         113 :                 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
    1588         113 :                 goto scan_work_done;
    1589             :         }
    1590             : 
    1591        5896 :         if (!wpas_driver_bss_selection(wpa_s) &&
    1592        2947 :             bgscan_notify_scan(wpa_s, scan_res) == 1)
    1593           0 :                 goto scan_work_done;
    1594             : 
    1595        2949 :         wpas_wps_update_ap_info(wpa_s, scan_res);
    1596             : 
    1597        3048 :         if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
    1598          99 :             wpa_s->wpa_state < WPA_COMPLETED)
    1599           0 :                 goto scan_work_done;
    1600             : 
    1601        2949 :         wpa_scan_results_free(scan_res);
    1602             : 
    1603        2949 :         if (own_request && wpa_s->scan_work) {
    1604        2905 :                 struct wpa_radio_work *work = wpa_s->scan_work;
    1605        2905 :                 wpa_s->scan_work = NULL;
    1606        2905 :                 radio_work_done(work);
    1607             :         }
    1608             : 
    1609        2949 :         return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
    1610             : 
    1611             : scan_work_done:
    1612        2678 :         wpa_scan_results_free(scan_res);
    1613        2678 :         if (own_request && wpa_s->scan_work) {
    1614         365 :                 struct wpa_radio_work *work = wpa_s->scan_work;
    1615         365 :                 wpa_s->scan_work = NULL;
    1616         365 :                 radio_work_done(work);
    1617             :         }
    1618        2678 :         return ret;
    1619             : }
    1620             : 
    1621             : 
    1622        5831 : static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
    1623             :                                               int new_scan, int own_request)
    1624             : {
    1625             :         struct wpa_bss *selected;
    1626        5831 :         struct wpa_ssid *ssid = NULL;
    1627        5831 :         int time_to_reenable = wpas_reenabled_network_time(wpa_s);
    1628             : 
    1629        5831 :         if (time_to_reenable > 0) {
    1630          14 :                 wpa_dbg(wpa_s, MSG_DEBUG,
    1631             :                         "Postpone network selection by %d seconds since all networks are disabled",
    1632             :                         time_to_reenable);
    1633          14 :                 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
    1634          14 :                 eloop_register_timeout(time_to_reenable, 0,
    1635             :                                        wpas_network_reenabled, wpa_s, NULL);
    1636          14 :                 return 0;
    1637             :         }
    1638             : 
    1639        5817 :         if (wpa_s->p2p_mgmt)
    1640          10 :                 return 0; /* no normal connection on p2p_mgmt interface */
    1641             : 
    1642        5807 :         selected = wpa_supplicant_pick_network(wpa_s, &ssid);
    1643             : 
    1644             : #ifdef CONFIG_MESH
    1645        5807 :         if (wpa_s->ifmsh) {
    1646           7 :                 wpa_msg(wpa_s, MSG_INFO,
    1647             :                         "Avoiding join because we already joined a mesh group");
    1648           7 :                 return 0;
    1649             :         }
    1650             : #endif /* CONFIG_MESH */
    1651             : 
    1652        5800 :         if (selected) {
    1653             :                 int skip;
    1654        4750 :                 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
    1655        4750 :                 if (skip) {
    1656          87 :                         if (new_scan)
    1657          87 :                                 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
    1658          87 :                         return 0;
    1659             :                 }
    1660             : 
    1661        5882 :                 if (ssid != wpa_s->current_ssid &&
    1662        1219 :                     wpa_s->wpa_state >= WPA_AUTHENTICATING) {
    1663           0 :                         wpa_s->own_disconnect_req = 1;
    1664           0 :                         wpa_supplicant_deauthenticate(
    1665             :                                 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
    1666             :                 }
    1667             : 
    1668        4663 :                 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
    1669           4 :                         wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
    1670           4 :                         return -1;
    1671             :                 }
    1672        4659 :                 if (new_scan)
    1673        1858 :                         wpa_supplicant_rsn_preauth_scan_results(wpa_s);
    1674             :                 /*
    1675             :                  * Do not notify other virtual radios of scan results since we do not
    1676             :                  * want them to start other associations at the same time.
    1677             :                  */
    1678        4659 :                 return 1;
    1679             :         } else {
    1680        1050 :                 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
    1681        1050 :                 ssid = wpa_supplicant_pick_new_network(wpa_s);
    1682        1050 :                 if (ssid) {
    1683          63 :                         wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
    1684          63 :                         wpa_supplicant_associate(wpa_s, NULL, ssid);
    1685          63 :                         if (new_scan)
    1686          55 :                                 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
    1687         987 :                 } else if (own_request) {
    1688             :                         /*
    1689             :                          * No SSID found. If SCAN results are as a result of
    1690             :                          * own scan request and not due to a scan request on
    1691             :                          * another shared interface, try another scan.
    1692             :                          */
    1693         962 :                         int timeout_sec = wpa_s->scan_interval;
    1694         962 :                         int timeout_usec = 0;
    1695             : #ifdef CONFIG_P2P
    1696             :                         int res;
    1697             : 
    1698         962 :                         res = wpas_p2p_scan_no_go_seen(wpa_s);
    1699         962 :                         if (res == 2)
    1700           1 :                                 return 2;
    1701         961 :                         if (res == 1)
    1702           0 :                                 return 0;
    1703             : 
    1704        1842 :                         if (wpa_s->p2p_in_provisioning ||
    1705        1697 :                             wpa_s->show_group_started ||
    1706         816 :                             wpa_s->p2p_in_invitation) {
    1707             :                                 /*
    1708             :                                  * Use shorter wait during P2P Provisioning
    1709             :                                  * state and during P2P join-a-group operation
    1710             :                                  * to speed up group formation.
    1711             :                                  */
    1712         145 :                                 timeout_sec = 0;
    1713         145 :                                 timeout_usec = 250000;
    1714         145 :                                 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
    1715             :                                                             timeout_usec);
    1716         145 :                                 return 0;
    1717             :                         }
    1718             : #endif /* CONFIG_P2P */
    1719             : #ifdef CONFIG_INTERWORKING
    1720         858 :                         if (wpa_s->conf->auto_interworking &&
    1721          84 :                             wpa_s->conf->interworking &&
    1722          42 :                             wpa_s->conf->cred) {
    1723          42 :                                 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
    1724             :                                         "start ANQP fetch since no matching "
    1725             :                                         "networks found");
    1726          42 :                                 wpa_s->network_select = 1;
    1727          42 :                                 wpa_s->auto_network_select = 1;
    1728          42 :                                 interworking_start_fetch_anqp(wpa_s);
    1729          42 :                                 return 1;
    1730             :                         }
    1731             : #endif /* CONFIG_INTERWORKING */
    1732             : #ifdef CONFIG_WPS
    1733         774 :                         if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
    1734         108 :                                 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
    1735         108 :                                 timeout_sec = 0;
    1736         108 :                                 timeout_usec = 500000;
    1737         108 :                                 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
    1738             :                                                             timeout_usec);
    1739         108 :                                 return 0;
    1740             :                         }
    1741             : #endif /* CONFIG_WPS */
    1742         666 :                         if (wpa_supplicant_req_sched_scan(wpa_s))
    1743         666 :                                 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
    1744             :                                                             timeout_usec);
    1745             : 
    1746         666 :                         wpa_msg_ctrl(wpa_s, MSG_INFO,
    1747             :                                      WPA_EVENT_NETWORK_NOT_FOUND);
    1748             :                 }
    1749             :         }
    1750         754 :         return 0;
    1751             : }
    1752             : 
    1753             : 
    1754        5602 : static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
    1755             :                                              union wpa_event_data *data)
    1756             : {
    1757             :         struct wpa_supplicant *ifs;
    1758             :         int res;
    1759             : 
    1760        5602 :         res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
    1761        5602 :         if (res == 2) {
    1762             :                 /*
    1763             :                  * Interface may have been removed, so must not dereference
    1764             :                  * wpa_s after this.
    1765             :                  */
    1766           1 :                 return 1;
    1767             :         }
    1768        5601 :         if (res != 0) {
    1769             :                 /*
    1770             :                  * If no scan results could be fetched, then no need to
    1771             :                  * notify those interfaces that did not actually request
    1772             :                  * this scan. Similarly, if scan results started a new operation on this
    1773             :                  * interface, do not notify other interfaces to avoid concurrent
    1774             :                  * operations during a connection attempt.
    1775             :                  */
    1776        4430 :                 return 0;
    1777             :         }
    1778             : 
    1779             :         /*
    1780             :          * Check other interfaces to see if they share the same radio. If
    1781             :          * so, they get updated with this same scan info.
    1782             :          */
    1783        2380 :         dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
    1784             :                          radio_list) {
    1785        1209 :                 if (ifs != wpa_s) {
    1786          38 :                         wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
    1787          38 :                                    "sibling", ifs->ifname);
    1788          38 :                         _wpa_supplicant_event_scan_results(ifs, data, 0);
    1789             :                 }
    1790             :         }
    1791             : 
    1792        1171 :         return 0;
    1793             : }
    1794             : 
    1795             : #endif /* CONFIG_NO_SCAN_PROCESSING */
    1796             : 
    1797             : 
    1798        4087 : int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
    1799             : {
    1800             : #ifdef CONFIG_NO_SCAN_PROCESSING
    1801             :         return -1;
    1802             : #else /* CONFIG_NO_SCAN_PROCESSING */
    1803             :         struct os_reltime now;
    1804             : 
    1805        4087 :         if (wpa_s->last_scan_res_used == 0)
    1806        1131 :                 return -1;
    1807             : 
    1808        2956 :         os_get_reltime(&now);
    1809        2956 :         if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
    1810          74 :                 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
    1811          74 :                 return -1;
    1812             :         }
    1813             : 
    1814        2882 :         return wpas_select_network_from_last_scan(wpa_s, 0, 1);
    1815             : #endif /* CONFIG_NO_SCAN_PROCESSING */
    1816             : }
    1817             : 
    1818             : #ifdef CONFIG_WNM
    1819             : 
    1820          21 : static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
    1821             : {
    1822          21 :         struct wpa_supplicant *wpa_s = eloop_ctx;
    1823             : 
    1824          21 :         if (wpa_s->wpa_state < WPA_ASSOCIATED)
    1825          21 :                 return;
    1826             : 
    1827          21 :         if (!wpa_s->no_keep_alive) {
    1828          18 :                 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
    1829          18 :                            MAC2STR(wpa_s->bssid));
    1830             :                 /* TODO: could skip this if normal data traffic has been sent */
    1831             :                 /* TODO: Consider using some more appropriate data frame for
    1832             :                  * this */
    1833           3 :                 if (wpa_s->l2)
    1834           3 :                         l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
    1835             :                                        (u8 *) "", 0);
    1836             :         }
    1837             : 
    1838             : #ifdef CONFIG_SME
    1839          21 :         if (wpa_s->sme.bss_max_idle_period) {
    1840             :                 unsigned int msec;
    1841          21 :                 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
    1842          21 :                 if (msec > 100)
    1843          21 :                         msec -= 100;
    1844          21 :                 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
    1845             :                                        wnm_bss_keep_alive, wpa_s, NULL);
    1846             :         }
    1847             : #endif /* CONFIG_SME */
    1848             : }
    1849             : 
    1850             : 
    1851        4753 : static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
    1852             :                                    const u8 *ies, size_t ies_len)
    1853             : {
    1854             :         struct ieee802_11_elems elems;
    1855             : 
    1856        4753 :         if (ies == NULL)
    1857           0 :                 return;
    1858             : 
    1859        4753 :         if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
    1860           0 :                 return;
    1861             : 
    1862             : #ifdef CONFIG_SME
    1863        4753 :         if (elems.bss_max_idle_period) {
    1864             :                 unsigned int msec;
    1865        4753 :                 wpa_s->sme.bss_max_idle_period =
    1866        4753 :                         WPA_GET_LE16(elems.bss_max_idle_period);
    1867        9506 :                 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
    1868        4753 :                            "TU)%s", wpa_s->sme.bss_max_idle_period,
    1869        4753 :                            (elems.bss_max_idle_period[2] & 0x01) ?
    1870             :                            " (protected keep-live required)" : "");
    1871        4753 :                 if (wpa_s->sme.bss_max_idle_period == 0)
    1872           0 :                         wpa_s->sme.bss_max_idle_period = 1;
    1873        4753 :                 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
    1874        4471 :                         eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
    1875             :                          /* msec times 1000 */
    1876        4471 :                         msec = wpa_s->sme.bss_max_idle_period * 1024;
    1877        4471 :                         if (msec > 100)
    1878        4471 :                                 msec -= 100;
    1879        4471 :                         eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
    1880             :                                                wnm_bss_keep_alive, wpa_s,
    1881             :                                                NULL);
    1882             :                 }
    1883             :         }
    1884             : #endif /* CONFIG_SME */
    1885             : }
    1886             : 
    1887             : #endif /* CONFIG_WNM */
    1888             : 
    1889             : 
    1890       11131 : void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
    1891             : {
    1892             : #ifdef CONFIG_WNM
    1893       11131 :         eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
    1894             : #endif /* CONFIG_WNM */
    1895       11131 : }
    1896             : 
    1897             : 
    1898             : #ifdef CONFIG_INTERWORKING
    1899             : 
    1900           2 : static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
    1901             :                             size_t len)
    1902             : {
    1903             :         int res;
    1904             : 
    1905           2 :         wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
    1906           2 :         res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
    1907           2 :         if (res) {
    1908           0 :                 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
    1909             :         }
    1910             : 
    1911           2 :         return res;
    1912             : }
    1913             : 
    1914             : 
    1915        4753 : static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
    1916             :                                             const u8 *ies, size_t ies_len)
    1917             : {
    1918             :         struct ieee802_11_elems elems;
    1919             : 
    1920        4753 :         if (ies == NULL)
    1921           0 :                 return;
    1922             : 
    1923        4753 :         if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
    1924           0 :                 return;
    1925             : 
    1926        4753 :         if (elems.qos_map_set) {
    1927           1 :                 wpas_qos_map_set(wpa_s, elems.qos_map_set,
    1928           1 :                                  elems.qos_map_set_len);
    1929             :         }
    1930             : }
    1931             : 
    1932             : #endif /* CONFIG_INTERWORKING */
    1933             : 
    1934             : 
    1935             : #ifdef CONFIG_FST
    1936       22918 : static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
    1937             :                                 const u8 *ie, size_t ie_len)
    1938             : {
    1939             :         struct mb_ies_info mb_ies;
    1940             : 
    1941       22918 :         if (!ie || !ie_len || !wpa_s->fst)
    1942       22650 :             return -ENOENT;
    1943             : 
    1944         268 :         os_memset(&mb_ies, 0, sizeof(mb_ies));
    1945             : 
    1946        2580 :         while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
    1947             :                 size_t len;
    1948             : 
    1949        2044 :                 len = 2 + ie[1];
    1950        2044 :                 if (len > ie_len) {
    1951           0 :                         wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
    1952             :                                     ie, ie_len);
    1953           0 :                         break;
    1954             :                 }
    1955             : 
    1956        2044 :                 if (ie[0] == WLAN_EID_MULTI_BAND) {
    1957         244 :                         wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
    1958             :                                    (unsigned int) len);
    1959         244 :                         mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
    1960         244 :                         mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
    1961         244 :                         mb_ies.nof_ies++;
    1962             :                 }
    1963             : 
    1964        2044 :                 ie_len -= len;
    1965        2044 :                 ie += len;
    1966             :         }
    1967             : 
    1968         268 :         if (mb_ies.nof_ies > 0) {
    1969         244 :                 wpabuf_free(wpa_s->received_mb_ies);
    1970         244 :                 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
    1971         244 :                 return 0;
    1972             :         }
    1973             : 
    1974          24 :         return -ENOENT;
    1975             : }
    1976             : #endif /* CONFIG_FST */
    1977             : 
    1978             : 
    1979        4782 : static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
    1980             :                                           union wpa_event_data *data)
    1981             : {
    1982        4782 :         int l, len, found = 0, wpa_found, rsn_found;
    1983             :         const u8 *p;
    1984             : #ifdef CONFIG_IEEE80211R
    1985             :         u8 bssid[ETH_ALEN];
    1986             : #endif /* CONFIG_IEEE80211R */
    1987             : 
    1988        4782 :         wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
    1989        4782 :         if (data->assoc_info.req_ies)
    1990           0 :                 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
    1991             :                             data->assoc_info.req_ies_len);
    1992        4782 :         if (data->assoc_info.resp_ies) {
    1993        4753 :                 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
    1994             :                             data->assoc_info.resp_ies_len);
    1995             : #ifdef CONFIG_TDLS
    1996        4753 :                 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
    1997             :                                         data->assoc_info.resp_ies_len);
    1998             : #endif /* CONFIG_TDLS */
    1999             : #ifdef CONFIG_WNM
    2000        4753 :                 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
    2001             :                                        data->assoc_info.resp_ies_len);
    2002             : #endif /* CONFIG_WNM */
    2003             : #ifdef CONFIG_INTERWORKING
    2004        4753 :                 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
    2005             :                                                 data->assoc_info.resp_ies_len);
    2006             : #endif /* CONFIG_INTERWORKING */
    2007             :         }
    2008        4782 :         if (data->assoc_info.beacon_ies)
    2009           0 :                 wpa_hexdump(MSG_DEBUG, "beacon_ies",
    2010           0 :                             data->assoc_info.beacon_ies,
    2011             :                             data->assoc_info.beacon_ies_len);
    2012        4782 :         if (data->assoc_info.freq)
    2013        4764 :                 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
    2014             :                         data->assoc_info.freq);
    2015             : 
    2016        4782 :         p = data->assoc_info.req_ies;
    2017        4782 :         l = data->assoc_info.req_ies_len;
    2018             : 
    2019             :         /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
    2020        9564 :         while (p && l >= 2) {
    2021           0 :                 len = p[1] + 2;
    2022           0 :                 if (len > l) {
    2023           0 :                         wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
    2024             :                                     p, l);
    2025           0 :                         break;
    2026             :                 }
    2027           0 :                 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
    2028           0 :                      (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
    2029           0 :                     (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 &&
    2030           0 :                      (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) ||
    2031           0 :                     (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
    2032           0 :                         if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
    2033           0 :                                 break;
    2034           0 :                         found = 1;
    2035           0 :                         wpa_find_assoc_pmkid(wpa_s);
    2036           0 :                         break;
    2037             :                 }
    2038           0 :                 l -= len;
    2039           0 :                 p += len;
    2040             :         }
    2041        4782 :         if (!found && data->assoc_info.req_ies)
    2042           0 :                 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
    2043             : 
    2044             : #ifdef CONFIG_IEEE80211R
    2045             : #ifdef CONFIG_SME
    2046        4782 :         if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
    2047         454 :                 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
    2048         227 :                     wpa_ft_validate_reassoc_resp(wpa_s->wpa,
    2049             :                                                  data->assoc_info.resp_ies,
    2050             :                                                  data->assoc_info.resp_ies_len,
    2051             :                                                  bssid) < 0) {
    2052           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
    2053             :                                 "Reassociation Response failed");
    2054           0 :                         wpa_supplicant_deauthenticate(
    2055             :                                 wpa_s, WLAN_REASON_INVALID_IE);
    2056           0 :                         return -1;
    2057             :                 }
    2058             :         }
    2059             : 
    2060        4782 :         p = data->assoc_info.resp_ies;
    2061        4782 :         l = data->assoc_info.resp_ies_len;
    2062             : 
    2063             : #ifdef CONFIG_WPS_STRICT
    2064             :         if (p && wpa_s->current_ssid &&
    2065             :             wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
    2066             :                 struct wpabuf *wps;
    2067             :                 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
    2068             :                 if (wps == NULL) {
    2069             :                         wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
    2070             :                                 "include WPS IE in (Re)Association Response");
    2071             :                         return -1;
    2072             :                 }
    2073             : 
    2074             :                 if (wps_validate_assoc_resp(wps) < 0) {
    2075             :                         wpabuf_free(wps);
    2076             :                         wpa_supplicant_deauthenticate(
    2077             :                                 wpa_s, WLAN_REASON_INVALID_IE);
    2078             :                         return -1;
    2079             :                 }
    2080             :                 wpabuf_free(wps);
    2081             :         }
    2082             : #endif /* CONFIG_WPS_STRICT */
    2083             : 
    2084             :         /* Go through the IEs and make a copy of the MDIE, if present. */
    2085       42261 :         while (p && l >= 2) {
    2086       32975 :                 len = p[1] + 2;
    2087       32975 :                 if (len > l) {
    2088           0 :                         wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
    2089             :                                     p, l);
    2090           0 :                         break;
    2091             :                 }
    2092       33253 :                 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
    2093         278 :                     p[1] >= MOBILITY_DOMAIN_ID_LEN) {
    2094         278 :                         wpa_s->sme.ft_used = 1;
    2095         278 :                         os_memcpy(wpa_s->sme.mobility_domain, p + 2,
    2096             :                                   MOBILITY_DOMAIN_ID_LEN);
    2097         278 :                         break;
    2098             :                 }
    2099       32697 :                 l -= len;
    2100       32697 :                 p += len;
    2101             :         }
    2102             : #endif /* CONFIG_SME */
    2103             : 
    2104             :         /* Process FT when SME is in the driver */
    2105        5064 :         if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
    2106         282 :             wpa_ft_is_completed(wpa_s->wpa)) {
    2107           0 :                 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
    2108           0 :                     wpa_ft_validate_reassoc_resp(wpa_s->wpa,
    2109             :                                                  data->assoc_info.resp_ies,
    2110             :                                                  data->assoc_info.resp_ies_len,
    2111             :                                                  bssid) < 0) {
    2112           0 :                         wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
    2113             :                                 "Reassociation Response failed");
    2114           0 :                         wpa_supplicant_deauthenticate(
    2115             :                                 wpa_s, WLAN_REASON_INVALID_IE);
    2116           0 :                         return -1;
    2117             :                 }
    2118           0 :                 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
    2119             :         }
    2120             : 
    2121        4782 :         wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
    2122             :                              data->assoc_info.resp_ies_len);
    2123             : #endif /* CONFIG_IEEE80211R */
    2124             : 
    2125             :         /* WPA/RSN IE from Beacon/ProbeResp */
    2126        4782 :         p = data->assoc_info.beacon_ies;
    2127        4782 :         l = data->assoc_info.beacon_ies_len;
    2128             : 
    2129             :         /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
    2130             :          */
    2131        4782 :         wpa_found = rsn_found = 0;
    2132        9564 :         while (p && l >= 2) {
    2133           0 :                 len = p[1] + 2;
    2134           0 :                 if (len > l) {
    2135           0 :                         wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
    2136             :                                     p, l);
    2137           0 :                         break;
    2138             :                 }
    2139           0 :                 if (!wpa_found &&
    2140           0 :                     p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
    2141           0 :                     os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
    2142           0 :                         wpa_found = 1;
    2143           0 :                         wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
    2144             :                 }
    2145             : 
    2146           0 :                 if (!rsn_found &&
    2147           0 :                     p[0] == WLAN_EID_RSN && p[1] >= 2) {
    2148           0 :                         rsn_found = 1;
    2149           0 :                         wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
    2150             :                 }
    2151             : 
    2152           0 :                 l -= len;
    2153           0 :                 p += len;
    2154             :         }
    2155             : 
    2156        4782 :         if (!wpa_found && data->assoc_info.beacon_ies)
    2157           0 :                 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
    2158        4782 :         if (!rsn_found && data->assoc_info.beacon_ies)
    2159           0 :                 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
    2160        4782 :         if (wpa_found || rsn_found)
    2161           0 :                 wpa_s->ap_ies_from_associnfo = 1;
    2162             : 
    2163        5116 :         if (wpa_s->assoc_freq && data->assoc_info.freq &&
    2164         334 :             wpa_s->assoc_freq != data->assoc_info.freq) {
    2165          10 :                 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
    2166             :                            "%u to %u MHz",
    2167             :                            wpa_s->assoc_freq, data->assoc_info.freq);
    2168          10 :                 wpa_supplicant_update_scan_results(wpa_s);
    2169             :         }
    2170             : 
    2171        4782 :         wpa_s->assoc_freq = data->assoc_info.freq;
    2172             : 
    2173        4782 :         return 0;
    2174             : }
    2175             : 
    2176             : 
    2177           2 : static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
    2178             : {
    2179           2 :         const u8 *bss_wpa = NULL, *bss_rsn = NULL;
    2180             : 
    2181           2 :         if (!wpa_s->current_bss || !wpa_s->current_ssid)
    2182           0 :                 return -1;
    2183             : 
    2184           2 :         if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
    2185           0 :                 return 0;
    2186             : 
    2187           2 :         bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
    2188             :                                         WPA_IE_VENDOR_TYPE);
    2189           2 :         bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
    2190             : 
    2191           2 :         if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
    2192           2 :                                  bss_wpa ? 2 + bss_wpa[1] : 0) ||
    2193           4 :             wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
    2194           2 :                                  bss_rsn ? 2 + bss_rsn[1] : 0))
    2195           0 :                 return -1;
    2196             : 
    2197           2 :         return 0;
    2198             : }
    2199             : 
    2200             : 
    2201        4777 : static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
    2202             :                                      union wpa_event_data *data)
    2203             : {
    2204             : #ifdef CONFIG_FST
    2205        4777 :         struct assoc_info *ai = data ? &data->assoc_info : NULL;
    2206        4777 :         struct wpa_bss *bss = wpa_s->current_bss;
    2207             :         const u8 *ieprb, *iebcn;
    2208             : 
    2209        4777 :         wpabuf_free(wpa_s->received_mb_ies);
    2210        4777 :         wpa_s->received_mb_ies = NULL;
    2211             : 
    2212        9540 :         if (ai &&
    2213        4763 :             !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
    2214         244 :                 wpa_printf(MSG_DEBUG,
    2215             :                            "FST: MB IEs updated from Association Response frame");
    2216         244 :                 return;
    2217             :         }
    2218             : 
    2219        9052 :         if (ai &&
    2220        4519 :             !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
    2221           0 :                 wpa_printf(MSG_DEBUG,
    2222             :                            "FST: MB IEs updated from association event Beacon IEs");
    2223           0 :                 return;
    2224             :         }
    2225             : 
    2226        4533 :         if (!bss)
    2227           0 :                 return;
    2228             : 
    2229        4533 :         ieprb = (const u8 *) (bss + 1);
    2230        4533 :         iebcn = ieprb + bss->ie_len;
    2231             : 
    2232        4533 :         if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
    2233           0 :                 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
    2234        4533 :         else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
    2235           0 :                 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
    2236             : #endif /* CONFIG_FST */
    2237             : }
    2238             : 
    2239             : 
    2240        4782 : static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
    2241             :                                        union wpa_event_data *data)
    2242             : {
    2243             :         u8 bssid[ETH_ALEN];
    2244             :         int ft_completed, already_authorized;
    2245        4782 :         int new_bss = 0;
    2246             : 
    2247             : #ifdef CONFIG_AP
    2248        4782 :         if (wpa_s->ap_iface) {
    2249           0 :                 if (!data)
    2250           7 :                         return;
    2251           0 :                 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
    2252             :                                     data->assoc_info.addr,
    2253             :                                     data->assoc_info.req_ies,
    2254             :                                     data->assoc_info.req_ies_len,
    2255             :                                     data->assoc_info.reassoc);
    2256           0 :                 return;
    2257             :         }
    2258             : #endif /* CONFIG_AP */
    2259             : 
    2260        4782 :         eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
    2261             : 
    2262        4782 :         ft_completed = wpa_ft_is_completed(wpa_s->wpa);
    2263        4782 :         if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
    2264           0 :                 return;
    2265             : 
    2266        4782 :         if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
    2267           0 :                 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
    2268           0 :                 wpa_supplicant_deauthenticate(
    2269             :                         wpa_s, WLAN_REASON_DEAUTH_LEAVING);
    2270           0 :                 return;
    2271             :         }
    2272             : 
    2273        4782 :         wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
    2274        4782 :         if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
    2275        4781 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
    2276             :                         MACSTR, MAC2STR(bssid));
    2277        4781 :                 new_bss = 1;
    2278             :                 random_add_randomness(bssid, ETH_ALEN);
    2279        4781 :                 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
    2280        4781 :                 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
    2281        4781 :                 wpas_notify_bssid_changed(wpa_s);
    2282             : 
    2283        4781 :                 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
    2284        3795 :                         wpa_clear_keys(wpa_s, bssid);
    2285             :                 }
    2286        4781 :                 if (wpa_supplicant_select_config(wpa_s) < 0) {
    2287           5 :                         wpa_supplicant_deauthenticate(
    2288             :                                 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
    2289           5 :                         return;
    2290             :                 }
    2291             :         }
    2292             : 
    2293        9544 :         if (wpa_s->conf->ap_scan == 1 &&
    2294        4767 :             wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
    2295           2 :                 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
    2296           0 :                         wpa_msg(wpa_s, MSG_WARNING,
    2297             :                                 "WPA/RSN IEs not updated");
    2298             :         }
    2299             : 
    2300        4777 :         wpas_fst_update_mb_assoc(wpa_s, data);
    2301             : 
    2302             : #ifdef CONFIG_SME
    2303        4777 :         os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
    2304        4777 :         wpa_s->sme.prev_bssid_set = 1;
    2305        4777 :         wpa_s->sme.last_unprot_disconnect.sec = 0;
    2306             : #endif /* CONFIG_SME */
    2307             : 
    2308        4777 :         wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
    2309        4777 :         if (wpa_s->current_ssid) {
    2310             :                 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
    2311             :                  * initialized before association, but for other modes,
    2312             :                  * initialize PC/SC here, if the current configuration needs
    2313             :                  * smartcard or SIM/USIM. */
    2314        4777 :                 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
    2315             :         }
    2316        4777 :         wpa_sm_notify_assoc(wpa_s->wpa, bssid);
    2317        4777 :         if (wpa_s->l2)
    2318        4777 :                 l2_packet_notify_auth_start(wpa_s->l2);
    2319             : 
    2320        4777 :         already_authorized = data && data->assoc_info.authorized;
    2321             : 
    2322             :         /*
    2323             :          * Set portEnabled first to FALSE in order to get EAP state machine out
    2324             :          * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
    2325             :          * state machine may transit to AUTHENTICATING state based on obsolete
    2326             :          * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
    2327             :          * AUTHENTICATED without ever giving chance to EAP state machine to
    2328             :          * reset the state.
    2329             :          */
    2330        4777 :         if (!ft_completed && !already_authorized) {
    2331        4550 :                 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
    2332        4550 :                 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
    2333             :         }
    2334        4777 :         if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed ||
    2335             :             already_authorized)
    2336        1175 :                 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
    2337             :         /* 802.1X::portControl = Auto */
    2338        4777 :         eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
    2339        4777 :         wpa_s->eapol_received = 0;
    2340        8809 :         if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
    2341        8059 :             wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
    2342        8054 :             (wpa_s->current_ssid &&
    2343        4027 :              wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
    2344        1522 :                 if (wpa_s->current_ssid &&
    2345         766 :                     wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
    2346           5 :                     (wpa_s->drv_flags &
    2347             :                      WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
    2348             :                         /*
    2349             :                          * Set the key after having received joined-IBSS event
    2350             :                          * from the driver.
    2351             :                          */
    2352           5 :                         wpa_supplicant_set_wpa_none_key(wpa_s,
    2353             :                                                         wpa_s->current_ssid);
    2354             :                 }
    2355         761 :                 wpa_supplicant_cancel_auth_timeout(wpa_s);
    2356         761 :                 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
    2357        4016 :         } else if (!ft_completed) {
    2358             :                 /* Timeout for receiving the first EAPOL packet */
    2359        3789 :                 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
    2360             :         }
    2361        4777 :         wpa_supplicant_cancel_scan(wpa_s);
    2362             : 
    2363        4777 :         if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
    2364           0 :             wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
    2365             :                 /*
    2366             :                  * We are done; the driver will take care of RSN 4-way
    2367             :                  * handshake.
    2368             :                  */
    2369           0 :                 wpa_supplicant_cancel_auth_timeout(wpa_s);
    2370           0 :                 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
    2371           0 :                 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
    2372           0 :                 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
    2373        4777 :         } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
    2374           0 :                    wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
    2375             :                 /*
    2376             :                  * The driver will take care of RSN 4-way handshake, so we need
    2377             :                  * to allow EAPOL supplicant to complete its work without
    2378             :                  * waiting for WPA supplicant.
    2379             :                  */
    2380           0 :                 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
    2381        4777 :         } else if (ft_completed) {
    2382             :                 /*
    2383             :                  * FT protocol completed - make sure EAPOL state machine ends
    2384             :                  * up in authenticated.
    2385             :                  */
    2386         227 :                 wpa_supplicant_cancel_auth_timeout(wpa_s);
    2387         227 :                 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
    2388         227 :                 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
    2389         227 :                 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
    2390             :         }
    2391             : 
    2392        4777 :         wpa_s->last_eapol_matches_bssid = 0;
    2393             : 
    2394        4777 :         if (wpa_s->pending_eapol_rx) {
    2395             :                 struct os_reltime now, age;
    2396           2 :                 os_get_reltime(&now);
    2397           2 :                 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
    2398           4 :                 if (age.sec == 0 && age.usec < 100000 &&
    2399           2 :                     os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
    2400             :                     0) {
    2401           2 :                         wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
    2402             :                                 "frame that was received just before "
    2403             :                                 "association notification");
    2404           4 :                         wpa_supplicant_rx_eapol(
    2405           2 :                                 wpa_s, wpa_s->pending_eapol_rx_src,
    2406           2 :                                 wpabuf_head(wpa_s->pending_eapol_rx),
    2407           2 :                                 wpabuf_len(wpa_s->pending_eapol_rx));
    2408             :                 }
    2409           2 :                 wpabuf_free(wpa_s->pending_eapol_rx);
    2410           2 :                 wpa_s->pending_eapol_rx = NULL;
    2411             :         }
    2412             : 
    2413        8809 :         if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
    2414        4797 :              wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
    2415        1530 :             wpa_s->current_ssid &&
    2416         765 :             (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
    2417             :                 /* Set static WEP keys again */
    2418         758 :                 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
    2419             :         }
    2420             : 
    2421             : #ifdef CONFIG_IBSS_RSN
    2422        9554 :         if (wpa_s->current_ssid &&
    2423        4804 :             wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
    2424          43 :             wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
    2425          27 :             wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
    2426          11 :             wpa_s->ibss_rsn == NULL) {
    2427          11 :                 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
    2428          11 :                 if (!wpa_s->ibss_rsn) {
    2429           2 :                         wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
    2430           2 :                         wpa_supplicant_deauthenticate(
    2431             :                                 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
    2432           2 :                         return;
    2433             :                 }
    2434             : 
    2435           9 :                 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
    2436             :         }
    2437             : #endif /* CONFIG_IBSS_RSN */
    2438             : 
    2439        4775 :         wpas_wps_notify_assoc(wpa_s, bssid);
    2440             : 
    2441        4775 :         if (data) {
    2442        4761 :                 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
    2443             :                                     data->assoc_info.resp_ies_len,
    2444        4761 :                                     &data->assoc_info.wmm_params);
    2445             : 
    2446        4761 :                 if (wpa_s->reassoc_same_bss)
    2447          62 :                         wmm_ac_restore_tspecs(wpa_s);
    2448             :         }
    2449             : }
    2450             : 
    2451             : 
    2452          54 : static int disconnect_reason_recoverable(u16 reason_code)
    2453             : {
    2454         106 :         return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
    2455         106 :                 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
    2456             :                 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
    2457             : }
    2458             : 
    2459             : 
    2460        4982 : static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
    2461             :                                           u16 reason_code,
    2462             :                                           int locally_generated)
    2463             : {
    2464             :         const u8 *bssid;
    2465             : 
    2466        4982 :         if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
    2467             :                 /*
    2468             :                  * At least Host AP driver and a Prism3 card seemed to be
    2469             :                  * generating streams of disconnected events when configuring
    2470             :                  * IBSS for WPA-None. Ignore them for now.
    2471             :                  */
    2472        4987 :                 return;
    2473             :         }
    2474             : 
    2475        4977 :         bssid = wpa_s->bssid;
    2476        4977 :         if (is_zero_ether_addr(bssid))
    2477         392 :                 bssid = wpa_s->pending_bssid;
    2478             : 
    2479        5357 :         if (!is_zero_ether_addr(bssid) ||
    2480         380 :             wpa_s->wpa_state >= WPA_AUTHENTICATING) {
    2481       32179 :                 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
    2482             :                         " reason=%d%s",
    2483       27582 :                         MAC2STR(bssid), reason_code,
    2484             :                         locally_generated ? " locally_generated=1" : "");
    2485             :         }
    2486             : }
    2487             : 
    2488             : 
    2489        4937 : static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
    2490             :                                  int locally_generated)
    2491             : {
    2492        4993 :         if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
    2493          56 :             !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
    2494        4918 :                 return 0; /* Not in 4-way handshake with PSK */
    2495             : 
    2496             :         /*
    2497             :          * It looks like connection was lost while trying to go through PSK
    2498             :          * 4-way handshake. Filter out known disconnection cases that are caused
    2499             :          * by something else than PSK mismatch to avoid confusing reports.
    2500             :          */
    2501             : 
    2502          19 :         if (locally_generated) {
    2503          12 :                 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
    2504           2 :                         return 0;
    2505             :         }
    2506             : 
    2507          17 :         return 1;
    2508             : }
    2509             : 
    2510             : 
    2511        4942 : static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
    2512             :                                                  u16 reason_code,
    2513             :                                                  int locally_generated)
    2514             : {
    2515             :         const u8 *bssid;
    2516             :         int authenticating;
    2517             :         u8 prev_pending_bssid[ETH_ALEN];
    2518        4942 :         struct wpa_bss *fast_reconnect = NULL;
    2519        4942 :         struct wpa_ssid *fast_reconnect_ssid = NULL;
    2520             :         struct wpa_ssid *last_ssid;
    2521        4942 :         struct wpa_bss *curr = NULL;
    2522             : 
    2523        4942 :         authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
    2524        4942 :         os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
    2525             : 
    2526        4942 :         if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
    2527             :                 /*
    2528             :                  * At least Host AP driver and a Prism3 card seemed to be
    2529             :                  * generating streams of disconnected events when configuring
    2530             :                  * IBSS for WPA-None. Ignore them for now.
    2531             :                  */
    2532           5 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
    2533             :                         "IBSS/WPA-None mode");
    2534           5 :                 return;
    2535             :         }
    2536             : 
    2537        4937 :         if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
    2538           4 :             reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
    2539             :             locally_generated)
    2540             :                 /*
    2541             :                  * Remove the inactive AP (which is probably out of range) from
    2542             :                  * the BSS list after marking disassociation. In particular
    2543             :                  * mac80211-based drivers use the
    2544             :                  * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
    2545             :                  * locally generated disconnection events for cases where the
    2546             :                  * AP does not reply anymore.
    2547             :                  */
    2548           2 :                 curr = wpa_s->current_bss;
    2549             : 
    2550        4937 :         if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
    2551          17 :                 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
    2552             :                         "pre-shared key may be incorrect");
    2553          17 :                 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
    2554           1 :                         return; /* P2P group removed */
    2555          16 :                 wpas_auth_failed(wpa_s, "WRONG_KEY");
    2556             :         }
    2557        8454 :         if (!wpa_s->disconnected &&
    2558        3520 :             (!wpa_s->auto_reconnect_disabled ||
    2559           3 :              wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
    2560           1 :              wpas_wps_searching(wpa_s) ||
    2561           0 :              wpas_wps_reenable_networks_pending(wpa_s))) {
    2562        3518 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
    2563             :                         "reconnect (wps=%d/%d wpa_state=%d)",
    2564             :                         wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
    2565             :                         wpas_wps_searching(wpa_s),
    2566             :                         wpa_s->wpa_state);
    2567        8012 :                 if (wpa_s->wpa_state == WPA_COMPLETED &&
    2568        1952 :                     wpa_s->current_ssid &&
    2569        1949 :                     wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
    2570          54 :                     !locally_generated &&
    2571          54 :                     disconnect_reason_recoverable(reason_code)) {
    2572             :                         /*
    2573             :                          * It looks like the AP has dropped association with
    2574             :                          * us, but could allow us to get back in. Try to
    2575             :                          * reconnect to the same BSS without full scan to save
    2576             :                          * time for some common cases.
    2577             :                          */
    2578           6 :                         fast_reconnect = wpa_s->current_bss;
    2579           6 :                         fast_reconnect_ssid = wpa_s->current_ssid;
    2580        3512 :                 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
    2581        2633 :                         wpa_supplicant_req_scan(wpa_s, 0, 100000);
    2582             :                 else
    2583         879 :                         wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
    2584             :                                 "immediate scan");
    2585             :         } else {
    2586        1418 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
    2587             :                         "try to re-connect");
    2588        1418 :                 wpa_s->reassociate = 0;
    2589        1418 :                 wpa_s->disconnected = 1;
    2590        1418 :                 if (!wpa_s->pno)
    2591        1418 :                         wpa_supplicant_cancel_sched_scan(wpa_s);
    2592             :         }
    2593        4936 :         bssid = wpa_s->bssid;
    2594        4936 :         if (is_zero_ether_addr(bssid))
    2595         521 :                 bssid = wpa_s->pending_bssid;
    2596        4936 :         if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
    2597        3615 :                 wpas_connection_failed(wpa_s, bssid);
    2598        4936 :         wpa_sm_notify_disassoc(wpa_s->wpa);
    2599        4936 :         if (locally_generated)
    2600        4417 :                 wpa_s->disconnect_reason = -reason_code;
    2601             :         else
    2602         519 :                 wpa_s->disconnect_reason = reason_code;
    2603        4936 :         wpas_notify_disconnect_reason(wpa_s);
    2604        4936 :         if (wpa_supplicant_dynamic_keys(wpa_s)) {
    2605        4210 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
    2606        4210 :                 wpa_clear_keys(wpa_s, wpa_s->bssid);
    2607             :         }
    2608        4936 :         last_ssid = wpa_s->current_ssid;
    2609        4936 :         wpa_supplicant_mark_disassoc(wpa_s);
    2610             : 
    2611        4936 :         if (curr)
    2612           2 :                 wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
    2613             : 
    2614        4936 :         if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
    2615           7 :                 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
    2616           7 :                 wpa_s->current_ssid = last_ssid;
    2617             :         }
    2618             : 
    2619        4942 :         if (fast_reconnect &&
    2620          12 :             !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
    2621          12 :             !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
    2622           6 :             !disallowed_ssid(wpa_s, fast_reconnect->ssid,
    2623           6 :                              fast_reconnect->ssid_len) &&
    2624          11 :             !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
    2625           5 :             !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect->bssid)) {
    2626             : #ifndef CONFIG_NO_SCAN_PROCESSING
    2627           5 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
    2628          10 :                 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
    2629             :                                            fast_reconnect_ssid) < 0) {
    2630             :                         /* Recover through full scan */
    2631           0 :                         wpa_supplicant_req_scan(wpa_s, 0, 100000);
    2632             :                 }
    2633             : #endif /* CONFIG_NO_SCAN_PROCESSING */
    2634        4931 :         } else if (fast_reconnect) {
    2635             :                 /*
    2636             :                  * Could not reconnect to the same BSS due to network being
    2637             :                  * disabled. Use a new scan to match the alternative behavior
    2638             :                  * above, i.e., to continue automatic reconnection attempt in a
    2639             :                  * way that enforces disabled network rules.
    2640             :                  */
    2641           1 :                 wpa_supplicant_req_scan(wpa_s, 0, 100000);
    2642             :         }
    2643             : }
    2644             : 
    2645             : 
    2646             : #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
    2647             : void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
    2648             : {
    2649             :         struct wpa_supplicant *wpa_s = eloop_ctx;
    2650             : 
    2651             :         if (!wpa_s->pending_mic_error_report)
    2652             :                 return;
    2653             : 
    2654             :         wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
    2655             :         wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
    2656             :         wpa_s->pending_mic_error_report = 0;
    2657             : }
    2658             : #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
    2659             : 
    2660             : 
    2661             : static void
    2662           4 : wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
    2663             :                                          union wpa_event_data *data)
    2664             : {
    2665             :         int pairwise;
    2666             :         struct os_reltime t;
    2667             : 
    2668           4 :         wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
    2669           4 :         pairwise = (data && data->michael_mic_failure.unicast);
    2670           4 :         os_get_reltime(&t);
    2671           6 :         if ((wpa_s->last_michael_mic_error.sec &&
    2672           4 :              !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
    2673           2 :             wpa_s->pending_mic_error_report) {
    2674           2 :                 if (wpa_s->pending_mic_error_report) {
    2675             :                         /*
    2676             :                          * Send the pending MIC error report immediately since
    2677             :                          * we are going to start countermeasures and AP better
    2678             :                          * do the same.
    2679             :                          */
    2680           0 :                         wpa_sm_key_request(wpa_s->wpa, 1,
    2681             :                                            wpa_s->pending_mic_error_pairwise);
    2682             :                 }
    2683             : 
    2684             :                 /* Send the new MIC error report immediately since we are going
    2685             :                  * to start countermeasures and AP better do the same.
    2686             :                  */
    2687           2 :                 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
    2688             : 
    2689             :                 /* initialize countermeasures */
    2690           2 :                 wpa_s->countermeasures = 1;
    2691             : 
    2692           2 :                 wpa_blacklist_add(wpa_s, wpa_s->bssid);
    2693             : 
    2694           2 :                 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
    2695             : 
    2696             :                 /*
    2697             :                  * Need to wait for completion of request frame. We do not get
    2698             :                  * any callback for the message completion, so just wait a
    2699             :                  * short while and hope for the best. */
    2700           2 :                 os_sleep(0, 10000);
    2701             : 
    2702           2 :                 wpa_drv_set_countermeasures(wpa_s, 1);
    2703           2 :                 wpa_supplicant_deauthenticate(wpa_s,
    2704             :                                               WLAN_REASON_MICHAEL_MIC_FAILURE);
    2705           2 :                 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
    2706             :                                      wpa_s, NULL);
    2707           2 :                 eloop_register_timeout(60, 0,
    2708             :                                        wpa_supplicant_stop_countermeasures,
    2709             :                                        wpa_s, NULL);
    2710             :                 /* TODO: mark the AP rejected for 60 second. STA is
    2711             :                  * allowed to associate with another AP.. */
    2712             :         } else {
    2713             : #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
    2714             :                 if (wpa_s->mic_errors_seen) {
    2715             :                         /*
    2716             :                          * Reduce the effectiveness of Michael MIC error
    2717             :                          * reports as a means for attacking against TKIP if
    2718             :                          * more than one MIC failure is noticed with the same
    2719             :                          * PTK. We delay the transmission of the reports by a
    2720             :                          * random time between 0 and 60 seconds in order to
    2721             :                          * force the attacker wait 60 seconds before getting
    2722             :                          * the information on whether a frame resulted in a MIC
    2723             :                          * failure.
    2724             :                          */
    2725             :                         u8 rval[4];
    2726             :                         int sec;
    2727             : 
    2728             :                         if (os_get_random(rval, sizeof(rval)) < 0)
    2729             :                                 sec = os_random() % 60;
    2730             :                         else
    2731             :                                 sec = WPA_GET_BE32(rval) % 60;
    2732             :                         wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
    2733             :                                 "report %d seconds", sec);
    2734             :                         wpa_s->pending_mic_error_report = 1;
    2735             :                         wpa_s->pending_mic_error_pairwise = pairwise;
    2736             :                         eloop_cancel_timeout(
    2737             :                                 wpa_supplicant_delayed_mic_error_report,
    2738             :                                 wpa_s, NULL);
    2739             :                         eloop_register_timeout(
    2740             :                                 sec, os_random() % 1000000,
    2741             :                                 wpa_supplicant_delayed_mic_error_report,
    2742             :                                 wpa_s, NULL);
    2743             :                 } else {
    2744             :                         wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
    2745             :                 }
    2746             : #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
    2747           2 :                 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
    2748             : #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
    2749             :         }
    2750           4 :         wpa_s->last_michael_mic_error = t;
    2751           4 :         wpa_s->mic_errors_seen++;
    2752           4 : }
    2753             : 
    2754             : 
    2755             : #ifdef CONFIG_TERMINATE_ONLASTIF
    2756             : static int any_interfaces(struct wpa_supplicant *head)
    2757             : {
    2758             :         struct wpa_supplicant *wpa_s;
    2759             : 
    2760             :         for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
    2761             :                 if (!wpa_s->interface_removed)
    2762             :                         return 1;
    2763             :         return 0;
    2764             : }
    2765             : #endif /* CONFIG_TERMINATE_ONLASTIF */
    2766             : 
    2767             : 
    2768             : static void
    2769         223 : wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
    2770             :                                       union wpa_event_data *data)
    2771             : {
    2772         223 :         if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
    2773         239 :                 return;
    2774             : 
    2775         207 :         switch (data->interface_status.ievent) {
    2776             :         case EVENT_INTERFACE_ADDED:
    2777         164 :                 if (!wpa_s->interface_removed)
    2778         164 :                         break;
    2779           0 :                 wpa_s->interface_removed = 0;
    2780           0 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
    2781           0 :                 if (wpa_supplicant_driver_init(wpa_s) < 0) {
    2782           0 :                         wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
    2783             :                                 "driver after interface was added");
    2784             :                 }
    2785             : 
    2786             : #ifdef CONFIG_P2P
    2787           0 :                 if (!wpa_s->global->p2p &&
    2788           0 :                     !wpa_s->global->p2p_disabled &&
    2789           0 :                     !wpa_s->conf->p2p_disabled &&
    2790           0 :                     (wpa_s->drv_flags &
    2791           0 :                      WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
    2792           0 :                     wpas_p2p_add_p2pdev_interface(
    2793           0 :                             wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
    2794           0 :                         wpa_printf(MSG_INFO,
    2795             :                                    "P2P: Failed to enable P2P Device interface");
    2796             :                         /* Try to continue without. P2P will be disabled. */
    2797             :                 }
    2798             : #endif /* CONFIG_P2P */
    2799             : 
    2800           0 :                 break;
    2801             :         case EVENT_INTERFACE_REMOVED:
    2802          43 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
    2803          43 :                 wpa_s->interface_removed = 1;
    2804          43 :                 wpa_supplicant_mark_disassoc(wpa_s);
    2805          43 :                 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
    2806          43 :                 l2_packet_deinit(wpa_s->l2);
    2807          43 :                 wpa_s->l2 = NULL;
    2808             : 
    2809             : #ifdef CONFIG_P2P
    2810          86 :                 if (wpa_s->global->p2p &&
    2811          85 :                     wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
    2812          42 :                     (wpa_s->drv_flags &
    2813             :                      WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
    2814          27 :                         wpa_dbg(wpa_s, MSG_DEBUG,
    2815             :                                 "Removing P2P Device interface");
    2816          27 :                         wpa_supplicant_remove_iface(
    2817          27 :                                 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
    2818             :                                 0);
    2819          27 :                         wpa_s->global->p2p_init_wpa_s = NULL;
    2820             :                 }
    2821             : #endif /* CONFIG_P2P */
    2822             : 
    2823             : #ifdef CONFIG_MATCH_IFACE
    2824             :                 if (wpa_s->matched) {
    2825             :                         wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
    2826             :                         break;
    2827             :                 }
    2828             : #endif /* CONFIG_MATCH_IFACE */
    2829             : 
    2830             : #ifdef CONFIG_TERMINATE_ONLASTIF
    2831             :                 /* check if last interface */
    2832             :                 if (!any_interfaces(wpa_s->global->ifaces))
    2833             :                         eloop_terminate();
    2834             : #endif /* CONFIG_TERMINATE_ONLASTIF */
    2835          43 :                 break;
    2836             :         }
    2837             : }
    2838             : 
    2839             : 
    2840             : #ifdef CONFIG_PEERKEY
    2841             : static void
    2842           0 : wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
    2843             :                               union wpa_event_data *data)
    2844             : {
    2845           0 :         if (data == NULL)
    2846           0 :                 return;
    2847           0 :         wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
    2848             : }
    2849             : #endif /* CONFIG_PEERKEY */
    2850             : 
    2851             : 
    2852             : #ifdef CONFIG_TDLS
    2853           0 : static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
    2854             :                                       union wpa_event_data *data)
    2855             : {
    2856           0 :         if (data == NULL)
    2857           0 :                 return;
    2858           0 :         switch (data->tdls.oper) {
    2859             :         case TDLS_REQUEST_SETUP:
    2860           0 :                 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
    2861           0 :                 if (wpa_tdls_is_external_setup(wpa_s->wpa))
    2862           0 :                         wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
    2863             :                 else
    2864           0 :                         wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
    2865           0 :                 break;
    2866             :         case TDLS_REQUEST_TEARDOWN:
    2867           0 :                 if (wpa_tdls_is_external_setup(wpa_s->wpa))
    2868           0 :                         wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
    2869           0 :                                                data->tdls.reason_code);
    2870             :                 else
    2871           0 :                         wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
    2872           0 :                                           data->tdls.peer);
    2873           0 :                 break;
    2874             :         case TDLS_REQUEST_DISCOVER:
    2875           0 :                         wpa_tdls_send_discovery_request(wpa_s->wpa,
    2876           0 :                                                         data->tdls.peer);
    2877           0 :                 break;
    2878             :         }
    2879             : }
    2880             : #endif /* CONFIG_TDLS */
    2881             : 
    2882             : 
    2883             : #ifdef CONFIG_WNM
    2884           0 : static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
    2885             :                                      union wpa_event_data *data)
    2886             : {
    2887           0 :         if (data == NULL)
    2888           0 :                 return;
    2889           0 :         switch (data->wnm.oper) {
    2890             :         case WNM_OPER_SLEEP:
    2891           0 :                 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
    2892             :                            "(action=%d, intval=%d)",
    2893           0 :                            data->wnm.sleep_action, data->wnm.sleep_intval);
    2894           0 :                 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
    2895           0 :                                              data->wnm.sleep_intval, NULL);
    2896           0 :                 break;
    2897             :         }
    2898             : }
    2899             : #endif /* CONFIG_WNM */
    2900             : 
    2901             : 
    2902             : #ifdef CONFIG_IEEE80211R
    2903             : static void
    2904           0 : wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
    2905             :                                  union wpa_event_data *data)
    2906             : {
    2907           0 :         if (data == NULL)
    2908           0 :                 return;
    2909             : 
    2910           0 :         if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
    2911             :                                     data->ft_ies.ies_len,
    2912             :                                     data->ft_ies.ft_action,
    2913           0 :                                     data->ft_ies.target_ap,
    2914             :                                     data->ft_ies.ric_ies,
    2915             :                                     data->ft_ies.ric_ies_len) < 0) {
    2916             :                 /* TODO: prevent MLME/driver from trying to associate? */
    2917             :         }
    2918             : }
    2919             : #endif /* CONFIG_IEEE80211R */
    2920             : 
    2921             : 
    2922             : #ifdef CONFIG_IBSS_RSN
    2923          22 : static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
    2924             :                                                 union wpa_event_data *data)
    2925             : {
    2926             :         struct wpa_ssid *ssid;
    2927          22 :         if (wpa_s->wpa_state < WPA_ASSOCIATED)
    2928           0 :                 return;
    2929          22 :         if (data == NULL)
    2930           0 :                 return;
    2931          22 :         ssid = wpa_s->current_ssid;
    2932          22 :         if (ssid == NULL)
    2933           0 :                 return;
    2934          22 :         if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
    2935           8 :                 return;
    2936             : 
    2937          14 :         ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
    2938             : }
    2939             : 
    2940             : 
    2941          26 : static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
    2942             :                                            union wpa_event_data *data)
    2943             : {
    2944          26 :         struct wpa_ssid *ssid = wpa_s->current_ssid;
    2945             : 
    2946          26 :         if (ssid == NULL)
    2947           0 :                 return;
    2948             : 
    2949             :         /* check if the ssid is correctly configured as IBSS/RSN */
    2950          26 :         if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
    2951           0 :                 return;
    2952             : 
    2953          26 :         ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
    2954             :                              data->rx_mgmt.frame_len);
    2955             : }
    2956             : #endif /* CONFIG_IBSS_RSN */
    2957             : 
    2958             : 
    2959             : #ifdef CONFIG_IEEE80211R
    2960         129 : static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
    2961             :                          size_t len)
    2962             : {
    2963             :         const u8 *sta_addr, *target_ap_addr;
    2964             :         u16 status;
    2965             : 
    2966         129 :         wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
    2967         129 :         if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
    2968           0 :                 return; /* only SME case supported for now */
    2969         129 :         if (len < 1 + 2 * ETH_ALEN + 2)
    2970           0 :                 return;
    2971         129 :         if (data[0] != 2)
    2972           1 :                 return; /* Only FT Action Response is supported for now */
    2973         128 :         sta_addr = data + 1;
    2974         128 :         target_ap_addr = data + 1 + ETH_ALEN;
    2975         128 :         status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
    2976         128 :         wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
    2977             :                 MACSTR " TargetAP " MACSTR " status %u",
    2978             :                 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
    2979             : 
    2980         128 :         if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
    2981           1 :                 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
    2982             :                         " in FT Action Response", MAC2STR(sta_addr));
    2983           1 :                 return;
    2984             :         }
    2985             : 
    2986         127 :         if (status) {
    2987           2 :                 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
    2988             :                         "failure (status code %d)", status);
    2989             :                 /* TODO: report error to FT code(?) */
    2990           2 :                 return;
    2991             :         }
    2992             : 
    2993         125 :         if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
    2994             :                                     len - (1 + 2 * ETH_ALEN + 2), 1,
    2995             :                                     target_ap_addr, NULL, 0) < 0)
    2996          17 :                 return;
    2997             : 
    2998             : #ifdef CONFIG_SME
    2999             :         {
    3000             :                 struct wpa_bss *bss;
    3001         108 :                 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
    3002         108 :                 if (bss)
    3003         108 :                         wpa_s->sme.freq = bss->freq;
    3004         108 :                 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
    3005         108 :                 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
    3006             :                               WLAN_AUTH_FT);
    3007             :         }
    3008             : #endif /* CONFIG_SME */
    3009             : }
    3010             : #endif /* CONFIG_IEEE80211R */
    3011             : 
    3012             : 
    3013          21 : static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
    3014             :                                                struct unprot_deauth *e)
    3015             : {
    3016             : #ifdef CONFIG_IEEE80211W
    3017         273 :         wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
    3018             :                    "dropped: " MACSTR " -> " MACSTR
    3019             :                    " (reason code %u)",
    3020         273 :                    MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
    3021          21 :         sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
    3022             : #endif /* CONFIG_IEEE80211W */
    3023          21 : }
    3024             : 
    3025             : 
    3026          19 : static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
    3027             :                                                  struct unprot_disassoc *e)
    3028             : {
    3029             : #ifdef CONFIG_IEEE80211W
    3030         247 :         wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
    3031             :                    "dropped: " MACSTR " -> " MACSTR
    3032             :                    " (reason code %u)",
    3033         247 :                    MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
    3034          19 :         sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
    3035             : #endif /* CONFIG_IEEE80211W */
    3036          19 : }
    3037             : 
    3038             : 
    3039        5128 : static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
    3040             :                                   u16 reason_code, int locally_generated,
    3041             :                                   const u8 *ie, size_t ie_len, int deauth)
    3042             : {
    3043             : #ifdef CONFIG_AP
    3044        5128 :         if (wpa_s->ap_iface && addr) {
    3045           0 :                 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
    3046           0 :                 return;
    3047             :         }
    3048             : 
    3049        5128 :         if (wpa_s->ap_iface) {
    3050         164 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
    3051         164 :                 return;
    3052             :         }
    3053             : #endif /* CONFIG_AP */
    3054             : 
    3055        4964 :         if (!locally_generated)
    3056         542 :                 wpa_s->own_disconnect_req = 0;
    3057             : 
    3058        4964 :         wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
    3059             : 
    3060        9674 :         if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
    3061        7315 :               ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
    3062        4729 :                 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
    3063        2784 :                eapol_sm_failed(wpa_s->eapol))) &&
    3064         660 :              !wpa_s->eap_expected_failure))
    3065         624 :                 wpas_auth_failed(wpa_s, "AUTH_FAILED");
    3066             : 
    3067             : #ifdef CONFIG_P2P
    3068        4964 :         if (deauth && reason_code > 0) {
    3069        4945 :                 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
    3070             :                                           locally_generated) > 0) {
    3071             :                         /*
    3072             :                          * The interface was removed, so cannot continue
    3073             :                          * processing any additional operations after this.
    3074             :                          */
    3075          22 :                         return;
    3076             :                 }
    3077             :         }
    3078             : #endif /* CONFIG_P2P */
    3079             : 
    3080        4942 :         wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
    3081             :                                              locally_generated);
    3082             : }
    3083             : 
    3084             : 
    3085          18 : static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
    3086             :                                 struct disassoc_info *info)
    3087             : {
    3088          18 :         u16 reason_code = 0;
    3089          18 :         int locally_generated = 0;
    3090          18 :         const u8 *addr = NULL;
    3091          18 :         const u8 *ie = NULL;
    3092          18 :         size_t ie_len = 0;
    3093             : 
    3094          18 :         wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
    3095             : 
    3096          18 :         if (info) {
    3097           9 :                 addr = info->addr;
    3098           9 :                 ie = info->ie;
    3099           9 :                 ie_len = info->ie_len;
    3100           9 :                 reason_code = info->reason_code;
    3101           9 :                 locally_generated = info->locally_generated;
    3102           9 :                 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
    3103             :                         locally_generated ? " (locally generated)" : "");
    3104           9 :                 if (addr)
    3105           9 :                         wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
    3106             :                                 MAC2STR(addr));
    3107           9 :                 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
    3108             :                             ie, ie_len);
    3109             :         }
    3110             : 
    3111             : #ifdef CONFIG_AP
    3112          18 :         if (wpa_s->ap_iface && info && info->addr) {
    3113           0 :                 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
    3114           0 :                 return;
    3115             :         }
    3116             : 
    3117          18 :         if (wpa_s->ap_iface) {
    3118           0 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
    3119           0 :                 return;
    3120             :         }
    3121             : #endif /* CONFIG_AP */
    3122             : 
    3123             : #ifdef CONFIG_P2P
    3124          18 :         if (info) {
    3125           9 :                 wpas_p2p_disassoc_notif(
    3126             :                         wpa_s, info->addr, reason_code, info->ie, info->ie_len,
    3127             :                         locally_generated);
    3128             :         }
    3129             : #endif /* CONFIG_P2P */
    3130             : 
    3131          18 :         if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
    3132           9 :                 sme_event_disassoc(wpa_s, info);
    3133             : 
    3134          18 :         wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
    3135             :                               ie, ie_len, 0);
    3136             : }
    3137             : 
    3138             : 
    3139        5110 : static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
    3140             :                               struct deauth_info *info)
    3141             : {
    3142        5110 :         u16 reason_code = 0;
    3143        5110 :         int locally_generated = 0;
    3144        5110 :         const u8 *addr = NULL;
    3145        5110 :         const u8 *ie = NULL;
    3146        5110 :         size_t ie_len = 0;
    3147             : 
    3148        5110 :         wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
    3149             : 
    3150        5110 :         if (info) {
    3151        5110 :                 addr = info->addr;
    3152        5110 :                 ie = info->ie;
    3153        5110 :                 ie_len = info->ie_len;
    3154        5110 :                 reason_code = info->reason_code;
    3155        5110 :                 locally_generated = info->locally_generated;
    3156        5110 :                 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
    3157             :                         reason_code,
    3158             :                         locally_generated ? " (locally generated)" : "");
    3159        5110 :                 if (addr) {
    3160         786 :                         wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
    3161             :                                 MAC2STR(addr));
    3162             :                 }
    3163        5110 :                 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
    3164             :                             ie, ie_len);
    3165             :         }
    3166             : 
    3167        5110 :         wpa_reset_ft_completed(wpa_s->wpa);
    3168             : 
    3169        5110 :         wpas_event_disconnect(wpa_s, addr, reason_code,
    3170             :                               locally_generated, ie, ie_len, 1);
    3171        5110 : }
    3172             : 
    3173             : 
    3174       14590 : static const char * reg_init_str(enum reg_change_initiator init)
    3175             : {
    3176       14590 :         switch (init) {
    3177             :         case REGDOM_SET_BY_CORE:
    3178       12150 :                 return "CORE";
    3179             :         case REGDOM_SET_BY_USER:
    3180        2267 :                 return "USER";
    3181             :         case REGDOM_SET_BY_DRIVER:
    3182           0 :                 return "DRIVER";
    3183             :         case REGDOM_SET_BY_COUNTRY_IE:
    3184          57 :                 return "COUNTRY_IE";
    3185             :         case REGDOM_BEACON_HINT:
    3186         116 :                 return "BEACON_HINT";
    3187             :         }
    3188           0 :         return "?";
    3189             : }
    3190             : 
    3191             : 
    3192       14590 : static const char * reg_type_str(enum reg_type type)
    3193             : {
    3194       14590 :         switch (type) {
    3195             :         case REGDOM_TYPE_UNKNOWN:
    3196         116 :                 return "UNKNOWN";
    3197             :         case REGDOM_TYPE_COUNTRY:
    3198        1603 :                 return "COUNTRY";
    3199             :         case REGDOM_TYPE_WORLD:
    3200       12871 :                 return "WORLD";
    3201             :         case REGDOM_TYPE_CUSTOM_WORLD:
    3202           0 :                 return "CUSTOM_WORLD";
    3203             :         case REGDOM_TYPE_INTERSECTION:
    3204           0 :                 return "INTERSECTION";
    3205             :         }
    3206           0 :         return "?";
    3207             : }
    3208             : 
    3209             : 
    3210       14590 : static void wpa_supplicant_update_channel_list(
    3211             :         struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
    3212             : {
    3213             :         struct wpa_supplicant *ifs;
    3214             : 
    3215             :         /*
    3216             :          * To allow backwards compatibility with higher level layers that
    3217             :          * assumed the REGDOM_CHANGE event is sent over the initially added
    3218             :          * interface. Find the highest parent of this interface and use it to
    3219             :          * send the event.
    3220             :          */
    3221       14590 :         for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
    3222             :                 ;
    3223             : 
    3224       29180 :         wpa_msg(ifs, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
    3225             :                 reg_init_str(info->initiator), reg_type_str(info->type),
    3226       14590 :                 info->alpha2[0] ? " alpha2=" : "",
    3227       14590 :                 info->alpha2[0] ? info->alpha2 : "");
    3228             : 
    3229       14590 :         if (wpa_s->drv_priv == NULL)
    3230       14590 :                 return; /* Ignore event during drv initialization */
    3231             : 
    3232       29293 :         dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
    3233             :                          radio_list) {
    3234       14703 :                 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
    3235       14703 :                            ifs->ifname);
    3236       14703 :                 free_hw_features(ifs);
    3237       14703 :                 ifs->hw.modes = wpa_drv_get_hw_feature_data(
    3238             :                         ifs, &ifs->hw.num_modes, &ifs->hw.flags);
    3239             : 
    3240             :                 /* Restart PNO/sched_scan with updated channel list */
    3241       14703 :                 if (ifs->pno) {
    3242           0 :                         wpas_stop_pno(ifs);
    3243           0 :                         wpas_start_pno(ifs);
    3244       14703 :                 } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
    3245           0 :                         wpa_dbg(ifs, MSG_DEBUG,
    3246             :                                 "Channel list changed - restart sched_scan");
    3247           0 :                         wpas_scan_restart_sched_scan(ifs);
    3248             :                 }
    3249             :         }
    3250             : 
    3251       14590 :         wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
    3252             : }
    3253             : 
    3254             : 
    3255        2948 : static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
    3256             :                                       const u8 *frame, size_t len, int freq,
    3257             :                                       int rssi)
    3258             : {
    3259             :         const struct ieee80211_mgmt *mgmt;
    3260             :         const u8 *payload;
    3261             :         size_t plen;
    3262             :         u8 category;
    3263             : 
    3264        2948 :         if (len < IEEE80211_HDRLEN + 2)
    3265           0 :                 return;
    3266             : 
    3267        2948 :         mgmt = (const struct ieee80211_mgmt *) frame;
    3268        2948 :         payload = frame + IEEE80211_HDRLEN;
    3269        2948 :         category = *payload++;
    3270        2948 :         plen = len - IEEE80211_HDRLEN - 1;
    3271             : 
    3272        2948 :         wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
    3273             :                 " Category=%u DataLen=%d freq=%d MHz",
    3274             :                 MAC2STR(mgmt->sa), category, (int) plen, freq);
    3275             : 
    3276        2948 :         if (category == WLAN_ACTION_WMM) {
    3277          15 :                 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
    3278          15 :                 return;
    3279             :         }
    3280             : 
    3281             : #ifdef CONFIG_IEEE80211R
    3282        2933 :         if (category == WLAN_ACTION_FT) {
    3283         129 :                 ft_rx_action(wpa_s, payload, plen);
    3284         129 :                 return;
    3285             :         }
    3286             : #endif /* CONFIG_IEEE80211R */
    3287             : 
    3288             : #ifdef CONFIG_IEEE80211W
    3289             : #ifdef CONFIG_SME
    3290        2804 :         if (category == WLAN_ACTION_SA_QUERY) {
    3291           3 :                 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
    3292           3 :                 return;
    3293             :         }
    3294             : #endif /* CONFIG_SME */
    3295             : #endif /* CONFIG_IEEE80211W */
    3296             : 
    3297             : #ifdef CONFIG_WNM
    3298        2801 :         if (mgmt->u.action.category == WLAN_ACTION_WNM) {
    3299         110 :                 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
    3300         110 :                 return;
    3301             :         }
    3302             : #endif /* CONFIG_WNM */
    3303             : 
    3304             : #ifdef CONFIG_GAS
    3305        3429 :         if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
    3306        2695 :              mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
    3307        1957 :             gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
    3308        1957 :                          mgmt->u.action.category,
    3309             :                          payload, plen, freq) == 0)
    3310         723 :                 return;
    3311             : #endif /* CONFIG_GAS */
    3312             : 
    3313             : #ifdef CONFIG_TDLS
    3314        3179 :         if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
    3315        1211 :             payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
    3316           2 :                 wpa_dbg(wpa_s, MSG_DEBUG,
    3317             :                         "TDLS: Received Discovery Response from " MACSTR,
    3318             :                         MAC2STR(mgmt->sa));
    3319           2 :                 return;
    3320             :         }
    3321             : #endif /* CONFIG_TDLS */
    3322             : 
    3323             : #ifdef CONFIG_INTERWORKING
    3324        1967 :         if (category == WLAN_ACTION_QOS && plen >= 1 &&
    3325           1 :             payload[0] == QOS_QOS_MAP_CONFIG) {
    3326           1 :                 const u8 *pos = payload + 1;
    3327           1 :                 size_t qlen = plen - 1;
    3328           1 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
    3329             :                         MACSTR, MAC2STR(mgmt->sa));
    3330           1 :                 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
    3331           2 :                     qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
    3332           2 :                     pos[1] <= qlen - 2 && pos[1] >= 16)
    3333           1 :                         wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
    3334           1 :                 return;
    3335             :         }
    3336             : #endif /* CONFIG_INTERWORKING */
    3337             : 
    3338        1983 :         if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
    3339          18 :             payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
    3340           1 :                 wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
    3341             :                                                           payload + 1,
    3342             :                                                           plen - 1);
    3343           1 :                 return;
    3344             :         }
    3345             : 
    3346        1981 :         if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
    3347          17 :             payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
    3348          17 :                 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
    3349          17 :                 return;
    3350             :         }
    3351             : 
    3352        1947 :         if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
    3353           0 :             payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
    3354           0 :                 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
    3355             :                                                          payload + 1, plen - 1,
    3356             :                                                          rssi);
    3357           0 :                 return;
    3358             :         }
    3359             : 
    3360             : #ifdef CONFIG_FST
    3361        1947 :         if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
    3362         351 :                 fst_rx_action(wpa_s->fst, mgmt, len);
    3363         351 :                 return;
    3364             :         }
    3365             : #endif /* CONFIG_FST */
    3366             : 
    3367        1596 :         wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
    3368             :                            category, payload, plen, freq);
    3369        1596 :         if (wpa_s->ifmsh)
    3370         359 :                 mesh_mpm_action_rx(wpa_s, mgmt, len);
    3371             : }
    3372             : 
    3373             : 
    3374           6 : static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
    3375             :                                              union wpa_event_data *event)
    3376             : {
    3377             :         struct wpa_freq_range_list *list;
    3378           6 :         char *str = NULL;
    3379             : 
    3380           6 :         list = &event->freq_range;
    3381             : 
    3382           6 :         if (list->num)
    3383           3 :                 str = freq_range_list_str(list);
    3384           6 :         wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
    3385             :                 str ? str : "");
    3386             : 
    3387             : #ifdef CONFIG_P2P
    3388           6 :         if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
    3389           0 :                 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
    3390             :                         __func__);
    3391             :         } else {
    3392           6 :                 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
    3393             : 
    3394             :                 /*
    3395             :                  * The update channel flow will also take care of moving a GO
    3396             :                  * from the unsafe frequency if needed.
    3397             :                  */
    3398           6 :                 wpas_p2p_update_channel_list(wpa_s,
    3399             :                                              WPAS_P2P_CHANNEL_UPDATE_AVOID);
    3400             :         }
    3401             : #endif /* CONFIG_P2P */
    3402             : 
    3403           6 :         os_free(str);
    3404           6 : }
    3405             : 
    3406             : 
    3407           0 : static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
    3408             :                                             union wpa_event_data *data)
    3409             : {
    3410           0 :         wpa_dbg(wpa_s, MSG_DEBUG,
    3411             :                 "Connection authorized by device, previous state %d",
    3412             :                 wpa_s->wpa_state);
    3413           0 :         if (wpa_s->wpa_state == WPA_ASSOCIATED) {
    3414           0 :                 wpa_supplicant_cancel_auth_timeout(wpa_s);
    3415           0 :                 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
    3416           0 :                 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
    3417           0 :                 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
    3418             :         }
    3419           0 :         wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
    3420           0 :         wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
    3421             :                                data->assoc_info.ptk_kck_len,
    3422             :                                data->assoc_info.ptk_kek,
    3423             :                                data->assoc_info.ptk_kek_len);
    3424           0 : }
    3425             : 
    3426             : 
    3427       60235 : void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
    3428             :                           union wpa_event_data *data)
    3429             : {
    3430       60235 :         struct wpa_supplicant *wpa_s = ctx;
    3431             :         int resched;
    3432             : 
    3433       60235 :         if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
    3434          87 :             event != EVENT_INTERFACE_ENABLED &&
    3435          43 :             event != EVENT_INTERFACE_STATUS &&
    3436          39 :             event != EVENT_SCAN_RESULTS &&
    3437             :             event != EVENT_SCHED_SCAN_STOPPED) {
    3438          39 :                 wpa_dbg(wpa_s, MSG_DEBUG,
    3439             :                         "Ignore event %s (%d) while interface is disabled",
    3440             :                         event_to_string(event), event);
    3441       60274 :                 return;
    3442             :         }
    3443             : 
    3444             : #ifndef CONFIG_NO_STDOUT_DEBUG
    3445             : {
    3446       60196 :         int level = MSG_DEBUG;
    3447             : 
    3448       60196 :         if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
    3449             :                 const struct ieee80211_hdr *hdr;
    3450             :                 u16 fc;
    3451        7331 :                 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
    3452        7331 :                 fc = le_to_host16(hdr->frame_control);
    3453       14662 :                 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
    3454        7331 :                     WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
    3455         829 :                         level = MSG_EXCESSIVE;
    3456             :         }
    3457             : 
    3458       60196 :         wpa_dbg(wpa_s, level, "Event %s (%d) received",
    3459             :                 event_to_string(event), event);
    3460             : }
    3461             : #endif /* CONFIG_NO_STDOUT_DEBUG */
    3462             : 
    3463       60196 :         switch (event) {
    3464             :         case EVENT_AUTH:
    3465             : #ifdef CONFIG_FST
    3466        4570 :                 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
    3467             :                                           data->auth.ies_len))
    3468           0 :                         wpa_printf(MSG_DEBUG,
    3469             :                                    "FST: MB IEs updated from auth IE");
    3470             : #endif /* CONFIG_FST */
    3471        4570 :                 sme_event_auth(wpa_s, data);
    3472        4570 :                 break;
    3473             :         case EVENT_ASSOC:
    3474             : #ifdef CONFIG_TESTING_OPTIONS
    3475        4784 :                 if (wpa_s->ignore_auth_resp) {
    3476           2 :                         wpa_printf(MSG_INFO,
    3477             :                                    "EVENT_ASSOC - ignore_auth_resp active!");
    3478           2 :                         break;
    3479             :                 }
    3480             : #endif /* CONFIG_TESTING_OPTIONS */
    3481        4782 :                 wpa_supplicant_event_assoc(wpa_s, data);
    3482        4782 :                 if (data && data->assoc_info.authorized)
    3483           0 :                         wpa_supplicant_event_assoc_auth(wpa_s, data);
    3484        4782 :                 if (data) {
    3485        4768 :                         wpa_msg(wpa_s, MSG_INFO,
    3486             :                                 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
    3487        4768 :                                 data->assoc_info.subnet_status);
    3488             :                 }
    3489        4782 :                 break;
    3490             :         case EVENT_DISASSOC:
    3491          18 :                 wpas_event_disassoc(wpa_s,
    3492             :                                     data ? &data->disassoc_info : NULL);
    3493          18 :                 break;
    3494             :         case EVENT_DEAUTH:
    3495             : #ifdef CONFIG_TESTING_OPTIONS
    3496        5116 :                 if (wpa_s->ignore_auth_resp) {
    3497           6 :                         wpa_printf(MSG_INFO,
    3498             :                                    "EVENT_DEAUTH - ignore_auth_resp active!");
    3499           6 :                         break;
    3500             :                 }
    3501             : #endif /* CONFIG_TESTING_OPTIONS */
    3502        5110 :                 wpas_event_deauth(wpa_s,
    3503             :                                   data ? &data->deauth_info : NULL);
    3504        5110 :                 break;
    3505             :         case EVENT_MICHAEL_MIC_FAILURE:
    3506           4 :                 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
    3507           4 :                 break;
    3508             : #ifndef CONFIG_NO_SCAN_PROCESSING
    3509             :         case EVENT_SCAN_STARTED:
    3510        5598 :                 if (wpa_s->own_scan_requested ||
    3511        5576 :                     (data && !data->scan_info.external_scan)) {
    3512             :                         struct os_reltime diff;
    3513             : 
    3514        5576 :                         os_get_reltime(&wpa_s->scan_start_time);
    3515        5576 :                         os_reltime_sub(&wpa_s->scan_start_time,
    3516             :                                        &wpa_s->scan_trigger_time, &diff);
    3517        5576 :                         wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
    3518             :                                 diff.sec, diff.usec);
    3519        5576 :                         wpa_s->own_scan_requested = 0;
    3520        5576 :                         wpa_s->own_scan_running = 1;
    3521        5576 :                         if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
    3522             :                             wpa_s->manual_scan_use_id) {
    3523          33 :                                 wpa_msg_ctrl(wpa_s, MSG_INFO,
    3524             :                                              WPA_EVENT_SCAN_STARTED "id=%u",
    3525             :                                              wpa_s->manual_scan_id);
    3526             :                         } else {
    3527        5543 :                                 wpa_msg_ctrl(wpa_s, MSG_INFO,
    3528             :                                              WPA_EVENT_SCAN_STARTED);
    3529             :                         }
    3530             :                 } else {
    3531          22 :                         wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
    3532          22 :                         wpa_s->radio->external_scan_running = 1;
    3533          22 :                         wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
    3534             :                 }
    3535        5598 :                 break;
    3536             :         case EVENT_SCAN_RESULTS:
    3537        5606 :                 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
    3538           4 :                         wpa_s->scan_res_handler = NULL;
    3539           4 :                         wpa_s->own_scan_running = 0;
    3540           4 :                         wpa_s->radio->external_scan_running = 0;
    3541           4 :                         wpa_s->last_scan_req = NORMAL_SCAN_REQ;
    3542           4 :                         break;
    3543             :                 }
    3544             : 
    3545       11191 :                 if (!(data && data->scan_info.external_scan) &&
    3546        5589 :                     os_reltime_initialized(&wpa_s->scan_start_time)) {
    3547             :                         struct os_reltime now, diff;
    3548        5564 :                         os_get_reltime(&now);
    3549        5564 :                         os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
    3550        5564 :                         wpa_s->scan_start_time.sec = 0;
    3551        5564 :                         wpa_s->scan_start_time.usec = 0;
    3552        5564 :                         wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
    3553             :                                 diff.sec, diff.usec);
    3554             :                 }
    3555        5602 :                 if (wpa_supplicant_event_scan_results(wpa_s, data))
    3556           1 :                         break; /* interface may have been removed */
    3557        5601 :                 if (!(data && data->scan_info.external_scan))
    3558        5588 :                         wpa_s->own_scan_running = 0;
    3559        5601 :                 if (data && data->scan_info.nl_scan_event)
    3560        5586 :                         wpa_s->radio->external_scan_running = 0;
    3561        5601 :                 radio_work_check_next(wpa_s);
    3562        5601 :                 break;
    3563             : #endif /* CONFIG_NO_SCAN_PROCESSING */
    3564             :         case EVENT_ASSOCINFO:
    3565          14 :                 wpa_supplicant_event_associnfo(wpa_s, data);
    3566          14 :                 break;
    3567             :         case EVENT_INTERFACE_STATUS:
    3568         223 :                 wpa_supplicant_event_interface_status(wpa_s, data);
    3569         223 :                 break;
    3570             :         case EVENT_PMKID_CANDIDATE:
    3571           0 :                 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
    3572           0 :                 break;
    3573             : #ifdef CONFIG_PEERKEY
    3574             :         case EVENT_STKSTART:
    3575           0 :                 wpa_supplicant_event_stkstart(wpa_s, data);
    3576           0 :                 break;
    3577             : #endif /* CONFIG_PEERKEY */
    3578             : #ifdef CONFIG_TDLS
    3579             :         case EVENT_TDLS:
    3580           0 :                 wpa_supplicant_event_tdls(wpa_s, data);
    3581           0 :                 break;
    3582             : #endif /* CONFIG_TDLS */
    3583             : #ifdef CONFIG_WNM
    3584             :         case EVENT_WNM:
    3585           0 :                 wpa_supplicant_event_wnm(wpa_s, data);
    3586           0 :                 break;
    3587             : #endif /* CONFIG_WNM */
    3588             : #ifdef CONFIG_IEEE80211R
    3589             :         case EVENT_FT_RESPONSE:
    3590           0 :                 wpa_supplicant_event_ft_response(wpa_s, data);
    3591           0 :                 break;
    3592             : #endif /* CONFIG_IEEE80211R */
    3593             : #ifdef CONFIG_IBSS_RSN
    3594             :         case EVENT_IBSS_RSN_START:
    3595          22 :                 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
    3596          22 :                 break;
    3597             : #endif /* CONFIG_IBSS_RSN */
    3598             :         case EVENT_ASSOC_REJECT:
    3599          51 :                 if (data->assoc_reject.bssid)
    3600         384 :                         wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
    3601             :                                 "bssid=" MACSTR       " status_code=%u%s",
    3602         288 :                                 MAC2STR(data->assoc_reject.bssid),
    3603          48 :                                 data->assoc_reject.status_code,
    3604          48 :                                 data->assoc_reject.timed_out ? " timeout" : "");
    3605             :                 else
    3606           6 :                         wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
    3607             :                                 "status_code=%u%s",
    3608           3 :                                 data->assoc_reject.status_code,
    3609           3 :                                 data->assoc_reject.timed_out ? " timeout" : "");
    3610          51 :                 wpa_s->assoc_status_code = data->assoc_reject.status_code;
    3611          51 :                 wpas_notify_assoc_status_code(wpa_s);
    3612          51 :                 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
    3613          44 :                         sme_event_assoc_reject(wpa_s, data);
    3614             :                 else {
    3615           7 :                         const u8 *bssid = data->assoc_reject.bssid;
    3616           7 :                         if (bssid == NULL || is_zero_ether_addr(bssid))
    3617           3 :                                 bssid = wpa_s->pending_bssid;
    3618           7 :                         wpas_connection_failed(wpa_s, bssid);
    3619           7 :                         wpa_supplicant_mark_disassoc(wpa_s);
    3620             :                 }
    3621          51 :                 break;
    3622             :         case EVENT_AUTH_TIMED_OUT:
    3623             :                 /* It is possible to get this event from earlier connection */
    3624          37 :                 if (wpa_s->current_ssid &&
    3625          18 :                     wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
    3626           0 :                         wpa_dbg(wpa_s, MSG_DEBUG,
    3627             :                                 "Ignore AUTH_TIMED_OUT in mesh configuration");
    3628           0 :                         break;
    3629             :                 }
    3630          19 :                 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
    3631          17 :                         sme_event_auth_timed_out(wpa_s, data);
    3632          19 :                 break;
    3633             :         case EVENT_ASSOC_TIMED_OUT:
    3634             :                 /* It is possible to get this event from earlier connection */
    3635           2 :                 if (wpa_s->current_ssid &&
    3636           1 :                     wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
    3637           0 :                         wpa_dbg(wpa_s, MSG_DEBUG,
    3638             :                                 "Ignore ASSOC_TIMED_OUT in mesh configuration");
    3639           0 :                         break;
    3640             :                 }
    3641           1 :                 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
    3642           1 :                         sme_event_assoc_timed_out(wpa_s, data);
    3643           1 :                 break;
    3644             :         case EVENT_TX_STATUS:
    3645        5597 :                 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
    3646             :                         " type=%d stype=%d",
    3647             :                         MAC2STR(data->tx_status.dst),
    3648             :                         data->tx_status.type, data->tx_status.stype);
    3649             : #ifdef CONFIG_AP
    3650        5597 :                 if (wpa_s->ap_iface == NULL) {
    3651             : #ifdef CONFIG_OFFCHANNEL
    3652        7374 :                         if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
    3653        3687 :                             data->tx_status.stype == WLAN_FC_STYPE_ACTION)
    3654        3687 :                                 offchannel_send_action_tx_status(
    3655             :                                         wpa_s, data->tx_status.dst,
    3656             :                                         data->tx_status.data,
    3657             :                                         data->tx_status.data_len,
    3658        3687 :                                         data->tx_status.ack ?
    3659             :                                         OFFCHANNEL_SEND_ACTION_SUCCESS :
    3660             :                                         OFFCHANNEL_SEND_ACTION_NO_ACK);
    3661             : #endif /* CONFIG_OFFCHANNEL */
    3662        3687 :                         break;
    3663             :                 }
    3664             : #endif /* CONFIG_AP */
    3665             : #ifdef CONFIG_OFFCHANNEL
    3666        1910 :                 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
    3667             :                         MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
    3668             :                 /*
    3669             :                  * Catch TX status events for Action frames we sent via group
    3670             :                  * interface in GO mode, or via standalone AP interface.
    3671             :                  * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
    3672             :                  * except when the primary interface is used as a GO interface
    3673             :                  * (for drivers which do not have group interface concurrency)
    3674             :                  */
    3675        3806 :                 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
    3676        1996 :                     data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
    3677         100 :                     os_memcmp(wpa_s->p2pdev->pending_action_dst,
    3678             :                               data->tx_status.dst, ETH_ALEN) == 0) {
    3679          92 :                         offchannel_send_action_tx_status(
    3680             :                                 wpa_s->p2pdev, data->tx_status.dst,
    3681             :                                 data->tx_status.data,
    3682             :                                 data->tx_status.data_len,
    3683          92 :                                 data->tx_status.ack ?
    3684             :                                 OFFCHANNEL_SEND_ACTION_SUCCESS :
    3685             :                                 OFFCHANNEL_SEND_ACTION_NO_ACK);
    3686          92 :                         break;
    3687             :                 }
    3688             : #endif /* CONFIG_OFFCHANNEL */
    3689             : #ifdef CONFIG_AP
    3690        1818 :                 switch (data->tx_status.type) {
    3691             :                 case WLAN_FC_TYPE_MGMT:
    3692        3608 :                         ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
    3693             :                                       data->tx_status.data_len,
    3694        1804 :                                       data->tx_status.stype,
    3695             :                                       data->tx_status.ack);
    3696        1804 :                         break;
    3697             :                 case WLAN_FC_TYPE_DATA:
    3698          14 :                         ap_tx_status(wpa_s, data->tx_status.dst,
    3699             :                                      data->tx_status.data,
    3700             :                                      data->tx_status.data_len,
    3701             :                                      data->tx_status.ack);
    3702          14 :                         break;
    3703             :                 }
    3704             : #endif /* CONFIG_AP */
    3705        1818 :                 break;
    3706             : #ifdef CONFIG_AP
    3707             :         case EVENT_EAPOL_TX_STATUS:
    3708        4664 :                 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
    3709             :                                    data->eapol_tx_status.data,
    3710        2332 :                                    data->eapol_tx_status.data_len,
    3711             :                                    data->eapol_tx_status.ack);
    3712        2332 :                 break;
    3713             :         case EVENT_DRIVER_CLIENT_POLL_OK:
    3714           0 :                 ap_client_poll_ok(wpa_s, data->client_poll.addr);
    3715           0 :                 break;
    3716             :         case EVENT_RX_FROM_UNKNOWN:
    3717           0 :                 if (wpa_s->ap_iface == NULL)
    3718           0 :                         break;
    3719           0 :                 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
    3720             :                                        data->rx_from_unknown.wds);
    3721           0 :                 break;
    3722             :         case EVENT_CH_SWITCH:
    3723          18 :                 if (!data || !wpa_s->current_ssid)
    3724             :                         break;
    3725             : 
    3726          18 :                 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CHANNEL_SWITCH
    3727             :                         "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
    3728             :                         data->ch_switch.freq,
    3729             :                         data->ch_switch.ht_enabled,
    3730             :                         data->ch_switch.ch_offset,
    3731             :                         channel_width_to_string(data->ch_switch.ch_width),
    3732             :                         data->ch_switch.cf1,
    3733             :                         data->ch_switch.cf2);
    3734             : 
    3735          18 :                 wpa_s->assoc_freq = data->ch_switch.freq;
    3736          18 :                 wpa_s->current_ssid->frequency = data->ch_switch.freq;
    3737             : 
    3738          36 :                 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
    3739          34 :                     wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
    3740          16 :                     wpa_s->current_ssid->mode ==
    3741             :                     WPAS_MODE_P2P_GROUP_FORMATION) {
    3742           4 :                         wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
    3743             :                                           data->ch_switch.ht_enabled,
    3744             :                                           data->ch_switch.ch_offset,
    3745           2 :                                           data->ch_switch.ch_width,
    3746             :                                           data->ch_switch.cf1,
    3747             :                                           data->ch_switch.cf2);
    3748             :                 }
    3749             : 
    3750          18 :                 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
    3751          18 :                 break;
    3752             : #ifdef NEED_AP_MLME
    3753             :         case EVENT_DFS_RADAR_DETECTED:
    3754          21 :                 if (data)
    3755          21 :                         wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
    3756          21 :                 break;
    3757             :         case EVENT_DFS_CAC_STARTED:
    3758           0 :                 if (data)
    3759           0 :                         wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
    3760           0 :                 break;
    3761             :         case EVENT_DFS_CAC_FINISHED:
    3762           1 :                 if (data)
    3763           1 :                         wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
    3764           1 :                 break;
    3765             :         case EVENT_DFS_CAC_ABORTED:
    3766           0 :                 if (data)
    3767           0 :                         wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
    3768           0 :                 break;
    3769             :         case EVENT_DFS_NOP_FINISHED:
    3770           0 :                 if (data)
    3771           0 :                         wpas_event_dfs_cac_nop_finished(wpa_s,
    3772             :                                                         &data->dfs_event);
    3773           0 :                 break;
    3774             : #endif /* NEED_AP_MLME */
    3775             : #endif /* CONFIG_AP */
    3776             :         case EVENT_RX_MGMT: {
    3777             :                 u16 fc, stype;
    3778             :                 const struct ieee80211_mgmt *mgmt;
    3779             : 
    3780             : #ifdef CONFIG_TESTING_OPTIONS
    3781        7331 :                 if (wpa_s->ext_mgmt_frame_handling) {
    3782         106 :                         struct rx_mgmt *rx = &data->rx_mgmt;
    3783         106 :                         size_t hex_len = 2 * rx->frame_len + 1;
    3784         106 :                         char *hex = os_malloc(hex_len);
    3785         106 :                         if (hex) {
    3786         106 :                                 wpa_snprintf_hex(hex, hex_len,
    3787             :                                                  rx->frame, rx->frame_len);
    3788         106 :                                 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
    3789             :                                         rx->freq, rx->datarate, rx->ssi_signal,
    3790             :                                         hex);
    3791         106 :                                 os_free(hex);
    3792             :                         }
    3793         106 :                         break;
    3794             :                 }
    3795             : #endif /* CONFIG_TESTING_OPTIONS */
    3796             : 
    3797        7225 :                 mgmt = (const struct ieee80211_mgmt *)
    3798             :                         data->rx_mgmt.frame;
    3799        7225 :                 fc = le_to_host16(mgmt->frame_control);
    3800        7225 :                 stype = WLAN_FC_GET_STYPE(fc);
    3801             : 
    3802             : #ifdef CONFIG_AP
    3803        7225 :                 if (wpa_s->ap_iface == NULL) {
    3804             : #endif /* CONFIG_AP */
    3805             : #ifdef CONFIG_P2P
    3806        5096 :                         if (stype == WLAN_FC_STYPE_PROBE_REQ &&
    3807         837 :                             data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
    3808         837 :                                 const u8 *src = mgmt->sa;
    3809             :                                 const u8 *ie;
    3810             :                                 size_t ie_len;
    3811             : 
    3812         837 :                                 ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
    3813         837 :                                 ie_len = data->rx_mgmt.frame_len -
    3814             :                                         IEEE80211_HDRLEN;
    3815        2511 :                                 wpas_p2p_probe_req_rx(
    3816         837 :                                         wpa_s, src, mgmt->da,
    3817         837 :                                         mgmt->bssid, ie, ie_len,
    3818         837 :                                         data->rx_mgmt.freq,
    3819             :                                         data->rx_mgmt.ssi_signal);
    3820         837 :                                 break;
    3821             :                         }
    3822             : #endif /* CONFIG_P2P */
    3823             : #ifdef CONFIG_IBSS_RSN
    3824        4961 :                         if (wpa_s->current_ssid &&
    3825        1565 :                             wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
    3826          26 :                             stype == WLAN_FC_STYPE_AUTH &&
    3827          26 :                             data->rx_mgmt.frame_len >= 30) {
    3828          26 :                                 wpa_supplicant_event_ibss_auth(wpa_s, data);
    3829          26 :                                 break;
    3830             :                         }
    3831             : #endif /* CONFIG_IBSS_RSN */
    3832             : 
    3833        3396 :                         if (stype == WLAN_FC_STYPE_ACTION) {
    3834        2948 :                                 wpas_event_rx_mgmt_action(
    3835             :                                         wpa_s, data->rx_mgmt.frame,
    3836             :                                         data->rx_mgmt.frame_len,
    3837             :                                         data->rx_mgmt.freq,
    3838             :                                         data->rx_mgmt.ssi_signal);
    3839        2948 :                                 break;
    3840             :                         }
    3841             : 
    3842         448 :                         if (wpa_s->ifmsh) {
    3843         422 :                                 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
    3844         422 :                                 break;
    3845             :                         }
    3846             : 
    3847          26 :                         wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
    3848             :                                 "management frame in non-AP mode");
    3849          26 :                         break;
    3850             : #ifdef CONFIG_AP
    3851             :                 }
    3852             : 
    3853        3533 :                 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
    3854         567 :                     data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
    3855             :                         const u8 *ie;
    3856             :                         size_t ie_len;
    3857             : 
    3858         567 :                         ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
    3859         567 :                         ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
    3860             : 
    3861        1134 :                         wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
    3862         567 :                                          mgmt->bssid, ie, ie_len,
    3863         567 :                                          data->rx_mgmt.ssi_signal);
    3864             :                 }
    3865             : 
    3866        2966 :                 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
    3867             : #endif /* CONFIG_AP */
    3868        2966 :                 break;
    3869             :                 }
    3870             :         case EVENT_RX_PROBE_REQ:
    3871           0 :                 if (data->rx_probe_req.sa == NULL ||
    3872           0 :                     data->rx_probe_req.ie == NULL)
    3873             :                         break;
    3874             : #ifdef CONFIG_AP
    3875           0 :                 if (wpa_s->ap_iface) {
    3876           0 :                         hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
    3877             :                                              data->rx_probe_req.sa,
    3878             :                                              data->rx_probe_req.da,
    3879             :                                              data->rx_probe_req.bssid,
    3880             :                                              data->rx_probe_req.ie,
    3881             :                                              data->rx_probe_req.ie_len,
    3882             :                                              data->rx_probe_req.ssi_signal);
    3883           0 :                         break;
    3884             :                 }
    3885             : #endif /* CONFIG_AP */
    3886           0 :                 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
    3887             :                                       data->rx_probe_req.da,
    3888             :                                       data->rx_probe_req.bssid,
    3889             :                                       data->rx_probe_req.ie,
    3890             :                                       data->rx_probe_req.ie_len,
    3891             :                                       0,
    3892             :                                       data->rx_probe_req.ssi_signal);
    3893           0 :                 break;
    3894             :         case EVENT_REMAIN_ON_CHANNEL:
    3895             : #ifdef CONFIG_OFFCHANNEL
    3896        2035 :                 offchannel_remain_on_channel_cb(
    3897             :                         wpa_s, data->remain_on_channel.freq,
    3898             :                         data->remain_on_channel.duration);
    3899             : #endif /* CONFIG_OFFCHANNEL */
    3900        2035 :                 wpas_p2p_remain_on_channel_cb(
    3901             :                         wpa_s, data->remain_on_channel.freq,
    3902             :                         data->remain_on_channel.duration);
    3903        2035 :                 break;
    3904             :         case EVENT_CANCEL_REMAIN_ON_CHANNEL:
    3905             : #ifdef CONFIG_OFFCHANNEL
    3906        1929 :                 offchannel_cancel_remain_on_channel_cb(
    3907             :                         wpa_s, data->remain_on_channel.freq);
    3908             : #endif /* CONFIG_OFFCHANNEL */
    3909        1929 :                 wpas_p2p_cancel_remain_on_channel_cb(
    3910             :                         wpa_s, data->remain_on_channel.freq);
    3911        1929 :                 break;
    3912             :         case EVENT_EAPOL_RX:
    3913           0 :                 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
    3914             :                                         data->eapol_rx.data,
    3915             :                                         data->eapol_rx.data_len);
    3916           0 :                 break;
    3917             :         case EVENT_SIGNAL_CHANGE:
    3918           7 :                 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
    3919             :                         "above=%d signal=%d noise=%d txrate=%d",
    3920             :                         data->signal_change.above_threshold,
    3921             :                         data->signal_change.current_signal,
    3922             :                         data->signal_change.current_noise,
    3923             :                         data->signal_change.current_txrate);
    3924           7 :                 wpa_bss_update_level(wpa_s->current_bss,
    3925             :                                      data->signal_change.current_signal);
    3926           7 :                 bgscan_notify_signal_change(
    3927             :                         wpa_s, data->signal_change.above_threshold,
    3928             :                         data->signal_change.current_signal,
    3929             :                         data->signal_change.current_noise,
    3930             :                         data->signal_change.current_txrate);
    3931           7 :                 break;
    3932             :         case EVENT_INTERFACE_ENABLED:
    3933          29 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
    3934          29 :                 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
    3935          26 :                         wpa_supplicant_update_mac_addr(wpa_s);
    3936          26 :                         if (wpa_s->p2p_mgmt) {
    3937           2 :                                 wpa_supplicant_set_state(wpa_s,
    3938             :                                                          WPA_DISCONNECTED);
    3939           2 :                                 break;
    3940             :                         }
    3941             : 
    3942             : #ifdef CONFIG_AP
    3943          24 :                         if (!wpa_s->ap_iface) {
    3944          24 :                                 wpa_supplicant_set_state(wpa_s,
    3945             :                                                          WPA_DISCONNECTED);
    3946          24 :                                 wpa_s->scan_req = NORMAL_SCAN_REQ;
    3947          24 :                                 wpa_supplicant_req_scan(wpa_s, 0, 0);
    3948             :                         } else
    3949           0 :                                 wpa_supplicant_set_state(wpa_s,
    3950             :                                                          WPA_COMPLETED);
    3951             : #else /* CONFIG_AP */
    3952             :                         wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
    3953             :                         wpa_supplicant_req_scan(wpa_s, 0, 0);
    3954             : #endif /* CONFIG_AP */
    3955             :                 }
    3956          27 :                 break;
    3957             :         case EVENT_INTERFACE_DISABLED:
    3958          72 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
    3959             : #ifdef CONFIG_P2P
    3960         143 :                 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
    3961          92 :                     (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
    3962           3 :                      wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
    3963             :                         /*
    3964             :                          * Mark interface disabled if this happens to end up not
    3965             :                          * being removed as a separate P2P group interface.
    3966             :                          */
    3967           1 :                         wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
    3968             :                         /*
    3969             :                          * The interface was externally disabled. Remove
    3970             :                          * it assuming an external entity will start a
    3971             :                          * new session if needed.
    3972             :                          */
    3973           2 :                         if (wpa_s->current_ssid &&
    3974           1 :                             wpa_s->current_ssid->p2p_group)
    3975           1 :                                 wpas_p2p_interface_unavailable(wpa_s);
    3976             :                         else
    3977           0 :                                 wpas_p2p_disconnect(wpa_s);
    3978             :                         /*
    3979             :                          * wpa_s instance may have been freed, so must not use
    3980             :                          * it here anymore.
    3981             :                          */
    3982           1 :                         break;
    3983             :                 }
    3984          73 :                 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
    3985           2 :                     p2p_in_progress(wpa_s->global->p2p) > 1) {
    3986             :                         /* This radio work will be cancelled, so clear P2P
    3987             :                          * state as well.
    3988             :                          */
    3989           2 :                         p2p_stop_find(wpa_s->global->p2p);
    3990             :                 }
    3991             : #endif /* CONFIG_P2P */
    3992             : 
    3993          71 :                 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
    3994             :                         /*
    3995             :                          * Indicate disconnection to keep ctrl_iface events
    3996             :                          * consistent.
    3997             :                          */
    3998          18 :                         wpa_supplicant_event_disassoc(
    3999             :                                 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
    4000             :                 }
    4001          71 :                 wpa_supplicant_mark_disassoc(wpa_s);
    4002          71 :                 wpa_bss_flush(wpa_s);
    4003          71 :                 radio_remove_works(wpa_s, NULL, 0);
    4004             : 
    4005          71 :                 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
    4006          71 :                 break;
    4007             :         case EVENT_CHANNEL_LIST_CHANGED:
    4008       14590 :                 wpa_supplicant_update_channel_list(
    4009             :                         wpa_s, &data->channel_list_changed);
    4010       14590 :                 break;
    4011             :         case EVENT_INTERFACE_UNAVAILABLE:
    4012           5 :                 wpas_p2p_interface_unavailable(wpa_s);
    4013           5 :                 break;
    4014             :         case EVENT_BEST_CHANNEL:
    4015           0 :                 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
    4016             :                         "(%d %d %d)",
    4017             :                         data->best_chan.freq_24, data->best_chan.freq_5,
    4018             :                         data->best_chan.freq_overall);
    4019           0 :                 wpa_s->best_24_freq = data->best_chan.freq_24;
    4020           0 :                 wpa_s->best_5_freq = data->best_chan.freq_5;
    4021           0 :                 wpa_s->best_overall_freq = data->best_chan.freq_overall;
    4022           0 :                 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
    4023             :                                               data->best_chan.freq_5,
    4024             :                                               data->best_chan.freq_overall);
    4025           0 :                 break;
    4026             :         case EVENT_UNPROT_DEAUTH:
    4027          21 :                 wpa_supplicant_event_unprot_deauth(wpa_s,
    4028             :                                                    &data->unprot_deauth);
    4029          21 :                 break;
    4030             :         case EVENT_UNPROT_DISASSOC:
    4031          19 :                 wpa_supplicant_event_unprot_disassoc(wpa_s,
    4032             :                                                      &data->unprot_disassoc);
    4033          19 :                 break;
    4034             :         case EVENT_STATION_LOW_ACK:
    4035             : #ifdef CONFIG_AP
    4036           0 :                 if (wpa_s->ap_iface && data)
    4037           0 :                         hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
    4038           0 :                                                   data->low_ack.addr);
    4039             : #endif /* CONFIG_AP */
    4040             : #ifdef CONFIG_TDLS
    4041           0 :                 if (data)
    4042           0 :                         wpa_tdls_disable_unreachable_link(wpa_s->wpa,
    4043           0 :                                                           data->low_ack.addr);
    4044             : #endif /* CONFIG_TDLS */
    4045           0 :                 break;
    4046             :         case EVENT_IBSS_PEER_LOST:
    4047             : #ifdef CONFIG_IBSS_RSN
    4048           2 :                 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
    4049             : #endif /* CONFIG_IBSS_RSN */
    4050           2 :                 break;
    4051             :         case EVENT_DRIVER_GTK_REKEY:
    4052           0 :                 if (os_memcmp(data->driver_gtk_rekey.bssid,
    4053             :                               wpa_s->bssid, ETH_ALEN))
    4054           0 :                         break;
    4055           0 :                 if (!wpa_s->wpa)
    4056           0 :                         break;
    4057           0 :                 wpa_sm_update_replay_ctr(wpa_s->wpa,
    4058             :                                          data->driver_gtk_rekey.replay_ctr);
    4059           0 :                 break;
    4060             :         case EVENT_SCHED_SCAN_STOPPED:
    4061           0 :                 wpa_s->sched_scanning = 0;
    4062           0 :                 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
    4063           0 :                 wpa_supplicant_notify_scanning(wpa_s, 0);
    4064             : 
    4065           0 :                 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
    4066           0 :                         break;
    4067             : 
    4068             :                 /*
    4069             :                  * If the driver stopped scanning without being requested to,
    4070             :                  * request a new scan to continue scanning for networks.
    4071             :                  */
    4072           0 :                 if (!wpa_s->sched_scan_stop_req &&
    4073           0 :                     wpa_s->wpa_state == WPA_SCANNING) {
    4074           0 :                         wpa_dbg(wpa_s, MSG_DEBUG,
    4075             :                                 "Restart scanning after unexpected sched_scan stop event");
    4076           0 :                         wpa_supplicant_req_scan(wpa_s, 1, 0);
    4077           0 :                         break;
    4078             :                 }
    4079             : 
    4080           0 :                 wpa_s->sched_scan_stop_req = 0;
    4081             : 
    4082             :                 /*
    4083             :                  * Start a new sched scan to continue searching for more SSIDs
    4084             :                  * either if timed out or PNO schedule scan is pending.
    4085             :                  */
    4086           0 :                 if (wpa_s->sched_scan_timed_out) {
    4087           0 :                         wpa_supplicant_req_sched_scan(wpa_s);
    4088           0 :                 } else if (wpa_s->pno_sched_pending) {
    4089           0 :                         wpa_s->pno_sched_pending = 0;
    4090           0 :                         wpas_start_pno(wpa_s);
    4091           0 :                 } else if (resched) {
    4092           0 :                         wpa_supplicant_req_scan(wpa_s, 0, 0);
    4093             :                 }
    4094             : 
    4095           0 :                 break;
    4096             :         case EVENT_WPS_BUTTON_PUSHED:
    4097             : #ifdef CONFIG_WPS
    4098           0 :                 wpas_wps_start_pbc(wpa_s, NULL, 0);
    4099             : #endif /* CONFIG_WPS */
    4100           0 :                 break;
    4101             :         case EVENT_AVOID_FREQUENCIES:
    4102           6 :                 wpa_supplicant_notify_avoid_freq(wpa_s, data);
    4103           6 :                 break;
    4104             :         case EVENT_CONNECT_FAILED_REASON:
    4105             : #ifdef CONFIG_AP
    4106           0 :                 if (!wpa_s->ap_iface || !data)
    4107             :                         break;
    4108           0 :                 hostapd_event_connect_failed_reason(
    4109           0 :                         wpa_s->ap_iface->bss[0],
    4110           0 :                         data->connect_failed_reason.addr,
    4111           0 :                         data->connect_failed_reason.code);
    4112             : #endif /* CONFIG_AP */
    4113           0 :                 break;
    4114             :         case EVENT_NEW_PEER_CANDIDATE:
    4115             : #ifdef CONFIG_MESH
    4116         150 :                 if (!wpa_s->ifmsh || !data)
    4117             :                         break;
    4118         150 :                 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
    4119             :                                      data->mesh_peer.ies,
    4120             :                                      data->mesh_peer.ie_len);
    4121             : #endif /* CONFIG_MESH */
    4122         150 :                 break;
    4123             :         case EVENT_SURVEY:
    4124             : #ifdef CONFIG_AP
    4125           5 :                 if (!wpa_s->ap_iface)
    4126           0 :                         break;
    4127           5 :                 hostapd_event_get_survey(wpa_s->ap_iface,
    4128             :                                          &data->survey_results);
    4129             : #endif /* CONFIG_AP */
    4130           5 :                 break;
    4131             :         case EVENT_ACS_CHANNEL_SELECTED:
    4132             : #ifdef CONFIG_ACS
    4133           0 :                 if (!wpa_s->ap_iface)
    4134           0 :                         break;
    4135           0 :                 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
    4136             :                                              &data->acs_selected_channels);
    4137             : #endif /* CONFIG_ACS */
    4138           0 :                 break;
    4139             :         case EVENT_P2P_LO_STOP:
    4140             : #ifdef CONFIG_P2P
    4141           0 :                 wpa_s->p2p_lo_started = 0;
    4142           0 :                 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
    4143             :                         P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
    4144           0 :                         data->p2p_lo_stop.reason_code);
    4145             : #endif /* CONFIG_P2P */
    4146           0 :                 break;
    4147             :         default:
    4148           0 :                 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
    4149           0 :                 break;
    4150             :         }
    4151             : }
    4152             : 
    4153             : 
    4154      144171 : void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
    4155             :                                  union wpa_event_data *data)
    4156             : {
    4157             :         struct wpa_supplicant *wpa_s;
    4158             : 
    4159      144171 :         if (event != EVENT_INTERFACE_STATUS)
    4160           0 :                 return;
    4161             : 
    4162      144171 :         wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
    4163      144171 :         if (wpa_s && wpa_s->driver->get_ifindex) {
    4164             :                 unsigned int ifindex;
    4165             : 
    4166           1 :                 ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
    4167           1 :                 if (ifindex != data->interface_status.ifindex) {
    4168           1 :                         wpa_dbg(wpa_s, MSG_DEBUG,
    4169             :                                 "interface status ifindex %d mismatch (%d)",
    4170             :                                 ifindex, data->interface_status.ifindex);
    4171           1 :                         return;
    4172             :                 }
    4173             :         }
    4174             : #ifdef CONFIG_MATCH_IFACE
    4175             :         else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
    4176             :                 struct wpa_interface *wpa_i;
    4177             : 
    4178             :                 wpa_i = wpa_supplicant_match_iface(
    4179             :                         ctx, data->interface_status.ifname);
    4180             :                 if (!wpa_i)
    4181             :                         return;
    4182             :                 wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
    4183             :                 os_free(wpa_i);
    4184             :                 if (wpa_s)
    4185             :                         wpa_s->matched = 1;
    4186             :         }
    4187             : #endif /* CONFIG_MATCH_IFACE */
    4188             : 
    4189      144170 :         if (wpa_s)
    4190         164 :                 wpa_supplicant_event(wpa_s, event, data);
    4191             : }

Generated by: LCOV version 1.10