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