1e28a4053SRui Paulo /*
2e28a4053SRui Paulo * hostapd / Callback functions for driver wrappers
35b9c547cSRui Paulo * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
4e28a4053SRui Paulo *
5f05cddf9SRui Paulo * This software may be distributed under the terms of the BSD license.
6f05cddf9SRui Paulo * See README for more details.
7e28a4053SRui Paulo */
8e28a4053SRui Paulo
9e28a4053SRui Paulo #include "utils/includes.h"
10e28a4053SRui Paulo
11e28a4053SRui Paulo #include "utils/common.h"
125b9c547cSRui Paulo #include "utils/eloop.h"
13e28a4053SRui Paulo #include "radius/radius.h"
14e28a4053SRui Paulo #include "drivers/driver.h"
15e28a4053SRui Paulo #include "common/ieee802_11_defs.h"
16e28a4053SRui Paulo #include "common/ieee802_11_common.h"
175b9c547cSRui Paulo #include "common/wpa_ctrl.h"
184bc52338SCy Schubert #include "common/dpp.h"
19c1d255d3SCy Schubert #include "common/sae.h"
20c1d255d3SCy Schubert #include "common/hw_features_common.h"
21f05cddf9SRui Paulo #include "crypto/random.h"
22f05cddf9SRui Paulo #include "p2p/p2p.h"
23f05cddf9SRui Paulo #include "wps/wps.h"
24325151a3SRui Paulo #include "fst/fst.h"
25f05cddf9SRui Paulo #include "wnm_ap.h"
26e28a4053SRui Paulo #include "hostapd.h"
27e28a4053SRui Paulo #include "ieee802_11.h"
28780fb4a2SCy Schubert #include "ieee802_11_auth.h"
29e28a4053SRui Paulo #include "sta_info.h"
30e28a4053SRui Paulo #include "accounting.h"
31e28a4053SRui Paulo #include "tkip_countermeasures.h"
32e28a4053SRui Paulo #include "ieee802_1x.h"
33e28a4053SRui Paulo #include "wpa_auth.h"
34e28a4053SRui Paulo #include "wps_hostapd.h"
35f05cddf9SRui Paulo #include "ap_drv_ops.h"
36e28a4053SRui Paulo #include "ap_config.h"
3785732ac8SCy Schubert #include "ap_mlme.h"
38f05cddf9SRui Paulo #include "hw_features.h"
395b9c547cSRui Paulo #include "dfs.h"
405b9c547cSRui Paulo #include "beacon.h"
41780fb4a2SCy Schubert #include "mbo_ap.h"
4285732ac8SCy Schubert #include "dpp_hostapd.h"
4385732ac8SCy Schubert #include "fils_hlp.h"
444bc52338SCy Schubert #include "neighbor_db.h"
45*a90b9d01SCy Schubert #include "nan_usd_ap.h"
4685732ac8SCy Schubert
4785732ac8SCy Schubert
4885732ac8SCy Schubert #ifdef CONFIG_FILS
hostapd_notify_assoc_fils_finish(struct hostapd_data * hapd,struct sta_info * sta)4985732ac8SCy Schubert void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd,
5085732ac8SCy Schubert struct sta_info *sta)
5185732ac8SCy Schubert {
5285732ac8SCy Schubert u16 reply_res = WLAN_STATUS_SUCCESS;
5385732ac8SCy Schubert struct ieee802_11_elems elems;
5485732ac8SCy Schubert u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf;
5585732ac8SCy Schubert int new_assoc;
56*a90b9d01SCy Schubert bool updated;
5785732ac8SCy Schubert
5885732ac8SCy Schubert wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR,
5985732ac8SCy Schubert __func__, MAC2STR(sta->addr));
6085732ac8SCy Schubert eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
6185732ac8SCy Schubert if (!sta->fils_pending_assoc_req)
6285732ac8SCy Schubert return;
6385732ac8SCy Schubert
64*a90b9d01SCy Schubert if (ieee802_11_parse_elems(sta->fils_pending_assoc_req,
65*a90b9d01SCy Schubert sta->fils_pending_assoc_req_len, &elems,
66*a90b9d01SCy Schubert 0) == ParseFailed ||
67*a90b9d01SCy Schubert !elems.fils_session) {
6885732ac8SCy Schubert wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element",
6985732ac8SCy Schubert __func__);
7085732ac8SCy Schubert return;
7185732ac8SCy Schubert }
7285732ac8SCy Schubert
7385732ac8SCy Schubert p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
7485732ac8SCy Schubert elems.fils_session,
7585732ac8SCy Schubert sta->fils_hlp_resp);
7685732ac8SCy Schubert
7785732ac8SCy Schubert reply_res = hostapd_sta_assoc(hapd, sta->addr,
7885732ac8SCy Schubert sta->fils_pending_assoc_is_reassoc,
7985732ac8SCy Schubert WLAN_STATUS_SUCCESS,
8085732ac8SCy Schubert buf, p - buf);
81*a90b9d01SCy Schubert updated = ap_sta_set_authorized_flag(hapd, sta, 1);
8285732ac8SCy Schubert new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
8385732ac8SCy Schubert sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
8485732ac8SCy Schubert sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
8585732ac8SCy Schubert hostapd_set_sta_flags(hapd, sta);
86*a90b9d01SCy Schubert if (updated)
87*a90b9d01SCy Schubert ap_sta_set_authorized_event(hapd, sta, 1);
8885732ac8SCy Schubert wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
8985732ac8SCy Schubert ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
9085732ac8SCy Schubert hostapd_new_assoc_sta(hapd, sta, !new_assoc);
9185732ac8SCy Schubert os_free(sta->fils_pending_assoc_req);
9285732ac8SCy Schubert sta->fils_pending_assoc_req = NULL;
9385732ac8SCy Schubert sta->fils_pending_assoc_req_len = 0;
9485732ac8SCy Schubert wpabuf_free(sta->fils_hlp_resp);
9585732ac8SCy Schubert sta->fils_hlp_resp = NULL;
9685732ac8SCy Schubert wpabuf_free(sta->hlp_dhcp_discover);
9785732ac8SCy Schubert sta->hlp_dhcp_discover = NULL;
9885732ac8SCy Schubert fils_hlp_deinit(hapd);
9985732ac8SCy Schubert
10085732ac8SCy Schubert /*
10185732ac8SCy Schubert * Remove the station in case transmission of a success response fails
10285732ac8SCy Schubert * (the STA was added associated to the driver) or if the station was
10385732ac8SCy Schubert * previously added unassociated.
10485732ac8SCy Schubert */
10585732ac8SCy Schubert if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) {
10685732ac8SCy Schubert hostapd_drv_sta_remove(hapd, sta->addr);
10785732ac8SCy Schubert sta->added_unassoc = 0;
10885732ac8SCy Schubert }
10985732ac8SCy Schubert }
11085732ac8SCy Schubert #endif /* CONFIG_FILS */
111e28a4053SRui Paulo
112e28a4053SRui Paulo
check_sa_query_need(struct hostapd_data * hapd,struct sta_info * sta)113c1d255d3SCy Schubert static bool check_sa_query_need(struct hostapd_data *hapd, struct sta_info *sta)
114c1d255d3SCy Schubert {
115c1d255d3SCy Schubert if ((sta->flags &
116c1d255d3SCy Schubert (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED)) !=
117c1d255d3SCy Schubert (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED))
118c1d255d3SCy Schubert return false;
119c1d255d3SCy Schubert
120c1d255d3SCy Schubert if (!sta->sa_query_timed_out && sta->sa_query_count > 0)
121c1d255d3SCy Schubert ap_check_sa_query_timeout(hapd, sta);
122c1d255d3SCy Schubert
123c1d255d3SCy Schubert if (!sta->sa_query_timed_out && (sta->auth_alg != WLAN_AUTH_FT)) {
124c1d255d3SCy Schubert /*
125c1d255d3SCy Schubert * STA has already been associated with MFP and SA Query timeout
126c1d255d3SCy Schubert * has not been reached. Reject the association attempt
127c1d255d3SCy Schubert * temporarily and start SA Query, if one is not pending.
128c1d255d3SCy Schubert */
129c1d255d3SCy Schubert if (sta->sa_query_count == 0)
130c1d255d3SCy Schubert ap_sta_start_sa_query(hapd, sta);
131c1d255d3SCy Schubert
132c1d255d3SCy Schubert return true;
133c1d255d3SCy Schubert }
134c1d255d3SCy Schubert
135c1d255d3SCy Schubert return false;
136c1d255d3SCy Schubert }
137c1d255d3SCy Schubert
138c1d255d3SCy Schubert
139*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
hostapd_update_sta_links_status(struct hostapd_data * hapd,struct sta_info * sta,const u8 * resp_ies,size_t resp_ies_len)140*a90b9d01SCy Schubert static int hostapd_update_sta_links_status(struct hostapd_data *hapd,
141*a90b9d01SCy Schubert struct sta_info *sta,
142*a90b9d01SCy Schubert const u8 *resp_ies,
143*a90b9d01SCy Schubert size_t resp_ies_len)
144*a90b9d01SCy Schubert {
145*a90b9d01SCy Schubert struct mld_info *info = &sta->mld_info;
146*a90b9d01SCy Schubert struct wpabuf *mlebuf;
147*a90b9d01SCy Schubert const u8 *mle, *pos;
148*a90b9d01SCy Schubert struct ieee802_11_elems elems;
149*a90b9d01SCy Schubert size_t mle_len, rem_len;
150*a90b9d01SCy Schubert int ret = 0;
151*a90b9d01SCy Schubert
152*a90b9d01SCy Schubert if (!resp_ies) {
153*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
154*a90b9d01SCy Schubert "MLO: (Re)Association Response frame elements not available");
155*a90b9d01SCy Schubert return -1;
156*a90b9d01SCy Schubert }
157*a90b9d01SCy Schubert
158*a90b9d01SCy Schubert if (ieee802_11_parse_elems(resp_ies, resp_ies_len, &elems, 0) ==
159*a90b9d01SCy Schubert ParseFailed) {
160*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
161*a90b9d01SCy Schubert "MLO: Failed to parse (Re)Association Response frame elements");
162*a90b9d01SCy Schubert return -1;
163*a90b9d01SCy Schubert }
164*a90b9d01SCy Schubert
165*a90b9d01SCy Schubert mlebuf = ieee802_11_defrag(elems.basic_mle, elems.basic_mle_len, true);
166*a90b9d01SCy Schubert if (!mlebuf) {
167*a90b9d01SCy Schubert wpa_printf(MSG_ERROR,
168*a90b9d01SCy Schubert "MLO: Basic Multi-Link element not found in (Re)Association Response frame");
169*a90b9d01SCy Schubert return -1;
170*a90b9d01SCy Schubert }
171*a90b9d01SCy Schubert
172*a90b9d01SCy Schubert mle = wpabuf_head(mlebuf);
173*a90b9d01SCy Schubert mle_len = wpabuf_len(mlebuf);
174*a90b9d01SCy Schubert if (mle_len < MULTI_LINK_CONTROL_LEN + 1 ||
175*a90b9d01SCy Schubert mle_len - MULTI_LINK_CONTROL_LEN < mle[MULTI_LINK_CONTROL_LEN]) {
176*a90b9d01SCy Schubert wpa_printf(MSG_ERROR,
177*a90b9d01SCy Schubert "MLO: Invalid Multi-Link element in (Re)Association Response frame");
178*a90b9d01SCy Schubert ret = -1;
179*a90b9d01SCy Schubert goto out;
180*a90b9d01SCy Schubert }
181*a90b9d01SCy Schubert
182*a90b9d01SCy Schubert /* Skip Common Info */
183*a90b9d01SCy Schubert pos = mle + MULTI_LINK_CONTROL_LEN + mle[MULTI_LINK_CONTROL_LEN];
184*a90b9d01SCy Schubert rem_len = mle_len -
185*a90b9d01SCy Schubert (MULTI_LINK_CONTROL_LEN + mle[MULTI_LINK_CONTROL_LEN]);
186*a90b9d01SCy Schubert
187*a90b9d01SCy Schubert /* Parse Subelements */
188*a90b9d01SCy Schubert while (rem_len > 2) {
189*a90b9d01SCy Schubert size_t ie_len = 2 + pos[1];
190*a90b9d01SCy Schubert
191*a90b9d01SCy Schubert if (rem_len < ie_len)
192*a90b9d01SCy Schubert break;
193*a90b9d01SCy Schubert
194*a90b9d01SCy Schubert if (pos[0] == MULTI_LINK_SUB_ELEM_ID_PER_STA_PROFILE) {
195*a90b9d01SCy Schubert u8 link_id;
196*a90b9d01SCy Schubert const u8 *sta_profile;
197*a90b9d01SCy Schubert size_t sta_profile_len;
198*a90b9d01SCy Schubert u16 sta_ctrl;
199*a90b9d01SCy Schubert
200*a90b9d01SCy Schubert if (pos[1] < BASIC_MLE_STA_CTRL_LEN + 1) {
201*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
202*a90b9d01SCy Schubert "MLO: Invalid per-STA profile IE");
203*a90b9d01SCy Schubert goto next_subelem;
204*a90b9d01SCy Schubert }
205*a90b9d01SCy Schubert
206*a90b9d01SCy Schubert sta_profile_len = pos[1];
207*a90b9d01SCy Schubert sta_profile = &pos[2];
208*a90b9d01SCy Schubert sta_ctrl = WPA_GET_LE16(sta_profile);
209*a90b9d01SCy Schubert link_id = sta_ctrl & BASIC_MLE_STA_CTRL_LINK_ID_MASK;
210*a90b9d01SCy Schubert if (link_id >= MAX_NUM_MLD_LINKS) {
211*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
212*a90b9d01SCy Schubert "MLO: Invalid link ID in per-STA profile IE");
213*a90b9d01SCy Schubert goto next_subelem;
214*a90b9d01SCy Schubert }
215*a90b9d01SCy Schubert
216*a90b9d01SCy Schubert /* Skip STA Control and STA Info */
217*a90b9d01SCy Schubert if (sta_profile_len - BASIC_MLE_STA_CTRL_LEN <
218*a90b9d01SCy Schubert sta_profile[BASIC_MLE_STA_CTRL_LEN]) {
219*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
220*a90b9d01SCy Schubert "MLO: Invalid STA info in per-STA profile IE");
221*a90b9d01SCy Schubert goto next_subelem;
222*a90b9d01SCy Schubert }
223*a90b9d01SCy Schubert
224*a90b9d01SCy Schubert sta_profile_len = sta_profile_len -
225*a90b9d01SCy Schubert (BASIC_MLE_STA_CTRL_LEN +
226*a90b9d01SCy Schubert sta_profile[BASIC_MLE_STA_CTRL_LEN]);
227*a90b9d01SCy Schubert sta_profile = sta_profile + BASIC_MLE_STA_CTRL_LEN +
228*a90b9d01SCy Schubert sta_profile[BASIC_MLE_STA_CTRL_LEN];
229*a90b9d01SCy Schubert
230*a90b9d01SCy Schubert /* Skip Capabilities Information field */
231*a90b9d01SCy Schubert if (sta_profile_len < 2)
232*a90b9d01SCy Schubert goto next_subelem;
233*a90b9d01SCy Schubert sta_profile_len -= 2;
234*a90b9d01SCy Schubert sta_profile += 2;
235*a90b9d01SCy Schubert
236*a90b9d01SCy Schubert /* Get status of the link */
237*a90b9d01SCy Schubert info->links[link_id].status = WPA_GET_LE16(sta_profile);
238*a90b9d01SCy Schubert }
239*a90b9d01SCy Schubert next_subelem:
240*a90b9d01SCy Schubert pos += ie_len;
241*a90b9d01SCy Schubert rem_len -= ie_len;
242*a90b9d01SCy Schubert }
243*a90b9d01SCy Schubert
244*a90b9d01SCy Schubert out:
245*a90b9d01SCy Schubert wpabuf_free(mlebuf);
246*a90b9d01SCy Schubert return ret;
247*a90b9d01SCy Schubert }
248*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
249*a90b9d01SCy Schubert
250*a90b9d01SCy Schubert
hostapd_notif_assoc(struct hostapd_data * hapd,const u8 * addr,const u8 * req_ies,size_t req_ies_len,const u8 * resp_ies,size_t resp_ies_len,const u8 * link_addr,int reassoc)251e28a4053SRui Paulo int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
252*a90b9d01SCy Schubert const u8 *req_ies, size_t req_ies_len,
253*a90b9d01SCy Schubert const u8 *resp_ies, size_t resp_ies_len,
254*a90b9d01SCy Schubert const u8 *link_addr, int reassoc)
255e28a4053SRui Paulo {
256e28a4053SRui Paulo struct sta_info *sta;
257c1d255d3SCy Schubert int new_assoc;
258c1d255d3SCy Schubert enum wpa_validate_result res;
259e28a4053SRui Paulo struct ieee802_11_elems elems;
260f05cddf9SRui Paulo const u8 *ie;
261f05cddf9SRui Paulo size_t ielen;
262f05cddf9SRui Paulo u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
263f05cddf9SRui Paulo u8 *p = buf;
264f05cddf9SRui Paulo u16 reason = WLAN_REASON_UNSPECIFIED;
265c1d255d3SCy Schubert int status = WLAN_STATUS_SUCCESS;
2665b9c547cSRui Paulo const u8 *p2p_dev_addr = NULL;
267*a90b9d01SCy Schubert #ifdef CONFIG_OWE
268*a90b9d01SCy Schubert struct hostapd_iface *iface = hapd->iface;
269*a90b9d01SCy Schubert #endif /* CONFIG_OWE */
270*a90b9d01SCy Schubert bool updated = false;
271e28a4053SRui Paulo
272e28a4053SRui Paulo if (addr == NULL) {
273e28a4053SRui Paulo /*
274e28a4053SRui Paulo * This could potentially happen with unexpected event from the
275e28a4053SRui Paulo * driver wrapper. This was seen at least in one case where the
276e28a4053SRui Paulo * driver ended up being set to station mode while hostapd was
277e28a4053SRui Paulo * running, so better make sure we stop processing such an
278e28a4053SRui Paulo * event here.
279e28a4053SRui Paulo */
280325151a3SRui Paulo wpa_printf(MSG_DEBUG,
281325151a3SRui Paulo "hostapd_notif_assoc: Skip event with no address");
282e28a4053SRui Paulo return -1;
283e28a4053SRui Paulo }
284c1d255d3SCy Schubert
285c1d255d3SCy Schubert if (is_multicast_ether_addr(addr) ||
286c1d255d3SCy Schubert is_zero_ether_addr(addr) ||
287*a90b9d01SCy Schubert ether_addr_equal(addr, hapd->own_addr)) {
288c1d255d3SCy Schubert /* Do not process any frames with unexpected/invalid SA so that
289c1d255d3SCy Schubert * we do not add any state for unexpected STA addresses or end
290c1d255d3SCy Schubert * up sending out frames to unexpected destination. */
291c1d255d3SCy Schubert wpa_printf(MSG_DEBUG, "%s: Invalid SA=" MACSTR
292c1d255d3SCy Schubert " in received indication - ignore this indication silently",
293c1d255d3SCy Schubert __func__, MAC2STR(addr));
294c1d255d3SCy Schubert return 0;
295c1d255d3SCy Schubert }
296c1d255d3SCy Schubert
297f05cddf9SRui Paulo random_add_randomness(addr, ETH_ALEN);
298e28a4053SRui Paulo
299e28a4053SRui Paulo hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
300e28a4053SRui Paulo HOSTAPD_LEVEL_INFO, "associated");
301e28a4053SRui Paulo
302*a90b9d01SCy Schubert if (ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0) ==
303*a90b9d01SCy Schubert ParseFailed) {
304*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG, "%s: Could not parse elements", __func__);
305*a90b9d01SCy Schubert return -1;
306*a90b9d01SCy Schubert }
307*a90b9d01SCy Schubert
308e28a4053SRui Paulo if (elems.wps_ie) {
309e28a4053SRui Paulo ie = elems.wps_ie - 2;
310e28a4053SRui Paulo ielen = elems.wps_ie_len + 2;
311e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
312e28a4053SRui Paulo } else if (elems.rsn_ie) {
313e28a4053SRui Paulo ie = elems.rsn_ie - 2;
314e28a4053SRui Paulo ielen = elems.rsn_ie_len + 2;
315e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
316e28a4053SRui Paulo } else if (elems.wpa_ie) {
317e28a4053SRui Paulo ie = elems.wpa_ie - 2;
318e28a4053SRui Paulo ielen = elems.wpa_ie_len + 2;
319e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
3205b9c547cSRui Paulo #ifdef CONFIG_HS20
3215b9c547cSRui Paulo } else if (elems.osen) {
3225b9c547cSRui Paulo ie = elems.osen - 2;
3235b9c547cSRui Paulo ielen = elems.osen_len + 2;
3245b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
3255b9c547cSRui Paulo #endif /* CONFIG_HS20 */
326e28a4053SRui Paulo } else {
327e28a4053SRui Paulo ie = NULL;
328e28a4053SRui Paulo ielen = 0;
329325151a3SRui Paulo wpa_printf(MSG_DEBUG,
330325151a3SRui Paulo "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
331e28a4053SRui Paulo }
332e28a4053SRui Paulo
333e28a4053SRui Paulo sta = ap_get_sta(hapd, addr);
334e28a4053SRui Paulo if (sta) {
3355b9c547cSRui Paulo ap_sta_no_session_timeout(hapd, sta);
336e28a4053SRui Paulo accounting_sta_stop(hapd, sta);
337f05cddf9SRui Paulo
338f05cddf9SRui Paulo /*
339f05cddf9SRui Paulo * Make sure that the previously registered inactivity timer
340f05cddf9SRui Paulo * will not remove the STA immediately.
341f05cddf9SRui Paulo */
342f05cddf9SRui Paulo sta->timeout_next = STA_NULLFUNC;
343e28a4053SRui Paulo } else {
344e28a4053SRui Paulo sta = ap_sta_add(hapd, addr);
345f05cddf9SRui Paulo if (sta == NULL) {
346f05cddf9SRui Paulo hostapd_drv_sta_disassoc(hapd, addr,
347f05cddf9SRui Paulo WLAN_REASON_DISASSOC_AP_BUSY);
348e28a4053SRui Paulo return -1;
349e28a4053SRui Paulo }
350f05cddf9SRui Paulo }
351*a90b9d01SCy Schubert
352*a90b9d01SCy Schubert if (hapd->conf->wpa && check_sa_query_need(hapd, sta)) {
353*a90b9d01SCy Schubert status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
354*a90b9d01SCy Schubert p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
355*a90b9d01SCy Schubert hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
356*a90b9d01SCy Schubert
357*a90b9d01SCy Schubert return 0;
358*a90b9d01SCy Schubert }
359*a90b9d01SCy Schubert
360*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
361*a90b9d01SCy Schubert if (link_addr) {
362*a90b9d01SCy Schubert struct mld_info *info = &sta->mld_info;
363*a90b9d01SCy Schubert int i, num_valid_links = 0;
364*a90b9d01SCy Schubert u8 link_id = hapd->mld_link_id;
365*a90b9d01SCy Schubert
366*a90b9d01SCy Schubert ap_sta_set_mld(sta, true);
367*a90b9d01SCy Schubert sta->mld_assoc_link_id = link_id;
368*a90b9d01SCy Schubert os_memcpy(info->common_info.mld_addr, addr, ETH_ALEN);
369*a90b9d01SCy Schubert info->links[link_id].valid = true;
370*a90b9d01SCy Schubert os_memcpy(info->links[link_id].peer_addr, link_addr, ETH_ALEN);
371*a90b9d01SCy Schubert os_memcpy(info->links[link_id].local_addr, hapd->own_addr,
372*a90b9d01SCy Schubert ETH_ALEN);
373*a90b9d01SCy Schubert
374*a90b9d01SCy Schubert if (!elems.basic_mle ||
375*a90b9d01SCy Schubert hostapd_process_ml_assoc_req(hapd, &elems, sta) !=
376*a90b9d01SCy Schubert WLAN_STATUS_SUCCESS) {
377*a90b9d01SCy Schubert reason = WLAN_REASON_UNSPECIFIED;
378*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
379*a90b9d01SCy Schubert "Failed to get STA non-assoc links info");
380*a90b9d01SCy Schubert goto fail;
381*a90b9d01SCy Schubert }
382*a90b9d01SCy Schubert
383*a90b9d01SCy Schubert for (i = 0 ; i < MAX_NUM_MLD_LINKS; i++) {
384*a90b9d01SCy Schubert if (info->links[i].valid)
385*a90b9d01SCy Schubert num_valid_links++;
386*a90b9d01SCy Schubert }
387*a90b9d01SCy Schubert if (num_valid_links > 1 &&
388*a90b9d01SCy Schubert hostapd_update_sta_links_status(hapd, sta, resp_ies,
389*a90b9d01SCy Schubert resp_ies_len)) {
390*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
391*a90b9d01SCy Schubert "Failed to get STA non-assoc links status info");
392*a90b9d01SCy Schubert reason = WLAN_REASON_UNSPECIFIED;
393*a90b9d01SCy Schubert goto fail;
394*a90b9d01SCy Schubert }
395*a90b9d01SCy Schubert }
396*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
397*a90b9d01SCy Schubert
398f05cddf9SRui Paulo sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
399f05cddf9SRui Paulo
400780fb4a2SCy Schubert /*
401780fb4a2SCy Schubert * ACL configurations to the drivers (implementing AP SME and ACL
402780fb4a2SCy Schubert * offload) without hostapd's knowledge, can result in a disconnection
403780fb4a2SCy Schubert * though the driver accepts the connection. Skip the hostapd check for
404780fb4a2SCy Schubert * ACL if the driver supports ACL offload to avoid potentially
405780fb4a2SCy Schubert * conflicting ACL rules.
406780fb4a2SCy Schubert */
407780fb4a2SCy Schubert if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
408780fb4a2SCy Schubert hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
409780fb4a2SCy Schubert wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
410780fb4a2SCy Schubert MAC2STR(addr));
411780fb4a2SCy Schubert reason = WLAN_REASON_UNSPECIFIED;
412780fb4a2SCy Schubert goto fail;
413780fb4a2SCy Schubert }
414780fb4a2SCy Schubert
415f05cddf9SRui Paulo #ifdef CONFIG_P2P
416f05cddf9SRui Paulo if (elems.p2p) {
417f05cddf9SRui Paulo wpabuf_free(sta->p2p_ie);
418f05cddf9SRui Paulo sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
419f05cddf9SRui Paulo P2P_IE_VENDOR_TYPE);
4205b9c547cSRui Paulo if (sta->p2p_ie)
4215b9c547cSRui Paulo p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
422f05cddf9SRui Paulo }
423f05cddf9SRui Paulo #endif /* CONFIG_P2P */
424f05cddf9SRui Paulo
4255b9c547cSRui Paulo #ifdef NEED_AP_MLME
4265b9c547cSRui Paulo if (elems.ht_capabilities &&
4275b9c547cSRui Paulo (hapd->iface->conf->ht_capab &
4285b9c547cSRui Paulo HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
4295b9c547cSRui Paulo struct ieee80211_ht_capabilities *ht_cap =
4305b9c547cSRui Paulo (struct ieee80211_ht_capabilities *)
4315b9c547cSRui Paulo elems.ht_capabilities;
4325b9c547cSRui Paulo
4335b9c547cSRui Paulo if (le_to_host16(ht_cap->ht_capabilities_info) &
4345b9c547cSRui Paulo HT_CAP_INFO_40MHZ_INTOLERANT)
4355b9c547cSRui Paulo ht40_intolerant_add(hapd->iface, sta);
4365b9c547cSRui Paulo }
4375b9c547cSRui Paulo #endif /* NEED_AP_MLME */
4385b9c547cSRui Paulo
439*a90b9d01SCy Schubert check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
4405b9c547cSRui Paulo
441f05cddf9SRui Paulo #ifdef CONFIG_HS20
442f05cddf9SRui Paulo wpabuf_free(sta->hs20_ie);
443f05cddf9SRui Paulo if (elems.hs20 && elems.hs20_len > 4) {
444f05cddf9SRui Paulo sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
445f05cddf9SRui Paulo elems.hs20_len - 4);
446f05cddf9SRui Paulo } else
447f05cddf9SRui Paulo sta->hs20_ie = NULL;
44885732ac8SCy Schubert
44985732ac8SCy Schubert wpabuf_free(sta->roaming_consortium);
45085732ac8SCy Schubert if (elems.roaming_cons_sel)
45185732ac8SCy Schubert sta->roaming_consortium = wpabuf_alloc_copy(
45285732ac8SCy Schubert elems.roaming_cons_sel + 4,
45385732ac8SCy Schubert elems.roaming_cons_sel_len - 4);
45485732ac8SCy Schubert else
45585732ac8SCy Schubert sta->roaming_consortium = NULL;
456f05cddf9SRui Paulo #endif /* CONFIG_HS20 */
457e28a4053SRui Paulo
458325151a3SRui Paulo #ifdef CONFIG_FST
459325151a3SRui Paulo wpabuf_free(sta->mb_ies);
460325151a3SRui Paulo if (hapd->iface->fst)
461325151a3SRui Paulo sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
462325151a3SRui Paulo else
463325151a3SRui Paulo sta->mb_ies = NULL;
464325151a3SRui Paulo #endif /* CONFIG_FST */
465325151a3SRui Paulo
466780fb4a2SCy Schubert mbo_ap_check_sta_assoc(hapd, sta, &elems);
467780fb4a2SCy Schubert
468780fb4a2SCy Schubert ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
469780fb4a2SCy Schubert elems.supp_op_classes_len);
470780fb4a2SCy Schubert
471e28a4053SRui Paulo if (hapd->conf->wpa) {
472e28a4053SRui Paulo if (ie == NULL || ielen == 0) {
473f05cddf9SRui Paulo #ifdef CONFIG_WPS
474e28a4053SRui Paulo if (hapd->conf->wps_state) {
475325151a3SRui Paulo wpa_printf(MSG_DEBUG,
476325151a3SRui Paulo "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
477e28a4053SRui Paulo sta->flags |= WLAN_STA_MAYBE_WPS;
478e28a4053SRui Paulo goto skip_wpa_check;
479e28a4053SRui Paulo }
480f05cddf9SRui Paulo #endif /* CONFIG_WPS */
481e28a4053SRui Paulo
482e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
48385732ac8SCy Schubert reason = WLAN_REASON_INVALID_IE;
48485732ac8SCy Schubert status = WLAN_STATUS_INVALID_IE;
48585732ac8SCy Schubert goto fail;
486e28a4053SRui Paulo }
487f05cddf9SRui Paulo #ifdef CONFIG_WPS
488e28a4053SRui Paulo if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
489e28a4053SRui Paulo os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
490f05cddf9SRui Paulo struct wpabuf *wps;
491325151a3SRui Paulo
492e28a4053SRui Paulo sta->flags |= WLAN_STA_WPS;
493f05cddf9SRui Paulo wps = ieee802_11_vendor_ie_concat(ie, ielen,
494f05cddf9SRui Paulo WPS_IE_VENDOR_TYPE);
495f05cddf9SRui Paulo if (wps) {
496f05cddf9SRui Paulo if (wps_is_20(wps)) {
497325151a3SRui Paulo wpa_printf(MSG_DEBUG,
498325151a3SRui Paulo "WPS: STA supports WPS 2.0");
499f05cddf9SRui Paulo sta->flags |= WLAN_STA_WPS2;
500f05cddf9SRui Paulo }
501f05cddf9SRui Paulo wpabuf_free(wps);
502f05cddf9SRui Paulo }
503e28a4053SRui Paulo goto skip_wpa_check;
504e28a4053SRui Paulo }
505f05cddf9SRui Paulo #endif /* CONFIG_WPS */
506e28a4053SRui Paulo
507e28a4053SRui Paulo if (sta->wpa_sm == NULL)
508e28a4053SRui Paulo sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
5095b9c547cSRui Paulo sta->addr,
5105b9c547cSRui Paulo p2p_dev_addr);
511e28a4053SRui Paulo if (sta->wpa_sm == NULL) {
512325151a3SRui Paulo wpa_printf(MSG_ERROR,
513325151a3SRui Paulo "Failed to initialize WPA state machine");
514e28a4053SRui Paulo return -1;
515e28a4053SRui Paulo }
516*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
517*a90b9d01SCy Schubert if (ap_sta_is_mld(hapd, sta)) {
518*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
519*a90b9d01SCy Schubert "MLD: Set ML info in RSN Authenticator");
520*a90b9d01SCy Schubert wpa_auth_set_ml_info(sta->wpa_sm,
521*a90b9d01SCy Schubert sta->mld_assoc_link_id,
522*a90b9d01SCy Schubert &sta->mld_info);
523*a90b9d01SCy Schubert }
524*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
525e28a4053SRui Paulo res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
5264bc52338SCy Schubert hapd->iface->freq,
527f05cddf9SRui Paulo ie, ielen,
528c1d255d3SCy Schubert elems.rsnxe ? elems.rsnxe - 2 : NULL,
529c1d255d3SCy Schubert elems.rsnxe ? elems.rsnxe_len + 2 : 0,
53085732ac8SCy Schubert elems.mdie, elems.mdie_len,
531*a90b9d01SCy Schubert elems.owe_dh, elems.owe_dh_len, NULL);
532c1d255d3SCy Schubert reason = WLAN_REASON_INVALID_IE;
533c1d255d3SCy Schubert status = WLAN_STATUS_INVALID_IE;
534c1d255d3SCy Schubert switch (res) {
535c1d255d3SCy Schubert case WPA_IE_OK:
536c1d255d3SCy Schubert reason = WLAN_REASON_UNSPECIFIED;
537c1d255d3SCy Schubert status = WLAN_STATUS_SUCCESS;
538c1d255d3SCy Schubert break;
539c1d255d3SCy Schubert case WPA_INVALID_IE:
540c1d255d3SCy Schubert reason = WLAN_REASON_INVALID_IE;
541c1d255d3SCy Schubert status = WLAN_STATUS_INVALID_IE;
542c1d255d3SCy Schubert break;
543c1d255d3SCy Schubert case WPA_INVALID_GROUP:
544c1d255d3SCy Schubert reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
545c1d255d3SCy Schubert status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
546c1d255d3SCy Schubert break;
547c1d255d3SCy Schubert case WPA_INVALID_PAIRWISE:
548c1d255d3SCy Schubert reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
549c1d255d3SCy Schubert status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
550c1d255d3SCy Schubert break;
551c1d255d3SCy Schubert case WPA_INVALID_AKMP:
552c1d255d3SCy Schubert reason = WLAN_REASON_AKMP_NOT_VALID;
553c1d255d3SCy Schubert status = WLAN_STATUS_AKMP_NOT_VALID;
554c1d255d3SCy Schubert break;
555c1d255d3SCy Schubert case WPA_NOT_ENABLED:
556c1d255d3SCy Schubert reason = WLAN_REASON_INVALID_IE;
557c1d255d3SCy Schubert status = WLAN_STATUS_INVALID_IE;
558c1d255d3SCy Schubert break;
559c1d255d3SCy Schubert case WPA_ALLOC_FAIL:
560c1d255d3SCy Schubert reason = WLAN_REASON_UNSPECIFIED;
561c1d255d3SCy Schubert status = WLAN_STATUS_UNSPECIFIED_FAILURE;
562c1d255d3SCy Schubert break;
563c1d255d3SCy Schubert case WPA_MGMT_FRAME_PROTECTION_VIOLATION:
564c1d255d3SCy Schubert reason = WLAN_REASON_INVALID_IE;
565c1d255d3SCy Schubert status = WLAN_STATUS_INVALID_IE;
566c1d255d3SCy Schubert break;
567c1d255d3SCy Schubert case WPA_INVALID_MGMT_GROUP_CIPHER:
568c1d255d3SCy Schubert reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
569c1d255d3SCy Schubert status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
570c1d255d3SCy Schubert break;
571c1d255d3SCy Schubert case WPA_INVALID_MDIE:
572c1d255d3SCy Schubert reason = WLAN_REASON_INVALID_MDE;
573c1d255d3SCy Schubert status = WLAN_STATUS_INVALID_MDIE;
574c1d255d3SCy Schubert break;
575c1d255d3SCy Schubert case WPA_INVALID_PROTO:
576c1d255d3SCy Schubert reason = WLAN_REASON_INVALID_IE;
577c1d255d3SCy Schubert status = WLAN_STATUS_INVALID_IE;
578c1d255d3SCy Schubert break;
579c1d255d3SCy Schubert case WPA_INVALID_PMKID:
580c1d255d3SCy Schubert reason = WLAN_REASON_INVALID_PMKID;
581c1d255d3SCy Schubert status = WLAN_STATUS_INVALID_PMKID;
582c1d255d3SCy Schubert break;
583c1d255d3SCy Schubert case WPA_DENIED_OTHER_REASON:
584c1d255d3SCy Schubert reason = WLAN_REASON_UNSPECIFIED;
585c1d255d3SCy Schubert status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
586c1d255d3SCy Schubert break;
587c1d255d3SCy Schubert }
588c1d255d3SCy Schubert if (status != WLAN_STATUS_SUCCESS) {
589325151a3SRui Paulo wpa_printf(MSG_DEBUG,
590325151a3SRui Paulo "WPA/RSN information element rejected? (res %u)",
591325151a3SRui Paulo res);
592e28a4053SRui Paulo wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
593f05cddf9SRui Paulo goto fail;
594f05cddf9SRui Paulo }
595f05cddf9SRui Paulo
596f05cddf9SRui Paulo if (wpa_auth_uses_mfp(sta->wpa_sm))
597f05cddf9SRui Paulo sta->flags |= WLAN_STA_MFP;
598f05cddf9SRui Paulo else
599f05cddf9SRui Paulo sta->flags &= ~WLAN_STA_MFP;
600f05cddf9SRui Paulo
60185732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
602f05cddf9SRui Paulo if (sta->auth_alg == WLAN_AUTH_FT) {
603f05cddf9SRui Paulo status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
604f05cddf9SRui Paulo req_ies_len);
605f05cddf9SRui Paulo if (status != WLAN_STATUS_SUCCESS) {
606f05cddf9SRui Paulo if (status == WLAN_STATUS_INVALID_PMKID)
607f05cddf9SRui Paulo reason = WLAN_REASON_INVALID_IE;
608f05cddf9SRui Paulo if (status == WLAN_STATUS_INVALID_MDIE)
609f05cddf9SRui Paulo reason = WLAN_REASON_INVALID_IE;
610f05cddf9SRui Paulo if (status == WLAN_STATUS_INVALID_FTIE)
611f05cddf9SRui Paulo reason = WLAN_REASON_INVALID_IE;
612f05cddf9SRui Paulo goto fail;
613f05cddf9SRui Paulo }
614f05cddf9SRui Paulo }
61585732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
616c1d255d3SCy Schubert #ifdef CONFIG_SAE
617*a90b9d01SCy Schubert if (hapd->conf->sae_pwe == SAE_PWE_BOTH &&
618c1d255d3SCy Schubert sta->auth_alg == WLAN_AUTH_SAE &&
619c1d255d3SCy Schubert sta->sae && !sta->sae->h2e &&
620c1d255d3SCy Schubert ieee802_11_rsnx_capab_len(elems.rsnxe, elems.rsnxe_len,
621c1d255d3SCy Schubert WLAN_RSNX_CAPAB_SAE_H2E)) {
622c1d255d3SCy Schubert wpa_printf(MSG_INFO, "SAE: " MACSTR
623c1d255d3SCy Schubert " indicates support for SAE H2E, but did not use it",
624c1d255d3SCy Schubert MAC2STR(sta->addr));
625c1d255d3SCy Schubert status = WLAN_STATUS_UNSPECIFIED_FAILURE;
626c1d255d3SCy Schubert reason = WLAN_REASON_UNSPECIFIED;
627c1d255d3SCy Schubert goto fail;
628c1d255d3SCy Schubert }
629c1d255d3SCy Schubert #endif /* CONFIG_SAE */
630e28a4053SRui Paulo } else if (hapd->conf->wps_state) {
631f05cddf9SRui Paulo #ifdef CONFIG_WPS
632f05cddf9SRui Paulo struct wpabuf *wps;
633325151a3SRui Paulo
634f05cddf9SRui Paulo if (req_ies)
635f05cddf9SRui Paulo wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
636f05cddf9SRui Paulo WPS_IE_VENDOR_TYPE);
637f05cddf9SRui Paulo else
638f05cddf9SRui Paulo wps = NULL;
639f05cddf9SRui Paulo #ifdef CONFIG_WPS_STRICT
640f05cddf9SRui Paulo if (wps && wps_validate_assoc_req(wps) < 0) {
641f05cddf9SRui Paulo reason = WLAN_REASON_INVALID_IE;
642f05cddf9SRui Paulo status = WLAN_STATUS_INVALID_IE;
643f05cddf9SRui Paulo wpabuf_free(wps);
644f05cddf9SRui Paulo goto fail;
645f05cddf9SRui Paulo }
646f05cddf9SRui Paulo #endif /* CONFIG_WPS_STRICT */
647f05cddf9SRui Paulo if (wps) {
648e28a4053SRui Paulo sta->flags |= WLAN_STA_WPS;
649f05cddf9SRui Paulo if (wps_is_20(wps)) {
650325151a3SRui Paulo wpa_printf(MSG_DEBUG,
651325151a3SRui Paulo "WPS: STA supports WPS 2.0");
652f05cddf9SRui Paulo sta->flags |= WLAN_STA_WPS2;
653f05cddf9SRui Paulo }
654e28a4053SRui Paulo } else
655e28a4053SRui Paulo sta->flags |= WLAN_STA_MAYBE_WPS;
656f05cddf9SRui Paulo wpabuf_free(wps);
657f05cddf9SRui Paulo #endif /* CONFIG_WPS */
6585b9c547cSRui Paulo #ifdef CONFIG_HS20
6595b9c547cSRui Paulo } else if (hapd->conf->osen) {
6605b9c547cSRui Paulo if (elems.osen == NULL) {
6615b9c547cSRui Paulo hostapd_logger(
6625b9c547cSRui Paulo hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
6635b9c547cSRui Paulo HOSTAPD_LEVEL_INFO,
6645b9c547cSRui Paulo "No HS 2.0 OSEN element in association request");
6655b9c547cSRui Paulo return WLAN_STATUS_INVALID_IE;
6665b9c547cSRui Paulo }
6675b9c547cSRui Paulo
6685b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
6695b9c547cSRui Paulo if (sta->wpa_sm == NULL)
6705b9c547cSRui Paulo sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
6715b9c547cSRui Paulo sta->addr, NULL);
6725b9c547cSRui Paulo if (sta->wpa_sm == NULL) {
673325151a3SRui Paulo wpa_printf(MSG_WARNING,
674325151a3SRui Paulo "Failed to initialize WPA state machine");
6755b9c547cSRui Paulo return WLAN_STATUS_UNSPECIFIED_FAILURE;
6765b9c547cSRui Paulo }
6775b9c547cSRui Paulo if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
6785b9c547cSRui Paulo elems.osen - 2, elems.osen_len + 2) < 0)
6795b9c547cSRui Paulo return WLAN_STATUS_INVALID_IE;
6805b9c547cSRui Paulo #endif /* CONFIG_HS20 */
681e28a4053SRui Paulo }
682c1d255d3SCy Schubert #ifdef CONFIG_WPS
683c1d255d3SCy Schubert skip_wpa_check:
684c1d255d3SCy Schubert #endif /* CONFIG_WPS */
685780fb4a2SCy Schubert
686780fb4a2SCy Schubert #ifdef CONFIG_MBO
687780fb4a2SCy Schubert if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
688780fb4a2SCy Schubert elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
689780fb4a2SCy Schubert hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
690780fb4a2SCy Schubert wpa_printf(MSG_INFO,
691780fb4a2SCy Schubert "MBO: Reject WPA2 association without PMF");
692780fb4a2SCy Schubert return WLAN_STATUS_UNSPECIFIED_FAILURE;
693780fb4a2SCy Schubert }
694780fb4a2SCy Schubert #endif /* CONFIG_MBO */
695780fb4a2SCy Schubert
69685732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
697f05cddf9SRui Paulo p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
698c1d255d3SCy Schubert sta->auth_alg, req_ies, req_ies_len,
699c1d255d3SCy Schubert !elems.rsnxe);
70085732ac8SCy Schubert if (!p) {
70185732ac8SCy Schubert wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs");
70285732ac8SCy Schubert return WLAN_STATUS_UNSPECIFIED_FAILURE;
70385732ac8SCy Schubert }
70485732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
705f05cddf9SRui Paulo
70685732ac8SCy Schubert #ifdef CONFIG_FILS
70785732ac8SCy Schubert if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
70885732ac8SCy Schubert sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
70985732ac8SCy Schubert sta->auth_alg == WLAN_AUTH_FILS_PK) {
71085732ac8SCy Schubert int delay_assoc = 0;
71185732ac8SCy Schubert
71285732ac8SCy Schubert if (!req_ies)
71385732ac8SCy Schubert return WLAN_STATUS_UNSPECIFIED_FAILURE;
71485732ac8SCy Schubert
71585732ac8SCy Schubert if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies,
71685732ac8SCy Schubert req_ies_len,
71785732ac8SCy Schubert sta->fils_session)) {
71885732ac8SCy Schubert wpa_printf(MSG_DEBUG,
71985732ac8SCy Schubert "FILS: Session validation failed");
72085732ac8SCy Schubert return WLAN_STATUS_UNSPECIFIED_FAILURE;
72185732ac8SCy Schubert }
72285732ac8SCy Schubert
72385732ac8SCy Schubert res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies,
72485732ac8SCy Schubert req_ies_len);
72585732ac8SCy Schubert if (res < 0) {
72685732ac8SCy Schubert wpa_printf(MSG_DEBUG,
72785732ac8SCy Schubert "FILS: Key Confirm validation failed");
72885732ac8SCy Schubert return WLAN_STATUS_UNSPECIFIED_FAILURE;
72985732ac8SCy Schubert }
73085732ac8SCy Schubert
73185732ac8SCy Schubert if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) {
73285732ac8SCy Schubert wpa_printf(MSG_DEBUG,
73385732ac8SCy Schubert "FILS: Delaying Assoc Response (HLP)");
73485732ac8SCy Schubert delay_assoc = 1;
73585732ac8SCy Schubert } else {
73685732ac8SCy Schubert wpa_printf(MSG_DEBUG,
73785732ac8SCy Schubert "FILS: Going ahead with Assoc Response (no HLP)");
73885732ac8SCy Schubert }
73985732ac8SCy Schubert
74085732ac8SCy Schubert if (sta) {
74185732ac8SCy Schubert wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup");
74285732ac8SCy Schubert eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
74385732ac8SCy Schubert os_free(sta->fils_pending_assoc_req);
74485732ac8SCy Schubert sta->fils_pending_assoc_req = NULL;
74585732ac8SCy Schubert sta->fils_pending_assoc_req_len = 0;
74685732ac8SCy Schubert wpabuf_free(sta->fils_hlp_resp);
74785732ac8SCy Schubert sta->fils_hlp_resp = NULL;
74885732ac8SCy Schubert sta->fils_drv_assoc_finish = 0;
74985732ac8SCy Schubert }
75085732ac8SCy Schubert
75185732ac8SCy Schubert if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) {
75285732ac8SCy Schubert u8 *req_tmp;
75385732ac8SCy Schubert
75485732ac8SCy Schubert req_tmp = os_malloc(req_ies_len);
75585732ac8SCy Schubert if (!req_tmp) {
75685732ac8SCy Schubert wpa_printf(MSG_DEBUG,
75785732ac8SCy Schubert "FILS: buffer allocation failed for assoc req");
75885732ac8SCy Schubert goto fail;
75985732ac8SCy Schubert }
76085732ac8SCy Schubert os_memcpy(req_tmp, req_ies, req_ies_len);
76185732ac8SCy Schubert sta->fils_pending_assoc_req = req_tmp;
76285732ac8SCy Schubert sta->fils_pending_assoc_req_len = req_ies_len;
76385732ac8SCy Schubert sta->fils_pending_assoc_is_reassoc = reassoc;
76485732ac8SCy Schubert sta->fils_drv_assoc_finish = 1;
76585732ac8SCy Schubert wpa_printf(MSG_DEBUG,
76685732ac8SCy Schubert "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
76785732ac8SCy Schubert MACSTR, MAC2STR(sta->addr));
76885732ac8SCy Schubert eloop_register_timeout(
76985732ac8SCy Schubert 0, hapd->conf->fils_hlp_wait_time * 1024,
77085732ac8SCy Schubert fils_hlp_timeout, hapd, sta);
77185732ac8SCy Schubert return 0;
77285732ac8SCy Schubert }
77385732ac8SCy Schubert p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
77485732ac8SCy Schubert elems.fils_session,
77585732ac8SCy Schubert sta->fils_hlp_resp);
77685732ac8SCy Schubert wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)",
77785732ac8SCy Schubert buf, p - buf);
77885732ac8SCy Schubert }
77985732ac8SCy Schubert #endif /* CONFIG_FILS */
78085732ac8SCy Schubert
78185732ac8SCy Schubert #ifdef CONFIG_OWE
78285732ac8SCy Schubert if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
783*a90b9d01SCy Schubert !(iface->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_AP) &&
78485732ac8SCy Schubert wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
78585732ac8SCy Schubert elems.owe_dh) {
78685732ac8SCy Schubert u8 *npos;
787c1d255d3SCy Schubert u16 ret_status;
78885732ac8SCy Schubert
78985732ac8SCy Schubert npos = owe_assoc_req_process(hapd, sta,
79085732ac8SCy Schubert elems.owe_dh, elems.owe_dh_len,
79185732ac8SCy Schubert p, sizeof(buf) - (p - buf),
792c1d255d3SCy Schubert &ret_status);
793c1d255d3SCy Schubert status = ret_status;
79485732ac8SCy Schubert if (npos)
79585732ac8SCy Schubert p = npos;
796c1d255d3SCy Schubert
79785732ac8SCy Schubert if (!npos &&
798c1d255d3SCy Schubert status == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
799c1d255d3SCy Schubert hostapd_sta_assoc(hapd, addr, reassoc, ret_status, buf,
80085732ac8SCy Schubert p - buf);
80185732ac8SCy Schubert return 0;
80285732ac8SCy Schubert }
80385732ac8SCy Schubert
804c1d255d3SCy Schubert if (!npos || status != WLAN_STATUS_SUCCESS)
80585732ac8SCy Schubert goto fail;
80685732ac8SCy Schubert }
80785732ac8SCy Schubert #endif /* CONFIG_OWE */
80885732ac8SCy Schubert
8094bc52338SCy Schubert #ifdef CONFIG_DPP2
8104bc52338SCy Schubert dpp_pfs_free(sta->dpp_pfs);
8114bc52338SCy Schubert sta->dpp_pfs = NULL;
8124bc52338SCy Schubert
8134bc52338SCy Schubert if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
8144bc52338SCy Schubert hapd->conf->dpp_netaccesskey && sta->wpa_sm &&
8154bc52338SCy Schubert wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP &&
8164bc52338SCy Schubert elems.owe_dh) {
8174bc52338SCy Schubert sta->dpp_pfs = dpp_pfs_init(
8184bc52338SCy Schubert wpabuf_head(hapd->conf->dpp_netaccesskey),
8194bc52338SCy Schubert wpabuf_len(hapd->conf->dpp_netaccesskey));
8204bc52338SCy Schubert if (!sta->dpp_pfs) {
8214bc52338SCy Schubert wpa_printf(MSG_DEBUG,
8224bc52338SCy Schubert "DPP: Could not initialize PFS");
8234bc52338SCy Schubert /* Try to continue without PFS */
8244bc52338SCy Schubert goto pfs_fail;
8254bc52338SCy Schubert }
8264bc52338SCy Schubert
8274bc52338SCy Schubert if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh,
8284bc52338SCy Schubert elems.owe_dh_len) < 0) {
8294bc52338SCy Schubert dpp_pfs_free(sta->dpp_pfs);
8304bc52338SCy Schubert sta->dpp_pfs = NULL;
8314bc52338SCy Schubert reason = WLAN_REASON_UNSPECIFIED;
8324bc52338SCy Schubert goto fail;
8334bc52338SCy Schubert }
8344bc52338SCy Schubert }
8354bc52338SCy Schubert
8364bc52338SCy Schubert wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ?
8374bc52338SCy Schubert sta->dpp_pfs->secret : NULL);
8384bc52338SCy Schubert pfs_fail:
8394bc52338SCy Schubert #endif /* CONFIG_DPP2 */
8404bc52338SCy Schubert
841c1d255d3SCy Schubert if (elems.rrm_enabled &&
842c1d255d3SCy Schubert elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
843c1d255d3SCy Schubert os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
844c1d255d3SCy Schubert sizeof(sta->rrm_enabled_capa));
845c1d255d3SCy Schubert
84685732ac8SCy Schubert #if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
847f05cddf9SRui Paulo hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
8485b9c547cSRui Paulo
84985732ac8SCy Schubert if (sta->auth_alg == WLAN_AUTH_FT ||
85085732ac8SCy Schubert sta->auth_alg == WLAN_AUTH_FILS_SK ||
85185732ac8SCy Schubert sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
85285732ac8SCy Schubert sta->auth_alg == WLAN_AUTH_FILS_PK)
853*a90b9d01SCy Schubert updated = ap_sta_set_authorized_flag(hapd, sta, 1);
85485732ac8SCy Schubert #else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
855f05cddf9SRui Paulo /* Keep compiler silent about unused variables */
856f05cddf9SRui Paulo if (status) {
857f05cddf9SRui Paulo }
85885732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
859e28a4053SRui Paulo
860*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
861*a90b9d01SCy Schubert if (hostapd_process_assoc_ml_info(hapd, sta, req_ies, req_ies_len,
862*a90b9d01SCy Schubert !!reassoc, WLAN_STATUS_SUCCESS,
863*a90b9d01SCy Schubert true)) {
864*a90b9d01SCy Schubert status = WLAN_STATUS_UNSPECIFIED_FAILURE;
865*a90b9d01SCy Schubert reason = WLAN_REASON_UNSPECIFIED;
866*a90b9d01SCy Schubert goto fail;
867*a90b9d01SCy Schubert }
868*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
869*a90b9d01SCy Schubert
870e28a4053SRui Paulo new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
871e28a4053SRui Paulo sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
8725b9c547cSRui Paulo sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
8735b9c547cSRui Paulo
8745b9c547cSRui Paulo hostapd_set_sta_flags(hapd, sta);
875*a90b9d01SCy Schubert if (updated)
876*a90b9d01SCy Schubert ap_sta_set_authorized_event(hapd, sta, 1);
877f05cddf9SRui Paulo
878f05cddf9SRui Paulo if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
879f05cddf9SRui Paulo wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
88085732ac8SCy Schubert #ifdef CONFIG_FILS
88185732ac8SCy Schubert else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
88285732ac8SCy Schubert sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
88385732ac8SCy Schubert sta->auth_alg == WLAN_AUTH_FILS_PK)
88485732ac8SCy Schubert wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
88585732ac8SCy Schubert #endif /* CONFIG_FILS */
886f05cddf9SRui Paulo else
887e28a4053SRui Paulo wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
888e28a4053SRui Paulo
889e28a4053SRui Paulo hostapd_new_assoc_sta(hapd, sta, !new_assoc);
890e28a4053SRui Paulo
891e28a4053SRui Paulo ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
892e28a4053SRui Paulo
893f05cddf9SRui Paulo #ifdef CONFIG_P2P
894f05cddf9SRui Paulo if (req_ies) {
895f05cddf9SRui Paulo p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
896f05cddf9SRui Paulo req_ies, req_ies_len);
897f05cddf9SRui Paulo }
898f05cddf9SRui Paulo #endif /* CONFIG_P2P */
899f05cddf9SRui Paulo
900e28a4053SRui Paulo return 0;
901f05cddf9SRui Paulo
902f05cddf9SRui Paulo fail:
90385732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
904c1d255d3SCy Schubert if (status >= 0)
905f05cddf9SRui Paulo hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
90685732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
907f05cddf9SRui Paulo hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
908f05cddf9SRui Paulo ap_free_sta(hapd, sta);
909f05cddf9SRui Paulo return -1;
910e28a4053SRui Paulo }
911e28a4053SRui Paulo
912e28a4053SRui Paulo
hostapd_remove_sta(struct hostapd_data * hapd,struct sta_info * sta)913*a90b9d01SCy Schubert static void hostapd_remove_sta(struct hostapd_data *hapd, struct sta_info *sta)
914*a90b9d01SCy Schubert {
915*a90b9d01SCy Schubert ap_sta_set_authorized(hapd, sta, 0);
916*a90b9d01SCy Schubert sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
917*a90b9d01SCy Schubert hostapd_set_sta_flags(hapd, sta);
918*a90b9d01SCy Schubert wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
919*a90b9d01SCy Schubert sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
920*a90b9d01SCy Schubert ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
921*a90b9d01SCy Schubert ap_free_sta(hapd, sta);
922*a90b9d01SCy Schubert }
923*a90b9d01SCy Schubert
924*a90b9d01SCy Schubert
925*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
hostapd_notif_disassoc_mld(struct hostapd_data * assoc_hapd,struct sta_info * sta,const u8 * addr)926*a90b9d01SCy Schubert static void hostapd_notif_disassoc_mld(struct hostapd_data *assoc_hapd,
927*a90b9d01SCy Schubert struct sta_info *sta,
928*a90b9d01SCy Schubert const u8 *addr)
929*a90b9d01SCy Schubert {
930*a90b9d01SCy Schubert unsigned int link_id, i;
931*a90b9d01SCy Schubert struct hostapd_data *tmp_hapd;
932*a90b9d01SCy Schubert struct hapd_interfaces *interfaces = assoc_hapd->iface->interfaces;
933*a90b9d01SCy Schubert
934*a90b9d01SCy Schubert /* Remove STA entry in non-assoc links */
935*a90b9d01SCy Schubert for (link_id = 0; link_id < MAX_NUM_MLD_LINKS; link_id++) {
936*a90b9d01SCy Schubert if (!sta->mld_info.links[link_id].valid)
937*a90b9d01SCy Schubert continue;
938*a90b9d01SCy Schubert
939*a90b9d01SCy Schubert for (i = 0; i < interfaces->count; i++) {
940*a90b9d01SCy Schubert struct sta_info *tmp_sta;
941*a90b9d01SCy Schubert
942*a90b9d01SCy Schubert tmp_hapd = interfaces->iface[i]->bss[0];
943*a90b9d01SCy Schubert
944*a90b9d01SCy Schubert if (!tmp_hapd->conf->mld_ap ||
945*a90b9d01SCy Schubert assoc_hapd == tmp_hapd ||
946*a90b9d01SCy Schubert assoc_hapd->conf->mld_id != tmp_hapd->conf->mld_id)
947*a90b9d01SCy Schubert continue;
948*a90b9d01SCy Schubert
949*a90b9d01SCy Schubert tmp_sta = ap_get_sta(tmp_hapd, addr);
950*a90b9d01SCy Schubert if (tmp_sta)
951*a90b9d01SCy Schubert ap_free_sta(tmp_hapd, tmp_sta);
952*a90b9d01SCy Schubert }
953*a90b9d01SCy Schubert }
954*a90b9d01SCy Schubert
955*a90b9d01SCy Schubert /* Remove STA in assoc link */
956*a90b9d01SCy Schubert hostapd_remove_sta(assoc_hapd, sta);
957*a90b9d01SCy Schubert }
958*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
959*a90b9d01SCy Schubert
960*a90b9d01SCy Schubert
hostapd_notif_disassoc(struct hostapd_data * hapd,const u8 * addr)961e28a4053SRui Paulo void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
962e28a4053SRui Paulo {
963e28a4053SRui Paulo struct sta_info *sta;
964e28a4053SRui Paulo
965f05cddf9SRui Paulo if (addr == NULL) {
966f05cddf9SRui Paulo /*
967f05cddf9SRui Paulo * This could potentially happen with unexpected event from the
968f05cddf9SRui Paulo * driver wrapper. This was seen at least in one case where the
969f05cddf9SRui Paulo * driver ended up reporting a station mode event while hostapd
970f05cddf9SRui Paulo * was running, so better make sure we stop processing such an
971f05cddf9SRui Paulo * event here.
972f05cddf9SRui Paulo */
973325151a3SRui Paulo wpa_printf(MSG_DEBUG,
974325151a3SRui Paulo "hostapd_notif_disassoc: Skip event with no address");
975f05cddf9SRui Paulo return;
976f05cddf9SRui Paulo }
977f05cddf9SRui Paulo
978e28a4053SRui Paulo hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
979e28a4053SRui Paulo HOSTAPD_LEVEL_INFO, "disassociated");
980e28a4053SRui Paulo
981e28a4053SRui Paulo sta = ap_get_sta(hapd, addr);
982*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
983*a90b9d01SCy Schubert if (hostapd_is_mld_ap(hapd)) {
984*a90b9d01SCy Schubert struct hostapd_data *assoc_hapd;
985*a90b9d01SCy Schubert unsigned int i;
986*a90b9d01SCy Schubert
987*a90b9d01SCy Schubert if (!sta) {
988*a90b9d01SCy Schubert /* Find non-MLO cases from any of the affiliated AP
989*a90b9d01SCy Schubert * links. */
990*a90b9d01SCy Schubert for (i = 0; i < hapd->iface->interfaces->count; ++i) {
991*a90b9d01SCy Schubert struct hostapd_iface *h =
992*a90b9d01SCy Schubert hapd->iface->interfaces->iface[i];
993*a90b9d01SCy Schubert struct hostapd_data *h_hapd = h->bss[0];
994*a90b9d01SCy Schubert struct hostapd_bss_config *hconf = h_hapd->conf;
995*a90b9d01SCy Schubert
996*a90b9d01SCy Schubert if (!hconf->mld_ap ||
997*a90b9d01SCy Schubert hconf->mld_id != hapd->conf->mld_id)
998*a90b9d01SCy Schubert continue;
999*a90b9d01SCy Schubert
1000*a90b9d01SCy Schubert sta = ap_get_sta(h_hapd, addr);
1001*a90b9d01SCy Schubert if (sta) {
1002*a90b9d01SCy Schubert if (!sta->mld_info.mld_sta) {
1003*a90b9d01SCy Schubert hapd = h_hapd;
1004*a90b9d01SCy Schubert goto legacy;
1005*a90b9d01SCy Schubert }
1006*a90b9d01SCy Schubert break;
1007*a90b9d01SCy Schubert }
1008*a90b9d01SCy Schubert }
1009*a90b9d01SCy Schubert } else if (!sta->mld_info.mld_sta) {
1010*a90b9d01SCy Schubert goto legacy;
1011*a90b9d01SCy Schubert }
1012*a90b9d01SCy Schubert if (!sta) {
1013*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
1014*a90b9d01SCy Schubert "Disassociation notification for unknown STA "
1015*a90b9d01SCy Schubert MACSTR, MAC2STR(addr));
1016*a90b9d01SCy Schubert return;
1017*a90b9d01SCy Schubert }
1018*a90b9d01SCy Schubert sta = hostapd_ml_get_assoc_sta(hapd, sta, &assoc_hapd);
1019*a90b9d01SCy Schubert if (sta)
1020*a90b9d01SCy Schubert hostapd_notif_disassoc_mld(assoc_hapd, sta, addr);
1021*a90b9d01SCy Schubert return;
1022*a90b9d01SCy Schubert }
1023*a90b9d01SCy Schubert
1024*a90b9d01SCy Schubert legacy:
1025*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1026e28a4053SRui Paulo if (sta == NULL) {
1027325151a3SRui Paulo wpa_printf(MSG_DEBUG,
1028325151a3SRui Paulo "Disassociation notification for unknown STA "
1029325151a3SRui Paulo MACSTR, MAC2STR(addr));
1030e28a4053SRui Paulo return;
1031e28a4053SRui Paulo }
1032e28a4053SRui Paulo
1033*a90b9d01SCy Schubert hostapd_remove_sta(hapd, sta);
1034e28a4053SRui Paulo }
1035e28a4053SRui Paulo
1036e28a4053SRui Paulo
hostapd_event_sta_low_ack(struct hostapd_data * hapd,const u8 * addr)1037f05cddf9SRui Paulo void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
1038f05cddf9SRui Paulo {
1039f05cddf9SRui Paulo struct sta_info *sta = ap_get_sta(hapd, addr);
1040f05cddf9SRui Paulo
104185732ac8SCy Schubert if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer)
1042f05cddf9SRui Paulo return;
1043f05cddf9SRui Paulo
1044f05cddf9SRui Paulo hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
1045325151a3SRui Paulo HOSTAPD_LEVEL_INFO,
1046325151a3SRui Paulo "disconnected due to excessive missing ACKs");
1047f05cddf9SRui Paulo hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
1048f05cddf9SRui Paulo ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
1049f05cddf9SRui Paulo }
1050f05cddf9SRui Paulo
1051f05cddf9SRui Paulo
hostapd_event_sta_opmode_changed(struct hostapd_data * hapd,const u8 * addr,enum smps_mode smps_mode,enum chan_width chan_width,u8 rx_nss)105285732ac8SCy Schubert void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr,
105385732ac8SCy Schubert enum smps_mode smps_mode,
105485732ac8SCy Schubert enum chan_width chan_width, u8 rx_nss)
105585732ac8SCy Schubert {
105685732ac8SCy Schubert struct sta_info *sta = ap_get_sta(hapd, addr);
105785732ac8SCy Schubert const char *txt;
105885732ac8SCy Schubert
105985732ac8SCy Schubert if (!sta)
106085732ac8SCy Schubert return;
106185732ac8SCy Schubert
106285732ac8SCy Schubert switch (smps_mode) {
106385732ac8SCy Schubert case SMPS_AUTOMATIC:
106485732ac8SCy Schubert txt = "automatic";
106585732ac8SCy Schubert break;
106685732ac8SCy Schubert case SMPS_OFF:
106785732ac8SCy Schubert txt = "off";
106885732ac8SCy Schubert break;
106985732ac8SCy Schubert case SMPS_DYNAMIC:
107085732ac8SCy Schubert txt = "dynamic";
107185732ac8SCy Schubert break;
107285732ac8SCy Schubert case SMPS_STATIC:
107385732ac8SCy Schubert txt = "static";
107485732ac8SCy Schubert break;
107585732ac8SCy Schubert default:
107685732ac8SCy Schubert txt = NULL;
107785732ac8SCy Schubert break;
107885732ac8SCy Schubert }
107985732ac8SCy Schubert if (txt) {
108085732ac8SCy Schubert wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED
108185732ac8SCy Schubert MACSTR " %s", MAC2STR(addr), txt);
108285732ac8SCy Schubert }
108385732ac8SCy Schubert
108485732ac8SCy Schubert switch (chan_width) {
108585732ac8SCy Schubert case CHAN_WIDTH_20_NOHT:
108685732ac8SCy Schubert txt = "20(no-HT)";
108785732ac8SCy Schubert break;
108885732ac8SCy Schubert case CHAN_WIDTH_20:
108985732ac8SCy Schubert txt = "20";
109085732ac8SCy Schubert break;
109185732ac8SCy Schubert case CHAN_WIDTH_40:
109285732ac8SCy Schubert txt = "40";
109385732ac8SCy Schubert break;
109485732ac8SCy Schubert case CHAN_WIDTH_80:
109585732ac8SCy Schubert txt = "80";
109685732ac8SCy Schubert break;
109785732ac8SCy Schubert case CHAN_WIDTH_80P80:
109885732ac8SCy Schubert txt = "80+80";
109985732ac8SCy Schubert break;
110085732ac8SCy Schubert case CHAN_WIDTH_160:
110185732ac8SCy Schubert txt = "160";
110285732ac8SCy Schubert break;
1103*a90b9d01SCy Schubert case CHAN_WIDTH_320:
1104*a90b9d01SCy Schubert txt = "320";
1105*a90b9d01SCy Schubert break;
110685732ac8SCy Schubert default:
110785732ac8SCy Schubert txt = NULL;
110885732ac8SCy Schubert break;
110985732ac8SCy Schubert }
111085732ac8SCy Schubert if (txt) {
111185732ac8SCy Schubert wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED
111285732ac8SCy Schubert MACSTR " %s", MAC2STR(addr), txt);
111385732ac8SCy Schubert }
111485732ac8SCy Schubert
111585732ac8SCy Schubert if (rx_nss != 0xff) {
111685732ac8SCy Schubert wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED
111785732ac8SCy Schubert MACSTR " %d", MAC2STR(addr), rx_nss);
111885732ac8SCy Schubert }
111985732ac8SCy Schubert }
112085732ac8SCy Schubert
112185732ac8SCy Schubert
hostapd_event_ch_switch(struct hostapd_data * hapd,int freq,int ht,int offset,int width,int cf1,int cf2,u16 punct_bitmap,int finished)1122f05cddf9SRui Paulo void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
1123206b73d0SCy Schubert int offset, int width, int cf1, int cf2,
1124*a90b9d01SCy Schubert u16 punct_bitmap, int finished)
1125f05cddf9SRui Paulo {
1126f05cddf9SRui Paulo #ifdef NEED_AP_MLME
1127*a90b9d01SCy Schubert int channel, chwidth, is_dfs0, is_dfs;
1128*a90b9d01SCy Schubert u8 seg0_idx = 0, seg1_idx = 0, op_class, chan_no;
11294bc52338SCy Schubert size_t i;
1130f05cddf9SRui Paulo
1131f05cddf9SRui Paulo hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
11325b9c547cSRui Paulo HOSTAPD_LEVEL_INFO,
1133*a90b9d01SCy Schubert "driver %s channel switch: iface->freq=%d, freq=%d, ht=%d, vht_ch=0x%x, he_ch=0x%x, eht_ch=0x%x, offset=%d, width=%d (%s), cf1=%d, cf2=%d, puncturing_bitmap=0x%x",
1134206b73d0SCy Schubert finished ? "had" : "starting",
1135*a90b9d01SCy Schubert hapd->iface->freq,
1136c1d255d3SCy Schubert freq, ht, hapd->iconf->ch_switch_vht_config,
1137*a90b9d01SCy Schubert hapd->iconf->ch_switch_he_config,
1138*a90b9d01SCy Schubert hapd->iconf->ch_switch_eht_config, offset,
1139*a90b9d01SCy Schubert width, channel_width_to_string(width), cf1, cf2,
1140*a90b9d01SCy Schubert punct_bitmap);
1141f05cddf9SRui Paulo
1142206b73d0SCy Schubert if (!hapd->iface->current_mode) {
1143206b73d0SCy Schubert hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1144206b73d0SCy Schubert HOSTAPD_LEVEL_WARNING,
1145206b73d0SCy Schubert "ignore channel switch since the interface is not yet ready");
1146206b73d0SCy Schubert return;
1147206b73d0SCy Schubert }
1148206b73d0SCy Schubert
1149*a90b9d01SCy Schubert /* Check if any of configured channels require DFS */
1150*a90b9d01SCy Schubert is_dfs0 = hostapd_is_dfs_required(hapd->iface);
1151f05cddf9SRui Paulo hapd->iface->freq = freq;
1152f05cddf9SRui Paulo
1153f05cddf9SRui Paulo channel = hostapd_hw_get_channel(hapd, freq);
1154f05cddf9SRui Paulo if (!channel) {
1155f05cddf9SRui Paulo hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1156325151a3SRui Paulo HOSTAPD_LEVEL_WARNING,
1157325151a3SRui Paulo "driver switched to bad channel!");
1158f05cddf9SRui Paulo return;
1159f05cddf9SRui Paulo }
1160f05cddf9SRui Paulo
11615b9c547cSRui Paulo switch (width) {
11625b9c547cSRui Paulo case CHAN_WIDTH_80:
1163*a90b9d01SCy Schubert chwidth = CONF_OPER_CHWIDTH_80MHZ;
11645b9c547cSRui Paulo break;
11655b9c547cSRui Paulo case CHAN_WIDTH_80P80:
1166*a90b9d01SCy Schubert chwidth = CONF_OPER_CHWIDTH_80P80MHZ;
11675b9c547cSRui Paulo break;
11685b9c547cSRui Paulo case CHAN_WIDTH_160:
1169*a90b9d01SCy Schubert chwidth = CONF_OPER_CHWIDTH_160MHZ;
1170*a90b9d01SCy Schubert break;
1171*a90b9d01SCy Schubert case CHAN_WIDTH_320:
1172*a90b9d01SCy Schubert chwidth = CONF_OPER_CHWIDTH_320MHZ;
11735b9c547cSRui Paulo break;
11745b9c547cSRui Paulo case CHAN_WIDTH_20_NOHT:
11755b9c547cSRui Paulo case CHAN_WIDTH_20:
11765b9c547cSRui Paulo case CHAN_WIDTH_40:
11775b9c547cSRui Paulo default:
1178*a90b9d01SCy Schubert chwidth = CONF_OPER_CHWIDTH_USE_HT;
11795b9c547cSRui Paulo break;
11805b9c547cSRui Paulo }
11815b9c547cSRui Paulo
1182*a90b9d01SCy Schubert /* The operating channel changed when CSA finished, so need to update
1183*a90b9d01SCy Schubert * hw_mode for all following operations to cover the cases where the
1184*a90b9d01SCy Schubert * driver changed the operating band. */
1185*a90b9d01SCy Schubert if (finished && hostapd_csa_update_hwmode(hapd->iface))
1186*a90b9d01SCy Schubert return;
1187*a90b9d01SCy Schubert
11885b9c547cSRui Paulo switch (hapd->iface->current_mode->mode) {
11895b9c547cSRui Paulo case HOSTAPD_MODE_IEEE80211A:
1190c1d255d3SCy Schubert if (cf1 == 5935)
1191c1d255d3SCy Schubert seg0_idx = (cf1 - 5925) / 5;
1192c1d255d3SCy Schubert else if (cf1 > 5950)
1193c1d255d3SCy Schubert seg0_idx = (cf1 - 5950) / 5;
1194c1d255d3SCy Schubert else if (cf1 > 5000)
11955b9c547cSRui Paulo seg0_idx = (cf1 - 5000) / 5;
1196c1d255d3SCy Schubert
1197c1d255d3SCy Schubert if (cf2 == 5935)
1198c1d255d3SCy Schubert seg1_idx = (cf2 - 5925) / 5;
1199c1d255d3SCy Schubert else if (cf2 > 5950)
1200c1d255d3SCy Schubert seg1_idx = (cf2 - 5950) / 5;
1201c1d255d3SCy Schubert else if (cf2 > 5000)
12025b9c547cSRui Paulo seg1_idx = (cf2 - 5000) / 5;
12035b9c547cSRui Paulo break;
12045b9c547cSRui Paulo default:
1205780fb4a2SCy Schubert ieee80211_freq_to_chan(cf1, &seg0_idx);
1206780fb4a2SCy Schubert ieee80211_freq_to_chan(cf2, &seg1_idx);
12075b9c547cSRui Paulo break;
12085b9c547cSRui Paulo }
12095b9c547cSRui Paulo
1210f05cddf9SRui Paulo hapd->iconf->channel = channel;
1211f05cddf9SRui Paulo hapd->iconf->ieee80211n = ht;
1212*a90b9d01SCy Schubert if (!ht)
12135b9c547cSRui Paulo hapd->iconf->ieee80211ac = 0;
1214*a90b9d01SCy Schubert if (hapd->iconf->ch_switch_vht_config) {
121585732ac8SCy Schubert /* CHAN_SWITCH VHT config */
121685732ac8SCy Schubert if (hapd->iconf->ch_switch_vht_config &
121785732ac8SCy Schubert CH_SWITCH_VHT_ENABLED)
121885732ac8SCy Schubert hapd->iconf->ieee80211ac = 1;
121985732ac8SCy Schubert else if (hapd->iconf->ch_switch_vht_config &
122085732ac8SCy Schubert CH_SWITCH_VHT_DISABLED)
122185732ac8SCy Schubert hapd->iconf->ieee80211ac = 0;
1222*a90b9d01SCy Schubert }
1223*a90b9d01SCy Schubert if (hapd->iconf->ch_switch_he_config) {
1224c1d255d3SCy Schubert /* CHAN_SWITCH HE config */
1225c1d255d3SCy Schubert if (hapd->iconf->ch_switch_he_config &
1226*a90b9d01SCy Schubert CH_SWITCH_HE_ENABLED) {
1227c1d255d3SCy Schubert hapd->iconf->ieee80211ax = 1;
1228*a90b9d01SCy Schubert if (hapd->iface->freq > 4000 &&
1229*a90b9d01SCy Schubert hapd->iface->freq < 5895)
1230*a90b9d01SCy Schubert hapd->iconf->ieee80211ac = 1;
1231*a90b9d01SCy Schubert }
1232c1d255d3SCy Schubert else if (hapd->iconf->ch_switch_he_config &
1233c1d255d3SCy Schubert CH_SWITCH_HE_DISABLED)
1234c1d255d3SCy Schubert hapd->iconf->ieee80211ax = 0;
123585732ac8SCy Schubert }
1236*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1237*a90b9d01SCy Schubert if (hapd->iconf->ch_switch_eht_config) {
1238*a90b9d01SCy Schubert /* CHAN_SWITCH EHT config */
1239*a90b9d01SCy Schubert if (hapd->iconf->ch_switch_eht_config &
1240*a90b9d01SCy Schubert CH_SWITCH_EHT_ENABLED) {
1241*a90b9d01SCy Schubert hapd->iconf->ieee80211be = 1;
1242*a90b9d01SCy Schubert hapd->iconf->ieee80211ax = 1;
1243*a90b9d01SCy Schubert if (!is_6ghz_freq(hapd->iface->freq) &&
1244*a90b9d01SCy Schubert hapd->iface->freq > 4000)
1245*a90b9d01SCy Schubert hapd->iconf->ieee80211ac = 1;
1246*a90b9d01SCy Schubert } else if (hapd->iconf->ch_switch_eht_config &
1247*a90b9d01SCy Schubert CH_SWITCH_EHT_DISABLED)
1248*a90b9d01SCy Schubert hapd->iconf->ieee80211be = 0;
1249*a90b9d01SCy Schubert }
1250*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
125185732ac8SCy Schubert hapd->iconf->ch_switch_vht_config = 0;
1252c1d255d3SCy Schubert hapd->iconf->ch_switch_he_config = 0;
1253*a90b9d01SCy Schubert hapd->iconf->ch_switch_eht_config = 0;
125485732ac8SCy Schubert
125532a95656SCy Schubert if (width == CHAN_WIDTH_40 || width == CHAN_WIDTH_80 ||
1256*a90b9d01SCy Schubert width == CHAN_WIDTH_80P80 || width == CHAN_WIDTH_160 ||
1257*a90b9d01SCy Schubert width == CHAN_WIDTH_320)
125832a95656SCy Schubert hapd->iconf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
125932a95656SCy Schubert else if (width == CHAN_WIDTH_20 || width == CHAN_WIDTH_20_NOHT)
126032a95656SCy Schubert hapd->iconf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
126132a95656SCy Schubert
1262f05cddf9SRui Paulo hapd->iconf->secondary_channel = offset;
1263*a90b9d01SCy Schubert if (ieee80211_freq_to_channel_ext(freq, offset, chwidth,
1264*a90b9d01SCy Schubert &op_class, &chan_no) !=
1265*a90b9d01SCy Schubert NUM_HOSTAPD_MODES)
1266*a90b9d01SCy Schubert hapd->iconf->op_class = op_class;
1267206b73d0SCy Schubert hostapd_set_oper_chwidth(hapd->iconf, chwidth);
1268206b73d0SCy Schubert hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, seg0_idx);
1269206b73d0SCy Schubert hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, seg1_idx);
1270*a90b9d01SCy Schubert /* Auto-detect new bw320_offset */
1271*a90b9d01SCy Schubert hostapd_set_and_check_bw320_offset(hapd->iconf, 0);
1272*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1273*a90b9d01SCy Schubert hapd->iconf->punct_bitmap = punct_bitmap;
1274*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1275c1d255d3SCy Schubert if (hapd->iconf->ieee80211ac) {
1276c1d255d3SCy Schubert hapd->iconf->vht_capab &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
1277*a90b9d01SCy Schubert if (chwidth == CONF_OPER_CHWIDTH_160MHZ)
1278c1d255d3SCy Schubert hapd->iconf->vht_capab |=
1279c1d255d3SCy Schubert VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
1280*a90b9d01SCy Schubert else if (chwidth == CONF_OPER_CHWIDTH_80P80MHZ)
1281c1d255d3SCy Schubert hapd->iconf->vht_capab |=
1282c1d255d3SCy Schubert VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1283c1d255d3SCy Schubert }
12845b9c547cSRui Paulo
128585732ac8SCy Schubert is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features,
128685732ac8SCy Schubert hapd->iface->num_hw_features);
12875b9c547cSRui Paulo
1288206b73d0SCy Schubert wpa_msg(hapd->msg_ctx, MSG_INFO,
1289*a90b9d01SCy Schubert "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d is_dfs0=%d dfs=%d puncturing_bitmap=0x%04x",
1290206b73d0SCy Schubert finished ? WPA_EVENT_CHANNEL_SWITCH :
1291206b73d0SCy Schubert WPA_EVENT_CHANNEL_SWITCH_STARTED,
1292206b73d0SCy Schubert freq, ht, offset, channel_width_to_string(width),
1293*a90b9d01SCy Schubert cf1, cf2, is_dfs0, is_dfs, punct_bitmap);
1294206b73d0SCy Schubert if (!finished)
1295206b73d0SCy Schubert return;
1296206b73d0SCy Schubert
12975b9c547cSRui Paulo if (hapd->csa_in_progress &&
12985b9c547cSRui Paulo freq == hapd->cs_freq_params.freq) {
12995b9c547cSRui Paulo hostapd_cleanup_cs_params(hapd);
13005b9c547cSRui Paulo ieee802_11_set_beacon(hapd);
13015b9c547cSRui Paulo
13025b9c547cSRui Paulo wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
13035b9c547cSRui Paulo "freq=%d dfs=%d", freq, is_dfs);
13045b9c547cSRui Paulo } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
1305*a90b9d01SCy Schubert /* Complete AP configuration for the first bring up. */
1306*a90b9d01SCy Schubert if (is_dfs0 > 0 &&
1307*a90b9d01SCy Schubert hostapd_is_dfs_required(hapd->iface) <= 0 &&
1308*a90b9d01SCy Schubert hapd->iface->state != HAPD_IFACE_ENABLED) {
1309*a90b9d01SCy Schubert /* Fake a CAC start bit to skip setting channel */
1310*a90b9d01SCy Schubert hapd->iface->cac_started = 1;
1311*a90b9d01SCy Schubert hostapd_setup_interface_complete(hapd->iface, 0);
1312*a90b9d01SCy Schubert }
13135b9c547cSRui Paulo wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
13145b9c547cSRui Paulo "freq=%d dfs=%d", freq, is_dfs);
1315c1d255d3SCy Schubert } else if (is_dfs &&
1316c1d255d3SCy Schubert hostapd_is_dfs_required(hapd->iface) &&
1317c1d255d3SCy Schubert !hostapd_is_dfs_chan_available(hapd->iface) &&
1318c1d255d3SCy Schubert !hapd->iface->cac_started) {
1319c1d255d3SCy Schubert hostapd_disable_iface(hapd->iface);
1320c1d255d3SCy Schubert hostapd_enable_iface(hapd->iface);
13215b9c547cSRui Paulo }
13224bc52338SCy Schubert
13234bc52338SCy Schubert for (i = 0; i < hapd->iface->num_bss; i++)
13244bc52338SCy Schubert hostapd_neighbor_set_own_report(hapd->iface->bss[i]);
1325c1d255d3SCy Schubert
1326c1d255d3SCy Schubert #ifdef CONFIG_OCV
1327*a90b9d01SCy Schubert if (hapd->conf->ocv &&
1328*a90b9d01SCy Schubert !(hapd->iface->drv_flags2 &
1329*a90b9d01SCy Schubert WPA_DRIVER_FLAGS2_SA_QUERY_OFFLOAD_AP)) {
1330c1d255d3SCy Schubert struct sta_info *sta;
1331c1d255d3SCy Schubert bool check_sa_query = false;
1332c1d255d3SCy Schubert
1333c1d255d3SCy Schubert for (sta = hapd->sta_list; sta; sta = sta->next) {
1334c1d255d3SCy Schubert if (wpa_auth_uses_ocv(sta->wpa_sm) &&
1335c1d255d3SCy Schubert !(sta->flags & WLAN_STA_WNM_SLEEP_MODE)) {
1336c1d255d3SCy Schubert sta->post_csa_sa_query = 1;
1337c1d255d3SCy Schubert check_sa_query = true;
1338c1d255d3SCy Schubert }
1339c1d255d3SCy Schubert }
1340c1d255d3SCy Schubert
1341c1d255d3SCy Schubert if (check_sa_query) {
1342c1d255d3SCy Schubert wpa_printf(MSG_DEBUG,
1343c1d255d3SCy Schubert "OCV: Check post-CSA SA Query initiation in 15 seconds");
1344c1d255d3SCy Schubert eloop_register_timeout(15, 0,
1345c1d255d3SCy Schubert hostapd_ocv_check_csa_sa_query,
1346c1d255d3SCy Schubert hapd, NULL);
1347c1d255d3SCy Schubert }
1348c1d255d3SCy Schubert }
1349c1d255d3SCy Schubert #endif /* CONFIG_OCV */
1350f05cddf9SRui Paulo #endif /* NEED_AP_MLME */
1351f05cddf9SRui Paulo }
1352f05cddf9SRui Paulo
1353f05cddf9SRui Paulo
hostapd_event_connect_failed_reason(struct hostapd_data * hapd,const u8 * addr,int reason_code)13545b9c547cSRui Paulo void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
13555b9c547cSRui Paulo const u8 *addr, int reason_code)
13565b9c547cSRui Paulo {
13575b9c547cSRui Paulo switch (reason_code) {
13585b9c547cSRui Paulo case MAX_CLIENT_REACHED:
13595b9c547cSRui Paulo wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
13605b9c547cSRui Paulo MAC2STR(addr));
13615b9c547cSRui Paulo break;
13625b9c547cSRui Paulo case BLOCKED_CLIENT:
13635b9c547cSRui Paulo wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
13645b9c547cSRui Paulo MAC2STR(addr));
13655b9c547cSRui Paulo break;
13665b9c547cSRui Paulo }
13675b9c547cSRui Paulo }
13685b9c547cSRui Paulo
13695b9c547cSRui Paulo
13705b9c547cSRui Paulo #ifdef CONFIG_ACS
hostapd_acs_channel_selected(struct hostapd_data * hapd,struct acs_selected_channels * acs_res)1371780fb4a2SCy Schubert void hostapd_acs_channel_selected(struct hostapd_data *hapd,
1372325151a3SRui Paulo struct acs_selected_channels *acs_res)
13735b9c547cSRui Paulo {
1374325151a3SRui Paulo int ret, i;
1375780fb4a2SCy Schubert int err = 0;
1376c1d255d3SCy Schubert struct hostapd_channel_data *pri_chan;
13775b9c547cSRui Paulo
1378*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1379*a90b9d01SCy Schubert if (acs_res->link_id != -1) {
1380*a90b9d01SCy Schubert hapd = hostapd_mld_get_link_bss(hapd, acs_res->link_id);
1381*a90b9d01SCy Schubert if (!hapd) {
1382*a90b9d01SCy Schubert wpa_printf(MSG_ERROR,
1383*a90b9d01SCy Schubert "MLD: Failed to get link BSS for EVENT_ACS_CHANNEL_SELECTED link_id=%d",
1384*a90b9d01SCy Schubert acs_res->link_id);
1385*a90b9d01SCy Schubert return;
1386*a90b9d01SCy Schubert }
1387*a90b9d01SCy Schubert }
1388*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1389*a90b9d01SCy Schubert
13905b9c547cSRui Paulo if (hapd->iconf->channel) {
13915b9c547cSRui Paulo wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
13925b9c547cSRui Paulo hapd->iconf->channel);
13935b9c547cSRui Paulo return;
13945b9c547cSRui Paulo }
13955b9c547cSRui Paulo
1396c1d255d3SCy Schubert hapd->iface->freq = acs_res->pri_freq;
1397c1d255d3SCy Schubert
1398325151a3SRui Paulo if (!hapd->iface->current_mode) {
1399325151a3SRui Paulo for (i = 0; i < hapd->iface->num_hw_features; i++) {
1400325151a3SRui Paulo struct hostapd_hw_modes *mode =
1401325151a3SRui Paulo &hapd->iface->hw_features[i];
14025b9c547cSRui Paulo
1403325151a3SRui Paulo if (mode->mode == acs_res->hw_mode) {
1404c1d255d3SCy Schubert if (hapd->iface->freq > 0 &&
1405c1d255d3SCy Schubert !hw_get_chan(mode->mode,
1406c1d255d3SCy Schubert hapd->iface->freq,
1407c1d255d3SCy Schubert hapd->iface->hw_features,
1408c1d255d3SCy Schubert hapd->iface->num_hw_features))
1409c1d255d3SCy Schubert continue;
1410325151a3SRui Paulo hapd->iface->current_mode = mode;
1411325151a3SRui Paulo break;
1412325151a3SRui Paulo }
1413325151a3SRui Paulo }
1414325151a3SRui Paulo if (!hapd->iface->current_mode) {
1415325151a3SRui Paulo hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1416325151a3SRui Paulo HOSTAPD_LEVEL_WARNING,
1417325151a3SRui Paulo "driver selected to bad hw_mode");
1418780fb4a2SCy Schubert err = 1;
1419780fb4a2SCy Schubert goto out;
1420325151a3SRui Paulo }
1421325151a3SRui Paulo }
1422325151a3SRui Paulo
1423c1d255d3SCy Schubert if (!acs_res->pri_freq) {
14245b9c547cSRui Paulo hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
14255b9c547cSRui Paulo HOSTAPD_LEVEL_WARNING,
14265b9c547cSRui Paulo "driver switched to bad channel");
1427780fb4a2SCy Schubert err = 1;
1428780fb4a2SCy Schubert goto out;
14295b9c547cSRui Paulo }
1430c1d255d3SCy Schubert pri_chan = hw_get_channel_freq(hapd->iface->current_mode->mode,
1431c1d255d3SCy Schubert acs_res->pri_freq, NULL,
1432c1d255d3SCy Schubert hapd->iface->hw_features,
1433c1d255d3SCy Schubert hapd->iface->num_hw_features);
1434c1d255d3SCy Schubert if (!pri_chan) {
1435c1d255d3SCy Schubert wpa_printf(MSG_ERROR,
1436c1d255d3SCy Schubert "ACS: Could not determine primary channel number from pri_freq %u",
1437c1d255d3SCy Schubert acs_res->pri_freq);
1438c1d255d3SCy Schubert err = 1;
1439c1d255d3SCy Schubert goto out;
1440c1d255d3SCy Schubert }
14415b9c547cSRui Paulo
1442c1d255d3SCy Schubert hapd->iconf->channel = pri_chan->chan;
1443325151a3SRui Paulo hapd->iconf->acs = 1;
14445b9c547cSRui Paulo
1445c1d255d3SCy Schubert if (acs_res->sec_freq == 0)
14465b9c547cSRui Paulo hapd->iconf->secondary_channel = 0;
1447c1d255d3SCy Schubert else if (acs_res->sec_freq < acs_res->pri_freq)
14485b9c547cSRui Paulo hapd->iconf->secondary_channel = -1;
1449c1d255d3SCy Schubert else if (acs_res->sec_freq > acs_res->pri_freq)
14505b9c547cSRui Paulo hapd->iconf->secondary_channel = 1;
14515b9c547cSRui Paulo else {
14525b9c547cSRui Paulo wpa_printf(MSG_ERROR, "Invalid secondary channel!");
1453780fb4a2SCy Schubert err = 1;
1454780fb4a2SCy Schubert goto out;
14555b9c547cSRui Paulo }
14565b9c547cSRui Paulo
1457c1d255d3SCy Schubert hapd->iconf->edmg_channel = acs_res->edmg_channel;
1458c1d255d3SCy Schubert
1459206b73d0SCy Schubert if (hapd->iface->conf->ieee80211ac || hapd->iface->conf->ieee80211ax) {
1460325151a3SRui Paulo /* set defaults for backwards compatibility */
1461206b73d0SCy Schubert hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1462206b73d0SCy Schubert hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, 0);
1463*a90b9d01SCy Schubert hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_USE_HT);
1464c1d255d3SCy Schubert if (acs_res->ch_width == 40) {
1465c1d255d3SCy Schubert if (is_6ghz_freq(acs_res->pri_freq))
1466c1d255d3SCy Schubert hostapd_set_oper_centr_freq_seg0_idx(
1467c1d255d3SCy Schubert hapd->iconf,
1468c1d255d3SCy Schubert acs_res->vht_seg0_center_ch);
1469c1d255d3SCy Schubert } else if (acs_res->ch_width == 80) {
1470206b73d0SCy Schubert hostapd_set_oper_centr_freq_seg0_idx(
1471206b73d0SCy Schubert hapd->iconf, acs_res->vht_seg0_center_ch);
1472325151a3SRui Paulo if (acs_res->vht_seg1_center_ch == 0) {
1473*a90b9d01SCy Schubert hostapd_set_oper_chwidth(
1474*a90b9d01SCy Schubert hapd->iconf, CONF_OPER_CHWIDTH_80MHZ);
1475325151a3SRui Paulo } else {
1476*a90b9d01SCy Schubert hostapd_set_oper_chwidth(
1477*a90b9d01SCy Schubert hapd->iconf,
1478*a90b9d01SCy Schubert CONF_OPER_CHWIDTH_80P80MHZ);
1479206b73d0SCy Schubert hostapd_set_oper_centr_freq_seg1_idx(
1480206b73d0SCy Schubert hapd->iconf,
1481206b73d0SCy Schubert acs_res->vht_seg1_center_ch);
1482325151a3SRui Paulo }
1483c1d255d3SCy Schubert } else if (acs_res->ch_width == 160) {
1484*a90b9d01SCy Schubert hostapd_set_oper_chwidth(hapd->iconf,
1485*a90b9d01SCy Schubert CONF_OPER_CHWIDTH_160MHZ);
1486c1d255d3SCy Schubert hostapd_set_oper_centr_freq_seg0_idx(
1487c1d255d3SCy Schubert hapd->iconf, acs_res->vht_seg1_center_ch);
1488325151a3SRui Paulo }
1489325151a3SRui Paulo }
1490325151a3SRui Paulo
1491*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1492*a90b9d01SCy Schubert if (hapd->iface->conf->ieee80211be && acs_res->ch_width == 320) {
1493*a90b9d01SCy Schubert hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_320MHZ);
1494*a90b9d01SCy Schubert hostapd_set_oper_centr_freq_seg0_idx(
1495*a90b9d01SCy Schubert hapd->iconf, acs_res->vht_seg1_center_ch);
1496*a90b9d01SCy Schubert hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1497*a90b9d01SCy Schubert }
1498*a90b9d01SCy Schubert
1499*a90b9d01SCy Schubert if (hapd->iface->conf->ieee80211be && acs_res->puncture_bitmap)
1500*a90b9d01SCy Schubert hapd->iconf->punct_bitmap = acs_res->puncture_bitmap;
1501*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1502*a90b9d01SCy Schubert
1503780fb4a2SCy Schubert out:
1504780fb4a2SCy Schubert ret = hostapd_acs_completed(hapd->iface, err);
15055b9c547cSRui Paulo if (ret) {
15065b9c547cSRui Paulo wpa_printf(MSG_ERROR,
15075b9c547cSRui Paulo "ACS: Possibly channel configuration is invalid");
15085b9c547cSRui Paulo }
15095b9c547cSRui Paulo }
15105b9c547cSRui Paulo #endif /* CONFIG_ACS */
15115b9c547cSRui Paulo
15125b9c547cSRui Paulo
hostapd_probe_req_rx(struct hostapd_data * hapd,const u8 * sa,const u8 * da,const u8 * bssid,const u8 * ie,size_t ie_len,int ssi_signal)1513f05cddf9SRui Paulo int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
1514f05cddf9SRui Paulo const u8 *bssid, const u8 *ie, size_t ie_len,
1515f05cddf9SRui Paulo int ssi_signal)
1516f05cddf9SRui Paulo {
1517f05cddf9SRui Paulo size_t i;
1518f05cddf9SRui Paulo int ret = 0;
1519f05cddf9SRui Paulo
1520f05cddf9SRui Paulo if (sa == NULL || ie == NULL)
1521f05cddf9SRui Paulo return -1;
1522f05cddf9SRui Paulo
1523f05cddf9SRui Paulo random_add_randomness(sa, ETH_ALEN);
1524f05cddf9SRui Paulo for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
1525f05cddf9SRui Paulo if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
1526f05cddf9SRui Paulo sa, da, bssid, ie, ie_len,
1527f05cddf9SRui Paulo ssi_signal) > 0) {
1528f05cddf9SRui Paulo ret = 1;
1529f05cddf9SRui Paulo break;
1530f05cddf9SRui Paulo }
1531f05cddf9SRui Paulo }
1532f05cddf9SRui Paulo return ret;
1533f05cddf9SRui Paulo }
1534f05cddf9SRui Paulo
1535f05cddf9SRui Paulo
1536e28a4053SRui Paulo #ifdef HOSTAPD
1537e28a4053SRui Paulo
153885732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
hostapd_notify_auth_ft_finish(void * ctx,const u8 * dst,u16 auth_transaction,u16 status,const u8 * ies,size_t ies_len)1539f05cddf9SRui Paulo static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
1540f05cddf9SRui Paulo u16 auth_transaction, u16 status,
1541f05cddf9SRui Paulo const u8 *ies, size_t ies_len)
1542e28a4053SRui Paulo {
1543f05cddf9SRui Paulo struct hostapd_data *hapd = ctx;
1544f05cddf9SRui Paulo struct sta_info *sta;
1545e28a4053SRui Paulo
1546f05cddf9SRui Paulo sta = ap_get_sta(hapd, dst);
1547f05cddf9SRui Paulo if (sta == NULL)
1548f05cddf9SRui Paulo return;
1549e28a4053SRui Paulo
1550f05cddf9SRui Paulo hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
1551f05cddf9SRui Paulo HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
1552f05cddf9SRui Paulo sta->flags |= WLAN_STA_AUTH;
1553e28a4053SRui Paulo
1554f05cddf9SRui Paulo hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
1555e28a4053SRui Paulo }
155685732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
155785732ac8SCy Schubert
155885732ac8SCy Schubert
155985732ac8SCy Schubert #ifdef CONFIG_FILS
hostapd_notify_auth_fils_finish(struct hostapd_data * hapd,struct sta_info * sta,u16 resp,struct wpabuf * data,int pub)156085732ac8SCy Schubert static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
156185732ac8SCy Schubert struct sta_info *sta, u16 resp,
156285732ac8SCy Schubert struct wpabuf *data, int pub)
156385732ac8SCy Schubert {
156485732ac8SCy Schubert if (resp == WLAN_STATUS_SUCCESS) {
156585732ac8SCy Schubert hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
156685732ac8SCy Schubert HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
156785732ac8SCy Schubert sta->flags |= WLAN_STA_AUTH;
156885732ac8SCy Schubert wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
156985732ac8SCy Schubert sta->auth_alg = WLAN_AUTH_FILS_SK;
157085732ac8SCy Schubert mlme_authenticate_indication(hapd, sta);
157185732ac8SCy Schubert } else {
157285732ac8SCy Schubert hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
157385732ac8SCy Schubert HOSTAPD_LEVEL_DEBUG,
157485732ac8SCy Schubert "authentication failed (FILS)");
157585732ac8SCy Schubert }
157685732ac8SCy Schubert
157785732ac8SCy Schubert hostapd_sta_auth(hapd, sta->addr, 2, resp,
157885732ac8SCy Schubert data ? wpabuf_head(data) : NULL,
157985732ac8SCy Schubert data ? wpabuf_len(data) : 0);
158085732ac8SCy Schubert wpabuf_free(data);
158185732ac8SCy Schubert }
158285732ac8SCy Schubert #endif /* CONFIG_FILS */
1583f05cddf9SRui Paulo
1584f05cddf9SRui Paulo
hostapd_notif_auth(struct hostapd_data * hapd,struct auth_info * rx_auth)1585f05cddf9SRui Paulo static void hostapd_notif_auth(struct hostapd_data *hapd,
1586f05cddf9SRui Paulo struct auth_info *rx_auth)
1587f05cddf9SRui Paulo {
1588f05cddf9SRui Paulo struct sta_info *sta;
1589f05cddf9SRui Paulo u16 status = WLAN_STATUS_SUCCESS;
1590f05cddf9SRui Paulo u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1591f05cddf9SRui Paulo size_t resp_ies_len = 0;
1592f05cddf9SRui Paulo
1593f05cddf9SRui Paulo sta = ap_get_sta(hapd, rx_auth->peer);
1594f05cddf9SRui Paulo if (!sta) {
1595f05cddf9SRui Paulo sta = ap_sta_add(hapd, rx_auth->peer);
1596f05cddf9SRui Paulo if (sta == NULL) {
15975b9c547cSRui Paulo status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1598f05cddf9SRui Paulo goto fail;
1599e28a4053SRui Paulo }
1600e28a4053SRui Paulo }
1601f05cddf9SRui Paulo sta->flags &= ~WLAN_STA_PREAUTH;
1602f05cddf9SRui Paulo ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
160385732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
1604f05cddf9SRui Paulo if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
1605f05cddf9SRui Paulo sta->auth_alg = WLAN_AUTH_FT;
1606f05cddf9SRui Paulo if (sta->wpa_sm == NULL)
1607f05cddf9SRui Paulo sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
16085b9c547cSRui Paulo sta->addr, NULL);
1609f05cddf9SRui Paulo if (sta->wpa_sm == NULL) {
1610325151a3SRui Paulo wpa_printf(MSG_DEBUG,
1611325151a3SRui Paulo "FT: Failed to initialize WPA state machine");
1612f05cddf9SRui Paulo status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1613f05cddf9SRui Paulo goto fail;
1614f05cddf9SRui Paulo }
1615*a90b9d01SCy Schubert wpa_ft_process_auth(sta->wpa_sm,
1616f05cddf9SRui Paulo rx_auth->auth_transaction, rx_auth->ies,
1617f05cddf9SRui Paulo rx_auth->ies_len,
1618f05cddf9SRui Paulo hostapd_notify_auth_ft_finish, hapd);
1619f05cddf9SRui Paulo return;
1620f05cddf9SRui Paulo }
162185732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
162285732ac8SCy Schubert
162385732ac8SCy Schubert #ifdef CONFIG_FILS
162485732ac8SCy Schubert if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
162585732ac8SCy Schubert sta->auth_alg = WLAN_AUTH_FILS_SK;
162685732ac8SCy Schubert handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
162785732ac8SCy Schubert rx_auth->auth_type, rx_auth->auth_transaction,
162885732ac8SCy Schubert rx_auth->status_code,
162985732ac8SCy Schubert hostapd_notify_auth_fils_finish);
163085732ac8SCy Schubert return;
163185732ac8SCy Schubert }
163285732ac8SCy Schubert #endif /* CONFIG_FILS */
163385732ac8SCy Schubert
1634f05cddf9SRui Paulo fail:
1635f05cddf9SRui Paulo hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
1636f05cddf9SRui Paulo status, resp_ies, resp_ies_len);
1637f05cddf9SRui Paulo }
1638e28a4053SRui Paulo
1639e28a4053SRui Paulo
16404bc52338SCy Schubert #ifndef NEED_AP_MLME
hostapd_action_rx(struct hostapd_data * hapd,struct rx_mgmt * drv_mgmt)1641f05cddf9SRui Paulo static void hostapd_action_rx(struct hostapd_data *hapd,
16425b9c547cSRui Paulo struct rx_mgmt *drv_mgmt)
1643f05cddf9SRui Paulo {
16445b9c547cSRui Paulo struct ieee80211_mgmt *mgmt;
1645f05cddf9SRui Paulo struct sta_info *sta;
16465b9c547cSRui Paulo size_t plen __maybe_unused;
16475b9c547cSRui Paulo u16 fc;
164885732ac8SCy Schubert u8 *action __maybe_unused;
16495b9c547cSRui Paulo
165085732ac8SCy Schubert if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1)
16515b9c547cSRui Paulo return;
16525b9c547cSRui Paulo
16534bc52338SCy Schubert plen = drv_mgmt->frame_len - IEEE80211_HDRLEN;
16545b9c547cSRui Paulo
16555b9c547cSRui Paulo mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
16565b9c547cSRui Paulo fc = le_to_host16(mgmt->frame_control);
16575b9c547cSRui Paulo if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
16585b9c547cSRui Paulo return; /* handled by the driver */
1659f05cddf9SRui Paulo
166085732ac8SCy Schubert action = (u8 *) &mgmt->u.action.u;
166185732ac8SCy Schubert wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
166285732ac8SCy Schubert " da " MACSTR " plen %d",
166385732ac8SCy Schubert mgmt->u.action.category, *action,
166485732ac8SCy Schubert MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen);
1665f05cddf9SRui Paulo
16665b9c547cSRui Paulo sta = ap_get_sta(hapd, mgmt->sa);
1667f05cddf9SRui Paulo if (sta == NULL) {
1668f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
1669f05cddf9SRui Paulo return;
1670f05cddf9SRui Paulo }
167185732ac8SCy Schubert #ifdef CONFIG_IEEE80211R_AP
16725b9c547cSRui Paulo if (mgmt->u.action.category == WLAN_ACTION_FT) {
16734bc52338SCy Schubert wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, plen);
16744bc52338SCy Schubert return;
1675f05cddf9SRui Paulo }
167685732ac8SCy Schubert #endif /* CONFIG_IEEE80211R_AP */
16774bc52338SCy Schubert if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY) {
16784bc52338SCy Schubert ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len);
16794bc52338SCy Schubert return;
1680f05cddf9SRui Paulo }
168185732ac8SCy Schubert #ifdef CONFIG_WNM_AP
16825b9c547cSRui Paulo if (mgmt->u.action.category == WLAN_ACTION_WNM) {
16835b9c547cSRui Paulo ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
16844bc52338SCy Schubert return;
1685f05cddf9SRui Paulo }
168685732ac8SCy Schubert #endif /* CONFIG_WNM_AP */
1687325151a3SRui Paulo #ifdef CONFIG_FST
1688325151a3SRui Paulo if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
1689325151a3SRui Paulo fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
1690325151a3SRui Paulo return;
1691325151a3SRui Paulo }
1692325151a3SRui Paulo #endif /* CONFIG_FST */
169385732ac8SCy Schubert #ifdef CONFIG_DPP
16944bc52338SCy Schubert if (plen >= 2 + 4 &&
1695*a90b9d01SCy Schubert mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
169685732ac8SCy Schubert mgmt->u.action.u.vs_public_action.action ==
169785732ac8SCy Schubert WLAN_PA_VENDOR_SPECIFIC &&
169885732ac8SCy Schubert WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
169985732ac8SCy Schubert OUI_WFA &&
170085732ac8SCy Schubert mgmt->u.action.u.vs_public_action.variable[0] ==
170185732ac8SCy Schubert DPP_OUI_TYPE) {
170285732ac8SCy Schubert const u8 *pos, *end;
1703325151a3SRui Paulo
170485732ac8SCy Schubert pos = mgmt->u.action.u.vs_public_action.oui;
170585732ac8SCy Schubert end = drv_mgmt->frame + drv_mgmt->frame_len;
170685732ac8SCy Schubert hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
170785732ac8SCy Schubert drv_mgmt->freq);
170885732ac8SCy Schubert return;
170985732ac8SCy Schubert }
171085732ac8SCy Schubert #endif /* CONFIG_DPP */
1711*a90b9d01SCy Schubert #ifdef CONFIG_NAN_USD
1712*a90b9d01SCy Schubert if (mgmt->u.action.category == WLAN_ACTION_PUBLIC && plen >= 5 &&
1713*a90b9d01SCy Schubert mgmt->u.action.u.vs_public_action.action ==
1714*a90b9d01SCy Schubert WLAN_PA_VENDOR_SPECIFIC &&
1715*a90b9d01SCy Schubert WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1716*a90b9d01SCy Schubert OUI_WFA &&
1717*a90b9d01SCy Schubert mgmt->u.action.u.vs_public_action.variable[0] == NAN_OUI_TYPE) {
1718*a90b9d01SCy Schubert const u8 *pos, *end;
1719*a90b9d01SCy Schubert
1720*a90b9d01SCy Schubert pos = mgmt->u.action.u.vs_public_action.variable;
1721*a90b9d01SCy Schubert end = drv_mgmt->frame + drv_mgmt->frame_len;
1722*a90b9d01SCy Schubert pos++;
1723*a90b9d01SCy Schubert hostapd_nan_usd_rx_sdf(hapd, mgmt->sa, drv_mgmt->freq,
1724*a90b9d01SCy Schubert pos, end - pos);
1725*a90b9d01SCy Schubert return;
1726*a90b9d01SCy Schubert }
1727*a90b9d01SCy Schubert #endif /* CONFIG_NAN_USD */
1728f05cddf9SRui Paulo }
17294bc52338SCy Schubert #endif /* NEED_AP_MLME */
1730f05cddf9SRui Paulo
1731f05cddf9SRui Paulo
1732f05cddf9SRui Paulo #ifdef NEED_AP_MLME
1733f05cddf9SRui Paulo
1734*a90b9d01SCy Schubert static struct hostapd_data *
switch_link_hapd(struct hostapd_data * hapd,int link_id)1735*a90b9d01SCy Schubert switch_link_hapd(struct hostapd_data *hapd, int link_id)
1736*a90b9d01SCy Schubert {
1737*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1738*a90b9d01SCy Schubert if (hapd->conf->mld_ap && link_id >= 0) {
1739*a90b9d01SCy Schubert struct hostapd_data *link_bss;
1740*a90b9d01SCy Schubert
1741*a90b9d01SCy Schubert link_bss = hostapd_mld_get_link_bss(hapd, link_id);
1742*a90b9d01SCy Schubert if (link_bss)
1743*a90b9d01SCy Schubert return link_bss;
1744*a90b9d01SCy Schubert }
1745*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1746*a90b9d01SCy Schubert
1747*a90b9d01SCy Schubert return hapd;
1748*a90b9d01SCy Schubert }
1749*a90b9d01SCy Schubert
1750*a90b9d01SCy Schubert
1751*a90b9d01SCy Schubert static struct hostapd_data *
switch_link_scan(struct hostapd_data * hapd,u64 scan_cookie)1752*a90b9d01SCy Schubert switch_link_scan(struct hostapd_data *hapd, u64 scan_cookie)
1753*a90b9d01SCy Schubert {
1754*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1755*a90b9d01SCy Schubert if (hapd->conf->mld_ap && scan_cookie != 0) {
1756*a90b9d01SCy Schubert unsigned int i;
1757*a90b9d01SCy Schubert
1758*a90b9d01SCy Schubert for (i = 0; i < hapd->iface->interfaces->count; i++) {
1759*a90b9d01SCy Schubert struct hostapd_iface *h;
1760*a90b9d01SCy Schubert struct hostapd_data *h_hapd;
1761*a90b9d01SCy Schubert
1762*a90b9d01SCy Schubert h = hapd->iface->interfaces->iface[i];
1763*a90b9d01SCy Schubert h_hapd = h->bss[0];
1764*a90b9d01SCy Schubert if (!hostapd_is_ml_partner(hapd, h_hapd))
1765*a90b9d01SCy Schubert continue;
1766*a90b9d01SCy Schubert
1767*a90b9d01SCy Schubert if (h_hapd->scan_cookie == scan_cookie) {
1768*a90b9d01SCy Schubert h_hapd->scan_cookie = 0;
1769*a90b9d01SCy Schubert return h_hapd;
1770*a90b9d01SCy Schubert }
1771*a90b9d01SCy Schubert }
1772*a90b9d01SCy Schubert }
1773*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1774*a90b9d01SCy Schubert
1775*a90b9d01SCy Schubert return hapd;
1776*a90b9d01SCy Schubert }
1777*a90b9d01SCy Schubert
1778*a90b9d01SCy Schubert
1779e28a4053SRui Paulo #define HAPD_BROADCAST ((struct hostapd_data *) -1)
1780e28a4053SRui Paulo
get_hapd_bssid(struct hostapd_iface * iface,const u8 * bssid,int link_id)1781e28a4053SRui Paulo static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
1782*a90b9d01SCy Schubert const u8 *bssid, int link_id)
1783e28a4053SRui Paulo {
1784e28a4053SRui Paulo size_t i;
1785e28a4053SRui Paulo
1786e28a4053SRui Paulo if (bssid == NULL)
1787e28a4053SRui Paulo return NULL;
1788e28a4053SRui Paulo if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1789e28a4053SRui Paulo bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1790e28a4053SRui Paulo return HAPD_BROADCAST;
1791e28a4053SRui Paulo
1792e28a4053SRui Paulo for (i = 0; i < iface->num_bss; i++) {
1793*a90b9d01SCy Schubert struct hostapd_data *hapd;
1794*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1795*a90b9d01SCy Schubert struct hostapd_data *p_hapd;
1796*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1797*a90b9d01SCy Schubert
1798*a90b9d01SCy Schubert hapd = iface->bss[i];
1799*a90b9d01SCy Schubert if (ether_addr_equal(bssid, hapd->own_addr))
1800*a90b9d01SCy Schubert return hapd;
1801*a90b9d01SCy Schubert
1802*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1803*a90b9d01SCy Schubert if (ether_addr_equal(bssid, hapd->own_addr) ||
1804*a90b9d01SCy Schubert (hapd->conf->mld_ap &&
1805*a90b9d01SCy Schubert ether_addr_equal(bssid, hapd->mld->mld_addr) &&
1806*a90b9d01SCy Schubert link_id == hapd->mld_link_id))
1807*a90b9d01SCy Schubert return hapd;
1808*a90b9d01SCy Schubert
1809*a90b9d01SCy Schubert if (!hapd->conf->mld_ap)
1810*a90b9d01SCy Schubert continue;
1811*a90b9d01SCy Schubert
1812*a90b9d01SCy Schubert for_each_mld_link(p_hapd, hapd) {
1813*a90b9d01SCy Schubert if (p_hapd == hapd)
1814*a90b9d01SCy Schubert continue;
1815*a90b9d01SCy Schubert
1816*a90b9d01SCy Schubert if (ether_addr_equal(bssid, p_hapd->own_addr) ||
1817*a90b9d01SCy Schubert (ether_addr_equal(bssid, p_hapd->mld->mld_addr) &&
1818*a90b9d01SCy Schubert link_id == p_hapd->mld_link_id))
1819*a90b9d01SCy Schubert return p_hapd;
1820*a90b9d01SCy Schubert }
1821*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1822e28a4053SRui Paulo }
1823e28a4053SRui Paulo
1824e28a4053SRui Paulo return NULL;
1825e28a4053SRui Paulo }
1826e28a4053SRui Paulo
1827e28a4053SRui Paulo
hostapd_rx_from_unknown_sta(struct hostapd_data * hapd,const u8 * bssid,const u8 * addr,int wds)1828e28a4053SRui Paulo static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
1829f05cddf9SRui Paulo const u8 *bssid, const u8 *addr,
1830f05cddf9SRui Paulo int wds)
1831e28a4053SRui Paulo {
1832*a90b9d01SCy Schubert hapd = get_hapd_bssid(hapd->iface, bssid, -1);
1833e28a4053SRui Paulo if (hapd == NULL || hapd == HAPD_BROADCAST)
1834e28a4053SRui Paulo return;
1835e28a4053SRui Paulo
1836f05cddf9SRui Paulo ieee802_11_rx_from_unknown(hapd, addr, wds);
1837e28a4053SRui Paulo }
1838e28a4053SRui Paulo
1839e28a4053SRui Paulo
hostapd_mgmt_rx(struct hostapd_data * hapd,struct rx_mgmt * rx_mgmt)18405b9c547cSRui Paulo static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
1841e28a4053SRui Paulo {
1842*a90b9d01SCy Schubert struct hostapd_iface *iface;
1843e28a4053SRui Paulo const struct ieee80211_hdr *hdr;
1844e28a4053SRui Paulo const u8 *bssid;
1845e28a4053SRui Paulo struct hostapd_frame_info fi;
18465b9c547cSRui Paulo int ret;
18475b9c547cSRui Paulo
1848*a90b9d01SCy Schubert if (rx_mgmt->ctx)
1849*a90b9d01SCy Schubert hapd = rx_mgmt->ctx;
1850*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd, rx_mgmt->link_id);
1851*a90b9d01SCy Schubert iface = hapd->iface;
1852*a90b9d01SCy Schubert
18535b9c547cSRui Paulo #ifdef CONFIG_TESTING_OPTIONS
18545b9c547cSRui Paulo if (hapd->ext_mgmt_frame_handling) {
18555b9c547cSRui Paulo size_t hex_len = 2 * rx_mgmt->frame_len + 1;
18565b9c547cSRui Paulo char *hex = os_malloc(hex_len);
1857325151a3SRui Paulo
18585b9c547cSRui Paulo if (hex) {
18595b9c547cSRui Paulo wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
18605b9c547cSRui Paulo rx_mgmt->frame_len);
18615b9c547cSRui Paulo wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
18625b9c547cSRui Paulo os_free(hex);
18635b9c547cSRui Paulo }
18645b9c547cSRui Paulo return 1;
18655b9c547cSRui Paulo }
18665b9c547cSRui Paulo #endif /* CONFIG_TESTING_OPTIONS */
1867e28a4053SRui Paulo
1868e28a4053SRui Paulo hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1869e28a4053SRui Paulo bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
1870e28a4053SRui Paulo if (bssid == NULL)
18715b9c547cSRui Paulo return 0;
1872e28a4053SRui Paulo
1873*a90b9d01SCy Schubert hapd = get_hapd_bssid(iface, bssid, rx_mgmt->link_id);
1874*a90b9d01SCy Schubert
1875*a90b9d01SCy Schubert if (!hapd) {
1876325151a3SRui Paulo u16 fc = le_to_host16(hdr->frame_control);
1877e28a4053SRui Paulo
1878e28a4053SRui Paulo /*
1879e28a4053SRui Paulo * Drop frames to unknown BSSIDs except for Beacon frames which
1880e28a4053SRui Paulo * could be used to update neighbor information.
1881e28a4053SRui Paulo */
1882e28a4053SRui Paulo if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1883e28a4053SRui Paulo WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1884e28a4053SRui Paulo hapd = iface->bss[0];
1885e28a4053SRui Paulo else
18865b9c547cSRui Paulo return 0;
1887e28a4053SRui Paulo }
1888e28a4053SRui Paulo
1889e28a4053SRui Paulo os_memset(&fi, 0, sizeof(fi));
189085732ac8SCy Schubert fi.freq = rx_mgmt->freq;
1891e28a4053SRui Paulo fi.datarate = rx_mgmt->datarate;
1892e28a4053SRui Paulo fi.ssi_signal = rx_mgmt->ssi_signal;
1893e28a4053SRui Paulo
1894e28a4053SRui Paulo if (hapd == HAPD_BROADCAST) {
1895e28a4053SRui Paulo size_t i;
1896325151a3SRui Paulo
18975b9c547cSRui Paulo ret = 0;
18985b9c547cSRui Paulo for (i = 0; i < iface->num_bss; i++) {
18995b9c547cSRui Paulo /* if bss is set, driver will call this function for
19005b9c547cSRui Paulo * each bss individually. */
19015b9c547cSRui Paulo if (rx_mgmt->drv_priv &&
19025b9c547cSRui Paulo (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
19035b9c547cSRui Paulo continue;
19045b9c547cSRui Paulo
19055b9c547cSRui Paulo if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
19065b9c547cSRui Paulo rx_mgmt->frame_len, &fi) > 0)
19075b9c547cSRui Paulo ret = 1;
19085b9c547cSRui Paulo }
1909e28a4053SRui Paulo } else
19105b9c547cSRui Paulo ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
19115b9c547cSRui Paulo &fi);
1912f05cddf9SRui Paulo
1913f05cddf9SRui Paulo random_add_randomness(&fi, sizeof(fi));
1914f05cddf9SRui Paulo
19155b9c547cSRui Paulo return ret;
1916e28a4053SRui Paulo }
1917e28a4053SRui Paulo
1918e28a4053SRui Paulo
hostapd_mgmt_tx_cb(struct hostapd_data * hapd,const u8 * buf,size_t len,u16 stype,int ok,int link_id)1919e28a4053SRui Paulo static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
1920*a90b9d01SCy Schubert size_t len, u16 stype, int ok, int link_id)
1921e28a4053SRui Paulo {
1922e28a4053SRui Paulo struct ieee80211_hdr *hdr;
1923*a90b9d01SCy Schubert struct hostapd_data *orig_hapd, *tmp_hapd;
1924*a90b9d01SCy Schubert
1925*a90b9d01SCy Schubert orig_hapd = hapd;
1926325151a3SRui Paulo
1927e28a4053SRui Paulo hdr = (struct ieee80211_hdr *) buf;
1928*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd, link_id);
1929*a90b9d01SCy Schubert tmp_hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len), link_id);
1930*a90b9d01SCy Schubert if (tmp_hapd) {
1931*a90b9d01SCy Schubert hapd = tmp_hapd;
1932*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1933*a90b9d01SCy Schubert } else if (hapd->conf->mld_ap &&
1934*a90b9d01SCy Schubert ether_addr_equal(hapd->mld->mld_addr,
1935*a90b9d01SCy Schubert get_hdr_bssid(hdr, len))) {
1936*a90b9d01SCy Schubert /* AP MLD address match - use hapd pointer as-is */
1937*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1938*a90b9d01SCy Schubert } else {
1939e28a4053SRui Paulo return;
1940*a90b9d01SCy Schubert }
1941*a90b9d01SCy Schubert
1942780fb4a2SCy Schubert if (hapd == HAPD_BROADCAST) {
1943780fb4a2SCy Schubert if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
1944780fb4a2SCy Schubert buf[24] != WLAN_ACTION_PUBLIC)
1945780fb4a2SCy Schubert return;
1946*a90b9d01SCy Schubert hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2, link_id);
1947780fb4a2SCy Schubert if (!hapd || hapd == HAPD_BROADCAST)
1948780fb4a2SCy Schubert return;
1949780fb4a2SCy Schubert /*
1950780fb4a2SCy Schubert * Allow processing of TX status for a Public Action frame that
1951780fb4a2SCy Schubert * used wildcard BBSID.
1952780fb4a2SCy Schubert */
1953780fb4a2SCy Schubert }
1954e28a4053SRui Paulo ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1955e28a4053SRui Paulo }
1956e28a4053SRui Paulo
1957e28a4053SRui Paulo #endif /* NEED_AP_MLME */
1958e28a4053SRui Paulo
1959e28a4053SRui Paulo
hostapd_event_new_sta(struct hostapd_data * hapd,const u8 * addr)1960e28a4053SRui Paulo static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
1961e28a4053SRui Paulo {
1962e28a4053SRui Paulo struct sta_info *sta = ap_get_sta(hapd, addr);
1963325151a3SRui Paulo
1964e28a4053SRui Paulo if (sta)
1965e28a4053SRui Paulo return 0;
1966e28a4053SRui Paulo
1967e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
1968e28a4053SRui Paulo " - adding a new STA", MAC2STR(addr));
1969e28a4053SRui Paulo sta = ap_sta_add(hapd, addr);
1970e28a4053SRui Paulo if (sta) {
1971e28a4053SRui Paulo hostapd_new_assoc_sta(hapd, sta, 0);
1972e28a4053SRui Paulo } else {
1973e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
1974e28a4053SRui Paulo MAC2STR(addr));
1975e28a4053SRui Paulo return -1;
1976e28a4053SRui Paulo }
1977e28a4053SRui Paulo
1978e28a4053SRui Paulo return 0;
1979e28a4053SRui Paulo }
1980e28a4053SRui Paulo
1981e28a4053SRui Paulo
hostapd_find_by_sta(struct hostapd_iface * iface,const u8 * src,bool rsn,struct sta_info ** sta_ret)1982*a90b9d01SCy Schubert static struct hostapd_data * hostapd_find_by_sta(struct hostapd_iface *iface,
1983*a90b9d01SCy Schubert const u8 *src, bool rsn,
1984*a90b9d01SCy Schubert struct sta_info **sta_ret)
1985e28a4053SRui Paulo {
1986*a90b9d01SCy Schubert struct hostapd_data *hapd;
1987f05cddf9SRui Paulo struct sta_info *sta;
1988*a90b9d01SCy Schubert unsigned int j;
1989*a90b9d01SCy Schubert
1990*a90b9d01SCy Schubert if (sta_ret)
1991*a90b9d01SCy Schubert *sta_ret = NULL;
1992e28a4053SRui Paulo
1993e28a4053SRui Paulo for (j = 0; j < iface->num_bss; j++) {
1994e28a4053SRui Paulo hapd = iface->bss[j];
1995*a90b9d01SCy Schubert sta = ap_get_sta(hapd, src);
1996*a90b9d01SCy Schubert if (sta && (sta->flags & WLAN_STA_ASSOC) &&
1997*a90b9d01SCy Schubert (!rsn || sta->wpa_sm)) {
1998*a90b9d01SCy Schubert if (sta_ret)
1999*a90b9d01SCy Schubert *sta_ret = sta;
2000*a90b9d01SCy Schubert return hapd;
2001e28a4053SRui Paulo }
2002*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
2003*a90b9d01SCy Schubert if (hapd->conf->mld_ap) {
2004*a90b9d01SCy Schubert struct hostapd_data *p_hapd;
2005*a90b9d01SCy Schubert
2006*a90b9d01SCy Schubert for_each_mld_link(p_hapd, hapd) {
2007*a90b9d01SCy Schubert if (p_hapd == hapd)
2008*a90b9d01SCy Schubert continue;
2009*a90b9d01SCy Schubert
2010*a90b9d01SCy Schubert sta = ap_get_sta(p_hapd, src);
2011*a90b9d01SCy Schubert if (sta && (sta->flags & WLAN_STA_ASSOC) &&
2012*a90b9d01SCy Schubert (!rsn || sta->wpa_sm)) {
2013*a90b9d01SCy Schubert if (sta_ret)
2014*a90b9d01SCy Schubert *sta_ret = sta;
2015*a90b9d01SCy Schubert return p_hapd;
2016*a90b9d01SCy Schubert }
2017*a90b9d01SCy Schubert }
2018*a90b9d01SCy Schubert }
2019*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
2020e28a4053SRui Paulo }
2021e28a4053SRui Paulo
2022*a90b9d01SCy Schubert return NULL;
2023*a90b9d01SCy Schubert }
2024*a90b9d01SCy Schubert
2025*a90b9d01SCy Schubert
hostapd_event_eapol_rx(struct hostapd_data * hapd,const u8 * src,const u8 * data,size_t data_len,enum frame_encryption encrypted,int link_id)2026*a90b9d01SCy Schubert static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
2027*a90b9d01SCy Schubert const u8 *data, size_t data_len,
2028*a90b9d01SCy Schubert enum frame_encryption encrypted,
2029*a90b9d01SCy Schubert int link_id)
2030*a90b9d01SCy Schubert {
2031*a90b9d01SCy Schubert struct hostapd_data *orig_hapd = hapd;
2032*a90b9d01SCy Schubert
2033*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
2034*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd, link_id);
2035*a90b9d01SCy Schubert hapd = hostapd_find_by_sta(hapd->iface, src, true, NULL);
2036*a90b9d01SCy Schubert #else /* CONFIG_IEEE80211BE */
2037*a90b9d01SCy Schubert hapd = hostapd_find_by_sta(hapd->iface, src, false, NULL);
2038*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
2039*a90b9d01SCy Schubert
2040*a90b9d01SCy Schubert if (!hapd) {
2041*a90b9d01SCy Schubert /* WLAN cases need to have an existing association, but non-WLAN
2042*a90b9d01SCy Schubert * cases (mainly, wired IEEE 802.1X) need to be able to process
2043*a90b9d01SCy Schubert * EAPOL frames from new devices that do not yet have a STA
2044*a90b9d01SCy Schubert * entry and as such, do not get a match in
2045*a90b9d01SCy Schubert * hostapd_find_by_sta(). */
2046*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
2047*a90b9d01SCy Schubert "No STA-specific hostapd instance for EAPOL RX found - fall back to initial context");
2048*a90b9d01SCy Schubert hapd = orig_hapd;
2049*a90b9d01SCy Schubert }
2050*a90b9d01SCy Schubert
2051*a90b9d01SCy Schubert ieee802_1x_receive(hapd, src, data, data_len, encrypted);
2052e28a4053SRui Paulo }
2053e28a4053SRui Paulo
2054780fb4a2SCy Schubert #endif /* HOSTAPD */
2055780fb4a2SCy Schubert
2056e28a4053SRui Paulo
2057c1d255d3SCy Schubert static struct hostapd_channel_data *
hostapd_get_mode_chan(struct hostapd_hw_modes * mode,unsigned int freq)2058c1d255d3SCy Schubert hostapd_get_mode_chan(struct hostapd_hw_modes *mode, unsigned int freq)
2059c1d255d3SCy Schubert {
2060c1d255d3SCy Schubert int i;
2061c1d255d3SCy Schubert struct hostapd_channel_data *chan;
2062c1d255d3SCy Schubert
2063c1d255d3SCy Schubert for (i = 0; i < mode->num_channels; i++) {
2064c1d255d3SCy Schubert chan = &mode->channels[i];
2065c1d255d3SCy Schubert if ((unsigned int) chan->freq == freq)
2066c1d255d3SCy Schubert return chan;
2067c1d255d3SCy Schubert }
2068c1d255d3SCy Schubert
2069c1d255d3SCy Schubert return NULL;
2070c1d255d3SCy Schubert }
2071c1d255d3SCy Schubert
2072c1d255d3SCy Schubert
hostapd_get_mode_channel(struct hostapd_iface * iface,unsigned int freq)20735b9c547cSRui Paulo static struct hostapd_channel_data * hostapd_get_mode_channel(
20745b9c547cSRui Paulo struct hostapd_iface *iface, unsigned int freq)
20755b9c547cSRui Paulo {
20765b9c547cSRui Paulo int i;
20775b9c547cSRui Paulo struct hostapd_channel_data *chan;
20785b9c547cSRui Paulo
2079c1d255d3SCy Schubert for (i = 0; i < iface->num_hw_features; i++) {
2080c1d255d3SCy Schubert if (hostapd_hw_skip_mode(iface, &iface->hw_features[i]))
2081c1d255d3SCy Schubert continue;
2082c1d255d3SCy Schubert chan = hostapd_get_mode_chan(&iface->hw_features[i], freq);
2083c1d255d3SCy Schubert if (chan)
20845b9c547cSRui Paulo return chan;
20855b9c547cSRui Paulo }
20865b9c547cSRui Paulo
20875b9c547cSRui Paulo return NULL;
20885b9c547cSRui Paulo }
20895b9c547cSRui Paulo
20905b9c547cSRui Paulo
hostapd_update_nf(struct hostapd_iface * iface,struct hostapd_channel_data * chan,struct freq_survey * survey)20915b9c547cSRui Paulo static void hostapd_update_nf(struct hostapd_iface *iface,
20925b9c547cSRui Paulo struct hostapd_channel_data *chan,
20935b9c547cSRui Paulo struct freq_survey *survey)
20945b9c547cSRui Paulo {
20955b9c547cSRui Paulo if (!iface->chans_surveyed) {
20965b9c547cSRui Paulo chan->min_nf = survey->nf;
20975b9c547cSRui Paulo iface->lowest_nf = survey->nf;
20985b9c547cSRui Paulo } else {
20995b9c547cSRui Paulo if (dl_list_empty(&chan->survey_list))
21005b9c547cSRui Paulo chan->min_nf = survey->nf;
21015b9c547cSRui Paulo else if (survey->nf < chan->min_nf)
21025b9c547cSRui Paulo chan->min_nf = survey->nf;
21035b9c547cSRui Paulo if (survey->nf < iface->lowest_nf)
21045b9c547cSRui Paulo iface->lowest_nf = survey->nf;
21055b9c547cSRui Paulo }
21065b9c547cSRui Paulo }
21075b9c547cSRui Paulo
21085b9c547cSRui Paulo
hostapd_single_channel_get_survey(struct hostapd_iface * iface,struct survey_results * survey_res)21095b9c547cSRui Paulo static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
21105b9c547cSRui Paulo struct survey_results *survey_res)
21115b9c547cSRui Paulo {
21125b9c547cSRui Paulo struct hostapd_channel_data *chan;
21135b9c547cSRui Paulo struct freq_survey *survey;
21145b9c547cSRui Paulo u64 divisor, dividend;
21155b9c547cSRui Paulo
21165b9c547cSRui Paulo survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
21175b9c547cSRui Paulo list);
21185b9c547cSRui Paulo if (!survey || !survey->freq)
21195b9c547cSRui Paulo return;
21205b9c547cSRui Paulo
21215b9c547cSRui Paulo chan = hostapd_get_mode_channel(iface, survey->freq);
21225b9c547cSRui Paulo if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
21235b9c547cSRui Paulo return;
21245b9c547cSRui Paulo
2125325151a3SRui Paulo wpa_printf(MSG_DEBUG,
2126325151a3SRui Paulo "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
21275b9c547cSRui Paulo survey->freq,
21285b9c547cSRui Paulo (unsigned long int) survey->channel_time,
21295b9c547cSRui Paulo (unsigned long int) survey->channel_time_busy);
21305b9c547cSRui Paulo
21315b9c547cSRui Paulo if (survey->channel_time > iface->last_channel_time &&
21325b9c547cSRui Paulo survey->channel_time > survey->channel_time_busy) {
21335b9c547cSRui Paulo dividend = survey->channel_time_busy -
21345b9c547cSRui Paulo iface->last_channel_time_busy;
21355b9c547cSRui Paulo divisor = survey->channel_time - iface->last_channel_time;
21365b9c547cSRui Paulo
21375b9c547cSRui Paulo iface->channel_utilization = dividend * 255 / divisor;
21385b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
21395b9c547cSRui Paulo iface->channel_utilization);
21405b9c547cSRui Paulo }
21415b9c547cSRui Paulo iface->last_channel_time = survey->channel_time;
21425b9c547cSRui Paulo iface->last_channel_time_busy = survey->channel_time_busy;
21435b9c547cSRui Paulo }
21445b9c547cSRui Paulo
21455b9c547cSRui Paulo
hostapd_event_get_survey(struct hostapd_iface * iface,struct survey_results * survey_results)2146780fb4a2SCy Schubert void hostapd_event_get_survey(struct hostapd_iface *iface,
21475b9c547cSRui Paulo struct survey_results *survey_results)
21485b9c547cSRui Paulo {
21495b9c547cSRui Paulo struct freq_survey *survey, *tmp;
21505b9c547cSRui Paulo struct hostapd_channel_data *chan;
21515b9c547cSRui Paulo
21525b9c547cSRui Paulo if (dl_list_empty(&survey_results->survey_list)) {
21535b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "No survey data received");
21545b9c547cSRui Paulo return;
21555b9c547cSRui Paulo }
21565b9c547cSRui Paulo
21575b9c547cSRui Paulo if (survey_results->freq_filter) {
21585b9c547cSRui Paulo hostapd_single_channel_get_survey(iface, survey_results);
21595b9c547cSRui Paulo return;
21605b9c547cSRui Paulo }
21615b9c547cSRui Paulo
21625b9c547cSRui Paulo dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
21635b9c547cSRui Paulo struct freq_survey, list) {
21645b9c547cSRui Paulo chan = hostapd_get_mode_channel(iface, survey->freq);
21655b9c547cSRui Paulo if (!chan)
21665b9c547cSRui Paulo continue;
21675b9c547cSRui Paulo if (chan->flag & HOSTAPD_CHAN_DISABLED)
21685b9c547cSRui Paulo continue;
21695b9c547cSRui Paulo
21705b9c547cSRui Paulo dl_list_del(&survey->list);
21715b9c547cSRui Paulo dl_list_add_tail(&chan->survey_list, &survey->list);
21725b9c547cSRui Paulo
21735b9c547cSRui Paulo hostapd_update_nf(iface, chan, survey);
21745b9c547cSRui Paulo
21755b9c547cSRui Paulo iface->chans_surveyed++;
21765b9c547cSRui Paulo }
21775b9c547cSRui Paulo }
21785b9c547cSRui Paulo
21795b9c547cSRui Paulo
2180780fb4a2SCy Schubert #ifdef HOSTAPD
21815b9c547cSRui Paulo #ifdef NEED_AP_MLME
21825b9c547cSRui Paulo
hostapd_event_iface_unavailable(struct hostapd_data * hapd)21835b9c547cSRui Paulo static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
21845b9c547cSRui Paulo {
21855b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
21865b9c547cSRui Paulo hapd->conf->iface);
21875b9c547cSRui Paulo
21885b9c547cSRui Paulo if (hapd->csa_in_progress) {
21895b9c547cSRui Paulo wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
21905b9c547cSRui Paulo hapd->conf->iface);
21915b9c547cSRui Paulo hostapd_switch_channel_fallback(hapd->iface,
21925b9c547cSRui Paulo &hapd->cs_freq_params);
21935b9c547cSRui Paulo }
21945b9c547cSRui Paulo }
21955b9c547cSRui Paulo
21965b9c547cSRui Paulo
hostapd_event_dfs_radar_detected(struct hostapd_data * hapd,struct dfs_event * radar)21975b9c547cSRui Paulo static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
21985b9c547cSRui Paulo struct dfs_event *radar)
21995b9c547cSRui Paulo {
22005b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
22015b9c547cSRui Paulo hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
22025b9c547cSRui Paulo radar->chan_offset, radar->chan_width,
22035b9c547cSRui Paulo radar->cf1, radar->cf2);
22045b9c547cSRui Paulo }
22055b9c547cSRui Paulo
22065b9c547cSRui Paulo
hostapd_event_dfs_pre_cac_expired(struct hostapd_data * hapd,struct dfs_event * radar)220785732ac8SCy Schubert static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
220885732ac8SCy Schubert struct dfs_event *radar)
220985732ac8SCy Schubert {
221085732ac8SCy Schubert wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
221185732ac8SCy Schubert hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
221285732ac8SCy Schubert radar->chan_offset, radar->chan_width,
221385732ac8SCy Schubert radar->cf1, radar->cf2);
221485732ac8SCy Schubert }
221585732ac8SCy Schubert
221685732ac8SCy Schubert
hostapd_event_dfs_cac_finished(struct hostapd_data * hapd,struct dfs_event * radar)22175b9c547cSRui Paulo static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
22185b9c547cSRui Paulo struct dfs_event *radar)
22195b9c547cSRui Paulo {
22205b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
22215b9c547cSRui Paulo hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
22225b9c547cSRui Paulo radar->chan_offset, radar->chan_width,
22235b9c547cSRui Paulo radar->cf1, radar->cf2);
22245b9c547cSRui Paulo }
22255b9c547cSRui Paulo
22265b9c547cSRui Paulo
hostapd_event_dfs_cac_aborted(struct hostapd_data * hapd,struct dfs_event * radar)22275b9c547cSRui Paulo static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
22285b9c547cSRui Paulo struct dfs_event *radar)
22295b9c547cSRui Paulo {
22305b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
22315b9c547cSRui Paulo hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
22325b9c547cSRui Paulo radar->chan_offset, radar->chan_width,
22335b9c547cSRui Paulo radar->cf1, radar->cf2);
22345b9c547cSRui Paulo }
22355b9c547cSRui Paulo
22365b9c547cSRui Paulo
hostapd_event_dfs_nop_finished(struct hostapd_data * hapd,struct dfs_event * radar)22375b9c547cSRui Paulo static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
22385b9c547cSRui Paulo struct dfs_event *radar)
22395b9c547cSRui Paulo {
22405b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
22415b9c547cSRui Paulo hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
22425b9c547cSRui Paulo radar->chan_offset, radar->chan_width,
22435b9c547cSRui Paulo radar->cf1, radar->cf2);
22445b9c547cSRui Paulo }
22455b9c547cSRui Paulo
22465b9c547cSRui Paulo
hostapd_event_dfs_cac_started(struct hostapd_data * hapd,struct dfs_event * radar)22475b9c547cSRui Paulo static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
22485b9c547cSRui Paulo struct dfs_event *radar)
22495b9c547cSRui Paulo {
22505b9c547cSRui Paulo wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
22515b9c547cSRui Paulo hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
22525b9c547cSRui Paulo radar->chan_offset, radar->chan_width,
22535b9c547cSRui Paulo radar->cf1, radar->cf2);
22545b9c547cSRui Paulo }
22555b9c547cSRui Paulo
22565b9c547cSRui Paulo #endif /* NEED_AP_MLME */
22575b9c547cSRui Paulo
22585b9c547cSRui Paulo
hostapd_event_wds_sta_interface_status(struct hostapd_data * hapd,int istatus,const char * ifname,const u8 * addr)225985732ac8SCy Schubert static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd,
226085732ac8SCy Schubert int istatus,
226185732ac8SCy Schubert const char *ifname,
226285732ac8SCy Schubert const u8 *addr)
226385732ac8SCy Schubert {
226485732ac8SCy Schubert struct sta_info *sta = ap_get_sta(hapd, addr);
226585732ac8SCy Schubert
226685732ac8SCy Schubert if (sta) {
226785732ac8SCy Schubert os_free(sta->ifname_wds);
226885732ac8SCy Schubert if (istatus == INTERFACE_ADDED)
226985732ac8SCy Schubert sta->ifname_wds = os_strdup(ifname);
227085732ac8SCy Schubert else
227185732ac8SCy Schubert sta->ifname_wds = NULL;
227285732ac8SCy Schubert }
227385732ac8SCy Schubert
227485732ac8SCy Schubert wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR,
227585732ac8SCy Schubert istatus == INTERFACE_ADDED ?
227685732ac8SCy Schubert WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED,
227785732ac8SCy Schubert ifname, MAC2STR(addr));
227885732ac8SCy Schubert }
227985732ac8SCy Schubert
228085732ac8SCy Schubert
2281206b73d0SCy Schubert #ifdef CONFIG_OWE
hostapd_notif_update_dh_ie(struct hostapd_data * hapd,const u8 * peer,const u8 * ie,size_t ie_len,const u8 * link_addr)2282206b73d0SCy Schubert static int hostapd_notif_update_dh_ie(struct hostapd_data *hapd,
2283206b73d0SCy Schubert const u8 *peer, const u8 *ie,
2284*a90b9d01SCy Schubert size_t ie_len, const u8 *link_addr)
2285206b73d0SCy Schubert {
2286206b73d0SCy Schubert u16 status;
2287206b73d0SCy Schubert struct sta_info *sta;
2288206b73d0SCy Schubert struct ieee802_11_elems elems;
2289206b73d0SCy Schubert
2290206b73d0SCy Schubert if (!hapd || !hapd->wpa_auth) {
2291206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "OWE: Invalid hapd context");
2292206b73d0SCy Schubert return -1;
2293206b73d0SCy Schubert }
2294206b73d0SCy Schubert if (!peer) {
2295206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "OWE: Peer unknown");
2296206b73d0SCy Schubert return -1;
2297206b73d0SCy Schubert }
2298206b73d0SCy Schubert if (!(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) {
2299206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "OWE: No OWE AKM configured");
2300206b73d0SCy Schubert status = WLAN_STATUS_AKMP_NOT_VALID;
2301206b73d0SCy Schubert goto err;
2302206b73d0SCy Schubert }
2303206b73d0SCy Schubert if (ieee802_11_parse_elems(ie, ie_len, &elems, 1) == ParseFailed) {
2304206b73d0SCy Schubert wpa_printf(MSG_DEBUG, "OWE: Failed to parse OWE IE for "
2305206b73d0SCy Schubert MACSTR, MAC2STR(peer));
2306206b73d0SCy Schubert status = WLAN_STATUS_UNSPECIFIED_FAILURE;
2307206b73d0SCy Schubert goto err;
2308206b73d0SCy Schubert }
2309206b73d0SCy Schubert status = owe_validate_request(hapd, peer, elems.rsn_ie,
2310206b73d0SCy Schubert elems.rsn_ie_len,
2311206b73d0SCy Schubert elems.owe_dh, elems.owe_dh_len);
2312206b73d0SCy Schubert if (status != WLAN_STATUS_SUCCESS)
2313206b73d0SCy Schubert goto err;
2314206b73d0SCy Schubert
2315206b73d0SCy Schubert sta = ap_get_sta(hapd, peer);
2316206b73d0SCy Schubert if (sta) {
2317206b73d0SCy Schubert ap_sta_no_session_timeout(hapd, sta);
2318206b73d0SCy Schubert accounting_sta_stop(hapd, sta);
2319206b73d0SCy Schubert
2320206b73d0SCy Schubert /*
2321206b73d0SCy Schubert * Make sure that the previously registered inactivity timer
2322206b73d0SCy Schubert * will not remove the STA immediately.
2323206b73d0SCy Schubert */
2324206b73d0SCy Schubert sta->timeout_next = STA_NULLFUNC;
2325206b73d0SCy Schubert } else {
2326206b73d0SCy Schubert sta = ap_sta_add(hapd, peer);
2327206b73d0SCy Schubert if (!sta) {
2328206b73d0SCy Schubert status = WLAN_STATUS_UNSPECIFIED_FAILURE;
2329206b73d0SCy Schubert goto err;
2330206b73d0SCy Schubert }
2331206b73d0SCy Schubert }
2332206b73d0SCy Schubert sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
2333206b73d0SCy Schubert
2334*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
2335*a90b9d01SCy Schubert if (link_addr) {
2336*a90b9d01SCy Schubert struct mld_info *info = &sta->mld_info;
2337*a90b9d01SCy Schubert u8 link_id = hapd->mld_link_id;
2338*a90b9d01SCy Schubert
2339*a90b9d01SCy Schubert ap_sta_set_mld(sta, true);
2340*a90b9d01SCy Schubert sta->mld_assoc_link_id = link_id;
2341*a90b9d01SCy Schubert os_memcpy(info->common_info.mld_addr, peer, ETH_ALEN);
2342*a90b9d01SCy Schubert info->links[link_id].valid = true;
2343*a90b9d01SCy Schubert os_memcpy(info->links[link_id].local_addr, hapd->own_addr,
2344*a90b9d01SCy Schubert ETH_ALEN);
2345*a90b9d01SCy Schubert os_memcpy(info->links[link_id].peer_addr, link_addr, ETH_ALEN);
2346*a90b9d01SCy Schubert }
2347*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
2348*a90b9d01SCy Schubert
2349206b73d0SCy Schubert status = owe_process_rsn_ie(hapd, sta, elems.rsn_ie,
2350206b73d0SCy Schubert elems.rsn_ie_len, elems.owe_dh,
2351*a90b9d01SCy Schubert elems.owe_dh_len, link_addr);
2352206b73d0SCy Schubert if (status != WLAN_STATUS_SUCCESS)
2353206b73d0SCy Schubert ap_free_sta(hapd, sta);
2354206b73d0SCy Schubert
2355206b73d0SCy Schubert return 0;
2356206b73d0SCy Schubert err:
2357*a90b9d01SCy Schubert hostapd_drv_update_dh_ie(hapd, link_addr ? link_addr : peer, status,
2358*a90b9d01SCy Schubert NULL, 0);
2359206b73d0SCy Schubert return 0;
2360206b73d0SCy Schubert }
2361206b73d0SCy Schubert #endif /* CONFIG_OWE */
2362206b73d0SCy Schubert
2363206b73d0SCy Schubert
2364*a90b9d01SCy Schubert #ifdef NEED_AP_MLME
hostapd_eapol_tx_status(struct hostapd_data * hapd,const u8 * dst,const u8 * data,size_t len,int ack,int link_id)2365*a90b9d01SCy Schubert static void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2366*a90b9d01SCy Schubert const u8 *data, size_t len, int ack,
2367*a90b9d01SCy Schubert int link_id)
2368*a90b9d01SCy Schubert {
2369*a90b9d01SCy Schubert struct sta_info *sta;
2370*a90b9d01SCy Schubert
2371*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd, link_id);
2372*a90b9d01SCy Schubert hapd = hostapd_find_by_sta(hapd->iface, dst, false, &sta);
2373*a90b9d01SCy Schubert
2374*a90b9d01SCy Schubert if (!sta) {
2375*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2376*a90b9d01SCy Schubert MACSTR " that is not currently associated",
2377*a90b9d01SCy Schubert MAC2STR(dst));
2378*a90b9d01SCy Schubert return;
2379*a90b9d01SCy Schubert }
2380*a90b9d01SCy Schubert
2381*a90b9d01SCy Schubert ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2382*a90b9d01SCy Schubert }
2383*a90b9d01SCy Schubert #endif /* NEED_AP_MLME */
2384*a90b9d01SCy Schubert
2385*a90b9d01SCy Schubert
2386*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211AX
hostapd_event_color_change(struct hostapd_data * hapd,bool success)2387*a90b9d01SCy Schubert static void hostapd_event_color_change(struct hostapd_data *hapd, bool success)
2388*a90b9d01SCy Schubert {
2389*a90b9d01SCy Schubert struct hostapd_data *bss;
2390*a90b9d01SCy Schubert size_t i;
2391*a90b9d01SCy Schubert
2392*a90b9d01SCy Schubert for (i = 0; i < hapd->iface->num_bss; i++) {
2393*a90b9d01SCy Schubert bss = hapd->iface->bss[i];
2394*a90b9d01SCy Schubert if (bss->cca_color == 0)
2395*a90b9d01SCy Schubert continue;
2396*a90b9d01SCy Schubert
2397*a90b9d01SCy Schubert if (success)
2398*a90b9d01SCy Schubert hapd->iface->conf->he_op.he_bss_color = bss->cca_color;
2399*a90b9d01SCy Schubert
2400*a90b9d01SCy Schubert bss->cca_in_progress = 0;
2401*a90b9d01SCy Schubert if (ieee802_11_set_beacon(bss)) {
2402*a90b9d01SCy Schubert wpa_printf(MSG_ERROR, "Failed to remove BCCA element");
2403*a90b9d01SCy Schubert bss->cca_in_progress = 1;
2404*a90b9d01SCy Schubert } else {
2405*a90b9d01SCy Schubert hostapd_cleanup_cca_params(bss);
2406*a90b9d01SCy Schubert }
2407*a90b9d01SCy Schubert }
2408*a90b9d01SCy Schubert }
2409*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211AX */
2410*a90b9d01SCy Schubert
2411*a90b9d01SCy Schubert
wpa_supplicant_event(void * ctx,enum wpa_event_type event,union wpa_event_data * data)2412e28a4053SRui Paulo void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2413e28a4053SRui Paulo union wpa_event_data *data)
2414e28a4053SRui Paulo {
2415e28a4053SRui Paulo struct hostapd_data *hapd = ctx;
2416*a90b9d01SCy Schubert struct sta_info *sta;
2417f05cddf9SRui Paulo #ifndef CONFIG_NO_STDOUT_DEBUG
2418f05cddf9SRui Paulo int level = MSG_DEBUG;
2419f05cddf9SRui Paulo
2420f05cddf9SRui Paulo if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
2421f05cddf9SRui Paulo data->rx_mgmt.frame_len >= 24) {
2422f05cddf9SRui Paulo const struct ieee80211_hdr *hdr;
2423f05cddf9SRui Paulo u16 fc;
2424325151a3SRui Paulo
2425f05cddf9SRui Paulo hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2426f05cddf9SRui Paulo fc = le_to_host16(hdr->frame_control);
2427f05cddf9SRui Paulo if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2428f05cddf9SRui Paulo WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2429f05cddf9SRui Paulo level = MSG_EXCESSIVE;
24305b9c547cSRui Paulo if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
24315b9c547cSRui Paulo WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
24325b9c547cSRui Paulo level = MSG_EXCESSIVE;
2433f05cddf9SRui Paulo }
2434f05cddf9SRui Paulo
2435f05cddf9SRui Paulo wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
2436f05cddf9SRui Paulo event_to_string(event), event);
2437f05cddf9SRui Paulo #endif /* CONFIG_NO_STDOUT_DEBUG */
2438e28a4053SRui Paulo
2439e28a4053SRui Paulo switch (event) {
2440e28a4053SRui Paulo case EVENT_MICHAEL_MIC_FAILURE:
2441e28a4053SRui Paulo michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
2442e28a4053SRui Paulo break;
2443e28a4053SRui Paulo case EVENT_SCAN_RESULTS:
2444*a90b9d01SCy Schubert #ifdef NEED_AP_MLME
2445*a90b9d01SCy Schubert if (data)
2446*a90b9d01SCy Schubert hapd = switch_link_scan(hapd,
2447*a90b9d01SCy Schubert data->scan_info.scan_cookie);
2448*a90b9d01SCy Schubert #endif /* NEED_AP_MLME */
2449e28a4053SRui Paulo if (hapd->iface->scan_cb)
2450e28a4053SRui Paulo hapd->iface->scan_cb(hapd->iface);
2451*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
2452*a90b9d01SCy Schubert if (!hapd->iface->scan_cb && hapd->conf->mld_ap) {
2453*a90b9d01SCy Schubert /* Other links may be waiting for HT scan result */
2454*a90b9d01SCy Schubert unsigned int i;
2455*a90b9d01SCy Schubert
2456*a90b9d01SCy Schubert for (i = 0; i < hapd->iface->interfaces->count; i++) {
2457*a90b9d01SCy Schubert struct hostapd_iface *h =
2458*a90b9d01SCy Schubert hapd->iface->interfaces->iface[i];
2459*a90b9d01SCy Schubert struct hostapd_data *h_hapd = h->bss[0];
2460*a90b9d01SCy Schubert
2461*a90b9d01SCy Schubert if (hostapd_is_ml_partner(hapd, h_hapd) &&
2462*a90b9d01SCy Schubert h_hapd->iface->scan_cb)
2463*a90b9d01SCy Schubert h_hapd->iface->scan_cb(h_hapd->iface);
2464*a90b9d01SCy Schubert }
2465*a90b9d01SCy Schubert }
2466*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
2467e28a4053SRui Paulo break;
2468e28a4053SRui Paulo case EVENT_WPS_BUTTON_PUSHED:
2469f05cddf9SRui Paulo hostapd_wps_button_pushed(hapd, NULL);
2470e28a4053SRui Paulo break;
2471e28a4053SRui Paulo #ifdef NEED_AP_MLME
2472e28a4053SRui Paulo case EVENT_TX_STATUS:
2473e28a4053SRui Paulo switch (data->tx_status.type) {
2474e28a4053SRui Paulo case WLAN_FC_TYPE_MGMT:
2475e28a4053SRui Paulo hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
2476e28a4053SRui Paulo data->tx_status.data_len,
2477e28a4053SRui Paulo data->tx_status.stype,
2478*a90b9d01SCy Schubert data->tx_status.ack,
2479*a90b9d01SCy Schubert data->tx_status.link_id);
2480e28a4053SRui Paulo break;
2481e28a4053SRui Paulo case WLAN_FC_TYPE_DATA:
2482e28a4053SRui Paulo hostapd_tx_status(hapd, data->tx_status.dst,
2483e28a4053SRui Paulo data->tx_status.data,
2484e28a4053SRui Paulo data->tx_status.data_len,
2485e28a4053SRui Paulo data->tx_status.ack);
2486e28a4053SRui Paulo break;
2487e28a4053SRui Paulo }
2488e28a4053SRui Paulo break;
2489f05cddf9SRui Paulo case EVENT_EAPOL_TX_STATUS:
2490f05cddf9SRui Paulo hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
2491f05cddf9SRui Paulo data->eapol_tx_status.data,
2492f05cddf9SRui Paulo data->eapol_tx_status.data_len,
2493*a90b9d01SCy Schubert data->eapol_tx_status.ack,
2494*a90b9d01SCy Schubert data->eapol_tx_status.link_id);
2495f05cddf9SRui Paulo break;
2496f05cddf9SRui Paulo case EVENT_DRIVER_CLIENT_POLL_OK:
2497f05cddf9SRui Paulo hostapd_client_poll_ok(hapd, data->client_poll.addr);
2498f05cddf9SRui Paulo break;
2499e28a4053SRui Paulo case EVENT_RX_FROM_UNKNOWN:
2500f05cddf9SRui Paulo hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
2501f05cddf9SRui Paulo data->rx_from_unknown.addr,
2502f05cddf9SRui Paulo data->rx_from_unknown.wds);
2503e28a4053SRui Paulo break;
25045b9c547cSRui Paulo #endif /* NEED_AP_MLME */
2505e28a4053SRui Paulo case EVENT_RX_MGMT:
25065b9c547cSRui Paulo if (!data->rx_mgmt.frame)
25075b9c547cSRui Paulo break;
25085b9c547cSRui Paulo #ifdef NEED_AP_MLME
25094bc52338SCy Schubert hostapd_mgmt_rx(hapd, &data->rx_mgmt);
25104bc52338SCy Schubert #else /* NEED_AP_MLME */
25115b9c547cSRui Paulo hostapd_action_rx(hapd, &data->rx_mgmt);
25124bc52338SCy Schubert #endif /* NEED_AP_MLME */
25135b9c547cSRui Paulo break;
2514e28a4053SRui Paulo case EVENT_RX_PROBE_REQ:
2515f05cddf9SRui Paulo if (data->rx_probe_req.sa == NULL ||
2516f05cddf9SRui Paulo data->rx_probe_req.ie == NULL)
2517f05cddf9SRui Paulo break;
2518e28a4053SRui Paulo hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
2519f05cddf9SRui Paulo data->rx_probe_req.da,
2520f05cddf9SRui Paulo data->rx_probe_req.bssid,
2521e28a4053SRui Paulo data->rx_probe_req.ie,
2522f05cddf9SRui Paulo data->rx_probe_req.ie_len,
2523f05cddf9SRui Paulo data->rx_probe_req.ssi_signal);
2524e28a4053SRui Paulo break;
2525e28a4053SRui Paulo case EVENT_NEW_STA:
2526e28a4053SRui Paulo hostapd_event_new_sta(hapd, data->new_sta.addr);
2527e28a4053SRui Paulo break;
2528e28a4053SRui Paulo case EVENT_EAPOL_RX:
2529e28a4053SRui Paulo hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
2530e28a4053SRui Paulo data->eapol_rx.data,
2531*a90b9d01SCy Schubert data->eapol_rx.data_len,
2532*a90b9d01SCy Schubert data->eapol_rx.encrypted,
2533*a90b9d01SCy Schubert data->eapol_rx.link_id);
2534e28a4053SRui Paulo break;
2535e28a4053SRui Paulo case EVENT_ASSOC:
25365b9c547cSRui Paulo if (!data)
25375b9c547cSRui Paulo return;
2538*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
2539*a90b9d01SCy Schubert if (data->assoc_info.assoc_link_id != -1) {
2540*a90b9d01SCy Schubert hapd = hostapd_mld_get_link_bss(
2541*a90b9d01SCy Schubert hapd, data->assoc_info.assoc_link_id);
2542*a90b9d01SCy Schubert if (!hapd) {
2543*a90b9d01SCy Schubert wpa_printf(MSG_ERROR,
2544*a90b9d01SCy Schubert "MLD: Failed to get link BSS for EVENT_ASSOC");
2545*a90b9d01SCy Schubert return;
2546*a90b9d01SCy Schubert }
2547*a90b9d01SCy Schubert }
2548*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
2549e28a4053SRui Paulo hostapd_notif_assoc(hapd, data->assoc_info.addr,
2550e28a4053SRui Paulo data->assoc_info.req_ies,
2551f05cddf9SRui Paulo data->assoc_info.req_ies_len,
2552*a90b9d01SCy Schubert data->assoc_info.resp_ies,
2553*a90b9d01SCy Schubert data->assoc_info.resp_ies_len,
2554*a90b9d01SCy Schubert data->assoc_info.link_addr,
2555f05cddf9SRui Paulo data->assoc_info.reassoc);
2556e28a4053SRui Paulo break;
2557*a90b9d01SCy Schubert case EVENT_PORT_AUTHORIZED:
2558*a90b9d01SCy Schubert /* Port authorized event for an associated STA */
2559*a90b9d01SCy Schubert sta = ap_get_sta(hapd, data->port_authorized.sta_addr);
2560*a90b9d01SCy Schubert if (sta)
2561*a90b9d01SCy Schubert ap_sta_set_authorized(hapd, sta, 1);
2562*a90b9d01SCy Schubert else
2563*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
2564*a90b9d01SCy Schubert "No STA info matching port authorized event found");
2565*a90b9d01SCy Schubert break;
2566206b73d0SCy Schubert #ifdef CONFIG_OWE
2567206b73d0SCy Schubert case EVENT_UPDATE_DH:
2568206b73d0SCy Schubert if (!data)
2569206b73d0SCy Schubert return;
2570*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
2571*a90b9d01SCy Schubert if (data->update_dh.assoc_link_id != -1) {
2572*a90b9d01SCy Schubert hapd = hostapd_mld_get_link_bss(
2573*a90b9d01SCy Schubert hapd, data->update_dh.assoc_link_id);
2574*a90b9d01SCy Schubert if (!hapd) {
2575*a90b9d01SCy Schubert wpa_printf(MSG_ERROR,
2576*a90b9d01SCy Schubert "MLD: Failed to get link BSS for EVENT_UPDATE_DH assoc_link_id=%d",
2577*a90b9d01SCy Schubert data->update_dh.assoc_link_id);
2578*a90b9d01SCy Schubert return;
2579*a90b9d01SCy Schubert }
2580*a90b9d01SCy Schubert }
2581*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
2582206b73d0SCy Schubert hostapd_notif_update_dh_ie(hapd, data->update_dh.peer,
2583206b73d0SCy Schubert data->update_dh.ie,
2584*a90b9d01SCy Schubert data->update_dh.ie_len,
2585*a90b9d01SCy Schubert data->update_dh.link_addr);
2586206b73d0SCy Schubert break;
2587206b73d0SCy Schubert #endif /* CONFIG_OWE */
2588e28a4053SRui Paulo case EVENT_DISASSOC:
2589e28a4053SRui Paulo if (data)
2590e28a4053SRui Paulo hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
2591e28a4053SRui Paulo break;
2592e28a4053SRui Paulo case EVENT_DEAUTH:
2593e28a4053SRui Paulo if (data)
2594e28a4053SRui Paulo hostapd_notif_disassoc(hapd, data->deauth_info.addr);
2595e28a4053SRui Paulo break;
2596f05cddf9SRui Paulo case EVENT_STATION_LOW_ACK:
2597f05cddf9SRui Paulo if (!data)
2598f05cddf9SRui Paulo break;
2599f05cddf9SRui Paulo hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
2600f05cddf9SRui Paulo break;
2601f05cddf9SRui Paulo case EVENT_AUTH:
2602f05cddf9SRui Paulo hostapd_notif_auth(hapd, &data->auth);
2603f05cddf9SRui Paulo break;
2604206b73d0SCy Schubert case EVENT_CH_SWITCH_STARTED:
2605f05cddf9SRui Paulo case EVENT_CH_SWITCH:
2606f05cddf9SRui Paulo if (!data)
2607f05cddf9SRui Paulo break;
2608*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
2609*a90b9d01SCy Schubert if (data->ch_switch.link_id != -1) {
2610*a90b9d01SCy Schubert hapd = hostapd_mld_get_link_bss(
2611*a90b9d01SCy Schubert hapd, data->ch_switch.link_id);
2612*a90b9d01SCy Schubert if (!hapd) {
2613*a90b9d01SCy Schubert wpa_printf(MSG_ERROR,
2614*a90b9d01SCy Schubert "MLD: Failed to get link (ID %d) BSS for EVENT_CH_SWITCH/EVENT_CH_SWITCH_STARTED",
2615*a90b9d01SCy Schubert data->ch_switch.link_id);
2616*a90b9d01SCy Schubert break;
2617*a90b9d01SCy Schubert }
2618*a90b9d01SCy Schubert }
2619*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
2620f05cddf9SRui Paulo hostapd_event_ch_switch(hapd, data->ch_switch.freq,
2621f05cddf9SRui Paulo data->ch_switch.ht_enabled,
26225b9c547cSRui Paulo data->ch_switch.ch_offset,
26235b9c547cSRui Paulo data->ch_switch.ch_width,
26245b9c547cSRui Paulo data->ch_switch.cf1,
2625206b73d0SCy Schubert data->ch_switch.cf2,
2626*a90b9d01SCy Schubert data->ch_switch.punct_bitmap,
2627206b73d0SCy Schubert event == EVENT_CH_SWITCH);
2628f05cddf9SRui Paulo break;
26295b9c547cSRui Paulo case EVENT_CONNECT_FAILED_REASON:
26305b9c547cSRui Paulo if (!data)
26315b9c547cSRui Paulo break;
26325b9c547cSRui Paulo hostapd_event_connect_failed_reason(
26335b9c547cSRui Paulo hapd, data->connect_failed_reason.addr,
26345b9c547cSRui Paulo data->connect_failed_reason.code);
26355b9c547cSRui Paulo break;
26365b9c547cSRui Paulo case EVENT_SURVEY:
2637780fb4a2SCy Schubert hostapd_event_get_survey(hapd->iface, &data->survey_results);
26385b9c547cSRui Paulo break;
26395b9c547cSRui Paulo #ifdef NEED_AP_MLME
26405b9c547cSRui Paulo case EVENT_INTERFACE_UNAVAILABLE:
26415b9c547cSRui Paulo hostapd_event_iface_unavailable(hapd);
26425b9c547cSRui Paulo break;
26435b9c547cSRui Paulo case EVENT_DFS_RADAR_DETECTED:
26445b9c547cSRui Paulo if (!data)
26455b9c547cSRui Paulo break;
2646*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
26475b9c547cSRui Paulo hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
26485b9c547cSRui Paulo break;
264985732ac8SCy Schubert case EVENT_DFS_PRE_CAC_EXPIRED:
265085732ac8SCy Schubert if (!data)
265185732ac8SCy Schubert break;
2652*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
265385732ac8SCy Schubert hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
265485732ac8SCy Schubert break;
26555b9c547cSRui Paulo case EVENT_DFS_CAC_FINISHED:
26565b9c547cSRui Paulo if (!data)
26575b9c547cSRui Paulo break;
2658*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
26595b9c547cSRui Paulo hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
26605b9c547cSRui Paulo break;
26615b9c547cSRui Paulo case EVENT_DFS_CAC_ABORTED:
26625b9c547cSRui Paulo if (!data)
26635b9c547cSRui Paulo break;
2664*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
26655b9c547cSRui Paulo hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
26665b9c547cSRui Paulo break;
26675b9c547cSRui Paulo case EVENT_DFS_NOP_FINISHED:
26685b9c547cSRui Paulo if (!data)
26695b9c547cSRui Paulo break;
2670*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
26715b9c547cSRui Paulo hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
26725b9c547cSRui Paulo break;
26735b9c547cSRui Paulo case EVENT_CHANNEL_LIST_CHANGED:
26745b9c547cSRui Paulo /* channel list changed (regulatory?), update channel list */
26755b9c547cSRui Paulo /* TODO: check this. hostapd_get_hw_features() initializes
26765b9c547cSRui Paulo * too much stuff. */
26775b9c547cSRui Paulo /* hostapd_get_hw_features(hapd->iface); */
26785b9c547cSRui Paulo hostapd_channel_list_updated(
26795b9c547cSRui Paulo hapd->iface, data->channel_list_changed.initiator);
26805b9c547cSRui Paulo break;
26815b9c547cSRui Paulo case EVENT_DFS_CAC_STARTED:
26825b9c547cSRui Paulo if (!data)
26835b9c547cSRui Paulo break;
2684*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
26855b9c547cSRui Paulo hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
26865b9c547cSRui Paulo break;
26875b9c547cSRui Paulo #endif /* NEED_AP_MLME */
26885b9c547cSRui Paulo case EVENT_INTERFACE_ENABLED:
26895b9c547cSRui Paulo wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
26905b9c547cSRui Paulo if (hapd->disabled && hapd->started) {
26915b9c547cSRui Paulo hapd->disabled = 0;
26925b9c547cSRui Paulo /*
26935b9c547cSRui Paulo * Try to re-enable interface if the driver stopped it
26945b9c547cSRui Paulo * when the interface got disabled.
26955b9c547cSRui Paulo */
269685732ac8SCy Schubert if (hapd->wpa_auth)
26975b9c547cSRui Paulo wpa_auth_reconfig_group_keys(hapd->wpa_auth);
269885732ac8SCy Schubert else
269985732ac8SCy Schubert hostapd_reconfig_encryption(hapd);
27005b9c547cSRui Paulo hapd->reenable_beacon = 1;
27015b9c547cSRui Paulo ieee802_11_set_beacon(hapd);
27024bc52338SCy Schubert #ifdef NEED_AP_MLME
27034bc52338SCy Schubert } else if (hapd->disabled && hapd->iface->cac_started) {
27044bc52338SCy Schubert wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC");
27054bc52338SCy Schubert hostapd_handle_dfs(hapd->iface);
27064bc52338SCy Schubert #endif /* NEED_AP_MLME */
27075b9c547cSRui Paulo }
27085b9c547cSRui Paulo break;
27095b9c547cSRui Paulo case EVENT_INTERFACE_DISABLED:
27105b9c547cSRui Paulo hostapd_free_stas(hapd);
27115b9c547cSRui Paulo wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
27125b9c547cSRui Paulo hapd->disabled = 1;
27135b9c547cSRui Paulo break;
27145b9c547cSRui Paulo #ifdef CONFIG_ACS
27155b9c547cSRui Paulo case EVENT_ACS_CHANNEL_SELECTED:
2716325151a3SRui Paulo hostapd_acs_channel_selected(hapd,
2717325151a3SRui Paulo &data->acs_selected_channels);
27185b9c547cSRui Paulo break;
27195b9c547cSRui Paulo #endif /* CONFIG_ACS */
272085732ac8SCy Schubert case EVENT_STATION_OPMODE_CHANGED:
272185732ac8SCy Schubert hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr,
272285732ac8SCy Schubert data->sta_opmode.smps_mode,
272385732ac8SCy Schubert data->sta_opmode.chan_width,
272485732ac8SCy Schubert data->sta_opmode.rx_nss);
272585732ac8SCy Schubert break;
272685732ac8SCy Schubert case EVENT_WDS_STA_INTERFACE_STATUS:
272785732ac8SCy Schubert hostapd_event_wds_sta_interface_status(
272885732ac8SCy Schubert hapd, data->wds_sta_interface.istatus,
272985732ac8SCy Schubert data->wds_sta_interface.ifname,
273085732ac8SCy Schubert data->wds_sta_interface.sta_addr);
273185732ac8SCy Schubert break;
2732*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211AX
2733*a90b9d01SCy Schubert case EVENT_BSS_COLOR_COLLISION:
2734*a90b9d01SCy Schubert /* The BSS color is shared amongst all BBSs on a specific phy.
2735*a90b9d01SCy Schubert * Therefore we always start the color change on the primary
2736*a90b9d01SCy Schubert * BSS. */
2737*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd,
2738*a90b9d01SCy Schubert data->bss_color_collision.link_id);
2739*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG, "BSS color collision on %s",
2740*a90b9d01SCy Schubert hapd->conf->iface);
2741*a90b9d01SCy Schubert hostapd_switch_color(hapd->iface->bss[0],
2742*a90b9d01SCy Schubert data->bss_color_collision.bitmap);
2743*a90b9d01SCy Schubert break;
2744*a90b9d01SCy Schubert case EVENT_CCA_STARTED_NOTIFY:
2745*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd,
2746*a90b9d01SCy Schubert data->bss_color_collision.link_id);
2747*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG, "CCA started on %s",
2748*a90b9d01SCy Schubert hapd->conf->iface);
2749*a90b9d01SCy Schubert break;
2750*a90b9d01SCy Schubert case EVENT_CCA_ABORTED_NOTIFY:
2751*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd,
2752*a90b9d01SCy Schubert data->bss_color_collision.link_id);
2753*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG, "CCA aborted on %s",
2754*a90b9d01SCy Schubert hapd->conf->iface);
2755*a90b9d01SCy Schubert hostapd_event_color_change(hapd, false);
2756*a90b9d01SCy Schubert break;
2757*a90b9d01SCy Schubert case EVENT_CCA_NOTIFY:
2758*a90b9d01SCy Schubert hapd = switch_link_hapd(hapd,
2759*a90b9d01SCy Schubert data->bss_color_collision.link_id);
2760*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG, "CCA finished on %s",
2761*a90b9d01SCy Schubert hapd->conf->iface);
2762*a90b9d01SCy Schubert hostapd_event_color_change(hapd, true);
2763*a90b9d01SCy Schubert break;
2764*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211AX */
2765e28a4053SRui Paulo default:
2766e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "Unknown event %d", event);
2767e28a4053SRui Paulo break;
2768e28a4053SRui Paulo }
2769e28a4053SRui Paulo }
2770e28a4053SRui Paulo
2771780fb4a2SCy Schubert
wpa_supplicant_event_global(void * ctx,enum wpa_event_type event,union wpa_event_data * data)2772780fb4a2SCy Schubert void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
2773780fb4a2SCy Schubert union wpa_event_data *data)
2774780fb4a2SCy Schubert {
2775780fb4a2SCy Schubert struct hapd_interfaces *interfaces = ctx;
2776780fb4a2SCy Schubert struct hostapd_data *hapd;
2777780fb4a2SCy Schubert
2778780fb4a2SCy Schubert if (event != EVENT_INTERFACE_STATUS)
2779780fb4a2SCy Schubert return;
2780780fb4a2SCy Schubert
2781780fb4a2SCy Schubert hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
2782780fb4a2SCy Schubert if (hapd && hapd->driver && hapd->driver->get_ifindex &&
2783780fb4a2SCy Schubert hapd->drv_priv) {
2784780fb4a2SCy Schubert unsigned int ifindex;
2785780fb4a2SCy Schubert
2786780fb4a2SCy Schubert ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
2787780fb4a2SCy Schubert if (ifindex != data->interface_status.ifindex) {
2788780fb4a2SCy Schubert wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
2789780fb4a2SCy Schubert "interface status ifindex %d mismatch (%d)",
2790780fb4a2SCy Schubert ifindex, data->interface_status.ifindex);
2791780fb4a2SCy Schubert return;
2792780fb4a2SCy Schubert }
2793780fb4a2SCy Schubert }
2794780fb4a2SCy Schubert if (hapd)
2795780fb4a2SCy Schubert wpa_supplicant_event(hapd, event, data);
2796780fb4a2SCy Schubert }
2797780fb4a2SCy Schubert
2798e28a4053SRui Paulo #endif /* HOSTAPD */
2799