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, 25, 26, 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
)
93 #ifdef CONFIG_TESTING_OPTIONS
94 if (wpa_s
->sae_commit_override
) {
95 wpa_printf(MSG_DEBUG
, "SAE: TESTING - commit override");
96 buf
= wpabuf_alloc(4 + wpabuf_len(wpa_s
->sae_commit_override
));
99 wpabuf_put_le16(buf
, 1); /* Transaction seq# */
100 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
101 wpabuf_put_buf(buf
, wpa_s
->sae_commit_override
);
104 #endif /* CONFIG_TESTING_OPTIONS */
106 password
= ssid
->sae_password
;
108 password
= ssid
->passphrase
;
110 wpa_printf(MSG_DEBUG
, "SAE: No password available");
114 if (sme_set_sae_group(wpa_s
) < 0) {
115 wpa_printf(MSG_DEBUG
, "SAE: Failed to select group");
119 if (sae_prepare_commit(wpa_s
->own_addr
, bssid
,
120 (u8
*) password
, os_strlen(password
),
121 ssid
->sae_password_id
,
122 &wpa_s
->sme
.sae
) < 0) {
123 wpa_printf(MSG_DEBUG
, "SAE: Could not pick PWE");
127 len
= wpa_s
->sme
.sae_token
? wpabuf_len(wpa_s
->sme
.sae_token
) : 0;
128 if (ssid
->sae_password_id
)
129 len
+= 4 + os_strlen(ssid
->sae_password_id
);
130 buf
= wpabuf_alloc(4 + SAE_COMMIT_MAX_LEN
+ len
);
134 wpabuf_put_le16(buf
, 1); /* Transaction seq# */
135 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
137 sae_write_commit(&wpa_s
->sme
.sae
, buf
, wpa_s
->sme
.sae_token
,
138 ssid
->sae_password_id
);
144 static struct wpabuf
* sme_auth_build_sae_confirm(struct wpa_supplicant
*wpa_s
,
149 buf
= wpabuf_alloc(4 + SAE_CONFIRM_MAX_LEN
);
154 wpabuf_put_le16(buf
, 2); /* Transaction seq# */
155 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
157 sae_write_confirm(&wpa_s
->sme
.sae
, buf
);
162 #endif /* CONFIG_SAE */
166 * sme_auth_handle_rrm - Handle RRM aspects of current authentication attempt
167 * @wpa_s: Pointer to wpa_supplicant data
168 * @bss: Pointer to the bss which is the target of authentication attempt
170 static void sme_auth_handle_rrm(struct wpa_supplicant
*wpa_s
,
173 const u8 rrm_ie_len
= 5;
177 wpa_s
->rrm
.rrm_used
= 0;
179 wpa_printf(MSG_DEBUG
,
180 "RRM: Determining whether RRM can be used - device support: 0x%x",
181 wpa_s
->drv_rrm_flags
);
183 rrm_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RRM_ENABLED_CAPABILITIES
);
184 if (!rrm_ie
|| !(bss
->caps
& IEEE80211_CAP_RRM
)) {
185 wpa_printf(MSG_DEBUG
, "RRM: No RRM in network");
189 if (!((wpa_s
->drv_rrm_flags
&
190 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES
) &&
191 (wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_QUIET
)) &&
192 !(wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_SUPPORT_RRM
)) {
193 wpa_printf(MSG_DEBUG
,
194 "RRM: Insufficient RRM support in driver - do not use RRM");
198 if (sizeof(wpa_s
->sme
.assoc_req_ie
) <
199 wpa_s
->sme
.assoc_req_ie_len
+ rrm_ie_len
+ 2) {
201 "RRM: Unable to use RRM, no room for RRM IE");
205 wpa_printf(MSG_DEBUG
, "RRM: Adding RRM IE to Association Request");
206 pos
= wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
;
207 os_memset(pos
, 0, 2 + rrm_ie_len
);
208 *pos
++ = WLAN_EID_RRM_ENABLED_CAPABILITIES
;
211 /* Set supported capabilites flags */
212 if (wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_TX_POWER_INSERTION
)
213 *pos
|= WLAN_RRM_CAPS_LINK_MEASUREMENT
;
215 *pos
|= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE
|
216 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE
|
217 WLAN_RRM_CAPS_BEACON_REPORT_TABLE
;
220 pos
[1] |= WLAN_RRM_CAPS_LCI_MEASUREMENT
;
222 wpa_s
->sme
.assoc_req_ie_len
+= rrm_ie_len
+ 2;
223 wpa_s
->rrm
.rrm_used
= 1;
227 static void sme_send_authentication(struct wpa_supplicant
*wpa_s
,
228 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
231 struct wpa_driver_auth_params params
;
232 struct wpa_ssid
*old_ssid
;
233 #ifdef CONFIG_IEEE80211R
235 #endif /* CONFIG_IEEE80211R */
236 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_FILS)
238 #endif /* CONFIG_IEEE80211R || CONFIG_FILS */
239 int i
, bssid_changed
;
240 struct wpabuf
*resp
= NULL
;
248 #endif /* CONFIG_MBO */
251 wpa_msg(wpa_s
, MSG_ERROR
, "SME: No scan result available for "
253 wpas_connect_work_done(wpa_s
);
257 skip_auth
= wpa_s
->conf
->reassoc_same_bss_optim
&&
258 wpa_s
->reassoc_same_bss
;
259 wpa_s
->current_bss
= bss
;
261 os_memset(¶ms
, 0, sizeof(params
));
262 wpa_s
->reassociate
= 0;
264 params
.freq
= bss
->freq
;
265 params
.bssid
= bss
->bssid
;
266 params
.ssid
= bss
->ssid
;
267 params
.ssid_len
= bss
->ssid_len
;
268 params
.p2p
= ssid
->p2p_group
;
270 if (wpa_s
->sme
.ssid_len
!= params
.ssid_len
||
271 os_memcmp(wpa_s
->sme
.ssid
, params
.ssid
, params
.ssid_len
) != 0)
272 wpa_s
->sme
.prev_bssid_set
= 0;
274 wpa_s
->sme
.freq
= params
.freq
;
275 os_memcpy(wpa_s
->sme
.ssid
, params
.ssid
, params
.ssid_len
);
276 wpa_s
->sme
.ssid_len
= params
.ssid_len
;
278 params
.auth_alg
= WPA_AUTH_ALG_OPEN
;
279 #ifdef IEEE8021X_EAPOL
280 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
282 if (ssid
->non_leap
== 0)
283 params
.auth_alg
= WPA_AUTH_ALG_LEAP
;
285 params
.auth_alg
|= WPA_AUTH_ALG_LEAP
;
288 #endif /* IEEE8021X_EAPOL */
289 wpa_dbg(wpa_s
, MSG_DEBUG
, "Automatic auth_alg selection: 0x%x",
291 if (ssid
->auth_alg
) {
292 params
.auth_alg
= ssid
->auth_alg
;
293 wpa_dbg(wpa_s
, MSG_DEBUG
, "Overriding auth_alg selection: "
294 "0x%x", params
.auth_alg
);
297 wpa_s
->sme
.sae_pmksa_caching
= 0;
298 if (wpa_key_mgmt_sae(ssid
->key_mgmt
)) {
300 struct wpa_ie_data ied
;
302 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
304 wpa_dbg(wpa_s
, MSG_DEBUG
,
305 "SAE enabled, but target BSS does not advertise RSN");
306 } else if (wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ied
) == 0 &&
307 wpa_key_mgmt_sae(ied
.key_mgmt
)) {
308 wpa_dbg(wpa_s
, MSG_DEBUG
, "Using SAE auth_alg");
309 params
.auth_alg
= WPA_AUTH_ALG_SAE
;
311 wpa_dbg(wpa_s
, MSG_DEBUG
,
312 "SAE enabled, but target BSS does not advertise SAE AKM for RSN");
315 #endif /* CONFIG_SAE */
317 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
318 if (ssid
->wep_key_len
[i
])
319 params
.wep_key
[i
] = ssid
->wep_key
[i
];
320 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
322 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
324 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
325 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
326 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
328 wpas_notify_bssid_changed(wpa_s
);
330 if ((wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
331 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
332 wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
333 int try_opportunistic
;
334 const u8
*cache_id
= NULL
;
336 try_opportunistic
= (ssid
->proactive_key_caching
< 0 ?
338 ssid
->proactive_key_caching
) &&
339 (ssid
->proto
& WPA_PROTO_RSN
);
341 if (wpa_key_mgmt_fils(ssid
->key_mgmt
))
342 cache_id
= wpa_bss_get_fils_cache_id(bss
);
343 #endif /* CONFIG_FILS */
344 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
346 try_opportunistic
, cache_id
,
348 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
349 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
350 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
351 wpa_s
->sme
.assoc_req_ie
,
352 &wpa_s
->sme
.assoc_req_ie_len
)) {
353 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
354 "key management and encryption suites");
355 wpas_connect_work_done(wpa_s
);
359 } else if (wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
) &&
360 (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
)) {
361 /* No PMKSA caching, but otherwise similar to RSN/WPA */
362 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
363 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
364 wpa_s
->sme
.assoc_req_ie
,
365 &wpa_s
->sme
.assoc_req_ie_len
)) {
366 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
367 "key management and encryption suites");
368 wpas_connect_work_done(wpa_s
);
371 #endif /* CONFIG_HS20 */
372 } else if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
373 wpa_key_mgmt_wpa_ieee8021x(ssid
->key_mgmt
)) {
375 * Both WPA and non-WPA IEEE 802.1X enabled in configuration -
376 * use non-WPA since the scan results did not indicate that the
377 * AP is using WPA or WPA2.
379 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
380 wpa_s
->sme
.assoc_req_ie_len
= 0;
381 } else if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
382 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
383 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
384 wpa_s
->sme
.assoc_req_ie
,
385 &wpa_s
->sme
.assoc_req_ie_len
)) {
386 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
387 "key management and encryption suites (no "
389 wpas_connect_work_done(wpa_s
);
393 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
394 struct wpabuf
*wps_ie
;
395 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
396 if (wps_ie
&& wpabuf_len(wps_ie
) <=
397 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
398 wpa_s
->sme
.assoc_req_ie_len
= wpabuf_len(wps_ie
);
399 os_memcpy(wpa_s
->sme
.assoc_req_ie
, wpabuf_head(wps_ie
),
400 wpa_s
->sme
.assoc_req_ie_len
);
402 wpa_s
->sme
.assoc_req_ie_len
= 0;
404 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
405 #endif /* CONFIG_WPS */
407 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
408 wpa_s
->sme
.assoc_req_ie_len
= 0;
411 /* In case the WPA vendor IE is used, it should be placed after all the
412 * non-vendor IEs, as the lower layer expects the IEs to be ordered as
413 * defined in the standard. Store the WPA IE so it can later be
414 * inserted at the correct location.
418 if (wpa_s
->wpa_proto
== WPA_PROTO_WPA
) {
419 wpa_ie
= os_memdup(wpa_s
->sme
.assoc_req_ie
,
420 wpa_s
->sme
.assoc_req_ie_len
);
422 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Storing WPA IE");
424 wpa_ie_len
= wpa_s
->sme
.assoc_req_ie_len
;
425 wpa_s
->sme
.assoc_req_ie_len
= 0;
427 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed copy WPA IE");
428 wpas_connect_work_done(wpa_s
);
433 #ifdef CONFIG_IEEE80211R
434 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
435 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
437 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
439 /* Prepare for the next transition */
440 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
443 if (md
&& !wpa_key_mgmt_ft(ssid
->key_mgmt
))
446 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: FT mobility domain %02x%02x",
449 if (wpa_s
->sme
.assoc_req_ie_len
+ 5 <
450 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
451 struct rsn_mdie
*mdie
;
452 u8
*pos
= wpa_s
->sme
.assoc_req_ie
+
453 wpa_s
->sme
.assoc_req_ie_len
;
454 *pos
++ = WLAN_EID_MOBILITY_DOMAIN
;
455 *pos
++ = sizeof(*mdie
);
456 mdie
= (struct rsn_mdie
*) pos
;
457 os_memcpy(mdie
->mobility_domain
, md
,
458 MOBILITY_DOMAIN_ID_LEN
);
459 mdie
->ft_capab
= md
[MOBILITY_DOMAIN_ID_LEN
];
460 wpa_s
->sme
.assoc_req_ie_len
+= 5;
463 if (wpa_s
->sme
.prev_bssid_set
&& wpa_s
->sme
.ft_used
&&
464 os_memcmp(md
, wpa_s
->sme
.mobility_domain
, 2) == 0 &&
465 wpa_sm_has_ptk(wpa_s
->wpa
)) {
466 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying to use FT "
468 params
.auth_alg
= WPA_AUTH_ALG_FT
;
469 params
.ie
= wpa_s
->sme
.ft_ies
;
470 params
.ie_len
= wpa_s
->sme
.ft_ies_len
;
473 #endif /* CONFIG_IEEE80211R */
475 #ifdef CONFIG_IEEE80211W
476 wpa_s
->sme
.mfp
= wpas_get_ssid_pmf(wpa_s
, ssid
);
477 if (wpa_s
->sme
.mfp
!= NO_MGMT_FRAME_PROTECTION
) {
478 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
479 struct wpa_ie_data _ie
;
480 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &_ie
) == 0 &&
482 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
483 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Selected AP supports "
485 wpa_s
->sme
.mfp
= MGMT_FRAME_PROTECTION_REQUIRED
;
488 #endif /* CONFIG_IEEE80211W */
491 if (wpa_s
->global
->p2p
) {
495 pos
= wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
;
496 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
497 wpa_s
->sme
.assoc_req_ie_len
;
498 res
= wpas_p2p_assoc_req_ie(wpa_s
, bss
, pos
, len
,
501 wpa_s
->sme
.assoc_req_ie_len
+= res
;
503 #endif /* CONFIG_P2P */
506 if (wpa_s
->fst_ies
) {
507 int fst_ies_len
= wpabuf_len(wpa_s
->fst_ies
);
509 if (wpa_s
->sme
.assoc_req_ie_len
+ fst_ies_len
<=
510 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
511 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
512 wpa_s
->sme
.assoc_req_ie_len
,
513 wpabuf_head(wpa_s
->fst_ies
),
515 wpa_s
->sme
.assoc_req_ie_len
+= fst_ies_len
;
518 #endif /* CONFIG_FST */
520 sme_auth_handle_rrm(wpa_s
, bss
);
522 wpa_s
->sme
.assoc_req_ie_len
+= wpas_supp_op_class_ie(
523 wpa_s
, ssid
, bss
->freq
,
524 wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
525 sizeof(wpa_s
->sme
.assoc_req_ie
) - wpa_s
->sme
.assoc_req_ie_len
);
528 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_P2P_CLIENT
);
530 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_STATION
);
532 ext_capab_len
= wpas_build_ext_capab(wpa_s
, ext_capab
,
534 if (ext_capab_len
> 0) {
535 u8
*pos
= wpa_s
->sme
.assoc_req_ie
;
536 if (wpa_s
->sme
.assoc_req_ie_len
> 0 && pos
[0] == WLAN_EID_RSN
)
538 os_memmove(pos
+ ext_capab_len
, pos
,
539 wpa_s
->sme
.assoc_req_ie_len
-
540 (pos
- wpa_s
->sme
.assoc_req_ie
));
541 wpa_s
->sme
.assoc_req_ie_len
+= ext_capab_len
;
542 os_memcpy(pos
, ext_capab
, ext_capab_len
);
546 if (is_hs20_network(wpa_s
, ssid
, bss
)) {
549 hs20
= wpabuf_alloc(20 + MAX_ROAMING_CONS_OI_LEN
);
551 int pps_mo_id
= hs20_get_pps_mo_id(wpa_s
, ssid
);
554 wpas_hs20_add_indication(hs20
, pps_mo_id
,
555 get_hs20_version(bss
));
556 wpas_hs20_add_roam_cons_sel(hs20
, ssid
);
557 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
558 wpa_s
->sme
.assoc_req_ie_len
;
559 if (wpabuf_len(hs20
) <= len
) {
560 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
561 wpa_s
->sme
.assoc_req_ie_len
,
562 wpabuf_head(hs20
), wpabuf_len(hs20
));
563 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(hs20
);
568 #endif /* CONFIG_HS20 */
573 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Reinsert WPA IE");
575 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
576 wpa_s
->sme
.assoc_req_ie_len
;
578 if (len
> wpa_ie_len
) {
579 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
580 wpa_s
->sme
.assoc_req_ie_len
,
582 wpa_s
->sme
.assoc_req_ie_len
+= wpa_ie_len
;
584 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Failed to add WPA IE");
590 if (wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
]) {
591 struct wpabuf
*buf
= wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
];
594 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
595 wpa_s
->sme
.assoc_req_ie_len
;
596 if (wpabuf_len(buf
) <= len
) {
597 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
598 wpa_s
->sme
.assoc_req_ie_len
,
599 wpabuf_head(buf
), wpabuf_len(buf
));
600 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(buf
);
605 mbo_ie
= wpa_bss_get_vendor_ie(bss
, MBO_IE_VENDOR_TYPE
);
609 len
= wpas_mbo_ie(wpa_s
, wpa_s
->sme
.assoc_req_ie
+
610 wpa_s
->sme
.assoc_req_ie_len
,
611 sizeof(wpa_s
->sme
.assoc_req_ie
) -
612 wpa_s
->sme
.assoc_req_ie_len
,
613 !!mbo_attr_from_mbo_ie(mbo_ie
,
614 OCE_ATTR_ID_CAPA_IND
));
616 wpa_s
->sme
.assoc_req_ie_len
+= len
;
618 #endif /* CONFIG_MBO */
621 if (!skip_auth
&& params
.auth_alg
== WPA_AUTH_ALG_SAE
&&
622 pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
, ssid
, 0,
623 NULL
, WPA_KEY_MGMT_SAE
) == 0) {
624 wpa_dbg(wpa_s
, MSG_DEBUG
,
625 "PMKSA cache entry found - try to use PMKSA caching instead of new SAE authentication");
626 wpa_sm_set_pmk_from_pmksa(wpa_s
->wpa
);
627 params
.auth_alg
= WPA_AUTH_ALG_OPEN
;
628 wpa_s
->sme
.sae_pmksa_caching
= 1;
631 if (!skip_auth
&& params
.auth_alg
== WPA_AUTH_ALG_SAE
) {
633 resp
= sme_auth_build_sae_commit(wpa_s
, ssid
,
636 resp
= sme_auth_build_sae_confirm(wpa_s
, 0);
638 wpas_connection_failed(wpa_s
, bss
->bssid
);
641 params
.auth_data
= wpabuf_head(resp
);
642 params
.auth_data_len
= wpabuf_len(resp
);
643 wpa_s
->sme
.sae
.state
= start
? SAE_COMMITTED
: SAE_CONFIRMED
;
645 #endif /* CONFIG_SAE */
647 old_ssid
= wpa_s
->current_ssid
;
648 wpa_s
->current_ssid
= ssid
;
649 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
650 wpa_supplicant_initiate_eapol(wpa_s
);
653 /* TODO: FILS operations can in some cases be done between different
654 * network_ctx (i.e., same credentials can be used with multiple
656 if (params
.auth_alg
== WPA_AUTH_ALG_OPEN
&&
657 wpa_key_mgmt_fils(ssid
->key_mgmt
)) {
660 const u8
*realm
, *username
, *rrk
;
661 size_t realm_len
, username_len
, rrk_len
;
665 * Check FILS Indication element (FILS Information field) bits
666 * indicating supported authentication algorithms against local
667 * configuration (ssid->fils_dh_group). Try to use FILS
668 * authentication only if the AP supports the combination in the
669 * network profile. */
670 indic
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
671 if (!indic
|| indic
[1] < 2) {
672 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
673 " does not include FILS Indication element - cannot use FILS authentication with it",
674 MAC2STR(bss
->bssid
));
678 fils_info
= WPA_GET_LE16(indic
+ 2);
679 if (ssid
->fils_dh_group
== 0 && !(fils_info
& BIT(9))) {
680 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
681 " does not support FILS SK without PFS - cannot use FILS authentication with it",
682 MAC2STR(bss
->bssid
));
685 if (ssid
->fils_dh_group
!= 0 && !(fils_info
& BIT(10))) {
686 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
687 " does not support FILS SK with PFS - cannot use FILS authentication with it",
688 MAC2STR(bss
->bssid
));
692 if (wpa_s
->last_con_fail_realm
&&
693 eapol_sm_get_erp_info(wpa_s
->eapol
, &ssid
->eap
,
694 &username
, &username_len
,
695 &realm
, &realm_len
, &next_seq_num
,
696 &rrk
, &rrk_len
) == 0 &&
697 realm
&& realm_len
== wpa_s
->last_con_fail_realm_len
&&
698 os_memcmp(realm
, wpa_s
->last_con_fail_realm
,
700 wpa_printf(MSG_DEBUG
,
701 "SME: FILS authentication for this realm failed last time - try to regenerate ERP key hierarchy");
705 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
707 wpa_bss_get_fils_cache_id(bss
),
709 wpa_printf(MSG_DEBUG
,
710 "SME: Try to use FILS with PMKSA caching");
711 resp
= fils_build_auth(wpa_s
->wpa
, ssid
->fils_dh_group
, md
);
715 if (ssid
->fils_dh_group
)
716 wpa_printf(MSG_DEBUG
,
717 "SME: Try to use FILS SK authentication with PFS (DH Group %u)",
718 ssid
->fils_dh_group
);
720 wpa_printf(MSG_DEBUG
,
721 "SME: Try to use FILS SK authentication without PFS");
722 auth_alg
= ssid
->fils_dh_group
?
723 WPA_AUTH_ALG_FILS_SK_PFS
: WPA_AUTH_ALG_FILS
;
724 params
.auth_alg
= auth_alg
;
725 params
.auth_data
= wpabuf_head(resp
);
726 params
.auth_data_len
= wpabuf_len(resp
);
727 wpa_s
->sme
.auth_alg
= auth_alg
;
731 #endif /* CONFIG_FILS */
733 wpa_supplicant_cancel_sched_scan(wpa_s
);
734 wpa_supplicant_cancel_scan(wpa_s
);
736 wpa_msg(wpa_s
, MSG_INFO
, "SME: Trying to authenticate with " MACSTR
737 " (SSID='%s' freq=%d MHz)", MAC2STR(params
.bssid
),
738 wpa_ssid_txt(params
.ssid
, params
.ssid_len
), params
.freq
);
740 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
741 wpa_clear_keys(wpa_s
, bss
->bssid
);
742 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
743 if (old_ssid
!= wpa_s
->current_ssid
)
744 wpas_notify_network_changed(wpa_s
);
747 hs20_configure_frame_filters(wpa_s
);
748 #endif /* CONFIG_HS20 */
752 * If multi-channel concurrency is not supported, check for any
753 * frequency conflict. In case of any frequency conflict, remove the
754 * least prioritized connection.
756 if (wpa_s
->num_multichan_concurrent
< 2) {
758 num
= get_shared_radio_freqs(wpa_s
, &freq
, 1);
759 if (num
> 0 && freq
> 0 && freq
!= params
.freq
) {
760 wpa_printf(MSG_DEBUG
,
761 "Conflicting frequency found (%d != %d)",
763 if (wpas_p2p_handle_frequency_conflicts(wpa_s
,
766 wpas_connection_failed(wpa_s
, bss
->bssid
);
767 wpa_supplicant_mark_disassoc(wpa_s
);
769 wpas_connect_work_done(wpa_s
);
774 #endif /* CONFIG_P2P */
777 wpa_msg(wpa_s
, MSG_DEBUG
,
778 "SME: Skip authentication step on reassoc-to-same-BSS");
780 sme_associate(wpa_s
, ssid
->mode
, bss
->bssid
, WLAN_AUTH_OPEN
);
785 wpa_s
->sme
.auth_alg
= params
.auth_alg
;
786 if (wpa_drv_authenticate(wpa_s
, ¶ms
) < 0) {
787 wpa_msg(wpa_s
, MSG_INFO
, "SME: Authentication request to the "
789 wpas_connection_failed(wpa_s
, bss
->bssid
);
790 wpa_supplicant_mark_disassoc(wpa_s
);
792 wpas_connect_work_done(wpa_s
);
796 eloop_register_timeout(SME_AUTH_TIMEOUT
, 0, sme_auth_timer
, wpa_s
,
800 * Association will be started based on the authentication event from
808 static void sme_auth_start_cb(struct wpa_radio_work
*work
, int deinit
)
810 struct wpa_connect_work
*cwork
= work
->ctx
;
811 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
815 wpa_s
->connect_work
= NULL
;
817 wpas_connect_work_free(cwork
);
821 wpa_s
->connect_work
= work
;
823 if (cwork
->bss_removed
||
824 !wpas_valid_bss_ssid(wpa_s
, cwork
->bss
, cwork
->ssid
) ||
825 wpas_network_disabled(wpa_s
, cwork
->ssid
)) {
826 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: BSS/SSID entry for authentication not valid anymore - drop connection attempt");
827 wpas_connect_work_done(wpa_s
);
831 /* Starting new connection, so clear the possibly used WPA IE from the
832 * previous association. */
833 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
835 sme_send_authentication(wpa_s
, cwork
->bss
, cwork
->ssid
, 1);
839 void sme_authenticate(struct wpa_supplicant
*wpa_s
,
840 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
842 struct wpa_connect_work
*cwork
;
844 if (bss
== NULL
|| ssid
== NULL
)
846 if (wpa_s
->connect_work
) {
847 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Reject sme_authenticate() call since connect_work exist");
851 if (radio_work_pending(wpa_s
, "sme-connect")) {
853 * The previous sme-connect work might no longer be valid due to
854 * the fact that the BSS list was updated. In addition, it makes
855 * sense to adhere to the 'newer' decision.
857 wpa_dbg(wpa_s
, MSG_DEBUG
,
858 "SME: Remove previous pending sme-connect");
859 radio_remove_works(wpa_s
, "sme-connect", 0);
862 wpas_abort_ongoing_scan(wpa_s
);
864 cwork
= os_zalloc(sizeof(*cwork
));
872 wpa_s
->sme
.sae
.state
= SAE_NOTHING
;
873 wpa_s
->sme
.sae
.send_confirm
= 0;
874 wpa_s
->sme
.sae_group_index
= 0;
875 #endif /* CONFIG_SAE */
877 if (radio_add_work(wpa_s
, bss
->freq
, "sme-connect", 1,
878 sme_auth_start_cb
, cwork
) < 0)
879 wpas_connect_work_free(cwork
);
885 static int sme_external_auth_build_buf(struct wpabuf
*buf
,
886 struct wpabuf
*params
,
887 const u8
*sa
, const u8
*da
,
888 u16 auth_transaction
, u16 seq_num
)
890 struct ieee80211_mgmt
*resp
;
892 resp
= wpabuf_put(buf
, offsetof(struct ieee80211_mgmt
,
895 resp
->frame_control
= host_to_le16((WLAN_FC_TYPE_MGMT
<< 2) |
896 (WLAN_FC_STYPE_AUTH
<< 4));
897 os_memcpy(resp
->da
, da
, ETH_ALEN
);
898 os_memcpy(resp
->sa
, sa
, ETH_ALEN
);
899 os_memcpy(resp
->bssid
, da
, ETH_ALEN
);
900 resp
->u
.auth
.auth_alg
= host_to_le16(WLAN_AUTH_SAE
);
901 resp
->seq_ctrl
= host_to_le16(seq_num
<< 4);
902 resp
->u
.auth
.auth_transaction
= host_to_le16(auth_transaction
);
903 resp
->u
.auth
.status_code
= host_to_le16(WLAN_STATUS_SUCCESS
);
905 wpabuf_put_buf(buf
, params
);
911 static void sme_external_auth_send_sae_commit(struct wpa_supplicant
*wpa_s
,
913 struct wpa_ssid
*ssid
)
915 struct wpabuf
*resp
, *buf
;
917 resp
= sme_auth_build_sae_commit(wpa_s
, ssid
, bssid
, 1);
921 wpa_s
->sme
.sae
.state
= SAE_COMMITTED
;
922 buf
= wpabuf_alloc(4 + SAE_COMMIT_MAX_LEN
+ wpabuf_len(resp
));
928 wpa_s
->sme
.seq_num
++;
929 sme_external_auth_build_buf(buf
, resp
, wpa_s
->own_addr
,
930 bssid
, 1, wpa_s
->sme
.seq_num
);
931 wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
), 1, 0);
937 static void sme_send_external_auth_status(struct wpa_supplicant
*wpa_s
,
940 struct external_auth params
;
942 os_memset(¶ms
, 0, sizeof(params
));
943 params
.status
= status
;
944 os_memcpy(params
.ssid
, wpa_s
->sme
.ext_auth
.ssid
,
945 wpa_s
->sme
.ext_auth
.ssid_len
);
946 params
.ssid_len
= wpa_s
->sme
.ext_auth
.ssid_len
;
947 os_memcpy(params
.bssid
, wpa_s
->sme
.ext_auth
.bssid
, ETH_ALEN
);
948 wpa_drv_send_external_auth_status(wpa_s
, ¶ms
);
952 static void sme_handle_external_auth_start(struct wpa_supplicant
*wpa_s
,
953 union wpa_event_data
*data
)
955 struct wpa_ssid
*ssid
;
956 size_t ssid_str_len
= data
->external_auth
.ssid_len
;
957 u8
*ssid_str
= data
->external_auth
.ssid
;
959 /* Get the SSID conf from the ssid string obtained */
960 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
961 if (!wpas_network_disabled(wpa_s
, ssid
) &&
962 ssid_str_len
== ssid
->ssid_len
&&
963 os_memcmp(ssid_str
, ssid
->ssid
, ssid_str_len
) == 0 &&
964 (ssid
->key_mgmt
& WPA_KEY_MGMT_SAE
))
968 sme_external_auth_send_sae_commit(wpa_s
,
969 data
->external_auth
.bssid
,
972 sme_send_external_auth_status(wpa_s
,
973 WLAN_STATUS_UNSPECIFIED_FAILURE
);
977 static void sme_external_auth_send_sae_confirm(struct wpa_supplicant
*wpa_s
,
980 struct wpabuf
*resp
, *buf
;
982 resp
= sme_auth_build_sae_confirm(wpa_s
, 1);
984 wpa_printf(MSG_DEBUG
, "SAE: Confirm message buf alloc failure");
988 wpa_s
->sme
.sae
.state
= SAE_CONFIRMED
;
989 buf
= wpabuf_alloc(4 + SAE_CONFIRM_MAX_LEN
+ wpabuf_len(resp
));
991 wpa_printf(MSG_DEBUG
, "SAE: Auth Confirm buf alloc failure");
995 wpa_s
->sme
.seq_num
++;
996 sme_external_auth_build_buf(buf
, resp
, wpa_s
->own_addr
,
997 da
, 2, wpa_s
->sme
.seq_num
);
998 wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
), 1, 0);
1004 void sme_external_auth_trigger(struct wpa_supplicant
*wpa_s
,
1005 union wpa_event_data
*data
)
1007 if (RSN_SELECTOR_GET(&data
->external_auth
.key_mgmt_suite
) !=
1008 RSN_AUTH_KEY_MGMT_SAE
)
1011 if (data
->external_auth
.action
== EXT_AUTH_START
) {
1012 os_memcpy(&wpa_s
->sme
.ext_auth
, data
,
1013 sizeof(struct external_auth
));
1014 wpa_s
->sme
.seq_num
= 0;
1015 wpa_s
->sme
.sae
.state
= SAE_NOTHING
;
1016 wpa_s
->sme
.sae
.send_confirm
= 0;
1017 wpa_s
->sme
.sae_group_index
= 0;
1018 sme_handle_external_auth_start(wpa_s
, data
);
1019 } else if (data
->external_auth
.action
== EXT_AUTH_ABORT
) {
1020 /* Report failure to driver for the wrong trigger */
1021 sme_send_external_auth_status(wpa_s
,
1022 WLAN_STATUS_UNSPECIFIED_FAILURE
);
1027 static int sme_sae_auth(struct wpa_supplicant
*wpa_s
, u16 auth_transaction
,
1028 u16 status_code
, const u8
*data
, size_t len
,
1029 int external
, const u8
*sa
)
1033 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SAE authentication transaction %u "
1034 "status code %u", auth_transaction
, status_code
);
1036 if (auth_transaction
== 1 &&
1037 status_code
== WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
&&
1038 wpa_s
->sme
.sae
.state
== SAE_COMMITTED
&&
1039 (external
|| wpa_s
->current_bss
) && wpa_s
->current_ssid
) {
1040 int default_groups
[] = { 19, 20, 21, 25, 26, 0 };
1043 groups
= wpa_s
->conf
->sae_groups
;
1044 if (!groups
|| groups
[0] <= 0)
1045 groups
= default_groups
;
1047 if (len
< sizeof(le16
)) {
1048 wpa_dbg(wpa_s
, MSG_DEBUG
,
1049 "SME: Too short SAE anti-clogging token request");
1052 group
= WPA_GET_LE16(data
);
1053 wpa_dbg(wpa_s
, MSG_DEBUG
,
1054 "SME: SAE anti-clogging token requested (group %u)",
1056 if (sae_group_allowed(&wpa_s
->sme
.sae
, groups
, group
) !=
1057 WLAN_STATUS_SUCCESS
) {
1058 wpa_dbg(wpa_s
, MSG_ERROR
,
1059 "SME: SAE group %u of anti-clogging request is invalid",
1063 wpabuf_free(wpa_s
->sme
.sae_token
);
1064 wpa_s
->sme
.sae_token
= wpabuf_alloc_copy(data
+ sizeof(le16
),
1065 len
- sizeof(le16
));
1067 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
1068 wpa_s
->current_ssid
, 1);
1070 sme_external_auth_send_sae_commit(
1071 wpa_s
, wpa_s
->sme
.ext_auth
.bssid
,
1072 wpa_s
->current_ssid
);
1076 if (auth_transaction
== 1 &&
1077 status_code
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1078 wpa_s
->sme
.sae
.state
== SAE_COMMITTED
&&
1079 (external
|| wpa_s
->current_bss
) && wpa_s
->current_ssid
) {
1080 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SAE group not supported");
1081 wpa_s
->sme
.sae_group_index
++;
1082 if (sme_set_sae_group(wpa_s
) < 0)
1083 return -1; /* no other groups enabled */
1084 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Try next enabled SAE group");
1086 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
1087 wpa_s
->current_ssid
, 1);
1089 sme_external_auth_send_sae_commit(
1090 wpa_s
, wpa_s
->sme
.ext_auth
.bssid
,
1091 wpa_s
->current_ssid
);
1095 if (auth_transaction
== 1 &&
1096 status_code
== WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER
) {
1097 const u8
*bssid
= sa
? sa
: wpa_s
->pending_bssid
;
1099 wpa_msg(wpa_s
, MSG_INFO
,
1100 WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER MACSTR
,
1105 if (status_code
!= WLAN_STATUS_SUCCESS
)
1108 if (auth_transaction
== 1) {
1111 groups
= wpa_s
->conf
->sae_groups
;
1113 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME SAE commit");
1114 if ((!external
&& wpa_s
->current_bss
== NULL
) ||
1115 wpa_s
->current_ssid
== NULL
)
1117 if (wpa_s
->sme
.sae
.state
!= SAE_COMMITTED
)
1119 if (groups
&& groups
[0] <= 0)
1121 res
= sae_parse_commit(&wpa_s
->sme
.sae
, data
, len
, NULL
, NULL
,
1123 if (res
== SAE_SILENTLY_DISCARD
) {
1124 wpa_printf(MSG_DEBUG
,
1125 "SAE: Drop commit message due to reflection attack");
1128 if (res
!= WLAN_STATUS_SUCCESS
)
1131 if (sae_process_commit(&wpa_s
->sme
.sae
) < 0) {
1132 wpa_printf(MSG_DEBUG
, "SAE: Failed to process peer "
1137 wpabuf_free(wpa_s
->sme
.sae_token
);
1138 wpa_s
->sme
.sae_token
= NULL
;
1140 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
1141 wpa_s
->current_ssid
, 0);
1143 sme_external_auth_send_sae_confirm(wpa_s
, sa
);
1145 } else if (auth_transaction
== 2) {
1146 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME SAE confirm");
1147 if (wpa_s
->sme
.sae
.state
!= SAE_CONFIRMED
)
1149 if (sae_check_confirm(&wpa_s
->sme
.sae
, data
, len
) < 0)
1151 wpa_s
->sme
.sae
.state
= SAE_ACCEPTED
;
1152 sae_clear_temp_data(&wpa_s
->sme
.sae
);
1155 /* Report success to driver */
1156 sme_send_external_auth_status(wpa_s
,
1157 WLAN_STATUS_SUCCESS
);
1167 void sme_external_auth_mgmt_rx(struct wpa_supplicant
*wpa_s
,
1168 const u8
*auth_frame
, size_t len
)
1170 const struct ieee80211_mgmt
*header
;
1173 header
= (const struct ieee80211_mgmt
*) auth_frame
;
1174 auth_length
= IEEE80211_HDRLEN
+ sizeof(header
->u
.auth
);
1176 if (len
< auth_length
) {
1177 /* Notify failure to the driver */
1178 sme_send_external_auth_status(wpa_s
,
1179 WLAN_STATUS_UNSPECIFIED_FAILURE
);
1183 if (le_to_host16(header
->u
.auth
.auth_alg
) == WLAN_AUTH_SAE
) {
1187 wpa_s
, le_to_host16(header
->u
.auth
.auth_transaction
),
1188 le_to_host16(header
->u
.auth
.status_code
),
1189 header
->u
.auth
.variable
,
1190 len
- auth_length
, 1, header
->sa
);
1192 /* Notify failure to the driver */
1193 sme_send_external_auth_status(
1194 wpa_s
, WLAN_STATUS_UNSPECIFIED_FAILURE
);
1200 wpa_printf(MSG_DEBUG
,
1201 "SME: SAE completed - setting PMK for 4-way handshake");
1202 wpa_sm_set_pmk(wpa_s
->wpa
, wpa_s
->sme
.sae
.pmk
, PMK_LEN
,
1203 wpa_s
->sme
.sae
.pmkid
, wpa_s
->pending_bssid
);
1207 #endif /* CONFIG_SAE */
1210 void sme_event_auth(struct wpa_supplicant
*wpa_s
, union wpa_event_data
*data
)
1212 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1215 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication event "
1216 "when network is not selected");
1220 if (wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) {
1221 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication event "
1222 "when not in authenticating state");
1226 if (os_memcmp(wpa_s
->pending_bssid
, data
->auth
.peer
, ETH_ALEN
) != 0) {
1227 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication with "
1228 "unexpected peer " MACSTR
,
1229 MAC2STR(data
->auth
.peer
));
1233 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Authentication response: peer=" MACSTR
1234 " auth_type=%d auth_transaction=%d status_code=%d",
1235 MAC2STR(data
->auth
.peer
), data
->auth
.auth_type
,
1236 data
->auth
.auth_transaction
, data
->auth
.status_code
);
1237 wpa_hexdump(MSG_MSGDUMP
, "SME: Authentication response IEs",
1238 data
->auth
.ies
, data
->auth
.ies_len
);
1240 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1243 if (data
->auth
.auth_type
== WLAN_AUTH_SAE
) {
1245 res
= sme_sae_auth(wpa_s
, data
->auth
.auth_transaction
,
1246 data
->auth
.status_code
, data
->auth
.ies
,
1247 data
->auth
.ies_len
, 0, NULL
);
1249 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1250 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1256 wpa_printf(MSG_DEBUG
, "SME: SAE completed - setting PMK for "
1258 wpa_sm_set_pmk(wpa_s
->wpa
, wpa_s
->sme
.sae
.pmk
, PMK_LEN
,
1259 wpa_s
->sme
.sae
.pmkid
, wpa_s
->pending_bssid
);
1261 #endif /* CONFIG_SAE */
1263 if (data
->auth
.status_code
!= WLAN_STATUS_SUCCESS
) {
1264 char *ie_txt
= NULL
;
1266 if (data
->auth
.ies
&& data
->auth
.ies_len
) {
1267 size_t buflen
= 2 * data
->auth
.ies_len
+ 1;
1268 ie_txt
= os_malloc(buflen
);
1270 wpa_snprintf_hex(ie_txt
, buflen
, data
->auth
.ies
,
1271 data
->auth
.ies_len
);
1274 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AUTH_REJECT MACSTR
1275 " auth_type=%u auth_transaction=%u status_code=%u%s%s",
1276 MAC2STR(data
->auth
.peer
), data
->auth
.auth_type
,
1277 data
->auth
.auth_transaction
, data
->auth
.status_code
,
1278 ie_txt
? " ie=" : "",
1279 ie_txt
? ie_txt
: "");
1283 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
||
1284 wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS_SK_PFS
)
1285 fils_connection_failure(wpa_s
);
1286 #endif /* CONFIG_FILS */
1288 if (data
->auth
.status_code
!=
1289 WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
||
1290 wpa_s
->sme
.auth_alg
== data
->auth
.auth_type
||
1291 wpa_s
->current_ssid
->auth_alg
== WPA_AUTH_ALG_LEAP
) {
1292 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1293 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1297 wpas_connect_work_done(wpa_s
);
1299 switch (data
->auth
.auth_type
) {
1300 case WLAN_AUTH_OPEN
:
1301 wpa_s
->current_ssid
->auth_alg
= WPA_AUTH_ALG_SHARED
;
1303 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying SHARED auth");
1304 wpa_supplicant_associate(wpa_s
, wpa_s
->current_bss
,
1305 wpa_s
->current_ssid
);
1308 case WLAN_AUTH_SHARED_KEY
:
1309 wpa_s
->current_ssid
->auth_alg
= WPA_AUTH_ALG_LEAP
;
1311 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying LEAP auth");
1312 wpa_supplicant_associate(wpa_s
, wpa_s
->current_bss
,
1313 wpa_s
->current_ssid
);
1321 #ifdef CONFIG_IEEE80211R
1322 if (data
->auth
.auth_type
== WLAN_AUTH_FT
) {
1323 const u8
*ric_ies
= NULL
;
1324 size_t ric_ies_len
= 0;
1326 if (wpa_s
->ric_ies
) {
1327 ric_ies
= wpabuf_head(wpa_s
->ric_ies
);
1328 ric_ies_len
= wpabuf_len(wpa_s
->ric_ies
);
1330 if (wpa_ft_process_response(wpa_s
->wpa
, data
->auth
.ies
,
1331 data
->auth
.ies_len
, 0,
1333 ric_ies
, ric_ies_len
) < 0) {
1334 wpa_dbg(wpa_s
, MSG_DEBUG
,
1335 "SME: FT Authentication response processing failed");
1336 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1338 " reason=%d locally_generated=1",
1339 MAC2STR(wpa_s
->pending_bssid
),
1340 WLAN_REASON_DEAUTH_LEAVING
);
1341 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1342 wpa_supplicant_mark_disassoc(wpa_s
);
1346 #endif /* CONFIG_IEEE80211R */
1349 if (data
->auth
.auth_type
== WLAN_AUTH_FILS_SK
||
1350 data
->auth
.auth_type
== WLAN_AUTH_FILS_SK_PFS
) {
1351 u16 expect_auth_type
;
1353 expect_auth_type
= wpa_s
->sme
.auth_alg
==
1354 WPA_AUTH_ALG_FILS_SK_PFS
? WLAN_AUTH_FILS_SK_PFS
:
1356 if (data
->auth
.auth_type
!= expect_auth_type
) {
1357 wpa_dbg(wpa_s
, MSG_DEBUG
,
1358 "SME: FILS Authentication response used different auth alg (%u; expected %u)",
1359 data
->auth
.auth_type
, expect_auth_type
);
1360 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1362 " reason=%d locally_generated=1",
1363 MAC2STR(wpa_s
->pending_bssid
),
1364 WLAN_REASON_DEAUTH_LEAVING
);
1365 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1366 wpa_supplicant_mark_disassoc(wpa_s
);
1370 if (fils_process_auth(wpa_s
->wpa
, wpa_s
->pending_bssid
,
1371 data
->auth
.ies
, data
->auth
.ies_len
) < 0) {
1372 wpa_dbg(wpa_s
, MSG_DEBUG
,
1373 "SME: FILS Authentication response processing failed");
1374 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1376 " reason=%d locally_generated=1",
1377 MAC2STR(wpa_s
->pending_bssid
),
1378 WLAN_REASON_DEAUTH_LEAVING
);
1379 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1380 wpa_supplicant_mark_disassoc(wpa_s
);
1384 #endif /* CONFIG_FILS */
1386 sme_associate(wpa_s
, ssid
->mode
, data
->auth
.peer
,
1387 data
->auth
.auth_type
);
1391 #ifdef CONFIG_IEEE80211R
1392 static void remove_ie(u8
*buf
, size_t *len
, u8 eid
)
1394 u8
*pos
, *next
, *end
;
1396 pos
= (u8
*) get_ie(buf
, *len
, eid
);
1398 next
= pos
+ 2 + pos
[1];
1401 os_memmove(pos
, next
, end
- next
);
1404 #endif /* CONFIG_IEEE80211R */
1407 void sme_associate(struct wpa_supplicant
*wpa_s
, enum wpas_mode mode
,
1408 const u8
*bssid
, u16 auth_type
)
1410 struct wpa_driver_associate_params params
;
1411 struct ieee802_11_elems elems
;
1413 u8 nonces
[2 * FILS_NONCE_LEN
];
1414 #endif /* CONFIG_FILS */
1415 #ifdef CONFIG_HT_OVERRIDES
1416 struct ieee80211_ht_capabilities htcaps
;
1417 struct ieee80211_ht_capabilities htcaps_mask
;
1418 #endif /* CONFIG_HT_OVERRIDES */
1419 #ifdef CONFIG_VHT_OVERRIDES
1420 struct ieee80211_vht_capabilities vhtcaps
;
1421 struct ieee80211_vht_capabilities vhtcaps_mask
;
1422 #endif /* CONFIG_VHT_OVERRIDES */
1424 os_memset(¶ms
, 0, sizeof(params
));
1427 if (auth_type
== WLAN_AUTH_FILS_SK
||
1428 auth_type
== WLAN_AUTH_FILS_SK_PFS
) {
1430 const u8
*snonce
, *anonce
;
1431 const unsigned int max_hlp
= 20;
1432 struct wpabuf
*hlp
[max_hlp
];
1433 unsigned int i
, num_hlp
= 0;
1434 struct fils_hlp_req
*req
;
1436 dl_list_for_each(req
, &wpa_s
->fils_hlp_req
, struct fils_hlp_req
,
1438 hlp
[num_hlp
] = wpabuf_alloc(2 * ETH_ALEN
+ 6 +
1439 wpabuf_len(req
->pkt
));
1442 wpabuf_put_data(hlp
[num_hlp
], req
->dst
, ETH_ALEN
);
1443 wpabuf_put_data(hlp
[num_hlp
], wpa_s
->own_addr
,
1445 wpabuf_put_data(hlp
[num_hlp
],
1446 "\xaa\xaa\x03\x00\x00\x00", 6);
1447 wpabuf_put_buf(hlp
[num_hlp
], req
->pkt
);
1449 if (num_hlp
>= max_hlp
)
1453 buf
= fils_build_assoc_req(wpa_s
->wpa
, ¶ms
.fils_kek
,
1454 ¶ms
.fils_kek_len
, &snonce
,
1456 (const struct wpabuf
**) hlp
,
1458 for (i
= 0; i
< num_hlp
; i
++)
1459 wpabuf_free(hlp
[i
]);
1462 wpa_hexdump(MSG_DEBUG
, "FILS: assoc_req before FILS elements",
1463 wpa_s
->sme
.assoc_req_ie
,
1464 wpa_s
->sme
.assoc_req_ie_len
);
1465 #ifdef CONFIG_IEEE80211R
1466 if (wpa_key_mgmt_ft(wpa_s
->key_mgmt
)) {
1467 /* Remove RSNE and MDE to allow them to be overridden
1468 * with FILS+FT specific values from
1469 * fils_build_assoc_req(). */
1470 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1471 &wpa_s
->sme
.assoc_req_ie_len
,
1473 wpa_hexdump(MSG_DEBUG
,
1474 "FILS: assoc_req after RSNE removal",
1475 wpa_s
->sme
.assoc_req_ie
,
1476 wpa_s
->sme
.assoc_req_ie_len
);
1477 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1478 &wpa_s
->sme
.assoc_req_ie_len
,
1479 WLAN_EID_MOBILITY_DOMAIN
);
1480 wpa_hexdump(MSG_DEBUG
,
1481 "FILS: assoc_req after MDE removal",
1482 wpa_s
->sme
.assoc_req_ie
,
1483 wpa_s
->sme
.assoc_req_ie_len
);
1485 #endif /* CONFIG_IEEE80211R */
1486 /* TODO: Make wpa_s->sme.assoc_req_ie use dynamic allocation */
1487 if (wpa_s
->sme
.assoc_req_ie_len
+ wpabuf_len(buf
) >
1488 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1489 wpa_printf(MSG_ERROR
,
1490 "FILS: Not enough buffer room for own AssocReq elements");
1494 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1495 wpabuf_head(buf
), wpabuf_len(buf
));
1496 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(buf
);
1498 wpa_hexdump(MSG_DEBUG
, "FILS: assoc_req after FILS elements",
1499 wpa_s
->sme
.assoc_req_ie
,
1500 wpa_s
->sme
.assoc_req_ie_len
);
1502 os_memcpy(nonces
, snonce
, FILS_NONCE_LEN
);
1503 os_memcpy(nonces
+ FILS_NONCE_LEN
, anonce
, FILS_NONCE_LEN
);
1504 params
.fils_nonces
= nonces
;
1505 params
.fils_nonces_len
= sizeof(nonces
);
1507 #endif /* CONFIG_FILS */
1510 #ifdef CONFIG_TESTING_OPTIONS
1511 if (get_ie_ext(wpa_s
->sme
.assoc_req_ie
, wpa_s
->sme
.assoc_req_ie_len
,
1512 WLAN_EID_EXT_OWE_DH_PARAM
)) {
1513 wpa_printf(MSG_INFO
, "TESTING: Override OWE DH element");
1515 #endif /* CONFIG_TESTING_OPTIONS */
1516 if (auth_type
== WLAN_AUTH_OPEN
&&
1517 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
) {
1518 struct wpabuf
*owe_ie
;
1521 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->owe_group
) {
1522 group
= wpa_s
->current_ssid
->owe_group
;
1523 } else if (wpa_s
->assoc_status_code
==
1524 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
) {
1525 if (wpa_s
->last_owe_group
== 19)
1527 else if (wpa_s
->last_owe_group
== 20)
1530 group
= OWE_DH_GROUP
;
1532 group
= OWE_DH_GROUP
;
1535 wpa_s
->last_owe_group
= group
;
1536 wpa_printf(MSG_DEBUG
, "OWE: Try to use group %u", group
);
1537 owe_ie
= owe_build_assoc_req(wpa_s
->wpa
, group
);
1539 wpa_printf(MSG_ERROR
,
1540 "OWE: Failed to build IE for Association Request frame");
1543 if (wpa_s
->sme
.assoc_req_ie_len
+ wpabuf_len(owe_ie
) >
1544 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1545 wpa_printf(MSG_ERROR
,
1546 "OWE: Not enough buffer room for own Association Request frame elements");
1547 wpabuf_free(owe_ie
);
1550 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1551 wpabuf_head(owe_ie
), wpabuf_len(owe_ie
));
1552 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(owe_ie
);
1553 wpabuf_free(owe_ie
);
1555 #endif /* CONFIG_OWE */
1557 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->multi_ap_backhaul_sta
) {
1558 size_t multi_ap_ie_len
;
1560 multi_ap_ie_len
= add_multi_ap_ie(
1561 wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1562 sizeof(wpa_s
->sme
.assoc_req_ie
) -
1563 wpa_s
->sme
.assoc_req_ie_len
,
1564 MULTI_AP_BACKHAUL_STA
);
1565 if (multi_ap_ie_len
== 0) {
1566 wpa_printf(MSG_ERROR
,
1567 "Multi-AP: Failed to build Multi-AP IE");
1570 wpa_s
->sme
.assoc_req_ie_len
+= multi_ap_ie_len
;
1573 params
.bssid
= bssid
;
1574 params
.ssid
= wpa_s
->sme
.ssid
;
1575 params
.ssid_len
= wpa_s
->sme
.ssid_len
;
1576 params
.freq
.freq
= wpa_s
->sme
.freq
;
1577 params
.bg_scan_period
= wpa_s
->current_ssid
?
1578 wpa_s
->current_ssid
->bg_scan_period
: -1;
1579 params
.wpa_ie
= wpa_s
->sme
.assoc_req_ie_len
?
1580 wpa_s
->sme
.assoc_req_ie
: NULL
;
1581 params
.wpa_ie_len
= wpa_s
->sme
.assoc_req_ie_len
;
1582 wpa_hexdump(MSG_DEBUG
, "SME: Association Request IEs",
1583 params
.wpa_ie
, params
.wpa_ie_len
);
1584 params
.pairwise_suite
= wpa_s
->pairwise_cipher
;
1585 params
.group_suite
= wpa_s
->group_cipher
;
1586 params
.mgmt_group_suite
= wpa_s
->mgmt_group_cipher
;
1587 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
1588 params
.wpa_proto
= wpa_s
->wpa_proto
;
1589 #ifdef CONFIG_HT_OVERRIDES
1590 os_memset(&htcaps
, 0, sizeof(htcaps
));
1591 os_memset(&htcaps_mask
, 0, sizeof(htcaps_mask
));
1592 params
.htcaps
= (u8
*) &htcaps
;
1593 params
.htcaps_mask
= (u8
*) &htcaps_mask
;
1594 wpa_supplicant_apply_ht_overrides(wpa_s
, wpa_s
->current_ssid
, ¶ms
);
1595 #endif /* CONFIG_HT_OVERRIDES */
1596 #ifdef CONFIG_VHT_OVERRIDES
1597 os_memset(&vhtcaps
, 0, sizeof(vhtcaps
));
1598 os_memset(&vhtcaps_mask
, 0, sizeof(vhtcaps_mask
));
1599 params
.vhtcaps
= &vhtcaps
;
1600 params
.vhtcaps_mask
= &vhtcaps_mask
;
1601 wpa_supplicant_apply_vht_overrides(wpa_s
, wpa_s
->current_ssid
, ¶ms
);
1602 #endif /* CONFIG_VHT_OVERRIDES */
1603 #ifdef CONFIG_IEEE80211R
1604 if (auth_type
== WLAN_AUTH_FT
&& wpa_s
->sme
.ft_ies
&&
1605 get_ie(wpa_s
->sme
.ft_ies
, wpa_s
->sme
.ft_ies_len
,
1606 WLAN_EID_RIC_DATA
)) {
1607 /* There seems to be a pretty inconvenient bug in the Linux
1608 * kernel IE splitting functionality when RIC is used. For now,
1609 * skip correct behavior in IE construction here (i.e., drop the
1610 * additional non-FT-specific IEs) to avoid kernel issues. This
1611 * is fine since RIC is used only for testing purposes in the
1612 * current implementation. */
1613 wpa_printf(MSG_INFO
,
1614 "SME: Linux kernel workaround - do not try to include additional IEs with RIC");
1615 params
.wpa_ie
= wpa_s
->sme
.ft_ies
;
1616 params
.wpa_ie_len
= wpa_s
->sme
.ft_ies_len
;
1617 } else if (auth_type
== WLAN_AUTH_FT
&& wpa_s
->sme
.ft_ies
) {
1618 const u8
*rm_en
, *pos
, *end
;
1619 size_t rm_en_len
= 0;
1620 u8
*rm_en_dup
= NULL
, *wpos
;
1622 /* Remove RSNE, MDE, FTE to allow them to be overridden with
1623 * FT specific values */
1624 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1625 &wpa_s
->sme
.assoc_req_ie_len
,
1627 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1628 &wpa_s
->sme
.assoc_req_ie_len
,
1629 WLAN_EID_MOBILITY_DOMAIN
);
1630 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1631 &wpa_s
->sme
.assoc_req_ie_len
,
1632 WLAN_EID_FAST_BSS_TRANSITION
);
1633 rm_en
= get_ie(wpa_s
->sme
.assoc_req_ie
,
1634 wpa_s
->sme
.assoc_req_ie_len
,
1635 WLAN_EID_RRM_ENABLED_CAPABILITIES
);
1637 /* Need to remove RM Enabled Capabilities element as
1638 * well temporarily, so that it can be placed between
1640 rm_en_len
= 2 + rm_en
[1];
1641 rm_en_dup
= os_memdup(rm_en
, rm_en_len
);
1642 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1643 &wpa_s
->sme
.assoc_req_ie_len
,
1644 WLAN_EID_RRM_ENABLED_CAPABILITIES
);
1646 wpa_hexdump(MSG_DEBUG
,
1647 "SME: Association Request IEs after FT IE removal",
1648 wpa_s
->sme
.assoc_req_ie
,
1649 wpa_s
->sme
.assoc_req_ie_len
);
1650 if (wpa_s
->sme
.assoc_req_ie_len
+ wpa_s
->sme
.ft_ies_len
+
1651 rm_en_len
> sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1652 wpa_printf(MSG_ERROR
,
1653 "SME: Not enough buffer room for FT IEs in Association Request frame");
1658 os_memmove(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.ft_ies_len
+
1660 wpa_s
->sme
.assoc_req_ie
,
1661 wpa_s
->sme
.assoc_req_ie_len
);
1662 pos
= wpa_s
->sme
.ft_ies
;
1663 end
= pos
+ wpa_s
->sme
.ft_ies_len
;
1664 wpos
= wpa_s
->sme
.assoc_req_ie
;
1665 if (*pos
== WLAN_EID_RSN
) {
1666 os_memcpy(wpos
, pos
, 2 + pos
[1]);
1671 os_memcpy(wpos
, rm_en_dup
, rm_en_len
);
1675 os_memcpy(wpos
, pos
, end
- pos
);
1676 wpa_s
->sme
.assoc_req_ie_len
+= wpa_s
->sme
.ft_ies_len
+
1678 params
.wpa_ie
= wpa_s
->sme
.assoc_req_ie
;
1679 params
.wpa_ie_len
= wpa_s
->sme
.assoc_req_ie_len
;
1680 wpa_hexdump(MSG_DEBUG
,
1681 "SME: Association Request IEs after FT override",
1682 params
.wpa_ie
, params
.wpa_ie_len
);
1684 #endif /* CONFIG_IEEE80211R */
1686 params
.mgmt_frame_protection
= wpa_s
->sme
.mfp
;
1687 params
.rrm_used
= wpa_s
->rrm
.rrm_used
;
1688 if (wpa_s
->sme
.prev_bssid_set
)
1689 params
.prev_bssid
= wpa_s
->sme
.prev_bssid
;
1691 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
1692 " (SSID='%s' freq=%d MHz)", MAC2STR(params
.bssid
),
1693 params
.ssid
? wpa_ssid_txt(params
.ssid
, params
.ssid_len
) : "",
1696 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
1698 if (params
.wpa_ie
== NULL
||
1699 ieee802_11_parse_elems(params
.wpa_ie
, params
.wpa_ie_len
, &elems
, 0)
1701 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Could not parse own IEs?!");
1702 os_memset(&elems
, 0, sizeof(elems
));
1705 params
.wpa_proto
= WPA_PROTO_RSN
;
1706 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.rsn_ie
- 2,
1707 elems
.rsn_ie_len
+ 2);
1708 } else if (elems
.wpa_ie
) {
1709 params
.wpa_proto
= WPA_PROTO_WPA
;
1710 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.wpa_ie
- 2,
1711 elems
.wpa_ie_len
+ 2);
1712 } else if (elems
.osen
) {
1713 params
.wpa_proto
= WPA_PROTO_OSEN
;
1714 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.osen
- 2,
1715 elems
.osen_len
+ 2);
1717 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1718 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
)
1721 if (wpa_s
->p2pdev
->set_sta_uapsd
)
1722 params
.uapsd
= wpa_s
->p2pdev
->sta_uapsd
;
1726 if (wpa_drv_associate(wpa_s
, ¶ms
) < 0) {
1727 wpa_msg(wpa_s
, MSG_INFO
, "SME: Association request to the "
1729 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1730 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1731 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1735 eloop_register_timeout(SME_ASSOC_TIMEOUT
, 0, sme_assoc_timer
, wpa_s
,
1738 #ifdef CONFIG_TESTING_OPTIONS
1739 wpabuf_free(wpa_s
->last_assoc_req_wpa_ie
);
1740 wpa_s
->last_assoc_req_wpa_ie
= NULL
;
1742 wpa_s
->last_assoc_req_wpa_ie
=
1743 wpabuf_alloc_copy(params
.wpa_ie
, params
.wpa_ie_len
);
1744 #endif /* CONFIG_TESTING_OPTIONS */
1748 int sme_update_ft_ies(struct wpa_supplicant
*wpa_s
, const u8
*md
,
1749 const u8
*ies
, size_t ies_len
)
1751 if (md
== NULL
|| ies
== NULL
) {
1752 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Remove mobility domain");
1753 os_free(wpa_s
->sme
.ft_ies
);
1754 wpa_s
->sme
.ft_ies
= NULL
;
1755 wpa_s
->sme
.ft_ies_len
= 0;
1756 wpa_s
->sme
.ft_used
= 0;
1760 os_memcpy(wpa_s
->sme
.mobility_domain
, md
, MOBILITY_DOMAIN_ID_LEN
);
1761 wpa_hexdump(MSG_DEBUG
, "SME: FT IEs", ies
, ies_len
);
1762 os_free(wpa_s
->sme
.ft_ies
);
1763 wpa_s
->sme
.ft_ies
= os_memdup(ies
, ies_len
);
1764 if (wpa_s
->sme
.ft_ies
== NULL
)
1766 wpa_s
->sme
.ft_ies_len
= ies_len
;
1771 static void sme_deauth(struct wpa_supplicant
*wpa_s
)
1775 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
1777 if (wpa_drv_deauthenticate(wpa_s
, wpa_s
->pending_bssid
,
1778 WLAN_REASON_DEAUTH_LEAVING
) < 0) {
1779 wpa_msg(wpa_s
, MSG_INFO
, "SME: Deauth request to the driver "
1782 wpa_s
->sme
.prev_bssid_set
= 0;
1784 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1785 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1786 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
1787 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1789 wpas_notify_bssid_changed(wpa_s
);
1793 void sme_event_assoc_reject(struct wpa_supplicant
*wpa_s
,
1794 union wpa_event_data
*data
)
1796 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association with " MACSTR
" failed: "
1797 "status code %d", MAC2STR(wpa_s
->pending_bssid
),
1798 data
->assoc_reject
.status_code
);
1800 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
1803 if (wpa_s
->sme
.sae_pmksa_caching
&& wpa_s
->current_ssid
&&
1804 wpa_key_mgmt_sae(wpa_s
->current_ssid
->key_mgmt
)) {
1805 wpa_dbg(wpa_s
, MSG_DEBUG
,
1806 "PMKSA caching attempt rejected - drop PMKSA cache entry and fall back to SAE authentication");
1807 wpa_sm_aborted_cached(wpa_s
->wpa
);
1808 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
1809 if (wpa_s
->current_bss
) {
1810 struct wpa_bss
*bss
= wpa_s
->current_bss
;
1811 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1813 wpa_drv_deauthenticate(wpa_s
, wpa_s
->pending_bssid
,
1814 WLAN_REASON_DEAUTH_LEAVING
);
1815 wpas_connect_work_done(wpa_s
);
1816 wpa_supplicant_mark_disassoc(wpa_s
);
1817 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
1821 #endif /* CONFIG_SAE */
1824 * For now, unconditionally terminate the previous authentication. In
1825 * theory, this should not be needed, but mac80211 gets quite confused
1826 * if the authentication is left pending.. Some roaming cases might
1827 * benefit from using the previous authentication, so this could be
1828 * optimized in the future.
1834 void sme_event_auth_timed_out(struct wpa_supplicant
*wpa_s
,
1835 union wpa_event_data
*data
)
1837 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Authentication timed out");
1838 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1839 wpa_supplicant_mark_disassoc(wpa_s
);
1843 void sme_event_assoc_timed_out(struct wpa_supplicant
*wpa_s
,
1844 union wpa_event_data
*data
)
1846 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association timed out");
1847 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1848 wpa_supplicant_mark_disassoc(wpa_s
);
1852 void sme_event_disassoc(struct wpa_supplicant
*wpa_s
,
1853 struct disassoc_info
*info
)
1855 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Disassociation event received");
1856 if (wpa_s
->sme
.prev_bssid_set
) {
1858 * cfg80211/mac80211 can get into somewhat confused state if
1859 * the AP only disassociates us and leaves us in authenticated
1860 * state. For now, force the state to be cleared to avoid
1861 * confusing errors if we try to associate with the AP again.
1863 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Deauthenticate to clear "
1865 wpa_drv_deauthenticate(wpa_s
, wpa_s
->sme
.prev_bssid
,
1866 WLAN_REASON_DEAUTH_LEAVING
);
1871 static void sme_auth_timer(void *eloop_ctx
, void *timeout_ctx
)
1873 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1874 if (wpa_s
->wpa_state
== WPA_AUTHENTICATING
) {
1875 wpa_msg(wpa_s
, MSG_DEBUG
, "SME: Authentication timeout");
1881 static void sme_assoc_timer(void *eloop_ctx
, void *timeout_ctx
)
1883 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1884 if (wpa_s
->wpa_state
== WPA_ASSOCIATING
) {
1885 wpa_msg(wpa_s
, MSG_DEBUG
, "SME: Association timeout");
1891 void sme_state_changed(struct wpa_supplicant
*wpa_s
)
1893 /* Make sure timers are cleaned up appropriately. */
1894 if (wpa_s
->wpa_state
!= WPA_ASSOCIATING
)
1895 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
1896 if (wpa_s
->wpa_state
!= WPA_AUTHENTICATING
)
1897 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1901 void sme_disassoc_while_authenticating(struct wpa_supplicant
*wpa_s
,
1902 const u8
*prev_pending_bssid
)
1905 * mac80211-workaround to force deauth on failed auth cmd,
1906 * requires us to remain in authenticating state to allow the
1907 * second authentication attempt to be continued properly.
1909 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Allow pending authentication "
1910 "to proceed after disconnection event");
1911 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
1912 os_memcpy(wpa_s
->pending_bssid
, prev_pending_bssid
, ETH_ALEN
);
1915 * Re-arm authentication timer in case auth fails for whatever reason.
1917 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1918 eloop_register_timeout(SME_AUTH_TIMEOUT
, 0, sme_auth_timer
, wpa_s
,
1923 void sme_clear_on_disassoc(struct wpa_supplicant
*wpa_s
)
1925 wpa_s
->sme
.prev_bssid_set
= 0;
1927 wpabuf_free(wpa_s
->sme
.sae_token
);
1928 wpa_s
->sme
.sae_token
= NULL
;
1929 sae_clear_data(&wpa_s
->sme
.sae
);
1930 #endif /* CONFIG_SAE */
1931 #ifdef CONFIG_IEEE80211R
1932 if (wpa_s
->sme
.ft_ies
|| wpa_s
->sme
.ft_used
)
1933 sme_update_ft_ies(wpa_s
, NULL
, NULL
, 0);
1934 #endif /* CONFIG_IEEE80211R */
1938 void sme_deinit(struct wpa_supplicant
*wpa_s
)
1940 os_free(wpa_s
->sme
.ft_ies
);
1941 wpa_s
->sme
.ft_ies
= NULL
;
1942 wpa_s
->sme
.ft_ies_len
= 0;
1943 #ifdef CONFIG_IEEE80211W
1944 sme_stop_sa_query(wpa_s
);
1945 #endif /* CONFIG_IEEE80211W */
1946 sme_clear_on_disassoc(wpa_s
);
1948 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
1949 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1950 eloop_cancel_timeout(sme_obss_scan_timeout
, wpa_s
, NULL
);
1954 static void sme_send_2040_bss_coex(struct wpa_supplicant
*wpa_s
,
1955 const u8
*chan_list
, u8 num_channels
,
1958 struct ieee80211_2040_bss_coex_ie
*bc_ie
;
1959 struct ieee80211_2040_intol_chan_report
*ic_report
;
1962 wpa_printf(MSG_DEBUG
, "SME: Send 20/40 BSS Coexistence to " MACSTR
1963 " (num_channels=%u num_intol=%u)",
1964 MAC2STR(wpa_s
->bssid
), num_channels
, num_intol
);
1965 wpa_hexdump(MSG_DEBUG
, "SME: 20/40 BSS Intolerant Channels",
1966 chan_list
, num_channels
);
1968 buf
= wpabuf_alloc(2 + /* action.category + action_code */
1969 sizeof(struct ieee80211_2040_bss_coex_ie
) +
1970 sizeof(struct ieee80211_2040_intol_chan_report
) +
1975 wpabuf_put_u8(buf
, WLAN_ACTION_PUBLIC
);
1976 wpabuf_put_u8(buf
, WLAN_PA_20_40_BSS_COEX
);
1978 bc_ie
= wpabuf_put(buf
, sizeof(*bc_ie
));
1979 bc_ie
->element_id
= WLAN_EID_20_40_BSS_COEXISTENCE
;
1982 bc_ie
->coex_param
|= WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ
;
1984 if (num_channels
> 0) {
1985 ic_report
= wpabuf_put(buf
, sizeof(*ic_report
));
1986 ic_report
->element_id
= WLAN_EID_20_40_BSS_INTOLERANT
;
1987 ic_report
->length
= num_channels
+ 1;
1988 ic_report
->op_class
= 0;
1989 os_memcpy(wpabuf_put(buf
, num_channels
), chan_list
,
1993 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
1994 wpa_s
->own_addr
, wpa_s
->bssid
,
1995 wpabuf_head(buf
), wpabuf_len(buf
), 0) < 0) {
1996 wpa_msg(wpa_s
, MSG_INFO
,
1997 "SME: Failed to send 20/40 BSS Coexistence frame");
2004 int sme_proc_obss_scan(struct wpa_supplicant
*wpa_s
)
2006 struct wpa_bss
*bss
;
2009 u8 chan_list
[P2P_MAX_CHANNELS
], channel
;
2010 u8 num_channels
= 0, num_intol
= 0, i
;
2012 if (!wpa_s
->sme
.sched_obss_scan
)
2015 wpa_s
->sme
.sched_obss_scan
= 0;
2016 if (!wpa_s
->current_bss
|| wpa_s
->wpa_state
!= WPA_COMPLETED
)
2020 * Check whether AP uses regulatory triplet or channel triplet in
2021 * country info. Right now the operating class of the BSS channel
2022 * width trigger event is "unknown" (IEEE Std 802.11-2012 10.15.12),
2023 * based on the assumption that operating class triplet is not used in
2024 * beacon frame. If the First Channel Number/Operating Extension
2025 * Identifier octet has a positive integer value of 201 or greater,
2026 * then its operating class triplet.
2028 * TODO: If Supported Operating Classes element is present in beacon
2029 * frame, have to lookup operating class in Annex E and fill them in
2032 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_COUNTRY
);
2033 if (ie
&& (ie
[1] >= 6) && (ie
[5] >= 201))
2036 os_memset(chan_list
, 0, sizeof(chan_list
));
2038 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2039 /* Skip other band bss */
2040 enum hostapd_hw_mode mode
;
2041 mode
= ieee80211_freq_to_chan(bss
->freq
, &channel
);
2042 if (mode
!= HOSTAPD_MODE_IEEE80211G
&&
2043 mode
!= HOSTAPD_MODE_IEEE80211B
)
2046 ie
= wpa_bss_get_ie(bss
, WLAN_EID_HT_CAP
);
2047 ht_cap
= (ie
&& (ie
[1] == 26)) ? WPA_GET_LE16(ie
+ 2) : 0;
2048 wpa_printf(MSG_DEBUG
, "SME OBSS scan BSS " MACSTR
2049 " freq=%u chan=%u ht_cap=0x%x",
2050 MAC2STR(bss
->bssid
), bss
->freq
, channel
, ht_cap
);
2052 if (!ht_cap
|| (ht_cap
& HT_CAP_INFO_40MHZ_INTOLERANT
)) {
2053 if (ht_cap
& HT_CAP_INFO_40MHZ_INTOLERANT
)
2056 /* Check whether the channel is already considered */
2057 for (i
= 0; i
< num_channels
; i
++) {
2058 if (channel
== chan_list
[i
])
2061 if (i
!= num_channels
)
2064 chan_list
[num_channels
++] = channel
;
2068 sme_send_2040_bss_coex(wpa_s
, chan_list
, num_channels
, num_intol
);
2073 static void wpa_obss_scan_freqs_list(struct wpa_supplicant
*wpa_s
,
2074 struct wpa_driver_scan_params
*params
)
2076 /* Include only affected channels */
2077 struct hostapd_hw_modes
*mode
;
2081 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
,
2082 HOSTAPD_MODE_IEEE80211G
);
2084 /* No channels supported in this band - use empty list */
2085 params
->freqs
= os_zalloc(sizeof(int));
2089 if (wpa_s
->sme
.ht_sec_chan
== HT_SEC_CHAN_UNKNOWN
&&
2090 wpa_s
->current_bss
) {
2093 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_HT_OPERATION
);
2094 if (ie
&& ie
[1] >= 2) {
2097 o
= ie
[3] & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK
;
2098 if (o
== HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE
)
2099 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_ABOVE
;
2100 else if (o
== HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW
)
2101 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_BELOW
;
2105 start
= wpa_s
->assoc_freq
- 10;
2106 end
= wpa_s
->assoc_freq
+ 10;
2107 switch (wpa_s
->sme
.ht_sec_chan
) {
2108 case HT_SEC_CHAN_UNKNOWN
:
2109 /* HT40+ possible on channels 1..9 */
2110 if (wpa_s
->assoc_freq
<= 2452)
2112 /* HT40- possible on channels 5-13 */
2113 if (wpa_s
->assoc_freq
>= 2432)
2116 case HT_SEC_CHAN_ABOVE
:
2119 case HT_SEC_CHAN_BELOW
:
2123 wpa_printf(MSG_DEBUG
,
2124 "OBSS: assoc_freq %d possible affected range %d-%d",
2125 wpa_s
->assoc_freq
, start
, end
);
2127 params
->freqs
= os_calloc(mode
->num_channels
+ 1, sizeof(int));
2128 if (params
->freqs
== NULL
)
2130 for (count
= 0, i
= 0; i
< mode
->num_channels
; i
++) {
2133 if (mode
->channels
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
2135 freq
= mode
->channels
[i
].freq
;
2136 if (freq
- 10 >= end
|| freq
+ 10 <= start
)
2137 continue; /* not affected */
2138 params
->freqs
[count
++] = freq
;
2143 static void sme_obss_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
2145 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2146 struct wpa_driver_scan_params params
;
2148 if (!wpa_s
->current_bss
) {
2149 wpa_printf(MSG_DEBUG
, "SME OBSS: Ignore scan request");
2153 os_memset(¶ms
, 0, sizeof(params
));
2154 wpa_obss_scan_freqs_list(wpa_s
, ¶ms
);
2155 params
.low_priority
= 1;
2156 wpa_printf(MSG_DEBUG
, "SME OBSS: Request an OBSS scan");
2158 if (wpa_supplicant_trigger_scan(wpa_s
, ¶ms
))
2159 wpa_printf(MSG_DEBUG
, "SME OBSS: Failed to trigger scan");
2161 wpa_s
->sme
.sched_obss_scan
= 1;
2162 os_free(params
.freqs
);
2164 eloop_register_timeout(wpa_s
->sme
.obss_scan_int
, 0,
2165 sme_obss_scan_timeout
, wpa_s
, NULL
);
2169 void sme_sched_obss_scan(struct wpa_supplicant
*wpa_s
, int enable
)
2172 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2173 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2174 struct hostapd_hw_modes
*hw_mode
= NULL
;
2177 eloop_cancel_timeout(sme_obss_scan_timeout
, wpa_s
, NULL
);
2178 wpa_s
->sme
.sched_obss_scan
= 0;
2179 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_UNKNOWN
;
2184 * Schedule OBSS scan if driver is using station SME in wpa_supplicant
2185 * or it expects OBSS scan to be performed by wpa_supplicant.
2187 if (!((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) ||
2188 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OBSS_SCAN
)) ||
2189 ssid
== NULL
|| ssid
->mode
!= IEEE80211_MODE_INFRA
)
2192 if (!wpa_s
->hw
.modes
)
2195 /* only HT caps in 11g mode are relevant */
2196 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
2197 hw_mode
= &wpa_s
->hw
.modes
[i
];
2198 if (hw_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
2202 /* Driver does not support HT40 for 11g or doesn't have 11g. */
2203 if (i
== wpa_s
->hw
.num_modes
|| !hw_mode
||
2204 !(hw_mode
->ht_capab
& HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
2207 if (bss
== NULL
|| bss
->freq
< 2400 || bss
->freq
> 2500)
2208 return; /* Not associated on 2.4 GHz band */
2210 /* Check whether AP supports HT40 */
2211 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_HT_CAP
);
2212 if (!ie
|| ie
[1] < 2 ||
2213 !(WPA_GET_LE16(ie
+ 2) & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
2214 return; /* AP does not support HT40 */
2216 ie
= wpa_bss_get_ie(wpa_s
->current_bss
,
2217 WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS
);
2218 if (!ie
|| ie
[1] < 14)
2219 return; /* AP does not request OBSS scans */
2221 wpa_s
->sme
.obss_scan_int
= WPA_GET_LE16(ie
+ 6);
2222 if (wpa_s
->sme
.obss_scan_int
< 10) {
2223 wpa_printf(MSG_DEBUG
, "SME: Invalid OBSS Scan Interval %u "
2224 "replaced with the minimum 10 sec",
2225 wpa_s
->sme
.obss_scan_int
);
2226 wpa_s
->sme
.obss_scan_int
= 10;
2228 wpa_printf(MSG_DEBUG
, "SME: OBSS Scan Interval %u sec",
2229 wpa_s
->sme
.obss_scan_int
);
2230 eloop_register_timeout(wpa_s
->sme
.obss_scan_int
, 0,
2231 sme_obss_scan_timeout
, wpa_s
, NULL
);
2235 #ifdef CONFIG_IEEE80211W
2237 static const unsigned int sa_query_max_timeout
= 1000;
2238 static const unsigned int sa_query_retry_timeout
= 201;
2239 static const unsigned int sa_query_ch_switch_max_delay
= 5000; /* in usec */
2241 static int sme_check_sa_query_timeout(struct wpa_supplicant
*wpa_s
)
2244 struct os_reltime now
, passed
;
2245 os_get_reltime(&now
);
2246 os_reltime_sub(&now
, &wpa_s
->sme
.sa_query_start
, &passed
);
2247 tu
= (passed
.sec
* 1000000 + passed
.usec
) / 1024;
2248 if (sa_query_max_timeout
< tu
) {
2249 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SA Query timed out");
2250 sme_stop_sa_query(wpa_s
);
2251 wpa_supplicant_deauthenticate(
2252 wpa_s
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
2260 static void sme_send_sa_query_req(struct wpa_supplicant
*wpa_s
,
2263 u8 req
[2 + WLAN_SA_QUERY_TR_ID_LEN
+ OCV_OCI_EXTENDED_LEN
];
2264 u8 req_len
= 2 + WLAN_SA_QUERY_TR_ID_LEN
;
2266 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Sending SA Query Request to "
2267 MACSTR
, MAC2STR(wpa_s
->bssid
));
2268 wpa_hexdump(MSG_DEBUG
, "SME: SA Query Transaction ID",
2269 trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
2270 req
[0] = WLAN_ACTION_SA_QUERY
;
2271 req
[1] = WLAN_SA_QUERY_REQUEST
;
2272 os_memcpy(req
+ 2, trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
2275 if (wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
2276 struct wpa_channel_info ci
;
2278 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
2279 wpa_printf(MSG_WARNING
,
2280 "Failed to get channel info for OCI element in SA Query Request frame");
2284 if (ocv_insert_extended_oci(&ci
, req
+ req_len
) < 0)
2287 req_len
+= OCV_OCI_EXTENDED_LEN
;
2289 #endif /* CONFIG_OCV */
2291 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
2292 wpa_s
->own_addr
, wpa_s
->bssid
,
2293 req
, req_len
, 0) < 0)
2294 wpa_msg(wpa_s
, MSG_INFO
, "SME: Failed to send SA Query "
2299 static void sme_sa_query_timer(void *eloop_ctx
, void *timeout_ctx
)
2301 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2302 unsigned int timeout
, sec
, usec
;
2303 u8
*trans_id
, *nbuf
;
2305 if (wpa_s
->sme
.sa_query_count
> 0 &&
2306 sme_check_sa_query_timeout(wpa_s
))
2309 nbuf
= os_realloc_array(wpa_s
->sme
.sa_query_trans_id
,
2310 wpa_s
->sme
.sa_query_count
+ 1,
2311 WLAN_SA_QUERY_TR_ID_LEN
);
2313 sme_stop_sa_query(wpa_s
);
2316 if (wpa_s
->sme
.sa_query_count
== 0) {
2317 /* Starting a new SA Query procedure */
2318 os_get_reltime(&wpa_s
->sme
.sa_query_start
);
2320 trans_id
= nbuf
+ wpa_s
->sme
.sa_query_count
* WLAN_SA_QUERY_TR_ID_LEN
;
2321 wpa_s
->sme
.sa_query_trans_id
= nbuf
;
2322 wpa_s
->sme
.sa_query_count
++;
2324 if (os_get_random(trans_id
, WLAN_SA_QUERY_TR_ID_LEN
) < 0) {
2325 wpa_printf(MSG_DEBUG
, "Could not generate SA Query ID");
2326 sme_stop_sa_query(wpa_s
);
2330 timeout
= sa_query_retry_timeout
;
2331 sec
= ((timeout
/ 1000) * 1024) / 1000;
2332 usec
= (timeout
% 1000) * 1024;
2333 eloop_register_timeout(sec
, usec
, sme_sa_query_timer
, wpa_s
, NULL
);
2335 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association SA Query attempt %d",
2336 wpa_s
->sme
.sa_query_count
);
2338 sme_send_sa_query_req(wpa_s
, trans_id
);
2342 static void sme_start_sa_query(struct wpa_supplicant
*wpa_s
)
2344 sme_sa_query_timer(wpa_s
, NULL
);
2348 static void sme_stop_sa_query(struct wpa_supplicant
*wpa_s
)
2350 eloop_cancel_timeout(sme_sa_query_timer
, wpa_s
, NULL
);
2351 os_free(wpa_s
->sme
.sa_query_trans_id
);
2352 wpa_s
->sme
.sa_query_trans_id
= NULL
;
2353 wpa_s
->sme
.sa_query_count
= 0;
2357 void sme_event_unprot_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*sa
,
2358 const u8
*da
, u16 reason_code
)
2360 struct wpa_ssid
*ssid
;
2361 struct os_reltime now
;
2363 if (wpa_s
->wpa_state
!= WPA_COMPLETED
)
2365 ssid
= wpa_s
->current_ssid
;
2366 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == NO_MGMT_FRAME_PROTECTION
)
2368 if (os_memcmp(sa
, wpa_s
->bssid
, ETH_ALEN
) != 0)
2370 if (reason_code
!= WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
&&
2371 reason_code
!= WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
)
2373 if (wpa_s
->sme
.sa_query_count
> 0)
2376 os_get_reltime(&now
);
2377 if (wpa_s
->sme
.last_unprot_disconnect
.sec
&&
2378 !os_reltime_expired(&now
, &wpa_s
->sme
.last_unprot_disconnect
, 10))
2379 return; /* limit SA Query procedure frequency */
2380 wpa_s
->sme
.last_unprot_disconnect
= now
;
2382 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Unprotected disconnect dropped - "
2383 "possible AP/STA state mismatch - trigger SA Query");
2384 sme_start_sa_query(wpa_s
);
2388 void sme_event_ch_switch(struct wpa_supplicant
*wpa_s
)
2393 if (wpa_s
->wpa_state
!= WPA_COMPLETED
||
2394 !wpa_sm_ocv_enabled(wpa_s
->wpa
))
2397 wpa_dbg(wpa_s
, MSG_DEBUG
,
2398 "SME: Channel switch completed - trigger new SA Query to verify new operating channel");
2399 sme_stop_sa_query(wpa_s
);
2401 if (os_get_random((u8
*) &_rand
, sizeof(_rand
)) < 0)
2402 _rand
= os_random();
2403 usec
= _rand
% (sa_query_ch_switch_max_delay
+ 1);
2404 eloop_register_timeout(0, usec
, sme_sa_query_timer
, wpa_s
, NULL
);
2408 static void sme_process_sa_query_request(struct wpa_supplicant
*wpa_s
,
2409 const u8
*sa
, const u8
*data
,
2412 u8 resp
[2 + WLAN_SA_QUERY_TR_ID_LEN
+ OCV_OCI_EXTENDED_LEN
];
2413 u8 resp_len
= 2 + WLAN_SA_QUERY_TR_ID_LEN
;
2415 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Sending SA Query Response to "
2416 MACSTR
, MAC2STR(wpa_s
->bssid
));
2418 resp
[0] = WLAN_ACTION_SA_QUERY
;
2419 resp
[1] = WLAN_SA_QUERY_RESPONSE
;
2420 os_memcpy(resp
+ 2, data
+ 1, WLAN_SA_QUERY_TR_ID_LEN
);
2423 if (wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
2424 struct wpa_channel_info ci
;
2426 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
2427 wpa_printf(MSG_WARNING
,
2428 "Failed to get channel info for OCI element in SA Query Response frame");
2432 if (ocv_insert_extended_oci(&ci
, resp
+ resp_len
) < 0)
2435 resp_len
+= OCV_OCI_EXTENDED_LEN
;
2437 #endif /* CONFIG_OCV */
2439 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
2440 wpa_s
->own_addr
, wpa_s
->bssid
,
2441 resp
, resp_len
, 0) < 0)
2442 wpa_msg(wpa_s
, MSG_INFO
,
2443 "SME: Failed to send SA Query Response");
2447 static void sme_process_sa_query_response(struct wpa_supplicant
*wpa_s
,
2448 const u8
*sa
, const u8
*data
,
2453 if (!wpa_s
->sme
.sa_query_trans_id
)
2456 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Received SA Query response from "
2457 MACSTR
" (trans_id %02x%02x)", MAC2STR(sa
), data
[1], data
[2]);
2459 if (os_memcmp(sa
, wpa_s
->bssid
, ETH_ALEN
) != 0)
2462 for (i
= 0; i
< wpa_s
->sme
.sa_query_count
; i
++) {
2463 if (os_memcmp(wpa_s
->sme
.sa_query_trans_id
+
2464 i
* WLAN_SA_QUERY_TR_ID_LEN
,
2465 data
+ 1, WLAN_SA_QUERY_TR_ID_LEN
) == 0)
2469 if (i
>= wpa_s
->sme
.sa_query_count
) {
2470 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: No matching SA Query "
2471 "transaction identifier found");
2475 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Reply to pending SA Query received "
2476 "from " MACSTR
, MAC2STR(sa
));
2477 sme_stop_sa_query(wpa_s
);
2481 void sme_sa_query_rx(struct wpa_supplicant
*wpa_s
, const u8
*sa
,
2482 const u8
*data
, size_t len
)
2484 if (len
< 1 + WLAN_SA_QUERY_TR_ID_LEN
)
2487 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Received SA Query frame from "
2488 MACSTR
" (trans_id %02x%02x)", MAC2STR(sa
), data
[1], data
[2]);
2491 if (wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
2492 struct ieee802_11_elems elems
;
2493 struct wpa_channel_info ci
;
2495 if (ieee802_11_parse_elems(data
+ 1 + WLAN_SA_QUERY_TR_ID_LEN
,
2496 len
- 1 - WLAN_SA_QUERY_TR_ID_LEN
,
2497 &elems
, 1) == ParseFailed
) {
2498 wpa_printf(MSG_DEBUG
,
2499 "SA Query: Failed to parse elements");
2503 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
2504 wpa_printf(MSG_WARNING
,
2505 "Failed to get channel info to validate received OCI in SA Query Action frame");
2509 if (ocv_verify_tx_params(elems
.oci
, elems
.oci_len
, &ci
,
2510 channel_width_to_int(ci
.chanwidth
),
2511 ci
.seg1_idx
) != 0) {
2512 wpa_printf(MSG_WARNING
, "%s", ocv_errorstr
);
2516 #endif /* CONFIG_OCV */
2518 if (data
[0] == WLAN_SA_QUERY_REQUEST
)
2519 sme_process_sa_query_request(wpa_s
, sa
, data
, len
);
2520 else if (data
[0] == WLAN_SA_QUERY_RESPONSE
)
2521 sme_process_sa_query_response(wpa_s
, sa
, data
, len
);
2524 #endif /* CONFIG_IEEE80211W */