]>
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]; | |
70 | if (group < 0) | |
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 | ||
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_printf(MSG_DEBUG, | |
168 | "RRM: Insufficient RRM support in driver - do not use RRM"); | |
169 | return; | |
170 | } | |
171 | ||
849367af JM |
172 | if (sizeof(wpa_s->sme.assoc_req_ie) < |
173 | wpa_s->sme.assoc_req_ie_len + rrm_ie_len + 2) { | |
b361d580 AK |
174 | wpa_printf(MSG_INFO, |
175 | "RRM: Unable to use RRM, no room for RRM IE"); | |
176 | return; | |
177 | } | |
178 | ||
179 | wpa_printf(MSG_DEBUG, "RRM: Adding RRM IE to Association Request"); | |
180 | pos = wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len; | |
b361d580 AK |
181 | os_memset(pos, 0, 2 + rrm_ie_len); |
182 | *pos++ = WLAN_EID_RRM_ENABLED_CAPABILITIES; | |
183 | *pos++ = rrm_ie_len; | |
70d1e728 AO |
184 | |
185 | /* Set supported capabilites flags */ | |
186 | if (wpa_s->drv_rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) | |
187 | *pos |= WLAN_RRM_CAPS_LINK_MEASUREMENT; | |
188 | ||
b361d580 AK |
189 | wpa_s->sme.assoc_req_ie_len += rrm_ie_len + 2; |
190 | wpa_s->rrm.rrm_used = 1; | |
191 | } | |
192 | ||
193 | ||
215ae884 JM |
194 | static void sme_send_authentication(struct wpa_supplicant *wpa_s, |
195 | struct wpa_bss *bss, struct wpa_ssid *ssid, | |
196 | int start) | |
c2a04078 JM |
197 | { |
198 | struct wpa_driver_auth_params params; | |
8bac466b | 199 | struct wpa_ssid *old_ssid; |
fdbe50ed | 200 | #ifdef CONFIG_IEEE80211R |
c2a04078 | 201 | const u8 *ie; |
fdbe50ed | 202 | #endif /* CONFIG_IEEE80211R */ |
c2a04078 JM |
203 | #ifdef CONFIG_IEEE80211R |
204 | const u8 *md = NULL; | |
205 | #endif /* CONFIG_IEEE80211R */ | |
8bac466b | 206 | int i, bssid_changed; |
c10347f2 | 207 | struct wpabuf *resp = NULL; |
0bbaa9b9 | 208 | u8 ext_capab[18]; |
03e47c9c | 209 | int ext_capab_len; |
c2a04078 JM |
210 | |
211 | if (bss == NULL) { | |
f049052b BG |
212 | wpa_msg(wpa_s, MSG_ERROR, "SME: No scan result available for " |
213 | "the network"); | |
6ac4b15e | 214 | wpas_connect_work_done(wpa_s); |
c2a04078 JM |
215 | return; |
216 | } | |
217 | ||
8f770587 JM |
218 | wpa_s->current_bss = bss; |
219 | ||
c2a04078 JM |
220 | os_memset(¶ms, 0, sizeof(params)); |
221 | wpa_s->reassociate = 0; | |
222 | ||
223 | params.freq = bss->freq; | |
224 | params.bssid = bss->bssid; | |
6fa81a3b JM |
225 | params.ssid = bss->ssid; |
226 | params.ssid_len = bss->ssid_len; | |
2f4f73b1 | 227 | params.p2p = ssid->p2p_group; |
c2a04078 | 228 | |
62fa124c JM |
229 | if (wpa_s->sme.ssid_len != params.ssid_len || |
230 | os_memcmp(wpa_s->sme.ssid, params.ssid, params.ssid_len) != 0) | |
231 | wpa_s->sme.prev_bssid_set = 0; | |
232 | ||
c2a04078 JM |
233 | wpa_s->sme.freq = params.freq; |
234 | os_memcpy(wpa_s->sme.ssid, params.ssid, params.ssid_len); | |
235 | wpa_s->sme.ssid_len = params.ssid_len; | |
236 | ||
abd9fafa | 237 | params.auth_alg = WPA_AUTH_ALG_OPEN; |
c2a04078 JM |
238 | #ifdef IEEE8021X_EAPOL |
239 | if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) { | |
240 | if (ssid->leap) { | |
241 | if (ssid->non_leap == 0) | |
abd9fafa | 242 | params.auth_alg = WPA_AUTH_ALG_LEAP; |
c2a04078 | 243 | else |
abd9fafa | 244 | params.auth_alg |= WPA_AUTH_ALG_LEAP; |
c2a04078 JM |
245 | } |
246 | } | |
247 | #endif /* IEEE8021X_EAPOL */ | |
f049052b BG |
248 | wpa_dbg(wpa_s, MSG_DEBUG, "Automatic auth_alg selection: 0x%x", |
249 | params.auth_alg); | |
c2a04078 | 250 | if (ssid->auth_alg) { |
abd9fafa | 251 | params.auth_alg = ssid->auth_alg; |
f049052b BG |
252 | wpa_dbg(wpa_s, MSG_DEBUG, "Overriding auth_alg selection: " |
253 | "0x%x", params.auth_alg); | |
c2a04078 | 254 | } |
c10347f2 | 255 | #ifdef CONFIG_SAE |
bc26ac50 | 256 | wpa_s->sme.sae_pmksa_caching = 0; |
c10347f2 JM |
257 | if (wpa_key_mgmt_sae(ssid->key_mgmt)) { |
258 | const u8 *rsn; | |
259 | struct wpa_ie_data ied; | |
260 | ||
261 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); | |
267ac3bc JM |
262 | if (!rsn) { |
263 | wpa_dbg(wpa_s, MSG_DEBUG, | |
264 | "SAE enabled, but target BSS does not advertise RSN"); | |
265 | } else if (wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ied) == 0 && | |
266 | wpa_key_mgmt_sae(ied.key_mgmt)) { | |
267 | wpa_dbg(wpa_s, MSG_DEBUG, "Using SAE auth_alg"); | |
268 | params.auth_alg = WPA_AUTH_ALG_SAE; | |
269 | } else { | |
270 | wpa_dbg(wpa_s, MSG_DEBUG, | |
271 | "SAE enabled, but target BSS does not advertise SAE AKM for RSN"); | |
c10347f2 JM |
272 | } |
273 | } | |
274 | #endif /* CONFIG_SAE */ | |
c2a04078 | 275 | |
a0b2f99b JM |
276 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
277 | if (ssid->wep_key_len[i]) | |
278 | params.wep_key[i] = ssid->wep_key[i]; | |
279 | params.wep_key_len[i] = ssid->wep_key_len[i]; | |
280 | } | |
281 | params.wep_tx_keyidx = ssid->wep_tx_keyidx; | |
282 | ||
8bac466b | 283 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
c2a04078 JM |
284 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
285 | os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN); | |
8bac466b JM |
286 | if (bssid_changed) |
287 | wpas_notify_bssid_changed(wpa_s); | |
c2a04078 | 288 | |
f337f0e9 JM |
289 | if ((wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) || |
290 | wpa_bss_get_ie(bss, WLAN_EID_RSN)) && | |
0bf927a0 | 291 | wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
c2a04078 | 292 | int try_opportunistic; |
6e202021 JM |
293 | try_opportunistic = (ssid->proactive_key_caching < 0 ? |
294 | wpa_s->conf->okc : | |
295 | ssid->proactive_key_caching) && | |
c2a04078 JM |
296 | (ssid->proto & WPA_PROTO_RSN); |
297 | if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid, | |
298 | wpa_s->current_ssid, | |
299 | try_opportunistic) == 0) | |
ba422613 | 300 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol); |
c2a04078 JM |
301 | wpa_s->sme.assoc_req_ie_len = sizeof(wpa_s->sme.assoc_req_ie); |
302 | if (wpa_supplicant_set_suites(wpa_s, bss, ssid, | |
303 | wpa_s->sme.assoc_req_ie, | |
304 | &wpa_s->sme.assoc_req_ie_len)) { | |
f049052b BG |
305 | wpa_msg(wpa_s, MSG_WARNING, "SME: Failed to set WPA " |
306 | "key management and encryption suites"); | |
6ac4b15e | 307 | wpas_connect_work_done(wpa_s); |
c2a04078 JM |
308 | return; |
309 | } | |
a3f7e518 JM |
310 | } else if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && |
311 | wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt)) { | |
312 | /* | |
313 | * Both WPA and non-WPA IEEE 802.1X enabled in configuration - | |
314 | * use non-WPA since the scan results did not indicate that the | |
315 | * AP is using WPA or WPA2. | |
316 | */ | |
317 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
318 | wpa_s->sme.assoc_req_ie_len = 0; | |
0bf927a0 | 319 | } else if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { |
c2a04078 JM |
320 | wpa_s->sme.assoc_req_ie_len = sizeof(wpa_s->sme.assoc_req_ie); |
321 | if (wpa_supplicant_set_suites(wpa_s, NULL, ssid, | |
322 | wpa_s->sme.assoc_req_ie, | |
323 | &wpa_s->sme.assoc_req_ie_len)) { | |
f049052b BG |
324 | wpa_msg(wpa_s, MSG_WARNING, "SME: Failed to set WPA " |
325 | "key management and encryption suites (no " | |
326 | "scan results)"); | |
6ac4b15e | 327 | wpas_connect_work_done(wpa_s); |
c2a04078 JM |
328 | return; |
329 | } | |
330 | #ifdef CONFIG_WPS | |
331 | } else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) { | |
332 | struct wpabuf *wps_ie; | |
333 | wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid)); | |
334 | if (wps_ie && wpabuf_len(wps_ie) <= | |
335 | sizeof(wpa_s->sme.assoc_req_ie)) { | |
336 | wpa_s->sme.assoc_req_ie_len = wpabuf_len(wps_ie); | |
337 | os_memcpy(wpa_s->sme.assoc_req_ie, wpabuf_head(wps_ie), | |
338 | wpa_s->sme.assoc_req_ie_len); | |
339 | } else | |
340 | wpa_s->sme.assoc_req_ie_len = 0; | |
341 | wpabuf_free(wps_ie); | |
342 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
343 | #endif /* CONFIG_WPS */ | |
344 | } else { | |
345 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); | |
346 | wpa_s->sme.assoc_req_ie_len = 0; | |
347 | } | |
348 | ||
349 | #ifdef CONFIG_IEEE80211R | |
6fa81a3b | 350 | ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); |
c2a04078 JM |
351 | if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN) |
352 | md = ie + 2; | |
e7846b68 | 353 | wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0); |
c2a04078 JM |
354 | if (md) { |
355 | /* Prepare for the next transition */ | |
76b7981d | 356 | wpa_ft_prepare_auth_request(wpa_s->wpa, ie); |
c2a04078 JM |
357 | } |
358 | ||
0bf927a0 | 359 | if (md && wpa_key_mgmt_ft(ssid->key_mgmt)) { |
c2a04078 JM |
360 | if (wpa_s->sme.assoc_req_ie_len + 5 < |
361 | sizeof(wpa_s->sme.assoc_req_ie)) { | |
362 | struct rsn_mdie *mdie; | |
363 | u8 *pos = wpa_s->sme.assoc_req_ie + | |
364 | wpa_s->sme.assoc_req_ie_len; | |
365 | *pos++ = WLAN_EID_MOBILITY_DOMAIN; | |
366 | *pos++ = sizeof(*mdie); | |
367 | mdie = (struct rsn_mdie *) pos; | |
368 | os_memcpy(mdie->mobility_domain, md, | |
369 | MOBILITY_DOMAIN_ID_LEN); | |
f4ec630d | 370 | mdie->ft_capab = md[MOBILITY_DOMAIN_ID_LEN]; |
c2a04078 JM |
371 | wpa_s->sme.assoc_req_ie_len += 5; |
372 | } | |
373 | ||
374 | if (wpa_s->sme.ft_used && | |
0d7b4409 JM |
375 | os_memcmp(md, wpa_s->sme.mobility_domain, 2) == 0 && |
376 | wpa_sm_has_ptk(wpa_s->wpa)) { | |
f049052b BG |
377 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Trying to use FT " |
378 | "over-the-air"); | |
abd9fafa | 379 | params.auth_alg = WPA_AUTH_ALG_FT; |
c2a04078 JM |
380 | params.ie = wpa_s->sme.ft_ies; |
381 | params.ie_len = wpa_s->sme.ft_ies_len; | |
382 | } | |
383 | } | |
384 | #endif /* CONFIG_IEEE80211R */ | |
385 | ||
386 | #ifdef CONFIG_IEEE80211W | |
3f56a2b7 | 387 | wpa_s->sme.mfp = wpas_get_ssid_pmf(wpa_s, ssid); |
62d49803 | 388 | if (wpa_s->sme.mfp != NO_MGMT_FRAME_PROTECTION) { |
6fa81a3b | 389 | const u8 *rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
c2a04078 JM |
390 | struct wpa_ie_data _ie; |
391 | if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &_ie) == 0 && | |
392 | _ie.capabilities & | |
393 | (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) { | |
f049052b BG |
394 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Selected AP supports " |
395 | "MFP: require MFP"); | |
c2a04078 JM |
396 | wpa_s->sme.mfp = MGMT_FRAME_PROTECTION_REQUIRED; |
397 | } | |
398 | } | |
399 | #endif /* CONFIG_IEEE80211W */ | |
400 | ||
5f3a6aa0 JM |
401 | #ifdef CONFIG_P2P |
402 | if (wpa_s->global->p2p) { | |
403 | u8 *pos; | |
404 | size_t len; | |
405 | int res; | |
5f3a6aa0 JM |
406 | pos = wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len; |
407 | len = sizeof(wpa_s->sme.assoc_req_ie) - | |
408 | wpa_s->sme.assoc_req_ie_len; | |
ffad8858 JM |
409 | res = wpas_p2p_assoc_req_ie(wpa_s, bss, pos, len, |
410 | ssid->p2p_group); | |
5f3a6aa0 JM |
411 | if (res >= 0) |
412 | wpa_s->sme.assoc_req_ie_len += res; | |
413 | } | |
414 | #endif /* CONFIG_P2P */ | |
415 | ||
cb418324 | 416 | #ifdef CONFIG_HS20 |
55a2df43 | 417 | if (is_hs20_network(wpa_s, ssid, bss)) { |
cb418324 JM |
418 | struct wpabuf *hs20; |
419 | hs20 = wpabuf_alloc(20); | |
420 | if (hs20) { | |
f9cd147d | 421 | int pps_mo_id = hs20_get_pps_mo_id(wpa_s, ssid); |
745ef184 JM |
422 | size_t len; |
423 | ||
f9cd147d | 424 | wpas_hs20_add_indication(hs20, pps_mo_id); |
745ef184 JM |
425 | len = sizeof(wpa_s->sme.assoc_req_ie) - |
426 | wpa_s->sme.assoc_req_ie_len; | |
427 | if (wpabuf_len(hs20) <= len) { | |
428 | os_memcpy(wpa_s->sme.assoc_req_ie + | |
429 | wpa_s->sme.assoc_req_ie_len, | |
430 | wpabuf_head(hs20), wpabuf_len(hs20)); | |
431 | wpa_s->sme.assoc_req_ie_len += wpabuf_len(hs20); | |
432 | } | |
cb418324 JM |
433 | wpabuf_free(hs20); |
434 | } | |
435 | } | |
436 | #endif /* CONFIG_HS20 */ | |
437 | ||
0bbaa9b9 JM |
438 | ext_capab_len = wpas_build_ext_capab(wpa_s, ext_capab, |
439 | sizeof(ext_capab)); | |
03e47c9c | 440 | if (ext_capab_len > 0) { |
92cbcf91 JM |
441 | u8 *pos = wpa_s->sme.assoc_req_ie; |
442 | if (wpa_s->sme.assoc_req_ie_len > 0 && pos[0] == WLAN_EID_RSN) | |
443 | pos += 2 + pos[1]; | |
03e47c9c | 444 | os_memmove(pos + ext_capab_len, pos, |
92cbcf91 JM |
445 | wpa_s->sme.assoc_req_ie_len - |
446 | (pos - wpa_s->sme.assoc_req_ie)); | |
03e47c9c JM |
447 | wpa_s->sme.assoc_req_ie_len += ext_capab_len; |
448 | os_memcpy(pos, ext_capab, ext_capab_len); | |
92cbcf91 | 449 | } |
92cbcf91 | 450 | |
d29fa3a7 JM |
451 | if (wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]) { |
452 | struct wpabuf *buf = wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]; | |
453 | size_t len; | |
454 | ||
455 | len = sizeof(wpa_s->sme.assoc_req_ie) - | |
456 | wpa_s->sme.assoc_req_ie_len; | |
457 | if (wpabuf_len(buf) <= len) { | |
458 | os_memcpy(wpa_s->sme.assoc_req_ie + | |
459 | wpa_s->sme.assoc_req_ie_len, | |
460 | wpabuf_head(buf), wpabuf_len(buf)); | |
461 | wpa_s->sme.assoc_req_ie_len += wpabuf_len(buf); | |
462 | } | |
463 | } | |
464 | ||
b361d580 AK |
465 | sme_auth_handle_rrm(wpa_s, bss); |
466 | ||
c10347f2 | 467 | #ifdef CONFIG_SAE |
bc26ac50 JM |
468 | if (params.auth_alg == WPA_AUTH_ALG_SAE && |
469 | pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid, ssid, 0) == 0) | |
470 | { | |
471 | wpa_dbg(wpa_s, MSG_DEBUG, | |
472 | "PMKSA cache entry found - try to use PMKSA caching instead of new SAE authentication"); | |
473 | params.auth_alg = WPA_AUTH_ALG_OPEN; | |
474 | wpa_s->sme.sae_pmksa_caching = 1; | |
475 | } | |
476 | ||
c10347f2 JM |
477 | if (params.auth_alg == WPA_AUTH_ALG_SAE) { |
478 | if (start) | |
8e31e955 JM |
479 | resp = sme_auth_build_sae_commit(wpa_s, ssid, |
480 | bss->bssid); | |
c10347f2 JM |
481 | else |
482 | resp = sme_auth_build_sae_confirm(wpa_s); | |
6ac4b15e | 483 | if (resp == NULL) { |
81648d00 | 484 | wpas_connection_failed(wpa_s, bss->bssid); |
c10347f2 | 485 | return; |
6ac4b15e | 486 | } |
c10347f2 JM |
487 | params.sae_data = wpabuf_head(resp); |
488 | params.sae_data_len = wpabuf_len(resp); | |
dd43026a | 489 | wpa_s->sme.sae.state = start ? SAE_COMMITTED : SAE_CONFIRMED; |
c10347f2 JM |
490 | } |
491 | #endif /* CONFIG_SAE */ | |
492 | ||
a4cba8f1 | 493 | wpa_supplicant_cancel_sched_scan(wpa_s); |
c2a04078 JM |
494 | wpa_supplicant_cancel_scan(wpa_s); |
495 | ||
f049052b | 496 | wpa_msg(wpa_s, MSG_INFO, "SME: Trying to authenticate with " MACSTR |
c2a04078 JM |
497 | " (SSID='%s' freq=%d MHz)", MAC2STR(params.bssid), |
498 | wpa_ssid_txt(params.ssid, params.ssid_len), params.freq); | |
499 | ||
500 | wpa_clear_keys(wpa_s, bss->bssid); | |
501 | wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING); | |
8bac466b | 502 | old_ssid = wpa_s->current_ssid; |
c2a04078 JM |
503 | wpa_s->current_ssid = ssid; |
504 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); | |
505 | wpa_supplicant_initiate_eapol(wpa_s); | |
8bac466b JM |
506 | if (old_ssid != wpa_s->current_ssid) |
507 | wpas_notify_network_changed(wpa_s); | |
c2a04078 | 508 | |
d0df6437 IP |
509 | #ifdef CONFIG_P2P |
510 | /* | |
511 | * If multi-channel concurrency is not supported, check for any | |
512 | * frequency conflict. In case of any frequency conflict, remove the | |
513 | * least prioritized connection. | |
514 | */ | |
515 | if (wpa_s->num_multichan_concurrent < 2) { | |
516 | int freq, num; | |
517 | num = get_shared_radio_freqs(wpa_s, &freq, 1); | |
518 | if (num > 0 && freq > 0 && freq != params.freq) { | |
519 | wpa_printf(MSG_DEBUG, | |
520 | "Conflicting frequency found (%d != %d)", | |
521 | freq, params.freq); | |
522 | if (wpas_p2p_handle_frequency_conflicts(wpa_s, | |
523 | params.freq, | |
524 | ssid) < 0) { | |
525 | wpas_connection_failed(wpa_s, bss->bssid); | |
526 | wpa_supplicant_mark_disassoc(wpa_s); | |
527 | wpabuf_free(resp); | |
528 | wpas_connect_work_done(wpa_s); | |
529 | return; | |
530 | } | |
531 | } | |
532 | } | |
533 | #endif /* CONFIG_P2P */ | |
534 | ||
62c72d72 | 535 | wpa_s->sme.auth_alg = params.auth_alg; |
c2a04078 | 536 | if (wpa_drv_authenticate(wpa_s, ¶ms) < 0) { |
f049052b | 537 | wpa_msg(wpa_s, MSG_INFO, "SME: Authentication request to the " |
c2a04078 | 538 | "driver failed"); |
ed57c590 | 539 | wpas_connection_failed(wpa_s, bss->bssid); |
1193dc8f | 540 | wpa_supplicant_mark_disassoc(wpa_s); |
c10347f2 | 541 | wpabuf_free(resp); |
6ac4b15e | 542 | wpas_connect_work_done(wpa_s); |
c2a04078 JM |
543 | return; |
544 | } | |
545 | ||
e29853bb BG |
546 | eloop_register_timeout(SME_AUTH_TIMEOUT, 0, sme_auth_timer, wpa_s, |
547 | NULL); | |
c2a04078 JM |
548 | |
549 | /* | |
550 | * Association will be started based on the authentication event from | |
551 | * the driver. | |
552 | */ | |
c10347f2 JM |
553 | |
554 | wpabuf_free(resp); | |
555 | } | |
556 | ||
557 | ||
6ac4b15e JM |
558 | static void sme_auth_start_cb(struct wpa_radio_work *work, int deinit) |
559 | { | |
560 | struct wpa_connect_work *cwork = work->ctx; | |
561 | struct wpa_supplicant *wpa_s = work->wpa_s; | |
562 | ||
563 | if (deinit) { | |
b3253ebb AO |
564 | if (work->started) |
565 | wpa_s->connect_work = NULL; | |
566 | ||
6ac4b15e JM |
567 | wpas_connect_work_free(cwork); |
568 | return; | |
569 | } | |
570 | ||
571 | wpa_s->connect_work = work; | |
572 | ||
a7f5271d JM |
573 | if (cwork->bss_removed || |
574 | !wpas_valid_bss_ssid(wpa_s, cwork->bss, cwork->ssid)) { | |
6ac4b15e JM |
575 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: BSS/SSID entry for authentication not valid anymore - drop connection attempt"); |
576 | wpas_connect_work_done(wpa_s); | |
577 | return; | |
578 | } | |
579 | ||
580 | sme_send_authentication(wpa_s, cwork->bss, cwork->ssid, 1); | |
581 | } | |
582 | ||
583 | ||
c10347f2 JM |
584 | void sme_authenticate(struct wpa_supplicant *wpa_s, |
585 | struct wpa_bss *bss, struct wpa_ssid *ssid) | |
586 | { | |
6ac4b15e JM |
587 | struct wpa_connect_work *cwork; |
588 | ||
589 | if (bss == NULL || ssid == NULL) | |
590 | return; | |
591 | if (wpa_s->connect_work) { | |
592 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Reject sme_authenticate() call since connect_work exist"); | |
593 | return; | |
594 | } | |
595 | ||
f0e30c84 | 596 | if (radio_work_pending(wpa_s, "sme-connect")) { |
f1c4dbf5 IP |
597 | /* |
598 | * The previous sme-connect work might no longer be valid due to | |
599 | * the fact that the BSS list was updated. In addition, it makes | |
600 | * sense to adhere to the 'newer' decision. | |
601 | */ | |
602 | wpa_dbg(wpa_s, MSG_DEBUG, | |
603 | "SME: Remove previous pending sme-connect"); | |
604 | radio_remove_works(wpa_s, "sme-connect", 0); | |
f0e30c84 JM |
605 | } |
606 | ||
6ac4b15e JM |
607 | cwork = os_zalloc(sizeof(*cwork)); |
608 | if (cwork == NULL) | |
609 | return; | |
610 | cwork->bss = bss; | |
611 | cwork->ssid = ssid; | |
612 | cwork->sme = 1; | |
613 | ||
98efcc41 | 614 | #ifdef CONFIG_SAE |
dd43026a | 615 | wpa_s->sme.sae.state = SAE_NOTHING; |
98efcc41 | 616 | wpa_s->sme.sae.send_confirm = 0; |
18ca7332 | 617 | wpa_s->sme.sae_group_index = 0; |
98efcc41 | 618 | #endif /* CONFIG_SAE */ |
6ac4b15e JM |
619 | |
620 | if (radio_add_work(wpa_s, bss->freq, "sme-connect", 1, | |
621 | sme_auth_start_cb, cwork) < 0) | |
622 | wpas_connect_work_free(cwork); | |
c2a04078 JM |
623 | } |
624 | ||
625 | ||
c10347f2 | 626 | #ifdef CONFIG_SAE |
21af6d15 | 627 | |
c10347f2 JM |
628 | static int sme_sae_auth(struct wpa_supplicant *wpa_s, u16 auth_transaction, |
629 | u16 status_code, const u8 *data, size_t len) | |
630 | { | |
a959a3b6 MH |
631 | int *groups; |
632 | ||
c10347f2 JM |
633 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: SAE authentication transaction %u " |
634 | "status code %u", auth_transaction, status_code); | |
c10347f2 | 635 | |
d136c376 JM |
636 | if (auth_transaction == 1 && |
637 | status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ && | |
638 | wpa_s->sme.sae.state == SAE_COMMITTED && | |
639 | wpa_s->current_bss && wpa_s->current_ssid) { | |
a959a3b6 MH |
640 | int default_groups[] = { 19, 20, 21, 25, 26, 0 }; |
641 | u16 group; | |
642 | ||
643 | groups = wpa_s->conf->sae_groups; | |
644 | if (!groups || groups[0] <= 0) | |
645 | groups = default_groups; | |
646 | ||
647 | if (len < sizeof(le16)) { | |
648 | wpa_dbg(wpa_s, MSG_DEBUG, | |
649 | "SME: Too short SAE anti-clogging token request"); | |
650 | return -1; | |
651 | } | |
652 | group = WPA_GET_LE16(data); | |
653 | wpa_dbg(wpa_s, MSG_DEBUG, | |
654 | "SME: SAE anti-clogging token requested (group %u)", | |
655 | group); | |
656 | if (sae_group_allowed(&wpa_s->sme.sae, groups, group) != | |
657 | WLAN_STATUS_SUCCESS) { | |
658 | wpa_dbg(wpa_s, MSG_ERROR, | |
659 | "SME: SAE group %u of anti-clogging request is invalid", | |
660 | group); | |
661 | return -1; | |
662 | } | |
d136c376 | 663 | wpabuf_free(wpa_s->sme.sae_token); |
a959a3b6 MH |
664 | wpa_s->sme.sae_token = wpabuf_alloc_copy(data + sizeof(le16), |
665 | len - sizeof(le16)); | |
d136c376 JM |
666 | sme_send_authentication(wpa_s, wpa_s->current_bss, |
667 | wpa_s->current_ssid, 1); | |
668 | return 0; | |
669 | } | |
670 | ||
625f202a JM |
671 | if (auth_transaction == 1 && |
672 | status_code == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED && | |
673 | wpa_s->sme.sae.state == SAE_COMMITTED && | |
674 | wpa_s->current_bss && wpa_s->current_ssid) { | |
675 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: SAE group not supported"); | |
676 | wpa_s->sme.sae_group_index++; | |
677 | if (sme_set_sae_group(wpa_s) < 0) | |
678 | return -1; /* no other groups enabled */ | |
679 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Try next enabled SAE group"); | |
680 | sme_send_authentication(wpa_s, wpa_s->current_bss, | |
681 | wpa_s->current_ssid, 1); | |
682 | return 0; | |
683 | } | |
684 | ||
c10347f2 JM |
685 | if (status_code != WLAN_STATUS_SUCCESS) |
686 | return -1; | |
687 | ||
688 | if (auth_transaction == 1) { | |
a959a3b6 | 689 | groups = wpa_s->conf->sae_groups; |
18ca7332 | 690 | |
c10347f2 JM |
691 | wpa_dbg(wpa_s, MSG_DEBUG, "SME SAE commit"); |
692 | if (wpa_s->current_bss == NULL || | |
693 | wpa_s->current_ssid == NULL) | |
694 | return -1; | |
dd43026a | 695 | if (wpa_s->sme.sae.state != SAE_COMMITTED) |
21af6d15 | 696 | return -1; |
18ca7332 JM |
697 | if (groups && groups[0] <= 0) |
698 | groups = NULL; | |
625f202a | 699 | if (sae_parse_commit(&wpa_s->sme.sae, data, len, NULL, NULL, |
18ca7332 | 700 | groups) != WLAN_STATUS_SUCCESS) |
21af6d15 | 701 | return -1; |
146f6c9a JM |
702 | |
703 | if (sae_process_commit(&wpa_s->sme.sae) < 0) { | |
704 | wpa_printf(MSG_DEBUG, "SAE: Failed to process peer " | |
705 | "commit"); | |
706 | return -1; | |
707 | } | |
708 | ||
d136c376 JM |
709 | wpabuf_free(wpa_s->sme.sae_token); |
710 | wpa_s->sme.sae_token = NULL; | |
c10347f2 JM |
711 | sme_send_authentication(wpa_s, wpa_s->current_bss, |
712 | wpa_s->current_ssid, 0); | |
713 | return 0; | |
714 | } else if (auth_transaction == 2) { | |
715 | wpa_dbg(wpa_s, MSG_DEBUG, "SME SAE confirm"); | |
dd43026a | 716 | if (wpa_s->sme.sae.state != SAE_CONFIRMED) |
21af6d15 | 717 | return -1; |
f2e9818f | 718 | if (sae_check_confirm(&wpa_s->sme.sae, data, len) < 0) |
21af6d15 | 719 | return -1; |
dd43026a | 720 | wpa_s->sme.sae.state = SAE_ACCEPTED; |
b4fd3613 | 721 | sae_clear_temp_data(&wpa_s->sme.sae); |
c10347f2 JM |
722 | return 1; |
723 | } | |
724 | ||
725 | return -1; | |
726 | } | |
727 | #endif /* CONFIG_SAE */ | |
728 | ||
729 | ||
c2a04078 JM |
730 | void sme_event_auth(struct wpa_supplicant *wpa_s, union wpa_event_data *data) |
731 | { | |
c2a04078 JM |
732 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
733 | ||
734 | if (ssid == NULL) { | |
f049052b BG |
735 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Ignore authentication event " |
736 | "when network is not selected"); | |
c2a04078 JM |
737 | return; |
738 | } | |
739 | ||
740 | if (wpa_s->wpa_state != WPA_AUTHENTICATING) { | |
f049052b BG |
741 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Ignore authentication event " |
742 | "when not in authenticating state"); | |
c2a04078 JM |
743 | return; |
744 | } | |
745 | ||
746 | if (os_memcmp(wpa_s->pending_bssid, data->auth.peer, ETH_ALEN) != 0) { | |
f049052b BG |
747 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Ignore authentication with " |
748 | "unexpected peer " MACSTR, | |
749 | MAC2STR(data->auth.peer)); | |
c2a04078 JM |
750 | return; |
751 | } | |
752 | ||
f049052b | 753 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Authentication response: peer=" MACSTR |
c10347f2 | 754 | " auth_type=%d auth_transaction=%d status_code=%d", |
f049052b | 755 | MAC2STR(data->auth.peer), data->auth.auth_type, |
c10347f2 | 756 | data->auth.auth_transaction, data->auth.status_code); |
c2a04078 JM |
757 | wpa_hexdump(MSG_MSGDUMP, "SME: Authentication response IEs", |
758 | data->auth.ies, data->auth.ies_len); | |
759 | ||
e29853bb BG |
760 | eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL); |
761 | ||
c10347f2 JM |
762 | #ifdef CONFIG_SAE |
763 | if (data->auth.auth_type == WLAN_AUTH_SAE) { | |
21af6d15 JM |
764 | int res; |
765 | res = sme_sae_auth(wpa_s, data->auth.auth_transaction, | |
766 | data->auth.status_code, data->auth.ies, | |
767 | data->auth.ies_len); | |
768 | if (res < 0) { | |
769 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); | |
770 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); | |
771 | ||
772 | } | |
773 | if (res != 1) | |
c10347f2 | 774 | return; |
47b55a3e JM |
775 | |
776 | wpa_printf(MSG_DEBUG, "SME: SAE completed - setting PMK for " | |
777 | "4-way handshake"); | |
bc26ac50 JM |
778 | wpa_sm_set_pmk(wpa_s->wpa, wpa_s->sme.sae.pmk, PMK_LEN, |
779 | wpa_s->pending_bssid); | |
c10347f2 JM |
780 | } |
781 | #endif /* CONFIG_SAE */ | |
782 | ||
c2a04078 | 783 | if (data->auth.status_code != WLAN_STATUS_SUCCESS) { |
f049052b BG |
784 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Authentication failed (status " |
785 | "code %d)", data->auth.status_code); | |
cb1583f6 SO |
786 | |
787 | if (data->auth.status_code != | |
788 | WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG || | |
789 | wpa_s->sme.auth_alg == data->auth.auth_type || | |
7e6646c7 | 790 | wpa_s->current_ssid->auth_alg == WPA_AUTH_ALG_LEAP) { |
0fb337c1 | 791 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
c1c02342 | 792 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
cb1583f6 | 793 | return; |
7e6646c7 | 794 | } |
cb1583f6 | 795 | |
d9504779 JM |
796 | wpas_connect_work_done(wpa_s); |
797 | ||
cb1583f6 SO |
798 | switch (data->auth.auth_type) { |
799 | case WLAN_AUTH_OPEN: | |
800 | wpa_s->current_ssid->auth_alg = WPA_AUTH_ALG_SHARED; | |
801 | ||
f049052b | 802 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Trying SHARED auth"); |
cb1583f6 SO |
803 | wpa_supplicant_associate(wpa_s, wpa_s->current_bss, |
804 | wpa_s->current_ssid); | |
805 | return; | |
806 | ||
807 | case WLAN_AUTH_SHARED_KEY: | |
808 | wpa_s->current_ssid->auth_alg = WPA_AUTH_ALG_LEAP; | |
809 | ||
f049052b | 810 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Trying LEAP auth"); |
cb1583f6 SO |
811 | wpa_supplicant_associate(wpa_s, wpa_s->current_bss, |
812 | wpa_s->current_ssid); | |
813 | return; | |
814 | ||
815 | default: | |
816 | return; | |
817 | } | |
c2a04078 JM |
818 | } |
819 | ||
820 | #ifdef CONFIG_IEEE80211R | |
821 | if (data->auth.auth_type == WLAN_AUTH_FT) { | |
822 | union wpa_event_data edata; | |
823 | os_memset(&edata, 0, sizeof(edata)); | |
824 | edata.ft_ies.ies = data->auth.ies; | |
825 | edata.ft_ies.ies_len = data->auth.ies_len; | |
826 | os_memcpy(edata.ft_ies.target_ap, data->auth.peer, ETH_ALEN); | |
827 | wpa_supplicant_event(wpa_s, EVENT_FT_RESPONSE, &edata); | |
828 | } | |
829 | #endif /* CONFIG_IEEE80211R */ | |
830 | ||
71024cb2 JM |
831 | sme_associate(wpa_s, ssid->mode, data->auth.peer, |
832 | data->auth.auth_type); | |
833 | } | |
834 | ||
835 | ||
836 | void sme_associate(struct wpa_supplicant *wpa_s, enum wpas_mode mode, | |
837 | const u8 *bssid, u16 auth_type) | |
838 | { | |
839 | struct wpa_driver_associate_params params; | |
d9a27b04 | 840 | struct ieee802_11_elems elems; |
80e8a5ee BG |
841 | #ifdef CONFIG_HT_OVERRIDES |
842 | struct ieee80211_ht_capabilities htcaps; | |
843 | struct ieee80211_ht_capabilities htcaps_mask; | |
844 | #endif /* CONFIG_HT_OVERRIDES */ | |
e9ee8dc3 JB |
845 | #ifdef CONFIG_VHT_OVERRIDES |
846 | struct ieee80211_vht_capabilities vhtcaps; | |
847 | struct ieee80211_vht_capabilities vhtcaps_mask; | |
848 | #endif /* CONFIG_VHT_OVERRIDES */ | |
71024cb2 | 849 | |
c2a04078 | 850 | os_memset(¶ms, 0, sizeof(params)); |
71024cb2 | 851 | params.bssid = bssid; |
c2a04078 JM |
852 | params.ssid = wpa_s->sme.ssid; |
853 | params.ssid_len = wpa_s->sme.ssid_len; | |
4ec68377 | 854 | params.freq.freq = wpa_s->sme.freq; |
1f6c0ab8 BS |
855 | params.bg_scan_period = wpa_s->current_ssid ? |
856 | wpa_s->current_ssid->bg_scan_period : -1; | |
c2a04078 JM |
857 | params.wpa_ie = wpa_s->sme.assoc_req_ie_len ? |
858 | wpa_s->sme.assoc_req_ie : NULL; | |
859 | params.wpa_ie_len = wpa_s->sme.assoc_req_ie_len; | |
4848a38d JM |
860 | params.pairwise_suite = wpa_s->pairwise_cipher; |
861 | params.group_suite = wpa_s->group_cipher; | |
163f801e JM |
862 | params.key_mgmt_suite = wpa_s->key_mgmt; |
863 | params.wpa_proto = wpa_s->wpa_proto; | |
80e8a5ee BG |
864 | #ifdef CONFIG_HT_OVERRIDES |
865 | os_memset(&htcaps, 0, sizeof(htcaps)); | |
866 | os_memset(&htcaps_mask, 0, sizeof(htcaps_mask)); | |
867 | params.htcaps = (u8 *) &htcaps; | |
868 | params.htcaps_mask = (u8 *) &htcaps_mask; | |
869 | wpa_supplicant_apply_ht_overrides(wpa_s, wpa_s->current_ssid, ¶ms); | |
870 | #endif /* CONFIG_HT_OVERRIDES */ | |
e9ee8dc3 JB |
871 | #ifdef CONFIG_VHT_OVERRIDES |
872 | os_memset(&vhtcaps, 0, sizeof(vhtcaps)); | |
873 | os_memset(&vhtcaps_mask, 0, sizeof(vhtcaps_mask)); | |
874 | params.vhtcaps = &vhtcaps; | |
875 | params.vhtcaps_mask = &vhtcaps_mask; | |
876 | wpa_supplicant_apply_vht_overrides(wpa_s, wpa_s->current_ssid, ¶ms); | |
877 | #endif /* CONFIG_VHT_OVERRIDES */ | |
c2a04078 | 878 | #ifdef CONFIG_IEEE80211R |
71024cb2 | 879 | if (auth_type == WLAN_AUTH_FT && wpa_s->sme.ft_ies) { |
c2a04078 JM |
880 | params.wpa_ie = wpa_s->sme.ft_ies; |
881 | params.wpa_ie_len = wpa_s->sme.ft_ies_len; | |
882 | } | |
883 | #endif /* CONFIG_IEEE80211R */ | |
71024cb2 | 884 | params.mode = mode; |
c2a04078 | 885 | params.mgmt_frame_protection = wpa_s->sme.mfp; |
b361d580 | 886 | params.rrm_used = wpa_s->rrm.rrm_used; |
62fa124c JM |
887 | if (wpa_s->sme.prev_bssid_set) |
888 | params.prev_bssid = wpa_s->sme.prev_bssid; | |
c2a04078 JM |
889 | |
890 | wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR | |
891 | " (SSID='%s' freq=%d MHz)", MAC2STR(params.bssid), | |
892 | params.ssid ? wpa_ssid_txt(params.ssid, params.ssid_len) : "", | |
4ec68377 | 893 | params.freq.freq); |
c2a04078 JM |
894 | |
895 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING); | |
896 | ||
9efc3f2a JM |
897 | if (params.wpa_ie == NULL || |
898 | ieee802_11_parse_elems(params.wpa_ie, params.wpa_ie_len, &elems, 0) | |
d9a27b04 | 899 | < 0) { |
f049052b | 900 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Could not parse own IEs?!"); |
d9a27b04 JM |
901 | os_memset(&elems, 0, sizeof(elems)); |
902 | } | |
64fa840a JM |
903 | if (elems.rsn_ie) { |
904 | params.wpa_proto = WPA_PROTO_RSN; | |
d9a27b04 JM |
905 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.rsn_ie - 2, |
906 | elems.rsn_ie_len + 2); | |
64fa840a JM |
907 | } else if (elems.wpa_ie) { |
908 | params.wpa_proto = WPA_PROTO_WPA; | |
d9a27b04 JM |
909 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.wpa_ie - 2, |
910 | elems.wpa_ie_len + 2); | |
df0f01d9 JM |
911 | } else if (elems.osen) { |
912 | params.wpa_proto = WPA_PROTO_OSEN; | |
913 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.osen - 2, | |
914 | elems.osen_len + 2); | |
64fa840a | 915 | } else |
d9a27b04 | 916 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); |
ffad8858 | 917 | if (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group) |
6e3f4b89 | 918 | params.p2p = 1; |
d9a27b04 | 919 | |
eea2fd9e JM |
920 | if (wpa_s->parent->set_sta_uapsd) |
921 | params.uapsd = wpa_s->parent->sta_uapsd; | |
922 | else | |
923 | params.uapsd = -1; | |
924 | ||
c2a04078 | 925 | if (wpa_drv_associate(wpa_s, ¶ms) < 0) { |
f049052b BG |
926 | wpa_msg(wpa_s, MSG_INFO, "SME: Association request to the " |
927 | "driver failed"); | |
e5ad96b7 | 928 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
c1c02342 | 929 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
e5ad96b7 | 930 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
c2a04078 JM |
931 | return; |
932 | } | |
933 | ||
e29853bb BG |
934 | eloop_register_timeout(SME_ASSOC_TIMEOUT, 0, sme_assoc_timer, wpa_s, |
935 | NULL); | |
c2a04078 JM |
936 | } |
937 | ||
938 | ||
939 | int sme_update_ft_ies(struct wpa_supplicant *wpa_s, const u8 *md, | |
940 | const u8 *ies, size_t ies_len) | |
941 | { | |
942 | if (md == NULL || ies == NULL) { | |
f049052b | 943 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Remove mobility domain"); |
c2a04078 JM |
944 | os_free(wpa_s->sme.ft_ies); |
945 | wpa_s->sme.ft_ies = NULL; | |
946 | wpa_s->sme.ft_ies_len = 0; | |
947 | wpa_s->sme.ft_used = 0; | |
948 | return 0; | |
949 | } | |
950 | ||
951 | os_memcpy(wpa_s->sme.mobility_domain, md, MOBILITY_DOMAIN_ID_LEN); | |
952 | wpa_hexdump(MSG_DEBUG, "SME: FT IEs", ies, ies_len); | |
953 | os_free(wpa_s->sme.ft_ies); | |
954 | wpa_s->sme.ft_ies = os_malloc(ies_len); | |
955 | if (wpa_s->sme.ft_ies == NULL) | |
956 | return -1; | |
957 | os_memcpy(wpa_s->sme.ft_ies, ies, ies_len); | |
958 | wpa_s->sme.ft_ies_len = ies_len; | |
959 | return 0; | |
960 | } | |
efa46078 JM |
961 | |
962 | ||
e29853bb | 963 | static void sme_deauth(struct wpa_supplicant *wpa_s) |
efa46078 | 964 | { |
8bac466b JM |
965 | int bssid_changed; |
966 | ||
8bac466b | 967 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
76d11d3f | 968 | |
76d11d3f JM |
969 | if (wpa_drv_deauthenticate(wpa_s, wpa_s->pending_bssid, |
970 | WLAN_REASON_DEAUTH_LEAVING) < 0) { | |
f049052b BG |
971 | wpa_msg(wpa_s, MSG_INFO, "SME: Deauth request to the driver " |
972 | "failed"); | |
76d11d3f | 973 | } |
62fa124c | 974 | wpa_s->sme.prev_bssid_set = 0; |
76d11d3f | 975 | |
0fb337c1 | 976 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
76d11d3f | 977 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
efa46078 JM |
978 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
979 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); | |
8bac466b JM |
980 | if (bssid_changed) |
981 | wpas_notify_bssid_changed(wpa_s); | |
efa46078 | 982 | } |
da1fb17c JM |
983 | |
984 | ||
e29853bb BG |
985 | void sme_event_assoc_reject(struct wpa_supplicant *wpa_s, |
986 | union wpa_event_data *data) | |
987 | { | |
988 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Association with " MACSTR " failed: " | |
989 | "status code %d", MAC2STR(wpa_s->pending_bssid), | |
990 | data->assoc_reject.status_code); | |
991 | ||
992 | eloop_cancel_timeout(sme_assoc_timer, wpa_s, NULL); | |
993 | ||
bc26ac50 JM |
994 | #ifdef CONFIG_SAE |
995 | if (wpa_s->sme.sae_pmksa_caching && wpa_s->current_ssid && | |
996 | wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt)) { | |
997 | wpa_dbg(wpa_s, MSG_DEBUG, | |
998 | "PMKSA caching attempt rejected - drop PMKSA cache entry and fall back to SAE authentication"); | |
999 | wpa_sm_aborted_cached(wpa_s->wpa); | |
1000 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid); | |
1001 | if (wpa_s->current_bss) { | |
1002 | struct wpa_bss *bss = wpa_s->current_bss; | |
1003 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
1004 | ||
1005 | wpa_drv_deauthenticate(wpa_s, wpa_s->pending_bssid, | |
1006 | WLAN_REASON_DEAUTH_LEAVING); | |
1007 | wpas_connect_work_done(wpa_s); | |
1008 | wpa_supplicant_mark_disassoc(wpa_s); | |
1009 | wpa_supplicant_connect(wpa_s, bss, ssid); | |
1010 | return; | |
1011 | } | |
1012 | } | |
1013 | #endif /* CONFIG_SAE */ | |
1014 | ||
e29853bb BG |
1015 | /* |
1016 | * For now, unconditionally terminate the previous authentication. In | |
1017 | * theory, this should not be needed, but mac80211 gets quite confused | |
1018 | * if the authentication is left pending.. Some roaming cases might | |
1019 | * benefit from using the previous authentication, so this could be | |
1020 | * optimized in the future. | |
1021 | */ | |
1022 | sme_deauth(wpa_s); | |
1023 | } | |
1024 | ||
1025 | ||
da1fb17c JM |
1026 | void sme_event_auth_timed_out(struct wpa_supplicant *wpa_s, |
1027 | union wpa_event_data *data) | |
1028 | { | |
f049052b | 1029 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Authentication timed out"); |
0fb337c1 | 1030 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
1193dc8f | 1031 | wpa_supplicant_mark_disassoc(wpa_s); |
da1fb17c JM |
1032 | } |
1033 | ||
1034 | ||
1035 | void sme_event_assoc_timed_out(struct wpa_supplicant *wpa_s, | |
1036 | union wpa_event_data *data) | |
1037 | { | |
f049052b | 1038 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Association timed out"); |
0fb337c1 | 1039 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
da1fb17c | 1040 | wpa_supplicant_mark_disassoc(wpa_s); |
da1fb17c | 1041 | } |
a84ed99e JM |
1042 | |
1043 | ||
1044 | void sme_event_disassoc(struct wpa_supplicant *wpa_s, | |
d7df0fa7 | 1045 | struct disassoc_info *info) |
a84ed99e | 1046 | { |
f049052b | 1047 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Disassociation event received"); |
17fbb751 | 1048 | if (wpa_s->sme.prev_bssid_set) { |
a84ed99e JM |
1049 | /* |
1050 | * cfg80211/mac80211 can get into somewhat confused state if | |
1051 | * the AP only disassociates us and leaves us in authenticated | |
1052 | * state. For now, force the state to be cleared to avoid | |
1053 | * confusing errors if we try to associate with the AP again. | |
1054 | */ | |
f049052b BG |
1055 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Deauthenticate to clear " |
1056 | "driver state"); | |
7e26053a | 1057 | wpa_drv_deauthenticate(wpa_s, wpa_s->sme.prev_bssid, |
a84ed99e JM |
1058 | WLAN_REASON_DEAUTH_LEAVING); |
1059 | } | |
1060 | } | |
7d878ca7 JM |
1061 | |
1062 | ||
e29853bb BG |
1063 | static void sme_auth_timer(void *eloop_ctx, void *timeout_ctx) |
1064 | { | |
1065 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1066 | if (wpa_s->wpa_state == WPA_AUTHENTICATING) { | |
1067 | wpa_msg(wpa_s, MSG_DEBUG, "SME: Authentication timeout"); | |
1068 | sme_deauth(wpa_s); | |
1069 | } | |
1070 | } | |
1071 | ||
1072 | ||
1073 | static void sme_assoc_timer(void *eloop_ctx, void *timeout_ctx) | |
1074 | { | |
1075 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1076 | if (wpa_s->wpa_state == WPA_ASSOCIATING) { | |
1077 | wpa_msg(wpa_s, MSG_DEBUG, "SME: Association timeout"); | |
1078 | sme_deauth(wpa_s); | |
1079 | } | |
1080 | } | |
1081 | ||
1082 | ||
1083 | void sme_state_changed(struct wpa_supplicant *wpa_s) | |
1084 | { | |
1085 | /* Make sure timers are cleaned up appropriately. */ | |
1086 | if (wpa_s->wpa_state != WPA_ASSOCIATING) | |
1087 | eloop_cancel_timeout(sme_assoc_timer, wpa_s, NULL); | |
1088 | if (wpa_s->wpa_state != WPA_AUTHENTICATING) | |
1089 | eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL); | |
1090 | } | |
1091 | ||
1092 | ||
1093 | void sme_disassoc_while_authenticating(struct wpa_supplicant *wpa_s, | |
1094 | const u8 *prev_pending_bssid) | |
1095 | { | |
1096 | /* | |
1097 | * mac80211-workaround to force deauth on failed auth cmd, | |
1098 | * requires us to remain in authenticating state to allow the | |
1099 | * second authentication attempt to be continued properly. | |
1100 | */ | |
1101 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Allow pending authentication " | |
1102 | "to proceed after disconnection event"); | |
1103 | wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING); | |
1104 | os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN); | |
1105 | ||
1106 | /* | |
1107 | * Re-arm authentication timer in case auth fails for whatever reason. | |
1108 | */ | |
1109 | eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL); | |
1110 | eloop_register_timeout(SME_AUTH_TIMEOUT, 0, sme_auth_timer, wpa_s, | |
1111 | NULL); | |
1112 | } | |
1113 | ||
1114 | ||
4e70bbf1 JM |
1115 | void sme_clear_on_disassoc(struct wpa_supplicant *wpa_s) |
1116 | { | |
1117 | wpa_s->sme.prev_bssid_set = 0; | |
1118 | #ifdef CONFIG_SAE | |
1119 | wpabuf_free(wpa_s->sme.sae_token); | |
1120 | wpa_s->sme.sae_token = NULL; | |
1121 | sae_clear_data(&wpa_s->sme.sae); | |
1122 | #endif /* CONFIG_SAE */ | |
1123 | #ifdef CONFIG_IEEE80211R | |
1124 | if (wpa_s->sme.ft_ies) | |
1125 | sme_update_ft_ies(wpa_s, NULL, NULL, 0); | |
1126 | #endif /* CONFIG_IEEE80211R */ | |
1127 | } | |
1128 | ||
1129 | ||
e29853bb BG |
1130 | void sme_deinit(struct wpa_supplicant *wpa_s) |
1131 | { | |
1132 | os_free(wpa_s->sme.ft_ies); | |
1133 | wpa_s->sme.ft_ies = NULL; | |
1134 | wpa_s->sme.ft_ies_len = 0; | |
1135 | #ifdef CONFIG_IEEE80211W | |
1136 | sme_stop_sa_query(wpa_s); | |
1137 | #endif /* CONFIG_IEEE80211W */ | |
4e70bbf1 | 1138 | sme_clear_on_disassoc(wpa_s); |
e29853bb BG |
1139 | |
1140 | eloop_cancel_timeout(sme_assoc_timer, wpa_s, NULL); | |
1141 | eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL); | |
c3701c66 RM |
1142 | eloop_cancel_timeout(sme_obss_scan_timeout, wpa_s, NULL); |
1143 | } | |
1144 | ||
1145 | ||
1146 | static void sme_send_2040_bss_coex(struct wpa_supplicant *wpa_s, | |
1147 | const u8 *chan_list, u8 num_channels, | |
1148 | u8 num_intol) | |
1149 | { | |
1150 | struct ieee80211_2040_bss_coex_ie *bc_ie; | |
1151 | struct ieee80211_2040_intol_chan_report *ic_report; | |
1152 | struct wpabuf *buf; | |
1153 | ||
31ded52e JM |
1154 | wpa_printf(MSG_DEBUG, "SME: Send 20/40 BSS Coexistence to " MACSTR |
1155 | " (num_channels=%u num_intol=%u)", | |
1156 | MAC2STR(wpa_s->bssid), num_channels, num_intol); | |
1157 | wpa_hexdump(MSG_DEBUG, "SME: 20/40 BSS Intolerant Channels", | |
1158 | chan_list, num_channels); | |
c3701c66 RM |
1159 | |
1160 | buf = wpabuf_alloc(2 + /* action.category + action_code */ | |
1161 | sizeof(struct ieee80211_2040_bss_coex_ie) + | |
1162 | sizeof(struct ieee80211_2040_intol_chan_report) + | |
1163 | num_channels); | |
1164 | if (buf == NULL) | |
1165 | return; | |
1166 | ||
1167 | wpabuf_put_u8(buf, WLAN_ACTION_PUBLIC); | |
1168 | wpabuf_put_u8(buf, WLAN_PA_20_40_BSS_COEX); | |
1169 | ||
1170 | bc_ie = wpabuf_put(buf, sizeof(*bc_ie)); | |
1171 | bc_ie->element_id = WLAN_EID_20_40_BSS_COEXISTENCE; | |
1172 | bc_ie->length = 1; | |
1173 | if (num_intol) | |
1174 | bc_ie->coex_param |= WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ; | |
1175 | ||
1176 | if (num_channels > 0) { | |
1177 | ic_report = wpabuf_put(buf, sizeof(*ic_report)); | |
1178 | ic_report->element_id = WLAN_EID_20_40_BSS_INTOLERANT; | |
1179 | ic_report->length = num_channels + 1; | |
1180 | ic_report->op_class = 0; | |
1181 | os_memcpy(wpabuf_put(buf, num_channels), chan_list, | |
1182 | num_channels); | |
1183 | } | |
1184 | ||
1185 | if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, | |
1186 | wpa_s->own_addr, wpa_s->bssid, | |
1187 | wpabuf_head(buf), wpabuf_len(buf), 0) < 0) { | |
1188 | wpa_msg(wpa_s, MSG_INFO, | |
1189 | "SME: Failed to send 20/40 BSS Coexistence frame"); | |
1190 | } | |
1191 | ||
1192 | wpabuf_free(buf); | |
1193 | } | |
1194 | ||
1195 | ||
c3701c66 RM |
1196 | int sme_proc_obss_scan(struct wpa_supplicant *wpa_s) |
1197 | { | |
1198 | struct wpa_bss *bss; | |
1199 | const u8 *ie; | |
1200 | u16 ht_cap; | |
1201 | u8 chan_list[P2P_MAX_CHANNELS], channel; | |
1202 | u8 num_channels = 0, num_intol = 0, i; | |
1203 | ||
1204 | if (!wpa_s->sme.sched_obss_scan) | |
1205 | return 0; | |
1206 | ||
1207 | wpa_s->sme.sched_obss_scan = 0; | |
1208 | if (!wpa_s->current_bss || wpa_s->wpa_state != WPA_COMPLETED) | |
1209 | return 1; | |
1210 | ||
1211 | /* | |
1212 | * Check whether AP uses regulatory triplet or channel triplet in | |
1213 | * country info. Right now the operating class of the BSS channel | |
1214 | * width trigger event is "unknown" (IEEE Std 802.11-2012 10.15.12), | |
1215 | * based on the assumption that operating class triplet is not used in | |
1216 | * beacon frame. If the First Channel Number/Operating Extension | |
1217 | * Identifier octet has a positive integer value of 201 or greater, | |
1218 | * then its operating class triplet. | |
1219 | * | |
1220 | * TODO: If Supported Operating Classes element is present in beacon | |
1221 | * frame, have to lookup operating class in Annex E and fill them in | |
1222 | * 2040 coex frame. | |
1223 | */ | |
1224 | ie = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_COUNTRY); | |
1225 | if (ie && (ie[1] >= 6) && (ie[5] >= 201)) | |
1226 | return 1; | |
1227 | ||
1228 | os_memset(chan_list, 0, sizeof(chan_list)); | |
1229 | ||
1230 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { | |
1231 | /* Skip other band bss */ | |
e864c0ae JM |
1232 | enum hostapd_hw_mode mode; |
1233 | mode = ieee80211_freq_to_chan(bss->freq, &channel); | |
1234 | if (mode != HOSTAPD_MODE_IEEE80211G && | |
1235 | mode != HOSTAPD_MODE_IEEE80211B) | |
c3701c66 RM |
1236 | continue; |
1237 | ||
1238 | ie = wpa_bss_get_ie(bss, WLAN_EID_HT_CAP); | |
1239 | ht_cap = (ie && (ie[1] == 26)) ? WPA_GET_LE16(ie + 2) : 0; | |
31ded52e JM |
1240 | wpa_printf(MSG_DEBUG, "SME OBSS scan BSS " MACSTR |
1241 | " freq=%u chan=%u ht_cap=0x%x", | |
1242 | MAC2STR(bss->bssid), bss->freq, channel, ht_cap); | |
c3701c66 RM |
1243 | |
1244 | if (!ht_cap || (ht_cap & HT_CAP_INFO_40MHZ_INTOLERANT)) { | |
7f8eb34d JM |
1245 | if (ht_cap & HT_CAP_INFO_40MHZ_INTOLERANT) |
1246 | num_intol++; | |
1247 | ||
c3701c66 RM |
1248 | /* Check whether the channel is already considered */ |
1249 | for (i = 0; i < num_channels; i++) { | |
1250 | if (channel == chan_list[i]) | |
1251 | break; | |
1252 | } | |
1253 | if (i != num_channels) | |
1254 | continue; | |
1255 | ||
c3701c66 RM |
1256 | chan_list[num_channels++] = channel; |
1257 | } | |
1258 | } | |
1259 | ||
1260 | sme_send_2040_bss_coex(wpa_s, chan_list, num_channels, num_intol); | |
1261 | return 1; | |
1262 | } | |
1263 | ||
1264 | ||
6434ad09 JM |
1265 | static struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes, |
1266 | u16 num_modes, | |
1267 | enum hostapd_hw_mode mode) | |
1268 | { | |
1269 | u16 i; | |
1270 | ||
1271 | for (i = 0; i < num_modes; i++) { | |
1272 | if (modes[i].mode == mode) | |
1273 | return &modes[i]; | |
1274 | } | |
1275 | ||
1276 | return NULL; | |
1277 | } | |
1278 | ||
1279 | ||
d97a3c48 JM |
1280 | static void wpa_obss_scan_freqs_list(struct wpa_supplicant *wpa_s, |
1281 | struct wpa_driver_scan_params *params) | |
6434ad09 | 1282 | { |
d97a3c48 | 1283 | /* Include only affected channels */ |
6434ad09 JM |
1284 | struct hostapd_hw_modes *mode; |
1285 | int count, i; | |
d97a3c48 | 1286 | int start, end; |
6434ad09 | 1287 | |
d97a3c48 JM |
1288 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
1289 | HOSTAPD_MODE_IEEE80211G); | |
6434ad09 JM |
1290 | if (mode == NULL) { |
1291 | /* No channels supported in this band - use empty list */ | |
1292 | params->freqs = os_zalloc(sizeof(int)); | |
1293 | return; | |
1294 | } | |
1295 | ||
d97a3c48 JM |
1296 | if (wpa_s->sme.ht_sec_chan == HT_SEC_CHAN_UNKNOWN && |
1297 | wpa_s->current_bss) { | |
1298 | const u8 *ie; | |
1299 | ||
1300 | ie = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_HT_OPERATION); | |
1301 | if (ie && ie[1] >= 2) { | |
1302 | u8 o; | |
1303 | ||
1304 | o = ie[3] & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK; | |
1305 | if (o == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE) | |
1306 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE; | |
1307 | else if (o == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW) | |
1308 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW; | |
1309 | } | |
1310 | } | |
1311 | ||
1312 | start = wpa_s->assoc_freq - 10; | |
1313 | end = wpa_s->assoc_freq + 10; | |
1314 | switch (wpa_s->sme.ht_sec_chan) { | |
1315 | case HT_SEC_CHAN_UNKNOWN: | |
1316 | /* HT40+ possible on channels 1..9 */ | |
1317 | if (wpa_s->assoc_freq <= 2452) | |
1318 | start -= 20; | |
1319 | /* HT40- possible on channels 5-13 */ | |
1320 | if (wpa_s->assoc_freq >= 2432) | |
1321 | end += 20; | |
1322 | break; | |
1323 | case HT_SEC_CHAN_ABOVE: | |
1324 | end += 20; | |
1325 | break; | |
1326 | case HT_SEC_CHAN_BELOW: | |
1327 | start -= 20; | |
1328 | break; | |
1329 | } | |
1330 | wpa_printf(MSG_DEBUG, | |
1331 | "OBSS: assoc_freq %d possible affected range %d-%d", | |
1332 | wpa_s->assoc_freq, start, end); | |
1333 | ||
f9884c09 | 1334 | params->freqs = os_calloc(mode->num_channels + 1, sizeof(int)); |
6434ad09 JM |
1335 | if (params->freqs == NULL) |
1336 | return; | |
1337 | for (count = 0, i = 0; i < mode->num_channels; i++) { | |
d97a3c48 JM |
1338 | int freq; |
1339 | ||
6434ad09 JM |
1340 | if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED) |
1341 | continue; | |
d97a3c48 JM |
1342 | freq = mode->channels[i].freq; |
1343 | if (freq - 10 >= end || freq + 10 <= start) | |
1344 | continue; /* not affected */ | |
1345 | params->freqs[count++] = freq; | |
6434ad09 JM |
1346 | } |
1347 | } | |
1348 | ||
1349 | ||
c3701c66 RM |
1350 | static void sme_obss_scan_timeout(void *eloop_ctx, void *timeout_ctx) |
1351 | { | |
1352 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1353 | struct wpa_driver_scan_params params; | |
1354 | ||
1355 | if (!wpa_s->current_bss) { | |
1356 | wpa_printf(MSG_DEBUG, "SME OBSS: Ignore scan request"); | |
1357 | return; | |
1358 | } | |
1359 | ||
1360 | os_memset(¶ms, 0, sizeof(params)); | |
d97a3c48 | 1361 | wpa_obss_scan_freqs_list(wpa_s, ¶ms); |
57a8f8af | 1362 | params.low_priority = 1; |
c3701c66 RM |
1363 | wpa_printf(MSG_DEBUG, "SME OBSS: Request an OBSS scan"); |
1364 | ||
1365 | if (wpa_supplicant_trigger_scan(wpa_s, ¶ms)) | |
1366 | wpa_printf(MSG_DEBUG, "SME OBSS: Failed to trigger scan"); | |
1367 | else | |
1368 | wpa_s->sme.sched_obss_scan = 1; | |
6434ad09 | 1369 | os_free(params.freqs); |
c3701c66 RM |
1370 | |
1371 | eloop_register_timeout(wpa_s->sme.obss_scan_int, 0, | |
1372 | sme_obss_scan_timeout, wpa_s, NULL); | |
1373 | } | |
1374 | ||
1375 | ||
1376 | void sme_sched_obss_scan(struct wpa_supplicant *wpa_s, int enable) | |
1377 | { | |
1378 | const u8 *ie; | |
1379 | struct wpa_bss *bss = wpa_s->current_bss; | |
1380 | struct wpa_ssid *ssid = wpa_s->current_ssid; | |
b6871ebb AN |
1381 | struct hostapd_hw_modes *hw_mode = NULL; |
1382 | int i; | |
c3701c66 RM |
1383 | |
1384 | eloop_cancel_timeout(sme_obss_scan_timeout, wpa_s, NULL); | |
1385 | wpa_s->sme.sched_obss_scan = 0; | |
d97a3c48 | 1386 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN; |
c3701c66 RM |
1387 | if (!enable) |
1388 | return; | |
1389 | ||
368b1957 AK |
1390 | /* |
1391 | * Schedule OBSS scan if driver is using station SME in wpa_supplicant | |
1392 | * or it expects OBSS scan to be performed by wpa_supplicant. | |
1393 | */ | |
1394 | if (!((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) || | |
1395 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OBSS_SCAN)) || | |
1396 | ssid == NULL || ssid->mode != IEEE80211_MODE_INFRA) | |
1397 | return; | |
c3701c66 | 1398 | |
b6871ebb AN |
1399 | if (!wpa_s->hw.modes) |
1400 | return; | |
1401 | ||
1402 | /* only HT caps in 11g mode are relevant */ | |
1403 | for (i = 0; i < wpa_s->hw.num_modes; i++) { | |
1404 | hw_mode = &wpa_s->hw.modes[i]; | |
1405 | if (hw_mode->mode == HOSTAPD_MODE_IEEE80211G) | |
1406 | break; | |
1407 | } | |
1408 | ||
1409 | /* Driver does not support HT40 for 11g or doesn't have 11g. */ | |
1410 | if (i == wpa_s->hw.num_modes || !hw_mode || | |
1411 | !(hw_mode->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) | |
1412 | return; | |
c3701c66 RM |
1413 | |
1414 | if (bss == NULL || bss->freq < 2400 || bss->freq > 2500) | |
1415 | return; /* Not associated on 2.4 GHz band */ | |
1416 | ||
1417 | /* Check whether AP supports HT40 */ | |
1418 | ie = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_HT_CAP); | |
1419 | if (!ie || ie[1] < 2 || | |
1420 | !(WPA_GET_LE16(ie + 2) & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) | |
1421 | return; /* AP does not support HT40 */ | |
1422 | ||
1423 | ie = wpa_bss_get_ie(wpa_s->current_bss, | |
1424 | WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS); | |
1425 | if (!ie || ie[1] < 14) | |
1426 | return; /* AP does not request OBSS scans */ | |
1427 | ||
1428 | wpa_s->sme.obss_scan_int = WPA_GET_LE16(ie + 6); | |
1429 | if (wpa_s->sme.obss_scan_int < 10) { | |
1430 | wpa_printf(MSG_DEBUG, "SME: Invalid OBSS Scan Interval %u " | |
1431 | "replaced with the minimum 10 sec", | |
1432 | wpa_s->sme.obss_scan_int); | |
1433 | wpa_s->sme.obss_scan_int = 10; | |
1434 | } | |
1435 | wpa_printf(MSG_DEBUG, "SME: OBSS Scan Interval %u sec", | |
1436 | wpa_s->sme.obss_scan_int); | |
1437 | eloop_register_timeout(wpa_s->sme.obss_scan_int, 0, | |
1438 | sme_obss_scan_timeout, wpa_s, NULL); | |
e29853bb BG |
1439 | } |
1440 | ||
1441 | ||
7d878ca7 JM |
1442 | #ifdef CONFIG_IEEE80211W |
1443 | ||
1444 | static const unsigned int sa_query_max_timeout = 1000; | |
1445 | static const unsigned int sa_query_retry_timeout = 201; | |
1446 | ||
1447 | static int sme_check_sa_query_timeout(struct wpa_supplicant *wpa_s) | |
1448 | { | |
1449 | u32 tu; | |
46b8d4c0 JB |
1450 | struct os_reltime now, passed; |
1451 | os_get_reltime(&now); | |
1452 | os_reltime_sub(&now, &wpa_s->sme.sa_query_start, &passed); | |
7d878ca7 JM |
1453 | tu = (passed.sec * 1000000 + passed.usec) / 1024; |
1454 | if (sa_query_max_timeout < tu) { | |
f049052b | 1455 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: SA Query timed out"); |
7d878ca7 JM |
1456 | sme_stop_sa_query(wpa_s); |
1457 | wpa_supplicant_deauthenticate( | |
1458 | wpa_s, WLAN_REASON_PREV_AUTH_NOT_VALID); | |
1459 | return 1; | |
1460 | } | |
1461 | ||
1462 | return 0; | |
1463 | } | |
1464 | ||
1465 | ||
1466 | static void sme_send_sa_query_req(struct wpa_supplicant *wpa_s, | |
1467 | const u8 *trans_id) | |
1468 | { | |
1469 | u8 req[2 + WLAN_SA_QUERY_TR_ID_LEN]; | |
f049052b BG |
1470 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Sending SA Query Request to " |
1471 | MACSTR, MAC2STR(wpa_s->bssid)); | |
7d878ca7 JM |
1472 | wpa_hexdump(MSG_DEBUG, "SME: SA Query Transaction ID", |
1473 | trans_id, WLAN_SA_QUERY_TR_ID_LEN); | |
1474 | req[0] = WLAN_ACTION_SA_QUERY; | |
1475 | req[1] = WLAN_SA_QUERY_REQUEST; | |
1476 | os_memcpy(req + 2, trans_id, WLAN_SA_QUERY_TR_ID_LEN); | |
190b9062 | 1477 | if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
7d878ca7 | 1478 | wpa_s->own_addr, wpa_s->bssid, |
b106173a | 1479 | req, sizeof(req), 0) < 0) |
f049052b BG |
1480 | wpa_msg(wpa_s, MSG_INFO, "SME: Failed to send SA Query " |
1481 | "Request"); | |
7d878ca7 JM |
1482 | } |
1483 | ||
1484 | ||
1485 | static void sme_sa_query_timer(void *eloop_ctx, void *timeout_ctx) | |
1486 | { | |
1487 | struct wpa_supplicant *wpa_s = eloop_ctx; | |
1488 | unsigned int timeout, sec, usec; | |
1489 | u8 *trans_id, *nbuf; | |
1490 | ||
1491 | if (wpa_s->sme.sa_query_count > 0 && | |
1492 | sme_check_sa_query_timeout(wpa_s)) | |
1493 | return; | |
1494 | ||
067ffa26 JM |
1495 | nbuf = os_realloc_array(wpa_s->sme.sa_query_trans_id, |
1496 | wpa_s->sme.sa_query_count + 1, | |
1497 | WLAN_SA_QUERY_TR_ID_LEN); | |
7d878ca7 JM |
1498 | if (nbuf == NULL) |
1499 | return; | |
1500 | if (wpa_s->sme.sa_query_count == 0) { | |
1501 | /* Starting a new SA Query procedure */ | |
46b8d4c0 | 1502 | os_get_reltime(&wpa_s->sme.sa_query_start); |
7d878ca7 JM |
1503 | } |
1504 | trans_id = nbuf + wpa_s->sme.sa_query_count * WLAN_SA_QUERY_TR_ID_LEN; | |
1505 | wpa_s->sme.sa_query_trans_id = nbuf; | |
1506 | wpa_s->sme.sa_query_count++; | |
1507 | ||
cb5ef952 JM |
1508 | if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) { |
1509 | wpa_printf(MSG_DEBUG, "Could not generate SA Query ID"); | |
1510 | return; | |
1511 | } | |
7d878ca7 JM |
1512 | |
1513 | timeout = sa_query_retry_timeout; | |
1514 | sec = ((timeout / 1000) * 1024) / 1000; | |
1515 | usec = (timeout % 1000) * 1024; | |
1516 | eloop_register_timeout(sec, usec, sme_sa_query_timer, wpa_s, NULL); | |
1517 | ||
f049052b BG |
1518 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Association SA Query attempt %d", |
1519 | wpa_s->sme.sa_query_count); | |
7d878ca7 JM |
1520 | |
1521 | sme_send_sa_query_req(wpa_s, trans_id); | |
1522 | } | |
1523 | ||
1524 | ||
1525 | static void sme_start_sa_query(struct wpa_supplicant *wpa_s) | |
1526 | { | |
1527 | sme_sa_query_timer(wpa_s, NULL); | |
1528 | } | |
1529 | ||
1530 | ||
19df9b07 | 1531 | static void sme_stop_sa_query(struct wpa_supplicant *wpa_s) |
7d878ca7 JM |
1532 | { |
1533 | eloop_cancel_timeout(sme_sa_query_timer, wpa_s, NULL); | |
1534 | os_free(wpa_s->sme.sa_query_trans_id); | |
1535 | wpa_s->sme.sa_query_trans_id = NULL; | |
1536 | wpa_s->sme.sa_query_count = 0; | |
1537 | } | |
1538 | ||
1539 | ||
1540 | void sme_event_unprot_disconnect(struct wpa_supplicant *wpa_s, const u8 *sa, | |
1541 | const u8 *da, u16 reason_code) | |
1542 | { | |
1543 | struct wpa_ssid *ssid; | |
3302b7c2 | 1544 | struct os_reltime now; |
7d878ca7 | 1545 | |
7d878ca7 JM |
1546 | if (wpa_s->wpa_state != WPA_COMPLETED) |
1547 | return; | |
1548 | ssid = wpa_s->current_ssid; | |
3f56a2b7 | 1549 | if (wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION) |
7d878ca7 JM |
1550 | return; |
1551 | if (os_memcmp(sa, wpa_s->bssid, ETH_ALEN) != 0) | |
1552 | return; | |
1553 | if (reason_code != WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA && | |
1554 | reason_code != WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA) | |
1555 | return; | |
1556 | if (wpa_s->sme.sa_query_count > 0) | |
1557 | return; | |
1558 | ||
3302b7c2 JM |
1559 | os_get_reltime(&now); |
1560 | if (wpa_s->sme.last_unprot_disconnect.sec && | |
1561 | !os_reltime_expired(&now, &wpa_s->sme.last_unprot_disconnect, 10)) | |
1562 | return; /* limit SA Query procedure frequency */ | |
1563 | wpa_s->sme.last_unprot_disconnect = now; | |
1564 | ||
f049052b BG |
1565 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Unprotected disconnect dropped - " |
1566 | "possible AP/STA state mismatch - trigger SA Query"); | |
7d878ca7 JM |
1567 | sme_start_sa_query(wpa_s); |
1568 | } | |
1569 | ||
1570 | ||
1571 | void sme_sa_query_rx(struct wpa_supplicant *wpa_s, const u8 *sa, | |
1572 | const u8 *data, size_t len) | |
1573 | { | |
1574 | int i; | |
1575 | ||
1576 | if (wpa_s->sme.sa_query_trans_id == NULL || | |
1577 | len < 1 + WLAN_SA_QUERY_TR_ID_LEN || | |
1578 | data[0] != WLAN_SA_QUERY_RESPONSE) | |
1579 | return; | |
f049052b BG |
1580 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Received SA Query response from " |
1581 | MACSTR " (trans_id %02x%02x)", MAC2STR(sa), data[1], data[2]); | |
7d878ca7 JM |
1582 | |
1583 | if (os_memcmp(sa, wpa_s->bssid, ETH_ALEN) != 0) | |
1584 | return; | |
1585 | ||
1586 | for (i = 0; i < wpa_s->sme.sa_query_count; i++) { | |
1587 | if (os_memcmp(wpa_s->sme.sa_query_trans_id + | |
1588 | i * WLAN_SA_QUERY_TR_ID_LEN, | |
1589 | data + 1, WLAN_SA_QUERY_TR_ID_LEN) == 0) | |
1590 | break; | |
1591 | } | |
1592 | ||
1593 | if (i >= wpa_s->sme.sa_query_count) { | |
f049052b BG |
1594 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: No matching SA Query " |
1595 | "transaction identifier found"); | |
7d878ca7 JM |
1596 | return; |
1597 | } | |
1598 | ||
f049052b BG |
1599 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Reply to pending SA Query received " |
1600 | "from " MACSTR, MAC2STR(sa)); | |
7d878ca7 JM |
1601 | sme_stop_sa_query(wpa_s); |
1602 | } | |
1603 | ||
1604 | #endif /* CONFIG_IEEE80211W */ |