tizen beta release
[framework/connectivity/wpasupplicant.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  * Oct, 26th. 2011. TIZEN
412  * Add a function to check current networks is set for wps in this file
413  */
414
415 #ifdef CONFIG_WPS
416 static int wpas_wps_in_use_events(struct wpa_config *conf)
417 {
418         struct wpa_ssid *ssid;
419         int wps = 0;
420
421         for (ssid = conf->ssid; ssid; ssid = ssid->next) {
422                 if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
423                         continue;
424
425                 wps = 1;
426
427                 if (!ssid->eap.phase1)
428                         continue;
429
430                 if (os_strstr(ssid->eap.phase1, "pbc=1"))
431                         return 2;
432         }
433
434         return wps;
435 }
436 #endif /* CONFIG_WPS */
437
438
439 static struct wpa_bss *
440 wpa_supplicant_select_bss_wpa(struct wpa_supplicant *wpa_s,
441                               struct wpa_scan_results *scan_res,
442                               struct wpa_ssid *group,
443                               struct wpa_ssid **selected_ssid)
444 {
445         struct wpa_ssid *ssid;
446         struct wpa_scan_res *bss;
447         size_t i;
448         struct wpa_blacklist *e;
449         const u8 *ie;
450
451         wpa_printf(MSG_DEBUG, "Try to find WPA-enabled AP");
452         for (i = 0; i < scan_res->num; i++) {
453                 const u8 *ssid_;
454                 u8 wpa_ie_len, rsn_ie_len, ssid_len;
455                 bss = scan_res->res[i];
456
457                 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
458                 ssid_ = ie ? ie + 2 : (u8 *) "";
459                 ssid_len = ie ? ie[1] : 0;
460
461                 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
462                 wpa_ie_len = ie ? ie[1] : 0;
463
464                 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
465                 rsn_ie_len = ie ? ie[1] : 0;
466
467                 wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
468                            "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
469                            (int) i, MAC2STR(bss->bssid),
470                            wpa_ssid_txt(ssid_, ssid_len),
471                            wpa_ie_len, rsn_ie_len, bss->caps);
472
473                 e = wpa_blacklist_get(wpa_s, bss->bssid);
474                 if (e && e->count > 1) {
475                         wpa_printf(MSG_DEBUG, "   skip - blacklisted");
476                         continue;
477                 }
478
479                 if (ssid_len == 0) {
480                         wpa_printf(MSG_DEBUG, "   skip - SSID not known");
481                         continue;
482                 }
483
484                 if (wpa_ie_len == 0 && rsn_ie_len == 0) {
485                         wpa_printf(MSG_DEBUG, "   skip - no WPA/RSN IE");
486                         continue;
487                 }
488
489                 for (ssid = group; ssid; ssid = ssid->pnext) {
490                         int check_ssid = 1;
491
492                         if (ssid->disabled) {
493                                 wpa_printf(MSG_DEBUG, "   skip - disabled");
494                                 continue;
495                         }
496
497 #ifdef CONFIG_WPS
498                         if (ssid->ssid_len == 0 &&
499                             wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
500                                 check_ssid = 0;
501 #endif /* CONFIG_WPS */
502
503                         if (check_ssid &&
504                             (ssid_len != ssid->ssid_len ||
505                              os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
506                                 wpa_printf(MSG_DEBUG, "   skip - "
507                                            "SSID mismatch");
508                                 continue;
509                         }
510
511                         if (ssid->bssid_set &&
512                             os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
513                                 wpa_printf(MSG_DEBUG, "   skip - "
514                                            "BSSID mismatch");
515                                 continue;
516                         }
517
518                         if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
519                                 continue;
520
521                         if (!freq_allowed(ssid->freq_list, bss->freq)) {
522                                 wpa_printf(MSG_DEBUG, "   skip - "
523                                            "frequency not allowed");
524                                 continue;
525                         }
526
527                         wpa_printf(MSG_DEBUG, "   selected WPA AP "
528                                    MACSTR " ssid='%s'",
529                                    MAC2STR(bss->bssid),
530                                    wpa_ssid_txt(ssid_, ssid_len));
531                         *selected_ssid = ssid;
532                         return wpa_bss_get(wpa_s, bss->bssid, ssid_, ssid_len);
533                 }
534         }
535
536         return NULL;
537 }
538
539
540 static struct wpa_bss *
541 wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant *wpa_s,
542                                   struct wpa_scan_results *scan_res,
543                                   struct wpa_ssid *group,
544                                   struct wpa_ssid **selected_ssid)
545 {
546         struct wpa_ssid *ssid;
547         struct wpa_scan_res *bss;
548         size_t i;
549         struct wpa_blacklist *e;
550         const u8 *ie;
551
552         wpa_printf(MSG_DEBUG, "Try to find non-WPA AP");
553         for (i = 0; i < scan_res->num; i++) {
554                 const u8 *ssid_;
555                 u8 wpa_ie_len, rsn_ie_len, ssid_len;
556                 bss = scan_res->res[i];
557
558                 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
559                 ssid_ = ie ? ie + 2 : (u8 *) "";
560                 ssid_len = ie ? ie[1] : 0;
561
562                 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
563                 wpa_ie_len = ie ? ie[1] : 0;
564
565                 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
566                 rsn_ie_len = ie ? ie[1] : 0;
567
568                 wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
569                            "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
570                            (int) i, MAC2STR(bss->bssid),
571                            wpa_ssid_txt(ssid_, ssid_len),
572                            wpa_ie_len, rsn_ie_len, bss->caps);
573
574                 e = wpa_blacklist_get(wpa_s, bss->bssid);
575                 if (e && e->count > 1) {
576                         wpa_printf(MSG_DEBUG, "   skip - blacklisted");
577                         continue;
578                 }
579
580                 if (ssid_len == 0) {
581                         wpa_printf(MSG_DEBUG, "   skip - SSID not known");
582                         continue;
583                 }
584
585                 for (ssid = group; ssid; ssid = ssid->pnext) {
586                         int check_ssid = ssid->ssid_len != 0;
587
588                         if (ssid->disabled) {
589                                 wpa_printf(MSG_DEBUG, "   skip - disabled");
590                                 continue;
591                         }
592
593 #ifdef CONFIG_WPS
594                         if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
595                                 /* Only allow wildcard SSID match if an AP
596                                  * advertises active WPS operation that matches
597                                  * with our mode. */
598                                 check_ssid = 1;
599                                 if (ssid->ssid_len == 0 &&
600                                     wpas_wps_ssid_wildcard_ok(wpa_s, ssid,
601                                                               bss))
602                                         check_ssid = 0;
603                         }
604 #endif /* CONFIG_WPS */
605
606                         if (check_ssid &&
607                             (ssid_len != ssid->ssid_len ||
608                              os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
609                                 wpa_printf(MSG_DEBUG, "   skip - "
610                                            "SSID mismatch");
611                                 continue;
612                         }
613
614                         if (ssid->bssid_set &&
615                             os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
616                                 wpa_printf(MSG_DEBUG, "   skip - "
617                                            "BSSID mismatch");
618                                 continue;
619                         }
620
621                         if (!(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
622                             !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
623                             !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
624                                 wpa_printf(MSG_DEBUG, "   skip - "
625                                            "non-WPA network not allowed");
626                                 continue;
627                         }
628
629                         if ((ssid->key_mgmt &
630                              (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK |
631                               WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK |
632                               WPA_KEY_MGMT_IEEE8021X_SHA256 |
633                               WPA_KEY_MGMT_PSK_SHA256)) &&
634                             (wpa_ie_len != 0 || rsn_ie_len != 0)) {
635                                 wpa_printf(MSG_DEBUG, "   skip - "
636                                            "WPA network");
637                                 continue;
638                         }
639
640                         if (!wpa_supplicant_match_privacy(bss, ssid)) {
641                                 wpa_printf(MSG_DEBUG, "   skip - "
642                                            "privacy mismatch");
643                                 continue;
644                         }
645
646                         if (bss->caps & IEEE80211_CAP_IBSS) {
647                                 wpa_printf(MSG_DEBUG, "   skip - "
648                                            "IBSS (adhoc) network");
649                                 continue;
650                         }
651
652                         if (!freq_allowed(ssid->freq_list, bss->freq)) {
653                                 wpa_printf(MSG_DEBUG, "   skip - "
654                                            "frequency not allowed");
655                                 continue;
656                         }
657
658                         wpa_printf(MSG_DEBUG, "   selected non-WPA AP "
659                                    MACSTR " ssid='%s'",
660                                    MAC2STR(bss->bssid),
661                                    wpa_ssid_txt(ssid_, ssid_len));
662                         *selected_ssid = ssid;
663                         return wpa_bss_get(wpa_s, bss->bssid, ssid_, ssid_len);
664                 }
665         }
666
667         return NULL;
668 }
669
670
671 static struct wpa_bss *
672 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
673                           struct wpa_scan_results *scan_res,
674                           struct wpa_ssid *group,
675                           struct wpa_ssid **selected_ssid)
676 {
677         struct wpa_bss *selected;
678
679         wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d",
680                    group->priority);
681
682         /* First, try to find WPA-enabled AP */
683         selected = wpa_supplicant_select_bss_wpa(wpa_s, scan_res, group,
684                                                  selected_ssid);
685         if (selected)
686                 return selected;
687
688         /* If no WPA-enabled AP found, try to find non-WPA AP, if configuration
689          * allows this. */
690         return wpa_supplicant_select_bss_non_wpa(wpa_s, scan_res, group,
691                                                  selected_ssid);
692 }
693
694
695 static struct wpa_bss *
696 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
697                             struct wpa_scan_results *scan_res,
698                             struct wpa_ssid **selected_ssid)
699 {
700         struct wpa_bss *selected = NULL;
701         int prio;
702
703         while (selected == NULL) {
704                 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
705                         selected = wpa_supplicant_select_bss(
706                                 wpa_s, scan_res, wpa_s->conf->pssid[prio],
707                                 selected_ssid);
708                         if (selected)
709                                 break;
710                 }
711
712                 if (selected == NULL && wpa_s->blacklist) {
713                         wpa_printf(MSG_DEBUG, "No APs found - clear blacklist "
714                                    "and try again");
715                         wpa_blacklist_clear(wpa_s);
716                         wpa_s->blacklist_cleared++;
717                 } else if (selected == NULL)
718                         break;
719         }
720
721         return selected;
722 }
723
724
725 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
726                                         int timeout_sec, int timeout_usec)
727 {
728         if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
729                 /*
730                  * No networks are enabled; short-circuit request so
731                  * we don't wait timeout seconds before transitioning
732                  * to INACTIVE state.
733                  */
734                 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
735                 return;
736         }
737         wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
738 }
739
740
741 void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
742                             struct wpa_bss *selected,
743                             struct wpa_ssid *ssid)
744 {
745         if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
746                 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
747                         "PBC session overlap");
748                 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
749                 return;
750         }
751
752         /*
753          * Do not trigger new association unless the BSSID has changed or if
754          * reassociation is requested. If we are in process of associating with
755          * the selected BSSID, do not trigger new attempt.
756          */
757         if (wpa_s->reassociate ||
758             (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
759              (wpa_s->wpa_state != WPA_ASSOCIATING ||
760               os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
761               0))) {
762                 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
763                         wpa_supplicant_req_new_scan(wpa_s, 10, 0);
764                         return;
765                 }
766                 wpa_supplicant_associate(wpa_s, selected, ssid);
767         } else {
768                 wpa_printf(MSG_DEBUG, "Already associated with the selected "
769                            "AP");
770         }
771 }
772
773
774 static struct wpa_ssid *
775 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
776 {
777         int prio;
778         struct wpa_ssid *ssid;
779
780         for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
781                 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) {
782                         if (ssid->disabled)
783                                 continue;
784                         if (ssid->mode == IEEE80211_MODE_IBSS ||
785                             ssid->mode == IEEE80211_MODE_AP)
786                                 return ssid;
787                 }
788         }
789         return NULL;
790 }
791
792
793 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
794  * on BSS added and BSS changed events */
795 static void wpa_supplicant_rsn_preauth_scan_results(
796         struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res)
797 {
798         int i;
799
800         if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
801                 return;
802
803         for (i = scan_res->num - 1; i >= 0; i--) {
804                 const u8 *ssid, *rsn;
805                 struct wpa_scan_res *r;
806
807                 r = scan_res->res[i];
808
809                 ssid = wpa_scan_get_ie(r, WLAN_EID_SSID);
810                 if (ssid == NULL)
811                         continue;
812
813                 rsn = wpa_scan_get_ie(r, WLAN_EID_RSN);
814                 if (rsn == NULL)
815                         continue;
816
817                 rsn_preauth_scan_result(wpa_s->wpa, r->bssid, ssid, rsn);
818         }
819
820 }
821
822
823 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
824                                        struct wpa_bss *selected,
825                                        struct wpa_ssid *ssid,
826                                        struct wpa_scan_results *scan_res)
827 {
828         size_t i;
829         struct wpa_scan_res *current_bss = NULL;
830         int min_diff;
831
832         if (wpa_s->reassociate)
833                 return 1; /* explicit request to reassociate */
834         if (wpa_s->wpa_state < WPA_ASSOCIATED)
835                 return 1; /* we are not associated; continue */
836         if (wpa_s->current_ssid == NULL)
837                 return 1; /* unknown current SSID */
838         if (wpa_s->current_ssid != ssid)
839                 return 1; /* different network block */
840
841         /*
842          * Oct, 14th 2011. TIZEN
843          *
844          * Temporally, prevent to roam
845          */
846
847         return 0;
848
849
850         for (i = 0; i < scan_res->num; i++) {
851                 struct wpa_scan_res *res = scan_res->res[i];
852                 const u8 *ie;
853                 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
854                         continue;
855
856                 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
857                 if (ie == NULL)
858                         continue;
859                 if (ie[1] != wpa_s->current_ssid->ssid_len ||
860                     os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
861                         continue;
862                 current_bss = res;
863                 break;
864         }
865
866         if (!current_bss)
867                 return 1; /* current BSS not seen in scan results */
868
869         wpa_printf(MSG_DEBUG, "Considering within-ESS reassociation");
870         wpa_printf(MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
871                    MAC2STR(current_bss->bssid), current_bss->level);
872         wpa_printf(MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
873                    MAC2STR(selected->bssid), selected->level);
874
875         if (wpa_s->current_ssid->bssid_set &&
876             os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
877             0) {
878                 wpa_printf(MSG_DEBUG, "Allow reassociation - selected BSS has "
879                            "preferred BSSID");
880                 return 1;
881         }
882
883         min_diff = 2;
884         if (current_bss->level < 0) {
885                 if (current_bss->level < -85)
886                         min_diff = 1;
887                 else if (current_bss->level < -80)
888                         min_diff = 2;
889                 else if (current_bss->level < -75)
890                         min_diff = 3;
891                 else if (current_bss->level < -70)
892                         min_diff = 4;
893                 else
894                         min_diff = 5;
895         }
896         if (abs(current_bss->level - selected->level) < min_diff) {
897                 wpa_printf(MSG_DEBUG, "Skip roam - too small difference in "
898                            "signal level");
899                 return 0;
900         }
901
902         return 1;
903 }
904
905
906 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
907                                               union wpa_event_data *data)
908 {
909         struct wpa_bss *selected;
910         struct wpa_ssid *ssid = NULL;
911         struct wpa_scan_results *scan_res;
912         int ap = 0;
913
914 #ifdef CONFIG_AP
915         if (wpa_s->ap_iface)
916                 ap = 1;
917 #endif /* CONFIG_AP */
918
919         wpa_supplicant_notify_scanning(wpa_s, 0);
920
921         scan_res = wpa_supplicant_get_scan_results(wpa_s,
922                                                    data ? &data->scan_info :
923                                                    NULL, 1);
924         if (scan_res == NULL) {
925         /*
926          * September, 9th 2011. TIZEN
927          * broadcom driver returns scan abort due to enable 802.11b only
928          * Therefore, this part is changed temporally until driver is fixed or
929          * our poilcy is changed.
930          * The supplicant tries to scan forcebly again after 1sec.
931          */
932
933                 /* original codes */
934                 /*
935                 if (wpa_s->conf->ap_scan == 2 || ap)
936                         return;
937                 wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
938                            "scanning again");
939                 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
940                 */
941
942                 /* changed codes */
943
944                 /* connman set ap_scan as 2, thus we remove this code */
945
946                 if (ap)
947                         return;
948                 wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
949                            "scanning again");
950                 /*Real scan function check !wpa_s->scan_req thus next line is added*/
951                 wpa_s->scan_req = 2;
952                 /* wpa_supplicant_req_new_scan checks enabled networks exist
953                  * however, there is not any enabled network in this function
954                  * To skip the checking routine, next line which is called scan function directly is added. */
955                 wpa_supplicant_req_scan(wpa_s, 1, 0);
956
957                 /************/
958                 return;
959         }
960
961         if (wpa_s->scan_res_handler) {
962                 wpa_s->scan_res_handler(wpa_s, scan_res);
963                 wpa_s->scan_res_handler = NULL;
964                 wpa_scan_results_free(scan_res);
965                 return;
966         }
967
968         if (ap) {
969                 wpa_printf(MSG_DEBUG, "Ignore scan results in AP mode");
970                 wpa_scan_results_free(scan_res);
971                 return;
972         }
973
974         wpa_printf(MSG_DEBUG, "New scan results available");
975         wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
976         wpas_notify_scan_results(wpa_s);
977
978         wpas_notify_scan_done(wpa_s, 1);
979
980         if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
981                 wpa_scan_results_free(scan_res);
982                 return;
983         }
984
985         if (wpa_s->disconnected) {
986                 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
987                 wpa_scan_results_free(scan_res);
988                 return;
989         }
990
991         if (bgscan_notify_scan(wpa_s) == 1) {
992                 wpa_scan_results_free(scan_res);
993                 return;
994         }
995
996         wpa_supplicant_rsn_preauth_scan_results(wpa_s, scan_res);
997
998         selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
999
1000         if (selected) {
1001                 int skip;
1002                 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
1003                                                                                         scan_res);
1004                 wpa_scan_results_free(scan_res);
1005
1006                 if (skip)
1007                         return;
1008                 wpa_supplicant_connect(wpa_s, selected, ssid);
1009         } else {
1010                 wpa_scan_results_free(scan_res);
1011                 wpa_printf(MSG_DEBUG, "No suitable network found");
1012                 ssid = wpa_supplicant_pick_new_network(wpa_s);
1013                 if (ssid) {
1014                         wpa_printf(MSG_DEBUG, "Setup a new network");
1015                         wpa_supplicant_associate(wpa_s, NULL, ssid);
1016                 } else {
1017                         /*
1018                          * Oct, 26th. 2011. TIZEN
1019                          * In case of WPS, wpa_s->conf->ssid should not be NULL
1020                          */
1021                         int wps = 0;
1022
1023                         int timeout_sec = 5;
1024                         int timeout_usec = 0;
1025
1026                         wps = wpas_wps_in_use_events(wpa_s->conf);
1027
1028                         if (wps == 0) {
1029                                 struct wpa_ssid *start;
1030                                 wpa_s->associate_num = 2;
1031                                 wpa_s->reassociate = 0;
1032                                 wpa_s->disconnected = 1;
1033                                 if (wpa_s->conf->ssid != NULL) {
1034                                         start = wpa_s->conf->ssid;
1035                                         while (start) {
1036                                                 start->scan_ssid = 0;
1037                                                 start = start->next;
1038                                         }
1039                                 }
1040                         }
1041
1042                         wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1043                                                     timeout_usec);
1044                 }
1045         }
1046 }
1047 #endif /* CONFIG_NO_SCAN_PROCESSING */
1048
1049
1050 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1051                                           union wpa_event_data *data)
1052 {
1053         int l, len, found = 0, wpa_found, rsn_found;
1054         const u8 *p;
1055
1056         wpa_printf(MSG_DEBUG, "Association info event");
1057         if (data->assoc_info.req_ies)
1058                 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1059                             data->assoc_info.req_ies_len);
1060         if (data->assoc_info.resp_ies)
1061                 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1062                             data->assoc_info.resp_ies_len);
1063         if (data->assoc_info.beacon_ies)
1064                 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1065                             data->assoc_info.beacon_ies,
1066                             data->assoc_info.beacon_ies_len);
1067         if (data->assoc_info.freq)
1068                 wpa_printf(MSG_DEBUG, "freq=%u MHz", data->assoc_info.freq);
1069
1070         p = data->assoc_info.req_ies;
1071         l = data->assoc_info.req_ies_len;
1072
1073         /* Go through the IEs and make a copy of the WPA/RSN 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_VENDOR_SPECIFIC && p[1] >= 6 &&
1082                      (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1083                     (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1084                         if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1085                                 break;
1086                         found = 1;
1087                         wpa_find_assoc_pmkid(wpa_s);
1088                         break;
1089                 }
1090                 l -= len;
1091                 p += len;
1092         }
1093         if (!found && data->assoc_info.req_ies)
1094                 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1095
1096 #ifdef CONFIG_IEEE80211R
1097 #ifdef CONFIG_SME
1098         if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
1099                 u8 bssid[ETH_ALEN];
1100                 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1101                     wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1102                                                  data->assoc_info.resp_ies,
1103                                                  data->assoc_info.resp_ies_len,
1104                                                  bssid) < 0) {
1105                         wpa_printf(MSG_DEBUG, "FT: Validation of "
1106                                    "Reassociation Response failed");
1107                         wpa_supplicant_deauthenticate(
1108                                 wpa_s, WLAN_REASON_INVALID_IE);
1109                         return -1;
1110                 }
1111         }
1112
1113         p = data->assoc_info.resp_ies;
1114         l = data->assoc_info.resp_ies_len;
1115
1116         /* Go through the IEs and make a copy of the MDIE, if present. */
1117         while (p && l >= 2) {
1118                 len = p[1] + 2;
1119                 if (len > l) {
1120                         wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1121                                     p, l);
1122                         break;
1123                 }
1124                 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1125                     p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1126                         wpa_s->sme.ft_used = 1;
1127                         os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1128                                   MOBILITY_DOMAIN_ID_LEN);
1129                         break;
1130                 }
1131                 l -= len;
1132                 p += len;
1133         }
1134 #endif /* CONFIG_SME */
1135
1136         wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1137                              data->assoc_info.resp_ies_len);
1138 #endif /* CONFIG_IEEE80211R */
1139
1140         /* WPA/RSN IE from Beacon/ProbeResp */
1141         p = data->assoc_info.beacon_ies;
1142         l = data->assoc_info.beacon_ies_len;
1143
1144         /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1145          */
1146         wpa_found = rsn_found = 0;
1147         while (p && l >= 2) {
1148                 len = p[1] + 2;
1149                 if (len > l) {
1150                         wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1151                                     p, l);
1152                         break;
1153                 }
1154                 if (!wpa_found &&
1155                     p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1156                     os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1157                         wpa_found = 1;
1158                         wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1159                 }
1160
1161                 if (!rsn_found &&
1162                     p[0] == WLAN_EID_RSN && p[1] >= 2) {
1163                         rsn_found = 1;
1164                         wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1165                 }
1166
1167                 l -= len;
1168                 p += len;
1169         }
1170
1171         if (!wpa_found && data->assoc_info.beacon_ies)
1172                 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1173         if (!rsn_found && data->assoc_info.beacon_ies)
1174                 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1175         if (wpa_found || rsn_found)
1176                 wpa_s->ap_ies_from_associnfo = 1;
1177
1178         wpa_s->assoc_freq = data->assoc_info.freq;
1179
1180         return 0;
1181 }
1182
1183
1184 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1185                                        union wpa_event_data *data)
1186 {
1187         u8 bssid[ETH_ALEN];
1188         int ft_completed;
1189         int bssid_changed;
1190         struct wpa_driver_capa capa;
1191
1192 #ifdef CONFIG_AP
1193         if (wpa_s->ap_iface) {
1194                 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1195                                     data->assoc_info.addr,
1196                                     data->assoc_info.req_ies,
1197                                     data->assoc_info.req_ies_len);
1198                 return;
1199         }
1200 #endif /* CONFIG_AP */
1201
1202         /*
1203          * Dec, 6th 2011. TIZEN
1204          * If a wpa_supplicant is disconnec state, this associate event should be
1205          * ignored and supplicant should be disconnected.
1206          */
1207         if (wpa_s->wpa_state < WPA_ASSOCIATING) {
1208                 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
1209                 return;
1210         }
1211
1212         ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1213         if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1214                 return;
1215
1216         wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
1217         if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
1218                 os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
1219         if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
1220             (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
1221              os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
1222                 wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1223                         MACSTR, MAC2STR(bssid));
1224                 bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
1225                 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1226                 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
1227                 if (bssid_changed)
1228                         wpas_notify_bssid_changed(wpa_s);
1229
1230                 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1231                         wpa_clear_keys(wpa_s, bssid);
1232                 }
1233                 if (wpa_supplicant_select_config(wpa_s) < 0) {
1234                         wpa_supplicant_disassociate(
1235                                 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1236                         return;
1237                 }
1238                 if (wpa_s->current_ssid) {
1239                         struct wpa_bss *bss = NULL;
1240                         struct wpa_ssid *ssid = wpa_s->current_ssid;
1241                         if (ssid->ssid_len > 0)
1242                                 bss = wpa_bss_get(wpa_s, bssid,
1243                                                   ssid->ssid, ssid->ssid_len);
1244                         if (!bss)
1245                                 bss = wpa_bss_get_bssid(wpa_s, bssid);
1246                         if (bss)
1247                                 wpa_s->current_bss = bss;
1248                 }
1249         }
1250
1251 #ifdef CONFIG_SME
1252         os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1253         wpa_s->sme.prev_bssid_set = 1;
1254 #endif /* CONFIG_SME */
1255
1256         wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1257         if (wpa_s->current_ssid) {
1258                 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1259                  * initialized before association, but for other modes,
1260                  * initialize PC/SC here, if the current configuration needs
1261                  * smartcard or SIM/USIM. */
1262                 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1263         }
1264         wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1265         if (wpa_s->l2)
1266                 l2_packet_notify_auth_start(wpa_s->l2);
1267
1268         /*
1269          * Set portEnabled first to FALSE in order to get EAP state machine out
1270          * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1271          * state machine may transit to AUTHENTICATING state based on obsolete
1272          * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1273          * AUTHENTICATED without ever giving chance to EAP state machine to
1274          * reset the state.
1275          */
1276         if (!ft_completed) {
1277                 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1278                 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1279         }
1280         if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1281                 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1282         /* 802.1X::portControl = Auto */
1283         eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1284         wpa_s->eapol_received = 0;
1285         if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1286             wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1287             (wpa_s->current_ssid &&
1288              wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
1289                 wpa_supplicant_cancel_auth_timeout(wpa_s);
1290                 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1291         } else if (!ft_completed) {
1292                 /* Timeout for receiving the first EAPOL packet */
1293                 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1294         }
1295         wpa_supplicant_cancel_scan(wpa_s);
1296
1297         if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1298             wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1299                 /*
1300                  * We are done; the driver will take care of RSN 4-way
1301                  * handshake.
1302                  */
1303                 wpa_supplicant_cancel_auth_timeout(wpa_s);
1304                 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1305                 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1306                 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1307         }
1308
1309         if (wpa_s->pending_eapol_rx) {
1310                 struct os_time now, age;
1311                 os_get_time(&now);
1312                 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1313                 if (age.sec == 0 && age.usec < 100000 &&
1314                     os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1315                     0) {
1316                         wpa_printf(MSG_DEBUG, "Process pending EAPOL frame "
1317                                    "that was received just before association "
1318                                    "notification");
1319                         wpa_supplicant_rx_eapol(
1320                                 wpa_s, wpa_s->pending_eapol_rx_src,
1321                                 wpabuf_head(wpa_s->pending_eapol_rx),
1322                                 wpabuf_len(wpa_s->pending_eapol_rx));
1323                 }
1324                 wpabuf_free(wpa_s->pending_eapol_rx);
1325                 wpa_s->pending_eapol_rx = NULL;
1326         }
1327
1328 #ifdef CONFIG_BGSCAN
1329         if (wpa_s->current_ssid != wpa_s->bgscan_ssid) {
1330                 bgscan_deinit(wpa_s);
1331                 if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) {
1332                         if (bgscan_init(wpa_s, wpa_s->current_ssid)) {
1333                                 wpa_printf(MSG_DEBUG, "Failed to initialize "
1334                                            "bgscan");
1335                                 /*
1336                                  * Live without bgscan; it is only used as a
1337                                  * roaming optimization, so the initial
1338                                  * connection is not affected.
1339                                  */
1340                         } else
1341                                 wpa_s->bgscan_ssid = wpa_s->current_ssid;
1342                 } else
1343                         wpa_s->bgscan_ssid = NULL;
1344         }
1345 #endif /* CONFIG_BGSCAN */
1346
1347         if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1348              wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
1349             wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
1350             capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
1351                 /* Set static WEP keys again */
1352                 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1353         }
1354 }
1355
1356
1357 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
1358                                           u16 reason_code)
1359 {
1360         /*
1361          * Oct, 26th. 2011. TIZEN
1362          * A wps variable is added for check enabled networks is set for WPS
1363          */
1364         int wps = 0;
1365
1366         const u8 *bssid;
1367 #ifdef CONFIG_SME
1368         int authenticating;
1369         u8 prev_pending_bssid[ETH_ALEN];
1370
1371         authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
1372         os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
1373 #endif /* CONFIG_SME */
1374
1375         if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1376                 /*
1377                  * At least Host AP driver and a Prism3 card seemed to be
1378                  * generating streams of disconnected events when configuring
1379                  * IBSS for WPA-None. Ignore them for now.
1380                  */
1381                 wpa_printf(MSG_DEBUG, "Disconnect event - ignore in "
1382                            "IBSS/WPA-None mode");
1383                 return;
1384         }
1385
1386 #if 0
1387         if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1388             wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1389                 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1390                         "pre-shared key may be incorrect");
1391         }
1392         if (wpa_s->wpa_state >= WPA_ASSOCIATED)
1393                 wpa_supplicant_req_scan(wpa_s, 0, 100000);
1394 #else
1395         /*
1396          * September, 29th 2011. TIZEN
1397          *
1398          * Because connman doesn't know authenticate fail
1399          * thus connman doesn't try to deauthenticate
1400          * We insert followings forcefully
1401          */
1402
1403         if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
1404             wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1405                 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
1406                         "pre-shared key may be incorrect");
1407         }
1408 #endif
1409
1410         /*
1411          * Oct, 26th. 2011. TIZEN
1412          * A wps variable is added for check enabled networks is set for WPS
1413          */
1414         wps = wpas_wps_in_use_events(wpa_s->conf);
1415
1416         if (wps == 0) {
1417                 struct wpa_ssid *start = wpa_s->conf->ssid;
1418                 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
1419                         ieee80211_sta_deauthenticate(wpa_s, reason_code);
1420                 else
1421                         wpa_drv_deauthenticate(wpa_s, wpa_s->bssid,
1422                                                    reason_code);
1423                 wpa_s->current_ssid = NULL;
1424                 wpa_s->current_bss = NULL;
1425                 wpa_s->reassociate = 0;
1426                 wpa_s->disconnected = 1;
1427                 while (start) {
1428                         start->scan_ssid = 0;
1429                         start = start->next;
1430                 }
1431
1432                 wpa_supplicant_cancel_auth_timeout(wpa_s);
1433         }
1434         /***********************************************/
1435
1436         bssid = wpa_s->bssid;
1437         if (is_zero_ether_addr(bssid))
1438                 bssid = wpa_s->pending_bssid;
1439         wpa_blacklist_add(wpa_s, bssid);
1440         wpa_sm_notify_disassoc(wpa_s->wpa);
1441         wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1442                 " reason=%d",
1443                 MAC2STR(bssid), reason_code);
1444         if (wpa_supplicant_dynamic_keys(wpa_s)) {
1445                 wpa_printf(MSG_DEBUG, "Disconnect event - remove keys");
1446                 wpa_s->keys_cleared = 0;
1447                 wpa_clear_keys(wpa_s, wpa_s->bssid);
1448         }
1449         wpa_supplicant_mark_disassoc(wpa_s);
1450         bgscan_deinit(wpa_s);
1451         wpa_s->bgscan_ssid = NULL;
1452 #ifdef CONFIG_SME
1453         if (authenticating &&
1454             (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
1455                 /*
1456                  * mac80211-workaround to force deauth on failed auth cmd,
1457                  * requires us to remain in authenticating state to allow the
1458                  * second authentication attempt to be continued properly.
1459                  */
1460                 wpa_printf(MSG_DEBUG, "SME: Allow pending authentication to "
1461                            "proceed after disconnection event");
1462                 wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
1463                 os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN);
1464         }
1465 #endif /* CONFIG_SME */
1466 }
1467
1468
1469 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1470 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
1471                                                     void *sock_ctx)
1472 {
1473         struct wpa_supplicant *wpa_s = eloop_ctx;
1474
1475         if (!wpa_s->pending_mic_error_report)
1476                 return;
1477
1478         wpa_printf(MSG_DEBUG, "WPA: Sending pending MIC error report");
1479         wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
1480         wpa_s->pending_mic_error_report = 0;
1481 }
1482 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1483
1484
1485 static void
1486 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
1487                                          union wpa_event_data *data)
1488 {
1489         int pairwise;
1490         struct os_time t;
1491
1492         wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
1493         pairwise = (data && data->michael_mic_failure.unicast);
1494         os_get_time(&t);
1495         if ((wpa_s->last_michael_mic_error &&
1496              t.sec - wpa_s->last_michael_mic_error <= 60) ||
1497             wpa_s->pending_mic_error_report) {
1498                 if (wpa_s->pending_mic_error_report) {
1499                         /*
1500                          * Send the pending MIC error report immediately since
1501                          * we are going to start countermeasures and AP better
1502                          * do the same.
1503                          */
1504                         wpa_sm_key_request(wpa_s->wpa, 1,
1505                                            wpa_s->pending_mic_error_pairwise);
1506                 }
1507
1508                 /* Send the new MIC error report immediately since we are going
1509                  * to start countermeasures and AP better do the same.
1510                  */
1511                 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1512
1513                 /* initialize countermeasures */
1514                 wpa_s->countermeasures = 1;
1515                 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
1516
1517                 /*
1518                  * Need to wait for completion of request frame. We do not get
1519                  * any callback for the message completion, so just wait a
1520                  * short while and hope for the best. */
1521                 os_sleep(0, 10000);
1522
1523                 wpa_drv_set_countermeasures(wpa_s, 1);
1524                 wpa_supplicant_deauthenticate(wpa_s,
1525                                               WLAN_REASON_MICHAEL_MIC_FAILURE);
1526                 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
1527                                      wpa_s, NULL);
1528                 eloop_register_timeout(60, 0,
1529                                        wpa_supplicant_stop_countermeasures,
1530                                        wpa_s, NULL);
1531                 /* TODO: mark the AP rejected for 60 second. STA is
1532                  * allowed to associate with another AP.. */
1533         } else {
1534 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
1535                 if (wpa_s->mic_errors_seen) {
1536                         /*
1537                          * Reduce the effectiveness of Michael MIC error
1538                          * reports as a means for attacking against TKIP if
1539                          * more than one MIC failure is noticed with the same
1540                          * PTK. We delay the transmission of the reports by a
1541                          * random time between 0 and 60 seconds in order to
1542                          * force the attacker wait 60 seconds before getting
1543                          * the information on whether a frame resulted in a MIC
1544                          * failure.
1545                          */
1546                         u8 rval[4];
1547                         int sec;
1548
1549                         if (os_get_random(rval, sizeof(rval)) < 0)
1550                                 sec = os_random() % 60;
1551                         else
1552                                 sec = WPA_GET_BE32(rval) % 60;
1553                         wpa_printf(MSG_DEBUG, "WPA: Delay MIC error report %d "
1554                                    "seconds", sec);
1555                         wpa_s->pending_mic_error_report = 1;
1556                         wpa_s->pending_mic_error_pairwise = pairwise;
1557                         eloop_cancel_timeout(
1558                                 wpa_supplicant_delayed_mic_error_report,
1559                                 wpa_s, NULL);
1560                         eloop_register_timeout(
1561                                 sec, os_random() % 1000000,
1562                                 wpa_supplicant_delayed_mic_error_report,
1563                                 wpa_s, NULL);
1564                 } else {
1565                         wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1566                 }
1567 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1568                 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
1569 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
1570         }
1571         wpa_s->last_michael_mic_error = t.sec;
1572         wpa_s->mic_errors_seen++;
1573 }
1574
1575
1576 #ifdef CONFIG_TERMINATE_ONLASTIF
1577 static int any_interfaces(struct wpa_supplicant *head)
1578 {
1579         struct wpa_supplicant *wpa_s;
1580
1581         for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
1582                 if (!wpa_s->interface_removed)
1583                         return 1;
1584         return 0;
1585 }
1586 #endif /* CONFIG_TERMINATE_ONLASTIF */
1587
1588
1589 static void
1590 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
1591                                       union wpa_event_data *data)
1592 {
1593         if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
1594                 return;
1595
1596         switch (data->interface_status.ievent) {
1597         case EVENT_INTERFACE_ADDED:
1598                 if (!wpa_s->interface_removed)
1599                         break;
1600                 wpa_s->interface_removed = 0;
1601                 wpa_printf(MSG_DEBUG, "Configured interface was added.");
1602                 if (wpa_supplicant_driver_init(wpa_s) < 0) {
1603                         wpa_printf(MSG_INFO, "Failed to initialize the driver "
1604                                    "after interface was added.");
1605                 }
1606                 break;
1607         case EVENT_INTERFACE_REMOVED:
1608                 wpa_printf(MSG_DEBUG, "Configured interface was removed.");
1609                 wpa_s->interface_removed = 1;
1610                 wpa_supplicant_mark_disassoc(wpa_s);
1611                 l2_packet_deinit(wpa_s->l2);
1612                 wpa_s->l2 = NULL;
1613 #ifdef CONFIG_TERMINATE_ONLASTIF
1614                 /* check if last interface */
1615                 if (!any_interfaces(wpa_s->global->ifaces))
1616                         eloop_terminate();
1617 #endif /* CONFIG_TERMINATE_ONLASTIF */
1618                 break;
1619         }
1620 }
1621
1622
1623 #ifdef CONFIG_PEERKEY
1624 static void
1625 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
1626                               union wpa_event_data *data)
1627 {
1628         if (data == NULL)
1629                 return;
1630         wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
1631 }
1632 #endif /* CONFIG_PEERKEY */
1633
1634
1635 #ifdef CONFIG_IEEE80211R
1636 static void
1637 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
1638                                  union wpa_event_data *data)
1639 {
1640         if (data == NULL)
1641                 return;
1642
1643         if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
1644                                     data->ft_ies.ies_len,
1645                                     data->ft_ies.ft_action,
1646                                     data->ft_ies.target_ap,
1647                                     data->ft_ies.ric_ies,
1648                                     data->ft_ies.ric_ies_len) < 0) {
1649                 /* TODO: prevent MLME/driver from trying to associate? */
1650         }
1651 }
1652 #endif /* CONFIG_IEEE80211R */
1653
1654
1655 #ifdef CONFIG_IBSS_RSN
1656 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
1657                                                 union wpa_event_data *data)
1658 {
1659         if (data == NULL)
1660                 return;
1661         ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
1662 }
1663 #endif /* CONFIG_IBSS_RSN */
1664
1665
1666 #ifdef CONFIG_IEEE80211R
1667 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
1668                          size_t len)
1669 {
1670         const u8 *sta_addr, *target_ap_addr;
1671         u16 status;
1672
1673         wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
1674         if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
1675                 return; /* only SME case supported for now */
1676         if (len < 1 + 2 * ETH_ALEN + 2)
1677                 return;
1678         if (data[0] != 2)
1679                 return; /* Only FT Action Response is supported for now */
1680         sta_addr = data + 1;
1681         target_ap_addr = data + 1 + ETH_ALEN;
1682         status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
1683         wpa_printf(MSG_DEBUG, "FT: Received FT Action Response: STA " MACSTR
1684                    " TargetAP " MACSTR " status %u",
1685                    MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
1686
1687         if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
1688                 wpa_printf(MSG_DEBUG, "FT: Foreign STA Address " MACSTR
1689                            " in FT Action Response", MAC2STR(sta_addr));
1690                 return;
1691         }
1692
1693         if (status) {
1694                 wpa_printf(MSG_DEBUG, "FT: FT Action Response indicates "
1695                            "failure (status code %d)", status);
1696                 /* TODO: report error to FT code(?) */
1697                 return;
1698         }
1699
1700         if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
1701                                     len - (1 + 2 * ETH_ALEN + 2), 1,
1702                                     target_ap_addr, NULL, 0) < 0)
1703                 return;
1704
1705 #ifdef CONFIG_SME
1706         {
1707                 struct wpa_bss *bss;
1708                 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
1709                 if (bss)
1710                         wpa_s->sme.freq = bss->freq;
1711                 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
1712                 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
1713                               WLAN_AUTH_FT);
1714         }
1715 #endif /* CONFIG_SME */
1716 }
1717 #endif /* CONFIG_IEEE80211R */
1718
1719
1720 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1721                           union wpa_event_data *data)
1722 {
1723         struct wpa_supplicant *wpa_s = ctx;
1724         u16 reason_code = 0;
1725
1726         switch (event) {
1727         case EVENT_AUTH:
1728                 sme_event_auth(wpa_s, data);
1729                 break;
1730         case EVENT_ASSOC:
1731                 wpa_supplicant_event_assoc(wpa_s, data);
1732                 break;
1733         case EVENT_DISASSOC:
1734                 wpa_printf(MSG_DEBUG, "Disassociation notification");
1735         /*
1736          * Oct, 26th. 2011. TIZEN
1737          * If wps is completed, broadcom 4330, 4329 driver send disassoc event.
1738          * Therefore, wps association trying with credential is failed.
1739          */
1740                 if (wpa_s->after_wps != 0)
1741                         break;
1742 #ifdef CONFIG_AP
1743                 if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
1744                         hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1745                                                data->disassoc_info.addr);
1746                         break;
1747                 }
1748 #endif /* CONFIG_AP */
1749                 if (data)
1750                         reason_code = data->deauth_info.reason_code;
1751                 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
1752                         sme_event_disassoc(wpa_s, data);
1753                 /* fall through */
1754         case EVENT_DEAUTH:
1755                 if (event == EVENT_DEAUTH) {
1756                         wpa_printf(MSG_DEBUG, "Deauthentication notification");
1757                         if (data)
1758                                 reason_code = data->deauth_info.reason_code;
1759                 }
1760 #ifdef CONFIG_AP
1761                 if (wpa_s->ap_iface && data && data->deauth_info.addr) {
1762                         hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
1763                                                data->deauth_info.addr);
1764                         break;
1765                 }
1766 #endif /* CONFIG_AP */
1767                 wpa_supplicant_event_disassoc(wpa_s, reason_code);
1768                 break;
1769         case EVENT_MICHAEL_MIC_FAILURE:
1770                 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
1771                 break;
1772 #ifndef CONFIG_NO_SCAN_PROCESSING
1773         case EVENT_SCAN_RESULTS:
1774                 wpa_supplicant_event_scan_results(wpa_s, data);
1775                 break;
1776 #endif /* CONFIG_NO_SCAN_PROCESSING */
1777         case EVENT_ASSOCINFO:
1778                 wpa_supplicant_event_associnfo(wpa_s, data);
1779                 break;
1780         case EVENT_INTERFACE_STATUS:
1781                 wpa_supplicant_event_interface_status(wpa_s, data);
1782                 break;
1783         case EVENT_PMKID_CANDIDATE:
1784                 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
1785                 break;
1786 #ifdef CONFIG_PEERKEY
1787         case EVENT_STKSTART:
1788                 wpa_supplicant_event_stkstart(wpa_s, data);
1789                 break;
1790 #endif /* CONFIG_PEERKEY */
1791 #ifdef CONFIG_IEEE80211R
1792         case EVENT_FT_RESPONSE:
1793                 wpa_supplicant_event_ft_response(wpa_s, data);
1794                 break;
1795 #endif /* CONFIG_IEEE80211R */
1796 #ifdef CONFIG_IBSS_RSN
1797         case EVENT_IBSS_RSN_START:
1798                 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
1799                 break;
1800 #endif /* CONFIG_IBSS_RSN */
1801         case EVENT_ASSOC_REJECT:
1802                 sme_event_assoc_reject(wpa_s, data);
1803                 break;
1804         case EVENT_AUTH_TIMED_OUT:
1805                 sme_event_auth_timed_out(wpa_s, data);
1806                 break;
1807         case EVENT_ASSOC_TIMED_OUT:
1808                 sme_event_assoc_timed_out(wpa_s, data);
1809                 break;
1810 #ifdef CONFIG_AP
1811         case EVENT_TX_STATUS:
1812                 if (wpa_s->ap_iface == NULL)
1813                         break;
1814                 switch (data->tx_status.type) {
1815                 case WLAN_FC_TYPE_MGMT:
1816                         ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
1817                                       data->tx_status.data_len,
1818                                       data->tx_status.stype,
1819                                       data->tx_status.ack);
1820                         break;
1821                 case WLAN_FC_TYPE_DATA:
1822                         ap_tx_status(wpa_s, data->tx_status.dst,
1823                                      data->tx_status.data,
1824                                      data->tx_status.data_len,
1825                                      data->tx_status.ack);
1826                         break;
1827                 }
1828                 break;
1829         case EVENT_RX_FROM_UNKNOWN:
1830                 if (wpa_s->ap_iface == NULL)
1831                         break;
1832                 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
1833                                        data->rx_from_unknown.len);
1834                 break;
1835         case EVENT_RX_MGMT:
1836                 if (wpa_s->ap_iface == NULL)
1837                         break;
1838                 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
1839                 break;
1840 #endif /* CONFIG_AP */
1841         case EVENT_RX_ACTION:
1842                 wpa_printf(MSG_DEBUG, "Received Action frame: SA=" MACSTR
1843                            " Category=%u DataLen=%d freq=%d MHz",
1844                            MAC2STR(data->rx_action.sa),
1845                            data->rx_action.category, (int) data->rx_action.len,
1846                            data->rx_action.freq);
1847 #ifdef CONFIG_IEEE80211R
1848                 if (data->rx_action.category == WLAN_ACTION_FT) {
1849                         ft_rx_action(wpa_s, data->rx_action.data,
1850                                      data->rx_action.len);
1851                         break;
1852                 }
1853 #endif /* CONFIG_IEEE80211R */
1854                 break;
1855 #ifdef CONFIG_CLIENT_MLME
1856         case EVENT_MLME_RX: {
1857                 struct ieee80211_rx_status rx_status;
1858                 os_memset(&rx_status, 0, sizeof(rx_status));
1859                 rx_status.freq = data->mlme_rx.freq;
1860                 rx_status.channel = data->mlme_rx.channel;
1861                 rx_status.ssi = data->mlme_rx.ssi;
1862                 ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
1863                                  &rx_status);
1864                 break;
1865         }
1866 #endif /* CONFIG_CLIENT_MLME */
1867         case EVENT_EAPOL_RX:
1868                 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
1869                                         data->eapol_rx.data,
1870                                         data->eapol_rx.data_len);
1871                 break;
1872         case EVENT_SIGNAL_CHANGE:
1873                 bgscan_notify_signal_change(
1874                         wpa_s, data->signal_change.above_threshold);
1875                 break;
1876         default:
1877                 wpa_printf(MSG_INFO, "Unknown event %d", event);
1878                 break;
1879         }
1880 }