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