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