2 * hostapd / Callback functions for driver wrappers
3 * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "radius/radius.h"
14 #include "drivers/driver.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/ieee802_11_common.h"
17 #include "common/wpa_ctrl.h"
18 #include "common/dpp.h"
19 #include "crypto/random.h"
25 #include "ieee802_11.h"
26 #include "ieee802_11_auth.h"
28 #include "accounting.h"
29 #include "tkip_countermeasures.h"
30 #include "ieee802_1x.h"
32 #include "wps_hostapd.h"
33 #include "ap_drv_ops.h"
34 #include "ap_config.h"
36 #include "hw_features.h"
40 #include "dpp_hostapd.h"
42 #include "neighbor_db.h"
46 void hostapd_notify_assoc_fils_finish(struct hostapd_data
*hapd
,
49 u16 reply_res
= WLAN_STATUS_SUCCESS
;
50 struct ieee802_11_elems elems
;
51 u8 buf
[IEEE80211_MAX_MMPDU_SIZE
], *p
= buf
;
54 wpa_printf(MSG_DEBUG
, "%s FILS: Finish association with " MACSTR
,
55 __func__
, MAC2STR(sta
->addr
));
56 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
57 if (!sta
->fils_pending_assoc_req
)
60 ieee802_11_parse_elems(sta
->fils_pending_assoc_req
,
61 sta
->fils_pending_assoc_req_len
, &elems
, 0);
62 if (!elems
.fils_session
) {
63 wpa_printf(MSG_DEBUG
, "%s failed to find FILS Session element",
68 p
= hostapd_eid_assoc_fils_session(sta
->wpa_sm
, p
,
72 reply_res
= hostapd_sta_assoc(hapd
, sta
->addr
,
73 sta
->fils_pending_assoc_is_reassoc
,
76 ap_sta_set_authorized(hapd
, sta
, 1);
77 new_assoc
= (sta
->flags
& WLAN_STA_ASSOC
) == 0;
78 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
79 sta
->flags
&= ~WLAN_STA_WNM_SLEEP_MODE
;
80 hostapd_set_sta_flags(hapd
, sta
);
81 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC_FILS
);
82 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 1);
83 hostapd_new_assoc_sta(hapd
, sta
, !new_assoc
);
84 os_free(sta
->fils_pending_assoc_req
);
85 sta
->fils_pending_assoc_req
= NULL
;
86 sta
->fils_pending_assoc_req_len
= 0;
87 wpabuf_free(sta
->fils_hlp_resp
);
88 sta
->fils_hlp_resp
= NULL
;
89 wpabuf_free(sta
->hlp_dhcp_discover
);
90 sta
->hlp_dhcp_discover
= NULL
;
91 fils_hlp_deinit(hapd
);
94 * Remove the station in case transmission of a success response fails
95 * (the STA was added associated to the driver) or if the station was
96 * previously added unassociated.
98 if (reply_res
!= WLAN_STATUS_SUCCESS
|| sta
->added_unassoc
) {
99 hostapd_drv_sta_remove(hapd
, sta
->addr
);
100 sta
->added_unassoc
= 0;
103 #endif /* CONFIG_FILS */
106 int hostapd_notif_assoc(struct hostapd_data
*hapd
, const u8
*addr
,
107 const u8
*req_ies
, size_t req_ies_len
, int reassoc
)
109 struct sta_info
*sta
;
111 struct ieee802_11_elems elems
;
114 #if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_IEEE80211W) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
115 u8 buf
[sizeof(struct ieee80211_mgmt
) + 1024];
117 #endif /* CONFIG_IEEE80211R_AP || CONFIG_IEEE80211W || CONFIG_FILS || CONFIG_OWE */
118 u16 reason
= WLAN_REASON_UNSPECIFIED
;
119 u16 status
= WLAN_STATUS_SUCCESS
;
120 const u8
*p2p_dev_addr
= NULL
;
124 * This could potentially happen with unexpected event from the
125 * driver wrapper. This was seen at least in one case where the
126 * driver ended up being set to station mode while hostapd was
127 * running, so better make sure we stop processing such an
130 wpa_printf(MSG_DEBUG
,
131 "hostapd_notif_assoc: Skip event with no address");
134 random_add_randomness(addr
, ETH_ALEN
);
136 hostapd_logger(hapd
, addr
, HOSTAPD_MODULE_IEEE80211
,
137 HOSTAPD_LEVEL_INFO
, "associated");
139 ieee802_11_parse_elems(req_ies
, req_ies_len
, &elems
, 0);
141 ie
= elems
.wps_ie
- 2;
142 ielen
= elems
.wps_ie_len
+ 2;
143 wpa_printf(MSG_DEBUG
, "STA included WPS IE in (Re)AssocReq");
144 } else if (elems
.rsn_ie
) {
145 ie
= elems
.rsn_ie
- 2;
146 ielen
= elems
.rsn_ie_len
+ 2;
147 wpa_printf(MSG_DEBUG
, "STA included RSN IE in (Re)AssocReq");
148 } else if (elems
.wpa_ie
) {
149 ie
= elems
.wpa_ie
- 2;
150 ielen
= elems
.wpa_ie_len
+ 2;
151 wpa_printf(MSG_DEBUG
, "STA included WPA IE in (Re)AssocReq");
153 } else if (elems
.osen
) {
155 ielen
= elems
.osen_len
+ 2;
156 wpa_printf(MSG_DEBUG
, "STA included OSEN IE in (Re)AssocReq");
157 #endif /* CONFIG_HS20 */
161 wpa_printf(MSG_DEBUG
,
162 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
165 sta
= ap_get_sta(hapd
, addr
);
167 ap_sta_no_session_timeout(hapd
, sta
);
168 accounting_sta_stop(hapd
, sta
);
171 * Make sure that the previously registered inactivity timer
172 * will not remove the STA immediately.
174 sta
->timeout_next
= STA_NULLFUNC
;
176 sta
= ap_sta_add(hapd
, addr
);
178 hostapd_drv_sta_disassoc(hapd
, addr
,
179 WLAN_REASON_DISASSOC_AP_BUSY
);
183 sta
->flags
&= ~(WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
| WLAN_STA_WPS2
);
186 * ACL configurations to the drivers (implementing AP SME and ACL
187 * offload) without hostapd's knowledge, can result in a disconnection
188 * though the driver accepts the connection. Skip the hostapd check for
189 * ACL if the driver supports ACL offload to avoid potentially
190 * conflicting ACL rules.
192 if (hapd
->iface
->drv_max_acl_mac_addrs
== 0 &&
193 hostapd_check_acl(hapd
, addr
, NULL
) != HOSTAPD_ACL_ACCEPT
) {
194 wpa_printf(MSG_INFO
, "STA " MACSTR
" not allowed to connect",
196 reason
= WLAN_REASON_UNSPECIFIED
;
202 wpabuf_free(sta
->p2p_ie
);
203 sta
->p2p_ie
= ieee802_11_vendor_ie_concat(req_ies
, req_ies_len
,
206 p2p_dev_addr
= p2p_get_go_dev_addr(sta
->p2p_ie
);
208 #endif /* CONFIG_P2P */
210 #ifdef CONFIG_IEEE80211N
212 if (elems
.ht_capabilities
&&
213 (hapd
->iface
->conf
->ht_capab
&
214 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
)) {
215 struct ieee80211_ht_capabilities
*ht_cap
=
216 (struct ieee80211_ht_capabilities
*)
217 elems
.ht_capabilities
;
219 if (le_to_host16(ht_cap
->ht_capabilities_info
) &
220 HT_CAP_INFO_40MHZ_INTOLERANT
)
221 ht40_intolerant_add(hapd
->iface
, sta
);
223 #endif /* NEED_AP_MLME */
224 #endif /* CONFIG_IEEE80211N */
226 #ifdef CONFIG_INTERWORKING
227 if (elems
.ext_capab
&& elems
.ext_capab_len
> 4) {
228 if (elems
.ext_capab
[4] & 0x01)
229 sta
->qos_map_enabled
= 1;
231 #endif /* CONFIG_INTERWORKING */
234 wpabuf_free(sta
->hs20_ie
);
235 if (elems
.hs20
&& elems
.hs20_len
> 4) {
236 sta
->hs20_ie
= wpabuf_alloc_copy(elems
.hs20
+ 4,
241 wpabuf_free(sta
->roaming_consortium
);
242 if (elems
.roaming_cons_sel
)
243 sta
->roaming_consortium
= wpabuf_alloc_copy(
244 elems
.roaming_cons_sel
+ 4,
245 elems
.roaming_cons_sel_len
- 4);
247 sta
->roaming_consortium
= NULL
;
248 #endif /* CONFIG_HS20 */
251 wpabuf_free(sta
->mb_ies
);
252 if (hapd
->iface
->fst
)
253 sta
->mb_ies
= mb_ies_by_info(&elems
.mb_ies
);
256 #endif /* CONFIG_FST */
258 mbo_ap_check_sta_assoc(hapd
, sta
, &elems
);
260 ap_copy_sta_supp_op_classes(sta
, elems
.supp_op_classes
,
261 elems
.supp_op_classes_len
);
263 if (hapd
->conf
->wpa
) {
264 if (ie
== NULL
|| ielen
== 0) {
266 if (hapd
->conf
->wps_state
) {
267 wpa_printf(MSG_DEBUG
,
268 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
269 sta
->flags
|= WLAN_STA_MAYBE_WPS
;
272 #endif /* CONFIG_WPS */
274 wpa_printf(MSG_DEBUG
, "No WPA/RSN IE from STA");
275 reason
= WLAN_REASON_INVALID_IE
;
276 status
= WLAN_STATUS_INVALID_IE
;
280 if (hapd
->conf
->wps_state
&& ie
[0] == 0xdd && ie
[1] >= 4 &&
281 os_memcmp(ie
+ 2, "\x00\x50\xf2\x04", 4) == 0) {
284 sta
->flags
|= WLAN_STA_WPS
;
285 wps
= ieee802_11_vendor_ie_concat(ie
, ielen
,
288 if (wps_is_20(wps
)) {
289 wpa_printf(MSG_DEBUG
,
290 "WPS: STA supports WPS 2.0");
291 sta
->flags
|= WLAN_STA_WPS2
;
297 #endif /* CONFIG_WPS */
299 if (sta
->wpa_sm
== NULL
)
300 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
303 if (sta
->wpa_sm
== NULL
) {
304 wpa_printf(MSG_ERROR
,
305 "Failed to initialize WPA state machine");
308 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
311 elems
.mdie
, elems
.mdie_len
,
312 elems
.owe_dh
, elems
.owe_dh_len
);
313 if (res
!= WPA_IE_OK
) {
314 wpa_printf(MSG_DEBUG
,
315 "WPA/RSN information element rejected? (res %u)",
317 wpa_hexdump(MSG_DEBUG
, "IE", ie
, ielen
);
318 if (res
== WPA_INVALID_GROUP
) {
319 reason
= WLAN_REASON_GROUP_CIPHER_NOT_VALID
;
320 status
= WLAN_STATUS_GROUP_CIPHER_NOT_VALID
;
321 } else if (res
== WPA_INVALID_PAIRWISE
) {
322 reason
= WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID
;
323 status
= WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID
;
324 } else if (res
== WPA_INVALID_AKMP
) {
325 reason
= WLAN_REASON_AKMP_NOT_VALID
;
326 status
= WLAN_STATUS_AKMP_NOT_VALID
;
328 #ifdef CONFIG_IEEE80211W
329 else if (res
== WPA_MGMT_FRAME_PROTECTION_VIOLATION
) {
330 reason
= WLAN_REASON_INVALID_IE
;
331 status
= WLAN_STATUS_INVALID_IE
;
332 } else if (res
== WPA_INVALID_MGMT_GROUP_CIPHER
) {
333 reason
= WLAN_REASON_CIPHER_SUITE_REJECTED
;
334 status
= WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
336 #endif /* CONFIG_IEEE80211W */
338 reason
= WLAN_REASON_INVALID_IE
;
339 status
= WLAN_STATUS_INVALID_IE
;
343 #ifdef CONFIG_IEEE80211W
344 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
345 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
346 !sta
->sa_query_timed_out
&&
347 sta
->sa_query_count
> 0)
348 ap_check_sa_query_timeout(hapd
, sta
);
349 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
350 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
351 !sta
->sa_query_timed_out
&&
352 (sta
->auth_alg
!= WLAN_AUTH_FT
)) {
354 * STA has already been associated with MFP and SA
355 * Query timeout has not been reached. Reject the
356 * association attempt temporarily and start SA Query,
357 * if one is not pending.
360 if (sta
->sa_query_count
== 0)
361 ap_sta_start_sa_query(hapd
, sta
);
363 status
= WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
;
365 p
= hostapd_eid_assoc_comeback_time(hapd
, sta
, p
);
367 hostapd_sta_assoc(hapd
, addr
, reassoc
, status
, buf
,
372 if (wpa_auth_uses_mfp(sta
->wpa_sm
))
373 sta
->flags
|= WLAN_STA_MFP
;
375 sta
->flags
&= ~WLAN_STA_MFP
;
376 #endif /* CONFIG_IEEE80211W */
378 #ifdef CONFIG_IEEE80211R_AP
379 if (sta
->auth_alg
== WLAN_AUTH_FT
) {
380 status
= wpa_ft_validate_reassoc(sta
->wpa_sm
, req_ies
,
382 if (status
!= WLAN_STATUS_SUCCESS
) {
383 if (status
== WLAN_STATUS_INVALID_PMKID
)
384 reason
= WLAN_REASON_INVALID_IE
;
385 if (status
== WLAN_STATUS_INVALID_MDIE
)
386 reason
= WLAN_REASON_INVALID_IE
;
387 if (status
== WLAN_STATUS_INVALID_FTIE
)
388 reason
= WLAN_REASON_INVALID_IE
;
392 #endif /* CONFIG_IEEE80211R_AP */
393 } else if (hapd
->conf
->wps_state
) {
398 wps
= ieee802_11_vendor_ie_concat(req_ies
, req_ies_len
,
402 #ifdef CONFIG_WPS_STRICT
403 if (wps
&& wps_validate_assoc_req(wps
) < 0) {
404 reason
= WLAN_REASON_INVALID_IE
;
405 status
= WLAN_STATUS_INVALID_IE
;
409 #endif /* CONFIG_WPS_STRICT */
411 sta
->flags
|= WLAN_STA_WPS
;
412 if (wps_is_20(wps
)) {
413 wpa_printf(MSG_DEBUG
,
414 "WPS: STA supports WPS 2.0");
415 sta
->flags
|= WLAN_STA_WPS2
;
418 sta
->flags
|= WLAN_STA_MAYBE_WPS
;
420 #endif /* CONFIG_WPS */
422 } else if (hapd
->conf
->osen
) {
423 if (elems
.osen
== NULL
) {
425 hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
427 "No HS 2.0 OSEN element in association request");
428 return WLAN_STATUS_INVALID_IE
;
431 wpa_printf(MSG_DEBUG
, "HS 2.0: OSEN association");
432 if (sta
->wpa_sm
== NULL
)
433 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
435 if (sta
->wpa_sm
== NULL
) {
436 wpa_printf(MSG_WARNING
,
437 "Failed to initialize WPA state machine");
438 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
440 if (wpa_validate_osen(hapd
->wpa_auth
, sta
->wpa_sm
,
441 elems
.osen
- 2, elems
.osen_len
+ 2) < 0)
442 return WLAN_STATUS_INVALID_IE
;
443 #endif /* CONFIG_HS20 */
447 if (hapd
->conf
->mbo_enabled
&& (hapd
->conf
->wpa
& 2) &&
448 elems
.mbo
&& sta
->cell_capa
&& !(sta
->flags
& WLAN_STA_MFP
) &&
449 hapd
->conf
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
451 "MBO: Reject WPA2 association without PMF");
452 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
454 #endif /* CONFIG_MBO */
458 #endif /* CONFIG_WPS */
460 #ifdef CONFIG_IEEE80211R_AP
461 p
= wpa_sm_write_assoc_resp_ies(sta
->wpa_sm
, buf
, sizeof(buf
),
462 sta
->auth_alg
, req_ies
, req_ies_len
);
464 wpa_printf(MSG_DEBUG
, "FT: Failed to write AssocResp IEs");
465 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
467 #endif /* CONFIG_IEEE80211R_AP */
470 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
471 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
472 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
476 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
478 if (!wpa_fils_validate_fils_session(sta
->wpa_sm
, req_ies
,
480 sta
->fils_session
)) {
481 wpa_printf(MSG_DEBUG
,
482 "FILS: Session validation failed");
483 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
486 res
= wpa_fils_validate_key_confirm(sta
->wpa_sm
, req_ies
,
489 wpa_printf(MSG_DEBUG
,
490 "FILS: Key Confirm validation failed");
491 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
494 if (fils_process_hlp(hapd
, sta
, req_ies
, req_ies_len
) > 0) {
495 wpa_printf(MSG_DEBUG
,
496 "FILS: Delaying Assoc Response (HLP)");
499 wpa_printf(MSG_DEBUG
,
500 "FILS: Going ahead with Assoc Response (no HLP)");
504 wpa_printf(MSG_DEBUG
, "FILS: HLP callback cleanup");
505 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
506 os_free(sta
->fils_pending_assoc_req
);
507 sta
->fils_pending_assoc_req
= NULL
;
508 sta
->fils_pending_assoc_req_len
= 0;
509 wpabuf_free(sta
->fils_hlp_resp
);
510 sta
->fils_hlp_resp
= NULL
;
511 sta
->fils_drv_assoc_finish
= 0;
514 if (sta
&& delay_assoc
&& status
== WLAN_STATUS_SUCCESS
) {
517 req_tmp
= os_malloc(req_ies_len
);
519 wpa_printf(MSG_DEBUG
,
520 "FILS: buffer allocation failed for assoc req");
523 os_memcpy(req_tmp
, req_ies
, req_ies_len
);
524 sta
->fils_pending_assoc_req
= req_tmp
;
525 sta
->fils_pending_assoc_req_len
= req_ies_len
;
526 sta
->fils_pending_assoc_is_reassoc
= reassoc
;
527 sta
->fils_drv_assoc_finish
= 1;
528 wpa_printf(MSG_DEBUG
,
529 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
530 MACSTR
, MAC2STR(sta
->addr
));
531 eloop_register_timeout(
532 0, hapd
->conf
->fils_hlp_wait_time
* 1024,
533 fils_hlp_timeout
, hapd
, sta
);
536 p
= hostapd_eid_assoc_fils_session(sta
->wpa_sm
, p
,
539 wpa_hexdump(MSG_DEBUG
, "FILS Assoc Resp BUF (IEs)",
542 #endif /* CONFIG_FILS */
545 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
546 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
&&
550 npos
= owe_assoc_req_process(hapd
, sta
,
551 elems
.owe_dh
, elems
.owe_dh_len
,
552 p
, sizeof(buf
) - (p
- buf
),
557 reason
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
) {
558 status
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
559 hostapd_sta_assoc(hapd
, addr
, reassoc
, status
, buf
,
564 if (!npos
|| reason
!= WLAN_STATUS_SUCCESS
)
567 #endif /* CONFIG_OWE */
570 dpp_pfs_free(sta
->dpp_pfs
);
573 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_DPP
) &&
574 hapd
->conf
->dpp_netaccesskey
&& sta
->wpa_sm
&&
575 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_DPP
&&
577 sta
->dpp_pfs
= dpp_pfs_init(
578 wpabuf_head(hapd
->conf
->dpp_netaccesskey
),
579 wpabuf_len(hapd
->conf
->dpp_netaccesskey
));
581 wpa_printf(MSG_DEBUG
,
582 "DPP: Could not initialize PFS");
583 /* Try to continue without PFS */
587 if (dpp_pfs_process(sta
->dpp_pfs
, elems
.owe_dh
,
588 elems
.owe_dh_len
) < 0) {
589 dpp_pfs_free(sta
->dpp_pfs
);
591 reason
= WLAN_REASON_UNSPECIFIED
;
596 wpa_auth_set_dpp_z(sta
->wpa_sm
, sta
->dpp_pfs
?
597 sta
->dpp_pfs
->secret
: NULL
);
599 #endif /* CONFIG_DPP2 */
601 #if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
602 hostapd_sta_assoc(hapd
, addr
, reassoc
, status
, buf
, p
- buf
);
604 if (sta
->auth_alg
== WLAN_AUTH_FT
||
605 sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
606 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
607 sta
->auth_alg
== WLAN_AUTH_FILS_PK
)
608 ap_sta_set_authorized(hapd
, sta
, 1);
609 #else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
610 /* Keep compiler silent about unused variables */
613 #endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
615 new_assoc
= (sta
->flags
& WLAN_STA_ASSOC
) == 0;
616 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
617 sta
->flags
&= ~WLAN_STA_WNM_SLEEP_MODE
;
619 hostapd_set_sta_flags(hapd
, sta
);
621 if (reassoc
&& (sta
->auth_alg
== WLAN_AUTH_FT
))
622 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC_FT
);
624 else if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
625 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
626 sta
->auth_alg
== WLAN_AUTH_FILS_PK
)
627 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC_FILS
);
628 #endif /* CONFIG_FILS */
630 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC
);
632 hostapd_new_assoc_sta(hapd
, sta
, !new_assoc
);
634 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 1);
638 p2p_group_notif_assoc(hapd
->p2p_group
, sta
->addr
,
639 req_ies
, req_ies_len
);
641 #endif /* CONFIG_P2P */
646 #ifdef CONFIG_IEEE80211R_AP
647 hostapd_sta_assoc(hapd
, addr
, reassoc
, status
, buf
, p
- buf
);
648 #endif /* CONFIG_IEEE80211R_AP */
649 hostapd_drv_sta_disassoc(hapd
, sta
->addr
, reason
);
650 ap_free_sta(hapd
, sta
);
655 void hostapd_notif_disassoc(struct hostapd_data
*hapd
, const u8
*addr
)
657 struct sta_info
*sta
;
661 * This could potentially happen with unexpected event from the
662 * driver wrapper. This was seen at least in one case where the
663 * driver ended up reporting a station mode event while hostapd
664 * was running, so better make sure we stop processing such an
667 wpa_printf(MSG_DEBUG
,
668 "hostapd_notif_disassoc: Skip event with no address");
672 hostapd_logger(hapd
, addr
, HOSTAPD_MODULE_IEEE80211
,
673 HOSTAPD_LEVEL_INFO
, "disassociated");
675 sta
= ap_get_sta(hapd
, addr
);
677 wpa_printf(MSG_DEBUG
,
678 "Disassociation notification for unknown STA "
679 MACSTR
, MAC2STR(addr
));
683 ap_sta_set_authorized(hapd
, sta
, 0);
684 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
);
685 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DISASSOC
);
686 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
687 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
688 ap_free_sta(hapd
, sta
);
692 void hostapd_event_sta_low_ack(struct hostapd_data
*hapd
, const u8
*addr
)
694 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
696 if (!sta
|| !hapd
->conf
->disassoc_low_ack
|| sta
->agreed_to_steer
)
699 hostapd_logger(hapd
, addr
, HOSTAPD_MODULE_IEEE80211
,
701 "disconnected due to excessive missing ACKs");
702 hostapd_drv_sta_disassoc(hapd
, addr
, WLAN_REASON_DISASSOC_LOW_ACK
);
703 ap_sta_disassociate(hapd
, sta
, WLAN_REASON_DISASSOC_LOW_ACK
);
707 void hostapd_event_sta_opmode_changed(struct hostapd_data
*hapd
, const u8
*addr
,
708 enum smps_mode smps_mode
,
709 enum chan_width chan_width
, u8 rx_nss
)
711 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
735 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, STA_OPMODE_SMPS_MODE_CHANGED
736 MACSTR
" %s", MAC2STR(addr
), txt
);
739 switch (chan_width
) {
740 case CHAN_WIDTH_20_NOHT
:
752 case CHAN_WIDTH_80P80
:
763 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, STA_OPMODE_MAX_BW_CHANGED
764 MACSTR
" %s", MAC2STR(addr
), txt
);
767 if (rx_nss
!= 0xff) {
768 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, STA_OPMODE_N_SS_CHANGED
769 MACSTR
" %d", MAC2STR(addr
), rx_nss
);
774 void hostapd_event_ch_switch(struct hostapd_data
*hapd
, int freq
, int ht
,
775 int offset
, int width
, int cf1
, int cf2
,
778 /* TODO: If OCV is enabled deauth STAs that don't perform a SA Query */
781 int channel
, chwidth
, is_dfs
;
782 u8 seg0_idx
= 0, seg1_idx
= 0;
785 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
787 "driver %s channel switch: freq=%d, ht=%d, vht_ch=0x%x, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
788 finished
? "had" : "starting",
789 freq
, ht
, hapd
->iconf
->ch_switch_vht_config
, offset
,
790 width
, channel_width_to_string(width
), cf1
, cf2
);
792 hapd
->iface
->freq
= freq
;
794 channel
= hostapd_hw_get_channel(hapd
, freq
);
796 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
797 HOSTAPD_LEVEL_WARNING
,
798 "driver switched to bad channel!");
804 chwidth
= VHT_CHANWIDTH_80MHZ
;
806 case CHAN_WIDTH_80P80
:
807 chwidth
= VHT_CHANWIDTH_80P80MHZ
;
810 chwidth
= VHT_CHANWIDTH_160MHZ
;
812 case CHAN_WIDTH_20_NOHT
:
816 chwidth
= VHT_CHANWIDTH_USE_HT
;
820 switch (hapd
->iface
->current_mode
->mode
) {
821 case HOSTAPD_MODE_IEEE80211A
:
823 seg0_idx
= (cf1
- 5000) / 5;
825 seg1_idx
= (cf2
- 5000) / 5;
828 ieee80211_freq_to_chan(cf1
, &seg0_idx
);
829 ieee80211_freq_to_chan(cf2
, &seg1_idx
);
833 hapd
->iconf
->channel
= channel
;
834 hapd
->iconf
->ieee80211n
= ht
;
836 hapd
->iconf
->ieee80211ac
= 0;
837 } else if (hapd
->iconf
->ch_switch_vht_config
) {
838 /* CHAN_SWITCH VHT config */
839 if (hapd
->iconf
->ch_switch_vht_config
&
840 CH_SWITCH_VHT_ENABLED
)
841 hapd
->iconf
->ieee80211ac
= 1;
842 else if (hapd
->iconf
->ch_switch_vht_config
&
843 CH_SWITCH_VHT_DISABLED
)
844 hapd
->iconf
->ieee80211ac
= 0;
846 hapd
->iconf
->ch_switch_vht_config
= 0;
848 hapd
->iconf
->secondary_channel
= offset
;
849 hapd
->iconf
->vht_oper_chwidth
= chwidth
;
850 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
= seg0_idx
;
851 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
= seg1_idx
;
853 is_dfs
= ieee80211_is_dfs(freq
, hapd
->iface
->hw_features
,
854 hapd
->iface
->num_hw_features
);
856 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
857 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d dfs=%d",
858 finished
? WPA_EVENT_CHANNEL_SWITCH
:
859 WPA_EVENT_CHANNEL_SWITCH_STARTED
,
860 freq
, ht
, offset
, channel_width_to_string(width
),
865 if (hapd
->csa_in_progress
&&
866 freq
== hapd
->cs_freq_params
.freq
) {
867 hostapd_cleanup_cs_params(hapd
);
868 ieee802_11_set_beacon(hapd
);
870 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_CSA_FINISHED
871 "freq=%d dfs=%d", freq
, is_dfs
);
872 } else if (hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_DFS_OFFLOAD
) {
873 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_CSA_FINISHED
874 "freq=%d dfs=%d", freq
, is_dfs
);
877 for (i
= 0; i
< hapd
->iface
->num_bss
; i
++)
878 hostapd_neighbor_set_own_report(hapd
->iface
->bss
[i
]);
879 #endif /* NEED_AP_MLME */
883 void hostapd_event_connect_failed_reason(struct hostapd_data
*hapd
,
884 const u8
*addr
, int reason_code
)
886 switch (reason_code
) {
887 case MAX_CLIENT_REACHED
:
888 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_REJECTED_MAX_STA MACSTR
,
892 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_REJECTED_BLOCKED_STA MACSTR
,
900 void hostapd_acs_channel_selected(struct hostapd_data
*hapd
,
901 struct acs_selected_channels
*acs_res
)
906 if (hapd
->iconf
->channel
) {
907 wpa_printf(MSG_INFO
, "ACS: Channel was already set to %d",
908 hapd
->iconf
->channel
);
912 if (!hapd
->iface
->current_mode
) {
913 for (i
= 0; i
< hapd
->iface
->num_hw_features
; i
++) {
914 struct hostapd_hw_modes
*mode
=
915 &hapd
->iface
->hw_features
[i
];
917 if (mode
->mode
== acs_res
->hw_mode
) {
918 hapd
->iface
->current_mode
= mode
;
922 if (!hapd
->iface
->current_mode
) {
923 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
924 HOSTAPD_LEVEL_WARNING
,
925 "driver selected to bad hw_mode");
931 hapd
->iface
->freq
= hostapd_hw_get_freq(hapd
, acs_res
->pri_channel
);
933 if (!acs_res
->pri_channel
) {
934 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
935 HOSTAPD_LEVEL_WARNING
,
936 "driver switched to bad channel");
941 hapd
->iconf
->channel
= acs_res
->pri_channel
;
942 hapd
->iconf
->acs
= 1;
944 if (acs_res
->sec_channel
== 0)
945 hapd
->iconf
->secondary_channel
= 0;
946 else if (acs_res
->sec_channel
< acs_res
->pri_channel
)
947 hapd
->iconf
->secondary_channel
= -1;
948 else if (acs_res
->sec_channel
> acs_res
->pri_channel
)
949 hapd
->iconf
->secondary_channel
= 1;
951 wpa_printf(MSG_ERROR
, "Invalid secondary channel!");
956 if (hapd
->iface
->conf
->ieee80211ac
) {
957 /* set defaults for backwards compatibility */
958 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
= 0;
959 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
= 0;
960 hapd
->iconf
->vht_oper_chwidth
= VHT_CHANWIDTH_USE_HT
;
961 if (acs_res
->ch_width
== 80) {
962 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
=
963 acs_res
->vht_seg0_center_ch
;
964 hapd
->iconf
->vht_oper_chwidth
= VHT_CHANWIDTH_80MHZ
;
965 } else if (acs_res
->ch_width
== 160) {
966 if (acs_res
->vht_seg1_center_ch
== 0) {
967 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
=
968 acs_res
->vht_seg0_center_ch
;
969 hapd
->iconf
->vht_oper_chwidth
=
970 VHT_CHANWIDTH_160MHZ
;
972 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
=
973 acs_res
->vht_seg0_center_ch
;
974 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
=
975 acs_res
->vht_seg1_center_ch
;
976 hapd
->iconf
->vht_oper_chwidth
=
977 VHT_CHANWIDTH_80P80MHZ
;
983 ret
= hostapd_acs_completed(hapd
->iface
, err
);
985 wpa_printf(MSG_ERROR
,
986 "ACS: Possibly channel configuration is invalid");
989 #endif /* CONFIG_ACS */
992 int hostapd_probe_req_rx(struct hostapd_data
*hapd
, const u8
*sa
, const u8
*da
,
993 const u8
*bssid
, const u8
*ie
, size_t ie_len
,
999 if (sa
== NULL
|| ie
== NULL
)
1002 random_add_randomness(sa
, ETH_ALEN
);
1003 for (i
= 0; hapd
->probereq_cb
&& i
< hapd
->num_probereq_cb
; i
++) {
1004 if (hapd
->probereq_cb
[i
].cb(hapd
->probereq_cb
[i
].ctx
,
1005 sa
, da
, bssid
, ie
, ie_len
,
1017 #ifdef CONFIG_IEEE80211R_AP
1018 static void hostapd_notify_auth_ft_finish(void *ctx
, const u8
*dst
,
1020 u16 auth_transaction
, u16 status
,
1021 const u8
*ies
, size_t ies_len
)
1023 struct hostapd_data
*hapd
= ctx
;
1024 struct sta_info
*sta
;
1026 sta
= ap_get_sta(hapd
, dst
);
1030 hostapd_logger(hapd
, dst
, HOSTAPD_MODULE_IEEE80211
,
1031 HOSTAPD_LEVEL_DEBUG
, "authentication OK (FT)");
1032 sta
->flags
|= WLAN_STA_AUTH
;
1034 hostapd_sta_auth(hapd
, dst
, auth_transaction
, status
, ies
, ies_len
);
1036 #endif /* CONFIG_IEEE80211R_AP */
1040 static void hostapd_notify_auth_fils_finish(struct hostapd_data
*hapd
,
1041 struct sta_info
*sta
, u16 resp
,
1042 struct wpabuf
*data
, int pub
)
1044 if (resp
== WLAN_STATUS_SUCCESS
) {
1045 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1046 HOSTAPD_LEVEL_DEBUG
, "authentication OK (FILS)");
1047 sta
->flags
|= WLAN_STA_AUTH
;
1048 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
1049 sta
->auth_alg
= WLAN_AUTH_FILS_SK
;
1050 mlme_authenticate_indication(hapd
, sta
);
1052 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1053 HOSTAPD_LEVEL_DEBUG
,
1054 "authentication failed (FILS)");
1057 hostapd_sta_auth(hapd
, sta
->addr
, 2, resp
,
1058 data
? wpabuf_head(data
) : NULL
,
1059 data
? wpabuf_len(data
) : 0);
1062 #endif /* CONFIG_FILS */
1065 static void hostapd_notif_auth(struct hostapd_data
*hapd
,
1066 struct auth_info
*rx_auth
)
1068 struct sta_info
*sta
;
1069 u16 status
= WLAN_STATUS_SUCCESS
;
1070 u8 resp_ies
[2 + WLAN_AUTH_CHALLENGE_LEN
];
1071 size_t resp_ies_len
= 0;
1073 sta
= ap_get_sta(hapd
, rx_auth
->peer
);
1075 sta
= ap_sta_add(hapd
, rx_auth
->peer
);
1077 status
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
1081 sta
->flags
&= ~WLAN_STA_PREAUTH
;
1082 ieee802_1x_notify_pre_auth(sta
->eapol_sm
, 0);
1083 #ifdef CONFIG_IEEE80211R_AP
1084 if (rx_auth
->auth_type
== WLAN_AUTH_FT
&& hapd
->wpa_auth
) {
1085 sta
->auth_alg
= WLAN_AUTH_FT
;
1086 if (sta
->wpa_sm
== NULL
)
1087 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
1089 if (sta
->wpa_sm
== NULL
) {
1090 wpa_printf(MSG_DEBUG
,
1091 "FT: Failed to initialize WPA state machine");
1092 status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1095 wpa_ft_process_auth(sta
->wpa_sm
, rx_auth
->bssid
,
1096 rx_auth
->auth_transaction
, rx_auth
->ies
,
1098 hostapd_notify_auth_ft_finish
, hapd
);
1101 #endif /* CONFIG_IEEE80211R_AP */
1104 if (rx_auth
->auth_type
== WLAN_AUTH_FILS_SK
) {
1105 sta
->auth_alg
= WLAN_AUTH_FILS_SK
;
1106 handle_auth_fils(hapd
, sta
, rx_auth
->ies
, rx_auth
->ies_len
,
1107 rx_auth
->auth_type
, rx_auth
->auth_transaction
,
1108 rx_auth
->status_code
,
1109 hostapd_notify_auth_fils_finish
);
1112 #endif /* CONFIG_FILS */
1115 hostapd_sta_auth(hapd
, rx_auth
->peer
, rx_auth
->auth_transaction
+ 1,
1116 status
, resp_ies
, resp_ies_len
);
1120 #ifndef NEED_AP_MLME
1121 static void hostapd_action_rx(struct hostapd_data
*hapd
,
1122 struct rx_mgmt
*drv_mgmt
)
1124 struct ieee80211_mgmt
*mgmt
;
1125 struct sta_info
*sta
;
1126 size_t plen __maybe_unused
;
1128 u8
*action __maybe_unused
;
1130 if (drv_mgmt
->frame_len
< IEEE80211_HDRLEN
+ 2 + 1)
1133 plen
= drv_mgmt
->frame_len
- IEEE80211_HDRLEN
;
1135 mgmt
= (struct ieee80211_mgmt
*) drv_mgmt
->frame
;
1136 fc
= le_to_host16(mgmt
->frame_control
);
1137 if (WLAN_FC_GET_STYPE(fc
) != WLAN_FC_STYPE_ACTION
)
1138 return; /* handled by the driver */
1140 action
= (u8
*) &mgmt
->u
.action
.u
;
1141 wpa_printf(MSG_DEBUG
, "RX_ACTION category %u action %u sa " MACSTR
1142 " da " MACSTR
" plen %d",
1143 mgmt
->u
.action
.category
, *action
,
1144 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->da
), (int) plen
);
1146 sta
= ap_get_sta(hapd
, mgmt
->sa
);
1148 wpa_printf(MSG_DEBUG
, "%s: station not found", __func__
);
1151 #ifdef CONFIG_IEEE80211R_AP
1152 if (mgmt
->u
.action
.category
== WLAN_ACTION_FT
) {
1153 wpa_ft_action_rx(sta
->wpa_sm
, (u8
*) &mgmt
->u
.action
, plen
);
1156 #endif /* CONFIG_IEEE80211R_AP */
1157 #ifdef CONFIG_IEEE80211W
1158 if (mgmt
->u
.action
.category
== WLAN_ACTION_SA_QUERY
) {
1159 ieee802_11_sa_query_action(hapd
, mgmt
, drv_mgmt
->frame_len
);
1162 #endif /* CONFIG_IEEE80211W */
1163 #ifdef CONFIG_WNM_AP
1164 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
1165 ieee802_11_rx_wnm_action_ap(hapd
, mgmt
, drv_mgmt
->frame_len
);
1168 #endif /* CONFIG_WNM_AP */
1170 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& hapd
->iface
->fst
) {
1171 fst_rx_action(hapd
->iface
->fst
, mgmt
, drv_mgmt
->frame_len
);
1174 #endif /* CONFIG_FST */
1176 if (plen
>= 2 + 4 &&
1177 mgmt
->u
.action
.u
.vs_public_action
.action
==
1178 WLAN_PA_VENDOR_SPECIFIC
&&
1179 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
1181 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
1183 const u8
*pos
, *end
;
1185 pos
= mgmt
->u
.action
.u
.vs_public_action
.oui
;
1186 end
= drv_mgmt
->frame
+ drv_mgmt
->frame_len
;
1187 hostapd_dpp_rx_action(hapd
, mgmt
->sa
, pos
, end
- pos
,
1191 #endif /* CONFIG_DPP */
1193 #endif /* NEED_AP_MLME */
1198 #define HAPD_BROADCAST ((struct hostapd_data *) -1)
1200 static struct hostapd_data
* get_hapd_bssid(struct hostapd_iface
*iface
,
1207 if (bssid
[0] == 0xff && bssid
[1] == 0xff && bssid
[2] == 0xff &&
1208 bssid
[3] == 0xff && bssid
[4] == 0xff && bssid
[5] == 0xff)
1209 return HAPD_BROADCAST
;
1211 for (i
= 0; i
< iface
->num_bss
; i
++) {
1212 if (os_memcmp(bssid
, iface
->bss
[i
]->own_addr
, ETH_ALEN
) == 0)
1213 return iface
->bss
[i
];
1220 static void hostapd_rx_from_unknown_sta(struct hostapd_data
*hapd
,
1221 const u8
*bssid
, const u8
*addr
,
1224 hapd
= get_hapd_bssid(hapd
->iface
, bssid
);
1225 if (hapd
== NULL
|| hapd
== HAPD_BROADCAST
)
1228 ieee802_11_rx_from_unknown(hapd
, addr
, wds
);
1232 static int hostapd_mgmt_rx(struct hostapd_data
*hapd
, struct rx_mgmt
*rx_mgmt
)
1234 struct hostapd_iface
*iface
= hapd
->iface
;
1235 const struct ieee80211_hdr
*hdr
;
1237 struct hostapd_frame_info fi
;
1240 #ifdef CONFIG_TESTING_OPTIONS
1241 if (hapd
->ext_mgmt_frame_handling
) {
1242 size_t hex_len
= 2 * rx_mgmt
->frame_len
+ 1;
1243 char *hex
= os_malloc(hex_len
);
1246 wpa_snprintf_hex(hex
, hex_len
, rx_mgmt
->frame
,
1247 rx_mgmt
->frame_len
);
1248 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "MGMT-RX %s", hex
);
1253 #endif /* CONFIG_TESTING_OPTIONS */
1255 hdr
= (const struct ieee80211_hdr
*) rx_mgmt
->frame
;
1256 bssid
= get_hdr_bssid(hdr
, rx_mgmt
->frame_len
);
1260 hapd
= get_hapd_bssid(iface
, bssid
);
1262 u16 fc
= le_to_host16(hdr
->frame_control
);
1265 * Drop frames to unknown BSSIDs except for Beacon frames which
1266 * could be used to update neighbor information.
1268 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
1269 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
1270 hapd
= iface
->bss
[0];
1275 os_memset(&fi
, 0, sizeof(fi
));
1276 fi
.freq
= rx_mgmt
->freq
;
1277 fi
.datarate
= rx_mgmt
->datarate
;
1278 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
1280 if (hapd
== HAPD_BROADCAST
) {
1284 for (i
= 0; i
< iface
->num_bss
; i
++) {
1285 /* if bss is set, driver will call this function for
1286 * each bss individually. */
1287 if (rx_mgmt
->drv_priv
&&
1288 (iface
->bss
[i
]->drv_priv
!= rx_mgmt
->drv_priv
))
1291 if (ieee802_11_mgmt(iface
->bss
[i
], rx_mgmt
->frame
,
1292 rx_mgmt
->frame_len
, &fi
) > 0)
1296 ret
= ieee802_11_mgmt(hapd
, rx_mgmt
->frame
, rx_mgmt
->frame_len
,
1299 random_add_randomness(&fi
, sizeof(fi
));
1305 static void hostapd_mgmt_tx_cb(struct hostapd_data
*hapd
, const u8
*buf
,
1306 size_t len
, u16 stype
, int ok
)
1308 struct ieee80211_hdr
*hdr
;
1309 struct hostapd_data
*orig_hapd
= hapd
;
1311 hdr
= (struct ieee80211_hdr
*) buf
;
1312 hapd
= get_hapd_bssid(hapd
->iface
, get_hdr_bssid(hdr
, len
));
1315 if (hapd
== HAPD_BROADCAST
) {
1316 if (stype
!= WLAN_FC_STYPE_ACTION
|| len
<= 25 ||
1317 buf
[24] != WLAN_ACTION_PUBLIC
)
1319 hapd
= get_hapd_bssid(orig_hapd
->iface
, hdr
->addr2
);
1320 if (!hapd
|| hapd
== HAPD_BROADCAST
)
1323 * Allow processing of TX status for a Public Action frame that
1324 * used wildcard BBSID.
1327 ieee802_11_mgmt_cb(hapd
, buf
, len
, stype
, ok
);
1330 #endif /* NEED_AP_MLME */
1333 static int hostapd_event_new_sta(struct hostapd_data
*hapd
, const u8
*addr
)
1335 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
1340 wpa_printf(MSG_DEBUG
, "Data frame from unknown STA " MACSTR
1341 " - adding a new STA", MAC2STR(addr
));
1342 sta
= ap_sta_add(hapd
, addr
);
1344 hostapd_new_assoc_sta(hapd
, sta
, 0);
1346 wpa_printf(MSG_DEBUG
, "Failed to add STA entry for " MACSTR
,
1355 static void hostapd_event_eapol_rx(struct hostapd_data
*hapd
, const u8
*src
,
1356 const u8
*data
, size_t data_len
)
1358 struct hostapd_iface
*iface
= hapd
->iface
;
1359 struct sta_info
*sta
;
1362 for (j
= 0; j
< iface
->num_bss
; j
++) {
1363 sta
= ap_get_sta(iface
->bss
[j
], src
);
1364 if (sta
&& sta
->flags
& WLAN_STA_ASSOC
) {
1365 hapd
= iface
->bss
[j
];
1370 ieee802_1x_receive(hapd
, src
, data
, data_len
);
1373 #endif /* HOSTAPD */
1376 static struct hostapd_channel_data
* hostapd_get_mode_channel(
1377 struct hostapd_iface
*iface
, unsigned int freq
)
1380 struct hostapd_channel_data
*chan
;
1382 for (i
= 0; i
< iface
->current_mode
->num_channels
; i
++) {
1383 chan
= &iface
->current_mode
->channels
[i
];
1384 if ((unsigned int) chan
->freq
== freq
)
1392 static void hostapd_update_nf(struct hostapd_iface
*iface
,
1393 struct hostapd_channel_data
*chan
,
1394 struct freq_survey
*survey
)
1396 if (!iface
->chans_surveyed
) {
1397 chan
->min_nf
= survey
->nf
;
1398 iface
->lowest_nf
= survey
->nf
;
1400 if (dl_list_empty(&chan
->survey_list
))
1401 chan
->min_nf
= survey
->nf
;
1402 else if (survey
->nf
< chan
->min_nf
)
1403 chan
->min_nf
= survey
->nf
;
1404 if (survey
->nf
< iface
->lowest_nf
)
1405 iface
->lowest_nf
= survey
->nf
;
1410 static void hostapd_single_channel_get_survey(struct hostapd_iface
*iface
,
1411 struct survey_results
*survey_res
)
1413 struct hostapd_channel_data
*chan
;
1414 struct freq_survey
*survey
;
1415 u64 divisor
, dividend
;
1417 survey
= dl_list_first(&survey_res
->survey_list
, struct freq_survey
,
1419 if (!survey
|| !survey
->freq
)
1422 chan
= hostapd_get_mode_channel(iface
, survey
->freq
);
1423 if (!chan
|| chan
->flag
& HOSTAPD_CHAN_DISABLED
)
1426 wpa_printf(MSG_DEBUG
,
1427 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
1429 (unsigned long int) survey
->channel_time
,
1430 (unsigned long int) survey
->channel_time_busy
);
1432 if (survey
->channel_time
> iface
->last_channel_time
&&
1433 survey
->channel_time
> survey
->channel_time_busy
) {
1434 dividend
= survey
->channel_time_busy
-
1435 iface
->last_channel_time_busy
;
1436 divisor
= survey
->channel_time
- iface
->last_channel_time
;
1438 iface
->channel_utilization
= dividend
* 255 / divisor
;
1439 wpa_printf(MSG_DEBUG
, "Channel Utilization: %d",
1440 iface
->channel_utilization
);
1442 iface
->last_channel_time
= survey
->channel_time
;
1443 iface
->last_channel_time_busy
= survey
->channel_time_busy
;
1447 void hostapd_event_get_survey(struct hostapd_iface
*iface
,
1448 struct survey_results
*survey_results
)
1450 struct freq_survey
*survey
, *tmp
;
1451 struct hostapd_channel_data
*chan
;
1453 if (dl_list_empty(&survey_results
->survey_list
)) {
1454 wpa_printf(MSG_DEBUG
, "No survey data received");
1458 if (survey_results
->freq_filter
) {
1459 hostapd_single_channel_get_survey(iface
, survey_results
);
1463 dl_list_for_each_safe(survey
, tmp
, &survey_results
->survey_list
,
1464 struct freq_survey
, list
) {
1465 chan
= hostapd_get_mode_channel(iface
, survey
->freq
);
1468 if (chan
->flag
& HOSTAPD_CHAN_DISABLED
)
1471 dl_list_del(&survey
->list
);
1472 dl_list_add_tail(&chan
->survey_list
, &survey
->list
);
1474 hostapd_update_nf(iface
, chan
, survey
);
1476 iface
->chans_surveyed
++;
1484 static void hostapd_event_iface_unavailable(struct hostapd_data
*hapd
)
1486 wpa_printf(MSG_DEBUG
, "Interface %s is unavailable -- stopped",
1489 if (hapd
->csa_in_progress
) {
1490 wpa_printf(MSG_INFO
, "CSA failed (%s was stopped)",
1492 hostapd_switch_channel_fallback(hapd
->iface
,
1493 &hapd
->cs_freq_params
);
1498 static void hostapd_event_dfs_radar_detected(struct hostapd_data
*hapd
,
1499 struct dfs_event
*radar
)
1501 wpa_printf(MSG_DEBUG
, "DFS radar detected on %d MHz", radar
->freq
);
1502 hostapd_dfs_radar_detected(hapd
->iface
, radar
->freq
, radar
->ht_enabled
,
1503 radar
->chan_offset
, radar
->chan_width
,
1504 radar
->cf1
, radar
->cf2
);
1508 static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data
*hapd
,
1509 struct dfs_event
*radar
)
1511 wpa_printf(MSG_DEBUG
, "DFS Pre-CAC expired on %d MHz", radar
->freq
);
1512 hostapd_dfs_pre_cac_expired(hapd
->iface
, radar
->freq
, radar
->ht_enabled
,
1513 radar
->chan_offset
, radar
->chan_width
,
1514 radar
->cf1
, radar
->cf2
);
1518 static void hostapd_event_dfs_cac_finished(struct hostapd_data
*hapd
,
1519 struct dfs_event
*radar
)
1521 wpa_printf(MSG_DEBUG
, "DFS CAC finished on %d MHz", radar
->freq
);
1522 hostapd_dfs_complete_cac(hapd
->iface
, 1, radar
->freq
, radar
->ht_enabled
,
1523 radar
->chan_offset
, radar
->chan_width
,
1524 radar
->cf1
, radar
->cf2
);
1528 static void hostapd_event_dfs_cac_aborted(struct hostapd_data
*hapd
,
1529 struct dfs_event
*radar
)
1531 wpa_printf(MSG_DEBUG
, "DFS CAC aborted on %d MHz", radar
->freq
);
1532 hostapd_dfs_complete_cac(hapd
->iface
, 0, radar
->freq
, radar
->ht_enabled
,
1533 radar
->chan_offset
, radar
->chan_width
,
1534 radar
->cf1
, radar
->cf2
);
1538 static void hostapd_event_dfs_nop_finished(struct hostapd_data
*hapd
,
1539 struct dfs_event
*radar
)
1541 wpa_printf(MSG_DEBUG
, "DFS NOP finished on %d MHz", radar
->freq
);
1542 hostapd_dfs_nop_finished(hapd
->iface
, radar
->freq
, radar
->ht_enabled
,
1543 radar
->chan_offset
, radar
->chan_width
,
1544 radar
->cf1
, radar
->cf2
);
1548 static void hostapd_event_dfs_cac_started(struct hostapd_data
*hapd
,
1549 struct dfs_event
*radar
)
1551 wpa_printf(MSG_DEBUG
, "DFS offload CAC started on %d MHz", radar
->freq
);
1552 hostapd_dfs_start_cac(hapd
->iface
, radar
->freq
, radar
->ht_enabled
,
1553 radar
->chan_offset
, radar
->chan_width
,
1554 radar
->cf1
, radar
->cf2
);
1557 #endif /* NEED_AP_MLME */
1560 static void hostapd_event_wds_sta_interface_status(struct hostapd_data
*hapd
,
1565 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
1568 os_free(sta
->ifname_wds
);
1569 if (istatus
== INTERFACE_ADDED
)
1570 sta
->ifname_wds
= os_strdup(ifname
);
1572 sta
->ifname_wds
= NULL
;
1575 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "%sifname=%s sta_addr=" MACSTR
,
1576 istatus
== INTERFACE_ADDED
?
1577 WDS_STA_INTERFACE_ADDED
: WDS_STA_INTERFACE_REMOVED
,
1578 ifname
, MAC2STR(addr
));
1582 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
1583 union wpa_event_data
*data
)
1585 struct hostapd_data
*hapd
= ctx
;
1586 #ifndef CONFIG_NO_STDOUT_DEBUG
1587 int level
= MSG_DEBUG
;
1589 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame
&&
1590 data
->rx_mgmt
.frame_len
>= 24) {
1591 const struct ieee80211_hdr
*hdr
;
1594 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
1595 fc
= le_to_host16(hdr
->frame_control
);
1596 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
1597 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
1598 level
= MSG_EXCESSIVE
;
1599 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
1600 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_REQ
)
1601 level
= MSG_EXCESSIVE
;
1604 wpa_dbg(hapd
->msg_ctx
, level
, "Event %s (%d) received",
1605 event_to_string(event
), event
);
1606 #endif /* CONFIG_NO_STDOUT_DEBUG */
1609 case EVENT_MICHAEL_MIC_FAILURE
:
1610 michael_mic_failure(hapd
, data
->michael_mic_failure
.src
, 1);
1612 case EVENT_SCAN_RESULTS
:
1613 if (hapd
->iface
->scan_cb
)
1614 hapd
->iface
->scan_cb(hapd
->iface
);
1616 case EVENT_WPS_BUTTON_PUSHED
:
1617 hostapd_wps_button_pushed(hapd
, NULL
);
1620 case EVENT_TX_STATUS
:
1621 switch (data
->tx_status
.type
) {
1622 case WLAN_FC_TYPE_MGMT
:
1623 hostapd_mgmt_tx_cb(hapd
, data
->tx_status
.data
,
1624 data
->tx_status
.data_len
,
1625 data
->tx_status
.stype
,
1626 data
->tx_status
.ack
);
1628 case WLAN_FC_TYPE_DATA
:
1629 hostapd_tx_status(hapd
, data
->tx_status
.dst
,
1630 data
->tx_status
.data
,
1631 data
->tx_status
.data_len
,
1632 data
->tx_status
.ack
);
1636 case EVENT_EAPOL_TX_STATUS
:
1637 hostapd_eapol_tx_status(hapd
, data
->eapol_tx_status
.dst
,
1638 data
->eapol_tx_status
.data
,
1639 data
->eapol_tx_status
.data_len
,
1640 data
->eapol_tx_status
.ack
);
1642 case EVENT_DRIVER_CLIENT_POLL_OK
:
1643 hostapd_client_poll_ok(hapd
, data
->client_poll
.addr
);
1645 case EVENT_RX_FROM_UNKNOWN
:
1646 hostapd_rx_from_unknown_sta(hapd
, data
->rx_from_unknown
.bssid
,
1647 data
->rx_from_unknown
.addr
,
1648 data
->rx_from_unknown
.wds
);
1650 #endif /* NEED_AP_MLME */
1652 if (!data
->rx_mgmt
.frame
)
1655 hostapd_mgmt_rx(hapd
, &data
->rx_mgmt
);
1656 #else /* NEED_AP_MLME */
1657 hostapd_action_rx(hapd
, &data
->rx_mgmt
);
1658 #endif /* NEED_AP_MLME */
1660 case EVENT_RX_PROBE_REQ
:
1661 if (data
->rx_probe_req
.sa
== NULL
||
1662 data
->rx_probe_req
.ie
== NULL
)
1664 hostapd_probe_req_rx(hapd
, data
->rx_probe_req
.sa
,
1665 data
->rx_probe_req
.da
,
1666 data
->rx_probe_req
.bssid
,
1667 data
->rx_probe_req
.ie
,
1668 data
->rx_probe_req
.ie_len
,
1669 data
->rx_probe_req
.ssi_signal
);
1672 hostapd_event_new_sta(hapd
, data
->new_sta
.addr
);
1674 case EVENT_EAPOL_RX
:
1675 hostapd_event_eapol_rx(hapd
, data
->eapol_rx
.src
,
1676 data
->eapol_rx
.data
,
1677 data
->eapol_rx
.data_len
);
1682 hostapd_notif_assoc(hapd
, data
->assoc_info
.addr
,
1683 data
->assoc_info
.req_ies
,
1684 data
->assoc_info
.req_ies_len
,
1685 data
->assoc_info
.reassoc
);
1687 case EVENT_DISASSOC
:
1689 hostapd_notif_disassoc(hapd
, data
->disassoc_info
.addr
);
1693 hostapd_notif_disassoc(hapd
, data
->deauth_info
.addr
);
1695 case EVENT_STATION_LOW_ACK
:
1698 hostapd_event_sta_low_ack(hapd
, data
->low_ack
.addr
);
1701 hostapd_notif_auth(hapd
, &data
->auth
);
1703 case EVENT_CH_SWITCH_STARTED
:
1704 case EVENT_CH_SWITCH
:
1707 hostapd_event_ch_switch(hapd
, data
->ch_switch
.freq
,
1708 data
->ch_switch
.ht_enabled
,
1709 data
->ch_switch
.ch_offset
,
1710 data
->ch_switch
.ch_width
,
1711 data
->ch_switch
.cf1
,
1712 data
->ch_switch
.cf2
,
1713 event
== EVENT_CH_SWITCH
);
1715 case EVENT_CONNECT_FAILED_REASON
:
1718 hostapd_event_connect_failed_reason(
1719 hapd
, data
->connect_failed_reason
.addr
,
1720 data
->connect_failed_reason
.code
);
1723 hostapd_event_get_survey(hapd
->iface
, &data
->survey_results
);
1726 case EVENT_INTERFACE_UNAVAILABLE
:
1727 hostapd_event_iface_unavailable(hapd
);
1729 case EVENT_DFS_RADAR_DETECTED
:
1732 hostapd_event_dfs_radar_detected(hapd
, &data
->dfs_event
);
1734 case EVENT_DFS_PRE_CAC_EXPIRED
:
1737 hostapd_event_dfs_pre_cac_expired(hapd
, &data
->dfs_event
);
1739 case EVENT_DFS_CAC_FINISHED
:
1742 hostapd_event_dfs_cac_finished(hapd
, &data
->dfs_event
);
1744 case EVENT_DFS_CAC_ABORTED
:
1747 hostapd_event_dfs_cac_aborted(hapd
, &data
->dfs_event
);
1749 case EVENT_DFS_NOP_FINISHED
:
1752 hostapd_event_dfs_nop_finished(hapd
, &data
->dfs_event
);
1754 case EVENT_CHANNEL_LIST_CHANGED
:
1755 /* channel list changed (regulatory?), update channel list */
1756 /* TODO: check this. hostapd_get_hw_features() initializes
1757 * too much stuff. */
1758 /* hostapd_get_hw_features(hapd->iface); */
1759 hostapd_channel_list_updated(
1760 hapd
->iface
, data
->channel_list_changed
.initiator
);
1762 case EVENT_DFS_CAC_STARTED
:
1765 hostapd_event_dfs_cac_started(hapd
, &data
->dfs_event
);
1767 #endif /* NEED_AP_MLME */
1768 case EVENT_INTERFACE_ENABLED
:
1769 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, INTERFACE_ENABLED
);
1770 if (hapd
->disabled
&& hapd
->started
) {
1773 * Try to re-enable interface if the driver stopped it
1774 * when the interface got disabled.
1777 wpa_auth_reconfig_group_keys(hapd
->wpa_auth
);
1779 hostapd_reconfig_encryption(hapd
);
1780 hapd
->reenable_beacon
= 1;
1781 ieee802_11_set_beacon(hapd
);
1783 } else if (hapd
->disabled
&& hapd
->iface
->cac_started
) {
1784 wpa_printf(MSG_DEBUG
, "DFS: restarting pending CAC");
1785 hostapd_handle_dfs(hapd
->iface
);
1786 #endif /* NEED_AP_MLME */
1789 case EVENT_INTERFACE_DISABLED
:
1790 hostapd_free_stas(hapd
);
1791 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, INTERFACE_DISABLED
);
1795 case EVENT_ACS_CHANNEL_SELECTED
:
1796 hostapd_acs_channel_selected(hapd
,
1797 &data
->acs_selected_channels
);
1799 #endif /* CONFIG_ACS */
1800 case EVENT_STATION_OPMODE_CHANGED
:
1801 hostapd_event_sta_opmode_changed(hapd
, data
->sta_opmode
.addr
,
1802 data
->sta_opmode
.smps_mode
,
1803 data
->sta_opmode
.chan_width
,
1804 data
->sta_opmode
.rx_nss
);
1806 case EVENT_WDS_STA_INTERFACE_STATUS
:
1807 hostapd_event_wds_sta_interface_status(
1808 hapd
, data
->wds_sta_interface
.istatus
,
1809 data
->wds_sta_interface
.ifname
,
1810 data
->wds_sta_interface
.sta_addr
);
1813 wpa_printf(MSG_DEBUG
, "Unknown event %d", event
);
1819 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
1820 union wpa_event_data
*data
)
1822 struct hapd_interfaces
*interfaces
= ctx
;
1823 struct hostapd_data
*hapd
;
1825 if (event
!= EVENT_INTERFACE_STATUS
)
1828 hapd
= hostapd_get_iface(interfaces
, data
->interface_status
.ifname
);
1829 if (hapd
&& hapd
->driver
&& hapd
->driver
->get_ifindex
&&
1831 unsigned int ifindex
;
1833 ifindex
= hapd
->driver
->get_ifindex(hapd
->drv_priv
);
1834 if (ifindex
!= data
->interface_status
.ifindex
) {
1835 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
1836 "interface status ifindex %d mismatch (%d)",
1837 ifindex
, data
->interface_status
.ifindex
);
1842 wpa_supplicant_event(hapd
, event
, data
);
1845 #endif /* HOSTAPD */