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