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