blob: 11946cda6ef71ee9bc9bc477b5ffd98207301cc4 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003 * Copyright (c) 2003-2015, 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"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080045#include "mesh.h"
46#include "mesh_mpm.h"
47#include "wmm_ac.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070048
49
Dmitry Shmidt34af3062013-07-11 10:46:32 -070050#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070051static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080052 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070053#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080054
55
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070056static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
57 struct wpa_ssid *ssid)
58{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080059 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070060
61 if (ssid == NULL || ssid->disabled_until.sec == 0)
62 return 0;
63
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080064 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070065 if (ssid->disabled_until.sec > now.sec)
66 return ssid->disabled_until.sec - now.sec;
67
68 wpas_clear_temp_disabled(wpa_s, ssid, 0);
69
70 return 0;
71}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070072
73
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070074/**
75 * wpas_reenabled_network_time - Time until first network is re-enabled
76 * @wpa_s: Pointer to wpa_supplicant data
77 * Returns: If all enabled networks are temporarily disabled, returns the time
78 * (in sec) until the first network is re-enabled. Otherwise returns 0.
79 *
80 * This function is used in case all enabled networks are temporarily disabled,
81 * in which case it returns the time (in sec) that the first network will be
82 * re-enabled. The function assumes that at least one network is enabled.
83 */
84static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
85{
86 struct wpa_ssid *ssid;
87 int disabled_for, res = 0;
88
89#ifdef CONFIG_INTERWORKING
90 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
91 wpa_s->conf->cred)
92 return 0;
93#endif /* CONFIG_INTERWORKING */
94
95 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
96 if (ssid->disabled)
97 continue;
98
99 disabled_for = wpas_temp_disabled(wpa_s, ssid);
100 if (!disabled_for)
101 return 0;
102
103 if (!res || disabled_for < res)
104 res = disabled_for;
105 }
106
107 return res;
108}
109
110
111void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
112{
113 struct wpa_supplicant *wpa_s = eloop_ctx;
114
115 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
116 return;
117
118 wpa_dbg(wpa_s, MSG_DEBUG,
119 "Try to associate due to network getting re-enabled");
120 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
121 wpa_supplicant_cancel_sched_scan(wpa_s);
122 wpa_supplicant_req_scan(wpa_s, 0, 0);
123 }
124}
125
126
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800127static struct wpa_bss * wpa_supplicant_get_new_bss(
128 struct wpa_supplicant *wpa_s, const u8 *bssid)
129{
130 struct wpa_bss *bss = NULL;
131 struct wpa_ssid *ssid = wpa_s->current_ssid;
132
133 if (ssid->ssid_len > 0)
134 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
135 if (!bss)
136 bss = wpa_bss_get_bssid(wpa_s, bssid);
137
138 return bss;
139}
140
141
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700142static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
143{
144 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
145
146 if (!bss) {
147 wpa_supplicant_update_scan_results(wpa_s);
148
149 /* Get the BSS from the new scan results */
150 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
151 }
152
153 if (bss)
154 wpa_s->current_bss = bss;
155}
156
157
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700158static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
159{
160 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700161 u8 drv_ssid[MAX_SSID_LEN];
162 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700163 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700164
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700165 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
166 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700167
168 if (wpa_s->current_ssid->ssid_len == 0)
169 return 0; /* current profile still in use */
170 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
171 if (res < 0) {
172 wpa_msg(wpa_s, MSG_INFO,
173 "Failed to read SSID from driver");
174 return 0; /* try to use current profile */
175 }
176 drv_ssid_len = res;
177
178 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
179 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
180 drv_ssid_len) == 0)
181 return 0; /* current profile still in use */
182
183 wpa_msg(wpa_s, MSG_DEBUG,
184 "Driver-initiated BSS selection changed the SSID to %s",
185 wpa_ssid_txt(drv_ssid, drv_ssid_len));
186 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700187 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700188
189 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
190 "information");
191 ssid = wpa_supplicant_get_ssid(wpa_s);
192 if (ssid == NULL) {
193 wpa_msg(wpa_s, MSG_INFO,
194 "No network configuration found for the current AP");
195 return -1;
196 }
197
Dmitry Shmidt04949592012-07-19 12:16:46 -0700198 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700199 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
200 return -1;
201 }
202
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800203 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
204 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
205 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
206 return -1;
207 }
208
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700209 res = wpas_temp_disabled(wpa_s, ssid);
210 if (res > 0) {
211 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
212 "disabled for %d second(s)", res);
213 return -1;
214 }
215
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700216 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
217 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800218 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219 u8 wpa_ie[80];
220 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800221 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
222 wpa_ie, &wpa_ie_len) < 0)
223 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700224 } else {
225 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
226 }
227
228 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
229 eapol_sm_invalidate_cached_session(wpa_s->eapol);
230 old_ssid = wpa_s->current_ssid;
231 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800232
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700233 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800234
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700235 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
236 wpa_supplicant_initiate_eapol(wpa_s);
237 if (old_ssid != wpa_s->current_ssid)
238 wpas_notify_network_changed(wpa_s);
239
240 return 0;
241}
242
243
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800244void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700245{
246 struct wpa_supplicant *wpa_s = eloop_ctx;
247
248 if (wpa_s->countermeasures) {
249 wpa_s->countermeasures = 0;
250 wpa_drv_set_countermeasures(wpa_s, 0);
251 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800252
253 /*
254 * It is possible that the device is sched scanning, which means
255 * that a connection attempt will be done only when we receive
256 * scan results. However, in this case, it would be preferable
257 * to scan and connect immediately, so cancel the sched_scan and
258 * issue a regular scan flow.
259 */
260 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700261 wpa_supplicant_req_scan(wpa_s, 0, 0);
262 }
263}
264
265
266void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
267{
268 int bssid_changed;
269
Dmitry Shmidt04949592012-07-19 12:16:46 -0700270 wnm_bss_keep_alive_deinit(wpa_s);
271
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700272#ifdef CONFIG_IBSS_RSN
273 ibss_rsn_deinit(wpa_s->ibss_rsn);
274 wpa_s->ibss_rsn = NULL;
275#endif /* CONFIG_IBSS_RSN */
276
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700277#ifdef CONFIG_AP
278 wpa_supplicant_ap_deinit(wpa_s);
279#endif /* CONFIG_AP */
280
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700281 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
282 return;
283
284 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
285 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
286 os_memset(wpa_s->bssid, 0, ETH_ALEN);
287 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800288 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800289#ifdef CONFIG_P2P
290 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
291#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292 wpa_s->current_bss = NULL;
293 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700294
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700295 if (bssid_changed)
296 wpas_notify_bssid_changed(wpa_s);
297
298 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
299 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
300 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
301 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
302 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700303 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700304 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700305 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800306
307 wpas_rrm_reset(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700308}
309
310
311static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
312{
313 struct wpa_ie_data ie;
314 int pmksa_set = -1;
315 size_t i;
316
317 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
318 ie.pmkid == NULL)
319 return;
320
321 for (i = 0; i < ie.num_pmkid; i++) {
322 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
323 ie.pmkid + i * PMKID_LEN,
324 NULL, NULL, 0);
325 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800326 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700327 break;
328 }
329 }
330
331 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
332 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
333}
334
335
336static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
337 union wpa_event_data *data)
338{
339 if (data == NULL) {
340 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
341 "event");
342 return;
343 }
344 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
345 " index=%d preauth=%d",
346 MAC2STR(data->pmkid_candidate.bssid),
347 data->pmkid_candidate.index,
348 data->pmkid_candidate.preauth);
349
350 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
351 data->pmkid_candidate.index,
352 data->pmkid_candidate.preauth);
353}
354
355
356static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
357{
358 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
359 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
360 return 0;
361
362#ifdef IEEE8021X_EAPOL
363 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
364 wpa_s->current_ssid &&
365 !(wpa_s->current_ssid->eapol_flags &
366 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
367 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
368 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
369 * plaintext or static WEP keys). */
370 return 0;
371 }
372#endif /* IEEE8021X_EAPOL */
373
374 return 1;
375}
376
377
378/**
379 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
380 * @wpa_s: pointer to wpa_supplicant data
381 * @ssid: Configuration data for the network
382 * Returns: 0 on success, -1 on failure
383 *
384 * This function is called when starting authentication with a network that is
385 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
386 */
387int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
388 struct wpa_ssid *ssid)
389{
390#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800391#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700392 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700393
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700394 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
395 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396 return 0;
397
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700398 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700399 sim = 1;
400 aka = 1;
401 } else {
402 struct eap_method_type *eap = ssid->eap.eap_methods;
403 while (eap->vendor != EAP_VENDOR_IETF ||
404 eap->method != EAP_TYPE_NONE) {
405 if (eap->vendor == EAP_VENDOR_IETF) {
406 if (eap->method == EAP_TYPE_SIM)
407 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700408 else if (eap->method == EAP_TYPE_AKA ||
409 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700410 aka = 1;
411 }
412 eap++;
413 }
414 }
415
416 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
417 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700418 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
419 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
420 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700421 aka = 0;
422
423 if (!sim && !aka) {
424 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
425 "use SIM, but neither EAP-SIM nor EAP-AKA are "
426 "enabled");
427 return 0;
428 }
429
430 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
431 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700432
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700433 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700434 if (wpa_s->scard == NULL) {
435 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
436 "(pcsc-lite)");
437 return -1;
438 }
439 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
440 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800441#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700442#endif /* IEEE8021X_EAPOL */
443
444 return 0;
445}
446
447
448#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700449
450static int has_wep_key(struct wpa_ssid *ssid)
451{
452 int i;
453
454 for (i = 0; i < NUM_WEP_KEYS; i++) {
455 if (ssid->wep_key_len[i])
456 return 1;
457 }
458
459 return 0;
460}
461
462
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700463static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700464 struct wpa_ssid *ssid)
465{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700466 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700467
468 if (ssid->mixed_cell)
469 return 1;
470
471#ifdef CONFIG_WPS
472 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
473 return 1;
474#endif /* CONFIG_WPS */
475
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700476 if (has_wep_key(ssid))
477 privacy = 1;
478
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479#ifdef IEEE8021X_EAPOL
480 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
481 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
482 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
483 privacy = 1;
484#endif /* IEEE8021X_EAPOL */
485
Jouni Malinen75ecf522011-06-27 15:19:46 -0700486 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
487 privacy = 1;
488
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800489 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
490 privacy = 1;
491
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700492 if (bss->caps & IEEE80211_CAP_PRIVACY)
493 return privacy;
494 return !privacy;
495}
496
497
498static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
499 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700500 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501{
502 struct wpa_ie_data ie;
503 int proto_match = 0;
504 const u8 *rsn_ie, *wpa_ie;
505 int ret;
506 int wep_ok;
507
508 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
509 if (ret >= 0)
510 return ret;
511
512 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
513 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
514 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
515 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
516 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
517
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700518 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700519 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
520 proto_match++;
521
522 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
523 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
524 "failed");
525 break;
526 }
527
528 if (wep_ok &&
529 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
530 {
531 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
532 "in RSN IE");
533 return 1;
534 }
535
536 if (!(ie.proto & ssid->proto)) {
537 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
538 "mismatch");
539 break;
540 }
541
542 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
543 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
544 "cipher mismatch");
545 break;
546 }
547
548 if (!(ie.group_cipher & ssid->group_cipher)) {
549 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
550 "cipher mismatch");
551 break;
552 }
553
554 if (!(ie.key_mgmt & ssid->key_mgmt)) {
555 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
556 "mismatch");
557 break;
558 }
559
560#ifdef CONFIG_IEEE80211W
561 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800562 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800563 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700564 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
565 "frame protection");
566 break;
567 }
568#endif /* CONFIG_IEEE80211W */
569
570 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
571 return 1;
572 }
573
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700574 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700575 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
576 proto_match++;
577
578 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
579 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
580 "failed");
581 break;
582 }
583
584 if (wep_ok &&
585 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
586 {
587 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
588 "in WPA IE");
589 return 1;
590 }
591
592 if (!(ie.proto & ssid->proto)) {
593 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
594 "mismatch");
595 break;
596 }
597
598 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
599 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
600 "cipher mismatch");
601 break;
602 }
603
604 if (!(ie.group_cipher & ssid->group_cipher)) {
605 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
606 "cipher mismatch");
607 break;
608 }
609
610 if (!(ie.key_mgmt & ssid->key_mgmt)) {
611 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
612 "mismatch");
613 break;
614 }
615
616 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
617 return 1;
618 }
619
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700620 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
621 !rsn_ie) {
622 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
623 return 1;
624 }
625
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700626 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
627 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
628 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
629 return 0;
630 }
631
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800632 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
633 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
634 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
635 return 1;
636 }
637
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700638 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
639 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
640 return 1;
641 }
642
643 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
644 "WPA/WPA2");
645
646 return 0;
647}
648
649
650static int freq_allowed(int *freqs, int freq)
651{
652 int i;
653
654 if (freqs == NULL)
655 return 1;
656
657 for (i = 0; freqs[i]; i++)
658 if (freqs[i] == freq)
659 return 1;
660 return 0;
661}
662
663
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700664static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800665{
666 const struct hostapd_hw_modes *mode = NULL, *modes;
667 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
668 const u8 *rate_ie;
669 int i, j, k;
670
671 if (bss->freq == 0)
672 return 1; /* Cannot do matching without knowing band */
673
674 modes = wpa_s->hw.modes;
675 if (modes == NULL) {
676 /*
677 * The driver does not provide any additional information
678 * about the utilized hardware, so allow the connection attempt
679 * to continue.
680 */
681 return 1;
682 }
683
684 for (i = 0; i < wpa_s->hw.num_modes; i++) {
685 for (j = 0; j < modes[i].num_channels; j++) {
686 int freq = modes[i].channels[j].freq;
687 if (freq == bss->freq) {
688 if (mode &&
689 mode->mode == HOSTAPD_MODE_IEEE80211G)
690 break; /* do not allow 802.11b replace
691 * 802.11g */
692 mode = &modes[i];
693 break;
694 }
695 }
696 }
697
698 if (mode == NULL)
699 return 0;
700
701 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700702 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800703 if (rate_ie == NULL)
704 continue;
705
706 for (j = 2; j < rate_ie[1] + 2; j++) {
707 int flagged = !!(rate_ie[j] & 0x80);
708 int r = (rate_ie[j] & 0x7f) * 5;
709
710 /*
711 * IEEE Std 802.11n-2009 7.3.2.2:
712 * The new BSS Membership selector value is encoded
713 * like a legacy basic rate, but it is not a rate and
714 * only indicates if the BSS members are required to
715 * support the mandatory features of Clause 20 [HT PHY]
716 * in order to join the BSS.
717 */
718 if (flagged && ((rate_ie[j] & 0x7f) ==
719 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
720 if (!ht_supported(mode)) {
721 wpa_dbg(wpa_s, MSG_DEBUG,
722 " hardware does not support "
723 "HT PHY");
724 return 0;
725 }
726 continue;
727 }
728
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700729 /* There's also a VHT selector for 802.11ac */
730 if (flagged && ((rate_ie[j] & 0x7f) ==
731 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
732 if (!vht_supported(mode)) {
733 wpa_dbg(wpa_s, MSG_DEBUG,
734 " hardware does not support "
735 "VHT PHY");
736 return 0;
737 }
738 continue;
739 }
740
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800741 if (!flagged)
742 continue;
743
744 /* check for legacy basic rates */
745 for (k = 0; k < mode->num_rates; k++) {
746 if (mode->rates[k] == r)
747 break;
748 }
749 if (k == mode->num_rates) {
750 /*
751 * IEEE Std 802.11-2007 7.3.2.2 demands that in
752 * order to join a BSS all required rates
753 * have to be supported by the hardware.
754 */
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -0700755 wpa_dbg(wpa_s, MSG_DEBUG,
756 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
757 r / 10, r % 10,
758 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800759 return 0;
760 }
761 }
762 }
763
764 return 1;
765}
766
767
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800768/*
769 * Test whether BSS is in an ESS.
770 * This is done differently in DMG (60 GHz) and non-DMG bands
771 */
772static int bss_is_ess(struct wpa_bss *bss)
773{
774 if (bss_is_dmg(bss)) {
775 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
776 IEEE80211_CAP_DMG_AP;
777 }
778
779 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
780 IEEE80211_CAP_ESS);
781}
782
783
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800784static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
785{
786 size_t i;
787
788 for (i = 0; i < ETH_ALEN; i++) {
789 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
790 return 0;
791 }
792 return 1;
793}
794
795
796static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
797{
798 size_t i;
799
800 for (i = 0; i < num; i++) {
801 const u8 *a = list + i * ETH_ALEN * 2;
802 const u8 *m = a + ETH_ALEN;
803
804 if (match_mac_mask(a, addr, m))
805 return 1;
806 }
807 return 0;
808}
809
810
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700811static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700812 int i, struct wpa_bss *bss,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800813 struct wpa_ssid *group,
814 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700815{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700816 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817 int wpa;
818 struct wpa_blacklist *e;
819 const u8 *ie;
820 struct wpa_ssid *ssid;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800821 int osen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700822
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700823 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700824 wpa_ie_len = ie ? ie[1] : 0;
825
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700826 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700827 rsn_ie_len = ie ? ie[1] : 0;
828
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800829 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
830 osen = ie != NULL;
831
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700832 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800833 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700834 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700835 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
Dmitry Shmidt96571392013-10-14 12:54:46 -0700836 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
837 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
838 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800839 " p2p" : "",
840 osen ? " osen=1" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700841
842 e = wpa_blacklist_get(wpa_s, bss->bssid);
843 if (e) {
844 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700845 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700846 /*
847 * When only a single network is enabled, we can
848 * trigger blacklisting on the first failure. This
849 * should not be done with multiple enabled networks to
850 * avoid getting forced to move into a worse ESS on
851 * single error if there are no other BSSes of the
852 * current ESS.
853 */
854 limit = 0;
855 }
856 if (e->count > limit) {
857 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
858 "(count=%d limit=%d)", e->count, limit);
859 return NULL;
860 }
861 }
862
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700863 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700864 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
865 return NULL;
866 }
867
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800868 if (disallowed_bssid(wpa_s, bss->bssid)) {
869 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
870 return NULL;
871 }
872
873 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
874 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
875 return NULL;
876 }
877
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700878 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
879
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800880 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700881 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700882 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700883
Dmitry Shmidt04949592012-07-19 12:16:46 -0700884 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700885 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
886 continue;
887 }
888
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700889 res = wpas_temp_disabled(wpa_s, ssid);
890 if (res > 0) {
891 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
892 "temporarily for %d second(s)", res);
893 continue;
894 }
895
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700896#ifdef CONFIG_WPS
897 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
898 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
899 "(WPS)");
900 continue;
901 }
902
903 if (wpa && ssid->ssid_len == 0 &&
904 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
905 check_ssid = 0;
906
907 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
908 /* Only allow wildcard SSID match if an AP
909 * advertises active WPS operation that matches
910 * with our mode. */
911 check_ssid = 1;
912 if (ssid->ssid_len == 0 &&
913 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
914 check_ssid = 0;
915 }
916#endif /* CONFIG_WPS */
917
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800918 if (ssid->bssid_set && ssid->ssid_len == 0 &&
919 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
920 check_ssid = 0;
921
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700922 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700923 (bss->ssid_len != ssid->ssid_len ||
924 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700925 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
926 continue;
927 }
928
929 if (ssid->bssid_set &&
930 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
931 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
932 continue;
933 }
934
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800935 /* check blacklist */
936 if (ssid->num_bssid_blacklist &&
937 addr_in_list(bss->bssid, ssid->bssid_blacklist,
938 ssid->num_bssid_blacklist)) {
939 wpa_dbg(wpa_s, MSG_DEBUG,
940 " skip - BSSID blacklisted");
941 continue;
942 }
943
944 /* if there is a whitelist, only accept those APs */
945 if (ssid->num_bssid_whitelist &&
946 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
947 ssid->num_bssid_whitelist)) {
948 wpa_dbg(wpa_s, MSG_DEBUG,
949 " skip - BSSID not in whitelist");
950 continue;
951 }
952
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700953 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
954 continue;
955
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800956 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700957 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
958 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
959 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
960 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
961 "not allowed");
962 continue;
963 }
964
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700965 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
966 has_wep_key(ssid)) {
967 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
968 continue;
969 }
970
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800971 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
972 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
973 "not allowed");
974 continue;
975 }
976
Jouni Malinen75ecf522011-06-27 15:19:46 -0700977 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700978 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
979 "mismatch");
980 continue;
981 }
982
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800983 if (!bss_is_ess(bss)) {
984 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700985 continue;
986 }
987
988 if (!freq_allowed(ssid->freq_list, bss->freq)) {
989 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
990 "allowed");
991 continue;
992 }
993
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800994 if (!rate_match(wpa_s, bss)) {
995 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
996 "not match");
997 continue;
998 }
999
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001000#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -07001001 if (ssid->p2p_group &&
1002 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1003 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1004 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1005 continue;
1006 }
1007
Dmitry Shmidt54605472013-11-08 11:10:19 -08001008 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1009 struct wpabuf *p2p_ie;
1010 u8 dev_addr[ETH_ALEN];
1011
1012 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1013 if (ie == NULL) {
1014 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
1015 continue;
1016 }
1017 p2p_ie = wpa_bss_get_vendor_ie_multi(
1018 bss, P2P_IE_VENDOR_TYPE);
1019 if (p2p_ie == NULL) {
1020 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
1021 continue;
1022 }
1023
1024 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1025 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1026 ETH_ALEN) != 0) {
1027 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
1028 wpabuf_free(p2p_ie);
1029 continue;
1030 }
1031 wpabuf_free(p2p_ie);
1032 }
1033
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034 /*
1035 * TODO: skip the AP if its P2P IE has Group Formation
1036 * bit set in the P2P Group Capability Bitmap and we
1037 * are not in Group Formation with that device.
1038 */
1039#endif /* CONFIG_P2P */
1040
1041 /* Matching configuration found */
1042 return ssid;
1043 }
1044
1045 /* No matching configuration found */
1046 return NULL;
1047}
1048
1049
1050static struct wpa_bss *
1051wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001052 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001053 struct wpa_ssid **selected_ssid,
1054 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001055{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001056 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001057
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001058 if (only_first_ssid)
1059 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1060 group->id);
1061 else
1062 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1063 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001064
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001065 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1066 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001067 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1068 only_first_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001069 if (!*selected_ssid)
1070 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001071 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1072 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001073 MAC2STR(bss->bssid),
1074 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1075 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076 }
1077
1078 return NULL;
1079}
1080
1081
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001082struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1083 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001084{
1085 struct wpa_bss *selected = NULL;
1086 int prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001087 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001088 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001089
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001090 if (wpa_s->last_scan_res == NULL ||
1091 wpa_s->last_scan_res_used == 0)
1092 return NULL; /* no scan results from last update */
1093
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001094 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001095 /* check that next_ssid is still valid */
1096 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1097 if (ssid == wpa_s->next_ssid)
1098 break;
1099 }
1100 next_ssid = ssid;
1101 wpa_s->next_ssid = NULL;
1102 }
1103
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001104 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001105 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1106 if (next_ssid && next_ssid->priority ==
1107 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001108 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001109 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001110 if (selected)
1111 break;
1112 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001114 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001115 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001116 if (selected)
1117 break;
1118 }
1119
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001120 if (selected == NULL && wpa_s->blacklist &&
1121 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001122 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1123 "blacklist and try again");
1124 wpa_blacklist_clear(wpa_s);
1125 wpa_s->blacklist_cleared++;
1126 } else if (selected == NULL)
1127 break;
1128 }
1129
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001130 ssid = *selected_ssid;
1131 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1132 !ssid->passphrase && !ssid->ext_psk) {
1133 const char *field_name, *txt = NULL;
1134
1135 wpa_dbg(wpa_s, MSG_DEBUG,
1136 "PSK/passphrase not yet available for the selected network");
1137
1138 wpas_notify_network_request(wpa_s, ssid,
1139 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1140
1141 field_name = wpa_supplicant_ctrl_req_to_string(
1142 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1143 if (field_name == NULL)
1144 return NULL;
1145
1146 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1147
1148 selected = NULL;
1149 }
1150
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001151 return selected;
1152}
1153
1154
1155static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1156 int timeout_sec, int timeout_usec)
1157{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001158 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001159 /*
1160 * No networks are enabled; short-circuit request so
1161 * we don't wait timeout seconds before transitioning
1162 * to INACTIVE state.
1163 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001164 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1165 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001166 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1167 return;
1168 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001169
1170 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001171 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1172}
1173
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001174
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001175int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001176 struct wpa_bss *selected,
1177 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001178{
1179 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1180 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1181 "PBC session overlap");
1182#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001183 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1184 wpa_s->p2p_in_provisioning) {
1185 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1186 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001187 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001188 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189#endif /* CONFIG_P2P */
1190
1191#ifdef CONFIG_WPS
1192 wpas_wps_cancel(wpa_s);
1193#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001194 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001195 }
1196
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001197 wpa_msg(wpa_s, MSG_DEBUG,
1198 "Considering connect request: reassociate: %d selected: "
1199 MACSTR " bssid: " MACSTR " pending: " MACSTR
1200 " wpa_state: %s ssid=%p current_ssid=%p",
1201 wpa_s->reassociate, MAC2STR(selected->bssid),
1202 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1203 wpa_supplicant_state_txt(wpa_s->wpa_state),
1204 ssid, wpa_s->current_ssid);
1205
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001206 /*
1207 * Do not trigger new association unless the BSSID has changed or if
1208 * reassociation is requested. If we are in process of associating with
1209 * the selected BSSID, do not trigger new attempt.
1210 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001211 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001212 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1213 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1214 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001215 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1216 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1217 0) ||
1218 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1219 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001220 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1221 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001222 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001223 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001224 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1225 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001226 wpa_supplicant_associate(wpa_s, selected, ssid);
1227 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001228 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1229 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001230 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001231
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001232 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001233}
1234
1235
1236static struct wpa_ssid *
1237wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1238{
1239 int prio;
1240 struct wpa_ssid *ssid;
1241
1242 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1243 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1244 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001245 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246 continue;
1247 if (ssid->mode == IEEE80211_MODE_IBSS ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001248 ssid->mode == IEEE80211_MODE_AP ||
1249 ssid->mode == IEEE80211_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001250 return ssid;
1251 }
1252 }
1253 return NULL;
1254}
1255
1256
1257/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1258 * on BSS added and BSS changed events */
1259static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001260 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001261{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001262 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001263
1264 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1265 return;
1266
Jouni Malinen87fd2792011-05-16 18:35:42 +03001267 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001268 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001269
Jouni Malinen87fd2792011-05-16 18:35:42 +03001270 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001271 if (ssid == NULL)
1272 continue;
1273
Jouni Malinen87fd2792011-05-16 18:35:42 +03001274 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001275 if (rsn == NULL)
1276 continue;
1277
Jouni Malinen87fd2792011-05-16 18:35:42 +03001278 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001279 }
1280
1281}
1282
1283
1284static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1285 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001286 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001287{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001288 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001289#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001290 int min_diff;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001291#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001292
1293 if (wpa_s->reassociate)
1294 return 1; /* explicit request to reassociate */
1295 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1296 return 1; /* we are not associated; continue */
1297 if (wpa_s->current_ssid == NULL)
1298 return 1; /* unknown current SSID */
1299 if (wpa_s->current_ssid != ssid)
1300 return 1; /* different network block */
1301
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001302 if (wpas_driver_bss_selection(wpa_s))
1303 return 0; /* Driver-based roaming */
1304
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001305 if (wpa_s->current_ssid->ssid)
1306 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1307 wpa_s->current_ssid->ssid,
1308 wpa_s->current_ssid->ssid_len);
1309 if (!current_bss)
1310 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001311
1312 if (!current_bss)
1313 return 1; /* current BSS not seen in scan results */
1314
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001315 if (current_bss == selected)
1316 return 0;
1317
1318 if (selected->last_update_idx > current_bss->last_update_idx)
1319 return 1; /* current BSS not seen in the last scan */
1320
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001321#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001322 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001323 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1324 " level=%d snr=%d est_throughput=%u",
1325 MAC2STR(current_bss->bssid), current_bss->level,
1326 current_bss->snr, current_bss->est_throughput);
1327 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1328 " level=%d snr=%d est_throughput=%u",
1329 MAC2STR(selected->bssid), selected->level,
1330 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001331
1332 if (wpa_s->current_ssid->bssid_set &&
1333 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1334 0) {
1335 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1336 "has preferred BSSID");
1337 return 1;
1338 }
1339
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001340 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1341 wpa_dbg(wpa_s, MSG_DEBUG,
1342 "Allow reassociation - selected BSS has better estimated throughput");
1343 return 1;
1344 }
1345
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001346 if (current_bss->level < 0 && current_bss->level > selected->level) {
1347 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1348 "signal level");
1349 return 0;
1350 }
1351
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001352 min_diff = 2;
1353 if (current_bss->level < 0) {
1354 if (current_bss->level < -85)
1355 min_diff = 1;
1356 else if (current_bss->level < -80)
1357 min_diff = 2;
1358 else if (current_bss->level < -75)
1359 min_diff = 3;
1360 else if (current_bss->level < -70)
1361 min_diff = 4;
1362 else
1363 min_diff = 5;
1364 }
1365 if (abs(current_bss->level - selected->level) < min_diff) {
1366 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1367 "in signal level");
1368 return 0;
1369 }
1370
1371 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001372#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001373 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001374#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001375}
1376
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001377
Jouni Malinen89ca7022012-09-14 13:03:12 -07001378/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001379 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001380static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001381 union wpa_event_data *data,
1382 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001383{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001384 struct wpa_scan_results *scan_res = NULL;
1385 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001386 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001387#ifndef CONFIG_NO_RANDOM_POOL
1388 size_t i, num;
1389#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001390
1391#ifdef CONFIG_AP
1392 if (wpa_s->ap_iface)
1393 ap = 1;
1394#endif /* CONFIG_AP */
1395
1396 wpa_supplicant_notify_scanning(wpa_s, 0);
1397
1398 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1399 data ? &data->scan_info :
1400 NULL, 1);
1401 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001402 if (wpa_s->conf->ap_scan == 2 || ap ||
1403 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001404 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001405 if (!own_request)
1406 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001407 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1408 "scanning again");
1409 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001410 ret = -1;
1411 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001412 }
1413
1414#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001415 num = scan_res->num;
1416 if (num > 10)
1417 num = 10;
1418 for (i = 0; i < num; i++) {
1419 u8 buf[5];
1420 struct wpa_scan_res *res = scan_res->res[i];
1421 buf[0] = res->bssid[5];
1422 buf[1] = res->qual & 0xff;
1423 buf[2] = res->noise & 0xff;
1424 buf[3] = res->level & 0xff;
1425 buf[4] = res->tsf & 0xff;
1426 random_add_randomness(buf, sizeof(buf));
1427 }
1428#endif /* CONFIG_NO_RANDOM_POOL */
1429
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001430 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001431 (wpa_s->own_scan_running || !wpa_s->radio->external_scan_running)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001432 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1433 struct wpa_scan_results *scan_res);
1434
1435 scan_res_handler = wpa_s->scan_res_handler;
1436 wpa_s->scan_res_handler = NULL;
1437 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001438 ret = -2;
1439 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001440 }
1441
1442 if (ap) {
1443 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1444#ifdef CONFIG_AP
1445 if (wpa_s->ap_iface->scan_cb)
1446 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1447#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001448 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001449 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001450
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001451 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001452 wpa_s->own_scan_running, wpa_s->radio->external_scan_running);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001453 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1454 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1455 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1456 wpa_s->manual_scan_id);
1457 wpa_s->manual_scan_use_id = 0;
1458 } else {
1459 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1460 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001461 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001462
1463 wpas_notify_scan_done(wpa_s, 1);
1464
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001465 if (!wpa_s->own_scan_running && wpa_s->radio->external_scan_running) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001466 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 -07001467 wpa_scan_results_free(scan_res);
1468 return 0;
1469 }
1470
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001471 if (wnm_scan_process(wpa_s, 1) > 0)
1472 goto scan_work_done;
1473
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001474 if (sme_proc_obss_scan(wpa_s) > 0)
1475 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001476
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001477 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1478 goto scan_work_done;
1479
1480 if (autoscan_notify_scan(wpa_s, scan_res))
1481 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001482
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001483 if (wpa_s->disconnected) {
1484 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001485 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001486 }
1487
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001488 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001489 bgscan_notify_scan(wpa_s, scan_res) == 1)
1490 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001491
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001492 wpas_wps_update_ap_info(wpa_s, scan_res);
1493
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001494 wpa_scan_results_free(scan_res);
1495
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001496 if (wpa_s->scan_work) {
1497 struct wpa_radio_work *work = wpa_s->scan_work;
1498 wpa_s->scan_work = NULL;
1499 radio_work_done(work);
1500 }
1501
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001502 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001503
1504scan_work_done:
1505 wpa_scan_results_free(scan_res);
1506 if (wpa_s->scan_work) {
1507 struct wpa_radio_work *work = wpa_s->scan_work;
1508 wpa_s->scan_work = NULL;
1509 radio_work_done(work);
1510 }
1511 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001512}
1513
1514
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001515static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001516 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001517{
1518 struct wpa_bss *selected;
1519 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001520 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1521
1522 if (time_to_reenable > 0) {
1523 wpa_dbg(wpa_s, MSG_DEBUG,
1524 "Postpone network selection by %d seconds since all networks are disabled",
1525 time_to_reenable);
1526 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1527 eloop_register_timeout(time_to_reenable, 0,
1528 wpas_network_reenabled, wpa_s, NULL);
1529 return 0;
1530 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001531
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001532 if (wpa_s->p2p_mgmt)
1533 return 0; /* no normal connection on p2p_mgmt interface */
1534
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001535 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001536
1537 if (selected) {
1538 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001539 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001540 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001541 if (new_scan)
1542 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001543 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001544 }
1545
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001546 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001547 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001548 return -1;
1549 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001550 if (new_scan)
1551 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001552 /*
1553 * Do not notify other virtual radios of scan results since we do not
1554 * want them to start other associations at the same time.
1555 */
1556 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001557 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001558#ifdef CONFIG_MESH
1559 if (wpa_s->ifmsh) {
1560 wpa_msg(wpa_s, MSG_INFO,
1561 "Avoiding join because we already joined a mesh group");
1562 return 0;
1563 }
1564#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001565 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1566 ssid = wpa_supplicant_pick_new_network(wpa_s);
1567 if (ssid) {
1568 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1569 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001570 if (new_scan)
1571 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001572 } else if (own_request) {
1573 /*
1574 * No SSID found. If SCAN results are as a result of
1575 * own scan request and not due to a scan request on
1576 * another shared interface, try another scan.
1577 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001578 int timeout_sec = wpa_s->scan_interval;
1579 int timeout_usec = 0;
1580#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001581 int res;
1582
1583 res = wpas_p2p_scan_no_go_seen(wpa_s);
1584 if (res == 2)
1585 return 2;
1586 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001587 return 0;
1588
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001589 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07001590 wpa_s->show_group_started ||
1591 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001592 /*
1593 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001594 * state and during P2P join-a-group operation
1595 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001596 */
1597 timeout_sec = 0;
1598 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001599 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1600 timeout_usec);
1601 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001602 }
1603#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001604#ifdef CONFIG_INTERWORKING
1605 if (wpa_s->conf->auto_interworking &&
1606 wpa_s->conf->interworking &&
1607 wpa_s->conf->cred) {
1608 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1609 "start ANQP fetch since no matching "
1610 "networks found");
1611 wpa_s->network_select = 1;
1612 wpa_s->auto_network_select = 1;
1613 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001614 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001615 }
1616#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001617#ifdef CONFIG_WPS
1618 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1619 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1620 timeout_sec = 0;
1621 timeout_usec = 500000;
1622 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1623 timeout_usec);
1624 return 0;
1625 }
1626#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001627 if (wpa_supplicant_req_sched_scan(wpa_s))
1628 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1629 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001630 }
1631 }
1632 return 0;
1633}
1634
1635
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001636static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1637 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001638{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001639 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001640 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001641
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001642 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1643 if (res == 2) {
1644 /*
1645 * Interface may have been removed, so must not dereference
1646 * wpa_s after this.
1647 */
1648 return 1;
1649 }
1650 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001651 /*
1652 * If no scan results could be fetched, then no need to
1653 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001654 * this scan. Similarly, if scan results started a new operation on this
1655 * interface, do not notify other interfaces to avoid concurrent
1656 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001657 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001658 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001659 }
1660
1661 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001662 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001663 * so, they get updated with this same scan info.
1664 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001665 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1666 radio_list) {
1667 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001668 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1669 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001670 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001671 }
1672 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001673
1674 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001675}
1676
1677#endif /* CONFIG_NO_SCAN_PROCESSING */
1678
1679
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001680int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1681{
1682#ifdef CONFIG_NO_SCAN_PROCESSING
1683 return -1;
1684#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001685 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001686
1687 if (wpa_s->last_scan_res_used <= 0)
1688 return -1;
1689
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001690 os_get_reltime(&now);
1691 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001692 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1693 return -1;
1694 }
1695
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001696 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001697#endif /* CONFIG_NO_SCAN_PROCESSING */
1698}
1699
Dmitry Shmidt04949592012-07-19 12:16:46 -07001700#ifdef CONFIG_WNM
1701
1702static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1703{
1704 struct wpa_supplicant *wpa_s = eloop_ctx;
1705
1706 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1707 return;
1708
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001709 if (!wpa_s->no_keep_alive) {
1710 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1711 MAC2STR(wpa_s->bssid));
1712 /* TODO: could skip this if normal data traffic has been sent */
1713 /* TODO: Consider using some more appropriate data frame for
1714 * this */
1715 if (wpa_s->l2)
1716 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1717 (u8 *) "", 0);
1718 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001719
1720#ifdef CONFIG_SME
1721 if (wpa_s->sme.bss_max_idle_period) {
1722 unsigned int msec;
1723 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1724 if (msec > 100)
1725 msec -= 100;
1726 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1727 wnm_bss_keep_alive, wpa_s, NULL);
1728 }
1729#endif /* CONFIG_SME */
1730}
1731
1732
1733static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1734 const u8 *ies, size_t ies_len)
1735{
1736 struct ieee802_11_elems elems;
1737
1738 if (ies == NULL)
1739 return;
1740
1741 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1742 return;
1743
1744#ifdef CONFIG_SME
1745 if (elems.bss_max_idle_period) {
1746 unsigned int msec;
1747 wpa_s->sme.bss_max_idle_period =
1748 WPA_GET_LE16(elems.bss_max_idle_period);
1749 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1750 "TU)%s", wpa_s->sme.bss_max_idle_period,
1751 (elems.bss_max_idle_period[2] & 0x01) ?
1752 " (protected keep-live required)" : "");
1753 if (wpa_s->sme.bss_max_idle_period == 0)
1754 wpa_s->sme.bss_max_idle_period = 1;
1755 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1756 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1757 /* msec times 1000 */
1758 msec = wpa_s->sme.bss_max_idle_period * 1024;
1759 if (msec > 100)
1760 msec -= 100;
1761 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1762 wnm_bss_keep_alive, wpa_s,
1763 NULL);
1764 }
1765 }
1766#endif /* CONFIG_SME */
1767}
1768
1769#endif /* CONFIG_WNM */
1770
1771
1772void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1773{
1774#ifdef CONFIG_WNM
1775 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1776#endif /* CONFIG_WNM */
1777}
1778
1779
Dmitry Shmidt051af732013-10-22 13:52:46 -07001780#ifdef CONFIG_INTERWORKING
1781
1782static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1783 size_t len)
1784{
1785 int res;
1786
1787 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1788 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1789 if (res) {
1790 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1791 }
1792
1793 return res;
1794}
1795
1796
1797static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1798 const u8 *ies, size_t ies_len)
1799{
1800 struct ieee802_11_elems elems;
1801
1802 if (ies == NULL)
1803 return;
1804
1805 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1806 return;
1807
1808 if (elems.qos_map_set) {
1809 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1810 elems.qos_map_set_len);
1811 }
1812}
1813
1814#endif /* CONFIG_INTERWORKING */
1815
1816
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001817static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1818 union wpa_event_data *data)
1819{
1820 int l, len, found = 0, wpa_found, rsn_found;
1821 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001822#ifdef CONFIG_IEEE80211R
1823 u8 bssid[ETH_ALEN];
1824#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001825
1826 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1827 if (data->assoc_info.req_ies)
1828 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1829 data->assoc_info.req_ies_len);
1830 if (data->assoc_info.resp_ies) {
1831 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1832 data->assoc_info.resp_ies_len);
1833#ifdef CONFIG_TDLS
1834 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1835 data->assoc_info.resp_ies_len);
1836#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001837#ifdef CONFIG_WNM
1838 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1839 data->assoc_info.resp_ies_len);
1840#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001841#ifdef CONFIG_INTERWORKING
1842 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1843 data->assoc_info.resp_ies_len);
1844#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001845 }
1846 if (data->assoc_info.beacon_ies)
1847 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1848 data->assoc_info.beacon_ies,
1849 data->assoc_info.beacon_ies_len);
1850 if (data->assoc_info.freq)
1851 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1852 data->assoc_info.freq);
1853
1854 p = data->assoc_info.req_ies;
1855 l = data->assoc_info.req_ies_len;
1856
1857 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1858 while (p && l >= 2) {
1859 len = p[1] + 2;
1860 if (len > l) {
1861 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1862 p, l);
1863 break;
1864 }
1865 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1866 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1867 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1868 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1869 break;
1870 found = 1;
1871 wpa_find_assoc_pmkid(wpa_s);
1872 break;
1873 }
1874 l -= len;
1875 p += len;
1876 }
1877 if (!found && data->assoc_info.req_ies)
1878 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1879
1880#ifdef CONFIG_IEEE80211R
1881#ifdef CONFIG_SME
1882 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001883 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1884 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1885 data->assoc_info.resp_ies,
1886 data->assoc_info.resp_ies_len,
1887 bssid) < 0) {
1888 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1889 "Reassociation Response failed");
1890 wpa_supplicant_deauthenticate(
1891 wpa_s, WLAN_REASON_INVALID_IE);
1892 return -1;
1893 }
1894 }
1895
1896 p = data->assoc_info.resp_ies;
1897 l = data->assoc_info.resp_ies_len;
1898
1899#ifdef CONFIG_WPS_STRICT
1900 if (p && wpa_s->current_ssid &&
1901 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1902 struct wpabuf *wps;
1903 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1904 if (wps == NULL) {
1905 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1906 "include WPS IE in (Re)Association Response");
1907 return -1;
1908 }
1909
1910 if (wps_validate_assoc_resp(wps) < 0) {
1911 wpabuf_free(wps);
1912 wpa_supplicant_deauthenticate(
1913 wpa_s, WLAN_REASON_INVALID_IE);
1914 return -1;
1915 }
1916 wpabuf_free(wps);
1917 }
1918#endif /* CONFIG_WPS_STRICT */
1919
1920 /* Go through the IEs and make a copy of the MDIE, if present. */
1921 while (p && l >= 2) {
1922 len = p[1] + 2;
1923 if (len > l) {
1924 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1925 p, l);
1926 break;
1927 }
1928 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1929 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1930 wpa_s->sme.ft_used = 1;
1931 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1932 MOBILITY_DOMAIN_ID_LEN);
1933 break;
1934 }
1935 l -= len;
1936 p += len;
1937 }
1938#endif /* CONFIG_SME */
1939
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001940 /* Process FT when SME is in the driver */
1941 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1942 wpa_ft_is_completed(wpa_s->wpa)) {
1943 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1944 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1945 data->assoc_info.resp_ies,
1946 data->assoc_info.resp_ies_len,
1947 bssid) < 0) {
1948 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1949 "Reassociation Response failed");
1950 wpa_supplicant_deauthenticate(
1951 wpa_s, WLAN_REASON_INVALID_IE);
1952 return -1;
1953 }
1954 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1955 }
1956
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001957 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1958 data->assoc_info.resp_ies_len);
1959#endif /* CONFIG_IEEE80211R */
1960
1961 /* WPA/RSN IE from Beacon/ProbeResp */
1962 p = data->assoc_info.beacon_ies;
1963 l = data->assoc_info.beacon_ies_len;
1964
1965 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1966 */
1967 wpa_found = rsn_found = 0;
1968 while (p && l >= 2) {
1969 len = p[1] + 2;
1970 if (len > l) {
1971 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1972 p, l);
1973 break;
1974 }
1975 if (!wpa_found &&
1976 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1977 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1978 wpa_found = 1;
1979 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1980 }
1981
1982 if (!rsn_found &&
1983 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1984 rsn_found = 1;
1985 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1986 }
1987
1988 l -= len;
1989 p += len;
1990 }
1991
1992 if (!wpa_found && data->assoc_info.beacon_ies)
1993 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1994 if (!rsn_found && data->assoc_info.beacon_ies)
1995 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1996 if (wpa_found || rsn_found)
1997 wpa_s->ap_ies_from_associnfo = 1;
1998
Jouni Malinen87fd2792011-05-16 18:35:42 +03001999 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2000 wpa_s->assoc_freq != data->assoc_info.freq) {
2001 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2002 "%u to %u MHz",
2003 wpa_s->assoc_freq, data->assoc_info.freq);
2004 wpa_supplicant_update_scan_results(wpa_s);
2005 }
2006
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002007 wpa_s->assoc_freq = data->assoc_info.freq;
2008
2009 return 0;
2010}
2011
2012
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002013static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2014{
2015 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2016
2017 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2018 return -1;
2019
2020 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2021 return 0;
2022
2023 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2024 WPA_IE_VENDOR_TYPE);
2025 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2026
2027 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2028 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2029 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2030 bss_rsn ? 2 + bss_rsn[1] : 0))
2031 return -1;
2032
2033 return 0;
2034}
2035
2036
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002037static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2038 union wpa_event_data *data)
2039{
2040 u8 bssid[ETH_ALEN];
2041 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002042
2043#ifdef CONFIG_AP
2044 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002045 if (!data)
2046 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002047 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2048 data->assoc_info.addr,
2049 data->assoc_info.req_ies,
2050 data->assoc_info.req_ies_len,
2051 data->assoc_info.reassoc);
2052 return;
2053 }
2054#endif /* CONFIG_AP */
2055
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002056 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2057
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002058 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2059 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2060 return;
2061
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002062 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2063 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002064 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002065 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2066 return;
2067 }
2068
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002069 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002070 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002071 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2072 MACSTR, MAC2STR(bssid));
2073 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002074 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2075 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002076 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002077
2078 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2079 wpa_clear_keys(wpa_s, bssid);
2080 }
2081 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002082 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002083 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2084 return;
2085 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002086
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08002087#ifdef ANDROID
2088 if (wpa_s->conf->ap_scan == 1) {
2089#else
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002090 if (wpa_s->conf->ap_scan == 1 &&
2091 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08002092#endif
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002093 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
2094 wpa_msg(wpa_s, MSG_WARNING,
2095 "WPA/RSN IEs not updated");
2096 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002097 }
2098
2099#ifdef CONFIG_SME
2100 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2101 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07002102 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002103#endif /* CONFIG_SME */
2104
2105 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2106 if (wpa_s->current_ssid) {
2107 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2108 * initialized before association, but for other modes,
2109 * initialize PC/SC here, if the current configuration needs
2110 * smartcard or SIM/USIM. */
2111 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2112 }
2113 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2114 if (wpa_s->l2)
2115 l2_packet_notify_auth_start(wpa_s->l2);
2116
2117 /*
2118 * Set portEnabled first to FALSE in order to get EAP state machine out
2119 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2120 * state machine may transit to AUTHENTICATING state based on obsolete
2121 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2122 * AUTHENTICATED without ever giving chance to EAP state machine to
2123 * reset the state.
2124 */
2125 if (!ft_completed) {
2126 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2127 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2128 }
2129 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2130 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2131 /* 802.1X::portControl = Auto */
2132 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2133 wpa_s->eapol_received = 0;
2134 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2135 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2136 (wpa_s->current_ssid &&
2137 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002138 if (wpa_s->current_ssid &&
2139 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002140 (wpa_s->drv_flags &
2141 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2142 /*
2143 * Set the key after having received joined-IBSS event
2144 * from the driver.
2145 */
2146 wpa_supplicant_set_wpa_none_key(wpa_s,
2147 wpa_s->current_ssid);
2148 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002149 wpa_supplicant_cancel_auth_timeout(wpa_s);
2150 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2151 } else if (!ft_completed) {
2152 /* Timeout for receiving the first EAPOL packet */
2153 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2154 }
2155 wpa_supplicant_cancel_scan(wpa_s);
2156
2157 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2158 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2159 /*
2160 * We are done; the driver will take care of RSN 4-way
2161 * handshake.
2162 */
2163 wpa_supplicant_cancel_auth_timeout(wpa_s);
2164 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2165 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2166 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2167 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2168 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2169 /*
2170 * The driver will take care of RSN 4-way handshake, so we need
2171 * to allow EAPOL supplicant to complete its work without
2172 * waiting for WPA supplicant.
2173 */
2174 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2175 } else if (ft_completed) {
2176 /*
2177 * FT protocol completed - make sure EAPOL state machine ends
2178 * up in authenticated.
2179 */
2180 wpa_supplicant_cancel_auth_timeout(wpa_s);
2181 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2182 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2183 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2184 }
2185
Jouni Malinena05074c2012-12-21 21:35:35 +02002186 wpa_s->last_eapol_matches_bssid = 0;
2187
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002188 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002189 struct os_reltime now, age;
2190 os_get_reltime(&now);
2191 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002192 if (age.sec == 0 && age.usec < 100000 &&
2193 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2194 0) {
2195 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2196 "frame that was received just before "
2197 "association notification");
2198 wpa_supplicant_rx_eapol(
2199 wpa_s, wpa_s->pending_eapol_rx_src,
2200 wpabuf_head(wpa_s->pending_eapol_rx),
2201 wpabuf_len(wpa_s->pending_eapol_rx));
2202 }
2203 wpabuf_free(wpa_s->pending_eapol_rx);
2204 wpa_s->pending_eapol_rx = NULL;
2205 }
2206
2207 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2208 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002209 wpa_s->current_ssid &&
2210 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002211 /* Set static WEP keys again */
2212 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2213 }
2214
2215#ifdef CONFIG_IBSS_RSN
2216 if (wpa_s->current_ssid &&
2217 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2218 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2219 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2220 wpa_s->ibss_rsn == NULL) {
2221 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2222 if (!wpa_s->ibss_rsn) {
2223 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2224 wpa_supplicant_deauthenticate(
2225 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2226 return;
2227 }
2228
2229 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2230 }
2231#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002232
2233 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002234
2235 if (data) {
2236 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2237 data->assoc_info.resp_ies_len,
2238 &data->assoc_info.wmm_params);
2239
2240 if (wpa_s->reassoc_same_bss)
2241 wmm_ac_restore_tspecs(wpa_s);
2242 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002243}
2244
2245
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002246static int disconnect_reason_recoverable(u16 reason_code)
2247{
2248 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2249 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2250 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2251}
2252
2253
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002254static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002255 u16 reason_code,
2256 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002257{
2258 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002259
2260 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2261 /*
2262 * At least Host AP driver and a Prism3 card seemed to be
2263 * generating streams of disconnected events when configuring
2264 * IBSS for WPA-None. Ignore them for now.
2265 */
2266 return;
2267 }
2268
2269 bssid = wpa_s->bssid;
2270 if (is_zero_ether_addr(bssid))
2271 bssid = wpa_s->pending_bssid;
2272
2273 if (!is_zero_ether_addr(bssid) ||
2274 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2275 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2276 " reason=%d%s",
2277 MAC2STR(bssid), reason_code,
2278 locally_generated ? " locally_generated=1" : "");
2279 }
2280}
2281
2282
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002283static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2284 int locally_generated)
2285{
2286 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2287 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2288 return 0; /* Not in 4-way handshake with PSK */
2289
2290 /*
2291 * It looks like connection was lost while trying to go through PSK
2292 * 4-way handshake. Filter out known disconnection cases that are caused
2293 * by something else than PSK mismatch to avoid confusing reports.
2294 */
2295
2296 if (locally_generated) {
2297 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2298 return 0;
2299 }
2300
2301 return 1;
2302}
2303
2304
Jouni Malinen2b89da82012-08-31 22:04:41 +03002305static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2306 u16 reason_code,
2307 int locally_generated)
2308{
2309 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002310 int authenticating;
2311 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002312 struct wpa_bss *fast_reconnect = NULL;
2313 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002314 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002315
2316 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2317 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2318
2319 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2320 /*
2321 * At least Host AP driver and a Prism3 card seemed to be
2322 * generating streams of disconnected events when configuring
2323 * IBSS for WPA-None. Ignore them for now.
2324 */
2325 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2326 "IBSS/WPA-None mode");
2327 return;
2328 }
2329
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002330 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002331 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2332 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002333 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2334 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002335 wpas_auth_failed(wpa_s, "WRONG_KEY");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002336 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002337 if (!wpa_s->disconnected &&
2338 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002339 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2340 wpas_wps_searching(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002341 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002342 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002343 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002344 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002345 wpa_s->wpa_state);
2346 if (wpa_s->wpa_state == WPA_COMPLETED &&
2347 wpa_s->current_ssid &&
2348 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002349 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002350 disconnect_reason_recoverable(reason_code)) {
2351 /*
2352 * It looks like the AP has dropped association with
2353 * us, but could allow us to get back in. Try to
2354 * reconnect to the same BSS without full scan to save
2355 * time for some common cases.
2356 */
2357 fast_reconnect = wpa_s->current_bss;
2358 fast_reconnect_ssid = wpa_s->current_ssid;
2359 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002360 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002361 else
2362 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2363 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002364 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002365 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002366 "try to re-connect");
2367 wpa_s->reassociate = 0;
2368 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002369 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002370 }
2371 bssid = wpa_s->bssid;
2372 if (is_zero_ether_addr(bssid))
2373 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002374 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2375 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002376 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002377 if (locally_generated)
2378 wpa_s->disconnect_reason = -reason_code;
2379 else
2380 wpa_s->disconnect_reason = reason_code;
2381 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002382 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2383 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002384 wpa_clear_keys(wpa_s, wpa_s->bssid);
2385 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002386 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002387 wpa_supplicant_mark_disassoc(wpa_s);
2388
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002389 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002390 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002391 wpa_s->current_ssid = last_ssid;
2392 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002393
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002394 if (fast_reconnect &&
2395 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2396 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2397 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2398 fast_reconnect->ssid_len) &&
2399 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002400#ifndef CONFIG_NO_SCAN_PROCESSING
2401 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2402 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2403 fast_reconnect_ssid) < 0) {
2404 /* Recover through full scan */
2405 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2406 }
2407#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002408 } else if (fast_reconnect) {
2409 /*
2410 * Could not reconnect to the same BSS due to network being
2411 * disabled. Use a new scan to match the alternative behavior
2412 * above, i.e., to continue automatic reconnection attempt in a
2413 * way that enforces disabled network rules.
2414 */
2415 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002416 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002417}
2418
2419
2420#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002421void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002422{
2423 struct wpa_supplicant *wpa_s = eloop_ctx;
2424
2425 if (!wpa_s->pending_mic_error_report)
2426 return;
2427
2428 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2429 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2430 wpa_s->pending_mic_error_report = 0;
2431}
2432#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2433
2434
2435static void
2436wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2437 union wpa_event_data *data)
2438{
2439 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002440 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002441
2442 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2443 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002444 os_get_reltime(&t);
2445 if ((wpa_s->last_michael_mic_error.sec &&
2446 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002447 wpa_s->pending_mic_error_report) {
2448 if (wpa_s->pending_mic_error_report) {
2449 /*
2450 * Send the pending MIC error report immediately since
2451 * we are going to start countermeasures and AP better
2452 * do the same.
2453 */
2454 wpa_sm_key_request(wpa_s->wpa, 1,
2455 wpa_s->pending_mic_error_pairwise);
2456 }
2457
2458 /* Send the new MIC error report immediately since we are going
2459 * to start countermeasures and AP better do the same.
2460 */
2461 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2462
2463 /* initialize countermeasures */
2464 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002465
2466 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2467
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002468 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2469
2470 /*
2471 * Need to wait for completion of request frame. We do not get
2472 * any callback for the message completion, so just wait a
2473 * short while and hope for the best. */
2474 os_sleep(0, 10000);
2475
2476 wpa_drv_set_countermeasures(wpa_s, 1);
2477 wpa_supplicant_deauthenticate(wpa_s,
2478 WLAN_REASON_MICHAEL_MIC_FAILURE);
2479 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2480 wpa_s, NULL);
2481 eloop_register_timeout(60, 0,
2482 wpa_supplicant_stop_countermeasures,
2483 wpa_s, NULL);
2484 /* TODO: mark the AP rejected for 60 second. STA is
2485 * allowed to associate with another AP.. */
2486 } else {
2487#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2488 if (wpa_s->mic_errors_seen) {
2489 /*
2490 * Reduce the effectiveness of Michael MIC error
2491 * reports as a means for attacking against TKIP if
2492 * more than one MIC failure is noticed with the same
2493 * PTK. We delay the transmission of the reports by a
2494 * random time between 0 and 60 seconds in order to
2495 * force the attacker wait 60 seconds before getting
2496 * the information on whether a frame resulted in a MIC
2497 * failure.
2498 */
2499 u8 rval[4];
2500 int sec;
2501
2502 if (os_get_random(rval, sizeof(rval)) < 0)
2503 sec = os_random() % 60;
2504 else
2505 sec = WPA_GET_BE32(rval) % 60;
2506 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2507 "report %d seconds", sec);
2508 wpa_s->pending_mic_error_report = 1;
2509 wpa_s->pending_mic_error_pairwise = pairwise;
2510 eloop_cancel_timeout(
2511 wpa_supplicant_delayed_mic_error_report,
2512 wpa_s, NULL);
2513 eloop_register_timeout(
2514 sec, os_random() % 1000000,
2515 wpa_supplicant_delayed_mic_error_report,
2516 wpa_s, NULL);
2517 } else {
2518 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2519 }
2520#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2521 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2522#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2523 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002524 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002525 wpa_s->mic_errors_seen++;
2526}
2527
2528
2529#ifdef CONFIG_TERMINATE_ONLASTIF
2530static int any_interfaces(struct wpa_supplicant *head)
2531{
2532 struct wpa_supplicant *wpa_s;
2533
2534 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2535 if (!wpa_s->interface_removed)
2536 return 1;
2537 return 0;
2538}
2539#endif /* CONFIG_TERMINATE_ONLASTIF */
2540
2541
2542static void
2543wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2544 union wpa_event_data *data)
2545{
2546 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2547 return;
2548
2549 switch (data->interface_status.ievent) {
2550 case EVENT_INTERFACE_ADDED:
2551 if (!wpa_s->interface_removed)
2552 break;
2553 wpa_s->interface_removed = 0;
2554 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2555 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2556 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2557 "driver after interface was added");
2558 }
2559 break;
2560 case EVENT_INTERFACE_REMOVED:
2561 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2562 wpa_s->interface_removed = 1;
2563 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002564 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002565 l2_packet_deinit(wpa_s->l2);
2566 wpa_s->l2 = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002567#ifdef CONFIG_TERMINATE_ONLASTIF
2568 /* check if last interface */
2569 if (!any_interfaces(wpa_s->global->ifaces))
2570 eloop_terminate();
2571#endif /* CONFIG_TERMINATE_ONLASTIF */
2572 break;
2573 }
2574}
2575
2576
2577#ifdef CONFIG_PEERKEY
2578static void
2579wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2580 union wpa_event_data *data)
2581{
2582 if (data == NULL)
2583 return;
2584 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2585}
2586#endif /* CONFIG_PEERKEY */
2587
2588
2589#ifdef CONFIG_TDLS
2590static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2591 union wpa_event_data *data)
2592{
2593 if (data == NULL)
2594 return;
2595 switch (data->tdls.oper) {
2596 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002597 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2598 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2599 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2600 else
2601 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002602 break;
2603 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002604 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2605 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2606 data->tdls.reason_code);
2607 else
2608 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2609 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002610 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07002611 case TDLS_REQUEST_DISCOVER:
2612 wpa_tdls_send_discovery_request(wpa_s->wpa,
2613 data->tdls.peer);
2614 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002615 }
2616}
2617#endif /* CONFIG_TDLS */
2618
2619
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002620#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002621static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2622 union wpa_event_data *data)
2623{
2624 if (data == NULL)
2625 return;
2626 switch (data->wnm.oper) {
2627 case WNM_OPER_SLEEP:
2628 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2629 "(action=%d, intval=%d)",
2630 data->wnm.sleep_action, data->wnm.sleep_intval);
2631 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002632 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002633 break;
2634 }
2635}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002636#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002637
2638
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002639#ifdef CONFIG_IEEE80211R
2640static void
2641wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2642 union wpa_event_data *data)
2643{
2644 if (data == NULL)
2645 return;
2646
2647 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2648 data->ft_ies.ies_len,
2649 data->ft_ies.ft_action,
2650 data->ft_ies.target_ap,
2651 data->ft_ies.ric_ies,
2652 data->ft_ies.ric_ies_len) < 0) {
2653 /* TODO: prevent MLME/driver from trying to associate? */
2654 }
2655}
2656#endif /* CONFIG_IEEE80211R */
2657
2658
2659#ifdef CONFIG_IBSS_RSN
2660static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2661 union wpa_event_data *data)
2662{
2663 struct wpa_ssid *ssid;
2664 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2665 return;
2666 if (data == NULL)
2667 return;
2668 ssid = wpa_s->current_ssid;
2669 if (ssid == NULL)
2670 return;
2671 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2672 return;
2673
2674 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2675}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002676
2677
2678static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2679 union wpa_event_data *data)
2680{
2681 struct wpa_ssid *ssid = wpa_s->current_ssid;
2682
2683 if (ssid == NULL)
2684 return;
2685
2686 /* check if the ssid is correctly configured as IBSS/RSN */
2687 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2688 return;
2689
2690 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2691 data->rx_mgmt.frame_len);
2692}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002693#endif /* CONFIG_IBSS_RSN */
2694
2695
2696#ifdef CONFIG_IEEE80211R
2697static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2698 size_t len)
2699{
2700 const u8 *sta_addr, *target_ap_addr;
2701 u16 status;
2702
2703 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2704 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2705 return; /* only SME case supported for now */
2706 if (len < 1 + 2 * ETH_ALEN + 2)
2707 return;
2708 if (data[0] != 2)
2709 return; /* Only FT Action Response is supported for now */
2710 sta_addr = data + 1;
2711 target_ap_addr = data + 1 + ETH_ALEN;
2712 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2713 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2714 MACSTR " TargetAP " MACSTR " status %u",
2715 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2716
2717 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2718 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2719 " in FT Action Response", MAC2STR(sta_addr));
2720 return;
2721 }
2722
2723 if (status) {
2724 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2725 "failure (status code %d)", status);
2726 /* TODO: report error to FT code(?) */
2727 return;
2728 }
2729
2730 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2731 len - (1 + 2 * ETH_ALEN + 2), 1,
2732 target_ap_addr, NULL, 0) < 0)
2733 return;
2734
2735#ifdef CONFIG_SME
2736 {
2737 struct wpa_bss *bss;
2738 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2739 if (bss)
2740 wpa_s->sme.freq = bss->freq;
2741 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2742 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2743 WLAN_AUTH_FT);
2744 }
2745#endif /* CONFIG_SME */
2746}
2747#endif /* CONFIG_IEEE80211R */
2748
2749
2750static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2751 struct unprot_deauth *e)
2752{
2753#ifdef CONFIG_IEEE80211W
2754 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2755 "dropped: " MACSTR " -> " MACSTR
2756 " (reason code %u)",
2757 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2758 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2759#endif /* CONFIG_IEEE80211W */
2760}
2761
2762
2763static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2764 struct unprot_disassoc *e)
2765{
2766#ifdef CONFIG_IEEE80211W
2767 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2768 "dropped: " MACSTR " -> " MACSTR
2769 " (reason code %u)",
2770 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2771 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2772#endif /* CONFIG_IEEE80211W */
2773}
2774
2775
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002776static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2777 u16 reason_code, int locally_generated,
2778 const u8 *ie, size_t ie_len, int deauth)
2779{
2780#ifdef CONFIG_AP
2781 if (wpa_s->ap_iface && addr) {
2782 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2783 return;
2784 }
2785
2786 if (wpa_s->ap_iface) {
2787 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2788 return;
2789 }
2790#endif /* CONFIG_AP */
2791
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002792 if (!locally_generated)
2793 wpa_s->own_disconnect_req = 0;
2794
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002795 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2796
Dmitry Shmidt344abd32014-01-14 13:17:00 -08002797 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2798 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2799 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2800 eapol_sm_failed(wpa_s->eapol))) &&
2801 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002802 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002803
2804#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002805 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002806 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2807 locally_generated) > 0) {
2808 /*
2809 * The interface was removed, so cannot continue
2810 * processing any additional operations after this.
2811 */
2812 return;
2813 }
2814 }
2815#endif /* CONFIG_P2P */
2816
2817 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2818 locally_generated);
2819}
2820
2821
2822static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2823 struct disassoc_info *info)
2824{
2825 u16 reason_code = 0;
2826 int locally_generated = 0;
2827 const u8 *addr = NULL;
2828 const u8 *ie = NULL;
2829 size_t ie_len = 0;
2830
2831 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2832
2833 if (info) {
2834 addr = info->addr;
2835 ie = info->ie;
2836 ie_len = info->ie_len;
2837 reason_code = info->reason_code;
2838 locally_generated = info->locally_generated;
2839 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2840 locally_generated ? " (locally generated)" : "");
2841 if (addr)
2842 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2843 MAC2STR(addr));
2844 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2845 ie, ie_len);
2846 }
2847
2848#ifdef CONFIG_AP
2849 if (wpa_s->ap_iface && info && info->addr) {
2850 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2851 return;
2852 }
2853
2854 if (wpa_s->ap_iface) {
2855 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2856 return;
2857 }
2858#endif /* CONFIG_AP */
2859
2860#ifdef CONFIG_P2P
2861 if (info) {
2862 wpas_p2p_disassoc_notif(
2863 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2864 locally_generated);
2865 }
2866#endif /* CONFIG_P2P */
2867
2868 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2869 sme_event_disassoc(wpa_s, info);
2870
2871 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2872 ie, ie_len, 0);
2873}
2874
2875
2876static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2877 struct deauth_info *info)
2878{
2879 u16 reason_code = 0;
2880 int locally_generated = 0;
2881 const u8 *addr = NULL;
2882 const u8 *ie = NULL;
2883 size_t ie_len = 0;
2884
2885 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2886
2887 if (info) {
2888 addr = info->addr;
2889 ie = info->ie;
2890 ie_len = info->ie_len;
2891 reason_code = info->reason_code;
2892 locally_generated = info->locally_generated;
2893 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2894 reason_code,
2895 locally_generated ? " (locally generated)" : "");
2896 if (addr) {
2897 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2898 MAC2STR(addr));
2899 }
2900 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2901 ie, ie_len);
2902 }
2903
2904 wpa_reset_ft_completed(wpa_s->wpa);
2905
2906 wpas_event_disconnect(wpa_s, addr, reason_code,
2907 locally_generated, ie, ie_len, 1);
2908}
2909
2910
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002911static const char * reg_init_str(enum reg_change_initiator init)
2912{
2913 switch (init) {
2914 case REGDOM_SET_BY_CORE:
2915 return "CORE";
2916 case REGDOM_SET_BY_USER:
2917 return "USER";
2918 case REGDOM_SET_BY_DRIVER:
2919 return "DRIVER";
2920 case REGDOM_SET_BY_COUNTRY_IE:
2921 return "COUNTRY_IE";
2922 case REGDOM_BEACON_HINT:
2923 return "BEACON_HINT";
2924 }
2925 return "?";
2926}
2927
2928
2929static const char * reg_type_str(enum reg_type type)
2930{
2931 switch (type) {
2932 case REGDOM_TYPE_UNKNOWN:
2933 return "UNKNOWN";
2934 case REGDOM_TYPE_COUNTRY:
2935 return "COUNTRY";
2936 case REGDOM_TYPE_WORLD:
2937 return "WORLD";
2938 case REGDOM_TYPE_CUSTOM_WORLD:
2939 return "CUSTOM_WORLD";
2940 case REGDOM_TYPE_INTERSECTION:
2941 return "INTERSECTION";
2942 }
2943 return "?";
2944}
2945
2946
2947static void wpa_supplicant_update_channel_list(
2948 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002949{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002950 struct wpa_supplicant *ifs;
2951
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002952 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
Dmitry Shmidtc2817022014-07-02 10:32:10 -07002953 reg_init_str(info->initiator), reg_type_str(info->type),
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002954 info->alpha2[0] ? " alpha2=" : "",
2955 info->alpha2[0] ? info->alpha2 : "");
2956
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002957 if (wpa_s->drv_priv == NULL)
2958 return; /* Ignore event during drv initialization */
2959
2960 free_hw_features(wpa_s);
2961 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2962 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2963
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002964 wpas_p2p_update_channel_list(wpa_s);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002965
2966 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002967 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002968 * so, they get updated with this same hw mode info.
2969 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002970 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2971 radio_list) {
2972 if (ifs != wpa_s) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002973 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2974 ifs->ifname);
2975 free_hw_features(ifs);
2976 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2977 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2978 }
2979 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002980
2981 /* Restart sched_scan with updated channel list */
2982 if (wpa_s->sched_scanning) {
2983 wpa_dbg(wpa_s, MSG_DEBUG,
2984 "Channel list changed restart sched scan.");
2985 wpa_supplicant_cancel_sched_scan(wpa_s);
2986 wpa_supplicant_req_scan(wpa_s, 0, 0);
2987 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002988}
2989
2990
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002991static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002992 const u8 *frame, size_t len, int freq,
2993 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002994{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07002995 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002996 const u8 *payload;
2997 size_t plen;
2998 u8 category;
2999
3000 if (len < IEEE80211_HDRLEN + 2)
3001 return;
3002
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003003 mgmt = (const struct ieee80211_mgmt *) frame;
3004 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003005 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003006 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003007
3008 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3009 " Category=%u DataLen=%d freq=%d MHz",
3010 MAC2STR(mgmt->sa), category, (int) plen, freq);
3011
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003012 if (category == WLAN_ACTION_WMM) {
3013 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3014 return;
3015 }
3016
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003017#ifdef CONFIG_IEEE80211R
3018 if (category == WLAN_ACTION_FT) {
3019 ft_rx_action(wpa_s, payload, plen);
3020 return;
3021 }
3022#endif /* CONFIG_IEEE80211R */
3023
3024#ifdef CONFIG_IEEE80211W
3025#ifdef CONFIG_SME
3026 if (category == WLAN_ACTION_SA_QUERY) {
3027 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3028 return;
3029 }
3030#endif /* CONFIG_SME */
3031#endif /* CONFIG_IEEE80211W */
3032
3033#ifdef CONFIG_WNM
3034 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3035 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3036 return;
3037 }
3038#endif /* CONFIG_WNM */
3039
3040#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08003041 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3042 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003043 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08003044 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003045 payload, plen, freq) == 0)
3046 return;
3047#endif /* CONFIG_GAS */
3048
3049#ifdef CONFIG_TDLS
3050 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3051 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3052 wpa_dbg(wpa_s, MSG_DEBUG,
3053 "TDLS: Received Discovery Response from " MACSTR,
3054 MAC2STR(mgmt->sa));
3055 return;
3056 }
3057#endif /* CONFIG_TDLS */
3058
3059#ifdef CONFIG_INTERWORKING
3060 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3061 payload[0] == QOS_QOS_MAP_CONFIG) {
3062 const u8 *pos = payload + 1;
3063 size_t qlen = plen - 1;
3064 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3065 MACSTR, MAC2STR(mgmt->sa));
3066 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3067 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3068 pos[1] <= qlen - 2 && pos[1] >= 16)
3069 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3070 return;
3071 }
3072#endif /* CONFIG_INTERWORKING */
3073
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003074 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3075 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3076 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3077 return;
3078 }
3079
3080 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3081 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3082 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3083 payload + 1, plen - 1,
3084 rssi);
3085 return;
3086 }
3087
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003088 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3089 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003090 if (wpa_s->ifmsh)
3091 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003092}
3093
3094
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003095static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3096 union wpa_event_data *event)
3097{
3098#ifdef CONFIG_P2P
3099 struct wpa_supplicant *ifs;
3100#endif /* CONFIG_P2P */
3101 struct wpa_freq_range_list *list;
3102 char *str = NULL;
3103
3104 list = &event->freq_range;
3105
3106 if (list->num)
3107 str = freq_range_list_str(list);
3108 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3109 str ? str : "");
3110
3111#ifdef CONFIG_P2P
3112 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3113 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3114 __func__);
3115 } else {
3116 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
3117 wpas_p2p_update_channel_list(wpa_s);
3118 }
3119
3120 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
3121 int freq;
3122 if (!ifs->current_ssid ||
3123 !ifs->current_ssid->p2p_group ||
3124 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
3125 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
3126 continue;
3127
3128 freq = ifs->current_ssid->frequency;
3129 if (!freq_range_list_includes(list, freq)) {
3130 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range",
3131 freq);
3132 continue;
3133 }
3134
3135 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz",
3136 freq);
3137 /* TODO: Consider using CSA or removing the group within
3138 * wpa_supplicant */
3139 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
3140 }
3141#endif /* CONFIG_P2P */
3142
3143 os_free(str);
3144}
3145
3146
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003147static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3148 union wpa_event_data *data)
3149{
3150 wpa_dbg(wpa_s, MSG_DEBUG,
3151 "Connection authorized by device, previous state %d",
3152 wpa_s->wpa_state);
3153 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3154 wpa_supplicant_cancel_auth_timeout(wpa_s);
3155 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3156 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3157 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3158 }
3159 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3160 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003161 data->assoc_info.ptk_kck_len,
3162 data->assoc_info.ptk_kek,
3163 data->assoc_info.ptk_kek_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003164}
3165
3166
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003167void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3168 union wpa_event_data *data)
3169{
3170 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003171
3172 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3173 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003174 event != EVENT_INTERFACE_STATUS &&
3175 event != EVENT_SCHED_SCAN_STOPPED) {
3176 wpa_dbg(wpa_s, MSG_DEBUG,
3177 "Ignore event %s (%d) while interface is disabled",
3178 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003179 return;
3180 }
3181
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003182#ifndef CONFIG_NO_STDOUT_DEBUG
3183{
3184 int level = MSG_DEBUG;
3185
Dmitry Shmidt04949592012-07-19 12:16:46 -07003186 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003187 const struct ieee80211_hdr *hdr;
3188 u16 fc;
3189 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3190 fc = le_to_host16(hdr->frame_control);
3191 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3192 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3193 level = MSG_EXCESSIVE;
3194 }
3195
3196 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3197 event_to_string(event), event);
3198}
3199#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003200
3201 switch (event) {
3202 case EVENT_AUTH:
3203 sme_event_auth(wpa_s, data);
3204 break;
3205 case EVENT_ASSOC:
3206 wpa_supplicant_event_assoc(wpa_s, data);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003207 if (data && data->assoc_info.authorized)
3208 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003209 break;
3210 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003211 wpas_event_disassoc(wpa_s,
3212 data ? &data->disassoc_info : NULL);
3213 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003214 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003215 wpas_event_deauth(wpa_s,
3216 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003217 break;
3218 case EVENT_MICHAEL_MIC_FAILURE:
3219 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3220 break;
3221#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003222 case EVENT_SCAN_STARTED:
3223 os_get_reltime(&wpa_s->scan_start_time);
3224 if (wpa_s->own_scan_requested) {
3225 struct os_reltime diff;
3226
3227 os_reltime_sub(&wpa_s->scan_start_time,
3228 &wpa_s->scan_trigger_time, &diff);
3229 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3230 diff.sec, diff.usec);
3231 wpa_s->own_scan_requested = 0;
3232 wpa_s->own_scan_running = 1;
3233 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3234 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003235 wpa_msg_ctrl(wpa_s, MSG_INFO,
3236 WPA_EVENT_SCAN_STARTED "id=%u",
3237 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003238 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003239 wpa_msg_ctrl(wpa_s, MSG_INFO,
3240 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003241 }
3242 } else {
3243 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003244 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003245 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003246 }
3247 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003248 case EVENT_SCAN_RESULTS:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003249 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3250 struct os_reltime now, diff;
3251 os_get_reltime(&now);
3252 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3253 wpa_s->scan_start_time.sec = 0;
3254 wpa_s->scan_start_time.usec = 0;
3255 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3256 diff.sec, diff.usec);
3257 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003258 if (wpa_supplicant_event_scan_results(wpa_s, data))
3259 break; /* interface may have been removed */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003260 wpa_s->own_scan_running = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003261 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003262 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003263 break;
3264#endif /* CONFIG_NO_SCAN_PROCESSING */
3265 case EVENT_ASSOCINFO:
3266 wpa_supplicant_event_associnfo(wpa_s, data);
3267 break;
3268 case EVENT_INTERFACE_STATUS:
3269 wpa_supplicant_event_interface_status(wpa_s, data);
3270 break;
3271 case EVENT_PMKID_CANDIDATE:
3272 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3273 break;
3274#ifdef CONFIG_PEERKEY
3275 case EVENT_STKSTART:
3276 wpa_supplicant_event_stkstart(wpa_s, data);
3277 break;
3278#endif /* CONFIG_PEERKEY */
3279#ifdef CONFIG_TDLS
3280 case EVENT_TDLS:
3281 wpa_supplicant_event_tdls(wpa_s, data);
3282 break;
3283#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003284#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003285 case EVENT_WNM:
3286 wpa_supplicant_event_wnm(wpa_s, data);
3287 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003288#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003289#ifdef CONFIG_IEEE80211R
3290 case EVENT_FT_RESPONSE:
3291 wpa_supplicant_event_ft_response(wpa_s, data);
3292 break;
3293#endif /* CONFIG_IEEE80211R */
3294#ifdef CONFIG_IBSS_RSN
3295 case EVENT_IBSS_RSN_START:
3296 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3297 break;
3298#endif /* CONFIG_IBSS_RSN */
3299 case EVENT_ASSOC_REJECT:
3300 if (data->assoc_reject.bssid)
3301 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3302 "bssid=" MACSTR " status_code=%u",
3303 MAC2STR(data->assoc_reject.bssid),
3304 data->assoc_reject.status_code);
3305 else
3306 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3307 "status_code=%u",
3308 data->assoc_reject.status_code);
3309 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3310 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07003311 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003312 const u8 *bssid = data->assoc_reject.bssid;
3313 if (bssid == NULL || is_zero_ether_addr(bssid))
3314 bssid = wpa_s->pending_bssid;
3315 wpas_connection_failed(wpa_s, bssid);
3316 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003317 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003318 break;
3319 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003320 /* It is possible to get this event from earlier connection */
3321 if (wpa_s->current_ssid &&
3322 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3323 wpa_dbg(wpa_s, MSG_DEBUG,
3324 "Ignore AUTH_TIMED_OUT in mesh configuration");
3325 break;
3326 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003327 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3328 sme_event_auth_timed_out(wpa_s, data);
3329 break;
3330 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003331 /* It is possible to get this event from earlier connection */
3332 if (wpa_s->current_ssid &&
3333 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3334 wpa_dbg(wpa_s, MSG_DEBUG,
3335 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3336 break;
3337 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003338 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3339 sme_event_assoc_timed_out(wpa_s, data);
3340 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003341 case EVENT_TX_STATUS:
3342 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3343 " type=%d stype=%d",
3344 MAC2STR(data->tx_status.dst),
3345 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003346#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003347 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003348#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003349 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3350 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003351 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003352 wpa_s, data->tx_status.dst,
3353 data->tx_status.data,
3354 data->tx_status.data_len,
3355 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003356 OFFCHANNEL_SEND_ACTION_SUCCESS :
3357 OFFCHANNEL_SEND_ACTION_NO_ACK);
3358#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003359 break;
3360 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003361#endif /* CONFIG_AP */
3362#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003363 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3364 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3365 /*
3366 * Catch TX status events for Action frames we sent via group
3367 * interface in GO mode.
3368 */
3369 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3370 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3371 os_memcmp(wpa_s->parent->pending_action_dst,
3372 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003373 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003374 wpa_s->parent, data->tx_status.dst,
3375 data->tx_status.data,
3376 data->tx_status.data_len,
3377 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003378 OFFCHANNEL_SEND_ACTION_SUCCESS :
3379 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003380 break;
3381 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003382#endif /* CONFIG_OFFCHANNEL */
3383#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003384 switch (data->tx_status.type) {
3385 case WLAN_FC_TYPE_MGMT:
3386 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3387 data->tx_status.data_len,
3388 data->tx_status.stype,
3389 data->tx_status.ack);
3390 break;
3391 case WLAN_FC_TYPE_DATA:
3392 ap_tx_status(wpa_s, data->tx_status.dst,
3393 data->tx_status.data,
3394 data->tx_status.data_len,
3395 data->tx_status.ack);
3396 break;
3397 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003398#endif /* CONFIG_AP */
3399 break;
3400#ifdef CONFIG_AP
3401 case EVENT_EAPOL_TX_STATUS:
3402 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3403 data->eapol_tx_status.data,
3404 data->eapol_tx_status.data_len,
3405 data->eapol_tx_status.ack);
3406 break;
3407 case EVENT_DRIVER_CLIENT_POLL_OK:
3408 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003409 break;
3410 case EVENT_RX_FROM_UNKNOWN:
3411 if (wpa_s->ap_iface == NULL)
3412 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003413 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3414 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003415 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003416 case EVENT_CH_SWITCH:
3417 if (!data)
3418 break;
3419 if (!wpa_s->ap_iface) {
3420 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3421 "event in non-AP mode");
3422 break;
3423 }
3424
Dmitry Shmidt04949592012-07-19 12:16:46 -07003425 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3426 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08003427 data->ch_switch.ch_offset,
3428 data->ch_switch.ch_width,
3429 data->ch_switch.cf1,
3430 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003431 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003432#ifdef NEED_AP_MLME
3433 case EVENT_DFS_RADAR_DETECTED:
3434 if (data)
3435 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3436 break;
3437 case EVENT_DFS_CAC_STARTED:
3438 if (data)
3439 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3440 break;
3441 case EVENT_DFS_CAC_FINISHED:
3442 if (data)
3443 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3444 break;
3445 case EVENT_DFS_CAC_ABORTED:
3446 if (data)
3447 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3448 break;
3449 case EVENT_DFS_NOP_FINISHED:
3450 if (data)
3451 wpas_event_dfs_cac_nop_finished(wpa_s,
3452 &data->dfs_event);
3453 break;
3454#endif /* NEED_AP_MLME */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003455#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003456 case EVENT_RX_MGMT: {
3457 u16 fc, stype;
3458 const struct ieee80211_mgmt *mgmt;
3459
Dmitry Shmidt818ea482014-03-10 13:15:21 -07003460#ifdef CONFIG_TESTING_OPTIONS
3461 if (wpa_s->ext_mgmt_frame_handling) {
3462 struct rx_mgmt *rx = &data->rx_mgmt;
3463 size_t hex_len = 2 * rx->frame_len + 1;
3464 char *hex = os_malloc(hex_len);
3465 if (hex) {
3466 wpa_snprintf_hex(hex, hex_len,
3467 rx->frame, rx->frame_len);
3468 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3469 rx->freq, rx->datarate, rx->ssi_signal,
3470 hex);
3471 os_free(hex);
3472 }
3473 break;
3474 }
3475#endif /* CONFIG_TESTING_OPTIONS */
3476
Dmitry Shmidt04949592012-07-19 12:16:46 -07003477 mgmt = (const struct ieee80211_mgmt *)
3478 data->rx_mgmt.frame;
3479 fc = le_to_host16(mgmt->frame_control);
3480 stype = WLAN_FC_GET_STYPE(fc);
3481
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003482#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003483 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003484#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003485#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003486 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3487 data->rx_mgmt.frame_len > 24) {
3488 const u8 *src = mgmt->sa;
3489 const u8 *ie = mgmt->u.probe_req.variable;
3490 size_t ie_len = data->rx_mgmt.frame_len -
3491 (mgmt->u.probe_req.variable -
3492 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003493 wpas_p2p_probe_req_rx(
3494 wpa_s, src, mgmt->da,
3495 mgmt->bssid, ie, ie_len,
3496 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003497 break;
3498 }
3499#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003500#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003501 if (wpa_s->current_ssid &&
3502 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3503 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003504 data->rx_mgmt.frame_len >= 30) {
3505 wpa_supplicant_event_ibss_auth(wpa_s, data);
3506 break;
3507 }
3508#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003509
3510 if (stype == WLAN_FC_STYPE_ACTION) {
3511 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003512 wpa_s, data->rx_mgmt.frame,
3513 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003514 data->rx_mgmt.freq,
3515 data->rx_mgmt.ssi_signal);
3516 break;
3517 }
3518
3519 if (wpa_s->ifmsh) {
3520 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003521 break;
3522 }
3523
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003524 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3525 "management frame in non-AP mode");
3526 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003527#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003528 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003529
3530 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3531 data->rx_mgmt.frame_len > 24) {
3532 const u8 *ie = mgmt->u.probe_req.variable;
3533 size_t ie_len = data->rx_mgmt.frame_len -
3534 (mgmt->u.probe_req.variable -
3535 data->rx_mgmt.frame);
3536
3537 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3538 mgmt->bssid, ie, ie_len,
3539 data->rx_mgmt.ssi_signal);
3540 }
3541
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003542 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003543#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003544 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003545 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003546 case EVENT_RX_PROBE_REQ:
3547 if (data->rx_probe_req.sa == NULL ||
3548 data->rx_probe_req.ie == NULL)
3549 break;
3550#ifdef CONFIG_AP
3551 if (wpa_s->ap_iface) {
3552 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3553 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003554 data->rx_probe_req.da,
3555 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003556 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003557 data->rx_probe_req.ie_len,
3558 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003559 break;
3560 }
3561#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003562 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003563 data->rx_probe_req.da,
3564 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003565 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003566 data->rx_probe_req.ie_len,
3567 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003568 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003569 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003570#ifdef CONFIG_OFFCHANNEL
3571 offchannel_remain_on_channel_cb(
3572 wpa_s, data->remain_on_channel.freq,
3573 data->remain_on_channel.duration);
3574#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003575 wpas_p2p_remain_on_channel_cb(
3576 wpa_s, data->remain_on_channel.freq,
3577 data->remain_on_channel.duration);
3578 break;
3579 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003580#ifdef CONFIG_OFFCHANNEL
3581 offchannel_cancel_remain_on_channel_cb(
3582 wpa_s, data->remain_on_channel.freq);
3583#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003584 wpas_p2p_cancel_remain_on_channel_cb(
3585 wpa_s, data->remain_on_channel.freq);
3586 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003587 case EVENT_EAPOL_RX:
3588 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3589 data->eapol_rx.data,
3590 data->eapol_rx.data_len);
3591 break;
3592 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003593 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3594 "above=%d signal=%d noise=%d txrate=%d",
3595 data->signal_change.above_threshold,
3596 data->signal_change.current_signal,
3597 data->signal_change.current_noise,
3598 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003599 wpa_bss_update_level(wpa_s->current_bss,
3600 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003601 bgscan_notify_signal_change(
3602 wpa_s, data->signal_change.above_threshold,
3603 data->signal_change.current_signal,
3604 data->signal_change.current_noise,
3605 data->signal_change.current_txrate);
3606 break;
3607 case EVENT_INTERFACE_ENABLED:
3608 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3609 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003610 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07003611 if (wpa_s->p2p_mgmt) {
3612 wpa_supplicant_set_state(wpa_s,
3613 WPA_DISCONNECTED);
3614 break;
3615 }
3616
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003617#ifdef CONFIG_AP
3618 if (!wpa_s->ap_iface) {
3619 wpa_supplicant_set_state(wpa_s,
3620 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003621 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003622 wpa_supplicant_req_scan(wpa_s, 0, 0);
3623 } else
3624 wpa_supplicant_set_state(wpa_s,
3625 WPA_COMPLETED);
3626#else /* CONFIG_AP */
3627 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3628 wpa_supplicant_req_scan(wpa_s, 0, 0);
3629#endif /* CONFIG_AP */
3630 }
3631 break;
3632 case EVENT_INTERFACE_DISABLED:
3633 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003634#ifdef CONFIG_P2P
3635 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3636 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3637 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3638 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003639 * Mark interface disabled if this happens to end up not
3640 * being removed as a separate P2P group interface.
3641 */
3642 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3643 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003644 * The interface was externally disabled. Remove
3645 * it assuming an external entity will start a
3646 * new session if needed.
3647 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003648 if (wpa_s->current_ssid &&
3649 wpa_s->current_ssid->p2p_group)
3650 wpas_p2p_interface_unavailable(wpa_s);
3651 else
3652 wpas_p2p_disconnect(wpa_s);
3653 /*
3654 * wpa_s instance may have been freed, so must not use
3655 * it here anymore.
3656 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003657 break;
3658 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003659 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3660 p2p_in_progress(wpa_s->global->p2p) > 1) {
3661 /* This radio work will be cancelled, so clear P2P
3662 * state as well.
3663 */
3664 p2p_stop_find(wpa_s->global->p2p);
3665 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003666#endif /* CONFIG_P2P */
3667
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003668 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3669 /*
3670 * Indicate disconnection to keep ctrl_iface events
3671 * consistent.
3672 */
3673 wpa_supplicant_event_disassoc(
3674 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3675 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003676 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003677 radio_remove_works(wpa_s, NULL, 0);
3678
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003679 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3680 break;
3681 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003682 wpa_supplicant_update_channel_list(
3683 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003684 break;
3685 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003686 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003687 break;
3688 case EVENT_BEST_CHANNEL:
3689 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3690 "(%d %d %d)",
3691 data->best_chan.freq_24, data->best_chan.freq_5,
3692 data->best_chan.freq_overall);
3693 wpa_s->best_24_freq = data->best_chan.freq_24;
3694 wpa_s->best_5_freq = data->best_chan.freq_5;
3695 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003696 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3697 data->best_chan.freq_5,
3698 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003699 break;
3700 case EVENT_UNPROT_DEAUTH:
3701 wpa_supplicant_event_unprot_deauth(wpa_s,
3702 &data->unprot_deauth);
3703 break;
3704 case EVENT_UNPROT_DISASSOC:
3705 wpa_supplicant_event_unprot_disassoc(wpa_s,
3706 &data->unprot_disassoc);
3707 break;
3708 case EVENT_STATION_LOW_ACK:
3709#ifdef CONFIG_AP
3710 if (wpa_s->ap_iface && data)
3711 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3712 data->low_ack.addr);
3713#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003714#ifdef CONFIG_TDLS
3715 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07003716 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3717 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003718#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003719 break;
3720 case EVENT_IBSS_PEER_LOST:
3721#ifdef CONFIG_IBSS_RSN
3722 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3723#endif /* CONFIG_IBSS_RSN */
3724 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003725 case EVENT_DRIVER_GTK_REKEY:
3726 if (os_memcmp(data->driver_gtk_rekey.bssid,
3727 wpa_s->bssid, ETH_ALEN))
3728 break;
3729 if (!wpa_s->wpa)
3730 break;
3731 wpa_sm_update_replay_ctr(wpa_s->wpa,
3732 data->driver_gtk_rekey.replay_ctr);
3733 break;
3734 case EVENT_SCHED_SCAN_STOPPED:
Dmitry Shmidt18463232014-01-24 12:29:41 -08003735 wpa_s->pno = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003736 wpa_s->sched_scanning = 0;
3737 wpa_supplicant_notify_scanning(wpa_s, 0);
3738
3739 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3740 break;
3741
3742 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08003743 * Start a new sched scan to continue searching for more SSIDs
3744 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003745 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07003746 if (wpa_s->sched_scan_timed_out) {
3747 wpa_supplicant_req_sched_scan(wpa_s);
3748 } else if (wpa_s->pno_sched_pending) {
3749 wpa_s->pno_sched_pending = 0;
3750 wpas_start_pno(wpa_s);
Dmitry Shmidt18463232014-01-24 12:29:41 -08003751 }
3752
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003753 break;
3754 case EVENT_WPS_BUTTON_PUSHED:
3755#ifdef CONFIG_WPS
3756 wpas_wps_start_pbc(wpa_s, NULL, 0);
3757#endif /* CONFIG_WPS */
3758 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003759 case EVENT_AVOID_FREQUENCIES:
3760 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3761 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003762 case EVENT_CONNECT_FAILED_REASON:
3763#ifdef CONFIG_AP
3764 if (!wpa_s->ap_iface || !data)
3765 break;
3766 hostapd_event_connect_failed_reason(
3767 wpa_s->ap_iface->bss[0],
3768 data->connect_failed_reason.addr,
3769 data->connect_failed_reason.code);
3770#endif /* CONFIG_AP */
3771 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003772 case EVENT_NEW_PEER_CANDIDATE:
3773#ifdef CONFIG_MESH
3774 if (!wpa_s->ifmsh || !data)
3775 break;
3776 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3777 data->mesh_peer.ies,
3778 data->mesh_peer.ie_len);
3779#endif /* CONFIG_MESH */
3780 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003781 default:
3782 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3783 break;
3784 }
3785}