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