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"
33 #include "common/ieee802_11_defs.h"
34 #include "common/ieee802_11_common.h"
35 #include "blacklist.h"
36 #include "wpas_glue.h"
37 #include "wps_supplicant.h"
40 #include "p2p_supplicant.h"
48 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
50 struct wpa_ssid *ssid, *old_ssid;
52 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
55 wpa_printf(MSG_DEBUG, "Select network based on association "
57 ssid = wpa_supplicant_get_ssid(wpa_s);
59 wpa_printf(MSG_INFO, "No network configuration found for the "
65 wpa_printf(MSG_DEBUG, "Selected network is disabled");
69 wpa_printf(MSG_DEBUG, "Network configuration found for the current "
71 if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
72 WPA_KEY_MGMT_WPA_NONE |
73 WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X |
74 WPA_KEY_MGMT_PSK_SHA256 |
75 WPA_KEY_MGMT_IEEE8021X_SHA256)) {
77 size_t wpa_ie_len = sizeof(wpa_ie);
78 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
81 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
84 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
85 eapol_sm_invalidate_cached_session(wpa_s->eapol);
86 old_ssid = wpa_s->current_ssid;
87 wpa_s->current_ssid = ssid;
88 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
89 wpa_supplicant_initiate_eapol(wpa_s);
90 if (old_ssid != wpa_s->current_ssid)
91 wpas_notify_network_changed(wpa_s);
97 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
100 struct wpa_supplicant *wpa_s = eloop_ctx;
102 if (wpa_s->countermeasures) {
103 wpa_s->countermeasures = 0;
104 wpa_drv_set_countermeasures(wpa_s, 0);
105 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
106 wpa_supplicant_req_scan(wpa_s, 0, 0);
111 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
115 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
118 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
119 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
120 os_memset(wpa_s->bssid, 0, ETH_ALEN);
121 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
122 wpa_s->current_bss = NULL;
124 wpas_notify_bssid_changed(wpa_s);
126 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
127 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
128 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
129 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
130 wpa_s->ap_ies_from_associnfo = 0;
134 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
136 struct wpa_ie_data ie;
140 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
144 for (i = 0; i < ie.num_pmkid; i++) {
145 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
146 ie.pmkid + i * PMKID_LEN,
148 if (pmksa_set == 0) {
149 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
154 wpa_printf(MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from PMKSA "
155 "cache", pmksa_set == 0 ? "" : "not ");
159 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
160 union wpa_event_data *data)
163 wpa_printf(MSG_DEBUG, "RSN: No data in PMKID candidate event");
166 wpa_printf(MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
167 " index=%d preauth=%d",
168 MAC2STR(data->pmkid_candidate.bssid),
169 data->pmkid_candidate.index,
170 data->pmkid_candidate.preauth);
172 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
173 data->pmkid_candidate.index,
174 data->pmkid_candidate.preauth);
178 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
180 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
181 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
184 #ifdef IEEE8021X_EAPOL
185 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
186 wpa_s->current_ssid &&
187 !(wpa_s->current_ssid->eapol_flags &
188 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
189 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
190 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
191 * plaintext or static WEP keys). */
194 #endif /* IEEE8021X_EAPOL */
201 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
202 * @wpa_s: pointer to wpa_supplicant data
203 * @ssid: Configuration data for the network
204 * Returns: 0 on success, -1 on failure
206 * This function is called when starting authentication with a network that is
207 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
209 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
210 struct wpa_ssid *ssid)
212 #ifdef IEEE8021X_EAPOL
213 int aka = 0, sim = 0, type;
215 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
218 if (ssid->eap.eap_methods == NULL) {
222 struct eap_method_type *eap = ssid->eap.eap_methods;
223 while (eap->vendor != EAP_VENDOR_IETF ||
224 eap->method != EAP_TYPE_NONE) {
225 if (eap->vendor == EAP_VENDOR_IETF) {
226 if (eap->method == EAP_TYPE_SIM)
228 else if (eap->method == EAP_TYPE_AKA)
235 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
237 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
241 wpa_printf(MSG_DEBUG, "Selected network is configured to use "
242 "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
246 wpa_printf(MSG_DEBUG, "Selected network is configured to use SIM "
247 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
249 type = SCARD_TRY_BOTH;
251 type = SCARD_USIM_ONLY;
253 type = SCARD_GSM_SIM_ONLY;
255 wpa_s->scard = scard_init(type);
256 if (wpa_s->scard == NULL) {
257 wpa_printf(MSG_WARNING, "Failed to initialize SIM "
261 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
262 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
263 #endif /* IEEE8021X_EAPOL */
269 #ifndef CONFIG_NO_SCAN_PROCESSING
270 static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
271 struct wpa_ssid *ssid)
275 if (ssid->mixed_cell)
279 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
281 #endif /* CONFIG_WPS */
283 for (i = 0; i < NUM_WEP_KEYS; i++) {
284 if (ssid->wep_key_len[i]) {
289 #ifdef IEEE8021X_EAPOL
290 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
291 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
292 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
294 #endif /* IEEE8021X_EAPOL */
296 if (bss->caps & IEEE80211_CAP_PRIVACY)
302 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
303 struct wpa_ssid *ssid,
304 struct wpa_scan_res *bss)
306 struct wpa_ie_data ie;
308 const u8 *rsn_ie, *wpa_ie;
311 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
315 rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
316 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
319 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
320 wpa_printf(MSG_DEBUG, " skip RSN IE - parse failed");
323 if (!(ie.proto & ssid->proto)) {
324 wpa_printf(MSG_DEBUG, " skip RSN IE - proto "
329 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
330 wpa_printf(MSG_DEBUG, " skip RSN IE - PTK cipher "
335 if (!(ie.group_cipher & ssid->group_cipher)) {
336 wpa_printf(MSG_DEBUG, " skip RSN IE - GTK cipher "
341 if (!(ie.key_mgmt & ssid->key_mgmt)) {
342 wpa_printf(MSG_DEBUG, " skip RSN IE - key mgmt "
347 #ifdef CONFIG_IEEE80211W
348 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
349 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
350 wpa_printf(MSG_DEBUG, " skip RSN IE - no mgmt frame "
354 #endif /* CONFIG_IEEE80211W */
356 wpa_printf(MSG_DEBUG, " selected based on RSN IE");
360 wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
361 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
364 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
365 wpa_printf(MSG_DEBUG, " skip WPA IE - parse failed");
368 if (!(ie.proto & ssid->proto)) {
369 wpa_printf(MSG_DEBUG, " skip WPA IE - proto "
374 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
375 wpa_printf(MSG_DEBUG, " skip WPA IE - PTK cipher "
380 if (!(ie.group_cipher & ssid->group_cipher)) {
381 wpa_printf(MSG_DEBUG, " skip WPA IE - GTK cipher "
386 if (!(ie.key_mgmt & ssid->key_mgmt)) {
387 wpa_printf(MSG_DEBUG, " skip WPA IE - key mgmt "
392 wpa_printf(MSG_DEBUG, " selected based on WPA IE");
396 if (proto_match == 0)
397 wpa_printf(MSG_DEBUG, " skip - no WPA/RSN proto match");
403 static int freq_allowed(int *freqs, int freq)
410 for (i = 0; freqs[i]; i++)
411 if (freqs[i] == freq)
417 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
418 int i, struct wpa_scan_res *bss,
419 struct wpa_ssid *group)
422 u8 wpa_ie_len, rsn_ie_len, ssid_len;
424 struct wpa_blacklist *e;
426 struct wpa_ssid *ssid;
428 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
429 ssid_ = ie ? ie + 2 : (u8 *) "";
430 ssid_len = ie ? ie[1] : 0;
432 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
433 wpa_ie_len = ie ? ie[1] : 0;
435 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
436 rsn_ie_len = ie ? ie[1] : 0;
438 wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
439 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
440 i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
441 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
442 wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ?
445 e = wpa_blacklist_get(wpa_s, bss->bssid);
446 if (e && e->count > 1) {
447 wpa_printf(MSG_DEBUG, " skip - blacklisted");
452 wpa_printf(MSG_DEBUG, " skip - SSID not known");
456 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
458 for (ssid = group; ssid; ssid = ssid->pnext) {
459 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
461 if (ssid->disabled) {
462 wpa_printf(MSG_DEBUG, " skip - disabled");
467 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
468 wpa_printf(MSG_DEBUG, " skip - blacklisted (WPS)");
472 if (wpa && ssid->ssid_len == 0 &&
473 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
476 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
477 /* Only allow wildcard SSID match if an AP
478 * advertises active WPS operation that matches
481 if (ssid->ssid_len == 0 &&
482 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
485 #endif /* CONFIG_WPS */
488 (ssid_len != ssid->ssid_len ||
489 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
490 wpa_printf(MSG_DEBUG, " skip - SSID mismatch");
494 if (ssid->bssid_set &&
495 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
496 wpa_printf(MSG_DEBUG, " skip - BSSID mismatch");
500 if (wpa && !wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
504 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
505 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
506 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
507 wpa_printf(MSG_DEBUG, " skip - non-WPA network not "
512 if (!wpa && !wpa_supplicant_match_privacy(bss, ssid)) {
513 wpa_printf(MSG_DEBUG, " skip - privacy mismatch");
517 if (!wpa && (bss->caps & IEEE80211_CAP_IBSS)) {
518 wpa_printf(MSG_DEBUG, " skip - IBSS (adhoc) "
523 if (!freq_allowed(ssid->freq_list, bss->freq)) {
524 wpa_printf(MSG_DEBUG, " skip - frequency not "
531 * TODO: skip the AP if its P2P IE has Group Formation
532 * bit set in the P2P Group Capability Bitmap and we
533 * are not in Group Formation with that device.
535 #endif /* CONFIG_P2P */
537 /* Matching configuration found */
541 /* No matching configuration found */
546 static struct wpa_bss *
547 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
548 struct wpa_scan_results *scan_res,
549 struct wpa_ssid *group,
550 struct wpa_ssid **selected_ssid)
554 wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d",
557 for (i = 0; i < scan_res->num; i++) {
558 struct wpa_scan_res *bss = scan_res->res[i];
562 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
566 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
567 ssid = ie ? ie + 2 : (u8 *) "";
568 ssid_len = ie ? ie[1] : 0;
570 wpa_printf(MSG_DEBUG, " selected BSS " MACSTR " ssid='%s'",
571 MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
572 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
579 static struct wpa_bss *
580 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
581 struct wpa_scan_results *scan_res,
582 struct wpa_ssid **selected_ssid)
584 struct wpa_bss *selected = NULL;
587 while (selected == NULL) {
588 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
589 selected = wpa_supplicant_select_bss(
590 wpa_s, scan_res, wpa_s->conf->pssid[prio],
596 if (selected == NULL && wpa_s->blacklist) {
597 wpa_printf(MSG_DEBUG, "No APs found - clear blacklist "
599 wpa_blacklist_clear(wpa_s);
600 wpa_s->blacklist_cleared++;
601 } else if (selected == NULL)
609 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
610 int timeout_sec, int timeout_usec)
612 if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
614 * No networks are enabled; short-circuit request so
615 * we don't wait timeout seconds before transitioning
618 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
621 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
625 void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
626 struct wpa_bss *selected,
627 struct wpa_ssid *ssid)
629 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
630 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
631 "PBC session overlap");
633 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
635 #endif /* CONFIG_P2P */
638 wpas_wps_cancel(wpa_s);
639 #endif /* CONFIG_WPS */
644 * Do not trigger new association unless the BSSID has changed or if
645 * reassociation is requested. If we are in process of associating with
646 * the selected BSSID, do not trigger new attempt.
648 if (wpa_s->reassociate ||
649 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
650 (wpa_s->wpa_state != WPA_ASSOCIATING ||
651 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
653 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
654 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
657 wpa_supplicant_associate(wpa_s, selected, ssid);
659 wpa_printf(MSG_DEBUG, "Already associated with the selected "
665 static struct wpa_ssid *
666 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
669 struct wpa_ssid *ssid;
671 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
672 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
676 if (ssid->mode == IEEE80211_MODE_IBSS ||
677 ssid->mode == IEEE80211_MODE_AP)
685 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
686 * on BSS added and BSS changed events */
687 static void wpa_supplicant_rsn_preauth_scan_results(
688 struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res)
692 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
695 for (i = scan_res->num - 1; i >= 0; i--) {
696 const u8 *ssid, *rsn;
697 struct wpa_scan_res *r;
699 r = scan_res->res[i];
701 ssid = wpa_scan_get_ie(r, WLAN_EID_SSID);
705 rsn = wpa_scan_get_ie(r, WLAN_EID_RSN);
709 rsn_preauth_scan_result(wpa_s->wpa, r->bssid, ssid, rsn);
715 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
716 struct wpa_bss *selected,
717 struct wpa_ssid *ssid,
718 struct wpa_scan_results *scan_res)
721 struct wpa_scan_res *current_bss = NULL;
724 if (wpa_s->reassociate)
725 return 1; /* explicit request to reassociate */
726 if (wpa_s->wpa_state < WPA_ASSOCIATED)
727 return 1; /* we are not associated; continue */
728 if (wpa_s->current_ssid == NULL)
729 return 1; /* unknown current SSID */
730 if (wpa_s->current_ssid != ssid)
731 return 1; /* different network block */
733 for (i = 0; i < scan_res->num; i++) {
734 struct wpa_scan_res *res = scan_res->res[i];
736 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
739 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
742 if (ie[1] != wpa_s->current_ssid->ssid_len ||
743 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
750 return 1; /* current BSS not seen in scan results */
752 wpa_printf(MSG_DEBUG, "Considering within-ESS reassociation");
753 wpa_printf(MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
754 MAC2STR(current_bss->bssid), current_bss->level);
755 wpa_printf(MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
756 MAC2STR(selected->bssid), selected->level);
758 if (wpa_s->current_ssid->bssid_set &&
759 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
761 wpa_printf(MSG_DEBUG, "Allow reassociation - selected BSS has "
767 if (current_bss->level < 0) {
768 if (current_bss->level < -85)
770 else if (current_bss->level < -80)
772 else if (current_bss->level < -75)
774 else if (current_bss->level < -70)
779 if (abs(current_bss->level - selected->level) < min_diff) {
780 wpa_printf(MSG_DEBUG, "Skip roam - too small difference in "
789 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
790 union wpa_event_data *data)
792 struct wpa_bss *selected;
793 struct wpa_ssid *ssid = NULL;
794 struct wpa_scan_results *scan_res;
800 #endif /* CONFIG_AP */
802 wpa_supplicant_notify_scanning(wpa_s, 0);
804 scan_res = wpa_supplicant_get_scan_results(wpa_s,
805 data ? &data->scan_info :
807 if (scan_res == NULL) {
808 if (wpa_s->conf->ap_scan == 2 || ap)
810 wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
812 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
816 if (wpa_s->scan_res_handler) {
817 wpa_s->scan_res_handler(wpa_s, scan_res);
818 wpa_s->scan_res_handler = NULL;
819 wpa_scan_results_free(scan_res);
824 wpa_printf(MSG_DEBUG, "Ignore scan results in AP mode");
825 wpa_scan_results_free(scan_res);
829 wpa_printf(MSG_DEBUG, "New scan results available");
830 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
831 wpas_notify_scan_results(wpa_s);
833 wpas_notify_scan_done(wpa_s, 1);
835 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
836 wpa_scan_results_free(scan_res);
840 if (wpa_s->disconnected) {
841 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
842 wpa_scan_results_free(scan_res);
846 if (bgscan_notify_scan(wpa_s, scan_res) == 1) {
847 wpa_scan_results_free(scan_res);
851 wpa_supplicant_rsn_preauth_scan_results(wpa_s, scan_res);
853 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
857 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
859 wpa_scan_results_free(scan_res);
862 wpa_supplicant_connect(wpa_s, selected, ssid);
864 wpa_scan_results_free(scan_res);
865 wpa_printf(MSG_DEBUG, "No suitable network found");
866 ssid = wpa_supplicant_pick_new_network(wpa_s);
868 wpa_printf(MSG_DEBUG, "Setup a new network");
869 wpa_supplicant_associate(wpa_s, NULL, ssid);
872 int timeout_usec = 0;
874 if (wpa_s->p2p_in_provisioning) {
876 * Use shorter wait during P2P Provisioning
877 * state to speed up group formation.
880 timeout_usec = 250000;
882 #endif /* CONFIG_P2P */
883 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
888 #endif /* CONFIG_NO_SCAN_PROCESSING */
891 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
892 union wpa_event_data *data)
894 int l, len, found = 0, wpa_found, rsn_found;
897 wpa_printf(MSG_DEBUG, "Association info event");
898 if (data->assoc_info.req_ies)
899 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
900 data->assoc_info.req_ies_len);
901 if (data->assoc_info.resp_ies)
902 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
903 data->assoc_info.resp_ies_len);
904 if (data->assoc_info.beacon_ies)
905 wpa_hexdump(MSG_DEBUG, "beacon_ies",
906 data->assoc_info.beacon_ies,
907 data->assoc_info.beacon_ies_len);
908 if (data->assoc_info.freq)
909 wpa_printf(MSG_DEBUG, "freq=%u MHz", data->assoc_info.freq);
911 p = data->assoc_info.req_ies;
912 l = data->assoc_info.req_ies_len;
914 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
915 while (p && l >= 2) {
918 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
922 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
923 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
924 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
925 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
928 wpa_find_assoc_pmkid(wpa_s);
934 if (!found && data->assoc_info.req_ies)
935 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
937 #ifdef CONFIG_IEEE80211R
939 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
941 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
942 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
943 data->assoc_info.resp_ies,
944 data->assoc_info.resp_ies_len,
946 wpa_printf(MSG_DEBUG, "FT: Validation of "
947 "Reassociation Response failed");
948 wpa_supplicant_deauthenticate(
949 wpa_s, WLAN_REASON_INVALID_IE);
954 p = data->assoc_info.resp_ies;
955 l = data->assoc_info.resp_ies_len;
957 #ifdef CONFIG_WPS_STRICT
958 if (wpa_s->current_ssid &&
959 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
961 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
963 wpa_printf(MSG_INFO, "WPS-STRICT: AP did not include "
964 "WPS IE in (Re)Association Response");
968 if (wps_validate_assoc_resp(wps) < 0) {
970 wpa_supplicant_deauthenticate(
971 wpa_s, WLAN_REASON_INVALID_IE);
976 #endif /* CONFIG_WPS_STRICT */
978 /* Go through the IEs and make a copy of the MDIE, if present. */
979 while (p && l >= 2) {
982 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
986 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
987 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
988 wpa_s->sme.ft_used = 1;
989 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
990 MOBILITY_DOMAIN_ID_LEN);
996 #endif /* CONFIG_SME */
998 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
999 data->assoc_info.resp_ies_len);
1000 #endif /* CONFIG_IEEE80211R */
1002 /* WPA/RSN IE from Beacon/ProbeResp */
1003 p = data->assoc_info.beacon_ies;
1004 l = data->assoc_info.beacon_ies_len;
1006 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1008 wpa_found = rsn_found = 0;
1009 while (p && l >= 2) {
1012 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1017 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1018 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1020 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1024 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1026 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1033 if (!wpa_found && data->assoc_info.beacon_ies)
1034 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1035 if (!rsn_found && data->assoc_info.beacon_ies)
1036 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1037 if (wpa_found || rsn_found)
1038 wpa_s->ap_ies_from_associnfo = 1;
1040 wpa_s->assoc_freq = data->assoc_info.freq;
1046 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1047 union wpa_event_data *data)
1052 struct wpa_driver_capa capa;
1055 if (wpa_s->ap_iface) {
1056 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1057 data->assoc_info.addr,
1058 data->assoc_info.req_ies,
1059 data->assoc_info.req_ies_len);
1062 #endif /* CONFIG_AP */
1064 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1065 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1068 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1069 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
1070 os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
1071 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
1072 (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
1073 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
1074 wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1075 MACSTR, MAC2STR(bssid));
1076 bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
1077 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1078 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1080 wpas_notify_bssid_changed(wpa_s);
1082 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1083 wpa_clear_keys(wpa_s, bssid);
1085 if (wpa_supplicant_select_config(wpa_s) < 0) {
1086 wpa_supplicant_disassociate(
1087 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1090 if (wpa_s->current_ssid) {
1091 struct wpa_bss *bss = NULL;
1092 struct wpa_ssid *ssid = wpa_s->current_ssid;
1093 if (ssid->ssid_len > 0)
1094 bss = wpa_bss_get(wpa_s, bssid,
1095 ssid->ssid, ssid->ssid_len);
1097 bss = wpa_bss_get_bssid(wpa_s, bssid);
1099 wpa_s->current_bss = bss;
1104 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1105 wpa_s->sme.prev_bssid_set = 1;
1106 #endif /* CONFIG_SME */
1108 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1109 if (wpa_s->current_ssid) {
1110 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1111 * initialized before association, but for other modes,
1112 * initialize PC/SC here, if the current configuration needs
1113 * smartcard or SIM/USIM. */
1114 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1116 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1118 l2_packet_notify_auth_start(wpa_s->l2);
1121 * Set portEnabled first to FALSE in order to get EAP state machine out
1122 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1123 * state machine may transit to AUTHENTICATING state based on obsolete
1124 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1125 * AUTHENTICATED without ever giving chance to EAP state machine to
1128 if (!ft_completed) {
1129 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1130 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1132 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1133 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1134 /* 802.1X::portControl = Auto */
1135 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1136 wpa_s->eapol_received = 0;
1137 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1138 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1139 (wpa_s->current_ssid &&
1140 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1141 wpa_supplicant_cancel_auth_timeout(wpa_s);
1142 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1143 } else if (!ft_completed) {
1144 /* Timeout for receiving the first EAPOL packet */
1145 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1147 wpa_supplicant_cancel_scan(wpa_s);
1149 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1150 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1152 * We are done; the driver will take care of RSN 4-way
1155 wpa_supplicant_cancel_auth_timeout(wpa_s);
1156 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1157 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1158 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1161 if (wpa_s->pending_eapol_rx) {
1162 struct os_time now, age;
1164 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1165 if (age.sec == 0 && age.usec < 100000 &&
1166 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1168 wpa_printf(MSG_DEBUG, "Process pending EAPOL frame "
1169 "that was received just before association "
1171 wpa_supplicant_rx_eapol(
1172 wpa_s, wpa_s->pending_eapol_rx_src,
1173 wpabuf_head(wpa_s->pending_eapol_rx),
1174 wpabuf_len(wpa_s->pending_eapol_rx));
1176 wpabuf_free(wpa_s->pending_eapol_rx);
1177 wpa_s->pending_eapol_rx = NULL;
1180 #ifdef CONFIG_BGSCAN
1181 if (wpa_s->current_ssid != wpa_s->bgscan_ssid) {
1182 bgscan_deinit(wpa_s);
1183 if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) {
1184 if (bgscan_init(wpa_s, wpa_s->current_ssid)) {
1185 wpa_printf(MSG_DEBUG, "Failed to initialize "
1188 * Live without bgscan; it is only used as a
1189 * roaming optimization, so the initial
1190 * connection is not affected.
1193 wpa_s->bgscan_ssid = wpa_s->current_ssid;
1195 wpa_s->bgscan_ssid = NULL;
1197 #endif /* CONFIG_BGSCAN */
1199 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1200 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1201 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1202 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1203 /* Set static WEP keys again */
1204 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1209 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1215 u8 prev_pending_bssid[ETH_ALEN];
1217 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1218 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1219 #endif /* CONFIG_SME */
1221 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1223 * At least Host AP driver and a Prism3 card seemed to be
1224 * generating streams of disconnected events when configuring
1225 * IBSS for WPA-None. Ignore them for now.
1227 wpa_printf(MSG_DEBUG, "Disconnect event - ignore in "
1228 "IBSS/WPA-None mode");
1232 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1233 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1234 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1235 "pre-shared key may be incorrect");
1237 if (!wpa_s->auto_reconnect_disabled ||
1238 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1239 wpa_printf(MSG_DEBUG, "WPA: Auto connect enabled: try to "
1240 "reconnect (wps=%d)",
1241 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS);
1242 if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1243 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1245 wpa_printf(MSG_DEBUG, "WPA: Auto connect disabled: do not try "
1247 wpa_s->reassociate = 0;
1248 wpa_s->disconnected = 1;
1250 bssid = wpa_s->bssid;
1251 if (is_zero_ether_addr(bssid))
1252 bssid = wpa_s->pending_bssid;
1253 wpa_blacklist_add(wpa_s, bssid);
1254 wpa_sm_notify_disassoc(wpa_s->wpa);
1255 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1257 MAC2STR(bssid), reason_code);
1258 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1259 wpa_printf(MSG_DEBUG, "Disconnect event - remove keys");
1260 wpa_s->keys_cleared = 0;
1261 wpa_clear_keys(wpa_s, wpa_s->bssid);
1263 wpa_supplicant_mark_disassoc(wpa_s);
1264 bgscan_deinit(wpa_s);
1265 wpa_s->bgscan_ssid = NULL;
1267 if (authenticating &&
1268 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
1270 * mac80211-workaround to force deauth on failed auth cmd,
1271 * requires us to remain in authenticating state to allow the
1272 * second authentication attempt to be continued properly.
1274 wpa_printf(MSG_DEBUG, "SME: Allow pending authentication to "
1275 "proceed after disconnection event");
1276 wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
1277 os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN);
1279 #endif /* CONFIG_SME */
1283 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1284 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
1287 struct wpa_supplicant *wpa_s = eloop_ctx;
1289 if (!wpa_s->pending_mic_error_report)
1292 wpa_printf(MSG_DEBUG, "WPA: Sending pending MIC error report");
1293 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1294 wpa_s->pending_mic_error_report = 0;
1296 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1300 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1301 union wpa_event_data *data)
1306 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1307 pairwise = (data && data->michael_mic_failure.unicast);
1309 if ((wpa_s->last_michael_mic_error &&
1310 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1311 wpa_s->pending_mic_error_report) {
1312 if (wpa_s->pending_mic_error_report) {
1314 * Send the pending MIC error report immediately since
1315 * we are going to start countermeasures and AP better
1318 wpa_sm_key_request(wpa_s->wpa, 1,
1319 wpa_s->pending_mic_error_pairwise);
1322 /* Send the new MIC error report immediately since we are going
1323 * to start countermeasures and AP better do the same.
1325 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1327 /* initialize countermeasures */
1328 wpa_s->countermeasures = 1;
1329 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1332 * Need to wait for completion of request frame. We do not get
1333 * any callback for the message completion, so just wait a
1334 * short while and hope for the best. */
1337 wpa_drv_set_countermeasures(wpa_s, 1);
1338 wpa_supplicant_deauthenticate(wpa_s,
1339 WLAN_REASON_MICHAEL_MIC_FAILURE);
1340 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1342 eloop_register_timeout(60, 0,
1343 wpa_supplicant_stop_countermeasures,
1345 /* TODO: mark the AP rejected for 60 second. STA is
1346 * allowed to associate with another AP.. */
1348 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1349 if (wpa_s->mic_errors_seen) {
1351 * Reduce the effectiveness of Michael MIC error
1352 * reports as a means for attacking against TKIP if
1353 * more than one MIC failure is noticed with the same
1354 * PTK. We delay the transmission of the reports by a
1355 * random time between 0 and 60 seconds in order to
1356 * force the attacker wait 60 seconds before getting
1357 * the information on whether a frame resulted in a MIC
1363 if (os_get_random(rval, sizeof(rval)) < 0)
1364 sec = os_random() % 60;
1366 sec = WPA_GET_BE32(rval) % 60;
1367 wpa_printf(MSG_DEBUG, "WPA: Delay MIC error report %d "
1369 wpa_s->pending_mic_error_report = 1;
1370 wpa_s->pending_mic_error_pairwise = pairwise;
1371 eloop_cancel_timeout(
1372 wpa_supplicant_delayed_mic_error_report,
1374 eloop_register_timeout(
1375 sec, os_random() % 1000000,
1376 wpa_supplicant_delayed_mic_error_report,
1379 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1381 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1382 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1383 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1385 wpa_s->last_michael_mic_error = t.sec;
1386 wpa_s->mic_errors_seen++;
1390 #ifdef CONFIG_TERMINATE_ONLASTIF
1391 static int any_interfaces(struct wpa_supplicant *head)
1393 struct wpa_supplicant *wpa_s;
1395 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1396 if (!wpa_s->interface_removed)
1400 #endif /* CONFIG_TERMINATE_ONLASTIF */
1404 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1405 union wpa_event_data *data)
1407 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1410 switch (data->interface_status.ievent) {
1411 case EVENT_INTERFACE_ADDED:
1412 if (!wpa_s->interface_removed)
1414 wpa_s->interface_removed = 0;
1415 wpa_printf(MSG_DEBUG, "Configured interface was added.");
1416 if (wpa_supplicant_driver_init(wpa_s) < 0) {
1417 wpa_printf(MSG_INFO, "Failed to initialize the driver "
1418 "after interface was added.");
1421 case EVENT_INTERFACE_REMOVED:
1422 wpa_printf(MSG_DEBUG, "Configured interface was removed.");
1423 wpa_s->interface_removed = 1;
1424 wpa_supplicant_mark_disassoc(wpa_s);
1425 l2_packet_deinit(wpa_s->l2);
1427 #ifdef CONFIG_TERMINATE_ONLASTIF
1428 /* check if last interface */
1429 if (!any_interfaces(wpa_s->global->ifaces))
1431 #endif /* CONFIG_TERMINATE_ONLASTIF */
1437 #ifdef CONFIG_PEERKEY
1439 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
1440 union wpa_event_data *data)
1444 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
1446 #endif /* CONFIG_PEERKEY */
1449 #ifdef CONFIG_IEEE80211R
1451 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
1452 union wpa_event_data *data)
1457 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
1458 data->ft_ies.ies_len,
1459 data->ft_ies.ft_action,
1460 data->ft_ies.target_ap,
1461 data->ft_ies.ric_ies,
1462 data->ft_ies.ric_ies_len) < 0) {
1463 /* TODO: prevent MLME/driver from trying to associate? */
1466 #endif /* CONFIG_IEEE80211R */
1469 #ifdef CONFIG_IBSS_RSN
1470 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
1471 union wpa_event_data *data)
1475 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
1477 #endif /* CONFIG_IBSS_RSN */
1480 #ifdef CONFIG_IEEE80211R
1481 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
1484 const u8 *sta_addr, *target_ap_addr;
1487 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
1488 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1489 return; /* only SME case supported for now */
1490 if (len < 1 + 2 * ETH_ALEN + 2)
1493 return; /* Only FT Action Response is supported for now */
1494 sta_addr = data + 1;
1495 target_ap_addr = data + 1 + ETH_ALEN;
1496 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
1497 wpa_printf(MSG_DEBUG, "FT: Received FT Action Response: STA " MACSTR
1498 " TargetAP " MACSTR " status %u",
1499 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
1501 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
1502 wpa_printf(MSG_DEBUG, "FT: Foreign STA Address " MACSTR
1503 " in FT Action Response", MAC2STR(sta_addr));
1508 wpa_printf(MSG_DEBUG, "FT: FT Action Response indicates "
1509 "failure (status code %d)", status);
1510 /* TODO: report error to FT code(?) */
1514 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
1515 len - (1 + 2 * ETH_ALEN + 2), 1,
1516 target_ap_addr, NULL, 0) < 0)
1521 struct wpa_bss *bss;
1522 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
1524 wpa_s->sme.freq = bss->freq;
1525 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
1526 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
1529 #endif /* CONFIG_SME */
1531 #endif /* CONFIG_IEEE80211R */
1534 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1535 union wpa_event_data *data)
1537 struct wpa_supplicant *wpa_s = ctx;
1538 u16 reason_code = 0;
1540 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
1541 event != EVENT_INTERFACE_ENABLED &&
1542 event != EVENT_INTERFACE_STATUS) {
1543 wpa_printf(MSG_DEBUG, "Ignore event %d while interface is "
1548 wpa_printf(MSG_DEBUG, "Event %d received on interface %s",
1549 event, wpa_s->ifname);
1553 sme_event_auth(wpa_s, data);
1556 wpa_supplicant_event_assoc(wpa_s, data);
1558 case EVENT_DISASSOC:
1559 wpa_printf(MSG_DEBUG, "Disassociation notification");
1561 wpa_printf(MSG_DEBUG, " * reason %u",
1562 data->disassoc_info.reason_code);
1563 if (data->disassoc_info.addr)
1564 wpa_printf(MSG_DEBUG, " * address " MACSTR,
1565 MAC2STR(data->disassoc_info.addr));
1568 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
1569 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1570 data->disassoc_info.addr);
1573 #endif /* CONFIG_AP */
1575 reason_code = data->disassoc_info.reason_code;
1576 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
1577 data->disassoc_info.ie,
1578 data->disassoc_info.ie_len);
1580 wpas_p2p_disassoc_notif(
1581 wpa_s, data->disassoc_info.addr, reason_code,
1582 data->disassoc_info.ie,
1583 data->disassoc_info.ie_len);
1584 #endif /* CONFIG_P2P */
1586 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
1587 sme_event_disassoc(wpa_s, data);
1590 if (event == EVENT_DEAUTH) {
1591 wpa_printf(MSG_DEBUG, "Deauthentication notification");
1593 reason_code = data->deauth_info.reason_code;
1594 wpa_printf(MSG_DEBUG, " * reason %u",
1595 data->deauth_info.reason_code);
1596 if (data->deauth_info.addr) {
1597 wpa_printf(MSG_DEBUG, " * address "
1599 MAC2STR(data->deauth_info.
1602 wpa_hexdump(MSG_DEBUG,
1603 "Deauthentication frame IE(s)",
1604 data->deauth_info.ie,
1605 data->deauth_info.ie_len);
1607 wpas_p2p_deauth_notif(
1608 wpa_s, data->deauth_info.addr,
1610 data->deauth_info.ie,
1611 data->deauth_info.ie_len);
1612 #endif /* CONFIG_P2P */
1616 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
1617 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1618 data->deauth_info.addr);
1621 #endif /* CONFIG_AP */
1622 wpa_supplicant_event_disassoc(wpa_s, reason_code);
1624 case EVENT_MICHAEL_MIC_FAILURE:
1625 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
1627 #ifndef CONFIG_NO_SCAN_PROCESSING
1628 case EVENT_SCAN_RESULTS:
1629 wpa_supplicant_event_scan_results(wpa_s, data);
1631 #endif /* CONFIG_NO_SCAN_PROCESSING */
1632 case EVENT_ASSOCINFO:
1633 wpa_supplicant_event_associnfo(wpa_s, data);
1635 case EVENT_INTERFACE_STATUS:
1636 wpa_supplicant_event_interface_status(wpa_s, data);
1638 case EVENT_PMKID_CANDIDATE:
1639 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
1641 #ifdef CONFIG_PEERKEY
1642 case EVENT_STKSTART:
1643 wpa_supplicant_event_stkstart(wpa_s, data);
1645 #endif /* CONFIG_PEERKEY */
1646 #ifdef CONFIG_IEEE80211R
1647 case EVENT_FT_RESPONSE:
1648 wpa_supplicant_event_ft_response(wpa_s, data);
1650 #endif /* CONFIG_IEEE80211R */
1651 #ifdef CONFIG_IBSS_RSN
1652 case EVENT_IBSS_RSN_START:
1653 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
1655 #endif /* CONFIG_IBSS_RSN */
1656 case EVENT_ASSOC_REJECT:
1657 sme_event_assoc_reject(wpa_s, data);
1659 case EVENT_AUTH_TIMED_OUT:
1660 sme_event_auth_timed_out(wpa_s, data);
1662 case EVENT_ASSOC_TIMED_OUT:
1663 sme_event_assoc_timed_out(wpa_s, data);
1666 case EVENT_TX_STATUS:
1667 wpa_printf(MSG_DEBUG, "EVENT_TX_STATUS on %s dst=" MACSTR
1668 " type=%d stype=%d pending_dst=" MACSTR,
1669 wpa_s->ifname, MAC2STR(data->tx_status.dst),
1670 data->tx_status.type, data->tx_status.stype,
1671 MAC2STR(wpa_s->parent->pending_action_dst));
1672 if (wpa_s->ap_iface == NULL) {
1674 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
1675 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
1676 wpas_send_action_tx_status(
1677 wpa_s, data->tx_status.dst,
1678 data->tx_status.data,
1679 data->tx_status.data_len,
1680 data->tx_status.ack ?
1681 P2P_SEND_ACTION_SUCCESS :
1682 P2P_SEND_ACTION_NO_ACK);
1683 #endif /* CONFIG_P2P */
1688 * Catch TX status events for Action frames we sent via group
1689 * interface in GO mode.
1691 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
1692 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
1693 os_memcmp(wpa_s->parent->pending_action_dst,
1694 data->tx_status.dst, ETH_ALEN) == 0) {
1695 wpas_send_action_tx_status(
1696 wpa_s->parent, data->tx_status.dst,
1697 data->tx_status.data,
1698 data->tx_status.data_len,
1699 data->tx_status.ack);
1702 #endif /* CONFIG_P2P */
1703 switch (data->tx_status.type) {
1704 case WLAN_FC_TYPE_MGMT:
1705 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
1706 data->tx_status.data_len,
1707 data->tx_status.stype,
1708 data->tx_status.ack);
1710 case WLAN_FC_TYPE_DATA:
1711 ap_tx_status(wpa_s, data->tx_status.dst,
1712 data->tx_status.data,
1713 data->tx_status.data_len,
1714 data->tx_status.ack);
1718 case EVENT_RX_FROM_UNKNOWN:
1719 if (wpa_s->ap_iface == NULL)
1721 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
1722 data->rx_from_unknown.len);
1725 if (wpa_s->ap_iface == NULL) {
1728 const struct ieee80211_mgmt *mgmt;
1729 mgmt = (const struct ieee80211_mgmt *)
1730 data->rx_mgmt.frame;
1731 fc = le_to_host16(mgmt->frame_control);
1732 stype = WLAN_FC_GET_STYPE(fc);
1733 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
1734 data->rx_mgmt.frame_len > 24) {
1735 const u8 *src = mgmt->sa;
1736 const u8 *ie = mgmt->u.probe_req.variable;
1737 size_t ie_len = data->rx_mgmt.frame_len -
1738 (mgmt->u.probe_req.variable -
1739 data->rx_mgmt.frame);
1740 wpas_p2p_probe_req_rx(wpa_s, src, ie, ie_len);
1743 #endif /* CONFIG_P2P */
1744 wpa_printf(MSG_DEBUG, "AP: ignore received management "
1745 "frame in non-AP mode");
1748 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
1750 #endif /* CONFIG_AP */
1751 case EVENT_RX_ACTION:
1752 wpa_printf(MSG_DEBUG, "Received Action frame: SA=" MACSTR
1753 " Category=%u DataLen=%d freq=%d MHz",
1754 MAC2STR(data->rx_action.sa),
1755 data->rx_action.category, (int) data->rx_action.len,
1756 data->rx_action.freq);
1757 #ifdef CONFIG_IEEE80211R
1758 if (data->rx_action.category == WLAN_ACTION_FT) {
1759 ft_rx_action(wpa_s, data->rx_action.data,
1760 data->rx_action.len);
1763 #endif /* CONFIG_IEEE80211R */
1765 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
1767 data->rx_action.bssid,
1768 data->rx_action.category,
1769 data->rx_action.data,
1770 data->rx_action.len, data->rx_action.freq);
1771 #endif /* CONFIG_P2P */
1774 case EVENT_REMAIN_ON_CHANNEL:
1775 wpas_p2p_remain_on_channel_cb(
1776 wpa_s, data->remain_on_channel.freq,
1777 data->remain_on_channel.duration);
1779 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
1780 wpas_p2p_cancel_remain_on_channel_cb(
1781 wpa_s, data->remain_on_channel.freq);
1783 case EVENT_RX_PROBE_REQ:
1784 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
1785 data->rx_probe_req.ie,
1786 data->rx_probe_req.ie_len);
1788 #endif /* CONFIG_P2P */
1789 #ifdef CONFIG_CLIENT_MLME
1790 case EVENT_MLME_RX: {
1791 struct ieee80211_rx_status rx_status;
1792 os_memset(&rx_status, 0, sizeof(rx_status));
1793 rx_status.freq = data->mlme_rx.freq;
1794 rx_status.channel = data->mlme_rx.channel;
1795 rx_status.ssi = data->mlme_rx.ssi;
1796 ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
1800 #endif /* CONFIG_CLIENT_MLME */
1801 case EVENT_EAPOL_RX:
1802 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
1803 data->eapol_rx.data,
1804 data->eapol_rx.data_len);
1806 case EVENT_SIGNAL_CHANGE:
1807 bgscan_notify_signal_change(
1808 wpa_s, data->signal_change.above_threshold,
1809 data->signal_change.current_signal,
1810 data->signal_change.current_noise,
1811 data->signal_change.current_txrate);
1813 case EVENT_INTERFACE_ENABLED:
1814 wpa_printf(MSG_DEBUG, "Interface was enabled");
1815 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
1817 if (!wpa_s->ap_iface) {
1818 wpa_supplicant_set_state(wpa_s,
1820 wpa_supplicant_req_scan(wpa_s, 0, 0);
1822 wpa_supplicant_set_state(wpa_s,
1824 #else /* CONFIG_AP */
1825 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1826 wpa_supplicant_req_scan(wpa_s, 0, 0);
1827 #endif /* CONFIG_AP */
1830 case EVENT_INTERFACE_DISABLED:
1831 wpa_printf(MSG_DEBUG, "Interface was disabled");
1832 wpa_supplicant_mark_disassoc(wpa_s);
1833 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
1835 case EVENT_CHANNEL_LIST_CHANGED:
1837 wpas_p2p_update_channel_list(wpa_s);
1838 #endif /* CONFIG_P2P */
1841 wpa_printf(MSG_INFO, "Unknown event %d", event);