3 * Copyright (c) 2009-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
14 #include "common/ieee802_11_common.h"
15 #include "common/ocv.h"
16 #include "eapol_supp/eapol_supp_sm.h"
17 #include "common/wpa_common.h"
18 #include "common/sae.h"
19 #include "rsn_supp/wpa.h"
20 #include "rsn_supp/pmksa_cache.h"
22 #include "wpa_supplicant_i.h"
24 #include "wpas_glue.h"
25 #include "wps_supplicant.h"
26 #include "p2p_supplicant.h"
31 #include "hs20_supplicant.h"
33 #define SME_AUTH_TIMEOUT 5
34 #define SME_ASSOC_TIMEOUT 5
36 static void sme_auth_timer(void *eloop_ctx
, void *timeout_ctx
);
37 static void sme_assoc_timer(void *eloop_ctx
, void *timeout_ctx
);
38 static void sme_obss_scan_timeout(void *eloop_ctx
, void *timeout_ctx
);
39 #ifdef CONFIG_IEEE80211W
40 static void sme_stop_sa_query(struct wpa_supplicant
*wpa_s
);
41 #endif /* CONFIG_IEEE80211W */
46 static int index_within_array(const int *array
, int idx
)
49 for (i
= 0; i
< idx
; i
++) {
57 static int sme_set_sae_group(struct wpa_supplicant
*wpa_s
)
59 int *groups
= wpa_s
->conf
->sae_groups
;
60 int default_groups
[] = { 19, 20, 21, 0 };
62 if (!groups
|| groups
[0] <= 0)
63 groups
= default_groups
;
65 /* Configuration may have changed, so validate current index */
66 if (!index_within_array(groups
, wpa_s
->sme
.sae_group_index
))
70 int group
= groups
[wpa_s
->sme
.sae_group_index
];
73 if (sae_set_group(&wpa_s
->sme
.sae
, group
) == 0) {
74 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Selected SAE group %d",
75 wpa_s
->sme
.sae
.group
);
78 wpa_s
->sme
.sae_group_index
++;
85 static struct wpabuf
* sme_auth_build_sae_commit(struct wpa_supplicant
*wpa_s
,
86 struct wpa_ssid
*ssid
,
87 const u8
*bssid
, int external
,
94 #ifdef CONFIG_TESTING_OPTIONS
95 if (wpa_s
->sae_commit_override
) {
96 wpa_printf(MSG_DEBUG
, "SAE: TESTING - commit override");
97 buf
= wpabuf_alloc(4 + wpabuf_len(wpa_s
->sae_commit_override
));
100 wpabuf_put_le16(buf
, 1); /* Transaction seq# */
101 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
102 wpabuf_put_buf(buf
, wpa_s
->sae_commit_override
);
105 #endif /* CONFIG_TESTING_OPTIONS */
107 password
= ssid
->sae_password
;
109 password
= ssid
->passphrase
;
111 wpa_printf(MSG_DEBUG
, "SAE: No password available");
115 if (reuse
&& wpa_s
->sme
.sae
.tmp
&&
116 os_memcmp(bssid
, wpa_s
->sme
.sae
.tmp
->bssid
, ETH_ALEN
) == 0) {
117 wpa_printf(MSG_DEBUG
,
118 "SAE: Reuse previously generated PWE on a retry with the same AP");
121 if (sme_set_sae_group(wpa_s
) < 0) {
122 wpa_printf(MSG_DEBUG
, "SAE: Failed to select group");
126 if (sae_prepare_commit(wpa_s
->own_addr
, bssid
,
127 (u8
*) password
, os_strlen(password
),
128 ssid
->sae_password_id
,
129 &wpa_s
->sme
.sae
) < 0) {
130 wpa_printf(MSG_DEBUG
, "SAE: Could not pick PWE");
133 if (wpa_s
->sme
.sae
.tmp
)
134 os_memcpy(wpa_s
->sme
.sae
.tmp
->bssid
, bssid
, ETH_ALEN
);
137 len
= wpa_s
->sme
.sae_token
? wpabuf_len(wpa_s
->sme
.sae_token
) : 0;
138 if (ssid
->sae_password_id
)
139 len
+= 4 + os_strlen(ssid
->sae_password_id
);
140 buf
= wpabuf_alloc(4 + SAE_COMMIT_MAX_LEN
+ len
);
144 wpabuf_put_le16(buf
, 1); /* Transaction seq# */
145 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
147 sae_write_commit(&wpa_s
->sme
.sae
, buf
, wpa_s
->sme
.sae_token
,
148 ssid
->sae_password_id
);
154 static struct wpabuf
* sme_auth_build_sae_confirm(struct wpa_supplicant
*wpa_s
,
159 buf
= wpabuf_alloc(4 + SAE_CONFIRM_MAX_LEN
);
164 wpabuf_put_le16(buf
, 2); /* Transaction seq# */
165 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
167 sae_write_confirm(&wpa_s
->sme
.sae
, buf
);
172 #endif /* CONFIG_SAE */
176 * sme_auth_handle_rrm - Handle RRM aspects of current authentication attempt
177 * @wpa_s: Pointer to wpa_supplicant data
178 * @bss: Pointer to the bss which is the target of authentication attempt
180 static void sme_auth_handle_rrm(struct wpa_supplicant
*wpa_s
,
183 const u8 rrm_ie_len
= 5;
187 wpa_s
->rrm
.rrm_used
= 0;
189 wpa_printf(MSG_DEBUG
,
190 "RRM: Determining whether RRM can be used - device support: 0x%x",
191 wpa_s
->drv_rrm_flags
);
193 rrm_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RRM_ENABLED_CAPABILITIES
);
194 if (!rrm_ie
|| !(bss
->caps
& IEEE80211_CAP_RRM
)) {
195 wpa_printf(MSG_DEBUG
, "RRM: No RRM in network");
199 if (!((wpa_s
->drv_rrm_flags
&
200 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES
) &&
201 (wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_QUIET
)) &&
202 !(wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_SUPPORT_RRM
)) {
203 wpa_printf(MSG_DEBUG
,
204 "RRM: Insufficient RRM support in driver - do not use RRM");
208 if (sizeof(wpa_s
->sme
.assoc_req_ie
) <
209 wpa_s
->sme
.assoc_req_ie_len
+ rrm_ie_len
+ 2) {
211 "RRM: Unable to use RRM, no room for RRM IE");
215 wpa_printf(MSG_DEBUG
, "RRM: Adding RRM IE to Association Request");
216 pos
= wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
;
217 os_memset(pos
, 0, 2 + rrm_ie_len
);
218 *pos
++ = WLAN_EID_RRM_ENABLED_CAPABILITIES
;
221 /* Set supported capabilites flags */
222 if (wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_TX_POWER_INSERTION
)
223 *pos
|= WLAN_RRM_CAPS_LINK_MEASUREMENT
;
225 *pos
|= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE
|
226 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE
|
227 WLAN_RRM_CAPS_BEACON_REPORT_TABLE
;
230 pos
[1] |= WLAN_RRM_CAPS_LCI_MEASUREMENT
;
232 wpa_s
->sme
.assoc_req_ie_len
+= rrm_ie_len
+ 2;
233 wpa_s
->rrm
.rrm_used
= 1;
237 static void sme_send_authentication(struct wpa_supplicant
*wpa_s
,
238 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
241 struct wpa_driver_auth_params params
;
242 struct wpa_ssid
*old_ssid
;
243 #ifdef CONFIG_IEEE80211R
245 #endif /* CONFIG_IEEE80211R */
246 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_FILS)
248 #endif /* CONFIG_IEEE80211R || CONFIG_FILS */
249 int i
, bssid_changed
;
250 struct wpabuf
*resp
= NULL
;
258 #endif /* CONFIG_MBO */
261 wpa_msg(wpa_s
, MSG_ERROR
, "SME: No scan result available for "
263 wpas_connect_work_done(wpa_s
);
267 skip_auth
= wpa_s
->conf
->reassoc_same_bss_optim
&&
268 wpa_s
->reassoc_same_bss
;
269 wpa_s
->current_bss
= bss
;
271 os_memset(¶ms
, 0, sizeof(params
));
272 wpa_s
->reassociate
= 0;
274 params
.freq
= bss
->freq
;
275 params
.bssid
= bss
->bssid
;
276 params
.ssid
= bss
->ssid
;
277 params
.ssid_len
= bss
->ssid_len
;
278 params
.p2p
= ssid
->p2p_group
;
280 if (wpa_s
->sme
.ssid_len
!= params
.ssid_len
||
281 os_memcmp(wpa_s
->sme
.ssid
, params
.ssid
, params
.ssid_len
) != 0)
282 wpa_s
->sme
.prev_bssid_set
= 0;
284 wpa_s
->sme
.freq
= params
.freq
;
285 os_memcpy(wpa_s
->sme
.ssid
, params
.ssid
, params
.ssid_len
);
286 wpa_s
->sme
.ssid_len
= params
.ssid_len
;
288 params
.auth_alg
= WPA_AUTH_ALG_OPEN
;
289 #ifdef IEEE8021X_EAPOL
290 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
292 if (ssid
->non_leap
== 0)
293 params
.auth_alg
= WPA_AUTH_ALG_LEAP
;
295 params
.auth_alg
|= WPA_AUTH_ALG_LEAP
;
298 #endif /* IEEE8021X_EAPOL */
299 wpa_dbg(wpa_s
, MSG_DEBUG
, "Automatic auth_alg selection: 0x%x",
301 if (ssid
->auth_alg
) {
302 params
.auth_alg
= ssid
->auth_alg
;
303 wpa_dbg(wpa_s
, MSG_DEBUG
, "Overriding auth_alg selection: "
304 "0x%x", params
.auth_alg
);
307 wpa_s
->sme
.sae_pmksa_caching
= 0;
308 if (wpa_key_mgmt_sae(ssid
->key_mgmt
)) {
310 struct wpa_ie_data ied
;
312 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
314 wpa_dbg(wpa_s
, MSG_DEBUG
,
315 "SAE enabled, but target BSS does not advertise RSN");
317 } else if (wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ied
) == 0 &&
318 (ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) &&
319 (ied
.key_mgmt
& WPA_KEY_MGMT_DPP
)) {
320 wpa_dbg(wpa_s
, MSG_DEBUG
, "Prefer DPP over SAE when both are enabled");
321 #endif /* CONFIG_DPP */
322 } else if (wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ied
) == 0 &&
323 wpa_key_mgmt_sae(ied
.key_mgmt
)) {
324 wpa_dbg(wpa_s
, MSG_DEBUG
, "Using SAE auth_alg");
325 params
.auth_alg
= WPA_AUTH_ALG_SAE
;
327 wpa_dbg(wpa_s
, MSG_DEBUG
,
328 "SAE enabled, but target BSS does not advertise SAE AKM for RSN");
331 #endif /* CONFIG_SAE */
333 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
334 if (ssid
->wep_key_len
[i
])
335 params
.wep_key
[i
] = ssid
->wep_key
[i
];
336 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
338 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
340 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
341 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
342 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
344 wpas_notify_bssid_changed(wpa_s
);
346 if ((wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
347 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
348 wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
349 int try_opportunistic
;
350 const u8
*cache_id
= NULL
;
352 try_opportunistic
= (ssid
->proactive_key_caching
< 0 ?
354 ssid
->proactive_key_caching
) &&
355 (ssid
->proto
& WPA_PROTO_RSN
);
357 if (wpa_key_mgmt_fils(ssid
->key_mgmt
))
358 cache_id
= wpa_bss_get_fils_cache_id(bss
);
359 #endif /* CONFIG_FILS */
360 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
362 try_opportunistic
, cache_id
,
364 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
365 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
366 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
367 wpa_s
->sme
.assoc_req_ie
,
368 &wpa_s
->sme
.assoc_req_ie_len
)) {
369 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
370 "key management and encryption suites");
371 wpas_connect_work_done(wpa_s
);
375 } else if (wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
) &&
376 (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
)) {
377 /* No PMKSA caching, but otherwise similar to RSN/WPA */
378 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
379 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
380 wpa_s
->sme
.assoc_req_ie
,
381 &wpa_s
->sme
.assoc_req_ie_len
)) {
382 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
383 "key management and encryption suites");
384 wpas_connect_work_done(wpa_s
);
387 #endif /* CONFIG_HS20 */
388 } else if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
389 wpa_key_mgmt_wpa_ieee8021x(ssid
->key_mgmt
)) {
391 * Both WPA and non-WPA IEEE 802.1X enabled in configuration -
392 * use non-WPA since the scan results did not indicate that the
393 * AP is using WPA or WPA2.
395 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
396 wpa_s
->sme
.assoc_req_ie_len
= 0;
397 } else if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
398 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
399 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
400 wpa_s
->sme
.assoc_req_ie
,
401 &wpa_s
->sme
.assoc_req_ie_len
)) {
402 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
403 "key management and encryption suites (no "
405 wpas_connect_work_done(wpa_s
);
409 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
410 struct wpabuf
*wps_ie
;
411 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
412 if (wps_ie
&& wpabuf_len(wps_ie
) <=
413 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
414 wpa_s
->sme
.assoc_req_ie_len
= wpabuf_len(wps_ie
);
415 os_memcpy(wpa_s
->sme
.assoc_req_ie
, wpabuf_head(wps_ie
),
416 wpa_s
->sme
.assoc_req_ie_len
);
418 wpa_s
->sme
.assoc_req_ie_len
= 0;
420 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
421 #endif /* CONFIG_WPS */
423 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
424 wpa_s
->sme
.assoc_req_ie_len
= 0;
427 /* In case the WPA vendor IE is used, it should be placed after all the
428 * non-vendor IEs, as the lower layer expects the IEs to be ordered as
429 * defined in the standard. Store the WPA IE so it can later be
430 * inserted at the correct location.
434 if (wpa_s
->wpa_proto
== WPA_PROTO_WPA
) {
435 wpa_ie
= os_memdup(wpa_s
->sme
.assoc_req_ie
,
436 wpa_s
->sme
.assoc_req_ie_len
);
438 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Storing WPA IE");
440 wpa_ie_len
= wpa_s
->sme
.assoc_req_ie_len
;
441 wpa_s
->sme
.assoc_req_ie_len
= 0;
443 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed copy WPA IE");
444 wpas_connect_work_done(wpa_s
);
449 #ifdef CONFIG_IEEE80211R
450 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
451 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
453 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
455 /* Prepare for the next transition */
456 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
459 if (md
&& !wpa_key_mgmt_ft(ssid
->key_mgmt
))
462 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: FT mobility domain %02x%02x",
465 if (wpa_s
->sme
.assoc_req_ie_len
+ 5 <
466 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
467 struct rsn_mdie
*mdie
;
468 u8
*pos
= wpa_s
->sme
.assoc_req_ie
+
469 wpa_s
->sme
.assoc_req_ie_len
;
470 *pos
++ = WLAN_EID_MOBILITY_DOMAIN
;
471 *pos
++ = sizeof(*mdie
);
472 mdie
= (struct rsn_mdie
*) pos
;
473 os_memcpy(mdie
->mobility_domain
, md
,
474 MOBILITY_DOMAIN_ID_LEN
);
475 mdie
->ft_capab
= md
[MOBILITY_DOMAIN_ID_LEN
];
476 wpa_s
->sme
.assoc_req_ie_len
+= 5;
479 if (wpa_s
->sme
.prev_bssid_set
&& wpa_s
->sme
.ft_used
&&
480 os_memcmp(md
, wpa_s
->sme
.mobility_domain
, 2) == 0 &&
481 wpa_sm_has_ptk(wpa_s
->wpa
)) {
482 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying to use FT "
484 params
.auth_alg
= WPA_AUTH_ALG_FT
;
485 params
.ie
= wpa_s
->sme
.ft_ies
;
486 params
.ie_len
= wpa_s
->sme
.ft_ies_len
;
489 #endif /* CONFIG_IEEE80211R */
491 #ifdef CONFIG_IEEE80211W
492 wpa_s
->sme
.mfp
= wpas_get_ssid_pmf(wpa_s
, ssid
);
493 if (wpa_s
->sme
.mfp
!= NO_MGMT_FRAME_PROTECTION
) {
494 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
495 struct wpa_ie_data _ie
;
496 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &_ie
) == 0 &&
498 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
499 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Selected AP supports "
501 wpa_s
->sme
.mfp
= MGMT_FRAME_PROTECTION_REQUIRED
;
504 #endif /* CONFIG_IEEE80211W */
507 if (wpa_s
->global
->p2p
) {
511 pos
= wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
;
512 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
513 wpa_s
->sme
.assoc_req_ie_len
;
514 res
= wpas_p2p_assoc_req_ie(wpa_s
, bss
, pos
, len
,
517 wpa_s
->sme
.assoc_req_ie_len
+= res
;
519 #endif /* CONFIG_P2P */
522 if (wpa_s
->fst_ies
) {
523 int fst_ies_len
= wpabuf_len(wpa_s
->fst_ies
);
525 if (wpa_s
->sme
.assoc_req_ie_len
+ fst_ies_len
<=
526 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
527 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
528 wpa_s
->sme
.assoc_req_ie_len
,
529 wpabuf_head(wpa_s
->fst_ies
),
531 wpa_s
->sme
.assoc_req_ie_len
+= fst_ies_len
;
534 #endif /* CONFIG_FST */
536 sme_auth_handle_rrm(wpa_s
, bss
);
538 wpa_s
->sme
.assoc_req_ie_len
+= wpas_supp_op_class_ie(
539 wpa_s
, ssid
, bss
->freq
,
540 wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
541 sizeof(wpa_s
->sme
.assoc_req_ie
) - wpa_s
->sme
.assoc_req_ie_len
);
544 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_P2P_CLIENT
);
546 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_STATION
);
548 ext_capab_len
= wpas_build_ext_capab(wpa_s
, ext_capab
,
550 if (ext_capab_len
> 0) {
551 u8
*pos
= wpa_s
->sme
.assoc_req_ie
;
552 if (wpa_s
->sme
.assoc_req_ie_len
> 0 && pos
[0] == WLAN_EID_RSN
)
554 os_memmove(pos
+ ext_capab_len
, pos
,
555 wpa_s
->sme
.assoc_req_ie_len
-
556 (pos
- wpa_s
->sme
.assoc_req_ie
));
557 wpa_s
->sme
.assoc_req_ie_len
+= ext_capab_len
;
558 os_memcpy(pos
, ext_capab
, ext_capab_len
);
562 if (is_hs20_network(wpa_s
, ssid
, bss
)) {
565 hs20
= wpabuf_alloc(20 + MAX_ROAMING_CONS_OI_LEN
);
567 int pps_mo_id
= hs20_get_pps_mo_id(wpa_s
, ssid
);
570 wpas_hs20_add_indication(hs20
, pps_mo_id
,
571 get_hs20_version(bss
));
572 wpas_hs20_add_roam_cons_sel(hs20
, ssid
);
573 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
574 wpa_s
->sme
.assoc_req_ie_len
;
575 if (wpabuf_len(hs20
) <= len
) {
576 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
577 wpa_s
->sme
.assoc_req_ie_len
,
578 wpabuf_head(hs20
), wpabuf_len(hs20
));
579 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(hs20
);
584 #endif /* CONFIG_HS20 */
589 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Reinsert WPA IE");
591 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
592 wpa_s
->sme
.assoc_req_ie_len
;
594 if (len
> wpa_ie_len
) {
595 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
596 wpa_s
->sme
.assoc_req_ie_len
,
598 wpa_s
->sme
.assoc_req_ie_len
+= wpa_ie_len
;
600 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Failed to add WPA IE");
606 if (wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
]) {
607 struct wpabuf
*buf
= wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
];
610 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
611 wpa_s
->sme
.assoc_req_ie_len
;
612 if (wpabuf_len(buf
) <= len
) {
613 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
614 wpa_s
->sme
.assoc_req_ie_len
,
615 wpabuf_head(buf
), wpabuf_len(buf
));
616 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(buf
);
621 mbo_ie
= wpa_bss_get_vendor_ie(bss
, MBO_IE_VENDOR_TYPE
);
625 len
= wpas_mbo_ie(wpa_s
, wpa_s
->sme
.assoc_req_ie
+
626 wpa_s
->sme
.assoc_req_ie_len
,
627 sizeof(wpa_s
->sme
.assoc_req_ie
) -
628 wpa_s
->sme
.assoc_req_ie_len
,
629 !!mbo_attr_from_mbo_ie(mbo_ie
,
630 OCE_ATTR_ID_CAPA_IND
));
632 wpa_s
->sme
.assoc_req_ie_len
+= len
;
634 #endif /* CONFIG_MBO */
637 if (!skip_auth
&& params
.auth_alg
== WPA_AUTH_ALG_SAE
&&
638 pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
, ssid
, 0,
639 NULL
, WPA_KEY_MGMT_SAE
) == 0) {
640 wpa_dbg(wpa_s
, MSG_DEBUG
,
641 "PMKSA cache entry found - try to use PMKSA caching instead of new SAE authentication");
642 wpa_sm_set_pmk_from_pmksa(wpa_s
->wpa
);
643 params
.auth_alg
= WPA_AUTH_ALG_OPEN
;
644 wpa_s
->sme
.sae_pmksa_caching
= 1;
647 if (!skip_auth
&& params
.auth_alg
== WPA_AUTH_ALG_SAE
) {
649 resp
= sme_auth_build_sae_commit(wpa_s
, ssid
,
653 resp
= sme_auth_build_sae_confirm(wpa_s
, 0);
655 wpas_connection_failed(wpa_s
, bss
->bssid
);
658 params
.auth_data
= wpabuf_head(resp
);
659 params
.auth_data_len
= wpabuf_len(resp
);
660 wpa_s
->sme
.sae
.state
= start
? SAE_COMMITTED
: SAE_CONFIRMED
;
662 #endif /* CONFIG_SAE */
664 old_ssid
= wpa_s
->current_ssid
;
665 wpa_s
->current_ssid
= ssid
;
666 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
667 wpa_supplicant_initiate_eapol(wpa_s
);
670 /* TODO: FILS operations can in some cases be done between different
671 * network_ctx (i.e., same credentials can be used with multiple
673 if (params
.auth_alg
== WPA_AUTH_ALG_OPEN
&&
674 wpa_key_mgmt_fils(ssid
->key_mgmt
)) {
677 const u8
*realm
, *username
, *rrk
;
678 size_t realm_len
, username_len
, rrk_len
;
682 * Check FILS Indication element (FILS Information field) bits
683 * indicating supported authentication algorithms against local
684 * configuration (ssid->fils_dh_group). Try to use FILS
685 * authentication only if the AP supports the combination in the
686 * network profile. */
687 indic
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
688 if (!indic
|| indic
[1] < 2) {
689 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
690 " does not include FILS Indication element - cannot use FILS authentication with it",
691 MAC2STR(bss
->bssid
));
695 fils_info
= WPA_GET_LE16(indic
+ 2);
696 if (ssid
->fils_dh_group
== 0 && !(fils_info
& BIT(9))) {
697 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
698 " does not support FILS SK without PFS - cannot use FILS authentication with it",
699 MAC2STR(bss
->bssid
));
702 if (ssid
->fils_dh_group
!= 0 && !(fils_info
& BIT(10))) {
703 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
704 " does not support FILS SK with PFS - cannot use FILS authentication with it",
705 MAC2STR(bss
->bssid
));
709 if (wpa_s
->last_con_fail_realm
&&
710 eapol_sm_get_erp_info(wpa_s
->eapol
, &ssid
->eap
,
711 &username
, &username_len
,
712 &realm
, &realm_len
, &next_seq_num
,
713 &rrk
, &rrk_len
) == 0 &&
714 realm
&& realm_len
== wpa_s
->last_con_fail_realm_len
&&
715 os_memcmp(realm
, wpa_s
->last_con_fail_realm
,
717 wpa_printf(MSG_DEBUG
,
718 "SME: FILS authentication for this realm failed last time - try to regenerate ERP key hierarchy");
722 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
724 wpa_bss_get_fils_cache_id(bss
),
726 wpa_printf(MSG_DEBUG
,
727 "SME: Try to use FILS with PMKSA caching");
728 resp
= fils_build_auth(wpa_s
->wpa
, ssid
->fils_dh_group
, md
);
732 if (ssid
->fils_dh_group
)
733 wpa_printf(MSG_DEBUG
,
734 "SME: Try to use FILS SK authentication with PFS (DH Group %u)",
735 ssid
->fils_dh_group
);
737 wpa_printf(MSG_DEBUG
,
738 "SME: Try to use FILS SK authentication without PFS");
739 auth_alg
= ssid
->fils_dh_group
?
740 WPA_AUTH_ALG_FILS_SK_PFS
: WPA_AUTH_ALG_FILS
;
741 params
.auth_alg
= auth_alg
;
742 params
.auth_data
= wpabuf_head(resp
);
743 params
.auth_data_len
= wpabuf_len(resp
);
744 wpa_s
->sme
.auth_alg
= auth_alg
;
748 #endif /* CONFIG_FILS */
750 wpa_supplicant_cancel_sched_scan(wpa_s
);
751 wpa_supplicant_cancel_scan(wpa_s
);
753 wpa_msg(wpa_s
, MSG_INFO
, "SME: Trying to authenticate with " MACSTR
754 " (SSID='%s' freq=%d MHz)", MAC2STR(params
.bssid
),
755 wpa_ssid_txt(params
.ssid
, params
.ssid_len
), params
.freq
);
757 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
758 wpa_clear_keys(wpa_s
, bss
->bssid
);
759 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
760 if (old_ssid
!= wpa_s
->current_ssid
)
761 wpas_notify_network_changed(wpa_s
);
764 hs20_configure_frame_filters(wpa_s
);
765 #endif /* CONFIG_HS20 */
769 * If multi-channel concurrency is not supported, check for any
770 * frequency conflict. In case of any frequency conflict, remove the
771 * least prioritized connection.
773 if (wpa_s
->num_multichan_concurrent
< 2) {
775 num
= get_shared_radio_freqs(wpa_s
, &freq
, 1);
776 if (num
> 0 && freq
> 0 && freq
!= params
.freq
) {
777 wpa_printf(MSG_DEBUG
,
778 "Conflicting frequency found (%d != %d)",
780 if (wpas_p2p_handle_frequency_conflicts(wpa_s
,
783 wpas_connection_failed(wpa_s
, bss
->bssid
);
784 wpa_supplicant_mark_disassoc(wpa_s
);
786 wpas_connect_work_done(wpa_s
);
791 #endif /* CONFIG_P2P */
794 wpa_msg(wpa_s
, MSG_DEBUG
,
795 "SME: Skip authentication step on reassoc-to-same-BSS");
797 sme_associate(wpa_s
, ssid
->mode
, bss
->bssid
, WLAN_AUTH_OPEN
);
802 wpa_s
->sme
.auth_alg
= params
.auth_alg
;
803 if (wpa_drv_authenticate(wpa_s
, ¶ms
) < 0) {
804 wpa_msg(wpa_s
, MSG_INFO
, "SME: Authentication request to the "
806 wpas_connection_failed(wpa_s
, bss
->bssid
);
807 wpa_supplicant_mark_disassoc(wpa_s
);
809 wpas_connect_work_done(wpa_s
);
813 eloop_register_timeout(SME_AUTH_TIMEOUT
, 0, sme_auth_timer
, wpa_s
,
817 * Association will be started based on the authentication event from
825 static void sme_auth_start_cb(struct wpa_radio_work
*work
, int deinit
)
827 struct wpa_connect_work
*cwork
= work
->ctx
;
828 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
832 wpa_s
->connect_work
= NULL
;
834 wpas_connect_work_free(cwork
);
838 wpa_s
->connect_work
= work
;
840 if (cwork
->bss_removed
||
841 !wpas_valid_bss_ssid(wpa_s
, cwork
->bss
, cwork
->ssid
) ||
842 wpas_network_disabled(wpa_s
, cwork
->ssid
)) {
843 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: BSS/SSID entry for authentication not valid anymore - drop connection attempt");
844 wpas_connect_work_done(wpa_s
);
848 /* Starting new connection, so clear the possibly used WPA IE from the
849 * previous association. */
850 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
852 sme_send_authentication(wpa_s
, cwork
->bss
, cwork
->ssid
, 1);
856 void sme_authenticate(struct wpa_supplicant
*wpa_s
,
857 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
859 struct wpa_connect_work
*cwork
;
861 if (bss
== NULL
|| ssid
== NULL
)
863 if (wpa_s
->connect_work
) {
864 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Reject sme_authenticate() call since connect_work exist");
868 if (radio_work_pending(wpa_s
, "sme-connect")) {
870 * The previous sme-connect work might no longer be valid due to
871 * the fact that the BSS list was updated. In addition, it makes
872 * sense to adhere to the 'newer' decision.
874 wpa_dbg(wpa_s
, MSG_DEBUG
,
875 "SME: Remove previous pending sme-connect");
876 radio_remove_works(wpa_s
, "sme-connect", 0);
879 wpas_abort_ongoing_scan(wpa_s
);
881 cwork
= os_zalloc(sizeof(*cwork
));
889 wpa_s
->sme
.sae
.state
= SAE_NOTHING
;
890 wpa_s
->sme
.sae
.send_confirm
= 0;
891 wpa_s
->sme
.sae_group_index
= 0;
892 #endif /* CONFIG_SAE */
894 if (radio_add_work(wpa_s
, bss
->freq
, "sme-connect", 1,
895 sme_auth_start_cb
, cwork
) < 0)
896 wpas_connect_work_free(cwork
);
902 static int sme_external_auth_build_buf(struct wpabuf
*buf
,
903 struct wpabuf
*params
,
904 const u8
*sa
, const u8
*da
,
905 u16 auth_transaction
, u16 seq_num
)
907 struct ieee80211_mgmt
*resp
;
909 resp
= wpabuf_put(buf
, offsetof(struct ieee80211_mgmt
,
912 resp
->frame_control
= host_to_le16((WLAN_FC_TYPE_MGMT
<< 2) |
913 (WLAN_FC_STYPE_AUTH
<< 4));
914 os_memcpy(resp
->da
, da
, ETH_ALEN
);
915 os_memcpy(resp
->sa
, sa
, ETH_ALEN
);
916 os_memcpy(resp
->bssid
, da
, ETH_ALEN
);
917 resp
->u
.auth
.auth_alg
= host_to_le16(WLAN_AUTH_SAE
);
918 resp
->seq_ctrl
= host_to_le16(seq_num
<< 4);
919 resp
->u
.auth
.auth_transaction
= host_to_le16(auth_transaction
);
920 resp
->u
.auth
.status_code
= host_to_le16(WLAN_STATUS_SUCCESS
);
922 wpabuf_put_buf(buf
, params
);
928 static void sme_external_auth_send_sae_commit(struct wpa_supplicant
*wpa_s
,
930 struct wpa_ssid
*ssid
)
932 struct wpabuf
*resp
, *buf
;
934 resp
= sme_auth_build_sae_commit(wpa_s
, ssid
, bssid
, 1, 0);
938 wpa_s
->sme
.sae
.state
= SAE_COMMITTED
;
939 buf
= wpabuf_alloc(4 + SAE_COMMIT_MAX_LEN
+ wpabuf_len(resp
));
945 wpa_s
->sme
.seq_num
++;
946 sme_external_auth_build_buf(buf
, resp
, wpa_s
->own_addr
,
947 bssid
, 1, wpa_s
->sme
.seq_num
);
948 wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
), 1, 0);
954 static void sme_send_external_auth_status(struct wpa_supplicant
*wpa_s
,
957 struct external_auth params
;
959 os_memset(¶ms
, 0, sizeof(params
));
960 params
.status
= status
;
961 os_memcpy(params
.ssid
, wpa_s
->sme
.ext_auth
.ssid
,
962 wpa_s
->sme
.ext_auth
.ssid_len
);
963 params
.ssid_len
= wpa_s
->sme
.ext_auth
.ssid_len
;
964 os_memcpy(params
.bssid
, wpa_s
->sme
.ext_auth
.bssid
, ETH_ALEN
);
965 wpa_drv_send_external_auth_status(wpa_s
, ¶ms
);
969 static void sme_handle_external_auth_start(struct wpa_supplicant
*wpa_s
,
970 union wpa_event_data
*data
)
972 struct wpa_ssid
*ssid
;
973 size_t ssid_str_len
= data
->external_auth
.ssid_len
;
974 u8
*ssid_str
= data
->external_auth
.ssid
;
976 /* Get the SSID conf from the ssid string obtained */
977 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
978 if (!wpas_network_disabled(wpa_s
, ssid
) &&
979 ssid_str_len
== ssid
->ssid_len
&&
980 os_memcmp(ssid_str
, ssid
->ssid
, ssid_str_len
) == 0 &&
981 (ssid
->key_mgmt
& WPA_KEY_MGMT_SAE
))
985 sme_external_auth_send_sae_commit(wpa_s
,
986 data
->external_auth
.bssid
,
989 sme_send_external_auth_status(wpa_s
,
990 WLAN_STATUS_UNSPECIFIED_FAILURE
);
994 static void sme_external_auth_send_sae_confirm(struct wpa_supplicant
*wpa_s
,
997 struct wpabuf
*resp
, *buf
;
999 resp
= sme_auth_build_sae_confirm(wpa_s
, 1);
1001 wpa_printf(MSG_DEBUG
, "SAE: Confirm message buf alloc failure");
1005 wpa_s
->sme
.sae
.state
= SAE_CONFIRMED
;
1006 buf
= wpabuf_alloc(4 + SAE_CONFIRM_MAX_LEN
+ wpabuf_len(resp
));
1008 wpa_printf(MSG_DEBUG
, "SAE: Auth Confirm buf alloc failure");
1012 wpa_s
->sme
.seq_num
++;
1013 sme_external_auth_build_buf(buf
, resp
, wpa_s
->own_addr
,
1014 da
, 2, wpa_s
->sme
.seq_num
);
1015 wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
), 1, 0);
1021 void sme_external_auth_trigger(struct wpa_supplicant
*wpa_s
,
1022 union wpa_event_data
*data
)
1024 if (RSN_SELECTOR_GET(&data
->external_auth
.key_mgmt_suite
) !=
1025 RSN_AUTH_KEY_MGMT_SAE
)
1028 if (data
->external_auth
.action
== EXT_AUTH_START
) {
1029 os_memcpy(&wpa_s
->sme
.ext_auth
, data
,
1030 sizeof(struct external_auth
));
1031 wpa_s
->sme
.seq_num
= 0;
1032 wpa_s
->sme
.sae
.state
= SAE_NOTHING
;
1033 wpa_s
->sme
.sae
.send_confirm
= 0;
1034 wpa_s
->sme
.sae_group_index
= 0;
1035 sme_handle_external_auth_start(wpa_s
, data
);
1036 } else if (data
->external_auth
.action
== EXT_AUTH_ABORT
) {
1037 /* Report failure to driver for the wrong trigger */
1038 sme_send_external_auth_status(wpa_s
,
1039 WLAN_STATUS_UNSPECIFIED_FAILURE
);
1044 static int sme_sae_auth(struct wpa_supplicant
*wpa_s
, u16 auth_transaction
,
1045 u16 status_code
, const u8
*data
, size_t len
,
1046 int external
, const u8
*sa
)
1050 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SAE authentication transaction %u "
1051 "status code %u", auth_transaction
, status_code
);
1053 if (auth_transaction
== 1 &&
1054 status_code
== WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
&&
1055 wpa_s
->sme
.sae
.state
== SAE_COMMITTED
&&
1056 (external
|| wpa_s
->current_bss
) && wpa_s
->current_ssid
) {
1057 int default_groups
[] = { 19, 20, 21, 0 };
1060 groups
= wpa_s
->conf
->sae_groups
;
1061 if (!groups
|| groups
[0] <= 0)
1062 groups
= default_groups
;
1064 if (len
< sizeof(le16
)) {
1065 wpa_dbg(wpa_s
, MSG_DEBUG
,
1066 "SME: Too short SAE anti-clogging token request");
1069 group
= WPA_GET_LE16(data
);
1070 wpa_dbg(wpa_s
, MSG_DEBUG
,
1071 "SME: SAE anti-clogging token requested (group %u)",
1073 if (sae_group_allowed(&wpa_s
->sme
.sae
, groups
, group
) !=
1074 WLAN_STATUS_SUCCESS
) {
1075 wpa_dbg(wpa_s
, MSG_ERROR
,
1076 "SME: SAE group %u of anti-clogging request is invalid",
1080 wpabuf_free(wpa_s
->sme
.sae_token
);
1081 wpa_s
->sme
.sae_token
= wpabuf_alloc_copy(data
+ sizeof(le16
),
1082 len
- sizeof(le16
));
1084 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
1085 wpa_s
->current_ssid
, 2);
1087 sme_external_auth_send_sae_commit(
1088 wpa_s
, wpa_s
->sme
.ext_auth
.bssid
,
1089 wpa_s
->current_ssid
);
1093 if (auth_transaction
== 1 &&
1094 status_code
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1095 wpa_s
->sme
.sae
.state
== SAE_COMMITTED
&&
1096 (external
|| wpa_s
->current_bss
) && wpa_s
->current_ssid
) {
1097 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SAE group not supported");
1098 wpa_s
->sme
.sae_group_index
++;
1099 if (sme_set_sae_group(wpa_s
) < 0)
1100 return -1; /* no other groups enabled */
1101 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Try next enabled SAE group");
1103 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
1104 wpa_s
->current_ssid
, 1);
1106 sme_external_auth_send_sae_commit(
1107 wpa_s
, wpa_s
->sme
.ext_auth
.bssid
,
1108 wpa_s
->current_ssid
);
1112 if (auth_transaction
== 1 &&
1113 status_code
== WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER
) {
1114 const u8
*bssid
= sa
? sa
: wpa_s
->pending_bssid
;
1116 wpa_msg(wpa_s
, MSG_INFO
,
1117 WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER MACSTR
,
1122 if (status_code
!= WLAN_STATUS_SUCCESS
)
1125 if (auth_transaction
== 1) {
1128 groups
= wpa_s
->conf
->sae_groups
;
1130 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME SAE commit");
1131 if ((!external
&& wpa_s
->current_bss
== NULL
) ||
1132 wpa_s
->current_ssid
== NULL
)
1134 if (wpa_s
->sme
.sae
.state
!= SAE_COMMITTED
)
1136 if (groups
&& groups
[0] <= 0)
1138 res
= sae_parse_commit(&wpa_s
->sme
.sae
, data
, len
, NULL
, NULL
,
1140 if (res
== SAE_SILENTLY_DISCARD
) {
1141 wpa_printf(MSG_DEBUG
,
1142 "SAE: Drop commit message due to reflection attack");
1145 if (res
!= WLAN_STATUS_SUCCESS
)
1148 if (sae_process_commit(&wpa_s
->sme
.sae
) < 0) {
1149 wpa_printf(MSG_DEBUG
, "SAE: Failed to process peer "
1154 wpabuf_free(wpa_s
->sme
.sae_token
);
1155 wpa_s
->sme
.sae_token
= NULL
;
1157 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
1158 wpa_s
->current_ssid
, 0);
1160 sme_external_auth_send_sae_confirm(wpa_s
, sa
);
1162 } else if (auth_transaction
== 2) {
1163 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME SAE confirm");
1164 if (wpa_s
->sme
.sae
.state
!= SAE_CONFIRMED
)
1166 if (sae_check_confirm(&wpa_s
->sme
.sae
, data
, len
) < 0)
1168 wpa_s
->sme
.sae
.state
= SAE_ACCEPTED
;
1169 sae_clear_temp_data(&wpa_s
->sme
.sae
);
1172 /* Report success to driver */
1173 sme_send_external_auth_status(wpa_s
,
1174 WLAN_STATUS_SUCCESS
);
1184 void sme_external_auth_mgmt_rx(struct wpa_supplicant
*wpa_s
,
1185 const u8
*auth_frame
, size_t len
)
1187 const struct ieee80211_mgmt
*header
;
1190 header
= (const struct ieee80211_mgmt
*) auth_frame
;
1191 auth_length
= IEEE80211_HDRLEN
+ sizeof(header
->u
.auth
);
1193 if (len
< auth_length
) {
1194 /* Notify failure to the driver */
1195 sme_send_external_auth_status(wpa_s
,
1196 WLAN_STATUS_UNSPECIFIED_FAILURE
);
1200 if (le_to_host16(header
->u
.auth
.auth_alg
) == WLAN_AUTH_SAE
) {
1204 wpa_s
, le_to_host16(header
->u
.auth
.auth_transaction
),
1205 le_to_host16(header
->u
.auth
.status_code
),
1206 header
->u
.auth
.variable
,
1207 len
- auth_length
, 1, header
->sa
);
1209 /* Notify failure to the driver */
1210 sme_send_external_auth_status(
1211 wpa_s
, WLAN_STATUS_UNSPECIFIED_FAILURE
);
1217 wpa_printf(MSG_DEBUG
,
1218 "SME: SAE completed - setting PMK for 4-way handshake");
1219 wpa_sm_set_pmk(wpa_s
->wpa
, wpa_s
->sme
.sae
.pmk
, PMK_LEN
,
1220 wpa_s
->sme
.sae
.pmkid
, wpa_s
->pending_bssid
);
1224 #endif /* CONFIG_SAE */
1227 void sme_event_auth(struct wpa_supplicant
*wpa_s
, union wpa_event_data
*data
)
1229 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1232 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication event "
1233 "when network is not selected");
1237 if (wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) {
1238 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication event "
1239 "when not in authenticating state");
1243 if (os_memcmp(wpa_s
->pending_bssid
, data
->auth
.peer
, ETH_ALEN
) != 0) {
1244 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication with "
1245 "unexpected peer " MACSTR
,
1246 MAC2STR(data
->auth
.peer
));
1250 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Authentication response: peer=" MACSTR
1251 " auth_type=%d auth_transaction=%d status_code=%d",
1252 MAC2STR(data
->auth
.peer
), data
->auth
.auth_type
,
1253 data
->auth
.auth_transaction
, data
->auth
.status_code
);
1254 wpa_hexdump(MSG_MSGDUMP
, "SME: Authentication response IEs",
1255 data
->auth
.ies
, data
->auth
.ies_len
);
1257 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1260 if (data
->auth
.auth_type
== WLAN_AUTH_SAE
) {
1262 res
= sme_sae_auth(wpa_s
, data
->auth
.auth_transaction
,
1263 data
->auth
.status_code
, data
->auth
.ies
,
1264 data
->auth
.ies_len
, 0, NULL
);
1266 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1267 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1273 wpa_printf(MSG_DEBUG
, "SME: SAE completed - setting PMK for "
1275 wpa_sm_set_pmk(wpa_s
->wpa
, wpa_s
->sme
.sae
.pmk
, PMK_LEN
,
1276 wpa_s
->sme
.sae
.pmkid
, wpa_s
->pending_bssid
);
1278 #endif /* CONFIG_SAE */
1280 if (data
->auth
.status_code
!= WLAN_STATUS_SUCCESS
) {
1281 char *ie_txt
= NULL
;
1283 if (data
->auth
.ies
&& data
->auth
.ies_len
) {
1284 size_t buflen
= 2 * data
->auth
.ies_len
+ 1;
1285 ie_txt
= os_malloc(buflen
);
1287 wpa_snprintf_hex(ie_txt
, buflen
, data
->auth
.ies
,
1288 data
->auth
.ies_len
);
1291 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AUTH_REJECT MACSTR
1292 " auth_type=%u auth_transaction=%u status_code=%u%s%s",
1293 MAC2STR(data
->auth
.peer
), data
->auth
.auth_type
,
1294 data
->auth
.auth_transaction
, data
->auth
.status_code
,
1295 ie_txt
? " ie=" : "",
1296 ie_txt
? ie_txt
: "");
1300 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
||
1301 wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS_SK_PFS
)
1302 fils_connection_failure(wpa_s
);
1303 #endif /* CONFIG_FILS */
1305 if (data
->auth
.status_code
!=
1306 WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
||
1307 wpa_s
->sme
.auth_alg
== data
->auth
.auth_type
||
1308 wpa_s
->current_ssid
->auth_alg
== WPA_AUTH_ALG_LEAP
) {
1309 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1310 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1314 wpas_connect_work_done(wpa_s
);
1316 switch (data
->auth
.auth_type
) {
1317 case WLAN_AUTH_OPEN
:
1318 wpa_s
->current_ssid
->auth_alg
= WPA_AUTH_ALG_SHARED
;
1320 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying SHARED auth");
1321 wpa_supplicant_associate(wpa_s
, wpa_s
->current_bss
,
1322 wpa_s
->current_ssid
);
1325 case WLAN_AUTH_SHARED_KEY
:
1326 wpa_s
->current_ssid
->auth_alg
= WPA_AUTH_ALG_LEAP
;
1328 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying LEAP auth");
1329 wpa_supplicant_associate(wpa_s
, wpa_s
->current_bss
,
1330 wpa_s
->current_ssid
);
1338 #ifdef CONFIG_IEEE80211R
1339 if (data
->auth
.auth_type
== WLAN_AUTH_FT
) {
1340 const u8
*ric_ies
= NULL
;
1341 size_t ric_ies_len
= 0;
1343 if (wpa_s
->ric_ies
) {
1344 ric_ies
= wpabuf_head(wpa_s
->ric_ies
);
1345 ric_ies_len
= wpabuf_len(wpa_s
->ric_ies
);
1347 if (wpa_ft_process_response(wpa_s
->wpa
, data
->auth
.ies
,
1348 data
->auth
.ies_len
, 0,
1350 ric_ies
, ric_ies_len
) < 0) {
1351 wpa_dbg(wpa_s
, MSG_DEBUG
,
1352 "SME: FT Authentication response processing failed");
1353 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1355 " reason=%d locally_generated=1",
1356 MAC2STR(wpa_s
->pending_bssid
),
1357 WLAN_REASON_DEAUTH_LEAVING
);
1358 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1359 wpa_supplicant_mark_disassoc(wpa_s
);
1363 #endif /* CONFIG_IEEE80211R */
1366 if (data
->auth
.auth_type
== WLAN_AUTH_FILS_SK
||
1367 data
->auth
.auth_type
== WLAN_AUTH_FILS_SK_PFS
) {
1368 u16 expect_auth_type
;
1370 expect_auth_type
= wpa_s
->sme
.auth_alg
==
1371 WPA_AUTH_ALG_FILS_SK_PFS
? WLAN_AUTH_FILS_SK_PFS
:
1373 if (data
->auth
.auth_type
!= expect_auth_type
) {
1374 wpa_dbg(wpa_s
, MSG_DEBUG
,
1375 "SME: FILS Authentication response used different auth alg (%u; expected %u)",
1376 data
->auth
.auth_type
, expect_auth_type
);
1377 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1379 " reason=%d locally_generated=1",
1380 MAC2STR(wpa_s
->pending_bssid
),
1381 WLAN_REASON_DEAUTH_LEAVING
);
1382 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1383 wpa_supplicant_mark_disassoc(wpa_s
);
1387 if (fils_process_auth(wpa_s
->wpa
, wpa_s
->pending_bssid
,
1388 data
->auth
.ies
, data
->auth
.ies_len
) < 0) {
1389 wpa_dbg(wpa_s
, MSG_DEBUG
,
1390 "SME: FILS Authentication response processing failed");
1391 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1393 " reason=%d locally_generated=1",
1394 MAC2STR(wpa_s
->pending_bssid
),
1395 WLAN_REASON_DEAUTH_LEAVING
);
1396 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1397 wpa_supplicant_mark_disassoc(wpa_s
);
1401 #endif /* CONFIG_FILS */
1403 sme_associate(wpa_s
, ssid
->mode
, data
->auth
.peer
,
1404 data
->auth
.auth_type
);
1408 #ifdef CONFIG_IEEE80211R
1409 static void remove_ie(u8
*buf
, size_t *len
, u8 eid
)
1411 u8
*pos
, *next
, *end
;
1413 pos
= (u8
*) get_ie(buf
, *len
, eid
);
1415 next
= pos
+ 2 + pos
[1];
1418 os_memmove(pos
, next
, end
- next
);
1421 #endif /* CONFIG_IEEE80211R */
1424 void sme_associate(struct wpa_supplicant
*wpa_s
, enum wpas_mode mode
,
1425 const u8
*bssid
, u16 auth_type
)
1427 struct wpa_driver_associate_params params
;
1428 struct ieee802_11_elems elems
;
1430 u8 nonces
[2 * FILS_NONCE_LEN
];
1431 #endif /* CONFIG_FILS */
1432 #ifdef CONFIG_HT_OVERRIDES
1433 struct ieee80211_ht_capabilities htcaps
;
1434 struct ieee80211_ht_capabilities htcaps_mask
;
1435 #endif /* CONFIG_HT_OVERRIDES */
1436 #ifdef CONFIG_VHT_OVERRIDES
1437 struct ieee80211_vht_capabilities vhtcaps
;
1438 struct ieee80211_vht_capabilities vhtcaps_mask
;
1439 #endif /* CONFIG_VHT_OVERRIDES */
1441 os_memset(¶ms
, 0, sizeof(params
));
1444 if (auth_type
== WLAN_AUTH_FILS_SK
||
1445 auth_type
== WLAN_AUTH_FILS_SK_PFS
) {
1447 const u8
*snonce
, *anonce
;
1448 const unsigned int max_hlp
= 20;
1449 struct wpabuf
*hlp
[max_hlp
];
1450 unsigned int i
, num_hlp
= 0;
1451 struct fils_hlp_req
*req
;
1453 dl_list_for_each(req
, &wpa_s
->fils_hlp_req
, struct fils_hlp_req
,
1455 hlp
[num_hlp
] = wpabuf_alloc(2 * ETH_ALEN
+ 6 +
1456 wpabuf_len(req
->pkt
));
1459 wpabuf_put_data(hlp
[num_hlp
], req
->dst
, ETH_ALEN
);
1460 wpabuf_put_data(hlp
[num_hlp
], wpa_s
->own_addr
,
1462 wpabuf_put_data(hlp
[num_hlp
],
1463 "\xaa\xaa\x03\x00\x00\x00", 6);
1464 wpabuf_put_buf(hlp
[num_hlp
], req
->pkt
);
1466 if (num_hlp
>= max_hlp
)
1470 buf
= fils_build_assoc_req(wpa_s
->wpa
, ¶ms
.fils_kek
,
1471 ¶ms
.fils_kek_len
, &snonce
,
1473 (const struct wpabuf
**) hlp
,
1475 for (i
= 0; i
< num_hlp
; i
++)
1476 wpabuf_free(hlp
[i
]);
1479 wpa_hexdump(MSG_DEBUG
, "FILS: assoc_req before FILS elements",
1480 wpa_s
->sme
.assoc_req_ie
,
1481 wpa_s
->sme
.assoc_req_ie_len
);
1482 #ifdef CONFIG_IEEE80211R
1483 if (wpa_key_mgmt_ft(wpa_s
->key_mgmt
)) {
1484 /* Remove RSNE and MDE to allow them to be overridden
1485 * with FILS+FT specific values from
1486 * fils_build_assoc_req(). */
1487 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1488 &wpa_s
->sme
.assoc_req_ie_len
,
1490 wpa_hexdump(MSG_DEBUG
,
1491 "FILS: assoc_req after RSNE removal",
1492 wpa_s
->sme
.assoc_req_ie
,
1493 wpa_s
->sme
.assoc_req_ie_len
);
1494 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1495 &wpa_s
->sme
.assoc_req_ie_len
,
1496 WLAN_EID_MOBILITY_DOMAIN
);
1497 wpa_hexdump(MSG_DEBUG
,
1498 "FILS: assoc_req after MDE removal",
1499 wpa_s
->sme
.assoc_req_ie
,
1500 wpa_s
->sme
.assoc_req_ie_len
);
1502 #endif /* CONFIG_IEEE80211R */
1503 /* TODO: Make wpa_s->sme.assoc_req_ie use dynamic allocation */
1504 if (wpa_s
->sme
.assoc_req_ie_len
+ wpabuf_len(buf
) >
1505 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1506 wpa_printf(MSG_ERROR
,
1507 "FILS: Not enough buffer room for own AssocReq elements");
1511 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1512 wpabuf_head(buf
), wpabuf_len(buf
));
1513 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(buf
);
1515 wpa_hexdump(MSG_DEBUG
, "FILS: assoc_req after FILS elements",
1516 wpa_s
->sme
.assoc_req_ie
,
1517 wpa_s
->sme
.assoc_req_ie_len
);
1519 os_memcpy(nonces
, snonce
, FILS_NONCE_LEN
);
1520 os_memcpy(nonces
+ FILS_NONCE_LEN
, anonce
, FILS_NONCE_LEN
);
1521 params
.fils_nonces
= nonces
;
1522 params
.fils_nonces_len
= sizeof(nonces
);
1524 #endif /* CONFIG_FILS */
1527 #ifdef CONFIG_TESTING_OPTIONS
1528 if (get_ie_ext(wpa_s
->sme
.assoc_req_ie
, wpa_s
->sme
.assoc_req_ie_len
,
1529 WLAN_EID_EXT_OWE_DH_PARAM
)) {
1530 wpa_printf(MSG_INFO
, "TESTING: Override OWE DH element");
1532 #endif /* CONFIG_TESTING_OPTIONS */
1533 if (auth_type
== WLAN_AUTH_OPEN
&&
1534 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
) {
1535 struct wpabuf
*owe_ie
;
1538 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->owe_group
) {
1539 group
= wpa_s
->current_ssid
->owe_group
;
1540 } else if (wpa_s
->assoc_status_code
==
1541 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
) {
1542 if (wpa_s
->last_owe_group
== 19)
1544 else if (wpa_s
->last_owe_group
== 20)
1547 group
= OWE_DH_GROUP
;
1549 group
= OWE_DH_GROUP
;
1552 wpa_s
->last_owe_group
= group
;
1553 wpa_printf(MSG_DEBUG
, "OWE: Try to use group %u", group
);
1554 owe_ie
= owe_build_assoc_req(wpa_s
->wpa
, group
);
1556 wpa_printf(MSG_ERROR
,
1557 "OWE: Failed to build IE for Association Request frame");
1560 if (wpa_s
->sme
.assoc_req_ie_len
+ wpabuf_len(owe_ie
) >
1561 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1562 wpa_printf(MSG_ERROR
,
1563 "OWE: Not enough buffer room for own Association Request frame elements");
1564 wpabuf_free(owe_ie
);
1567 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1568 wpabuf_head(owe_ie
), wpabuf_len(owe_ie
));
1569 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(owe_ie
);
1570 wpabuf_free(owe_ie
);
1572 #endif /* CONFIG_OWE */
1574 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->multi_ap_backhaul_sta
) {
1575 size_t multi_ap_ie_len
;
1577 multi_ap_ie_len
= add_multi_ap_ie(
1578 wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1579 sizeof(wpa_s
->sme
.assoc_req_ie
) -
1580 wpa_s
->sme
.assoc_req_ie_len
,
1581 MULTI_AP_BACKHAUL_STA
);
1582 if (multi_ap_ie_len
== 0) {
1583 wpa_printf(MSG_ERROR
,
1584 "Multi-AP: Failed to build Multi-AP IE");
1587 wpa_s
->sme
.assoc_req_ie_len
+= multi_ap_ie_len
;
1590 params
.bssid
= bssid
;
1591 params
.ssid
= wpa_s
->sme
.ssid
;
1592 params
.ssid_len
= wpa_s
->sme
.ssid_len
;
1593 params
.freq
.freq
= wpa_s
->sme
.freq
;
1594 params
.bg_scan_period
= wpa_s
->current_ssid
?
1595 wpa_s
->current_ssid
->bg_scan_period
: -1;
1596 params
.wpa_ie
= wpa_s
->sme
.assoc_req_ie_len
?
1597 wpa_s
->sme
.assoc_req_ie
: NULL
;
1598 params
.wpa_ie_len
= wpa_s
->sme
.assoc_req_ie_len
;
1599 wpa_hexdump(MSG_DEBUG
, "SME: Association Request IEs",
1600 params
.wpa_ie
, params
.wpa_ie_len
);
1601 params
.pairwise_suite
= wpa_s
->pairwise_cipher
;
1602 params
.group_suite
= wpa_s
->group_cipher
;
1603 params
.mgmt_group_suite
= wpa_s
->mgmt_group_cipher
;
1604 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
1605 params
.wpa_proto
= wpa_s
->wpa_proto
;
1606 #ifdef CONFIG_HT_OVERRIDES
1607 os_memset(&htcaps
, 0, sizeof(htcaps
));
1608 os_memset(&htcaps_mask
, 0, sizeof(htcaps_mask
));
1609 params
.htcaps
= (u8
*) &htcaps
;
1610 params
.htcaps_mask
= (u8
*) &htcaps_mask
;
1611 wpa_supplicant_apply_ht_overrides(wpa_s
, wpa_s
->current_ssid
, ¶ms
);
1612 #endif /* CONFIG_HT_OVERRIDES */
1613 #ifdef CONFIG_VHT_OVERRIDES
1614 os_memset(&vhtcaps
, 0, sizeof(vhtcaps
));
1615 os_memset(&vhtcaps_mask
, 0, sizeof(vhtcaps_mask
));
1616 params
.vhtcaps
= &vhtcaps
;
1617 params
.vhtcaps_mask
= &vhtcaps_mask
;
1618 wpa_supplicant_apply_vht_overrides(wpa_s
, wpa_s
->current_ssid
, ¶ms
);
1619 #endif /* CONFIG_VHT_OVERRIDES */
1620 #ifdef CONFIG_IEEE80211R
1621 if (auth_type
== WLAN_AUTH_FT
&& wpa_s
->sme
.ft_ies
&&
1622 get_ie(wpa_s
->sme
.ft_ies
, wpa_s
->sme
.ft_ies_len
,
1623 WLAN_EID_RIC_DATA
)) {
1624 /* There seems to be a pretty inconvenient bug in the Linux
1625 * kernel IE splitting functionality when RIC is used. For now,
1626 * skip correct behavior in IE construction here (i.e., drop the
1627 * additional non-FT-specific IEs) to avoid kernel issues. This
1628 * is fine since RIC is used only for testing purposes in the
1629 * current implementation. */
1630 wpa_printf(MSG_INFO
,
1631 "SME: Linux kernel workaround - do not try to include additional IEs with RIC");
1632 params
.wpa_ie
= wpa_s
->sme
.ft_ies
;
1633 params
.wpa_ie_len
= wpa_s
->sme
.ft_ies_len
;
1634 } else if (auth_type
== WLAN_AUTH_FT
&& wpa_s
->sme
.ft_ies
) {
1635 const u8
*rm_en
, *pos
, *end
;
1636 size_t rm_en_len
= 0;
1637 u8
*rm_en_dup
= NULL
, *wpos
;
1639 /* Remove RSNE, MDE, FTE to allow them to be overridden with
1640 * FT specific values */
1641 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1642 &wpa_s
->sme
.assoc_req_ie_len
,
1644 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1645 &wpa_s
->sme
.assoc_req_ie_len
,
1646 WLAN_EID_MOBILITY_DOMAIN
);
1647 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1648 &wpa_s
->sme
.assoc_req_ie_len
,
1649 WLAN_EID_FAST_BSS_TRANSITION
);
1650 rm_en
= get_ie(wpa_s
->sme
.assoc_req_ie
,
1651 wpa_s
->sme
.assoc_req_ie_len
,
1652 WLAN_EID_RRM_ENABLED_CAPABILITIES
);
1654 /* Need to remove RM Enabled Capabilities element as
1655 * well temporarily, so that it can be placed between
1657 rm_en_len
= 2 + rm_en
[1];
1658 rm_en_dup
= os_memdup(rm_en
, rm_en_len
);
1659 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1660 &wpa_s
->sme
.assoc_req_ie_len
,
1661 WLAN_EID_RRM_ENABLED_CAPABILITIES
);
1663 wpa_hexdump(MSG_DEBUG
,
1664 "SME: Association Request IEs after FT IE removal",
1665 wpa_s
->sme
.assoc_req_ie
,
1666 wpa_s
->sme
.assoc_req_ie_len
);
1667 if (wpa_s
->sme
.assoc_req_ie_len
+ wpa_s
->sme
.ft_ies_len
+
1668 rm_en_len
> sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1669 wpa_printf(MSG_ERROR
,
1670 "SME: Not enough buffer room for FT IEs in Association Request frame");
1675 os_memmove(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.ft_ies_len
+
1677 wpa_s
->sme
.assoc_req_ie
,
1678 wpa_s
->sme
.assoc_req_ie_len
);
1679 pos
= wpa_s
->sme
.ft_ies
;
1680 end
= pos
+ wpa_s
->sme
.ft_ies_len
;
1681 wpos
= wpa_s
->sme
.assoc_req_ie
;
1682 if (*pos
== WLAN_EID_RSN
) {
1683 os_memcpy(wpos
, pos
, 2 + pos
[1]);
1688 os_memcpy(wpos
, rm_en_dup
, rm_en_len
);
1692 os_memcpy(wpos
, pos
, end
- pos
);
1693 wpa_s
->sme
.assoc_req_ie_len
+= wpa_s
->sme
.ft_ies_len
+
1695 params
.wpa_ie
= wpa_s
->sme
.assoc_req_ie
;
1696 params
.wpa_ie_len
= wpa_s
->sme
.assoc_req_ie_len
;
1697 wpa_hexdump(MSG_DEBUG
,
1698 "SME: Association Request IEs after FT override",
1699 params
.wpa_ie
, params
.wpa_ie_len
);
1701 #endif /* CONFIG_IEEE80211R */
1703 params
.mgmt_frame_protection
= wpa_s
->sme
.mfp
;
1704 params
.rrm_used
= wpa_s
->rrm
.rrm_used
;
1705 if (wpa_s
->sme
.prev_bssid_set
)
1706 params
.prev_bssid
= wpa_s
->sme
.prev_bssid
;
1708 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
1709 " (SSID='%s' freq=%d MHz)", MAC2STR(params
.bssid
),
1710 params
.ssid
? wpa_ssid_txt(params
.ssid
, params
.ssid_len
) : "",
1713 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
1715 if (params
.wpa_ie
== NULL
||
1716 ieee802_11_parse_elems(params
.wpa_ie
, params
.wpa_ie_len
, &elems
, 0)
1718 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Could not parse own IEs?!");
1719 os_memset(&elems
, 0, sizeof(elems
));
1722 params
.wpa_proto
= WPA_PROTO_RSN
;
1723 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.rsn_ie
- 2,
1724 elems
.rsn_ie_len
+ 2);
1725 } else if (elems
.wpa_ie
) {
1726 params
.wpa_proto
= WPA_PROTO_WPA
;
1727 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.wpa_ie
- 2,
1728 elems
.wpa_ie_len
+ 2);
1729 } else if (elems
.osen
) {
1730 params
.wpa_proto
= WPA_PROTO_OSEN
;
1731 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.osen
- 2,
1732 elems
.osen_len
+ 2);
1734 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1735 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
)
1738 if (wpa_s
->p2pdev
->set_sta_uapsd
)
1739 params
.uapsd
= wpa_s
->p2pdev
->sta_uapsd
;
1743 if (wpa_drv_associate(wpa_s
, ¶ms
) < 0) {
1744 wpa_msg(wpa_s
, MSG_INFO
, "SME: Association request to the "
1746 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1747 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1748 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1752 eloop_register_timeout(SME_ASSOC_TIMEOUT
, 0, sme_assoc_timer
, wpa_s
,
1755 #ifdef CONFIG_TESTING_OPTIONS
1756 wpabuf_free(wpa_s
->last_assoc_req_wpa_ie
);
1757 wpa_s
->last_assoc_req_wpa_ie
= NULL
;
1759 wpa_s
->last_assoc_req_wpa_ie
=
1760 wpabuf_alloc_copy(params
.wpa_ie
, params
.wpa_ie_len
);
1761 #endif /* CONFIG_TESTING_OPTIONS */
1765 int sme_update_ft_ies(struct wpa_supplicant
*wpa_s
, const u8
*md
,
1766 const u8
*ies
, size_t ies_len
)
1768 if (md
== NULL
|| ies
== NULL
) {
1769 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Remove mobility domain");
1770 os_free(wpa_s
->sme
.ft_ies
);
1771 wpa_s
->sme
.ft_ies
= NULL
;
1772 wpa_s
->sme
.ft_ies_len
= 0;
1773 wpa_s
->sme
.ft_used
= 0;
1777 os_memcpy(wpa_s
->sme
.mobility_domain
, md
, MOBILITY_DOMAIN_ID_LEN
);
1778 wpa_hexdump(MSG_DEBUG
, "SME: FT IEs", ies
, ies_len
);
1779 os_free(wpa_s
->sme
.ft_ies
);
1780 wpa_s
->sme
.ft_ies
= os_memdup(ies
, ies_len
);
1781 if (wpa_s
->sme
.ft_ies
== NULL
)
1783 wpa_s
->sme
.ft_ies_len
= ies_len
;
1788 static void sme_deauth(struct wpa_supplicant
*wpa_s
)
1792 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
1794 if (wpa_drv_deauthenticate(wpa_s
, wpa_s
->pending_bssid
,
1795 WLAN_REASON_DEAUTH_LEAVING
) < 0) {
1796 wpa_msg(wpa_s
, MSG_INFO
, "SME: Deauth request to the driver "
1799 wpa_s
->sme
.prev_bssid_set
= 0;
1801 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1802 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1803 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
1804 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1806 wpas_notify_bssid_changed(wpa_s
);
1810 void sme_event_assoc_reject(struct wpa_supplicant
*wpa_s
,
1811 union wpa_event_data
*data
)
1813 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association with " MACSTR
" failed: "
1814 "status code %d", MAC2STR(wpa_s
->pending_bssid
),
1815 data
->assoc_reject
.status_code
);
1817 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
1820 if (wpa_s
->sme
.sae_pmksa_caching
&& wpa_s
->current_ssid
&&
1821 wpa_key_mgmt_sae(wpa_s
->current_ssid
->key_mgmt
)) {
1822 wpa_dbg(wpa_s
, MSG_DEBUG
,
1823 "PMKSA caching attempt rejected - drop PMKSA cache entry and fall back to SAE authentication");
1824 wpa_sm_aborted_cached(wpa_s
->wpa
);
1825 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
1826 if (wpa_s
->current_bss
) {
1827 struct wpa_bss
*bss
= wpa_s
->current_bss
;
1828 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1830 wpa_drv_deauthenticate(wpa_s
, wpa_s
->pending_bssid
,
1831 WLAN_REASON_DEAUTH_LEAVING
);
1832 wpas_connect_work_done(wpa_s
);
1833 wpa_supplicant_mark_disassoc(wpa_s
);
1834 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
1838 #endif /* CONFIG_SAE */
1841 * For now, unconditionally terminate the previous authentication. In
1842 * theory, this should not be needed, but mac80211 gets quite confused
1843 * if the authentication is left pending.. Some roaming cases might
1844 * benefit from using the previous authentication, so this could be
1845 * optimized in the future.
1851 void sme_event_auth_timed_out(struct wpa_supplicant
*wpa_s
,
1852 union wpa_event_data
*data
)
1854 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Authentication timed out");
1855 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1856 wpa_supplicant_mark_disassoc(wpa_s
);
1860 void sme_event_assoc_timed_out(struct wpa_supplicant
*wpa_s
,
1861 union wpa_event_data
*data
)
1863 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association timed out");
1864 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1865 wpa_supplicant_mark_disassoc(wpa_s
);
1869 void sme_event_disassoc(struct wpa_supplicant
*wpa_s
,
1870 struct disassoc_info
*info
)
1872 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Disassociation event received");
1873 if (wpa_s
->sme
.prev_bssid_set
) {
1875 * cfg80211/mac80211 can get into somewhat confused state if
1876 * the AP only disassociates us and leaves us in authenticated
1877 * state. For now, force the state to be cleared to avoid
1878 * confusing errors if we try to associate with the AP again.
1880 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Deauthenticate to clear "
1882 wpa_drv_deauthenticate(wpa_s
, wpa_s
->sme
.prev_bssid
,
1883 WLAN_REASON_DEAUTH_LEAVING
);
1888 static void sme_auth_timer(void *eloop_ctx
, void *timeout_ctx
)
1890 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1891 if (wpa_s
->wpa_state
== WPA_AUTHENTICATING
) {
1892 wpa_msg(wpa_s
, MSG_DEBUG
, "SME: Authentication timeout");
1898 static void sme_assoc_timer(void *eloop_ctx
, void *timeout_ctx
)
1900 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1901 if (wpa_s
->wpa_state
== WPA_ASSOCIATING
) {
1902 wpa_msg(wpa_s
, MSG_DEBUG
, "SME: Association timeout");
1908 void sme_state_changed(struct wpa_supplicant
*wpa_s
)
1910 /* Make sure timers are cleaned up appropriately. */
1911 if (wpa_s
->wpa_state
!= WPA_ASSOCIATING
)
1912 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
1913 if (wpa_s
->wpa_state
!= WPA_AUTHENTICATING
)
1914 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1918 void sme_disassoc_while_authenticating(struct wpa_supplicant
*wpa_s
,
1919 const u8
*prev_pending_bssid
)
1922 * mac80211-workaround to force deauth on failed auth cmd,
1923 * requires us to remain in authenticating state to allow the
1924 * second authentication attempt to be continued properly.
1926 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Allow pending authentication "
1927 "to proceed after disconnection event");
1928 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
1929 os_memcpy(wpa_s
->pending_bssid
, prev_pending_bssid
, ETH_ALEN
);
1932 * Re-arm authentication timer in case auth fails for whatever reason.
1934 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1935 eloop_register_timeout(SME_AUTH_TIMEOUT
, 0, sme_auth_timer
, wpa_s
,
1940 void sme_clear_on_disassoc(struct wpa_supplicant
*wpa_s
)
1942 wpa_s
->sme
.prev_bssid_set
= 0;
1944 wpabuf_free(wpa_s
->sme
.sae_token
);
1945 wpa_s
->sme
.sae_token
= NULL
;
1946 sae_clear_data(&wpa_s
->sme
.sae
);
1947 #endif /* CONFIG_SAE */
1948 #ifdef CONFIG_IEEE80211R
1949 if (wpa_s
->sme
.ft_ies
|| wpa_s
->sme
.ft_used
)
1950 sme_update_ft_ies(wpa_s
, NULL
, NULL
, 0);
1951 #endif /* CONFIG_IEEE80211R */
1955 void sme_deinit(struct wpa_supplicant
*wpa_s
)
1957 os_free(wpa_s
->sme
.ft_ies
);
1958 wpa_s
->sme
.ft_ies
= NULL
;
1959 wpa_s
->sme
.ft_ies_len
= 0;
1960 #ifdef CONFIG_IEEE80211W
1961 sme_stop_sa_query(wpa_s
);
1962 #endif /* CONFIG_IEEE80211W */
1963 sme_clear_on_disassoc(wpa_s
);
1965 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
1966 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1967 eloop_cancel_timeout(sme_obss_scan_timeout
, wpa_s
, NULL
);
1971 static void sme_send_2040_bss_coex(struct wpa_supplicant
*wpa_s
,
1972 const u8
*chan_list
, u8 num_channels
,
1975 struct ieee80211_2040_bss_coex_ie
*bc_ie
;
1976 struct ieee80211_2040_intol_chan_report
*ic_report
;
1979 wpa_printf(MSG_DEBUG
, "SME: Send 20/40 BSS Coexistence to " MACSTR
1980 " (num_channels=%u num_intol=%u)",
1981 MAC2STR(wpa_s
->bssid
), num_channels
, num_intol
);
1982 wpa_hexdump(MSG_DEBUG
, "SME: 20/40 BSS Intolerant Channels",
1983 chan_list
, num_channels
);
1985 buf
= wpabuf_alloc(2 + /* action.category + action_code */
1986 sizeof(struct ieee80211_2040_bss_coex_ie
) +
1987 sizeof(struct ieee80211_2040_intol_chan_report
) +
1992 wpabuf_put_u8(buf
, WLAN_ACTION_PUBLIC
);
1993 wpabuf_put_u8(buf
, WLAN_PA_20_40_BSS_COEX
);
1995 bc_ie
= wpabuf_put(buf
, sizeof(*bc_ie
));
1996 bc_ie
->element_id
= WLAN_EID_20_40_BSS_COEXISTENCE
;
1999 bc_ie
->coex_param
|= WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ
;
2001 if (num_channels
> 0) {
2002 ic_report
= wpabuf_put(buf
, sizeof(*ic_report
));
2003 ic_report
->element_id
= WLAN_EID_20_40_BSS_INTOLERANT
;
2004 ic_report
->length
= num_channels
+ 1;
2005 ic_report
->op_class
= 0;
2006 os_memcpy(wpabuf_put(buf
, num_channels
), chan_list
,
2010 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
2011 wpa_s
->own_addr
, wpa_s
->bssid
,
2012 wpabuf_head(buf
), wpabuf_len(buf
), 0) < 0) {
2013 wpa_msg(wpa_s
, MSG_INFO
,
2014 "SME: Failed to send 20/40 BSS Coexistence frame");
2021 int sme_proc_obss_scan(struct wpa_supplicant
*wpa_s
)
2023 struct wpa_bss
*bss
;
2026 u8 chan_list
[P2P_MAX_CHANNELS
], channel
;
2027 u8 num_channels
= 0, num_intol
= 0, i
;
2029 if (!wpa_s
->sme
.sched_obss_scan
)
2032 wpa_s
->sme
.sched_obss_scan
= 0;
2033 if (!wpa_s
->current_bss
|| wpa_s
->wpa_state
!= WPA_COMPLETED
)
2037 * Check whether AP uses regulatory triplet or channel triplet in
2038 * country info. Right now the operating class of the BSS channel
2039 * width trigger event is "unknown" (IEEE Std 802.11-2012 10.15.12),
2040 * based on the assumption that operating class triplet is not used in
2041 * beacon frame. If the First Channel Number/Operating Extension
2042 * Identifier octet has a positive integer value of 201 or greater,
2043 * then its operating class triplet.
2045 * TODO: If Supported Operating Classes element is present in beacon
2046 * frame, have to lookup operating class in Annex E and fill them in
2049 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_COUNTRY
);
2050 if (ie
&& (ie
[1] >= 6) && (ie
[5] >= 201))
2053 os_memset(chan_list
, 0, sizeof(chan_list
));
2055 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2056 /* Skip other band bss */
2057 enum hostapd_hw_mode mode
;
2058 mode
= ieee80211_freq_to_chan(bss
->freq
, &channel
);
2059 if (mode
!= HOSTAPD_MODE_IEEE80211G
&&
2060 mode
!= HOSTAPD_MODE_IEEE80211B
)
2063 ie
= wpa_bss_get_ie(bss
, WLAN_EID_HT_CAP
);
2064 ht_cap
= (ie
&& (ie
[1] == 26)) ? WPA_GET_LE16(ie
+ 2) : 0;
2065 wpa_printf(MSG_DEBUG
, "SME OBSS scan BSS " MACSTR
2066 " freq=%u chan=%u ht_cap=0x%x",
2067 MAC2STR(bss
->bssid
), bss
->freq
, channel
, ht_cap
);
2069 if (!ht_cap
|| (ht_cap
& HT_CAP_INFO_40MHZ_INTOLERANT
)) {
2070 if (ht_cap
& HT_CAP_INFO_40MHZ_INTOLERANT
)
2073 /* Check whether the channel is already considered */
2074 for (i
= 0; i
< num_channels
; i
++) {
2075 if (channel
== chan_list
[i
])
2078 if (i
!= num_channels
)
2081 chan_list
[num_channels
++] = channel
;
2085 sme_send_2040_bss_coex(wpa_s
, chan_list
, num_channels
, num_intol
);
2090 static void wpa_obss_scan_freqs_list(struct wpa_supplicant
*wpa_s
,
2091 struct wpa_driver_scan_params
*params
)
2093 /* Include only affected channels */
2094 struct hostapd_hw_modes
*mode
;
2098 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
,
2099 HOSTAPD_MODE_IEEE80211G
);
2101 /* No channels supported in this band - use empty list */
2102 params
->freqs
= os_zalloc(sizeof(int));
2106 if (wpa_s
->sme
.ht_sec_chan
== HT_SEC_CHAN_UNKNOWN
&&
2107 wpa_s
->current_bss
) {
2110 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_HT_OPERATION
);
2111 if (ie
&& ie
[1] >= 2) {
2114 o
= ie
[3] & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK
;
2115 if (o
== HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE
)
2116 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_ABOVE
;
2117 else if (o
== HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW
)
2118 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_BELOW
;
2122 start
= wpa_s
->assoc_freq
- 10;
2123 end
= wpa_s
->assoc_freq
+ 10;
2124 switch (wpa_s
->sme
.ht_sec_chan
) {
2125 case HT_SEC_CHAN_UNKNOWN
:
2126 /* HT40+ possible on channels 1..9 */
2127 if (wpa_s
->assoc_freq
<= 2452)
2129 /* HT40- possible on channels 5-13 */
2130 if (wpa_s
->assoc_freq
>= 2432)
2133 case HT_SEC_CHAN_ABOVE
:
2136 case HT_SEC_CHAN_BELOW
:
2140 wpa_printf(MSG_DEBUG
,
2141 "OBSS: assoc_freq %d possible affected range %d-%d",
2142 wpa_s
->assoc_freq
, start
, end
);
2144 params
->freqs
= os_calloc(mode
->num_channels
+ 1, sizeof(int));
2145 if (params
->freqs
== NULL
)
2147 for (count
= 0, i
= 0; i
< mode
->num_channels
; i
++) {
2150 if (mode
->channels
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
2152 freq
= mode
->channels
[i
].freq
;
2153 if (freq
- 10 >= end
|| freq
+ 10 <= start
)
2154 continue; /* not affected */
2155 params
->freqs
[count
++] = freq
;
2160 static void sme_obss_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
2162 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2163 struct wpa_driver_scan_params params
;
2165 if (!wpa_s
->current_bss
) {
2166 wpa_printf(MSG_DEBUG
, "SME OBSS: Ignore scan request");
2170 os_memset(¶ms
, 0, sizeof(params
));
2171 wpa_obss_scan_freqs_list(wpa_s
, ¶ms
);
2172 params
.low_priority
= 1;
2173 wpa_printf(MSG_DEBUG
, "SME OBSS: Request an OBSS scan");
2175 if (wpa_supplicant_trigger_scan(wpa_s
, ¶ms
))
2176 wpa_printf(MSG_DEBUG
, "SME OBSS: Failed to trigger scan");
2178 wpa_s
->sme
.sched_obss_scan
= 1;
2179 os_free(params
.freqs
);
2181 eloop_register_timeout(wpa_s
->sme
.obss_scan_int
, 0,
2182 sme_obss_scan_timeout
, wpa_s
, NULL
);
2186 void sme_sched_obss_scan(struct wpa_supplicant
*wpa_s
, int enable
)
2189 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2190 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2191 struct hostapd_hw_modes
*hw_mode
= NULL
;
2194 eloop_cancel_timeout(sme_obss_scan_timeout
, wpa_s
, NULL
);
2195 wpa_s
->sme
.sched_obss_scan
= 0;
2196 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_UNKNOWN
;
2201 * Schedule OBSS scan if driver is using station SME in wpa_supplicant
2202 * or it expects OBSS scan to be performed by wpa_supplicant.
2204 if (!((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) ||
2205 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OBSS_SCAN
)) ||
2206 ssid
== NULL
|| ssid
->mode
!= IEEE80211_MODE_INFRA
)
2209 if (!wpa_s
->hw
.modes
)
2212 /* only HT caps in 11g mode are relevant */
2213 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
2214 hw_mode
= &wpa_s
->hw
.modes
[i
];
2215 if (hw_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
2219 /* Driver does not support HT40 for 11g or doesn't have 11g. */
2220 if (i
== wpa_s
->hw
.num_modes
|| !hw_mode
||
2221 !(hw_mode
->ht_capab
& HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
2224 if (bss
== NULL
|| bss
->freq
< 2400 || bss
->freq
> 2500)
2225 return; /* Not associated on 2.4 GHz band */
2227 /* Check whether AP supports HT40 */
2228 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_HT_CAP
);
2229 if (!ie
|| ie
[1] < 2 ||
2230 !(WPA_GET_LE16(ie
+ 2) & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
2231 return; /* AP does not support HT40 */
2233 ie
= wpa_bss_get_ie(wpa_s
->current_bss
,
2234 WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS
);
2235 if (!ie
|| ie
[1] < 14)
2236 return; /* AP does not request OBSS scans */
2238 wpa_s
->sme
.obss_scan_int
= WPA_GET_LE16(ie
+ 6);
2239 if (wpa_s
->sme
.obss_scan_int
< 10) {
2240 wpa_printf(MSG_DEBUG
, "SME: Invalid OBSS Scan Interval %u "
2241 "replaced with the minimum 10 sec",
2242 wpa_s
->sme
.obss_scan_int
);
2243 wpa_s
->sme
.obss_scan_int
= 10;
2245 wpa_printf(MSG_DEBUG
, "SME: OBSS Scan Interval %u sec",
2246 wpa_s
->sme
.obss_scan_int
);
2247 eloop_register_timeout(wpa_s
->sme
.obss_scan_int
, 0,
2248 sme_obss_scan_timeout
, wpa_s
, NULL
);
2252 #ifdef CONFIG_IEEE80211W
2254 static const unsigned int sa_query_max_timeout
= 1000;
2255 static const unsigned int sa_query_retry_timeout
= 201;
2256 static const unsigned int sa_query_ch_switch_max_delay
= 5000; /* in usec */
2258 static int sme_check_sa_query_timeout(struct wpa_supplicant
*wpa_s
)
2261 struct os_reltime now
, passed
;
2262 os_get_reltime(&now
);
2263 os_reltime_sub(&now
, &wpa_s
->sme
.sa_query_start
, &passed
);
2264 tu
= (passed
.sec
* 1000000 + passed
.usec
) / 1024;
2265 if (sa_query_max_timeout
< tu
) {
2266 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SA Query timed out");
2267 sme_stop_sa_query(wpa_s
);
2268 wpa_supplicant_deauthenticate(
2269 wpa_s
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
2277 static void sme_send_sa_query_req(struct wpa_supplicant
*wpa_s
,
2280 u8 req
[2 + WLAN_SA_QUERY_TR_ID_LEN
+ OCV_OCI_EXTENDED_LEN
];
2281 u8 req_len
= 2 + WLAN_SA_QUERY_TR_ID_LEN
;
2283 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Sending SA Query Request to "
2284 MACSTR
, MAC2STR(wpa_s
->bssid
));
2285 wpa_hexdump(MSG_DEBUG
, "SME: SA Query Transaction ID",
2286 trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
2287 req
[0] = WLAN_ACTION_SA_QUERY
;
2288 req
[1] = WLAN_SA_QUERY_REQUEST
;
2289 os_memcpy(req
+ 2, trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
2292 if (wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
2293 struct wpa_channel_info ci
;
2295 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
2296 wpa_printf(MSG_WARNING
,
2297 "Failed to get channel info for OCI element in SA Query Request frame");
2301 if (ocv_insert_extended_oci(&ci
, req
+ req_len
) < 0)
2304 req_len
+= OCV_OCI_EXTENDED_LEN
;
2306 #endif /* CONFIG_OCV */
2308 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
2309 wpa_s
->own_addr
, wpa_s
->bssid
,
2310 req
, req_len
, 0) < 0)
2311 wpa_msg(wpa_s
, MSG_INFO
, "SME: Failed to send SA Query "
2316 static void sme_sa_query_timer(void *eloop_ctx
, void *timeout_ctx
)
2318 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2319 unsigned int timeout
, sec
, usec
;
2320 u8
*trans_id
, *nbuf
;
2322 if (wpa_s
->sme
.sa_query_count
> 0 &&
2323 sme_check_sa_query_timeout(wpa_s
))
2326 nbuf
= os_realloc_array(wpa_s
->sme
.sa_query_trans_id
,
2327 wpa_s
->sme
.sa_query_count
+ 1,
2328 WLAN_SA_QUERY_TR_ID_LEN
);
2330 sme_stop_sa_query(wpa_s
);
2333 if (wpa_s
->sme
.sa_query_count
== 0) {
2334 /* Starting a new SA Query procedure */
2335 os_get_reltime(&wpa_s
->sme
.sa_query_start
);
2337 trans_id
= nbuf
+ wpa_s
->sme
.sa_query_count
* WLAN_SA_QUERY_TR_ID_LEN
;
2338 wpa_s
->sme
.sa_query_trans_id
= nbuf
;
2339 wpa_s
->sme
.sa_query_count
++;
2341 if (os_get_random(trans_id
, WLAN_SA_QUERY_TR_ID_LEN
) < 0) {
2342 wpa_printf(MSG_DEBUG
, "Could not generate SA Query ID");
2343 sme_stop_sa_query(wpa_s
);
2347 timeout
= sa_query_retry_timeout
;
2348 sec
= ((timeout
/ 1000) * 1024) / 1000;
2349 usec
= (timeout
% 1000) * 1024;
2350 eloop_register_timeout(sec
, usec
, sme_sa_query_timer
, wpa_s
, NULL
);
2352 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association SA Query attempt %d",
2353 wpa_s
->sme
.sa_query_count
);
2355 sme_send_sa_query_req(wpa_s
, trans_id
);
2359 static void sme_start_sa_query(struct wpa_supplicant
*wpa_s
)
2361 sme_sa_query_timer(wpa_s
, NULL
);
2365 static void sme_stop_sa_query(struct wpa_supplicant
*wpa_s
)
2367 eloop_cancel_timeout(sme_sa_query_timer
, wpa_s
, NULL
);
2368 os_free(wpa_s
->sme
.sa_query_trans_id
);
2369 wpa_s
->sme
.sa_query_trans_id
= NULL
;
2370 wpa_s
->sme
.sa_query_count
= 0;
2374 void sme_event_unprot_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*sa
,
2375 const u8
*da
, u16 reason_code
)
2377 struct wpa_ssid
*ssid
;
2378 struct os_reltime now
;
2380 if (wpa_s
->wpa_state
!= WPA_COMPLETED
)
2382 ssid
= wpa_s
->current_ssid
;
2383 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == NO_MGMT_FRAME_PROTECTION
)
2385 if (os_memcmp(sa
, wpa_s
->bssid
, ETH_ALEN
) != 0)
2387 if (reason_code
!= WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
&&
2388 reason_code
!= WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
)
2390 if (wpa_s
->sme
.sa_query_count
> 0)
2393 os_get_reltime(&now
);
2394 if (wpa_s
->sme
.last_unprot_disconnect
.sec
&&
2395 !os_reltime_expired(&now
, &wpa_s
->sme
.last_unprot_disconnect
, 10))
2396 return; /* limit SA Query procedure frequency */
2397 wpa_s
->sme
.last_unprot_disconnect
= now
;
2399 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Unprotected disconnect dropped - "
2400 "possible AP/STA state mismatch - trigger SA Query");
2401 sme_start_sa_query(wpa_s
);
2405 void sme_event_ch_switch(struct wpa_supplicant
*wpa_s
)
2410 if (wpa_s
->wpa_state
!= WPA_COMPLETED
||
2411 !wpa_sm_ocv_enabled(wpa_s
->wpa
))
2414 wpa_dbg(wpa_s
, MSG_DEBUG
,
2415 "SME: Channel switch completed - trigger new SA Query to verify new operating channel");
2416 sme_stop_sa_query(wpa_s
);
2418 if (os_get_random((u8
*) &_rand
, sizeof(_rand
)) < 0)
2419 _rand
= os_random();
2420 usec
= _rand
% (sa_query_ch_switch_max_delay
+ 1);
2421 eloop_register_timeout(0, usec
, sme_sa_query_timer
, wpa_s
, NULL
);
2425 static void sme_process_sa_query_request(struct wpa_supplicant
*wpa_s
,
2426 const u8
*sa
, const u8
*data
,
2429 u8 resp
[2 + WLAN_SA_QUERY_TR_ID_LEN
+ OCV_OCI_EXTENDED_LEN
];
2430 u8 resp_len
= 2 + WLAN_SA_QUERY_TR_ID_LEN
;
2432 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Sending SA Query Response to "
2433 MACSTR
, MAC2STR(wpa_s
->bssid
));
2435 resp
[0] = WLAN_ACTION_SA_QUERY
;
2436 resp
[1] = WLAN_SA_QUERY_RESPONSE
;
2437 os_memcpy(resp
+ 2, data
+ 1, WLAN_SA_QUERY_TR_ID_LEN
);
2440 if (wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
2441 struct wpa_channel_info ci
;
2443 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
2444 wpa_printf(MSG_WARNING
,
2445 "Failed to get channel info for OCI element in SA Query Response frame");
2449 if (ocv_insert_extended_oci(&ci
, resp
+ resp_len
) < 0)
2452 resp_len
+= OCV_OCI_EXTENDED_LEN
;
2454 #endif /* CONFIG_OCV */
2456 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
2457 wpa_s
->own_addr
, wpa_s
->bssid
,
2458 resp
, resp_len
, 0) < 0)
2459 wpa_msg(wpa_s
, MSG_INFO
,
2460 "SME: Failed to send SA Query Response");
2464 static void sme_process_sa_query_response(struct wpa_supplicant
*wpa_s
,
2465 const u8
*sa
, const u8
*data
,
2470 if (!wpa_s
->sme
.sa_query_trans_id
)
2473 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Received SA Query response from "
2474 MACSTR
" (trans_id %02x%02x)", MAC2STR(sa
), data
[1], data
[2]);
2476 if (os_memcmp(sa
, wpa_s
->bssid
, ETH_ALEN
) != 0)
2479 for (i
= 0; i
< wpa_s
->sme
.sa_query_count
; i
++) {
2480 if (os_memcmp(wpa_s
->sme
.sa_query_trans_id
+
2481 i
* WLAN_SA_QUERY_TR_ID_LEN
,
2482 data
+ 1, WLAN_SA_QUERY_TR_ID_LEN
) == 0)
2486 if (i
>= wpa_s
->sme
.sa_query_count
) {
2487 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: No matching SA Query "
2488 "transaction identifier found");
2492 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Reply to pending SA Query received "
2493 "from " MACSTR
, MAC2STR(sa
));
2494 sme_stop_sa_query(wpa_s
);
2498 void sme_sa_query_rx(struct wpa_supplicant
*wpa_s
, const u8
*sa
,
2499 const u8
*data
, size_t len
)
2501 if (len
< 1 + WLAN_SA_QUERY_TR_ID_LEN
)
2504 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Received SA Query frame from "
2505 MACSTR
" (trans_id %02x%02x)", MAC2STR(sa
), data
[1], data
[2]);
2508 if (wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
2509 struct ieee802_11_elems elems
;
2510 struct wpa_channel_info ci
;
2512 if (ieee802_11_parse_elems(data
+ 1 + WLAN_SA_QUERY_TR_ID_LEN
,
2513 len
- 1 - WLAN_SA_QUERY_TR_ID_LEN
,
2514 &elems
, 1) == ParseFailed
) {
2515 wpa_printf(MSG_DEBUG
,
2516 "SA Query: Failed to parse elements");
2520 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
2521 wpa_printf(MSG_WARNING
,
2522 "Failed to get channel info to validate received OCI in SA Query Action frame");
2526 if (ocv_verify_tx_params(elems
.oci
, elems
.oci_len
, &ci
,
2527 channel_width_to_int(ci
.chanwidth
),
2528 ci
.seg1_idx
) != 0) {
2529 wpa_printf(MSG_WARNING
, "%s", ocv_errorstr
);
2533 #endif /* CONFIG_OCV */
2535 if (data
[0] == WLAN_SA_QUERY_REQUEST
)
2536 sme_process_sa_query_request(wpa_s
, sa
, data
, len
);
2537 else if (data
[0] == WLAN_SA_QUERY_RESPONSE
)
2538 sme_process_sa_query_response(wpa_s
, sa
, data
, len
);
2541 #endif /* CONFIG_IEEE80211W */