]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant - Driver event processing | |
d12a51b5 | 3 | * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi> |
6fc6879b | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
6fc6879b JM |
7 | */ |
8 | ||
9 | #include "includes.h" | |
10 | ||
11 | #include "common.h" | |
12 | #include "eapol_supp/eapol_supp_sm.h" | |
3acb5005 | 13 | #include "rsn_supp/wpa.h" |
6fc6879b | 14 | #include "eloop.h" |
6fc6879b JM |
15 | #include "config.h" |
16 | #include "l2_packet/l2_packet.h" | |
17 | #include "wpa_supplicant_i.h" | |
2d5b792d | 18 | #include "driver_i.h" |
6fc6879b | 19 | #include "pcsc_funcs.h" |
3acb5005 JM |
20 | #include "rsn_supp/preauth.h" |
21 | #include "rsn_supp/pmksa_cache.h" | |
90973fb2 | 22 | #include "common/wpa_ctrl.h" |
6fc6879b | 23 | #include "eap_peer/eap.h" |
1d041bec | 24 | #include "ap/hostapd.h" |
93b7ddd0 | 25 | #include "p2p/p2p.h" |
75cad1a0 | 26 | #include "wnm_sta.h" |
8bac466b | 27 | #include "notify.h" |
90973fb2 | 28 | #include "common/ieee802_11_defs.h" |
54f489be | 29 | #include "common/ieee802_11_common.h" |
bbb921da | 30 | #include "crypto/random.h" |
6fc6879b JM |
31 | #include "blacklist.h" |
32 | #include "wpas_glue.h" | |
351f09a2 | 33 | #include "wps_supplicant.h" |
11ef8d35 | 34 | #include "ibss_rsn.h" |
c2a04078 | 35 | #include "sme.h" |
04ea7b79 | 36 | #include "gas_query.h" |
9bae1be0 | 37 | #include "p2p_supplicant.h" |
60b94c98 | 38 | #include "bgscan.h" |
7c865c68 | 39 | #include "autoscan.h" |
f8b1f695 | 40 | #include "ap.h" |
6fa81a3b | 41 | #include "bss.h" |
9ba9fa07 | 42 | #include "scan.h" |
24f6497c | 43 | #include "offchannel.h" |
4d5bda5f | 44 | #include "interworking.h" |
8319e312 | 45 | #include "mesh.h" |
5f92659d | 46 | #include "mesh_mpm.h" |
a0413b17 | 47 | #include "wmm_ac.h" |
6fc6879b JM |
48 | |
49 | ||
5d5c4ee5 | 50 | #ifndef CONFIG_NO_SCAN_PROCESSING |
06b7f58d | 51 | static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, |
cc4952ad | 52 | int new_scan, int own_request); |
5d5c4ee5 | 53 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
d6bbcce4 JM |
54 | |
55 | ||
00e5e3d5 JM |
56 | static int wpas_temp_disabled(struct wpa_supplicant *wpa_s, |
57 | struct wpa_ssid *ssid) | |
58 | { | |
4e1eae1d | 59 | struct os_reltime now; |
00e5e3d5 JM |
60 | |
61 | if (ssid == NULL || ssid->disabled_until.sec == 0) | |
62 | return 0; | |
63 | ||
4e1eae1d | 64 | os_get_reltime(&now); |
00e5e3d5 JM |
65 | if (ssid->disabled_until.sec > now.sec) |
66 | return ssid->disabled_until.sec - now.sec; | |
67 | ||
68 | wpas_clear_temp_disabled(wpa_s, ssid, 0); | |
69 | ||
70 | return 0; | |
71 | } | |
72 | ||
73 | ||
5cd47405 JM |
74 | static struct wpa_bss * wpa_supplicant_get_new_bss( |
75 | struct wpa_supplicant *wpa_s, const u8 *bssid) | |
76 | { | |
77 | struct wpa_bss *bss = NULL; | |
78 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
79 | ||
80 | if (ssid->ssid_len > 0) | |
81 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); | |
82 | if (!bss) | |
83 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
84 | ||
85 | return bss; | |
86 | } | |
87 | ||
88 | ||
068e3877 JM |
89 | static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s) |
90 | { | |
91 | struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid); | |
92 | ||
93 | if (!bss) { | |
94 | wpa_supplicant_update_scan_results(wpa_s); | |
95 | ||
96 | /* Get the BSS from the new scan results */ | |
97 | bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid); | |
98 | } | |
99 | ||
100 | if (bss) | |
101 | wpa_s->current_bss = bss; | |
102 | } | |
103 | ||
104 | ||
6fc6879b JM |
105 | static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s) |
106 | { | |
8bac466b | 107 | struct wpa_ssid *ssid, *old_ssid; |
00e5e3d5 | 108 | int res; |
6fc6879b | 109 | |
068e3877 JM |
110 | if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) { |
111 | wpa_supplicant_update_current_bss(wpa_s); | |
6fc6879b | 112 | return 0; |
068e3877 | 113 | } |
6fc6879b | 114 | |
f049052b BG |
115 | wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association " |
116 | "information"); | |
6fc6879b JM |
117 | ssid = wpa_supplicant_get_ssid(wpa_s); |
118 | if (ssid == NULL) { | |
f049052b BG |
119 | wpa_msg(wpa_s, MSG_INFO, |
120 | "No network configuration found for the current AP"); | |
6fc6879b JM |
121 | return -1; |
122 | } | |
123 | ||
349493bd | 124 | if (wpas_network_disabled(wpa_s, ssid)) { |
f049052b | 125 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled"); |
6fc6879b JM |
126 | return -1; |
127 | } | |
128 | ||
6407f413 JM |
129 | if (disallowed_bssid(wpa_s, wpa_s->bssid) || |
130 | disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) { | |
131 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed"); | |
132 | return -1; | |
133 | } | |
134 | ||
00e5e3d5 JM |
135 | res = wpas_temp_disabled(wpa_s, ssid); |
136 | if (res > 0) { | |
137 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily " | |
138 | "disabled for %d second(s)", res); | |
139 | return -1; | |
140 | } | |
141 | ||
f049052b BG |
142 | wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the " |
143 | "current AP"); | |
0bf927a0 | 144 | if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { |
6fc6879b JM |
145 | u8 wpa_ie[80]; |
146 | size_t wpa_ie_len = sizeof(wpa_ie); | |
cbf61176 JM |
147 | if (wpa_supplicant_set_suites(wpa_s, NULL, ssid, |
148 | wpa_ie, &wpa_ie_len) < 0) | |
149 | wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites"); | |
6fc6879b JM |
150 | } else { |
151 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
152 | } | |
153 | ||
154 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) | |
155 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
8bac466b | 156 | old_ssid = wpa_s->current_ssid; |
6fc6879b | 157 | wpa_s->current_ssid = ssid; |
5cd47405 | 158 | |
068e3877 | 159 | wpa_supplicant_update_current_bss(wpa_s); |
5cd47405 | 160 | |
6fc6879b JM |
161 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); |
162 | wpa_supplicant_initiate_eapol(wpa_s); | |
8bac466b JM |
163 | if (old_ssid != wpa_s->current_ssid) |
164 | wpas_notify_network_changed(wpa_s); | |
6fc6879b JM |
165 | |
166 | return 0; | |
167 | } | |
168 | ||
169 | ||
01a17491 | 170 | void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx) |
6fc6879b JM |
171 | { |
172 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
173 | ||
174 | if (wpa_s->countermeasures) { | |
175 | wpa_s->countermeasures = 0; | |
176 | wpa_drv_set_countermeasures(wpa_s, 0); | |
177 | wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped"); | |
178 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
179 | } | |
180 | } | |
181 | ||
182 | ||
183 | void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) | |
184 | { | |
8bac466b JM |
185 | int bssid_changed; |
186 | ||
b6668734 JM |
187 | wnm_bss_keep_alive_deinit(wpa_s); |
188 | ||
78177a00 JM |
189 | #ifdef CONFIG_IBSS_RSN |
190 | ibss_rsn_deinit(wpa_s->ibss_rsn); | |
191 | wpa_s->ibss_rsn = NULL; | |
192 | #endif /* CONFIG_IBSS_RSN */ | |
193 | ||
ca62e114 JM |
194 | #ifdef CONFIG_AP |
195 | wpa_supplicant_ap_deinit(wpa_s); | |
196 | #endif /* CONFIG_AP */ | |
197 | ||
8401a6b0 JM |
198 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
199 | return; | |
200 | ||
6fc6879b | 201 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
8bac466b | 202 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
6fc6879b JM |
203 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
204 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
4e70bbf1 | 205 | sme_clear_on_disassoc(wpa_s); |
b1aebbc4 JM |
206 | #ifdef CONFIG_P2P |
207 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); | |
208 | #endif /* CONFIG_P2P */ | |
be8be671 | 209 | wpa_s->current_bss = NULL; |
3c85f144 | 210 | wpa_s->assoc_freq = 0; |
8fd0f0f3 | 211 | |
8bac466b JM |
212 | if (bssid_changed) |
213 | wpas_notify_bssid_changed(wpa_s); | |
214 | ||
6fc6879b JM |
215 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); |
216 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
56586197 | 217 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) |
6fc6879b JM |
218 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
219 | wpa_s->ap_ies_from_associnfo = 0; | |
0d30cc24 | 220 | wpa_s->current_ssid = NULL; |
25a8f9e3 | 221 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
0d30cc24 | 222 | wpa_s->key_mgmt = 0; |
b361d580 AK |
223 | |
224 | wpas_rrm_reset(wpa_s); | |
6fc6879b JM |
225 | } |
226 | ||
227 | ||
228 | static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s) | |
229 | { | |
230 | struct wpa_ie_data ie; | |
231 | int pmksa_set = -1; | |
232 | size_t i; | |
233 | ||
234 | if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 || | |
235 | ie.pmkid == NULL) | |
236 | return; | |
237 | ||
238 | for (i = 0; i < ie.num_pmkid; i++) { | |
239 | pmksa_set = pmksa_cache_set_current(wpa_s->wpa, | |
240 | ie.pmkid + i * PMKID_LEN, | |
241 | NULL, NULL, 0); | |
242 | if (pmksa_set == 0) { | |
243 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1); | |
244 | break; | |
245 | } | |
246 | } | |
247 | ||
f049052b BG |
248 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from " |
249 | "PMKSA cache", pmksa_set == 0 ? "" : "not "); | |
6fc6879b JM |
250 | } |
251 | ||
252 | ||
253 | static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s, | |
254 | union wpa_event_data *data) | |
255 | { | |
256 | if (data == NULL) { | |
f049052b BG |
257 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate " |
258 | "event"); | |
6fc6879b JM |
259 | return; |
260 | } | |
f049052b BG |
261 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR |
262 | " index=%d preauth=%d", | |
263 | MAC2STR(data->pmkid_candidate.bssid), | |
264 | data->pmkid_candidate.index, | |
265 | data->pmkid_candidate.preauth); | |
6fc6879b JM |
266 | |
267 | pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid, | |
268 | data->pmkid_candidate.index, | |
269 | data->pmkid_candidate.preauth); | |
270 | } | |
271 | ||
272 | ||
273 | static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s) | |
274 | { | |
275 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
276 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) | |
277 | return 0; | |
278 | ||
279 | #ifdef IEEE8021X_EAPOL | |
280 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA && | |
281 | wpa_s->current_ssid && | |
282 | !(wpa_s->current_ssid->eapol_flags & | |
283 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
284 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) { | |
285 | /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either | |
286 | * plaintext or static WEP keys). */ | |
287 | return 0; | |
288 | } | |
289 | #endif /* IEEE8021X_EAPOL */ | |
290 | ||
291 | return 1; | |
292 | } | |
293 | ||
294 | ||
295 | /** | |
296 | * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC | |
297 | * @wpa_s: pointer to wpa_supplicant data | |
298 | * @ssid: Configuration data for the network | |
299 | * Returns: 0 on success, -1 on failure | |
300 | * | |
301 | * This function is called when starting authentication with a network that is | |
302 | * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA). | |
303 | */ | |
304 | int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s, | |
305 | struct wpa_ssid *ssid) | |
306 | { | |
307 | #ifdef IEEE8021X_EAPOL | |
b832d34c | 308 | #ifdef PCSC_FUNCS |
eb324600 | 309 | int aka = 0, sim = 0; |
6fc6879b | 310 | |
62f736dd JT |
311 | if ((ssid != NULL && ssid->eap.pcsc == NULL) || |
312 | wpa_s->scard != NULL || wpa_s->conf->external_sim) | |
6fc6879b JM |
313 | return 0; |
314 | ||
62f736dd | 315 | if (ssid == NULL || ssid->eap.eap_methods == NULL) { |
6fc6879b JM |
316 | sim = 1; |
317 | aka = 1; | |
318 | } else { | |
319 | struct eap_method_type *eap = ssid->eap.eap_methods; | |
320 | while (eap->vendor != EAP_VENDOR_IETF || | |
321 | eap->method != EAP_TYPE_NONE) { | |
322 | if (eap->vendor == EAP_VENDOR_IETF) { | |
323 | if (eap->method == EAP_TYPE_SIM) | |
324 | sim = 1; | |
3d332fe7 JM |
325 | else if (eap->method == EAP_TYPE_AKA || |
326 | eap->method == EAP_TYPE_AKA_PRIME) | |
6fc6879b JM |
327 | aka = 1; |
328 | } | |
329 | eap++; | |
330 | } | |
331 | } | |
332 | ||
333 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL) | |
334 | sim = 0; | |
3d332fe7 JM |
335 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL && |
336 | eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) == | |
337 | NULL) | |
6fc6879b JM |
338 | aka = 0; |
339 | ||
340 | if (!sim && !aka) { | |
f049052b BG |
341 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to " |
342 | "use SIM, but neither EAP-SIM nor EAP-AKA are " | |
343 | "enabled"); | |
6fc6879b JM |
344 | return 0; |
345 | } | |
346 | ||
f049052b BG |
347 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM " |
348 | "(sim=%d aka=%d) - initialize PCSC", sim, aka); | |
eb324600 | 349 | |
5a620604 | 350 | wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader); |
6fc6879b | 351 | if (wpa_s->scard == NULL) { |
f049052b BG |
352 | wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM " |
353 | "(pcsc-lite)"); | |
6fc6879b JM |
354 | return -1; |
355 | } | |
356 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); | |
357 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); | |
b832d34c | 358 | #endif /* PCSC_FUNCS */ |
6fc6879b JM |
359 | #endif /* IEEE8021X_EAPOL */ |
360 | ||
361 | return 0; | |
362 | } | |
363 | ||
364 | ||
365 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
86bd1410 JM |
366 | |
367 | static int has_wep_key(struct wpa_ssid *ssid) | |
368 | { | |
369 | int i; | |
370 | ||
371 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
372 | if (ssid->wep_key_len[i]) | |
373 | return 1; | |
374 | } | |
375 | ||
376 | return 0; | |
377 | } | |
378 | ||
379 | ||
620c7837 | 380 | static int wpa_supplicant_match_privacy(struct wpa_bss *bss, |
6fc6879b JM |
381 | struct wpa_ssid *ssid) |
382 | { | |
86bd1410 | 383 | int privacy = 0; |
6fc6879b JM |
384 | |
385 | if (ssid->mixed_cell) | |
386 | return 1; | |
387 | ||
0632542b AT |
388 | #ifdef CONFIG_WPS |
389 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) | |
390 | return 1; | |
391 | #endif /* CONFIG_WPS */ | |
392 | ||
86bd1410 JM |
393 | if (has_wep_key(ssid)) |
394 | privacy = 1; | |
395 | ||
6fc6879b JM |
396 | #ifdef IEEE8021X_EAPOL |
397 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
398 | ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
399 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) | |
400 | privacy = 1; | |
401 | #endif /* IEEE8021X_EAPOL */ | |
402 | ||
29fbc522 JM |
403 | if (wpa_key_mgmt_wpa(ssid->key_mgmt)) |
404 | privacy = 1; | |
405 | ||
df0f01d9 JM |
406 | if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN) |
407 | privacy = 1; | |
408 | ||
6fc6879b JM |
409 | if (bss->caps & IEEE80211_CAP_PRIVACY) |
410 | return privacy; | |
411 | return !privacy; | |
412 | } | |
413 | ||
414 | ||
a6099152 JM |
415 | static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, |
416 | struct wpa_ssid *ssid, | |
620c7837 | 417 | struct wpa_bss *bss) |
6fc6879b JM |
418 | { |
419 | struct wpa_ie_data ie; | |
420 | int proto_match = 0; | |
421 | const u8 *rsn_ie, *wpa_ie; | |
351f09a2 | 422 | int ret; |
43882f1e | 423 | int wep_ok; |
6fc6879b | 424 | |
a6099152 | 425 | ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); |
351f09a2 JM |
426 | if (ret >= 0) |
427 | return ret; | |
ad08c363 | 428 | |
43882f1e JM |
429 | /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */ |
430 | wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) && | |
431 | (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) && | |
432 | ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) || | |
433 | (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)); | |
434 | ||
620c7837 | 435 | rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
6fc6879b JM |
436 | while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) { |
437 | proto_match++; | |
438 | ||
439 | if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { | |
f049052b BG |
440 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse " |
441 | "failed"); | |
6fc6879b JM |
442 | break; |
443 | } | |
43882f1e JM |
444 | |
445 | if (wep_ok && | |
446 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
447 | { | |
f049052b BG |
448 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " |
449 | "in RSN IE"); | |
43882f1e JM |
450 | return 1; |
451 | } | |
452 | ||
6fc6879b | 453 | if (!(ie.proto & ssid->proto)) { |
f049052b BG |
454 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto " |
455 | "mismatch"); | |
6fc6879b JM |
456 | break; |
457 | } | |
458 | ||
459 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
f049052b BG |
460 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK " |
461 | "cipher mismatch"); | |
6fc6879b JM |
462 | break; |
463 | } | |
464 | ||
465 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
f049052b BG |
466 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK " |
467 | "cipher mismatch"); | |
6fc6879b JM |
468 | break; |
469 | } | |
470 | ||
471 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
f049052b BG |
472 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt " |
473 | "mismatch"); | |
6fc6879b JM |
474 | break; |
475 | } | |
476 | ||
477 | #ifdef CONFIG_IEEE80211W | |
0b60b0aa | 478 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
62d49803 JM |
479 | (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ? |
480 | wpa_s->conf->pmf : ssid->ieee80211w) == | |
481 | MGMT_FRAME_PROTECTION_REQUIRED) { | |
f049052b BG |
482 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt " |
483 | "frame protection"); | |
6fc6879b JM |
484 | break; |
485 | } | |
486 | #endif /* CONFIG_IEEE80211W */ | |
487 | ||
f049052b | 488 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE"); |
6fc6879b JM |
489 | return 1; |
490 | } | |
491 | ||
620c7837 | 492 | wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
6fc6879b JM |
493 | while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { |
494 | proto_match++; | |
495 | ||
496 | if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { | |
f049052b BG |
497 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse " |
498 | "failed"); | |
6fc6879b JM |
499 | break; |
500 | } | |
43882f1e JM |
501 | |
502 | if (wep_ok && | |
503 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
504 | { | |
f049052b BG |
505 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " |
506 | "in WPA IE"); | |
43882f1e JM |
507 | return 1; |
508 | } | |
509 | ||
6fc6879b | 510 | if (!(ie.proto & ssid->proto)) { |
f049052b BG |
511 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto " |
512 | "mismatch"); | |
6fc6879b JM |
513 | break; |
514 | } | |
515 | ||
516 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
f049052b BG |
517 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK " |
518 | "cipher mismatch"); | |
6fc6879b JM |
519 | break; |
520 | } | |
521 | ||
522 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
f049052b BG |
523 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK " |
524 | "cipher mismatch"); | |
6fc6879b JM |
525 | break; |
526 | } | |
527 | ||
528 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
f049052b BG |
529 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt " |
530 | "mismatch"); | |
6fc6879b JM |
531 | break; |
532 | } | |
533 | ||
f049052b | 534 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE"); |
6fc6879b JM |
535 | return 1; |
536 | } | |
537 | ||
a3f7e518 JM |
538 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie && |
539 | !rsn_ie) { | |
540 | wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X"); | |
541 | return 1; | |
542 | } | |
543 | ||
cc5e390d | 544 | if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) && |
df83fb7d | 545 | wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) { |
f049052b | 546 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match"); |
cc5e390d JM |
547 | return 0; |
548 | } | |
6fc6879b | 549 | |
df0f01d9 JM |
550 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && |
551 | wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) { | |
552 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN"); | |
553 | return 1; | |
554 | } | |
555 | ||
c2f1fe41 JM |
556 | if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
557 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2"); | |
558 | return 1; | |
559 | } | |
560 | ||
561 | wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with " | |
562 | "WPA/WPA2"); | |
563 | ||
564 | return 0; | |
6fc6879b JM |
565 | } |
566 | ||
567 | ||
b766a9a2 JM |
568 | static int freq_allowed(int *freqs, int freq) |
569 | { | |
570 | int i; | |
571 | ||
572 | if (freqs == NULL) | |
573 | return 1; | |
574 | ||
575 | for (i = 0; freqs[i]; i++) | |
576 | if (freqs[i] == freq) | |
577 | return 1; | |
578 | return 0; | |
579 | } | |
580 | ||
581 | ||
620c7837 | 582 | static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
e1e8cae3 CL |
583 | { |
584 | const struct hostapd_hw_modes *mode = NULL, *modes; | |
585 | const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES }; | |
586 | const u8 *rate_ie; | |
587 | int i, j, k; | |
588 | ||
a6d94e1b JM |
589 | if (bss->freq == 0) |
590 | return 1; /* Cannot do matching without knowing band */ | |
591 | ||
e1e8cae3 CL |
592 | modes = wpa_s->hw.modes; |
593 | if (modes == NULL) { | |
594 | /* | |
595 | * The driver does not provide any additional information | |
596 | * about the utilized hardware, so allow the connection attempt | |
597 | * to continue. | |
598 | */ | |
599 | return 1; | |
600 | } | |
601 | ||
602 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
603 | for (j = 0; j < modes[i].num_channels; j++) { | |
604 | int freq = modes[i].channels[j].freq; | |
605 | if (freq == bss->freq) { | |
606 | if (mode && | |
607 | mode->mode == HOSTAPD_MODE_IEEE80211G) | |
608 | break; /* do not allow 802.11b replace | |
609 | * 802.11g */ | |
610 | mode = &modes[i]; | |
611 | break; | |
612 | } | |
613 | } | |
614 | } | |
615 | ||
616 | if (mode == NULL) | |
617 | return 0; | |
618 | ||
619 | for (i = 0; i < (int) sizeof(scan_ie); i++) { | |
620c7837 | 620 | rate_ie = wpa_bss_get_ie(bss, scan_ie[i]); |
e1e8cae3 CL |
621 | if (rate_ie == NULL) |
622 | continue; | |
623 | ||
624 | for (j = 2; j < rate_ie[1] + 2; j++) { | |
625 | int flagged = !!(rate_ie[j] & 0x80); | |
626 | int r = (rate_ie[j] & 0x7f) * 5; | |
627 | ||
628 | /* | |
629 | * IEEE Std 802.11n-2009 7.3.2.2: | |
630 | * The new BSS Membership selector value is encoded | |
631 | * like a legacy basic rate, but it is not a rate and | |
632 | * only indicates if the BSS members are required to | |
633 | * support the mandatory features of Clause 20 [HT PHY] | |
634 | * in order to join the BSS. | |
635 | */ | |
636 | if (flagged && ((rate_ie[j] & 0x7f) == | |
637 | BSS_MEMBERSHIP_SELECTOR_HT_PHY)) { | |
638 | if (!ht_supported(mode)) { | |
639 | wpa_dbg(wpa_s, MSG_DEBUG, | |
640 | " hardware does not support " | |
641 | "HT PHY"); | |
642 | return 0; | |
643 | } | |
644 | continue; | |
645 | } | |
646 | ||
c8ebeda4 MK |
647 | /* There's also a VHT selector for 802.11ac */ |
648 | if (flagged && ((rate_ie[j] & 0x7f) == | |
649 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) { | |
650 | if (!vht_supported(mode)) { | |
651 | wpa_dbg(wpa_s, MSG_DEBUG, | |
652 | " hardware does not support " | |
653 | "VHT PHY"); | |
654 | return 0; | |
655 | } | |
656 | continue; | |
657 | } | |
658 | ||
e1e8cae3 CL |
659 | if (!flagged) |
660 | continue; | |
661 | ||
662 | /* check for legacy basic rates */ | |
663 | for (k = 0; k < mode->num_rates; k++) { | |
664 | if (mode->rates[k] == r) | |
665 | break; | |
666 | } | |
667 | if (k == mode->num_rates) { | |
668 | /* | |
669 | * IEEE Std 802.11-2007 7.3.2.2 demands that in | |
670 | * order to join a BSS all required rates | |
671 | * have to be supported by the hardware. | |
672 | */ | |
673 | wpa_dbg(wpa_s, MSG_DEBUG, " hardware does " | |
674 | "not support required rate %d.%d Mbps", | |
675 | r / 10, r % 10); | |
676 | return 0; | |
677 | } | |
678 | } | |
679 | } | |
680 | ||
681 | return 1; | |
682 | } | |
683 | ||
684 | ||
ff3ad3c5 VK |
685 | /* |
686 | * Test whether BSS is in an ESS. | |
687 | * This is done differently in DMG (60 GHz) and non-DMG bands | |
688 | */ | |
689 | static int bss_is_ess(struct wpa_bss *bss) | |
690 | { | |
691 | if (bss_is_dmg(bss)) { | |
692 | return (bss->caps & IEEE80211_CAP_DMG_MASK) == | |
693 | IEEE80211_CAP_DMG_AP; | |
694 | } | |
695 | ||
696 | return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) == | |
697 | IEEE80211_CAP_ESS); | |
698 | } | |
699 | ||
700 | ||
79cd993a ST |
701 | static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask) |
702 | { | |
703 | size_t i; | |
704 | ||
705 | for (i = 0; i < ETH_ALEN; i++) { | |
706 | if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i])) | |
707 | return 0; | |
708 | } | |
709 | return 1; | |
710 | } | |
711 | ||
712 | ||
b83e4554 ST |
713 | static int addr_in_list(const u8 *addr, const u8 *list, size_t num) |
714 | { | |
715 | size_t i; | |
716 | ||
717 | for (i = 0; i < num; i++) { | |
79cd993a ST |
718 | const u8 *a = list + i * ETH_ALEN * 2; |
719 | const u8 *m = a + ETH_ALEN; | |
b83e4554 | 720 | |
79cd993a | 721 | if (match_mac_mask(a, addr, m)) |
b83e4554 ST |
722 | return 1; |
723 | } | |
724 | return 0; | |
725 | } | |
726 | ||
727 | ||
d8d940b7 | 728 | static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s, |
620c7837 | 729 | int i, struct wpa_bss *bss, |
3d910ef4 JM |
730 | struct wpa_ssid *group, |
731 | int only_first_ssid) | |
6fc6879b | 732 | { |
620c7837 | 733 | u8 wpa_ie_len, rsn_ie_len; |
d8d940b7 | 734 | int wpa; |
6fc6879b JM |
735 | struct wpa_blacklist *e; |
736 | const u8 *ie; | |
d8d940b7 | 737 | struct wpa_ssid *ssid; |
df0f01d9 | 738 | int osen; |
6fc6879b | 739 | |
620c7837 | 740 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
d8d940b7 | 741 | wpa_ie_len = ie ? ie[1] : 0; |
6fc6879b | 742 | |
620c7837 | 743 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
d8d940b7 | 744 | rsn_ie_len = ie ? ie[1] : 0; |
6fc6879b | 745 | |
df0f01d9 JM |
746 | ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
747 | osen = ie != NULL; | |
748 | ||
f049052b | 749 | wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' " |
df0f01d9 | 750 | "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s", |
620c7837 | 751 | i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len), |
f049052b | 752 | wpa_ie_len, rsn_ie_len, bss->caps, bss->level, |
b16696ff JM |
753 | wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "", |
754 | (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || | |
755 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ? | |
df0f01d9 JM |
756 | " p2p" : "", |
757 | osen ? " osen=1" : ""); | |
9cf32261 | 758 | |
d8d940b7 | 759 | e = wpa_blacklist_get(wpa_s, bss->bssid); |
5471c343 JM |
760 | if (e) { |
761 | int limit = 1; | |
349493bd | 762 | if (wpa_supplicant_enabled_networks(wpa_s) == 1) { |
5471c343 JM |
763 | /* |
764 | * When only a single network is enabled, we can | |
765 | * trigger blacklisting on the first failure. This | |
766 | * should not be done with multiple enabled networks to | |
767 | * avoid getting forced to move into a worse ESS on | |
768 | * single error if there are no other BSSes of the | |
769 | * current ESS. | |
770 | */ | |
771 | limit = 0; | |
772 | } | |
773 | if (e->count > limit) { | |
f049052b BG |
774 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " |
775 | "(count=%d limit=%d)", e->count, limit); | |
c2197bc9 | 776 | return NULL; |
5471c343 | 777 | } |
d8d940b7 | 778 | } |
6fc6879b | 779 | |
620c7837 | 780 | if (bss->ssid_len == 0) { |
f049052b | 781 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known"); |
c2197bc9 | 782 | return NULL; |
d8d940b7 | 783 | } |
e81634cd | 784 | |
6407f413 JM |
785 | if (disallowed_bssid(wpa_s, bss->bssid)) { |
786 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed"); | |
787 | return NULL; | |
788 | } | |
789 | ||
790 | if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) { | |
791 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed"); | |
792 | return NULL; | |
793 | } | |
794 | ||
d8d940b7 | 795 | wpa = wpa_ie_len > 0 || rsn_ie_len > 0; |
6fc6879b | 796 | |
3d910ef4 | 797 | for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) { |
d8d940b7 | 798 | int check_ssid = wpa ? 1 : (ssid->ssid_len != 0); |
00e5e3d5 | 799 | int res; |
ad08c363 | 800 | |
349493bd | 801 | if (wpas_network_disabled(wpa_s, ssid)) { |
f049052b | 802 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled"); |
0c703df3 | 803 | continue; |
d8d940b7 | 804 | } |
9cf32261 | 805 | |
00e5e3d5 JM |
806 | res = wpas_temp_disabled(wpa_s, ssid); |
807 | if (res > 0) { | |
808 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled " | |
809 | "temporarily for %d second(s)", res); | |
810 | continue; | |
811 | } | |
812 | ||
ad08c363 | 813 | #ifdef CONFIG_WPS |
f648bc7d | 814 | if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) { |
f049052b BG |
815 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " |
816 | "(WPS)"); | |
f648bc7d JM |
817 | continue; |
818 | } | |
819 | ||
d8d940b7 JM |
820 | if (wpa && ssid->ssid_len == 0 && |
821 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) | |
822 | check_ssid = 0; | |
823 | ||
824 | if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { | |
825 | /* Only allow wildcard SSID match if an AP | |
826 | * advertises active WPS operation that matches | |
827 | * with our mode. */ | |
828 | check_ssid = 1; | |
ad08c363 | 829 | if (ssid->ssid_len == 0 && |
a6099152 | 830 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) |
ad08c363 | 831 | check_ssid = 0; |
d8d940b7 | 832 | } |
ad08c363 JM |
833 | #endif /* CONFIG_WPS */ |
834 | ||
7d232e23 ZC |
835 | if (ssid->bssid_set && ssid->ssid_len == 0 && |
836 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0) | |
837 | check_ssid = 0; | |
838 | ||
d8d940b7 | 839 | if (check_ssid && |
620c7837 JM |
840 | (bss->ssid_len != ssid->ssid_len || |
841 | os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) { | |
f049052b | 842 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch"); |
0c703df3 | 843 | continue; |
6fc6879b | 844 | } |
6fc6879b | 845 | |
d8d940b7 JM |
846 | if (ssid->bssid_set && |
847 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) { | |
f049052b | 848 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch"); |
0c703df3 | 849 | continue; |
d8d940b7 | 850 | } |
6fc6879b | 851 | |
b83e4554 ST |
852 | /* check blacklist */ |
853 | if (ssid->num_bssid_blacklist && | |
854 | addr_in_list(bss->bssid, ssid->bssid_blacklist, | |
855 | ssid->num_bssid_blacklist)) { | |
856 | wpa_dbg(wpa_s, MSG_DEBUG, | |
857 | " skip - BSSID blacklisted"); | |
858 | continue; | |
859 | } | |
860 | ||
861 | /* if there is a whitelist, only accept those APs */ | |
862 | if (ssid->num_bssid_whitelist && | |
863 | !addr_in_list(bss->bssid, ssid->bssid_whitelist, | |
864 | ssid->num_bssid_whitelist)) { | |
865 | wpa_dbg(wpa_s, MSG_DEBUG, | |
866 | " skip - BSSID not in whitelist"); | |
867 | continue; | |
868 | } | |
869 | ||
cc5e390d | 870 | if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss)) |
0c703df3 | 871 | continue; |
9cf32261 | 872 | |
df0f01d9 | 873 | if (!osen && !wpa && |
d8d940b7 JM |
874 | !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) && |
875 | !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) && | |
876 | !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) { | |
f049052b BG |
877 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network " |
878 | "not allowed"); | |
0c703df3 | 879 | continue; |
6fc6879b | 880 | } |
9cf32261 | 881 | |
86bd1410 JM |
882 | if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && |
883 | has_wep_key(ssid)) { | |
884 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block"); | |
885 | continue; | |
886 | } | |
887 | ||
df0f01d9 JM |
888 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) { |
889 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network " | |
890 | "not allowed"); | |
891 | continue; | |
892 | } | |
893 | ||
29fbc522 | 894 | if (!wpa_supplicant_match_privacy(bss, ssid)) { |
f049052b BG |
895 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy " |
896 | "mismatch"); | |
0c703df3 | 897 | continue; |
e81634cd JM |
898 | } |
899 | ||
ff3ad3c5 VK |
900 | if (!bss_is_ess(bss)) { |
901 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network"); | |
0c703df3 | 902 | continue; |
d8d940b7 | 903 | } |
b766a9a2 | 904 | |
d8d940b7 | 905 | if (!freq_allowed(ssid->freq_list, bss->freq)) { |
f049052b BG |
906 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not " |
907 | "allowed"); | |
0c703df3 | 908 | continue; |
6fc6879b | 909 | } |
d8d940b7 | 910 | |
e1e8cae3 CL |
911 | if (!rate_match(wpa_s, bss)) { |
912 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do " | |
913 | "not match"); | |
914 | continue; | |
915 | } | |
916 | ||
73e49269 | 917 | #ifdef CONFIG_P2P |
b72e14e5 JM |
918 | if (ssid->p2p_group && |
919 | !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) && | |
920 | !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { | |
921 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen"); | |
922 | continue; | |
923 | } | |
924 | ||
9ec87666 JM |
925 | if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) { |
926 | struct wpabuf *p2p_ie; | |
927 | u8 dev_addr[ETH_ALEN]; | |
928 | ||
929 | ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); | |
930 | if (ie == NULL) { | |
931 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element"); | |
932 | continue; | |
933 | } | |
934 | p2p_ie = wpa_bss_get_vendor_ie_multi( | |
935 | bss, P2P_IE_VENDOR_TYPE); | |
936 | if (p2p_ie == NULL) { | |
937 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element"); | |
938 | continue; | |
939 | } | |
940 | ||
941 | if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 | |
942 | || os_memcmp(dev_addr, ssid->go_p2p_dev_addr, | |
943 | ETH_ALEN) != 0) { | |
944 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element"); | |
945 | wpabuf_free(p2p_ie); | |
946 | continue; | |
947 | } | |
948 | wpabuf_free(p2p_ie); | |
949 | } | |
950 | ||
73e49269 JM |
951 | /* |
952 | * TODO: skip the AP if its P2P IE has Group Formation | |
953 | * bit set in the P2P Group Capability Bitmap and we | |
954 | * are not in Group Formation with that device. | |
955 | */ | |
956 | #endif /* CONFIG_P2P */ | |
957 | ||
d8d940b7 JM |
958 | /* Matching configuration found */ |
959 | return ssid; | |
6fc6879b JM |
960 | } |
961 | ||
d8d940b7 | 962 | /* No matching configuration found */ |
c2197bc9 | 963 | return NULL; |
9cf32261 JM |
964 | } |
965 | ||
966 | ||
6fa81a3b | 967 | static struct wpa_bss * |
a1fd2ce5 | 968 | wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, |
a1fd2ce5 | 969 | struct wpa_ssid *group, |
3d910ef4 JM |
970 | struct wpa_ssid **selected_ssid, |
971 | int only_first_ssid) | |
9cf32261 | 972 | { |
620c7837 | 973 | unsigned int i; |
9cf32261 | 974 | |
3d910ef4 JM |
975 | if (only_first_ssid) |
976 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d", | |
977 | group->id); | |
978 | else | |
979 | wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d", | |
980 | group->priority); | |
9cf32261 | 981 | |
620c7837 JM |
982 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
983 | struct wpa_bss *bss = wpa_s->last_scan_res[i]; | |
3d910ef4 JM |
984 | *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group, |
985 | only_first_ssid); | |
d8d940b7 JM |
986 | if (!*selected_ssid) |
987 | continue; | |
f049052b BG |
988 | wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR |
989 | " ssid='%s'", | |
620c7837 JM |
990 | MAC2STR(bss->bssid), |
991 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); | |
992 | return bss; | |
d8d940b7 JM |
993 | } |
994 | ||
995 | return NULL; | |
6fc6879b JM |
996 | } |
997 | ||
998 | ||
97236cee MH |
999 | struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s, |
1000 | struct wpa_ssid **selected_ssid) | |
6fc6879b | 1001 | { |
6fa81a3b | 1002 | struct wpa_bss *selected = NULL; |
09b9df4e | 1003 | int prio; |
7c373ac2 | 1004 | struct wpa_ssid *next_ssid = NULL; |
09b9df4e | 1005 | |
620c7837 JM |
1006 | if (wpa_s->last_scan_res == NULL || |
1007 | wpa_s->last_scan_res_used == 0) | |
1008 | return NULL; /* no scan results from last update */ | |
1009 | ||
7c373ac2 JM |
1010 | if (wpa_s->next_ssid) { |
1011 | struct wpa_ssid *ssid; | |
3d910ef4 | 1012 | |
7c373ac2 JM |
1013 | /* check that next_ssid is still valid */ |
1014 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { | |
1015 | if (ssid == wpa_s->next_ssid) | |
1016 | break; | |
1017 | } | |
1018 | next_ssid = ssid; | |
1019 | wpa_s->next_ssid = NULL; | |
1020 | } | |
3d910ef4 | 1021 | |
7c373ac2 JM |
1022 | while (selected == NULL) { |
1023 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
1024 | if (next_ssid && next_ssid->priority == | |
1025 | wpa_s->conf->pssid[prio]->priority) { | |
3d910ef4 | 1026 | selected = wpa_supplicant_select_bss( |
7c373ac2 | 1027 | wpa_s, next_ssid, selected_ssid, 1); |
3d910ef4 JM |
1028 | if (selected) |
1029 | break; | |
1030 | } | |
09b9df4e | 1031 | selected = wpa_supplicant_select_bss( |
620c7837 | 1032 | wpa_s, wpa_s->conf->pssid[prio], |
3d910ef4 | 1033 | selected_ssid, 0); |
09b9df4e JM |
1034 | if (selected) |
1035 | break; | |
1036 | } | |
1037 | ||
8945cc45 BM |
1038 | if (selected == NULL && wpa_s->blacklist && |
1039 | !wpa_s->countermeasures) { | |
f049052b BG |
1040 | wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear " |
1041 | "blacklist and try again"); | |
09b9df4e JM |
1042 | wpa_blacklist_clear(wpa_s); |
1043 | wpa_s->blacklist_cleared++; | |
1044 | } else if (selected == NULL) | |
1045 | break; | |
1046 | } | |
1047 | ||
1048 | return selected; | |
1049 | } | |
1050 | ||
1051 | ||
1052 | static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s, | |
977b1174 | 1053 | int timeout_sec, int timeout_usec) |
09b9df4e | 1054 | { |
349493bd | 1055 | if (!wpa_supplicant_enabled_networks(wpa_s)) { |
4f34d51a SL |
1056 | /* |
1057 | * No networks are enabled; short-circuit request so | |
1058 | * we don't wait timeout seconds before transitioning | |
1059 | * to INACTIVE state. | |
1060 | */ | |
ac06fb12 JM |
1061 | wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request " |
1062 | "since there are no enabled networks"); | |
4f34d51a SL |
1063 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
1064 | return; | |
09b9df4e | 1065 | } |
5cc70322 JM |
1066 | |
1067 | wpa_s->scan_for_connection = 1; | |
977b1174 | 1068 | wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec); |
09b9df4e JM |
1069 | } |
1070 | ||
1071 | ||
5cbd88d9 JJ |
1072 | int wpa_supplicant_connect(struct wpa_supplicant *wpa_s, |
1073 | struct wpa_bss *selected, | |
1074 | struct wpa_ssid *ssid) | |
09b9df4e JM |
1075 | { |
1076 | if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) { | |
1077 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP | |
1078 | "PBC session overlap"); | |
b73bf0a7 | 1079 | #ifdef CONFIG_P2P |
ace0fbdb AS |
1080 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT || |
1081 | wpa_s->p2p_in_provisioning) { | |
1082 | eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb, | |
1083 | wpa_s, NULL); | |
5cbd88d9 | 1084 | return -1; |
ace0fbdb | 1085 | } |
b73bf0a7 | 1086 | #endif /* CONFIG_P2P */ |
199716ad BG |
1087 | |
1088 | #ifdef CONFIG_WPS | |
7736f18b | 1089 | wpas_wps_cancel(wpa_s); |
199716ad | 1090 | #endif /* CONFIG_WPS */ |
5cbd88d9 | 1091 | return -1; |
09b9df4e JM |
1092 | } |
1093 | ||
b0680017 JM |
1094 | wpa_msg(wpa_s, MSG_DEBUG, |
1095 | "Considering connect request: reassociate: %d selected: " | |
1096 | MACSTR " bssid: " MACSTR " pending: " MACSTR | |
1097 | " wpa_state: %s ssid=%p current_ssid=%p", | |
1098 | wpa_s->reassociate, MAC2STR(selected->bssid), | |
1099 | MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), | |
1100 | wpa_supplicant_state_txt(wpa_s->wpa_state), | |
1101 | ssid, wpa_s->current_ssid); | |
1102 | ||
09b9df4e JM |
1103 | /* |
1104 | * Do not trigger new association unless the BSSID has changed or if | |
1105 | * reassociation is requested. If we are in process of associating with | |
1106 | * the selected BSSID, do not trigger new attempt. | |
1107 | */ | |
1108 | if (wpa_s->reassociate || | |
1109 | (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 && | |
e29853bb BG |
1110 | ((wpa_s->wpa_state != WPA_ASSOCIATING && |
1111 | wpa_s->wpa_state != WPA_AUTHENTICATING) || | |
b0680017 JM |
1112 | (!is_zero_ether_addr(wpa_s->pending_bssid) && |
1113 | os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) != | |
1114 | 0) || | |
1115 | (is_zero_ether_addr(wpa_s->pending_bssid) && | |
1116 | ssid != wpa_s->current_ssid)))) { | |
09b9df4e | 1117 | if (wpa_supplicant_scard_init(wpa_s, ssid)) { |
977b1174 | 1118 | wpa_supplicant_req_new_scan(wpa_s, 10, 0); |
5cbd88d9 | 1119 | return 0; |
09b9df4e | 1120 | } |
b0680017 JM |
1121 | wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR, |
1122 | MAC2STR(selected->bssid)); | |
09b9df4e JM |
1123 | wpa_supplicant_associate(wpa_s, selected, ssid); |
1124 | } else { | |
b0680017 JM |
1125 | wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to " |
1126 | "connect with the selected AP"); | |
09b9df4e | 1127 | } |
5cbd88d9 JJ |
1128 | |
1129 | return 0; | |
09b9df4e JM |
1130 | } |
1131 | ||
1132 | ||
b55aaa5f JM |
1133 | static struct wpa_ssid * |
1134 | wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s) | |
1135 | { | |
1136 | int prio; | |
1137 | struct wpa_ssid *ssid; | |
1138 | ||
1139 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
1140 | for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) | |
1141 | { | |
349493bd | 1142 | if (wpas_network_disabled(wpa_s, ssid)) |
b55aaa5f JM |
1143 | continue; |
1144 | if (ssid->mode == IEEE80211_MODE_IBSS || | |
476e6bb6 TP |
1145 | ssid->mode == IEEE80211_MODE_AP || |
1146 | ssid->mode == IEEE80211_MODE_MESH) | |
b55aaa5f JM |
1147 | return ssid; |
1148 | } | |
1149 | } | |
1150 | return NULL; | |
1151 | } | |
1152 | ||
1153 | ||
a1fd2ce5 JM |
1154 | /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based |
1155 | * on BSS added and BSS changed events */ | |
6ae93185 | 1156 | static void wpa_supplicant_rsn_preauth_scan_results( |
6d28fb96 | 1157 | struct wpa_supplicant *wpa_s) |
6ae93185 | 1158 | { |
6d28fb96 | 1159 | struct wpa_bss *bss; |
6ae93185 JM |
1160 | |
1161 | if (rsn_preauth_scan_results(wpa_s->wpa) < 0) | |
1162 | return; | |
1163 | ||
6d28fb96 | 1164 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
6ae93185 | 1165 | const u8 *ssid, *rsn; |
6ae93185 | 1166 | |
6d28fb96 | 1167 | ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID); |
6ae93185 JM |
1168 | if (ssid == NULL) |
1169 | continue; | |
1170 | ||
6d28fb96 | 1171 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
6ae93185 JM |
1172 | if (rsn == NULL) |
1173 | continue; | |
1174 | ||
6d28fb96 | 1175 | rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn); |
6ae93185 JM |
1176 | } |
1177 | ||
1178 | } | |
1179 | ||
1180 | ||
48563d86 JM |
1181 | static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, |
1182 | struct wpa_bss *selected, | |
20ed5e40 | 1183 | struct wpa_ssid *ssid) |
48563d86 | 1184 | { |
20ed5e40 | 1185 | struct wpa_bss *current_bss = NULL; |
48563d86 JM |
1186 | int min_diff; |
1187 | ||
1188 | if (wpa_s->reassociate) | |
1189 | return 1; /* explicit request to reassociate */ | |
1190 | if (wpa_s->wpa_state < WPA_ASSOCIATED) | |
1191 | return 1; /* we are not associated; continue */ | |
1192 | if (wpa_s->current_ssid == NULL) | |
1193 | return 1; /* unknown current SSID */ | |
1194 | if (wpa_s->current_ssid != ssid) | |
1195 | return 1; /* different network block */ | |
1196 | ||
22628eca JM |
1197 | if (wpas_driver_bss_selection(wpa_s)) |
1198 | return 0; /* Driver-based roaming */ | |
1199 | ||
20ed5e40 JM |
1200 | if (wpa_s->current_ssid->ssid) |
1201 | current_bss = wpa_bss_get(wpa_s, wpa_s->bssid, | |
1202 | wpa_s->current_ssid->ssid, | |
1203 | wpa_s->current_ssid->ssid_len); | |
1204 | if (!current_bss) | |
1205 | current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid); | |
48563d86 JM |
1206 | |
1207 | if (!current_bss) | |
1208 | return 1; /* current BSS not seen in scan results */ | |
1209 | ||
20ed5e40 JM |
1210 | if (current_bss == selected) |
1211 | return 0; | |
1212 | ||
1213 | if (selected->last_update_idx > current_bss->last_update_idx) | |
1214 | return 1; /* current BSS not seen in the last scan */ | |
1215 | ||
e9af53ad | 1216 | #ifndef CONFIG_NO_ROAMING |
f049052b BG |
1217 | wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation"); |
1218 | wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d", | |
1219 | MAC2STR(current_bss->bssid), current_bss->level); | |
1220 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d", | |
1221 | MAC2STR(selected->bssid), selected->level); | |
48563d86 | 1222 | |
ac26ebd8 JM |
1223 | if (wpa_s->current_ssid->bssid_set && |
1224 | os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) == | |
1225 | 0) { | |
f049052b BG |
1226 | wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS " |
1227 | "has preferred BSSID"); | |
ac26ebd8 JM |
1228 | return 1; |
1229 | } | |
1230 | ||
bff954e9 RS |
1231 | if (current_bss->level < 0 && current_bss->level > selected->level) { |
1232 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better " | |
1233 | "signal level"); | |
1234 | return 0; | |
1235 | } | |
1236 | ||
48563d86 JM |
1237 | min_diff = 2; |
1238 | if (current_bss->level < 0) { | |
1239 | if (current_bss->level < -85) | |
1240 | min_diff = 1; | |
1241 | else if (current_bss->level < -80) | |
1242 | min_diff = 2; | |
1243 | else if (current_bss->level < -75) | |
1244 | min_diff = 3; | |
1245 | else if (current_bss->level < -70) | |
1246 | min_diff = 4; | |
1247 | else | |
1248 | min_diff = 5; | |
1249 | } | |
1250 | if (abs(current_bss->level - selected->level) < min_diff) { | |
f049052b BG |
1251 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference " |
1252 | "in signal level"); | |
48563d86 JM |
1253 | return 0; |
1254 | } | |
1255 | ||
1256 | return 1; | |
e9af53ad DS |
1257 | #else /* CONFIG_NO_ROAMING */ |
1258 | return 0; | |
1259 | #endif /* CONFIG_NO_ROAMING */ | |
48563d86 JM |
1260 | } |
1261 | ||
cd2f4ddf | 1262 | |
0dd54313 | 1263 | /* Return != 0 if no scan results could be fetched or if scan results should not |
10ac7ddf | 1264 | * be shared with other virtual interfaces. */ |
e1504976 | 1265 | static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, |
cfd31b50 JM |
1266 | union wpa_event_data *data, |
1267 | int own_request) | |
09b9df4e | 1268 | { |
d12a51b5 JM |
1269 | struct wpa_scan_results *scan_res = NULL; |
1270 | int ret = 0; | |
5bc0cdb7 | 1271 | int ap = 0; |
7b1aa4fe JM |
1272 | #ifndef CONFIG_NO_RANDOM_POOL |
1273 | size_t i, num; | |
1274 | #endif /* CONFIG_NO_RANDOM_POOL */ | |
5bc0cdb7 JM |
1275 | |
1276 | #ifdef CONFIG_AP | |
1277 | if (wpa_s->ap_iface) | |
1278 | ap = 1; | |
1279 | #endif /* CONFIG_AP */ | |
6fc6879b | 1280 | |
cb8564b1 DW |
1281 | wpa_supplicant_notify_scanning(wpa_s, 0); |
1282 | ||
a1fd2ce5 JM |
1283 | scan_res = wpa_supplicant_get_scan_results(wpa_s, |
1284 | data ? &data->scan_info : | |
1285 | NULL, 1); | |
1286 | if (scan_res == NULL) { | |
66fe0f70 DS |
1287 | if (wpa_s->conf->ap_scan == 2 || ap || |
1288 | wpa_s->scan_res_handler == scan_only_handler) | |
e1504976 | 1289 | return -1; |
cfd31b50 JM |
1290 | if (!own_request) |
1291 | return -1; | |
f049052b BG |
1292 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try " |
1293 | "scanning again"); | |
977b1174 | 1294 | wpa_supplicant_req_new_scan(wpa_s, 1, 0); |
d12a51b5 JM |
1295 | ret = -1; |
1296 | goto scan_work_done; | |
6fc6879b JM |
1297 | } |
1298 | ||
bbb921da | 1299 | #ifndef CONFIG_NO_RANDOM_POOL |
bbb921da JM |
1300 | num = scan_res->num; |
1301 | if (num > 10) | |
1302 | num = 10; | |
1303 | for (i = 0; i < num; i++) { | |
1304 | u8 buf[5]; | |
1305 | struct wpa_scan_res *res = scan_res->res[i]; | |
1306 | buf[0] = res->bssid[5]; | |
1307 | buf[1] = res->qual & 0xff; | |
1308 | buf[2] = res->noise & 0xff; | |
1309 | buf[3] = res->level & 0xff; | |
1310 | buf[4] = res->tsf & 0xff; | |
1311 | random_add_randomness(buf, sizeof(buf)); | |
1312 | } | |
1313 | #endif /* CONFIG_NO_RANDOM_POOL */ | |
1314 | ||
06f9acce JM |
1315 | if (own_request && wpa_s->scan_res_handler && |
1316 | (wpa_s->own_scan_running || !wpa_s->external_scan_running)) { | |
860fddbb JB |
1317 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, |
1318 | struct wpa_scan_results *scan_res); | |
1319 | ||
1320 | scan_res_handler = wpa_s->scan_res_handler; | |
64e58f51 | 1321 | wpa_s->scan_res_handler = NULL; |
860fddbb | 1322 | scan_res_handler(wpa_s, scan_res); |
d12a51b5 JM |
1323 | ret = -2; |
1324 | goto scan_work_done; | |
64e58f51 JM |
1325 | } |
1326 | ||
5bc0cdb7 | 1327 | if (ap) { |
f049052b | 1328 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode"); |
c202f19c JB |
1329 | #ifdef CONFIG_AP |
1330 | if (wpa_s->ap_iface->scan_cb) | |
1331 | wpa_s->ap_iface->scan_cb(wpa_s->ap_iface); | |
1332 | #endif /* CONFIG_AP */ | |
d12a51b5 | 1333 | goto scan_work_done; |
5bc0cdb7 JM |
1334 | } |
1335 | ||
a5f40eff JM |
1336 | wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)", |
1337 | wpa_s->own_scan_running, wpa_s->external_scan_running); | |
d81c73be JM |
1338 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
1339 | wpa_s->manual_scan_use_id && wpa_s->own_scan_running) { | |
1340 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u", | |
1341 | wpa_s->manual_scan_id); | |
1342 | wpa_s->manual_scan_use_id = 0; | |
1343 | } else { | |
1344 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); | |
1345 | } | |
24f76940 | 1346 | wpas_notify_scan_results(wpa_s); |
6fc6879b | 1347 | |
8bac466b JM |
1348 | wpas_notify_scan_done(wpa_s, 1); |
1349 | ||
015af91f JM |
1350 | if (!wpa_s->own_scan_running && wpa_s->external_scan_running) { |
1351 | wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection"); | |
1352 | wpa_scan_results_free(scan_res); | |
1353 | return 0; | |
1354 | } | |
1355 | ||
75d65857 | 1356 | if (wnm_scan_process(wpa_s, 1) > 0) |
d0b9ab69 JM |
1357 | goto scan_work_done; |
1358 | ||
d12a51b5 JM |
1359 | if (sme_proc_obss_scan(wpa_s) > 0) |
1360 | goto scan_work_done; | |
c3701c66 | 1361 | |
d12a51b5 JM |
1362 | if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) |
1363 | goto scan_work_done; | |
6fc6879b | 1364 | |
d12a51b5 JM |
1365 | if (autoscan_notify_scan(wpa_s, scan_res)) |
1366 | goto scan_work_done; | |
7c865c68 | 1367 | |
3180d7a2 SO |
1368 | if (wpa_s->disconnected) { |
1369 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
d12a51b5 | 1370 | goto scan_work_done; |
3180d7a2 SO |
1371 | } |
1372 | ||
22628eca | 1373 | if (!wpas_driver_bss_selection(wpa_s) && |
d12a51b5 JM |
1374 | bgscan_notify_scan(wpa_s, scan_res) == 1) |
1375 | goto scan_work_done; | |
a1fd2ce5 | 1376 | |
f9f0526b JM |
1377 | wpas_wps_update_ap_info(wpa_s, scan_res); |
1378 | ||
20ed5e40 JM |
1379 | wpa_scan_results_free(scan_res); |
1380 | ||
d12a51b5 JM |
1381 | if (wpa_s->scan_work) { |
1382 | struct wpa_radio_work *work = wpa_s->scan_work; | |
1383 | wpa_s->scan_work = NULL; | |
1384 | radio_work_done(work); | |
1385 | } | |
1386 | ||
cc4952ad | 1387 | return wpas_select_network_from_last_scan(wpa_s, 1, own_request); |
d12a51b5 JM |
1388 | |
1389 | scan_work_done: | |
1390 | wpa_scan_results_free(scan_res); | |
1391 | if (wpa_s->scan_work) { | |
1392 | struct wpa_radio_work *work = wpa_s->scan_work; | |
1393 | wpa_s->scan_work = NULL; | |
1394 | radio_work_done(work); | |
1395 | } | |
1396 | return ret; | |
a594e2a9 JM |
1397 | } |
1398 | ||
1399 | ||
06b7f58d | 1400 | static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, |
cc4952ad | 1401 | int new_scan, int own_request) |
a594e2a9 JM |
1402 | { |
1403 | struct wpa_bss *selected; | |
1404 | struct wpa_ssid *ssid = NULL; | |
1405 | ||
620c7837 JM |
1406 | selected = wpa_supplicant_pick_network(wpa_s, &ssid); |
1407 | ||
6fc6879b | 1408 | if (selected) { |
48563d86 | 1409 | int skip; |
20ed5e40 | 1410 | skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid); |
1bbff09e | 1411 | if (skip) { |
06b7f58d JM |
1412 | if (new_scan) |
1413 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); | |
e1504976 | 1414 | return 0; |
1bbff09e | 1415 | } |
5cbd88d9 JJ |
1416 | |
1417 | if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) { | |
1418 | wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed"); | |
1419 | return -1; | |
1420 | } | |
06b7f58d JM |
1421 | if (new_scan) |
1422 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); | |
0dd54313 JM |
1423 | /* |
1424 | * Do not notify other virtual radios of scan results since we do not | |
1425 | * want them to start other associations at the same time. | |
1426 | */ | |
1427 | return 1; | |
6fc6879b | 1428 | } else { |
a3335ef5 TP |
1429 | #ifdef CONFIG_MESH |
1430 | if (wpa_s->ifmsh) { | |
1431 | wpa_msg(wpa_s, MSG_INFO, | |
1432 | "Avoiding join because we already joined a mesh group"); | |
1433 | return 0; | |
1434 | } | |
1435 | #endif /* CONFIG_MESH */ | |
f049052b | 1436 | wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found"); |
b55aaa5f JM |
1437 | ssid = wpa_supplicant_pick_new_network(wpa_s); |
1438 | if (ssid) { | |
f049052b | 1439 | wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network"); |
b55aaa5f | 1440 | wpa_supplicant_associate(wpa_s, NULL, ssid); |
06b7f58d JM |
1441 | if (new_scan) |
1442 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); | |
cc4952ad JJ |
1443 | } else if (own_request) { |
1444 | /* | |
1445 | * No SSID found. If SCAN results are as a result of | |
1446 | * own scan request and not due to a scan request on | |
1447 | * another shared interface, try another scan. | |
1448 | */ | |
67b9bd08 | 1449 | int timeout_sec = wpa_s->scan_interval; |
977b1174 | 1450 | int timeout_usec = 0; |
0817de90 | 1451 | #ifdef CONFIG_P2P |
aa9bb764 JM |
1452 | if (wpas_p2p_scan_no_go_seen(wpa_s) == 1) |
1453 | return 0; | |
1454 | ||
6fc48481 | 1455 | if (wpa_s->p2p_in_provisioning || |
41d5ce9e RR |
1456 | wpa_s->show_group_started || |
1457 | wpa_s->p2p_in_invitation) { | |
0817de90 JM |
1458 | /* |
1459 | * Use shorter wait during P2P Provisioning | |
6fc48481 RR |
1460 | * state and during P2P join-a-group operation |
1461 | * to speed up group formation. | |
0817de90 JM |
1462 | */ |
1463 | timeout_sec = 0; | |
1464 | timeout_usec = 250000; | |
a4cba8f1 LC |
1465 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
1466 | timeout_usec); | |
1467 | return 0; | |
0817de90 JM |
1468 | } |
1469 | #endif /* CONFIG_P2P */ | |
4d5bda5f JM |
1470 | #ifdef CONFIG_INTERWORKING |
1471 | if (wpa_s->conf->auto_interworking && | |
1472 | wpa_s->conf->interworking && | |
1473 | wpa_s->conf->cred) { | |
1474 | wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: " | |
1475 | "start ANQP fetch since no matching " | |
1476 | "networks found"); | |
1477 | wpa_s->network_select = 1; | |
1478 | wpa_s->auto_network_select = 1; | |
1479 | interworking_start_fetch_anqp(wpa_s); | |
0dd54313 | 1480 | return 1; |
4d5bda5f JM |
1481 | } |
1482 | #endif /* CONFIG_INTERWORKING */ | |
662b40b1 | 1483 | #ifdef CONFIG_WPS |
538d6f4b | 1484 | if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) { |
662b40b1 JM |
1485 | wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing"); |
1486 | timeout_sec = 0; | |
1487 | timeout_usec = 500000; | |
1488 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, | |
1489 | timeout_usec); | |
1490 | return 0; | |
1491 | } | |
1492 | #endif /* CONFIG_WPS */ | |
a4cba8f1 LC |
1493 | if (wpa_supplicant_req_sched_scan(wpa_s)) |
1494 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, | |
1495 | timeout_usec); | |
977b1174 | 1496 | } |
6fc6879b | 1497 | } |
e1504976 | 1498 | return 0; |
6fc6879b | 1499 | } |
6859f1cb BG |
1500 | |
1501 | ||
1502 | static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, | |
1503 | union wpa_event_data *data) | |
1504 | { | |
6859f1cb BG |
1505 | struct wpa_supplicant *ifs; |
1506 | ||
cfd31b50 | 1507 | if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) { |
e1504976 BG |
1508 | /* |
1509 | * If no scan results could be fetched, then no need to | |
1510 | * notify those interfaces that did not actually request | |
0dd54313 JM |
1511 | * this scan. Similarly, if scan results started a new operation on this |
1512 | * interface, do not notify other interfaces to avoid concurrent | |
1513 | * operations during a connection attempt. | |
e1504976 BG |
1514 | */ |
1515 | return; | |
1516 | } | |
6859f1cb BG |
1517 | |
1518 | /* | |
f88f19b4 | 1519 | * Check other interfaces to see if they share the same radio. If |
6859f1cb BG |
1520 | * so, they get updated with this same scan info. |
1521 | */ | |
f88f19b4 JM |
1522 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
1523 | radio_list) { | |
1524 | if (ifs != wpa_s) { | |
6859f1cb BG |
1525 | wpa_printf(MSG_DEBUG, "%s: Updating scan results from " |
1526 | "sibling", ifs->ifname); | |
cfd31b50 | 1527 | _wpa_supplicant_event_scan_results(ifs, data, 0); |
6859f1cb BG |
1528 | } |
1529 | } | |
1530 | } | |
1531 | ||
6fc6879b JM |
1532 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
1533 | ||
1534 | ||
cecdddc1 PS |
1535 | int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s) |
1536 | { | |
1537 | #ifdef CONFIG_NO_SCAN_PROCESSING | |
1538 | return -1; | |
1539 | #else /* CONFIG_NO_SCAN_PROCESSING */ | |
a12d3454 | 1540 | struct os_reltime now; |
cecdddc1 PS |
1541 | |
1542 | if (wpa_s->last_scan_res_used <= 0) | |
1543 | return -1; | |
1544 | ||
a12d3454 JB |
1545 | os_get_reltime(&now); |
1546 | if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) { | |
cecdddc1 PS |
1547 | wpa_printf(MSG_DEBUG, "Fast associate: Old scan results"); |
1548 | return -1; | |
1549 | } | |
1550 | ||
cc4952ad | 1551 | return wpas_select_network_from_last_scan(wpa_s, 0, 1); |
cecdddc1 PS |
1552 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
1553 | } | |
1554 | ||
b6668734 JM |
1555 | #ifdef CONFIG_WNM |
1556 | ||
1557 | static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx) | |
1558 | { | |
1559 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1560 | ||
1561 | if (wpa_s->wpa_state < WPA_ASSOCIATED) | |
1562 | return; | |
1563 | ||
2ec535fd JM |
1564 | if (!wpa_s->no_keep_alive) { |
1565 | wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR, | |
1566 | MAC2STR(wpa_s->bssid)); | |
1567 | /* TODO: could skip this if normal data traffic has been sent */ | |
1568 | /* TODO: Consider using some more appropriate data frame for | |
1569 | * this */ | |
1570 | if (wpa_s->l2) | |
1571 | l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, | |
1572 | (u8 *) "", 0); | |
1573 | } | |
b6668734 | 1574 | |
597c7a8d | 1575 | #ifdef CONFIG_SME |
b6668734 JM |
1576 | if (wpa_s->sme.bss_max_idle_period) { |
1577 | unsigned int msec; | |
1578 | msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */ | |
1579 | if (msec > 100) | |
1580 | msec -= 100; | |
1581 | eloop_register_timeout(msec / 1000, msec % 1000 * 1000, | |
1582 | wnm_bss_keep_alive, wpa_s, NULL); | |
1583 | } | |
597c7a8d | 1584 | #endif /* CONFIG_SME */ |
b6668734 JM |
1585 | } |
1586 | ||
1587 | ||
1588 | static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s, | |
1589 | const u8 *ies, size_t ies_len) | |
1590 | { | |
1591 | struct ieee802_11_elems elems; | |
1592 | ||
1593 | if (ies == NULL) | |
1594 | return; | |
1595 | ||
1596 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) | |
1597 | return; | |
1598 | ||
1599 | #ifdef CONFIG_SME | |
1600 | if (elems.bss_max_idle_period) { | |
1601 | unsigned int msec; | |
1602 | wpa_s->sme.bss_max_idle_period = | |
1603 | WPA_GET_LE16(elems.bss_max_idle_period); | |
1604 | wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 " | |
1605 | "TU)%s", wpa_s->sme.bss_max_idle_period, | |
1606 | (elems.bss_max_idle_period[2] & 0x01) ? | |
1607 | " (protected keep-live required)" : ""); | |
1608 | if (wpa_s->sme.bss_max_idle_period == 0) | |
1609 | wpa_s->sme.bss_max_idle_period = 1; | |
1610 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) { | |
1611 | eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); | |
1612 | /* msec times 1000 */ | |
1613 | msec = wpa_s->sme.bss_max_idle_period * 1024; | |
1614 | if (msec > 100) | |
1615 | msec -= 100; | |
1616 | eloop_register_timeout(msec / 1000, msec % 1000 * 1000, | |
1617 | wnm_bss_keep_alive, wpa_s, | |
1618 | NULL); | |
1619 | } | |
1620 | } | |
1621 | #endif /* CONFIG_SME */ | |
1622 | } | |
1623 | ||
1624 | #endif /* CONFIG_WNM */ | |
1625 | ||
1626 | ||
1627 | void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s) | |
1628 | { | |
1629 | #ifdef CONFIG_WNM | |
1630 | eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); | |
1631 | #endif /* CONFIG_WNM */ | |
1632 | } | |
1633 | ||
1634 | ||
56f5af48 JM |
1635 | #ifdef CONFIG_INTERWORKING |
1636 | ||
1637 | static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map, | |
1638 | size_t len) | |
1639 | { | |
1640 | int res; | |
1641 | ||
1642 | wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len); | |
1643 | res = wpa_drv_set_qos_map(wpa_s, qos_map, len); | |
1644 | if (res) { | |
1645 | wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver"); | |
1646 | } | |
1647 | ||
1648 | return res; | |
1649 | } | |
1650 | ||
1651 | ||
1652 | static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s, | |
1653 | const u8 *ies, size_t ies_len) | |
1654 | { | |
1655 | struct ieee802_11_elems elems; | |
1656 | ||
1657 | if (ies == NULL) | |
1658 | return; | |
1659 | ||
1660 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) | |
1661 | return; | |
1662 | ||
1663 | if (elems.qos_map_set) { | |
1664 | wpas_qos_map_set(wpa_s, elems.qos_map_set, | |
1665 | elems.qos_map_set_len); | |
1666 | } | |
1667 | } | |
1668 | ||
1669 | #endif /* CONFIG_INTERWORKING */ | |
1670 | ||
1671 | ||
579ce771 JM |
1672 | static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, |
1673 | union wpa_event_data *data) | |
6fc6879b JM |
1674 | { |
1675 | int l, len, found = 0, wpa_found, rsn_found; | |
c2a04078 | 1676 | const u8 *p; |
b6714ca1 | 1677 | #ifdef CONFIG_IEEE80211R |
6a1ce395 | 1678 | u8 bssid[ETH_ALEN]; |
b6714ca1 | 1679 | #endif /* CONFIG_IEEE80211R */ |
6fc6879b | 1680 | |
f049052b | 1681 | wpa_dbg(wpa_s, MSG_DEBUG, "Association info event"); |
6fc6879b JM |
1682 | if (data->assoc_info.req_ies) |
1683 | wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, | |
1684 | data->assoc_info.req_ies_len); | |
52c9e6f3 | 1685 | if (data->assoc_info.resp_ies) { |
6fc6879b JM |
1686 | wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, |
1687 | data->assoc_info.resp_ies_len); | |
52c9e6f3 JM |
1688 | #ifdef CONFIG_TDLS |
1689 | wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies, | |
1690 | data->assoc_info.resp_ies_len); | |
1691 | #endif /* CONFIG_TDLS */ | |
b6668734 JM |
1692 | #ifdef CONFIG_WNM |
1693 | wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, | |
1694 | data->assoc_info.resp_ies_len); | |
1695 | #endif /* CONFIG_WNM */ | |
56f5af48 JM |
1696 | #ifdef CONFIG_INTERWORKING |
1697 | interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, | |
1698 | data->assoc_info.resp_ies_len); | |
1699 | #endif /* CONFIG_INTERWORKING */ | |
52c9e6f3 | 1700 | } |
6fc6879b JM |
1701 | if (data->assoc_info.beacon_ies) |
1702 | wpa_hexdump(MSG_DEBUG, "beacon_ies", | |
1703 | data->assoc_info.beacon_ies, | |
1704 | data->assoc_info.beacon_ies_len); | |
4832ecd7 | 1705 | if (data->assoc_info.freq) |
f049052b BG |
1706 | wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz", |
1707 | data->assoc_info.freq); | |
6fc6879b JM |
1708 | |
1709 | p = data->assoc_info.req_ies; | |
1710 | l = data->assoc_info.req_ies_len; | |
1711 | ||
1712 | /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ | |
1713 | while (p && l >= 2) { | |
1714 | len = p[1] + 2; | |
1715 | if (len > l) { | |
1716 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
1717 | p, l); | |
1718 | break; | |
1719 | } | |
1720 | if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
1721 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || | |
1722 | (p[0] == WLAN_EID_RSN && p[1] >= 2)) { | |
1723 | if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) | |
1724 | break; | |
1725 | found = 1; | |
1726 | wpa_find_assoc_pmkid(wpa_s); | |
1727 | break; | |
1728 | } | |
1729 | l -= len; | |
1730 | p += len; | |
1731 | } | |
1732 | if (!found && data->assoc_info.req_ies) | |
1733 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); | |
1734 | ||
c2a04078 | 1735 | #ifdef CONFIG_IEEE80211R |
62c72d72 JM |
1736 | #ifdef CONFIG_SME |
1737 | if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) { | |
62c72d72 JM |
1738 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || |
1739 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, | |
1740 | data->assoc_info.resp_ies, | |
1741 | data->assoc_info.resp_ies_len, | |
1742 | bssid) < 0) { | |
f049052b BG |
1743 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " |
1744 | "Reassociation Response failed"); | |
579ce771 JM |
1745 | wpa_supplicant_deauthenticate( |
1746 | wpa_s, WLAN_REASON_INVALID_IE); | |
1747 | return -1; | |
62c72d72 JM |
1748 | } |
1749 | } | |
62c72d72 | 1750 | |
c2a04078 JM |
1751 | p = data->assoc_info.resp_ies; |
1752 | l = data->assoc_info.resp_ies_len; | |
1753 | ||
54f489be | 1754 | #ifdef CONFIG_WPS_STRICT |
5dac11e0 | 1755 | if (p && wpa_s->current_ssid && |
54f489be JM |
1756 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) { |
1757 | struct wpabuf *wps; | |
1758 | wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE); | |
1759 | if (wps == NULL) { | |
f049052b BG |
1760 | wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not " |
1761 | "include WPS IE in (Re)Association Response"); | |
54f489be JM |
1762 | return -1; |
1763 | } | |
1764 | ||
1765 | if (wps_validate_assoc_resp(wps) < 0) { | |
1766 | wpabuf_free(wps); | |
1767 | wpa_supplicant_deauthenticate( | |
1768 | wpa_s, WLAN_REASON_INVALID_IE); | |
1769 | return -1; | |
1770 | } | |
1771 | wpabuf_free(wps); | |
1772 | } | |
1773 | #endif /* CONFIG_WPS_STRICT */ | |
1774 | ||
e7846b68 | 1775 | /* Go through the IEs and make a copy of the MDIE, if present. */ |
c2a04078 JM |
1776 | while (p && l >= 2) { |
1777 | len = p[1] + 2; | |
1778 | if (len > l) { | |
1779 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
1780 | p, l); | |
1781 | break; | |
1782 | } | |
e7846b68 JM |
1783 | if (p[0] == WLAN_EID_MOBILITY_DOMAIN && |
1784 | p[1] >= MOBILITY_DOMAIN_ID_LEN) { | |
1785 | wpa_s->sme.ft_used = 1; | |
1786 | os_memcpy(wpa_s->sme.mobility_domain, p + 2, | |
1787 | MOBILITY_DOMAIN_ID_LEN); | |
1788 | break; | |
1789 | } | |
c2a04078 JM |
1790 | l -= len; |
1791 | p += len; | |
1792 | } | |
e7846b68 | 1793 | #endif /* CONFIG_SME */ |
c2a04078 | 1794 | |
6a1ce395 DG |
1795 | /* Process FT when SME is in the driver */ |
1796 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && | |
1797 | wpa_ft_is_completed(wpa_s->wpa)) { | |
1798 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || | |
1799 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, | |
1800 | data->assoc_info.resp_ies, | |
1801 | data->assoc_info.resp_ies_len, | |
1802 | bssid) < 0) { | |
1803 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " | |
1804 | "Reassociation Response failed"); | |
1805 | wpa_supplicant_deauthenticate( | |
1806 | wpa_s, WLAN_REASON_INVALID_IE); | |
1807 | return -1; | |
1808 | } | |
1809 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done"); | |
1810 | } | |
1811 | ||
e7846b68 JM |
1812 | wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies, |
1813 | data->assoc_info.resp_ies_len); | |
c2a04078 JM |
1814 | #endif /* CONFIG_IEEE80211R */ |
1815 | ||
6fc6879b JM |
1816 | /* WPA/RSN IE from Beacon/ProbeResp */ |
1817 | p = data->assoc_info.beacon_ies; | |
1818 | l = data->assoc_info.beacon_ies_len; | |
1819 | ||
1820 | /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. | |
1821 | */ | |
1822 | wpa_found = rsn_found = 0; | |
1823 | while (p && l >= 2) { | |
1824 | len = p[1] + 2; | |
1825 | if (len > l) { | |
1826 | wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", | |
1827 | p, l); | |
1828 | break; | |
1829 | } | |
1830 | if (!wpa_found && | |
1831 | p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
1832 | os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { | |
1833 | wpa_found = 1; | |
1834 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); | |
1835 | } | |
1836 | ||
1837 | if (!rsn_found && | |
1838 | p[0] == WLAN_EID_RSN && p[1] >= 2) { | |
1839 | rsn_found = 1; | |
1840 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); | |
1841 | } | |
1842 | ||
1843 | l -= len; | |
1844 | p += len; | |
1845 | } | |
1846 | ||
1847 | if (!wpa_found && data->assoc_info.beacon_ies) | |
1848 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); | |
1849 | if (!rsn_found && data->assoc_info.beacon_ies) | |
1850 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); | |
1851 | if (wpa_found || rsn_found) | |
1852 | wpa_s->ap_ies_from_associnfo = 1; | |
4832ecd7 | 1853 | |
117e812d JM |
1854 | if (wpa_s->assoc_freq && data->assoc_info.freq && |
1855 | wpa_s->assoc_freq != data->assoc_info.freq) { | |
1856 | wpa_printf(MSG_DEBUG, "Operating frequency changed from " | |
1857 | "%u to %u MHz", | |
1858 | wpa_s->assoc_freq, data->assoc_info.freq); | |
1859 | wpa_supplicant_update_scan_results(wpa_s); | |
1860 | } | |
1861 | ||
4832ecd7 | 1862 | wpa_s->assoc_freq = data->assoc_info.freq; |
579ce771 JM |
1863 | |
1864 | return 0; | |
6fc6879b JM |
1865 | } |
1866 | ||
1867 | ||
ad9ee4d4 JM |
1868 | static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s) |
1869 | { | |
1870 | const u8 *bss_wpa = NULL, *bss_rsn = NULL; | |
1871 | ||
1872 | if (!wpa_s->current_bss || !wpa_s->current_ssid) | |
1873 | return -1; | |
1874 | ||
1875 | if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt)) | |
1876 | return 0; | |
1877 | ||
1878 | bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss, | |
1879 | WPA_IE_VENDOR_TYPE); | |
1880 | bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN); | |
1881 | ||
1882 | if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa, | |
1883 | bss_wpa ? 2 + bss_wpa[1] : 0) || | |
1884 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn, | |
1885 | bss_rsn ? 2 + bss_rsn[1] : 0)) | |
1886 | return -1; | |
1887 | ||
1888 | return 0; | |
1889 | } | |
1890 | ||
1891 | ||
6fc6879b JM |
1892 | static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, |
1893 | union wpa_event_data *data) | |
1894 | { | |
1895 | u8 bssid[ETH_ALEN]; | |
1d041bec | 1896 | int ft_completed; |
6fc6879b | 1897 | |
1d041bec JM |
1898 | #ifdef CONFIG_AP |
1899 | if (wpa_s->ap_iface) { | |
a01acc50 JM |
1900 | if (!data) |
1901 | return; | |
1d041bec JM |
1902 | hostapd_notif_assoc(wpa_s->ap_iface->bss[0], |
1903 | data->assoc_info.addr, | |
1904 | data->assoc_info.req_ies, | |
39b08b5f SP |
1905 | data->assoc_info.req_ies_len, |
1906 | data->assoc_info.reassoc); | |
1d041bec JM |
1907 | return; |
1908 | } | |
1909 | #endif /* CONFIG_AP */ | |
1910 | ||
1911 | ft_completed = wpa_ft_is_completed(wpa_s->wpa); | |
579ce771 JM |
1912 | if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0) |
1913 | return; | |
6fc6879b | 1914 | |
0a0c38f6 MH |
1915 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
1916 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID"); | |
07783eaa | 1917 | wpa_supplicant_deauthenticate( |
0a0c38f6 MH |
1918 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
1919 | return; | |
1920 | } | |
1921 | ||
6fc6879b | 1922 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); |
0a0c38f6 | 1923 | if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) { |
f049052b | 1924 | wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" |
6fc6879b | 1925 | MACSTR, MAC2STR(bssid)); |
bbb921da | 1926 | random_add_randomness(bssid, ETH_ALEN); |
6fc6879b JM |
1927 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
1928 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
e485286c | 1929 | wpas_notify_bssid_changed(wpa_s); |
8bac466b | 1930 | |
6fc6879b JM |
1931 | if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { |
1932 | wpa_clear_keys(wpa_s, bssid); | |
1933 | } | |
1934 | if (wpa_supplicant_select_config(wpa_s) < 0) { | |
07783eaa | 1935 | wpa_supplicant_deauthenticate( |
6fc6879b JM |
1936 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
1937 | return; | |
1938 | } | |
cd2f4ddf SM |
1939 | |
1940 | if (wpa_s->conf->ap_scan == 1 && | |
1941 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) { | |
1942 | if (wpa_supplicant_assoc_update_ie(wpa_s) < 0) | |
1943 | wpa_msg(wpa_s, MSG_WARNING, | |
1944 | "WPA/RSN IEs not updated"); | |
1945 | } | |
6fc6879b JM |
1946 | } |
1947 | ||
62fa124c JM |
1948 | #ifdef CONFIG_SME |
1949 | os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN); | |
1950 | wpa_s->sme.prev_bssid_set = 1; | |
3302b7c2 | 1951 | wpa_s->sme.last_unprot_disconnect.sec = 0; |
62fa124c JM |
1952 | #endif /* CONFIG_SME */ |
1953 | ||
6fc6879b JM |
1954 | wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); |
1955 | if (wpa_s->current_ssid) { | |
1956 | /* When using scanning (ap_scan=1), SIM PC/SC interface can be | |
1957 | * initialized before association, but for other modes, | |
1958 | * initialize PC/SC here, if the current configuration needs | |
1959 | * smartcard or SIM/USIM. */ | |
1960 | wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); | |
1961 | } | |
1962 | wpa_sm_notify_assoc(wpa_s->wpa, bssid); | |
3f967fe0 JM |
1963 | if (wpa_s->l2) |
1964 | l2_packet_notify_auth_start(wpa_s->l2); | |
6fc6879b JM |
1965 | |
1966 | /* | |
1967 | * Set portEnabled first to FALSE in order to get EAP state machine out | |
1968 | * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE | |
1969 | * state machine may transit to AUTHENTICATING state based on obsolete | |
1970 | * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to | |
1971 | * AUTHENTICATED without ever giving chance to EAP state machine to | |
1972 | * reset the state. | |
1973 | */ | |
1974 | if (!ft_completed) { | |
1975 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); | |
1976 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
1977 | } | |
56586197 | 1978 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed) |
6fc6879b JM |
1979 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
1980 | /* 802.1X::portControl = Auto */ | |
1981 | eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE); | |
1982 | wpa_s->eapol_received = 0; | |
1983 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
9c972abb JM |
1984 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || |
1985 | (wpa_s->current_ssid && | |
1986 | wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) { | |
fb958ea7 JM |
1987 | if (wpa_s->current_ssid && |
1988 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE && | |
6ea1f413 JM |
1989 | (wpa_s->drv_flags & |
1990 | WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { | |
1991 | /* | |
1992 | * Set the key after having received joined-IBSS event | |
1993 | * from the driver. | |
1994 | */ | |
1995 | wpa_supplicant_set_wpa_none_key(wpa_s, | |
1996 | wpa_s->current_ssid); | |
1997 | } | |
6fc6879b JM |
1998 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
1999 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
2000 | } else if (!ft_completed) { | |
2001 | /* Timeout for receiving the first EAPOL packet */ | |
2002 | wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); | |
2003 | } | |
2004 | wpa_supplicant_cancel_scan(wpa_s); | |
2005 | ||
c2a04078 | 2006 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
56586197 | 2007 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
6fc6879b JM |
2008 | /* |
2009 | * We are done; the driver will take care of RSN 4-way | |
2010 | * handshake. | |
2011 | */ | |
2012 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
2013 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
2014 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
2015 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
98ea9431 JM |
2016 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
2017 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { | |
2018 | /* | |
2019 | * The driver will take care of RSN 4-way handshake, so we need | |
2020 | * to allow EAPOL supplicant to complete its work without | |
2021 | * waiting for WPA supplicant. | |
2022 | */ | |
2023 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
16a83d29 JM |
2024 | } else if (ft_completed) { |
2025 | /* | |
2026 | * FT protocol completed - make sure EAPOL state machine ends | |
2027 | * up in authenticated. | |
2028 | */ | |
2029 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
2030 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
2031 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
2032 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
6fc6879b | 2033 | } |
1ff73338 | 2034 | |
3ab35a66 JM |
2035 | wpa_s->last_eapol_matches_bssid = 0; |
2036 | ||
1ff73338 | 2037 | if (wpa_s->pending_eapol_rx) { |
c2be937c JB |
2038 | struct os_reltime now, age; |
2039 | os_get_reltime(&now); | |
2040 | os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age); | |
1ff73338 JM |
2041 | if (age.sec == 0 && age.usec < 100000 && |
2042 | os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) == | |
2043 | 0) { | |
f049052b BG |
2044 | wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL " |
2045 | "frame that was received just before " | |
2046 | "association notification"); | |
1ff73338 JM |
2047 | wpa_supplicant_rx_eapol( |
2048 | wpa_s, wpa_s->pending_eapol_rx_src, | |
2049 | wpabuf_head(wpa_s->pending_eapol_rx), | |
2050 | wpabuf_len(wpa_s->pending_eapol_rx)); | |
2051 | } | |
2052 | wpabuf_free(wpa_s->pending_eapol_rx); | |
2053 | wpa_s->pending_eapol_rx = NULL; | |
2054 | } | |
60b94c98 | 2055 | |
0194fedb JB |
2056 | if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
2057 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
66562e9c JM |
2058 | wpa_s->current_ssid && |
2059 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { | |
0194fedb JB |
2060 | /* Set static WEP keys again */ |
2061 | wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); | |
2062 | } | |
50b05780 JM |
2063 | |
2064 | #ifdef CONFIG_IBSS_RSN | |
2065 | if (wpa_s->current_ssid && | |
2066 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && | |
2067 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && | |
78177a00 JM |
2068 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE && |
2069 | wpa_s->ibss_rsn == NULL) { | |
2070 | wpa_s->ibss_rsn = ibss_rsn_init(wpa_s); | |
2071 | if (!wpa_s->ibss_rsn) { | |
2072 | wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN"); | |
2073 | wpa_supplicant_deauthenticate( | |
2074 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
2075 | return; | |
2076 | } | |
2077 | ||
2078 | ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk); | |
2079 | } | |
50b05780 | 2080 | #endif /* CONFIG_IBSS_RSN */ |
f9f0526b JM |
2081 | |
2082 | wpas_wps_notify_assoc(wpa_s, bssid); | |
a0413b17 MB |
2083 | |
2084 | if (data) { | |
2085 | wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies, | |
2086 | data->assoc_info.resp_ies_len, | |
2087 | &data->assoc_info.wmm_params); | |
8c42b369 EP |
2088 | |
2089 | if (wpa_s->reassoc_same_bss) | |
2090 | wmm_ac_restore_tspecs(wpa_s); | |
a0413b17 | 2091 | } |
6fc6879b JM |
2092 | } |
2093 | ||
2094 | ||
d00821e9 JM |
2095 | static int disconnect_reason_recoverable(u16 reason_code) |
2096 | { | |
2097 | return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY || | |
2098 | reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA || | |
2099 | reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA; | |
2100 | } | |
2101 | ||
2102 | ||
0544b242 | 2103 | static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, |
3d9975d5 JM |
2104 | u16 reason_code, |
2105 | int locally_generated) | |
6fc6879b JM |
2106 | { |
2107 | const u8 *bssid; | |
0aadd568 JM |
2108 | |
2109 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
2110 | /* | |
2111 | * At least Host AP driver and a Prism3 card seemed to be | |
2112 | * generating streams of disconnected events when configuring | |
2113 | * IBSS for WPA-None. Ignore them for now. | |
2114 | */ | |
2115 | return; | |
2116 | } | |
2117 | ||
2118 | bssid = wpa_s->bssid; | |
2119 | if (is_zero_ether_addr(bssid)) | |
2120 | bssid = wpa_s->pending_bssid; | |
2121 | ||
2122 | if (!is_zero_ether_addr(bssid) || | |
2123 | wpa_s->wpa_state >= WPA_AUTHENTICATING) { | |
2124 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR | |
2125 | " reason=%d%s", | |
2126 | MAC2STR(bssid), reason_code, | |
2127 | locally_generated ? " locally_generated=1" : ""); | |
2128 | } | |
2129 | } | |
2130 | ||
2131 | ||
c9a82218 JM |
2132 | static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code, |
2133 | int locally_generated) | |
2134 | { | |
2135 | if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE || | |
2136 | !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) | |
2137 | return 0; /* Not in 4-way handshake with PSK */ | |
2138 | ||
2139 | /* | |
2140 | * It looks like connection was lost while trying to go through PSK | |
2141 | * 4-way handshake. Filter out known disconnection cases that are caused | |
2142 | * by something else than PSK mismatch to avoid confusing reports. | |
2143 | */ | |
2144 | ||
2145 | if (locally_generated) { | |
2146 | if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS) | |
2147 | return 0; | |
2148 | } | |
2149 | ||
2150 | return 1; | |
2151 | } | |
2152 | ||
2153 | ||
0aadd568 JM |
2154 | static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s, |
2155 | u16 reason_code, | |
2156 | int locally_generated) | |
2157 | { | |
2158 | const u8 *bssid; | |
6d6f4bb8 JM |
2159 | int authenticating; |
2160 | u8 prev_pending_bssid[ETH_ALEN]; | |
d00821e9 JM |
2161 | struct wpa_bss *fast_reconnect = NULL; |
2162 | struct wpa_ssid *fast_reconnect_ssid = NULL; | |
bcdf2096 | 2163 | struct wpa_ssid *last_ssid; |
6d6f4bb8 JM |
2164 | |
2165 | authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING; | |
2166 | os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN); | |
6fc6879b JM |
2167 | |
2168 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
2169 | /* | |
2170 | * At least Host AP driver and a Prism3 card seemed to be | |
2171 | * generating streams of disconnected events when configuring | |
2172 | * IBSS for WPA-None. Ignore them for now. | |
2173 | */ | |
f049052b BG |
2174 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in " |
2175 | "IBSS/WPA-None mode"); | |
6fc6879b JM |
2176 | return; |
2177 | } | |
2178 | ||
c9a82218 | 2179 | if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) { |
6fc6879b JM |
2180 | wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " |
2181 | "pre-shared key may be incorrect"); | |
5bf9a6c8 JM |
2182 | if (wpas_p2p_4way_hs_failed(wpa_s) > 0) |
2183 | return; /* P2P group removed */ | |
b19c098e | 2184 | wpas_auth_failed(wpa_s, "WRONG_KEY"); |
6fc6879b | 2185 | } |
3636b891 JM |
2186 | if (!wpa_s->disconnected && |
2187 | (!wpa_s->auto_reconnect_disabled || | |
6e252b0d JM |
2188 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS || |
2189 | wpas_wps_searching(wpa_s))) { | |
d00821e9 | 2190 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to " |
6e252b0d | 2191 | "reconnect (wps=%d/%d wpa_state=%d)", |
f7da5a9e | 2192 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS, |
6e252b0d | 2193 | wpas_wps_searching(wpa_s), |
f7da5a9e | 2194 | wpa_s->wpa_state); |
d00821e9 JM |
2195 | if (wpa_s->wpa_state == WPA_COMPLETED && |
2196 | wpa_s->current_ssid && | |
2197 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA && | |
3d9975d5 | 2198 | !locally_generated && |
d00821e9 JM |
2199 | disconnect_reason_recoverable(reason_code)) { |
2200 | /* | |
2201 | * It looks like the AP has dropped association with | |
2202 | * us, but could allow us to get back in. Try to | |
2203 | * reconnect to the same BSS without full scan to save | |
2204 | * time for some common cases. | |
2205 | */ | |
2206 | fast_reconnect = wpa_s->current_bss; | |
2207 | fast_reconnect_ssid = wpa_s->current_ssid; | |
2208 | } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) | |
0d0a8ca1 | 2209 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
f7da5a9e JM |
2210 | else |
2211 | wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new " | |
2212 | "immediate scan"); | |
0d0a8ca1 | 2213 | } else { |
d00821e9 | 2214 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not " |
f049052b | 2215 | "try to re-connect"); |
0d0a8ca1 AC |
2216 | wpa_s->reassociate = 0; |
2217 | wpa_s->disconnected = 1; | |
433cd2ce | 2218 | wpa_supplicant_cancel_sched_scan(wpa_s); |
0d0a8ca1 | 2219 | } |
6fc6879b | 2220 | bssid = wpa_s->bssid; |
a8e16edc | 2221 | if (is_zero_ether_addr(bssid)) |
6fc6879b | 2222 | bssid = wpa_s->pending_bssid; |
56d24b4e JM |
2223 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
2224 | wpas_connection_failed(wpa_s, bssid); | |
6fc6879b | 2225 | wpa_sm_notify_disassoc(wpa_s->wpa); |
0bb1e425 GM |
2226 | if (locally_generated) |
2227 | wpa_s->disconnect_reason = -reason_code; | |
2228 | else | |
2229 | wpa_s->disconnect_reason = reason_code; | |
2230 | wpas_notify_disconnect_reason(wpa_s); | |
6fc6879b | 2231 | if (wpa_supplicant_dynamic_keys(wpa_s)) { |
f049052b | 2232 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys"); |
6fc6879b JM |
2233 | wpa_clear_keys(wpa_s, wpa_s->bssid); |
2234 | } | |
bcdf2096 | 2235 | last_ssid = wpa_s->current_ssid; |
6fc6879b | 2236 | wpa_supplicant_mark_disassoc(wpa_s); |
e29853bb | 2237 | |
bcdf2096 | 2238 | if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) { |
e29853bb | 2239 | sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid); |
bcdf2096 JM |
2240 | wpa_s->current_ssid = last_ssid; |
2241 | } | |
d00821e9 | 2242 | |
eef7235d JM |
2243 | if (fast_reconnect && |
2244 | !wpas_network_disabled(wpa_s, fast_reconnect_ssid) && | |
2245 | !disallowed_bssid(wpa_s, fast_reconnect->bssid) && | |
2246 | !disallowed_ssid(wpa_s, fast_reconnect->ssid, | |
2247 | fast_reconnect->ssid_len) && | |
2248 | !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) { | |
5928411e | 2249 | #ifndef CONFIG_NO_SCAN_PROCESSING |
d00821e9 JM |
2250 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS"); |
2251 | if (wpa_supplicant_connect(wpa_s, fast_reconnect, | |
2252 | fast_reconnect_ssid) < 0) { | |
2253 | /* Recover through full scan */ | |
2254 | wpa_supplicant_req_scan(wpa_s, 0, 100000); | |
2255 | } | |
5928411e | 2256 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
eef7235d JM |
2257 | } else if (fast_reconnect) { |
2258 | /* | |
2259 | * Could not reconnect to the same BSS due to network being | |
2260 | * disabled. Use a new scan to match the alternative behavior | |
2261 | * above, i.e., to continue automatic reconnection attempt in a | |
2262 | * way that enforces disabled network rules. | |
2263 | */ | |
2264 | wpa_supplicant_req_scan(wpa_s, 0, 100000); | |
d00821e9 | 2265 | } |
6fc6879b JM |
2266 | } |
2267 | ||
2268 | ||
46690a3b | 2269 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
01a17491 | 2270 | void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx) |
46690a3b JM |
2271 | { |
2272 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
2273 | ||
2274 | if (!wpa_s->pending_mic_error_report) | |
2275 | return; | |
2276 | ||
f049052b | 2277 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report"); |
46690a3b JM |
2278 | wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); |
2279 | wpa_s->pending_mic_error_report = 0; | |
2280 | } | |
2281 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
2282 | ||
2283 | ||
6fc6879b JM |
2284 | static void |
2285 | wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, | |
2286 | union wpa_event_data *data) | |
2287 | { | |
2288 | int pairwise; | |
6473e5c8 | 2289 | struct os_reltime t; |
6fc6879b JM |
2290 | |
2291 | wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); | |
2292 | pairwise = (data && data->michael_mic_failure.unicast); | |
6473e5c8 JB |
2293 | os_get_reltime(&t); |
2294 | if ((wpa_s->last_michael_mic_error.sec && | |
2295 | !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) || | |
46690a3b JM |
2296 | wpa_s->pending_mic_error_report) { |
2297 | if (wpa_s->pending_mic_error_report) { | |
2298 | /* | |
2299 | * Send the pending MIC error report immediately since | |
2300 | * we are going to start countermeasures and AP better | |
2301 | * do the same. | |
2302 | */ | |
2303 | wpa_sm_key_request(wpa_s->wpa, 1, | |
2304 | wpa_s->pending_mic_error_pairwise); | |
2305 | } | |
2306 | ||
2307 | /* Send the new MIC error report immediately since we are going | |
2308 | * to start countermeasures and AP better do the same. | |
2309 | */ | |
2310 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
2311 | ||
6fc6879b JM |
2312 | /* initialize countermeasures */ |
2313 | wpa_s->countermeasures = 1; | |
8945cc45 BM |
2314 | |
2315 | wpa_blacklist_add(wpa_s, wpa_s->bssid); | |
2316 | ||
6fc6879b JM |
2317 | wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); |
2318 | ||
2319 | /* | |
2320 | * Need to wait for completion of request frame. We do not get | |
2321 | * any callback for the message completion, so just wait a | |
2322 | * short while and hope for the best. */ | |
2323 | os_sleep(0, 10000); | |
2324 | ||
2325 | wpa_drv_set_countermeasures(wpa_s, 1); | |
2326 | wpa_supplicant_deauthenticate(wpa_s, | |
2327 | WLAN_REASON_MICHAEL_MIC_FAILURE); | |
2328 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, | |
2329 | wpa_s, NULL); | |
2330 | eloop_register_timeout(60, 0, | |
2331 | wpa_supplicant_stop_countermeasures, | |
2332 | wpa_s, NULL); | |
2333 | /* TODO: mark the AP rejected for 60 second. STA is | |
2334 | * allowed to associate with another AP.. */ | |
46690a3b JM |
2335 | } else { |
2336 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT | |
2337 | if (wpa_s->mic_errors_seen) { | |
2338 | /* | |
2339 | * Reduce the effectiveness of Michael MIC error | |
2340 | * reports as a means for attacking against TKIP if | |
2341 | * more than one MIC failure is noticed with the same | |
2342 | * PTK. We delay the transmission of the reports by a | |
2343 | * random time between 0 and 60 seconds in order to | |
2344 | * force the attacker wait 60 seconds before getting | |
2345 | * the information on whether a frame resulted in a MIC | |
2346 | * failure. | |
2347 | */ | |
2348 | u8 rval[4]; | |
2349 | int sec; | |
2350 | ||
2351 | if (os_get_random(rval, sizeof(rval)) < 0) | |
2352 | sec = os_random() % 60; | |
2353 | else | |
2354 | sec = WPA_GET_BE32(rval) % 60; | |
f049052b BG |
2355 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error " |
2356 | "report %d seconds", sec); | |
46690a3b JM |
2357 | wpa_s->pending_mic_error_report = 1; |
2358 | wpa_s->pending_mic_error_pairwise = pairwise; | |
2359 | eloop_cancel_timeout( | |
2360 | wpa_supplicant_delayed_mic_error_report, | |
2361 | wpa_s, NULL); | |
2362 | eloop_register_timeout( | |
2363 | sec, os_random() % 1000000, | |
2364 | wpa_supplicant_delayed_mic_error_report, | |
2365 | wpa_s, NULL); | |
2366 | } else { | |
2367 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
2368 | } | |
2369 | #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
2370 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
2371 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
6fc6879b | 2372 | } |
6473e5c8 | 2373 | wpa_s->last_michael_mic_error = t; |
46690a3b | 2374 | wpa_s->mic_errors_seen++; |
6fc6879b JM |
2375 | } |
2376 | ||
2377 | ||
a83d9c96 SL |
2378 | #ifdef CONFIG_TERMINATE_ONLASTIF |
2379 | static int any_interfaces(struct wpa_supplicant *head) | |
2380 | { | |
2381 | struct wpa_supplicant *wpa_s; | |
2382 | ||
2383 | for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) | |
2384 | if (!wpa_s->interface_removed) | |
2385 | return 1; | |
2386 | return 0; | |
2387 | } | |
2388 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
2389 | ||
2390 | ||
6fc6879b JM |
2391 | static void |
2392 | wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, | |
2393 | union wpa_event_data *data) | |
2394 | { | |
2395 | if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) | |
2396 | return; | |
2397 | ||
2398 | switch (data->interface_status.ievent) { | |
2399 | case EVENT_INTERFACE_ADDED: | |
2400 | if (!wpa_s->interface_removed) | |
2401 | break; | |
2402 | wpa_s->interface_removed = 0; | |
f049052b | 2403 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added"); |
6fc6879b | 2404 | if (wpa_supplicant_driver_init(wpa_s) < 0) { |
f049052b BG |
2405 | wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the " |
2406 | "driver after interface was added"); | |
6fc6879b JM |
2407 | } |
2408 | break; | |
2409 | case EVENT_INTERFACE_REMOVED: | |
f049052b | 2410 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed"); |
6fc6879b JM |
2411 | wpa_s->interface_removed = 1; |
2412 | wpa_supplicant_mark_disassoc(wpa_s); | |
cb6710a4 | 2413 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
6fc6879b JM |
2414 | l2_packet_deinit(wpa_s->l2); |
2415 | wpa_s->l2 = NULL; | |
a83d9c96 SL |
2416 | #ifdef CONFIG_TERMINATE_ONLASTIF |
2417 | /* check if last interface */ | |
2418 | if (!any_interfaces(wpa_s->global->ifaces)) | |
2419 | eloop_terminate(); | |
2420 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
6fc6879b JM |
2421 | break; |
2422 | } | |
2423 | } | |
2424 | ||
2425 | ||
2426 | #ifdef CONFIG_PEERKEY | |
2427 | static void | |
2428 | wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s, | |
2429 | union wpa_event_data *data) | |
2430 | { | |
2431 | if (data == NULL) | |
2432 | return; | |
2433 | wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer); | |
2434 | } | |
2435 | #endif /* CONFIG_PEERKEY */ | |
2436 | ||
2437 | ||
281ff0aa GP |
2438 | #ifdef CONFIG_TDLS |
2439 | static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s, | |
2440 | union wpa_event_data *data) | |
2441 | { | |
2442 | if (data == NULL) | |
2443 | return; | |
2444 | switch (data->tdls.oper) { | |
2445 | case TDLS_REQUEST_SETUP: | |
3887878e SD |
2446 | wpa_tdls_remove(wpa_s->wpa, data->tdls.peer); |
2447 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) | |
2448 | wpa_tdls_start(wpa_s->wpa, data->tdls.peer); | |
2449 | else | |
2450 | wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer); | |
281ff0aa GP |
2451 | break; |
2452 | case TDLS_REQUEST_TEARDOWN: | |
f130b105 SD |
2453 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
2454 | wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer, | |
2455 | data->tdls.reason_code); | |
2456 | else | |
2457 | wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, | |
2458 | data->tdls.peer); | |
281ff0aa GP |
2459 | break; |
2460 | } | |
2461 | } | |
2462 | #endif /* CONFIG_TDLS */ | |
2463 | ||
2464 | ||
ad3872a3 | 2465 | #ifdef CONFIG_WNM |
75cad1a0 XC |
2466 | static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s, |
2467 | union wpa_event_data *data) | |
2468 | { | |
2469 | if (data == NULL) | |
2470 | return; | |
2471 | switch (data->wnm.oper) { | |
2472 | case WNM_OPER_SLEEP: | |
2473 | wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request " | |
2474 | "(action=%d, intval=%d)", | |
2475 | data->wnm.sleep_action, data->wnm.sleep_intval); | |
2476 | ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action, | |
cd0ef657 | 2477 | data->wnm.sleep_intval, NULL); |
75cad1a0 XC |
2478 | break; |
2479 | } | |
2480 | } | |
ad3872a3 | 2481 | #endif /* CONFIG_WNM */ |
75cad1a0 XC |
2482 | |
2483 | ||
6fc6879b JM |
2484 | #ifdef CONFIG_IEEE80211R |
2485 | static void | |
2486 | wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s, | |
2487 | union wpa_event_data *data) | |
2488 | { | |
2489 | if (data == NULL) | |
2490 | return; | |
2491 | ||
2492 | if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies, | |
2493 | data->ft_ies.ies_len, | |
2494 | data->ft_ies.ft_action, | |
babfbf15 JM |
2495 | data->ft_ies.target_ap, |
2496 | data->ft_ies.ric_ies, | |
2497 | data->ft_ies.ric_ies_len) < 0) { | |
6fc6879b JM |
2498 | /* TODO: prevent MLME/driver from trying to associate? */ |
2499 | } | |
2500 | } | |
2501 | #endif /* CONFIG_IEEE80211R */ | |
2502 | ||
2503 | ||
11ef8d35 JM |
2504 | #ifdef CONFIG_IBSS_RSN |
2505 | static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s, | |
2506 | union wpa_event_data *data) | |
2507 | { | |
df4bc509 | 2508 | struct wpa_ssid *ssid; |
df418245 XC |
2509 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
2510 | return; | |
11ef8d35 JM |
2511 | if (data == NULL) |
2512 | return; | |
df4bc509 JM |
2513 | ssid = wpa_s->current_ssid; |
2514 | if (ssid == NULL) | |
2515 | return; | |
2516 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) | |
2517 | return; | |
2518 | ||
11ef8d35 JM |
2519 | ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); |
2520 | } | |
13adc57b AQ |
2521 | |
2522 | ||
2523 | static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s, | |
2524 | union wpa_event_data *data) | |
2525 | { | |
2526 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
2527 | ||
2528 | if (ssid == NULL) | |
2529 | return; | |
2530 | ||
2531 | /* check if the ssid is correctly configured as IBSS/RSN */ | |
2532 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) | |
2533 | return; | |
2534 | ||
2535 | ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame, | |
2536 | data->rx_mgmt.frame_len); | |
2537 | } | |
11ef8d35 JM |
2538 | #endif /* CONFIG_IBSS_RSN */ |
2539 | ||
2540 | ||
036f7c4a JM |
2541 | #ifdef CONFIG_IEEE80211R |
2542 | static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data, | |
2543 | size_t len) | |
2544 | { | |
2545 | const u8 *sta_addr, *target_ap_addr; | |
2546 | u16 status; | |
2547 | ||
2548 | wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len); | |
2549 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) | |
2550 | return; /* only SME case supported for now */ | |
2551 | if (len < 1 + 2 * ETH_ALEN + 2) | |
2552 | return; | |
2553 | if (data[0] != 2) | |
2554 | return; /* Only FT Action Response is supported for now */ | |
2555 | sta_addr = data + 1; | |
2556 | target_ap_addr = data + 1 + ETH_ALEN; | |
2557 | status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN); | |
f049052b BG |
2558 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA " |
2559 | MACSTR " TargetAP " MACSTR " status %u", | |
2560 | MAC2STR(sta_addr), MAC2STR(target_ap_addr), status); | |
036f7c4a JM |
2561 | |
2562 | if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) { | |
f049052b BG |
2563 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR |
2564 | " in FT Action Response", MAC2STR(sta_addr)); | |
036f7c4a JM |
2565 | return; |
2566 | } | |
2567 | ||
2568 | if (status) { | |
f049052b BG |
2569 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates " |
2570 | "failure (status code %d)", status); | |
036f7c4a JM |
2571 | /* TODO: report error to FT code(?) */ |
2572 | return; | |
2573 | } | |
2574 | ||
2575 | if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2, | |
2576 | len - (1 + 2 * ETH_ALEN + 2), 1, | |
2577 | target_ap_addr, NULL, 0) < 0) | |
2578 | return; | |
2579 | ||
fe191985 JM |
2580 | #ifdef CONFIG_SME |
2581 | { | |
2582 | struct wpa_bss *bss; | |
2583 | bss = wpa_bss_get_bssid(wpa_s, target_ap_addr); | |
2584 | if (bss) | |
2585 | wpa_s->sme.freq = bss->freq; | |
62c72d72 | 2586 | wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT; |
fe191985 JM |
2587 | sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr, |
2588 | WLAN_AUTH_FT); | |
2589 | } | |
2590 | #endif /* CONFIG_SME */ | |
036f7c4a JM |
2591 | } |
2592 | #endif /* CONFIG_IEEE80211R */ | |
2593 | ||
2594 | ||
7d878ca7 JM |
2595 | static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s, |
2596 | struct unprot_deauth *e) | |
2597 | { | |
2598 | #ifdef CONFIG_IEEE80211W | |
2599 | wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame " | |
2600 | "dropped: " MACSTR " -> " MACSTR | |
2601 | " (reason code %u)", | |
2602 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); | |
2603 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); | |
2604 | #endif /* CONFIG_IEEE80211W */ | |
2605 | } | |
2606 | ||
2607 | ||
2608 | static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s, | |
2609 | struct unprot_disassoc *e) | |
2610 | { | |
2611 | #ifdef CONFIG_IEEE80211W | |
2612 | wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame " | |
2613 | "dropped: " MACSTR " -> " MACSTR | |
2614 | " (reason code %u)", | |
2615 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); | |
2616 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); | |
2617 | #endif /* CONFIG_IEEE80211W */ | |
2618 | } | |
2619 | ||
2620 | ||
d7df0fa7 JM |
2621 | static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr, |
2622 | u16 reason_code, int locally_generated, | |
2623 | const u8 *ie, size_t ie_len, int deauth) | |
2624 | { | |
2625 | #ifdef CONFIG_AP | |
2626 | if (wpa_s->ap_iface && addr) { | |
2627 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr); | |
2628 | return; | |
2629 | } | |
2630 | ||
2631 | if (wpa_s->ap_iface) { | |
2632 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode"); | |
2633 | return; | |
2634 | } | |
2635 | #endif /* CONFIG_AP */ | |
2636 | ||
2637 | wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated); | |
2638 | ||
c60ba9f7 JM |
2639 | if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED || |
2640 | ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || | |
2641 | (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) && | |
2642 | eapol_sm_failed(wpa_s->eapol))) && | |
2643 | !wpa_s->eap_expected_failure)) | |
b19c098e | 2644 | wpas_auth_failed(wpa_s, "AUTH_FAILED"); |
d7df0fa7 JM |
2645 | |
2646 | #ifdef CONFIG_P2P | |
43ee4704 | 2647 | if (deauth && reason_code > 0) { |
d7df0fa7 JM |
2648 | if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len, |
2649 | locally_generated) > 0) { | |
2650 | /* | |
2651 | * The interface was removed, so cannot continue | |
2652 | * processing any additional operations after this. | |
2653 | */ | |
2654 | return; | |
2655 | } | |
2656 | } | |
2657 | #endif /* CONFIG_P2P */ | |
2658 | ||
2659 | wpa_supplicant_event_disassoc_finish(wpa_s, reason_code, | |
2660 | locally_generated); | |
2661 | } | |
2662 | ||
2663 | ||
2664 | static void wpas_event_disassoc(struct wpa_supplicant *wpa_s, | |
2665 | struct disassoc_info *info) | |
2666 | { | |
2667 | u16 reason_code = 0; | |
2668 | int locally_generated = 0; | |
2669 | const u8 *addr = NULL; | |
2670 | const u8 *ie = NULL; | |
2671 | size_t ie_len = 0; | |
2672 | ||
2673 | wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification"); | |
2674 | ||
2675 | if (info) { | |
2676 | addr = info->addr; | |
2677 | ie = info->ie; | |
2678 | ie_len = info->ie_len; | |
2679 | reason_code = info->reason_code; | |
2680 | locally_generated = info->locally_generated; | |
2681 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code, | |
2682 | locally_generated ? " (locally generated)" : ""); | |
2683 | if (addr) | |
2684 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, | |
2685 | MAC2STR(addr)); | |
2686 | wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)", | |
2687 | ie, ie_len); | |
2688 | } | |
2689 | ||
2690 | #ifdef CONFIG_AP | |
2691 | if (wpa_s->ap_iface && info && info->addr) { | |
2692 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr); | |
2693 | return; | |
2694 | } | |
2695 | ||
2696 | if (wpa_s->ap_iface) { | |
2697 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode"); | |
2698 | return; | |
2699 | } | |
2700 | #endif /* CONFIG_AP */ | |
2701 | ||
2702 | #ifdef CONFIG_P2P | |
2703 | if (info) { | |
2704 | wpas_p2p_disassoc_notif( | |
2705 | wpa_s, info->addr, reason_code, info->ie, info->ie_len, | |
2706 | locally_generated); | |
2707 | } | |
2708 | #endif /* CONFIG_P2P */ | |
2709 | ||
2710 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) | |
2711 | sme_event_disassoc(wpa_s, info); | |
2712 | ||
2713 | wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated, | |
2714 | ie, ie_len, 0); | |
2715 | } | |
2716 | ||
2717 | ||
2718 | static void wpas_event_deauth(struct wpa_supplicant *wpa_s, | |
2719 | struct deauth_info *info) | |
2720 | { | |
2721 | u16 reason_code = 0; | |
2722 | int locally_generated = 0; | |
2723 | const u8 *addr = NULL; | |
2724 | const u8 *ie = NULL; | |
2725 | size_t ie_len = 0; | |
2726 | ||
2727 | wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification"); | |
2728 | ||
2729 | if (info) { | |
2730 | addr = info->addr; | |
2731 | ie = info->ie; | |
2732 | ie_len = info->ie_len; | |
2733 | reason_code = info->reason_code; | |
2734 | locally_generated = info->locally_generated; | |
2735 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", | |
2736 | reason_code, | |
2737 | locally_generated ? " (locally generated)" : ""); | |
2738 | if (addr) { | |
2739 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, | |
2740 | MAC2STR(addr)); | |
2741 | } | |
2742 | wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)", | |
2743 | ie, ie_len); | |
2744 | } | |
2745 | ||
2746 | wpa_reset_ft_completed(wpa_s->wpa); | |
2747 | ||
2748 | wpas_event_disconnect(wpa_s, addr, reason_code, | |
2749 | locally_generated, ie, ie_len, 1); | |
2750 | } | |
2751 | ||
2752 | ||
142817b2 JM |
2753 | static const char * reg_init_str(enum reg_change_initiator init) |
2754 | { | |
2755 | switch (init) { | |
2756 | case REGDOM_SET_BY_CORE: | |
2757 | return "CORE"; | |
2758 | case REGDOM_SET_BY_USER: | |
2759 | return "USER"; | |
2760 | case REGDOM_SET_BY_DRIVER: | |
2761 | return "DRIVER"; | |
2762 | case REGDOM_SET_BY_COUNTRY_IE: | |
2763 | return "COUNTRY_IE"; | |
2764 | case REGDOM_BEACON_HINT: | |
2765 | return "BEACON_HINT"; | |
2766 | } | |
2767 | return "?"; | |
2768 | } | |
2769 | ||
2770 | ||
2771 | static const char * reg_type_str(enum reg_type type) | |
2772 | { | |
2773 | switch (type) { | |
2774 | case REGDOM_TYPE_UNKNOWN: | |
2775 | return "UNKNOWN"; | |
2776 | case REGDOM_TYPE_COUNTRY: | |
2777 | return "COUNTRY"; | |
2778 | case REGDOM_TYPE_WORLD: | |
2779 | return "WORLD"; | |
2780 | case REGDOM_TYPE_CUSTOM_WORLD: | |
2781 | return "CUSTOM_WORLD"; | |
2782 | case REGDOM_TYPE_INTERSECTION: | |
2783 | return "INTERSECTION"; | |
2784 | } | |
2785 | return "?"; | |
2786 | } | |
2787 | ||
2788 | ||
2789 | static void wpa_supplicant_update_channel_list( | |
2790 | struct wpa_supplicant *wpa_s, struct channel_list_changed *info) | |
731ca636 | 2791 | { |
731ca636 VKE |
2792 | struct wpa_supplicant *ifs; |
2793 | ||
142817b2 | 2794 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s", |
42619d68 | 2795 | reg_init_str(info->initiator), reg_type_str(info->type), |
142817b2 JM |
2796 | info->alpha2[0] ? " alpha2=" : "", |
2797 | info->alpha2[0] ? info->alpha2 : ""); | |
2798 | ||
731ca636 VKE |
2799 | if (wpa_s->drv_priv == NULL) |
2800 | return; /* Ignore event during drv initialization */ | |
2801 | ||
2802 | free_hw_features(wpa_s); | |
2803 | wpa_s->hw.modes = wpa_drv_get_hw_feature_data( | |
2804 | wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags); | |
2805 | ||
731ca636 | 2806 | wpas_p2p_update_channel_list(wpa_s); |
731ca636 VKE |
2807 | |
2808 | /* | |
c67e7e2a | 2809 | * Check other interfaces to see if they share the same radio. If |
731ca636 VKE |
2810 | * so, they get updated with this same hw mode info. |
2811 | */ | |
c67e7e2a JM |
2812 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
2813 | radio_list) { | |
2814 | if (ifs != wpa_s) { | |
731ca636 VKE |
2815 | wpa_printf(MSG_DEBUG, "%s: Updating hw mode", |
2816 | ifs->ifname); | |
2817 | free_hw_features(ifs); | |
2818 | ifs->hw.modes = wpa_drv_get_hw_feature_data( | |
2819 | ifs, &ifs->hw.num_modes, &ifs->hw.flags); | |
2820 | } | |
2821 | } | |
2822 | } | |
2823 | ||
2824 | ||
dbfb8e82 | 2825 | static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s, |
70d1e728 AO |
2826 | const u8 *frame, size_t len, int freq, |
2827 | int rssi) | |
dbfb8e82 | 2828 | { |
70d95373 | 2829 | const struct ieee80211_mgmt *mgmt; |
dbfb8e82 JM |
2830 | const u8 *payload; |
2831 | size_t plen; | |
2832 | u8 category; | |
2833 | ||
2834 | if (len < IEEE80211_HDRLEN + 2) | |
2835 | return; | |
2836 | ||
70d95373 JM |
2837 | mgmt = (const struct ieee80211_mgmt *) frame; |
2838 | payload = frame + IEEE80211_HDRLEN; | |
dbfb8e82 | 2839 | category = *payload++; |
70d95373 | 2840 | plen = len - IEEE80211_HDRLEN - 1; |
dbfb8e82 JM |
2841 | |
2842 | wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR | |
2843 | " Category=%u DataLen=%d freq=%d MHz", | |
2844 | MAC2STR(mgmt->sa), category, (int) plen, freq); | |
2845 | ||
d1f88001 MB |
2846 | if (category == WLAN_ACTION_WMM) { |
2847 | wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen); | |
2848 | return; | |
2849 | } | |
2850 | ||
dbfb8e82 JM |
2851 | #ifdef CONFIG_IEEE80211R |
2852 | if (category == WLAN_ACTION_FT) { | |
2853 | ft_rx_action(wpa_s, payload, plen); | |
2854 | return; | |
2855 | } | |
2856 | #endif /* CONFIG_IEEE80211R */ | |
2857 | ||
2858 | #ifdef CONFIG_IEEE80211W | |
2859 | #ifdef CONFIG_SME | |
2860 | if (category == WLAN_ACTION_SA_QUERY) { | |
2861 | sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen); | |
2862 | return; | |
2863 | } | |
2864 | #endif /* CONFIG_SME */ | |
2865 | #endif /* CONFIG_IEEE80211W */ | |
2866 | ||
2867 | #ifdef CONFIG_WNM | |
2868 | if (mgmt->u.action.category == WLAN_ACTION_WNM) { | |
2869 | ieee802_11_rx_wnm_action(wpa_s, mgmt, len); | |
2870 | return; | |
2871 | } | |
2872 | #endif /* CONFIG_WNM */ | |
2873 | ||
2874 | #ifdef CONFIG_GAS | |
c5a64e2d JM |
2875 | if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC || |
2876 | mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) && | |
dbfb8e82 | 2877 | gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid, |
c5a64e2d | 2878 | mgmt->u.action.category, |
dbfb8e82 JM |
2879 | payload, plen, freq) == 0) |
2880 | return; | |
2881 | #endif /* CONFIG_GAS */ | |
2882 | ||
2883 | #ifdef CONFIG_TDLS | |
2884 | if (category == WLAN_ACTION_PUBLIC && plen >= 4 && | |
2885 | payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) { | |
2886 | wpa_dbg(wpa_s, MSG_DEBUG, | |
2887 | "TDLS: Received Discovery Response from " MACSTR, | |
2888 | MAC2STR(mgmt->sa)); | |
2889 | return; | |
2890 | } | |
2891 | #endif /* CONFIG_TDLS */ | |
2892 | ||
2893 | #ifdef CONFIG_INTERWORKING | |
2894 | if (category == WLAN_ACTION_QOS && plen >= 1 && | |
2895 | payload[0] == QOS_QOS_MAP_CONFIG) { | |
2896 | const u8 *pos = payload + 1; | |
2897 | size_t qlen = plen - 1; | |
2898 | wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from " | |
2899 | MACSTR, MAC2STR(mgmt->sa)); | |
2900 | if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 && | |
2901 | qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET && | |
2902 | pos[1] <= qlen - 2 && pos[1] >= 16) | |
2903 | wpas_qos_map_set(wpa_s, pos + 2, pos[1]); | |
2904 | return; | |
2905 | } | |
2906 | #endif /* CONFIG_INTERWORKING */ | |
2907 | ||
d89c0701 AK |
2908 | if (category == WLAN_ACTION_RADIO_MEASUREMENT && |
2909 | payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) { | |
2910 | wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1); | |
2911 | return; | |
2912 | } | |
2913 | ||
70d1e728 AO |
2914 | if (category == WLAN_ACTION_RADIO_MEASUREMENT && |
2915 | payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) { | |
2916 | wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa, | |
2917 | payload + 1, plen - 1, | |
2918 | rssi); | |
2919 | return; | |
2920 | } | |
2921 | ||
dbfb8e82 JM |
2922 | wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid, |
2923 | category, payload, plen, freq); | |
5f92659d BC |
2924 | if (wpa_s->ifmsh) |
2925 | mesh_mpm_action_rx(wpa_s, mgmt, len); | |
dbfb8e82 JM |
2926 | } |
2927 | ||
2928 | ||
253f2e37 AH |
2929 | static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s, |
2930 | union wpa_event_data *event) | |
2931 | { | |
2932 | #ifdef CONFIG_P2P | |
2933 | struct wpa_supplicant *ifs; | |
2934 | #endif /* CONFIG_P2P */ | |
2935 | struct wpa_freq_range_list *list; | |
2936 | char *str = NULL; | |
2937 | ||
2938 | list = &event->freq_range; | |
2939 | ||
2940 | if (list->num) | |
2941 | str = freq_range_list_str(list); | |
2942 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s", | |
2943 | str ? str : ""); | |
2944 | ||
2945 | #ifdef CONFIG_P2P | |
2946 | if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) { | |
2947 | wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range", | |
2948 | __func__); | |
2949 | } else { | |
2950 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event"); | |
2951 | wpas_p2p_update_channel_list(wpa_s); | |
2952 | } | |
2953 | ||
2954 | for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { | |
2955 | int freq; | |
2956 | if (!ifs->current_ssid || | |
2957 | !ifs->current_ssid->p2p_group || | |
2958 | (ifs->current_ssid->mode != WPAS_MODE_P2P_GO && | |
2959 | ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION)) | |
2960 | continue; | |
2961 | ||
2962 | freq = ifs->current_ssid->frequency; | |
2963 | if (!freq_range_list_includes(list, freq)) { | |
2964 | wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range", | |
2965 | freq); | |
2966 | continue; | |
2967 | } | |
2968 | ||
2969 | wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz", | |
2970 | freq); | |
2971 | /* TODO: Consider using CSA or removing the group within | |
2972 | * wpa_supplicant */ | |
2973 | wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP); | |
2974 | } | |
2975 | #endif /* CONFIG_P2P */ | |
2976 | ||
2977 | os_free(str); | |
2978 | } | |
2979 | ||
2980 | ||
b41f2684 CL |
2981 | static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s, |
2982 | union wpa_event_data *data) | |
2983 | { | |
2984 | wpa_dbg(wpa_s, MSG_DEBUG, | |
2985 | "Connection authorized by device, previous state %d", | |
2986 | wpa_s->wpa_state); | |
2987 | if (wpa_s->wpa_state == WPA_ASSOCIATED) { | |
2988 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
2989 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
2990 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
2991 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
2992 | } | |
2993 | wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr); | |
2994 | wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck, | |
2995 | data->assoc_info.ptk_kek); | |
2996 | } | |
2997 | ||
2998 | ||
9646a8ab | 2999 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
6fc6879b JM |
3000 | union wpa_event_data *data) |
3001 | { | |
3002 | struct wpa_supplicant *wpa_s = ctx; | |
3003 | ||
8401a6b0 JM |
3004 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED && |
3005 | event != EVENT_INTERFACE_ENABLED && | |
9b6f44cb JM |
3006 | event != EVENT_INTERFACE_STATUS && |
3007 | event != EVENT_SCHED_SCAN_STOPPED) { | |
6c3771d7 BG |
3008 | wpa_dbg(wpa_s, MSG_DEBUG, |
3009 | "Ignore event %s (%d) while interface is disabled", | |
3010 | event_to_string(event), event); | |
8401a6b0 JM |
3011 | return; |
3012 | } | |
3013 | ||
74781dfc JM |
3014 | #ifndef CONFIG_NO_STDOUT_DEBUG |
3015 | { | |
3016 | int level = MSG_DEBUG; | |
3017 | ||
eab6f5e0 | 3018 | if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) { |
74781dfc JM |
3019 | const struct ieee80211_hdr *hdr; |
3020 | u16 fc; | |
3021 | hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; | |
3022 | fc = le_to_host16(hdr->frame_control); | |
3023 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
3024 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) | |
3025 | level = MSG_EXCESSIVE; | |
3026 | } | |
3027 | ||
3028 | wpa_dbg(wpa_s, level, "Event %s (%d) received", | |
6c3771d7 | 3029 | event_to_string(event), event); |
74781dfc JM |
3030 | } |
3031 | #endif /* CONFIG_NO_STDOUT_DEBUG */ | |
9b7124b2 | 3032 | |
6fc6879b | 3033 | switch (event) { |
c2a04078 JM |
3034 | case EVENT_AUTH: |
3035 | sme_event_auth(wpa_s, data); | |
3036 | break; | |
6fc6879b JM |
3037 | case EVENT_ASSOC: |
3038 | wpa_supplicant_event_assoc(wpa_s, data); | |
b41f2684 CL |
3039 | if (data && data->assoc_info.authorized) |
3040 | wpa_supplicant_event_assoc_auth(wpa_s, data); | |
6fc6879b JM |
3041 | break; |
3042 | case EVENT_DISASSOC: | |
d7df0fa7 JM |
3043 | wpas_event_disassoc(wpa_s, |
3044 | data ? &data->disassoc_info : NULL); | |
3045 | break; | |
a84ed99e | 3046 | case EVENT_DEAUTH: |
d7df0fa7 JM |
3047 | wpas_event_deauth(wpa_s, |
3048 | data ? &data->deauth_info : NULL); | |
6fc6879b JM |
3049 | break; |
3050 | case EVENT_MICHAEL_MIC_FAILURE: | |
3051 | wpa_supplicant_event_michael_mic_failure(wpa_s, data); | |
3052 | break; | |
3053 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
a5f40eff | 3054 | case EVENT_SCAN_STARTED: |
dc3906cb | 3055 | os_get_reltime(&wpa_s->scan_start_time); |
a5f40eff | 3056 | if (wpa_s->own_scan_requested) { |
dc3906cb JM |
3057 | struct os_reltime diff; |
3058 | ||
3059 | os_reltime_sub(&wpa_s->scan_start_time, | |
3060 | &wpa_s->scan_trigger_time, &diff); | |
3061 | wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds", | |
3062 | diff.sec, diff.usec); | |
a5f40eff JM |
3063 | wpa_s->own_scan_requested = 0; |
3064 | wpa_s->own_scan_running = 1; | |
d81c73be JM |
3065 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
3066 | wpa_s->manual_scan_use_id) { | |
abc05534 DS |
3067 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
3068 | WPA_EVENT_SCAN_STARTED "id=%u", | |
3069 | wpa_s->manual_scan_id); | |
d81c73be | 3070 | } else { |
abc05534 DS |
3071 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
3072 | WPA_EVENT_SCAN_STARTED); | |
d81c73be | 3073 | } |
a5f40eff JM |
3074 | } else { |
3075 | wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan"); | |
3076 | wpa_s->external_scan_running = 1; | |
abc05534 | 3077 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED); |
a5f40eff JM |
3078 | } |
3079 | break; | |
6fc6879b | 3080 | case EVENT_SCAN_RESULTS: |
dc3906cb JM |
3081 | if (os_reltime_initialized(&wpa_s->scan_start_time)) { |
3082 | struct os_reltime now, diff; | |
3083 | os_get_reltime(&now); | |
3084 | os_reltime_sub(&now, &wpa_s->scan_start_time, &diff); | |
3085 | wpa_s->scan_start_time.sec = 0; | |
3086 | wpa_s->scan_start_time.usec = 0; | |
3087 | wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds", | |
3088 | diff.sec, diff.usec); | |
3089 | } | |
8d923a4a | 3090 | wpa_supplicant_event_scan_results(wpa_s, data); |
a5f40eff JM |
3091 | wpa_s->own_scan_running = 0; |
3092 | wpa_s->external_scan_running = 0; | |
6428d0a7 | 3093 | radio_work_check_next(wpa_s); |
6fc6879b JM |
3094 | break; |
3095 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | |
3096 | case EVENT_ASSOCINFO: | |
3097 | wpa_supplicant_event_associnfo(wpa_s, data); | |
3098 | break; | |
3099 | case EVENT_INTERFACE_STATUS: | |
3100 | wpa_supplicant_event_interface_status(wpa_s, data); | |
3101 | break; | |
3102 | case EVENT_PMKID_CANDIDATE: | |
3103 | wpa_supplicant_event_pmkid_candidate(wpa_s, data); | |
3104 | break; | |
3105 | #ifdef CONFIG_PEERKEY | |
3106 | case EVENT_STKSTART: | |
3107 | wpa_supplicant_event_stkstart(wpa_s, data); | |
3108 | break; | |
3109 | #endif /* CONFIG_PEERKEY */ | |
281ff0aa GP |
3110 | #ifdef CONFIG_TDLS |
3111 | case EVENT_TDLS: | |
3112 | wpa_supplicant_event_tdls(wpa_s, data); | |
3113 | break; | |
3114 | #endif /* CONFIG_TDLS */ | |
ad3872a3 | 3115 | #ifdef CONFIG_WNM |
75cad1a0 XC |
3116 | case EVENT_WNM: |
3117 | wpa_supplicant_event_wnm(wpa_s, data); | |
3118 | break; | |
ad3872a3 | 3119 | #endif /* CONFIG_WNM */ |
6fc6879b JM |
3120 | #ifdef CONFIG_IEEE80211R |
3121 | case EVENT_FT_RESPONSE: | |
3122 | wpa_supplicant_event_ft_response(wpa_s, data); | |
3123 | break; | |
3124 | #endif /* CONFIG_IEEE80211R */ | |
11ef8d35 JM |
3125 | #ifdef CONFIG_IBSS_RSN |
3126 | case EVENT_IBSS_RSN_START: | |
3127 | wpa_supplicant_event_ibss_rsn_start(wpa_s, data); | |
3128 | break; | |
3129 | #endif /* CONFIG_IBSS_RSN */ | |
efa46078 | 3130 | case EVENT_ASSOC_REJECT: |
c05d6d18 JM |
3131 | if (data->assoc_reject.bssid) |
3132 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT | |
3133 | "bssid=" MACSTR " status_code=%u", | |
3134 | MAC2STR(data->assoc_reject.bssid), | |
3135 | data->assoc_reject.status_code); | |
3136 | else | |
3137 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT | |
3138 | "status_code=%u", | |
3139 | data->assoc_reject.status_code); | |
ea78c315 JM |
3140 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
3141 | sme_event_assoc_reject(wpa_s, data); | |
10737aba JM |
3142 | else { |
3143 | const u8 *bssid = data->assoc_reject.bssid; | |
3144 | if (bssid == NULL || is_zero_ether_addr(bssid)) | |
3145 | bssid = wpa_s->pending_bssid; | |
3146 | wpas_connection_failed(wpa_s, bssid); | |
3147 | wpa_supplicant_mark_disassoc(wpa_s); | |
3148 | } | |
efa46078 | 3149 | break; |
da1fb17c | 3150 | case EVENT_AUTH_TIMED_OUT: |
9a700ff9 JM |
3151 | /* It is possible to get this event from earlier connection */ |
3152 | if (wpa_s->current_ssid && | |
3153 | wpa_s->current_ssid->mode == WPAS_MODE_MESH) { | |
3154 | wpa_dbg(wpa_s, MSG_DEBUG, | |
3155 | "Ignore AUTH_TIMED_OUT in mesh configuration"); | |
3156 | break; | |
3157 | } | |
ea78c315 JM |
3158 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
3159 | sme_event_auth_timed_out(wpa_s, data); | |
da1fb17c JM |
3160 | break; |
3161 | case EVENT_ASSOC_TIMED_OUT: | |
9a700ff9 JM |
3162 | /* It is possible to get this event from earlier connection */ |
3163 | if (wpa_s->current_ssid && | |
3164 | wpa_s->current_ssid->mode == WPAS_MODE_MESH) { | |
3165 | wpa_dbg(wpa_s, MSG_DEBUG, | |
3166 | "Ignore ASSOC_TIMED_OUT in mesh configuration"); | |
3167 | break; | |
3168 | } | |
ea78c315 JM |
3169 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
3170 | sme_event_assoc_timed_out(wpa_s, data); | |
da1fb17c | 3171 | break; |
f8b1f695 | 3172 | case EVENT_TX_STATUS: |
f049052b BG |
3173 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR |
3174 | " type=%d stype=%d", | |
3175 | MAC2STR(data->tx_status.dst), | |
3176 | data->tx_status.type, data->tx_status.stype); | |
24f6497c | 3177 | #ifdef CONFIG_AP |
9bae1be0 | 3178 | if (wpa_s->ap_iface == NULL) { |
24f6497c | 3179 | #ifdef CONFIG_OFFCHANNEL |
9bae1be0 JM |
3180 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
3181 | data->tx_status.stype == WLAN_FC_STYPE_ACTION) | |
24f6497c | 3182 | offchannel_send_action_tx_status( |
9bae1be0 JM |
3183 | wpa_s, data->tx_status.dst, |
3184 | data->tx_status.data, | |
3185 | data->tx_status.data_len, | |
93b7ddd0 | 3186 | data->tx_status.ack ? |
24f6497c JM |
3187 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
3188 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
3189 | #endif /* CONFIG_OFFCHANNEL */ | |
9bae1be0 JM |
3190 | break; |
3191 | } | |
24f6497c JM |
3192 | #endif /* CONFIG_AP */ |
3193 | #ifdef CONFIG_OFFCHANNEL | |
f049052b BG |
3194 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst=" |
3195 | MACSTR, MAC2STR(wpa_s->parent->pending_action_dst)); | |
9bae1be0 JM |
3196 | /* |
3197 | * Catch TX status events for Action frames we sent via group | |
3198 | * interface in GO mode. | |
3199 | */ | |
3200 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && | |
3201 | data->tx_status.stype == WLAN_FC_STYPE_ACTION && | |
3202 | os_memcmp(wpa_s->parent->pending_action_dst, | |
3203 | data->tx_status.dst, ETH_ALEN) == 0) { | |
24f6497c | 3204 | offchannel_send_action_tx_status( |
9bae1be0 JM |
3205 | wpa_s->parent, data->tx_status.dst, |
3206 | data->tx_status.data, | |
3207 | data->tx_status.data_len, | |
1d39378a | 3208 | data->tx_status.ack ? |
24f6497c JM |
3209 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
3210 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
f8b1f695 | 3211 | break; |
9bae1be0 | 3212 | } |
24f6497c JM |
3213 | #endif /* CONFIG_OFFCHANNEL */ |
3214 | #ifdef CONFIG_AP | |
f8b1f695 JM |
3215 | switch (data->tx_status.type) { |
3216 | case WLAN_FC_TYPE_MGMT: | |
3217 | ap_mgmt_tx_cb(wpa_s, data->tx_status.data, | |
3218 | data->tx_status.data_len, | |
3219 | data->tx_status.stype, | |
3220 | data->tx_status.ack); | |
3221 | break; | |
3222 | case WLAN_FC_TYPE_DATA: | |
3223 | ap_tx_status(wpa_s, data->tx_status.dst, | |
3224 | data->tx_status.data, | |
3225 | data->tx_status.data_len, | |
3226 | data->tx_status.ack); | |
3227 | break; | |
3228 | } | |
24f6497c | 3229 | #endif /* CONFIG_AP */ |
f8b1f695 | 3230 | break; |
24f6497c | 3231 | #ifdef CONFIG_AP |
dd840f79 JB |
3232 | case EVENT_EAPOL_TX_STATUS: |
3233 | ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst, | |
3234 | data->eapol_tx_status.data, | |
3235 | data->eapol_tx_status.data_len, | |
3236 | data->eapol_tx_status.ack); | |
3237 | break; | |
bcf24348 JB |
3238 | case EVENT_DRIVER_CLIENT_POLL_OK: |
3239 | ap_client_poll_ok(wpa_s, data->client_poll.addr); | |
3240 | break; | |
f8b1f695 JM |
3241 | case EVENT_RX_FROM_UNKNOWN: |
3242 | if (wpa_s->ap_iface == NULL) | |
3243 | break; | |
9b90955e JB |
3244 | ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr, |
3245 | data->rx_from_unknown.wds); | |
f8b1f695 | 3246 | break; |
1b487b8b TP |
3247 | case EVENT_CH_SWITCH: |
3248 | if (!data) | |
3249 | break; | |
3250 | if (!wpa_s->ap_iface) { | |
3251 | wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch " | |
3252 | "event in non-AP mode"); | |
3253 | break; | |
3254 | } | |
3255 | ||
1b487b8b TP |
3256 | wpas_ap_ch_switch(wpa_s, data->ch_switch.freq, |
3257 | data->ch_switch.ht_enabled, | |
8d1fdde7 JD |
3258 | data->ch_switch.ch_offset, |
3259 | data->ch_switch.ch_width, | |
3260 | data->ch_switch.cf1, | |
3261 | data->ch_switch.cf2); | |
1b487b8b | 3262 | break; |
13adc57b | 3263 | #endif /* CONFIG_AP */ |
2d43d37f JB |
3264 | case EVENT_RX_MGMT: { |
3265 | u16 fc, stype; | |
3266 | const struct ieee80211_mgmt *mgmt; | |
3267 | ||
60b893df JM |
3268 | #ifdef CONFIG_TESTING_OPTIONS |
3269 | if (wpa_s->ext_mgmt_frame_handling) { | |
3270 | struct rx_mgmt *rx = &data->rx_mgmt; | |
3271 | size_t hex_len = 2 * rx->frame_len + 1; | |
3272 | char *hex = os_malloc(hex_len); | |
3273 | if (hex) { | |
3274 | wpa_snprintf_hex(hex, hex_len, | |
3275 | rx->frame, rx->frame_len); | |
3276 | wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s", | |
3277 | rx->freq, rx->datarate, rx->ssi_signal, | |
3278 | hex); | |
3279 | os_free(hex); | |
3280 | } | |
3281 | break; | |
3282 | } | |
3283 | #endif /* CONFIG_TESTING_OPTIONS */ | |
3284 | ||
2d43d37f JB |
3285 | mgmt = (const struct ieee80211_mgmt *) |
3286 | data->rx_mgmt.frame; | |
3287 | fc = le_to_host16(mgmt->frame_control); | |
3288 | stype = WLAN_FC_GET_STYPE(fc); | |
3289 | ||
13adc57b | 3290 | #ifdef CONFIG_AP |
9bae1be0 | 3291 | if (wpa_s->ap_iface == NULL) { |
13adc57b | 3292 | #endif /* CONFIG_AP */ |
9bae1be0 | 3293 | #ifdef CONFIG_P2P |
9bae1be0 JM |
3294 | if (stype == WLAN_FC_STYPE_PROBE_REQ && |
3295 | data->rx_mgmt.frame_len > 24) { | |
3296 | const u8 *src = mgmt->sa; | |
3297 | const u8 *ie = mgmt->u.probe_req.variable; | |
3298 | size_t ie_len = data->rx_mgmt.frame_len - | |
3299 | (mgmt->u.probe_req.variable - | |
3300 | data->rx_mgmt.frame); | |
baf513d6 JB |
3301 | wpas_p2p_probe_req_rx( |
3302 | wpa_s, src, mgmt->da, | |
3303 | mgmt->bssid, ie, ie_len, | |
3304 | data->rx_mgmt.ssi_signal); | |
9bae1be0 JM |
3305 | break; |
3306 | } | |
3307 | #endif /* CONFIG_P2P */ | |
13adc57b | 3308 | #ifdef CONFIG_IBSS_RSN |
5f92659d BC |
3309 | if (wpa_s->current_ssid && |
3310 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && | |
3311 | stype == WLAN_FC_STYPE_AUTH && | |
13adc57b AQ |
3312 | data->rx_mgmt.frame_len >= 30) { |
3313 | wpa_supplicant_event_ibss_auth(wpa_s, data); | |
3314 | break; | |
3315 | } | |
3316 | #endif /* CONFIG_IBSS_RSN */ | |
dbfb8e82 JM |
3317 | |
3318 | if (stype == WLAN_FC_STYPE_ACTION) { | |
3319 | wpas_event_rx_mgmt_action( | |
70d95373 JM |
3320 | wpa_s, data->rx_mgmt.frame, |
3321 | data->rx_mgmt.frame_len, | |
70d1e728 AO |
3322 | data->rx_mgmt.freq, |
3323 | data->rx_mgmt.ssi_signal); | |
dbfb8e82 JM |
3324 | break; |
3325 | } | |
3326 | ||
5f92659d BC |
3327 | if (wpa_s->ifmsh) { |
3328 | mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt); | |
3329 | break; | |
3330 | } | |
3331 | ||
f049052b BG |
3332 | wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received " |
3333 | "management frame in non-AP mode"); | |
f8b1f695 | 3334 | break; |
13adc57b | 3335 | #ifdef CONFIG_AP |
9bae1be0 | 3336 | } |
2d43d37f JB |
3337 | |
3338 | if (stype == WLAN_FC_STYPE_PROBE_REQ && | |
3339 | data->rx_mgmt.frame_len > 24) { | |
3340 | const u8 *ie = mgmt->u.probe_req.variable; | |
3341 | size_t ie_len = data->rx_mgmt.frame_len - | |
3342 | (mgmt->u.probe_req.variable - | |
3343 | data->rx_mgmt.frame); | |
3344 | ||
3345 | wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da, | |
3346 | mgmt->bssid, ie, ie_len, | |
3347 | data->rx_mgmt.ssi_signal); | |
2d43d37f JB |
3348 | } |
3349 | ||
2a8b7416 | 3350 | ap_mgmt_rx(wpa_s, &data->rx_mgmt); |
13adc57b | 3351 | #endif /* CONFIG_AP */ |
f8b1f695 | 3352 | break; |
2d43d37f | 3353 | } |
e67b55fb | 3354 | case EVENT_RX_PROBE_REQ: |
b211f3eb JM |
3355 | if (data->rx_probe_req.sa == NULL || |
3356 | data->rx_probe_req.ie == NULL) | |
3357 | break; | |
e67b55fb JM |
3358 | #ifdef CONFIG_AP |
3359 | if (wpa_s->ap_iface) { | |
3360 | hostapd_probe_req_rx(wpa_s->ap_iface->bss[0], | |
3361 | data->rx_probe_req.sa, | |
04a85e44 JM |
3362 | data->rx_probe_req.da, |
3363 | data->rx_probe_req.bssid, | |
e67b55fb | 3364 | data->rx_probe_req.ie, |
baf513d6 JB |
3365 | data->rx_probe_req.ie_len, |
3366 | data->rx_probe_req.ssi_signal); | |
e67b55fb JM |
3367 | break; |
3368 | } | |
3369 | #endif /* CONFIG_AP */ | |
e67b55fb | 3370 | wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa, |
04a85e44 JM |
3371 | data->rx_probe_req.da, |
3372 | data->rx_probe_req.bssid, | |
e67b55fb | 3373 | data->rx_probe_req.ie, |
baf513d6 JB |
3374 | data->rx_probe_req.ie_len, |
3375 | data->rx_probe_req.ssi_signal); | |
036f7c4a | 3376 | break; |
9bae1be0 | 3377 | case EVENT_REMAIN_ON_CHANNEL: |
24f6497c JM |
3378 | #ifdef CONFIG_OFFCHANNEL |
3379 | offchannel_remain_on_channel_cb( | |
3380 | wpa_s, data->remain_on_channel.freq, | |
3381 | data->remain_on_channel.duration); | |
3382 | #endif /* CONFIG_OFFCHANNEL */ | |
9bae1be0 JM |
3383 | wpas_p2p_remain_on_channel_cb( |
3384 | wpa_s, data->remain_on_channel.freq, | |
3385 | data->remain_on_channel.duration); | |
3386 | break; | |
3387 | case EVENT_CANCEL_REMAIN_ON_CHANNEL: | |
24f6497c JM |
3388 | #ifdef CONFIG_OFFCHANNEL |
3389 | offchannel_cancel_remain_on_channel_cb( | |
3390 | wpa_s, data->remain_on_channel.freq); | |
3391 | #endif /* CONFIG_OFFCHANNEL */ | |
9bae1be0 JM |
3392 | wpas_p2p_cancel_remain_on_channel_cb( |
3393 | wpa_s, data->remain_on_channel.freq); | |
3394 | break; | |
a8e0505b JM |
3395 | case EVENT_EAPOL_RX: |
3396 | wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src, | |
3397 | data->eapol_rx.data, | |
3398 | data->eapol_rx.data_len); | |
3399 | break; | |
e2f74005 | 3400 | case EVENT_SIGNAL_CHANGE: |
0cd86028 JM |
3401 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE |
3402 | "above=%d signal=%d noise=%d txrate=%d", | |
3403 | data->signal_change.above_threshold, | |
3404 | data->signal_change.current_signal, | |
3405 | data->signal_change.current_noise, | |
3406 | data->signal_change.current_txrate); | |
e2f74005 | 3407 | bgscan_notify_signal_change( |
60a972a6 | 3408 | wpa_s, data->signal_change.above_threshold, |
174fa789 PS |
3409 | data->signal_change.current_signal, |
3410 | data->signal_change.current_noise, | |
3411 | data->signal_change.current_txrate); | |
e2f74005 | 3412 | break; |
8401a6b0 | 3413 | case EVENT_INTERFACE_ENABLED: |
f049052b | 3414 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled"); |
8401a6b0 | 3415 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
bfba8deb | 3416 | wpa_supplicant_update_mac_addr(wpa_s); |
782e2f78 IP |
3417 | if (wpa_s->p2p_mgmt) { |
3418 | wpa_supplicant_set_state(wpa_s, | |
3419 | WPA_DISCONNECTED); | |
3420 | break; | |
3421 | } | |
3422 | ||
199716ad | 3423 | #ifdef CONFIG_AP |
9919f7a2 JB |
3424 | if (!wpa_s->ap_iface) { |
3425 | wpa_supplicant_set_state(wpa_s, | |
3426 | WPA_DISCONNECTED); | |
635874b5 | 3427 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
9919f7a2 JB |
3428 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
3429 | } else | |
3430 | wpa_supplicant_set_state(wpa_s, | |
3431 | WPA_COMPLETED); | |
199716ad BG |
3432 | #else /* CONFIG_AP */ |
3433 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
3434 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
3435 | #endif /* CONFIG_AP */ | |
8401a6b0 JM |
3436 | } |
3437 | break; | |
3438 | case EVENT_INTERFACE_DISABLED: | |
f049052b | 3439 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled"); |
6f72577f IP |
3440 | #ifdef CONFIG_P2P |
3441 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO || | |
3442 | (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group && | |
3443 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) { | |
635874b5 JM |
3444 | /* |
3445 | * Mark interface disabled if this happens to end up not | |
3446 | * being removed as a separate P2P group interface. | |
3447 | */ | |
3448 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); | |
6f72577f IP |
3449 | /* |
3450 | * The interface was externally disabled. Remove | |
3451 | * it assuming an external entity will start a | |
3452 | * new session if needed. | |
3453 | */ | |
8f2cf379 JM |
3454 | if (wpa_s->current_ssid && |
3455 | wpa_s->current_ssid->p2p_group) | |
3456 | wpas_p2p_interface_unavailable(wpa_s); | |
3457 | else | |
3458 | wpas_p2p_disconnect(wpa_s); | |
635874b5 JM |
3459 | /* |
3460 | * wpa_s instance may have been freed, so must not use | |
3461 | * it here anymore. | |
3462 | */ | |
6f72577f IP |
3463 | break; |
3464 | } | |
c71c2416 JM |
3465 | if (wpa_s->p2p_scan_work && wpa_s->global->p2p && |
3466 | p2p_in_progress(wpa_s->global->p2p) > 1) { | |
3467 | /* This radio work will be cancelled, so clear P2P | |
3468 | * state as well. | |
3469 | */ | |
3470 | p2p_stop_find(wpa_s->global->p2p); | |
3471 | } | |
6f72577f IP |
3472 | #endif /* CONFIG_P2P */ |
3473 | ||
b7a6702f JM |
3474 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
3475 | /* | |
3476 | * Indicate disconnection to keep ctrl_iface events | |
3477 | * consistent. | |
3478 | */ | |
3479 | wpa_supplicant_event_disassoc( | |
3480 | wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1); | |
3481 | } | |
8401a6b0 | 3482 | wpa_supplicant_mark_disassoc(wpa_s); |
b3253ebb AO |
3483 | radio_remove_works(wpa_s, NULL, 0); |
3484 | ||
8401a6b0 JM |
3485 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
3486 | break; | |
b5c9da8d | 3487 | case EVENT_CHANNEL_LIST_CHANGED: |
142817b2 JM |
3488 | wpa_supplicant_update_channel_list( |
3489 | wpa_s, &data->channel_list_changed); | |
c973f386 JM |
3490 | break; |
3491 | case EVENT_INTERFACE_UNAVAILABLE: | |
c973f386 | 3492 | wpas_p2p_interface_unavailable(wpa_s); |
7cfc4ac3 AGS |
3493 | break; |
3494 | case EVENT_BEST_CHANNEL: | |
f049052b BG |
3495 | wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received " |
3496 | "(%d %d %d)", | |
3497 | data->best_chan.freq_24, data->best_chan.freq_5, | |
3498 | data->best_chan.freq_overall); | |
7cfc4ac3 AGS |
3499 | wpa_s->best_24_freq = data->best_chan.freq_24; |
3500 | wpa_s->best_5_freq = data->best_chan.freq_5; | |
3501 | wpa_s->best_overall_freq = data->best_chan.freq_overall; | |
7cfc4ac3 AGS |
3502 | wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24, |
3503 | data->best_chan.freq_5, | |
3504 | data->best_chan.freq_overall); | |
b5c9da8d | 3505 | break; |
7d878ca7 JM |
3506 | case EVENT_UNPROT_DEAUTH: |
3507 | wpa_supplicant_event_unprot_deauth(wpa_s, | |
3508 | &data->unprot_deauth); | |
3509 | break; | |
3510 | case EVENT_UNPROT_DISASSOC: | |
3511 | wpa_supplicant_event_unprot_disassoc(wpa_s, | |
3512 | &data->unprot_disassoc); | |
3513 | break; | |
0d7e5a3a JB |
3514 | case EVENT_STATION_LOW_ACK: |
3515 | #ifdef CONFIG_AP | |
3516 | if (wpa_s->ap_iface && data) | |
3517 | hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0], | |
3518 | data->low_ack.addr); | |
3519 | #endif /* CONFIG_AP */ | |
8f15f711 AN |
3520 | #ifdef CONFIG_TDLS |
3521 | if (data) | |
947f900f AN |
3522 | wpa_tdls_disable_unreachable_link(wpa_s->wpa, |
3523 | data->low_ack.addr); | |
8f15f711 | 3524 | #endif /* CONFIG_TDLS */ |
0d7e5a3a | 3525 | break; |
ea244d21 XC |
3526 | case EVENT_IBSS_PEER_LOST: |
3527 | #ifdef CONFIG_IBSS_RSN | |
3528 | ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer); | |
3529 | #endif /* CONFIG_IBSS_RSN */ | |
3530 | break; | |
b14a210c JB |
3531 | case EVENT_DRIVER_GTK_REKEY: |
3532 | if (os_memcmp(data->driver_gtk_rekey.bssid, | |
3533 | wpa_s->bssid, ETH_ALEN)) | |
3534 | break; | |
3535 | if (!wpa_s->wpa) | |
3536 | break; | |
3537 | wpa_sm_update_replay_ctr(wpa_s->wpa, | |
3538 | data->driver_gtk_rekey.replay_ctr); | |
3539 | break; | |
cbdf3507 | 3540 | case EVENT_SCHED_SCAN_STOPPED: |
dd271857 | 3541 | wpa_s->pno = 0; |
cbdf3507 LC |
3542 | wpa_s->sched_scanning = 0; |
3543 | wpa_supplicant_notify_scanning(wpa_s, 0); | |
3544 | ||
9b6f44cb JM |
3545 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
3546 | break; | |
3547 | ||
cbdf3507 | 3548 | /* |
cf70d298 RM |
3549 | * Start a new sched scan to continue searching for more SSIDs |
3550 | * either if timed out or PNO schedule scan is pending. | |
cbdf3507 | 3551 | */ |
5e3ddf4d AB |
3552 | if (wpa_s->sched_scan_timed_out) { |
3553 | wpa_supplicant_req_sched_scan(wpa_s); | |
3554 | } else if (wpa_s->pno_sched_pending) { | |
3555 | wpa_s->pno_sched_pending = 0; | |
3556 | wpas_start_pno(wpa_s); | |
cf70d298 RM |
3557 | } |
3558 | ||
cbdf3507 | 3559 | break; |
783fcb7d GG |
3560 | case EVENT_WPS_BUTTON_PUSHED: |
3561 | #ifdef CONFIG_WPS | |
3562 | wpas_wps_start_pbc(wpa_s, NULL, 0); | |
3563 | #endif /* CONFIG_WPS */ | |
3564 | break; | |
253f2e37 AH |
3565 | case EVENT_AVOID_FREQUENCIES: |
3566 | wpa_supplicant_notify_avoid_freq(wpa_s, data); | |
3567 | break; | |
3140803b RM |
3568 | case EVENT_CONNECT_FAILED_REASON: |
3569 | #ifdef CONFIG_AP | |
3570 | if (!wpa_s->ap_iface || !data) | |
3571 | break; | |
3572 | hostapd_event_connect_failed_reason( | |
3573 | wpa_s->ap_iface->bss[0], | |
3574 | data->connect_failed_reason.addr, | |
3575 | data->connect_failed_reason.code); | |
3576 | #endif /* CONFIG_AP */ | |
3577 | break; | |
8319e312 | 3578 | case EVENT_NEW_PEER_CANDIDATE: |
eac02316 MH |
3579 | #ifdef CONFIG_MESH |
3580 | if (!wpa_s->ifmsh || !data) | |
3581 | break; | |
8319e312 TP |
3582 | wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer, |
3583 | data->mesh_peer.ies, | |
3584 | data->mesh_peer.ie_len); | |
eac02316 | 3585 | #endif /* CONFIG_MESH */ |
8319e312 | 3586 | break; |
6fc6879b | 3587 | default: |
f049052b | 3588 | wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event); |
6fc6879b JM |
3589 | break; |
3590 | } | |
3591 | } |