blob: a84ba2dccc24ae46e79d6047c6699a5086fe9cbd [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 Shmidtd80a4012015-11-05 16:35:40 -080026#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070027#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#include "notify.h"
29#include "common/ieee802_11_defs.h"
30#include "common/ieee802_11_common.h"
31#include "crypto/random.h"
32#include "blacklist.h"
33#include "wpas_glue.h"
34#include "wps_supplicant.h"
35#include "ibss_rsn.h"
36#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080037#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070038#include "p2p_supplicant.h"
39#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070040#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041#include "ap.h"
42#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080044#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070045#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080046#include "mesh.h"
47#include "mesh_mpm.h"
48#include "wmm_ac.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070049
50
Dmitry Shmidt34af3062013-07-11 10:46:32 -070051#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070052static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080053 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070054#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080055
56
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070057static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
58 struct wpa_ssid *ssid)
59{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080060 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070061
62 if (ssid == NULL || ssid->disabled_until.sec == 0)
63 return 0;
64
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080065 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070066 if (ssid->disabled_until.sec > now.sec)
67 return ssid->disabled_until.sec - now.sec;
68
69 wpas_clear_temp_disabled(wpa_s, ssid, 0);
70
71 return 0;
72}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070073
74
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080075#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtdda10c22015-03-24 16:05:01 -070076/**
77 * wpas_reenabled_network_time - Time until first network is re-enabled
78 * @wpa_s: Pointer to wpa_supplicant data
79 * Returns: If all enabled networks are temporarily disabled, returns the time
80 * (in sec) until the first network is re-enabled. Otherwise returns 0.
81 *
82 * This function is used in case all enabled networks are temporarily disabled,
83 * in which case it returns the time (in sec) that the first network will be
84 * re-enabled. The function assumes that at least one network is enabled.
85 */
86static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
87{
88 struct wpa_ssid *ssid;
89 int disabled_for, res = 0;
90
91#ifdef CONFIG_INTERWORKING
92 if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
93 wpa_s->conf->cred)
94 return 0;
95#endif /* CONFIG_INTERWORKING */
96
97 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
98 if (ssid->disabled)
99 continue;
100
101 disabled_for = wpas_temp_disabled(wpa_s, ssid);
102 if (!disabled_for)
103 return 0;
104
105 if (!res || disabled_for < res)
106 res = disabled_for;
107 }
108
109 return res;
110}
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800111#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700112
113
114void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
115{
116 struct wpa_supplicant *wpa_s = eloop_ctx;
117
118 if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
119 return;
120
121 wpa_dbg(wpa_s, MSG_DEBUG,
122 "Try to associate due to network getting re-enabled");
123 if (wpa_supplicant_fast_associate(wpa_s) != 1) {
124 wpa_supplicant_cancel_sched_scan(wpa_s);
125 wpa_supplicant_req_scan(wpa_s, 0, 0);
126 }
127}
128
129
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800130static struct wpa_bss * wpa_supplicant_get_new_bss(
131 struct wpa_supplicant *wpa_s, const u8 *bssid)
132{
133 struct wpa_bss *bss = NULL;
134 struct wpa_ssid *ssid = wpa_s->current_ssid;
135
136 if (ssid->ssid_len > 0)
137 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
138 if (!bss)
139 bss = wpa_bss_get_bssid(wpa_s, bssid);
140
141 return bss;
142}
143
144
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700145static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
146{
147 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
148
149 if (!bss) {
150 wpa_supplicant_update_scan_results(wpa_s);
151
152 /* Get the BSS from the new scan results */
153 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
154 }
155
156 if (bss)
157 wpa_s->current_bss = bss;
158}
159
160
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700161static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
162{
163 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700164 u8 drv_ssid[SSID_MAX_LEN];
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700165 size_t drv_ssid_len;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700166 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700167
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700168 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
169 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700170
171 if (wpa_s->current_ssid->ssid_len == 0)
172 return 0; /* current profile still in use */
173 res = wpa_drv_get_ssid(wpa_s, drv_ssid);
174 if (res < 0) {
175 wpa_msg(wpa_s, MSG_INFO,
176 "Failed to read SSID from driver");
177 return 0; /* try to use current profile */
178 }
179 drv_ssid_len = res;
180
181 if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
182 os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
183 drv_ssid_len) == 0)
184 return 0; /* current profile still in use */
185
186 wpa_msg(wpa_s, MSG_DEBUG,
187 "Driver-initiated BSS selection changed the SSID to %s",
188 wpa_ssid_txt(drv_ssid, drv_ssid_len));
189 /* continue selecting a new network profile */
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700190 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700191
192 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
193 "information");
194 ssid = wpa_supplicant_get_ssid(wpa_s);
195 if (ssid == NULL) {
196 wpa_msg(wpa_s, MSG_INFO,
197 "No network configuration found for the current AP");
198 return -1;
199 }
200
Dmitry Shmidt04949592012-07-19 12:16:46 -0700201 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700202 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
203 return -1;
204 }
205
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800206 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
207 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
208 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
209 return -1;
210 }
211
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700212 res = wpas_temp_disabled(wpa_s, ssid);
213 if (res > 0) {
214 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
215 "disabled for %d second(s)", res);
216 return -1;
217 }
218
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
220 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800221 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222 u8 wpa_ie[80];
223 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800224 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
225 wpa_ie, &wpa_ie_len) < 0)
226 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700227 } else {
228 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
229 }
230
231 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
232 eapol_sm_invalidate_cached_session(wpa_s->eapol);
233 old_ssid = wpa_s->current_ssid;
234 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800235
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700236 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800237
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700238 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
239 wpa_supplicant_initiate_eapol(wpa_s);
240 if (old_ssid != wpa_s->current_ssid)
241 wpas_notify_network_changed(wpa_s);
242
243 return 0;
244}
245
246
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800247void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700248{
249 struct wpa_supplicant *wpa_s = eloop_ctx;
250
251 if (wpa_s->countermeasures) {
252 wpa_s->countermeasures = 0;
253 wpa_drv_set_countermeasures(wpa_s, 0);
254 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800255
256 /*
257 * It is possible that the device is sched scanning, which means
258 * that a connection attempt will be done only when we receive
259 * scan results. However, in this case, it would be preferable
260 * to scan and connect immediately, so cancel the sched_scan and
261 * issue a regular scan flow.
262 */
263 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700264 wpa_supplicant_req_scan(wpa_s, 0, 0);
265 }
266}
267
268
269void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
270{
271 int bssid_changed;
272
Dmitry Shmidt04949592012-07-19 12:16:46 -0700273 wnm_bss_keep_alive_deinit(wpa_s);
274
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700275#ifdef CONFIG_IBSS_RSN
276 ibss_rsn_deinit(wpa_s->ibss_rsn);
277 wpa_s->ibss_rsn = NULL;
278#endif /* CONFIG_IBSS_RSN */
279
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700280#ifdef CONFIG_AP
281 wpa_supplicant_ap_deinit(wpa_s);
282#endif /* CONFIG_AP */
283
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700284 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
285 return;
286
287 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
288 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
289 os_memset(wpa_s->bssid, 0, ETH_ALEN);
290 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800291 sme_clear_on_disassoc(wpa_s);
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 Shmidtb70d0bb2015-11-16 10:43:06 -0800308 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700309}
310
311
312static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
313{
314 struct wpa_ie_data ie;
315 int pmksa_set = -1;
316 size_t i;
317
318 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
319 ie.pmkid == NULL)
320 return;
321
322 for (i = 0; i < ie.num_pmkid; i++) {
323 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
324 ie.pmkid + i * PMKID_LEN,
325 NULL, NULL, 0);
326 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800327 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700328 break;
329 }
330 }
331
332 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
333 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
334}
335
336
337static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
338 union wpa_event_data *data)
339{
340 if (data == NULL) {
341 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
342 "event");
343 return;
344 }
345 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
346 " index=%d preauth=%d",
347 MAC2STR(data->pmkid_candidate.bssid),
348 data->pmkid_candidate.index,
349 data->pmkid_candidate.preauth);
350
351 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
352 data->pmkid_candidate.index,
353 data->pmkid_candidate.preauth);
354}
355
356
357static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
358{
359 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
360 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
361 return 0;
362
363#ifdef IEEE8021X_EAPOL
364 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
365 wpa_s->current_ssid &&
366 !(wpa_s->current_ssid->eapol_flags &
367 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
368 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
369 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
370 * plaintext or static WEP keys). */
371 return 0;
372 }
373#endif /* IEEE8021X_EAPOL */
374
375 return 1;
376}
377
378
379/**
380 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
381 * @wpa_s: pointer to wpa_supplicant data
382 * @ssid: Configuration data for the network
383 * Returns: 0 on success, -1 on failure
384 *
385 * This function is called when starting authentication with a network that is
386 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
387 */
388int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
389 struct wpa_ssid *ssid)
390{
391#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800392#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700393 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700394
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700395 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
396 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700397 return 0;
398
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700399 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700400 sim = 1;
401 aka = 1;
402 } else {
403 struct eap_method_type *eap = ssid->eap.eap_methods;
404 while (eap->vendor != EAP_VENDOR_IETF ||
405 eap->method != EAP_TYPE_NONE) {
406 if (eap->vendor == EAP_VENDOR_IETF) {
407 if (eap->method == EAP_TYPE_SIM)
408 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700409 else if (eap->method == EAP_TYPE_AKA ||
410 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411 aka = 1;
412 }
413 eap++;
414 }
415 }
416
417 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
418 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700419 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
420 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
421 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700422 aka = 0;
423
424 if (!sim && !aka) {
425 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
426 "use SIM, but neither EAP-SIM nor EAP-AKA are "
427 "enabled");
428 return 0;
429 }
430
431 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
432 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700433
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700434 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700435 if (wpa_s->scard == NULL) {
436 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
437 "(pcsc-lite)");
438 return -1;
439 }
440 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
441 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800442#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700443#endif /* IEEE8021X_EAPOL */
444
445 return 0;
446}
447
448
449#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700450
451static int has_wep_key(struct wpa_ssid *ssid)
452{
453 int i;
454
455 for (i = 0; i < NUM_WEP_KEYS; i++) {
456 if (ssid->wep_key_len[i])
457 return 1;
458 }
459
460 return 0;
461}
462
463
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700464static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700465 struct wpa_ssid *ssid)
466{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700467 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700468
469 if (ssid->mixed_cell)
470 return 1;
471
472#ifdef CONFIG_WPS
473 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
474 return 1;
475#endif /* CONFIG_WPS */
476
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700477 if (has_wep_key(ssid))
478 privacy = 1;
479
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700480#ifdef IEEE8021X_EAPOL
481 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
482 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
483 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
484 privacy = 1;
485#endif /* IEEE8021X_EAPOL */
486
Jouni Malinen75ecf522011-06-27 15:19:46 -0700487 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
488 privacy = 1;
489
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800490 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
491 privacy = 1;
492
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700493 if (bss->caps & IEEE80211_CAP_PRIVACY)
494 return privacy;
495 return !privacy;
496}
497
498
499static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
500 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700501 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700502{
503 struct wpa_ie_data ie;
504 int proto_match = 0;
505 const u8 *rsn_ie, *wpa_ie;
506 int ret;
507 int wep_ok;
508
509 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
510 if (ret >= 0)
511 return ret;
512
513 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
514 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
515 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
516 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
517 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
518
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700519 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
521 proto_match++;
522
523 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
524 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
525 "failed");
526 break;
527 }
528
529 if (wep_ok &&
530 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
531 {
532 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
533 "in RSN IE");
534 return 1;
535 }
536
537 if (!(ie.proto & ssid->proto)) {
538 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
539 "mismatch");
540 break;
541 }
542
543 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
544 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
545 "cipher mismatch");
546 break;
547 }
548
549 if (!(ie.group_cipher & ssid->group_cipher)) {
550 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
551 "cipher mismatch");
552 break;
553 }
554
555 if (!(ie.key_mgmt & ssid->key_mgmt)) {
556 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
557 "mismatch");
558 break;
559 }
560
561#ifdef CONFIG_IEEE80211W
562 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800563 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800564 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700565 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
566 "frame protection");
567 break;
568 }
569#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800570 if ((ie.capabilities & WPA_CAPABILITY_MFPR) &&
571 wpas_get_ssid_pmf(wpa_s, ssid) ==
572 NO_MGMT_FRAME_PROTECTION) {
573 wpa_dbg(wpa_s, MSG_DEBUG,
574 " skip RSN IE - no mgmt frame protection enabled but AP requires it");
575 break;
576 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800577#ifdef CONFIG_MBO
578 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
579 wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND) &&
580 wpas_get_ssid_pmf(wpa_s, ssid) !=
581 NO_MGMT_FRAME_PROTECTION) {
582 wpa_dbg(wpa_s, MSG_DEBUG,
583 " skip RSN IE - no mgmt frame protection enabled on MBO AP");
584 break;
585 }
586#endif /* CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700587
588 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
589 return 1;
590 }
591
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700592 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700593 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
594 proto_match++;
595
596 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
597 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
598 "failed");
599 break;
600 }
601
602 if (wep_ok &&
603 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
604 {
605 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
606 "in WPA IE");
607 return 1;
608 }
609
610 if (!(ie.proto & ssid->proto)) {
611 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
612 "mismatch");
613 break;
614 }
615
616 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
617 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
618 "cipher mismatch");
619 break;
620 }
621
622 if (!(ie.group_cipher & ssid->group_cipher)) {
623 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
624 "cipher mismatch");
625 break;
626 }
627
628 if (!(ie.key_mgmt & ssid->key_mgmt)) {
629 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
630 "mismatch");
631 break;
632 }
633
634 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
635 return 1;
636 }
637
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700638 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
639 !rsn_ie) {
640 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
641 return 1;
642 }
643
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700644 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
645 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
646 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
647 return 0;
648 }
649
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800650 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
651 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
652 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
653 return 1;
654 }
655
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
657 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
658 return 1;
659 }
660
661 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
662 "WPA/WPA2");
663
664 return 0;
665}
666
667
668static int freq_allowed(int *freqs, int freq)
669{
670 int i;
671
672 if (freqs == NULL)
673 return 1;
674
675 for (i = 0; freqs[i]; i++)
676 if (freqs[i] == freq)
677 return 1;
678 return 0;
679}
680
681
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700682static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800683{
684 const struct hostapd_hw_modes *mode = NULL, *modes;
685 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
686 const u8 *rate_ie;
687 int i, j, k;
688
689 if (bss->freq == 0)
690 return 1; /* Cannot do matching without knowing band */
691
692 modes = wpa_s->hw.modes;
693 if (modes == NULL) {
694 /*
695 * The driver does not provide any additional information
696 * about the utilized hardware, so allow the connection attempt
697 * to continue.
698 */
699 return 1;
700 }
701
702 for (i = 0; i < wpa_s->hw.num_modes; i++) {
703 for (j = 0; j < modes[i].num_channels; j++) {
704 int freq = modes[i].channels[j].freq;
705 if (freq == bss->freq) {
706 if (mode &&
707 mode->mode == HOSTAPD_MODE_IEEE80211G)
708 break; /* do not allow 802.11b replace
709 * 802.11g */
710 mode = &modes[i];
711 break;
712 }
713 }
714 }
715
716 if (mode == NULL)
717 return 0;
718
719 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700720 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800721 if (rate_ie == NULL)
722 continue;
723
724 for (j = 2; j < rate_ie[1] + 2; j++) {
725 int flagged = !!(rate_ie[j] & 0x80);
726 int r = (rate_ie[j] & 0x7f) * 5;
727
728 /*
729 * IEEE Std 802.11n-2009 7.3.2.2:
730 * The new BSS Membership selector value is encoded
731 * like a legacy basic rate, but it is not a rate and
732 * only indicates if the BSS members are required to
733 * support the mandatory features of Clause 20 [HT PHY]
734 * in order to join the BSS.
735 */
736 if (flagged && ((rate_ie[j] & 0x7f) ==
737 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
738 if (!ht_supported(mode)) {
739 wpa_dbg(wpa_s, MSG_DEBUG,
740 " hardware does not support "
741 "HT PHY");
742 return 0;
743 }
744 continue;
745 }
746
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700747 /* There's also a VHT selector for 802.11ac */
748 if (flagged && ((rate_ie[j] & 0x7f) ==
749 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
750 if (!vht_supported(mode)) {
751 wpa_dbg(wpa_s, MSG_DEBUG,
752 " hardware does not support "
753 "VHT PHY");
754 return 0;
755 }
756 continue;
757 }
758
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800759 if (!flagged)
760 continue;
761
762 /* check for legacy basic rates */
763 for (k = 0; k < mode->num_rates; k++) {
764 if (mode->rates[k] == r)
765 break;
766 }
767 if (k == mode->num_rates) {
768 /*
769 * IEEE Std 802.11-2007 7.3.2.2 demands that in
770 * order to join a BSS all required rates
771 * have to be supported by the hardware.
772 */
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -0700773 wpa_dbg(wpa_s, MSG_DEBUG,
774 " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
775 r / 10, r % 10,
776 bss->freq, mode->mode, mode->num_rates);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800777 return 0;
778 }
779 }
780 }
781
782 return 1;
783}
784
785
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800786/*
787 * Test whether BSS is in an ESS.
788 * This is done differently in DMG (60 GHz) and non-DMG bands
789 */
790static int bss_is_ess(struct wpa_bss *bss)
791{
792 if (bss_is_dmg(bss)) {
793 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
794 IEEE80211_CAP_DMG_AP;
795 }
796
797 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
798 IEEE80211_CAP_ESS);
799}
800
801
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800802static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
803{
804 size_t i;
805
806 for (i = 0; i < ETH_ALEN; i++) {
807 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
808 return 0;
809 }
810 return 1;
811}
812
813
814static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
815{
816 size_t i;
817
818 for (i = 0; i < num; i++) {
819 const u8 *a = list + i * ETH_ALEN * 2;
820 const u8 *m = a + ETH_ALEN;
821
822 if (match_mac_mask(a, addr, m))
823 return 1;
824 }
825 return 0;
826}
827
828
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800829struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
830 int i, struct wpa_bss *bss,
831 struct wpa_ssid *group,
832 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700833{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700834 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700835 int wpa;
836 struct wpa_blacklist *e;
837 const u8 *ie;
838 struct wpa_ssid *ssid;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800839 int osen;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800840#ifdef CONFIG_MBO
841 const u8 *assoc_disallow;
842#endif /* CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700843
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700844 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 wpa_ie_len = ie ? ie[1] : 0;
846
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700847 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700848 rsn_ie_len = ie ? ie[1] : 0;
849
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800850 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
851 osen = ie != NULL;
852
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700853 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800854 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700855 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800856 wpa_ie_len, rsn_ie_len, bss->caps, bss->level, bss->freq,
Dmitry Shmidt96571392013-10-14 12:54:46 -0700857 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
858 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
859 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800860 " p2p" : "",
861 osen ? " osen=1" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862
863 e = wpa_blacklist_get(wpa_s, bss->bssid);
864 if (e) {
865 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700866 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700867 /*
868 * When only a single network is enabled, we can
869 * trigger blacklisting on the first failure. This
870 * should not be done with multiple enabled networks to
871 * avoid getting forced to move into a worse ESS on
872 * single error if there are no other BSSes of the
873 * current ESS.
874 */
875 limit = 0;
876 }
877 if (e->count > limit) {
878 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
879 "(count=%d limit=%d)", e->count, limit);
880 return NULL;
881 }
882 }
883
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700884 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700885 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
886 return NULL;
887 }
888
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800889 if (disallowed_bssid(wpa_s, bss->bssid)) {
890 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
891 return NULL;
892 }
893
894 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
895 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
896 return NULL;
897 }
898
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700899 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
900
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800901 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700902 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700903 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700904
Dmitry Shmidt04949592012-07-19 12:16:46 -0700905 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700906 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
907 continue;
908 }
909
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700910 res = wpas_temp_disabled(wpa_s, ssid);
911 if (res > 0) {
912 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
913 "temporarily for %d second(s)", res);
914 continue;
915 }
916
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700917#ifdef CONFIG_WPS
918 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
919 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
920 "(WPS)");
921 continue;
922 }
923
924 if (wpa && ssid->ssid_len == 0 &&
925 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
926 check_ssid = 0;
927
928 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
929 /* Only allow wildcard SSID match if an AP
930 * advertises active WPS operation that matches
931 * with our mode. */
932 check_ssid = 1;
933 if (ssid->ssid_len == 0 &&
934 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
935 check_ssid = 0;
936 }
937#endif /* CONFIG_WPS */
938
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800939 if (ssid->bssid_set && ssid->ssid_len == 0 &&
940 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
941 check_ssid = 0;
942
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700943 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700944 (bss->ssid_len != ssid->ssid_len ||
945 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700946 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
947 continue;
948 }
949
950 if (ssid->bssid_set &&
951 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
952 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
953 continue;
954 }
955
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800956 /* check blacklist */
957 if (ssid->num_bssid_blacklist &&
958 addr_in_list(bss->bssid, ssid->bssid_blacklist,
959 ssid->num_bssid_blacklist)) {
960 wpa_dbg(wpa_s, MSG_DEBUG,
961 " skip - BSSID blacklisted");
962 continue;
963 }
964
965 /* if there is a whitelist, only accept those APs */
966 if (ssid->num_bssid_whitelist &&
967 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
968 ssid->num_bssid_whitelist)) {
969 wpa_dbg(wpa_s, MSG_DEBUG,
970 " skip - BSSID not in whitelist");
971 continue;
972 }
973
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700974 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
975 continue;
976
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800977 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700978 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
979 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
980 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
981 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
982 "not allowed");
983 continue;
984 }
985
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700986 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
987 has_wep_key(ssid)) {
988 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
989 continue;
990 }
991
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800992 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
993 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
994 "not allowed");
995 continue;
996 }
997
Jouni Malinen75ecf522011-06-27 15:19:46 -0700998 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700999 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
1000 "mismatch");
1001 continue;
1002 }
1003
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001004 if (!bss_is_ess(bss) && !bss_is_pbss(bss)) {
1005 wpa_dbg(wpa_s, MSG_DEBUG, " skip - neither ESS nor PBSS network");
1006 continue;
1007 }
1008
1009 if (ssid->pbss != bss_is_pbss(bss)) {
1010 wpa_dbg(wpa_s, MSG_DEBUG, " skip - PBSS mismatch (ssid %d bss %d)",
1011 ssid->pbss, bss_is_pbss(bss));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001012 continue;
1013 }
1014
1015 if (!freq_allowed(ssid->freq_list, bss->freq)) {
1016 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
1017 "allowed");
1018 continue;
1019 }
1020
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001021 if (!rate_match(wpa_s, bss)) {
1022 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
1023 "not match");
1024 continue;
1025 }
1026
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001027#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -07001028 if (ssid->p2p_group &&
1029 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
1030 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
1031 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
1032 continue;
1033 }
1034
Dmitry Shmidt54605472013-11-08 11:10:19 -08001035 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
1036 struct wpabuf *p2p_ie;
1037 u8 dev_addr[ETH_ALEN];
1038
1039 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1040 if (ie == NULL) {
1041 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
1042 continue;
1043 }
1044 p2p_ie = wpa_bss_get_vendor_ie_multi(
1045 bss, P2P_IE_VENDOR_TYPE);
1046 if (p2p_ie == NULL) {
1047 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
1048 continue;
1049 }
1050
1051 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
1052 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
1053 ETH_ALEN) != 0) {
1054 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
1055 wpabuf_free(p2p_ie);
1056 continue;
1057 }
1058 wpabuf_free(p2p_ie);
1059 }
1060
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001061 /*
1062 * TODO: skip the AP if its P2P IE has Group Formation
1063 * bit set in the P2P Group Capability Bitmap and we
1064 * are not in Group Formation with that device.
1065 */
1066#endif /* CONFIG_P2P */
1067
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001068 if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
1069 {
1070 struct os_reltime diff;
1071
1072 os_reltime_sub(&wpa_s->scan_min_time,
1073 &bss->last_update, &diff);
1074 wpa_dbg(wpa_s, MSG_DEBUG,
1075 " skip - scan result not recent enough (%u.%06u seconds too old)",
1076 (unsigned int) diff.sec,
1077 (unsigned int) diff.usec);
1078 continue;
1079 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001080#ifdef CONFIG_MBO
1081 assoc_disallow = wpas_mbo_get_bss_attr(
1082 bss, MBO_ATTR_ID_ASSOC_DISALLOW);
1083 if (assoc_disallow && assoc_disallow[1] >= 1) {
1084 wpa_dbg(wpa_s, MSG_DEBUG,
1085 " skip - MBO association disallowed (reason %u)",
1086 assoc_disallow[2]);
1087 continue;
1088 }
1089
1090 if (wpa_is_bss_tmp_disallowed(wpa_s, bss->bssid)) {
1091 wpa_dbg(wpa_s, MSG_DEBUG,
1092 " skip - MBO retry delay has not passed yet");
1093 continue;
1094 }
1095#endif /* CONFIG_MBO */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001096
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001097 /* Matching configuration found */
1098 return ssid;
1099 }
1100
1101 /* No matching configuration found */
1102 return NULL;
1103}
1104
1105
1106static struct wpa_bss *
1107wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001108 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001109 struct wpa_ssid **selected_ssid,
1110 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001112 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001114 if (only_first_ssid)
1115 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
1116 group->id);
1117 else
1118 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
1119 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001120
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001121 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
1122 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001123 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
1124 only_first_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001125 if (!*selected_ssid)
1126 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001127 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
1128 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001129 MAC2STR(bss->bssid),
1130 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1131 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001132 }
1133
1134 return NULL;
1135}
1136
1137
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001138struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1139 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001140{
1141 struct wpa_bss *selected = NULL;
1142 int prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001143 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001144 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001145
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001146 if (wpa_s->last_scan_res == NULL ||
1147 wpa_s->last_scan_res_used == 0)
1148 return NULL; /* no scan results from last update */
1149
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001150 if (wpa_s->next_ssid) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001151 /* check that next_ssid is still valid */
1152 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1153 if (ssid == wpa_s->next_ssid)
1154 break;
1155 }
1156 next_ssid = ssid;
1157 wpa_s->next_ssid = NULL;
1158 }
1159
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001160 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001161 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1162 if (next_ssid && next_ssid->priority ==
1163 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001164 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001165 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001166 if (selected)
1167 break;
1168 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001169 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001170 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001171 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001172 if (selected)
1173 break;
1174 }
1175
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001176 if (selected == NULL && wpa_s->blacklist &&
1177 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001178 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1179 "blacklist and try again");
1180 wpa_blacklist_clear(wpa_s);
1181 wpa_s->blacklist_cleared++;
1182 } else if (selected == NULL)
1183 break;
1184 }
1185
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001186 ssid = *selected_ssid;
1187 if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
1188 !ssid->passphrase && !ssid->ext_psk) {
1189 const char *field_name, *txt = NULL;
1190
1191 wpa_dbg(wpa_s, MSG_DEBUG,
1192 "PSK/passphrase not yet available for the selected network");
1193
1194 wpas_notify_network_request(wpa_s, ssid,
1195 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
1196
1197 field_name = wpa_supplicant_ctrl_req_to_string(
1198 WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
1199 if (field_name == NULL)
1200 return NULL;
1201
1202 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
1203
1204 selected = NULL;
1205 }
1206
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001207 return selected;
1208}
1209
1210
1211static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1212 int timeout_sec, int timeout_usec)
1213{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001214 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001215 /*
1216 * No networks are enabled; short-circuit request so
1217 * we don't wait timeout seconds before transitioning
1218 * to INACTIVE state.
1219 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001220 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1221 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001222 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1223 return;
1224 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001225
1226 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001227 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1228}
1229
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001230
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001231int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001232 struct wpa_bss *selected,
1233 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001234{
1235 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1236 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1237 "PBC session overlap");
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07001238 wpas_notify_wps_event_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001239#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001240 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1241 wpa_s->p2p_in_provisioning) {
1242 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1243 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001244 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001245 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246#endif /* CONFIG_P2P */
1247
1248#ifdef CONFIG_WPS
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001249 wpas_wps_pbc_overlap(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001250 wpas_wps_cancel(wpa_s);
1251#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001252 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001253 }
1254
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001255 wpa_msg(wpa_s, MSG_DEBUG,
1256 "Considering connect request: reassociate: %d selected: "
1257 MACSTR " bssid: " MACSTR " pending: " MACSTR
1258 " wpa_state: %s ssid=%p current_ssid=%p",
1259 wpa_s->reassociate, MAC2STR(selected->bssid),
1260 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1261 wpa_supplicant_state_txt(wpa_s->wpa_state),
1262 ssid, wpa_s->current_ssid);
1263
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001264 /*
1265 * Do not trigger new association unless the BSSID has changed or if
1266 * reassociation is requested. If we are in process of associating with
1267 * the selected BSSID, do not trigger new attempt.
1268 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001269 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001270 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1271 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1272 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001273 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1274 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1275 0) ||
1276 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1277 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001278 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1279 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001280 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001281 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001282 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1283 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001284 wpa_supplicant_associate(wpa_s, selected, ssid);
1285 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001286 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1287 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001288 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001289
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001290 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001291}
1292
1293
1294static struct wpa_ssid *
1295wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1296{
1297 int prio;
1298 struct wpa_ssid *ssid;
1299
1300 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1301 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1302 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001303 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001304 continue;
1305 if (ssid->mode == IEEE80211_MODE_IBSS ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001306 ssid->mode == IEEE80211_MODE_AP ||
1307 ssid->mode == IEEE80211_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308 return ssid;
1309 }
1310 }
1311 return NULL;
1312}
1313
1314
1315/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1316 * on BSS added and BSS changed events */
1317static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001318 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001319{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001320 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001321
1322 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1323 return;
1324
Jouni Malinen87fd2792011-05-16 18:35:42 +03001325 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001326 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001327
Jouni Malinen87fd2792011-05-16 18:35:42 +03001328 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001329 if (ssid == NULL)
1330 continue;
1331
Jouni Malinen87fd2792011-05-16 18:35:42 +03001332 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001333 if (rsn == NULL)
1334 continue;
1335
Jouni Malinen87fd2792011-05-16 18:35:42 +03001336 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001337 }
1338
1339}
1340
1341
1342static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1343 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001344 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001345{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001346 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001347#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001348 int min_diff;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07001349#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001350
1351 if (wpa_s->reassociate)
1352 return 1; /* explicit request to reassociate */
1353 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1354 return 1; /* we are not associated; continue */
1355 if (wpa_s->current_ssid == NULL)
1356 return 1; /* unknown current SSID */
1357 if (wpa_s->current_ssid != ssid)
1358 return 1; /* different network block */
1359
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001360 if (wpas_driver_bss_selection(wpa_s))
1361 return 0; /* Driver-based roaming */
1362
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001363 if (wpa_s->current_ssid->ssid)
1364 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1365 wpa_s->current_ssid->ssid,
1366 wpa_s->current_ssid->ssid_len);
1367 if (!current_bss)
1368 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001369
1370 if (!current_bss)
1371 return 1; /* current BSS not seen in scan results */
1372
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001373 if (current_bss == selected)
1374 return 0;
1375
1376 if (selected->last_update_idx > current_bss->last_update_idx)
1377 return 1; /* current BSS not seen in the last scan */
1378
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001379#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001380 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001381 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1382 " level=%d snr=%d est_throughput=%u",
1383 MAC2STR(current_bss->bssid), current_bss->level,
1384 current_bss->snr, current_bss->est_throughput);
1385 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1386 " level=%d snr=%d est_throughput=%u",
1387 MAC2STR(selected->bssid), selected->level,
1388 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001389
1390 if (wpa_s->current_ssid->bssid_set &&
1391 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1392 0) {
1393 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1394 "has preferred BSSID");
1395 return 1;
1396 }
1397
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001398 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1399 wpa_dbg(wpa_s, MSG_DEBUG,
1400 "Allow reassociation - selected BSS has better estimated throughput");
1401 return 1;
1402 }
1403
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001404 if (current_bss->level < 0 && current_bss->level > selected->level) {
1405 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1406 "signal level");
1407 return 0;
1408 }
1409
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001410 min_diff = 2;
1411 if (current_bss->level < 0) {
1412 if (current_bss->level < -85)
1413 min_diff = 1;
1414 else if (current_bss->level < -80)
1415 min_diff = 2;
1416 else if (current_bss->level < -75)
1417 min_diff = 3;
1418 else if (current_bss->level < -70)
1419 min_diff = 4;
1420 else
1421 min_diff = 5;
1422 }
1423 if (abs(current_bss->level - selected->level) < min_diff) {
1424 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1425 "in signal level");
1426 return 0;
1427 }
1428
1429 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001430#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001431 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001432#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001433}
1434
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001435
Jouni Malinen89ca7022012-09-14 13:03:12 -07001436/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001437 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001438static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001439 union wpa_event_data *data,
1440 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001441{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001442 struct wpa_scan_results *scan_res = NULL;
1443 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001444 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001445#ifndef CONFIG_NO_RANDOM_POOL
1446 size_t i, num;
1447#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001448
1449#ifdef CONFIG_AP
1450 if (wpa_s->ap_iface)
1451 ap = 1;
1452#endif /* CONFIG_AP */
1453
1454 wpa_supplicant_notify_scanning(wpa_s, 0);
1455
1456 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1457 data ? &data->scan_info :
1458 NULL, 1);
1459 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001460 if (wpa_s->conf->ap_scan == 2 || ap ||
1461 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001462 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001463 if (!own_request)
1464 return -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001465 if (data && data->scan_info.external_scan)
1466 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001467 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1468 "scanning again");
1469 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001470 ret = -1;
1471 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001472 }
1473
1474#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001475 num = scan_res->num;
1476 if (num > 10)
1477 num = 10;
1478 for (i = 0; i < num; i++) {
1479 u8 buf[5];
1480 struct wpa_scan_res *res = scan_res->res[i];
1481 buf[0] = res->bssid[5];
1482 buf[1] = res->qual & 0xff;
1483 buf[2] = res->noise & 0xff;
1484 buf[3] = res->level & 0xff;
1485 buf[4] = res->tsf & 0xff;
1486 random_add_randomness(buf, sizeof(buf));
1487 }
1488#endif /* CONFIG_NO_RANDOM_POOL */
1489
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001490 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001491 !(data && data->scan_info.external_scan)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001492 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1493 struct wpa_scan_results *scan_res);
1494
1495 scan_res_handler = wpa_s->scan_res_handler;
1496 wpa_s->scan_res_handler = NULL;
1497 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001498 ret = -2;
1499 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001500 }
1501
1502 if (ap) {
1503 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1504#ifdef CONFIG_AP
1505 if (wpa_s->ap_iface->scan_cb)
1506 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1507#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001508 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001509 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001510
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001511 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001512 wpa_s->own_scan_running,
1513 data ? data->scan_info.external_scan : 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001514 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001515 wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
1516 own_request && !(data && data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001517 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1518 wpa_s->manual_scan_id);
1519 wpa_s->manual_scan_use_id = 0;
1520 } else {
1521 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1522 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001523 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001524
1525 wpas_notify_scan_done(wpa_s, 1);
1526
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001527 if (data && data->scan_info.external_scan) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001528 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 -07001529 wpa_scan_results_free(scan_res);
1530 return 0;
1531 }
1532
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001533 if (wnm_scan_process(wpa_s, 1) > 0)
1534 goto scan_work_done;
1535
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001536 if (sme_proc_obss_scan(wpa_s) > 0)
1537 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001538
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001539 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1540 goto scan_work_done;
1541
1542 if (autoscan_notify_scan(wpa_s, scan_res))
1543 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001544
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001545 if (wpa_s->disconnected) {
1546 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001547 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001548 }
1549
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001550 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001551 bgscan_notify_scan(wpa_s, scan_res) == 1)
1552 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001553
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001554 wpas_wps_update_ap_info(wpa_s, scan_res);
1555
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001556 if (wpa_s->wpa_state >= WPA_AUTHENTICATING &&
1557 wpa_s->wpa_state < WPA_COMPLETED)
1558 goto scan_work_done;
1559
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001560 wpa_scan_results_free(scan_res);
1561
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001562 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001563 struct wpa_radio_work *work = wpa_s->scan_work;
1564 wpa_s->scan_work = NULL;
1565 radio_work_done(work);
1566 }
1567
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001568 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001569
1570scan_work_done:
1571 wpa_scan_results_free(scan_res);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001572 if (own_request && wpa_s->scan_work) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001573 struct wpa_radio_work *work = wpa_s->scan_work;
1574 wpa_s->scan_work = NULL;
1575 radio_work_done(work);
1576 }
1577 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001578}
1579
1580
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001581static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001582 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001583{
1584 struct wpa_bss *selected;
1585 struct wpa_ssid *ssid = NULL;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001586 int time_to_reenable = wpas_reenabled_network_time(wpa_s);
1587
1588 if (time_to_reenable > 0) {
1589 wpa_dbg(wpa_s, MSG_DEBUG,
1590 "Postpone network selection by %d seconds since all networks are disabled",
1591 time_to_reenable);
1592 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
1593 eloop_register_timeout(time_to_reenable, 0,
1594 wpas_network_reenabled, wpa_s, NULL);
1595 return 0;
1596 }
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001597
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001598 if (wpa_s->p2p_mgmt)
1599 return 0; /* no normal connection on p2p_mgmt interface */
1600
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001601 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001602
1603 if (selected) {
1604 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001605 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001606 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001607 if (new_scan)
1608 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001609 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001610 }
1611
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001612 if (ssid != wpa_s->current_ssid &&
1613 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1614 wpa_s->own_disconnect_req = 1;
1615 wpa_supplicant_deauthenticate(
1616 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1617 }
1618
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001619 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001620 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001621 return -1;
1622 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001623 if (new_scan)
1624 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001625 /*
1626 * Do not notify other virtual radios of scan results since we do not
1627 * want them to start other associations at the same time.
1628 */
1629 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001630 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001631#ifdef CONFIG_MESH
1632 if (wpa_s->ifmsh) {
1633 wpa_msg(wpa_s, MSG_INFO,
1634 "Avoiding join because we already joined a mesh group");
1635 return 0;
1636 }
1637#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001638 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1639 ssid = wpa_supplicant_pick_new_network(wpa_s);
1640 if (ssid) {
1641 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1642 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001643 if (new_scan)
1644 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001645 } else if (own_request) {
1646 /*
1647 * No SSID found. If SCAN results are as a result of
1648 * own scan request and not due to a scan request on
1649 * another shared interface, try another scan.
1650 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001651 int timeout_sec = wpa_s->scan_interval;
1652 int timeout_usec = 0;
1653#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001654 int res;
1655
1656 res = wpas_p2p_scan_no_go_seen(wpa_s);
1657 if (res == 2)
1658 return 2;
1659 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001660 return 0;
1661
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001662 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07001663 wpa_s->show_group_started ||
1664 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001665 /*
1666 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001667 * state and during P2P join-a-group operation
1668 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001669 */
1670 timeout_sec = 0;
1671 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001672 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1673 timeout_usec);
1674 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001675 }
1676#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001677#ifdef CONFIG_INTERWORKING
1678 if (wpa_s->conf->auto_interworking &&
1679 wpa_s->conf->interworking &&
1680 wpa_s->conf->cred) {
1681 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1682 "start ANQP fetch since no matching "
1683 "networks found");
1684 wpa_s->network_select = 1;
1685 wpa_s->auto_network_select = 1;
1686 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001687 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001688 }
1689#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001690#ifdef CONFIG_WPS
1691 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1692 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1693 timeout_sec = 0;
1694 timeout_usec = 500000;
1695 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1696 timeout_usec);
1697 return 0;
1698 }
1699#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001700 if (wpa_supplicant_req_sched_scan(wpa_s))
1701 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1702 timeout_usec);
Dmitry Shmidt41712582015-06-29 11:02:15 -07001703
1704 wpa_msg_ctrl(wpa_s, MSG_INFO,
1705 WPA_EVENT_NETWORK_NOT_FOUND);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001706 }
1707 }
1708 return 0;
1709}
1710
1711
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001712static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1713 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001714{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001715 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001716 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001717
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001718 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1719 if (res == 2) {
1720 /*
1721 * Interface may have been removed, so must not dereference
1722 * wpa_s after this.
1723 */
1724 return 1;
1725 }
1726 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001727 /*
1728 * If no scan results could be fetched, then no need to
1729 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001730 * this scan. Similarly, if scan results started a new operation on this
1731 * interface, do not notify other interfaces to avoid concurrent
1732 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001733 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001734 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001735 }
1736
1737 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001738 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001739 * so, they get updated with this same scan info.
1740 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001741 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1742 radio_list) {
1743 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001744 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1745 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001746 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001747 }
1748 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001749
1750 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001751}
1752
1753#endif /* CONFIG_NO_SCAN_PROCESSING */
1754
1755
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001756int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1757{
1758#ifdef CONFIG_NO_SCAN_PROCESSING
1759 return -1;
1760#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001761 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001762
Dmitry Shmidt41712582015-06-29 11:02:15 -07001763 if (wpa_s->last_scan_res_used == 0)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001764 return -1;
1765
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001766 os_get_reltime(&now);
1767 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001768 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1769 return -1;
1770 }
1771
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001772 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001773#endif /* CONFIG_NO_SCAN_PROCESSING */
1774}
1775
Dmitry Shmidt04949592012-07-19 12:16:46 -07001776#ifdef CONFIG_WNM
1777
1778static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1779{
1780 struct wpa_supplicant *wpa_s = eloop_ctx;
1781
1782 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1783 return;
1784
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001785 if (!wpa_s->no_keep_alive) {
1786 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1787 MAC2STR(wpa_s->bssid));
1788 /* TODO: could skip this if normal data traffic has been sent */
1789 /* TODO: Consider using some more appropriate data frame for
1790 * this */
1791 if (wpa_s->l2)
1792 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1793 (u8 *) "", 0);
1794 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001795
1796#ifdef CONFIG_SME
1797 if (wpa_s->sme.bss_max_idle_period) {
1798 unsigned int msec;
1799 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1800 if (msec > 100)
1801 msec -= 100;
1802 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1803 wnm_bss_keep_alive, wpa_s, NULL);
1804 }
1805#endif /* CONFIG_SME */
1806}
1807
1808
1809static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1810 const u8 *ies, size_t ies_len)
1811{
1812 struct ieee802_11_elems elems;
1813
1814 if (ies == NULL)
1815 return;
1816
1817 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1818 return;
1819
1820#ifdef CONFIG_SME
1821 if (elems.bss_max_idle_period) {
1822 unsigned int msec;
1823 wpa_s->sme.bss_max_idle_period =
1824 WPA_GET_LE16(elems.bss_max_idle_period);
1825 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1826 "TU)%s", wpa_s->sme.bss_max_idle_period,
1827 (elems.bss_max_idle_period[2] & 0x01) ?
1828 " (protected keep-live required)" : "");
1829 if (wpa_s->sme.bss_max_idle_period == 0)
1830 wpa_s->sme.bss_max_idle_period = 1;
1831 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1832 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1833 /* msec times 1000 */
1834 msec = wpa_s->sme.bss_max_idle_period * 1024;
1835 if (msec > 100)
1836 msec -= 100;
1837 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1838 wnm_bss_keep_alive, wpa_s,
1839 NULL);
1840 }
1841 }
1842#endif /* CONFIG_SME */
1843}
1844
1845#endif /* CONFIG_WNM */
1846
1847
1848void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1849{
1850#ifdef CONFIG_WNM
1851 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1852#endif /* CONFIG_WNM */
1853}
1854
1855
Dmitry Shmidt051af732013-10-22 13:52:46 -07001856#ifdef CONFIG_INTERWORKING
1857
1858static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1859 size_t len)
1860{
1861 int res;
1862
1863 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1864 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1865 if (res) {
1866 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1867 }
1868
1869 return res;
1870}
1871
1872
1873static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1874 const u8 *ies, size_t ies_len)
1875{
1876 struct ieee802_11_elems elems;
1877
1878 if (ies == NULL)
1879 return;
1880
1881 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1882 return;
1883
1884 if (elems.qos_map_set) {
1885 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1886 elems.qos_map_set_len);
1887 }
1888}
1889
1890#endif /* CONFIG_INTERWORKING */
1891
1892
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001893#ifdef CONFIG_FST
1894static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s,
1895 const u8 *ie, size_t ie_len)
1896{
1897 struct mb_ies_info mb_ies;
1898
1899 if (!ie || !ie_len || !wpa_s->fst)
1900 return -ENOENT;
1901
1902 os_memset(&mb_ies, 0, sizeof(mb_ies));
1903
1904 while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) {
1905 size_t len;
1906
1907 len = 2 + ie[1];
1908 if (len > ie_len) {
1909 wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found",
1910 ie, ie_len);
1911 break;
1912 }
1913
1914 if (ie[0] == WLAN_EID_MULTI_BAND) {
1915 wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
1916 (unsigned int) len);
1917 mb_ies.ies[mb_ies.nof_ies].ie = ie + 2;
1918 mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2;
1919 mb_ies.nof_ies++;
1920 }
1921
1922 ie_len -= len;
1923 ie += len;
1924 }
1925
1926 if (mb_ies.nof_ies > 0) {
1927 wpabuf_free(wpa_s->received_mb_ies);
1928 wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
1929 return 0;
1930 }
1931
1932 return -ENOENT;
1933}
1934#endif /* CONFIG_FST */
1935
1936
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001937static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1938 union wpa_event_data *data)
1939{
1940 int l, len, found = 0, wpa_found, rsn_found;
1941 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001942#ifdef CONFIG_IEEE80211R
1943 u8 bssid[ETH_ALEN];
1944#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001945
1946 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1947 if (data->assoc_info.req_ies)
1948 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1949 data->assoc_info.req_ies_len);
1950 if (data->assoc_info.resp_ies) {
1951 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1952 data->assoc_info.resp_ies_len);
1953#ifdef CONFIG_TDLS
1954 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1955 data->assoc_info.resp_ies_len);
1956#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001957#ifdef CONFIG_WNM
1958 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1959 data->assoc_info.resp_ies_len);
1960#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001961#ifdef CONFIG_INTERWORKING
1962 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1963 data->assoc_info.resp_ies_len);
1964#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001965 }
1966 if (data->assoc_info.beacon_ies)
1967 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1968 data->assoc_info.beacon_ies,
1969 data->assoc_info.beacon_ies_len);
1970 if (data->assoc_info.freq)
1971 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1972 data->assoc_info.freq);
1973
1974 p = data->assoc_info.req_ies;
1975 l = data->assoc_info.req_ies_len;
1976
1977 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1978 while (p && l >= 2) {
1979 len = p[1] + 2;
1980 if (len > l) {
1981 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1982 p, l);
1983 break;
1984 }
1985 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1986 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1987 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1988 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1989 break;
1990 found = 1;
1991 wpa_find_assoc_pmkid(wpa_s);
1992 break;
1993 }
1994 l -= len;
1995 p += len;
1996 }
1997 if (!found && data->assoc_info.req_ies)
1998 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1999
2000#ifdef CONFIG_IEEE80211R
2001#ifdef CONFIG_SME
2002 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002003 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2004 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2005 data->assoc_info.resp_ies,
2006 data->assoc_info.resp_ies_len,
2007 bssid) < 0) {
2008 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2009 "Reassociation Response failed");
2010 wpa_supplicant_deauthenticate(
2011 wpa_s, WLAN_REASON_INVALID_IE);
2012 return -1;
2013 }
2014 }
2015
2016 p = data->assoc_info.resp_ies;
2017 l = data->assoc_info.resp_ies_len;
2018
2019#ifdef CONFIG_WPS_STRICT
2020 if (p && wpa_s->current_ssid &&
2021 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
2022 struct wpabuf *wps;
2023 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
2024 if (wps == NULL) {
2025 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
2026 "include WPS IE in (Re)Association Response");
2027 return -1;
2028 }
2029
2030 if (wps_validate_assoc_resp(wps) < 0) {
2031 wpabuf_free(wps);
2032 wpa_supplicant_deauthenticate(
2033 wpa_s, WLAN_REASON_INVALID_IE);
2034 return -1;
2035 }
2036 wpabuf_free(wps);
2037 }
2038#endif /* CONFIG_WPS_STRICT */
2039
2040 /* Go through the IEs and make a copy of the MDIE, if present. */
2041 while (p && l >= 2) {
2042 len = p[1] + 2;
2043 if (len > l) {
2044 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
2045 p, l);
2046 break;
2047 }
2048 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
2049 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
2050 wpa_s->sme.ft_used = 1;
2051 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
2052 MOBILITY_DOMAIN_ID_LEN);
2053 break;
2054 }
2055 l -= len;
2056 p += len;
2057 }
2058#endif /* CONFIG_SME */
2059
Dmitry Shmidt700a1372013-03-15 14:14:44 -07002060 /* Process FT when SME is in the driver */
2061 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
2062 wpa_ft_is_completed(wpa_s->wpa)) {
2063 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
2064 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
2065 data->assoc_info.resp_ies,
2066 data->assoc_info.resp_ies_len,
2067 bssid) < 0) {
2068 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
2069 "Reassociation Response failed");
2070 wpa_supplicant_deauthenticate(
2071 wpa_s, WLAN_REASON_INVALID_IE);
2072 return -1;
2073 }
2074 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
2075 }
2076
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002077 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
2078 data->assoc_info.resp_ies_len);
2079#endif /* CONFIG_IEEE80211R */
2080
2081 /* WPA/RSN IE from Beacon/ProbeResp */
2082 p = data->assoc_info.beacon_ies;
2083 l = data->assoc_info.beacon_ies_len;
2084
2085 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
2086 */
2087 wpa_found = rsn_found = 0;
2088 while (p && l >= 2) {
2089 len = p[1] + 2;
2090 if (len > l) {
2091 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
2092 p, l);
2093 break;
2094 }
2095 if (!wpa_found &&
2096 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
2097 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
2098 wpa_found = 1;
2099 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
2100 }
2101
2102 if (!rsn_found &&
2103 p[0] == WLAN_EID_RSN && p[1] >= 2) {
2104 rsn_found = 1;
2105 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
2106 }
2107
2108 l -= len;
2109 p += len;
2110 }
2111
2112 if (!wpa_found && data->assoc_info.beacon_ies)
2113 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
2114 if (!rsn_found && data->assoc_info.beacon_ies)
2115 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
2116 if (wpa_found || rsn_found)
2117 wpa_s->ap_ies_from_associnfo = 1;
2118
Jouni Malinen87fd2792011-05-16 18:35:42 +03002119 if (wpa_s->assoc_freq && data->assoc_info.freq &&
2120 wpa_s->assoc_freq != data->assoc_info.freq) {
2121 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
2122 "%u to %u MHz",
2123 wpa_s->assoc_freq, data->assoc_info.freq);
2124 wpa_supplicant_update_scan_results(wpa_s);
2125 }
2126
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002127 wpa_s->assoc_freq = data->assoc_info.freq;
2128
2129 return 0;
2130}
2131
2132
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002133static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
2134{
2135 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
2136
2137 if (!wpa_s->current_bss || !wpa_s->current_ssid)
2138 return -1;
2139
2140 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
2141 return 0;
2142
2143 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2144 WPA_IE_VENDOR_TYPE);
2145 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
2146
2147 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
2148 bss_wpa ? 2 + bss_wpa[1] : 0) ||
2149 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
2150 bss_rsn ? 2 + bss_rsn[1] : 0))
2151 return -1;
2152
2153 return 0;
2154}
2155
2156
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002157static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
2158 union wpa_event_data *data)
2159{
2160#ifdef CONFIG_FST
2161 struct assoc_info *ai = data ? &data->assoc_info : NULL;
2162 struct wpa_bss *bss = wpa_s->current_bss;
2163 const u8 *ieprb, *iebcn;
2164
2165 wpabuf_free(wpa_s->received_mb_ies);
2166 wpa_s->received_mb_ies = NULL;
2167
2168 if (ai &&
2169 !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
2170 wpa_printf(MSG_DEBUG,
2171 "FST: MB IEs updated from Association Response frame");
2172 return;
2173 }
2174
2175 if (ai &&
2176 !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
2177 wpa_printf(MSG_DEBUG,
2178 "FST: MB IEs updated from association event Beacon IEs");
2179 return;
2180 }
2181
2182 if (!bss)
2183 return;
2184
2185 ieprb = (const u8 *) (bss + 1);
2186 iebcn = ieprb + bss->ie_len;
2187
2188 if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
2189 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
2190 else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
2191 wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
2192#endif /* CONFIG_FST */
2193}
2194
2195
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002196static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
2197 union wpa_event_data *data)
2198{
2199 u8 bssid[ETH_ALEN];
2200 int ft_completed;
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002201 int new_bss = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002202
2203#ifdef CONFIG_AP
2204 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002205 if (!data)
2206 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002207 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
2208 data->assoc_info.addr,
2209 data->assoc_info.req_ies,
2210 data->assoc_info.req_ies_len,
2211 data->assoc_info.reassoc);
2212 return;
2213 }
2214#endif /* CONFIG_AP */
2215
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002216 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
2217
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002218 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
2219 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
2220 return;
2221
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002222 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
2223 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002224 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002225 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2226 return;
2227 }
2228
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002229 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002230 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002231 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
2232 MACSTR, MAC2STR(bssid));
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002233 new_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002234 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002235 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
2236 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002237 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002238
2239 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
2240 wpa_clear_keys(wpa_s, bssid);
2241 }
2242 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002243 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002244 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2245 return;
2246 }
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002247 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002248
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08002249#ifdef ANDROID
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002250 if (wpa_s->conf->ap_scan == 1) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08002251#else
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002252 if (wpa_s->conf->ap_scan == 1 &&
2253 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08002254#endif
Amarnath Hullur Subramanyama82c83c2015-09-18 06:57:06 -07002255 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
2256 wpa_msg(wpa_s, MSG_WARNING,
2257 "WPA/RSN IEs not updated");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002258 }
2259
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002260 wpas_fst_update_mb_assoc(wpa_s, data);
2261
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002262#ifdef CONFIG_SME
2263 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
2264 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07002265 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002266#endif /* CONFIG_SME */
2267
2268 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
2269 if (wpa_s->current_ssid) {
2270 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
2271 * initialized before association, but for other modes,
2272 * initialize PC/SC here, if the current configuration needs
2273 * smartcard or SIM/USIM. */
2274 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
2275 }
2276 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2277 if (wpa_s->l2)
2278 l2_packet_notify_auth_start(wpa_s->l2);
2279
2280 /*
2281 * Set portEnabled first to FALSE in order to get EAP state machine out
2282 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2283 * state machine may transit to AUTHENTICATING state based on obsolete
2284 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2285 * AUTHENTICATED without ever giving chance to EAP state machine to
2286 * reset the state.
2287 */
2288 if (!ft_completed) {
2289 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2290 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2291 }
2292 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2293 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2294 /* 802.1X::portControl = Auto */
2295 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2296 wpa_s->eapol_received = 0;
2297 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2298 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2299 (wpa_s->current_ssid &&
2300 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002301 if (wpa_s->current_ssid &&
2302 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002303 (wpa_s->drv_flags &
2304 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2305 /*
2306 * Set the key after having received joined-IBSS event
2307 * from the driver.
2308 */
2309 wpa_supplicant_set_wpa_none_key(wpa_s,
2310 wpa_s->current_ssid);
2311 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002312 wpa_supplicant_cancel_auth_timeout(wpa_s);
2313 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2314 } else if (!ft_completed) {
2315 /* Timeout for receiving the first EAPOL packet */
2316 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2317 }
2318 wpa_supplicant_cancel_scan(wpa_s);
2319
2320 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2321 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2322 /*
2323 * We are done; the driver will take care of RSN 4-way
2324 * handshake.
2325 */
2326 wpa_supplicant_cancel_auth_timeout(wpa_s);
2327 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2328 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2329 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2330 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2331 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2332 /*
2333 * The driver will take care of RSN 4-way handshake, so we need
2334 * to allow EAPOL supplicant to complete its work without
2335 * waiting for WPA supplicant.
2336 */
2337 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2338 } else if (ft_completed) {
2339 /*
2340 * FT protocol completed - make sure EAPOL state machine ends
2341 * up in authenticated.
2342 */
2343 wpa_supplicant_cancel_auth_timeout(wpa_s);
2344 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2345 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2346 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2347 }
2348
Jouni Malinena05074c2012-12-21 21:35:35 +02002349 wpa_s->last_eapol_matches_bssid = 0;
2350
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002351 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002352 struct os_reltime now, age;
2353 os_get_reltime(&now);
2354 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002355 if (age.sec == 0 && age.usec < 100000 &&
2356 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2357 0) {
2358 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2359 "frame that was received just before "
2360 "association notification");
2361 wpa_supplicant_rx_eapol(
2362 wpa_s, wpa_s->pending_eapol_rx_src,
2363 wpabuf_head(wpa_s->pending_eapol_rx),
2364 wpabuf_len(wpa_s->pending_eapol_rx));
2365 }
2366 wpabuf_free(wpa_s->pending_eapol_rx);
2367 wpa_s->pending_eapol_rx = NULL;
2368 }
2369
2370 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2371 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002372 wpa_s->current_ssid &&
2373 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002374 /* Set static WEP keys again */
2375 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2376 }
2377
2378#ifdef CONFIG_IBSS_RSN
2379 if (wpa_s->current_ssid &&
2380 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2381 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2382 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2383 wpa_s->ibss_rsn == NULL) {
2384 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2385 if (!wpa_s->ibss_rsn) {
2386 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2387 wpa_supplicant_deauthenticate(
2388 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2389 return;
2390 }
2391
2392 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2393 }
2394#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002395
2396 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002397
2398 if (data) {
2399 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2400 data->assoc_info.resp_ies_len,
2401 &data->assoc_info.wmm_params);
2402
2403 if (wpa_s->reassoc_same_bss)
2404 wmm_ac_restore_tspecs(wpa_s);
2405 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002406}
2407
2408
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002409static int disconnect_reason_recoverable(u16 reason_code)
2410{
2411 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2412 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2413 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2414}
2415
2416
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002417static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002418 u16 reason_code,
2419 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002420{
2421 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002422
2423 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2424 /*
2425 * At least Host AP driver and a Prism3 card seemed to be
2426 * generating streams of disconnected events when configuring
2427 * IBSS for WPA-None. Ignore them for now.
2428 */
2429 return;
2430 }
2431
2432 bssid = wpa_s->bssid;
2433 if (is_zero_ether_addr(bssid))
2434 bssid = wpa_s->pending_bssid;
2435
2436 if (!is_zero_ether_addr(bssid) ||
2437 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2438 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2439 " reason=%d%s",
2440 MAC2STR(bssid), reason_code,
2441 locally_generated ? " locally_generated=1" : "");
2442 }
2443}
2444
2445
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002446static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2447 int locally_generated)
2448{
2449 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2450 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2451 return 0; /* Not in 4-way handshake with PSK */
2452
2453 /*
2454 * It looks like connection was lost while trying to go through PSK
2455 * 4-way handshake. Filter out known disconnection cases that are caused
2456 * by something else than PSK mismatch to avoid confusing reports.
2457 */
2458
2459 if (locally_generated) {
2460 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2461 return 0;
2462 }
2463
2464 return 1;
2465}
2466
2467
Jouni Malinen2b89da82012-08-31 22:04:41 +03002468static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2469 u16 reason_code,
2470 int locally_generated)
2471{
2472 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002473 int authenticating;
2474 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002475 struct wpa_bss *fast_reconnect = NULL;
2476 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002477 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002478
2479 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2480 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2481
2482 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2483 /*
2484 * At least Host AP driver and a Prism3 card seemed to be
2485 * generating streams of disconnected events when configuring
2486 * IBSS for WPA-None. Ignore them for now.
2487 */
2488 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2489 "IBSS/WPA-None mode");
2490 return;
2491 }
2492
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002493 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002494 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2495 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002496 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2497 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002498 wpas_auth_failed(wpa_s, "WRONG_KEY");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002499 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002500 if (!wpa_s->disconnected &&
2501 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002502 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08002503 wpas_wps_searching(wpa_s) ||
2504 wpas_wps_reenable_networks_pending(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002505 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002506 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002507 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002508 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002509 wpa_s->wpa_state);
2510 if (wpa_s->wpa_state == WPA_COMPLETED &&
2511 wpa_s->current_ssid &&
2512 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002513 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002514 disconnect_reason_recoverable(reason_code)) {
2515 /*
2516 * It looks like the AP has dropped association with
2517 * us, but could allow us to get back in. Try to
2518 * reconnect to the same BSS without full scan to save
2519 * time for some common cases.
2520 */
2521 fast_reconnect = wpa_s->current_bss;
2522 fast_reconnect_ssid = wpa_s->current_ssid;
2523 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002524 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002525 else
2526 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2527 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002528 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002529 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002530 "try to re-connect");
2531 wpa_s->reassociate = 0;
2532 wpa_s->disconnected = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002533 if (!wpa_s->pno)
2534 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002535 }
2536 bssid = wpa_s->bssid;
2537 if (is_zero_ether_addr(bssid))
2538 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002539 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2540 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002541 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002542 if (locally_generated)
2543 wpa_s->disconnect_reason = -reason_code;
2544 else
2545 wpa_s->disconnect_reason = reason_code;
2546 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002547 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2548 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002549 wpa_clear_keys(wpa_s, wpa_s->bssid);
2550 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002551 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002552 wpa_supplicant_mark_disassoc(wpa_s);
2553
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002554 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002555 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002556 wpa_s->current_ssid = last_ssid;
2557 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002558
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002559 if (fast_reconnect &&
2560 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2561 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2562 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2563 fast_reconnect->ssid_len) &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002564 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
2565 !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect->bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002566#ifndef CONFIG_NO_SCAN_PROCESSING
2567 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2568 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2569 fast_reconnect_ssid) < 0) {
2570 /* Recover through full scan */
2571 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2572 }
2573#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002574 } else if (fast_reconnect) {
2575 /*
2576 * Could not reconnect to the same BSS due to network being
2577 * disabled. Use a new scan to match the alternative behavior
2578 * above, i.e., to continue automatic reconnection attempt in a
2579 * way that enforces disabled network rules.
2580 */
2581 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002582 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002583}
2584
2585
2586#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002587void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002588{
2589 struct wpa_supplicant *wpa_s = eloop_ctx;
2590
2591 if (!wpa_s->pending_mic_error_report)
2592 return;
2593
2594 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2595 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2596 wpa_s->pending_mic_error_report = 0;
2597}
2598#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2599
2600
2601static void
2602wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2603 union wpa_event_data *data)
2604{
2605 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002606 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002607
2608 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2609 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002610 os_get_reltime(&t);
2611 if ((wpa_s->last_michael_mic_error.sec &&
2612 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002613 wpa_s->pending_mic_error_report) {
2614 if (wpa_s->pending_mic_error_report) {
2615 /*
2616 * Send the pending MIC error report immediately since
2617 * we are going to start countermeasures and AP better
2618 * do the same.
2619 */
2620 wpa_sm_key_request(wpa_s->wpa, 1,
2621 wpa_s->pending_mic_error_pairwise);
2622 }
2623
2624 /* Send the new MIC error report immediately since we are going
2625 * to start countermeasures and AP better do the same.
2626 */
2627 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2628
2629 /* initialize countermeasures */
2630 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002631
2632 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2633
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002634 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2635
2636 /*
2637 * Need to wait for completion of request frame. We do not get
2638 * any callback for the message completion, so just wait a
2639 * short while and hope for the best. */
2640 os_sleep(0, 10000);
2641
2642 wpa_drv_set_countermeasures(wpa_s, 1);
2643 wpa_supplicant_deauthenticate(wpa_s,
2644 WLAN_REASON_MICHAEL_MIC_FAILURE);
2645 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2646 wpa_s, NULL);
2647 eloop_register_timeout(60, 0,
2648 wpa_supplicant_stop_countermeasures,
2649 wpa_s, NULL);
2650 /* TODO: mark the AP rejected for 60 second. STA is
2651 * allowed to associate with another AP.. */
2652 } else {
2653#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2654 if (wpa_s->mic_errors_seen) {
2655 /*
2656 * Reduce the effectiveness of Michael MIC error
2657 * reports as a means for attacking against TKIP if
2658 * more than one MIC failure is noticed with the same
2659 * PTK. We delay the transmission of the reports by a
2660 * random time between 0 and 60 seconds in order to
2661 * force the attacker wait 60 seconds before getting
2662 * the information on whether a frame resulted in a MIC
2663 * failure.
2664 */
2665 u8 rval[4];
2666 int sec;
2667
2668 if (os_get_random(rval, sizeof(rval)) < 0)
2669 sec = os_random() % 60;
2670 else
2671 sec = WPA_GET_BE32(rval) % 60;
2672 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2673 "report %d seconds", sec);
2674 wpa_s->pending_mic_error_report = 1;
2675 wpa_s->pending_mic_error_pairwise = pairwise;
2676 eloop_cancel_timeout(
2677 wpa_supplicant_delayed_mic_error_report,
2678 wpa_s, NULL);
2679 eloop_register_timeout(
2680 sec, os_random() % 1000000,
2681 wpa_supplicant_delayed_mic_error_report,
2682 wpa_s, NULL);
2683 } else {
2684 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2685 }
2686#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2687 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2688#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2689 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002690 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002691 wpa_s->mic_errors_seen++;
2692}
2693
2694
2695#ifdef CONFIG_TERMINATE_ONLASTIF
2696static int any_interfaces(struct wpa_supplicant *head)
2697{
2698 struct wpa_supplicant *wpa_s;
2699
2700 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2701 if (!wpa_s->interface_removed)
2702 return 1;
2703 return 0;
2704}
2705#endif /* CONFIG_TERMINATE_ONLASTIF */
2706
2707
2708static void
2709wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2710 union wpa_event_data *data)
2711{
2712 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2713 return;
2714
2715 switch (data->interface_status.ievent) {
2716 case EVENT_INTERFACE_ADDED:
2717 if (!wpa_s->interface_removed)
2718 break;
2719 wpa_s->interface_removed = 0;
2720 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2721 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2722 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2723 "driver after interface was added");
2724 }
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07002725
2726#ifdef CONFIG_P2P
2727 if (!wpa_s->global->p2p &&
2728 !wpa_s->global->p2p_disabled &&
2729 !wpa_s->conf->p2p_disabled &&
2730 (wpa_s->drv_flags &
2731 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
2732 wpas_p2p_add_p2pdev_interface(
2733 wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
2734 wpa_printf(MSG_INFO,
2735 "P2P: Failed to enable P2P Device interface");
2736 /* Try to continue without. P2P will be disabled. */
2737 }
2738#endif /* CONFIG_P2P */
2739
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002740 break;
2741 case EVENT_INTERFACE_REMOVED:
2742 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2743 wpa_s->interface_removed = 1;
2744 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002745 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002746 l2_packet_deinit(wpa_s->l2);
2747 wpa_s->l2 = NULL;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07002748
2749#ifdef CONFIG_P2P
2750 if (wpa_s->global->p2p &&
2751 wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
2752 (wpa_s->drv_flags &
2753 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
2754 wpa_dbg(wpa_s, MSG_DEBUG,
2755 "Removing P2P Device interface");
2756 wpa_supplicant_remove_iface(
2757 wpa_s->global, wpa_s->global->p2p_init_wpa_s,
2758 0);
2759 wpa_s->global->p2p_init_wpa_s = NULL;
2760 }
2761#endif /* CONFIG_P2P */
2762
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002763#ifdef CONFIG_TERMINATE_ONLASTIF
2764 /* check if last interface */
2765 if (!any_interfaces(wpa_s->global->ifaces))
2766 eloop_terminate();
2767#endif /* CONFIG_TERMINATE_ONLASTIF */
2768 break;
2769 }
2770}
2771
2772
2773#ifdef CONFIG_PEERKEY
2774static void
2775wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2776 union wpa_event_data *data)
2777{
2778 if (data == NULL)
2779 return;
2780 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2781}
2782#endif /* CONFIG_PEERKEY */
2783
2784
2785#ifdef CONFIG_TDLS
2786static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2787 union wpa_event_data *data)
2788{
2789 if (data == NULL)
2790 return;
2791 switch (data->tdls.oper) {
2792 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002793 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2794 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2795 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2796 else
2797 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002798 break;
2799 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002800 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2801 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2802 data->tdls.reason_code);
2803 else
2804 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2805 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002806 break;
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07002807 case TDLS_REQUEST_DISCOVER:
2808 wpa_tdls_send_discovery_request(wpa_s->wpa,
2809 data->tdls.peer);
2810 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002811 }
2812}
2813#endif /* CONFIG_TDLS */
2814
2815
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002816#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002817static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2818 union wpa_event_data *data)
2819{
2820 if (data == NULL)
2821 return;
2822 switch (data->wnm.oper) {
2823 case WNM_OPER_SLEEP:
2824 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2825 "(action=%d, intval=%d)",
2826 data->wnm.sleep_action, data->wnm.sleep_intval);
2827 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002828 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002829 break;
2830 }
2831}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002832#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002833
2834
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002835#ifdef CONFIG_IEEE80211R
2836static void
2837wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2838 union wpa_event_data *data)
2839{
2840 if (data == NULL)
2841 return;
2842
2843 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2844 data->ft_ies.ies_len,
2845 data->ft_ies.ft_action,
2846 data->ft_ies.target_ap,
2847 data->ft_ies.ric_ies,
2848 data->ft_ies.ric_ies_len) < 0) {
2849 /* TODO: prevent MLME/driver from trying to associate? */
2850 }
2851}
2852#endif /* CONFIG_IEEE80211R */
2853
2854
2855#ifdef CONFIG_IBSS_RSN
2856static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2857 union wpa_event_data *data)
2858{
2859 struct wpa_ssid *ssid;
2860 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2861 return;
2862 if (data == NULL)
2863 return;
2864 ssid = wpa_s->current_ssid;
2865 if (ssid == NULL)
2866 return;
2867 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2868 return;
2869
2870 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2871}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002872
2873
2874static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2875 union wpa_event_data *data)
2876{
2877 struct wpa_ssid *ssid = wpa_s->current_ssid;
2878
2879 if (ssid == NULL)
2880 return;
2881
2882 /* check if the ssid is correctly configured as IBSS/RSN */
2883 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2884 return;
2885
2886 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2887 data->rx_mgmt.frame_len);
2888}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002889#endif /* CONFIG_IBSS_RSN */
2890
2891
2892#ifdef CONFIG_IEEE80211R
2893static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2894 size_t len)
2895{
2896 const u8 *sta_addr, *target_ap_addr;
2897 u16 status;
2898
2899 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2900 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2901 return; /* only SME case supported for now */
2902 if (len < 1 + 2 * ETH_ALEN + 2)
2903 return;
2904 if (data[0] != 2)
2905 return; /* Only FT Action Response is supported for now */
2906 sta_addr = data + 1;
2907 target_ap_addr = data + 1 + ETH_ALEN;
2908 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2909 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2910 MACSTR " TargetAP " MACSTR " status %u",
2911 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2912
2913 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2914 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2915 " in FT Action Response", MAC2STR(sta_addr));
2916 return;
2917 }
2918
2919 if (status) {
2920 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2921 "failure (status code %d)", status);
2922 /* TODO: report error to FT code(?) */
2923 return;
2924 }
2925
2926 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2927 len - (1 + 2 * ETH_ALEN + 2), 1,
2928 target_ap_addr, NULL, 0) < 0)
2929 return;
2930
2931#ifdef CONFIG_SME
2932 {
2933 struct wpa_bss *bss;
2934 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2935 if (bss)
2936 wpa_s->sme.freq = bss->freq;
2937 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2938 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2939 WLAN_AUTH_FT);
2940 }
2941#endif /* CONFIG_SME */
2942}
2943#endif /* CONFIG_IEEE80211R */
2944
2945
2946static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2947 struct unprot_deauth *e)
2948{
2949#ifdef CONFIG_IEEE80211W
2950 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2951 "dropped: " MACSTR " -> " MACSTR
2952 " (reason code %u)",
2953 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2954 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2955#endif /* CONFIG_IEEE80211W */
2956}
2957
2958
2959static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2960 struct unprot_disassoc *e)
2961{
2962#ifdef CONFIG_IEEE80211W
2963 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2964 "dropped: " MACSTR " -> " MACSTR
2965 " (reason code %u)",
2966 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2967 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2968#endif /* CONFIG_IEEE80211W */
2969}
2970
2971
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002972static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2973 u16 reason_code, int locally_generated,
2974 const u8 *ie, size_t ie_len, int deauth)
2975{
2976#ifdef CONFIG_AP
2977 if (wpa_s->ap_iface && addr) {
2978 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2979 return;
2980 }
2981
2982 if (wpa_s->ap_iface) {
2983 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2984 return;
2985 }
2986#endif /* CONFIG_AP */
2987
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002988 if (!locally_generated)
2989 wpa_s->own_disconnect_req = 0;
2990
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002991 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2992
Dmitry Shmidt344abd32014-01-14 13:17:00 -08002993 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2994 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2995 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2996 eapol_sm_failed(wpa_s->eapol))) &&
2997 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002998 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002999
3000#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003001 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003002 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
3003 locally_generated) > 0) {
3004 /*
3005 * The interface was removed, so cannot continue
3006 * processing any additional operations after this.
3007 */
3008 return;
3009 }
3010 }
3011#endif /* CONFIG_P2P */
3012
3013 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
3014 locally_generated);
3015}
3016
3017
3018static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
3019 struct disassoc_info *info)
3020{
3021 u16 reason_code = 0;
3022 int locally_generated = 0;
3023 const u8 *addr = NULL;
3024 const u8 *ie = NULL;
3025 size_t ie_len = 0;
3026
3027 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
3028
3029 if (info) {
3030 addr = info->addr;
3031 ie = info->ie;
3032 ie_len = info->ie_len;
3033 reason_code = info->reason_code;
3034 locally_generated = info->locally_generated;
3035 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
3036 locally_generated ? " (locally generated)" : "");
3037 if (addr)
3038 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3039 MAC2STR(addr));
3040 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
3041 ie, ie_len);
3042 }
3043
3044#ifdef CONFIG_AP
3045 if (wpa_s->ap_iface && info && info->addr) {
3046 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
3047 return;
3048 }
3049
3050 if (wpa_s->ap_iface) {
3051 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
3052 return;
3053 }
3054#endif /* CONFIG_AP */
3055
3056#ifdef CONFIG_P2P
3057 if (info) {
3058 wpas_p2p_disassoc_notif(
3059 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
3060 locally_generated);
3061 }
3062#endif /* CONFIG_P2P */
3063
3064 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3065 sme_event_disassoc(wpa_s, info);
3066
3067 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
3068 ie, ie_len, 0);
3069}
3070
3071
3072static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
3073 struct deauth_info *info)
3074{
3075 u16 reason_code = 0;
3076 int locally_generated = 0;
3077 const u8 *addr = NULL;
3078 const u8 *ie = NULL;
3079 size_t ie_len = 0;
3080
3081 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
3082
3083 if (info) {
3084 addr = info->addr;
3085 ie = info->ie;
3086 ie_len = info->ie_len;
3087 reason_code = info->reason_code;
3088 locally_generated = info->locally_generated;
3089 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
3090 reason_code,
3091 locally_generated ? " (locally generated)" : "");
3092 if (addr) {
3093 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
3094 MAC2STR(addr));
3095 }
3096 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
3097 ie, ie_len);
3098 }
3099
3100 wpa_reset_ft_completed(wpa_s->wpa);
3101
3102 wpas_event_disconnect(wpa_s, addr, reason_code,
3103 locally_generated, ie, ie_len, 1);
3104}
3105
3106
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003107static const char * reg_init_str(enum reg_change_initiator init)
3108{
3109 switch (init) {
3110 case REGDOM_SET_BY_CORE:
3111 return "CORE";
3112 case REGDOM_SET_BY_USER:
3113 return "USER";
3114 case REGDOM_SET_BY_DRIVER:
3115 return "DRIVER";
3116 case REGDOM_SET_BY_COUNTRY_IE:
3117 return "COUNTRY_IE";
3118 case REGDOM_BEACON_HINT:
3119 return "BEACON_HINT";
3120 }
3121 return "?";
3122}
3123
3124
3125static const char * reg_type_str(enum reg_type type)
3126{
3127 switch (type) {
3128 case REGDOM_TYPE_UNKNOWN:
3129 return "UNKNOWN";
3130 case REGDOM_TYPE_COUNTRY:
3131 return "COUNTRY";
3132 case REGDOM_TYPE_WORLD:
3133 return "WORLD";
3134 case REGDOM_TYPE_CUSTOM_WORLD:
3135 return "CUSTOM_WORLD";
3136 case REGDOM_TYPE_INTERSECTION:
3137 return "INTERSECTION";
3138 }
3139 return "?";
3140}
3141
3142
3143static void wpa_supplicant_update_channel_list(
3144 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003145{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003146 struct wpa_supplicant *ifs;
3147
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003148 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
Dmitry Shmidtc2817022014-07-02 10:32:10 -07003149 reg_init_str(info->initiator), reg_type_str(info->type),
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003150 info->alpha2[0] ? " alpha2=" : "",
3151 info->alpha2[0] ? info->alpha2 : "");
3152
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003153 if (wpa_s->drv_priv == NULL)
3154 return; /* Ignore event during drv initialization */
3155
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003156 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
3157 radio_list) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003158 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
3159 ifs->ifname);
3160 free_hw_features(ifs);
3161 ifs->hw.modes = wpa_drv_get_hw_feature_data(
3162 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003163 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07003164
3165 /* Restart sched_scan with updated channel list */
3166 if (wpa_s->sched_scanning) {
3167 wpa_dbg(wpa_s, MSG_DEBUG,
3168 "Channel list changed restart sched scan.");
3169 wpa_supplicant_cancel_sched_scan(wpa_s);
3170 wpa_supplicant_req_scan(wpa_s, 0, 0);
3171 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003172
3173 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003174}
3175
3176
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003177static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003178 const u8 *frame, size_t len, int freq,
3179 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003180{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003181 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003182 const u8 *payload;
3183 size_t plen;
3184 u8 category;
3185
3186 if (len < IEEE80211_HDRLEN + 2)
3187 return;
3188
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003189 mgmt = (const struct ieee80211_mgmt *) frame;
3190 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003191 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003192 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003193
3194 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
3195 " Category=%u DataLen=%d freq=%d MHz",
3196 MAC2STR(mgmt->sa), category, (int) plen, freq);
3197
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003198 if (category == WLAN_ACTION_WMM) {
3199 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
3200 return;
3201 }
3202
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003203#ifdef CONFIG_IEEE80211R
3204 if (category == WLAN_ACTION_FT) {
3205 ft_rx_action(wpa_s, payload, plen);
3206 return;
3207 }
3208#endif /* CONFIG_IEEE80211R */
3209
3210#ifdef CONFIG_IEEE80211W
3211#ifdef CONFIG_SME
3212 if (category == WLAN_ACTION_SA_QUERY) {
3213 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
3214 return;
3215 }
3216#endif /* CONFIG_SME */
3217#endif /* CONFIG_IEEE80211W */
3218
3219#ifdef CONFIG_WNM
3220 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
3221 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
3222 return;
3223 }
3224#endif /* CONFIG_WNM */
3225
3226#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08003227 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
3228 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003229 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08003230 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003231 payload, plen, freq) == 0)
3232 return;
3233#endif /* CONFIG_GAS */
3234
3235#ifdef CONFIG_TDLS
3236 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
3237 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
3238 wpa_dbg(wpa_s, MSG_DEBUG,
3239 "TDLS: Received Discovery Response from " MACSTR,
3240 MAC2STR(mgmt->sa));
3241 return;
3242 }
3243#endif /* CONFIG_TDLS */
3244
3245#ifdef CONFIG_INTERWORKING
3246 if (category == WLAN_ACTION_QOS && plen >= 1 &&
3247 payload[0] == QOS_QOS_MAP_CONFIG) {
3248 const u8 *pos = payload + 1;
3249 size_t qlen = plen - 1;
3250 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
3251 MACSTR, MAC2STR(mgmt->sa));
3252 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
3253 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
3254 pos[1] <= qlen - 2 && pos[1] >= 16)
3255 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
3256 return;
3257 }
3258#endif /* CONFIG_INTERWORKING */
3259
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003260 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3261 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
3262 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
3263 return;
3264 }
3265
3266 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
3267 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
3268 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
3269 payload + 1, plen - 1,
3270 rssi);
3271 return;
3272 }
3273
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003274#ifdef CONFIG_FST
3275 if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
3276 fst_rx_action(wpa_s->fst, mgmt, len);
3277 return;
3278 }
3279#endif /* CONFIG_FST */
3280
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003281 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
3282 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003283 if (wpa_s->ifmsh)
3284 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003285}
3286
3287
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003288static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
3289 union wpa_event_data *event)
3290{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003291 struct wpa_freq_range_list *list;
3292 char *str = NULL;
3293
3294 list = &event->freq_range;
3295
3296 if (list->num)
3297 str = freq_range_list_str(list);
3298 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
3299 str ? str : "");
3300
3301#ifdef CONFIG_P2P
3302 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
3303 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
3304 __func__);
3305 } else {
3306 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003307
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003308 /*
3309 * The update channel flow will also take care of moving a GO
3310 * from the unsafe frequency if needed.
3311 */
3312 wpas_p2p_update_channel_list(wpa_s,
3313 WPAS_P2P_CHANNEL_UPDATE_AVOID);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003314 }
3315#endif /* CONFIG_P2P */
3316
3317 os_free(str);
3318}
3319
3320
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003321static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3322 union wpa_event_data *data)
3323{
3324 wpa_dbg(wpa_s, MSG_DEBUG,
3325 "Connection authorized by device, previous state %d",
3326 wpa_s->wpa_state);
3327 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3328 wpa_supplicant_cancel_auth_timeout(wpa_s);
3329 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3330 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3331 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3332 }
3333 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3334 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003335 data->assoc_info.ptk_kck_len,
3336 data->assoc_info.ptk_kek,
3337 data->assoc_info.ptk_kek_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003338}
3339
3340
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003341void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3342 union wpa_event_data *data)
3343{
3344 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07003345 int resched;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003346
3347 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3348 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003349 event != EVENT_INTERFACE_STATUS &&
Dmitry Shmidt9c175262016-03-03 10:20:07 -08003350 event != EVENT_SCAN_RESULTS &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003351 event != EVENT_SCHED_SCAN_STOPPED) {
3352 wpa_dbg(wpa_s, MSG_DEBUG,
3353 "Ignore event %s (%d) while interface is disabled",
3354 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003355 return;
3356 }
3357
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003358#ifndef CONFIG_NO_STDOUT_DEBUG
3359{
3360 int level = MSG_DEBUG;
3361
Dmitry Shmidt04949592012-07-19 12:16:46 -07003362 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003363 const struct ieee80211_hdr *hdr;
3364 u16 fc;
3365 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3366 fc = le_to_host16(hdr->frame_control);
3367 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3368 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3369 level = MSG_EXCESSIVE;
3370 }
3371
3372 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3373 event_to_string(event), event);
3374}
3375#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003376
3377 switch (event) {
3378 case EVENT_AUTH:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003379#ifdef CONFIG_FST
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08003380 if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
3381 data->auth.ies_len))
3382 wpa_printf(MSG_DEBUG,
3383 "FST: MB IEs updated from auth IE");
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003384#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003385 sme_event_auth(wpa_s, data);
3386 break;
3387 case EVENT_ASSOC:
3388 wpa_supplicant_event_assoc(wpa_s, data);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003389 if (data && data->assoc_info.authorized)
3390 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08003391 if (data) {
3392 wpa_msg(wpa_s, MSG_INFO,
3393 WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
3394 data->assoc_info.subnet_status);
3395 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003396 break;
3397 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003398 wpas_event_disassoc(wpa_s,
3399 data ? &data->disassoc_info : NULL);
3400 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003401 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003402 wpas_event_deauth(wpa_s,
3403 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003404 break;
3405 case EVENT_MICHAEL_MIC_FAILURE:
3406 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3407 break;
3408#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003409 case EVENT_SCAN_STARTED:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003410 if (wpa_s->own_scan_requested ||
3411 (data && !data->scan_info.external_scan)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003412 struct os_reltime diff;
3413
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003414 os_get_reltime(&wpa_s->scan_start_time);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003415 os_reltime_sub(&wpa_s->scan_start_time,
3416 &wpa_s->scan_trigger_time, &diff);
3417 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3418 diff.sec, diff.usec);
3419 wpa_s->own_scan_requested = 0;
3420 wpa_s->own_scan_running = 1;
3421 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3422 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003423 wpa_msg_ctrl(wpa_s, MSG_INFO,
3424 WPA_EVENT_SCAN_STARTED "id=%u",
3425 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003426 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003427 wpa_msg_ctrl(wpa_s, MSG_INFO,
3428 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003429 }
3430 } else {
3431 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003432 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003433 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003434 }
3435 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003436 case EVENT_SCAN_RESULTS:
Dmitry Shmidt9c175262016-03-03 10:20:07 -08003437 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3438 wpa_s->scan_res_handler = NULL;
3439 wpa_s->own_scan_running = 0;
3440 wpa_s->radio->external_scan_running = 0;
3441 wpa_s->last_scan_req = NORMAL_SCAN_REQ;
3442 break;
3443 }
3444
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003445 if (!(data && data->scan_info.external_scan) &&
3446 os_reltime_initialized(&wpa_s->scan_start_time)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003447 struct os_reltime now, diff;
3448 os_get_reltime(&now);
3449 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3450 wpa_s->scan_start_time.sec = 0;
3451 wpa_s->scan_start_time.usec = 0;
3452 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3453 diff.sec, diff.usec);
3454 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003455 if (wpa_supplicant_event_scan_results(wpa_s, data))
3456 break; /* interface may have been removed */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003457 if (!(data && data->scan_info.external_scan))
3458 wpa_s->own_scan_running = 0;
3459 if (data && data->scan_info.nl_scan_event)
3460 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003461 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003462 break;
3463#endif /* CONFIG_NO_SCAN_PROCESSING */
3464 case EVENT_ASSOCINFO:
3465 wpa_supplicant_event_associnfo(wpa_s, data);
3466 break;
3467 case EVENT_INTERFACE_STATUS:
3468 wpa_supplicant_event_interface_status(wpa_s, data);
3469 break;
3470 case EVENT_PMKID_CANDIDATE:
3471 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3472 break;
3473#ifdef CONFIG_PEERKEY
3474 case EVENT_STKSTART:
3475 wpa_supplicant_event_stkstart(wpa_s, data);
3476 break;
3477#endif /* CONFIG_PEERKEY */
3478#ifdef CONFIG_TDLS
3479 case EVENT_TDLS:
3480 wpa_supplicant_event_tdls(wpa_s, data);
3481 break;
3482#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003483#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003484 case EVENT_WNM:
3485 wpa_supplicant_event_wnm(wpa_s, data);
3486 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003487#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003488#ifdef CONFIG_IEEE80211R
3489 case EVENT_FT_RESPONSE:
3490 wpa_supplicant_event_ft_response(wpa_s, data);
3491 break;
3492#endif /* CONFIG_IEEE80211R */
3493#ifdef CONFIG_IBSS_RSN
3494 case EVENT_IBSS_RSN_START:
3495 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3496 break;
3497#endif /* CONFIG_IBSS_RSN */
3498 case EVENT_ASSOC_REJECT:
3499 if (data->assoc_reject.bssid)
3500 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3501 "bssid=" MACSTR " status_code=%u",
3502 MAC2STR(data->assoc_reject.bssid),
3503 data->assoc_reject.status_code);
3504 else
3505 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3506 "status_code=%u",
3507 data->assoc_reject.status_code);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003508 wpa_s->assoc_status_code = data->assoc_reject.status_code;
3509 wpas_notify_assoc_status_code(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003510 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3511 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07003512 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003513 const u8 *bssid = data->assoc_reject.bssid;
3514 if (bssid == NULL || is_zero_ether_addr(bssid))
3515 bssid = wpa_s->pending_bssid;
3516 wpas_connection_failed(wpa_s, bssid);
3517 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003518 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003519 break;
3520 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003521 /* It is possible to get this event from earlier connection */
3522 if (wpa_s->current_ssid &&
3523 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3524 wpa_dbg(wpa_s, MSG_DEBUG,
3525 "Ignore AUTH_TIMED_OUT in mesh configuration");
3526 break;
3527 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003528 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3529 sme_event_auth_timed_out(wpa_s, data);
3530 break;
3531 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003532 /* It is possible to get this event from earlier connection */
3533 if (wpa_s->current_ssid &&
3534 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3535 wpa_dbg(wpa_s, MSG_DEBUG,
3536 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3537 break;
3538 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003539 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3540 sme_event_assoc_timed_out(wpa_s, data);
3541 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003542 case EVENT_TX_STATUS:
3543 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3544 " type=%d stype=%d",
3545 MAC2STR(data->tx_status.dst),
3546 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003547#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003548 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003549#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003550 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3551 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003552 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003553 wpa_s, data->tx_status.dst,
3554 data->tx_status.data,
3555 data->tx_status.data_len,
3556 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003557 OFFCHANNEL_SEND_ACTION_SUCCESS :
3558 OFFCHANNEL_SEND_ACTION_NO_ACK);
3559#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003560 break;
3561 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003562#endif /* CONFIG_AP */
3563#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003564 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3565 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3566 /*
3567 * Catch TX status events for Action frames we sent via group
3568 * interface in GO mode.
3569 */
3570 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3571 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3572 os_memcmp(wpa_s->parent->pending_action_dst,
3573 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003574 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003575 wpa_s->parent, data->tx_status.dst,
3576 data->tx_status.data,
3577 data->tx_status.data_len,
3578 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003579 OFFCHANNEL_SEND_ACTION_SUCCESS :
3580 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003581 break;
3582 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003583#endif /* CONFIG_OFFCHANNEL */
3584#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003585 switch (data->tx_status.type) {
3586 case WLAN_FC_TYPE_MGMT:
3587 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3588 data->tx_status.data_len,
3589 data->tx_status.stype,
3590 data->tx_status.ack);
3591 break;
3592 case WLAN_FC_TYPE_DATA:
3593 ap_tx_status(wpa_s, data->tx_status.dst,
3594 data->tx_status.data,
3595 data->tx_status.data_len,
3596 data->tx_status.ack);
3597 break;
3598 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003599#endif /* CONFIG_AP */
3600 break;
3601#ifdef CONFIG_AP
3602 case EVENT_EAPOL_TX_STATUS:
3603 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3604 data->eapol_tx_status.data,
3605 data->eapol_tx_status.data_len,
3606 data->eapol_tx_status.ack);
3607 break;
3608 case EVENT_DRIVER_CLIENT_POLL_OK:
3609 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003610 break;
3611 case EVENT_RX_FROM_UNKNOWN:
3612 if (wpa_s->ap_iface == NULL)
3613 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003614 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3615 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003616 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003617 case EVENT_CH_SWITCH:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003618 if (!data || !wpa_s->current_ssid)
Dmitry Shmidt04949592012-07-19 12:16:46 -07003619 break;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003620
3621 wpa_s->assoc_freq = data->ch_switch.freq;
3622 wpa_s->current_ssid->frequency = data->ch_switch.freq;
3623
3624 if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
3625 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
3626 wpa_s->current_ssid->mode ==
3627 WPAS_MODE_P2P_GROUP_FORMATION) {
3628 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3629 data->ch_switch.ht_enabled,
3630 data->ch_switch.ch_offset,
3631 data->ch_switch.ch_width,
3632 data->ch_switch.cf1,
3633 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003634 }
3635
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003636 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003637 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08003638#ifdef NEED_AP_MLME
3639 case EVENT_DFS_RADAR_DETECTED:
3640 if (data)
3641 wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
3642 break;
3643 case EVENT_DFS_CAC_STARTED:
3644 if (data)
3645 wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
3646 break;
3647 case EVENT_DFS_CAC_FINISHED:
3648 if (data)
3649 wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
3650 break;
3651 case EVENT_DFS_CAC_ABORTED:
3652 if (data)
3653 wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
3654 break;
3655 case EVENT_DFS_NOP_FINISHED:
3656 if (data)
3657 wpas_event_dfs_cac_nop_finished(wpa_s,
3658 &data->dfs_event);
3659 break;
3660#endif /* NEED_AP_MLME */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003661#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003662 case EVENT_RX_MGMT: {
3663 u16 fc, stype;
3664 const struct ieee80211_mgmt *mgmt;
3665
Dmitry Shmidt818ea482014-03-10 13:15:21 -07003666#ifdef CONFIG_TESTING_OPTIONS
3667 if (wpa_s->ext_mgmt_frame_handling) {
3668 struct rx_mgmt *rx = &data->rx_mgmt;
3669 size_t hex_len = 2 * rx->frame_len + 1;
3670 char *hex = os_malloc(hex_len);
3671 if (hex) {
3672 wpa_snprintf_hex(hex, hex_len,
3673 rx->frame, rx->frame_len);
3674 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3675 rx->freq, rx->datarate, rx->ssi_signal,
3676 hex);
3677 os_free(hex);
3678 }
3679 break;
3680 }
3681#endif /* CONFIG_TESTING_OPTIONS */
3682
Dmitry Shmidt04949592012-07-19 12:16:46 -07003683 mgmt = (const struct ieee80211_mgmt *)
3684 data->rx_mgmt.frame;
3685 fc = le_to_host16(mgmt->frame_control);
3686 stype = WLAN_FC_GET_STYPE(fc);
3687
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003688#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003689 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003690#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003691#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003692 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3693 data->rx_mgmt.frame_len > 24) {
3694 const u8 *src = mgmt->sa;
3695 const u8 *ie = mgmt->u.probe_req.variable;
3696 size_t ie_len = data->rx_mgmt.frame_len -
3697 (mgmt->u.probe_req.variable -
3698 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003699 wpas_p2p_probe_req_rx(
3700 wpa_s, src, mgmt->da,
3701 mgmt->bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003702 data->rx_mgmt.freq,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003703 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003704 break;
3705 }
3706#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003707#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003708 if (wpa_s->current_ssid &&
3709 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3710 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003711 data->rx_mgmt.frame_len >= 30) {
3712 wpa_supplicant_event_ibss_auth(wpa_s, data);
3713 break;
3714 }
3715#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003716
3717 if (stype == WLAN_FC_STYPE_ACTION) {
3718 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003719 wpa_s, data->rx_mgmt.frame,
3720 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003721 data->rx_mgmt.freq,
3722 data->rx_mgmt.ssi_signal);
3723 break;
3724 }
3725
3726 if (wpa_s->ifmsh) {
3727 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003728 break;
3729 }
3730
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003731 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3732 "management frame in non-AP mode");
3733 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003734#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003735 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003736
3737 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3738 data->rx_mgmt.frame_len > 24) {
3739 const u8 *ie = mgmt->u.probe_req.variable;
3740 size_t ie_len = data->rx_mgmt.frame_len -
3741 (mgmt->u.probe_req.variable -
3742 data->rx_mgmt.frame);
3743
3744 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3745 mgmt->bssid, ie, ie_len,
3746 data->rx_mgmt.ssi_signal);
3747 }
3748
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003749 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003750#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003751 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003752 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003753 case EVENT_RX_PROBE_REQ:
3754 if (data->rx_probe_req.sa == NULL ||
3755 data->rx_probe_req.ie == NULL)
3756 break;
3757#ifdef CONFIG_AP
3758 if (wpa_s->ap_iface) {
3759 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3760 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003761 data->rx_probe_req.da,
3762 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003763 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003764 data->rx_probe_req.ie_len,
3765 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003766 break;
3767 }
3768#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003769 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003770 data->rx_probe_req.da,
3771 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003772 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003773 data->rx_probe_req.ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07003774 0,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003775 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003776 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003777 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003778#ifdef CONFIG_OFFCHANNEL
3779 offchannel_remain_on_channel_cb(
3780 wpa_s, data->remain_on_channel.freq,
3781 data->remain_on_channel.duration);
3782#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003783 wpas_p2p_remain_on_channel_cb(
3784 wpa_s, data->remain_on_channel.freq,
3785 data->remain_on_channel.duration);
3786 break;
3787 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003788#ifdef CONFIG_OFFCHANNEL
3789 offchannel_cancel_remain_on_channel_cb(
3790 wpa_s, data->remain_on_channel.freq);
3791#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003792 wpas_p2p_cancel_remain_on_channel_cb(
3793 wpa_s, data->remain_on_channel.freq);
3794 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003795 case EVENT_EAPOL_RX:
3796 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3797 data->eapol_rx.data,
3798 data->eapol_rx.data_len);
3799 break;
3800 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003801 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3802 "above=%d signal=%d noise=%d txrate=%d",
3803 data->signal_change.above_threshold,
3804 data->signal_change.current_signal,
3805 data->signal_change.current_noise,
3806 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003807 wpa_bss_update_level(wpa_s->current_bss,
3808 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003809 bgscan_notify_signal_change(
3810 wpa_s, data->signal_change.above_threshold,
3811 data->signal_change.current_signal,
3812 data->signal_change.current_noise,
3813 data->signal_change.current_txrate);
3814 break;
3815 case EVENT_INTERFACE_ENABLED:
3816 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3817 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003818 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07003819 if (wpa_s->p2p_mgmt) {
3820 wpa_supplicant_set_state(wpa_s,
3821 WPA_DISCONNECTED);
3822 break;
3823 }
3824
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003825#ifdef CONFIG_AP
3826 if (!wpa_s->ap_iface) {
3827 wpa_supplicant_set_state(wpa_s,
3828 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003829 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003830 wpa_supplicant_req_scan(wpa_s, 0, 0);
3831 } else
3832 wpa_supplicant_set_state(wpa_s,
3833 WPA_COMPLETED);
3834#else /* CONFIG_AP */
3835 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3836 wpa_supplicant_req_scan(wpa_s, 0, 0);
3837#endif /* CONFIG_AP */
3838 }
3839 break;
3840 case EVENT_INTERFACE_DISABLED:
3841 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003842#ifdef CONFIG_P2P
3843 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3844 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3845 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3846 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003847 * Mark interface disabled if this happens to end up not
3848 * being removed as a separate P2P group interface.
3849 */
3850 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3851 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003852 * The interface was externally disabled. Remove
3853 * it assuming an external entity will start a
3854 * new session if needed.
3855 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003856 if (wpa_s->current_ssid &&
3857 wpa_s->current_ssid->p2p_group)
3858 wpas_p2p_interface_unavailable(wpa_s);
3859 else
3860 wpas_p2p_disconnect(wpa_s);
3861 /*
3862 * wpa_s instance may have been freed, so must not use
3863 * it here anymore.
3864 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003865 break;
3866 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003867 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3868 p2p_in_progress(wpa_s->global->p2p) > 1) {
3869 /* This radio work will be cancelled, so clear P2P
3870 * state as well.
3871 */
3872 p2p_stop_find(wpa_s->global->p2p);
3873 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003874#endif /* CONFIG_P2P */
3875
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003876 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3877 /*
3878 * Indicate disconnection to keep ctrl_iface events
3879 * consistent.
3880 */
3881 wpa_supplicant_event_disassoc(
3882 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3883 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003884 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003885 radio_remove_works(wpa_s, NULL, 0);
3886
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003887 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3888 break;
3889 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003890 wpa_supplicant_update_channel_list(
3891 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003892 break;
3893 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003894 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003895 break;
3896 case EVENT_BEST_CHANNEL:
3897 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3898 "(%d %d %d)",
3899 data->best_chan.freq_24, data->best_chan.freq_5,
3900 data->best_chan.freq_overall);
3901 wpa_s->best_24_freq = data->best_chan.freq_24;
3902 wpa_s->best_5_freq = data->best_chan.freq_5;
3903 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003904 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3905 data->best_chan.freq_5,
3906 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003907 break;
3908 case EVENT_UNPROT_DEAUTH:
3909 wpa_supplicant_event_unprot_deauth(wpa_s,
3910 &data->unprot_deauth);
3911 break;
3912 case EVENT_UNPROT_DISASSOC:
3913 wpa_supplicant_event_unprot_disassoc(wpa_s,
3914 &data->unprot_disassoc);
3915 break;
3916 case EVENT_STATION_LOW_ACK:
3917#ifdef CONFIG_AP
3918 if (wpa_s->ap_iface && data)
3919 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3920 data->low_ack.addr);
3921#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003922#ifdef CONFIG_TDLS
3923 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07003924 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3925 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003926#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003927 break;
3928 case EVENT_IBSS_PEER_LOST:
3929#ifdef CONFIG_IBSS_RSN
3930 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3931#endif /* CONFIG_IBSS_RSN */
3932 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003933 case EVENT_DRIVER_GTK_REKEY:
3934 if (os_memcmp(data->driver_gtk_rekey.bssid,
3935 wpa_s->bssid, ETH_ALEN))
3936 break;
3937 if (!wpa_s->wpa)
3938 break;
3939 wpa_sm_update_replay_ctr(wpa_s->wpa,
3940 data->driver_gtk_rekey.replay_ctr);
3941 break;
3942 case EVENT_SCHED_SCAN_STOPPED:
Dmitry Shmidt18463232014-01-24 12:29:41 -08003943 wpa_s->pno = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003944 wpa_s->sched_scanning = 0;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08003945 resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003946 wpa_supplicant_notify_scanning(wpa_s, 0);
3947
3948 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3949 break;
3950
3951 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08003952 * Start a new sched scan to continue searching for more SSIDs
3953 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003954 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07003955 if (wpa_s->sched_scan_timed_out) {
3956 wpa_supplicant_req_sched_scan(wpa_s);
3957 } else if (wpa_s->pno_sched_pending) {
3958 wpa_s->pno_sched_pending = 0;
3959 wpas_start_pno(wpa_s);
Dmitry Shmidtaf9da312015-04-03 10:03:11 -07003960 } else if (resched) {
3961 wpa_supplicant_req_scan(wpa_s, 0, 0);
Dmitry Shmidt18463232014-01-24 12:29:41 -08003962 }
3963
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003964 break;
3965 case EVENT_WPS_BUTTON_PUSHED:
3966#ifdef CONFIG_WPS
3967 wpas_wps_start_pbc(wpa_s, NULL, 0);
3968#endif /* CONFIG_WPS */
3969 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003970 case EVENT_AVOID_FREQUENCIES:
3971 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3972 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003973 case EVENT_CONNECT_FAILED_REASON:
3974#ifdef CONFIG_AP
3975 if (!wpa_s->ap_iface || !data)
3976 break;
3977 hostapd_event_connect_failed_reason(
3978 wpa_s->ap_iface->bss[0],
3979 data->connect_failed_reason.addr,
3980 data->connect_failed_reason.code);
3981#endif /* CONFIG_AP */
3982 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003983 case EVENT_NEW_PEER_CANDIDATE:
3984#ifdef CONFIG_MESH
3985 if (!wpa_s->ifmsh || !data)
3986 break;
3987 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3988 data->mesh_peer.ies,
3989 data->mesh_peer.ie_len);
3990#endif /* CONFIG_MESH */
3991 break;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08003992 case EVENT_SURVEY:
3993#ifdef CONFIG_AP
3994 if (!wpa_s->ap_iface)
3995 break;
3996 hostapd_event_get_survey(wpa_s->ap_iface,
3997 &data->survey_results);
3998#endif /* CONFIG_AP */
3999 break;
4000 case EVENT_ACS_CHANNEL_SELECTED:
4001#ifdef CONFIG_ACS
4002 if (!wpa_s->ap_iface)
4003 break;
4004 hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
4005 &data->acs_selected_channels);
4006#endif /* CONFIG_ACS */
4007 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004008 default:
4009 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
4010 break;
4011 }
4012}