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