Lines Matching refs:wpa_s
44 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
48 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
51 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
53 ssid = wpa_supplicant_get_ssid(wpa_s);
55 wpa_msg(wpa_s, MSG_INFO,
61 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
65 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
70 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
73 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
76 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
77 eapol_sm_invalidate_cached_session(wpa_s->eapol);
78 old_ssid = wpa_s->current_ssid;
79 wpa_s->current_ssid = ssid;
80 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
81 wpa_supplicant_initiate_eapol(wpa_s);
82 if (old_ssid != wpa_s->current_ssid)
83 wpas_notify_network_changed(wpa_s);
91 struct wpa_supplicant *wpa_s = eloop_ctx;
93 if (wpa_s->countermeasures) {
94 wpa_s->countermeasures = 0;
95 wpa_drv_set_countermeasures(wpa_s, 0);
96 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
97 wpa_supplicant_req_scan(wpa_s, 0, 0);
102 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
107 ibss_rsn_deinit(wpa_s->ibss_rsn);
108 wpa_s->ibss_rsn = NULL;
112 wpa_supplicant_ap_deinit(wpa_s);
115 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
118 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
120 wpa_s->conf->ap_scan = DEFAULT_AP_SCAN;
122 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
123 os_memset(wpa_s->bssid, 0, ETH_ALEN);
124 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
126 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
128 wpa_s->current_bss = NULL;
129 wpa_s->assoc_freq = 0;
132 if (wpa_s->sme.ft_ies)
133 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
138 wpas_notify_bssid_changed(wpa_s);
140 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
141 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
142 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
143 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
144 wpa_s->ap_ies_from_associnfo = 0;
148 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
154 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
159 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
163 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
168 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
173 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
177 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
181 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
187 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
193 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
195 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
196 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
200 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
201 wpa_s->current_ssid &&
202 !(wpa_s->current_ssid->eapol_flags &
217 * @wpa_s: pointer to wpa_supplicant data
224 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
231 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
257 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
263 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
272 wpa_s->scard = scard_init(type);
273 if (wpa_s->scard == NULL) {
274 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
278 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
279 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
323 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
333 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
348 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
356 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
362 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
368 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
374 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
380 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
388 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
394 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
403 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
411 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
417 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
423 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
429 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
435 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
440 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
446 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
451 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
455 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
494 static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_scan_res *bss)
504 modes = wpa_s->hw.modes;
514 for (i = 0; i < wpa_s->hw.num_modes; i++) {
551 wpa_dbg(wpa_s, MSG_DEBUG,
573 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
585 static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
606 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
612 e = wpa_blacklist_get(wpa_s, bss->bssid);
615 if (wpa_supplicant_enabled_networks(wpa_s->conf) == 1) {
627 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
634 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
644 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
650 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
656 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
665 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
677 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
683 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
687 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
694 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
700 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
706 wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
712 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
717 if (!rate_match(wpa_s, bss)) {
718 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
741 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
748 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
756 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
764 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
767 return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
775 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
783 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
785 wpa_s, scan_res, wpa_s->conf->pssid[prio],
791 if (selected == NULL && wpa_s->blacklist &&
792 !wpa_s->countermeasures) {
793 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
795 wpa_blacklist_clear(wpa_s);
796 wpa_s->blacklist_cleared++;
805 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
808 if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
814 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
817 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
821 int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
825 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
826 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
829 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
834 wpas_wps_cancel(wpa_s);
844 if (wpa_s->reassociate ||
845 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
846 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
847 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
848 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
850 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
851 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
854 wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
857 wpa_s->reassociate, MAC2STR(selected->bssid),
858 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
859 wpa_supplicant_state_txt(wpa_s->wpa_state));
860 wpa_supplicant_associate(wpa_s, selected, ssid);
862 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
871 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
876 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
877 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
893 struct wpa_supplicant *wpa_s)
897 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
900 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
911 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
917 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
926 if (wpa_s->reassociate)
928 if (wpa_s->wpa_state < WPA_ASSOCIATED)
930 if (wpa_s->current_ssid == NULL)
932 if (wpa_s->current_ssid != ssid)
935 if (wpas_driver_bss_selection(wpa_s))
941 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
947 if (ie[1] != wpa_s->current_ssid->ssid_len ||
948 os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
958 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
959 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
961 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
964 if (wpa_s->current_ssid->bssid_set &&
965 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
967 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
986 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1000 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1003 static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1013 if (wpa_s->ap_iface)
1017 wpa_supplicant_notify_scanning(wpa_s, 0);
1021 if (p2p_search_pending(wpa_s->global->p2p) && !wpa_s->global->p2p_disabled &&
1023 if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
1025 wpa_s->global->p2p != NULL) {
1026 wpa_s->p2p_cb_on_scan_complete = 0;
1027 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1028 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1035 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1039 if (wpa_s->conf->ap_scan == 2 || ap)
1041 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1043 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1064 if (wpa_s->scan_res_handler) {
1065 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1068 scan_res_handler = wpa_s->scan_res_handler;
1069 wpa_s->scan_res_handler = NULL;
1070 scan_res_handler(wpa_s, scan_res);
1077 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1079 if (wpa_s->ap_iface->scan_cb)
1080 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1089 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1090 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1091 wpas_notify_scan_results(wpa_s);
1094 wpas_notify_scan_done(wpa_s, 1);
1096 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1101 if (wpa_s->disconnected) {
1102 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1107 if (!wpas_driver_bss_selection(wpa_s) &&
1108 bgscan_notify_scan(wpa_s, scan_res) == 1) {
1113 selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
1117 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
1121 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1125 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
1126 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
1129 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1132 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1133 ssid = wpa_supplicant_pick_new_network(wpa_s);
1135 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1136 wpa_supplicant_associate(wpa_s, NULL, ssid);
1137 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
1139 int timeout_sec = wpa_s->scan_interval;
1142 if (wpa_s->p2p_in_provisioning) {
1149 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1154 if (wpa_supplicant_req_sched_scan(wpa_s))
1155 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1163 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1169 if (_wpa_supplicant_event_scan_results(wpa_s, data, 0) < 0) {
1171 if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
1185 if (!wpa_s->driver->get_radio_name)
1188 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1192 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1195 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1196 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1207 "sibling %s", ifs->ifname, wpa_s->ifname);
1216 if(p2p_search_in_progress(wpa_s->global->p2p))
1231 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1237 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1245 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1254 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1271 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1274 wpa_find_assoc_pmkid(wpa_s);
1281 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1285 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1287 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1288 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1292 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1295 wpa_s, WLAN_REASON_INVALID_IE);
1304 if (p && wpa_s->current_ssid &&
1305 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1309 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1317 wpa_s, WLAN_REASON_INVALID_IE);
1334 wpa_s->sme.ft_used = 1;
1335 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1344 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1366 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1372 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1380 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1382 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1384 wpa_s->ap_ies_from_associnfo = 1;
1386 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1387 wpa_s->assoc_freq != data->assoc_info.freq) {
1390 wpa_s->assoc_freq, data->assoc_info.freq);
1391 wpa_supplicant_update_scan_results(wpa_s);
1394 wpa_s->assoc_freq = data->assoc_info.freq;
1401 struct wpa_supplicant *wpa_s, const u8 *bssid)
1404 struct wpa_ssid *ssid = wpa_s->current_ssid;
1407 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1409 bss = wpa_bss_get_bssid(wpa_s, bssid);
1415 static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1419 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1422 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1425 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1427 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1429 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1431 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1439 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1448 if (wpa_s->ap_iface) {
1449 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1458 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1459 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1462 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1463 if (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
1464 os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
1465 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1468 bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
1469 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1470 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1472 wpas_notify_bssid_changed(wpa_s);
1474 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1475 wpa_clear_keys(wpa_s, bssid);
1477 if (wpa_supplicant_select_config(wpa_s) < 0) {
1479 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1482 if (wpa_s->current_ssid) {
1485 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1487 wpa_supplicant_update_scan_results(wpa_s);
1490 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1494 wpa_s->current_bss = bss;
1497 if (wpa_s->conf->ap_scan == 1 &&
1498 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
1499 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1500 wpa_msg(wpa_s, MSG_WARNING,
1506 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1507 wpa_s->sme.prev_bssid_set = 1;
1510 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1511 if (wpa_s->current_ssid) {
1516 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1518 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1519 if (wpa_s->l2)
1520 l2_packet_notify_auth_start(wpa_s->l2);
1531 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1532 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1534 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1535 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1537 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1538 wpa_s->eapol_received = 0;
1539 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1540 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1541 (wpa_s->current_ssid &&
1542 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1543 wpa_supplicant_cancel_auth_timeout(wpa_s);
1544 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1547 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1549 wpa_supplicant_cancel_scan(wpa_s);
1551 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1552 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1557 wpa_supplicant_cancel_auth_timeout(wpa_s);
1558 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1559 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1560 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1561 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1562 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1568 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1574 wpa_supplicant_cancel_auth_timeout(wpa_s);
1575 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1576 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1577 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1580 if (wpa_s->pending_eapol_rx) {
1583 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1585 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1587 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1591 wpa_s, wpa_s->pending_eapol_rx_src,
1592 wpabuf_head(wpa_s->pending_eapol_rx),
1593 wpabuf_len(wpa_s->pending_eapol_rx));
1595 wpabuf_free(wpa_s->pending_eapol_rx);
1596 wpa_s->pending_eapol_rx = NULL;
1599 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1600 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1601 wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1604 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1608 if (wpa_s->current_ssid &&
1609 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1610 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1611 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1612 wpa_s->ibss_rsn == NULL) {
1613 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1614 if (!wpa_s->ibss_rsn) {
1615 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1617 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1621 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1635 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1645 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1646 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1648 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1654 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
1659 if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1660 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1661 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1664 if (!wpa_s->auto_reconnect_disabled ||
1665 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
1666 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
1668 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
1669 wpa_s->wpa_state);
1670 if (wpa_s->wpa_state == WPA_COMPLETED &&
1671 wpa_s->current_ssid &&
1672 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
1681 fast_reconnect = wpa_s->current_bss;
1682 fast_reconnect_ssid = wpa_s->current_ssid;
1683 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
1685 wpa_supplicant_req_scan(wpa_s, 0, 500000);
1687 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1690 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
1693 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
1695 wpa_s->reassociate = 0;
1696 wpa_s->disconnected = 1;
1697 wpa_supplicant_cancel_sched_scan(wpa_s);
1699 bssid = wpa_s->bssid;
1701 bssid = wpa_s->pending_bssid;
1702 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
1703 wpas_connection_failed(wpa_s, bssid);
1704 wpa_sm_notify_disassoc(wpa_s->wpa);
1705 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1708 if (wpa_supplicant_dynamic_keys(wpa_s)) {
1709 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
1710 wpa_s->keys_cleared = 0;
1711 wpa_clear_keys(wpa_s, wpa_s->bssid);
1713 wpa_supplicant_mark_disassoc(wpa_s);
1715 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1716 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
1720 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
1721 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
1724 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1734 struct wpa_supplicant *wpa_s = eloop_ctx;
1736 if (!wpa_s->pending_mic_error_report)
1739 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
1740 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1741 wpa_s->pending_mic_error_report = 0;
1747 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1753 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1756 if ((wpa_s->last_michael_mic_error &&
1757 t.sec - wpa_s->last_michael_mic_error <= 60) ||
1758 wpa_s->pending_mic_error_report) {
1759 if (wpa_s->pending_mic_error_report) {
1765 wpa_sm_key_request(wpa_s->wpa, 1,
1766 wpa_s->pending_mic_error_pairwise);
1772 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1775 wpa_s->countermeasures = 1;
1777 wpa_blacklist_add(wpa_s, wpa_s->bssid);
1779 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1787 wpa_drv_set_countermeasures(wpa_s, 1);
1788 wpa_supplicant_deauthenticate(wpa_s,
1791 wpa_s, NULL);
1794 wpa_s, NULL);
1799 if (wpa_s->mic_errors_seen) {
1817 wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
1819 wpa_s->pending_mic_error_report = 1;
1820 wpa_s->pending_mic_error_pairwise = pairwise;
1823 wpa_s, NULL);
1827 wpa_s, NULL);
1829 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1832 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1835 wpa_s->last_michael_mic_error = t.sec;
1836 wpa_s->mic_errors_seen++;
1843 struct wpa_supplicant *wpa_s;
1845 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1846 if (!wpa_s->interface_removed)
1854 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1857 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1862 if (!wpa_s->interface_removed)
1864 wpa_s->interface_removed = 0;
1865 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
1866 if (wpa_supplicant_driver_init(wpa_s) < 0) {
1867 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
1872 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
1873 wpa_s->interface_removed = 1;
1874 wpa_supplicant_mark_disassoc(wpa_s);
1875 l2_packet_deinit(wpa_s->l2);
1876 wpa_s->l2 = NULL;
1878 ibss_rsn_deinit(wpa_s->ibss_rsn);
1879 wpa_s->ibss_rsn = NULL;
1883 if (!any_interfaces(wpa_s->global->ifaces))
1893 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
1898 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
1904 static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
1911 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
1914 wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
1924 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
1930 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
1943 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
1947 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1951 ssid = wpa_s->current_ssid;
1957 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
1963 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
1970 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1979 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
1983 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
1984 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
1990 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
1996 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2004 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2006 wpa_s->sme.freq = bss->freq;
2007 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2008 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2016 static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2024 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2029 static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2037 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2042 static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
2078 wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
2089 struct wpa_supplicant *wpa_s = ctx;
2093 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2097 wpa_dbg(wpa_s, MSG_DEBUG,
2118 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2125 sme_event_auth(wpa_s, data);
2128 wpa_supplicant_event_assoc(wpa_s, data);
2131 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2133 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2138 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2142 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
2143 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2147 if (wpa_s->ap_iface) {
2148 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
2162 wpa_s, data->disassoc_info.addr, reason_code,
2167 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2168 sme_event_disassoc(wpa_s, data);
2172 wpa_dbg(wpa_s, MSG_DEBUG,
2178 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2183 wpa_dbg(wpa_s, MSG_DEBUG, " * address "
2194 wpa_s, data->deauth_info.addr,
2202 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
2203 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
2207 if (wpa_s->ap_iface) {
2208 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
2213 wpa_supplicant_event_disassoc(wpa_s, reason_code,
2217 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2221 wpa_supplicant_event_scan_results(wpa_s, data);
2225 wpa_supplicant_event_associnfo(wpa_s, data);
2228 wpa_supplicant_event_interface_status(wpa_s, data);
2231 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2235 wpa_supplicant_event_stkstart(wpa_s, data);
2240 wpa_supplicant_event_tdls(wpa_s, data);
2245 wpa_supplicant_event_ft_response(wpa_s, data);
2250 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2255 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2260 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2263 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2264 sme_event_assoc_reject(wpa_s, data);
2267 else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
2268 if (!wpa_s->current_ssid) {
2276 if (wpa_s->current_ssid->assoc_retry++ < 5) {
2278 wpa_s->current_ssid->assoc_retry);
2279 wpa_supplicant_cancel_auth_timeout(wpa_s);
2282 wpa_sm_notify_disassoc(wpa_s->wpa);
2283 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2285 wpa_s->reassociate = 1;
2286 wpa_supplicant_req_scan(wpa_s, 1, 0);
2293 wpa_s->current_ssid->assoc_retry = 0;
2294 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
2295 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
2302 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2303 sme_event_auth_timed_out(wpa_s, data);
2306 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2307 sme_event_assoc_timed_out(wpa_s, data);
2310 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2315 if (wpa_s->ap_iface == NULL) {
2320 wpa_s, data->tx_status.dst,
2331 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2332 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2339 os_memcmp(wpa_s->parent->pending_action_dst,
2342 wpa_s->parent, data->tx_status.dst,
2354 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2360 ap_tx_status(wpa_s, data->tx_status.dst,
2370 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2376 ap_client_poll_ok(wpa_s, data->client_poll.addr);
2379 if (wpa_s->ap_iface == NULL)
2381 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2385 if (wpa_s->ap_iface == NULL) {
2400 wpas_p2p_probe_req_rx(wpa_s, src, mgmt->da,
2405 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2409 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
2413 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2420 ft_rx_action(wpa_s, data->rx_action.data,
2428 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2437 gas_query_rx(wpa_s->gas, data->rx_action.da,
2444 wnm_action_rx(wpa_s, &data->rx_action);
2451 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2458 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2471 if (wpa_s->ap_iface) {
2472 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2482 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
2492 wpa_s, data->remain_on_channel.freq,
2497 wpa_s, data->remain_on_channel.freq,
2504 wpa_s, data->remain_on_channel.freq);
2508 wpa_s, data->remain_on_channel.freq);
2536 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
2540 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
2544 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
2547 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
2558 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
2562 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
2570 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
2577 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
2583 wpa_s, data->signal_change.above_threshold,
2589 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
2590 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
2591 wpa_supplicant_update_mac_addr(wpa_s);
2593 if (!wpa_s->ap_iface) {
2594 wpa_supplicant_set_state(wpa_s,
2596 wpa_supplicant_req_scan(wpa_s, 0, 0);
2598 wpa_supplicant_set_state(wpa_s,
2601 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
2602 wpa_supplicant_req_scan(wpa_s, 0, 0);
2607 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
2608 wpa_supplicant_mark_disassoc(wpa_s);
2609 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
2612 if (wpa_s->drv_priv == NULL)
2615 wpas_p2p_update_channel_list(wpa_s);
2620 wpas_p2p_interface_unavailable(wpa_s);
2624 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
2628 wpa_s->best_24_freq = data->best_chan.freq_24;
2629 wpa_s->best_5_freq = data->best_chan.freq_5;
2630 wpa_s->best_overall_freq = data->best_chan.freq_overall;
2632 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
2638 wpa_supplicant_event_unprot_deauth(wpa_s,
2642 wpa_supplicant_event_unprot_disassoc(wpa_s,
2647 if (wpa_s->ap_iface && data)
2648 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
2653 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
2658 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
2663 wpa_s->bssid, ETH_ALEN))
2665 if (!wpa_s->wpa)
2667 wpa_sm_update_replay_ctr(wpa_s->wpa,
2671 wpa_s->sched_scanning = 0;
2672 wpa_supplicant_notify_scanning(wpa_s, 0);
2674 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2681 if (wpa_s->sched_scan_timed_out)
2682 wpa_supplicant_req_sched_scan(wpa_s);
2686 wpas_wps_start_pbc(wpa_s, NULL, 0);
2690 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);