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