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