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