blob: 82a922edc29151ffef1ebb87d0d6c15e19d99b4f [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"
Sunil Ravi79e6c4f2025-01-04 00:47:06 +000021#include "common/nan_de.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include "crypto/random.h"
23#include "p2p/p2p.h"
24#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080025#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070026#include "wnm_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "hostapd.h"
28#include "ieee802_11.h"
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080029#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#include "sta_info.h"
31#include "accounting.h"
32#include "tkip_countermeasures.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033#include "ieee802_1x.h"
34#include "wpa_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070035#include "wps_hostapd.h"
36#include "ap_drv_ops.h"
37#include "ap_config.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070038#include "ap_mlme.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070039#include "hw_features.h"
Dmitry Shmidt051af732013-10-22 13:52:46 -070040#include "dfs.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070041#include "beacon.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080042#include "mbo_ap.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070043#include "dpp_hostapd.h"
44#include "fils_hlp.h"
Hai Shalom74f70d42019-02-11 14:42:39 -080045#include "neighbor_db.h"
Sunil Ravib0ac25f2024-07-12 01:42:03 +000046#include "nan_usd_ap.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070047
48
49#ifdef CONFIG_FILS
50void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd,
51 struct sta_info *sta)
52{
53 u16 reply_res = WLAN_STATUS_SUCCESS;
54 struct ieee802_11_elems elems;
55 u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf;
56 int new_assoc;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000057 bool updated;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070058
59 wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR,
60 __func__, MAC2STR(sta->addr));
61 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
62 if (!sta->fils_pending_assoc_req)
63 return;
64
Sunil Ravi2a14cf12023-11-21 00:54:38 +000065 if (ieee802_11_parse_elems(sta->fils_pending_assoc_req,
66 sta->fils_pending_assoc_req_len, &elems,
67 0) == ParseFailed ||
68 !elems.fils_session) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070069 wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element",
70 __func__);
71 return;
72 }
73
74 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
75 elems.fils_session,
76 sta->fils_hlp_resp);
Sunil Ravic0f5d412024-09-11 22:12:49 +000077 if (!p)
78 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070079
80 reply_res = hostapd_sta_assoc(hapd, sta->addr,
81 sta->fils_pending_assoc_is_reassoc,
82 WLAN_STATUS_SUCCESS,
83 buf, p - buf);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000084 updated = ap_sta_set_authorized_flag(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070085 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
86 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
87 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
88 hostapd_set_sta_flags(hapd, sta);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000089 if (updated)
90 ap_sta_set_authorized_event(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070091 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
92 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
93 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
94 os_free(sta->fils_pending_assoc_req);
95 sta->fils_pending_assoc_req = NULL;
96 sta->fils_pending_assoc_req_len = 0;
97 wpabuf_free(sta->fils_hlp_resp);
98 sta->fils_hlp_resp = NULL;
99 wpabuf_free(sta->hlp_dhcp_discover);
100 sta->hlp_dhcp_discover = NULL;
101 fils_hlp_deinit(hapd);
102
103 /*
104 * Remove the station in case transmission of a success response fails
105 * (the STA was added associated to the driver) or if the station was
106 * previously added unassociated.
107 */
108 if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) {
109 hostapd_drv_sta_remove(hapd, sta->addr);
110 sta->added_unassoc = 0;
111 }
112}
113#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114
115
Hai Shalom899fcc72020-10-19 14:38:18 -0700116static bool check_sa_query_need(struct hostapd_data *hapd, struct sta_info *sta)
117{
118 if ((sta->flags &
119 (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED)) !=
120 (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED))
121 return false;
122
123 if (!sta->sa_query_timed_out && sta->sa_query_count > 0)
124 ap_check_sa_query_timeout(hapd, sta);
125
126 if (!sta->sa_query_timed_out && (sta->auth_alg != WLAN_AUTH_FT)) {
127 /*
128 * STA has already been associated with MFP and SA Query timeout
129 * has not been reached. Reject the association attempt
130 * temporarily and start SA Query, if one is not pending.
131 */
132 if (sta->sa_query_count == 0)
133 ap_sta_start_sa_query(hapd, sta);
134
135 return true;
136 }
137
138 return false;
139}
140
141
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000142#ifdef CONFIG_IEEE80211BE
143static int hostapd_update_sta_links_status(struct hostapd_data *hapd,
144 struct sta_info *sta,
145 const u8 *resp_ies,
146 size_t resp_ies_len)
147{
148 struct mld_info *info = &sta->mld_info;
149 struct wpabuf *mlebuf;
150 const u8 *mle, *pos;
151 struct ieee802_11_elems elems;
152 size_t mle_len, rem_len;
153 int ret = 0;
154
155 if (!resp_ies) {
156 wpa_printf(MSG_DEBUG,
157 "MLO: (Re)Association Response frame elements not available");
158 return -1;
159 }
160
161 if (ieee802_11_parse_elems(resp_ies, resp_ies_len, &elems, 0) ==
162 ParseFailed) {
163 wpa_printf(MSG_DEBUG,
164 "MLO: Failed to parse (Re)Association Response frame elements");
165 return -1;
166 }
167
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000168 mlebuf = ieee802_11_defrag(elems.basic_mle, elems.basic_mle_len, true);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000169 if (!mlebuf) {
170 wpa_printf(MSG_ERROR,
171 "MLO: Basic Multi-Link element not found in (Re)Association Response frame");
172 return -1;
173 }
174
175 mle = wpabuf_head(mlebuf);
176 mle_len = wpabuf_len(mlebuf);
177 if (mle_len < MULTI_LINK_CONTROL_LEN + 1 ||
178 mle_len - MULTI_LINK_CONTROL_LEN < mle[MULTI_LINK_CONTROL_LEN]) {
179 wpa_printf(MSG_ERROR,
180 "MLO: Invalid Multi-Link element in (Re)Association Response frame");
181 ret = -1;
182 goto out;
183 }
184
185 /* Skip Common Info */
186 pos = mle + MULTI_LINK_CONTROL_LEN + mle[MULTI_LINK_CONTROL_LEN];
187 rem_len = mle_len -
188 (MULTI_LINK_CONTROL_LEN + mle[MULTI_LINK_CONTROL_LEN]);
189
190 /* Parse Subelements */
191 while (rem_len > 2) {
192 size_t ie_len = 2 + pos[1];
193
194 if (rem_len < ie_len)
195 break;
196
197 if (pos[0] == MULTI_LINK_SUB_ELEM_ID_PER_STA_PROFILE) {
198 u8 link_id;
199 const u8 *sta_profile;
200 size_t sta_profile_len;
201 u16 sta_ctrl;
202
203 if (pos[1] < BASIC_MLE_STA_CTRL_LEN + 1) {
204 wpa_printf(MSG_DEBUG,
205 "MLO: Invalid per-STA profile IE");
206 goto next_subelem;
207 }
208
209 sta_profile_len = pos[1];
210 sta_profile = &pos[2];
211 sta_ctrl = WPA_GET_LE16(sta_profile);
212 link_id = sta_ctrl & BASIC_MLE_STA_CTRL_LINK_ID_MASK;
213 if (link_id >= MAX_NUM_MLD_LINKS) {
214 wpa_printf(MSG_DEBUG,
215 "MLO: Invalid link ID in per-STA profile IE");
216 goto next_subelem;
217 }
218
219 /* Skip STA Control and STA Info */
220 if (sta_profile_len - BASIC_MLE_STA_CTRL_LEN <
221 sta_profile[BASIC_MLE_STA_CTRL_LEN]) {
222 wpa_printf(MSG_DEBUG,
223 "MLO: Invalid STA info in per-STA profile IE");
224 goto next_subelem;
225 }
226
227 sta_profile_len = sta_profile_len -
228 (BASIC_MLE_STA_CTRL_LEN +
229 sta_profile[BASIC_MLE_STA_CTRL_LEN]);
230 sta_profile = sta_profile + BASIC_MLE_STA_CTRL_LEN +
231 sta_profile[BASIC_MLE_STA_CTRL_LEN];
232
233 /* Skip Capabilities Information field */
234 if (sta_profile_len < 2)
235 goto next_subelem;
236 sta_profile_len -= 2;
237 sta_profile += 2;
238
239 /* Get status of the link */
240 info->links[link_id].status = WPA_GET_LE16(sta_profile);
241 }
242next_subelem:
243 pos += ie_len;
244 rem_len -= ie_len;
245 }
246
247out:
248 wpabuf_free(mlebuf);
249 return ret;
250}
251#endif /* CONFIG_IEEE80211BE */
252
253
Sunil Ravic0f5d412024-09-11 22:12:49 +0000254#if defined(HOSTAPD) || defined(CONFIG_IEEE80211BE)
255static struct hostapd_data * hostapd_find_by_sta(struct hostapd_iface *iface,
256 const u8 *src, bool rsn,
257 struct sta_info **sta_ret)
258{
259 struct hostapd_data *hapd;
260 struct sta_info *sta;
261 unsigned int j;
262
263 if (sta_ret)
264 *sta_ret = NULL;
265
266 for (j = 0; j < iface->num_bss; j++) {
267 hapd = iface->bss[j];
268 sta = ap_get_sta(hapd, src);
269 if (sta && (sta->flags & WLAN_STA_ASSOC) &&
270 (!rsn || sta->wpa_sm)) {
271 if (sta_ret)
272 *sta_ret = sta;
273 return hapd;
274 }
275#ifdef CONFIG_IEEE80211BE
276 if (hapd->conf->mld_ap) {
277 struct hostapd_data *p_hapd;
278
279 for_each_mld_link(p_hapd, hapd) {
280 if (p_hapd == hapd)
281 continue;
282
283 sta = ap_get_sta(p_hapd, src);
284 if (sta && (sta->flags & WLAN_STA_ASSOC) &&
285 (!rsn || sta->wpa_sm)) {
286 if (sta_ret)
287 *sta_ret = sta;
288 return p_hapd;
289 }
290 }
291 }
292#endif /* CONFIG_IEEE80211BE */
293 }
294
295 return NULL;
296}
297#endif /* HOSTAPD || CONFIG_IEEE80211BE */
298
299
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700300int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000301 const u8 *req_ies, size_t req_ies_len,
302 const u8 *resp_ies, size_t resp_ies_len,
303 const u8 *link_addr, int reassoc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304{
305 struct sta_info *sta;
Hai Shalomfdcde762020-04-02 11:19:20 -0700306 int new_assoc;
307 enum wpa_validate_result res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700308 struct ieee802_11_elems elems;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800309 const u8 *ie;
310 size_t ielen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700311 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
312 u8 *p = buf;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800313 u16 reason = WLAN_REASON_UNSPECIFIED;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700314 int status = WLAN_STATUS_SUCCESS;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700315 const u8 *p2p_dev_addr = NULL;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000316#ifdef CONFIG_OWE
317 struct hostapd_iface *iface = hapd->iface;
318#endif /* CONFIG_OWE */
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000319 bool updated = false;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700320
321 if (addr == NULL) {
322 /*
323 * This could potentially happen with unexpected event from the
324 * driver wrapper. This was seen at least in one case where the
325 * driver ended up being set to station mode while hostapd was
326 * running, so better make sure we stop processing such an
327 * event here.
328 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800329 wpa_printf(MSG_DEBUG,
330 "hostapd_notif_assoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700331 return -1;
332 }
Hai Shalomc3565922019-10-28 11:58:20 -0700333
334 if (is_multicast_ether_addr(addr) ||
335 is_zero_ether_addr(addr) ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000336 ether_addr_equal(addr, hapd->own_addr)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700337 /* Do not process any frames with unexpected/invalid SA so that
338 * we do not add any state for unexpected STA addresses or end
339 * up sending out frames to unexpected destination. */
340 wpa_printf(MSG_DEBUG, "%s: Invalid SA=" MACSTR
341 " in received indication - ignore this indication silently",
342 __func__, MAC2STR(addr));
343 return 0;
344 }
345
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700346 random_add_randomness(addr, ETH_ALEN);
347
348 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
349 HOSTAPD_LEVEL_INFO, "associated");
350
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000351 if (ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0) ==
352 ParseFailed) {
353 wpa_printf(MSG_DEBUG, "%s: Could not parse elements", __func__);
354 return -1;
355 }
356
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700357 if (elems.wps_ie) {
358 ie = elems.wps_ie - 2;
359 ielen = elems.wps_ie_len + 2;
360 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
361 } else if (elems.rsn_ie) {
362 ie = elems.rsn_ie - 2;
363 ielen = elems.rsn_ie_len + 2;
364 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
365 } else if (elems.wpa_ie) {
366 ie = elems.wpa_ie - 2;
367 ielen = elems.wpa_ie_len + 2;
368 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800369#ifdef CONFIG_HS20
370 } else if (elems.osen) {
371 ie = elems.osen - 2;
372 ielen = elems.osen_len + 2;
373 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
374#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700375 } else {
376 ie = NULL;
377 ielen = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800378 wpa_printf(MSG_DEBUG,
379 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700380 }
381
382 sta = ap_get_sta(hapd, addr);
383 if (sta) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700384 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700385 accounting_sta_stop(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700386
387 /*
388 * Make sure that the previously registered inactivity timer
389 * will not remove the STA immediately.
390 */
391 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700392 } else {
393 sta = ap_sta_add(hapd, addr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700394 if (sta == NULL) {
395 hostapd_drv_sta_disassoc(hapd, addr,
396 WLAN_REASON_DISASSOC_AP_BUSY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700397 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700398 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700399 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000400
401 if (hapd->conf->wpa && check_sa_query_need(hapd, sta)) {
402 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
403 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
404 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
405
406 return 0;
407 }
408
409#ifdef CONFIG_IEEE80211BE
410 if (link_addr) {
411 struct mld_info *info = &sta->mld_info;
412 int i, num_valid_links = 0;
413 u8 link_id = hapd->mld_link_id;
414
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000415 ap_sta_set_mld(sta, true);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000416 sta->mld_assoc_link_id = link_id;
417 os_memcpy(info->common_info.mld_addr, addr, ETH_ALEN);
418 info->links[link_id].valid = true;
419 os_memcpy(info->links[link_id].peer_addr, link_addr, ETH_ALEN);
420 os_memcpy(info->links[link_id].local_addr, hapd->own_addr,
421 ETH_ALEN);
422
423 if (!elems.basic_mle ||
424 hostapd_process_ml_assoc_req(hapd, &elems, sta) !=
425 WLAN_STATUS_SUCCESS) {
426 reason = WLAN_REASON_UNSPECIFIED;
427 wpa_printf(MSG_DEBUG,
428 "Failed to get STA non-assoc links info");
429 goto fail;
430 }
431
432 for (i = 0 ; i < MAX_NUM_MLD_LINKS; i++) {
433 if (info->links[i].valid)
434 num_valid_links++;
435 }
436 if (num_valid_links > 1 &&
437 hostapd_update_sta_links_status(hapd, sta, resp_ies,
438 resp_ies_len)) {
439 wpa_printf(MSG_DEBUG,
440 "Failed to get STA non-assoc links status info");
441 reason = WLAN_REASON_UNSPECIFIED;
442 goto fail;
443 }
444 }
445#endif /* CONFIG_IEEE80211BE */
446
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800447 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700448
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700449 /*
450 * ACL configurations to the drivers (implementing AP SME and ACL
451 * offload) without hostapd's knowledge, can result in a disconnection
452 * though the driver accepts the connection. Skip the hostapd check for
453 * ACL if the driver supports ACL offload to avoid potentially
454 * conflicting ACL rules.
455 */
456 if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
457 hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800458 wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
459 MAC2STR(addr));
460 reason = WLAN_REASON_UNSPECIFIED;
461 goto fail;
462 }
463
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700464#ifdef CONFIG_P2P
465 if (elems.p2p) {
466 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800467 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700468 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700469 if (sta->p2p_ie)
470 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700471 }
472#endif /* CONFIG_P2P */
473
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700474#ifdef NEED_AP_MLME
475 if (elems.ht_capabilities &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700476 (hapd->iface->conf->ht_capab &
477 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
478 struct ieee80211_ht_capabilities *ht_cap =
479 (struct ieee80211_ht_capabilities *)
480 elems.ht_capabilities;
481
482 if (le_to_host16(ht_cap->ht_capabilities_info) &
483 HT_CAP_INFO_40MHZ_INTOLERANT)
484 ht40_intolerant_add(hapd->iface, sta);
485 }
486#endif /* NEED_AP_MLME */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700487
Sunil Ravia04bd252022-05-02 22:54:18 -0700488 check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700489
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800490#ifdef CONFIG_HS20
491 wpabuf_free(sta->hs20_ie);
492 if (elems.hs20 && elems.hs20_len > 4) {
493 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
494 elems.hs20_len - 4);
495 } else
496 sta->hs20_ie = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700497
498 wpabuf_free(sta->roaming_consortium);
499 if (elems.roaming_cons_sel)
500 sta->roaming_consortium = wpabuf_alloc_copy(
501 elems.roaming_cons_sel + 4,
502 elems.roaming_cons_sel_len - 4);
503 else
504 sta->roaming_consortium = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800505#endif /* CONFIG_HS20 */
506
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800507#ifdef CONFIG_FST
508 wpabuf_free(sta->mb_ies);
509 if (hapd->iface->fst)
510 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
511 else
512 sta->mb_ies = NULL;
513#endif /* CONFIG_FST */
514
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800515 mbo_ap_check_sta_assoc(hapd, sta, &elems);
516
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800517 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
518 elems.supp_op_classes_len);
519
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 if (hapd->conf->wpa) {
521 if (ie == NULL || ielen == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800522#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700523 if (hapd->conf->wps_state) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800524 wpa_printf(MSG_DEBUG,
525 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700526 sta->flags |= WLAN_STA_MAYBE_WPS;
527 goto skip_wpa_check;
528 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800529#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700530
531 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700532 reason = WLAN_REASON_INVALID_IE;
533 status = WLAN_STATUS_INVALID_IE;
534 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700535 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800536#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700537 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
538 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800539 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800540
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800542 wps = ieee802_11_vendor_ie_concat(ie, ielen,
543 WPS_IE_VENDOR_TYPE);
544 if (wps) {
545 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800546 wpa_printf(MSG_DEBUG,
547 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800548 sta->flags |= WLAN_STA_WPS2;
549 }
550 wpabuf_free(wps);
551 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700552 goto skip_wpa_check;
553 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800554#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700555
556 if (sta->wpa_sm == NULL)
557 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700558 sta->addr,
559 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700560 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800561 wpa_printf(MSG_ERROR,
562 "Failed to initialize WPA state machine");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563 return -1;
564 }
Sunil Ravic0f5d412024-09-11 22:12:49 +0000565 wpa_auth_set_rsn_selection(sta->wpa_sm, elems.rsn_selection,
566 elems.rsn_selection_len);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000567#ifdef CONFIG_IEEE80211BE
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000568 if (ap_sta_is_mld(hapd, sta)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000569 wpa_printf(MSG_DEBUG,
570 "MLD: Set ML info in RSN Authenticator");
Sunil Ravi7f769292024-07-23 22:21:32 +0000571 wpa_auth_set_ml_info(sta->wpa_sm,
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000572 sta->mld_assoc_link_id,
573 &sta->mld_info);
574 }
575#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700576 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Hai Shalom021b0b52019-04-10 11:17:58 -0700577 hapd->iface->freq,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700578 ie, ielen,
Hai Shalomc3565922019-10-28 11:58:20 -0700579 elems.rsnxe ? elems.rsnxe - 2 : NULL,
580 elems.rsnxe ? elems.rsnxe_len + 2 : 0,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700581 elems.mdie, elems.mdie_len,
Sunil Ravi7f769292024-07-23 22:21:32 +0000582 elems.owe_dh, elems.owe_dh_len, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -0700583 reason = WLAN_REASON_INVALID_IE;
584 status = WLAN_STATUS_INVALID_IE;
585 switch (res) {
586 case WPA_IE_OK:
587 reason = WLAN_REASON_UNSPECIFIED;
588 status = WLAN_STATUS_SUCCESS;
589 break;
590 case WPA_INVALID_IE:
591 reason = WLAN_REASON_INVALID_IE;
592 status = WLAN_STATUS_INVALID_IE;
593 break;
594 case WPA_INVALID_GROUP:
595 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
596 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
597 break;
598 case WPA_INVALID_PAIRWISE:
599 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
600 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
601 break;
602 case WPA_INVALID_AKMP:
603 reason = WLAN_REASON_AKMP_NOT_VALID;
604 status = WLAN_STATUS_AKMP_NOT_VALID;
605 break;
606 case WPA_NOT_ENABLED:
607 reason = WLAN_REASON_INVALID_IE;
608 status = WLAN_STATUS_INVALID_IE;
609 break;
610 case WPA_ALLOC_FAIL:
611 reason = WLAN_REASON_UNSPECIFIED;
612 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
613 break;
614 case WPA_MGMT_FRAME_PROTECTION_VIOLATION:
615 reason = WLAN_REASON_INVALID_IE;
616 status = WLAN_STATUS_INVALID_IE;
617 break;
618 case WPA_INVALID_MGMT_GROUP_CIPHER:
619 reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
620 status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
621 break;
622 case WPA_INVALID_MDIE:
623 reason = WLAN_REASON_INVALID_MDE;
624 status = WLAN_STATUS_INVALID_MDIE;
625 break;
626 case WPA_INVALID_PROTO:
627 reason = WLAN_REASON_INVALID_IE;
628 status = WLAN_STATUS_INVALID_IE;
629 break;
630 case WPA_INVALID_PMKID:
631 reason = WLAN_REASON_INVALID_PMKID;
632 status = WLAN_STATUS_INVALID_PMKID;
633 break;
634 case WPA_DENIED_OTHER_REASON:
635 reason = WLAN_REASON_UNSPECIFIED;
636 status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
637 break;
638 }
639 if (status != WLAN_STATUS_SUCCESS) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800640 wpa_printf(MSG_DEBUG,
641 "WPA/RSN information element rejected? (res %u)",
642 res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700643 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800644 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700645 }
Hai Shalomc3565922019-10-28 11:58:20 -0700646
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700647 if (wpa_auth_uses_mfp(sta->wpa_sm))
648 sta->flags |= WLAN_STA_MFP;
649 else
650 sta->flags &= ~WLAN_STA_MFP;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700651
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800652#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700653 if (sta->auth_alg == WLAN_AUTH_FT) {
654 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
655 req_ies_len);
656 if (status != WLAN_STATUS_SUCCESS) {
657 if (status == WLAN_STATUS_INVALID_PMKID)
658 reason = WLAN_REASON_INVALID_IE;
659 if (status == WLAN_STATUS_INVALID_MDIE)
660 reason = WLAN_REASON_INVALID_IE;
661 if (status == WLAN_STATUS_INVALID_FTIE)
662 reason = WLAN_REASON_INVALID_IE;
663 goto fail;
664 }
665 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800666#endif /* CONFIG_IEEE80211R_AP */
Hai Shalomc3565922019-10-28 11:58:20 -0700667#ifdef CONFIG_SAE
Sunil Ravi77d572f2023-01-17 23:58:31 +0000668 if (hapd->conf->sae_pwe == SAE_PWE_BOTH &&
Hai Shalomc3565922019-10-28 11:58:20 -0700669 sta->auth_alg == WLAN_AUTH_SAE &&
Hai Shalom899fcc72020-10-19 14:38:18 -0700670 sta->sae && !sta->sae->h2e &&
Hai Shaloma20dcd72022-02-04 13:43:00 -0800671 ieee802_11_rsnx_capab_len(elems.rsnxe, elems.rsnxe_len,
672 WLAN_RSNX_CAPAB_SAE_H2E)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700673 wpa_printf(MSG_INFO, "SAE: " MACSTR
674 " indicates support for SAE H2E, but did not use it",
675 MAC2STR(sta->addr));
676 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
677 reason = WLAN_REASON_UNSPECIFIED;
678 goto fail;
679 }
680#endif /* CONFIG_SAE */
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000681
682 wpa_auth_set_ssid_protection(
683 sta->wpa_sm,
684 hapd->conf->ssid_protection &&
685 ieee802_11_rsnx_capab_len(
686 elems.rsnxe, elems.rsnxe_len,
687 WLAN_RSNX_CAPAB_SSID_PROTECTION));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700688 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800689#ifdef CONFIG_WPS
690 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800691
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800692 if (req_ies)
693 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700694 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800695 else
696 wps = NULL;
697#ifdef CONFIG_WPS_STRICT
698 if (wps && wps_validate_assoc_req(wps) < 0) {
699 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700700 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800702 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700703 }
704#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800705 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800707 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800708 wpa_printf(MSG_DEBUG,
709 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800710 sta->flags |= WLAN_STA_WPS2;
711 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700712 } else
713 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800714 wpabuf_free(wps);
715#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800716#ifdef CONFIG_HS20
717 } else if (hapd->conf->osen) {
718 if (elems.osen == NULL) {
719 hostapd_logger(
720 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
721 HOSTAPD_LEVEL_INFO,
722 "No HS 2.0 OSEN element in association request");
723 return WLAN_STATUS_INVALID_IE;
724 }
725
726 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
727 if (sta->wpa_sm == NULL)
728 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
729 sta->addr, NULL);
730 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800731 wpa_printf(MSG_WARNING,
732 "Failed to initialize WPA state machine");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800733 return WLAN_STATUS_UNSPECIFIED_FAILURE;
734 }
735 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
736 elems.osen - 2, elems.osen_len + 2) < 0)
737 return WLAN_STATUS_INVALID_IE;
738#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700739 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700740#ifdef CONFIG_WPS
741skip_wpa_check:
742#endif /* CONFIG_WPS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800743
744#ifdef CONFIG_MBO
745 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
746 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
747 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
748 wpa_printf(MSG_INFO,
749 "MBO: Reject WPA2 association without PMF");
750 return WLAN_STATUS_UNSPECIFIED_FAILURE;
751 }
752#endif /* CONFIG_MBO */
753
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800754#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700755 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
Hai Shalomfdcde762020-04-02 11:19:20 -0700756 sta->auth_alg, req_ies, req_ies_len,
757 !elems.rsnxe);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700758 if (!p) {
759 wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs");
760 return WLAN_STATUS_UNSPECIFIED_FAILURE;
761 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700762#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700763
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700764#ifdef CONFIG_FILS
765 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
766 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
767 sta->auth_alg == WLAN_AUTH_FILS_PK) {
768 int delay_assoc = 0;
769
770 if (!req_ies)
771 return WLAN_STATUS_UNSPECIFIED_FAILURE;
772
773 if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies,
774 req_ies_len,
775 sta->fils_session)) {
776 wpa_printf(MSG_DEBUG,
777 "FILS: Session validation failed");
778 return WLAN_STATUS_UNSPECIFIED_FAILURE;
779 }
780
781 res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies,
782 req_ies_len);
783 if (res < 0) {
784 wpa_printf(MSG_DEBUG,
785 "FILS: Key Confirm validation failed");
786 return WLAN_STATUS_UNSPECIFIED_FAILURE;
787 }
788
789 if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) {
790 wpa_printf(MSG_DEBUG,
791 "FILS: Delaying Assoc Response (HLP)");
792 delay_assoc = 1;
793 } else {
794 wpa_printf(MSG_DEBUG,
795 "FILS: Going ahead with Assoc Response (no HLP)");
796 }
797
798 if (sta) {
799 wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup");
800 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
801 os_free(sta->fils_pending_assoc_req);
802 sta->fils_pending_assoc_req = NULL;
803 sta->fils_pending_assoc_req_len = 0;
804 wpabuf_free(sta->fils_hlp_resp);
805 sta->fils_hlp_resp = NULL;
806 sta->fils_drv_assoc_finish = 0;
807 }
808
809 if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) {
810 u8 *req_tmp;
811
812 req_tmp = os_malloc(req_ies_len);
813 if (!req_tmp) {
814 wpa_printf(MSG_DEBUG,
815 "FILS: buffer allocation failed for assoc req");
816 goto fail;
817 }
818 os_memcpy(req_tmp, req_ies, req_ies_len);
819 sta->fils_pending_assoc_req = req_tmp;
820 sta->fils_pending_assoc_req_len = req_ies_len;
821 sta->fils_pending_assoc_is_reassoc = reassoc;
822 sta->fils_drv_assoc_finish = 1;
823 wpa_printf(MSG_DEBUG,
824 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
825 MACSTR, MAC2STR(sta->addr));
826 eloop_register_timeout(
827 0, hapd->conf->fils_hlp_wait_time * 1024,
828 fils_hlp_timeout, hapd, sta);
829 return 0;
830 }
831 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
832 elems.fils_session,
833 sta->fils_hlp_resp);
Sunil Ravic0f5d412024-09-11 22:12:49 +0000834 if (!p)
835 goto fail;
836
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700837 wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)",
838 buf, p - buf);
839 }
840#endif /* CONFIG_FILS */
841
Roshan Pius3a1667e2018-07-03 15:17:14 -0700842#ifdef CONFIG_OWE
843 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000844 !(iface->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_AP) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -0700845 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
846 elems.owe_dh) {
847 u8 *npos;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700848 u16 ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700849
850 npos = owe_assoc_req_process(hapd, sta,
851 elems.owe_dh, elems.owe_dh_len,
852 p, sizeof(buf) - (p - buf),
Hai Shalomb755a2a2020-04-23 21:49:02 -0700853 &ret_status);
854 status = ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700855 if (npos)
856 p = npos;
Hai Shalomfdcde762020-04-02 11:19:20 -0700857
Roshan Pius3a1667e2018-07-03 15:17:14 -0700858 if (!npos &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700859 status == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
Hai Shalomb755a2a2020-04-23 21:49:02 -0700860 hostapd_sta_assoc(hapd, addr, reassoc, ret_status, buf,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700861 p - buf);
862 return 0;
863 }
864
Hai Shalomfdcde762020-04-02 11:19:20 -0700865 if (!npos || status != WLAN_STATUS_SUCCESS)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700866 goto fail;
867 }
868#endif /* CONFIG_OWE */
869
Hai Shalom021b0b52019-04-10 11:17:58 -0700870#ifdef CONFIG_DPP2
871 dpp_pfs_free(sta->dpp_pfs);
872 sta->dpp_pfs = NULL;
873
874 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
875 hapd->conf->dpp_netaccesskey && sta->wpa_sm &&
876 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP &&
877 elems.owe_dh) {
878 sta->dpp_pfs = dpp_pfs_init(
879 wpabuf_head(hapd->conf->dpp_netaccesskey),
880 wpabuf_len(hapd->conf->dpp_netaccesskey));
881 if (!sta->dpp_pfs) {
882 wpa_printf(MSG_DEBUG,
883 "DPP: Could not initialize PFS");
884 /* Try to continue without PFS */
885 goto pfs_fail;
886 }
887
888 if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh,
889 elems.owe_dh_len) < 0) {
890 dpp_pfs_free(sta->dpp_pfs);
891 sta->dpp_pfs = NULL;
892 reason = WLAN_REASON_UNSPECIFIED;
893 goto fail;
894 }
895 }
896
897 wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ?
898 sta->dpp_pfs->secret : NULL);
899 pfs_fail:
900#endif /* CONFIG_DPP2 */
901
Hai Shalomfdcde762020-04-02 11:19:20 -0700902 if (elems.rrm_enabled &&
903 elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
904 os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
905 sizeof(sta->rrm_enabled_capa));
906
Roshan Pius3a1667e2018-07-03 15:17:14 -0700907#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700908 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700909
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700910 if (sta->auth_alg == WLAN_AUTH_FT ||
911 sta->auth_alg == WLAN_AUTH_FILS_SK ||
912 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
913 sta->auth_alg == WLAN_AUTH_FILS_PK)
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000914 updated = ap_sta_set_authorized_flag(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700915#else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700916 /* Keep compiler silent about unused variables */
917 if (status) {
918 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700919#endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700920
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000921#ifdef CONFIG_IEEE80211BE
922 if (hostapd_process_assoc_ml_info(hapd, sta, req_ies, req_ies_len,
923 !!reassoc, WLAN_STATUS_SUCCESS,
924 true)) {
925 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
926 reason = WLAN_REASON_UNSPECIFIED;
927 goto fail;
928 }
929#endif /* CONFIG_IEEE80211BE */
930
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700931 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
932 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800933 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700934
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700935 hostapd_set_sta_flags(hapd, sta);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000936 if (updated)
937 ap_sta_set_authorized_event(hapd, sta, 1);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700938
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700939 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
940 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700941#ifdef CONFIG_FILS
942 else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
943 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
944 sta->auth_alg == WLAN_AUTH_FILS_PK)
945 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
946#endif /* CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700947 else
948 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700949
950 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
951
952 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
953
954#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800955 if (req_ies) {
956 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
957 req_ies, req_ies_len);
958 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700959#endif /* CONFIG_P2P */
960
Sunil Ravi79e6c4f2025-01-04 00:47:06 +0000961 if (elems.wfa_capab)
962 hostapd_wfa_capab(hapd, sta, elems.wfa_capab,
963 elems.wfa_capab + elems.wfa_capab_len);
964
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700965 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800966
967fail:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800968#ifdef CONFIG_IEEE80211R_AP
Hai Shalomb755a2a2020-04-23 21:49:02 -0700969 if (status >= 0)
970 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800971#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800972 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
973 ap_free_sta(hapd, sta);
974 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700975}
976
977
Sunil Ravi99c035e2024-07-12 01:42:03 +0000978static void hostapd_remove_sta(struct hostapd_data *hapd, struct sta_info *sta)
979{
980 ap_sta_set_authorized(hapd, sta, 0);
981 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
982 hostapd_set_sta_flags(hapd, sta);
983 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
984 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
985 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
986 ap_free_sta(hapd, sta);
987}
988
989
990#ifdef CONFIG_IEEE80211BE
991static void hostapd_notif_disassoc_mld(struct hostapd_data *assoc_hapd,
992 struct sta_info *sta,
993 const u8 *addr)
994{
995 unsigned int link_id, i;
996 struct hostapd_data *tmp_hapd;
997 struct hapd_interfaces *interfaces = assoc_hapd->iface->interfaces;
998
999 /* Remove STA entry in non-assoc links */
1000 for (link_id = 0; link_id < MAX_NUM_MLD_LINKS; link_id++) {
1001 if (!sta->mld_info.links[link_id].valid)
1002 continue;
1003
1004 for (i = 0; i < interfaces->count; i++) {
1005 struct sta_info *tmp_sta;
1006
1007 tmp_hapd = interfaces->iface[i]->bss[0];
1008
1009 if (!tmp_hapd->conf->mld_ap ||
1010 assoc_hapd == tmp_hapd ||
1011 assoc_hapd->conf->mld_id != tmp_hapd->conf->mld_id)
1012 continue;
1013
1014 tmp_sta = ap_get_sta(tmp_hapd, addr);
1015 if (tmp_sta)
1016 ap_free_sta(tmp_hapd, tmp_sta);
1017 }
1018 }
1019
1020 /* Remove STA in assoc link */
1021 hostapd_remove_sta(assoc_hapd, sta);
1022}
1023#endif /* CONFIG_IEEE80211BE */
1024
1025
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001026void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
1027{
1028 struct sta_info *sta;
1029
1030 if (addr == NULL) {
1031 /*
1032 * This could potentially happen with unexpected event from the
1033 * driver wrapper. This was seen at least in one case where the
1034 * driver ended up reporting a station mode event while hostapd
1035 * was running, so better make sure we stop processing such an
1036 * event here.
1037 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001038 wpa_printf(MSG_DEBUG,
1039 "hostapd_notif_disassoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040 return;
1041 }
1042
1043 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
1044 HOSTAPD_LEVEL_INFO, "disassociated");
1045
1046 sta = ap_get_sta(hapd, addr);
Sunil Ravi99c035e2024-07-12 01:42:03 +00001047#ifdef CONFIG_IEEE80211BE
1048 if (hostapd_is_mld_ap(hapd)) {
1049 struct hostapd_data *assoc_hapd;
1050 unsigned int i;
1051
1052 if (!sta) {
1053 /* Find non-MLO cases from any of the affiliated AP
1054 * links. */
1055 for (i = 0; i < hapd->iface->interfaces->count; ++i) {
1056 struct hostapd_iface *h =
1057 hapd->iface->interfaces->iface[i];
1058 struct hostapd_data *h_hapd = h->bss[0];
1059 struct hostapd_bss_config *hconf = h_hapd->conf;
1060
1061 if (!hconf->mld_ap ||
1062 hconf->mld_id != hapd->conf->mld_id)
1063 continue;
1064
1065 sta = ap_get_sta(h_hapd, addr);
1066 if (sta) {
1067 if (!sta->mld_info.mld_sta) {
1068 hapd = h_hapd;
1069 goto legacy;
1070 }
1071 break;
1072 }
1073 }
1074 } else if (!sta->mld_info.mld_sta) {
1075 goto legacy;
1076 }
1077 if (!sta) {
1078 wpa_printf(MSG_DEBUG,
1079 "Disassociation notification for unknown STA "
1080 MACSTR, MAC2STR(addr));
1081 return;
1082 }
1083 sta = hostapd_ml_get_assoc_sta(hapd, sta, &assoc_hapd);
1084 if (sta)
1085 hostapd_notif_disassoc_mld(assoc_hapd, sta, addr);
1086 return;
1087 }
1088
1089legacy:
1090#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001091 if (sta == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001092 wpa_printf(MSG_DEBUG,
1093 "Disassociation notification for unknown STA "
1094 MACSTR, MAC2STR(addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001095 return;
1096 }
1097
Sunil Ravi99c035e2024-07-12 01:42:03 +00001098 hostapd_remove_sta(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001099}
1100
1101
1102void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
1103{
1104 struct sta_info *sta = ap_get_sta(hapd, addr);
Sunil Ravic0f5d412024-09-11 22:12:49 +00001105#ifdef CONFIG_IEEE80211BE
1106 struct hostapd_data *orig_hapd = hapd;
1107
1108 if (!sta && hapd->conf->mld_ap) {
1109 hapd = hostapd_find_by_sta(hapd->iface, addr, true, &sta);
1110 if (!hapd) {
1111 wpa_printf(MSG_DEBUG,
1112 "No partner link BSS found for STA " MACSTR
1113 " - fallback to received context",
1114 MAC2STR(addr));
1115 hapd = orig_hapd;
1116 }
1117 }
1118#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001119
Roshan Pius3a1667e2018-07-03 15:17:14 -07001120 if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001121 return;
1122
1123 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001124 HOSTAPD_LEVEL_INFO,
1125 "disconnected due to excessive missing ACKs");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001126 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001127 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001128}
1129
1130
Roshan Pius3a1667e2018-07-03 15:17:14 -07001131void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr,
1132 enum smps_mode smps_mode,
1133 enum chan_width chan_width, u8 rx_nss)
1134{
1135 struct sta_info *sta = ap_get_sta(hapd, addr);
1136 const char *txt;
1137
1138 if (!sta)
1139 return;
1140
1141 switch (smps_mode) {
1142 case SMPS_AUTOMATIC:
1143 txt = "automatic";
1144 break;
1145 case SMPS_OFF:
1146 txt = "off";
1147 break;
1148 case SMPS_DYNAMIC:
1149 txt = "dynamic";
1150 break;
1151 case SMPS_STATIC:
1152 txt = "static";
1153 break;
1154 default:
1155 txt = NULL;
1156 break;
1157 }
1158 if (txt) {
1159 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED
1160 MACSTR " %s", MAC2STR(addr), txt);
1161 }
1162
1163 switch (chan_width) {
1164 case CHAN_WIDTH_20_NOHT:
1165 txt = "20(no-HT)";
1166 break;
1167 case CHAN_WIDTH_20:
1168 txt = "20";
1169 break;
1170 case CHAN_WIDTH_40:
1171 txt = "40";
1172 break;
1173 case CHAN_WIDTH_80:
1174 txt = "80";
1175 break;
1176 case CHAN_WIDTH_80P80:
1177 txt = "80+80";
1178 break;
1179 case CHAN_WIDTH_160:
1180 txt = "160";
1181 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001182 case CHAN_WIDTH_320:
1183 txt = "320";
1184 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001185 default:
1186 txt = NULL;
1187 break;
1188 }
1189 if (txt) {
1190 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED
1191 MACSTR " %s", MAC2STR(addr), txt);
1192 }
1193
1194 if (rx_nss != 0xff) {
1195 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED
1196 MACSTR " %d", MAC2STR(addr), rx_nss);
1197 }
1198}
1199
1200
Dmitry Shmidt04949592012-07-19 12:16:46 -07001201void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001202 int offset, int width, int cf1, int cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07001203 u16 punct_bitmap, int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001204{
1205#ifdef NEED_AP_MLME
Sunil Ravi77d572f2023-01-17 23:58:31 +00001206 int channel, chwidth, is_dfs0, is_dfs;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001207 u8 seg0_idx = 0, seg1_idx = 0, op_class, chan_no;
Hai Shalom74f70d42019-02-11 14:42:39 -08001208 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001209
1210 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001211 HOSTAPD_LEVEL_INFO,
Sunil Ravi036cec52023-03-29 11:35:17 -07001212 "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 -07001213 finished ? "had" : "starting",
Sunil Ravi77d572f2023-01-17 23:58:31 +00001214 hapd->iface->freq,
Hai Shalom60840252021-02-19 19:02:11 -08001215 freq, ht, hapd->iconf->ch_switch_vht_config,
Sunil Ravia04bd252022-05-02 22:54:18 -07001216 hapd->iconf->ch_switch_he_config,
1217 hapd->iconf->ch_switch_eht_config, offset,
Sunil Ravi036cec52023-03-29 11:35:17 -07001218 width, channel_width_to_string(width), cf1, cf2,
1219 punct_bitmap);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001220
Hai Shalom1dc4d202019-04-29 16:22:27 -07001221 if (!hapd->iface->current_mode) {
1222 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1223 HOSTAPD_LEVEL_WARNING,
1224 "ignore channel switch since the interface is not yet ready");
1225 return;
1226 }
1227
Sunil Ravi77d572f2023-01-17 23:58:31 +00001228 /* Check if any of configured channels require DFS */
1229 is_dfs0 = hostapd_is_dfs_required(hapd->iface);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001230 hapd->iface->freq = freq;
1231
1232 channel = hostapd_hw_get_channel(hapd, freq);
1233 if (!channel) {
1234 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001235 HOSTAPD_LEVEL_WARNING,
1236 "driver switched to bad channel!");
Dmitry Shmidt04949592012-07-19 12:16:46 -07001237 return;
1238 }
1239
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001240 switch (width) {
1241 case CHAN_WIDTH_80:
Sunil8cd6f4d2022-06-28 18:40:46 +00001242 chwidth = CONF_OPER_CHWIDTH_80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001243 break;
1244 case CHAN_WIDTH_80P80:
Sunil8cd6f4d2022-06-28 18:40:46 +00001245 chwidth = CONF_OPER_CHWIDTH_80P80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001246 break;
1247 case CHAN_WIDTH_160:
Sunil8cd6f4d2022-06-28 18:40:46 +00001248 chwidth = CONF_OPER_CHWIDTH_160MHZ;
1249 break;
1250 case CHAN_WIDTH_320:
1251 chwidth = CONF_OPER_CHWIDTH_320MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001252 break;
1253 case CHAN_WIDTH_20_NOHT:
1254 case CHAN_WIDTH_20:
1255 case CHAN_WIDTH_40:
1256 default:
Sunil8cd6f4d2022-06-28 18:40:46 +00001257 chwidth = CONF_OPER_CHWIDTH_USE_HT;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001258 break;
1259 }
1260
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001261 /* The operating channel changed when CSA finished, so need to update
1262 * hw_mode for all following operations to cover the cases where the
1263 * driver changed the operating band. */
1264 if (finished && hostapd_csa_update_hwmode(hapd->iface))
1265 return;
1266
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001267 switch (hapd->iface->current_mode->mode) {
1268 case HOSTAPD_MODE_IEEE80211A:
Hai Shalom899fcc72020-10-19 14:38:18 -07001269 if (cf1 == 5935)
1270 seg0_idx = (cf1 - 5925) / 5;
1271 else if (cf1 > 5950)
1272 seg0_idx = (cf1 - 5950) / 5;
1273 else if (cf1 > 5000)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001274 seg0_idx = (cf1 - 5000) / 5;
Hai Shalom899fcc72020-10-19 14:38:18 -07001275
1276 if (cf2 == 5935)
1277 seg1_idx = (cf2 - 5925) / 5;
1278 else if (cf2 > 5950)
1279 seg1_idx = (cf2 - 5950) / 5;
1280 else if (cf2 > 5000)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001281 seg1_idx = (cf2 - 5000) / 5;
1282 break;
1283 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001284 ieee80211_freq_to_chan(cf1, &seg0_idx);
1285 ieee80211_freq_to_chan(cf2, &seg1_idx);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001286 break;
1287 }
1288
Dmitry Shmidt04949592012-07-19 12:16:46 -07001289 hapd->iconf->channel = channel;
1290 hapd->iconf->ieee80211n = ht;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001291 if (!ht)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001292 hapd->iconf->ieee80211ac = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001293 if (hapd->iconf->ch_switch_vht_config) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001294 /* CHAN_SWITCH VHT config */
1295 if (hapd->iconf->ch_switch_vht_config &
1296 CH_SWITCH_VHT_ENABLED)
1297 hapd->iconf->ieee80211ac = 1;
1298 else if (hapd->iconf->ch_switch_vht_config &
1299 CH_SWITCH_VHT_DISABLED)
1300 hapd->iconf->ieee80211ac = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001301 }
1302 if (hapd->iconf->ch_switch_he_config) {
Hai Shalom60840252021-02-19 19:02:11 -08001303 /* CHAN_SWITCH HE config */
1304 if (hapd->iconf->ch_switch_he_config &
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001305 CH_SWITCH_HE_ENABLED) {
Hai Shalom60840252021-02-19 19:02:11 -08001306 hapd->iconf->ieee80211ax = 1;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001307 if (hapd->iface->freq > 4000 &&
1308 hapd->iface->freq < 5895)
1309 hapd->iconf->ieee80211ac = 1;
1310 }
Hai Shalom60840252021-02-19 19:02:11 -08001311 else if (hapd->iconf->ch_switch_he_config &
1312 CH_SWITCH_HE_DISABLED)
1313 hapd->iconf->ieee80211ax = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001314 }
Sunil Ravia04bd252022-05-02 22:54:18 -07001315#ifdef CONFIG_IEEE80211BE
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001316 if (hapd->iconf->ch_switch_eht_config) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001317 /* CHAN_SWITCH EHT config */
1318 if (hapd->iconf->ch_switch_eht_config &
1319 CH_SWITCH_EHT_ENABLED) {
1320 hapd->iconf->ieee80211be = 1;
1321 hapd->iconf->ieee80211ax = 1;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001322 if (!is_6ghz_freq(hapd->iface->freq) &&
1323 hapd->iface->freq > 4000)
Sunil Ravia04bd252022-05-02 22:54:18 -07001324 hapd->iconf->ieee80211ac = 1;
1325 } else if (hapd->iconf->ch_switch_eht_config &
1326 CH_SWITCH_EHT_DISABLED)
1327 hapd->iconf->ieee80211be = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001328 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001329#endif /* CONFIG_IEEE80211BE */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001330 hapd->iconf->ch_switch_vht_config = 0;
Hai Shalom60840252021-02-19 19:02:11 -08001331 hapd->iconf->ch_switch_he_config = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -07001332 hapd->iconf->ch_switch_eht_config = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001333
Hai Shaloma20dcd72022-02-04 13:43:00 -08001334 if (width == CHAN_WIDTH_40 || width == CHAN_WIDTH_80 ||
Sunil Ravi640215c2023-06-28 23:08:09 +00001335 width == CHAN_WIDTH_80P80 || width == CHAN_WIDTH_160 ||
1336 width == CHAN_WIDTH_320)
Hai Shaloma20dcd72022-02-04 13:43:00 -08001337 hapd->iconf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1338 else if (width == CHAN_WIDTH_20 || width == CHAN_WIDTH_20_NOHT)
1339 hapd->iconf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1340
Dmitry Shmidt04949592012-07-19 12:16:46 -07001341 hapd->iconf->secondary_channel = offset;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001342 if (ieee80211_freq_to_channel_ext(freq, offset, chwidth,
1343 &op_class, &chan_no) !=
1344 NUM_HOSTAPD_MODES)
1345 hapd->iconf->op_class = op_class;
Hai Shalom81f62d82019-07-22 12:10:00 -07001346 hostapd_set_oper_chwidth(hapd->iconf, chwidth);
1347 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, seg0_idx);
1348 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, seg1_idx);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001349 /* Auto-detect new bw320_offset */
1350 hostapd_set_and_check_bw320_offset(hapd->iconf, 0);
Sunil Ravi036cec52023-03-29 11:35:17 -07001351#ifdef CONFIG_IEEE80211BE
1352 hapd->iconf->punct_bitmap = punct_bitmap;
1353#endif /* CONFIG_IEEE80211BE */
Hai Shaloma20dcd72022-02-04 13:43:00 -08001354 if (hapd->iconf->ieee80211ac) {
1355 hapd->iconf->vht_capab &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
Sunil8cd6f4d2022-06-28 18:40:46 +00001356 if (chwidth == CONF_OPER_CHWIDTH_160MHZ)
Hai Shaloma20dcd72022-02-04 13:43:00 -08001357 hapd->iconf->vht_capab |=
1358 VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Sunil8cd6f4d2022-06-28 18:40:46 +00001359 else if (chwidth == CONF_OPER_CHWIDTH_80P80MHZ)
Hai Shaloma20dcd72022-02-04 13:43:00 -08001360 hapd->iconf->vht_capab |=
1361 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1362 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001363
Roshan Pius3a1667e2018-07-03 15:17:14 -07001364 is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features,
1365 hapd->iface->num_hw_features);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001366
Hai Shalom81f62d82019-07-22 12:10:00 -07001367 wpa_msg(hapd->msg_ctx, MSG_INFO,
Sunil Ravi036cec52023-03-29 11:35:17 -07001368 "%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 -07001369 finished ? WPA_EVENT_CHANNEL_SWITCH :
1370 WPA_EVENT_CHANNEL_SWITCH_STARTED,
1371 freq, ht, offset, channel_width_to_string(width),
Sunil Ravi036cec52023-03-29 11:35:17 -07001372 cf1, cf2, is_dfs0, is_dfs, punct_bitmap);
Hai Shalom81f62d82019-07-22 12:10:00 -07001373 if (!finished)
1374 return;
1375
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001376 if (hapd->csa_in_progress &&
1377 freq == hapd->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001378 hostapd_cleanup_cs_params(hapd);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001379 ieee802_11_set_beacon(hapd);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001380
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001381 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
1382 "freq=%d dfs=%d", freq, is_dfs);
1383 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00001384 /* Complete AP configuration for the first bring up. */
1385 if (is_dfs0 > 0 &&
1386 hostapd_is_dfs_required(hapd->iface) <= 0 &&
1387 hapd->iface->state != HAPD_IFACE_ENABLED) {
1388 /* Fake a CAC start bit to skip setting channel */
1389 hapd->iface->cac_started = 1;
1390 hostapd_setup_interface_complete(hapd->iface, 0);
1391 }
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001392 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
1393 "freq=%d dfs=%d", freq, is_dfs);
Hai Shalomfdcde762020-04-02 11:19:20 -07001394 } else if (is_dfs &&
1395 hostapd_is_dfs_required(hapd->iface) &&
1396 !hostapd_is_dfs_chan_available(hapd->iface) &&
1397 !hapd->iface->cac_started) {
1398 hostapd_disable_iface(hapd->iface);
1399 hostapd_enable_iface(hapd->iface);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001400 }
Hai Shalom74f70d42019-02-11 14:42:39 -08001401
1402 for (i = 0; i < hapd->iface->num_bss; i++)
1403 hostapd_neighbor_set_own_report(hapd->iface->bss[i]);
Hai Shalom899fcc72020-10-19 14:38:18 -07001404
1405#ifdef CONFIG_OCV
Sunil Ravia04bd252022-05-02 22:54:18 -07001406 if (hapd->conf->ocv &&
1407 !(hapd->iface->drv_flags2 &
1408 WPA_DRIVER_FLAGS2_SA_QUERY_OFFLOAD_AP)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001409 struct sta_info *sta;
1410 bool check_sa_query = false;
1411
1412 for (sta = hapd->sta_list; sta; sta = sta->next) {
1413 if (wpa_auth_uses_ocv(sta->wpa_sm) &&
1414 !(sta->flags & WLAN_STA_WNM_SLEEP_MODE)) {
1415 sta->post_csa_sa_query = 1;
1416 check_sa_query = true;
1417 }
1418 }
1419
1420 if (check_sa_query) {
1421 wpa_printf(MSG_DEBUG,
1422 "OCV: Check post-CSA SA Query initiation in 15 seconds");
1423 eloop_register_timeout(15, 0,
1424 hostapd_ocv_check_csa_sa_query,
1425 hapd, NULL);
1426 }
1427 }
1428#endif /* CONFIG_OCV */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001429#endif /* NEED_AP_MLME */
1430}
1431
1432
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001433void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
1434 const u8 *addr, int reason_code)
1435{
1436 switch (reason_code) {
1437 case MAX_CLIENT_REACHED:
1438 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
1439 MAC2STR(addr));
1440 break;
1441 case BLOCKED_CLIENT:
1442 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
1443 MAC2STR(addr));
1444 break;
1445 }
1446}
1447
1448
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001449#ifdef CONFIG_ACS
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001450void hostapd_acs_channel_selected(struct hostapd_data *hapd,
1451 struct acs_selected_channels *acs_res)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001452{
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001453 int ret, i;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001454 int err = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001455 struct hostapd_channel_data *pri_chan;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001456
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001457#ifdef CONFIG_IEEE80211BE
1458 if (acs_res->link_id != -1) {
1459 hapd = hostapd_mld_get_link_bss(hapd, acs_res->link_id);
1460 if (!hapd) {
1461 wpa_printf(MSG_ERROR,
1462 "MLD: Failed to get link BSS for EVENT_ACS_CHANNEL_SELECTED link_id=%d",
1463 acs_res->link_id);
1464 return;
1465 }
1466 }
1467#endif /* CONFIG_IEEE80211BE */
1468
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001469 if (hapd->iconf->channel) {
1470 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
1471 hapd->iconf->channel);
1472 return;
1473 }
1474
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001475 hapd->iface->freq = acs_res->pri_freq;
1476
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001477 if (!hapd->iface->current_mode) {
1478 for (i = 0; i < hapd->iface->num_hw_features; i++) {
1479 struct hostapd_hw_modes *mode =
1480 &hapd->iface->hw_features[i];
1481
1482 if (mode->mode == acs_res->hw_mode) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001483 if (hapd->iface->freq > 0 &&
1484 !hw_get_chan(mode->mode,
1485 hapd->iface->freq,
1486 hapd->iface->hw_features,
1487 hapd->iface->num_hw_features))
1488 continue;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001489 hapd->iface->current_mode = mode;
1490 break;
1491 }
1492 }
1493 if (!hapd->iface->current_mode) {
1494 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1495 HOSTAPD_LEVEL_WARNING,
1496 "driver selected to bad hw_mode");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001497 err = 1;
1498 goto out;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001499 }
1500 }
1501
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001502 if (!acs_res->pri_freq) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001503 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1504 HOSTAPD_LEVEL_WARNING,
1505 "driver switched to bad channel");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001506 err = 1;
1507 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001508 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001509 pri_chan = hw_get_channel_freq(hapd->iface->current_mode->mode,
1510 acs_res->pri_freq, NULL,
1511 hapd->iface->hw_features,
1512 hapd->iface->num_hw_features);
1513 if (!pri_chan) {
1514 wpa_printf(MSG_ERROR,
1515 "ACS: Could not determine primary channel number from pri_freq %u",
1516 acs_res->pri_freq);
1517 err = 1;
1518 goto out;
1519 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001520
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001521 hapd->iconf->channel = pri_chan->chan;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001522 hapd->iconf->acs = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001523
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001524 if (acs_res->sec_freq == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001525 hapd->iconf->secondary_channel = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001526 else if (acs_res->sec_freq < acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001527 hapd->iconf->secondary_channel = -1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001528 else if (acs_res->sec_freq > acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001529 hapd->iconf->secondary_channel = 1;
1530 else {
1531 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001532 err = 1;
1533 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001534 }
1535
Hai Shalomfdcde762020-04-02 11:19:20 -07001536 hapd->iconf->edmg_channel = acs_res->edmg_channel;
1537
Hai Shalom81f62d82019-07-22 12:10:00 -07001538 if (hapd->iface->conf->ieee80211ac || hapd->iface->conf->ieee80211ax) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001539 /* set defaults for backwards compatibility */
Hai Shalom81f62d82019-07-22 12:10:00 -07001540 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1541 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, 0);
Sunil8cd6f4d2022-06-28 18:40:46 +00001542 hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_USE_HT);
Hai Shalomfdcde762020-04-02 11:19:20 -07001543 if (acs_res->ch_width == 40) {
1544 if (is_6ghz_freq(acs_res->pri_freq))
1545 hostapd_set_oper_centr_freq_seg0_idx(
1546 hapd->iconf,
1547 acs_res->vht_seg0_center_ch);
1548 } else if (acs_res->ch_width == 80) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001549 hostapd_set_oper_centr_freq_seg0_idx(
1550 hapd->iconf, acs_res->vht_seg0_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001551 if (acs_res->vht_seg1_center_ch == 0) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001552 hostapd_set_oper_chwidth(
1553 hapd->iconf, CONF_OPER_CHWIDTH_80MHZ);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001554 } else {
Sunil8cd6f4d2022-06-28 18:40:46 +00001555 hostapd_set_oper_chwidth(
1556 hapd->iconf,
1557 CONF_OPER_CHWIDTH_80P80MHZ);
Hai Shalom81f62d82019-07-22 12:10:00 -07001558 hostapd_set_oper_centr_freq_seg1_idx(
1559 hapd->iconf,
1560 acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001561 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001562 } else if (acs_res->ch_width == 160) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001563 hostapd_set_oper_chwidth(hapd->iconf,
1564 CONF_OPER_CHWIDTH_160MHZ);
Hai Shalomfdcde762020-04-02 11:19:20 -07001565 hostapd_set_oper_centr_freq_seg0_idx(
1566 hapd->iconf, acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001567 }
1568 }
1569
Sunil8cd6f4d2022-06-28 18:40:46 +00001570#ifdef CONFIG_IEEE80211BE
1571 if (hapd->iface->conf->ieee80211be && acs_res->ch_width == 320) {
1572 hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_320MHZ);
1573 hostapd_set_oper_centr_freq_seg0_idx(
1574 hapd->iconf, acs_res->vht_seg1_center_ch);
1575 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1576 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001577
1578 if (hapd->iface->conf->ieee80211be && acs_res->puncture_bitmap)
1579 hapd->iconf->punct_bitmap = acs_res->puncture_bitmap;
Sunil8cd6f4d2022-06-28 18:40:46 +00001580#endif /* CONFIG_IEEE80211BE */
1581
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001582out:
1583 ret = hostapd_acs_completed(hapd->iface, err);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001584 if (ret) {
1585 wpa_printf(MSG_ERROR,
1586 "ACS: Possibly channel configuration is invalid");
1587 }
1588}
1589#endif /* CONFIG_ACS */
1590
1591
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001592int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001593 const u8 *bssid, const u8 *ie, size_t ie_len,
1594 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001595{
1596 size_t i;
1597 int ret = 0;
1598
1599 if (sa == NULL || ie == NULL)
1600 return -1;
1601
1602 random_add_randomness(sa, ETH_ALEN);
1603 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
1604 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001605 sa, da, bssid, ie, ie_len,
1606 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001607 ret = 1;
1608 break;
1609 }
1610 }
1611 return ret;
1612}
1613
1614
1615#ifdef HOSTAPD
1616
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001617#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001618static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001619 u16 auth_transaction, u16 status,
1620 const u8 *ies, size_t ies_len)
1621{
1622 struct hostapd_data *hapd = ctx;
1623 struct sta_info *sta;
1624
1625 sta = ap_get_sta(hapd, dst);
1626 if (sta == NULL)
1627 return;
1628
1629 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
1630 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
1631 sta->flags |= WLAN_STA_AUTH;
1632
1633 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
1634}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001635#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001636
1637
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001638#ifdef CONFIG_FILS
1639static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
1640 struct sta_info *sta, u16 resp,
1641 struct wpabuf *data, int pub)
1642{
1643 if (resp == WLAN_STATUS_SUCCESS) {
1644 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1645 HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
1646 sta->flags |= WLAN_STA_AUTH;
1647 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1648 sta->auth_alg = WLAN_AUTH_FILS_SK;
1649 mlme_authenticate_indication(hapd, sta);
1650 } else {
1651 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1652 HOSTAPD_LEVEL_DEBUG,
1653 "authentication failed (FILS)");
1654 }
1655
1656 hostapd_sta_auth(hapd, sta->addr, 2, resp,
1657 data ? wpabuf_head(data) : NULL,
1658 data ? wpabuf_len(data) : 0);
1659 wpabuf_free(data);
1660}
1661#endif /* CONFIG_FILS */
1662
1663
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001664static void hostapd_notif_auth(struct hostapd_data *hapd,
1665 struct auth_info *rx_auth)
1666{
1667 struct sta_info *sta;
1668 u16 status = WLAN_STATUS_SUCCESS;
1669 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1670 size_t resp_ies_len = 0;
1671
1672 sta = ap_get_sta(hapd, rx_auth->peer);
1673 if (!sta) {
1674 sta = ap_sta_add(hapd, rx_auth->peer);
1675 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -07001676 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001677 goto fail;
1678 }
1679 }
1680 sta->flags &= ~WLAN_STA_PREAUTH;
1681 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001682#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001683 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
1684 sta->auth_alg = WLAN_AUTH_FT;
1685 if (sta->wpa_sm == NULL)
1686 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001687 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001688 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001689 wpa_printf(MSG_DEBUG,
1690 "FT: Failed to initialize WPA state machine");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001691 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1692 goto fail;
1693 }
Sunil Ravi7f769292024-07-23 22:21:32 +00001694 wpa_ft_process_auth(sta->wpa_sm,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001695 rx_auth->auth_transaction, rx_auth->ies,
1696 rx_auth->ies_len,
1697 hostapd_notify_auth_ft_finish, hapd);
1698 return;
1699 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001700#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001701
1702#ifdef CONFIG_FILS
1703 if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
1704 sta->auth_alg = WLAN_AUTH_FILS_SK;
1705 handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
1706 rx_auth->auth_type, rx_auth->auth_transaction,
1707 rx_auth->status_code,
1708 hostapd_notify_auth_fils_finish);
1709 return;
1710 }
1711#endif /* CONFIG_FILS */
1712
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001713fail:
1714 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
1715 status, resp_ies, resp_ies_len);
1716}
1717
1718
Hai Shalom021b0b52019-04-10 11:17:58 -07001719#ifndef NEED_AP_MLME
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001720static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001721 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001722{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001723 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001724 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001725 size_t plen __maybe_unused;
1726 u16 fc;
Hai Shalom74f70d42019-02-11 14:42:39 -08001727 u8 *action __maybe_unused;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001728
Hai Shalom74f70d42019-02-11 14:42:39 -08001729 if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001730 return;
1731
Hai Shalom021b0b52019-04-10 11:17:58 -07001732 plen = drv_mgmt->frame_len - IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001733
1734 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
1735 fc = le_to_host16(mgmt->frame_control);
1736 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
1737 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001738
Hai Shalom74f70d42019-02-11 14:42:39 -08001739 action = (u8 *) &mgmt->u.action.u;
1740 wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
1741 " da " MACSTR " plen %d",
1742 mgmt->u.action.category, *action,
1743 MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001744
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001745 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001746 if (sta == NULL) {
1747 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
1748 return;
1749 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001750#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001751 if (mgmt->u.action.category == WLAN_ACTION_FT) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001752 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, plen);
1753 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001754 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001755#endif /* CONFIG_IEEE80211R_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001756 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001757 ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001758 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001759 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001760#ifdef CONFIG_WNM_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001761 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
1762 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001763 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001764 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001765#endif /* CONFIG_WNM_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001766#ifdef CONFIG_FST
1767 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
1768 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
1769 return;
1770 }
1771#endif /* CONFIG_FST */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001772#ifdef CONFIG_DPP
Hai Shalom021b0b52019-04-10 11:17:58 -07001773 if (plen >= 2 + 4 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001774 mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001775 mgmt->u.action.u.vs_public_action.action ==
1776 WLAN_PA_VENDOR_SPECIFIC &&
1777 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1778 OUI_WFA &&
1779 mgmt->u.action.u.vs_public_action.variable[0] ==
1780 DPP_OUI_TYPE) {
1781 const u8 *pos, *end;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001782
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001783 pos = mgmt->u.action.u.vs_public_action.oui;
1784 end = drv_mgmt->frame + drv_mgmt->frame_len;
1785 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
1786 drv_mgmt->freq);
1787 return;
1788 }
1789#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001790#ifdef CONFIG_NAN_USD
1791 if (mgmt->u.action.category == WLAN_ACTION_PUBLIC && plen >= 5 &&
1792 mgmt->u.action.u.vs_public_action.action ==
1793 WLAN_PA_VENDOR_SPECIFIC &&
1794 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1795 OUI_WFA &&
1796 mgmt->u.action.u.vs_public_action.variable[0] == NAN_OUI_TYPE) {
1797 const u8 *pos, *end;
1798
1799 pos = mgmt->u.action.u.vs_public_action.variable;
1800 end = drv_mgmt->frame + drv_mgmt->frame_len;
1801 pos++;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001802 hostapd_nan_usd_rx_sdf(hapd, mgmt->sa, mgmt->bssid,
1803 drv_mgmt->freq, pos, end - pos);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001804 return;
1805 }
1806#endif /* CONFIG_NAN_USD */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001807}
Hai Shalom021b0b52019-04-10 11:17:58 -07001808#endif /* NEED_AP_MLME */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001809
1810
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001811#ifdef NEED_AP_MLME
1812
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001813static struct hostapd_data *
1814switch_link_hapd(struct hostapd_data *hapd, int link_id)
1815{
1816#ifdef CONFIG_IEEE80211BE
1817 if (hapd->conf->mld_ap && link_id >= 0) {
1818 struct hostapd_data *link_bss;
1819
1820 link_bss = hostapd_mld_get_link_bss(hapd, link_id);
1821 if (link_bss)
1822 return link_bss;
1823 }
1824#endif /* CONFIG_IEEE80211BE */
1825
1826 return hapd;
1827}
1828
1829
Sunil Ravi99c035e2024-07-12 01:42:03 +00001830static struct hostapd_data *
1831switch_link_scan(struct hostapd_data *hapd, u64 scan_cookie)
1832{
1833#ifdef CONFIG_IEEE80211BE
1834 if (hapd->conf->mld_ap && scan_cookie != 0) {
1835 unsigned int i;
1836
1837 for (i = 0; i < hapd->iface->interfaces->count; i++) {
1838 struct hostapd_iface *h;
1839 struct hostapd_data *h_hapd;
1840
1841 h = hapd->iface->interfaces->iface[i];
1842 h_hapd = h->bss[0];
1843 if (!hostapd_is_ml_partner(hapd, h_hapd))
1844 continue;
1845
1846 if (h_hapd->scan_cookie == scan_cookie) {
1847 h_hapd->scan_cookie = 0;
1848 return h_hapd;
1849 }
1850 }
1851 }
1852#endif /* CONFIG_IEEE80211BE */
1853
1854 return hapd;
1855}
1856
1857
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001858#define HAPD_BROADCAST ((struct hostapd_data *) -1)
1859
1860static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
Sunil Ravi7f769292024-07-23 22:21:32 +00001861 const u8 *bssid, int link_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001862{
1863 size_t i;
1864
1865 if (bssid == NULL)
1866 return NULL;
1867 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1868 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1869 return HAPD_BROADCAST;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00001870#ifdef CONFIG_NAN_USD
1871 if (nan_de_is_nan_network_id(bssid))
1872 return HAPD_BROADCAST; /* Process NAN Network ID like broadcast
1873 */
1874#endif /* CONFIG_NAN_USD */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001875
1876 for (i = 0; i < iface->num_bss; i++) {
Sunil Ravi7f769292024-07-23 22:21:32 +00001877 struct hostapd_data *hapd;
1878#ifdef CONFIG_IEEE80211BE
1879 struct hostapd_data *p_hapd;
1880#endif /* CONFIG_IEEE80211BE */
1881
1882 hapd = iface->bss[i];
1883 if (ether_addr_equal(bssid, hapd->own_addr))
1884 return hapd;
1885
1886#ifdef CONFIG_IEEE80211BE
1887 if (ether_addr_equal(bssid, hapd->own_addr) ||
1888 (hapd->conf->mld_ap &&
1889 ether_addr_equal(bssid, hapd->mld->mld_addr) &&
1890 link_id == hapd->mld_link_id))
1891 return hapd;
1892
1893 if (!hapd->conf->mld_ap)
1894 continue;
1895
1896 for_each_mld_link(p_hapd, hapd) {
1897 if (p_hapd == hapd)
1898 continue;
1899
1900 if (ether_addr_equal(bssid, p_hapd->own_addr) ||
1901 (ether_addr_equal(bssid, p_hapd->mld->mld_addr) &&
1902 link_id == p_hapd->mld_link_id))
1903 return p_hapd;
1904 }
1905#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001906 }
1907
1908 return NULL;
1909}
1910
1911
1912static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001913 const u8 *bssid, const u8 *addr,
1914 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001915{
Sunil Ravi7f769292024-07-23 22:21:32 +00001916 hapd = get_hapd_bssid(hapd->iface, bssid, -1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001917 if (hapd == NULL || hapd == HAPD_BROADCAST)
1918 return;
1919
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001920 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001921}
1922
1923
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001924static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001925{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001926 struct hostapd_iface *iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001927 const struct ieee80211_hdr *hdr;
1928 const u8 *bssid;
1929 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001930 int ret;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001931
Sunil Ravi7f769292024-07-23 22:21:32 +00001932 if (rx_mgmt->ctx)
1933 hapd = rx_mgmt->ctx;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001934 hapd = switch_link_hapd(hapd, rx_mgmt->link_id);
1935 iface = hapd->iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001936
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001937#ifdef CONFIG_TESTING_OPTIONS
1938 if (hapd->ext_mgmt_frame_handling) {
1939 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
1940 char *hex = os_malloc(hex_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001941
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001942 if (hex) {
1943 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
1944 rx_mgmt->frame_len);
1945 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1946 os_free(hex);
1947 }
1948 return 1;
1949 }
1950#endif /* CONFIG_TESTING_OPTIONS */
1951
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001952 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1953 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
1954 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001955 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001956
Sunil Ravi7f769292024-07-23 22:21:32 +00001957 hapd = get_hapd_bssid(iface, bssid, rx_mgmt->link_id);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001958
1959 if (!hapd) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001960 u16 fc = le_to_host16(hdr->frame_control);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001961
1962 /*
1963 * Drop frames to unknown BSSIDs except for Beacon frames which
1964 * could be used to update neighbor information.
1965 */
1966 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1967 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1968 hapd = iface->bss[0];
1969 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001970 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001971 }
1972
1973 os_memset(&fi, 0, sizeof(fi));
Roshan Pius3a1667e2018-07-03 15:17:14 -07001974 fi.freq = rx_mgmt->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001975 fi.datarate = rx_mgmt->datarate;
1976 fi.ssi_signal = rx_mgmt->ssi_signal;
1977
1978 if (hapd == HAPD_BROADCAST) {
1979 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001980
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001981 ret = 0;
1982 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -07001983 /* if bss is set, driver will call this function for
1984 * each bss individually. */
1985 if (rx_mgmt->drv_priv &&
1986 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
1987 continue;
1988
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001989 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
1990 rx_mgmt->frame_len, &fi) > 0)
1991 ret = 1;
1992 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001993 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001994 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
1995 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001996
1997 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001998
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001999 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07002000}
2001
2002
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002003static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002004 size_t len, u16 stype, int ok, int link_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002005{
2006 struct ieee80211_hdr *hdr;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002007 struct hostapd_data *orig_hapd, *tmp_hapd;
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00002008 const u8 *bssid;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002009
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002010 orig_hapd = hapd;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002011
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002012 hdr = (struct ieee80211_hdr *) buf;
Sunil Ravi7f769292024-07-23 22:21:32 +00002013 hapd = switch_link_hapd(hapd, link_id);
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00002014 bssid = get_hdr_bssid(hdr, len);
2015 tmp_hapd = get_hapd_bssid(hapd->iface, bssid, link_id);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002016 if (tmp_hapd) {
2017 hapd = tmp_hapd;
2018#ifdef CONFIG_IEEE80211BE
Sunil Ravi79e6c4f2025-01-04 00:47:06 +00002019 } else if (hapd->conf->mld_ap && bssid &&
2020 ether_addr_equal(hapd->mld->mld_addr, bssid)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002021 /* AP MLD address match - use hapd pointer as-is */
2022#endif /* CONFIG_IEEE80211BE */
2023 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002024 return;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002025 }
2026
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002027 if (hapd == HAPD_BROADCAST) {
2028 if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
2029 buf[24] != WLAN_ACTION_PUBLIC)
2030 return;
Sunil Ravi7f769292024-07-23 22:21:32 +00002031 hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2, link_id);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002032 if (!hapd || hapd == HAPD_BROADCAST)
2033 return;
2034 /*
2035 * Allow processing of TX status for a Public Action frame that
2036 * used wildcard BBSID.
2037 */
2038 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002039 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
2040}
2041
2042#endif /* NEED_AP_MLME */
2043
2044
2045static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
2046{
2047 struct sta_info *sta = ap_get_sta(hapd, addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002048
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002049 if (sta)
2050 return 0;
2051
2052 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
2053 " - adding a new STA", MAC2STR(addr));
2054 sta = ap_sta_add(hapd, addr);
2055 if (sta) {
2056 hostapd_new_assoc_sta(hapd, sta, 0);
2057 } else {
2058 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
2059 MAC2STR(addr));
2060 return -1;
2061 }
2062
2063 return 0;
2064}
2065
2066
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002067static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
2068 const u8 *data, size_t data_len,
2069 enum frame_encryption encrypted,
2070 int link_id)
2071{
2072 struct hostapd_data *orig_hapd = hapd;
2073
2074#ifdef CONFIG_IEEE80211BE
Sunil Ravi7f769292024-07-23 22:21:32 +00002075 hapd = switch_link_hapd(hapd, link_id);
2076 hapd = hostapd_find_by_sta(hapd->iface, src, true, NULL);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002077#else /* CONFIG_IEEE80211BE */
Sunil Ravi7f769292024-07-23 22:21:32 +00002078 hapd = hostapd_find_by_sta(hapd->iface, src, false, NULL);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002079#endif /* CONFIG_IEEE80211BE */
2080
2081 if (!hapd) {
2082 /* WLAN cases need to have an existing association, but non-WLAN
2083 * cases (mainly, wired IEEE 802.1X) need to be able to process
2084 * EAPOL frames from new devices that do not yet have a STA
2085 * entry and as such, do not get a match in
2086 * hostapd_find_by_sta(). */
2087 wpa_printf(MSG_DEBUG,
2088 "No STA-specific hostapd instance for EAPOL RX found - fall back to initial context");
2089 hapd = orig_hapd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002090 }
2091
Sunil8cd6f4d2022-06-28 18:40:46 +00002092 ieee802_1x_receive(hapd, src, data, data_len, encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002093}
2094
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002095#endif /* HOSTAPD */
2096
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002097
Hai Shalomfdcde762020-04-02 11:19:20 -07002098static struct hostapd_channel_data *
2099hostapd_get_mode_chan(struct hostapd_hw_modes *mode, unsigned int freq)
2100{
2101 int i;
2102 struct hostapd_channel_data *chan;
2103
2104 for (i = 0; i < mode->num_channels; i++) {
2105 chan = &mode->channels[i];
2106 if ((unsigned int) chan->freq == freq)
2107 return chan;
2108 }
2109
2110 return NULL;
2111}
2112
2113
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002114static struct hostapd_channel_data * hostapd_get_mode_channel(
2115 struct hostapd_iface *iface, unsigned int freq)
2116{
2117 int i;
2118 struct hostapd_channel_data *chan;
2119
Hai Shalomfdcde762020-04-02 11:19:20 -07002120 for (i = 0; i < iface->num_hw_features; i++) {
2121 if (hostapd_hw_skip_mode(iface, &iface->hw_features[i]))
2122 continue;
2123 chan = hostapd_get_mode_chan(&iface->hw_features[i], freq);
2124 if (chan)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002125 return chan;
2126 }
2127
2128 return NULL;
2129}
2130
2131
2132static void hostapd_update_nf(struct hostapd_iface *iface,
2133 struct hostapd_channel_data *chan,
2134 struct freq_survey *survey)
2135{
2136 if (!iface->chans_surveyed) {
2137 chan->min_nf = survey->nf;
2138 iface->lowest_nf = survey->nf;
2139 } else {
2140 if (dl_list_empty(&chan->survey_list))
2141 chan->min_nf = survey->nf;
2142 else if (survey->nf < chan->min_nf)
2143 chan->min_nf = survey->nf;
2144 if (survey->nf < iface->lowest_nf)
2145 iface->lowest_nf = survey->nf;
2146 }
2147}
2148
2149
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002150static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
2151 struct survey_results *survey_res)
2152{
2153 struct hostapd_channel_data *chan;
2154 struct freq_survey *survey;
2155 u64 divisor, dividend;
2156
2157 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
2158 list);
2159 if (!survey || !survey->freq)
2160 return;
2161
2162 chan = hostapd_get_mode_channel(iface, survey->freq);
2163 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
2164 return;
2165
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002166 wpa_printf(MSG_DEBUG,
2167 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002168 survey->freq,
2169 (unsigned long int) survey->channel_time,
2170 (unsigned long int) survey->channel_time_busy);
2171
2172 if (survey->channel_time > iface->last_channel_time &&
2173 survey->channel_time > survey->channel_time_busy) {
2174 dividend = survey->channel_time_busy -
2175 iface->last_channel_time_busy;
2176 divisor = survey->channel_time - iface->last_channel_time;
2177
2178 iface->channel_utilization = dividend * 255 / divisor;
2179 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
2180 iface->channel_utilization);
2181 }
2182 iface->last_channel_time = survey->channel_time;
2183 iface->last_channel_time_busy = survey->channel_time_busy;
2184}
2185
2186
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002187void hostapd_event_get_survey(struct hostapd_iface *iface,
2188 struct survey_results *survey_results)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002189{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002190 struct freq_survey *survey, *tmp;
2191 struct hostapd_channel_data *chan;
2192
2193 if (dl_list_empty(&survey_results->survey_list)) {
2194 wpa_printf(MSG_DEBUG, "No survey data received");
2195 return;
2196 }
2197
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002198 if (survey_results->freq_filter) {
2199 hostapd_single_channel_get_survey(iface, survey_results);
2200 return;
2201 }
2202
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002203 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
2204 struct freq_survey, list) {
2205 chan = hostapd_get_mode_channel(iface, survey->freq);
2206 if (!chan)
2207 continue;
2208 if (chan->flag & HOSTAPD_CHAN_DISABLED)
2209 continue;
2210
2211 dl_list_del(&survey->list);
2212 dl_list_add_tail(&chan->survey_list, &survey->list);
2213
2214 hostapd_update_nf(iface, chan, survey);
2215
2216 iface->chans_surveyed++;
2217 }
2218}
2219
2220
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002221#ifdef HOSTAPD
Dmitry Shmidt051af732013-10-22 13:52:46 -07002222#ifdef NEED_AP_MLME
2223
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002224static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
2225{
2226 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
2227 hapd->conf->iface);
2228
2229 if (hapd->csa_in_progress) {
2230 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
2231 hapd->conf->iface);
2232 hostapd_switch_channel_fallback(hapd->iface,
2233 &hapd->cs_freq_params);
2234 }
Yu Ouyang378d3c42021-08-20 17:31:08 +08002235
2236 // inform framework that interface is unavailable
2237 hostapd_disable_iface(hapd->iface);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002238}
2239
2240
Dmitry Shmidt051af732013-10-22 13:52:46 -07002241static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
2242 struct dfs_event *radar)
2243{
2244 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002245 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002246 radar->chan_offset, radar->chan_width,
2247 radar->cf1, radar->cf2);
2248}
2249
2250
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002251static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
2252 struct dfs_event *radar)
2253{
2254 wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
2255 hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
2256 radar->chan_offset, radar->chan_width,
2257 radar->cf1, radar->cf2);
2258}
2259
2260
Dmitry Shmidt051af732013-10-22 13:52:46 -07002261static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
2262 struct dfs_event *radar)
2263{
2264 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002265 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002266 radar->chan_offset, radar->chan_width,
2267 radar->cf1, radar->cf2);
2268}
2269
2270
2271static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
2272 struct dfs_event *radar)
2273{
2274 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002275 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002276 radar->chan_offset, radar->chan_width,
2277 radar->cf1, radar->cf2);
2278}
2279
2280
2281static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
2282 struct dfs_event *radar)
2283{
2284 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002285 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002286 radar->chan_offset, radar->chan_width,
2287 radar->cf1, radar->cf2);
2288}
2289
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002290
2291static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
2292 struct dfs_event *radar)
2293{
2294 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
2295 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
2296 radar->chan_offset, radar->chan_width,
2297 radar->cf1, radar->cf2);
2298}
2299
Dmitry Shmidt051af732013-10-22 13:52:46 -07002300#endif /* NEED_AP_MLME */
2301
2302
Roshan Pius3a1667e2018-07-03 15:17:14 -07002303static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd,
2304 int istatus,
2305 const char *ifname,
2306 const u8 *addr)
2307{
2308 struct sta_info *sta = ap_get_sta(hapd, addr);
2309
2310 if (sta) {
2311 os_free(sta->ifname_wds);
2312 if (istatus == INTERFACE_ADDED)
2313 sta->ifname_wds = os_strdup(ifname);
2314 else
2315 sta->ifname_wds = NULL;
2316 }
2317
2318 wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR,
2319 istatus == INTERFACE_ADDED ?
2320 WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED,
2321 ifname, MAC2STR(addr));
2322}
2323
2324
Hai Shalom81f62d82019-07-22 12:10:00 -07002325#ifdef CONFIG_OWE
2326static int hostapd_notif_update_dh_ie(struct hostapd_data *hapd,
2327 const u8 *peer, const u8 *ie,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002328 size_t ie_len, const u8 *link_addr)
Hai Shalom81f62d82019-07-22 12:10:00 -07002329{
2330 u16 status;
2331 struct sta_info *sta;
2332 struct ieee802_11_elems elems;
2333
2334 if (!hapd || !hapd->wpa_auth) {
2335 wpa_printf(MSG_DEBUG, "OWE: Invalid hapd context");
2336 return -1;
2337 }
2338 if (!peer) {
2339 wpa_printf(MSG_DEBUG, "OWE: Peer unknown");
2340 return -1;
2341 }
2342 if (!(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) {
2343 wpa_printf(MSG_DEBUG, "OWE: No OWE AKM configured");
2344 status = WLAN_STATUS_AKMP_NOT_VALID;
2345 goto err;
2346 }
2347 if (ieee802_11_parse_elems(ie, ie_len, &elems, 1) == ParseFailed) {
2348 wpa_printf(MSG_DEBUG, "OWE: Failed to parse OWE IE for "
2349 MACSTR, MAC2STR(peer));
2350 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
2351 goto err;
2352 }
2353 status = owe_validate_request(hapd, peer, elems.rsn_ie,
2354 elems.rsn_ie_len,
2355 elems.owe_dh, elems.owe_dh_len);
2356 if (status != WLAN_STATUS_SUCCESS)
2357 goto err;
2358
2359 sta = ap_get_sta(hapd, peer);
2360 if (sta) {
2361 ap_sta_no_session_timeout(hapd, sta);
2362 accounting_sta_stop(hapd, sta);
2363
2364 /*
2365 * Make sure that the previously registered inactivity timer
2366 * will not remove the STA immediately.
2367 */
2368 sta->timeout_next = STA_NULLFUNC;
2369 } else {
2370 sta = ap_sta_add(hapd, peer);
2371 if (!sta) {
2372 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
2373 goto err;
2374 }
2375 }
2376 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
2377
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002378#ifdef CONFIG_IEEE80211BE
2379 if (link_addr) {
2380 struct mld_info *info = &sta->mld_info;
2381 u8 link_id = hapd->mld_link_id;
2382
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002383 ap_sta_set_mld(sta, true);
2384 sta->mld_assoc_link_id = link_id;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002385 os_memcpy(info->common_info.mld_addr, peer, ETH_ALEN);
2386 info->links[link_id].valid = true;
2387 os_memcpy(info->links[link_id].local_addr, hapd->own_addr,
2388 ETH_ALEN);
2389 os_memcpy(info->links[link_id].peer_addr, link_addr, ETH_ALEN);
2390 }
2391#endif /* CONFIG_IEEE80211BE */
2392
Hai Shalom81f62d82019-07-22 12:10:00 -07002393 status = owe_process_rsn_ie(hapd, sta, elems.rsn_ie,
2394 elems.rsn_ie_len, elems.owe_dh,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002395 elems.owe_dh_len, link_addr);
Hai Shalom81f62d82019-07-22 12:10:00 -07002396 if (status != WLAN_STATUS_SUCCESS)
2397 ap_free_sta(hapd, sta);
2398
2399 return 0;
2400err:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002401 hostapd_drv_update_dh_ie(hapd, link_addr ? link_addr : peer, status,
2402 NULL, 0);
Hai Shalom81f62d82019-07-22 12:10:00 -07002403 return 0;
2404}
2405#endif /* CONFIG_OWE */
2406
2407
Sunil Ravi7f769292024-07-23 22:21:32 +00002408#ifdef NEED_AP_MLME
2409static void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2410 const u8 *data, size_t len, int ack,
2411 int link_id)
2412{
2413 struct sta_info *sta;
2414
2415 hapd = switch_link_hapd(hapd, link_id);
2416 hapd = hostapd_find_by_sta(hapd->iface, dst, false, &sta);
2417
2418 if (!sta) {
2419 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2420 MACSTR " that is not currently associated",
2421 MAC2STR(dst));
2422 return;
2423 }
2424
2425 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2426}
2427#endif /* NEED_AP_MLME */
2428
2429
2430#ifdef CONFIG_IEEE80211AX
2431static void hostapd_event_color_change(struct hostapd_data *hapd, bool success)
2432{
2433 struct hostapd_data *bss;
2434 size_t i;
2435
2436 for (i = 0; i < hapd->iface->num_bss; i++) {
2437 bss = hapd->iface->bss[i];
2438 if (bss->cca_color == 0)
2439 continue;
2440
2441 if (success)
2442 hapd->iface->conf->he_op.he_bss_color = bss->cca_color;
2443
2444 bss->cca_in_progress = 0;
2445 if (ieee802_11_set_beacon(bss)) {
2446 wpa_printf(MSG_ERROR, "Failed to remove BCCA element");
2447 bss->cca_in_progress = 1;
2448 } else {
2449 hostapd_cleanup_cca_params(bss);
2450 }
2451 }
2452}
2453#endif /* CONFIG_IEEE80211AX */
2454
2455
Sunil Ravic0f5d412024-09-11 22:12:49 +00002456static void hostapd_iface_enable(struct hostapd_data *hapd)
2457{
2458 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
2459 if (hapd->disabled && hapd->started) {
2460 hapd->disabled = 0;
2461 /*
2462 * Try to re-enable interface if the driver stopped it
2463 * when the interface got disabled.
2464 */
2465 if (hapd->wpa_auth)
2466 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
2467 else
2468 hostapd_reconfig_encryption(hapd);
2469 hapd->reenable_beacon = 1;
2470 ieee802_11_set_beacon(hapd);
2471#ifdef NEED_AP_MLME
2472 } else if (hapd->disabled && hapd->iface->cac_started) {
2473 wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC");
2474 hostapd_handle_dfs(hapd->iface);
2475#endif /* NEED_AP_MLME */
2476 }
2477}
2478
2479
2480static void hostapd_iface_disable(struct hostapd_data *hapd)
2481{
2482 hostapd_free_stas(hapd);
2483 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
2484 hapd->disabled = 1;
2485}
2486
2487
2488#ifdef CONFIG_IEEE80211BE
2489
2490static void hostapd_mld_iface_enable(struct hostapd_data *hapd)
2491{
2492 struct hostapd_data *first_link, *link_bss;
2493
2494 first_link = hostapd_mld_is_first_bss(hapd) ? hapd :
2495 hostapd_mld_get_first_bss(hapd);
2496
2497 /* Links have been removed. Re-add all links and enable them, but
2498 * enable the first link BSS before doing that. */
2499 if (hostapd_drv_link_add(first_link, first_link->mld_link_id,
2500 first_link->own_addr)) {
2501 wpa_printf(MSG_ERROR, "MLD: Failed to re-add link %d in MLD %s",
2502 first_link->mld_link_id, first_link->conf->iface);
2503 return;
2504 }
2505
2506 hostapd_iface_enable(first_link);
2507
2508 /* Add other affiliated links */
2509 for_each_mld_link(link_bss, first_link) {
2510 if (link_bss == first_link)
2511 continue;
2512
2513 if (hostapd_drv_link_add(link_bss, link_bss->mld_link_id,
2514 link_bss->own_addr)) {
2515 wpa_printf(MSG_ERROR,
2516 "MLD: Failed to re-add link %d in MLD %s",
2517 link_bss->mld_link_id,
2518 link_bss->conf->iface);
2519 continue;
2520 }
2521
2522 hostapd_iface_enable(link_bss);
2523 }
2524}
2525
2526
2527static void hostapd_mld_iface_disable(struct hostapd_data *hapd)
2528{
2529 struct hostapd_data *link_bss;
2530
2531 for_each_mld_link(link_bss, hapd)
2532 hostapd_iface_disable(link_bss);
2533}
2534
2535#endif /* CONFIG_IEEE80211BE */
2536
2537
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002538void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2539 union wpa_event_data *data)
2540{
2541 struct hostapd_data *hapd = ctx;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002542 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002543#ifndef CONFIG_NO_STDOUT_DEBUG
2544 int level = MSG_DEBUG;
2545
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002546 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002547 data->rx_mgmt.frame_len >= 24) {
2548 const struct ieee80211_hdr *hdr;
2549 u16 fc;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002550
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002551 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2552 fc = le_to_host16(hdr->frame_control);
2553 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2554 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2555 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002556 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2557 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
2558 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002559 }
2560
2561 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
2562 event_to_string(event), event);
2563#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002564
2565 switch (event) {
2566 case EVENT_MICHAEL_MIC_FAILURE:
2567 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
2568 break;
2569 case EVENT_SCAN_RESULTS:
Sunil Ravi99c035e2024-07-12 01:42:03 +00002570#ifdef NEED_AP_MLME
2571 if (data)
2572 hapd = switch_link_scan(hapd,
2573 data->scan_info.scan_cookie);
2574#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002575 if (hapd->iface->scan_cb)
2576 hapd->iface->scan_cb(hapd->iface);
Sunil Ravi99c035e2024-07-12 01:42:03 +00002577#ifdef CONFIG_IEEE80211BE
2578 if (!hapd->iface->scan_cb && hapd->conf->mld_ap) {
2579 /* Other links may be waiting for HT scan result */
2580 unsigned int i;
2581
2582 for (i = 0; i < hapd->iface->interfaces->count; i++) {
2583 struct hostapd_iface *h =
2584 hapd->iface->interfaces->iface[i];
2585 struct hostapd_data *h_hapd = h->bss[0];
2586
2587 if (hostapd_is_ml_partner(hapd, h_hapd) &&
2588 h_hapd->iface->scan_cb)
2589 h_hapd->iface->scan_cb(h_hapd->iface);
2590 }
2591 }
2592#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002593 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002594 case EVENT_WPS_BUTTON_PUSHED:
2595 hostapd_wps_button_pushed(hapd, NULL);
2596 break;
2597#ifdef NEED_AP_MLME
2598 case EVENT_TX_STATUS:
2599 switch (data->tx_status.type) {
2600 case WLAN_FC_TYPE_MGMT:
2601 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
2602 data->tx_status.data_len,
2603 data->tx_status.stype,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002604 data->tx_status.ack,
2605 data->tx_status.link_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002606 break;
2607 case WLAN_FC_TYPE_DATA:
2608 hostapd_tx_status(hapd, data->tx_status.dst,
2609 data->tx_status.data,
2610 data->tx_status.data_len,
2611 data->tx_status.ack);
2612 break;
2613 }
2614 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002615 case EVENT_EAPOL_TX_STATUS:
2616 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
2617 data->eapol_tx_status.data,
2618 data->eapol_tx_status.data_len,
Sunil Ravi7f769292024-07-23 22:21:32 +00002619 data->eapol_tx_status.ack,
2620 data->eapol_tx_status.link_id);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002621 break;
2622 case EVENT_DRIVER_CLIENT_POLL_OK:
2623 hostapd_client_poll_ok(hapd, data->client_poll.addr);
2624 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002625 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002626 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
2627 data->rx_from_unknown.addr,
2628 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002629 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002630#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002631 case EVENT_RX_MGMT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002632 if (!data->rx_mgmt.frame)
2633 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002634#ifdef NEED_AP_MLME
Hai Shalom021b0b52019-04-10 11:17:58 -07002635 hostapd_mgmt_rx(hapd, &data->rx_mgmt);
2636#else /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002637 hostapd_action_rx(hapd, &data->rx_mgmt);
Hai Shalom021b0b52019-04-10 11:17:58 -07002638#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002639 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002640 case EVENT_RX_PROBE_REQ:
2641 if (data->rx_probe_req.sa == NULL ||
2642 data->rx_probe_req.ie == NULL)
2643 break;
2644 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002645 data->rx_probe_req.da,
2646 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002647 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002648 data->rx_probe_req.ie_len,
2649 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002650 break;
2651 case EVENT_NEW_STA:
2652 hostapd_event_new_sta(hapd, data->new_sta.addr);
2653 break;
2654 case EVENT_EAPOL_RX:
2655 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
2656 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00002657 data->eapol_rx.data_len,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002658 data->eapol_rx.encrypted,
2659 data->eapol_rx.link_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002660 break;
2661 case EVENT_ASSOC:
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002662 if (!data)
2663 return;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002664#ifdef CONFIG_IEEE80211BE
2665 if (data->assoc_info.assoc_link_id != -1) {
2666 hapd = hostapd_mld_get_link_bss(
2667 hapd, data->assoc_info.assoc_link_id);
2668 if (!hapd) {
2669 wpa_printf(MSG_ERROR,
2670 "MLD: Failed to get link BSS for EVENT_ASSOC");
2671 return;
2672 }
2673 }
2674#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002675 hostapd_notif_assoc(hapd, data->assoc_info.addr,
2676 data->assoc_info.req_ies,
2677 data->assoc_info.req_ies_len,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002678 data->assoc_info.resp_ies,
2679 data->assoc_info.resp_ies_len,
2680 data->assoc_info.link_addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002681 data->assoc_info.reassoc);
2682 break;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002683 case EVENT_PORT_AUTHORIZED:
2684 /* Port authorized event for an associated STA */
2685 sta = ap_get_sta(hapd, data->port_authorized.sta_addr);
2686 if (sta)
2687 ap_sta_set_authorized(hapd, sta, 1);
2688 else
2689 wpa_printf(MSG_DEBUG,
2690 "No STA info matching port authorized event found");
2691 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07002692#ifdef CONFIG_OWE
2693 case EVENT_UPDATE_DH:
2694 if (!data)
2695 return;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002696#ifdef CONFIG_IEEE80211BE
2697 if (data->update_dh.assoc_link_id != -1) {
2698 hapd = hostapd_mld_get_link_bss(
2699 hapd, data->update_dh.assoc_link_id);
2700 if (!hapd) {
2701 wpa_printf(MSG_ERROR,
2702 "MLD: Failed to get link BSS for EVENT_UPDATE_DH assoc_link_id=%d",
2703 data->update_dh.assoc_link_id);
2704 return;
2705 }
2706 }
2707#endif /* CONFIG_IEEE80211BE */
Hai Shalom81f62d82019-07-22 12:10:00 -07002708 hostapd_notif_update_dh_ie(hapd, data->update_dh.peer,
2709 data->update_dh.ie,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002710 data->update_dh.ie_len,
2711 data->update_dh.link_addr);
Hai Shalom81f62d82019-07-22 12:10:00 -07002712 break;
2713#endif /* CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002714 case EVENT_DISASSOC:
2715 if (data)
2716 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
2717 break;
2718 case EVENT_DEAUTH:
2719 if (data)
2720 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
2721 break;
2722 case EVENT_STATION_LOW_ACK:
2723 if (!data)
2724 break;
2725 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
2726 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002727 case EVENT_AUTH:
2728 hostapd_notif_auth(hapd, &data->auth);
2729 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07002730 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07002731 case EVENT_CH_SWITCH:
2732 if (!data)
2733 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002734#ifdef CONFIG_IEEE80211BE
2735 if (data->ch_switch.link_id != -1) {
2736 hapd = hostapd_mld_get_link_bss(
2737 hapd, data->ch_switch.link_id);
2738 if (!hapd) {
2739 wpa_printf(MSG_ERROR,
2740 "MLD: Failed to get link (ID %d) BSS for EVENT_CH_SWITCH/EVENT_CH_SWITCH_STARTED",
2741 data->ch_switch.link_id);
2742 break;
2743 }
2744 }
2745#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002746 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
2747 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08002748 data->ch_switch.ch_offset,
2749 data->ch_switch.ch_width,
2750 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07002751 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07002752 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07002753 event == EVENT_CH_SWITCH);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002754 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002755 case EVENT_CONNECT_FAILED_REASON:
2756 if (!data)
2757 break;
2758 hostapd_event_connect_failed_reason(
2759 hapd, data->connect_failed_reason.addr,
2760 data->connect_failed_reason.code);
2761 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002762 case EVENT_SURVEY:
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002763 hostapd_event_get_survey(hapd->iface, &data->survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002764 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002765#ifdef NEED_AP_MLME
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002766 case EVENT_INTERFACE_UNAVAILABLE:
2767 hostapd_event_iface_unavailable(hapd);
2768 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002769 case EVENT_DFS_RADAR_DETECTED:
2770 if (!data)
2771 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002772 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002773 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
2774 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002775 case EVENT_DFS_PRE_CAC_EXPIRED:
2776 if (!data)
2777 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002778 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002779 hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
2780 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002781 case EVENT_DFS_CAC_FINISHED:
2782 if (!data)
2783 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002784 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002785 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
2786 break;
2787 case EVENT_DFS_CAC_ABORTED:
2788 if (!data)
2789 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002790 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002791 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
2792 break;
2793 case EVENT_DFS_NOP_FINISHED:
2794 if (!data)
2795 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002796 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002797 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
2798 break;
2799 case EVENT_CHANNEL_LIST_CHANGED:
2800 /* channel list changed (regulatory?), update channel list */
2801 /* TODO: check this. hostapd_get_hw_features() initializes
2802 * too much stuff. */
2803 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002804 hostapd_channel_list_updated(
2805 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002806 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002807 case EVENT_DFS_CAC_STARTED:
2808 if (!data)
2809 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002810 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002811 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
2812 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002813#endif /* NEED_AP_MLME */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002814 case EVENT_INTERFACE_ENABLED:
Sunil Ravic0f5d412024-09-11 22:12:49 +00002815#ifdef CONFIG_IEEE80211BE
2816 if (hapd->conf->mld_ap) {
2817 hostapd_mld_iface_enable(hapd);
2818 break;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002819 }
Sunil Ravic0f5d412024-09-11 22:12:49 +00002820#endif /* CONFIG_IEEE80211BE */
2821 hostapd_iface_enable(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002822 break;
2823 case EVENT_INTERFACE_DISABLED:
Sunil Ravic0f5d412024-09-11 22:12:49 +00002824#ifdef CONFIG_IEEE80211BE
2825 if (hapd->conf->mld_ap) {
2826 hostapd_mld_iface_disable(hapd);
2827 break;
2828 }
2829#endif /* CONFIG_IEEE80211BE */
2830 hostapd_iface_disable(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002831 break;
2832#ifdef CONFIG_ACS
2833 case EVENT_ACS_CHANNEL_SELECTED:
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002834 hostapd_acs_channel_selected(hapd,
2835 &data->acs_selected_channels);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002836 break;
2837#endif /* CONFIG_ACS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002838 case EVENT_STATION_OPMODE_CHANGED:
2839 hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr,
2840 data->sta_opmode.smps_mode,
2841 data->sta_opmode.chan_width,
2842 data->sta_opmode.rx_nss);
2843 break;
2844 case EVENT_WDS_STA_INTERFACE_STATUS:
2845 hostapd_event_wds_sta_interface_status(
2846 hapd, data->wds_sta_interface.istatus,
2847 data->wds_sta_interface.ifname,
2848 data->wds_sta_interface.sta_addr);
2849 break;
Sunil Ravia04bd252022-05-02 22:54:18 -07002850#ifdef CONFIG_IEEE80211AX
2851 case EVENT_BSS_COLOR_COLLISION:
2852 /* The BSS color is shared amongst all BBSs on a specific phy.
2853 * Therefore we always start the color change on the primary
2854 * BSS. */
Sunil Ravi7f769292024-07-23 22:21:32 +00002855 hapd = switch_link_hapd(hapd,
2856 data->bss_color_collision.link_id);
Sunil Ravia04bd252022-05-02 22:54:18 -07002857 wpa_printf(MSG_DEBUG, "BSS color collision on %s",
2858 hapd->conf->iface);
2859 hostapd_switch_color(hapd->iface->bss[0],
2860 data->bss_color_collision.bitmap);
2861 break;
2862 case EVENT_CCA_STARTED_NOTIFY:
Sunil Ravi7f769292024-07-23 22:21:32 +00002863 hapd = switch_link_hapd(hapd,
2864 data->bss_color_collision.link_id);
2865 wpa_printf(MSG_DEBUG, "CCA started on %s",
Sunil Ravia04bd252022-05-02 22:54:18 -07002866 hapd->conf->iface);
2867 break;
2868 case EVENT_CCA_ABORTED_NOTIFY:
Sunil Ravi7f769292024-07-23 22:21:32 +00002869 hapd = switch_link_hapd(hapd,
2870 data->bss_color_collision.link_id);
2871 wpa_printf(MSG_DEBUG, "CCA aborted on %s",
Sunil Ravia04bd252022-05-02 22:54:18 -07002872 hapd->conf->iface);
Sunil Ravi7f769292024-07-23 22:21:32 +00002873 hostapd_event_color_change(hapd, false);
Sunil Ravia04bd252022-05-02 22:54:18 -07002874 break;
2875 case EVENT_CCA_NOTIFY:
Sunil Ravi7f769292024-07-23 22:21:32 +00002876 hapd = switch_link_hapd(hapd,
2877 data->bss_color_collision.link_id);
2878 wpa_printf(MSG_DEBUG, "CCA finished on %s",
Sunil Ravia04bd252022-05-02 22:54:18 -07002879 hapd->conf->iface);
Sunil Ravi7f769292024-07-23 22:21:32 +00002880 hostapd_event_color_change(hapd, true);
Sunil Ravia04bd252022-05-02 22:54:18 -07002881 break;
2882#endif /* CONFIG_IEEE80211AX */
Sunil Ravic0f5d412024-09-11 22:12:49 +00002883#ifdef CONFIG_IEEE80211BE
2884 case EVENT_MLD_INTERFACE_FREED:
2885 wpa_printf(MSG_DEBUG, "MLD: Interface %s freed",
2886 hapd->conf->iface);
2887 hostapd_mld_interface_freed(hapd);
2888 break;
2889#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002890 default:
2891 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
2892 break;
2893 }
2894}
2895
Dmitry Shmidte4663042016-04-04 10:07:49 -07002896
2897void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
2898 union wpa_event_data *data)
2899{
2900 struct hapd_interfaces *interfaces = ctx;
2901 struct hostapd_data *hapd;
2902
2903 if (event != EVENT_INTERFACE_STATUS)
2904 return;
2905
2906 hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
2907 if (hapd && hapd->driver && hapd->driver->get_ifindex &&
2908 hapd->drv_priv) {
2909 unsigned int ifindex;
2910
2911 ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
2912 if (ifindex != data->interface_status.ifindex) {
2913 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
2914 "interface status ifindex %d mismatch (%d)",
2915 ifindex, data->interface_status.ifindex);
2916 return;
2917 }
2918 }
2919 if (hapd)
2920 wpa_supplicant_event(hapd, event, data);
2921}
2922
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002923#endif /* HOSTAPD */