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