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 "common/hw_features_common.h"
17 #include "eapol_supp/eapol_supp_sm.h"
18 #include "common/wpa_common.h"
19 #include "common/sae.h"
20 #include "common/dpp.h"
21 #include "rsn_supp/wpa.h"
22 #include "rsn_supp/pmksa_cache.h"
24 #include "wpa_supplicant_i.h"
26 #include "wpas_glue.h"
27 #include "wps_supplicant.h"
28 #include "p2p_supplicant.h"
33 #include "hs20_supplicant.h"
35 #define SME_AUTH_TIMEOUT 5
36 #define SME_ASSOC_TIMEOUT 5
38 static void sme_auth_timer(void *eloop_ctx
, void *timeout_ctx
);
39 static void sme_assoc_timer(void *eloop_ctx
, void *timeout_ctx
);
40 static void sme_obss_scan_timeout(void *eloop_ctx
, void *timeout_ctx
);
41 static void sme_stop_sa_query(struct wpa_supplicant
*wpa_s
);
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
,
88 int reuse
, int *ret_use_pt
)
99 #ifdef CONFIG_TESTING_OPTIONS
100 if (wpa_s
->sae_commit_override
) {
101 wpa_printf(MSG_DEBUG
, "SAE: TESTING - commit override");
102 buf
= wpabuf_alloc(4 + wpabuf_len(wpa_s
->sae_commit_override
));
106 wpabuf_put_le16(buf
, 1); /* Transaction seq# */
107 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
109 wpabuf_put_buf(buf
, wpa_s
->sae_commit_override
);
112 #endif /* CONFIG_TESTING_OPTIONS */
114 password
= ssid
->sae_password
;
116 password
= ssid
->passphrase
;
118 wpa_printf(MSG_DEBUG
, "SAE: No password available");
122 if (reuse
&& wpa_s
->sme
.sae
.tmp
&&
123 os_memcmp(bssid
, wpa_s
->sme
.sae
.tmp
->bssid
, ETH_ALEN
) == 0) {
124 wpa_printf(MSG_DEBUG
,
125 "SAE: Reuse previously generated PWE on a retry with the same AP");
126 use_pt
= wpa_s
->sme
.sae
.tmp
->h2e
;
129 if (sme_set_sae_group(wpa_s
) < 0) {
130 wpa_printf(MSG_DEBUG
, "SAE: Failed to select group");
134 if (ssid
->sae_password_id
&& wpa_s
->conf
->sae_pwe
!= 3)
137 if (use_pt
|| wpa_s
->conf
->sae_pwe
== 1 || wpa_s
->conf
->sae_pwe
== 2) {
138 bss
= wpa_bss_get_bssid_latest(wpa_s
, bssid
);
142 rsnxe
= wpa_bss_get_ie(bss
, WLAN_EID_RSNX
);
143 if (rsnxe
&& rsnxe
[1] >= 1)
144 use_pt
= !!(rsnxe
[2] &
145 BIT(WLAN_RSNX_CAPAB_SAE_H2E
));
148 if ((wpa_s
->conf
->sae_pwe
== 1 || ssid
->sae_password_id
) &&
149 wpa_s
->conf
->sae_pwe
!= 3 &&
151 wpa_printf(MSG_DEBUG
,
152 "SAE: Cannot use H2E with the selected AP");
158 sae_prepare_commit_pt(&wpa_s
->sme
.sae
, ssid
->pt
,
159 wpa_s
->own_addr
, bssid
,
160 wpa_s
->sme
.sae_rejected_groups
) < 0)
163 sae_prepare_commit(wpa_s
->own_addr
, bssid
,
164 (u8
*) password
, os_strlen(password
),
165 ssid
->sae_password_id
,
166 &wpa_s
->sme
.sae
) < 0) {
167 wpa_printf(MSG_DEBUG
, "SAE: Could not pick PWE");
170 if (wpa_s
->sme
.sae
.tmp
)
171 os_memcpy(wpa_s
->sme
.sae
.tmp
->bssid
, bssid
, ETH_ALEN
);
174 len
= wpa_s
->sme
.sae_token
? 3 + wpabuf_len(wpa_s
->sme
.sae_token
) : 0;
175 if (ssid
->sae_password_id
)
176 len
+= 4 + os_strlen(ssid
->sae_password_id
);
177 buf
= wpabuf_alloc(4 + SAE_COMMIT_MAX_LEN
+ len
);
181 wpabuf_put_le16(buf
, 1); /* Transaction seq# */
182 wpabuf_put_le16(buf
, use_pt
? WLAN_STATUS_SAE_HASH_TO_ELEMENT
:
183 WLAN_STATUS_SUCCESS
);
185 if (sae_write_commit(&wpa_s
->sme
.sae
, buf
, wpa_s
->sme
.sae_token
,
186 ssid
->sae_password_id
) < 0) {
191 *ret_use_pt
= use_pt
;
197 static struct wpabuf
* sme_auth_build_sae_confirm(struct wpa_supplicant
*wpa_s
,
202 buf
= wpabuf_alloc(4 + SAE_CONFIRM_MAX_LEN
);
207 wpabuf_put_le16(buf
, 2); /* Transaction seq# */
208 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
210 sae_write_confirm(&wpa_s
->sme
.sae
, buf
);
215 #endif /* CONFIG_SAE */
219 * sme_auth_handle_rrm - Handle RRM aspects of current authentication attempt
220 * @wpa_s: Pointer to wpa_supplicant data
221 * @bss: Pointer to the bss which is the target of authentication attempt
223 static void sme_auth_handle_rrm(struct wpa_supplicant
*wpa_s
,
226 const u8 rrm_ie_len
= 5;
230 wpa_s
->rrm
.rrm_used
= 0;
232 wpa_printf(MSG_DEBUG
,
233 "RRM: Determining whether RRM can be used - device support: 0x%x",
234 wpa_s
->drv_rrm_flags
);
236 rrm_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RRM_ENABLED_CAPABILITIES
);
237 if (!rrm_ie
|| !(bss
->caps
& IEEE80211_CAP_RRM
)) {
238 wpa_printf(MSG_DEBUG
, "RRM: No RRM in network");
242 if (!((wpa_s
->drv_rrm_flags
&
243 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES
) &&
244 (wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_QUIET
)) &&
245 !(wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_SUPPORT_RRM
)) {
246 wpa_printf(MSG_DEBUG
,
247 "RRM: Insufficient RRM support in driver - do not use RRM");
251 if (sizeof(wpa_s
->sme
.assoc_req_ie
) <
252 wpa_s
->sme
.assoc_req_ie_len
+ rrm_ie_len
+ 2) {
254 "RRM: Unable to use RRM, no room for RRM IE");
258 wpa_printf(MSG_DEBUG
, "RRM: Adding RRM IE to Association Request");
259 pos
= wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
;
260 os_memset(pos
, 0, 2 + rrm_ie_len
);
261 *pos
++ = WLAN_EID_RRM_ENABLED_CAPABILITIES
;
264 /* Set supported capabilites flags */
265 if (wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_TX_POWER_INSERTION
)
266 *pos
|= WLAN_RRM_CAPS_LINK_MEASUREMENT
;
268 *pos
|= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE
|
269 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE
|
270 WLAN_RRM_CAPS_BEACON_REPORT_TABLE
;
273 pos
[1] |= WLAN_RRM_CAPS_LCI_MEASUREMENT
;
275 wpa_s
->sme
.assoc_req_ie_len
+= rrm_ie_len
+ 2;
276 wpa_s
->rrm
.rrm_used
= 1;
280 static void sme_send_authentication(struct wpa_supplicant
*wpa_s
,
281 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
284 struct wpa_driver_auth_params params
;
285 struct wpa_ssid
*old_ssid
;
286 #ifdef CONFIG_IEEE80211R
288 #endif /* CONFIG_IEEE80211R */
289 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_FILS)
291 #endif /* CONFIG_IEEE80211R || CONFIG_FILS */
293 struct wpabuf
*resp
= NULL
;
301 #endif /* CONFIG_MBO */
305 wpa_msg(wpa_s
, MSG_ERROR
, "SME: No scan result available for "
307 wpas_connect_work_done(wpa_s
);
311 skip_auth
= wpa_s
->conf
->reassoc_same_bss_optim
&&
312 wpa_s
->reassoc_same_bss
;
313 wpa_s
->current_bss
= bss
;
315 os_memset(¶ms
, 0, sizeof(params
));
316 wpa_s
->reassociate
= 0;
318 params
.freq
= bss
->freq
;
319 params
.bssid
= bss
->bssid
;
320 params
.ssid
= bss
->ssid
;
321 params
.ssid_len
= bss
->ssid_len
;
322 params
.p2p
= ssid
->p2p_group
;
324 if (wpa_s
->sme
.ssid_len
!= params
.ssid_len
||
325 os_memcmp(wpa_s
->sme
.ssid
, params
.ssid
, params
.ssid_len
) != 0)
326 wpa_s
->sme
.prev_bssid_set
= 0;
328 wpa_s
->sme
.freq
= params
.freq
;
329 os_memcpy(wpa_s
->sme
.ssid
, params
.ssid
, params
.ssid_len
);
330 wpa_s
->sme
.ssid_len
= params
.ssid_len
;
332 params
.auth_alg
= WPA_AUTH_ALG_OPEN
;
333 #ifdef IEEE8021X_EAPOL
334 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
336 if (ssid
->non_leap
== 0)
337 params
.auth_alg
= WPA_AUTH_ALG_LEAP
;
339 params
.auth_alg
|= WPA_AUTH_ALG_LEAP
;
342 #endif /* IEEE8021X_EAPOL */
343 wpa_dbg(wpa_s
, MSG_DEBUG
, "Automatic auth_alg selection: 0x%x",
345 if (ssid
->auth_alg
) {
346 params
.auth_alg
= ssid
->auth_alg
;
347 wpa_dbg(wpa_s
, MSG_DEBUG
, "Overriding auth_alg selection: "
348 "0x%x", params
.auth_alg
);
351 wpa_s
->sme
.sae_pmksa_caching
= 0;
352 if (wpa_key_mgmt_sae(ssid
->key_mgmt
)) {
354 struct wpa_ie_data ied
;
356 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
358 wpa_dbg(wpa_s
, MSG_DEBUG
,
359 "SAE enabled, but target BSS does not advertise RSN");
361 } else if (wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ied
) == 0 &&
362 (ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) &&
363 (ied
.key_mgmt
& WPA_KEY_MGMT_DPP
)) {
364 wpa_dbg(wpa_s
, MSG_DEBUG
, "Prefer DPP over SAE when both are enabled");
365 #endif /* CONFIG_DPP */
366 } else if (wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ied
) == 0 &&
367 wpa_key_mgmt_sae(ied
.key_mgmt
)) {
368 wpa_dbg(wpa_s
, MSG_DEBUG
, "Using SAE auth_alg");
369 params
.auth_alg
= WPA_AUTH_ALG_SAE
;
371 wpa_dbg(wpa_s
, MSG_DEBUG
,
372 "SAE enabled, but target BSS does not advertise SAE AKM for RSN");
375 #endif /* CONFIG_SAE */
381 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
382 if (ssid
->wep_key_len
[i
])
383 params
.wep_key
[i
] = ssid
->wep_key
[i
];
384 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
386 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
388 #endif /* CONFIG_WEP */
390 if ((wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
391 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
392 wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
393 int try_opportunistic
;
394 const u8
*cache_id
= NULL
;
396 try_opportunistic
= (ssid
->proactive_key_caching
< 0 ?
398 ssid
->proactive_key_caching
) &&
399 (ssid
->proto
& WPA_PROTO_RSN
);
401 if (wpa_key_mgmt_fils(ssid
->key_mgmt
))
402 cache_id
= wpa_bss_get_fils_cache_id(bss
);
403 #endif /* CONFIG_FILS */
404 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
406 try_opportunistic
, cache_id
,
408 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
409 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
410 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
411 wpa_s
->sme
.assoc_req_ie
,
412 &wpa_s
->sme
.assoc_req_ie_len
)) {
413 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
414 "key management and encryption suites");
415 wpas_connect_work_done(wpa_s
);
419 } else if (wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
) &&
420 (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
)) {
421 /* No PMKSA caching, but otherwise similar to RSN/WPA */
422 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
423 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
424 wpa_s
->sme
.assoc_req_ie
,
425 &wpa_s
->sme
.assoc_req_ie_len
)) {
426 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
427 "key management and encryption suites");
428 wpas_connect_work_done(wpa_s
);
431 #endif /* CONFIG_HS20 */
432 } else if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
433 wpa_key_mgmt_wpa_ieee8021x(ssid
->key_mgmt
)) {
435 * Both WPA and non-WPA IEEE 802.1X enabled in configuration -
436 * use non-WPA since the scan results did not indicate that the
437 * AP is using WPA or WPA2.
439 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
440 wpa_s
->sme
.assoc_req_ie_len
= 0;
441 } else if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
442 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
443 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
444 wpa_s
->sme
.assoc_req_ie
,
445 &wpa_s
->sme
.assoc_req_ie_len
)) {
446 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
447 "key management and encryption suites (no "
449 wpas_connect_work_done(wpa_s
);
453 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
454 struct wpabuf
*wps_ie
;
455 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
456 if (wps_ie
&& wpabuf_len(wps_ie
) <=
457 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
458 wpa_s
->sme
.assoc_req_ie_len
= wpabuf_len(wps_ie
);
459 os_memcpy(wpa_s
->sme
.assoc_req_ie
, wpabuf_head(wps_ie
),
460 wpa_s
->sme
.assoc_req_ie_len
);
462 wpa_s
->sme
.assoc_req_ie_len
= 0;
464 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
465 #endif /* CONFIG_WPS */
467 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
468 wpa_s
->sme
.assoc_req_ie_len
= 0;
471 /* In case the WPA vendor IE is used, it should be placed after all the
472 * non-vendor IEs, as the lower layer expects the IEs to be ordered as
473 * defined in the standard. Store the WPA IE so it can later be
474 * inserted at the correct location.
478 if (wpa_s
->wpa_proto
== WPA_PROTO_WPA
) {
479 wpa_ie
= os_memdup(wpa_s
->sme
.assoc_req_ie
,
480 wpa_s
->sme
.assoc_req_ie_len
);
482 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Storing WPA IE");
484 wpa_ie_len
= wpa_s
->sme
.assoc_req_ie_len
;
485 wpa_s
->sme
.assoc_req_ie_len
= 0;
487 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed copy WPA IE");
488 wpas_connect_work_done(wpa_s
);
493 #ifdef CONFIG_IEEE80211R
494 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
495 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
497 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
498 if (md
&& (!wpa_key_mgmt_ft(ssid
->key_mgmt
) ||
499 !wpa_key_mgmt_ft(wpa_s
->key_mgmt
)))
502 /* Prepare for the next transition */
503 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
507 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: FT mobility domain %02x%02x",
510 omit_rsnxe
= !wpa_bss_get_ie(bss
, WLAN_EID_RSNX
);
511 if (wpa_s
->sme
.assoc_req_ie_len
+ 5 <
512 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
513 struct rsn_mdie
*mdie
;
514 u8
*pos
= wpa_s
->sme
.assoc_req_ie
+
515 wpa_s
->sme
.assoc_req_ie_len
;
516 *pos
++ = WLAN_EID_MOBILITY_DOMAIN
;
517 *pos
++ = sizeof(*mdie
);
518 mdie
= (struct rsn_mdie
*) pos
;
519 os_memcpy(mdie
->mobility_domain
, md
,
520 MOBILITY_DOMAIN_ID_LEN
);
521 mdie
->ft_capab
= md
[MOBILITY_DOMAIN_ID_LEN
];
522 wpa_s
->sme
.assoc_req_ie_len
+= 5;
525 if (wpa_s
->sme
.prev_bssid_set
&& wpa_s
->sme
.ft_used
&&
526 os_memcmp(md
, wpa_s
->sme
.mobility_domain
, 2) == 0 &&
527 wpa_sm_has_ptk(wpa_s
->wpa
)) {
528 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying to use FT "
530 params
.auth_alg
= WPA_AUTH_ALG_FT
;
531 params
.ie
= wpa_s
->sme
.ft_ies
;
532 params
.ie_len
= wpa_s
->sme
.ft_ies_len
;
535 #endif /* CONFIG_IEEE80211R */
537 wpa_s
->sme
.mfp
= wpas_get_ssid_pmf(wpa_s
, ssid
);
538 if (wpa_s
->sme
.mfp
!= NO_MGMT_FRAME_PROTECTION
) {
539 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
540 struct wpa_ie_data _ie
;
541 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &_ie
) == 0 &&
543 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
544 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Selected AP supports "
546 wpa_s
->sme
.mfp
= MGMT_FRAME_PROTECTION_REQUIRED
;
551 if (wpa_s
->global
->p2p
) {
555 pos
= wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
;
556 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
557 wpa_s
->sme
.assoc_req_ie_len
;
558 res
= wpas_p2p_assoc_req_ie(wpa_s
, bss
, pos
, len
,
561 wpa_s
->sme
.assoc_req_ie_len
+= res
;
563 #endif /* CONFIG_P2P */
566 if (wpa_s
->fst_ies
) {
567 int fst_ies_len
= wpabuf_len(wpa_s
->fst_ies
);
569 if (wpa_s
->sme
.assoc_req_ie_len
+ fst_ies_len
<=
570 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
571 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
572 wpa_s
->sme
.assoc_req_ie_len
,
573 wpabuf_head(wpa_s
->fst_ies
),
575 wpa_s
->sme
.assoc_req_ie_len
+= fst_ies_len
;
578 #endif /* CONFIG_FST */
580 sme_auth_handle_rrm(wpa_s
, bss
);
582 wpa_s
->sme
.assoc_req_ie_len
+= wpas_supp_op_class_ie(
584 wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
585 sizeof(wpa_s
->sme
.assoc_req_ie
) - wpa_s
->sme
.assoc_req_ie_len
);
588 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_P2P_CLIENT
);
590 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_STATION
);
592 ext_capab_len
= wpas_build_ext_capab(wpa_s
, ext_capab
,
594 if (ext_capab_len
> 0) {
595 u8
*pos
= wpa_s
->sme
.assoc_req_ie
;
596 if (wpa_s
->sme
.assoc_req_ie_len
> 0 && pos
[0] == WLAN_EID_RSN
)
598 os_memmove(pos
+ ext_capab_len
, pos
,
599 wpa_s
->sme
.assoc_req_ie_len
-
600 (pos
- wpa_s
->sme
.assoc_req_ie
));
601 wpa_s
->sme
.assoc_req_ie_len
+= ext_capab_len
;
602 os_memcpy(pos
, ext_capab
, ext_capab_len
);
605 #ifdef CONFIG_TESTING_OPTIONS
606 if (wpa_s
->rsnxe_override_assoc
&&
607 wpabuf_len(wpa_s
->rsnxe_override_assoc
) <=
608 sizeof(wpa_s
->sme
.assoc_req_ie
) - wpa_s
->sme
.assoc_req_ie_len
) {
609 wpa_printf(MSG_DEBUG
, "TESTING: RSNXE AssocReq override");
610 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
611 wpabuf_head(wpa_s
->rsnxe_override_assoc
),
612 wpabuf_len(wpa_s
->rsnxe_override_assoc
));
613 wpa_s
->sme
.assoc_req_ie_len
+=
614 wpabuf_len(wpa_s
->rsnxe_override_assoc
);
616 #endif /* CONFIG_TESTING_OPTIONS */
617 if (wpa_s
->rsnxe_len
> 0 &&
619 sizeof(wpa_s
->sme
.assoc_req_ie
) - wpa_s
->sme
.assoc_req_ie_len
&&
621 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
622 wpa_s
->rsnxe
, wpa_s
->rsnxe_len
);
623 wpa_s
->sme
.assoc_req_ie_len
+= wpa_s
->rsnxe_len
;
627 if (is_hs20_network(wpa_s
, ssid
, bss
)) {
630 hs20
= wpabuf_alloc(20 + MAX_ROAMING_CONS_OI_LEN
);
632 int pps_mo_id
= hs20_get_pps_mo_id(wpa_s
, ssid
);
635 wpas_hs20_add_indication(hs20
, pps_mo_id
,
636 get_hs20_version(bss
));
637 wpas_hs20_add_roam_cons_sel(hs20
, ssid
);
638 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
639 wpa_s
->sme
.assoc_req_ie_len
;
640 if (wpabuf_len(hs20
) <= len
) {
641 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
642 wpa_s
->sme
.assoc_req_ie_len
,
643 wpabuf_head(hs20
), wpabuf_len(hs20
));
644 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(hs20
);
649 #endif /* CONFIG_HS20 */
654 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Reinsert WPA IE");
656 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
657 wpa_s
->sme
.assoc_req_ie_len
;
659 if (len
> wpa_ie_len
) {
660 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
661 wpa_s
->sme
.assoc_req_ie_len
,
663 wpa_s
->sme
.assoc_req_ie_len
+= wpa_ie_len
;
665 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Failed to add WPA IE");
671 if (wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
]) {
672 struct wpabuf
*buf
= wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
];
675 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
676 wpa_s
->sme
.assoc_req_ie_len
;
677 if (wpabuf_len(buf
) <= len
) {
678 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
679 wpa_s
->sme
.assoc_req_ie_len
,
680 wpabuf_head(buf
), wpabuf_len(buf
));
681 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(buf
);
686 mbo_ie
= wpa_bss_get_vendor_ie(bss
, MBO_IE_VENDOR_TYPE
);
687 if (!wpa_s
->disable_mbo_oce
&& mbo_ie
) {
690 len
= wpas_mbo_ie(wpa_s
, wpa_s
->sme
.assoc_req_ie
+
691 wpa_s
->sme
.assoc_req_ie_len
,
692 sizeof(wpa_s
->sme
.assoc_req_ie
) -
693 wpa_s
->sme
.assoc_req_ie_len
,
694 !!mbo_attr_from_mbo_ie(mbo_ie
,
695 OCE_ATTR_ID_CAPA_IND
));
697 wpa_s
->sme
.assoc_req_ie_len
+= len
;
699 #endif /* CONFIG_MBO */
702 if (!skip_auth
&& params
.auth_alg
== WPA_AUTH_ALG_SAE
&&
703 pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
, ssid
, 0,
705 wpa_s
->key_mgmt
== WPA_KEY_MGMT_FT_SAE
?
706 WPA_KEY_MGMT_FT_SAE
:
707 WPA_KEY_MGMT_SAE
) == 0) {
708 wpa_dbg(wpa_s
, MSG_DEBUG
,
709 "PMKSA cache entry found - try to use PMKSA caching instead of new SAE authentication");
710 wpa_sm_set_pmk_from_pmksa(wpa_s
->wpa
);
711 params
.auth_alg
= WPA_AUTH_ALG_OPEN
;
712 wpa_s
->sme
.sae_pmksa_caching
= 1;
715 if (!skip_auth
&& params
.auth_alg
== WPA_AUTH_ALG_SAE
) {
717 resp
= sme_auth_build_sae_commit(wpa_s
, ssid
,
721 resp
= sme_auth_build_sae_confirm(wpa_s
, 0);
723 wpas_connection_failed(wpa_s
, bss
->bssid
);
726 params
.auth_data
= wpabuf_head(resp
);
727 params
.auth_data_len
= wpabuf_len(resp
);
728 wpa_s
->sme
.sae
.state
= start
? SAE_COMMITTED
: SAE_CONFIRMED
;
730 #endif /* CONFIG_SAE */
732 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
733 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
734 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
736 wpas_notify_bssid_changed(wpa_s
);
738 old_ssid
= wpa_s
->current_ssid
;
739 wpa_s
->current_ssid
= ssid
;
740 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
741 wpa_supplicant_initiate_eapol(wpa_s
);
744 /* TODO: FILS operations can in some cases be done between different
745 * network_ctx (i.e., same credentials can be used with multiple
747 if (params
.auth_alg
== WPA_AUTH_ALG_OPEN
&&
748 wpa_key_mgmt_fils(ssid
->key_mgmt
)) {
751 const u8
*realm
, *username
, *rrk
;
752 size_t realm_len
, username_len
, rrk_len
;
756 * Check FILS Indication element (FILS Information field) bits
757 * indicating supported authentication algorithms against local
758 * configuration (ssid->fils_dh_group). Try to use FILS
759 * authentication only if the AP supports the combination in the
760 * network profile. */
761 indic
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
762 if (!indic
|| indic
[1] < 2) {
763 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
764 " does not include FILS Indication element - cannot use FILS authentication with it",
765 MAC2STR(bss
->bssid
));
769 fils_info
= WPA_GET_LE16(indic
+ 2);
770 if (ssid
->fils_dh_group
== 0 && !(fils_info
& BIT(9))) {
771 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
772 " does not support FILS SK without PFS - cannot use FILS authentication with it",
773 MAC2STR(bss
->bssid
));
776 if (ssid
->fils_dh_group
!= 0 && !(fils_info
& BIT(10))) {
777 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
778 " does not support FILS SK with PFS - cannot use FILS authentication with it",
779 MAC2STR(bss
->bssid
));
783 if (wpa_s
->last_con_fail_realm
&&
784 eapol_sm_get_erp_info(wpa_s
->eapol
, &ssid
->eap
,
785 &username
, &username_len
,
786 &realm
, &realm_len
, &next_seq_num
,
787 &rrk
, &rrk_len
) == 0 &&
788 realm
&& realm_len
== wpa_s
->last_con_fail_realm_len
&&
789 os_memcmp(realm
, wpa_s
->last_con_fail_realm
,
791 wpa_printf(MSG_DEBUG
,
792 "SME: FILS authentication for this realm failed last time - try to regenerate ERP key hierarchy");
796 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
798 wpa_bss_get_fils_cache_id(bss
),
800 wpa_printf(MSG_DEBUG
,
801 "SME: Try to use FILS with PMKSA caching");
802 resp
= fils_build_auth(wpa_s
->wpa
, ssid
->fils_dh_group
, md
);
806 if (ssid
->fils_dh_group
)
807 wpa_printf(MSG_DEBUG
,
808 "SME: Try to use FILS SK authentication with PFS (DH Group %u)",
809 ssid
->fils_dh_group
);
811 wpa_printf(MSG_DEBUG
,
812 "SME: Try to use FILS SK authentication without PFS");
813 auth_alg
= ssid
->fils_dh_group
?
814 WPA_AUTH_ALG_FILS_SK_PFS
: WPA_AUTH_ALG_FILS
;
815 params
.auth_alg
= auth_alg
;
816 params
.auth_data
= wpabuf_head(resp
);
817 params
.auth_data_len
= wpabuf_len(resp
);
818 wpa_s
->sme
.auth_alg
= auth_alg
;
822 #endif /* CONFIG_FILS */
824 wpa_supplicant_cancel_sched_scan(wpa_s
);
825 wpa_supplicant_cancel_scan(wpa_s
);
827 wpa_msg(wpa_s
, MSG_INFO
, "SME: Trying to authenticate with " MACSTR
828 " (SSID='%s' freq=%d MHz)", MAC2STR(params
.bssid
),
829 wpa_ssid_txt(params
.ssid
, params
.ssid_len
), params
.freq
);
831 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
832 wpa_clear_keys(wpa_s
, bss
->bssid
);
833 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
834 if (old_ssid
!= wpa_s
->current_ssid
)
835 wpas_notify_network_changed(wpa_s
);
838 hs20_configure_frame_filters(wpa_s
);
839 #endif /* CONFIG_HS20 */
843 * If multi-channel concurrency is not supported, check for any
844 * frequency conflict. In case of any frequency conflict, remove the
845 * least prioritized connection.
847 if (wpa_s
->num_multichan_concurrent
< 2) {
849 num
= get_shared_radio_freqs(wpa_s
, &freq
, 1);
850 if (num
> 0 && freq
> 0 && freq
!= params
.freq
) {
851 wpa_printf(MSG_DEBUG
,
852 "Conflicting frequency found (%d != %d)",
854 if (wpas_p2p_handle_frequency_conflicts(wpa_s
,
857 wpas_connection_failed(wpa_s
, bss
->bssid
);
858 wpa_supplicant_mark_disassoc(wpa_s
);
860 wpas_connect_work_done(wpa_s
);
865 #endif /* CONFIG_P2P */
868 wpa_msg(wpa_s
, MSG_DEBUG
,
869 "SME: Skip authentication step on reassoc-to-same-BSS");
871 sme_associate(wpa_s
, ssid
->mode
, bss
->bssid
, WLAN_AUTH_OPEN
);
876 wpa_s
->sme
.auth_alg
= params
.auth_alg
;
877 if (wpa_drv_authenticate(wpa_s
, ¶ms
) < 0) {
878 wpa_msg(wpa_s
, MSG_INFO
, "SME: Authentication request to the "
880 wpas_connection_failed(wpa_s
, bss
->bssid
);
881 wpa_supplicant_mark_disassoc(wpa_s
);
883 wpas_connect_work_done(wpa_s
);
887 eloop_register_timeout(SME_AUTH_TIMEOUT
, 0, sme_auth_timer
, wpa_s
,
891 * Association will be started based on the authentication event from
899 static void sme_auth_start_cb(struct wpa_radio_work
*work
, int deinit
)
901 struct wpa_connect_work
*cwork
= work
->ctx
;
902 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
906 wpa_s
->connect_work
= NULL
;
908 wpas_connect_work_free(cwork
);
912 wpa_s
->connect_work
= work
;
914 if (cwork
->bss_removed
||
915 !wpas_valid_bss_ssid(wpa_s
, cwork
->bss
, cwork
->ssid
) ||
916 wpas_network_disabled(wpa_s
, cwork
->ssid
)) {
917 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: BSS/SSID entry for authentication not valid anymore - drop connection attempt");
918 wpas_connect_work_done(wpa_s
);
922 /* Starting new connection, so clear the possibly used WPA IE from the
923 * previous association. */
924 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
925 wpa_sm_set_assoc_rsnxe(wpa_s
->wpa
, NULL
, 0);
926 wpa_s
->rsnxe_len
= 0;
928 sme_send_authentication(wpa_s
, cwork
->bss
, cwork
->ssid
, 1);
932 void sme_authenticate(struct wpa_supplicant
*wpa_s
,
933 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
935 struct wpa_connect_work
*cwork
;
937 if (bss
== NULL
|| ssid
== NULL
)
939 if (wpa_s
->connect_work
) {
940 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Reject sme_authenticate() call since connect_work exist");
944 if (radio_work_pending(wpa_s
, "sme-connect")) {
946 * The previous sme-connect work might no longer be valid due to
947 * the fact that the BSS list was updated. In addition, it makes
948 * sense to adhere to the 'newer' decision.
950 wpa_dbg(wpa_s
, MSG_DEBUG
,
951 "SME: Remove previous pending sme-connect");
952 radio_remove_works(wpa_s
, "sme-connect", 0);
955 wpas_abort_ongoing_scan(wpa_s
);
957 cwork
= os_zalloc(sizeof(*cwork
));
965 wpa_s
->sme
.sae
.state
= SAE_NOTHING
;
966 wpa_s
->sme
.sae
.send_confirm
= 0;
967 wpa_s
->sme
.sae_group_index
= 0;
968 #endif /* CONFIG_SAE */
970 if (radio_add_work(wpa_s
, bss
->freq
, "sme-connect", 1,
971 sme_auth_start_cb
, cwork
) < 0)
972 wpas_connect_work_free(cwork
);
978 static int sme_external_auth_build_buf(struct wpabuf
*buf
,
979 struct wpabuf
*params
,
980 const u8
*sa
, const u8
*da
,
981 u16 auth_transaction
, u16 seq_num
,
984 struct ieee80211_mgmt
*resp
;
986 resp
= wpabuf_put(buf
, offsetof(struct ieee80211_mgmt
,
989 resp
->frame_control
= host_to_le16((WLAN_FC_TYPE_MGMT
<< 2) |
990 (WLAN_FC_STYPE_AUTH
<< 4));
991 os_memcpy(resp
->da
, da
, ETH_ALEN
);
992 os_memcpy(resp
->sa
, sa
, ETH_ALEN
);
993 os_memcpy(resp
->bssid
, da
, ETH_ALEN
);
994 resp
->u
.auth
.auth_alg
= host_to_le16(WLAN_AUTH_SAE
);
995 resp
->seq_ctrl
= host_to_le16(seq_num
<< 4);
996 resp
->u
.auth
.auth_transaction
= host_to_le16(auth_transaction
);
997 resp
->u
.auth
.status_code
= host_to_le16(status_code
);
999 wpabuf_put_buf(buf
, params
);
1005 static int sme_external_auth_send_sae_commit(struct wpa_supplicant
*wpa_s
,
1007 struct wpa_ssid
*ssid
)
1009 struct wpabuf
*resp
, *buf
;
1012 resp
= sme_auth_build_sae_commit(wpa_s
, ssid
, bssid
, 1, 0, &use_pt
);
1014 wpa_printf(MSG_DEBUG
, "SAE: Failed to build SAE commit");
1018 wpa_s
->sme
.sae
.state
= SAE_COMMITTED
;
1019 buf
= wpabuf_alloc(4 + SAE_COMMIT_MAX_LEN
+ wpabuf_len(resp
));
1025 wpa_s
->sme
.seq_num
++;
1026 sme_external_auth_build_buf(buf
, resp
, wpa_s
->own_addr
,
1027 bssid
, 1, wpa_s
->sme
.seq_num
,
1028 use_pt
? WLAN_STATUS_SAE_HASH_TO_ELEMENT
:
1029 WLAN_STATUS_SUCCESS
);
1030 wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
), 1, 0, 0);
1038 static void sme_send_external_auth_status(struct wpa_supplicant
*wpa_s
,
1041 struct external_auth params
;
1043 os_memset(¶ms
, 0, sizeof(params
));
1044 params
.status
= status
;
1045 params
.ssid
= wpa_s
->sme
.ext_auth_ssid
;
1046 params
.ssid_len
= wpa_s
->sme
.ext_auth_ssid_len
;
1047 params
.bssid
= wpa_s
->sme
.ext_auth_bssid
;
1048 if (wpa_s
->conf
->sae_pmkid_in_assoc
&& status
== WLAN_STATUS_SUCCESS
)
1049 params
.pmkid
= wpa_s
->sme
.sae
.pmkid
;
1050 wpa_drv_send_external_auth_status(wpa_s
, ¶ms
);
1054 static int sme_handle_external_auth_start(struct wpa_supplicant
*wpa_s
,
1055 union wpa_event_data
*data
)
1057 struct wpa_ssid
*ssid
;
1058 size_t ssid_str_len
= data
->external_auth
.ssid_len
;
1059 const u8
*ssid_str
= data
->external_auth
.ssid
;
1061 /* Get the SSID conf from the ssid string obtained */
1062 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
1063 if (!wpas_network_disabled(wpa_s
, ssid
) &&
1064 ssid_str_len
== ssid
->ssid_len
&&
1065 os_memcmp(ssid_str
, ssid
->ssid
, ssid_str_len
) == 0 &&
1066 (ssid
->key_mgmt
& (WPA_KEY_MGMT_SAE
| WPA_KEY_MGMT_FT_SAE
)))
1070 sme_external_auth_send_sae_commit(wpa_s
, data
->external_auth
.bssid
,
1078 static void sme_external_auth_send_sae_confirm(struct wpa_supplicant
*wpa_s
,
1081 struct wpabuf
*resp
, *buf
;
1083 resp
= sme_auth_build_sae_confirm(wpa_s
, 1);
1085 wpa_printf(MSG_DEBUG
, "SAE: Confirm message buf alloc failure");
1089 wpa_s
->sme
.sae
.state
= SAE_CONFIRMED
;
1090 buf
= wpabuf_alloc(4 + SAE_CONFIRM_MAX_LEN
+ wpabuf_len(resp
));
1092 wpa_printf(MSG_DEBUG
, "SAE: Auth Confirm buf alloc failure");
1096 wpa_s
->sme
.seq_num
++;
1097 sme_external_auth_build_buf(buf
, resp
, wpa_s
->own_addr
,
1098 da
, 2, wpa_s
->sme
.seq_num
,
1099 WLAN_STATUS_SUCCESS
);
1100 wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
), 1, 0, 0);
1106 void sme_external_auth_trigger(struct wpa_supplicant
*wpa_s
,
1107 union wpa_event_data
*data
)
1109 if (RSN_SELECTOR_GET(&data
->external_auth
.key_mgmt_suite
) !=
1110 RSN_AUTH_KEY_MGMT_SAE
)
1113 if (data
->external_auth
.action
== EXT_AUTH_START
) {
1114 if (!data
->external_auth
.bssid
|| !data
->external_auth
.ssid
)
1116 os_memcpy(wpa_s
->sme
.ext_auth_bssid
, data
->external_auth
.bssid
,
1118 os_memcpy(wpa_s
->sme
.ext_auth_ssid
, data
->external_auth
.ssid
,
1119 data
->external_auth
.ssid_len
);
1120 wpa_s
->sme
.ext_auth_ssid_len
= data
->external_auth
.ssid_len
;
1121 wpa_s
->sme
.seq_num
= 0;
1122 wpa_s
->sme
.sae
.state
= SAE_NOTHING
;
1123 wpa_s
->sme
.sae
.send_confirm
= 0;
1124 wpa_s
->sme
.sae_group_index
= 0;
1125 if (sme_handle_external_auth_start(wpa_s
, data
) < 0)
1126 sme_send_external_auth_status(wpa_s
,
1127 WLAN_STATUS_UNSPECIFIED_FAILURE
);
1128 } else if (data
->external_auth
.action
== EXT_AUTH_ABORT
) {
1129 /* Report failure to driver for the wrong trigger */
1130 sme_send_external_auth_status(wpa_s
,
1131 WLAN_STATUS_UNSPECIFIED_FAILURE
);
1136 static int sme_sae_is_group_enabled(struct wpa_supplicant
*wpa_s
, int group
)
1138 int *groups
= wpa_s
->conf
->sae_groups
;
1139 int default_groups
[] = { 19, 20, 21, 0 };
1143 groups
= default_groups
;
1145 for (i
= 0; groups
[i
] > 0; i
++) {
1146 if (groups
[i
] == group
)
1154 static int sme_check_sae_rejected_groups(struct wpa_supplicant
*wpa_s
,
1155 const struct wpabuf
*groups
)
1163 pos
= wpabuf_head(groups
);
1164 count
= wpabuf_len(groups
) / 2;
1165 for (i
= 0; i
< count
; i
++) {
1169 group
= WPA_GET_LE16(pos
);
1171 enabled
= sme_sae_is_group_enabled(wpa_s
, group
);
1172 wpa_printf(MSG_DEBUG
, "SAE: Rejected group %u is %s",
1173 group
, enabled
? "enabled" : "disabled");
1182 static int sme_sae_auth(struct wpa_supplicant
*wpa_s
, u16 auth_transaction
,
1183 u16 status_code
, const u8
*data
, size_t len
,
1184 int external
, const u8
*sa
)
1188 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SAE authentication transaction %u "
1189 "status code %u", auth_transaction
, status_code
);
1191 if (auth_transaction
== 1 &&
1192 status_code
== WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
&&
1193 wpa_s
->sme
.sae
.state
== SAE_COMMITTED
&&
1194 (external
|| wpa_s
->current_bss
) && wpa_s
->current_ssid
) {
1195 int default_groups
[] = { 19, 20, 21, 0 };
1197 const u8
*token_pos
;
1201 groups
= wpa_s
->conf
->sae_groups
;
1202 if (!groups
|| groups
[0] <= 0)
1203 groups
= default_groups
;
1205 wpa_hexdump(MSG_DEBUG
, "SME: SAE anti-clogging token request",
1207 if (len
< sizeof(le16
)) {
1208 wpa_dbg(wpa_s
, MSG_DEBUG
,
1209 "SME: Too short SAE anti-clogging token request");
1212 group
= WPA_GET_LE16(data
);
1213 wpa_dbg(wpa_s
, MSG_DEBUG
,
1214 "SME: SAE anti-clogging token requested (group %u)",
1216 if (sae_group_allowed(&wpa_s
->sme
.sae
, groups
, group
) !=
1217 WLAN_STATUS_SUCCESS
) {
1218 wpa_dbg(wpa_s
, MSG_ERROR
,
1219 "SME: SAE group %u of anti-clogging request is invalid",
1223 wpabuf_free(wpa_s
->sme
.sae_token
);
1224 token_pos
= data
+ sizeof(le16
);
1225 token_len
= len
- sizeof(le16
);
1226 if (wpa_s
->sme
.sae
.tmp
)
1227 h2e
= wpa_s
->sme
.sae
.tmp
->h2e
;
1229 if (token_len
< 3) {
1230 wpa_dbg(wpa_s
, MSG_DEBUG
,
1231 "SME: Too short SAE anti-clogging token container");
1234 if (token_pos
[0] != WLAN_EID_EXTENSION
||
1235 token_pos
[1] == 0 ||
1236 token_pos
[1] > token_len
- 2 ||
1237 token_pos
[2] != WLAN_EID_EXT_ANTI_CLOGGING_TOKEN
) {
1238 wpa_dbg(wpa_s
, MSG_DEBUG
,
1239 "SME: Invalid SAE anti-clogging token container header");
1242 token_len
= token_pos
[1] - 1;
1245 wpa_s
->sme
.sae_token
= wpabuf_alloc_copy(token_pos
, token_len
);
1246 wpa_hexdump_buf(MSG_DEBUG
, "SME: Requested anti-clogging token",
1247 wpa_s
->sme
.sae_token
);
1249 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
1250 wpa_s
->current_ssid
, 2);
1252 sme_external_auth_send_sae_commit(
1253 wpa_s
, wpa_s
->sme
.ext_auth_bssid
,
1254 wpa_s
->current_ssid
);
1258 if (auth_transaction
== 1 &&
1259 status_code
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1260 wpa_s
->sme
.sae
.state
== SAE_COMMITTED
&&
1261 (external
|| wpa_s
->current_bss
) && wpa_s
->current_ssid
) {
1262 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SAE group not supported");
1263 int_array_add_unique(&wpa_s
->sme
.sae_rejected_groups
,
1264 wpa_s
->sme
.sae
.group
);
1265 wpa_s
->sme
.sae_group_index
++;
1266 if (sme_set_sae_group(wpa_s
) < 0)
1267 return -1; /* no other groups enabled */
1268 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Try next enabled SAE group");
1270 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
1271 wpa_s
->current_ssid
, 1);
1273 sme_external_auth_send_sae_commit(
1274 wpa_s
, wpa_s
->sme
.ext_auth_bssid
,
1275 wpa_s
->current_ssid
);
1279 if (auth_transaction
== 1 &&
1280 status_code
== WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER
) {
1281 const u8
*bssid
= sa
? sa
: wpa_s
->pending_bssid
;
1283 wpa_msg(wpa_s
, MSG_INFO
,
1284 WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER MACSTR
,
1289 if (status_code
!= WLAN_STATUS_SUCCESS
&&
1290 status_code
!= WLAN_STATUS_SAE_HASH_TO_ELEMENT
)
1293 if (auth_transaction
== 1) {
1296 groups
= wpa_s
->conf
->sae_groups
;
1298 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME SAE commit");
1299 if ((!external
&& wpa_s
->current_bss
== NULL
) ||
1300 wpa_s
->current_ssid
== NULL
)
1302 if (wpa_s
->sme
.sae
.state
!= SAE_COMMITTED
) {
1303 wpa_printf(MSG_DEBUG
,
1304 "SAE: Ignore commit message while waiting for confirm");
1307 if (wpa_s
->sme
.sae
.tmp
&& wpa_s
->sme
.sae
.tmp
->h2e
&&
1308 status_code
== WLAN_STATUS_SUCCESS
) {
1309 wpa_printf(MSG_DEBUG
,
1310 "SAE: Unexpected use of status code 0 in SAE commit when H2E was expected");
1313 if (wpa_s
->sme
.sae
.tmp
&& !wpa_s
->sme
.sae
.tmp
->h2e
&&
1314 status_code
== WLAN_STATUS_SAE_HASH_TO_ELEMENT
) {
1315 wpa_printf(MSG_DEBUG
,
1316 "SAE: Unexpected use of status code for H2E in SAE commit when H2E was not expected");
1320 if (groups
&& groups
[0] <= 0)
1322 res
= sae_parse_commit(&wpa_s
->sme
.sae
, data
, len
, NULL
, NULL
,
1323 groups
, status_code
==
1324 WLAN_STATUS_SAE_HASH_TO_ELEMENT
);
1325 if (res
== SAE_SILENTLY_DISCARD
) {
1326 wpa_printf(MSG_DEBUG
,
1327 "SAE: Drop commit message due to reflection attack");
1330 if (res
!= WLAN_STATUS_SUCCESS
)
1333 if (wpa_s
->sme
.sae
.tmp
&&
1334 sme_check_sae_rejected_groups(
1336 wpa_s
->sme
.sae
.tmp
->peer_rejected_groups
))
1339 if (sae_process_commit(&wpa_s
->sme
.sae
) < 0) {
1340 wpa_printf(MSG_DEBUG
, "SAE: Failed to process peer "
1345 wpabuf_free(wpa_s
->sme
.sae_token
);
1346 wpa_s
->sme
.sae_token
= NULL
;
1348 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
1349 wpa_s
->current_ssid
, 0);
1351 sme_external_auth_send_sae_confirm(wpa_s
, sa
);
1353 } else if (auth_transaction
== 2) {
1354 if (status_code
!= WLAN_STATUS_SUCCESS
)
1356 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME SAE confirm");
1357 if (wpa_s
->sme
.sae
.state
!= SAE_CONFIRMED
)
1359 if (sae_check_confirm(&wpa_s
->sme
.sae
, data
, len
) < 0)
1361 wpa_s
->sme
.sae
.state
= SAE_ACCEPTED
;
1362 sae_clear_temp_data(&wpa_s
->sme
.sae
);
1365 /* Report success to driver */
1366 sme_send_external_auth_status(wpa_s
,
1367 WLAN_STATUS_SUCCESS
);
1377 static int sme_sae_set_pmk(struct wpa_supplicant
*wpa_s
, const u8
*bssid
)
1379 wpa_printf(MSG_DEBUG
,
1380 "SME: SAE completed - setting PMK for 4-way handshake");
1381 wpa_sm_set_pmk(wpa_s
->wpa
, wpa_s
->sme
.sae
.pmk
, PMK_LEN
,
1382 wpa_s
->sme
.sae
.pmkid
, bssid
);
1383 if (wpa_s
->conf
->sae_pmkid_in_assoc
) {
1384 /* Update the own RSNE contents now that we have set the PMK
1385 * and added a PMKSA cache entry based on the successfully
1386 * completed SAE exchange. In practice, this will add the PMKID
1388 if (wpa_s
->sme
.assoc_req_ie_len
+ 2 + PMKID_LEN
>
1389 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1390 wpa_msg(wpa_s
, MSG_WARNING
,
1391 "RSN: Not enough room for inserting own PMKID into RSNE");
1394 if (wpa_insert_pmkid(wpa_s
->sme
.assoc_req_ie
,
1395 &wpa_s
->sme
.assoc_req_ie_len
,
1396 wpa_s
->sme
.sae
.pmkid
) < 0)
1398 wpa_hexdump(MSG_DEBUG
,
1399 "SME: Updated Association Request IEs",
1400 wpa_s
->sme
.assoc_req_ie
,
1401 wpa_s
->sme
.assoc_req_ie_len
);
1408 void sme_external_auth_mgmt_rx(struct wpa_supplicant
*wpa_s
,
1409 const u8
*auth_frame
, size_t len
)
1411 const struct ieee80211_mgmt
*header
;
1414 header
= (const struct ieee80211_mgmt
*) auth_frame
;
1415 auth_length
= IEEE80211_HDRLEN
+ sizeof(header
->u
.auth
);
1417 if (len
< auth_length
) {
1418 /* Notify failure to the driver */
1419 sme_send_external_auth_status(wpa_s
,
1420 WLAN_STATUS_UNSPECIFIED_FAILURE
);
1424 if (le_to_host16(header
->u
.auth
.auth_alg
) == WLAN_AUTH_SAE
) {
1428 wpa_s
, le_to_host16(header
->u
.auth
.auth_transaction
),
1429 le_to_host16(header
->u
.auth
.status_code
),
1430 header
->u
.auth
.variable
,
1431 len
- auth_length
, 1, header
->sa
);
1433 /* Notify failure to the driver */
1434 sme_send_external_auth_status(
1435 wpa_s
, WLAN_STATUS_UNSPECIFIED_FAILURE
);
1441 if (sme_sae_set_pmk(wpa_s
, wpa_s
->sme
.ext_auth_bssid
) < 0)
1446 #endif /* CONFIG_SAE */
1449 void sme_event_auth(struct wpa_supplicant
*wpa_s
, union wpa_event_data
*data
)
1451 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1454 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication event "
1455 "when network is not selected");
1459 if (wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) {
1460 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication event "
1461 "when not in authenticating state");
1465 if (os_memcmp(wpa_s
->pending_bssid
, data
->auth
.peer
, ETH_ALEN
) != 0) {
1466 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication with "
1467 "unexpected peer " MACSTR
,
1468 MAC2STR(data
->auth
.peer
));
1472 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Authentication response: peer=" MACSTR
1473 " auth_type=%d auth_transaction=%d status_code=%d",
1474 MAC2STR(data
->auth
.peer
), data
->auth
.auth_type
,
1475 data
->auth
.auth_transaction
, data
->auth
.status_code
);
1476 wpa_hexdump(MSG_MSGDUMP
, "SME: Authentication response IEs",
1477 data
->auth
.ies
, data
->auth
.ies_len
);
1479 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1482 if (data
->auth
.auth_type
== WLAN_AUTH_SAE
) {
1484 res
= sme_sae_auth(wpa_s
, data
->auth
.auth_transaction
,
1485 data
->auth
.status_code
, data
->auth
.ies
,
1486 data
->auth
.ies_len
, 0, NULL
);
1488 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1489 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1495 if (sme_sae_set_pmk(wpa_s
, wpa_s
->pending_bssid
) < 0)
1498 #endif /* CONFIG_SAE */
1500 if (data
->auth
.status_code
!= WLAN_STATUS_SUCCESS
) {
1501 char *ie_txt
= NULL
;
1503 if (data
->auth
.ies
&& data
->auth
.ies_len
) {
1504 size_t buflen
= 2 * data
->auth
.ies_len
+ 1;
1505 ie_txt
= os_malloc(buflen
);
1507 wpa_snprintf_hex(ie_txt
, buflen
, data
->auth
.ies
,
1508 data
->auth
.ies_len
);
1511 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AUTH_REJECT MACSTR
1512 " auth_type=%u auth_transaction=%u status_code=%u%s%s",
1513 MAC2STR(data
->auth
.peer
), data
->auth
.auth_type
,
1514 data
->auth
.auth_transaction
, data
->auth
.status_code
,
1515 ie_txt
? " ie=" : "",
1516 ie_txt
? ie_txt
: "");
1520 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
||
1521 wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS_SK_PFS
)
1522 fils_connection_failure(wpa_s
);
1523 #endif /* CONFIG_FILS */
1525 if (data
->auth
.status_code
!=
1526 WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
||
1527 wpa_s
->sme
.auth_alg
== data
->auth
.auth_type
||
1528 wpa_s
->current_ssid
->auth_alg
== WPA_AUTH_ALG_LEAP
) {
1529 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1530 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1534 wpas_connect_work_done(wpa_s
);
1536 switch (data
->auth
.auth_type
) {
1537 case WLAN_AUTH_OPEN
:
1538 wpa_s
->current_ssid
->auth_alg
= WPA_AUTH_ALG_SHARED
;
1540 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying SHARED auth");
1541 wpa_supplicant_associate(wpa_s
, wpa_s
->current_bss
,
1542 wpa_s
->current_ssid
);
1545 case WLAN_AUTH_SHARED_KEY
:
1546 wpa_s
->current_ssid
->auth_alg
= WPA_AUTH_ALG_LEAP
;
1548 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying LEAP auth");
1549 wpa_supplicant_associate(wpa_s
, wpa_s
->current_bss
,
1550 wpa_s
->current_ssid
);
1558 #ifdef CONFIG_IEEE80211R
1559 if (data
->auth
.auth_type
== WLAN_AUTH_FT
) {
1560 const u8
*ric_ies
= NULL
;
1561 size_t ric_ies_len
= 0;
1563 if (wpa_s
->ric_ies
) {
1564 ric_ies
= wpabuf_head(wpa_s
->ric_ies
);
1565 ric_ies_len
= wpabuf_len(wpa_s
->ric_ies
);
1567 if (wpa_ft_process_response(wpa_s
->wpa
, data
->auth
.ies
,
1568 data
->auth
.ies_len
, 0,
1570 ric_ies
, ric_ies_len
) < 0) {
1571 wpa_dbg(wpa_s
, MSG_DEBUG
,
1572 "SME: FT Authentication response processing failed");
1573 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1575 " reason=%d locally_generated=1",
1576 MAC2STR(wpa_s
->pending_bssid
),
1577 WLAN_REASON_DEAUTH_LEAVING
);
1578 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1579 wpa_supplicant_mark_disassoc(wpa_s
);
1583 #endif /* CONFIG_IEEE80211R */
1586 if (data
->auth
.auth_type
== WLAN_AUTH_FILS_SK
||
1587 data
->auth
.auth_type
== WLAN_AUTH_FILS_SK_PFS
) {
1588 u16 expect_auth_type
;
1590 expect_auth_type
= wpa_s
->sme
.auth_alg
==
1591 WPA_AUTH_ALG_FILS_SK_PFS
? WLAN_AUTH_FILS_SK_PFS
:
1593 if (data
->auth
.auth_type
!= expect_auth_type
) {
1594 wpa_dbg(wpa_s
, MSG_DEBUG
,
1595 "SME: FILS Authentication response used different auth alg (%u; expected %u)",
1596 data
->auth
.auth_type
, expect_auth_type
);
1597 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1599 " reason=%d locally_generated=1",
1600 MAC2STR(wpa_s
->pending_bssid
),
1601 WLAN_REASON_DEAUTH_LEAVING
);
1602 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1603 wpa_supplicant_mark_disassoc(wpa_s
);
1607 if (fils_process_auth(wpa_s
->wpa
, wpa_s
->pending_bssid
,
1608 data
->auth
.ies
, data
->auth
.ies_len
) < 0) {
1609 wpa_dbg(wpa_s
, MSG_DEBUG
,
1610 "SME: FILS Authentication response processing failed");
1611 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1613 " reason=%d locally_generated=1",
1614 MAC2STR(wpa_s
->pending_bssid
),
1615 WLAN_REASON_DEAUTH_LEAVING
);
1616 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1617 wpa_supplicant_mark_disassoc(wpa_s
);
1621 #endif /* CONFIG_FILS */
1623 sme_associate(wpa_s
, ssid
->mode
, data
->auth
.peer
,
1624 data
->auth
.auth_type
);
1628 #ifdef CONFIG_IEEE80211R
1629 static void remove_ie(u8
*buf
, size_t *len
, u8 eid
)
1631 u8
*pos
, *next
, *end
;
1633 pos
= (u8
*) get_ie(buf
, *len
, eid
);
1635 next
= pos
+ 2 + pos
[1];
1638 os_memmove(pos
, next
, end
- next
);
1641 #endif /* CONFIG_IEEE80211R */
1644 void sme_associate(struct wpa_supplicant
*wpa_s
, enum wpas_mode mode
,
1645 const u8
*bssid
, u16 auth_type
)
1647 struct wpa_driver_associate_params params
;
1648 struct ieee802_11_elems elems
;
1650 u8 nonces
[2 * FILS_NONCE_LEN
];
1651 #endif /* CONFIG_FILS */
1652 #ifdef CONFIG_HT_OVERRIDES
1653 struct ieee80211_ht_capabilities htcaps
;
1654 struct ieee80211_ht_capabilities htcaps_mask
;
1655 #endif /* CONFIG_HT_OVERRIDES */
1656 #ifdef CONFIG_VHT_OVERRIDES
1657 struct ieee80211_vht_capabilities vhtcaps
;
1658 struct ieee80211_vht_capabilities vhtcaps_mask
;
1659 #endif /* CONFIG_VHT_OVERRIDES */
1661 os_memset(¶ms
, 0, sizeof(params
));
1664 if (auth_type
== WLAN_AUTH_FILS_SK
||
1665 auth_type
== WLAN_AUTH_FILS_SK_PFS
) {
1667 const u8
*snonce
, *anonce
;
1668 const unsigned int max_hlp
= 20;
1669 struct wpabuf
*hlp
[max_hlp
];
1670 unsigned int i
, num_hlp
= 0;
1671 struct fils_hlp_req
*req
;
1673 dl_list_for_each(req
, &wpa_s
->fils_hlp_req
, struct fils_hlp_req
,
1675 hlp
[num_hlp
] = wpabuf_alloc(2 * ETH_ALEN
+ 6 +
1676 wpabuf_len(req
->pkt
));
1679 wpabuf_put_data(hlp
[num_hlp
], req
->dst
, ETH_ALEN
);
1680 wpabuf_put_data(hlp
[num_hlp
], wpa_s
->own_addr
,
1682 wpabuf_put_data(hlp
[num_hlp
],
1683 "\xaa\xaa\x03\x00\x00\x00", 6);
1684 wpabuf_put_buf(hlp
[num_hlp
], req
->pkt
);
1686 if (num_hlp
>= max_hlp
)
1690 buf
= fils_build_assoc_req(wpa_s
->wpa
, ¶ms
.fils_kek
,
1691 ¶ms
.fils_kek_len
, &snonce
,
1693 (const struct wpabuf
**) hlp
,
1695 for (i
= 0; i
< num_hlp
; i
++)
1696 wpabuf_free(hlp
[i
]);
1699 wpa_hexdump(MSG_DEBUG
, "FILS: assoc_req before FILS elements",
1700 wpa_s
->sme
.assoc_req_ie
,
1701 wpa_s
->sme
.assoc_req_ie_len
);
1702 #ifdef CONFIG_IEEE80211R
1703 if (wpa_key_mgmt_ft(wpa_s
->key_mgmt
)) {
1704 /* Remove RSNE and MDE to allow them to be overridden
1705 * with FILS+FT specific values from
1706 * fils_build_assoc_req(). */
1707 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1708 &wpa_s
->sme
.assoc_req_ie_len
,
1710 wpa_hexdump(MSG_DEBUG
,
1711 "FILS: assoc_req after RSNE removal",
1712 wpa_s
->sme
.assoc_req_ie
,
1713 wpa_s
->sme
.assoc_req_ie_len
);
1714 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1715 &wpa_s
->sme
.assoc_req_ie_len
,
1716 WLAN_EID_MOBILITY_DOMAIN
);
1717 wpa_hexdump(MSG_DEBUG
,
1718 "FILS: assoc_req after MDE removal",
1719 wpa_s
->sme
.assoc_req_ie
,
1720 wpa_s
->sme
.assoc_req_ie_len
);
1722 #endif /* CONFIG_IEEE80211R */
1723 /* TODO: Make wpa_s->sme.assoc_req_ie use dynamic allocation */
1724 if (wpa_s
->sme
.assoc_req_ie_len
+ wpabuf_len(buf
) >
1725 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1726 wpa_printf(MSG_ERROR
,
1727 "FILS: Not enough buffer room for own AssocReq elements");
1731 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1732 wpabuf_head(buf
), wpabuf_len(buf
));
1733 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(buf
);
1735 wpa_hexdump(MSG_DEBUG
, "FILS: assoc_req after FILS elements",
1736 wpa_s
->sme
.assoc_req_ie
,
1737 wpa_s
->sme
.assoc_req_ie_len
);
1739 os_memcpy(nonces
, snonce
, FILS_NONCE_LEN
);
1740 os_memcpy(nonces
+ FILS_NONCE_LEN
, anonce
, FILS_NONCE_LEN
);
1741 params
.fils_nonces
= nonces
;
1742 params
.fils_nonces_len
= sizeof(nonces
);
1744 #endif /* CONFIG_FILS */
1747 #ifdef CONFIG_TESTING_OPTIONS
1748 if (get_ie_ext(wpa_s
->sme
.assoc_req_ie
, wpa_s
->sme
.assoc_req_ie_len
,
1749 WLAN_EID_EXT_OWE_DH_PARAM
)) {
1750 wpa_printf(MSG_INFO
, "TESTING: Override OWE DH element");
1752 #endif /* CONFIG_TESTING_OPTIONS */
1753 if (auth_type
== WLAN_AUTH_OPEN
&&
1754 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
) {
1755 struct wpabuf
*owe_ie
;
1758 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->owe_group
) {
1759 group
= wpa_s
->current_ssid
->owe_group
;
1760 } else if (wpa_s
->assoc_status_code
==
1761 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
) {
1762 if (wpa_s
->last_owe_group
== 19)
1764 else if (wpa_s
->last_owe_group
== 20)
1767 group
= OWE_DH_GROUP
;
1769 group
= OWE_DH_GROUP
;
1772 wpa_s
->last_owe_group
= group
;
1773 wpa_printf(MSG_DEBUG
, "OWE: Try to use group %u", group
);
1774 owe_ie
= owe_build_assoc_req(wpa_s
->wpa
, group
);
1776 wpa_printf(MSG_ERROR
,
1777 "OWE: Failed to build IE for Association Request frame");
1780 if (wpa_s
->sme
.assoc_req_ie_len
+ wpabuf_len(owe_ie
) >
1781 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1782 wpa_printf(MSG_ERROR
,
1783 "OWE: Not enough buffer room for own Association Request frame elements");
1784 wpabuf_free(owe_ie
);
1787 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1788 wpabuf_head(owe_ie
), wpabuf_len(owe_ie
));
1789 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(owe_ie
);
1790 wpabuf_free(owe_ie
);
1792 #endif /* CONFIG_OWE */
1795 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
&& wpa_s
->current_ssid
&&
1796 wpa_s
->current_ssid
->dpp_netaccesskey
) {
1797 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1799 dpp_pfs_free(wpa_s
->dpp_pfs
);
1800 wpa_s
->dpp_pfs
= dpp_pfs_init(ssid
->dpp_netaccesskey
,
1801 ssid
->dpp_netaccesskey_len
);
1802 if (!wpa_s
->dpp_pfs
) {
1803 wpa_printf(MSG_DEBUG
, "DPP: Could not initialize PFS");
1804 /* Try to continue without PFS */
1807 if (wpa_s
->sme
.assoc_req_ie_len
+
1808 wpabuf_len(wpa_s
->dpp_pfs
->ie
) >
1809 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1810 wpa_printf(MSG_ERROR
,
1811 "DPP: Not enough buffer room for own Association Request frame elements");
1812 dpp_pfs_free(wpa_s
->dpp_pfs
);
1813 wpa_s
->dpp_pfs
= NULL
;
1816 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1817 wpabuf_head(wpa_s
->dpp_pfs
->ie
),
1818 wpabuf_len(wpa_s
->dpp_pfs
->ie
));
1819 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(wpa_s
->dpp_pfs
->ie
);
1822 #endif /* CONFIG_DPP2 */
1824 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->multi_ap_backhaul_sta
) {
1825 size_t multi_ap_ie_len
;
1827 multi_ap_ie_len
= add_multi_ap_ie(
1828 wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1829 sizeof(wpa_s
->sme
.assoc_req_ie
) -
1830 wpa_s
->sme
.assoc_req_ie_len
,
1831 MULTI_AP_BACKHAUL_STA
);
1832 if (multi_ap_ie_len
== 0) {
1833 wpa_printf(MSG_ERROR
,
1834 "Multi-AP: Failed to build Multi-AP IE");
1837 wpa_s
->sme
.assoc_req_ie_len
+= multi_ap_ie_len
;
1840 params
.bssid
= bssid
;
1841 params
.ssid
= wpa_s
->sme
.ssid
;
1842 params
.ssid_len
= wpa_s
->sme
.ssid_len
;
1843 params
.freq
.freq
= wpa_s
->sme
.freq
;
1844 params
.bg_scan_period
= wpa_s
->current_ssid
?
1845 wpa_s
->current_ssid
->bg_scan_period
: -1;
1846 params
.wpa_ie
= wpa_s
->sme
.assoc_req_ie_len
?
1847 wpa_s
->sme
.assoc_req_ie
: NULL
;
1848 params
.wpa_ie_len
= wpa_s
->sme
.assoc_req_ie_len
;
1849 wpa_hexdump(MSG_DEBUG
, "SME: Association Request IEs",
1850 params
.wpa_ie
, params
.wpa_ie_len
);
1851 params
.pairwise_suite
= wpa_s
->pairwise_cipher
;
1852 params
.group_suite
= wpa_s
->group_cipher
;
1853 params
.mgmt_group_suite
= wpa_s
->mgmt_group_cipher
;
1854 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
1855 params
.wpa_proto
= wpa_s
->wpa_proto
;
1856 #ifdef CONFIG_HT_OVERRIDES
1857 os_memset(&htcaps
, 0, sizeof(htcaps
));
1858 os_memset(&htcaps_mask
, 0, sizeof(htcaps_mask
));
1859 params
.htcaps
= (u8
*) &htcaps
;
1860 params
.htcaps_mask
= (u8
*) &htcaps_mask
;
1861 wpa_supplicant_apply_ht_overrides(wpa_s
, wpa_s
->current_ssid
, ¶ms
);
1862 #endif /* CONFIG_HT_OVERRIDES */
1863 #ifdef CONFIG_VHT_OVERRIDES
1864 os_memset(&vhtcaps
, 0, sizeof(vhtcaps
));
1865 os_memset(&vhtcaps_mask
, 0, sizeof(vhtcaps_mask
));
1866 params
.vhtcaps
= &vhtcaps
;
1867 params
.vhtcaps_mask
= &vhtcaps_mask
;
1868 wpa_supplicant_apply_vht_overrides(wpa_s
, wpa_s
->current_ssid
, ¶ms
);
1869 #endif /* CONFIG_VHT_OVERRIDES */
1870 #ifdef CONFIG_IEEE80211R
1871 if (auth_type
== WLAN_AUTH_FT
&& wpa_s
->sme
.ft_ies
&&
1872 get_ie(wpa_s
->sme
.ft_ies
, wpa_s
->sme
.ft_ies_len
,
1873 WLAN_EID_RIC_DATA
)) {
1874 /* There seems to be a pretty inconvenient bug in the Linux
1875 * kernel IE splitting functionality when RIC is used. For now,
1876 * skip correct behavior in IE construction here (i.e., drop the
1877 * additional non-FT-specific IEs) to avoid kernel issues. This
1878 * is fine since RIC is used only for testing purposes in the
1879 * current implementation. */
1880 wpa_printf(MSG_INFO
,
1881 "SME: Linux kernel workaround - do not try to include additional IEs with RIC");
1882 params
.wpa_ie
= wpa_s
->sme
.ft_ies
;
1883 params
.wpa_ie_len
= wpa_s
->sme
.ft_ies_len
;
1884 } else if (auth_type
== WLAN_AUTH_FT
&& wpa_s
->sme
.ft_ies
) {
1885 const u8
*rm_en
, *pos
, *end
;
1886 size_t rm_en_len
= 0;
1887 u8
*rm_en_dup
= NULL
, *wpos
;
1889 /* Remove RSNE, MDE, FTE to allow them to be overridden with
1890 * FT specific values */
1891 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1892 &wpa_s
->sme
.assoc_req_ie_len
,
1894 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1895 &wpa_s
->sme
.assoc_req_ie_len
,
1896 WLAN_EID_MOBILITY_DOMAIN
);
1897 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1898 &wpa_s
->sme
.assoc_req_ie_len
,
1899 WLAN_EID_FAST_BSS_TRANSITION
);
1900 rm_en
= get_ie(wpa_s
->sme
.assoc_req_ie
,
1901 wpa_s
->sme
.assoc_req_ie_len
,
1902 WLAN_EID_RRM_ENABLED_CAPABILITIES
);
1904 /* Need to remove RM Enabled Capabilities element as
1905 * well temporarily, so that it can be placed between
1907 rm_en_len
= 2 + rm_en
[1];
1908 rm_en_dup
= os_memdup(rm_en
, rm_en_len
);
1909 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1910 &wpa_s
->sme
.assoc_req_ie_len
,
1911 WLAN_EID_RRM_ENABLED_CAPABILITIES
);
1913 wpa_hexdump(MSG_DEBUG
,
1914 "SME: Association Request IEs after FT IE removal",
1915 wpa_s
->sme
.assoc_req_ie
,
1916 wpa_s
->sme
.assoc_req_ie_len
);
1917 if (wpa_s
->sme
.assoc_req_ie_len
+ wpa_s
->sme
.ft_ies_len
+
1918 rm_en_len
> sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1919 wpa_printf(MSG_ERROR
,
1920 "SME: Not enough buffer room for FT IEs in Association Request frame");
1925 os_memmove(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.ft_ies_len
+
1927 wpa_s
->sme
.assoc_req_ie
,
1928 wpa_s
->sme
.assoc_req_ie_len
);
1929 pos
= wpa_s
->sme
.ft_ies
;
1930 end
= pos
+ wpa_s
->sme
.ft_ies_len
;
1931 wpos
= wpa_s
->sme
.assoc_req_ie
;
1932 if (*pos
== WLAN_EID_RSN
) {
1933 os_memcpy(wpos
, pos
, 2 + pos
[1]);
1938 os_memcpy(wpos
, rm_en_dup
, rm_en_len
);
1942 os_memcpy(wpos
, pos
, end
- pos
);
1943 wpa_s
->sme
.assoc_req_ie_len
+= wpa_s
->sme
.ft_ies_len
+
1945 params
.wpa_ie
= wpa_s
->sme
.assoc_req_ie
;
1946 params
.wpa_ie_len
= wpa_s
->sme
.assoc_req_ie_len
;
1947 wpa_hexdump(MSG_DEBUG
,
1948 "SME: Association Request IEs after FT override",
1949 params
.wpa_ie
, params
.wpa_ie_len
);
1951 #endif /* CONFIG_IEEE80211R */
1953 params
.mgmt_frame_protection
= wpa_s
->sme
.mfp
;
1954 params
.rrm_used
= wpa_s
->rrm
.rrm_used
;
1955 if (wpa_s
->sme
.prev_bssid_set
)
1956 params
.prev_bssid
= wpa_s
->sme
.prev_bssid
;
1958 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
1959 " (SSID='%s' freq=%d MHz)", MAC2STR(params
.bssid
),
1960 params
.ssid
? wpa_ssid_txt(params
.ssid
, params
.ssid_len
) : "",
1963 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
1965 if (params
.wpa_ie
== NULL
||
1966 ieee802_11_parse_elems(params
.wpa_ie
, params
.wpa_ie_len
, &elems
, 0)
1968 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Could not parse own IEs?!");
1969 os_memset(&elems
, 0, sizeof(elems
));
1972 params
.wpa_proto
= WPA_PROTO_RSN
;
1973 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.rsn_ie
- 2,
1974 elems
.rsn_ie_len
+ 2);
1975 } else if (elems
.wpa_ie
) {
1976 params
.wpa_proto
= WPA_PROTO_WPA
;
1977 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.wpa_ie
- 2,
1978 elems
.wpa_ie_len
+ 2);
1979 } else if (elems
.osen
) {
1980 params
.wpa_proto
= WPA_PROTO_OSEN
;
1981 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.osen
- 2,
1982 elems
.osen_len
+ 2);
1984 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1986 wpa_sm_set_assoc_rsnxe(wpa_s
->wpa
, elems
.rsnxe
- 2,
1987 elems
.rsnxe_len
+ 2);
1989 wpa_sm_set_assoc_rsnxe(wpa_s
->wpa
, NULL
, 0);
1990 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
)
1993 if (wpa_s
->p2pdev
->set_sta_uapsd
)
1994 params
.uapsd
= wpa_s
->p2pdev
->sta_uapsd
;
1998 if (wpa_drv_associate(wpa_s
, ¶ms
) < 0) {
1999 wpa_msg(wpa_s
, MSG_INFO
, "SME: Association request to the "
2001 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
2002 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2003 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2007 eloop_register_timeout(SME_ASSOC_TIMEOUT
, 0, sme_assoc_timer
, wpa_s
,
2010 #ifdef CONFIG_TESTING_OPTIONS
2011 wpabuf_free(wpa_s
->last_assoc_req_wpa_ie
);
2012 wpa_s
->last_assoc_req_wpa_ie
= NULL
;
2014 wpa_s
->last_assoc_req_wpa_ie
=
2015 wpabuf_alloc_copy(params
.wpa_ie
, params
.wpa_ie_len
);
2016 #endif /* CONFIG_TESTING_OPTIONS */
2020 int sme_update_ft_ies(struct wpa_supplicant
*wpa_s
, const u8
*md
,
2021 const u8
*ies
, size_t ies_len
)
2023 if (md
== NULL
|| ies
== NULL
) {
2024 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Remove mobility domain");
2025 os_free(wpa_s
->sme
.ft_ies
);
2026 wpa_s
->sme
.ft_ies
= NULL
;
2027 wpa_s
->sme
.ft_ies_len
= 0;
2028 wpa_s
->sme
.ft_used
= 0;
2032 os_memcpy(wpa_s
->sme
.mobility_domain
, md
, MOBILITY_DOMAIN_ID_LEN
);
2033 wpa_hexdump(MSG_DEBUG
, "SME: FT IEs", ies
, ies_len
);
2034 os_free(wpa_s
->sme
.ft_ies
);
2035 wpa_s
->sme
.ft_ies
= os_memdup(ies
, ies_len
);
2036 if (wpa_s
->sme
.ft_ies
== NULL
)
2038 wpa_s
->sme
.ft_ies_len
= ies_len
;
2043 static void sme_deauth(struct wpa_supplicant
*wpa_s
)
2047 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
2049 if (wpa_drv_deauthenticate(wpa_s
, wpa_s
->pending_bssid
,
2050 WLAN_REASON_DEAUTH_LEAVING
) < 0) {
2051 wpa_msg(wpa_s
, MSG_INFO
, "SME: Deauth request to the driver "
2054 wpa_s
->sme
.prev_bssid_set
= 0;
2056 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
2057 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
2058 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
2059 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
2061 wpas_notify_bssid_changed(wpa_s
);
2065 void sme_event_assoc_reject(struct wpa_supplicant
*wpa_s
,
2066 union wpa_event_data
*data
)
2068 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association with " MACSTR
" failed: "
2069 "status code %d", MAC2STR(wpa_s
->pending_bssid
),
2070 data
->assoc_reject
.status_code
);
2072 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
2075 if (wpa_s
->sme
.sae_pmksa_caching
&& wpa_s
->current_ssid
&&
2076 wpa_key_mgmt_sae(wpa_s
->current_ssid
->key_mgmt
)) {
2077 wpa_dbg(wpa_s
, MSG_DEBUG
,
2078 "PMKSA caching attempt rejected - drop PMKSA cache entry and fall back to SAE authentication");
2079 wpa_sm_aborted_cached(wpa_s
->wpa
);
2080 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
2081 if (wpa_s
->current_bss
) {
2082 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2083 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2085 wpa_drv_deauthenticate(wpa_s
, wpa_s
->pending_bssid
,
2086 WLAN_REASON_DEAUTH_LEAVING
);
2087 wpas_connect_work_done(wpa_s
);
2088 wpa_supplicant_mark_disassoc(wpa_s
);
2089 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
2093 #endif /* CONFIG_SAE */
2096 * For now, unconditionally terminate the previous authentication. In
2097 * theory, this should not be needed, but mac80211 gets quite confused
2098 * if the authentication is left pending.. Some roaming cases might
2099 * benefit from using the previous authentication, so this could be
2100 * optimized in the future.
2106 void sme_event_auth_timed_out(struct wpa_supplicant
*wpa_s
,
2107 union wpa_event_data
*data
)
2109 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Authentication timed out");
2110 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
2111 wpa_supplicant_mark_disassoc(wpa_s
);
2115 void sme_event_assoc_timed_out(struct wpa_supplicant
*wpa_s
,
2116 union wpa_event_data
*data
)
2118 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association timed out");
2119 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
2120 wpa_supplicant_mark_disassoc(wpa_s
);
2124 void sme_event_disassoc(struct wpa_supplicant
*wpa_s
,
2125 struct disassoc_info
*info
)
2127 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Disassociation event received");
2128 if (wpa_s
->sme
.prev_bssid_set
) {
2130 * cfg80211/mac80211 can get into somewhat confused state if
2131 * the AP only disassociates us and leaves us in authenticated
2132 * state. For now, force the state to be cleared to avoid
2133 * confusing errors if we try to associate with the AP again.
2135 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Deauthenticate to clear "
2137 wpa_drv_deauthenticate(wpa_s
, wpa_s
->sme
.prev_bssid
,
2138 WLAN_REASON_DEAUTH_LEAVING
);
2143 static void sme_auth_timer(void *eloop_ctx
, void *timeout_ctx
)
2145 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2146 if (wpa_s
->wpa_state
== WPA_AUTHENTICATING
) {
2147 wpa_msg(wpa_s
, MSG_DEBUG
, "SME: Authentication timeout");
2153 static void sme_assoc_timer(void *eloop_ctx
, void *timeout_ctx
)
2155 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2156 if (wpa_s
->wpa_state
== WPA_ASSOCIATING
) {
2157 wpa_msg(wpa_s
, MSG_DEBUG
, "SME: Association timeout");
2163 void sme_state_changed(struct wpa_supplicant
*wpa_s
)
2165 /* Make sure timers are cleaned up appropriately. */
2166 if (wpa_s
->wpa_state
!= WPA_ASSOCIATING
)
2167 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
2168 if (wpa_s
->wpa_state
!= WPA_AUTHENTICATING
)
2169 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
2173 void sme_disassoc_while_authenticating(struct wpa_supplicant
*wpa_s
,
2174 const u8
*prev_pending_bssid
)
2177 * mac80211-workaround to force deauth on failed auth cmd,
2178 * requires us to remain in authenticating state to allow the
2179 * second authentication attempt to be continued properly.
2181 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Allow pending authentication "
2182 "to proceed after disconnection event");
2183 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
2184 os_memcpy(wpa_s
->pending_bssid
, prev_pending_bssid
, ETH_ALEN
);
2187 * Re-arm authentication timer in case auth fails for whatever reason.
2189 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
2190 eloop_register_timeout(SME_AUTH_TIMEOUT
, 0, sme_auth_timer
, wpa_s
,
2195 void sme_clear_on_disassoc(struct wpa_supplicant
*wpa_s
)
2197 wpa_s
->sme
.prev_bssid_set
= 0;
2199 wpabuf_free(wpa_s
->sme
.sae_token
);
2200 wpa_s
->sme
.sae_token
= NULL
;
2201 sae_clear_data(&wpa_s
->sme
.sae
);
2202 #endif /* CONFIG_SAE */
2203 #ifdef CONFIG_IEEE80211R
2204 if (wpa_s
->sme
.ft_ies
|| wpa_s
->sme
.ft_used
)
2205 sme_update_ft_ies(wpa_s
, NULL
, NULL
, 0);
2206 #endif /* CONFIG_IEEE80211R */
2207 sme_stop_sa_query(wpa_s
);
2211 void sme_deinit(struct wpa_supplicant
*wpa_s
)
2213 sme_clear_on_disassoc(wpa_s
);
2215 os_free(wpa_s
->sme
.sae_rejected_groups
);
2216 wpa_s
->sme
.sae_rejected_groups
= NULL
;
2217 #endif /* CONFIG_SAE */
2219 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
2220 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
2221 eloop_cancel_timeout(sme_obss_scan_timeout
, wpa_s
, NULL
);
2225 static void sme_send_2040_bss_coex(struct wpa_supplicant
*wpa_s
,
2226 const u8
*chan_list
, u8 num_channels
,
2229 struct ieee80211_2040_bss_coex_ie
*bc_ie
;
2230 struct ieee80211_2040_intol_chan_report
*ic_report
;
2233 wpa_printf(MSG_DEBUG
, "SME: Send 20/40 BSS Coexistence to " MACSTR
2234 " (num_channels=%u num_intol=%u)",
2235 MAC2STR(wpa_s
->bssid
), num_channels
, num_intol
);
2236 wpa_hexdump(MSG_DEBUG
, "SME: 20/40 BSS Intolerant Channels",
2237 chan_list
, num_channels
);
2239 buf
= wpabuf_alloc(2 + /* action.category + action_code */
2240 sizeof(struct ieee80211_2040_bss_coex_ie
) +
2241 sizeof(struct ieee80211_2040_intol_chan_report
) +
2246 wpabuf_put_u8(buf
, WLAN_ACTION_PUBLIC
);
2247 wpabuf_put_u8(buf
, WLAN_PA_20_40_BSS_COEX
);
2249 bc_ie
= wpabuf_put(buf
, sizeof(*bc_ie
));
2250 bc_ie
->element_id
= WLAN_EID_20_40_BSS_COEXISTENCE
;
2253 bc_ie
->coex_param
|= WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ
;
2255 if (num_channels
> 0) {
2256 ic_report
= wpabuf_put(buf
, sizeof(*ic_report
));
2257 ic_report
->element_id
= WLAN_EID_20_40_BSS_INTOLERANT
;
2258 ic_report
->length
= num_channels
+ 1;
2259 ic_report
->op_class
= 0;
2260 os_memcpy(wpabuf_put(buf
, num_channels
), chan_list
,
2264 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
2265 wpa_s
->own_addr
, wpa_s
->bssid
,
2266 wpabuf_head(buf
), wpabuf_len(buf
), 0) < 0) {
2267 wpa_msg(wpa_s
, MSG_INFO
,
2268 "SME: Failed to send 20/40 BSS Coexistence frame");
2275 int sme_proc_obss_scan(struct wpa_supplicant
*wpa_s
,
2276 struct wpa_scan_results
*scan_res
)
2279 u8 chan_list
[P2P_MAX_CHANNELS
], channel
;
2280 u8 num_channels
= 0, num_intol
= 0, i
;
2282 int pri_freq
, sec_freq
;
2284 if (!wpa_s
->sme
.sched_obss_scan
)
2287 wpa_s
->sme
.sched_obss_scan
= 0;
2288 if (!wpa_s
->current_bss
|| wpa_s
->wpa_state
!= WPA_COMPLETED
)
2292 * Check whether AP uses regulatory triplet or channel triplet in
2293 * country info. Right now the operating class of the BSS channel
2294 * width trigger event is "unknown" (IEEE Std 802.11-2012 10.15.12),
2295 * based on the assumption that operating class triplet is not used in
2296 * beacon frame. If the First Channel Number/Operating Extension
2297 * Identifier octet has a positive integer value of 201 or greater,
2298 * then its operating class triplet.
2300 * TODO: If Supported Operating Classes element is present in beacon
2301 * frame, have to lookup operating class in Annex E and fill them in
2304 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_COUNTRY
);
2305 if (ie
&& (ie
[1] >= 6) && (ie
[5] >= 201))
2308 os_memset(chan_list
, 0, sizeof(chan_list
));
2310 pri_freq
= wpa_s
->assoc_freq
;
2312 switch (wpa_s
->sme
.ht_sec_chan
) {
2313 case HT_SEC_CHAN_ABOVE
:
2314 sec_freq
= pri_freq
+ 20;
2316 case HT_SEC_CHAN_BELOW
:
2317 sec_freq
= pri_freq
- 20;
2319 case HT_SEC_CHAN_UNKNOWN
:
2321 wpa_msg(wpa_s
, MSG_WARNING
,
2322 "Undefined secondary channel: drop OBSS scan results");
2326 for (j
= 0; j
< scan_res
->num
; j
++) {
2327 struct wpa_scan_res
*bss
= scan_res
->res
[j
];
2328 enum hostapd_hw_mode mode
;
2331 /* Skip other band bss */
2332 mode
= ieee80211_freq_to_chan(bss
->freq
, &channel
);
2333 if (mode
!= HOSTAPD_MODE_IEEE80211G
&&
2334 mode
!= HOSTAPD_MODE_IEEE80211B
)
2337 res
= check_bss_coex_40mhz(bss
, pri_freq
, sec_freq
);
2342 /* Check whether the channel is already considered */
2343 for (i
= 0; i
< num_channels
; i
++) {
2344 if (channel
== chan_list
[i
])
2347 if (i
!= num_channels
)
2350 chan_list
[num_channels
++] = channel
;
2354 sme_send_2040_bss_coex(wpa_s
, chan_list
, num_channels
, num_intol
);
2359 static void wpa_obss_scan_freqs_list(struct wpa_supplicant
*wpa_s
,
2360 struct wpa_driver_scan_params
*params
)
2362 /* Include only affected channels */
2363 struct hostapd_hw_modes
*mode
;
2367 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
,
2368 HOSTAPD_MODE_IEEE80211G
, 0);
2370 /* No channels supported in this band - use empty list */
2371 params
->freqs
= os_zalloc(sizeof(int));
2375 if (wpa_s
->sme
.ht_sec_chan
== HT_SEC_CHAN_UNKNOWN
&&
2376 wpa_s
->current_bss
) {
2379 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_HT_OPERATION
);
2380 if (ie
&& ie
[1] >= 2) {
2383 o
= ie
[3] & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK
;
2384 if (o
== HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE
)
2385 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_ABOVE
;
2386 else if (o
== HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW
)
2387 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_BELOW
;
2391 start
= wpa_s
->assoc_freq
- 10;
2392 end
= wpa_s
->assoc_freq
+ 10;
2393 switch (wpa_s
->sme
.ht_sec_chan
) {
2394 case HT_SEC_CHAN_UNKNOWN
:
2395 /* HT40+ possible on channels 1..9 */
2396 if (wpa_s
->assoc_freq
<= 2452)
2398 /* HT40- possible on channels 5-13 */
2399 if (wpa_s
->assoc_freq
>= 2432)
2402 case HT_SEC_CHAN_ABOVE
:
2405 case HT_SEC_CHAN_BELOW
:
2409 wpa_printf(MSG_DEBUG
,
2410 "OBSS: assoc_freq %d possible affected range %d-%d",
2411 wpa_s
->assoc_freq
, start
, end
);
2413 params
->freqs
= os_calloc(mode
->num_channels
+ 1, sizeof(int));
2414 if (params
->freqs
== NULL
)
2416 for (count
= 0, i
= 0; i
< mode
->num_channels
; i
++) {
2419 if (mode
->channels
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
2421 freq
= mode
->channels
[i
].freq
;
2422 if (freq
- 10 >= end
|| freq
+ 10 <= start
)
2423 continue; /* not affected */
2424 params
->freqs
[count
++] = freq
;
2429 static void sme_obss_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
2431 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2432 struct wpa_driver_scan_params params
;
2434 if (!wpa_s
->current_bss
) {
2435 wpa_printf(MSG_DEBUG
, "SME OBSS: Ignore scan request");
2439 os_memset(¶ms
, 0, sizeof(params
));
2440 wpa_obss_scan_freqs_list(wpa_s
, ¶ms
);
2441 params
.low_priority
= 1;
2442 wpa_printf(MSG_DEBUG
, "SME OBSS: Request an OBSS scan");
2444 if (wpa_supplicant_trigger_scan(wpa_s
, ¶ms
))
2445 wpa_printf(MSG_DEBUG
, "SME OBSS: Failed to trigger scan");
2447 wpa_s
->sme
.sched_obss_scan
= 1;
2448 os_free(params
.freqs
);
2450 eloop_register_timeout(wpa_s
->sme
.obss_scan_int
, 0,
2451 sme_obss_scan_timeout
, wpa_s
, NULL
);
2455 void sme_sched_obss_scan(struct wpa_supplicant
*wpa_s
, int enable
)
2458 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2459 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2460 struct hostapd_hw_modes
*hw_mode
= NULL
;
2463 eloop_cancel_timeout(sme_obss_scan_timeout
, wpa_s
, NULL
);
2464 wpa_s
->sme
.sched_obss_scan
= 0;
2465 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_UNKNOWN
;
2470 * Schedule OBSS scan if driver is using station SME in wpa_supplicant
2471 * or it expects OBSS scan to be performed by wpa_supplicant.
2473 if (!((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) ||
2474 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OBSS_SCAN
)) ||
2475 ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_INFRA
)
2478 if (!wpa_s
->hw
.modes
)
2481 /* only HT caps in 11g mode are relevant */
2482 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
2483 hw_mode
= &wpa_s
->hw
.modes
[i
];
2484 if (hw_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
2488 /* Driver does not support HT40 for 11g or doesn't have 11g. */
2489 if (i
== wpa_s
->hw
.num_modes
|| !hw_mode
||
2490 !(hw_mode
->ht_capab
& HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
2493 if (bss
== NULL
|| bss
->freq
< 2400 || bss
->freq
> 2500)
2494 return; /* Not associated on 2.4 GHz band */
2496 /* Check whether AP supports HT40 */
2497 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_HT_CAP
);
2498 if (!ie
|| ie
[1] < 2 ||
2499 !(WPA_GET_LE16(ie
+ 2) & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
2500 return; /* AP does not support HT40 */
2502 ie
= wpa_bss_get_ie(wpa_s
->current_bss
,
2503 WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS
);
2504 if (!ie
|| ie
[1] < 14)
2505 return; /* AP does not request OBSS scans */
2507 wpa_s
->sme
.obss_scan_int
= WPA_GET_LE16(ie
+ 6);
2508 if (wpa_s
->sme
.obss_scan_int
< 10) {
2509 wpa_printf(MSG_DEBUG
, "SME: Invalid OBSS Scan Interval %u "
2510 "replaced with the minimum 10 sec",
2511 wpa_s
->sme
.obss_scan_int
);
2512 wpa_s
->sme
.obss_scan_int
= 10;
2514 wpa_printf(MSG_DEBUG
, "SME: OBSS Scan Interval %u sec",
2515 wpa_s
->sme
.obss_scan_int
);
2516 eloop_register_timeout(wpa_s
->sme
.obss_scan_int
, 0,
2517 sme_obss_scan_timeout
, wpa_s
, NULL
);
2521 static const unsigned int sa_query_max_timeout
= 1000;
2522 static const unsigned int sa_query_retry_timeout
= 201;
2523 static const unsigned int sa_query_ch_switch_max_delay
= 5000; /* in usec */
2525 static int sme_check_sa_query_timeout(struct wpa_supplicant
*wpa_s
)
2528 struct os_reltime now
, passed
;
2529 os_get_reltime(&now
);
2530 os_reltime_sub(&now
, &wpa_s
->sme
.sa_query_start
, &passed
);
2531 tu
= (passed
.sec
* 1000000 + passed
.usec
) / 1024;
2532 if (sa_query_max_timeout
< tu
) {
2533 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SA Query timed out");
2534 sme_stop_sa_query(wpa_s
);
2535 wpa_supplicant_deauthenticate(
2536 wpa_s
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
2544 static void sme_send_sa_query_req(struct wpa_supplicant
*wpa_s
,
2547 u8 req
[2 + WLAN_SA_QUERY_TR_ID_LEN
+ OCV_OCI_EXTENDED_LEN
];
2548 u8 req_len
= 2 + WLAN_SA_QUERY_TR_ID_LEN
;
2550 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Sending SA Query Request to "
2551 MACSTR
, MAC2STR(wpa_s
->bssid
));
2552 wpa_hexdump(MSG_DEBUG
, "SME: SA Query Transaction ID",
2553 trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
2554 req
[0] = WLAN_ACTION_SA_QUERY
;
2555 req
[1] = WLAN_SA_QUERY_REQUEST
;
2556 os_memcpy(req
+ 2, trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
2559 if (wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
2560 struct wpa_channel_info ci
;
2562 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
2563 wpa_printf(MSG_WARNING
,
2564 "Failed to get channel info for OCI element in SA Query Request frame");
2568 if (ocv_insert_extended_oci(&ci
, req
+ req_len
) < 0)
2571 req_len
+= OCV_OCI_EXTENDED_LEN
;
2573 #endif /* CONFIG_OCV */
2575 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
2576 wpa_s
->own_addr
, wpa_s
->bssid
,
2577 req
, req_len
, 0) < 0)
2578 wpa_msg(wpa_s
, MSG_INFO
, "SME: Failed to send SA Query "
2583 static void sme_sa_query_timer(void *eloop_ctx
, void *timeout_ctx
)
2585 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2586 unsigned int timeout
, sec
, usec
;
2587 u8
*trans_id
, *nbuf
;
2589 if (wpa_s
->sme
.sa_query_count
> 0 &&
2590 sme_check_sa_query_timeout(wpa_s
))
2593 nbuf
= os_realloc_array(wpa_s
->sme
.sa_query_trans_id
,
2594 wpa_s
->sme
.sa_query_count
+ 1,
2595 WLAN_SA_QUERY_TR_ID_LEN
);
2597 sme_stop_sa_query(wpa_s
);
2600 if (wpa_s
->sme
.sa_query_count
== 0) {
2601 /* Starting a new SA Query procedure */
2602 os_get_reltime(&wpa_s
->sme
.sa_query_start
);
2604 trans_id
= nbuf
+ wpa_s
->sme
.sa_query_count
* WLAN_SA_QUERY_TR_ID_LEN
;
2605 wpa_s
->sme
.sa_query_trans_id
= nbuf
;
2606 wpa_s
->sme
.sa_query_count
++;
2608 if (os_get_random(trans_id
, WLAN_SA_QUERY_TR_ID_LEN
) < 0) {
2609 wpa_printf(MSG_DEBUG
, "Could not generate SA Query ID");
2610 sme_stop_sa_query(wpa_s
);
2614 timeout
= sa_query_retry_timeout
;
2615 sec
= ((timeout
/ 1000) * 1024) / 1000;
2616 usec
= (timeout
% 1000) * 1024;
2617 eloop_register_timeout(sec
, usec
, sme_sa_query_timer
, wpa_s
, NULL
);
2619 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association SA Query attempt %d",
2620 wpa_s
->sme
.sa_query_count
);
2622 sme_send_sa_query_req(wpa_s
, trans_id
);
2626 static void sme_start_sa_query(struct wpa_supplicant
*wpa_s
)
2628 sme_sa_query_timer(wpa_s
, NULL
);
2632 static void sme_stop_sa_query(struct wpa_supplicant
*wpa_s
)
2634 if (wpa_s
->sme
.sa_query_trans_id
)
2635 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Stop SA Query");
2636 eloop_cancel_timeout(sme_sa_query_timer
, wpa_s
, NULL
);
2637 os_free(wpa_s
->sme
.sa_query_trans_id
);
2638 wpa_s
->sme
.sa_query_trans_id
= NULL
;
2639 wpa_s
->sme
.sa_query_count
= 0;
2643 void sme_event_unprot_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*sa
,
2644 const u8
*da
, u16 reason_code
)
2646 struct wpa_ssid
*ssid
;
2647 struct os_reltime now
;
2649 if (wpa_s
->wpa_state
!= WPA_COMPLETED
)
2651 ssid
= wpa_s
->current_ssid
;
2652 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == NO_MGMT_FRAME_PROTECTION
)
2654 if (os_memcmp(sa
, wpa_s
->bssid
, ETH_ALEN
) != 0)
2656 if (reason_code
!= WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
&&
2657 reason_code
!= WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
)
2659 if (wpa_s
->sme
.sa_query_count
> 0)
2662 os_get_reltime(&now
);
2663 if (wpa_s
->sme
.last_unprot_disconnect
.sec
&&
2664 !os_reltime_expired(&now
, &wpa_s
->sme
.last_unprot_disconnect
, 10))
2665 return; /* limit SA Query procedure frequency */
2666 wpa_s
->sme
.last_unprot_disconnect
= now
;
2668 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Unprotected disconnect dropped - "
2669 "possible AP/STA state mismatch - trigger SA Query");
2670 sme_start_sa_query(wpa_s
);
2674 void sme_event_ch_switch(struct wpa_supplicant
*wpa_s
)
2679 if (wpa_s
->wpa_state
!= WPA_COMPLETED
||
2680 !wpa_sm_ocv_enabled(wpa_s
->wpa
))
2683 wpa_dbg(wpa_s
, MSG_DEBUG
,
2684 "SME: Channel switch completed - trigger new SA Query to verify new operating channel");
2685 sme_stop_sa_query(wpa_s
);
2687 if (os_get_random((u8
*) &_rand
, sizeof(_rand
)) < 0)
2688 _rand
= os_random();
2689 usec
= _rand
% (sa_query_ch_switch_max_delay
+ 1);
2690 eloop_register_timeout(0, usec
, sme_sa_query_timer
, wpa_s
, NULL
);
2694 static void sme_process_sa_query_request(struct wpa_supplicant
*wpa_s
,
2695 const u8
*sa
, const u8
*data
,
2698 u8 resp
[2 + WLAN_SA_QUERY_TR_ID_LEN
+ OCV_OCI_EXTENDED_LEN
];
2699 u8 resp_len
= 2 + WLAN_SA_QUERY_TR_ID_LEN
;
2701 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Sending SA Query Response to "
2702 MACSTR
, MAC2STR(wpa_s
->bssid
));
2704 resp
[0] = WLAN_ACTION_SA_QUERY
;
2705 resp
[1] = WLAN_SA_QUERY_RESPONSE
;
2706 os_memcpy(resp
+ 2, data
+ 1, WLAN_SA_QUERY_TR_ID_LEN
);
2709 if (wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
2710 struct wpa_channel_info ci
;
2712 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
2713 wpa_printf(MSG_WARNING
,
2714 "Failed to get channel info for OCI element in SA Query Response frame");
2718 if (ocv_insert_extended_oci(&ci
, resp
+ resp_len
) < 0)
2721 resp_len
+= OCV_OCI_EXTENDED_LEN
;
2723 #endif /* CONFIG_OCV */
2725 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
2726 wpa_s
->own_addr
, wpa_s
->bssid
,
2727 resp
, resp_len
, 0) < 0)
2728 wpa_msg(wpa_s
, MSG_INFO
,
2729 "SME: Failed to send SA Query Response");
2733 static void sme_process_sa_query_response(struct wpa_supplicant
*wpa_s
,
2734 const u8
*sa
, const u8
*data
,
2739 if (!wpa_s
->sme
.sa_query_trans_id
)
2742 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Received SA Query response from "
2743 MACSTR
" (trans_id %02x%02x)", MAC2STR(sa
), data
[1], data
[2]);
2745 if (os_memcmp(sa
, wpa_s
->bssid
, ETH_ALEN
) != 0)
2748 for (i
= 0; i
< wpa_s
->sme
.sa_query_count
; i
++) {
2749 if (os_memcmp(wpa_s
->sme
.sa_query_trans_id
+
2750 i
* WLAN_SA_QUERY_TR_ID_LEN
,
2751 data
+ 1, WLAN_SA_QUERY_TR_ID_LEN
) == 0)
2755 if (i
>= wpa_s
->sme
.sa_query_count
) {
2756 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: No matching SA Query "
2757 "transaction identifier found");
2761 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Reply to pending SA Query received "
2762 "from " MACSTR
, MAC2STR(sa
));
2763 sme_stop_sa_query(wpa_s
);
2767 void sme_sa_query_rx(struct wpa_supplicant
*wpa_s
, const u8
*sa
,
2768 const u8
*data
, size_t len
)
2770 if (len
< 1 + WLAN_SA_QUERY_TR_ID_LEN
)
2773 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Received SA Query frame from "
2774 MACSTR
" (trans_id %02x%02x)", MAC2STR(sa
), data
[1], data
[2]);
2777 if (wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
2778 struct ieee802_11_elems elems
;
2779 struct wpa_channel_info ci
;
2781 if (ieee802_11_parse_elems(data
+ 1 + WLAN_SA_QUERY_TR_ID_LEN
,
2782 len
- 1 - WLAN_SA_QUERY_TR_ID_LEN
,
2783 &elems
, 1) == ParseFailed
) {
2784 wpa_printf(MSG_DEBUG
,
2785 "SA Query: Failed to parse elements");
2789 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
2790 wpa_printf(MSG_WARNING
,
2791 "Failed to get channel info to validate received OCI in SA Query Action frame");
2795 if (ocv_verify_tx_params(elems
.oci
, elems
.oci_len
, &ci
,
2796 channel_width_to_int(ci
.chanwidth
),
2797 ci
.seg1_idx
) != 0) {
2798 wpa_printf(MSG_WARNING
, "%s", ocv_errorstr
);
2802 #endif /* CONFIG_OCV */
2804 if (data
[0] == WLAN_SA_QUERY_REQUEST
)
2805 sme_process_sa_query_request(wpa_s
, sa
, data
, len
);
2806 else if (data
[0] == WLAN_SA_QUERY_RESPONSE
)
2807 sme_process_sa_query_response(wpa_s
, sa
, data
, len
);