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 "crypto/random.h"
24 #include "ieee802_11.h"
25 #include "ieee802_11_auth.h"
27 #include "accounting.h"
28 #include "tkip_countermeasures.h"
29 #include "ieee802_1x.h"
31 #include "wps_hostapd.h"
32 #include "ap_drv_ops.h"
33 #include "ap_config.h"
35 #include "hw_features.h"
39 #include "dpp_hostapd.h"
44 void hostapd_notify_assoc_fils_finish(struct hostapd_data
*hapd
,
47 u16 reply_res
= WLAN_STATUS_SUCCESS
;
48 struct ieee802_11_elems elems
;
49 u8 buf
[IEEE80211_MAX_MMPDU_SIZE
], *p
= buf
;
52 wpa_printf(MSG_DEBUG
, "%s FILS: Finish association with " MACSTR
,
53 __func__
, MAC2STR(sta
->addr
));
54 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
55 if (!sta
->fils_pending_assoc_req
)
58 ieee802_11_parse_elems(sta
->fils_pending_assoc_req
,
59 sta
->fils_pending_assoc_req_len
, &elems
, 0);
60 if (!elems
.fils_session
) {
61 wpa_printf(MSG_DEBUG
, "%s failed to find FILS Session element",
66 p
= hostapd_eid_assoc_fils_session(sta
->wpa_sm
, p
,
70 reply_res
= hostapd_sta_assoc(hapd
, sta
->addr
,
71 sta
->fils_pending_assoc_is_reassoc
,
74 ap_sta_set_authorized(hapd
, sta
, 1);
75 new_assoc
= (sta
->flags
& WLAN_STA_ASSOC
) == 0;
76 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
77 sta
->flags
&= ~WLAN_STA_WNM_SLEEP_MODE
;
78 hostapd_set_sta_flags(hapd
, sta
);
79 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC_FILS
);
80 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 1);
81 hostapd_new_assoc_sta(hapd
, sta
, !new_assoc
);
82 os_free(sta
->fils_pending_assoc_req
);
83 sta
->fils_pending_assoc_req
= NULL
;
84 sta
->fils_pending_assoc_req_len
= 0;
85 wpabuf_free(sta
->fils_hlp_resp
);
86 sta
->fils_hlp_resp
= NULL
;
87 wpabuf_free(sta
->hlp_dhcp_discover
);
88 sta
->hlp_dhcp_discover
= NULL
;
89 fils_hlp_deinit(hapd
);
92 * Remove the station in case transmission of a success response fails
93 * (the STA was added associated to the driver) or if the station was
94 * previously added unassociated.
96 if (reply_res
!= WLAN_STATUS_SUCCESS
|| sta
->added_unassoc
) {
97 hostapd_drv_sta_remove(hapd
, sta
->addr
);
98 sta
->added_unassoc
= 0;
101 #endif /* CONFIG_FILS */
104 int hostapd_notif_assoc(struct hostapd_data
*hapd
, const u8
*addr
,
105 const u8
*req_ies
, size_t req_ies_len
, int reassoc
)
107 struct sta_info
*sta
;
109 struct ieee802_11_elems elems
;
112 #if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_IEEE80211W) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
113 u8 buf
[sizeof(struct ieee80211_mgmt
) + 1024];
115 #endif /* CONFIG_IEEE80211R_AP || CONFIG_IEEE80211W || CONFIG_FILS || CONFIG_OWE */
116 u16 reason
= WLAN_REASON_UNSPECIFIED
;
117 u16 status
= WLAN_STATUS_SUCCESS
;
118 const u8
*p2p_dev_addr
= NULL
;
122 * This could potentially happen with unexpected event from the
123 * driver wrapper. This was seen at least in one case where the
124 * driver ended up being set to station mode while hostapd was
125 * running, so better make sure we stop processing such an
128 wpa_printf(MSG_DEBUG
,
129 "hostapd_notif_assoc: Skip event with no address");
132 random_add_randomness(addr
, ETH_ALEN
);
134 hostapd_logger(hapd
, addr
, HOSTAPD_MODULE_IEEE80211
,
135 HOSTAPD_LEVEL_INFO
, "associated");
137 ieee802_11_parse_elems(req_ies
, req_ies_len
, &elems
, 0);
139 ie
= elems
.wps_ie
- 2;
140 ielen
= elems
.wps_ie_len
+ 2;
141 wpa_printf(MSG_DEBUG
, "STA included WPS IE in (Re)AssocReq");
142 } else if (elems
.rsn_ie
) {
143 ie
= elems
.rsn_ie
- 2;
144 ielen
= elems
.rsn_ie_len
+ 2;
145 wpa_printf(MSG_DEBUG
, "STA included RSN IE in (Re)AssocReq");
146 } else if (elems
.wpa_ie
) {
147 ie
= elems
.wpa_ie
- 2;
148 ielen
= elems
.wpa_ie_len
+ 2;
149 wpa_printf(MSG_DEBUG
, "STA included WPA IE in (Re)AssocReq");
151 } else if (elems
.osen
) {
153 ielen
= elems
.osen_len
+ 2;
154 wpa_printf(MSG_DEBUG
, "STA included OSEN IE in (Re)AssocReq");
155 #endif /* CONFIG_HS20 */
159 wpa_printf(MSG_DEBUG
,
160 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
163 sta
= ap_get_sta(hapd
, addr
);
165 ap_sta_no_session_timeout(hapd
, sta
);
166 accounting_sta_stop(hapd
, sta
);
169 * Make sure that the previously registered inactivity timer
170 * will not remove the STA immediately.
172 sta
->timeout_next
= STA_NULLFUNC
;
174 sta
= ap_sta_add(hapd
, addr
);
176 hostapd_drv_sta_disassoc(hapd
, addr
,
177 WLAN_REASON_DISASSOC_AP_BUSY
);
181 sta
->flags
&= ~(WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
| WLAN_STA_WPS2
);
184 * ACL configurations to the drivers (implementing AP SME and ACL
185 * offload) without hostapd's knowledge, can result in a disconnection
186 * though the driver accepts the connection. Skip the hostapd check for
187 * ACL if the driver supports ACL offload to avoid potentially
188 * conflicting ACL rules.
190 if (hapd
->iface
->drv_max_acl_mac_addrs
== 0 &&
191 hostapd_check_acl(hapd
, addr
, NULL
) != HOSTAPD_ACL_ACCEPT
) {
192 wpa_printf(MSG_INFO
, "STA " MACSTR
" not allowed to connect",
194 reason
= WLAN_REASON_UNSPECIFIED
;
200 wpabuf_free(sta
->p2p_ie
);
201 sta
->p2p_ie
= ieee802_11_vendor_ie_concat(req_ies
, req_ies_len
,
204 p2p_dev_addr
= p2p_get_go_dev_addr(sta
->p2p_ie
);
206 #endif /* CONFIG_P2P */
208 #ifdef CONFIG_IEEE80211N
210 if (elems
.ht_capabilities
&&
211 (hapd
->iface
->conf
->ht_capab
&
212 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
)) {
213 struct ieee80211_ht_capabilities
*ht_cap
=
214 (struct ieee80211_ht_capabilities
*)
215 elems
.ht_capabilities
;
217 if (le_to_host16(ht_cap
->ht_capabilities_info
) &
218 HT_CAP_INFO_40MHZ_INTOLERANT
)
219 ht40_intolerant_add(hapd
->iface
, sta
);
221 #endif /* NEED_AP_MLME */
222 #endif /* CONFIG_IEEE80211N */
224 #ifdef CONFIG_INTERWORKING
225 if (elems
.ext_capab
&& elems
.ext_capab_len
> 4) {
226 if (elems
.ext_capab
[4] & 0x01)
227 sta
->qos_map_enabled
= 1;
229 #endif /* CONFIG_INTERWORKING */
232 wpabuf_free(sta
->hs20_ie
);
233 if (elems
.hs20
&& elems
.hs20_len
> 4) {
234 sta
->hs20_ie
= wpabuf_alloc_copy(elems
.hs20
+ 4,
239 wpabuf_free(sta
->roaming_consortium
);
240 if (elems
.roaming_cons_sel
)
241 sta
->roaming_consortium
= wpabuf_alloc_copy(
242 elems
.roaming_cons_sel
+ 4,
243 elems
.roaming_cons_sel_len
- 4);
245 sta
->roaming_consortium
= NULL
;
246 #endif /* CONFIG_HS20 */
249 wpabuf_free(sta
->mb_ies
);
250 if (hapd
->iface
->fst
)
251 sta
->mb_ies
= mb_ies_by_info(&elems
.mb_ies
);
254 #endif /* CONFIG_FST */
256 mbo_ap_check_sta_assoc(hapd
, sta
, &elems
);
258 ap_copy_sta_supp_op_classes(sta
, elems
.supp_op_classes
,
259 elems
.supp_op_classes_len
);
261 if (hapd
->conf
->wpa
) {
262 if (ie
== NULL
|| ielen
== 0) {
264 if (hapd
->conf
->wps_state
) {
265 wpa_printf(MSG_DEBUG
,
266 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
267 sta
->flags
|= WLAN_STA_MAYBE_WPS
;
270 #endif /* CONFIG_WPS */
272 wpa_printf(MSG_DEBUG
, "No WPA/RSN IE from STA");
273 reason
= WLAN_REASON_INVALID_IE
;
274 status
= WLAN_STATUS_INVALID_IE
;
278 if (hapd
->conf
->wps_state
&& ie
[0] == 0xdd && ie
[1] >= 4 &&
279 os_memcmp(ie
+ 2, "\x00\x50\xf2\x04", 4) == 0) {
282 sta
->flags
|= WLAN_STA_WPS
;
283 wps
= ieee802_11_vendor_ie_concat(ie
, ielen
,
286 if (wps_is_20(wps
)) {
287 wpa_printf(MSG_DEBUG
,
288 "WPS: STA supports WPS 2.0");
289 sta
->flags
|= WLAN_STA_WPS2
;
295 #endif /* CONFIG_WPS */
297 if (sta
->wpa_sm
== NULL
)
298 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
301 if (sta
->wpa_sm
== NULL
) {
302 wpa_printf(MSG_ERROR
,
303 "Failed to initialize WPA state machine");
306 res
= wpa_validate_wpa_ie(hapd
->wpa_auth
, sta
->wpa_sm
,
308 elems
.mdie
, elems
.mdie_len
,
309 elems
.owe_dh
, elems
.owe_dh_len
);
310 if (res
!= WPA_IE_OK
) {
311 wpa_printf(MSG_DEBUG
,
312 "WPA/RSN information element rejected? (res %u)",
314 wpa_hexdump(MSG_DEBUG
, "IE", ie
, ielen
);
315 if (res
== WPA_INVALID_GROUP
) {
316 reason
= WLAN_REASON_GROUP_CIPHER_NOT_VALID
;
317 status
= WLAN_STATUS_GROUP_CIPHER_NOT_VALID
;
318 } else if (res
== WPA_INVALID_PAIRWISE
) {
319 reason
= WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID
;
320 status
= WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID
;
321 } else if (res
== WPA_INVALID_AKMP
) {
322 reason
= WLAN_REASON_AKMP_NOT_VALID
;
323 status
= WLAN_STATUS_AKMP_NOT_VALID
;
325 #ifdef CONFIG_IEEE80211W
326 else if (res
== WPA_MGMT_FRAME_PROTECTION_VIOLATION
) {
327 reason
= WLAN_REASON_INVALID_IE
;
328 status
= WLAN_STATUS_INVALID_IE
;
329 } else if (res
== WPA_INVALID_MGMT_GROUP_CIPHER
) {
330 reason
= WLAN_REASON_CIPHER_SUITE_REJECTED
;
331 status
= WLAN_STATUS_CIPHER_REJECTED_PER_POLICY
;
333 #endif /* CONFIG_IEEE80211W */
335 reason
= WLAN_REASON_INVALID_IE
;
336 status
= WLAN_STATUS_INVALID_IE
;
340 #ifdef CONFIG_IEEE80211W
341 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
342 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
343 !sta
->sa_query_timed_out
&&
344 sta
->sa_query_count
> 0)
345 ap_check_sa_query_timeout(hapd
, sta
);
346 if ((sta
->flags
& (WLAN_STA_ASSOC
| WLAN_STA_MFP
)) ==
347 (WLAN_STA_ASSOC
| WLAN_STA_MFP
) &&
348 !sta
->sa_query_timed_out
&&
349 (sta
->auth_alg
!= WLAN_AUTH_FT
)) {
351 * STA has already been associated with MFP and SA
352 * Query timeout has not been reached. Reject the
353 * association attempt temporarily and start SA Query,
354 * if one is not pending.
357 if (sta
->sa_query_count
== 0)
358 ap_sta_start_sa_query(hapd
, sta
);
360 status
= WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
;
362 p
= hostapd_eid_assoc_comeback_time(hapd
, sta
, p
);
364 hostapd_sta_assoc(hapd
, addr
, reassoc
, status
, buf
,
369 if (wpa_auth_uses_mfp(sta
->wpa_sm
))
370 sta
->flags
|= WLAN_STA_MFP
;
372 sta
->flags
&= ~WLAN_STA_MFP
;
373 #endif /* CONFIG_IEEE80211W */
375 #ifdef CONFIG_IEEE80211R_AP
376 if (sta
->auth_alg
== WLAN_AUTH_FT
) {
377 status
= wpa_ft_validate_reassoc(sta
->wpa_sm
, req_ies
,
379 if (status
!= WLAN_STATUS_SUCCESS
) {
380 if (status
== WLAN_STATUS_INVALID_PMKID
)
381 reason
= WLAN_REASON_INVALID_IE
;
382 if (status
== WLAN_STATUS_INVALID_MDIE
)
383 reason
= WLAN_REASON_INVALID_IE
;
384 if (status
== WLAN_STATUS_INVALID_FTIE
)
385 reason
= WLAN_REASON_INVALID_IE
;
389 #endif /* CONFIG_IEEE80211R_AP */
390 } else if (hapd
->conf
->wps_state
) {
395 wps
= ieee802_11_vendor_ie_concat(req_ies
, req_ies_len
,
399 #ifdef CONFIG_WPS_STRICT
400 if (wps
&& wps_validate_assoc_req(wps
) < 0) {
401 reason
= WLAN_REASON_INVALID_IE
;
402 status
= WLAN_STATUS_INVALID_IE
;
406 #endif /* CONFIG_WPS_STRICT */
408 sta
->flags
|= WLAN_STA_WPS
;
409 if (wps_is_20(wps
)) {
410 wpa_printf(MSG_DEBUG
,
411 "WPS: STA supports WPS 2.0");
412 sta
->flags
|= WLAN_STA_WPS2
;
415 sta
->flags
|= WLAN_STA_MAYBE_WPS
;
417 #endif /* CONFIG_WPS */
419 } else if (hapd
->conf
->osen
) {
420 if (elems
.osen
== NULL
) {
422 hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
424 "No HS 2.0 OSEN element in association request");
425 return WLAN_STATUS_INVALID_IE
;
428 wpa_printf(MSG_DEBUG
, "HS 2.0: OSEN association");
429 if (sta
->wpa_sm
== NULL
)
430 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
432 if (sta
->wpa_sm
== NULL
) {
433 wpa_printf(MSG_WARNING
,
434 "Failed to initialize WPA state machine");
435 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
437 if (wpa_validate_osen(hapd
->wpa_auth
, sta
->wpa_sm
,
438 elems
.osen
- 2, elems
.osen_len
+ 2) < 0)
439 return WLAN_STATUS_INVALID_IE
;
440 #endif /* CONFIG_HS20 */
444 if (hapd
->conf
->mbo_enabled
&& (hapd
->conf
->wpa
& 2) &&
445 elems
.mbo
&& sta
->cell_capa
&& !(sta
->flags
& WLAN_STA_MFP
) &&
446 hapd
->conf
->ieee80211w
!= NO_MGMT_FRAME_PROTECTION
) {
448 "MBO: Reject WPA2 association without PMF");
449 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
451 #endif /* CONFIG_MBO */
455 #endif /* CONFIG_WPS */
457 #ifdef CONFIG_IEEE80211R_AP
458 p
= wpa_sm_write_assoc_resp_ies(sta
->wpa_sm
, buf
, sizeof(buf
),
459 sta
->auth_alg
, req_ies
, req_ies_len
);
461 wpa_printf(MSG_DEBUG
, "FT: Failed to write AssocResp IEs");
462 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
464 #endif /* CONFIG_IEEE80211R_AP */
467 if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
468 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
469 sta
->auth_alg
== WLAN_AUTH_FILS_PK
) {
473 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
475 if (!wpa_fils_validate_fils_session(sta
->wpa_sm
, req_ies
,
477 sta
->fils_session
)) {
478 wpa_printf(MSG_DEBUG
,
479 "FILS: Session validation failed");
480 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
483 res
= wpa_fils_validate_key_confirm(sta
->wpa_sm
, req_ies
,
486 wpa_printf(MSG_DEBUG
,
487 "FILS: Key Confirm validation failed");
488 return WLAN_STATUS_UNSPECIFIED_FAILURE
;
491 if (fils_process_hlp(hapd
, sta
, req_ies
, req_ies_len
) > 0) {
492 wpa_printf(MSG_DEBUG
,
493 "FILS: Delaying Assoc Response (HLP)");
496 wpa_printf(MSG_DEBUG
,
497 "FILS: Going ahead with Assoc Response (no HLP)");
501 wpa_printf(MSG_DEBUG
, "FILS: HLP callback cleanup");
502 eloop_cancel_timeout(fils_hlp_timeout
, hapd
, sta
);
503 os_free(sta
->fils_pending_assoc_req
);
504 sta
->fils_pending_assoc_req
= NULL
;
505 sta
->fils_pending_assoc_req_len
= 0;
506 wpabuf_free(sta
->fils_hlp_resp
);
507 sta
->fils_hlp_resp
= NULL
;
508 sta
->fils_drv_assoc_finish
= 0;
511 if (sta
&& delay_assoc
&& status
== WLAN_STATUS_SUCCESS
) {
514 req_tmp
= os_malloc(req_ies_len
);
516 wpa_printf(MSG_DEBUG
,
517 "FILS: buffer allocation failed for assoc req");
520 os_memcpy(req_tmp
, req_ies
, req_ies_len
);
521 sta
->fils_pending_assoc_req
= req_tmp
;
522 sta
->fils_pending_assoc_req_len
= req_ies_len
;
523 sta
->fils_pending_assoc_is_reassoc
= reassoc
;
524 sta
->fils_drv_assoc_finish
= 1;
525 wpa_printf(MSG_DEBUG
,
526 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
527 MACSTR
, MAC2STR(sta
->addr
));
528 eloop_register_timeout(
529 0, hapd
->conf
->fils_hlp_wait_time
* 1024,
530 fils_hlp_timeout
, hapd
, sta
);
533 p
= hostapd_eid_assoc_fils_session(sta
->wpa_sm
, p
,
536 wpa_hexdump(MSG_DEBUG
, "FILS Assoc Resp BUF (IEs)",
539 #endif /* CONFIG_FILS */
542 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
543 wpa_auth_sta_key_mgmt(sta
->wpa_sm
) == WPA_KEY_MGMT_OWE
&&
547 npos
= owe_assoc_req_process(hapd
, sta
,
548 elems
.owe_dh
, elems
.owe_dh_len
,
549 p
, sizeof(buf
) - (p
- buf
),
554 reason
== WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
) {
555 status
= WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED
;
556 hostapd_sta_assoc(hapd
, addr
, reassoc
, status
, buf
,
561 if (!npos
|| reason
!= WLAN_STATUS_SUCCESS
)
564 #endif /* CONFIG_OWE */
566 #if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
567 hostapd_sta_assoc(hapd
, addr
, reassoc
, status
, buf
, p
- buf
);
569 if (sta
->auth_alg
== WLAN_AUTH_FT
||
570 sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
571 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
572 sta
->auth_alg
== WLAN_AUTH_FILS_PK
)
573 ap_sta_set_authorized(hapd
, sta
, 1);
574 #else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
575 /* Keep compiler silent about unused variables */
578 #endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
580 new_assoc
= (sta
->flags
& WLAN_STA_ASSOC
) == 0;
581 sta
->flags
|= WLAN_STA_AUTH
| WLAN_STA_ASSOC
;
582 sta
->flags
&= ~WLAN_STA_WNM_SLEEP_MODE
;
584 hostapd_set_sta_flags(hapd
, sta
);
586 if (reassoc
&& (sta
->auth_alg
== WLAN_AUTH_FT
))
587 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC_FT
);
589 else if (sta
->auth_alg
== WLAN_AUTH_FILS_SK
||
590 sta
->auth_alg
== WLAN_AUTH_FILS_SK_PFS
||
591 sta
->auth_alg
== WLAN_AUTH_FILS_PK
)
592 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC_FILS
);
593 #endif /* CONFIG_FILS */
595 wpa_auth_sm_event(sta
->wpa_sm
, WPA_ASSOC
);
597 hostapd_new_assoc_sta(hapd
, sta
, !new_assoc
);
599 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 1);
603 p2p_group_notif_assoc(hapd
->p2p_group
, sta
->addr
,
604 req_ies
, req_ies_len
);
606 #endif /* CONFIG_P2P */
611 #ifdef CONFIG_IEEE80211R_AP
612 hostapd_sta_assoc(hapd
, addr
, reassoc
, status
, buf
, p
- buf
);
613 #endif /* CONFIG_IEEE80211R_AP */
614 hostapd_drv_sta_disassoc(hapd
, sta
->addr
, reason
);
615 ap_free_sta(hapd
, sta
);
620 void hostapd_notif_disassoc(struct hostapd_data
*hapd
, const u8
*addr
)
622 struct sta_info
*sta
;
626 * This could potentially happen with unexpected event from the
627 * driver wrapper. This was seen at least in one case where the
628 * driver ended up reporting a station mode event while hostapd
629 * was running, so better make sure we stop processing such an
632 wpa_printf(MSG_DEBUG
,
633 "hostapd_notif_disassoc: Skip event with no address");
637 hostapd_logger(hapd
, addr
, HOSTAPD_MODULE_IEEE80211
,
638 HOSTAPD_LEVEL_INFO
, "disassociated");
640 sta
= ap_get_sta(hapd
, addr
);
642 wpa_printf(MSG_DEBUG
,
643 "Disassociation notification for unknown STA "
644 MACSTR
, MAC2STR(addr
));
648 ap_sta_set_authorized(hapd
, sta
, 0);
649 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
);
650 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DISASSOC
);
651 sta
->acct_terminate_cause
= RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST
;
652 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
653 ap_free_sta(hapd
, sta
);
657 void hostapd_event_sta_low_ack(struct hostapd_data
*hapd
, const u8
*addr
)
659 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
661 if (!sta
|| !hapd
->conf
->disassoc_low_ack
|| sta
->agreed_to_steer
)
664 hostapd_logger(hapd
, addr
, HOSTAPD_MODULE_IEEE80211
,
666 "disconnected due to excessive missing ACKs");
667 hostapd_drv_sta_disassoc(hapd
, addr
, WLAN_REASON_DISASSOC_LOW_ACK
);
668 ap_sta_disassociate(hapd
, sta
, WLAN_REASON_DISASSOC_LOW_ACK
);
672 void hostapd_event_sta_opmode_changed(struct hostapd_data
*hapd
, const u8
*addr
,
673 enum smps_mode smps_mode
,
674 enum chan_width chan_width
, u8 rx_nss
)
676 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
700 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, STA_OPMODE_SMPS_MODE_CHANGED
701 MACSTR
" %s", MAC2STR(addr
), txt
);
704 switch (chan_width
) {
705 case CHAN_WIDTH_20_NOHT
:
717 case CHAN_WIDTH_80P80
:
728 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, STA_OPMODE_MAX_BW_CHANGED
729 MACSTR
" %s", MAC2STR(addr
), txt
);
732 if (rx_nss
!= 0xff) {
733 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, STA_OPMODE_N_SS_CHANGED
734 MACSTR
" %d", MAC2STR(addr
), rx_nss
);
739 void hostapd_event_ch_switch(struct hostapd_data
*hapd
, int freq
, int ht
,
740 int offset
, int width
, int cf1
, int cf2
)
743 int channel
, chwidth
, is_dfs
;
744 u8 seg0_idx
= 0, seg1_idx
= 0;
746 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
748 "driver had channel switch: freq=%d, ht=%d, vht_ch=0x%x, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
749 freq
, ht
, hapd
->iconf
->ch_switch_vht_config
, offset
,
750 width
, channel_width_to_string(width
), cf1
, cf2
);
752 hapd
->iface
->freq
= freq
;
754 channel
= hostapd_hw_get_channel(hapd
, freq
);
756 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
757 HOSTAPD_LEVEL_WARNING
,
758 "driver switched to bad channel!");
764 chwidth
= VHT_CHANWIDTH_80MHZ
;
766 case CHAN_WIDTH_80P80
:
767 chwidth
= VHT_CHANWIDTH_80P80MHZ
;
770 chwidth
= VHT_CHANWIDTH_160MHZ
;
772 case CHAN_WIDTH_20_NOHT
:
776 chwidth
= VHT_CHANWIDTH_USE_HT
;
780 switch (hapd
->iface
->current_mode
->mode
) {
781 case HOSTAPD_MODE_IEEE80211A
:
783 seg0_idx
= (cf1
- 5000) / 5;
785 seg1_idx
= (cf2
- 5000) / 5;
788 ieee80211_freq_to_chan(cf1
, &seg0_idx
);
789 ieee80211_freq_to_chan(cf2
, &seg1_idx
);
793 hapd
->iconf
->channel
= channel
;
794 hapd
->iconf
->ieee80211n
= ht
;
796 hapd
->iconf
->ieee80211ac
= 0;
797 } else if (hapd
->iconf
->ch_switch_vht_config
) {
798 /* CHAN_SWITCH VHT config */
799 if (hapd
->iconf
->ch_switch_vht_config
&
800 CH_SWITCH_VHT_ENABLED
)
801 hapd
->iconf
->ieee80211ac
= 1;
802 else if (hapd
->iconf
->ch_switch_vht_config
&
803 CH_SWITCH_VHT_DISABLED
)
804 hapd
->iconf
->ieee80211ac
= 0;
806 hapd
->iconf
->ch_switch_vht_config
= 0;
808 hapd
->iconf
->secondary_channel
= offset
;
809 hapd
->iconf
->vht_oper_chwidth
= chwidth
;
810 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
= seg0_idx
;
811 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
= seg1_idx
;
813 is_dfs
= ieee80211_is_dfs(freq
, hapd
->iface
->hw_features
,
814 hapd
->iface
->num_hw_features
);
816 if (hapd
->csa_in_progress
&&
817 freq
== hapd
->cs_freq_params
.freq
) {
818 hostapd_cleanup_cs_params(hapd
);
819 ieee802_11_set_beacon(hapd
);
821 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_CSA_FINISHED
822 "freq=%d dfs=%d", freq
, is_dfs
);
823 } else if (hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_DFS_OFFLOAD
) {
824 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_CSA_FINISHED
825 "freq=%d dfs=%d", freq
, is_dfs
);
827 #endif /* NEED_AP_MLME */
831 void hostapd_event_connect_failed_reason(struct hostapd_data
*hapd
,
832 const u8
*addr
, int reason_code
)
834 switch (reason_code
) {
835 case MAX_CLIENT_REACHED
:
836 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_REJECTED_MAX_STA MACSTR
,
840 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_REJECTED_BLOCKED_STA MACSTR
,
848 void hostapd_acs_channel_selected(struct hostapd_data
*hapd
,
849 struct acs_selected_channels
*acs_res
)
854 if (hapd
->iconf
->channel
) {
855 wpa_printf(MSG_INFO
, "ACS: Channel was already set to %d",
856 hapd
->iconf
->channel
);
860 if (!hapd
->iface
->current_mode
) {
861 for (i
= 0; i
< hapd
->iface
->num_hw_features
; i
++) {
862 struct hostapd_hw_modes
*mode
=
863 &hapd
->iface
->hw_features
[i
];
865 if (mode
->mode
== acs_res
->hw_mode
) {
866 hapd
->iface
->current_mode
= mode
;
870 if (!hapd
->iface
->current_mode
) {
871 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
872 HOSTAPD_LEVEL_WARNING
,
873 "driver selected to bad hw_mode");
879 hapd
->iface
->freq
= hostapd_hw_get_freq(hapd
, acs_res
->pri_channel
);
881 if (!acs_res
->pri_channel
) {
882 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
883 HOSTAPD_LEVEL_WARNING
,
884 "driver switched to bad channel");
889 hapd
->iconf
->channel
= acs_res
->pri_channel
;
890 hapd
->iconf
->acs
= 1;
892 if (acs_res
->sec_channel
== 0)
893 hapd
->iconf
->secondary_channel
= 0;
894 else if (acs_res
->sec_channel
< acs_res
->pri_channel
)
895 hapd
->iconf
->secondary_channel
= -1;
896 else if (acs_res
->sec_channel
> acs_res
->pri_channel
)
897 hapd
->iconf
->secondary_channel
= 1;
899 wpa_printf(MSG_ERROR
, "Invalid secondary channel!");
904 if (hapd
->iface
->conf
->ieee80211ac
) {
905 /* set defaults for backwards compatibility */
906 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
= 0;
907 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
= 0;
908 hapd
->iconf
->vht_oper_chwidth
= VHT_CHANWIDTH_USE_HT
;
909 if (acs_res
->ch_width
== 80) {
910 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
=
911 acs_res
->vht_seg0_center_ch
;
912 hapd
->iconf
->vht_oper_chwidth
= VHT_CHANWIDTH_80MHZ
;
913 } else if (acs_res
->ch_width
== 160) {
914 if (acs_res
->vht_seg1_center_ch
== 0) {
915 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
=
916 acs_res
->vht_seg0_center_ch
;
917 hapd
->iconf
->vht_oper_chwidth
=
918 VHT_CHANWIDTH_160MHZ
;
920 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
=
921 acs_res
->vht_seg0_center_ch
;
922 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
=
923 acs_res
->vht_seg1_center_ch
;
924 hapd
->iconf
->vht_oper_chwidth
=
925 VHT_CHANWIDTH_80P80MHZ
;
931 ret
= hostapd_acs_completed(hapd
->iface
, err
);
933 wpa_printf(MSG_ERROR
,
934 "ACS: Possibly channel configuration is invalid");
937 #endif /* CONFIG_ACS */
940 int hostapd_probe_req_rx(struct hostapd_data
*hapd
, const u8
*sa
, const u8
*da
,
941 const u8
*bssid
, const u8
*ie
, size_t ie_len
,
947 if (sa
== NULL
|| ie
== NULL
)
950 random_add_randomness(sa
, ETH_ALEN
);
951 for (i
= 0; hapd
->probereq_cb
&& i
< hapd
->num_probereq_cb
; i
++) {
952 if (hapd
->probereq_cb
[i
].cb(hapd
->probereq_cb
[i
].ctx
,
953 sa
, da
, bssid
, ie
, ie_len
,
965 #ifdef CONFIG_IEEE80211R_AP
966 static void hostapd_notify_auth_ft_finish(void *ctx
, const u8
*dst
,
968 u16 auth_transaction
, u16 status
,
969 const u8
*ies
, size_t ies_len
)
971 struct hostapd_data
*hapd
= ctx
;
972 struct sta_info
*sta
;
974 sta
= ap_get_sta(hapd
, dst
);
978 hostapd_logger(hapd
, dst
, HOSTAPD_MODULE_IEEE80211
,
979 HOSTAPD_LEVEL_DEBUG
, "authentication OK (FT)");
980 sta
->flags
|= WLAN_STA_AUTH
;
982 hostapd_sta_auth(hapd
, dst
, auth_transaction
, status
, ies
, ies_len
);
984 #endif /* CONFIG_IEEE80211R_AP */
988 static void hostapd_notify_auth_fils_finish(struct hostapd_data
*hapd
,
989 struct sta_info
*sta
, u16 resp
,
990 struct wpabuf
*data
, int pub
)
992 if (resp
== WLAN_STATUS_SUCCESS
) {
993 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
994 HOSTAPD_LEVEL_DEBUG
, "authentication OK (FILS)");
995 sta
->flags
|= WLAN_STA_AUTH
;
996 wpa_auth_sm_event(sta
->wpa_sm
, WPA_AUTH
);
997 sta
->auth_alg
= WLAN_AUTH_FILS_SK
;
998 mlme_authenticate_indication(hapd
, sta
);
1000 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1001 HOSTAPD_LEVEL_DEBUG
,
1002 "authentication failed (FILS)");
1005 hostapd_sta_auth(hapd
, sta
->addr
, 2, resp
,
1006 data
? wpabuf_head(data
) : NULL
,
1007 data
? wpabuf_len(data
) : 0);
1010 #endif /* CONFIG_FILS */
1013 static void hostapd_notif_auth(struct hostapd_data
*hapd
,
1014 struct auth_info
*rx_auth
)
1016 struct sta_info
*sta
;
1017 u16 status
= WLAN_STATUS_SUCCESS
;
1018 u8 resp_ies
[2 + WLAN_AUTH_CHALLENGE_LEN
];
1019 size_t resp_ies_len
= 0;
1021 sta
= ap_get_sta(hapd
, rx_auth
->peer
);
1023 sta
= ap_sta_add(hapd
, rx_auth
->peer
);
1025 status
= WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA
;
1029 sta
->flags
&= ~WLAN_STA_PREAUTH
;
1030 ieee802_1x_notify_pre_auth(sta
->eapol_sm
, 0);
1031 #ifdef CONFIG_IEEE80211R_AP
1032 if (rx_auth
->auth_type
== WLAN_AUTH_FT
&& hapd
->wpa_auth
) {
1033 sta
->auth_alg
= WLAN_AUTH_FT
;
1034 if (sta
->wpa_sm
== NULL
)
1035 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
,
1037 if (sta
->wpa_sm
== NULL
) {
1038 wpa_printf(MSG_DEBUG
,
1039 "FT: Failed to initialize WPA state machine");
1040 status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1043 wpa_ft_process_auth(sta
->wpa_sm
, rx_auth
->bssid
,
1044 rx_auth
->auth_transaction
, rx_auth
->ies
,
1046 hostapd_notify_auth_ft_finish
, hapd
);
1049 #endif /* CONFIG_IEEE80211R_AP */
1052 if (rx_auth
->auth_type
== WLAN_AUTH_FILS_SK
) {
1053 sta
->auth_alg
= WLAN_AUTH_FILS_SK
;
1054 handle_auth_fils(hapd
, sta
, rx_auth
->ies
, rx_auth
->ies_len
,
1055 rx_auth
->auth_type
, rx_auth
->auth_transaction
,
1056 rx_auth
->status_code
,
1057 hostapd_notify_auth_fils_finish
);
1060 #endif /* CONFIG_FILS */
1063 hostapd_sta_auth(hapd
, rx_auth
->peer
, rx_auth
->auth_transaction
+ 1,
1064 status
, resp_ies
, resp_ies_len
);
1068 static void hostapd_action_rx(struct hostapd_data
*hapd
,
1069 struct rx_mgmt
*drv_mgmt
)
1071 struct ieee80211_mgmt
*mgmt
;
1072 struct sta_info
*sta
;
1073 size_t plen __maybe_unused
;
1075 u8
*action __maybe_unused
;
1077 if (drv_mgmt
->frame_len
< IEEE80211_HDRLEN
+ 2 + 1)
1080 plen
= drv_mgmt
->frame_len
- IEEE80211_HDRLEN
- 1;
1082 mgmt
= (struct ieee80211_mgmt
*) drv_mgmt
->frame
;
1083 fc
= le_to_host16(mgmt
->frame_control
);
1084 if (WLAN_FC_GET_STYPE(fc
) != WLAN_FC_STYPE_ACTION
)
1085 return; /* handled by the driver */
1087 action
= (u8
*) &mgmt
->u
.action
.u
;
1088 wpa_printf(MSG_DEBUG
, "RX_ACTION category %u action %u sa " MACSTR
1089 " da " MACSTR
" plen %d",
1090 mgmt
->u
.action
.category
, *action
,
1091 MAC2STR(mgmt
->sa
), MAC2STR(mgmt
->da
), (int) plen
);
1093 sta
= ap_get_sta(hapd
, mgmt
->sa
);
1095 wpa_printf(MSG_DEBUG
, "%s: station not found", __func__
);
1098 #ifdef CONFIG_IEEE80211R_AP
1099 if (mgmt
->u
.action
.category
== WLAN_ACTION_FT
) {
1100 const u8
*payload
= drv_mgmt
->frame
+ 24 + 1;
1102 wpa_ft_action_rx(sta
->wpa_sm
, payload
, plen
);
1104 #endif /* CONFIG_IEEE80211R_AP */
1105 #ifdef CONFIG_IEEE80211W
1106 if (mgmt
->u
.action
.category
== WLAN_ACTION_SA_QUERY
&& plen
>= 4) {
1107 ieee802_11_sa_query_action(hapd
, mgmt
, drv_mgmt
->frame_len
);
1109 #endif /* CONFIG_IEEE80211W */
1110 #ifdef CONFIG_WNM_AP
1111 if (mgmt
->u
.action
.category
== WLAN_ACTION_WNM
) {
1112 ieee802_11_rx_wnm_action_ap(hapd
, mgmt
, drv_mgmt
->frame_len
);
1114 #endif /* CONFIG_WNM_AP */
1116 if (mgmt
->u
.action
.category
== WLAN_ACTION_FST
&& hapd
->iface
->fst
) {
1117 fst_rx_action(hapd
->iface
->fst
, mgmt
, drv_mgmt
->frame_len
);
1120 #endif /* CONFIG_FST */
1122 if (plen
>= 1 + 4 &&
1123 mgmt
->u
.action
.u
.vs_public_action
.action
==
1124 WLAN_PA_VENDOR_SPECIFIC
&&
1125 WPA_GET_BE24(mgmt
->u
.action
.u
.vs_public_action
.oui
) ==
1127 mgmt
->u
.action
.u
.vs_public_action
.variable
[0] ==
1129 const u8
*pos
, *end
;
1131 pos
= mgmt
->u
.action
.u
.vs_public_action
.oui
;
1132 end
= drv_mgmt
->frame
+ drv_mgmt
->frame_len
;
1133 hostapd_dpp_rx_action(hapd
, mgmt
->sa
, pos
, end
- pos
,
1137 #endif /* CONFIG_DPP */
1143 #define HAPD_BROADCAST ((struct hostapd_data *) -1)
1145 static struct hostapd_data
* get_hapd_bssid(struct hostapd_iface
*iface
,
1152 if (bssid
[0] == 0xff && bssid
[1] == 0xff && bssid
[2] == 0xff &&
1153 bssid
[3] == 0xff && bssid
[4] == 0xff && bssid
[5] == 0xff)
1154 return HAPD_BROADCAST
;
1156 for (i
= 0; i
< iface
->num_bss
; i
++) {
1157 if (os_memcmp(bssid
, iface
->bss
[i
]->own_addr
, ETH_ALEN
) == 0)
1158 return iface
->bss
[i
];
1165 static void hostapd_rx_from_unknown_sta(struct hostapd_data
*hapd
,
1166 const u8
*bssid
, const u8
*addr
,
1169 hapd
= get_hapd_bssid(hapd
->iface
, bssid
);
1170 if (hapd
== NULL
|| hapd
== HAPD_BROADCAST
)
1173 ieee802_11_rx_from_unknown(hapd
, addr
, wds
);
1177 static int hostapd_mgmt_rx(struct hostapd_data
*hapd
, struct rx_mgmt
*rx_mgmt
)
1179 struct hostapd_iface
*iface
= hapd
->iface
;
1180 const struct ieee80211_hdr
*hdr
;
1182 struct hostapd_frame_info fi
;
1185 #ifdef CONFIG_TESTING_OPTIONS
1186 if (hapd
->ext_mgmt_frame_handling
) {
1187 size_t hex_len
= 2 * rx_mgmt
->frame_len
+ 1;
1188 char *hex
= os_malloc(hex_len
);
1191 wpa_snprintf_hex(hex
, hex_len
, rx_mgmt
->frame
,
1192 rx_mgmt
->frame_len
);
1193 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "MGMT-RX %s", hex
);
1198 #endif /* CONFIG_TESTING_OPTIONS */
1200 hdr
= (const struct ieee80211_hdr
*) rx_mgmt
->frame
;
1201 bssid
= get_hdr_bssid(hdr
, rx_mgmt
->frame_len
);
1205 hapd
= get_hapd_bssid(iface
, bssid
);
1207 u16 fc
= le_to_host16(hdr
->frame_control
);
1210 * Drop frames to unknown BSSIDs except for Beacon frames which
1211 * could be used to update neighbor information.
1213 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
1214 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
1215 hapd
= iface
->bss
[0];
1220 os_memset(&fi
, 0, sizeof(fi
));
1221 fi
.freq
= rx_mgmt
->freq
;
1222 fi
.datarate
= rx_mgmt
->datarate
;
1223 fi
.ssi_signal
= rx_mgmt
->ssi_signal
;
1225 if (hapd
== HAPD_BROADCAST
) {
1229 for (i
= 0; i
< iface
->num_bss
; i
++) {
1230 /* if bss is set, driver will call this function for
1231 * each bss individually. */
1232 if (rx_mgmt
->drv_priv
&&
1233 (iface
->bss
[i
]->drv_priv
!= rx_mgmt
->drv_priv
))
1236 if (ieee802_11_mgmt(iface
->bss
[i
], rx_mgmt
->frame
,
1237 rx_mgmt
->frame_len
, &fi
) > 0)
1241 ret
= ieee802_11_mgmt(hapd
, rx_mgmt
->frame
, rx_mgmt
->frame_len
,
1244 random_add_randomness(&fi
, sizeof(fi
));
1250 static void hostapd_mgmt_tx_cb(struct hostapd_data
*hapd
, const u8
*buf
,
1251 size_t len
, u16 stype
, int ok
)
1253 struct ieee80211_hdr
*hdr
;
1254 struct hostapd_data
*orig_hapd
= hapd
;
1256 hdr
= (struct ieee80211_hdr
*) buf
;
1257 hapd
= get_hapd_bssid(hapd
->iface
, get_hdr_bssid(hdr
, len
));
1260 if (hapd
== HAPD_BROADCAST
) {
1261 if (stype
!= WLAN_FC_STYPE_ACTION
|| len
<= 25 ||
1262 buf
[24] != WLAN_ACTION_PUBLIC
)
1264 hapd
= get_hapd_bssid(orig_hapd
->iface
, hdr
->addr2
);
1265 if (!hapd
|| hapd
== HAPD_BROADCAST
)
1268 * Allow processing of TX status for a Public Action frame that
1269 * used wildcard BBSID.
1272 ieee802_11_mgmt_cb(hapd
, buf
, len
, stype
, ok
);
1275 #endif /* NEED_AP_MLME */
1278 static int hostapd_event_new_sta(struct hostapd_data
*hapd
, const u8
*addr
)
1280 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
1285 wpa_printf(MSG_DEBUG
, "Data frame from unknown STA " MACSTR
1286 " - adding a new STA", MAC2STR(addr
));
1287 sta
= ap_sta_add(hapd
, addr
);
1289 hostapd_new_assoc_sta(hapd
, sta
, 0);
1291 wpa_printf(MSG_DEBUG
, "Failed to add STA entry for " MACSTR
,
1300 static void hostapd_event_eapol_rx(struct hostapd_data
*hapd
, const u8
*src
,
1301 const u8
*data
, size_t data_len
)
1303 struct hostapd_iface
*iface
= hapd
->iface
;
1304 struct sta_info
*sta
;
1307 for (j
= 0; j
< iface
->num_bss
; j
++) {
1308 sta
= ap_get_sta(iface
->bss
[j
], src
);
1309 if (sta
&& sta
->flags
& WLAN_STA_ASSOC
) {
1310 hapd
= iface
->bss
[j
];
1315 ieee802_1x_receive(hapd
, src
, data
, data_len
);
1318 #endif /* HOSTAPD */
1321 static struct hostapd_channel_data
* hostapd_get_mode_channel(
1322 struct hostapd_iface
*iface
, unsigned int freq
)
1325 struct hostapd_channel_data
*chan
;
1327 for (i
= 0; i
< iface
->current_mode
->num_channels
; i
++) {
1328 chan
= &iface
->current_mode
->channels
[i
];
1329 if ((unsigned int) chan
->freq
== freq
)
1337 static void hostapd_update_nf(struct hostapd_iface
*iface
,
1338 struct hostapd_channel_data
*chan
,
1339 struct freq_survey
*survey
)
1341 if (!iface
->chans_surveyed
) {
1342 chan
->min_nf
= survey
->nf
;
1343 iface
->lowest_nf
= survey
->nf
;
1345 if (dl_list_empty(&chan
->survey_list
))
1346 chan
->min_nf
= survey
->nf
;
1347 else if (survey
->nf
< chan
->min_nf
)
1348 chan
->min_nf
= survey
->nf
;
1349 if (survey
->nf
< iface
->lowest_nf
)
1350 iface
->lowest_nf
= survey
->nf
;
1355 static void hostapd_single_channel_get_survey(struct hostapd_iface
*iface
,
1356 struct survey_results
*survey_res
)
1358 struct hostapd_channel_data
*chan
;
1359 struct freq_survey
*survey
;
1360 u64 divisor
, dividend
;
1362 survey
= dl_list_first(&survey_res
->survey_list
, struct freq_survey
,
1364 if (!survey
|| !survey
->freq
)
1367 chan
= hostapd_get_mode_channel(iface
, survey
->freq
);
1368 if (!chan
|| chan
->flag
& HOSTAPD_CHAN_DISABLED
)
1371 wpa_printf(MSG_DEBUG
,
1372 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
1374 (unsigned long int) survey
->channel_time
,
1375 (unsigned long int) survey
->channel_time_busy
);
1377 if (survey
->channel_time
> iface
->last_channel_time
&&
1378 survey
->channel_time
> survey
->channel_time_busy
) {
1379 dividend
= survey
->channel_time_busy
-
1380 iface
->last_channel_time_busy
;
1381 divisor
= survey
->channel_time
- iface
->last_channel_time
;
1383 iface
->channel_utilization
= dividend
* 255 / divisor
;
1384 wpa_printf(MSG_DEBUG
, "Channel Utilization: %d",
1385 iface
->channel_utilization
);
1387 iface
->last_channel_time
= survey
->channel_time
;
1388 iface
->last_channel_time_busy
= survey
->channel_time_busy
;
1392 void hostapd_event_get_survey(struct hostapd_iface
*iface
,
1393 struct survey_results
*survey_results
)
1395 struct freq_survey
*survey
, *tmp
;
1396 struct hostapd_channel_data
*chan
;
1398 if (dl_list_empty(&survey_results
->survey_list
)) {
1399 wpa_printf(MSG_DEBUG
, "No survey data received");
1403 if (survey_results
->freq_filter
) {
1404 hostapd_single_channel_get_survey(iface
, survey_results
);
1408 dl_list_for_each_safe(survey
, tmp
, &survey_results
->survey_list
,
1409 struct freq_survey
, list
) {
1410 chan
= hostapd_get_mode_channel(iface
, survey
->freq
);
1413 if (chan
->flag
& HOSTAPD_CHAN_DISABLED
)
1416 dl_list_del(&survey
->list
);
1417 dl_list_add_tail(&chan
->survey_list
, &survey
->list
);
1419 hostapd_update_nf(iface
, chan
, survey
);
1421 iface
->chans_surveyed
++;
1429 static void hostapd_event_iface_unavailable(struct hostapd_data
*hapd
)
1431 wpa_printf(MSG_DEBUG
, "Interface %s is unavailable -- stopped",
1434 if (hapd
->csa_in_progress
) {
1435 wpa_printf(MSG_INFO
, "CSA failed (%s was stopped)",
1437 hostapd_switch_channel_fallback(hapd
->iface
,
1438 &hapd
->cs_freq_params
);
1443 static void hostapd_event_dfs_radar_detected(struct hostapd_data
*hapd
,
1444 struct dfs_event
*radar
)
1446 wpa_printf(MSG_DEBUG
, "DFS radar detected on %d MHz", radar
->freq
);
1447 hostapd_dfs_radar_detected(hapd
->iface
, radar
->freq
, radar
->ht_enabled
,
1448 radar
->chan_offset
, radar
->chan_width
,
1449 radar
->cf1
, radar
->cf2
);
1453 static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data
*hapd
,
1454 struct dfs_event
*radar
)
1456 wpa_printf(MSG_DEBUG
, "DFS Pre-CAC expired on %d MHz", radar
->freq
);
1457 hostapd_dfs_pre_cac_expired(hapd
->iface
, radar
->freq
, radar
->ht_enabled
,
1458 radar
->chan_offset
, radar
->chan_width
,
1459 radar
->cf1
, radar
->cf2
);
1463 static void hostapd_event_dfs_cac_finished(struct hostapd_data
*hapd
,
1464 struct dfs_event
*radar
)
1466 wpa_printf(MSG_DEBUG
, "DFS CAC finished on %d MHz", radar
->freq
);
1467 hostapd_dfs_complete_cac(hapd
->iface
, 1, radar
->freq
, radar
->ht_enabled
,
1468 radar
->chan_offset
, radar
->chan_width
,
1469 radar
->cf1
, radar
->cf2
);
1473 static void hostapd_event_dfs_cac_aborted(struct hostapd_data
*hapd
,
1474 struct dfs_event
*radar
)
1476 wpa_printf(MSG_DEBUG
, "DFS CAC aborted on %d MHz", radar
->freq
);
1477 hostapd_dfs_complete_cac(hapd
->iface
, 0, radar
->freq
, radar
->ht_enabled
,
1478 radar
->chan_offset
, radar
->chan_width
,
1479 radar
->cf1
, radar
->cf2
);
1483 static void hostapd_event_dfs_nop_finished(struct hostapd_data
*hapd
,
1484 struct dfs_event
*radar
)
1486 wpa_printf(MSG_DEBUG
, "DFS NOP finished on %d MHz", radar
->freq
);
1487 hostapd_dfs_nop_finished(hapd
->iface
, radar
->freq
, radar
->ht_enabled
,
1488 radar
->chan_offset
, radar
->chan_width
,
1489 radar
->cf1
, radar
->cf2
);
1493 static void hostapd_event_dfs_cac_started(struct hostapd_data
*hapd
,
1494 struct dfs_event
*radar
)
1496 wpa_printf(MSG_DEBUG
, "DFS offload CAC started on %d MHz", radar
->freq
);
1497 hostapd_dfs_start_cac(hapd
->iface
, radar
->freq
, radar
->ht_enabled
,
1498 radar
->chan_offset
, radar
->chan_width
,
1499 radar
->cf1
, radar
->cf2
);
1502 #endif /* NEED_AP_MLME */
1505 static void hostapd_event_wds_sta_interface_status(struct hostapd_data
*hapd
,
1510 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
1513 os_free(sta
->ifname_wds
);
1514 if (istatus
== INTERFACE_ADDED
)
1515 sta
->ifname_wds
= os_strdup(ifname
);
1517 sta
->ifname_wds
= NULL
;
1520 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "%sifname=%s sta_addr=" MACSTR
,
1521 istatus
== INTERFACE_ADDED
?
1522 WDS_STA_INTERFACE_ADDED
: WDS_STA_INTERFACE_REMOVED
,
1523 ifname
, MAC2STR(addr
));
1527 void wpa_supplicant_event(void *ctx
, enum wpa_event_type event
,
1528 union wpa_event_data
*data
)
1530 struct hostapd_data
*hapd
= ctx
;
1531 #ifndef CONFIG_NO_STDOUT_DEBUG
1532 int level
= MSG_DEBUG
;
1534 if (event
== EVENT_RX_MGMT
&& data
->rx_mgmt
.frame
&&
1535 data
->rx_mgmt
.frame_len
>= 24) {
1536 const struct ieee80211_hdr
*hdr
;
1539 hdr
= (const struct ieee80211_hdr
*) data
->rx_mgmt
.frame
;
1540 fc
= le_to_host16(hdr
->frame_control
);
1541 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
1542 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_BEACON
)
1543 level
= MSG_EXCESSIVE
;
1544 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
1545 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_REQ
)
1546 level
= MSG_EXCESSIVE
;
1549 wpa_dbg(hapd
->msg_ctx
, level
, "Event %s (%d) received",
1550 event_to_string(event
), event
);
1551 #endif /* CONFIG_NO_STDOUT_DEBUG */
1554 case EVENT_MICHAEL_MIC_FAILURE
:
1555 michael_mic_failure(hapd
, data
->michael_mic_failure
.src
, 1);
1557 case EVENT_SCAN_RESULTS
:
1558 if (hapd
->iface
->scan_cb
)
1559 hapd
->iface
->scan_cb(hapd
->iface
);
1561 case EVENT_WPS_BUTTON_PUSHED
:
1562 hostapd_wps_button_pushed(hapd
, NULL
);
1565 case EVENT_TX_STATUS
:
1566 switch (data
->tx_status
.type
) {
1567 case WLAN_FC_TYPE_MGMT
:
1568 hostapd_mgmt_tx_cb(hapd
, data
->tx_status
.data
,
1569 data
->tx_status
.data_len
,
1570 data
->tx_status
.stype
,
1571 data
->tx_status
.ack
);
1573 case WLAN_FC_TYPE_DATA
:
1574 hostapd_tx_status(hapd
, data
->tx_status
.dst
,
1575 data
->tx_status
.data
,
1576 data
->tx_status
.data_len
,
1577 data
->tx_status
.ack
);
1581 case EVENT_EAPOL_TX_STATUS
:
1582 hostapd_eapol_tx_status(hapd
, data
->eapol_tx_status
.dst
,
1583 data
->eapol_tx_status
.data
,
1584 data
->eapol_tx_status
.data_len
,
1585 data
->eapol_tx_status
.ack
);
1587 case EVENT_DRIVER_CLIENT_POLL_OK
:
1588 hostapd_client_poll_ok(hapd
, data
->client_poll
.addr
);
1590 case EVENT_RX_FROM_UNKNOWN
:
1591 hostapd_rx_from_unknown_sta(hapd
, data
->rx_from_unknown
.bssid
,
1592 data
->rx_from_unknown
.addr
,
1593 data
->rx_from_unknown
.wds
);
1595 #endif /* NEED_AP_MLME */
1597 if (!data
->rx_mgmt
.frame
)
1600 if (hostapd_mgmt_rx(hapd
, &data
->rx_mgmt
) > 0)
1602 #endif /* NEED_AP_MLME */
1603 hostapd_action_rx(hapd
, &data
->rx_mgmt
);
1605 case EVENT_RX_PROBE_REQ
:
1606 if (data
->rx_probe_req
.sa
== NULL
||
1607 data
->rx_probe_req
.ie
== NULL
)
1609 hostapd_probe_req_rx(hapd
, data
->rx_probe_req
.sa
,
1610 data
->rx_probe_req
.da
,
1611 data
->rx_probe_req
.bssid
,
1612 data
->rx_probe_req
.ie
,
1613 data
->rx_probe_req
.ie_len
,
1614 data
->rx_probe_req
.ssi_signal
);
1617 hostapd_event_new_sta(hapd
, data
->new_sta
.addr
);
1619 case EVENT_EAPOL_RX
:
1620 hostapd_event_eapol_rx(hapd
, data
->eapol_rx
.src
,
1621 data
->eapol_rx
.data
,
1622 data
->eapol_rx
.data_len
);
1627 hostapd_notif_assoc(hapd
, data
->assoc_info
.addr
,
1628 data
->assoc_info
.req_ies
,
1629 data
->assoc_info
.req_ies_len
,
1630 data
->assoc_info
.reassoc
);
1632 case EVENT_DISASSOC
:
1634 hostapd_notif_disassoc(hapd
, data
->disassoc_info
.addr
);
1638 hostapd_notif_disassoc(hapd
, data
->deauth_info
.addr
);
1640 case EVENT_STATION_LOW_ACK
:
1643 hostapd_event_sta_low_ack(hapd
, data
->low_ack
.addr
);
1646 hostapd_notif_auth(hapd
, &data
->auth
);
1648 case EVENT_CH_SWITCH
:
1651 hostapd_event_ch_switch(hapd
, data
->ch_switch
.freq
,
1652 data
->ch_switch
.ht_enabled
,
1653 data
->ch_switch
.ch_offset
,
1654 data
->ch_switch
.ch_width
,
1655 data
->ch_switch
.cf1
,
1656 data
->ch_switch
.cf2
);
1658 case EVENT_CONNECT_FAILED_REASON
:
1661 hostapd_event_connect_failed_reason(
1662 hapd
, data
->connect_failed_reason
.addr
,
1663 data
->connect_failed_reason
.code
);
1666 hostapd_event_get_survey(hapd
->iface
, &data
->survey_results
);
1669 case EVENT_INTERFACE_UNAVAILABLE
:
1670 hostapd_event_iface_unavailable(hapd
);
1672 case EVENT_DFS_RADAR_DETECTED
:
1675 hostapd_event_dfs_radar_detected(hapd
, &data
->dfs_event
);
1677 case EVENT_DFS_PRE_CAC_EXPIRED
:
1680 hostapd_event_dfs_pre_cac_expired(hapd
, &data
->dfs_event
);
1682 case EVENT_DFS_CAC_FINISHED
:
1685 hostapd_event_dfs_cac_finished(hapd
, &data
->dfs_event
);
1687 case EVENT_DFS_CAC_ABORTED
:
1690 hostapd_event_dfs_cac_aborted(hapd
, &data
->dfs_event
);
1692 case EVENT_DFS_NOP_FINISHED
:
1695 hostapd_event_dfs_nop_finished(hapd
, &data
->dfs_event
);
1697 case EVENT_CHANNEL_LIST_CHANGED
:
1698 /* channel list changed (regulatory?), update channel list */
1699 /* TODO: check this. hostapd_get_hw_features() initializes
1700 * too much stuff. */
1701 /* hostapd_get_hw_features(hapd->iface); */
1702 hostapd_channel_list_updated(
1703 hapd
->iface
, data
->channel_list_changed
.initiator
);
1705 case EVENT_DFS_CAC_STARTED
:
1708 hostapd_event_dfs_cac_started(hapd
, &data
->dfs_event
);
1710 #endif /* NEED_AP_MLME */
1711 case EVENT_INTERFACE_ENABLED
:
1712 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, INTERFACE_ENABLED
);
1713 if (hapd
->disabled
&& hapd
->started
) {
1716 * Try to re-enable interface if the driver stopped it
1717 * when the interface got disabled.
1720 wpa_auth_reconfig_group_keys(hapd
->wpa_auth
);
1722 hostapd_reconfig_encryption(hapd
);
1723 hapd
->reenable_beacon
= 1;
1724 ieee802_11_set_beacon(hapd
);
1727 case EVENT_INTERFACE_DISABLED
:
1728 hostapd_free_stas(hapd
);
1729 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, INTERFACE_DISABLED
);
1733 case EVENT_ACS_CHANNEL_SELECTED
:
1734 hostapd_acs_channel_selected(hapd
,
1735 &data
->acs_selected_channels
);
1737 #endif /* CONFIG_ACS */
1738 case EVENT_STATION_OPMODE_CHANGED
:
1739 hostapd_event_sta_opmode_changed(hapd
, data
->sta_opmode
.addr
,
1740 data
->sta_opmode
.smps_mode
,
1741 data
->sta_opmode
.chan_width
,
1742 data
->sta_opmode
.rx_nss
);
1744 case EVENT_WDS_STA_INTERFACE_STATUS
:
1745 hostapd_event_wds_sta_interface_status(
1746 hapd
, data
->wds_sta_interface
.istatus
,
1747 data
->wds_sta_interface
.ifname
,
1748 data
->wds_sta_interface
.sta_addr
);
1751 wpa_printf(MSG_DEBUG
, "Unknown event %d", event
);
1757 void wpa_supplicant_event_global(void *ctx
, enum wpa_event_type event
,
1758 union wpa_event_data
*data
)
1760 struct hapd_interfaces
*interfaces
= ctx
;
1761 struct hostapd_data
*hapd
;
1763 if (event
!= EVENT_INTERFACE_STATUS
)
1766 hapd
= hostapd_get_iface(interfaces
, data
->interface_status
.ifname
);
1767 if (hapd
&& hapd
->driver
&& hapd
->driver
->get_ifindex
&&
1769 unsigned int ifindex
;
1771 ifindex
= hapd
->driver
->get_ifindex(hapd
->drv_priv
);
1772 if (ifindex
!= data
->interface_status
.ifindex
) {
1773 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
1774 "interface status ifindex %d mismatch (%d)",
1775 ifindex
, data
->interface_status
.ifindex
);
1780 wpa_supplicant_event(hapd
, event
, data
);
1783 #endif /* HOSTAPD */