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