]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * WPA Supplicant - Driver event processing | |
16a83d29 | 3 | * Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi> |
6fc6879b JM |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License version 2 as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * Alternatively, this software may be distributed under the terms of BSD | |
10 | * license. | |
11 | * | |
12 | * See README and COPYING for more details. | |
13 | */ | |
14 | ||
15 | #include "includes.h" | |
16 | ||
17 | #include "common.h" | |
18 | #include "eapol_supp/eapol_supp_sm.h" | |
3acb5005 | 19 | #include "rsn_supp/wpa.h" |
6fc6879b | 20 | #include "eloop.h" |
6fc6879b JM |
21 | #include "config.h" |
22 | #include "l2_packet/l2_packet.h" | |
23 | #include "wpa_supplicant_i.h" | |
2d5b792d | 24 | #include "driver_i.h" |
6fc6879b | 25 | #include "pcsc_funcs.h" |
3acb5005 JM |
26 | #include "rsn_supp/preauth.h" |
27 | #include "rsn_supp/pmksa_cache.h" | |
90973fb2 | 28 | #include "common/wpa_ctrl.h" |
6fc6879b | 29 | #include "eap_peer/eap.h" |
1d041bec | 30 | #include "ap/hostapd.h" |
93b7ddd0 | 31 | #include "p2p/p2p.h" |
8bac466b | 32 | #include "notify.h" |
90973fb2 | 33 | #include "common/ieee802_11_defs.h" |
54f489be | 34 | #include "common/ieee802_11_common.h" |
bbb921da | 35 | #include "crypto/random.h" |
6fc6879b JM |
36 | #include "blacklist.h" |
37 | #include "wpas_glue.h" | |
351f09a2 | 38 | #include "wps_supplicant.h" |
11ef8d35 | 39 | #include "ibss_rsn.h" |
c2a04078 | 40 | #include "sme.h" |
04ea7b79 | 41 | #include "gas_query.h" |
9bae1be0 | 42 | #include "p2p_supplicant.h" |
60b94c98 | 43 | #include "bgscan.h" |
f8b1f695 | 44 | #include "ap.h" |
6fa81a3b | 45 | #include "bss.h" |
9ba9fa07 | 46 | #include "scan.h" |
24f6497c | 47 | #include "offchannel.h" |
6fc6879b JM |
48 | |
49 | ||
50 | static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s) | |
51 | { | |
8bac466b | 52 | struct wpa_ssid *ssid, *old_ssid; |
6fc6879b JM |
53 | |
54 | if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) | |
55 | return 0; | |
56 | ||
f049052b BG |
57 | wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association " |
58 | "information"); | |
6fc6879b JM |
59 | ssid = wpa_supplicant_get_ssid(wpa_s); |
60 | if (ssid == NULL) { | |
f049052b BG |
61 | wpa_msg(wpa_s, MSG_INFO, |
62 | "No network configuration found for the current AP"); | |
6fc6879b JM |
63 | return -1; |
64 | } | |
65 | ||
66 | if (ssid->disabled) { | |
f049052b | 67 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled"); |
6fc6879b JM |
68 | return -1; |
69 | } | |
70 | ||
f049052b BG |
71 | wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the " |
72 | "current AP"); | |
6fc6879b JM |
73 | if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X | |
74 | WPA_KEY_MGMT_WPA_NONE | | |
56586197 JM |
75 | WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X | |
76 | WPA_KEY_MGMT_PSK_SHA256 | | |
77 | WPA_KEY_MGMT_IEEE8021X_SHA256)) { | |
6fc6879b JM |
78 | u8 wpa_ie[80]; |
79 | size_t wpa_ie_len = sizeof(wpa_ie); | |
80 | wpa_supplicant_set_suites(wpa_s, NULL, ssid, | |
81 | wpa_ie, &wpa_ie_len); | |
82 | } else { | |
83 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
84 | } | |
85 | ||
86 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) | |
87 | eapol_sm_invalidate_cached_session(wpa_s->eapol); | |
8bac466b | 88 | old_ssid = wpa_s->current_ssid; |
6fc6879b JM |
89 | wpa_s->current_ssid = ssid; |
90 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); | |
91 | wpa_supplicant_initiate_eapol(wpa_s); | |
8bac466b JM |
92 | if (old_ssid != wpa_s->current_ssid) |
93 | wpas_notify_network_changed(wpa_s); | |
6fc6879b JM |
94 | |
95 | return 0; | |
96 | } | |
97 | ||
98 | ||
99 | static void wpa_supplicant_stop_countermeasures(void *eloop_ctx, | |
100 | void *sock_ctx) | |
101 | { | |
102 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
103 | ||
104 | if (wpa_s->countermeasures) { | |
105 | wpa_s->countermeasures = 0; | |
106 | wpa_drv_set_countermeasures(wpa_s, 0); | |
107 | wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped"); | |
108 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
109 | } | |
110 | } | |
111 | ||
112 | ||
113 | void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) | |
114 | { | |
8bac466b JM |
115 | int bssid_changed; |
116 | ||
78177a00 JM |
117 | #ifdef CONFIG_IBSS_RSN |
118 | ibss_rsn_deinit(wpa_s->ibss_rsn); | |
119 | wpa_s->ibss_rsn = NULL; | |
120 | #endif /* CONFIG_IBSS_RSN */ | |
121 | ||
ca62e114 JM |
122 | #ifdef CONFIG_AP |
123 | wpa_supplicant_ap_deinit(wpa_s); | |
124 | #endif /* CONFIG_AP */ | |
125 | ||
8401a6b0 JM |
126 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
127 | return; | |
128 | ||
6fc6879b | 129 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
8bac466b | 130 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
6fc6879b JM |
131 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
132 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
be8be671 | 133 | wpa_s->current_bss = NULL; |
3c85f144 | 134 | wpa_s->assoc_freq = 0; |
8fd0f0f3 HW |
135 | #ifdef CONFIG_IEEE80211R |
136 | #ifdef CONFIG_SME | |
137 | if (wpa_s->sme.ft_ies) | |
138 | sme_update_ft_ies(wpa_s, NULL, NULL, 0); | |
139 | #endif /* CONFIG_SME */ | |
140 | #endif /* CONFIG_IEEE80211R */ | |
141 | ||
8bac466b JM |
142 | if (bssid_changed) |
143 | wpas_notify_bssid_changed(wpa_s); | |
144 | ||
6fc6879b JM |
145 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); |
146 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
56586197 | 147 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) |
6fc6879b JM |
148 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
149 | wpa_s->ap_ies_from_associnfo = 0; | |
150 | } | |
151 | ||
152 | ||
153 | static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s) | |
154 | { | |
155 | struct wpa_ie_data ie; | |
156 | int pmksa_set = -1; | |
157 | size_t i; | |
158 | ||
159 | if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 || | |
160 | ie.pmkid == NULL) | |
161 | return; | |
162 | ||
163 | for (i = 0; i < ie.num_pmkid; i++) { | |
164 | pmksa_set = pmksa_cache_set_current(wpa_s->wpa, | |
165 | ie.pmkid + i * PMKID_LEN, | |
166 | NULL, NULL, 0); | |
167 | if (pmksa_set == 0) { | |
168 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1); | |
169 | break; | |
170 | } | |
171 | } | |
172 | ||
f049052b BG |
173 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from " |
174 | "PMKSA cache", pmksa_set == 0 ? "" : "not "); | |
6fc6879b JM |
175 | } |
176 | ||
177 | ||
178 | static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s, | |
179 | union wpa_event_data *data) | |
180 | { | |
181 | if (data == NULL) { | |
f049052b BG |
182 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate " |
183 | "event"); | |
6fc6879b JM |
184 | return; |
185 | } | |
f049052b BG |
186 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR |
187 | " index=%d preauth=%d", | |
188 | MAC2STR(data->pmkid_candidate.bssid), | |
189 | data->pmkid_candidate.index, | |
190 | data->pmkid_candidate.preauth); | |
6fc6879b JM |
191 | |
192 | pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid, | |
193 | data->pmkid_candidate.index, | |
194 | data->pmkid_candidate.preauth); | |
195 | } | |
196 | ||
197 | ||
198 | static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s) | |
199 | { | |
200 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
201 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) | |
202 | return 0; | |
203 | ||
204 | #ifdef IEEE8021X_EAPOL | |
205 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA && | |
206 | wpa_s->current_ssid && | |
207 | !(wpa_s->current_ssid->eapol_flags & | |
208 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
209 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) { | |
210 | /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either | |
211 | * plaintext or static WEP keys). */ | |
212 | return 0; | |
213 | } | |
214 | #endif /* IEEE8021X_EAPOL */ | |
215 | ||
216 | return 1; | |
217 | } | |
218 | ||
219 | ||
220 | /** | |
221 | * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC | |
222 | * @wpa_s: pointer to wpa_supplicant data | |
223 | * @ssid: Configuration data for the network | |
224 | * Returns: 0 on success, -1 on failure | |
225 | * | |
226 | * This function is called when starting authentication with a network that is | |
227 | * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA). | |
228 | */ | |
229 | int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s, | |
230 | struct wpa_ssid *ssid) | |
231 | { | |
232 | #ifdef IEEE8021X_EAPOL | |
b832d34c | 233 | #ifdef PCSC_FUNCS |
6fc6879b JM |
234 | int aka = 0, sim = 0, type; |
235 | ||
236 | if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL) | |
237 | return 0; | |
238 | ||
239 | if (ssid->eap.eap_methods == NULL) { | |
240 | sim = 1; | |
241 | aka = 1; | |
242 | } else { | |
243 | struct eap_method_type *eap = ssid->eap.eap_methods; | |
244 | while (eap->vendor != EAP_VENDOR_IETF || | |
245 | eap->method != EAP_TYPE_NONE) { | |
246 | if (eap->vendor == EAP_VENDOR_IETF) { | |
247 | if (eap->method == EAP_TYPE_SIM) | |
248 | sim = 1; | |
249 | else if (eap->method == EAP_TYPE_AKA) | |
250 | aka = 1; | |
251 | } | |
252 | eap++; | |
253 | } | |
254 | } | |
255 | ||
256 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL) | |
257 | sim = 0; | |
258 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL) | |
259 | aka = 0; | |
260 | ||
261 | if (!sim && !aka) { | |
f049052b BG |
262 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to " |
263 | "use SIM, but neither EAP-SIM nor EAP-AKA are " | |
264 | "enabled"); | |
6fc6879b JM |
265 | return 0; |
266 | } | |
267 | ||
f049052b BG |
268 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM " |
269 | "(sim=%d aka=%d) - initialize PCSC", sim, aka); | |
6fc6879b JM |
270 | if (sim && aka) |
271 | type = SCARD_TRY_BOTH; | |
272 | else if (aka) | |
273 | type = SCARD_USIM_ONLY; | |
274 | else | |
275 | type = SCARD_GSM_SIM_ONLY; | |
276 | ||
277 | wpa_s->scard = scard_init(type); | |
278 | if (wpa_s->scard == NULL) { | |
f049052b BG |
279 | wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM " |
280 | "(pcsc-lite)"); | |
6fc6879b JM |
281 | return -1; |
282 | } | |
283 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); | |
284 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); | |
b832d34c | 285 | #endif /* PCSC_FUNCS */ |
6fc6879b JM |
286 | #endif /* IEEE8021X_EAPOL */ |
287 | ||
288 | return 0; | |
289 | } | |
290 | ||
291 | ||
292 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
293 | static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss, | |
294 | struct wpa_ssid *ssid) | |
295 | { | |
296 | int i, privacy = 0; | |
297 | ||
298 | if (ssid->mixed_cell) | |
299 | return 1; | |
300 | ||
0632542b AT |
301 | #ifdef CONFIG_WPS |
302 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) | |
303 | return 1; | |
304 | #endif /* CONFIG_WPS */ | |
305 | ||
6fc6879b JM |
306 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
307 | if (ssid->wep_key_len[i]) { | |
308 | privacy = 1; | |
309 | break; | |
310 | } | |
311 | } | |
312 | #ifdef IEEE8021X_EAPOL | |
313 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
314 | ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST | | |
315 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) | |
316 | privacy = 1; | |
317 | #endif /* IEEE8021X_EAPOL */ | |
318 | ||
29fbc522 JM |
319 | if (wpa_key_mgmt_wpa(ssid->key_mgmt)) |
320 | privacy = 1; | |
321 | ||
6fc6879b JM |
322 | if (bss->caps & IEEE80211_CAP_PRIVACY) |
323 | return privacy; | |
324 | return !privacy; | |
325 | } | |
326 | ||
327 | ||
a6099152 JM |
328 | static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, |
329 | struct wpa_ssid *ssid, | |
6fc6879b JM |
330 | struct wpa_scan_res *bss) |
331 | { | |
332 | struct wpa_ie_data ie; | |
333 | int proto_match = 0; | |
334 | const u8 *rsn_ie, *wpa_ie; | |
351f09a2 | 335 | int ret; |
43882f1e | 336 | int wep_ok; |
6fc6879b | 337 | |
a6099152 | 338 | ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); |
351f09a2 JM |
339 | if (ret >= 0) |
340 | return ret; | |
ad08c363 | 341 | |
43882f1e JM |
342 | /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */ |
343 | wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) && | |
344 | (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) && | |
345 | ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) || | |
346 | (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)); | |
347 | ||
6fc6879b JM |
348 | rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN); |
349 | while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) { | |
350 | proto_match++; | |
351 | ||
352 | if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { | |
f049052b BG |
353 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse " |
354 | "failed"); | |
6fc6879b JM |
355 | break; |
356 | } | |
43882f1e JM |
357 | |
358 | if (wep_ok && | |
359 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
360 | { | |
f049052b BG |
361 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " |
362 | "in RSN IE"); | |
43882f1e JM |
363 | return 1; |
364 | } | |
365 | ||
6fc6879b | 366 | if (!(ie.proto & ssid->proto)) { |
f049052b BG |
367 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto " |
368 | "mismatch"); | |
6fc6879b JM |
369 | break; |
370 | } | |
371 | ||
372 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
f049052b BG |
373 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK " |
374 | "cipher mismatch"); | |
6fc6879b JM |
375 | break; |
376 | } | |
377 | ||
378 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
f049052b BG |
379 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK " |
380 | "cipher mismatch"); | |
6fc6879b JM |
381 | break; |
382 | } | |
383 | ||
384 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
f049052b BG |
385 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt " |
386 | "mismatch"); | |
6fc6879b JM |
387 | break; |
388 | } | |
389 | ||
390 | #ifdef CONFIG_IEEE80211W | |
0b60b0aa | 391 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
70f8cc8e | 392 | ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) { |
f049052b BG |
393 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt " |
394 | "frame protection"); | |
6fc6879b JM |
395 | break; |
396 | } | |
397 | #endif /* CONFIG_IEEE80211W */ | |
398 | ||
f049052b | 399 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE"); |
6fc6879b JM |
400 | return 1; |
401 | } | |
402 | ||
403 | wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); | |
404 | while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { | |
405 | proto_match++; | |
406 | ||
407 | if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { | |
f049052b BG |
408 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse " |
409 | "failed"); | |
6fc6879b JM |
410 | break; |
411 | } | |
43882f1e JM |
412 | |
413 | if (wep_ok && | |
414 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) | |
415 | { | |
f049052b BG |
416 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " |
417 | "in WPA IE"); | |
43882f1e JM |
418 | return 1; |
419 | } | |
420 | ||
6fc6879b | 421 | if (!(ie.proto & ssid->proto)) { |
f049052b BG |
422 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto " |
423 | "mismatch"); | |
6fc6879b JM |
424 | break; |
425 | } | |
426 | ||
427 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { | |
f049052b BG |
428 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK " |
429 | "cipher mismatch"); | |
6fc6879b JM |
430 | break; |
431 | } | |
432 | ||
433 | if (!(ie.group_cipher & ssid->group_cipher)) { | |
f049052b BG |
434 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK " |
435 | "cipher mismatch"); | |
6fc6879b JM |
436 | break; |
437 | } | |
438 | ||
439 | if (!(ie.key_mgmt & ssid->key_mgmt)) { | |
f049052b BG |
440 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt " |
441 | "mismatch"); | |
6fc6879b JM |
442 | break; |
443 | } | |
444 | ||
f049052b | 445 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE"); |
6fc6879b JM |
446 | return 1; |
447 | } | |
448 | ||
cc5e390d | 449 | if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) && |
df83fb7d | 450 | wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) { |
f049052b | 451 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match"); |
cc5e390d JM |
452 | return 0; |
453 | } | |
6fc6879b | 454 | |
c2f1fe41 JM |
455 | if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
456 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2"); | |
457 | return 1; | |
458 | } | |
459 | ||
460 | wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with " | |
461 | "WPA/WPA2"); | |
462 | ||
463 | return 0; | |
6fc6879b JM |
464 | } |
465 | ||
466 | ||
b766a9a2 JM |
467 | static int freq_allowed(int *freqs, int freq) |
468 | { | |
469 | int i; | |
470 | ||
471 | if (freqs == NULL) | |
472 | return 1; | |
473 | ||
474 | for (i = 0; freqs[i]; i++) | |
475 | if (freqs[i] == freq) | |
476 | return 1; | |
477 | return 0; | |
478 | } | |
479 | ||
480 | ||
e1e8cae3 CL |
481 | static int ht_supported(const struct hostapd_hw_modes *mode) |
482 | { | |
483 | if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) { | |
484 | /* | |
485 | * The driver did not indicate whether it supports HT. Assume | |
486 | * it does to avoid connection issues. | |
487 | */ | |
488 | return 1; | |
489 | } | |
490 | ||
491 | /* | |
492 | * IEEE Std 802.11n-2009 20.1.1: | |
493 | * An HT non-AP STA shall support all EQM rates for one spatial stream. | |
494 | */ | |
495 | return mode->mcs_set[0] == 0xff; | |
496 | } | |
497 | ||
498 | ||
499 | static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_scan_res *bss) | |
500 | { | |
501 | const struct hostapd_hw_modes *mode = NULL, *modes; | |
502 | const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES }; | |
503 | const u8 *rate_ie; | |
504 | int i, j, k; | |
505 | ||
a6d94e1b JM |
506 | if (bss->freq == 0) |
507 | return 1; /* Cannot do matching without knowing band */ | |
508 | ||
e1e8cae3 CL |
509 | modes = wpa_s->hw.modes; |
510 | if (modes == NULL) { | |
511 | /* | |
512 | * The driver does not provide any additional information | |
513 | * about the utilized hardware, so allow the connection attempt | |
514 | * to continue. | |
515 | */ | |
516 | return 1; | |
517 | } | |
518 | ||
519 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
520 | for (j = 0; j < modes[i].num_channels; j++) { | |
521 | int freq = modes[i].channels[j].freq; | |
522 | if (freq == bss->freq) { | |
523 | if (mode && | |
524 | mode->mode == HOSTAPD_MODE_IEEE80211G) | |
525 | break; /* do not allow 802.11b replace | |
526 | * 802.11g */ | |
527 | mode = &modes[i]; | |
528 | break; | |
529 | } | |
530 | } | |
531 | } | |
532 | ||
533 | if (mode == NULL) | |
534 | return 0; | |
535 | ||
536 | for (i = 0; i < (int) sizeof(scan_ie); i++) { | |
537 | rate_ie = wpa_scan_get_ie(bss, scan_ie[i]); | |
538 | if (rate_ie == NULL) | |
539 | continue; | |
540 | ||
541 | for (j = 2; j < rate_ie[1] + 2; j++) { | |
542 | int flagged = !!(rate_ie[j] & 0x80); | |
543 | int r = (rate_ie[j] & 0x7f) * 5; | |
544 | ||
545 | /* | |
546 | * IEEE Std 802.11n-2009 7.3.2.2: | |
547 | * The new BSS Membership selector value is encoded | |
548 | * like a legacy basic rate, but it is not a rate and | |
549 | * only indicates if the BSS members are required to | |
550 | * support the mandatory features of Clause 20 [HT PHY] | |
551 | * in order to join the BSS. | |
552 | */ | |
553 | if (flagged && ((rate_ie[j] & 0x7f) == | |
554 | BSS_MEMBERSHIP_SELECTOR_HT_PHY)) { | |
555 | if (!ht_supported(mode)) { | |
556 | wpa_dbg(wpa_s, MSG_DEBUG, | |
557 | " hardware does not support " | |
558 | "HT PHY"); | |
559 | return 0; | |
560 | } | |
561 | continue; | |
562 | } | |
563 | ||
564 | if (!flagged) | |
565 | continue; | |
566 | ||
567 | /* check for legacy basic rates */ | |
568 | for (k = 0; k < mode->num_rates; k++) { | |
569 | if (mode->rates[k] == r) | |
570 | break; | |
571 | } | |
572 | if (k == mode->num_rates) { | |
573 | /* | |
574 | * IEEE Std 802.11-2007 7.3.2.2 demands that in | |
575 | * order to join a BSS all required rates | |
576 | * have to be supported by the hardware. | |
577 | */ | |
578 | wpa_dbg(wpa_s, MSG_DEBUG, " hardware does " | |
579 | "not support required rate %d.%d Mbps", | |
580 | r / 10, r % 10); | |
581 | return 0; | |
582 | } | |
583 | } | |
584 | } | |
585 | ||
586 | return 1; | |
587 | } | |
588 | ||
589 | ||
d8d940b7 JM |
590 | static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s, |
591 | int i, struct wpa_scan_res *bss, | |
592 | struct wpa_ssid *group) | |
6fc6879b | 593 | { |
d8d940b7 JM |
594 | const u8 *ssid_; |
595 | u8 wpa_ie_len, rsn_ie_len, ssid_len; | |
596 | int wpa; | |
6fc6879b JM |
597 | struct wpa_blacklist *e; |
598 | const u8 *ie; | |
d8d940b7 | 599 | struct wpa_ssid *ssid; |
6fc6879b | 600 | |
d8d940b7 JM |
601 | ie = wpa_scan_get_ie(bss, WLAN_EID_SSID); |
602 | ssid_ = ie ? ie + 2 : (u8 *) ""; | |
603 | ssid_len = ie ? ie[1] : 0; | |
6fc6879b | 604 | |
d8d940b7 JM |
605 | ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
606 | wpa_ie_len = ie ? ie[1] : 0; | |
6fc6879b | 607 | |
d8d940b7 JM |
608 | ie = wpa_scan_get_ie(bss, WLAN_EID_RSN); |
609 | rsn_ie_len = ie ? ie[1] : 0; | |
6fc6879b | 610 | |
f049052b BG |
611 | wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' " |
612 | "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s", | |
613 | i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len), | |
614 | wpa_ie_len, rsn_ie_len, bss->caps, bss->level, | |
615 | wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : ""); | |
9cf32261 | 616 | |
d8d940b7 | 617 | e = wpa_blacklist_get(wpa_s, bss->bssid); |
5471c343 JM |
618 | if (e) { |
619 | int limit = 1; | |
620 | if (wpa_supplicant_enabled_networks(wpa_s->conf) == 1) { | |
621 | /* | |
622 | * When only a single network is enabled, we can | |
623 | * trigger blacklisting on the first failure. This | |
624 | * should not be done with multiple enabled networks to | |
625 | * avoid getting forced to move into a worse ESS on | |
626 | * single error if there are no other BSSes of the | |
627 | * current ESS. | |
628 | */ | |
629 | limit = 0; | |
630 | } | |
631 | if (e->count > limit) { | |
f049052b BG |
632 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " |
633 | "(count=%d limit=%d)", e->count, limit); | |
c2197bc9 | 634 | return NULL; |
5471c343 | 635 | } |
d8d940b7 | 636 | } |
6fc6879b | 637 | |
d8d940b7 | 638 | if (ssid_len == 0) { |
f049052b | 639 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known"); |
c2197bc9 | 640 | return NULL; |
d8d940b7 | 641 | } |
e81634cd | 642 | |
d8d940b7 | 643 | wpa = wpa_ie_len > 0 || rsn_ie_len > 0; |
6fc6879b | 644 | |
d8d940b7 JM |
645 | for (ssid = group; ssid; ssid = ssid->pnext) { |
646 | int check_ssid = wpa ? 1 : (ssid->ssid_len != 0); | |
ad08c363 | 647 | |
d8d940b7 | 648 | if (ssid->disabled) { |
f049052b | 649 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled"); |
0c703df3 | 650 | continue; |
d8d940b7 | 651 | } |
9cf32261 | 652 | |
ad08c363 | 653 | #ifdef CONFIG_WPS |
f648bc7d | 654 | if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) { |
f049052b BG |
655 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " |
656 | "(WPS)"); | |
f648bc7d JM |
657 | continue; |
658 | } | |
659 | ||
d8d940b7 JM |
660 | if (wpa && ssid->ssid_len == 0 && |
661 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) | |
662 | check_ssid = 0; | |
663 | ||
664 | if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { | |
665 | /* Only allow wildcard SSID match if an AP | |
666 | * advertises active WPS operation that matches | |
667 | * with our mode. */ | |
668 | check_ssid = 1; | |
ad08c363 | 669 | if (ssid->ssid_len == 0 && |
a6099152 | 670 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) |
ad08c363 | 671 | check_ssid = 0; |
d8d940b7 | 672 | } |
ad08c363 JM |
673 | #endif /* CONFIG_WPS */ |
674 | ||
7d232e23 ZC |
675 | if (ssid->bssid_set && ssid->ssid_len == 0 && |
676 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0) | |
677 | check_ssid = 0; | |
678 | ||
d8d940b7 JM |
679 | if (check_ssid && |
680 | (ssid_len != ssid->ssid_len || | |
681 | os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) { | |
f049052b | 682 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch"); |
0c703df3 | 683 | continue; |
6fc6879b | 684 | } |
6fc6879b | 685 | |
d8d940b7 JM |
686 | if (ssid->bssid_set && |
687 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) { | |
f049052b | 688 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch"); |
0c703df3 | 689 | continue; |
d8d940b7 | 690 | } |
6fc6879b | 691 | |
cc5e390d | 692 | if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss)) |
0c703df3 | 693 | continue; |
9cf32261 | 694 | |
d8d940b7 JM |
695 | if (!wpa && |
696 | !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) && | |
697 | !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) && | |
698 | !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) { | |
f049052b BG |
699 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network " |
700 | "not allowed"); | |
0c703df3 | 701 | continue; |
6fc6879b | 702 | } |
9cf32261 | 703 | |
29fbc522 | 704 | if (!wpa_supplicant_match_privacy(bss, ssid)) { |
f049052b BG |
705 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy " |
706 | "mismatch"); | |
0c703df3 | 707 | continue; |
e81634cd JM |
708 | } |
709 | ||
29fbc522 | 710 | if (bss->caps & IEEE80211_CAP_IBSS) { |
f049052b BG |
711 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) " |
712 | "network"); | |
0c703df3 | 713 | continue; |
d8d940b7 | 714 | } |
b766a9a2 | 715 | |
d8d940b7 | 716 | if (!freq_allowed(ssid->freq_list, bss->freq)) { |
f049052b BG |
717 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not " |
718 | "allowed"); | |
0c703df3 | 719 | continue; |
6fc6879b | 720 | } |
d8d940b7 | 721 | |
e1e8cae3 CL |
722 | if (!rate_match(wpa_s, bss)) { |
723 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do " | |
724 | "not match"); | |
725 | continue; | |
726 | } | |
727 | ||
73e49269 JM |
728 | #ifdef CONFIG_P2P |
729 | /* | |
730 | * TODO: skip the AP if its P2P IE has Group Formation | |
731 | * bit set in the P2P Group Capability Bitmap and we | |
732 | * are not in Group Formation with that device. | |
733 | */ | |
734 | #endif /* CONFIG_P2P */ | |
735 | ||
d8d940b7 JM |
736 | /* Matching configuration found */ |
737 | return ssid; | |
6fc6879b JM |
738 | } |
739 | ||
d8d940b7 | 740 | /* No matching configuration found */ |
c2197bc9 | 741 | return NULL; |
9cf32261 JM |
742 | } |
743 | ||
744 | ||
6fa81a3b | 745 | static struct wpa_bss * |
a1fd2ce5 JM |
746 | wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, |
747 | struct wpa_scan_results *scan_res, | |
748 | struct wpa_ssid *group, | |
9cf32261 JM |
749 | struct wpa_ssid **selected_ssid) |
750 | { | |
d8d940b7 | 751 | size_t i; |
9cf32261 | 752 | |
f049052b BG |
753 | wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d", |
754 | group->priority); | |
9cf32261 | 755 | |
d8d940b7 JM |
756 | for (i = 0; i < scan_res->num; i++) { |
757 | struct wpa_scan_res *bss = scan_res->res[i]; | |
758 | const u8 *ie, *ssid; | |
759 | u8 ssid_len; | |
760 | ||
761 | *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group); | |
762 | if (!*selected_ssid) | |
763 | continue; | |
764 | ||
765 | ie = wpa_scan_get_ie(bss, WLAN_EID_SSID); | |
766 | ssid = ie ? ie + 2 : (u8 *) ""; | |
767 | ssid_len = ie ? ie[1] : 0; | |
9cf32261 | 768 | |
f049052b BG |
769 | wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR |
770 | " ssid='%s'", | |
771 | MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len)); | |
d8d940b7 JM |
772 | return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len); |
773 | } | |
774 | ||
775 | return NULL; | |
6fc6879b JM |
776 | } |
777 | ||
778 | ||
6fa81a3b | 779 | static struct wpa_bss * |
09b9df4e | 780 | wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s, |
a1fd2ce5 | 781 | struct wpa_scan_results *scan_res, |
09b9df4e | 782 | struct wpa_ssid **selected_ssid) |
6fc6879b | 783 | { |
6fa81a3b | 784 | struct wpa_bss *selected = NULL; |
09b9df4e JM |
785 | int prio; |
786 | ||
787 | while (selected == NULL) { | |
788 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
789 | selected = wpa_supplicant_select_bss( | |
a1fd2ce5 | 790 | wpa_s, scan_res, wpa_s->conf->pssid[prio], |
09b9df4e JM |
791 | selected_ssid); |
792 | if (selected) | |
793 | break; | |
794 | } | |
795 | ||
796 | if (selected == NULL && wpa_s->blacklist) { | |
f049052b BG |
797 | wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear " |
798 | "blacklist and try again"); | |
09b9df4e JM |
799 | wpa_blacklist_clear(wpa_s); |
800 | wpa_s->blacklist_cleared++; | |
801 | } else if (selected == NULL) | |
802 | break; | |
803 | } | |
804 | ||
805 | return selected; | |
806 | } | |
807 | ||
808 | ||
809 | static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s, | |
977b1174 | 810 | int timeout_sec, int timeout_usec) |
09b9df4e | 811 | { |
24f76940 | 812 | if (!wpa_supplicant_enabled_networks(wpa_s->conf)) { |
4f34d51a SL |
813 | /* |
814 | * No networks are enabled; short-circuit request so | |
815 | * we don't wait timeout seconds before transitioning | |
816 | * to INACTIVE state. | |
817 | */ | |
818 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); | |
819 | return; | |
09b9df4e | 820 | } |
977b1174 | 821 | wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec); |
09b9df4e JM |
822 | } |
823 | ||
824 | ||
5cbd88d9 JJ |
825 | int wpa_supplicant_connect(struct wpa_supplicant *wpa_s, |
826 | struct wpa_bss *selected, | |
827 | struct wpa_ssid *ssid) | |
09b9df4e JM |
828 | { |
829 | if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) { | |
830 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP | |
831 | "PBC session overlap"); | |
b73bf0a7 JM |
832 | #ifdef CONFIG_P2P |
833 | if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1) | |
5cbd88d9 | 834 | return -1; |
b73bf0a7 | 835 | #endif /* CONFIG_P2P */ |
199716ad BG |
836 | |
837 | #ifdef CONFIG_WPS | |
7736f18b | 838 | wpas_wps_cancel(wpa_s); |
199716ad | 839 | #endif /* CONFIG_WPS */ |
5cbd88d9 | 840 | return -1; |
09b9df4e JM |
841 | } |
842 | ||
843 | /* | |
844 | * Do not trigger new association unless the BSSID has changed or if | |
845 | * reassociation is requested. If we are in process of associating with | |
846 | * the selected BSSID, do not trigger new attempt. | |
847 | */ | |
848 | if (wpa_s->reassociate || | |
849 | (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 && | |
e29853bb BG |
850 | ((wpa_s->wpa_state != WPA_ASSOCIATING && |
851 | wpa_s->wpa_state != WPA_AUTHENTICATING) || | |
09b9df4e JM |
852 | os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) != |
853 | 0))) { | |
854 | if (wpa_supplicant_scard_init(wpa_s, ssid)) { | |
977b1174 | 855 | wpa_supplicant_req_new_scan(wpa_s, 10, 0); |
5cbd88d9 | 856 | return 0; |
09b9df4e | 857 | } |
e29853bb BG |
858 | wpa_msg(wpa_s, MSG_DEBUG, "Request association: " |
859 | "reassociate: %d selected: "MACSTR " bssid: " MACSTR | |
860 | " pending: " MACSTR " wpa_state: %s", | |
861 | wpa_s->reassociate, MAC2STR(selected->bssid), | |
862 | MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), | |
863 | wpa_supplicant_state_txt(wpa_s->wpa_state)); | |
09b9df4e JM |
864 | wpa_supplicant_associate(wpa_s, selected, ssid); |
865 | } else { | |
f049052b BG |
866 | wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the " |
867 | "selected AP"); | |
09b9df4e | 868 | } |
5cbd88d9 JJ |
869 | |
870 | return 0; | |
09b9df4e JM |
871 | } |
872 | ||
873 | ||
b55aaa5f JM |
874 | static struct wpa_ssid * |
875 | wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s) | |
876 | { | |
877 | int prio; | |
878 | struct wpa_ssid *ssid; | |
879 | ||
880 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { | |
881 | for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) | |
882 | { | |
883 | if (ssid->disabled) | |
884 | continue; | |
885 | if (ssid->mode == IEEE80211_MODE_IBSS || | |
886 | ssid->mode == IEEE80211_MODE_AP) | |
887 | return ssid; | |
888 | } | |
889 | } | |
890 | return NULL; | |
891 | } | |
892 | ||
893 | ||
a1fd2ce5 JM |
894 | /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based |
895 | * on BSS added and BSS changed events */ | |
6ae93185 | 896 | static void wpa_supplicant_rsn_preauth_scan_results( |
6d28fb96 | 897 | struct wpa_supplicant *wpa_s) |
6ae93185 | 898 | { |
6d28fb96 | 899 | struct wpa_bss *bss; |
6ae93185 JM |
900 | |
901 | if (rsn_preauth_scan_results(wpa_s->wpa) < 0) | |
902 | return; | |
903 | ||
6d28fb96 | 904 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
6ae93185 | 905 | const u8 *ssid, *rsn; |
6ae93185 | 906 | |
6d28fb96 | 907 | ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID); |
6ae93185 JM |
908 | if (ssid == NULL) |
909 | continue; | |
910 | ||
6d28fb96 | 911 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
6ae93185 JM |
912 | if (rsn == NULL) |
913 | continue; | |
914 | ||
6d28fb96 | 915 | rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn); |
6ae93185 JM |
916 | } |
917 | ||
918 | } | |
919 | ||
920 | ||
48563d86 JM |
921 | static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, |
922 | struct wpa_bss *selected, | |
923 | struct wpa_ssid *ssid, | |
924 | struct wpa_scan_results *scan_res) | |
925 | { | |
926 | size_t i; | |
927 | struct wpa_scan_res *current_bss = NULL; | |
928 | int min_diff; | |
929 | ||
930 | if (wpa_s->reassociate) | |
931 | return 1; /* explicit request to reassociate */ | |
932 | if (wpa_s->wpa_state < WPA_ASSOCIATED) | |
933 | return 1; /* we are not associated; continue */ | |
934 | if (wpa_s->current_ssid == NULL) | |
935 | return 1; /* unknown current SSID */ | |
936 | if (wpa_s->current_ssid != ssid) | |
937 | return 1; /* different network block */ | |
938 | ||
22628eca JM |
939 | if (wpas_driver_bss_selection(wpa_s)) |
940 | return 0; /* Driver-based roaming */ | |
941 | ||
48563d86 JM |
942 | for (i = 0; i < scan_res->num; i++) { |
943 | struct wpa_scan_res *res = scan_res->res[i]; | |
944 | const u8 *ie; | |
945 | if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0) | |
946 | continue; | |
947 | ||
948 | ie = wpa_scan_get_ie(res, WLAN_EID_SSID); | |
949 | if (ie == NULL) | |
950 | continue; | |
951 | if (ie[1] != wpa_s->current_ssid->ssid_len || | |
952 | os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0) | |
953 | continue; | |
954 | current_bss = res; | |
955 | break; | |
956 | } | |
957 | ||
958 | if (!current_bss) | |
959 | return 1; /* current BSS not seen in scan results */ | |
960 | ||
f049052b BG |
961 | wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation"); |
962 | wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d", | |
963 | MAC2STR(current_bss->bssid), current_bss->level); | |
964 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d", | |
965 | MAC2STR(selected->bssid), selected->level); | |
48563d86 | 966 | |
ac26ebd8 JM |
967 | if (wpa_s->current_ssid->bssid_set && |
968 | os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) == | |
969 | 0) { | |
f049052b BG |
970 | wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS " |
971 | "has preferred BSSID"); | |
ac26ebd8 JM |
972 | return 1; |
973 | } | |
974 | ||
48563d86 JM |
975 | min_diff = 2; |
976 | if (current_bss->level < 0) { | |
977 | if (current_bss->level < -85) | |
978 | min_diff = 1; | |
979 | else if (current_bss->level < -80) | |
980 | min_diff = 2; | |
981 | else if (current_bss->level < -75) | |
982 | min_diff = 3; | |
983 | else if (current_bss->level < -70) | |
984 | min_diff = 4; | |
985 | else | |
986 | min_diff = 5; | |
987 | } | |
988 | if (abs(current_bss->level - selected->level) < min_diff) { | |
f049052b BG |
989 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference " |
990 | "in signal level"); | |
48563d86 JM |
991 | return 0; |
992 | } | |
993 | ||
994 | return 1; | |
995 | } | |
996 | ||
e1504976 BG |
997 | /* Return < 0 if no scan results could be fetched. */ |
998 | static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, | |
999 | union wpa_event_data *data) | |
09b9df4e | 1000 | { |
6fa81a3b | 1001 | struct wpa_bss *selected; |
6fc6879b | 1002 | struct wpa_ssid *ssid = NULL; |
a1fd2ce5 | 1003 | struct wpa_scan_results *scan_res; |
5bc0cdb7 JM |
1004 | int ap = 0; |
1005 | ||
1006 | #ifdef CONFIG_AP | |
1007 | if (wpa_s->ap_iface) | |
1008 | ap = 1; | |
1009 | #endif /* CONFIG_AP */ | |
6fc6879b | 1010 | |
cb8564b1 DW |
1011 | wpa_supplicant_notify_scanning(wpa_s, 0); |
1012 | ||
a1fd2ce5 JM |
1013 | scan_res = wpa_supplicant_get_scan_results(wpa_s, |
1014 | data ? &data->scan_info : | |
1015 | NULL, 1); | |
1016 | if (scan_res == NULL) { | |
5bc0cdb7 | 1017 | if (wpa_s->conf->ap_scan == 2 || ap) |
e1504976 | 1018 | return -1; |
f049052b BG |
1019 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try " |
1020 | "scanning again"); | |
977b1174 | 1021 | wpa_supplicant_req_new_scan(wpa_s, 1, 0); |
e1504976 | 1022 | return -1; |
6fc6879b JM |
1023 | } |
1024 | ||
bbb921da JM |
1025 | #ifndef CONFIG_NO_RANDOM_POOL |
1026 | size_t i, num; | |
1027 | num = scan_res->num; | |
1028 | if (num > 10) | |
1029 | num = 10; | |
1030 | for (i = 0; i < num; i++) { | |
1031 | u8 buf[5]; | |
1032 | struct wpa_scan_res *res = scan_res->res[i]; | |
1033 | buf[0] = res->bssid[5]; | |
1034 | buf[1] = res->qual & 0xff; | |
1035 | buf[2] = res->noise & 0xff; | |
1036 | buf[3] = res->level & 0xff; | |
1037 | buf[4] = res->tsf & 0xff; | |
1038 | random_add_randomness(buf, sizeof(buf)); | |
1039 | } | |
1040 | #endif /* CONFIG_NO_RANDOM_POOL */ | |
1041 | ||
64e58f51 | 1042 | if (wpa_s->scan_res_handler) { |
860fddbb JB |
1043 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, |
1044 | struct wpa_scan_results *scan_res); | |
1045 | ||
1046 | scan_res_handler = wpa_s->scan_res_handler; | |
64e58f51 | 1047 | wpa_s->scan_res_handler = NULL; |
860fddbb JB |
1048 | scan_res_handler(wpa_s, scan_res); |
1049 | ||
64e58f51 | 1050 | wpa_scan_results_free(scan_res); |
e1504976 | 1051 | return 0; |
64e58f51 JM |
1052 | } |
1053 | ||
5bc0cdb7 | 1054 | if (ap) { |
f049052b | 1055 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode"); |
c202f19c JB |
1056 | #ifdef CONFIG_AP |
1057 | if (wpa_s->ap_iface->scan_cb) | |
1058 | wpa_s->ap_iface->scan_cb(wpa_s->ap_iface); | |
1059 | #endif /* CONFIG_AP */ | |
5bc0cdb7 | 1060 | wpa_scan_results_free(scan_res); |
e1504976 | 1061 | return 0; |
5bc0cdb7 JM |
1062 | } |
1063 | ||
f049052b | 1064 | wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available"); |
24f76940 JM |
1065 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); |
1066 | wpas_notify_scan_results(wpa_s); | |
6fc6879b | 1067 | |
8bac466b JM |
1068 | wpas_notify_scan_done(wpa_s, 1); |
1069 | ||
a1fd2ce5 JM |
1070 | if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) { |
1071 | wpa_scan_results_free(scan_res); | |
e1504976 | 1072 | return 0; |
a1fd2ce5 | 1073 | } |
6fc6879b | 1074 | |
3180d7a2 SO |
1075 | if (wpa_s->disconnected) { |
1076 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
a1fd2ce5 | 1077 | wpa_scan_results_free(scan_res); |
e1504976 | 1078 | return 0; |
3180d7a2 SO |
1079 | } |
1080 | ||
22628eca JM |
1081 | if (!wpas_driver_bss_selection(wpa_s) && |
1082 | bgscan_notify_scan(wpa_s, scan_res) == 1) { | |
a1fd2ce5 | 1083 | wpa_scan_results_free(scan_res); |
e1504976 | 1084 | return 0; |
a1fd2ce5 JM |
1085 | } |
1086 | ||
a1fd2ce5 | 1087 | selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid); |
6ae93185 | 1088 | |
6fc6879b | 1089 | if (selected) { |
48563d86 JM |
1090 | int skip; |
1091 | skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid, | |
1092 | scan_res); | |
1093 | wpa_scan_results_free(scan_res); | |
1094 | if (skip) | |
e1504976 | 1095 | return 0; |
5cbd88d9 JJ |
1096 | |
1097 | if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) { | |
1098 | wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed"); | |
1099 | return -1; | |
1100 | } | |
6d28fb96 | 1101 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
6fc6879b | 1102 | } else { |
48563d86 | 1103 | wpa_scan_results_free(scan_res); |
f049052b | 1104 | wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found"); |
b55aaa5f JM |
1105 | ssid = wpa_supplicant_pick_new_network(wpa_s); |
1106 | if (ssid) { | |
f049052b | 1107 | wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network"); |
b55aaa5f | 1108 | wpa_supplicant_associate(wpa_s, NULL, ssid); |
6d28fb96 | 1109 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
977b1174 | 1110 | } else { |
67b9bd08 | 1111 | int timeout_sec = wpa_s->scan_interval; |
977b1174 | 1112 | int timeout_usec = 0; |
0817de90 JM |
1113 | #ifdef CONFIG_P2P |
1114 | if (wpa_s->p2p_in_provisioning) { | |
1115 | /* | |
1116 | * Use shorter wait during P2P Provisioning | |
1117 | * state to speed up group formation. | |
1118 | */ | |
1119 | timeout_sec = 0; | |
1120 | timeout_usec = 250000; | |
a4cba8f1 LC |
1121 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
1122 | timeout_usec); | |
1123 | return 0; | |
0817de90 JM |
1124 | } |
1125 | #endif /* CONFIG_P2P */ | |
a4cba8f1 LC |
1126 | if (wpa_supplicant_req_sched_scan(wpa_s)) |
1127 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, | |
1128 | timeout_usec); | |
977b1174 | 1129 | } |
6fc6879b | 1130 | } |
e1504976 | 1131 | return 0; |
6fc6879b | 1132 | } |
6859f1cb BG |
1133 | |
1134 | ||
1135 | static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, | |
1136 | union wpa_event_data *data) | |
1137 | { | |
1138 | const char *rn, *rn2; | |
1139 | struct wpa_supplicant *ifs; | |
1140 | ||
e1504976 BG |
1141 | if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) { |
1142 | /* | |
1143 | * If no scan results could be fetched, then no need to | |
1144 | * notify those interfaces that did not actually request | |
1145 | * this scan. | |
1146 | */ | |
1147 | return; | |
1148 | } | |
6859f1cb BG |
1149 | |
1150 | /* | |
1151 | * Check other interfaces to see if they have the same radio-name. If | |
1152 | * so, they get updated with this same scan info. | |
1153 | */ | |
1154 | if (!wpa_s->driver->get_radio_name) | |
1155 | return; | |
1156 | ||
1157 | rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv); | |
1158 | if (rn == NULL || rn[0] == '\0') | |
1159 | return; | |
1160 | ||
f049052b BG |
1161 | wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces " |
1162 | "sharing same radio (%s) in event_scan_results", rn); | |
6859f1cb BG |
1163 | |
1164 | for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { | |
1165 | if (ifs == wpa_s || !ifs->driver->get_radio_name) | |
1166 | continue; | |
1167 | ||
1168 | rn2 = ifs->driver->get_radio_name(ifs->drv_priv); | |
1169 | if (rn2 && os_strcmp(rn, rn2) == 0) { | |
1170 | wpa_printf(MSG_DEBUG, "%s: Updating scan results from " | |
1171 | "sibling", ifs->ifname); | |
1172 | _wpa_supplicant_event_scan_results(ifs, data); | |
1173 | } | |
1174 | } | |
1175 | } | |
1176 | ||
6fc6879b JM |
1177 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
1178 | ||
1179 | ||
579ce771 JM |
1180 | static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, |
1181 | union wpa_event_data *data) | |
6fc6879b JM |
1182 | { |
1183 | int l, len, found = 0, wpa_found, rsn_found; | |
c2a04078 | 1184 | const u8 *p; |
6fc6879b | 1185 | |
f049052b | 1186 | wpa_dbg(wpa_s, MSG_DEBUG, "Association info event"); |
6fc6879b JM |
1187 | if (data->assoc_info.req_ies) |
1188 | wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, | |
1189 | data->assoc_info.req_ies_len); | |
52c9e6f3 | 1190 | if (data->assoc_info.resp_ies) { |
6fc6879b JM |
1191 | wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, |
1192 | data->assoc_info.resp_ies_len); | |
52c9e6f3 JM |
1193 | #ifdef CONFIG_TDLS |
1194 | wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies, | |
1195 | data->assoc_info.resp_ies_len); | |
1196 | #endif /* CONFIG_TDLS */ | |
1197 | } | |
6fc6879b JM |
1198 | if (data->assoc_info.beacon_ies) |
1199 | wpa_hexdump(MSG_DEBUG, "beacon_ies", | |
1200 | data->assoc_info.beacon_ies, | |
1201 | data->assoc_info.beacon_ies_len); | |
4832ecd7 | 1202 | if (data->assoc_info.freq) |
f049052b BG |
1203 | wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz", |
1204 | data->assoc_info.freq); | |
6fc6879b JM |
1205 | |
1206 | p = data->assoc_info.req_ies; | |
1207 | l = data->assoc_info.req_ies_len; | |
1208 | ||
1209 | /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ | |
1210 | while (p && l >= 2) { | |
1211 | len = p[1] + 2; | |
1212 | if (len > l) { | |
1213 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
1214 | p, l); | |
1215 | break; | |
1216 | } | |
1217 | if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
1218 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || | |
1219 | (p[0] == WLAN_EID_RSN && p[1] >= 2)) { | |
1220 | if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) | |
1221 | break; | |
1222 | found = 1; | |
1223 | wpa_find_assoc_pmkid(wpa_s); | |
1224 | break; | |
1225 | } | |
1226 | l -= len; | |
1227 | p += len; | |
1228 | } | |
1229 | if (!found && data->assoc_info.req_ies) | |
1230 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); | |
1231 | ||
c2a04078 | 1232 | #ifdef CONFIG_IEEE80211R |
62c72d72 JM |
1233 | #ifdef CONFIG_SME |
1234 | if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) { | |
1235 | u8 bssid[ETH_ALEN]; | |
1236 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || | |
1237 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, | |
1238 | data->assoc_info.resp_ies, | |
1239 | data->assoc_info.resp_ies_len, | |
1240 | bssid) < 0) { | |
f049052b BG |
1241 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " |
1242 | "Reassociation Response failed"); | |
579ce771 JM |
1243 | wpa_supplicant_deauthenticate( |
1244 | wpa_s, WLAN_REASON_INVALID_IE); | |
1245 | return -1; | |
62c72d72 JM |
1246 | } |
1247 | } | |
62c72d72 | 1248 | |
c2a04078 JM |
1249 | p = data->assoc_info.resp_ies; |
1250 | l = data->assoc_info.resp_ies_len; | |
1251 | ||
54f489be | 1252 | #ifdef CONFIG_WPS_STRICT |
5dac11e0 | 1253 | if (p && wpa_s->current_ssid && |
54f489be JM |
1254 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) { |
1255 | struct wpabuf *wps; | |
1256 | wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE); | |
1257 | if (wps == NULL) { | |
f049052b BG |
1258 | wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not " |
1259 | "include WPS IE in (Re)Association Response"); | |
54f489be JM |
1260 | return -1; |
1261 | } | |
1262 | ||
1263 | if (wps_validate_assoc_resp(wps) < 0) { | |
1264 | wpabuf_free(wps); | |
1265 | wpa_supplicant_deauthenticate( | |
1266 | wpa_s, WLAN_REASON_INVALID_IE); | |
1267 | return -1; | |
1268 | } | |
1269 | wpabuf_free(wps); | |
1270 | } | |
1271 | #endif /* CONFIG_WPS_STRICT */ | |
1272 | ||
e7846b68 | 1273 | /* Go through the IEs and make a copy of the MDIE, if present. */ |
c2a04078 JM |
1274 | while (p && l >= 2) { |
1275 | len = p[1] + 2; | |
1276 | if (len > l) { | |
1277 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", | |
1278 | p, l); | |
1279 | break; | |
1280 | } | |
e7846b68 JM |
1281 | if (p[0] == WLAN_EID_MOBILITY_DOMAIN && |
1282 | p[1] >= MOBILITY_DOMAIN_ID_LEN) { | |
1283 | wpa_s->sme.ft_used = 1; | |
1284 | os_memcpy(wpa_s->sme.mobility_domain, p + 2, | |
1285 | MOBILITY_DOMAIN_ID_LEN); | |
1286 | break; | |
1287 | } | |
c2a04078 JM |
1288 | l -= len; |
1289 | p += len; | |
1290 | } | |
e7846b68 | 1291 | #endif /* CONFIG_SME */ |
c2a04078 | 1292 | |
e7846b68 JM |
1293 | wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies, |
1294 | data->assoc_info.resp_ies_len); | |
c2a04078 JM |
1295 | #endif /* CONFIG_IEEE80211R */ |
1296 | ||
6fc6879b JM |
1297 | /* WPA/RSN IE from Beacon/ProbeResp */ |
1298 | p = data->assoc_info.beacon_ies; | |
1299 | l = data->assoc_info.beacon_ies_len; | |
1300 | ||
1301 | /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. | |
1302 | */ | |
1303 | wpa_found = rsn_found = 0; | |
1304 | while (p && l >= 2) { | |
1305 | len = p[1] + 2; | |
1306 | if (len > l) { | |
1307 | wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", | |
1308 | p, l); | |
1309 | break; | |
1310 | } | |
1311 | if (!wpa_found && | |
1312 | p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && | |
1313 | os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { | |
1314 | wpa_found = 1; | |
1315 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); | |
1316 | } | |
1317 | ||
1318 | if (!rsn_found && | |
1319 | p[0] == WLAN_EID_RSN && p[1] >= 2) { | |
1320 | rsn_found = 1; | |
1321 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); | |
1322 | } | |
1323 | ||
1324 | l -= len; | |
1325 | p += len; | |
1326 | } | |
1327 | ||
1328 | if (!wpa_found && data->assoc_info.beacon_ies) | |
1329 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); | |
1330 | if (!rsn_found && data->assoc_info.beacon_ies) | |
1331 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); | |
1332 | if (wpa_found || rsn_found) | |
1333 | wpa_s->ap_ies_from_associnfo = 1; | |
4832ecd7 | 1334 | |
117e812d JM |
1335 | if (wpa_s->assoc_freq && data->assoc_info.freq && |
1336 | wpa_s->assoc_freq != data->assoc_info.freq) { | |
1337 | wpa_printf(MSG_DEBUG, "Operating frequency changed from " | |
1338 | "%u to %u MHz", | |
1339 | wpa_s->assoc_freq, data->assoc_info.freq); | |
1340 | wpa_supplicant_update_scan_results(wpa_s); | |
1341 | } | |
1342 | ||
4832ecd7 | 1343 | wpa_s->assoc_freq = data->assoc_info.freq; |
579ce771 JM |
1344 | |
1345 | return 0; | |
6fc6879b JM |
1346 | } |
1347 | ||
1348 | ||
1349 | static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, | |
1350 | union wpa_event_data *data) | |
1351 | { | |
1352 | u8 bssid[ETH_ALEN]; | |
1d041bec | 1353 | int ft_completed; |
8bac466b | 1354 | int bssid_changed; |
0194fedb | 1355 | struct wpa_driver_capa capa; |
6fc6879b | 1356 | |
1d041bec JM |
1357 | #ifdef CONFIG_AP |
1358 | if (wpa_s->ap_iface) { | |
1359 | hostapd_notif_assoc(wpa_s->ap_iface->bss[0], | |
1360 | data->assoc_info.addr, | |
1361 | data->assoc_info.req_ies, | |
39b08b5f SP |
1362 | data->assoc_info.req_ies_len, |
1363 | data->assoc_info.reassoc); | |
1d041bec JM |
1364 | return; |
1365 | } | |
1366 | #endif /* CONFIG_AP */ | |
1367 | ||
1368 | ft_completed = wpa_ft_is_completed(wpa_s->wpa); | |
579ce771 JM |
1369 | if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0) |
1370 | return; | |
6fc6879b JM |
1371 | |
1372 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); | |
17fbb751 JM |
1373 | if (wpa_drv_get_bssid(wpa_s, bssid) >= 0 && |
1374 | os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) { | |
f049052b | 1375 | wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" |
6fc6879b | 1376 | MACSTR, MAC2STR(bssid)); |
bbb921da | 1377 | random_add_randomness(bssid, ETH_ALEN); |
8bac466b | 1378 | bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN); |
6fc6879b JM |
1379 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
1380 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
8bac466b JM |
1381 | if (bssid_changed) |
1382 | wpas_notify_bssid_changed(wpa_s); | |
1383 | ||
6fc6879b JM |
1384 | if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { |
1385 | wpa_clear_keys(wpa_s, bssid); | |
1386 | } | |
1387 | if (wpa_supplicant_select_config(wpa_s) < 0) { | |
1388 | wpa_supplicant_disassociate( | |
1389 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
1390 | return; | |
1391 | } | |
8f770587 JM |
1392 | if (wpa_s->current_ssid) { |
1393 | struct wpa_bss *bss = NULL; | |
1394 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
1395 | if (ssid->ssid_len > 0) | |
1396 | bss = wpa_bss_get(wpa_s, bssid, | |
1397 | ssid->ssid, ssid->ssid_len); | |
1398 | if (!bss) | |
1399 | bss = wpa_bss_get_bssid(wpa_s, bssid); | |
1400 | if (bss) | |
1401 | wpa_s->current_bss = bss; | |
1402 | } | |
6fc6879b JM |
1403 | } |
1404 | ||
62fa124c JM |
1405 | #ifdef CONFIG_SME |
1406 | os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN); | |
1407 | wpa_s->sme.prev_bssid_set = 1; | |
1408 | #endif /* CONFIG_SME */ | |
1409 | ||
6fc6879b JM |
1410 | wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); |
1411 | if (wpa_s->current_ssid) { | |
1412 | /* When using scanning (ap_scan=1), SIM PC/SC interface can be | |
1413 | * initialized before association, but for other modes, | |
1414 | * initialize PC/SC here, if the current configuration needs | |
1415 | * smartcard or SIM/USIM. */ | |
1416 | wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); | |
1417 | } | |
1418 | wpa_sm_notify_assoc(wpa_s->wpa, bssid); | |
3f967fe0 JM |
1419 | if (wpa_s->l2) |
1420 | l2_packet_notify_auth_start(wpa_s->l2); | |
6fc6879b JM |
1421 | |
1422 | /* | |
1423 | * Set portEnabled first to FALSE in order to get EAP state machine out | |
1424 | * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE | |
1425 | * state machine may transit to AUTHENTICATING state based on obsolete | |
1426 | * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to | |
1427 | * AUTHENTICATED without ever giving chance to EAP state machine to | |
1428 | * reset the state. | |
1429 | */ | |
1430 | if (!ft_completed) { | |
1431 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); | |
1432 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); | |
1433 | } | |
56586197 | 1434 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed) |
6fc6879b JM |
1435 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
1436 | /* 802.1X::portControl = Auto */ | |
1437 | eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE); | |
1438 | wpa_s->eapol_received = 0; | |
1439 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || | |
9c972abb JM |
1440 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || |
1441 | (wpa_s->current_ssid && | |
1442 | wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) { | |
6fc6879b JM |
1443 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
1444 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1445 | } else if (!ft_completed) { | |
1446 | /* Timeout for receiving the first EAPOL packet */ | |
1447 | wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); | |
1448 | } | |
1449 | wpa_supplicant_cancel_scan(wpa_s); | |
1450 | ||
c2a04078 | 1451 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
56586197 | 1452 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
6fc6879b JM |
1453 | /* |
1454 | * We are done; the driver will take care of RSN 4-way | |
1455 | * handshake. | |
1456 | */ | |
1457 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
1458 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1459 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
1460 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
98ea9431 JM |
1461 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
1462 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { | |
1463 | /* | |
1464 | * The driver will take care of RSN 4-way handshake, so we need | |
1465 | * to allow EAPOL supplicant to complete its work without | |
1466 | * waiting for WPA supplicant. | |
1467 | */ | |
1468 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
16a83d29 JM |
1469 | } else if (ft_completed) { |
1470 | /* | |
1471 | * FT protocol completed - make sure EAPOL state machine ends | |
1472 | * up in authenticated. | |
1473 | */ | |
1474 | wpa_supplicant_cancel_auth_timeout(wpa_s); | |
1475 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); | |
1476 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); | |
1477 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); | |
6fc6879b | 1478 | } |
1ff73338 JM |
1479 | |
1480 | if (wpa_s->pending_eapol_rx) { | |
1481 | struct os_time now, age; | |
1482 | os_get_time(&now); | |
1483 | os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age); | |
1484 | if (age.sec == 0 && age.usec < 100000 && | |
1485 | os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) == | |
1486 | 0) { | |
f049052b BG |
1487 | wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL " |
1488 | "frame that was received just before " | |
1489 | "association notification"); | |
1ff73338 JM |
1490 | wpa_supplicant_rx_eapol( |
1491 | wpa_s, wpa_s->pending_eapol_rx_src, | |
1492 | wpabuf_head(wpa_s->pending_eapol_rx), | |
1493 | wpabuf_len(wpa_s->pending_eapol_rx)); | |
1494 | } | |
1495 | wpabuf_free(wpa_s->pending_eapol_rx); | |
1496 | wpa_s->pending_eapol_rx = NULL; | |
1497 | } | |
60b94c98 | 1498 | |
0194fedb JB |
1499 | if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
1500 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && | |
1501 | wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 && | |
1502 | capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) { | |
1503 | /* Set static WEP keys again */ | |
1504 | wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); | |
1505 | } | |
50b05780 JM |
1506 | |
1507 | #ifdef CONFIG_IBSS_RSN | |
1508 | if (wpa_s->current_ssid && | |
1509 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && | |
1510 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && | |
78177a00 JM |
1511 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE && |
1512 | wpa_s->ibss_rsn == NULL) { | |
1513 | wpa_s->ibss_rsn = ibss_rsn_init(wpa_s); | |
1514 | if (!wpa_s->ibss_rsn) { | |
1515 | wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN"); | |
1516 | wpa_supplicant_deauthenticate( | |
1517 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); | |
1518 | return; | |
1519 | } | |
1520 | ||
1521 | ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk); | |
1522 | } | |
50b05780 | 1523 | #endif /* CONFIG_IBSS_RSN */ |
6fc6879b JM |
1524 | } |
1525 | ||
1526 | ||
0544b242 JM |
1527 | static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, |
1528 | u16 reason_code) | |
6fc6879b JM |
1529 | { |
1530 | const u8 *bssid; | |
6d6f4bb8 JM |
1531 | int authenticating; |
1532 | u8 prev_pending_bssid[ETH_ALEN]; | |
1533 | ||
1534 | authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING; | |
1535 | os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN); | |
6fc6879b JM |
1536 | |
1537 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { | |
1538 | /* | |
1539 | * At least Host AP driver and a Prism3 card seemed to be | |
1540 | * generating streams of disconnected events when configuring | |
1541 | * IBSS for WPA-None. Ignore them for now. | |
1542 | */ | |
f049052b BG |
1543 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in " |
1544 | "IBSS/WPA-None mode"); | |
6fc6879b JM |
1545 | return; |
1546 | } | |
1547 | ||
1548 | if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE && | |
56586197 | 1549 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
6fc6879b JM |
1550 | wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " |
1551 | "pre-shared key may be incorrect"); | |
1552 | } | |
0d0a8ca1 AC |
1553 | if (!wpa_s->auto_reconnect_disabled || |
1554 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { | |
f049052b BG |
1555 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect enabled: try to " |
1556 | "reconnect (wps=%d)", | |
1557 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS); | |
ea184114 | 1558 | if (wpa_s->wpa_state >= WPA_ASSOCIATING) |
0d0a8ca1 AC |
1559 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
1560 | } else { | |
f049052b BG |
1561 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect disabled: do not " |
1562 | "try to re-connect"); | |
0d0a8ca1 AC |
1563 | wpa_s->reassociate = 0; |
1564 | wpa_s->disconnected = 1; | |
1565 | } | |
6fc6879b | 1566 | bssid = wpa_s->bssid; |
a8e16edc | 1567 | if (is_zero_ether_addr(bssid)) |
6fc6879b | 1568 | bssid = wpa_s->pending_bssid; |
0fb337c1 | 1569 | wpas_connection_failed(wpa_s, bssid); |
6fc6879b | 1570 | wpa_sm_notify_disassoc(wpa_s->wpa); |
0544b242 JM |
1571 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR |
1572 | " reason=%d", | |
1573 | MAC2STR(bssid), reason_code); | |
6fc6879b | 1574 | if (wpa_supplicant_dynamic_keys(wpa_s)) { |
f049052b | 1575 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys"); |
6fc6879b JM |
1576 | wpa_s->keys_cleared = 0; |
1577 | wpa_clear_keys(wpa_s, wpa_s->bssid); | |
1578 | } | |
1579 | wpa_supplicant_mark_disassoc(wpa_s); | |
e29853bb BG |
1580 | |
1581 | if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) | |
1582 | sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid); | |
6fc6879b JM |
1583 | } |
1584 | ||
1585 | ||
46690a3b JM |
1586 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
1587 | static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, | |
1588 | void *sock_ctx) | |
1589 | { | |
1590 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1591 | ||
1592 | if (!wpa_s->pending_mic_error_report) | |
1593 | return; | |
1594 | ||
f049052b | 1595 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report"); |
46690a3b JM |
1596 | wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); |
1597 | wpa_s->pending_mic_error_report = 0; | |
1598 | } | |
1599 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
1600 | ||
1601 | ||
6fc6879b JM |
1602 | static void |
1603 | wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, | |
1604 | union wpa_event_data *data) | |
1605 | { | |
1606 | int pairwise; | |
1607 | struct os_time t; | |
1608 | ||
1609 | wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); | |
1610 | pairwise = (data && data->michael_mic_failure.unicast); | |
6fc6879b | 1611 | os_get_time(&t); |
46690a3b JM |
1612 | if ((wpa_s->last_michael_mic_error && |
1613 | t.sec - wpa_s->last_michael_mic_error <= 60) || | |
1614 | wpa_s->pending_mic_error_report) { | |
1615 | if (wpa_s->pending_mic_error_report) { | |
1616 | /* | |
1617 | * Send the pending MIC error report immediately since | |
1618 | * we are going to start countermeasures and AP better | |
1619 | * do the same. | |
1620 | */ | |
1621 | wpa_sm_key_request(wpa_s->wpa, 1, | |
1622 | wpa_s->pending_mic_error_pairwise); | |
1623 | } | |
1624 | ||
1625 | /* Send the new MIC error report immediately since we are going | |
1626 | * to start countermeasures and AP better do the same. | |
1627 | */ | |
1628 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1629 | ||
6fc6879b JM |
1630 | /* initialize countermeasures */ |
1631 | wpa_s->countermeasures = 1; | |
1632 | wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); | |
1633 | ||
1634 | /* | |
1635 | * Need to wait for completion of request frame. We do not get | |
1636 | * any callback for the message completion, so just wait a | |
1637 | * short while and hope for the best. */ | |
1638 | os_sleep(0, 10000); | |
1639 | ||
1640 | wpa_drv_set_countermeasures(wpa_s, 1); | |
1641 | wpa_supplicant_deauthenticate(wpa_s, | |
1642 | WLAN_REASON_MICHAEL_MIC_FAILURE); | |
1643 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, | |
1644 | wpa_s, NULL); | |
1645 | eloop_register_timeout(60, 0, | |
1646 | wpa_supplicant_stop_countermeasures, | |
1647 | wpa_s, NULL); | |
1648 | /* TODO: mark the AP rejected for 60 second. STA is | |
1649 | * allowed to associate with another AP.. */ | |
46690a3b JM |
1650 | } else { |
1651 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT | |
1652 | if (wpa_s->mic_errors_seen) { | |
1653 | /* | |
1654 | * Reduce the effectiveness of Michael MIC error | |
1655 | * reports as a means for attacking against TKIP if | |
1656 | * more than one MIC failure is noticed with the same | |
1657 | * PTK. We delay the transmission of the reports by a | |
1658 | * random time between 0 and 60 seconds in order to | |
1659 | * force the attacker wait 60 seconds before getting | |
1660 | * the information on whether a frame resulted in a MIC | |
1661 | * failure. | |
1662 | */ | |
1663 | u8 rval[4]; | |
1664 | int sec; | |
1665 | ||
1666 | if (os_get_random(rval, sizeof(rval)) < 0) | |
1667 | sec = os_random() % 60; | |
1668 | else | |
1669 | sec = WPA_GET_BE32(rval) % 60; | |
f049052b BG |
1670 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error " |
1671 | "report %d seconds", sec); | |
46690a3b JM |
1672 | wpa_s->pending_mic_error_report = 1; |
1673 | wpa_s->pending_mic_error_pairwise = pairwise; | |
1674 | eloop_cancel_timeout( | |
1675 | wpa_supplicant_delayed_mic_error_report, | |
1676 | wpa_s, NULL); | |
1677 | eloop_register_timeout( | |
1678 | sec, os_random() % 1000000, | |
1679 | wpa_supplicant_delayed_mic_error_report, | |
1680 | wpa_s, NULL); | |
1681 | } else { | |
1682 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1683 | } | |
1684 | #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
1685 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); | |
1686 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ | |
6fc6879b JM |
1687 | } |
1688 | wpa_s->last_michael_mic_error = t.sec; | |
46690a3b | 1689 | wpa_s->mic_errors_seen++; |
6fc6879b JM |
1690 | } |
1691 | ||
1692 | ||
a83d9c96 SL |
1693 | #ifdef CONFIG_TERMINATE_ONLASTIF |
1694 | static int any_interfaces(struct wpa_supplicant *head) | |
1695 | { | |
1696 | struct wpa_supplicant *wpa_s; | |
1697 | ||
1698 | for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) | |
1699 | if (!wpa_s->interface_removed) | |
1700 | return 1; | |
1701 | return 0; | |
1702 | } | |
1703 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
1704 | ||
1705 | ||
6fc6879b JM |
1706 | static void |
1707 | wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, | |
1708 | union wpa_event_data *data) | |
1709 | { | |
1710 | if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) | |
1711 | return; | |
1712 | ||
1713 | switch (data->interface_status.ievent) { | |
1714 | case EVENT_INTERFACE_ADDED: | |
1715 | if (!wpa_s->interface_removed) | |
1716 | break; | |
1717 | wpa_s->interface_removed = 0; | |
f049052b | 1718 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added"); |
6fc6879b | 1719 | if (wpa_supplicant_driver_init(wpa_s) < 0) { |
f049052b BG |
1720 | wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the " |
1721 | "driver after interface was added"); | |
6fc6879b JM |
1722 | } |
1723 | break; | |
1724 | case EVENT_INTERFACE_REMOVED: | |
f049052b | 1725 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed"); |
6fc6879b JM |
1726 | wpa_s->interface_removed = 1; |
1727 | wpa_supplicant_mark_disassoc(wpa_s); | |
1728 | l2_packet_deinit(wpa_s->l2); | |
1729 | wpa_s->l2 = NULL; | |
ea244d21 | 1730 | #ifdef CONFIG_IBSS_RSN |
78177a00 JM |
1731 | ibss_rsn_deinit(wpa_s->ibss_rsn); |
1732 | wpa_s->ibss_rsn = NULL; | |
ea244d21 | 1733 | #endif /* CONFIG_IBSS_RSN */ |
a83d9c96 SL |
1734 | #ifdef CONFIG_TERMINATE_ONLASTIF |
1735 | /* check if last interface */ | |
1736 | if (!any_interfaces(wpa_s->global->ifaces)) | |
1737 | eloop_terminate(); | |
1738 | #endif /* CONFIG_TERMINATE_ONLASTIF */ | |
6fc6879b JM |
1739 | break; |
1740 | } | |
1741 | } | |
1742 | ||
1743 | ||
1744 | #ifdef CONFIG_PEERKEY | |
1745 | static void | |
1746 | wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s, | |
1747 | union wpa_event_data *data) | |
1748 | { | |
1749 | if (data == NULL) | |
1750 | return; | |
1751 | wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer); | |
1752 | } | |
1753 | #endif /* CONFIG_PEERKEY */ | |
1754 | ||
1755 | ||
281ff0aa GP |
1756 | #ifdef CONFIG_TDLS |
1757 | static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s, | |
1758 | union wpa_event_data *data) | |
1759 | { | |
1760 | if (data == NULL) | |
1761 | return; | |
1762 | switch (data->tdls.oper) { | |
1763 | case TDLS_REQUEST_SETUP: | |
1764 | wpa_tdls_start(wpa_s->wpa, data->tdls.peer); | |
1765 | break; | |
1766 | case TDLS_REQUEST_TEARDOWN: | |
7de27409 AN |
1767 | wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer, |
1768 | data->tdls.reason_code); | |
281ff0aa GP |
1769 | break; |
1770 | } | |
1771 | } | |
1772 | #endif /* CONFIG_TDLS */ | |
1773 | ||
1774 | ||
6fc6879b JM |
1775 | #ifdef CONFIG_IEEE80211R |
1776 | static void | |
1777 | wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s, | |
1778 | union wpa_event_data *data) | |
1779 | { | |
1780 | if (data == NULL) | |
1781 | return; | |
1782 | ||
1783 | if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies, | |
1784 | data->ft_ies.ies_len, | |
1785 | data->ft_ies.ft_action, | |
babfbf15 JM |
1786 | data->ft_ies.target_ap, |
1787 | data->ft_ies.ric_ies, | |
1788 | data->ft_ies.ric_ies_len) < 0) { | |
6fc6879b JM |
1789 | /* TODO: prevent MLME/driver from trying to associate? */ |
1790 | } | |
1791 | } | |
1792 | #endif /* CONFIG_IEEE80211R */ | |
1793 | ||
1794 | ||
11ef8d35 JM |
1795 | #ifdef CONFIG_IBSS_RSN |
1796 | static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s, | |
1797 | union wpa_event_data *data) | |
1798 | { | |
df4bc509 | 1799 | struct wpa_ssid *ssid; |
df418245 XC |
1800 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
1801 | return; | |
11ef8d35 JM |
1802 | if (data == NULL) |
1803 | return; | |
df4bc509 JM |
1804 | ssid = wpa_s->current_ssid; |
1805 | if (ssid == NULL) | |
1806 | return; | |
1807 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) | |
1808 | return; | |
1809 | ||
11ef8d35 JM |
1810 | ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); |
1811 | } | |
1812 | #endif /* CONFIG_IBSS_RSN */ | |
1813 | ||
1814 | ||
036f7c4a JM |
1815 | #ifdef CONFIG_IEEE80211R |
1816 | static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data, | |
1817 | size_t len) | |
1818 | { | |
1819 | const u8 *sta_addr, *target_ap_addr; | |
1820 | u16 status; | |
1821 | ||
1822 | wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len); | |
1823 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) | |
1824 | return; /* only SME case supported for now */ | |
1825 | if (len < 1 + 2 * ETH_ALEN + 2) | |
1826 | return; | |
1827 | if (data[0] != 2) | |
1828 | return; /* Only FT Action Response is supported for now */ | |
1829 | sta_addr = data + 1; | |
1830 | target_ap_addr = data + 1 + ETH_ALEN; | |
1831 | status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN); | |
f049052b BG |
1832 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA " |
1833 | MACSTR " TargetAP " MACSTR " status %u", | |
1834 | MAC2STR(sta_addr), MAC2STR(target_ap_addr), status); | |
036f7c4a JM |
1835 | |
1836 | if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) { | |
f049052b BG |
1837 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR |
1838 | " in FT Action Response", MAC2STR(sta_addr)); | |
036f7c4a JM |
1839 | return; |
1840 | } | |
1841 | ||
1842 | if (status) { | |
f049052b BG |
1843 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates " |
1844 | "failure (status code %d)", status); | |
036f7c4a JM |
1845 | /* TODO: report error to FT code(?) */ |
1846 | return; | |
1847 | } | |
1848 | ||
1849 | if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2, | |
1850 | len - (1 + 2 * ETH_ALEN + 2), 1, | |
1851 | target_ap_addr, NULL, 0) < 0) | |
1852 | return; | |
1853 | ||
fe191985 JM |
1854 | #ifdef CONFIG_SME |
1855 | { | |
1856 | struct wpa_bss *bss; | |
1857 | bss = wpa_bss_get_bssid(wpa_s, target_ap_addr); | |
1858 | if (bss) | |
1859 | wpa_s->sme.freq = bss->freq; | |
62c72d72 | 1860 | wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT; |
fe191985 JM |
1861 | sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr, |
1862 | WLAN_AUTH_FT); | |
1863 | } | |
1864 | #endif /* CONFIG_SME */ | |
036f7c4a JM |
1865 | } |
1866 | #endif /* CONFIG_IEEE80211R */ | |
1867 | ||
1868 | ||
7d878ca7 JM |
1869 | static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s, |
1870 | struct unprot_deauth *e) | |
1871 | { | |
1872 | #ifdef CONFIG_IEEE80211W | |
1873 | wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame " | |
1874 | "dropped: " MACSTR " -> " MACSTR | |
1875 | " (reason code %u)", | |
1876 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); | |
1877 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); | |
1878 | #endif /* CONFIG_IEEE80211W */ | |
1879 | } | |
1880 | ||
1881 | ||
1882 | static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s, | |
1883 | struct unprot_disassoc *e) | |
1884 | { | |
1885 | #ifdef CONFIG_IEEE80211W | |
1886 | wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame " | |
1887 | "dropped: " MACSTR " -> " MACSTR | |
1888 | " (reason code %u)", | |
1889 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); | |
1890 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); | |
1891 | #endif /* CONFIG_IEEE80211W */ | |
1892 | } | |
1893 | ||
1894 | ||
71269b37 JM |
1895 | static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx) |
1896 | { | |
1897 | u8 action, mode; | |
1898 | const u8 *pos, *end; | |
1899 | ||
1900 | if (rx->data == NULL || rx->len == 0) | |
1901 | return; | |
1902 | ||
1903 | pos = rx->data; | |
1904 | end = pos + rx->len; | |
1905 | action = *pos++; | |
1906 | ||
1907 | wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR, | |
1908 | action, MAC2STR(rx->sa)); | |
1909 | switch (action) { | |
1910 | case WNM_BSS_TRANS_MGMT_REQ: | |
1911 | if (pos + 5 > end) | |
1912 | break; | |
1913 | wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management " | |
1914 | "Request: dialog_token=%u request_mode=0x%x " | |
1915 | "disassoc_timer=%u validity_interval=%u", | |
1916 | pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]); | |
1917 | mode = pos[1]; | |
1918 | pos += 5; | |
1919 | if (mode & 0x08) | |
1920 | pos += 12; /* BSS Termination Duration */ | |
1921 | if (mode & 0x10) { | |
1922 | char url[256]; | |
1923 | if (pos + 1 > end || pos + 1 + pos[0] > end) { | |
1924 | wpa_printf(MSG_DEBUG, "WNM: Invalid BSS " | |
1925 | "Transition Management Request " | |
1926 | "(URL)"); | |
1927 | break; | |
1928 | } | |
1929 | os_memcpy(url, pos + 1, pos[0]); | |
1930 | url[pos[0]] = '\0'; | |
1931 | wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation " | |
1932 | "Imminent - session_info_url=%s", url); | |
1933 | } | |
1934 | break; | |
1935 | } | |
1936 | } | |
1937 | ||
1938 | ||
9646a8ab | 1939 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
6fc6879b JM |
1940 | union wpa_event_data *data) |
1941 | { | |
1942 | struct wpa_supplicant *wpa_s = ctx; | |
0544b242 | 1943 | u16 reason_code = 0; |
6fc6879b | 1944 | |
8401a6b0 JM |
1945 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED && |
1946 | event != EVENT_INTERFACE_ENABLED && | |
1947 | event != EVENT_INTERFACE_STATUS) { | |
f049052b BG |
1948 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore event %d while interface is " |
1949 | "disabled", event); | |
8401a6b0 JM |
1950 | return; |
1951 | } | |
1952 | ||
f049052b BG |
1953 | wpa_dbg(wpa_s, MSG_DEBUG, "Event %d received on interface %s", |
1954 | event, wpa_s->ifname); | |
9b7124b2 | 1955 | |
6fc6879b | 1956 | switch (event) { |
c2a04078 JM |
1957 | case EVENT_AUTH: |
1958 | sme_event_auth(wpa_s, data); | |
1959 | break; | |
6fc6879b JM |
1960 | case EVENT_ASSOC: |
1961 | wpa_supplicant_event_assoc(wpa_s, data); | |
1962 | break; | |
1963 | case EVENT_DISASSOC: | |
f049052b | 1964 | wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification"); |
2e75a2b3 | 1965 | if (data) { |
f049052b BG |
1966 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u", |
1967 | data->disassoc_info.reason_code); | |
2e75a2b3 | 1968 | if (data->disassoc_info.addr) |
f049052b BG |
1969 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, |
1970 | MAC2STR(data->disassoc_info.addr)); | |
2e75a2b3 | 1971 | } |
1d041bec | 1972 | #ifdef CONFIG_AP |
7f542069 | 1973 | if (wpa_s->ap_iface && data && data->disassoc_info.addr) { |
1d041bec JM |
1974 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], |
1975 | data->disassoc_info.addr); | |
1976 | break; | |
1977 | } | |
1978 | #endif /* CONFIG_AP */ | |
9fdd0fad JM |
1979 | if (data) { |
1980 | reason_code = data->disassoc_info.reason_code; | |
1981 | wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)", | |
1982 | data->disassoc_info.ie, | |
1983 | data->disassoc_info.ie_len); | |
1984 | #ifdef CONFIG_P2P | |
1985 | wpas_p2p_disassoc_notif( | |
1986 | wpa_s, data->disassoc_info.addr, reason_code, | |
1987 | data->disassoc_info.ie, | |
1988 | data->disassoc_info.ie_len); | |
1989 | #endif /* CONFIG_P2P */ | |
1990 | } | |
0e379654 JM |
1991 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
1992 | sme_event_disassoc(wpa_s, data); | |
a84ed99e JM |
1993 | /* fall through */ |
1994 | case EVENT_DEAUTH: | |
0544b242 | 1995 | if (event == EVENT_DEAUTH) { |
f049052b BG |
1996 | wpa_dbg(wpa_s, MSG_DEBUG, |
1997 | "Deauthentication notification"); | |
2e75a2b3 | 1998 | if (data) { |
0544b242 | 1999 | reason_code = data->deauth_info.reason_code; |
f049052b BG |
2000 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u", |
2001 | data->deauth_info.reason_code); | |
2e75a2b3 | 2002 | if (data->deauth_info.addr) { |
f049052b BG |
2003 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " |
2004 | MACSTR, | |
2005 | MAC2STR(data->deauth_info. | |
2006 | addr)); | |
2e75a2b3 | 2007 | } |
9fdd0fad JM |
2008 | wpa_hexdump(MSG_DEBUG, |
2009 | "Deauthentication frame IE(s)", | |
2010 | data->deauth_info.ie, | |
2011 | data->deauth_info.ie_len); | |
2012 | #ifdef CONFIG_P2P | |
2013 | wpas_p2p_deauth_notif( | |
2014 | wpa_s, data->deauth_info.addr, | |
2015 | reason_code, | |
2016 | data->deauth_info.ie, | |
2017 | data->deauth_info.ie_len); | |
2018 | #endif /* CONFIG_P2P */ | |
2e75a2b3 | 2019 | } |
0544b242 | 2020 | } |
1d041bec | 2021 | #ifdef CONFIG_AP |
7f542069 | 2022 | if (wpa_s->ap_iface && data && data->deauth_info.addr) { |
1d041bec JM |
2023 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], |
2024 | data->deauth_info.addr); | |
2025 | break; | |
2026 | } | |
2027 | #endif /* CONFIG_AP */ | |
0544b242 | 2028 | wpa_supplicant_event_disassoc(wpa_s, reason_code); |
6fc6879b JM |
2029 | break; |
2030 | case EVENT_MICHAEL_MIC_FAILURE: | |
2031 | wpa_supplicant_event_michael_mic_failure(wpa_s, data); | |
2032 | break; | |
2033 | #ifndef CONFIG_NO_SCAN_PROCESSING | |
2034 | case EVENT_SCAN_RESULTS: | |
8d923a4a | 2035 | wpa_supplicant_event_scan_results(wpa_s, data); |
6fc6879b JM |
2036 | break; |
2037 | #endif /* CONFIG_NO_SCAN_PROCESSING */ | |
2038 | case EVENT_ASSOCINFO: | |
2039 | wpa_supplicant_event_associnfo(wpa_s, data); | |
2040 | break; | |
2041 | case EVENT_INTERFACE_STATUS: | |
2042 | wpa_supplicant_event_interface_status(wpa_s, data); | |
2043 | break; | |
2044 | case EVENT_PMKID_CANDIDATE: | |
2045 | wpa_supplicant_event_pmkid_candidate(wpa_s, data); | |
2046 | break; | |
2047 | #ifdef CONFIG_PEERKEY | |
2048 | case EVENT_STKSTART: | |
2049 | wpa_supplicant_event_stkstart(wpa_s, data); | |
2050 | break; | |
2051 | #endif /* CONFIG_PEERKEY */ | |
281ff0aa GP |
2052 | #ifdef CONFIG_TDLS |
2053 | case EVENT_TDLS: | |
2054 | wpa_supplicant_event_tdls(wpa_s, data); | |
2055 | break; | |
2056 | #endif /* CONFIG_TDLS */ | |
6fc6879b JM |
2057 | #ifdef CONFIG_IEEE80211R |
2058 | case EVENT_FT_RESPONSE: | |
2059 | wpa_supplicant_event_ft_response(wpa_s, data); | |
2060 | break; | |
2061 | #endif /* CONFIG_IEEE80211R */ | |
11ef8d35 JM |
2062 | #ifdef CONFIG_IBSS_RSN |
2063 | case EVENT_IBSS_RSN_START: | |
2064 | wpa_supplicant_event_ibss_rsn_start(wpa_s, data); | |
2065 | break; | |
2066 | #endif /* CONFIG_IBSS_RSN */ | |
efa46078 | 2067 | case EVENT_ASSOC_REJECT: |
c05d6d18 JM |
2068 | if (data->assoc_reject.bssid) |
2069 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT | |
2070 | "bssid=" MACSTR " status_code=%u", | |
2071 | MAC2STR(data->assoc_reject.bssid), | |
2072 | data->assoc_reject.status_code); | |
2073 | else | |
2074 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT | |
2075 | "status_code=%u", | |
2076 | data->assoc_reject.status_code); | |
ea78c315 JM |
2077 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
2078 | sme_event_assoc_reject(wpa_s, data); | |
efa46078 | 2079 | break; |
da1fb17c | 2080 | case EVENT_AUTH_TIMED_OUT: |
ea78c315 JM |
2081 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
2082 | sme_event_auth_timed_out(wpa_s, data); | |
da1fb17c JM |
2083 | break; |
2084 | case EVENT_ASSOC_TIMED_OUT: | |
ea78c315 JM |
2085 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
2086 | sme_event_assoc_timed_out(wpa_s, data); | |
da1fb17c | 2087 | break; |
f8b1f695 | 2088 | case EVENT_TX_STATUS: |
f049052b BG |
2089 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR |
2090 | " type=%d stype=%d", | |
2091 | MAC2STR(data->tx_status.dst), | |
2092 | data->tx_status.type, data->tx_status.stype); | |
24f6497c | 2093 | #ifdef CONFIG_AP |
9bae1be0 | 2094 | if (wpa_s->ap_iface == NULL) { |
24f6497c | 2095 | #ifdef CONFIG_OFFCHANNEL |
9bae1be0 JM |
2096 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
2097 | data->tx_status.stype == WLAN_FC_STYPE_ACTION) | |
24f6497c | 2098 | offchannel_send_action_tx_status( |
9bae1be0 JM |
2099 | wpa_s, data->tx_status.dst, |
2100 | data->tx_status.data, | |
2101 | data->tx_status.data_len, | |
93b7ddd0 | 2102 | data->tx_status.ack ? |
24f6497c JM |
2103 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
2104 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
2105 | #endif /* CONFIG_OFFCHANNEL */ | |
9bae1be0 JM |
2106 | break; |
2107 | } | |
24f6497c JM |
2108 | #endif /* CONFIG_AP */ |
2109 | #ifdef CONFIG_OFFCHANNEL | |
f049052b BG |
2110 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst=" |
2111 | MACSTR, MAC2STR(wpa_s->parent->pending_action_dst)); | |
9bae1be0 JM |
2112 | /* |
2113 | * Catch TX status events for Action frames we sent via group | |
2114 | * interface in GO mode. | |
2115 | */ | |
2116 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && | |
2117 | data->tx_status.stype == WLAN_FC_STYPE_ACTION && | |
2118 | os_memcmp(wpa_s->parent->pending_action_dst, | |
2119 | data->tx_status.dst, ETH_ALEN) == 0) { | |
24f6497c | 2120 | offchannel_send_action_tx_status( |
9bae1be0 JM |
2121 | wpa_s->parent, data->tx_status.dst, |
2122 | data->tx_status.data, | |
2123 | data->tx_status.data_len, | |
1d39378a | 2124 | data->tx_status.ack ? |
24f6497c JM |
2125 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
2126 | OFFCHANNEL_SEND_ACTION_NO_ACK); | |
f8b1f695 | 2127 | break; |
9bae1be0 | 2128 | } |
24f6497c JM |
2129 | #endif /* CONFIG_OFFCHANNEL */ |
2130 | #ifdef CONFIG_AP | |
f8b1f695 JM |
2131 | switch (data->tx_status.type) { |
2132 | case WLAN_FC_TYPE_MGMT: | |
2133 | ap_mgmt_tx_cb(wpa_s, data->tx_status.data, | |
2134 | data->tx_status.data_len, | |
2135 | data->tx_status.stype, | |
2136 | data->tx_status.ack); | |
2137 | break; | |
2138 | case WLAN_FC_TYPE_DATA: | |
2139 | ap_tx_status(wpa_s, data->tx_status.dst, | |
2140 | data->tx_status.data, | |
2141 | data->tx_status.data_len, | |
2142 | data->tx_status.ack); | |
2143 | break; | |
2144 | } | |
24f6497c | 2145 | #endif /* CONFIG_AP */ |
f8b1f695 | 2146 | break; |
24f6497c | 2147 | #ifdef CONFIG_AP |
bcf24348 JB |
2148 | case EVENT_DRIVER_CLIENT_POLL_OK: |
2149 | ap_client_poll_ok(wpa_s, data->client_poll.addr); | |
2150 | break; | |
f8b1f695 JM |
2151 | case EVENT_RX_FROM_UNKNOWN: |
2152 | if (wpa_s->ap_iface == NULL) | |
2153 | break; | |
9b90955e JB |
2154 | ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr, |
2155 | data->rx_from_unknown.wds); | |
f8b1f695 JM |
2156 | break; |
2157 | case EVENT_RX_MGMT: | |
9bae1be0 JM |
2158 | if (wpa_s->ap_iface == NULL) { |
2159 | #ifdef CONFIG_P2P | |
2160 | u16 fc, stype; | |
2161 | const struct ieee80211_mgmt *mgmt; | |
2162 | mgmt = (const struct ieee80211_mgmt *) | |
2163 | data->rx_mgmt.frame; | |
2164 | fc = le_to_host16(mgmt->frame_control); | |
2165 | stype = WLAN_FC_GET_STYPE(fc); | |
2166 | if (stype == WLAN_FC_STYPE_PROBE_REQ && | |
2167 | data->rx_mgmt.frame_len > 24) { | |
2168 | const u8 *src = mgmt->sa; | |
2169 | const u8 *ie = mgmt->u.probe_req.variable; | |
2170 | size_t ie_len = data->rx_mgmt.frame_len - | |
2171 | (mgmt->u.probe_req.variable - | |
2172 | data->rx_mgmt.frame); | |
04a85e44 JM |
2173 | wpas_p2p_probe_req_rx(wpa_s, src, mgmt->da, |
2174 | mgmt->bssid, ie, ie_len); | |
9bae1be0 JM |
2175 | break; |
2176 | } | |
2177 | #endif /* CONFIG_P2P */ | |
f049052b BG |
2178 | wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received " |
2179 | "management frame in non-AP mode"); | |
f8b1f695 | 2180 | break; |
9bae1be0 | 2181 | } |
2a8b7416 | 2182 | ap_mgmt_rx(wpa_s, &data->rx_mgmt); |
f8b1f695 JM |
2183 | break; |
2184 | #endif /* CONFIG_AP */ | |
036f7c4a | 2185 | case EVENT_RX_ACTION: |
f049052b BG |
2186 | wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR |
2187 | " Category=%u DataLen=%d freq=%d MHz", | |
2188 | MAC2STR(data->rx_action.sa), | |
2189 | data->rx_action.category, (int) data->rx_action.len, | |
2190 | data->rx_action.freq); | |
036f7c4a JM |
2191 | #ifdef CONFIG_IEEE80211R |
2192 | if (data->rx_action.category == WLAN_ACTION_FT) { | |
2193 | ft_rx_action(wpa_s, data->rx_action.data, | |
2194 | data->rx_action.len); | |
2195 | break; | |
2196 | } | |
2197 | #endif /* CONFIG_IEEE80211R */ | |
7d878ca7 JM |
2198 | #ifdef CONFIG_IEEE80211W |
2199 | #ifdef CONFIG_SME | |
2200 | if (data->rx_action.category == WLAN_ACTION_SA_QUERY) { | |
2201 | sme_sa_query_rx(wpa_s, data->rx_action.sa, | |
2202 | data->rx_action.data, | |
2203 | data->rx_action.len); | |
2204 | break; | |
2205 | } | |
2206 | #endif /* CONFIG_SME */ | |
2207 | #endif /* CONFIG_IEEE80211W */ | |
04ea7b79 JM |
2208 | #ifdef CONFIG_GAS |
2209 | if (data->rx_action.category == WLAN_ACTION_PUBLIC && | |
2210 | gas_query_rx(wpa_s->gas, data->rx_action.da, | |
2211 | data->rx_action.sa, data->rx_action.bssid, | |
2212 | data->rx_action.data, data->rx_action.len, | |
2213 | data->rx_action.freq) == 0) | |
2214 | break; | |
2215 | #endif /* CONFIG_GAS */ | |
71269b37 JM |
2216 | if (data->rx_action.category == WLAN_ACTION_WNM) { |
2217 | wnm_action_rx(wpa_s, &data->rx_action); | |
2218 | break; | |
2219 | } | |
35287637 AN |
2220 | #ifdef CONFIG_TDLS |
2221 | if (data->rx_action.category == WLAN_ACTION_PUBLIC && | |
2222 | data->rx_action.len >= 4 && | |
2223 | data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) { | |
2224 | wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery " | |
2225 | "Response from " MACSTR, | |
2226 | MAC2STR(data->rx_action.sa)); | |
2227 | break; | |
2228 | } | |
2229 | #endif /* CONFIG_TDLS */ | |
9bae1be0 JM |
2230 | #ifdef CONFIG_P2P |
2231 | wpas_p2p_rx_action(wpa_s, data->rx_action.da, | |
2232 | data->rx_action.sa, | |
2233 | data->rx_action.bssid, | |
2234 | data->rx_action.category, | |
2235 | data->rx_action.data, | |
2236 | data->rx_action.len, data->rx_action.freq); | |
e67b55fb JM |
2237 | #endif /* CONFIG_P2P */ |
2238 | break; | |
2239 | case EVENT_RX_PROBE_REQ: | |
b211f3eb JM |
2240 | if (data->rx_probe_req.sa == NULL || |
2241 | data->rx_probe_req.ie == NULL) | |
2242 | break; | |
e67b55fb JM |
2243 | #ifdef CONFIG_AP |
2244 | if (wpa_s->ap_iface) { | |
2245 | hostapd_probe_req_rx(wpa_s->ap_iface->bss[0], | |
2246 | data->rx_probe_req.sa, | |
04a85e44 JM |
2247 | data->rx_probe_req.da, |
2248 | data->rx_probe_req.bssid, | |
e67b55fb JM |
2249 | data->rx_probe_req.ie, |
2250 | data->rx_probe_req.ie_len); | |
2251 | break; | |
2252 | } | |
2253 | #endif /* CONFIG_AP */ | |
2254 | #ifdef CONFIG_P2P | |
2255 | wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa, | |
04a85e44 JM |
2256 | data->rx_probe_req.da, |
2257 | data->rx_probe_req.bssid, | |
e67b55fb JM |
2258 | data->rx_probe_req.ie, |
2259 | data->rx_probe_req.ie_len); | |
9bae1be0 | 2260 | #endif /* CONFIG_P2P */ |
036f7c4a | 2261 | break; |
9bae1be0 | 2262 | case EVENT_REMAIN_ON_CHANNEL: |
24f6497c JM |
2263 | #ifdef CONFIG_OFFCHANNEL |
2264 | offchannel_remain_on_channel_cb( | |
2265 | wpa_s, data->remain_on_channel.freq, | |
2266 | data->remain_on_channel.duration); | |
2267 | #endif /* CONFIG_OFFCHANNEL */ | |
2268 | #ifdef CONFIG_P2P | |
9bae1be0 JM |
2269 | wpas_p2p_remain_on_channel_cb( |
2270 | wpa_s, data->remain_on_channel.freq, | |
2271 | data->remain_on_channel.duration); | |
24f6497c | 2272 | #endif /* CONFIG_P2P */ |
9bae1be0 JM |
2273 | break; |
2274 | case EVENT_CANCEL_REMAIN_ON_CHANNEL: | |
24f6497c JM |
2275 | #ifdef CONFIG_OFFCHANNEL |
2276 | offchannel_cancel_remain_on_channel_cb( | |
2277 | wpa_s, data->remain_on_channel.freq); | |
2278 | #endif /* CONFIG_OFFCHANNEL */ | |
2279 | #ifdef CONFIG_P2P | |
9bae1be0 JM |
2280 | wpas_p2p_cancel_remain_on_channel_cb( |
2281 | wpa_s, data->remain_on_channel.freq); | |
24f6497c | 2282 | #endif /* CONFIG_P2P */ |
9bae1be0 | 2283 | break; |
24f6497c | 2284 | #ifdef CONFIG_P2P |
c5db8e51 KRK |
2285 | case EVENT_P2P_DEV_FOUND: { |
2286 | struct p2p_peer_info peer_info; | |
2287 | ||
2288 | os_memset(&peer_info, 0, sizeof(peer_info)); | |
2289 | if (data->p2p_dev_found.dev_addr) | |
2290 | os_memcpy(peer_info.p2p_device_addr, | |
2291 | data->p2p_dev_found.dev_addr, ETH_ALEN); | |
2292 | if (data->p2p_dev_found.pri_dev_type) | |
2293 | os_memcpy(peer_info.pri_dev_type, | |
2294 | data->p2p_dev_found.pri_dev_type, | |
2295 | sizeof(peer_info.pri_dev_type)); | |
2296 | if (data->p2p_dev_found.dev_name) | |
2297 | os_strlcpy(peer_info.device_name, | |
2298 | data->p2p_dev_found.dev_name, | |
2299 | sizeof(peer_info.device_name)); | |
2300 | peer_info.config_methods = data->p2p_dev_found.config_methods; | |
2301 | peer_info.dev_capab = data->p2p_dev_found.dev_capab; | |
2302 | peer_info.group_capab = data->p2p_dev_found.group_capab; | |
2303 | ||
8fd7dc1b JB |
2304 | /* |
2305 | * FIX: new_device=1 is not necessarily correct. We should | |
2306 | * maintain a P2P peer database in wpa_supplicant and update | |
2307 | * this information based on whether the peer is truly new. | |
2308 | */ | |
2309 | wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1); | |
3ac17eba | 2310 | break; |
c5db8e51 | 2311 | } |
3ac17eba JM |
2312 | case EVENT_P2P_GO_NEG_REQ_RX: |
2313 | wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src, | |
2314 | data->p2p_go_neg_req_rx.dev_passwd_id); | |
2315 | break; | |
2316 | case EVENT_P2P_GO_NEG_COMPLETED: | |
2317 | wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res); | |
2318 | break; | |
2319 | case EVENT_P2P_PROV_DISC_REQUEST: | |
2320 | wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer, | |
2321 | data->p2p_prov_disc_req.config_methods, | |
2322 | data->p2p_prov_disc_req.dev_addr, | |
2323 | data->p2p_prov_disc_req.pri_dev_type, | |
2324 | data->p2p_prov_disc_req.dev_name, | |
2325 | data->p2p_prov_disc_req.supp_config_methods, | |
2326 | data->p2p_prov_disc_req.dev_capab, | |
2327 | data->p2p_prov_disc_req.group_capab); | |
2328 | break; | |
2329 | case EVENT_P2P_PROV_DISC_RESPONSE: | |
2330 | wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer, | |
2331 | data->p2p_prov_disc_resp.config_methods); | |
2332 | break; | |
2333 | case EVENT_P2P_SD_REQUEST: | |
2334 | wpas_sd_request(wpa_s, data->p2p_sd_req.freq, | |
2335 | data->p2p_sd_req.sa, | |
2336 | data->p2p_sd_req.dialog_token, | |
2337 | data->p2p_sd_req.update_indic, | |
2338 | data->p2p_sd_req.tlvs, | |
2339 | data->p2p_sd_req.tlvs_len); | |
2340 | break; | |
2341 | case EVENT_P2P_SD_RESPONSE: | |
2342 | wpas_sd_response(wpa_s, data->p2p_sd_resp.sa, | |
2343 | data->p2p_sd_resp.update_indic, | |
2344 | data->p2p_sd_resp.tlvs, | |
2345 | data->p2p_sd_resp.tlvs_len); | |
2346 | break; | |
9bae1be0 | 2347 | #endif /* CONFIG_P2P */ |
a8e0505b JM |
2348 | case EVENT_EAPOL_RX: |
2349 | wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src, | |
2350 | data->eapol_rx.data, | |
2351 | data->eapol_rx.data_len); | |
2352 | break; | |
e2f74005 JM |
2353 | case EVENT_SIGNAL_CHANGE: |
2354 | bgscan_notify_signal_change( | |
60a972a6 | 2355 | wpa_s, data->signal_change.above_threshold, |
174fa789 PS |
2356 | data->signal_change.current_signal, |
2357 | data->signal_change.current_noise, | |
2358 | data->signal_change.current_txrate); | |
e2f74005 | 2359 | break; |
8401a6b0 | 2360 | case EVENT_INTERFACE_ENABLED: |
f049052b | 2361 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled"); |
8401a6b0 | 2362 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
199716ad | 2363 | #ifdef CONFIG_AP |
9919f7a2 JB |
2364 | if (!wpa_s->ap_iface) { |
2365 | wpa_supplicant_set_state(wpa_s, | |
2366 | WPA_DISCONNECTED); | |
2367 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
2368 | } else | |
2369 | wpa_supplicant_set_state(wpa_s, | |
2370 | WPA_COMPLETED); | |
199716ad BG |
2371 | #else /* CONFIG_AP */ |
2372 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
2373 | wpa_supplicant_req_scan(wpa_s, 0, 0); | |
2374 | #endif /* CONFIG_AP */ | |
8401a6b0 JM |
2375 | } |
2376 | break; | |
2377 | case EVENT_INTERFACE_DISABLED: | |
f049052b | 2378 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled"); |
8401a6b0 JM |
2379 | wpa_supplicant_mark_disassoc(wpa_s); |
2380 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); | |
2381 | break; | |
b5c9da8d | 2382 | case EVENT_CHANNEL_LIST_CHANGED: |
35c5d610 JM |
2383 | if (wpa_s->drv_priv == NULL) |
2384 | break; /* Ignore event during drv initialization */ | |
b5c9da8d JM |
2385 | #ifdef CONFIG_P2P |
2386 | wpas_p2p_update_channel_list(wpa_s); | |
c973f386 JM |
2387 | #endif /* CONFIG_P2P */ |
2388 | break; | |
2389 | case EVENT_INTERFACE_UNAVAILABLE: | |
2390 | #ifdef CONFIG_P2P | |
2391 | wpas_p2p_interface_unavailable(wpa_s); | |
7cfc4ac3 AGS |
2392 | #endif /* CONFIG_P2P */ |
2393 | break; | |
2394 | case EVENT_BEST_CHANNEL: | |
f049052b BG |
2395 | wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received " |
2396 | "(%d %d %d)", | |
2397 | data->best_chan.freq_24, data->best_chan.freq_5, | |
2398 | data->best_chan.freq_overall); | |
7cfc4ac3 AGS |
2399 | wpa_s->best_24_freq = data->best_chan.freq_24; |
2400 | wpa_s->best_5_freq = data->best_chan.freq_5; | |
2401 | wpa_s->best_overall_freq = data->best_chan.freq_overall; | |
2402 | #ifdef CONFIG_P2P | |
2403 | wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24, | |
2404 | data->best_chan.freq_5, | |
2405 | data->best_chan.freq_overall); | |
b5c9da8d JM |
2406 | #endif /* CONFIG_P2P */ |
2407 | break; | |
7d878ca7 JM |
2408 | case EVENT_UNPROT_DEAUTH: |
2409 | wpa_supplicant_event_unprot_deauth(wpa_s, | |
2410 | &data->unprot_deauth); | |
2411 | break; | |
2412 | case EVENT_UNPROT_DISASSOC: | |
2413 | wpa_supplicant_event_unprot_disassoc(wpa_s, | |
2414 | &data->unprot_disassoc); | |
2415 | break; | |
0d7e5a3a JB |
2416 | case EVENT_STATION_LOW_ACK: |
2417 | #ifdef CONFIG_AP | |
2418 | if (wpa_s->ap_iface && data) | |
2419 | hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0], | |
2420 | data->low_ack.addr); | |
2421 | #endif /* CONFIG_AP */ | |
8f15f711 AN |
2422 | #ifdef CONFIG_TDLS |
2423 | if (data) | |
2424 | wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr); | |
2425 | #endif /* CONFIG_TDLS */ | |
0d7e5a3a | 2426 | break; |
ea244d21 XC |
2427 | case EVENT_IBSS_PEER_LOST: |
2428 | #ifdef CONFIG_IBSS_RSN | |
2429 | ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer); | |
2430 | #endif /* CONFIG_IBSS_RSN */ | |
2431 | break; | |
b14a210c JB |
2432 | case EVENT_DRIVER_GTK_REKEY: |
2433 | if (os_memcmp(data->driver_gtk_rekey.bssid, | |
2434 | wpa_s->bssid, ETH_ALEN)) | |
2435 | break; | |
2436 | if (!wpa_s->wpa) | |
2437 | break; | |
2438 | wpa_sm_update_replay_ctr(wpa_s->wpa, | |
2439 | data->driver_gtk_rekey.replay_ctr); | |
2440 | break; | |
cbdf3507 LC |
2441 | case EVENT_SCHED_SCAN_STOPPED: |
2442 | wpa_s->sched_scanning = 0; | |
2443 | wpa_supplicant_notify_scanning(wpa_s, 0); | |
2444 | ||
2445 | /* | |
2446 | * If we timed out, start a new sched scan to continue | |
2447 | * searching for more SSIDs. | |
2448 | */ | |
2449 | if (wpa_s->sched_scan_timed_out) | |
2450 | wpa_supplicant_req_sched_scan(wpa_s); | |
2451 | break; | |
783fcb7d GG |
2452 | case EVENT_WPS_BUTTON_PUSHED: |
2453 | #ifdef CONFIG_WPS | |
2454 | wpas_wps_start_pbc(wpa_s, NULL, 0); | |
2455 | #endif /* CONFIG_WPS */ | |
2456 | break; | |
6fc6879b | 2457 | default: |
f049052b | 2458 | wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event); |
6fc6879b JM |
2459 | break; |
2460 | } | |
2461 | } |