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