2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
18 #include "eapol_supp/eapol_supp_sm.h"
19 #include "rsn_supp/wpa.h"
22 #include "l2_packet/l2_packet.h"
23 #include "wpa_supplicant_i.h"
25 #include "pcsc_funcs.h"
26 #include "rsn_supp/preauth.h"
27 #include "rsn_supp/pmksa_cache.h"
28 #include "common/wpa_ctrl.h"
29 #include "eap_peer/eap.h"
30 #include "ap/hostapd.h"
32 #include "common/ieee802_11_defs.h"
33 #include "common/ieee802_11_common.h"
34 #include "blacklist.h"
35 #include "wpas_glue.h"
36 #include "wps_supplicant.h"
39 #include "p2p_supplicant.h"
47 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
49 struct wpa_ssid *ssid, *old_ssid;
51 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
54 wpa_printf(MSG_DEBUG, "Select network based on association "
56 ssid = wpa_supplicant_get_ssid(wpa_s);
58 wpa_printf(MSG_INFO, "No network configuration found for the "
64 wpa_printf(MSG_DEBUG, "Selected network is disabled");
68 wpa_printf(MSG_DEBUG, "Network configuration found for the current "
70 if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
71 WPA_KEY_MGMT_WPA_NONE |
72 WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X |
73 WPA_KEY_MGMT_PSK_SHA256 |
74 WPA_KEY_MGMT_IEEE8021X_SHA256)) {
76 size_t wpa_ie_len = sizeof(wpa_ie);
77 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
80 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
83 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
84 eapol_sm_invalidate_cached_session(wpa_s->eapol);
85 old_ssid = wpa_s->current_ssid;
86 wpa_s->current_ssid = ssid;
87 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
88 wpa_supplicant_initiate_eapol(wpa_s);
89 if (old_ssid != wpa_s->current_ssid)
90 wpas_notify_network_changed(wpa_s);
96 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
99 struct wpa_supplicant *wpa_s = eloop_ctx;
101 if (wpa_s->countermeasures) {
102 wpa_s->countermeasures = 0;
103 wpa_drv_set_countermeasures(wpa_s, 0);
104 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
105 wpa_supplicant_req_scan(wpa_s, 0, 0);
110 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
114 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
117 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
118 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
119 os_memset(wpa_s->bssid, 0, ETH_ALEN);
120 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
121 wpa_s->current_bss = NULL;
123 wpas_notify_bssid_changed(wpa_s);
125 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
126 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
127 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
128 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
129 wpa_s->ap_ies_from_associnfo = 0;
133 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
135 struct wpa_ie_data ie;
139 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
143 for (i = 0; i < ie.num_pmkid; i++) {
144 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
145 ie.pmkid + i * PMKID_LEN,
147 if (pmksa_set == 0) {
148 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
153 wpa_printf(MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from PMKSA "
154 "cache", pmksa_set == 0 ? "" : "not ");
158 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
159 union wpa_event_data *data)
162 wpa_printf(MSG_DEBUG, "RSN: No data in PMKID candidate event");
165 wpa_printf(MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
166 " index=%d preauth=%d",
167 MAC2STR(data->pmkid_candidate.bssid),
168 data->pmkid_candidate.index,
169 data->pmkid_candidate.preauth);
171 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
172 data->pmkid_candidate.index,
173 data->pmkid_candidate.preauth);
177 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
179 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
180 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
183 #ifdef IEEE8021X_EAPOL
184 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
185 wpa_s->current_ssid &&
186 !(wpa_s->current_ssid->eapol_flags &
187 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
188 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
189 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
190 * plaintext or static WEP keys). */
193 #endif /* IEEE8021X_EAPOL */
200 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
201 * @wpa_s: pointer to wpa_supplicant data
202 * @ssid: Configuration data for the network
203 * Returns: 0 on success, -1 on failure
205 * This function is called when starting authentication with a network that is
206 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
208 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
209 struct wpa_ssid *ssid)
211 #ifdef IEEE8021X_EAPOL
212 int aka = 0, sim = 0, type;
214 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
217 if (ssid->eap.eap_methods == NULL) {
221 struct eap_method_type *eap = ssid->eap.eap_methods;
222 while (eap->vendor != EAP_VENDOR_IETF ||
223 eap->method != EAP_TYPE_NONE) {
224 if (eap->vendor == EAP_VENDOR_IETF) {
225 if (eap->method == EAP_TYPE_SIM)
227 else if (eap->method == EAP_TYPE_AKA)
234 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
236 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
240 wpa_printf(MSG_DEBUG, "Selected network is configured to use "
241 "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
245 wpa_printf(MSG_DEBUG, "Selected network is configured to use SIM "
246 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
248 type = SCARD_TRY_BOTH;
250 type = SCARD_USIM_ONLY;
252 type = SCARD_GSM_SIM_ONLY;
254 wpa_s->scard = scard_init(type);
255 if (wpa_s->scard == NULL) {
256 wpa_printf(MSG_WARNING, "Failed to initialize SIM "
260 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
261 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
262 #endif /* IEEE8021X_EAPOL */
268 #ifndef CONFIG_NO_SCAN_PROCESSING
269 static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
270 struct wpa_ssid *ssid)
274 if (ssid->mixed_cell)
278 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
280 #endif /* CONFIG_WPS */
282 for (i = 0; i < NUM_WEP_KEYS; i++) {
283 if (ssid->wep_key_len[i]) {
288 #ifdef IEEE8021X_EAPOL
289 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
290 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
291 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
293 #endif /* IEEE8021X_EAPOL */
295 if (bss->caps & IEEE80211_CAP_PRIVACY)
301 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
302 struct wpa_ssid *ssid,
303 struct wpa_scan_res *bss)
305 struct wpa_ie_data ie;
307 const u8 *rsn_ie, *wpa_ie;
310 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
314 rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
315 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
318 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
319 wpa_printf(MSG_DEBUG, " skip RSN IE - parse failed");
322 if (!(ie.proto & ssid->proto)) {
323 wpa_printf(MSG_DEBUG, " skip RSN IE - proto "
328 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
329 wpa_printf(MSG_DEBUG, " skip RSN IE - PTK cipher "
334 if (!(ie.group_cipher & ssid->group_cipher)) {
335 wpa_printf(MSG_DEBUG, " skip RSN IE - GTK cipher "
340 if (!(ie.key_mgmt & ssid->key_mgmt)) {
341 wpa_printf(MSG_DEBUG, " skip RSN IE - key mgmt "
346 #ifdef CONFIG_IEEE80211W
347 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
348 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
349 wpa_printf(MSG_DEBUG, " skip RSN IE - no mgmt frame "
353 #endif /* CONFIG_IEEE80211W */
355 wpa_printf(MSG_DEBUG, " selected based on RSN IE");
359 wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
360 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
363 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
364 wpa_printf(MSG_DEBUG, " skip WPA IE - parse failed");
367 if (!(ie.proto & ssid->proto)) {
368 wpa_printf(MSG_DEBUG, " skip WPA IE - proto "
373 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
374 wpa_printf(MSG_DEBUG, " skip WPA IE - PTK cipher "
379 if (!(ie.group_cipher & ssid->group_cipher)) {
380 wpa_printf(MSG_DEBUG, " skip WPA IE - GTK cipher "
385 if (!(ie.key_mgmt & ssid->key_mgmt)) {
386 wpa_printf(MSG_DEBUG, " skip WPA IE - key mgmt "
391 wpa_printf(MSG_DEBUG, " selected based on WPA IE");
395 if (proto_match == 0)
396 wpa_printf(MSG_DEBUG, " skip - no WPA/RSN proto match");
402 static int freq_allowed(int *freqs, int freq)
409 for (i = 0; freqs[i]; i++)
410 if (freqs[i] == freq)
416 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
417 int i, struct wpa_scan_res *bss,
418 struct wpa_ssid *group)
421 u8 wpa_ie_len, rsn_ie_len, ssid_len;
423 struct wpa_blacklist *e;
425 struct wpa_ssid *ssid;
427 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
428 ssid_ = ie ? ie + 2 : (u8 *) "";
429 ssid_len = ie ? ie[1] : 0;
431 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
432 wpa_ie_len = ie ? ie[1] : 0;
434 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
435 rsn_ie_len = ie ? ie[1] : 0;
437 wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
438 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
439 i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
440 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
441 wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
444 e = wpa_blacklist_get(wpa_s, bss->bssid);
445 if (e && e->count > 1) {
446 wpa_printf(MSG_DEBUG, " skip - blacklisted");
451 wpa_printf(MSG_DEBUG, " skip - SSID not known");
455 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
457 for (ssid = group; ssid; ssid = ssid->pnext) {
458 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
460 if (ssid->disabled) {
461 wpa_printf(MSG_DEBUG, " skip - disabled");
466 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
467 wpa_printf(MSG_DEBUG, " skip - blacklisted (WPS)");
471 if (wpa && ssid->ssid_len == 0 &&
472 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
475 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
476 /* Only allow wildcard SSID match if an AP
477 * advertises active WPS operation that matches
480 if (ssid->ssid_len == 0 &&
481 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
484 #endif /* CONFIG_WPS */
487 (ssid_len != ssid->ssid_len ||
488 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
489 wpa_printf(MSG_DEBUG, " skip - SSID mismatch");
493 if (ssid->bssid_set &&
494 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
495 wpa_printf(MSG_DEBUG, " skip - BSSID mismatch");
499 if (wpa && !wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
503 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
504 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
505 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
506 wpa_printf(MSG_DEBUG, " skip - non-WPA network not "
511 if (!wpa && !wpa_supplicant_match_privacy(bss, ssid)) {
512 wpa_printf(MSG_DEBUG, " skip - privacy mismatch");
516 if (!wpa && (bss->caps & IEEE80211_CAP_IBSS)) {
517 wpa_printf(MSG_DEBUG, " skip - IBSS (adhoc) "
522 if (!freq_allowed(ssid->freq_list, bss->freq)) {
523 wpa_printf(MSG_DEBUG, " skip - frequency not "
530 * TODO: skip the AP if its P2P IE has Group Formation
531 * bit set in the P2P Group Capability Bitmap and we
532 * are not in Group Formation with that device.
534 #endif /* CONFIG_P2P */
536 /* Matching configuration found */
540 /* No matching configuration found */
545 static struct wpa_bss *
546 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
547 struct wpa_scan_results *scan_res,
548 struct wpa_ssid *group,
549 struct wpa_ssid **selected_ssid)
553 wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d",
556 for (i = 0; i < scan_res->num; i++) {
557 struct wpa_scan_res *bss = scan_res->res[i];
561 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
565 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
566 ssid = ie ? ie + 2 : (u8 *) "";
567 ssid_len = ie ? ie[1] : 0;
569 wpa_printf(MSG_DEBUG, " selected BSS " MACSTR " ssid='%s'",
570 MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
571 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
578 static struct wpa_bss *
579 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
580 struct wpa_scan_results *scan_res,
581 struct wpa_ssid **selected_ssid)
583 struct wpa_bss *selected = NULL;
586 while (selected == NULL) {
587 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
588 selected = wpa_supplicant_select_bss(
589 wpa_s, scan_res, wpa_s->conf->pssid[prio],
595 if (selected == NULL && wpa_s->blacklist) {
596 wpa_printf(MSG_DEBUG, "No APs found - clear blacklist "
598 wpa_blacklist_clear(wpa_s);
599 wpa_s->blacklist_cleared++;
600 } else if (selected == NULL)
608 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
609 int timeout_sec, int timeout_usec)
611 if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
613 * No networks are enabled; short-circuit request so
614 * we don't wait timeout seconds before transitioning
617 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
620 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
624 void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
625 struct wpa_bss *selected,
626 struct wpa_ssid *ssid)
628 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
629 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
630 "PBC session overlap");
632 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
634 #endif /* CONFIG_P2P */
635 wpas_wps_cancel(wpa_s);
640 * Do not trigger new association unless the BSSID has changed or if
641 * reassociation is requested. If we are in process of associating with
642 * the selected BSSID, do not trigger new attempt.
644 if (wpa_s->reassociate ||
645 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
646 (wpa_s->wpa_state != WPA_ASSOCIATING ||
647 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
649 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
650 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
653 wpa_supplicant_associate(wpa_s, selected, ssid);
655 wpa_printf(MSG_DEBUG, "Already associated with the selected "
661 static struct wpa_ssid *
662 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
665 struct wpa_ssid *ssid;
667 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
668 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
672 if (ssid->mode == IEEE80211_MODE_IBSS ||
673 ssid->mode == IEEE80211_MODE_AP)
681 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
682 * on BSS added and BSS changed events */
683 static void wpa_supplicant_rsn_preauth_scan_results(
684 struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res)
688 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
691 for (i = scan_res->num - 1; i >= 0; i--) {
692 const u8 *ssid, *rsn;
693 struct wpa_scan_res *r;
695 r = scan_res->res[i];
697 ssid = wpa_scan_get_ie(r, WLAN_EID_SSID);
701 rsn = wpa_scan_get_ie(r, WLAN_EID_RSN);
705 rsn_preauth_scan_result(wpa_s->wpa, r->bssid, ssid, rsn);
711 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
712 struct wpa_bss *selected,
713 struct wpa_ssid *ssid,
714 struct wpa_scan_results *scan_res)
717 struct wpa_scan_res *current_bss = NULL;
720 if (wpa_s->reassociate)
721 return 1; /* explicit request to reassociate */
722 if (wpa_s->wpa_state < WPA_ASSOCIATED)
723 return 1; /* we are not associated; continue */
724 if (wpa_s->current_ssid == NULL)
725 return 1; /* unknown current SSID */
726 if (wpa_s->current_ssid != ssid)
727 return 1; /* different network block */
729 for (i = 0; i < scan_res->num; i++) {
730 struct wpa_scan_res *res = scan_res->res[i];
732 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
735 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
738 if (ie[1] != wpa_s->current_ssid->ssid_len ||
739 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
746 return 1; /* current BSS not seen in scan results */
748 wpa_printf(MSG_DEBUG, "Considering within-ESS reassociation");
749 wpa_printf(MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
750 MAC2STR(current_bss->bssid), current_bss->level);
751 wpa_printf(MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
752 MAC2STR(selected->bssid), selected->level);
754 if (wpa_s->current_ssid->bssid_set &&
755 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
757 wpa_printf(MSG_DEBUG, "Allow reassociation - selected BSS has "
763 if (current_bss->level < 0) {
764 if (current_bss->level < -85)
766 else if (current_bss->level < -80)
768 else if (current_bss->level < -75)
770 else if (current_bss->level < -70)
775 if (abs(current_bss->level - selected->level) < min_diff) {
776 wpa_printf(MSG_DEBUG, "Skip roam - too small difference in "
785 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
786 union wpa_event_data *data)
788 struct wpa_bss *selected;
789 struct wpa_ssid *ssid = NULL;
790 struct wpa_scan_results *scan_res;
796 #endif /* CONFIG_AP */
798 wpa_supplicant_notify_scanning(wpa_s, 0);
800 scan_res = wpa_supplicant_get_scan_results(wpa_s,
801 data ? &data->scan_info :
803 if (scan_res == NULL) {
804 if (wpa_s->conf->ap_scan == 2 || ap)
806 wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
808 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
812 if (wpa_s->scan_res_handler) {
813 wpa_s->scan_res_handler(wpa_s, scan_res);
814 wpa_s->scan_res_handler = NULL;
815 wpa_scan_results_free(scan_res);
820 wpa_printf(MSG_DEBUG, "Ignore scan results in AP mode");
821 wpa_scan_results_free(scan_res);
825 wpa_printf(MSG_DEBUG, "New scan results available");
826 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
827 wpas_notify_scan_results(wpa_s);
829 wpas_notify_scan_done(wpa_s, 1);
831 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
832 wpa_scan_results_free(scan_res);
836 if (wpa_s->disconnected) {
837 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
838 wpa_scan_results_free(scan_res);
842 if (bgscan_notify_scan(wpa_s, scan_res) == 1) {
843 wpa_scan_results_free(scan_res);
847 wpa_supplicant_rsn_preauth_scan_results(wpa_s, scan_res);
849 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
853 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
855 wpa_scan_results_free(scan_res);
858 wpa_supplicant_connect(wpa_s, selected, ssid);
860 wpa_scan_results_free(scan_res);
861 wpa_printf(MSG_DEBUG, "No suitable network found");
862 ssid = wpa_supplicant_pick_new_network(wpa_s);
864 wpa_printf(MSG_DEBUG, "Setup a new network");
865 wpa_supplicant_associate(wpa_s, NULL, ssid);
868 int timeout_usec = 0;
870 if (wpa_s->p2p_in_provisioning) {
872 * Use shorter wait during P2P Provisioning
873 * state to speed up group formation.
876 timeout_usec = 250000;
878 #endif /* CONFIG_P2P */
879 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
884 #endif /* CONFIG_NO_SCAN_PROCESSING */
887 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
888 union wpa_event_data *data)
890 int l, len, found = 0, wpa_found, rsn_found;
893 wpa_printf(MSG_DEBUG, "Association info event");
894 if (data->assoc_info.req_ies)
895 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
896 data->assoc_info.req_ies_len);
897 if (data->assoc_info.resp_ies)
898 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
899 data->assoc_info.resp_ies_len);
900 if (data->assoc_info.beacon_ies)
901 wpa_hexdump(MSG_DEBUG, "beacon_ies",
902 data->assoc_info.beacon_ies,
903 data->assoc_info.beacon_ies_len);
904 if (data->assoc_info.freq)
905 wpa_printf(MSG_DEBUG, "freq=%u MHz", data->assoc_info.freq);
907 p = data->assoc_info.req_ies;
908 l = data->assoc_info.req_ies_len;
910 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
911 while (p && l >= 2) {
914 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
918 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
919 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
920 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
921 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
924 wpa_find_assoc_pmkid(wpa_s);
930 if (!found && data->assoc_info.req_ies)
931 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
933 #ifdef CONFIG_IEEE80211R
935 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
937 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
938 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
939 data->assoc_info.resp_ies,
940 data->assoc_info.resp_ies_len,
942 wpa_printf(MSG_DEBUG, "FT: Validation of "
943 "Reassociation Response failed");
944 wpa_supplicant_deauthenticate(
945 wpa_s, WLAN_REASON_INVALID_IE);
950 p = data->assoc_info.resp_ies;
951 l = data->assoc_info.resp_ies_len;
953 #ifdef CONFIG_WPS_STRICT
954 if (wpa_s->current_ssid &&
955 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
957 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
959 wpa_printf(MSG_INFO, "WPS-STRICT: AP did not include "
960 "WPS IE in (Re)Association Response");
964 if (wps_validate_assoc_resp(wps) < 0) {
966 wpa_supplicant_deauthenticate(
967 wpa_s, WLAN_REASON_INVALID_IE);
972 #endif /* CONFIG_WPS_STRICT */
974 /* Go through the IEs and make a copy of the MDIE, if present. */
975 while (p && l >= 2) {
978 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
982 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
983 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
984 wpa_s->sme.ft_used = 1;
985 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
986 MOBILITY_DOMAIN_ID_LEN);
992 #endif /* CONFIG_SME */
994 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
995 data->assoc_info.resp_ies_len);
996 #endif /* CONFIG_IEEE80211R */
998 /* WPA/RSN IE from Beacon/ProbeResp */
999 p = data->assoc_info.beacon_ies;
1000 l = data->assoc_info.beacon_ies_len;
1002 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1004 wpa_found = rsn_found = 0;
1005 while (p && l >= 2) {
1008 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1013 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1014 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1016 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1020 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1022 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1029 if (!wpa_found && data->assoc_info.beacon_ies)
1030 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1031 if (!rsn_found && data->assoc_info.beacon_ies)
1032 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1033 if (wpa_found || rsn_found)
1034 wpa_s->ap_ies_from_associnfo = 1;
1036 wpa_s->assoc_freq = data->assoc_info.freq;
1042 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1043 union wpa_event_data *data)
1048 struct wpa_driver_capa capa;
1051 if (wpa_s->ap_iface) {
1052 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1053 data->assoc_info.addr,
1054 data->assoc_info.req_ies,
1055 data->assoc_info.req_ies_len);
1058 #endif /* CONFIG_AP */
1060 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1061 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1064 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1065 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
1066 os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
1067 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
1068 (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
1069 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
1070 wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1071 MACSTR, MAC2STR(bssid));
1072 bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
1073 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1074 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1076 wpas_notify_bssid_changed(wpa_s);
1078 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1079 wpa_clear_keys(wpa_s, bssid);
1081 if (wpa_supplicant_select_config(wpa_s) < 0) {
1082 wpa_supplicant_disassociate(
1083 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1086 if (wpa_s->current_ssid) {
1087 struct wpa_bss *bss = NULL;
1088 struct wpa_ssid *ssid = wpa_s->current_ssid;
1089 if (ssid->ssid_len > 0)
1090 bss = wpa_bss_get(wpa_s, bssid,
1091 ssid->ssid, ssid->ssid_len);
1093 bss = wpa_bss_get_bssid(wpa_s, bssid);
1095 wpa_s->current_bss = bss;
1100 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1101 wpa_s->sme.prev_bssid_set = 1;
1102 #endif /* CONFIG_SME */
1104 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1105 if (wpa_s->current_ssid) {
1106 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1107 * initialized before association, but for other modes,
1108 * initialize PC/SC here, if the current configuration needs
1109 * smartcard or SIM/USIM. */
1110 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1112 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1114 l2_packet_notify_auth_start(wpa_s->l2);
1117 * Set portEnabled first to FALSE in order to get EAP state machine out
1118 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1119 * state machine may transit to AUTHENTICATING state based on obsolete
1120 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1121 * AUTHENTICATED without ever giving chance to EAP state machine to
1124 if (!ft_completed) {
1125 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1126 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1128 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1129 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1130 /* 802.1X::portControl = Auto */
1131 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1132 wpa_s->eapol_received = 0;
1133 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1134 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1135 (wpa_s->current_ssid &&
1136 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1137 wpa_supplicant_cancel_auth_timeout(wpa_s);
1138 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1139 } else if (!ft_completed) {
1140 /* Timeout for receiving the first EAPOL packet */
1141 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1143 wpa_supplicant_cancel_scan(wpa_s);
1145 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1146 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1148 * We are done; the driver will take care of RSN 4-way
1151 wpa_supplicant_cancel_auth_timeout(wpa_s);
1152 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1153 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1154 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1157 if (wpa_s->pending_eapol_rx) {
1158 struct os_time now, age;
1160 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1161 if (age.sec == 0 && age.usec < 100000 &&
1162 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1164 wpa_printf(MSG_DEBUG, "Process pending EAPOL frame "
1165 "that was received just before association "
1167 wpa_supplicant_rx_eapol(
1168 wpa_s, wpa_s->pending_eapol_rx_src,
1169 wpabuf_head(wpa_s->pending_eapol_rx),
1170 wpabuf_len(wpa_s->pending_eapol_rx));
1172 wpabuf_free(wpa_s->pending_eapol_rx);
1173 wpa_s->pending_eapol_rx = NULL;
1176 #ifdef CONFIG_BGSCAN
1177 if (wpa_s->current_ssid != wpa_s->bgscan_ssid) {
1178 bgscan_deinit(wpa_s);
1179 if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) {
1180 if (bgscan_init(wpa_s, wpa_s->current_ssid)) {
1181 wpa_printf(MSG_DEBUG, "Failed to initialize "
1184 * Live without bgscan; it is only used as a
1185 * roaming optimization, so the initial
1186 * connection is not affected.
1189 wpa_s->bgscan_ssid = wpa_s->current_ssid;
1191 wpa_s->bgscan_ssid = NULL;
1193 #endif /* CONFIG_BGSCAN */
1195 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1196 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1197 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1198 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1199 /* Set static WEP keys again */
1200 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1205 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1211 u8 prev_pending_bssid[ETH_ALEN];
1213 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1214 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1215 #endif /* CONFIG_SME */
1217 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1219 * At least Host AP driver and a Prism3 card seemed to be
1220 * generating streams of disconnected events when configuring
1221 * IBSS for WPA-None. Ignore them for now.
1223 wpa_printf(MSG_DEBUG, "Disconnect event - ignore in "
1224 "IBSS/WPA-None mode");
1228 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1229 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1230 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1231 "pre-shared key may be incorrect");
1233 if (!wpa_s->auto_reconnect_disabled ||
1234 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1235 wpa_printf(MSG_DEBUG, "WPA: Auto connect enabled: try to "
1236 "reconnect (wps=%d)",
1237 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS);
1238 if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1239 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1241 wpa_printf(MSG_DEBUG, "WPA: Auto connect disabled: do not try "
1243 wpa_s->reassociate = 0;
1244 wpa_s->disconnected = 1;
1246 bssid = wpa_s->bssid;
1247 if (is_zero_ether_addr(bssid))
1248 bssid = wpa_s->pending_bssid;
1249 wpa_blacklist_add(wpa_s, bssid);
1250 wpa_sm_notify_disassoc(wpa_s->wpa);
1251 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1253 MAC2STR(bssid), reason_code);
1254 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1255 wpa_printf(MSG_DEBUG, "Disconnect event - remove keys");
1256 wpa_s->keys_cleared = 0;
1257 wpa_clear_keys(wpa_s, wpa_s->bssid);
1259 wpa_supplicant_mark_disassoc(wpa_s);
1260 bgscan_deinit(wpa_s);
1261 wpa_s->bgscan_ssid = NULL;
1263 if (authenticating &&
1264 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
1266 * mac80211-workaround to force deauth on failed auth cmd,
1267 * requires us to remain in authenticating state to allow the
1268 * second authentication attempt to be continued properly.
1270 wpa_printf(MSG_DEBUG, "SME: Allow pending authentication to "
1271 "proceed after disconnection event");
1272 wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
1273 os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN);
1275 #endif /* CONFIG_SME */
1279 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1280 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
1283 struct wpa_supplicant *wpa_s = eloop_ctx;
1285 if (!wpa_s->pending_mic_error_report)
1288 wpa_printf(MSG_DEBUG, "WPA: Sending pending MIC error report");
1289 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1290 wpa_s->pending_mic_error_report = 0;
1292 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1296 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1297 union wpa_event_data *data)
1302 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1303 pairwise = (data && data->michael_mic_failure.unicast);
1305 if ((wpa_s->last_michael_mic_error &&
1306 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1307 wpa_s->pending_mic_error_report) {
1308 if (wpa_s->pending_mic_error_report) {
1310 * Send the pending MIC error report immediately since
1311 * we are going to start countermeasures and AP better
1314 wpa_sm_key_request(wpa_s->wpa, 1,
1315 wpa_s->pending_mic_error_pairwise);
1318 /* Send the new MIC error report immediately since we are going
1319 * to start countermeasures and AP better do the same.
1321 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1323 /* initialize countermeasures */
1324 wpa_s->countermeasures = 1;
1325 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1328 * Need to wait for completion of request frame. We do not get
1329 * any callback for the message completion, so just wait a
1330 * short while and hope for the best. */
1333 wpa_drv_set_countermeasures(wpa_s, 1);
1334 wpa_supplicant_deauthenticate(wpa_s,
1335 WLAN_REASON_MICHAEL_MIC_FAILURE);
1336 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1338 eloop_register_timeout(60, 0,
1339 wpa_supplicant_stop_countermeasures,
1341 /* TODO: mark the AP rejected for 60 second. STA is
1342 * allowed to associate with another AP.. */
1344 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1345 if (wpa_s->mic_errors_seen) {
1347 * Reduce the effectiveness of Michael MIC error
1348 * reports as a means for attacking against TKIP if
1349 * more than one MIC failure is noticed with the same
1350 * PTK. We delay the transmission of the reports by a
1351 * random time between 0 and 60 seconds in order to
1352 * force the attacker wait 60 seconds before getting
1353 * the information on whether a frame resulted in a MIC
1359 if (os_get_random(rval, sizeof(rval)) < 0)
1360 sec = os_random() % 60;
1362 sec = WPA_GET_BE32(rval) % 60;
1363 wpa_printf(MSG_DEBUG, "WPA: Delay MIC error report %d "
1365 wpa_s->pending_mic_error_report = 1;
1366 wpa_s->pending_mic_error_pairwise = pairwise;
1367 eloop_cancel_timeout(
1368 wpa_supplicant_delayed_mic_error_report,
1370 eloop_register_timeout(
1371 sec, os_random() % 1000000,
1372 wpa_supplicant_delayed_mic_error_report,
1375 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1377 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1378 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1379 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1381 wpa_s->last_michael_mic_error = t.sec;
1382 wpa_s->mic_errors_seen++;
1386 #ifdef CONFIG_TERMINATE_ONLASTIF
1387 static int any_interfaces(struct wpa_supplicant *head)
1389 struct wpa_supplicant *wpa_s;
1391 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1392 if (!wpa_s->interface_removed)
1396 #endif /* CONFIG_TERMINATE_ONLASTIF */
1400 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1401 union wpa_event_data *data)
1403 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1406 switch (data->interface_status.ievent) {
1407 case EVENT_INTERFACE_ADDED:
1408 if (!wpa_s->interface_removed)
1410 wpa_s->interface_removed = 0;
1411 wpa_printf(MSG_DEBUG, "Configured interface was added.");
1412 if (wpa_supplicant_driver_init(wpa_s) < 0) {
1413 wpa_printf(MSG_INFO, "Failed to initialize the driver "
1414 "after interface was added.");
1417 case EVENT_INTERFACE_REMOVED:
1418 wpa_printf(MSG_DEBUG, "Configured interface was removed.");
1419 wpa_s->interface_removed = 1;
1420 wpa_supplicant_mark_disassoc(wpa_s);
1421 l2_packet_deinit(wpa_s->l2);
1423 #ifdef CONFIG_TERMINATE_ONLASTIF
1424 /* check if last interface */
1425 if (!any_interfaces(wpa_s->global->ifaces))
1427 #endif /* CONFIG_TERMINATE_ONLASTIF */
1433 #ifdef CONFIG_PEERKEY
1435 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
1436 union wpa_event_data *data)
1440 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
1442 #endif /* CONFIG_PEERKEY */
1445 #ifdef CONFIG_IEEE80211R
1447 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
1448 union wpa_event_data *data)
1453 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
1454 data->ft_ies.ies_len,
1455 data->ft_ies.ft_action,
1456 data->ft_ies.target_ap,
1457 data->ft_ies.ric_ies,
1458 data->ft_ies.ric_ies_len) < 0) {
1459 /* TODO: prevent MLME/driver from trying to associate? */
1462 #endif /* CONFIG_IEEE80211R */
1465 #ifdef CONFIG_IBSS_RSN
1466 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
1467 union wpa_event_data *data)
1471 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
1473 #endif /* CONFIG_IBSS_RSN */
1476 #ifdef CONFIG_IEEE80211R
1477 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
1480 const u8 *sta_addr, *target_ap_addr;
1483 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
1484 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1485 return; /* only SME case supported for now */
1486 if (len < 1 + 2 * ETH_ALEN + 2)
1489 return; /* Only FT Action Response is supported for now */
1490 sta_addr = data + 1;
1491 target_ap_addr = data + 1 + ETH_ALEN;
1492 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
1493 wpa_printf(MSG_DEBUG, "FT: Received FT Action Response: STA " MACSTR
1494 " TargetAP " MACSTR " status %u",
1495 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
1497 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
1498 wpa_printf(MSG_DEBUG, "FT: Foreign STA Address " MACSTR
1499 " in FT Action Response", MAC2STR(sta_addr));
1504 wpa_printf(MSG_DEBUG, "FT: FT Action Response indicates "
1505 "failure (status code %d)", status);
1506 /* TODO: report error to FT code(?) */
1510 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
1511 len - (1 + 2 * ETH_ALEN + 2), 1,
1512 target_ap_addr, NULL, 0) < 0)
1517 struct wpa_bss *bss;
1518 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
1520 wpa_s->sme.freq = bss->freq;
1521 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
1522 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
1525 #endif /* CONFIG_SME */
1527 #endif /* CONFIG_IEEE80211R */
1530 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1531 union wpa_event_data *data)
1533 struct wpa_supplicant *wpa_s = ctx;
1534 u16 reason_code = 0;
1536 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
1537 event != EVENT_INTERFACE_ENABLED &&
1538 event != EVENT_INTERFACE_STATUS) {
1539 wpa_printf(MSG_DEBUG, "Ignore event %d while interface is "
1544 wpa_printf(MSG_DEBUG, "Event %d received on interface %s",
1545 event, wpa_s->ifname);
1549 sme_event_auth(wpa_s, data);
1552 wpa_supplicant_event_assoc(wpa_s, data);
1554 case EVENT_DISASSOC:
1555 wpa_printf(MSG_DEBUG, "Disassociation notification");
1557 wpa_printf(MSG_DEBUG, " * reason %u",
1558 data->disassoc_info.reason_code);
1559 if (data->disassoc_info.addr)
1560 wpa_printf(MSG_DEBUG, " * address " MACSTR,
1561 MAC2STR(data->disassoc_info.addr));
1564 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
1565 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1566 data->disassoc_info.addr);
1569 #endif /* CONFIG_AP */
1571 reason_code = data->disassoc_info.reason_code;
1572 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
1573 data->disassoc_info.ie,
1574 data->disassoc_info.ie_len);
1576 wpas_p2p_disassoc_notif(
1577 wpa_s, data->disassoc_info.addr, reason_code,
1578 data->disassoc_info.ie,
1579 data->disassoc_info.ie_len);
1580 #endif /* CONFIG_P2P */
1582 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
1583 sme_event_disassoc(wpa_s, data);
1586 if (event == EVENT_DEAUTH) {
1587 wpa_printf(MSG_DEBUG, "Deauthentication notification");
1589 reason_code = data->deauth_info.reason_code;
1590 wpa_printf(MSG_DEBUG, " * reason %u",
1591 data->deauth_info.reason_code);
1592 if (data->deauth_info.addr) {
1593 wpa_printf(MSG_DEBUG, " * address "
1595 MAC2STR(data->deauth_info.
1598 wpa_hexdump(MSG_DEBUG,
1599 "Deauthentication frame IE(s)",
1600 data->deauth_info.ie,
1601 data->deauth_info.ie_len);
1603 wpas_p2p_deauth_notif(
1604 wpa_s, data->deauth_info.addr,
1606 data->deauth_info.ie,
1607 data->deauth_info.ie_len);
1608 #endif /* CONFIG_P2P */
1612 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
1613 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1614 data->deauth_info.addr);
1617 #endif /* CONFIG_AP */
1618 wpa_supplicant_event_disassoc(wpa_s, reason_code);
1620 case EVENT_MICHAEL_MIC_FAILURE:
1621 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
1623 #ifndef CONFIG_NO_SCAN_PROCESSING
1624 case EVENT_SCAN_RESULTS:
1625 wpa_supplicant_event_scan_results(wpa_s, data);
1627 #endif /* CONFIG_NO_SCAN_PROCESSING */
1628 case EVENT_ASSOCINFO:
1629 wpa_supplicant_event_associnfo(wpa_s, data);
1631 case EVENT_INTERFACE_STATUS:
1632 wpa_supplicant_event_interface_status(wpa_s, data);
1634 case EVENT_PMKID_CANDIDATE:
1635 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
1637 #ifdef CONFIG_PEERKEY
1638 case EVENT_STKSTART:
1639 wpa_supplicant_event_stkstart(wpa_s, data);
1641 #endif /* CONFIG_PEERKEY */
1642 #ifdef CONFIG_IEEE80211R
1643 case EVENT_FT_RESPONSE:
1644 wpa_supplicant_event_ft_response(wpa_s, data);
1646 #endif /* CONFIG_IEEE80211R */
1647 #ifdef CONFIG_IBSS_RSN
1648 case EVENT_IBSS_RSN_START:
1649 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
1651 #endif /* CONFIG_IBSS_RSN */
1652 case EVENT_ASSOC_REJECT:
1653 sme_event_assoc_reject(wpa_s, data);
1655 case EVENT_AUTH_TIMED_OUT:
1656 sme_event_auth_timed_out(wpa_s, data);
1658 case EVENT_ASSOC_TIMED_OUT:
1659 sme_event_assoc_timed_out(wpa_s, data);
1662 case EVENT_TX_STATUS:
1663 wpa_printf(MSG_DEBUG, "EVENT_TX_STATUS on %s dst=" MACSTR
1664 " type=%d stype=%d pending_dst=" MACSTR,
1665 wpa_s->ifname, MAC2STR(data->tx_status.dst),
1666 data->tx_status.type, data->tx_status.stype,
1667 MAC2STR(wpa_s->parent->pending_action_dst));
1668 if (wpa_s->ap_iface == NULL) {
1670 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
1671 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
1672 wpas_send_action_tx_status(
1673 wpa_s, data->tx_status.dst,
1674 data->tx_status.data,
1675 data->tx_status.data_len,
1676 data->tx_status.ack);
1677 #endif /* CONFIG_P2P */
1682 * Catch TX status events for Action frames we sent via group
1683 * interface in GO mode.
1685 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
1686 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
1687 os_memcmp(wpa_s->parent->pending_action_dst,
1688 data->tx_status.dst, ETH_ALEN) == 0) {
1689 wpas_send_action_tx_status(
1690 wpa_s->parent, data->tx_status.dst,
1691 data->tx_status.data,
1692 data->tx_status.data_len,
1693 data->tx_status.ack);
1696 #endif /* CONFIG_P2P */
1697 switch (data->tx_status.type) {
1698 case WLAN_FC_TYPE_MGMT:
1699 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
1700 data->tx_status.data_len,
1701 data->tx_status.stype,
1702 data->tx_status.ack);
1704 case WLAN_FC_TYPE_DATA:
1705 ap_tx_status(wpa_s, data->tx_status.dst,
1706 data->tx_status.data,
1707 data->tx_status.data_len,
1708 data->tx_status.ack);
1712 case EVENT_RX_FROM_UNKNOWN:
1713 if (wpa_s->ap_iface == NULL)
1715 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
1716 data->rx_from_unknown.len);
1719 if (wpa_s->ap_iface == NULL) {
1722 const struct ieee80211_mgmt *mgmt;
1723 mgmt = (const struct ieee80211_mgmt *)
1724 data->rx_mgmt.frame;
1725 fc = le_to_host16(mgmt->frame_control);
1726 stype = WLAN_FC_GET_STYPE(fc);
1727 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
1728 data->rx_mgmt.frame_len > 24) {
1729 const u8 *src = mgmt->sa;
1730 const u8 *ie = mgmt->u.probe_req.variable;
1731 size_t ie_len = data->rx_mgmt.frame_len -
1732 (mgmt->u.probe_req.variable -
1733 data->rx_mgmt.frame);
1734 wpas_p2p_probe_req_rx(wpa_s, src, ie, ie_len);
1737 #endif /* CONFIG_P2P */
1738 wpa_printf(MSG_DEBUG, "AP: ignore received management "
1739 "frame in non-AP mode");
1742 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
1744 #endif /* CONFIG_AP */
1745 case EVENT_RX_ACTION:
1746 wpa_printf(MSG_DEBUG, "Received Action frame: SA=" MACSTR
1747 " Category=%u DataLen=%d freq=%d MHz",
1748 MAC2STR(data->rx_action.sa),
1749 data->rx_action.category, (int) data->rx_action.len,
1750 data->rx_action.freq);
1751 #ifdef CONFIG_IEEE80211R
1752 if (data->rx_action.category == WLAN_ACTION_FT) {
1753 ft_rx_action(wpa_s, data->rx_action.data,
1754 data->rx_action.len);
1757 #endif /* CONFIG_IEEE80211R */
1759 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
1761 data->rx_action.bssid,
1762 data->rx_action.category,
1763 data->rx_action.data,
1764 data->rx_action.len, data->rx_action.freq);
1765 #endif /* CONFIG_P2P */
1768 case EVENT_REMAIN_ON_CHANNEL:
1769 wpas_p2p_remain_on_channel_cb(
1770 wpa_s, data->remain_on_channel.freq,
1771 data->remain_on_channel.duration);
1773 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
1774 wpas_p2p_cancel_remain_on_channel_cb(
1775 wpa_s, data->remain_on_channel.freq);
1777 case EVENT_RX_PROBE_REQ:
1778 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
1779 data->rx_probe_req.ie,
1780 data->rx_probe_req.ie_len);
1782 #endif /* CONFIG_P2P */
1783 #ifdef CONFIG_CLIENT_MLME
1784 case EVENT_MLME_RX: {
1785 struct ieee80211_rx_status rx_status;
1786 os_memset(&rx_status, 0, sizeof(rx_status));
1787 rx_status.freq = data->mlme_rx.freq;
1788 rx_status.channel = data->mlme_rx.channel;
1789 rx_status.ssi = data->mlme_rx.ssi;
1790 ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
1794 #endif /* CONFIG_CLIENT_MLME */
1795 case EVENT_EAPOL_RX:
1796 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
1797 data->eapol_rx.data,
1798 data->eapol_rx.data_len);
1800 case EVENT_SIGNAL_CHANGE:
1801 bgscan_notify_signal_change(
1802 wpa_s, data->signal_change.above_threshold,
1803 data->signal_change.current_signal);
1805 case EVENT_INTERFACE_ENABLED:
1806 wpa_printf(MSG_DEBUG, "Interface was enabled");
1807 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
1808 wpa_supplicant_set_state(wpa_s,
1810 wpa_supplicant_req_scan(wpa_s, 0, 0);
1813 case EVENT_INTERFACE_DISABLED:
1814 wpa_printf(MSG_DEBUG, "Interface was disabled");
1815 wpa_supplicant_mark_disassoc(wpa_s);
1816 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
1819 wpa_printf(MSG_INFO, "Unknown event %d", event);