blob: 05adc411649842a5f7acf93df0e0cb62428233d0 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Callback functions for driver wrappers
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003 * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070012#include "utils/eloop.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013#include "radius/radius.h"
14#include "drivers/driver.h"
15#include "common/ieee802_11_defs.h"
16#include "common/ieee802_11_common.h"
Dmitry Shmidtf8623282013-02-20 14:34:59 -080017#include "common/wpa_ctrl.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070018#include "common/dpp.h"
Hai Shalomc3565922019-10-28 11:58:20 -070019#include "common/sae.h"
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080020#include "common/hw_features_common.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070021#include "crypto/random.h"
22#include "p2p/p2p.h"
23#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080024#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070025#include "wnm_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070026#include "hostapd.h"
27#include "ieee802_11.h"
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080028#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070029#include "sta_info.h"
30#include "accounting.h"
31#include "tkip_countermeasures.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070032#include "ieee802_1x.h"
33#include "wpa_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070034#include "wps_hostapd.h"
35#include "ap_drv_ops.h"
36#include "ap_config.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070037#include "ap_mlme.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070038#include "hw_features.h"
Dmitry Shmidt051af732013-10-22 13:52:46 -070039#include "dfs.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070040#include "beacon.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080041#include "mbo_ap.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070042#include "dpp_hostapd.h"
43#include "fils_hlp.h"
Hai Shalom74f70d42019-02-11 14:42:39 -080044#include "neighbor_db.h"
Sunil Ravib0ac25f2024-07-12 01:42:03 +000045#include "nan_usd_ap.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070046
47
48#ifdef CONFIG_FILS
49void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd,
50 struct sta_info *sta)
51{
52 u16 reply_res = WLAN_STATUS_SUCCESS;
53 struct ieee802_11_elems elems;
54 u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf;
55 int new_assoc;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000056 bool updated;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070057
58 wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR,
59 __func__, MAC2STR(sta->addr));
60 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
61 if (!sta->fils_pending_assoc_req)
62 return;
63
Sunil Ravi2a14cf12023-11-21 00:54:38 +000064 if (ieee802_11_parse_elems(sta->fils_pending_assoc_req,
65 sta->fils_pending_assoc_req_len, &elems,
66 0) == ParseFailed ||
67 !elems.fils_session) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070068 wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element",
69 __func__);
70 return;
71 }
72
73 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
74 elems.fils_session,
75 sta->fils_hlp_resp);
Sunil Ravic0f5d412024-09-11 22:12:49 +000076 if (!p)
77 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070078
79 reply_res = hostapd_sta_assoc(hapd, sta->addr,
80 sta->fils_pending_assoc_is_reassoc,
81 WLAN_STATUS_SUCCESS,
82 buf, p - buf);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000083 updated = ap_sta_set_authorized_flag(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070084 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
85 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
86 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
87 hostapd_set_sta_flags(hapd, sta);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000088 if (updated)
89 ap_sta_set_authorized_event(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070090 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
91 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
92 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
93 os_free(sta->fils_pending_assoc_req);
94 sta->fils_pending_assoc_req = NULL;
95 sta->fils_pending_assoc_req_len = 0;
96 wpabuf_free(sta->fils_hlp_resp);
97 sta->fils_hlp_resp = NULL;
98 wpabuf_free(sta->hlp_dhcp_discover);
99 sta->hlp_dhcp_discover = NULL;
100 fils_hlp_deinit(hapd);
101
102 /*
103 * Remove the station in case transmission of a success response fails
104 * (the STA was added associated to the driver) or if the station was
105 * previously added unassociated.
106 */
107 if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) {
108 hostapd_drv_sta_remove(hapd, sta->addr);
109 sta->added_unassoc = 0;
110 }
111}
112#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700113
114
Hai Shalom899fcc72020-10-19 14:38:18 -0700115static bool check_sa_query_need(struct hostapd_data *hapd, struct sta_info *sta)
116{
117 if ((sta->flags &
118 (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED)) !=
119 (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED))
120 return false;
121
122 if (!sta->sa_query_timed_out && sta->sa_query_count > 0)
123 ap_check_sa_query_timeout(hapd, sta);
124
125 if (!sta->sa_query_timed_out && (sta->auth_alg != WLAN_AUTH_FT)) {
126 /*
127 * STA has already been associated with MFP and SA Query timeout
128 * has not been reached. Reject the association attempt
129 * temporarily and start SA Query, if one is not pending.
130 */
131 if (sta->sa_query_count == 0)
132 ap_sta_start_sa_query(hapd, sta);
133
134 return true;
135 }
136
137 return false;
138}
139
140
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000141#ifdef CONFIG_IEEE80211BE
142static int hostapd_update_sta_links_status(struct hostapd_data *hapd,
143 struct sta_info *sta,
144 const u8 *resp_ies,
145 size_t resp_ies_len)
146{
147 struct mld_info *info = &sta->mld_info;
148 struct wpabuf *mlebuf;
149 const u8 *mle, *pos;
150 struct ieee802_11_elems elems;
151 size_t mle_len, rem_len;
152 int ret = 0;
153
154 if (!resp_ies) {
155 wpa_printf(MSG_DEBUG,
156 "MLO: (Re)Association Response frame elements not available");
157 return -1;
158 }
159
160 if (ieee802_11_parse_elems(resp_ies, resp_ies_len, &elems, 0) ==
161 ParseFailed) {
162 wpa_printf(MSG_DEBUG,
163 "MLO: Failed to parse (Re)Association Response frame elements");
164 return -1;
165 }
166
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000167 mlebuf = ieee802_11_defrag(elems.basic_mle, elems.basic_mle_len, true);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000168 if (!mlebuf) {
169 wpa_printf(MSG_ERROR,
170 "MLO: Basic Multi-Link element not found in (Re)Association Response frame");
171 return -1;
172 }
173
174 mle = wpabuf_head(mlebuf);
175 mle_len = wpabuf_len(mlebuf);
176 if (mle_len < MULTI_LINK_CONTROL_LEN + 1 ||
177 mle_len - MULTI_LINK_CONTROL_LEN < mle[MULTI_LINK_CONTROL_LEN]) {
178 wpa_printf(MSG_ERROR,
179 "MLO: Invalid Multi-Link element in (Re)Association Response frame");
180 ret = -1;
181 goto out;
182 }
183
184 /* Skip Common Info */
185 pos = mle + MULTI_LINK_CONTROL_LEN + mle[MULTI_LINK_CONTROL_LEN];
186 rem_len = mle_len -
187 (MULTI_LINK_CONTROL_LEN + mle[MULTI_LINK_CONTROL_LEN]);
188
189 /* Parse Subelements */
190 while (rem_len > 2) {
191 size_t ie_len = 2 + pos[1];
192
193 if (rem_len < ie_len)
194 break;
195
196 if (pos[0] == MULTI_LINK_SUB_ELEM_ID_PER_STA_PROFILE) {
197 u8 link_id;
198 const u8 *sta_profile;
199 size_t sta_profile_len;
200 u16 sta_ctrl;
201
202 if (pos[1] < BASIC_MLE_STA_CTRL_LEN + 1) {
203 wpa_printf(MSG_DEBUG,
204 "MLO: Invalid per-STA profile IE");
205 goto next_subelem;
206 }
207
208 sta_profile_len = pos[1];
209 sta_profile = &pos[2];
210 sta_ctrl = WPA_GET_LE16(sta_profile);
211 link_id = sta_ctrl & BASIC_MLE_STA_CTRL_LINK_ID_MASK;
212 if (link_id >= MAX_NUM_MLD_LINKS) {
213 wpa_printf(MSG_DEBUG,
214 "MLO: Invalid link ID in per-STA profile IE");
215 goto next_subelem;
216 }
217
218 /* Skip STA Control and STA Info */
219 if (sta_profile_len - BASIC_MLE_STA_CTRL_LEN <
220 sta_profile[BASIC_MLE_STA_CTRL_LEN]) {
221 wpa_printf(MSG_DEBUG,
222 "MLO: Invalid STA info in per-STA profile IE");
223 goto next_subelem;
224 }
225
226 sta_profile_len = sta_profile_len -
227 (BASIC_MLE_STA_CTRL_LEN +
228 sta_profile[BASIC_MLE_STA_CTRL_LEN]);
229 sta_profile = sta_profile + BASIC_MLE_STA_CTRL_LEN +
230 sta_profile[BASIC_MLE_STA_CTRL_LEN];
231
232 /* Skip Capabilities Information field */
233 if (sta_profile_len < 2)
234 goto next_subelem;
235 sta_profile_len -= 2;
236 sta_profile += 2;
237
238 /* Get status of the link */
239 info->links[link_id].status = WPA_GET_LE16(sta_profile);
240 }
241next_subelem:
242 pos += ie_len;
243 rem_len -= ie_len;
244 }
245
246out:
247 wpabuf_free(mlebuf);
248 return ret;
249}
250#endif /* CONFIG_IEEE80211BE */
251
252
Sunil Ravic0f5d412024-09-11 22:12:49 +0000253#if defined(HOSTAPD) || defined(CONFIG_IEEE80211BE)
254static struct hostapd_data * hostapd_find_by_sta(struct hostapd_iface *iface,
255 const u8 *src, bool rsn,
256 struct sta_info **sta_ret)
257{
258 struct hostapd_data *hapd;
259 struct sta_info *sta;
260 unsigned int j;
261
262 if (sta_ret)
263 *sta_ret = NULL;
264
265 for (j = 0; j < iface->num_bss; j++) {
266 hapd = iface->bss[j];
267 sta = ap_get_sta(hapd, src);
268 if (sta && (sta->flags & WLAN_STA_ASSOC) &&
269 (!rsn || sta->wpa_sm)) {
270 if (sta_ret)
271 *sta_ret = sta;
272 return hapd;
273 }
274#ifdef CONFIG_IEEE80211BE
275 if (hapd->conf->mld_ap) {
276 struct hostapd_data *p_hapd;
277
278 for_each_mld_link(p_hapd, hapd) {
279 if (p_hapd == hapd)
280 continue;
281
282 sta = ap_get_sta(p_hapd, src);
283 if (sta && (sta->flags & WLAN_STA_ASSOC) &&
284 (!rsn || sta->wpa_sm)) {
285 if (sta_ret)
286 *sta_ret = sta;
287 return p_hapd;
288 }
289 }
290 }
291#endif /* CONFIG_IEEE80211BE */
292 }
293
294 return NULL;
295}
296#endif /* HOSTAPD || CONFIG_IEEE80211BE */
297
298
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000300 const u8 *req_ies, size_t req_ies_len,
301 const u8 *resp_ies, size_t resp_ies_len,
302 const u8 *link_addr, int reassoc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700303{
304 struct sta_info *sta;
Hai Shalomfdcde762020-04-02 11:19:20 -0700305 int new_assoc;
306 enum wpa_validate_result res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307 struct ieee802_11_elems elems;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800308 const u8 *ie;
309 size_t ielen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700310 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
311 u8 *p = buf;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800312 u16 reason = WLAN_REASON_UNSPECIFIED;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700313 int status = WLAN_STATUS_SUCCESS;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700314 const u8 *p2p_dev_addr = NULL;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000315#ifdef CONFIG_OWE
316 struct hostapd_iface *iface = hapd->iface;
317#endif /* CONFIG_OWE */
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000318 bool updated = false;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319
320 if (addr == NULL) {
321 /*
322 * This could potentially happen with unexpected event from the
323 * driver wrapper. This was seen at least in one case where the
324 * driver ended up being set to station mode while hostapd was
325 * running, so better make sure we stop processing such an
326 * event here.
327 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800328 wpa_printf(MSG_DEBUG,
329 "hostapd_notif_assoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700330 return -1;
331 }
Hai Shalomc3565922019-10-28 11:58:20 -0700332
333 if (is_multicast_ether_addr(addr) ||
334 is_zero_ether_addr(addr) ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000335 ether_addr_equal(addr, hapd->own_addr)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700336 /* Do not process any frames with unexpected/invalid SA so that
337 * we do not add any state for unexpected STA addresses or end
338 * up sending out frames to unexpected destination. */
339 wpa_printf(MSG_DEBUG, "%s: Invalid SA=" MACSTR
340 " in received indication - ignore this indication silently",
341 __func__, MAC2STR(addr));
342 return 0;
343 }
344
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700345 random_add_randomness(addr, ETH_ALEN);
346
347 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
348 HOSTAPD_LEVEL_INFO, "associated");
349
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000350 if (ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0) ==
351 ParseFailed) {
352 wpa_printf(MSG_DEBUG, "%s: Could not parse elements", __func__);
353 return -1;
354 }
355
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700356 if (elems.wps_ie) {
357 ie = elems.wps_ie - 2;
358 ielen = elems.wps_ie_len + 2;
359 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
360 } else if (elems.rsn_ie) {
361 ie = elems.rsn_ie - 2;
362 ielen = elems.rsn_ie_len + 2;
363 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
364 } else if (elems.wpa_ie) {
365 ie = elems.wpa_ie - 2;
366 ielen = elems.wpa_ie_len + 2;
367 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800368#ifdef CONFIG_HS20
369 } else if (elems.osen) {
370 ie = elems.osen - 2;
371 ielen = elems.osen_len + 2;
372 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
373#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700374 } else {
375 ie = NULL;
376 ielen = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800377 wpa_printf(MSG_DEBUG,
378 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700379 }
380
381 sta = ap_get_sta(hapd, addr);
382 if (sta) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700383 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700384 accounting_sta_stop(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700385
386 /*
387 * Make sure that the previously registered inactivity timer
388 * will not remove the STA immediately.
389 */
390 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700391 } else {
392 sta = ap_sta_add(hapd, addr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700393 if (sta == NULL) {
394 hostapd_drv_sta_disassoc(hapd, addr,
395 WLAN_REASON_DISASSOC_AP_BUSY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700397 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700398 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000399
400 if (hapd->conf->wpa && check_sa_query_need(hapd, sta)) {
401 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
402 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
403 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
404
405 return 0;
406 }
407
408#ifdef CONFIG_IEEE80211BE
409 if (link_addr) {
410 struct mld_info *info = &sta->mld_info;
411 int i, num_valid_links = 0;
412 u8 link_id = hapd->mld_link_id;
413
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000414 ap_sta_set_mld(sta, true);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000415 sta->mld_assoc_link_id = link_id;
416 os_memcpy(info->common_info.mld_addr, addr, ETH_ALEN);
417 info->links[link_id].valid = true;
418 os_memcpy(info->links[link_id].peer_addr, link_addr, ETH_ALEN);
419 os_memcpy(info->links[link_id].local_addr, hapd->own_addr,
420 ETH_ALEN);
421
422 if (!elems.basic_mle ||
423 hostapd_process_ml_assoc_req(hapd, &elems, sta) !=
424 WLAN_STATUS_SUCCESS) {
425 reason = WLAN_REASON_UNSPECIFIED;
426 wpa_printf(MSG_DEBUG,
427 "Failed to get STA non-assoc links info");
428 goto fail;
429 }
430
431 for (i = 0 ; i < MAX_NUM_MLD_LINKS; i++) {
432 if (info->links[i].valid)
433 num_valid_links++;
434 }
435 if (num_valid_links > 1 &&
436 hostapd_update_sta_links_status(hapd, sta, resp_ies,
437 resp_ies_len)) {
438 wpa_printf(MSG_DEBUG,
439 "Failed to get STA non-assoc links status info");
440 reason = WLAN_REASON_UNSPECIFIED;
441 goto fail;
442 }
443 }
444#endif /* CONFIG_IEEE80211BE */
445
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800446 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700447
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700448 /*
449 * ACL configurations to the drivers (implementing AP SME and ACL
450 * offload) without hostapd's knowledge, can result in a disconnection
451 * though the driver accepts the connection. Skip the hostapd check for
452 * ACL if the driver supports ACL offload to avoid potentially
453 * conflicting ACL rules.
454 */
455 if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
456 hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800457 wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
458 MAC2STR(addr));
459 reason = WLAN_REASON_UNSPECIFIED;
460 goto fail;
461 }
462
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700463#ifdef CONFIG_P2P
464 if (elems.p2p) {
465 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800466 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700467 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700468 if (sta->p2p_ie)
469 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700470 }
471#endif /* CONFIG_P2P */
472
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700473#ifdef NEED_AP_MLME
474 if (elems.ht_capabilities &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700475 (hapd->iface->conf->ht_capab &
476 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
477 struct ieee80211_ht_capabilities *ht_cap =
478 (struct ieee80211_ht_capabilities *)
479 elems.ht_capabilities;
480
481 if (le_to_host16(ht_cap->ht_capabilities_info) &
482 HT_CAP_INFO_40MHZ_INTOLERANT)
483 ht40_intolerant_add(hapd->iface, sta);
484 }
485#endif /* NEED_AP_MLME */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700486
Sunil Ravia04bd252022-05-02 22:54:18 -0700487 check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700488
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800489#ifdef CONFIG_HS20
490 wpabuf_free(sta->hs20_ie);
491 if (elems.hs20 && elems.hs20_len > 4) {
492 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
493 elems.hs20_len - 4);
494 } else
495 sta->hs20_ie = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700496
497 wpabuf_free(sta->roaming_consortium);
498 if (elems.roaming_cons_sel)
499 sta->roaming_consortium = wpabuf_alloc_copy(
500 elems.roaming_cons_sel + 4,
501 elems.roaming_cons_sel_len - 4);
502 else
503 sta->roaming_consortium = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800504#endif /* CONFIG_HS20 */
505
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800506#ifdef CONFIG_FST
507 wpabuf_free(sta->mb_ies);
508 if (hapd->iface->fst)
509 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
510 else
511 sta->mb_ies = NULL;
512#endif /* CONFIG_FST */
513
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800514 mbo_ap_check_sta_assoc(hapd, sta, &elems);
515
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800516 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
517 elems.supp_op_classes_len);
518
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700519 if (hapd->conf->wpa) {
520 if (ie == NULL || ielen == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800521#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700522 if (hapd->conf->wps_state) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800523 wpa_printf(MSG_DEBUG,
524 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700525 sta->flags |= WLAN_STA_MAYBE_WPS;
526 goto skip_wpa_check;
527 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800528#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529
530 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700531 reason = WLAN_REASON_INVALID_IE;
532 status = WLAN_STATUS_INVALID_IE;
533 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700534 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800535#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700536 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
537 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800538 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800539
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700540 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800541 wps = ieee802_11_vendor_ie_concat(ie, ielen,
542 WPS_IE_VENDOR_TYPE);
543 if (wps) {
544 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800545 wpa_printf(MSG_DEBUG,
546 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800547 sta->flags |= WLAN_STA_WPS2;
548 }
549 wpabuf_free(wps);
550 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700551 goto skip_wpa_check;
552 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800553#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700554
555 if (sta->wpa_sm == NULL)
556 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700557 sta->addr,
558 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700559 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800560 wpa_printf(MSG_ERROR,
561 "Failed to initialize WPA state machine");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700562 return -1;
563 }
Sunil Ravic0f5d412024-09-11 22:12:49 +0000564 wpa_auth_set_rsn_selection(sta->wpa_sm, elems.rsn_selection,
565 elems.rsn_selection_len);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000566#ifdef CONFIG_IEEE80211BE
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000567 if (ap_sta_is_mld(hapd, sta)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000568 wpa_printf(MSG_DEBUG,
569 "MLD: Set ML info in RSN Authenticator");
Sunil Ravi7f769292024-07-23 22:21:32 +0000570 wpa_auth_set_ml_info(sta->wpa_sm,
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000571 sta->mld_assoc_link_id,
572 &sta->mld_info);
573 }
574#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700575 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Hai Shalom021b0b52019-04-10 11:17:58 -0700576 hapd->iface->freq,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700577 ie, ielen,
Hai Shalomc3565922019-10-28 11:58:20 -0700578 elems.rsnxe ? elems.rsnxe - 2 : NULL,
579 elems.rsnxe ? elems.rsnxe_len + 2 : 0,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700580 elems.mdie, elems.mdie_len,
Sunil Ravi7f769292024-07-23 22:21:32 +0000581 elems.owe_dh, elems.owe_dh_len, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -0700582 reason = WLAN_REASON_INVALID_IE;
583 status = WLAN_STATUS_INVALID_IE;
584 switch (res) {
585 case WPA_IE_OK:
586 reason = WLAN_REASON_UNSPECIFIED;
587 status = WLAN_STATUS_SUCCESS;
588 break;
589 case WPA_INVALID_IE:
590 reason = WLAN_REASON_INVALID_IE;
591 status = WLAN_STATUS_INVALID_IE;
592 break;
593 case WPA_INVALID_GROUP:
594 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
595 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
596 break;
597 case WPA_INVALID_PAIRWISE:
598 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
599 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
600 break;
601 case WPA_INVALID_AKMP:
602 reason = WLAN_REASON_AKMP_NOT_VALID;
603 status = WLAN_STATUS_AKMP_NOT_VALID;
604 break;
605 case WPA_NOT_ENABLED:
606 reason = WLAN_REASON_INVALID_IE;
607 status = WLAN_STATUS_INVALID_IE;
608 break;
609 case WPA_ALLOC_FAIL:
610 reason = WLAN_REASON_UNSPECIFIED;
611 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
612 break;
613 case WPA_MGMT_FRAME_PROTECTION_VIOLATION:
614 reason = WLAN_REASON_INVALID_IE;
615 status = WLAN_STATUS_INVALID_IE;
616 break;
617 case WPA_INVALID_MGMT_GROUP_CIPHER:
618 reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
619 status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
620 break;
621 case WPA_INVALID_MDIE:
622 reason = WLAN_REASON_INVALID_MDE;
623 status = WLAN_STATUS_INVALID_MDIE;
624 break;
625 case WPA_INVALID_PROTO:
626 reason = WLAN_REASON_INVALID_IE;
627 status = WLAN_STATUS_INVALID_IE;
628 break;
629 case WPA_INVALID_PMKID:
630 reason = WLAN_REASON_INVALID_PMKID;
631 status = WLAN_STATUS_INVALID_PMKID;
632 break;
633 case WPA_DENIED_OTHER_REASON:
634 reason = WLAN_REASON_UNSPECIFIED;
635 status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
636 break;
637 }
638 if (status != WLAN_STATUS_SUCCESS) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800639 wpa_printf(MSG_DEBUG,
640 "WPA/RSN information element rejected? (res %u)",
641 res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800643 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700644 }
Hai Shalomc3565922019-10-28 11:58:20 -0700645
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700646 if (wpa_auth_uses_mfp(sta->wpa_sm))
647 sta->flags |= WLAN_STA_MFP;
648 else
649 sta->flags &= ~WLAN_STA_MFP;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700650
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800651#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700652 if (sta->auth_alg == WLAN_AUTH_FT) {
653 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
654 req_ies_len);
655 if (status != WLAN_STATUS_SUCCESS) {
656 if (status == WLAN_STATUS_INVALID_PMKID)
657 reason = WLAN_REASON_INVALID_IE;
658 if (status == WLAN_STATUS_INVALID_MDIE)
659 reason = WLAN_REASON_INVALID_IE;
660 if (status == WLAN_STATUS_INVALID_FTIE)
661 reason = WLAN_REASON_INVALID_IE;
662 goto fail;
663 }
664 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800665#endif /* CONFIG_IEEE80211R_AP */
Hai Shalomc3565922019-10-28 11:58:20 -0700666#ifdef CONFIG_SAE
Sunil Ravi77d572f2023-01-17 23:58:31 +0000667 if (hapd->conf->sae_pwe == SAE_PWE_BOTH &&
Hai Shalomc3565922019-10-28 11:58:20 -0700668 sta->auth_alg == WLAN_AUTH_SAE &&
Hai Shalom899fcc72020-10-19 14:38:18 -0700669 sta->sae && !sta->sae->h2e &&
Hai Shaloma20dcd72022-02-04 13:43:00 -0800670 ieee802_11_rsnx_capab_len(elems.rsnxe, elems.rsnxe_len,
671 WLAN_RSNX_CAPAB_SAE_H2E)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700672 wpa_printf(MSG_INFO, "SAE: " MACSTR
673 " indicates support for SAE H2E, but did not use it",
674 MAC2STR(sta->addr));
675 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
676 reason = WLAN_REASON_UNSPECIFIED;
677 goto fail;
678 }
679#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700680 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800681#ifdef CONFIG_WPS
682 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800683
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800684 if (req_ies)
685 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700686 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800687 else
688 wps = NULL;
689#ifdef CONFIG_WPS_STRICT
690 if (wps && wps_validate_assoc_req(wps) < 0) {
691 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700692 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700693 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800694 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700695 }
696#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800697 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800699 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800700 wpa_printf(MSG_DEBUG,
701 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800702 sta->flags |= WLAN_STA_WPS2;
703 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700704 } else
705 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800706 wpabuf_free(wps);
707#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800708#ifdef CONFIG_HS20
709 } else if (hapd->conf->osen) {
710 if (elems.osen == NULL) {
711 hostapd_logger(
712 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
713 HOSTAPD_LEVEL_INFO,
714 "No HS 2.0 OSEN element in association request");
715 return WLAN_STATUS_INVALID_IE;
716 }
717
718 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
719 if (sta->wpa_sm == NULL)
720 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
721 sta->addr, NULL);
722 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800723 wpa_printf(MSG_WARNING,
724 "Failed to initialize WPA state machine");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800725 return WLAN_STATUS_UNSPECIFIED_FAILURE;
726 }
727 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
728 elems.osen - 2, elems.osen_len + 2) < 0)
729 return WLAN_STATUS_INVALID_IE;
730#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700731 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700732#ifdef CONFIG_WPS
733skip_wpa_check:
734#endif /* CONFIG_WPS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800735
736#ifdef CONFIG_MBO
737 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
738 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
739 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
740 wpa_printf(MSG_INFO,
741 "MBO: Reject WPA2 association without PMF");
742 return WLAN_STATUS_UNSPECIFIED_FAILURE;
743 }
744#endif /* CONFIG_MBO */
745
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800746#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700747 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
Hai Shalomfdcde762020-04-02 11:19:20 -0700748 sta->auth_alg, req_ies, req_ies_len,
749 !elems.rsnxe);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700750 if (!p) {
751 wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs");
752 return WLAN_STATUS_UNSPECIFIED_FAILURE;
753 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700754#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700755
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700756#ifdef CONFIG_FILS
757 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
758 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
759 sta->auth_alg == WLAN_AUTH_FILS_PK) {
760 int delay_assoc = 0;
761
762 if (!req_ies)
763 return WLAN_STATUS_UNSPECIFIED_FAILURE;
764
765 if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies,
766 req_ies_len,
767 sta->fils_session)) {
768 wpa_printf(MSG_DEBUG,
769 "FILS: Session validation failed");
770 return WLAN_STATUS_UNSPECIFIED_FAILURE;
771 }
772
773 res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies,
774 req_ies_len);
775 if (res < 0) {
776 wpa_printf(MSG_DEBUG,
777 "FILS: Key Confirm validation failed");
778 return WLAN_STATUS_UNSPECIFIED_FAILURE;
779 }
780
781 if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) {
782 wpa_printf(MSG_DEBUG,
783 "FILS: Delaying Assoc Response (HLP)");
784 delay_assoc = 1;
785 } else {
786 wpa_printf(MSG_DEBUG,
787 "FILS: Going ahead with Assoc Response (no HLP)");
788 }
789
790 if (sta) {
791 wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup");
792 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
793 os_free(sta->fils_pending_assoc_req);
794 sta->fils_pending_assoc_req = NULL;
795 sta->fils_pending_assoc_req_len = 0;
796 wpabuf_free(sta->fils_hlp_resp);
797 sta->fils_hlp_resp = NULL;
798 sta->fils_drv_assoc_finish = 0;
799 }
800
801 if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) {
802 u8 *req_tmp;
803
804 req_tmp = os_malloc(req_ies_len);
805 if (!req_tmp) {
806 wpa_printf(MSG_DEBUG,
807 "FILS: buffer allocation failed for assoc req");
808 goto fail;
809 }
810 os_memcpy(req_tmp, req_ies, req_ies_len);
811 sta->fils_pending_assoc_req = req_tmp;
812 sta->fils_pending_assoc_req_len = req_ies_len;
813 sta->fils_pending_assoc_is_reassoc = reassoc;
814 sta->fils_drv_assoc_finish = 1;
815 wpa_printf(MSG_DEBUG,
816 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
817 MACSTR, MAC2STR(sta->addr));
818 eloop_register_timeout(
819 0, hapd->conf->fils_hlp_wait_time * 1024,
820 fils_hlp_timeout, hapd, sta);
821 return 0;
822 }
823 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
824 elems.fils_session,
825 sta->fils_hlp_resp);
Sunil Ravic0f5d412024-09-11 22:12:49 +0000826 if (!p)
827 goto fail;
828
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700829 wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)",
830 buf, p - buf);
831 }
832#endif /* CONFIG_FILS */
833
Roshan Pius3a1667e2018-07-03 15:17:14 -0700834#ifdef CONFIG_OWE
835 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000836 !(iface->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_AP) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -0700837 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
838 elems.owe_dh) {
839 u8 *npos;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700840 u16 ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700841
842 npos = owe_assoc_req_process(hapd, sta,
843 elems.owe_dh, elems.owe_dh_len,
844 p, sizeof(buf) - (p - buf),
Hai Shalomb755a2a2020-04-23 21:49:02 -0700845 &ret_status);
846 status = ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700847 if (npos)
848 p = npos;
Hai Shalomfdcde762020-04-02 11:19:20 -0700849
Roshan Pius3a1667e2018-07-03 15:17:14 -0700850 if (!npos &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700851 status == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
Hai Shalomb755a2a2020-04-23 21:49:02 -0700852 hostapd_sta_assoc(hapd, addr, reassoc, ret_status, buf,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700853 p - buf);
854 return 0;
855 }
856
Hai Shalomfdcde762020-04-02 11:19:20 -0700857 if (!npos || status != WLAN_STATUS_SUCCESS)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700858 goto fail;
859 }
860#endif /* CONFIG_OWE */
861
Hai Shalom021b0b52019-04-10 11:17:58 -0700862#ifdef CONFIG_DPP2
863 dpp_pfs_free(sta->dpp_pfs);
864 sta->dpp_pfs = NULL;
865
866 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
867 hapd->conf->dpp_netaccesskey && sta->wpa_sm &&
868 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP &&
869 elems.owe_dh) {
870 sta->dpp_pfs = dpp_pfs_init(
871 wpabuf_head(hapd->conf->dpp_netaccesskey),
872 wpabuf_len(hapd->conf->dpp_netaccesskey));
873 if (!sta->dpp_pfs) {
874 wpa_printf(MSG_DEBUG,
875 "DPP: Could not initialize PFS");
876 /* Try to continue without PFS */
877 goto pfs_fail;
878 }
879
880 if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh,
881 elems.owe_dh_len) < 0) {
882 dpp_pfs_free(sta->dpp_pfs);
883 sta->dpp_pfs = NULL;
884 reason = WLAN_REASON_UNSPECIFIED;
885 goto fail;
886 }
887 }
888
889 wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ?
890 sta->dpp_pfs->secret : NULL);
891 pfs_fail:
892#endif /* CONFIG_DPP2 */
893
Hai Shalomfdcde762020-04-02 11:19:20 -0700894 if (elems.rrm_enabled &&
895 elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
896 os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
897 sizeof(sta->rrm_enabled_capa));
898
Roshan Pius3a1667e2018-07-03 15:17:14 -0700899#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700900 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700901
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700902 if (sta->auth_alg == WLAN_AUTH_FT ||
903 sta->auth_alg == WLAN_AUTH_FILS_SK ||
904 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
905 sta->auth_alg == WLAN_AUTH_FILS_PK)
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000906 updated = ap_sta_set_authorized_flag(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700907#else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700908 /* Keep compiler silent about unused variables */
909 if (status) {
910 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700911#endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700912
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000913#ifdef CONFIG_IEEE80211BE
914 if (hostapd_process_assoc_ml_info(hapd, sta, req_ies, req_ies_len,
915 !!reassoc, WLAN_STATUS_SUCCESS,
916 true)) {
917 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
918 reason = WLAN_REASON_UNSPECIFIED;
919 goto fail;
920 }
921#endif /* CONFIG_IEEE80211BE */
922
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700923 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
924 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800925 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700926
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700927 hostapd_set_sta_flags(hapd, sta);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000928 if (updated)
929 ap_sta_set_authorized_event(hapd, sta, 1);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700930
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700931 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
932 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700933#ifdef CONFIG_FILS
934 else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
935 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
936 sta->auth_alg == WLAN_AUTH_FILS_PK)
937 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
938#endif /* CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700939 else
940 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700941
942 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
943
944 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
945
946#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800947 if (req_ies) {
948 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
949 req_ies, req_ies_len);
950 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951#endif /* CONFIG_P2P */
952
953 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800954
955fail:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800956#ifdef CONFIG_IEEE80211R_AP
Hai Shalomb755a2a2020-04-23 21:49:02 -0700957 if (status >= 0)
958 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800959#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800960 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
961 ap_free_sta(hapd, sta);
962 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700963}
964
965
Sunil Ravi99c035e2024-07-12 01:42:03 +0000966static void hostapd_remove_sta(struct hostapd_data *hapd, struct sta_info *sta)
967{
968 ap_sta_set_authorized(hapd, sta, 0);
969 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
970 hostapd_set_sta_flags(hapd, sta);
971 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
972 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
973 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
974 ap_free_sta(hapd, sta);
975}
976
977
978#ifdef CONFIG_IEEE80211BE
979static void hostapd_notif_disassoc_mld(struct hostapd_data *assoc_hapd,
980 struct sta_info *sta,
981 const u8 *addr)
982{
983 unsigned int link_id, i;
984 struct hostapd_data *tmp_hapd;
985 struct hapd_interfaces *interfaces = assoc_hapd->iface->interfaces;
986
987 /* Remove STA entry in non-assoc links */
988 for (link_id = 0; link_id < MAX_NUM_MLD_LINKS; link_id++) {
989 if (!sta->mld_info.links[link_id].valid)
990 continue;
991
992 for (i = 0; i < interfaces->count; i++) {
993 struct sta_info *tmp_sta;
994
995 tmp_hapd = interfaces->iface[i]->bss[0];
996
997 if (!tmp_hapd->conf->mld_ap ||
998 assoc_hapd == tmp_hapd ||
999 assoc_hapd->conf->mld_id != tmp_hapd->conf->mld_id)
1000 continue;
1001
1002 tmp_sta = ap_get_sta(tmp_hapd, addr);
1003 if (tmp_sta)
1004 ap_free_sta(tmp_hapd, tmp_sta);
1005 }
1006 }
1007
1008 /* Remove STA in assoc link */
1009 hostapd_remove_sta(assoc_hapd, sta);
1010}
1011#endif /* CONFIG_IEEE80211BE */
1012
1013
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001014void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
1015{
1016 struct sta_info *sta;
1017
1018 if (addr == NULL) {
1019 /*
1020 * This could potentially happen with unexpected event from the
1021 * driver wrapper. This was seen at least in one case where the
1022 * driver ended up reporting a station mode event while hostapd
1023 * was running, so better make sure we stop processing such an
1024 * event here.
1025 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001026 wpa_printf(MSG_DEBUG,
1027 "hostapd_notif_disassoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001028 return;
1029 }
1030
1031 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
1032 HOSTAPD_LEVEL_INFO, "disassociated");
1033
1034 sta = ap_get_sta(hapd, addr);
Sunil Ravi99c035e2024-07-12 01:42:03 +00001035#ifdef CONFIG_IEEE80211BE
1036 if (hostapd_is_mld_ap(hapd)) {
1037 struct hostapd_data *assoc_hapd;
1038 unsigned int i;
1039
1040 if (!sta) {
1041 /* Find non-MLO cases from any of the affiliated AP
1042 * links. */
1043 for (i = 0; i < hapd->iface->interfaces->count; ++i) {
1044 struct hostapd_iface *h =
1045 hapd->iface->interfaces->iface[i];
1046 struct hostapd_data *h_hapd = h->bss[0];
1047 struct hostapd_bss_config *hconf = h_hapd->conf;
1048
1049 if (!hconf->mld_ap ||
1050 hconf->mld_id != hapd->conf->mld_id)
1051 continue;
1052
1053 sta = ap_get_sta(h_hapd, addr);
1054 if (sta) {
1055 if (!sta->mld_info.mld_sta) {
1056 hapd = h_hapd;
1057 goto legacy;
1058 }
1059 break;
1060 }
1061 }
1062 } else if (!sta->mld_info.mld_sta) {
1063 goto legacy;
1064 }
1065 if (!sta) {
1066 wpa_printf(MSG_DEBUG,
1067 "Disassociation notification for unknown STA "
1068 MACSTR, MAC2STR(addr));
1069 return;
1070 }
1071 sta = hostapd_ml_get_assoc_sta(hapd, sta, &assoc_hapd);
1072 if (sta)
1073 hostapd_notif_disassoc_mld(assoc_hapd, sta, addr);
1074 return;
1075 }
1076
1077legacy:
1078#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001079 if (sta == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001080 wpa_printf(MSG_DEBUG,
1081 "Disassociation notification for unknown STA "
1082 MACSTR, MAC2STR(addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083 return;
1084 }
1085
Sunil Ravi99c035e2024-07-12 01:42:03 +00001086 hostapd_remove_sta(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087}
1088
1089
1090void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
1091{
1092 struct sta_info *sta = ap_get_sta(hapd, addr);
Sunil Ravic0f5d412024-09-11 22:12:49 +00001093#ifdef CONFIG_IEEE80211BE
1094 struct hostapd_data *orig_hapd = hapd;
1095
1096 if (!sta && hapd->conf->mld_ap) {
1097 hapd = hostapd_find_by_sta(hapd->iface, addr, true, &sta);
1098 if (!hapd) {
1099 wpa_printf(MSG_DEBUG,
1100 "No partner link BSS found for STA " MACSTR
1101 " - fallback to received context",
1102 MAC2STR(addr));
1103 hapd = orig_hapd;
1104 }
1105 }
1106#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001107
Roshan Pius3a1667e2018-07-03 15:17:14 -07001108 if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001109 return;
1110
1111 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001112 HOSTAPD_LEVEL_INFO,
1113 "disconnected due to excessive missing ACKs");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001114 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001115 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001116}
1117
1118
Roshan Pius3a1667e2018-07-03 15:17:14 -07001119void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr,
1120 enum smps_mode smps_mode,
1121 enum chan_width chan_width, u8 rx_nss)
1122{
1123 struct sta_info *sta = ap_get_sta(hapd, addr);
1124 const char *txt;
1125
1126 if (!sta)
1127 return;
1128
1129 switch (smps_mode) {
1130 case SMPS_AUTOMATIC:
1131 txt = "automatic";
1132 break;
1133 case SMPS_OFF:
1134 txt = "off";
1135 break;
1136 case SMPS_DYNAMIC:
1137 txt = "dynamic";
1138 break;
1139 case SMPS_STATIC:
1140 txt = "static";
1141 break;
1142 default:
1143 txt = NULL;
1144 break;
1145 }
1146 if (txt) {
1147 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED
1148 MACSTR " %s", MAC2STR(addr), txt);
1149 }
1150
1151 switch (chan_width) {
1152 case CHAN_WIDTH_20_NOHT:
1153 txt = "20(no-HT)";
1154 break;
1155 case CHAN_WIDTH_20:
1156 txt = "20";
1157 break;
1158 case CHAN_WIDTH_40:
1159 txt = "40";
1160 break;
1161 case CHAN_WIDTH_80:
1162 txt = "80";
1163 break;
1164 case CHAN_WIDTH_80P80:
1165 txt = "80+80";
1166 break;
1167 case CHAN_WIDTH_160:
1168 txt = "160";
1169 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001170 case CHAN_WIDTH_320:
1171 txt = "320";
1172 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001173 default:
1174 txt = NULL;
1175 break;
1176 }
1177 if (txt) {
1178 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED
1179 MACSTR " %s", MAC2STR(addr), txt);
1180 }
1181
1182 if (rx_nss != 0xff) {
1183 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED
1184 MACSTR " %d", MAC2STR(addr), rx_nss);
1185 }
1186}
1187
1188
Dmitry Shmidt04949592012-07-19 12:16:46 -07001189void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001190 int offset, int width, int cf1, int cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07001191 u16 punct_bitmap, int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001192{
1193#ifdef NEED_AP_MLME
Sunil Ravi77d572f2023-01-17 23:58:31 +00001194 int channel, chwidth, is_dfs0, is_dfs;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001195 u8 seg0_idx = 0, seg1_idx = 0, op_class, chan_no;
Hai Shalom74f70d42019-02-11 14:42:39 -08001196 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001197
1198 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001199 HOSTAPD_LEVEL_INFO,
Sunil Ravi036cec52023-03-29 11:35:17 -07001200 "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 -07001201 finished ? "had" : "starting",
Sunil Ravi77d572f2023-01-17 23:58:31 +00001202 hapd->iface->freq,
Hai Shalom60840252021-02-19 19:02:11 -08001203 freq, ht, hapd->iconf->ch_switch_vht_config,
Sunil Ravia04bd252022-05-02 22:54:18 -07001204 hapd->iconf->ch_switch_he_config,
1205 hapd->iconf->ch_switch_eht_config, offset,
Sunil Ravi036cec52023-03-29 11:35:17 -07001206 width, channel_width_to_string(width), cf1, cf2,
1207 punct_bitmap);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001208
Hai Shalom1dc4d202019-04-29 16:22:27 -07001209 if (!hapd->iface->current_mode) {
1210 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1211 HOSTAPD_LEVEL_WARNING,
1212 "ignore channel switch since the interface is not yet ready");
1213 return;
1214 }
1215
Sunil Ravi77d572f2023-01-17 23:58:31 +00001216 /* Check if any of configured channels require DFS */
1217 is_dfs0 = hostapd_is_dfs_required(hapd->iface);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001218 hapd->iface->freq = freq;
1219
1220 channel = hostapd_hw_get_channel(hapd, freq);
1221 if (!channel) {
1222 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001223 HOSTAPD_LEVEL_WARNING,
1224 "driver switched to bad channel!");
Dmitry Shmidt04949592012-07-19 12:16:46 -07001225 return;
1226 }
1227
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001228 switch (width) {
1229 case CHAN_WIDTH_80:
Sunil8cd6f4d2022-06-28 18:40:46 +00001230 chwidth = CONF_OPER_CHWIDTH_80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001231 break;
1232 case CHAN_WIDTH_80P80:
Sunil8cd6f4d2022-06-28 18:40:46 +00001233 chwidth = CONF_OPER_CHWIDTH_80P80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001234 break;
1235 case CHAN_WIDTH_160:
Sunil8cd6f4d2022-06-28 18:40:46 +00001236 chwidth = CONF_OPER_CHWIDTH_160MHZ;
1237 break;
1238 case CHAN_WIDTH_320:
1239 chwidth = CONF_OPER_CHWIDTH_320MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001240 break;
1241 case CHAN_WIDTH_20_NOHT:
1242 case CHAN_WIDTH_20:
1243 case CHAN_WIDTH_40:
1244 default:
Sunil8cd6f4d2022-06-28 18:40:46 +00001245 chwidth = CONF_OPER_CHWIDTH_USE_HT;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001246 break;
1247 }
1248
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001249 /* The operating channel changed when CSA finished, so need to update
1250 * hw_mode for all following operations to cover the cases where the
1251 * driver changed the operating band. */
1252 if (finished && hostapd_csa_update_hwmode(hapd->iface))
1253 return;
1254
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001255 switch (hapd->iface->current_mode->mode) {
1256 case HOSTAPD_MODE_IEEE80211A:
Hai Shalom899fcc72020-10-19 14:38:18 -07001257 if (cf1 == 5935)
1258 seg0_idx = (cf1 - 5925) / 5;
1259 else if (cf1 > 5950)
1260 seg0_idx = (cf1 - 5950) / 5;
1261 else if (cf1 > 5000)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001262 seg0_idx = (cf1 - 5000) / 5;
Hai Shalom899fcc72020-10-19 14:38:18 -07001263
1264 if (cf2 == 5935)
1265 seg1_idx = (cf2 - 5925) / 5;
1266 else if (cf2 > 5950)
1267 seg1_idx = (cf2 - 5950) / 5;
1268 else if (cf2 > 5000)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001269 seg1_idx = (cf2 - 5000) / 5;
1270 break;
1271 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001272 ieee80211_freq_to_chan(cf1, &seg0_idx);
1273 ieee80211_freq_to_chan(cf2, &seg1_idx);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001274 break;
1275 }
1276
Dmitry Shmidt04949592012-07-19 12:16:46 -07001277 hapd->iconf->channel = channel;
1278 hapd->iconf->ieee80211n = ht;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001279 if (!ht)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001280 hapd->iconf->ieee80211ac = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001281 if (hapd->iconf->ch_switch_vht_config) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001282 /* CHAN_SWITCH VHT config */
1283 if (hapd->iconf->ch_switch_vht_config &
1284 CH_SWITCH_VHT_ENABLED)
1285 hapd->iconf->ieee80211ac = 1;
1286 else if (hapd->iconf->ch_switch_vht_config &
1287 CH_SWITCH_VHT_DISABLED)
1288 hapd->iconf->ieee80211ac = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001289 }
1290 if (hapd->iconf->ch_switch_he_config) {
Hai Shalom60840252021-02-19 19:02:11 -08001291 /* CHAN_SWITCH HE config */
1292 if (hapd->iconf->ch_switch_he_config &
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001293 CH_SWITCH_HE_ENABLED) {
Hai Shalom60840252021-02-19 19:02:11 -08001294 hapd->iconf->ieee80211ax = 1;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001295 if (hapd->iface->freq > 4000 &&
1296 hapd->iface->freq < 5895)
1297 hapd->iconf->ieee80211ac = 1;
1298 }
Hai Shalom60840252021-02-19 19:02:11 -08001299 else if (hapd->iconf->ch_switch_he_config &
1300 CH_SWITCH_HE_DISABLED)
1301 hapd->iconf->ieee80211ax = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001302 }
Sunil Ravia04bd252022-05-02 22:54:18 -07001303#ifdef CONFIG_IEEE80211BE
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001304 if (hapd->iconf->ch_switch_eht_config) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001305 /* CHAN_SWITCH EHT config */
1306 if (hapd->iconf->ch_switch_eht_config &
1307 CH_SWITCH_EHT_ENABLED) {
1308 hapd->iconf->ieee80211be = 1;
1309 hapd->iconf->ieee80211ax = 1;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001310 if (!is_6ghz_freq(hapd->iface->freq) &&
1311 hapd->iface->freq > 4000)
Sunil Ravia04bd252022-05-02 22:54:18 -07001312 hapd->iconf->ieee80211ac = 1;
1313 } else if (hapd->iconf->ch_switch_eht_config &
1314 CH_SWITCH_EHT_DISABLED)
1315 hapd->iconf->ieee80211be = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001316 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001317#endif /* CONFIG_IEEE80211BE */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001318 hapd->iconf->ch_switch_vht_config = 0;
Hai Shalom60840252021-02-19 19:02:11 -08001319 hapd->iconf->ch_switch_he_config = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -07001320 hapd->iconf->ch_switch_eht_config = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001321
Hai Shaloma20dcd72022-02-04 13:43:00 -08001322 if (width == CHAN_WIDTH_40 || width == CHAN_WIDTH_80 ||
Sunil Ravi640215c2023-06-28 23:08:09 +00001323 width == CHAN_WIDTH_80P80 || width == CHAN_WIDTH_160 ||
1324 width == CHAN_WIDTH_320)
Hai Shaloma20dcd72022-02-04 13:43:00 -08001325 hapd->iconf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1326 else if (width == CHAN_WIDTH_20 || width == CHAN_WIDTH_20_NOHT)
1327 hapd->iconf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1328
Dmitry Shmidt04949592012-07-19 12:16:46 -07001329 hapd->iconf->secondary_channel = offset;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001330 if (ieee80211_freq_to_channel_ext(freq, offset, chwidth,
1331 &op_class, &chan_no) !=
1332 NUM_HOSTAPD_MODES)
1333 hapd->iconf->op_class = op_class;
Hai Shalom81f62d82019-07-22 12:10:00 -07001334 hostapd_set_oper_chwidth(hapd->iconf, chwidth);
1335 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, seg0_idx);
1336 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, seg1_idx);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001337 /* Auto-detect new bw320_offset */
1338 hostapd_set_and_check_bw320_offset(hapd->iconf, 0);
Sunil Ravi036cec52023-03-29 11:35:17 -07001339#ifdef CONFIG_IEEE80211BE
1340 hapd->iconf->punct_bitmap = punct_bitmap;
1341#endif /* CONFIG_IEEE80211BE */
Hai Shaloma20dcd72022-02-04 13:43:00 -08001342 if (hapd->iconf->ieee80211ac) {
1343 hapd->iconf->vht_capab &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
Sunil8cd6f4d2022-06-28 18:40:46 +00001344 if (chwidth == CONF_OPER_CHWIDTH_160MHZ)
Hai Shaloma20dcd72022-02-04 13:43:00 -08001345 hapd->iconf->vht_capab |=
1346 VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Sunil8cd6f4d2022-06-28 18:40:46 +00001347 else if (chwidth == CONF_OPER_CHWIDTH_80P80MHZ)
Hai Shaloma20dcd72022-02-04 13:43:00 -08001348 hapd->iconf->vht_capab |=
1349 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1350 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001351
Roshan Pius3a1667e2018-07-03 15:17:14 -07001352 is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features,
1353 hapd->iface->num_hw_features);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001354
Hai Shalom81f62d82019-07-22 12:10:00 -07001355 wpa_msg(hapd->msg_ctx, MSG_INFO,
Sunil Ravi036cec52023-03-29 11:35:17 -07001356 "%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 -07001357 finished ? WPA_EVENT_CHANNEL_SWITCH :
1358 WPA_EVENT_CHANNEL_SWITCH_STARTED,
1359 freq, ht, offset, channel_width_to_string(width),
Sunil Ravi036cec52023-03-29 11:35:17 -07001360 cf1, cf2, is_dfs0, is_dfs, punct_bitmap);
Hai Shalom81f62d82019-07-22 12:10:00 -07001361 if (!finished)
1362 return;
1363
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001364 if (hapd->csa_in_progress &&
1365 freq == hapd->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001366 hostapd_cleanup_cs_params(hapd);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001367 ieee802_11_set_beacon(hapd);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001368
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001369 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
1370 "freq=%d dfs=%d", freq, is_dfs);
1371 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00001372 /* Complete AP configuration for the first bring up. */
1373 if (is_dfs0 > 0 &&
1374 hostapd_is_dfs_required(hapd->iface) <= 0 &&
1375 hapd->iface->state != HAPD_IFACE_ENABLED) {
1376 /* Fake a CAC start bit to skip setting channel */
1377 hapd->iface->cac_started = 1;
1378 hostapd_setup_interface_complete(hapd->iface, 0);
1379 }
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001380 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
1381 "freq=%d dfs=%d", freq, is_dfs);
Hai Shalomfdcde762020-04-02 11:19:20 -07001382 } else if (is_dfs &&
1383 hostapd_is_dfs_required(hapd->iface) &&
1384 !hostapd_is_dfs_chan_available(hapd->iface) &&
1385 !hapd->iface->cac_started) {
1386 hostapd_disable_iface(hapd->iface);
1387 hostapd_enable_iface(hapd->iface);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001388 }
Hai Shalom74f70d42019-02-11 14:42:39 -08001389
1390 for (i = 0; i < hapd->iface->num_bss; i++)
1391 hostapd_neighbor_set_own_report(hapd->iface->bss[i]);
Hai Shalom899fcc72020-10-19 14:38:18 -07001392
1393#ifdef CONFIG_OCV
Sunil Ravia04bd252022-05-02 22:54:18 -07001394 if (hapd->conf->ocv &&
1395 !(hapd->iface->drv_flags2 &
1396 WPA_DRIVER_FLAGS2_SA_QUERY_OFFLOAD_AP)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001397 struct sta_info *sta;
1398 bool check_sa_query = false;
1399
1400 for (sta = hapd->sta_list; sta; sta = sta->next) {
1401 if (wpa_auth_uses_ocv(sta->wpa_sm) &&
1402 !(sta->flags & WLAN_STA_WNM_SLEEP_MODE)) {
1403 sta->post_csa_sa_query = 1;
1404 check_sa_query = true;
1405 }
1406 }
1407
1408 if (check_sa_query) {
1409 wpa_printf(MSG_DEBUG,
1410 "OCV: Check post-CSA SA Query initiation in 15 seconds");
1411 eloop_register_timeout(15, 0,
1412 hostapd_ocv_check_csa_sa_query,
1413 hapd, NULL);
1414 }
1415 }
1416#endif /* CONFIG_OCV */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001417#endif /* NEED_AP_MLME */
1418}
1419
1420
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001421void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
1422 const u8 *addr, int reason_code)
1423{
1424 switch (reason_code) {
1425 case MAX_CLIENT_REACHED:
1426 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
1427 MAC2STR(addr));
1428 break;
1429 case BLOCKED_CLIENT:
1430 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
1431 MAC2STR(addr));
1432 break;
1433 }
1434}
1435
1436
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001437#ifdef CONFIG_ACS
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001438void hostapd_acs_channel_selected(struct hostapd_data *hapd,
1439 struct acs_selected_channels *acs_res)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001440{
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001441 int ret, i;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001442 int err = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001443 struct hostapd_channel_data *pri_chan;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001444
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001445#ifdef CONFIG_IEEE80211BE
1446 if (acs_res->link_id != -1) {
1447 hapd = hostapd_mld_get_link_bss(hapd, acs_res->link_id);
1448 if (!hapd) {
1449 wpa_printf(MSG_ERROR,
1450 "MLD: Failed to get link BSS for EVENT_ACS_CHANNEL_SELECTED link_id=%d",
1451 acs_res->link_id);
1452 return;
1453 }
1454 }
1455#endif /* CONFIG_IEEE80211BE */
1456
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001457 if (hapd->iconf->channel) {
1458 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
1459 hapd->iconf->channel);
1460 return;
1461 }
1462
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001463 hapd->iface->freq = acs_res->pri_freq;
1464
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001465 if (!hapd->iface->current_mode) {
1466 for (i = 0; i < hapd->iface->num_hw_features; i++) {
1467 struct hostapd_hw_modes *mode =
1468 &hapd->iface->hw_features[i];
1469
1470 if (mode->mode == acs_res->hw_mode) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001471 if (hapd->iface->freq > 0 &&
1472 !hw_get_chan(mode->mode,
1473 hapd->iface->freq,
1474 hapd->iface->hw_features,
1475 hapd->iface->num_hw_features))
1476 continue;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001477 hapd->iface->current_mode = mode;
1478 break;
1479 }
1480 }
1481 if (!hapd->iface->current_mode) {
1482 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1483 HOSTAPD_LEVEL_WARNING,
1484 "driver selected to bad hw_mode");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001485 err = 1;
1486 goto out;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001487 }
1488 }
1489
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001490 if (!acs_res->pri_freq) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001491 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1492 HOSTAPD_LEVEL_WARNING,
1493 "driver switched to bad channel");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001494 err = 1;
1495 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001496 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001497 pri_chan = hw_get_channel_freq(hapd->iface->current_mode->mode,
1498 acs_res->pri_freq, NULL,
1499 hapd->iface->hw_features,
1500 hapd->iface->num_hw_features);
1501 if (!pri_chan) {
1502 wpa_printf(MSG_ERROR,
1503 "ACS: Could not determine primary channel number from pri_freq %u",
1504 acs_res->pri_freq);
1505 err = 1;
1506 goto out;
1507 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001508
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001509 hapd->iconf->channel = pri_chan->chan;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001510 hapd->iconf->acs = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001511
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001512 if (acs_res->sec_freq == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001513 hapd->iconf->secondary_channel = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001514 else if (acs_res->sec_freq < acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001515 hapd->iconf->secondary_channel = -1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001516 else if (acs_res->sec_freq > acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001517 hapd->iconf->secondary_channel = 1;
1518 else {
1519 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001520 err = 1;
1521 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001522 }
1523
Hai Shalomfdcde762020-04-02 11:19:20 -07001524 hapd->iconf->edmg_channel = acs_res->edmg_channel;
1525
Hai Shalom81f62d82019-07-22 12:10:00 -07001526 if (hapd->iface->conf->ieee80211ac || hapd->iface->conf->ieee80211ax) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001527 /* set defaults for backwards compatibility */
Hai Shalom81f62d82019-07-22 12:10:00 -07001528 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1529 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, 0);
Sunil8cd6f4d2022-06-28 18:40:46 +00001530 hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_USE_HT);
Hai Shalomfdcde762020-04-02 11:19:20 -07001531 if (acs_res->ch_width == 40) {
1532 if (is_6ghz_freq(acs_res->pri_freq))
1533 hostapd_set_oper_centr_freq_seg0_idx(
1534 hapd->iconf,
1535 acs_res->vht_seg0_center_ch);
1536 } else if (acs_res->ch_width == 80) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001537 hostapd_set_oper_centr_freq_seg0_idx(
1538 hapd->iconf, acs_res->vht_seg0_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001539 if (acs_res->vht_seg1_center_ch == 0) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001540 hostapd_set_oper_chwidth(
1541 hapd->iconf, CONF_OPER_CHWIDTH_80MHZ);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001542 } else {
Sunil8cd6f4d2022-06-28 18:40:46 +00001543 hostapd_set_oper_chwidth(
1544 hapd->iconf,
1545 CONF_OPER_CHWIDTH_80P80MHZ);
Hai Shalom81f62d82019-07-22 12:10:00 -07001546 hostapd_set_oper_centr_freq_seg1_idx(
1547 hapd->iconf,
1548 acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001549 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001550 } else if (acs_res->ch_width == 160) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001551 hostapd_set_oper_chwidth(hapd->iconf,
1552 CONF_OPER_CHWIDTH_160MHZ);
Hai Shalomfdcde762020-04-02 11:19:20 -07001553 hostapd_set_oper_centr_freq_seg0_idx(
1554 hapd->iconf, acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001555 }
1556 }
1557
Sunil8cd6f4d2022-06-28 18:40:46 +00001558#ifdef CONFIG_IEEE80211BE
1559 if (hapd->iface->conf->ieee80211be && acs_res->ch_width == 320) {
1560 hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_320MHZ);
1561 hostapd_set_oper_centr_freq_seg0_idx(
1562 hapd->iconf, acs_res->vht_seg1_center_ch);
1563 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1564 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001565
1566 if (hapd->iface->conf->ieee80211be && acs_res->puncture_bitmap)
1567 hapd->iconf->punct_bitmap = acs_res->puncture_bitmap;
Sunil8cd6f4d2022-06-28 18:40:46 +00001568#endif /* CONFIG_IEEE80211BE */
1569
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001570out:
1571 ret = hostapd_acs_completed(hapd->iface, err);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001572 if (ret) {
1573 wpa_printf(MSG_ERROR,
1574 "ACS: Possibly channel configuration is invalid");
1575 }
1576}
1577#endif /* CONFIG_ACS */
1578
1579
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001580int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001581 const u8 *bssid, const u8 *ie, size_t ie_len,
1582 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001583{
1584 size_t i;
1585 int ret = 0;
1586
1587 if (sa == NULL || ie == NULL)
1588 return -1;
1589
1590 random_add_randomness(sa, ETH_ALEN);
1591 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
1592 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001593 sa, da, bssid, ie, ie_len,
1594 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001595 ret = 1;
1596 break;
1597 }
1598 }
1599 return ret;
1600}
1601
1602
1603#ifdef HOSTAPD
1604
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001605#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001606static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001607 u16 auth_transaction, u16 status,
1608 const u8 *ies, size_t ies_len)
1609{
1610 struct hostapd_data *hapd = ctx;
1611 struct sta_info *sta;
1612
1613 sta = ap_get_sta(hapd, dst);
1614 if (sta == NULL)
1615 return;
1616
1617 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
1618 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
1619 sta->flags |= WLAN_STA_AUTH;
1620
1621 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
1622}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001623#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001624
1625
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001626#ifdef CONFIG_FILS
1627static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
1628 struct sta_info *sta, u16 resp,
1629 struct wpabuf *data, int pub)
1630{
1631 if (resp == WLAN_STATUS_SUCCESS) {
1632 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1633 HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
1634 sta->flags |= WLAN_STA_AUTH;
1635 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1636 sta->auth_alg = WLAN_AUTH_FILS_SK;
1637 mlme_authenticate_indication(hapd, sta);
1638 } else {
1639 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1640 HOSTAPD_LEVEL_DEBUG,
1641 "authentication failed (FILS)");
1642 }
1643
1644 hostapd_sta_auth(hapd, sta->addr, 2, resp,
1645 data ? wpabuf_head(data) : NULL,
1646 data ? wpabuf_len(data) : 0);
1647 wpabuf_free(data);
1648}
1649#endif /* CONFIG_FILS */
1650
1651
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001652static void hostapd_notif_auth(struct hostapd_data *hapd,
1653 struct auth_info *rx_auth)
1654{
1655 struct sta_info *sta;
1656 u16 status = WLAN_STATUS_SUCCESS;
1657 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1658 size_t resp_ies_len = 0;
1659
1660 sta = ap_get_sta(hapd, rx_auth->peer);
1661 if (!sta) {
1662 sta = ap_sta_add(hapd, rx_auth->peer);
1663 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -07001664 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001665 goto fail;
1666 }
1667 }
1668 sta->flags &= ~WLAN_STA_PREAUTH;
1669 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001670#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001671 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
1672 sta->auth_alg = WLAN_AUTH_FT;
1673 if (sta->wpa_sm == NULL)
1674 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001675 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001676 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001677 wpa_printf(MSG_DEBUG,
1678 "FT: Failed to initialize WPA state machine");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001679 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1680 goto fail;
1681 }
Sunil Ravi7f769292024-07-23 22:21:32 +00001682 wpa_ft_process_auth(sta->wpa_sm,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001683 rx_auth->auth_transaction, rx_auth->ies,
1684 rx_auth->ies_len,
1685 hostapd_notify_auth_ft_finish, hapd);
1686 return;
1687 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001688#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001689
1690#ifdef CONFIG_FILS
1691 if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
1692 sta->auth_alg = WLAN_AUTH_FILS_SK;
1693 handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
1694 rx_auth->auth_type, rx_auth->auth_transaction,
1695 rx_auth->status_code,
1696 hostapd_notify_auth_fils_finish);
1697 return;
1698 }
1699#endif /* CONFIG_FILS */
1700
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001701fail:
1702 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
1703 status, resp_ies, resp_ies_len);
1704}
1705
1706
Hai Shalom021b0b52019-04-10 11:17:58 -07001707#ifndef NEED_AP_MLME
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001708static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001709 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001710{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001711 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001712 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001713 size_t plen __maybe_unused;
1714 u16 fc;
Hai Shalom74f70d42019-02-11 14:42:39 -08001715 u8 *action __maybe_unused;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001716
Hai Shalom74f70d42019-02-11 14:42:39 -08001717 if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001718 return;
1719
Hai Shalom021b0b52019-04-10 11:17:58 -07001720 plen = drv_mgmt->frame_len - IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001721
1722 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
1723 fc = le_to_host16(mgmt->frame_control);
1724 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
1725 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001726
Hai Shalom74f70d42019-02-11 14:42:39 -08001727 action = (u8 *) &mgmt->u.action.u;
1728 wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
1729 " da " MACSTR " plen %d",
1730 mgmt->u.action.category, *action,
1731 MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001732
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001733 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001734 if (sta == NULL) {
1735 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
1736 return;
1737 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001738#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001739 if (mgmt->u.action.category == WLAN_ACTION_FT) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001740 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, plen);
1741 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001742 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001743#endif /* CONFIG_IEEE80211R_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001744 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001745 ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001746 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001747 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001748#ifdef CONFIG_WNM_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001749 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
1750 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001751 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001752 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001753#endif /* CONFIG_WNM_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001754#ifdef CONFIG_FST
1755 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
1756 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
1757 return;
1758 }
1759#endif /* CONFIG_FST */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001760#ifdef CONFIG_DPP
Hai Shalom021b0b52019-04-10 11:17:58 -07001761 if (plen >= 2 + 4 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001762 mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001763 mgmt->u.action.u.vs_public_action.action ==
1764 WLAN_PA_VENDOR_SPECIFIC &&
1765 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1766 OUI_WFA &&
1767 mgmt->u.action.u.vs_public_action.variable[0] ==
1768 DPP_OUI_TYPE) {
1769 const u8 *pos, *end;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001770
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001771 pos = mgmt->u.action.u.vs_public_action.oui;
1772 end = drv_mgmt->frame + drv_mgmt->frame_len;
1773 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
1774 drv_mgmt->freq);
1775 return;
1776 }
1777#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001778#ifdef CONFIG_NAN_USD
1779 if (mgmt->u.action.category == WLAN_ACTION_PUBLIC && plen >= 5 &&
1780 mgmt->u.action.u.vs_public_action.action ==
1781 WLAN_PA_VENDOR_SPECIFIC &&
1782 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1783 OUI_WFA &&
1784 mgmt->u.action.u.vs_public_action.variable[0] == NAN_OUI_TYPE) {
1785 const u8 *pos, *end;
1786
1787 pos = mgmt->u.action.u.vs_public_action.variable;
1788 end = drv_mgmt->frame + drv_mgmt->frame_len;
1789 pos++;
1790 hostapd_nan_usd_rx_sdf(hapd, mgmt->sa, drv_mgmt->freq,
1791 pos, end - pos);
1792 return;
1793 }
1794#endif /* CONFIG_NAN_USD */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001795}
Hai Shalom021b0b52019-04-10 11:17:58 -07001796#endif /* NEED_AP_MLME */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001797
1798
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001799#ifdef NEED_AP_MLME
1800
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001801static struct hostapd_data *
1802switch_link_hapd(struct hostapd_data *hapd, int link_id)
1803{
1804#ifdef CONFIG_IEEE80211BE
1805 if (hapd->conf->mld_ap && link_id >= 0) {
1806 struct hostapd_data *link_bss;
1807
1808 link_bss = hostapd_mld_get_link_bss(hapd, link_id);
1809 if (link_bss)
1810 return link_bss;
1811 }
1812#endif /* CONFIG_IEEE80211BE */
1813
1814 return hapd;
1815}
1816
1817
Sunil Ravi99c035e2024-07-12 01:42:03 +00001818static struct hostapd_data *
1819switch_link_scan(struct hostapd_data *hapd, u64 scan_cookie)
1820{
1821#ifdef CONFIG_IEEE80211BE
1822 if (hapd->conf->mld_ap && scan_cookie != 0) {
1823 unsigned int i;
1824
1825 for (i = 0; i < hapd->iface->interfaces->count; i++) {
1826 struct hostapd_iface *h;
1827 struct hostapd_data *h_hapd;
1828
1829 h = hapd->iface->interfaces->iface[i];
1830 h_hapd = h->bss[0];
1831 if (!hostapd_is_ml_partner(hapd, h_hapd))
1832 continue;
1833
1834 if (h_hapd->scan_cookie == scan_cookie) {
1835 h_hapd->scan_cookie = 0;
1836 return h_hapd;
1837 }
1838 }
1839 }
1840#endif /* CONFIG_IEEE80211BE */
1841
1842 return hapd;
1843}
1844
1845
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001846#define HAPD_BROADCAST ((struct hostapd_data *) -1)
1847
1848static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
Sunil Ravi7f769292024-07-23 22:21:32 +00001849 const u8 *bssid, int link_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001850{
1851 size_t i;
1852
1853 if (bssid == NULL)
1854 return NULL;
1855 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1856 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1857 return HAPD_BROADCAST;
1858
1859 for (i = 0; i < iface->num_bss; i++) {
Sunil Ravi7f769292024-07-23 22:21:32 +00001860 struct hostapd_data *hapd;
1861#ifdef CONFIG_IEEE80211BE
1862 struct hostapd_data *p_hapd;
1863#endif /* CONFIG_IEEE80211BE */
1864
1865 hapd = iface->bss[i];
1866 if (ether_addr_equal(bssid, hapd->own_addr))
1867 return hapd;
1868
1869#ifdef CONFIG_IEEE80211BE
1870 if (ether_addr_equal(bssid, hapd->own_addr) ||
1871 (hapd->conf->mld_ap &&
1872 ether_addr_equal(bssid, hapd->mld->mld_addr) &&
1873 link_id == hapd->mld_link_id))
1874 return hapd;
1875
1876 if (!hapd->conf->mld_ap)
1877 continue;
1878
1879 for_each_mld_link(p_hapd, hapd) {
1880 if (p_hapd == hapd)
1881 continue;
1882
1883 if (ether_addr_equal(bssid, p_hapd->own_addr) ||
1884 (ether_addr_equal(bssid, p_hapd->mld->mld_addr) &&
1885 link_id == p_hapd->mld_link_id))
1886 return p_hapd;
1887 }
1888#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001889 }
1890
1891 return NULL;
1892}
1893
1894
1895static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001896 const u8 *bssid, const u8 *addr,
1897 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001898{
Sunil Ravi7f769292024-07-23 22:21:32 +00001899 hapd = get_hapd_bssid(hapd->iface, bssid, -1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001900 if (hapd == NULL || hapd == HAPD_BROADCAST)
1901 return;
1902
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001903 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001904}
1905
1906
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001907static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001908{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001909 struct hostapd_iface *iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001910 const struct ieee80211_hdr *hdr;
1911 const u8 *bssid;
1912 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001913 int ret;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001914
Sunil Ravi7f769292024-07-23 22:21:32 +00001915 if (rx_mgmt->ctx)
1916 hapd = rx_mgmt->ctx;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001917 hapd = switch_link_hapd(hapd, rx_mgmt->link_id);
1918 iface = hapd->iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001919
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001920#ifdef CONFIG_TESTING_OPTIONS
1921 if (hapd->ext_mgmt_frame_handling) {
1922 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
1923 char *hex = os_malloc(hex_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001924
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001925 if (hex) {
1926 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
1927 rx_mgmt->frame_len);
1928 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1929 os_free(hex);
1930 }
1931 return 1;
1932 }
1933#endif /* CONFIG_TESTING_OPTIONS */
1934
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001935 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1936 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
1937 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001938 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001939
Sunil Ravi7f769292024-07-23 22:21:32 +00001940 hapd = get_hapd_bssid(iface, bssid, rx_mgmt->link_id);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001941
1942 if (!hapd) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001943 u16 fc = le_to_host16(hdr->frame_control);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001944
1945 /*
1946 * Drop frames to unknown BSSIDs except for Beacon frames which
1947 * could be used to update neighbor information.
1948 */
1949 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1950 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1951 hapd = iface->bss[0];
1952 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001953 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001954 }
1955
1956 os_memset(&fi, 0, sizeof(fi));
Roshan Pius3a1667e2018-07-03 15:17:14 -07001957 fi.freq = rx_mgmt->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001958 fi.datarate = rx_mgmt->datarate;
1959 fi.ssi_signal = rx_mgmt->ssi_signal;
1960
1961 if (hapd == HAPD_BROADCAST) {
1962 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001963
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001964 ret = 0;
1965 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -07001966 /* if bss is set, driver will call this function for
1967 * each bss individually. */
1968 if (rx_mgmt->drv_priv &&
1969 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
1970 continue;
1971
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001972 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
1973 rx_mgmt->frame_len, &fi) > 0)
1974 ret = 1;
1975 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001976 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001977 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
1978 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001979
1980 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001981
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001982 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001983}
1984
1985
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001986static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001987 size_t len, u16 stype, int ok, int link_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001988{
1989 struct ieee80211_hdr *hdr;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001990 struct hostapd_data *orig_hapd, *tmp_hapd;
1991
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001992 orig_hapd = hapd;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001993
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001994 hdr = (struct ieee80211_hdr *) buf;
Sunil Ravi7f769292024-07-23 22:21:32 +00001995 hapd = switch_link_hapd(hapd, link_id);
1996 tmp_hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len), link_id);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001997 if (tmp_hapd) {
1998 hapd = tmp_hapd;
1999#ifdef CONFIG_IEEE80211BE
2000 } else if (hapd->conf->mld_ap &&
Sunil Ravi99c035e2024-07-12 01:42:03 +00002001 ether_addr_equal(hapd->mld->mld_addr,
2002 get_hdr_bssid(hdr, len))) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002003 /* AP MLD address match - use hapd pointer as-is */
2004#endif /* CONFIG_IEEE80211BE */
2005 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002006 return;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002007 }
2008
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002009 if (hapd == HAPD_BROADCAST) {
2010 if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
2011 buf[24] != WLAN_ACTION_PUBLIC)
2012 return;
Sunil Ravi7f769292024-07-23 22:21:32 +00002013 hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2, link_id);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002014 if (!hapd || hapd == HAPD_BROADCAST)
2015 return;
2016 /*
2017 * Allow processing of TX status for a Public Action frame that
2018 * used wildcard BBSID.
2019 */
2020 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002021 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
2022}
2023
2024#endif /* NEED_AP_MLME */
2025
2026
2027static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
2028{
2029 struct sta_info *sta = ap_get_sta(hapd, addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002030
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002031 if (sta)
2032 return 0;
2033
2034 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
2035 " - adding a new STA", MAC2STR(addr));
2036 sta = ap_sta_add(hapd, addr);
2037 if (sta) {
2038 hostapd_new_assoc_sta(hapd, sta, 0);
2039 } else {
2040 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
2041 MAC2STR(addr));
2042 return -1;
2043 }
2044
2045 return 0;
2046}
2047
2048
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002049static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
2050 const u8 *data, size_t data_len,
2051 enum frame_encryption encrypted,
2052 int link_id)
2053{
2054 struct hostapd_data *orig_hapd = hapd;
2055
2056#ifdef CONFIG_IEEE80211BE
Sunil Ravi7f769292024-07-23 22:21:32 +00002057 hapd = switch_link_hapd(hapd, link_id);
2058 hapd = hostapd_find_by_sta(hapd->iface, src, true, NULL);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002059#else /* CONFIG_IEEE80211BE */
Sunil Ravi7f769292024-07-23 22:21:32 +00002060 hapd = hostapd_find_by_sta(hapd->iface, src, false, NULL);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002061#endif /* CONFIG_IEEE80211BE */
2062
2063 if (!hapd) {
2064 /* WLAN cases need to have an existing association, but non-WLAN
2065 * cases (mainly, wired IEEE 802.1X) need to be able to process
2066 * EAPOL frames from new devices that do not yet have a STA
2067 * entry and as such, do not get a match in
2068 * hostapd_find_by_sta(). */
2069 wpa_printf(MSG_DEBUG,
2070 "No STA-specific hostapd instance for EAPOL RX found - fall back to initial context");
2071 hapd = orig_hapd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002072 }
2073
Sunil8cd6f4d2022-06-28 18:40:46 +00002074 ieee802_1x_receive(hapd, src, data, data_len, encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002075}
2076
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002077#endif /* HOSTAPD */
2078
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002079
Hai Shalomfdcde762020-04-02 11:19:20 -07002080static struct hostapd_channel_data *
2081hostapd_get_mode_chan(struct hostapd_hw_modes *mode, unsigned int freq)
2082{
2083 int i;
2084 struct hostapd_channel_data *chan;
2085
2086 for (i = 0; i < mode->num_channels; i++) {
2087 chan = &mode->channels[i];
2088 if ((unsigned int) chan->freq == freq)
2089 return chan;
2090 }
2091
2092 return NULL;
2093}
2094
2095
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002096static struct hostapd_channel_data * hostapd_get_mode_channel(
2097 struct hostapd_iface *iface, unsigned int freq)
2098{
2099 int i;
2100 struct hostapd_channel_data *chan;
2101
Hai Shalomfdcde762020-04-02 11:19:20 -07002102 for (i = 0; i < iface->num_hw_features; i++) {
2103 if (hostapd_hw_skip_mode(iface, &iface->hw_features[i]))
2104 continue;
2105 chan = hostapd_get_mode_chan(&iface->hw_features[i], freq);
2106 if (chan)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002107 return chan;
2108 }
2109
2110 return NULL;
2111}
2112
2113
2114static void hostapd_update_nf(struct hostapd_iface *iface,
2115 struct hostapd_channel_data *chan,
2116 struct freq_survey *survey)
2117{
2118 if (!iface->chans_surveyed) {
2119 chan->min_nf = survey->nf;
2120 iface->lowest_nf = survey->nf;
2121 } else {
2122 if (dl_list_empty(&chan->survey_list))
2123 chan->min_nf = survey->nf;
2124 else if (survey->nf < chan->min_nf)
2125 chan->min_nf = survey->nf;
2126 if (survey->nf < iface->lowest_nf)
2127 iface->lowest_nf = survey->nf;
2128 }
2129}
2130
2131
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002132static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
2133 struct survey_results *survey_res)
2134{
2135 struct hostapd_channel_data *chan;
2136 struct freq_survey *survey;
2137 u64 divisor, dividend;
2138
2139 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
2140 list);
2141 if (!survey || !survey->freq)
2142 return;
2143
2144 chan = hostapd_get_mode_channel(iface, survey->freq);
2145 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
2146 return;
2147
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002148 wpa_printf(MSG_DEBUG,
2149 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002150 survey->freq,
2151 (unsigned long int) survey->channel_time,
2152 (unsigned long int) survey->channel_time_busy);
2153
2154 if (survey->channel_time > iface->last_channel_time &&
2155 survey->channel_time > survey->channel_time_busy) {
2156 dividend = survey->channel_time_busy -
2157 iface->last_channel_time_busy;
2158 divisor = survey->channel_time - iface->last_channel_time;
2159
2160 iface->channel_utilization = dividend * 255 / divisor;
2161 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
2162 iface->channel_utilization);
2163 }
2164 iface->last_channel_time = survey->channel_time;
2165 iface->last_channel_time_busy = survey->channel_time_busy;
2166}
2167
2168
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002169void hostapd_event_get_survey(struct hostapd_iface *iface,
2170 struct survey_results *survey_results)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002171{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002172 struct freq_survey *survey, *tmp;
2173 struct hostapd_channel_data *chan;
2174
2175 if (dl_list_empty(&survey_results->survey_list)) {
2176 wpa_printf(MSG_DEBUG, "No survey data received");
2177 return;
2178 }
2179
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002180 if (survey_results->freq_filter) {
2181 hostapd_single_channel_get_survey(iface, survey_results);
2182 return;
2183 }
2184
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002185 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
2186 struct freq_survey, list) {
2187 chan = hostapd_get_mode_channel(iface, survey->freq);
2188 if (!chan)
2189 continue;
2190 if (chan->flag & HOSTAPD_CHAN_DISABLED)
2191 continue;
2192
2193 dl_list_del(&survey->list);
2194 dl_list_add_tail(&chan->survey_list, &survey->list);
2195
2196 hostapd_update_nf(iface, chan, survey);
2197
2198 iface->chans_surveyed++;
2199 }
2200}
2201
2202
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002203#ifdef HOSTAPD
Dmitry Shmidt051af732013-10-22 13:52:46 -07002204#ifdef NEED_AP_MLME
2205
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002206static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
2207{
2208 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
2209 hapd->conf->iface);
2210
2211 if (hapd->csa_in_progress) {
2212 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
2213 hapd->conf->iface);
2214 hostapd_switch_channel_fallback(hapd->iface,
2215 &hapd->cs_freq_params);
2216 }
Yu Ouyang378d3c42021-08-20 17:31:08 +08002217
2218 // inform framework that interface is unavailable
2219 hostapd_disable_iface(hapd->iface);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002220}
2221
2222
Dmitry Shmidt051af732013-10-22 13:52:46 -07002223static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
2224 struct dfs_event *radar)
2225{
2226 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002227 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002228 radar->chan_offset, radar->chan_width,
2229 radar->cf1, radar->cf2);
2230}
2231
2232
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002233static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
2234 struct dfs_event *radar)
2235{
2236 wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
2237 hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
2238 radar->chan_offset, radar->chan_width,
2239 radar->cf1, radar->cf2);
2240}
2241
2242
Dmitry Shmidt051af732013-10-22 13:52:46 -07002243static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
2244 struct dfs_event *radar)
2245{
2246 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002247 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002248 radar->chan_offset, radar->chan_width,
2249 radar->cf1, radar->cf2);
2250}
2251
2252
2253static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
2254 struct dfs_event *radar)
2255{
2256 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002257 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002258 radar->chan_offset, radar->chan_width,
2259 radar->cf1, radar->cf2);
2260}
2261
2262
2263static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
2264 struct dfs_event *radar)
2265{
2266 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002267 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002268 radar->chan_offset, radar->chan_width,
2269 radar->cf1, radar->cf2);
2270}
2271
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002272
2273static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
2274 struct dfs_event *radar)
2275{
2276 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
2277 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
2278 radar->chan_offset, radar->chan_width,
2279 radar->cf1, radar->cf2);
2280}
2281
Dmitry Shmidt051af732013-10-22 13:52:46 -07002282#endif /* NEED_AP_MLME */
2283
2284
Roshan Pius3a1667e2018-07-03 15:17:14 -07002285static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd,
2286 int istatus,
2287 const char *ifname,
2288 const u8 *addr)
2289{
2290 struct sta_info *sta = ap_get_sta(hapd, addr);
2291
2292 if (sta) {
2293 os_free(sta->ifname_wds);
2294 if (istatus == INTERFACE_ADDED)
2295 sta->ifname_wds = os_strdup(ifname);
2296 else
2297 sta->ifname_wds = NULL;
2298 }
2299
2300 wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR,
2301 istatus == INTERFACE_ADDED ?
2302 WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED,
2303 ifname, MAC2STR(addr));
2304}
2305
2306
Hai Shalom81f62d82019-07-22 12:10:00 -07002307#ifdef CONFIG_OWE
2308static int hostapd_notif_update_dh_ie(struct hostapd_data *hapd,
2309 const u8 *peer, const u8 *ie,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002310 size_t ie_len, const u8 *link_addr)
Hai Shalom81f62d82019-07-22 12:10:00 -07002311{
2312 u16 status;
2313 struct sta_info *sta;
2314 struct ieee802_11_elems elems;
2315
2316 if (!hapd || !hapd->wpa_auth) {
2317 wpa_printf(MSG_DEBUG, "OWE: Invalid hapd context");
2318 return -1;
2319 }
2320 if (!peer) {
2321 wpa_printf(MSG_DEBUG, "OWE: Peer unknown");
2322 return -1;
2323 }
2324 if (!(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) {
2325 wpa_printf(MSG_DEBUG, "OWE: No OWE AKM configured");
2326 status = WLAN_STATUS_AKMP_NOT_VALID;
2327 goto err;
2328 }
2329 if (ieee802_11_parse_elems(ie, ie_len, &elems, 1) == ParseFailed) {
2330 wpa_printf(MSG_DEBUG, "OWE: Failed to parse OWE IE for "
2331 MACSTR, MAC2STR(peer));
2332 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
2333 goto err;
2334 }
2335 status = owe_validate_request(hapd, peer, elems.rsn_ie,
2336 elems.rsn_ie_len,
2337 elems.owe_dh, elems.owe_dh_len);
2338 if (status != WLAN_STATUS_SUCCESS)
2339 goto err;
2340
2341 sta = ap_get_sta(hapd, peer);
2342 if (sta) {
2343 ap_sta_no_session_timeout(hapd, sta);
2344 accounting_sta_stop(hapd, sta);
2345
2346 /*
2347 * Make sure that the previously registered inactivity timer
2348 * will not remove the STA immediately.
2349 */
2350 sta->timeout_next = STA_NULLFUNC;
2351 } else {
2352 sta = ap_sta_add(hapd, peer);
2353 if (!sta) {
2354 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
2355 goto err;
2356 }
2357 }
2358 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
2359
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002360#ifdef CONFIG_IEEE80211BE
2361 if (link_addr) {
2362 struct mld_info *info = &sta->mld_info;
2363 u8 link_id = hapd->mld_link_id;
2364
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002365 ap_sta_set_mld(sta, true);
2366 sta->mld_assoc_link_id = link_id;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002367 os_memcpy(info->common_info.mld_addr, peer, ETH_ALEN);
2368 info->links[link_id].valid = true;
2369 os_memcpy(info->links[link_id].local_addr, hapd->own_addr,
2370 ETH_ALEN);
2371 os_memcpy(info->links[link_id].peer_addr, link_addr, ETH_ALEN);
2372 }
2373#endif /* CONFIG_IEEE80211BE */
2374
Hai Shalom81f62d82019-07-22 12:10:00 -07002375 status = owe_process_rsn_ie(hapd, sta, elems.rsn_ie,
2376 elems.rsn_ie_len, elems.owe_dh,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002377 elems.owe_dh_len, link_addr);
Hai Shalom81f62d82019-07-22 12:10:00 -07002378 if (status != WLAN_STATUS_SUCCESS)
2379 ap_free_sta(hapd, sta);
2380
2381 return 0;
2382err:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002383 hostapd_drv_update_dh_ie(hapd, link_addr ? link_addr : peer, status,
2384 NULL, 0);
Hai Shalom81f62d82019-07-22 12:10:00 -07002385 return 0;
2386}
2387#endif /* CONFIG_OWE */
2388
2389
Sunil Ravi7f769292024-07-23 22:21:32 +00002390#ifdef NEED_AP_MLME
2391static void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2392 const u8 *data, size_t len, int ack,
2393 int link_id)
2394{
2395 struct sta_info *sta;
2396
2397 hapd = switch_link_hapd(hapd, link_id);
2398 hapd = hostapd_find_by_sta(hapd->iface, dst, false, &sta);
2399
2400 if (!sta) {
2401 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2402 MACSTR " that is not currently associated",
2403 MAC2STR(dst));
2404 return;
2405 }
2406
2407 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2408}
2409#endif /* NEED_AP_MLME */
2410
2411
2412#ifdef CONFIG_IEEE80211AX
2413static void hostapd_event_color_change(struct hostapd_data *hapd, bool success)
2414{
2415 struct hostapd_data *bss;
2416 size_t i;
2417
2418 for (i = 0; i < hapd->iface->num_bss; i++) {
2419 bss = hapd->iface->bss[i];
2420 if (bss->cca_color == 0)
2421 continue;
2422
2423 if (success)
2424 hapd->iface->conf->he_op.he_bss_color = bss->cca_color;
2425
2426 bss->cca_in_progress = 0;
2427 if (ieee802_11_set_beacon(bss)) {
2428 wpa_printf(MSG_ERROR, "Failed to remove BCCA element");
2429 bss->cca_in_progress = 1;
2430 } else {
2431 hostapd_cleanup_cca_params(bss);
2432 }
2433 }
2434}
2435#endif /* CONFIG_IEEE80211AX */
2436
2437
Sunil Ravic0f5d412024-09-11 22:12:49 +00002438static void hostapd_iface_enable(struct hostapd_data *hapd)
2439{
2440 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
2441 if (hapd->disabled && hapd->started) {
2442 hapd->disabled = 0;
2443 /*
2444 * Try to re-enable interface if the driver stopped it
2445 * when the interface got disabled.
2446 */
2447 if (hapd->wpa_auth)
2448 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
2449 else
2450 hostapd_reconfig_encryption(hapd);
2451 hapd->reenable_beacon = 1;
2452 ieee802_11_set_beacon(hapd);
2453#ifdef NEED_AP_MLME
2454 } else if (hapd->disabled && hapd->iface->cac_started) {
2455 wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC");
2456 hostapd_handle_dfs(hapd->iface);
2457#endif /* NEED_AP_MLME */
2458 }
2459}
2460
2461
2462static void hostapd_iface_disable(struct hostapd_data *hapd)
2463{
2464 hostapd_free_stas(hapd);
2465 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
2466 hapd->disabled = 1;
2467}
2468
2469
2470#ifdef CONFIG_IEEE80211BE
2471
2472static void hostapd_mld_iface_enable(struct hostapd_data *hapd)
2473{
2474 struct hostapd_data *first_link, *link_bss;
2475
2476 first_link = hostapd_mld_is_first_bss(hapd) ? hapd :
2477 hostapd_mld_get_first_bss(hapd);
2478
2479 /* Links have been removed. Re-add all links and enable them, but
2480 * enable the first link BSS before doing that. */
2481 if (hostapd_drv_link_add(first_link, first_link->mld_link_id,
2482 first_link->own_addr)) {
2483 wpa_printf(MSG_ERROR, "MLD: Failed to re-add link %d in MLD %s",
2484 first_link->mld_link_id, first_link->conf->iface);
2485 return;
2486 }
2487
2488 hostapd_iface_enable(first_link);
2489
2490 /* Add other affiliated links */
2491 for_each_mld_link(link_bss, first_link) {
2492 if (link_bss == first_link)
2493 continue;
2494
2495 if (hostapd_drv_link_add(link_bss, link_bss->mld_link_id,
2496 link_bss->own_addr)) {
2497 wpa_printf(MSG_ERROR,
2498 "MLD: Failed to re-add link %d in MLD %s",
2499 link_bss->mld_link_id,
2500 link_bss->conf->iface);
2501 continue;
2502 }
2503
2504 hostapd_iface_enable(link_bss);
2505 }
2506}
2507
2508
2509static void hostapd_mld_iface_disable(struct hostapd_data *hapd)
2510{
2511 struct hostapd_data *link_bss;
2512
2513 for_each_mld_link(link_bss, hapd)
2514 hostapd_iface_disable(link_bss);
2515}
2516
2517#endif /* CONFIG_IEEE80211BE */
2518
2519
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002520void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2521 union wpa_event_data *data)
2522{
2523 struct hostapd_data *hapd = ctx;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002524 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002525#ifndef CONFIG_NO_STDOUT_DEBUG
2526 int level = MSG_DEBUG;
2527
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002528 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002529 data->rx_mgmt.frame_len >= 24) {
2530 const struct ieee80211_hdr *hdr;
2531 u16 fc;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002532
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002533 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2534 fc = le_to_host16(hdr->frame_control);
2535 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2536 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2537 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002538 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2539 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
2540 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002541 }
2542
2543 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
2544 event_to_string(event), event);
2545#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002546
2547 switch (event) {
2548 case EVENT_MICHAEL_MIC_FAILURE:
2549 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
2550 break;
2551 case EVENT_SCAN_RESULTS:
Sunil Ravi99c035e2024-07-12 01:42:03 +00002552#ifdef NEED_AP_MLME
2553 if (data)
2554 hapd = switch_link_scan(hapd,
2555 data->scan_info.scan_cookie);
2556#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002557 if (hapd->iface->scan_cb)
2558 hapd->iface->scan_cb(hapd->iface);
Sunil Ravi99c035e2024-07-12 01:42:03 +00002559#ifdef CONFIG_IEEE80211BE
2560 if (!hapd->iface->scan_cb && hapd->conf->mld_ap) {
2561 /* Other links may be waiting for HT scan result */
2562 unsigned int i;
2563
2564 for (i = 0; i < hapd->iface->interfaces->count; i++) {
2565 struct hostapd_iface *h =
2566 hapd->iface->interfaces->iface[i];
2567 struct hostapd_data *h_hapd = h->bss[0];
2568
2569 if (hostapd_is_ml_partner(hapd, h_hapd) &&
2570 h_hapd->iface->scan_cb)
2571 h_hapd->iface->scan_cb(h_hapd->iface);
2572 }
2573 }
2574#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002575 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002576 case EVENT_WPS_BUTTON_PUSHED:
2577 hostapd_wps_button_pushed(hapd, NULL);
2578 break;
2579#ifdef NEED_AP_MLME
2580 case EVENT_TX_STATUS:
2581 switch (data->tx_status.type) {
2582 case WLAN_FC_TYPE_MGMT:
2583 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
2584 data->tx_status.data_len,
2585 data->tx_status.stype,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002586 data->tx_status.ack,
2587 data->tx_status.link_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002588 break;
2589 case WLAN_FC_TYPE_DATA:
2590 hostapd_tx_status(hapd, data->tx_status.dst,
2591 data->tx_status.data,
2592 data->tx_status.data_len,
2593 data->tx_status.ack);
2594 break;
2595 }
2596 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002597 case EVENT_EAPOL_TX_STATUS:
2598 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
2599 data->eapol_tx_status.data,
2600 data->eapol_tx_status.data_len,
Sunil Ravi7f769292024-07-23 22:21:32 +00002601 data->eapol_tx_status.ack,
2602 data->eapol_tx_status.link_id);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002603 break;
2604 case EVENT_DRIVER_CLIENT_POLL_OK:
2605 hostapd_client_poll_ok(hapd, data->client_poll.addr);
2606 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002607 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002608 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
2609 data->rx_from_unknown.addr,
2610 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002611 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002612#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002613 case EVENT_RX_MGMT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002614 if (!data->rx_mgmt.frame)
2615 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002616#ifdef NEED_AP_MLME
Hai Shalom021b0b52019-04-10 11:17:58 -07002617 hostapd_mgmt_rx(hapd, &data->rx_mgmt);
2618#else /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002619 hostapd_action_rx(hapd, &data->rx_mgmt);
Hai Shalom021b0b52019-04-10 11:17:58 -07002620#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002621 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002622 case EVENT_RX_PROBE_REQ:
2623 if (data->rx_probe_req.sa == NULL ||
2624 data->rx_probe_req.ie == NULL)
2625 break;
2626 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002627 data->rx_probe_req.da,
2628 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002629 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002630 data->rx_probe_req.ie_len,
2631 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002632 break;
2633 case EVENT_NEW_STA:
2634 hostapd_event_new_sta(hapd, data->new_sta.addr);
2635 break;
2636 case EVENT_EAPOL_RX:
2637 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
2638 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00002639 data->eapol_rx.data_len,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002640 data->eapol_rx.encrypted,
2641 data->eapol_rx.link_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002642 break;
2643 case EVENT_ASSOC:
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002644 if (!data)
2645 return;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002646#ifdef CONFIG_IEEE80211BE
2647 if (data->assoc_info.assoc_link_id != -1) {
2648 hapd = hostapd_mld_get_link_bss(
2649 hapd, data->assoc_info.assoc_link_id);
2650 if (!hapd) {
2651 wpa_printf(MSG_ERROR,
2652 "MLD: Failed to get link BSS for EVENT_ASSOC");
2653 return;
2654 }
2655 }
2656#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002657 hostapd_notif_assoc(hapd, data->assoc_info.addr,
2658 data->assoc_info.req_ies,
2659 data->assoc_info.req_ies_len,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002660 data->assoc_info.resp_ies,
2661 data->assoc_info.resp_ies_len,
2662 data->assoc_info.link_addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002663 data->assoc_info.reassoc);
2664 break;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002665 case EVENT_PORT_AUTHORIZED:
2666 /* Port authorized event for an associated STA */
2667 sta = ap_get_sta(hapd, data->port_authorized.sta_addr);
2668 if (sta)
2669 ap_sta_set_authorized(hapd, sta, 1);
2670 else
2671 wpa_printf(MSG_DEBUG,
2672 "No STA info matching port authorized event found");
2673 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07002674#ifdef CONFIG_OWE
2675 case EVENT_UPDATE_DH:
2676 if (!data)
2677 return;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002678#ifdef CONFIG_IEEE80211BE
2679 if (data->update_dh.assoc_link_id != -1) {
2680 hapd = hostapd_mld_get_link_bss(
2681 hapd, data->update_dh.assoc_link_id);
2682 if (!hapd) {
2683 wpa_printf(MSG_ERROR,
2684 "MLD: Failed to get link BSS for EVENT_UPDATE_DH assoc_link_id=%d",
2685 data->update_dh.assoc_link_id);
2686 return;
2687 }
2688 }
2689#endif /* CONFIG_IEEE80211BE */
Hai Shalom81f62d82019-07-22 12:10:00 -07002690 hostapd_notif_update_dh_ie(hapd, data->update_dh.peer,
2691 data->update_dh.ie,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002692 data->update_dh.ie_len,
2693 data->update_dh.link_addr);
Hai Shalom81f62d82019-07-22 12:10:00 -07002694 break;
2695#endif /* CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002696 case EVENT_DISASSOC:
2697 if (data)
2698 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
2699 break;
2700 case EVENT_DEAUTH:
2701 if (data)
2702 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
2703 break;
2704 case EVENT_STATION_LOW_ACK:
2705 if (!data)
2706 break;
2707 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
2708 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002709 case EVENT_AUTH:
2710 hostapd_notif_auth(hapd, &data->auth);
2711 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07002712 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07002713 case EVENT_CH_SWITCH:
2714 if (!data)
2715 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002716#ifdef CONFIG_IEEE80211BE
2717 if (data->ch_switch.link_id != -1) {
2718 hapd = hostapd_mld_get_link_bss(
2719 hapd, data->ch_switch.link_id);
2720 if (!hapd) {
2721 wpa_printf(MSG_ERROR,
2722 "MLD: Failed to get link (ID %d) BSS for EVENT_CH_SWITCH/EVENT_CH_SWITCH_STARTED",
2723 data->ch_switch.link_id);
2724 break;
2725 }
2726 }
2727#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt04949592012-07-19 12:16:46 -07002728 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
2729 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08002730 data->ch_switch.ch_offset,
2731 data->ch_switch.ch_width,
2732 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07002733 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07002734 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07002735 event == EVENT_CH_SWITCH);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002736 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002737 case EVENT_CONNECT_FAILED_REASON:
2738 if (!data)
2739 break;
2740 hostapd_event_connect_failed_reason(
2741 hapd, data->connect_failed_reason.addr,
2742 data->connect_failed_reason.code);
2743 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002744 case EVENT_SURVEY:
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002745 hostapd_event_get_survey(hapd->iface, &data->survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002746 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002747#ifdef NEED_AP_MLME
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002748 case EVENT_INTERFACE_UNAVAILABLE:
2749 hostapd_event_iface_unavailable(hapd);
2750 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002751 case EVENT_DFS_RADAR_DETECTED:
2752 if (!data)
2753 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002754 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002755 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
2756 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002757 case EVENT_DFS_PRE_CAC_EXPIRED:
2758 if (!data)
2759 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002760 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002761 hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
2762 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002763 case EVENT_DFS_CAC_FINISHED:
2764 if (!data)
2765 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002766 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002767 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
2768 break;
2769 case EVENT_DFS_CAC_ABORTED:
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_cac_aborted(hapd, &data->dfs_event);
2774 break;
2775 case EVENT_DFS_NOP_FINISHED:
2776 if (!data)
2777 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002778 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002779 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
2780 break;
2781 case EVENT_CHANNEL_LIST_CHANGED:
2782 /* channel list changed (regulatory?), update channel list */
2783 /* TODO: check this. hostapd_get_hw_features() initializes
2784 * too much stuff. */
2785 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002786 hostapd_channel_list_updated(
2787 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002788 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002789 case EVENT_DFS_CAC_STARTED:
2790 if (!data)
2791 break;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00002792 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002793 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
2794 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002795#endif /* NEED_AP_MLME */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002796 case EVENT_INTERFACE_ENABLED:
Sunil Ravic0f5d412024-09-11 22:12:49 +00002797#ifdef CONFIG_IEEE80211BE
2798 if (hapd->conf->mld_ap) {
2799 hostapd_mld_iface_enable(hapd);
2800 break;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002801 }
Sunil Ravic0f5d412024-09-11 22:12:49 +00002802#endif /* CONFIG_IEEE80211BE */
2803 hostapd_iface_enable(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002804 break;
2805 case EVENT_INTERFACE_DISABLED:
Sunil Ravic0f5d412024-09-11 22:12:49 +00002806#ifdef CONFIG_IEEE80211BE
2807 if (hapd->conf->mld_ap) {
2808 hostapd_mld_iface_disable(hapd);
2809 break;
2810 }
2811#endif /* CONFIG_IEEE80211BE */
2812 hostapd_iface_disable(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002813 break;
2814#ifdef CONFIG_ACS
2815 case EVENT_ACS_CHANNEL_SELECTED:
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002816 hostapd_acs_channel_selected(hapd,
2817 &data->acs_selected_channels);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002818 break;
2819#endif /* CONFIG_ACS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002820 case EVENT_STATION_OPMODE_CHANGED:
2821 hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr,
2822 data->sta_opmode.smps_mode,
2823 data->sta_opmode.chan_width,
2824 data->sta_opmode.rx_nss);
2825 break;
2826 case EVENT_WDS_STA_INTERFACE_STATUS:
2827 hostapd_event_wds_sta_interface_status(
2828 hapd, data->wds_sta_interface.istatus,
2829 data->wds_sta_interface.ifname,
2830 data->wds_sta_interface.sta_addr);
2831 break;
Sunil Ravia04bd252022-05-02 22:54:18 -07002832#ifdef CONFIG_IEEE80211AX
2833 case EVENT_BSS_COLOR_COLLISION:
2834 /* The BSS color is shared amongst all BBSs on a specific phy.
2835 * Therefore we always start the color change on the primary
2836 * BSS. */
Sunil Ravi7f769292024-07-23 22:21:32 +00002837 hapd = switch_link_hapd(hapd,
2838 data->bss_color_collision.link_id);
Sunil Ravia04bd252022-05-02 22:54:18 -07002839 wpa_printf(MSG_DEBUG, "BSS color collision on %s",
2840 hapd->conf->iface);
2841 hostapd_switch_color(hapd->iface->bss[0],
2842 data->bss_color_collision.bitmap);
2843 break;
2844 case EVENT_CCA_STARTED_NOTIFY:
Sunil Ravi7f769292024-07-23 22:21:32 +00002845 hapd = switch_link_hapd(hapd,
2846 data->bss_color_collision.link_id);
2847 wpa_printf(MSG_DEBUG, "CCA started on %s",
Sunil Ravia04bd252022-05-02 22:54:18 -07002848 hapd->conf->iface);
2849 break;
2850 case EVENT_CCA_ABORTED_NOTIFY:
Sunil Ravi7f769292024-07-23 22:21:32 +00002851 hapd = switch_link_hapd(hapd,
2852 data->bss_color_collision.link_id);
2853 wpa_printf(MSG_DEBUG, "CCA aborted on %s",
Sunil Ravia04bd252022-05-02 22:54:18 -07002854 hapd->conf->iface);
Sunil Ravi7f769292024-07-23 22:21:32 +00002855 hostapd_event_color_change(hapd, false);
Sunil Ravia04bd252022-05-02 22:54:18 -07002856 break;
2857 case EVENT_CCA_NOTIFY:
Sunil Ravi7f769292024-07-23 22:21:32 +00002858 hapd = switch_link_hapd(hapd,
2859 data->bss_color_collision.link_id);
2860 wpa_printf(MSG_DEBUG, "CCA finished on %s",
Sunil Ravia04bd252022-05-02 22:54:18 -07002861 hapd->conf->iface);
Sunil Ravi7f769292024-07-23 22:21:32 +00002862 hostapd_event_color_change(hapd, true);
Sunil Ravia04bd252022-05-02 22:54:18 -07002863 break;
2864#endif /* CONFIG_IEEE80211AX */
Sunil Ravic0f5d412024-09-11 22:12:49 +00002865#ifdef CONFIG_IEEE80211BE
2866 case EVENT_MLD_INTERFACE_FREED:
2867 wpa_printf(MSG_DEBUG, "MLD: Interface %s freed",
2868 hapd->conf->iface);
2869 hostapd_mld_interface_freed(hapd);
2870 break;
2871#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002872 default:
2873 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
2874 break;
2875 }
2876}
2877
Dmitry Shmidte4663042016-04-04 10:07:49 -07002878
2879void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
2880 union wpa_event_data *data)
2881{
2882 struct hapd_interfaces *interfaces = ctx;
2883 struct hostapd_data *hapd;
2884
2885 if (event != EVENT_INTERFACE_STATUS)
2886 return;
2887
2888 hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
2889 if (hapd && hapd->driver && hapd->driver->get_ifindex &&
2890 hapd->drv_priv) {
2891 unsigned int ifindex;
2892
2893 ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
2894 if (ifindex != data->interface_status.ifindex) {
2895 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
2896 "interface status ifindex %d mismatch (%d)",
2897 ifindex, data->interface_status.ifindex);
2898 return;
2899 }
2900 }
2901 if (hapd)
2902 wpa_supplicant_event(hapd, event, data);
2903}
2904
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002905#endif /* HOSTAPD */