2 * WPA Supplicant - Driver event processing
3 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "rsn_supp/wpa.h"
16 #include "l2_packet/l2_packet.h"
17 #include "wpa_supplicant_i.h"
19 #include "pcsc_funcs.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "common/wpa_ctrl.h"
23 #include "eap_peer/eap.h"
24 #include "ap/hostapd.h"
28 #include "common/ieee802_11_defs.h"
29 #include "common/ieee802_11_common.h"
30 #include "crypto/random.h"
31 #include "blacklist.h"
32 #include "wpas_glue.h"
33 #include "wps_supplicant.h"
36 #include "gas_query.h"
37 #include "p2p_supplicant.h"
43 #include "offchannel.h"
44 #include "interworking.h"
47 static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
48 struct wpa_ssid *ssid)
52 if (ssid == NULL || ssid->disabled_until.sec == 0)
56 if (ssid->disabled_until.sec > now.sec)
57 return ssid->disabled_until.sec - now.sec;
59 wpas_clear_temp_disabled(wpa_s, ssid, 0);
65 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
67 struct wpa_ssid *ssid, *old_ssid;
70 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
73 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
75 ssid = wpa_supplicant_get_ssid(wpa_s);
77 wpa_msg(wpa_s, MSG_INFO,
78 "No network configuration found for the current AP");
82 if (wpas_network_disabled(wpa_s, ssid)) {
83 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
87 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
88 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
89 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
93 res = wpas_temp_disabled(wpa_s, ssid);
95 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
96 "disabled for %d second(s)", res);
100 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
102 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
104 size_t wpa_ie_len = sizeof(wpa_ie);
105 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
106 wpa_ie, &wpa_ie_len) < 0)
107 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
109 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
112 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
113 eapol_sm_invalidate_cached_session(wpa_s->eapol);
114 old_ssid = wpa_s->current_ssid;
115 wpa_s->current_ssid = ssid;
116 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
117 wpa_supplicant_initiate_eapol(wpa_s);
118 if (old_ssid != wpa_s->current_ssid)
119 wpas_notify_network_changed(wpa_s);
125 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
127 struct wpa_supplicant *wpa_s = eloop_ctx;
129 if (wpa_s->countermeasures) {
130 wpa_s->countermeasures = 0;
131 wpa_drv_set_countermeasures(wpa_s, 0);
132 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
133 wpa_supplicant_req_scan(wpa_s, 0, 0);
138 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
142 wnm_bss_keep_alive_deinit(wpa_s);
144 #ifdef CONFIG_IBSS_RSN
145 ibss_rsn_deinit(wpa_s->ibss_rsn);
146 wpa_s->ibss_rsn = NULL;
147 #endif /* CONFIG_IBSS_RSN */
150 wpa_supplicant_ap_deinit(wpa_s);
151 #endif /* CONFIG_AP */
153 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
156 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
157 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
158 os_memset(wpa_s->bssid, 0, ETH_ALEN);
159 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
161 wpa_s->sme.prev_bssid_set = 0;
162 #endif /* CONFIG_SME */
164 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
165 #endif /* CONFIG_P2P */
166 wpa_s->current_bss = NULL;
167 wpa_s->assoc_freq = 0;
168 #ifdef CONFIG_IEEE80211R
170 if (wpa_s->sme.ft_ies)
171 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
172 #endif /* CONFIG_SME */
173 #endif /* CONFIG_IEEE80211R */
176 wpas_notify_bssid_changed(wpa_s);
178 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
179 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
180 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
181 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
182 wpa_s->ap_ies_from_associnfo = 0;
183 wpa_s->current_ssid = NULL;
188 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
190 struct wpa_ie_data ie;
194 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
198 for (i = 0; i < ie.num_pmkid; i++) {
199 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
200 ie.pmkid + i * PMKID_LEN,
202 if (pmksa_set == 0) {
203 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
208 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
209 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
213 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
214 union wpa_event_data *data)
217 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
221 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
222 " index=%d preauth=%d",
223 MAC2STR(data->pmkid_candidate.bssid),
224 data->pmkid_candidate.index,
225 data->pmkid_candidate.preauth);
227 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
228 data->pmkid_candidate.index,
229 data->pmkid_candidate.preauth);
233 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
235 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
236 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
239 #ifdef IEEE8021X_EAPOL
240 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
241 wpa_s->current_ssid &&
242 !(wpa_s->current_ssid->eapol_flags &
243 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
244 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
245 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
246 * plaintext or static WEP keys). */
249 #endif /* IEEE8021X_EAPOL */
256 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
257 * @wpa_s: pointer to wpa_supplicant data
258 * @ssid: Configuration data for the network
259 * Returns: 0 on success, -1 on failure
261 * This function is called when starting authentication with a network that is
262 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
264 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
265 struct wpa_ssid *ssid)
267 #ifdef IEEE8021X_EAPOL
269 int aka = 0, sim = 0, type;
271 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
274 if (ssid->eap.eap_methods == NULL) {
278 struct eap_method_type *eap = ssid->eap.eap_methods;
279 while (eap->vendor != EAP_VENDOR_IETF ||
280 eap->method != EAP_TYPE_NONE) {
281 if (eap->vendor == EAP_VENDOR_IETF) {
282 if (eap->method == EAP_TYPE_SIM)
284 else if (eap->method == EAP_TYPE_AKA ||
285 eap->method == EAP_TYPE_AKA_PRIME)
292 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
294 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
295 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
300 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
301 "use SIM, but neither EAP-SIM nor EAP-AKA are "
306 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
307 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
309 type = SCARD_TRY_BOTH;
311 type = SCARD_USIM_ONLY;
313 type = SCARD_GSM_SIM_ONLY;
315 wpa_s->scard = scard_init(type, NULL);
316 if (wpa_s->scard == NULL) {
317 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
321 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
322 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
323 #endif /* PCSC_FUNCS */
324 #endif /* IEEE8021X_EAPOL */
330 #ifndef CONFIG_NO_SCAN_PROCESSING
331 static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
332 struct wpa_ssid *ssid)
336 if (ssid->mixed_cell)
340 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
342 #endif /* CONFIG_WPS */
344 for (i = 0; i < NUM_WEP_KEYS; i++) {
345 if (ssid->wep_key_len[i]) {
350 #ifdef IEEE8021X_EAPOL
351 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
352 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
353 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
355 #endif /* IEEE8021X_EAPOL */
357 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
360 if (bss->caps & IEEE80211_CAP_PRIVACY)
366 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
367 struct wpa_ssid *ssid,
370 struct wpa_ie_data ie;
372 const u8 *rsn_ie, *wpa_ie;
376 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
380 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
381 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
382 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
383 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
384 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
386 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
387 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
390 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
391 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
397 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
399 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
404 if (!(ie.proto & ssid->proto)) {
405 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
410 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
411 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
416 if (!(ie.group_cipher & ssid->group_cipher)) {
417 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
422 if (!(ie.key_mgmt & ssid->key_mgmt)) {
423 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
428 #ifdef CONFIG_IEEE80211W
429 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
430 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
431 wpa_s->conf->pmf : ssid->ieee80211w) ==
432 MGMT_FRAME_PROTECTION_REQUIRED) {
433 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
437 #endif /* CONFIG_IEEE80211W */
439 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
443 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
444 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
447 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
448 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
454 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
456 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
461 if (!(ie.proto & ssid->proto)) {
462 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
467 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
468 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
473 if (!(ie.group_cipher & ssid->group_cipher)) {
474 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
479 if (!(ie.key_mgmt & ssid->key_mgmt)) {
480 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
485 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
489 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
491 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
495 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
496 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
497 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
501 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
502 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
506 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
513 static int freq_allowed(int *freqs, int freq)
520 for (i = 0; freqs[i]; i++)
521 if (freqs[i] == freq)
527 static int ht_supported(const struct hostapd_hw_modes *mode)
529 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
531 * The driver did not indicate whether it supports HT. Assume
532 * it does to avoid connection issues.
538 * IEEE Std 802.11n-2009 20.1.1:
539 * An HT non-AP STA shall support all EQM rates for one spatial stream.
541 return mode->mcs_set[0] == 0xff;
545 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
547 const struct hostapd_hw_modes *mode = NULL, *modes;
548 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
553 return 1; /* Cannot do matching without knowing band */
555 modes = wpa_s->hw.modes;
558 * The driver does not provide any additional information
559 * about the utilized hardware, so allow the connection attempt
565 for (i = 0; i < wpa_s->hw.num_modes; i++) {
566 for (j = 0; j < modes[i].num_channels; j++) {
567 int freq = modes[i].channels[j].freq;
568 if (freq == bss->freq) {
570 mode->mode == HOSTAPD_MODE_IEEE80211G)
571 break; /* do not allow 802.11b replace
582 for (i = 0; i < (int) sizeof(scan_ie); i++) {
583 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
587 for (j = 2; j < rate_ie[1] + 2; j++) {
588 int flagged = !!(rate_ie[j] & 0x80);
589 int r = (rate_ie[j] & 0x7f) * 5;
592 * IEEE Std 802.11n-2009 7.3.2.2:
593 * The new BSS Membership selector value is encoded
594 * like a legacy basic rate, but it is not a rate and
595 * only indicates if the BSS members are required to
596 * support the mandatory features of Clause 20 [HT PHY]
597 * in order to join the BSS.
599 if (flagged && ((rate_ie[j] & 0x7f) ==
600 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
601 if (!ht_supported(mode)) {
602 wpa_dbg(wpa_s, MSG_DEBUG,
603 " hardware does not support "
613 /* check for legacy basic rates */
614 for (k = 0; k < mode->num_rates; k++) {
615 if (mode->rates[k] == r)
618 if (k == mode->num_rates) {
620 * IEEE Std 802.11-2007 7.3.2.2 demands that in
621 * order to join a BSS all required rates
622 * have to be supported by the hardware.
624 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
625 "not support required rate %d.%d Mbps",
636 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
637 int i, struct wpa_bss *bss,
638 struct wpa_ssid *group)
640 u8 wpa_ie_len, rsn_ie_len;
642 struct wpa_blacklist *e;
644 struct wpa_ssid *ssid;
646 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
647 wpa_ie_len = ie ? ie[1] : 0;
649 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
650 rsn_ie_len = ie ? ie[1] : 0;
652 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
653 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
654 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
655 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
656 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
658 e = wpa_blacklist_get(wpa_s, bss->bssid);
661 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
663 * When only a single network is enabled, we can
664 * trigger blacklisting on the first failure. This
665 * should not be done with multiple enabled networks to
666 * avoid getting forced to move into a worse ESS on
667 * single error if there are no other BSSes of the
672 if (e->count > limit) {
673 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
674 "(count=%d limit=%d)", e->count, limit);
679 if (bss->ssid_len == 0) {
680 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
684 if (disallowed_bssid(wpa_s, bss->bssid)) {
685 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
689 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
690 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
694 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
696 for (ssid = group; ssid; ssid = ssid->pnext) {
697 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
700 if (wpas_network_disabled(wpa_s, ssid)) {
701 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
705 res = wpas_temp_disabled(wpa_s, ssid);
707 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
708 "temporarily for %d second(s)", res);
713 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
714 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
719 if (wpa && ssid->ssid_len == 0 &&
720 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
723 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
724 /* Only allow wildcard SSID match if an AP
725 * advertises active WPS operation that matches
728 if (ssid->ssid_len == 0 &&
729 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
732 #endif /* CONFIG_WPS */
734 if (ssid->bssid_set && ssid->ssid_len == 0 &&
735 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
739 (bss->ssid_len != ssid->ssid_len ||
740 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
741 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
745 if (ssid->bssid_set &&
746 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
747 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
751 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
755 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
756 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
757 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
758 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
763 if (!wpa_supplicant_match_privacy(bss, ssid)) {
764 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
769 if (bss->caps & IEEE80211_CAP_IBSS) {
770 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
775 if (!freq_allowed(ssid->freq_list, bss->freq)) {
776 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
781 if (!rate_match(wpa_s, bss)) {
782 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
789 * TODO: skip the AP if its P2P IE has Group Formation
790 * bit set in the P2P Group Capability Bitmap and we
791 * are not in Group Formation with that device.
793 #endif /* CONFIG_P2P */
795 /* Matching configuration found */
799 /* No matching configuration found */
804 static struct wpa_bss *
805 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
806 struct wpa_ssid *group,
807 struct wpa_ssid **selected_ssid)
811 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
814 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
815 struct wpa_bss *bss = wpa_s->last_scan_res[i];
816 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
819 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
822 wpa_ssid_txt(bss->ssid, bss->ssid_len));
830 static struct wpa_bss *
831 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
832 struct wpa_ssid **selected_ssid)
834 struct wpa_bss *selected = NULL;
837 if (wpa_s->last_scan_res == NULL ||
838 wpa_s->last_scan_res_used == 0)
839 return NULL; /* no scan results from last update */
841 while (selected == NULL) {
842 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
843 selected = wpa_supplicant_select_bss(
844 wpa_s, wpa_s->conf->pssid[prio],
850 if (selected == NULL && wpa_s->blacklist &&
851 !wpa_s->countermeasures) {
852 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
853 "blacklist and try again");
854 wpa_blacklist_clear(wpa_s);
855 wpa_s->blacklist_cleared++;
856 } else if (selected == NULL)
864 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
865 int timeout_sec, int timeout_usec)
867 if (!wpa_supplicant_enabled_networks(wpa_s)) {
869 * No networks are enabled; short-circuit request so
870 * we don't wait timeout seconds before transitioning
873 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
874 "since there are no enabled networks");
875 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
877 wpa_s->sta_scan_pending = 0;
878 #endif /* CONFIG_P2P */
882 wpa_s->scan_for_connection = 1;
883 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
887 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
888 struct wpa_bss *selected,
889 struct wpa_ssid *ssid)
891 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
892 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
893 "PBC session overlap");
895 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
897 #endif /* CONFIG_P2P */
900 wpas_wps_cancel(wpa_s);
901 #endif /* CONFIG_WPS */
906 * Do not trigger new association unless the BSSID has changed or if
907 * reassociation is requested. If we are in process of associating with
908 * the selected BSSID, do not trigger new attempt.
910 if (wpa_s->reassociate ||
911 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
912 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
913 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
914 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
916 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
917 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
920 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
921 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
922 " pending: " MACSTR " wpa_state: %s",
923 wpa_s->reassociate, MAC2STR(selected->bssid),
924 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
925 wpa_supplicant_state_txt(wpa_s->wpa_state));
926 wpa_supplicant_associate(wpa_s, selected, ssid);
928 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
936 static struct wpa_ssid *
937 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
940 struct wpa_ssid *ssid;
942 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
943 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
945 if (wpas_network_disabled(wpa_s, ssid))
947 if (ssid->mode == IEEE80211_MODE_IBSS ||
948 ssid->mode == IEEE80211_MODE_AP)
956 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
957 * on BSS added and BSS changed events */
958 static void wpa_supplicant_rsn_preauth_scan_results(
959 struct wpa_supplicant *wpa_s)
963 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
966 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
967 const u8 *ssid, *rsn;
969 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
973 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
977 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
983 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
984 struct wpa_bss *selected,
985 struct wpa_ssid *ssid)
987 struct wpa_bss *current_bss = NULL;
990 if (wpa_s->reassociate)
991 return 1; /* explicit request to reassociate */
992 if (wpa_s->wpa_state < WPA_ASSOCIATED)
993 return 1; /* we are not associated; continue */
994 if (wpa_s->current_ssid == NULL)
995 return 1; /* unknown current SSID */
996 if (wpa_s->current_ssid != ssid)
997 return 1; /* different network block */
999 if (wpas_driver_bss_selection(wpa_s))
1000 return 0; /* Driver-based roaming */
1002 if (wpa_s->current_ssid->ssid)
1003 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1004 wpa_s->current_ssid->ssid,
1005 wpa_s->current_ssid->ssid_len);
1007 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
1010 return 1; /* current BSS not seen in scan results */
1012 if (current_bss == selected)
1015 if (selected->last_update_idx > current_bss->last_update_idx)
1016 return 1; /* current BSS not seen in the last scan */
1018 #ifndef CONFIG_NO_ROAMING
1019 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1020 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1021 MAC2STR(current_bss->bssid), current_bss->level);
1022 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1023 MAC2STR(selected->bssid), selected->level);
1025 if (wpa_s->current_ssid->bssid_set &&
1026 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1028 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1029 "has preferred BSSID");
1033 if (current_bss->level < 0 && current_bss->level > selected->level) {
1034 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1040 if (current_bss->level < 0) {
1041 if (current_bss->level < -85)
1043 else if (current_bss->level < -80)
1045 else if (current_bss->level < -75)
1047 else if (current_bss->level < -70)
1052 if (abs(current_bss->level - selected->level) < min_diff) {
1053 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1059 #else /* CONFIG_NO_ROAMING */
1061 #endif /* CONFIG_NO_ROAMING */
1065 /* Return != 0 if no scan results could be fetched or if scan results should not
1066 * be shared with other virtual interfaces. */
1067 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1068 union wpa_event_data *data)
1070 struct wpa_scan_results *scan_res;
1072 #ifndef CONFIG_NO_RANDOM_POOL
1074 #endif /* CONFIG_NO_RANDOM_POOL */
1077 if (wpa_s->ap_iface)
1079 #endif /* CONFIG_AP */
1081 wpa_supplicant_notify_scanning(wpa_s, 0);
1084 if (wpa_s->global->p2p_cb_on_scan_complete &&
1085 !wpa_s->global->p2p_disabled &&
1086 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1087 !wpa_s->scan_res_handler) {
1088 wpa_s->global->p2p_cb_on_scan_complete = 0;
1089 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1090 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1091 "stopped scan processing");
1092 wpa_s->sta_scan_pending = 1;
1093 wpa_supplicant_req_scan(wpa_s, 5, 0);
1097 wpa_s->sta_scan_pending = 0;
1098 #endif /* CONFIG_P2P */
1100 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1101 data ? &data->scan_info :
1103 if (scan_res == NULL) {
1104 if (wpa_s->conf->ap_scan == 2 || ap)
1106 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1108 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1112 #ifndef CONFIG_NO_RANDOM_POOL
1113 num = scan_res->num;
1116 for (i = 0; i < num; i++) {
1118 struct wpa_scan_res *res = scan_res->res[i];
1119 buf[0] = res->bssid[5];
1120 buf[1] = res->qual & 0xff;
1121 buf[2] = res->noise & 0xff;
1122 buf[3] = res->level & 0xff;
1123 buf[4] = res->tsf & 0xff;
1124 random_add_randomness(buf, sizeof(buf));
1126 #endif /* CONFIG_NO_RANDOM_POOL */
1128 if (wpa_s->scan_res_handler) {
1129 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1130 struct wpa_scan_results *scan_res);
1132 scan_res_handler = wpa_s->scan_res_handler;
1133 wpa_s->scan_res_handler = NULL;
1134 scan_res_handler(wpa_s, scan_res);
1136 wpa_scan_results_free(scan_res);
1141 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1143 if (wpa_s->ap_iface->scan_cb)
1144 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1145 #endif /* CONFIG_AP */
1146 wpa_scan_results_free(scan_res);
1150 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1151 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1152 wpas_notify_scan_results(wpa_s);
1154 wpas_notify_scan_done(wpa_s, 1);
1156 if (sme_proc_obss_scan(wpa_s) > 0) {
1157 wpa_scan_results_free(scan_res);
1161 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1162 wpa_scan_results_free(scan_res);
1166 if (autoscan_notify_scan(wpa_s, scan_res)) {
1167 wpa_scan_results_free(scan_res);
1171 if (wpa_s->disconnected) {
1172 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1173 wpa_scan_results_free(scan_res);
1177 if (!wpas_driver_bss_selection(wpa_s) &&
1178 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1179 wpa_scan_results_free(scan_res);
1183 wpas_wps_update_ap_info(wpa_s, scan_res);
1185 wpa_scan_results_free(scan_res);
1187 return wpas_select_network_from_last_scan(wpa_s);
1191 int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s)
1193 struct wpa_bss *selected;
1194 struct wpa_ssid *ssid = NULL;
1196 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
1200 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
1202 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1206 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1207 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1210 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1212 * Do not notify other virtual radios of scan results since we do not
1213 * want them to start other associations at the same time.
1217 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1218 ssid = wpa_supplicant_pick_new_network(wpa_s);
1220 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1221 wpa_supplicant_associate(wpa_s, NULL, ssid);
1222 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1224 int timeout_sec = wpa_s->scan_interval;
1225 int timeout_usec = 0;
1227 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1230 if (wpa_s->p2p_in_provisioning) {
1232 * Use shorter wait during P2P Provisioning
1233 * state to speed up group formation.
1236 timeout_usec = 250000;
1237 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1241 #endif /* CONFIG_P2P */
1242 #ifdef CONFIG_INTERWORKING
1243 if (wpa_s->conf->auto_interworking &&
1244 wpa_s->conf->interworking &&
1245 wpa_s->conf->cred) {
1246 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1247 "start ANQP fetch since no matching "
1249 wpa_s->network_select = 1;
1250 wpa_s->auto_network_select = 1;
1251 interworking_start_fetch_anqp(wpa_s);
1254 #endif /* CONFIG_INTERWORKING */
1255 if (wpa_supplicant_req_sched_scan(wpa_s))
1256 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1264 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1265 union wpa_event_data *data)
1267 const char *rn, *rn2;
1268 struct wpa_supplicant *ifs;
1270 if (_wpa_supplicant_event_scan_results(wpa_s, data) != 0) {
1272 * If no scan results could be fetched, then no need to
1273 * notify those interfaces that did not actually request
1274 * this scan. Similarly, if scan results started a new operation on this
1275 * interface, do not notify other interfaces to avoid concurrent
1276 * operations during a connection attempt.
1282 * Check other interfaces to see if they have the same radio-name. If
1283 * so, they get updated with this same scan info.
1285 if (!wpa_s->driver->get_radio_name)
1288 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1289 if (rn == NULL || rn[0] == '\0')
1292 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1293 "sharing same radio (%s) in event_scan_results", rn);
1295 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1296 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1299 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1300 if (rn2 && os_strcmp(rn, rn2) == 0) {
1301 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1302 "sibling", ifs->ifname);
1303 _wpa_supplicant_event_scan_results(ifs, data);
1308 #endif /* CONFIG_NO_SCAN_PROCESSING */
1311 int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1313 #ifdef CONFIG_NO_SCAN_PROCESSING
1315 #else /* CONFIG_NO_SCAN_PROCESSING */
1318 if (wpa_s->last_scan_res_used <= 0)
1322 if (now.sec - wpa_s->last_scan.sec > 5) {
1323 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1327 return wpas_select_network_from_last_scan(wpa_s);
1328 #endif /* CONFIG_NO_SCAN_PROCESSING */
1333 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1335 struct wpa_supplicant *wpa_s = eloop_ctx;
1337 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1340 if (!wpa_s->no_keep_alive) {
1341 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1342 MAC2STR(wpa_s->bssid));
1343 /* TODO: could skip this if normal data traffic has been sent */
1344 /* TODO: Consider using some more appropriate data frame for
1347 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1352 if (wpa_s->sme.bss_max_idle_period) {
1354 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1357 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1358 wnm_bss_keep_alive, wpa_s, NULL);
1360 #endif /* CONFIG_SME */
1364 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1365 const u8 *ies, size_t ies_len)
1367 struct ieee802_11_elems elems;
1372 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1376 if (elems.bss_max_idle_period) {
1378 wpa_s->sme.bss_max_idle_period =
1379 WPA_GET_LE16(elems.bss_max_idle_period);
1380 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1381 "TU)%s", wpa_s->sme.bss_max_idle_period,
1382 (elems.bss_max_idle_period[2] & 0x01) ?
1383 " (protected keep-live required)" : "");
1384 if (wpa_s->sme.bss_max_idle_period == 0)
1385 wpa_s->sme.bss_max_idle_period = 1;
1386 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1387 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1388 /* msec times 1000 */
1389 msec = wpa_s->sme.bss_max_idle_period * 1024;
1392 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1393 wnm_bss_keep_alive, wpa_s,
1397 #endif /* CONFIG_SME */
1400 #endif /* CONFIG_WNM */
1403 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1406 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1407 #endif /* CONFIG_WNM */
1411 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1412 union wpa_event_data *data)
1414 int l, len, found = 0, wpa_found, rsn_found;
1417 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1418 if (data->assoc_info.req_ies)
1419 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1420 data->assoc_info.req_ies_len);
1421 if (data->assoc_info.resp_ies) {
1422 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1423 data->assoc_info.resp_ies_len);
1425 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1426 data->assoc_info.resp_ies_len);
1427 #endif /* CONFIG_TDLS */
1429 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1430 data->assoc_info.resp_ies_len);
1431 #endif /* CONFIG_WNM */
1433 if (data->assoc_info.beacon_ies)
1434 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1435 data->assoc_info.beacon_ies,
1436 data->assoc_info.beacon_ies_len);
1437 if (data->assoc_info.freq)
1438 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1439 data->assoc_info.freq);
1441 p = data->assoc_info.req_ies;
1442 l = data->assoc_info.req_ies_len;
1444 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1445 while (p && l >= 2) {
1448 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1452 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1453 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1454 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1455 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1458 wpa_find_assoc_pmkid(wpa_s);
1464 if (!found && data->assoc_info.req_ies)
1465 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1467 #ifdef CONFIG_IEEE80211R
1469 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1471 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1472 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1473 data->assoc_info.resp_ies,
1474 data->assoc_info.resp_ies_len,
1476 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1477 "Reassociation Response failed");
1478 wpa_supplicant_deauthenticate(
1479 wpa_s, WLAN_REASON_INVALID_IE);
1484 p = data->assoc_info.resp_ies;
1485 l = data->assoc_info.resp_ies_len;
1487 #ifdef CONFIG_WPS_STRICT
1488 if (p && wpa_s->current_ssid &&
1489 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1491 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1493 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1494 "include WPS IE in (Re)Association Response");
1498 if (wps_validate_assoc_resp(wps) < 0) {
1500 wpa_supplicant_deauthenticate(
1501 wpa_s, WLAN_REASON_INVALID_IE);
1506 #endif /* CONFIG_WPS_STRICT */
1508 /* Go through the IEs and make a copy of the MDIE, if present. */
1509 while (p && l >= 2) {
1512 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1516 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1517 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1518 wpa_s->sme.ft_used = 1;
1519 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1520 MOBILITY_DOMAIN_ID_LEN);
1526 #endif /* CONFIG_SME */
1528 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1529 data->assoc_info.resp_ies_len);
1530 #endif /* CONFIG_IEEE80211R */
1532 /* WPA/RSN IE from Beacon/ProbeResp */
1533 p = data->assoc_info.beacon_ies;
1534 l = data->assoc_info.beacon_ies_len;
1536 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1538 wpa_found = rsn_found = 0;
1539 while (p && l >= 2) {
1542 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1547 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1548 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1550 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1554 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1556 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1563 if (!wpa_found && data->assoc_info.beacon_ies)
1564 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1565 if (!rsn_found && data->assoc_info.beacon_ies)
1566 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1567 if (wpa_found || rsn_found)
1568 wpa_s->ap_ies_from_associnfo = 1;
1570 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1571 wpa_s->assoc_freq != data->assoc_info.freq) {
1572 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1574 wpa_s->assoc_freq, data->assoc_info.freq);
1575 wpa_supplicant_update_scan_results(wpa_s);
1578 wpa_s->assoc_freq = data->assoc_info.freq;
1584 static struct wpa_bss * wpa_supplicant_get_new_bss(
1585 struct wpa_supplicant *wpa_s, const u8 *bssid)
1587 struct wpa_bss *bss = NULL;
1588 struct wpa_ssid *ssid = wpa_s->current_ssid;
1590 if (ssid->ssid_len > 0)
1591 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1593 bss = wpa_bss_get_bssid(wpa_s, bssid);
1599 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1601 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1603 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1606 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1609 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1610 WPA_IE_VENDOR_TYPE);
1611 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1613 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1614 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1615 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1616 bss_rsn ? 2 + bss_rsn[1] : 0))
1623 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1624 union wpa_event_data *data)
1628 struct wpa_driver_capa capa;
1631 if (wpa_s->ap_iface) {
1632 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1633 data->assoc_info.addr,
1634 data->assoc_info.req_ies,
1635 data->assoc_info.req_ies_len,
1636 data->assoc_info.reassoc);
1639 #endif /* CONFIG_AP */
1641 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1642 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1645 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1646 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1647 wpa_supplicant_deauthenticate(
1648 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1652 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1653 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1654 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1655 MACSTR, MAC2STR(bssid));
1656 random_add_randomness(bssid, ETH_ALEN);
1657 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1658 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1659 wpas_notify_bssid_changed(wpa_s);
1661 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1662 wpa_clear_keys(wpa_s, bssid);
1664 if (wpa_supplicant_select_config(wpa_s) < 0) {
1665 wpa_supplicant_deauthenticate(
1666 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1669 if (wpa_s->current_ssid) {
1670 struct wpa_bss *bss = NULL;
1672 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1674 wpa_supplicant_update_scan_results(wpa_s);
1676 /* Get the BSS from the new scan results */
1677 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1681 wpa_s->current_bss = bss;
1684 if (wpa_s->conf->ap_scan == 1 &&
1685 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1686 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1687 wpa_msg(wpa_s, MSG_WARNING,
1688 "WPA/RSN IEs not updated");
1693 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1694 wpa_s->sme.prev_bssid_set = 1;
1695 #endif /* CONFIG_SME */
1697 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1698 if (wpa_s->current_ssid) {
1699 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1700 * initialized before association, but for other modes,
1701 * initialize PC/SC here, if the current configuration needs
1702 * smartcard or SIM/USIM. */
1703 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1705 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1707 l2_packet_notify_auth_start(wpa_s->l2);
1710 * Set portEnabled first to FALSE in order to get EAP state machine out
1711 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1712 * state machine may transit to AUTHENTICATING state based on obsolete
1713 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1714 * AUTHENTICATED without ever giving chance to EAP state machine to
1717 if (!ft_completed) {
1718 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1719 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1721 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1722 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1723 /* 802.1X::portControl = Auto */
1724 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1725 wpa_s->eapol_received = 0;
1726 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1727 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1728 (wpa_s->current_ssid &&
1729 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1730 wpa_supplicant_cancel_auth_timeout(wpa_s);
1731 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1732 } else if (!ft_completed) {
1733 /* Timeout for receiving the first EAPOL packet */
1734 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1736 wpa_supplicant_cancel_scan(wpa_s);
1738 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1739 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1741 * We are done; the driver will take care of RSN 4-way
1744 wpa_supplicant_cancel_auth_timeout(wpa_s);
1745 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1746 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1747 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1748 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1749 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1751 * The driver will take care of RSN 4-way handshake, so we need
1752 * to allow EAPOL supplicant to complete its work without
1753 * waiting for WPA supplicant.
1755 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1756 } else if (ft_completed) {
1758 * FT protocol completed - make sure EAPOL state machine ends
1759 * up in authenticated.
1761 wpa_supplicant_cancel_auth_timeout(wpa_s);
1762 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1763 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1764 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1767 wpa_s->last_eapol_matches_bssid = 0;
1769 if (wpa_s->pending_eapol_rx) {
1770 struct os_time now, age;
1772 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1773 if (age.sec == 0 && age.usec < 100000 &&
1774 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1776 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1777 "frame that was received just before "
1778 "association notification");
1779 wpa_supplicant_rx_eapol(
1780 wpa_s, wpa_s->pending_eapol_rx_src,
1781 wpabuf_head(wpa_s->pending_eapol_rx),
1782 wpabuf_len(wpa_s->pending_eapol_rx));
1784 wpabuf_free(wpa_s->pending_eapol_rx);
1785 wpa_s->pending_eapol_rx = NULL;
1788 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1789 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1790 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1791 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1792 /* Set static WEP keys again */
1793 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1796 #ifdef CONFIG_IBSS_RSN
1797 if (wpa_s->current_ssid &&
1798 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1799 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1800 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1801 wpa_s->ibss_rsn == NULL) {
1802 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1803 if (!wpa_s->ibss_rsn) {
1804 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1805 wpa_supplicant_deauthenticate(
1806 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1810 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1812 #endif /* CONFIG_IBSS_RSN */
1814 wpas_wps_notify_assoc(wpa_s, bssid);
1818 static int disconnect_reason_recoverable(u16 reason_code)
1820 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1821 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1822 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1826 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1828 int locally_generated)
1832 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1834 * At least Host AP driver and a Prism3 card seemed to be
1835 * generating streams of disconnected events when configuring
1836 * IBSS for WPA-None. Ignore them for now.
1841 bssid = wpa_s->bssid;
1842 if (is_zero_ether_addr(bssid))
1843 bssid = wpa_s->pending_bssid;
1845 if (!is_zero_ether_addr(bssid) ||
1846 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1847 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1849 MAC2STR(bssid), reason_code,
1850 locally_generated ? " locally_generated=1" : "");
1855 static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1856 int locally_generated)
1858 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1859 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1860 return 0; /* Not in 4-way handshake with PSK */
1863 * It looks like connection was lost while trying to go through PSK
1864 * 4-way handshake. Filter out known disconnection cases that are caused
1865 * by something else than PSK mismatch to avoid confusing reports.
1868 if (locally_generated) {
1869 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1877 static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1879 int locally_generated)
1883 u8 prev_pending_bssid[ETH_ALEN];
1884 struct wpa_bss *fast_reconnect = NULL;
1885 struct wpa_ssid *fast_reconnect_ssid = NULL;
1886 struct wpa_ssid *last_ssid;
1888 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1889 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1891 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1893 * At least Host AP driver and a Prism3 card seemed to be
1894 * generating streams of disconnected events when configuring
1895 * IBSS for WPA-None. Ignore them for now.
1897 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1898 "IBSS/WPA-None mode");
1902 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
1903 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1904 "pre-shared key may be incorrect");
1905 wpas_auth_failed(wpa_s);
1907 if (!wpa_s->auto_reconnect_disabled ||
1908 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1909 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1910 "reconnect (wps=%d wpa_state=%d)",
1911 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1913 if (wpa_s->wpa_state == WPA_COMPLETED &&
1914 wpa_s->current_ssid &&
1915 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1916 !locally_generated &&
1917 disconnect_reason_recoverable(reason_code)) {
1919 * It looks like the AP has dropped association with
1920 * us, but could allow us to get back in. Try to
1921 * reconnect to the same BSS without full scan to save
1922 * time for some common cases.
1924 fast_reconnect = wpa_s->current_bss;
1925 fast_reconnect_ssid = wpa_s->current_ssid;
1926 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1927 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1929 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1932 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1933 "try to re-connect");
1934 wpa_s->reassociate = 0;
1935 wpa_s->disconnected = 1;
1936 wpa_supplicant_cancel_sched_scan(wpa_s);
1938 bssid = wpa_s->bssid;
1939 if (is_zero_ether_addr(bssid))
1940 bssid = wpa_s->pending_bssid;
1941 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1942 wpas_connection_failed(wpa_s, bssid);
1943 wpa_sm_notify_disassoc(wpa_s->wpa);
1944 if (locally_generated)
1945 wpa_s->disconnect_reason = -reason_code;
1947 wpa_s->disconnect_reason = reason_code;
1948 wpas_notify_disconnect_reason(wpa_s);
1949 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1950 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1951 wpa_s->keys_cleared = 0;
1952 wpa_clear_keys(wpa_s, wpa_s->bssid);
1954 last_ssid = wpa_s->current_ssid;
1955 wpa_supplicant_mark_disassoc(wpa_s);
1957 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
1958 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1959 wpa_s->current_ssid = last_ssid;
1962 if (fast_reconnect) {
1963 #ifndef CONFIG_NO_SCAN_PROCESSING
1964 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1965 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1966 fast_reconnect_ssid) < 0) {
1967 /* Recover through full scan */
1968 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1970 #endif /* CONFIG_NO_SCAN_PROCESSING */
1975 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1976 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
1978 struct wpa_supplicant *wpa_s = eloop_ctx;
1980 if (!wpa_s->pending_mic_error_report)
1983 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1984 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1985 wpa_s->pending_mic_error_report = 0;
1987 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1991 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1992 union wpa_event_data *data)
1997 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1998 pairwise = (data && data->michael_mic_failure.unicast);
2000 if ((wpa_s->last_michael_mic_error &&
2001 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2002 wpa_s->pending_mic_error_report) {
2003 if (wpa_s->pending_mic_error_report) {
2005 * Send the pending MIC error report immediately since
2006 * we are going to start countermeasures and AP better
2009 wpa_sm_key_request(wpa_s->wpa, 1,
2010 wpa_s->pending_mic_error_pairwise);
2013 /* Send the new MIC error report immediately since we are going
2014 * to start countermeasures and AP better do the same.
2016 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2018 /* initialize countermeasures */
2019 wpa_s->countermeasures = 1;
2021 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2023 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2026 * Need to wait for completion of request frame. We do not get
2027 * any callback for the message completion, so just wait a
2028 * short while and hope for the best. */
2031 wpa_drv_set_countermeasures(wpa_s, 1);
2032 wpa_supplicant_deauthenticate(wpa_s,
2033 WLAN_REASON_MICHAEL_MIC_FAILURE);
2034 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2036 eloop_register_timeout(60, 0,
2037 wpa_supplicant_stop_countermeasures,
2039 /* TODO: mark the AP rejected for 60 second. STA is
2040 * allowed to associate with another AP.. */
2042 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2043 if (wpa_s->mic_errors_seen) {
2045 * Reduce the effectiveness of Michael MIC error
2046 * reports as a means for attacking against TKIP if
2047 * more than one MIC failure is noticed with the same
2048 * PTK. We delay the transmission of the reports by a
2049 * random time between 0 and 60 seconds in order to
2050 * force the attacker wait 60 seconds before getting
2051 * the information on whether a frame resulted in a MIC
2057 if (os_get_random(rval, sizeof(rval)) < 0)
2058 sec = os_random() % 60;
2060 sec = WPA_GET_BE32(rval) % 60;
2061 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2062 "report %d seconds", sec);
2063 wpa_s->pending_mic_error_report = 1;
2064 wpa_s->pending_mic_error_pairwise = pairwise;
2065 eloop_cancel_timeout(
2066 wpa_supplicant_delayed_mic_error_report,
2068 eloop_register_timeout(
2069 sec, os_random() % 1000000,
2070 wpa_supplicant_delayed_mic_error_report,
2073 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2075 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2076 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2077 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2079 wpa_s->last_michael_mic_error = t.sec;
2080 wpa_s->mic_errors_seen++;
2084 #ifdef CONFIG_TERMINATE_ONLASTIF
2085 static int any_interfaces(struct wpa_supplicant *head)
2087 struct wpa_supplicant *wpa_s;
2089 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2090 if (!wpa_s->interface_removed)
2094 #endif /* CONFIG_TERMINATE_ONLASTIF */
2098 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2099 union wpa_event_data *data)
2101 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2104 switch (data->interface_status.ievent) {
2105 case EVENT_INTERFACE_ADDED:
2106 if (!wpa_s->interface_removed)
2108 wpa_s->interface_removed = 0;
2109 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2110 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2111 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2112 "driver after interface was added");
2114 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2116 case EVENT_INTERFACE_REMOVED:
2117 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2118 wpa_s->interface_removed = 1;
2119 wpa_supplicant_mark_disassoc(wpa_s);
2120 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2121 l2_packet_deinit(wpa_s->l2);
2123 #ifdef CONFIG_IBSS_RSN
2124 ibss_rsn_deinit(wpa_s->ibss_rsn);
2125 wpa_s->ibss_rsn = NULL;
2126 #endif /* CONFIG_IBSS_RSN */
2127 #ifdef CONFIG_TERMINATE_ONLASTIF
2128 /* check if last interface */
2129 if (!any_interfaces(wpa_s->global->ifaces))
2131 #endif /* CONFIG_TERMINATE_ONLASTIF */
2137 #ifdef CONFIG_PEERKEY
2139 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2140 union wpa_event_data *data)
2144 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2146 #endif /* CONFIG_PEERKEY */
2150 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2151 union wpa_event_data *data)
2155 switch (data->tdls.oper) {
2156 case TDLS_REQUEST_SETUP:
2157 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2159 case TDLS_REQUEST_TEARDOWN:
2160 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2161 data->tdls.reason_code);
2165 #endif /* CONFIG_TDLS */
2169 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2170 union wpa_event_data *data)
2174 switch (data->wnm.oper) {
2175 case WNM_OPER_SLEEP:
2176 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2177 "(action=%d, intval=%d)",
2178 data->wnm.sleep_action, data->wnm.sleep_intval);
2179 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2180 data->wnm.sleep_intval, NULL);
2184 #endif /* CONFIG_WNM */
2187 #ifdef CONFIG_IEEE80211R
2189 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2190 union wpa_event_data *data)
2195 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2196 data->ft_ies.ies_len,
2197 data->ft_ies.ft_action,
2198 data->ft_ies.target_ap,
2199 data->ft_ies.ric_ies,
2200 data->ft_ies.ric_ies_len) < 0) {
2201 /* TODO: prevent MLME/driver from trying to associate? */
2204 #endif /* CONFIG_IEEE80211R */
2207 #ifdef CONFIG_IBSS_RSN
2208 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2209 union wpa_event_data *data)
2211 struct wpa_ssid *ssid;
2212 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2216 ssid = wpa_s->current_ssid;
2219 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2222 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2224 #endif /* CONFIG_IBSS_RSN */
2227 #ifdef CONFIG_IEEE80211R
2228 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2231 const u8 *sta_addr, *target_ap_addr;
2234 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2235 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2236 return; /* only SME case supported for now */
2237 if (len < 1 + 2 * ETH_ALEN + 2)
2240 return; /* Only FT Action Response is supported for now */
2241 sta_addr = data + 1;
2242 target_ap_addr = data + 1 + ETH_ALEN;
2243 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2244 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2245 MACSTR " TargetAP " MACSTR " status %u",
2246 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2248 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2249 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2250 " in FT Action Response", MAC2STR(sta_addr));
2255 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2256 "failure (status code %d)", status);
2257 /* TODO: report error to FT code(?) */
2261 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2262 len - (1 + 2 * ETH_ALEN + 2), 1,
2263 target_ap_addr, NULL, 0) < 0)
2268 struct wpa_bss *bss;
2269 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2271 wpa_s->sme.freq = bss->freq;
2272 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2273 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2276 #endif /* CONFIG_SME */
2278 #endif /* CONFIG_IEEE80211R */
2281 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2282 struct unprot_deauth *e)
2284 #ifdef CONFIG_IEEE80211W
2285 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2286 "dropped: " MACSTR " -> " MACSTR
2287 " (reason code %u)",
2288 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2289 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2290 #endif /* CONFIG_IEEE80211W */
2294 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2295 struct unprot_disassoc *e)
2297 #ifdef CONFIG_IEEE80211W
2298 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2299 "dropped: " MACSTR " -> " MACSTR
2300 " (reason code %u)",
2301 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2302 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2303 #endif /* CONFIG_IEEE80211W */
2307 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2308 union wpa_event_data *data)
2310 struct wpa_supplicant *wpa_s = ctx;
2311 u16 reason_code = 0;
2312 int locally_generated = 0;
2314 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2315 event != EVENT_INTERFACE_ENABLED &&
2316 event != EVENT_INTERFACE_STATUS &&
2317 event != EVENT_SCHED_SCAN_STOPPED) {
2318 wpa_dbg(wpa_s, MSG_DEBUG,
2319 "Ignore event %s (%d) while interface is disabled",
2320 event_to_string(event), event);
2324 #ifndef CONFIG_NO_STDOUT_DEBUG
2326 int level = MSG_DEBUG;
2328 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2329 const struct ieee80211_hdr *hdr;
2331 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2332 fc = le_to_host16(hdr->frame_control);
2333 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2334 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2335 level = MSG_EXCESSIVE;
2338 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2339 event_to_string(event), event);
2341 #endif /* CONFIG_NO_STDOUT_DEBUG */
2345 sme_event_auth(wpa_s, data);
2348 wpa_supplicant_event_assoc(wpa_s, data);
2350 case EVENT_DISASSOC:
2351 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2353 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2354 data->disassoc_info.reason_code,
2355 data->disassoc_info.locally_generated ?
2356 " (locally generated)" : "");
2357 if (data->disassoc_info.addr)
2358 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2359 MAC2STR(data->disassoc_info.addr));
2362 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2363 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2364 data->disassoc_info.addr);
2367 if (wpa_s->ap_iface) {
2368 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2372 #endif /* CONFIG_AP */
2374 reason_code = data->disassoc_info.reason_code;
2376 data->disassoc_info.locally_generated;
2377 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2378 data->disassoc_info.ie,
2379 data->disassoc_info.ie_len);
2381 wpas_p2p_disassoc_notif(
2382 wpa_s, data->disassoc_info.addr, reason_code,
2383 data->disassoc_info.ie,
2384 data->disassoc_info.ie_len,
2386 #endif /* CONFIG_P2P */
2388 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2389 sme_event_disassoc(wpa_s, data);
2392 if (event == EVENT_DEAUTH) {
2393 wpa_dbg(wpa_s, MSG_DEBUG,
2394 "Deauthentication notification");
2396 reason_code = data->deauth_info.reason_code;
2398 data->deauth_info.locally_generated;
2399 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2400 data->deauth_info.reason_code,
2401 data->deauth_info.locally_generated ?
2402 " (locally generated)" : "");
2403 if (data->deauth_info.addr) {
2404 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2406 MAC2STR(data->deauth_info.
2409 wpa_hexdump(MSG_DEBUG,
2410 "Deauthentication frame IE(s)",
2411 data->deauth_info.ie,
2412 data->deauth_info.ie_len);
2416 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2417 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2418 data->deauth_info.addr);
2421 if (wpa_s->ap_iface) {
2422 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2426 #endif /* CONFIG_AP */
2427 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2429 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2430 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2431 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2432 eapol_sm_failed(wpa_s->eapol)))
2433 wpas_auth_failed(wpa_s);
2435 if (event == EVENT_DEAUTH && data) {
2436 if (wpas_p2p_deauth_notif(wpa_s,
2437 data->deauth_info.addr,
2439 data->deauth_info.ie,
2440 data->deauth_info.ie_len,
2441 locally_generated) > 0) {
2443 * The interface was removed, so cannot
2444 * continue processing any additional
2445 * operations after this.
2450 #endif /* CONFIG_P2P */
2451 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2454 case EVENT_MICHAEL_MIC_FAILURE:
2455 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2457 #ifndef CONFIG_NO_SCAN_PROCESSING
2458 case EVENT_SCAN_RESULTS:
2459 wpa_supplicant_event_scan_results(wpa_s, data);
2461 if (wpa_s->global->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2462 wpa_s->global->p2p != NULL &&
2463 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2464 wpa_s->wpa_state != WPA_ASSOCIATING) {
2465 wpa_s->global->p2p_cb_on_scan_complete = 0;
2466 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2467 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2468 "continued after scan result processing");
2471 #endif /* CONFIG_P2P */
2473 #endif /* CONFIG_NO_SCAN_PROCESSING */
2474 case EVENT_ASSOCINFO:
2475 wpa_supplicant_event_associnfo(wpa_s, data);
2477 case EVENT_INTERFACE_STATUS:
2478 wpa_supplicant_event_interface_status(wpa_s, data);
2480 case EVENT_PMKID_CANDIDATE:
2481 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2483 #ifdef CONFIG_PEERKEY
2484 case EVENT_STKSTART:
2485 wpa_supplicant_event_stkstart(wpa_s, data);
2487 #endif /* CONFIG_PEERKEY */
2490 wpa_supplicant_event_tdls(wpa_s, data);
2492 #endif /* CONFIG_TDLS */
2495 wpa_supplicant_event_wnm(wpa_s, data);
2497 #endif /* CONFIG_WNM */
2498 #ifdef CONFIG_IEEE80211R
2499 case EVENT_FT_RESPONSE:
2500 wpa_supplicant_event_ft_response(wpa_s, data);
2502 #endif /* CONFIG_IEEE80211R */
2503 #ifdef CONFIG_IBSS_RSN
2504 case EVENT_IBSS_RSN_START:
2505 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2507 #endif /* CONFIG_IBSS_RSN */
2508 case EVENT_ASSOC_REJECT:
2509 if (data->assoc_reject.bssid)
2510 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2511 "bssid=" MACSTR " status_code=%u",
2512 MAC2STR(data->assoc_reject.bssid),
2513 data->assoc_reject.status_code);
2515 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2517 data->assoc_reject.status_code);
2518 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2519 sme_event_assoc_reject(wpa_s, data);
2521 const u8 *bssid = data->assoc_reject.bssid;
2522 if (bssid == NULL || is_zero_ether_addr(bssid))
2523 bssid = wpa_s->pending_bssid;
2524 wpas_connection_failed(wpa_s, bssid);
2525 wpa_supplicant_mark_disassoc(wpa_s);
2528 case EVENT_AUTH_TIMED_OUT:
2529 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2530 sme_event_auth_timed_out(wpa_s, data);
2532 case EVENT_ASSOC_TIMED_OUT:
2533 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2534 sme_event_assoc_timed_out(wpa_s, data);
2536 case EVENT_TX_STATUS:
2537 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2538 " type=%d stype=%d",
2539 MAC2STR(data->tx_status.dst),
2540 data->tx_status.type, data->tx_status.stype);
2542 if (wpa_s->ap_iface == NULL) {
2543 #ifdef CONFIG_OFFCHANNEL
2544 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2545 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
2546 offchannel_send_action_tx_status(
2547 wpa_s, data->tx_status.dst,
2548 data->tx_status.data,
2549 data->tx_status.data_len,
2550 data->tx_status.ack ?
2551 OFFCHANNEL_SEND_ACTION_SUCCESS :
2552 OFFCHANNEL_SEND_ACTION_NO_ACK);
2553 #endif /* CONFIG_OFFCHANNEL */
2556 #endif /* CONFIG_AP */
2557 #ifdef CONFIG_OFFCHANNEL
2558 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2559 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2561 * Catch TX status events for Action frames we sent via group
2562 * interface in GO mode.
2564 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2565 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2566 os_memcmp(wpa_s->parent->pending_action_dst,
2567 data->tx_status.dst, ETH_ALEN) == 0) {
2568 offchannel_send_action_tx_status(
2569 wpa_s->parent, data->tx_status.dst,
2570 data->tx_status.data,
2571 data->tx_status.data_len,
2572 data->tx_status.ack ?
2573 OFFCHANNEL_SEND_ACTION_SUCCESS :
2574 OFFCHANNEL_SEND_ACTION_NO_ACK);
2577 #endif /* CONFIG_OFFCHANNEL */
2579 switch (data->tx_status.type) {
2580 case WLAN_FC_TYPE_MGMT:
2581 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2582 data->tx_status.data_len,
2583 data->tx_status.stype,
2584 data->tx_status.ack);
2586 case WLAN_FC_TYPE_DATA:
2587 ap_tx_status(wpa_s, data->tx_status.dst,
2588 data->tx_status.data,
2589 data->tx_status.data_len,
2590 data->tx_status.ack);
2593 #endif /* CONFIG_AP */
2596 case EVENT_EAPOL_TX_STATUS:
2597 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2598 data->eapol_tx_status.data,
2599 data->eapol_tx_status.data_len,
2600 data->eapol_tx_status.ack);
2602 case EVENT_DRIVER_CLIENT_POLL_OK:
2603 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2605 case EVENT_RX_FROM_UNKNOWN:
2606 if (wpa_s->ap_iface == NULL)
2608 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2609 data->rx_from_unknown.wds);
2611 case EVENT_CH_SWITCH:
2614 if (!wpa_s->ap_iface) {
2615 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2616 "event in non-AP mode");
2621 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2622 data->ch_switch.ht_enabled,
2623 data->ch_switch.ch_offset);
2624 #endif /* CONFIG_AP */
2626 case EVENT_RX_MGMT: {
2628 const struct ieee80211_mgmt *mgmt;
2630 mgmt = (const struct ieee80211_mgmt *)
2631 data->rx_mgmt.frame;
2632 fc = le_to_host16(mgmt->frame_control);
2633 stype = WLAN_FC_GET_STYPE(fc);
2635 if (wpa_s->ap_iface == NULL) {
2637 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2638 data->rx_mgmt.frame_len > 24) {
2639 const u8 *src = mgmt->sa;
2640 const u8 *ie = mgmt->u.probe_req.variable;
2641 size_t ie_len = data->rx_mgmt.frame_len -
2642 (mgmt->u.probe_req.variable -
2643 data->rx_mgmt.frame);
2644 wpas_p2p_probe_req_rx(
2645 wpa_s, src, mgmt->da,
2646 mgmt->bssid, ie, ie_len,
2647 data->rx_mgmt.ssi_signal);
2650 #endif /* CONFIG_P2P */
2651 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2652 "management frame in non-AP mode");
2656 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2657 data->rx_mgmt.frame_len > 24) {
2658 const u8 *ie = mgmt->u.probe_req.variable;
2659 size_t ie_len = data->rx_mgmt.frame_len -
2660 (mgmt->u.probe_req.variable -
2661 data->rx_mgmt.frame);
2663 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2664 mgmt->bssid, ie, ie_len,
2665 data->rx_mgmt.ssi_signal);
2668 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2671 #endif /* CONFIG_AP */
2672 case EVENT_RX_ACTION:
2673 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2674 " Category=%u DataLen=%d freq=%d MHz",
2675 MAC2STR(data->rx_action.sa),
2676 data->rx_action.category, (int) data->rx_action.len,
2677 data->rx_action.freq);
2678 #ifdef CONFIG_IEEE80211R
2679 if (data->rx_action.category == WLAN_ACTION_FT) {
2680 ft_rx_action(wpa_s, data->rx_action.data,
2681 data->rx_action.len);
2684 #endif /* CONFIG_IEEE80211R */
2685 #ifdef CONFIG_IEEE80211W
2687 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2688 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2689 data->rx_action.data,
2690 data->rx_action.len);
2693 #endif /* CONFIG_SME */
2694 #endif /* CONFIG_IEEE80211W */
2696 if (data->rx_action.category == WLAN_ACTION_WNM) {
2697 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2700 #endif /* CONFIG_WNM */
2702 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2703 gas_query_rx(wpa_s->gas, data->rx_action.da,
2704 data->rx_action.sa, data->rx_action.bssid,
2705 data->rx_action.data, data->rx_action.len,
2706 data->rx_action.freq) == 0)
2708 #endif /* CONFIG_GAS */
2710 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2711 data->rx_action.len >= 4 &&
2712 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2713 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2714 "Response from " MACSTR,
2715 MAC2STR(data->rx_action.sa));
2718 #endif /* CONFIG_TDLS */
2720 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2722 data->rx_action.bssid,
2723 data->rx_action.category,
2724 data->rx_action.data,
2725 data->rx_action.len, data->rx_action.freq);
2726 #endif /* CONFIG_P2P */
2728 case EVENT_RX_PROBE_REQ:
2729 if (data->rx_probe_req.sa == NULL ||
2730 data->rx_probe_req.ie == NULL)
2733 if (wpa_s->ap_iface) {
2734 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2735 data->rx_probe_req.sa,
2736 data->rx_probe_req.da,
2737 data->rx_probe_req.bssid,
2738 data->rx_probe_req.ie,
2739 data->rx_probe_req.ie_len,
2740 data->rx_probe_req.ssi_signal);
2743 #endif /* CONFIG_AP */
2745 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2746 data->rx_probe_req.da,
2747 data->rx_probe_req.bssid,
2748 data->rx_probe_req.ie,
2749 data->rx_probe_req.ie_len,
2750 data->rx_probe_req.ssi_signal);
2751 #endif /* CONFIG_P2P */
2753 case EVENT_REMAIN_ON_CHANNEL:
2754 #ifdef CONFIG_OFFCHANNEL
2755 offchannel_remain_on_channel_cb(
2756 wpa_s, data->remain_on_channel.freq,
2757 data->remain_on_channel.duration);
2758 #endif /* CONFIG_OFFCHANNEL */
2760 wpas_p2p_remain_on_channel_cb(
2761 wpa_s, data->remain_on_channel.freq,
2762 data->remain_on_channel.duration);
2763 #endif /* CONFIG_P2P */
2765 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2766 #ifdef CONFIG_OFFCHANNEL
2767 offchannel_cancel_remain_on_channel_cb(
2768 wpa_s, data->remain_on_channel.freq);
2769 #endif /* CONFIG_OFFCHANNEL */
2771 wpas_p2p_cancel_remain_on_channel_cb(
2772 wpa_s, data->remain_on_channel.freq);
2773 #endif /* CONFIG_P2P */
2776 case EVENT_P2P_DEV_FOUND: {
2777 struct p2p_peer_info peer_info;
2779 os_memset(&peer_info, 0, sizeof(peer_info));
2780 if (data->p2p_dev_found.dev_addr)
2781 os_memcpy(peer_info.p2p_device_addr,
2782 data->p2p_dev_found.dev_addr, ETH_ALEN);
2783 if (data->p2p_dev_found.pri_dev_type)
2784 os_memcpy(peer_info.pri_dev_type,
2785 data->p2p_dev_found.pri_dev_type,
2786 sizeof(peer_info.pri_dev_type));
2787 if (data->p2p_dev_found.dev_name)
2788 os_strlcpy(peer_info.device_name,
2789 data->p2p_dev_found.dev_name,
2790 sizeof(peer_info.device_name));
2791 peer_info.config_methods = data->p2p_dev_found.config_methods;
2792 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2793 peer_info.group_capab = data->p2p_dev_found.group_capab;
2796 * FIX: new_device=1 is not necessarily correct. We should
2797 * maintain a P2P peer database in wpa_supplicant and update
2798 * this information based on whether the peer is truly new.
2800 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2803 case EVENT_P2P_GO_NEG_REQ_RX:
2804 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2805 data->p2p_go_neg_req_rx.dev_passwd_id);
2807 case EVENT_P2P_GO_NEG_COMPLETED:
2808 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2810 case EVENT_P2P_PROV_DISC_REQUEST:
2811 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2812 data->p2p_prov_disc_req.config_methods,
2813 data->p2p_prov_disc_req.dev_addr,
2814 data->p2p_prov_disc_req.pri_dev_type,
2815 data->p2p_prov_disc_req.dev_name,
2816 data->p2p_prov_disc_req.supp_config_methods,
2817 data->p2p_prov_disc_req.dev_capab,
2818 data->p2p_prov_disc_req.group_capab,
2821 case EVENT_P2P_PROV_DISC_RESPONSE:
2822 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2823 data->p2p_prov_disc_resp.config_methods);
2825 case EVENT_P2P_SD_REQUEST:
2826 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2827 data->p2p_sd_req.sa,
2828 data->p2p_sd_req.dialog_token,
2829 data->p2p_sd_req.update_indic,
2830 data->p2p_sd_req.tlvs,
2831 data->p2p_sd_req.tlvs_len);
2833 case EVENT_P2P_SD_RESPONSE:
2834 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2835 data->p2p_sd_resp.update_indic,
2836 data->p2p_sd_resp.tlvs,
2837 data->p2p_sd_resp.tlvs_len);
2839 #endif /* CONFIG_P2P */
2840 case EVENT_EAPOL_RX:
2841 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2842 data->eapol_rx.data,
2843 data->eapol_rx.data_len);
2845 case EVENT_SIGNAL_CHANGE:
2846 bgscan_notify_signal_change(
2847 wpa_s, data->signal_change.above_threshold,
2848 data->signal_change.current_signal,
2849 data->signal_change.current_noise,
2850 data->signal_change.current_txrate);
2852 case EVENT_INTERFACE_ENABLED:
2853 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2854 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2855 wpa_supplicant_update_mac_addr(wpa_s);
2857 if (!wpa_s->ap_iface) {
2858 wpa_supplicant_set_state(wpa_s,
2860 wpa_supplicant_req_scan(wpa_s, 0, 0);
2862 wpa_supplicant_set_state(wpa_s,
2864 #else /* CONFIG_AP */
2865 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2866 wpa_supplicant_req_scan(wpa_s, 0, 0);
2867 #endif /* CONFIG_AP */
2870 case EVENT_INTERFACE_DISABLED:
2871 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2872 wpa_supplicant_mark_disassoc(wpa_s);
2873 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2875 case EVENT_CHANNEL_LIST_CHANGED:
2876 if (wpa_s->drv_priv == NULL)
2877 break; /* Ignore event during drv initialization */
2879 free_hw_features(wpa_s);
2880 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2881 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2884 wpas_p2p_update_channel_list(wpa_s);
2885 #endif /* CONFIG_P2P */
2887 case EVENT_INTERFACE_UNAVAILABLE:
2889 wpas_p2p_interface_unavailable(wpa_s);
2890 #endif /* CONFIG_P2P */
2892 case EVENT_BEST_CHANNEL:
2893 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2895 data->best_chan.freq_24, data->best_chan.freq_5,
2896 data->best_chan.freq_overall);
2897 wpa_s->best_24_freq = data->best_chan.freq_24;
2898 wpa_s->best_5_freq = data->best_chan.freq_5;
2899 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2901 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2902 data->best_chan.freq_5,
2903 data->best_chan.freq_overall);
2904 #endif /* CONFIG_P2P */
2906 case EVENT_UNPROT_DEAUTH:
2907 wpa_supplicant_event_unprot_deauth(wpa_s,
2908 &data->unprot_deauth);
2910 case EVENT_UNPROT_DISASSOC:
2911 wpa_supplicant_event_unprot_disassoc(wpa_s,
2912 &data->unprot_disassoc);
2914 case EVENT_STATION_LOW_ACK:
2916 if (wpa_s->ap_iface && data)
2917 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2918 data->low_ack.addr);
2919 #endif /* CONFIG_AP */
2922 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2923 #endif /* CONFIG_TDLS */
2925 case EVENT_IBSS_PEER_LOST:
2926 #ifdef CONFIG_IBSS_RSN
2927 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2928 #endif /* CONFIG_IBSS_RSN */
2930 case EVENT_DRIVER_GTK_REKEY:
2931 if (os_memcmp(data->driver_gtk_rekey.bssid,
2932 wpa_s->bssid, ETH_ALEN))
2936 wpa_sm_update_replay_ctr(wpa_s->wpa,
2937 data->driver_gtk_rekey.replay_ctr);
2939 case EVENT_SCHED_SCAN_STOPPED:
2940 wpa_s->sched_scanning = 0;
2941 wpa_supplicant_notify_scanning(wpa_s, 0);
2943 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2947 * If we timed out, start a new sched scan to continue
2948 * searching for more SSIDs.
2950 if (wpa_s->sched_scan_timed_out)
2951 wpa_supplicant_req_sched_scan(wpa_s);
2953 case EVENT_WPS_BUTTON_PUSHED:
2955 wpas_wps_start_pbc(wpa_s, NULL, 0);
2956 #endif /* CONFIG_WPS */
2959 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);