blob: 9de8d7f6e489536128769d12a21e8acab0322d2d [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Driver event processing
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003 * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
13#include "rsn_supp/wpa.h"
14#include "eloop.h"
15#include "config.h"
16#include "l2_packet/l2_packet.h"
17#include "wpa_supplicant_i.h"
18#include "driver_i.h"
19#include "pcsc_funcs.h"
20#include "rsn_supp/preauth.h"
21#include "rsn_supp/pmksa_cache.h"
22#include "common/wpa_ctrl.h"
23#include "eap_peer/eap.h"
24#include "ap/hostapd.h"
25#include "p2p/p2p.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070026#include "wnm_sta.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "notify.h"
28#include "common/ieee802_11_defs.h"
29#include "common/ieee802_11_common.h"
30#include "crypto/random.h"
31#include "blacklist.h"
32#include "wpas_glue.h"
33#include "wps_supplicant.h"
34#include "ibss_rsn.h"
35#include "sme.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080036#include "gas_query.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037#include "p2p_supplicant.h"
38#include "bgscan.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070039#include "autoscan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040#include "ap.h"
41#include "bss.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042#include "scan.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080043#include "offchannel.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070044#include "interworking.h"
45
46
Dmitry Shmidt34af3062013-07-11 10:46:32 -070047#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt8da800a2013-04-24 12:57:01 -070048static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
49 int new_scan);
Dmitry Shmidt34af3062013-07-11 10:46:32 -070050#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -080051
52
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070053static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
54 struct wpa_ssid *ssid)
55{
56 struct os_time now;
57
58 if (ssid == NULL || ssid->disabled_until.sec == 0)
59 return 0;
60
61 os_get_time(&now);
62 if (ssid->disabled_until.sec > now.sec)
63 return ssid->disabled_until.sec - now.sec;
64
65 wpas_clear_temp_disabled(wpa_s, ssid, 0);
66
67 return 0;
68}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069
70
71static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
72{
73 struct wpa_ssid *ssid, *old_ssid;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070074 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070075
76 if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
77 return 0;
78
79 wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
80 "information");
81 ssid = wpa_supplicant_get_ssid(wpa_s);
82 if (ssid == NULL) {
83 wpa_msg(wpa_s, MSG_INFO,
84 "No network configuration found for the current AP");
85 return -1;
86 }
87
Dmitry Shmidt04949592012-07-19 12:16:46 -070088 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
90 return -1;
91 }
92
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080093 if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
94 disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
95 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
96 return -1;
97 }
98
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070099 res = wpas_temp_disabled(wpa_s, ssid);
100 if (res > 0) {
101 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
102 "disabled for %d second(s)", res);
103 return -1;
104 }
105
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700106 wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
107 "current AP");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800108 if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109 u8 wpa_ie[80];
110 size_t wpa_ie_len = sizeof(wpa_ie);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800111 if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
112 wpa_ie, &wpa_ie_len) < 0)
113 wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 } else {
115 wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
116 }
117
118 if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
119 eapol_sm_invalidate_cached_session(wpa_s->eapol);
120 old_ssid = wpa_s->current_ssid;
121 wpa_s->current_ssid = ssid;
122 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
123 wpa_supplicant_initiate_eapol(wpa_s);
124 if (old_ssid != wpa_s->current_ssid)
125 wpas_notify_network_changed(wpa_s);
126
127 return 0;
128}
129
130
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800131void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700132{
133 struct wpa_supplicant *wpa_s = eloop_ctx;
134
135 if (wpa_s->countermeasures) {
136 wpa_s->countermeasures = 0;
137 wpa_drv_set_countermeasures(wpa_s, 0);
138 wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
139 wpa_supplicant_req_scan(wpa_s, 0, 0);
140 }
141}
142
143
144void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
145{
146 int bssid_changed;
147
Dmitry Shmidt04949592012-07-19 12:16:46 -0700148 wnm_bss_keep_alive_deinit(wpa_s);
149
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150#ifdef CONFIG_IBSS_RSN
151 ibss_rsn_deinit(wpa_s->ibss_rsn);
152 wpa_s->ibss_rsn = NULL;
153#endif /* CONFIG_IBSS_RSN */
154
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700155#ifdef CONFIG_AP
156 wpa_supplicant_ap_deinit(wpa_s);
157#endif /* CONFIG_AP */
158
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
160 return;
161
162 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800163#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -0700164 wpa_s->conf->ap_scan = DEFAULT_AP_SCAN;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800165#endif
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700166 bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
167 os_memset(wpa_s->bssid, 0, ETH_ALEN);
168 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700169#ifdef CONFIG_SME
170 wpa_s->sme.prev_bssid_set = 0;
171#endif /* CONFIG_SME */
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800172#ifdef CONFIG_P2P
173 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
174#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700175 wpa_s->current_bss = NULL;
176 wpa_s->assoc_freq = 0;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700177#ifdef CONFIG_IEEE80211R
178#ifdef CONFIG_SME
179 if (wpa_s->sme.ft_ies)
180 sme_update_ft_ies(wpa_s, NULL, NULL, 0);
181#endif /* CONFIG_SME */
182#endif /* CONFIG_IEEE80211R */
183
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700184 if (bssid_changed)
185 wpas_notify_bssid_changed(wpa_s);
186
187 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
188 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
189 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
190 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
191 wpa_s->ap_ies_from_associnfo = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700192 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700193 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700194 wpa_s->key_mgmt = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700195}
196
197
198static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
199{
200 struct wpa_ie_data ie;
201 int pmksa_set = -1;
202 size_t i;
203
204 if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
205 ie.pmkid == NULL)
206 return;
207
208 for (i = 0; i < ie.num_pmkid; i++) {
209 pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
210 ie.pmkid + i * PMKID_LEN,
211 NULL, NULL, 0);
212 if (pmksa_set == 0) {
213 eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
214 break;
215 }
216 }
217
218 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
219 "PMKSA cache", pmksa_set == 0 ? "" : "not ");
220}
221
222
223static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
224 union wpa_event_data *data)
225{
226 if (data == NULL) {
227 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
228 "event");
229 return;
230 }
231 wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
232 " index=%d preauth=%d",
233 MAC2STR(data->pmkid_candidate.bssid),
234 data->pmkid_candidate.index,
235 data->pmkid_candidate.preauth);
236
237 pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
238 data->pmkid_candidate.index,
239 data->pmkid_candidate.preauth);
240}
241
242
243static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
244{
245 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
246 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
247 return 0;
248
249#ifdef IEEE8021X_EAPOL
250 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
251 wpa_s->current_ssid &&
252 !(wpa_s->current_ssid->eapol_flags &
253 (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
254 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
255 /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
256 * plaintext or static WEP keys). */
257 return 0;
258 }
259#endif /* IEEE8021X_EAPOL */
260
261 return 1;
262}
263
264
265/**
266 * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
267 * @wpa_s: pointer to wpa_supplicant data
268 * @ssid: Configuration data for the network
269 * Returns: 0 on success, -1 on failure
270 *
271 * This function is called when starting authentication with a network that is
272 * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
273 */
274int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
275 struct wpa_ssid *ssid)
276{
277#ifdef IEEE8021X_EAPOL
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800278#ifdef PCSC_FUNCS
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700279 int aka = 0, sim = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280
281 if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
282 return 0;
283
284 if (ssid->eap.eap_methods == NULL) {
285 sim = 1;
286 aka = 1;
287 } else {
288 struct eap_method_type *eap = ssid->eap.eap_methods;
289 while (eap->vendor != EAP_VENDOR_IETF ||
290 eap->method != EAP_TYPE_NONE) {
291 if (eap->vendor == EAP_VENDOR_IETF) {
292 if (eap->method == EAP_TYPE_SIM)
293 sim = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700294 else if (eap->method == EAP_TYPE_AKA ||
295 eap->method == EAP_TYPE_AKA_PRIME)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700296 aka = 1;
297 }
298 eap++;
299 }
300 }
301
302 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
303 sim = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700304 if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
305 eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
306 NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307 aka = 0;
308
309 if (!sim && !aka) {
310 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
311 "use SIM, but neither EAP-SIM nor EAP-AKA are "
312 "enabled");
313 return 0;
314 }
315
316 wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
317 "(sim=%d aka=%d) - initialize PCSC", sim, aka);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700318
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700319 wpa_s->scard = scard_init((!sim && aka) ? SCARD_USIM_ONLY :
320 SCARD_TRY_BOTH, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700321 if (wpa_s->scard == NULL) {
322 wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
323 "(pcsc-lite)");
324 return -1;
325 }
326 wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
327 eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800328#endif /* PCSC_FUNCS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700329#endif /* IEEE8021X_EAPOL */
330
331 return 0;
332}
333
334
335#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700336
337static int has_wep_key(struct wpa_ssid *ssid)
338{
339 int i;
340
341 for (i = 0; i < NUM_WEP_KEYS; i++) {
342 if (ssid->wep_key_len[i])
343 return 1;
344 }
345
346 return 0;
347}
348
349
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700350static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700351 struct wpa_ssid *ssid)
352{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700353 int privacy = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700354
355 if (ssid->mixed_cell)
356 return 1;
357
358#ifdef CONFIG_WPS
359 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
360 return 1;
361#endif /* CONFIG_WPS */
362
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700363 if (has_wep_key(ssid))
364 privacy = 1;
365
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700366#ifdef IEEE8021X_EAPOL
367 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
368 ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
369 EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
370 privacy = 1;
371#endif /* IEEE8021X_EAPOL */
372
Jouni Malinen75ecf522011-06-27 15:19:46 -0700373 if (wpa_key_mgmt_wpa(ssid->key_mgmt))
374 privacy = 1;
375
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700376 if (bss->caps & IEEE80211_CAP_PRIVACY)
377 return privacy;
378 return !privacy;
379}
380
381
382static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
383 struct wpa_ssid *ssid,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700384 struct wpa_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700385{
386 struct wpa_ie_data ie;
387 int proto_match = 0;
388 const u8 *rsn_ie, *wpa_ie;
389 int ret;
390 int wep_ok;
391
392 ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
393 if (ret >= 0)
394 return ret;
395
396 /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
397 wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
398 (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
399 ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
400 (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
401
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700402 rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700403 while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
404 proto_match++;
405
406 if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
407 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
408 "failed");
409 break;
410 }
411
412 if (wep_ok &&
413 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
414 {
415 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
416 "in RSN IE");
417 return 1;
418 }
419
420 if (!(ie.proto & ssid->proto)) {
421 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
422 "mismatch");
423 break;
424 }
425
426 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
427 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
428 "cipher mismatch");
429 break;
430 }
431
432 if (!(ie.group_cipher & ssid->group_cipher)) {
433 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
434 "cipher mismatch");
435 break;
436 }
437
438 if (!(ie.key_mgmt & ssid->key_mgmt)) {
439 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
440 "mismatch");
441 break;
442 }
443
444#ifdef CONFIG_IEEE80211W
445 if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800446 (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
447 wpa_s->conf->pmf : ssid->ieee80211w) ==
448 MGMT_FRAME_PROTECTION_REQUIRED) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700449 wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
450 "frame protection");
451 break;
452 }
453#endif /* CONFIG_IEEE80211W */
454
455 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
456 return 1;
457 }
458
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700459 wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700460 while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
461 proto_match++;
462
463 if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
464 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
465 "failed");
466 break;
467 }
468
469 if (wep_ok &&
470 (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
471 {
472 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
473 "in WPA IE");
474 return 1;
475 }
476
477 if (!(ie.proto & ssid->proto)) {
478 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
479 "mismatch");
480 break;
481 }
482
483 if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
484 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
485 "cipher mismatch");
486 break;
487 }
488
489 if (!(ie.group_cipher & ssid->group_cipher)) {
490 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
491 "cipher mismatch");
492 break;
493 }
494
495 if (!(ie.key_mgmt & ssid->key_mgmt)) {
496 wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
497 "mismatch");
498 break;
499 }
500
501 wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
502 return 1;
503 }
504
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700505 if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
506 !rsn_ie) {
507 wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
508 return 1;
509 }
510
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700511 if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
512 wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
513 wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
514 return 0;
515 }
516
517 if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
518 wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
519 return 1;
520 }
521
522 wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
523 "WPA/WPA2");
524
525 return 0;
526}
527
528
529static int freq_allowed(int *freqs, int freq)
530{
531 int i;
532
533 if (freqs == NULL)
534 return 1;
535
536 for (i = 0; freqs[i]; i++)
537 if (freqs[i] == freq)
538 return 1;
539 return 0;
540}
541
542
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800543static int ht_supported(const struct hostapd_hw_modes *mode)
544{
545 if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
546 /*
547 * The driver did not indicate whether it supports HT. Assume
548 * it does to avoid connection issues.
549 */
550 return 1;
551 }
552
553 /*
554 * IEEE Std 802.11n-2009 20.1.1:
555 * An HT non-AP STA shall support all EQM rates for one spatial stream.
556 */
557 return mode->mcs_set[0] == 0xff;
558}
559
560
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700561static int vht_supported(const struct hostapd_hw_modes *mode)
562{
563 if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) {
564 /*
565 * The driver did not indicate whether it supports VHT. Assume
566 * it does to avoid connection issues.
567 */
568 return 1;
569 }
570
571 /*
572 * A VHT non-AP STA shall support MCS 0-7 for one spatial stream.
573 * TODO: Verify if this complies with the standard
574 */
575 return (mode->vht_mcs_set[0] & 0x3) != 3;
576}
577
578
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700579static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800580{
581 const struct hostapd_hw_modes *mode = NULL, *modes;
582 const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
583 const u8 *rate_ie;
584 int i, j, k;
585
586 if (bss->freq == 0)
587 return 1; /* Cannot do matching without knowing band */
588
589 modes = wpa_s->hw.modes;
590 if (modes == NULL) {
591 /*
592 * The driver does not provide any additional information
593 * about the utilized hardware, so allow the connection attempt
594 * to continue.
595 */
596 return 1;
597 }
598
599 for (i = 0; i < wpa_s->hw.num_modes; i++) {
600 for (j = 0; j < modes[i].num_channels; j++) {
601 int freq = modes[i].channels[j].freq;
602 if (freq == bss->freq) {
603 if (mode &&
604 mode->mode == HOSTAPD_MODE_IEEE80211G)
605 break; /* do not allow 802.11b replace
606 * 802.11g */
607 mode = &modes[i];
608 break;
609 }
610 }
611 }
612
613 if (mode == NULL)
614 return 0;
615
616 for (i = 0; i < (int) sizeof(scan_ie); i++) {
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700617 rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800618 if (rate_ie == NULL)
619 continue;
620
621 for (j = 2; j < rate_ie[1] + 2; j++) {
622 int flagged = !!(rate_ie[j] & 0x80);
623 int r = (rate_ie[j] & 0x7f) * 5;
624
625 /*
626 * IEEE Std 802.11n-2009 7.3.2.2:
627 * The new BSS Membership selector value is encoded
628 * like a legacy basic rate, but it is not a rate and
629 * only indicates if the BSS members are required to
630 * support the mandatory features of Clause 20 [HT PHY]
631 * in order to join the BSS.
632 */
633 if (flagged && ((rate_ie[j] & 0x7f) ==
634 BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
635 if (!ht_supported(mode)) {
636 wpa_dbg(wpa_s, MSG_DEBUG,
637 " hardware does not support "
638 "HT PHY");
639 return 0;
640 }
641 continue;
642 }
643
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700644 /* There's also a VHT selector for 802.11ac */
645 if (flagged && ((rate_ie[j] & 0x7f) ==
646 BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
647 if (!vht_supported(mode)) {
648 wpa_dbg(wpa_s, MSG_DEBUG,
649 " hardware does not support "
650 "VHT PHY");
651 return 0;
652 }
653 continue;
654 }
655
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800656 if (!flagged)
657 continue;
658
659 /* check for legacy basic rates */
660 for (k = 0; k < mode->num_rates; k++) {
661 if (mode->rates[k] == r)
662 break;
663 }
664 if (k == mode->num_rates) {
665 /*
666 * IEEE Std 802.11-2007 7.3.2.2 demands that in
667 * order to join a BSS all required rates
668 * have to be supported by the hardware.
669 */
670 wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
671 "not support required rate %d.%d Mbps",
672 r / 10, r % 10);
673 return 0;
674 }
675 }
676 }
677
678 return 1;
679}
680
681
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800682static int bss_is_dmg(struct wpa_bss *bss)
683{
684 return bss->freq > 45000;
685}
686
687
688/*
689 * Test whether BSS is in an ESS.
690 * This is done differently in DMG (60 GHz) and non-DMG bands
691 */
692static int bss_is_ess(struct wpa_bss *bss)
693{
694 if (bss_is_dmg(bss)) {
695 return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
696 IEEE80211_CAP_DMG_AP;
697 }
698
699 return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
700 IEEE80211_CAP_ESS);
701}
702
703
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700704static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700705 int i, struct wpa_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 struct wpa_ssid *group)
707{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700708 u8 wpa_ie_len, rsn_ie_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700709 int wpa;
710 struct wpa_blacklist *e;
711 const u8 *ie;
712 struct wpa_ssid *ssid;
713
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700714 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700715 wpa_ie_len = ie ? ie[1] : 0;
716
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700717 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700718 rsn_ie_len = ie ? ie[1] : 0;
719
720 wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
721 "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700722 i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700723 wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700724 wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725
726 e = wpa_blacklist_get(wpa_s, bss->bssid);
727 if (e) {
728 int limit = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700729 if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 /*
731 * When only a single network is enabled, we can
732 * trigger blacklisting on the first failure. This
733 * should not be done with multiple enabled networks to
734 * avoid getting forced to move into a worse ESS on
735 * single error if there are no other BSSes of the
736 * current ESS.
737 */
738 limit = 0;
739 }
740 if (e->count > limit) {
741 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
742 "(count=%d limit=%d)", e->count, limit);
743 return NULL;
744 }
745 }
746
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700747 if (bss->ssid_len == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700748 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
749 return NULL;
750 }
751
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800752 if (disallowed_bssid(wpa_s, bss->bssid)) {
753 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
754 return NULL;
755 }
756
757 if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
758 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
759 return NULL;
760 }
761
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762 wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
763
764 for (ssid = group; ssid; ssid = ssid->pnext) {
765 int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700766 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767
Dmitry Shmidt04949592012-07-19 12:16:46 -0700768 if (wpas_network_disabled(wpa_s, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
770 continue;
771 }
772
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700773 res = wpas_temp_disabled(wpa_s, ssid);
774 if (res > 0) {
775 wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
776 "temporarily for %d second(s)", res);
777 continue;
778 }
779
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780#ifdef CONFIG_WPS
781 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
782 wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
783 "(WPS)");
784 continue;
785 }
786
787 if (wpa && ssid->ssid_len == 0 &&
788 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
789 check_ssid = 0;
790
791 if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
792 /* Only allow wildcard SSID match if an AP
793 * advertises active WPS operation that matches
794 * with our mode. */
795 check_ssid = 1;
796 if (ssid->ssid_len == 0 &&
797 wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
798 check_ssid = 0;
799 }
800#endif /* CONFIG_WPS */
801
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800802 if (ssid->bssid_set && ssid->ssid_len == 0 &&
803 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
804 check_ssid = 0;
805
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700806 if (check_ssid &&
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700807 (bss->ssid_len != ssid->ssid_len ||
808 os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809 wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
810 continue;
811 }
812
813 if (ssid->bssid_set &&
814 os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
815 wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
816 continue;
817 }
818
819 if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
820 continue;
821
822 if (!wpa &&
823 !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
824 !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
825 !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
826 wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
827 "not allowed");
828 continue;
829 }
830
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700831 if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
832 has_wep_key(ssid)) {
833 wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
834 continue;
835 }
836
Jouni Malinen75ecf522011-06-27 15:19:46 -0700837 if (!wpa_supplicant_match_privacy(bss, ssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
839 "mismatch");
840 continue;
841 }
842
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800843 if (!bss_is_ess(bss)) {
844 wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 continue;
846 }
847
848 if (!freq_allowed(ssid->freq_list, bss->freq)) {
849 wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
850 "allowed");
851 continue;
852 }
853
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800854 if (!rate_match(wpa_s, bss)) {
855 wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
856 "not match");
857 continue;
858 }
859
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700860#ifdef CONFIG_P2P
861 /*
862 * TODO: skip the AP if its P2P IE has Group Formation
863 * bit set in the P2P Group Capability Bitmap and we
864 * are not in Group Formation with that device.
865 */
866#endif /* CONFIG_P2P */
867
868 /* Matching configuration found */
869 return ssid;
870 }
871
872 /* No matching configuration found */
873 return NULL;
874}
875
876
877static struct wpa_bss *
878wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700879 struct wpa_ssid *group,
880 struct wpa_ssid **selected_ssid)
881{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700882 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700883
884 wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
885 group->priority);
886
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700887 for (i = 0; i < wpa_s->last_scan_res_used; i++) {
888 struct wpa_bss *bss = wpa_s->last_scan_res[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700889 *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
890 if (!*selected_ssid)
891 continue;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700892 wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
893 " ssid='%s'",
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700894 MAC2STR(bss->bssid),
895 wpa_ssid_txt(bss->ssid, bss->ssid_len));
896 return bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700897 }
898
899 return NULL;
900}
901
902
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700903struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
904 struct wpa_ssid **selected_ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700905{
906 struct wpa_bss *selected = NULL;
907 int prio;
908
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700909 if (wpa_s->last_scan_res == NULL ||
910 wpa_s->last_scan_res_used == 0)
911 return NULL; /* no scan results from last update */
912
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700913 while (selected == NULL) {
914 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
915 selected = wpa_supplicant_select_bss(
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -0700916 wpa_s, wpa_s->conf->pssid[prio],
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700917 selected_ssid);
918 if (selected)
919 break;
920 }
921
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800922 if (selected == NULL && wpa_s->blacklist &&
923 !wpa_s->countermeasures) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700924 wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
925 "blacklist and try again");
926 wpa_blacklist_clear(wpa_s);
927 wpa_s->blacklist_cleared++;
928 } else if (selected == NULL)
929 break;
930 }
931
932 return selected;
933}
934
935
936static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
937 int timeout_sec, int timeout_usec)
938{
Dmitry Shmidt04949592012-07-19 12:16:46 -0700939 if (!wpa_supplicant_enabled_networks(wpa_s)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700940 /*
941 * No networks are enabled; short-circuit request so
942 * we don't wait timeout seconds before transitioning
943 * to INACTIVE state.
944 */
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700945 wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
946 "since there are no enabled networks");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700947 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
Dmitry Shmidtaa532512012-09-24 10:35:31 -0700948#ifdef CONFIG_P2P
949 wpa_s->sta_scan_pending = 0;
950#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951 return;
952 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800953
954 wpa_s->scan_for_connection = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700955 wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
956}
957
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800958
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700959int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800960 struct wpa_bss *selected,
961 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700962{
963 if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
964 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
965 "PBC session overlap");
966#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800967 if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700968 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700969#endif /* CONFIG_P2P */
970
971#ifdef CONFIG_WPS
972 wpas_wps_cancel(wpa_s);
973#endif /* CONFIG_WPS */
Dmitry Shmidt44da0252011-08-23 12:30:30 -0700974 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700975 }
976
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -0700977 wpa_msg(wpa_s, MSG_DEBUG,
978 "Considering connect request: reassociate: %d selected: "
979 MACSTR " bssid: " MACSTR " pending: " MACSTR
980 " wpa_state: %s ssid=%p current_ssid=%p",
981 wpa_s->reassociate, MAC2STR(selected->bssid),
982 MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
983 wpa_supplicant_state_txt(wpa_s->wpa_state),
984 ssid, wpa_s->current_ssid);
985
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700986 /*
987 * Do not trigger new association unless the BSSID has changed or if
988 * reassociation is requested. If we are in process of associating with
989 * the selected BSSID, do not trigger new attempt.
990 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800991 if (wpa_s->reassociate ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992 (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
993 ((wpa_s->wpa_state != WPA_ASSOCIATING &&
994 wpa_s->wpa_state != WPA_AUTHENTICATING) ||
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -0700995 (!is_zero_ether_addr(wpa_s->pending_bssid) &&
996 os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
997 0) ||
998 (is_zero_ether_addr(wpa_s->pending_bssid) &&
999 ssid != wpa_s->current_ssid)))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001000 if (wpa_supplicant_scard_init(wpa_s, ssid)) {
1001 wpa_supplicant_req_new_scan(wpa_s, 10, 0);
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001002 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001003 }
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001004 wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
1005 MAC2STR(selected->bssid));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001006 wpa_supplicant_associate(wpa_s, selected, ssid);
1007 } else {
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07001008 wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
1009 "connect with the selected AP");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001010 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001011
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001012 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001013}
1014
1015
1016static struct wpa_ssid *
1017wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
1018{
1019 int prio;
1020 struct wpa_ssid *ssid;
1021
1022 for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
1023 for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
1024 {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001025 if (wpas_network_disabled(wpa_s, ssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001026 continue;
1027 if (ssid->mode == IEEE80211_MODE_IBSS ||
1028 ssid->mode == IEEE80211_MODE_AP)
1029 return ssid;
1030 }
1031 }
1032 return NULL;
1033}
1034
1035
1036/* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
1037 * on BSS added and BSS changed events */
1038static void wpa_supplicant_rsn_preauth_scan_results(
Jouni Malinen87fd2792011-05-16 18:35:42 +03001039 struct wpa_supplicant *wpa_s)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040{
Jouni Malinen87fd2792011-05-16 18:35:42 +03001041 struct wpa_bss *bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001042
1043 if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
1044 return;
1045
Jouni Malinen87fd2792011-05-16 18:35:42 +03001046 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001047 const u8 *ssid, *rsn;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001048
Jouni Malinen87fd2792011-05-16 18:35:42 +03001049 ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001050 if (ssid == NULL)
1051 continue;
1052
Jouni Malinen87fd2792011-05-16 18:35:42 +03001053 rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001054 if (rsn == NULL)
1055 continue;
1056
Jouni Malinen87fd2792011-05-16 18:35:42 +03001057 rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001058 }
1059
1060}
1061
1062
1063static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
1064 struct wpa_bss *selected,
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001065 struct wpa_ssid *ssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001066{
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001067 struct wpa_bss *current_bss = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001068 int min_diff;
1069
1070 if (wpa_s->reassociate)
1071 return 1; /* explicit request to reassociate */
1072 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1073 return 1; /* we are not associated; continue */
1074 if (wpa_s->current_ssid == NULL)
1075 return 1; /* unknown current SSID */
1076 if (wpa_s->current_ssid != ssid)
1077 return 1; /* different network block */
1078
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001079 if (wpas_driver_bss_selection(wpa_s))
1080 return 0; /* Driver-based roaming */
1081
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001082 if (wpa_s->current_ssid->ssid)
1083 current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
1084 wpa_s->current_ssid->ssid,
1085 wpa_s->current_ssid->ssid_len);
1086 if (!current_bss)
1087 current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088
1089 if (!current_bss)
1090 return 1; /* current BSS not seen in scan results */
1091
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001092 if (current_bss == selected)
1093 return 0;
1094
1095 if (selected->last_update_idx > current_bss->last_update_idx)
1096 return 1; /* current BSS not seen in the last scan */
1097
Dmitry Shmidt9e077672012-04-13 10:07:27 -07001098#ifndef CONFIG_NO_ROAMING
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001099 wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
1100 wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
1101 MAC2STR(current_bss->bssid), current_bss->level);
1102 wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
1103 MAC2STR(selected->bssid), selected->level);
1104
1105 if (wpa_s->current_ssid->bssid_set &&
1106 os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
1107 0) {
1108 wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
1109 "has preferred BSSID");
1110 return 1;
1111 }
1112
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001113 if (current_bss->level < 0 && current_bss->level > selected->level) {
1114 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
1115 "signal level");
1116 return 0;
1117 }
1118
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001119 min_diff = 2;
1120 if (current_bss->level < 0) {
1121 if (current_bss->level < -85)
1122 min_diff = 1;
1123 else if (current_bss->level < -80)
1124 min_diff = 2;
1125 else if (current_bss->level < -75)
1126 min_diff = 3;
1127 else if (current_bss->level < -70)
1128 min_diff = 4;
1129 else
1130 min_diff = 5;
1131 }
1132 if (abs(current_bss->level - selected->level) < min_diff) {
1133 wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
1134 "in signal level");
1135 return 0;
1136 }
1137
1138 return 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001139#else /* CONFIG_NO_ROAMING */
Dmitry Shmidtefdec2e2011-08-16 11:55:46 -07001140 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001141#endif /* CONFIG_NO_ROAMING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001142}
1143
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001144
Jouni Malinen89ca7022012-09-14 13:03:12 -07001145/* Return != 0 if no scan results could be fetched or if scan results should not
Dmitry Shmidt04949592012-07-19 12:16:46 -07001146 * be shared with other virtual interfaces. */
Dmitry Shmidtf6c92c42012-01-26 12:57:43 -08001147static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001148 union wpa_event_data *data,
1149 int own_request)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001150{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001151 struct wpa_scan_results *scan_res;
1152 int ap = 0;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001153#ifndef CONFIG_NO_RANDOM_POOL
1154 size_t i, num;
1155#endif /* CONFIG_NO_RANDOM_POOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001156
1157#ifdef CONFIG_AP
1158 if (wpa_s->ap_iface)
1159 ap = 1;
1160#endif /* CONFIG_AP */
1161
1162 wpa_supplicant_notify_scanning(wpa_s, 0);
1163
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001164#ifdef CONFIG_P2P
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001165 if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
Jouni Malinendc7b7132012-09-14 12:53:47 -07001166 !wpa_s->global->p2p_disabled &&
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001167 wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
1168 !wpa_s->scan_res_handler) {
Jouni Malinendc7b7132012-09-14 12:53:47 -07001169 wpa_s->global->p2p_cb_on_scan_complete = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001170 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
1171 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
1172 "stopped scan processing");
Jouni Malinenfa08f9e2012-09-13 18:05:55 -07001173 wpa_s->sta_scan_pending = 1;
1174 wpa_supplicant_req_scan(wpa_s, 5, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001175 return -1;
1176 }
1177 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001178 wpa_s->sta_scan_pending = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001179#endif /* CONFIG_P2P */
1180
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001181 scan_res = wpa_supplicant_get_scan_results(wpa_s,
1182 data ? &data->scan_info :
1183 NULL, 1);
1184 if (scan_res == NULL) {
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001185 if (wpa_s->conf->ap_scan == 2 || ap ||
1186 wpa_s->scan_res_handler == scan_only_handler)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001187 return -1;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001188 if (!own_request)
1189 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001190 wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
1191 "scanning again");
1192 wpa_supplicant_req_new_scan(wpa_s, 1, 0);
1193 return -1;
1194 }
1195
1196#ifndef CONFIG_NO_RANDOM_POOL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001197 num = scan_res->num;
1198 if (num > 10)
1199 num = 10;
1200 for (i = 0; i < num; i++) {
1201 u8 buf[5];
1202 struct wpa_scan_res *res = scan_res->res[i];
1203 buf[0] = res->bssid[5];
1204 buf[1] = res->qual & 0xff;
1205 buf[2] = res->noise & 0xff;
1206 buf[3] = res->level & 0xff;
1207 buf[4] = res->tsf & 0xff;
1208 random_add_randomness(buf, sizeof(buf));
1209 }
1210#endif /* CONFIG_NO_RANDOM_POOL */
1211
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001212 if (own_request && wpa_s->scan_res_handler) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001213 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
1214 struct wpa_scan_results *scan_res);
1215
1216 scan_res_handler = wpa_s->scan_res_handler;
1217 wpa_s->scan_res_handler = NULL;
1218 scan_res_handler(wpa_s, scan_res);
1219
1220 wpa_scan_results_free(scan_res);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001221 return -2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001222 }
1223
1224 if (ap) {
1225 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
1226#ifdef CONFIG_AP
1227 if (wpa_s->ap_iface->scan_cb)
1228 wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
1229#endif /* CONFIG_AP */
1230 wpa_scan_results_free(scan_res);
1231 return 0;
1232 }
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001233
Dmitry Shmidt04949592012-07-19 12:16:46 -07001234 wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
1235 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
1236 wpas_notify_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001237
1238 wpas_notify_scan_done(wpa_s, 1);
1239
Dmitry Shmidt04949592012-07-19 12:16:46 -07001240 if (sme_proc_obss_scan(wpa_s) > 0) {
1241 wpa_scan_results_free(scan_res);
1242 return 0;
1243 }
1244
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245 if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
1246 wpa_scan_results_free(scan_res);
1247 return 0;
1248 }
1249
Dmitry Shmidt04949592012-07-19 12:16:46 -07001250 if (autoscan_notify_scan(wpa_s, scan_res)) {
1251 wpa_scan_results_free(scan_res);
1252 return 0;
1253 }
1254
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001255 if (wpa_s->disconnected) {
1256 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
1257 wpa_scan_results_free(scan_res);
1258 return 0;
1259 }
1260
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001261 if (!wpas_driver_bss_selection(wpa_s) &&
1262 bgscan_notify_scan(wpa_s, scan_res) == 1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001263 wpa_scan_results_free(scan_res);
1264 return 0;
1265 }
1266
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001267 wpas_wps_update_ap_info(wpa_s, scan_res);
1268
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001269 wpa_scan_results_free(scan_res);
1270
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001271 return wpas_select_network_from_last_scan(wpa_s, 1);
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001272}
1273
1274
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001275static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
1276 int new_scan)
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001277{
1278 struct wpa_bss *selected;
1279 struct wpa_ssid *ssid = NULL;
1280
1281 selected = wpa_supplicant_pick_network(wpa_s, &ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001282
1283 if (selected) {
1284 int skip;
Dmitry Shmidt9bce59c2012-09-11 15:06:38 -07001285 skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001286 if (skip) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001287 if (new_scan)
1288 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001289 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001290 }
1291
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001292 if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001293 wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
Dmitry Shmidt44da0252011-08-23 12:30:30 -07001294 return -1;
1295 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001296 if (new_scan)
1297 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001298 /*
1299 * Do not notify other virtual radios of scan results since we do not
1300 * want them to start other associations at the same time.
1301 */
1302 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001303 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001304 wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
1305 ssid = wpa_supplicant_pick_new_network(wpa_s);
1306 if (ssid) {
1307 wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
1308 wpa_supplicant_associate(wpa_s, NULL, ssid);
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001309 if (new_scan)
1310 wpa_supplicant_rsn_preauth_scan_results(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001311 } else {
1312 int timeout_sec = wpa_s->scan_interval;
1313 int timeout_usec = 0;
1314#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001315 if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
1316 return 0;
1317
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001318 if (wpa_s->p2p_in_provisioning) {
1319 /*
1320 * Use shorter wait during P2P Provisioning
1321 * state to speed up group formation.
1322 */
1323 timeout_sec = 0;
1324 timeout_usec = 250000;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001325 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1326 timeout_usec);
1327 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001328 }
1329#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001330#ifdef CONFIG_INTERWORKING
1331 if (wpa_s->conf->auto_interworking &&
1332 wpa_s->conf->interworking &&
1333 wpa_s->conf->cred) {
1334 wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
1335 "start ANQP fetch since no matching "
1336 "networks found");
1337 wpa_s->network_select = 1;
1338 wpa_s->auto_network_select = 1;
1339 interworking_start_fetch_anqp(wpa_s);
Jouni Malinen89ca7022012-09-14 13:03:12 -07001340 return 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001341 }
1342#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001343 if (wpa_supplicant_req_sched_scan(wpa_s))
1344 wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
1345 timeout_usec);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001346 }
1347 }
1348 return 0;
1349}
1350
1351
1352static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
1353 union wpa_event_data *data)
1354{
1355 const char *rn, *rn2;
1356 struct wpa_supplicant *ifs;
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001357
1358 if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001359 /*
1360 * If no scan results could be fetched, then no need to
1361 * notify those interfaces that did not actually request
Jouni Malinen89ca7022012-09-14 13:03:12 -07001362 * this scan. Similarly, if scan results started a new operation on this
1363 * interface, do not notify other interfaces to avoid concurrent
1364 * operations during a connection attempt.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001365 */
1366 return;
1367 }
1368
1369 /*
1370 * Check other interfaces to see if they have the same radio-name. If
1371 * so, they get updated with this same scan info.
1372 */
1373 if (!wpa_s->driver->get_radio_name)
1374 return;
1375
1376 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
1377 if (rn == NULL || rn[0] == '\0')
1378 return;
1379
1380 wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
1381 "sharing same radio (%s) in event_scan_results", rn);
1382
1383 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
1384 if (ifs == wpa_s || !ifs->driver->get_radio_name)
1385 continue;
1386
1387 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
1388 if (rn2 && os_strcmp(rn, rn2) == 0) {
1389 wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
1390 "sibling", ifs->ifname);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07001391 _wpa_supplicant_event_scan_results(ifs, data, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001392 }
1393 }
1394}
1395
1396#endif /* CONFIG_NO_SCAN_PROCESSING */
1397
1398
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001399int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
1400{
1401#ifdef CONFIG_NO_SCAN_PROCESSING
1402 return -1;
1403#else /* CONFIG_NO_SCAN_PROCESSING */
1404 struct os_time now;
1405
1406 if (wpa_s->last_scan_res_used <= 0)
1407 return -1;
1408
1409 os_get_time(&now);
1410 if (now.sec - wpa_s->last_scan.sec > 5) {
1411 wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
1412 return -1;
1413 }
1414
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001415 return wpas_select_network_from_last_scan(wpa_s, 0);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001416#endif /* CONFIG_NO_SCAN_PROCESSING */
1417}
1418
Dmitry Shmidt04949592012-07-19 12:16:46 -07001419#ifdef CONFIG_WNM
1420
1421static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
1422{
1423 struct wpa_supplicant *wpa_s = eloop_ctx;
1424
1425 if (wpa_s->wpa_state < WPA_ASSOCIATED)
1426 return;
1427
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001428 if (!wpa_s->no_keep_alive) {
1429 wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
1430 MAC2STR(wpa_s->bssid));
1431 /* TODO: could skip this if normal data traffic has been sent */
1432 /* TODO: Consider using some more appropriate data frame for
1433 * this */
1434 if (wpa_s->l2)
1435 l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
1436 (u8 *) "", 0);
1437 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001438
1439#ifdef CONFIG_SME
1440 if (wpa_s->sme.bss_max_idle_period) {
1441 unsigned int msec;
1442 msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
1443 if (msec > 100)
1444 msec -= 100;
1445 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1446 wnm_bss_keep_alive, wpa_s, NULL);
1447 }
1448#endif /* CONFIG_SME */
1449}
1450
1451
1452static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
1453 const u8 *ies, size_t ies_len)
1454{
1455 struct ieee802_11_elems elems;
1456
1457 if (ies == NULL)
1458 return;
1459
1460 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
1461 return;
1462
1463#ifdef CONFIG_SME
1464 if (elems.bss_max_idle_period) {
1465 unsigned int msec;
1466 wpa_s->sme.bss_max_idle_period =
1467 WPA_GET_LE16(elems.bss_max_idle_period);
1468 wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
1469 "TU)%s", wpa_s->sme.bss_max_idle_period,
1470 (elems.bss_max_idle_period[2] & 0x01) ?
1471 " (protected keep-live required)" : "");
1472 if (wpa_s->sme.bss_max_idle_period == 0)
1473 wpa_s->sme.bss_max_idle_period = 1;
1474 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
1475 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1476 /* msec times 1000 */
1477 msec = wpa_s->sme.bss_max_idle_period * 1024;
1478 if (msec > 100)
1479 msec -= 100;
1480 eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
1481 wnm_bss_keep_alive, wpa_s,
1482 NULL);
1483 }
1484 }
1485#endif /* CONFIG_SME */
1486}
1487
1488#endif /* CONFIG_WNM */
1489
1490
1491void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
1492{
1493#ifdef CONFIG_WNM
1494 eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
1495#endif /* CONFIG_WNM */
1496}
1497
1498
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001499static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
1500 union wpa_event_data *data)
1501{
1502 int l, len, found = 0, wpa_found, rsn_found;
1503 const u8 *p;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001504#ifdef CONFIG_IEEE80211R
1505 u8 bssid[ETH_ALEN];
1506#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001507
1508 wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
1509 if (data->assoc_info.req_ies)
1510 wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
1511 data->assoc_info.req_ies_len);
1512 if (data->assoc_info.resp_ies) {
1513 wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
1514 data->assoc_info.resp_ies_len);
1515#ifdef CONFIG_TDLS
1516 wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
1517 data->assoc_info.resp_ies_len);
1518#endif /* CONFIG_TDLS */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001519#ifdef CONFIG_WNM
1520 wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
1521 data->assoc_info.resp_ies_len);
1522#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001523 }
1524 if (data->assoc_info.beacon_ies)
1525 wpa_hexdump(MSG_DEBUG, "beacon_ies",
1526 data->assoc_info.beacon_ies,
1527 data->assoc_info.beacon_ies_len);
1528 if (data->assoc_info.freq)
1529 wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
1530 data->assoc_info.freq);
1531
1532 p = data->assoc_info.req_ies;
1533 l = data->assoc_info.req_ies_len;
1534
1535 /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
1536 while (p && l >= 2) {
1537 len = p[1] + 2;
1538 if (len > l) {
1539 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1540 p, l);
1541 break;
1542 }
1543 if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1544 (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
1545 (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
1546 if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
1547 break;
1548 found = 1;
1549 wpa_find_assoc_pmkid(wpa_s);
1550 break;
1551 }
1552 l -= len;
1553 p += len;
1554 }
1555 if (!found && data->assoc_info.req_ies)
1556 wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
1557
1558#ifdef CONFIG_IEEE80211R
1559#ifdef CONFIG_SME
1560 if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001561 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1562 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1563 data->assoc_info.resp_ies,
1564 data->assoc_info.resp_ies_len,
1565 bssid) < 0) {
1566 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1567 "Reassociation Response failed");
1568 wpa_supplicant_deauthenticate(
1569 wpa_s, WLAN_REASON_INVALID_IE);
1570 return -1;
1571 }
1572 }
1573
1574 p = data->assoc_info.resp_ies;
1575 l = data->assoc_info.resp_ies_len;
1576
1577#ifdef CONFIG_WPS_STRICT
1578 if (p && wpa_s->current_ssid &&
1579 wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
1580 struct wpabuf *wps;
1581 wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
1582 if (wps == NULL) {
1583 wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
1584 "include WPS IE in (Re)Association Response");
1585 return -1;
1586 }
1587
1588 if (wps_validate_assoc_resp(wps) < 0) {
1589 wpabuf_free(wps);
1590 wpa_supplicant_deauthenticate(
1591 wpa_s, WLAN_REASON_INVALID_IE);
1592 return -1;
1593 }
1594 wpabuf_free(wps);
1595 }
1596#endif /* CONFIG_WPS_STRICT */
1597
1598 /* Go through the IEs and make a copy of the MDIE, if present. */
1599 while (p && l >= 2) {
1600 len = p[1] + 2;
1601 if (len > l) {
1602 wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
1603 p, l);
1604 break;
1605 }
1606 if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
1607 p[1] >= MOBILITY_DOMAIN_ID_LEN) {
1608 wpa_s->sme.ft_used = 1;
1609 os_memcpy(wpa_s->sme.mobility_domain, p + 2,
1610 MOBILITY_DOMAIN_ID_LEN);
1611 break;
1612 }
1613 l -= len;
1614 p += len;
1615 }
1616#endif /* CONFIG_SME */
1617
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001618 /* Process FT when SME is in the driver */
1619 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
1620 wpa_ft_is_completed(wpa_s->wpa)) {
1621 if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
1622 wpa_ft_validate_reassoc_resp(wpa_s->wpa,
1623 data->assoc_info.resp_ies,
1624 data->assoc_info.resp_ies_len,
1625 bssid) < 0) {
1626 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
1627 "Reassociation Response failed");
1628 wpa_supplicant_deauthenticate(
1629 wpa_s, WLAN_REASON_INVALID_IE);
1630 return -1;
1631 }
1632 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
1633 }
1634
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001635 wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
1636 data->assoc_info.resp_ies_len);
1637#endif /* CONFIG_IEEE80211R */
1638
1639 /* WPA/RSN IE from Beacon/ProbeResp */
1640 p = data->assoc_info.beacon_ies;
1641 l = data->assoc_info.beacon_ies_len;
1642
1643 /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
1644 */
1645 wpa_found = rsn_found = 0;
1646 while (p && l >= 2) {
1647 len = p[1] + 2;
1648 if (len > l) {
1649 wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
1650 p, l);
1651 break;
1652 }
1653 if (!wpa_found &&
1654 p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
1655 os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
1656 wpa_found = 1;
1657 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
1658 }
1659
1660 if (!rsn_found &&
1661 p[0] == WLAN_EID_RSN && p[1] >= 2) {
1662 rsn_found = 1;
1663 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
1664 }
1665
1666 l -= len;
1667 p += len;
1668 }
1669
1670 if (!wpa_found && data->assoc_info.beacon_ies)
1671 wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
1672 if (!rsn_found && data->assoc_info.beacon_ies)
1673 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
1674 if (wpa_found || rsn_found)
1675 wpa_s->ap_ies_from_associnfo = 1;
1676
Jouni Malinen87fd2792011-05-16 18:35:42 +03001677 if (wpa_s->assoc_freq && data->assoc_info.freq &&
1678 wpa_s->assoc_freq != data->assoc_info.freq) {
1679 wpa_printf(MSG_DEBUG, "Operating frequency changed from "
1680 "%u to %u MHz",
1681 wpa_s->assoc_freq, data->assoc_info.freq);
1682 wpa_supplicant_update_scan_results(wpa_s);
1683 }
1684
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001685 wpa_s->assoc_freq = data->assoc_info.freq;
1686
1687 return 0;
1688}
1689
1690
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001691static struct wpa_bss * wpa_supplicant_get_new_bss(
1692 struct wpa_supplicant *wpa_s, const u8 *bssid)
1693{
1694 struct wpa_bss *bss = NULL;
1695 struct wpa_ssid *ssid = wpa_s->current_ssid;
1696
1697 if (ssid->ssid_len > 0)
1698 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
1699 if (!bss)
1700 bss = wpa_bss_get_bssid(wpa_s, bssid);
1701
1702 return bss;
1703}
1704
1705
1706static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
1707{
1708 const u8 *bss_wpa = NULL, *bss_rsn = NULL;
1709
1710 if (!wpa_s->current_bss || !wpa_s->current_ssid)
1711 return -1;
1712
1713 if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
1714 return 0;
1715
1716 bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1717 WPA_IE_VENDOR_TYPE);
1718 bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
1719
1720 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
1721 bss_wpa ? 2 + bss_wpa[1] : 0) ||
1722 wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
1723 bss_rsn ? 2 + bss_rsn[1] : 0))
1724 return -1;
1725
1726 return 0;
1727}
1728
1729
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001730static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
1731 union wpa_event_data *data)
1732{
1733 u8 bssid[ETH_ALEN];
1734 int ft_completed;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001735
1736#ifdef CONFIG_AP
1737 if (wpa_s->ap_iface) {
1738 hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
1739 data->assoc_info.addr,
1740 data->assoc_info.req_ies,
1741 data->assoc_info.req_ies_len,
1742 data->assoc_info.reassoc);
1743 return;
1744 }
1745#endif /* CONFIG_AP */
1746
1747 ft_completed = wpa_ft_is_completed(wpa_s->wpa);
1748 if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
1749 return;
1750
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001751 if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
1752 wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001753 wpa_supplicant_deauthenticate(
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001754 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1755 return;
1756 }
1757
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001758 wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001759 if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001760 wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
1761 MACSTR, MAC2STR(bssid));
1762 random_add_randomness(bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001763 os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
1764 os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001765 wpas_notify_bssid_changed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001766
1767 if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
1768 wpa_clear_keys(wpa_s, bssid);
1769 }
1770 if (wpa_supplicant_select_config(wpa_s) < 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001771 wpa_supplicant_deauthenticate(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001772 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1773 return;
1774 }
1775 if (wpa_s->current_ssid) {
1776 struct wpa_bss *bss = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001777
1778 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1779 if (!bss) {
1780 wpa_supplicant_update_scan_results(wpa_s);
1781
1782 /* Get the BSS from the new scan results */
1783 bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
1784 }
1785
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001786 if (bss)
1787 wpa_s->current_bss = bss;
1788 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001789
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001790#ifdef ANDROID
1791 if (wpa_s->conf->ap_scan == 1) {
1792#else
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001793 if (wpa_s->conf->ap_scan == 1 &&
1794 wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
Dmitry Shmidt1e1c48d2013-02-14 16:44:44 -08001795#endif
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001796 if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
1797 wpa_msg(wpa_s, MSG_WARNING,
1798 "WPA/RSN IEs not updated");
1799 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001800 }
1801
1802#ifdef CONFIG_SME
1803 os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
1804 wpa_s->sme.prev_bssid_set = 1;
1805#endif /* CONFIG_SME */
1806
1807 wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
1808 if (wpa_s->current_ssid) {
1809 /* When using scanning (ap_scan=1), SIM PC/SC interface can be
1810 * initialized before association, but for other modes,
1811 * initialize PC/SC here, if the current configuration needs
1812 * smartcard or SIM/USIM. */
1813 wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
1814 }
1815 wpa_sm_notify_assoc(wpa_s->wpa, bssid);
1816 if (wpa_s->l2)
1817 l2_packet_notify_auth_start(wpa_s->l2);
1818
1819 /*
1820 * Set portEnabled first to FALSE in order to get EAP state machine out
1821 * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
1822 * state machine may transit to AUTHENTICATING state based on obsolete
1823 * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
1824 * AUTHENTICATED without ever giving chance to EAP state machine to
1825 * reset the state.
1826 */
1827 if (!ft_completed) {
1828 eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
1829 eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
1830 }
1831 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
1832 eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
1833 /* 802.1X::portControl = Auto */
1834 eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
1835 wpa_s->eapol_received = 0;
1836 if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1837 wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
1838 (wpa_s->current_ssid &&
1839 wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001840 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
1841 (wpa_s->drv_flags &
1842 WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
1843 /*
1844 * Set the key after having received joined-IBSS event
1845 * from the driver.
1846 */
1847 wpa_supplicant_set_wpa_none_key(wpa_s,
1848 wpa_s->current_ssid);
1849 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001850 wpa_supplicant_cancel_auth_timeout(wpa_s);
1851 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1852 } else if (!ft_completed) {
1853 /* Timeout for receiving the first EAPOL packet */
1854 wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
1855 }
1856 wpa_supplicant_cancel_scan(wpa_s);
1857
1858 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1859 wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
1860 /*
1861 * We are done; the driver will take care of RSN 4-way
1862 * handshake.
1863 */
1864 wpa_supplicant_cancel_auth_timeout(wpa_s);
1865 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1866 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1867 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1868 } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
1869 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1870 /*
1871 * The driver will take care of RSN 4-way handshake, so we need
1872 * to allow EAPOL supplicant to complete its work without
1873 * waiting for WPA supplicant.
1874 */
1875 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1876 } else if (ft_completed) {
1877 /*
1878 * FT protocol completed - make sure EAPOL state machine ends
1879 * up in authenticated.
1880 */
1881 wpa_supplicant_cancel_auth_timeout(wpa_s);
1882 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
1883 eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
1884 eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
1885 }
1886
Jouni Malinena05074c2012-12-21 21:35:35 +02001887 wpa_s->last_eapol_matches_bssid = 0;
1888
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001889 if (wpa_s->pending_eapol_rx) {
1890 struct os_time now, age;
1891 os_get_time(&now);
1892 os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
1893 if (age.sec == 0 && age.usec < 100000 &&
1894 os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
1895 0) {
1896 wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
1897 "frame that was received just before "
1898 "association notification");
1899 wpa_supplicant_rx_eapol(
1900 wpa_s, wpa_s->pending_eapol_rx_src,
1901 wpabuf_head(wpa_s->pending_eapol_rx),
1902 wpabuf_len(wpa_s->pending_eapol_rx));
1903 }
1904 wpabuf_free(wpa_s->pending_eapol_rx);
1905 wpa_s->pending_eapol_rx = NULL;
1906 }
1907
1908 if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
1909 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07001910 wpa_s->current_ssid &&
1911 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001912 /* Set static WEP keys again */
1913 wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
1914 }
1915
1916#ifdef CONFIG_IBSS_RSN
1917 if (wpa_s->current_ssid &&
1918 wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
1919 wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
1920 wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
1921 wpa_s->ibss_rsn == NULL) {
1922 wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
1923 if (!wpa_s->ibss_rsn) {
1924 wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
1925 wpa_supplicant_deauthenticate(
1926 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1927 return;
1928 }
1929
1930 ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
1931 }
1932#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001933
1934 wpas_wps_notify_assoc(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001935}
1936
1937
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001938static int disconnect_reason_recoverable(u16 reason_code)
1939{
1940 return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
1941 reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
1942 reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
1943}
1944
1945
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001946static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001947 u16 reason_code,
1948 int locally_generated)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001949{
1950 const u8 *bssid;
Jouni Malinen2b89da82012-08-31 22:04:41 +03001951
1952 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
1953 /*
1954 * At least Host AP driver and a Prism3 card seemed to be
1955 * generating streams of disconnected events when configuring
1956 * IBSS for WPA-None. Ignore them for now.
1957 */
1958 return;
1959 }
1960
1961 bssid = wpa_s->bssid;
1962 if (is_zero_ether_addr(bssid))
1963 bssid = wpa_s->pending_bssid;
1964
1965 if (!is_zero_ether_addr(bssid) ||
1966 wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1967 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1968 " reason=%d%s",
1969 MAC2STR(bssid), reason_code,
1970 locally_generated ? " locally_generated=1" : "");
1971 }
1972}
1973
1974
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001975static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
1976 int locally_generated)
1977{
1978 if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
1979 !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
1980 return 0; /* Not in 4-way handshake with PSK */
1981
1982 /*
1983 * It looks like connection was lost while trying to go through PSK
1984 * 4-way handshake. Filter out known disconnection cases that are caused
1985 * by something else than PSK mismatch to avoid confusing reports.
1986 */
1987
1988 if (locally_generated) {
1989 if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
1990 return 0;
1991 }
1992
1993 return 1;
1994}
1995
1996
Jouni Malinen2b89da82012-08-31 22:04:41 +03001997static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
1998 u16 reason_code,
1999 int locally_generated)
2000{
2001 const u8 *bssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002002 int authenticating;
2003 u8 prev_pending_bssid[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002004 struct wpa_bss *fast_reconnect = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002005#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002006 struct wpa_ssid *fast_reconnect_ssid = NULL;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002007#endif /* CONFIG_NO_SCAN_PROCESSING */
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002008 struct wpa_ssid *last_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002009
2010 authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
2011 os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
2012
2013 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
2014 /*
2015 * At least Host AP driver and a Prism3 card seemed to be
2016 * generating streams of disconnected events when configuring
2017 * IBSS for WPA-None. Ignore them for now.
2018 */
2019 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
2020 "IBSS/WPA-None mode");
2021 return;
2022 }
2023
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002024 if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002025 wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
2026 "pre-shared key may be incorrect");
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002027 if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
2028 return; /* P2P group removed */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002029 wpas_auth_failed(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002030 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07002031 if (!wpa_s->disconnected &&
2032 (!wpa_s->auto_reconnect_disabled ||
2033 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002034 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
2035 "reconnect (wps=%d wpa_state=%d)",
2036 wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
2037 wpa_s->wpa_state);
2038 if (wpa_s->wpa_state == WPA_COMPLETED &&
2039 wpa_s->current_ssid &&
2040 wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002041 !locally_generated &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002042 disconnect_reason_recoverable(reason_code)) {
2043 /*
2044 * It looks like the AP has dropped association with
2045 * us, but could allow us to get back in. Try to
2046 * reconnect to the same BSS without full scan to save
2047 * time for some common cases.
2048 */
2049 fast_reconnect = wpa_s->current_bss;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002050#ifndef CONFIG_NO_SCAN_PROCESSING
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002051 fast_reconnect_ssid = wpa_s->current_ssid;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002052#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002053 } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002054#ifdef ANDROID
Dmitry Shmidt43007fd2011-04-11 15:58:40 -07002055 wpa_supplicant_req_scan(wpa_s, 0, 500000);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002056#else
2057 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2058#endif
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002059 else
2060 wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
2061 "immediate scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002062 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002063 wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002064 "try to re-connect");
2065 wpa_s->reassociate = 0;
2066 wpa_s->disconnected = 1;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002067 wpa_supplicant_cancel_sched_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002068 }
2069 bssid = wpa_s->bssid;
2070 if (is_zero_ether_addr(bssid))
2071 bssid = wpa_s->pending_bssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002072 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2073 wpas_connection_failed(wpa_s, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002074 wpa_sm_notify_disassoc(wpa_s->wpa);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002075 if (locally_generated)
2076 wpa_s->disconnect_reason = -reason_code;
2077 else
2078 wpa_s->disconnect_reason = reason_code;
2079 wpas_notify_disconnect_reason(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002080 if (wpa_supplicant_dynamic_keys(wpa_s)) {
2081 wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
2082 wpa_s->keys_cleared = 0;
2083 wpa_clear_keys(wpa_s, wpa_s->bssid);
2084 }
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002085 last_ssid = wpa_s->current_ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002086 wpa_supplicant_mark_disassoc(wpa_s);
2087
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002088 if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002089 sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
Jouni Malinenf8a26a82012-09-01 17:20:27 +03002090 wpa_s->current_ssid = last_ssid;
2091 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002092
2093 if (fast_reconnect) {
2094#ifndef CONFIG_NO_SCAN_PROCESSING
2095 wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
2096 if (wpa_supplicant_connect(wpa_s, fast_reconnect,
2097 fast_reconnect_ssid) < 0) {
2098 /* Recover through full scan */
2099 wpa_supplicant_req_scan(wpa_s, 0, 100000);
2100 }
2101#endif /* CONFIG_NO_SCAN_PROCESSING */
2102 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002103}
2104
2105
2106#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002107void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002108{
2109 struct wpa_supplicant *wpa_s = eloop_ctx;
2110
2111 if (!wpa_s->pending_mic_error_report)
2112 return;
2113
2114 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
2115 wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
2116 wpa_s->pending_mic_error_report = 0;
2117}
2118#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2119
2120
2121static void
2122wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
2123 union wpa_event_data *data)
2124{
2125 int pairwise;
2126 struct os_time t;
2127
2128 wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
2129 pairwise = (data && data->michael_mic_failure.unicast);
2130 os_get_time(&t);
2131 if ((wpa_s->last_michael_mic_error &&
2132 t.sec - wpa_s->last_michael_mic_error <= 60) ||
2133 wpa_s->pending_mic_error_report) {
2134 if (wpa_s->pending_mic_error_report) {
2135 /*
2136 * Send the pending MIC error report immediately since
2137 * we are going to start countermeasures and AP better
2138 * do the same.
2139 */
2140 wpa_sm_key_request(wpa_s->wpa, 1,
2141 wpa_s->pending_mic_error_pairwise);
2142 }
2143
2144 /* Send the new MIC error report immediately since we are going
2145 * to start countermeasures and AP better do the same.
2146 */
2147 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2148
2149 /* initialize countermeasures */
2150 wpa_s->countermeasures = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002151
2152 wpa_blacklist_add(wpa_s, wpa_s->bssid);
2153
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002154 wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
2155
2156 /*
2157 * Need to wait for completion of request frame. We do not get
2158 * any callback for the message completion, so just wait a
2159 * short while and hope for the best. */
2160 os_sleep(0, 10000);
2161
2162 wpa_drv_set_countermeasures(wpa_s, 1);
2163 wpa_supplicant_deauthenticate(wpa_s,
2164 WLAN_REASON_MICHAEL_MIC_FAILURE);
2165 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
2166 wpa_s, NULL);
2167 eloop_register_timeout(60, 0,
2168 wpa_supplicant_stop_countermeasures,
2169 wpa_s, NULL);
2170 /* TODO: mark the AP rejected for 60 second. STA is
2171 * allowed to associate with another AP.. */
2172 } else {
2173#ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
2174 if (wpa_s->mic_errors_seen) {
2175 /*
2176 * Reduce the effectiveness of Michael MIC error
2177 * reports as a means for attacking against TKIP if
2178 * more than one MIC failure is noticed with the same
2179 * PTK. We delay the transmission of the reports by a
2180 * random time between 0 and 60 seconds in order to
2181 * force the attacker wait 60 seconds before getting
2182 * the information on whether a frame resulted in a MIC
2183 * failure.
2184 */
2185 u8 rval[4];
2186 int sec;
2187
2188 if (os_get_random(rval, sizeof(rval)) < 0)
2189 sec = os_random() % 60;
2190 else
2191 sec = WPA_GET_BE32(rval) % 60;
2192 wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
2193 "report %d seconds", sec);
2194 wpa_s->pending_mic_error_report = 1;
2195 wpa_s->pending_mic_error_pairwise = pairwise;
2196 eloop_cancel_timeout(
2197 wpa_supplicant_delayed_mic_error_report,
2198 wpa_s, NULL);
2199 eloop_register_timeout(
2200 sec, os_random() % 1000000,
2201 wpa_supplicant_delayed_mic_error_report,
2202 wpa_s, NULL);
2203 } else {
2204 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2205 }
2206#else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2207 wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
2208#endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
2209 }
2210 wpa_s->last_michael_mic_error = t.sec;
2211 wpa_s->mic_errors_seen++;
2212}
2213
2214
2215#ifdef CONFIG_TERMINATE_ONLASTIF
2216static int any_interfaces(struct wpa_supplicant *head)
2217{
2218 struct wpa_supplicant *wpa_s;
2219
2220 for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
2221 if (!wpa_s->interface_removed)
2222 return 1;
2223 return 0;
2224}
2225#endif /* CONFIG_TERMINATE_ONLASTIF */
2226
2227
2228static void
2229wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
2230 union wpa_event_data *data)
2231{
2232 if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
2233 return;
2234
2235 switch (data->interface_status.ievent) {
2236 case EVENT_INTERFACE_ADDED:
2237 if (!wpa_s->interface_removed)
2238 break;
2239 wpa_s->interface_removed = 0;
2240 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
2241 if (wpa_supplicant_driver_init(wpa_s) < 0) {
2242 wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
2243 "driver after interface was added");
2244 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002245 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002246 break;
2247 case EVENT_INTERFACE_REMOVED:
2248 wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
2249 wpa_s->interface_removed = 1;
2250 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002251 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002252 l2_packet_deinit(wpa_s->l2);
2253 wpa_s->l2 = NULL;
2254#ifdef CONFIG_IBSS_RSN
2255 ibss_rsn_deinit(wpa_s->ibss_rsn);
2256 wpa_s->ibss_rsn = NULL;
2257#endif /* CONFIG_IBSS_RSN */
2258#ifdef CONFIG_TERMINATE_ONLASTIF
2259 /* check if last interface */
2260 if (!any_interfaces(wpa_s->global->ifaces))
2261 eloop_terminate();
2262#endif /* CONFIG_TERMINATE_ONLASTIF */
2263 break;
2264 }
2265}
2266
2267
2268#ifdef CONFIG_PEERKEY
2269static void
2270wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
2271 union wpa_event_data *data)
2272{
2273 if (data == NULL)
2274 return;
2275 wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
2276}
2277#endif /* CONFIG_PEERKEY */
2278
2279
2280#ifdef CONFIG_TDLS
2281static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
2282 union wpa_event_data *data)
2283{
2284 if (data == NULL)
2285 return;
2286 switch (data->tdls.oper) {
2287 case TDLS_REQUEST_SETUP:
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002288 wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
2289 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2290 wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
2291 else
2292 wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002293 break;
2294 case TDLS_REQUEST_TEARDOWN:
Sunil Dutt6a9f5222013-09-30 17:10:18 +03002295 if (wpa_tdls_is_external_setup(wpa_s->wpa))
2296 wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
2297 data->tdls.reason_code);
2298 else
2299 wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
2300 data->tdls.peer);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002301 break;
2302 }
2303}
2304#endif /* CONFIG_TDLS */
2305
2306
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002307#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002308static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
2309 union wpa_event_data *data)
2310{
2311 if (data == NULL)
2312 return;
2313 switch (data->wnm.oper) {
2314 case WNM_OPER_SLEEP:
2315 wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
2316 "(action=%d, intval=%d)",
2317 data->wnm.sleep_action, data->wnm.sleep_intval);
2318 ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002319 data->wnm.sleep_intval, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002320 break;
2321 }
2322}
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002323#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002324
2325
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002326#ifdef CONFIG_IEEE80211R
2327static void
2328wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
2329 union wpa_event_data *data)
2330{
2331 if (data == NULL)
2332 return;
2333
2334 if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
2335 data->ft_ies.ies_len,
2336 data->ft_ies.ft_action,
2337 data->ft_ies.target_ap,
2338 data->ft_ies.ric_ies,
2339 data->ft_ies.ric_ies_len) < 0) {
2340 /* TODO: prevent MLME/driver from trying to associate? */
2341 }
2342}
2343#endif /* CONFIG_IEEE80211R */
2344
2345
2346#ifdef CONFIG_IBSS_RSN
2347static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
2348 union wpa_event_data *data)
2349{
2350 struct wpa_ssid *ssid;
2351 if (wpa_s->wpa_state < WPA_ASSOCIATED)
2352 return;
2353 if (data == NULL)
2354 return;
2355 ssid = wpa_s->current_ssid;
2356 if (ssid == NULL)
2357 return;
2358 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2359 return;
2360
2361 ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
2362}
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002363
2364
2365static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
2366 union wpa_event_data *data)
2367{
2368 struct wpa_ssid *ssid = wpa_s->current_ssid;
2369
2370 if (ssid == NULL)
2371 return;
2372
2373 /* check if the ssid is correctly configured as IBSS/RSN */
2374 if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
2375 return;
2376
2377 ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
2378 data->rx_mgmt.frame_len);
2379}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002380#endif /* CONFIG_IBSS_RSN */
2381
2382
2383#ifdef CONFIG_IEEE80211R
2384static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
2385 size_t len)
2386{
2387 const u8 *sta_addr, *target_ap_addr;
2388 u16 status;
2389
2390 wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
2391 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
2392 return; /* only SME case supported for now */
2393 if (len < 1 + 2 * ETH_ALEN + 2)
2394 return;
2395 if (data[0] != 2)
2396 return; /* Only FT Action Response is supported for now */
2397 sta_addr = data + 1;
2398 target_ap_addr = data + 1 + ETH_ALEN;
2399 status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
2400 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
2401 MACSTR " TargetAP " MACSTR " status %u",
2402 MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
2403
2404 if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
2405 wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
2406 " in FT Action Response", MAC2STR(sta_addr));
2407 return;
2408 }
2409
2410 if (status) {
2411 wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
2412 "failure (status code %d)", status);
2413 /* TODO: report error to FT code(?) */
2414 return;
2415 }
2416
2417 if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
2418 len - (1 + 2 * ETH_ALEN + 2), 1,
2419 target_ap_addr, NULL, 0) < 0)
2420 return;
2421
2422#ifdef CONFIG_SME
2423 {
2424 struct wpa_bss *bss;
2425 bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
2426 if (bss)
2427 wpa_s->sme.freq = bss->freq;
2428 wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
2429 sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
2430 WLAN_AUTH_FT);
2431 }
2432#endif /* CONFIG_SME */
2433}
2434#endif /* CONFIG_IEEE80211R */
2435
2436
2437static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
2438 struct unprot_deauth *e)
2439{
2440#ifdef CONFIG_IEEE80211W
2441 wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
2442 "dropped: " MACSTR " -> " MACSTR
2443 " (reason code %u)",
2444 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2445 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2446#endif /* CONFIG_IEEE80211W */
2447}
2448
2449
2450static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
2451 struct unprot_disassoc *e)
2452{
2453#ifdef CONFIG_IEEE80211W
2454 wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
2455 "dropped: " MACSTR " -> " MACSTR
2456 " (reason code %u)",
2457 MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
2458 sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
2459#endif /* CONFIG_IEEE80211W */
2460}
2461
2462
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002463static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
2464 u16 reason_code, int locally_generated,
2465 const u8 *ie, size_t ie_len, int deauth)
2466{
2467#ifdef CONFIG_AP
2468 if (wpa_s->ap_iface && addr) {
2469 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
2470 return;
2471 }
2472
2473 if (wpa_s->ap_iface) {
2474 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
2475 return;
2476 }
2477#endif /* CONFIG_AP */
2478
2479 wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
2480
2481 if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
2482 ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2483 (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
2484 eapol_sm_failed(wpa_s->eapol)))
2485 wpas_auth_failed(wpa_s);
2486
2487#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002488 if (deauth && reason_code > 0) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002489 if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
2490 locally_generated) > 0) {
2491 /*
2492 * The interface was removed, so cannot continue
2493 * processing any additional operations after this.
2494 */
2495 return;
2496 }
2497 }
2498#endif /* CONFIG_P2P */
2499
2500 wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
2501 locally_generated);
2502}
2503
2504
2505static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
2506 struct disassoc_info *info)
2507{
2508 u16 reason_code = 0;
2509 int locally_generated = 0;
2510 const u8 *addr = NULL;
2511 const u8 *ie = NULL;
2512 size_t ie_len = 0;
2513
2514 wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
2515
2516 if (info) {
2517 addr = info->addr;
2518 ie = info->ie;
2519 ie_len = info->ie_len;
2520 reason_code = info->reason_code;
2521 locally_generated = info->locally_generated;
2522 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
2523 locally_generated ? " (locally generated)" : "");
2524 if (addr)
2525 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2526 MAC2STR(addr));
2527 wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
2528 ie, ie_len);
2529 }
2530
2531#ifdef CONFIG_AP
2532 if (wpa_s->ap_iface && info && info->addr) {
2533 hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
2534 return;
2535 }
2536
2537 if (wpa_s->ap_iface) {
2538 wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
2539 return;
2540 }
2541#endif /* CONFIG_AP */
2542
2543#ifdef CONFIG_P2P
2544 if (info) {
2545 wpas_p2p_disassoc_notif(
2546 wpa_s, info->addr, reason_code, info->ie, info->ie_len,
2547 locally_generated);
2548 }
2549#endif /* CONFIG_P2P */
2550
2551 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2552 sme_event_disassoc(wpa_s, info);
2553
2554 wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
2555 ie, ie_len, 0);
2556}
2557
2558
2559static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
2560 struct deauth_info *info)
2561{
2562 u16 reason_code = 0;
2563 int locally_generated = 0;
2564 const u8 *addr = NULL;
2565 const u8 *ie = NULL;
2566 size_t ie_len = 0;
2567
2568 wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
2569
2570 if (info) {
2571 addr = info->addr;
2572 ie = info->ie;
2573 ie_len = info->ie_len;
2574 reason_code = info->reason_code;
2575 locally_generated = info->locally_generated;
2576 wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
2577 reason_code,
2578 locally_generated ? " (locally generated)" : "");
2579 if (addr) {
2580 wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
2581 MAC2STR(addr));
2582 }
2583 wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
2584 ie, ie_len);
2585 }
2586
2587 wpa_reset_ft_completed(wpa_s->wpa);
2588
2589 wpas_event_disconnect(wpa_s, addr, reason_code,
2590 locally_generated, ie, ie_len, 1);
2591}
2592
2593
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002594void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2595 union wpa_event_data *data)
2596{
2597 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002598
2599 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
2600 event != EVENT_INTERFACE_ENABLED &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002601 event != EVENT_INTERFACE_STATUS &&
2602 event != EVENT_SCHED_SCAN_STOPPED) {
2603 wpa_dbg(wpa_s, MSG_DEBUG,
2604 "Ignore event %s (%d) while interface is disabled",
2605 event_to_string(event), event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002606 return;
2607 }
2608
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002609#ifndef CONFIG_NO_STDOUT_DEBUG
2610{
2611 int level = MSG_DEBUG;
2612
Dmitry Shmidt04949592012-07-19 12:16:46 -07002613 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002614 const struct ieee80211_hdr *hdr;
2615 u16 fc;
2616 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2617 fc = le_to_host16(hdr->frame_control);
2618 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2619 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2620 level = MSG_EXCESSIVE;
2621 }
2622
2623 wpa_dbg(wpa_s, level, "Event %s (%d) received",
2624 event_to_string(event), event);
2625}
2626#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002627
2628 switch (event) {
2629 case EVENT_AUTH:
2630 sme_event_auth(wpa_s, data);
2631 break;
2632 case EVENT_ASSOC:
2633 wpa_supplicant_event_assoc(wpa_s, data);
2634 break;
2635 case EVENT_DISASSOC:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002636 wpas_event_disassoc(wpa_s,
2637 data ? &data->disassoc_info : NULL);
2638 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002639 case EVENT_DEAUTH:
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002640 wpas_event_deauth(wpa_s,
2641 data ? &data->deauth_info : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002642 break;
2643 case EVENT_MICHAEL_MIC_FAILURE:
2644 wpa_supplicant_event_michael_mic_failure(wpa_s, data);
2645 break;
2646#ifndef CONFIG_NO_SCAN_PROCESSING
2647 case EVENT_SCAN_RESULTS:
2648 wpa_supplicant_event_scan_results(wpa_s, data);
Dmitry Shmidt37d4d6a2013-03-18 13:09:42 -07002649 if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
2650 wpa_s->wpa_state != WPA_ASSOCIATING)
2651 wpas_p2p_continue_after_scan(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002652 break;
2653#endif /* CONFIG_NO_SCAN_PROCESSING */
2654 case EVENT_ASSOCINFO:
2655 wpa_supplicant_event_associnfo(wpa_s, data);
2656 break;
2657 case EVENT_INTERFACE_STATUS:
2658 wpa_supplicant_event_interface_status(wpa_s, data);
2659 break;
2660 case EVENT_PMKID_CANDIDATE:
2661 wpa_supplicant_event_pmkid_candidate(wpa_s, data);
2662 break;
2663#ifdef CONFIG_PEERKEY
2664 case EVENT_STKSTART:
2665 wpa_supplicant_event_stkstart(wpa_s, data);
2666 break;
2667#endif /* CONFIG_PEERKEY */
2668#ifdef CONFIG_TDLS
2669 case EVENT_TDLS:
2670 wpa_supplicant_event_tdls(wpa_s, data);
2671 break;
2672#endif /* CONFIG_TDLS */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002673#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002674 case EVENT_WNM:
2675 wpa_supplicant_event_wnm(wpa_s, data);
2676 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002677#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002678#ifdef CONFIG_IEEE80211R
2679 case EVENT_FT_RESPONSE:
2680 wpa_supplicant_event_ft_response(wpa_s, data);
2681 break;
2682#endif /* CONFIG_IEEE80211R */
2683#ifdef CONFIG_IBSS_RSN
2684 case EVENT_IBSS_RSN_START:
2685 wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
2686 break;
2687#endif /* CONFIG_IBSS_RSN */
2688 case EVENT_ASSOC_REJECT:
2689 if (data->assoc_reject.bssid)
2690 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2691 "bssid=" MACSTR " status_code=%u",
2692 MAC2STR(data->assoc_reject.bssid),
2693 data->assoc_reject.status_code);
2694 else
2695 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
2696 "status_code=%u",
2697 data->assoc_reject.status_code);
2698 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2699 sme_event_assoc_reject(wpa_s, data);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002700 else {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002701#ifdef ANDROID_P2P
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002702 if(!wpa_s->current_ssid) {
2703 wpa_printf(MSG_ERROR, "current_ssid == NULL");
2704 break;
2705 }
2706 /* If assoc reject is reported by the driver, then avoid
2707 * waiting for the authentication timeout. Cancel the
2708 * authentication timeout and retry the assoc.
2709 */
Jeff Johnsonb485b182012-10-21 18:19:27 -07002710 if(wpa_s->current_ssid->assoc_retry++ < 10) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002711 wpa_printf(MSG_ERROR, "Retrying assoc: %d ",
2712 wpa_s->current_ssid->assoc_retry);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002713
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002714 wpa_supplicant_cancel_auth_timeout(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002715
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002716 /* Clear the states */
2717 wpa_sm_notify_disassoc(wpa_s->wpa);
2718 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2719
2720 wpa_s->reassociate = 1;
Jeff Johnsonb485b182012-10-21 18:19:27 -07002721 if (wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE) {
Dmitry Shmidt54cb0f62012-10-29 13:12:24 -07002722 const u8 *bl_bssid = data->assoc_reject.bssid;
2723 if (!bl_bssid || is_zero_ether_addr(bl_bssid))
2724 bl_bssid = wpa_s->pending_bssid;
2725 wpa_blacklist_add(wpa_s, bl_bssid);
Jeff Johnsonb485b182012-10-21 18:19:27 -07002726 wpa_supplicant_req_scan(wpa_s, 0, 0);
2727 } else {
2728 wpa_supplicant_req_scan(wpa_s, 1, 0);
2729 }
2730 } else if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002731 /* If we ASSOC_REJECT's hits threshold, disable the
2732 * network
2733 */
2734 wpa_printf(MSG_ERROR, "Assoc retry threshold reached. "
2735 "Disabling the network");
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002736 wpa_s->current_ssid->assoc_retry = 0;
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002737 wpa_supplicant_disable_network(wpa_s, wpa_s->current_ssid);
Irfan Sheriff2fb835a2012-06-18 09:39:07 -07002738 wpas_p2p_group_remove(wpa_s, wpa_s->ifname);
Irfan Sheriff7db4ef72012-06-18 09:39:07 -07002739 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002740#else
2741 const u8 *bssid = data->assoc_reject.bssid;
2742 if (bssid == NULL || is_zero_ether_addr(bssid))
2743 bssid = wpa_s->pending_bssid;
2744 wpas_connection_failed(wpa_s, bssid);
2745 wpa_supplicant_mark_disassoc(wpa_s);
Dmitry Shmidt98f9e762012-05-30 11:18:46 -07002746#endif /* ANDROID_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002747 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002748 break;
2749 case EVENT_AUTH_TIMED_OUT:
2750 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2751 sme_event_auth_timed_out(wpa_s, data);
2752 break;
2753 case EVENT_ASSOC_TIMED_OUT:
2754 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
2755 sme_event_assoc_timed_out(wpa_s, data);
2756 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002757 case EVENT_TX_STATUS:
2758 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
2759 " type=%d stype=%d",
2760 MAC2STR(data->tx_status.dst),
2761 data->tx_status.type, data->tx_status.stype);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002762#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002763 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002764#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002765 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2766 data->tx_status.stype == WLAN_FC_STYPE_ACTION)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002767 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002768 wpa_s, data->tx_status.dst,
2769 data->tx_status.data,
2770 data->tx_status.data_len,
2771 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002772 OFFCHANNEL_SEND_ACTION_SUCCESS :
2773 OFFCHANNEL_SEND_ACTION_NO_ACK);
2774#endif /* CONFIG_OFFCHANNEL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002775 break;
2776 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002777#endif /* CONFIG_AP */
2778#ifdef CONFIG_OFFCHANNEL
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002779 wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
2780 MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
2781 /*
2782 * Catch TX status events for Action frames we sent via group
2783 * interface in GO mode.
2784 */
2785 if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
2786 data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
2787 os_memcmp(wpa_s->parent->pending_action_dst,
2788 data->tx_status.dst, ETH_ALEN) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002789 offchannel_send_action_tx_status(
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002790 wpa_s->parent, data->tx_status.dst,
2791 data->tx_status.data,
2792 data->tx_status.data_len,
2793 data->tx_status.ack ?
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002794 OFFCHANNEL_SEND_ACTION_SUCCESS :
2795 OFFCHANNEL_SEND_ACTION_NO_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002796 break;
2797 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002798#endif /* CONFIG_OFFCHANNEL */
2799#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002800 switch (data->tx_status.type) {
2801 case WLAN_FC_TYPE_MGMT:
2802 ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
2803 data->tx_status.data_len,
2804 data->tx_status.stype,
2805 data->tx_status.ack);
2806 break;
2807 case WLAN_FC_TYPE_DATA:
2808 ap_tx_status(wpa_s, data->tx_status.dst,
2809 data->tx_status.data,
2810 data->tx_status.data_len,
2811 data->tx_status.ack);
2812 break;
2813 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002814#endif /* CONFIG_AP */
2815 break;
2816#ifdef CONFIG_AP
2817 case EVENT_EAPOL_TX_STATUS:
2818 ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
2819 data->eapol_tx_status.data,
2820 data->eapol_tx_status.data_len,
2821 data->eapol_tx_status.ack);
2822 break;
2823 case EVENT_DRIVER_CLIENT_POLL_OK:
2824 ap_client_poll_ok(wpa_s, data->client_poll.addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002825 break;
2826 case EVENT_RX_FROM_UNKNOWN:
2827 if (wpa_s->ap_iface == NULL)
2828 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002829 ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
2830 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002831 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002832 case EVENT_CH_SWITCH:
2833 if (!data)
2834 break;
2835 if (!wpa_s->ap_iface) {
2836 wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
2837 "event in non-AP mode");
2838 break;
2839 }
2840
Dmitry Shmidt04949592012-07-19 12:16:46 -07002841 wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
2842 data->ch_switch.ht_enabled,
2843 data->ch_switch.ch_offset);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002844 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002845#endif /* CONFIG_AP */
2846#if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
Dmitry Shmidt04949592012-07-19 12:16:46 -07002847 case EVENT_RX_MGMT: {
2848 u16 fc, stype;
2849 const struct ieee80211_mgmt *mgmt;
2850
2851 mgmt = (const struct ieee80211_mgmt *)
2852 data->rx_mgmt.frame;
2853 fc = le_to_host16(mgmt->frame_control);
2854 stype = WLAN_FC_GET_STYPE(fc);
2855
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002856#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002857 if (wpa_s->ap_iface == NULL) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002858#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002859#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002860 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2861 data->rx_mgmt.frame_len > 24) {
2862 const u8 *src = mgmt->sa;
2863 const u8 *ie = mgmt->u.probe_req.variable;
2864 size_t ie_len = data->rx_mgmt.frame_len -
2865 (mgmt->u.probe_req.variable -
2866 data->rx_mgmt.frame);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002867 wpas_p2p_probe_req_rx(
2868 wpa_s, src, mgmt->da,
2869 mgmt->bssid, ie, ie_len,
2870 data->rx_mgmt.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002871 break;
2872 }
2873#endif /* CONFIG_P2P */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002874#ifdef CONFIG_IBSS_RSN
2875 if (stype == WLAN_FC_STYPE_AUTH &&
2876 data->rx_mgmt.frame_len >= 30) {
2877 wpa_supplicant_event_ibss_auth(wpa_s, data);
2878 break;
2879 }
2880#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002881 wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
2882 "management frame in non-AP mode");
2883 break;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002884#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002885 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002886
2887 if (stype == WLAN_FC_STYPE_PROBE_REQ &&
2888 data->rx_mgmt.frame_len > 24) {
2889 const u8 *ie = mgmt->u.probe_req.variable;
2890 size_t ie_len = data->rx_mgmt.frame_len -
2891 (mgmt->u.probe_req.variable -
2892 data->rx_mgmt.frame);
2893
2894 wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
2895 mgmt->bssid, ie, ie_len,
2896 data->rx_mgmt.ssi_signal);
2897 }
2898
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002899 ap_mgmt_rx(wpa_s, &data->rx_mgmt);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002900#endif /* CONFIG_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002901 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002902 }
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002903#endif /* CONFIG_AP || CONFIG_IBSS_RSN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002904 case EVENT_RX_ACTION:
2905 wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
2906 " Category=%u DataLen=%d freq=%d MHz",
2907 MAC2STR(data->rx_action.sa),
2908 data->rx_action.category, (int) data->rx_action.len,
2909 data->rx_action.freq);
2910#ifdef CONFIG_IEEE80211R
2911 if (data->rx_action.category == WLAN_ACTION_FT) {
2912 ft_rx_action(wpa_s, data->rx_action.data,
2913 data->rx_action.len);
2914 break;
2915 }
2916#endif /* CONFIG_IEEE80211R */
2917#ifdef CONFIG_IEEE80211W
2918#ifdef CONFIG_SME
2919 if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
2920 sme_sa_query_rx(wpa_s, data->rx_action.sa,
2921 data->rx_action.data,
2922 data->rx_action.len);
2923 break;
2924 }
2925#endif /* CONFIG_SME */
2926#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002927#ifdef CONFIG_WNM
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002928 if (data->rx_action.category == WLAN_ACTION_WNM) {
2929 ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
2930 break;
2931 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002932#endif /* CONFIG_WNM */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002933#ifdef CONFIG_GAS
2934 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2935 gas_query_rx(wpa_s->gas, data->rx_action.da,
2936 data->rx_action.sa, data->rx_action.bssid,
2937 data->rx_action.data, data->rx_action.len,
2938 data->rx_action.freq) == 0)
2939 break;
2940#endif /* CONFIG_GAS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002941#ifdef CONFIG_TDLS
2942 if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
2943 data->rx_action.len >= 4 &&
2944 data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
2945 wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
2946 "Response from " MACSTR,
2947 MAC2STR(data->rx_action.sa));
2948 break;
2949 }
2950#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002951#ifdef CONFIG_P2P
2952 wpas_p2p_rx_action(wpa_s, data->rx_action.da,
2953 data->rx_action.sa,
2954 data->rx_action.bssid,
2955 data->rx_action.category,
2956 data->rx_action.data,
2957 data->rx_action.len, data->rx_action.freq);
2958#endif /* CONFIG_P2P */
2959 break;
2960 case EVENT_RX_PROBE_REQ:
2961 if (data->rx_probe_req.sa == NULL ||
2962 data->rx_probe_req.ie == NULL)
2963 break;
2964#ifdef CONFIG_AP
2965 if (wpa_s->ap_iface) {
2966 hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
2967 data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002968 data->rx_probe_req.da,
2969 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002970 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002971 data->rx_probe_req.ie_len,
2972 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002973 break;
2974 }
2975#endif /* CONFIG_AP */
2976#ifdef CONFIG_P2P
2977 wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002978 data->rx_probe_req.da,
2979 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002980 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002981 data->rx_probe_req.ie_len,
2982 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002983#endif /* CONFIG_P2P */
2984 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002985 case EVENT_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002986#ifdef CONFIG_OFFCHANNEL
2987 offchannel_remain_on_channel_cb(
2988 wpa_s, data->remain_on_channel.freq,
2989 data->remain_on_channel.duration);
2990#endif /* CONFIG_OFFCHANNEL */
2991#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002992 wpas_p2p_remain_on_channel_cb(
2993 wpa_s, data->remain_on_channel.freq,
2994 data->remain_on_channel.duration);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002995#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002996 break;
2997 case EVENT_CANCEL_REMAIN_ON_CHANNEL:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002998#ifdef CONFIG_OFFCHANNEL
2999 offchannel_cancel_remain_on_channel_cb(
3000 wpa_s, data->remain_on_channel.freq);
3001#endif /* CONFIG_OFFCHANNEL */
3002#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003003 wpas_p2p_cancel_remain_on_channel_cb(
3004 wpa_s, data->remain_on_channel.freq);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003005#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003006 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003007#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003008 case EVENT_P2P_DEV_FOUND: {
3009 struct p2p_peer_info peer_info;
3010
3011 os_memset(&peer_info, 0, sizeof(peer_info));
3012 if (data->p2p_dev_found.dev_addr)
3013 os_memcpy(peer_info.p2p_device_addr,
3014 data->p2p_dev_found.dev_addr, ETH_ALEN);
3015 if (data->p2p_dev_found.pri_dev_type)
3016 os_memcpy(peer_info.pri_dev_type,
3017 data->p2p_dev_found.pri_dev_type,
3018 sizeof(peer_info.pri_dev_type));
3019 if (data->p2p_dev_found.dev_name)
3020 os_strlcpy(peer_info.device_name,
3021 data->p2p_dev_found.dev_name,
3022 sizeof(peer_info.device_name));
3023 peer_info.config_methods = data->p2p_dev_found.config_methods;
3024 peer_info.dev_capab = data->p2p_dev_found.dev_capab;
3025 peer_info.group_capab = data->p2p_dev_found.group_capab;
3026
3027 /*
3028 * FIX: new_device=1 is not necessarily correct. We should
3029 * maintain a P2P peer database in wpa_supplicant and update
3030 * this information based on whether the peer is truly new.
3031 */
3032 wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
3033 break;
3034 }
3035 case EVENT_P2P_GO_NEG_REQ_RX:
3036 wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
3037 data->p2p_go_neg_req_rx.dev_passwd_id);
3038 break;
3039 case EVENT_P2P_GO_NEG_COMPLETED:
3040 wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
3041 break;
3042 case EVENT_P2P_PROV_DISC_REQUEST:
3043 wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
3044 data->p2p_prov_disc_req.config_methods,
3045 data->p2p_prov_disc_req.dev_addr,
3046 data->p2p_prov_disc_req.pri_dev_type,
3047 data->p2p_prov_disc_req.dev_name,
3048 data->p2p_prov_disc_req.supp_config_methods,
3049 data->p2p_prov_disc_req.dev_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003050 data->p2p_prov_disc_req.group_capab,
3051 NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003052 break;
3053 case EVENT_P2P_PROV_DISC_RESPONSE:
3054 wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
3055 data->p2p_prov_disc_resp.config_methods);
3056 break;
3057 case EVENT_P2P_SD_REQUEST:
3058 wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
3059 data->p2p_sd_req.sa,
3060 data->p2p_sd_req.dialog_token,
3061 data->p2p_sd_req.update_indic,
3062 data->p2p_sd_req.tlvs,
3063 data->p2p_sd_req.tlvs_len);
3064 break;
3065 case EVENT_P2P_SD_RESPONSE:
3066 wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
3067 data->p2p_sd_resp.update_indic,
3068 data->p2p_sd_resp.tlvs,
3069 data->p2p_sd_resp.tlvs_len);
3070 break;
3071#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003072 case EVENT_EAPOL_RX:
3073 wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
3074 data->eapol_rx.data,
3075 data->eapol_rx.data_len);
3076 break;
3077 case EVENT_SIGNAL_CHANGE:
3078 bgscan_notify_signal_change(
3079 wpa_s, data->signal_change.above_threshold,
3080 data->signal_change.current_signal,
3081 data->signal_change.current_noise,
3082 data->signal_change.current_txrate);
3083 break;
3084 case EVENT_INTERFACE_ENABLED:
3085 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
3086 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003087 wpa_supplicant_update_mac_addr(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003088#ifdef CONFIG_AP
3089 if (!wpa_s->ap_iface) {
3090 wpa_supplicant_set_state(wpa_s,
3091 WPA_DISCONNECTED);
3092 wpa_supplicant_req_scan(wpa_s, 0, 0);
3093 } else
3094 wpa_supplicant_set_state(wpa_s,
3095 WPA_COMPLETED);
3096#else /* CONFIG_AP */
3097 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
3098 wpa_supplicant_req_scan(wpa_s, 0, 0);
3099#endif /* CONFIG_AP */
3100 }
3101 break;
3102 case EVENT_INTERFACE_DISABLED:
3103 wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
3104 wpa_supplicant_mark_disassoc(wpa_s);
3105 wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
3106 break;
3107 case EVENT_CHANNEL_LIST_CHANGED:
3108 if (wpa_s->drv_priv == NULL)
3109 break; /* Ignore event during drv initialization */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003110
3111 free_hw_features(wpa_s);
3112 wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
3113 wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
3114
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003115#ifdef CONFIG_P2P
3116 wpas_p2p_update_channel_list(wpa_s);
3117#endif /* CONFIG_P2P */
3118 break;
3119 case EVENT_INTERFACE_UNAVAILABLE:
3120#ifdef CONFIG_P2P
3121 wpas_p2p_interface_unavailable(wpa_s);
3122#endif /* CONFIG_P2P */
3123 break;
3124 case EVENT_BEST_CHANNEL:
3125 wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
3126 "(%d %d %d)",
3127 data->best_chan.freq_24, data->best_chan.freq_5,
3128 data->best_chan.freq_overall);
3129 wpa_s->best_24_freq = data->best_chan.freq_24;
3130 wpa_s->best_5_freq = data->best_chan.freq_5;
3131 wpa_s->best_overall_freq = data->best_chan.freq_overall;
3132#ifdef CONFIG_P2P
3133 wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
3134 data->best_chan.freq_5,
3135 data->best_chan.freq_overall);
3136#endif /* CONFIG_P2P */
3137 break;
3138 case EVENT_UNPROT_DEAUTH:
3139 wpa_supplicant_event_unprot_deauth(wpa_s,
3140 &data->unprot_deauth);
3141 break;
3142 case EVENT_UNPROT_DISASSOC:
3143 wpa_supplicant_event_unprot_disassoc(wpa_s,
3144 &data->unprot_disassoc);
3145 break;
3146 case EVENT_STATION_LOW_ACK:
3147#ifdef CONFIG_AP
3148 if (wpa_s->ap_iface && data)
3149 hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
3150 data->low_ack.addr);
3151#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003152#ifdef CONFIG_TDLS
3153 if (data)
3154 wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
3155#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003156 break;
3157 case EVENT_IBSS_PEER_LOST:
3158#ifdef CONFIG_IBSS_RSN
3159 ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
3160#endif /* CONFIG_IBSS_RSN */
3161 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003162 case EVENT_DRIVER_GTK_REKEY:
3163 if (os_memcmp(data->driver_gtk_rekey.bssid,
3164 wpa_s->bssid, ETH_ALEN))
3165 break;
3166 if (!wpa_s->wpa)
3167 break;
3168 wpa_sm_update_replay_ctr(wpa_s->wpa,
3169 data->driver_gtk_rekey.replay_ctr);
3170 break;
3171 case EVENT_SCHED_SCAN_STOPPED:
3172 wpa_s->sched_scanning = 0;
3173 wpa_supplicant_notify_scanning(wpa_s, 0);
3174
3175 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3176 break;
3177
3178 /*
3179 * If we timed out, start a new sched scan to continue
3180 * searching for more SSIDs.
3181 */
3182 if (wpa_s->sched_scan_timed_out)
3183 wpa_supplicant_req_sched_scan(wpa_s);
3184 break;
3185 case EVENT_WPS_BUTTON_PUSHED:
3186#ifdef CONFIG_WPS
3187 wpas_wps_start_pbc(wpa_s, NULL, 0);
3188#endif /* CONFIG_WPS */
3189 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003190 case EVENT_CONNECT_FAILED_REASON:
3191#ifdef CONFIG_AP
3192 if (!wpa_s->ap_iface || !data)
3193 break;
3194 hostapd_event_connect_failed_reason(
3195 wpa_s->ap_iface->bss[0],
3196 data->connect_failed_reason.addr,
3197 data->connect_failed_reason.code);
3198#endif /* CONFIG_AP */
3199 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003200 default:
3201 wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
3202 break;
3203 }
3204}