2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_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"
28 #include "common/ieee802_11_defs.h"
29 #include "common/ieee802_11_common.h"
30 #include "crypto/random.h"
31 #include "blacklist.h"
32 #include "wpas_glue.h"
33 #include "wps_supplicant.h"
36 #include "gas_query.h"
37 #include "p2p_supplicant.h"
43 #include "offchannel.h"
44 #include "interworking.h"
47 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
51 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
52 struct wpa_ssid *ssid)
56 if (ssid == NULL || ssid->disabled_until.sec == 0)
60 if (ssid->disabled_until.sec > now.sec)
61 return ssid->disabled_until.sec - now.sec;
63 wpas_clear_temp_disabled(wpa_s, ssid, 0);
69 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
71 struct wpa_ssid *ssid, *old_ssid;
74 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
77 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
79 ssid = wpa_supplicant_get_ssid(wpa_s);
81 wpa_msg(wpa_s, MSG_INFO,
82 "No network configuration found for the current AP");
86 if (wpas_network_disabled(wpa_s, ssid)) {
87 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
91 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
92 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
93 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
97 res = wpas_temp_disabled(wpa_s, ssid);
99 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
100 "disabled for %d second(s)", res);
104 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
106 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
108 size_t wpa_ie_len = sizeof(wpa_ie);
109 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
110 wpa_ie, &wpa_ie_len) < 0)
111 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
113 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
116 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
117 eapol_sm_invalidate_cached_session(wpa_s->eapol);
118 old_ssid = wpa_s->current_ssid;
119 wpa_s->current_ssid = ssid;
120 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
121 wpa_supplicant_initiate_eapol(wpa_s);
122 if (old_ssid != wpa_s->current_ssid)
123 wpas_notify_network_changed(wpa_s);
129 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
131 struct wpa_supplicant *wpa_s = eloop_ctx;
133 if (wpa_s->countermeasures) {
134 wpa_s->countermeasures = 0;
135 wpa_drv_set_countermeasures(wpa_s, 0);
136 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
137 wpa_supplicant_req_scan(wpa_s, 0, 0);
142 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
146 wnm_bss_keep_alive_deinit(wpa_s);
148 #ifdef CONFIG_IBSS_RSN
149 ibss_rsn_deinit(wpa_s->ibss_rsn);
150 wpa_s->ibss_rsn = NULL;
151 #endif /* CONFIG_IBSS_RSN */
154 wpa_supplicant_ap_deinit(wpa_s);
155 #endif /* CONFIG_AP */
157 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
160 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
161 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
162 os_memset(wpa_s->bssid, 0, ETH_ALEN);
163 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
165 wpa_s->sme.prev_bssid_set = 0;
166 #endif /* CONFIG_SME */
168 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
169 #endif /* CONFIG_P2P */
170 wpa_s->current_bss = NULL;
171 wpa_s->assoc_freq = 0;
172 #ifdef CONFIG_IEEE80211R
174 if (wpa_s->sme.ft_ies)
175 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
176 #endif /* CONFIG_SME */
177 #endif /* CONFIG_IEEE80211R */
180 wpas_notify_bssid_changed(wpa_s);
182 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
183 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
184 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
185 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
186 wpa_s->ap_ies_from_associnfo = 0;
187 wpa_s->current_ssid = NULL;
192 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
194 struct wpa_ie_data ie;
198 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
202 for (i = 0; i < ie.num_pmkid; i++) {
203 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
204 ie.pmkid + i * PMKID_LEN,
206 if (pmksa_set == 0) {
207 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
212 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
213 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
217 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
218 union wpa_event_data *data)
221 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
225 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
226 " index=%d preauth=%d",
227 MAC2STR(data->pmkid_candidate.bssid),
228 data->pmkid_candidate.index,
229 data->pmkid_candidate.preauth);
231 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
232 data->pmkid_candidate.index,
233 data->pmkid_candidate.preauth);
237 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
239 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
240 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
243 #ifdef IEEE8021X_EAPOL
244 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
245 wpa_s->current_ssid &&
246 !(wpa_s->current_ssid->eapol_flags &
247 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
248 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
249 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
250 * plaintext or static WEP keys). */
253 #endif /* IEEE8021X_EAPOL */
260 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
261 * @wpa_s: pointer to wpa_supplicant data
262 * @ssid: Configuration data for the network
263 * Returns: 0 on success, -1 on failure
265 * This function is called when starting authentication with a network that is
266 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
268 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
269 struct wpa_ssid *ssid)
271 #ifdef IEEE8021X_EAPOL
273 int aka = 0, sim = 0, type;
275 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
278 if (ssid->eap.eap_methods == NULL) {
282 struct eap_method_type *eap = ssid->eap.eap_methods;
283 while (eap->vendor != EAP_VENDOR_IETF ||
284 eap->method != EAP_TYPE_NONE) {
285 if (eap->vendor == EAP_VENDOR_IETF) {
286 if (eap->method == EAP_TYPE_SIM)
288 else if (eap->method == EAP_TYPE_AKA ||
289 eap->method == EAP_TYPE_AKA_PRIME)
296 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
298 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
299 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
304 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
305 "use SIM, but neither EAP-SIM nor EAP-AKA are "
310 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
311 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
313 type = SCARD_TRY_BOTH;
315 type = SCARD_USIM_ONLY;
317 type = SCARD_GSM_SIM_ONLY;
319 wpa_s->scard = scard_init(type, NULL);
320 if (wpa_s->scard == NULL) {
321 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
325 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
326 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
327 #endif /* PCSC_FUNCS */
328 #endif /* IEEE8021X_EAPOL */
334 #ifndef CONFIG_NO_SCAN_PROCESSING
335 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
336 struct wpa_ssid *ssid)
340 if (ssid->mixed_cell)
344 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
346 #endif /* CONFIG_WPS */
348 for (i = 0; i < NUM_WEP_KEYS; i++) {
349 if (ssid->wep_key_len[i]) {
354 #ifdef IEEE8021X_EAPOL
355 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
356 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
357 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
359 #endif /* IEEE8021X_EAPOL */
361 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
364 if (bss->caps & IEEE80211_CAP_PRIVACY)
370 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
371 struct wpa_ssid *ssid,
374 struct wpa_ie_data ie;
376 const u8 *rsn_ie, *wpa_ie;
380 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
384 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
385 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
386 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
387 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
388 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
390 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
391 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
394 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
395 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
401 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
403 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
408 if (!(ie.proto & ssid->proto)) {
409 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
414 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
415 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
420 if (!(ie.group_cipher & ssid->group_cipher)) {
421 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
426 if (!(ie.key_mgmt & ssid->key_mgmt)) {
427 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
432 #ifdef CONFIG_IEEE80211W
433 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
434 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
435 wpa_s->conf->pmf : ssid->ieee80211w) ==
436 MGMT_FRAME_PROTECTION_REQUIRED) {
437 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
441 #endif /* CONFIG_IEEE80211W */
443 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
447 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
448 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
451 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
452 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
458 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
460 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
465 if (!(ie.proto & ssid->proto)) {
466 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
471 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
472 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
477 if (!(ie.group_cipher & ssid->group_cipher)) {
478 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
483 if (!(ie.key_mgmt & ssid->key_mgmt)) {
484 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
489 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
493 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
495 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
499 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
500 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
501 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
505 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
506 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
510 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
517 static int freq_allowed(int *freqs, int freq)
524 for (i = 0; freqs[i]; i++)
525 if (freqs[i] == freq)
531 static int ht_supported(const struct hostapd_hw_modes *mode)
533 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
535 * The driver did not indicate whether it supports HT. Assume
536 * it does to avoid connection issues.
542 * IEEE Std 802.11n-2009 20.1.1:
543 * An HT non-AP STA shall support all EQM rates for one spatial stream.
545 return mode->mcs_set[0] == 0xff;
549 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
551 const struct hostapd_hw_modes *mode = NULL, *modes;
552 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
557 return 1; /* Cannot do matching without knowing band */
559 modes = wpa_s->hw.modes;
562 * The driver does not provide any additional information
563 * about the utilized hardware, so allow the connection attempt
569 for (i = 0; i < wpa_s->hw.num_modes; i++) {
570 for (j = 0; j < modes[i].num_channels; j++) {
571 int freq = modes[i].channels[j].freq;
572 if (freq == bss->freq) {
574 mode->mode == HOSTAPD_MODE_IEEE80211G)
575 break; /* do not allow 802.11b replace
586 for (i = 0; i < (int) sizeof(scan_ie); i++) {
587 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
591 for (j = 2; j < rate_ie[1] + 2; j++) {
592 int flagged = !!(rate_ie[j] & 0x80);
593 int r = (rate_ie[j] & 0x7f) * 5;
596 * IEEE Std 802.11n-2009 7.3.2.2:
597 * The new BSS Membership selector value is encoded
598 * like a legacy basic rate, but it is not a rate and
599 * only indicates if the BSS members are required to
600 * support the mandatory features of Clause 20 [HT PHY]
601 * in order to join the BSS.
603 if (flagged && ((rate_ie[j] & 0x7f) ==
604 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
605 if (!ht_supported(mode)) {
606 wpa_dbg(wpa_s, MSG_DEBUG,
607 " hardware does not support "
617 /* check for legacy basic rates */
618 for (k = 0; k < mode->num_rates; k++) {
619 if (mode->rates[k] == r)
622 if (k == mode->num_rates) {
624 * IEEE Std 802.11-2007 7.3.2.2 demands that in
625 * order to join a BSS all required rates
626 * have to be supported by the hardware.
628 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
629 "not support required rate %d.%d Mbps",
640 static int bss_is_dmg(struct wpa_bss *bss)
642 return bss->freq > 45000;
647 * Test whether BSS is in an ESS.
648 * This is done differently in DMG (60 GHz) and non-DMG bands
650 static int bss_is_ess(struct wpa_bss *bss)
652 if (bss_is_dmg(bss)) {
653 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
654 IEEE80211_CAP_DMG_AP;
657 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
662 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
663 int i, struct wpa_bss *bss,
664 struct wpa_ssid *group)
666 u8 wpa_ie_len, rsn_ie_len;
668 struct wpa_blacklist *e;
670 struct wpa_ssid *ssid;
672 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
673 wpa_ie_len = ie ? ie[1] : 0;
675 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
676 rsn_ie_len = ie ? ie[1] : 0;
678 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
679 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
680 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
681 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
682 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
684 e = wpa_blacklist_get(wpa_s, bss->bssid);
687 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
689 * When only a single network is enabled, we can
690 * trigger blacklisting on the first failure. This
691 * should not be done with multiple enabled networks to
692 * avoid getting forced to move into a worse ESS on
693 * single error if there are no other BSSes of the
698 if (e->count > limit) {
699 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
700 "(count=%d limit=%d)", e->count, limit);
705 if (bss->ssid_len == 0) {
706 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
710 if (disallowed_bssid(wpa_s, bss->bssid)) {
711 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
715 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
716 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
720 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
722 for (ssid = group; ssid; ssid = ssid->pnext) {
723 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
726 if (wpas_network_disabled(wpa_s, ssid)) {
727 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
731 res = wpas_temp_disabled(wpa_s, ssid);
733 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
734 "temporarily for %d second(s)", res);
739 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
740 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
745 if (wpa && ssid->ssid_len == 0 &&
746 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
749 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
750 /* Only allow wildcard SSID match if an AP
751 * advertises active WPS operation that matches
754 if (ssid->ssid_len == 0 &&
755 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
758 #endif /* CONFIG_WPS */
760 if (ssid->bssid_set && ssid->ssid_len == 0 &&
761 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
765 (bss->ssid_len != ssid->ssid_len ||
766 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
767 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
771 if (ssid->bssid_set &&
772 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
773 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
777 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
781 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
782 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
783 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
784 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
789 if (!wpa_supplicant_match_privacy(bss, ssid)) {
790 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
795 if (!bss_is_ess(bss)) {
796 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
800 if (!freq_allowed(ssid->freq_list, bss->freq)) {
801 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
806 if (!rate_match(wpa_s, bss)) {
807 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
814 * TODO: skip the AP if its P2P IE has Group Formation
815 * bit set in the P2P Group Capability Bitmap and we
816 * are not in Group Formation with that device.
818 #endif /* CONFIG_P2P */
820 /* Matching configuration found */
824 /* No matching configuration found */
829 static struct wpa_bss *
830 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
831 struct wpa_ssid *group,
832 struct wpa_ssid **selected_ssid)
836 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
839 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
840 struct wpa_bss *bss = wpa_s->last_scan_res[i];
841 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
844 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
847 wpa_ssid_txt(bss->ssid, bss->ssid_len));
855 struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
856 struct wpa_ssid **selected_ssid)
858 struct wpa_bss *selected = NULL;
861 if (wpa_s->last_scan_res == NULL ||
862 wpa_s->last_scan_res_used == 0)
863 return NULL; /* no scan results from last update */
865 while (selected == NULL) {
866 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
867 selected = wpa_supplicant_select_bss(
868 wpa_s, wpa_s->conf->pssid[prio],
874 if (selected == NULL && wpa_s->blacklist &&
875 !wpa_s->countermeasures) {
876 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
877 "blacklist and try again");
878 wpa_blacklist_clear(wpa_s);
879 wpa_s->blacklist_cleared++;
880 } else if (selected == NULL)
888 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
889 int timeout_sec, int timeout_usec)
891 if (!wpa_supplicant_enabled_networks(wpa_s)) {
893 * No networks are enabled; short-circuit request so
894 * we don't wait timeout seconds before transitioning
897 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
898 "since there are no enabled networks");
899 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
901 wpa_s->sta_scan_pending = 0;
902 #endif /* CONFIG_P2P */
906 wpa_s->scan_for_connection = 1;
907 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
911 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
912 struct wpa_bss *selected,
913 struct wpa_ssid *ssid)
915 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
916 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
917 "PBC session overlap");
919 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
921 #endif /* CONFIG_P2P */
924 wpas_wps_cancel(wpa_s);
925 #endif /* CONFIG_WPS */
930 * Do not trigger new association unless the BSSID has changed or if
931 * reassociation is requested. If we are in process of associating with
932 * the selected BSSID, do not trigger new attempt.
934 if (wpa_s->reassociate ||
935 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
936 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
937 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
938 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
940 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
941 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
944 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
945 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
946 " pending: " MACSTR " wpa_state: %s",
947 wpa_s->reassociate, MAC2STR(selected->bssid),
948 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
949 wpa_supplicant_state_txt(wpa_s->wpa_state));
950 wpa_supplicant_associate(wpa_s, selected, ssid);
952 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
960 static struct wpa_ssid *
961 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
964 struct wpa_ssid *ssid;
966 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
967 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
969 if (wpas_network_disabled(wpa_s, ssid))
971 if (ssid->mode == IEEE80211_MODE_IBSS ||
972 ssid->mode == IEEE80211_MODE_AP)
980 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
981 * on BSS added and BSS changed events */
982 static void wpa_supplicant_rsn_preauth_scan_results(
983 struct wpa_supplicant *wpa_s)
987 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
990 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
991 const u8 *ssid, *rsn;
993 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
997 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1001 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
1007 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1008 struct wpa_bss *selected,
1009 struct wpa_ssid *ssid)
1011 struct wpa_bss *current_bss = NULL;
1014 if (wpa_s->reassociate)
1015 return 1; /* explicit request to reassociate */
1016 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1017 return 1; /* we are not associated; continue */
1018 if (wpa_s->current_ssid == NULL)
1019 return 1; /* unknown current SSID */
1020 if (wpa_s->current_ssid != ssid)
1021 return 1; /* different network block */
1023 if (wpas_driver_bss_selection(wpa_s))
1024 return 0; /* Driver-based roaming */
1026 if (wpa_s->current_ssid->ssid)
1027 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1028 wpa_s->current_ssid->ssid,
1029 wpa_s->current_ssid->ssid_len);
1031 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1034 return 1; /* current BSS not seen in scan results */
1036 if (current_bss == selected)
1039 if (selected->last_update_idx > current_bss->last_update_idx)
1040 return 1; /* current BSS not seen in the last scan */
1042 #ifndef CONFIG_NO_ROAMING
1043 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1044 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1045 MAC2STR(current_bss->bssid), current_bss->level);
1046 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1047 MAC2STR(selected->bssid), selected->level);
1049 if (wpa_s->current_ssid->bssid_set &&
1050 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1052 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1053 "has preferred BSSID");
1057 if (current_bss->level < 0 && current_bss->level > selected->level) {
1058 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1064 if (current_bss->level < 0) {
1065 if (current_bss->level < -85)
1067 else if (current_bss->level < -80)
1069 else if (current_bss->level < -75)
1071 else if (current_bss->level < -70)
1076 if (abs(current_bss->level - selected->level) < min_diff) {
1077 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1083 #else /* CONFIG_NO_ROAMING */
1085 #endif /* CONFIG_NO_ROAMING */
1089 /* Return != 0 if no scan results could be fetched or if scan results should not
1090 * be shared with other virtual interfaces. */
1091 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1092 union wpa_event_data *data,
1095 struct wpa_scan_results *scan_res;
1097 #ifndef CONFIG_NO_RANDOM_POOL
1099 #endif /* CONFIG_NO_RANDOM_POOL */
1102 if (wpa_s->ap_iface)
1104 #endif /* CONFIG_AP */
1106 wpa_supplicant_notify_scanning(wpa_s, 0);
1109 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
1110 !wpa_s->global->p2p_disabled &&
1111 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1112 !wpa_s->scan_res_handler) {
1113 wpa_s->global->p2p_cb_on_scan_complete = 0;
1114 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1115 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1116 "stopped scan processing");
1117 wpa_s->sta_scan_pending = 1;
1118 wpa_supplicant_req_scan(wpa_s, 5, 0);
1122 wpa_s->sta_scan_pending = 0;
1123 #endif /* CONFIG_P2P */
1125 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1126 data ? &data->scan_info :
1128 if (scan_res == NULL) {
1129 if (wpa_s->conf->ap_scan == 2 || ap ||
1130 wpa_s->scan_res_handler == scan_only_handler)
1134 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1136 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1140 #ifndef CONFIG_NO_RANDOM_POOL
1141 num = scan_res->num;
1144 for (i = 0; i < num; i++) {
1146 struct wpa_scan_res *res = scan_res->res[i];
1147 buf[0] = res->bssid[5];
1148 buf[1] = res->qual & 0xff;
1149 buf[2] = res->noise & 0xff;
1150 buf[3] = res->level & 0xff;
1151 buf[4] = res->tsf & 0xff;
1152 random_add_randomness(buf, sizeof(buf));
1154 #endif /* CONFIG_NO_RANDOM_POOL */
1156 if (own_request && wpa_s->scan_res_handler) {
1157 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1158 struct wpa_scan_results *scan_res);
1160 scan_res_handler = wpa_s->scan_res_handler;
1161 wpa_s->scan_res_handler = NULL;
1162 scan_res_handler(wpa_s, scan_res);
1164 wpa_scan_results_free(scan_res);
1169 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1171 if (wpa_s->ap_iface->scan_cb)
1172 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1173 #endif /* CONFIG_AP */
1174 wpa_scan_results_free(scan_res);
1178 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1179 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1180 wpas_notify_scan_results(wpa_s);
1182 wpas_notify_scan_done(wpa_s, 1);
1184 if (sme_proc_obss_scan(wpa_s) > 0) {
1185 wpa_scan_results_free(scan_res);
1189 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1190 wpa_scan_results_free(scan_res);
1194 if (autoscan_notify_scan(wpa_s, scan_res)) {
1195 wpa_scan_results_free(scan_res);
1199 if (wpa_s->disconnected) {
1200 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1201 wpa_scan_results_free(scan_res);
1205 if (!wpas_driver_bss_selection(wpa_s) &&
1206 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1207 wpa_scan_results_free(scan_res);
1211 wpas_wps_update_ap_info(wpa_s, scan_res);
1213 wpa_scan_results_free(scan_res);
1215 return wpas_select_network_from_last_scan(wpa_s, 1);
1219 static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1222 struct wpa_bss *selected;
1223 struct wpa_ssid *ssid = NULL;
1225 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1229 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1232 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1236 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1237 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1241 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1243 * Do not notify other virtual radios of scan results since we do not
1244 * want them to start other associations at the same time.
1248 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1249 ssid = wpa_supplicant_pick_new_network(wpa_s);
1251 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1252 wpa_supplicant_associate(wpa_s, NULL, ssid);
1254 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1256 int timeout_sec = wpa_s->scan_interval;
1257 int timeout_usec = 0;
1259 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1262 if (wpa_s->p2p_in_provisioning) {
1264 * Use shorter wait during P2P Provisioning
1265 * state to speed up group formation.
1268 timeout_usec = 250000;
1269 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1273 #endif /* CONFIG_P2P */
1274 #ifdef CONFIG_INTERWORKING
1275 if (wpa_s->conf->auto_interworking &&
1276 wpa_s->conf->interworking &&
1277 wpa_s->conf->cred) {
1278 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1279 "start ANQP fetch since no matching "
1281 wpa_s->network_select = 1;
1282 wpa_s->auto_network_select = 1;
1283 interworking_start_fetch_anqp(wpa_s);
1286 #endif /* CONFIG_INTERWORKING */
1287 if (wpa_supplicant_req_sched_scan(wpa_s))
1288 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1296 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1297 union wpa_event_data *data)
1299 const char *rn, *rn2;
1300 struct wpa_supplicant *ifs;
1302 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
1304 * If no scan results could be fetched, then no need to
1305 * notify those interfaces that did not actually request
1306 * this scan. Similarly, if scan results started a new operation on this
1307 * interface, do not notify other interfaces to avoid concurrent
1308 * operations during a connection attempt.
1314 * Check other interfaces to see if they have the same radio-name. If
1315 * so, they get updated with this same scan info.
1317 if (!wpa_s->driver->get_radio_name)
1320 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1321 if (rn == NULL || rn[0] == '\0')
1324 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1325 "sharing same radio (%s) in event_scan_results", rn);
1327 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1328 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1331 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1332 if (rn2 && os_strcmp(rn, rn2) == 0) {
1333 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1334 "sibling", ifs->ifname);
1335 _wpa_supplicant_event_scan_results(ifs, data, 0);
1340 #endif /* CONFIG_NO_SCAN_PROCESSING */
1343 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1345 #ifdef CONFIG_NO_SCAN_PROCESSING
1347 #else /* CONFIG_NO_SCAN_PROCESSING */
1350 if (wpa_s->last_scan_res_used <= 0)
1354 if (now.sec - wpa_s->last_scan.sec > 5) {
1355 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1359 return wpas_select_network_from_last_scan(wpa_s, 0);
1360 #endif /* CONFIG_NO_SCAN_PROCESSING */
1365 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1367 struct wpa_supplicant *wpa_s = eloop_ctx;
1369 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1372 if (!wpa_s->no_keep_alive) {
1373 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1374 MAC2STR(wpa_s->bssid));
1375 /* TODO: could skip this if normal data traffic has been sent */
1376 /* TODO: Consider using some more appropriate data frame for
1379 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1384 if (wpa_s->sme.bss_max_idle_period) {
1386 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1389 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1390 wnm_bss_keep_alive, wpa_s, NULL);
1392 #endif /* CONFIG_SME */
1396 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1397 const u8 *ies, size_t ies_len)
1399 struct ieee802_11_elems elems;
1404 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1408 if (elems.bss_max_idle_period) {
1410 wpa_s->sme.bss_max_idle_period =
1411 WPA_GET_LE16(elems.bss_max_idle_period);
1412 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1413 "TU)%s", wpa_s->sme.bss_max_idle_period,
1414 (elems.bss_max_idle_period[2] & 0x01) ?
1415 " (protected keep-live required)" : "");
1416 if (wpa_s->sme.bss_max_idle_period == 0)
1417 wpa_s->sme.bss_max_idle_period = 1;
1418 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1419 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1420 /* msec times 1000 */
1421 msec = wpa_s->sme.bss_max_idle_period * 1024;
1424 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1425 wnm_bss_keep_alive, wpa_s,
1429 #endif /* CONFIG_SME */
1432 #endif /* CONFIG_WNM */
1435 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1438 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1439 #endif /* CONFIG_WNM */
1443 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1444 union wpa_event_data *data)
1446 int l, len, found = 0, wpa_found, rsn_found;
1448 #ifdef CONFIG_IEEE80211R
1450 #endif /* CONFIG_IEEE80211R */
1452 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1453 if (data->assoc_info.req_ies)
1454 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1455 data->assoc_info.req_ies_len);
1456 if (data->assoc_info.resp_ies) {
1457 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1458 data->assoc_info.resp_ies_len);
1460 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1461 data->assoc_info.resp_ies_len);
1462 #endif /* CONFIG_TDLS */
1464 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1465 data->assoc_info.resp_ies_len);
1466 #endif /* CONFIG_WNM */
1468 if (data->assoc_info.beacon_ies)
1469 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1470 data->assoc_info.beacon_ies,
1471 data->assoc_info.beacon_ies_len);
1472 if (data->assoc_info.freq)
1473 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1474 data->assoc_info.freq);
1476 p = data->assoc_info.req_ies;
1477 l = data->assoc_info.req_ies_len;
1479 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1480 while (p && l >= 2) {
1483 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1487 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1488 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1489 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1490 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1493 wpa_find_assoc_pmkid(wpa_s);
1499 if (!found && data->assoc_info.req_ies)
1500 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1502 #ifdef CONFIG_IEEE80211R
1504 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1505 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1506 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1507 data->assoc_info.resp_ies,
1508 data->assoc_info.resp_ies_len,
1510 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1511 "Reassociation Response failed");
1512 wpa_supplicant_deauthenticate(
1513 wpa_s, WLAN_REASON_INVALID_IE);
1518 p = data->assoc_info.resp_ies;
1519 l = data->assoc_info.resp_ies_len;
1521 #ifdef CONFIG_WPS_STRICT
1522 if (p && wpa_s->current_ssid &&
1523 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1525 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1527 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1528 "include WPS IE in (Re)Association Response");
1532 if (wps_validate_assoc_resp(wps) < 0) {
1534 wpa_supplicant_deauthenticate(
1535 wpa_s, WLAN_REASON_INVALID_IE);
1540 #endif /* CONFIG_WPS_STRICT */
1542 /* Go through the IEs and make a copy of the MDIE, if present. */
1543 while (p && l >= 2) {
1546 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1550 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1551 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1552 wpa_s->sme.ft_used = 1;
1553 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1554 MOBILITY_DOMAIN_ID_LEN);
1560 #endif /* CONFIG_SME */
1562 /* Process FT when SME is in the driver */
1563 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1564 wpa_ft_is_completed(wpa_s->wpa)) {
1565 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1566 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1567 data->assoc_info.resp_ies,
1568 data->assoc_info.resp_ies_len,
1570 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1571 "Reassociation Response failed");
1572 wpa_supplicant_deauthenticate(
1573 wpa_s, WLAN_REASON_INVALID_IE);
1576 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1579 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1580 data->assoc_info.resp_ies_len);
1581 #endif /* CONFIG_IEEE80211R */
1583 /* WPA/RSN IE from Beacon/ProbeResp */
1584 p = data->assoc_info.beacon_ies;
1585 l = data->assoc_info.beacon_ies_len;
1587 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1589 wpa_found = rsn_found = 0;
1590 while (p && l >= 2) {
1593 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1598 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1599 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1601 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1605 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1607 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1614 if (!wpa_found && data->assoc_info.beacon_ies)
1615 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1616 if (!rsn_found && data->assoc_info.beacon_ies)
1617 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1618 if (wpa_found || rsn_found)
1619 wpa_s->ap_ies_from_associnfo = 1;
1621 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1622 wpa_s->assoc_freq != data->assoc_info.freq) {
1623 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1625 wpa_s->assoc_freq, data->assoc_info.freq);
1626 wpa_supplicant_update_scan_results(wpa_s);
1629 wpa_s->assoc_freq = data->assoc_info.freq;
1635 static struct wpa_bss * wpa_supplicant_get_new_bss(
1636 struct wpa_supplicant *wpa_s, const u8 *bssid)
1638 struct wpa_bss *bss = NULL;
1639 struct wpa_ssid *ssid = wpa_s->current_ssid;
1641 if (ssid->ssid_len > 0)
1642 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1644 bss = wpa_bss_get_bssid(wpa_s, bssid);
1650 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1652 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1654 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1657 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1660 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1661 WPA_IE_VENDOR_TYPE);
1662 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1664 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1665 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1666 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1667 bss_rsn ? 2 + bss_rsn[1] : 0))
1674 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1675 union wpa_event_data *data)
1681 if (wpa_s->ap_iface) {
1682 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1683 data->assoc_info.addr,
1684 data->assoc_info.req_ies,
1685 data->assoc_info.req_ies_len,
1686 data->assoc_info.reassoc);
1689 #endif /* CONFIG_AP */
1691 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1692 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1695 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1696 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1697 wpa_supplicant_deauthenticate(
1698 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1702 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1703 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1704 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1705 MACSTR, MAC2STR(bssid));
1706 random_add_randomness(bssid, ETH_ALEN);
1707 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1708 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1709 wpas_notify_bssid_changed(wpa_s);
1711 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1712 wpa_clear_keys(wpa_s, bssid);
1714 if (wpa_supplicant_select_config(wpa_s) < 0) {
1715 wpa_supplicant_deauthenticate(
1716 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1719 if (wpa_s->current_ssid) {
1720 struct wpa_bss *bss = NULL;
1722 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1724 wpa_supplicant_update_scan_results(wpa_s);
1726 /* Get the BSS from the new scan results */
1727 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1731 wpa_s->current_bss = bss;
1734 if (wpa_s->conf->ap_scan == 1 &&
1735 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1736 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1737 wpa_msg(wpa_s, MSG_WARNING,
1738 "WPA/RSN IEs not updated");
1743 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1744 wpa_s->sme.prev_bssid_set = 1;
1745 #endif /* CONFIG_SME */
1747 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1748 if (wpa_s->current_ssid) {
1749 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1750 * initialized before association, but for other modes,
1751 * initialize PC/SC here, if the current configuration needs
1752 * smartcard or SIM/USIM. */
1753 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1755 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1757 l2_packet_notify_auth_start(wpa_s->l2);
1760 * Set portEnabled first to FALSE in order to get EAP state machine out
1761 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1762 * state machine may transit to AUTHENTICATING state based on obsolete
1763 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1764 * AUTHENTICATED without ever giving chance to EAP state machine to
1767 if (!ft_completed) {
1768 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1769 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1771 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1772 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1773 /* 802.1X::portControl = Auto */
1774 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1775 wpa_s->eapol_received = 0;
1776 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1777 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1778 (wpa_s->current_ssid &&
1779 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1780 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1782 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1784 * Set the key after having received joined-IBSS event
1787 wpa_supplicant_set_wpa_none_key(wpa_s,
1788 wpa_s->current_ssid);
1790 wpa_supplicant_cancel_auth_timeout(wpa_s);
1791 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1792 } else if (!ft_completed) {
1793 /* Timeout for receiving the first EAPOL packet */
1794 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1796 wpa_supplicant_cancel_scan(wpa_s);
1798 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1799 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1801 * We are done; the driver will take care of RSN 4-way
1804 wpa_supplicant_cancel_auth_timeout(wpa_s);
1805 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1806 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1807 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1808 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1809 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1811 * The driver will take care of RSN 4-way handshake, so we need
1812 * to allow EAPOL supplicant to complete its work without
1813 * waiting for WPA supplicant.
1815 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1816 } else if (ft_completed) {
1818 * FT protocol completed - make sure EAPOL state machine ends
1819 * up in authenticated.
1821 wpa_supplicant_cancel_auth_timeout(wpa_s);
1822 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1823 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1824 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1827 wpa_s->last_eapol_matches_bssid = 0;
1829 if (wpa_s->pending_eapol_rx) {
1830 struct os_time now, age;
1832 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1833 if (age.sec == 0 && age.usec < 100000 &&
1834 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1836 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1837 "frame that was received just before "
1838 "association notification");
1839 wpa_supplicant_rx_eapol(
1840 wpa_s, wpa_s->pending_eapol_rx_src,
1841 wpabuf_head(wpa_s->pending_eapol_rx),
1842 wpabuf_len(wpa_s->pending_eapol_rx));
1844 wpabuf_free(wpa_s->pending_eapol_rx);
1845 wpa_s->pending_eapol_rx = NULL;
1848 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1849 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1850 wpa_s->current_ssid &&
1851 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1852 /* Set static WEP keys again */
1853 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1856 #ifdef CONFIG_IBSS_RSN
1857 if (wpa_s->current_ssid &&
1858 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1859 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1860 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1861 wpa_s->ibss_rsn == NULL) {
1862 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1863 if (!wpa_s->ibss_rsn) {
1864 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1865 wpa_supplicant_deauthenticate(
1866 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1870 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1872 #endif /* CONFIG_IBSS_RSN */
1874 wpas_wps_notify_assoc(wpa_s, bssid);
1878 static int disconnect_reason_recoverable(u16 reason_code)
1880 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1881 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1882 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1886 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1888 int locally_generated)
1892 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1894 * At least Host AP driver and a Prism3 card seemed to be
1895 * generating streams of disconnected events when configuring
1896 * IBSS for WPA-None. Ignore them for now.
1901 bssid = wpa_s->bssid;
1902 if (is_zero_ether_addr(bssid))
1903 bssid = wpa_s->pending_bssid;
1905 if (!is_zero_ether_addr(bssid) ||
1906 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1907 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1909 MAC2STR(bssid), reason_code,
1910 locally_generated ? " locally_generated=1" : "");
1915 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1916 int locally_generated)
1918 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1919 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1920 return 0; /* Not in 4-way handshake with PSK */
1923 * It looks like connection was lost while trying to go through PSK
1924 * 4-way handshake. Filter out known disconnection cases that are caused
1925 * by something else than PSK mismatch to avoid confusing reports.
1928 if (locally_generated) {
1929 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1937 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1939 int locally_generated)
1943 u8 prev_pending_bssid[ETH_ALEN];
1944 struct wpa_bss *fast_reconnect = NULL;
1945 struct wpa_ssid *fast_reconnect_ssid = NULL;
1946 struct wpa_ssid *last_ssid;
1948 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1949 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1951 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1953 * At least Host AP driver and a Prism3 card seemed to be
1954 * generating streams of disconnected events when configuring
1955 * IBSS for WPA-None. Ignore them for now.
1957 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1958 "IBSS/WPA-None mode");
1962 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
1963 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1964 "pre-shared key may be incorrect");
1965 wpas_auth_failed(wpa_s);
1967 if (!wpa_s->disconnected &&
1968 (!wpa_s->auto_reconnect_disabled ||
1969 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
1970 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1971 "reconnect (wps=%d wpa_state=%d)",
1972 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1974 if (wpa_s->wpa_state == WPA_COMPLETED &&
1975 wpa_s->current_ssid &&
1976 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1977 !locally_generated &&
1978 disconnect_reason_recoverable(reason_code)) {
1980 * It looks like the AP has dropped association with
1981 * us, but could allow us to get back in. Try to
1982 * reconnect to the same BSS without full scan to save
1983 * time for some common cases.
1985 fast_reconnect = wpa_s->current_bss;
1986 fast_reconnect_ssid = wpa_s->current_ssid;
1987 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1988 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1990 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1993 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1994 "try to re-connect");
1995 wpa_s->reassociate = 0;
1996 wpa_s->disconnected = 1;
1997 wpa_supplicant_cancel_sched_scan(wpa_s);
1999 bssid = wpa_s->bssid;
2000 if (is_zero_ether_addr(bssid))
2001 bssid = wpa_s->pending_bssid;
2002 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2003 wpas_connection_failed(wpa_s, bssid);
2004 wpa_sm_notify_disassoc(wpa_s->wpa);
2005 if (locally_generated)
2006 wpa_s->disconnect_reason = -reason_code;
2008 wpa_s->disconnect_reason = reason_code;
2009 wpas_notify_disconnect_reason(wpa_s);
2010 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2011 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2012 wpa_s->keys_cleared = 0;
2013 wpa_clear_keys(wpa_s, wpa_s->bssid);
2015 last_ssid = wpa_s->current_ssid;
2016 wpa_supplicant_mark_disassoc(wpa_s);
2018 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
2019 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
2020 wpa_s->current_ssid = last_ssid;
2023 if (fast_reconnect) {
2024 #ifndef CONFIG_NO_SCAN_PROCESSING
2025 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2026 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2027 fast_reconnect_ssid) < 0) {
2028 /* Recover through full scan */
2029 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2031 #endif /* CONFIG_NO_SCAN_PROCESSING */
2036 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2037 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
2039 struct wpa_supplicant *wpa_s = eloop_ctx;
2041 if (!wpa_s->pending_mic_error_report)
2044 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2045 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2046 wpa_s->pending_mic_error_report = 0;
2048 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2052 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2053 union wpa_event_data *data)
2058 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2059 pairwise = (data && data->michael_mic_failure.unicast);
2061 if ((wpa_s->last_michael_mic_error &&
2062 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2063 wpa_s->pending_mic_error_report) {
2064 if (wpa_s->pending_mic_error_report) {
2066 * Send the pending MIC error report immediately since
2067 * we are going to start countermeasures and AP better
2070 wpa_sm_key_request(wpa_s->wpa, 1,
2071 wpa_s->pending_mic_error_pairwise);
2074 /* Send the new MIC error report immediately since we are going
2075 * to start countermeasures and AP better do the same.
2077 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2079 /* initialize countermeasures */
2080 wpa_s->countermeasures = 1;
2082 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2084 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2087 * Need to wait for completion of request frame. We do not get
2088 * any callback for the message completion, so just wait a
2089 * short while and hope for the best. */
2092 wpa_drv_set_countermeasures(wpa_s, 1);
2093 wpa_supplicant_deauthenticate(wpa_s,
2094 WLAN_REASON_MICHAEL_MIC_FAILURE);
2095 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2097 eloop_register_timeout(60, 0,
2098 wpa_supplicant_stop_countermeasures,
2100 /* TODO: mark the AP rejected for 60 second. STA is
2101 * allowed to associate with another AP.. */
2103 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2104 if (wpa_s->mic_errors_seen) {
2106 * Reduce the effectiveness of Michael MIC error
2107 * reports as a means for attacking against TKIP if
2108 * more than one MIC failure is noticed with the same
2109 * PTK. We delay the transmission of the reports by a
2110 * random time between 0 and 60 seconds in order to
2111 * force the attacker wait 60 seconds before getting
2112 * the information on whether a frame resulted in a MIC
2118 if (os_get_random(rval, sizeof(rval)) < 0)
2119 sec = os_random() % 60;
2121 sec = WPA_GET_BE32(rval) % 60;
2122 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2123 "report %d seconds", sec);
2124 wpa_s->pending_mic_error_report = 1;
2125 wpa_s->pending_mic_error_pairwise = pairwise;
2126 eloop_cancel_timeout(
2127 wpa_supplicant_delayed_mic_error_report,
2129 eloop_register_timeout(
2130 sec, os_random() % 1000000,
2131 wpa_supplicant_delayed_mic_error_report,
2134 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2136 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2137 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2138 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2140 wpa_s->last_michael_mic_error = t.sec;
2141 wpa_s->mic_errors_seen++;
2145 #ifdef CONFIG_TERMINATE_ONLASTIF
2146 static int any_interfaces(struct wpa_supplicant *head)
2148 struct wpa_supplicant *wpa_s;
2150 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2151 if (!wpa_s->interface_removed)
2155 #endif /* CONFIG_TERMINATE_ONLASTIF */
2159 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2160 union wpa_event_data *data)
2162 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2165 switch (data->interface_status.ievent) {
2166 case EVENT_INTERFACE_ADDED:
2167 if (!wpa_s->interface_removed)
2169 wpa_s->interface_removed = 0;
2170 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2171 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2172 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2173 "driver after interface was added");
2175 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2177 case EVENT_INTERFACE_REMOVED:
2178 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2179 wpa_s->interface_removed = 1;
2180 wpa_supplicant_mark_disassoc(wpa_s);
2181 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2182 l2_packet_deinit(wpa_s->l2);
2184 #ifdef CONFIG_IBSS_RSN
2185 ibss_rsn_deinit(wpa_s->ibss_rsn);
2186 wpa_s->ibss_rsn = NULL;
2187 #endif /* CONFIG_IBSS_RSN */
2188 #ifdef CONFIG_TERMINATE_ONLASTIF
2189 /* check if last interface */
2190 if (!any_interfaces(wpa_s->global->ifaces))
2192 #endif /* CONFIG_TERMINATE_ONLASTIF */
2198 #ifdef CONFIG_PEERKEY
2200 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2201 union wpa_event_data *data)
2205 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2207 #endif /* CONFIG_PEERKEY */
2211 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2212 union wpa_event_data *data)
2216 switch (data->tdls.oper) {
2217 case TDLS_REQUEST_SETUP:
2218 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2219 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2220 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2222 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
2224 case TDLS_REQUEST_TEARDOWN:
2225 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2226 data->tdls.reason_code);
2230 #endif /* CONFIG_TDLS */
2234 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2235 union wpa_event_data *data)
2239 switch (data->wnm.oper) {
2240 case WNM_OPER_SLEEP:
2241 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2242 "(action=%d, intval=%d)",
2243 data->wnm.sleep_action, data->wnm.sleep_intval);
2244 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2245 data->wnm.sleep_intval, NULL);
2249 #endif /* CONFIG_WNM */
2252 #ifdef CONFIG_IEEE80211R
2254 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2255 union wpa_event_data *data)
2260 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2261 data->ft_ies.ies_len,
2262 data->ft_ies.ft_action,
2263 data->ft_ies.target_ap,
2264 data->ft_ies.ric_ies,
2265 data->ft_ies.ric_ies_len) < 0) {
2266 /* TODO: prevent MLME/driver from trying to associate? */
2269 #endif /* CONFIG_IEEE80211R */
2272 #ifdef CONFIG_IBSS_RSN
2273 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2274 union wpa_event_data *data)
2276 struct wpa_ssid *ssid;
2277 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2281 ssid = wpa_s->current_ssid;
2284 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2287 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2289 #endif /* CONFIG_IBSS_RSN */
2292 #ifdef CONFIG_IEEE80211R
2293 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2296 const u8 *sta_addr, *target_ap_addr;
2299 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2300 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2301 return; /* only SME case supported for now */
2302 if (len < 1 + 2 * ETH_ALEN + 2)
2305 return; /* Only FT Action Response is supported for now */
2306 sta_addr = data + 1;
2307 target_ap_addr = data + 1 + ETH_ALEN;
2308 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2309 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2310 MACSTR " TargetAP " MACSTR " status %u",
2311 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2313 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2314 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2315 " in FT Action Response", MAC2STR(sta_addr));
2320 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2321 "failure (status code %d)", status);
2322 /* TODO: report error to FT code(?) */
2326 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2327 len - (1 + 2 * ETH_ALEN + 2), 1,
2328 target_ap_addr, NULL, 0) < 0)
2333 struct wpa_bss *bss;
2334 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2336 wpa_s->sme.freq = bss->freq;
2337 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2338 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2341 #endif /* CONFIG_SME */
2343 #endif /* CONFIG_IEEE80211R */
2346 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2347 struct unprot_deauth *e)
2349 #ifdef CONFIG_IEEE80211W
2350 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2351 "dropped: " MACSTR " -> " MACSTR
2352 " (reason code %u)",
2353 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2354 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2355 #endif /* CONFIG_IEEE80211W */
2359 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2360 struct unprot_disassoc *e)
2362 #ifdef CONFIG_IEEE80211W
2363 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2364 "dropped: " MACSTR " -> " MACSTR
2365 " (reason code %u)",
2366 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2367 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2368 #endif /* CONFIG_IEEE80211W */
2372 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2373 union wpa_event_data *data)
2375 struct wpa_supplicant *wpa_s = ctx;
2376 u16 reason_code = 0;
2377 int locally_generated = 0;
2379 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2380 event != EVENT_INTERFACE_ENABLED &&
2381 event != EVENT_INTERFACE_STATUS &&
2382 event != EVENT_SCHED_SCAN_STOPPED) {
2383 wpa_dbg(wpa_s, MSG_DEBUG,
2384 "Ignore event %s (%d) while interface is disabled",
2385 event_to_string(event), event);
2389 #ifndef CONFIG_NO_STDOUT_DEBUG
2391 int level = MSG_DEBUG;
2393 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2394 const struct ieee80211_hdr *hdr;
2396 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2397 fc = le_to_host16(hdr->frame_control);
2398 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2399 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2400 level = MSG_EXCESSIVE;
2403 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2404 event_to_string(event), event);
2406 #endif /* CONFIG_NO_STDOUT_DEBUG */
2410 sme_event_auth(wpa_s, data);
2413 wpa_supplicant_event_assoc(wpa_s, data);
2415 case EVENT_DISASSOC:
2416 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2418 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2419 data->disassoc_info.reason_code,
2420 data->disassoc_info.locally_generated ?
2421 " (locally generated)" : "");
2422 if (data->disassoc_info.addr)
2423 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2424 MAC2STR(data->disassoc_info.addr));
2427 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2428 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2429 data->disassoc_info.addr);
2432 if (wpa_s->ap_iface) {
2433 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2437 #endif /* CONFIG_AP */
2439 reason_code = data->disassoc_info.reason_code;
2441 data->disassoc_info.locally_generated;
2442 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2443 data->disassoc_info.ie,
2444 data->disassoc_info.ie_len);
2446 wpas_p2p_disassoc_notif(
2447 wpa_s, data->disassoc_info.addr, reason_code,
2448 data->disassoc_info.ie,
2449 data->disassoc_info.ie_len,
2451 #endif /* CONFIG_P2P */
2453 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2454 sme_event_disassoc(wpa_s, data);
2457 if (event == EVENT_DEAUTH) {
2458 wpa_dbg(wpa_s, MSG_DEBUG,
2459 "Deauthentication notification");
2461 reason_code = data->deauth_info.reason_code;
2463 data->deauth_info.locally_generated;
2464 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2465 data->deauth_info.reason_code,
2466 data->deauth_info.locally_generated ?
2467 " (locally generated)" : "");
2468 if (data->deauth_info.addr) {
2469 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2471 MAC2STR(data->deauth_info.
2474 wpa_hexdump(MSG_DEBUG,
2475 "Deauthentication frame IE(s)",
2476 data->deauth_info.ie,
2477 data->deauth_info.ie_len);
2479 wpa_reset_ft_completed(wpa_s->wpa);
2482 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2483 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2484 data->deauth_info.addr);
2487 if (wpa_s->ap_iface) {
2488 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2492 #endif /* CONFIG_AP */
2493 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2495 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2496 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2497 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2498 eapol_sm_failed(wpa_s->eapol)))
2499 wpas_auth_failed(wpa_s);
2501 if (event == EVENT_DEAUTH && data) {
2502 if (wpas_p2p_deauth_notif(wpa_s,
2503 data->deauth_info.addr,
2505 data->deauth_info.ie,
2506 data->deauth_info.ie_len,
2507 locally_generated) > 0) {
2509 * The interface was removed, so cannot
2510 * continue processing any additional
2511 * operations after this.
2516 #endif /* CONFIG_P2P */
2517 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2520 case EVENT_MICHAEL_MIC_FAILURE:
2521 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2523 #ifndef CONFIG_NO_SCAN_PROCESSING
2524 case EVENT_SCAN_RESULTS:
2525 wpa_supplicant_event_scan_results(wpa_s, data);
2526 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2527 wpa_s->wpa_state != WPA_ASSOCIATING)
2528 wpas_p2p_continue_after_scan(wpa_s);
2530 #endif /* CONFIG_NO_SCAN_PROCESSING */
2531 case EVENT_ASSOCINFO:
2532 wpa_supplicant_event_associnfo(wpa_s, data);
2534 case EVENT_INTERFACE_STATUS:
2535 wpa_supplicant_event_interface_status(wpa_s, data);
2537 case EVENT_PMKID_CANDIDATE:
2538 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2540 #ifdef CONFIG_PEERKEY
2541 case EVENT_STKSTART:
2542 wpa_supplicant_event_stkstart(wpa_s, data);
2544 #endif /* CONFIG_PEERKEY */
2547 wpa_supplicant_event_tdls(wpa_s, data);
2549 #endif /* CONFIG_TDLS */
2552 wpa_supplicant_event_wnm(wpa_s, data);
2554 #endif /* CONFIG_WNM */
2555 #ifdef CONFIG_IEEE80211R
2556 case EVENT_FT_RESPONSE:
2557 wpa_supplicant_event_ft_response(wpa_s, data);
2559 #endif /* CONFIG_IEEE80211R */
2560 #ifdef CONFIG_IBSS_RSN
2561 case EVENT_IBSS_RSN_START:
2562 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2564 #endif /* CONFIG_IBSS_RSN */
2565 case EVENT_ASSOC_REJECT:
2566 if (data->assoc_reject.bssid)
2567 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2568 "bssid=" MACSTR " status_code=%u",
2569 MAC2STR(data->assoc_reject.bssid),
2570 data->assoc_reject.status_code);
2572 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2574 data->assoc_reject.status_code);
2575 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2576 sme_event_assoc_reject(wpa_s, data);
2578 const u8 *bssid = data->assoc_reject.bssid;
2579 if (bssid == NULL || is_zero_ether_addr(bssid))
2580 bssid = wpa_s->pending_bssid;
2581 wpas_connection_failed(wpa_s, bssid);
2582 wpa_supplicant_mark_disassoc(wpa_s);
2585 case EVENT_AUTH_TIMED_OUT:
2586 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2587 sme_event_auth_timed_out(wpa_s, data);
2589 case EVENT_ASSOC_TIMED_OUT:
2590 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2591 sme_event_assoc_timed_out(wpa_s, data);
2593 case EVENT_TX_STATUS:
2594 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2595 " type=%d stype=%d",
2596 MAC2STR(data->tx_status.dst),
2597 data->tx_status.type, data->tx_status.stype);
2599 if (wpa_s->ap_iface == NULL) {
2600 #ifdef CONFIG_OFFCHANNEL
2601 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2602 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2603 offchannel_send_action_tx_status(
2604 wpa_s, data->tx_status.dst,
2605 data->tx_status.data,
2606 data->tx_status.data_len,
2607 data->tx_status.ack ?
2608 OFFCHANNEL_SEND_ACTION_SUCCESS :
2609 OFFCHANNEL_SEND_ACTION_NO_ACK);
2610 #endif /* CONFIG_OFFCHANNEL */
2613 #endif /* CONFIG_AP */
2614 #ifdef CONFIG_OFFCHANNEL
2615 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2616 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2618 * Catch TX status events for Action frames we sent via group
2619 * interface in GO mode.
2621 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2622 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2623 os_memcmp(wpa_s->parent->pending_action_dst,
2624 data->tx_status.dst, ETH_ALEN) == 0) {
2625 offchannel_send_action_tx_status(
2626 wpa_s->parent, data->tx_status.dst,
2627 data->tx_status.data,
2628 data->tx_status.data_len,
2629 data->tx_status.ack ?
2630 OFFCHANNEL_SEND_ACTION_SUCCESS :
2631 OFFCHANNEL_SEND_ACTION_NO_ACK);
2634 #endif /* CONFIG_OFFCHANNEL */
2636 switch (data->tx_status.type) {
2637 case WLAN_FC_TYPE_MGMT:
2638 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2639 data->tx_status.data_len,
2640 data->tx_status.stype,
2641 data->tx_status.ack);
2643 case WLAN_FC_TYPE_DATA:
2644 ap_tx_status(wpa_s, data->tx_status.dst,
2645 data->tx_status.data,
2646 data->tx_status.data_len,
2647 data->tx_status.ack);
2650 #endif /* CONFIG_AP */
2653 case EVENT_EAPOL_TX_STATUS:
2654 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2655 data->eapol_tx_status.data,
2656 data->eapol_tx_status.data_len,
2657 data->eapol_tx_status.ack);
2659 case EVENT_DRIVER_CLIENT_POLL_OK:
2660 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2662 case EVENT_RX_FROM_UNKNOWN:
2663 if (wpa_s->ap_iface == NULL)
2665 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2666 data->rx_from_unknown.wds);
2668 case EVENT_CH_SWITCH:
2671 if (!wpa_s->ap_iface) {
2672 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2673 "event in non-AP mode");
2678 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2679 data->ch_switch.ht_enabled,
2680 data->ch_switch.ch_offset);
2681 #endif /* CONFIG_AP */
2683 case EVENT_RX_MGMT: {
2685 const struct ieee80211_mgmt *mgmt;
2687 mgmt = (const struct ieee80211_mgmt *)
2688 data->rx_mgmt.frame;
2689 fc = le_to_host16(mgmt->frame_control);
2690 stype = WLAN_FC_GET_STYPE(fc);
2692 if (wpa_s->ap_iface == NULL) {
2694 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2695 data->rx_mgmt.frame_len > 24) {
2696 const u8 *src = mgmt->sa;
2697 const u8 *ie = mgmt->u.probe_req.variable;
2698 size_t ie_len = data->rx_mgmt.frame_len -
2699 (mgmt->u.probe_req.variable -
2700 data->rx_mgmt.frame);
2701 wpas_p2p_probe_req_rx(
2702 wpa_s, src, mgmt->da,
2703 mgmt->bssid, ie, ie_len,
2704 data->rx_mgmt.ssi_signal);
2707 #endif /* CONFIG_P2P */
2708 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2709 "management frame in non-AP mode");
2713 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2714 data->rx_mgmt.frame_len > 24) {
2715 const u8 *ie = mgmt->u.probe_req.variable;
2716 size_t ie_len = data->rx_mgmt.frame_len -
2717 (mgmt->u.probe_req.variable -
2718 data->rx_mgmt.frame);
2720 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2721 mgmt->bssid, ie, ie_len,
2722 data->rx_mgmt.ssi_signal);
2725 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2728 #endif /* CONFIG_AP */
2729 case EVENT_RX_ACTION:
2730 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2731 " Category=%u DataLen=%d freq=%d MHz",
2732 MAC2STR(data->rx_action.sa),
2733 data->rx_action.category, (int) data->rx_action.len,
2734 data->rx_action.freq);
2735 #ifdef CONFIG_IEEE80211R
2736 if (data->rx_action.category == WLAN_ACTION_FT) {
2737 ft_rx_action(wpa_s, data->rx_action.data,
2738 data->rx_action.len);
2741 #endif /* CONFIG_IEEE80211R */
2742 #ifdef CONFIG_IEEE80211W
2744 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2745 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2746 data->rx_action.data,
2747 data->rx_action.len);
2750 #endif /* CONFIG_SME */
2751 #endif /* CONFIG_IEEE80211W */
2753 if (data->rx_action.category == WLAN_ACTION_WNM) {
2754 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2757 #endif /* CONFIG_WNM */
2759 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2760 gas_query_rx(wpa_s->gas, data->rx_action.da,
2761 data->rx_action.sa, data->rx_action.bssid,
2762 data->rx_action.data, data->rx_action.len,
2763 data->rx_action.freq) == 0)
2765 #endif /* CONFIG_GAS */
2767 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2768 data->rx_action.len >= 4 &&
2769 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2770 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2771 "Response from " MACSTR,
2772 MAC2STR(data->rx_action.sa));
2775 #endif /* CONFIG_TDLS */
2777 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2779 data->rx_action.bssid,
2780 data->rx_action.category,
2781 data->rx_action.data,
2782 data->rx_action.len, data->rx_action.freq);
2783 #endif /* CONFIG_P2P */
2785 case EVENT_RX_PROBE_REQ:
2786 if (data->rx_probe_req.sa == NULL ||
2787 data->rx_probe_req.ie == NULL)
2790 if (wpa_s->ap_iface) {
2791 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2792 data->rx_probe_req.sa,
2793 data->rx_probe_req.da,
2794 data->rx_probe_req.bssid,
2795 data->rx_probe_req.ie,
2796 data->rx_probe_req.ie_len,
2797 data->rx_probe_req.ssi_signal);
2800 #endif /* CONFIG_AP */
2802 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2803 data->rx_probe_req.da,
2804 data->rx_probe_req.bssid,
2805 data->rx_probe_req.ie,
2806 data->rx_probe_req.ie_len,
2807 data->rx_probe_req.ssi_signal);
2808 #endif /* CONFIG_P2P */
2810 case EVENT_REMAIN_ON_CHANNEL:
2811 #ifdef CONFIG_OFFCHANNEL
2812 offchannel_remain_on_channel_cb(
2813 wpa_s, data->remain_on_channel.freq,
2814 data->remain_on_channel.duration);
2815 #endif /* CONFIG_OFFCHANNEL */
2817 wpas_p2p_remain_on_channel_cb(
2818 wpa_s, data->remain_on_channel.freq,
2819 data->remain_on_channel.duration);
2820 #endif /* CONFIG_P2P */
2822 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2823 #ifdef CONFIG_OFFCHANNEL
2824 offchannel_cancel_remain_on_channel_cb(
2825 wpa_s, data->remain_on_channel.freq);
2826 #endif /* CONFIG_OFFCHANNEL */
2828 wpas_p2p_cancel_remain_on_channel_cb(
2829 wpa_s, data->remain_on_channel.freq);
2830 #endif /* CONFIG_P2P */
2833 case EVENT_P2P_DEV_FOUND: {
2834 struct p2p_peer_info peer_info;
2836 os_memset(&peer_info, 0, sizeof(peer_info));
2837 if (data->p2p_dev_found.dev_addr)
2838 os_memcpy(peer_info.p2p_device_addr,
2839 data->p2p_dev_found.dev_addr, ETH_ALEN);
2840 if (data->p2p_dev_found.pri_dev_type)
2841 os_memcpy(peer_info.pri_dev_type,
2842 data->p2p_dev_found.pri_dev_type,
2843 sizeof(peer_info.pri_dev_type));
2844 if (data->p2p_dev_found.dev_name)
2845 os_strlcpy(peer_info.device_name,
2846 data->p2p_dev_found.dev_name,
2847 sizeof(peer_info.device_name));
2848 peer_info.config_methods = data->p2p_dev_found.config_methods;
2849 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2850 peer_info.group_capab = data->p2p_dev_found.group_capab;
2853 * FIX: new_device=1 is not necessarily correct. We should
2854 * maintain a P2P peer database in wpa_supplicant and update
2855 * this information based on whether the peer is truly new.
2857 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2860 case EVENT_P2P_GO_NEG_REQ_RX:
2861 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2862 data->p2p_go_neg_req_rx.dev_passwd_id);
2864 case EVENT_P2P_GO_NEG_COMPLETED:
2865 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2867 case EVENT_P2P_PROV_DISC_REQUEST:
2868 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2869 data->p2p_prov_disc_req.config_methods,
2870 data->p2p_prov_disc_req.dev_addr,
2871 data->p2p_prov_disc_req.pri_dev_type,
2872 data->p2p_prov_disc_req.dev_name,
2873 data->p2p_prov_disc_req.supp_config_methods,
2874 data->p2p_prov_disc_req.dev_capab,
2875 data->p2p_prov_disc_req.group_capab,
2878 case EVENT_P2P_PROV_DISC_RESPONSE:
2879 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2880 data->p2p_prov_disc_resp.config_methods);
2882 case EVENT_P2P_SD_REQUEST:
2883 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2884 data->p2p_sd_req.sa,
2885 data->p2p_sd_req.dialog_token,
2886 data->p2p_sd_req.update_indic,
2887 data->p2p_sd_req.tlvs,
2888 data->p2p_sd_req.tlvs_len);
2890 case EVENT_P2P_SD_RESPONSE:
2891 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2892 data->p2p_sd_resp.update_indic,
2893 data->p2p_sd_resp.tlvs,
2894 data->p2p_sd_resp.tlvs_len);
2896 #endif /* CONFIG_P2P */
2897 case EVENT_EAPOL_RX:
2898 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2899 data->eapol_rx.data,
2900 data->eapol_rx.data_len);
2902 case EVENT_SIGNAL_CHANGE:
2903 bgscan_notify_signal_change(
2904 wpa_s, data->signal_change.above_threshold,
2905 data->signal_change.current_signal,
2906 data->signal_change.current_noise,
2907 data->signal_change.current_txrate);
2909 case EVENT_INTERFACE_ENABLED:
2910 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2911 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2912 wpa_supplicant_update_mac_addr(wpa_s);
2914 if (!wpa_s->ap_iface) {
2915 wpa_supplicant_set_state(wpa_s,
2917 wpa_supplicant_req_scan(wpa_s, 0, 0);
2919 wpa_supplicant_set_state(wpa_s,
2921 #else /* CONFIG_AP */
2922 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2923 wpa_supplicant_req_scan(wpa_s, 0, 0);
2924 #endif /* CONFIG_AP */
2927 case EVENT_INTERFACE_DISABLED:
2928 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2929 wpa_supplicant_mark_disassoc(wpa_s);
2930 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2932 case EVENT_CHANNEL_LIST_CHANGED:
2933 if (wpa_s->drv_priv == NULL)
2934 break; /* Ignore event during drv initialization */
2936 free_hw_features(wpa_s);
2937 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2938 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2941 wpas_p2p_update_channel_list(wpa_s);
2942 #endif /* CONFIG_P2P */
2944 case EVENT_INTERFACE_UNAVAILABLE:
2946 wpas_p2p_interface_unavailable(wpa_s);
2947 #endif /* CONFIG_P2P */
2949 case EVENT_BEST_CHANNEL:
2950 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2952 data->best_chan.freq_24, data->best_chan.freq_5,
2953 data->best_chan.freq_overall);
2954 wpa_s->best_24_freq = data->best_chan.freq_24;
2955 wpa_s->best_5_freq = data->best_chan.freq_5;
2956 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2958 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2959 data->best_chan.freq_5,
2960 data->best_chan.freq_overall);
2961 #endif /* CONFIG_P2P */
2963 case EVENT_UNPROT_DEAUTH:
2964 wpa_supplicant_event_unprot_deauth(wpa_s,
2965 &data->unprot_deauth);
2967 case EVENT_UNPROT_DISASSOC:
2968 wpa_supplicant_event_unprot_disassoc(wpa_s,
2969 &data->unprot_disassoc);
2971 case EVENT_STATION_LOW_ACK:
2973 if (wpa_s->ap_iface && data)
2974 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2975 data->low_ack.addr);
2976 #endif /* CONFIG_AP */
2979 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2980 #endif /* CONFIG_TDLS */
2982 case EVENT_IBSS_PEER_LOST:
2983 #ifdef CONFIG_IBSS_RSN
2984 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2985 #endif /* CONFIG_IBSS_RSN */
2987 case EVENT_DRIVER_GTK_REKEY:
2988 if (os_memcmp(data->driver_gtk_rekey.bssid,
2989 wpa_s->bssid, ETH_ALEN))
2993 wpa_sm_update_replay_ctr(wpa_s->wpa,
2994 data->driver_gtk_rekey.replay_ctr);
2996 case EVENT_SCHED_SCAN_STOPPED:
2997 wpa_s->sched_scanning = 0;
2998 wpa_supplicant_notify_scanning(wpa_s, 0);
3000 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3004 * If we timed out, start a new sched scan to continue
3005 * searching for more SSIDs.
3007 if (wpa_s->sched_scan_timed_out)
3008 wpa_supplicant_req_sched_scan(wpa_s);
3010 case EVENT_WPS_BUTTON_PUSHED:
3012 wpas_wps_start_pbc(wpa_s, NULL, 0);
3013 #endif /* CONFIG_WPS */
3015 case EVENT_CONNECT_FAILED_REASON:
3017 if (!wpa_s->ap_iface || !data)
3019 hostapd_event_connect_failed_reason(
3020 wpa_s->ap_iface->bss[0],
3021 data->connect_failed_reason.addr,
3022 data->connect_failed_reason.code);
3023 #endif /* CONFIG_AP */
3026 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);