]>
Commit | Line | Data |
---|---|---|
c2a04078 JM |
1 | /* |
2 | * wpa_supplicant - SME | |
6ac4b15e | 3 | * Copyright (c) 2009-2014, Jouni Malinen <j@w1.fi> |
c2a04078 | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
c2a04078 JM |
7 | */ |
8 | ||
9 | #include "includes.h" | |
10 | ||
11 | #include "common.h" | |
7d878ca7 | 12 | #include "utils/eloop.h" |
90973fb2 | 13 | #include "common/ieee802_11_defs.h" |
d9a27b04 | 14 | #include "common/ieee802_11_common.h" |
c2a04078 | 15 | #include "eapol_supp/eapol_supp_sm.h" |
90973fb2 | 16 | #include "common/wpa_common.h" |
98efcc41 | 17 | #include "common/sae.h" |
3acb5005 JM |
18 | #include "rsn_supp/wpa.h" |
19 | #include "rsn_supp/pmksa_cache.h" | |
c2a04078 JM |
20 | #include "config.h" |
21 | #include "wpa_supplicant_i.h" | |
2d5b792d | 22 | #include "driver_i.h" |
c2a04078 JM |
23 | #include "wpas_glue.h" |
24 | #include "wps_supplicant.h" | |
5f3a6aa0 | 25 | #include "p2p_supplicant.h" |
8bac466b | 26 | #include "notify.h" |
6fa81a3b | 27 | #include "bss.h" |
9ba9fa07 | 28 | #include "scan.h" |
c2a04078 | 29 | #include "sme.h" |
cb418324 | 30 | #include "hs20_supplicant.h" |
c2a04078 | 31 | |
e29853bb BG |
32 | #define SME_AUTH_TIMEOUT 5 |
33 | #define SME_ASSOC_TIMEOUT 5 | |
34 | ||
35 | static void sme_auth_timer(void *eloop_ctx, void *timeout_ctx); | |
36 | static void sme_assoc_timer(void *eloop_ctx, void *timeout_ctx); | |
c3701c66 | 37 | static void sme_obss_scan_timeout(void *eloop_ctx, void *timeout_ctx); |
e29853bb BG |
38 | #ifdef CONFIG_IEEE80211W |
39 | static void sme_stop_sa_query(struct wpa_supplicant *wpa_s); | |
40 | #endif /* CONFIG_IEEE80211W */ | |
41 | ||
42 | ||
c10347f2 JM |
43 | #ifdef CONFIG_SAE |
44 | ||
625f202a JM |
45 | static int index_within_array(const int *array, int idx) |
46 | { | |
47 | int i; | |
48 | for (i = 0; i < idx; i++) { | |
18ca7332 | 49 | if (array[i] <= 0) |
625f202a JM |
50 | return 0; |
51 | } | |
52 | return 1; | |
53 | } | |
54 | ||
55 | ||
56 | static int sme_set_sae_group(struct wpa_supplicant *wpa_s) | |
57 | { | |
58 | int *groups = wpa_s->conf->sae_groups; | |
18ca7332 | 59 | int default_groups[] = { 19, 20, 21, 25, 26, 0 }; |
625f202a | 60 | |
18ca7332 | 61 | if (!groups || groups[0] <= 0) |
625f202a JM |
62 | groups = default_groups; |
63 | ||
64 | /* Configuration may have changed, so validate current index */ | |
65 | if (!index_within_array(groups, wpa_s->sme.sae_group_index)) | |
66 | return -1; | |
67 | ||
68 | for (;;) { | |
69 | int group = groups[wpa_s->sme.sae_group_index]; | |
04e6c4cc | 70 | if (group <= 0) |
625f202a JM |
71 | break; |
72 | if (sae_set_group(&wpa_s->sme.sae, group) == 0) { | |
73 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Selected SAE group %d", | |
74 | wpa_s->sme.sae.group); | |
75 | return 0; | |
76 | } | |
77 | wpa_s->sme.sae_group_index++; | |
78 | } | |
79 | ||
80 | return -1; | |
81 | } | |
82 | ||
83 | ||
8e31e955 JM |
84 | static struct wpabuf * sme_auth_build_sae_commit(struct wpa_supplicant *wpa_s, |
85 | struct wpa_ssid *ssid, | |
5ff39c13 | 86 | const u8 *bssid, int external) |
c10347f2 JM |
87 | { |
88 | struct wpabuf *buf; | |
d136c376 | 89 | size_t len; |
a34ca59e | 90 | const char *password; |
c10347f2 | 91 | |
a0f19e9c JM |
92 | #ifdef CONFIG_TESTING_OPTIONS |
93 | if (wpa_s->sae_commit_override) { | |
94 | wpa_printf(MSG_DEBUG, "SAE: TESTING - commit override"); | |
95 | buf = wpabuf_alloc(4 + wpabuf_len(wpa_s->sae_commit_override)); | |
96 | if (!buf) | |
97 | return NULL; | |
98 | wpabuf_put_le16(buf, 1); /* Transaction seq# */ | |
99 | wpabuf_put_le16(buf, WLAN_STATUS_SUCCESS); | |
100 | wpabuf_put_buf(buf, wpa_s->sae_commit_override); | |
101 | return buf; | |
102 | } | |
103 | #endif /* CONFIG_TESTING_OPTIONS */ | |
104 | ||
a34ca59e JM |
105 | password = ssid->sae_password; |
106 | if (!password) | |
107 | password = ssid->passphrase; | |
108 | if (!password) { | |
8e31e955 JM |
109 | wpa_printf(MSG_DEBUG, "SAE: No password available"); |
110 | return NULL; | |
111 | } | |
112 | ||
625f202a JM |
113 | if (sme_set_sae_group(wpa_s) < 0) { |
114 | wpa_printf(MSG_DEBUG, "SAE: Failed to select group"); | |
a46d72d7 | 115 | return NULL; |
625f202a | 116 | } |
a46d72d7 | 117 | |
8e31e955 | 118 | if (sae_prepare_commit(wpa_s->own_addr, bssid, |
a34ca59e | 119 | (u8 *) password, os_strlen(password), |
9be19d0b | 120 | ssid->sae_password_id, |
8e31e955 JM |
121 | &wpa_s->sme.sae) < 0) { |
122 | wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE"); | |
123 | return NULL; | |
124 | } | |
125 | ||
d136c376 | 126 | len = wpa_s->sme.sae_token ? wpabuf_len(wpa_s->sme.sae_token) : 0; |
9be19d0b JM |
127 | if (ssid->sae_password_id) |
128 | len += 4 + os_strlen(ssid->sae_password_id); | |
d136c376 | 129 | buf = wpabuf_alloc(4 + SAE_COMMIT_MAX_LEN + len); |
c10347f2 JM |
130 | if (buf == NULL) |
131 | return NULL; | |
5ff39c13 SD |
132 | if (!external) { |
133 | wpabuf_put_le16(buf, 1); /* Transaction seq# */ | |
134 | wpabuf_put_le16(buf, WLAN_STATUS_SUCCESS); | |
135 | } | |
9be19d0b JM |
136 | sae_write_commit(&wpa_s->sme.sae, buf, wpa_s->sme.sae_token, |
137 | ssid->sae_password_id); | |
c10347f2 JM |
138 | |
139 | return buf; | |
140 | } | |
141 | ||
142 | ||
5ff39c13 SD |
143 | static struct wpabuf * sme_auth_build_sae_confirm(struct wpa_supplicant *wpa_s, |
144 | int external) | |
c10347f2 JM |
145 | { |
146 | struct wpabuf *buf; | |
147 | ||
fb8fcc29 | 148 | buf = wpabuf_alloc(4 + SAE_CONFIRM_MAX_LEN); |
c10347f2 JM |
149 | if (buf == NULL) |
150 | return NULL; | |
151 | ||
5ff39c13 SD |
152 | if (!external) { |
153 | wpabuf_put_le16(buf, 2); /* Transaction seq# */ | |
154 | wpabuf_put_le16(buf, WLAN_STATUS_SUCCESS); | |
155 | } | |
fb8fcc29 | 156 | sae_write_confirm(&wpa_s->sme.sae, buf); |
c10347f2 JM |
157 | |
158 | return buf; | |
159 | } | |
160 | ||
161 | #endif /* CONFIG_SAE */ | |
162 | ||
163 | ||
b361d580 AK |
164 | /** |
165 | * sme_auth_handle_rrm - Handle RRM aspects of current authentication attempt | |
166 | * @wpa_s: Pointer to wpa_supplicant data | |
167 | * @bss: Pointer to the bss which is the target of authentication attempt | |
168 | */ | |
169 | static void sme_auth_handle_rrm(struct wpa_supplicant *wpa_s, | |
170 | struct wpa_bss *bss) | |
171 | { | |
172 | const u8 rrm_ie_len = 5; | |
173 | u8 *pos; | |
174 | const u8 *rrm_ie; | |
175 | ||
176 | wpa_s->rrm.rrm_used = 0; | |
177 | ||
178 | wpa_printf(MSG_DEBUG, | |
179 | "RRM: Determining whether RRM can be used - device support: 0x%x", | |
180 | wpa_s->drv_rrm_flags); | |
181 | ||
182 | rrm_ie = wpa_bss_get_ie(bss, WLAN_EID_RRM_ENABLED_CAPABILITIES); | |
183 | if (!rrm_ie || !(bss->caps & IEEE80211_CAP_RRM)) { | |
184 | wpa_printf(MSG_DEBUG, "RRM: No RRM in network"); | |
185 | return; | |
186 | } | |
187 | ||
00ed0aa2 BL |
188 | if (!((wpa_s->drv_rrm_flags & |
189 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && | |
190 | (wpa_s->drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && | |
191 | !(wpa_s->drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) { | |
b361d580 AK |
192 | wpa_printf(MSG_DEBUG, |
193 | "RRM: Insufficient RRM support in driver - do not use RRM"); | |
194 | return; | |
195 | } | |
196 | ||
849367af JM |
197 | if (sizeof(wpa_s->sme.assoc_req_ie) < |
198 | wpa_s->sme.assoc_req_ie_len + rrm_ie_len + 2) { | |
b361d580 AK |
199 | wpa_printf(MSG_INFO, |
200 | "RRM: Unable to use RRM, no room for RRM IE"); | |
201 | return; | |
202 | } | |
203 | ||
204 | wpa_printf(MSG_DEBUG, "RRM: Adding RRM IE to Association Request"); | |
205 | pos = wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len; | |
b361d580 AK |
206 | os_memset(pos, 0, 2 + rrm_ie_len); |
207 | *pos++ = WLAN_EID_RRM_ENABLED_CAPABILITIES; | |
208 | *pos++ = rrm_ie_len; | |
70d1e728 AO |
209 | |
210 | /* Set supported capabilites flags */ | |
211 | if (wpa_s->drv_rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) | |
212 | *pos |= WLAN_RRM_CAPS_LINK_MEASUREMENT; | |
213 | ||
d7342014 JM |
214 | *pos |= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE | |
215 | WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE | | |
216 | WLAN_RRM_CAPS_BEACON_REPORT_TABLE; | |
76196ddb | 217 | |
4a742011 DS |
218 | if (wpa_s->lci) |
219 | pos[1] |= WLAN_RRM_CAPS_LCI_MEASUREMENT; | |
220 | ||
b361d580 AK |
221 | wpa_s->sme.assoc_req_ie_len += rrm_ie_len + 2; |
222 | wpa_s->rrm.rrm_used = 1; | |
223 | } | |
224 | ||
225 | ||
215ae884 JM |
226 | static void sme_send_authentication(struct wpa_supplicant *wpa_s, |
227 | struct wpa_bss *bss, struct wpa_ssid *ssid, | |
228 | int start) | |
c2a04078 JM |
229 | { |
230 | struct wpa_driver_auth_params params; | |
8bac466b | 231 | struct wpa_ssid *old_ssid; |
fdbe50ed | 232 | #ifdef CONFIG_IEEE80211R |
c2a04078 | 233 | const u8 *ie; |
fdbe50ed | 234 | #endif /* CONFIG_IEEE80211R */ |
af3e362f | 235 | #if defined(CONFIG_IEEE80211R) || defined(CONFIG_FILS) |
c2a04078 | 236 | const u8 *md = NULL; |
af3e362f | 237 | #endif /* CONFIG_IEEE80211R || CONFIG_FILS */ |
8bac466b | 238 | int i, bssid_changed; |
c10347f2 | 239 | struct wpabuf *resp = NULL; |
0bbaa9b9 | 240 | u8 ext_capab[18]; |
03e47c9c | 241 | int ext_capab_len; |
59b416c7 | 242 | int skip_auth; |
170244a1 IP |
243 | u8 *wpa_ie; |
244 | size_t wpa_ie_len; | |
077232f6 BL |
245 | #ifdef CONFIG_MBO |
246 | const u8 *mbo_ie; | |
247 | #endif /* CONFIG_MBO */ | |
c2a04078 JM |
248 | |
249 | if (bss == NULL) { | |
f049052b BG |
250 | wpa_msg(wpa_s, MSG_ERROR, "SME: No scan result available for " |
251 | "the network"); | |
6ac4b15e | 252 | wpas_connect_work_done(wpa_s); |
c2a04078 JM |
253 | return; |
254 | } | |
255 | ||
59b416c7 JM |
256 | skip_auth = wpa_s->conf->reassoc_same_bss_optim && |
257 | wpa_s->reassoc_same_bss; | |
8f770587 JM |
258 | wpa_s->current_bss = bss; |
259 | ||
c2a04078 JM |
260 | os_memset(¶ms, 0, sizeof(params)); |
261 | wpa_s->reassociate = 0; | |
262 | ||
263 | params.freq = bss->freq; | |
264 | params.bssid = bss->bssid; | |
6fa81a3b JM |
265 | params.ssid = bss->ssid; |
266 | params.ssid_len = bss->ssid_len; | |
2f4f73b1 | 267 | params.p2p = ssid->p2p_group; |
c2a04078 | 268 | |
62fa124c JM |
269 | if (wpa_s->sme.ssid_len != params.ssid_len || |
270 | os_memcmp(wpa_s->sme.ssid, params.ssid, params.ssid_len) != 0) | |
271 | wpa_s->sme.prev_bssid_set = 0; | |
272 | ||
c2a04078 JM |
273 | wpa_s->sme.freq = params.freq; |
274 | os_memcpy(wpa_s->sme.ssid, params.ssid, params.ssid_len); | |
275 | wpa_s->sme.ssid_len = params.ssid_len; | |
276 | ||
abd9fafa | 277 | params.auth_alg = WPA_AUTH_ALG_OPEN; |
c2a04078 JM |
278 | #ifdef IEEE8021X_EAPOL |
279 | if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
280 | if (ssid->leap) { | |
281 | if (ssid->non_leap == 0) | |
abd9fafa | 282 | params.auth_alg = WPA_AUTH_ALG_LEAP; |
c2a04078 | 283 | else |
abd9fafa | 284 | params.auth_alg |= WPA_AUTH_ALG_LEAP; |
c2a04078 JM |
285 | } |
286 | } | |
287 | #endif /* IEEE8021X_EAPOL */ | |
f049052b BG |
288 | wpa_dbg(wpa_s, MSG_DEBUG, "Automatic auth_alg selection: 0x%x", |
289 | params.auth_alg); | |
c2a04078 | 290 | if (ssid->auth_alg) { |
abd9fafa | 291 | params.auth_alg = ssid->auth_alg; |
f049052b BG |
292 | wpa_dbg(wpa_s, MSG_DEBUG, "Overriding auth_alg selection: " |
293 | "0x%x", params.auth_alg); | |
c2a04078 | 294 | } |
c10347f2 | 295 | #ifdef CONFIG_SAE |
bc26ac50 | 296 | wpa_s->sme.sae_pmksa_caching = 0; |
c10347f2 JM |
297 | if (wpa_key_mgmt_sae(ssid->key_mgmt)) { |
298 | const u8 *rsn; | |
299 | struct wpa_ie_data ied; | |
300 | ||
301 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); | |
267ac3bc JM |
302 | if (!rsn) { |
303 | wpa_dbg(wpa_s, MSG_DEBUG, | |
304 | "SAE enabled, but target BSS does not advertise RSN"); | |
305 | } else if (wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ied) == 0 && | |
306 | wpa_key_mgmt_sae(ied.key_mgmt)) { | |
307 | wpa_dbg(wpa_s, MSG_DEBUG, "Using SAE auth_alg"); | |
308 | params.auth_alg = WPA_AUTH_ALG_SAE; | |
309 | } else { | |
310 | wpa_dbg(wpa_s, MSG_DEBUG, | |
311 | "SAE enabled, but target BSS does not advertise SAE AKM for RSN"); | |
c10347f2 JM |
312 | } |
313 | } | |
314 | #endif /* CONFIG_SAE */ | |
c2a04078 | 315 | |
a0b2f99b JM |
316 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
317 | if (ssid->wep_key_len[i]) | |
318 | params.wep_key[i] = ssid->wep_key[i]; | |
319 | params.wep_key_len[i] = ssid->wep_key_len[i]; | |
320 | } | |
321 | params.wep_tx_keyidx = ssid->wep_tx_keyidx; | |
322 | ||
8bac466b | 323 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
c2a04078 JM |
324 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
325 | os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN); | |
8bac466b JM |
326 | if (bssid_changed) |
327 | wpas_notify_bssid_changed(wpa_s); | |
c2a04078 | 328 | |
f337f0e9 JM |
329 | if ((wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) || |
330 | wpa_bss_get_ie(bss, WLAN_EID_RSN)) && | |
0bf927a0 | 331 | wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
c2a04078 | 332 | int try_opportunistic; |
869af307 JM |
333 | const u8 *cache_id = NULL; |
334 | ||
6e202021 JM |
335 | try_opportunistic = (ssid->proactive_key_caching < 0 ? |
336 | wpa_s->conf->okc : | |
337 | ssid->proactive_key_caching) && | |
c2a04078 | 338 | (ssid->proto & WPA_PROTO_RSN); |
869af307 JM |
339 | #ifdef CONFIG_FILS |
340 | if (wpa_key_mgmt_fils(ssid->key_mgmt)) | |
341 | cache_id = wpa_bss_get_fils_cache_id(bss); | |
342 | #endif /* CONFIG_FILS */ | |
c2a04078 JM |
343 | if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid, |
344 | wpa_s->current_ssid, | |
852b2f27 JM |
345 | try_opportunistic, cache_id, |
346 | 0) == 0) | |
ba422613 | 347 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol); |
c2a04078 JM |
348 | wpa_s->sme.assoc_req_ie_len = sizeof(wpa_s->sme.assoc_req_ie); |
349 | if (wpa_supplicant_set_suites(wpa_s, bss, ssid, | |
350 | wpa_s->sme.assoc_req_ie, | |
351 | &wpa_s->sme.assoc_req_ie_len)) { | |
f049052b BG |
352 | wpa_msg(wpa_s, MSG_WARNING, "SME: Failed to set WPA " |
353 | "key management and encryption suites"); | |
6ac4b15e | 354 | wpas_connect_work_done(wpa_s); |
c2a04078 JM |
355 | return; |
356 | } | |
a3f7e518 JM |
357 | } else if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && |
358 | wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt)) { | |
359 | /* | |
360 | * Both WPA and non-WPA IEEE 802.1X enabled in configuration - | |
361 | * use non-WPA since the scan results did not indicate that the | |
362 | * AP is using WPA or WPA2. | |
363 | */ | |
364 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
365 | wpa_s->sme.assoc_req_ie_len = 0; | |
0bf927a0 | 366 | } else if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { |
c2a04078 JM |
367 | wpa_s->sme.assoc_req_ie_len = sizeof(wpa_s->sme.assoc_req_ie); |
368 | if (wpa_supplicant_set_suites(wpa_s, NULL, ssid, | |
369 | wpa_s->sme.assoc_req_ie, | |
370 | &wpa_s->sme.assoc_req_ie_len)) { | |
f049052b BG |
371 | wpa_msg(wpa_s, MSG_WARNING, "SME: Failed to set WPA " |
372 | "key management and encryption suites (no " | |
373 | "scan results)"); | |
6ac4b15e | 374 | wpas_connect_work_done(wpa_s); |
c2a04078 JM |
375 | return; |
376 | } | |
377 | #ifdef CONFIG_WPS | |
378 | } else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) { | |
379 | struct wpabuf *wps_ie; | |
380 | wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid)); | |
381 | if (wps_ie && wpabuf_len(wps_ie) <= | |
382 | sizeof(wpa_s->sme.assoc_req_ie)) { | |
383 | wpa_s->sme.assoc_req_ie_len = wpabuf_len(wps_ie); | |
384 | os_memcpy(wpa_s->sme.assoc_req_ie, wpabuf_head(wps_ie), | |
385 | wpa_s->sme.assoc_req_ie_len); | |
386 | } else | |
387 | wpa_s->sme.assoc_req_ie_len = 0; | |
388 | wpabuf_free(wps_ie); | |
389 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
390 | #endif /* CONFIG_WPS */ | |
391 | } else { | |
392 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
393 | wpa_s->sme.assoc_req_ie_len = 0; | |
394 | } | |
395 | ||
170244a1 IP |
396 | /* In case the WPA vendor IE is used, it should be placed after all the |
397 | * non-vendor IEs, as the lower layer expects the IEs to be ordered as | |
398 | * defined in the standard. Store the WPA IE so it can later be | |
399 | * inserted at the correct location. | |
400 | */ | |
401 | wpa_ie = NULL; | |
402 | wpa_ie_len = 0; | |
403 | if (wpa_s->wpa_proto == WPA_PROTO_WPA) { | |
404 | wpa_ie = os_memdup(wpa_s->sme.assoc_req_ie, | |
405 | wpa_s->sme.assoc_req_ie_len); | |
406 | if (wpa_ie) { | |
407 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Storing WPA IE"); | |
408 | ||
409 | wpa_ie_len = wpa_s->sme.assoc_req_ie_len; | |
410 | wpa_s->sme.assoc_req_ie_len = 0; | |
411 | } else { | |
412 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed copy WPA IE"); | |
413 | wpas_connect_work_done(wpa_s); | |
414 | return; | |
415 | } | |
416 | } | |
417 | ||
c2a04078 | 418 | #ifdef CONFIG_IEEE80211R |
6fa81a3b | 419 | ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); |
c2a04078 JM |
420 | if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN) |
421 | md = ie + 2; | |
e7846b68 | 422 | wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0); |
c2a04078 JM |
423 | if (md) { |
424 | /* Prepare for the next transition */ | |
76b7981d | 425 | wpa_ft_prepare_auth_request(wpa_s->wpa, ie); |
c2a04078 JM |
426 | } |
427 | ||
af3e362f JM |
428 | if (md && !wpa_key_mgmt_ft(ssid->key_mgmt)) |
429 | md = NULL; | |
430 | if (md) { | |
431 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: FT mobility domain %02x%02x", | |
432 | md[0], md[1]); | |
433 | ||
c2a04078 JM |
434 | if (wpa_s->sme.assoc_req_ie_len + 5 < |
435 | sizeof(wpa_s->sme.assoc_req_ie)) { | |
436 | struct rsn_mdie *mdie; | |
437 | u8 *pos = wpa_s->sme.assoc_req_ie + | |
438 | wpa_s->sme.assoc_req_ie_len; | |
439 | *pos++ = WLAN_EID_MOBILITY_DOMAIN; | |
440 | *pos++ = sizeof(*mdie); | |
441 | mdie = (struct rsn_mdie *) pos; | |
442 | os_memcpy(mdie->mobility_domain, md, | |
443 | MOBILITY_DOMAIN_ID_LEN); | |
f4ec630d | 444 | mdie->ft_capab = md[MOBILITY_DOMAIN_ID_LEN]; |
c2a04078 JM |
445 | wpa_s->sme.assoc_req_ie_len += 5; |
446 | } | |
447 | ||
448 | if (wpa_s->sme.ft_used && | |
0d7b4409 JM |
449 | os_memcmp(md, wpa_s->sme.mobility_domain, 2) == 0 && |
450 | wpa_sm_has_ptk(wpa_s->wpa)) { | |
f049052b BG |
451 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Trying to use FT " |
452 | "over-the-air"); | |
abd9fafa | 453 | params.auth_alg = WPA_AUTH_ALG_FT; |
c2a04078 JM |
454 | params.ie = wpa_s->sme.ft_ies; |
455 | params.ie_len = wpa_s->sme.ft_ies_len; | |
456 | } | |
457 | } | |
458 | #endif /* CONFIG_IEEE80211R */ | |
459 | ||
460 | #ifdef CONFIG_IEEE80211W | |
3f56a2b7 | 461 | wpa_s->sme.mfp = wpas_get_ssid_pmf(wpa_s, ssid); |
62d49803 | 462 | if (wpa_s->sme.mfp != NO_MGMT_FRAME_PROTECTION) { |
6fa81a3b | 463 | const u8 *rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
c2a04078 JM |
464 | struct wpa_ie_data _ie; |
465 | if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &_ie) == 0 && | |
466 | _ie.capabilities & | |
467 | (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) { | |
f049052b BG |
468 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Selected AP supports " |
469 | "MFP: require MFP"); | |
c2a04078 JM |
470 | wpa_s->sme.mfp = MGMT_FRAME_PROTECTION_REQUIRED; |
471 | } | |
472 | } | |
473 | #endif /* CONFIG_IEEE80211W */ | |
474 | ||
5f3a6aa0 JM |
475 | #ifdef CONFIG_P2P |
476 | if (wpa_s->global->p2p) { | |
477 | u8 *pos; | |
478 | size_t len; | |
479 | int res; | |
5f3a6aa0 JM |
480 | pos = wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len; |
481 | len = sizeof(wpa_s->sme.assoc_req_ie) - | |
482 | wpa_s->sme.assoc_req_ie_len; | |
ffad8858 JM |
483 | res = wpas_p2p_assoc_req_ie(wpa_s, bss, pos, len, |
484 | ssid->p2p_group); | |
5f3a6aa0 JM |
485 | if (res >= 0) |
486 | wpa_s->sme.assoc_req_ie_len += res; | |
487 | } | |
488 | #endif /* CONFIG_P2P */ | |
489 | ||
b36a3a65 AN |
490 | #ifdef CONFIG_FST |
491 | if (wpa_s->fst_ies) { | |
492 | int fst_ies_len = wpabuf_len(wpa_s->fst_ies); | |
493 | ||
494 | if (wpa_s->sme.assoc_req_ie_len + fst_ies_len <= | |
495 | sizeof(wpa_s->sme.assoc_req_ie)) { | |
496 | os_memcpy(wpa_s->sme.assoc_req_ie + | |
497 | wpa_s->sme.assoc_req_ie_len, | |
498 | wpabuf_head(wpa_s->fst_ies), | |
499 | fst_ies_len); | |
500 | wpa_s->sme.assoc_req_ie_len += fst_ies_len; | |
501 | } | |
502 | } | |
503 | #endif /* CONFIG_FST */ | |
504 | ||
a0c38e5d AS |
505 | sme_auth_handle_rrm(wpa_s, bss); |
506 | ||
065c029a | 507 | wpa_s->sme.assoc_req_ie_len += wpas_supp_op_class_ie( |
508 | wpa_s, bss->freq, | |
509 | wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len, | |
510 | sizeof(wpa_s->sme.assoc_req_ie) - wpa_s->sme.assoc_req_ie_len); | |
5e57ba25 | 511 | |
cc9a2575 KV |
512 | if (params.p2p) |
513 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_CLIENT); | |
514 | else | |
515 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_STATION); | |
516 | ||
0bbaa9b9 JM |
517 | ext_capab_len = wpas_build_ext_capab(wpa_s, ext_capab, |
518 | sizeof(ext_capab)); | |
03e47c9c | 519 | if (ext_capab_len > 0) { |
92cbcf91 JM |
520 | u8 *pos = wpa_s->sme.assoc_req_ie; |
521 | if (wpa_s->sme.assoc_req_ie_len > 0 && pos[0] == WLAN_EID_RSN) | |
522 | pos += 2 + pos[1]; | |
03e47c9c | 523 | os_memmove(pos + ext_capab_len, pos, |
92cbcf91 JM |
524 | wpa_s->sme.assoc_req_ie_len - |
525 | (pos - wpa_s->sme.assoc_req_ie)); | |
03e47c9c JM |
526 | wpa_s->sme.assoc_req_ie_len += ext_capab_len; |
527 | os_memcpy(pos, ext_capab, ext_capab_len); | |
92cbcf91 | 528 | } |
92cbcf91 | 529 | |
c484b198 AS |
530 | #ifdef CONFIG_HS20 |
531 | if (is_hs20_network(wpa_s, ssid, bss)) { | |
532 | struct wpabuf *hs20; | |
533 | ||
4204669c | 534 | hs20 = wpabuf_alloc(20 + MAX_ROAMING_CONS_OI_LEN); |
c484b198 AS |
535 | if (hs20) { |
536 | int pps_mo_id = hs20_get_pps_mo_id(wpa_s, ssid); | |
537 | size_t len; | |
538 | ||
539 | wpas_hs20_add_indication(hs20, pps_mo_id); | |
4204669c | 540 | wpas_hs20_add_roam_cons_sel(hs20, ssid); |
c484b198 AS |
541 | len = sizeof(wpa_s->sme.assoc_req_ie) - |
542 | wpa_s->sme.assoc_req_ie_len; | |
543 | if (wpabuf_len(hs20) <= len) { | |
544 | os_memcpy(wpa_s->sme.assoc_req_ie + | |
545 | wpa_s->sme.assoc_req_ie_len, | |
546 | wpabuf_head(hs20), wpabuf_len(hs20)); | |
547 | wpa_s->sme.assoc_req_ie_len += wpabuf_len(hs20); | |
548 | } | |
549 | wpabuf_free(hs20); | |
550 | } | |
551 | } | |
552 | #endif /* CONFIG_HS20 */ | |
553 | ||
170244a1 IP |
554 | if (wpa_ie) { |
555 | size_t len; | |
556 | ||
557 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Reinsert WPA IE"); | |
558 | ||
559 | len = sizeof(wpa_s->sme.assoc_req_ie) - | |
560 | wpa_s->sme.assoc_req_ie_len; | |
561 | ||
562 | if (len > wpa_ie_len) { | |
563 | os_memcpy(wpa_s->sme.assoc_req_ie + | |
564 | wpa_s->sme.assoc_req_ie_len, | |
565 | wpa_ie, wpa_ie_len); | |
566 | wpa_s->sme.assoc_req_ie_len += wpa_ie_len; | |
567 | } else { | |
568 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Failed to add WPA IE"); | |
569 | } | |
570 | ||
571 | os_free(wpa_ie); | |
572 | } | |
573 | ||
d29fa3a7 JM |
574 | if (wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]) { |
575 | struct wpabuf *buf = wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]; | |
576 | size_t len; | |
577 | ||
578 | len = sizeof(wpa_s->sme.assoc_req_ie) - | |
579 | wpa_s->sme.assoc_req_ie_len; | |
580 | if (wpabuf_len(buf) <= len) { | |
581 | os_memcpy(wpa_s->sme.assoc_req_ie + | |
582 | wpa_s->sme.assoc_req_ie_len, | |
583 | wpabuf_head(buf), wpabuf_len(buf)); | |
584 | wpa_s->sme.assoc_req_ie_len += wpabuf_len(buf); | |
585 | } | |
586 | } | |
587 | ||
92c6e2e3 | 588 | #ifdef CONFIG_MBO |
077232f6 BL |
589 | mbo_ie = wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE); |
590 | if (mbo_ie) { | |
5e57ba25 | 591 | int len; |
92c6e2e3 | 592 | |
5e57ba25 AS |
593 | len = wpas_mbo_ie(wpa_s, wpa_s->sme.assoc_req_ie + |
594 | wpa_s->sme.assoc_req_ie_len, | |
595 | sizeof(wpa_s->sme.assoc_req_ie) - | |
077232f6 BL |
596 | wpa_s->sme.assoc_req_ie_len, |
597 | !!mbo_attr_from_mbo_ie(mbo_ie, | |
598 | OCE_ATTR_ID_CAPA_IND)); | |
5e57ba25 AS |
599 | if (len >= 0) |
600 | wpa_s->sme.assoc_req_ie_len += len; | |
92c6e2e3 DS |
601 | } |
602 | #endif /* CONFIG_MBO */ | |
603 | ||
c10347f2 | 604 | #ifdef CONFIG_SAE |
59b416c7 | 605 | if (!skip_auth && params.auth_alg == WPA_AUTH_ALG_SAE && |
869af307 | 606 | pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid, ssid, 0, |
852b2f27 | 607 | NULL, WPA_KEY_MGMT_SAE) == 0) { |
bc26ac50 JM |
608 | wpa_dbg(wpa_s, MSG_DEBUG, |
609 | "PMKSA cache entry found - try to use PMKSA caching instead of new SAE authentication"); | |
06b1a104 | 610 | wpa_sm_set_pmk_from_pmksa(wpa_s->wpa); |
bc26ac50 JM |
611 | params.auth_alg = WPA_AUTH_ALG_OPEN; |
612 | wpa_s->sme.sae_pmksa_caching = 1; | |
613 | } | |
614 | ||
59b416c7 | 615 | if (!skip_auth && params.auth_alg == WPA_AUTH_ALG_SAE) { |
c10347f2 | 616 | if (start) |
8e31e955 | 617 | resp = sme_auth_build_sae_commit(wpa_s, ssid, |
5ff39c13 | 618 | bss->bssid, 0); |
c10347f2 | 619 | else |
5ff39c13 | 620 | resp = sme_auth_build_sae_confirm(wpa_s, 0); |
6ac4b15e | 621 | if (resp == NULL) { |
81648d00 | 622 | wpas_connection_failed(wpa_s, bss->bssid); |
c10347f2 | 623 | return; |
6ac4b15e | 624 | } |
ce16c489 JM |
625 | params.auth_data = wpabuf_head(resp); |
626 | params.auth_data_len = wpabuf_len(resp); | |
dd43026a | 627 | wpa_s->sme.sae.state = start ? SAE_COMMITTED : SAE_CONFIRMED; |
c10347f2 JM |
628 | } |
629 | #endif /* CONFIG_SAE */ | |
630 | ||
f00b9b88 JM |
631 | old_ssid = wpa_s->current_ssid; |
632 | wpa_s->current_ssid = ssid; | |
633 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); | |
634 | wpa_supplicant_initiate_eapol(wpa_s); | |
635 | ||
636 | #ifdef CONFIG_FILS | |
637 | /* TODO: FILS operations can in some cases be done between different | |
638 | * network_ctx (i.e., same credentials can be used with multiple | |
639 | * networks). */ | |
640 | if (params.auth_alg == WPA_AUTH_ALG_OPEN && | |
641 | wpa_key_mgmt_fils(ssid->key_mgmt)) { | |
64983516 JM |
642 | const u8 *indic; |
643 | u16 fils_info; | |
af835d75 AB |
644 | const u8 *realm, *username, *rrk; |
645 | size_t realm_len, username_len, rrk_len; | |
646 | u16 next_seq_num; | |
64983516 JM |
647 | |
648 | /* | |
649 | * Check FILS Indication element (FILS Information field) bits | |
650 | * indicating supported authentication algorithms against local | |
651 | * configuration (ssid->fils_dh_group). Try to use FILS | |
652 | * authentication only if the AP supports the combination in the | |
653 | * network profile. */ | |
654 | indic = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION); | |
655 | if (!indic || indic[1] < 2) { | |
656 | wpa_printf(MSG_DEBUG, "SME: " MACSTR | |
657 | " does not include FILS Indication element - cannot use FILS authentication with it", | |
658 | MAC2STR(bss->bssid)); | |
659 | goto no_fils; | |
660 | } | |
661 | ||
662 | fils_info = WPA_GET_LE16(indic + 2); | |
663 | if (ssid->fils_dh_group == 0 && !(fils_info & BIT(9))) { | |
664 | wpa_printf(MSG_DEBUG, "SME: " MACSTR | |
665 | " does not support FILS SK without PFS - cannot use FILS authentication with it", | |
666 | MAC2STR(bss->bssid)); | |
667 | goto no_fils; | |
668 | } | |
669 | if (ssid->fils_dh_group != 0 && !(fils_info & BIT(10))) { | |
670 | wpa_printf(MSG_DEBUG, "SME: " MACSTR | |
671 | " does not support FILS SK with PFS - cannot use FILS authentication with it", | |
672 | MAC2STR(bss->bssid)); | |
673 | goto no_fils; | |
674 | } | |
675 | ||
af835d75 AB |
676 | if (wpa_s->last_con_fail_realm && |
677 | eapol_sm_get_erp_info(wpa_s->eapol, &ssid->eap, | |
678 | &username, &username_len, | |
679 | &realm, &realm_len, &next_seq_num, | |
680 | &rrk, &rrk_len) == 0 && | |
681 | realm && realm_len == wpa_s->last_con_fail_realm_len && | |
682 | os_memcmp(realm, wpa_s->last_con_fail_realm, | |
683 | realm_len) == 0) { | |
684 | wpa_printf(MSG_DEBUG, | |
685 | "SME: FILS authentication for this realm failed last time - try to regenerate ERP key hierarchy"); | |
686 | goto no_fils; | |
687 | } | |
688 | ||
f00b9b88 | 689 | if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid, |
869af307 | 690 | ssid, 0, |
852b2f27 JM |
691 | wpa_bss_get_fils_cache_id(bss), |
692 | 0) == 0) | |
f00b9b88 JM |
693 | wpa_printf(MSG_DEBUG, |
694 | "SME: Try to use FILS with PMKSA caching"); | |
af3e362f | 695 | resp = fils_build_auth(wpa_s->wpa, ssid->fils_dh_group, md); |
f00b9b88 | 696 | if (resp) { |
76e20f4f JM |
697 | int auth_alg; |
698 | ||
699 | if (ssid->fils_dh_group) | |
700 | wpa_printf(MSG_DEBUG, | |
701 | "SME: Try to use FILS SK authentication with PFS (DH Group %u)", | |
702 | ssid->fils_dh_group); | |
703 | else | |
704 | wpa_printf(MSG_DEBUG, | |
705 | "SME: Try to use FILS SK authentication without PFS"); | |
706 | auth_alg = ssid->fils_dh_group ? | |
707 | WPA_AUTH_ALG_FILS_SK_PFS : WPA_AUTH_ALG_FILS; | |
708 | params.auth_alg = auth_alg; | |
f00b9b88 JM |
709 | params.auth_data = wpabuf_head(resp); |
710 | params.auth_data_len = wpabuf_len(resp); | |
76e20f4f | 711 | wpa_s->sme.auth_alg = auth_alg; |
f00b9b88 JM |
712 | } |
713 | } | |
64983516 | 714 | no_fils: |
f00b9b88 JM |
715 | #endif /* CONFIG_FILS */ |
716 | ||
a4cba8f1 | 717 | wpa_supplicant_cancel_sched_scan(wpa_s); |
c2a04078 JM |
718 | wpa_supplicant_cancel_scan(wpa_s); |
719 | ||
f049052b | 720 | wpa_msg(wpa_s, MSG_INFO, "SME: Trying to authenticate with " MACSTR |
c2a04078 JM |
721 | " (SSID='%s' freq=%d MHz)", MAC2STR(params.bssid), |
722 | wpa_ssid_txt(params.ssid, params.ssid_len), params.freq); | |
723 | ||
6aea02e5 | 724 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); |
c2a04078 JM |
725 | wpa_clear_keys(wpa_s, bss->bssid); |
726 | wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING); | |
8bac466b JM |
727 | if (old_ssid != wpa_s->current_ssid) |
728 | wpas_notify_network_changed(wpa_s); | |
c2a04078 | 729 | |
ece4ac5f MG |
730 | #ifdef CONFIG_HS20 |
731 | hs20_configure_frame_filters(wpa_s); | |
732 | #endif /* CONFIG_HS20 */ | |
733 | ||
d0df6437 IP |
734 | #ifdef CONFIG_P2P |
735 | /* | |
736 | * If multi-channel concurrency is not supported, check for any | |
737 | * frequency conflict. In case of any frequency conflict, remove the | |
738 | * least prioritized connection. | |
739 | */ | |
740 | if (wpa_s->num_multichan_concurrent < 2) { | |
741 | int freq, num; | |
742 | num = get_shared_radio_freqs(wpa_s, &freq, 1); | |
743 | if (num > 0 && freq > 0 && freq != params.freq) { | |
744 | wpa_printf(MSG_DEBUG, | |
745 | "Conflicting frequency found (%d != %d)", | |
746 | freq, params.freq); | |
747 | if (wpas_p2p_handle_frequency_conflicts(wpa_s, | |
748 | params.freq, | |
749 | ssid) < 0) { | |
750 | wpas_connection_failed(wpa_s, bss->bssid); | |
751 | wpa_supplicant_mark_disassoc(wpa_s); | |
752 | wpabuf_free(resp); | |
753 | wpas_connect_work_done(wpa_s); | |
754 | return; | |
755 | } | |
756 | } | |
757 | } | |
758 | #endif /* CONFIG_P2P */ | |
759 | ||
59b416c7 JM |
760 | if (skip_auth) { |
761 | wpa_msg(wpa_s, MSG_DEBUG, | |
762 | "SME: Skip authentication step on reassoc-to-same-BSS"); | |
763 | wpabuf_free(resp); | |
764 | sme_associate(wpa_s, ssid->mode, bss->bssid, WLAN_AUTH_OPEN); | |
765 | return; | |
766 | } | |
767 | ||
768 | ||
62c72d72 | 769 | wpa_s->sme.auth_alg = params.auth_alg; |
c2a04078 | 770 | if (wpa_drv_authenticate(wpa_s, ¶ms) < 0) { |
f049052b | 771 | wpa_msg(wpa_s, MSG_INFO, "SME: Authentication request to the " |
c2a04078 | 772 | "driver failed"); |
ed57c590 | 773 | wpas_connection_failed(wpa_s, bss->bssid); |
1193dc8f | 774 | wpa_supplicant_mark_disassoc(wpa_s); |
c10347f2 | 775 | wpabuf_free(resp); |
6ac4b15e | 776 | wpas_connect_work_done(wpa_s); |
c2a04078 JM |
777 | return; |
778 | } | |
779 | ||
e29853bb BG |
780 | eloop_register_timeout(SME_AUTH_TIMEOUT, 0, sme_auth_timer, wpa_s, |
781 | NULL); | |
c2a04078 JM |
782 | |
783 | /* | |
784 | * Association will be started based on the authentication event from | |
785 | * the driver. | |
786 | */ | |
c10347f2 JM |
787 | |
788 | wpabuf_free(resp); | |
789 | } | |
790 | ||
791 | ||
6ac4b15e JM |
792 | static void sme_auth_start_cb(struct wpa_radio_work *work, int deinit) |
793 | { | |
794 | struct wpa_connect_work *cwork = work->ctx; | |
795 | struct wpa_supplicant *wpa_s = work->wpa_s; | |
796 | ||
797 | if (deinit) { | |
b3253ebb AO |
798 | if (work->started) |
799 | wpa_s->connect_work = NULL; | |
800 | ||
6ac4b15e JM |
801 | wpas_connect_work_free(cwork); |
802 | return; | |
803 | } | |
804 | ||
805 | wpa_s->connect_work = work; | |
806 | ||
a7f5271d | 807 | if (cwork->bss_removed || |
6108536d HW |
808 | !wpas_valid_bss_ssid(wpa_s, cwork->bss, cwork->ssid) || |
809 | wpas_network_disabled(wpa_s, cwork->ssid)) { | |
6ac4b15e JM |
810 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: BSS/SSID entry for authentication not valid anymore - drop connection attempt"); |
811 | wpas_connect_work_done(wpa_s); | |
812 | return; | |
813 | } | |
814 | ||
2c2c5579 JM |
815 | /* Starting new connection, so clear the possibly used WPA IE from the |
816 | * previous association. */ | |
817 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); | |
818 | ||
6ac4b15e JM |
819 | sme_send_authentication(wpa_s, cwork->bss, cwork->ssid, 1); |
820 | } | |
821 | ||
822 | ||
c10347f2 JM |
823 | void sme_authenticate(struct wpa_supplicant *wpa_s, |
824 | struct wpa_bss *bss, struct wpa_ssid *ssid) | |
825 | { | |
6ac4b15e JM |
826 | struct wpa_connect_work *cwork; |
827 | ||
828 | if (bss == NULL || ssid == NULL) | |
829 | return; | |
830 | if (wpa_s->connect_work) { | |
831 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Reject sme_authenticate() call since connect_work exist"); | |
832 | return; | |
833 | } | |
834 | ||
f0e30c84 | 835 | if (radio_work_pending(wpa_s, "sme-connect")) { |
f1c4dbf5 IP |
836 | /* |
837 | * The previous sme-connect work might no longer be valid due to | |
838 | * the fact that the BSS list was updated. In addition, it makes | |
839 | * sense to adhere to the 'newer' decision. | |
840 | */ | |
841 | wpa_dbg(wpa_s, MSG_DEBUG, | |
842 | "SME: Remove previous pending sme-connect"); | |
843 | radio_remove_works(wpa_s, "sme-connect", 0); | |
f0e30c84 JM |
844 | } |
845 | ||
4ead7cfd KV |
846 | wpas_abort_ongoing_scan(wpa_s); |
847 | ||
6ac4b15e JM |
848 | cwork = os_zalloc(sizeof(*cwork)); |
849 | if (cwork == NULL) | |
850 | return; | |
851 | cwork->bss = bss; | |
852 | cwork->ssid = ssid; | |
853 | cwork->sme = 1; | |
854 | ||
98efcc41 | 855 | #ifdef CONFIG_SAE |
dd43026a | 856 | wpa_s->sme.sae.state = SAE_NOTHING; |
98efcc41 | 857 | wpa_s->sme.sae.send_confirm = 0; |
18ca7332 | 858 | wpa_s->sme.sae_group_index = 0; |
98efcc41 | 859 | #endif /* CONFIG_SAE */ |
6ac4b15e JM |
860 | |
861 | if (radio_add_work(wpa_s, bss->freq, "sme-connect", 1, | |
862 | sme_auth_start_cb, cwork) < 0) | |
863 | wpas_connect_work_free(cwork); | |
c2a04078 JM |
864 | } |
865 | ||
866 | ||
c10347f2 | 867 | #ifdef CONFIG_SAE |
21af6d15 | 868 | |
5ff39c13 SD |
869 | static int sme_external_auth_build_buf(struct wpabuf *buf, |
870 | struct wpabuf *params, | |
871 | const u8 *sa, const u8 *da, | |
872 | u16 auth_transaction, u16 seq_num) | |
873 | { | |
874 | struct ieee80211_mgmt *resp; | |
875 | ||
876 | resp = wpabuf_put(buf, offsetof(struct ieee80211_mgmt, | |
877 | u.auth.variable)); | |
878 | ||
879 | resp->frame_control = host_to_le16((WLAN_FC_TYPE_MGMT << 2) | | |
880 | (WLAN_FC_STYPE_AUTH << 4)); | |
881 | os_memcpy(resp->da, da, ETH_ALEN); | |
882 | os_memcpy(resp->sa, sa, ETH_ALEN); | |
883 | os_memcpy(resp->bssid, da, ETH_ALEN); | |
884 | resp->u.auth.auth_alg = WLAN_AUTH_SAE; | |
885 | resp->seq_ctrl = seq_num << 4; | |
886 | resp->u.auth.auth_transaction = auth_transaction; | |
887 | resp->u.auth.status_code = WLAN_STATUS_SUCCESS; | |
888 | if (params) | |
889 | wpabuf_put_buf(buf, params); | |
890 | ||
891 | return 0; | |
892 | } | |
893 | ||
894 | ||
895 | static void sme_external_auth_send_sae_commit(struct wpa_supplicant *wpa_s, | |
896 | const u8 *bssid, | |
897 | struct wpa_ssid *ssid) | |
898 | { | |
899 | struct wpabuf *resp, *buf; | |
900 | ||
901 | resp = sme_auth_build_sae_commit(wpa_s, ssid, bssid, 1); | |
902 | if (!resp) | |
903 | return; | |
904 | ||
905 | wpa_s->sme.sae.state = SAE_COMMITTED; | |
906 | buf = wpabuf_alloc(4 + SAE_COMMIT_MAX_LEN + wpabuf_len(resp)); | |
907 | if (!buf) { | |
908 | wpabuf_free(resp); | |
909 | return; | |
910 | } | |
911 | ||
912 | wpa_s->sme.seq_num++; | |
913 | sme_external_auth_build_buf(buf, resp, wpa_s->own_addr, | |
914 | bssid, 1, wpa_s->sme.seq_num); | |
915 | wpa_drv_send_mlme(wpa_s, wpabuf_head(buf), wpabuf_len(buf), 1, 0); | |
916 | wpabuf_free(resp); | |
917 | wpabuf_free(buf); | |
918 | } | |
919 | ||
920 | ||
921 | static void sme_send_external_auth_status(struct wpa_supplicant *wpa_s, | |
922 | u16 status) | |
923 | { | |
924 | struct external_auth params; | |
925 | ||
926 | os_memset(¶ms, 0, sizeof(params)); | |
927 | params.status = status; | |
928 | os_memcpy(params.ssid, wpa_s->sme.ext_auth.ssid, | |
929 | wpa_s->sme.ext_auth.ssid_len); | |
930 | params.ssid_len = wpa_s->sme.ext_auth.ssid_len; | |
931 | os_memcpy(params.bssid, wpa_s->sme.ext_auth.bssid, ETH_ALEN); | |
932 | wpa_drv_send_external_auth_status(wpa_s, ¶ms); | |
933 | } | |
934 | ||
935 | ||
936 | static void sme_handle_external_auth_start(struct wpa_supplicant *wpa_s, | |
937 | union wpa_event_data *data) | |
938 | { | |
939 | struct wpa_ssid *ssid; | |
940 | size_t ssid_str_len = data->external_auth.ssid_len; | |
941 | u8 *ssid_str = data->external_auth.ssid; | |
942 | ||
943 | /* Get the SSID conf from the ssid string obtained */ | |
944 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { | |
945 | if (!wpas_network_disabled(wpa_s, ssid) && | |
946 | ssid_str_len == ssid->ssid_len && | |
947 | os_memcmp(ssid_str, ssid->ssid, ssid_str_len) == 0) | |
948 | break; | |
949 | } | |
950 | if (ssid) | |
951 | sme_external_auth_send_sae_commit(wpa_s, | |
952 | data->external_auth.bssid, | |
953 | ssid); | |
954 | else | |
955 | sme_send_external_auth_status(wpa_s, | |
956 | WLAN_STATUS_UNSPECIFIED_FAILURE); | |
957 | } | |
958 | ||
959 | ||
960 | static void sme_external_auth_send_sae_confirm(struct wpa_supplicant *wpa_s, | |
961 | const u8 *da) | |
962 | { | |
963 | struct wpabuf *resp, *buf; | |
964 | ||
965 | resp = sme_auth_build_sae_confirm(wpa_s, 1); | |
966 | if (!resp) { | |
967 | wpa_printf(MSG_DEBUG, "SAE: Confirm message buf alloc failure"); | |
968 | return; | |
969 | } | |
970 | ||
971 | wpa_s->sme.sae.state = SAE_CONFIRMED; | |
972 | buf = wpabuf_alloc(4 + SAE_CONFIRM_MAX_LEN + wpabuf_len(resp)); | |
973 | if (!buf) { | |
974 | wpa_printf(MSG_DEBUG, "SAE: Auth Confirm buf alloc failure"); | |
975 | wpabuf_free(resp); | |
976 | return; | |
977 | } | |
978 | wpa_s->sme.seq_num++; | |
979 | sme_external_auth_build_buf(buf, resp, wpa_s->own_addr, | |
980 | da, 2, wpa_s->sme.seq_num); | |
981 | wpa_drv_send_mlme(wpa_s, wpabuf_head(buf), wpabuf_len(buf), 1, 0); | |
982 | wpabuf_free(resp); | |
983 | wpabuf_free(buf); | |
984 | } | |
985 | ||
986 | ||
987 | void sme_external_auth_trigger(struct wpa_supplicant *wpa_s, | |
988 | union wpa_event_data *data) | |
989 | { | |
990 | if (RSN_SELECTOR_GET(&data->external_auth.key_mgmt_suite) != | |
991 | RSN_AUTH_KEY_MGMT_SAE) | |
992 | return; | |
993 | ||
994 | if (data->external_auth.action == EXT_AUTH_START) { | |
995 | os_memcpy(&wpa_s->sme.ext_auth, data, | |
996 | sizeof(struct external_auth)); | |
997 | wpa_s->sme.seq_num = 0; | |
998 | wpa_s->sme.sae.state = SAE_NOTHING; | |
999 | wpa_s->sme.sae.send_confirm = 0; | |
1000 | wpa_s->sme.sae_group_index = 0; | |
1001 | sme_handle_external_auth_start(wpa_s, data); | |
1002 | } else if (data->external_auth.action == EXT_AUTH_ABORT) { | |
1003 | /* Report failure to driver for the wrong trigger */ | |
1004 | sme_send_external_auth_status(wpa_s, | |
1005 | WLAN_STATUS_UNSPECIFIED_FAILURE); | |
1006 | } | |
1007 | } | |
1008 | ||
1009 | ||
c10347f2 | 1010 | static int sme_sae_auth(struct wpa_supplicant *wpa_s, u16 auth_transaction, |
5ff39c13 SD |
1011 | u16 status_code, const u8 *data, size_t len, |
1012 | int external, const u8 *sa) | |
c10347f2 | 1013 | { |
a959a3b6 MH |
1014 | int *groups; |
1015 | ||
c10347f2 JM |
1016 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: SAE authentication transaction %u " |
1017 | "status code %u", auth_transaction, status_code); | |
c10347f2 | 1018 | |
d136c376 JM |
1019 | if (auth_transaction == 1 && |
1020 | status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ && | |
1021 | wpa_s->sme.sae.state == SAE_COMMITTED && | |
5ff39c13 | 1022 | (external || wpa_s->current_bss) && wpa_s->current_ssid) { |
a959a3b6 MH |
1023 | int default_groups[] = { 19, 20, 21, 25, 26, 0 }; |
1024 | u16 group; | |
1025 | ||
1026 | groups = wpa_s->conf->sae_groups; | |
1027 | if (!groups || groups[0] <= 0) | |
1028 | groups = default_groups; | |
1029 | ||
1030 | if (len < sizeof(le16)) { | |
1031 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1032 | "SME: Too short SAE anti-clogging token request"); | |
1033 | return -1; | |
1034 | } | |
1035 | group = WPA_GET_LE16(data); | |
1036 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1037 | "SME: SAE anti-clogging token requested (group %u)", | |
1038 | group); | |
1039 | if (sae_group_allowed(&wpa_s->sme.sae, groups, group) != | |
1040 | WLAN_STATUS_SUCCESS) { | |
1041 | wpa_dbg(wpa_s, MSG_ERROR, | |
1042 | "SME: SAE group %u of anti-clogging request is invalid", | |
1043 | group); | |
1044 | return -1; | |
1045 | } | |
d136c376 | 1046 | wpabuf_free(wpa_s->sme.sae_token); |
a959a3b6 MH |
1047 | wpa_s->sme.sae_token = wpabuf_alloc_copy(data + sizeof(le16), |
1048 | len - sizeof(le16)); | |
5ff39c13 SD |
1049 | if (!external) |
1050 | sme_send_authentication(wpa_s, wpa_s->current_bss, | |
1051 | wpa_s->current_ssid, 1); | |
1052 | else | |
1053 | sme_external_auth_send_sae_commit( | |
1054 | wpa_s, wpa_s->sme.ext_auth.bssid, | |
1055 | wpa_s->current_ssid); | |
d136c376 JM |
1056 | return 0; |
1057 | } | |
1058 | ||
625f202a JM |
1059 | if (auth_transaction == 1 && |
1060 | status_code == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED && | |
1061 | wpa_s->sme.sae.state == SAE_COMMITTED && | |
5ff39c13 | 1062 | (external || wpa_s->current_bss) && wpa_s->current_ssid) { |
625f202a JM |
1063 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: SAE group not supported"); |
1064 | wpa_s->sme.sae_group_index++; | |
1065 | if (sme_set_sae_group(wpa_s) < 0) | |
1066 | return -1; /* no other groups enabled */ | |
1067 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Try next enabled SAE group"); | |
5ff39c13 SD |
1068 | if (!external) |
1069 | sme_send_authentication(wpa_s, wpa_s->current_bss, | |
1070 | wpa_s->current_ssid, 1); | |
1071 | else | |
1072 | sme_external_auth_send_sae_commit( | |
1073 | wpa_s, wpa_s->sme.ext_auth.bssid, | |
1074 | wpa_s->current_ssid); | |
625f202a JM |
1075 | return 0; |
1076 | } | |
1077 | ||
9be19d0b JM |
1078 | if (auth_transaction == 1 && |
1079 | status_code == WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER) { | |
1080 | const u8 *bssid = sa ? sa : wpa_s->pending_bssid; | |
1081 | ||
1082 | wpa_msg(wpa_s, MSG_INFO, | |
1083 | WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER MACSTR, | |
1084 | MAC2STR(bssid)); | |
1085 | return -1; | |
1086 | } | |
1087 | ||
c10347f2 JM |
1088 | if (status_code != WLAN_STATUS_SUCCESS) |
1089 | return -1; | |
1090 | ||
1091 | if (auth_transaction == 1) { | |
6a58444d JM |
1092 | u16 res; |
1093 | ||
a959a3b6 | 1094 | groups = wpa_s->conf->sae_groups; |
18ca7332 | 1095 | |
c10347f2 | 1096 | wpa_dbg(wpa_s, MSG_DEBUG, "SME SAE commit"); |
5ff39c13 | 1097 | if ((!external && wpa_s->current_bss == NULL) || |
c10347f2 JM |
1098 | wpa_s->current_ssid == NULL) |
1099 | return -1; | |
dd43026a | 1100 | if (wpa_s->sme.sae.state != SAE_COMMITTED) |
21af6d15 | 1101 | return -1; |
18ca7332 JM |
1102 | if (groups && groups[0] <= 0) |
1103 | groups = NULL; | |
6a58444d JM |
1104 | res = sae_parse_commit(&wpa_s->sme.sae, data, len, NULL, NULL, |
1105 | groups); | |
1106 | if (res == SAE_SILENTLY_DISCARD) { | |
1107 | wpa_printf(MSG_DEBUG, | |
1108 | "SAE: Drop commit message due to reflection attack"); | |
1109 | return 0; | |
1110 | } | |
1111 | if (res != WLAN_STATUS_SUCCESS) | |
21af6d15 | 1112 | return -1; |
146f6c9a JM |
1113 | |
1114 | if (sae_process_commit(&wpa_s->sme.sae) < 0) { | |
1115 | wpa_printf(MSG_DEBUG, "SAE: Failed to process peer " | |
1116 | "commit"); | |
1117 | return -1; | |
1118 | } | |
1119 | ||
d136c376 JM |
1120 | wpabuf_free(wpa_s->sme.sae_token); |
1121 | wpa_s->sme.sae_token = NULL; | |
5ff39c13 SD |
1122 | if (!external) |
1123 | sme_send_authentication(wpa_s, wpa_s->current_bss, | |
1124 | wpa_s->current_ssid, 0); | |
1125 | else | |
1126 | sme_external_auth_send_sae_confirm(wpa_s, sa); | |
c10347f2 JM |
1127 | return 0; |
1128 | } else if (auth_transaction == 2) { | |
1129 | wpa_dbg(wpa_s, MSG_DEBUG, "SME SAE confirm"); | |
dd43026a | 1130 | if (wpa_s->sme.sae.state != SAE_CONFIRMED) |
21af6d15 | 1131 | return -1; |
f2e9818f | 1132 | if (sae_check_confirm(&wpa_s->sme.sae, data, len) < 0) |
21af6d15 | 1133 | return -1; |
dd43026a | 1134 | wpa_s->sme.sae.state = SAE_ACCEPTED; |
b4fd3613 | 1135 | sae_clear_temp_data(&wpa_s->sme.sae); |
5ff39c13 SD |
1136 | |
1137 | if (external) { | |
1138 | /* Report success to driver */ | |
1139 | sme_send_external_auth_status(wpa_s, | |
1140 | WLAN_STATUS_SUCCESS); | |
1141 | } | |
1142 | ||
c10347f2 JM |
1143 | return 1; |
1144 | } | |
1145 | ||
1146 | return -1; | |
1147 | } | |
5ff39c13 SD |
1148 | |
1149 | ||
1150 | void sme_external_auth_mgmt_rx(struct wpa_supplicant *wpa_s, | |
1151 | const u8 *auth_frame, size_t len) | |
1152 | { | |
1153 | const struct ieee80211_mgmt *header; | |
1154 | size_t auth_length; | |
1155 | ||
1156 | header = (const struct ieee80211_mgmt *) auth_frame; | |
1157 | auth_length = IEEE80211_HDRLEN + sizeof(header->u.auth); | |
1158 | ||
1159 | if (len < auth_length) { | |
1160 | /* Notify failure to the driver */ | |
1161 | sme_send_external_auth_status(wpa_s, | |
1162 | WLAN_STATUS_UNSPECIFIED_FAILURE); | |
1163 | return; | |
1164 | } | |
1165 | ||
1166 | if (header->u.auth.auth_alg == WLAN_AUTH_SAE) { | |
1167 | int res; | |
1168 | ||
1169 | res = sme_sae_auth(wpa_s, header->u.auth.auth_transaction, | |
1170 | header->u.auth.status_code, | |
1171 | header->u.auth.variable, | |
1172 | len - auth_length, 1, header->sa); | |
1173 | if (res < 0) { | |
1174 | /* Notify failure to the driver */ | |
1175 | sme_send_external_auth_status( | |
1176 | wpa_s, WLAN_STATUS_UNSPECIFIED_FAILURE); | |
1177 | return; | |
1178 | } | |
1179 | if (res != 1) | |
1180 | return; | |
1181 | ||
1182 | wpa_printf(MSG_DEBUG, | |
1183 | "SME: SAE completed - setting PMK for 4-way handshake"); | |
1184 | wpa_sm_set_pmk(wpa_s->wpa, wpa_s->sme.sae.pmk, PMK_LEN, | |
1185 | wpa_s->sme.sae.pmkid, wpa_s->pending_bssid); | |
1186 | } | |
1187 | } | |
1188 | ||
c10347f2 JM |
1189 | #endif /* CONFIG_SAE */ |
1190 | ||
1191 | ||
c2a04078 JM |
1192 | void sme_event_auth(struct wpa_supplicant *wpa_s, union wpa_event_data *data) |
1193 | { | |
c2a04078 JM |
1194 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
1195 | ||
1196 | if (ssid == NULL) { | |
f049052b BG |
1197 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Ignore authentication event " |
1198 | "when network is not selected"); | |
c2a04078 JM |
1199 | return; |
1200 | } | |
1201 | ||
1202 | if (wpa_s->wpa_state != WPA_AUTHENTICATING) { | |
f049052b BG |
1203 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Ignore authentication event " |
1204 | "when not in authenticating state"); | |
c2a04078 JM |
1205 | return; |
1206 | } | |
1207 | ||
1208 | if (os_memcmp(wpa_s->pending_bssid, data->auth.peer, ETH_ALEN) != 0) { | |
f049052b BG |
1209 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Ignore authentication with " |
1210 | "unexpected peer " MACSTR, | |
1211 | MAC2STR(data->auth.peer)); | |
c2a04078 JM |
1212 | return; |
1213 | } | |
1214 | ||
f049052b | 1215 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Authentication response: peer=" MACSTR |
c10347f2 | 1216 | " auth_type=%d auth_transaction=%d status_code=%d", |
f049052b | 1217 | MAC2STR(data->auth.peer), data->auth.auth_type, |
c10347f2 | 1218 | data->auth.auth_transaction, data->auth.status_code); |
c2a04078 JM |
1219 | wpa_hexdump(MSG_MSGDUMP, "SME: Authentication response IEs", |
1220 | data->auth.ies, data->auth.ies_len); | |
1221 | ||
e29853bb BG |
1222 | eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL); |
1223 | ||
c10347f2 JM |
1224 | #ifdef CONFIG_SAE |
1225 | if (data->auth.auth_type == WLAN_AUTH_SAE) { | |
21af6d15 JM |
1226 | int res; |
1227 | res = sme_sae_auth(wpa_s, data->auth.auth_transaction, | |
1228 | data->auth.status_code, data->auth.ies, | |
5ff39c13 | 1229 | data->auth.ies_len, 0, NULL); |
21af6d15 JM |
1230 | if (res < 0) { |
1231 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); | |
1232 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
1233 | ||
1234 | } | |
1235 | if (res != 1) | |
c10347f2 | 1236 | return; |
47b55a3e JM |
1237 | |
1238 | wpa_printf(MSG_DEBUG, "SME: SAE completed - setting PMK for " | |
1239 | "4-way handshake"); | |
bc26ac50 | 1240 | wpa_sm_set_pmk(wpa_s->wpa, wpa_s->sme.sae.pmk, PMK_LEN, |
70c93963 | 1241 | wpa_s->sme.sae.pmkid, wpa_s->pending_bssid); |
c10347f2 JM |
1242 | } |
1243 | #endif /* CONFIG_SAE */ | |
1244 | ||
c2a04078 | 1245 | if (data->auth.status_code != WLAN_STATUS_SUCCESS) { |
ec4387f9 JM |
1246 | char *ie_txt = NULL; |
1247 | ||
1248 | if (data->auth.ies && data->auth.ies_len) { | |
1249 | size_t buflen = 2 * data->auth.ies_len + 1; | |
1250 | ie_txt = os_malloc(buflen); | |
1251 | if (ie_txt) { | |
1252 | wpa_snprintf_hex(ie_txt, buflen, data->auth.ies, | |
1253 | data->auth.ies_len); | |
1254 | } | |
1255 | } | |
1256 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AUTH_REJECT MACSTR | |
5f11880f | 1257 | " auth_type=%u auth_transaction=%u status_code=%u%s%s", |
ec4387f9 JM |
1258 | MAC2STR(data->auth.peer), data->auth.auth_type, |
1259 | data->auth.auth_transaction, data->auth.status_code, | |
5f11880f JM |
1260 | ie_txt ? " ie=" : "", |
1261 | ie_txt ? ie_txt : ""); | |
ec4387f9 | 1262 | os_free(ie_txt); |
cb1583f6 | 1263 | |
af835d75 AB |
1264 | #ifdef CONFIG_FILS |
1265 | if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS || | |
1266 | wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) | |
1267 | fils_connection_failure(wpa_s); | |
1268 | #endif /* CONFIG_FILS */ | |
1269 | ||
cb1583f6 SO |
1270 | if (data->auth.status_code != |
1271 | WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG || | |
1272 | wpa_s->sme.auth_alg == data->auth.auth_type || | |
7e6646c7 | 1273 | wpa_s->current_ssid->auth_alg == WPA_AUTH_ALG_LEAP) { |
0fb337c1 | 1274 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
c1c02342 | 1275 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
cb1583f6 | 1276 | return; |
7e6646c7 | 1277 | } |
cb1583f6 | 1278 | |
d9504779 JM |
1279 | wpas_connect_work_done(wpa_s); |
1280 | ||
cb1583f6 SO |
1281 | switch (data->auth.auth_type) { |
1282 | case WLAN_AUTH_OPEN: | |
1283 | wpa_s->current_ssid->auth_alg = WPA_AUTH_ALG_SHARED; | |
1284 | ||
f049052b | 1285 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Trying SHARED auth"); |
cb1583f6 SO |
1286 | wpa_supplicant_associate(wpa_s, wpa_s->current_bss, |
1287 | wpa_s->current_ssid); | |
1288 | return; | |
1289 | ||
1290 | case WLAN_AUTH_SHARED_KEY: | |
1291 | wpa_s->current_ssid->auth_alg = WPA_AUTH_ALG_LEAP; | |
1292 | ||
f049052b | 1293 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Trying LEAP auth"); |
cb1583f6 SO |
1294 | wpa_supplicant_associate(wpa_s, wpa_s->current_bss, |
1295 | wpa_s->current_ssid); | |
1296 | return; | |
1297 | ||
1298 | default: | |
1299 | return; | |
1300 | } | |
c2a04078 JM |
1301 | } |
1302 | ||
1303 | #ifdef CONFIG_IEEE80211R | |
1304 | if (data->auth.auth_type == WLAN_AUTH_FT) { | |
c6c41f6e JM |
1305 | const u8 *ric_ies = NULL; |
1306 | size_t ric_ies_len = 0; | |
1307 | ||
1308 | if (wpa_s->ric_ies) { | |
1309 | ric_ies = wpabuf_head(wpa_s->ric_ies); | |
1310 | ric_ies_len = wpabuf_len(wpa_s->ric_ies); | |
1311 | } | |
ee140ef9 JM |
1312 | if (wpa_ft_process_response(wpa_s->wpa, data->auth.ies, |
1313 | data->auth.ies_len, 0, | |
c6c41f6e JM |
1314 | data->auth.peer, |
1315 | ric_ies, ric_ies_len) < 0) { | |
ee140ef9 JM |
1316 | wpa_dbg(wpa_s, MSG_DEBUG, |
1317 | "SME: FT Authentication response processing failed"); | |
1318 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" | |
1319 | MACSTR | |
1320 | " reason=%d locally_generated=1", | |
1321 | MAC2STR(wpa_s->pending_bssid), | |
1322 | WLAN_REASON_DEAUTH_LEAVING); | |
1323 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); | |
1324 | wpa_supplicant_mark_disassoc(wpa_s); | |
1325 | return; | |
1326 | } | |
c2a04078 JM |
1327 | } |
1328 | #endif /* CONFIG_IEEE80211R */ | |
1329 | ||
a6609937 | 1330 | #ifdef CONFIG_FILS |
76e20f4f JM |
1331 | if (data->auth.auth_type == WLAN_AUTH_FILS_SK || |
1332 | data->auth.auth_type == WLAN_AUTH_FILS_SK_PFS) { | |
1333 | u16 expect_auth_type; | |
1334 | ||
1335 | expect_auth_type = wpa_s->sme.auth_alg == | |
1336 | WPA_AUTH_ALG_FILS_SK_PFS ? WLAN_AUTH_FILS_SK_PFS : | |
1337 | WLAN_AUTH_FILS_SK; | |
1338 | if (data->auth.auth_type != expect_auth_type) { | |
1339 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1340 | "SME: FILS Authentication response used different auth alg (%u; expected %u)", | |
1341 | data->auth.auth_type, expect_auth_type); | |
1342 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" | |
1343 | MACSTR | |
1344 | " reason=%d locally_generated=1", | |
1345 | MAC2STR(wpa_s->pending_bssid), | |
1346 | WLAN_REASON_DEAUTH_LEAVING); | |
1347 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); | |
1348 | wpa_supplicant_mark_disassoc(wpa_s); | |
1349 | return; | |
1350 | } | |
1351 | ||
ba9774bd JM |
1352 | if (fils_process_auth(wpa_s->wpa, wpa_s->pending_bssid, |
1353 | data->auth.ies, data->auth.ies_len) < 0) { | |
a6609937 JM |
1354 | wpa_dbg(wpa_s, MSG_DEBUG, |
1355 | "SME: FILS Authentication response processing failed"); | |
1356 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" | |
1357 | MACSTR | |
1358 | " reason=%d locally_generated=1", | |
1359 | MAC2STR(wpa_s->pending_bssid), | |
1360 | WLAN_REASON_DEAUTH_LEAVING); | |
1361 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); | |
1362 | wpa_supplicant_mark_disassoc(wpa_s); | |
1363 | return; | |
1364 | } | |
1365 | } | |
1366 | #endif /* CONFIG_FILS */ | |
1367 | ||
71024cb2 JM |
1368 | sme_associate(wpa_s, ssid->mode, data->auth.peer, |
1369 | data->auth.auth_type); | |
1370 | } | |
1371 | ||
1372 | ||
95818ec1 | 1373 | #ifdef CONFIG_FILS |
7d440a3b JM |
1374 | #ifdef CONFIG_IEEE80211R |
1375 | static void remove_ie(u8 *buf, size_t *len, u8 eid) | |
1376 | { | |
1377 | u8 *pos, *next, *end; | |
1378 | ||
1379 | pos = (u8 *) get_ie(buf, *len, eid); | |
1380 | if (pos) { | |
1381 | next = pos + 2 + pos[1]; | |
1382 | end = buf + *len; | |
1383 | *len -= 2 + pos[1]; | |
1384 | os_memmove(pos, next, end - next); | |
1385 | } | |
1386 | } | |
1387 | #endif /* CONFIG_IEEE80211R */ | |
95818ec1 | 1388 | #endif /* CONFIG_FILS */ |
7d440a3b JM |
1389 | |
1390 | ||
71024cb2 JM |
1391 | void sme_associate(struct wpa_supplicant *wpa_s, enum wpas_mode mode, |
1392 | const u8 *bssid, u16 auth_type) | |
1393 | { | |
1394 | struct wpa_driver_associate_params params; | |
d9a27b04 | 1395 | struct ieee802_11_elems elems; |
86cd6928 JM |
1396 | #ifdef CONFIG_FILS |
1397 | u8 nonces[2 * FILS_NONCE_LEN]; | |
1398 | #endif /* CONFIG_FILS */ | |
80e8a5ee BG |
1399 | #ifdef CONFIG_HT_OVERRIDES |
1400 | struct ieee80211_ht_capabilities htcaps; | |
1401 | struct ieee80211_ht_capabilities htcaps_mask; | |
1402 | #endif /* CONFIG_HT_OVERRIDES */ | |
e9ee8dc3 JB |
1403 | #ifdef CONFIG_VHT_OVERRIDES |
1404 | struct ieee80211_vht_capabilities vhtcaps; | |
1405 | struct ieee80211_vht_capabilities vhtcaps_mask; | |
1406 | #endif /* CONFIG_VHT_OVERRIDES */ | |
71024cb2 | 1407 | |
c2a04078 | 1408 | os_memset(¶ms, 0, sizeof(params)); |
86cd6928 JM |
1409 | |
1410 | #ifdef CONFIG_FILS | |
76e20f4f JM |
1411 | if (auth_type == WLAN_AUTH_FILS_SK || |
1412 | auth_type == WLAN_AUTH_FILS_SK_PFS) { | |
86cd6928 JM |
1413 | struct wpabuf *buf; |
1414 | const u8 *snonce, *anonce; | |
5732b770 JM |
1415 | const unsigned int max_hlp = 20; |
1416 | struct wpabuf *hlp[max_hlp]; | |
1417 | unsigned int i, num_hlp = 0; | |
1418 | struct fils_hlp_req *req; | |
1419 | ||
1420 | dl_list_for_each(req, &wpa_s->fils_hlp_req, struct fils_hlp_req, | |
1421 | list) { | |
1422 | hlp[num_hlp] = wpabuf_alloc(2 * ETH_ALEN + 6 + | |
1423 | wpabuf_len(req->pkt)); | |
1424 | if (!hlp[num_hlp]) | |
1425 | break; | |
1426 | wpabuf_put_data(hlp[num_hlp], req->dst, ETH_ALEN); | |
1427 | wpabuf_put_data(hlp[num_hlp], wpa_s->own_addr, | |
1428 | ETH_ALEN); | |
1429 | wpabuf_put_data(hlp[num_hlp], | |
1430 | "\xaa\xaa\x03\x00\x00\x00", 6); | |
1431 | wpabuf_put_buf(hlp[num_hlp], req->pkt); | |
1432 | num_hlp++; | |
1433 | if (num_hlp >= max_hlp) | |
1434 | break; | |
1435 | } | |
86cd6928 JM |
1436 | |
1437 | buf = fils_build_assoc_req(wpa_s->wpa, ¶ms.fils_kek, | |
1438 | ¶ms.fils_kek_len, &snonce, | |
5732b770 JM |
1439 | &anonce, |
1440 | (const struct wpabuf **) hlp, | |
1441 | num_hlp); | |
1442 | for (i = 0; i < num_hlp; i++) | |
1443 | wpabuf_free(hlp[i]); | |
86cd6928 JM |
1444 | if (!buf) |
1445 | return; | |
7d440a3b JM |
1446 | wpa_hexdump(MSG_DEBUG, "FILS: assoc_req before FILS elements", |
1447 | wpa_s->sme.assoc_req_ie, | |
1448 | wpa_s->sme.assoc_req_ie_len); | |
1449 | #ifdef CONFIG_IEEE80211R | |
1450 | if (wpa_key_mgmt_ft(wpa_s->key_mgmt)) { | |
1451 | /* Remove RSNE and MDE to allow them to be overridden | |
1452 | * with FILS+FT specific values from | |
1453 | * fils_build_assoc_req(). */ | |
1454 | remove_ie(wpa_s->sme.assoc_req_ie, | |
1455 | &wpa_s->sme.assoc_req_ie_len, | |
1456 | WLAN_EID_RSN); | |
1457 | wpa_hexdump(MSG_DEBUG, | |
1458 | "FILS: assoc_req after RSNE removal", | |
1459 | wpa_s->sme.assoc_req_ie, | |
1460 | wpa_s->sme.assoc_req_ie_len); | |
1461 | remove_ie(wpa_s->sme.assoc_req_ie, | |
1462 | &wpa_s->sme.assoc_req_ie_len, | |
1463 | WLAN_EID_MOBILITY_DOMAIN); | |
1464 | wpa_hexdump(MSG_DEBUG, | |
1465 | "FILS: assoc_req after MDE removal", | |
1466 | wpa_s->sme.assoc_req_ie, | |
1467 | wpa_s->sme.assoc_req_ie_len); | |
1468 | } | |
1469 | #endif /* CONFIG_IEEE80211R */ | |
86cd6928 JM |
1470 | /* TODO: Make wpa_s->sme.assoc_req_ie use dynamic allocation */ |
1471 | if (wpa_s->sme.assoc_req_ie_len + wpabuf_len(buf) > | |
1472 | sizeof(wpa_s->sme.assoc_req_ie)) { | |
1473 | wpa_printf(MSG_ERROR, | |
1474 | "FILS: Not enough buffer room for own AssocReq elements"); | |
1475 | wpabuf_free(buf); | |
1476 | return; | |
1477 | } | |
1478 | os_memcpy(wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len, | |
1479 | wpabuf_head(buf), wpabuf_len(buf)); | |
1480 | wpa_s->sme.assoc_req_ie_len += wpabuf_len(buf); | |
1481 | wpabuf_free(buf); | |
7d440a3b JM |
1482 | wpa_hexdump(MSG_DEBUG, "FILS: assoc_req after FILS elements", |
1483 | wpa_s->sme.assoc_req_ie, | |
1484 | wpa_s->sme.assoc_req_ie_len); | |
86cd6928 JM |
1485 | |
1486 | os_memcpy(nonces, snonce, FILS_NONCE_LEN); | |
1487 | os_memcpy(nonces + FILS_NONCE_LEN, anonce, FILS_NONCE_LEN); | |
1488 | params.fils_nonces = nonces; | |
1489 | params.fils_nonces_len = sizeof(nonces); | |
1490 | } | |
1491 | #endif /* CONFIG_FILS */ | |
1492 | ||
0a614799 | 1493 | #ifdef CONFIG_OWE |
265bda34 JM |
1494 | #ifdef CONFIG_TESTING_OPTIONS |
1495 | if (get_ie_ext(wpa_s->sme.assoc_req_ie, wpa_s->sme.assoc_req_ie_len, | |
1496 | WLAN_EID_EXT_OWE_DH_PARAM)) { | |
1497 | wpa_printf(MSG_INFO, "TESTING: Override OWE DH element"); | |
1498 | } else | |
1499 | #endif /* CONFIG_TESTING_OPTIONS */ | |
0a614799 JM |
1500 | if (auth_type == WLAN_AUTH_OPEN && |
1501 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE) { | |
1502 | struct wpabuf *owe_ie; | |
2cb40e9f | 1503 | u16 group; |
0a614799 | 1504 | |
2cb40e9f | 1505 | if (wpa_s->current_ssid && wpa_s->current_ssid->owe_group) { |
ec9f4837 | 1506 | group = wpa_s->current_ssid->owe_group; |
2cb40e9f JM |
1507 | } else { |
1508 | if (wpa_s->last_owe_group == 19) | |
1509 | group = 20; | |
1510 | else if (wpa_s->last_owe_group == 20) | |
1511 | group = 21; | |
1512 | else | |
1513 | group = OWE_DH_GROUP; | |
1514 | } | |
1515 | wpa_s->last_owe_group = group; | |
1516 | wpa_printf(MSG_DEBUG, "OWE: Try to use group %u", group); | |
ec9f4837 | 1517 | owe_ie = owe_build_assoc_req(wpa_s->wpa, group); |
0a614799 JM |
1518 | if (!owe_ie) { |
1519 | wpa_printf(MSG_ERROR, | |
1520 | "OWE: Failed to build IE for Association Request frame"); | |
1521 | return; | |
1522 | } | |
1523 | if (wpa_s->sme.assoc_req_ie_len + wpabuf_len(owe_ie) > | |
1524 | sizeof(wpa_s->sme.assoc_req_ie)) { | |
1525 | wpa_printf(MSG_ERROR, | |
1526 | "OWE: Not enough buffer room for own Association Request frame elements"); | |
1527 | wpabuf_free(owe_ie); | |
1528 | return; | |
1529 | } | |
1530 | os_memcpy(wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len, | |
1531 | wpabuf_head(owe_ie), wpabuf_len(owe_ie)); | |
1532 | wpa_s->sme.assoc_req_ie_len += wpabuf_len(owe_ie); | |
1533 | wpabuf_free(owe_ie); | |
1534 | } | |
1535 | #endif /* CONFIG_OWE */ | |
1536 | ||
71024cb2 | 1537 | params.bssid = bssid; |
c2a04078 JM |
1538 | params.ssid = wpa_s->sme.ssid; |
1539 | params.ssid_len = wpa_s->sme.ssid_len; | |
4ec68377 | 1540 | params.freq.freq = wpa_s->sme.freq; |
1f6c0ab8 BS |
1541 | params.bg_scan_period = wpa_s->current_ssid ? |
1542 | wpa_s->current_ssid->bg_scan_period : -1; | |
c2a04078 JM |
1543 | params.wpa_ie = wpa_s->sme.assoc_req_ie_len ? |
1544 | wpa_s->sme.assoc_req_ie : NULL; | |
1545 | params.wpa_ie_len = wpa_s->sme.assoc_req_ie_len; | |
4848a38d JM |
1546 | params.pairwise_suite = wpa_s->pairwise_cipher; |
1547 | params.group_suite = wpa_s->group_cipher; | |
61a56c14 | 1548 | params.mgmt_group_suite = wpa_s->mgmt_group_cipher; |
163f801e JM |
1549 | params.key_mgmt_suite = wpa_s->key_mgmt; |
1550 | params.wpa_proto = wpa_s->wpa_proto; | |
80e8a5ee BG |
1551 | #ifdef CONFIG_HT_OVERRIDES |
1552 | os_memset(&htcaps, 0, sizeof(htcaps)); | |
1553 | os_memset(&htcaps_mask, 0, sizeof(htcaps_mask)); | |
1554 | params.htcaps = (u8 *) &htcaps; | |
1555 | params.htcaps_mask = (u8 *) &htcaps_mask; | |
1556 | wpa_supplicant_apply_ht_overrides(wpa_s, wpa_s->current_ssid, ¶ms); | |
1557 | #endif /* CONFIG_HT_OVERRIDES */ | |
e9ee8dc3 JB |
1558 | #ifdef CONFIG_VHT_OVERRIDES |
1559 | os_memset(&vhtcaps, 0, sizeof(vhtcaps)); | |
1560 | os_memset(&vhtcaps_mask, 0, sizeof(vhtcaps_mask)); | |
1561 | params.vhtcaps = &vhtcaps; | |
1562 | params.vhtcaps_mask = &vhtcaps_mask; | |
1563 | wpa_supplicant_apply_vht_overrides(wpa_s, wpa_s->current_ssid, ¶ms); | |
1564 | #endif /* CONFIG_VHT_OVERRIDES */ | |
c2a04078 | 1565 | #ifdef CONFIG_IEEE80211R |
71024cb2 | 1566 | if (auth_type == WLAN_AUTH_FT && wpa_s->sme.ft_ies) { |
c2a04078 JM |
1567 | params.wpa_ie = wpa_s->sme.ft_ies; |
1568 | params.wpa_ie_len = wpa_s->sme.ft_ies_len; | |
1569 | } | |
1570 | #endif /* CONFIG_IEEE80211R */ | |
71024cb2 | 1571 | params.mode = mode; |
c2a04078 | 1572 | params.mgmt_frame_protection = wpa_s->sme.mfp; |
b361d580 | 1573 | params.rrm_used = wpa_s->rrm.rrm_used; |
62fa124c JM |
1574 | if (wpa_s->sme.prev_bssid_set) |
1575 | params.prev_bssid = wpa_s->sme.prev_bssid; | |
c2a04078 JM |
1576 | |
1577 | wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR | |
1578 | " (SSID='%s' freq=%d MHz)", MAC2STR(params.bssid), | |
1579 | params.ssid ? wpa_ssid_txt(params.ssid, params.ssid_len) : "", | |
4ec68377 | 1580 | params.freq.freq); |
c2a04078 JM |
1581 | |
1582 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING); | |
1583 | ||
9efc3f2a JM |
1584 | if (params.wpa_ie == NULL || |
1585 | ieee802_11_parse_elems(params.wpa_ie, params.wpa_ie_len, &elems, 0) | |
d9a27b04 | 1586 | < 0) { |
f049052b | 1587 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Could not parse own IEs?!"); |
d9a27b04 JM |
1588 | os_memset(&elems, 0, sizeof(elems)); |
1589 | } | |
64fa840a JM |
1590 | if (elems.rsn_ie) { |
1591 | params.wpa_proto = WPA_PROTO_RSN; | |
d9a27b04 JM |
1592 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.rsn_ie - 2, |
1593 | elems.rsn_ie_len + 2); | |
64fa840a JM |
1594 | } else if (elems.wpa_ie) { |
1595 | params.wpa_proto = WPA_PROTO_WPA; | |
d9a27b04 JM |
1596 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.wpa_ie - 2, |
1597 | elems.wpa_ie_len + 2); | |
df0f01d9 JM |
1598 | } else if (elems.osen) { |
1599 | params.wpa_proto = WPA_PROTO_OSEN; | |
1600 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.osen - 2, | |
1601 | elems.osen_len + 2); | |
64fa840a | 1602 | } else |
d9a27b04 | 1603 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); |
ffad8858 | 1604 | if (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group) |
6e3f4b89 | 1605 | params.p2p = 1; |
d9a27b04 | 1606 | |
ba307f85 LD |
1607 | if (wpa_s->p2pdev->set_sta_uapsd) |
1608 | params.uapsd = wpa_s->p2pdev->sta_uapsd; | |
eea2fd9e JM |
1609 | else |
1610 | params.uapsd = -1; | |
1611 | ||
c2a04078 | 1612 | if (wpa_drv_associate(wpa_s, ¶ms) < 0) { |
f049052b BG |
1613 | wpa_msg(wpa_s, MSG_INFO, "SME: Association request to the " |
1614 | "driver failed"); | |
e5ad96b7 | 1615 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
c1c02342 | 1616 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
e5ad96b7 | 1617 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
c2a04078 JM |
1618 | return; |
1619 | } | |
1620 | ||
e29853bb BG |
1621 | eloop_register_timeout(SME_ASSOC_TIMEOUT, 0, sme_assoc_timer, wpa_s, |
1622 | NULL); | |
daa40960 JM |
1623 | |
1624 | #ifdef CONFIG_TESTING_OPTIONS | |
1625 | wpabuf_free(wpa_s->last_assoc_req_wpa_ie); | |
1626 | wpa_s->last_assoc_req_wpa_ie = NULL; | |
1627 | if (params.wpa_ie) | |
1628 | wpa_s->last_assoc_req_wpa_ie = | |
1629 | wpabuf_alloc_copy(params.wpa_ie, params.wpa_ie_len); | |
1630 | #endif /* CONFIG_TESTING_OPTIONS */ | |
c2a04078 JM |
1631 | } |
1632 | ||
1633 | ||
1634 | int sme_update_ft_ies(struct wpa_supplicant *wpa_s, const u8 *md, | |
1635 | const u8 *ies, size_t ies_len) | |
1636 | { | |
1637 | if (md == NULL || ies == NULL) { | |
f049052b | 1638 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Remove mobility domain"); |
c2a04078 JM |
1639 | os_free(wpa_s->sme.ft_ies); |
1640 | wpa_s->sme.ft_ies = NULL; | |
1641 | wpa_s->sme.ft_ies_len = 0; | |
1642 | wpa_s->sme.ft_used = 0; | |
1643 | return 0; | |
1644 | } | |
1645 | ||
1646 | os_memcpy(wpa_s->sme.mobility_domain, md, MOBILITY_DOMAIN_ID_LEN); | |
1647 | wpa_hexdump(MSG_DEBUG, "SME: FT IEs", ies, ies_len); | |
1648 | os_free(wpa_s->sme.ft_ies); | |
a1f11e34 | 1649 | wpa_s->sme.ft_ies = os_memdup(ies, ies_len); |
c2a04078 JM |
1650 | if (wpa_s->sme.ft_ies == NULL) |
1651 | return -1; | |
c2a04078 JM |
1652 | wpa_s->sme.ft_ies_len = ies_len; |
1653 | return 0; | |
1654 | } | |
efa46078 JM |
1655 | |
1656 | ||
e29853bb | 1657 | static void sme_deauth(struct wpa_supplicant *wpa_s) |
efa46078 | 1658 | { |
8bac466b JM |
1659 | int bssid_changed; |
1660 | ||
8bac466b | 1661 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
76d11d3f | 1662 | |
76d11d3f JM |
1663 | if (wpa_drv_deauthenticate(wpa_s, wpa_s->pending_bssid, |
1664 | WLAN_REASON_DEAUTH_LEAVING) < 0) { | |
f049052b BG |
1665 | wpa_msg(wpa_s, MSG_INFO, "SME: Deauth request to the driver " |
1666 | "failed"); | |
76d11d3f | 1667 | } |
62fa124c | 1668 | wpa_s->sme.prev_bssid_set = 0; |
76d11d3f | 1669 | |
0fb337c1 | 1670 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
76d11d3f | 1671 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
efa46078 JM |
1672 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
1673 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
8bac466b JM |
1674 | if (bssid_changed) |
1675 | wpas_notify_bssid_changed(wpa_s); | |
efa46078 | 1676 | } |
da1fb17c JM |
1677 | |
1678 | ||
e29853bb BG |
1679 | void sme_event_assoc_reject(struct wpa_supplicant *wpa_s, |
1680 | union wpa_event_data *data) | |
1681 | { | |
1682 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Association with " MACSTR " failed: " | |
1683 | "status code %d", MAC2STR(wpa_s->pending_bssid), | |
1684 | data->assoc_reject.status_code); | |
1685 | ||
1686 | eloop_cancel_timeout(sme_assoc_timer, wpa_s, NULL); | |
1687 | ||
bc26ac50 JM |
1688 | #ifdef CONFIG_SAE |
1689 | if (wpa_s->sme.sae_pmksa_caching && wpa_s->current_ssid && | |
1690 | wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt)) { | |
1691 | wpa_dbg(wpa_s, MSG_DEBUG, | |
1692 | "PMKSA caching attempt rejected - drop PMKSA cache entry and fall back to SAE authentication"); | |
1693 | wpa_sm_aborted_cached(wpa_s->wpa); | |
1694 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid); | |
1695 | if (wpa_s->current_bss) { | |
1696 | struct wpa_bss *bss = wpa_s->current_bss; | |
1697 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
1698 | ||
1699 | wpa_drv_deauthenticate(wpa_s, wpa_s->pending_bssid, | |
1700 | WLAN_REASON_DEAUTH_LEAVING); | |
1701 | wpas_connect_work_done(wpa_s); | |
1702 | wpa_supplicant_mark_disassoc(wpa_s); | |
1703 | wpa_supplicant_connect(wpa_s, bss, ssid); | |
1704 | return; | |
1705 | } | |
1706 | } | |
1707 | #endif /* CONFIG_SAE */ | |
1708 | ||
e29853bb BG |
1709 | /* |
1710 | * For now, unconditionally terminate the previous authentication. In | |
1711 | * theory, this should not be needed, but mac80211 gets quite confused | |
1712 | * if the authentication is left pending.. Some roaming cases might | |
1713 | * benefit from using the previous authentication, so this could be | |
1714 | * optimized in the future. | |
1715 | */ | |
1716 | sme_deauth(wpa_s); | |
1717 | } | |
1718 | ||
1719 | ||
da1fb17c JM |
1720 | void sme_event_auth_timed_out(struct wpa_supplicant *wpa_s, |
1721 | union wpa_event_data *data) | |
1722 | { | |
f049052b | 1723 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Authentication timed out"); |
0fb337c1 | 1724 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
1193dc8f | 1725 | wpa_supplicant_mark_disassoc(wpa_s); |
da1fb17c JM |
1726 | } |
1727 | ||
1728 | ||
1729 | void sme_event_assoc_timed_out(struct wpa_supplicant *wpa_s, | |
1730 | union wpa_event_data *data) | |
1731 | { | |
f049052b | 1732 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Association timed out"); |
0fb337c1 | 1733 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
da1fb17c | 1734 | wpa_supplicant_mark_disassoc(wpa_s); |
da1fb17c | 1735 | } |
a84ed99e JM |
1736 | |
1737 | ||
1738 | void sme_event_disassoc(struct wpa_supplicant *wpa_s, | |
d7df0fa7 | 1739 | struct disassoc_info *info) |
a84ed99e | 1740 | { |
f049052b | 1741 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Disassociation event received"); |
17fbb751 | 1742 | if (wpa_s->sme.prev_bssid_set) { |
a84ed99e JM |
1743 | /* |
1744 | * cfg80211/mac80211 can get into somewhat confused state if | |
1745 | * the AP only disassociates us and leaves us in authenticated | |
1746 | * state. For now, force the state to be cleared to avoid | |
1747 | * confusing errors if we try to associate with the AP again. | |
1748 | */ | |
f049052b BG |
1749 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Deauthenticate to clear " |
1750 | "driver state"); | |
7e26053a | 1751 | wpa_drv_deauthenticate(wpa_s, wpa_s->sme.prev_bssid, |
a84ed99e JM |
1752 | WLAN_REASON_DEAUTH_LEAVING); |
1753 | } | |
1754 | } | |
7d878ca7 JM |
1755 | |
1756 | ||
e29853bb BG |
1757 | static void sme_auth_timer(void *eloop_ctx, void *timeout_ctx) |
1758 | { | |
1759 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1760 | if (wpa_s->wpa_state == WPA_AUTHENTICATING) { | |
1761 | wpa_msg(wpa_s, MSG_DEBUG, "SME: Authentication timeout"); | |
1762 | sme_deauth(wpa_s); | |
1763 | } | |
1764 | } | |
1765 | ||
1766 | ||
1767 | static void sme_assoc_timer(void *eloop_ctx, void *timeout_ctx) | |
1768 | { | |
1769 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1770 | if (wpa_s->wpa_state == WPA_ASSOCIATING) { | |
1771 | wpa_msg(wpa_s, MSG_DEBUG, "SME: Association timeout"); | |
1772 | sme_deauth(wpa_s); | |
1773 | } | |
1774 | } | |
1775 | ||
1776 | ||
1777 | void sme_state_changed(struct wpa_supplicant *wpa_s) | |
1778 | { | |
1779 | /* Make sure timers are cleaned up appropriately. */ | |
1780 | if (wpa_s->wpa_state != WPA_ASSOCIATING) | |
1781 | eloop_cancel_timeout(sme_assoc_timer, wpa_s, NULL); | |
1782 | if (wpa_s->wpa_state != WPA_AUTHENTICATING) | |
1783 | eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL); | |
1784 | } | |
1785 | ||
1786 | ||
1787 | void sme_disassoc_while_authenticating(struct wpa_supplicant *wpa_s, | |
1788 | const u8 *prev_pending_bssid) | |
1789 | { | |
1790 | /* | |
1791 | * mac80211-workaround to force deauth on failed auth cmd, | |
1792 | * requires us to remain in authenticating state to allow the | |
1793 | * second authentication attempt to be continued properly. | |
1794 | */ | |
1795 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Allow pending authentication " | |
1796 | "to proceed after disconnection event"); | |
1797 | wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING); | |
1798 | os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN); | |
1799 | ||
1800 | /* | |
1801 | * Re-arm authentication timer in case auth fails for whatever reason. | |
1802 | */ | |
1803 | eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL); | |
1804 | eloop_register_timeout(SME_AUTH_TIMEOUT, 0, sme_auth_timer, wpa_s, | |
1805 | NULL); | |
1806 | } | |
1807 | ||
1808 | ||
4e70bbf1 JM |
1809 | void sme_clear_on_disassoc(struct wpa_supplicant *wpa_s) |
1810 | { | |
1811 | wpa_s->sme.prev_bssid_set = 0; | |
1812 | #ifdef CONFIG_SAE | |
1813 | wpabuf_free(wpa_s->sme.sae_token); | |
1814 | wpa_s->sme.sae_token = NULL; | |
1815 | sae_clear_data(&wpa_s->sme.sae); | |
1816 | #endif /* CONFIG_SAE */ | |
1817 | #ifdef CONFIG_IEEE80211R | |
60a5737e | 1818 | if (wpa_s->sme.ft_ies || wpa_s->sme.ft_used) |
4e70bbf1 JM |
1819 | sme_update_ft_ies(wpa_s, NULL, NULL, 0); |
1820 | #endif /* CONFIG_IEEE80211R */ | |
1821 | } | |
1822 | ||
1823 | ||
e29853bb BG |
1824 | void sme_deinit(struct wpa_supplicant *wpa_s) |
1825 | { | |
1826 | os_free(wpa_s->sme.ft_ies); | |
1827 | wpa_s->sme.ft_ies = NULL; | |
1828 | wpa_s->sme.ft_ies_len = 0; | |
1829 | #ifdef CONFIG_IEEE80211W | |
1830 | sme_stop_sa_query(wpa_s); | |
1831 | #endif /* CONFIG_IEEE80211W */ | |
4e70bbf1 | 1832 | sme_clear_on_disassoc(wpa_s); |
e29853bb BG |
1833 | |
1834 | eloop_cancel_timeout(sme_assoc_timer, wpa_s, NULL); | |
1835 | eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL); | |
c3701c66 RM |
1836 | eloop_cancel_timeout(sme_obss_scan_timeout, wpa_s, NULL); |
1837 | } | |
1838 | ||
1839 | ||
1840 | static void sme_send_2040_bss_coex(struct wpa_supplicant *wpa_s, | |
1841 | const u8 *chan_list, u8 num_channels, | |
1842 | u8 num_intol) | |
1843 | { | |
1844 | struct ieee80211_2040_bss_coex_ie *bc_ie; | |
1845 | struct ieee80211_2040_intol_chan_report *ic_report; | |
1846 | struct wpabuf *buf; | |
1847 | ||
31ded52e JM |
1848 | wpa_printf(MSG_DEBUG, "SME: Send 20/40 BSS Coexistence to " MACSTR |
1849 | " (num_channels=%u num_intol=%u)", | |
1850 | MAC2STR(wpa_s->bssid), num_channels, num_intol); | |
1851 | wpa_hexdump(MSG_DEBUG, "SME: 20/40 BSS Intolerant Channels", | |
1852 | chan_list, num_channels); | |
c3701c66 RM |
1853 | |
1854 | buf = wpabuf_alloc(2 + /* action.category + action_code */ | |
1855 | sizeof(struct ieee80211_2040_bss_coex_ie) + | |
1856 | sizeof(struct ieee80211_2040_intol_chan_report) + | |
1857 | num_channels); | |
1858 | if (buf == NULL) | |
1859 | return; | |
1860 | ||
1861 | wpabuf_put_u8(buf, WLAN_ACTION_PUBLIC); | |
1862 | wpabuf_put_u8(buf, WLAN_PA_20_40_BSS_COEX); | |
1863 | ||
1864 | bc_ie = wpabuf_put(buf, sizeof(*bc_ie)); | |
1865 | bc_ie->element_id = WLAN_EID_20_40_BSS_COEXISTENCE; | |
1866 | bc_ie->length = 1; | |
1867 | if (num_intol) | |
1868 | bc_ie->coex_param |= WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ; | |
1869 | ||
1870 | if (num_channels > 0) { | |
1871 | ic_report = wpabuf_put(buf, sizeof(*ic_report)); | |
1872 | ic_report->element_id = WLAN_EID_20_40_BSS_INTOLERANT; | |
1873 | ic_report->length = num_channels + 1; | |
1874 | ic_report->op_class = 0; | |
1875 | os_memcpy(wpabuf_put(buf, num_channels), chan_list, | |
1876 | num_channels); | |
1877 | } | |
1878 | ||
1879 | if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, | |
1880 | wpa_s->own_addr, wpa_s->bssid, | |
1881 | wpabuf_head(buf), wpabuf_len(buf), 0) < 0) { | |
1882 | wpa_msg(wpa_s, MSG_INFO, | |
1883 | "SME: Failed to send 20/40 BSS Coexistence frame"); | |
1884 | } | |
1885 | ||
1886 | wpabuf_free(buf); | |
1887 | } | |
1888 | ||
1889 | ||
c3701c66 RM |
1890 | int sme_proc_obss_scan(struct wpa_supplicant *wpa_s) |
1891 | { | |
1892 | struct wpa_bss *bss; | |
1893 | const u8 *ie; | |
1894 | u16 ht_cap; | |
1895 | u8 chan_list[P2P_MAX_CHANNELS], channel; | |
1896 | u8 num_channels = 0, num_intol = 0, i; | |
1897 | ||
1898 | if (!wpa_s->sme.sched_obss_scan) | |
1899 | return 0; | |
1900 | ||
1901 | wpa_s->sme.sched_obss_scan = 0; | |
1902 | if (!wpa_s->current_bss || wpa_s->wpa_state != WPA_COMPLETED) | |
1903 | return 1; | |
1904 | ||
1905 | /* | |
1906 | * Check whether AP uses regulatory triplet or channel triplet in | |
1907 | * country info. Right now the operating class of the BSS channel | |
1908 | * width trigger event is "unknown" (IEEE Std 802.11-2012 10.15.12), | |
1909 | * based on the assumption that operating class triplet is not used in | |
1910 | * beacon frame. If the First Channel Number/Operating Extension | |
1911 | * Identifier octet has a positive integer value of 201 or greater, | |
1912 | * then its operating class triplet. | |
1913 | * | |
1914 | * TODO: If Supported Operating Classes element is present in beacon | |
1915 | * frame, have to lookup operating class in Annex E and fill them in | |
1916 | * 2040 coex frame. | |
1917 | */ | |
1918 | ie = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_COUNTRY); | |
1919 | if (ie && (ie[1] >= 6) && (ie[5] >= 201)) | |
1920 | return 1; | |
1921 | ||
1922 | os_memset(chan_list, 0, sizeof(chan_list)); | |
1923 | ||
1924 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { | |
1925 | /* Skip other band bss */ | |
e864c0ae JM |
1926 | enum hostapd_hw_mode mode; |
1927 | mode = ieee80211_freq_to_chan(bss->freq, &channel); | |
1928 | if (mode != HOSTAPD_MODE_IEEE80211G && | |
1929 | mode != HOSTAPD_MODE_IEEE80211B) | |
c3701c66 RM |
1930 | continue; |
1931 | ||
1932 | ie = wpa_bss_get_ie(bss, WLAN_EID_HT_CAP); | |
1933 | ht_cap = (ie && (ie[1] == 26)) ? WPA_GET_LE16(ie + 2) : 0; | |
31ded52e JM |
1934 | wpa_printf(MSG_DEBUG, "SME OBSS scan BSS " MACSTR |
1935 | " freq=%u chan=%u ht_cap=0x%x", | |
1936 | MAC2STR(bss->bssid), bss->freq, channel, ht_cap); | |
c3701c66 RM |
1937 | |
1938 | if (!ht_cap || (ht_cap & HT_CAP_INFO_40MHZ_INTOLERANT)) { | |
7f8eb34d JM |
1939 | if (ht_cap & HT_CAP_INFO_40MHZ_INTOLERANT) |
1940 | num_intol++; | |
1941 | ||
c3701c66 RM |
1942 | /* Check whether the channel is already considered */ |
1943 | for (i = 0; i < num_channels; i++) { | |
1944 | if (channel == chan_list[i]) | |
1945 | break; | |
1946 | } | |
1947 | if (i != num_channels) | |
1948 | continue; | |
1949 | ||
c3701c66 RM |
1950 | chan_list[num_channels++] = channel; |
1951 | } | |
1952 | } | |
1953 | ||
1954 | sme_send_2040_bss_coex(wpa_s, chan_list, num_channels, num_intol); | |
1955 | return 1; | |
1956 | } | |
1957 | ||
1958 | ||
d97a3c48 JM |
1959 | static void wpa_obss_scan_freqs_list(struct wpa_supplicant *wpa_s, |
1960 | struct wpa_driver_scan_params *params) | |
6434ad09 | 1961 | { |
d97a3c48 | 1962 | /* Include only affected channels */ |
6434ad09 JM |
1963 | struct hostapd_hw_modes *mode; |
1964 | int count, i; | |
d97a3c48 | 1965 | int start, end; |
6434ad09 | 1966 | |
d97a3c48 JM |
1967 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
1968 | HOSTAPD_MODE_IEEE80211G); | |
6434ad09 JM |
1969 | if (mode == NULL) { |
1970 | /* No channels supported in this band - use empty list */ | |
1971 | params->freqs = os_zalloc(sizeof(int)); | |
1972 | return; | |
1973 | } | |
1974 | ||
d97a3c48 JM |
1975 | if (wpa_s->sme.ht_sec_chan == HT_SEC_CHAN_UNKNOWN && |
1976 | wpa_s->current_bss) { | |
1977 | const u8 *ie; | |
1978 | ||
1979 | ie = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_HT_OPERATION); | |
1980 | if (ie && ie[1] >= 2) { | |
1981 | u8 o; | |
1982 | ||
1983 | o = ie[3] & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK; | |
1984 | if (o == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE) | |
1985 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE; | |
1986 | else if (o == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW) | |
1987 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW; | |
1988 | } | |
1989 | } | |
1990 | ||
1991 | start = wpa_s->assoc_freq - 10; | |
1992 | end = wpa_s->assoc_freq + 10; | |
1993 | switch (wpa_s->sme.ht_sec_chan) { | |
1994 | case HT_SEC_CHAN_UNKNOWN: | |
1995 | /* HT40+ possible on channels 1..9 */ | |
1996 | if (wpa_s->assoc_freq <= 2452) | |
1997 | start -= 20; | |
1998 | /* HT40- possible on channels 5-13 */ | |
1999 | if (wpa_s->assoc_freq >= 2432) | |
2000 | end += 20; | |
2001 | break; | |
2002 | case HT_SEC_CHAN_ABOVE: | |
2003 | end += 20; | |
2004 | break; | |
2005 | case HT_SEC_CHAN_BELOW: | |
2006 | start -= 20; | |
2007 | break; | |
2008 | } | |
2009 | wpa_printf(MSG_DEBUG, | |
2010 | "OBSS: assoc_freq %d possible affected range %d-%d", | |
2011 | wpa_s->assoc_freq, start, end); | |
2012 | ||
f9884c09 | 2013 | params->freqs = os_calloc(mode->num_channels + 1, sizeof(int)); |
6434ad09 JM |
2014 | if (params->freqs == NULL) |
2015 | return; | |
2016 | for (count = 0, i = 0; i < mode->num_channels; i++) { | |
d97a3c48 JM |
2017 | int freq; |
2018 | ||
6434ad09 JM |
2019 | if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED) |
2020 | continue; | |
d97a3c48 JM |
2021 | freq = mode->channels[i].freq; |
2022 | if (freq - 10 >= end || freq + 10 <= start) | |
2023 | continue; /* not affected */ | |
2024 | params->freqs[count++] = freq; | |
6434ad09 JM |
2025 | } |
2026 | } | |
2027 | ||
2028 | ||
c3701c66 RM |
2029 | static void sme_obss_scan_timeout(void *eloop_ctx, void *timeout_ctx) |
2030 | { | |
2031 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
2032 | struct wpa_driver_scan_params params; | |
2033 | ||
2034 | if (!wpa_s->current_bss) { | |
2035 | wpa_printf(MSG_DEBUG, "SME OBSS: Ignore scan request"); | |
2036 | return; | |
2037 | } | |
2038 | ||
2039 | os_memset(¶ms, 0, sizeof(params)); | |
d97a3c48 | 2040 | wpa_obss_scan_freqs_list(wpa_s, ¶ms); |
57a8f8af | 2041 | params.low_priority = 1; |
c3701c66 RM |
2042 | wpa_printf(MSG_DEBUG, "SME OBSS: Request an OBSS scan"); |
2043 | ||
2044 | if (wpa_supplicant_trigger_scan(wpa_s, ¶ms)) | |
2045 | wpa_printf(MSG_DEBUG, "SME OBSS: Failed to trigger scan"); | |
2046 | else | |
2047 | wpa_s->sme.sched_obss_scan = 1; | |
6434ad09 | 2048 | os_free(params.freqs); |
c3701c66 RM |
2049 | |
2050 | eloop_register_timeout(wpa_s->sme.obss_scan_int, 0, | |
2051 | sme_obss_scan_timeout, wpa_s, NULL); | |
2052 | } | |
2053 | ||
2054 | ||
2055 | void sme_sched_obss_scan(struct wpa_supplicant *wpa_s, int enable) | |
2056 | { | |
2057 | const u8 *ie; | |
2058 | struct wpa_bss *bss = wpa_s->current_bss; | |
2059 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
b6871ebb AN |
2060 | struct hostapd_hw_modes *hw_mode = NULL; |
2061 | int i; | |
c3701c66 RM |
2062 | |
2063 | eloop_cancel_timeout(sme_obss_scan_timeout, wpa_s, NULL); | |
2064 | wpa_s->sme.sched_obss_scan = 0; | |
d97a3c48 | 2065 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN; |
c3701c66 RM |
2066 | if (!enable) |
2067 | return; | |
2068 | ||
368b1957 AK |
2069 | /* |
2070 | * Schedule OBSS scan if driver is using station SME in wpa_supplicant | |
2071 | * or it expects OBSS scan to be performed by wpa_supplicant. | |
2072 | */ | |
2073 | if (!((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) || | |
2074 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OBSS_SCAN)) || | |
2075 | ssid == NULL || ssid->mode != IEEE80211_MODE_INFRA) | |
2076 | return; | |
c3701c66 | 2077 | |
b6871ebb AN |
2078 | if (!wpa_s->hw.modes) |
2079 | return; | |
2080 | ||
2081 | /* only HT caps in 11g mode are relevant */ | |
2082 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
2083 | hw_mode = &wpa_s->hw.modes[i]; | |
2084 | if (hw_mode->mode == HOSTAPD_MODE_IEEE80211G) | |
2085 | break; | |
2086 | } | |
2087 | ||
2088 | /* Driver does not support HT40 for 11g or doesn't have 11g. */ | |
2089 | if (i == wpa_s->hw.num_modes || !hw_mode || | |
2090 | !(hw_mode->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) | |
2091 | return; | |
c3701c66 RM |
2092 | |
2093 | if (bss == NULL || bss->freq < 2400 || bss->freq > 2500) | |
2094 | return; /* Not associated on 2.4 GHz band */ | |
2095 | ||
2096 | /* Check whether AP supports HT40 */ | |
2097 | ie = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_HT_CAP); | |
2098 | if (!ie || ie[1] < 2 || | |
2099 | !(WPA_GET_LE16(ie + 2) & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) | |
2100 | return; /* AP does not support HT40 */ | |
2101 | ||
2102 | ie = wpa_bss_get_ie(wpa_s->current_bss, | |
2103 | WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS); | |
2104 | if (!ie || ie[1] < 14) | |
2105 | return; /* AP does not request OBSS scans */ | |
2106 | ||
2107 | wpa_s->sme.obss_scan_int = WPA_GET_LE16(ie + 6); | |
2108 | if (wpa_s->sme.obss_scan_int < 10) { | |
2109 | wpa_printf(MSG_DEBUG, "SME: Invalid OBSS Scan Interval %u " | |
2110 | "replaced with the minimum 10 sec", | |
2111 | wpa_s->sme.obss_scan_int); | |
2112 | wpa_s->sme.obss_scan_int = 10; | |
2113 | } | |
2114 | wpa_printf(MSG_DEBUG, "SME: OBSS Scan Interval %u sec", | |
2115 | wpa_s->sme.obss_scan_int); | |
2116 | eloop_register_timeout(wpa_s->sme.obss_scan_int, 0, | |
2117 | sme_obss_scan_timeout, wpa_s, NULL); | |
e29853bb BG |
2118 | } |
2119 | ||
2120 | ||
7d878ca7 JM |
2121 | #ifdef CONFIG_IEEE80211W |
2122 | ||
2123 | static const unsigned int sa_query_max_timeout = 1000; | |
2124 | static const unsigned int sa_query_retry_timeout = 201; | |
2125 | ||
2126 | static int sme_check_sa_query_timeout(struct wpa_supplicant *wpa_s) | |
2127 | { | |
2128 | u32 tu; | |
46b8d4c0 JB |
2129 | struct os_reltime now, passed; |
2130 | os_get_reltime(&now); | |
2131 | os_reltime_sub(&now, &wpa_s->sme.sa_query_start, &passed); | |
7d878ca7 JM |
2132 | tu = (passed.sec * 1000000 + passed.usec) / 1024; |
2133 | if (sa_query_max_timeout < tu) { | |
f049052b | 2134 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: SA Query timed out"); |
7d878ca7 JM |
2135 | sme_stop_sa_query(wpa_s); |
2136 | wpa_supplicant_deauthenticate( | |
2137 | wpa_s, WLAN_REASON_PREV_AUTH_NOT_VALID); | |
2138 | return 1; | |
2139 | } | |
2140 | ||
2141 | return 0; | |
2142 | } | |
2143 | ||
2144 | ||
2145 | static void sme_send_sa_query_req(struct wpa_supplicant *wpa_s, | |
2146 | const u8 *trans_id) | |
2147 | { | |
2148 | u8 req[2 + WLAN_SA_QUERY_TR_ID_LEN]; | |
f049052b BG |
2149 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Sending SA Query Request to " |
2150 | MACSTR, MAC2STR(wpa_s->bssid)); | |
7d878ca7 JM |
2151 | wpa_hexdump(MSG_DEBUG, "SME: SA Query Transaction ID", |
2152 | trans_id, WLAN_SA_QUERY_TR_ID_LEN); | |
2153 | req[0] = WLAN_ACTION_SA_QUERY; | |
2154 | req[1] = WLAN_SA_QUERY_REQUEST; | |
2155 | os_memcpy(req + 2, trans_id, WLAN_SA_QUERY_TR_ID_LEN); | |
190b9062 | 2156 | if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
7d878ca7 | 2157 | wpa_s->own_addr, wpa_s->bssid, |
b106173a | 2158 | req, sizeof(req), 0) < 0) |
f049052b BG |
2159 | wpa_msg(wpa_s, MSG_INFO, "SME: Failed to send SA Query " |
2160 | "Request"); | |
7d878ca7 JM |
2161 | } |
2162 | ||
2163 | ||
2164 | static void sme_sa_query_timer(void *eloop_ctx, void *timeout_ctx) | |
2165 | { | |
2166 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
2167 | unsigned int timeout, sec, usec; | |
2168 | u8 *trans_id, *nbuf; | |
2169 | ||
2170 | if (wpa_s->sme.sa_query_count > 0 && | |
2171 | sme_check_sa_query_timeout(wpa_s)) | |
2172 | return; | |
2173 | ||
067ffa26 JM |
2174 | nbuf = os_realloc_array(wpa_s->sme.sa_query_trans_id, |
2175 | wpa_s->sme.sa_query_count + 1, | |
2176 | WLAN_SA_QUERY_TR_ID_LEN); | |
f8608fab JM |
2177 | if (nbuf == NULL) { |
2178 | sme_stop_sa_query(wpa_s); | |
7d878ca7 | 2179 | return; |
f8608fab | 2180 | } |
7d878ca7 JM |
2181 | if (wpa_s->sme.sa_query_count == 0) { |
2182 | /* Starting a new SA Query procedure */ | |
46b8d4c0 | 2183 | os_get_reltime(&wpa_s->sme.sa_query_start); |
7d878ca7 JM |
2184 | } |
2185 | trans_id = nbuf + wpa_s->sme.sa_query_count * WLAN_SA_QUERY_TR_ID_LEN; | |
2186 | wpa_s->sme.sa_query_trans_id = nbuf; | |
2187 | wpa_s->sme.sa_query_count++; | |
2188 | ||
cb5ef952 JM |
2189 | if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) { |
2190 | wpa_printf(MSG_DEBUG, "Could not generate SA Query ID"); | |
f8608fab | 2191 | sme_stop_sa_query(wpa_s); |
cb5ef952 JM |
2192 | return; |
2193 | } | |
7d878ca7 JM |
2194 | |
2195 | timeout = sa_query_retry_timeout; | |
2196 | sec = ((timeout / 1000) * 1024) / 1000; | |
2197 | usec = (timeout % 1000) * 1024; | |
2198 | eloop_register_timeout(sec, usec, sme_sa_query_timer, wpa_s, NULL); | |
2199 | ||
f049052b BG |
2200 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Association SA Query attempt %d", |
2201 | wpa_s->sme.sa_query_count); | |
7d878ca7 JM |
2202 | |
2203 | sme_send_sa_query_req(wpa_s, trans_id); | |
2204 | } | |
2205 | ||
2206 | ||
2207 | static void sme_start_sa_query(struct wpa_supplicant *wpa_s) | |
2208 | { | |
2209 | sme_sa_query_timer(wpa_s, NULL); | |
2210 | } | |
2211 | ||
2212 | ||
19df9b07 | 2213 | static void sme_stop_sa_query(struct wpa_supplicant *wpa_s) |
7d878ca7 JM |
2214 | { |
2215 | eloop_cancel_timeout(sme_sa_query_timer, wpa_s, NULL); | |
2216 | os_free(wpa_s->sme.sa_query_trans_id); | |
2217 | wpa_s->sme.sa_query_trans_id = NULL; | |
2218 | wpa_s->sme.sa_query_count = 0; | |
2219 | } | |
2220 | ||
2221 | ||
2222 | void sme_event_unprot_disconnect(struct wpa_supplicant *wpa_s, const u8 *sa, | |
2223 | const u8 *da, u16 reason_code) | |
2224 | { | |
2225 | struct wpa_ssid *ssid; | |
3302b7c2 | 2226 | struct os_reltime now; |
7d878ca7 | 2227 | |
7d878ca7 JM |
2228 | if (wpa_s->wpa_state != WPA_COMPLETED) |
2229 | return; | |
2230 | ssid = wpa_s->current_ssid; | |
3f56a2b7 | 2231 | if (wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION) |
7d878ca7 JM |
2232 | return; |
2233 | if (os_memcmp(sa, wpa_s->bssid, ETH_ALEN) != 0) | |
2234 | return; | |
2235 | if (reason_code != WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA && | |
2236 | reason_code != WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA) | |
2237 | return; | |
2238 | if (wpa_s->sme.sa_query_count > 0) | |
2239 | return; | |
2240 | ||
3302b7c2 JM |
2241 | os_get_reltime(&now); |
2242 | if (wpa_s->sme.last_unprot_disconnect.sec && | |
2243 | !os_reltime_expired(&now, &wpa_s->sme.last_unprot_disconnect, 10)) | |
2244 | return; /* limit SA Query procedure frequency */ | |
2245 | wpa_s->sme.last_unprot_disconnect = now; | |
2246 | ||
f049052b BG |
2247 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Unprotected disconnect dropped - " |
2248 | "possible AP/STA state mismatch - trigger SA Query"); | |
7d878ca7 JM |
2249 | sme_start_sa_query(wpa_s); |
2250 | } | |
2251 | ||
2252 | ||
2253 | void sme_sa_query_rx(struct wpa_supplicant *wpa_s, const u8 *sa, | |
2254 | const u8 *data, size_t len) | |
2255 | { | |
2256 | int i; | |
2257 | ||
2258 | if (wpa_s->sme.sa_query_trans_id == NULL || | |
2259 | len < 1 + WLAN_SA_QUERY_TR_ID_LEN || | |
2260 | data[0] != WLAN_SA_QUERY_RESPONSE) | |
2261 | return; | |
f049052b BG |
2262 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Received SA Query response from " |
2263 | MACSTR " (trans_id %02x%02x)", MAC2STR(sa), data[1], data[2]); | |
7d878ca7 JM |
2264 | |
2265 | if (os_memcmp(sa, wpa_s->bssid, ETH_ALEN) != 0) | |
2266 | return; | |
2267 | ||
2268 | for (i = 0; i < wpa_s->sme.sa_query_count; i++) { | |
2269 | if (os_memcmp(wpa_s->sme.sa_query_trans_id + | |
2270 | i * WLAN_SA_QUERY_TR_ID_LEN, | |
2271 | data + 1, WLAN_SA_QUERY_TR_ID_LEN) == 0) | |
2272 | break; | |
2273 | } | |
2274 | ||
2275 | if (i >= wpa_s->sme.sa_query_count) { | |
f049052b BG |
2276 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: No matching SA Query " |
2277 | "transaction identifier found"); | |
7d878ca7 JM |
2278 | return; |
2279 | } | |
2280 | ||
f049052b BG |
2281 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Reply to pending SA Query received " |
2282 | "from " MACSTR, MAC2STR(sa)); | |
7d878ca7 JM |
2283 | sme_stop_sa_query(wpa_s); |
2284 | } | |
2285 | ||
2286 | #endif /* CONFIG_IEEE80211W */ |