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