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