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 (wpa && ssid->ssid_len == 0 &&
467 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
470 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
471 /* Only allow wildcard SSID match if an AP
472 * advertises active WPS operation that matches
475 if (ssid->ssid_len == 0 &&
476 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
479 #endif /* CONFIG_WPS */
482 (ssid_len != ssid->ssid_len ||
483 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
484 wpa_printf(MSG_DEBUG, " skip - SSID mismatch");
488 if (ssid->bssid_set &&
489 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
490 wpa_printf(MSG_DEBUG, " skip - BSSID mismatch");
494 if (wpa && !wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
498 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
499 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
500 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
501 wpa_printf(MSG_DEBUG, " skip - non-WPA network not "
506 if (!wpa && !wpa_supplicant_match_privacy(bss, ssid)) {
507 wpa_printf(MSG_DEBUG, " skip - privacy mismatch");
511 if (!wpa && (bss->caps & IEEE80211_CAP_IBSS)) {
512 wpa_printf(MSG_DEBUG, " skip - IBSS (adhoc) "
517 if (!freq_allowed(ssid->freq_list, bss->freq)) {
518 wpa_printf(MSG_DEBUG, " skip - frequency not "
525 * TODO: skip the AP if its P2P IE has Group Formation
526 * bit set in the P2P Group Capability Bitmap and we
527 * are not in Group Formation with that device.
529 #endif /* CONFIG_P2P */
531 /* Matching configuration found */
535 /* No matching configuration found */
540 static struct wpa_bss *
541 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
542 struct wpa_scan_results *scan_res,
543 struct wpa_ssid *group,
544 struct wpa_ssid **selected_ssid)
548 wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d",
551 for (i = 0; i < scan_res->num; i++) {
552 struct wpa_scan_res *bss = scan_res->res[i];
556 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
560 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
561 ssid = ie ? ie + 2 : (u8 *) "";
562 ssid_len = ie ? ie[1] : 0;
564 wpa_printf(MSG_DEBUG, " selected BSS " MACSTR " ssid='%s'",
565 MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
566 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
573 static struct wpa_bss *
574 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
575 struct wpa_scan_results *scan_res,
576 struct wpa_ssid **selected_ssid)
578 struct wpa_bss *selected = NULL;
581 while (selected == NULL) {
582 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
583 selected = wpa_supplicant_select_bss(
584 wpa_s, scan_res, wpa_s->conf->pssid[prio],
590 if (selected == NULL && wpa_s->blacklist) {
591 wpa_printf(MSG_DEBUG, "No APs found - clear blacklist "
593 wpa_blacklist_clear(wpa_s);
594 wpa_s->blacklist_cleared++;
595 } else if (selected == NULL)
603 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
604 int timeout_sec, int timeout_usec)
606 if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
608 * No networks are enabled; short-circuit request so
609 * we don't wait timeout seconds before transitioning
612 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
615 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
619 void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
620 struct wpa_bss *selected,
621 struct wpa_ssid *ssid)
623 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
624 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
625 "PBC session overlap");
627 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
629 #endif /* CONFIG_P2P */
630 wpas_wps_cancel(wpa_s);
635 * Do not trigger new association unless the BSSID has changed or if
636 * reassociation is requested. If we are in process of associating with
637 * the selected BSSID, do not trigger new attempt.
639 if (wpa_s->reassociate ||
640 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
641 (wpa_s->wpa_state != WPA_ASSOCIATING ||
642 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
644 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
645 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
648 wpa_supplicant_associate(wpa_s, selected, ssid);
650 wpa_printf(MSG_DEBUG, "Already associated with the selected "
656 static struct wpa_ssid *
657 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
660 struct wpa_ssid *ssid;
662 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
663 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
667 if (ssid->mode == IEEE80211_MODE_IBSS ||
668 ssid->mode == IEEE80211_MODE_AP)
676 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
677 * on BSS added and BSS changed events */
678 static void wpa_supplicant_rsn_preauth_scan_results(
679 struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res)
683 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
686 for (i = scan_res->num - 1; i >= 0; i--) {
687 const u8 *ssid, *rsn;
688 struct wpa_scan_res *r;
690 r = scan_res->res[i];
692 ssid = wpa_scan_get_ie(r, WLAN_EID_SSID);
696 rsn = wpa_scan_get_ie(r, WLAN_EID_RSN);
700 rsn_preauth_scan_result(wpa_s->wpa, r->bssid, ssid, rsn);
706 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
707 struct wpa_bss *selected,
708 struct wpa_ssid *ssid,
709 struct wpa_scan_results *scan_res)
712 struct wpa_scan_res *current_bss = NULL;
715 if (wpa_s->reassociate)
716 return 1; /* explicit request to reassociate */
717 if (wpa_s->wpa_state < WPA_ASSOCIATED)
718 return 1; /* we are not associated; continue */
719 if (wpa_s->current_ssid == NULL)
720 return 1; /* unknown current SSID */
721 if (wpa_s->current_ssid != ssid)
722 return 1; /* different network block */
724 for (i = 0; i < scan_res->num; i++) {
725 struct wpa_scan_res *res = scan_res->res[i];
727 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
730 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
733 if (ie[1] != wpa_s->current_ssid->ssid_len ||
734 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
741 return 1; /* current BSS not seen in scan results */
743 wpa_printf(MSG_DEBUG, "Considering within-ESS reassociation");
744 wpa_printf(MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
745 MAC2STR(current_bss->bssid), current_bss->level);
746 wpa_printf(MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
747 MAC2STR(selected->bssid), selected->level);
749 if (wpa_s->current_ssid->bssid_set &&
750 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
752 wpa_printf(MSG_DEBUG, "Allow reassociation - selected BSS has "
758 if (current_bss->level < 0) {
759 if (current_bss->level < -85)
761 else if (current_bss->level < -80)
763 else if (current_bss->level < -75)
765 else if (current_bss->level < -70)
770 if (abs(current_bss->level - selected->level) < min_diff) {
771 wpa_printf(MSG_DEBUG, "Skip roam - too small difference in "
780 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
781 union wpa_event_data *data)
783 struct wpa_bss *selected;
784 struct wpa_ssid *ssid = NULL;
785 struct wpa_scan_results *scan_res;
791 #endif /* CONFIG_AP */
793 wpa_supplicant_notify_scanning(wpa_s, 0);
795 scan_res = wpa_supplicant_get_scan_results(wpa_s,
796 data ? &data->scan_info :
798 if (scan_res == NULL) {
799 if (wpa_s->conf->ap_scan == 2 || ap)
801 wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
803 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
807 if (wpa_s->scan_res_handler) {
808 wpa_s->scan_res_handler(wpa_s, scan_res);
809 wpa_s->scan_res_handler = NULL;
810 wpa_scan_results_free(scan_res);
815 wpa_printf(MSG_DEBUG, "Ignore scan results in AP mode");
816 wpa_scan_results_free(scan_res);
820 wpa_printf(MSG_DEBUG, "New scan results available");
821 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
822 wpas_notify_scan_results(wpa_s);
824 wpas_notify_scan_done(wpa_s, 1);
826 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
827 wpa_scan_results_free(scan_res);
831 if (wpa_s->disconnected) {
832 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
833 wpa_scan_results_free(scan_res);
837 if (bgscan_notify_scan(wpa_s, scan_res) == 1) {
838 wpa_scan_results_free(scan_res);
842 wpa_supplicant_rsn_preauth_scan_results(wpa_s, scan_res);
844 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
848 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
850 wpa_scan_results_free(scan_res);
853 wpa_supplicant_connect(wpa_s, selected, ssid);
855 wpa_scan_results_free(scan_res);
856 wpa_printf(MSG_DEBUG, "No suitable network found");
857 ssid = wpa_supplicant_pick_new_network(wpa_s);
859 wpa_printf(MSG_DEBUG, "Setup a new network");
860 wpa_supplicant_associate(wpa_s, NULL, ssid);
863 int timeout_usec = 0;
865 if (wpa_s->p2p_in_provisioning) {
867 * Use shorter wait during P2P Provisioning
868 * state to speed up group formation.
871 timeout_usec = 250000;
873 #endif /* CONFIG_P2P */
874 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
879 #endif /* CONFIG_NO_SCAN_PROCESSING */
882 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
883 union wpa_event_data *data)
885 int l, len, found = 0, wpa_found, rsn_found;
888 wpa_printf(MSG_DEBUG, "Association info event");
889 if (data->assoc_info.req_ies)
890 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
891 data->assoc_info.req_ies_len);
892 if (data->assoc_info.resp_ies)
893 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
894 data->assoc_info.resp_ies_len);
895 if (data->assoc_info.beacon_ies)
896 wpa_hexdump(MSG_DEBUG, "beacon_ies",
897 data->assoc_info.beacon_ies,
898 data->assoc_info.beacon_ies_len);
899 if (data->assoc_info.freq)
900 wpa_printf(MSG_DEBUG, "freq=%u MHz", data->assoc_info.freq);
902 p = data->assoc_info.req_ies;
903 l = data->assoc_info.req_ies_len;
905 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
906 while (p && l >= 2) {
909 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
913 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
914 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
915 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
916 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
919 wpa_find_assoc_pmkid(wpa_s);
925 if (!found && data->assoc_info.req_ies)
926 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
928 #ifdef CONFIG_IEEE80211R
930 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
932 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
933 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
934 data->assoc_info.resp_ies,
935 data->assoc_info.resp_ies_len,
937 wpa_printf(MSG_DEBUG, "FT: Validation of "
938 "Reassociation Response failed");
939 wpa_supplicant_deauthenticate(
940 wpa_s, WLAN_REASON_INVALID_IE);
945 p = data->assoc_info.resp_ies;
946 l = data->assoc_info.resp_ies_len;
948 #ifdef CONFIG_WPS_STRICT
949 if (wpa_s->current_ssid &&
950 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
952 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
954 wpa_printf(MSG_INFO, "WPS-STRICT: AP did not include "
955 "WPS IE in (Re)Association Response");
959 if (wps_validate_assoc_resp(wps) < 0) {
961 wpa_supplicant_deauthenticate(
962 wpa_s, WLAN_REASON_INVALID_IE);
967 #endif /* CONFIG_WPS_STRICT */
969 /* Go through the IEs and make a copy of the MDIE, if present. */
970 while (p && l >= 2) {
973 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
977 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
978 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
979 wpa_s->sme.ft_used = 1;
980 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
981 MOBILITY_DOMAIN_ID_LEN);
987 #endif /* CONFIG_SME */
989 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
990 data->assoc_info.resp_ies_len);
991 #endif /* CONFIG_IEEE80211R */
993 /* WPA/RSN IE from Beacon/ProbeResp */
994 p = data->assoc_info.beacon_ies;
995 l = data->assoc_info.beacon_ies_len;
997 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
999 wpa_found = rsn_found = 0;
1000 while (p && l >= 2) {
1003 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1008 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1009 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1011 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1015 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1017 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1024 if (!wpa_found && data->assoc_info.beacon_ies)
1025 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1026 if (!rsn_found && data->assoc_info.beacon_ies)
1027 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1028 if (wpa_found || rsn_found)
1029 wpa_s->ap_ies_from_associnfo = 1;
1031 wpa_s->assoc_freq = data->assoc_info.freq;
1037 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1038 union wpa_event_data *data)
1043 struct wpa_driver_capa capa;
1046 if (wpa_s->ap_iface) {
1047 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1048 data->assoc_info.addr,
1049 data->assoc_info.req_ies,
1050 data->assoc_info.req_ies_len);
1053 #endif /* CONFIG_AP */
1055 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1056 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1059 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1060 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
1061 os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
1062 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
1063 (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
1064 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
1065 wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1066 MACSTR, MAC2STR(bssid));
1067 bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
1068 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1069 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1071 wpas_notify_bssid_changed(wpa_s);
1073 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1074 wpa_clear_keys(wpa_s, bssid);
1076 if (wpa_supplicant_select_config(wpa_s) < 0) {
1077 wpa_supplicant_disassociate(
1078 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1081 if (wpa_s->current_ssid) {
1082 struct wpa_bss *bss = NULL;
1083 struct wpa_ssid *ssid = wpa_s->current_ssid;
1084 if (ssid->ssid_len > 0)
1085 bss = wpa_bss_get(wpa_s, bssid,
1086 ssid->ssid, ssid->ssid_len);
1088 bss = wpa_bss_get_bssid(wpa_s, bssid);
1090 wpa_s->current_bss = bss;
1095 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1096 wpa_s->sme.prev_bssid_set = 1;
1097 #endif /* CONFIG_SME */
1099 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1100 if (wpa_s->current_ssid) {
1101 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1102 * initialized before association, but for other modes,
1103 * initialize PC/SC here, if the current configuration needs
1104 * smartcard or SIM/USIM. */
1105 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1107 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1109 l2_packet_notify_auth_start(wpa_s->l2);
1112 * Set portEnabled first to FALSE in order to get EAP state machine out
1113 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1114 * state machine may transit to AUTHENTICATING state based on obsolete
1115 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1116 * AUTHENTICATED without ever giving chance to EAP state machine to
1119 if (!ft_completed) {
1120 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1121 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1123 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1124 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1125 /* 802.1X::portControl = Auto */
1126 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1127 wpa_s->eapol_received = 0;
1128 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1129 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1130 (wpa_s->current_ssid &&
1131 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1132 wpa_supplicant_cancel_auth_timeout(wpa_s);
1133 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1134 } else if (!ft_completed) {
1135 /* Timeout for receiving the first EAPOL packet */
1136 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1138 wpa_supplicant_cancel_scan(wpa_s);
1140 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1141 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1143 * We are done; the driver will take care of RSN 4-way
1146 wpa_supplicant_cancel_auth_timeout(wpa_s);
1147 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1148 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1149 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1152 if (wpa_s->pending_eapol_rx) {
1153 struct os_time now, age;
1155 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1156 if (age.sec == 0 && age.usec < 100000 &&
1157 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1159 wpa_printf(MSG_DEBUG, "Process pending EAPOL frame "
1160 "that was received just before association "
1162 wpa_supplicant_rx_eapol(
1163 wpa_s, wpa_s->pending_eapol_rx_src,
1164 wpabuf_head(wpa_s->pending_eapol_rx),
1165 wpabuf_len(wpa_s->pending_eapol_rx));
1167 wpabuf_free(wpa_s->pending_eapol_rx);
1168 wpa_s->pending_eapol_rx = NULL;
1171 #ifdef CONFIG_BGSCAN
1172 if (wpa_s->current_ssid != wpa_s->bgscan_ssid) {
1173 bgscan_deinit(wpa_s);
1174 if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) {
1175 if (bgscan_init(wpa_s, wpa_s->current_ssid)) {
1176 wpa_printf(MSG_DEBUG, "Failed to initialize "
1179 * Live without bgscan; it is only used as a
1180 * roaming optimization, so the initial
1181 * connection is not affected.
1184 wpa_s->bgscan_ssid = wpa_s->current_ssid;
1186 wpa_s->bgscan_ssid = NULL;
1188 #endif /* CONFIG_BGSCAN */
1190 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1191 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1192 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1193 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1194 /* Set static WEP keys again */
1195 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1200 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1206 u8 prev_pending_bssid[ETH_ALEN];
1208 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1209 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1210 #endif /* CONFIG_SME */
1212 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1214 * At least Host AP driver and a Prism3 card seemed to be
1215 * generating streams of disconnected events when configuring
1216 * IBSS for WPA-None. Ignore them for now.
1218 wpa_printf(MSG_DEBUG, "Disconnect event - ignore in "
1219 "IBSS/WPA-None mode");
1223 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1224 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1225 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1226 "pre-shared key may be incorrect");
1228 if (!wpa_s->auto_reconnect_disabled ||
1229 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1230 wpa_printf(MSG_DEBUG, "WPA: Auto connect enabled: try to "
1231 "reconnect (wps=%d)",
1232 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS);
1233 if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1234 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1236 wpa_printf(MSG_DEBUG, "WPA: Auto connect disabled: do not try "
1238 wpa_s->reassociate = 0;
1239 wpa_s->disconnected = 1;
1241 bssid = wpa_s->bssid;
1242 if (is_zero_ether_addr(bssid))
1243 bssid = wpa_s->pending_bssid;
1244 wpa_blacklist_add(wpa_s, bssid);
1245 wpa_sm_notify_disassoc(wpa_s->wpa);
1246 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1248 MAC2STR(bssid), reason_code);
1249 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1250 wpa_printf(MSG_DEBUG, "Disconnect event - remove keys");
1251 wpa_s->keys_cleared = 0;
1252 wpa_clear_keys(wpa_s, wpa_s->bssid);
1254 wpa_supplicant_mark_disassoc(wpa_s);
1255 bgscan_deinit(wpa_s);
1256 wpa_s->bgscan_ssid = NULL;
1258 if (authenticating &&
1259 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
1261 * mac80211-workaround to force deauth on failed auth cmd,
1262 * requires us to remain in authenticating state to allow the
1263 * second authentication attempt to be continued properly.
1265 wpa_printf(MSG_DEBUG, "SME: Allow pending authentication to "
1266 "proceed after disconnection event");
1267 wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
1268 os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN);
1270 #endif /* CONFIG_SME */
1274 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1275 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
1278 struct wpa_supplicant *wpa_s = eloop_ctx;
1280 if (!wpa_s->pending_mic_error_report)
1283 wpa_printf(MSG_DEBUG, "WPA: Sending pending MIC error report");
1284 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1285 wpa_s->pending_mic_error_report = 0;
1287 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1291 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1292 union wpa_event_data *data)
1297 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1298 pairwise = (data && data->michael_mic_failure.unicast);
1300 if ((wpa_s->last_michael_mic_error &&
1301 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1302 wpa_s->pending_mic_error_report) {
1303 if (wpa_s->pending_mic_error_report) {
1305 * Send the pending MIC error report immediately since
1306 * we are going to start countermeasures and AP better
1309 wpa_sm_key_request(wpa_s->wpa, 1,
1310 wpa_s->pending_mic_error_pairwise);
1313 /* Send the new MIC error report immediately since we are going
1314 * to start countermeasures and AP better do the same.
1316 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1318 /* initialize countermeasures */
1319 wpa_s->countermeasures = 1;
1320 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1323 * Need to wait for completion of request frame. We do not get
1324 * any callback for the message completion, so just wait a
1325 * short while and hope for the best. */
1328 wpa_drv_set_countermeasures(wpa_s, 1);
1329 wpa_supplicant_deauthenticate(wpa_s,
1330 WLAN_REASON_MICHAEL_MIC_FAILURE);
1331 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1333 eloop_register_timeout(60, 0,
1334 wpa_supplicant_stop_countermeasures,
1336 /* TODO: mark the AP rejected for 60 second. STA is
1337 * allowed to associate with another AP.. */
1339 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1340 if (wpa_s->mic_errors_seen) {
1342 * Reduce the effectiveness of Michael MIC error
1343 * reports as a means for attacking against TKIP if
1344 * more than one MIC failure is noticed with the same
1345 * PTK. We delay the transmission of the reports by a
1346 * random time between 0 and 60 seconds in order to
1347 * force the attacker wait 60 seconds before getting
1348 * the information on whether a frame resulted in a MIC
1354 if (os_get_random(rval, sizeof(rval)) < 0)
1355 sec = os_random() % 60;
1357 sec = WPA_GET_BE32(rval) % 60;
1358 wpa_printf(MSG_DEBUG, "WPA: Delay MIC error report %d "
1360 wpa_s->pending_mic_error_report = 1;
1361 wpa_s->pending_mic_error_pairwise = pairwise;
1362 eloop_cancel_timeout(
1363 wpa_supplicant_delayed_mic_error_report,
1365 eloop_register_timeout(
1366 sec, os_random() % 1000000,
1367 wpa_supplicant_delayed_mic_error_report,
1370 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1372 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1373 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1374 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1376 wpa_s->last_michael_mic_error = t.sec;
1377 wpa_s->mic_errors_seen++;
1381 #ifdef CONFIG_TERMINATE_ONLASTIF
1382 static int any_interfaces(struct wpa_supplicant *head)
1384 struct wpa_supplicant *wpa_s;
1386 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1387 if (!wpa_s->interface_removed)
1391 #endif /* CONFIG_TERMINATE_ONLASTIF */
1395 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1396 union wpa_event_data *data)
1398 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1401 switch (data->interface_status.ievent) {
1402 case EVENT_INTERFACE_ADDED:
1403 if (!wpa_s->interface_removed)
1405 wpa_s->interface_removed = 0;
1406 wpa_printf(MSG_DEBUG, "Configured interface was added.");
1407 if (wpa_supplicant_driver_init(wpa_s) < 0) {
1408 wpa_printf(MSG_INFO, "Failed to initialize the driver "
1409 "after interface was added.");
1412 case EVENT_INTERFACE_REMOVED:
1413 wpa_printf(MSG_DEBUG, "Configured interface was removed.");
1414 wpa_s->interface_removed = 1;
1415 wpa_supplicant_mark_disassoc(wpa_s);
1416 l2_packet_deinit(wpa_s->l2);
1418 #ifdef CONFIG_TERMINATE_ONLASTIF
1419 /* check if last interface */
1420 if (!any_interfaces(wpa_s->global->ifaces))
1422 #endif /* CONFIG_TERMINATE_ONLASTIF */
1428 #ifdef CONFIG_PEERKEY
1430 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
1431 union wpa_event_data *data)
1435 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
1437 #endif /* CONFIG_PEERKEY */
1440 #ifdef CONFIG_IEEE80211R
1442 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
1443 union wpa_event_data *data)
1448 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
1449 data->ft_ies.ies_len,
1450 data->ft_ies.ft_action,
1451 data->ft_ies.target_ap,
1452 data->ft_ies.ric_ies,
1453 data->ft_ies.ric_ies_len) < 0) {
1454 /* TODO: prevent MLME/driver from trying to associate? */
1457 #endif /* CONFIG_IEEE80211R */
1460 #ifdef CONFIG_IBSS_RSN
1461 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
1462 union wpa_event_data *data)
1466 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
1468 #endif /* CONFIG_IBSS_RSN */
1471 #ifdef CONFIG_IEEE80211R
1472 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
1475 const u8 *sta_addr, *target_ap_addr;
1478 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
1479 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1480 return; /* only SME case supported for now */
1481 if (len < 1 + 2 * ETH_ALEN + 2)
1484 return; /* Only FT Action Response is supported for now */
1485 sta_addr = data + 1;
1486 target_ap_addr = data + 1 + ETH_ALEN;
1487 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
1488 wpa_printf(MSG_DEBUG, "FT: Received FT Action Response: STA " MACSTR
1489 " TargetAP " MACSTR " status %u",
1490 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
1492 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
1493 wpa_printf(MSG_DEBUG, "FT: Foreign STA Address " MACSTR
1494 " in FT Action Response", MAC2STR(sta_addr));
1499 wpa_printf(MSG_DEBUG, "FT: FT Action Response indicates "
1500 "failure (status code %d)", status);
1501 /* TODO: report error to FT code(?) */
1505 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
1506 len - (1 + 2 * ETH_ALEN + 2), 1,
1507 target_ap_addr, NULL, 0) < 0)
1512 struct wpa_bss *bss;
1513 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
1515 wpa_s->sme.freq = bss->freq;
1516 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
1517 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
1520 #endif /* CONFIG_SME */
1522 #endif /* CONFIG_IEEE80211R */
1525 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1526 union wpa_event_data *data)
1528 struct wpa_supplicant *wpa_s = ctx;
1529 u16 reason_code = 0;
1531 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
1532 event != EVENT_INTERFACE_ENABLED &&
1533 event != EVENT_INTERFACE_STATUS) {
1534 wpa_printf(MSG_DEBUG, "Ignore event %d while interface is "
1539 wpa_printf(MSG_DEBUG, "Event %d received on interface %s",
1540 event, wpa_s->ifname);
1544 sme_event_auth(wpa_s, data);
1547 wpa_supplicant_event_assoc(wpa_s, data);
1549 case EVENT_DISASSOC:
1550 wpa_printf(MSG_DEBUG, "Disassociation notification");
1552 wpa_printf(MSG_DEBUG, " * reason %u",
1553 data->disassoc_info.reason_code);
1554 if (data->disassoc_info.addr)
1555 wpa_printf(MSG_DEBUG, " * address " MACSTR,
1556 MAC2STR(data->disassoc_info.addr));
1559 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
1560 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1561 data->disassoc_info.addr);
1564 #endif /* CONFIG_AP */
1566 reason_code = data->disassoc_info.reason_code;
1567 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
1568 data->disassoc_info.ie,
1569 data->disassoc_info.ie_len);
1571 wpas_p2p_disassoc_notif(
1572 wpa_s, data->disassoc_info.addr, reason_code,
1573 data->disassoc_info.ie,
1574 data->disassoc_info.ie_len);
1575 #endif /* CONFIG_P2P */
1577 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
1578 sme_event_disassoc(wpa_s, data);
1581 if (event == EVENT_DEAUTH) {
1582 wpa_printf(MSG_DEBUG, "Deauthentication notification");
1584 reason_code = data->deauth_info.reason_code;
1585 wpa_printf(MSG_DEBUG, " * reason %u",
1586 data->deauth_info.reason_code);
1587 if (data->deauth_info.addr) {
1588 wpa_printf(MSG_DEBUG, " * address "
1590 MAC2STR(data->deauth_info.
1593 wpa_hexdump(MSG_DEBUG,
1594 "Deauthentication frame IE(s)",
1595 data->deauth_info.ie,
1596 data->deauth_info.ie_len);
1598 wpas_p2p_deauth_notif(
1599 wpa_s, data->deauth_info.addr,
1601 data->deauth_info.ie,
1602 data->deauth_info.ie_len);
1603 #endif /* CONFIG_P2P */
1607 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
1608 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1609 data->deauth_info.addr);
1612 #endif /* CONFIG_AP */
1613 wpa_supplicant_event_disassoc(wpa_s, reason_code);
1615 case EVENT_MICHAEL_MIC_FAILURE:
1616 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
1618 #ifndef CONFIG_NO_SCAN_PROCESSING
1619 case EVENT_SCAN_RESULTS:
1620 wpa_supplicant_event_scan_results(wpa_s, data);
1622 #endif /* CONFIG_NO_SCAN_PROCESSING */
1623 case EVENT_ASSOCINFO:
1624 wpa_supplicant_event_associnfo(wpa_s, data);
1626 case EVENT_INTERFACE_STATUS:
1627 wpa_supplicant_event_interface_status(wpa_s, data);
1629 case EVENT_PMKID_CANDIDATE:
1630 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
1632 #ifdef CONFIG_PEERKEY
1633 case EVENT_STKSTART:
1634 wpa_supplicant_event_stkstart(wpa_s, data);
1636 #endif /* CONFIG_PEERKEY */
1637 #ifdef CONFIG_IEEE80211R
1638 case EVENT_FT_RESPONSE:
1639 wpa_supplicant_event_ft_response(wpa_s, data);
1641 #endif /* CONFIG_IEEE80211R */
1642 #ifdef CONFIG_IBSS_RSN
1643 case EVENT_IBSS_RSN_START:
1644 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
1646 #endif /* CONFIG_IBSS_RSN */
1647 case EVENT_ASSOC_REJECT:
1648 sme_event_assoc_reject(wpa_s, data);
1650 case EVENT_AUTH_TIMED_OUT:
1651 sme_event_auth_timed_out(wpa_s, data);
1653 case EVENT_ASSOC_TIMED_OUT:
1654 sme_event_assoc_timed_out(wpa_s, data);
1657 case EVENT_TX_STATUS:
1658 wpa_printf(MSG_DEBUG, "EVENT_TX_STATUS on %s dst=" MACSTR
1659 " type=%d stype=%d pending_dst=" MACSTR,
1660 wpa_s->ifname, MAC2STR(data->tx_status.dst),
1661 data->tx_status.type, data->tx_status.stype,
1662 MAC2STR(wpa_s->parent->pending_action_dst));
1663 if (wpa_s->ap_iface == NULL) {
1665 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
1666 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
1667 wpas_send_action_tx_status(
1668 wpa_s, data->tx_status.dst,
1669 data->tx_status.data,
1670 data->tx_status.data_len,
1671 data->tx_status.ack);
1672 #endif /* CONFIG_P2P */
1677 * Catch TX status events for Action frames we sent via group
1678 * interface in GO mode.
1680 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
1681 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
1682 os_memcmp(wpa_s->parent->pending_action_dst,
1683 data->tx_status.dst, ETH_ALEN) == 0) {
1684 wpas_send_action_tx_status(
1685 wpa_s->parent, data->tx_status.dst,
1686 data->tx_status.data,
1687 data->tx_status.data_len,
1688 data->tx_status.ack);
1691 #endif /* CONFIG_P2P */
1692 switch (data->tx_status.type) {
1693 case WLAN_FC_TYPE_MGMT:
1694 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
1695 data->tx_status.data_len,
1696 data->tx_status.stype,
1697 data->tx_status.ack);
1699 case WLAN_FC_TYPE_DATA:
1700 ap_tx_status(wpa_s, data->tx_status.dst,
1701 data->tx_status.data,
1702 data->tx_status.data_len,
1703 data->tx_status.ack);
1707 case EVENT_RX_FROM_UNKNOWN:
1708 if (wpa_s->ap_iface == NULL)
1710 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
1711 data->rx_from_unknown.len);
1714 if (wpa_s->ap_iface == NULL) {
1717 const struct ieee80211_mgmt *mgmt;
1718 mgmt = (const struct ieee80211_mgmt *)
1719 data->rx_mgmt.frame;
1720 fc = le_to_host16(mgmt->frame_control);
1721 stype = WLAN_FC_GET_STYPE(fc);
1722 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
1723 data->rx_mgmt.frame_len > 24) {
1724 const u8 *src = mgmt->sa;
1725 const u8 *ie = mgmt->u.probe_req.variable;
1726 size_t ie_len = data->rx_mgmt.frame_len -
1727 (mgmt->u.probe_req.variable -
1728 data->rx_mgmt.frame);
1729 wpas_p2p_probe_req_rx(wpa_s, src, ie, ie_len);
1732 #endif /* CONFIG_P2P */
1733 wpa_printf(MSG_DEBUG, "AP: ignore received management "
1734 "frame in non-AP mode");
1737 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
1739 #endif /* CONFIG_AP */
1740 case EVENT_RX_ACTION:
1741 wpa_printf(MSG_DEBUG, "Received Action frame: SA=" MACSTR
1742 " Category=%u DataLen=%d freq=%d MHz",
1743 MAC2STR(data->rx_action.sa),
1744 data->rx_action.category, (int) data->rx_action.len,
1745 data->rx_action.freq);
1746 #ifdef CONFIG_IEEE80211R
1747 if (data->rx_action.category == WLAN_ACTION_FT) {
1748 ft_rx_action(wpa_s, data->rx_action.data,
1749 data->rx_action.len);
1752 #endif /* CONFIG_IEEE80211R */
1754 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
1756 data->rx_action.bssid,
1757 data->rx_action.category,
1758 data->rx_action.data,
1759 data->rx_action.len, data->rx_action.freq);
1760 #endif /* CONFIG_P2P */
1763 case EVENT_REMAIN_ON_CHANNEL:
1764 wpas_p2p_remain_on_channel_cb(
1765 wpa_s, data->remain_on_channel.freq,
1766 data->remain_on_channel.duration);
1768 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
1769 wpas_p2p_cancel_remain_on_channel_cb(
1770 wpa_s, data->remain_on_channel.freq);
1772 case EVENT_RX_PROBE_REQ:
1773 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
1774 data->rx_probe_req.ie,
1775 data->rx_probe_req.ie_len);
1777 #endif /* CONFIG_P2P */
1778 #ifdef CONFIG_CLIENT_MLME
1779 case EVENT_MLME_RX: {
1780 struct ieee80211_rx_status rx_status;
1781 os_memset(&rx_status, 0, sizeof(rx_status));
1782 rx_status.freq = data->mlme_rx.freq;
1783 rx_status.channel = data->mlme_rx.channel;
1784 rx_status.ssi = data->mlme_rx.ssi;
1785 ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
1789 #endif /* CONFIG_CLIENT_MLME */
1790 case EVENT_EAPOL_RX:
1791 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
1792 data->eapol_rx.data,
1793 data->eapol_rx.data_len);
1795 case EVENT_SIGNAL_CHANGE:
1796 bgscan_notify_signal_change(
1797 wpa_s, data->signal_change.above_threshold,
1798 data->signal_change.current_signal);
1800 case EVENT_INTERFACE_ENABLED:
1801 wpa_printf(MSG_DEBUG, "Interface was enabled");
1802 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
1803 wpa_supplicant_set_state(wpa_s,
1805 wpa_supplicant_req_scan(wpa_s, 0, 0);
1808 case EVENT_INTERFACE_DISABLED:
1809 wpa_printf(MSG_DEBUG, "Interface was disabled");
1810 wpa_supplicant_mark_disassoc(wpa_s);
1811 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
1814 wpa_printf(MSG_INFO, "Unknown event %d", event);