]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant - Driver event processing | |
16a83d29 | 3 | * Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi> |
6fc6879b JM |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License version 2 as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * Alternatively, this software may be distributed under the terms of BSD | |
10 | * license. | |
11 | * | |
12 | * See README and COPYING for more details. | |
13 | */ | |
14 | ||
15 | #include "includes.h" | |
16 | ||
17 | #include "common.h" | |
18 | #include "eapol_supp/eapol_supp_sm.h" | |
3acb5005 | 19 | #include "rsn_supp/wpa.h" |
6fc6879b | 20 | #include "eloop.h" |
6fc6879b JM |
21 | #include "config.h" |
22 | #include "l2_packet/l2_packet.h" | |
23 | #include "wpa_supplicant_i.h" | |
2d5b792d | 24 | #include "driver_i.h" |
6fc6879b | 25 | #include "pcsc_funcs.h" |
3acb5005 JM |
26 | #include "rsn_supp/preauth.h" |
27 | #include "rsn_supp/pmksa_cache.h" | |
90973fb2 | 28 | #include "common/wpa_ctrl.h" |
6fc6879b | 29 | #include "eap_peer/eap.h" |
1d041bec | 30 | #include "ap/hostapd.h" |
93b7ddd0 | 31 | #include "p2p/p2p.h" |
8bac466b | 32 | #include "notify.h" |
90973fb2 | 33 | #include "common/ieee802_11_defs.h" |
54f489be | 34 | #include "common/ieee802_11_common.h" |
bbb921da | 35 | #include "crypto/random.h" |
6fc6879b JM |
36 | #include "blacklist.h" |
37 | #include "wpas_glue.h" | |
351f09a2 | 38 | #include "wps_supplicant.h" |
11ef8d35 | 39 | #include "ibss_rsn.h" |
c2a04078 | 40 | #include "sme.h" |
04ea7b79 | 41 | #include "gas_query.h" |
9bae1be0 | 42 | #include "p2p_supplicant.h" |
60b94c98 | 43 | #include "bgscan.h" |
f8b1f695 | 44 | #include "ap.h" |
6fa81a3b | 45 | #include "bss.h" |
245519e0 | 46 | #include "mlme.h" |
9ba9fa07 | 47 | #include "scan.h" |
24f6497c | 48 | #include "offchannel.h" |
6fc6879b JM |
49 | |
50 | ||
51 | static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s) | |
52 | { | |
8bac466b | 53 | struct wpa_ssid *ssid, *old_ssid; |
6fc6879b JM |
54 | |
55 | if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) | |
56 | return 0; | |
57 | ||
f049052b BG |
58 | wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association " |
59 | "information"); | |
6fc6879b JM |
60 | ssid = wpa_supplicant_get_ssid(wpa_s); |
61 | if (ssid == NULL) { | |
f049052b BG |
62 | wpa_msg(wpa_s, MSG_INFO, |
63 | "No network configuration found for the current AP"); | |
6fc6879b JM |
64 | return -1; |
65 | } | |
66 | ||
67 | if (ssid->disabled) { | |
f049052b | 68 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled"); |
6fc6879b JM |
69 | return -1; |
70 | } | |
71 | ||
f049052b BG |
72 | wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the " |
73 | "current AP"); | |
6fc6879b JM |
74 | if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X | |
75 | WPA_KEY_MGMT_WPA_NONE | | |
56586197 JM |
76 | WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X | |
77 | WPA_KEY_MGMT_PSK_SHA256 | | |
78 | WPA_KEY_MGMT_IEEE8021X_SHA256)) { | |
6fc6879b JM |
79 | u8 wpa_ie[80]; |
80 | size_t wpa_ie_len = sizeof(wpa_ie); | |
81 | wpa_supplicant_set_suites(wpa_s, NULL, ssid, | |
82 | wpa_ie, &wpa_ie_len); | |
83 | } else { | |
84 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
85 | } | |
86 | ||
87 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) | |
88 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
8bac466b | 89 | old_ssid = wpa_s->current_ssid; |
6fc6879b JM |
90 | wpa_s->current_ssid = ssid; |
91 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); | |
92 | wpa_supplicant_initiate_eapol(wpa_s); | |
8bac466b JM |
93 | if (old_ssid != wpa_s->current_ssid) |
94 | wpas_notify_network_changed(wpa_s); | |
6fc6879b JM |
95 | |
96 | return 0; | |
97 | } | |
98 | ||
99 | ||
100 | static void wpa_supplicant_stop_countermeasures(void *eloop_ctx, | |
101 | void *sock_ctx) | |
102 | { | |
103 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
104 | ||
105 | if (wpa_s->countermeasures) { | |
106 | wpa_s->countermeasures = 0; | |
107 | wpa_drv_set_countermeasures(wpa_s, 0); | |
108 | wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped"); | |
109 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
110 | } | |
111 | } | |
112 | ||
113 | ||
114 | void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) | |
115 | { | |
8bac466b JM |
116 | int bssid_changed; |
117 | ||
78177a00 JM |
118 | #ifdef CONFIG_IBSS_RSN |
119 | ibss_rsn_deinit(wpa_s->ibss_rsn); | |
120 | wpa_s->ibss_rsn = NULL; | |
121 | #endif /* CONFIG_IBSS_RSN */ | |
122 | ||
ca62e114 JM |
123 | #ifdef CONFIG_AP |
124 | wpa_supplicant_ap_deinit(wpa_s); | |
125 | #endif /* CONFIG_AP */ | |
126 | ||
8401a6b0 JM |
127 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
128 | return; | |
129 | ||
6fc6879b | 130 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
8bac466b | 131 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
6fc6879b JM |
132 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
133 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
be8be671 | 134 | wpa_s->current_bss = NULL; |
3c85f144 | 135 | wpa_s->assoc_freq = 0; |
8fd0f0f3 HW |
136 | #ifdef CONFIG_IEEE80211R |
137 | #ifdef CONFIG_SME | |
138 | if (wpa_s->sme.ft_ies) | |
139 | sme_update_ft_ies(wpa_s, NULL, NULL, 0); | |
140 | #endif /* CONFIG_SME */ | |
141 | #endif /* CONFIG_IEEE80211R */ | |
142 | ||
8bac466b JM |
143 | if (bssid_changed) |
144 | wpas_notify_bssid_changed(wpa_s); | |
145 | ||
6fc6879b JM |
146 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); |
147 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
56586197 | 148 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) |
6fc6879b JM |
149 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
150 | wpa_s->ap_ies_from_associnfo = 0; | |
151 | } | |
152 | ||
153 | ||
154 | static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s) | |
155 | { | |
156 | struct wpa_ie_data ie; | |
157 | int pmksa_set = -1; | |
158 | size_t i; | |
159 | ||
160 | if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 || | |
161 | ie.pmkid == NULL) | |
162 | return; | |
163 | ||
164 | for (i = 0; i < ie.num_pmkid; i++) { | |
165 | pmksa_set = pmksa_cache_set_current(wpa_s->wpa, | |
166 | ie.pmkid + i * PMKID_LEN, | |
167 | NULL, NULL, 0); | |
168 | if (pmksa_set == 0) { | |
169 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1); | |
170 | break; | |
171 | } | |
172 | } | |
173 | ||
f049052b BG |
174 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from " |
175 | "PMKSA cache", pmksa_set == 0 ? "" : "not "); | |
6fc6879b JM |
176 | } |
177 | ||
178 | ||
179 | static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s, | |
180 | union wpa_event_data *data) | |
181 | { | |
182 | if (data == NULL) { | |
f049052b BG |
183 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate " |
184 | "event"); | |
6fc6879b JM |
185 | return; |
186 | } | |
f049052b BG |
187 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR |
188 | " index=%d preauth=%d", | |
189 | MAC2STR(data->pmkid_candidate.bssid), | |
190 | data->pmkid_candidate.index, | |
191 | data->pmkid_candidate.preauth); | |
6fc6879b JM |
192 | |
193 | pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid, | |
194 | data->pmkid_candidate.index, | |
195 | data->pmkid_candidate.preauth); | |
196 | } | |
197 | ||
198 | ||
199 | static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s) | |
200 | { | |
201 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
202 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) | |
203 | return 0; | |
204 | ||
205 | #ifdef IEEE8021X_EAPOL | |
206 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA && | |
207 | wpa_s->current_ssid && | |
208 | !(wpa_s->current_ssid->eapol_flags & | |
209 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
210 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) { | |
211 | /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either | |
212 | * plaintext or static WEP keys). */ | |
213 | return 0; | |
214 | } | |
215 | #endif /* IEEE8021X_EAPOL */ | |
216 | ||
217 | return 1; | |
218 | } | |
219 | ||
220 | ||
221 | /** | |
222 | * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC | |
223 | * @wpa_s: pointer to wpa_supplicant data | |
224 | * @ssid: Configuration data for the network | |
225 | * Returns: 0 on success, -1 on failure | |
226 | * | |
227 | * This function is called when starting authentication with a network that is | |
228 | * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA). | |
229 | */ | |
230 | int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s, | |
231 | struct wpa_ssid *ssid) | |
232 | { | |
233 | #ifdef IEEE8021X_EAPOL | |
234 | int aka = 0, sim = 0, type; | |
235 | ||
236 | if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL) | |
237 | return 0; | |
238 | ||
239 | if (ssid->eap.eap_methods == NULL) { | |
240 | sim = 1; | |
241 | aka = 1; | |
242 | } else { | |
243 | struct eap_method_type *eap = ssid->eap.eap_methods; | |
244 | while (eap->vendor != EAP_VENDOR_IETF || | |
245 | eap->method != EAP_TYPE_NONE) { | |
246 | if (eap->vendor == EAP_VENDOR_IETF) { | |
247 | if (eap->method == EAP_TYPE_SIM) | |
248 | sim = 1; | |
249 | else if (eap->method == EAP_TYPE_AKA) | |
250 | aka = 1; | |
251 | } | |
252 | eap++; | |
253 | } | |
254 | } | |
255 | ||
256 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL) | |
257 | sim = 0; | |
258 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL) | |
259 | aka = 0; | |
260 | ||
261 | if (!sim && !aka) { | |
f049052b BG |
262 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to " |
263 | "use SIM, but neither EAP-SIM nor EAP-AKA are " | |
264 | "enabled"); | |
6fc6879b JM |
265 | return 0; |
266 | } | |
267 | ||
f049052b BG |
268 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM " |
269 | "(sim=%d aka=%d) - initialize PCSC", sim, aka); | |
6fc6879b JM |
270 | if (sim && aka) |
271 | type = SCARD_TRY_BOTH; | |
272 | else if (aka) | |
273 | type = SCARD_USIM_ONLY; | |
274 | else | |
275 | type = SCARD_GSM_SIM_ONLY; | |
276 | ||
277 | wpa_s->scard = scard_init(type); | |
278 | if (wpa_s->scard == NULL) { | |
f049052b BG |
279 | wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM " |
280 | "(pcsc-lite)"); | |
6fc6879b JM |
281 | return -1; |
282 | } | |
283 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); | |
284 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); | |
285 | #endif /* IEEE8021X_EAPOL */ | |
286 | ||
287 | return 0; | |
288 | } | |
289 | ||
290 | ||
291 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
292 | static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss, | |
293 | struct wpa_ssid *ssid) | |
294 | { | |
295 | int i, privacy = 0; | |
296 | ||
297 | if (ssid->mixed_cell) | |
298 | return 1; | |
299 | ||
0632542b AT |
300 | #ifdef CONFIG_WPS |
301 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) | |
302 | return 1; | |
303 | #endif /* CONFIG_WPS */ | |
304 | ||
6fc6879b JM |
305 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
306 | if (ssid->wep_key_len[i]) { | |
307 | privacy = 1; | |
308 | break; | |
309 | } | |
310 | } | |
311 | #ifdef IEEE8021X_EAPOL | |
312 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
313 | ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
314 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) | |
315 | privacy = 1; | |
316 | #endif /* IEEE8021X_EAPOL */ | |
317 | ||
29fbc522 JM |
318 | if (wpa_key_mgmt_wpa(ssid->key_mgmt)) |
319 | privacy = 1; | |
320 | ||
6fc6879b JM |
321 | if (bss->caps & IEEE80211_CAP_PRIVACY) |
322 | return privacy; | |
323 | return !privacy; | |
324 | } | |
325 | ||
326 | ||
a6099152 JM |
327 | static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, |
328 | struct wpa_ssid *ssid, | |
6fc6879b JM |
329 | struct wpa_scan_res *bss) |
330 | { | |
331 | struct wpa_ie_data ie; | |
332 | int proto_match = 0; | |
333 | const u8 *rsn_ie, *wpa_ie; | |
351f09a2 | 334 | int ret; |
43882f1e | 335 | int wep_ok; |
6fc6879b | 336 | |
a6099152 | 337 | ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); |
351f09a2 JM |
338 | if (ret >= 0) |
339 | return ret; | |
ad08c363 | 340 | |
43882f1e JM |
341 | /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */ |
342 | wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) && | |
343 | (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) && | |
344 | ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) || | |
345 | (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)); | |
346 | ||
6fc6879b JM |
347 | rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN); |
348 | while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) { | |
349 | proto_match++; | |
350 | ||
351 | if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { | |
f049052b BG |
352 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse " |
353 | "failed"); | |
6fc6879b JM |
354 | break; |
355 | } | |
43882f1e JM |
356 | |
357 | if (wep_ok && | |
358 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
359 | { | |
f049052b BG |
360 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " |
361 | "in RSN IE"); | |
43882f1e JM |
362 | return 1; |
363 | } | |
364 | ||
6fc6879b | 365 | if (!(ie.proto & ssid->proto)) { |
f049052b BG |
366 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto " |
367 | "mismatch"); | |
6fc6879b JM |
368 | break; |
369 | } | |
370 | ||
371 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
f049052b BG |
372 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK " |
373 | "cipher mismatch"); | |
6fc6879b JM |
374 | break; |
375 | } | |
376 | ||
377 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
f049052b BG |
378 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK " |
379 | "cipher mismatch"); | |
6fc6879b JM |
380 | break; |
381 | } | |
382 | ||
383 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
f049052b BG |
384 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt " |
385 | "mismatch"); | |
6fc6879b JM |
386 | break; |
387 | } | |
388 | ||
389 | #ifdef CONFIG_IEEE80211W | |
0b60b0aa | 390 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
70f8cc8e | 391 | ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) { |
f049052b BG |
392 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt " |
393 | "frame protection"); | |
6fc6879b JM |
394 | break; |
395 | } | |
396 | #endif /* CONFIG_IEEE80211W */ | |
397 | ||
f049052b | 398 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE"); |
6fc6879b JM |
399 | return 1; |
400 | } | |
401 | ||
402 | wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | |
403 | while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { | |
404 | proto_match++; | |
405 | ||
406 | if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { | |
f049052b BG |
407 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse " |
408 | "failed"); | |
6fc6879b JM |
409 | break; |
410 | } | |
43882f1e JM |
411 | |
412 | if (wep_ok && | |
413 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
414 | { | |
f049052b BG |
415 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " |
416 | "in WPA IE"); | |
43882f1e JM |
417 | return 1; |
418 | } | |
419 | ||
6fc6879b | 420 | if (!(ie.proto & ssid->proto)) { |
f049052b BG |
421 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto " |
422 | "mismatch"); | |
6fc6879b JM |
423 | break; |
424 | } | |
425 | ||
426 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
f049052b BG |
427 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK " |
428 | "cipher mismatch"); | |
6fc6879b JM |
429 | break; |
430 | } | |
431 | ||
432 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
f049052b BG |
433 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK " |
434 | "cipher mismatch"); | |
6fc6879b JM |
435 | break; |
436 | } | |
437 | ||
438 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
f049052b BG |
439 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt " |
440 | "mismatch"); | |
6fc6879b JM |
441 | break; |
442 | } | |
443 | ||
f049052b | 444 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE"); |
6fc6879b JM |
445 | return 1; |
446 | } | |
447 | ||
cc5e390d | 448 | if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) && |
df83fb7d | 449 | wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) { |
f049052b | 450 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match"); |
cc5e390d JM |
451 | return 0; |
452 | } | |
6fc6879b | 453 | |
c2f1fe41 JM |
454 | if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
455 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2"); | |
456 | return 1; | |
457 | } | |
458 | ||
459 | wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with " | |
460 | "WPA/WPA2"); | |
461 | ||
462 | return 0; | |
6fc6879b JM |
463 | } |
464 | ||
465 | ||
b766a9a2 JM |
466 | static int freq_allowed(int *freqs, int freq) |
467 | { | |
468 | int i; | |
469 | ||
470 | if (freqs == NULL) | |
471 | return 1; | |
472 | ||
473 | for (i = 0; freqs[i]; i++) | |
474 | if (freqs[i] == freq) | |
475 | return 1; | |
476 | return 0; | |
477 | } | |
478 | ||
479 | ||
d8d940b7 JM |
480 | static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s, |
481 | int i, struct wpa_scan_res *bss, | |
482 | struct wpa_ssid *group) | |
6fc6879b | 483 | { |
d8d940b7 JM |
484 | const u8 *ssid_; |
485 | u8 wpa_ie_len, rsn_ie_len, ssid_len; | |
486 | int wpa; | |
6fc6879b JM |
487 | struct wpa_blacklist *e; |
488 | const u8 *ie; | |
d8d940b7 | 489 | struct wpa_ssid *ssid; |
6fc6879b | 490 | |
d8d940b7 JM |
491 | ie = wpa_scan_get_ie(bss, WLAN_EID_SSID); |
492 | ssid_ = ie ? ie + 2 : (u8 *) ""; | |
493 | ssid_len = ie ? ie[1] : 0; | |
6fc6879b | 494 | |
d8d940b7 JM |
495 | ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
496 | wpa_ie_len = ie ? ie[1] : 0; | |
6fc6879b | 497 | |
d8d940b7 JM |
498 | ie = wpa_scan_get_ie(bss, WLAN_EID_RSN); |
499 | rsn_ie_len = ie ? ie[1] : 0; | |
6fc6879b | 500 | |
f049052b BG |
501 | wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' " |
502 | "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s", | |
503 | i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len), | |
504 | wpa_ie_len, rsn_ie_len, bss->caps, bss->level, | |
505 | wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : ""); | |
9cf32261 | 506 | |
d8d940b7 | 507 | e = wpa_blacklist_get(wpa_s, bss->bssid); |
5471c343 JM |
508 | if (e) { |
509 | int limit = 1; | |
510 | if (wpa_supplicant_enabled_networks(wpa_s->conf) == 1) { | |
511 | /* | |
512 | * When only a single network is enabled, we can | |
513 | * trigger blacklisting on the first failure. This | |
514 | * should not be done with multiple enabled networks to | |
515 | * avoid getting forced to move into a worse ESS on | |
516 | * single error if there are no other BSSes of the | |
517 | * current ESS. | |
518 | */ | |
519 | limit = 0; | |
520 | } | |
521 | if (e->count > limit) { | |
f049052b BG |
522 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " |
523 | "(count=%d limit=%d)", e->count, limit); | |
c2197bc9 | 524 | return NULL; |
5471c343 | 525 | } |
d8d940b7 | 526 | } |
6fc6879b | 527 | |
d8d940b7 | 528 | if (ssid_len == 0) { |
f049052b | 529 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known"); |
c2197bc9 | 530 | return NULL; |
d8d940b7 | 531 | } |
e81634cd | 532 | |
d8d940b7 | 533 | wpa = wpa_ie_len > 0 || rsn_ie_len > 0; |
6fc6879b | 534 | |
d8d940b7 JM |
535 | for (ssid = group; ssid; ssid = ssid->pnext) { |
536 | int check_ssid = wpa ? 1 : (ssid->ssid_len != 0); | |
ad08c363 | 537 | |
d8d940b7 | 538 | if (ssid->disabled) { |
f049052b | 539 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled"); |
0c703df3 | 540 | continue; |
d8d940b7 | 541 | } |
9cf32261 | 542 | |
ad08c363 | 543 | #ifdef CONFIG_WPS |
f648bc7d | 544 | if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) { |
f049052b BG |
545 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " |
546 | "(WPS)"); | |
f648bc7d JM |
547 | continue; |
548 | } | |
549 | ||
d8d940b7 JM |
550 | if (wpa && ssid->ssid_len == 0 && |
551 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) | |
552 | check_ssid = 0; | |
553 | ||
554 | if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { | |
555 | /* Only allow wildcard SSID match if an AP | |
556 | * advertises active WPS operation that matches | |
557 | * with our mode. */ | |
558 | check_ssid = 1; | |
ad08c363 | 559 | if (ssid->ssid_len == 0 && |
a6099152 | 560 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) |
ad08c363 | 561 | check_ssid = 0; |
d8d940b7 | 562 | } |
ad08c363 JM |
563 | #endif /* CONFIG_WPS */ |
564 | ||
7d232e23 ZC |
565 | if (ssid->bssid_set && ssid->ssid_len == 0 && |
566 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0) | |
567 | check_ssid = 0; | |
568 | ||
d8d940b7 JM |
569 | if (check_ssid && |
570 | (ssid_len != ssid->ssid_len || | |
571 | os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) { | |
f049052b | 572 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch"); |
0c703df3 | 573 | continue; |
6fc6879b | 574 | } |
6fc6879b | 575 | |
d8d940b7 JM |
576 | if (ssid->bssid_set && |
577 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) { | |
f049052b | 578 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch"); |
0c703df3 | 579 | continue; |
d8d940b7 | 580 | } |
6fc6879b | 581 | |
cc5e390d | 582 | if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss)) |
0c703df3 | 583 | continue; |
9cf32261 | 584 | |
d8d940b7 JM |
585 | if (!wpa && |
586 | !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) && | |
587 | !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) && | |
588 | !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) { | |
f049052b BG |
589 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network " |
590 | "not allowed"); | |
0c703df3 | 591 | continue; |
6fc6879b | 592 | } |
9cf32261 | 593 | |
29fbc522 | 594 | if (!wpa_supplicant_match_privacy(bss, ssid)) { |
f049052b BG |
595 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy " |
596 | "mismatch"); | |
0c703df3 | 597 | continue; |
e81634cd JM |
598 | } |
599 | ||
29fbc522 | 600 | if (bss->caps & IEEE80211_CAP_IBSS) { |
f049052b BG |
601 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) " |
602 | "network"); | |
0c703df3 | 603 | continue; |
d8d940b7 | 604 | } |
b766a9a2 | 605 | |
d8d940b7 | 606 | if (!freq_allowed(ssid->freq_list, bss->freq)) { |
f049052b BG |
607 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not " |
608 | "allowed"); | |
0c703df3 | 609 | continue; |
6fc6879b | 610 | } |
d8d940b7 | 611 | |
73e49269 JM |
612 | #ifdef CONFIG_P2P |
613 | /* | |
614 | * TODO: skip the AP if its P2P IE has Group Formation | |
615 | * bit set in the P2P Group Capability Bitmap and we | |
616 | * are not in Group Formation with that device. | |
617 | */ | |
618 | #endif /* CONFIG_P2P */ | |
619 | ||
d8d940b7 JM |
620 | /* Matching configuration found */ |
621 | return ssid; | |
6fc6879b JM |
622 | } |
623 | ||
d8d940b7 | 624 | /* No matching configuration found */ |
c2197bc9 | 625 | return NULL; |
9cf32261 JM |
626 | } |
627 | ||
628 | ||
6fa81a3b | 629 | static struct wpa_bss * |
a1fd2ce5 JM |
630 | wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, |
631 | struct wpa_scan_results *scan_res, | |
632 | struct wpa_ssid *group, | |
9cf32261 JM |
633 | struct wpa_ssid **selected_ssid) |
634 | { | |
d8d940b7 | 635 | size_t i; |
9cf32261 | 636 | |
f049052b BG |
637 | wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d", |
638 | group->priority); | |
9cf32261 | 639 | |
d8d940b7 JM |
640 | for (i = 0; i < scan_res->num; i++) { |
641 | struct wpa_scan_res *bss = scan_res->res[i]; | |
642 | const u8 *ie, *ssid; | |
643 | u8 ssid_len; | |
644 | ||
645 | *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group); | |
646 | if (!*selected_ssid) | |
647 | continue; | |
648 | ||
649 | ie = wpa_scan_get_ie(bss, WLAN_EID_SSID); | |
650 | ssid = ie ? ie + 2 : (u8 *) ""; | |
651 | ssid_len = ie ? ie[1] : 0; | |
9cf32261 | 652 | |
f049052b BG |
653 | wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR |
654 | " ssid='%s'", | |
655 | MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len)); | |
d8d940b7 JM |
656 | return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len); |
657 | } | |
658 | ||
659 | return NULL; | |
6fc6879b JM |
660 | } |
661 | ||
662 | ||
6fa81a3b | 663 | static struct wpa_bss * |
09b9df4e | 664 | wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s, |
a1fd2ce5 | 665 | struct wpa_scan_results *scan_res, |
09b9df4e | 666 | struct wpa_ssid **selected_ssid) |
6fc6879b | 667 | { |
6fa81a3b | 668 | struct wpa_bss *selected = NULL; |
09b9df4e JM |
669 | int prio; |
670 | ||
671 | while (selected == NULL) { | |
672 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
673 | selected = wpa_supplicant_select_bss( | |
a1fd2ce5 | 674 | wpa_s, scan_res, wpa_s->conf->pssid[prio], |
09b9df4e JM |
675 | selected_ssid); |
676 | if (selected) | |
677 | break; | |
678 | } | |
679 | ||
680 | if (selected == NULL && wpa_s->blacklist) { | |
f049052b BG |
681 | wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear " |
682 | "blacklist and try again"); | |
09b9df4e JM |
683 | wpa_blacklist_clear(wpa_s); |
684 | wpa_s->blacklist_cleared++; | |
685 | } else if (selected == NULL) | |
686 | break; | |
687 | } | |
688 | ||
689 | return selected; | |
690 | } | |
691 | ||
692 | ||
693 | static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s, | |
977b1174 | 694 | int timeout_sec, int timeout_usec) |
09b9df4e | 695 | { |
24f76940 | 696 | if (!wpa_supplicant_enabled_networks(wpa_s->conf)) { |
4f34d51a SL |
697 | /* |
698 | * No networks are enabled; short-circuit request so | |
699 | * we don't wait timeout seconds before transitioning | |
700 | * to INACTIVE state. | |
701 | */ | |
702 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); | |
703 | return; | |
09b9df4e | 704 | } |
977b1174 | 705 | wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec); |
09b9df4e JM |
706 | } |
707 | ||
708 | ||
86d4f806 JM |
709 | void wpa_supplicant_connect(struct wpa_supplicant *wpa_s, |
710 | struct wpa_bss *selected, | |
711 | struct wpa_ssid *ssid) | |
09b9df4e JM |
712 | { |
713 | if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) { | |
714 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP | |
715 | "PBC session overlap"); | |
b73bf0a7 JM |
716 | #ifdef CONFIG_P2P |
717 | if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1) | |
718 | return; | |
719 | #endif /* CONFIG_P2P */ | |
199716ad BG |
720 | |
721 | #ifdef CONFIG_WPS | |
7736f18b | 722 | wpas_wps_cancel(wpa_s); |
199716ad | 723 | #endif /* CONFIG_WPS */ |
09b9df4e JM |
724 | return; |
725 | } | |
726 | ||
727 | /* | |
728 | * Do not trigger new association unless the BSSID has changed or if | |
729 | * reassociation is requested. If we are in process of associating with | |
730 | * the selected BSSID, do not trigger new attempt. | |
731 | */ | |
732 | if (wpa_s->reassociate || | |
733 | (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 && | |
e29853bb BG |
734 | ((wpa_s->wpa_state != WPA_ASSOCIATING && |
735 | wpa_s->wpa_state != WPA_AUTHENTICATING) || | |
09b9df4e JM |
736 | os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) != |
737 | 0))) { | |
738 | if (wpa_supplicant_scard_init(wpa_s, ssid)) { | |
977b1174 | 739 | wpa_supplicant_req_new_scan(wpa_s, 10, 0); |
09b9df4e JM |
740 | return; |
741 | } | |
e29853bb BG |
742 | wpa_msg(wpa_s, MSG_DEBUG, "Request association: " |
743 | "reassociate: %d selected: "MACSTR " bssid: " MACSTR | |
744 | " pending: " MACSTR " wpa_state: %s", | |
745 | wpa_s->reassociate, MAC2STR(selected->bssid), | |
746 | MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), | |
747 | wpa_supplicant_state_txt(wpa_s->wpa_state)); | |
09b9df4e JM |
748 | wpa_supplicant_associate(wpa_s, selected, ssid); |
749 | } else { | |
f049052b BG |
750 | wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the " |
751 | "selected AP"); | |
09b9df4e | 752 | } |
09b9df4e JM |
753 | } |
754 | ||
755 | ||
b55aaa5f JM |
756 | static struct wpa_ssid * |
757 | wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s) | |
758 | { | |
759 | int prio; | |
760 | struct wpa_ssid *ssid; | |
761 | ||
762 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
763 | for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) | |
764 | { | |
765 | if (ssid->disabled) | |
766 | continue; | |
767 | if (ssid->mode == IEEE80211_MODE_IBSS || | |
768 | ssid->mode == IEEE80211_MODE_AP) | |
769 | return ssid; | |
770 | } | |
771 | } | |
772 | return NULL; | |
773 | } | |
774 | ||
775 | ||
a1fd2ce5 JM |
776 | /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based |
777 | * on BSS added and BSS changed events */ | |
6ae93185 | 778 | static void wpa_supplicant_rsn_preauth_scan_results( |
6d28fb96 | 779 | struct wpa_supplicant *wpa_s) |
6ae93185 | 780 | { |
6d28fb96 | 781 | struct wpa_bss *bss; |
6ae93185 JM |
782 | |
783 | if (rsn_preauth_scan_results(wpa_s->wpa) < 0) | |
784 | return; | |
785 | ||
6d28fb96 | 786 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
6ae93185 | 787 | const u8 *ssid, *rsn; |
6ae93185 | 788 | |
6d28fb96 | 789 | ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID); |
6ae93185 JM |
790 | if (ssid == NULL) |
791 | continue; | |
792 | ||
6d28fb96 | 793 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
6ae93185 JM |
794 | if (rsn == NULL) |
795 | continue; | |
796 | ||
6d28fb96 | 797 | rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn); |
6ae93185 JM |
798 | } |
799 | ||
800 | } | |
801 | ||
802 | ||
48563d86 JM |
803 | static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, |
804 | struct wpa_bss *selected, | |
805 | struct wpa_ssid *ssid, | |
806 | struct wpa_scan_results *scan_res) | |
807 | { | |
808 | size_t i; | |
809 | struct wpa_scan_res *current_bss = NULL; | |
810 | int min_diff; | |
811 | ||
812 | if (wpa_s->reassociate) | |
813 | return 1; /* explicit request to reassociate */ | |
814 | if (wpa_s->wpa_state < WPA_ASSOCIATED) | |
815 | return 1; /* we are not associated; continue */ | |
816 | if (wpa_s->current_ssid == NULL) | |
817 | return 1; /* unknown current SSID */ | |
818 | if (wpa_s->current_ssid != ssid) | |
819 | return 1; /* different network block */ | |
820 | ||
22628eca JM |
821 | if (wpas_driver_bss_selection(wpa_s)) |
822 | return 0; /* Driver-based roaming */ | |
823 | ||
48563d86 JM |
824 | for (i = 0; i < scan_res->num; i++) { |
825 | struct wpa_scan_res *res = scan_res->res[i]; | |
826 | const u8 *ie; | |
827 | if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0) | |
828 | continue; | |
829 | ||
830 | ie = wpa_scan_get_ie(res, WLAN_EID_SSID); | |
831 | if (ie == NULL) | |
832 | continue; | |
833 | if (ie[1] != wpa_s->current_ssid->ssid_len || | |
834 | os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0) | |
835 | continue; | |
836 | current_bss = res; | |
837 | break; | |
838 | } | |
839 | ||
840 | if (!current_bss) | |
841 | return 1; /* current BSS not seen in scan results */ | |
842 | ||
f049052b BG |
843 | wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation"); |
844 | wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d", | |
845 | MAC2STR(current_bss->bssid), current_bss->level); | |
846 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d", | |
847 | MAC2STR(selected->bssid), selected->level); | |
48563d86 | 848 | |
ac26ebd8 JM |
849 | if (wpa_s->current_ssid->bssid_set && |
850 | os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) == | |
851 | 0) { | |
f049052b BG |
852 | wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS " |
853 | "has preferred BSSID"); | |
ac26ebd8 JM |
854 | return 1; |
855 | } | |
856 | ||
48563d86 JM |
857 | min_diff = 2; |
858 | if (current_bss->level < 0) { | |
859 | if (current_bss->level < -85) | |
860 | min_diff = 1; | |
861 | else if (current_bss->level < -80) | |
862 | min_diff = 2; | |
863 | else if (current_bss->level < -75) | |
864 | min_diff = 3; | |
865 | else if (current_bss->level < -70) | |
866 | min_diff = 4; | |
867 | else | |
868 | min_diff = 5; | |
869 | } | |
870 | if (abs(current_bss->level - selected->level) < min_diff) { | |
f049052b BG |
871 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference " |
872 | "in signal level"); | |
48563d86 JM |
873 | return 0; |
874 | } | |
875 | ||
876 | return 1; | |
877 | } | |
878 | ||
e1504976 BG |
879 | /* Return < 0 if no scan results could be fetched. */ |
880 | static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, | |
881 | union wpa_event_data *data) | |
09b9df4e | 882 | { |
6fa81a3b | 883 | struct wpa_bss *selected; |
6fc6879b | 884 | struct wpa_ssid *ssid = NULL; |
a1fd2ce5 | 885 | struct wpa_scan_results *scan_res; |
5bc0cdb7 JM |
886 | int ap = 0; |
887 | ||
888 | #ifdef CONFIG_AP | |
889 | if (wpa_s->ap_iface) | |
890 | ap = 1; | |
891 | #endif /* CONFIG_AP */ | |
6fc6879b | 892 | |
cb8564b1 DW |
893 | wpa_supplicant_notify_scanning(wpa_s, 0); |
894 | ||
a1fd2ce5 JM |
895 | scan_res = wpa_supplicant_get_scan_results(wpa_s, |
896 | data ? &data->scan_info : | |
897 | NULL, 1); | |
898 | if (scan_res == NULL) { | |
5bc0cdb7 | 899 | if (wpa_s->conf->ap_scan == 2 || ap) |
e1504976 | 900 | return -1; |
f049052b BG |
901 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try " |
902 | "scanning again"); | |
977b1174 | 903 | wpa_supplicant_req_new_scan(wpa_s, 1, 0); |
e1504976 | 904 | return -1; |
6fc6879b JM |
905 | } |
906 | ||
bbb921da JM |
907 | #ifndef CONFIG_NO_RANDOM_POOL |
908 | size_t i, num; | |
909 | num = scan_res->num; | |
910 | if (num > 10) | |
911 | num = 10; | |
912 | for (i = 0; i < num; i++) { | |
913 | u8 buf[5]; | |
914 | struct wpa_scan_res *res = scan_res->res[i]; | |
915 | buf[0] = res->bssid[5]; | |
916 | buf[1] = res->qual & 0xff; | |
917 | buf[2] = res->noise & 0xff; | |
918 | buf[3] = res->level & 0xff; | |
919 | buf[4] = res->tsf & 0xff; | |
920 | random_add_randomness(buf, sizeof(buf)); | |
921 | } | |
922 | #endif /* CONFIG_NO_RANDOM_POOL */ | |
923 | ||
64e58f51 | 924 | if (wpa_s->scan_res_handler) { |
860fddbb JB |
925 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, |
926 | struct wpa_scan_results *scan_res); | |
927 | ||
928 | scan_res_handler = wpa_s->scan_res_handler; | |
64e58f51 | 929 | wpa_s->scan_res_handler = NULL; |
860fddbb JB |
930 | scan_res_handler(wpa_s, scan_res); |
931 | ||
64e58f51 | 932 | wpa_scan_results_free(scan_res); |
e1504976 | 933 | return 0; |
64e58f51 JM |
934 | } |
935 | ||
5bc0cdb7 | 936 | if (ap) { |
f049052b | 937 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode"); |
c202f19c JB |
938 | #ifdef CONFIG_AP |
939 | if (wpa_s->ap_iface->scan_cb) | |
940 | wpa_s->ap_iface->scan_cb(wpa_s->ap_iface); | |
941 | #endif /* CONFIG_AP */ | |
5bc0cdb7 | 942 | wpa_scan_results_free(scan_res); |
e1504976 | 943 | return 0; |
5bc0cdb7 JM |
944 | } |
945 | ||
f049052b | 946 | wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available"); |
24f76940 JM |
947 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); |
948 | wpas_notify_scan_results(wpa_s); | |
6fc6879b | 949 | |
8bac466b JM |
950 | wpas_notify_scan_done(wpa_s, 1); |
951 | ||
a1fd2ce5 JM |
952 | if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) { |
953 | wpa_scan_results_free(scan_res); | |
e1504976 | 954 | return 0; |
a1fd2ce5 | 955 | } |
6fc6879b | 956 | |
3180d7a2 SO |
957 | if (wpa_s->disconnected) { |
958 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
a1fd2ce5 | 959 | wpa_scan_results_free(scan_res); |
e1504976 | 960 | return 0; |
3180d7a2 SO |
961 | } |
962 | ||
22628eca JM |
963 | if (!wpas_driver_bss_selection(wpa_s) && |
964 | bgscan_notify_scan(wpa_s, scan_res) == 1) { | |
a1fd2ce5 | 965 | wpa_scan_results_free(scan_res); |
e1504976 | 966 | return 0; |
a1fd2ce5 JM |
967 | } |
968 | ||
a1fd2ce5 | 969 | selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid); |
6ae93185 | 970 | |
6fc6879b | 971 | if (selected) { |
48563d86 JM |
972 | int skip; |
973 | skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid, | |
974 | scan_res); | |
975 | wpa_scan_results_free(scan_res); | |
976 | if (skip) | |
e1504976 | 977 | return 0; |
09b9df4e | 978 | wpa_supplicant_connect(wpa_s, selected, ssid); |
6d28fb96 | 979 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
6fc6879b | 980 | } else { |
48563d86 | 981 | wpa_scan_results_free(scan_res); |
f049052b | 982 | wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found"); |
b55aaa5f JM |
983 | ssid = wpa_supplicant_pick_new_network(wpa_s); |
984 | if (ssid) { | |
f049052b | 985 | wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network"); |
b55aaa5f | 986 | wpa_supplicant_associate(wpa_s, NULL, ssid); |
6d28fb96 | 987 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
977b1174 | 988 | } else { |
67b9bd08 | 989 | int timeout_sec = wpa_s->scan_interval; |
977b1174 | 990 | int timeout_usec = 0; |
0817de90 JM |
991 | #ifdef CONFIG_P2P |
992 | if (wpa_s->p2p_in_provisioning) { | |
993 | /* | |
994 | * Use shorter wait during P2P Provisioning | |
995 | * state to speed up group formation. | |
996 | */ | |
997 | timeout_sec = 0; | |
998 | timeout_usec = 250000; | |
999 | } | |
1000 | #endif /* CONFIG_P2P */ | |
977b1174 JM |
1001 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
1002 | timeout_usec); | |
1003 | } | |
6fc6879b | 1004 | } |
e1504976 | 1005 | return 0; |
6fc6879b | 1006 | } |
6859f1cb BG |
1007 | |
1008 | ||
1009 | static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, | |
1010 | union wpa_event_data *data) | |
1011 | { | |
1012 | const char *rn, *rn2; | |
1013 | struct wpa_supplicant *ifs; | |
1014 | ||
e1504976 BG |
1015 | if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) { |
1016 | /* | |
1017 | * If no scan results could be fetched, then no need to | |
1018 | * notify those interfaces that did not actually request | |
1019 | * this scan. | |
1020 | */ | |
1021 | return; | |
1022 | } | |
6859f1cb BG |
1023 | |
1024 | /* | |
1025 | * Check other interfaces to see if they have the same radio-name. If | |
1026 | * so, they get updated with this same scan info. | |
1027 | */ | |
1028 | if (!wpa_s->driver->get_radio_name) | |
1029 | return; | |
1030 | ||
1031 | rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv); | |
1032 | if (rn == NULL || rn[0] == '\0') | |
1033 | return; | |
1034 | ||
f049052b BG |
1035 | wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces " |
1036 | "sharing same radio (%s) in event_scan_results", rn); | |
6859f1cb BG |
1037 | |
1038 | for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { | |
1039 | if (ifs == wpa_s || !ifs->driver->get_radio_name) | |
1040 | continue; | |
1041 | ||
1042 | rn2 = ifs->driver->get_radio_name(ifs->drv_priv); | |
1043 | if (rn2 && os_strcmp(rn, rn2) == 0) { | |
1044 | wpa_printf(MSG_DEBUG, "%s: Updating scan results from " | |
1045 | "sibling", ifs->ifname); | |
1046 | _wpa_supplicant_event_scan_results(ifs, data); | |
1047 | } | |
1048 | } | |
1049 | } | |
1050 | ||
6fc6879b JM |
1051 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
1052 | ||
1053 | ||
579ce771 JM |
1054 | static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, |
1055 | union wpa_event_data *data) | |
6fc6879b JM |
1056 | { |
1057 | int l, len, found = 0, wpa_found, rsn_found; | |
c2a04078 | 1058 | const u8 *p; |
6fc6879b | 1059 | |
f049052b | 1060 | wpa_dbg(wpa_s, MSG_DEBUG, "Association info event"); |
6fc6879b JM |
1061 | if (data->assoc_info.req_ies) |
1062 | wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, | |
1063 | data->assoc_info.req_ies_len); | |
52c9e6f3 | 1064 | if (data->assoc_info.resp_ies) { |
6fc6879b JM |
1065 | wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, |
1066 | data->assoc_info.resp_ies_len); | |
52c9e6f3 JM |
1067 | #ifdef CONFIG_TDLS |
1068 | wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies, | |
1069 | data->assoc_info.resp_ies_len); | |
1070 | #endif /* CONFIG_TDLS */ | |
1071 | } | |
6fc6879b JM |
1072 | if (data->assoc_info.beacon_ies) |
1073 | wpa_hexdump(MSG_DEBUG, "beacon_ies", | |
1074 | data->assoc_info.beacon_ies, | |
1075 | data->assoc_info.beacon_ies_len); | |
4832ecd7 | 1076 | if (data->assoc_info.freq) |
f049052b BG |
1077 | wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz", |
1078 | data->assoc_info.freq); | |
6fc6879b JM |
1079 | |
1080 | p = data->assoc_info.req_ies; | |
1081 | l = data->assoc_info.req_ies_len; | |
1082 | ||
1083 | /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ | |
1084 | while (p && l >= 2) { | |
1085 | len = p[1] + 2; | |
1086 | if (len > l) { | |
1087 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
1088 | p, l); | |
1089 | break; | |
1090 | } | |
1091 | if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
1092 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || | |
1093 | (p[0] == WLAN_EID_RSN && p[1] >= 2)) { | |
1094 | if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) | |
1095 | break; | |
1096 | found = 1; | |
1097 | wpa_find_assoc_pmkid(wpa_s); | |
1098 | break; | |
1099 | } | |
1100 | l -= len; | |
1101 | p += len; | |
1102 | } | |
1103 | if (!found && data->assoc_info.req_ies) | |
1104 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); | |
1105 | ||
c2a04078 | 1106 | #ifdef CONFIG_IEEE80211R |
62c72d72 JM |
1107 | #ifdef CONFIG_SME |
1108 | if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) { | |
1109 | u8 bssid[ETH_ALEN]; | |
1110 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || | |
1111 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, | |
1112 | data->assoc_info.resp_ies, | |
1113 | data->assoc_info.resp_ies_len, | |
1114 | bssid) < 0) { | |
f049052b BG |
1115 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " |
1116 | "Reassociation Response failed"); | |
579ce771 JM |
1117 | wpa_supplicant_deauthenticate( |
1118 | wpa_s, WLAN_REASON_INVALID_IE); | |
1119 | return -1; | |
62c72d72 JM |
1120 | } |
1121 | } | |
62c72d72 | 1122 | |
c2a04078 JM |
1123 | p = data->assoc_info.resp_ies; |
1124 | l = data->assoc_info.resp_ies_len; | |
1125 | ||
54f489be | 1126 | #ifdef CONFIG_WPS_STRICT |
5dac11e0 | 1127 | if (p && wpa_s->current_ssid && |
54f489be JM |
1128 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) { |
1129 | struct wpabuf *wps; | |
1130 | wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE); | |
1131 | if (wps == NULL) { | |
f049052b BG |
1132 | wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not " |
1133 | "include WPS IE in (Re)Association Response"); | |
54f489be JM |
1134 | return -1; |
1135 | } | |
1136 | ||
1137 | if (wps_validate_assoc_resp(wps) < 0) { | |
1138 | wpabuf_free(wps); | |
1139 | wpa_supplicant_deauthenticate( | |
1140 | wpa_s, WLAN_REASON_INVALID_IE); | |
1141 | return -1; | |
1142 | } | |
1143 | wpabuf_free(wps); | |
1144 | } | |
1145 | #endif /* CONFIG_WPS_STRICT */ | |
1146 | ||
e7846b68 | 1147 | /* Go through the IEs and make a copy of the MDIE, if present. */ |
c2a04078 JM |
1148 | while (p && l >= 2) { |
1149 | len = p[1] + 2; | |
1150 | if (len > l) { | |
1151 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
1152 | p, l); | |
1153 | break; | |
1154 | } | |
e7846b68 JM |
1155 | if (p[0] == WLAN_EID_MOBILITY_DOMAIN && |
1156 | p[1] >= MOBILITY_DOMAIN_ID_LEN) { | |
1157 | wpa_s->sme.ft_used = 1; | |
1158 | os_memcpy(wpa_s->sme.mobility_domain, p + 2, | |
1159 | MOBILITY_DOMAIN_ID_LEN); | |
1160 | break; | |
1161 | } | |
c2a04078 JM |
1162 | l -= len; |
1163 | p += len; | |
1164 | } | |
e7846b68 | 1165 | #endif /* CONFIG_SME */ |
c2a04078 | 1166 | |
e7846b68 JM |
1167 | wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies, |
1168 | data->assoc_info.resp_ies_len); | |
c2a04078 JM |
1169 | #endif /* CONFIG_IEEE80211R */ |
1170 | ||
6fc6879b JM |
1171 | /* WPA/RSN IE from Beacon/ProbeResp */ |
1172 | p = data->assoc_info.beacon_ies; | |
1173 | l = data->assoc_info.beacon_ies_len; | |
1174 | ||
1175 | /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. | |
1176 | */ | |
1177 | wpa_found = rsn_found = 0; | |
1178 | while (p && l >= 2) { | |
1179 | len = p[1] + 2; | |
1180 | if (len > l) { | |
1181 | wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", | |
1182 | p, l); | |
1183 | break; | |
1184 | } | |
1185 | if (!wpa_found && | |
1186 | p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
1187 | os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { | |
1188 | wpa_found = 1; | |
1189 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); | |
1190 | } | |
1191 | ||
1192 | if (!rsn_found && | |
1193 | p[0] == WLAN_EID_RSN && p[1] >= 2) { | |
1194 | rsn_found = 1; | |
1195 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); | |
1196 | } | |
1197 | ||
1198 | l -= len; | |
1199 | p += len; | |
1200 | } | |
1201 | ||
1202 | if (!wpa_found && data->assoc_info.beacon_ies) | |
1203 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); | |
1204 | if (!rsn_found && data->assoc_info.beacon_ies) | |
1205 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); | |
1206 | if (wpa_found || rsn_found) | |
1207 | wpa_s->ap_ies_from_associnfo = 1; | |
4832ecd7 | 1208 | |
117e812d JM |
1209 | if (wpa_s->assoc_freq && data->assoc_info.freq && |
1210 | wpa_s->assoc_freq != data->assoc_info.freq) { | |
1211 | wpa_printf(MSG_DEBUG, "Operating frequency changed from " | |
1212 | "%u to %u MHz", | |
1213 | wpa_s->assoc_freq, data->assoc_info.freq); | |
1214 | wpa_supplicant_update_scan_results(wpa_s); | |
1215 | } | |
1216 | ||
4832ecd7 | 1217 | wpa_s->assoc_freq = data->assoc_info.freq; |
579ce771 JM |
1218 | |
1219 | return 0; | |
6fc6879b JM |
1220 | } |
1221 | ||
1222 | ||
1223 | static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, | |
1224 | union wpa_event_data *data) | |
1225 | { | |
1226 | u8 bssid[ETH_ALEN]; | |
1d041bec | 1227 | int ft_completed; |
8bac466b | 1228 | int bssid_changed; |
0194fedb | 1229 | struct wpa_driver_capa capa; |
6fc6879b | 1230 | |
1d041bec JM |
1231 | #ifdef CONFIG_AP |
1232 | if (wpa_s->ap_iface) { | |
1233 | hostapd_notif_assoc(wpa_s->ap_iface->bss[0], | |
1234 | data->assoc_info.addr, | |
1235 | data->assoc_info.req_ies, | |
39b08b5f SP |
1236 | data->assoc_info.req_ies_len, |
1237 | data->assoc_info.reassoc); | |
1d041bec JM |
1238 | return; |
1239 | } | |
1240 | #endif /* CONFIG_AP */ | |
1241 | ||
1242 | ft_completed = wpa_ft_is_completed(wpa_s->wpa); | |
579ce771 JM |
1243 | if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0) |
1244 | return; | |
6fc6879b JM |
1245 | |
1246 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); | |
c2a04078 | 1247 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) |
6fc6879b | 1248 | os_memcpy(bssid, wpa_s->bssid, ETH_ALEN); |
c2a04078 | 1249 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) || |
6fc6879b JM |
1250 | (wpa_drv_get_bssid(wpa_s, bssid) >= 0 && |
1251 | os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) { | |
f049052b | 1252 | wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" |
6fc6879b | 1253 | MACSTR, MAC2STR(bssid)); |
bbb921da | 1254 | random_add_randomness(bssid, ETH_ALEN); |
8bac466b | 1255 | bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN); |
6fc6879b JM |
1256 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
1257 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
8bac466b JM |
1258 | if (bssid_changed) |
1259 | wpas_notify_bssid_changed(wpa_s); | |
1260 | ||
6fc6879b JM |
1261 | if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { |
1262 | wpa_clear_keys(wpa_s, bssid); | |
1263 | } | |
1264 | if (wpa_supplicant_select_config(wpa_s) < 0) { | |
1265 | wpa_supplicant_disassociate( | |
1266 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
1267 | return; | |
1268 | } | |
8f770587 JM |
1269 | if (wpa_s->current_ssid) { |
1270 | struct wpa_bss *bss = NULL; | |
1271 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
1272 | if (ssid->ssid_len > 0) | |
1273 | bss = wpa_bss_get(wpa_s, bssid, | |
1274 | ssid->ssid, ssid->ssid_len); | |
1275 | if (!bss) | |
1276 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
1277 | if (bss) | |
1278 | wpa_s->current_bss = bss; | |
1279 | } | |
6fc6879b JM |
1280 | } |
1281 | ||
62fa124c JM |
1282 | #ifdef CONFIG_SME |
1283 | os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN); | |
1284 | wpa_s->sme.prev_bssid_set = 1; | |
1285 | #endif /* CONFIG_SME */ | |
1286 | ||
6fc6879b JM |
1287 | wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); |
1288 | if (wpa_s->current_ssid) { | |
1289 | /* When using scanning (ap_scan=1), SIM PC/SC interface can be | |
1290 | * initialized before association, but for other modes, | |
1291 | * initialize PC/SC here, if the current configuration needs | |
1292 | * smartcard or SIM/USIM. */ | |
1293 | wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); | |
1294 | } | |
1295 | wpa_sm_notify_assoc(wpa_s->wpa, bssid); | |
3f967fe0 JM |
1296 | if (wpa_s->l2) |
1297 | l2_packet_notify_auth_start(wpa_s->l2); | |
6fc6879b JM |
1298 | |
1299 | /* | |
1300 | * Set portEnabled first to FALSE in order to get EAP state machine out | |
1301 | * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE | |
1302 | * state machine may transit to AUTHENTICATING state based on obsolete | |
1303 | * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to | |
1304 | * AUTHENTICATED without ever giving chance to EAP state machine to | |
1305 | * reset the state. | |
1306 | */ | |
1307 | if (!ft_completed) { | |
1308 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); | |
1309 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
1310 | } | |
56586197 | 1311 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed) |
6fc6879b JM |
1312 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
1313 | /* 802.1X::portControl = Auto */ | |
1314 | eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE); | |
1315 | wpa_s->eapol_received = 0; | |
1316 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
9c972abb JM |
1317 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || |
1318 | (wpa_s->current_ssid && | |
1319 | wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) { | |
6fc6879b JM |
1320 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
1321 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1322 | } else if (!ft_completed) { | |
1323 | /* Timeout for receiving the first EAPOL packet */ | |
1324 | wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); | |
1325 | } | |
1326 | wpa_supplicant_cancel_scan(wpa_s); | |
1327 | ||
c2a04078 | 1328 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
56586197 | 1329 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
6fc6879b JM |
1330 | /* |
1331 | * We are done; the driver will take care of RSN 4-way | |
1332 | * handshake. | |
1333 | */ | |
1334 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
1335 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1336 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
1337 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
98ea9431 JM |
1338 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
1339 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { | |
1340 | /* | |
1341 | * The driver will take care of RSN 4-way handshake, so we need | |
1342 | * to allow EAPOL supplicant to complete its work without | |
1343 | * waiting for WPA supplicant. | |
1344 | */ | |
1345 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
16a83d29 JM |
1346 | } else if (ft_completed) { |
1347 | /* | |
1348 | * FT protocol completed - make sure EAPOL state machine ends | |
1349 | * up in authenticated. | |
1350 | */ | |
1351 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
1352 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1353 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
1354 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
6fc6879b | 1355 | } |
1ff73338 JM |
1356 | |
1357 | if (wpa_s->pending_eapol_rx) { | |
1358 | struct os_time now, age; | |
1359 | os_get_time(&now); | |
1360 | os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age); | |
1361 | if (age.sec == 0 && age.usec < 100000 && | |
1362 | os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) == | |
1363 | 0) { | |
f049052b BG |
1364 | wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL " |
1365 | "frame that was received just before " | |
1366 | "association notification"); | |
1ff73338 JM |
1367 | wpa_supplicant_rx_eapol( |
1368 | wpa_s, wpa_s->pending_eapol_rx_src, | |
1369 | wpabuf_head(wpa_s->pending_eapol_rx), | |
1370 | wpabuf_len(wpa_s->pending_eapol_rx)); | |
1371 | } | |
1372 | wpabuf_free(wpa_s->pending_eapol_rx); | |
1373 | wpa_s->pending_eapol_rx = NULL; | |
1374 | } | |
60b94c98 | 1375 | |
0194fedb JB |
1376 | if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
1377 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
1378 | wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 && | |
1379 | capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) { | |
1380 | /* Set static WEP keys again */ | |
1381 | wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); | |
1382 | } | |
50b05780 JM |
1383 | |
1384 | #ifdef CONFIG_IBSS_RSN | |
1385 | if (wpa_s->current_ssid && | |
1386 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && | |
1387 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && | |
78177a00 JM |
1388 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE && |
1389 | wpa_s->ibss_rsn == NULL) { | |
1390 | wpa_s->ibss_rsn = ibss_rsn_init(wpa_s); | |
1391 | if (!wpa_s->ibss_rsn) { | |
1392 | wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN"); | |
1393 | wpa_supplicant_deauthenticate( | |
1394 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
1395 | return; | |
1396 | } | |
1397 | ||
1398 | ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk); | |
1399 | } | |
50b05780 | 1400 | #endif /* CONFIG_IBSS_RSN */ |
6fc6879b JM |
1401 | } |
1402 | ||
1403 | ||
0544b242 JM |
1404 | static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, |
1405 | u16 reason_code) | |
6fc6879b JM |
1406 | { |
1407 | const u8 *bssid; | |
6d6f4bb8 JM |
1408 | int authenticating; |
1409 | u8 prev_pending_bssid[ETH_ALEN]; | |
1410 | ||
1411 | authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING; | |
1412 | os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN); | |
6fc6879b JM |
1413 | |
1414 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
1415 | /* | |
1416 | * At least Host AP driver and a Prism3 card seemed to be | |
1417 | * generating streams of disconnected events when configuring | |
1418 | * IBSS for WPA-None. Ignore them for now. | |
1419 | */ | |
f049052b BG |
1420 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in " |
1421 | "IBSS/WPA-None mode"); | |
6fc6879b JM |
1422 | return; |
1423 | } | |
1424 | ||
1425 | if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE && | |
56586197 | 1426 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
6fc6879b JM |
1427 | wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " |
1428 | "pre-shared key may be incorrect"); | |
1429 | } | |
0d0a8ca1 AC |
1430 | if (!wpa_s->auto_reconnect_disabled || |
1431 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { | |
f049052b BG |
1432 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect enabled: try to " |
1433 | "reconnect (wps=%d)", | |
1434 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS); | |
ea184114 | 1435 | if (wpa_s->wpa_state >= WPA_ASSOCIATING) |
0d0a8ca1 AC |
1436 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
1437 | } else { | |
f049052b BG |
1438 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect disabled: do not " |
1439 | "try to re-connect"); | |
0d0a8ca1 AC |
1440 | wpa_s->reassociate = 0; |
1441 | wpa_s->disconnected = 1; | |
1442 | } | |
6fc6879b | 1443 | bssid = wpa_s->bssid; |
a8e16edc | 1444 | if (is_zero_ether_addr(bssid)) |
6fc6879b | 1445 | bssid = wpa_s->pending_bssid; |
0fb337c1 | 1446 | wpas_connection_failed(wpa_s, bssid); |
6fc6879b | 1447 | wpa_sm_notify_disassoc(wpa_s->wpa); |
0544b242 JM |
1448 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR |
1449 | " reason=%d", | |
1450 | MAC2STR(bssid), reason_code); | |
6fc6879b | 1451 | if (wpa_supplicant_dynamic_keys(wpa_s)) { |
f049052b | 1452 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys"); |
6fc6879b JM |
1453 | wpa_s->keys_cleared = 0; |
1454 | wpa_clear_keys(wpa_s, wpa_s->bssid); | |
1455 | } | |
1456 | wpa_supplicant_mark_disassoc(wpa_s); | |
e29853bb BG |
1457 | |
1458 | if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) | |
1459 | sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid); | |
6fc6879b JM |
1460 | } |
1461 | ||
1462 | ||
46690a3b JM |
1463 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
1464 | static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, | |
1465 | void *sock_ctx) | |
1466 | { | |
1467 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1468 | ||
1469 | if (!wpa_s->pending_mic_error_report) | |
1470 | return; | |
1471 | ||
f049052b | 1472 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report"); |
46690a3b JM |
1473 | wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); |
1474 | wpa_s->pending_mic_error_report = 0; | |
1475 | } | |
1476 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
1477 | ||
1478 | ||
6fc6879b JM |
1479 | static void |
1480 | wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, | |
1481 | union wpa_event_data *data) | |
1482 | { | |
1483 | int pairwise; | |
1484 | struct os_time t; | |
1485 | ||
1486 | wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); | |
1487 | pairwise = (data && data->michael_mic_failure.unicast); | |
6fc6879b | 1488 | os_get_time(&t); |
46690a3b JM |
1489 | if ((wpa_s->last_michael_mic_error && |
1490 | t.sec - wpa_s->last_michael_mic_error <= 60) || | |
1491 | wpa_s->pending_mic_error_report) { | |
1492 | if (wpa_s->pending_mic_error_report) { | |
1493 | /* | |
1494 | * Send the pending MIC error report immediately since | |
1495 | * we are going to start countermeasures and AP better | |
1496 | * do the same. | |
1497 | */ | |
1498 | wpa_sm_key_request(wpa_s->wpa, 1, | |
1499 | wpa_s->pending_mic_error_pairwise); | |
1500 | } | |
1501 | ||
1502 | /* Send the new MIC error report immediately since we are going | |
1503 | * to start countermeasures and AP better do the same. | |
1504 | */ | |
1505 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1506 | ||
6fc6879b JM |
1507 | /* initialize countermeasures */ |
1508 | wpa_s->countermeasures = 1; | |
1509 | wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); | |
1510 | ||
1511 | /* | |
1512 | * Need to wait for completion of request frame. We do not get | |
1513 | * any callback for the message completion, so just wait a | |
1514 | * short while and hope for the best. */ | |
1515 | os_sleep(0, 10000); | |
1516 | ||
1517 | wpa_drv_set_countermeasures(wpa_s, 1); | |
1518 | wpa_supplicant_deauthenticate(wpa_s, | |
1519 | WLAN_REASON_MICHAEL_MIC_FAILURE); | |
1520 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, | |
1521 | wpa_s, NULL); | |
1522 | eloop_register_timeout(60, 0, | |
1523 | wpa_supplicant_stop_countermeasures, | |
1524 | wpa_s, NULL); | |
1525 | /* TODO: mark the AP rejected for 60 second. STA is | |
1526 | * allowed to associate with another AP.. */ | |
46690a3b JM |
1527 | } else { |
1528 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT | |
1529 | if (wpa_s->mic_errors_seen) { | |
1530 | /* | |
1531 | * Reduce the effectiveness of Michael MIC error | |
1532 | * reports as a means for attacking against TKIP if | |
1533 | * more than one MIC failure is noticed with the same | |
1534 | * PTK. We delay the transmission of the reports by a | |
1535 | * random time between 0 and 60 seconds in order to | |
1536 | * force the attacker wait 60 seconds before getting | |
1537 | * the information on whether a frame resulted in a MIC | |
1538 | * failure. | |
1539 | */ | |
1540 | u8 rval[4]; | |
1541 | int sec; | |
1542 | ||
1543 | if (os_get_random(rval, sizeof(rval)) < 0) | |
1544 | sec = os_random() % 60; | |
1545 | else | |
1546 | sec = WPA_GET_BE32(rval) % 60; | |
f049052b BG |
1547 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error " |
1548 | "report %d seconds", sec); | |
46690a3b JM |
1549 | wpa_s->pending_mic_error_report = 1; |
1550 | wpa_s->pending_mic_error_pairwise = pairwise; | |
1551 | eloop_cancel_timeout( | |
1552 | wpa_supplicant_delayed_mic_error_report, | |
1553 | wpa_s, NULL); | |
1554 | eloop_register_timeout( | |
1555 | sec, os_random() % 1000000, | |
1556 | wpa_supplicant_delayed_mic_error_report, | |
1557 | wpa_s, NULL); | |
1558 | } else { | |
1559 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1560 | } | |
1561 | #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
1562 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1563 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
6fc6879b JM |
1564 | } |
1565 | wpa_s->last_michael_mic_error = t.sec; | |
46690a3b | 1566 | wpa_s->mic_errors_seen++; |
6fc6879b JM |
1567 | } |
1568 | ||
1569 | ||
a83d9c96 SL |
1570 | #ifdef CONFIG_TERMINATE_ONLASTIF |
1571 | static int any_interfaces(struct wpa_supplicant *head) | |
1572 | { | |
1573 | struct wpa_supplicant *wpa_s; | |
1574 | ||
1575 | for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) | |
1576 | if (!wpa_s->interface_removed) | |
1577 | return 1; | |
1578 | return 0; | |
1579 | } | |
1580 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
1581 | ||
1582 | ||
6fc6879b JM |
1583 | static void |
1584 | wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, | |
1585 | union wpa_event_data *data) | |
1586 | { | |
1587 | if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) | |
1588 | return; | |
1589 | ||
1590 | switch (data->interface_status.ievent) { | |
1591 | case EVENT_INTERFACE_ADDED: | |
1592 | if (!wpa_s->interface_removed) | |
1593 | break; | |
1594 | wpa_s->interface_removed = 0; | |
f049052b | 1595 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added"); |
6fc6879b | 1596 | if (wpa_supplicant_driver_init(wpa_s) < 0) { |
f049052b BG |
1597 | wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the " |
1598 | "driver after interface was added"); | |
6fc6879b JM |
1599 | } |
1600 | break; | |
1601 | case EVENT_INTERFACE_REMOVED: | |
f049052b | 1602 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed"); |
6fc6879b JM |
1603 | wpa_s->interface_removed = 1; |
1604 | wpa_supplicant_mark_disassoc(wpa_s); | |
1605 | l2_packet_deinit(wpa_s->l2); | |
1606 | wpa_s->l2 = NULL; | |
ea244d21 | 1607 | #ifdef CONFIG_IBSS_RSN |
78177a00 JM |
1608 | ibss_rsn_deinit(wpa_s->ibss_rsn); |
1609 | wpa_s->ibss_rsn = NULL; | |
ea244d21 | 1610 | #endif /* CONFIG_IBSS_RSN */ |
a83d9c96 SL |
1611 | #ifdef CONFIG_TERMINATE_ONLASTIF |
1612 | /* check if last interface */ | |
1613 | if (!any_interfaces(wpa_s->global->ifaces)) | |
1614 | eloop_terminate(); | |
1615 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
6fc6879b JM |
1616 | break; |
1617 | } | |
1618 | } | |
1619 | ||
1620 | ||
1621 | #ifdef CONFIG_PEERKEY | |
1622 | static void | |
1623 | wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s, | |
1624 | union wpa_event_data *data) | |
1625 | { | |
1626 | if (data == NULL) | |
1627 | return; | |
1628 | wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer); | |
1629 | } | |
1630 | #endif /* CONFIG_PEERKEY */ | |
1631 | ||
1632 | ||
281ff0aa GP |
1633 | #ifdef CONFIG_TDLS |
1634 | static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s, | |
1635 | union wpa_event_data *data) | |
1636 | { | |
1637 | if (data == NULL) | |
1638 | return; | |
1639 | switch (data->tdls.oper) { | |
1640 | case TDLS_REQUEST_SETUP: | |
1641 | wpa_tdls_start(wpa_s->wpa, data->tdls.peer); | |
1642 | break; | |
1643 | case TDLS_REQUEST_TEARDOWN: | |
1644 | /* request from driver to add FTIE */ | |
1645 | wpa_tdls_recv_teardown_notify(wpa_s->wpa, data->tdls.peer, | |
1646 | data->tdls.reason_code); | |
1647 | break; | |
1648 | } | |
1649 | } | |
1650 | #endif /* CONFIG_TDLS */ | |
1651 | ||
1652 | ||
6fc6879b JM |
1653 | #ifdef CONFIG_IEEE80211R |
1654 | static void | |
1655 | wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s, | |
1656 | union wpa_event_data *data) | |
1657 | { | |
1658 | if (data == NULL) | |
1659 | return; | |
1660 | ||
1661 | if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies, | |
1662 | data->ft_ies.ies_len, | |
1663 | data->ft_ies.ft_action, | |
babfbf15 JM |
1664 | data->ft_ies.target_ap, |
1665 | data->ft_ies.ric_ies, | |
1666 | data->ft_ies.ric_ies_len) < 0) { | |
6fc6879b JM |
1667 | /* TODO: prevent MLME/driver from trying to associate? */ |
1668 | } | |
1669 | } | |
1670 | #endif /* CONFIG_IEEE80211R */ | |
1671 | ||
1672 | ||
11ef8d35 JM |
1673 | #ifdef CONFIG_IBSS_RSN |
1674 | static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s, | |
1675 | union wpa_event_data *data) | |
1676 | { | |
df4bc509 | 1677 | struct wpa_ssid *ssid; |
df418245 XC |
1678 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
1679 | return; | |
11ef8d35 JM |
1680 | if (data == NULL) |
1681 | return; | |
df4bc509 JM |
1682 | ssid = wpa_s->current_ssid; |
1683 | if (ssid == NULL) | |
1684 | return; | |
1685 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) | |
1686 | return; | |
1687 | ||
11ef8d35 JM |
1688 | ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); |
1689 | } | |
1690 | #endif /* CONFIG_IBSS_RSN */ | |
1691 | ||
1692 | ||
036f7c4a JM |
1693 | #ifdef CONFIG_IEEE80211R |
1694 | static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data, | |
1695 | size_t len) | |
1696 | { | |
1697 | const u8 *sta_addr, *target_ap_addr; | |
1698 | u16 status; | |
1699 | ||
1700 | wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len); | |
1701 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) | |
1702 | return; /* only SME case supported for now */ | |
1703 | if (len < 1 + 2 * ETH_ALEN + 2) | |
1704 | return; | |
1705 | if (data[0] != 2) | |
1706 | return; /* Only FT Action Response is supported for now */ | |
1707 | sta_addr = data + 1; | |
1708 | target_ap_addr = data + 1 + ETH_ALEN; | |
1709 | status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN); | |
f049052b BG |
1710 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA " |
1711 | MACSTR " TargetAP " MACSTR " status %u", | |
1712 | MAC2STR(sta_addr), MAC2STR(target_ap_addr), status); | |
036f7c4a JM |
1713 | |
1714 | if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) { | |
f049052b BG |
1715 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR |
1716 | " in FT Action Response", MAC2STR(sta_addr)); | |
036f7c4a JM |
1717 | return; |
1718 | } | |
1719 | ||
1720 | if (status) { | |
f049052b BG |
1721 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates " |
1722 | "failure (status code %d)", status); | |
036f7c4a JM |
1723 | /* TODO: report error to FT code(?) */ |
1724 | return; | |
1725 | } | |
1726 | ||
1727 | if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2, | |
1728 | len - (1 + 2 * ETH_ALEN + 2), 1, | |
1729 | target_ap_addr, NULL, 0) < 0) | |
1730 | return; | |
1731 | ||
fe191985 JM |
1732 | #ifdef CONFIG_SME |
1733 | { | |
1734 | struct wpa_bss *bss; | |
1735 | bss = wpa_bss_get_bssid(wpa_s, target_ap_addr); | |
1736 | if (bss) | |
1737 | wpa_s->sme.freq = bss->freq; | |
62c72d72 | 1738 | wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT; |
fe191985 JM |
1739 | sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr, |
1740 | WLAN_AUTH_FT); | |
1741 | } | |
1742 | #endif /* CONFIG_SME */ | |
036f7c4a JM |
1743 | } |
1744 | #endif /* CONFIG_IEEE80211R */ | |
1745 | ||
1746 | ||
7d878ca7 JM |
1747 | static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s, |
1748 | struct unprot_deauth *e) | |
1749 | { | |
1750 | #ifdef CONFIG_IEEE80211W | |
1751 | wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame " | |
1752 | "dropped: " MACSTR " -> " MACSTR | |
1753 | " (reason code %u)", | |
1754 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); | |
1755 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); | |
1756 | #endif /* CONFIG_IEEE80211W */ | |
1757 | } | |
1758 | ||
1759 | ||
1760 | static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s, | |
1761 | struct unprot_disassoc *e) | |
1762 | { | |
1763 | #ifdef CONFIG_IEEE80211W | |
1764 | wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame " | |
1765 | "dropped: " MACSTR " -> " MACSTR | |
1766 | " (reason code %u)", | |
1767 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); | |
1768 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); | |
1769 | #endif /* CONFIG_IEEE80211W */ | |
1770 | } | |
1771 | ||
1772 | ||
9646a8ab | 1773 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
6fc6879b JM |
1774 | union wpa_event_data *data) |
1775 | { | |
1776 | struct wpa_supplicant *wpa_s = ctx; | |
0544b242 | 1777 | u16 reason_code = 0; |
6fc6879b | 1778 | |
8401a6b0 JM |
1779 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED && |
1780 | event != EVENT_INTERFACE_ENABLED && | |
1781 | event != EVENT_INTERFACE_STATUS) { | |
f049052b BG |
1782 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore event %d while interface is " |
1783 | "disabled", event); | |
8401a6b0 JM |
1784 | return; |
1785 | } | |
1786 | ||
f049052b BG |
1787 | wpa_dbg(wpa_s, MSG_DEBUG, "Event %d received on interface %s", |
1788 | event, wpa_s->ifname); | |
9b7124b2 | 1789 | |
6fc6879b | 1790 | switch (event) { |
c2a04078 JM |
1791 | case EVENT_AUTH: |
1792 | sme_event_auth(wpa_s, data); | |
1793 | break; | |
6fc6879b JM |
1794 | case EVENT_ASSOC: |
1795 | wpa_supplicant_event_assoc(wpa_s, data); | |
1796 | break; | |
1797 | case EVENT_DISASSOC: | |
f049052b | 1798 | wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification"); |
2e75a2b3 | 1799 | if (data) { |
f049052b BG |
1800 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u", |
1801 | data->disassoc_info.reason_code); | |
2e75a2b3 | 1802 | if (data->disassoc_info.addr) |
f049052b BG |
1803 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, |
1804 | MAC2STR(data->disassoc_info.addr)); | |
2e75a2b3 | 1805 | } |
1d041bec | 1806 | #ifdef CONFIG_AP |
7f542069 | 1807 | if (wpa_s->ap_iface && data && data->disassoc_info.addr) { |
1d041bec JM |
1808 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], |
1809 | data->disassoc_info.addr); | |
1810 | break; | |
1811 | } | |
1812 | #endif /* CONFIG_AP */ | |
9fdd0fad JM |
1813 | if (data) { |
1814 | reason_code = data->disassoc_info.reason_code; | |
1815 | wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)", | |
1816 | data->disassoc_info.ie, | |
1817 | data->disassoc_info.ie_len); | |
1818 | #ifdef CONFIG_P2P | |
1819 | wpas_p2p_disassoc_notif( | |
1820 | wpa_s, data->disassoc_info.addr, reason_code, | |
1821 | data->disassoc_info.ie, | |
1822 | data->disassoc_info.ie_len); | |
1823 | #endif /* CONFIG_P2P */ | |
1824 | } | |
0e379654 JM |
1825 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
1826 | sme_event_disassoc(wpa_s, data); | |
a84ed99e JM |
1827 | /* fall through */ |
1828 | case EVENT_DEAUTH: | |
0544b242 | 1829 | if (event == EVENT_DEAUTH) { |
f049052b BG |
1830 | wpa_dbg(wpa_s, MSG_DEBUG, |
1831 | "Deauthentication notification"); | |
2e75a2b3 | 1832 | if (data) { |
0544b242 | 1833 | reason_code = data->deauth_info.reason_code; |
f049052b BG |
1834 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u", |
1835 | data->deauth_info.reason_code); | |
2e75a2b3 | 1836 | if (data->deauth_info.addr) { |
f049052b BG |
1837 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " |
1838 | MACSTR, | |
1839 | MAC2STR(data->deauth_info. | |
1840 | addr)); | |
2e75a2b3 | 1841 | } |
9fdd0fad JM |
1842 | wpa_hexdump(MSG_DEBUG, |
1843 | "Deauthentication frame IE(s)", | |
1844 | data->deauth_info.ie, | |
1845 | data->deauth_info.ie_len); | |
1846 | #ifdef CONFIG_P2P | |
1847 | wpas_p2p_deauth_notif( | |
1848 | wpa_s, data->deauth_info.addr, | |
1849 | reason_code, | |
1850 | data->deauth_info.ie, | |
1851 | data->deauth_info.ie_len); | |
1852 | #endif /* CONFIG_P2P */ | |
2e75a2b3 | 1853 | } |
0544b242 | 1854 | } |
1d041bec | 1855 | #ifdef CONFIG_AP |
7f542069 | 1856 | if (wpa_s->ap_iface && data && data->deauth_info.addr) { |
1d041bec JM |
1857 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], |
1858 | data->deauth_info.addr); | |
1859 | break; | |
1860 | } | |
1861 | #endif /* CONFIG_AP */ | |
0544b242 | 1862 | wpa_supplicant_event_disassoc(wpa_s, reason_code); |
6fc6879b JM |
1863 | break; |
1864 | case EVENT_MICHAEL_MIC_FAILURE: | |
1865 | wpa_supplicant_event_michael_mic_failure(wpa_s, data); | |
1866 | break; | |
1867 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
1868 | case EVENT_SCAN_RESULTS: | |
8d923a4a | 1869 | wpa_supplicant_event_scan_results(wpa_s, data); |
6fc6879b JM |
1870 | break; |
1871 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | |
1872 | case EVENT_ASSOCINFO: | |
1873 | wpa_supplicant_event_associnfo(wpa_s, data); | |
1874 | break; | |
1875 | case EVENT_INTERFACE_STATUS: | |
1876 | wpa_supplicant_event_interface_status(wpa_s, data); | |
1877 | break; | |
1878 | case EVENT_PMKID_CANDIDATE: | |
1879 | wpa_supplicant_event_pmkid_candidate(wpa_s, data); | |
1880 | break; | |
1881 | #ifdef CONFIG_PEERKEY | |
1882 | case EVENT_STKSTART: | |
1883 | wpa_supplicant_event_stkstart(wpa_s, data); | |
1884 | break; | |
1885 | #endif /* CONFIG_PEERKEY */ | |
281ff0aa GP |
1886 | #ifdef CONFIG_TDLS |
1887 | case EVENT_TDLS: | |
1888 | wpa_supplicant_event_tdls(wpa_s, data); | |
1889 | break; | |
1890 | #endif /* CONFIG_TDLS */ | |
6fc6879b JM |
1891 | #ifdef CONFIG_IEEE80211R |
1892 | case EVENT_FT_RESPONSE: | |
1893 | wpa_supplicant_event_ft_response(wpa_s, data); | |
1894 | break; | |
1895 | #endif /* CONFIG_IEEE80211R */ | |
11ef8d35 JM |
1896 | #ifdef CONFIG_IBSS_RSN |
1897 | case EVENT_IBSS_RSN_START: | |
1898 | wpa_supplicant_event_ibss_rsn_start(wpa_s, data); | |
1899 | break; | |
1900 | #endif /* CONFIG_IBSS_RSN */ | |
efa46078 | 1901 | case EVENT_ASSOC_REJECT: |
c05d6d18 JM |
1902 | if (data->assoc_reject.bssid) |
1903 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT | |
1904 | "bssid=" MACSTR " status_code=%u", | |
1905 | MAC2STR(data->assoc_reject.bssid), | |
1906 | data->assoc_reject.status_code); | |
1907 | else | |
1908 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT | |
1909 | "status_code=%u", | |
1910 | data->assoc_reject.status_code); | |
ea78c315 JM |
1911 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
1912 | sme_event_assoc_reject(wpa_s, data); | |
efa46078 | 1913 | break; |
da1fb17c | 1914 | case EVENT_AUTH_TIMED_OUT: |
ea78c315 JM |
1915 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
1916 | sme_event_auth_timed_out(wpa_s, data); | |
da1fb17c JM |
1917 | break; |
1918 | case EVENT_ASSOC_TIMED_OUT: | |
ea78c315 JM |
1919 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
1920 | sme_event_assoc_timed_out(wpa_s, data); | |
da1fb17c | 1921 | break; |
f8b1f695 | 1922 | case EVENT_TX_STATUS: |
f049052b BG |
1923 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR |
1924 | " type=%d stype=%d", | |
1925 | MAC2STR(data->tx_status.dst), | |
1926 | data->tx_status.type, data->tx_status.stype); | |
24f6497c | 1927 | #ifdef CONFIG_AP |
9bae1be0 | 1928 | if (wpa_s->ap_iface == NULL) { |
24f6497c | 1929 | #ifdef CONFIG_OFFCHANNEL |
9bae1be0 JM |
1930 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
1931 | data->tx_status.stype == WLAN_FC_STYPE_ACTION) | |
24f6497c | 1932 | offchannel_send_action_tx_status( |
9bae1be0 JM |
1933 | wpa_s, data->tx_status.dst, |
1934 | data->tx_status.data, | |
1935 | data->tx_status.data_len, | |
93b7ddd0 | 1936 | data->tx_status.ack ? |
24f6497c JM |
1937 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
1938 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
1939 | #endif /* CONFIG_OFFCHANNEL */ | |
9bae1be0 JM |
1940 | break; |
1941 | } | |
24f6497c JM |
1942 | #endif /* CONFIG_AP */ |
1943 | #ifdef CONFIG_OFFCHANNEL | |
f049052b BG |
1944 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst=" |
1945 | MACSTR, MAC2STR(wpa_s->parent->pending_action_dst)); | |
9bae1be0 JM |
1946 | /* |
1947 | * Catch TX status events for Action frames we sent via group | |
1948 | * interface in GO mode. | |
1949 | */ | |
1950 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && | |
1951 | data->tx_status.stype == WLAN_FC_STYPE_ACTION && | |
1952 | os_memcmp(wpa_s->parent->pending_action_dst, | |
1953 | data->tx_status.dst, ETH_ALEN) == 0) { | |
24f6497c | 1954 | offchannel_send_action_tx_status( |
9bae1be0 JM |
1955 | wpa_s->parent, data->tx_status.dst, |
1956 | data->tx_status.data, | |
1957 | data->tx_status.data_len, | |
1d39378a | 1958 | data->tx_status.ack ? |
24f6497c JM |
1959 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
1960 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
f8b1f695 | 1961 | break; |
9bae1be0 | 1962 | } |
24f6497c JM |
1963 | #endif /* CONFIG_OFFCHANNEL */ |
1964 | #ifdef CONFIG_AP | |
f8b1f695 JM |
1965 | switch (data->tx_status.type) { |
1966 | case WLAN_FC_TYPE_MGMT: | |
1967 | ap_mgmt_tx_cb(wpa_s, data->tx_status.data, | |
1968 | data->tx_status.data_len, | |
1969 | data->tx_status.stype, | |
1970 | data->tx_status.ack); | |
1971 | break; | |
1972 | case WLAN_FC_TYPE_DATA: | |
1973 | ap_tx_status(wpa_s, data->tx_status.dst, | |
1974 | data->tx_status.data, | |
1975 | data->tx_status.data_len, | |
1976 | data->tx_status.ack); | |
1977 | break; | |
1978 | } | |
24f6497c | 1979 | #endif /* CONFIG_AP */ |
f8b1f695 | 1980 | break; |
24f6497c | 1981 | #ifdef CONFIG_AP |
f8b1f695 JM |
1982 | case EVENT_RX_FROM_UNKNOWN: |
1983 | if (wpa_s->ap_iface == NULL) | |
1984 | break; | |
fdbe50ed | 1985 | ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame, |
f8b1f695 JM |
1986 | data->rx_from_unknown.len); |
1987 | break; | |
1988 | case EVENT_RX_MGMT: | |
9bae1be0 JM |
1989 | if (wpa_s->ap_iface == NULL) { |
1990 | #ifdef CONFIG_P2P | |
1991 | u16 fc, stype; | |
1992 | const struct ieee80211_mgmt *mgmt; | |
1993 | mgmt = (const struct ieee80211_mgmt *) | |
1994 | data->rx_mgmt.frame; | |
1995 | fc = le_to_host16(mgmt->frame_control); | |
1996 | stype = WLAN_FC_GET_STYPE(fc); | |
1997 | if (stype == WLAN_FC_STYPE_PROBE_REQ && | |
1998 | data->rx_mgmt.frame_len > 24) { | |
1999 | const u8 *src = mgmt->sa; | |
2000 | const u8 *ie = mgmt->u.probe_req.variable; | |
2001 | size_t ie_len = data->rx_mgmt.frame_len - | |
2002 | (mgmt->u.probe_req.variable - | |
2003 | data->rx_mgmt.frame); | |
04a85e44 JM |
2004 | wpas_p2p_probe_req_rx(wpa_s, src, mgmt->da, |
2005 | mgmt->bssid, ie, ie_len); | |
9bae1be0 JM |
2006 | break; |
2007 | } | |
2008 | #endif /* CONFIG_P2P */ | |
f049052b BG |
2009 | wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received " |
2010 | "management frame in non-AP mode"); | |
f8b1f695 | 2011 | break; |
9bae1be0 | 2012 | } |
2a8b7416 | 2013 | ap_mgmt_rx(wpa_s, &data->rx_mgmt); |
f8b1f695 JM |
2014 | break; |
2015 | #endif /* CONFIG_AP */ | |
036f7c4a | 2016 | case EVENT_RX_ACTION: |
f049052b BG |
2017 | wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR |
2018 | " Category=%u DataLen=%d freq=%d MHz", | |
2019 | MAC2STR(data->rx_action.sa), | |
2020 | data->rx_action.category, (int) data->rx_action.len, | |
2021 | data->rx_action.freq); | |
036f7c4a JM |
2022 | #ifdef CONFIG_IEEE80211R |
2023 | if (data->rx_action.category == WLAN_ACTION_FT) { | |
2024 | ft_rx_action(wpa_s, data->rx_action.data, | |
2025 | data->rx_action.len); | |
2026 | break; | |
2027 | } | |
2028 | #endif /* CONFIG_IEEE80211R */ | |
7d878ca7 JM |
2029 | #ifdef CONFIG_IEEE80211W |
2030 | #ifdef CONFIG_SME | |
2031 | if (data->rx_action.category == WLAN_ACTION_SA_QUERY) { | |
2032 | sme_sa_query_rx(wpa_s, data->rx_action.sa, | |
2033 | data->rx_action.data, | |
2034 | data->rx_action.len); | |
2035 | break; | |
2036 | } | |
2037 | #endif /* CONFIG_SME */ | |
2038 | #endif /* CONFIG_IEEE80211W */ | |
04ea7b79 JM |
2039 | #ifdef CONFIG_GAS |
2040 | if (data->rx_action.category == WLAN_ACTION_PUBLIC && | |
2041 | gas_query_rx(wpa_s->gas, data->rx_action.da, | |
2042 | data->rx_action.sa, data->rx_action.bssid, | |
2043 | data->rx_action.data, data->rx_action.len, | |
2044 | data->rx_action.freq) == 0) | |
2045 | break; | |
2046 | #endif /* CONFIG_GAS */ | |
9bae1be0 JM |
2047 | #ifdef CONFIG_P2P |
2048 | wpas_p2p_rx_action(wpa_s, data->rx_action.da, | |
2049 | data->rx_action.sa, | |
2050 | data->rx_action.bssid, | |
2051 | data->rx_action.category, | |
2052 | data->rx_action.data, | |
2053 | data->rx_action.len, data->rx_action.freq); | |
e67b55fb JM |
2054 | #endif /* CONFIG_P2P */ |
2055 | break; | |
2056 | case EVENT_RX_PROBE_REQ: | |
b211f3eb JM |
2057 | if (data->rx_probe_req.sa == NULL || |
2058 | data->rx_probe_req.ie == NULL) | |
2059 | break; | |
e67b55fb JM |
2060 | #ifdef CONFIG_AP |
2061 | if (wpa_s->ap_iface) { | |
2062 | hostapd_probe_req_rx(wpa_s->ap_iface->bss[0], | |
2063 | data->rx_probe_req.sa, | |
04a85e44 JM |
2064 | data->rx_probe_req.da, |
2065 | data->rx_probe_req.bssid, | |
e67b55fb JM |
2066 | data->rx_probe_req.ie, |
2067 | data->rx_probe_req.ie_len); | |
2068 | break; | |
2069 | } | |
2070 | #endif /* CONFIG_AP */ | |
2071 | #ifdef CONFIG_P2P | |
2072 | wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa, | |
04a85e44 JM |
2073 | data->rx_probe_req.da, |
2074 | data->rx_probe_req.bssid, | |
e67b55fb JM |
2075 | data->rx_probe_req.ie, |
2076 | data->rx_probe_req.ie_len); | |
9bae1be0 | 2077 | #endif /* CONFIG_P2P */ |
036f7c4a | 2078 | break; |
9bae1be0 | 2079 | case EVENT_REMAIN_ON_CHANNEL: |
24f6497c JM |
2080 | #ifdef CONFIG_OFFCHANNEL |
2081 | offchannel_remain_on_channel_cb( | |
2082 | wpa_s, data->remain_on_channel.freq, | |
2083 | data->remain_on_channel.duration); | |
2084 | #endif /* CONFIG_OFFCHANNEL */ | |
2085 | #ifdef CONFIG_P2P | |
9bae1be0 JM |
2086 | wpas_p2p_remain_on_channel_cb( |
2087 | wpa_s, data->remain_on_channel.freq, | |
2088 | data->remain_on_channel.duration); | |
24f6497c | 2089 | #endif /* CONFIG_P2P */ |
9bae1be0 JM |
2090 | break; |
2091 | case EVENT_CANCEL_REMAIN_ON_CHANNEL: | |
24f6497c JM |
2092 | #ifdef CONFIG_OFFCHANNEL |
2093 | offchannel_cancel_remain_on_channel_cb( | |
2094 | wpa_s, data->remain_on_channel.freq); | |
2095 | #endif /* CONFIG_OFFCHANNEL */ | |
2096 | #ifdef CONFIG_P2P | |
9bae1be0 JM |
2097 | wpas_p2p_cancel_remain_on_channel_cb( |
2098 | wpa_s, data->remain_on_channel.freq); | |
24f6497c | 2099 | #endif /* CONFIG_P2P */ |
9bae1be0 | 2100 | break; |
24f6497c | 2101 | #ifdef CONFIG_P2P |
c5db8e51 KRK |
2102 | case EVENT_P2P_DEV_FOUND: { |
2103 | struct p2p_peer_info peer_info; | |
2104 | ||
2105 | os_memset(&peer_info, 0, sizeof(peer_info)); | |
2106 | if (data->p2p_dev_found.dev_addr) | |
2107 | os_memcpy(peer_info.p2p_device_addr, | |
2108 | data->p2p_dev_found.dev_addr, ETH_ALEN); | |
2109 | if (data->p2p_dev_found.pri_dev_type) | |
2110 | os_memcpy(peer_info.pri_dev_type, | |
2111 | data->p2p_dev_found.pri_dev_type, | |
2112 | sizeof(peer_info.pri_dev_type)); | |
2113 | if (data->p2p_dev_found.dev_name) | |
2114 | os_strlcpy(peer_info.device_name, | |
2115 | data->p2p_dev_found.dev_name, | |
2116 | sizeof(peer_info.device_name)); | |
2117 | peer_info.config_methods = data->p2p_dev_found.config_methods; | |
2118 | peer_info.dev_capab = data->p2p_dev_found.dev_capab; | |
2119 | peer_info.group_capab = data->p2p_dev_found.group_capab; | |
2120 | ||
8fd7dc1b JB |
2121 | /* |
2122 | * FIX: new_device=1 is not necessarily correct. We should | |
2123 | * maintain a P2P peer database in wpa_supplicant and update | |
2124 | * this information based on whether the peer is truly new. | |
2125 | */ | |
2126 | wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1); | |
3ac17eba | 2127 | break; |
c5db8e51 | 2128 | } |
3ac17eba JM |
2129 | case EVENT_P2P_GO_NEG_REQ_RX: |
2130 | wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src, | |
2131 | data->p2p_go_neg_req_rx.dev_passwd_id); | |
2132 | break; | |
2133 | case EVENT_P2P_GO_NEG_COMPLETED: | |
2134 | wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res); | |
2135 | break; | |
2136 | case EVENT_P2P_PROV_DISC_REQUEST: | |
2137 | wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer, | |
2138 | data->p2p_prov_disc_req.config_methods, | |
2139 | data->p2p_prov_disc_req.dev_addr, | |
2140 | data->p2p_prov_disc_req.pri_dev_type, | |
2141 | data->p2p_prov_disc_req.dev_name, | |
2142 | data->p2p_prov_disc_req.supp_config_methods, | |
2143 | data->p2p_prov_disc_req.dev_capab, | |
2144 | data->p2p_prov_disc_req.group_capab); | |
2145 | break; | |
2146 | case EVENT_P2P_PROV_DISC_RESPONSE: | |
2147 | wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer, | |
2148 | data->p2p_prov_disc_resp.config_methods); | |
2149 | break; | |
2150 | case EVENT_P2P_SD_REQUEST: | |
2151 | wpas_sd_request(wpa_s, data->p2p_sd_req.freq, | |
2152 | data->p2p_sd_req.sa, | |
2153 | data->p2p_sd_req.dialog_token, | |
2154 | data->p2p_sd_req.update_indic, | |
2155 | data->p2p_sd_req.tlvs, | |
2156 | data->p2p_sd_req.tlvs_len); | |
2157 | break; | |
2158 | case EVENT_P2P_SD_RESPONSE: | |
2159 | wpas_sd_response(wpa_s, data->p2p_sd_resp.sa, | |
2160 | data->p2p_sd_resp.update_indic, | |
2161 | data->p2p_sd_resp.tlvs, | |
2162 | data->p2p_sd_resp.tlvs_len); | |
2163 | break; | |
9bae1be0 | 2164 | #endif /* CONFIG_P2P */ |
245519e0 JM |
2165 | #ifdef CONFIG_CLIENT_MLME |
2166 | case EVENT_MLME_RX: { | |
2167 | struct ieee80211_rx_status rx_status; | |
2168 | os_memset(&rx_status, 0, sizeof(rx_status)); | |
2169 | rx_status.freq = data->mlme_rx.freq; | |
2170 | rx_status.channel = data->mlme_rx.channel; | |
2171 | rx_status.ssi = data->mlme_rx.ssi; | |
2172 | ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len, | |
2173 | &rx_status); | |
2174 | break; | |
2175 | } | |
2176 | #endif /* CONFIG_CLIENT_MLME */ | |
a8e0505b JM |
2177 | case EVENT_EAPOL_RX: |
2178 | wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src, | |
2179 | data->eapol_rx.data, | |
2180 | data->eapol_rx.data_len); | |
2181 | break; | |
e2f74005 JM |
2182 | case EVENT_SIGNAL_CHANGE: |
2183 | bgscan_notify_signal_change( | |
60a972a6 | 2184 | wpa_s, data->signal_change.above_threshold, |
174fa789 PS |
2185 | data->signal_change.current_signal, |
2186 | data->signal_change.current_noise, | |
2187 | data->signal_change.current_txrate); | |
e2f74005 | 2188 | break; |
8401a6b0 | 2189 | case EVENT_INTERFACE_ENABLED: |
f049052b | 2190 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled"); |
8401a6b0 | 2191 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
199716ad | 2192 | #ifdef CONFIG_AP |
9919f7a2 JB |
2193 | if (!wpa_s->ap_iface) { |
2194 | wpa_supplicant_set_state(wpa_s, | |
2195 | WPA_DISCONNECTED); | |
2196 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
2197 | } else | |
2198 | wpa_supplicant_set_state(wpa_s, | |
2199 | WPA_COMPLETED); | |
199716ad BG |
2200 | #else /* CONFIG_AP */ |
2201 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
2202 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
2203 | #endif /* CONFIG_AP */ | |
8401a6b0 JM |
2204 | } |
2205 | break; | |
2206 | case EVENT_INTERFACE_DISABLED: | |
f049052b | 2207 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled"); |
8401a6b0 JM |
2208 | wpa_supplicant_mark_disassoc(wpa_s); |
2209 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); | |
2210 | break; | |
b5c9da8d | 2211 | case EVENT_CHANNEL_LIST_CHANGED: |
35c5d610 JM |
2212 | if (wpa_s->drv_priv == NULL) |
2213 | break; /* Ignore event during drv initialization */ | |
b5c9da8d JM |
2214 | #ifdef CONFIG_P2P |
2215 | wpas_p2p_update_channel_list(wpa_s); | |
c973f386 JM |
2216 | #endif /* CONFIG_P2P */ |
2217 | break; | |
2218 | case EVENT_INTERFACE_UNAVAILABLE: | |
2219 | #ifdef CONFIG_P2P | |
2220 | wpas_p2p_interface_unavailable(wpa_s); | |
7cfc4ac3 AGS |
2221 | #endif /* CONFIG_P2P */ |
2222 | break; | |
2223 | case EVENT_BEST_CHANNEL: | |
f049052b BG |
2224 | wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received " |
2225 | "(%d %d %d)", | |
2226 | data->best_chan.freq_24, data->best_chan.freq_5, | |
2227 | data->best_chan.freq_overall); | |
7cfc4ac3 AGS |
2228 | wpa_s->best_24_freq = data->best_chan.freq_24; |
2229 | wpa_s->best_5_freq = data->best_chan.freq_5; | |
2230 | wpa_s->best_overall_freq = data->best_chan.freq_overall; | |
2231 | #ifdef CONFIG_P2P | |
2232 | wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24, | |
2233 | data->best_chan.freq_5, | |
2234 | data->best_chan.freq_overall); | |
b5c9da8d JM |
2235 | #endif /* CONFIG_P2P */ |
2236 | break; | |
7d878ca7 JM |
2237 | case EVENT_UNPROT_DEAUTH: |
2238 | wpa_supplicant_event_unprot_deauth(wpa_s, | |
2239 | &data->unprot_deauth); | |
2240 | break; | |
2241 | case EVENT_UNPROT_DISASSOC: | |
2242 | wpa_supplicant_event_unprot_disassoc(wpa_s, | |
2243 | &data->unprot_disassoc); | |
2244 | break; | |
0d7e5a3a JB |
2245 | case EVENT_STATION_LOW_ACK: |
2246 | #ifdef CONFIG_AP | |
2247 | if (wpa_s->ap_iface && data) | |
2248 | hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0], | |
2249 | data->low_ack.addr); | |
2250 | #endif /* CONFIG_AP */ | |
2251 | break; | |
ea244d21 XC |
2252 | case EVENT_IBSS_PEER_LOST: |
2253 | #ifdef CONFIG_IBSS_RSN | |
2254 | ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer); | |
2255 | #endif /* CONFIG_IBSS_RSN */ | |
2256 | break; | |
b14a210c JB |
2257 | case EVENT_DRIVER_GTK_REKEY: |
2258 | if (os_memcmp(data->driver_gtk_rekey.bssid, | |
2259 | wpa_s->bssid, ETH_ALEN)) | |
2260 | break; | |
2261 | if (!wpa_s->wpa) | |
2262 | break; | |
2263 | wpa_sm_update_replay_ctr(wpa_s->wpa, | |
2264 | data->driver_gtk_rekey.replay_ctr); | |
2265 | break; | |
cbdf3507 LC |
2266 | case EVENT_SCHED_SCAN_STOPPED: |
2267 | wpa_s->sched_scanning = 0; | |
2268 | wpa_supplicant_notify_scanning(wpa_s, 0); | |
2269 | ||
2270 | /* | |
2271 | * If we timed out, start a new sched scan to continue | |
2272 | * searching for more SSIDs. | |
2273 | */ | |
2274 | if (wpa_s->sched_scan_timed_out) | |
2275 | wpa_supplicant_req_sched_scan(wpa_s); | |
2276 | break; | |
6fc6879b | 2277 | default: |
f049052b | 2278 | wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event); |
6fc6879b JM |
2279 | break; |
2280 | } | |
2281 | } |