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