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