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