]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant - Driver event processing | |
6ae93185 | 3 | * Copyright (c) 2003-2009, 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" |
8bac466b | 30 | #include "notify.h" |
90973fb2 | 31 | #include "common/ieee802_11_defs.h" |
6fc6879b JM |
32 | #include "blacklist.h" |
33 | #include "wpas_glue.h" | |
351f09a2 | 34 | #include "wps_supplicant.h" |
11ef8d35 | 35 | #include "ibss_rsn.h" |
c2a04078 | 36 | #include "sme.h" |
60b94c98 | 37 | #include "bgscan.h" |
f8b1f695 | 38 | #include "ap.h" |
6fc6879b JM |
39 | |
40 | ||
41 | static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s) | |
42 | { | |
8bac466b | 43 | struct wpa_ssid *ssid, *old_ssid; |
6fc6879b JM |
44 | |
45 | if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) | |
46 | return 0; | |
47 | ||
48 | wpa_printf(MSG_DEBUG, "Select network based on association " | |
49 | "information"); | |
50 | ssid = wpa_supplicant_get_ssid(wpa_s); | |
51 | if (ssid == NULL) { | |
52 | wpa_printf(MSG_INFO, "No network configuration found for the " | |
53 | "current AP"); | |
54 | return -1; | |
55 | } | |
56 | ||
57 | if (ssid->disabled) { | |
58 | wpa_printf(MSG_DEBUG, "Selected network is disabled"); | |
59 | return -1; | |
60 | } | |
61 | ||
62 | wpa_printf(MSG_DEBUG, "Network configuration found for the current " | |
63 | "AP"); | |
64 | if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X | | |
65 | WPA_KEY_MGMT_WPA_NONE | | |
56586197 JM |
66 | WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X | |
67 | WPA_KEY_MGMT_PSK_SHA256 | | |
68 | WPA_KEY_MGMT_IEEE8021X_SHA256)) { | |
6fc6879b JM |
69 | u8 wpa_ie[80]; |
70 | size_t wpa_ie_len = sizeof(wpa_ie); | |
71 | wpa_supplicant_set_suites(wpa_s, NULL, ssid, | |
72 | wpa_ie, &wpa_ie_len); | |
73 | } else { | |
74 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
75 | } | |
76 | ||
77 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) | |
78 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
8bac466b | 79 | old_ssid = wpa_s->current_ssid; |
6fc6879b JM |
80 | wpa_s->current_ssid = ssid; |
81 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); | |
82 | wpa_supplicant_initiate_eapol(wpa_s); | |
8bac466b JM |
83 | if (old_ssid != wpa_s->current_ssid) |
84 | wpas_notify_network_changed(wpa_s); | |
6fc6879b JM |
85 | |
86 | return 0; | |
87 | } | |
88 | ||
89 | ||
90 | static void wpa_supplicant_stop_countermeasures(void *eloop_ctx, | |
91 | void *sock_ctx) | |
92 | { | |
93 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
94 | ||
95 | if (wpa_s->countermeasures) { | |
96 | wpa_s->countermeasures = 0; | |
97 | wpa_drv_set_countermeasures(wpa_s, 0); | |
98 | wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped"); | |
99 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
100 | } | |
101 | } | |
102 | ||
103 | ||
104 | void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) | |
105 | { | |
8bac466b JM |
106 | int bssid_changed; |
107 | ||
6fc6879b | 108 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
8bac466b | 109 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
6fc6879b JM |
110 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
111 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
8bac466b JM |
112 | if (bssid_changed) |
113 | wpas_notify_bssid_changed(wpa_s); | |
114 | ||
6fc6879b JM |
115 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); |
116 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
56586197 | 117 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) |
6fc6879b JM |
118 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
119 | wpa_s->ap_ies_from_associnfo = 0; | |
120 | } | |
121 | ||
122 | ||
123 | static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s) | |
124 | { | |
125 | struct wpa_ie_data ie; | |
126 | int pmksa_set = -1; | |
127 | size_t i; | |
128 | ||
129 | if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 || | |
130 | ie.pmkid == NULL) | |
131 | return; | |
132 | ||
133 | for (i = 0; i < ie.num_pmkid; i++) { | |
134 | pmksa_set = pmksa_cache_set_current(wpa_s->wpa, | |
135 | ie.pmkid + i * PMKID_LEN, | |
136 | NULL, NULL, 0); | |
137 | if (pmksa_set == 0) { | |
138 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1); | |
139 | break; | |
140 | } | |
141 | } | |
142 | ||
143 | wpa_printf(MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from PMKSA " | |
144 | "cache", pmksa_set == 0 ? "" : "not "); | |
145 | } | |
146 | ||
147 | ||
148 | static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s, | |
149 | union wpa_event_data *data) | |
150 | { | |
151 | if (data == NULL) { | |
152 | wpa_printf(MSG_DEBUG, "RSN: No data in PMKID candidate event"); | |
153 | return; | |
154 | } | |
155 | wpa_printf(MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR | |
156 | " index=%d preauth=%d", | |
157 | MAC2STR(data->pmkid_candidate.bssid), | |
158 | data->pmkid_candidate.index, | |
159 | data->pmkid_candidate.preauth); | |
160 | ||
161 | pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid, | |
162 | data->pmkid_candidate.index, | |
163 | data->pmkid_candidate.preauth); | |
164 | } | |
165 | ||
166 | ||
167 | static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s) | |
168 | { | |
169 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
170 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) | |
171 | return 0; | |
172 | ||
173 | #ifdef IEEE8021X_EAPOL | |
174 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA && | |
175 | wpa_s->current_ssid && | |
176 | !(wpa_s->current_ssid->eapol_flags & | |
177 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
178 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) { | |
179 | /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either | |
180 | * plaintext or static WEP keys). */ | |
181 | return 0; | |
182 | } | |
183 | #endif /* IEEE8021X_EAPOL */ | |
184 | ||
185 | return 1; | |
186 | } | |
187 | ||
188 | ||
189 | /** | |
190 | * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC | |
191 | * @wpa_s: pointer to wpa_supplicant data | |
192 | * @ssid: Configuration data for the network | |
193 | * Returns: 0 on success, -1 on failure | |
194 | * | |
195 | * This function is called when starting authentication with a network that is | |
196 | * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA). | |
197 | */ | |
198 | int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s, | |
199 | struct wpa_ssid *ssid) | |
200 | { | |
201 | #ifdef IEEE8021X_EAPOL | |
202 | int aka = 0, sim = 0, type; | |
203 | ||
204 | if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL) | |
205 | return 0; | |
206 | ||
207 | if (ssid->eap.eap_methods == NULL) { | |
208 | sim = 1; | |
209 | aka = 1; | |
210 | } else { | |
211 | struct eap_method_type *eap = ssid->eap.eap_methods; | |
212 | while (eap->vendor != EAP_VENDOR_IETF || | |
213 | eap->method != EAP_TYPE_NONE) { | |
214 | if (eap->vendor == EAP_VENDOR_IETF) { | |
215 | if (eap->method == EAP_TYPE_SIM) | |
216 | sim = 1; | |
217 | else if (eap->method == EAP_TYPE_AKA) | |
218 | aka = 1; | |
219 | } | |
220 | eap++; | |
221 | } | |
222 | } | |
223 | ||
224 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL) | |
225 | sim = 0; | |
226 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL) | |
227 | aka = 0; | |
228 | ||
229 | if (!sim && !aka) { | |
230 | wpa_printf(MSG_DEBUG, "Selected network is configured to use " | |
231 | "SIM, but neither EAP-SIM nor EAP-AKA are enabled"); | |
232 | return 0; | |
233 | } | |
234 | ||
235 | wpa_printf(MSG_DEBUG, "Selected network is configured to use SIM " | |
236 | "(sim=%d aka=%d) - initialize PCSC", sim, aka); | |
237 | if (sim && aka) | |
238 | type = SCARD_TRY_BOTH; | |
239 | else if (aka) | |
240 | type = SCARD_USIM_ONLY; | |
241 | else | |
242 | type = SCARD_GSM_SIM_ONLY; | |
243 | ||
244 | wpa_s->scard = scard_init(type); | |
245 | if (wpa_s->scard == NULL) { | |
246 | wpa_printf(MSG_WARNING, "Failed to initialize SIM " | |
247 | "(pcsc-lite)"); | |
248 | return -1; | |
249 | } | |
250 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); | |
251 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); | |
252 | #endif /* IEEE8021X_EAPOL */ | |
253 | ||
254 | return 0; | |
255 | } | |
256 | ||
257 | ||
258 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
259 | static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss, | |
260 | struct wpa_ssid *ssid) | |
261 | { | |
262 | int i, privacy = 0; | |
263 | ||
264 | if (ssid->mixed_cell) | |
265 | return 1; | |
266 | ||
0632542b AT |
267 | #ifdef CONFIG_WPS |
268 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) | |
269 | return 1; | |
270 | #endif /* CONFIG_WPS */ | |
271 | ||
6fc6879b JM |
272 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
273 | if (ssid->wep_key_len[i]) { | |
274 | privacy = 1; | |
275 | break; | |
276 | } | |
277 | } | |
278 | #ifdef IEEE8021X_EAPOL | |
279 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
280 | ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
281 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) | |
282 | privacy = 1; | |
283 | #endif /* IEEE8021X_EAPOL */ | |
284 | ||
285 | if (bss->caps & IEEE80211_CAP_PRIVACY) | |
286 | return privacy; | |
287 | return !privacy; | |
288 | } | |
289 | ||
290 | ||
a6099152 JM |
291 | static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, |
292 | struct wpa_ssid *ssid, | |
6fc6879b JM |
293 | struct wpa_scan_res *bss) |
294 | { | |
295 | struct wpa_ie_data ie; | |
296 | int proto_match = 0; | |
297 | const u8 *rsn_ie, *wpa_ie; | |
351f09a2 | 298 | int ret; |
6fc6879b | 299 | |
a6099152 | 300 | ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); |
351f09a2 JM |
301 | if (ret >= 0) |
302 | return ret; | |
ad08c363 | 303 | |
6fc6879b JM |
304 | rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN); |
305 | while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) { | |
306 | proto_match++; | |
307 | ||
308 | if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { | |
309 | wpa_printf(MSG_DEBUG, " skip RSN IE - parse failed"); | |
310 | break; | |
311 | } | |
312 | if (!(ie.proto & ssid->proto)) { | |
313 | wpa_printf(MSG_DEBUG, " skip RSN IE - proto " | |
314 | "mismatch"); | |
315 | break; | |
316 | } | |
317 | ||
318 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
319 | wpa_printf(MSG_DEBUG, " skip RSN IE - PTK cipher " | |
320 | "mismatch"); | |
321 | break; | |
322 | } | |
323 | ||
324 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
325 | wpa_printf(MSG_DEBUG, " skip RSN IE - GTK cipher " | |
326 | "mismatch"); | |
327 | break; | |
328 | } | |
329 | ||
330 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
331 | wpa_printf(MSG_DEBUG, " skip RSN IE - key mgmt " | |
332 | "mismatch"); | |
333 | break; | |
334 | } | |
335 | ||
336 | #ifdef CONFIG_IEEE80211W | |
0b60b0aa JM |
337 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
338 | ssid->ieee80211w == IEEE80211W_REQUIRED) { | |
6fc6879b JM |
339 | wpa_printf(MSG_DEBUG, " skip RSN IE - no mgmt frame " |
340 | "protection"); | |
341 | break; | |
342 | } | |
343 | #endif /* CONFIG_IEEE80211W */ | |
344 | ||
345 | wpa_printf(MSG_DEBUG, " selected based on RSN IE"); | |
346 | return 1; | |
347 | } | |
348 | ||
349 | wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | |
350 | while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { | |
351 | proto_match++; | |
352 | ||
353 | if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { | |
354 | wpa_printf(MSG_DEBUG, " skip WPA IE - parse failed"); | |
355 | break; | |
356 | } | |
357 | if (!(ie.proto & ssid->proto)) { | |
358 | wpa_printf(MSG_DEBUG, " skip WPA IE - proto " | |
359 | "mismatch"); | |
360 | break; | |
361 | } | |
362 | ||
363 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
364 | wpa_printf(MSG_DEBUG, " skip WPA IE - PTK cipher " | |
365 | "mismatch"); | |
366 | break; | |
367 | } | |
368 | ||
369 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
370 | wpa_printf(MSG_DEBUG, " skip WPA IE - GTK cipher " | |
371 | "mismatch"); | |
372 | break; | |
373 | } | |
374 | ||
375 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
376 | wpa_printf(MSG_DEBUG, " skip WPA IE - key mgmt " | |
377 | "mismatch"); | |
378 | break; | |
379 | } | |
380 | ||
381 | wpa_printf(MSG_DEBUG, " selected based on WPA IE"); | |
382 | return 1; | |
383 | } | |
384 | ||
385 | if (proto_match == 0) | |
386 | wpa_printf(MSG_DEBUG, " skip - no WPA/RSN proto match"); | |
387 | ||
388 | return 0; | |
389 | } | |
390 | ||
391 | ||
392 | static struct wpa_scan_res * | |
9cf32261 JM |
393 | wpa_supplicant_select_bss_wpa(struct wpa_supplicant *wpa_s, |
394 | struct wpa_ssid *group, | |
395 | struct wpa_ssid **selected_ssid) | |
6fc6879b JM |
396 | { |
397 | struct wpa_ssid *ssid; | |
9cf32261 | 398 | struct wpa_scan_res *bss; |
6fc6879b JM |
399 | size_t i; |
400 | struct wpa_blacklist *e; | |
401 | const u8 *ie; | |
402 | ||
6fc6879b | 403 | wpa_printf(MSG_DEBUG, "Try to find WPA-enabled AP"); |
9cf32261 | 404 | for (i = 0; i < wpa_s->scan_res->num; i++) { |
6fc6879b JM |
405 | const u8 *ssid_; |
406 | u8 wpa_ie_len, rsn_ie_len, ssid_len; | |
407 | bss = wpa_s->scan_res->res[i]; | |
408 | ||
409 | ie = wpa_scan_get_ie(bss, WLAN_EID_SSID); | |
410 | ssid_ = ie ? ie + 2 : (u8 *) ""; | |
411 | ssid_len = ie ? ie[1] : 0; | |
412 | ||
413 | ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | |
414 | wpa_ie_len = ie ? ie[1] : 0; | |
415 | ||
416 | ie = wpa_scan_get_ie(bss, WLAN_EID_RSN); | |
417 | rsn_ie_len = ie ? ie[1] : 0; | |
418 | ||
419 | wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' " | |
420 | "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x", | |
421 | (int) i, MAC2STR(bss->bssid), | |
422 | wpa_ssid_txt(ssid_, ssid_len), | |
423 | wpa_ie_len, rsn_ie_len, bss->caps); | |
9cf32261 | 424 | |
6fc6879b JM |
425 | e = wpa_blacklist_get(wpa_s, bss->bssid); |
426 | if (e && e->count > 1) { | |
427 | wpa_printf(MSG_DEBUG, " skip - blacklisted"); | |
428 | continue; | |
429 | } | |
430 | ||
e81634cd JM |
431 | if (ssid_len == 0) { |
432 | wpa_printf(MSG_DEBUG, " skip - SSID not known"); | |
433 | continue; | |
434 | } | |
435 | ||
6fc6879b JM |
436 | if (wpa_ie_len == 0 && rsn_ie_len == 0) { |
437 | wpa_printf(MSG_DEBUG, " skip - no WPA/RSN IE"); | |
438 | continue; | |
439 | } | |
440 | ||
441 | for (ssid = group; ssid; ssid = ssid->pnext) { | |
ad08c363 JM |
442 | int check_ssid = 1; |
443 | ||
6fc6879b JM |
444 | if (ssid->disabled) { |
445 | wpa_printf(MSG_DEBUG, " skip - disabled"); | |
446 | continue; | |
447 | } | |
9cf32261 | 448 | |
ad08c363 JM |
449 | #ifdef CONFIG_WPS |
450 | if (ssid->ssid_len == 0 && | |
a6099152 | 451 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) |
ad08c363 JM |
452 | check_ssid = 0; |
453 | #endif /* CONFIG_WPS */ | |
454 | ||
455 | if (check_ssid && | |
456 | (ssid_len != ssid->ssid_len || | |
457 | os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) { | |
6fc6879b JM |
458 | wpa_printf(MSG_DEBUG, " skip - " |
459 | "SSID mismatch"); | |
460 | continue; | |
461 | } | |
9cf32261 | 462 | |
6fc6879b JM |
463 | if (ssid->bssid_set && |
464 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) | |
465 | { | |
466 | wpa_printf(MSG_DEBUG, " skip - " | |
467 | "BSSID mismatch"); | |
468 | continue; | |
469 | } | |
9cf32261 | 470 | |
a6099152 | 471 | if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss)) |
9cf32261 JM |
472 | continue; |
473 | ||
474 | wpa_printf(MSG_DEBUG, " selected WPA AP " | |
475 | MACSTR " ssid='%s'", | |
476 | MAC2STR(bss->bssid), | |
477 | wpa_ssid_txt(ssid_, ssid_len)); | |
478 | *selected_ssid = ssid; | |
479 | return bss; | |
6fc6879b JM |
480 | } |
481 | } | |
482 | ||
9cf32261 JM |
483 | return NULL; |
484 | } | |
485 | ||
486 | ||
487 | static struct wpa_scan_res * | |
488 | wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant *wpa_s, | |
489 | struct wpa_ssid *group, | |
490 | struct wpa_ssid **selected_ssid) | |
491 | { | |
492 | struct wpa_ssid *ssid; | |
493 | struct wpa_scan_res *bss; | |
494 | size_t i; | |
495 | struct wpa_blacklist *e; | |
496 | const u8 *ie; | |
497 | ||
6fc6879b | 498 | wpa_printf(MSG_DEBUG, "Try to find non-WPA AP"); |
9cf32261 | 499 | for (i = 0; i < wpa_s->scan_res->num; i++) { |
6fc6879b JM |
500 | const u8 *ssid_; |
501 | u8 wpa_ie_len, rsn_ie_len, ssid_len; | |
502 | bss = wpa_s->scan_res->res[i]; | |
503 | ||
504 | ie = wpa_scan_get_ie(bss, WLAN_EID_SSID); | |
505 | ssid_ = ie ? ie + 2 : (u8 *) ""; | |
506 | ssid_len = ie ? ie[1] : 0; | |
507 | ||
508 | ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | |
509 | wpa_ie_len = ie ? ie[1] : 0; | |
510 | ||
511 | ie = wpa_scan_get_ie(bss, WLAN_EID_RSN); | |
512 | rsn_ie_len = ie ? ie[1] : 0; | |
513 | ||
514 | wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' " | |
515 | "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x", | |
516 | (int) i, MAC2STR(bss->bssid), | |
517 | wpa_ssid_txt(ssid_, ssid_len), | |
518 | wpa_ie_len, rsn_ie_len, bss->caps); | |
9cf32261 | 519 | |
6fc6879b JM |
520 | e = wpa_blacklist_get(wpa_s, bss->bssid); |
521 | if (e && e->count > 1) { | |
522 | wpa_printf(MSG_DEBUG, " skip - blacklisted"); | |
523 | continue; | |
524 | } | |
9cf32261 | 525 | |
e81634cd JM |
526 | if (ssid_len == 0) { |
527 | wpa_printf(MSG_DEBUG, " skip - SSID not known"); | |
528 | continue; | |
529 | } | |
530 | ||
6fc6879b | 531 | for (ssid = group; ssid; ssid = ssid->pnext) { |
ad08c363 JM |
532 | int check_ssid = ssid->ssid_len != 0; |
533 | ||
6fc6879b JM |
534 | if (ssid->disabled) { |
535 | wpa_printf(MSG_DEBUG, " skip - disabled"); | |
536 | continue; | |
537 | } | |
9cf32261 | 538 | |
ad08c363 JM |
539 | #ifdef CONFIG_WPS |
540 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) { | |
541 | /* Only allow wildcard SSID match if an AP | |
542 | * advertises active WPS operation that matches | |
543 | * with our mode. */ | |
544 | check_ssid = 1; | |
545 | if (ssid->ssid_len == 0 && | |
a6099152 JM |
546 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, |
547 | bss)) | |
ad08c363 JM |
548 | check_ssid = 0; |
549 | } | |
550 | #endif /* CONFIG_WPS */ | |
551 | ||
552 | if (check_ssid && | |
6fc6879b JM |
553 | (ssid_len != ssid->ssid_len || |
554 | os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) { | |
555 | wpa_printf(MSG_DEBUG, " skip - " | |
556 | "SSID mismatch"); | |
557 | continue; | |
558 | } | |
559 | ||
560 | if (ssid->bssid_set && | |
561 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) | |
562 | { | |
563 | wpa_printf(MSG_DEBUG, " skip - " | |
564 | "BSSID mismatch"); | |
565 | continue; | |
566 | } | |
1bd3f426 | 567 | |
6fc6879b | 568 | if (!(ssid->key_mgmt & WPA_KEY_MGMT_NONE) && |
ad08c363 | 569 | !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) && |
6fc6879b JM |
570 | !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) |
571 | { | |
572 | wpa_printf(MSG_DEBUG, " skip - " | |
573 | "non-WPA network not allowed"); | |
574 | continue; | |
575 | } | |
576 | ||
1bd3f426 | 577 | if ((ssid->key_mgmt & |
56586197 JM |
578 | (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK | |
579 | WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK | | |
580 | WPA_KEY_MGMT_IEEE8021X_SHA256 | | |
581 | WPA_KEY_MGMT_PSK_SHA256)) && | |
6fc6879b JM |
582 | (wpa_ie_len != 0 || rsn_ie_len != 0)) { |
583 | wpa_printf(MSG_DEBUG, " skip - " | |
584 | "WPA network"); | |
585 | continue; | |
586 | } | |
587 | ||
588 | if (!wpa_supplicant_match_privacy(bss, ssid)) { | |
589 | wpa_printf(MSG_DEBUG, " skip - " | |
590 | "privacy mismatch"); | |
591 | continue; | |
592 | } | |
593 | ||
594 | if (bss->caps & IEEE80211_CAP_IBSS) { | |
595 | wpa_printf(MSG_DEBUG, " skip - " | |
596 | "IBSS (adhoc) network"); | |
597 | continue; | |
598 | } | |
599 | ||
6fc6879b JM |
600 | wpa_printf(MSG_DEBUG, " selected non-WPA AP " |
601 | MACSTR " ssid='%s'", | |
602 | MAC2STR(bss->bssid), | |
603 | wpa_ssid_txt(ssid_, ssid_len)); | |
9cf32261 JM |
604 | *selected_ssid = ssid; |
605 | return bss; | |
6fc6879b JM |
606 | } |
607 | } | |
608 | ||
9cf32261 JM |
609 | return NULL; |
610 | } | |
611 | ||
612 | ||
613 | static struct wpa_scan_res * | |
614 | wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, struct wpa_ssid *group, | |
615 | struct wpa_ssid **selected_ssid) | |
616 | { | |
617 | struct wpa_scan_res *selected; | |
618 | ||
619 | wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d", | |
620 | group->priority); | |
621 | ||
622 | /* First, try to find WPA-enabled AP */ | |
623 | selected = wpa_supplicant_select_bss_wpa(wpa_s, group, selected_ssid); | |
624 | if (selected) | |
625 | return selected; | |
626 | ||
627 | /* If no WPA-enabled AP found, try to find non-WPA AP, if configuration | |
628 | * allows this. */ | |
629 | return wpa_supplicant_select_bss_non_wpa(wpa_s, group, selected_ssid); | |
6fc6879b JM |
630 | } |
631 | ||
632 | ||
09b9df4e JM |
633 | static struct wpa_scan_res * |
634 | wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s, | |
635 | struct wpa_ssid **selected_ssid) | |
6fc6879b | 636 | { |
6fc6879b | 637 | struct wpa_scan_res *selected = NULL; |
09b9df4e JM |
638 | int prio; |
639 | ||
640 | while (selected == NULL) { | |
641 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
642 | selected = wpa_supplicant_select_bss( | |
643 | wpa_s, wpa_s->conf->pssid[prio], | |
644 | selected_ssid); | |
645 | if (selected) | |
646 | break; | |
647 | } | |
648 | ||
649 | if (selected == NULL && wpa_s->blacklist) { | |
650 | wpa_printf(MSG_DEBUG, "No APs found - clear blacklist " | |
651 | "and try again"); | |
652 | wpa_blacklist_clear(wpa_s); | |
653 | wpa_s->blacklist_cleared++; | |
654 | } else if (selected == NULL) | |
655 | break; | |
656 | } | |
657 | ||
658 | return selected; | |
659 | } | |
660 | ||
661 | ||
662 | static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s, | |
663 | int timeout) | |
664 | { | |
665 | if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1) { | |
666 | /* | |
667 | * Quick recovery if the initial scan results were not | |
668 | * complete when fetched before the first scan request. | |
669 | */ | |
670 | wpa_s->scan_res_tried++; | |
671 | timeout = 0; | |
4f34d51a SL |
672 | } else if (!wpa_supplicant_enabled_networks(wpa_s->conf)) { |
673 | /* | |
674 | * No networks are enabled; short-circuit request so | |
675 | * we don't wait timeout seconds before transitioning | |
676 | * to INACTIVE state. | |
677 | */ | |
678 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); | |
679 | return; | |
09b9df4e JM |
680 | } |
681 | wpa_supplicant_req_scan(wpa_s, timeout, 0); | |
682 | } | |
683 | ||
684 | ||
685 | static void wpa_supplicant_connect(struct wpa_supplicant *wpa_s, | |
686 | struct wpa_scan_res *selected, | |
687 | struct wpa_ssid *ssid) | |
688 | { | |
689 | if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) { | |
690 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP | |
691 | "PBC session overlap"); | |
692 | wpa_supplicant_req_new_scan(wpa_s, 10); | |
693 | return; | |
694 | } | |
695 | ||
696 | /* | |
697 | * Do not trigger new association unless the BSSID has changed or if | |
698 | * reassociation is requested. If we are in process of associating with | |
699 | * the selected BSSID, do not trigger new attempt. | |
700 | */ | |
701 | if (wpa_s->reassociate || | |
702 | (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 && | |
703 | (wpa_s->wpa_state != WPA_ASSOCIATING || | |
704 | os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) != | |
705 | 0))) { | |
706 | if (wpa_supplicant_scard_init(wpa_s, ssid)) { | |
707 | wpa_supplicant_req_new_scan(wpa_s, 10); | |
708 | return; | |
709 | } | |
710 | wpa_supplicant_associate(wpa_s, selected, ssid); | |
711 | } else { | |
712 | wpa_printf(MSG_DEBUG, "Already associated with the selected " | |
713 | "AP"); | |
714 | } | |
09b9df4e JM |
715 | } |
716 | ||
717 | ||
b55aaa5f JM |
718 | static struct wpa_ssid * |
719 | wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s) | |
720 | { | |
721 | int prio; | |
722 | struct wpa_ssid *ssid; | |
723 | ||
724 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
725 | for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) | |
726 | { | |
727 | if (ssid->disabled) | |
728 | continue; | |
729 | if (ssid->mode == IEEE80211_MODE_IBSS || | |
730 | ssid->mode == IEEE80211_MODE_AP) | |
731 | return ssid; | |
732 | } | |
733 | } | |
734 | return NULL; | |
735 | } | |
736 | ||
737 | ||
6ae93185 JM |
738 | static void wpa_supplicant_rsn_preauth_scan_results( |
739 | struct wpa_supplicant *wpa_s) | |
740 | { | |
741 | int i; | |
742 | ||
743 | if (rsn_preauth_scan_results(wpa_s->wpa) < 0) | |
744 | return; | |
745 | ||
746 | for (i = wpa_s->scan_res->num - 1; i >= 0; i--) { | |
747 | const u8 *ssid, *rsn; | |
748 | struct wpa_scan_res *r; | |
749 | ||
750 | r = wpa_s->scan_res->res[i]; | |
751 | ||
752 | ssid = wpa_scan_get_ie(r, WLAN_EID_SSID); | |
753 | if (ssid == NULL) | |
754 | continue; | |
755 | ||
756 | rsn = wpa_scan_get_ie(r, WLAN_EID_RSN); | |
757 | if (rsn == NULL) | |
758 | continue; | |
759 | ||
760 | rsn_preauth_scan_result(wpa_s->wpa, r->bssid, ssid, rsn); | |
761 | } | |
762 | ||
763 | } | |
764 | ||
765 | ||
09b9df4e JM |
766 | static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s) |
767 | { | |
768 | struct wpa_scan_res *selected; | |
6fc6879b JM |
769 | struct wpa_ssid *ssid = NULL; |
770 | ||
cb8564b1 DW |
771 | wpa_supplicant_notify_scanning(wpa_s, 0); |
772 | ||
6fc6879b JM |
773 | if (wpa_supplicant_get_scan_results(wpa_s) < 0) { |
774 | if (wpa_s->conf->ap_scan == 2) | |
775 | return; | |
776 | wpa_printf(MSG_DEBUG, "Failed to get scan results - try " | |
777 | "scanning again"); | |
09b9df4e JM |
778 | wpa_supplicant_req_new_scan(wpa_s, 1); |
779 | return; | |
6fc6879b JM |
780 | } |
781 | ||
23e07237 DN |
782 | /* |
783 | * Don't post the results if this was the initial cached | |
784 | * and there were no results. | |
785 | */ | |
786 | if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1 && | |
787 | wpa_s->scan_res->num == 0) { | |
788 | wpa_msg(wpa_s, MSG_DEBUG, "Cached scan results are " | |
789 | "empty - not posting"); | |
790 | } else { | |
69856fad JM |
791 | wpa_printf(MSG_DEBUG, "New scan results available"); |
792 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); | |
8bac466b | 793 | wpas_notify_scan_results(wpa_s); |
23e07237 | 794 | } |
6fc6879b | 795 | |
8bac466b JM |
796 | wpas_notify_scan_done(wpa_s, 1); |
797 | ||
3180d7a2 | 798 | if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) |
6fc6879b JM |
799 | return; |
800 | ||
3180d7a2 SO |
801 | if (wpa_s->disconnected) { |
802 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
803 | return; | |
804 | } | |
805 | ||
60b94c98 JM |
806 | if (bgscan_notify_scan(wpa_s) == 1) |
807 | return; | |
808 | ||
6ae93185 JM |
809 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
810 | ||
09b9df4e | 811 | selected = wpa_supplicant_pick_network(wpa_s, &ssid); |
6fc6879b | 812 | if (selected) { |
09b9df4e | 813 | wpa_supplicant_connect(wpa_s, selected, ssid); |
6fc6879b | 814 | } else { |
09b9df4e | 815 | wpa_printf(MSG_DEBUG, "No suitable network found"); |
b55aaa5f JM |
816 | ssid = wpa_supplicant_pick_new_network(wpa_s); |
817 | if (ssid) { | |
818 | wpa_printf(MSG_DEBUG, "Setup a new network"); | |
819 | wpa_supplicant_associate(wpa_s, NULL, ssid); | |
820 | } else | |
821 | wpa_supplicant_req_new_scan(wpa_s, 5); | |
6fc6879b | 822 | } |
6fc6879b JM |
823 | } |
824 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | |
825 | ||
826 | ||
c2a04078 JM |
827 | #ifdef CONFIG_IEEE80211R |
828 | static void wpa_assoc_set_ft_params(struct wpa_supplicant *wpa_s, | |
829 | const u8 *ftie, const u8 *mdie) | |
830 | { | |
831 | const u8 *mobility_domain = NULL; | |
832 | const u8 *r0kh_id = NULL; | |
833 | size_t r0kh_id_len = 0; | |
834 | const u8 *r1kh_id = NULL; | |
835 | struct rsn_ftie *hdr; | |
836 | const u8 *pos, *end; | |
837 | ||
838 | if (mdie == NULL || ftie == NULL) | |
839 | return; | |
840 | ||
841 | if (mdie[1] >= MOBILITY_DOMAIN_ID_LEN) { | |
842 | mobility_domain = mdie + 2; | |
843 | #ifdef CONFIG_SME | |
844 | wpa_s->sme.ft_used = 1; | |
845 | os_memcpy(wpa_s->sme.mobility_domain, mobility_domain, 2); | |
846 | #endif /* CONFIG_SME */ | |
847 | } | |
848 | if (ftie[1] >= sizeof(struct rsn_ftie)) { | |
849 | end = ftie + 2 + ftie[1]; | |
850 | hdr = (struct rsn_ftie *) (ftie + 2); | |
851 | pos = (const u8 *) (hdr + 1); | |
852 | while (pos + 1 < end) { | |
853 | if (pos + 2 + pos[1] > end) | |
854 | break; | |
855 | if (pos[0] == FTIE_SUBELEM_R1KH_ID && | |
856 | pos[1] == FT_R1KH_ID_LEN) | |
857 | r1kh_id = pos + 2; | |
858 | else if (pos[0] == FTIE_SUBELEM_R0KH_ID && | |
859 | pos[1] >= 1 && pos[1] <= FT_R0KH_ID_MAX_LEN) { | |
860 | r0kh_id = pos + 2; | |
861 | r0kh_id_len = pos[1]; | |
862 | } | |
863 | pos += 2 + pos[1]; | |
864 | } | |
865 | } | |
866 | wpa_sm_set_ft_params(wpa_s->wpa, mobility_domain, r0kh_id, | |
867 | r0kh_id_len, r1kh_id); | |
868 | } | |
869 | #endif /* CONFIG_IEEE80211R */ | |
870 | ||
6fc6879b JM |
871 | static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, |
872 | union wpa_event_data *data) | |
873 | { | |
874 | int l, len, found = 0, wpa_found, rsn_found; | |
c2a04078 JM |
875 | const u8 *p; |
876 | #ifdef CONFIG_IEEE80211R | |
877 | const u8 *mdie = NULL, *ftie = NULL; | |
878 | #endif /* CONFIG_IEEE80211R */ | |
6fc6879b JM |
879 | |
880 | wpa_printf(MSG_DEBUG, "Association info event"); | |
881 | if (data->assoc_info.req_ies) | |
882 | wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, | |
883 | data->assoc_info.req_ies_len); | |
884 | if (data->assoc_info.resp_ies) | |
885 | wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, | |
886 | data->assoc_info.resp_ies_len); | |
887 | if (data->assoc_info.beacon_ies) | |
888 | wpa_hexdump(MSG_DEBUG, "beacon_ies", | |
889 | data->assoc_info.beacon_ies, | |
890 | data->assoc_info.beacon_ies_len); | |
891 | ||
892 | p = data->assoc_info.req_ies; | |
893 | l = data->assoc_info.req_ies_len; | |
894 | ||
895 | /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ | |
896 | while (p && l >= 2) { | |
897 | len = p[1] + 2; | |
898 | if (len > l) { | |
899 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
900 | p, l); | |
901 | break; | |
902 | } | |
903 | if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
904 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || | |
905 | (p[0] == WLAN_EID_RSN && p[1] >= 2)) { | |
906 | if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) | |
907 | break; | |
908 | found = 1; | |
909 | wpa_find_assoc_pmkid(wpa_s); | |
910 | break; | |
911 | } | |
912 | l -= len; | |
913 | p += len; | |
914 | } | |
915 | if (!found && data->assoc_info.req_ies) | |
916 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); | |
917 | ||
c2a04078 JM |
918 | #ifdef CONFIG_IEEE80211R |
919 | p = data->assoc_info.resp_ies; | |
920 | l = data->assoc_info.resp_ies_len; | |
921 | ||
94873e3b | 922 | /* Go through the IEs and make a copy of the FT/MD IE, if present. */ |
c2a04078 JM |
923 | while (p && l >= 2) { |
924 | len = p[1] + 2; | |
925 | if (len > l) { | |
926 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
927 | p, l); | |
928 | break; | |
929 | } | |
930 | if (p[0] == WLAN_EID_FAST_BSS_TRANSITION) | |
931 | ftie = p; | |
932 | else if (p[0] == WLAN_EID_MOBILITY_DOMAIN) | |
933 | mdie = p; | |
934 | l -= len; | |
935 | p += len; | |
936 | } | |
937 | ||
938 | wpa_assoc_set_ft_params(wpa_s, ftie, mdie); | |
939 | #endif /* CONFIG_IEEE80211R */ | |
940 | ||
6fc6879b JM |
941 | /* WPA/RSN IE from Beacon/ProbeResp */ |
942 | p = data->assoc_info.beacon_ies; | |
943 | l = data->assoc_info.beacon_ies_len; | |
944 | ||
945 | /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. | |
946 | */ | |
947 | wpa_found = rsn_found = 0; | |
948 | while (p && l >= 2) { | |
949 | len = p[1] + 2; | |
950 | if (len > l) { | |
951 | wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", | |
952 | p, l); | |
953 | break; | |
954 | } | |
955 | if (!wpa_found && | |
956 | p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
957 | os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { | |
958 | wpa_found = 1; | |
959 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); | |
960 | } | |
961 | ||
962 | if (!rsn_found && | |
963 | p[0] == WLAN_EID_RSN && p[1] >= 2) { | |
964 | rsn_found = 1; | |
965 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); | |
966 | } | |
967 | ||
968 | l -= len; | |
969 | p += len; | |
970 | } | |
971 | ||
972 | if (!wpa_found && data->assoc_info.beacon_ies) | |
973 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); | |
974 | if (!rsn_found && data->assoc_info.beacon_ies) | |
975 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); | |
976 | if (wpa_found || rsn_found) | |
977 | wpa_s->ap_ies_from_associnfo = 1; | |
978 | } | |
979 | ||
980 | ||
981 | static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, | |
982 | union wpa_event_data *data) | |
983 | { | |
984 | u8 bssid[ETH_ALEN]; | |
985 | int ft_completed = wpa_ft_is_completed(wpa_s->wpa); | |
8bac466b | 986 | int bssid_changed; |
0194fedb | 987 | struct wpa_driver_capa capa; |
6fc6879b JM |
988 | |
989 | if (data) | |
990 | wpa_supplicant_event_associnfo(wpa_s, data); | |
991 | ||
992 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); | |
c2a04078 | 993 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) |
6fc6879b | 994 | os_memcpy(bssid, wpa_s->bssid, ETH_ALEN); |
c2a04078 | 995 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) || |
6fc6879b JM |
996 | (wpa_drv_get_bssid(wpa_s, bssid) >= 0 && |
997 | os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) { | |
998 | wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" | |
999 | MACSTR, MAC2STR(bssid)); | |
8bac466b | 1000 | bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN); |
6fc6879b JM |
1001 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
1002 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
8bac466b JM |
1003 | if (bssid_changed) |
1004 | wpas_notify_bssid_changed(wpa_s); | |
1005 | ||
6fc6879b JM |
1006 | if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { |
1007 | wpa_clear_keys(wpa_s, bssid); | |
1008 | } | |
1009 | if (wpa_supplicant_select_config(wpa_s) < 0) { | |
1010 | wpa_supplicant_disassociate( | |
1011 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
1012 | return; | |
1013 | } | |
1014 | } | |
1015 | ||
62fa124c JM |
1016 | #ifdef CONFIG_SME |
1017 | os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN); | |
1018 | wpa_s->sme.prev_bssid_set = 1; | |
1019 | #endif /* CONFIG_SME */ | |
1020 | ||
6fc6879b JM |
1021 | wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); |
1022 | if (wpa_s->current_ssid) { | |
1023 | /* When using scanning (ap_scan=1), SIM PC/SC interface can be | |
1024 | * initialized before association, but for other modes, | |
1025 | * initialize PC/SC here, if the current configuration needs | |
1026 | * smartcard or SIM/USIM. */ | |
1027 | wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); | |
1028 | } | |
1029 | wpa_sm_notify_assoc(wpa_s->wpa, bssid); | |
1030 | l2_packet_notify_auth_start(wpa_s->l2); | |
1031 | ||
1032 | /* | |
1033 | * Set portEnabled first to FALSE in order to get EAP state machine out | |
1034 | * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE | |
1035 | * state machine may transit to AUTHENTICATING state based on obsolete | |
1036 | * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to | |
1037 | * AUTHENTICATED without ever giving chance to EAP state machine to | |
1038 | * reset the state. | |
1039 | */ | |
1040 | if (!ft_completed) { | |
1041 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); | |
1042 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
1043 | } | |
56586197 | 1044 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed) |
6fc6879b JM |
1045 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
1046 | /* 802.1X::portControl = Auto */ | |
1047 | eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE); | |
1048 | wpa_s->eapol_received = 0; | |
1049 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
9c972abb JM |
1050 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || |
1051 | (wpa_s->current_ssid && | |
1052 | wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) { | |
6fc6879b JM |
1053 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
1054 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1055 | } else if (!ft_completed) { | |
1056 | /* Timeout for receiving the first EAPOL packet */ | |
1057 | wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); | |
1058 | } | |
1059 | wpa_supplicant_cancel_scan(wpa_s); | |
1060 | ||
c2a04078 | 1061 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
56586197 | 1062 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
6fc6879b JM |
1063 | /* |
1064 | * We are done; the driver will take care of RSN 4-way | |
1065 | * handshake. | |
1066 | */ | |
1067 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
1068 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1069 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
1070 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
1071 | } | |
1ff73338 JM |
1072 | |
1073 | if (wpa_s->pending_eapol_rx) { | |
1074 | struct os_time now, age; | |
1075 | os_get_time(&now); | |
1076 | os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age); | |
1077 | if (age.sec == 0 && age.usec < 100000 && | |
1078 | os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) == | |
1079 | 0) { | |
1080 | wpa_printf(MSG_DEBUG, "Process pending EAPOL frame " | |
1081 | "that was received just before association " | |
1082 | "notification"); | |
1083 | wpa_supplicant_rx_eapol( | |
1084 | wpa_s, wpa_s->pending_eapol_rx_src, | |
1085 | wpabuf_head(wpa_s->pending_eapol_rx), | |
1086 | wpabuf_len(wpa_s->pending_eapol_rx)); | |
1087 | } | |
1088 | wpabuf_free(wpa_s->pending_eapol_rx); | |
1089 | wpa_s->pending_eapol_rx = NULL; | |
1090 | } | |
60b94c98 JM |
1091 | |
1092 | #ifdef CONFIG_BGSCAN | |
1093 | if (wpa_s->current_ssid != wpa_s->bgscan_ssid) { | |
1094 | bgscan_deinit(wpa_s); | |
1095 | if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) { | |
1096 | if (bgscan_init(wpa_s, wpa_s->current_ssid)) { | |
1097 | wpa_printf(MSG_DEBUG, "Failed to initialize " | |
1098 | "bgscan"); | |
1099 | /* | |
1100 | * Live without bgscan; it is only used as a | |
1101 | * roaming optimization, so the initial | |
1102 | * connection is not affected. | |
1103 | */ | |
1104 | } else | |
1105 | wpa_s->bgscan_ssid = wpa_s->current_ssid; | |
1106 | } else | |
1107 | wpa_s->bgscan_ssid = NULL; | |
1108 | } | |
1109 | #endif /* CONFIG_BGSCAN */ | |
0194fedb JB |
1110 | |
1111 | if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
1112 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
1113 | wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 && | |
1114 | capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) { | |
1115 | /* Set static WEP keys again */ | |
1116 | wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); | |
1117 | } | |
6fc6879b JM |
1118 | } |
1119 | ||
1120 | ||
1121 | static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s) | |
1122 | { | |
1123 | const u8 *bssid; | |
6d6f4bb8 JM |
1124 | #ifdef CONFIG_SME |
1125 | int authenticating; | |
1126 | u8 prev_pending_bssid[ETH_ALEN]; | |
1127 | ||
1128 | authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING; | |
1129 | os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN); | |
1130 | #endif /* CONFIG_SME */ | |
6fc6879b JM |
1131 | |
1132 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
1133 | /* | |
1134 | * At least Host AP driver and a Prism3 card seemed to be | |
1135 | * generating streams of disconnected events when configuring | |
1136 | * IBSS for WPA-None. Ignore them for now. | |
1137 | */ | |
1138 | wpa_printf(MSG_DEBUG, "Disconnect event - ignore in " | |
1139 | "IBSS/WPA-None mode"); | |
1140 | return; | |
1141 | } | |
1142 | ||
1143 | if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE && | |
56586197 | 1144 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
6fc6879b JM |
1145 | wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " |
1146 | "pre-shared key may be incorrect"); | |
1147 | } | |
1148 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) | |
1149 | wpa_supplicant_req_scan(wpa_s, 0, 100000); | |
1150 | bssid = wpa_s->bssid; | |
a8e16edc | 1151 | if (is_zero_ether_addr(bssid)) |
6fc6879b JM |
1152 | bssid = wpa_s->pending_bssid; |
1153 | wpa_blacklist_add(wpa_s, bssid); | |
1154 | wpa_sm_notify_disassoc(wpa_s->wpa); | |
1155 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "- Disconnect event - " | |
1156 | "remove keys"); | |
1157 | if (wpa_supplicant_dynamic_keys(wpa_s)) { | |
1158 | wpa_s->keys_cleared = 0; | |
1159 | wpa_clear_keys(wpa_s, wpa_s->bssid); | |
1160 | } | |
1161 | wpa_supplicant_mark_disassoc(wpa_s); | |
60b94c98 | 1162 | bgscan_deinit(wpa_s); |
6d6f4bb8 JM |
1163 | #ifdef CONFIG_SME |
1164 | if (authenticating && | |
1165 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) { | |
1166 | /* | |
1167 | * mac80211-workaround to force deauth on failed auth cmd, | |
1168 | * requires us to remain in authenticating state to allow the | |
1169 | * second authentication attempt to be continued properly. | |
1170 | */ | |
1171 | wpa_printf(MSG_DEBUG, "SME: Allow pending authentication to " | |
1172 | "proceed after disconnection event"); | |
1173 | wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING); | |
1174 | os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN); | |
1175 | } | |
1176 | #endif /* CONFIG_SME */ | |
6fc6879b JM |
1177 | } |
1178 | ||
1179 | ||
46690a3b JM |
1180 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
1181 | static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, | |
1182 | void *sock_ctx) | |
1183 | { | |
1184 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1185 | ||
1186 | if (!wpa_s->pending_mic_error_report) | |
1187 | return; | |
1188 | ||
1189 | wpa_printf(MSG_DEBUG, "WPA: Sending pending MIC error report"); | |
1190 | wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); | |
1191 | wpa_s->pending_mic_error_report = 0; | |
1192 | } | |
1193 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
1194 | ||
1195 | ||
6fc6879b JM |
1196 | static void |
1197 | wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, | |
1198 | union wpa_event_data *data) | |
1199 | { | |
1200 | int pairwise; | |
1201 | struct os_time t; | |
1202 | ||
1203 | wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); | |
1204 | pairwise = (data && data->michael_mic_failure.unicast); | |
6fc6879b | 1205 | os_get_time(&t); |
46690a3b JM |
1206 | if ((wpa_s->last_michael_mic_error && |
1207 | t.sec - wpa_s->last_michael_mic_error <= 60) || | |
1208 | wpa_s->pending_mic_error_report) { | |
1209 | if (wpa_s->pending_mic_error_report) { | |
1210 | /* | |
1211 | * Send the pending MIC error report immediately since | |
1212 | * we are going to start countermeasures and AP better | |
1213 | * do the same. | |
1214 | */ | |
1215 | wpa_sm_key_request(wpa_s->wpa, 1, | |
1216 | wpa_s->pending_mic_error_pairwise); | |
1217 | } | |
1218 | ||
1219 | /* Send the new MIC error report immediately since we are going | |
1220 | * to start countermeasures and AP better do the same. | |
1221 | */ | |
1222 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1223 | ||
6fc6879b JM |
1224 | /* initialize countermeasures */ |
1225 | wpa_s->countermeasures = 1; | |
1226 | wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); | |
1227 | ||
1228 | /* | |
1229 | * Need to wait for completion of request frame. We do not get | |
1230 | * any callback for the message completion, so just wait a | |
1231 | * short while and hope for the best. */ | |
1232 | os_sleep(0, 10000); | |
1233 | ||
1234 | wpa_drv_set_countermeasures(wpa_s, 1); | |
1235 | wpa_supplicant_deauthenticate(wpa_s, | |
1236 | WLAN_REASON_MICHAEL_MIC_FAILURE); | |
1237 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, | |
1238 | wpa_s, NULL); | |
1239 | eloop_register_timeout(60, 0, | |
1240 | wpa_supplicant_stop_countermeasures, | |
1241 | wpa_s, NULL); | |
1242 | /* TODO: mark the AP rejected for 60 second. STA is | |
1243 | * allowed to associate with another AP.. */ | |
46690a3b JM |
1244 | } else { |
1245 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT | |
1246 | if (wpa_s->mic_errors_seen) { | |
1247 | /* | |
1248 | * Reduce the effectiveness of Michael MIC error | |
1249 | * reports as a means for attacking against TKIP if | |
1250 | * more than one MIC failure is noticed with the same | |
1251 | * PTK. We delay the transmission of the reports by a | |
1252 | * random time between 0 and 60 seconds in order to | |
1253 | * force the attacker wait 60 seconds before getting | |
1254 | * the information on whether a frame resulted in a MIC | |
1255 | * failure. | |
1256 | */ | |
1257 | u8 rval[4]; | |
1258 | int sec; | |
1259 | ||
1260 | if (os_get_random(rval, sizeof(rval)) < 0) | |
1261 | sec = os_random() % 60; | |
1262 | else | |
1263 | sec = WPA_GET_BE32(rval) % 60; | |
1264 | wpa_printf(MSG_DEBUG, "WPA: Delay MIC error report %d " | |
1265 | "seconds", sec); | |
1266 | wpa_s->pending_mic_error_report = 1; | |
1267 | wpa_s->pending_mic_error_pairwise = pairwise; | |
1268 | eloop_cancel_timeout( | |
1269 | wpa_supplicant_delayed_mic_error_report, | |
1270 | wpa_s, NULL); | |
1271 | eloop_register_timeout( | |
1272 | sec, os_random() % 1000000, | |
1273 | wpa_supplicant_delayed_mic_error_report, | |
1274 | wpa_s, NULL); | |
1275 | } else { | |
1276 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1277 | } | |
1278 | #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
1279 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1280 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
6fc6879b JM |
1281 | } |
1282 | wpa_s->last_michael_mic_error = t.sec; | |
46690a3b | 1283 | wpa_s->mic_errors_seen++; |
6fc6879b JM |
1284 | } |
1285 | ||
1286 | ||
a83d9c96 SL |
1287 | #ifdef CONFIG_TERMINATE_ONLASTIF |
1288 | static int any_interfaces(struct wpa_supplicant *head) | |
1289 | { | |
1290 | struct wpa_supplicant *wpa_s; | |
1291 | ||
1292 | for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) | |
1293 | if (!wpa_s->interface_removed) | |
1294 | return 1; | |
1295 | return 0; | |
1296 | } | |
1297 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
1298 | ||
1299 | ||
6fc6879b JM |
1300 | static void |
1301 | wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, | |
1302 | union wpa_event_data *data) | |
1303 | { | |
1304 | if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) | |
1305 | return; | |
1306 | ||
1307 | switch (data->interface_status.ievent) { | |
1308 | case EVENT_INTERFACE_ADDED: | |
1309 | if (!wpa_s->interface_removed) | |
1310 | break; | |
1311 | wpa_s->interface_removed = 0; | |
1312 | wpa_printf(MSG_DEBUG, "Configured interface was added."); | |
1313 | if (wpa_supplicant_driver_init(wpa_s) < 0) { | |
1314 | wpa_printf(MSG_INFO, "Failed to initialize the driver " | |
1315 | "after interface was added."); | |
1316 | } | |
1317 | break; | |
1318 | case EVENT_INTERFACE_REMOVED: | |
1319 | wpa_printf(MSG_DEBUG, "Configured interface was removed."); | |
1320 | wpa_s->interface_removed = 1; | |
1321 | wpa_supplicant_mark_disassoc(wpa_s); | |
1322 | l2_packet_deinit(wpa_s->l2); | |
1323 | wpa_s->l2 = NULL; | |
a83d9c96 SL |
1324 | #ifdef CONFIG_TERMINATE_ONLASTIF |
1325 | /* check if last interface */ | |
1326 | if (!any_interfaces(wpa_s->global->ifaces)) | |
1327 | eloop_terminate(); | |
1328 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
6fc6879b JM |
1329 | break; |
1330 | } | |
1331 | } | |
1332 | ||
1333 | ||
1334 | #ifdef CONFIG_PEERKEY | |
1335 | static void | |
1336 | wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s, | |
1337 | union wpa_event_data *data) | |
1338 | { | |
1339 | if (data == NULL) | |
1340 | return; | |
1341 | wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer); | |
1342 | } | |
1343 | #endif /* CONFIG_PEERKEY */ | |
1344 | ||
1345 | ||
1346 | #ifdef CONFIG_IEEE80211R | |
1347 | static void | |
1348 | wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s, | |
1349 | union wpa_event_data *data) | |
1350 | { | |
1351 | if (data == NULL) | |
1352 | return; | |
1353 | ||
1354 | if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies, | |
1355 | data->ft_ies.ies_len, | |
1356 | data->ft_ies.ft_action, | |
babfbf15 JM |
1357 | data->ft_ies.target_ap, |
1358 | data->ft_ies.ric_ies, | |
1359 | data->ft_ies.ric_ies_len) < 0) { | |
6fc6879b JM |
1360 | /* TODO: prevent MLME/driver from trying to associate? */ |
1361 | } | |
1362 | } | |
1363 | #endif /* CONFIG_IEEE80211R */ | |
1364 | ||
1365 | ||
11ef8d35 JM |
1366 | #ifdef CONFIG_IBSS_RSN |
1367 | static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s, | |
1368 | union wpa_event_data *data) | |
1369 | { | |
1370 | if (data == NULL) | |
1371 | return; | |
1372 | ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); | |
1373 | } | |
1374 | #endif /* CONFIG_IBSS_RSN */ | |
1375 | ||
1376 | ||
6fc6879b JM |
1377 | void wpa_supplicant_event(void *ctx, wpa_event_type event, |
1378 | union wpa_event_data *data) | |
1379 | { | |
1380 | struct wpa_supplicant *wpa_s = ctx; | |
1381 | ||
1382 | switch (event) { | |
c2a04078 JM |
1383 | case EVENT_AUTH: |
1384 | sme_event_auth(wpa_s, data); | |
1385 | break; | |
6fc6879b JM |
1386 | case EVENT_ASSOC: |
1387 | wpa_supplicant_event_assoc(wpa_s, data); | |
1388 | break; | |
1389 | case EVENT_DISASSOC: | |
0e379654 JM |
1390 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
1391 | sme_event_disassoc(wpa_s, data); | |
a84ed99e JM |
1392 | /* fall through */ |
1393 | case EVENT_DEAUTH: | |
6fc6879b JM |
1394 | wpa_supplicant_event_disassoc(wpa_s); |
1395 | break; | |
1396 | case EVENT_MICHAEL_MIC_FAILURE: | |
1397 | wpa_supplicant_event_michael_mic_failure(wpa_s, data); | |
1398 | break; | |
1399 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
1400 | case EVENT_SCAN_RESULTS: | |
1401 | wpa_supplicant_event_scan_results(wpa_s); | |
1402 | break; | |
1403 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | |
1404 | case EVENT_ASSOCINFO: | |
1405 | wpa_supplicant_event_associnfo(wpa_s, data); | |
1406 | break; | |
1407 | case EVENT_INTERFACE_STATUS: | |
1408 | wpa_supplicant_event_interface_status(wpa_s, data); | |
1409 | break; | |
1410 | case EVENT_PMKID_CANDIDATE: | |
1411 | wpa_supplicant_event_pmkid_candidate(wpa_s, data); | |
1412 | break; | |
1413 | #ifdef CONFIG_PEERKEY | |
1414 | case EVENT_STKSTART: | |
1415 | wpa_supplicant_event_stkstart(wpa_s, data); | |
1416 | break; | |
1417 | #endif /* CONFIG_PEERKEY */ | |
1418 | #ifdef CONFIG_IEEE80211R | |
1419 | case EVENT_FT_RESPONSE: | |
1420 | wpa_supplicant_event_ft_response(wpa_s, data); | |
1421 | break; | |
1422 | #endif /* CONFIG_IEEE80211R */ | |
11ef8d35 JM |
1423 | #ifdef CONFIG_IBSS_RSN |
1424 | case EVENT_IBSS_RSN_START: | |
1425 | wpa_supplicant_event_ibss_rsn_start(wpa_s, data); | |
1426 | break; | |
1427 | #endif /* CONFIG_IBSS_RSN */ | |
efa46078 JM |
1428 | case EVENT_ASSOC_REJECT: |
1429 | sme_event_assoc_reject(wpa_s, data); | |
1430 | break; | |
da1fb17c JM |
1431 | case EVENT_AUTH_TIMED_OUT: |
1432 | sme_event_auth_timed_out(wpa_s, data); | |
1433 | break; | |
1434 | case EVENT_ASSOC_TIMED_OUT: | |
1435 | sme_event_assoc_timed_out(wpa_s, data); | |
1436 | break; | |
f8b1f695 JM |
1437 | #ifdef CONFIG_AP |
1438 | case EVENT_TX_STATUS: | |
1439 | if (wpa_s->ap_iface == NULL) | |
1440 | break; | |
1441 | switch (data->tx_status.type) { | |
1442 | case WLAN_FC_TYPE_MGMT: | |
1443 | ap_mgmt_tx_cb(wpa_s, data->tx_status.data, | |
1444 | data->tx_status.data_len, | |
1445 | data->tx_status.stype, | |
1446 | data->tx_status.ack); | |
1447 | break; | |
1448 | case WLAN_FC_TYPE_DATA: | |
1449 | ap_tx_status(wpa_s, data->tx_status.dst, | |
1450 | data->tx_status.data, | |
1451 | data->tx_status.data_len, | |
1452 | data->tx_status.ack); | |
1453 | break; | |
1454 | } | |
1455 | break; | |
1456 | case EVENT_RX_FROM_UNKNOWN: | |
1457 | if (wpa_s->ap_iface == NULL) | |
1458 | break; | |
1459 | ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.hdr, | |
1460 | data->rx_from_unknown.len); | |
1461 | break; | |
1462 | case EVENT_RX_MGMT: | |
1463 | if (wpa_s->ap_iface == NULL) | |
1464 | break; | |
1465 | ap_mgmt_rx(wpa_s, data->rx_mgmt.frame, | |
1466 | data->rx_mgmt.frame_len, data->rx_mgmt.fi); | |
1467 | break; | |
1468 | #endif /* CONFIG_AP */ | |
6fc6879b JM |
1469 | default: |
1470 | wpa_printf(MSG_INFO, "Unknown event %d", event); | |
1471 | break; | |
1472 | } | |
1473 | } |