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