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 "common/dpp.h"
20 #include "rsn_supp/wpa.h"
21 #include "rsn_supp/pmksa_cache.h"
23 #include "wpa_supplicant_i.h"
25 #include "wpas_glue.h"
26 #include "wps_supplicant.h"
27 #include "p2p_supplicant.h"
32 #include "hs20_supplicant.h"
34 #define SME_AUTH_TIMEOUT 5
35 #define SME_ASSOC_TIMEOUT 5
37 static void sme_auth_timer(void *eloop_ctx
, void *timeout_ctx
);
38 static void sme_assoc_timer(void *eloop_ctx
, void *timeout_ctx
);
39 static void sme_obss_scan_timeout(void *eloop_ctx
, void *timeout_ctx
);
40 #ifdef CONFIG_IEEE80211W
41 static void sme_stop_sa_query(struct wpa_supplicant
*wpa_s
);
42 #endif /* CONFIG_IEEE80211W */
47 static int index_within_array(const int *array
, int idx
)
50 for (i
= 0; i
< idx
; i
++) {
58 static int sme_set_sae_group(struct wpa_supplicant
*wpa_s
)
60 int *groups
= wpa_s
->conf
->sae_groups
;
61 int default_groups
[] = { 19, 20, 21, 0 };
63 if (!groups
|| groups
[0] <= 0)
64 groups
= default_groups
;
66 /* Configuration may have changed, so validate current index */
67 if (!index_within_array(groups
, wpa_s
->sme
.sae_group_index
))
71 int group
= groups
[wpa_s
->sme
.sae_group_index
];
74 if (sae_set_group(&wpa_s
->sme
.sae
, group
) == 0) {
75 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Selected SAE group %d",
76 wpa_s
->sme
.sae
.group
);
79 wpa_s
->sme
.sae_group_index
++;
86 static struct wpabuf
* sme_auth_build_sae_commit(struct wpa_supplicant
*wpa_s
,
87 struct wpa_ssid
*ssid
,
88 const u8
*bssid
, int external
,
95 #ifdef CONFIG_TESTING_OPTIONS
96 if (wpa_s
->sae_commit_override
) {
97 wpa_printf(MSG_DEBUG
, "SAE: TESTING - commit override");
98 buf
= wpabuf_alloc(4 + wpabuf_len(wpa_s
->sae_commit_override
));
101 wpabuf_put_le16(buf
, 1); /* Transaction seq# */
102 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
103 wpabuf_put_buf(buf
, wpa_s
->sae_commit_override
);
106 #endif /* CONFIG_TESTING_OPTIONS */
108 password
= ssid
->sae_password
;
110 password
= ssid
->passphrase
;
112 wpa_printf(MSG_DEBUG
, "SAE: No password available");
116 if (reuse
&& wpa_s
->sme
.sae
.tmp
&&
117 os_memcmp(bssid
, wpa_s
->sme
.sae
.tmp
->bssid
, ETH_ALEN
) == 0) {
118 wpa_printf(MSG_DEBUG
,
119 "SAE: Reuse previously generated PWE on a retry with the same AP");
122 if (sme_set_sae_group(wpa_s
) < 0) {
123 wpa_printf(MSG_DEBUG
, "SAE: Failed to select group");
127 if (sae_prepare_commit(wpa_s
->own_addr
, bssid
,
128 (u8
*) password
, os_strlen(password
),
129 ssid
->sae_password_id
,
130 &wpa_s
->sme
.sae
) < 0) {
131 wpa_printf(MSG_DEBUG
, "SAE: Could not pick PWE");
134 if (wpa_s
->sme
.sae
.tmp
)
135 os_memcpy(wpa_s
->sme
.sae
.tmp
->bssid
, bssid
, ETH_ALEN
);
138 len
= wpa_s
->sme
.sae_token
? wpabuf_len(wpa_s
->sme
.sae_token
) : 0;
139 if (ssid
->sae_password_id
)
140 len
+= 4 + os_strlen(ssid
->sae_password_id
);
141 buf
= wpabuf_alloc(4 + SAE_COMMIT_MAX_LEN
+ len
);
145 wpabuf_put_le16(buf
, 1); /* Transaction seq# */
146 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
148 sae_write_commit(&wpa_s
->sme
.sae
, buf
, wpa_s
->sme
.sae_token
,
149 ssid
->sae_password_id
);
155 static struct wpabuf
* sme_auth_build_sae_confirm(struct wpa_supplicant
*wpa_s
,
160 buf
= wpabuf_alloc(4 + SAE_CONFIRM_MAX_LEN
);
165 wpabuf_put_le16(buf
, 2); /* Transaction seq# */
166 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
168 sae_write_confirm(&wpa_s
->sme
.sae
, buf
);
173 #endif /* CONFIG_SAE */
177 * sme_auth_handle_rrm - Handle RRM aspects of current authentication attempt
178 * @wpa_s: Pointer to wpa_supplicant data
179 * @bss: Pointer to the bss which is the target of authentication attempt
181 static void sme_auth_handle_rrm(struct wpa_supplicant
*wpa_s
,
184 const u8 rrm_ie_len
= 5;
188 wpa_s
->rrm
.rrm_used
= 0;
190 wpa_printf(MSG_DEBUG
,
191 "RRM: Determining whether RRM can be used - device support: 0x%x",
192 wpa_s
->drv_rrm_flags
);
194 rrm_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RRM_ENABLED_CAPABILITIES
);
195 if (!rrm_ie
|| !(bss
->caps
& IEEE80211_CAP_RRM
)) {
196 wpa_printf(MSG_DEBUG
, "RRM: No RRM in network");
200 if (!((wpa_s
->drv_rrm_flags
&
201 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES
) &&
202 (wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_QUIET
)) &&
203 !(wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_SUPPORT_RRM
)) {
204 wpa_printf(MSG_DEBUG
,
205 "RRM: Insufficient RRM support in driver - do not use RRM");
209 if (sizeof(wpa_s
->sme
.assoc_req_ie
) <
210 wpa_s
->sme
.assoc_req_ie_len
+ rrm_ie_len
+ 2) {
212 "RRM: Unable to use RRM, no room for RRM IE");
216 wpa_printf(MSG_DEBUG
, "RRM: Adding RRM IE to Association Request");
217 pos
= wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
;
218 os_memset(pos
, 0, 2 + rrm_ie_len
);
219 *pos
++ = WLAN_EID_RRM_ENABLED_CAPABILITIES
;
222 /* Set supported capabilites flags */
223 if (wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_TX_POWER_INSERTION
)
224 *pos
|= WLAN_RRM_CAPS_LINK_MEASUREMENT
;
226 *pos
|= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE
|
227 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE
|
228 WLAN_RRM_CAPS_BEACON_REPORT_TABLE
;
231 pos
[1] |= WLAN_RRM_CAPS_LCI_MEASUREMENT
;
233 wpa_s
->sme
.assoc_req_ie_len
+= rrm_ie_len
+ 2;
234 wpa_s
->rrm
.rrm_used
= 1;
238 static void sme_send_authentication(struct wpa_supplicant
*wpa_s
,
239 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
242 struct wpa_driver_auth_params params
;
243 struct wpa_ssid
*old_ssid
;
244 #ifdef CONFIG_IEEE80211R
246 #endif /* CONFIG_IEEE80211R */
247 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_FILS)
249 #endif /* CONFIG_IEEE80211R || CONFIG_FILS */
250 int i
, bssid_changed
;
251 struct wpabuf
*resp
= NULL
;
259 #endif /* CONFIG_MBO */
262 wpa_msg(wpa_s
, MSG_ERROR
, "SME: No scan result available for "
264 wpas_connect_work_done(wpa_s
);
268 skip_auth
= wpa_s
->conf
->reassoc_same_bss_optim
&&
269 wpa_s
->reassoc_same_bss
;
270 wpa_s
->current_bss
= bss
;
272 os_memset(¶ms
, 0, sizeof(params
));
273 wpa_s
->reassociate
= 0;
275 params
.freq
= bss
->freq
;
276 params
.bssid
= bss
->bssid
;
277 params
.ssid
= bss
->ssid
;
278 params
.ssid_len
= bss
->ssid_len
;
279 params
.p2p
= ssid
->p2p_group
;
281 if (wpa_s
->sme
.ssid_len
!= params
.ssid_len
||
282 os_memcmp(wpa_s
->sme
.ssid
, params
.ssid
, params
.ssid_len
) != 0)
283 wpa_s
->sme
.prev_bssid_set
= 0;
285 wpa_s
->sme
.freq
= params
.freq
;
286 os_memcpy(wpa_s
->sme
.ssid
, params
.ssid
, params
.ssid_len
);
287 wpa_s
->sme
.ssid_len
= params
.ssid_len
;
289 params
.auth_alg
= WPA_AUTH_ALG_OPEN
;
290 #ifdef IEEE8021X_EAPOL
291 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
293 if (ssid
->non_leap
== 0)
294 params
.auth_alg
= WPA_AUTH_ALG_LEAP
;
296 params
.auth_alg
|= WPA_AUTH_ALG_LEAP
;
299 #endif /* IEEE8021X_EAPOL */
300 wpa_dbg(wpa_s
, MSG_DEBUG
, "Automatic auth_alg selection: 0x%x",
302 if (ssid
->auth_alg
) {
303 params
.auth_alg
= ssid
->auth_alg
;
304 wpa_dbg(wpa_s
, MSG_DEBUG
, "Overriding auth_alg selection: "
305 "0x%x", params
.auth_alg
);
308 wpa_s
->sme
.sae_pmksa_caching
= 0;
309 if (wpa_key_mgmt_sae(ssid
->key_mgmt
)) {
311 struct wpa_ie_data ied
;
313 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
315 wpa_dbg(wpa_s
, MSG_DEBUG
,
316 "SAE enabled, but target BSS does not advertise RSN");
318 } else if (wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ied
) == 0 &&
319 (ssid
->key_mgmt
& WPA_KEY_MGMT_DPP
) &&
320 (ied
.key_mgmt
& WPA_KEY_MGMT_DPP
)) {
321 wpa_dbg(wpa_s
, MSG_DEBUG
, "Prefer DPP over SAE when both are enabled");
322 #endif /* CONFIG_DPP */
323 } else if (wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ied
) == 0 &&
324 wpa_key_mgmt_sae(ied
.key_mgmt
)) {
325 wpa_dbg(wpa_s
, MSG_DEBUG
, "Using SAE auth_alg");
326 params
.auth_alg
= WPA_AUTH_ALG_SAE
;
328 wpa_dbg(wpa_s
, MSG_DEBUG
,
329 "SAE enabled, but target BSS does not advertise SAE AKM for RSN");
332 #endif /* CONFIG_SAE */
334 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
335 if (ssid
->wep_key_len
[i
])
336 params
.wep_key
[i
] = ssid
->wep_key
[i
];
337 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
339 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
341 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
342 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
343 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
345 wpas_notify_bssid_changed(wpa_s
);
347 if ((wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
348 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
349 wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
350 int try_opportunistic
;
351 const u8
*cache_id
= NULL
;
353 try_opportunistic
= (ssid
->proactive_key_caching
< 0 ?
355 ssid
->proactive_key_caching
) &&
356 (ssid
->proto
& WPA_PROTO_RSN
);
358 if (wpa_key_mgmt_fils(ssid
->key_mgmt
))
359 cache_id
= wpa_bss_get_fils_cache_id(bss
);
360 #endif /* CONFIG_FILS */
361 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
363 try_opportunistic
, cache_id
,
365 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
366 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
367 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
368 wpa_s
->sme
.assoc_req_ie
,
369 &wpa_s
->sme
.assoc_req_ie_len
)) {
370 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
371 "key management and encryption suites");
372 wpas_connect_work_done(wpa_s
);
376 } else if (wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
) &&
377 (ssid
->key_mgmt
& WPA_KEY_MGMT_OSEN
)) {
378 /* No PMKSA caching, but otherwise similar to RSN/WPA */
379 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
380 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
381 wpa_s
->sme
.assoc_req_ie
,
382 &wpa_s
->sme
.assoc_req_ie_len
)) {
383 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
384 "key management and encryption suites");
385 wpas_connect_work_done(wpa_s
);
388 #endif /* CONFIG_HS20 */
389 } else if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
390 wpa_key_mgmt_wpa_ieee8021x(ssid
->key_mgmt
)) {
392 * Both WPA and non-WPA IEEE 802.1X enabled in configuration -
393 * use non-WPA since the scan results did not indicate that the
394 * AP is using WPA or WPA2.
396 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
397 wpa_s
->sme
.assoc_req_ie_len
= 0;
398 } else if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
399 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
400 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
401 wpa_s
->sme
.assoc_req_ie
,
402 &wpa_s
->sme
.assoc_req_ie_len
)) {
403 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
404 "key management and encryption suites (no "
406 wpas_connect_work_done(wpa_s
);
410 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
411 struct wpabuf
*wps_ie
;
412 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
413 if (wps_ie
&& wpabuf_len(wps_ie
) <=
414 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
415 wpa_s
->sme
.assoc_req_ie_len
= wpabuf_len(wps_ie
);
416 os_memcpy(wpa_s
->sme
.assoc_req_ie
, wpabuf_head(wps_ie
),
417 wpa_s
->sme
.assoc_req_ie_len
);
419 wpa_s
->sme
.assoc_req_ie_len
= 0;
421 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
422 #endif /* CONFIG_WPS */
424 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
425 wpa_s
->sme
.assoc_req_ie_len
= 0;
428 /* In case the WPA vendor IE is used, it should be placed after all the
429 * non-vendor IEs, as the lower layer expects the IEs to be ordered as
430 * defined in the standard. Store the WPA IE so it can later be
431 * inserted at the correct location.
435 if (wpa_s
->wpa_proto
== WPA_PROTO_WPA
) {
436 wpa_ie
= os_memdup(wpa_s
->sme
.assoc_req_ie
,
437 wpa_s
->sme
.assoc_req_ie_len
);
439 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Storing WPA IE");
441 wpa_ie_len
= wpa_s
->sme
.assoc_req_ie_len
;
442 wpa_s
->sme
.assoc_req_ie_len
= 0;
444 wpa_msg(wpa_s
, MSG_WARNING
, "WPA: Failed copy WPA IE");
445 wpas_connect_work_done(wpa_s
);
450 #ifdef CONFIG_IEEE80211R
451 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
452 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
454 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
455 if (md
&& (!wpa_key_mgmt_ft(ssid
->key_mgmt
) ||
456 !wpa_key_mgmt_ft(wpa_s
->key_mgmt
)))
459 /* Prepare for the next transition */
460 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
464 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: FT mobility domain %02x%02x",
467 if (wpa_s
->sme
.assoc_req_ie_len
+ 5 <
468 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
469 struct rsn_mdie
*mdie
;
470 u8
*pos
= wpa_s
->sme
.assoc_req_ie
+
471 wpa_s
->sme
.assoc_req_ie_len
;
472 *pos
++ = WLAN_EID_MOBILITY_DOMAIN
;
473 *pos
++ = sizeof(*mdie
);
474 mdie
= (struct rsn_mdie
*) pos
;
475 os_memcpy(mdie
->mobility_domain
, md
,
476 MOBILITY_DOMAIN_ID_LEN
);
477 mdie
->ft_capab
= md
[MOBILITY_DOMAIN_ID_LEN
];
478 wpa_s
->sme
.assoc_req_ie_len
+= 5;
481 if (wpa_s
->sme
.prev_bssid_set
&& wpa_s
->sme
.ft_used
&&
482 os_memcmp(md
, wpa_s
->sme
.mobility_domain
, 2) == 0 &&
483 wpa_sm_has_ptk(wpa_s
->wpa
)) {
484 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying to use FT "
486 params
.auth_alg
= WPA_AUTH_ALG_FT
;
487 params
.ie
= wpa_s
->sme
.ft_ies
;
488 params
.ie_len
= wpa_s
->sme
.ft_ies_len
;
491 #endif /* CONFIG_IEEE80211R */
493 #ifdef CONFIG_IEEE80211W
494 wpa_s
->sme
.mfp
= wpas_get_ssid_pmf(wpa_s
, ssid
);
495 if (wpa_s
->sme
.mfp
!= NO_MGMT_FRAME_PROTECTION
) {
496 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
497 struct wpa_ie_data _ie
;
498 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &_ie
) == 0 &&
500 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
501 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Selected AP supports "
503 wpa_s
->sme
.mfp
= MGMT_FRAME_PROTECTION_REQUIRED
;
506 #endif /* CONFIG_IEEE80211W */
509 if (wpa_s
->global
->p2p
) {
513 pos
= wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
;
514 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
515 wpa_s
->sme
.assoc_req_ie_len
;
516 res
= wpas_p2p_assoc_req_ie(wpa_s
, bss
, pos
, len
,
519 wpa_s
->sme
.assoc_req_ie_len
+= res
;
521 #endif /* CONFIG_P2P */
524 if (wpa_s
->fst_ies
) {
525 int fst_ies_len
= wpabuf_len(wpa_s
->fst_ies
);
527 if (wpa_s
->sme
.assoc_req_ie_len
+ fst_ies_len
<=
528 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
529 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
530 wpa_s
->sme
.assoc_req_ie_len
,
531 wpabuf_head(wpa_s
->fst_ies
),
533 wpa_s
->sme
.assoc_req_ie_len
+= fst_ies_len
;
536 #endif /* CONFIG_FST */
538 sme_auth_handle_rrm(wpa_s
, bss
);
540 wpa_s
->sme
.assoc_req_ie_len
+= wpas_supp_op_class_ie(
541 wpa_s
, ssid
, bss
->freq
,
542 wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
543 sizeof(wpa_s
->sme
.assoc_req_ie
) - wpa_s
->sme
.assoc_req_ie_len
);
546 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_P2P_CLIENT
);
548 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_STATION
);
550 ext_capab_len
= wpas_build_ext_capab(wpa_s
, ext_capab
,
552 if (ext_capab_len
> 0) {
553 u8
*pos
= wpa_s
->sme
.assoc_req_ie
;
554 if (wpa_s
->sme
.assoc_req_ie_len
> 0 && pos
[0] == WLAN_EID_RSN
)
556 os_memmove(pos
+ ext_capab_len
, pos
,
557 wpa_s
->sme
.assoc_req_ie_len
-
558 (pos
- wpa_s
->sme
.assoc_req_ie
));
559 wpa_s
->sme
.assoc_req_ie_len
+= ext_capab_len
;
560 os_memcpy(pos
, ext_capab
, ext_capab_len
);
564 if (is_hs20_network(wpa_s
, ssid
, bss
)) {
567 hs20
= wpabuf_alloc(20 + MAX_ROAMING_CONS_OI_LEN
);
569 int pps_mo_id
= hs20_get_pps_mo_id(wpa_s
, ssid
);
572 wpas_hs20_add_indication(hs20
, pps_mo_id
,
573 get_hs20_version(bss
));
574 wpas_hs20_add_roam_cons_sel(hs20
, ssid
);
575 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
576 wpa_s
->sme
.assoc_req_ie_len
;
577 if (wpabuf_len(hs20
) <= len
) {
578 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
579 wpa_s
->sme
.assoc_req_ie_len
,
580 wpabuf_head(hs20
), wpabuf_len(hs20
));
581 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(hs20
);
586 #endif /* CONFIG_HS20 */
591 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Reinsert WPA IE");
593 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
594 wpa_s
->sme
.assoc_req_ie_len
;
596 if (len
> wpa_ie_len
) {
597 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
598 wpa_s
->sme
.assoc_req_ie_len
,
600 wpa_s
->sme
.assoc_req_ie_len
+= wpa_ie_len
;
602 wpa_dbg(wpa_s
, MSG_DEBUG
, "WPA: Failed to add WPA IE");
608 if (wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
]) {
609 struct wpabuf
*buf
= wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
];
612 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
613 wpa_s
->sme
.assoc_req_ie_len
;
614 if (wpabuf_len(buf
) <= len
) {
615 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
616 wpa_s
->sme
.assoc_req_ie_len
,
617 wpabuf_head(buf
), wpabuf_len(buf
));
618 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(buf
);
623 mbo_ie
= wpa_bss_get_vendor_ie(bss
, MBO_IE_VENDOR_TYPE
);
627 len
= wpas_mbo_ie(wpa_s
, wpa_s
->sme
.assoc_req_ie
+
628 wpa_s
->sme
.assoc_req_ie_len
,
629 sizeof(wpa_s
->sme
.assoc_req_ie
) -
630 wpa_s
->sme
.assoc_req_ie_len
,
631 !!mbo_attr_from_mbo_ie(mbo_ie
,
632 OCE_ATTR_ID_CAPA_IND
));
634 wpa_s
->sme
.assoc_req_ie_len
+= len
;
636 #endif /* CONFIG_MBO */
639 if (!skip_auth
&& params
.auth_alg
== WPA_AUTH_ALG_SAE
&&
640 pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
, ssid
, 0,
642 wpa_s
->key_mgmt
== WPA_KEY_MGMT_FT_SAE
?
643 WPA_KEY_MGMT_FT_SAE
:
644 WPA_KEY_MGMT_SAE
) == 0) {
645 wpa_dbg(wpa_s
, MSG_DEBUG
,
646 "PMKSA cache entry found - try to use PMKSA caching instead of new SAE authentication");
647 wpa_sm_set_pmk_from_pmksa(wpa_s
->wpa
);
648 params
.auth_alg
= WPA_AUTH_ALG_OPEN
;
649 wpa_s
->sme
.sae_pmksa_caching
= 1;
652 if (!skip_auth
&& params
.auth_alg
== WPA_AUTH_ALG_SAE
) {
654 resp
= sme_auth_build_sae_commit(wpa_s
, ssid
,
658 resp
= sme_auth_build_sae_confirm(wpa_s
, 0);
660 wpas_connection_failed(wpa_s
, bss
->bssid
);
663 params
.auth_data
= wpabuf_head(resp
);
664 params
.auth_data_len
= wpabuf_len(resp
);
665 wpa_s
->sme
.sae
.state
= start
? SAE_COMMITTED
: SAE_CONFIRMED
;
667 #endif /* CONFIG_SAE */
669 old_ssid
= wpa_s
->current_ssid
;
670 wpa_s
->current_ssid
= ssid
;
671 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
672 wpa_supplicant_initiate_eapol(wpa_s
);
675 /* TODO: FILS operations can in some cases be done between different
676 * network_ctx (i.e., same credentials can be used with multiple
678 if (params
.auth_alg
== WPA_AUTH_ALG_OPEN
&&
679 wpa_key_mgmt_fils(ssid
->key_mgmt
)) {
682 const u8
*realm
, *username
, *rrk
;
683 size_t realm_len
, username_len
, rrk_len
;
687 * Check FILS Indication element (FILS Information field) bits
688 * indicating supported authentication algorithms against local
689 * configuration (ssid->fils_dh_group). Try to use FILS
690 * authentication only if the AP supports the combination in the
691 * network profile. */
692 indic
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
693 if (!indic
|| indic
[1] < 2) {
694 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
695 " does not include FILS Indication element - cannot use FILS authentication with it",
696 MAC2STR(bss
->bssid
));
700 fils_info
= WPA_GET_LE16(indic
+ 2);
701 if (ssid
->fils_dh_group
== 0 && !(fils_info
& BIT(9))) {
702 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
703 " does not support FILS SK without PFS - cannot use FILS authentication with it",
704 MAC2STR(bss
->bssid
));
707 if (ssid
->fils_dh_group
!= 0 && !(fils_info
& BIT(10))) {
708 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
709 " does not support FILS SK with PFS - cannot use FILS authentication with it",
710 MAC2STR(bss
->bssid
));
714 if (wpa_s
->last_con_fail_realm
&&
715 eapol_sm_get_erp_info(wpa_s
->eapol
, &ssid
->eap
,
716 &username
, &username_len
,
717 &realm
, &realm_len
, &next_seq_num
,
718 &rrk
, &rrk_len
) == 0 &&
719 realm
&& realm_len
== wpa_s
->last_con_fail_realm_len
&&
720 os_memcmp(realm
, wpa_s
->last_con_fail_realm
,
722 wpa_printf(MSG_DEBUG
,
723 "SME: FILS authentication for this realm failed last time - try to regenerate ERP key hierarchy");
727 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
729 wpa_bss_get_fils_cache_id(bss
),
731 wpa_printf(MSG_DEBUG
,
732 "SME: Try to use FILS with PMKSA caching");
733 resp
= fils_build_auth(wpa_s
->wpa
, ssid
->fils_dh_group
, md
);
737 if (ssid
->fils_dh_group
)
738 wpa_printf(MSG_DEBUG
,
739 "SME: Try to use FILS SK authentication with PFS (DH Group %u)",
740 ssid
->fils_dh_group
);
742 wpa_printf(MSG_DEBUG
,
743 "SME: Try to use FILS SK authentication without PFS");
744 auth_alg
= ssid
->fils_dh_group
?
745 WPA_AUTH_ALG_FILS_SK_PFS
: WPA_AUTH_ALG_FILS
;
746 params
.auth_alg
= auth_alg
;
747 params
.auth_data
= wpabuf_head(resp
);
748 params
.auth_data_len
= wpabuf_len(resp
);
749 wpa_s
->sme
.auth_alg
= auth_alg
;
753 #endif /* CONFIG_FILS */
755 wpa_supplicant_cancel_sched_scan(wpa_s
);
756 wpa_supplicant_cancel_scan(wpa_s
);
758 wpa_msg(wpa_s
, MSG_INFO
, "SME: Trying to authenticate with " MACSTR
759 " (SSID='%s' freq=%d MHz)", MAC2STR(params
.bssid
),
760 wpa_ssid_txt(params
.ssid
, params
.ssid_len
), params
.freq
);
762 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
763 wpa_clear_keys(wpa_s
, bss
->bssid
);
764 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
765 if (old_ssid
!= wpa_s
->current_ssid
)
766 wpas_notify_network_changed(wpa_s
);
769 hs20_configure_frame_filters(wpa_s
);
770 #endif /* CONFIG_HS20 */
774 * If multi-channel concurrency is not supported, check for any
775 * frequency conflict. In case of any frequency conflict, remove the
776 * least prioritized connection.
778 if (wpa_s
->num_multichan_concurrent
< 2) {
780 num
= get_shared_radio_freqs(wpa_s
, &freq
, 1);
781 if (num
> 0 && freq
> 0 && freq
!= params
.freq
) {
782 wpa_printf(MSG_DEBUG
,
783 "Conflicting frequency found (%d != %d)",
785 if (wpas_p2p_handle_frequency_conflicts(wpa_s
,
788 wpas_connection_failed(wpa_s
, bss
->bssid
);
789 wpa_supplicant_mark_disassoc(wpa_s
);
791 wpas_connect_work_done(wpa_s
);
796 #endif /* CONFIG_P2P */
799 wpa_msg(wpa_s
, MSG_DEBUG
,
800 "SME: Skip authentication step on reassoc-to-same-BSS");
802 sme_associate(wpa_s
, ssid
->mode
, bss
->bssid
, WLAN_AUTH_OPEN
);
807 wpa_s
->sme
.auth_alg
= params
.auth_alg
;
808 if (wpa_drv_authenticate(wpa_s
, ¶ms
) < 0) {
809 wpa_msg(wpa_s
, MSG_INFO
, "SME: Authentication request to the "
811 wpas_connection_failed(wpa_s
, bss
->bssid
);
812 wpa_supplicant_mark_disassoc(wpa_s
);
814 wpas_connect_work_done(wpa_s
);
818 eloop_register_timeout(SME_AUTH_TIMEOUT
, 0, sme_auth_timer
, wpa_s
,
822 * Association will be started based on the authentication event from
830 static void sme_auth_start_cb(struct wpa_radio_work
*work
, int deinit
)
832 struct wpa_connect_work
*cwork
= work
->ctx
;
833 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
837 wpa_s
->connect_work
= NULL
;
839 wpas_connect_work_free(cwork
);
843 wpa_s
->connect_work
= work
;
845 if (cwork
->bss_removed
||
846 !wpas_valid_bss_ssid(wpa_s
, cwork
->bss
, cwork
->ssid
) ||
847 wpas_network_disabled(wpa_s
, cwork
->ssid
)) {
848 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: BSS/SSID entry for authentication not valid anymore - drop connection attempt");
849 wpas_connect_work_done(wpa_s
);
853 /* Starting new connection, so clear the possibly used WPA IE from the
854 * previous association. */
855 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
857 sme_send_authentication(wpa_s
, cwork
->bss
, cwork
->ssid
, 1);
861 void sme_authenticate(struct wpa_supplicant
*wpa_s
,
862 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
864 struct wpa_connect_work
*cwork
;
866 if (bss
== NULL
|| ssid
== NULL
)
868 if (wpa_s
->connect_work
) {
869 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Reject sme_authenticate() call since connect_work exist");
873 if (radio_work_pending(wpa_s
, "sme-connect")) {
875 * The previous sme-connect work might no longer be valid due to
876 * the fact that the BSS list was updated. In addition, it makes
877 * sense to adhere to the 'newer' decision.
879 wpa_dbg(wpa_s
, MSG_DEBUG
,
880 "SME: Remove previous pending sme-connect");
881 radio_remove_works(wpa_s
, "sme-connect", 0);
884 wpas_abort_ongoing_scan(wpa_s
);
886 cwork
= os_zalloc(sizeof(*cwork
));
894 wpa_s
->sme
.sae
.state
= SAE_NOTHING
;
895 wpa_s
->sme
.sae
.send_confirm
= 0;
896 wpa_s
->sme
.sae_group_index
= 0;
897 #endif /* CONFIG_SAE */
899 if (radio_add_work(wpa_s
, bss
->freq
, "sme-connect", 1,
900 sme_auth_start_cb
, cwork
) < 0)
901 wpas_connect_work_free(cwork
);
907 static int sme_external_auth_build_buf(struct wpabuf
*buf
,
908 struct wpabuf
*params
,
909 const u8
*sa
, const u8
*da
,
910 u16 auth_transaction
, u16 seq_num
)
912 struct ieee80211_mgmt
*resp
;
914 resp
= wpabuf_put(buf
, offsetof(struct ieee80211_mgmt
,
917 resp
->frame_control
= host_to_le16((WLAN_FC_TYPE_MGMT
<< 2) |
918 (WLAN_FC_STYPE_AUTH
<< 4));
919 os_memcpy(resp
->da
, da
, ETH_ALEN
);
920 os_memcpy(resp
->sa
, sa
, ETH_ALEN
);
921 os_memcpy(resp
->bssid
, da
, ETH_ALEN
);
922 resp
->u
.auth
.auth_alg
= host_to_le16(WLAN_AUTH_SAE
);
923 resp
->seq_ctrl
= host_to_le16(seq_num
<< 4);
924 resp
->u
.auth
.auth_transaction
= host_to_le16(auth_transaction
);
925 resp
->u
.auth
.status_code
= host_to_le16(WLAN_STATUS_SUCCESS
);
927 wpabuf_put_buf(buf
, params
);
933 static void sme_external_auth_send_sae_commit(struct wpa_supplicant
*wpa_s
,
935 struct wpa_ssid
*ssid
)
937 struct wpabuf
*resp
, *buf
;
939 resp
= sme_auth_build_sae_commit(wpa_s
, ssid
, bssid
, 1, 0);
943 wpa_s
->sme
.sae
.state
= SAE_COMMITTED
;
944 buf
= wpabuf_alloc(4 + SAE_COMMIT_MAX_LEN
+ wpabuf_len(resp
));
950 wpa_s
->sme
.seq_num
++;
951 sme_external_auth_build_buf(buf
, resp
, wpa_s
->own_addr
,
952 bssid
, 1, wpa_s
->sme
.seq_num
);
953 wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
), 1, 0);
959 static void sme_send_external_auth_status(struct wpa_supplicant
*wpa_s
,
962 struct external_auth params
;
964 os_memset(¶ms
, 0, sizeof(params
));
965 params
.status
= status
;
966 os_memcpy(params
.ssid
, wpa_s
->sme
.ext_auth
.ssid
,
967 wpa_s
->sme
.ext_auth
.ssid_len
);
968 params
.ssid_len
= wpa_s
->sme
.ext_auth
.ssid_len
;
969 os_memcpy(params
.bssid
, wpa_s
->sme
.ext_auth
.bssid
, ETH_ALEN
);
970 wpa_drv_send_external_auth_status(wpa_s
, ¶ms
);
974 static void sme_handle_external_auth_start(struct wpa_supplicant
*wpa_s
,
975 union wpa_event_data
*data
)
977 struct wpa_ssid
*ssid
;
978 size_t ssid_str_len
= data
->external_auth
.ssid_len
;
979 u8
*ssid_str
= data
->external_auth
.ssid
;
981 /* Get the SSID conf from the ssid string obtained */
982 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
983 if (!wpas_network_disabled(wpa_s
, ssid
) &&
984 ssid_str_len
== ssid
->ssid_len
&&
985 os_memcmp(ssid_str
, ssid
->ssid
, ssid_str_len
) == 0 &&
986 (ssid
->key_mgmt
& (WPA_KEY_MGMT_SAE
| WPA_KEY_MGMT_FT_SAE
)))
990 sme_external_auth_send_sae_commit(wpa_s
,
991 data
->external_auth
.bssid
,
994 sme_send_external_auth_status(wpa_s
,
995 WLAN_STATUS_UNSPECIFIED_FAILURE
);
999 static void sme_external_auth_send_sae_confirm(struct wpa_supplicant
*wpa_s
,
1002 struct wpabuf
*resp
, *buf
;
1004 resp
= sme_auth_build_sae_confirm(wpa_s
, 1);
1006 wpa_printf(MSG_DEBUG
, "SAE: Confirm message buf alloc failure");
1010 wpa_s
->sme
.sae
.state
= SAE_CONFIRMED
;
1011 buf
= wpabuf_alloc(4 + SAE_CONFIRM_MAX_LEN
+ wpabuf_len(resp
));
1013 wpa_printf(MSG_DEBUG
, "SAE: Auth Confirm buf alloc failure");
1017 wpa_s
->sme
.seq_num
++;
1018 sme_external_auth_build_buf(buf
, resp
, wpa_s
->own_addr
,
1019 da
, 2, wpa_s
->sme
.seq_num
);
1020 wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
), 1, 0);
1026 void sme_external_auth_trigger(struct wpa_supplicant
*wpa_s
,
1027 union wpa_event_data
*data
)
1029 if (RSN_SELECTOR_GET(&data
->external_auth
.key_mgmt_suite
) !=
1030 RSN_AUTH_KEY_MGMT_SAE
)
1033 if (data
->external_auth
.action
== EXT_AUTH_START
) {
1034 os_memcpy(&wpa_s
->sme
.ext_auth
, data
,
1035 sizeof(struct external_auth
));
1036 wpa_s
->sme
.seq_num
= 0;
1037 wpa_s
->sme
.sae
.state
= SAE_NOTHING
;
1038 wpa_s
->sme
.sae
.send_confirm
= 0;
1039 wpa_s
->sme
.sae_group_index
= 0;
1040 sme_handle_external_auth_start(wpa_s
, data
);
1041 } else if (data
->external_auth
.action
== EXT_AUTH_ABORT
) {
1042 /* Report failure to driver for the wrong trigger */
1043 sme_send_external_auth_status(wpa_s
,
1044 WLAN_STATUS_UNSPECIFIED_FAILURE
);
1049 static int sme_sae_auth(struct wpa_supplicant
*wpa_s
, u16 auth_transaction
,
1050 u16 status_code
, const u8
*data
, size_t len
,
1051 int external
, const u8
*sa
)
1055 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SAE authentication transaction %u "
1056 "status code %u", auth_transaction
, status_code
);
1058 if (auth_transaction
== 1 &&
1059 status_code
== WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
&&
1060 wpa_s
->sme
.sae
.state
== SAE_COMMITTED
&&
1061 (external
|| wpa_s
->current_bss
) && wpa_s
->current_ssid
) {
1062 int default_groups
[] = { 19, 20, 21, 0 };
1065 groups
= wpa_s
->conf
->sae_groups
;
1066 if (!groups
|| groups
[0] <= 0)
1067 groups
= default_groups
;
1069 if (len
< sizeof(le16
)) {
1070 wpa_dbg(wpa_s
, MSG_DEBUG
,
1071 "SME: Too short SAE anti-clogging token request");
1074 group
= WPA_GET_LE16(data
);
1075 wpa_dbg(wpa_s
, MSG_DEBUG
,
1076 "SME: SAE anti-clogging token requested (group %u)",
1078 if (sae_group_allowed(&wpa_s
->sme
.sae
, groups
, group
) !=
1079 WLAN_STATUS_SUCCESS
) {
1080 wpa_dbg(wpa_s
, MSG_ERROR
,
1081 "SME: SAE group %u of anti-clogging request is invalid",
1085 wpabuf_free(wpa_s
->sme
.sae_token
);
1086 wpa_s
->sme
.sae_token
= wpabuf_alloc_copy(data
+ sizeof(le16
),
1087 len
- sizeof(le16
));
1089 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
1090 wpa_s
->current_ssid
, 2);
1092 sme_external_auth_send_sae_commit(
1093 wpa_s
, wpa_s
->sme
.ext_auth
.bssid
,
1094 wpa_s
->current_ssid
);
1098 if (auth_transaction
== 1 &&
1099 status_code
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
1100 wpa_s
->sme
.sae
.state
== SAE_COMMITTED
&&
1101 (external
|| wpa_s
->current_bss
) && wpa_s
->current_ssid
) {
1102 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SAE group not supported");
1103 wpa_s
->sme
.sae_group_index
++;
1104 if (sme_set_sae_group(wpa_s
) < 0)
1105 return -1; /* no other groups enabled */
1106 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Try next enabled SAE group");
1108 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
1109 wpa_s
->current_ssid
, 1);
1111 sme_external_auth_send_sae_commit(
1112 wpa_s
, wpa_s
->sme
.ext_auth
.bssid
,
1113 wpa_s
->current_ssid
);
1117 if (auth_transaction
== 1 &&
1118 status_code
== WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER
) {
1119 const u8
*bssid
= sa
? sa
: wpa_s
->pending_bssid
;
1121 wpa_msg(wpa_s
, MSG_INFO
,
1122 WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER MACSTR
,
1127 if (status_code
!= WLAN_STATUS_SUCCESS
)
1130 if (auth_transaction
== 1) {
1133 groups
= wpa_s
->conf
->sae_groups
;
1135 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME SAE commit");
1136 if ((!external
&& wpa_s
->current_bss
== NULL
) ||
1137 wpa_s
->current_ssid
== NULL
)
1139 if (wpa_s
->sme
.sae
.state
!= SAE_COMMITTED
)
1141 if (groups
&& groups
[0] <= 0)
1143 res
= sae_parse_commit(&wpa_s
->sme
.sae
, data
, len
, NULL
, NULL
,
1145 if (res
== SAE_SILENTLY_DISCARD
) {
1146 wpa_printf(MSG_DEBUG
,
1147 "SAE: Drop commit message due to reflection attack");
1150 if (res
!= WLAN_STATUS_SUCCESS
)
1153 if (sae_process_commit(&wpa_s
->sme
.sae
) < 0) {
1154 wpa_printf(MSG_DEBUG
, "SAE: Failed to process peer "
1159 wpabuf_free(wpa_s
->sme
.sae_token
);
1160 wpa_s
->sme
.sae_token
= NULL
;
1162 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
1163 wpa_s
->current_ssid
, 0);
1165 sme_external_auth_send_sae_confirm(wpa_s
, sa
);
1167 } else if (auth_transaction
== 2) {
1168 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME SAE confirm");
1169 if (wpa_s
->sme
.sae
.state
!= SAE_CONFIRMED
)
1171 if (sae_check_confirm(&wpa_s
->sme
.sae
, data
, len
) < 0)
1173 wpa_s
->sme
.sae
.state
= SAE_ACCEPTED
;
1174 sae_clear_temp_data(&wpa_s
->sme
.sae
);
1177 /* Report success to driver */
1178 sme_send_external_auth_status(wpa_s
,
1179 WLAN_STATUS_SUCCESS
);
1189 void sme_external_auth_mgmt_rx(struct wpa_supplicant
*wpa_s
,
1190 const u8
*auth_frame
, size_t len
)
1192 const struct ieee80211_mgmt
*header
;
1195 header
= (const struct ieee80211_mgmt
*) auth_frame
;
1196 auth_length
= IEEE80211_HDRLEN
+ sizeof(header
->u
.auth
);
1198 if (len
< auth_length
) {
1199 /* Notify failure to the driver */
1200 sme_send_external_auth_status(wpa_s
,
1201 WLAN_STATUS_UNSPECIFIED_FAILURE
);
1205 if (le_to_host16(header
->u
.auth
.auth_alg
) == WLAN_AUTH_SAE
) {
1209 wpa_s
, le_to_host16(header
->u
.auth
.auth_transaction
),
1210 le_to_host16(header
->u
.auth
.status_code
),
1211 header
->u
.auth
.variable
,
1212 len
- auth_length
, 1, header
->sa
);
1214 /* Notify failure to the driver */
1215 sme_send_external_auth_status(
1216 wpa_s
, WLAN_STATUS_UNSPECIFIED_FAILURE
);
1222 wpa_printf(MSG_DEBUG
,
1223 "SME: SAE completed - setting PMK for 4-way handshake");
1224 wpa_sm_set_pmk(wpa_s
->wpa
, wpa_s
->sme
.sae
.pmk
, PMK_LEN
,
1225 wpa_s
->sme
.sae
.pmkid
, wpa_s
->pending_bssid
);
1229 #endif /* CONFIG_SAE */
1232 void sme_event_auth(struct wpa_supplicant
*wpa_s
, union wpa_event_data
*data
)
1234 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1237 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication event "
1238 "when network is not selected");
1242 if (wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) {
1243 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication event "
1244 "when not in authenticating state");
1248 if (os_memcmp(wpa_s
->pending_bssid
, data
->auth
.peer
, ETH_ALEN
) != 0) {
1249 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication with "
1250 "unexpected peer " MACSTR
,
1251 MAC2STR(data
->auth
.peer
));
1255 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Authentication response: peer=" MACSTR
1256 " auth_type=%d auth_transaction=%d status_code=%d",
1257 MAC2STR(data
->auth
.peer
), data
->auth
.auth_type
,
1258 data
->auth
.auth_transaction
, data
->auth
.status_code
);
1259 wpa_hexdump(MSG_MSGDUMP
, "SME: Authentication response IEs",
1260 data
->auth
.ies
, data
->auth
.ies_len
);
1262 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1265 if (data
->auth
.auth_type
== WLAN_AUTH_SAE
) {
1267 res
= sme_sae_auth(wpa_s
, data
->auth
.auth_transaction
,
1268 data
->auth
.status_code
, data
->auth
.ies
,
1269 data
->auth
.ies_len
, 0, NULL
);
1271 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1272 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1278 wpa_printf(MSG_DEBUG
, "SME: SAE completed - setting PMK for "
1280 wpa_sm_set_pmk(wpa_s
->wpa
, wpa_s
->sme
.sae
.pmk
, PMK_LEN
,
1281 wpa_s
->sme
.sae
.pmkid
, wpa_s
->pending_bssid
);
1283 #endif /* CONFIG_SAE */
1285 if (data
->auth
.status_code
!= WLAN_STATUS_SUCCESS
) {
1286 char *ie_txt
= NULL
;
1288 if (data
->auth
.ies
&& data
->auth
.ies_len
) {
1289 size_t buflen
= 2 * data
->auth
.ies_len
+ 1;
1290 ie_txt
= os_malloc(buflen
);
1292 wpa_snprintf_hex(ie_txt
, buflen
, data
->auth
.ies
,
1293 data
->auth
.ies_len
);
1296 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AUTH_REJECT MACSTR
1297 " auth_type=%u auth_transaction=%u status_code=%u%s%s",
1298 MAC2STR(data
->auth
.peer
), data
->auth
.auth_type
,
1299 data
->auth
.auth_transaction
, data
->auth
.status_code
,
1300 ie_txt
? " ie=" : "",
1301 ie_txt
? ie_txt
: "");
1305 if (wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS
||
1306 wpa_s
->sme
.auth_alg
== WPA_AUTH_ALG_FILS_SK_PFS
)
1307 fils_connection_failure(wpa_s
);
1308 #endif /* CONFIG_FILS */
1310 if (data
->auth
.status_code
!=
1311 WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
||
1312 wpa_s
->sme
.auth_alg
== data
->auth
.auth_type
||
1313 wpa_s
->current_ssid
->auth_alg
== WPA_AUTH_ALG_LEAP
) {
1314 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1315 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1319 wpas_connect_work_done(wpa_s
);
1321 switch (data
->auth
.auth_type
) {
1322 case WLAN_AUTH_OPEN
:
1323 wpa_s
->current_ssid
->auth_alg
= WPA_AUTH_ALG_SHARED
;
1325 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying SHARED auth");
1326 wpa_supplicant_associate(wpa_s
, wpa_s
->current_bss
,
1327 wpa_s
->current_ssid
);
1330 case WLAN_AUTH_SHARED_KEY
:
1331 wpa_s
->current_ssid
->auth_alg
= WPA_AUTH_ALG_LEAP
;
1333 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying LEAP auth");
1334 wpa_supplicant_associate(wpa_s
, wpa_s
->current_bss
,
1335 wpa_s
->current_ssid
);
1343 #ifdef CONFIG_IEEE80211R
1344 if (data
->auth
.auth_type
== WLAN_AUTH_FT
) {
1345 const u8
*ric_ies
= NULL
;
1346 size_t ric_ies_len
= 0;
1348 if (wpa_s
->ric_ies
) {
1349 ric_ies
= wpabuf_head(wpa_s
->ric_ies
);
1350 ric_ies_len
= wpabuf_len(wpa_s
->ric_ies
);
1352 if (wpa_ft_process_response(wpa_s
->wpa
, data
->auth
.ies
,
1353 data
->auth
.ies_len
, 0,
1355 ric_ies
, ric_ies_len
) < 0) {
1356 wpa_dbg(wpa_s
, MSG_DEBUG
,
1357 "SME: FT Authentication response processing failed");
1358 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1360 " reason=%d locally_generated=1",
1361 MAC2STR(wpa_s
->pending_bssid
),
1362 WLAN_REASON_DEAUTH_LEAVING
);
1363 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1364 wpa_supplicant_mark_disassoc(wpa_s
);
1368 #endif /* CONFIG_IEEE80211R */
1371 if (data
->auth
.auth_type
== WLAN_AUTH_FILS_SK
||
1372 data
->auth
.auth_type
== WLAN_AUTH_FILS_SK_PFS
) {
1373 u16 expect_auth_type
;
1375 expect_auth_type
= wpa_s
->sme
.auth_alg
==
1376 WPA_AUTH_ALG_FILS_SK_PFS
? WLAN_AUTH_FILS_SK_PFS
:
1378 if (data
->auth
.auth_type
!= expect_auth_type
) {
1379 wpa_dbg(wpa_s
, MSG_DEBUG
,
1380 "SME: FILS Authentication response used different auth alg (%u; expected %u)",
1381 data
->auth
.auth_type
, expect_auth_type
);
1382 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1384 " reason=%d locally_generated=1",
1385 MAC2STR(wpa_s
->pending_bssid
),
1386 WLAN_REASON_DEAUTH_LEAVING
);
1387 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1388 wpa_supplicant_mark_disassoc(wpa_s
);
1392 if (fils_process_auth(wpa_s
->wpa
, wpa_s
->pending_bssid
,
1393 data
->auth
.ies
, data
->auth
.ies_len
) < 0) {
1394 wpa_dbg(wpa_s
, MSG_DEBUG
,
1395 "SME: FILS Authentication response processing failed");
1396 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1398 " reason=%d locally_generated=1",
1399 MAC2STR(wpa_s
->pending_bssid
),
1400 WLAN_REASON_DEAUTH_LEAVING
);
1401 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1402 wpa_supplicant_mark_disassoc(wpa_s
);
1406 #endif /* CONFIG_FILS */
1408 sme_associate(wpa_s
, ssid
->mode
, data
->auth
.peer
,
1409 data
->auth
.auth_type
);
1413 #ifdef CONFIG_IEEE80211R
1414 static void remove_ie(u8
*buf
, size_t *len
, u8 eid
)
1416 u8
*pos
, *next
, *end
;
1418 pos
= (u8
*) get_ie(buf
, *len
, eid
);
1420 next
= pos
+ 2 + pos
[1];
1423 os_memmove(pos
, next
, end
- next
);
1426 #endif /* CONFIG_IEEE80211R */
1429 void sme_associate(struct wpa_supplicant
*wpa_s
, enum wpas_mode mode
,
1430 const u8
*bssid
, u16 auth_type
)
1432 struct wpa_driver_associate_params params
;
1433 struct ieee802_11_elems elems
;
1435 u8 nonces
[2 * FILS_NONCE_LEN
];
1436 #endif /* CONFIG_FILS */
1437 #ifdef CONFIG_HT_OVERRIDES
1438 struct ieee80211_ht_capabilities htcaps
;
1439 struct ieee80211_ht_capabilities htcaps_mask
;
1440 #endif /* CONFIG_HT_OVERRIDES */
1441 #ifdef CONFIG_VHT_OVERRIDES
1442 struct ieee80211_vht_capabilities vhtcaps
;
1443 struct ieee80211_vht_capabilities vhtcaps_mask
;
1444 #endif /* CONFIG_VHT_OVERRIDES */
1446 os_memset(¶ms
, 0, sizeof(params
));
1449 if (auth_type
== WLAN_AUTH_FILS_SK
||
1450 auth_type
== WLAN_AUTH_FILS_SK_PFS
) {
1452 const u8
*snonce
, *anonce
;
1453 const unsigned int max_hlp
= 20;
1454 struct wpabuf
*hlp
[max_hlp
];
1455 unsigned int i
, num_hlp
= 0;
1456 struct fils_hlp_req
*req
;
1458 dl_list_for_each(req
, &wpa_s
->fils_hlp_req
, struct fils_hlp_req
,
1460 hlp
[num_hlp
] = wpabuf_alloc(2 * ETH_ALEN
+ 6 +
1461 wpabuf_len(req
->pkt
));
1464 wpabuf_put_data(hlp
[num_hlp
], req
->dst
, ETH_ALEN
);
1465 wpabuf_put_data(hlp
[num_hlp
], wpa_s
->own_addr
,
1467 wpabuf_put_data(hlp
[num_hlp
],
1468 "\xaa\xaa\x03\x00\x00\x00", 6);
1469 wpabuf_put_buf(hlp
[num_hlp
], req
->pkt
);
1471 if (num_hlp
>= max_hlp
)
1475 buf
= fils_build_assoc_req(wpa_s
->wpa
, ¶ms
.fils_kek
,
1476 ¶ms
.fils_kek_len
, &snonce
,
1478 (const struct wpabuf
**) hlp
,
1480 for (i
= 0; i
< num_hlp
; i
++)
1481 wpabuf_free(hlp
[i
]);
1484 wpa_hexdump(MSG_DEBUG
, "FILS: assoc_req before FILS elements",
1485 wpa_s
->sme
.assoc_req_ie
,
1486 wpa_s
->sme
.assoc_req_ie_len
);
1487 #ifdef CONFIG_IEEE80211R
1488 if (wpa_key_mgmt_ft(wpa_s
->key_mgmt
)) {
1489 /* Remove RSNE and MDE to allow them to be overridden
1490 * with FILS+FT specific values from
1491 * fils_build_assoc_req(). */
1492 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1493 &wpa_s
->sme
.assoc_req_ie_len
,
1495 wpa_hexdump(MSG_DEBUG
,
1496 "FILS: assoc_req after RSNE removal",
1497 wpa_s
->sme
.assoc_req_ie
,
1498 wpa_s
->sme
.assoc_req_ie_len
);
1499 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1500 &wpa_s
->sme
.assoc_req_ie_len
,
1501 WLAN_EID_MOBILITY_DOMAIN
);
1502 wpa_hexdump(MSG_DEBUG
,
1503 "FILS: assoc_req after MDE removal",
1504 wpa_s
->sme
.assoc_req_ie
,
1505 wpa_s
->sme
.assoc_req_ie_len
);
1507 #endif /* CONFIG_IEEE80211R */
1508 /* TODO: Make wpa_s->sme.assoc_req_ie use dynamic allocation */
1509 if (wpa_s
->sme
.assoc_req_ie_len
+ wpabuf_len(buf
) >
1510 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1511 wpa_printf(MSG_ERROR
,
1512 "FILS: Not enough buffer room for own AssocReq elements");
1516 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1517 wpabuf_head(buf
), wpabuf_len(buf
));
1518 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(buf
);
1520 wpa_hexdump(MSG_DEBUG
, "FILS: assoc_req after FILS elements",
1521 wpa_s
->sme
.assoc_req_ie
,
1522 wpa_s
->sme
.assoc_req_ie_len
);
1524 os_memcpy(nonces
, snonce
, FILS_NONCE_LEN
);
1525 os_memcpy(nonces
+ FILS_NONCE_LEN
, anonce
, FILS_NONCE_LEN
);
1526 params
.fils_nonces
= nonces
;
1527 params
.fils_nonces_len
= sizeof(nonces
);
1529 #endif /* CONFIG_FILS */
1532 #ifdef CONFIG_TESTING_OPTIONS
1533 if (get_ie_ext(wpa_s
->sme
.assoc_req_ie
, wpa_s
->sme
.assoc_req_ie_len
,
1534 WLAN_EID_EXT_OWE_DH_PARAM
)) {
1535 wpa_printf(MSG_INFO
, "TESTING: Override OWE DH element");
1537 #endif /* CONFIG_TESTING_OPTIONS */
1538 if (auth_type
== WLAN_AUTH_OPEN
&&
1539 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
) {
1540 struct wpabuf
*owe_ie
;
1543 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->owe_group
) {
1544 group
= wpa_s
->current_ssid
->owe_group
;
1545 } else if (wpa_s
->assoc_status_code
==
1546 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
) {
1547 if (wpa_s
->last_owe_group
== 19)
1549 else if (wpa_s
->last_owe_group
== 20)
1552 group
= OWE_DH_GROUP
;
1554 group
= OWE_DH_GROUP
;
1557 wpa_s
->last_owe_group
= group
;
1558 wpa_printf(MSG_DEBUG
, "OWE: Try to use group %u", group
);
1559 owe_ie
= owe_build_assoc_req(wpa_s
->wpa
, group
);
1561 wpa_printf(MSG_ERROR
,
1562 "OWE: Failed to build IE for Association Request frame");
1565 if (wpa_s
->sme
.assoc_req_ie_len
+ wpabuf_len(owe_ie
) >
1566 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1567 wpa_printf(MSG_ERROR
,
1568 "OWE: Not enough buffer room for own Association Request frame elements");
1569 wpabuf_free(owe_ie
);
1572 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1573 wpabuf_head(owe_ie
), wpabuf_len(owe_ie
));
1574 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(owe_ie
);
1575 wpabuf_free(owe_ie
);
1577 #endif /* CONFIG_OWE */
1580 if (wpa_s
->key_mgmt
== WPA_KEY_MGMT_DPP
&& wpa_s
->current_ssid
&&
1581 wpa_s
->current_ssid
->dpp_netaccesskey
) {
1582 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1584 dpp_pfs_free(wpa_s
->dpp_pfs
);
1585 wpa_s
->dpp_pfs
= dpp_pfs_init(ssid
->dpp_netaccesskey
,
1586 ssid
->dpp_netaccesskey_len
);
1587 if (!wpa_s
->dpp_pfs
) {
1588 wpa_printf(MSG_DEBUG
, "DPP: Could not initialize PFS");
1589 /* Try to continue without PFS */
1592 if (wpa_s
->sme
.assoc_req_ie_len
+
1593 wpabuf_len(wpa_s
->dpp_pfs
->ie
) >
1594 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1595 wpa_printf(MSG_ERROR
,
1596 "DPP: Not enough buffer room for own Association Request frame elements");
1597 dpp_pfs_free(wpa_s
->dpp_pfs
);
1598 wpa_s
->dpp_pfs
= NULL
;
1601 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1602 wpabuf_head(wpa_s
->dpp_pfs
->ie
),
1603 wpabuf_len(wpa_s
->dpp_pfs
->ie
));
1604 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(wpa_s
->dpp_pfs
->ie
);
1607 #endif /* CONFIG_DPP2 */
1609 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->multi_ap_backhaul_sta
) {
1610 size_t multi_ap_ie_len
;
1612 multi_ap_ie_len
= add_multi_ap_ie(
1613 wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1614 sizeof(wpa_s
->sme
.assoc_req_ie
) -
1615 wpa_s
->sme
.assoc_req_ie_len
,
1616 MULTI_AP_BACKHAUL_STA
);
1617 if (multi_ap_ie_len
== 0) {
1618 wpa_printf(MSG_ERROR
,
1619 "Multi-AP: Failed to build Multi-AP IE");
1622 wpa_s
->sme
.assoc_req_ie_len
+= multi_ap_ie_len
;
1625 params
.bssid
= bssid
;
1626 params
.ssid
= wpa_s
->sme
.ssid
;
1627 params
.ssid_len
= wpa_s
->sme
.ssid_len
;
1628 params
.freq
.freq
= wpa_s
->sme
.freq
;
1629 params
.bg_scan_period
= wpa_s
->current_ssid
?
1630 wpa_s
->current_ssid
->bg_scan_period
: -1;
1631 params
.wpa_ie
= wpa_s
->sme
.assoc_req_ie_len
?
1632 wpa_s
->sme
.assoc_req_ie
: NULL
;
1633 params
.wpa_ie_len
= wpa_s
->sme
.assoc_req_ie_len
;
1634 wpa_hexdump(MSG_DEBUG
, "SME: Association Request IEs",
1635 params
.wpa_ie
, params
.wpa_ie_len
);
1636 params
.pairwise_suite
= wpa_s
->pairwise_cipher
;
1637 params
.group_suite
= wpa_s
->group_cipher
;
1638 params
.mgmt_group_suite
= wpa_s
->mgmt_group_cipher
;
1639 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
1640 params
.wpa_proto
= wpa_s
->wpa_proto
;
1641 #ifdef CONFIG_HT_OVERRIDES
1642 os_memset(&htcaps
, 0, sizeof(htcaps
));
1643 os_memset(&htcaps_mask
, 0, sizeof(htcaps_mask
));
1644 params
.htcaps
= (u8
*) &htcaps
;
1645 params
.htcaps_mask
= (u8
*) &htcaps_mask
;
1646 wpa_supplicant_apply_ht_overrides(wpa_s
, wpa_s
->current_ssid
, ¶ms
);
1647 #endif /* CONFIG_HT_OVERRIDES */
1648 #ifdef CONFIG_VHT_OVERRIDES
1649 os_memset(&vhtcaps
, 0, sizeof(vhtcaps
));
1650 os_memset(&vhtcaps_mask
, 0, sizeof(vhtcaps_mask
));
1651 params
.vhtcaps
= &vhtcaps
;
1652 params
.vhtcaps_mask
= &vhtcaps_mask
;
1653 wpa_supplicant_apply_vht_overrides(wpa_s
, wpa_s
->current_ssid
, ¶ms
);
1654 #endif /* CONFIG_VHT_OVERRIDES */
1655 #ifdef CONFIG_IEEE80211R
1656 if (auth_type
== WLAN_AUTH_FT
&& wpa_s
->sme
.ft_ies
&&
1657 get_ie(wpa_s
->sme
.ft_ies
, wpa_s
->sme
.ft_ies_len
,
1658 WLAN_EID_RIC_DATA
)) {
1659 /* There seems to be a pretty inconvenient bug in the Linux
1660 * kernel IE splitting functionality when RIC is used. For now,
1661 * skip correct behavior in IE construction here (i.e., drop the
1662 * additional non-FT-specific IEs) to avoid kernel issues. This
1663 * is fine since RIC is used only for testing purposes in the
1664 * current implementation. */
1665 wpa_printf(MSG_INFO
,
1666 "SME: Linux kernel workaround - do not try to include additional IEs with RIC");
1667 params
.wpa_ie
= wpa_s
->sme
.ft_ies
;
1668 params
.wpa_ie_len
= wpa_s
->sme
.ft_ies_len
;
1669 } else if (auth_type
== WLAN_AUTH_FT
&& wpa_s
->sme
.ft_ies
) {
1670 const u8
*rm_en
, *pos
, *end
;
1671 size_t rm_en_len
= 0;
1672 u8
*rm_en_dup
= NULL
, *wpos
;
1674 /* Remove RSNE, MDE, FTE to allow them to be overridden with
1675 * FT specific values */
1676 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1677 &wpa_s
->sme
.assoc_req_ie_len
,
1679 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1680 &wpa_s
->sme
.assoc_req_ie_len
,
1681 WLAN_EID_MOBILITY_DOMAIN
);
1682 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1683 &wpa_s
->sme
.assoc_req_ie_len
,
1684 WLAN_EID_FAST_BSS_TRANSITION
);
1685 rm_en
= get_ie(wpa_s
->sme
.assoc_req_ie
,
1686 wpa_s
->sme
.assoc_req_ie_len
,
1687 WLAN_EID_RRM_ENABLED_CAPABILITIES
);
1689 /* Need to remove RM Enabled Capabilities element as
1690 * well temporarily, so that it can be placed between
1692 rm_en_len
= 2 + rm_en
[1];
1693 rm_en_dup
= os_memdup(rm_en
, rm_en_len
);
1694 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1695 &wpa_s
->sme
.assoc_req_ie_len
,
1696 WLAN_EID_RRM_ENABLED_CAPABILITIES
);
1698 wpa_hexdump(MSG_DEBUG
,
1699 "SME: Association Request IEs after FT IE removal",
1700 wpa_s
->sme
.assoc_req_ie
,
1701 wpa_s
->sme
.assoc_req_ie_len
);
1702 if (wpa_s
->sme
.assoc_req_ie_len
+ wpa_s
->sme
.ft_ies_len
+
1703 rm_en_len
> sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1704 wpa_printf(MSG_ERROR
,
1705 "SME: Not enough buffer room for FT IEs in Association Request frame");
1710 os_memmove(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.ft_ies_len
+
1712 wpa_s
->sme
.assoc_req_ie
,
1713 wpa_s
->sme
.assoc_req_ie_len
);
1714 pos
= wpa_s
->sme
.ft_ies
;
1715 end
= pos
+ wpa_s
->sme
.ft_ies_len
;
1716 wpos
= wpa_s
->sme
.assoc_req_ie
;
1717 if (*pos
== WLAN_EID_RSN
) {
1718 os_memcpy(wpos
, pos
, 2 + pos
[1]);
1723 os_memcpy(wpos
, rm_en_dup
, rm_en_len
);
1727 os_memcpy(wpos
, pos
, end
- pos
);
1728 wpa_s
->sme
.assoc_req_ie_len
+= wpa_s
->sme
.ft_ies_len
+
1730 params
.wpa_ie
= wpa_s
->sme
.assoc_req_ie
;
1731 params
.wpa_ie_len
= wpa_s
->sme
.assoc_req_ie_len
;
1732 wpa_hexdump(MSG_DEBUG
,
1733 "SME: Association Request IEs after FT override",
1734 params
.wpa_ie
, params
.wpa_ie_len
);
1736 #endif /* CONFIG_IEEE80211R */
1738 params
.mgmt_frame_protection
= wpa_s
->sme
.mfp
;
1739 params
.rrm_used
= wpa_s
->rrm
.rrm_used
;
1740 if (wpa_s
->sme
.prev_bssid_set
)
1741 params
.prev_bssid
= wpa_s
->sme
.prev_bssid
;
1743 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
1744 " (SSID='%s' freq=%d MHz)", MAC2STR(params
.bssid
),
1745 params
.ssid
? wpa_ssid_txt(params
.ssid
, params
.ssid_len
) : "",
1748 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
1750 if (params
.wpa_ie
== NULL
||
1751 ieee802_11_parse_elems(params
.wpa_ie
, params
.wpa_ie_len
, &elems
, 0)
1753 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Could not parse own IEs?!");
1754 os_memset(&elems
, 0, sizeof(elems
));
1757 params
.wpa_proto
= WPA_PROTO_RSN
;
1758 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.rsn_ie
- 2,
1759 elems
.rsn_ie_len
+ 2);
1760 } else if (elems
.wpa_ie
) {
1761 params
.wpa_proto
= WPA_PROTO_WPA
;
1762 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.wpa_ie
- 2,
1763 elems
.wpa_ie_len
+ 2);
1764 } else if (elems
.osen
) {
1765 params
.wpa_proto
= WPA_PROTO_OSEN
;
1766 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.osen
- 2,
1767 elems
.osen_len
+ 2);
1769 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1770 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
)
1773 if (wpa_s
->p2pdev
->set_sta_uapsd
)
1774 params
.uapsd
= wpa_s
->p2pdev
->sta_uapsd
;
1778 if (wpa_drv_associate(wpa_s
, ¶ms
) < 0) {
1779 wpa_msg(wpa_s
, MSG_INFO
, "SME: Association request to the "
1781 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1782 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1783 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1787 eloop_register_timeout(SME_ASSOC_TIMEOUT
, 0, sme_assoc_timer
, wpa_s
,
1790 #ifdef CONFIG_TESTING_OPTIONS
1791 wpabuf_free(wpa_s
->last_assoc_req_wpa_ie
);
1792 wpa_s
->last_assoc_req_wpa_ie
= NULL
;
1794 wpa_s
->last_assoc_req_wpa_ie
=
1795 wpabuf_alloc_copy(params
.wpa_ie
, params
.wpa_ie_len
);
1796 #endif /* CONFIG_TESTING_OPTIONS */
1800 int sme_update_ft_ies(struct wpa_supplicant
*wpa_s
, const u8
*md
,
1801 const u8
*ies
, size_t ies_len
)
1803 if (md
== NULL
|| ies
== NULL
) {
1804 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Remove mobility domain");
1805 os_free(wpa_s
->sme
.ft_ies
);
1806 wpa_s
->sme
.ft_ies
= NULL
;
1807 wpa_s
->sme
.ft_ies_len
= 0;
1808 wpa_s
->sme
.ft_used
= 0;
1812 os_memcpy(wpa_s
->sme
.mobility_domain
, md
, MOBILITY_DOMAIN_ID_LEN
);
1813 wpa_hexdump(MSG_DEBUG
, "SME: FT IEs", ies
, ies_len
);
1814 os_free(wpa_s
->sme
.ft_ies
);
1815 wpa_s
->sme
.ft_ies
= os_memdup(ies
, ies_len
);
1816 if (wpa_s
->sme
.ft_ies
== NULL
)
1818 wpa_s
->sme
.ft_ies_len
= ies_len
;
1823 static void sme_deauth(struct wpa_supplicant
*wpa_s
)
1827 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
1829 if (wpa_drv_deauthenticate(wpa_s
, wpa_s
->pending_bssid
,
1830 WLAN_REASON_DEAUTH_LEAVING
) < 0) {
1831 wpa_msg(wpa_s
, MSG_INFO
, "SME: Deauth request to the driver "
1834 wpa_s
->sme
.prev_bssid_set
= 0;
1836 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1837 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1838 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
1839 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1841 wpas_notify_bssid_changed(wpa_s
);
1845 void sme_event_assoc_reject(struct wpa_supplicant
*wpa_s
,
1846 union wpa_event_data
*data
)
1848 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association with " MACSTR
" failed: "
1849 "status code %d", MAC2STR(wpa_s
->pending_bssid
),
1850 data
->assoc_reject
.status_code
);
1852 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
1855 if (wpa_s
->sme
.sae_pmksa_caching
&& wpa_s
->current_ssid
&&
1856 wpa_key_mgmt_sae(wpa_s
->current_ssid
->key_mgmt
)) {
1857 wpa_dbg(wpa_s
, MSG_DEBUG
,
1858 "PMKSA caching attempt rejected - drop PMKSA cache entry and fall back to SAE authentication");
1859 wpa_sm_aborted_cached(wpa_s
->wpa
);
1860 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
1861 if (wpa_s
->current_bss
) {
1862 struct wpa_bss
*bss
= wpa_s
->current_bss
;
1863 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1865 wpa_drv_deauthenticate(wpa_s
, wpa_s
->pending_bssid
,
1866 WLAN_REASON_DEAUTH_LEAVING
);
1867 wpas_connect_work_done(wpa_s
);
1868 wpa_supplicant_mark_disassoc(wpa_s
);
1869 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
1873 #endif /* CONFIG_SAE */
1876 * For now, unconditionally terminate the previous authentication. In
1877 * theory, this should not be needed, but mac80211 gets quite confused
1878 * if the authentication is left pending.. Some roaming cases might
1879 * benefit from using the previous authentication, so this could be
1880 * optimized in the future.
1886 void sme_event_auth_timed_out(struct wpa_supplicant
*wpa_s
,
1887 union wpa_event_data
*data
)
1889 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Authentication timed out");
1890 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1891 wpa_supplicant_mark_disassoc(wpa_s
);
1895 void sme_event_assoc_timed_out(struct wpa_supplicant
*wpa_s
,
1896 union wpa_event_data
*data
)
1898 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association timed out");
1899 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1900 wpa_supplicant_mark_disassoc(wpa_s
);
1904 void sme_event_disassoc(struct wpa_supplicant
*wpa_s
,
1905 struct disassoc_info
*info
)
1907 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Disassociation event received");
1908 if (wpa_s
->sme
.prev_bssid_set
) {
1910 * cfg80211/mac80211 can get into somewhat confused state if
1911 * the AP only disassociates us and leaves us in authenticated
1912 * state. For now, force the state to be cleared to avoid
1913 * confusing errors if we try to associate with the AP again.
1915 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Deauthenticate to clear "
1917 wpa_drv_deauthenticate(wpa_s
, wpa_s
->sme
.prev_bssid
,
1918 WLAN_REASON_DEAUTH_LEAVING
);
1923 static void sme_auth_timer(void *eloop_ctx
, void *timeout_ctx
)
1925 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1926 if (wpa_s
->wpa_state
== WPA_AUTHENTICATING
) {
1927 wpa_msg(wpa_s
, MSG_DEBUG
, "SME: Authentication timeout");
1933 static void sme_assoc_timer(void *eloop_ctx
, void *timeout_ctx
)
1935 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1936 if (wpa_s
->wpa_state
== WPA_ASSOCIATING
) {
1937 wpa_msg(wpa_s
, MSG_DEBUG
, "SME: Association timeout");
1943 void sme_state_changed(struct wpa_supplicant
*wpa_s
)
1945 /* Make sure timers are cleaned up appropriately. */
1946 if (wpa_s
->wpa_state
!= WPA_ASSOCIATING
)
1947 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
1948 if (wpa_s
->wpa_state
!= WPA_AUTHENTICATING
)
1949 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1953 void sme_disassoc_while_authenticating(struct wpa_supplicant
*wpa_s
,
1954 const u8
*prev_pending_bssid
)
1957 * mac80211-workaround to force deauth on failed auth cmd,
1958 * requires us to remain in authenticating state to allow the
1959 * second authentication attempt to be continued properly.
1961 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Allow pending authentication "
1962 "to proceed after disconnection event");
1963 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
1964 os_memcpy(wpa_s
->pending_bssid
, prev_pending_bssid
, ETH_ALEN
);
1967 * Re-arm authentication timer in case auth fails for whatever reason.
1969 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1970 eloop_register_timeout(SME_AUTH_TIMEOUT
, 0, sme_auth_timer
, wpa_s
,
1975 void sme_clear_on_disassoc(struct wpa_supplicant
*wpa_s
)
1977 wpa_s
->sme
.prev_bssid_set
= 0;
1979 wpabuf_free(wpa_s
->sme
.sae_token
);
1980 wpa_s
->sme
.sae_token
= NULL
;
1981 sae_clear_data(&wpa_s
->sme
.sae
);
1982 #endif /* CONFIG_SAE */
1983 #ifdef CONFIG_IEEE80211R
1984 if (wpa_s
->sme
.ft_ies
|| wpa_s
->sme
.ft_used
)
1985 sme_update_ft_ies(wpa_s
, NULL
, NULL
, 0);
1986 #endif /* CONFIG_IEEE80211R */
1990 void sme_deinit(struct wpa_supplicant
*wpa_s
)
1992 os_free(wpa_s
->sme
.ft_ies
);
1993 wpa_s
->sme
.ft_ies
= NULL
;
1994 wpa_s
->sme
.ft_ies_len
= 0;
1995 #ifdef CONFIG_IEEE80211W
1996 sme_stop_sa_query(wpa_s
);
1997 #endif /* CONFIG_IEEE80211W */
1998 sme_clear_on_disassoc(wpa_s
);
2000 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
2001 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
2002 eloop_cancel_timeout(sme_obss_scan_timeout
, wpa_s
, NULL
);
2006 static void sme_send_2040_bss_coex(struct wpa_supplicant
*wpa_s
,
2007 const u8
*chan_list
, u8 num_channels
,
2010 struct ieee80211_2040_bss_coex_ie
*bc_ie
;
2011 struct ieee80211_2040_intol_chan_report
*ic_report
;
2014 wpa_printf(MSG_DEBUG
, "SME: Send 20/40 BSS Coexistence to " MACSTR
2015 " (num_channels=%u num_intol=%u)",
2016 MAC2STR(wpa_s
->bssid
), num_channels
, num_intol
);
2017 wpa_hexdump(MSG_DEBUG
, "SME: 20/40 BSS Intolerant Channels",
2018 chan_list
, num_channels
);
2020 buf
= wpabuf_alloc(2 + /* action.category + action_code */
2021 sizeof(struct ieee80211_2040_bss_coex_ie
) +
2022 sizeof(struct ieee80211_2040_intol_chan_report
) +
2027 wpabuf_put_u8(buf
, WLAN_ACTION_PUBLIC
);
2028 wpabuf_put_u8(buf
, WLAN_PA_20_40_BSS_COEX
);
2030 bc_ie
= wpabuf_put(buf
, sizeof(*bc_ie
));
2031 bc_ie
->element_id
= WLAN_EID_20_40_BSS_COEXISTENCE
;
2034 bc_ie
->coex_param
|= WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ
;
2036 if (num_channels
> 0) {
2037 ic_report
= wpabuf_put(buf
, sizeof(*ic_report
));
2038 ic_report
->element_id
= WLAN_EID_20_40_BSS_INTOLERANT
;
2039 ic_report
->length
= num_channels
+ 1;
2040 ic_report
->op_class
= 0;
2041 os_memcpy(wpabuf_put(buf
, num_channels
), chan_list
,
2045 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
2046 wpa_s
->own_addr
, wpa_s
->bssid
,
2047 wpabuf_head(buf
), wpabuf_len(buf
), 0) < 0) {
2048 wpa_msg(wpa_s
, MSG_INFO
,
2049 "SME: Failed to send 20/40 BSS Coexistence frame");
2056 int sme_proc_obss_scan(struct wpa_supplicant
*wpa_s
)
2058 struct wpa_bss
*bss
;
2061 u8 chan_list
[P2P_MAX_CHANNELS
], channel
;
2062 u8 num_channels
= 0, num_intol
= 0, i
;
2064 if (!wpa_s
->sme
.sched_obss_scan
)
2067 wpa_s
->sme
.sched_obss_scan
= 0;
2068 if (!wpa_s
->current_bss
|| wpa_s
->wpa_state
!= WPA_COMPLETED
)
2072 * Check whether AP uses regulatory triplet or channel triplet in
2073 * country info. Right now the operating class of the BSS channel
2074 * width trigger event is "unknown" (IEEE Std 802.11-2012 10.15.12),
2075 * based on the assumption that operating class triplet is not used in
2076 * beacon frame. If the First Channel Number/Operating Extension
2077 * Identifier octet has a positive integer value of 201 or greater,
2078 * then its operating class triplet.
2080 * TODO: If Supported Operating Classes element is present in beacon
2081 * frame, have to lookup operating class in Annex E and fill them in
2084 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_COUNTRY
);
2085 if (ie
&& (ie
[1] >= 6) && (ie
[5] >= 201))
2088 os_memset(chan_list
, 0, sizeof(chan_list
));
2090 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
2091 /* Skip other band bss */
2092 enum hostapd_hw_mode mode
;
2093 mode
= ieee80211_freq_to_chan(bss
->freq
, &channel
);
2094 if (mode
!= HOSTAPD_MODE_IEEE80211G
&&
2095 mode
!= HOSTAPD_MODE_IEEE80211B
)
2098 ie
= wpa_bss_get_ie(bss
, WLAN_EID_HT_CAP
);
2099 ht_cap
= (ie
&& (ie
[1] == 26)) ? WPA_GET_LE16(ie
+ 2) : 0;
2100 wpa_printf(MSG_DEBUG
, "SME OBSS scan BSS " MACSTR
2101 " freq=%u chan=%u ht_cap=0x%x",
2102 MAC2STR(bss
->bssid
), bss
->freq
, channel
, ht_cap
);
2104 if (!ht_cap
|| (ht_cap
& HT_CAP_INFO_40MHZ_INTOLERANT
)) {
2105 if (ht_cap
& HT_CAP_INFO_40MHZ_INTOLERANT
)
2108 /* Check whether the channel is already considered */
2109 for (i
= 0; i
< num_channels
; i
++) {
2110 if (channel
== chan_list
[i
])
2113 if (i
!= num_channels
)
2116 chan_list
[num_channels
++] = channel
;
2120 sme_send_2040_bss_coex(wpa_s
, chan_list
, num_channels
, num_intol
);
2125 static void wpa_obss_scan_freqs_list(struct wpa_supplicant
*wpa_s
,
2126 struct wpa_driver_scan_params
*params
)
2128 /* Include only affected channels */
2129 struct hostapd_hw_modes
*mode
;
2133 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
,
2134 HOSTAPD_MODE_IEEE80211G
);
2136 /* No channels supported in this band - use empty list */
2137 params
->freqs
= os_zalloc(sizeof(int));
2141 if (wpa_s
->sme
.ht_sec_chan
== HT_SEC_CHAN_UNKNOWN
&&
2142 wpa_s
->current_bss
) {
2145 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_HT_OPERATION
);
2146 if (ie
&& ie
[1] >= 2) {
2149 o
= ie
[3] & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK
;
2150 if (o
== HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE
)
2151 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_ABOVE
;
2152 else if (o
== HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW
)
2153 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_BELOW
;
2157 start
= wpa_s
->assoc_freq
- 10;
2158 end
= wpa_s
->assoc_freq
+ 10;
2159 switch (wpa_s
->sme
.ht_sec_chan
) {
2160 case HT_SEC_CHAN_UNKNOWN
:
2161 /* HT40+ possible on channels 1..9 */
2162 if (wpa_s
->assoc_freq
<= 2452)
2164 /* HT40- possible on channels 5-13 */
2165 if (wpa_s
->assoc_freq
>= 2432)
2168 case HT_SEC_CHAN_ABOVE
:
2171 case HT_SEC_CHAN_BELOW
:
2175 wpa_printf(MSG_DEBUG
,
2176 "OBSS: assoc_freq %d possible affected range %d-%d",
2177 wpa_s
->assoc_freq
, start
, end
);
2179 params
->freqs
= os_calloc(mode
->num_channels
+ 1, sizeof(int));
2180 if (params
->freqs
== NULL
)
2182 for (count
= 0, i
= 0; i
< mode
->num_channels
; i
++) {
2185 if (mode
->channels
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
2187 freq
= mode
->channels
[i
].freq
;
2188 if (freq
- 10 >= end
|| freq
+ 10 <= start
)
2189 continue; /* not affected */
2190 params
->freqs
[count
++] = freq
;
2195 static void sme_obss_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
2197 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2198 struct wpa_driver_scan_params params
;
2200 if (!wpa_s
->current_bss
) {
2201 wpa_printf(MSG_DEBUG
, "SME OBSS: Ignore scan request");
2205 os_memset(¶ms
, 0, sizeof(params
));
2206 wpa_obss_scan_freqs_list(wpa_s
, ¶ms
);
2207 params
.low_priority
= 1;
2208 wpa_printf(MSG_DEBUG
, "SME OBSS: Request an OBSS scan");
2210 if (wpa_supplicant_trigger_scan(wpa_s
, ¶ms
))
2211 wpa_printf(MSG_DEBUG
, "SME OBSS: Failed to trigger scan");
2213 wpa_s
->sme
.sched_obss_scan
= 1;
2214 os_free(params
.freqs
);
2216 eloop_register_timeout(wpa_s
->sme
.obss_scan_int
, 0,
2217 sme_obss_scan_timeout
, wpa_s
, NULL
);
2221 void sme_sched_obss_scan(struct wpa_supplicant
*wpa_s
, int enable
)
2224 struct wpa_bss
*bss
= wpa_s
->current_bss
;
2225 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2226 struct hostapd_hw_modes
*hw_mode
= NULL
;
2229 eloop_cancel_timeout(sme_obss_scan_timeout
, wpa_s
, NULL
);
2230 wpa_s
->sme
.sched_obss_scan
= 0;
2231 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_UNKNOWN
;
2236 * Schedule OBSS scan if driver is using station SME in wpa_supplicant
2237 * or it expects OBSS scan to be performed by wpa_supplicant.
2239 if (!((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) ||
2240 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OBSS_SCAN
)) ||
2241 ssid
== NULL
|| ssid
->mode
!= IEEE80211_MODE_INFRA
)
2244 if (!wpa_s
->hw
.modes
)
2247 /* only HT caps in 11g mode are relevant */
2248 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
2249 hw_mode
= &wpa_s
->hw
.modes
[i
];
2250 if (hw_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
2254 /* Driver does not support HT40 for 11g or doesn't have 11g. */
2255 if (i
== wpa_s
->hw
.num_modes
|| !hw_mode
||
2256 !(hw_mode
->ht_capab
& HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
2259 if (bss
== NULL
|| bss
->freq
< 2400 || bss
->freq
> 2500)
2260 return; /* Not associated on 2.4 GHz band */
2262 /* Check whether AP supports HT40 */
2263 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_HT_CAP
);
2264 if (!ie
|| ie
[1] < 2 ||
2265 !(WPA_GET_LE16(ie
+ 2) & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
2266 return; /* AP does not support HT40 */
2268 ie
= wpa_bss_get_ie(wpa_s
->current_bss
,
2269 WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS
);
2270 if (!ie
|| ie
[1] < 14)
2271 return; /* AP does not request OBSS scans */
2273 wpa_s
->sme
.obss_scan_int
= WPA_GET_LE16(ie
+ 6);
2274 if (wpa_s
->sme
.obss_scan_int
< 10) {
2275 wpa_printf(MSG_DEBUG
, "SME: Invalid OBSS Scan Interval %u "
2276 "replaced with the minimum 10 sec",
2277 wpa_s
->sme
.obss_scan_int
);
2278 wpa_s
->sme
.obss_scan_int
= 10;
2280 wpa_printf(MSG_DEBUG
, "SME: OBSS Scan Interval %u sec",
2281 wpa_s
->sme
.obss_scan_int
);
2282 eloop_register_timeout(wpa_s
->sme
.obss_scan_int
, 0,
2283 sme_obss_scan_timeout
, wpa_s
, NULL
);
2287 #ifdef CONFIG_IEEE80211W
2289 static const unsigned int sa_query_max_timeout
= 1000;
2290 static const unsigned int sa_query_retry_timeout
= 201;
2291 static const unsigned int sa_query_ch_switch_max_delay
= 5000; /* in usec */
2293 static int sme_check_sa_query_timeout(struct wpa_supplicant
*wpa_s
)
2296 struct os_reltime now
, passed
;
2297 os_get_reltime(&now
);
2298 os_reltime_sub(&now
, &wpa_s
->sme
.sa_query_start
, &passed
);
2299 tu
= (passed
.sec
* 1000000 + passed
.usec
) / 1024;
2300 if (sa_query_max_timeout
< tu
) {
2301 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SA Query timed out");
2302 sme_stop_sa_query(wpa_s
);
2303 wpa_supplicant_deauthenticate(
2304 wpa_s
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
2312 static void sme_send_sa_query_req(struct wpa_supplicant
*wpa_s
,
2315 u8 req
[2 + WLAN_SA_QUERY_TR_ID_LEN
+ OCV_OCI_EXTENDED_LEN
];
2316 u8 req_len
= 2 + WLAN_SA_QUERY_TR_ID_LEN
;
2318 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Sending SA Query Request to "
2319 MACSTR
, MAC2STR(wpa_s
->bssid
));
2320 wpa_hexdump(MSG_DEBUG
, "SME: SA Query Transaction ID",
2321 trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
2322 req
[0] = WLAN_ACTION_SA_QUERY
;
2323 req
[1] = WLAN_SA_QUERY_REQUEST
;
2324 os_memcpy(req
+ 2, trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
2327 if (wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
2328 struct wpa_channel_info ci
;
2330 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
2331 wpa_printf(MSG_WARNING
,
2332 "Failed to get channel info for OCI element in SA Query Request frame");
2336 if (ocv_insert_extended_oci(&ci
, req
+ req_len
) < 0)
2339 req_len
+= OCV_OCI_EXTENDED_LEN
;
2341 #endif /* CONFIG_OCV */
2343 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
2344 wpa_s
->own_addr
, wpa_s
->bssid
,
2345 req
, req_len
, 0) < 0)
2346 wpa_msg(wpa_s
, MSG_INFO
, "SME: Failed to send SA Query "
2351 static void sme_sa_query_timer(void *eloop_ctx
, void *timeout_ctx
)
2353 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2354 unsigned int timeout
, sec
, usec
;
2355 u8
*trans_id
, *nbuf
;
2357 if (wpa_s
->sme
.sa_query_count
> 0 &&
2358 sme_check_sa_query_timeout(wpa_s
))
2361 nbuf
= os_realloc_array(wpa_s
->sme
.sa_query_trans_id
,
2362 wpa_s
->sme
.sa_query_count
+ 1,
2363 WLAN_SA_QUERY_TR_ID_LEN
);
2365 sme_stop_sa_query(wpa_s
);
2368 if (wpa_s
->sme
.sa_query_count
== 0) {
2369 /* Starting a new SA Query procedure */
2370 os_get_reltime(&wpa_s
->sme
.sa_query_start
);
2372 trans_id
= nbuf
+ wpa_s
->sme
.sa_query_count
* WLAN_SA_QUERY_TR_ID_LEN
;
2373 wpa_s
->sme
.sa_query_trans_id
= nbuf
;
2374 wpa_s
->sme
.sa_query_count
++;
2376 if (os_get_random(trans_id
, WLAN_SA_QUERY_TR_ID_LEN
) < 0) {
2377 wpa_printf(MSG_DEBUG
, "Could not generate SA Query ID");
2378 sme_stop_sa_query(wpa_s
);
2382 timeout
= sa_query_retry_timeout
;
2383 sec
= ((timeout
/ 1000) * 1024) / 1000;
2384 usec
= (timeout
% 1000) * 1024;
2385 eloop_register_timeout(sec
, usec
, sme_sa_query_timer
, wpa_s
, NULL
);
2387 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association SA Query attempt %d",
2388 wpa_s
->sme
.sa_query_count
);
2390 sme_send_sa_query_req(wpa_s
, trans_id
);
2394 static void sme_start_sa_query(struct wpa_supplicant
*wpa_s
)
2396 sme_sa_query_timer(wpa_s
, NULL
);
2400 static void sme_stop_sa_query(struct wpa_supplicant
*wpa_s
)
2402 eloop_cancel_timeout(sme_sa_query_timer
, wpa_s
, NULL
);
2403 os_free(wpa_s
->sme
.sa_query_trans_id
);
2404 wpa_s
->sme
.sa_query_trans_id
= NULL
;
2405 wpa_s
->sme
.sa_query_count
= 0;
2409 void sme_event_unprot_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*sa
,
2410 const u8
*da
, u16 reason_code
)
2412 struct wpa_ssid
*ssid
;
2413 struct os_reltime now
;
2415 if (wpa_s
->wpa_state
!= WPA_COMPLETED
)
2417 ssid
= wpa_s
->current_ssid
;
2418 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == NO_MGMT_FRAME_PROTECTION
)
2420 if (os_memcmp(sa
, wpa_s
->bssid
, ETH_ALEN
) != 0)
2422 if (reason_code
!= WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
&&
2423 reason_code
!= WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
)
2425 if (wpa_s
->sme
.sa_query_count
> 0)
2428 os_get_reltime(&now
);
2429 if (wpa_s
->sme
.last_unprot_disconnect
.sec
&&
2430 !os_reltime_expired(&now
, &wpa_s
->sme
.last_unprot_disconnect
, 10))
2431 return; /* limit SA Query procedure frequency */
2432 wpa_s
->sme
.last_unprot_disconnect
= now
;
2434 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Unprotected disconnect dropped - "
2435 "possible AP/STA state mismatch - trigger SA Query");
2436 sme_start_sa_query(wpa_s
);
2440 void sme_event_ch_switch(struct wpa_supplicant
*wpa_s
)
2445 if (wpa_s
->wpa_state
!= WPA_COMPLETED
||
2446 !wpa_sm_ocv_enabled(wpa_s
->wpa
))
2449 wpa_dbg(wpa_s
, MSG_DEBUG
,
2450 "SME: Channel switch completed - trigger new SA Query to verify new operating channel");
2451 sme_stop_sa_query(wpa_s
);
2453 if (os_get_random((u8
*) &_rand
, sizeof(_rand
)) < 0)
2454 _rand
= os_random();
2455 usec
= _rand
% (sa_query_ch_switch_max_delay
+ 1);
2456 eloop_register_timeout(0, usec
, sme_sa_query_timer
, wpa_s
, NULL
);
2460 static void sme_process_sa_query_request(struct wpa_supplicant
*wpa_s
,
2461 const u8
*sa
, const u8
*data
,
2464 u8 resp
[2 + WLAN_SA_QUERY_TR_ID_LEN
+ OCV_OCI_EXTENDED_LEN
];
2465 u8 resp_len
= 2 + WLAN_SA_QUERY_TR_ID_LEN
;
2467 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Sending SA Query Response to "
2468 MACSTR
, MAC2STR(wpa_s
->bssid
));
2470 resp
[0] = WLAN_ACTION_SA_QUERY
;
2471 resp
[1] = WLAN_SA_QUERY_RESPONSE
;
2472 os_memcpy(resp
+ 2, data
+ 1, WLAN_SA_QUERY_TR_ID_LEN
);
2475 if (wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
2476 struct wpa_channel_info ci
;
2478 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
2479 wpa_printf(MSG_WARNING
,
2480 "Failed to get channel info for OCI element in SA Query Response frame");
2484 if (ocv_insert_extended_oci(&ci
, resp
+ resp_len
) < 0)
2487 resp_len
+= OCV_OCI_EXTENDED_LEN
;
2489 #endif /* CONFIG_OCV */
2491 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
2492 wpa_s
->own_addr
, wpa_s
->bssid
,
2493 resp
, resp_len
, 0) < 0)
2494 wpa_msg(wpa_s
, MSG_INFO
,
2495 "SME: Failed to send SA Query Response");
2499 static void sme_process_sa_query_response(struct wpa_supplicant
*wpa_s
,
2500 const u8
*sa
, const u8
*data
,
2505 if (!wpa_s
->sme
.sa_query_trans_id
)
2508 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Received SA Query response from "
2509 MACSTR
" (trans_id %02x%02x)", MAC2STR(sa
), data
[1], data
[2]);
2511 if (os_memcmp(sa
, wpa_s
->bssid
, ETH_ALEN
) != 0)
2514 for (i
= 0; i
< wpa_s
->sme
.sa_query_count
; i
++) {
2515 if (os_memcmp(wpa_s
->sme
.sa_query_trans_id
+
2516 i
* WLAN_SA_QUERY_TR_ID_LEN
,
2517 data
+ 1, WLAN_SA_QUERY_TR_ID_LEN
) == 0)
2521 if (i
>= wpa_s
->sme
.sa_query_count
) {
2522 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: No matching SA Query "
2523 "transaction identifier found");
2527 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Reply to pending SA Query received "
2528 "from " MACSTR
, MAC2STR(sa
));
2529 sme_stop_sa_query(wpa_s
);
2533 void sme_sa_query_rx(struct wpa_supplicant
*wpa_s
, const u8
*sa
,
2534 const u8
*data
, size_t len
)
2536 if (len
< 1 + WLAN_SA_QUERY_TR_ID_LEN
)
2539 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Received SA Query frame from "
2540 MACSTR
" (trans_id %02x%02x)", MAC2STR(sa
), data
[1], data
[2]);
2543 if (wpa_sm_ocv_enabled(wpa_s
->wpa
)) {
2544 struct ieee802_11_elems elems
;
2545 struct wpa_channel_info ci
;
2547 if (ieee802_11_parse_elems(data
+ 1 + WLAN_SA_QUERY_TR_ID_LEN
,
2548 len
- 1 - WLAN_SA_QUERY_TR_ID_LEN
,
2549 &elems
, 1) == ParseFailed
) {
2550 wpa_printf(MSG_DEBUG
,
2551 "SA Query: Failed to parse elements");
2555 if (wpa_drv_channel_info(wpa_s
, &ci
) != 0) {
2556 wpa_printf(MSG_WARNING
,
2557 "Failed to get channel info to validate received OCI in SA Query Action frame");
2561 if (ocv_verify_tx_params(elems
.oci
, elems
.oci_len
, &ci
,
2562 channel_width_to_int(ci
.chanwidth
),
2563 ci
.seg1_idx
) != 0) {
2564 wpa_printf(MSG_WARNING
, "%s", ocv_errorstr
);
2568 #endif /* CONFIG_OCV */
2570 if (data
[0] == WLAN_SA_QUERY_REQUEST
)
2571 sme_process_sa_query_request(wpa_s
, sa
, data
, len
);
2572 else if (data
[0] == WLAN_SA_QUERY_RESPONSE
)
2573 sme_process_sa_query_response(wpa_s
, sa
, data
, len
);
2576 #endif /* CONFIG_IEEE80211W */