blob: 98794c26e9f23b195eaaf0ad81636331139ce615 [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"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070045
46
47#ifdef CONFIG_FILS
48void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd,
49 struct sta_info *sta)
50{
51 u16 reply_res = WLAN_STATUS_SUCCESS;
52 struct ieee802_11_elems elems;
53 u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf;
54 int new_assoc;
55
56 wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR,
57 __func__, MAC2STR(sta->addr));
58 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
59 if (!sta->fils_pending_assoc_req)
60 return;
61
Sunil Ravi2a14cf12023-11-21 00:54:38 +000062 if (ieee802_11_parse_elems(sta->fils_pending_assoc_req,
63 sta->fils_pending_assoc_req_len, &elems,
64 0) == ParseFailed ||
65 !elems.fils_session) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070066 wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element",
67 __func__);
68 return;
69 }
70
71 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
72 elems.fils_session,
73 sta->fils_hlp_resp);
74
75 reply_res = hostapd_sta_assoc(hapd, sta->addr,
76 sta->fils_pending_assoc_is_reassoc,
77 WLAN_STATUS_SUCCESS,
78 buf, p - buf);
79 ap_sta_set_authorized(hapd, sta, 1);
80 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
81 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
82 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
83 hostapd_set_sta_flags(hapd, sta);
84 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
85 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
86 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
87 os_free(sta->fils_pending_assoc_req);
88 sta->fils_pending_assoc_req = NULL;
89 sta->fils_pending_assoc_req_len = 0;
90 wpabuf_free(sta->fils_hlp_resp);
91 sta->fils_hlp_resp = NULL;
92 wpabuf_free(sta->hlp_dhcp_discover);
93 sta->hlp_dhcp_discover = NULL;
94 fils_hlp_deinit(hapd);
95
96 /*
97 * Remove the station in case transmission of a success response fails
98 * (the STA was added associated to the driver) or if the station was
99 * previously added unassociated.
100 */
101 if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) {
102 hostapd_drv_sta_remove(hapd, sta->addr);
103 sta->added_unassoc = 0;
104 }
105}
106#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700107
108
Hai Shalom899fcc72020-10-19 14:38:18 -0700109static bool check_sa_query_need(struct hostapd_data *hapd, struct sta_info *sta)
110{
111 if ((sta->flags &
112 (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED)) !=
113 (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED))
114 return false;
115
116 if (!sta->sa_query_timed_out && sta->sa_query_count > 0)
117 ap_check_sa_query_timeout(hapd, sta);
118
119 if (!sta->sa_query_timed_out && (sta->auth_alg != WLAN_AUTH_FT)) {
120 /*
121 * STA has already been associated with MFP and SA Query timeout
122 * has not been reached. Reject the association attempt
123 * temporarily and start SA Query, if one is not pending.
124 */
125 if (sta->sa_query_count == 0)
126 ap_sta_start_sa_query(hapd, sta);
127
128 return true;
129 }
130
131 return false;
132}
133
134
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000135#ifdef CONFIG_IEEE80211BE
136static int hostapd_update_sta_links_status(struct hostapd_data *hapd,
137 struct sta_info *sta,
138 const u8 *resp_ies,
139 size_t resp_ies_len)
140{
141 struct mld_info *info = &sta->mld_info;
142 struct wpabuf *mlebuf;
143 const u8 *mle, *pos;
144 struct ieee802_11_elems elems;
145 size_t mle_len, rem_len;
146 int ret = 0;
147
148 if (!resp_ies) {
149 wpa_printf(MSG_DEBUG,
150 "MLO: (Re)Association Response frame elements not available");
151 return -1;
152 }
153
154 if (ieee802_11_parse_elems(resp_ies, resp_ies_len, &elems, 0) ==
155 ParseFailed) {
156 wpa_printf(MSG_DEBUG,
157 "MLO: Failed to parse (Re)Association Response frame elements");
158 return -1;
159 }
160
161 mlebuf = ieee802_11_defrag_mle(&elems, MULTI_LINK_CONTROL_TYPE_BASIC);
162 if (!mlebuf) {
163 wpa_printf(MSG_ERROR,
164 "MLO: Basic Multi-Link element not found in (Re)Association Response frame");
165 return -1;
166 }
167
168 mle = wpabuf_head(mlebuf);
169 mle_len = wpabuf_len(mlebuf);
170 if (mle_len < MULTI_LINK_CONTROL_LEN + 1 ||
171 mle_len - MULTI_LINK_CONTROL_LEN < mle[MULTI_LINK_CONTROL_LEN]) {
172 wpa_printf(MSG_ERROR,
173 "MLO: Invalid Multi-Link element in (Re)Association Response frame");
174 ret = -1;
175 goto out;
176 }
177
178 /* Skip Common Info */
179 pos = mle + MULTI_LINK_CONTROL_LEN + mle[MULTI_LINK_CONTROL_LEN];
180 rem_len = mle_len -
181 (MULTI_LINK_CONTROL_LEN + mle[MULTI_LINK_CONTROL_LEN]);
182
183 /* Parse Subelements */
184 while (rem_len > 2) {
185 size_t ie_len = 2 + pos[1];
186
187 if (rem_len < ie_len)
188 break;
189
190 if (pos[0] == MULTI_LINK_SUB_ELEM_ID_PER_STA_PROFILE) {
191 u8 link_id;
192 const u8 *sta_profile;
193 size_t sta_profile_len;
194 u16 sta_ctrl;
195
196 if (pos[1] < BASIC_MLE_STA_CTRL_LEN + 1) {
197 wpa_printf(MSG_DEBUG,
198 "MLO: Invalid per-STA profile IE");
199 goto next_subelem;
200 }
201
202 sta_profile_len = pos[1];
203 sta_profile = &pos[2];
204 sta_ctrl = WPA_GET_LE16(sta_profile);
205 link_id = sta_ctrl & BASIC_MLE_STA_CTRL_LINK_ID_MASK;
206 if (link_id >= MAX_NUM_MLD_LINKS) {
207 wpa_printf(MSG_DEBUG,
208 "MLO: Invalid link ID in per-STA profile IE");
209 goto next_subelem;
210 }
211
212 /* Skip STA Control and STA Info */
213 if (sta_profile_len - BASIC_MLE_STA_CTRL_LEN <
214 sta_profile[BASIC_MLE_STA_CTRL_LEN]) {
215 wpa_printf(MSG_DEBUG,
216 "MLO: Invalid STA info in per-STA profile IE");
217 goto next_subelem;
218 }
219
220 sta_profile_len = sta_profile_len -
221 (BASIC_MLE_STA_CTRL_LEN +
222 sta_profile[BASIC_MLE_STA_CTRL_LEN]);
223 sta_profile = sta_profile + BASIC_MLE_STA_CTRL_LEN +
224 sta_profile[BASIC_MLE_STA_CTRL_LEN];
225
226 /* Skip Capabilities Information field */
227 if (sta_profile_len < 2)
228 goto next_subelem;
229 sta_profile_len -= 2;
230 sta_profile += 2;
231
232 /* Get status of the link */
233 info->links[link_id].status = WPA_GET_LE16(sta_profile);
234 }
235next_subelem:
236 pos += ie_len;
237 rem_len -= ie_len;
238 }
239
240out:
241 wpabuf_free(mlebuf);
242 return ret;
243}
244#endif /* CONFIG_IEEE80211BE */
245
246
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700247int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000248 const u8 *req_ies, size_t req_ies_len,
249 const u8 *resp_ies, size_t resp_ies_len,
250 const u8 *link_addr, int reassoc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700251{
252 struct sta_info *sta;
Hai Shalomfdcde762020-04-02 11:19:20 -0700253 int new_assoc;
254 enum wpa_validate_result res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700255 struct ieee802_11_elems elems;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800256 const u8 *ie;
257 size_t ielen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700258 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
259 u8 *p = buf;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800260 u16 reason = WLAN_REASON_UNSPECIFIED;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700261 int status = WLAN_STATUS_SUCCESS;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700262 const u8 *p2p_dev_addr = NULL;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000263#ifdef CONFIG_OWE
264 struct hostapd_iface *iface = hapd->iface;
265#endif /* CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700266
267 if (addr == NULL) {
268 /*
269 * This could potentially happen with unexpected event from the
270 * driver wrapper. This was seen at least in one case where the
271 * driver ended up being set to station mode while hostapd was
272 * running, so better make sure we stop processing such an
273 * event here.
274 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800275 wpa_printf(MSG_DEBUG,
276 "hostapd_notif_assoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700277 return -1;
278 }
Hai Shalomc3565922019-10-28 11:58:20 -0700279
280 if (is_multicast_ether_addr(addr) ||
281 is_zero_ether_addr(addr) ||
282 os_memcmp(addr, hapd->own_addr, ETH_ALEN) == 0) {
283 /* Do not process any frames with unexpected/invalid SA so that
284 * we do not add any state for unexpected STA addresses or end
285 * up sending out frames to unexpected destination. */
286 wpa_printf(MSG_DEBUG, "%s: Invalid SA=" MACSTR
287 " in received indication - ignore this indication silently",
288 __func__, MAC2STR(addr));
289 return 0;
290 }
291
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292 random_add_randomness(addr, ETH_ALEN);
293
294 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
295 HOSTAPD_LEVEL_INFO, "associated");
296
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000297 if (ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0) ==
298 ParseFailed) {
299 wpa_printf(MSG_DEBUG, "%s: Could not parse elements", __func__);
300 return -1;
301 }
302
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700303 if (elems.wps_ie) {
304 ie = elems.wps_ie - 2;
305 ielen = elems.wps_ie_len + 2;
306 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
307 } else if (elems.rsn_ie) {
308 ie = elems.rsn_ie - 2;
309 ielen = elems.rsn_ie_len + 2;
310 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
311 } else if (elems.wpa_ie) {
312 ie = elems.wpa_ie - 2;
313 ielen = elems.wpa_ie_len + 2;
314 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800315#ifdef CONFIG_HS20
316 } else if (elems.osen) {
317 ie = elems.osen - 2;
318 ielen = elems.osen_len + 2;
319 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
320#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700321 } else {
322 ie = NULL;
323 ielen = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800324 wpa_printf(MSG_DEBUG,
325 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700326 }
327
328 sta = ap_get_sta(hapd, addr);
329 if (sta) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700330 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700331 accounting_sta_stop(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700332
333 /*
334 * Make sure that the previously registered inactivity timer
335 * will not remove the STA immediately.
336 */
337 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338 } else {
339 sta = ap_sta_add(hapd, addr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700340 if (sta == NULL) {
341 hostapd_drv_sta_disassoc(hapd, addr,
342 WLAN_REASON_DISASSOC_AP_BUSY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700343 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700344 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700345 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000346
347 if (hapd->conf->wpa && check_sa_query_need(hapd, sta)) {
348 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
349 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
350 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
351
352 return 0;
353 }
354
355#ifdef CONFIG_IEEE80211BE
356 if (link_addr) {
357 struct mld_info *info = &sta->mld_info;
358 int i, num_valid_links = 0;
359 u8 link_id = hapd->mld_link_id;
360
361 info->mld_sta = true;
362 sta->mld_assoc_link_id = link_id;
363 os_memcpy(info->common_info.mld_addr, addr, ETH_ALEN);
364 info->links[link_id].valid = true;
365 os_memcpy(info->links[link_id].peer_addr, link_addr, ETH_ALEN);
366 os_memcpy(info->links[link_id].local_addr, hapd->own_addr,
367 ETH_ALEN);
368
369 if (!elems.basic_mle ||
370 hostapd_process_ml_assoc_req(hapd, &elems, sta) !=
371 WLAN_STATUS_SUCCESS) {
372 reason = WLAN_REASON_UNSPECIFIED;
373 wpa_printf(MSG_DEBUG,
374 "Failed to get STA non-assoc links info");
375 goto fail;
376 }
377
378 for (i = 0 ; i < MAX_NUM_MLD_LINKS; i++) {
379 if (info->links[i].valid)
380 num_valid_links++;
381 }
382 if (num_valid_links > 1 &&
383 hostapd_update_sta_links_status(hapd, sta, resp_ies,
384 resp_ies_len)) {
385 wpa_printf(MSG_DEBUG,
386 "Failed to get STA non-assoc links status info");
387 reason = WLAN_REASON_UNSPECIFIED;
388 goto fail;
389 }
390 }
391#endif /* CONFIG_IEEE80211BE */
392
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800393 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700394
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700395 /*
396 * ACL configurations to the drivers (implementing AP SME and ACL
397 * offload) without hostapd's knowledge, can result in a disconnection
398 * though the driver accepts the connection. Skip the hostapd check for
399 * ACL if the driver supports ACL offload to avoid potentially
400 * conflicting ACL rules.
401 */
402 if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
403 hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800404 wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
405 MAC2STR(addr));
406 reason = WLAN_REASON_UNSPECIFIED;
407 goto fail;
408 }
409
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700410#ifdef CONFIG_P2P
411 if (elems.p2p) {
412 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800413 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700414 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700415 if (sta->p2p_ie)
416 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700417 }
418#endif /* CONFIG_P2P */
419
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700420#ifdef NEED_AP_MLME
421 if (elems.ht_capabilities &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700422 (hapd->iface->conf->ht_capab &
423 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
424 struct ieee80211_ht_capabilities *ht_cap =
425 (struct ieee80211_ht_capabilities *)
426 elems.ht_capabilities;
427
428 if (le_to_host16(ht_cap->ht_capabilities_info) &
429 HT_CAP_INFO_40MHZ_INTOLERANT)
430 ht40_intolerant_add(hapd->iface, sta);
431 }
432#endif /* NEED_AP_MLME */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700433
Sunil Ravia04bd252022-05-02 22:54:18 -0700434 check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700435
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800436#ifdef CONFIG_HS20
437 wpabuf_free(sta->hs20_ie);
438 if (elems.hs20 && elems.hs20_len > 4) {
439 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
440 elems.hs20_len - 4);
441 } else
442 sta->hs20_ie = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700443
444 wpabuf_free(sta->roaming_consortium);
445 if (elems.roaming_cons_sel)
446 sta->roaming_consortium = wpabuf_alloc_copy(
447 elems.roaming_cons_sel + 4,
448 elems.roaming_cons_sel_len - 4);
449 else
450 sta->roaming_consortium = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800451#endif /* CONFIG_HS20 */
452
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800453#ifdef CONFIG_FST
454 wpabuf_free(sta->mb_ies);
455 if (hapd->iface->fst)
456 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
457 else
458 sta->mb_ies = NULL;
459#endif /* CONFIG_FST */
460
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800461 mbo_ap_check_sta_assoc(hapd, sta, &elems);
462
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800463 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
464 elems.supp_op_classes_len);
465
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466 if (hapd->conf->wpa) {
467 if (ie == NULL || ielen == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800468#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700469 if (hapd->conf->wps_state) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800470 wpa_printf(MSG_DEBUG,
471 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700472 sta->flags |= WLAN_STA_MAYBE_WPS;
473 goto skip_wpa_check;
474 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800475#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700476
477 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700478 reason = WLAN_REASON_INVALID_IE;
479 status = WLAN_STATUS_INVALID_IE;
480 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700481 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800482#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700483 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
484 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800485 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800486
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700487 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800488 wps = ieee802_11_vendor_ie_concat(ie, ielen,
489 WPS_IE_VENDOR_TYPE);
490 if (wps) {
491 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800492 wpa_printf(MSG_DEBUG,
493 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800494 sta->flags |= WLAN_STA_WPS2;
495 }
496 wpabuf_free(wps);
497 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700498 goto skip_wpa_check;
499 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800500#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501
502 if (sta->wpa_sm == NULL)
503 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700504 sta->addr,
505 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700506 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800507 wpa_printf(MSG_ERROR,
508 "Failed to initialize WPA state machine");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700509 return -1;
510 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000511#ifdef CONFIG_IEEE80211BE
512 if (sta->mld_info.mld_sta) {
513 wpa_printf(MSG_DEBUG,
514 "MLD: Set ML info in RSN Authenticator");
515 wpa_auth_set_ml_info(sta->wpa_sm, hapd->mld_addr,
516 sta->mld_assoc_link_id,
517 &sta->mld_info);
518 }
519#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Hai Shalom021b0b52019-04-10 11:17:58 -0700521 hapd->iface->freq,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700522 ie, ielen,
Hai Shalomc3565922019-10-28 11:58:20 -0700523 elems.rsnxe ? elems.rsnxe - 2 : NULL,
524 elems.rsnxe ? elems.rsnxe_len + 2 : 0,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700525 elems.mdie, elems.mdie_len,
526 elems.owe_dh, elems.owe_dh_len);
Hai Shalomfdcde762020-04-02 11:19:20 -0700527 reason = WLAN_REASON_INVALID_IE;
528 status = WLAN_STATUS_INVALID_IE;
529 switch (res) {
530 case WPA_IE_OK:
531 reason = WLAN_REASON_UNSPECIFIED;
532 status = WLAN_STATUS_SUCCESS;
533 break;
534 case WPA_INVALID_IE:
535 reason = WLAN_REASON_INVALID_IE;
536 status = WLAN_STATUS_INVALID_IE;
537 break;
538 case WPA_INVALID_GROUP:
539 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
540 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
541 break;
542 case WPA_INVALID_PAIRWISE:
543 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
544 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
545 break;
546 case WPA_INVALID_AKMP:
547 reason = WLAN_REASON_AKMP_NOT_VALID;
548 status = WLAN_STATUS_AKMP_NOT_VALID;
549 break;
550 case WPA_NOT_ENABLED:
551 reason = WLAN_REASON_INVALID_IE;
552 status = WLAN_STATUS_INVALID_IE;
553 break;
554 case WPA_ALLOC_FAIL:
555 reason = WLAN_REASON_UNSPECIFIED;
556 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
557 break;
558 case WPA_MGMT_FRAME_PROTECTION_VIOLATION:
559 reason = WLAN_REASON_INVALID_IE;
560 status = WLAN_STATUS_INVALID_IE;
561 break;
562 case WPA_INVALID_MGMT_GROUP_CIPHER:
563 reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
564 status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
565 break;
566 case WPA_INVALID_MDIE:
567 reason = WLAN_REASON_INVALID_MDE;
568 status = WLAN_STATUS_INVALID_MDIE;
569 break;
570 case WPA_INVALID_PROTO:
571 reason = WLAN_REASON_INVALID_IE;
572 status = WLAN_STATUS_INVALID_IE;
573 break;
574 case WPA_INVALID_PMKID:
575 reason = WLAN_REASON_INVALID_PMKID;
576 status = WLAN_STATUS_INVALID_PMKID;
577 break;
578 case WPA_DENIED_OTHER_REASON:
579 reason = WLAN_REASON_UNSPECIFIED;
580 status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
581 break;
582 }
583 if (status != WLAN_STATUS_SUCCESS) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800584 wpa_printf(MSG_DEBUG,
585 "WPA/RSN information element rejected? (res %u)",
586 res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700587 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800588 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589 }
Hai Shalomc3565922019-10-28 11:58:20 -0700590
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700591 if (wpa_auth_uses_mfp(sta->wpa_sm))
592 sta->flags |= WLAN_STA_MFP;
593 else
594 sta->flags &= ~WLAN_STA_MFP;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700595
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800596#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700597 if (sta->auth_alg == WLAN_AUTH_FT) {
598 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
599 req_ies_len);
600 if (status != WLAN_STATUS_SUCCESS) {
601 if (status == WLAN_STATUS_INVALID_PMKID)
602 reason = WLAN_REASON_INVALID_IE;
603 if (status == WLAN_STATUS_INVALID_MDIE)
604 reason = WLAN_REASON_INVALID_IE;
605 if (status == WLAN_STATUS_INVALID_FTIE)
606 reason = WLAN_REASON_INVALID_IE;
607 goto fail;
608 }
609 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800610#endif /* CONFIG_IEEE80211R_AP */
Hai Shalomc3565922019-10-28 11:58:20 -0700611#ifdef CONFIG_SAE
Sunil Ravi77d572f2023-01-17 23:58:31 +0000612 if (hapd->conf->sae_pwe == SAE_PWE_BOTH &&
Hai Shalomc3565922019-10-28 11:58:20 -0700613 sta->auth_alg == WLAN_AUTH_SAE &&
Hai Shalom899fcc72020-10-19 14:38:18 -0700614 sta->sae && !sta->sae->h2e &&
Hai Shaloma20dcd72022-02-04 13:43:00 -0800615 ieee802_11_rsnx_capab_len(elems.rsnxe, elems.rsnxe_len,
616 WLAN_RSNX_CAPAB_SAE_H2E)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700617 wpa_printf(MSG_INFO, "SAE: " MACSTR
618 " indicates support for SAE H2E, but did not use it",
619 MAC2STR(sta->addr));
620 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
621 reason = WLAN_REASON_UNSPECIFIED;
622 goto fail;
623 }
624#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700625 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800626#ifdef CONFIG_WPS
627 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800628
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800629 if (req_ies)
630 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700631 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800632 else
633 wps = NULL;
634#ifdef CONFIG_WPS_STRICT
635 if (wps && wps_validate_assoc_req(wps) < 0) {
636 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700637 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700638 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800639 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700640 }
641#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800642 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700643 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800644 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800645 wpa_printf(MSG_DEBUG,
646 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800647 sta->flags |= WLAN_STA_WPS2;
648 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700649 } else
650 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800651 wpabuf_free(wps);
652#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800653#ifdef CONFIG_HS20
654 } else if (hapd->conf->osen) {
655 if (elems.osen == NULL) {
656 hostapd_logger(
657 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
658 HOSTAPD_LEVEL_INFO,
659 "No HS 2.0 OSEN element in association request");
660 return WLAN_STATUS_INVALID_IE;
661 }
662
663 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
664 if (sta->wpa_sm == NULL)
665 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
666 sta->addr, NULL);
667 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800668 wpa_printf(MSG_WARNING,
669 "Failed to initialize WPA state machine");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800670 return WLAN_STATUS_UNSPECIFIED_FAILURE;
671 }
672 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
673 elems.osen - 2, elems.osen_len + 2) < 0)
674 return WLAN_STATUS_INVALID_IE;
675#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700676 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700677#ifdef CONFIG_WPS
678skip_wpa_check:
679#endif /* CONFIG_WPS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800680
681#ifdef CONFIG_MBO
682 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
683 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
684 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
685 wpa_printf(MSG_INFO,
686 "MBO: Reject WPA2 association without PMF");
687 return WLAN_STATUS_UNSPECIFIED_FAILURE;
688 }
689#endif /* CONFIG_MBO */
690
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800691#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700692 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
Hai Shalomfdcde762020-04-02 11:19:20 -0700693 sta->auth_alg, req_ies, req_ies_len,
694 !elems.rsnxe);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700695 if (!p) {
696 wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs");
697 return WLAN_STATUS_UNSPECIFIED_FAILURE;
698 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700699#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700700
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700701#ifdef CONFIG_FILS
702 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
703 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
704 sta->auth_alg == WLAN_AUTH_FILS_PK) {
705 int delay_assoc = 0;
706
707 if (!req_ies)
708 return WLAN_STATUS_UNSPECIFIED_FAILURE;
709
710 if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies,
711 req_ies_len,
712 sta->fils_session)) {
713 wpa_printf(MSG_DEBUG,
714 "FILS: Session validation failed");
715 return WLAN_STATUS_UNSPECIFIED_FAILURE;
716 }
717
718 res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies,
719 req_ies_len);
720 if (res < 0) {
721 wpa_printf(MSG_DEBUG,
722 "FILS: Key Confirm validation failed");
723 return WLAN_STATUS_UNSPECIFIED_FAILURE;
724 }
725
726 if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) {
727 wpa_printf(MSG_DEBUG,
728 "FILS: Delaying Assoc Response (HLP)");
729 delay_assoc = 1;
730 } else {
731 wpa_printf(MSG_DEBUG,
732 "FILS: Going ahead with Assoc Response (no HLP)");
733 }
734
735 if (sta) {
736 wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup");
737 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
738 os_free(sta->fils_pending_assoc_req);
739 sta->fils_pending_assoc_req = NULL;
740 sta->fils_pending_assoc_req_len = 0;
741 wpabuf_free(sta->fils_hlp_resp);
742 sta->fils_hlp_resp = NULL;
743 sta->fils_drv_assoc_finish = 0;
744 }
745
746 if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) {
747 u8 *req_tmp;
748
749 req_tmp = os_malloc(req_ies_len);
750 if (!req_tmp) {
751 wpa_printf(MSG_DEBUG,
752 "FILS: buffer allocation failed for assoc req");
753 goto fail;
754 }
755 os_memcpy(req_tmp, req_ies, req_ies_len);
756 sta->fils_pending_assoc_req = req_tmp;
757 sta->fils_pending_assoc_req_len = req_ies_len;
758 sta->fils_pending_assoc_is_reassoc = reassoc;
759 sta->fils_drv_assoc_finish = 1;
760 wpa_printf(MSG_DEBUG,
761 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
762 MACSTR, MAC2STR(sta->addr));
763 eloop_register_timeout(
764 0, hapd->conf->fils_hlp_wait_time * 1024,
765 fils_hlp_timeout, hapd, sta);
766 return 0;
767 }
768 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
769 elems.fils_session,
770 sta->fils_hlp_resp);
771 wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)",
772 buf, p - buf);
773 }
774#endif /* CONFIG_FILS */
775
Roshan Pius3a1667e2018-07-03 15:17:14 -0700776#ifdef CONFIG_OWE
777 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000778 !(iface->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_AP) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -0700779 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
780 elems.owe_dh) {
781 u8 *npos;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700782 u16 ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700783
784 npos = owe_assoc_req_process(hapd, sta,
785 elems.owe_dh, elems.owe_dh_len,
786 p, sizeof(buf) - (p - buf),
Hai Shalomb755a2a2020-04-23 21:49:02 -0700787 &ret_status);
788 status = ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700789 if (npos)
790 p = npos;
Hai Shalomfdcde762020-04-02 11:19:20 -0700791
Roshan Pius3a1667e2018-07-03 15:17:14 -0700792 if (!npos &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700793 status == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
Hai Shalomb755a2a2020-04-23 21:49:02 -0700794 hostapd_sta_assoc(hapd, addr, reassoc, ret_status, buf,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700795 p - buf);
796 return 0;
797 }
798
Hai Shalomfdcde762020-04-02 11:19:20 -0700799 if (!npos || status != WLAN_STATUS_SUCCESS)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700800 goto fail;
801 }
802#endif /* CONFIG_OWE */
803
Hai Shalom021b0b52019-04-10 11:17:58 -0700804#ifdef CONFIG_DPP2
805 dpp_pfs_free(sta->dpp_pfs);
806 sta->dpp_pfs = NULL;
807
808 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
809 hapd->conf->dpp_netaccesskey && sta->wpa_sm &&
810 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP &&
811 elems.owe_dh) {
812 sta->dpp_pfs = dpp_pfs_init(
813 wpabuf_head(hapd->conf->dpp_netaccesskey),
814 wpabuf_len(hapd->conf->dpp_netaccesskey));
815 if (!sta->dpp_pfs) {
816 wpa_printf(MSG_DEBUG,
817 "DPP: Could not initialize PFS");
818 /* Try to continue without PFS */
819 goto pfs_fail;
820 }
821
822 if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh,
823 elems.owe_dh_len) < 0) {
824 dpp_pfs_free(sta->dpp_pfs);
825 sta->dpp_pfs = NULL;
826 reason = WLAN_REASON_UNSPECIFIED;
827 goto fail;
828 }
829 }
830
831 wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ?
832 sta->dpp_pfs->secret : NULL);
833 pfs_fail:
834#endif /* CONFIG_DPP2 */
835
Hai Shalomfdcde762020-04-02 11:19:20 -0700836 if (elems.rrm_enabled &&
837 elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
838 os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
839 sizeof(sta->rrm_enabled_capa));
840
Roshan Pius3a1667e2018-07-03 15:17:14 -0700841#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700842 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700843
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700844 if (sta->auth_alg == WLAN_AUTH_FT ||
845 sta->auth_alg == WLAN_AUTH_FILS_SK ||
846 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
847 sta->auth_alg == WLAN_AUTH_FILS_PK)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700848 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700849#else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700850 /* Keep compiler silent about unused variables */
851 if (status) {
852 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700853#endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700854
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700855 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
856 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800857 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700858
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700859 hostapd_set_sta_flags(hapd, sta);
860
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700861 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
862 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700863#ifdef CONFIG_FILS
864 else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
865 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
866 sta->auth_alg == WLAN_AUTH_FILS_PK)
867 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
868#endif /* CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700869 else
870 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700871
872 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
873
874 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
875
876#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800877 if (req_ies) {
878 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
879 req_ies, req_ies_len);
880 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700881#endif /* CONFIG_P2P */
882
883 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800884
885fail:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800886#ifdef CONFIG_IEEE80211R_AP
Hai Shalomb755a2a2020-04-23 21:49:02 -0700887 if (status >= 0)
888 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800889#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800890 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
891 ap_free_sta(hapd, sta);
892 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700893}
894
895
896void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
897{
898 struct sta_info *sta;
899
900 if (addr == NULL) {
901 /*
902 * This could potentially happen with unexpected event from the
903 * driver wrapper. This was seen at least in one case where the
904 * driver ended up reporting a station mode event while hostapd
905 * was running, so better make sure we stop processing such an
906 * event here.
907 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800908 wpa_printf(MSG_DEBUG,
909 "hostapd_notif_disassoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700910 return;
911 }
912
913 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
914 HOSTAPD_LEVEL_INFO, "disassociated");
915
916 sta = ap_get_sta(hapd, addr);
917 if (sta == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800918 wpa_printf(MSG_DEBUG,
919 "Disassociation notification for unknown STA "
920 MACSTR, MAC2STR(addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700921 return;
922 }
923
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800924 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700925 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Hai Shalomfdcde762020-04-02 11:19:20 -0700926 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700927 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
928 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
929 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
930 ap_free_sta(hapd, sta);
931}
932
933
934void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
935{
936 struct sta_info *sta = ap_get_sta(hapd, addr);
937
Roshan Pius3a1667e2018-07-03 15:17:14 -0700938 if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700939 return;
940
941 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800942 HOSTAPD_LEVEL_INFO,
943 "disconnected due to excessive missing ACKs");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700944 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800945 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700946}
947
948
Roshan Pius3a1667e2018-07-03 15:17:14 -0700949void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr,
950 enum smps_mode smps_mode,
951 enum chan_width chan_width, u8 rx_nss)
952{
953 struct sta_info *sta = ap_get_sta(hapd, addr);
954 const char *txt;
955
956 if (!sta)
957 return;
958
959 switch (smps_mode) {
960 case SMPS_AUTOMATIC:
961 txt = "automatic";
962 break;
963 case SMPS_OFF:
964 txt = "off";
965 break;
966 case SMPS_DYNAMIC:
967 txt = "dynamic";
968 break;
969 case SMPS_STATIC:
970 txt = "static";
971 break;
972 default:
973 txt = NULL;
974 break;
975 }
976 if (txt) {
977 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED
978 MACSTR " %s", MAC2STR(addr), txt);
979 }
980
981 switch (chan_width) {
982 case CHAN_WIDTH_20_NOHT:
983 txt = "20(no-HT)";
984 break;
985 case CHAN_WIDTH_20:
986 txt = "20";
987 break;
988 case CHAN_WIDTH_40:
989 txt = "40";
990 break;
991 case CHAN_WIDTH_80:
992 txt = "80";
993 break;
994 case CHAN_WIDTH_80P80:
995 txt = "80+80";
996 break;
997 case CHAN_WIDTH_160:
998 txt = "160";
999 break;
Sunil8cd6f4d2022-06-28 18:40:46 +00001000 case CHAN_WIDTH_320:
1001 txt = "320";
1002 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001003 default:
1004 txt = NULL;
1005 break;
1006 }
1007 if (txt) {
1008 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED
1009 MACSTR " %s", MAC2STR(addr), txt);
1010 }
1011
1012 if (rx_nss != 0xff) {
1013 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED
1014 MACSTR " %d", MAC2STR(addr), rx_nss);
1015 }
1016}
1017
1018
Dmitry Shmidt04949592012-07-19 12:16:46 -07001019void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001020 int offset, int width, int cf1, int cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07001021 u16 punct_bitmap, int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001022{
1023#ifdef NEED_AP_MLME
Sunil Ravi77d572f2023-01-17 23:58:31 +00001024 int channel, chwidth, is_dfs0, is_dfs;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001025 u8 seg0_idx = 0, seg1_idx = 0, op_class, chan_no;
Hai Shalom74f70d42019-02-11 14:42:39 -08001026 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001027
1028 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001029 HOSTAPD_LEVEL_INFO,
Sunil Ravi036cec52023-03-29 11:35:17 -07001030 "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 -07001031 finished ? "had" : "starting",
Sunil Ravi77d572f2023-01-17 23:58:31 +00001032 hapd->iface->freq,
Hai Shalom60840252021-02-19 19:02:11 -08001033 freq, ht, hapd->iconf->ch_switch_vht_config,
Sunil Ravia04bd252022-05-02 22:54:18 -07001034 hapd->iconf->ch_switch_he_config,
1035 hapd->iconf->ch_switch_eht_config, offset,
Sunil Ravi036cec52023-03-29 11:35:17 -07001036 width, channel_width_to_string(width), cf1, cf2,
1037 punct_bitmap);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001038
Hai Shalom1dc4d202019-04-29 16:22:27 -07001039 if (!hapd->iface->current_mode) {
1040 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1041 HOSTAPD_LEVEL_WARNING,
1042 "ignore channel switch since the interface is not yet ready");
1043 return;
1044 }
1045
Sunil Ravi77d572f2023-01-17 23:58:31 +00001046 /* Check if any of configured channels require DFS */
1047 is_dfs0 = hostapd_is_dfs_required(hapd->iface);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001048 hapd->iface->freq = freq;
1049
1050 channel = hostapd_hw_get_channel(hapd, freq);
1051 if (!channel) {
1052 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001053 HOSTAPD_LEVEL_WARNING,
1054 "driver switched to bad channel!");
Dmitry Shmidt04949592012-07-19 12:16:46 -07001055 return;
1056 }
1057
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001058 switch (width) {
1059 case CHAN_WIDTH_80:
Sunil8cd6f4d2022-06-28 18:40:46 +00001060 chwidth = CONF_OPER_CHWIDTH_80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001061 break;
1062 case CHAN_WIDTH_80P80:
Sunil8cd6f4d2022-06-28 18:40:46 +00001063 chwidth = CONF_OPER_CHWIDTH_80P80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001064 break;
1065 case CHAN_WIDTH_160:
Sunil8cd6f4d2022-06-28 18:40:46 +00001066 chwidth = CONF_OPER_CHWIDTH_160MHZ;
1067 break;
1068 case CHAN_WIDTH_320:
1069 chwidth = CONF_OPER_CHWIDTH_320MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001070 break;
1071 case CHAN_WIDTH_20_NOHT:
1072 case CHAN_WIDTH_20:
1073 case CHAN_WIDTH_40:
1074 default:
Sunil8cd6f4d2022-06-28 18:40:46 +00001075 chwidth = CONF_OPER_CHWIDTH_USE_HT;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001076 break;
1077 }
1078
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001079 /* The operating channel changed when CSA finished, so need to update
1080 * hw_mode for all following operations to cover the cases where the
1081 * driver changed the operating band. */
1082 if (finished && hostapd_csa_update_hwmode(hapd->iface))
1083 return;
1084
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001085 switch (hapd->iface->current_mode->mode) {
1086 case HOSTAPD_MODE_IEEE80211A:
Hai Shalom899fcc72020-10-19 14:38:18 -07001087 if (cf1 == 5935)
1088 seg0_idx = (cf1 - 5925) / 5;
1089 else if (cf1 > 5950)
1090 seg0_idx = (cf1 - 5950) / 5;
1091 else if (cf1 > 5000)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001092 seg0_idx = (cf1 - 5000) / 5;
Hai Shalom899fcc72020-10-19 14:38:18 -07001093
1094 if (cf2 == 5935)
1095 seg1_idx = (cf2 - 5925) / 5;
1096 else if (cf2 > 5950)
1097 seg1_idx = (cf2 - 5950) / 5;
1098 else if (cf2 > 5000)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001099 seg1_idx = (cf2 - 5000) / 5;
1100 break;
1101 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001102 ieee80211_freq_to_chan(cf1, &seg0_idx);
1103 ieee80211_freq_to_chan(cf2, &seg1_idx);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001104 break;
1105 }
1106
Dmitry Shmidt04949592012-07-19 12:16:46 -07001107 hapd->iconf->channel = channel;
1108 hapd->iconf->ieee80211n = ht;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001109 if (!ht)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001110 hapd->iconf->ieee80211ac = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001111 if (hapd->iconf->ch_switch_vht_config) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001112 /* CHAN_SWITCH VHT config */
1113 if (hapd->iconf->ch_switch_vht_config &
1114 CH_SWITCH_VHT_ENABLED)
1115 hapd->iconf->ieee80211ac = 1;
1116 else if (hapd->iconf->ch_switch_vht_config &
1117 CH_SWITCH_VHT_DISABLED)
1118 hapd->iconf->ieee80211ac = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001119 }
1120 if (hapd->iconf->ch_switch_he_config) {
Hai Shalom60840252021-02-19 19:02:11 -08001121 /* CHAN_SWITCH HE config */
1122 if (hapd->iconf->ch_switch_he_config &
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001123 CH_SWITCH_HE_ENABLED) {
Hai Shalom60840252021-02-19 19:02:11 -08001124 hapd->iconf->ieee80211ax = 1;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001125 if (hapd->iface->freq > 4000 &&
1126 hapd->iface->freq < 5895)
1127 hapd->iconf->ieee80211ac = 1;
1128 }
Hai Shalom60840252021-02-19 19:02:11 -08001129 else if (hapd->iconf->ch_switch_he_config &
1130 CH_SWITCH_HE_DISABLED)
1131 hapd->iconf->ieee80211ax = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001132 }
Sunil Ravia04bd252022-05-02 22:54:18 -07001133#ifdef CONFIG_IEEE80211BE
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001134 if (hapd->iconf->ch_switch_eht_config) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001135 /* CHAN_SWITCH EHT config */
1136 if (hapd->iconf->ch_switch_eht_config &
1137 CH_SWITCH_EHT_ENABLED) {
1138 hapd->iconf->ieee80211be = 1;
1139 hapd->iconf->ieee80211ax = 1;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001140 if (!is_6ghz_freq(hapd->iface->freq) &&
1141 hapd->iface->freq > 4000)
Sunil Ravia04bd252022-05-02 22:54:18 -07001142 hapd->iconf->ieee80211ac = 1;
1143 } else if (hapd->iconf->ch_switch_eht_config &
1144 CH_SWITCH_EHT_DISABLED)
1145 hapd->iconf->ieee80211be = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001146 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001147#endif /* CONFIG_IEEE80211BE */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001148 hapd->iconf->ch_switch_vht_config = 0;
Hai Shalom60840252021-02-19 19:02:11 -08001149 hapd->iconf->ch_switch_he_config = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -07001150 hapd->iconf->ch_switch_eht_config = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001151
Hai Shaloma20dcd72022-02-04 13:43:00 -08001152 if (width == CHAN_WIDTH_40 || width == CHAN_WIDTH_80 ||
Sunil Ravi640215c2023-06-28 23:08:09 +00001153 width == CHAN_WIDTH_80P80 || width == CHAN_WIDTH_160 ||
1154 width == CHAN_WIDTH_320)
Hai Shaloma20dcd72022-02-04 13:43:00 -08001155 hapd->iconf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1156 else if (width == CHAN_WIDTH_20 || width == CHAN_WIDTH_20_NOHT)
1157 hapd->iconf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
1158
Dmitry Shmidt04949592012-07-19 12:16:46 -07001159 hapd->iconf->secondary_channel = offset;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001160 if (ieee80211_freq_to_channel_ext(freq, offset, chwidth,
1161 &op_class, &chan_no) !=
1162 NUM_HOSTAPD_MODES)
1163 hapd->iconf->op_class = op_class;
Hai Shalom81f62d82019-07-22 12:10:00 -07001164 hostapd_set_oper_chwidth(hapd->iconf, chwidth);
1165 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, seg0_idx);
1166 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, seg1_idx);
Sunil Ravi036cec52023-03-29 11:35:17 -07001167#ifdef CONFIG_IEEE80211BE
1168 hapd->iconf->punct_bitmap = punct_bitmap;
1169#endif /* CONFIG_IEEE80211BE */
Hai Shaloma20dcd72022-02-04 13:43:00 -08001170 if (hapd->iconf->ieee80211ac) {
1171 hapd->iconf->vht_capab &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
Sunil8cd6f4d2022-06-28 18:40:46 +00001172 if (chwidth == CONF_OPER_CHWIDTH_160MHZ)
Hai Shaloma20dcd72022-02-04 13:43:00 -08001173 hapd->iconf->vht_capab |=
1174 VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Sunil8cd6f4d2022-06-28 18:40:46 +00001175 else if (chwidth == CONF_OPER_CHWIDTH_80P80MHZ)
Hai Shaloma20dcd72022-02-04 13:43:00 -08001176 hapd->iconf->vht_capab |=
1177 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
1178 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001179
Roshan Pius3a1667e2018-07-03 15:17:14 -07001180 is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features,
1181 hapd->iface->num_hw_features);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001182
Hai Shalom81f62d82019-07-22 12:10:00 -07001183 wpa_msg(hapd->msg_ctx, MSG_INFO,
Sunil Ravi036cec52023-03-29 11:35:17 -07001184 "%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 -07001185 finished ? WPA_EVENT_CHANNEL_SWITCH :
1186 WPA_EVENT_CHANNEL_SWITCH_STARTED,
1187 freq, ht, offset, channel_width_to_string(width),
Sunil Ravi036cec52023-03-29 11:35:17 -07001188 cf1, cf2, is_dfs0, is_dfs, punct_bitmap);
Hai Shalom81f62d82019-07-22 12:10:00 -07001189 if (!finished)
1190 return;
1191
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001192 if (hapd->csa_in_progress &&
1193 freq == hapd->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001194 hostapd_cleanup_cs_params(hapd);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001195 ieee802_11_set_beacon(hapd);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001196
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001197 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
1198 "freq=%d dfs=%d", freq, is_dfs);
1199 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00001200 /* Complete AP configuration for the first bring up. */
1201 if (is_dfs0 > 0 &&
1202 hostapd_is_dfs_required(hapd->iface) <= 0 &&
1203 hapd->iface->state != HAPD_IFACE_ENABLED) {
1204 /* Fake a CAC start bit to skip setting channel */
1205 hapd->iface->cac_started = 1;
1206 hostapd_setup_interface_complete(hapd->iface, 0);
1207 }
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001208 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
1209 "freq=%d dfs=%d", freq, is_dfs);
Hai Shalomfdcde762020-04-02 11:19:20 -07001210 } else if (is_dfs &&
1211 hostapd_is_dfs_required(hapd->iface) &&
1212 !hostapd_is_dfs_chan_available(hapd->iface) &&
1213 !hapd->iface->cac_started) {
1214 hostapd_disable_iface(hapd->iface);
1215 hostapd_enable_iface(hapd->iface);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001216 }
Hai Shalom74f70d42019-02-11 14:42:39 -08001217
1218 for (i = 0; i < hapd->iface->num_bss; i++)
1219 hostapd_neighbor_set_own_report(hapd->iface->bss[i]);
Hai Shalom899fcc72020-10-19 14:38:18 -07001220
1221#ifdef CONFIG_OCV
Sunil Ravia04bd252022-05-02 22:54:18 -07001222 if (hapd->conf->ocv &&
1223 !(hapd->iface->drv_flags2 &
1224 WPA_DRIVER_FLAGS2_SA_QUERY_OFFLOAD_AP)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001225 struct sta_info *sta;
1226 bool check_sa_query = false;
1227
1228 for (sta = hapd->sta_list; sta; sta = sta->next) {
1229 if (wpa_auth_uses_ocv(sta->wpa_sm) &&
1230 !(sta->flags & WLAN_STA_WNM_SLEEP_MODE)) {
1231 sta->post_csa_sa_query = 1;
1232 check_sa_query = true;
1233 }
1234 }
1235
1236 if (check_sa_query) {
1237 wpa_printf(MSG_DEBUG,
1238 "OCV: Check post-CSA SA Query initiation in 15 seconds");
1239 eloop_register_timeout(15, 0,
1240 hostapd_ocv_check_csa_sa_query,
1241 hapd, NULL);
1242 }
1243 }
1244#endif /* CONFIG_OCV */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001245#endif /* NEED_AP_MLME */
1246}
1247
1248
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001249void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
1250 const u8 *addr, int reason_code)
1251{
1252 switch (reason_code) {
1253 case MAX_CLIENT_REACHED:
1254 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
1255 MAC2STR(addr));
1256 break;
1257 case BLOCKED_CLIENT:
1258 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
1259 MAC2STR(addr));
1260 break;
1261 }
1262}
1263
1264
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001265#ifdef CONFIG_ACS
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001266void hostapd_acs_channel_selected(struct hostapd_data *hapd,
1267 struct acs_selected_channels *acs_res)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001268{
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001269 int ret, i;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001270 int err = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001271 struct hostapd_channel_data *pri_chan;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001272
1273 if (hapd->iconf->channel) {
1274 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
1275 hapd->iconf->channel);
1276 return;
1277 }
1278
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001279 hapd->iface->freq = acs_res->pri_freq;
1280
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001281 if (!hapd->iface->current_mode) {
1282 for (i = 0; i < hapd->iface->num_hw_features; i++) {
1283 struct hostapd_hw_modes *mode =
1284 &hapd->iface->hw_features[i];
1285
1286 if (mode->mode == acs_res->hw_mode) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001287 if (hapd->iface->freq > 0 &&
1288 !hw_get_chan(mode->mode,
1289 hapd->iface->freq,
1290 hapd->iface->hw_features,
1291 hapd->iface->num_hw_features))
1292 continue;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001293 hapd->iface->current_mode = mode;
1294 break;
1295 }
1296 }
1297 if (!hapd->iface->current_mode) {
1298 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1299 HOSTAPD_LEVEL_WARNING,
1300 "driver selected to bad hw_mode");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001301 err = 1;
1302 goto out;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001303 }
1304 }
1305
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001306 if (!acs_res->pri_freq) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001307 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1308 HOSTAPD_LEVEL_WARNING,
1309 "driver switched to bad channel");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001310 err = 1;
1311 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001312 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001313 pri_chan = hw_get_channel_freq(hapd->iface->current_mode->mode,
1314 acs_res->pri_freq, NULL,
1315 hapd->iface->hw_features,
1316 hapd->iface->num_hw_features);
1317 if (!pri_chan) {
1318 wpa_printf(MSG_ERROR,
1319 "ACS: Could not determine primary channel number from pri_freq %u",
1320 acs_res->pri_freq);
1321 err = 1;
1322 goto out;
1323 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001324
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001325 hapd->iconf->channel = pri_chan->chan;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001326 hapd->iconf->acs = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001327
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001328 if (acs_res->sec_freq == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001329 hapd->iconf->secondary_channel = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001330 else if (acs_res->sec_freq < acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001331 hapd->iconf->secondary_channel = -1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001332 else if (acs_res->sec_freq > acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001333 hapd->iconf->secondary_channel = 1;
1334 else {
1335 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001336 err = 1;
1337 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001338 }
1339
Hai Shalomfdcde762020-04-02 11:19:20 -07001340 hapd->iconf->edmg_channel = acs_res->edmg_channel;
1341
Hai Shalom81f62d82019-07-22 12:10:00 -07001342 if (hapd->iface->conf->ieee80211ac || hapd->iface->conf->ieee80211ax) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001343 /* set defaults for backwards compatibility */
Hai Shalom81f62d82019-07-22 12:10:00 -07001344 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1345 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, 0);
Sunil8cd6f4d2022-06-28 18:40:46 +00001346 hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_USE_HT);
Hai Shalomfdcde762020-04-02 11:19:20 -07001347 if (acs_res->ch_width == 40) {
1348 if (is_6ghz_freq(acs_res->pri_freq))
1349 hostapd_set_oper_centr_freq_seg0_idx(
1350 hapd->iconf,
1351 acs_res->vht_seg0_center_ch);
1352 } else if (acs_res->ch_width == 80) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001353 hostapd_set_oper_centr_freq_seg0_idx(
1354 hapd->iconf, acs_res->vht_seg0_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001355 if (acs_res->vht_seg1_center_ch == 0) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001356 hostapd_set_oper_chwidth(
1357 hapd->iconf, CONF_OPER_CHWIDTH_80MHZ);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001358 } else {
Sunil8cd6f4d2022-06-28 18:40:46 +00001359 hostapd_set_oper_chwidth(
1360 hapd->iconf,
1361 CONF_OPER_CHWIDTH_80P80MHZ);
Hai Shalom81f62d82019-07-22 12:10:00 -07001362 hostapd_set_oper_centr_freq_seg1_idx(
1363 hapd->iconf,
1364 acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001365 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001366 } else if (acs_res->ch_width == 160) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001367 hostapd_set_oper_chwidth(hapd->iconf,
1368 CONF_OPER_CHWIDTH_160MHZ);
Hai Shalomfdcde762020-04-02 11:19:20 -07001369 hostapd_set_oper_centr_freq_seg0_idx(
1370 hapd->iconf, acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001371 }
1372 }
1373
Sunil8cd6f4d2022-06-28 18:40:46 +00001374#ifdef CONFIG_IEEE80211BE
1375 if (hapd->iface->conf->ieee80211be && acs_res->ch_width == 320) {
1376 hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_320MHZ);
1377 hostapd_set_oper_centr_freq_seg0_idx(
1378 hapd->iconf, acs_res->vht_seg1_center_ch);
1379 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1380 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001381
1382 if (hapd->iface->conf->ieee80211be && acs_res->puncture_bitmap)
1383 hapd->iconf->punct_bitmap = acs_res->puncture_bitmap;
Sunil8cd6f4d2022-06-28 18:40:46 +00001384#endif /* CONFIG_IEEE80211BE */
1385
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001386out:
1387 ret = hostapd_acs_completed(hapd->iface, err);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001388 if (ret) {
1389 wpa_printf(MSG_ERROR,
1390 "ACS: Possibly channel configuration is invalid");
1391 }
1392}
1393#endif /* CONFIG_ACS */
1394
1395
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001396int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001397 const u8 *bssid, const u8 *ie, size_t ie_len,
1398 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001399{
1400 size_t i;
1401 int ret = 0;
1402
1403 if (sa == NULL || ie == NULL)
1404 return -1;
1405
1406 random_add_randomness(sa, ETH_ALEN);
1407 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
1408 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001409 sa, da, bssid, ie, ie_len,
1410 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001411 ret = 1;
1412 break;
1413 }
1414 }
1415 return ret;
1416}
1417
1418
1419#ifdef HOSTAPD
1420
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001421#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001422static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
1423 const u8 *bssid,
1424 u16 auth_transaction, u16 status,
1425 const u8 *ies, size_t ies_len)
1426{
1427 struct hostapd_data *hapd = ctx;
1428 struct sta_info *sta;
1429
1430 sta = ap_get_sta(hapd, dst);
1431 if (sta == NULL)
1432 return;
1433
1434 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
1435 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
1436 sta->flags |= WLAN_STA_AUTH;
1437
1438 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
1439}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001440#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001441
1442
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001443#ifdef CONFIG_FILS
1444static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
1445 struct sta_info *sta, u16 resp,
1446 struct wpabuf *data, int pub)
1447{
1448 if (resp == WLAN_STATUS_SUCCESS) {
1449 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1450 HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
1451 sta->flags |= WLAN_STA_AUTH;
1452 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1453 sta->auth_alg = WLAN_AUTH_FILS_SK;
1454 mlme_authenticate_indication(hapd, sta);
1455 } else {
1456 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1457 HOSTAPD_LEVEL_DEBUG,
1458 "authentication failed (FILS)");
1459 }
1460
1461 hostapd_sta_auth(hapd, sta->addr, 2, resp,
1462 data ? wpabuf_head(data) : NULL,
1463 data ? wpabuf_len(data) : 0);
1464 wpabuf_free(data);
1465}
1466#endif /* CONFIG_FILS */
1467
1468
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001469static void hostapd_notif_auth(struct hostapd_data *hapd,
1470 struct auth_info *rx_auth)
1471{
1472 struct sta_info *sta;
1473 u16 status = WLAN_STATUS_SUCCESS;
1474 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1475 size_t resp_ies_len = 0;
1476
1477 sta = ap_get_sta(hapd, rx_auth->peer);
1478 if (!sta) {
1479 sta = ap_sta_add(hapd, rx_auth->peer);
1480 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -07001481 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001482 goto fail;
1483 }
1484 }
1485 sta->flags &= ~WLAN_STA_PREAUTH;
1486 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001487#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001488 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
1489 sta->auth_alg = WLAN_AUTH_FT;
1490 if (sta->wpa_sm == NULL)
1491 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001492 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001493 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001494 wpa_printf(MSG_DEBUG,
1495 "FT: Failed to initialize WPA state machine");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001496 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1497 goto fail;
1498 }
1499 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
1500 rx_auth->auth_transaction, rx_auth->ies,
1501 rx_auth->ies_len,
1502 hostapd_notify_auth_ft_finish, hapd);
1503 return;
1504 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001505#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001506
1507#ifdef CONFIG_FILS
1508 if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
1509 sta->auth_alg = WLAN_AUTH_FILS_SK;
1510 handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
1511 rx_auth->auth_type, rx_auth->auth_transaction,
1512 rx_auth->status_code,
1513 hostapd_notify_auth_fils_finish);
1514 return;
1515 }
1516#endif /* CONFIG_FILS */
1517
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001518fail:
1519 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
1520 status, resp_ies, resp_ies_len);
1521}
1522
1523
Hai Shalom021b0b52019-04-10 11:17:58 -07001524#ifndef NEED_AP_MLME
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001525static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001526 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001527{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001528 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001529 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001530 size_t plen __maybe_unused;
1531 u16 fc;
Hai Shalom74f70d42019-02-11 14:42:39 -08001532 u8 *action __maybe_unused;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001533
Hai Shalom74f70d42019-02-11 14:42:39 -08001534 if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001535 return;
1536
Hai Shalom021b0b52019-04-10 11:17:58 -07001537 plen = drv_mgmt->frame_len - IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001538
1539 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
1540 fc = le_to_host16(mgmt->frame_control);
1541 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
1542 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001543
Hai Shalom74f70d42019-02-11 14:42:39 -08001544 action = (u8 *) &mgmt->u.action.u;
1545 wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
1546 " da " MACSTR " plen %d",
1547 mgmt->u.action.category, *action,
1548 MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001549
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001550 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001551 if (sta == NULL) {
1552 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
1553 return;
1554 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001555#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001556 if (mgmt->u.action.category == WLAN_ACTION_FT) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001557 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, plen);
1558 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001559 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001560#endif /* CONFIG_IEEE80211R_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001561 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001562 ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001563 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001564 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001565#ifdef CONFIG_WNM_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001566 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
1567 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001568 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001569 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001570#endif /* CONFIG_WNM_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001571#ifdef CONFIG_FST
1572 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
1573 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
1574 return;
1575 }
1576#endif /* CONFIG_FST */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001577#ifdef CONFIG_DPP
Hai Shalom021b0b52019-04-10 11:17:58 -07001578 if (plen >= 2 + 4 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001579 mgmt->u.action.u.vs_public_action.action ==
1580 WLAN_PA_VENDOR_SPECIFIC &&
1581 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1582 OUI_WFA &&
1583 mgmt->u.action.u.vs_public_action.variable[0] ==
1584 DPP_OUI_TYPE) {
1585 const u8 *pos, *end;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001586
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001587 pos = mgmt->u.action.u.vs_public_action.oui;
1588 end = drv_mgmt->frame + drv_mgmt->frame_len;
1589 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
1590 drv_mgmt->freq);
1591 return;
1592 }
1593#endif /* CONFIG_DPP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001594}
Hai Shalom021b0b52019-04-10 11:17:58 -07001595#endif /* NEED_AP_MLME */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001596
1597
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001598#ifdef NEED_AP_MLME
1599
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001600static struct hostapd_data *
1601switch_link_hapd(struct hostapd_data *hapd, int link_id)
1602{
1603#ifdef CONFIG_IEEE80211BE
1604 if (hapd->conf->mld_ap && link_id >= 0) {
1605 struct hostapd_data *link_bss;
1606
1607 link_bss = hostapd_mld_get_link_bss(hapd, link_id);
1608 if (link_bss)
1609 return link_bss;
1610 }
1611#endif /* CONFIG_IEEE80211BE */
1612
1613 return hapd;
1614}
1615
1616
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001617#define HAPD_BROADCAST ((struct hostapd_data *) -1)
1618
1619static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
1620 const u8 *bssid)
1621{
1622 size_t i;
1623
1624 if (bssid == NULL)
1625 return NULL;
1626 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1627 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1628 return HAPD_BROADCAST;
1629
1630 for (i = 0; i < iface->num_bss; i++) {
1631 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
1632 return iface->bss[i];
1633 }
1634
1635 return NULL;
1636}
1637
1638
1639static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001640 const u8 *bssid, const u8 *addr,
1641 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001642{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001643 hapd = get_hapd_bssid(hapd->iface, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001644 if (hapd == NULL || hapd == HAPD_BROADCAST)
1645 return;
1646
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001647 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001648}
1649
1650
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001651static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001652{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001653 struct hostapd_iface *iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001654 const struct ieee80211_hdr *hdr;
1655 const u8 *bssid;
1656 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001657 int ret;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001658 bool is_mld = false;
1659
1660 hapd = switch_link_hapd(hapd, rx_mgmt->link_id);
1661 iface = hapd->iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001662
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001663#ifdef CONFIG_TESTING_OPTIONS
1664 if (hapd->ext_mgmt_frame_handling) {
1665 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
1666 char *hex = os_malloc(hex_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001667
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001668 if (hex) {
1669 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
1670 rx_mgmt->frame_len);
1671 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1672 os_free(hex);
1673 }
1674 return 1;
1675 }
1676#endif /* CONFIG_TESTING_OPTIONS */
1677
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001678 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1679 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
1680 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001681 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001682
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001683#ifdef CONFIG_IEEE80211BE
1684 if (hapd->conf->mld_ap &&
1685 os_memcmp(hapd->mld_addr, bssid, ETH_ALEN) == 0)
1686 is_mld = true;
1687#endif /* CONFIG_IEEE80211BE */
1688
1689 if (!is_mld)
1690 hapd = get_hapd_bssid(iface, bssid);
1691
1692 if (!hapd) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001693 u16 fc = le_to_host16(hdr->frame_control);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001694
1695 /*
1696 * Drop frames to unknown BSSIDs except for Beacon frames which
1697 * could be used to update neighbor information.
1698 */
1699 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1700 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1701 hapd = iface->bss[0];
1702 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001703 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001704 }
1705
1706 os_memset(&fi, 0, sizeof(fi));
Roshan Pius3a1667e2018-07-03 15:17:14 -07001707 fi.freq = rx_mgmt->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001708 fi.datarate = rx_mgmt->datarate;
1709 fi.ssi_signal = rx_mgmt->ssi_signal;
1710
1711 if (hapd == HAPD_BROADCAST) {
1712 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001713
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001714 ret = 0;
1715 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -07001716 /* if bss is set, driver will call this function for
1717 * each bss individually. */
1718 if (rx_mgmt->drv_priv &&
1719 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
1720 continue;
1721
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001722 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
1723 rx_mgmt->frame_len, &fi) > 0)
1724 ret = 1;
1725 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001726 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001727 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
1728 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001729
1730 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001731
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001732 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001733}
1734
1735
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001736static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001737 size_t len, u16 stype, int ok, int link_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001738{
1739 struct ieee80211_hdr *hdr;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001740 struct hostapd_data *orig_hapd, *tmp_hapd;
1741
1742#ifdef CONFIG_IEEE80211BE
1743 if (hapd->conf->mld_ap && link_id != -1) {
1744 tmp_hapd = hostapd_mld_get_link_bss(hapd, link_id);
1745 if (tmp_hapd)
1746 hapd = tmp_hapd;
1747 }
1748#endif /* CONFIG_IEEE80211BE */
1749 orig_hapd = hapd;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001750
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001751 hdr = (struct ieee80211_hdr *) buf;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001752 tmp_hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
1753 if (tmp_hapd) {
1754 hapd = tmp_hapd;
1755#ifdef CONFIG_IEEE80211BE
1756 } else if (hapd->conf->mld_ap &&
1757 os_memcmp(hapd->mld_addr, get_hdr_bssid(hdr, len),
1758 ETH_ALEN) == 0) {
1759 /* AP MLD address match - use hapd pointer as-is */
1760#endif /* CONFIG_IEEE80211BE */
1761 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001762 return;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001763 }
1764
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001765 if (hapd == HAPD_BROADCAST) {
1766 if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
1767 buf[24] != WLAN_ACTION_PUBLIC)
1768 return;
1769 hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2);
1770 if (!hapd || hapd == HAPD_BROADCAST)
1771 return;
1772 /*
1773 * Allow processing of TX status for a Public Action frame that
1774 * used wildcard BBSID.
1775 */
1776 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001777 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1778}
1779
1780#endif /* NEED_AP_MLME */
1781
1782
1783static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
1784{
1785 struct sta_info *sta = ap_get_sta(hapd, addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001786
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001787 if (sta)
1788 return 0;
1789
1790 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
1791 " - adding a new STA", MAC2STR(addr));
1792 sta = ap_sta_add(hapd, addr);
1793 if (sta) {
1794 hostapd_new_assoc_sta(hapd, sta, 0);
1795 } else {
1796 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
1797 MAC2STR(addr));
1798 return -1;
1799 }
1800
1801 return 0;
1802}
1803
1804
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001805static struct hostapd_data * hostapd_find_by_sta(struct hostapd_iface *iface,
1806 const u8 *src)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001807{
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001808 struct sta_info *sta;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001809 unsigned int j;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001810
1811 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001812 sta = ap_get_sta(iface->bss[j], src);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001813 if (sta && sta->flags & WLAN_STA_ASSOC)
1814 return iface->bss[j];
1815 }
1816
1817 return NULL;
1818}
1819
1820
1821static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
1822 const u8 *data, size_t data_len,
1823 enum frame_encryption encrypted,
1824 int link_id)
1825{
1826 struct hostapd_data *orig_hapd = hapd;
1827
1828#ifdef CONFIG_IEEE80211BE
1829 if (link_id != -1) {
1830 struct hostapd_data *h_hapd;
1831
1832 hapd = switch_link_hapd(hapd, link_id);
1833 h_hapd = hostapd_find_by_sta(hapd->iface, src);
1834 if (!h_hapd)
1835 h_hapd = hostapd_find_by_sta(orig_hapd->iface, src);
1836 if (h_hapd)
1837 hapd = h_hapd;
1838 } else if (hapd->conf->mld_ap) {
1839 unsigned int i;
1840
1841 /* Search for STA on other MLO BSSs */
1842 for (i = 0; i < hapd->iface->interfaces->count; i++) {
1843 struct hostapd_iface *h =
1844 hapd->iface->interfaces->iface[i];
1845 struct hostapd_data *h_hapd = h->bss[0];
1846 struct hostapd_bss_config *hconf = h_hapd->conf;
1847
1848 if (!hconf->mld_ap ||
1849 hconf->mld_id != hapd->conf->mld_id)
1850 continue;
1851
1852 h_hapd = hostapd_find_by_sta(h, src);
1853 if (h_hapd) {
1854 hapd = h_hapd;
1855 break;
1856 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001857 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001858 } else {
1859 hapd = hostapd_find_by_sta(hapd->iface, src);
1860 }
1861#else /* CONFIG_IEEE80211BE */
1862 hapd = hostapd_find_by_sta(hapd->iface, src);
1863#endif /* CONFIG_IEEE80211BE */
1864
1865 if (!hapd) {
1866 /* WLAN cases need to have an existing association, but non-WLAN
1867 * cases (mainly, wired IEEE 802.1X) need to be able to process
1868 * EAPOL frames from new devices that do not yet have a STA
1869 * entry and as such, do not get a match in
1870 * hostapd_find_by_sta(). */
1871 wpa_printf(MSG_DEBUG,
1872 "No STA-specific hostapd instance for EAPOL RX found - fall back to initial context");
1873 hapd = orig_hapd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001874 }
1875
Sunil8cd6f4d2022-06-28 18:40:46 +00001876 ieee802_1x_receive(hapd, src, data, data_len, encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001877}
1878
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001879#endif /* HOSTAPD */
1880
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001881
Hai Shalomfdcde762020-04-02 11:19:20 -07001882static struct hostapd_channel_data *
1883hostapd_get_mode_chan(struct hostapd_hw_modes *mode, unsigned int freq)
1884{
1885 int i;
1886 struct hostapd_channel_data *chan;
1887
1888 for (i = 0; i < mode->num_channels; i++) {
1889 chan = &mode->channels[i];
1890 if ((unsigned int) chan->freq == freq)
1891 return chan;
1892 }
1893
1894 return NULL;
1895}
1896
1897
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001898static struct hostapd_channel_data * hostapd_get_mode_channel(
1899 struct hostapd_iface *iface, unsigned int freq)
1900{
1901 int i;
1902 struct hostapd_channel_data *chan;
1903
Hai Shalomfdcde762020-04-02 11:19:20 -07001904 for (i = 0; i < iface->num_hw_features; i++) {
1905 if (hostapd_hw_skip_mode(iface, &iface->hw_features[i]))
1906 continue;
1907 chan = hostapd_get_mode_chan(&iface->hw_features[i], freq);
1908 if (chan)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001909 return chan;
1910 }
1911
1912 return NULL;
1913}
1914
1915
1916static void hostapd_update_nf(struct hostapd_iface *iface,
1917 struct hostapd_channel_data *chan,
1918 struct freq_survey *survey)
1919{
1920 if (!iface->chans_surveyed) {
1921 chan->min_nf = survey->nf;
1922 iface->lowest_nf = survey->nf;
1923 } else {
1924 if (dl_list_empty(&chan->survey_list))
1925 chan->min_nf = survey->nf;
1926 else if (survey->nf < chan->min_nf)
1927 chan->min_nf = survey->nf;
1928 if (survey->nf < iface->lowest_nf)
1929 iface->lowest_nf = survey->nf;
1930 }
1931}
1932
1933
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001934static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
1935 struct survey_results *survey_res)
1936{
1937 struct hostapd_channel_data *chan;
1938 struct freq_survey *survey;
1939 u64 divisor, dividend;
1940
1941 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
1942 list);
1943 if (!survey || !survey->freq)
1944 return;
1945
1946 chan = hostapd_get_mode_channel(iface, survey->freq);
1947 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
1948 return;
1949
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001950 wpa_printf(MSG_DEBUG,
1951 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001952 survey->freq,
1953 (unsigned long int) survey->channel_time,
1954 (unsigned long int) survey->channel_time_busy);
1955
1956 if (survey->channel_time > iface->last_channel_time &&
1957 survey->channel_time > survey->channel_time_busy) {
1958 dividend = survey->channel_time_busy -
1959 iface->last_channel_time_busy;
1960 divisor = survey->channel_time - iface->last_channel_time;
1961
1962 iface->channel_utilization = dividend * 255 / divisor;
1963 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
1964 iface->channel_utilization);
1965 }
1966 iface->last_channel_time = survey->channel_time;
1967 iface->last_channel_time_busy = survey->channel_time_busy;
1968}
1969
1970
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001971void hostapd_event_get_survey(struct hostapd_iface *iface,
1972 struct survey_results *survey_results)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001973{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001974 struct freq_survey *survey, *tmp;
1975 struct hostapd_channel_data *chan;
1976
1977 if (dl_list_empty(&survey_results->survey_list)) {
1978 wpa_printf(MSG_DEBUG, "No survey data received");
1979 return;
1980 }
1981
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001982 if (survey_results->freq_filter) {
1983 hostapd_single_channel_get_survey(iface, survey_results);
1984 return;
1985 }
1986
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001987 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
1988 struct freq_survey, list) {
1989 chan = hostapd_get_mode_channel(iface, survey->freq);
1990 if (!chan)
1991 continue;
1992 if (chan->flag & HOSTAPD_CHAN_DISABLED)
1993 continue;
1994
1995 dl_list_del(&survey->list);
1996 dl_list_add_tail(&chan->survey_list, &survey->list);
1997
1998 hostapd_update_nf(iface, chan, survey);
1999
2000 iface->chans_surveyed++;
2001 }
2002}
2003
2004
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002005#ifdef HOSTAPD
Dmitry Shmidt051af732013-10-22 13:52:46 -07002006#ifdef NEED_AP_MLME
2007
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002008static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
2009{
2010 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
2011 hapd->conf->iface);
2012
2013 if (hapd->csa_in_progress) {
2014 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
2015 hapd->conf->iface);
2016 hostapd_switch_channel_fallback(hapd->iface,
2017 &hapd->cs_freq_params);
2018 }
Yu Ouyang378d3c42021-08-20 17:31:08 +08002019
2020 // inform framework that interface is unavailable
2021 hostapd_disable_iface(hapd->iface);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002022}
2023
2024
Dmitry Shmidt051af732013-10-22 13:52:46 -07002025static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
2026 struct dfs_event *radar)
2027{
2028 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002029 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002030 radar->chan_offset, radar->chan_width,
2031 radar->cf1, radar->cf2);
2032}
2033
2034
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002035static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
2036 struct dfs_event *radar)
2037{
2038 wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
2039 hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
2040 radar->chan_offset, radar->chan_width,
2041 radar->cf1, radar->cf2);
2042}
2043
2044
Dmitry Shmidt051af732013-10-22 13:52:46 -07002045static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
2046 struct dfs_event *radar)
2047{
2048 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002049 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002050 radar->chan_offset, radar->chan_width,
2051 radar->cf1, radar->cf2);
2052}
2053
2054
2055static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
2056 struct dfs_event *radar)
2057{
2058 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002059 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002060 radar->chan_offset, radar->chan_width,
2061 radar->cf1, radar->cf2);
2062}
2063
2064
2065static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
2066 struct dfs_event *radar)
2067{
2068 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002069 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07002070 radar->chan_offset, radar->chan_width,
2071 radar->cf1, radar->cf2);
2072}
2073
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002074
2075static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
2076 struct dfs_event *radar)
2077{
2078 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
2079 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
2080 radar->chan_offset, radar->chan_width,
2081 radar->cf1, radar->cf2);
2082}
2083
Dmitry Shmidt051af732013-10-22 13:52:46 -07002084#endif /* NEED_AP_MLME */
2085
2086
Roshan Pius3a1667e2018-07-03 15:17:14 -07002087static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd,
2088 int istatus,
2089 const char *ifname,
2090 const u8 *addr)
2091{
2092 struct sta_info *sta = ap_get_sta(hapd, addr);
2093
2094 if (sta) {
2095 os_free(sta->ifname_wds);
2096 if (istatus == INTERFACE_ADDED)
2097 sta->ifname_wds = os_strdup(ifname);
2098 else
2099 sta->ifname_wds = NULL;
2100 }
2101
2102 wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR,
2103 istatus == INTERFACE_ADDED ?
2104 WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED,
2105 ifname, MAC2STR(addr));
2106}
2107
2108
Hai Shalom81f62d82019-07-22 12:10:00 -07002109#ifdef CONFIG_OWE
2110static int hostapd_notif_update_dh_ie(struct hostapd_data *hapd,
2111 const u8 *peer, const u8 *ie,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002112 size_t ie_len, const u8 *link_addr)
Hai Shalom81f62d82019-07-22 12:10:00 -07002113{
2114 u16 status;
2115 struct sta_info *sta;
2116 struct ieee802_11_elems elems;
2117
2118 if (!hapd || !hapd->wpa_auth) {
2119 wpa_printf(MSG_DEBUG, "OWE: Invalid hapd context");
2120 return -1;
2121 }
2122 if (!peer) {
2123 wpa_printf(MSG_DEBUG, "OWE: Peer unknown");
2124 return -1;
2125 }
2126 if (!(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) {
2127 wpa_printf(MSG_DEBUG, "OWE: No OWE AKM configured");
2128 status = WLAN_STATUS_AKMP_NOT_VALID;
2129 goto err;
2130 }
2131 if (ieee802_11_parse_elems(ie, ie_len, &elems, 1) == ParseFailed) {
2132 wpa_printf(MSG_DEBUG, "OWE: Failed to parse OWE IE for "
2133 MACSTR, MAC2STR(peer));
2134 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
2135 goto err;
2136 }
2137 status = owe_validate_request(hapd, peer, elems.rsn_ie,
2138 elems.rsn_ie_len,
2139 elems.owe_dh, elems.owe_dh_len);
2140 if (status != WLAN_STATUS_SUCCESS)
2141 goto err;
2142
2143 sta = ap_get_sta(hapd, peer);
2144 if (sta) {
2145 ap_sta_no_session_timeout(hapd, sta);
2146 accounting_sta_stop(hapd, sta);
2147
2148 /*
2149 * Make sure that the previously registered inactivity timer
2150 * will not remove the STA immediately.
2151 */
2152 sta->timeout_next = STA_NULLFUNC;
2153 } else {
2154 sta = ap_sta_add(hapd, peer);
2155 if (!sta) {
2156 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
2157 goto err;
2158 }
2159 }
2160 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
2161
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002162#ifdef CONFIG_IEEE80211BE
2163 if (link_addr) {
2164 struct mld_info *info = &sta->mld_info;
2165 u8 link_id = hapd->mld_link_id;
2166
2167 info->mld_sta = true;
2168 sta->mld_assoc_link_id = link_id;;
2169 os_memcpy(info->common_info.mld_addr, peer, ETH_ALEN);
2170 info->links[link_id].valid = true;
2171 os_memcpy(info->links[link_id].local_addr, hapd->own_addr,
2172 ETH_ALEN);
2173 os_memcpy(info->links[link_id].peer_addr, link_addr, ETH_ALEN);
2174 }
2175#endif /* CONFIG_IEEE80211BE */
2176
Hai Shalom81f62d82019-07-22 12:10:00 -07002177 status = owe_process_rsn_ie(hapd, sta, elems.rsn_ie,
2178 elems.rsn_ie_len, elems.owe_dh,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002179 elems.owe_dh_len, link_addr);
Hai Shalom81f62d82019-07-22 12:10:00 -07002180 if (status != WLAN_STATUS_SUCCESS)
2181 ap_free_sta(hapd, sta);
2182
2183 return 0;
2184err:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002185 hostapd_drv_update_dh_ie(hapd, link_addr ? link_addr : peer, status,
2186 NULL, 0);
Hai Shalom81f62d82019-07-22 12:10:00 -07002187 return 0;
2188}
2189#endif /* CONFIG_OWE */
2190
2191
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002192void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
2193 union wpa_event_data *data)
2194{
2195 struct hostapd_data *hapd = ctx;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002196 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002197#ifndef CONFIG_NO_STDOUT_DEBUG
2198 int level = MSG_DEBUG;
2199
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002200 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002201 data->rx_mgmt.frame_len >= 24) {
2202 const struct ieee80211_hdr *hdr;
2203 u16 fc;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002204
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002205 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
2206 fc = le_to_host16(hdr->frame_control);
2207 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2208 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2209 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002210 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2211 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
2212 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002213 }
2214
2215 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
2216 event_to_string(event), event);
2217#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002218
2219 switch (event) {
2220 case EVENT_MICHAEL_MIC_FAILURE:
2221 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
2222 break;
2223 case EVENT_SCAN_RESULTS:
2224 if (hapd->iface->scan_cb)
2225 hapd->iface->scan_cb(hapd->iface);
2226 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002227 case EVENT_WPS_BUTTON_PUSHED:
2228 hostapd_wps_button_pushed(hapd, NULL);
2229 break;
2230#ifdef NEED_AP_MLME
2231 case EVENT_TX_STATUS:
2232 switch (data->tx_status.type) {
2233 case WLAN_FC_TYPE_MGMT:
2234 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
2235 data->tx_status.data_len,
2236 data->tx_status.stype,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002237 data->tx_status.ack,
2238 data->tx_status.link_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002239 break;
2240 case WLAN_FC_TYPE_DATA:
2241 hostapd_tx_status(hapd, data->tx_status.dst,
2242 data->tx_status.data,
2243 data->tx_status.data_len,
2244 data->tx_status.ack);
2245 break;
2246 }
2247 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002248 case EVENT_EAPOL_TX_STATUS:
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002249 hapd = switch_link_hapd(hapd, data->eapol_tx_status.link_id);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002250 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
2251 data->eapol_tx_status.data,
2252 data->eapol_tx_status.data_len,
2253 data->eapol_tx_status.ack);
2254 break;
2255 case EVENT_DRIVER_CLIENT_POLL_OK:
2256 hostapd_client_poll_ok(hapd, data->client_poll.addr);
2257 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002258 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002259 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
2260 data->rx_from_unknown.addr,
2261 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002262 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002263#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002264 case EVENT_RX_MGMT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002265 if (!data->rx_mgmt.frame)
2266 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002267#ifdef NEED_AP_MLME
Hai Shalom021b0b52019-04-10 11:17:58 -07002268 hostapd_mgmt_rx(hapd, &data->rx_mgmt);
2269#else /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002270 hostapd_action_rx(hapd, &data->rx_mgmt);
Hai Shalom021b0b52019-04-10 11:17:58 -07002271#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002272 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002273 case EVENT_RX_PROBE_REQ:
2274 if (data->rx_probe_req.sa == NULL ||
2275 data->rx_probe_req.ie == NULL)
2276 break;
2277 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002278 data->rx_probe_req.da,
2279 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002280 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07002281 data->rx_probe_req.ie_len,
2282 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002283 break;
2284 case EVENT_NEW_STA:
2285 hostapd_event_new_sta(hapd, data->new_sta.addr);
2286 break;
2287 case EVENT_EAPOL_RX:
2288 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
2289 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00002290 data->eapol_rx.data_len,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002291 data->eapol_rx.encrypted,
2292 data->eapol_rx.link_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002293 break;
2294 case EVENT_ASSOC:
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002295 if (!data)
2296 return;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002297#ifdef CONFIG_IEEE80211BE
2298 if (data->assoc_info.assoc_link_id != -1) {
2299 hapd = hostapd_mld_get_link_bss(
2300 hapd, data->assoc_info.assoc_link_id);
2301 if (!hapd) {
2302 wpa_printf(MSG_ERROR,
2303 "MLD: Failed to get link BSS for EVENT_ASSOC");
2304 return;
2305 }
2306 }
2307#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002308 hostapd_notif_assoc(hapd, data->assoc_info.addr,
2309 data->assoc_info.req_ies,
2310 data->assoc_info.req_ies_len,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002311 data->assoc_info.resp_ies,
2312 data->assoc_info.resp_ies_len,
2313 data->assoc_info.link_addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002314 data->assoc_info.reassoc);
2315 break;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002316 case EVENT_PORT_AUTHORIZED:
2317 /* Port authorized event for an associated STA */
2318 sta = ap_get_sta(hapd, data->port_authorized.sta_addr);
2319 if (sta)
2320 ap_sta_set_authorized(hapd, sta, 1);
2321 else
2322 wpa_printf(MSG_DEBUG,
2323 "No STA info matching port authorized event found");
2324 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07002325#ifdef CONFIG_OWE
2326 case EVENT_UPDATE_DH:
2327 if (!data)
2328 return;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002329#ifdef CONFIG_IEEE80211BE
2330 if (data->update_dh.assoc_link_id != -1) {
2331 hapd = hostapd_mld_get_link_bss(
2332 hapd, data->update_dh.assoc_link_id);
2333 if (!hapd) {
2334 wpa_printf(MSG_ERROR,
2335 "MLD: Failed to get link BSS for EVENT_UPDATE_DH assoc_link_id=%d",
2336 data->update_dh.assoc_link_id);
2337 return;
2338 }
2339 }
2340#endif /* CONFIG_IEEE80211BE */
Hai Shalom81f62d82019-07-22 12:10:00 -07002341 hostapd_notif_update_dh_ie(hapd, data->update_dh.peer,
2342 data->update_dh.ie,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002343 data->update_dh.ie_len,
2344 data->update_dh.link_addr);
Hai Shalom81f62d82019-07-22 12:10:00 -07002345 break;
2346#endif /* CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002347 case EVENT_DISASSOC:
2348 if (data)
2349 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
2350 break;
2351 case EVENT_DEAUTH:
2352 if (data)
2353 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
2354 break;
2355 case EVENT_STATION_LOW_ACK:
2356 if (!data)
2357 break;
2358 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
2359 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002360 case EVENT_AUTH:
2361 hostapd_notif_auth(hapd, &data->auth);
2362 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07002363 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07002364 case EVENT_CH_SWITCH:
2365 if (!data)
2366 break;
2367 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
2368 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08002369 data->ch_switch.ch_offset,
2370 data->ch_switch.ch_width,
2371 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07002372 data->ch_switch.cf2,
Sunil Ravi036cec52023-03-29 11:35:17 -07002373 data->ch_switch.punct_bitmap,
Hai Shalom81f62d82019-07-22 12:10:00 -07002374 event == EVENT_CH_SWITCH);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002375 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002376 case EVENT_CONNECT_FAILED_REASON:
2377 if (!data)
2378 break;
2379 hostapd_event_connect_failed_reason(
2380 hapd, data->connect_failed_reason.addr,
2381 data->connect_failed_reason.code);
2382 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002383 case EVENT_SURVEY:
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002384 hostapd_event_get_survey(hapd->iface, &data->survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002385 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002386#ifdef NEED_AP_MLME
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002387 case EVENT_INTERFACE_UNAVAILABLE:
2388 hostapd_event_iface_unavailable(hapd);
2389 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002390 case EVENT_DFS_RADAR_DETECTED:
2391 if (!data)
2392 break;
2393 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
2394 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002395 case EVENT_DFS_PRE_CAC_EXPIRED:
2396 if (!data)
2397 break;
2398 hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
2399 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002400 case EVENT_DFS_CAC_FINISHED:
2401 if (!data)
2402 break;
2403 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
2404 break;
2405 case EVENT_DFS_CAC_ABORTED:
2406 if (!data)
2407 break;
2408 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
2409 break;
2410 case EVENT_DFS_NOP_FINISHED:
2411 if (!data)
2412 break;
2413 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
2414 break;
2415 case EVENT_CHANNEL_LIST_CHANGED:
2416 /* channel list changed (regulatory?), update channel list */
2417 /* TODO: check this. hostapd_get_hw_features() initializes
2418 * too much stuff. */
2419 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002420 hostapd_channel_list_updated(
2421 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002422 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002423 case EVENT_DFS_CAC_STARTED:
2424 if (!data)
2425 break;
2426 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
2427 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002428#endif /* NEED_AP_MLME */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002429 case EVENT_INTERFACE_ENABLED:
2430 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002431 if (hapd->disabled && hapd->started) {
2432 hapd->disabled = 0;
2433 /*
2434 * Try to re-enable interface if the driver stopped it
2435 * when the interface got disabled.
2436 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07002437 if (hapd->wpa_auth)
2438 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
2439 else
2440 hostapd_reconfig_encryption(hapd);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002441 hapd->reenable_beacon = 1;
2442 ieee802_11_set_beacon(hapd);
Hai Shalom74f70d42019-02-11 14:42:39 -08002443#ifdef NEED_AP_MLME
2444 } else if (hapd->disabled && hapd->iface->cac_started) {
2445 wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC");
2446 hostapd_handle_dfs(hapd->iface);
2447#endif /* NEED_AP_MLME */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002448 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002449 break;
2450 case EVENT_INTERFACE_DISABLED:
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002451 hostapd_free_stas(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002452 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002453 hapd->disabled = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002454 break;
2455#ifdef CONFIG_ACS
2456 case EVENT_ACS_CHANNEL_SELECTED:
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002457 hostapd_acs_channel_selected(hapd,
2458 &data->acs_selected_channels);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002459 break;
2460#endif /* CONFIG_ACS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002461 case EVENT_STATION_OPMODE_CHANGED:
2462 hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr,
2463 data->sta_opmode.smps_mode,
2464 data->sta_opmode.chan_width,
2465 data->sta_opmode.rx_nss);
2466 break;
2467 case EVENT_WDS_STA_INTERFACE_STATUS:
2468 hostapd_event_wds_sta_interface_status(
2469 hapd, data->wds_sta_interface.istatus,
2470 data->wds_sta_interface.ifname,
2471 data->wds_sta_interface.sta_addr);
2472 break;
Sunil Ravia04bd252022-05-02 22:54:18 -07002473#ifdef CONFIG_IEEE80211AX
2474 case EVENT_BSS_COLOR_COLLISION:
2475 /* The BSS color is shared amongst all BBSs on a specific phy.
2476 * Therefore we always start the color change on the primary
2477 * BSS. */
2478 wpa_printf(MSG_DEBUG, "BSS color collision on %s",
2479 hapd->conf->iface);
2480 hostapd_switch_color(hapd->iface->bss[0],
2481 data->bss_color_collision.bitmap);
2482 break;
2483 case EVENT_CCA_STARTED_NOTIFY:
2484 wpa_printf(MSG_DEBUG, "CCA started on on %s",
2485 hapd->conf->iface);
2486 break;
2487 case EVENT_CCA_ABORTED_NOTIFY:
2488 wpa_printf(MSG_DEBUG, "CCA aborted on on %s",
2489 hapd->conf->iface);
2490 hostapd_cleanup_cca_params(hapd);
2491 break;
2492 case EVENT_CCA_NOTIFY:
2493 wpa_printf(MSG_DEBUG, "CCA finished on on %s",
2494 hapd->conf->iface);
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002495 if (hapd->cca_color)
2496 hapd->iface->conf->he_op.he_bss_color = hapd->cca_color;
Sunil Ravia04bd252022-05-02 22:54:18 -07002497 hostapd_cleanup_cca_params(hapd);
2498 break;
2499#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002500 default:
2501 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
2502 break;
2503 }
2504}
2505
Dmitry Shmidte4663042016-04-04 10:07:49 -07002506
2507void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
2508 union wpa_event_data *data)
2509{
2510 struct hapd_interfaces *interfaces = ctx;
2511 struct hostapd_data *hapd;
2512
2513 if (event != EVENT_INTERFACE_STATUS)
2514 return;
2515
2516 hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
2517 if (hapd && hapd->driver && hapd->driver->get_ifindex &&
2518 hapd->drv_priv) {
2519 unsigned int ifindex;
2520
2521 ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
2522 if (ifindex != data->interface_status.ifindex) {
2523 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
2524 "interface status ifindex %d mismatch (%d)",
2525 ifindex, data->interface_status.ifindex);
2526 return;
2527 }
2528 }
2529 if (hapd)
2530 wpa_supplicant_event(hapd, event, data);
2531}
2532
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002533#endif /* HOSTAPD */