blob: c03dcc25ed0c318bd8fbb6fdbe7a87c83afeeea0 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "pcsc_funcs.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "common/wpa_ctrl.h"
23#include "eap_peer/eap.h"
24#include "ap/hostapd.h"
25#include "p2p/p2p.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070026#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "notify.h"
28#include "common/ieee802_11_defs.h"
29#include "common/ieee802_11_common.h"
30#include "crypto/random.h"
31#include "blacklist.h"
32#include "wpas_glue.h"
33#include "wps_supplicant.h"
34#include "ibss_rsn.h"
35#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080036#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037#include "p2p_supplicant.h"
38#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070039#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040#include "ap.h"
41#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080043#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070044#include "interworking.h"
45
46
Dmitry Shmidt34af3062013-07-11 10:46:32 -070047#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070048static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080049 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070050#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080051
52
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070053static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
54 struct wpa_ssid *ssid)
55{
56 struct os_time now;
57
58 if (ssid == NULL || ssid->disabled_until.sec == 0)
59 return 0;
60
61 os_get_time(&now);
62 if (ssid->disabled_until.sec > now.sec)
63 return ssid->disabled_until.sec - now.sec;
64
65 wpas_clear_temp_disabled(wpa_s, ssid, 0);
66
67 return 0;
68}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069
70
71static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
72{
73 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070074 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070075
76 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
77 return 0;
78
79 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
80 "information");
81 ssid = wpa_supplicant_get_ssid(wpa_s);
82 if (ssid == NULL) {
83 wpa_msg(wpa_s, MSG_INFO,
84 "No network configuration found for the current AP");
85 return -1;
86 }
87
Dmitry Shmidt04949592012-07-19 12:16:46 -070088 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
90 return -1;
91 }
92
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080093 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
94 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
95 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
96 return -1;
97 }
98
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070099 res = wpas_temp_disabled(wpa_s, ssid);
100 if (res > 0) {
101 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
102 "disabled for %d second(s)", res);
103 return -1;
104 }
105
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700106 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
107 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800108 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109 u8 wpa_ie[80];
110 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800111 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
112 wpa_ie, &wpa_ie_len) < 0)
113 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 } else {
115 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
116 }
117
118 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
119 eapol_sm_invalidate_cached_session(wpa_s->eapol);
120 old_ssid = wpa_s->current_ssid;
121 wpa_s->current_ssid = ssid;
122 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
123 wpa_supplicant_initiate_eapol(wpa_s);
124 if (old_ssid != wpa_s->current_ssid)
125 wpas_notify_network_changed(wpa_s);
126
127 return 0;
128}
129
130
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800131void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700132{
133 struct wpa_supplicant *wpa_s = eloop_ctx;
134
135 if (wpa_s->countermeasures) {
136 wpa_s->countermeasures = 0;
137 wpa_drv_set_countermeasures(wpa_s, 0);
138 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
139 wpa_supplicant_req_scan(wpa_s, 0, 0);
140 }
141}
142
143
144void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
145{
146 int bssid_changed;
147
Dmitry Shmidt04949592012-07-19 12:16:46 -0700148 wnm_bss_keep_alive_deinit(wpa_s);
149
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150#ifdef CONFIG_IBSS_RSN
151 ibss_rsn_deinit(wpa_s->ibss_rsn);
152 wpa_s->ibss_rsn = NULL;
153#endif /* CONFIG_IBSS_RSN */
154
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700155#ifdef CONFIG_AP
156 wpa_supplicant_ap_deinit(wpa_s);
157#endif /* CONFIG_AP */
158
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
160 return;
161
162 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
163 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
164 os_memset(wpa_s->bssid, 0, ETH_ALEN);
165 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700166#ifdef CONFIG_SME
167 wpa_s->sme.prev_bssid_set = 0;
168#endif /* CONFIG_SME */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800169#ifdef CONFIG_P2P
170 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
171#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700172 wpa_s->current_bss = NULL;
173 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700174#ifdef CONFIG_IEEE80211R
175#ifdef CONFIG_SME
176 if (wpa_s->sme.ft_ies)
177 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
178#endif /* CONFIG_SME */
179#endif /* CONFIG_IEEE80211R */
180
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181 if (bssid_changed)
182 wpas_notify_bssid_changed(wpa_s);
183
184 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
185 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
186 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
187 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
188 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700189 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700190 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700191 wpa_s->key_mgmt = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192}
193
194
195static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
196{
197 struct wpa_ie_data ie;
198 int pmksa_set = -1;
199 size_t i;
200
201 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
202 ie.pmkid == NULL)
203 return;
204
205 for (i = 0; i < ie.num_pmkid; i++) {
206 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
207 ie.pmkid + i * PMKID_LEN,
208 NULL, NULL, 0);
209 if (pmksa_set == 0) {
210 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
211 break;
212 }
213 }
214
215 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
216 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
217}
218
219
220static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
221 union wpa_event_data *data)
222{
223 if (data == NULL) {
224 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
225 "event");
226 return;
227 }
228 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
229 " index=%d preauth=%d",
230 MAC2STR(data->pmkid_candidate.bssid),
231 data->pmkid_candidate.index,
232 data->pmkid_candidate.preauth);
233
234 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
235 data->pmkid_candidate.index,
236 data->pmkid_candidate.preauth);
237}
238
239
240static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
241{
242 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
243 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
244 return 0;
245
246#ifdef IEEE8021X_EAPOL
247 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
248 wpa_s->current_ssid &&
249 !(wpa_s->current_ssid->eapol_flags &
250 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
251 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
252 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
253 * plaintext or static WEP keys). */
254 return 0;
255 }
256#endif /* IEEE8021X_EAPOL */
257
258 return 1;
259}
260
261
262/**
263 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
264 * @wpa_s: pointer to wpa_supplicant data
265 * @ssid: Configuration data for the network
266 * Returns: 0 on success, -1 on failure
267 *
268 * This function is called when starting authentication with a network that is
269 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
270 */
271int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
272 struct wpa_ssid *ssid)
273{
274#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800275#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700276 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700277
Dmitry Shmidt051af732013-10-22 13:52:46 -0700278 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL ||
279 wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280 return 0;
281
282 if (ssid->eap.eap_methods == NULL) {
283 sim = 1;
284 aka = 1;
285 } else {
286 struct eap_method_type *eap = ssid->eap.eap_methods;
287 while (eap->vendor != EAP_VENDOR_IETF ||
288 eap->method != EAP_TYPE_NONE) {
289 if (eap->vendor == EAP_VENDOR_IETF) {
290 if (eap->method == EAP_TYPE_SIM)
291 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700292 else if (eap->method == EAP_TYPE_AKA ||
293 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700294 aka = 1;
295 }
296 eap++;
297 }
298 }
299
300 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
301 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700302 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
303 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
304 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700305 aka = 0;
306
307 if (!sim && !aka) {
308 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
309 "use SIM, but neither EAP-SIM nor EAP-AKA are "
310 "enabled");
311 return 0;
312 }
313
314 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
315 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800317 wpa_s->scard = scard_init(NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700318 if (wpa_s->scard == NULL) {
319 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
320 "(pcsc-lite)");
321 return -1;
322 }
323 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
324 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800325#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700326#endif /* IEEE8021X_EAPOL */
327
328 return 0;
329}
330
331
332#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700333
334static int has_wep_key(struct wpa_ssid *ssid)
335{
336 int i;
337
338 for (i = 0; i < NUM_WEP_KEYS; i++) {
339 if (ssid->wep_key_len[i])
340 return 1;
341 }
342
343 return 0;
344}
345
346
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700347static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700348 struct wpa_ssid *ssid)
349{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700350 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700351
352 if (ssid->mixed_cell)
353 return 1;
354
355#ifdef CONFIG_WPS
356 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
357 return 1;
358#endif /* CONFIG_WPS */
359
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700360 if (has_wep_key(ssid))
361 privacy = 1;
362
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363#ifdef IEEE8021X_EAPOL
364 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
365 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
366 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
367 privacy = 1;
368#endif /* IEEE8021X_EAPOL */
369
Jouni Malinen75ecf522011-06-27 15:19:46 -0700370 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
371 privacy = 1;
372
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700373 if (bss->caps & IEEE80211_CAP_PRIVACY)
374 return privacy;
375 return !privacy;
376}
377
378
379static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
380 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700381 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700382{
383 struct wpa_ie_data ie;
384 int proto_match = 0;
385 const u8 *rsn_ie, *wpa_ie;
386 int ret;
387 int wep_ok;
388
389 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
390 if (ret >= 0)
391 return ret;
392
393 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
394 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
395 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
396 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
397 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
398
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700399 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700400 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
401 proto_match++;
402
403 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
404 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
405 "failed");
406 break;
407 }
408
409 if (wep_ok &&
410 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
411 {
412 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
413 "in RSN IE");
414 return 1;
415 }
416
417 if (!(ie.proto & ssid->proto)) {
418 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
419 "mismatch");
420 break;
421 }
422
423 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
424 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
425 "cipher mismatch");
426 break;
427 }
428
429 if (!(ie.group_cipher & ssid->group_cipher)) {
430 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
431 "cipher mismatch");
432 break;
433 }
434
435 if (!(ie.key_mgmt & ssid->key_mgmt)) {
436 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
437 "mismatch");
438 break;
439 }
440
441#ifdef CONFIG_IEEE80211W
442 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800443 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
444 wpa_s->conf->pmf : ssid->ieee80211w) ==
445 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
447 "frame protection");
448 break;
449 }
450#endif /* CONFIG_IEEE80211W */
451
452 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
453 return 1;
454 }
455
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700456 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
458 proto_match++;
459
460 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
461 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
462 "failed");
463 break;
464 }
465
466 if (wep_ok &&
467 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
468 {
469 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
470 "in WPA IE");
471 return 1;
472 }
473
474 if (!(ie.proto & ssid->proto)) {
475 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
476 "mismatch");
477 break;
478 }
479
480 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
481 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
482 "cipher mismatch");
483 break;
484 }
485
486 if (!(ie.group_cipher & ssid->group_cipher)) {
487 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
488 "cipher mismatch");
489 break;
490 }
491
492 if (!(ie.key_mgmt & ssid->key_mgmt)) {
493 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
494 "mismatch");
495 break;
496 }
497
498 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
499 return 1;
500 }
501
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700502 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
503 !rsn_ie) {
504 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
505 return 1;
506 }
507
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700508 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
509 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
510 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
511 return 0;
512 }
513
514 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
515 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
516 return 1;
517 }
518
519 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
520 "WPA/WPA2");
521
522 return 0;
523}
524
525
526static int freq_allowed(int *freqs, int freq)
527{
528 int i;
529
530 if (freqs == NULL)
531 return 1;
532
533 for (i = 0; freqs[i]; i++)
534 if (freqs[i] == freq)
535 return 1;
536 return 0;
537}
538
539
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800540static int ht_supported(const struct hostapd_hw_modes *mode)
541{
542 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
543 /*
544 * The driver did not indicate whether it supports HT. Assume
545 * it does to avoid connection issues.
546 */
547 return 1;
548 }
549
550 /*
551 * IEEE Std 802.11n-2009 20.1.1:
552 * An HT non-AP STA shall support all EQM rates for one spatial stream.
553 */
554 return mode->mcs_set[0] == 0xff;
555}
556
557
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700558static int vht_supported(const struct hostapd_hw_modes *mode)
559{
560 if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) {
561 /*
562 * The driver did not indicate whether it supports VHT. Assume
563 * it does to avoid connection issues.
564 */
565 return 1;
566 }
567
568 /*
569 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
570 * TODO: Verify if this complies with the standard
571 */
572 return (mode->vht_mcs_set[0] & 0x3) != 3;
573}
574
575
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700576static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800577{
578 const struct hostapd_hw_modes *mode = NULL, *modes;
579 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
580 const u8 *rate_ie;
581 int i, j, k;
582
583 if (bss->freq == 0)
584 return 1; /* Cannot do matching without knowing band */
585
586 modes = wpa_s->hw.modes;
587 if (modes == NULL) {
588 /*
589 * The driver does not provide any additional information
590 * about the utilized hardware, so allow the connection attempt
591 * to continue.
592 */
593 return 1;
594 }
595
596 for (i = 0; i < wpa_s->hw.num_modes; i++) {
597 for (j = 0; j < modes[i].num_channels; j++) {
598 int freq = modes[i].channels[j].freq;
599 if (freq == bss->freq) {
600 if (mode &&
601 mode->mode == HOSTAPD_MODE_IEEE80211G)
602 break; /* do not allow 802.11b replace
603 * 802.11g */
604 mode = &modes[i];
605 break;
606 }
607 }
608 }
609
610 if (mode == NULL)
611 return 0;
612
613 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700614 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800615 if (rate_ie == NULL)
616 continue;
617
618 for (j = 2; j < rate_ie[1] + 2; j++) {
619 int flagged = !!(rate_ie[j] & 0x80);
620 int r = (rate_ie[j] & 0x7f) * 5;
621
622 /*
623 * IEEE Std 802.11n-2009 7.3.2.2:
624 * The new BSS Membership selector value is encoded
625 * like a legacy basic rate, but it is not a rate and
626 * only indicates if the BSS members are required to
627 * support the mandatory features of Clause 20 [HT PHY]
628 * in order to join the BSS.
629 */
630 if (flagged && ((rate_ie[j] & 0x7f) ==
631 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
632 if (!ht_supported(mode)) {
633 wpa_dbg(wpa_s, MSG_DEBUG,
634 " hardware does not support "
635 "HT PHY");
636 return 0;
637 }
638 continue;
639 }
640
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700641 /* There's also a VHT selector for 802.11ac */
642 if (flagged && ((rate_ie[j] & 0x7f) ==
643 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
644 if (!vht_supported(mode)) {
645 wpa_dbg(wpa_s, MSG_DEBUG,
646 " hardware does not support "
647 "VHT PHY");
648 return 0;
649 }
650 continue;
651 }
652
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800653 if (!flagged)
654 continue;
655
656 /* check for legacy basic rates */
657 for (k = 0; k < mode->num_rates; k++) {
658 if (mode->rates[k] == r)
659 break;
660 }
661 if (k == mode->num_rates) {
662 /*
663 * IEEE Std 802.11-2007 7.3.2.2 demands that in
664 * order to join a BSS all required rates
665 * have to be supported by the hardware.
666 */
667 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
668 "not support required rate %d.%d Mbps",
669 r / 10, r % 10);
670 return 0;
671 }
672 }
673 }
674
675 return 1;
676}
677
678
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800679static int bss_is_dmg(struct wpa_bss *bss)
680{
681 return bss->freq > 45000;
682}
683
684
685/*
686 * Test whether BSS is in an ESS.
687 * This is done differently in DMG (60 GHz) and non-DMG bands
688 */
689static int bss_is_ess(struct wpa_bss *bss)
690{
691 if (bss_is_dmg(bss)) {
692 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
693 IEEE80211_CAP_DMG_AP;
694 }
695
696 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
697 IEEE80211_CAP_ESS);
698}
699
700
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700702 int i, struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700703 struct wpa_ssid *group)
704{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700705 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 int wpa;
707 struct wpa_blacklist *e;
708 const u8 *ie;
709 struct wpa_ssid *ssid;
710
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700711 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700712 wpa_ie_len = ie ? ie[1] : 0;
713
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700714 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700715 rsn_ie_len = ie ? ie[1] : 0;
716
717 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
Dmitry Shmidt96571392013-10-14 12:54:46 -0700718 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700719 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700720 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
Dmitry Shmidt96571392013-10-14 12:54:46 -0700721 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
722 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
723 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
724 " p2p" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725
726 e = wpa_blacklist_get(wpa_s, bss->bssid);
727 if (e) {
728 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700729 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 /*
731 * When only a single network is enabled, we can
732 * trigger blacklisting on the first failure. This
733 * should not be done with multiple enabled networks to
734 * avoid getting forced to move into a worse ESS on
735 * single error if there are no other BSSes of the
736 * current ESS.
737 */
738 limit = 0;
739 }
740 if (e->count > limit) {
741 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
742 "(count=%d limit=%d)", e->count, limit);
743 return NULL;
744 }
745 }
746
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700747 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700748 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
749 return NULL;
750 }
751
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800752 if (disallowed_bssid(wpa_s, bss->bssid)) {
753 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
754 return NULL;
755 }
756
757 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
758 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
759 return NULL;
760 }
761
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
763
764 for (ssid = group; ssid; ssid = ssid->pnext) {
765 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700766 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767
Dmitry Shmidt04949592012-07-19 12:16:46 -0700768 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
770 continue;
771 }
772
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700773 res = wpas_temp_disabled(wpa_s, ssid);
774 if (res > 0) {
775 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
776 "temporarily for %d second(s)", res);
777 continue;
778 }
779
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780#ifdef CONFIG_WPS
781 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
782 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
783 "(WPS)");
784 continue;
785 }
786
787 if (wpa && ssid->ssid_len == 0 &&
788 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
789 check_ssid = 0;
790
791 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
792 /* Only allow wildcard SSID match if an AP
793 * advertises active WPS operation that matches
794 * with our mode. */
795 check_ssid = 1;
796 if (ssid->ssid_len == 0 &&
797 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
798 check_ssid = 0;
799 }
800#endif /* CONFIG_WPS */
801
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800802 if (ssid->bssid_set && ssid->ssid_len == 0 &&
803 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
804 check_ssid = 0;
805
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700806 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700807 (bss->ssid_len != ssid->ssid_len ||
808 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
810 continue;
811 }
812
813 if (ssid->bssid_set &&
814 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
815 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
816 continue;
817 }
818
819 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
820 continue;
821
822 if (!wpa &&
823 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
824 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
825 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
826 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
827 "not allowed");
828 continue;
829 }
830
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700831 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
832 has_wep_key(ssid)) {
833 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
834 continue;
835 }
836
Jouni Malinen75ecf522011-06-27 15:19:46 -0700837 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
839 "mismatch");
840 continue;
841 }
842
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800843 if (!bss_is_ess(bss)) {
844 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 continue;
846 }
847
848 if (!freq_allowed(ssid->freq_list, bss->freq)) {
849 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
850 "allowed");
851 continue;
852 }
853
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800854 if (!rate_match(wpa_s, bss)) {
855 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
856 "not match");
857 continue;
858 }
859
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700860#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -0700861 if (ssid->p2p_group &&
862 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
863 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
864 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
865 continue;
866 }
867
Dmitry Shmidt54605472013-11-08 11:10:19 -0800868 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
869 struct wpabuf *p2p_ie;
870 u8 dev_addr[ETH_ALEN];
871
872 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
873 if (ie == NULL) {
874 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
875 continue;
876 }
877 p2p_ie = wpa_bss_get_vendor_ie_multi(
878 bss, P2P_IE_VENDOR_TYPE);
879 if (p2p_ie == NULL) {
880 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
881 continue;
882 }
883
884 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
885 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
886 ETH_ALEN) != 0) {
887 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
888 wpabuf_free(p2p_ie);
889 continue;
890 }
891 wpabuf_free(p2p_ie);
892 }
893
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894 /*
895 * TODO: skip the AP if its P2P IE has Group Formation
896 * bit set in the P2P Group Capability Bitmap and we
897 * are not in Group Formation with that device.
898 */
899#endif /* CONFIG_P2P */
900
901 /* Matching configuration found */
902 return ssid;
903 }
904
905 /* No matching configuration found */
906 return NULL;
907}
908
909
910static struct wpa_bss *
911wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700912 struct wpa_ssid *group,
913 struct wpa_ssid **selected_ssid)
914{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700915 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700916
917 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
918 group->priority);
919
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700920 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
921 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700922 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
923 if (!*selected_ssid)
924 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700925 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
926 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700927 MAC2STR(bss->bssid),
928 wpa_ssid_txt(bss->ssid, bss->ssid_len));
929 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700930 }
931
932 return NULL;
933}
934
935
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700936struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
937 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700938{
939 struct wpa_bss *selected = NULL;
940 int prio;
941
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700942 if (wpa_s->last_scan_res == NULL ||
943 wpa_s->last_scan_res_used == 0)
944 return NULL; /* no scan results from last update */
945
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700946 while (selected == NULL) {
947 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
948 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700949 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700950 selected_ssid);
951 if (selected)
952 break;
953 }
954
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800955 if (selected == NULL && wpa_s->blacklist &&
956 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700957 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
958 "blacklist and try again");
959 wpa_blacklist_clear(wpa_s);
960 wpa_s->blacklist_cleared++;
961 } else if (selected == NULL)
962 break;
963 }
964
965 return selected;
966}
967
968
969static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
970 int timeout_sec, int timeout_usec)
971{
Dmitry Shmidt04949592012-07-19 12:16:46 -0700972 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700973 /*
974 * No networks are enabled; short-circuit request so
975 * we don't wait timeout seconds before transitioning
976 * to INACTIVE state.
977 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700978 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
979 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700981#ifdef CONFIG_P2P
982 wpa_s->sta_scan_pending = 0;
983#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700984 return;
985 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800986
987 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
989}
990
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800991
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700992int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800993 struct wpa_bss *selected,
994 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700995{
996 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
997 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
998 "PBC session overlap");
999#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001000 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001001 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001002#endif /* CONFIG_P2P */
1003
1004#ifdef CONFIG_WPS
1005 wpas_wps_cancel(wpa_s);
1006#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001007 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001008 }
1009
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001010 wpa_msg(wpa_s, MSG_DEBUG,
1011 "Considering connect request: reassociate: %d selected: "
1012 MACSTR " bssid: " MACSTR " pending: " MACSTR
1013 " wpa_state: %s ssid=%p current_ssid=%p",
1014 wpa_s->reassociate, MAC2STR(selected->bssid),
1015 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1016 wpa_supplicant_state_txt(wpa_s->wpa_state),
1017 ssid, wpa_s->current_ssid);
1018
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001019 /*
1020 * Do not trigger new association unless the BSSID has changed or if
1021 * reassociation is requested. If we are in process of associating with
1022 * the selected BSSID, do not trigger new attempt.
1023 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001024 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001025 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1026 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1027 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001028 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1029 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1030 0) ||
1031 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1032 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001033 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1034 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001035 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001036 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001037 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1038 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001039 wpa_supplicant_associate(wpa_s, selected, ssid);
1040 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001041 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1042 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001043 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001044
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001045 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001046}
1047
1048
1049static struct wpa_ssid *
1050wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1051{
1052 int prio;
1053 struct wpa_ssid *ssid;
1054
1055 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1056 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1057 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001058 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001059 continue;
1060 if (ssid->mode == IEEE80211_MODE_IBSS ||
1061 ssid->mode == IEEE80211_MODE_AP)
1062 return ssid;
1063 }
1064 }
1065 return NULL;
1066}
1067
1068
1069/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1070 * on BSS added and BSS changed events */
1071static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001072 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001074 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001075
1076 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1077 return;
1078
Jouni Malinen87fd2792011-05-16 18:35:42 +03001079 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001080 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001081
Jouni Malinen87fd2792011-05-16 18:35:42 +03001082 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083 if (ssid == NULL)
1084 continue;
1085
Jouni Malinen87fd2792011-05-16 18:35:42 +03001086 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087 if (rsn == NULL)
1088 continue;
1089
Jouni Malinen87fd2792011-05-16 18:35:42 +03001090 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001091 }
1092
1093}
1094
1095
1096static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1097 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001098 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001099{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001100 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001101 int min_diff;
1102
1103 if (wpa_s->reassociate)
1104 return 1; /* explicit request to reassociate */
1105 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1106 return 1; /* we are not associated; continue */
1107 if (wpa_s->current_ssid == NULL)
1108 return 1; /* unknown current SSID */
1109 if (wpa_s->current_ssid != ssid)
1110 return 1; /* different network block */
1111
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001112 if (wpas_driver_bss_selection(wpa_s))
1113 return 0; /* Driver-based roaming */
1114
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001115 if (wpa_s->current_ssid->ssid)
1116 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1117 wpa_s->current_ssid->ssid,
1118 wpa_s->current_ssid->ssid_len);
1119 if (!current_bss)
1120 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001121
1122 if (!current_bss)
1123 return 1; /* current BSS not seen in scan results */
1124
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001125 if (current_bss == selected)
1126 return 0;
1127
1128 if (selected->last_update_idx > current_bss->last_update_idx)
1129 return 1; /* current BSS not seen in the last scan */
1130
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001131#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001132 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1133 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1134 MAC2STR(current_bss->bssid), current_bss->level);
1135 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1136 MAC2STR(selected->bssid), selected->level);
1137
1138 if (wpa_s->current_ssid->bssid_set &&
1139 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1140 0) {
1141 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1142 "has preferred BSSID");
1143 return 1;
1144 }
1145
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001146 if (current_bss->level < 0 && current_bss->level > selected->level) {
1147 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1148 "signal level");
1149 return 0;
1150 }
1151
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001152 min_diff = 2;
1153 if (current_bss->level < 0) {
1154 if (current_bss->level < -85)
1155 min_diff = 1;
1156 else if (current_bss->level < -80)
1157 min_diff = 2;
1158 else if (current_bss->level < -75)
1159 min_diff = 3;
1160 else if (current_bss->level < -70)
1161 min_diff = 4;
1162 else
1163 min_diff = 5;
1164 }
1165 if (abs(current_bss->level - selected->level) < min_diff) {
1166 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1167 "in signal level");
1168 return 0;
1169 }
1170
1171 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001172#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001173 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001174#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001175}
1176
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001177
Jouni Malinen89ca7022012-09-14 13:03:12 -07001178/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001179 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001180static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001181 union wpa_event_data *data,
1182 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001183{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184 struct wpa_scan_results *scan_res;
1185 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001186#ifndef CONFIG_NO_RANDOM_POOL
1187 size_t i, num;
1188#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189
1190#ifdef CONFIG_AP
1191 if (wpa_s->ap_iface)
1192 ap = 1;
1193#endif /* CONFIG_AP */
1194
1195 wpa_supplicant_notify_scanning(wpa_s, 0);
1196
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001197#ifdef CONFIG_P2P
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001198 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
Jouni Malinendc7b7132012-09-14 12:53:47 -07001199 !wpa_s->global->p2p_disabled &&
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001200 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1201 !wpa_s->scan_res_handler) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07001202 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001203 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1204 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1205 "stopped scan processing");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001206 wpa_s->scan_req = wpa_s->last_scan_req;
Jouni Malinenfa08f9e2012-09-13 18:05:55 -07001207 wpa_s->sta_scan_pending = 1;
1208 wpa_supplicant_req_scan(wpa_s, 5, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001209 return -1;
1210 }
1211 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001212 wpa_s->sta_scan_pending = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001213#endif /* CONFIG_P2P */
1214
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001215 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1216 data ? &data->scan_info :
1217 NULL, 1);
1218 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001219 if (wpa_s->conf->ap_scan == 2 || ap ||
1220 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001221 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001222 if (!own_request)
1223 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001224 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1225 "scanning again");
1226 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1227 return -1;
1228 }
1229
1230#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001231 num = scan_res->num;
1232 if (num > 10)
1233 num = 10;
1234 for (i = 0; i < num; i++) {
1235 u8 buf[5];
1236 struct wpa_scan_res *res = scan_res->res[i];
1237 buf[0] = res->bssid[5];
1238 buf[1] = res->qual & 0xff;
1239 buf[2] = res->noise & 0xff;
1240 buf[3] = res->level & 0xff;
1241 buf[4] = res->tsf & 0xff;
1242 random_add_randomness(buf, sizeof(buf));
1243 }
1244#endif /* CONFIG_NO_RANDOM_POOL */
1245
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001246 if (own_request && wpa_s->scan_res_handler) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001247 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1248 struct wpa_scan_results *scan_res);
1249
1250 scan_res_handler = wpa_s->scan_res_handler;
1251 wpa_s->scan_res_handler = NULL;
1252 scan_res_handler(wpa_s, scan_res);
1253
1254 wpa_scan_results_free(scan_res);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001255 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001256 }
1257
1258 if (ap) {
1259 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1260#ifdef CONFIG_AP
1261 if (wpa_s->ap_iface->scan_cb)
1262 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1263#endif /* CONFIG_AP */
1264 wpa_scan_results_free(scan_res);
1265 return 0;
1266 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001267
Dmitry Shmidt04949592012-07-19 12:16:46 -07001268 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1269 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1270 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001271
1272 wpas_notify_scan_done(wpa_s, 1);
1273
Dmitry Shmidt04949592012-07-19 12:16:46 -07001274 if (sme_proc_obss_scan(wpa_s) > 0) {
1275 wpa_scan_results_free(scan_res);
1276 return 0;
1277 }
1278
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001279 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1280 wpa_scan_results_free(scan_res);
1281 return 0;
1282 }
1283
Dmitry Shmidt04949592012-07-19 12:16:46 -07001284 if (autoscan_notify_scan(wpa_s, scan_res)) {
1285 wpa_scan_results_free(scan_res);
1286 return 0;
1287 }
1288
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001289 if (wpa_s->disconnected) {
1290 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1291 wpa_scan_results_free(scan_res);
1292 return 0;
1293 }
1294
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001295 if (!wpas_driver_bss_selection(wpa_s) &&
1296 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001297 wpa_scan_results_free(scan_res);
1298 return 0;
1299 }
1300
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001301 wpas_wps_update_ap_info(wpa_s, scan_res);
1302
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001303 wpa_scan_results_free(scan_res);
1304
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001305 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001306}
1307
1308
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001309static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001310 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001311{
1312 struct wpa_bss *selected;
1313 struct wpa_ssid *ssid = NULL;
1314
1315 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001316
1317 if (selected) {
1318 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001319 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001320 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001321 if (new_scan)
1322 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001323 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001324 }
1325
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001326 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001327 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001328 return -1;
1329 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001330 if (new_scan)
1331 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001332 /*
1333 * Do not notify other virtual radios of scan results since we do not
1334 * want them to start other associations at the same time.
1335 */
1336 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001337 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001338 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1339 ssid = wpa_supplicant_pick_new_network(wpa_s);
1340 if (ssid) {
1341 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1342 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001343 if (new_scan)
1344 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001345 } else if (own_request) {
1346 /*
1347 * No SSID found. If SCAN results are as a result of
1348 * own scan request and not due to a scan request on
1349 * another shared interface, try another scan.
1350 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001351 int timeout_sec = wpa_s->scan_interval;
1352 int timeout_usec = 0;
1353#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001354 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1355 return 0;
1356
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001357 if (wpa_s->p2p_in_provisioning ||
1358 wpa_s->show_group_started) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001359 /*
1360 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001361 * state and during P2P join-a-group operation
1362 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001363 */
1364 timeout_sec = 0;
1365 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001366 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1367 timeout_usec);
1368 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001369 }
1370#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001371#ifdef CONFIG_INTERWORKING
1372 if (wpa_s->conf->auto_interworking &&
1373 wpa_s->conf->interworking &&
1374 wpa_s->conf->cred) {
1375 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1376 "start ANQP fetch since no matching "
1377 "networks found");
1378 wpa_s->network_select = 1;
1379 wpa_s->auto_network_select = 1;
1380 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001381 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001382 }
1383#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001384 if (wpa_supplicant_req_sched_scan(wpa_s))
1385 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1386 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001387 }
1388 }
1389 return 0;
1390}
1391
1392
1393static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1394 union wpa_event_data *data)
1395{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001396 struct wpa_supplicant *ifs;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001397
1398 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001399 /*
1400 * If no scan results could be fetched, then no need to
1401 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001402 * this scan. Similarly, if scan results started a new operation on this
1403 * interface, do not notify other interfaces to avoid concurrent
1404 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001405 */
1406 return;
1407 }
1408
1409 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001410 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001411 * so, they get updated with this same scan info.
1412 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001413 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1414 radio_list) {
1415 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001416 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1417 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001418 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001419 }
1420 }
1421}
1422
1423#endif /* CONFIG_NO_SCAN_PROCESSING */
1424
1425
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001426int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1427{
1428#ifdef CONFIG_NO_SCAN_PROCESSING
1429 return -1;
1430#else /* CONFIG_NO_SCAN_PROCESSING */
1431 struct os_time now;
1432
1433 if (wpa_s->last_scan_res_used <= 0)
1434 return -1;
1435
1436 os_get_time(&now);
1437 if (now.sec - wpa_s->last_scan.sec > 5) {
1438 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1439 return -1;
1440 }
1441
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001442 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001443#endif /* CONFIG_NO_SCAN_PROCESSING */
1444}
1445
Dmitry Shmidt04949592012-07-19 12:16:46 -07001446#ifdef CONFIG_WNM
1447
1448static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1449{
1450 struct wpa_supplicant *wpa_s = eloop_ctx;
1451
1452 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1453 return;
1454
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001455 if (!wpa_s->no_keep_alive) {
1456 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1457 MAC2STR(wpa_s->bssid));
1458 /* TODO: could skip this if normal data traffic has been sent */
1459 /* TODO: Consider using some more appropriate data frame for
1460 * this */
1461 if (wpa_s->l2)
1462 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1463 (u8 *) "", 0);
1464 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001465
1466#ifdef CONFIG_SME
1467 if (wpa_s->sme.bss_max_idle_period) {
1468 unsigned int msec;
1469 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1470 if (msec > 100)
1471 msec -= 100;
1472 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1473 wnm_bss_keep_alive, wpa_s, NULL);
1474 }
1475#endif /* CONFIG_SME */
1476}
1477
1478
1479static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1480 const u8 *ies, size_t ies_len)
1481{
1482 struct ieee802_11_elems elems;
1483
1484 if (ies == NULL)
1485 return;
1486
1487 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1488 return;
1489
1490#ifdef CONFIG_SME
1491 if (elems.bss_max_idle_period) {
1492 unsigned int msec;
1493 wpa_s->sme.bss_max_idle_period =
1494 WPA_GET_LE16(elems.bss_max_idle_period);
1495 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1496 "TU)%s", wpa_s->sme.bss_max_idle_period,
1497 (elems.bss_max_idle_period[2] & 0x01) ?
1498 " (protected keep-live required)" : "");
1499 if (wpa_s->sme.bss_max_idle_period == 0)
1500 wpa_s->sme.bss_max_idle_period = 1;
1501 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1502 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1503 /* msec times 1000 */
1504 msec = wpa_s->sme.bss_max_idle_period * 1024;
1505 if (msec > 100)
1506 msec -= 100;
1507 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1508 wnm_bss_keep_alive, wpa_s,
1509 NULL);
1510 }
1511 }
1512#endif /* CONFIG_SME */
1513}
1514
1515#endif /* CONFIG_WNM */
1516
1517
1518void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1519{
1520#ifdef CONFIG_WNM
1521 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1522#endif /* CONFIG_WNM */
1523}
1524
1525
Dmitry Shmidt051af732013-10-22 13:52:46 -07001526#ifdef CONFIG_INTERWORKING
1527
1528static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1529 size_t len)
1530{
1531 int res;
1532
1533 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1534 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1535 if (res) {
1536 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1537 }
1538
1539 return res;
1540}
1541
1542
1543static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1544 const u8 *ies, size_t ies_len)
1545{
1546 struct ieee802_11_elems elems;
1547
1548 if (ies == NULL)
1549 return;
1550
1551 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1552 return;
1553
1554 if (elems.qos_map_set) {
1555 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1556 elems.qos_map_set_len);
1557 }
1558}
1559
1560#endif /* CONFIG_INTERWORKING */
1561
1562
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001563static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1564 union wpa_event_data *data)
1565{
1566 int l, len, found = 0, wpa_found, rsn_found;
1567 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001568#ifdef CONFIG_IEEE80211R
1569 u8 bssid[ETH_ALEN];
1570#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001571
1572 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1573 if (data->assoc_info.req_ies)
1574 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1575 data->assoc_info.req_ies_len);
1576 if (data->assoc_info.resp_ies) {
1577 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1578 data->assoc_info.resp_ies_len);
1579#ifdef CONFIG_TDLS
1580 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1581 data->assoc_info.resp_ies_len);
1582#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001583#ifdef CONFIG_WNM
1584 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1585 data->assoc_info.resp_ies_len);
1586#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001587#ifdef CONFIG_INTERWORKING
1588 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1589 data->assoc_info.resp_ies_len);
1590#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001591 }
1592 if (data->assoc_info.beacon_ies)
1593 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1594 data->assoc_info.beacon_ies,
1595 data->assoc_info.beacon_ies_len);
1596 if (data->assoc_info.freq)
1597 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1598 data->assoc_info.freq);
1599
1600 p = data->assoc_info.req_ies;
1601 l = data->assoc_info.req_ies_len;
1602
1603 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1604 while (p && l >= 2) {
1605 len = p[1] + 2;
1606 if (len > l) {
1607 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1608 p, l);
1609 break;
1610 }
1611 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1612 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1613 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1614 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1615 break;
1616 found = 1;
1617 wpa_find_assoc_pmkid(wpa_s);
1618 break;
1619 }
1620 l -= len;
1621 p += len;
1622 }
1623 if (!found && data->assoc_info.req_ies)
1624 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1625
1626#ifdef CONFIG_IEEE80211R
1627#ifdef CONFIG_SME
1628 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001629 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1630 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1631 data->assoc_info.resp_ies,
1632 data->assoc_info.resp_ies_len,
1633 bssid) < 0) {
1634 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1635 "Reassociation Response failed");
1636 wpa_supplicant_deauthenticate(
1637 wpa_s, WLAN_REASON_INVALID_IE);
1638 return -1;
1639 }
1640 }
1641
1642 p = data->assoc_info.resp_ies;
1643 l = data->assoc_info.resp_ies_len;
1644
1645#ifdef CONFIG_WPS_STRICT
1646 if (p && wpa_s->current_ssid &&
1647 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1648 struct wpabuf *wps;
1649 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1650 if (wps == NULL) {
1651 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1652 "include WPS IE in (Re)Association Response");
1653 return -1;
1654 }
1655
1656 if (wps_validate_assoc_resp(wps) < 0) {
1657 wpabuf_free(wps);
1658 wpa_supplicant_deauthenticate(
1659 wpa_s, WLAN_REASON_INVALID_IE);
1660 return -1;
1661 }
1662 wpabuf_free(wps);
1663 }
1664#endif /* CONFIG_WPS_STRICT */
1665
1666 /* Go through the IEs and make a copy of the MDIE, if present. */
1667 while (p && l >= 2) {
1668 len = p[1] + 2;
1669 if (len > l) {
1670 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1671 p, l);
1672 break;
1673 }
1674 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1675 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1676 wpa_s->sme.ft_used = 1;
1677 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1678 MOBILITY_DOMAIN_ID_LEN);
1679 break;
1680 }
1681 l -= len;
1682 p += len;
1683 }
1684#endif /* CONFIG_SME */
1685
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001686 /* Process FT when SME is in the driver */
1687 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1688 wpa_ft_is_completed(wpa_s->wpa)) {
1689 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1690 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1691 data->assoc_info.resp_ies,
1692 data->assoc_info.resp_ies_len,
1693 bssid) < 0) {
1694 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1695 "Reassociation Response failed");
1696 wpa_supplicant_deauthenticate(
1697 wpa_s, WLAN_REASON_INVALID_IE);
1698 return -1;
1699 }
1700 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1701 }
1702
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001703 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1704 data->assoc_info.resp_ies_len);
1705#endif /* CONFIG_IEEE80211R */
1706
1707 /* WPA/RSN IE from Beacon/ProbeResp */
1708 p = data->assoc_info.beacon_ies;
1709 l = data->assoc_info.beacon_ies_len;
1710
1711 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1712 */
1713 wpa_found = rsn_found = 0;
1714 while (p && l >= 2) {
1715 len = p[1] + 2;
1716 if (len > l) {
1717 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1718 p, l);
1719 break;
1720 }
1721 if (!wpa_found &&
1722 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1723 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1724 wpa_found = 1;
1725 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1726 }
1727
1728 if (!rsn_found &&
1729 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1730 rsn_found = 1;
1731 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1732 }
1733
1734 l -= len;
1735 p += len;
1736 }
1737
1738 if (!wpa_found && data->assoc_info.beacon_ies)
1739 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1740 if (!rsn_found && data->assoc_info.beacon_ies)
1741 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1742 if (wpa_found || rsn_found)
1743 wpa_s->ap_ies_from_associnfo = 1;
1744
Jouni Malinen87fd2792011-05-16 18:35:42 +03001745 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1746 wpa_s->assoc_freq != data->assoc_info.freq) {
1747 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1748 "%u to %u MHz",
1749 wpa_s->assoc_freq, data->assoc_info.freq);
1750 wpa_supplicant_update_scan_results(wpa_s);
1751 }
1752
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001753 wpa_s->assoc_freq = data->assoc_info.freq;
1754
1755 return 0;
1756}
1757
1758
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001759static struct wpa_bss * wpa_supplicant_get_new_bss(
1760 struct wpa_supplicant *wpa_s, const u8 *bssid)
1761{
1762 struct wpa_bss *bss = NULL;
1763 struct wpa_ssid *ssid = wpa_s->current_ssid;
1764
1765 if (ssid->ssid_len > 0)
1766 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1767 if (!bss)
1768 bss = wpa_bss_get_bssid(wpa_s, bssid);
1769
1770 return bss;
1771}
1772
1773
1774static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1775{
1776 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1777
1778 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1779 return -1;
1780
1781 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1782 return 0;
1783
1784 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1785 WPA_IE_VENDOR_TYPE);
1786 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1787
1788 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1789 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1790 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1791 bss_rsn ? 2 + bss_rsn[1] : 0))
1792 return -1;
1793
1794 return 0;
1795}
1796
1797
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001798static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1799 union wpa_event_data *data)
1800{
1801 u8 bssid[ETH_ALEN];
1802 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001803
1804#ifdef CONFIG_AP
1805 if (wpa_s->ap_iface) {
1806 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1807 data->assoc_info.addr,
1808 data->assoc_info.req_ies,
1809 data->assoc_info.req_ies_len,
1810 data->assoc_info.reassoc);
1811 return;
1812 }
1813#endif /* CONFIG_AP */
1814
1815 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1816 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1817 return;
1818
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001819 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1820 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001821 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001822 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1823 return;
1824 }
1825
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001826 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001827 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001828 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1829 MACSTR, MAC2STR(bssid));
1830 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001831 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1832 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001833 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001834
1835 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1836 wpa_clear_keys(wpa_s, bssid);
1837 }
1838 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001839 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001840 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1841 return;
1842 }
1843 if (wpa_s->current_ssid) {
1844 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001845
1846 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1847 if (!bss) {
1848 wpa_supplicant_update_scan_results(wpa_s);
1849
1850 /* Get the BSS from the new scan results */
1851 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1852 }
1853
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001854 if (bss)
1855 wpa_s->current_bss = bss;
1856 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001857
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001858#ifdef ANDROID
1859 if (wpa_s->conf->ap_scan == 1) {
1860#else
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001861 if (wpa_s->conf->ap_scan == 1 &&
1862 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001863#endif
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001864 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1865 wpa_msg(wpa_s, MSG_WARNING,
1866 "WPA/RSN IEs not updated");
1867 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001868 }
1869
1870#ifdef CONFIG_SME
1871 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1872 wpa_s->sme.prev_bssid_set = 1;
1873#endif /* CONFIG_SME */
1874
1875 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1876 if (wpa_s->current_ssid) {
1877 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1878 * initialized before association, but for other modes,
1879 * initialize PC/SC here, if the current configuration needs
1880 * smartcard or SIM/USIM. */
1881 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1882 }
1883 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1884 if (wpa_s->l2)
1885 l2_packet_notify_auth_start(wpa_s->l2);
1886
1887 /*
1888 * Set portEnabled first to FALSE in order to get EAP state machine out
1889 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1890 * state machine may transit to AUTHENTICATING state based on obsolete
1891 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1892 * AUTHENTICATED without ever giving chance to EAP state machine to
1893 * reset the state.
1894 */
1895 if (!ft_completed) {
1896 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1897 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1898 }
1899 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1900 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1901 /* 802.1X::portControl = Auto */
1902 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1903 wpa_s->eapol_received = 0;
1904 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1905 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1906 (wpa_s->current_ssid &&
1907 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001908 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1909 (wpa_s->drv_flags &
1910 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1911 /*
1912 * Set the key after having received joined-IBSS event
1913 * from the driver.
1914 */
1915 wpa_supplicant_set_wpa_none_key(wpa_s,
1916 wpa_s->current_ssid);
1917 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001918 wpa_supplicant_cancel_auth_timeout(wpa_s);
1919 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1920 } else if (!ft_completed) {
1921 /* Timeout for receiving the first EAPOL packet */
1922 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1923 }
1924 wpa_supplicant_cancel_scan(wpa_s);
1925
1926 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1927 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1928 /*
1929 * We are done; the driver will take care of RSN 4-way
1930 * handshake.
1931 */
1932 wpa_supplicant_cancel_auth_timeout(wpa_s);
1933 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1934 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1935 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1936 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1937 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1938 /*
1939 * The driver will take care of RSN 4-way handshake, so we need
1940 * to allow EAPOL supplicant to complete its work without
1941 * waiting for WPA supplicant.
1942 */
1943 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1944 } else if (ft_completed) {
1945 /*
1946 * FT protocol completed - make sure EAPOL state machine ends
1947 * up in authenticated.
1948 */
1949 wpa_supplicant_cancel_auth_timeout(wpa_s);
1950 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1951 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1952 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1953 }
1954
Jouni Malinena05074c2012-12-21 21:35:35 +02001955 wpa_s->last_eapol_matches_bssid = 0;
1956
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001957 if (wpa_s->pending_eapol_rx) {
1958 struct os_time now, age;
1959 os_get_time(&now);
1960 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1961 if (age.sec == 0 && age.usec < 100000 &&
1962 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1963 0) {
1964 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1965 "frame that was received just before "
1966 "association notification");
1967 wpa_supplicant_rx_eapol(
1968 wpa_s, wpa_s->pending_eapol_rx_src,
1969 wpabuf_head(wpa_s->pending_eapol_rx),
1970 wpabuf_len(wpa_s->pending_eapol_rx));
1971 }
1972 wpabuf_free(wpa_s->pending_eapol_rx);
1973 wpa_s->pending_eapol_rx = NULL;
1974 }
1975
1976 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1977 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001978 wpa_s->current_ssid &&
1979 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001980 /* Set static WEP keys again */
1981 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1982 }
1983
1984#ifdef CONFIG_IBSS_RSN
1985 if (wpa_s->current_ssid &&
1986 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1987 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1988 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1989 wpa_s->ibss_rsn == NULL) {
1990 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1991 if (!wpa_s->ibss_rsn) {
1992 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1993 wpa_supplicant_deauthenticate(
1994 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1995 return;
1996 }
1997
1998 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1999 }
2000#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002001
2002 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002003}
2004
2005
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002006static int disconnect_reason_recoverable(u16 reason_code)
2007{
2008 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2009 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2010 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2011}
2012
2013
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002014static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002015 u16 reason_code,
2016 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002017{
2018 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002019
2020 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2021 /*
2022 * At least Host AP driver and a Prism3 card seemed to be
2023 * generating streams of disconnected events when configuring
2024 * IBSS for WPA-None. Ignore them for now.
2025 */
2026 return;
2027 }
2028
2029 bssid = wpa_s->bssid;
2030 if (is_zero_ether_addr(bssid))
2031 bssid = wpa_s->pending_bssid;
2032
2033 if (!is_zero_ether_addr(bssid) ||
2034 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2035 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2036 " reason=%d%s",
2037 MAC2STR(bssid), reason_code,
2038 locally_generated ? " locally_generated=1" : "");
2039 }
2040}
2041
2042
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002043static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2044 int locally_generated)
2045{
2046 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2047 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2048 return 0; /* Not in 4-way handshake with PSK */
2049
2050 /*
2051 * It looks like connection was lost while trying to go through PSK
2052 * 4-way handshake. Filter out known disconnection cases that are caused
2053 * by something else than PSK mismatch to avoid confusing reports.
2054 */
2055
2056 if (locally_generated) {
2057 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2058 return 0;
2059 }
2060
2061 return 1;
2062}
2063
2064
Jouni Malinen2b89da82012-08-31 22:04:41 +03002065static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2066 u16 reason_code,
2067 int locally_generated)
2068{
2069 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002070 int authenticating;
2071 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002072 struct wpa_bss *fast_reconnect = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002073#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002074 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002075#endif /* CONFIG_NO_SCAN_PROCESSING */
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002076 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002077
2078 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2079 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2080
2081 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2082 /*
2083 * At least Host AP driver and a Prism3 card seemed to be
2084 * generating streams of disconnected events when configuring
2085 * IBSS for WPA-None. Ignore them for now.
2086 */
2087 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2088 "IBSS/WPA-None mode");
2089 return;
2090 }
2091
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002092 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002093 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2094 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002095 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2096 return; /* P2P group removed */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002097 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002098 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002099 if (!wpa_s->disconnected &&
2100 (!wpa_s->auto_reconnect_disabled ||
2101 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002102 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2103 "reconnect (wps=%d wpa_state=%d)",
2104 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2105 wpa_s->wpa_state);
2106 if (wpa_s->wpa_state == WPA_COMPLETED &&
2107 wpa_s->current_ssid &&
2108 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002109 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002110 disconnect_reason_recoverable(reason_code)) {
2111 /*
2112 * It looks like the AP has dropped association with
2113 * us, but could allow us to get back in. Try to
2114 * reconnect to the same BSS without full scan to save
2115 * time for some common cases.
2116 */
2117 fast_reconnect = wpa_s->current_bss;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002118#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002119 fast_reconnect_ssid = wpa_s->current_ssid;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002120#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002121 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002122 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002123 else
2124 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2125 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002126 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002127 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002128 "try to re-connect");
2129 wpa_s->reassociate = 0;
2130 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002131 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002132 }
2133 bssid = wpa_s->bssid;
2134 if (is_zero_ether_addr(bssid))
2135 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002136 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2137 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002138 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002139 if (locally_generated)
2140 wpa_s->disconnect_reason = -reason_code;
2141 else
2142 wpa_s->disconnect_reason = reason_code;
2143 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002144 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2145 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2146 wpa_s->keys_cleared = 0;
2147 wpa_clear_keys(wpa_s, wpa_s->bssid);
2148 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002149 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002150 wpa_supplicant_mark_disassoc(wpa_s);
2151
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002152 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002153 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002154 wpa_s->current_ssid = last_ssid;
2155 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002156
2157 if (fast_reconnect) {
2158#ifndef CONFIG_NO_SCAN_PROCESSING
2159 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2160 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2161 fast_reconnect_ssid) < 0) {
2162 /* Recover through full scan */
2163 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2164 }
2165#endif /* CONFIG_NO_SCAN_PROCESSING */
2166 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002167}
2168
2169
2170#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002171void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002172{
2173 struct wpa_supplicant *wpa_s = eloop_ctx;
2174
2175 if (!wpa_s->pending_mic_error_report)
2176 return;
2177
2178 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2179 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2180 wpa_s->pending_mic_error_report = 0;
2181}
2182#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2183
2184
2185static void
2186wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2187 union wpa_event_data *data)
2188{
2189 int pairwise;
2190 struct os_time t;
2191
2192 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2193 pairwise = (data && data->michael_mic_failure.unicast);
2194 os_get_time(&t);
2195 if ((wpa_s->last_michael_mic_error &&
2196 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2197 wpa_s->pending_mic_error_report) {
2198 if (wpa_s->pending_mic_error_report) {
2199 /*
2200 * Send the pending MIC error report immediately since
2201 * we are going to start countermeasures and AP better
2202 * do the same.
2203 */
2204 wpa_sm_key_request(wpa_s->wpa, 1,
2205 wpa_s->pending_mic_error_pairwise);
2206 }
2207
2208 /* Send the new MIC error report immediately since we are going
2209 * to start countermeasures and AP better do the same.
2210 */
2211 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2212
2213 /* initialize countermeasures */
2214 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002215
2216 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2217
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002218 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2219
2220 /*
2221 * Need to wait for completion of request frame. We do not get
2222 * any callback for the message completion, so just wait a
2223 * short while and hope for the best. */
2224 os_sleep(0, 10000);
2225
2226 wpa_drv_set_countermeasures(wpa_s, 1);
2227 wpa_supplicant_deauthenticate(wpa_s,
2228 WLAN_REASON_MICHAEL_MIC_FAILURE);
2229 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2230 wpa_s, NULL);
2231 eloop_register_timeout(60, 0,
2232 wpa_supplicant_stop_countermeasures,
2233 wpa_s, NULL);
2234 /* TODO: mark the AP rejected for 60 second. STA is
2235 * allowed to associate with another AP.. */
2236 } else {
2237#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2238 if (wpa_s->mic_errors_seen) {
2239 /*
2240 * Reduce the effectiveness of Michael MIC error
2241 * reports as a means for attacking against TKIP if
2242 * more than one MIC failure is noticed with the same
2243 * PTK. We delay the transmission of the reports by a
2244 * random time between 0 and 60 seconds in order to
2245 * force the attacker wait 60 seconds before getting
2246 * the information on whether a frame resulted in a MIC
2247 * failure.
2248 */
2249 u8 rval[4];
2250 int sec;
2251
2252 if (os_get_random(rval, sizeof(rval)) < 0)
2253 sec = os_random() % 60;
2254 else
2255 sec = WPA_GET_BE32(rval) % 60;
2256 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2257 "report %d seconds", sec);
2258 wpa_s->pending_mic_error_report = 1;
2259 wpa_s->pending_mic_error_pairwise = pairwise;
2260 eloop_cancel_timeout(
2261 wpa_supplicant_delayed_mic_error_report,
2262 wpa_s, NULL);
2263 eloop_register_timeout(
2264 sec, os_random() % 1000000,
2265 wpa_supplicant_delayed_mic_error_report,
2266 wpa_s, NULL);
2267 } else {
2268 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2269 }
2270#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2271 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2272#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2273 }
2274 wpa_s->last_michael_mic_error = t.sec;
2275 wpa_s->mic_errors_seen++;
2276}
2277
2278
2279#ifdef CONFIG_TERMINATE_ONLASTIF
2280static int any_interfaces(struct wpa_supplicant *head)
2281{
2282 struct wpa_supplicant *wpa_s;
2283
2284 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2285 if (!wpa_s->interface_removed)
2286 return 1;
2287 return 0;
2288}
2289#endif /* CONFIG_TERMINATE_ONLASTIF */
2290
2291
2292static void
2293wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2294 union wpa_event_data *data)
2295{
2296 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2297 return;
2298
2299 switch (data->interface_status.ievent) {
2300 case EVENT_INTERFACE_ADDED:
2301 if (!wpa_s->interface_removed)
2302 break;
2303 wpa_s->interface_removed = 0;
2304 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2305 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2306 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2307 "driver after interface was added");
2308 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002309 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002310 break;
2311 case EVENT_INTERFACE_REMOVED:
2312 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2313 wpa_s->interface_removed = 1;
2314 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002315 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002316 l2_packet_deinit(wpa_s->l2);
2317 wpa_s->l2 = NULL;
2318#ifdef CONFIG_IBSS_RSN
2319 ibss_rsn_deinit(wpa_s->ibss_rsn);
2320 wpa_s->ibss_rsn = NULL;
2321#endif /* CONFIG_IBSS_RSN */
2322#ifdef CONFIG_TERMINATE_ONLASTIF
2323 /* check if last interface */
2324 if (!any_interfaces(wpa_s->global->ifaces))
2325 eloop_terminate();
2326#endif /* CONFIG_TERMINATE_ONLASTIF */
2327 break;
2328 }
2329}
2330
2331
2332#ifdef CONFIG_PEERKEY
2333static void
2334wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2335 union wpa_event_data *data)
2336{
2337 if (data == NULL)
2338 return;
2339 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2340}
2341#endif /* CONFIG_PEERKEY */
2342
2343
2344#ifdef CONFIG_TDLS
2345static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2346 union wpa_event_data *data)
2347{
2348 if (data == NULL)
2349 return;
2350 switch (data->tdls.oper) {
2351 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002352 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2353 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2354 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2355 else
2356 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002357 break;
2358 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002359 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2360 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2361 data->tdls.reason_code);
2362 else
2363 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2364 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002365 break;
2366 }
2367}
2368#endif /* CONFIG_TDLS */
2369
2370
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002371#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002372static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2373 union wpa_event_data *data)
2374{
2375 if (data == NULL)
2376 return;
2377 switch (data->wnm.oper) {
2378 case WNM_OPER_SLEEP:
2379 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2380 "(action=%d, intval=%d)",
2381 data->wnm.sleep_action, data->wnm.sleep_intval);
2382 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002383 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002384 break;
2385 }
2386}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002387#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002388
2389
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002390#ifdef CONFIG_IEEE80211R
2391static void
2392wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2393 union wpa_event_data *data)
2394{
2395 if (data == NULL)
2396 return;
2397
2398 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2399 data->ft_ies.ies_len,
2400 data->ft_ies.ft_action,
2401 data->ft_ies.target_ap,
2402 data->ft_ies.ric_ies,
2403 data->ft_ies.ric_ies_len) < 0) {
2404 /* TODO: prevent MLME/driver from trying to associate? */
2405 }
2406}
2407#endif /* CONFIG_IEEE80211R */
2408
2409
2410#ifdef CONFIG_IBSS_RSN
2411static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2412 union wpa_event_data *data)
2413{
2414 struct wpa_ssid *ssid;
2415 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2416 return;
2417 if (data == NULL)
2418 return;
2419 ssid = wpa_s->current_ssid;
2420 if (ssid == NULL)
2421 return;
2422 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2423 return;
2424
2425 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2426}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002427
2428
2429static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2430 union wpa_event_data *data)
2431{
2432 struct wpa_ssid *ssid = wpa_s->current_ssid;
2433
2434 if (ssid == NULL)
2435 return;
2436
2437 /* check if the ssid is correctly configured as IBSS/RSN */
2438 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2439 return;
2440
2441 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2442 data->rx_mgmt.frame_len);
2443}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002444#endif /* CONFIG_IBSS_RSN */
2445
2446
2447#ifdef CONFIG_IEEE80211R
2448static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2449 size_t len)
2450{
2451 const u8 *sta_addr, *target_ap_addr;
2452 u16 status;
2453
2454 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2455 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2456 return; /* only SME case supported for now */
2457 if (len < 1 + 2 * ETH_ALEN + 2)
2458 return;
2459 if (data[0] != 2)
2460 return; /* Only FT Action Response is supported for now */
2461 sta_addr = data + 1;
2462 target_ap_addr = data + 1 + ETH_ALEN;
2463 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2464 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2465 MACSTR " TargetAP " MACSTR " status %u",
2466 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2467
2468 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2469 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2470 " in FT Action Response", MAC2STR(sta_addr));
2471 return;
2472 }
2473
2474 if (status) {
2475 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2476 "failure (status code %d)", status);
2477 /* TODO: report error to FT code(?) */
2478 return;
2479 }
2480
2481 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2482 len - (1 + 2 * ETH_ALEN + 2), 1,
2483 target_ap_addr, NULL, 0) < 0)
2484 return;
2485
2486#ifdef CONFIG_SME
2487 {
2488 struct wpa_bss *bss;
2489 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2490 if (bss)
2491 wpa_s->sme.freq = bss->freq;
2492 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2493 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2494 WLAN_AUTH_FT);
2495 }
2496#endif /* CONFIG_SME */
2497}
2498#endif /* CONFIG_IEEE80211R */
2499
2500
2501static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2502 struct unprot_deauth *e)
2503{
2504#ifdef CONFIG_IEEE80211W
2505 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2506 "dropped: " MACSTR " -> " MACSTR
2507 " (reason code %u)",
2508 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2509 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2510#endif /* CONFIG_IEEE80211W */
2511}
2512
2513
2514static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2515 struct unprot_disassoc *e)
2516{
2517#ifdef CONFIG_IEEE80211W
2518 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2519 "dropped: " MACSTR " -> " MACSTR
2520 " (reason code %u)",
2521 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2522 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2523#endif /* CONFIG_IEEE80211W */
2524}
2525
2526
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002527static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2528 u16 reason_code, int locally_generated,
2529 const u8 *ie, size_t ie_len, int deauth)
2530{
2531#ifdef CONFIG_AP
2532 if (wpa_s->ap_iface && addr) {
2533 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2534 return;
2535 }
2536
2537 if (wpa_s->ap_iface) {
2538 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2539 return;
2540 }
2541#endif /* CONFIG_AP */
2542
2543 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2544
2545 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2546 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2547 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2548 eapol_sm_failed(wpa_s->eapol)))
2549 wpas_auth_failed(wpa_s);
2550
2551#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002552 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002553 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2554 locally_generated) > 0) {
2555 /*
2556 * The interface was removed, so cannot continue
2557 * processing any additional operations after this.
2558 */
2559 return;
2560 }
2561 }
2562#endif /* CONFIG_P2P */
2563
2564 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2565 locally_generated);
2566}
2567
2568
2569static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2570 struct disassoc_info *info)
2571{
2572 u16 reason_code = 0;
2573 int locally_generated = 0;
2574 const u8 *addr = NULL;
2575 const u8 *ie = NULL;
2576 size_t ie_len = 0;
2577
2578 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2579
2580 if (info) {
2581 addr = info->addr;
2582 ie = info->ie;
2583 ie_len = info->ie_len;
2584 reason_code = info->reason_code;
2585 locally_generated = info->locally_generated;
2586 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2587 locally_generated ? " (locally generated)" : "");
2588 if (addr)
2589 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2590 MAC2STR(addr));
2591 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2592 ie, ie_len);
2593 }
2594
2595#ifdef CONFIG_AP
2596 if (wpa_s->ap_iface && info && info->addr) {
2597 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2598 return;
2599 }
2600
2601 if (wpa_s->ap_iface) {
2602 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2603 return;
2604 }
2605#endif /* CONFIG_AP */
2606
2607#ifdef CONFIG_P2P
2608 if (info) {
2609 wpas_p2p_disassoc_notif(
2610 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2611 locally_generated);
2612 }
2613#endif /* CONFIG_P2P */
2614
2615 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2616 sme_event_disassoc(wpa_s, info);
2617
2618 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2619 ie, ie_len, 0);
2620}
2621
2622
2623static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2624 struct deauth_info *info)
2625{
2626 u16 reason_code = 0;
2627 int locally_generated = 0;
2628 const u8 *addr = NULL;
2629 const u8 *ie = NULL;
2630 size_t ie_len = 0;
2631
2632 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2633
2634 if (info) {
2635 addr = info->addr;
2636 ie = info->ie;
2637 ie_len = info->ie_len;
2638 reason_code = info->reason_code;
2639 locally_generated = info->locally_generated;
2640 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2641 reason_code,
2642 locally_generated ? " (locally generated)" : "");
2643 if (addr) {
2644 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2645 MAC2STR(addr));
2646 }
2647 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2648 ie, ie_len);
2649 }
2650
2651 wpa_reset_ft_completed(wpa_s->wpa);
2652
2653 wpas_event_disconnect(wpa_s, addr, reason_code,
2654 locally_generated, ie, ie_len, 1);
2655}
2656
2657
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002658static void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s)
2659{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002660 struct wpa_supplicant *ifs;
2661
2662 if (wpa_s->drv_priv == NULL)
2663 return; /* Ignore event during drv initialization */
2664
2665 free_hw_features(wpa_s);
2666 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2667 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2668
2669#ifdef CONFIG_P2P
2670 wpas_p2p_update_channel_list(wpa_s);
2671#endif /* CONFIG_P2P */
2672
2673 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002674 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002675 * so, they get updated with this same hw mode info.
2676 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002677 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2678 radio_list) {
2679 if (ifs != wpa_s) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002680 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2681 ifs->ifname);
2682 free_hw_features(ifs);
2683 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2684 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2685 }
2686 }
2687}
2688
2689
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002690void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2691 union wpa_event_data *data)
2692{
2693 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002694
2695 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2696 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002697 event != EVENT_INTERFACE_STATUS &&
2698 event != EVENT_SCHED_SCAN_STOPPED) {
2699 wpa_dbg(wpa_s, MSG_DEBUG,
2700 "Ignore event %s (%d) while interface is disabled",
2701 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002702 return;
2703 }
2704
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002705#ifndef CONFIG_NO_STDOUT_DEBUG
2706{
2707 int level = MSG_DEBUG;
2708
Dmitry Shmidt04949592012-07-19 12:16:46 -07002709 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002710 const struct ieee80211_hdr *hdr;
2711 u16 fc;
2712 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2713 fc = le_to_host16(hdr->frame_control);
2714 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2715 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2716 level = MSG_EXCESSIVE;
2717 }
2718
2719 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2720 event_to_string(event), event);
2721}
2722#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002723
2724 switch (event) {
2725 case EVENT_AUTH:
2726 sme_event_auth(wpa_s, data);
2727 break;
2728 case EVENT_ASSOC:
2729 wpa_supplicant_event_assoc(wpa_s, data);
2730 break;
2731 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002732 wpas_event_disassoc(wpa_s,
2733 data ? &data->disassoc_info : NULL);
2734 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002735 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002736 wpas_event_deauth(wpa_s,
2737 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002738 break;
2739 case EVENT_MICHAEL_MIC_FAILURE:
2740 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2741 break;
2742#ifndef CONFIG_NO_SCAN_PROCESSING
2743 case EVENT_SCAN_RESULTS:
2744 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002745 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2746 wpa_s->wpa_state != WPA_ASSOCIATING)
2747 wpas_p2p_continue_after_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002748 break;
2749#endif /* CONFIG_NO_SCAN_PROCESSING */
2750 case EVENT_ASSOCINFO:
2751 wpa_supplicant_event_associnfo(wpa_s, data);
2752 break;
2753 case EVENT_INTERFACE_STATUS:
2754 wpa_supplicant_event_interface_status(wpa_s, data);
2755 break;
2756 case EVENT_PMKID_CANDIDATE:
2757 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2758 break;
2759#ifdef CONFIG_PEERKEY
2760 case EVENT_STKSTART:
2761 wpa_supplicant_event_stkstart(wpa_s, data);
2762 break;
2763#endif /* CONFIG_PEERKEY */
2764#ifdef CONFIG_TDLS
2765 case EVENT_TDLS:
2766 wpa_supplicant_event_tdls(wpa_s, data);
2767 break;
2768#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002769#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002770 case EVENT_WNM:
2771 wpa_supplicant_event_wnm(wpa_s, data);
2772 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002773#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002774#ifdef CONFIG_IEEE80211R
2775 case EVENT_FT_RESPONSE:
2776 wpa_supplicant_event_ft_response(wpa_s, data);
2777 break;
2778#endif /* CONFIG_IEEE80211R */
2779#ifdef CONFIG_IBSS_RSN
2780 case EVENT_IBSS_RSN_START:
2781 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2782 break;
2783#endif /* CONFIG_IBSS_RSN */
2784 case EVENT_ASSOC_REJECT:
2785 if (data->assoc_reject.bssid)
2786 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2787 "bssid=" MACSTR " status_code=%u",
2788 MAC2STR(data->assoc_reject.bssid),
2789 data->assoc_reject.status_code);
2790 else
2791 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2792 "status_code=%u",
2793 data->assoc_reject.status_code);
2794 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2795 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002796 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002797 const u8 *bssid = data->assoc_reject.bssid;
2798 if (bssid == NULL || is_zero_ether_addr(bssid))
2799 bssid = wpa_s->pending_bssid;
2800 wpas_connection_failed(wpa_s, bssid);
2801 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002802 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002803 break;
2804 case EVENT_AUTH_TIMED_OUT:
2805 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2806 sme_event_auth_timed_out(wpa_s, data);
2807 break;
2808 case EVENT_ASSOC_TIMED_OUT:
2809 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2810 sme_event_assoc_timed_out(wpa_s, data);
2811 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002812 case EVENT_TX_STATUS:
2813 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2814 " type=%d stype=%d",
2815 MAC2STR(data->tx_status.dst),
2816 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002817#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002818 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002819#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002820 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2821 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002822 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002823 wpa_s, data->tx_status.dst,
2824 data->tx_status.data,
2825 data->tx_status.data_len,
2826 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002827 OFFCHANNEL_SEND_ACTION_SUCCESS :
2828 OFFCHANNEL_SEND_ACTION_NO_ACK);
2829#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002830 break;
2831 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002832#endif /* CONFIG_AP */
2833#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002834 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2835 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2836 /*
2837 * Catch TX status events for Action frames we sent via group
2838 * interface in GO mode.
2839 */
2840 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2841 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2842 os_memcmp(wpa_s->parent->pending_action_dst,
2843 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002844 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002845 wpa_s->parent, data->tx_status.dst,
2846 data->tx_status.data,
2847 data->tx_status.data_len,
2848 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002849 OFFCHANNEL_SEND_ACTION_SUCCESS :
2850 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002851 break;
2852 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002853#endif /* CONFIG_OFFCHANNEL */
2854#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002855 switch (data->tx_status.type) {
2856 case WLAN_FC_TYPE_MGMT:
2857 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2858 data->tx_status.data_len,
2859 data->tx_status.stype,
2860 data->tx_status.ack);
2861 break;
2862 case WLAN_FC_TYPE_DATA:
2863 ap_tx_status(wpa_s, data->tx_status.dst,
2864 data->tx_status.data,
2865 data->tx_status.data_len,
2866 data->tx_status.ack);
2867 break;
2868 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002869#endif /* CONFIG_AP */
2870 break;
2871#ifdef CONFIG_AP
2872 case EVENT_EAPOL_TX_STATUS:
2873 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2874 data->eapol_tx_status.data,
2875 data->eapol_tx_status.data_len,
2876 data->eapol_tx_status.ack);
2877 break;
2878 case EVENT_DRIVER_CLIENT_POLL_OK:
2879 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002880 break;
2881 case EVENT_RX_FROM_UNKNOWN:
2882 if (wpa_s->ap_iface == NULL)
2883 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002884 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2885 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002886 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002887 case EVENT_CH_SWITCH:
2888 if (!data)
2889 break;
2890 if (!wpa_s->ap_iface) {
2891 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2892 "event in non-AP mode");
2893 break;
2894 }
2895
Dmitry Shmidt04949592012-07-19 12:16:46 -07002896 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2897 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08002898 data->ch_switch.ch_offset,
2899 data->ch_switch.ch_width,
2900 data->ch_switch.cf1,
2901 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002902 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002903#endif /* CONFIG_AP */
2904#if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002905 case EVENT_RX_MGMT: {
2906 u16 fc, stype;
2907 const struct ieee80211_mgmt *mgmt;
2908
2909 mgmt = (const struct ieee80211_mgmt *)
2910 data->rx_mgmt.frame;
2911 fc = le_to_host16(mgmt->frame_control);
2912 stype = WLAN_FC_GET_STYPE(fc);
2913
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002914#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002915 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002916#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002917#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002918 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2919 data->rx_mgmt.frame_len > 24) {
2920 const u8 *src = mgmt->sa;
2921 const u8 *ie = mgmt->u.probe_req.variable;
2922 size_t ie_len = data->rx_mgmt.frame_len -
2923 (mgmt->u.probe_req.variable -
2924 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002925 wpas_p2p_probe_req_rx(
2926 wpa_s, src, mgmt->da,
2927 mgmt->bssid, ie, ie_len,
2928 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002929 break;
2930 }
2931#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002932#ifdef CONFIG_IBSS_RSN
2933 if (stype == WLAN_FC_STYPE_AUTH &&
2934 data->rx_mgmt.frame_len >= 30) {
2935 wpa_supplicant_event_ibss_auth(wpa_s, data);
2936 break;
2937 }
2938#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002939 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2940 "management frame in non-AP mode");
2941 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002942#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002943 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002944
2945 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2946 data->rx_mgmt.frame_len > 24) {
2947 const u8 *ie = mgmt->u.probe_req.variable;
2948 size_t ie_len = data->rx_mgmt.frame_len -
2949 (mgmt->u.probe_req.variable -
2950 data->rx_mgmt.frame);
2951
2952 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2953 mgmt->bssid, ie, ie_len,
2954 data->rx_mgmt.ssi_signal);
2955 }
2956
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002957 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002958#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002959 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002960 }
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002961#endif /* CONFIG_AP || CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002962 case EVENT_RX_ACTION:
2963 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2964 " Category=%u DataLen=%d freq=%d MHz",
2965 MAC2STR(data->rx_action.sa),
2966 data->rx_action.category, (int) data->rx_action.len,
2967 data->rx_action.freq);
2968#ifdef CONFIG_IEEE80211R
2969 if (data->rx_action.category == WLAN_ACTION_FT) {
2970 ft_rx_action(wpa_s, data->rx_action.data,
2971 data->rx_action.len);
2972 break;
2973 }
2974#endif /* CONFIG_IEEE80211R */
2975#ifdef CONFIG_IEEE80211W
2976#ifdef CONFIG_SME
2977 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2978 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2979 data->rx_action.data,
2980 data->rx_action.len);
2981 break;
2982 }
2983#endif /* CONFIG_SME */
2984#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002985#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002986 if (data->rx_action.category == WLAN_ACTION_WNM) {
2987 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2988 break;
2989 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002990#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002991#ifdef CONFIG_GAS
2992 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2993 gas_query_rx(wpa_s->gas, data->rx_action.da,
2994 data->rx_action.sa, data->rx_action.bssid,
2995 data->rx_action.data, data->rx_action.len,
2996 data->rx_action.freq) == 0)
2997 break;
2998#endif /* CONFIG_GAS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002999#ifdef CONFIG_TDLS
3000 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
3001 data->rx_action.len >= 4 &&
3002 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3003 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
3004 "Response from " MACSTR,
3005 MAC2STR(data->rx_action.sa));
3006 break;
3007 }
3008#endif /* CONFIG_TDLS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003009#ifdef CONFIG_INTERWORKING
3010 if (data->rx_action.category == WLAN_ACTION_QOS &&
3011 data->rx_action.len >= 1 &&
3012 data->rx_action.data[0] == QOS_QOS_MAP_CONFIG) {
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08003013 const u8 *pos = data->rx_action.data + 1;
3014 size_t len = data->rx_action.len - 1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003015 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3016 MACSTR, MAC2STR(data->rx_action.sa));
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08003017 if (os_memcmp(data->rx_action.sa, wpa_s->bssid,
3018 ETH_ALEN) == 0 &&
3019 len > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3020 pos[1] <= len - 2 && pos[1] >= 16)
3021 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
Dmitry Shmidt051af732013-10-22 13:52:46 -07003022 break;
3023 }
3024#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003025#ifdef CONFIG_P2P
3026 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
3027 data->rx_action.sa,
3028 data->rx_action.bssid,
3029 data->rx_action.category,
3030 data->rx_action.data,
3031 data->rx_action.len, data->rx_action.freq);
3032#endif /* CONFIG_P2P */
3033 break;
3034 case EVENT_RX_PROBE_REQ:
3035 if (data->rx_probe_req.sa == NULL ||
3036 data->rx_probe_req.ie == NULL)
3037 break;
3038#ifdef CONFIG_AP
3039 if (wpa_s->ap_iface) {
3040 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3041 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003042 data->rx_probe_req.da,
3043 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003044 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003045 data->rx_probe_req.ie_len,
3046 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003047 break;
3048 }
3049#endif /* CONFIG_AP */
3050#ifdef CONFIG_P2P
3051 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003052 data->rx_probe_req.da,
3053 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003054 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003055 data->rx_probe_req.ie_len,
3056 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003057#endif /* CONFIG_P2P */
3058 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003059 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003060#ifdef CONFIG_OFFCHANNEL
3061 offchannel_remain_on_channel_cb(
3062 wpa_s, data->remain_on_channel.freq,
3063 data->remain_on_channel.duration);
3064#endif /* CONFIG_OFFCHANNEL */
3065#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003066 wpas_p2p_remain_on_channel_cb(
3067 wpa_s, data->remain_on_channel.freq,
3068 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003069#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003070 break;
3071 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003072#ifdef CONFIG_OFFCHANNEL
3073 offchannel_cancel_remain_on_channel_cb(
3074 wpa_s, data->remain_on_channel.freq);
3075#endif /* CONFIG_OFFCHANNEL */
3076#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003077 wpas_p2p_cancel_remain_on_channel_cb(
3078 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003079#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003080 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003081#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003082 case EVENT_P2P_DEV_FOUND: {
3083 struct p2p_peer_info peer_info;
3084
3085 os_memset(&peer_info, 0, sizeof(peer_info));
3086 if (data->p2p_dev_found.dev_addr)
3087 os_memcpy(peer_info.p2p_device_addr,
3088 data->p2p_dev_found.dev_addr, ETH_ALEN);
3089 if (data->p2p_dev_found.pri_dev_type)
3090 os_memcpy(peer_info.pri_dev_type,
3091 data->p2p_dev_found.pri_dev_type,
3092 sizeof(peer_info.pri_dev_type));
3093 if (data->p2p_dev_found.dev_name)
3094 os_strlcpy(peer_info.device_name,
3095 data->p2p_dev_found.dev_name,
3096 sizeof(peer_info.device_name));
3097 peer_info.config_methods = data->p2p_dev_found.config_methods;
3098 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
3099 peer_info.group_capab = data->p2p_dev_found.group_capab;
3100
3101 /*
3102 * FIX: new_device=1 is not necessarily correct. We should
3103 * maintain a P2P peer database in wpa_supplicant and update
3104 * this information based on whether the peer is truly new.
3105 */
3106 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
3107 break;
3108 }
3109 case EVENT_P2P_GO_NEG_REQ_RX:
3110 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
3111 data->p2p_go_neg_req_rx.dev_passwd_id);
3112 break;
3113 case EVENT_P2P_GO_NEG_COMPLETED:
3114 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
3115 break;
3116 case EVENT_P2P_PROV_DISC_REQUEST:
3117 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
3118 data->p2p_prov_disc_req.config_methods,
3119 data->p2p_prov_disc_req.dev_addr,
3120 data->p2p_prov_disc_req.pri_dev_type,
3121 data->p2p_prov_disc_req.dev_name,
3122 data->p2p_prov_disc_req.supp_config_methods,
3123 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003124 data->p2p_prov_disc_req.group_capab,
3125 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003126 break;
3127 case EVENT_P2P_PROV_DISC_RESPONSE:
3128 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
3129 data->p2p_prov_disc_resp.config_methods);
3130 break;
3131 case EVENT_P2P_SD_REQUEST:
3132 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
3133 data->p2p_sd_req.sa,
3134 data->p2p_sd_req.dialog_token,
3135 data->p2p_sd_req.update_indic,
3136 data->p2p_sd_req.tlvs,
3137 data->p2p_sd_req.tlvs_len);
3138 break;
3139 case EVENT_P2P_SD_RESPONSE:
3140 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
3141 data->p2p_sd_resp.update_indic,
3142 data->p2p_sd_resp.tlvs,
3143 data->p2p_sd_resp.tlvs_len);
3144 break;
3145#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003146 case EVENT_EAPOL_RX:
3147 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3148 data->eapol_rx.data,
3149 data->eapol_rx.data_len);
3150 break;
3151 case EVENT_SIGNAL_CHANGE:
3152 bgscan_notify_signal_change(
3153 wpa_s, data->signal_change.above_threshold,
3154 data->signal_change.current_signal,
3155 data->signal_change.current_noise,
3156 data->signal_change.current_txrate);
3157 break;
3158 case EVENT_INTERFACE_ENABLED:
3159 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3160 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003161 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003162#ifdef CONFIG_AP
3163 if (!wpa_s->ap_iface) {
3164 wpa_supplicant_set_state(wpa_s,
3165 WPA_DISCONNECTED);
3166 wpa_supplicant_req_scan(wpa_s, 0, 0);
3167 } else
3168 wpa_supplicant_set_state(wpa_s,
3169 WPA_COMPLETED);
3170#else /* CONFIG_AP */
3171 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3172 wpa_supplicant_req_scan(wpa_s, 0, 0);
3173#endif /* CONFIG_AP */
3174 }
3175 break;
3176 case EVENT_INTERFACE_DISABLED:
3177 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003178#ifdef CONFIG_P2P
3179 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3180 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3181 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3182 /*
3183 * The interface was externally disabled. Remove
3184 * it assuming an external entity will start a
3185 * new session if needed.
3186 */
3187 wpas_p2p_disconnect(wpa_s);
3188 break;
3189 }
3190#endif /* CONFIG_P2P */
3191
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003192 wpa_supplicant_mark_disassoc(wpa_s);
3193 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3194 break;
3195 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003196 wpa_supplicant_update_channel_list(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003197 break;
3198 case EVENT_INTERFACE_UNAVAILABLE:
3199#ifdef CONFIG_P2P
3200 wpas_p2p_interface_unavailable(wpa_s);
3201#endif /* CONFIG_P2P */
3202 break;
3203 case EVENT_BEST_CHANNEL:
3204 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3205 "(%d %d %d)",
3206 data->best_chan.freq_24, data->best_chan.freq_5,
3207 data->best_chan.freq_overall);
3208 wpa_s->best_24_freq = data->best_chan.freq_24;
3209 wpa_s->best_5_freq = data->best_chan.freq_5;
3210 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3211#ifdef CONFIG_P2P
3212 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3213 data->best_chan.freq_5,
3214 data->best_chan.freq_overall);
3215#endif /* CONFIG_P2P */
3216 break;
3217 case EVENT_UNPROT_DEAUTH:
3218 wpa_supplicant_event_unprot_deauth(wpa_s,
3219 &data->unprot_deauth);
3220 break;
3221 case EVENT_UNPROT_DISASSOC:
3222 wpa_supplicant_event_unprot_disassoc(wpa_s,
3223 &data->unprot_disassoc);
3224 break;
3225 case EVENT_STATION_LOW_ACK:
3226#ifdef CONFIG_AP
3227 if (wpa_s->ap_iface && data)
3228 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3229 data->low_ack.addr);
3230#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003231#ifdef CONFIG_TDLS
3232 if (data)
3233 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3234#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003235 break;
3236 case EVENT_IBSS_PEER_LOST:
3237#ifdef CONFIG_IBSS_RSN
3238 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3239#endif /* CONFIG_IBSS_RSN */
3240 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003241 case EVENT_DRIVER_GTK_REKEY:
3242 if (os_memcmp(data->driver_gtk_rekey.bssid,
3243 wpa_s->bssid, ETH_ALEN))
3244 break;
3245 if (!wpa_s->wpa)
3246 break;
3247 wpa_sm_update_replay_ctr(wpa_s->wpa,
3248 data->driver_gtk_rekey.replay_ctr);
3249 break;
3250 case EVENT_SCHED_SCAN_STOPPED:
3251 wpa_s->sched_scanning = 0;
3252 wpa_supplicant_notify_scanning(wpa_s, 0);
3253
3254 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3255 break;
3256
3257 /*
3258 * If we timed out, start a new sched scan to continue
3259 * searching for more SSIDs.
3260 */
3261 if (wpa_s->sched_scan_timed_out)
3262 wpa_supplicant_req_sched_scan(wpa_s);
3263 break;
3264 case EVENT_WPS_BUTTON_PUSHED:
3265#ifdef CONFIG_WPS
3266 wpas_wps_start_pbc(wpa_s, NULL, 0);
3267#endif /* CONFIG_WPS */
3268 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003269 case EVENT_CONNECT_FAILED_REASON:
3270#ifdef CONFIG_AP
3271 if (!wpa_s->ap_iface || !data)
3272 break;
3273 hostapd_event_connect_failed_reason(
3274 wpa_s->ap_iface->bss[0],
3275 data->connect_failed_reason.addr,
3276 data->connect_failed_reason.code);
3277#endif /* CONFIG_AP */
3278 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003279 default:
3280 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3281 break;
3282 }
3283}