events.c
Go to the documentation of this file.
00001 /*
00002  * WPA Supplicant - Driver event processing
00003  * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #include "includes.h"
00016 
00017 #include "common.h"
00018 #include "eapol_supp/eapol_supp_sm.h"
00019 #include "rsn_supp/wpa.h"
00020 #include "eloop.h"
00021 #include "config.h"
00022 #include "l2_packet/l2_packet.h"
00023 #include "wpa_supplicant_i.h"
00024 #include "driver_i.h"
00025 #include "pcsc_funcs.h"
00026 #include "rsn_supp/preauth.h"
00027 #include "rsn_supp/pmksa_cache.h"
00028 #include "common/wpa_ctrl.h"
00029 #include "eap_peer/eap.h"
00030 #include "ap/hostapd.h"
00031 #include "notify.h"
00032 #include "common/ieee802_11_defs.h"
00033 #include "blacklist.h"
00034 #include "wpas_glue.h"
00035 #include "wps_supplicant.h"
00036 #include "ibss_rsn.h"
00037 #include "sme.h"
00038 #include "bgscan.h"
00039 #include "ap.h"
00040 #include "bss.h"
00041 #include "mlme.h"
00042 #include "scan.h"
00043 #include "../../src/nodes/wpa_supplicant_node.h"
00044 
00045 static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
00046 {
00047         struct wpa_ssid *ssid, *old_ssid;
00048 
00049         if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
00050                 return 0;
00051 
00052         wpa_printf(MSG_DEBUG, "Select network based on association "
00053                    "information");
00054         ssid = wpa_supplicant_get_ssid(wpa_s);
00055         if (ssid == NULL) {
00056                 wpa_printf(MSG_INFO, "No network configuration found for the "
00057                            "current AP");
00058                 return -1;
00059         }
00060 
00061         if (ssid->disabled) {
00062                 wpa_printf(MSG_DEBUG, "Selected network is disabled");
00063                 return -1;
00064         }
00065 
00066         wpa_printf(MSG_DEBUG, "Network configuration found for the current "
00067                    "AP");
00068         if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
00069                               WPA_KEY_MGMT_WPA_NONE |
00070                               WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X |
00071                               WPA_KEY_MGMT_PSK_SHA256 |
00072                               WPA_KEY_MGMT_IEEE8021X_SHA256)) {
00073                 u8 wpa_ie[80];
00074                 size_t wpa_ie_len = sizeof(wpa_ie);
00075                 wpa_supplicant_set_suites(wpa_s, NULL, ssid,
00076                                           wpa_ie, &wpa_ie_len);
00077         } else {
00078                 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
00079         }
00080 
00081         if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
00082                 eapol_sm_invalidate_cached_session(wpa_s->eapol);
00083         old_ssid = wpa_s->current_ssid;
00084         wpa_s->current_ssid = ssid;
00085         wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
00086         wpa_supplicant_initiate_eapol(wpa_s);
00087         if (old_ssid != wpa_s->current_ssid)
00088                 wpas_notify_network_changed(wpa_s);
00089 
00090         return 0;
00091 }
00092 
00093 
00094 static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
00095                                                 void *sock_ctx)
00096 {
00097         struct wpa_supplicant *wpa_s = eloop_ctx;
00098 
00099         if (wpa_s->countermeasures) {
00100                 wpa_s->countermeasures = 0;
00101                 wpa_drv_set_countermeasures(wpa_s, 0);
00102                 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
00103                 //wpa_supplicant_req_scan(wpa_s, 0, 0);
00104         }
00105 }
00106 
00107 
00108 void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
00109 {
00110         int bssid_changed;
00111 
00112         wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
00113         bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
00114         os_memset(wpa_s->bssid, 0, ETH_ALEN);
00115         os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
00116         wpa_s->current_bss = NULL;
00117         if (bssid_changed)
00118                 wpas_notify_bssid_changed(wpa_s);
00119 
00120         eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
00121         eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
00122         if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
00123                 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
00124         wpa_s->ap_ies_from_associnfo = 0;
00125 }
00126 
00127 
00128 static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
00129 {
00130         struct wpa_ie_data ie;
00131         int pmksa_set = -1;
00132         size_t i;
00133 
00134         if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
00135             ie.pmkid == NULL)
00136                 return;
00137 
00138         for (i = 0; i < ie.num_pmkid; i++) {
00139                 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
00140                                                     ie.pmkid + i * PMKID_LEN,
00141                                                     NULL, NULL, 0);
00142                 if (pmksa_set == 0) {
00143                         eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
00144                         break;
00145                 }
00146         }
00147 
00148         wpa_printf(MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from PMKSA "
00149                    "cache", pmksa_set == 0 ? "" : "not ");
00150 }
00151 
00152 
00153 static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
00154                                                  union wpa_event_data *data)
00155 {
00156         if (data == NULL) {
00157                 wpa_printf(MSG_DEBUG, "RSN: No data in PMKID candidate event");
00158                 return;
00159         }
00160         wpa_printf(MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
00161                    " index=%d preauth=%d",
00162                    MAC2STR(data->pmkid_candidate.bssid),
00163                    data->pmkid_candidate.index,
00164                    data->pmkid_candidate.preauth);
00165 
00166         pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
00167                             data->pmkid_candidate.index,
00168                             data->pmkid_candidate.preauth);
00169 }
00170 
00171 
00172 static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
00173 {
00174         if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
00175             wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
00176                 return 0;
00177 
00178 #ifdef IEEE8021X_EAPOL
00179         if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
00180             wpa_s->current_ssid &&
00181             !(wpa_s->current_ssid->eapol_flags &
00182               (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
00183                EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
00184                 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
00185                  * plaintext or static WEP keys). */
00186                 return 0;
00187         }
00188 #endif /* IEEE8021X_EAPOL */
00189 
00190         return 1;
00191 }
00192 
00193 
00203 int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
00204                               struct wpa_ssid *ssid)
00205 {
00206 #ifdef IEEE8021X_EAPOL
00207         int aka = 0, sim = 0, type;
00208 
00209         if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
00210                 return 0;
00211 
00212         if (ssid->eap.eap_methods == NULL) {
00213                 sim = 1;
00214                 aka = 1;
00215         } else {
00216                 struct eap_method_type *eap = ssid->eap.eap_methods;
00217                 while (eap->vendor != EAP_VENDOR_IETF ||
00218                        eap->method != EAP_TYPE_NONE) {
00219                         if (eap->vendor == EAP_VENDOR_IETF) {
00220                                 if (eap->method == EAP_TYPE_SIM)
00221                                         sim = 1;
00222                                 else if (eap->method == EAP_TYPE_AKA)
00223                                         aka = 1;
00224                         }
00225                         eap++;
00226                 }
00227         }
00228 
00229         if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
00230                 sim = 0;
00231         if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
00232                 aka = 0;
00233 
00234         if (!sim && !aka) {
00235                 wpa_printf(MSG_DEBUG, "Selected network is configured to use "
00236                            "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
00237                 return 0;
00238         }
00239 
00240         wpa_printf(MSG_DEBUG, "Selected network is configured to use SIM "
00241                    "(sim=%d aka=%d) - initialize PCSC", sim, aka);
00242         if (sim && aka)
00243                 type = SCARD_TRY_BOTH;
00244         else if (aka)
00245                 type = SCARD_USIM_ONLY;
00246         else
00247                 type = SCARD_GSM_SIM_ONLY;
00248 
00249         wpa_s->scard = scard_init(type);
00250         if (wpa_s->scard == NULL) {
00251                 wpa_printf(MSG_WARNING, "Failed to initialize SIM "
00252                            "(pcsc-lite)");
00253                 return -1;
00254         }
00255         wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
00256         eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
00257 #endif /* IEEE8021X_EAPOL */
00258 
00259         return 0;
00260 }
00261 
00262 
00263 #ifndef CONFIG_NO_SCAN_PROCESSING
00264 #if 0
00265 static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
00266                                         struct wpa_ssid *ssid)
00267 {
00268         int i, privacy = 0;
00269 
00270         if (ssid->mixed_cell)
00271                 return 1;
00272 
00273 #ifdef CONFIG_WPS
00274         if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
00275                 return 1;
00276 #endif /* CONFIG_WPS */
00277 
00278         for (i = 0; i < NUM_WEP_KEYS; i++) {
00279                 if (ssid->wep_key_len[i]) {
00280                         privacy = 1;
00281                         break;
00282                 }
00283         }
00284 #ifdef IEEE8021X_EAPOL
00285         if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
00286             ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
00287                                  EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
00288                 privacy = 1;
00289 #endif /* IEEE8021X_EAPOL */
00290 
00291         if (bss->caps & IEEE80211_CAP_PRIVACY)
00292                 return privacy;
00293         return !privacy;
00294 }
00295 #endif
00296 
00297 #if 0
00298 static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
00299                                          struct wpa_ssid *ssid,
00300                                          struct wpa_scan_res *bss)
00301 {
00302         struct wpa_ie_data ie;
00303         int proto_match = 0;
00304         const u8 *rsn_ie, *wpa_ie;
00305         int ret;
00306 
00307         ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
00308         if (ret >= 0)
00309                 return ret;
00310 
00311         rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
00312         while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
00313                 proto_match++;
00314 
00315                 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
00316                         wpa_printf(MSG_DEBUG, "   skip RSN IE - parse failed");
00317                         break;
00318                 }
00319                 if (!(ie.proto & ssid->proto)) {
00320                         wpa_printf(MSG_DEBUG, "   skip RSN IE - proto "
00321                                    "mismatch");
00322                         break;
00323                 }
00324 
00325                 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
00326                         wpa_printf(MSG_DEBUG, "   skip RSN IE - PTK cipher "
00327                                    "mismatch");
00328                         break;
00329                 }
00330 
00331                 if (!(ie.group_cipher & ssid->group_cipher)) {
00332                         wpa_printf(MSG_DEBUG, "   skip RSN IE - GTK cipher "
00333                                    "mismatch");
00334                         break;
00335                 }
00336 
00337                 if (!(ie.key_mgmt & ssid->key_mgmt)) {
00338                         wpa_printf(MSG_DEBUG, "   skip RSN IE - key mgmt "
00339                                    "mismatch");
00340                         break;
00341                 }
00342 
00343 #ifdef CONFIG_IEEE80211W
00344                 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
00345                     ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
00346                         wpa_printf(MSG_DEBUG, "   skip RSN IE - no mgmt frame "
00347                                    "protection");
00348                         break;
00349                 }
00350 #endif /* CONFIG_IEEE80211W */
00351 
00352                 wpa_printf(MSG_DEBUG, "   selected based on RSN IE");
00353                 return 1;
00354         }
00355 
00356         wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
00357         while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
00358                 proto_match++;
00359 
00360                 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
00361                         wpa_printf(MSG_DEBUG, "   skip WPA IE - parse failed");
00362                         break;
00363                 }
00364                 if (!(ie.proto & ssid->proto)) {
00365                         wpa_printf(MSG_DEBUG, "   skip WPA IE - proto "
00366                                    "mismatch");
00367                         break;
00368                 }
00369 
00370                 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
00371                         wpa_printf(MSG_DEBUG, "   skip WPA IE - PTK cipher "
00372                                    "mismatch");
00373                         break;
00374                 }
00375 
00376                 if (!(ie.group_cipher & ssid->group_cipher)) {
00377                         wpa_printf(MSG_DEBUG, "   skip WPA IE - GTK cipher "
00378                                    "mismatch");
00379                         break;
00380                 }
00381 
00382                 if (!(ie.key_mgmt & ssid->key_mgmt)) {
00383                         wpa_printf(MSG_DEBUG, "   skip WPA IE - key mgmt "
00384                                    "mismatch");
00385                         break;
00386                 }
00387 
00388                 wpa_printf(MSG_DEBUG, "   selected based on WPA IE");
00389                 return 1;
00390         }
00391 
00392         if (proto_match == 0)
00393                 wpa_printf(MSG_DEBUG, "   skip - no WPA/RSN proto match");
00394 
00395         return 0;
00396 }
00397 #endif
00398 
00399 #if 0
00400 static int freq_allowed(int *freqs, int freq)
00401 {
00402         int i;
00403 
00404         if (freqs == NULL)
00405                 return 1;
00406 
00407         for (i = 0; freqs[i]; i++)
00408                 if (freqs[i] == freq)
00409                         return 1;
00410         return 0;
00411 }
00412 #endif
00413 
00414 #if 0
00415 static struct wpa_bss *
00416 wpa_supplicant_select_bss_wpa(struct wpa_supplicant *wpa_s,
00417                               struct wpa_scan_results *scan_res,
00418                               struct wpa_ssid *group,
00419                               struct wpa_ssid **selected_ssid)
00420 {
00421         struct wpa_ssid *ssid;
00422         struct wpa_scan_res *bss;
00423         size_t i;
00424         struct wpa_blacklist *e;
00425         const u8 *ie;
00426 
00427         wpa_printf(MSG_DEBUG, "Try to find WPA-enabled AP");
00428         for (i = 0; i < scan_res->num; i++) {
00429                 const u8 *ssid_;
00430                 u8 wpa_ie_len, rsn_ie_len, ssid_len;
00431                 bss = scan_res->res[i];
00432 
00433                 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
00434                 ssid_ = ie ? ie + 2 : (u8 *) "";
00435                 ssid_len = ie ? ie[1] : 0;
00436 
00437                 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
00438                 wpa_ie_len = ie ? ie[1] : 0;
00439 
00440                 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
00441                 rsn_ie_len = ie ? ie[1] : 0;
00442 
00443                 wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
00444                            "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
00445                            (int) i, MAC2STR(bss->bssid),
00446                            wpa_ssid_txt(ssid_, ssid_len),
00447                            wpa_ie_len, rsn_ie_len, bss->caps);
00448 
00449                 e = wpa_blacklist_get(wpa_s, bss->bssid);
00450                 if (e && e->count > 1) {
00451                         wpa_printf(MSG_DEBUG, "   skip - blacklisted");
00452                         continue;
00453                 }
00454 
00455                 if (ssid_len == 0) {
00456                         wpa_printf(MSG_DEBUG, "   skip - SSID not known");
00457                         continue;
00458                 }
00459 
00460                 if (wpa_ie_len == 0 && rsn_ie_len == 0) {
00461                         wpa_printf(MSG_DEBUG, "   skip - no WPA/RSN IE");
00462                         continue;
00463                 }
00464 
00465                 for (ssid = group; ssid; ssid = ssid->pnext) {
00466                         int check_ssid = 1;
00467 
00468                         if (ssid->disabled) {
00469                                 wpa_printf(MSG_DEBUG, "   skip - disabled");
00470                                 continue;
00471                         }
00472 
00473 #ifdef CONFIG_WPS
00474                         if (ssid->ssid_len == 0 &&
00475                             wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
00476                                 check_ssid = 0;
00477 #endif /* CONFIG_WPS */
00478 
00479                         if (check_ssid &&
00480                             (ssid_len != ssid->ssid_len ||
00481                              os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
00482                                 wpa_printf(MSG_DEBUG, "   skip - "
00483                                            "SSID mismatch");
00484                                 continue;
00485                         }
00486 
00487                         if (ssid->bssid_set &&
00488                             os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
00489                         {
00490                                 wpa_printf(MSG_DEBUG, "   skip - "
00491                                            "BSSID mismatch");
00492                                 continue;
00493                         }
00494 
00495                         if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
00496                                 continue;
00497 
00498                         if (!freq_allowed(ssid->freq_list, bss->freq)) {
00499                                 wpa_printf(MSG_DEBUG, "   skip - "
00500                                            "frequency not allowed");
00501                                 continue;
00502                         }
00503 
00504                         wpa_printf(MSG_DEBUG, "   selected WPA AP "
00505                                    MACSTR " ssid='%s'",
00506                                    MAC2STR(bss->bssid),
00507                                    wpa_ssid_txt(ssid_, ssid_len));
00508                         *selected_ssid = ssid;
00509                         return wpa_bss_get(wpa_s, bss->bssid, ssid_, ssid_len);
00510                 }
00511         }
00512 
00513         return NULL;
00514 }
00515 #endif
00516 
00517 #if 0
00518 static struct wpa_bss *
00519 wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant *wpa_s,
00520                                   struct wpa_scan_results *scan_res,
00521                                   struct wpa_ssid *group,
00522                                   struct wpa_ssid **selected_ssid)
00523 {
00524         struct wpa_ssid *ssid;
00525         struct wpa_scan_res *bss;
00526         size_t i;
00527         struct wpa_blacklist *e;
00528         const u8 *ie;
00529 
00530         wpa_printf(MSG_DEBUG, "Try to find non-WPA AP");
00531         for (i = 0; i < scan_res->num; i++) {
00532                 const u8 *ssid_;
00533                 u8 wpa_ie_len, rsn_ie_len, ssid_len;
00534                 bss = scan_res->res[i];
00535 
00536                 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
00537                 ssid_ = ie ? ie + 2 : (u8 *) "";
00538                 ssid_len = ie ? ie[1] : 0;
00539 
00540                 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
00541                 wpa_ie_len = ie ? ie[1] : 0;
00542 
00543                 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
00544                 rsn_ie_len = ie ? ie[1] : 0;
00545 
00546                 wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
00547                            "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
00548                            (int) i, MAC2STR(bss->bssid),
00549                            wpa_ssid_txt(ssid_, ssid_len),
00550                            wpa_ie_len, rsn_ie_len, bss->caps);
00551 
00552                 e = wpa_blacklist_get(wpa_s, bss->bssid);
00553                 if (e && e->count > 1) {
00554                         wpa_printf(MSG_DEBUG, "   skip - blacklisted");
00555                         continue;
00556                 }
00557 
00558                 if (ssid_len == 0) {
00559                         wpa_printf(MSG_DEBUG, "   skip - SSID not known");
00560                         continue;
00561                 }
00562 
00563                 for (ssid = group; ssid; ssid = ssid->pnext) {
00564                         int check_ssid = ssid->ssid_len != 0;
00565 
00566                         if (ssid->disabled) {
00567                                 wpa_printf(MSG_DEBUG, "   skip - disabled");
00568                                 continue;
00569                         }
00570 
00571 #ifdef CONFIG_WPS
00572                         if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
00573                                 /* Only allow wildcard SSID match if an AP
00574                                  * advertises active WPS operation that matches
00575                                  * with our mode. */
00576                                 check_ssid = 1;
00577                                 if (ssid->ssid_len == 0 &&
00578                                     wpas_wps_ssid_wildcard_ok(wpa_s, ssid,
00579                                                               bss))
00580                                         check_ssid = 0;
00581                         }
00582 #endif /* CONFIG_WPS */
00583 
00584                         if (check_ssid &&
00585                             (ssid_len != ssid->ssid_len ||
00586                              os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
00587                                 wpa_printf(MSG_DEBUG, "   skip - "
00588                                            "SSID mismatch");
00589                                 continue;
00590                         }
00591 
00592                         if (ssid->bssid_set &&
00593                             os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
00594                         {
00595                                 wpa_printf(MSG_DEBUG, "   skip - "
00596                                            "BSSID mismatch");
00597                                 continue;
00598                         }
00599 
00600                         if (!(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
00601                             !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
00602                             !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA))
00603                         {
00604                                 wpa_printf(MSG_DEBUG, "   skip - "
00605                                            "non-WPA network not allowed");
00606                                 continue;
00607                         }
00608 
00609                         if ((ssid->key_mgmt &
00610                              (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK |
00611                               WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK |
00612                               WPA_KEY_MGMT_IEEE8021X_SHA256 |
00613                               WPA_KEY_MGMT_PSK_SHA256)) &&
00614                             (wpa_ie_len != 0 || rsn_ie_len != 0)) {
00615                                 wpa_printf(MSG_DEBUG, "   skip - "
00616                                            "WPA network");
00617                                 continue;
00618                         }
00619 
00620                         if (!wpa_supplicant_match_privacy(bss, ssid)) {
00621                                 wpa_printf(MSG_DEBUG, "   skip - "
00622                                            "privacy mismatch");
00623                                 continue;
00624                         }
00625 
00626                         if (bss->caps & IEEE80211_CAP_IBSS) {
00627                                 wpa_printf(MSG_DEBUG, "   skip - "
00628                                            "IBSS (adhoc) network");
00629                                 continue;
00630                         }
00631 
00632                         if (!freq_allowed(ssid->freq_list, bss->freq)) {
00633                                 wpa_printf(MSG_DEBUG, "   skip - "
00634                                            "frequency not allowed");
00635                                 continue;
00636                         }
00637 
00638                         wpa_printf(MSG_DEBUG, "   selected non-WPA AP "
00639                                    MACSTR " ssid='%s'",
00640                                    MAC2STR(bss->bssid),
00641                                    wpa_ssid_txt(ssid_, ssid_len));
00642                         *selected_ssid = ssid;
00643                         return wpa_bss_get(wpa_s, bss->bssid, ssid_, ssid_len);
00644                 }
00645         }
00646 
00647         return NULL;
00648 }
00649 #endif
00650 
00651 #if 0
00652 static struct wpa_bss *
00653 wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
00654                           struct wpa_scan_results *scan_res,
00655                           struct wpa_ssid *group,
00656                           struct wpa_ssid **selected_ssid)
00657 {
00658         struct wpa_bss *selected;
00659 
00660         wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d",
00661                    group->priority);
00662 
00663         /* First, try to find WPA-enabled AP */
00664         selected = wpa_supplicant_select_bss_wpa(wpa_s, scan_res, group,
00665                                                  selected_ssid);
00666         if (selected)
00667                 return selected;
00668 
00669         /* If no WPA-enabled AP found, try to find non-WPA AP, if configuration
00670          * allows this. */
00671         return wpa_supplicant_select_bss_non_wpa(wpa_s, scan_res, group,
00672                                                  selected_ssid);
00673 }
00674 #endif
00675 
00676 #if 0
00677 static struct wpa_bss *
00678 wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
00679                             struct wpa_scan_results *scan_res,
00680                             struct wpa_ssid **selected_ssid)
00681 {
00682         struct wpa_bss *selected = NULL;
00683         int prio;
00684 
00685         while (selected == NULL) {
00686                 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
00687                         selected = wpa_supplicant_select_bss(
00688                                 wpa_s, scan_res, wpa_s->conf->pssid[prio],
00689                                 selected_ssid);
00690                         if (selected)
00691                                 break;
00692                 }
00693 
00694                 if (selected == NULL && wpa_s->blacklist) {
00695                         wpa_printf(MSG_DEBUG, "No APs found - clear blacklist "
00696                                    "and try again");
00697                         wpa_blacklist_clear(wpa_s);
00698                         wpa_s->blacklist_cleared++;
00699                 } else if (selected == NULL)
00700                         break;
00701         }
00702 
00703         return selected;
00704 }
00705 #endif
00706 
00707 static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
00708                                         int timeout_sec, int timeout_usec)
00709 {
00710         if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1) {
00711                 /*
00712                  * Quick recovery if the initial scan results were not
00713                  * complete when fetched before the first scan request.
00714                  */
00715                 wpa_s->scan_res_tried++;
00716                 timeout_sec = 0;
00717                 timeout_usec = 0;
00718         } else if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
00719                 /*
00720                  * No networks are enabled; short-circuit request so
00721                  * we don't wait timeout seconds before transitioning
00722                  * to INACTIVE state.
00723                  */
00724                 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
00725                 return;
00726         }
00727         wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
00728 }
00729 
00730 
00731 void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
00732                             struct wpa_bss *selected,
00733                             struct wpa_ssid *ssid)
00734 {
00735         if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
00736                 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
00737                         "PBC session overlap");
00738                 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
00739                 return;
00740         }
00741 
00742         /*
00743          * Do not trigger new association unless the BSSID has changed or if
00744          * reassociation is requested. If we are in process of associating with
00745          * the selected BSSID, do not trigger new attempt.
00746          */
00747         if (wpa_s->reassociate ||
00748             (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
00749              (wpa_s->wpa_state != WPA_ASSOCIATING ||
00750               os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
00751               0))) {
00752                 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
00753                         wpa_supplicant_req_new_scan(wpa_s, 10, 0);
00754                         return;
00755                 }
00756                 wpa_supplicant_associate(wpa_s, selected, ssid);
00757         } else {
00758                 wpa_printf(MSG_DEBUG, "Already associated with the selected "
00759                            "AP");
00760         }
00761 }
00762 
00763 
00764 #if 0
00765 static struct wpa_ssid *
00766 wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
00767 {
00768         int prio;
00769         struct wpa_ssid *ssid;
00770 
00771         for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
00772                 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
00773                 {
00774                         if (ssid->disabled)
00775                                 continue;
00776                         if (ssid->mode == IEEE80211_MODE_IBSS ||
00777                             ssid->mode == IEEE80211_MODE_AP)
00778                                 return ssid;
00779                 }
00780         }
00781         return NULL;
00782 }
00783 #endif
00784 
00785 /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
00786  * on BSS added and BSS changed events */
00787 static void wpa_supplicant_rsn_preauth_scan_results(
00788         struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res)
00789 {
00790         int i;
00791 
00792         if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
00793                 return;
00794 
00795         for (i = scan_res->num - 1; i >= 0; i--) {
00796                 const u8 *ssid, *rsn;
00797                 struct wpa_scan_res *r;
00798 
00799                 r = scan_res->res[i];
00800 
00801                 ssid = wpa_scan_get_ie(r, WLAN_EID_SSID);
00802                 if (ssid == NULL)
00803                         continue;
00804 
00805                 rsn = wpa_scan_get_ie(r, WLAN_EID_RSN);
00806                 if (rsn == NULL)
00807                         continue;
00808 
00809                 rsn_preauth_scan_result(wpa_s->wpa, r->bssid, ssid, rsn);
00810         }
00811 
00812 }
00813 
00814 #if 0
00815 static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
00816                                        struct wpa_bss *selected,
00817                                        struct wpa_ssid *ssid,
00818                                        struct wpa_scan_results *scan_res)
00819 {
00820         size_t i;
00821         struct wpa_scan_res *current_bss = NULL;
00822         int min_diff;
00823 
00824         if (wpa_s->reassociate)
00825                 return 1; /* explicit request to reassociate */
00826         if (wpa_s->wpa_state < WPA_ASSOCIATED)
00827                 return 1; /* we are not associated; continue */
00828         if (wpa_s->current_ssid == NULL)
00829                 return 1; /* unknown current SSID */
00830         if (wpa_s->current_ssid != ssid)
00831                 return 1; /* different network block */
00832 
00833         for (i = 0; i < scan_res->num; i++) {
00834                 struct wpa_scan_res *res = scan_res->res[i];
00835                 const u8 *ie;
00836                 if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
00837                         continue;
00838 
00839                 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
00840                 if (ie == NULL)
00841                         continue;
00842                 if (ie[1] != wpa_s->current_ssid->ssid_len ||
00843                     os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
00844                         continue;
00845                 current_bss = res;
00846                 break;
00847         }
00848 
00849         if (!current_bss)
00850                 return 1; /* current BSS not seen in scan results */
00851 
00852         wpa_printf(MSG_DEBUG, "Considering within-ESS reassociation");
00853         wpa_printf(MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
00854                    MAC2STR(current_bss->bssid), current_bss->level);
00855         wpa_printf(MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
00856                    MAC2STR(selected->bssid), selected->level);
00857 
00858         if (wpa_s->current_ssid->bssid_set &&
00859             os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
00860             0) {
00861                 wpa_printf(MSG_DEBUG, "Allow reassociation - selected BSS has "
00862                            "preferred BSSID");
00863                 return 1;
00864         }
00865 
00866         min_diff = 2;
00867         if (current_bss->level < 0) {
00868                 if (current_bss->level < -85)
00869                         min_diff = 1;
00870                 else if (current_bss->level < -80)
00871                         min_diff = 2;
00872                 else if (current_bss->level < -75)
00873                         min_diff = 3;
00874                 else if (current_bss->level < -70)
00875                         min_diff = 4;
00876                 else
00877                         min_diff = 5;
00878         }
00879         if (abs(current_bss->level - selected->level) < min_diff) {
00880                 wpa_printf(MSG_DEBUG, "Skip roam - too small difference in "
00881                            "signal level");
00882                 return 0;
00883         }
00884 
00885         return 1;
00886 }
00887 #endif
00888 
00889 static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
00890                                               union wpa_event_data *data)
00891 {
00892         //struct wpa_bss *selected;
00893         //struct wpa_ssid *ssid = NULL;
00894         struct wpa_scan_results *scan_res;
00895 
00896         wpa_supplicant_notify_scanning(wpa_s, 0);
00897                 
00898         scan_res = wpa_supplicant_get_scan_results(wpa_s,
00899                                                    data ? &data->scan_info :
00900                                                    NULL, 1);
00901         
00902         ros_scan_completed(wpa_s, scan_res);
00903 
00904         if (scan_res == NULL) {
00905                 if (wpa_s->conf->ap_scan == 2)
00906                         return;
00907                 wpa_printf(MSG_DEBUG, "Failed to get scan results - don't bother try "
00908                            "scanning again");
00909                 //wpa_supplicant_req_new_scan(wpa_s, 1, 0);
00910                 return;
00911         }
00912 
00913         if (wpa_s->scan_res_handler) {
00914                 wpa_s->scan_res_handler(wpa_s, scan_res);
00915                 wpa_s->scan_res_handler = NULL;
00916                 wpa_scan_results_free(scan_res);
00917                 return;
00918         }
00919 
00920         /*
00921          * Don't post the results if this was the initial cached
00922          * and there were no results.
00923          */
00924         if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1 &&
00925             scan_res->num == 0) {
00926                 wpa_msg(wpa_s, MSG_DEBUG, "Cached scan results are "
00927                         "empty - not posting");
00928         } else {
00929                 wpa_printf(MSG_DEBUG, "New scan results available");
00930                 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
00931                 wpas_notify_scan_results(wpa_s);
00932         }
00933 
00934         wpas_notify_scan_done(wpa_s, 1);
00935 
00936         if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
00937                 wpa_scan_results_free(scan_res);
00938                 return;
00939         }
00940 
00941         if (wpa_s->disconnected) {
00942                 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
00943                 wpa_scan_results_free(scan_res);
00944                 return;
00945         }
00946 
00947         if (bgscan_notify_scan(wpa_s) == 1) {
00948                 wpa_scan_results_free(scan_res);
00949                 return;
00950         }
00951 
00952         wpa_supplicant_rsn_preauth_scan_results(wpa_s, scan_res);
00953 
00954         /*selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
00955 
00956         if (selected) {
00957                 int skip;
00958                 wpa_s->more_bss_to_try = 1;
00959                 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
00960                                                     scan_res);
00961                 wpa_scan_results_free(scan_res);
00962                 if (skip)
00963                         return;
00964                 wpa_supplicant_connect(wpa_s, selected, ssid);
00965         } else {
00966                 wpa_s->more_bss_to_try = 0;
00967                 wpa_scan_results_free(scan_res);
00968                 wpa_printf(MSG_DEBUG, "No suitable network found");
00969                 ssid = wpa_supplicant_pick_new_network(wpa_s);
00970                 if (ssid) {
00971                         wpa_printf(MSG_DEBUG, "Setup a new network");
00972                         wpa_supplicant_associate(wpa_s, NULL, ssid);
00973                 } else {
00974                         int timeout_sec = 1;
00975                         int timeout_usec = 0;
00976                         wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
00977                                                     timeout_usec);
00978                 }
00979         } */
00980 }
00981 #endif /* CONFIG_NO_SCAN_PROCESSING */
00982 
00983 
00984 static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
00985                                           union wpa_event_data *data)
00986 {
00987         int l, len, found = 0, wpa_found, rsn_found;
00988         const u8 *p;
00989 
00990         wpa_printf(MSG_DEBUG, "Association info event");
00991         if (data->assoc_info.req_ies)
00992                 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
00993                             data->assoc_info.req_ies_len);
00994         if (data->assoc_info.resp_ies)
00995                 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
00996                             data->assoc_info.resp_ies_len);
00997         if (data->assoc_info.beacon_ies)
00998                 wpa_hexdump(MSG_DEBUG, "beacon_ies",
00999                             data->assoc_info.beacon_ies,
01000                             data->assoc_info.beacon_ies_len);
01001         if (data->assoc_info.freq)
01002                 wpa_printf(MSG_DEBUG, "freq=%u MHz", data->assoc_info.freq);
01003 
01004         p = data->assoc_info.req_ies;
01005         l = data->assoc_info.req_ies_len;
01006 
01007         /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
01008         while (p && l >= 2) {
01009                 len = p[1] + 2;
01010                 if (len > l) {
01011                         wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
01012                                     p, l);
01013                         break;
01014                 }
01015                 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
01016                      (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
01017                     (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
01018                         if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
01019                                 break;
01020                         found = 1;
01021                         wpa_find_assoc_pmkid(wpa_s);
01022                         break;
01023                 }
01024                 l -= len;
01025                 p += len;
01026         }
01027         if (!found && data->assoc_info.req_ies)
01028                 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
01029 
01030 #ifdef CONFIG_IEEE80211R
01031 #ifdef CONFIG_SME
01032         if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
01033                 u8 bssid[ETH_ALEN];
01034                 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
01035                     wpa_ft_validate_reassoc_resp(wpa_s->wpa,
01036                                                  data->assoc_info.resp_ies,
01037                                                  data->assoc_info.resp_ies_len,
01038                                                  bssid) < 0) {
01039                         wpa_printf(MSG_DEBUG, "FT: Validation of "
01040                                    "Reassociation Response failed");
01041                         wpa_supplicant_deauthenticate(
01042                                 wpa_s, WLAN_REASON_INVALID_IE);
01043                         return -1;
01044                 }
01045         }
01046 
01047         p = data->assoc_info.resp_ies;
01048         l = data->assoc_info.resp_ies_len;
01049 
01050         /* Go through the IEs and make a copy of the MDIE, if present. */
01051         while (p && l >= 2) {
01052                 len = p[1] + 2;
01053                 if (len > l) {
01054                         wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
01055                                     p, l);
01056                         break;
01057                 }
01058                 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
01059                     p[1] >= MOBILITY_DOMAIN_ID_LEN) {
01060                         wpa_s->sme.ft_used = 1;
01061                         os_memcpy(wpa_s->sme.mobility_domain, p + 2,
01062                                   MOBILITY_DOMAIN_ID_LEN);
01063                         break;
01064                 }
01065                 l -= len;
01066                 p += len;
01067         }
01068 #endif /* CONFIG_SME */
01069 
01070         wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
01071                              data->assoc_info.resp_ies_len);
01072 #endif /* CONFIG_IEEE80211R */
01073 
01074         /* WPA/RSN IE from Beacon/ProbeResp */
01075         p = data->assoc_info.beacon_ies;
01076         l = data->assoc_info.beacon_ies_len;
01077 
01078         /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
01079          */
01080         wpa_found = rsn_found = 0;
01081         while (p && l >= 2) {
01082                 len = p[1] + 2;
01083                 if (len > l) {
01084                         wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
01085                                     p, l);
01086                         break;
01087                 }
01088                 if (!wpa_found &&
01089                     p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
01090                     os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
01091                         wpa_found = 1;
01092                         wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
01093                 }
01094 
01095                 if (!rsn_found &&
01096                     p[0] == WLAN_EID_RSN && p[1] >= 2) {
01097                         rsn_found = 1;
01098                         wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
01099                 }
01100 
01101                 l -= len;
01102                 p += len;
01103         }
01104 
01105         if (!wpa_found && data->assoc_info.beacon_ies)
01106                 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
01107         if (!rsn_found && data->assoc_info.beacon_ies)
01108                 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
01109         if (wpa_found || rsn_found)
01110                 wpa_s->ap_ies_from_associnfo = 1;
01111 
01112         wpa_s->assoc_freq = data->assoc_info.freq;
01113 
01114         return 0;
01115 }
01116 
01117 
01118 static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
01119                                        union wpa_event_data *data)
01120 {
01121         u8 bssid[ETH_ALEN];
01122         int ft_completed;
01123         int bssid_changed;
01124         struct wpa_driver_capa capa;
01125 
01126 #ifdef CONFIG_AP
01127         if (wpa_s->ap_iface) {
01128                 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
01129                                     data->assoc_info.addr,
01130                                     data->assoc_info.req_ies,
01131                                     data->assoc_info.req_ies_len);
01132                 return;
01133         }
01134 #endif /* CONFIG_AP */
01135 
01136         ft_completed = wpa_ft_is_completed(wpa_s->wpa);
01137         if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
01138                 return;
01139 
01140         wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
01141         if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
01142                 os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
01143         if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
01144             (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
01145              os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
01146                 wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
01147                         MACSTR, MAC2STR(bssid));
01148                 bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
01149                 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
01150                 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
01151                 if (bssid_changed)
01152                         wpas_notify_bssid_changed(wpa_s);
01153 
01154                 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
01155                         wpa_clear_keys(wpa_s, bssid);
01156                 }
01157                 if (wpa_supplicant_select_config(wpa_s) < 0) {
01158                         wpa_supplicant_disassociate(
01159                                 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
01160                         return;
01161                 }
01162                 if (wpa_s->current_ssid) {
01163                         struct wpa_bss *bss = NULL;
01164                         struct wpa_ssid *ssid = wpa_s->current_ssid;
01165                         if (ssid->ssid_len > 0)
01166                                 bss = wpa_bss_get(wpa_s, bssid,
01167                                                   ssid->ssid, ssid->ssid_len);
01168                         if (!bss)
01169                                 bss = wpa_bss_get_bssid(wpa_s, bssid);
01170                         if (bss)
01171                                 wpa_s->current_bss = bss;
01172                 }
01173         }
01174                         
01175 #ifdef CONFIG_SME
01176         os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
01177         wpa_s->sme.prev_bssid_set = 1;
01178         wpa_msg(wpa_s, MSG_INFO, "prev_bssid set");
01179 #endif /* CONFIG_SME */
01180 
01181         wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
01182         if (wpa_s->current_ssid) {
01183                 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
01184                  * initialized before association, but for other modes,
01185                  * initialize PC/SC here, if the current configuration needs
01186                  * smartcard or SIM/USIM. */
01187                 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
01188         }
01189         wpa_sm_notify_assoc(wpa_s->wpa, bssid);
01190         l2_packet_notify_auth_start(wpa_s->l2);
01191 
01192         /*
01193          * Set portEnabled first to FALSE in order to get EAP state machine out
01194          * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
01195          * state machine may transit to AUTHENTICATING state based on obsolete
01196          * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
01197          * AUTHENTICATED without ever giving chance to EAP state machine to
01198          * reset the state.
01199          */
01200         if (!ft_completed) {
01201                 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
01202                 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
01203         }
01204         if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
01205                 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
01206         /* 802.1X::portControl = Auto */
01207         eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
01208         wpa_s->eapol_received = 0;
01209         if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
01210             wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
01211             (wpa_s->current_ssid &&
01212              wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
01213                 wpa_supplicant_cancel_auth_timeout(wpa_s);
01214                 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
01215         } else if (!ft_completed) {
01216                 /* Timeout for receiving the first EAPOL packet */
01217                 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
01218         }
01219         wpa_supplicant_cancel_scan(wpa_s);
01220 
01221         if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
01222             wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
01223                 /*
01224                  * We are done; the driver will take care of RSN 4-way
01225                  * handshake.
01226                  */
01227                 wpa_supplicant_cancel_auth_timeout(wpa_s);
01228                 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
01229                 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
01230                 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
01231         }
01232 
01233         if (wpa_s->pending_eapol_rx) {
01234                 struct os_time now, age;
01235                 os_get_time(&now);
01236                 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
01237                 if (age.sec == 0 && age.usec < 100000 &&
01238                     os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
01239                     0) {
01240                         wpa_printf(MSG_DEBUG, "Process pending EAPOL frame "
01241                                    "that was received just before association "
01242                                    "notification");
01243                         wpa_supplicant_rx_eapol(
01244                                 wpa_s, wpa_s->pending_eapol_rx_src,
01245                                 wpabuf_head(wpa_s->pending_eapol_rx),
01246                                 wpabuf_len(wpa_s->pending_eapol_rx));
01247                 }
01248                 wpabuf_free(wpa_s->pending_eapol_rx);
01249                 wpa_s->pending_eapol_rx = NULL;
01250         }
01251 
01252 #ifdef CONFIG_BGSCAN
01253         if (wpa_s->current_ssid != wpa_s->bgscan_ssid) {
01254                 bgscan_deinit(wpa_s);
01255                 if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) {
01256                         if (bgscan_init(wpa_s, wpa_s->current_ssid)) {
01257                                 wpa_printf(MSG_DEBUG, "Failed to initialize "
01258                                            "bgscan");
01259                                 /*
01260                                  * Live without bgscan; it is only used as a
01261                                  * roaming optimization, so the initial
01262                                  * connection is not affected.
01263                                  */
01264                         } else
01265                                 wpa_s->bgscan_ssid = wpa_s->current_ssid;
01266                 } else
01267                         wpa_s->bgscan_ssid = NULL;
01268         }
01269 #endif /* CONFIG_BGSCAN */
01270 
01271         if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
01272              wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
01273             wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
01274             capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
01275                 /* Set static WEP keys again */
01276                 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
01277         }
01278 }
01279 
01280 
01281 static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
01282                                           u16 reason_code)
01283 {
01284         const u8 *bssid;
01285 #ifdef CONFIG_SME
01286         int authenticating;
01287         u8 prev_pending_bssid[ETH_ALEN];
01288 
01289         authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
01290         os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
01291 #endif /* CONFIG_SME */
01292 
01293         if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
01294                 /*
01295                  * At least Host AP driver and a Prism3 card seemed to be
01296                  * generating streams of disconnected events when configuring
01297                  * IBSS for WPA-None. Ignore them for now.
01298                  */
01299                 wpa_printf(MSG_DEBUG, "Disconnect event - ignore in "
01300                            "IBSS/WPA-None mode");
01301                 return;
01302         }
01303 
01304         if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
01305             wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
01306                 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
01307                         "pre-shared key may be incorrect");
01308         }
01309         //if (wpa_s->wpa_state >= WPA_ASSOCIATED)
01310         //      wpa_supplicant_req_scan(wpa_s, 0, 100000);
01311         bssid = wpa_s->bssid;
01312         if (is_zero_ether_addr(bssid))
01313                 bssid = wpa_s->pending_bssid;
01314         wpa_blacklist_add(wpa_s, bssid);
01315         wpa_sm_notify_disassoc(wpa_s->wpa);
01316         wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
01317                 " reason=%d",
01318                 MAC2STR(bssid), reason_code);
01319         if (wpa_supplicant_dynamic_keys(wpa_s)) {
01320                 wpa_printf(MSG_DEBUG, "Disconnect event - remove keys");
01321                 wpa_s->keys_cleared = 0;
01322                 wpa_clear_keys(wpa_s, wpa_s->bssid);
01323         }
01324         
01325         //ros_assoc_failed(wpa_s, bssid, "Disassociation event received");
01326 
01327         wpa_supplicant_mark_disassoc(wpa_s);
01328         bgscan_deinit(wpa_s);
01329 #ifdef CONFIG_SME
01330 //      if (authenticating &&
01331 //          (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
01332 //              /*
01333 //               * mac80211-workaround to force deauth on failed auth cmd,
01334 //               * requires us to remain in authenticating state to allow the
01335 //               * second authentication attempt to be continued properly.
01336 //               */
01337 //              wpa_printf(MSG_DEBUG, "SME: Allow pending authentication to "
01338 //                         "proceed after disconnection event");
01339 //              wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
01340 //              os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN);
01341 //      }
01342 #endif /* CONFIG_SME */
01343 }
01344 
01345 
01346 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
01347 static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
01348                                                     void *sock_ctx)
01349 {
01350         struct wpa_supplicant *wpa_s = eloop_ctx;
01351 
01352         if (!wpa_s->pending_mic_error_report)
01353                 return;
01354 
01355         wpa_printf(MSG_DEBUG, "WPA: Sending pending MIC error report");
01356         wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
01357         wpa_s->pending_mic_error_report = 0;
01358 }
01359 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
01360 
01361 
01362 static void
01363 wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
01364                                          union wpa_event_data *data)
01365 {
01366         int pairwise;
01367         struct os_time t;
01368 
01369         wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
01370         pairwise = (data && data->michael_mic_failure.unicast);
01371         os_get_time(&t);
01372         if ((wpa_s->last_michael_mic_error &&
01373              t.sec - wpa_s->last_michael_mic_error <= 60) ||
01374             wpa_s->pending_mic_error_report) {
01375                 if (wpa_s->pending_mic_error_report) {
01376                         /*
01377                          * Send the pending MIC error report immediately since
01378                          * we are going to start countermeasures and AP better
01379                          * do the same.
01380                          */
01381                         wpa_sm_key_request(wpa_s->wpa, 1,
01382                                            wpa_s->pending_mic_error_pairwise);
01383                 }
01384 
01385                 /* Send the new MIC error report immediately since we are going
01386                  * to start countermeasures and AP better do the same.
01387                  */
01388                 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
01389 
01390                 /* initialize countermeasures */
01391                 wpa_s->countermeasures = 1;
01392                 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
01393 
01394                 /*
01395                  * Need to wait for completion of request frame. We do not get
01396                  * any callback for the message completion, so just wait a
01397                  * short while and hope for the best. */
01398                 os_sleep(0, 10000);
01399 
01400                 wpa_drv_set_countermeasures(wpa_s, 1);
01401                 wpa_supplicant_deauthenticate(wpa_s,
01402                                               WLAN_REASON_MICHAEL_MIC_FAILURE);
01403                 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
01404                                      wpa_s, NULL);
01405                 eloop_register_timeout(60, 0,
01406                                        wpa_supplicant_stop_countermeasures,
01407                                        wpa_s, NULL);
01408                 /* TODO: mark the AP rejected for 60 second. STA is
01409                  * allowed to associate with another AP.. */
01410         } else {
01411 #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
01412                 if (wpa_s->mic_errors_seen) {
01413                         /*
01414                          * Reduce the effectiveness of Michael MIC error
01415                          * reports as a means for attacking against TKIP if
01416                          * more than one MIC failure is noticed with the same
01417                          * PTK. We delay the transmission of the reports by a
01418                          * random time between 0 and 60 seconds in order to
01419                          * force the attacker wait 60 seconds before getting
01420                          * the information on whether a frame resulted in a MIC
01421                          * failure.
01422                          */
01423                         u8 rval[4];
01424                         int sec;
01425 
01426                         if (os_get_random(rval, sizeof(rval)) < 0)
01427                                 sec = os_random() % 60;
01428                         else
01429                                 sec = WPA_GET_BE32(rval) % 60;
01430                         wpa_printf(MSG_DEBUG, "WPA: Delay MIC error report %d "
01431                                    "seconds", sec);
01432                         wpa_s->pending_mic_error_report = 1;
01433                         wpa_s->pending_mic_error_pairwise = pairwise;
01434                         eloop_cancel_timeout(
01435                                 wpa_supplicant_delayed_mic_error_report,
01436                                 wpa_s, NULL);
01437                         eloop_register_timeout(
01438                                 sec, os_random() % 1000000,
01439                                 wpa_supplicant_delayed_mic_error_report,
01440                                 wpa_s, NULL);
01441                 } else {
01442                         wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
01443                 }
01444 #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
01445                 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
01446 #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
01447         }
01448         wpa_s->last_michael_mic_error = t.sec;
01449         wpa_s->mic_errors_seen++;
01450 }
01451 
01452 
01453 #ifdef CONFIG_TERMINATE_ONLASTIF
01454 static int any_interfaces(struct wpa_supplicant *head)
01455 {
01456         struct wpa_supplicant *wpa_s;
01457 
01458         for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
01459                 if (!wpa_s->interface_removed)
01460                         return 1;
01461         return 0;
01462 }
01463 #endif /* CONFIG_TERMINATE_ONLASTIF */
01464 
01465 
01466 static void
01467 wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
01468                                       union wpa_event_data *data)
01469 {
01470         if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
01471                 return;
01472 
01473         switch (data->interface_status.ievent) {
01474         case EVENT_INTERFACE_ADDED:
01475                 if (!wpa_s->interface_removed)
01476                         break;
01477                 wpa_s->interface_removed = 0;
01478                 wpa_printf(MSG_DEBUG, "Configured interface was added.");
01479                 if (wpa_supplicant_driver_init(wpa_s) < 0) {
01480                         wpa_printf(MSG_INFO, "Failed to initialize the driver "
01481                                    "after interface was added.");
01482                 }
01483                 break;
01484         case EVENT_INTERFACE_REMOVED:
01485                 wpa_printf(MSG_DEBUG, "Configured interface was removed.");
01486                 wpa_s->interface_removed = 1;
01487                 wpa_supplicant_mark_disassoc(wpa_s);
01488                 l2_packet_deinit(wpa_s->l2);
01489                 wpa_s->l2 = NULL;
01490 #ifdef CONFIG_TERMINATE_ONLASTIF
01491                 /* check if last interface */
01492                 if (!any_interfaces(wpa_s->global->ifaces))
01493                         eloop_terminate();
01494 #endif /* CONFIG_TERMINATE_ONLASTIF */
01495                 break;
01496         }
01497 }
01498 
01499 
01500 #ifdef CONFIG_PEERKEY
01501 static void
01502 wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
01503                               union wpa_event_data *data)
01504 {
01505         if (data == NULL)
01506                 return;
01507         wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
01508 }
01509 #endif /* CONFIG_PEERKEY */
01510 
01511 
01512 #ifdef CONFIG_IEEE80211R
01513 static void
01514 wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
01515                                  union wpa_event_data *data)
01516 {
01517         if (data == NULL)
01518                 return;
01519 
01520         if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
01521                                     data->ft_ies.ies_len,
01522                                     data->ft_ies.ft_action,
01523                                     data->ft_ies.target_ap,
01524                                     data->ft_ies.ric_ies,
01525                                     data->ft_ies.ric_ies_len) < 0) {
01526                 /* TODO: prevent MLME/driver from trying to associate? */
01527         }
01528 }
01529 #endif /* CONFIG_IEEE80211R */
01530 
01531 
01532 #ifdef CONFIG_IBSS_RSN
01533 static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
01534                                                 union wpa_event_data *data)
01535 {
01536         if (data == NULL)
01537                 return;
01538         ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
01539 }
01540 #endif /* CONFIG_IBSS_RSN */
01541 
01542 
01543 #ifdef CONFIG_IEEE80211R
01544 static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
01545                          size_t len)
01546 {
01547         const u8 *sta_addr, *target_ap_addr;
01548         u16 status;
01549 
01550         wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
01551         if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
01552                 return; /* only SME case supported for now */
01553         if (len < 1 + 2 * ETH_ALEN + 2)
01554                 return;
01555         if (data[0] != 2)
01556                 return; /* Only FT Action Response is supported for now */
01557         sta_addr = data + 1;
01558         target_ap_addr = data + 1 + ETH_ALEN;
01559         status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
01560         wpa_printf(MSG_DEBUG, "FT: Received FT Action Response: STA " MACSTR
01561                    " TargetAP " MACSTR " status %u",
01562                    MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
01563 
01564         if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
01565                 wpa_printf(MSG_DEBUG, "FT: Foreign STA Address " MACSTR
01566                            " in FT Action Response", MAC2STR(sta_addr));
01567                 return;
01568         }
01569 
01570         if (status) {
01571                 wpa_printf(MSG_DEBUG, "FT: FT Action Response indicates "
01572                            "failure (status code %d)", status);
01573                 /* TODO: report error to FT code(?) */
01574                 return;
01575         }
01576 
01577         if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
01578                                     len - (1 + 2 * ETH_ALEN + 2), 1,
01579                                     target_ap_addr, NULL, 0) < 0)
01580                 return;
01581 
01582 #ifdef CONFIG_SME
01583         {
01584                 struct wpa_bss *bss;
01585                 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
01586                 if (bss)
01587                         wpa_s->sme.freq = bss->freq;
01588                 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
01589                 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
01590                               WLAN_AUTH_FT);
01591         }
01592 #endif /* CONFIG_SME */
01593 }
01594 #endif /* CONFIG_IEEE80211R */
01595 
01596 
01597 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
01598                           union wpa_event_data *data)
01599 {
01600         struct wpa_supplicant *wpa_s = ctx;
01601         u16 reason_code = 0;
01602         struct u8 *event_bssid;
01603 
01604         switch (event) {
01605         case EVENT_AUTH:
01606                 sme_event_auth(wpa_s, data);
01607                 break;
01608         case EVENT_ASSOC:
01609                 wpa_supplicant_event_assoc(wpa_s, data);
01610                 break;
01611         case EVENT_DISASSOC:
01612                 wpa_printf(MSG_DEBUG, "Disassociation notification");
01613 #ifdef CONFIG_AP
01614                 if (wpa_s->ap_iface && data) {
01615                         hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
01616                                                data->disassoc_info.addr);
01617                         break;
01618                 }
01619 #endif /* CONFIG_AP */
01620                 if (data) {
01621                   reason_code = data->disassoc_info.reason_code;
01622                   event_bssid = data->disassoc_info.addr;
01623                 }
01624                 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
01625                         sme_event_disassoc(wpa_s, data);
01626                 /* fall through */
01627         case EVENT_DEAUTH:
01628                 if (event == EVENT_DEAUTH) {
01629                         wpa_printf(MSG_DEBUG, "Deauthentication notification");
01630                         if (data) {
01631                                 reason_code = data->deauth_info.reason_code;
01632                                 event_bssid = data->deauth_info.addr;
01633                         }
01634                 }
01635                 if (wpa_s->current_bss && event_bssid && os_memcmp(wpa_s->current_bss->bssid, event_bssid, ETH_ALEN))
01636                   break; // A new association is in progress. This event refers to an old association.
01637 #ifdef CONFIG_AP
01638                 if (wpa_s->ap_iface && data) {
01639                         hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
01640                                                data->deauth_info.addr);
01641                         break;
01642                 }
01643 #endif /* CONFIG_AP */
01644                 wpa_supplicant_event_disassoc(wpa_s, reason_code);
01645                 break;
01646         case EVENT_MICHAEL_MIC_FAILURE:
01647                 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
01648                 break;
01649 #ifndef CONFIG_NO_SCAN_PROCESSING
01650         case EVENT_SCAN_RESULTS:
01651                 wpa_supplicant_event_scan_results(wpa_s, data);
01652                 break;
01653 #endif /* CONFIG_NO_SCAN_PROCESSING */
01654         case EVENT_ASSOCINFO:
01655                 wpa_supplicant_event_associnfo(wpa_s, data);
01656                 break;
01657         case EVENT_INTERFACE_STATUS:
01658                 wpa_supplicant_event_interface_status(wpa_s, data);
01659                 break;
01660         case EVENT_PMKID_CANDIDATE:
01661                 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
01662                 break;
01663 #ifdef CONFIG_PEERKEY
01664         case EVENT_STKSTART:
01665                 wpa_supplicant_event_stkstart(wpa_s, data);
01666                 break;
01667 #endif /* CONFIG_PEERKEY */
01668 #ifdef CONFIG_IEEE80211R
01669         case EVENT_FT_RESPONSE:
01670                 wpa_supplicant_event_ft_response(wpa_s, data);
01671                 break;
01672 #endif /* CONFIG_IEEE80211R */
01673 #ifdef CONFIG_IBSS_RSN
01674         case EVENT_IBSS_RSN_START:
01675                 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
01676                 break;
01677 #endif /* CONFIG_IBSS_RSN */
01678         case EVENT_ASSOC_REJECT:
01679                 sme_event_assoc_reject(wpa_s, data);
01680                 break;
01681         case EVENT_AUTH_TIMED_OUT:
01682                 sme_event_auth_timed_out(wpa_s, data);
01683                 break;
01684         case EVENT_ASSOC_TIMED_OUT:
01685                 sme_event_assoc_timed_out(wpa_s, data);
01686                 break;
01687 #ifdef CONFIG_AP
01688         case EVENT_TX_STATUS:
01689                 if (wpa_s->ap_iface == NULL)
01690                         break;
01691                 switch (data->tx_status.type) {
01692                 case WLAN_FC_TYPE_MGMT:
01693                         ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
01694                                       data->tx_status.data_len,
01695                                       data->tx_status.stype,
01696                                       data->tx_status.ack);
01697                         break;
01698                 case WLAN_FC_TYPE_DATA:
01699                         ap_tx_status(wpa_s, data->tx_status.dst,
01700                                      data->tx_status.data,
01701                                      data->tx_status.data_len,
01702                                      data->tx_status.ack);
01703                         break;
01704                 }
01705                 break;
01706         case EVENT_RX_FROM_UNKNOWN:
01707                 if (wpa_s->ap_iface == NULL)
01708                         break;
01709                 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
01710                                        data->rx_from_unknown.len);
01711                 break;
01712         case EVENT_RX_MGMT:
01713                 if (wpa_s->ap_iface == NULL)
01714                         break;
01715                 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
01716                 break;
01717 #endif /* CONFIG_AP */
01718         case EVENT_RX_ACTION:
01719                 wpa_printf(MSG_DEBUG, "Received Action frame: SA=" MACSTR
01720                            " Category=%u DataLen=%d freq=%d MHz",
01721                            MAC2STR(data->rx_action.sa),
01722                            data->rx_action.category, (int) data->rx_action.len,
01723                            data->rx_action.freq);
01724 #ifdef CONFIG_IEEE80211R
01725                 if (data->rx_action.category == WLAN_ACTION_FT) {
01726                         ft_rx_action(wpa_s, data->rx_action.data,
01727                                      data->rx_action.len);
01728                         break;
01729                 }
01730 #endif /* CONFIG_IEEE80211R */
01731                 break;
01732 #ifdef CONFIG_CLIENT_MLME
01733         case EVENT_MLME_RX: {
01734                 struct ieee80211_rx_status rx_status;
01735                 os_memset(&rx_status, 0, sizeof(rx_status));
01736                 rx_status.freq = data->mlme_rx.freq;
01737                 rx_status.channel = data->mlme_rx.channel;
01738                 rx_status.ssi = data->mlme_rx.ssi;
01739                 ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
01740                                  &rx_status);
01741                 break;
01742         }
01743 #endif /* CONFIG_CLIENT_MLME */
01744         case EVENT_EAPOL_RX:
01745                 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
01746                                         data->eapol_rx.data,
01747                                         data->eapol_rx.data_len);
01748                 break;
01749         case EVENT_SIGNAL_CHANGE:
01750                 bgscan_notify_signal_change(
01751                         wpa_s, data->signal_change.above_threshold);
01752                 break;
01753         default:
01754                 wpa_printf(MSG_INFO, "Unknown event %d", event);
01755                 break;
01756         }
01757 }


wpa_supplicant_node
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Jan 2 2014 11:25:14