2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2011, 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 "crypto/random.h"
36 #include "blacklist.h"
37 #include "wpas_glue.h"
38 #include "wps_supplicant.h"
41 #include "gas_query.h"
42 #include "p2p_supplicant.h"
48 #include "offchannel.h"
51 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
53 struct wpa_ssid *ssid, *old_ssid;
55 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
58 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
60 ssid = wpa_supplicant_get_ssid(wpa_s);
62 wpa_msg(wpa_s, MSG_INFO,
63 "No network configuration found for the current AP");
68 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
72 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
74 if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
75 WPA_KEY_MGMT_WPA_NONE |
76 WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X |
77 WPA_KEY_MGMT_PSK_SHA256 |
78 WPA_KEY_MGMT_IEEE8021X_SHA256)) {
80 size_t wpa_ie_len = sizeof(wpa_ie);
81 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
84 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
87 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
88 eapol_sm_invalidate_cached_session(wpa_s->eapol);
89 old_ssid = wpa_s->current_ssid;
90 wpa_s->current_ssid = ssid;
91 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
92 wpa_supplicant_initiate_eapol(wpa_s);
93 if (old_ssid != wpa_s->current_ssid)
94 wpas_notify_network_changed(wpa_s);
100 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
103 struct wpa_supplicant *wpa_s = eloop_ctx;
105 if (wpa_s->countermeasures) {
106 wpa_s->countermeasures = 0;
107 wpa_drv_set_countermeasures(wpa_s, 0);
108 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
109 wpa_supplicant_req_scan(wpa_s, 0, 0);
114 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
118 #ifdef CONFIG_IBSS_RSN
119 ibss_rsn_deinit(wpa_s->ibss_rsn);
120 wpa_s->ibss_rsn = NULL;
121 #endif /* CONFIG_IBSS_RSN */
124 wpa_supplicant_ap_deinit(wpa_s);
125 #endif /* CONFIG_AP */
127 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
130 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
131 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
132 os_memset(wpa_s->bssid, 0, ETH_ALEN);
133 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
134 wpa_s->current_bss = NULL;
135 wpa_s->assoc_freq = 0;
136 #ifdef CONFIG_IEEE80211R
138 if (wpa_s->sme.ft_ies)
139 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
140 #endif /* CONFIG_SME */
141 #endif /* CONFIG_IEEE80211R */
144 wpas_notify_bssid_changed(wpa_s);
146 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
147 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
148 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
149 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
150 wpa_s->ap_ies_from_associnfo = 0;
154 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
156 struct wpa_ie_data ie;
160 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
164 for (i = 0; i < ie.num_pmkid; i++) {
165 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
166 ie.pmkid + i * PMKID_LEN,
168 if (pmksa_set == 0) {
169 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
174 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
175 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
179 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
180 union wpa_event_data *data)
183 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
187 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
188 " index=%d preauth=%d",
189 MAC2STR(data->pmkid_candidate.bssid),
190 data->pmkid_candidate.index,
191 data->pmkid_candidate.preauth);
193 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
194 data->pmkid_candidate.index,
195 data->pmkid_candidate.preauth);
199 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
201 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
202 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
205 #ifdef IEEE8021X_EAPOL
206 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
207 wpa_s->current_ssid &&
208 !(wpa_s->current_ssid->eapol_flags &
209 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
210 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
211 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
212 * plaintext or static WEP keys). */
215 #endif /* IEEE8021X_EAPOL */
222 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
223 * @wpa_s: pointer to wpa_supplicant data
224 * @ssid: Configuration data for the network
225 * Returns: 0 on success, -1 on failure
227 * This function is called when starting authentication with a network that is
228 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
230 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
231 struct wpa_ssid *ssid)
233 #ifdef IEEE8021X_EAPOL
234 int aka = 0, sim = 0, type;
236 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
239 if (ssid->eap.eap_methods == NULL) {
243 struct eap_method_type *eap = ssid->eap.eap_methods;
244 while (eap->vendor != EAP_VENDOR_IETF ||
245 eap->method != EAP_TYPE_NONE) {
246 if (eap->vendor == EAP_VENDOR_IETF) {
247 if (eap->method == EAP_TYPE_SIM)
249 else if (eap->method == EAP_TYPE_AKA)
256 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
258 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
262 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
263 "use SIM, but neither EAP-SIM nor EAP-AKA are "
268 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
269 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
271 type = SCARD_TRY_BOTH;
273 type = SCARD_USIM_ONLY;
275 type = SCARD_GSM_SIM_ONLY;
277 wpa_s->scard = scard_init(type);
278 if (wpa_s->scard == NULL) {
279 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
283 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
284 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
285 #endif /* IEEE8021X_EAPOL */
291 #ifndef CONFIG_NO_SCAN_PROCESSING
292 static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
293 struct wpa_ssid *ssid)
297 if (ssid->mixed_cell)
301 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
303 #endif /* CONFIG_WPS */
305 for (i = 0; i < NUM_WEP_KEYS; i++) {
306 if (ssid->wep_key_len[i]) {
311 #ifdef IEEE8021X_EAPOL
312 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
313 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
314 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
316 #endif /* IEEE8021X_EAPOL */
318 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
321 if (bss->caps & IEEE80211_CAP_PRIVACY)
327 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
328 struct wpa_ssid *ssid,
329 struct wpa_scan_res *bss)
331 struct wpa_ie_data ie;
333 const u8 *rsn_ie, *wpa_ie;
337 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
341 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
342 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
343 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
344 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
345 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
347 rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
348 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
351 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
352 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
358 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
360 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
365 if (!(ie.proto & ssid->proto)) {
366 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
371 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
372 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
377 if (!(ie.group_cipher & ssid->group_cipher)) {
378 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
383 if (!(ie.key_mgmt & ssid->key_mgmt)) {
384 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
389 #ifdef CONFIG_IEEE80211W
390 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
391 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
392 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
396 #endif /* CONFIG_IEEE80211W */
398 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
402 wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
403 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
406 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
407 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
413 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
415 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
420 if (!(ie.proto & ssid->proto)) {
421 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
426 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
427 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
432 if (!(ie.group_cipher & ssid->group_cipher)) {
433 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
438 if (!(ie.key_mgmt & ssid->key_mgmt)) {
439 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
444 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
448 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
449 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
450 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
454 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
455 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
459 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
466 static int freq_allowed(int *freqs, int freq)
473 for (i = 0; freqs[i]; i++)
474 if (freqs[i] == freq)
480 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
481 int i, struct wpa_scan_res *bss,
482 struct wpa_ssid *group)
485 u8 wpa_ie_len, rsn_ie_len, ssid_len;
487 struct wpa_blacklist *e;
489 struct wpa_ssid *ssid;
491 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
492 ssid_ = ie ? ie + 2 : (u8 *) "";
493 ssid_len = ie ? ie[1] : 0;
495 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
496 wpa_ie_len = ie ? ie[1] : 0;
498 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
499 rsn_ie_len = ie ? ie[1] : 0;
501 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
502 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
503 i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
504 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
505 wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
507 e = wpa_blacklist_get(wpa_s, bss->bssid);
510 if (wpa_supplicant_enabled_networks(wpa_s->conf) == 1) {
512 * When only a single network is enabled, we can
513 * trigger blacklisting on the first failure. This
514 * should not be done with multiple enabled networks to
515 * avoid getting forced to move into a worse ESS on
516 * single error if there are no other BSSes of the
521 if (e->count > limit) {
522 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
523 "(count=%d limit=%d)", e->count, limit);
529 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
533 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
535 for (ssid = group; ssid; ssid = ssid->pnext) {
536 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
538 if (ssid->disabled) {
539 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
544 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
545 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
550 if (wpa && ssid->ssid_len == 0 &&
551 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
554 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
555 /* Only allow wildcard SSID match if an AP
556 * advertises active WPS operation that matches
559 if (ssid->ssid_len == 0 &&
560 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
563 #endif /* CONFIG_WPS */
565 if (ssid->bssid_set && ssid->ssid_len == 0 &&
566 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
570 (ssid_len != ssid->ssid_len ||
571 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
572 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
576 if (ssid->bssid_set &&
577 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
578 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
582 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
586 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
587 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
588 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
589 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
594 if (!wpa_supplicant_match_privacy(bss, ssid)) {
595 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
600 if (bss->caps & IEEE80211_CAP_IBSS) {
601 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
606 if (!freq_allowed(ssid->freq_list, bss->freq)) {
607 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
614 * TODO: skip the AP if its P2P IE has Group Formation
615 * bit set in the P2P Group Capability Bitmap and we
616 * are not in Group Formation with that device.
618 #endif /* CONFIG_P2P */
620 /* Matching configuration found */
624 /* No matching configuration found */
629 static struct wpa_bss *
630 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
631 struct wpa_scan_results *scan_res,
632 struct wpa_ssid *group,
633 struct wpa_ssid **selected_ssid)
637 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
640 for (i = 0; i < scan_res->num; i++) {
641 struct wpa_scan_res *bss = scan_res->res[i];
645 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
649 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
650 ssid = ie ? ie + 2 : (u8 *) "";
651 ssid_len = ie ? ie[1] : 0;
653 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
655 MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
656 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
663 static struct wpa_bss *
664 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
665 struct wpa_scan_results *scan_res,
666 struct wpa_ssid **selected_ssid)
668 struct wpa_bss *selected = NULL;
671 while (selected == NULL) {
672 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
673 selected = wpa_supplicant_select_bss(
674 wpa_s, scan_res, wpa_s->conf->pssid[prio],
680 if (selected == NULL && wpa_s->blacklist) {
681 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
682 "blacklist and try again");
683 wpa_blacklist_clear(wpa_s);
684 wpa_s->blacklist_cleared++;
685 } else if (selected == NULL)
693 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
694 int timeout_sec, int timeout_usec)
696 if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
698 * No networks are enabled; short-circuit request so
699 * we don't wait timeout seconds before transitioning
702 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
705 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
709 void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
710 struct wpa_bss *selected,
711 struct wpa_ssid *ssid)
713 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
714 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
715 "PBC session overlap");
717 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
719 #endif /* CONFIG_P2P */
722 wpas_wps_cancel(wpa_s);
723 #endif /* CONFIG_WPS */
728 * Do not trigger new association unless the BSSID has changed or if
729 * reassociation is requested. If we are in process of associating with
730 * the selected BSSID, do not trigger new attempt.
732 if (wpa_s->reassociate ||
733 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
734 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
735 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
736 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
738 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
739 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
742 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
743 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
744 " pending: " MACSTR " wpa_state: %s",
745 wpa_s->reassociate, MAC2STR(selected->bssid),
746 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
747 wpa_supplicant_state_txt(wpa_s->wpa_state));
748 wpa_supplicant_associate(wpa_s, selected, ssid);
750 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
756 static struct wpa_ssid *
757 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
760 struct wpa_ssid *ssid;
762 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
763 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
767 if (ssid->mode == IEEE80211_MODE_IBSS ||
768 ssid->mode == IEEE80211_MODE_AP)
776 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
777 * on BSS added and BSS changed events */
778 static void wpa_supplicant_rsn_preauth_scan_results(
779 struct wpa_supplicant *wpa_s)
783 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
786 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
787 const u8 *ssid, *rsn;
789 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
793 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
797 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
803 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
804 struct wpa_bss *selected,
805 struct wpa_ssid *ssid,
806 struct wpa_scan_results *scan_res)
809 struct wpa_scan_res *current_bss = NULL;
812 if (wpa_s->reassociate)
813 return 1; /* explicit request to reassociate */
814 if (wpa_s->wpa_state < WPA_ASSOCIATED)
815 return 1; /* we are not associated; continue */
816 if (wpa_s->current_ssid == NULL)
817 return 1; /* unknown current SSID */
818 if (wpa_s->current_ssid != ssid)
819 return 1; /* different network block */
821 if (wpas_driver_bss_selection(wpa_s))
822 return 0; /* Driver-based roaming */
824 for (i = 0; i < scan_res->num; i++) {
825 struct wpa_scan_res *res = scan_res->res[i];
827 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
830 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
833 if (ie[1] != wpa_s->current_ssid->ssid_len ||
834 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
841 return 1; /* current BSS not seen in scan results */
843 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
844 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
845 MAC2STR(current_bss->bssid), current_bss->level);
846 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
847 MAC2STR(selected->bssid), selected->level);
849 if (wpa_s->current_ssid->bssid_set &&
850 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
852 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
853 "has preferred BSSID");
858 if (current_bss->level < 0) {
859 if (current_bss->level < -85)
861 else if (current_bss->level < -80)
863 else if (current_bss->level < -75)
865 else if (current_bss->level < -70)
870 if (abs(current_bss->level - selected->level) < min_diff) {
871 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
879 /* Return < 0 if no scan results could be fetched. */
880 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
881 union wpa_event_data *data)
883 struct wpa_bss *selected;
884 struct wpa_ssid *ssid = NULL;
885 struct wpa_scan_results *scan_res;
891 #endif /* CONFIG_AP */
893 wpa_supplicant_notify_scanning(wpa_s, 0);
895 scan_res = wpa_supplicant_get_scan_results(wpa_s,
896 data ? &data->scan_info :
898 if (scan_res == NULL) {
899 if (wpa_s->conf->ap_scan == 2 || ap)
901 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
903 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
907 #ifndef CONFIG_NO_RANDOM_POOL
912 for (i = 0; i < num; i++) {
914 struct wpa_scan_res *res = scan_res->res[i];
915 buf[0] = res->bssid[5];
916 buf[1] = res->qual & 0xff;
917 buf[2] = res->noise & 0xff;
918 buf[3] = res->level & 0xff;
919 buf[4] = res->tsf & 0xff;
920 random_add_randomness(buf, sizeof(buf));
922 #endif /* CONFIG_NO_RANDOM_POOL */
924 if (wpa_s->scan_res_handler) {
925 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
926 struct wpa_scan_results *scan_res);
928 scan_res_handler = wpa_s->scan_res_handler;
929 wpa_s->scan_res_handler = NULL;
930 scan_res_handler(wpa_s, scan_res);
932 wpa_scan_results_free(scan_res);
937 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
939 if (wpa_s->ap_iface->scan_cb)
940 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
941 #endif /* CONFIG_AP */
942 wpa_scan_results_free(scan_res);
946 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
947 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
948 wpas_notify_scan_results(wpa_s);
950 wpas_notify_scan_done(wpa_s, 1);
952 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
953 wpa_scan_results_free(scan_res);
957 if (wpa_s->disconnected) {
958 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
959 wpa_scan_results_free(scan_res);
963 if (!wpas_driver_bss_selection(wpa_s) &&
964 bgscan_notify_scan(wpa_s, scan_res) == 1) {
965 wpa_scan_results_free(scan_res);
969 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
973 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
975 wpa_scan_results_free(scan_res);
978 wpa_supplicant_connect(wpa_s, selected, ssid);
979 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
981 wpa_scan_results_free(scan_res);
982 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
983 ssid = wpa_supplicant_pick_new_network(wpa_s);
985 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
986 wpa_supplicant_associate(wpa_s, NULL, ssid);
987 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
989 int timeout_sec = wpa_s->scan_interval;
990 int timeout_usec = 0;
992 if (wpa_s->p2p_in_provisioning) {
994 * Use shorter wait during P2P Provisioning
995 * state to speed up group formation.
998 timeout_usec = 250000;
999 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1003 #endif /* CONFIG_P2P */
1004 if (wpa_supplicant_req_sched_scan(wpa_s))
1005 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1013 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1014 union wpa_event_data *data)
1016 const char *rn, *rn2;
1017 struct wpa_supplicant *ifs;
1019 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
1021 * If no scan results could be fetched, then no need to
1022 * notify those interfaces that did not actually request
1029 * Check other interfaces to see if they have the same radio-name. If
1030 * so, they get updated with this same scan info.
1032 if (!wpa_s->driver->get_radio_name)
1035 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1036 if (rn == NULL || rn[0] == '\0')
1039 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1040 "sharing same radio (%s) in event_scan_results", rn);
1042 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1043 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1046 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1047 if (rn2 && os_strcmp(rn, rn2) == 0) {
1048 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1049 "sibling", ifs->ifname);
1050 _wpa_supplicant_event_scan_results(ifs, data);
1055 #endif /* CONFIG_NO_SCAN_PROCESSING */
1058 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1059 union wpa_event_data *data)
1061 int l, len, found = 0, wpa_found, rsn_found;
1064 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1065 if (data->assoc_info.req_ies)
1066 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1067 data->assoc_info.req_ies_len);
1068 if (data->assoc_info.resp_ies) {
1069 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1070 data->assoc_info.resp_ies_len);
1072 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1073 data->assoc_info.resp_ies_len);
1074 #endif /* CONFIG_TDLS */
1076 if (data->assoc_info.beacon_ies)
1077 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1078 data->assoc_info.beacon_ies,
1079 data->assoc_info.beacon_ies_len);
1080 if (data->assoc_info.freq)
1081 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1082 data->assoc_info.freq);
1084 p = data->assoc_info.req_ies;
1085 l = data->assoc_info.req_ies_len;
1087 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1088 while (p && l >= 2) {
1091 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1095 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1096 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1097 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1098 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1101 wpa_find_assoc_pmkid(wpa_s);
1107 if (!found && data->assoc_info.req_ies)
1108 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1110 #ifdef CONFIG_IEEE80211R
1112 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1114 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1115 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1116 data->assoc_info.resp_ies,
1117 data->assoc_info.resp_ies_len,
1119 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1120 "Reassociation Response failed");
1121 wpa_supplicant_deauthenticate(
1122 wpa_s, WLAN_REASON_INVALID_IE);
1127 p = data->assoc_info.resp_ies;
1128 l = data->assoc_info.resp_ies_len;
1130 #ifdef CONFIG_WPS_STRICT
1131 if (p && wpa_s->current_ssid &&
1132 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1134 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1136 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1137 "include WPS IE in (Re)Association Response");
1141 if (wps_validate_assoc_resp(wps) < 0) {
1143 wpa_supplicant_deauthenticate(
1144 wpa_s, WLAN_REASON_INVALID_IE);
1149 #endif /* CONFIG_WPS_STRICT */
1151 /* Go through the IEs and make a copy of the MDIE, if present. */
1152 while (p && l >= 2) {
1155 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1159 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1160 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1161 wpa_s->sme.ft_used = 1;
1162 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1163 MOBILITY_DOMAIN_ID_LEN);
1169 #endif /* CONFIG_SME */
1171 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1172 data->assoc_info.resp_ies_len);
1173 #endif /* CONFIG_IEEE80211R */
1175 /* WPA/RSN IE from Beacon/ProbeResp */
1176 p = data->assoc_info.beacon_ies;
1177 l = data->assoc_info.beacon_ies_len;
1179 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1181 wpa_found = rsn_found = 0;
1182 while (p && l >= 2) {
1185 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1190 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1191 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1193 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1197 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1199 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1206 if (!wpa_found && data->assoc_info.beacon_ies)
1207 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1208 if (!rsn_found && data->assoc_info.beacon_ies)
1209 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1210 if (wpa_found || rsn_found)
1211 wpa_s->ap_ies_from_associnfo = 1;
1213 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1214 wpa_s->assoc_freq != data->assoc_info.freq) {
1215 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1217 wpa_s->assoc_freq, data->assoc_info.freq);
1218 wpa_supplicant_update_scan_results(wpa_s);
1221 wpa_s->assoc_freq = data->assoc_info.freq;
1227 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1228 union wpa_event_data *data)
1233 struct wpa_driver_capa capa;
1236 if (wpa_s->ap_iface) {
1237 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1238 data->assoc_info.addr,
1239 data->assoc_info.req_ies,
1240 data->assoc_info.req_ies_len,
1241 data->assoc_info.reassoc);
1244 #endif /* CONFIG_AP */
1246 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1247 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1250 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1251 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
1252 os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
1253 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
1254 (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
1255 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
1256 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1257 MACSTR, MAC2STR(bssid));
1258 random_add_randomness(bssid, ETH_ALEN);
1259 bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
1260 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1261 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1263 wpas_notify_bssid_changed(wpa_s);
1265 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1266 wpa_clear_keys(wpa_s, bssid);
1268 if (wpa_supplicant_select_config(wpa_s) < 0) {
1269 wpa_supplicant_disassociate(
1270 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1273 if (wpa_s->current_ssid) {
1274 struct wpa_bss *bss = NULL;
1275 struct wpa_ssid *ssid = wpa_s->current_ssid;
1276 if (ssid->ssid_len > 0)
1277 bss = wpa_bss_get(wpa_s, bssid,
1278 ssid->ssid, ssid->ssid_len);
1280 bss = wpa_bss_get_bssid(wpa_s, bssid);
1282 wpa_s->current_bss = bss;
1287 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1288 wpa_s->sme.prev_bssid_set = 1;
1289 #endif /* CONFIG_SME */
1291 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1292 if (wpa_s->current_ssid) {
1293 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1294 * initialized before association, but for other modes,
1295 * initialize PC/SC here, if the current configuration needs
1296 * smartcard or SIM/USIM. */
1297 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1299 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1301 l2_packet_notify_auth_start(wpa_s->l2);
1304 * Set portEnabled first to FALSE in order to get EAP state machine out
1305 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1306 * state machine may transit to AUTHENTICATING state based on obsolete
1307 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1308 * AUTHENTICATED without ever giving chance to EAP state machine to
1311 if (!ft_completed) {
1312 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1313 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1315 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1316 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1317 /* 802.1X::portControl = Auto */
1318 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1319 wpa_s->eapol_received = 0;
1320 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1321 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1322 (wpa_s->current_ssid &&
1323 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1324 wpa_supplicant_cancel_auth_timeout(wpa_s);
1325 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1326 } else if (!ft_completed) {
1327 /* Timeout for receiving the first EAPOL packet */
1328 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1330 wpa_supplicant_cancel_scan(wpa_s);
1332 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1333 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1335 * We are done; the driver will take care of RSN 4-way
1338 wpa_supplicant_cancel_auth_timeout(wpa_s);
1339 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1340 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1341 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1342 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1343 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1345 * The driver will take care of RSN 4-way handshake, so we need
1346 * to allow EAPOL supplicant to complete its work without
1347 * waiting for WPA supplicant.
1349 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1350 } else if (ft_completed) {
1352 * FT protocol completed - make sure EAPOL state machine ends
1353 * up in authenticated.
1355 wpa_supplicant_cancel_auth_timeout(wpa_s);
1356 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1357 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1358 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1361 if (wpa_s->pending_eapol_rx) {
1362 struct os_time now, age;
1364 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1365 if (age.sec == 0 && age.usec < 100000 &&
1366 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1368 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1369 "frame that was received just before "
1370 "association notification");
1371 wpa_supplicant_rx_eapol(
1372 wpa_s, wpa_s->pending_eapol_rx_src,
1373 wpabuf_head(wpa_s->pending_eapol_rx),
1374 wpabuf_len(wpa_s->pending_eapol_rx));
1376 wpabuf_free(wpa_s->pending_eapol_rx);
1377 wpa_s->pending_eapol_rx = NULL;
1380 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1381 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1382 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1383 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1384 /* Set static WEP keys again */
1385 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1388 #ifdef CONFIG_IBSS_RSN
1389 if (wpa_s->current_ssid &&
1390 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1391 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1392 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1393 wpa_s->ibss_rsn == NULL) {
1394 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1395 if (!wpa_s->ibss_rsn) {
1396 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1397 wpa_supplicant_deauthenticate(
1398 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1402 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1404 #endif /* CONFIG_IBSS_RSN */
1408 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1413 u8 prev_pending_bssid[ETH_ALEN];
1415 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1416 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1418 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1420 * At least Host AP driver and a Prism3 card seemed to be
1421 * generating streams of disconnected events when configuring
1422 * IBSS for WPA-None. Ignore them for now.
1424 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1425 "IBSS/WPA-None mode");
1429 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1430 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1431 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1432 "pre-shared key may be incorrect");
1434 if (!wpa_s->auto_reconnect_disabled ||
1435 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1436 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect enabled: try to "
1437 "reconnect (wps=%d)",
1438 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS);
1439 if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1440 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1442 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect disabled: do not "
1443 "try to re-connect");
1444 wpa_s->reassociate = 0;
1445 wpa_s->disconnected = 1;
1447 bssid = wpa_s->bssid;
1448 if (is_zero_ether_addr(bssid))
1449 bssid = wpa_s->pending_bssid;
1450 wpas_connection_failed(wpa_s, bssid);
1451 wpa_sm_notify_disassoc(wpa_s->wpa);
1452 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1454 MAC2STR(bssid), reason_code);
1455 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1456 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1457 wpa_s->keys_cleared = 0;
1458 wpa_clear_keys(wpa_s, wpa_s->bssid);
1460 wpa_supplicant_mark_disassoc(wpa_s);
1462 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1463 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1467 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1468 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
1471 struct wpa_supplicant *wpa_s = eloop_ctx;
1473 if (!wpa_s->pending_mic_error_report)
1476 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1477 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1478 wpa_s->pending_mic_error_report = 0;
1480 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1484 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1485 union wpa_event_data *data)
1490 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1491 pairwise = (data && data->michael_mic_failure.unicast);
1493 if ((wpa_s->last_michael_mic_error &&
1494 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1495 wpa_s->pending_mic_error_report) {
1496 if (wpa_s->pending_mic_error_report) {
1498 * Send the pending MIC error report immediately since
1499 * we are going to start countermeasures and AP better
1502 wpa_sm_key_request(wpa_s->wpa, 1,
1503 wpa_s->pending_mic_error_pairwise);
1506 /* Send the new MIC error report immediately since we are going
1507 * to start countermeasures and AP better do the same.
1509 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1511 /* initialize countermeasures */
1512 wpa_s->countermeasures = 1;
1513 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1516 * Need to wait for completion of request frame. We do not get
1517 * any callback for the message completion, so just wait a
1518 * short while and hope for the best. */
1521 wpa_drv_set_countermeasures(wpa_s, 1);
1522 wpa_supplicant_deauthenticate(wpa_s,
1523 WLAN_REASON_MICHAEL_MIC_FAILURE);
1524 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1526 eloop_register_timeout(60, 0,
1527 wpa_supplicant_stop_countermeasures,
1529 /* TODO: mark the AP rejected for 60 second. STA is
1530 * allowed to associate with another AP.. */
1532 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1533 if (wpa_s->mic_errors_seen) {
1535 * Reduce the effectiveness of Michael MIC error
1536 * reports as a means for attacking against TKIP if
1537 * more than one MIC failure is noticed with the same
1538 * PTK. We delay the transmission of the reports by a
1539 * random time between 0 and 60 seconds in order to
1540 * force the attacker wait 60 seconds before getting
1541 * the information on whether a frame resulted in a MIC
1547 if (os_get_random(rval, sizeof(rval)) < 0)
1548 sec = os_random() % 60;
1550 sec = WPA_GET_BE32(rval) % 60;
1551 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
1552 "report %d seconds", sec);
1553 wpa_s->pending_mic_error_report = 1;
1554 wpa_s->pending_mic_error_pairwise = pairwise;
1555 eloop_cancel_timeout(
1556 wpa_supplicant_delayed_mic_error_report,
1558 eloop_register_timeout(
1559 sec, os_random() % 1000000,
1560 wpa_supplicant_delayed_mic_error_report,
1563 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1565 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1566 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1567 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1569 wpa_s->last_michael_mic_error = t.sec;
1570 wpa_s->mic_errors_seen++;
1574 #ifdef CONFIG_TERMINATE_ONLASTIF
1575 static int any_interfaces(struct wpa_supplicant *head)
1577 struct wpa_supplicant *wpa_s;
1579 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1580 if (!wpa_s->interface_removed)
1584 #endif /* CONFIG_TERMINATE_ONLASTIF */
1588 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1589 union wpa_event_data *data)
1591 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1594 switch (data->interface_status.ievent) {
1595 case EVENT_INTERFACE_ADDED:
1596 if (!wpa_s->interface_removed)
1598 wpa_s->interface_removed = 0;
1599 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
1600 if (wpa_supplicant_driver_init(wpa_s) < 0) {
1601 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
1602 "driver after interface was added");
1605 case EVENT_INTERFACE_REMOVED:
1606 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
1607 wpa_s->interface_removed = 1;
1608 wpa_supplicant_mark_disassoc(wpa_s);
1609 l2_packet_deinit(wpa_s->l2);
1611 #ifdef CONFIG_IBSS_RSN
1612 ibss_rsn_deinit(wpa_s->ibss_rsn);
1613 wpa_s->ibss_rsn = NULL;
1614 #endif /* CONFIG_IBSS_RSN */
1615 #ifdef CONFIG_TERMINATE_ONLASTIF
1616 /* check if last interface */
1617 if (!any_interfaces(wpa_s->global->ifaces))
1619 #endif /* CONFIG_TERMINATE_ONLASTIF */
1625 #ifdef CONFIG_PEERKEY
1627 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
1628 union wpa_event_data *data)
1632 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
1634 #endif /* CONFIG_PEERKEY */
1638 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
1639 union wpa_event_data *data)
1643 switch (data->tdls.oper) {
1644 case TDLS_REQUEST_SETUP:
1645 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
1647 case TDLS_REQUEST_TEARDOWN:
1648 /* request from driver to add FTIE */
1649 wpa_tdls_recv_teardown_notify(wpa_s->wpa, data->tdls.peer,
1650 data->tdls.reason_code);
1654 #endif /* CONFIG_TDLS */
1657 #ifdef CONFIG_IEEE80211R
1659 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
1660 union wpa_event_data *data)
1665 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
1666 data->ft_ies.ies_len,
1667 data->ft_ies.ft_action,
1668 data->ft_ies.target_ap,
1669 data->ft_ies.ric_ies,
1670 data->ft_ies.ric_ies_len) < 0) {
1671 /* TODO: prevent MLME/driver from trying to associate? */
1674 #endif /* CONFIG_IEEE80211R */
1677 #ifdef CONFIG_IBSS_RSN
1678 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
1679 union wpa_event_data *data)
1681 struct wpa_ssid *ssid;
1682 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1686 ssid = wpa_s->current_ssid;
1689 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
1692 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
1694 #endif /* CONFIG_IBSS_RSN */
1697 #ifdef CONFIG_IEEE80211R
1698 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
1701 const u8 *sta_addr, *target_ap_addr;
1704 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
1705 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1706 return; /* only SME case supported for now */
1707 if (len < 1 + 2 * ETH_ALEN + 2)
1710 return; /* Only FT Action Response is supported for now */
1711 sta_addr = data + 1;
1712 target_ap_addr = data + 1 + ETH_ALEN;
1713 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
1714 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
1715 MACSTR " TargetAP " MACSTR " status %u",
1716 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
1718 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
1719 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
1720 " in FT Action Response", MAC2STR(sta_addr));
1725 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
1726 "failure (status code %d)", status);
1727 /* TODO: report error to FT code(?) */
1731 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
1732 len - (1 + 2 * ETH_ALEN + 2), 1,
1733 target_ap_addr, NULL, 0) < 0)
1738 struct wpa_bss *bss;
1739 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
1741 wpa_s->sme.freq = bss->freq;
1742 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
1743 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
1746 #endif /* CONFIG_SME */
1748 #endif /* CONFIG_IEEE80211R */
1751 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
1752 struct unprot_deauth *e)
1754 #ifdef CONFIG_IEEE80211W
1755 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
1756 "dropped: " MACSTR " -> " MACSTR
1757 " (reason code %u)",
1758 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
1759 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
1760 #endif /* CONFIG_IEEE80211W */
1764 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
1765 struct unprot_disassoc *e)
1767 #ifdef CONFIG_IEEE80211W
1768 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
1769 "dropped: " MACSTR " -> " MACSTR
1770 " (reason code %u)",
1771 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
1772 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
1773 #endif /* CONFIG_IEEE80211W */
1777 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1778 union wpa_event_data *data)
1780 struct wpa_supplicant *wpa_s = ctx;
1781 u16 reason_code = 0;
1783 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
1784 event != EVENT_INTERFACE_ENABLED &&
1785 event != EVENT_INTERFACE_STATUS) {
1786 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore event %d while interface is "
1791 wpa_dbg(wpa_s, MSG_DEBUG, "Event %d received on interface %s",
1792 event, wpa_s->ifname);
1796 sme_event_auth(wpa_s, data);
1799 wpa_supplicant_event_assoc(wpa_s, data);
1801 case EVENT_DISASSOC:
1802 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
1804 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
1805 data->disassoc_info.reason_code);
1806 if (data->disassoc_info.addr)
1807 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
1808 MAC2STR(data->disassoc_info.addr));
1811 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
1812 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1813 data->disassoc_info.addr);
1816 #endif /* CONFIG_AP */
1818 reason_code = data->disassoc_info.reason_code;
1819 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
1820 data->disassoc_info.ie,
1821 data->disassoc_info.ie_len);
1823 wpas_p2p_disassoc_notif(
1824 wpa_s, data->disassoc_info.addr, reason_code,
1825 data->disassoc_info.ie,
1826 data->disassoc_info.ie_len);
1827 #endif /* CONFIG_P2P */
1829 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
1830 sme_event_disassoc(wpa_s, data);
1833 if (event == EVENT_DEAUTH) {
1834 wpa_dbg(wpa_s, MSG_DEBUG,
1835 "Deauthentication notification");
1837 reason_code = data->deauth_info.reason_code;
1838 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
1839 data->deauth_info.reason_code);
1840 if (data->deauth_info.addr) {
1841 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
1843 MAC2STR(data->deauth_info.
1846 wpa_hexdump(MSG_DEBUG,
1847 "Deauthentication frame IE(s)",
1848 data->deauth_info.ie,
1849 data->deauth_info.ie_len);
1851 wpas_p2p_deauth_notif(
1852 wpa_s, data->deauth_info.addr,
1854 data->deauth_info.ie,
1855 data->deauth_info.ie_len);
1856 #endif /* CONFIG_P2P */
1860 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
1861 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1862 data->deauth_info.addr);
1865 #endif /* CONFIG_AP */
1866 wpa_supplicant_event_disassoc(wpa_s, reason_code);
1868 case EVENT_MICHAEL_MIC_FAILURE:
1869 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
1871 #ifndef CONFIG_NO_SCAN_PROCESSING
1872 case EVENT_SCAN_RESULTS:
1873 wpa_supplicant_event_scan_results(wpa_s, data);
1875 #endif /* CONFIG_NO_SCAN_PROCESSING */
1876 case EVENT_ASSOCINFO:
1877 wpa_supplicant_event_associnfo(wpa_s, data);
1879 case EVENT_INTERFACE_STATUS:
1880 wpa_supplicant_event_interface_status(wpa_s, data);
1882 case EVENT_PMKID_CANDIDATE:
1883 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
1885 #ifdef CONFIG_PEERKEY
1886 case EVENT_STKSTART:
1887 wpa_supplicant_event_stkstart(wpa_s, data);
1889 #endif /* CONFIG_PEERKEY */
1892 wpa_supplicant_event_tdls(wpa_s, data);
1894 #endif /* CONFIG_TDLS */
1895 #ifdef CONFIG_IEEE80211R
1896 case EVENT_FT_RESPONSE:
1897 wpa_supplicant_event_ft_response(wpa_s, data);
1899 #endif /* CONFIG_IEEE80211R */
1900 #ifdef CONFIG_IBSS_RSN
1901 case EVENT_IBSS_RSN_START:
1902 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
1904 #endif /* CONFIG_IBSS_RSN */
1905 case EVENT_ASSOC_REJECT:
1906 if (data->assoc_reject.bssid)
1907 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
1908 "bssid=" MACSTR " status_code=%u",
1909 MAC2STR(data->assoc_reject.bssid),
1910 data->assoc_reject.status_code);
1912 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
1914 data->assoc_reject.status_code);
1915 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
1916 sme_event_assoc_reject(wpa_s, data);
1918 case EVENT_AUTH_TIMED_OUT:
1919 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
1920 sme_event_auth_timed_out(wpa_s, data);
1922 case EVENT_ASSOC_TIMED_OUT:
1923 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
1924 sme_event_assoc_timed_out(wpa_s, data);
1926 case EVENT_TX_STATUS:
1927 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
1928 " type=%d stype=%d",
1929 MAC2STR(data->tx_status.dst),
1930 data->tx_status.type, data->tx_status.stype);
1932 if (wpa_s->ap_iface == NULL) {
1933 #ifdef CONFIG_OFFCHANNEL
1934 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
1935 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
1936 offchannel_send_action_tx_status(
1937 wpa_s, data->tx_status.dst,
1938 data->tx_status.data,
1939 data->tx_status.data_len,
1940 data->tx_status.ack ?
1941 OFFCHANNEL_SEND_ACTION_SUCCESS :
1942 OFFCHANNEL_SEND_ACTION_NO_ACK);
1943 #endif /* CONFIG_OFFCHANNEL */
1946 #endif /* CONFIG_AP */
1947 #ifdef CONFIG_OFFCHANNEL
1948 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
1949 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
1951 * Catch TX status events for Action frames we sent via group
1952 * interface in GO mode.
1954 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
1955 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
1956 os_memcmp(wpa_s->parent->pending_action_dst,
1957 data->tx_status.dst, ETH_ALEN) == 0) {
1958 offchannel_send_action_tx_status(
1959 wpa_s->parent, data->tx_status.dst,
1960 data->tx_status.data,
1961 data->tx_status.data_len,
1962 data->tx_status.ack ?
1963 OFFCHANNEL_SEND_ACTION_SUCCESS :
1964 OFFCHANNEL_SEND_ACTION_NO_ACK);
1967 #endif /* CONFIG_OFFCHANNEL */
1969 switch (data->tx_status.type) {
1970 case WLAN_FC_TYPE_MGMT:
1971 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
1972 data->tx_status.data_len,
1973 data->tx_status.stype,
1974 data->tx_status.ack);
1976 case WLAN_FC_TYPE_DATA:
1977 ap_tx_status(wpa_s, data->tx_status.dst,
1978 data->tx_status.data,
1979 data->tx_status.data_len,
1980 data->tx_status.ack);
1983 #endif /* CONFIG_AP */
1986 case EVENT_RX_FROM_UNKNOWN:
1987 if (wpa_s->ap_iface == NULL)
1989 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
1990 data->rx_from_unknown.len);
1993 if (wpa_s->ap_iface == NULL) {
1996 const struct ieee80211_mgmt *mgmt;
1997 mgmt = (const struct ieee80211_mgmt *)
1998 data->rx_mgmt.frame;
1999 fc = le_to_host16(mgmt->frame_control);
2000 stype = WLAN_FC_GET_STYPE(fc);
2001 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2002 data->rx_mgmt.frame_len > 24) {
2003 const u8 *src = mgmt->sa;
2004 const u8 *ie = mgmt->u.probe_req.variable;
2005 size_t ie_len = data->rx_mgmt.frame_len -
2006 (mgmt->u.probe_req.variable -
2007 data->rx_mgmt.frame);
2008 wpas_p2p_probe_req_rx(wpa_s, src, mgmt->da,
2009 mgmt->bssid, ie, ie_len);
2012 #endif /* CONFIG_P2P */
2013 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2014 "management frame in non-AP mode");
2017 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2019 #endif /* CONFIG_AP */
2020 case EVENT_RX_ACTION:
2021 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2022 " Category=%u DataLen=%d freq=%d MHz",
2023 MAC2STR(data->rx_action.sa),
2024 data->rx_action.category, (int) data->rx_action.len,
2025 data->rx_action.freq);
2026 #ifdef CONFIG_IEEE80211R
2027 if (data->rx_action.category == WLAN_ACTION_FT) {
2028 ft_rx_action(wpa_s, data->rx_action.data,
2029 data->rx_action.len);
2032 #endif /* CONFIG_IEEE80211R */
2033 #ifdef CONFIG_IEEE80211W
2035 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2036 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2037 data->rx_action.data,
2038 data->rx_action.len);
2041 #endif /* CONFIG_SME */
2042 #endif /* CONFIG_IEEE80211W */
2044 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2045 gas_query_rx(wpa_s->gas, data->rx_action.da,
2046 data->rx_action.sa, data->rx_action.bssid,
2047 data->rx_action.data, data->rx_action.len,
2048 data->rx_action.freq) == 0)
2050 #endif /* CONFIG_GAS */
2052 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2054 data->rx_action.bssid,
2055 data->rx_action.category,
2056 data->rx_action.data,
2057 data->rx_action.len, data->rx_action.freq);
2058 #endif /* CONFIG_P2P */
2060 case EVENT_RX_PROBE_REQ:
2061 if (data->rx_probe_req.sa == NULL ||
2062 data->rx_probe_req.ie == NULL)
2065 if (wpa_s->ap_iface) {
2066 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2067 data->rx_probe_req.sa,
2068 data->rx_probe_req.da,
2069 data->rx_probe_req.bssid,
2070 data->rx_probe_req.ie,
2071 data->rx_probe_req.ie_len);
2074 #endif /* CONFIG_AP */
2076 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2077 data->rx_probe_req.da,
2078 data->rx_probe_req.bssid,
2079 data->rx_probe_req.ie,
2080 data->rx_probe_req.ie_len);
2081 #endif /* CONFIG_P2P */
2083 case EVENT_REMAIN_ON_CHANNEL:
2084 #ifdef CONFIG_OFFCHANNEL
2085 offchannel_remain_on_channel_cb(
2086 wpa_s, data->remain_on_channel.freq,
2087 data->remain_on_channel.duration);
2088 #endif /* CONFIG_OFFCHANNEL */
2090 wpas_p2p_remain_on_channel_cb(
2091 wpa_s, data->remain_on_channel.freq,
2092 data->remain_on_channel.duration);
2093 #endif /* CONFIG_P2P */
2095 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2096 #ifdef CONFIG_OFFCHANNEL
2097 offchannel_cancel_remain_on_channel_cb(
2098 wpa_s, data->remain_on_channel.freq);
2099 #endif /* CONFIG_OFFCHANNEL */
2101 wpas_p2p_cancel_remain_on_channel_cb(
2102 wpa_s, data->remain_on_channel.freq);
2103 #endif /* CONFIG_P2P */
2106 case EVENT_P2P_DEV_FOUND: {
2107 struct p2p_peer_info peer_info;
2109 os_memset(&peer_info, 0, sizeof(peer_info));
2110 if (data->p2p_dev_found.dev_addr)
2111 os_memcpy(peer_info.p2p_device_addr,
2112 data->p2p_dev_found.dev_addr, ETH_ALEN);
2113 if (data->p2p_dev_found.pri_dev_type)
2114 os_memcpy(peer_info.pri_dev_type,
2115 data->p2p_dev_found.pri_dev_type,
2116 sizeof(peer_info.pri_dev_type));
2117 if (data->p2p_dev_found.dev_name)
2118 os_strlcpy(peer_info.device_name,
2119 data->p2p_dev_found.dev_name,
2120 sizeof(peer_info.device_name));
2121 peer_info.config_methods = data->p2p_dev_found.config_methods;
2122 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2123 peer_info.group_capab = data->p2p_dev_found.group_capab;
2126 * FIX: new_device=1 is not necessarily correct. We should
2127 * maintain a P2P peer database in wpa_supplicant and update
2128 * this information based on whether the peer is truly new.
2130 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2133 case EVENT_P2P_GO_NEG_REQ_RX:
2134 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2135 data->p2p_go_neg_req_rx.dev_passwd_id);
2137 case EVENT_P2P_GO_NEG_COMPLETED:
2138 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2140 case EVENT_P2P_PROV_DISC_REQUEST:
2141 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2142 data->p2p_prov_disc_req.config_methods,
2143 data->p2p_prov_disc_req.dev_addr,
2144 data->p2p_prov_disc_req.pri_dev_type,
2145 data->p2p_prov_disc_req.dev_name,
2146 data->p2p_prov_disc_req.supp_config_methods,
2147 data->p2p_prov_disc_req.dev_capab,
2148 data->p2p_prov_disc_req.group_capab);
2150 case EVENT_P2P_PROV_DISC_RESPONSE:
2151 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2152 data->p2p_prov_disc_resp.config_methods);
2154 case EVENT_P2P_SD_REQUEST:
2155 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2156 data->p2p_sd_req.sa,
2157 data->p2p_sd_req.dialog_token,
2158 data->p2p_sd_req.update_indic,
2159 data->p2p_sd_req.tlvs,
2160 data->p2p_sd_req.tlvs_len);
2162 case EVENT_P2P_SD_RESPONSE:
2163 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2164 data->p2p_sd_resp.update_indic,
2165 data->p2p_sd_resp.tlvs,
2166 data->p2p_sd_resp.tlvs_len);
2168 #endif /* CONFIG_P2P */
2169 #ifdef CONFIG_CLIENT_MLME
2170 case EVENT_MLME_RX: {
2171 struct ieee80211_rx_status rx_status;
2172 os_memset(&rx_status, 0, sizeof(rx_status));
2173 rx_status.freq = data->mlme_rx.freq;
2174 rx_status.channel = data->mlme_rx.channel;
2175 rx_status.ssi = data->mlme_rx.ssi;
2176 ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
2180 #endif /* CONFIG_CLIENT_MLME */
2181 case EVENT_EAPOL_RX:
2182 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2183 data->eapol_rx.data,
2184 data->eapol_rx.data_len);
2186 case EVENT_SIGNAL_CHANGE:
2187 bgscan_notify_signal_change(
2188 wpa_s, data->signal_change.above_threshold,
2189 data->signal_change.current_signal,
2190 data->signal_change.current_noise,
2191 data->signal_change.current_txrate);
2193 case EVENT_INTERFACE_ENABLED:
2194 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2195 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2197 if (!wpa_s->ap_iface) {
2198 wpa_supplicant_set_state(wpa_s,
2200 wpa_supplicant_req_scan(wpa_s, 0, 0);
2202 wpa_supplicant_set_state(wpa_s,
2204 #else /* CONFIG_AP */
2205 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2206 wpa_supplicant_req_scan(wpa_s, 0, 0);
2207 #endif /* CONFIG_AP */
2210 case EVENT_INTERFACE_DISABLED:
2211 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2212 wpa_supplicant_mark_disassoc(wpa_s);
2213 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2215 case EVENT_CHANNEL_LIST_CHANGED:
2216 if (wpa_s->drv_priv == NULL)
2217 break; /* Ignore event during drv initialization */
2219 wpas_p2p_update_channel_list(wpa_s);
2220 #endif /* CONFIG_P2P */
2222 case EVENT_INTERFACE_UNAVAILABLE:
2224 wpas_p2p_interface_unavailable(wpa_s);
2225 #endif /* CONFIG_P2P */
2227 case EVENT_BEST_CHANNEL:
2228 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2230 data->best_chan.freq_24, data->best_chan.freq_5,
2231 data->best_chan.freq_overall);
2232 wpa_s->best_24_freq = data->best_chan.freq_24;
2233 wpa_s->best_5_freq = data->best_chan.freq_5;
2234 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2236 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2237 data->best_chan.freq_5,
2238 data->best_chan.freq_overall);
2239 #endif /* CONFIG_P2P */
2241 case EVENT_UNPROT_DEAUTH:
2242 wpa_supplicant_event_unprot_deauth(wpa_s,
2243 &data->unprot_deauth);
2245 case EVENT_UNPROT_DISASSOC:
2246 wpa_supplicant_event_unprot_disassoc(wpa_s,
2247 &data->unprot_disassoc);
2249 case EVENT_STATION_LOW_ACK:
2251 if (wpa_s->ap_iface && data)
2252 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2253 data->low_ack.addr);
2254 #endif /* CONFIG_AP */
2256 case EVENT_IBSS_PEER_LOST:
2257 #ifdef CONFIG_IBSS_RSN
2258 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2259 #endif /* CONFIG_IBSS_RSN */
2261 case EVENT_DRIVER_GTK_REKEY:
2262 if (os_memcmp(data->driver_gtk_rekey.bssid,
2263 wpa_s->bssid, ETH_ALEN))
2267 wpa_sm_update_replay_ctr(wpa_s->wpa,
2268 data->driver_gtk_rekey.replay_ctr);
2270 case EVENT_SCHED_SCAN_STOPPED:
2271 wpa_s->sched_scanning = 0;
2272 wpa_supplicant_notify_scanning(wpa_s, 0);
2275 * If we timed out, start a new sched scan to continue
2276 * searching for more SSIDs.
2278 if (wpa_s->sched_scan_timed_out)
2279 wpa_supplicant_req_sched_scan(wpa_s);
2282 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);