blob: 49c4058a2d2df284a1781f15d22e97d346f4cabe [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003 * Copyright (c) 2003-2014, 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{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080056 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070057
58 if (ssid == NULL || ssid->disabled_until.sec == 0)
59 return 0;
60
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080061 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070062 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);
981 return;
982 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800983
984 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700985 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
986}
987
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800988
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700989int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800990 struct wpa_bss *selected,
991 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992{
993 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
994 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
995 "PBC session overlap");
996#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800997 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700998 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700999#endif /* CONFIG_P2P */
1000
1001#ifdef CONFIG_WPS
1002 wpas_wps_cancel(wpa_s);
1003#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001004 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001005 }
1006
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001007 wpa_msg(wpa_s, MSG_DEBUG,
1008 "Considering connect request: reassociate: %d selected: "
1009 MACSTR " bssid: " MACSTR " pending: " MACSTR
1010 " wpa_state: %s ssid=%p current_ssid=%p",
1011 wpa_s->reassociate, MAC2STR(selected->bssid),
1012 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1013 wpa_supplicant_state_txt(wpa_s->wpa_state),
1014 ssid, wpa_s->current_ssid);
1015
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001016 /*
1017 * Do not trigger new association unless the BSSID has changed or if
1018 * reassociation is requested. If we are in process of associating with
1019 * the selected BSSID, do not trigger new attempt.
1020 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001021 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001022 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1023 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1024 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001025 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1026 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1027 0) ||
1028 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1029 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001030 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1031 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001032 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001033 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001034 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1035 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001036 wpa_supplicant_associate(wpa_s, selected, ssid);
1037 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001038 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1039 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001041
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001042 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001043}
1044
1045
1046static struct wpa_ssid *
1047wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1048{
1049 int prio;
1050 struct wpa_ssid *ssid;
1051
1052 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1053 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1054 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001055 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001056 continue;
1057 if (ssid->mode == IEEE80211_MODE_IBSS ||
1058 ssid->mode == IEEE80211_MODE_AP)
1059 return ssid;
1060 }
1061 }
1062 return NULL;
1063}
1064
1065
1066/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1067 * on BSS added and BSS changed events */
1068static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001069 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001070{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001071 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001072
1073 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1074 return;
1075
Jouni Malinen87fd2792011-05-16 18:35:42 +03001076 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001077 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001078
Jouni Malinen87fd2792011-05-16 18:35:42 +03001079 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001080 if (ssid == NULL)
1081 continue;
1082
Jouni Malinen87fd2792011-05-16 18:35:42 +03001083 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001084 if (rsn == NULL)
1085 continue;
1086
Jouni Malinen87fd2792011-05-16 18:35:42 +03001087 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088 }
1089
1090}
1091
1092
1093static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1094 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001095 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001096{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001097 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001098 int min_diff;
1099
1100 if (wpa_s->reassociate)
1101 return 1; /* explicit request to reassociate */
1102 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1103 return 1; /* we are not associated; continue */
1104 if (wpa_s->current_ssid == NULL)
1105 return 1; /* unknown current SSID */
1106 if (wpa_s->current_ssid != ssid)
1107 return 1; /* different network block */
1108
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001109 if (wpas_driver_bss_selection(wpa_s))
1110 return 0; /* Driver-based roaming */
1111
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001112 if (wpa_s->current_ssid->ssid)
1113 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1114 wpa_s->current_ssid->ssid,
1115 wpa_s->current_ssid->ssid_len);
1116 if (!current_bss)
1117 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001118
1119 if (!current_bss)
1120 return 1; /* current BSS not seen in scan results */
1121
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001122 if (current_bss == selected)
1123 return 0;
1124
1125 if (selected->last_update_idx > current_bss->last_update_idx)
1126 return 1; /* current BSS not seen in the last scan */
1127
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001128#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001129 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1130 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1131 MAC2STR(current_bss->bssid), current_bss->level);
1132 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1133 MAC2STR(selected->bssid), selected->level);
1134
1135 if (wpa_s->current_ssid->bssid_set &&
1136 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1137 0) {
1138 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1139 "has preferred BSSID");
1140 return 1;
1141 }
1142
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001143 if (current_bss->level < 0 && current_bss->level > selected->level) {
1144 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1145 "signal level");
1146 return 0;
1147 }
1148
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001149 min_diff = 2;
1150 if (current_bss->level < 0) {
1151 if (current_bss->level < -85)
1152 min_diff = 1;
1153 else if (current_bss->level < -80)
1154 min_diff = 2;
1155 else if (current_bss->level < -75)
1156 min_diff = 3;
1157 else if (current_bss->level < -70)
1158 min_diff = 4;
1159 else
1160 min_diff = 5;
1161 }
1162 if (abs(current_bss->level - selected->level) < min_diff) {
1163 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1164 "in signal level");
1165 return 0;
1166 }
1167
1168 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001169#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001170 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001171#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001172}
1173
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001174
Jouni Malinen89ca7022012-09-14 13:03:12 -07001175/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001176 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001177static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001178 union wpa_event_data *data,
1179 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001180{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001181 struct wpa_scan_results *scan_res = NULL;
1182 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001183 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001184#ifndef CONFIG_NO_RANDOM_POOL
1185 size_t i, num;
1186#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001187
1188#ifdef CONFIG_AP
1189 if (wpa_s->ap_iface)
1190 ap = 1;
1191#endif /* CONFIG_AP */
1192
1193 wpa_supplicant_notify_scanning(wpa_s, 0);
1194
1195 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1196 data ? &data->scan_info :
1197 NULL, 1);
1198 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001199 if (wpa_s->conf->ap_scan == 2 || ap ||
1200 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001201 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001202 if (!own_request)
1203 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001204 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1205 "scanning again");
1206 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001207 ret = -1;
1208 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001209 }
1210
1211#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001212 num = scan_res->num;
1213 if (num > 10)
1214 num = 10;
1215 for (i = 0; i < num; i++) {
1216 u8 buf[5];
1217 struct wpa_scan_res *res = scan_res->res[i];
1218 buf[0] = res->bssid[5];
1219 buf[1] = res->qual & 0xff;
1220 buf[2] = res->noise & 0xff;
1221 buf[3] = res->level & 0xff;
1222 buf[4] = res->tsf & 0xff;
1223 random_add_randomness(buf, sizeof(buf));
1224 }
1225#endif /* CONFIG_NO_RANDOM_POOL */
1226
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001227 if (own_request && wpa_s->scan_res_handler &&
1228 (wpa_s->own_scan_running || !wpa_s->external_scan_running)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001229 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1230 struct wpa_scan_results *scan_res);
1231
1232 scan_res_handler = wpa_s->scan_res_handler;
1233 wpa_s->scan_res_handler = NULL;
1234 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001235 ret = -2;
1236 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001237 }
1238
1239 if (ap) {
1240 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1241#ifdef CONFIG_AP
1242 if (wpa_s->ap_iface->scan_cb)
1243 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1244#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001245 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001247
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001248 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
1249 wpa_s->own_scan_running, wpa_s->external_scan_running);
1250 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1251 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1252 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1253 wpa_s->manual_scan_id);
1254 wpa_s->manual_scan_use_id = 0;
1255 } else {
1256 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1257 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001258 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001259
1260 wpas_notify_scan_done(wpa_s, 1);
1261
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001262 if (!wpa_s->own_scan_running && wpa_s->external_scan_running) {
1263 wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
Dmitry Shmidt04949592012-07-19 12:16:46 -07001264 wpa_scan_results_free(scan_res);
1265 return 0;
1266 }
1267
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001268 if (sme_proc_obss_scan(wpa_s) > 0)
1269 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001270
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001271 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1272 goto scan_work_done;
1273
1274 if (autoscan_notify_scan(wpa_s, scan_res))
1275 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001276
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001277 if (wpa_s->disconnected) {
1278 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001279 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001280 }
1281
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001282 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001283 bgscan_notify_scan(wpa_s, scan_res) == 1)
1284 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001285
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001286 wpas_wps_update_ap_info(wpa_s, scan_res);
1287
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001288 wpa_scan_results_free(scan_res);
1289
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001290 if (wpa_s->scan_work) {
1291 struct wpa_radio_work *work = wpa_s->scan_work;
1292 wpa_s->scan_work = NULL;
1293 radio_work_done(work);
1294 }
1295
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001296 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001297
1298scan_work_done:
1299 wpa_scan_results_free(scan_res);
1300 if (wpa_s->scan_work) {
1301 struct wpa_radio_work *work = wpa_s->scan_work;
1302 wpa_s->scan_work = NULL;
1303 radio_work_done(work);
1304 }
1305 return ret;
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 Shmidtfb79edc2014-01-10 10:45:54 -08001384#ifdef CONFIG_WPS
1385 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1386 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1387 timeout_sec = 0;
1388 timeout_usec = 500000;
1389 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1390 timeout_usec);
1391 return 0;
1392 }
1393#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001394 if (wpa_supplicant_req_sched_scan(wpa_s))
1395 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1396 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001397 }
1398 }
1399 return 0;
1400}
1401
1402
1403static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1404 union wpa_event_data *data)
1405{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001406 struct wpa_supplicant *ifs;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001407
1408 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001409 /*
1410 * If no scan results could be fetched, then no need to
1411 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001412 * this scan. Similarly, if scan results started a new operation on this
1413 * interface, do not notify other interfaces to avoid concurrent
1414 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001415 */
1416 return;
1417 }
1418
1419 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001420 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001421 * so, they get updated with this same scan info.
1422 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001423 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1424 radio_list) {
1425 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001426 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1427 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001428 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001429 }
1430 }
1431}
1432
1433#endif /* CONFIG_NO_SCAN_PROCESSING */
1434
1435
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001436int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1437{
1438#ifdef CONFIG_NO_SCAN_PROCESSING
1439 return -1;
1440#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001441 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001442
1443 if (wpa_s->last_scan_res_used <= 0)
1444 return -1;
1445
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001446 os_get_reltime(&now);
1447 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001448 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1449 return -1;
1450 }
1451
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001452 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001453#endif /* CONFIG_NO_SCAN_PROCESSING */
1454}
1455
Dmitry Shmidt04949592012-07-19 12:16:46 -07001456#ifdef CONFIG_WNM
1457
1458static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1459{
1460 struct wpa_supplicant *wpa_s = eloop_ctx;
1461
1462 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1463 return;
1464
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001465 if (!wpa_s->no_keep_alive) {
1466 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1467 MAC2STR(wpa_s->bssid));
1468 /* TODO: could skip this if normal data traffic has been sent */
1469 /* TODO: Consider using some more appropriate data frame for
1470 * this */
1471 if (wpa_s->l2)
1472 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1473 (u8 *) "", 0);
1474 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001475
1476#ifdef CONFIG_SME
1477 if (wpa_s->sme.bss_max_idle_period) {
1478 unsigned int msec;
1479 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1480 if (msec > 100)
1481 msec -= 100;
1482 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1483 wnm_bss_keep_alive, wpa_s, NULL);
1484 }
1485#endif /* CONFIG_SME */
1486}
1487
1488
1489static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1490 const u8 *ies, size_t ies_len)
1491{
1492 struct ieee802_11_elems elems;
1493
1494 if (ies == NULL)
1495 return;
1496
1497 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1498 return;
1499
1500#ifdef CONFIG_SME
1501 if (elems.bss_max_idle_period) {
1502 unsigned int msec;
1503 wpa_s->sme.bss_max_idle_period =
1504 WPA_GET_LE16(elems.bss_max_idle_period);
1505 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1506 "TU)%s", wpa_s->sme.bss_max_idle_period,
1507 (elems.bss_max_idle_period[2] & 0x01) ?
1508 " (protected keep-live required)" : "");
1509 if (wpa_s->sme.bss_max_idle_period == 0)
1510 wpa_s->sme.bss_max_idle_period = 1;
1511 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1512 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1513 /* msec times 1000 */
1514 msec = wpa_s->sme.bss_max_idle_period * 1024;
1515 if (msec > 100)
1516 msec -= 100;
1517 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1518 wnm_bss_keep_alive, wpa_s,
1519 NULL);
1520 }
1521 }
1522#endif /* CONFIG_SME */
1523}
1524
1525#endif /* CONFIG_WNM */
1526
1527
1528void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1529{
1530#ifdef CONFIG_WNM
1531 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1532#endif /* CONFIG_WNM */
1533}
1534
1535
Dmitry Shmidt051af732013-10-22 13:52:46 -07001536#ifdef CONFIG_INTERWORKING
1537
1538static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1539 size_t len)
1540{
1541 int res;
1542
1543 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1544 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1545 if (res) {
1546 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1547 }
1548
1549 return res;
1550}
1551
1552
1553static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1554 const u8 *ies, size_t ies_len)
1555{
1556 struct ieee802_11_elems elems;
1557
1558 if (ies == NULL)
1559 return;
1560
1561 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1562 return;
1563
1564 if (elems.qos_map_set) {
1565 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1566 elems.qos_map_set_len);
1567 }
1568}
1569
1570#endif /* CONFIG_INTERWORKING */
1571
1572
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001573static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1574 union wpa_event_data *data)
1575{
1576 int l, len, found = 0, wpa_found, rsn_found;
1577 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001578#ifdef CONFIG_IEEE80211R
1579 u8 bssid[ETH_ALEN];
1580#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001581
1582 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1583 if (data->assoc_info.req_ies)
1584 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1585 data->assoc_info.req_ies_len);
1586 if (data->assoc_info.resp_ies) {
1587 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1588 data->assoc_info.resp_ies_len);
1589#ifdef CONFIG_TDLS
1590 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1591 data->assoc_info.resp_ies_len);
1592#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001593#ifdef CONFIG_WNM
1594 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1595 data->assoc_info.resp_ies_len);
1596#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001597#ifdef CONFIG_INTERWORKING
1598 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1599 data->assoc_info.resp_ies_len);
1600#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001601 }
1602 if (data->assoc_info.beacon_ies)
1603 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1604 data->assoc_info.beacon_ies,
1605 data->assoc_info.beacon_ies_len);
1606 if (data->assoc_info.freq)
1607 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1608 data->assoc_info.freq);
1609
1610 p = data->assoc_info.req_ies;
1611 l = data->assoc_info.req_ies_len;
1612
1613 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1614 while (p && l >= 2) {
1615 len = p[1] + 2;
1616 if (len > l) {
1617 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1618 p, l);
1619 break;
1620 }
1621 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1622 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1623 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1624 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1625 break;
1626 found = 1;
1627 wpa_find_assoc_pmkid(wpa_s);
1628 break;
1629 }
1630 l -= len;
1631 p += len;
1632 }
1633 if (!found && data->assoc_info.req_ies)
1634 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1635
1636#ifdef CONFIG_IEEE80211R
1637#ifdef CONFIG_SME
1638 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001639 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1640 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1641 data->assoc_info.resp_ies,
1642 data->assoc_info.resp_ies_len,
1643 bssid) < 0) {
1644 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1645 "Reassociation Response failed");
1646 wpa_supplicant_deauthenticate(
1647 wpa_s, WLAN_REASON_INVALID_IE);
1648 return -1;
1649 }
1650 }
1651
1652 p = data->assoc_info.resp_ies;
1653 l = data->assoc_info.resp_ies_len;
1654
1655#ifdef CONFIG_WPS_STRICT
1656 if (p && wpa_s->current_ssid &&
1657 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1658 struct wpabuf *wps;
1659 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1660 if (wps == NULL) {
1661 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1662 "include WPS IE in (Re)Association Response");
1663 return -1;
1664 }
1665
1666 if (wps_validate_assoc_resp(wps) < 0) {
1667 wpabuf_free(wps);
1668 wpa_supplicant_deauthenticate(
1669 wpa_s, WLAN_REASON_INVALID_IE);
1670 return -1;
1671 }
1672 wpabuf_free(wps);
1673 }
1674#endif /* CONFIG_WPS_STRICT */
1675
1676 /* Go through the IEs and make a copy of the MDIE, if present. */
1677 while (p && l >= 2) {
1678 len = p[1] + 2;
1679 if (len > l) {
1680 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1681 p, l);
1682 break;
1683 }
1684 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1685 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1686 wpa_s->sme.ft_used = 1;
1687 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1688 MOBILITY_DOMAIN_ID_LEN);
1689 break;
1690 }
1691 l -= len;
1692 p += len;
1693 }
1694#endif /* CONFIG_SME */
1695
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001696 /* Process FT when SME is in the driver */
1697 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1698 wpa_ft_is_completed(wpa_s->wpa)) {
1699 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1700 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1701 data->assoc_info.resp_ies,
1702 data->assoc_info.resp_ies_len,
1703 bssid) < 0) {
1704 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1705 "Reassociation Response failed");
1706 wpa_supplicant_deauthenticate(
1707 wpa_s, WLAN_REASON_INVALID_IE);
1708 return -1;
1709 }
1710 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1711 }
1712
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001713 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1714 data->assoc_info.resp_ies_len);
1715#endif /* CONFIG_IEEE80211R */
1716
1717 /* WPA/RSN IE from Beacon/ProbeResp */
1718 p = data->assoc_info.beacon_ies;
1719 l = data->assoc_info.beacon_ies_len;
1720
1721 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1722 */
1723 wpa_found = rsn_found = 0;
1724 while (p && l >= 2) {
1725 len = p[1] + 2;
1726 if (len > l) {
1727 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1728 p, l);
1729 break;
1730 }
1731 if (!wpa_found &&
1732 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1733 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1734 wpa_found = 1;
1735 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1736 }
1737
1738 if (!rsn_found &&
1739 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1740 rsn_found = 1;
1741 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1742 }
1743
1744 l -= len;
1745 p += len;
1746 }
1747
1748 if (!wpa_found && data->assoc_info.beacon_ies)
1749 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1750 if (!rsn_found && data->assoc_info.beacon_ies)
1751 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1752 if (wpa_found || rsn_found)
1753 wpa_s->ap_ies_from_associnfo = 1;
1754
Jouni Malinen87fd2792011-05-16 18:35:42 +03001755 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1756 wpa_s->assoc_freq != data->assoc_info.freq) {
1757 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1758 "%u to %u MHz",
1759 wpa_s->assoc_freq, data->assoc_info.freq);
1760 wpa_supplicant_update_scan_results(wpa_s);
1761 }
1762
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001763 wpa_s->assoc_freq = data->assoc_info.freq;
1764
1765 return 0;
1766}
1767
1768
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001769static struct wpa_bss * wpa_supplicant_get_new_bss(
1770 struct wpa_supplicant *wpa_s, const u8 *bssid)
1771{
1772 struct wpa_bss *bss = NULL;
1773 struct wpa_ssid *ssid = wpa_s->current_ssid;
1774
1775 if (ssid->ssid_len > 0)
1776 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1777 if (!bss)
1778 bss = wpa_bss_get_bssid(wpa_s, bssid);
1779
1780 return bss;
1781}
1782
1783
1784static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1785{
1786 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1787
1788 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1789 return -1;
1790
1791 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1792 return 0;
1793
1794 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1795 WPA_IE_VENDOR_TYPE);
1796 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1797
1798 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1799 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1800 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1801 bss_rsn ? 2 + bss_rsn[1] : 0))
1802 return -1;
1803
1804 return 0;
1805}
1806
1807
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001808static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1809 union wpa_event_data *data)
1810{
1811 u8 bssid[ETH_ALEN];
1812 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001813
1814#ifdef CONFIG_AP
1815 if (wpa_s->ap_iface) {
1816 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1817 data->assoc_info.addr,
1818 data->assoc_info.req_ies,
1819 data->assoc_info.req_ies_len,
1820 data->assoc_info.reassoc);
1821 return;
1822 }
1823#endif /* CONFIG_AP */
1824
1825 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1826 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1827 return;
1828
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001829 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1830 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001831 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001832 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1833 return;
1834 }
1835
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001836 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001837 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1839 MACSTR, MAC2STR(bssid));
1840 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1842 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001843 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001844
1845 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1846 wpa_clear_keys(wpa_s, bssid);
1847 }
1848 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001849 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001850 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1851 return;
1852 }
1853 if (wpa_s->current_ssid) {
1854 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001855
1856 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1857 if (!bss) {
1858 wpa_supplicant_update_scan_results(wpa_s);
1859
1860 /* Get the BSS from the new scan results */
1861 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1862 }
1863
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001864 if (bss)
1865 wpa_s->current_bss = bss;
1866 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001867
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001868#ifdef ANDROID
1869 if (wpa_s->conf->ap_scan == 1) {
1870#else
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001871 if (wpa_s->conf->ap_scan == 1 &&
1872 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001873#endif
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001874 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1875 wpa_msg(wpa_s, MSG_WARNING,
1876 "WPA/RSN IEs not updated");
1877 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001878 }
1879
1880#ifdef CONFIG_SME
1881 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1882 wpa_s->sme.prev_bssid_set = 1;
1883#endif /* CONFIG_SME */
1884
1885 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1886 if (wpa_s->current_ssid) {
1887 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1888 * initialized before association, but for other modes,
1889 * initialize PC/SC here, if the current configuration needs
1890 * smartcard or SIM/USIM. */
1891 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1892 }
1893 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1894 if (wpa_s->l2)
1895 l2_packet_notify_auth_start(wpa_s->l2);
1896
1897 /*
1898 * Set portEnabled first to FALSE in order to get EAP state machine out
1899 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1900 * state machine may transit to AUTHENTICATING state based on obsolete
1901 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1902 * AUTHENTICATED without ever giving chance to EAP state machine to
1903 * reset the state.
1904 */
1905 if (!ft_completed) {
1906 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1907 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1908 }
1909 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1910 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1911 /* 802.1X::portControl = Auto */
1912 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1913 wpa_s->eapol_received = 0;
1914 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1915 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1916 (wpa_s->current_ssid &&
1917 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001918 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1919 (wpa_s->drv_flags &
1920 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1921 /*
1922 * Set the key after having received joined-IBSS event
1923 * from the driver.
1924 */
1925 wpa_supplicant_set_wpa_none_key(wpa_s,
1926 wpa_s->current_ssid);
1927 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001928 wpa_supplicant_cancel_auth_timeout(wpa_s);
1929 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1930 } else if (!ft_completed) {
1931 /* Timeout for receiving the first EAPOL packet */
1932 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1933 }
1934 wpa_supplicant_cancel_scan(wpa_s);
1935
1936 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1937 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1938 /*
1939 * We are done; the driver will take care of RSN 4-way
1940 * handshake.
1941 */
1942 wpa_supplicant_cancel_auth_timeout(wpa_s);
1943 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1944 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1945 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1946 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1947 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1948 /*
1949 * The driver will take care of RSN 4-way handshake, so we need
1950 * to allow EAPOL supplicant to complete its work without
1951 * waiting for WPA supplicant.
1952 */
1953 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1954 } else if (ft_completed) {
1955 /*
1956 * FT protocol completed - make sure EAPOL state machine ends
1957 * up in authenticated.
1958 */
1959 wpa_supplicant_cancel_auth_timeout(wpa_s);
1960 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1961 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1962 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1963 }
1964
Jouni Malinena05074c2012-12-21 21:35:35 +02001965 wpa_s->last_eapol_matches_bssid = 0;
1966
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001967 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001968 struct os_reltime now, age;
1969 os_get_reltime(&now);
1970 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001971 if (age.sec == 0 && age.usec < 100000 &&
1972 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1973 0) {
1974 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1975 "frame that was received just before "
1976 "association notification");
1977 wpa_supplicant_rx_eapol(
1978 wpa_s, wpa_s->pending_eapol_rx_src,
1979 wpabuf_head(wpa_s->pending_eapol_rx),
1980 wpabuf_len(wpa_s->pending_eapol_rx));
1981 }
1982 wpabuf_free(wpa_s->pending_eapol_rx);
1983 wpa_s->pending_eapol_rx = NULL;
1984 }
1985
1986 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1987 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001988 wpa_s->current_ssid &&
1989 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001990 /* Set static WEP keys again */
1991 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1992 }
1993
1994#ifdef CONFIG_IBSS_RSN
1995 if (wpa_s->current_ssid &&
1996 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1997 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1998 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1999 wpa_s->ibss_rsn == NULL) {
2000 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2001 if (!wpa_s->ibss_rsn) {
2002 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2003 wpa_supplicant_deauthenticate(
2004 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2005 return;
2006 }
2007
2008 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2009 }
2010#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002011
2012 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002013}
2014
2015
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002016static int disconnect_reason_recoverable(u16 reason_code)
2017{
2018 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2019 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2020 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2021}
2022
2023
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002024static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002025 u16 reason_code,
2026 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002027{
2028 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002029
2030 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2031 /*
2032 * At least Host AP driver and a Prism3 card seemed to be
2033 * generating streams of disconnected events when configuring
2034 * IBSS for WPA-None. Ignore them for now.
2035 */
2036 return;
2037 }
2038
2039 bssid = wpa_s->bssid;
2040 if (is_zero_ether_addr(bssid))
2041 bssid = wpa_s->pending_bssid;
2042
2043 if (!is_zero_ether_addr(bssid) ||
2044 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2045 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2046 " reason=%d%s",
2047 MAC2STR(bssid), reason_code,
2048 locally_generated ? " locally_generated=1" : "");
2049 }
2050}
2051
2052
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002053static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2054 int locally_generated)
2055{
2056 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2057 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2058 return 0; /* Not in 4-way handshake with PSK */
2059
2060 /*
2061 * It looks like connection was lost while trying to go through PSK
2062 * 4-way handshake. Filter out known disconnection cases that are caused
2063 * by something else than PSK mismatch to avoid confusing reports.
2064 */
2065
2066 if (locally_generated) {
2067 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2068 return 0;
2069 }
2070
2071 return 1;
2072}
2073
2074
Jouni Malinen2b89da82012-08-31 22:04:41 +03002075static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2076 u16 reason_code,
2077 int locally_generated)
2078{
2079 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002080 int authenticating;
2081 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002082 struct wpa_bss *fast_reconnect = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002083#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002084 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002085#endif /* CONFIG_NO_SCAN_PROCESSING */
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002086 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002087
2088 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2089 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2090
2091 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2092 /*
2093 * At least Host AP driver and a Prism3 card seemed to be
2094 * generating streams of disconnected events when configuring
2095 * IBSS for WPA-None. Ignore them for now.
2096 */
2097 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2098 "IBSS/WPA-None mode");
2099 return;
2100 }
2101
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002102 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002103 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2104 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002105 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2106 return; /* P2P group removed */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002107 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002108 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002109 if (!wpa_s->disconnected &&
2110 (!wpa_s->auto_reconnect_disabled ||
2111 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002112 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2113 "reconnect (wps=%d wpa_state=%d)",
2114 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2115 wpa_s->wpa_state);
2116 if (wpa_s->wpa_state == WPA_COMPLETED &&
2117 wpa_s->current_ssid &&
2118 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002119 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002120 disconnect_reason_recoverable(reason_code)) {
2121 /*
2122 * It looks like the AP has dropped association with
2123 * us, but could allow us to get back in. Try to
2124 * reconnect to the same BSS without full scan to save
2125 * time for some common cases.
2126 */
2127 fast_reconnect = wpa_s->current_bss;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002128#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002129 fast_reconnect_ssid = wpa_s->current_ssid;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002130#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002131 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002132 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002133 else
2134 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2135 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002136 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002137 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002138 "try to re-connect");
2139 wpa_s->reassociate = 0;
2140 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002141 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002142 }
2143 bssid = wpa_s->bssid;
2144 if (is_zero_ether_addr(bssid))
2145 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002146 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2147 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002148 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002149 if (locally_generated)
2150 wpa_s->disconnect_reason = -reason_code;
2151 else
2152 wpa_s->disconnect_reason = reason_code;
2153 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002154 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2155 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002156 wpa_clear_keys(wpa_s, wpa_s->bssid);
2157 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002158 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002159 wpa_supplicant_mark_disassoc(wpa_s);
2160
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002161 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002162 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002163 wpa_s->current_ssid = last_ssid;
2164 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002165
2166 if (fast_reconnect) {
2167#ifndef CONFIG_NO_SCAN_PROCESSING
2168 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2169 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2170 fast_reconnect_ssid) < 0) {
2171 /* Recover through full scan */
2172 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2173 }
2174#endif /* CONFIG_NO_SCAN_PROCESSING */
2175 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002176}
2177
2178
2179#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002180void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002181{
2182 struct wpa_supplicant *wpa_s = eloop_ctx;
2183
2184 if (!wpa_s->pending_mic_error_report)
2185 return;
2186
2187 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2188 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2189 wpa_s->pending_mic_error_report = 0;
2190}
2191#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2192
2193
2194static void
2195wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2196 union wpa_event_data *data)
2197{
2198 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002199 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002200
2201 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2202 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002203 os_get_reltime(&t);
2204 if ((wpa_s->last_michael_mic_error.sec &&
2205 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002206 wpa_s->pending_mic_error_report) {
2207 if (wpa_s->pending_mic_error_report) {
2208 /*
2209 * Send the pending MIC error report immediately since
2210 * we are going to start countermeasures and AP better
2211 * do the same.
2212 */
2213 wpa_sm_key_request(wpa_s->wpa, 1,
2214 wpa_s->pending_mic_error_pairwise);
2215 }
2216
2217 /* Send the new MIC error report immediately since we are going
2218 * to start countermeasures and AP better do the same.
2219 */
2220 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2221
2222 /* initialize countermeasures */
2223 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002224
2225 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2226
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002227 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2228
2229 /*
2230 * Need to wait for completion of request frame. We do not get
2231 * any callback for the message completion, so just wait a
2232 * short while and hope for the best. */
2233 os_sleep(0, 10000);
2234
2235 wpa_drv_set_countermeasures(wpa_s, 1);
2236 wpa_supplicant_deauthenticate(wpa_s,
2237 WLAN_REASON_MICHAEL_MIC_FAILURE);
2238 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2239 wpa_s, NULL);
2240 eloop_register_timeout(60, 0,
2241 wpa_supplicant_stop_countermeasures,
2242 wpa_s, NULL);
2243 /* TODO: mark the AP rejected for 60 second. STA is
2244 * allowed to associate with another AP.. */
2245 } else {
2246#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2247 if (wpa_s->mic_errors_seen) {
2248 /*
2249 * Reduce the effectiveness of Michael MIC error
2250 * reports as a means for attacking against TKIP if
2251 * more than one MIC failure is noticed with the same
2252 * PTK. We delay the transmission of the reports by a
2253 * random time between 0 and 60 seconds in order to
2254 * force the attacker wait 60 seconds before getting
2255 * the information on whether a frame resulted in a MIC
2256 * failure.
2257 */
2258 u8 rval[4];
2259 int sec;
2260
2261 if (os_get_random(rval, sizeof(rval)) < 0)
2262 sec = os_random() % 60;
2263 else
2264 sec = WPA_GET_BE32(rval) % 60;
2265 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2266 "report %d seconds", sec);
2267 wpa_s->pending_mic_error_report = 1;
2268 wpa_s->pending_mic_error_pairwise = pairwise;
2269 eloop_cancel_timeout(
2270 wpa_supplicant_delayed_mic_error_report,
2271 wpa_s, NULL);
2272 eloop_register_timeout(
2273 sec, os_random() % 1000000,
2274 wpa_supplicant_delayed_mic_error_report,
2275 wpa_s, NULL);
2276 } else {
2277 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2278 }
2279#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2280 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2281#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2282 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002283 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002284 wpa_s->mic_errors_seen++;
2285}
2286
2287
2288#ifdef CONFIG_TERMINATE_ONLASTIF
2289static int any_interfaces(struct wpa_supplicant *head)
2290{
2291 struct wpa_supplicant *wpa_s;
2292
2293 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2294 if (!wpa_s->interface_removed)
2295 return 1;
2296 return 0;
2297}
2298#endif /* CONFIG_TERMINATE_ONLASTIF */
2299
2300
2301static void
2302wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2303 union wpa_event_data *data)
2304{
2305 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2306 return;
2307
2308 switch (data->interface_status.ievent) {
2309 case EVENT_INTERFACE_ADDED:
2310 if (!wpa_s->interface_removed)
2311 break;
2312 wpa_s->interface_removed = 0;
2313 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2314 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2315 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2316 "driver after interface was added");
2317 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002318 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002319 break;
2320 case EVENT_INTERFACE_REMOVED:
2321 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2322 wpa_s->interface_removed = 1;
2323 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002324 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002325 l2_packet_deinit(wpa_s->l2);
2326 wpa_s->l2 = NULL;
2327#ifdef CONFIG_IBSS_RSN
2328 ibss_rsn_deinit(wpa_s->ibss_rsn);
2329 wpa_s->ibss_rsn = NULL;
2330#endif /* CONFIG_IBSS_RSN */
2331#ifdef CONFIG_TERMINATE_ONLASTIF
2332 /* check if last interface */
2333 if (!any_interfaces(wpa_s->global->ifaces))
2334 eloop_terminate();
2335#endif /* CONFIG_TERMINATE_ONLASTIF */
2336 break;
2337 }
2338}
2339
2340
2341#ifdef CONFIG_PEERKEY
2342static void
2343wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2344 union wpa_event_data *data)
2345{
2346 if (data == NULL)
2347 return;
2348 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2349}
2350#endif /* CONFIG_PEERKEY */
2351
2352
2353#ifdef CONFIG_TDLS
2354static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2355 union wpa_event_data *data)
2356{
2357 if (data == NULL)
2358 return;
2359 switch (data->tdls.oper) {
2360 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002361 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2362 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2363 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2364 else
2365 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002366 break;
2367 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002368 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2369 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2370 data->tdls.reason_code);
2371 else
2372 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2373 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002374 break;
2375 }
2376}
2377#endif /* CONFIG_TDLS */
2378
2379
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002380#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002381static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2382 union wpa_event_data *data)
2383{
2384 if (data == NULL)
2385 return;
2386 switch (data->wnm.oper) {
2387 case WNM_OPER_SLEEP:
2388 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2389 "(action=%d, intval=%d)",
2390 data->wnm.sleep_action, data->wnm.sleep_intval);
2391 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002392 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002393 break;
2394 }
2395}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002396#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002397
2398
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002399#ifdef CONFIG_IEEE80211R
2400static void
2401wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2402 union wpa_event_data *data)
2403{
2404 if (data == NULL)
2405 return;
2406
2407 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2408 data->ft_ies.ies_len,
2409 data->ft_ies.ft_action,
2410 data->ft_ies.target_ap,
2411 data->ft_ies.ric_ies,
2412 data->ft_ies.ric_ies_len) < 0) {
2413 /* TODO: prevent MLME/driver from trying to associate? */
2414 }
2415}
2416#endif /* CONFIG_IEEE80211R */
2417
2418
2419#ifdef CONFIG_IBSS_RSN
2420static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2421 union wpa_event_data *data)
2422{
2423 struct wpa_ssid *ssid;
2424 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2425 return;
2426 if (data == NULL)
2427 return;
2428 ssid = wpa_s->current_ssid;
2429 if (ssid == NULL)
2430 return;
2431 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2432 return;
2433
2434 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2435}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002436
2437
2438static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2439 union wpa_event_data *data)
2440{
2441 struct wpa_ssid *ssid = wpa_s->current_ssid;
2442
2443 if (ssid == NULL)
2444 return;
2445
2446 /* check if the ssid is correctly configured as IBSS/RSN */
2447 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2448 return;
2449
2450 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2451 data->rx_mgmt.frame_len);
2452}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002453#endif /* CONFIG_IBSS_RSN */
2454
2455
2456#ifdef CONFIG_IEEE80211R
2457static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2458 size_t len)
2459{
2460 const u8 *sta_addr, *target_ap_addr;
2461 u16 status;
2462
2463 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2464 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2465 return; /* only SME case supported for now */
2466 if (len < 1 + 2 * ETH_ALEN + 2)
2467 return;
2468 if (data[0] != 2)
2469 return; /* Only FT Action Response is supported for now */
2470 sta_addr = data + 1;
2471 target_ap_addr = data + 1 + ETH_ALEN;
2472 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2473 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2474 MACSTR " TargetAP " MACSTR " status %u",
2475 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2476
2477 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2478 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2479 " in FT Action Response", MAC2STR(sta_addr));
2480 return;
2481 }
2482
2483 if (status) {
2484 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2485 "failure (status code %d)", status);
2486 /* TODO: report error to FT code(?) */
2487 return;
2488 }
2489
2490 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2491 len - (1 + 2 * ETH_ALEN + 2), 1,
2492 target_ap_addr, NULL, 0) < 0)
2493 return;
2494
2495#ifdef CONFIG_SME
2496 {
2497 struct wpa_bss *bss;
2498 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2499 if (bss)
2500 wpa_s->sme.freq = bss->freq;
2501 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2502 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2503 WLAN_AUTH_FT);
2504 }
2505#endif /* CONFIG_SME */
2506}
2507#endif /* CONFIG_IEEE80211R */
2508
2509
2510static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2511 struct unprot_deauth *e)
2512{
2513#ifdef CONFIG_IEEE80211W
2514 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2515 "dropped: " MACSTR " -> " MACSTR
2516 " (reason code %u)",
2517 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2518 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2519#endif /* CONFIG_IEEE80211W */
2520}
2521
2522
2523static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2524 struct unprot_disassoc *e)
2525{
2526#ifdef CONFIG_IEEE80211W
2527 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2528 "dropped: " MACSTR " -> " MACSTR
2529 " (reason code %u)",
2530 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2531 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2532#endif /* CONFIG_IEEE80211W */
2533}
2534
2535
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002536static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2537 u16 reason_code, int locally_generated,
2538 const u8 *ie, size_t ie_len, int deauth)
2539{
2540#ifdef CONFIG_AP
2541 if (wpa_s->ap_iface && addr) {
2542 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2543 return;
2544 }
2545
2546 if (wpa_s->ap_iface) {
2547 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2548 return;
2549 }
2550#endif /* CONFIG_AP */
2551
2552 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2553
2554 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2555 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2556 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2557 eapol_sm_failed(wpa_s->eapol)))
2558 wpas_auth_failed(wpa_s);
2559
2560#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002561 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002562 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2563 locally_generated) > 0) {
2564 /*
2565 * The interface was removed, so cannot continue
2566 * processing any additional operations after this.
2567 */
2568 return;
2569 }
2570 }
2571#endif /* CONFIG_P2P */
2572
2573 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2574 locally_generated);
2575}
2576
2577
2578static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2579 struct disassoc_info *info)
2580{
2581 u16 reason_code = 0;
2582 int locally_generated = 0;
2583 const u8 *addr = NULL;
2584 const u8 *ie = NULL;
2585 size_t ie_len = 0;
2586
2587 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2588
2589 if (info) {
2590 addr = info->addr;
2591 ie = info->ie;
2592 ie_len = info->ie_len;
2593 reason_code = info->reason_code;
2594 locally_generated = info->locally_generated;
2595 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2596 locally_generated ? " (locally generated)" : "");
2597 if (addr)
2598 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2599 MAC2STR(addr));
2600 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2601 ie, ie_len);
2602 }
2603
2604#ifdef CONFIG_AP
2605 if (wpa_s->ap_iface && info && info->addr) {
2606 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2607 return;
2608 }
2609
2610 if (wpa_s->ap_iface) {
2611 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2612 return;
2613 }
2614#endif /* CONFIG_AP */
2615
2616#ifdef CONFIG_P2P
2617 if (info) {
2618 wpas_p2p_disassoc_notif(
2619 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2620 locally_generated);
2621 }
2622#endif /* CONFIG_P2P */
2623
2624 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2625 sme_event_disassoc(wpa_s, info);
2626
2627 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2628 ie, ie_len, 0);
2629}
2630
2631
2632static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2633 struct deauth_info *info)
2634{
2635 u16 reason_code = 0;
2636 int locally_generated = 0;
2637 const u8 *addr = NULL;
2638 const u8 *ie = NULL;
2639 size_t ie_len = 0;
2640
2641 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2642
2643 if (info) {
2644 addr = info->addr;
2645 ie = info->ie;
2646 ie_len = info->ie_len;
2647 reason_code = info->reason_code;
2648 locally_generated = info->locally_generated;
2649 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2650 reason_code,
2651 locally_generated ? " (locally generated)" : "");
2652 if (addr) {
2653 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2654 MAC2STR(addr));
2655 }
2656 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2657 ie, ie_len);
2658 }
2659
2660 wpa_reset_ft_completed(wpa_s->wpa);
2661
2662 wpas_event_disconnect(wpa_s, addr, reason_code,
2663 locally_generated, ie, ie_len, 1);
2664}
2665
2666
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002667static void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s)
2668{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002669 struct wpa_supplicant *ifs;
2670
2671 if (wpa_s->drv_priv == NULL)
2672 return; /* Ignore event during drv initialization */
2673
2674 free_hw_features(wpa_s);
2675 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2676 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2677
2678#ifdef CONFIG_P2P
2679 wpas_p2p_update_channel_list(wpa_s);
2680#endif /* CONFIG_P2P */
2681
2682 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002683 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002684 * so, they get updated with this same hw mode info.
2685 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002686 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2687 radio_list) {
2688 if (ifs != wpa_s) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002689 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2690 ifs->ifname);
2691 free_hw_features(ifs);
2692 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2693 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2694 }
2695 }
2696}
2697
2698
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002699static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
2700 const struct ieee80211_mgmt *mgmt,
2701 size_t len, int freq)
2702{
2703 const u8 *payload;
2704 size_t plen;
2705 u8 category;
2706
2707 if (len < IEEE80211_HDRLEN + 2)
2708 return;
2709
2710 payload = &mgmt->u.action.category;
2711 category = *payload++;
2712 plen = (((const u8 *) mgmt) + len) - payload;
2713
2714 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2715 " Category=%u DataLen=%d freq=%d MHz",
2716 MAC2STR(mgmt->sa), category, (int) plen, freq);
2717
2718#ifdef CONFIG_IEEE80211R
2719 if (category == WLAN_ACTION_FT) {
2720 ft_rx_action(wpa_s, payload, plen);
2721 return;
2722 }
2723#endif /* CONFIG_IEEE80211R */
2724
2725#ifdef CONFIG_IEEE80211W
2726#ifdef CONFIG_SME
2727 if (category == WLAN_ACTION_SA_QUERY) {
2728 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
2729 return;
2730 }
2731#endif /* CONFIG_SME */
2732#endif /* CONFIG_IEEE80211W */
2733
2734#ifdef CONFIG_WNM
2735 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
2736 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
2737 return;
2738 }
2739#endif /* CONFIG_WNM */
2740
2741#ifdef CONFIG_GAS
2742 if (mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
2743 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
2744 payload, plen, freq) == 0)
2745 return;
2746#endif /* CONFIG_GAS */
2747
2748#ifdef CONFIG_TDLS
2749 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
2750 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2751 wpa_dbg(wpa_s, MSG_DEBUG,
2752 "TDLS: Received Discovery Response from " MACSTR,
2753 MAC2STR(mgmt->sa));
2754 return;
2755 }
2756#endif /* CONFIG_TDLS */
2757
2758#ifdef CONFIG_INTERWORKING
2759 if (category == WLAN_ACTION_QOS && plen >= 1 &&
2760 payload[0] == QOS_QOS_MAP_CONFIG) {
2761 const u8 *pos = payload + 1;
2762 size_t qlen = plen - 1;
2763 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
2764 MACSTR, MAC2STR(mgmt->sa));
2765 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
2766 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
2767 pos[1] <= qlen - 2 && pos[1] >= 16)
2768 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
2769 return;
2770 }
2771#endif /* CONFIG_INTERWORKING */
2772
2773#ifdef CONFIG_P2P
2774 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
2775 category, payload, plen, freq);
2776#endif /* CONFIG_P2P */
2777}
2778
2779
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002780void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2781 union wpa_event_data *data)
2782{
2783 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002784
2785 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2786 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002787 event != EVENT_INTERFACE_STATUS &&
2788 event != EVENT_SCHED_SCAN_STOPPED) {
2789 wpa_dbg(wpa_s, MSG_DEBUG,
2790 "Ignore event %s (%d) while interface is disabled",
2791 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002792 return;
2793 }
2794
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002795#ifndef CONFIG_NO_STDOUT_DEBUG
2796{
2797 int level = MSG_DEBUG;
2798
Dmitry Shmidt04949592012-07-19 12:16:46 -07002799 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002800 const struct ieee80211_hdr *hdr;
2801 u16 fc;
2802 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2803 fc = le_to_host16(hdr->frame_control);
2804 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2805 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2806 level = MSG_EXCESSIVE;
2807 }
2808
2809 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2810 event_to_string(event), event);
2811}
2812#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002813
2814 switch (event) {
2815 case EVENT_AUTH:
2816 sme_event_auth(wpa_s, data);
2817 break;
2818 case EVENT_ASSOC:
2819 wpa_supplicant_event_assoc(wpa_s, data);
2820 break;
2821 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002822 wpas_event_disassoc(wpa_s,
2823 data ? &data->disassoc_info : NULL);
2824 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002825 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002826 wpas_event_deauth(wpa_s,
2827 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002828 break;
2829 case EVENT_MICHAEL_MIC_FAILURE:
2830 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2831 break;
2832#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002833 case EVENT_SCAN_STARTED:
2834 os_get_reltime(&wpa_s->scan_start_time);
2835 if (wpa_s->own_scan_requested) {
2836 struct os_reltime diff;
2837
2838 os_reltime_sub(&wpa_s->scan_start_time,
2839 &wpa_s->scan_trigger_time, &diff);
2840 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
2841 diff.sec, diff.usec);
2842 wpa_s->own_scan_requested = 0;
2843 wpa_s->own_scan_running = 1;
2844 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
2845 wpa_s->manual_scan_use_id) {
2846 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED "id=%u",
2847 wpa_s->manual_scan_id);
2848 } else {
2849 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
2850 }
2851 } else {
2852 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
2853 wpa_s->external_scan_running = 1;
2854 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
2855 }
2856 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002857 case EVENT_SCAN_RESULTS:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002858 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
2859 struct os_reltime now, diff;
2860 os_get_reltime(&now);
2861 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
2862 wpa_s->scan_start_time.sec = 0;
2863 wpa_s->scan_start_time.usec = 0;
2864 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
2865 diff.sec, diff.usec);
2866 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002867 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002868 wpa_s->own_scan_running = 0;
2869 wpa_s->external_scan_running = 0;
2870 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002871 break;
2872#endif /* CONFIG_NO_SCAN_PROCESSING */
2873 case EVENT_ASSOCINFO:
2874 wpa_supplicant_event_associnfo(wpa_s, data);
2875 break;
2876 case EVENT_INTERFACE_STATUS:
2877 wpa_supplicant_event_interface_status(wpa_s, data);
2878 break;
2879 case EVENT_PMKID_CANDIDATE:
2880 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2881 break;
2882#ifdef CONFIG_PEERKEY
2883 case EVENT_STKSTART:
2884 wpa_supplicant_event_stkstart(wpa_s, data);
2885 break;
2886#endif /* CONFIG_PEERKEY */
2887#ifdef CONFIG_TDLS
2888 case EVENT_TDLS:
2889 wpa_supplicant_event_tdls(wpa_s, data);
2890 break;
2891#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002892#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002893 case EVENT_WNM:
2894 wpa_supplicant_event_wnm(wpa_s, data);
2895 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002896#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002897#ifdef CONFIG_IEEE80211R
2898 case EVENT_FT_RESPONSE:
2899 wpa_supplicant_event_ft_response(wpa_s, data);
2900 break;
2901#endif /* CONFIG_IEEE80211R */
2902#ifdef CONFIG_IBSS_RSN
2903 case EVENT_IBSS_RSN_START:
2904 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2905 break;
2906#endif /* CONFIG_IBSS_RSN */
2907 case EVENT_ASSOC_REJECT:
2908 if (data->assoc_reject.bssid)
2909 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2910 "bssid=" MACSTR " status_code=%u",
2911 MAC2STR(data->assoc_reject.bssid),
2912 data->assoc_reject.status_code);
2913 else
2914 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2915 "status_code=%u",
2916 data->assoc_reject.status_code);
2917 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2918 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002919 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002920 const u8 *bssid = data->assoc_reject.bssid;
2921 if (bssid == NULL || is_zero_ether_addr(bssid))
2922 bssid = wpa_s->pending_bssid;
2923 wpas_connection_failed(wpa_s, bssid);
2924 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002925 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002926 break;
2927 case EVENT_AUTH_TIMED_OUT:
2928 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2929 sme_event_auth_timed_out(wpa_s, data);
2930 break;
2931 case EVENT_ASSOC_TIMED_OUT:
2932 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2933 sme_event_assoc_timed_out(wpa_s, data);
2934 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002935 case EVENT_TX_STATUS:
2936 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2937 " type=%d stype=%d",
2938 MAC2STR(data->tx_status.dst),
2939 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002940#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002941 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002942#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002943 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2944 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002945 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002946 wpa_s, data->tx_status.dst,
2947 data->tx_status.data,
2948 data->tx_status.data_len,
2949 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002950 OFFCHANNEL_SEND_ACTION_SUCCESS :
2951 OFFCHANNEL_SEND_ACTION_NO_ACK);
2952#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002953 break;
2954 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002955#endif /* CONFIG_AP */
2956#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002957 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2958 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2959 /*
2960 * Catch TX status events for Action frames we sent via group
2961 * interface in GO mode.
2962 */
2963 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2964 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2965 os_memcmp(wpa_s->parent->pending_action_dst,
2966 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002967 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002968 wpa_s->parent, data->tx_status.dst,
2969 data->tx_status.data,
2970 data->tx_status.data_len,
2971 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002972 OFFCHANNEL_SEND_ACTION_SUCCESS :
2973 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002974 break;
2975 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002976#endif /* CONFIG_OFFCHANNEL */
2977#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002978 switch (data->tx_status.type) {
2979 case WLAN_FC_TYPE_MGMT:
2980 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2981 data->tx_status.data_len,
2982 data->tx_status.stype,
2983 data->tx_status.ack);
2984 break;
2985 case WLAN_FC_TYPE_DATA:
2986 ap_tx_status(wpa_s, data->tx_status.dst,
2987 data->tx_status.data,
2988 data->tx_status.data_len,
2989 data->tx_status.ack);
2990 break;
2991 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002992#endif /* CONFIG_AP */
2993 break;
2994#ifdef CONFIG_AP
2995 case EVENT_EAPOL_TX_STATUS:
2996 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2997 data->eapol_tx_status.data,
2998 data->eapol_tx_status.data_len,
2999 data->eapol_tx_status.ack);
3000 break;
3001 case EVENT_DRIVER_CLIENT_POLL_OK:
3002 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003003 break;
3004 case EVENT_RX_FROM_UNKNOWN:
3005 if (wpa_s->ap_iface == NULL)
3006 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003007 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3008 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003009 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003010 case EVENT_CH_SWITCH:
3011 if (!data)
3012 break;
3013 if (!wpa_s->ap_iface) {
3014 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3015 "event in non-AP mode");
3016 break;
3017 }
3018
Dmitry Shmidt04949592012-07-19 12:16:46 -07003019 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3020 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08003021 data->ch_switch.ch_offset,
3022 data->ch_switch.ch_width,
3023 data->ch_switch.cf1,
3024 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003025 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003026#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003027 case EVENT_RX_MGMT: {
3028 u16 fc, stype;
3029 const struct ieee80211_mgmt *mgmt;
3030
3031 mgmt = (const struct ieee80211_mgmt *)
3032 data->rx_mgmt.frame;
3033 fc = le_to_host16(mgmt->frame_control);
3034 stype = WLAN_FC_GET_STYPE(fc);
3035
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003036#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003037 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003038#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003039#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003040 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3041 data->rx_mgmt.frame_len > 24) {
3042 const u8 *src = mgmt->sa;
3043 const u8 *ie = mgmt->u.probe_req.variable;
3044 size_t ie_len = data->rx_mgmt.frame_len -
3045 (mgmt->u.probe_req.variable -
3046 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003047 wpas_p2p_probe_req_rx(
3048 wpa_s, src, mgmt->da,
3049 mgmt->bssid, ie, ie_len,
3050 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003051 break;
3052 }
3053#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003054#ifdef CONFIG_IBSS_RSN
3055 if (stype == WLAN_FC_STYPE_AUTH &&
3056 data->rx_mgmt.frame_len >= 30) {
3057 wpa_supplicant_event_ibss_auth(wpa_s, data);
3058 break;
3059 }
3060#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003061
3062 if (stype == WLAN_FC_STYPE_ACTION) {
3063 wpas_event_rx_mgmt_action(
3064 wpa_s, mgmt, data->rx_mgmt.frame_len,
3065 data->rx_mgmt.freq);
3066 break;
3067 }
3068
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003069 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3070 "management frame in non-AP mode");
3071 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003072#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003073 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003074
3075 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3076 data->rx_mgmt.frame_len > 24) {
3077 const u8 *ie = mgmt->u.probe_req.variable;
3078 size_t ie_len = data->rx_mgmt.frame_len -
3079 (mgmt->u.probe_req.variable -
3080 data->rx_mgmt.frame);
3081
3082 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3083 mgmt->bssid, ie, ie_len,
3084 data->rx_mgmt.ssi_signal);
3085 }
3086
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003087 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003088#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003089 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003090 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003091 case EVENT_RX_PROBE_REQ:
3092 if (data->rx_probe_req.sa == NULL ||
3093 data->rx_probe_req.ie == NULL)
3094 break;
3095#ifdef CONFIG_AP
3096 if (wpa_s->ap_iface) {
3097 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3098 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003099 data->rx_probe_req.da,
3100 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003101 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003102 data->rx_probe_req.ie_len,
3103 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003104 break;
3105 }
3106#endif /* CONFIG_AP */
3107#ifdef CONFIG_P2P
3108 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003109 data->rx_probe_req.da,
3110 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003111 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003112 data->rx_probe_req.ie_len,
3113 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003114#endif /* CONFIG_P2P */
3115 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003116 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003117#ifdef CONFIG_OFFCHANNEL
3118 offchannel_remain_on_channel_cb(
3119 wpa_s, data->remain_on_channel.freq,
3120 data->remain_on_channel.duration);
3121#endif /* CONFIG_OFFCHANNEL */
3122#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003123 wpas_p2p_remain_on_channel_cb(
3124 wpa_s, data->remain_on_channel.freq,
3125 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003126#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003127 break;
3128 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003129#ifdef CONFIG_OFFCHANNEL
3130 offchannel_cancel_remain_on_channel_cb(
3131 wpa_s, data->remain_on_channel.freq);
3132#endif /* CONFIG_OFFCHANNEL */
3133#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003134 wpas_p2p_cancel_remain_on_channel_cb(
3135 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003136#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003137 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003138 case EVENT_EAPOL_RX:
3139 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3140 data->eapol_rx.data,
3141 data->eapol_rx.data_len);
3142 break;
3143 case EVENT_SIGNAL_CHANGE:
3144 bgscan_notify_signal_change(
3145 wpa_s, data->signal_change.above_threshold,
3146 data->signal_change.current_signal,
3147 data->signal_change.current_noise,
3148 data->signal_change.current_txrate);
3149 break;
3150 case EVENT_INTERFACE_ENABLED:
3151 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3152 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003153 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003154#ifdef CONFIG_AP
3155 if (!wpa_s->ap_iface) {
3156 wpa_supplicant_set_state(wpa_s,
3157 WPA_DISCONNECTED);
3158 wpa_supplicant_req_scan(wpa_s, 0, 0);
3159 } else
3160 wpa_supplicant_set_state(wpa_s,
3161 WPA_COMPLETED);
3162#else /* CONFIG_AP */
3163 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3164 wpa_supplicant_req_scan(wpa_s, 0, 0);
3165#endif /* CONFIG_AP */
3166 }
3167 break;
3168 case EVENT_INTERFACE_DISABLED:
3169 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003170#ifdef CONFIG_P2P
3171 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3172 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3173 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3174 /*
3175 * The interface was externally disabled. Remove
3176 * it assuming an external entity will start a
3177 * new session if needed.
3178 */
3179 wpas_p2p_disconnect(wpa_s);
3180 break;
3181 }
3182#endif /* CONFIG_P2P */
3183
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003184 wpa_supplicant_mark_disassoc(wpa_s);
3185 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3186 break;
3187 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003188 wpa_supplicant_update_channel_list(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003189 break;
3190 case EVENT_INTERFACE_UNAVAILABLE:
3191#ifdef CONFIG_P2P
3192 wpas_p2p_interface_unavailable(wpa_s);
3193#endif /* CONFIG_P2P */
3194 break;
3195 case EVENT_BEST_CHANNEL:
3196 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3197 "(%d %d %d)",
3198 data->best_chan.freq_24, data->best_chan.freq_5,
3199 data->best_chan.freq_overall);
3200 wpa_s->best_24_freq = data->best_chan.freq_24;
3201 wpa_s->best_5_freq = data->best_chan.freq_5;
3202 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3203#ifdef CONFIG_P2P
3204 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3205 data->best_chan.freq_5,
3206 data->best_chan.freq_overall);
3207#endif /* CONFIG_P2P */
3208 break;
3209 case EVENT_UNPROT_DEAUTH:
3210 wpa_supplicant_event_unprot_deauth(wpa_s,
3211 &data->unprot_deauth);
3212 break;
3213 case EVENT_UNPROT_DISASSOC:
3214 wpa_supplicant_event_unprot_disassoc(wpa_s,
3215 &data->unprot_disassoc);
3216 break;
3217 case EVENT_STATION_LOW_ACK:
3218#ifdef CONFIG_AP
3219 if (wpa_s->ap_iface && data)
3220 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3221 data->low_ack.addr);
3222#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003223#ifdef CONFIG_TDLS
3224 if (data)
3225 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3226#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003227 break;
3228 case EVENT_IBSS_PEER_LOST:
3229#ifdef CONFIG_IBSS_RSN
3230 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3231#endif /* CONFIG_IBSS_RSN */
3232 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003233 case EVENT_DRIVER_GTK_REKEY:
3234 if (os_memcmp(data->driver_gtk_rekey.bssid,
3235 wpa_s->bssid, ETH_ALEN))
3236 break;
3237 if (!wpa_s->wpa)
3238 break;
3239 wpa_sm_update_replay_ctr(wpa_s->wpa,
3240 data->driver_gtk_rekey.replay_ctr);
3241 break;
3242 case EVENT_SCHED_SCAN_STOPPED:
3243 wpa_s->sched_scanning = 0;
3244 wpa_supplicant_notify_scanning(wpa_s, 0);
3245
3246 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3247 break;
3248
3249 /*
3250 * If we timed out, start a new sched scan to continue
3251 * searching for more SSIDs.
3252 */
3253 if (wpa_s->sched_scan_timed_out)
3254 wpa_supplicant_req_sched_scan(wpa_s);
3255 break;
3256 case EVENT_WPS_BUTTON_PUSHED:
3257#ifdef CONFIG_WPS
3258 wpas_wps_start_pbc(wpa_s, NULL, 0);
3259#endif /* CONFIG_WPS */
3260 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003261 case EVENT_CONNECT_FAILED_REASON:
3262#ifdef CONFIG_AP
3263 if (!wpa_s->ap_iface || !data)
3264 break;
3265 hostapd_event_connect_failed_reason(
3266 wpa_s->ap_iface->bss[0],
3267 data->connect_failed_reason.addr,
3268 data->connect_failed_reason.code);
3269#endif /* CONFIG_AP */
3270 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003271 default:
3272 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3273 break;
3274 }
3275}