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 "blacklist.h"
34 #include "wpas_glue.h"
35 #include "wps_supplicant.h"
45 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
47 struct wpa_ssid *ssid, *old_ssid;
49 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
52 wpa_printf(MSG_DEBUG, "Select network based on association "
54 ssid = wpa_supplicant_get_ssid(wpa_s);
56 wpa_printf(MSG_INFO, "No network configuration found for the "
62 wpa_printf(MSG_DEBUG, "Selected network is disabled");
66 wpa_printf(MSG_DEBUG, "Network configuration found for the current "
68 if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
69 WPA_KEY_MGMT_WPA_NONE |
70 WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X |
71 WPA_KEY_MGMT_PSK_SHA256 |
72 WPA_KEY_MGMT_IEEE8021X_SHA256)) {
74 size_t wpa_ie_len = sizeof(wpa_ie);
75 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
78 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
81 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
82 eapol_sm_invalidate_cached_session(wpa_s->eapol);
83 old_ssid = wpa_s->current_ssid;
84 wpa_s->current_ssid = ssid;
85 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
86 wpa_supplicant_initiate_eapol(wpa_s);
87 if (old_ssid != wpa_s->current_ssid)
88 wpas_notify_network_changed(wpa_s);
94 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
97 struct wpa_supplicant *wpa_s = eloop_ctx;
99 if (wpa_s->countermeasures) {
100 wpa_s->countermeasures = 0;
101 wpa_drv_set_countermeasures(wpa_s, 0);
102 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
103 wpa_supplicant_req_scan(wpa_s, 0, 0);
108 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
112 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
115 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
116 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
117 os_memset(wpa_s->bssid, 0, ETH_ALEN);
118 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
119 wpa_s->current_bss = NULL;
121 wpas_notify_bssid_changed(wpa_s);
123 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
124 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
125 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
126 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
127 wpa_s->ap_ies_from_associnfo = 0;
131 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
133 struct wpa_ie_data ie;
137 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
141 for (i = 0; i < ie.num_pmkid; i++) {
142 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
143 ie.pmkid + i * PMKID_LEN,
145 if (pmksa_set == 0) {
146 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
151 wpa_printf(MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from PMKSA "
152 "cache", pmksa_set == 0 ? "" : "not ");
156 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
157 union wpa_event_data *data)
160 wpa_printf(MSG_DEBUG, "RSN: No data in PMKID candidate event");
163 wpa_printf(MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
164 " index=%d preauth=%d",
165 MAC2STR(data->pmkid_candidate.bssid),
166 data->pmkid_candidate.index,
167 data->pmkid_candidate.preauth);
169 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
170 data->pmkid_candidate.index,
171 data->pmkid_candidate.preauth);
175 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
177 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
178 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
181 #ifdef IEEE8021X_EAPOL
182 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
183 wpa_s->current_ssid &&
184 !(wpa_s->current_ssid->eapol_flags &
185 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
186 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
187 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
188 * plaintext or static WEP keys). */
191 #endif /* IEEE8021X_EAPOL */
198 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
199 * @wpa_s: pointer to wpa_supplicant data
200 * @ssid: Configuration data for the network
201 * Returns: 0 on success, -1 on failure
203 * This function is called when starting authentication with a network that is
204 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
206 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
207 struct wpa_ssid *ssid)
209 #ifdef IEEE8021X_EAPOL
210 int aka = 0, sim = 0, type;
212 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
215 if (ssid->eap.eap_methods == NULL) {
219 struct eap_method_type *eap = ssid->eap.eap_methods;
220 while (eap->vendor != EAP_VENDOR_IETF ||
221 eap->method != EAP_TYPE_NONE) {
222 if (eap->vendor == EAP_VENDOR_IETF) {
223 if (eap->method == EAP_TYPE_SIM)
225 else if (eap->method == EAP_TYPE_AKA)
232 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
234 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
238 wpa_printf(MSG_DEBUG, "Selected network is configured to use "
239 "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
243 wpa_printf(MSG_DEBUG, "Selected network is configured to use SIM "
244 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
246 type = SCARD_TRY_BOTH;
248 type = SCARD_USIM_ONLY;
250 type = SCARD_GSM_SIM_ONLY;
252 wpa_s->scard = scard_init(type);
253 if (wpa_s->scard == NULL) {
254 wpa_printf(MSG_WARNING, "Failed to initialize SIM "
258 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
259 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
260 #endif /* IEEE8021X_EAPOL */
266 #ifndef CONFIG_NO_SCAN_PROCESSING
267 static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
268 struct wpa_ssid *ssid)
272 if (ssid->mixed_cell)
276 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
278 #endif /* CONFIG_WPS */
280 for (i = 0; i < NUM_WEP_KEYS; i++) {
281 if (ssid->wep_key_len[i]) {
286 #ifdef IEEE8021X_EAPOL
287 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
288 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
289 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
291 #endif /* IEEE8021X_EAPOL */
293 if (bss->caps & IEEE80211_CAP_PRIVACY)
299 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
300 struct wpa_ssid *ssid,
301 struct wpa_scan_res *bss)
303 struct wpa_ie_data ie;
305 const u8 *rsn_ie, *wpa_ie;
308 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
312 rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
313 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
316 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
317 wpa_printf(MSG_DEBUG, " skip RSN IE - parse failed");
320 if (!(ie.proto & ssid->proto)) {
321 wpa_printf(MSG_DEBUG, " skip RSN IE - proto "
326 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
327 wpa_printf(MSG_DEBUG, " skip RSN IE - PTK cipher "
332 if (!(ie.group_cipher & ssid->group_cipher)) {
333 wpa_printf(MSG_DEBUG, " skip RSN IE - GTK cipher "
338 if (!(ie.key_mgmt & ssid->key_mgmt)) {
339 wpa_printf(MSG_DEBUG, " skip RSN IE - key mgmt "
344 #ifdef CONFIG_IEEE80211W
345 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
346 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
347 wpa_printf(MSG_DEBUG, " skip RSN IE - no mgmt frame "
351 #endif /* CONFIG_IEEE80211W */
353 wpa_printf(MSG_DEBUG, " selected based on RSN IE");
357 wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
358 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
361 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
362 wpa_printf(MSG_DEBUG, " skip WPA IE - parse failed");
365 if (!(ie.proto & ssid->proto)) {
366 wpa_printf(MSG_DEBUG, " skip WPA IE - proto "
371 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
372 wpa_printf(MSG_DEBUG, " skip WPA IE - PTK cipher "
377 if (!(ie.group_cipher & ssid->group_cipher)) {
378 wpa_printf(MSG_DEBUG, " skip WPA IE - GTK cipher "
383 if (!(ie.key_mgmt & ssid->key_mgmt)) {
384 wpa_printf(MSG_DEBUG, " skip WPA IE - key mgmt "
389 wpa_printf(MSG_DEBUG, " selected based on WPA IE");
393 if (proto_match == 0)
394 wpa_printf(MSG_DEBUG, " skip - no WPA/RSN proto match");
400 static int freq_allowed(int *freqs, int freq)
407 for (i = 0; freqs[i]; i++)
408 if (freqs[i] == freq)
414 static struct wpa_bss *
415 wpa_supplicant_select_bss_wpa(struct wpa_supplicant *wpa_s,
416 struct wpa_scan_results *scan_res,
417 struct wpa_ssid *group,
418 struct wpa_ssid **selected_ssid)
420 struct wpa_ssid *ssid;
421 struct wpa_scan_res *bss;
423 struct wpa_blacklist *e;
426 wpa_printf(MSG_DEBUG, "Try to find WPA-enabled AP");
427 for (i = 0; i < scan_res->num; i++) {
429 u8 wpa_ie_len, rsn_ie_len, ssid_len;
430 bss = scan_res->res[i];
432 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
433 ssid_ = ie ? ie + 2 : (u8 *) "";
434 ssid_len = ie ? ie[1] : 0;
436 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
437 wpa_ie_len = ie ? ie[1] : 0;
439 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
440 rsn_ie_len = ie ? ie[1] : 0;
442 wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
443 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
444 (int) i, MAC2STR(bss->bssid),
445 wpa_ssid_txt(ssid_, ssid_len),
446 wpa_ie_len, rsn_ie_len, bss->caps);
448 e = wpa_blacklist_get(wpa_s, bss->bssid);
449 if (e && e->count > 1) {
450 wpa_printf(MSG_DEBUG, " skip - blacklisted");
455 wpa_printf(MSG_DEBUG, " skip - SSID not known");
459 if (wpa_ie_len == 0 && rsn_ie_len == 0) {
460 wpa_printf(MSG_DEBUG, " skip - no WPA/RSN IE");
464 for (ssid = group; ssid; ssid = ssid->pnext) {
467 if (ssid->disabled) {
468 wpa_printf(MSG_DEBUG, " skip - disabled");
473 if (ssid->ssid_len == 0 &&
474 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
476 #endif /* CONFIG_WPS */
479 (ssid_len != ssid->ssid_len ||
480 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
481 wpa_printf(MSG_DEBUG, " skip - "
486 if (ssid->bssid_set &&
487 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
489 wpa_printf(MSG_DEBUG, " skip - "
494 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
497 if (!freq_allowed(ssid->freq_list, bss->freq)) {
498 wpa_printf(MSG_DEBUG, " skip - "
499 "frequency not allowed");
503 wpa_printf(MSG_DEBUG, " selected WPA AP "
506 wpa_ssid_txt(ssid_, ssid_len));
507 *selected_ssid = ssid;
508 return wpa_bss_get(wpa_s, bss->bssid, ssid_, ssid_len);
516 static struct wpa_bss *
517 wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant *wpa_s,
518 struct wpa_scan_results *scan_res,
519 struct wpa_ssid *group,
520 struct wpa_ssid **selected_ssid)
522 struct wpa_ssid *ssid;
523 struct wpa_scan_res *bss;
525 struct wpa_blacklist *e;
528 wpa_printf(MSG_DEBUG, "Try to find non-WPA AP");
529 for (i = 0; i < scan_res->num; i++) {
531 u8 wpa_ie_len, rsn_ie_len, ssid_len;
532 bss = scan_res->res[i];
534 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
535 ssid_ = ie ? ie + 2 : (u8 *) "";
536 ssid_len = ie ? ie[1] : 0;
538 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
539 wpa_ie_len = ie ? ie[1] : 0;
541 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
542 rsn_ie_len = ie ? ie[1] : 0;
544 wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
545 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
546 (int) i, MAC2STR(bss->bssid),
547 wpa_ssid_txt(ssid_, ssid_len),
548 wpa_ie_len, rsn_ie_len, bss->caps);
550 e = wpa_blacklist_get(wpa_s, bss->bssid);
551 if (e && e->count > 1) {
552 wpa_printf(MSG_DEBUG, " skip - blacklisted");
557 wpa_printf(MSG_DEBUG, " skip - SSID not known");
561 for (ssid = group; ssid; ssid = ssid->pnext) {
562 int check_ssid = ssid->ssid_len != 0;
564 if (ssid->disabled) {
565 wpa_printf(MSG_DEBUG, " skip - disabled");
570 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
571 /* Only allow wildcard SSID match if an AP
572 * advertises active WPS operation that matches
575 if (ssid->ssid_len == 0 &&
576 wpas_wps_ssid_wildcard_ok(wpa_s, ssid,
580 #endif /* CONFIG_WPS */
583 (ssid_len != ssid->ssid_len ||
584 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
585 wpa_printf(MSG_DEBUG, " skip - "
590 if (ssid->bssid_set &&
591 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
593 wpa_printf(MSG_DEBUG, " skip - "
598 if (!(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
599 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
600 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA))
602 wpa_printf(MSG_DEBUG, " skip - "
603 "non-WPA network not allowed");
607 if ((ssid->key_mgmt &
608 (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK |
609 WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK |
610 WPA_KEY_MGMT_IEEE8021X_SHA256 |
611 WPA_KEY_MGMT_PSK_SHA256)) &&
612 (wpa_ie_len != 0 || rsn_ie_len != 0)) {
613 wpa_printf(MSG_DEBUG, " skip - "
618 if (!wpa_supplicant_match_privacy(bss, ssid)) {
619 wpa_printf(MSG_DEBUG, " skip - "
624 if (bss->caps & IEEE80211_CAP_IBSS) {
625 wpa_printf(MSG_DEBUG, " skip - "
626 "IBSS (adhoc) network");
630 if (!freq_allowed(ssid->freq_list, bss->freq)) {
631 wpa_printf(MSG_DEBUG, " skip - "
632 "frequency not allowed");
636 wpa_printf(MSG_DEBUG, " selected non-WPA AP "
639 wpa_ssid_txt(ssid_, ssid_len));
640 *selected_ssid = ssid;
641 return wpa_bss_get(wpa_s, bss->bssid, ssid_, ssid_len);
649 static struct wpa_bss *
650 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
651 struct wpa_scan_results *scan_res,
652 struct wpa_ssid *group,
653 struct wpa_ssid **selected_ssid)
655 struct wpa_bss *selected;
657 wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d",
660 /* First, try to find WPA-enabled AP */
661 selected = wpa_supplicant_select_bss_wpa(wpa_s, scan_res, group,
666 /* If no WPA-enabled AP found, try to find non-WPA AP, if configuration
668 return wpa_supplicant_select_bss_non_wpa(wpa_s, scan_res, group,
673 static struct wpa_bss *
674 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
675 struct wpa_scan_results *scan_res,
676 struct wpa_ssid **selected_ssid)
678 struct wpa_bss *selected = NULL;
681 while (selected == NULL) {
682 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
683 selected = wpa_supplicant_select_bss(
684 wpa_s, scan_res, wpa_s->conf->pssid[prio],
690 if (selected == NULL && wpa_s->blacklist) {
691 wpa_printf(MSG_DEBUG, "No APs found - clear blacklist "
693 wpa_blacklist_clear(wpa_s);
694 wpa_s->blacklist_cleared++;
695 } else if (selected == NULL)
703 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
704 int timeout_sec, int timeout_usec)
706 if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1) {
708 * Quick recovery if the initial scan results were not
709 * complete when fetched before the first scan request.
711 wpa_s->scan_res_tried++;
714 } else if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
716 * No networks are enabled; short-circuit request so
717 * we don't wait timeout seconds before transitioning
720 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
723 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
727 void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
728 struct wpa_bss *selected,
729 struct wpa_ssid *ssid)
731 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
732 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
733 "PBC session overlap");
734 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
739 * Do not trigger new association unless the BSSID has changed or if
740 * reassociation is requested. If we are in process of associating with
741 * the selected BSSID, do not trigger new attempt.
743 if (wpa_s->reassociate ||
744 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
745 (wpa_s->wpa_state != WPA_ASSOCIATING ||
746 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
748 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
749 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
752 wpa_supplicant_associate(wpa_s, selected, ssid);
754 wpa_printf(MSG_DEBUG, "Already associated with the selected "
760 static struct wpa_ssid *
761 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
764 struct wpa_ssid *ssid;
766 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
767 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
771 if (ssid->mode == IEEE80211_MODE_IBSS ||
772 ssid->mode == IEEE80211_MODE_AP)
780 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
781 * on BSS added and BSS changed events */
782 static void wpa_supplicant_rsn_preauth_scan_results(
783 struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res)
787 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
790 for (i = scan_res->num - 1; i >= 0; i--) {
791 const u8 *ssid, *rsn;
792 struct wpa_scan_res *r;
794 r = scan_res->res[i];
796 ssid = wpa_scan_get_ie(r, WLAN_EID_SSID);
800 rsn = wpa_scan_get_ie(r, WLAN_EID_RSN);
804 rsn_preauth_scan_result(wpa_s->wpa, r->bssid, ssid, rsn);
810 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
811 struct wpa_bss *selected,
812 struct wpa_ssid *ssid,
813 struct wpa_scan_results *scan_res)
816 struct wpa_scan_res *current_bss = NULL;
819 if (wpa_s->reassociate)
820 return 1; /* explicit request to reassociate */
821 if (wpa_s->wpa_state < WPA_ASSOCIATED)
822 return 1; /* we are not associated; continue */
823 if (wpa_s->current_ssid == NULL)
824 return 1; /* unknown current SSID */
825 if (wpa_s->current_ssid != ssid)
826 return 1; /* different network block */
828 for (i = 0; i < scan_res->num; i++) {
829 struct wpa_scan_res *res = scan_res->res[i];
831 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
834 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
837 if (ie[1] != wpa_s->current_ssid->ssid_len ||
838 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
845 return 1; /* current BSS not seen in scan results */
847 wpa_printf(MSG_DEBUG, "Considering within-ESS reassociation");
848 wpa_printf(MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
849 MAC2STR(current_bss->bssid), current_bss->level);
850 wpa_printf(MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
851 MAC2STR(selected->bssid), selected->level);
853 if (wpa_s->current_ssid->bssid_set &&
854 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
856 wpa_printf(MSG_DEBUG, "Allow reassociation - selected BSS has "
862 if (current_bss->level < 0) {
863 if (current_bss->level < -85)
865 else if (current_bss->level < -80)
867 else if (current_bss->level < -75)
869 else if (current_bss->level < -70)
874 if (abs(current_bss->level - selected->level) < min_diff) {
875 wpa_printf(MSG_DEBUG, "Skip roam - too small difference in "
884 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
885 union wpa_event_data *data)
887 struct wpa_bss *selected;
888 struct wpa_ssid *ssid = NULL;
889 struct wpa_scan_results *scan_res;
891 wpa_supplicant_notify_scanning(wpa_s, 0);
893 scan_res = wpa_supplicant_get_scan_results(wpa_s,
894 data ? &data->scan_info :
896 if (scan_res == NULL) {
897 if (wpa_s->conf->ap_scan == 2)
899 wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
901 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
905 if (wpa_s->scan_res_handler) {
906 wpa_s->scan_res_handler(wpa_s, scan_res);
907 wpa_s->scan_res_handler = NULL;
908 wpa_scan_results_free(scan_res);
913 * Don't post the results if this was the initial cached
914 * and there were no results.
916 if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1 &&
917 scan_res->num == 0) {
918 wpa_msg(wpa_s, MSG_DEBUG, "Cached scan results are "
919 "empty - not posting");
921 wpa_printf(MSG_DEBUG, "New scan results available");
922 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
923 wpas_notify_scan_results(wpa_s);
926 wpas_notify_scan_done(wpa_s, 1);
928 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
929 wpa_scan_results_free(scan_res);
933 if (wpa_s->disconnected) {
934 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
935 wpa_scan_results_free(scan_res);
939 if (bgscan_notify_scan(wpa_s) == 1) {
940 wpa_scan_results_free(scan_res);
944 wpa_supplicant_rsn_preauth_scan_results(wpa_s, scan_res);
946 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
950 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
952 wpa_scan_results_free(scan_res);
955 wpa_supplicant_connect(wpa_s, selected, ssid);
957 wpa_scan_results_free(scan_res);
958 wpa_printf(MSG_DEBUG, "No suitable network found");
959 ssid = wpa_supplicant_pick_new_network(wpa_s);
961 wpa_printf(MSG_DEBUG, "Setup a new network");
962 wpa_supplicant_associate(wpa_s, NULL, ssid);
965 int timeout_usec = 0;
966 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
971 #endif /* CONFIG_NO_SCAN_PROCESSING */
974 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
975 union wpa_event_data *data)
977 int l, len, found = 0, wpa_found, rsn_found;
980 wpa_printf(MSG_DEBUG, "Association info event");
981 if (data->assoc_info.req_ies)
982 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
983 data->assoc_info.req_ies_len);
984 if (data->assoc_info.resp_ies)
985 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
986 data->assoc_info.resp_ies_len);
987 if (data->assoc_info.beacon_ies)
988 wpa_hexdump(MSG_DEBUG, "beacon_ies",
989 data->assoc_info.beacon_ies,
990 data->assoc_info.beacon_ies_len);
991 if (data->assoc_info.freq)
992 wpa_printf(MSG_DEBUG, "freq=%u MHz", data->assoc_info.freq);
994 p = data->assoc_info.req_ies;
995 l = data->assoc_info.req_ies_len;
997 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
998 while (p && l >= 2) {
1001 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1005 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1006 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1007 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1008 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1011 wpa_find_assoc_pmkid(wpa_s);
1017 if (!found && data->assoc_info.req_ies)
1018 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1020 #ifdef CONFIG_IEEE80211R
1022 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1024 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1025 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1026 data->assoc_info.resp_ies,
1027 data->assoc_info.resp_ies_len,
1029 wpa_printf(MSG_DEBUG, "FT: Validation of "
1030 "Reassociation Response failed");
1031 wpa_supplicant_deauthenticate(
1032 wpa_s, WLAN_REASON_INVALID_IE);
1037 p = data->assoc_info.resp_ies;
1038 l = data->assoc_info.resp_ies_len;
1040 /* Go through the IEs and make a copy of the MDIE, if present. */
1041 while (p && l >= 2) {
1044 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1048 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1049 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1050 wpa_s->sme.ft_used = 1;
1051 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1052 MOBILITY_DOMAIN_ID_LEN);
1058 #endif /* CONFIG_SME */
1060 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1061 data->assoc_info.resp_ies_len);
1062 #endif /* CONFIG_IEEE80211R */
1064 /* WPA/RSN IE from Beacon/ProbeResp */
1065 p = data->assoc_info.beacon_ies;
1066 l = data->assoc_info.beacon_ies_len;
1068 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1070 wpa_found = rsn_found = 0;
1071 while (p && l >= 2) {
1074 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1079 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1080 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1082 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1086 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1088 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1095 if (!wpa_found && data->assoc_info.beacon_ies)
1096 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1097 if (!rsn_found && data->assoc_info.beacon_ies)
1098 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1099 if (wpa_found || rsn_found)
1100 wpa_s->ap_ies_from_associnfo = 1;
1102 wpa_s->assoc_freq = data->assoc_info.freq;
1108 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1109 union wpa_event_data *data)
1114 struct wpa_driver_capa capa;
1117 if (wpa_s->ap_iface) {
1118 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1119 data->assoc_info.addr,
1120 data->assoc_info.req_ies,
1121 data->assoc_info.req_ies_len);
1124 #endif /* CONFIG_AP */
1126 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1127 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1130 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1131 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
1132 os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
1133 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
1134 (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
1135 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
1136 wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1137 MACSTR, MAC2STR(bssid));
1138 bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
1139 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1140 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1142 wpas_notify_bssid_changed(wpa_s);
1144 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1145 wpa_clear_keys(wpa_s, bssid);
1147 if (wpa_supplicant_select_config(wpa_s) < 0) {
1148 wpa_supplicant_disassociate(
1149 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1152 if (wpa_s->current_ssid) {
1153 struct wpa_bss *bss = NULL;
1154 struct wpa_ssid *ssid = wpa_s->current_ssid;
1155 if (ssid->ssid_len > 0)
1156 bss = wpa_bss_get(wpa_s, bssid,
1157 ssid->ssid, ssid->ssid_len);
1159 bss = wpa_bss_get_bssid(wpa_s, bssid);
1161 wpa_s->current_bss = bss;
1166 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1167 wpa_s->sme.prev_bssid_set = 1;
1168 #endif /* CONFIG_SME */
1170 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1171 if (wpa_s->current_ssid) {
1172 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1173 * initialized before association, but for other modes,
1174 * initialize PC/SC here, if the current configuration needs
1175 * smartcard or SIM/USIM. */
1176 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1178 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1179 l2_packet_notify_auth_start(wpa_s->l2);
1182 * Set portEnabled first to FALSE in order to get EAP state machine out
1183 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1184 * state machine may transit to AUTHENTICATING state based on obsolete
1185 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1186 * AUTHENTICATED without ever giving chance to EAP state machine to
1189 if (!ft_completed) {
1190 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1191 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1193 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1194 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1195 /* 802.1X::portControl = Auto */
1196 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1197 wpa_s->eapol_received = 0;
1198 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1199 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1200 (wpa_s->current_ssid &&
1201 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1202 wpa_supplicant_cancel_auth_timeout(wpa_s);
1203 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1204 } else if (!ft_completed) {
1205 /* Timeout for receiving the first EAPOL packet */
1206 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1208 wpa_supplicant_cancel_scan(wpa_s);
1210 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1211 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1213 * We are done; the driver will take care of RSN 4-way
1216 wpa_supplicant_cancel_auth_timeout(wpa_s);
1217 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1218 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1219 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1222 if (wpa_s->pending_eapol_rx) {
1223 struct os_time now, age;
1225 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1226 if (age.sec == 0 && age.usec < 100000 &&
1227 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1229 wpa_printf(MSG_DEBUG, "Process pending EAPOL frame "
1230 "that was received just before association "
1232 wpa_supplicant_rx_eapol(
1233 wpa_s, wpa_s->pending_eapol_rx_src,
1234 wpabuf_head(wpa_s->pending_eapol_rx),
1235 wpabuf_len(wpa_s->pending_eapol_rx));
1237 wpabuf_free(wpa_s->pending_eapol_rx);
1238 wpa_s->pending_eapol_rx = NULL;
1241 #ifdef CONFIG_BGSCAN
1242 if (wpa_s->current_ssid != wpa_s->bgscan_ssid) {
1243 bgscan_deinit(wpa_s);
1244 if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) {
1245 if (bgscan_init(wpa_s, wpa_s->current_ssid)) {
1246 wpa_printf(MSG_DEBUG, "Failed to initialize "
1249 * Live without bgscan; it is only used as a
1250 * roaming optimization, so the initial
1251 * connection is not affected.
1254 wpa_s->bgscan_ssid = wpa_s->current_ssid;
1256 wpa_s->bgscan_ssid = NULL;
1258 #endif /* CONFIG_BGSCAN */
1260 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1261 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1262 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1263 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1264 /* Set static WEP keys again */
1265 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1270 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1276 u8 prev_pending_bssid[ETH_ALEN];
1278 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1279 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1280 #endif /* CONFIG_SME */
1282 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1284 * At least Host AP driver and a Prism3 card seemed to be
1285 * generating streams of disconnected events when configuring
1286 * IBSS for WPA-None. Ignore them for now.
1288 wpa_printf(MSG_DEBUG, "Disconnect event - ignore in "
1289 "IBSS/WPA-None mode");
1293 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1294 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1295 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1296 "pre-shared key may be incorrect");
1298 if (wpa_s->wpa_state >= WPA_ASSOCIATED)
1299 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1300 bssid = wpa_s->bssid;
1301 if (is_zero_ether_addr(bssid))
1302 bssid = wpa_s->pending_bssid;
1303 wpa_blacklist_add(wpa_s, bssid);
1304 wpa_sm_notify_disassoc(wpa_s->wpa);
1305 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1307 MAC2STR(bssid), reason_code);
1308 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1309 wpa_printf(MSG_DEBUG, "Disconnect event - remove keys");
1310 wpa_s->keys_cleared = 0;
1311 wpa_clear_keys(wpa_s, wpa_s->bssid);
1313 wpa_supplicant_mark_disassoc(wpa_s);
1314 bgscan_deinit(wpa_s);
1316 if (authenticating &&
1317 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
1319 * mac80211-workaround to force deauth on failed auth cmd,
1320 * requires us to remain in authenticating state to allow the
1321 * second authentication attempt to be continued properly.
1323 wpa_printf(MSG_DEBUG, "SME: Allow pending authentication to "
1324 "proceed after disconnection event");
1325 wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
1326 os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN);
1328 #endif /* CONFIG_SME */
1332 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1333 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
1336 struct wpa_supplicant *wpa_s = eloop_ctx;
1338 if (!wpa_s->pending_mic_error_report)
1341 wpa_printf(MSG_DEBUG, "WPA: Sending pending MIC error report");
1342 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1343 wpa_s->pending_mic_error_report = 0;
1345 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1349 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1350 union wpa_event_data *data)
1355 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1356 pairwise = (data && data->michael_mic_failure.unicast);
1358 if ((wpa_s->last_michael_mic_error &&
1359 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1360 wpa_s->pending_mic_error_report) {
1361 if (wpa_s->pending_mic_error_report) {
1363 * Send the pending MIC error report immediately since
1364 * we are going to start countermeasures and AP better
1367 wpa_sm_key_request(wpa_s->wpa, 1,
1368 wpa_s->pending_mic_error_pairwise);
1371 /* Send the new MIC error report immediately since we are going
1372 * to start countermeasures and AP better do the same.
1374 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1376 /* initialize countermeasures */
1377 wpa_s->countermeasures = 1;
1378 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1381 * Need to wait for completion of request frame. We do not get
1382 * any callback for the message completion, so just wait a
1383 * short while and hope for the best. */
1386 wpa_drv_set_countermeasures(wpa_s, 1);
1387 wpa_supplicant_deauthenticate(wpa_s,
1388 WLAN_REASON_MICHAEL_MIC_FAILURE);
1389 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1391 eloop_register_timeout(60, 0,
1392 wpa_supplicant_stop_countermeasures,
1394 /* TODO: mark the AP rejected for 60 second. STA is
1395 * allowed to associate with another AP.. */
1397 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1398 if (wpa_s->mic_errors_seen) {
1400 * Reduce the effectiveness of Michael MIC error
1401 * reports as a means for attacking against TKIP if
1402 * more than one MIC failure is noticed with the same
1403 * PTK. We delay the transmission of the reports by a
1404 * random time between 0 and 60 seconds in order to
1405 * force the attacker wait 60 seconds before getting
1406 * the information on whether a frame resulted in a MIC
1412 if (os_get_random(rval, sizeof(rval)) < 0)
1413 sec = os_random() % 60;
1415 sec = WPA_GET_BE32(rval) % 60;
1416 wpa_printf(MSG_DEBUG, "WPA: Delay MIC error report %d "
1418 wpa_s->pending_mic_error_report = 1;
1419 wpa_s->pending_mic_error_pairwise = pairwise;
1420 eloop_cancel_timeout(
1421 wpa_supplicant_delayed_mic_error_report,
1423 eloop_register_timeout(
1424 sec, os_random() % 1000000,
1425 wpa_supplicant_delayed_mic_error_report,
1428 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1430 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1431 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1432 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1434 wpa_s->last_michael_mic_error = t.sec;
1435 wpa_s->mic_errors_seen++;
1439 #ifdef CONFIG_TERMINATE_ONLASTIF
1440 static int any_interfaces(struct wpa_supplicant *head)
1442 struct wpa_supplicant *wpa_s;
1444 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1445 if (!wpa_s->interface_removed)
1449 #endif /* CONFIG_TERMINATE_ONLASTIF */
1453 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1454 union wpa_event_data *data)
1456 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1459 switch (data->interface_status.ievent) {
1460 case EVENT_INTERFACE_ADDED:
1461 if (!wpa_s->interface_removed)
1463 wpa_s->interface_removed = 0;
1464 wpa_printf(MSG_DEBUG, "Configured interface was added.");
1465 if (wpa_supplicant_driver_init(wpa_s) < 0) {
1466 wpa_printf(MSG_INFO, "Failed to initialize the driver "
1467 "after interface was added.");
1470 case EVENT_INTERFACE_REMOVED:
1471 wpa_printf(MSG_DEBUG, "Configured interface was removed.");
1472 wpa_s->interface_removed = 1;
1473 wpa_supplicant_mark_disassoc(wpa_s);
1474 l2_packet_deinit(wpa_s->l2);
1476 #ifdef CONFIG_TERMINATE_ONLASTIF
1477 /* check if last interface */
1478 if (!any_interfaces(wpa_s->global->ifaces))
1480 #endif /* CONFIG_TERMINATE_ONLASTIF */
1486 #ifdef CONFIG_PEERKEY
1488 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
1489 union wpa_event_data *data)
1493 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
1495 #endif /* CONFIG_PEERKEY */
1498 #ifdef CONFIG_IEEE80211R
1500 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
1501 union wpa_event_data *data)
1506 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
1507 data->ft_ies.ies_len,
1508 data->ft_ies.ft_action,
1509 data->ft_ies.target_ap,
1510 data->ft_ies.ric_ies,
1511 data->ft_ies.ric_ies_len) < 0) {
1512 /* TODO: prevent MLME/driver from trying to associate? */
1515 #endif /* CONFIG_IEEE80211R */
1518 #ifdef CONFIG_IBSS_RSN
1519 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
1520 union wpa_event_data *data)
1524 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
1526 #endif /* CONFIG_IBSS_RSN */
1529 #ifdef CONFIG_IEEE80211R
1530 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
1533 const u8 *sta_addr, *target_ap_addr;
1536 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
1537 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1538 return; /* only SME case supported for now */
1539 if (len < 1 + 2 * ETH_ALEN + 2)
1542 return; /* Only FT Action Response is supported for now */
1543 sta_addr = data + 1;
1544 target_ap_addr = data + 1 + ETH_ALEN;
1545 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
1546 wpa_printf(MSG_DEBUG, "FT: Received FT Action Response: STA " MACSTR
1547 " TargetAP " MACSTR " status %u",
1548 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
1550 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
1551 wpa_printf(MSG_DEBUG, "FT: Foreign STA Address " MACSTR
1552 " in FT Action Response", MAC2STR(sta_addr));
1557 wpa_printf(MSG_DEBUG, "FT: FT Action Response indicates "
1558 "failure (status code %d)", status);
1559 /* TODO: report error to FT code(?) */
1563 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
1564 len - (1 + 2 * ETH_ALEN + 2), 1,
1565 target_ap_addr, NULL, 0) < 0)
1570 struct wpa_bss *bss;
1571 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
1573 wpa_s->sme.freq = bss->freq;
1574 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
1575 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
1578 #endif /* CONFIG_SME */
1580 #endif /* CONFIG_IEEE80211R */
1583 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1584 union wpa_event_data *data)
1586 struct wpa_supplicant *wpa_s = ctx;
1587 u16 reason_code = 0;
1589 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
1590 event != EVENT_INTERFACE_ENABLED &&
1591 event != EVENT_INTERFACE_STATUS) {
1592 wpa_printf(MSG_DEBUG, "Ignore event %d while interface is "
1599 sme_event_auth(wpa_s, data);
1602 wpa_supplicant_event_assoc(wpa_s, data);
1604 case EVENT_DISASSOC:
1605 wpa_printf(MSG_DEBUG, "Disassociation notification");
1607 if (wpa_s->ap_iface && data) {
1608 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1609 data->disassoc_info.addr);
1612 #endif /* CONFIG_AP */
1614 reason_code = data->deauth_info.reason_code;
1615 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
1616 sme_event_disassoc(wpa_s, data);
1619 if (event == EVENT_DEAUTH) {
1620 wpa_printf(MSG_DEBUG, "Deauthentication notification");
1622 reason_code = data->deauth_info.reason_code;
1625 if (wpa_s->ap_iface && data) {
1626 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1627 data->deauth_info.addr);
1630 #endif /* CONFIG_AP */
1631 wpa_supplicant_event_disassoc(wpa_s, reason_code);
1633 case EVENT_MICHAEL_MIC_FAILURE:
1634 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
1636 #ifndef CONFIG_NO_SCAN_PROCESSING
1637 case EVENT_SCAN_RESULTS:
1638 wpa_supplicant_event_scan_results(wpa_s, data);
1640 #endif /* CONFIG_NO_SCAN_PROCESSING */
1641 case EVENT_ASSOCINFO:
1642 wpa_supplicant_event_associnfo(wpa_s, data);
1644 case EVENT_INTERFACE_STATUS:
1645 wpa_supplicant_event_interface_status(wpa_s, data);
1647 case EVENT_PMKID_CANDIDATE:
1648 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
1650 #ifdef CONFIG_PEERKEY
1651 case EVENT_STKSTART:
1652 wpa_supplicant_event_stkstart(wpa_s, data);
1654 #endif /* CONFIG_PEERKEY */
1655 #ifdef CONFIG_IEEE80211R
1656 case EVENT_FT_RESPONSE:
1657 wpa_supplicant_event_ft_response(wpa_s, data);
1659 #endif /* CONFIG_IEEE80211R */
1660 #ifdef CONFIG_IBSS_RSN
1661 case EVENT_IBSS_RSN_START:
1662 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
1664 #endif /* CONFIG_IBSS_RSN */
1665 case EVENT_ASSOC_REJECT:
1666 sme_event_assoc_reject(wpa_s, data);
1668 case EVENT_AUTH_TIMED_OUT:
1669 sme_event_auth_timed_out(wpa_s, data);
1671 case EVENT_ASSOC_TIMED_OUT:
1672 sme_event_assoc_timed_out(wpa_s, data);
1675 case EVENT_TX_STATUS:
1676 if (wpa_s->ap_iface == NULL)
1678 switch (data->tx_status.type) {
1679 case WLAN_FC_TYPE_MGMT:
1680 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
1681 data->tx_status.data_len,
1682 data->tx_status.stype,
1683 data->tx_status.ack);
1685 case WLAN_FC_TYPE_DATA:
1686 ap_tx_status(wpa_s, data->tx_status.dst,
1687 data->tx_status.data,
1688 data->tx_status.data_len,
1689 data->tx_status.ack);
1693 case EVENT_RX_FROM_UNKNOWN:
1694 if (wpa_s->ap_iface == NULL)
1696 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
1697 data->rx_from_unknown.len);
1700 if (wpa_s->ap_iface == NULL)
1702 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
1704 #endif /* CONFIG_AP */
1705 case EVENT_RX_ACTION:
1706 wpa_printf(MSG_DEBUG, "Received Action frame: SA=" MACSTR
1707 " Category=%u DataLen=%d freq=%d MHz",
1708 MAC2STR(data->rx_action.sa),
1709 data->rx_action.category, (int) data->rx_action.len,
1710 data->rx_action.freq);
1711 #ifdef CONFIG_IEEE80211R
1712 if (data->rx_action.category == WLAN_ACTION_FT) {
1713 ft_rx_action(wpa_s, data->rx_action.data,
1714 data->rx_action.len);
1717 #endif /* CONFIG_IEEE80211R */
1719 #ifdef CONFIG_CLIENT_MLME
1720 case EVENT_MLME_RX: {
1721 struct ieee80211_rx_status rx_status;
1722 os_memset(&rx_status, 0, sizeof(rx_status));
1723 rx_status.freq = data->mlme_rx.freq;
1724 rx_status.channel = data->mlme_rx.channel;
1725 rx_status.ssi = data->mlme_rx.ssi;
1726 ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
1730 #endif /* CONFIG_CLIENT_MLME */
1731 case EVENT_EAPOL_RX:
1732 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
1733 data->eapol_rx.data,
1734 data->eapol_rx.data_len);
1736 case EVENT_SIGNAL_CHANGE:
1737 bgscan_notify_signal_change(
1738 wpa_s, data->signal_change.above_threshold);
1740 case EVENT_INTERFACE_ENABLED:
1741 wpa_printf(MSG_DEBUG, "Interface was enabled");
1742 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
1743 wpa_supplicant_set_state(wpa_s,
1745 wpa_supplicant_req_scan(wpa_s, 0, 0);
1748 case EVENT_INTERFACE_DISABLED:
1749 wpa_printf(MSG_DEBUG, "Interface was disabled");
1750 wpa_supplicant_mark_disassoc(wpa_s);
1751 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
1754 wpa_printf(MSG_INFO, "Unknown event %d", event);