blob: 533cc5402be48638c52f1d7635e9b2a52064ce0f [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Callback functions for driver wrappers
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003 * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070012#include "utils/eloop.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013#include "radius/radius.h"
14#include "drivers/driver.h"
15#include "common/ieee802_11_defs.h"
16#include "common/ieee802_11_common.h"
Dmitry Shmidtf8623282013-02-20 14:34:59 -080017#include "common/wpa_ctrl.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070018#include "common/dpp.h"
Hai Shalomc3565922019-10-28 11:58:20 -070019#include "common/sae.h"
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080020#include "common/hw_features_common.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070021#include "crypto/random.h"
22#include "p2p/p2p.h"
23#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080024#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070025#include "wnm_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070026#include "hostapd.h"
27#include "ieee802_11.h"
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080028#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070029#include "sta_info.h"
30#include "accounting.h"
31#include "tkip_countermeasures.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070032#include "ieee802_1x.h"
33#include "wpa_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070034#include "wps_hostapd.h"
35#include "ap_drv_ops.h"
36#include "ap_config.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070037#include "ap_mlme.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070038#include "hw_features.h"
Dmitry Shmidt051af732013-10-22 13:52:46 -070039#include "dfs.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070040#include "beacon.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080041#include "mbo_ap.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070042#include "dpp_hostapd.h"
43#include "fils_hlp.h"
Hai Shalom74f70d42019-02-11 14:42:39 -080044#include "neighbor_db.h"
Sunil Ravib0ac25f2024-07-12 01:42:03 +000045#include "nan_usd_ap.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070046
47
48#ifdef CONFIG_FILS
49void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd,
50 struct sta_info *sta)
51{
52 u16 reply_res = WLAN_STATUS_SUCCESS;
53 struct ieee802_11_elems elems;
54 u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf;
55 int new_assoc;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000056 bool updated;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070057
58 wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR,
59 __func__, MAC2STR(sta->addr));
60 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
61 if (!sta->fils_pending_assoc_req)
62 return;
63
Sunil Ravi2a14cf12023-11-21 00:54:38 +000064 if (ieee802_11_parse_elems(sta->fils_pending_assoc_req,
65 sta->fils_pending_assoc_req_len, &elems,
66 0) == ParseFailed ||
67 !elems.fils_session) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070068 wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element",
69 __func__);
70 return;
71 }
72
73 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
74 elems.fils_session,
75 sta->fils_hlp_resp);
76
77 reply_res = hostapd_sta_assoc(hapd, sta->addr,
78 sta->fils_pending_assoc_is_reassoc,
79 WLAN_STATUS_SUCCESS,
80 buf, p - buf);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000081 updated = ap_sta_set_authorized_flag(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070082 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
83 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
84 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
85 hostapd_set_sta_flags(hapd, sta);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000086 if (updated)
87 ap_sta_set_authorized_event(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070088 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
89 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
90 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
91 os_free(sta->fils_pending_assoc_req);
92 sta->fils_pending_assoc_req = NULL;
93 sta->fils_pending_assoc_req_len = 0;
94 wpabuf_free(sta->fils_hlp_resp);
95 sta->fils_hlp_resp = NULL;
96 wpabuf_free(sta->hlp_dhcp_discover);
97 sta->hlp_dhcp_discover = NULL;
98 fils_hlp_deinit(hapd);
99
100 /*
101 * Remove the station in case transmission of a success response fails
102 * (the STA was added associated to the driver) or if the station was
103 * previously added unassociated.
104 */
105 if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) {
106 hostapd_drv_sta_remove(hapd, sta->addr);
107 sta->added_unassoc = 0;
108 }
109}
110#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700111
112
Hai Shalom899fcc72020-10-19 14:38:18 -0700113static bool check_sa_query_need(struct hostapd_data *hapd, struct sta_info *sta)
114{
115 if ((sta->flags &
116 (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED)) !=
117 (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED))
118 return false;
119
120 if (!sta->sa_query_timed_out && sta->sa_query_count > 0)
121 ap_check_sa_query_timeout(hapd, sta);
122
123 if (!sta->sa_query_timed_out && (sta->auth_alg != WLAN_AUTH_FT)) {
124 /*
125 * STA has already been associated with MFP and SA Query timeout
126 * has not been reached. Reject the association attempt
127 * temporarily and start SA Query, if one is not pending.
128 */
129 if (sta->sa_query_count == 0)
130 ap_sta_start_sa_query(hapd, sta);
131
132 return true;
133 }
134
135 return false;
136}
137
138
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000139#ifdef CONFIG_IEEE80211BE
140static int hostapd_update_sta_links_status(struct hostapd_data *hapd,
141 struct sta_info *sta,
142 const u8 *resp_ies,
143 size_t resp_ies_len)
144{
145 struct mld_info *info = &sta->mld_info;
146 struct wpabuf *mlebuf;
147 const u8 *mle, *pos;
148 struct ieee802_11_elems elems;
149 size_t mle_len, rem_len;
150 int ret = 0;
151
152 if (!resp_ies) {
153 wpa_printf(MSG_DEBUG,
154 "MLO: (Re)Association Response frame elements not available");
155 return -1;
156 }
157
158 if (ieee802_11_parse_elems(resp_ies, resp_ies_len, &elems, 0) ==
159 ParseFailed) {
160 wpa_printf(MSG_DEBUG,
161 "MLO: Failed to parse (Re)Association Response frame elements");
162 return -1;
163 }
164
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000165 mlebuf = ieee802_11_defrag(elems.basic_mle, elems.basic_mle_len, true);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000166 if (!mlebuf) {
167 wpa_printf(MSG_ERROR,
168 "MLO: Basic Multi-Link element not found in (Re)Association Response frame");
169 return -1;
170 }
171
172 mle = wpabuf_head(mlebuf);
173 mle_len = wpabuf_len(mlebuf);
174 if (mle_len < MULTI_LINK_CONTROL_LEN + 1 ||
175 mle_len - MULTI_LINK_CONTROL_LEN < mle[MULTI_LINK_CONTROL_LEN]) {
176 wpa_printf(MSG_ERROR,
177 "MLO: Invalid Multi-Link element in (Re)Association Response frame");
178 ret = -1;
179 goto out;
180 }
181
182 /* Skip Common Info */
183 pos = mle + MULTI_LINK_CONTROL_LEN + mle[MULTI_LINK_CONTROL_LEN];
184 rem_len = mle_len -
185 (MULTI_LINK_CONTROL_LEN + mle[MULTI_LINK_CONTROL_LEN]);
186
187 /* Parse Subelements */
188 while (rem_len > 2) {
189 size_t ie_len = 2 + pos[1];
190
191 if (rem_len < ie_len)
192 break;
193
194 if (pos[0] == MULTI_LINK_SUB_ELEM_ID_PER_STA_PROFILE) {
195 u8 link_id;
196 const u8 *sta_profile;
197 size_t sta_profile_len;
198 u16 sta_ctrl;
199
200 if (pos[1] < BASIC_MLE_STA_CTRL_LEN + 1) {
201 wpa_printf(MSG_DEBUG,
202 "MLO: Invalid per-STA profile IE");
203 goto next_subelem;
204 }
205
206 sta_profile_len = pos[1];
207 sta_profile = &pos[2];
208 sta_ctrl = WPA_GET_LE16(sta_profile);
209 link_id = sta_ctrl & BASIC_MLE_STA_CTRL_LINK_ID_MASK;
210 if (link_id >= MAX_NUM_MLD_LINKS) {
211 wpa_printf(MSG_DEBUG,
212 "MLO: Invalid link ID in per-STA profile IE");
213 goto next_subelem;
214 }
215
216 /* Skip STA Control and STA Info */
217 if (sta_profile_len - BASIC_MLE_STA_CTRL_LEN <
218 sta_profile[BASIC_MLE_STA_CTRL_LEN]) {
219 wpa_printf(MSG_DEBUG,
220 "MLO: Invalid STA info in per-STA profile IE");
221 goto next_subelem;
222 }
223
224 sta_profile_len = sta_profile_len -
225 (BASIC_MLE_STA_CTRL_LEN +
226 sta_profile[BASIC_MLE_STA_CTRL_LEN]);
227 sta_profile = sta_profile + BASIC_MLE_STA_CTRL_LEN +
228 sta_profile[BASIC_MLE_STA_CTRL_LEN];
229
230 /* Skip Capabilities Information field */
231 if (sta_profile_len < 2)
232 goto next_subelem;
233 sta_profile_len -= 2;
234 sta_profile += 2;
235
236 /* Get status of the link */
237 info->links[link_id].status = WPA_GET_LE16(sta_profile);
238 }
239next_subelem:
240 pos += ie_len;
241 rem_len -= ie_len;
242 }
243
244out:
245 wpabuf_free(mlebuf);
246 return ret;
247}
248#endif /* CONFIG_IEEE80211BE */
249
250
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700251int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000252 const u8 *req_ies, size_t req_ies_len,
253 const u8 *resp_ies, size_t resp_ies_len,
254 const u8 *link_addr, int reassoc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700255{
256 struct sta_info *sta;
Hai Shalomfdcde762020-04-02 11:19:20 -0700257 int new_assoc;
258 enum wpa_validate_result res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700259 struct ieee802_11_elems elems;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800260 const u8 *ie;
261 size_t ielen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700262 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
263 u8 *p = buf;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800264 u16 reason = WLAN_REASON_UNSPECIFIED;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700265 int status = WLAN_STATUS_SUCCESS;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700266 const u8 *p2p_dev_addr = NULL;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000267#ifdef CONFIG_OWE
268 struct hostapd_iface *iface = hapd->iface;
269#endif /* CONFIG_OWE */
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000270 bool updated = false;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271
272 if (addr == NULL) {
273 /*
274 * This could potentially happen with unexpected event from the
275 * driver wrapper. This was seen at least in one case where the
276 * driver ended up being set to station mode while hostapd was
277 * running, so better make sure we stop processing such an
278 * event here.
279 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800280 wpa_printf(MSG_DEBUG,
281 "hostapd_notif_assoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700282 return -1;
283 }
Hai Shalomc3565922019-10-28 11:58:20 -0700284
285 if (is_multicast_ether_addr(addr) ||
286 is_zero_ether_addr(addr) ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000287 ether_addr_equal(addr, hapd->own_addr)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700288 /* Do not process any frames with unexpected/invalid SA so that
289 * we do not add any state for unexpected STA addresses or end
290 * up sending out frames to unexpected destination. */
291 wpa_printf(MSG_DEBUG, "%s: Invalid SA=" MACSTR
292 " in received indication - ignore this indication silently",
293 __func__, MAC2STR(addr));
294 return 0;
295 }
296
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700297 random_add_randomness(addr, ETH_ALEN);
298
299 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
300 HOSTAPD_LEVEL_INFO, "associated");
301
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000302 if (ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0) ==
303 ParseFailed) {
304 wpa_printf(MSG_DEBUG, "%s: Could not parse elements", __func__);
305 return -1;
306 }
307
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700308 if (elems.wps_ie) {
309 ie = elems.wps_ie - 2;
310 ielen = elems.wps_ie_len + 2;
311 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
312 } else if (elems.rsn_ie) {
313 ie = elems.rsn_ie - 2;
314 ielen = elems.rsn_ie_len + 2;
315 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
316 } else if (elems.wpa_ie) {
317 ie = elems.wpa_ie - 2;
318 ielen = elems.wpa_ie_len + 2;
319 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800320#ifdef CONFIG_HS20
321 } else if (elems.osen) {
322 ie = elems.osen - 2;
323 ielen = elems.osen_len + 2;
324 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
325#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700326 } else {
327 ie = NULL;
328 ielen = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800329 wpa_printf(MSG_DEBUG,
330 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700331 }
332
333 sta = ap_get_sta(hapd, addr);
334 if (sta) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700335 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336 accounting_sta_stop(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700337
338 /*
339 * Make sure that the previously registered inactivity timer
340 * will not remove the STA immediately.
341 */
342 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700343 } else {
344 sta = ap_sta_add(hapd, addr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700345 if (sta == NULL) {
346 hostapd_drv_sta_disassoc(hapd, addr,
347 WLAN_REASON_DISASSOC_AP_BUSY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700348 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700349 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700350 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000351
352 if (hapd->conf->wpa && check_sa_query_need(hapd, sta)) {
353 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
354 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
355 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
356
357 return 0;
358 }
359
360#ifdef CONFIG_IEEE80211BE
361 if (link_addr) {
362 struct mld_info *info = &sta->mld_info;
363 int i, num_valid_links = 0;
364 u8 link_id = hapd->mld_link_id;
365
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000366 ap_sta_set_mld(sta, true);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000367 sta->mld_assoc_link_id = link_id;
368 os_memcpy(info->common_info.mld_addr, addr, ETH_ALEN);
369 info->links[link_id].valid = true;
370 os_memcpy(info->links[link_id].peer_addr, link_addr, ETH_ALEN);
371 os_memcpy(info->links[link_id].local_addr, hapd->own_addr,
372 ETH_ALEN);
373
374 if (!elems.basic_mle ||
375 hostapd_process_ml_assoc_req(hapd, &elems, sta) !=
376 WLAN_STATUS_SUCCESS) {
377 reason = WLAN_REASON_UNSPECIFIED;
378 wpa_printf(MSG_DEBUG,
379 "Failed to get STA non-assoc links info");
380 goto fail;
381 }
382
383 for (i = 0 ; i < MAX_NUM_MLD_LINKS; i++) {
384 if (info->links[i].valid)
385 num_valid_links++;
386 }
387 if (num_valid_links > 1 &&
388 hostapd_update_sta_links_status(hapd, sta, resp_ies,
389 resp_ies_len)) {
390 wpa_printf(MSG_DEBUG,
391 "Failed to get STA non-assoc links status info");
392 reason = WLAN_REASON_UNSPECIFIED;
393 goto fail;
394 }
395 }
396#endif /* CONFIG_IEEE80211BE */
397
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800398 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700399
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700400 /*
401 * ACL configurations to the drivers (implementing AP SME and ACL
402 * offload) without hostapd's knowledge, can result in a disconnection
403 * though the driver accepts the connection. Skip the hostapd check for
404 * ACL if the driver supports ACL offload to avoid potentially
405 * conflicting ACL rules.
406 */
407 if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
408 hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800409 wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
410 MAC2STR(addr));
411 reason = WLAN_REASON_UNSPECIFIED;
412 goto fail;
413 }
414
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700415#ifdef CONFIG_P2P
416 if (elems.p2p) {
417 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800418 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700419 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700420 if (sta->p2p_ie)
421 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700422 }
423#endif /* CONFIG_P2P */
424
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700425#ifdef NEED_AP_MLME
426 if (elems.ht_capabilities &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700427 (hapd->iface->conf->ht_capab &
428 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
429 struct ieee80211_ht_capabilities *ht_cap =
430 (struct ieee80211_ht_capabilities *)
431 elems.ht_capabilities;
432
433 if (le_to_host16(ht_cap->ht_capabilities_info) &
434 HT_CAP_INFO_40MHZ_INTOLERANT)
435 ht40_intolerant_add(hapd->iface, sta);
436 }
437#endif /* NEED_AP_MLME */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700438
Sunil Ravia04bd252022-05-02 22:54:18 -0700439 check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700440
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800441#ifdef CONFIG_HS20
442 wpabuf_free(sta->hs20_ie);
443 if (elems.hs20 && elems.hs20_len > 4) {
444 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
445 elems.hs20_len - 4);
446 } else
447 sta->hs20_ie = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700448
449 wpabuf_free(sta->roaming_consortium);
450 if (elems.roaming_cons_sel)
451 sta->roaming_consortium = wpabuf_alloc_copy(
452 elems.roaming_cons_sel + 4,
453 elems.roaming_cons_sel_len - 4);
454 else
455 sta->roaming_consortium = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800456#endif /* CONFIG_HS20 */
457
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800458#ifdef CONFIG_FST
459 wpabuf_free(sta->mb_ies);
460 if (hapd->iface->fst)
461 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
462 else
463 sta->mb_ies = NULL;
464#endif /* CONFIG_FST */
465
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800466 mbo_ap_check_sta_assoc(hapd, sta, &elems);
467
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800468 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
469 elems.supp_op_classes_len);
470
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700471 if (hapd->conf->wpa) {
472 if (ie == NULL || ielen == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800473#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700474 if (hapd->conf->wps_state) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800475 wpa_printf(MSG_DEBUG,
476 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700477 sta->flags |= WLAN_STA_MAYBE_WPS;
478 goto skip_wpa_check;
479 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800480#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700481
482 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700483 reason = WLAN_REASON_INVALID_IE;
484 status = WLAN_STATUS_INVALID_IE;
485 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700486 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800487#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700488 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
489 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800490 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800491
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700492 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800493 wps = ieee802_11_vendor_ie_concat(ie, ielen,
494 WPS_IE_VENDOR_TYPE);
495 if (wps) {
496 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800497 wpa_printf(MSG_DEBUG,
498 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800499 sta->flags |= WLAN_STA_WPS2;
500 }
501 wpabuf_free(wps);
502 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700503 goto skip_wpa_check;
504 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800505#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700506
507 if (sta->wpa_sm == NULL)
508 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700509 sta->addr,
510 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700511 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800512 wpa_printf(MSG_ERROR,
513 "Failed to initialize WPA state machine");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700514 return -1;
515 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000516#ifdef CONFIG_IEEE80211BE
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000517 if (ap_sta_is_mld(hapd, sta)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000518 wpa_printf(MSG_DEBUG,
519 "MLD: Set ML info in RSN Authenticator");
Sunil Ravi88611412024-06-28 17:34:56 +0000520 wpa_auth_set_ml_info(sta->wpa_sm, hapd->mld_addr,
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000521 sta->mld_assoc_link_id,
522 &sta->mld_info);
523 }
524#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700525 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Hai Shalom021b0b52019-04-10 11:17:58 -0700526 hapd->iface->freq,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700527 ie, ielen,
Hai Shalomc3565922019-10-28 11:58:20 -0700528 elems.rsnxe ? elems.rsnxe - 2 : NULL,
529 elems.rsnxe ? elems.rsnxe_len + 2 : 0,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700530 elems.mdie, elems.mdie_len,
531 elems.owe_dh, elems.owe_dh_len);
Hai Shalomfdcde762020-04-02 11:19:20 -0700532 reason = WLAN_REASON_INVALID_IE;
533 status = WLAN_STATUS_INVALID_IE;
534 switch (res) {
535 case WPA_IE_OK:
536 reason = WLAN_REASON_UNSPECIFIED;
537 status = WLAN_STATUS_SUCCESS;
538 break;
539 case WPA_INVALID_IE:
540 reason = WLAN_REASON_INVALID_IE;
541 status = WLAN_STATUS_INVALID_IE;
542 break;
543 case WPA_INVALID_GROUP:
544 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
545 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
546 break;
547 case WPA_INVALID_PAIRWISE:
548 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
549 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
550 break;
551 case WPA_INVALID_AKMP:
552 reason = WLAN_REASON_AKMP_NOT_VALID;
553 status = WLAN_STATUS_AKMP_NOT_VALID;
554 break;
555 case WPA_NOT_ENABLED:
556 reason = WLAN_REASON_INVALID_IE;
557 status = WLAN_STATUS_INVALID_IE;
558 break;
559 case WPA_ALLOC_FAIL:
560 reason = WLAN_REASON_UNSPECIFIED;
561 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
562 break;
563 case WPA_MGMT_FRAME_PROTECTION_VIOLATION:
564 reason = WLAN_REASON_INVALID_IE;
565 status = WLAN_STATUS_INVALID_IE;
566 break;
567 case WPA_INVALID_MGMT_GROUP_CIPHER:
568 reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
569 status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
570 break;
571 case WPA_INVALID_MDIE:
572 reason = WLAN_REASON_INVALID_MDE;
573 status = WLAN_STATUS_INVALID_MDIE;
574 break;
575 case WPA_INVALID_PROTO:
576 reason = WLAN_REASON_INVALID_IE;
577 status = WLAN_STATUS_INVALID_IE;
578 break;
579 case WPA_INVALID_PMKID:
580 reason = WLAN_REASON_INVALID_PMKID;
581 status = WLAN_STATUS_INVALID_PMKID;
582 break;
583 case WPA_DENIED_OTHER_REASON:
584 reason = WLAN_REASON_UNSPECIFIED;
585 status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
586 break;
587 }
588 if (status != WLAN_STATUS_SUCCESS) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800589 wpa_printf(MSG_DEBUG,
590 "WPA/RSN information element rejected? (res %u)",
591 res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700592 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800593 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700594 }
Hai Shalomc3565922019-10-28 11:58:20 -0700595
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700596 if (wpa_auth_uses_mfp(sta->wpa_sm))
597 sta->flags |= WLAN_STA_MFP;
598 else
599 sta->flags &= ~WLAN_STA_MFP;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700600
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800601#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700602 if (sta->auth_alg == WLAN_AUTH_FT) {
603 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
604 req_ies_len);
605 if (status != WLAN_STATUS_SUCCESS) {
606 if (status == WLAN_STATUS_INVALID_PMKID)
607 reason = WLAN_REASON_INVALID_IE;
608 if (status == WLAN_STATUS_INVALID_MDIE)
609 reason = WLAN_REASON_INVALID_IE;
610 if (status == WLAN_STATUS_INVALID_FTIE)
611 reason = WLAN_REASON_INVALID_IE;
612 goto fail;
613 }
614 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800615#endif /* CONFIG_IEEE80211R_AP */
Hai Shalomc3565922019-10-28 11:58:20 -0700616#ifdef CONFIG_SAE
Sunil Ravi77d572f2023-01-17 23:58:31 +0000617 if (hapd->conf->sae_pwe == SAE_PWE_BOTH &&
Hai Shalomc3565922019-10-28 11:58:20 -0700618 sta->auth_alg == WLAN_AUTH_SAE &&
Hai Shalom899fcc72020-10-19 14:38:18 -0700619 sta->sae && !sta->sae->h2e &&
Hai Shaloma20dcd72022-02-04 13:43:00 -0800620 ieee802_11_rsnx_capab_len(elems.rsnxe, elems.rsnxe_len,
621 WLAN_RSNX_CAPAB_SAE_H2E)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700622 wpa_printf(MSG_INFO, "SAE: " MACSTR
623 " indicates support for SAE H2E, but did not use it",
624 MAC2STR(sta->addr));
625 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
626 reason = WLAN_REASON_UNSPECIFIED;
627 goto fail;
628 }
629#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700630 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800631#ifdef CONFIG_WPS
632 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800633
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800634 if (req_ies)
635 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700636 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800637 else
638 wps = NULL;
639#ifdef CONFIG_WPS_STRICT
640 if (wps && wps_validate_assoc_req(wps) < 0) {
641 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700642 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700643 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800644 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700645 }
646#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800647 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700648 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800649 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800650 wpa_printf(MSG_DEBUG,
651 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800652 sta->flags |= WLAN_STA_WPS2;
653 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700654 } else
655 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800656 wpabuf_free(wps);
657#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800658#ifdef CONFIG_HS20
659 } else if (hapd->conf->osen) {
660 if (elems.osen == NULL) {
661 hostapd_logger(
662 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
663 HOSTAPD_LEVEL_INFO,
664 "No HS 2.0 OSEN element in association request");
665 return WLAN_STATUS_INVALID_IE;
666 }
667
668 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
669 if (sta->wpa_sm == NULL)
670 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
671 sta->addr, NULL);
672 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800673 wpa_printf(MSG_WARNING,
674 "Failed to initialize WPA state machine");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800675 return WLAN_STATUS_UNSPECIFIED_FAILURE;
676 }
677 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
678 elems.osen - 2, elems.osen_len + 2) < 0)
679 return WLAN_STATUS_INVALID_IE;
680#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700681 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700682#ifdef CONFIG_WPS
683skip_wpa_check:
684#endif /* CONFIG_WPS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800685
686#ifdef CONFIG_MBO
687 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
688 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
689 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
690 wpa_printf(MSG_INFO,
691 "MBO: Reject WPA2 association without PMF");
692 return WLAN_STATUS_UNSPECIFIED_FAILURE;
693 }
694#endif /* CONFIG_MBO */
695
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800696#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700697 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
Hai Shalomfdcde762020-04-02 11:19:20 -0700698 sta->auth_alg, req_ies, req_ies_len,
699 !elems.rsnxe);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700700 if (!p) {
701 wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs");
702 return WLAN_STATUS_UNSPECIFIED_FAILURE;
703 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700704#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700705
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700706#ifdef CONFIG_FILS
707 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
708 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
709 sta->auth_alg == WLAN_AUTH_FILS_PK) {
710 int delay_assoc = 0;
711
712 if (!req_ies)
713 return WLAN_STATUS_UNSPECIFIED_FAILURE;
714
715 if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies,
716 req_ies_len,
717 sta->fils_session)) {
718 wpa_printf(MSG_DEBUG,
719 "FILS: Session validation failed");
720 return WLAN_STATUS_UNSPECIFIED_FAILURE;
721 }
722
723 res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies,
724 req_ies_len);
725 if (res < 0) {
726 wpa_printf(MSG_DEBUG,
727 "FILS: Key Confirm validation failed");
728 return WLAN_STATUS_UNSPECIFIED_FAILURE;
729 }
730
731 if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) {
732 wpa_printf(MSG_DEBUG,
733 "FILS: Delaying Assoc Response (HLP)");
734 delay_assoc = 1;
735 } else {
736 wpa_printf(MSG_DEBUG,
737 "FILS: Going ahead with Assoc Response (no HLP)");
738 }
739
740 if (sta) {
741 wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup");
742 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
743 os_free(sta->fils_pending_assoc_req);
744 sta->fils_pending_assoc_req = NULL;
745 sta->fils_pending_assoc_req_len = 0;
746 wpabuf_free(sta->fils_hlp_resp);
747 sta->fils_hlp_resp = NULL;
748 sta->fils_drv_assoc_finish = 0;
749 }
750
751 if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) {
752 u8 *req_tmp;
753
754 req_tmp = os_malloc(req_ies_len);
755 if (!req_tmp) {
756 wpa_printf(MSG_DEBUG,
757 "FILS: buffer allocation failed for assoc req");
758 goto fail;
759 }
760 os_memcpy(req_tmp, req_ies, req_ies_len);
761 sta->fils_pending_assoc_req = req_tmp;
762 sta->fils_pending_assoc_req_len = req_ies_len;
763 sta->fils_pending_assoc_is_reassoc = reassoc;
764 sta->fils_drv_assoc_finish = 1;
765 wpa_printf(MSG_DEBUG,
766 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
767 MACSTR, MAC2STR(sta->addr));
768 eloop_register_timeout(
769 0, hapd->conf->fils_hlp_wait_time * 1024,
770 fils_hlp_timeout, hapd, sta);
771 return 0;
772 }
773 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
774 elems.fils_session,
775 sta->fils_hlp_resp);
776 wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)",
777 buf, p - buf);
778 }
779#endif /* CONFIG_FILS */
780
Roshan Pius3a1667e2018-07-03 15:17:14 -0700781#ifdef CONFIG_OWE
782 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000783 !(iface->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_AP) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -0700784 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
785 elems.owe_dh) {
786 u8 *npos;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700787 u16 ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700788
789 npos = owe_assoc_req_process(hapd, sta,
790 elems.owe_dh, elems.owe_dh_len,
791 p, sizeof(buf) - (p - buf),
Hai Shalomb755a2a2020-04-23 21:49:02 -0700792 &ret_status);
793 status = ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700794 if (npos)
795 p = npos;
Hai Shalomfdcde762020-04-02 11:19:20 -0700796
Roshan Pius3a1667e2018-07-03 15:17:14 -0700797 if (!npos &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700798 status == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
Hai Shalomb755a2a2020-04-23 21:49:02 -0700799 hostapd_sta_assoc(hapd, addr, reassoc, ret_status, buf,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700800 p - buf);
801 return 0;
802 }
803
Hai Shalomfdcde762020-04-02 11:19:20 -0700804 if (!npos || status != WLAN_STATUS_SUCCESS)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700805 goto fail;
806 }
807#endif /* CONFIG_OWE */
808
Hai Shalom021b0b52019-04-10 11:17:58 -0700809#ifdef CONFIG_DPP2
810 dpp_pfs_free(sta->dpp_pfs);
811 sta->dpp_pfs = NULL;
812
813 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
814 hapd->conf->dpp_netaccesskey && sta->wpa_sm &&
815 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP &&
816 elems.owe_dh) {
817 sta->dpp_pfs = dpp_pfs_init(
818 wpabuf_head(hapd->conf->dpp_netaccesskey),
819 wpabuf_len(hapd->conf->dpp_netaccesskey));
820 if (!sta->dpp_pfs) {
821 wpa_printf(MSG_DEBUG,
822 "DPP: Could not initialize PFS");
823 /* Try to continue without PFS */
824 goto pfs_fail;
825 }
826
827 if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh,
828 elems.owe_dh_len) < 0) {
829 dpp_pfs_free(sta->dpp_pfs);
830 sta->dpp_pfs = NULL;
831 reason = WLAN_REASON_UNSPECIFIED;
832 goto fail;
833 }
834 }
835
836 wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ?
837 sta->dpp_pfs->secret : NULL);
838 pfs_fail:
839#endif /* CONFIG_DPP2 */
840
Hai Shalomfdcde762020-04-02 11:19:20 -0700841 if (elems.rrm_enabled &&
842 elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
843 os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
844 sizeof(sta->rrm_enabled_capa));
845
Roshan Pius3a1667e2018-07-03 15:17:14 -0700846#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700847 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700848
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700849 if (sta->auth_alg == WLAN_AUTH_FT ||
850 sta->auth_alg == WLAN_AUTH_FILS_SK ||
851 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
852 sta->auth_alg == WLAN_AUTH_FILS_PK)
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000853 updated = ap_sta_set_authorized_flag(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700854#else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700855 /* Keep compiler silent about unused variables */
856 if (status) {
857 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700858#endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700859
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000860#ifdef CONFIG_IEEE80211BE
861 if (hostapd_process_assoc_ml_info(hapd, sta, req_ies, req_ies_len,
862 !!reassoc, WLAN_STATUS_SUCCESS,
863 true)) {
864 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
865 reason = WLAN_REASON_UNSPECIFIED;
866 goto fail;
867 }
868#endif /* CONFIG_IEEE80211BE */
869
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700870 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
871 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800872 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700873
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700874 hostapd_set_sta_flags(hapd, sta);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000875 if (updated)
876 ap_sta_set_authorized_event(hapd, sta, 1);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700877
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700878 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
879 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700880#ifdef CONFIG_FILS
881 else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
882 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
883 sta->auth_alg == WLAN_AUTH_FILS_PK)
884 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
885#endif /* CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700886 else
887 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700888
889 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
890
891 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
892
893#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800894 if (req_ies) {
895 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
896 req_ies, req_ies_len);
897 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700898#endif /* CONFIG_P2P */
899
900 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800901
902fail:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800903#ifdef CONFIG_IEEE80211R_AP
Hai Shalomb755a2a2020-04-23 21:49:02 -0700904 if (status >= 0)
905 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800906#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800907 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
908 ap_free_sta(hapd, sta);
909 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700910}
911
912
913void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
914{
915 struct sta_info *sta;
916
917 if (addr == NULL) {
918 /*
919 * This could potentially happen with unexpected event from the
920 * driver wrapper. This was seen at least in one case where the
921 * driver ended up reporting a station mode event while hostapd
922 * was running, so better make sure we stop processing such an
923 * event here.
924 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800925 wpa_printf(MSG_DEBUG,
926 "hostapd_notif_disassoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700927 return;
928 }
929
930 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
931 HOSTAPD_LEVEL_INFO, "disassociated");
932
933 sta = ap_get_sta(hapd, addr);
934 if (sta == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800935 wpa_printf(MSG_DEBUG,
936 "Disassociation notification for unknown STA "
937 MACSTR, MAC2STR(addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700938 return;
939 }
940
Sunil Ravi88611412024-06-28 17:34:56 +0000941 ap_sta_set_authorized(hapd, sta, 0);
942 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
943 hostapd_set_sta_flags(hapd, sta);
944 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
945 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
946 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
947 ap_free_sta(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700948}
949
950
951void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
952{
953 struct sta_info *sta = ap_get_sta(hapd, addr);
954
Roshan Pius3a1667e2018-07-03 15:17:14 -0700955 if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700956 return;
957
958 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800959 HOSTAPD_LEVEL_INFO,
960 "disconnected due to excessive missing ACKs");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700961 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800962 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700963}
964
965
Roshan Pius3a1667e2018-07-03 15:17:14 -0700966void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr,
967 enum smps_mode smps_mode,
968 enum chan_width chan_width, u8 rx_nss)
969{
970 struct sta_info *sta = ap_get_sta(hapd, addr);
971 const char *txt;
972
973 if (!sta)
974 return;
975
976 switch (smps_mode) {
977 case SMPS_AUTOMATIC:
978 txt = "automatic";
979 break;
980 case SMPS_OFF:
981 txt = "off";
982 break;
983 case SMPS_DYNAMIC:
984 txt = "dynamic";
985 break;
986 case SMPS_STATIC:
987 txt = "static";
988 break;
989 default:
990 txt = NULL;
991 break;
992 }
993 if (txt) {
994 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED
995 MACSTR " %s", MAC2STR(addr), txt);
996 }
997
998 switch (chan_width) {
999 case CHAN_WIDTH_20_NOHT:
1000 txt = "20(no-HT)";
1001 break;
1002 case CHAN_WIDTH_20:
1003 txt = "20";
1004 break;
1005 case CHAN_WIDTH_40:
1006 txt = "40";
1007 break;
1008 case CHAN_WIDTH_80:
1009 txt = "80";
1010 break;
1011 case CHAN_WIDTH_80P80:
1012 txt = "80+80";
1013 break;
1014 case CHAN_WIDTH_160:
1015 txt = "160";
1016 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001017 case CHAN_WIDTH_320:
1018 txt = "320";
1019 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001020 default:
1021 txt = NULL;
1022 break;
1023 }
1024 if (txt) {
1025 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED
1026 MACSTR " %s", MAC2STR(addr), txt);
1027 }
1028
1029 if (rx_nss != 0xff) {
1030 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED
1031 MACSTR " %d", MAC2STR(addr), rx_nss);
1032 }
1033}
1034
1035
Dmitry Shmidt04949592012-07-19 12:16:46 -07001036void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001037 int offset, int width, int cf1, int cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07001038 u16 punct_bitmap, int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001039{
1040#ifdef NEED_AP_MLME
Sunil Ravi77d572f2023-01-17 23:58:31 +00001041 int channel, chwidth, is_dfs0, is_dfs;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001042 u8 seg0_idx = 0, seg1_idx = 0, op_class, chan_no;
Hai Shalom74f70d42019-02-11 14:42:39 -08001043 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001044
1045 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001046 HOSTAPD_LEVEL_INFO,
Sunil Ravi036cec52023-03-29 11:35:17 -07001047 "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",
Hai Shalom81f62d82019-07-22 12:10:00 -07001048 finished ? "had" : "starting",
Sunil Ravi77d572f2023-01-17 23:58:31 +00001049 hapd->iface->freq,
Hai Shalom60840252021-02-19 19:02:11 -08001050 freq, ht, hapd->iconf->ch_switch_vht_config,
Sunil Ravia04bd252022-05-02 22:54:18 -07001051 hapd->iconf->ch_switch_he_config,
1052 hapd->iconf->ch_switch_eht_config, offset,
Sunil Ravi036cec52023-03-29 11:35:17 -07001053 width, channel_width_to_string(width), cf1, cf2,
1054 punct_bitmap);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001055
Hai Shalom1dc4d202019-04-29 16:22:27 -07001056 if (!hapd->iface->current_mode) {
1057 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1058 HOSTAPD_LEVEL_WARNING,
1059 "ignore channel switch since the interface is not yet ready");
1060 return;
1061 }
1062
Sunil Ravi77d572f2023-01-17 23:58:31 +00001063 /* Check if any of configured channels require DFS */
1064 is_dfs0 = hostapd_is_dfs_required(hapd->iface);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001065 hapd->iface->freq = freq;
1066
1067 channel = hostapd_hw_get_channel(hapd, freq);
1068 if (!channel) {
1069 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001070 HOSTAPD_LEVEL_WARNING,
1071 "driver switched to bad channel!");
Dmitry Shmidt04949592012-07-19 12:16:46 -07001072 return;
1073 }
1074
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001075 switch (width) {
1076 case CHAN_WIDTH_80:
Sunil8cd6f4d2022-06-28 18:40:46 +00001077 chwidth = CONF_OPER_CHWIDTH_80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001078 break;
1079 case CHAN_WIDTH_80P80:
Sunil8cd6f4d2022-06-28 18:40:46 +00001080 chwidth = CONF_OPER_CHWIDTH_80P80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001081 break;
1082 case CHAN_WIDTH_160:
Sunil8cd6f4d2022-06-28 18:40:46 +00001083 chwidth = CONF_OPER_CHWIDTH_160MHZ;
1084 break;
1085 case CHAN_WIDTH_320:
1086 chwidth = CONF_OPER_CHWIDTH_320MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001087 break;
1088 case CHAN_WIDTH_20_NOHT:
1089 case CHAN_WIDTH_20:
1090 case CHAN_WIDTH_40:
1091 default:
Sunil8cd6f4d2022-06-28 18:40:46 +00001092 chwidth = CONF_OPER_CHWIDTH_USE_HT;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001093 break;
1094 }
1095
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001096 /* The operating channel changed when CSA finished, so need to update
1097 * hw_mode for all following operations to cover the cases where the
1098 * driver changed the operating band. */
1099 if (finished && hostapd_csa_update_hwmode(hapd->iface))
1100 return;
1101
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001102 switch (hapd->iface->current_mode->mode) {
1103 case HOSTAPD_MODE_IEEE80211A:
Hai Shalom899fcc72020-10-19 14:38:18 -07001104 if (cf1 == 5935)
1105 seg0_idx = (cf1 - 5925) / 5;
1106 else if (cf1 > 5950)
1107 seg0_idx = (cf1 - 5950) / 5;
1108 else if (cf1 > 5000)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001109 seg0_idx = (cf1 - 5000) / 5;
Hai Shalom899fcc72020-10-19 14:38:18 -07001110
1111 if (cf2 == 5935)
1112 seg1_idx = (cf2 - 5925) / 5;
1113 else if (cf2 > 5950)
1114 seg1_idx = (cf2 - 5950) / 5;
1115 else if (cf2 > 5000)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001116 seg1_idx = (cf2 - 5000) / 5;
1117 break;
1118 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001119 ieee80211_freq_to_chan(cf1, &seg0_idx);
1120 ieee80211_freq_to_chan(cf2, &seg1_idx);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001121 break;
1122 }
1123
Dmitry Shmidt04949592012-07-19 12:16:46 -07001124 hapd->iconf->channel = channel;
1125 hapd->iconf->ieee80211n = ht;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001126 if (!ht)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001127 hapd->iconf->ieee80211ac = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001128 if (hapd->iconf->ch_switch_vht_config) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001129 /* CHAN_SWITCH VHT config */
1130 if (hapd->iconf->ch_switch_vht_config &
1131 CH_SWITCH_VHT_ENABLED)
1132 hapd->iconf->ieee80211ac = 1;
1133 else if (hapd->iconf->ch_switch_vht_config &
1134 CH_SWITCH_VHT_DISABLED)
1135 hapd->iconf->ieee80211ac = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001136 }
1137 if (hapd->iconf->ch_switch_he_config) {
Hai Shalom60840252021-02-19 19:02:11 -08001138 /* CHAN_SWITCH HE config */
1139 if (hapd->iconf->ch_switch_he_config &
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001140 CH_SWITCH_HE_ENABLED) {
Hai Shalom60840252021-02-19 19:02:11 -08001141 hapd->iconf->ieee80211ax = 1;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001142 if (hapd->iface->freq > 4000 &&
1143 hapd->iface->freq < 5895)
1144 hapd->iconf->ieee80211ac = 1;
1145 }
Hai Shalom60840252021-02-19 19:02:11 -08001146 else if (hapd->iconf->ch_switch_he_config &
1147 CH_SWITCH_HE_DISABLED)
1148 hapd->iconf->ieee80211ax = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001149 }
Sunil Ravia04bd252022-05-02 22:54:18 -07001150#ifdef CONFIG_IEEE80211BE
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001151 if (hapd->iconf->ch_switch_eht_config) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001152 /* CHAN_SWITCH EHT config */
1153 if (hapd->iconf->ch_switch_eht_config &
1154 CH_SWITCH_EHT_ENABLED) {
1155 hapd->iconf->ieee80211be = 1;
1156 hapd->iconf->ieee80211ax = 1;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001157 if (!is_6ghz_freq(hapd->iface->freq) &&
1158 hapd->iface->freq > 4000)
Sunil Ravia04bd252022-05-02 22:54:18 -07001159 hapd->iconf->ieee80211ac = 1;
1160 } else if (hapd->iconf->ch_switch_eht_config &
1161 CH_SWITCH_EHT_DISABLED)
1162 hapd->iconf->ieee80211be = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001163 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001164#endif /* CONFIG_IEEE80211BE */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001165 hapd->iconf->ch_switch_vht_config = 0;
Hai Shalom60840252021-02-19 19:02:11 -08001166 hapd->iconf->ch_switch_he_config = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -07001167 hapd->iconf->ch_switch_eht_config = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001168
Hai Shaloma20dcd72022-02-04 13:43:00 -08001169 if (width == CHAN_WIDTH_40 || width == CHAN_WIDTH_80 ||
Sunil Ravi640215c2023-06-28 23:08:09 +00001170 width == CHAN_WIDTH_80P80 || width == CHAN_WIDTH_160 ||
1171 width == CHAN_WIDTH_320)
Hai Shaloma20dcd72022-02-04 13:43:00 -08001172 hapd->iconf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1173 else if (width == CHAN_WIDTH_20 || width == CHAN_WIDTH_20_NOHT)
1174 hapd->iconf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1175
Dmitry Shmidt04949592012-07-19 12:16:46 -07001176 hapd->iconf->secondary_channel = offset;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001177 if (ieee80211_freq_to_channel_ext(freq, offset, chwidth,
1178 &op_class, &chan_no) !=
1179 NUM_HOSTAPD_MODES)
1180 hapd->iconf->op_class = op_class;
Hai Shalom81f62d82019-07-22 12:10:00 -07001181 hostapd_set_oper_chwidth(hapd->iconf, chwidth);
1182 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, seg0_idx);
1183 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, seg1_idx);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001184 /* Auto-detect new bw320_offset */
1185 hostapd_set_and_check_bw320_offset(hapd->iconf, 0);
Sunil Ravi036cec52023-03-29 11:35:17 -07001186#ifdef CONFIG_IEEE80211BE
1187 hapd->iconf->punct_bitmap = punct_bitmap;
1188#endif /* CONFIG_IEEE80211BE */
Hai Shaloma20dcd72022-02-04 13:43:00 -08001189 if (hapd->iconf->ieee80211ac) {
1190 hapd->iconf->vht_capab &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
Sunil8cd6f4d2022-06-28 18:40:46 +00001191 if (chwidth == CONF_OPER_CHWIDTH_160MHZ)
Hai Shaloma20dcd72022-02-04 13:43:00 -08001192 hapd->iconf->vht_capab |=
1193 VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Sunil8cd6f4d2022-06-28 18:40:46 +00001194 else if (chwidth == CONF_OPER_CHWIDTH_80P80MHZ)
Hai Shaloma20dcd72022-02-04 13:43:00 -08001195 hapd->iconf->vht_capab |=
1196 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1197 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001198
Roshan Pius3a1667e2018-07-03 15:17:14 -07001199 is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features,
1200 hapd->iface->num_hw_features);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001201
Hai Shalom81f62d82019-07-22 12:10:00 -07001202 wpa_msg(hapd->msg_ctx, MSG_INFO,
Sunil Ravi036cec52023-03-29 11:35:17 -07001203 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d is_dfs0=%d dfs=%d puncturing_bitmap=0x%04x",
Hai Shalom81f62d82019-07-22 12:10:00 -07001204 finished ? WPA_EVENT_CHANNEL_SWITCH :
1205 WPA_EVENT_CHANNEL_SWITCH_STARTED,
1206 freq, ht, offset, channel_width_to_string(width),
Sunil Ravi036cec52023-03-29 11:35:17 -07001207 cf1, cf2, is_dfs0, is_dfs, punct_bitmap);
Hai Shalom81f62d82019-07-22 12:10:00 -07001208 if (!finished)
1209 return;
1210
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001211 if (hapd->csa_in_progress &&
1212 freq == hapd->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001213 hostapd_cleanup_cs_params(hapd);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001214 ieee802_11_set_beacon(hapd);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001215
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001216 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
1217 "freq=%d dfs=%d", freq, is_dfs);
1218 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00001219 /* Complete AP configuration for the first bring up. */
1220 if (is_dfs0 > 0 &&
1221 hostapd_is_dfs_required(hapd->iface) <= 0 &&
1222 hapd->iface->state != HAPD_IFACE_ENABLED) {
1223 /* Fake a CAC start bit to skip setting channel */
1224 hapd->iface->cac_started = 1;
1225 hostapd_setup_interface_complete(hapd->iface, 0);
1226 }
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001227 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
1228 "freq=%d dfs=%d", freq, is_dfs);
Hai Shalomfdcde762020-04-02 11:19:20 -07001229 } else if (is_dfs &&
1230 hostapd_is_dfs_required(hapd->iface) &&
1231 !hostapd_is_dfs_chan_available(hapd->iface) &&
1232 !hapd->iface->cac_started) {
1233 hostapd_disable_iface(hapd->iface);
1234 hostapd_enable_iface(hapd->iface);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001235 }
Hai Shalom74f70d42019-02-11 14:42:39 -08001236
1237 for (i = 0; i < hapd->iface->num_bss; i++)
1238 hostapd_neighbor_set_own_report(hapd->iface->bss[i]);
Hai Shalom899fcc72020-10-19 14:38:18 -07001239
1240#ifdef CONFIG_OCV
Sunil Ravia04bd252022-05-02 22:54:18 -07001241 if (hapd->conf->ocv &&
1242 !(hapd->iface->drv_flags2 &
1243 WPA_DRIVER_FLAGS2_SA_QUERY_OFFLOAD_AP)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001244 struct sta_info *sta;
1245 bool check_sa_query = false;
1246
1247 for (sta = hapd->sta_list; sta; sta = sta->next) {
1248 if (wpa_auth_uses_ocv(sta->wpa_sm) &&
1249 !(sta->flags & WLAN_STA_WNM_SLEEP_MODE)) {
1250 sta->post_csa_sa_query = 1;
1251 check_sa_query = true;
1252 }
1253 }
1254
1255 if (check_sa_query) {
1256 wpa_printf(MSG_DEBUG,
1257 "OCV: Check post-CSA SA Query initiation in 15 seconds");
1258 eloop_register_timeout(15, 0,
1259 hostapd_ocv_check_csa_sa_query,
1260 hapd, NULL);
1261 }
1262 }
1263#endif /* CONFIG_OCV */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001264#endif /* NEED_AP_MLME */
1265}
1266
1267
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001268void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
1269 const u8 *addr, int reason_code)
1270{
1271 switch (reason_code) {
1272 case MAX_CLIENT_REACHED:
1273 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
1274 MAC2STR(addr));
1275 break;
1276 case BLOCKED_CLIENT:
1277 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
1278 MAC2STR(addr));
1279 break;
1280 }
1281}
1282
1283
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001284#ifdef CONFIG_ACS
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001285void hostapd_acs_channel_selected(struct hostapd_data *hapd,
1286 struct acs_selected_channels *acs_res)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001287{
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001288 int ret, i;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001289 int err = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001290 struct hostapd_channel_data *pri_chan;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001291
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001292#ifdef CONFIG_IEEE80211BE
1293 if (acs_res->link_id != -1) {
1294 hapd = hostapd_mld_get_link_bss(hapd, acs_res->link_id);
1295 if (!hapd) {
1296 wpa_printf(MSG_ERROR,
1297 "MLD: Failed to get link BSS for EVENT_ACS_CHANNEL_SELECTED link_id=%d",
1298 acs_res->link_id);
1299 return;
1300 }
1301 }
1302#endif /* CONFIG_IEEE80211BE */
1303
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001304 if (hapd->iconf->channel) {
1305 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
1306 hapd->iconf->channel);
1307 return;
1308 }
1309
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001310 hapd->iface->freq = acs_res->pri_freq;
1311
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001312 if (!hapd->iface->current_mode) {
1313 for (i = 0; i < hapd->iface->num_hw_features; i++) {
1314 struct hostapd_hw_modes *mode =
1315 &hapd->iface->hw_features[i];
1316
1317 if (mode->mode == acs_res->hw_mode) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001318 if (hapd->iface->freq > 0 &&
1319 !hw_get_chan(mode->mode,
1320 hapd->iface->freq,
1321 hapd->iface->hw_features,
1322 hapd->iface->num_hw_features))
1323 continue;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001324 hapd->iface->current_mode = mode;
1325 break;
1326 }
1327 }
1328 if (!hapd->iface->current_mode) {
1329 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1330 HOSTAPD_LEVEL_WARNING,
1331 "driver selected to bad hw_mode");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001332 err = 1;
1333 goto out;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001334 }
1335 }
1336
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001337 if (!acs_res->pri_freq) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001338 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1339 HOSTAPD_LEVEL_WARNING,
1340 "driver switched to bad channel");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001341 err = 1;
1342 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001343 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001344 pri_chan = hw_get_channel_freq(hapd->iface->current_mode->mode,
1345 acs_res->pri_freq, NULL,
1346 hapd->iface->hw_features,
1347 hapd->iface->num_hw_features);
1348 if (!pri_chan) {
1349 wpa_printf(MSG_ERROR,
1350 "ACS: Could not determine primary channel number from pri_freq %u",
1351 acs_res->pri_freq);
1352 err = 1;
1353 goto out;
1354 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001355
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001356 hapd->iconf->channel = pri_chan->chan;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001357 hapd->iconf->acs = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001358
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001359 if (acs_res->sec_freq == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001360 hapd->iconf->secondary_channel = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001361 else if (acs_res->sec_freq < acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001362 hapd->iconf->secondary_channel = -1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001363 else if (acs_res->sec_freq > acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001364 hapd->iconf->secondary_channel = 1;
1365 else {
1366 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001367 err = 1;
1368 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001369 }
1370
Hai Shalomfdcde762020-04-02 11:19:20 -07001371 hapd->iconf->edmg_channel = acs_res->edmg_channel;
1372
Hai Shalom81f62d82019-07-22 12:10:00 -07001373 if (hapd->iface->conf->ieee80211ac || hapd->iface->conf->ieee80211ax) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001374 /* set defaults for backwards compatibility */
Hai Shalom81f62d82019-07-22 12:10:00 -07001375 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1376 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, 0);
Sunil8cd6f4d2022-06-28 18:40:46 +00001377 hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_USE_HT);
Hai Shalomfdcde762020-04-02 11:19:20 -07001378 if (acs_res->ch_width == 40) {
1379 if (is_6ghz_freq(acs_res->pri_freq))
1380 hostapd_set_oper_centr_freq_seg0_idx(
1381 hapd->iconf,
1382 acs_res->vht_seg0_center_ch);
1383 } else if (acs_res->ch_width == 80) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001384 hostapd_set_oper_centr_freq_seg0_idx(
1385 hapd->iconf, acs_res->vht_seg0_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001386 if (acs_res->vht_seg1_center_ch == 0) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001387 hostapd_set_oper_chwidth(
1388 hapd->iconf, CONF_OPER_CHWIDTH_80MHZ);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001389 } else {
Sunil8cd6f4d2022-06-28 18:40:46 +00001390 hostapd_set_oper_chwidth(
1391 hapd->iconf,
1392 CONF_OPER_CHWIDTH_80P80MHZ);
Hai Shalom81f62d82019-07-22 12:10:00 -07001393 hostapd_set_oper_centr_freq_seg1_idx(
1394 hapd->iconf,
1395 acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001396 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001397 } else if (acs_res->ch_width == 160) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001398 hostapd_set_oper_chwidth(hapd->iconf,
1399 CONF_OPER_CHWIDTH_160MHZ);
Hai Shalomfdcde762020-04-02 11:19:20 -07001400 hostapd_set_oper_centr_freq_seg0_idx(
1401 hapd->iconf, acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001402 }
1403 }
1404
Sunil8cd6f4d2022-06-28 18:40:46 +00001405#ifdef CONFIG_IEEE80211BE
1406 if (hapd->iface->conf->ieee80211be && acs_res->ch_width == 320) {
1407 hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_320MHZ);
1408 hostapd_set_oper_centr_freq_seg0_idx(
1409 hapd->iconf, acs_res->vht_seg1_center_ch);
1410 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1411 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001412
1413 if (hapd->iface->conf->ieee80211be && acs_res->puncture_bitmap)
1414 hapd->iconf->punct_bitmap = acs_res->puncture_bitmap;
Sunil8cd6f4d2022-06-28 18:40:46 +00001415#endif /* CONFIG_IEEE80211BE */
1416
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001417out:
1418 ret = hostapd_acs_completed(hapd->iface, err);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001419 if (ret) {
1420 wpa_printf(MSG_ERROR,
1421 "ACS: Possibly channel configuration is invalid");
1422 }
1423}
1424#endif /* CONFIG_ACS */
1425
1426
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001427int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001428 const u8 *bssid, const u8 *ie, size_t ie_len,
1429 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001430{
1431 size_t i;
1432 int ret = 0;
1433
1434 if (sa == NULL || ie == NULL)
1435 return -1;
1436
1437 random_add_randomness(sa, ETH_ALEN);
1438 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
1439 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001440 sa, da, bssid, ie, ie_len,
1441 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001442 ret = 1;
1443 break;
1444 }
1445 }
1446 return ret;
1447}
1448
1449
1450#ifdef HOSTAPD
1451
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001452#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001453static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
1454 const u8 *bssid,
1455 u16 auth_transaction, u16 status,
1456 const u8 *ies, size_t ies_len)
1457{
1458 struct hostapd_data *hapd = ctx;
1459 struct sta_info *sta;
1460
1461 sta = ap_get_sta(hapd, dst);
1462 if (sta == NULL)
1463 return;
1464
1465 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
1466 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
1467 sta->flags |= WLAN_STA_AUTH;
1468
1469 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
1470}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001471#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001472
1473
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001474#ifdef CONFIG_FILS
1475static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
1476 struct sta_info *sta, u16 resp,
1477 struct wpabuf *data, int pub)
1478{
1479 if (resp == WLAN_STATUS_SUCCESS) {
1480 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1481 HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
1482 sta->flags |= WLAN_STA_AUTH;
1483 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1484 sta->auth_alg = WLAN_AUTH_FILS_SK;
1485 mlme_authenticate_indication(hapd, sta);
1486 } else {
1487 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1488 HOSTAPD_LEVEL_DEBUG,
1489 "authentication failed (FILS)");
1490 }
1491
1492 hostapd_sta_auth(hapd, sta->addr, 2, resp,
1493 data ? wpabuf_head(data) : NULL,
1494 data ? wpabuf_len(data) : 0);
1495 wpabuf_free(data);
1496}
1497#endif /* CONFIG_FILS */
1498
1499
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001500static void hostapd_notif_auth(struct hostapd_data *hapd,
1501 struct auth_info *rx_auth)
1502{
1503 struct sta_info *sta;
1504 u16 status = WLAN_STATUS_SUCCESS;
1505 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1506 size_t resp_ies_len = 0;
1507
1508 sta = ap_get_sta(hapd, rx_auth->peer);
1509 if (!sta) {
1510 sta = ap_sta_add(hapd, rx_auth->peer);
1511 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -07001512 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001513 goto fail;
1514 }
1515 }
1516 sta->flags &= ~WLAN_STA_PREAUTH;
1517 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001518#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001519 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
1520 sta->auth_alg = WLAN_AUTH_FT;
1521 if (sta->wpa_sm == NULL)
1522 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001523 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001524 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001525 wpa_printf(MSG_DEBUG,
1526 "FT: Failed to initialize WPA state machine");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001527 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1528 goto fail;
1529 }
1530 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
1531 rx_auth->auth_transaction, rx_auth->ies,
1532 rx_auth->ies_len,
1533 hostapd_notify_auth_ft_finish, hapd);
1534 return;
1535 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001536#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001537
1538#ifdef CONFIG_FILS
1539 if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
1540 sta->auth_alg = WLAN_AUTH_FILS_SK;
1541 handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
1542 rx_auth->auth_type, rx_auth->auth_transaction,
1543 rx_auth->status_code,
1544 hostapd_notify_auth_fils_finish);
1545 return;
1546 }
1547#endif /* CONFIG_FILS */
1548
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001549fail:
1550 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
1551 status, resp_ies, resp_ies_len);
1552}
1553
1554
Hai Shalom021b0b52019-04-10 11:17:58 -07001555#ifndef NEED_AP_MLME
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001556static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001557 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001558{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001559 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001560 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001561 size_t plen __maybe_unused;
1562 u16 fc;
Hai Shalom74f70d42019-02-11 14:42:39 -08001563 u8 *action __maybe_unused;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001564
Hai Shalom74f70d42019-02-11 14:42:39 -08001565 if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001566 return;
1567
Hai Shalom021b0b52019-04-10 11:17:58 -07001568 plen = drv_mgmt->frame_len - IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001569
1570 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
1571 fc = le_to_host16(mgmt->frame_control);
1572 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
1573 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001574
Hai Shalom74f70d42019-02-11 14:42:39 -08001575 action = (u8 *) &mgmt->u.action.u;
1576 wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
1577 " da " MACSTR " plen %d",
1578 mgmt->u.action.category, *action,
1579 MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001580
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001581 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001582 if (sta == NULL) {
1583 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
1584 return;
1585 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001586#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001587 if (mgmt->u.action.category == WLAN_ACTION_FT) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001588 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, plen);
1589 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001590 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001591#endif /* CONFIG_IEEE80211R_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001592 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001593 ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001594 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001595 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001596#ifdef CONFIG_WNM_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001597 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
1598 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001599 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001600 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001601#endif /* CONFIG_WNM_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001602#ifdef CONFIG_FST
1603 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
1604 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
1605 return;
1606 }
1607#endif /* CONFIG_FST */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001608#ifdef CONFIG_DPP
Hai Shalom021b0b52019-04-10 11:17:58 -07001609 if (plen >= 2 + 4 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001610 mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001611 mgmt->u.action.u.vs_public_action.action ==
1612 WLAN_PA_VENDOR_SPECIFIC &&
1613 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1614 OUI_WFA &&
1615 mgmt->u.action.u.vs_public_action.variable[0] ==
1616 DPP_OUI_TYPE) {
1617 const u8 *pos, *end;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001618
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001619 pos = mgmt->u.action.u.vs_public_action.oui;
1620 end = drv_mgmt->frame + drv_mgmt->frame_len;
1621 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
1622 drv_mgmt->freq);
1623 return;
1624 }
1625#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001626#ifdef CONFIG_NAN_USD
1627 if (mgmt->u.action.category == WLAN_ACTION_PUBLIC && plen >= 5 &&
1628 mgmt->u.action.u.vs_public_action.action ==
1629 WLAN_PA_VENDOR_SPECIFIC &&
1630 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1631 OUI_WFA &&
1632 mgmt->u.action.u.vs_public_action.variable[0] == NAN_OUI_TYPE) {
1633 const u8 *pos, *end;
1634
1635 pos = mgmt->u.action.u.vs_public_action.variable;
1636 end = drv_mgmt->frame + drv_mgmt->frame_len;
1637 pos++;
1638 hostapd_nan_usd_rx_sdf(hapd, mgmt->sa, drv_mgmt->freq,
1639 pos, end - pos);
1640 return;
1641 }
1642#endif /* CONFIG_NAN_USD */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001643}
Hai Shalom021b0b52019-04-10 11:17:58 -07001644#endif /* NEED_AP_MLME */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001645
1646
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001647#ifdef NEED_AP_MLME
1648
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001649static struct hostapd_data *
1650switch_link_hapd(struct hostapd_data *hapd, int link_id)
1651{
1652#ifdef CONFIG_IEEE80211BE
1653 if (hapd->conf->mld_ap && link_id >= 0) {
1654 struct hostapd_data *link_bss;
1655
1656 link_bss = hostapd_mld_get_link_bss(hapd, link_id);
1657 if (link_bss)
1658 return link_bss;
1659 }
1660#endif /* CONFIG_IEEE80211BE */
1661
1662 return hapd;
1663}
1664
1665
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001666#define HAPD_BROADCAST ((struct hostapd_data *) -1)
1667
1668static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
1669 const u8 *bssid)
1670{
1671 size_t i;
1672
1673 if (bssid == NULL)
1674 return NULL;
1675 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1676 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1677 return HAPD_BROADCAST;
1678
1679 for (i = 0; i < iface->num_bss; i++) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001680 if (ether_addr_equal(bssid, iface->bss[i]->own_addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001681 return iface->bss[i];
1682 }
1683
1684 return NULL;
1685}
1686
1687
1688static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001689 const u8 *bssid, const u8 *addr,
1690 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001691{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001692 hapd = get_hapd_bssid(hapd->iface, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001693 if (hapd == NULL || hapd == HAPD_BROADCAST)
1694 return;
1695
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001696 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001697}
1698
1699
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001700static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001701{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001702 struct hostapd_iface *iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001703 const struct ieee80211_hdr *hdr;
1704 const u8 *bssid;
1705 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001706 int ret;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001707 bool is_mld = false;
1708
1709 hapd = switch_link_hapd(hapd, rx_mgmt->link_id);
1710 iface = hapd->iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001711
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001712#ifdef CONFIG_TESTING_OPTIONS
1713 if (hapd->ext_mgmt_frame_handling) {
1714 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
1715 char *hex = os_malloc(hex_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001716
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001717 if (hex) {
1718 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
1719 rx_mgmt->frame_len);
1720 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1721 os_free(hex);
1722 }
1723 return 1;
1724 }
1725#endif /* CONFIG_TESTING_OPTIONS */
1726
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001727 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1728 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
1729 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001730 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001731
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001732#ifdef CONFIG_IEEE80211BE
1733 if (hapd->conf->mld_ap &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001734 ether_addr_equal(hapd->mld_addr, bssid))
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001735 is_mld = true;
1736#endif /* CONFIG_IEEE80211BE */
1737
1738 if (!is_mld)
1739 hapd = get_hapd_bssid(iface, bssid);
1740
1741 if (!hapd) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001742 u16 fc = le_to_host16(hdr->frame_control);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001743
1744 /*
1745 * Drop frames to unknown BSSIDs except for Beacon frames which
1746 * could be used to update neighbor information.
1747 */
1748 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1749 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1750 hapd = iface->bss[0];
1751 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001752 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001753 }
1754
1755 os_memset(&fi, 0, sizeof(fi));
Roshan Pius3a1667e2018-07-03 15:17:14 -07001756 fi.freq = rx_mgmt->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001757 fi.datarate = rx_mgmt->datarate;
1758 fi.ssi_signal = rx_mgmt->ssi_signal;
1759
1760 if (hapd == HAPD_BROADCAST) {
1761 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001762
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001763 ret = 0;
1764 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -07001765 /* if bss is set, driver will call this function for
1766 * each bss individually. */
1767 if (rx_mgmt->drv_priv &&
1768 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
1769 continue;
1770
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001771 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
1772 rx_mgmt->frame_len, &fi) > 0)
1773 ret = 1;
1774 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001775 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001776 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
1777 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001778
1779 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001780
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001781 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001782}
1783
1784
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001785static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001786 size_t len, u16 stype, int ok, int link_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001787{
1788 struct ieee80211_hdr *hdr;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001789 struct hostapd_data *orig_hapd, *tmp_hapd;
1790
1791#ifdef CONFIG_IEEE80211BE
1792 if (hapd->conf->mld_ap && link_id != -1) {
1793 tmp_hapd = hostapd_mld_get_link_bss(hapd, link_id);
1794 if (tmp_hapd)
1795 hapd = tmp_hapd;
1796 }
1797#endif /* CONFIG_IEEE80211BE */
1798 orig_hapd = hapd;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001799
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001800 hdr = (struct ieee80211_hdr *) buf;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001801 tmp_hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
1802 if (tmp_hapd) {
1803 hapd = tmp_hapd;
1804#ifdef CONFIG_IEEE80211BE
1805 } else if (hapd->conf->mld_ap &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001806 ether_addr_equal(hapd->mld_addr, get_hdr_bssid(hdr, len))) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001807 /* AP MLD address match - use hapd pointer as-is */
1808#endif /* CONFIG_IEEE80211BE */
1809 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001810 return;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001811 }
1812
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001813 if (hapd == HAPD_BROADCAST) {
1814 if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
1815 buf[24] != WLAN_ACTION_PUBLIC)
1816 return;
1817 hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2);
1818 if (!hapd || hapd == HAPD_BROADCAST)
1819 return;
1820 /*
1821 * Allow processing of TX status for a Public Action frame that
1822 * used wildcard BBSID.
1823 */
1824 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001825 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1826}
1827
1828#endif /* NEED_AP_MLME */
1829
1830
1831static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
1832{
1833 struct sta_info *sta = ap_get_sta(hapd, addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001834
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001835 if (sta)
1836 return 0;
1837
1838 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
1839 " - adding a new STA", MAC2STR(addr));
1840 sta = ap_sta_add(hapd, addr);
1841 if (sta) {
1842 hostapd_new_assoc_sta(hapd, sta, 0);
1843 } else {
1844 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
1845 MAC2STR(addr));
1846 return -1;
1847 }
1848
1849 return 0;
1850}
1851
1852
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001853static struct hostapd_data * hostapd_find_by_sta(struct hostapd_iface *iface,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001854 const u8 *src, bool rsn)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001855{
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001856 struct sta_info *sta;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001857 unsigned int j;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001858
1859 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001860 sta = ap_get_sta(iface->bss[j], src);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001861 if (sta && (sta->flags & WLAN_STA_ASSOC) &&
1862 (!rsn || sta->wpa_sm))
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001863 return iface->bss[j];
1864 }
1865
1866 return NULL;
1867}
1868
1869
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001870#ifdef CONFIG_IEEE80211BE
1871static bool search_mld_sta(struct hostapd_data **p_hapd, const u8 *src)
1872{
1873 struct hostapd_data *hapd = *p_hapd;
1874 unsigned int i;
1875
1876 /* Search for STA on other MLO BSSs */
1877 for (i = 0; i < hapd->iface->interfaces->count; i++) {
1878 struct hostapd_iface *h =
1879 hapd->iface->interfaces->iface[i];
1880 struct hostapd_data *h_hapd = h->bss[0];
1881 struct hostapd_bss_config *hconf = h_hapd->conf;
1882
1883 if (!hconf->mld_ap ||
1884 hconf->mld_id != hapd->conf->mld_id)
1885 continue;
1886
1887 h_hapd = hostapd_find_by_sta(h, src, false);
1888 if (h_hapd) {
1889 struct sta_info *sta = ap_get_sta(h_hapd, src);
1890
1891 if (sta && sta->mld_info.mld_sta &&
1892 sta->mld_assoc_link_id != h_hapd->mld_link_id)
1893 continue;
1894 *p_hapd = h_hapd;
1895 return true;
1896 }
1897 }
1898
1899 return false;
1900}
1901#endif /* CONFIG_IEEE80211BE */
1902
1903
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001904static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
1905 const u8 *data, size_t data_len,
1906 enum frame_encryption encrypted,
1907 int link_id)
1908{
1909 struct hostapd_data *orig_hapd = hapd;
1910
1911#ifdef CONFIG_IEEE80211BE
1912 if (link_id != -1) {
1913 struct hostapd_data *h_hapd;
1914
1915 hapd = switch_link_hapd(hapd, link_id);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001916 h_hapd = hostapd_find_by_sta(hapd->iface, src, true);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001917 if (!h_hapd)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001918 h_hapd = hostapd_find_by_sta(orig_hapd->iface, src,
1919 true);
1920 if (!h_hapd)
1921 h_hapd = hostapd_find_by_sta(hapd->iface, src, false);
1922 if (!h_hapd)
1923 h_hapd = hostapd_find_by_sta(orig_hapd->iface, src,
1924 false);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001925 if (h_hapd)
1926 hapd = h_hapd;
1927 } else if (hapd->conf->mld_ap) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001928 search_mld_sta(&hapd, src);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001929 } else {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001930 hapd = hostapd_find_by_sta(hapd->iface, src, false);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001931 }
1932#else /* CONFIG_IEEE80211BE */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001933 hapd = hostapd_find_by_sta(hapd->iface, src, false);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001934#endif /* CONFIG_IEEE80211BE */
1935
1936 if (!hapd) {
1937 /* WLAN cases need to have an existing association, but non-WLAN
1938 * cases (mainly, wired IEEE 802.1X) need to be able to process
1939 * EAPOL frames from new devices that do not yet have a STA
1940 * entry and as such, do not get a match in
1941 * hostapd_find_by_sta(). */
1942 wpa_printf(MSG_DEBUG,
1943 "No STA-specific hostapd instance for EAPOL RX found - fall back to initial context");
1944 hapd = orig_hapd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001945 }
1946
Sunil8cd6f4d2022-06-28 18:40:46 +00001947 ieee802_1x_receive(hapd, src, data, data_len, encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001948}
1949
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001950#endif /* HOSTAPD */
1951
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001952
Hai Shalomfdcde762020-04-02 11:19:20 -07001953static struct hostapd_channel_data *
1954hostapd_get_mode_chan(struct hostapd_hw_modes *mode, unsigned int freq)
1955{
1956 int i;
1957 struct hostapd_channel_data *chan;
1958
1959 for (i = 0; i < mode->num_channels; i++) {
1960 chan = &mode->channels[i];
1961 if ((unsigned int) chan->freq == freq)
1962 return chan;
1963 }
1964
1965 return NULL;
1966}
1967
1968
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001969static struct hostapd_channel_data * hostapd_get_mode_channel(
1970 struct hostapd_iface *iface, unsigned int freq)
1971{
1972 int i;
1973 struct hostapd_channel_data *chan;
1974
Hai Shalomfdcde762020-04-02 11:19:20 -07001975 for (i = 0; i < iface->num_hw_features; i++) {
1976 if (hostapd_hw_skip_mode(iface, &iface->hw_features[i]))
1977 continue;
1978 chan = hostapd_get_mode_chan(&iface->hw_features[i], freq);
1979 if (chan)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001980 return chan;
1981 }
1982
1983 return NULL;
1984}
1985
1986
1987static void hostapd_update_nf(struct hostapd_iface *iface,
1988 struct hostapd_channel_data *chan,
1989 struct freq_survey *survey)
1990{
1991 if (!iface->chans_surveyed) {
1992 chan->min_nf = survey->nf;
1993 iface->lowest_nf = survey->nf;
1994 } else {
1995 if (dl_list_empty(&chan->survey_list))
1996 chan->min_nf = survey->nf;
1997 else if (survey->nf < chan->min_nf)
1998 chan->min_nf = survey->nf;
1999 if (survey->nf < iface->lowest_nf)
2000 iface->lowest_nf = survey->nf;
2001 }
2002}
2003
2004
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002005static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
2006 struct survey_results *survey_res)
2007{
2008 struct hostapd_channel_data *chan;
2009 struct freq_survey *survey;
2010 u64 divisor, dividend;
2011
2012 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
2013 list);
2014 if (!survey || !survey->freq)
2015 return;
2016
2017 chan = hostapd_get_mode_channel(iface, survey->freq);
2018 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
2019 return;
2020
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002021 wpa_printf(MSG_DEBUG,
2022 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002023 survey->freq,
2024 (unsigned long int) survey->channel_time,
2025 (unsigned long int) survey->channel_time_busy);
2026
2027 if (survey->channel_time > iface->last_channel_time &&
2028 survey->channel_time > survey->channel_time_busy) {
2029 dividend = survey->channel_time_busy -
2030 iface->last_channel_time_busy;
2031 divisor = survey->channel_time - iface->last_channel_time;
2032
2033 iface->channel_utilization = dividend * 255 / divisor;
2034 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
2035 iface->channel_utilization);
2036 }
2037 iface->last_channel_time = survey->channel_time;
2038 iface->last_channel_time_busy = survey->channel_time_busy;
2039}
2040
2041
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002042void hostapd_event_get_survey(struct hostapd_iface *iface,
2043 struct survey_results *survey_results)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002044{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002045 struct freq_survey *survey, *tmp;
2046 struct hostapd_channel_data *chan;
2047
2048 if (dl_list_empty(&survey_results->survey_list)) {
2049 wpa_printf(MSG_DEBUG, "No survey data received");
2050 return;
2051 }
2052
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002053 if (survey_results->freq_filter) {
2054 hostapd_single_channel_get_survey(iface, survey_results);
2055 return;
2056 }
2057
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002058 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
2059 struct freq_survey, list) {
2060 chan = hostapd_get_mode_channel(iface, survey->freq);
2061 if (!chan)
2062 continue;
2063 if (chan->flag & HOSTAPD_CHAN_DISABLED)
2064 continue;
2065
2066 dl_list_del(&survey->list);
2067 dl_list_add_tail(&chan->survey_list, &survey->list);
2068
2069 hostapd_update_nf(iface, chan, survey);
2070
2071 iface->chans_surveyed++;
2072 }
2073}
2074
2075
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002076#ifdef HOSTAPD
Dmitry Shmidt051af732013-10-22 13:52:46 -07002077#ifdef NEED_AP_MLME
2078
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002079static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
2080{
2081 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
2082 hapd->conf->iface);
2083
2084 if (hapd->csa_in_progress) {
2085 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
2086 hapd->conf->iface);
2087 hostapd_switch_channel_fallback(hapd->iface,
2088 &hapd->cs_freq_params);
2089 }
Yu Ouyang378d3c42021-08-20 17:31:08 +08002090
2091 // inform framework that interface is unavailable
2092 hostapd_disable_iface(hapd->iface);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002093}
2094
2095
Dmitry Shmidt051af732013-10-22 13:52:46 -07002096static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
2097 struct dfs_event *radar)
2098{
2099 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002100 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002101 radar->chan_offset, radar->chan_width,
2102 radar->cf1, radar->cf2);
2103}
2104
2105
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002106static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
2107 struct dfs_event *radar)
2108{
2109 wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
2110 hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
2111 radar->chan_offset, radar->chan_width,
2112 radar->cf1, radar->cf2);
2113}
2114
2115
Dmitry Shmidt051af732013-10-22 13:52:46 -07002116static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
2117 struct dfs_event *radar)
2118{
2119 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002120 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002121 radar->chan_offset, radar->chan_width,
2122 radar->cf1, radar->cf2);
2123}
2124
2125
2126static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
2127 struct dfs_event *radar)
2128{
2129 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002130 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002131 radar->chan_offset, radar->chan_width,
2132 radar->cf1, radar->cf2);
2133}
2134
2135
2136static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
2137 struct dfs_event *radar)
2138{
2139 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002140 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002141 radar->chan_offset, radar->chan_width,
2142 radar->cf1, radar->cf2);
2143}
2144
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002145
2146static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
2147 struct dfs_event *radar)
2148{
2149 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
2150 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
2151 radar->chan_offset, radar->chan_width,
2152 radar->cf1, radar->cf2);
2153}
2154
Dmitry Shmidt051af732013-10-22 13:52:46 -07002155#endif /* NEED_AP_MLME */
2156
2157
Roshan Pius3a1667e2018-07-03 15:17:14 -07002158static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd,
2159 int istatus,
2160 const char *ifname,
2161 const u8 *addr)
2162{
2163 struct sta_info *sta = ap_get_sta(hapd, addr);
2164
2165 if (sta) {
2166 os_free(sta->ifname_wds);
2167 if (istatus == INTERFACE_ADDED)
2168 sta->ifname_wds = os_strdup(ifname);
2169 else
2170 sta->ifname_wds = NULL;
2171 }
2172
2173 wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR,
2174 istatus == INTERFACE_ADDED ?
2175 WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED,
2176 ifname, MAC2STR(addr));
2177}
2178
2179
Hai Shalom81f62d82019-07-22 12:10:00 -07002180#ifdef CONFIG_OWE
2181static int hostapd_notif_update_dh_ie(struct hostapd_data *hapd,
2182 const u8 *peer, const u8 *ie,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002183 size_t ie_len, const u8 *link_addr)
Hai Shalom81f62d82019-07-22 12:10:00 -07002184{
2185 u16 status;
2186 struct sta_info *sta;
2187 struct ieee802_11_elems elems;
2188
2189 if (!hapd || !hapd->wpa_auth) {
2190 wpa_printf(MSG_DEBUG, "OWE: Invalid hapd context");
2191 return -1;
2192 }
2193 if (!peer) {
2194 wpa_printf(MSG_DEBUG, "OWE: Peer unknown");
2195 return -1;
2196 }
2197 if (!(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) {
2198 wpa_printf(MSG_DEBUG, "OWE: No OWE AKM configured");
2199 status = WLAN_STATUS_AKMP_NOT_VALID;
2200 goto err;
2201 }
2202 if (ieee802_11_parse_elems(ie, ie_len, &elems, 1) == ParseFailed) {
2203 wpa_printf(MSG_DEBUG, "OWE: Failed to parse OWE IE for "
2204 MACSTR, MAC2STR(peer));
2205 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
2206 goto err;
2207 }
2208 status = owe_validate_request(hapd, peer, elems.rsn_ie,
2209 elems.rsn_ie_len,
2210 elems.owe_dh, elems.owe_dh_len);
2211 if (status != WLAN_STATUS_SUCCESS)
2212 goto err;
2213
2214 sta = ap_get_sta(hapd, peer);
2215 if (sta) {
2216 ap_sta_no_session_timeout(hapd, sta);
2217 accounting_sta_stop(hapd, sta);
2218
2219 /*
2220 * Make sure that the previously registered inactivity timer
2221 * will not remove the STA immediately.
2222 */
2223 sta->timeout_next = STA_NULLFUNC;
2224 } else {
2225 sta = ap_sta_add(hapd, peer);
2226 if (!sta) {
2227 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
2228 goto err;
2229 }
2230 }
2231 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
2232
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002233#ifdef CONFIG_IEEE80211BE
2234 if (link_addr) {
2235 struct mld_info *info = &sta->mld_info;
2236 u8 link_id = hapd->mld_link_id;
2237
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002238 ap_sta_set_mld(sta, true);
2239 sta->mld_assoc_link_id = link_id;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002240 os_memcpy(info->common_info.mld_addr, peer, ETH_ALEN);
2241 info->links[link_id].valid = true;
2242 os_memcpy(info->links[link_id].local_addr, hapd->own_addr,
2243 ETH_ALEN);
2244 os_memcpy(info->links[link_id].peer_addr, link_addr, ETH_ALEN);
2245 }
2246#endif /* CONFIG_IEEE80211BE */
2247
Hai Shalom81f62d82019-07-22 12:10:00 -07002248 status = owe_process_rsn_ie(hapd, sta, elems.rsn_ie,
2249 elems.rsn_ie_len, elems.owe_dh,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002250 elems.owe_dh_len, link_addr);
Hai Shalom81f62d82019-07-22 12:10:00 -07002251 if (status != WLAN_STATUS_SUCCESS)
2252 ap_free_sta(hapd, sta);
2253
2254 return 0;
2255err:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002256 hostapd_drv_update_dh_ie(hapd, link_addr ? link_addr : peer, status,
2257 NULL, 0);
Hai Shalom81f62d82019-07-22 12:10:00 -07002258 return 0;
2259}
2260#endif /* CONFIG_OWE */
2261
2262
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002263void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2264 union wpa_event_data *data)
2265{
2266 struct hostapd_data *hapd = ctx;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002267 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002268#ifndef CONFIG_NO_STDOUT_DEBUG
2269 int level = MSG_DEBUG;
2270
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002271 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002272 data->rx_mgmt.frame_len >= 24) {
2273 const struct ieee80211_hdr *hdr;
2274 u16 fc;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002275
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002276 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2277 fc = le_to_host16(hdr->frame_control);
2278 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2279 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2280 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002281 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2282 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
2283 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002284 }
2285
2286 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
2287 event_to_string(event), event);
2288#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002289
2290 switch (event) {
2291 case EVENT_MICHAEL_MIC_FAILURE:
2292 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
2293 break;
2294 case EVENT_SCAN_RESULTS:
2295 if (hapd->iface->scan_cb)
2296 hapd->iface->scan_cb(hapd->iface);
2297 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002298 case EVENT_WPS_BUTTON_PUSHED:
2299 hostapd_wps_button_pushed(hapd, NULL);
2300 break;
2301#ifdef NEED_AP_MLME
2302 case EVENT_TX_STATUS:
2303 switch (data->tx_status.type) {
2304 case WLAN_FC_TYPE_MGMT:
2305 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
2306 data->tx_status.data_len,
2307 data->tx_status.stype,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002308 data->tx_status.ack,
2309 data->tx_status.link_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002310 break;
2311 case WLAN_FC_TYPE_DATA:
2312 hostapd_tx_status(hapd, data->tx_status.dst,
2313 data->tx_status.data,
2314 data->tx_status.data_len,
2315 data->tx_status.ack);
2316 break;
2317 }
2318 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002319 case EVENT_EAPOL_TX_STATUS:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002320 hapd = switch_link_hapd(hapd, data->eapol_tx_status.link_id);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002321 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
2322 data->eapol_tx_status.data,
2323 data->eapol_tx_status.data_len,
2324 data->eapol_tx_status.ack);
2325 break;
2326 case EVENT_DRIVER_CLIENT_POLL_OK:
2327 hostapd_client_poll_ok(hapd, data->client_poll.addr);
2328 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002329 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002330 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
2331 data->rx_from_unknown.addr,
2332 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002333 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002334#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002335 case EVENT_RX_MGMT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002336 if (!data->rx_mgmt.frame)
2337 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002338#ifdef NEED_AP_MLME
Hai Shalom021b0b52019-04-10 11:17:58 -07002339 hostapd_mgmt_rx(hapd, &data->rx_mgmt);
2340#else /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002341 hostapd_action_rx(hapd, &data->rx_mgmt);
Hai Shalom021b0b52019-04-10 11:17:58 -07002342#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002343 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002344 case EVENT_RX_PROBE_REQ:
2345 if (data->rx_probe_req.sa == NULL ||
2346 data->rx_probe_req.ie == NULL)
2347 break;
2348 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002349 data->rx_probe_req.da,
2350 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002351 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002352 data->rx_probe_req.ie_len,
2353 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002354 break;
2355 case EVENT_NEW_STA:
2356 hostapd_event_new_sta(hapd, data->new_sta.addr);
2357 break;
2358 case EVENT_EAPOL_RX:
2359 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
2360 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00002361 data->eapol_rx.data_len,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002362 data->eapol_rx.encrypted,
2363 data->eapol_rx.link_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002364 break;
2365 case EVENT_ASSOC:
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002366 if (!data)
2367 return;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002368#ifdef CONFIG_IEEE80211BE
2369 if (data->assoc_info.assoc_link_id != -1) {
2370 hapd = hostapd_mld_get_link_bss(
2371 hapd, data->assoc_info.assoc_link_id);
2372 if (!hapd) {
2373 wpa_printf(MSG_ERROR,
2374 "MLD: Failed to get link BSS for EVENT_ASSOC");
2375 return;
2376 }
2377 }
2378#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002379 hostapd_notif_assoc(hapd, data->assoc_info.addr,
2380 data->assoc_info.req_ies,
2381 data->assoc_info.req_ies_len,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002382 data->assoc_info.resp_ies,
2383 data->assoc_info.resp_ies_len,
2384 data->assoc_info.link_addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002385 data->assoc_info.reassoc);
2386 break;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002387 case EVENT_PORT_AUTHORIZED:
2388 /* Port authorized event for an associated STA */
2389 sta = ap_get_sta(hapd, data->port_authorized.sta_addr);
2390 if (sta)
2391 ap_sta_set_authorized(hapd, sta, 1);
2392 else
2393 wpa_printf(MSG_DEBUG,
2394 "No STA info matching port authorized event found");
2395 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07002396#ifdef CONFIG_OWE
2397 case EVENT_UPDATE_DH:
2398 if (!data)
2399 return;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002400#ifdef CONFIG_IEEE80211BE
2401 if (data->update_dh.assoc_link_id != -1) {
2402 hapd = hostapd_mld_get_link_bss(
2403 hapd, data->update_dh.assoc_link_id);
2404 if (!hapd) {
2405 wpa_printf(MSG_ERROR,
2406 "MLD: Failed to get link BSS for EVENT_UPDATE_DH assoc_link_id=%d",
2407 data->update_dh.assoc_link_id);
2408 return;
2409 }
2410 }
2411#endif /* CONFIG_IEEE80211BE */
Hai Shalom81f62d82019-07-22 12:10:00 -07002412 hostapd_notif_update_dh_ie(hapd, data->update_dh.peer,
2413 data->update_dh.ie,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002414 data->update_dh.ie_len,
2415 data->update_dh.link_addr);
Hai Shalom81f62d82019-07-22 12:10:00 -07002416 break;
2417#endif /* CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002418 case EVENT_DISASSOC:
2419 if (data)
2420 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
2421 break;
2422 case EVENT_DEAUTH:
2423 if (data)
2424 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
2425 break;
2426 case EVENT_STATION_LOW_ACK:
2427 if (!data)
2428 break;
2429 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
2430 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002431 case EVENT_AUTH:
2432 hostapd_notif_auth(hapd, &data->auth);
2433 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07002434 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07002435 case EVENT_CH_SWITCH:
2436 if (!data)
2437 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002438#ifdef CONFIG_IEEE80211BE
2439 if (data->ch_switch.link_id != -1) {
2440 hapd = hostapd_mld_get_link_bss(
2441 hapd, data->ch_switch.link_id);
2442 if (!hapd) {
2443 wpa_printf(MSG_ERROR,
2444 "MLD: Failed to get link (ID %d) BSS for EVENT_CH_SWITCH/EVENT_CH_SWITCH_STARTED",
2445 data->ch_switch.link_id);
2446 break;
2447 }
2448 }
2449#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002450 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
2451 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08002452 data->ch_switch.ch_offset,
2453 data->ch_switch.ch_width,
2454 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07002455 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07002456 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07002457 event == EVENT_CH_SWITCH);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002458 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002459 case EVENT_CONNECT_FAILED_REASON:
2460 if (!data)
2461 break;
2462 hostapd_event_connect_failed_reason(
2463 hapd, data->connect_failed_reason.addr,
2464 data->connect_failed_reason.code);
2465 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002466 case EVENT_SURVEY:
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002467 hostapd_event_get_survey(hapd->iface, &data->survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002468 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002469#ifdef NEED_AP_MLME
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002470 case EVENT_INTERFACE_UNAVAILABLE:
2471 hostapd_event_iface_unavailable(hapd);
2472 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002473 case EVENT_DFS_RADAR_DETECTED:
2474 if (!data)
2475 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002476 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002477 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
2478 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002479 case EVENT_DFS_PRE_CAC_EXPIRED:
2480 if (!data)
2481 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002482 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002483 hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
2484 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002485 case EVENT_DFS_CAC_FINISHED:
2486 if (!data)
2487 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002488 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002489 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
2490 break;
2491 case EVENT_DFS_CAC_ABORTED:
2492 if (!data)
2493 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002494 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002495 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
2496 break;
2497 case EVENT_DFS_NOP_FINISHED:
2498 if (!data)
2499 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002500 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002501 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
2502 break;
2503 case EVENT_CHANNEL_LIST_CHANGED:
2504 /* channel list changed (regulatory?), update channel list */
2505 /* TODO: check this. hostapd_get_hw_features() initializes
2506 * too much stuff. */
2507 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002508 hostapd_channel_list_updated(
2509 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002510 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002511 case EVENT_DFS_CAC_STARTED:
2512 if (!data)
2513 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002514 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002515 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
2516 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002517#endif /* NEED_AP_MLME */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002518 case EVENT_INTERFACE_ENABLED:
2519 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002520 if (hapd->disabled && hapd->started) {
2521 hapd->disabled = 0;
2522 /*
2523 * Try to re-enable interface if the driver stopped it
2524 * when the interface got disabled.
2525 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07002526 if (hapd->wpa_auth)
2527 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
2528 else
2529 hostapd_reconfig_encryption(hapd);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002530 hapd->reenable_beacon = 1;
2531 ieee802_11_set_beacon(hapd);
Hai Shalom74f70d42019-02-11 14:42:39 -08002532#ifdef NEED_AP_MLME
2533 } else if (hapd->disabled && hapd->iface->cac_started) {
2534 wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC");
2535 hostapd_handle_dfs(hapd->iface);
2536#endif /* NEED_AP_MLME */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002537 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002538 break;
2539 case EVENT_INTERFACE_DISABLED:
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002540 hostapd_free_stas(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002541 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002542 hapd->disabled = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002543 break;
2544#ifdef CONFIG_ACS
2545 case EVENT_ACS_CHANNEL_SELECTED:
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002546 hostapd_acs_channel_selected(hapd,
2547 &data->acs_selected_channels);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002548 break;
2549#endif /* CONFIG_ACS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002550 case EVENT_STATION_OPMODE_CHANGED:
2551 hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr,
2552 data->sta_opmode.smps_mode,
2553 data->sta_opmode.chan_width,
2554 data->sta_opmode.rx_nss);
2555 break;
2556 case EVENT_WDS_STA_INTERFACE_STATUS:
2557 hostapd_event_wds_sta_interface_status(
2558 hapd, data->wds_sta_interface.istatus,
2559 data->wds_sta_interface.ifname,
2560 data->wds_sta_interface.sta_addr);
2561 break;
Sunil Ravia04bd252022-05-02 22:54:18 -07002562#ifdef CONFIG_IEEE80211AX
2563 case EVENT_BSS_COLOR_COLLISION:
2564 /* The BSS color is shared amongst all BBSs on a specific phy.
2565 * Therefore we always start the color change on the primary
2566 * BSS. */
2567 wpa_printf(MSG_DEBUG, "BSS color collision on %s",
2568 hapd->conf->iface);
2569 hostapd_switch_color(hapd->iface->bss[0],
2570 data->bss_color_collision.bitmap);
2571 break;
2572 case EVENT_CCA_STARTED_NOTIFY:
2573 wpa_printf(MSG_DEBUG, "CCA started on on %s",
2574 hapd->conf->iface);
2575 break;
2576 case EVENT_CCA_ABORTED_NOTIFY:
2577 wpa_printf(MSG_DEBUG, "CCA aborted on on %s",
2578 hapd->conf->iface);
2579 hostapd_cleanup_cca_params(hapd);
2580 break;
2581 case EVENT_CCA_NOTIFY:
2582 wpa_printf(MSG_DEBUG, "CCA finished on on %s",
2583 hapd->conf->iface);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002584 if (hapd->cca_color)
2585 hapd->iface->conf->he_op.he_bss_color = hapd->cca_color;
Sunil Ravia04bd252022-05-02 22:54:18 -07002586 hostapd_cleanup_cca_params(hapd);
2587 break;
2588#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002589 default:
2590 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
2591 break;
2592 }
2593}
2594
Dmitry Shmidte4663042016-04-04 10:07:49 -07002595
2596void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
2597 union wpa_event_data *data)
2598{
2599 struct hapd_interfaces *interfaces = ctx;
2600 struct hostapd_data *hapd;
2601
2602 if (event != EVENT_INTERFACE_STATUS)
2603 return;
2604
2605 hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
2606 if (hapd && hapd->driver && hapd->driver->get_ifindex &&
2607 hapd->drv_priv) {
2608 unsigned int ifindex;
2609
2610 ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
2611 if (ifindex != data->interface_status.ifindex) {
2612 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
2613 "interface status ifindex %d mismatch (%d)",
2614 ifindex, data->interface_status.ifindex);
2615 return;
2616 }
2617 }
2618 if (hapd)
2619 wpa_supplicant_event(hapd, event, data);
2620}
2621
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002622#endif /* HOSTAPD */