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