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 "eapol_supp/eapol_supp_sm.h"
16 #include "common/wpa_common.h"
17 #include "common/sae.h"
18 #include "rsn_supp/wpa.h"
19 #include "rsn_supp/pmksa_cache.h"
21 #include "wpa_supplicant_i.h"
23 #include "wpas_glue.h"
24 #include "wps_supplicant.h"
25 #include "p2p_supplicant.h"
30 #include "hs20_supplicant.h"
32 #define SME_AUTH_TIMEOUT 5
33 #define SME_ASSOC_TIMEOUT 5
35 static void sme_auth_timer(void *eloop_ctx
, void *timeout_ctx
);
36 static void sme_assoc_timer(void *eloop_ctx
, void *timeout_ctx
);
37 static void sme_obss_scan_timeout(void *eloop_ctx
, void *timeout_ctx
);
38 #ifdef CONFIG_IEEE80211W
39 static void sme_stop_sa_query(struct wpa_supplicant
*wpa_s
);
40 #endif /* CONFIG_IEEE80211W */
45 static int index_within_array(const int *array
, int idx
)
48 for (i
= 0; i
< idx
; i
++) {
56 static int sme_set_sae_group(struct wpa_supplicant
*wpa_s
)
58 int *groups
= wpa_s
->conf
->sae_groups
;
59 int default_groups
[] = { 19, 20, 21, 25, 26, 0 };
61 if (!groups
|| groups
[0] <= 0)
62 groups
= default_groups
;
64 /* Configuration may have changed, so validate current index */
65 if (!index_within_array(groups
, wpa_s
->sme
.sae_group_index
))
69 int group
= groups
[wpa_s
->sme
.sae_group_index
];
72 if (sae_set_group(&wpa_s
->sme
.sae
, group
) == 0) {
73 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Selected SAE group %d",
74 wpa_s
->sme
.sae
.group
);
77 wpa_s
->sme
.sae_group_index
++;
84 static struct wpabuf
* sme_auth_build_sae_commit(struct wpa_supplicant
*wpa_s
,
85 struct wpa_ssid
*ssid
,
91 #ifdef CONFIG_TESTING_OPTIONS
92 if (wpa_s
->sae_commit_override
) {
93 wpa_printf(MSG_DEBUG
, "SAE: TESTING - commit override");
94 buf
= wpabuf_alloc(4 + wpabuf_len(wpa_s
->sae_commit_override
));
97 wpabuf_put_le16(buf
, 1); /* Transaction seq# */
98 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
99 wpabuf_put_buf(buf
, wpa_s
->sae_commit_override
);
102 #endif /* CONFIG_TESTING_OPTIONS */
104 if (ssid
->passphrase
== NULL
) {
105 wpa_printf(MSG_DEBUG
, "SAE: No password available");
109 if (sme_set_sae_group(wpa_s
) < 0) {
110 wpa_printf(MSG_DEBUG
, "SAE: Failed to select group");
114 if (sae_prepare_commit(wpa_s
->own_addr
, bssid
,
115 (u8
*) ssid
->passphrase
,
116 os_strlen(ssid
->passphrase
),
117 &wpa_s
->sme
.sae
) < 0) {
118 wpa_printf(MSG_DEBUG
, "SAE: Could not pick PWE");
122 len
= wpa_s
->sme
.sae_token
? wpabuf_len(wpa_s
->sme
.sae_token
) : 0;
123 buf
= wpabuf_alloc(4 + SAE_COMMIT_MAX_LEN
+ len
);
127 wpabuf_put_le16(buf
, 1); /* Transaction seq# */
128 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
129 sae_write_commit(&wpa_s
->sme
.sae
, buf
, wpa_s
->sme
.sae_token
);
135 static struct wpabuf
* sme_auth_build_sae_confirm(struct wpa_supplicant
*wpa_s
)
139 buf
= wpabuf_alloc(4 + SAE_CONFIRM_MAX_LEN
);
143 wpabuf_put_le16(buf
, 2); /* Transaction seq# */
144 wpabuf_put_le16(buf
, WLAN_STATUS_SUCCESS
);
145 sae_write_confirm(&wpa_s
->sme
.sae
, buf
);
150 #endif /* CONFIG_SAE */
154 * sme_auth_handle_rrm - Handle RRM aspects of current authentication attempt
155 * @wpa_s: Pointer to wpa_supplicant data
156 * @bss: Pointer to the bss which is the target of authentication attempt
158 static void sme_auth_handle_rrm(struct wpa_supplicant
*wpa_s
,
161 const u8 rrm_ie_len
= 5;
165 wpa_s
->rrm
.rrm_used
= 0;
167 wpa_printf(MSG_DEBUG
,
168 "RRM: Determining whether RRM can be used - device support: 0x%x",
169 wpa_s
->drv_rrm_flags
);
171 rrm_ie
= wpa_bss_get_ie(bss
, WLAN_EID_RRM_ENABLED_CAPABILITIES
);
172 if (!rrm_ie
|| !(bss
->caps
& IEEE80211_CAP_RRM
)) {
173 wpa_printf(MSG_DEBUG
, "RRM: No RRM in network");
177 if (!((wpa_s
->drv_rrm_flags
&
178 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES
) &&
179 (wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_QUIET
)) &&
180 !(wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_SUPPORT_RRM
)) {
181 wpa_printf(MSG_DEBUG
,
182 "RRM: Insufficient RRM support in driver - do not use RRM");
186 if (sizeof(wpa_s
->sme
.assoc_req_ie
) <
187 wpa_s
->sme
.assoc_req_ie_len
+ rrm_ie_len
+ 2) {
189 "RRM: Unable to use RRM, no room for RRM IE");
193 wpa_printf(MSG_DEBUG
, "RRM: Adding RRM IE to Association Request");
194 pos
= wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
;
195 os_memset(pos
, 0, 2 + rrm_ie_len
);
196 *pos
++ = WLAN_EID_RRM_ENABLED_CAPABILITIES
;
199 /* Set supported capabilites flags */
200 if (wpa_s
->drv_rrm_flags
& WPA_DRIVER_FLAGS_TX_POWER_INSERTION
)
201 *pos
|= WLAN_RRM_CAPS_LINK_MEASUREMENT
;
203 *pos
|= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE
|
204 WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE
|
205 WLAN_RRM_CAPS_BEACON_REPORT_TABLE
;
208 pos
[1] |= WLAN_RRM_CAPS_LCI_MEASUREMENT
;
210 wpa_s
->sme
.assoc_req_ie_len
+= rrm_ie_len
+ 2;
211 wpa_s
->rrm
.rrm_used
= 1;
215 static void sme_send_authentication(struct wpa_supplicant
*wpa_s
,
216 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
,
219 struct wpa_driver_auth_params params
;
220 struct wpa_ssid
*old_ssid
;
221 #ifdef CONFIG_IEEE80211R
223 #endif /* CONFIG_IEEE80211R */
224 #if defined(CONFIG_IEEE80211R) || defined(CONFIG_FILS)
226 #endif /* CONFIG_IEEE80211R || CONFIG_FILS */
227 int i
, bssid_changed
;
228 struct wpabuf
*resp
= NULL
;
234 wpa_msg(wpa_s
, MSG_ERROR
, "SME: No scan result available for "
236 wpas_connect_work_done(wpa_s
);
240 skip_auth
= wpa_s
->conf
->reassoc_same_bss_optim
&&
241 wpa_s
->reassoc_same_bss
;
242 wpa_s
->current_bss
= bss
;
244 os_memset(¶ms
, 0, sizeof(params
));
245 wpa_s
->reassociate
= 0;
247 params
.freq
= bss
->freq
;
248 params
.bssid
= bss
->bssid
;
249 params
.ssid
= bss
->ssid
;
250 params
.ssid_len
= bss
->ssid_len
;
251 params
.p2p
= ssid
->p2p_group
;
253 if (wpa_s
->sme
.ssid_len
!= params
.ssid_len
||
254 os_memcmp(wpa_s
->sme
.ssid
, params
.ssid
, params
.ssid_len
) != 0)
255 wpa_s
->sme
.prev_bssid_set
= 0;
257 wpa_s
->sme
.freq
= params
.freq
;
258 os_memcpy(wpa_s
->sme
.ssid
, params
.ssid
, params
.ssid_len
);
259 wpa_s
->sme
.ssid_len
= params
.ssid_len
;
261 params
.auth_alg
= WPA_AUTH_ALG_OPEN
;
262 #ifdef IEEE8021X_EAPOL
263 if (ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
265 if (ssid
->non_leap
== 0)
266 params
.auth_alg
= WPA_AUTH_ALG_LEAP
;
268 params
.auth_alg
|= WPA_AUTH_ALG_LEAP
;
271 #endif /* IEEE8021X_EAPOL */
272 wpa_dbg(wpa_s
, MSG_DEBUG
, "Automatic auth_alg selection: 0x%x",
274 if (ssid
->auth_alg
) {
275 params
.auth_alg
= ssid
->auth_alg
;
276 wpa_dbg(wpa_s
, MSG_DEBUG
, "Overriding auth_alg selection: "
277 "0x%x", params
.auth_alg
);
280 wpa_s
->sme
.sae_pmksa_caching
= 0;
281 if (wpa_key_mgmt_sae(ssid
->key_mgmt
)) {
283 struct wpa_ie_data ied
;
285 rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
287 wpa_dbg(wpa_s
, MSG_DEBUG
,
288 "SAE enabled, but target BSS does not advertise RSN");
289 } else if (wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &ied
) == 0 &&
290 wpa_key_mgmt_sae(ied
.key_mgmt
)) {
291 wpa_dbg(wpa_s
, MSG_DEBUG
, "Using SAE auth_alg");
292 params
.auth_alg
= WPA_AUTH_ALG_SAE
;
294 wpa_dbg(wpa_s
, MSG_DEBUG
,
295 "SAE enabled, but target BSS does not advertise SAE AKM for RSN");
298 #endif /* CONFIG_SAE */
300 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
301 if (ssid
->wep_key_len
[i
])
302 params
.wep_key
[i
] = ssid
->wep_key
[i
];
303 params
.wep_key_len
[i
] = ssid
->wep_key_len
[i
];
305 params
.wep_tx_keyidx
= ssid
->wep_tx_keyidx
;
307 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
308 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
309 os_memcpy(wpa_s
->pending_bssid
, bss
->bssid
, ETH_ALEN
);
311 wpas_notify_bssid_changed(wpa_s
);
313 if ((wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
) ||
314 wpa_bss_get_ie(bss
, WLAN_EID_RSN
)) &&
315 wpa_key_mgmt_wpa(ssid
->key_mgmt
)) {
316 int try_opportunistic
;
317 const u8
*cache_id
= NULL
;
319 try_opportunistic
= (ssid
->proactive_key_caching
< 0 ?
321 ssid
->proactive_key_caching
) &&
322 (ssid
->proto
& WPA_PROTO_RSN
);
324 if (wpa_key_mgmt_fils(ssid
->key_mgmt
))
325 cache_id
= wpa_bss_get_fils_cache_id(bss
);
326 #endif /* CONFIG_FILS */
327 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
329 try_opportunistic
, cache_id
) == 0)
330 eapol_sm_notify_pmkid_attempt(wpa_s
->eapol
);
331 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
332 if (wpa_supplicant_set_suites(wpa_s
, bss
, ssid
,
333 wpa_s
->sme
.assoc_req_ie
,
334 &wpa_s
->sme
.assoc_req_ie_len
)) {
335 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
336 "key management and encryption suites");
337 wpas_connect_work_done(wpa_s
);
340 } else if ((ssid
->key_mgmt
& WPA_KEY_MGMT_IEEE8021X_NO_WPA
) &&
341 wpa_key_mgmt_wpa_ieee8021x(ssid
->key_mgmt
)) {
343 * Both WPA and non-WPA IEEE 802.1X enabled in configuration -
344 * use non-WPA since the scan results did not indicate that the
345 * AP is using WPA or WPA2.
347 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
348 wpa_s
->sme
.assoc_req_ie_len
= 0;
349 } else if (wpa_key_mgmt_wpa_any(ssid
->key_mgmt
)) {
350 wpa_s
->sme
.assoc_req_ie_len
= sizeof(wpa_s
->sme
.assoc_req_ie
);
351 if (wpa_supplicant_set_suites(wpa_s
, NULL
, ssid
,
352 wpa_s
->sme
.assoc_req_ie
,
353 &wpa_s
->sme
.assoc_req_ie_len
)) {
354 wpa_msg(wpa_s
, MSG_WARNING
, "SME: Failed to set WPA "
355 "key management and encryption suites (no "
357 wpas_connect_work_done(wpa_s
);
361 } else if (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
) {
362 struct wpabuf
*wps_ie
;
363 wps_ie
= wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid
));
364 if (wps_ie
&& wpabuf_len(wps_ie
) <=
365 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
366 wpa_s
->sme
.assoc_req_ie_len
= wpabuf_len(wps_ie
);
367 os_memcpy(wpa_s
->sme
.assoc_req_ie
, wpabuf_head(wps_ie
),
368 wpa_s
->sme
.assoc_req_ie_len
);
370 wpa_s
->sme
.assoc_req_ie_len
= 0;
372 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
373 #endif /* CONFIG_WPS */
375 wpa_supplicant_set_non_wpa_policy(wpa_s
, ssid
);
376 wpa_s
->sme
.assoc_req_ie_len
= 0;
379 #ifdef CONFIG_IEEE80211R
380 ie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
381 if (ie
&& ie
[1] >= MOBILITY_DOMAIN_ID_LEN
)
383 wpa_sm_set_ft_params(wpa_s
->wpa
, ie
, ie
? 2 + ie
[1] : 0);
385 /* Prepare for the next transition */
386 wpa_ft_prepare_auth_request(wpa_s
->wpa
, ie
);
389 if (md
&& !wpa_key_mgmt_ft(ssid
->key_mgmt
))
392 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: FT mobility domain %02x%02x",
395 if (wpa_s
->sme
.assoc_req_ie_len
+ 5 <
396 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
397 struct rsn_mdie
*mdie
;
398 u8
*pos
= wpa_s
->sme
.assoc_req_ie
+
399 wpa_s
->sme
.assoc_req_ie_len
;
400 *pos
++ = WLAN_EID_MOBILITY_DOMAIN
;
401 *pos
++ = sizeof(*mdie
);
402 mdie
= (struct rsn_mdie
*) pos
;
403 os_memcpy(mdie
->mobility_domain
, md
,
404 MOBILITY_DOMAIN_ID_LEN
);
405 mdie
->ft_capab
= md
[MOBILITY_DOMAIN_ID_LEN
];
406 wpa_s
->sme
.assoc_req_ie_len
+= 5;
409 if (wpa_s
->sme
.ft_used
&&
410 os_memcmp(md
, wpa_s
->sme
.mobility_domain
, 2) == 0 &&
411 wpa_sm_has_ptk(wpa_s
->wpa
)) {
412 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying to use FT "
414 params
.auth_alg
= WPA_AUTH_ALG_FT
;
415 params
.ie
= wpa_s
->sme
.ft_ies
;
416 params
.ie_len
= wpa_s
->sme
.ft_ies_len
;
419 #endif /* CONFIG_IEEE80211R */
421 #ifdef CONFIG_IEEE80211W
422 wpa_s
->sme
.mfp
= wpas_get_ssid_pmf(wpa_s
, ssid
);
423 if (wpa_s
->sme
.mfp
!= NO_MGMT_FRAME_PROTECTION
) {
424 const u8
*rsn
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
425 struct wpa_ie_data _ie
;
426 if (rsn
&& wpa_parse_wpa_ie(rsn
, 2 + rsn
[1], &_ie
) == 0 &&
428 (WPA_CAPABILITY_MFPC
| WPA_CAPABILITY_MFPR
)) {
429 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Selected AP supports "
431 wpa_s
->sme
.mfp
= MGMT_FRAME_PROTECTION_REQUIRED
;
434 #endif /* CONFIG_IEEE80211W */
437 if (wpa_s
->global
->p2p
) {
441 pos
= wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
;
442 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
443 wpa_s
->sme
.assoc_req_ie_len
;
444 res
= wpas_p2p_assoc_req_ie(wpa_s
, bss
, pos
, len
,
447 wpa_s
->sme
.assoc_req_ie_len
+= res
;
449 #endif /* CONFIG_P2P */
452 if (wpa_s
->fst_ies
) {
453 int fst_ies_len
= wpabuf_len(wpa_s
->fst_ies
);
455 if (wpa_s
->sme
.assoc_req_ie_len
+ fst_ies_len
<=
456 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
457 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
458 wpa_s
->sme
.assoc_req_ie_len
,
459 wpabuf_head(wpa_s
->fst_ies
),
461 wpa_s
->sme
.assoc_req_ie_len
+= fst_ies_len
;
464 #endif /* CONFIG_FST */
466 sme_auth_handle_rrm(wpa_s
, bss
);
468 wpa_s
->sme
.assoc_req_ie_len
+= wpas_supp_op_class_ie(
470 wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
471 sizeof(wpa_s
->sme
.assoc_req_ie
) - wpa_s
->sme
.assoc_req_ie_len
);
474 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_P2P_CLIENT
);
476 wpa_drv_get_ext_capa(wpa_s
, WPA_IF_STATION
);
478 ext_capab_len
= wpas_build_ext_capab(wpa_s
, ext_capab
,
480 if (ext_capab_len
> 0) {
481 u8
*pos
= wpa_s
->sme
.assoc_req_ie
;
482 if (wpa_s
->sme
.assoc_req_ie_len
> 0 && pos
[0] == WLAN_EID_RSN
)
484 os_memmove(pos
+ ext_capab_len
, pos
,
485 wpa_s
->sme
.assoc_req_ie_len
-
486 (pos
- wpa_s
->sme
.assoc_req_ie
));
487 wpa_s
->sme
.assoc_req_ie_len
+= ext_capab_len
;
488 os_memcpy(pos
, ext_capab
, ext_capab_len
);
492 if (is_hs20_network(wpa_s
, ssid
, bss
)) {
495 hs20
= wpabuf_alloc(20);
497 int pps_mo_id
= hs20_get_pps_mo_id(wpa_s
, ssid
);
500 wpas_hs20_add_indication(hs20
, pps_mo_id
);
501 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
502 wpa_s
->sme
.assoc_req_ie_len
;
503 if (wpabuf_len(hs20
) <= len
) {
504 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
505 wpa_s
->sme
.assoc_req_ie_len
,
506 wpabuf_head(hs20
), wpabuf_len(hs20
));
507 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(hs20
);
512 #endif /* CONFIG_HS20 */
514 if (wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
]) {
515 struct wpabuf
*buf
= wpa_s
->vendor_elem
[VENDOR_ELEM_ASSOC_REQ
];
518 len
= sizeof(wpa_s
->sme
.assoc_req_ie
) -
519 wpa_s
->sme
.assoc_req_ie_len
;
520 if (wpabuf_len(buf
) <= len
) {
521 os_memcpy(wpa_s
->sme
.assoc_req_ie
+
522 wpa_s
->sme
.assoc_req_ie_len
,
523 wpabuf_head(buf
), wpabuf_len(buf
));
524 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(buf
);
529 if (wpa_bss_get_vendor_ie(bss
, MBO_IE_VENDOR_TYPE
)) {
532 len
= wpas_mbo_ie(wpa_s
, wpa_s
->sme
.assoc_req_ie
+
533 wpa_s
->sme
.assoc_req_ie_len
,
534 sizeof(wpa_s
->sme
.assoc_req_ie
) -
535 wpa_s
->sme
.assoc_req_ie_len
);
537 wpa_s
->sme
.assoc_req_ie_len
+= len
;
539 #endif /* CONFIG_MBO */
542 if (!skip_auth
&& params
.auth_alg
== WPA_AUTH_ALG_SAE
&&
543 pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
, ssid
, 0,
545 wpa_dbg(wpa_s
, MSG_DEBUG
,
546 "PMKSA cache entry found - try to use PMKSA caching instead of new SAE authentication");
547 params
.auth_alg
= WPA_AUTH_ALG_OPEN
;
548 wpa_s
->sme
.sae_pmksa_caching
= 1;
551 if (!skip_auth
&& params
.auth_alg
== WPA_AUTH_ALG_SAE
) {
553 resp
= sme_auth_build_sae_commit(wpa_s
, ssid
,
556 resp
= sme_auth_build_sae_confirm(wpa_s
);
558 wpas_connection_failed(wpa_s
, bss
->bssid
);
561 params
.auth_data
= wpabuf_head(resp
);
562 params
.auth_data_len
= wpabuf_len(resp
);
563 wpa_s
->sme
.sae
.state
= start
? SAE_COMMITTED
: SAE_CONFIRMED
;
565 #endif /* CONFIG_SAE */
567 old_ssid
= wpa_s
->current_ssid
;
568 wpa_s
->current_ssid
= ssid
;
569 wpa_supplicant_rsn_supp_set_config(wpa_s
, wpa_s
->current_ssid
);
570 wpa_supplicant_initiate_eapol(wpa_s
);
573 /* TODO: FILS operations can in some cases be done between different
574 * network_ctx (i.e., same credentials can be used with multiple
576 if (params
.auth_alg
== WPA_AUTH_ALG_OPEN
&&
577 wpa_key_mgmt_fils(ssid
->key_mgmt
)) {
582 * Check FILS Indication element (FILS Information field) bits
583 * indicating supported authentication algorithms against local
584 * configuration (ssid->fils_dh_group). Try to use FILS
585 * authentication only if the AP supports the combination in the
586 * network profile. */
587 indic
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
588 if (!indic
|| indic
[1] < 2) {
589 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
590 " does not include FILS Indication element - cannot use FILS authentication with it",
591 MAC2STR(bss
->bssid
));
595 fils_info
= WPA_GET_LE16(indic
+ 2);
596 if (ssid
->fils_dh_group
== 0 && !(fils_info
& BIT(9))) {
597 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
598 " does not support FILS SK without PFS - cannot use FILS authentication with it",
599 MAC2STR(bss
->bssid
));
602 if (ssid
->fils_dh_group
!= 0 && !(fils_info
& BIT(10))) {
603 wpa_printf(MSG_DEBUG
, "SME: " MACSTR
604 " does not support FILS SK with PFS - cannot use FILS authentication with it",
605 MAC2STR(bss
->bssid
));
609 if (pmksa_cache_set_current(wpa_s
->wpa
, NULL
, bss
->bssid
,
611 wpa_bss_get_fils_cache_id(bss
)) ==
613 wpa_printf(MSG_DEBUG
,
614 "SME: Try to use FILS with PMKSA caching");
615 resp
= fils_build_auth(wpa_s
->wpa
, ssid
->fils_dh_group
, md
);
619 if (ssid
->fils_dh_group
)
620 wpa_printf(MSG_DEBUG
,
621 "SME: Try to use FILS SK authentication with PFS (DH Group %u)",
622 ssid
->fils_dh_group
);
624 wpa_printf(MSG_DEBUG
,
625 "SME: Try to use FILS SK authentication without PFS");
626 auth_alg
= ssid
->fils_dh_group
?
627 WPA_AUTH_ALG_FILS_SK_PFS
: WPA_AUTH_ALG_FILS
;
628 params
.auth_alg
= auth_alg
;
629 params
.auth_data
= wpabuf_head(resp
);
630 params
.auth_data_len
= wpabuf_len(resp
);
631 wpa_s
->sme
.auth_alg
= auth_alg
;
635 #endif /* CONFIG_FILS */
637 wpa_supplicant_cancel_sched_scan(wpa_s
);
638 wpa_supplicant_cancel_scan(wpa_s
);
640 wpa_msg(wpa_s
, MSG_INFO
, "SME: Trying to authenticate with " MACSTR
641 " (SSID='%s' freq=%d MHz)", MAC2STR(params
.bssid
),
642 wpa_ssid_txt(params
.ssid
, params
.ssid_len
), params
.freq
);
644 eapol_sm_notify_portValid(wpa_s
->eapol
, FALSE
);
645 wpa_clear_keys(wpa_s
, bss
->bssid
);
646 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
647 if (old_ssid
!= wpa_s
->current_ssid
)
648 wpas_notify_network_changed(wpa_s
);
651 hs20_configure_frame_filters(wpa_s
);
652 #endif /* CONFIG_HS20 */
656 * If multi-channel concurrency is not supported, check for any
657 * frequency conflict. In case of any frequency conflict, remove the
658 * least prioritized connection.
660 if (wpa_s
->num_multichan_concurrent
< 2) {
662 num
= get_shared_radio_freqs(wpa_s
, &freq
, 1);
663 if (num
> 0 && freq
> 0 && freq
!= params
.freq
) {
664 wpa_printf(MSG_DEBUG
,
665 "Conflicting frequency found (%d != %d)",
667 if (wpas_p2p_handle_frequency_conflicts(wpa_s
,
670 wpas_connection_failed(wpa_s
, bss
->bssid
);
671 wpa_supplicant_mark_disassoc(wpa_s
);
673 wpas_connect_work_done(wpa_s
);
678 #endif /* CONFIG_P2P */
681 wpa_msg(wpa_s
, MSG_DEBUG
,
682 "SME: Skip authentication step on reassoc-to-same-BSS");
684 sme_associate(wpa_s
, ssid
->mode
, bss
->bssid
, WLAN_AUTH_OPEN
);
689 wpa_s
->sme
.auth_alg
= params
.auth_alg
;
690 if (wpa_drv_authenticate(wpa_s
, ¶ms
) < 0) {
691 wpa_msg(wpa_s
, MSG_INFO
, "SME: Authentication request to the "
693 wpas_connection_failed(wpa_s
, bss
->bssid
);
694 wpa_supplicant_mark_disassoc(wpa_s
);
696 wpas_connect_work_done(wpa_s
);
700 eloop_register_timeout(SME_AUTH_TIMEOUT
, 0, sme_auth_timer
, wpa_s
,
704 * Association will be started based on the authentication event from
712 static void sme_auth_start_cb(struct wpa_radio_work
*work
, int deinit
)
714 struct wpa_connect_work
*cwork
= work
->ctx
;
715 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
719 wpa_s
->connect_work
= NULL
;
721 wpas_connect_work_free(cwork
);
725 wpa_s
->connect_work
= work
;
727 if (cwork
->bss_removed
||
728 !wpas_valid_bss_ssid(wpa_s
, cwork
->bss
, cwork
->ssid
) ||
729 wpas_network_disabled(wpa_s
, cwork
->ssid
)) {
730 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: BSS/SSID entry for authentication not valid anymore - drop connection attempt");
731 wpas_connect_work_done(wpa_s
);
735 /* Starting new connection, so clear the possibly used WPA IE from the
736 * previous association. */
737 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
739 sme_send_authentication(wpa_s
, cwork
->bss
, cwork
->ssid
, 1);
743 void sme_authenticate(struct wpa_supplicant
*wpa_s
,
744 struct wpa_bss
*bss
, struct wpa_ssid
*ssid
)
746 struct wpa_connect_work
*cwork
;
748 if (bss
== NULL
|| ssid
== NULL
)
750 if (wpa_s
->connect_work
) {
751 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Reject sme_authenticate() call since connect_work exist");
755 if (radio_work_pending(wpa_s
, "sme-connect")) {
757 * The previous sme-connect work might no longer be valid due to
758 * the fact that the BSS list was updated. In addition, it makes
759 * sense to adhere to the 'newer' decision.
761 wpa_dbg(wpa_s
, MSG_DEBUG
,
762 "SME: Remove previous pending sme-connect");
763 radio_remove_works(wpa_s
, "sme-connect", 0);
766 wpas_abort_ongoing_scan(wpa_s
);
768 cwork
= os_zalloc(sizeof(*cwork
));
776 wpa_s
->sme
.sae
.state
= SAE_NOTHING
;
777 wpa_s
->sme
.sae
.send_confirm
= 0;
778 wpa_s
->sme
.sae_group_index
= 0;
779 #endif /* CONFIG_SAE */
781 if (radio_add_work(wpa_s
, bss
->freq
, "sme-connect", 1,
782 sme_auth_start_cb
, cwork
) < 0)
783 wpas_connect_work_free(cwork
);
789 static int sme_sae_auth(struct wpa_supplicant
*wpa_s
, u16 auth_transaction
,
790 u16 status_code
, const u8
*data
, size_t len
)
794 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SAE authentication transaction %u "
795 "status code %u", auth_transaction
, status_code
);
797 if (auth_transaction
== 1 &&
798 status_code
== WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ
&&
799 wpa_s
->sme
.sae
.state
== SAE_COMMITTED
&&
800 wpa_s
->current_bss
&& wpa_s
->current_ssid
) {
801 int default_groups
[] = { 19, 20, 21, 25, 26, 0 };
804 groups
= wpa_s
->conf
->sae_groups
;
805 if (!groups
|| groups
[0] <= 0)
806 groups
= default_groups
;
808 if (len
< sizeof(le16
)) {
809 wpa_dbg(wpa_s
, MSG_DEBUG
,
810 "SME: Too short SAE anti-clogging token request");
813 group
= WPA_GET_LE16(data
);
814 wpa_dbg(wpa_s
, MSG_DEBUG
,
815 "SME: SAE anti-clogging token requested (group %u)",
817 if (sae_group_allowed(&wpa_s
->sme
.sae
, groups
, group
) !=
818 WLAN_STATUS_SUCCESS
) {
819 wpa_dbg(wpa_s
, MSG_ERROR
,
820 "SME: SAE group %u of anti-clogging request is invalid",
824 wpabuf_free(wpa_s
->sme
.sae_token
);
825 wpa_s
->sme
.sae_token
= wpabuf_alloc_copy(data
+ sizeof(le16
),
827 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
828 wpa_s
->current_ssid
, 1);
832 if (auth_transaction
== 1 &&
833 status_code
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
&&
834 wpa_s
->sme
.sae
.state
== SAE_COMMITTED
&&
835 wpa_s
->current_bss
&& wpa_s
->current_ssid
) {
836 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SAE group not supported");
837 wpa_s
->sme
.sae_group_index
++;
838 if (sme_set_sae_group(wpa_s
) < 0)
839 return -1; /* no other groups enabled */
840 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Try next enabled SAE group");
841 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
842 wpa_s
->current_ssid
, 1);
846 if (status_code
!= WLAN_STATUS_SUCCESS
)
849 if (auth_transaction
== 1) {
852 groups
= wpa_s
->conf
->sae_groups
;
854 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME SAE commit");
855 if (wpa_s
->current_bss
== NULL
||
856 wpa_s
->current_ssid
== NULL
)
858 if (wpa_s
->sme
.sae
.state
!= SAE_COMMITTED
)
860 if (groups
&& groups
[0] <= 0)
862 res
= sae_parse_commit(&wpa_s
->sme
.sae
, data
, len
, NULL
, NULL
,
864 if (res
== SAE_SILENTLY_DISCARD
) {
865 wpa_printf(MSG_DEBUG
,
866 "SAE: Drop commit message due to reflection attack");
869 if (res
!= WLAN_STATUS_SUCCESS
)
872 if (sae_process_commit(&wpa_s
->sme
.sae
) < 0) {
873 wpa_printf(MSG_DEBUG
, "SAE: Failed to process peer "
878 wpabuf_free(wpa_s
->sme
.sae_token
);
879 wpa_s
->sme
.sae_token
= NULL
;
880 sme_send_authentication(wpa_s
, wpa_s
->current_bss
,
881 wpa_s
->current_ssid
, 0);
883 } else if (auth_transaction
== 2) {
884 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME SAE confirm");
885 if (wpa_s
->sme
.sae
.state
!= SAE_CONFIRMED
)
887 if (sae_check_confirm(&wpa_s
->sme
.sae
, data
, len
) < 0)
889 wpa_s
->sme
.sae
.state
= SAE_ACCEPTED
;
890 sae_clear_temp_data(&wpa_s
->sme
.sae
);
896 #endif /* CONFIG_SAE */
899 void sme_event_auth(struct wpa_supplicant
*wpa_s
, union wpa_event_data
*data
)
901 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
904 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication event "
905 "when network is not selected");
909 if (wpa_s
->wpa_state
!= WPA_AUTHENTICATING
) {
910 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication event "
911 "when not in authenticating state");
915 if (os_memcmp(wpa_s
->pending_bssid
, data
->auth
.peer
, ETH_ALEN
) != 0) {
916 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Ignore authentication with "
917 "unexpected peer " MACSTR
,
918 MAC2STR(data
->auth
.peer
));
922 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Authentication response: peer=" MACSTR
923 " auth_type=%d auth_transaction=%d status_code=%d",
924 MAC2STR(data
->auth
.peer
), data
->auth
.auth_type
,
925 data
->auth
.auth_transaction
, data
->auth
.status_code
);
926 wpa_hexdump(MSG_MSGDUMP
, "SME: Authentication response IEs",
927 data
->auth
.ies
, data
->auth
.ies_len
);
929 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
932 if (data
->auth
.auth_type
== WLAN_AUTH_SAE
) {
934 res
= sme_sae_auth(wpa_s
, data
->auth
.auth_transaction
,
935 data
->auth
.status_code
, data
->auth
.ies
,
938 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
939 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
945 wpa_printf(MSG_DEBUG
, "SME: SAE completed - setting PMK for "
947 wpa_sm_set_pmk(wpa_s
->wpa
, wpa_s
->sme
.sae
.pmk
, PMK_LEN
,
948 wpa_s
->sme
.sae
.pmkid
, wpa_s
->pending_bssid
);
950 #endif /* CONFIG_SAE */
952 if (data
->auth
.status_code
!= WLAN_STATUS_SUCCESS
) {
955 if (data
->auth
.ies
&& data
->auth
.ies_len
) {
956 size_t buflen
= 2 * data
->auth
.ies_len
+ 1;
957 ie_txt
= os_malloc(buflen
);
959 wpa_snprintf_hex(ie_txt
, buflen
, data
->auth
.ies
,
963 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_AUTH_REJECT MACSTR
964 " auth_type=%u auth_transaction=%u status_code=%u%s%s",
965 MAC2STR(data
->auth
.peer
), data
->auth
.auth_type
,
966 data
->auth
.auth_transaction
, data
->auth
.status_code
,
967 ie_txt
? " ie=" : "",
968 ie_txt
? ie_txt
: "");
971 if (data
->auth
.status_code
!=
972 WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG
||
973 wpa_s
->sme
.auth_alg
== data
->auth
.auth_type
||
974 wpa_s
->current_ssid
->auth_alg
== WPA_AUTH_ALG_LEAP
) {
975 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
976 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
980 wpas_connect_work_done(wpa_s
);
982 switch (data
->auth
.auth_type
) {
984 wpa_s
->current_ssid
->auth_alg
= WPA_AUTH_ALG_SHARED
;
986 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying SHARED auth");
987 wpa_supplicant_associate(wpa_s
, wpa_s
->current_bss
,
988 wpa_s
->current_ssid
);
991 case WLAN_AUTH_SHARED_KEY
:
992 wpa_s
->current_ssid
->auth_alg
= WPA_AUTH_ALG_LEAP
;
994 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Trying LEAP auth");
995 wpa_supplicant_associate(wpa_s
, wpa_s
->current_bss
,
996 wpa_s
->current_ssid
);
1004 #ifdef CONFIG_IEEE80211R
1005 if (data
->auth
.auth_type
== WLAN_AUTH_FT
) {
1006 const u8
*ric_ies
= NULL
;
1007 size_t ric_ies_len
= 0;
1009 if (wpa_s
->ric_ies
) {
1010 ric_ies
= wpabuf_head(wpa_s
->ric_ies
);
1011 ric_ies_len
= wpabuf_len(wpa_s
->ric_ies
);
1013 if (wpa_ft_process_response(wpa_s
->wpa
, data
->auth
.ies
,
1014 data
->auth
.ies_len
, 0,
1016 ric_ies
, ric_ies_len
) < 0) {
1017 wpa_dbg(wpa_s
, MSG_DEBUG
,
1018 "SME: FT Authentication response processing failed");
1019 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1021 " reason=%d locally_generated=1",
1022 MAC2STR(wpa_s
->pending_bssid
),
1023 WLAN_REASON_DEAUTH_LEAVING
);
1024 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1025 wpa_supplicant_mark_disassoc(wpa_s
);
1029 #endif /* CONFIG_IEEE80211R */
1032 if (data
->auth
.auth_type
== WLAN_AUTH_FILS_SK
||
1033 data
->auth
.auth_type
== WLAN_AUTH_FILS_SK_PFS
) {
1034 u16 expect_auth_type
;
1036 expect_auth_type
= wpa_s
->sme
.auth_alg
==
1037 WPA_AUTH_ALG_FILS_SK_PFS
? WLAN_AUTH_FILS_SK_PFS
:
1039 if (data
->auth
.auth_type
!= expect_auth_type
) {
1040 wpa_dbg(wpa_s
, MSG_DEBUG
,
1041 "SME: FILS Authentication response used different auth alg (%u; expected %u)",
1042 data
->auth
.auth_type
, expect_auth_type
);
1043 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1045 " reason=%d locally_generated=1",
1046 MAC2STR(wpa_s
->pending_bssid
),
1047 WLAN_REASON_DEAUTH_LEAVING
);
1048 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1049 wpa_supplicant_mark_disassoc(wpa_s
);
1053 if (fils_process_auth(wpa_s
->wpa
, wpa_s
->pending_bssid
,
1054 data
->auth
.ies
, data
->auth
.ies_len
) < 0) {
1055 wpa_dbg(wpa_s
, MSG_DEBUG
,
1056 "SME: FILS Authentication response processing failed");
1057 wpa_msg(wpa_s
, MSG_INFO
, WPA_EVENT_DISCONNECTED
"bssid="
1059 " reason=%d locally_generated=1",
1060 MAC2STR(wpa_s
->pending_bssid
),
1061 WLAN_REASON_DEAUTH_LEAVING
);
1062 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1063 wpa_supplicant_mark_disassoc(wpa_s
);
1067 #endif /* CONFIG_FILS */
1069 sme_associate(wpa_s
, ssid
->mode
, data
->auth
.peer
,
1070 data
->auth
.auth_type
);
1075 #ifdef CONFIG_IEEE80211R
1076 static void remove_ie(u8
*buf
, size_t *len
, u8 eid
)
1078 u8
*pos
, *next
, *end
;
1080 pos
= (u8
*) get_ie(buf
, *len
, eid
);
1082 next
= pos
+ 2 + pos
[1];
1085 os_memmove(pos
, next
, end
- next
);
1088 #endif /* CONFIG_IEEE80211R */
1089 #endif /* CONFIG_FILS */
1092 void sme_associate(struct wpa_supplicant
*wpa_s
, enum wpas_mode mode
,
1093 const u8
*bssid
, u16 auth_type
)
1095 struct wpa_driver_associate_params params
;
1096 struct ieee802_11_elems elems
;
1098 u8 nonces
[2 * FILS_NONCE_LEN
];
1099 #endif /* CONFIG_FILS */
1100 #ifdef CONFIG_HT_OVERRIDES
1101 struct ieee80211_ht_capabilities htcaps
;
1102 struct ieee80211_ht_capabilities htcaps_mask
;
1103 #endif /* CONFIG_HT_OVERRIDES */
1104 #ifdef CONFIG_VHT_OVERRIDES
1105 struct ieee80211_vht_capabilities vhtcaps
;
1106 struct ieee80211_vht_capabilities vhtcaps_mask
;
1107 #endif /* CONFIG_VHT_OVERRIDES */
1109 os_memset(¶ms
, 0, sizeof(params
));
1112 if (auth_type
== WLAN_AUTH_FILS_SK
||
1113 auth_type
== WLAN_AUTH_FILS_SK_PFS
) {
1115 const u8
*snonce
, *anonce
;
1116 const unsigned int max_hlp
= 20;
1117 struct wpabuf
*hlp
[max_hlp
];
1118 unsigned int i
, num_hlp
= 0;
1119 struct fils_hlp_req
*req
;
1121 dl_list_for_each(req
, &wpa_s
->fils_hlp_req
, struct fils_hlp_req
,
1123 hlp
[num_hlp
] = wpabuf_alloc(2 * ETH_ALEN
+ 6 +
1124 wpabuf_len(req
->pkt
));
1127 wpabuf_put_data(hlp
[num_hlp
], req
->dst
, ETH_ALEN
);
1128 wpabuf_put_data(hlp
[num_hlp
], wpa_s
->own_addr
,
1130 wpabuf_put_data(hlp
[num_hlp
],
1131 "\xaa\xaa\x03\x00\x00\x00", 6);
1132 wpabuf_put_buf(hlp
[num_hlp
], req
->pkt
);
1134 if (num_hlp
>= max_hlp
)
1138 buf
= fils_build_assoc_req(wpa_s
->wpa
, ¶ms
.fils_kek
,
1139 ¶ms
.fils_kek_len
, &snonce
,
1141 (const struct wpabuf
**) hlp
,
1143 for (i
= 0; i
< num_hlp
; i
++)
1144 wpabuf_free(hlp
[i
]);
1147 wpa_hexdump(MSG_DEBUG
, "FILS: assoc_req before FILS elements",
1148 wpa_s
->sme
.assoc_req_ie
,
1149 wpa_s
->sme
.assoc_req_ie_len
);
1150 #ifdef CONFIG_IEEE80211R
1151 if (wpa_key_mgmt_ft(wpa_s
->key_mgmt
)) {
1152 /* Remove RSNE and MDE to allow them to be overridden
1153 * with FILS+FT specific values from
1154 * fils_build_assoc_req(). */
1155 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1156 &wpa_s
->sme
.assoc_req_ie_len
,
1158 wpa_hexdump(MSG_DEBUG
,
1159 "FILS: assoc_req after RSNE removal",
1160 wpa_s
->sme
.assoc_req_ie
,
1161 wpa_s
->sme
.assoc_req_ie_len
);
1162 remove_ie(wpa_s
->sme
.assoc_req_ie
,
1163 &wpa_s
->sme
.assoc_req_ie_len
,
1164 WLAN_EID_MOBILITY_DOMAIN
);
1165 wpa_hexdump(MSG_DEBUG
,
1166 "FILS: assoc_req after MDE removal",
1167 wpa_s
->sme
.assoc_req_ie
,
1168 wpa_s
->sme
.assoc_req_ie_len
);
1170 #endif /* CONFIG_IEEE80211R */
1171 /* TODO: Make wpa_s->sme.assoc_req_ie use dynamic allocation */
1172 if (wpa_s
->sme
.assoc_req_ie_len
+ wpabuf_len(buf
) >
1173 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1174 wpa_printf(MSG_ERROR
,
1175 "FILS: Not enough buffer room for own AssocReq elements");
1179 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1180 wpabuf_head(buf
), wpabuf_len(buf
));
1181 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(buf
);
1183 wpa_hexdump(MSG_DEBUG
, "FILS: assoc_req after FILS elements",
1184 wpa_s
->sme
.assoc_req_ie
,
1185 wpa_s
->sme
.assoc_req_ie_len
);
1187 os_memcpy(nonces
, snonce
, FILS_NONCE_LEN
);
1188 os_memcpy(nonces
+ FILS_NONCE_LEN
, anonce
, FILS_NONCE_LEN
);
1189 params
.fils_nonces
= nonces
;
1190 params
.fils_nonces_len
= sizeof(nonces
);
1192 #endif /* CONFIG_FILS */
1195 if (auth_type
== WLAN_AUTH_OPEN
&&
1196 wpa_s
->key_mgmt
== WPA_KEY_MGMT_OWE
) {
1197 struct wpabuf
*owe_ie
;
1198 u16 group
= OWE_DH_GROUP
;
1200 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->owe_group
)
1201 group
= wpa_s
->current_ssid
->owe_group
;
1202 owe_ie
= owe_build_assoc_req(wpa_s
->wpa
, group
);
1204 wpa_printf(MSG_ERROR
,
1205 "OWE: Failed to build IE for Association Request frame");
1208 if (wpa_s
->sme
.assoc_req_ie_len
+ wpabuf_len(owe_ie
) >
1209 sizeof(wpa_s
->sme
.assoc_req_ie
)) {
1210 wpa_printf(MSG_ERROR
,
1211 "OWE: Not enough buffer room for own Association Request frame elements");
1212 wpabuf_free(owe_ie
);
1215 os_memcpy(wpa_s
->sme
.assoc_req_ie
+ wpa_s
->sme
.assoc_req_ie_len
,
1216 wpabuf_head(owe_ie
), wpabuf_len(owe_ie
));
1217 wpa_s
->sme
.assoc_req_ie_len
+= wpabuf_len(owe_ie
);
1218 wpabuf_free(owe_ie
);
1220 #endif /* CONFIG_OWE */
1222 params
.bssid
= bssid
;
1223 params
.ssid
= wpa_s
->sme
.ssid
;
1224 params
.ssid_len
= wpa_s
->sme
.ssid_len
;
1225 params
.freq
.freq
= wpa_s
->sme
.freq
;
1226 params
.bg_scan_period
= wpa_s
->current_ssid
?
1227 wpa_s
->current_ssid
->bg_scan_period
: -1;
1228 params
.wpa_ie
= wpa_s
->sme
.assoc_req_ie_len
?
1229 wpa_s
->sme
.assoc_req_ie
: NULL
;
1230 params
.wpa_ie_len
= wpa_s
->sme
.assoc_req_ie_len
;
1231 params
.pairwise_suite
= wpa_s
->pairwise_cipher
;
1232 params
.group_suite
= wpa_s
->group_cipher
;
1233 params
.mgmt_group_suite
= wpa_s
->mgmt_group_cipher
;
1234 params
.key_mgmt_suite
= wpa_s
->key_mgmt
;
1235 params
.wpa_proto
= wpa_s
->wpa_proto
;
1236 #ifdef CONFIG_HT_OVERRIDES
1237 os_memset(&htcaps
, 0, sizeof(htcaps
));
1238 os_memset(&htcaps_mask
, 0, sizeof(htcaps_mask
));
1239 params
.htcaps
= (u8
*) &htcaps
;
1240 params
.htcaps_mask
= (u8
*) &htcaps_mask
;
1241 wpa_supplicant_apply_ht_overrides(wpa_s
, wpa_s
->current_ssid
, ¶ms
);
1242 #endif /* CONFIG_HT_OVERRIDES */
1243 #ifdef CONFIG_VHT_OVERRIDES
1244 os_memset(&vhtcaps
, 0, sizeof(vhtcaps
));
1245 os_memset(&vhtcaps_mask
, 0, sizeof(vhtcaps_mask
));
1246 params
.vhtcaps
= &vhtcaps
;
1247 params
.vhtcaps_mask
= &vhtcaps_mask
;
1248 wpa_supplicant_apply_vht_overrides(wpa_s
, wpa_s
->current_ssid
, ¶ms
);
1249 #endif /* CONFIG_VHT_OVERRIDES */
1250 #ifdef CONFIG_IEEE80211R
1251 if (auth_type
== WLAN_AUTH_FT
&& wpa_s
->sme
.ft_ies
) {
1252 params
.wpa_ie
= wpa_s
->sme
.ft_ies
;
1253 params
.wpa_ie_len
= wpa_s
->sme
.ft_ies_len
;
1255 #endif /* CONFIG_IEEE80211R */
1257 params
.mgmt_frame_protection
= wpa_s
->sme
.mfp
;
1258 params
.rrm_used
= wpa_s
->rrm
.rrm_used
;
1259 if (wpa_s
->sme
.prev_bssid_set
)
1260 params
.prev_bssid
= wpa_s
->sme
.prev_bssid
;
1262 wpa_msg(wpa_s
, MSG_INFO
, "Trying to associate with " MACSTR
1263 " (SSID='%s' freq=%d MHz)", MAC2STR(params
.bssid
),
1264 params
.ssid
? wpa_ssid_txt(params
.ssid
, params
.ssid_len
) : "",
1267 wpa_supplicant_set_state(wpa_s
, WPA_ASSOCIATING
);
1269 if (params
.wpa_ie
== NULL
||
1270 ieee802_11_parse_elems(params
.wpa_ie
, params
.wpa_ie_len
, &elems
, 0)
1272 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Could not parse own IEs?!");
1273 os_memset(&elems
, 0, sizeof(elems
));
1276 params
.wpa_proto
= WPA_PROTO_RSN
;
1277 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.rsn_ie
- 2,
1278 elems
.rsn_ie_len
+ 2);
1279 } else if (elems
.wpa_ie
) {
1280 params
.wpa_proto
= WPA_PROTO_WPA
;
1281 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.wpa_ie
- 2,
1282 elems
.wpa_ie_len
+ 2);
1283 } else if (elems
.osen
) {
1284 params
.wpa_proto
= WPA_PROTO_OSEN
;
1285 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, elems
.osen
- 2,
1286 elems
.osen_len
+ 2);
1288 wpa_sm_set_assoc_wpa_ie(wpa_s
->wpa
, NULL
, 0);
1289 if (wpa_s
->current_ssid
&& wpa_s
->current_ssid
->p2p_group
)
1292 if (wpa_s
->p2pdev
->set_sta_uapsd
)
1293 params
.uapsd
= wpa_s
->p2pdev
->sta_uapsd
;
1297 if (wpa_drv_associate(wpa_s
, ¶ms
) < 0) {
1298 wpa_msg(wpa_s
, MSG_INFO
, "SME: Association request to the "
1300 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1301 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1302 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1306 eloop_register_timeout(SME_ASSOC_TIMEOUT
, 0, sme_assoc_timer
, wpa_s
,
1311 int sme_update_ft_ies(struct wpa_supplicant
*wpa_s
, const u8
*md
,
1312 const u8
*ies
, size_t ies_len
)
1314 if (md
== NULL
|| ies
== NULL
) {
1315 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Remove mobility domain");
1316 os_free(wpa_s
->sme
.ft_ies
);
1317 wpa_s
->sme
.ft_ies
= NULL
;
1318 wpa_s
->sme
.ft_ies_len
= 0;
1319 wpa_s
->sme
.ft_used
= 0;
1323 os_memcpy(wpa_s
->sme
.mobility_domain
, md
, MOBILITY_DOMAIN_ID_LEN
);
1324 wpa_hexdump(MSG_DEBUG
, "SME: FT IEs", ies
, ies_len
);
1325 os_free(wpa_s
->sme
.ft_ies
);
1326 wpa_s
->sme
.ft_ies
= os_memdup(ies
, ies_len
);
1327 if (wpa_s
->sme
.ft_ies
== NULL
)
1329 wpa_s
->sme
.ft_ies_len
= ies_len
;
1334 static void sme_deauth(struct wpa_supplicant
*wpa_s
)
1338 bssid_changed
= !is_zero_ether_addr(wpa_s
->bssid
);
1340 if (wpa_drv_deauthenticate(wpa_s
, wpa_s
->pending_bssid
,
1341 WLAN_REASON_DEAUTH_LEAVING
) < 0) {
1342 wpa_msg(wpa_s
, MSG_INFO
, "SME: Deauth request to the driver "
1345 wpa_s
->sme
.prev_bssid_set
= 0;
1347 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1348 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
1349 os_memset(wpa_s
->bssid
, 0, ETH_ALEN
);
1350 os_memset(wpa_s
->pending_bssid
, 0, ETH_ALEN
);
1352 wpas_notify_bssid_changed(wpa_s
);
1356 void sme_event_assoc_reject(struct wpa_supplicant
*wpa_s
,
1357 union wpa_event_data
*data
)
1359 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association with " MACSTR
" failed: "
1360 "status code %d", MAC2STR(wpa_s
->pending_bssid
),
1361 data
->assoc_reject
.status_code
);
1363 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
1366 if (wpa_s
->sme
.sae_pmksa_caching
&& wpa_s
->current_ssid
&&
1367 wpa_key_mgmt_sae(wpa_s
->current_ssid
->key_mgmt
)) {
1368 wpa_dbg(wpa_s
, MSG_DEBUG
,
1369 "PMKSA caching attempt rejected - drop PMKSA cache entry and fall back to SAE authentication");
1370 wpa_sm_aborted_cached(wpa_s
->wpa
);
1371 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, wpa_s
->current_ssid
);
1372 if (wpa_s
->current_bss
) {
1373 struct wpa_bss
*bss
= wpa_s
->current_bss
;
1374 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1376 wpa_drv_deauthenticate(wpa_s
, wpa_s
->pending_bssid
,
1377 WLAN_REASON_DEAUTH_LEAVING
);
1378 wpas_connect_work_done(wpa_s
);
1379 wpa_supplicant_mark_disassoc(wpa_s
);
1380 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
1384 #endif /* CONFIG_SAE */
1387 * For now, unconditionally terminate the previous authentication. In
1388 * theory, this should not be needed, but mac80211 gets quite confused
1389 * if the authentication is left pending.. Some roaming cases might
1390 * benefit from using the previous authentication, so this could be
1391 * optimized in the future.
1397 void sme_event_auth_timed_out(struct wpa_supplicant
*wpa_s
,
1398 union wpa_event_data
*data
)
1400 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Authentication timed out");
1401 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1402 wpa_supplicant_mark_disassoc(wpa_s
);
1406 void sme_event_assoc_timed_out(struct wpa_supplicant
*wpa_s
,
1407 union wpa_event_data
*data
)
1409 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association timed out");
1410 wpas_connection_failed(wpa_s
, wpa_s
->pending_bssid
);
1411 wpa_supplicant_mark_disassoc(wpa_s
);
1415 void sme_event_disassoc(struct wpa_supplicant
*wpa_s
,
1416 struct disassoc_info
*info
)
1418 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Disassociation event received");
1419 if (wpa_s
->sme
.prev_bssid_set
) {
1421 * cfg80211/mac80211 can get into somewhat confused state if
1422 * the AP only disassociates us and leaves us in authenticated
1423 * state. For now, force the state to be cleared to avoid
1424 * confusing errors if we try to associate with the AP again.
1426 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Deauthenticate to clear "
1428 wpa_drv_deauthenticate(wpa_s
, wpa_s
->sme
.prev_bssid
,
1429 WLAN_REASON_DEAUTH_LEAVING
);
1434 static void sme_auth_timer(void *eloop_ctx
, void *timeout_ctx
)
1436 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1437 if (wpa_s
->wpa_state
== WPA_AUTHENTICATING
) {
1438 wpa_msg(wpa_s
, MSG_DEBUG
, "SME: Authentication timeout");
1444 static void sme_assoc_timer(void *eloop_ctx
, void *timeout_ctx
)
1446 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1447 if (wpa_s
->wpa_state
== WPA_ASSOCIATING
) {
1448 wpa_msg(wpa_s
, MSG_DEBUG
, "SME: Association timeout");
1454 void sme_state_changed(struct wpa_supplicant
*wpa_s
)
1456 /* Make sure timers are cleaned up appropriately. */
1457 if (wpa_s
->wpa_state
!= WPA_ASSOCIATING
)
1458 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
1459 if (wpa_s
->wpa_state
!= WPA_AUTHENTICATING
)
1460 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1464 void sme_disassoc_while_authenticating(struct wpa_supplicant
*wpa_s
,
1465 const u8
*prev_pending_bssid
)
1468 * mac80211-workaround to force deauth on failed auth cmd,
1469 * requires us to remain in authenticating state to allow the
1470 * second authentication attempt to be continued properly.
1472 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Allow pending authentication "
1473 "to proceed after disconnection event");
1474 wpa_supplicant_set_state(wpa_s
, WPA_AUTHENTICATING
);
1475 os_memcpy(wpa_s
->pending_bssid
, prev_pending_bssid
, ETH_ALEN
);
1478 * Re-arm authentication timer in case auth fails for whatever reason.
1480 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1481 eloop_register_timeout(SME_AUTH_TIMEOUT
, 0, sme_auth_timer
, wpa_s
,
1486 void sme_clear_on_disassoc(struct wpa_supplicant
*wpa_s
)
1488 wpa_s
->sme
.prev_bssid_set
= 0;
1490 wpabuf_free(wpa_s
->sme
.sae_token
);
1491 wpa_s
->sme
.sae_token
= NULL
;
1492 sae_clear_data(&wpa_s
->sme
.sae
);
1493 #endif /* CONFIG_SAE */
1494 #ifdef CONFIG_IEEE80211R
1495 if (wpa_s
->sme
.ft_ies
)
1496 sme_update_ft_ies(wpa_s
, NULL
, NULL
, 0);
1497 #endif /* CONFIG_IEEE80211R */
1501 void sme_deinit(struct wpa_supplicant
*wpa_s
)
1503 os_free(wpa_s
->sme
.ft_ies
);
1504 wpa_s
->sme
.ft_ies
= NULL
;
1505 wpa_s
->sme
.ft_ies_len
= 0;
1506 #ifdef CONFIG_IEEE80211W
1507 sme_stop_sa_query(wpa_s
);
1508 #endif /* CONFIG_IEEE80211W */
1509 sme_clear_on_disassoc(wpa_s
);
1511 eloop_cancel_timeout(sme_assoc_timer
, wpa_s
, NULL
);
1512 eloop_cancel_timeout(sme_auth_timer
, wpa_s
, NULL
);
1513 eloop_cancel_timeout(sme_obss_scan_timeout
, wpa_s
, NULL
);
1517 static void sme_send_2040_bss_coex(struct wpa_supplicant
*wpa_s
,
1518 const u8
*chan_list
, u8 num_channels
,
1521 struct ieee80211_2040_bss_coex_ie
*bc_ie
;
1522 struct ieee80211_2040_intol_chan_report
*ic_report
;
1525 wpa_printf(MSG_DEBUG
, "SME: Send 20/40 BSS Coexistence to " MACSTR
1526 " (num_channels=%u num_intol=%u)",
1527 MAC2STR(wpa_s
->bssid
), num_channels
, num_intol
);
1528 wpa_hexdump(MSG_DEBUG
, "SME: 20/40 BSS Intolerant Channels",
1529 chan_list
, num_channels
);
1531 buf
= wpabuf_alloc(2 + /* action.category + action_code */
1532 sizeof(struct ieee80211_2040_bss_coex_ie
) +
1533 sizeof(struct ieee80211_2040_intol_chan_report
) +
1538 wpabuf_put_u8(buf
, WLAN_ACTION_PUBLIC
);
1539 wpabuf_put_u8(buf
, WLAN_PA_20_40_BSS_COEX
);
1541 bc_ie
= wpabuf_put(buf
, sizeof(*bc_ie
));
1542 bc_ie
->element_id
= WLAN_EID_20_40_BSS_COEXISTENCE
;
1545 bc_ie
->coex_param
|= WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ
;
1547 if (num_channels
> 0) {
1548 ic_report
= wpabuf_put(buf
, sizeof(*ic_report
));
1549 ic_report
->element_id
= WLAN_EID_20_40_BSS_INTOLERANT
;
1550 ic_report
->length
= num_channels
+ 1;
1551 ic_report
->op_class
= 0;
1552 os_memcpy(wpabuf_put(buf
, num_channels
), chan_list
,
1556 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
1557 wpa_s
->own_addr
, wpa_s
->bssid
,
1558 wpabuf_head(buf
), wpabuf_len(buf
), 0) < 0) {
1559 wpa_msg(wpa_s
, MSG_INFO
,
1560 "SME: Failed to send 20/40 BSS Coexistence frame");
1567 int sme_proc_obss_scan(struct wpa_supplicant
*wpa_s
)
1569 struct wpa_bss
*bss
;
1572 u8 chan_list
[P2P_MAX_CHANNELS
], channel
;
1573 u8 num_channels
= 0, num_intol
= 0, i
;
1575 if (!wpa_s
->sme
.sched_obss_scan
)
1578 wpa_s
->sme
.sched_obss_scan
= 0;
1579 if (!wpa_s
->current_bss
|| wpa_s
->wpa_state
!= WPA_COMPLETED
)
1583 * Check whether AP uses regulatory triplet or channel triplet in
1584 * country info. Right now the operating class of the BSS channel
1585 * width trigger event is "unknown" (IEEE Std 802.11-2012 10.15.12),
1586 * based on the assumption that operating class triplet is not used in
1587 * beacon frame. If the First Channel Number/Operating Extension
1588 * Identifier octet has a positive integer value of 201 or greater,
1589 * then its operating class triplet.
1591 * TODO: If Supported Operating Classes element is present in beacon
1592 * frame, have to lookup operating class in Annex E and fill them in
1595 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_COUNTRY
);
1596 if (ie
&& (ie
[1] >= 6) && (ie
[5] >= 201))
1599 os_memset(chan_list
, 0, sizeof(chan_list
));
1601 dl_list_for_each(bss
, &wpa_s
->bss
, struct wpa_bss
, list
) {
1602 /* Skip other band bss */
1603 enum hostapd_hw_mode mode
;
1604 mode
= ieee80211_freq_to_chan(bss
->freq
, &channel
);
1605 if (mode
!= HOSTAPD_MODE_IEEE80211G
&&
1606 mode
!= HOSTAPD_MODE_IEEE80211B
)
1609 ie
= wpa_bss_get_ie(bss
, WLAN_EID_HT_CAP
);
1610 ht_cap
= (ie
&& (ie
[1] == 26)) ? WPA_GET_LE16(ie
+ 2) : 0;
1611 wpa_printf(MSG_DEBUG
, "SME OBSS scan BSS " MACSTR
1612 " freq=%u chan=%u ht_cap=0x%x",
1613 MAC2STR(bss
->bssid
), bss
->freq
, channel
, ht_cap
);
1615 if (!ht_cap
|| (ht_cap
& HT_CAP_INFO_40MHZ_INTOLERANT
)) {
1616 if (ht_cap
& HT_CAP_INFO_40MHZ_INTOLERANT
)
1619 /* Check whether the channel is already considered */
1620 for (i
= 0; i
< num_channels
; i
++) {
1621 if (channel
== chan_list
[i
])
1624 if (i
!= num_channels
)
1627 chan_list
[num_channels
++] = channel
;
1631 sme_send_2040_bss_coex(wpa_s
, chan_list
, num_channels
, num_intol
);
1636 static void wpa_obss_scan_freqs_list(struct wpa_supplicant
*wpa_s
,
1637 struct wpa_driver_scan_params
*params
)
1639 /* Include only affected channels */
1640 struct hostapd_hw_modes
*mode
;
1644 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
,
1645 HOSTAPD_MODE_IEEE80211G
);
1647 /* No channels supported in this band - use empty list */
1648 params
->freqs
= os_zalloc(sizeof(int));
1652 if (wpa_s
->sme
.ht_sec_chan
== HT_SEC_CHAN_UNKNOWN
&&
1653 wpa_s
->current_bss
) {
1656 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_HT_OPERATION
);
1657 if (ie
&& ie
[1] >= 2) {
1660 o
= ie
[3] & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK
;
1661 if (o
== HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE
)
1662 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_ABOVE
;
1663 else if (o
== HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW
)
1664 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_BELOW
;
1668 start
= wpa_s
->assoc_freq
- 10;
1669 end
= wpa_s
->assoc_freq
+ 10;
1670 switch (wpa_s
->sme
.ht_sec_chan
) {
1671 case HT_SEC_CHAN_UNKNOWN
:
1672 /* HT40+ possible on channels 1..9 */
1673 if (wpa_s
->assoc_freq
<= 2452)
1675 /* HT40- possible on channels 5-13 */
1676 if (wpa_s
->assoc_freq
>= 2432)
1679 case HT_SEC_CHAN_ABOVE
:
1682 case HT_SEC_CHAN_BELOW
:
1686 wpa_printf(MSG_DEBUG
,
1687 "OBSS: assoc_freq %d possible affected range %d-%d",
1688 wpa_s
->assoc_freq
, start
, end
);
1690 params
->freqs
= os_calloc(mode
->num_channels
+ 1, sizeof(int));
1691 if (params
->freqs
== NULL
)
1693 for (count
= 0, i
= 0; i
< mode
->num_channels
; i
++) {
1696 if (mode
->channels
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
1698 freq
= mode
->channels
[i
].freq
;
1699 if (freq
- 10 >= end
|| freq
+ 10 <= start
)
1700 continue; /* not affected */
1701 params
->freqs
[count
++] = freq
;
1706 static void sme_obss_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
1708 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1709 struct wpa_driver_scan_params params
;
1711 if (!wpa_s
->current_bss
) {
1712 wpa_printf(MSG_DEBUG
, "SME OBSS: Ignore scan request");
1716 os_memset(¶ms
, 0, sizeof(params
));
1717 wpa_obss_scan_freqs_list(wpa_s
, ¶ms
);
1718 params
.low_priority
= 1;
1719 wpa_printf(MSG_DEBUG
, "SME OBSS: Request an OBSS scan");
1721 if (wpa_supplicant_trigger_scan(wpa_s
, ¶ms
))
1722 wpa_printf(MSG_DEBUG
, "SME OBSS: Failed to trigger scan");
1724 wpa_s
->sme
.sched_obss_scan
= 1;
1725 os_free(params
.freqs
);
1727 eloop_register_timeout(wpa_s
->sme
.obss_scan_int
, 0,
1728 sme_obss_scan_timeout
, wpa_s
, NULL
);
1732 void sme_sched_obss_scan(struct wpa_supplicant
*wpa_s
, int enable
)
1735 struct wpa_bss
*bss
= wpa_s
->current_bss
;
1736 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1737 struct hostapd_hw_modes
*hw_mode
= NULL
;
1740 eloop_cancel_timeout(sme_obss_scan_timeout
, wpa_s
, NULL
);
1741 wpa_s
->sme
.sched_obss_scan
= 0;
1742 wpa_s
->sme
.ht_sec_chan
= HT_SEC_CHAN_UNKNOWN
;
1747 * Schedule OBSS scan if driver is using station SME in wpa_supplicant
1748 * or it expects OBSS scan to be performed by wpa_supplicant.
1750 if (!((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SME
) ||
1751 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_OBSS_SCAN
)) ||
1752 ssid
== NULL
|| ssid
->mode
!= IEEE80211_MODE_INFRA
)
1755 if (!wpa_s
->hw
.modes
)
1758 /* only HT caps in 11g mode are relevant */
1759 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
1760 hw_mode
= &wpa_s
->hw
.modes
[i
];
1761 if (hw_mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
1765 /* Driver does not support HT40 for 11g or doesn't have 11g. */
1766 if (i
== wpa_s
->hw
.num_modes
|| !hw_mode
||
1767 !(hw_mode
->ht_capab
& HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
1770 if (bss
== NULL
|| bss
->freq
< 2400 || bss
->freq
> 2500)
1771 return; /* Not associated on 2.4 GHz band */
1773 /* Check whether AP supports HT40 */
1774 ie
= wpa_bss_get_ie(wpa_s
->current_bss
, WLAN_EID_HT_CAP
);
1775 if (!ie
|| ie
[1] < 2 ||
1776 !(WPA_GET_LE16(ie
+ 2) & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
1777 return; /* AP does not support HT40 */
1779 ie
= wpa_bss_get_ie(wpa_s
->current_bss
,
1780 WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS
);
1781 if (!ie
|| ie
[1] < 14)
1782 return; /* AP does not request OBSS scans */
1784 wpa_s
->sme
.obss_scan_int
= WPA_GET_LE16(ie
+ 6);
1785 if (wpa_s
->sme
.obss_scan_int
< 10) {
1786 wpa_printf(MSG_DEBUG
, "SME: Invalid OBSS Scan Interval %u "
1787 "replaced with the minimum 10 sec",
1788 wpa_s
->sme
.obss_scan_int
);
1789 wpa_s
->sme
.obss_scan_int
= 10;
1791 wpa_printf(MSG_DEBUG
, "SME: OBSS Scan Interval %u sec",
1792 wpa_s
->sme
.obss_scan_int
);
1793 eloop_register_timeout(wpa_s
->sme
.obss_scan_int
, 0,
1794 sme_obss_scan_timeout
, wpa_s
, NULL
);
1798 #ifdef CONFIG_IEEE80211W
1800 static const unsigned int sa_query_max_timeout
= 1000;
1801 static const unsigned int sa_query_retry_timeout
= 201;
1803 static int sme_check_sa_query_timeout(struct wpa_supplicant
*wpa_s
)
1806 struct os_reltime now
, passed
;
1807 os_get_reltime(&now
);
1808 os_reltime_sub(&now
, &wpa_s
->sme
.sa_query_start
, &passed
);
1809 tu
= (passed
.sec
* 1000000 + passed
.usec
) / 1024;
1810 if (sa_query_max_timeout
< tu
) {
1811 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: SA Query timed out");
1812 sme_stop_sa_query(wpa_s
);
1813 wpa_supplicant_deauthenticate(
1814 wpa_s
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
1822 static void sme_send_sa_query_req(struct wpa_supplicant
*wpa_s
,
1825 u8 req
[2 + WLAN_SA_QUERY_TR_ID_LEN
];
1826 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Sending SA Query Request to "
1827 MACSTR
, MAC2STR(wpa_s
->bssid
));
1828 wpa_hexdump(MSG_DEBUG
, "SME: SA Query Transaction ID",
1829 trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
1830 req
[0] = WLAN_ACTION_SA_QUERY
;
1831 req
[1] = WLAN_SA_QUERY_REQUEST
;
1832 os_memcpy(req
+ 2, trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
1833 if (wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0, wpa_s
->bssid
,
1834 wpa_s
->own_addr
, wpa_s
->bssid
,
1835 req
, sizeof(req
), 0) < 0)
1836 wpa_msg(wpa_s
, MSG_INFO
, "SME: Failed to send SA Query "
1841 static void sme_sa_query_timer(void *eloop_ctx
, void *timeout_ctx
)
1843 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1844 unsigned int timeout
, sec
, usec
;
1845 u8
*trans_id
, *nbuf
;
1847 if (wpa_s
->sme
.sa_query_count
> 0 &&
1848 sme_check_sa_query_timeout(wpa_s
))
1851 nbuf
= os_realloc_array(wpa_s
->sme
.sa_query_trans_id
,
1852 wpa_s
->sme
.sa_query_count
+ 1,
1853 WLAN_SA_QUERY_TR_ID_LEN
);
1855 sme_stop_sa_query(wpa_s
);
1858 if (wpa_s
->sme
.sa_query_count
== 0) {
1859 /* Starting a new SA Query procedure */
1860 os_get_reltime(&wpa_s
->sme
.sa_query_start
);
1862 trans_id
= nbuf
+ wpa_s
->sme
.sa_query_count
* WLAN_SA_QUERY_TR_ID_LEN
;
1863 wpa_s
->sme
.sa_query_trans_id
= nbuf
;
1864 wpa_s
->sme
.sa_query_count
++;
1866 if (os_get_random(trans_id
, WLAN_SA_QUERY_TR_ID_LEN
) < 0) {
1867 wpa_printf(MSG_DEBUG
, "Could not generate SA Query ID");
1868 sme_stop_sa_query(wpa_s
);
1872 timeout
= sa_query_retry_timeout
;
1873 sec
= ((timeout
/ 1000) * 1024) / 1000;
1874 usec
= (timeout
% 1000) * 1024;
1875 eloop_register_timeout(sec
, usec
, sme_sa_query_timer
, wpa_s
, NULL
);
1877 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Association SA Query attempt %d",
1878 wpa_s
->sme
.sa_query_count
);
1880 sme_send_sa_query_req(wpa_s
, trans_id
);
1884 static void sme_start_sa_query(struct wpa_supplicant
*wpa_s
)
1886 sme_sa_query_timer(wpa_s
, NULL
);
1890 static void sme_stop_sa_query(struct wpa_supplicant
*wpa_s
)
1892 eloop_cancel_timeout(sme_sa_query_timer
, wpa_s
, NULL
);
1893 os_free(wpa_s
->sme
.sa_query_trans_id
);
1894 wpa_s
->sme
.sa_query_trans_id
= NULL
;
1895 wpa_s
->sme
.sa_query_count
= 0;
1899 void sme_event_unprot_disconnect(struct wpa_supplicant
*wpa_s
, const u8
*sa
,
1900 const u8
*da
, u16 reason_code
)
1902 struct wpa_ssid
*ssid
;
1903 struct os_reltime now
;
1905 if (wpa_s
->wpa_state
!= WPA_COMPLETED
)
1907 ssid
= wpa_s
->current_ssid
;
1908 if (wpas_get_ssid_pmf(wpa_s
, ssid
) == NO_MGMT_FRAME_PROTECTION
)
1910 if (os_memcmp(sa
, wpa_s
->bssid
, ETH_ALEN
) != 0)
1912 if (reason_code
!= WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA
&&
1913 reason_code
!= WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA
)
1915 if (wpa_s
->sme
.sa_query_count
> 0)
1918 os_get_reltime(&now
);
1919 if (wpa_s
->sme
.last_unprot_disconnect
.sec
&&
1920 !os_reltime_expired(&now
, &wpa_s
->sme
.last_unprot_disconnect
, 10))
1921 return; /* limit SA Query procedure frequency */
1922 wpa_s
->sme
.last_unprot_disconnect
= now
;
1924 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Unprotected disconnect dropped - "
1925 "possible AP/STA state mismatch - trigger SA Query");
1926 sme_start_sa_query(wpa_s
);
1930 void sme_sa_query_rx(struct wpa_supplicant
*wpa_s
, const u8
*sa
,
1931 const u8
*data
, size_t len
)
1935 if (wpa_s
->sme
.sa_query_trans_id
== NULL
||
1936 len
< 1 + WLAN_SA_QUERY_TR_ID_LEN
||
1937 data
[0] != WLAN_SA_QUERY_RESPONSE
)
1939 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Received SA Query response from "
1940 MACSTR
" (trans_id %02x%02x)", MAC2STR(sa
), data
[1], data
[2]);
1942 if (os_memcmp(sa
, wpa_s
->bssid
, ETH_ALEN
) != 0)
1945 for (i
= 0; i
< wpa_s
->sme
.sa_query_count
; i
++) {
1946 if (os_memcmp(wpa_s
->sme
.sa_query_trans_id
+
1947 i
* WLAN_SA_QUERY_TR_ID_LEN
,
1948 data
+ 1, WLAN_SA_QUERY_TR_ID_LEN
) == 0)
1952 if (i
>= wpa_s
->sme
.sa_query_count
) {
1953 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: No matching SA Query "
1954 "transaction identifier found");
1958 wpa_dbg(wpa_s
, MSG_DEBUG
, "SME: Reply to pending SA Query received "
1959 "from " MACSTR
, MAC2STR(sa
));
1960 sme_stop_sa_query(wpa_s
);
1963 #endif /* CONFIG_IEEE80211W */