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 res = wpas_temp_disabled(wpa_s, ssid);
89 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
90 "disabled for %d second(s)", res);
94 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
96 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
98 size_t wpa_ie_len = sizeof(wpa_ie);
99 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
100 wpa_ie, &wpa_ie_len);
102 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
105 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
106 eapol_sm_invalidate_cached_session(wpa_s->eapol);
107 old_ssid = wpa_s->current_ssid;
108 wpa_s->current_ssid = ssid;
109 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
110 wpa_supplicant_initiate_eapol(wpa_s);
111 if (old_ssid != wpa_s->current_ssid)
112 wpas_notify_network_changed(wpa_s);
118 void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
120 struct wpa_supplicant *wpa_s = eloop_ctx;
122 if (wpa_s->countermeasures) {
123 wpa_s->countermeasures = 0;
124 wpa_drv_set_countermeasures(wpa_s, 0);
125 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
126 wpa_supplicant_req_scan(wpa_s, 0, 0);
131 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
135 wnm_bss_keep_alive_deinit(wpa_s);
137 #ifdef CONFIG_IBSS_RSN
138 ibss_rsn_deinit(wpa_s->ibss_rsn);
139 wpa_s->ibss_rsn = NULL;
140 #endif /* CONFIG_IBSS_RSN */
143 wpa_supplicant_ap_deinit(wpa_s);
144 #endif /* CONFIG_AP */
146 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
149 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
151 wpa_s->conf->ap_scan = DEFAULT_AP_SCAN;
153 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
154 os_memset(wpa_s->bssid, 0, ETH_ALEN);
155 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
157 wpa_s->sme.prev_bssid_set = 0;
158 #endif /* CONFIG_SME */
160 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
161 #endif /* CONFIG_P2P */
162 wpa_s->current_bss = NULL;
163 wpa_s->assoc_freq = 0;
164 #ifdef CONFIG_IEEE80211R
166 if (wpa_s->sme.ft_ies)
167 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
168 #endif /* CONFIG_SME */
169 #endif /* CONFIG_IEEE80211R */
172 wpas_notify_bssid_changed(wpa_s);
174 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
175 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
176 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
177 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
178 wpa_s->ap_ies_from_associnfo = 0;
179 wpa_s->current_ssid = NULL;
184 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
186 struct wpa_ie_data ie;
190 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
194 for (i = 0; i < ie.num_pmkid; i++) {
195 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
196 ie.pmkid + i * PMKID_LEN,
198 if (pmksa_set == 0) {
199 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
204 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
205 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
209 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
210 union wpa_event_data *data)
213 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
217 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
218 " index=%d preauth=%d",
219 MAC2STR(data->pmkid_candidate.bssid),
220 data->pmkid_candidate.index,
221 data->pmkid_candidate.preauth);
223 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
224 data->pmkid_candidate.index,
225 data->pmkid_candidate.preauth);
229 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
231 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
232 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
235 #ifdef IEEE8021X_EAPOL
236 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
237 wpa_s->current_ssid &&
238 !(wpa_s->current_ssid->eapol_flags &
239 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
240 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
241 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
242 * plaintext or static WEP keys). */
245 #endif /* IEEE8021X_EAPOL */
252 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
253 * @wpa_s: pointer to wpa_supplicant data
254 * @ssid: Configuration data for the network
255 * Returns: 0 on success, -1 on failure
257 * This function is called when starting authentication with a network that is
258 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
260 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
261 struct wpa_ssid *ssid)
263 #ifdef IEEE8021X_EAPOL
265 int aka = 0, sim = 0, type;
267 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
270 if (ssid->eap.eap_methods == NULL) {
274 struct eap_method_type *eap = ssid->eap.eap_methods;
275 while (eap->vendor != EAP_VENDOR_IETF ||
276 eap->method != EAP_TYPE_NONE) {
277 if (eap->vendor == EAP_VENDOR_IETF) {
278 if (eap->method == EAP_TYPE_SIM)
280 else if (eap->method == EAP_TYPE_AKA ||
281 eap->method == EAP_TYPE_AKA_PRIME)
288 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
290 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
291 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
296 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
297 "use SIM, but neither EAP-SIM nor EAP-AKA are "
302 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
303 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
305 type = SCARD_TRY_BOTH;
307 type = SCARD_USIM_ONLY;
309 type = SCARD_GSM_SIM_ONLY;
311 wpa_s->scard = scard_init(type, NULL);
312 if (wpa_s->scard == NULL) {
313 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
317 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
318 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
319 #endif /* PCSC_FUNCS */
320 #endif /* IEEE8021X_EAPOL */
326 #ifndef CONFIG_NO_SCAN_PROCESSING
327 static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
328 struct wpa_ssid *ssid)
332 if (ssid->mixed_cell)
336 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
338 #endif /* CONFIG_WPS */
340 for (i = 0; i < NUM_WEP_KEYS; i++) {
341 if (ssid->wep_key_len[i]) {
346 #ifdef IEEE8021X_EAPOL
347 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
348 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
349 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
351 #endif /* IEEE8021X_EAPOL */
353 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
356 if (bss->caps & IEEE80211_CAP_PRIVACY)
362 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
363 struct wpa_ssid *ssid,
364 struct wpa_scan_res *bss)
366 struct wpa_ie_data ie;
368 const u8 *rsn_ie, *wpa_ie;
372 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
376 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
377 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
378 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
379 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
380 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
382 rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
383 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
386 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
387 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
393 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
395 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
400 if (!(ie.proto & ssid->proto)) {
401 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
406 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
407 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
412 if (!(ie.group_cipher & ssid->group_cipher)) {
413 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
418 if (!(ie.key_mgmt & ssid->key_mgmt)) {
419 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
424 #ifdef CONFIG_IEEE80211W
425 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
426 ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
427 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
431 #endif /* CONFIG_IEEE80211W */
433 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
437 wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
438 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
441 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
442 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
448 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
450 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
455 if (!(ie.proto & ssid->proto)) {
456 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
461 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
462 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
467 if (!(ie.group_cipher & ssid->group_cipher)) {
468 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
473 if (!(ie.key_mgmt & ssid->key_mgmt)) {
474 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
479 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
483 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
485 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
489 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
490 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
491 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
495 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
496 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
500 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
507 static int freq_allowed(int *freqs, int freq)
514 for (i = 0; freqs[i]; i++)
515 if (freqs[i] == freq)
521 static int ht_supported(const struct hostapd_hw_modes *mode)
523 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
525 * The driver did not indicate whether it supports HT. Assume
526 * it does to avoid connection issues.
532 * IEEE Std 802.11n-2009 20.1.1:
533 * An HT non-AP STA shall support all EQM rates for one spatial stream.
535 return mode->mcs_set[0] == 0xff;
539 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_scan_res *bss)
541 const struct hostapd_hw_modes *mode = NULL, *modes;
542 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
547 return 1; /* Cannot do matching without knowing band */
549 modes = wpa_s->hw.modes;
552 * The driver does not provide any additional information
553 * about the utilized hardware, so allow the connection attempt
559 for (i = 0; i < wpa_s->hw.num_modes; i++) {
560 for (j = 0; j < modes[i].num_channels; j++) {
561 int freq = modes[i].channels[j].freq;
562 if (freq == bss->freq) {
564 mode->mode == HOSTAPD_MODE_IEEE80211G)
565 break; /* do not allow 802.11b replace
576 for (i = 0; i < (int) sizeof(scan_ie); i++) {
577 rate_ie = wpa_scan_get_ie(bss, scan_ie[i]);
581 for (j = 2; j < rate_ie[1] + 2; j++) {
582 int flagged = !!(rate_ie[j] & 0x80);
583 int r = (rate_ie[j] & 0x7f) * 5;
586 * IEEE Std 802.11n-2009 7.3.2.2:
587 * The new BSS Membership selector value is encoded
588 * like a legacy basic rate, but it is not a rate and
589 * only indicates if the BSS members are required to
590 * support the mandatory features of Clause 20 [HT PHY]
591 * in order to join the BSS.
593 if (flagged && ((rate_ie[j] & 0x7f) ==
594 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
595 if (!ht_supported(mode)) {
596 wpa_dbg(wpa_s, MSG_DEBUG,
597 " hardware does not support "
607 /* check for legacy basic rates */
608 for (k = 0; k < mode->num_rates; k++) {
609 if (mode->rates[k] == r)
612 if (k == mode->num_rates) {
614 * IEEE Std 802.11-2007 7.3.2.2 demands that in
615 * order to join a BSS all required rates
616 * have to be supported by the hardware.
618 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
619 "not support required rate %d.%d Mbps",
630 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
631 int i, struct wpa_scan_res *bss,
632 struct wpa_ssid *group)
635 u8 wpa_ie_len, rsn_ie_len, ssid_len;
637 struct wpa_blacklist *e;
639 struct wpa_ssid *ssid;
641 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
642 ssid_ = ie ? ie + 2 : (u8 *) "";
643 ssid_len = ie ? ie[1] : 0;
645 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
646 wpa_ie_len = ie ? ie[1] : 0;
648 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
649 rsn_ie_len = ie ? ie[1] : 0;
651 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
652 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
653 i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
654 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
655 wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
657 e = wpa_blacklist_get(wpa_s, bss->bssid);
660 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
662 * When only a single network is enabled, we can
663 * trigger blacklisting on the first failure. This
664 * should not be done with multiple enabled networks to
665 * avoid getting forced to move into a worse ESS on
666 * single error if there are no other BSSes of the
671 if (e->count > limit) {
672 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
673 "(count=%d limit=%d)", e->count, limit);
679 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
683 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
685 for (ssid = group; ssid; ssid = ssid->pnext) {
686 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
689 if (wpas_network_disabled(wpa_s, ssid)) {
690 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
694 res = wpas_temp_disabled(wpa_s, ssid);
696 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
697 "temporarily for %d second(s)", res);
702 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
703 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
708 if (wpa && ssid->ssid_len == 0 &&
709 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
712 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
713 /* Only allow wildcard SSID match if an AP
714 * advertises active WPS operation that matches
717 if (ssid->ssid_len == 0 &&
718 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
721 #endif /* CONFIG_WPS */
723 if (ssid->bssid_set && ssid->ssid_len == 0 &&
724 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
728 (ssid_len != ssid->ssid_len ||
729 os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
730 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
734 if (ssid->bssid_set &&
735 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
736 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
740 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
744 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
745 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
746 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
747 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
752 if (!wpa_supplicant_match_privacy(bss, ssid)) {
753 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
758 if (bss->caps & IEEE80211_CAP_IBSS) {
759 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
764 if (!freq_allowed(ssid->freq_list, bss->freq)) {
765 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
770 if (!rate_match(wpa_s, bss)) {
771 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
778 * TODO: skip the AP if its P2P IE has Group Formation
779 * bit set in the P2P Group Capability Bitmap and we
780 * are not in Group Formation with that device.
782 #endif /* CONFIG_P2P */
784 /* Matching configuration found */
788 /* No matching configuration found */
793 static struct wpa_bss *
794 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
795 struct wpa_scan_results *scan_res,
796 struct wpa_ssid *group,
797 struct wpa_ssid **selected_ssid)
801 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
804 for (i = 0; i < scan_res->num; i++) {
805 struct wpa_scan_res *bss = scan_res->res[i];
809 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
813 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
814 ssid = ie ? ie + 2 : (u8 *) "";
815 ssid_len = ie ? ie[1] : 0;
817 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
819 MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
820 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
827 static struct wpa_bss *
828 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
829 struct wpa_scan_results *scan_res,
830 struct wpa_ssid **selected_ssid)
832 struct wpa_bss *selected = NULL;
835 while (selected == NULL) {
836 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
837 selected = wpa_supplicant_select_bss(
838 wpa_s, scan_res, wpa_s->conf->pssid[prio],
844 if (selected == NULL && wpa_s->blacklist &&
845 !wpa_s->countermeasures) {
846 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
847 "blacklist and try again");
848 wpa_blacklist_clear(wpa_s);
849 wpa_s->blacklist_cleared++;
850 } else if (selected == NULL)
858 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
859 int timeout_sec, int timeout_usec)
861 if (!wpa_supplicant_enabled_networks(wpa_s)) {
863 * No networks are enabled; short-circuit request so
864 * we don't wait timeout seconds before transitioning
867 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
870 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
874 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
875 struct wpa_bss *selected,
876 struct wpa_ssid *ssid)
878 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
879 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
880 "PBC session overlap");
882 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
884 #endif /* CONFIG_P2P */
887 wpas_wps_cancel(wpa_s);
888 #endif /* CONFIG_WPS */
893 * Do not trigger new association unless the BSSID has changed or if
894 * reassociation is requested. If we are in process of associating with
895 * the selected BSSID, do not trigger new attempt.
897 if (wpa_s->reassociate ||
898 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
899 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
900 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
901 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
903 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
904 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
907 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
908 "reassociate: %d selected: "MACSTR " bssid: " MACSTR
909 " pending: " MACSTR " wpa_state: %s",
910 wpa_s->reassociate, MAC2STR(selected->bssid),
911 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
912 wpa_supplicant_state_txt(wpa_s->wpa_state));
913 wpa_supplicant_associate(wpa_s, selected, ssid);
915 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
923 static struct wpa_ssid *
924 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
927 struct wpa_ssid *ssid;
929 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
930 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
932 if (wpas_network_disabled(wpa_s, ssid))
934 if (ssid->mode == IEEE80211_MODE_IBSS ||
935 ssid->mode == IEEE80211_MODE_AP)
943 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
944 * on BSS added and BSS changed events */
945 static void wpa_supplicant_rsn_preauth_scan_results(
946 struct wpa_supplicant *wpa_s)
950 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
953 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
954 const u8 *ssid, *rsn;
956 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
960 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
964 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
970 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
971 struct wpa_bss *selected,
972 struct wpa_ssid *ssid,
973 struct wpa_scan_results *scan_res)
976 struct wpa_scan_res *current_bss = NULL;
979 if (wpa_s->reassociate)
980 return 1; /* explicit request to reassociate */
981 if (wpa_s->wpa_state < WPA_ASSOCIATED)
982 return 1; /* we are not associated; continue */
983 if (wpa_s->current_ssid == NULL)
984 return 1; /* unknown current SSID */
985 if (wpa_s->current_ssid != ssid)
986 return 1; /* different network block */
988 if (wpas_driver_bss_selection(wpa_s))
989 return 0; /* Driver-based roaming */
991 for (i = 0; i < scan_res->num; i++) {
992 struct wpa_scan_res *res = scan_res->res[i];
994 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
997 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
1000 if (ie[1] != wpa_s->current_ssid->ssid_len ||
1001 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
1008 return 1; /* current BSS not seen in scan results */
1010 #ifndef CONFIG_NO_ROAMING
1011 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1012 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1013 MAC2STR(current_bss->bssid), current_bss->level);
1014 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1015 MAC2STR(selected->bssid), selected->level);
1017 if (wpa_s->current_ssid->bssid_set &&
1018 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1020 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1021 "has preferred BSSID");
1026 if (current_bss->level < 0) {
1027 if (current_bss->level < -85)
1029 else if (current_bss->level < -80)
1031 else if (current_bss->level < -75)
1033 else if (current_bss->level < -70)
1038 if (abs(current_bss->level - selected->level) < min_diff) {
1039 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1045 #else /* CONFIG_NO_ROAMING */
1047 #endif /* CONFIG_NO_ROAMING */
1051 /* Return < 0 if no scan results could be fetched or if scan results should not
1052 * be shared with other virtual interfaces. */
1054 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1055 union wpa_event_data *data, int suppress_event)
1057 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1058 union wpa_event_data *data)
1061 struct wpa_bss *selected;
1062 struct wpa_ssid *ssid = NULL;
1063 struct wpa_scan_results *scan_res;
1067 if (wpa_s->ap_iface)
1069 #endif /* CONFIG_AP */
1071 wpa_supplicant_notify_scanning(wpa_s, 0);
1075 if (p2p_search_pending(wpa_s->global->p2p) && !wpa_s->global->p2p_disabled &&
1077 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
1079 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending) {
1080 wpa_s->p2p_cb_on_scan_complete = 0;
1081 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1082 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1083 "stopped scan processing");
1087 wpa_s->sta_scan_pending = 0;
1088 #endif /* CONFIG_P2P */
1090 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1091 data ? &data->scan_info :
1093 if (scan_res == NULL) {
1094 if (wpa_s->conf->ap_scan == 2 || ap)
1096 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1098 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1102 #ifndef CONFIG_NO_RANDOM_POOL
1104 num = scan_res->num;
1107 for (i = 0; i < num; i++) {
1109 struct wpa_scan_res *res = scan_res->res[i];
1110 buf[0] = res->bssid[5];
1111 buf[1] = res->qual & 0xff;
1112 buf[2] = res->noise & 0xff;
1113 buf[3] = res->level & 0xff;
1114 buf[4] = res->tsf & 0xff;
1115 random_add_randomness(buf, sizeof(buf));
1117 #endif /* CONFIG_NO_RANDOM_POOL */
1119 if (wpa_s->scan_res_handler) {
1120 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1121 struct wpa_scan_results *scan_res);
1123 scan_res_handler = wpa_s->scan_res_handler;
1124 wpa_s->scan_res_handler = NULL;
1125 scan_res_handler(wpa_s, scan_res);
1127 wpa_scan_results_free(scan_res);
1132 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1134 if (wpa_s->ap_iface->scan_cb)
1135 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1136 #endif /* CONFIG_AP */
1137 wpa_scan_results_free(scan_res);
1143 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1144 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1145 wpas_notify_scan_results(wpa_s);
1148 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1149 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1150 wpas_notify_scan_results(wpa_s);
1153 wpas_notify_scan_done(wpa_s, 1);
1155 if (sme_proc_obss_scan(wpa_s) > 0) {
1156 wpa_scan_results_free(scan_res);
1160 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1161 wpa_scan_results_free(scan_res);
1165 if (autoscan_notify_scan(wpa_s, scan_res)) {
1166 wpa_scan_results_free(scan_res);
1170 if (wpa_s->disconnected) {
1171 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1172 wpa_scan_results_free(scan_res);
1176 if (!wpas_driver_bss_selection(wpa_s) &&
1177 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1178 wpa_scan_results_free(scan_res);
1182 wpas_wps_update_ap_info(wpa_s, scan_res);
1184 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
1188 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
1190 wpa_scan_results_free(scan_res);
1192 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1196 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1197 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1200 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1202 wpa_scan_results_free(scan_res);
1203 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1204 ssid = wpa_supplicant_pick_new_network(wpa_s);
1206 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1207 wpa_supplicant_associate(wpa_s, NULL, ssid);
1208 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1210 int timeout_sec = wpa_s->scan_interval;
1211 int timeout_usec = 0;
1213 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1216 if (wpa_s->p2p_in_provisioning) {
1218 * Use shorter wait during P2P Provisioning
1219 * state to speed up group formation.
1222 timeout_usec = 250000;
1223 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1227 #endif /* CONFIG_P2P */
1228 #ifdef CONFIG_INTERWORKING
1229 if (wpa_s->conf->auto_interworking &&
1230 wpa_s->conf->interworking &&
1231 wpa_s->conf->cred) {
1232 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1233 "start ANQP fetch since no matching "
1235 wpa_s->network_select = 1;
1236 wpa_s->auto_network_select = 1;
1237 interworking_start_fetch_anqp(wpa_s);
1240 #endif /* CONFIG_INTERWORKING */
1241 if (wpa_supplicant_req_sched_scan(wpa_s))
1242 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1250 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1251 union wpa_event_data *data)
1253 const char *rn, *rn2;
1254 struct wpa_supplicant *ifs;
1256 if (_wpa_supplicant_event_scan_results(wpa_s, data, 0) < 0) {
1258 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
1261 * If no scan results could be fetched, then no need to
1262 * notify those interfaces that did not actually request
1269 * Check other interfaces to see if they have the same radio-name. If
1270 * so, they get updated with this same scan info.
1272 if (!wpa_s->driver->get_radio_name)
1275 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1276 if (rn == NULL || rn[0] == '\0')
1279 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1280 "sharing same radio (%s) in event_scan_results", rn);
1282 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1283 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1286 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1287 if (rn2 && os_strcmp(rn, rn2) == 0) {
1288 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1289 "sibling", ifs->ifname);
1291 if ( (ifs->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) || (ifs->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)) {
1292 /* Do not update the scan results from STA interface to p2p interfaces */
1293 wpa_printf(MSG_DEBUG, "Not Updating scan results on interface %s from "
1294 "sibling %s", ifs->ifname, wpa_s->ifname);
1298 /* P2P_FIND will result in too many SCAN_RESULT_EVENTS within
1299 * no time. Avoid announcing it to application as it may not
1300 * be that useful (since results will be that of only 1,6,11).
1301 * over to any other interface as it
1303 if(p2p_search_in_progress(wpa_s->global->p2p))
1304 _wpa_supplicant_event_scan_results(ifs, data, 1);
1306 _wpa_supplicant_event_scan_results(ifs, data, 0);
1309 _wpa_supplicant_event_scan_results(ifs, data);
1315 #endif /* CONFIG_NO_SCAN_PROCESSING */
1320 static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1322 struct wpa_supplicant *wpa_s = eloop_ctx;
1324 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1327 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1328 MAC2STR(wpa_s->bssid));
1329 /* TODO: could skip this if normal data traffic has been sent */
1330 /* TODO: Consider using some more appropriate data frame for this */
1332 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
1335 if (wpa_s->sme.bss_max_idle_period) {
1337 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1340 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1341 wnm_bss_keep_alive, wpa_s, NULL);
1343 #endif /* CONFIG_SME */
1347 static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1348 const u8 *ies, size_t ies_len)
1350 struct ieee802_11_elems elems;
1355 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1359 if (elems.bss_max_idle_period) {
1361 wpa_s->sme.bss_max_idle_period =
1362 WPA_GET_LE16(elems.bss_max_idle_period);
1363 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1364 "TU)%s", wpa_s->sme.bss_max_idle_period,
1365 (elems.bss_max_idle_period[2] & 0x01) ?
1366 " (protected keep-live required)" : "");
1367 if (wpa_s->sme.bss_max_idle_period == 0)
1368 wpa_s->sme.bss_max_idle_period = 1;
1369 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1370 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1371 /* msec times 1000 */
1372 msec = wpa_s->sme.bss_max_idle_period * 1024;
1375 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1376 wnm_bss_keep_alive, wpa_s,
1380 #endif /* CONFIG_SME */
1383 #endif /* CONFIG_WNM */
1386 void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1389 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1390 #endif /* CONFIG_WNM */
1394 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1395 union wpa_event_data *data)
1397 int l, len, found = 0, wpa_found, rsn_found;
1400 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1401 if (data->assoc_info.req_ies)
1402 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1403 data->assoc_info.req_ies_len);
1404 if (data->assoc_info.resp_ies) {
1405 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1406 data->assoc_info.resp_ies_len);
1408 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1409 data->assoc_info.resp_ies_len);
1410 #endif /* CONFIG_TDLS */
1412 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1413 data->assoc_info.resp_ies_len);
1414 #endif /* CONFIG_WNM */
1416 if (data->assoc_info.beacon_ies)
1417 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1418 data->assoc_info.beacon_ies,
1419 data->assoc_info.beacon_ies_len);
1420 if (data->assoc_info.freq)
1421 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1422 data->assoc_info.freq);
1424 p = data->assoc_info.req_ies;
1425 l = data->assoc_info.req_ies_len;
1427 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1428 while (p && l >= 2) {
1431 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1435 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1436 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1437 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1438 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1441 wpa_find_assoc_pmkid(wpa_s);
1447 if (!found && data->assoc_info.req_ies)
1448 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1450 #ifdef CONFIG_IEEE80211R
1452 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1454 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1455 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1456 data->assoc_info.resp_ies,
1457 data->assoc_info.resp_ies_len,
1459 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1460 "Reassociation Response failed");
1461 wpa_supplicant_deauthenticate(
1462 wpa_s, WLAN_REASON_INVALID_IE);
1467 p = data->assoc_info.resp_ies;
1468 l = data->assoc_info.resp_ies_len;
1470 #ifdef CONFIG_WPS_STRICT
1471 if (p && wpa_s->current_ssid &&
1472 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1474 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1476 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1477 "include WPS IE in (Re)Association Response");
1481 if (wps_validate_assoc_resp(wps) < 0) {
1483 wpa_supplicant_deauthenticate(
1484 wpa_s, WLAN_REASON_INVALID_IE);
1489 #endif /* CONFIG_WPS_STRICT */
1491 /* Go through the IEs and make a copy of the MDIE, if present. */
1492 while (p && l >= 2) {
1495 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1499 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1500 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1501 wpa_s->sme.ft_used = 1;
1502 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1503 MOBILITY_DOMAIN_ID_LEN);
1509 #endif /* CONFIG_SME */
1511 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1512 data->assoc_info.resp_ies_len);
1513 #endif /* CONFIG_IEEE80211R */
1515 /* WPA/RSN IE from Beacon/ProbeResp */
1516 p = data->assoc_info.beacon_ies;
1517 l = data->assoc_info.beacon_ies_len;
1519 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1521 wpa_found = rsn_found = 0;
1522 while (p && l >= 2) {
1525 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1530 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1531 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1533 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1537 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1539 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1546 if (!wpa_found && data->assoc_info.beacon_ies)
1547 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1548 if (!rsn_found && data->assoc_info.beacon_ies)
1549 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1550 if (wpa_found || rsn_found)
1551 wpa_s->ap_ies_from_associnfo = 1;
1553 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1554 wpa_s->assoc_freq != data->assoc_info.freq) {
1555 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1557 wpa_s->assoc_freq, data->assoc_info.freq);
1558 wpa_supplicant_update_scan_results(wpa_s);
1561 wpa_s->assoc_freq = data->assoc_info.freq;
1567 static struct wpa_bss * wpa_supplicant_get_new_bss(
1568 struct wpa_supplicant *wpa_s, const u8 *bssid)
1570 struct wpa_bss *bss = NULL;
1571 struct wpa_ssid *ssid = wpa_s->current_ssid;
1573 if (ssid->ssid_len > 0)
1574 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1576 bss = wpa_bss_get_bssid(wpa_s, bssid);
1582 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1584 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1586 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1589 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1592 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1593 WPA_IE_VENDOR_TYPE);
1594 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1596 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1597 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1598 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1599 bss_rsn ? 2 + bss_rsn[1] : 0))
1606 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1607 union wpa_event_data *data)
1611 struct wpa_driver_capa capa;
1614 if (wpa_s->ap_iface) {
1615 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1616 data->assoc_info.addr,
1617 data->assoc_info.req_ies,
1618 data->assoc_info.req_ies_len,
1619 data->assoc_info.reassoc);
1622 #endif /* CONFIG_AP */
1624 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1625 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1628 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1629 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
1630 wpa_supplicant_disassociate(
1631 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1635 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1636 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1637 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1638 MACSTR, MAC2STR(bssid));
1639 random_add_randomness(bssid, ETH_ALEN);
1640 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1641 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1642 wpas_notify_bssid_changed(wpa_s);
1644 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1645 wpa_clear_keys(wpa_s, bssid);
1647 if (wpa_supplicant_select_config(wpa_s) < 0) {
1648 wpa_supplicant_disassociate(
1649 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1652 if (wpa_s->current_ssid) {
1653 struct wpa_bss *bss = NULL;
1655 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1657 wpa_supplicant_update_scan_results(wpa_s);
1659 /* Get the BSS from the new scan results */
1660 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1664 wpa_s->current_bss = bss;
1667 if (wpa_s->conf->ap_scan == 1 &&
1668 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1669 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1670 wpa_msg(wpa_s, MSG_WARNING,
1671 "WPA/RSN IEs not updated");
1676 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1677 wpa_s->sme.prev_bssid_set = 1;
1678 #endif /* CONFIG_SME */
1680 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1681 if (wpa_s->current_ssid) {
1682 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1683 * initialized before association, but for other modes,
1684 * initialize PC/SC here, if the current configuration needs
1685 * smartcard or SIM/USIM. */
1686 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1688 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1690 l2_packet_notify_auth_start(wpa_s->l2);
1693 * Set portEnabled first to FALSE in order to get EAP state machine out
1694 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1695 * state machine may transit to AUTHENTICATING state based on obsolete
1696 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1697 * AUTHENTICATED without ever giving chance to EAP state machine to
1700 if (!ft_completed) {
1701 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1702 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1704 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1705 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1706 /* 802.1X::portControl = Auto */
1707 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1708 wpa_s->eapol_received = 0;
1709 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1710 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1711 (wpa_s->current_ssid &&
1712 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1713 wpa_supplicant_cancel_auth_timeout(wpa_s);
1714 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1715 } else if (!ft_completed) {
1716 /* Timeout for receiving the first EAPOL packet */
1717 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1719 wpa_supplicant_cancel_scan(wpa_s);
1721 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1722 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1724 * We are done; the driver will take care of RSN 4-way
1727 wpa_supplicant_cancel_auth_timeout(wpa_s);
1728 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1729 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1730 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1731 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1732 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1734 * The driver will take care of RSN 4-way handshake, so we need
1735 * to allow EAPOL supplicant to complete its work without
1736 * waiting for WPA supplicant.
1738 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1739 } else if (ft_completed) {
1741 * FT protocol completed - make sure EAPOL state machine ends
1742 * up in authenticated.
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);
1750 if (wpa_s->pending_eapol_rx) {
1751 struct os_time now, age;
1753 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1754 if (age.sec == 0 && age.usec < 100000 &&
1755 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1757 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1758 "frame that was received just before "
1759 "association notification");
1760 wpa_supplicant_rx_eapol(
1761 wpa_s, wpa_s->pending_eapol_rx_src,
1762 wpabuf_head(wpa_s->pending_eapol_rx),
1763 wpabuf_len(wpa_s->pending_eapol_rx));
1765 wpabuf_free(wpa_s->pending_eapol_rx);
1766 wpa_s->pending_eapol_rx = NULL;
1769 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1770 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1771 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1772 capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1773 /* Set static WEP keys again */
1774 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1777 #ifdef CONFIG_IBSS_RSN
1778 if (wpa_s->current_ssid &&
1779 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1780 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1781 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1782 wpa_s->ibss_rsn == NULL) {
1783 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1784 if (!wpa_s->ibss_rsn) {
1785 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1786 wpa_supplicant_deauthenticate(
1787 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1791 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1793 #endif /* CONFIG_IBSS_RSN */
1795 wpas_wps_notify_assoc(wpa_s, bssid);
1799 static int disconnect_reason_recoverable(u16 reason_code)
1801 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1802 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1803 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1807 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1809 int locally_generated)
1813 u8 prev_pending_bssid[ETH_ALEN];
1814 struct wpa_bss *fast_reconnect = NULL;
1815 struct wpa_ssid *fast_reconnect_ssid = NULL;
1817 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1818 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1820 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1822 * At least Host AP driver and a Prism3 card seemed to be
1823 * generating streams of disconnected events when configuring
1824 * IBSS for WPA-None. Ignore them for now.
1826 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1827 "IBSS/WPA-None mode");
1831 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1832 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1833 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1834 "pre-shared key may be incorrect");
1835 wpas_auth_failed(wpa_s);
1837 if (!wpa_s->auto_reconnect_disabled ||
1838 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1839 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1840 "reconnect (wps=%d wpa_state=%d)",
1841 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1843 if (wpa_s->wpa_state == WPA_COMPLETED &&
1844 wpa_s->current_ssid &&
1845 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1846 !locally_generated &&
1847 disconnect_reason_recoverable(reason_code)) {
1849 * It looks like the AP has dropped association with
1850 * us, but could allow us to get back in. Try to
1851 * reconnect to the same BSS without full scan to save
1852 * time for some common cases.
1854 fast_reconnect = wpa_s->current_bss;
1855 fast_reconnect_ssid = wpa_s->current_ssid;
1856 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1858 wpa_supplicant_req_scan(wpa_s, 0, 500000);
1860 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1863 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1866 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1867 "try to re-connect");
1868 wpa_s->reassociate = 0;
1869 wpa_s->disconnected = 1;
1870 wpa_supplicant_cancel_sched_scan(wpa_s);
1872 bssid = wpa_s->bssid;
1873 if (is_zero_ether_addr(bssid))
1874 bssid = wpa_s->pending_bssid;
1875 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1876 wpas_connection_failed(wpa_s, bssid);
1877 wpa_sm_notify_disassoc(wpa_s->wpa);
1878 if (locally_generated)
1879 wpa_s->disconnect_reason = -reason_code;
1881 wpa_s->disconnect_reason = reason_code;
1882 wpas_notify_disconnect_reason(wpa_s);
1883 if (!is_zero_ether_addr(bssid) ||
1884 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1885 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1887 MAC2STR(bssid), reason_code,
1888 locally_generated ? " locally_generated=1" : "");
1890 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1891 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1892 wpa_s->keys_cleared = 0;
1893 wpa_clear_keys(wpa_s, wpa_s->bssid);
1895 wpa_supplicant_mark_disassoc(wpa_s);
1897 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1898 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1900 if (fast_reconnect) {
1901 #ifndef CONFIG_NO_SCAN_PROCESSING
1902 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1903 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1904 fast_reconnect_ssid) < 0) {
1905 /* Recover through full scan */
1906 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1908 #endif /* CONFIG_NO_SCAN_PROCESSING */
1913 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1914 void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
1916 struct wpa_supplicant *wpa_s = eloop_ctx;
1918 if (!wpa_s->pending_mic_error_report)
1921 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1922 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1923 wpa_s->pending_mic_error_report = 0;
1925 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1929 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1930 union wpa_event_data *data)
1935 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1936 pairwise = (data && data->michael_mic_failure.unicast);
1938 if ((wpa_s->last_michael_mic_error &&
1939 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1940 wpa_s->pending_mic_error_report) {
1941 if (wpa_s->pending_mic_error_report) {
1943 * Send the pending MIC error report immediately since
1944 * we are going to start countermeasures and AP better
1947 wpa_sm_key_request(wpa_s->wpa, 1,
1948 wpa_s->pending_mic_error_pairwise);
1951 /* Send the new MIC error report immediately since we are going
1952 * to start countermeasures and AP better do the same.
1954 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1956 /* initialize countermeasures */
1957 wpa_s->countermeasures = 1;
1959 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1961 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1964 * Need to wait for completion of request frame. We do not get
1965 * any callback for the message completion, so just wait a
1966 * short while and hope for the best. */
1969 wpa_drv_set_countermeasures(wpa_s, 1);
1970 wpa_supplicant_deauthenticate(wpa_s,
1971 WLAN_REASON_MICHAEL_MIC_FAILURE);
1972 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1974 eloop_register_timeout(60, 0,
1975 wpa_supplicant_stop_countermeasures,
1977 /* TODO: mark the AP rejected for 60 second. STA is
1978 * allowed to associate with another AP.. */
1980 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1981 if (wpa_s->mic_errors_seen) {
1983 * Reduce the effectiveness of Michael MIC error
1984 * reports as a means for attacking against TKIP if
1985 * more than one MIC failure is noticed with the same
1986 * PTK. We delay the transmission of the reports by a
1987 * random time between 0 and 60 seconds in order to
1988 * force the attacker wait 60 seconds before getting
1989 * the information on whether a frame resulted in a MIC
1995 if (os_get_random(rval, sizeof(rval)) < 0)
1996 sec = os_random() % 60;
1998 sec = WPA_GET_BE32(rval) % 60;
1999 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2000 "report %d seconds", sec);
2001 wpa_s->pending_mic_error_report = 1;
2002 wpa_s->pending_mic_error_pairwise = pairwise;
2003 eloop_cancel_timeout(
2004 wpa_supplicant_delayed_mic_error_report,
2006 eloop_register_timeout(
2007 sec, os_random() % 1000000,
2008 wpa_supplicant_delayed_mic_error_report,
2011 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2013 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2014 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2015 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2017 wpa_s->last_michael_mic_error = t.sec;
2018 wpa_s->mic_errors_seen++;
2022 #ifdef CONFIG_TERMINATE_ONLASTIF
2023 static int any_interfaces(struct wpa_supplicant *head)
2025 struct wpa_supplicant *wpa_s;
2027 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2028 if (!wpa_s->interface_removed)
2032 #endif /* CONFIG_TERMINATE_ONLASTIF */
2036 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2037 union wpa_event_data *data)
2039 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2042 switch (data->interface_status.ievent) {
2043 case EVENT_INTERFACE_ADDED:
2044 if (!wpa_s->interface_removed)
2046 wpa_s->interface_removed = 0;
2047 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2048 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2049 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2050 "driver after interface was added");
2052 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2054 case EVENT_INTERFACE_REMOVED:
2055 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2056 wpa_s->interface_removed = 1;
2057 wpa_supplicant_mark_disassoc(wpa_s);
2058 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2059 l2_packet_deinit(wpa_s->l2);
2061 #ifdef CONFIG_IBSS_RSN
2062 ibss_rsn_deinit(wpa_s->ibss_rsn);
2063 wpa_s->ibss_rsn = NULL;
2064 #endif /* CONFIG_IBSS_RSN */
2065 #ifdef CONFIG_TERMINATE_ONLASTIF
2066 /* check if last interface */
2067 if (!any_interfaces(wpa_s->global->ifaces))
2069 #endif /* CONFIG_TERMINATE_ONLASTIF */
2075 #ifdef CONFIG_PEERKEY
2077 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2078 union wpa_event_data *data)
2082 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2084 #endif /* CONFIG_PEERKEY */
2088 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2089 union wpa_event_data *data)
2093 switch (data->tdls.oper) {
2094 case TDLS_REQUEST_SETUP:
2095 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2097 case TDLS_REQUEST_TEARDOWN:
2098 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
2099 data->tdls.reason_code);
2103 #endif /* CONFIG_TDLS */
2106 #ifdef CONFIG_IEEE80211V
2107 static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2108 union wpa_event_data *data)
2112 switch (data->wnm.oper) {
2113 case WNM_OPER_SLEEP:
2114 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2115 "(action=%d, intval=%d)",
2116 data->wnm.sleep_action, data->wnm.sleep_intval);
2117 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
2118 data->wnm.sleep_intval);
2122 #endif /* CONFIG_IEEE80211V */
2125 #ifdef CONFIG_IEEE80211R
2127 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2128 union wpa_event_data *data)
2133 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2134 data->ft_ies.ies_len,
2135 data->ft_ies.ft_action,
2136 data->ft_ies.target_ap,
2137 data->ft_ies.ric_ies,
2138 data->ft_ies.ric_ies_len) < 0) {
2139 /* TODO: prevent MLME/driver from trying to associate? */
2142 #endif /* CONFIG_IEEE80211R */
2145 #ifdef CONFIG_IBSS_RSN
2146 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2147 union wpa_event_data *data)
2149 struct wpa_ssid *ssid;
2150 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2154 ssid = wpa_s->current_ssid;
2157 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2160 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2162 #endif /* CONFIG_IBSS_RSN */
2165 #ifdef CONFIG_IEEE80211R
2166 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2169 const u8 *sta_addr, *target_ap_addr;
2172 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2173 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2174 return; /* only SME case supported for now */
2175 if (len < 1 + 2 * ETH_ALEN + 2)
2178 return; /* Only FT Action Response is supported for now */
2179 sta_addr = data + 1;
2180 target_ap_addr = data + 1 + ETH_ALEN;
2181 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2182 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2183 MACSTR " TargetAP " MACSTR " status %u",
2184 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2186 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2187 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2188 " in FT Action Response", MAC2STR(sta_addr));
2193 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2194 "failure (status code %d)", status);
2195 /* TODO: report error to FT code(?) */
2199 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2200 len - (1 + 2 * ETH_ALEN + 2), 1,
2201 target_ap_addr, NULL, 0) < 0)
2206 struct wpa_bss *bss;
2207 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2209 wpa_s->sme.freq = bss->freq;
2210 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2211 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2214 #endif /* CONFIG_SME */
2216 #endif /* CONFIG_IEEE80211R */
2219 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2220 struct unprot_deauth *e)
2222 #ifdef CONFIG_IEEE80211W
2223 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2224 "dropped: " MACSTR " -> " MACSTR
2225 " (reason code %u)",
2226 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2227 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2228 #endif /* CONFIG_IEEE80211W */
2232 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2233 struct unprot_disassoc *e)
2235 #ifdef CONFIG_IEEE80211W
2236 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2237 "dropped: " MACSTR " -> " MACSTR
2238 " (reason code %u)",
2239 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2240 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2241 #endif /* CONFIG_IEEE80211W */
2245 static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2248 const u8 *pos, *end;
2250 if (rx->data == NULL || rx->len == 0)
2254 end = pos + rx->len;
2257 wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
2258 action, MAC2STR(rx->sa));
2260 case WNM_BSS_TRANS_MGMT_REQ:
2263 wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
2264 "Request: dialog_token=%u request_mode=0x%x "
2265 "disassoc_timer=%u validity_interval=%u",
2266 pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
2270 pos += 12; /* BSS Termination Duration */
2273 if (pos + 1 > end || pos + 1 + pos[0] > end) {
2274 wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
2275 "Transition Management Request "
2279 os_memcpy(url, pos + 1, pos[0]);
2281 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2282 "Imminent - session_info_url=%s", url);
2289 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2290 union wpa_event_data *data)
2292 struct wpa_supplicant *wpa_s = ctx;
2293 u16 reason_code = 0;
2294 int locally_generated = 0;
2296 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2297 event != EVENT_INTERFACE_ENABLED &&
2298 event != EVENT_INTERFACE_STATUS &&
2299 event != EVENT_SCHED_SCAN_STOPPED) {
2300 wpa_dbg(wpa_s, MSG_DEBUG,
2301 "Ignore event %s (%d) while interface is disabled",
2302 event_to_string(event), event);
2306 #ifndef CONFIG_NO_STDOUT_DEBUG
2308 int level = MSG_DEBUG;
2310 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
2311 const struct ieee80211_hdr *hdr;
2313 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2314 fc = le_to_host16(hdr->frame_control);
2315 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2316 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2317 level = MSG_EXCESSIVE;
2320 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2321 event_to_string(event), event);
2323 #endif /* CONFIG_NO_STDOUT_DEBUG */
2327 sme_event_auth(wpa_s, data);
2330 wpa_supplicant_event_assoc(wpa_s, data);
2332 case EVENT_DISASSOC:
2333 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2335 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2336 data->disassoc_info.reason_code,
2337 data->disassoc_info.locally_generated ?
2338 " (locally generated)" : "");
2339 if (data->disassoc_info.addr)
2340 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2341 MAC2STR(data->disassoc_info.addr));
2344 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2345 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2346 data->disassoc_info.addr);
2349 if (wpa_s->ap_iface) {
2350 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2354 #endif /* CONFIG_AP */
2356 reason_code = data->disassoc_info.reason_code;
2358 data->disassoc_info.locally_generated;
2359 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2360 data->disassoc_info.ie,
2361 data->disassoc_info.ie_len);
2363 wpas_p2p_disassoc_notif(
2364 wpa_s, data->disassoc_info.addr, reason_code,
2365 data->disassoc_info.ie,
2366 data->disassoc_info.ie_len,
2368 #endif /* CONFIG_P2P */
2370 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2371 sme_event_disassoc(wpa_s, data);
2374 if (event == EVENT_DEAUTH) {
2375 wpa_dbg(wpa_s, MSG_DEBUG,
2376 "Deauthentication notification");
2378 reason_code = data->deauth_info.reason_code;
2380 data->deauth_info.locally_generated;
2381 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2382 data->deauth_info.reason_code,
2383 data->deauth_info.locally_generated ?
2384 " (locally generated)" : "");
2385 if (data->deauth_info.addr) {
2386 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2388 MAC2STR(data->deauth_info.
2391 wpa_hexdump(MSG_DEBUG,
2392 "Deauthentication frame IE(s)",
2393 data->deauth_info.ie,
2394 data->deauth_info.ie_len);
2398 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2399 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2400 data->deauth_info.addr);
2403 if (wpa_s->ap_iface) {
2404 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2408 #endif /* CONFIG_AP */
2409 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2411 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2412 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2413 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2414 eapol_sm_failed(wpa_s->eapol)))
2415 wpas_auth_failed(wpa_s);
2417 if (event == EVENT_DEAUTH && data) {
2418 wpas_p2p_deauth_notif(wpa_s, data->deauth_info.addr,
2420 data->deauth_info.ie,
2421 data->deauth_info.ie_len,
2424 #endif /* CONFIG_P2P */
2426 case EVENT_MICHAEL_MIC_FAILURE:
2427 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2429 #ifndef CONFIG_NO_SCAN_PROCESSING
2430 case EVENT_SCAN_RESULTS:
2431 wpa_supplicant_event_scan_results(wpa_s, data);
2433 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
2434 wpa_s->global->p2p != NULL &&
2435 wpa_s->wpa_state != WPA_AUTHENTICATING &&
2436 wpa_s->wpa_state != WPA_ASSOCIATING) {
2437 wpa_s->p2p_cb_on_scan_complete = 0;
2438 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
2439 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
2440 "continued after scan result processing");
2443 #endif /* CONFIG_P2P */
2445 #endif /* CONFIG_NO_SCAN_PROCESSING */
2446 case EVENT_ASSOCINFO:
2447 wpa_supplicant_event_associnfo(wpa_s, data);
2449 case EVENT_INTERFACE_STATUS:
2450 wpa_supplicant_event_interface_status(wpa_s, data);
2452 case EVENT_PMKID_CANDIDATE:
2453 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2455 #ifdef CONFIG_PEERKEY
2456 case EVENT_STKSTART:
2457 wpa_supplicant_event_stkstart(wpa_s, data);
2459 #endif /* CONFIG_PEERKEY */
2462 wpa_supplicant_event_tdls(wpa_s, data);
2464 #endif /* CONFIG_TDLS */
2465 #ifdef CONFIG_IEEE80211V
2467 wpa_supplicant_event_wnm(wpa_s, data);
2469 #endif /* CONFIG_IEEE80211V */
2470 #ifdef CONFIG_IEEE80211R
2471 case EVENT_FT_RESPONSE:
2472 wpa_supplicant_event_ft_response(wpa_s, data);
2474 #endif /* CONFIG_IEEE80211R */
2475 #ifdef CONFIG_IBSS_RSN
2476 case EVENT_IBSS_RSN_START:
2477 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2479 #endif /* CONFIG_IBSS_RSN */
2480 case EVENT_ASSOC_REJECT:
2481 if (data->assoc_reject.bssid)
2482 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2483 "bssid=" MACSTR " status_code=%u",
2484 MAC2STR(data->assoc_reject.bssid),
2485 data->assoc_reject.status_code);
2487 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2489 data->assoc_reject.status_code);
2490 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2491 sme_event_assoc_reject(wpa_s, data);
2494 else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
2495 if(!wpa_s->current_ssid) {
2496 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2499 /* If assoc reject is reported by the driver, then avoid
2500 * waiting for the authentication timeout. Cancel the
2501 * authentication timeout and retry the assoc.
2503 if(wpa_s->current_ssid->assoc_retry++ < 5) {
2504 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2505 wpa_s->current_ssid->assoc_retry);
2506 wpa_supplicant_cancel_auth_timeout(wpa_s);
2508 /* Clear the states */
2509 wpa_sm_notify_disassoc(wpa_s->wpa);
2510 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2512 wpa_s->reassociate = 1;
2513 wpa_supplicant_req_scan(wpa_s, 1, 0);
2515 /* If we ASSOC_REJECT's hits threshold, disable the
2518 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2519 "Disabling the network");
2520 wpa_s->current_ssid->assoc_retry = 0;
2521 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
2522 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
2526 #endif /* ANDROID_P2P */
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 */
2695 #ifdef CONFIG_IEEE80211V
2696 if (data->rx_action.category == WLAN_ACTION_WNM) {
2697 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2700 #endif /* CONFIG_IEEE80211V */
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 */
2709 if (data->rx_action.category == WLAN_ACTION_WNM) {
2710 wnm_action_rx(wpa_s, &data->rx_action);
2714 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2715 data->rx_action.len >= 4 &&
2716 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2717 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2718 "Response from " MACSTR,
2719 MAC2STR(data->rx_action.sa));
2722 #endif /* CONFIG_TDLS */
2724 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2726 data->rx_action.bssid,
2727 data->rx_action.category,
2728 data->rx_action.data,
2729 data->rx_action.len, data->rx_action.freq);
2730 #endif /* CONFIG_P2P */
2732 case EVENT_RX_PROBE_REQ:
2733 if (data->rx_probe_req.sa == NULL ||
2734 data->rx_probe_req.ie == NULL)
2737 if (wpa_s->ap_iface) {
2738 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2739 data->rx_probe_req.sa,
2740 data->rx_probe_req.da,
2741 data->rx_probe_req.bssid,
2742 data->rx_probe_req.ie,
2743 data->rx_probe_req.ie_len,
2744 data->rx_probe_req.ssi_signal);
2747 #endif /* CONFIG_AP */
2749 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2750 data->rx_probe_req.da,
2751 data->rx_probe_req.bssid,
2752 data->rx_probe_req.ie,
2753 data->rx_probe_req.ie_len,
2754 data->rx_probe_req.ssi_signal);
2755 #endif /* CONFIG_P2P */
2757 case EVENT_REMAIN_ON_CHANNEL:
2758 #ifdef CONFIG_OFFCHANNEL
2759 offchannel_remain_on_channel_cb(
2760 wpa_s, data->remain_on_channel.freq,
2761 data->remain_on_channel.duration);
2762 #endif /* CONFIG_OFFCHANNEL */
2764 wpas_p2p_remain_on_channel_cb(
2765 wpa_s, data->remain_on_channel.freq,
2766 data->remain_on_channel.duration);
2767 #endif /* CONFIG_P2P */
2769 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
2770 #ifdef CONFIG_OFFCHANNEL
2771 offchannel_cancel_remain_on_channel_cb(
2772 wpa_s, data->remain_on_channel.freq);
2773 #endif /* CONFIG_OFFCHANNEL */
2775 wpas_p2p_cancel_remain_on_channel_cb(
2776 wpa_s, data->remain_on_channel.freq);
2777 #endif /* CONFIG_P2P */
2780 case EVENT_P2P_DEV_FOUND: {
2781 struct p2p_peer_info peer_info;
2783 os_memset(&peer_info, 0, sizeof(peer_info));
2784 if (data->p2p_dev_found.dev_addr)
2785 os_memcpy(peer_info.p2p_device_addr,
2786 data->p2p_dev_found.dev_addr, ETH_ALEN);
2787 if (data->p2p_dev_found.pri_dev_type)
2788 os_memcpy(peer_info.pri_dev_type,
2789 data->p2p_dev_found.pri_dev_type,
2790 sizeof(peer_info.pri_dev_type));
2791 if (data->p2p_dev_found.dev_name)
2792 os_strlcpy(peer_info.device_name,
2793 data->p2p_dev_found.dev_name,
2794 sizeof(peer_info.device_name));
2795 peer_info.config_methods = data->p2p_dev_found.config_methods;
2796 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
2797 peer_info.group_capab = data->p2p_dev_found.group_capab;
2800 * FIX: new_device=1 is not necessarily correct. We should
2801 * maintain a P2P peer database in wpa_supplicant and update
2802 * this information based on whether the peer is truly new.
2804 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2807 case EVENT_P2P_GO_NEG_REQ_RX:
2808 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2809 data->p2p_go_neg_req_rx.dev_passwd_id);
2811 case EVENT_P2P_GO_NEG_COMPLETED:
2812 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2814 case EVENT_P2P_PROV_DISC_REQUEST:
2815 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2816 data->p2p_prov_disc_req.config_methods,
2817 data->p2p_prov_disc_req.dev_addr,
2818 data->p2p_prov_disc_req.pri_dev_type,
2819 data->p2p_prov_disc_req.dev_name,
2820 data->p2p_prov_disc_req.supp_config_methods,
2821 data->p2p_prov_disc_req.dev_capab,
2822 data->p2p_prov_disc_req.group_capab,
2825 case EVENT_P2P_PROV_DISC_RESPONSE:
2826 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2827 data->p2p_prov_disc_resp.config_methods);
2829 case EVENT_P2P_SD_REQUEST:
2830 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2831 data->p2p_sd_req.sa,
2832 data->p2p_sd_req.dialog_token,
2833 data->p2p_sd_req.update_indic,
2834 data->p2p_sd_req.tlvs,
2835 data->p2p_sd_req.tlvs_len);
2837 case EVENT_P2P_SD_RESPONSE:
2838 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2839 data->p2p_sd_resp.update_indic,
2840 data->p2p_sd_resp.tlvs,
2841 data->p2p_sd_resp.tlvs_len);
2843 #endif /* CONFIG_P2P */
2844 case EVENT_EAPOL_RX:
2845 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2846 data->eapol_rx.data,
2847 data->eapol_rx.data_len);
2849 case EVENT_SIGNAL_CHANGE:
2850 bgscan_notify_signal_change(
2851 wpa_s, data->signal_change.above_threshold,
2852 data->signal_change.current_signal,
2853 data->signal_change.current_noise,
2854 data->signal_change.current_txrate);
2856 case EVENT_INTERFACE_ENABLED:
2857 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2858 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2859 wpa_supplicant_update_mac_addr(wpa_s);
2861 if (!wpa_s->ap_iface) {
2862 wpa_supplicant_set_state(wpa_s,
2864 wpa_supplicant_req_scan(wpa_s, 0, 0);
2866 wpa_supplicant_set_state(wpa_s,
2868 #else /* CONFIG_AP */
2869 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2870 wpa_supplicant_req_scan(wpa_s, 0, 0);
2871 #endif /* CONFIG_AP */
2874 case EVENT_INTERFACE_DISABLED:
2875 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2876 wpa_supplicant_mark_disassoc(wpa_s);
2877 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2879 case EVENT_CHANNEL_LIST_CHANGED:
2880 if (wpa_s->drv_priv == NULL)
2881 break; /* Ignore event during drv initialization */
2883 free_hw_features(wpa_s);
2884 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2885 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2888 wpas_p2p_update_channel_list(wpa_s);
2889 #endif /* CONFIG_P2P */
2891 case EVENT_INTERFACE_UNAVAILABLE:
2893 wpas_p2p_interface_unavailable(wpa_s);
2894 #endif /* CONFIG_P2P */
2896 case EVENT_BEST_CHANNEL:
2897 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2899 data->best_chan.freq_24, data->best_chan.freq_5,
2900 data->best_chan.freq_overall);
2901 wpa_s->best_24_freq = data->best_chan.freq_24;
2902 wpa_s->best_5_freq = data->best_chan.freq_5;
2903 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2905 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2906 data->best_chan.freq_5,
2907 data->best_chan.freq_overall);
2908 #endif /* CONFIG_P2P */
2910 case EVENT_UNPROT_DEAUTH:
2911 wpa_supplicant_event_unprot_deauth(wpa_s,
2912 &data->unprot_deauth);
2914 case EVENT_UNPROT_DISASSOC:
2915 wpa_supplicant_event_unprot_disassoc(wpa_s,
2916 &data->unprot_disassoc);
2918 case EVENT_STATION_LOW_ACK:
2920 if (wpa_s->ap_iface && data)
2921 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2922 data->low_ack.addr);
2923 #endif /* CONFIG_AP */
2926 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2927 #endif /* CONFIG_TDLS */
2929 case EVENT_IBSS_PEER_LOST:
2930 #ifdef CONFIG_IBSS_RSN
2931 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2932 #endif /* CONFIG_IBSS_RSN */
2934 case EVENT_DRIVER_GTK_REKEY:
2935 if (os_memcmp(data->driver_gtk_rekey.bssid,
2936 wpa_s->bssid, ETH_ALEN))
2940 wpa_sm_update_replay_ctr(wpa_s->wpa,
2941 data->driver_gtk_rekey.replay_ctr);
2943 case EVENT_SCHED_SCAN_STOPPED:
2944 wpa_s->sched_scanning = 0;
2945 wpa_supplicant_notify_scanning(wpa_s, 0);
2947 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2951 * If we timed out, start a new sched scan to continue
2952 * searching for more SSIDs.
2954 if (wpa_s->sched_scan_timed_out)
2955 wpa_supplicant_req_sched_scan(wpa_s);
2957 case EVENT_WPS_BUTTON_PUSHED:
2959 wpas_wps_start_pbc(wpa_s, NULL, 0);
2960 #endif /* CONFIG_WPS */
2963 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);