blob: 1c46d35d81a1a7287c135de770beccbe93aaded2 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003 * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "pcsc_funcs.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "common/wpa_ctrl.h"
23#include "eap_peer/eap.h"
24#include "ap/hostapd.h"
25#include "p2p/p2p.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070026#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "notify.h"
28#include "common/ieee802_11_defs.h"
29#include "common/ieee802_11_common.h"
30#include "crypto/random.h"
31#include "blacklist.h"
32#include "wpas_glue.h"
33#include "wps_supplicant.h"
34#include "ibss_rsn.h"
35#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080036#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037#include "p2p_supplicant.h"
38#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070039#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040#include "ap.h"
41#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080043#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070044#include "interworking.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080045#include "mesh.h"
46#include "mesh_mpm.h"
47#include "wmm_ac.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070048
49
Dmitry Shmidt34af3062013-07-11 10:46:32 -070050#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070051static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080052 int new_scan, int own_request);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070053#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080054
55
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070056static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
57 struct wpa_ssid *ssid)
58{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080059 struct os_reltime now;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070060
61 if (ssid == NULL || ssid->disabled_until.sec == 0)
62 return 0;
63
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080064 os_get_reltime(&now);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070065 if (ssid->disabled_until.sec > now.sec)
66 return ssid->disabled_until.sec - now.sec;
67
68 wpas_clear_temp_disabled(wpa_s, ssid, 0);
69
70 return 0;
71}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070072
73
Dmitry Shmidtcf32e602014-01-28 10:57:39 -080074static struct wpa_bss * wpa_supplicant_get_new_bss(
75 struct wpa_supplicant *wpa_s, const u8 *bssid)
76{
77 struct wpa_bss *bss = NULL;
78 struct wpa_ssid *ssid = wpa_s->current_ssid;
79
80 if (ssid->ssid_len > 0)
81 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
82 if (!bss)
83 bss = wpa_bss_get_bssid(wpa_s, bssid);
84
85 return bss;
86}
87
88
Jouni Malinen5c879ee2014-08-18 11:04:56 -070089static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
90{
91 struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
92
93 if (!bss) {
94 wpa_supplicant_update_scan_results(wpa_s);
95
96 /* Get the BSS from the new scan results */
97 bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
98 }
99
100 if (bss)
101 wpa_s->current_bss = bss;
102}
103
104
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700105static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
106{
107 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700108 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700110 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
111 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700112 return 0;
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700113 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114
115 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
116 "information");
117 ssid = wpa_supplicant_get_ssid(wpa_s);
118 if (ssid == NULL) {
119 wpa_msg(wpa_s, MSG_INFO,
120 "No network configuration found for the current AP");
121 return -1;
122 }
123
Dmitry Shmidt04949592012-07-19 12:16:46 -0700124 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700125 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
126 return -1;
127 }
128
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800129 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
130 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
131 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
132 return -1;
133 }
134
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700135 res = wpas_temp_disabled(wpa_s, ssid);
136 if (res > 0) {
137 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
138 "disabled for %d second(s)", res);
139 return -1;
140 }
141
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700142 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
143 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800144 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700145 u8 wpa_ie[80];
146 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800147 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
148 wpa_ie, &wpa_ie_len) < 0)
149 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150 } else {
151 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
152 }
153
154 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
155 eapol_sm_invalidate_cached_session(wpa_s->eapol);
156 old_ssid = wpa_s->current_ssid;
157 wpa_s->current_ssid = ssid;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800158
Jouni Malinen5c879ee2014-08-18 11:04:56 -0700159 wpa_supplicant_update_current_bss(wpa_s);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800160
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700161 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
162 wpa_supplicant_initiate_eapol(wpa_s);
163 if (old_ssid != wpa_s->current_ssid)
164 wpas_notify_network_changed(wpa_s);
165
166 return 0;
167}
168
169
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800170void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171{
172 struct wpa_supplicant *wpa_s = eloop_ctx;
173
174 if (wpa_s->countermeasures) {
175 wpa_s->countermeasures = 0;
176 wpa_drv_set_countermeasures(wpa_s, 0);
177 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800178
179 /*
180 * It is possible that the device is sched scanning, which means
181 * that a connection attempt will be done only when we receive
182 * scan results. However, in this case, it would be preferable
183 * to scan and connect immediately, so cancel the sched_scan and
184 * issue a regular scan flow.
185 */
186 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700187 wpa_supplicant_req_scan(wpa_s, 0, 0);
188 }
189}
190
191
192void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
193{
194 int bssid_changed;
195
Dmitry Shmidt04949592012-07-19 12:16:46 -0700196 wnm_bss_keep_alive_deinit(wpa_s);
197
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198#ifdef CONFIG_IBSS_RSN
199 ibss_rsn_deinit(wpa_s->ibss_rsn);
200 wpa_s->ibss_rsn = NULL;
201#endif /* CONFIG_IBSS_RSN */
202
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700203#ifdef CONFIG_AP
204 wpa_supplicant_ap_deinit(wpa_s);
205#endif /* CONFIG_AP */
206
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700207 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
208 return;
209
210 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
211 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
212 os_memset(wpa_s->bssid, 0, ETH_ALEN);
213 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800214 sme_clear_on_disassoc(wpa_s);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800215#ifdef CONFIG_P2P
216 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
217#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700218 wpa_s->current_bss = NULL;
219 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700220
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700221 if (bssid_changed)
222 wpas_notify_bssid_changed(wpa_s);
223
224 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
225 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
226 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
227 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
228 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700229 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700230 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700231 wpa_s->key_mgmt = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800232
233 wpas_rrm_reset(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700234}
235
236
237static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
238{
239 struct wpa_ie_data ie;
240 int pmksa_set = -1;
241 size_t i;
242
243 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
244 ie.pmkid == NULL)
245 return;
246
247 for (i = 0; i < ie.num_pmkid; i++) {
248 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
249 ie.pmkid + i * PMKID_LEN,
250 NULL, NULL, 0);
251 if (pmksa_set == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800252 eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700253 break;
254 }
255 }
256
257 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
258 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
259}
260
261
262static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
263 union wpa_event_data *data)
264{
265 if (data == NULL) {
266 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
267 "event");
268 return;
269 }
270 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
271 " index=%d preauth=%d",
272 MAC2STR(data->pmkid_candidate.bssid),
273 data->pmkid_candidate.index,
274 data->pmkid_candidate.preauth);
275
276 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
277 data->pmkid_candidate.index,
278 data->pmkid_candidate.preauth);
279}
280
281
282static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
283{
284 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
285 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
286 return 0;
287
288#ifdef IEEE8021X_EAPOL
289 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
290 wpa_s->current_ssid &&
291 !(wpa_s->current_ssid->eapol_flags &
292 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
293 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
294 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
295 * plaintext or static WEP keys). */
296 return 0;
297 }
298#endif /* IEEE8021X_EAPOL */
299
300 return 1;
301}
302
303
304/**
305 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
306 * @wpa_s: pointer to wpa_supplicant data
307 * @ssid: Configuration data for the network
308 * Returns: 0 on success, -1 on failure
309 *
310 * This function is called when starting authentication with a network that is
311 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
312 */
313int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
314 struct wpa_ssid *ssid)
315{
316#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800317#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700318 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700320 if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
321 wpa_s->scard != NULL || wpa_s->conf->external_sim)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700322 return 0;
323
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700324 if (ssid == NULL || ssid->eap.eap_methods == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700325 sim = 1;
326 aka = 1;
327 } else {
328 struct eap_method_type *eap = ssid->eap.eap_methods;
329 while (eap->vendor != EAP_VENDOR_IETF ||
330 eap->method != EAP_TYPE_NONE) {
331 if (eap->vendor == EAP_VENDOR_IETF) {
332 if (eap->method == EAP_TYPE_SIM)
333 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700334 else if (eap->method == EAP_TYPE_AKA ||
335 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336 aka = 1;
337 }
338 eap++;
339 }
340 }
341
342 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
343 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700344 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
345 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
346 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700347 aka = 0;
348
349 if (!sim && !aka) {
350 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
351 "use SIM, but neither EAP-SIM nor EAP-AKA are "
352 "enabled");
353 return 0;
354 }
355
356 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
357 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700358
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -0700359 wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700360 if (wpa_s->scard == NULL) {
361 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
362 "(pcsc-lite)");
363 return -1;
364 }
365 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
366 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800367#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700368#endif /* IEEE8021X_EAPOL */
369
370 return 0;
371}
372
373
374#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700375
376static int has_wep_key(struct wpa_ssid *ssid)
377{
378 int i;
379
380 for (i = 0; i < NUM_WEP_KEYS; i++) {
381 if (ssid->wep_key_len[i])
382 return 1;
383 }
384
385 return 0;
386}
387
388
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700389static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700390 struct wpa_ssid *ssid)
391{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700392 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700393
394 if (ssid->mixed_cell)
395 return 1;
396
397#ifdef CONFIG_WPS
398 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
399 return 1;
400#endif /* CONFIG_WPS */
401
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700402 if (has_wep_key(ssid))
403 privacy = 1;
404
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700405#ifdef IEEE8021X_EAPOL
406 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
407 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
408 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
409 privacy = 1;
410#endif /* IEEE8021X_EAPOL */
411
Jouni Malinen75ecf522011-06-27 15:19:46 -0700412 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
413 privacy = 1;
414
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800415 if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
416 privacy = 1;
417
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700418 if (bss->caps & IEEE80211_CAP_PRIVACY)
419 return privacy;
420 return !privacy;
421}
422
423
424static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
425 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700426 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700427{
428 struct wpa_ie_data ie;
429 int proto_match = 0;
430 const u8 *rsn_ie, *wpa_ie;
431 int ret;
432 int wep_ok;
433
434 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
435 if (ret >= 0)
436 return ret;
437
438 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
439 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
440 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
441 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
442 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
443
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700444 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700445 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
446 proto_match++;
447
448 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
449 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
450 "failed");
451 break;
452 }
453
454 if (wep_ok &&
455 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
456 {
457 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
458 "in RSN IE");
459 return 1;
460 }
461
462 if (!(ie.proto & ssid->proto)) {
463 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
464 "mismatch");
465 break;
466 }
467
468 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
469 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
470 "cipher mismatch");
471 break;
472 }
473
474 if (!(ie.group_cipher & ssid->group_cipher)) {
475 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
476 "cipher mismatch");
477 break;
478 }
479
480 if (!(ie.key_mgmt & ssid->key_mgmt)) {
481 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
482 "mismatch");
483 break;
484 }
485
486#ifdef CONFIG_IEEE80211W
487 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800488 wpas_get_ssid_pmf(wpa_s, ssid) ==
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800489 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700490 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
491 "frame protection");
492 break;
493 }
494#endif /* CONFIG_IEEE80211W */
495
496 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
497 return 1;
498 }
499
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700500 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
502 proto_match++;
503
504 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
505 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
506 "failed");
507 break;
508 }
509
510 if (wep_ok &&
511 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
512 {
513 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
514 "in WPA IE");
515 return 1;
516 }
517
518 if (!(ie.proto & ssid->proto)) {
519 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
520 "mismatch");
521 break;
522 }
523
524 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
525 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
526 "cipher mismatch");
527 break;
528 }
529
530 if (!(ie.group_cipher & ssid->group_cipher)) {
531 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
532 "cipher mismatch");
533 break;
534 }
535
536 if (!(ie.key_mgmt & ssid->key_mgmt)) {
537 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
538 "mismatch");
539 break;
540 }
541
542 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
543 return 1;
544 }
545
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700546 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
547 !rsn_ie) {
548 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
549 return 1;
550 }
551
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700552 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
553 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
554 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
555 return 0;
556 }
557
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800558 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
559 wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
560 wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
561 return 1;
562 }
563
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700564 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
565 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
566 return 1;
567 }
568
569 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
570 "WPA/WPA2");
571
572 return 0;
573}
574
575
576static int freq_allowed(int *freqs, int freq)
577{
578 int i;
579
580 if (freqs == NULL)
581 return 1;
582
583 for (i = 0; freqs[i]; i++)
584 if (freqs[i] == freq)
585 return 1;
586 return 0;
587}
588
589
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700590static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800591{
592 const struct hostapd_hw_modes *mode = NULL, *modes;
593 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
594 const u8 *rate_ie;
595 int i, j, k;
596
597 if (bss->freq == 0)
598 return 1; /* Cannot do matching without knowing band */
599
600 modes = wpa_s->hw.modes;
601 if (modes == NULL) {
602 /*
603 * The driver does not provide any additional information
604 * about the utilized hardware, so allow the connection attempt
605 * to continue.
606 */
607 return 1;
608 }
609
610 for (i = 0; i < wpa_s->hw.num_modes; i++) {
611 for (j = 0; j < modes[i].num_channels; j++) {
612 int freq = modes[i].channels[j].freq;
613 if (freq == bss->freq) {
614 if (mode &&
615 mode->mode == HOSTAPD_MODE_IEEE80211G)
616 break; /* do not allow 802.11b replace
617 * 802.11g */
618 mode = &modes[i];
619 break;
620 }
621 }
622 }
623
624 if (mode == NULL)
625 return 0;
626
627 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700628 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800629 if (rate_ie == NULL)
630 continue;
631
632 for (j = 2; j < rate_ie[1] + 2; j++) {
633 int flagged = !!(rate_ie[j] & 0x80);
634 int r = (rate_ie[j] & 0x7f) * 5;
635
636 /*
637 * IEEE Std 802.11n-2009 7.3.2.2:
638 * The new BSS Membership selector value is encoded
639 * like a legacy basic rate, but it is not a rate and
640 * only indicates if the BSS members are required to
641 * support the mandatory features of Clause 20 [HT PHY]
642 * in order to join the BSS.
643 */
644 if (flagged && ((rate_ie[j] & 0x7f) ==
645 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
646 if (!ht_supported(mode)) {
647 wpa_dbg(wpa_s, MSG_DEBUG,
648 " hardware does not support "
649 "HT PHY");
650 return 0;
651 }
652 continue;
653 }
654
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700655 /* There's also a VHT selector for 802.11ac */
656 if (flagged && ((rate_ie[j] & 0x7f) ==
657 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
658 if (!vht_supported(mode)) {
659 wpa_dbg(wpa_s, MSG_DEBUG,
660 " hardware does not support "
661 "VHT PHY");
662 return 0;
663 }
664 continue;
665 }
666
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800667 if (!flagged)
668 continue;
669
670 /* check for legacy basic rates */
671 for (k = 0; k < mode->num_rates; k++) {
672 if (mode->rates[k] == r)
673 break;
674 }
675 if (k == mode->num_rates) {
676 /*
677 * IEEE Std 802.11-2007 7.3.2.2 demands that in
678 * order to join a BSS all required rates
679 * have to be supported by the hardware.
680 */
681 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
682 "not support required rate %d.%d Mbps",
683 r / 10, r % 10);
684 return 0;
685 }
686 }
687 }
688
689 return 1;
690}
691
692
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800693/*
694 * Test whether BSS is in an ESS.
695 * This is done differently in DMG (60 GHz) and non-DMG bands
696 */
697static int bss_is_ess(struct wpa_bss *bss)
698{
699 if (bss_is_dmg(bss)) {
700 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
701 IEEE80211_CAP_DMG_AP;
702 }
703
704 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
705 IEEE80211_CAP_ESS);
706}
707
708
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800709static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
710{
711 size_t i;
712
713 for (i = 0; i < ETH_ALEN; i++) {
714 if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
715 return 0;
716 }
717 return 1;
718}
719
720
721static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
722{
723 size_t i;
724
725 for (i = 0; i < num; i++) {
726 const u8 *a = list + i * ETH_ALEN * 2;
727 const u8 *m = a + ETH_ALEN;
728
729 if (match_mac_mask(a, addr, m))
730 return 1;
731 }
732 return 0;
733}
734
735
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700736static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700737 int i, struct wpa_bss *bss,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800738 struct wpa_ssid *group,
739 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700740{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700741 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700742 int wpa;
743 struct wpa_blacklist *e;
744 const u8 *ie;
745 struct wpa_ssid *ssid;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800746 int osen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700747
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700748 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700749 wpa_ie_len = ie ? ie[1] : 0;
750
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700751 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700752 rsn_ie_len = ie ? ie[1] : 0;
753
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800754 ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
755 osen = ie != NULL;
756
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700757 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800758 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700759 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700760 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
Dmitry Shmidt96571392013-10-14 12:54:46 -0700761 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
762 (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
763 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800764 " p2p" : "",
765 osen ? " osen=1" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700766
767 e = wpa_blacklist_get(wpa_s, bss->bssid);
768 if (e) {
769 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700770 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771 /*
772 * When only a single network is enabled, we can
773 * trigger blacklisting on the first failure. This
774 * should not be done with multiple enabled networks to
775 * avoid getting forced to move into a worse ESS on
776 * single error if there are no other BSSes of the
777 * current ESS.
778 */
779 limit = 0;
780 }
781 if (e->count > limit) {
782 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
783 "(count=%d limit=%d)", e->count, limit);
784 return NULL;
785 }
786 }
787
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700788 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700789 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
790 return NULL;
791 }
792
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800793 if (disallowed_bssid(wpa_s, bss->bssid)) {
794 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
795 return NULL;
796 }
797
798 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
799 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
800 return NULL;
801 }
802
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700803 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
804
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800805 for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700806 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700807 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808
Dmitry Shmidt04949592012-07-19 12:16:46 -0700809 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700810 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
811 continue;
812 }
813
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700814 res = wpas_temp_disabled(wpa_s, ssid);
815 if (res > 0) {
816 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
817 "temporarily for %d second(s)", res);
818 continue;
819 }
820
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700821#ifdef CONFIG_WPS
822 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
823 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
824 "(WPS)");
825 continue;
826 }
827
828 if (wpa && ssid->ssid_len == 0 &&
829 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
830 check_ssid = 0;
831
832 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
833 /* Only allow wildcard SSID match if an AP
834 * advertises active WPS operation that matches
835 * with our mode. */
836 check_ssid = 1;
837 if (ssid->ssid_len == 0 &&
838 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
839 check_ssid = 0;
840 }
841#endif /* CONFIG_WPS */
842
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800843 if (ssid->bssid_set && ssid->ssid_len == 0 &&
844 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
845 check_ssid = 0;
846
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700848 (bss->ssid_len != ssid->ssid_len ||
849 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700850 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
851 continue;
852 }
853
854 if (ssid->bssid_set &&
855 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
856 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
857 continue;
858 }
859
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800860 /* check blacklist */
861 if (ssid->num_bssid_blacklist &&
862 addr_in_list(bss->bssid, ssid->bssid_blacklist,
863 ssid->num_bssid_blacklist)) {
864 wpa_dbg(wpa_s, MSG_DEBUG,
865 " skip - BSSID blacklisted");
866 continue;
867 }
868
869 /* if there is a whitelist, only accept those APs */
870 if (ssid->num_bssid_whitelist &&
871 !addr_in_list(bss->bssid, ssid->bssid_whitelist,
872 ssid->num_bssid_whitelist)) {
873 wpa_dbg(wpa_s, MSG_DEBUG,
874 " skip - BSSID not in whitelist");
875 continue;
876 }
877
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700878 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
879 continue;
880
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800881 if (!osen && !wpa &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700882 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
883 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
884 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
885 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
886 "not allowed");
887 continue;
888 }
889
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700890 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
891 has_wep_key(ssid)) {
892 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
893 continue;
894 }
895
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800896 if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
897 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
898 "not allowed");
899 continue;
900 }
901
Jouni Malinen75ecf522011-06-27 15:19:46 -0700902 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700903 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
904 "mismatch");
905 continue;
906 }
907
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800908 if (!bss_is_ess(bss)) {
909 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700910 continue;
911 }
912
913 if (!freq_allowed(ssid->freq_list, bss->freq)) {
914 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
915 "allowed");
916 continue;
917 }
918
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800919 if (!rate_match(wpa_s, bss)) {
920 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
921 "not match");
922 continue;
923 }
924
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700925#ifdef CONFIG_P2P
Dmitry Shmidt96571392013-10-14 12:54:46 -0700926 if (ssid->p2p_group &&
927 !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
928 !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
929 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
930 continue;
931 }
932
Dmitry Shmidt54605472013-11-08 11:10:19 -0800933 if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
934 struct wpabuf *p2p_ie;
935 u8 dev_addr[ETH_ALEN];
936
937 ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
938 if (ie == NULL) {
939 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
940 continue;
941 }
942 p2p_ie = wpa_bss_get_vendor_ie_multi(
943 bss, P2P_IE_VENDOR_TYPE);
944 if (p2p_ie == NULL) {
945 wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
946 continue;
947 }
948
949 if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
950 || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
951 ETH_ALEN) != 0) {
952 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
953 wpabuf_free(p2p_ie);
954 continue;
955 }
956 wpabuf_free(p2p_ie);
957 }
958
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700959 /*
960 * TODO: skip the AP if its P2P IE has Group Formation
961 * bit set in the P2P Group Capability Bitmap and we
962 * are not in Group Formation with that device.
963 */
964#endif /* CONFIG_P2P */
965
966 /* Matching configuration found */
967 return ssid;
968 }
969
970 /* No matching configuration found */
971 return NULL;
972}
973
974
975static struct wpa_bss *
976wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700977 struct wpa_ssid *group,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800978 struct wpa_ssid **selected_ssid,
979 int only_first_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700981 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700982
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800983 if (only_first_ssid)
984 wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
985 group->id);
986 else
987 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
988 group->priority);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700989
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700990 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
991 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800992 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
993 only_first_ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700994 if (!*selected_ssid)
995 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700996 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
997 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700998 MAC2STR(bss->bssid),
999 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1000 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001001 }
1002
1003 return NULL;
1004}
1005
1006
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001007struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
1008 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001009{
1010 struct wpa_bss *selected = NULL;
1011 int prio;
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001012 struct wpa_ssid *next_ssid = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001013
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001014 if (wpa_s->last_scan_res == NULL ||
1015 wpa_s->last_scan_res_used == 0)
1016 return NULL; /* no scan results from last update */
1017
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001018 if (wpa_s->next_ssid) {
1019 struct wpa_ssid *ssid;
1020
1021 /* check that next_ssid is still valid */
1022 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1023 if (ssid == wpa_s->next_ssid)
1024 break;
1025 }
1026 next_ssid = ssid;
1027 wpa_s->next_ssid = NULL;
1028 }
1029
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001030 while (selected == NULL) {
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001031 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1032 if (next_ssid && next_ssid->priority ==
1033 wpa_s->conf->pssid[prio]->priority) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001034 selected = wpa_supplicant_select_bss(
Dmitry Shmidt4582d2a2014-02-28 11:14:23 -08001035 wpa_s, next_ssid, selected_ssid, 1);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001036 if (selected)
1037 break;
1038 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001039 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001040 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001041 selected_ssid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001042 if (selected)
1043 break;
1044 }
1045
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001046 if (selected == NULL && wpa_s->blacklist &&
1047 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001048 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
1049 "blacklist and try again");
1050 wpa_blacklist_clear(wpa_s);
1051 wpa_s->blacklist_cleared++;
1052 } else if (selected == NULL)
1053 break;
1054 }
1055
1056 return selected;
1057}
1058
1059
1060static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
1061 int timeout_sec, int timeout_usec)
1062{
Dmitry Shmidt04949592012-07-19 12:16:46 -07001063 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001064 /*
1065 * No networks are enabled; short-circuit request so
1066 * we don't wait timeout seconds before transitioning
1067 * to INACTIVE state.
1068 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001069 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
1070 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001071 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
1072 return;
1073 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001074
1075 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
1077}
1078
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001079
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001080int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001081 struct wpa_bss *selected,
1082 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083{
1084 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
1085 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
1086 "PBC session overlap");
1087#ifdef CONFIG_P2P
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001088 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
1089 wpa_s->p2p_in_provisioning) {
1090 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
1091 wpa_s, NULL);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001092 return -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001093 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001094#endif /* CONFIG_P2P */
1095
1096#ifdef CONFIG_WPS
1097 wpas_wps_cancel(wpa_s);
1098#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001099 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001100 }
1101
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001102 wpa_msg(wpa_s, MSG_DEBUG,
1103 "Considering connect request: reassociate: %d selected: "
1104 MACSTR " bssid: " MACSTR " pending: " MACSTR
1105 " wpa_state: %s ssid=%p current_ssid=%p",
1106 wpa_s->reassociate, MAC2STR(selected->bssid),
1107 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
1108 wpa_supplicant_state_txt(wpa_s->wpa_state),
1109 ssid, wpa_s->current_ssid);
1110
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111 /*
1112 * Do not trigger new association unless the BSSID has changed or if
1113 * reassociation is requested. If we are in process of associating with
1114 * the selected BSSID, do not trigger new attempt.
1115 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001116 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001117 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
1118 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
1119 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001120 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
1121 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
1122 0) ||
1123 (is_zero_ether_addr(wpa_s->pending_bssid) &&
1124 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001125 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1126 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001127 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001128 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001129 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1130 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001131 wpa_supplicant_associate(wpa_s, selected, ssid);
1132 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001133 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1134 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001135 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001136
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001137 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001138}
1139
1140
1141static struct wpa_ssid *
1142wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1143{
1144 int prio;
1145 struct wpa_ssid *ssid;
1146
1147 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1148 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1149 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001150 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001151 continue;
1152 if (ssid->mode == IEEE80211_MODE_IBSS ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001153 ssid->mode == IEEE80211_MODE_AP ||
1154 ssid->mode == IEEE80211_MODE_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001155 return ssid;
1156 }
1157 }
1158 return NULL;
1159}
1160
1161
1162/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1163 * on BSS added and BSS changed events */
1164static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001165 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001166{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001167 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001168
1169 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1170 return;
1171
Jouni Malinen87fd2792011-05-16 18:35:42 +03001172 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001173 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001174
Jouni Malinen87fd2792011-05-16 18:35:42 +03001175 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001176 if (ssid == NULL)
1177 continue;
1178
Jouni Malinen87fd2792011-05-16 18:35:42 +03001179 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001180 if (rsn == NULL)
1181 continue;
1182
Jouni Malinen87fd2792011-05-16 18:35:42 +03001183 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184 }
1185
1186}
1187
1188
1189static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1190 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001191 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001192{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001193 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001194 int min_diff;
1195
1196 if (wpa_s->reassociate)
1197 return 1; /* explicit request to reassociate */
1198 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1199 return 1; /* we are not associated; continue */
1200 if (wpa_s->current_ssid == NULL)
1201 return 1; /* unknown current SSID */
1202 if (wpa_s->current_ssid != ssid)
1203 return 1; /* different network block */
1204
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001205 if (wpas_driver_bss_selection(wpa_s))
1206 return 0; /* Driver-based roaming */
1207
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001208 if (wpa_s->current_ssid->ssid)
1209 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1210 wpa_s->current_ssid->ssid,
1211 wpa_s->current_ssid->ssid_len);
1212 if (!current_bss)
1213 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001214
1215 if (!current_bss)
1216 return 1; /* current BSS not seen in scan results */
1217
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001218 if (current_bss == selected)
1219 return 0;
1220
1221 if (selected->last_update_idx > current_bss->last_update_idx)
1222 return 1; /* current BSS not seen in the last scan */
1223
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001224#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001225 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001226 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
1227 " level=%d snr=%d est_throughput=%u",
1228 MAC2STR(current_bss->bssid), current_bss->level,
1229 current_bss->snr, current_bss->est_throughput);
1230 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
1231 " level=%d snr=%d est_throughput=%u",
1232 MAC2STR(selected->bssid), selected->level,
1233 selected->snr, selected->est_throughput);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001234
1235 if (wpa_s->current_ssid->bssid_set &&
1236 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1237 0) {
1238 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1239 "has preferred BSSID");
1240 return 1;
1241 }
1242
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001243 if (selected->est_throughput > current_bss->est_throughput + 5000) {
1244 wpa_dbg(wpa_s, MSG_DEBUG,
1245 "Allow reassociation - selected BSS has better estimated throughput");
1246 return 1;
1247 }
1248
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001249 if (current_bss->level < 0 && current_bss->level > selected->level) {
1250 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1251 "signal level");
1252 return 0;
1253 }
1254
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001255 min_diff = 2;
1256 if (current_bss->level < 0) {
1257 if (current_bss->level < -85)
1258 min_diff = 1;
1259 else if (current_bss->level < -80)
1260 min_diff = 2;
1261 else if (current_bss->level < -75)
1262 min_diff = 3;
1263 else if (current_bss->level < -70)
1264 min_diff = 4;
1265 else
1266 min_diff = 5;
1267 }
1268 if (abs(current_bss->level - selected->level) < min_diff) {
1269 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1270 "in signal level");
1271 return 0;
1272 }
1273
1274 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001275#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001276 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001277#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001278}
1279
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001280
Jouni Malinen89ca7022012-09-14 13:03:12 -07001281/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001282 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001283static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001284 union wpa_event_data *data,
1285 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001286{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001287 struct wpa_scan_results *scan_res = NULL;
1288 int ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001289 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001290#ifndef CONFIG_NO_RANDOM_POOL
1291 size_t i, num;
1292#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001293
1294#ifdef CONFIG_AP
1295 if (wpa_s->ap_iface)
1296 ap = 1;
1297#endif /* CONFIG_AP */
1298
1299 wpa_supplicant_notify_scanning(wpa_s, 0);
1300
1301 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1302 data ? &data->scan_info :
1303 NULL, 1);
1304 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001305 if (wpa_s->conf->ap_scan == 2 || ap ||
1306 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001307 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001308 if (!own_request)
1309 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001310 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1311 "scanning again");
1312 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001313 ret = -1;
1314 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315 }
1316
1317#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001318 num = scan_res->num;
1319 if (num > 10)
1320 num = 10;
1321 for (i = 0; i < num; i++) {
1322 u8 buf[5];
1323 struct wpa_scan_res *res = scan_res->res[i];
1324 buf[0] = res->bssid[5];
1325 buf[1] = res->qual & 0xff;
1326 buf[2] = res->noise & 0xff;
1327 buf[3] = res->level & 0xff;
1328 buf[4] = res->tsf & 0xff;
1329 random_add_randomness(buf, sizeof(buf));
1330 }
1331#endif /* CONFIG_NO_RANDOM_POOL */
1332
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001333 if (own_request && wpa_s->scan_res_handler &&
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001334 (wpa_s->own_scan_running || !wpa_s->radio->external_scan_running)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001335 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1336 struct wpa_scan_results *scan_res);
1337
1338 scan_res_handler = wpa_s->scan_res_handler;
1339 wpa_s->scan_res_handler = NULL;
1340 scan_res_handler(wpa_s, scan_res);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001341 ret = -2;
1342 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001343 }
1344
1345 if (ap) {
1346 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1347#ifdef CONFIG_AP
1348 if (wpa_s->ap_iface->scan_cb)
1349 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1350#endif /* CONFIG_AP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001351 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001352 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001353
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001354 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001355 wpa_s->own_scan_running, wpa_s->radio->external_scan_running);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001356 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
1357 wpa_s->manual_scan_use_id && wpa_s->own_scan_running) {
1358 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
1359 wpa_s->manual_scan_id);
1360 wpa_s->manual_scan_use_id = 0;
1361 } else {
1362 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1363 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001364 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001365
1366 wpas_notify_scan_done(wpa_s, 1);
1367
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001368 if (!wpa_s->own_scan_running && wpa_s->radio->external_scan_running) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001369 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 -07001370 wpa_scan_results_free(scan_res);
1371 return 0;
1372 }
1373
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001374 if (wnm_scan_process(wpa_s, 1) > 0)
1375 goto scan_work_done;
1376
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001377 if (sme_proc_obss_scan(wpa_s) > 0)
1378 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001379
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001380 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
1381 goto scan_work_done;
1382
1383 if (autoscan_notify_scan(wpa_s, scan_res))
1384 goto scan_work_done;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001385
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001386 if (wpa_s->disconnected) {
1387 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001388 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001389 }
1390
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001391 if (!wpas_driver_bss_selection(wpa_s) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001392 bgscan_notify_scan(wpa_s, scan_res) == 1)
1393 goto scan_work_done;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001394
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001395 wpas_wps_update_ap_info(wpa_s, scan_res);
1396
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001397 wpa_scan_results_free(scan_res);
1398
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001399 if (wpa_s->scan_work) {
1400 struct wpa_radio_work *work = wpa_s->scan_work;
1401 wpa_s->scan_work = NULL;
1402 radio_work_done(work);
1403 }
1404
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001405 return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001406
1407scan_work_done:
1408 wpa_scan_results_free(scan_res);
1409 if (wpa_s->scan_work) {
1410 struct wpa_radio_work *work = wpa_s->scan_work;
1411 wpa_s->scan_work = NULL;
1412 radio_work_done(work);
1413 }
1414 return ret;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001415}
1416
1417
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001418static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001419 int new_scan, int own_request)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001420{
1421 struct wpa_bss *selected;
1422 struct wpa_ssid *ssid = NULL;
1423
1424 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001425
1426 if (selected) {
1427 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001428 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001429 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001430 if (new_scan)
1431 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001432 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001433 }
1434
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001435 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001436 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001437 return -1;
1438 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001439 if (new_scan)
1440 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001441 /*
1442 * Do not notify other virtual radios of scan results since we do not
1443 * want them to start other associations at the same time.
1444 */
1445 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001446 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001447#ifdef CONFIG_MESH
1448 if (wpa_s->ifmsh) {
1449 wpa_msg(wpa_s, MSG_INFO,
1450 "Avoiding join because we already joined a mesh group");
1451 return 0;
1452 }
1453#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001454 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1455 ssid = wpa_supplicant_pick_new_network(wpa_s);
1456 if (ssid) {
1457 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1458 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001459 if (new_scan)
1460 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001461 } else if (own_request) {
1462 /*
1463 * No SSID found. If SCAN results are as a result of
1464 * own scan request and not due to a scan request on
1465 * another shared interface, try another scan.
1466 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001467 int timeout_sec = wpa_s->scan_interval;
1468 int timeout_usec = 0;
1469#ifdef CONFIG_P2P
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001470 int res;
1471
1472 res = wpas_p2p_scan_no_go_seen(wpa_s);
1473 if (res == 2)
1474 return 2;
1475 if (res == 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001476 return 0;
1477
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001478 if (wpa_s->p2p_in_provisioning ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07001479 wpa_s->show_group_started ||
1480 wpa_s->p2p_in_invitation) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001481 /*
1482 * Use shorter wait during P2P Provisioning
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -08001483 * state and during P2P join-a-group operation
1484 * to speed up group formation.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001485 */
1486 timeout_sec = 0;
1487 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001488 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1489 timeout_usec);
1490 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001491 }
1492#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001493#ifdef CONFIG_INTERWORKING
1494 if (wpa_s->conf->auto_interworking &&
1495 wpa_s->conf->interworking &&
1496 wpa_s->conf->cred) {
1497 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1498 "start ANQP fetch since no matching "
1499 "networks found");
1500 wpa_s->network_select = 1;
1501 wpa_s->auto_network_select = 1;
1502 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001503 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001504 }
1505#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001506#ifdef CONFIG_WPS
1507 if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
1508 wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
1509 timeout_sec = 0;
1510 timeout_usec = 500000;
1511 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1512 timeout_usec);
1513 return 0;
1514 }
1515#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001516 if (wpa_supplicant_req_sched_scan(wpa_s))
1517 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1518 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001519 }
1520 }
1521 return 0;
1522}
1523
1524
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001525static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1526 union wpa_event_data *data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001527{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001528 struct wpa_supplicant *ifs;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001529 int res;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001530
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001531 res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
1532 if (res == 2) {
1533 /*
1534 * Interface may have been removed, so must not dereference
1535 * wpa_s after this.
1536 */
1537 return 1;
1538 }
1539 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001540 /*
1541 * If no scan results could be fetched, then no need to
1542 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001543 * this scan. Similarly, if scan results started a new operation on this
1544 * interface, do not notify other interfaces to avoid concurrent
1545 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001546 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001547 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001548 }
1549
1550 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001551 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001552 * so, they get updated with this same scan info.
1553 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08001554 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
1555 radio_list) {
1556 if (ifs != wpa_s) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001557 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1558 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001559 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001560 }
1561 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001562
1563 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001564}
1565
1566#endif /* CONFIG_NO_SCAN_PROCESSING */
1567
1568
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001569int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1570{
1571#ifdef CONFIG_NO_SCAN_PROCESSING
1572 return -1;
1573#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001574 struct os_reltime now;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001575
1576 if (wpa_s->last_scan_res_used <= 0)
1577 return -1;
1578
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001579 os_get_reltime(&now);
1580 if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001581 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1582 return -1;
1583 }
1584
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001585 return wpas_select_network_from_last_scan(wpa_s, 0, 1);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001586#endif /* CONFIG_NO_SCAN_PROCESSING */
1587}
1588
Dmitry Shmidt04949592012-07-19 12:16:46 -07001589#ifdef CONFIG_WNM
1590
1591static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1592{
1593 struct wpa_supplicant *wpa_s = eloop_ctx;
1594
1595 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1596 return;
1597
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001598 if (!wpa_s->no_keep_alive) {
1599 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1600 MAC2STR(wpa_s->bssid));
1601 /* TODO: could skip this if normal data traffic has been sent */
1602 /* TODO: Consider using some more appropriate data frame for
1603 * this */
1604 if (wpa_s->l2)
1605 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1606 (u8 *) "", 0);
1607 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001608
1609#ifdef CONFIG_SME
1610 if (wpa_s->sme.bss_max_idle_period) {
1611 unsigned int msec;
1612 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1613 if (msec > 100)
1614 msec -= 100;
1615 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1616 wnm_bss_keep_alive, wpa_s, NULL);
1617 }
1618#endif /* CONFIG_SME */
1619}
1620
1621
1622static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1623 const u8 *ies, size_t ies_len)
1624{
1625 struct ieee802_11_elems elems;
1626
1627 if (ies == NULL)
1628 return;
1629
1630 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1631 return;
1632
1633#ifdef CONFIG_SME
1634 if (elems.bss_max_idle_period) {
1635 unsigned int msec;
1636 wpa_s->sme.bss_max_idle_period =
1637 WPA_GET_LE16(elems.bss_max_idle_period);
1638 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1639 "TU)%s", wpa_s->sme.bss_max_idle_period,
1640 (elems.bss_max_idle_period[2] & 0x01) ?
1641 " (protected keep-live required)" : "");
1642 if (wpa_s->sme.bss_max_idle_period == 0)
1643 wpa_s->sme.bss_max_idle_period = 1;
1644 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1645 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1646 /* msec times 1000 */
1647 msec = wpa_s->sme.bss_max_idle_period * 1024;
1648 if (msec > 100)
1649 msec -= 100;
1650 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1651 wnm_bss_keep_alive, wpa_s,
1652 NULL);
1653 }
1654 }
1655#endif /* CONFIG_SME */
1656}
1657
1658#endif /* CONFIG_WNM */
1659
1660
1661void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1662{
1663#ifdef CONFIG_WNM
1664 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1665#endif /* CONFIG_WNM */
1666}
1667
1668
Dmitry Shmidt051af732013-10-22 13:52:46 -07001669#ifdef CONFIG_INTERWORKING
1670
1671static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
1672 size_t len)
1673{
1674 int res;
1675
1676 wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
1677 res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
1678 if (res) {
1679 wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
1680 }
1681
1682 return res;
1683}
1684
1685
1686static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
1687 const u8 *ies, size_t ies_len)
1688{
1689 struct ieee802_11_elems elems;
1690
1691 if (ies == NULL)
1692 return;
1693
1694 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1695 return;
1696
1697 if (elems.qos_map_set) {
1698 wpas_qos_map_set(wpa_s, elems.qos_map_set,
1699 elems.qos_map_set_len);
1700 }
1701}
1702
1703#endif /* CONFIG_INTERWORKING */
1704
1705
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001706static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1707 union wpa_event_data *data)
1708{
1709 int l, len, found = 0, wpa_found, rsn_found;
1710 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001711#ifdef CONFIG_IEEE80211R
1712 u8 bssid[ETH_ALEN];
1713#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001714
1715 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1716 if (data->assoc_info.req_ies)
1717 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1718 data->assoc_info.req_ies_len);
1719 if (data->assoc_info.resp_ies) {
1720 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1721 data->assoc_info.resp_ies_len);
1722#ifdef CONFIG_TDLS
1723 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1724 data->assoc_info.resp_ies_len);
1725#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001726#ifdef CONFIG_WNM
1727 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1728 data->assoc_info.resp_ies_len);
1729#endif /* CONFIG_WNM */
Dmitry Shmidt051af732013-10-22 13:52:46 -07001730#ifdef CONFIG_INTERWORKING
1731 interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1732 data->assoc_info.resp_ies_len);
1733#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001734 }
1735 if (data->assoc_info.beacon_ies)
1736 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1737 data->assoc_info.beacon_ies,
1738 data->assoc_info.beacon_ies_len);
1739 if (data->assoc_info.freq)
1740 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1741 data->assoc_info.freq);
1742
1743 p = data->assoc_info.req_ies;
1744 l = data->assoc_info.req_ies_len;
1745
1746 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1747 while (p && l >= 2) {
1748 len = p[1] + 2;
1749 if (len > l) {
1750 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1751 p, l);
1752 break;
1753 }
1754 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1755 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1756 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1757 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1758 break;
1759 found = 1;
1760 wpa_find_assoc_pmkid(wpa_s);
1761 break;
1762 }
1763 l -= len;
1764 p += len;
1765 }
1766 if (!found && data->assoc_info.req_ies)
1767 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1768
1769#ifdef CONFIG_IEEE80211R
1770#ifdef CONFIG_SME
1771 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001772 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1773 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1774 data->assoc_info.resp_ies,
1775 data->assoc_info.resp_ies_len,
1776 bssid) < 0) {
1777 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1778 "Reassociation Response failed");
1779 wpa_supplicant_deauthenticate(
1780 wpa_s, WLAN_REASON_INVALID_IE);
1781 return -1;
1782 }
1783 }
1784
1785 p = data->assoc_info.resp_ies;
1786 l = data->assoc_info.resp_ies_len;
1787
1788#ifdef CONFIG_WPS_STRICT
1789 if (p && wpa_s->current_ssid &&
1790 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1791 struct wpabuf *wps;
1792 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1793 if (wps == NULL) {
1794 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1795 "include WPS IE in (Re)Association Response");
1796 return -1;
1797 }
1798
1799 if (wps_validate_assoc_resp(wps) < 0) {
1800 wpabuf_free(wps);
1801 wpa_supplicant_deauthenticate(
1802 wpa_s, WLAN_REASON_INVALID_IE);
1803 return -1;
1804 }
1805 wpabuf_free(wps);
1806 }
1807#endif /* CONFIG_WPS_STRICT */
1808
1809 /* Go through the IEs and make a copy of the MDIE, if present. */
1810 while (p && l >= 2) {
1811 len = p[1] + 2;
1812 if (len > l) {
1813 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1814 p, l);
1815 break;
1816 }
1817 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1818 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1819 wpa_s->sme.ft_used = 1;
1820 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1821 MOBILITY_DOMAIN_ID_LEN);
1822 break;
1823 }
1824 l -= len;
1825 p += len;
1826 }
1827#endif /* CONFIG_SME */
1828
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001829 /* Process FT when SME is in the driver */
1830 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1831 wpa_ft_is_completed(wpa_s->wpa)) {
1832 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1833 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1834 data->assoc_info.resp_ies,
1835 data->assoc_info.resp_ies_len,
1836 bssid) < 0) {
1837 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1838 "Reassociation Response failed");
1839 wpa_supplicant_deauthenticate(
1840 wpa_s, WLAN_REASON_INVALID_IE);
1841 return -1;
1842 }
1843 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1844 }
1845
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001846 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1847 data->assoc_info.resp_ies_len);
1848#endif /* CONFIG_IEEE80211R */
1849
1850 /* WPA/RSN IE from Beacon/ProbeResp */
1851 p = data->assoc_info.beacon_ies;
1852 l = data->assoc_info.beacon_ies_len;
1853
1854 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1855 */
1856 wpa_found = rsn_found = 0;
1857 while (p && l >= 2) {
1858 len = p[1] + 2;
1859 if (len > l) {
1860 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1861 p, l);
1862 break;
1863 }
1864 if (!wpa_found &&
1865 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1866 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1867 wpa_found = 1;
1868 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1869 }
1870
1871 if (!rsn_found &&
1872 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1873 rsn_found = 1;
1874 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1875 }
1876
1877 l -= len;
1878 p += len;
1879 }
1880
1881 if (!wpa_found && data->assoc_info.beacon_ies)
1882 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1883 if (!rsn_found && data->assoc_info.beacon_ies)
1884 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1885 if (wpa_found || rsn_found)
1886 wpa_s->ap_ies_from_associnfo = 1;
1887
Jouni Malinen87fd2792011-05-16 18:35:42 +03001888 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1889 wpa_s->assoc_freq != data->assoc_info.freq) {
1890 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1891 "%u to %u MHz",
1892 wpa_s->assoc_freq, data->assoc_info.freq);
1893 wpa_supplicant_update_scan_results(wpa_s);
1894 }
1895
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001896 wpa_s->assoc_freq = data->assoc_info.freq;
1897
1898 return 0;
1899}
1900
1901
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001902static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1903{
1904 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1905
1906 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1907 return -1;
1908
1909 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1910 return 0;
1911
1912 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1913 WPA_IE_VENDOR_TYPE);
1914 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1915
1916 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1917 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1918 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1919 bss_rsn ? 2 + bss_rsn[1] : 0))
1920 return -1;
1921
1922 return 0;
1923}
1924
1925
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001926static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1927 union wpa_event_data *data)
1928{
1929 u8 bssid[ETH_ALEN];
1930 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001931
1932#ifdef CONFIG_AP
1933 if (wpa_s->ap_iface) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07001934 if (!data)
1935 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001936 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1937 data->assoc_info.addr,
1938 data->assoc_info.req_ies,
1939 data->assoc_info.req_ies_len,
1940 data->assoc_info.reassoc);
1941 return;
1942 }
1943#endif /* CONFIG_AP */
1944
1945 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1946 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1947 return;
1948
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001949 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1950 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001951 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001952 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1953 return;
1954 }
1955
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001956 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001957 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001958 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1959 MACSTR, MAC2STR(bssid));
1960 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001961 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1962 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001963 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001964
1965 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1966 wpa_clear_keys(wpa_s, bssid);
1967 }
1968 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001969 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001970 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1971 return;
1972 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001973
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001974#ifdef ANDROID
1975 if (wpa_s->conf->ap_scan == 1) {
1976#else
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001977 if (wpa_s->conf->ap_scan == 1 &&
1978 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001979#endif
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001980 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1981 wpa_msg(wpa_s, MSG_WARNING,
1982 "WPA/RSN IEs not updated");
1983 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001984 }
1985
1986#ifdef CONFIG_SME
1987 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1988 wpa_s->sme.prev_bssid_set = 1;
Dmitry Shmidt0c08fdc2014-06-20 10:16:40 -07001989 wpa_s->sme.last_unprot_disconnect.sec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001990#endif /* CONFIG_SME */
1991
1992 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1993 if (wpa_s->current_ssid) {
1994 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1995 * initialized before association, but for other modes,
1996 * initialize PC/SC here, if the current configuration needs
1997 * smartcard or SIM/USIM. */
1998 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1999 }
2000 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
2001 if (wpa_s->l2)
2002 l2_packet_notify_auth_start(wpa_s->l2);
2003
2004 /*
2005 * Set portEnabled first to FALSE in order to get EAP state machine out
2006 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
2007 * state machine may transit to AUTHENTICATING state based on obsolete
2008 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
2009 * AUTHENTICATED without ever giving chance to EAP state machine to
2010 * reset the state.
2011 */
2012 if (!ft_completed) {
2013 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
2014 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
2015 }
2016 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
2017 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
2018 /* 802.1X::portControl = Auto */
2019 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
2020 wpa_s->eapol_received = 0;
2021 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2022 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
2023 (wpa_s->current_ssid &&
2024 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt09f57ba2014-06-10 16:07:13 -07002025 if (wpa_s->current_ssid &&
2026 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002027 (wpa_s->drv_flags &
2028 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
2029 /*
2030 * Set the key after having received joined-IBSS event
2031 * from the driver.
2032 */
2033 wpa_supplicant_set_wpa_none_key(wpa_s,
2034 wpa_s->current_ssid);
2035 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002036 wpa_supplicant_cancel_auth_timeout(wpa_s);
2037 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2038 } else if (!ft_completed) {
2039 /* Timeout for receiving the first EAPOL packet */
2040 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
2041 }
2042 wpa_supplicant_cancel_scan(wpa_s);
2043
2044 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2045 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
2046 /*
2047 * We are done; the driver will take care of RSN 4-way
2048 * handshake.
2049 */
2050 wpa_supplicant_cancel_auth_timeout(wpa_s);
2051 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2052 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2053 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2054 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
2055 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2056 /*
2057 * The driver will take care of RSN 4-way handshake, so we need
2058 * to allow EAPOL supplicant to complete its work without
2059 * waiting for WPA supplicant.
2060 */
2061 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2062 } else if (ft_completed) {
2063 /*
2064 * FT protocol completed - make sure EAPOL state machine ends
2065 * up in authenticated.
2066 */
2067 wpa_supplicant_cancel_auth_timeout(wpa_s);
2068 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
2069 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
2070 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
2071 }
2072
Jouni Malinena05074c2012-12-21 21:35:35 +02002073 wpa_s->last_eapol_matches_bssid = 0;
2074
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002075 if (wpa_s->pending_eapol_rx) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002076 struct os_reltime now, age;
2077 os_get_reltime(&now);
2078 os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002079 if (age.sec == 0 && age.usec < 100000 &&
2080 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
2081 0) {
2082 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
2083 "frame that was received just before "
2084 "association notification");
2085 wpa_supplicant_rx_eapol(
2086 wpa_s, wpa_s->pending_eapol_rx_src,
2087 wpabuf_head(wpa_s->pending_eapol_rx),
2088 wpabuf_len(wpa_s->pending_eapol_rx));
2089 }
2090 wpabuf_free(wpa_s->pending_eapol_rx);
2091 wpa_s->pending_eapol_rx = NULL;
2092 }
2093
2094 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
2095 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07002096 wpa_s->current_ssid &&
2097 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002098 /* Set static WEP keys again */
2099 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
2100 }
2101
2102#ifdef CONFIG_IBSS_RSN
2103 if (wpa_s->current_ssid &&
2104 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
2105 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
2106 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
2107 wpa_s->ibss_rsn == NULL) {
2108 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
2109 if (!wpa_s->ibss_rsn) {
2110 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
2111 wpa_supplicant_deauthenticate(
2112 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2113 return;
2114 }
2115
2116 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
2117 }
2118#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002119
2120 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002121
2122 if (data) {
2123 wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
2124 data->assoc_info.resp_ies_len,
2125 &data->assoc_info.wmm_params);
2126
2127 if (wpa_s->reassoc_same_bss)
2128 wmm_ac_restore_tspecs(wpa_s);
2129 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002130}
2131
2132
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002133static int disconnect_reason_recoverable(u16 reason_code)
2134{
2135 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
2136 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
2137 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
2138}
2139
2140
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002141static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002142 u16 reason_code,
2143 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002144{
2145 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03002146
2147 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2148 /*
2149 * At least Host AP driver and a Prism3 card seemed to be
2150 * generating streams of disconnected events when configuring
2151 * IBSS for WPA-None. Ignore them for now.
2152 */
2153 return;
2154 }
2155
2156 bssid = wpa_s->bssid;
2157 if (is_zero_ether_addr(bssid))
2158 bssid = wpa_s->pending_bssid;
2159
2160 if (!is_zero_ether_addr(bssid) ||
2161 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2162 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
2163 " reason=%d%s",
2164 MAC2STR(bssid), reason_code,
2165 locally_generated ? " locally_generated=1" : "");
2166 }
2167}
2168
2169
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002170static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
2171 int locally_generated)
2172{
2173 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
2174 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
2175 return 0; /* Not in 4-way handshake with PSK */
2176
2177 /*
2178 * It looks like connection was lost while trying to go through PSK
2179 * 4-way handshake. Filter out known disconnection cases that are caused
2180 * by something else than PSK mismatch to avoid confusing reports.
2181 */
2182
2183 if (locally_generated) {
2184 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
2185 return 0;
2186 }
2187
2188 return 1;
2189}
2190
2191
Jouni Malinen2b89da82012-08-31 22:04:41 +03002192static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
2193 u16 reason_code,
2194 int locally_generated)
2195{
2196 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002197 int authenticating;
2198 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002199 struct wpa_bss *fast_reconnect = NULL;
2200 struct wpa_ssid *fast_reconnect_ssid = NULL;
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002201 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002202
2203 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2204 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2205
2206 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2207 /*
2208 * At least Host AP driver and a Prism3 card seemed to be
2209 * generating streams of disconnected events when configuring
2210 * IBSS for WPA-None. Ignore them for now.
2211 */
2212 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2213 "IBSS/WPA-None mode");
2214 return;
2215 }
2216
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002217 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002218 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2219 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002220 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2221 return; /* P2P group removed */
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002222 wpas_auth_failed(wpa_s, "WRONG_KEY");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002223 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002224 if (!wpa_s->disconnected &&
2225 (!wpa_s->auto_reconnect_disabled ||
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002226 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
2227 wpas_wps_searching(wpa_s))) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002228 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002229 "reconnect (wps=%d/%d wpa_state=%d)",
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002230 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002231 wpas_wps_searching(wpa_s),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002232 wpa_s->wpa_state);
2233 if (wpa_s->wpa_state == WPA_COMPLETED &&
2234 wpa_s->current_ssid &&
2235 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002236 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002237 disconnect_reason_recoverable(reason_code)) {
2238 /*
2239 * It looks like the AP has dropped association with
2240 * us, but could allow us to get back in. Try to
2241 * reconnect to the same BSS without full scan to save
2242 * time for some common cases.
2243 */
2244 fast_reconnect = wpa_s->current_bss;
2245 fast_reconnect_ssid = wpa_s->current_ssid;
2246 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002247 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002248 else
2249 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2250 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002251 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002252 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002253 "try to re-connect");
2254 wpa_s->reassociate = 0;
2255 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002256 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002257 }
2258 bssid = wpa_s->bssid;
2259 if (is_zero_ether_addr(bssid))
2260 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002261 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2262 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002263 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002264 if (locally_generated)
2265 wpa_s->disconnect_reason = -reason_code;
2266 else
2267 wpa_s->disconnect_reason = reason_code;
2268 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002269 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2270 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002271 wpa_clear_keys(wpa_s, wpa_s->bssid);
2272 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002273 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002274 wpa_supplicant_mark_disassoc(wpa_s);
2275
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002276 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002277 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002278 wpa_s->current_ssid = last_ssid;
2279 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002280
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002281 if (fast_reconnect &&
2282 !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
2283 !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
2284 !disallowed_ssid(wpa_s, fast_reconnect->ssid,
2285 fast_reconnect->ssid_len) &&
2286 !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002287#ifndef CONFIG_NO_SCAN_PROCESSING
2288 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2289 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2290 fast_reconnect_ssid) < 0) {
2291 /* Recover through full scan */
2292 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2293 }
2294#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002295 } else if (fast_reconnect) {
2296 /*
2297 * Could not reconnect to the same BSS due to network being
2298 * disabled. Use a new scan to match the alternative behavior
2299 * above, i.e., to continue automatic reconnection attempt in a
2300 * way that enforces disabled network rules.
2301 */
2302 wpa_supplicant_req_scan(wpa_s, 0, 100000);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002303 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002304}
2305
2306
2307#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002308void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002309{
2310 struct wpa_supplicant *wpa_s = eloop_ctx;
2311
2312 if (!wpa_s->pending_mic_error_report)
2313 return;
2314
2315 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2316 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2317 wpa_s->pending_mic_error_report = 0;
2318}
2319#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2320
2321
2322static void
2323wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2324 union wpa_event_data *data)
2325{
2326 int pairwise;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002327 struct os_reltime t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002328
2329 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2330 pairwise = (data && data->michael_mic_failure.unicast);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002331 os_get_reltime(&t);
2332 if ((wpa_s->last_michael_mic_error.sec &&
2333 !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002334 wpa_s->pending_mic_error_report) {
2335 if (wpa_s->pending_mic_error_report) {
2336 /*
2337 * Send the pending MIC error report immediately since
2338 * we are going to start countermeasures and AP better
2339 * do the same.
2340 */
2341 wpa_sm_key_request(wpa_s->wpa, 1,
2342 wpa_s->pending_mic_error_pairwise);
2343 }
2344
2345 /* Send the new MIC error report immediately since we are going
2346 * to start countermeasures and AP better do the same.
2347 */
2348 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2349
2350 /* initialize countermeasures */
2351 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002352
2353 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2354
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002355 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2356
2357 /*
2358 * Need to wait for completion of request frame. We do not get
2359 * any callback for the message completion, so just wait a
2360 * short while and hope for the best. */
2361 os_sleep(0, 10000);
2362
2363 wpa_drv_set_countermeasures(wpa_s, 1);
2364 wpa_supplicant_deauthenticate(wpa_s,
2365 WLAN_REASON_MICHAEL_MIC_FAILURE);
2366 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2367 wpa_s, NULL);
2368 eloop_register_timeout(60, 0,
2369 wpa_supplicant_stop_countermeasures,
2370 wpa_s, NULL);
2371 /* TODO: mark the AP rejected for 60 second. STA is
2372 * allowed to associate with another AP.. */
2373 } else {
2374#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2375 if (wpa_s->mic_errors_seen) {
2376 /*
2377 * Reduce the effectiveness of Michael MIC error
2378 * reports as a means for attacking against TKIP if
2379 * more than one MIC failure is noticed with the same
2380 * PTK. We delay the transmission of the reports by a
2381 * random time between 0 and 60 seconds in order to
2382 * force the attacker wait 60 seconds before getting
2383 * the information on whether a frame resulted in a MIC
2384 * failure.
2385 */
2386 u8 rval[4];
2387 int sec;
2388
2389 if (os_get_random(rval, sizeof(rval)) < 0)
2390 sec = os_random() % 60;
2391 else
2392 sec = WPA_GET_BE32(rval) % 60;
2393 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2394 "report %d seconds", sec);
2395 wpa_s->pending_mic_error_report = 1;
2396 wpa_s->pending_mic_error_pairwise = pairwise;
2397 eloop_cancel_timeout(
2398 wpa_supplicant_delayed_mic_error_report,
2399 wpa_s, NULL);
2400 eloop_register_timeout(
2401 sec, os_random() % 1000000,
2402 wpa_supplicant_delayed_mic_error_report,
2403 wpa_s, NULL);
2404 } else {
2405 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2406 }
2407#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2408 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2409#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2410 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002411 wpa_s->last_michael_mic_error = t;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002412 wpa_s->mic_errors_seen++;
2413}
2414
2415
2416#ifdef CONFIG_TERMINATE_ONLASTIF
2417static int any_interfaces(struct wpa_supplicant *head)
2418{
2419 struct wpa_supplicant *wpa_s;
2420
2421 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2422 if (!wpa_s->interface_removed)
2423 return 1;
2424 return 0;
2425}
2426#endif /* CONFIG_TERMINATE_ONLASTIF */
2427
2428
2429static void
2430wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2431 union wpa_event_data *data)
2432{
2433 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2434 return;
2435
2436 switch (data->interface_status.ievent) {
2437 case EVENT_INTERFACE_ADDED:
2438 if (!wpa_s->interface_removed)
2439 break;
2440 wpa_s->interface_removed = 0;
2441 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2442 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2443 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2444 "driver after interface was added");
2445 }
2446 break;
2447 case EVENT_INTERFACE_REMOVED:
2448 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2449 wpa_s->interface_removed = 1;
2450 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002451 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002452 l2_packet_deinit(wpa_s->l2);
2453 wpa_s->l2 = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002454#ifdef CONFIG_TERMINATE_ONLASTIF
2455 /* check if last interface */
2456 if (!any_interfaces(wpa_s->global->ifaces))
2457 eloop_terminate();
2458#endif /* CONFIG_TERMINATE_ONLASTIF */
2459 break;
2460 }
2461}
2462
2463
2464#ifdef CONFIG_PEERKEY
2465static void
2466wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2467 union wpa_event_data *data)
2468{
2469 if (data == NULL)
2470 return;
2471 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2472}
2473#endif /* CONFIG_PEERKEY */
2474
2475
2476#ifdef CONFIG_TDLS
2477static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2478 union wpa_event_data *data)
2479{
2480 if (data == NULL)
2481 return;
2482 switch (data->tdls.oper) {
2483 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002484 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2485 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2486 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2487 else
2488 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002489 break;
2490 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002491 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2492 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2493 data->tdls.reason_code);
2494 else
2495 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2496 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002497 break;
2498 }
2499}
2500#endif /* CONFIG_TDLS */
2501
2502
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002503#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002504static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2505 union wpa_event_data *data)
2506{
2507 if (data == NULL)
2508 return;
2509 switch (data->wnm.oper) {
2510 case WNM_OPER_SLEEP:
2511 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2512 "(action=%d, intval=%d)",
2513 data->wnm.sleep_action, data->wnm.sleep_intval);
2514 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002515 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002516 break;
2517 }
2518}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002519#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002520
2521
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002522#ifdef CONFIG_IEEE80211R
2523static void
2524wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2525 union wpa_event_data *data)
2526{
2527 if (data == NULL)
2528 return;
2529
2530 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2531 data->ft_ies.ies_len,
2532 data->ft_ies.ft_action,
2533 data->ft_ies.target_ap,
2534 data->ft_ies.ric_ies,
2535 data->ft_ies.ric_ies_len) < 0) {
2536 /* TODO: prevent MLME/driver from trying to associate? */
2537 }
2538}
2539#endif /* CONFIG_IEEE80211R */
2540
2541
2542#ifdef CONFIG_IBSS_RSN
2543static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2544 union wpa_event_data *data)
2545{
2546 struct wpa_ssid *ssid;
2547 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2548 return;
2549 if (data == NULL)
2550 return;
2551 ssid = wpa_s->current_ssid;
2552 if (ssid == NULL)
2553 return;
2554 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2555 return;
2556
2557 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2558}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002559
2560
2561static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2562 union wpa_event_data *data)
2563{
2564 struct wpa_ssid *ssid = wpa_s->current_ssid;
2565
2566 if (ssid == NULL)
2567 return;
2568
2569 /* check if the ssid is correctly configured as IBSS/RSN */
2570 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2571 return;
2572
2573 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2574 data->rx_mgmt.frame_len);
2575}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002576#endif /* CONFIG_IBSS_RSN */
2577
2578
2579#ifdef CONFIG_IEEE80211R
2580static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2581 size_t len)
2582{
2583 const u8 *sta_addr, *target_ap_addr;
2584 u16 status;
2585
2586 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2587 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2588 return; /* only SME case supported for now */
2589 if (len < 1 + 2 * ETH_ALEN + 2)
2590 return;
2591 if (data[0] != 2)
2592 return; /* Only FT Action Response is supported for now */
2593 sta_addr = data + 1;
2594 target_ap_addr = data + 1 + ETH_ALEN;
2595 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2596 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2597 MACSTR " TargetAP " MACSTR " status %u",
2598 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2599
2600 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2601 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2602 " in FT Action Response", MAC2STR(sta_addr));
2603 return;
2604 }
2605
2606 if (status) {
2607 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2608 "failure (status code %d)", status);
2609 /* TODO: report error to FT code(?) */
2610 return;
2611 }
2612
2613 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2614 len - (1 + 2 * ETH_ALEN + 2), 1,
2615 target_ap_addr, NULL, 0) < 0)
2616 return;
2617
2618#ifdef CONFIG_SME
2619 {
2620 struct wpa_bss *bss;
2621 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2622 if (bss)
2623 wpa_s->sme.freq = bss->freq;
2624 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2625 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2626 WLAN_AUTH_FT);
2627 }
2628#endif /* CONFIG_SME */
2629}
2630#endif /* CONFIG_IEEE80211R */
2631
2632
2633static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2634 struct unprot_deauth *e)
2635{
2636#ifdef CONFIG_IEEE80211W
2637 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2638 "dropped: " MACSTR " -> " MACSTR
2639 " (reason code %u)",
2640 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2641 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2642#endif /* CONFIG_IEEE80211W */
2643}
2644
2645
2646static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2647 struct unprot_disassoc *e)
2648{
2649#ifdef CONFIG_IEEE80211W
2650 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2651 "dropped: " MACSTR " -> " MACSTR
2652 " (reason code %u)",
2653 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2654 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2655#endif /* CONFIG_IEEE80211W */
2656}
2657
2658
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002659static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2660 u16 reason_code, int locally_generated,
2661 const u8 *ie, size_t ie_len, int deauth)
2662{
2663#ifdef CONFIG_AP
2664 if (wpa_s->ap_iface && addr) {
2665 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2666 return;
2667 }
2668
2669 if (wpa_s->ap_iface) {
2670 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2671 return;
2672 }
2673#endif /* CONFIG_AP */
2674
2675 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2676
Dmitry Shmidt344abd32014-01-14 13:17:00 -08002677 if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2678 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2679 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2680 eapol_sm_failed(wpa_s->eapol))) &&
2681 !wpa_s->eap_expected_failure))
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07002682 wpas_auth_failed(wpa_s, "AUTH_FAILED");
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002683
2684#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002685 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002686 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2687 locally_generated) > 0) {
2688 /*
2689 * The interface was removed, so cannot continue
2690 * processing any additional operations after this.
2691 */
2692 return;
2693 }
2694 }
2695#endif /* CONFIG_P2P */
2696
2697 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2698 locally_generated);
2699}
2700
2701
2702static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2703 struct disassoc_info *info)
2704{
2705 u16 reason_code = 0;
2706 int locally_generated = 0;
2707 const u8 *addr = NULL;
2708 const u8 *ie = NULL;
2709 size_t ie_len = 0;
2710
2711 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2712
2713 if (info) {
2714 addr = info->addr;
2715 ie = info->ie;
2716 ie_len = info->ie_len;
2717 reason_code = info->reason_code;
2718 locally_generated = info->locally_generated;
2719 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2720 locally_generated ? " (locally generated)" : "");
2721 if (addr)
2722 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2723 MAC2STR(addr));
2724 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2725 ie, ie_len);
2726 }
2727
2728#ifdef CONFIG_AP
2729 if (wpa_s->ap_iface && info && info->addr) {
2730 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2731 return;
2732 }
2733
2734 if (wpa_s->ap_iface) {
2735 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2736 return;
2737 }
2738#endif /* CONFIG_AP */
2739
2740#ifdef CONFIG_P2P
2741 if (info) {
2742 wpas_p2p_disassoc_notif(
2743 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2744 locally_generated);
2745 }
2746#endif /* CONFIG_P2P */
2747
2748 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2749 sme_event_disassoc(wpa_s, info);
2750
2751 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2752 ie, ie_len, 0);
2753}
2754
2755
2756static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2757 struct deauth_info *info)
2758{
2759 u16 reason_code = 0;
2760 int locally_generated = 0;
2761 const u8 *addr = NULL;
2762 const u8 *ie = NULL;
2763 size_t ie_len = 0;
2764
2765 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2766
2767 if (info) {
2768 addr = info->addr;
2769 ie = info->ie;
2770 ie_len = info->ie_len;
2771 reason_code = info->reason_code;
2772 locally_generated = info->locally_generated;
2773 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2774 reason_code,
2775 locally_generated ? " (locally generated)" : "");
2776 if (addr) {
2777 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2778 MAC2STR(addr));
2779 }
2780 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2781 ie, ie_len);
2782 }
2783
2784 wpa_reset_ft_completed(wpa_s->wpa);
2785
2786 wpas_event_disconnect(wpa_s, addr, reason_code,
2787 locally_generated, ie, ie_len, 1);
2788}
2789
2790
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002791static const char * reg_init_str(enum reg_change_initiator init)
2792{
2793 switch (init) {
2794 case REGDOM_SET_BY_CORE:
2795 return "CORE";
2796 case REGDOM_SET_BY_USER:
2797 return "USER";
2798 case REGDOM_SET_BY_DRIVER:
2799 return "DRIVER";
2800 case REGDOM_SET_BY_COUNTRY_IE:
2801 return "COUNTRY_IE";
2802 case REGDOM_BEACON_HINT:
2803 return "BEACON_HINT";
2804 }
2805 return "?";
2806}
2807
2808
2809static const char * reg_type_str(enum reg_type type)
2810{
2811 switch (type) {
2812 case REGDOM_TYPE_UNKNOWN:
2813 return "UNKNOWN";
2814 case REGDOM_TYPE_COUNTRY:
2815 return "COUNTRY";
2816 case REGDOM_TYPE_WORLD:
2817 return "WORLD";
2818 case REGDOM_TYPE_CUSTOM_WORLD:
2819 return "CUSTOM_WORLD";
2820 case REGDOM_TYPE_INTERSECTION:
2821 return "INTERSECTION";
2822 }
2823 return "?";
2824}
2825
2826
2827static void wpa_supplicant_update_channel_list(
2828 struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002829{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002830 struct wpa_supplicant *ifs;
2831
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002832 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
Dmitry Shmidtc2817022014-07-02 10:32:10 -07002833 reg_init_str(info->initiator), reg_type_str(info->type),
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002834 info->alpha2[0] ? " alpha2=" : "",
2835 info->alpha2[0] ? info->alpha2 : "");
2836
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002837 if (wpa_s->drv_priv == NULL)
2838 return; /* Ignore event during drv initialization */
2839
2840 free_hw_features(wpa_s);
2841 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
2842 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
2843
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002844 wpas_p2p_update_channel_list(wpa_s);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002845
2846 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002847 * Check other interfaces to see if they share the same radio. If
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002848 * so, they get updated with this same hw mode info.
2849 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002850 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
2851 radio_list) {
2852 if (ifs != wpa_s) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002853 wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
2854 ifs->ifname);
2855 free_hw_features(ifs);
2856 ifs->hw.modes = wpa_drv_get_hw_feature_data(
2857 ifs, &ifs->hw.num_modes, &ifs->hw.flags);
2858 }
2859 }
2860}
2861
2862
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002863static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002864 const u8 *frame, size_t len, int freq,
2865 int rssi)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002866{
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07002867 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002868 const u8 *payload;
2869 size_t plen;
2870 u8 category;
2871
2872 if (len < IEEE80211_HDRLEN + 2)
2873 return;
2874
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07002875 mgmt = (const struct ieee80211_mgmt *) frame;
2876 payload = frame + IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002877 category = *payload++;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07002878 plen = len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002879
2880 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2881 " Category=%u DataLen=%d freq=%d MHz",
2882 MAC2STR(mgmt->sa), category, (int) plen, freq);
2883
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002884 if (category == WLAN_ACTION_WMM) {
2885 wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
2886 return;
2887 }
2888
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002889#ifdef CONFIG_IEEE80211R
2890 if (category == WLAN_ACTION_FT) {
2891 ft_rx_action(wpa_s, payload, plen);
2892 return;
2893 }
2894#endif /* CONFIG_IEEE80211R */
2895
2896#ifdef CONFIG_IEEE80211W
2897#ifdef CONFIG_SME
2898 if (category == WLAN_ACTION_SA_QUERY) {
2899 sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
2900 return;
2901 }
2902#endif /* CONFIG_SME */
2903#endif /* CONFIG_IEEE80211W */
2904
2905#ifdef CONFIG_WNM
2906 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
2907 ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
2908 return;
2909 }
2910#endif /* CONFIG_WNM */
2911
2912#ifdef CONFIG_GAS
Dmitry Shmidt18463232014-01-24 12:29:41 -08002913 if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
2914 mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002915 gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
Dmitry Shmidt18463232014-01-24 12:29:41 -08002916 mgmt->u.action.category,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002917 payload, plen, freq) == 0)
2918 return;
2919#endif /* CONFIG_GAS */
2920
2921#ifdef CONFIG_TDLS
2922 if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
2923 payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2924 wpa_dbg(wpa_s, MSG_DEBUG,
2925 "TDLS: Received Discovery Response from " MACSTR,
2926 MAC2STR(mgmt->sa));
2927 return;
2928 }
2929#endif /* CONFIG_TDLS */
2930
2931#ifdef CONFIG_INTERWORKING
2932 if (category == WLAN_ACTION_QOS && plen >= 1 &&
2933 payload[0] == QOS_QOS_MAP_CONFIG) {
2934 const u8 *pos = payload + 1;
2935 size_t qlen = plen - 1;
2936 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
2937 MACSTR, MAC2STR(mgmt->sa));
2938 if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
2939 qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
2940 pos[1] <= qlen - 2 && pos[1] >= 16)
2941 wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
2942 return;
2943 }
2944#endif /* CONFIG_INTERWORKING */
2945
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002946 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2947 payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
2948 wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
2949 return;
2950 }
2951
2952 if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
2953 payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
2954 wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
2955 payload + 1, plen - 1,
2956 rssi);
2957 return;
2958 }
2959
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002960 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
2961 category, payload, plen, freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002962 if (wpa_s->ifmsh)
2963 mesh_mpm_action_rx(wpa_s, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002964}
2965
2966
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08002967static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
2968 union wpa_event_data *event)
2969{
2970#ifdef CONFIG_P2P
2971 struct wpa_supplicant *ifs;
2972#endif /* CONFIG_P2P */
2973 struct wpa_freq_range_list *list;
2974 char *str = NULL;
2975
2976 list = &event->freq_range;
2977
2978 if (list->num)
2979 str = freq_range_list_str(list);
2980 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
2981 str ? str : "");
2982
2983#ifdef CONFIG_P2P
2984 if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
2985 wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
2986 __func__);
2987 } else {
2988 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
2989 wpas_p2p_update_channel_list(wpa_s);
2990 }
2991
2992 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
2993 int freq;
2994 if (!ifs->current_ssid ||
2995 !ifs->current_ssid->p2p_group ||
2996 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
2997 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
2998 continue;
2999
3000 freq = ifs->current_ssid->frequency;
3001 if (!freq_range_list_includes(list, freq)) {
3002 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range",
3003 freq);
3004 continue;
3005 }
3006
3007 wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz",
3008 freq);
3009 /* TODO: Consider using CSA or removing the group within
3010 * wpa_supplicant */
3011 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
3012 }
3013#endif /* CONFIG_P2P */
3014
3015 os_free(str);
3016}
3017
3018
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003019static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
3020 union wpa_event_data *data)
3021{
3022 wpa_dbg(wpa_s, MSG_DEBUG,
3023 "Connection authorized by device, previous state %d",
3024 wpa_s->wpa_state);
3025 if (wpa_s->wpa_state == WPA_ASSOCIATED) {
3026 wpa_supplicant_cancel_auth_timeout(wpa_s);
3027 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
3028 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
3029 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
3030 }
3031 wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
3032 wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003033 data->assoc_info.ptk_kck_len,
3034 data->assoc_info.ptk_kek,
3035 data->assoc_info.ptk_kek_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003036}
3037
3038
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003039void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
3040 union wpa_event_data *data)
3041{
3042 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003043
3044 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
3045 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003046 event != EVENT_INTERFACE_STATUS &&
3047 event != EVENT_SCHED_SCAN_STOPPED) {
3048 wpa_dbg(wpa_s, MSG_DEBUG,
3049 "Ignore event %s (%d) while interface is disabled",
3050 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003051 return;
3052 }
3053
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003054#ifndef CONFIG_NO_STDOUT_DEBUG
3055{
3056 int level = MSG_DEBUG;
3057
Dmitry Shmidt04949592012-07-19 12:16:46 -07003058 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003059 const struct ieee80211_hdr *hdr;
3060 u16 fc;
3061 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
3062 fc = le_to_host16(hdr->frame_control);
3063 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3064 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
3065 level = MSG_EXCESSIVE;
3066 }
3067
3068 wpa_dbg(wpa_s, level, "Event %s (%d) received",
3069 event_to_string(event), event);
3070}
3071#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003072
3073 switch (event) {
3074 case EVENT_AUTH:
3075 sme_event_auth(wpa_s, data);
3076 break;
3077 case EVENT_ASSOC:
3078 wpa_supplicant_event_assoc(wpa_s, data);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003079 if (data && data->assoc_info.authorized)
3080 wpa_supplicant_event_assoc_auth(wpa_s, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003081 break;
3082 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003083 wpas_event_disassoc(wpa_s,
3084 data ? &data->disassoc_info : NULL);
3085 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003086 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003087 wpas_event_deauth(wpa_s,
3088 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003089 break;
3090 case EVENT_MICHAEL_MIC_FAILURE:
3091 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
3092 break;
3093#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003094 case EVENT_SCAN_STARTED:
3095 os_get_reltime(&wpa_s->scan_start_time);
3096 if (wpa_s->own_scan_requested) {
3097 struct os_reltime diff;
3098
3099 os_reltime_sub(&wpa_s->scan_start_time,
3100 &wpa_s->scan_trigger_time, &diff);
3101 wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
3102 diff.sec, diff.usec);
3103 wpa_s->own_scan_requested = 0;
3104 wpa_s->own_scan_running = 1;
3105 if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
3106 wpa_s->manual_scan_use_id) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003107 wpa_msg_ctrl(wpa_s, MSG_INFO,
3108 WPA_EVENT_SCAN_STARTED "id=%u",
3109 wpa_s->manual_scan_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003110 } else {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003111 wpa_msg_ctrl(wpa_s, MSG_INFO,
3112 WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003113 }
3114 } else {
3115 wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003116 wpa_s->radio->external_scan_running = 1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003117 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003118 }
3119 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003120 case EVENT_SCAN_RESULTS:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003121 if (os_reltime_initialized(&wpa_s->scan_start_time)) {
3122 struct os_reltime now, diff;
3123 os_get_reltime(&now);
3124 os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
3125 wpa_s->scan_start_time.sec = 0;
3126 wpa_s->scan_start_time.usec = 0;
3127 wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
3128 diff.sec, diff.usec);
3129 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003130 if (wpa_supplicant_event_scan_results(wpa_s, data))
3131 break; /* interface may have been removed */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003132 wpa_s->own_scan_running = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08003133 wpa_s->radio->external_scan_running = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003134 radio_work_check_next(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003135 break;
3136#endif /* CONFIG_NO_SCAN_PROCESSING */
3137 case EVENT_ASSOCINFO:
3138 wpa_supplicant_event_associnfo(wpa_s, data);
3139 break;
3140 case EVENT_INTERFACE_STATUS:
3141 wpa_supplicant_event_interface_status(wpa_s, data);
3142 break;
3143 case EVENT_PMKID_CANDIDATE:
3144 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
3145 break;
3146#ifdef CONFIG_PEERKEY
3147 case EVENT_STKSTART:
3148 wpa_supplicant_event_stkstart(wpa_s, data);
3149 break;
3150#endif /* CONFIG_PEERKEY */
3151#ifdef CONFIG_TDLS
3152 case EVENT_TDLS:
3153 wpa_supplicant_event_tdls(wpa_s, data);
3154 break;
3155#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003156#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003157 case EVENT_WNM:
3158 wpa_supplicant_event_wnm(wpa_s, data);
3159 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003160#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003161#ifdef CONFIG_IEEE80211R
3162 case EVENT_FT_RESPONSE:
3163 wpa_supplicant_event_ft_response(wpa_s, data);
3164 break;
3165#endif /* CONFIG_IEEE80211R */
3166#ifdef CONFIG_IBSS_RSN
3167 case EVENT_IBSS_RSN_START:
3168 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
3169 break;
3170#endif /* CONFIG_IBSS_RSN */
3171 case EVENT_ASSOC_REJECT:
3172 if (data->assoc_reject.bssid)
3173 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3174 "bssid=" MACSTR " status_code=%u",
3175 MAC2STR(data->assoc_reject.bssid),
3176 data->assoc_reject.status_code);
3177 else
3178 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
3179 "status_code=%u",
3180 data->assoc_reject.status_code);
3181 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3182 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07003183 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003184 const u8 *bssid = data->assoc_reject.bssid;
3185 if (bssid == NULL || is_zero_ether_addr(bssid))
3186 bssid = wpa_s->pending_bssid;
3187 wpas_connection_failed(wpa_s, bssid);
3188 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003189 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003190 break;
3191 case EVENT_AUTH_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003192 /* It is possible to get this event from earlier connection */
3193 if (wpa_s->current_ssid &&
3194 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3195 wpa_dbg(wpa_s, MSG_DEBUG,
3196 "Ignore AUTH_TIMED_OUT in mesh configuration");
3197 break;
3198 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003199 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3200 sme_event_auth_timed_out(wpa_s, data);
3201 break;
3202 case EVENT_ASSOC_TIMED_OUT:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003203 /* It is possible to get this event from earlier connection */
3204 if (wpa_s->current_ssid &&
3205 wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
3206 wpa_dbg(wpa_s, MSG_DEBUG,
3207 "Ignore ASSOC_TIMED_OUT in mesh configuration");
3208 break;
3209 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003210 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
3211 sme_event_assoc_timed_out(wpa_s, data);
3212 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003213 case EVENT_TX_STATUS:
3214 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
3215 " type=%d stype=%d",
3216 MAC2STR(data->tx_status.dst),
3217 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003218#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003219 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003220#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003221 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3222 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003223 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003224 wpa_s, data->tx_status.dst,
3225 data->tx_status.data,
3226 data->tx_status.data_len,
3227 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003228 OFFCHANNEL_SEND_ACTION_SUCCESS :
3229 OFFCHANNEL_SEND_ACTION_NO_ACK);
3230#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003231 break;
3232 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003233#endif /* CONFIG_AP */
3234#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003235 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
3236 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
3237 /*
3238 * Catch TX status events for Action frames we sent via group
3239 * interface in GO mode.
3240 */
3241 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
3242 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
3243 os_memcmp(wpa_s->parent->pending_action_dst,
3244 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003245 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003246 wpa_s->parent, data->tx_status.dst,
3247 data->tx_status.data,
3248 data->tx_status.data_len,
3249 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003250 OFFCHANNEL_SEND_ACTION_SUCCESS :
3251 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003252 break;
3253 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003254#endif /* CONFIG_OFFCHANNEL */
3255#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003256 switch (data->tx_status.type) {
3257 case WLAN_FC_TYPE_MGMT:
3258 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
3259 data->tx_status.data_len,
3260 data->tx_status.stype,
3261 data->tx_status.ack);
3262 break;
3263 case WLAN_FC_TYPE_DATA:
3264 ap_tx_status(wpa_s, data->tx_status.dst,
3265 data->tx_status.data,
3266 data->tx_status.data_len,
3267 data->tx_status.ack);
3268 break;
3269 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003270#endif /* CONFIG_AP */
3271 break;
3272#ifdef CONFIG_AP
3273 case EVENT_EAPOL_TX_STATUS:
3274 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
3275 data->eapol_tx_status.data,
3276 data->eapol_tx_status.data_len,
3277 data->eapol_tx_status.ack);
3278 break;
3279 case EVENT_DRIVER_CLIENT_POLL_OK:
3280 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003281 break;
3282 case EVENT_RX_FROM_UNKNOWN:
3283 if (wpa_s->ap_iface == NULL)
3284 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003285 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
3286 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003287 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003288 case EVENT_CH_SWITCH:
3289 if (!data)
3290 break;
3291 if (!wpa_s->ap_iface) {
3292 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
3293 "event in non-AP mode");
3294 break;
3295 }
3296
Dmitry Shmidt04949592012-07-19 12:16:46 -07003297 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
3298 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08003299 data->ch_switch.ch_offset,
3300 data->ch_switch.ch_width,
3301 data->ch_switch.cf1,
3302 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003303 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003304#endif /* CONFIG_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003305 case EVENT_RX_MGMT: {
3306 u16 fc, stype;
3307 const struct ieee80211_mgmt *mgmt;
3308
Dmitry Shmidt818ea482014-03-10 13:15:21 -07003309#ifdef CONFIG_TESTING_OPTIONS
3310 if (wpa_s->ext_mgmt_frame_handling) {
3311 struct rx_mgmt *rx = &data->rx_mgmt;
3312 size_t hex_len = 2 * rx->frame_len + 1;
3313 char *hex = os_malloc(hex_len);
3314 if (hex) {
3315 wpa_snprintf_hex(hex, hex_len,
3316 rx->frame, rx->frame_len);
3317 wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
3318 rx->freq, rx->datarate, rx->ssi_signal,
3319 hex);
3320 os_free(hex);
3321 }
3322 break;
3323 }
3324#endif /* CONFIG_TESTING_OPTIONS */
3325
Dmitry Shmidt04949592012-07-19 12:16:46 -07003326 mgmt = (const struct ieee80211_mgmt *)
3327 data->rx_mgmt.frame;
3328 fc = le_to_host16(mgmt->frame_control);
3329 stype = WLAN_FC_GET_STYPE(fc);
3330
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003331#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003332 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003333#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003334#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003335 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3336 data->rx_mgmt.frame_len > 24) {
3337 const u8 *src = mgmt->sa;
3338 const u8 *ie = mgmt->u.probe_req.variable;
3339 size_t ie_len = data->rx_mgmt.frame_len -
3340 (mgmt->u.probe_req.variable -
3341 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003342 wpas_p2p_probe_req_rx(
3343 wpa_s, src, mgmt->da,
3344 mgmt->bssid, ie, ie_len,
3345 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003346 break;
3347 }
3348#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003349#ifdef CONFIG_IBSS_RSN
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003350 if (wpa_s->current_ssid &&
3351 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
3352 stype == WLAN_FC_STYPE_AUTH &&
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003353 data->rx_mgmt.frame_len >= 30) {
3354 wpa_supplicant_event_ibss_auth(wpa_s, data);
3355 break;
3356 }
3357#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003358
3359 if (stype == WLAN_FC_STYPE_ACTION) {
3360 wpas_event_rx_mgmt_action(
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07003361 wpa_s, data->rx_mgmt.frame,
3362 data->rx_mgmt.frame_len,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003363 data->rx_mgmt.freq,
3364 data->rx_mgmt.ssi_signal);
3365 break;
3366 }
3367
3368 if (wpa_s->ifmsh) {
3369 mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003370 break;
3371 }
3372
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003373 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
3374 "management frame in non-AP mode");
3375 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003376#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003377 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003378
3379 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
3380 data->rx_mgmt.frame_len > 24) {
3381 const u8 *ie = mgmt->u.probe_req.variable;
3382 size_t ie_len = data->rx_mgmt.frame_len -
3383 (mgmt->u.probe_req.variable -
3384 data->rx_mgmt.frame);
3385
3386 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
3387 mgmt->bssid, ie, ie_len,
3388 data->rx_mgmt.ssi_signal);
3389 }
3390
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003391 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07003392#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003393 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003394 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003395 case EVENT_RX_PROBE_REQ:
3396 if (data->rx_probe_req.sa == NULL ||
3397 data->rx_probe_req.ie == NULL)
3398 break;
3399#ifdef CONFIG_AP
3400 if (wpa_s->ap_iface) {
3401 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
3402 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003403 data->rx_probe_req.da,
3404 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003405 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003406 data->rx_probe_req.ie_len,
3407 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003408 break;
3409 }
3410#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003411 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003412 data->rx_probe_req.da,
3413 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003414 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07003415 data->rx_probe_req.ie_len,
3416 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003417 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003418 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003419#ifdef CONFIG_OFFCHANNEL
3420 offchannel_remain_on_channel_cb(
3421 wpa_s, data->remain_on_channel.freq,
3422 data->remain_on_channel.duration);
3423#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003424 wpas_p2p_remain_on_channel_cb(
3425 wpa_s, data->remain_on_channel.freq,
3426 data->remain_on_channel.duration);
3427 break;
3428 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003429#ifdef CONFIG_OFFCHANNEL
3430 offchannel_cancel_remain_on_channel_cb(
3431 wpa_s, data->remain_on_channel.freq);
3432#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003433 wpas_p2p_cancel_remain_on_channel_cb(
3434 wpa_s, data->remain_on_channel.freq);
3435 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003436 case EVENT_EAPOL_RX:
3437 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3438 data->eapol_rx.data,
3439 data->eapol_rx.data_len);
3440 break;
3441 case EVENT_SIGNAL_CHANGE:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003442 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
3443 "above=%d signal=%d noise=%d txrate=%d",
3444 data->signal_change.above_threshold,
3445 data->signal_change.current_signal,
3446 data->signal_change.current_noise,
3447 data->signal_change.current_txrate);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003448 wpa_bss_update_level(wpa_s->current_bss,
3449 data->signal_change.current_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003450 bgscan_notify_signal_change(
3451 wpa_s, data->signal_change.above_threshold,
3452 data->signal_change.current_signal,
3453 data->signal_change.current_noise,
3454 data->signal_change.current_txrate);
3455 break;
3456 case EVENT_INTERFACE_ENABLED:
3457 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3458 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003459 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07003460 if (wpa_s->p2p_mgmt) {
3461 wpa_supplicant_set_state(wpa_s,
3462 WPA_DISCONNECTED);
3463 break;
3464 }
3465
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003466#ifdef CONFIG_AP
3467 if (!wpa_s->ap_iface) {
3468 wpa_supplicant_set_state(wpa_s,
3469 WPA_DISCONNECTED);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003470 wpa_s->scan_req = NORMAL_SCAN_REQ;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003471 wpa_supplicant_req_scan(wpa_s, 0, 0);
3472 } else
3473 wpa_supplicant_set_state(wpa_s,
3474 WPA_COMPLETED);
3475#else /* CONFIG_AP */
3476 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3477 wpa_supplicant_req_scan(wpa_s, 0, 0);
3478#endif /* CONFIG_AP */
3479 }
3480 break;
3481 case EVENT_INTERFACE_DISABLED:
3482 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003483#ifdef CONFIG_P2P
3484 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
3485 (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
3486 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
3487 /*
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003488 * Mark interface disabled if this happens to end up not
3489 * being removed as a separate P2P group interface.
3490 */
3491 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3492 /*
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003493 * The interface was externally disabled. Remove
3494 * it assuming an external entity will start a
3495 * new session if needed.
3496 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003497 if (wpa_s->current_ssid &&
3498 wpa_s->current_ssid->p2p_group)
3499 wpas_p2p_interface_unavailable(wpa_s);
3500 else
3501 wpas_p2p_disconnect(wpa_s);
3502 /*
3503 * wpa_s instance may have been freed, so must not use
3504 * it here anymore.
3505 */
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003506 break;
3507 }
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003508 if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
3509 p2p_in_progress(wpa_s->global->p2p) > 1) {
3510 /* This radio work will be cancelled, so clear P2P
3511 * state as well.
3512 */
3513 p2p_stop_find(wpa_s->global->p2p);
3514 }
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003515#endif /* CONFIG_P2P */
3516
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003517 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
3518 /*
3519 * Indicate disconnection to keep ctrl_iface events
3520 * consistent.
3521 */
3522 wpa_supplicant_event_disassoc(
3523 wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
3524 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003525 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003526 radio_remove_works(wpa_s, NULL, 0);
3527
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003528 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3529 break;
3530 case EVENT_CHANNEL_LIST_CHANGED:
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07003531 wpa_supplicant_update_channel_list(
3532 wpa_s, &data->channel_list_changed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003533 break;
3534 case EVENT_INTERFACE_UNAVAILABLE:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003535 wpas_p2p_interface_unavailable(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003536 break;
3537 case EVENT_BEST_CHANNEL:
3538 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3539 "(%d %d %d)",
3540 data->best_chan.freq_24, data->best_chan.freq_5,
3541 data->best_chan.freq_overall);
3542 wpa_s->best_24_freq = data->best_chan.freq_24;
3543 wpa_s->best_5_freq = data->best_chan.freq_5;
3544 wpa_s->best_overall_freq = data->best_chan.freq_overall;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003545 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3546 data->best_chan.freq_5,
3547 data->best_chan.freq_overall);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003548 break;
3549 case EVENT_UNPROT_DEAUTH:
3550 wpa_supplicant_event_unprot_deauth(wpa_s,
3551 &data->unprot_deauth);
3552 break;
3553 case EVENT_UNPROT_DISASSOC:
3554 wpa_supplicant_event_unprot_disassoc(wpa_s,
3555 &data->unprot_disassoc);
3556 break;
3557 case EVENT_STATION_LOW_ACK:
3558#ifdef CONFIG_AP
3559 if (wpa_s->ap_iface && data)
3560 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3561 data->low_ack.addr);
3562#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003563#ifdef CONFIG_TDLS
3564 if (data)
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07003565 wpa_tdls_disable_unreachable_link(wpa_s->wpa,
3566 data->low_ack.addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003567#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003568 break;
3569 case EVENT_IBSS_PEER_LOST:
3570#ifdef CONFIG_IBSS_RSN
3571 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3572#endif /* CONFIG_IBSS_RSN */
3573 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003574 case EVENT_DRIVER_GTK_REKEY:
3575 if (os_memcmp(data->driver_gtk_rekey.bssid,
3576 wpa_s->bssid, ETH_ALEN))
3577 break;
3578 if (!wpa_s->wpa)
3579 break;
3580 wpa_sm_update_replay_ctr(wpa_s->wpa,
3581 data->driver_gtk_rekey.replay_ctr);
3582 break;
3583 case EVENT_SCHED_SCAN_STOPPED:
Dmitry Shmidt18463232014-01-24 12:29:41 -08003584 wpa_s->pno = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003585 wpa_s->sched_scanning = 0;
3586 wpa_supplicant_notify_scanning(wpa_s, 0);
3587
3588 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3589 break;
3590
3591 /*
Dmitry Shmidt18463232014-01-24 12:29:41 -08003592 * Start a new sched scan to continue searching for more SSIDs
3593 * either if timed out or PNO schedule scan is pending.
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003594 */
Dmitry Shmidt98660862014-03-11 17:26:21 -07003595 if (wpa_s->sched_scan_timed_out) {
3596 wpa_supplicant_req_sched_scan(wpa_s);
3597 } else if (wpa_s->pno_sched_pending) {
3598 wpa_s->pno_sched_pending = 0;
3599 wpas_start_pno(wpa_s);
Dmitry Shmidt18463232014-01-24 12:29:41 -08003600 }
3601
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003602 break;
3603 case EVENT_WPS_BUTTON_PUSHED:
3604#ifdef CONFIG_WPS
3605 wpas_wps_start_pbc(wpa_s, NULL, 0);
3606#endif /* CONFIG_WPS */
3607 break;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08003608 case EVENT_AVOID_FREQUENCIES:
3609 wpa_supplicant_notify_avoid_freq(wpa_s, data);
3610 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003611 case EVENT_CONNECT_FAILED_REASON:
3612#ifdef CONFIG_AP
3613 if (!wpa_s->ap_iface || !data)
3614 break;
3615 hostapd_event_connect_failed_reason(
3616 wpa_s->ap_iface->bss[0],
3617 data->connect_failed_reason.addr,
3618 data->connect_failed_reason.code);
3619#endif /* CONFIG_AP */
3620 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003621 case EVENT_NEW_PEER_CANDIDATE:
3622#ifdef CONFIG_MESH
3623 if (!wpa_s->ifmsh || !data)
3624 break;
3625 wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
3626 data->mesh_peer.ies,
3627 data->mesh_peer.ie_len);
3628#endif /* CONFIG_MESH */
3629 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003630 default:
3631 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3632 break;
3633 }
3634}