blob: b1cb31e651808da1b790476d5faeb72192c10df8 [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
62 ieee802_11_parse_elems(sta->fils_pending_assoc_req,
63 sta->fils_pending_assoc_req_len, &elems, 0);
64 if (!elems.fils_session) {
65 wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element",
66 __func__);
67 return;
68 }
69
70 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
71 elems.fils_session,
72 sta->fils_hlp_resp);
73
74 reply_res = hostapd_sta_assoc(hapd, sta->addr,
75 sta->fils_pending_assoc_is_reassoc,
76 WLAN_STATUS_SUCCESS,
77 buf, p - buf);
78 ap_sta_set_authorized(hapd, sta, 1);
79 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
80 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
81 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
82 hostapd_set_sta_flags(hapd, sta);
83 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
84 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
85 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
86 os_free(sta->fils_pending_assoc_req);
87 sta->fils_pending_assoc_req = NULL;
88 sta->fils_pending_assoc_req_len = 0;
89 wpabuf_free(sta->fils_hlp_resp);
90 sta->fils_hlp_resp = NULL;
91 wpabuf_free(sta->hlp_dhcp_discover);
92 sta->hlp_dhcp_discover = NULL;
93 fils_hlp_deinit(hapd);
94
95 /*
96 * Remove the station in case transmission of a success response fails
97 * (the STA was added associated to the driver) or if the station was
98 * previously added unassociated.
99 */
100 if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) {
101 hostapd_drv_sta_remove(hapd, sta->addr);
102 sta->added_unassoc = 0;
103 }
104}
105#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700106
107
Hai Shalom899fcc72020-10-19 14:38:18 -0700108static bool check_sa_query_need(struct hostapd_data *hapd, struct sta_info *sta)
109{
110 if ((sta->flags &
111 (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED)) !=
112 (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED))
113 return false;
114
115 if (!sta->sa_query_timed_out && sta->sa_query_count > 0)
116 ap_check_sa_query_timeout(hapd, sta);
117
118 if (!sta->sa_query_timed_out && (sta->auth_alg != WLAN_AUTH_FT)) {
119 /*
120 * STA has already been associated with MFP and SA Query timeout
121 * has not been reached. Reject the association attempt
122 * temporarily and start SA Query, if one is not pending.
123 */
124 if (sta->sa_query_count == 0)
125 ap_sta_start_sa_query(hapd, sta);
126
127 return true;
128 }
129
130 return false;
131}
132
133
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700134int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800135 const u8 *req_ies, size_t req_ies_len, int reassoc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700136{
137 struct sta_info *sta;
Hai Shalomfdcde762020-04-02 11:19:20 -0700138 int new_assoc;
139 enum wpa_validate_result res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700140 struct ieee802_11_elems elems;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800141 const u8 *ie;
142 size_t ielen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700143 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
144 u8 *p = buf;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800145 u16 reason = WLAN_REASON_UNSPECIFIED;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700146 int status = WLAN_STATUS_SUCCESS;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700147 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700148
149 if (addr == NULL) {
150 /*
151 * This could potentially happen with unexpected event from the
152 * driver wrapper. This was seen at least in one case where the
153 * driver ended up being set to station mode while hostapd was
154 * running, so better make sure we stop processing such an
155 * event here.
156 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800157 wpa_printf(MSG_DEBUG,
158 "hostapd_notif_assoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159 return -1;
160 }
Hai Shalomc3565922019-10-28 11:58:20 -0700161
162 if (is_multicast_ether_addr(addr) ||
163 is_zero_ether_addr(addr) ||
164 os_memcmp(addr, hapd->own_addr, ETH_ALEN) == 0) {
165 /* Do not process any frames with unexpected/invalid SA so that
166 * we do not add any state for unexpected STA addresses or end
167 * up sending out frames to unexpected destination. */
168 wpa_printf(MSG_DEBUG, "%s: Invalid SA=" MACSTR
169 " in received indication - ignore this indication silently",
170 __func__, MAC2STR(addr));
171 return 0;
172 }
173
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700174 random_add_randomness(addr, ETH_ALEN);
175
176 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
177 HOSTAPD_LEVEL_INFO, "associated");
178
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800179 ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180 if (elems.wps_ie) {
181 ie = elems.wps_ie - 2;
182 ielen = elems.wps_ie_len + 2;
183 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
184 } else if (elems.rsn_ie) {
185 ie = elems.rsn_ie - 2;
186 ielen = elems.rsn_ie_len + 2;
187 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
188 } else if (elems.wpa_ie) {
189 ie = elems.wpa_ie - 2;
190 ielen = elems.wpa_ie_len + 2;
191 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800192#ifdef CONFIG_HS20
193 } else if (elems.osen) {
194 ie = elems.osen - 2;
195 ielen = elems.osen_len + 2;
196 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
197#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198 } else {
199 ie = NULL;
200 ielen = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800201 wpa_printf(MSG_DEBUG,
202 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203 }
204
205 sta = ap_get_sta(hapd, addr);
206 if (sta) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700207 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700208 accounting_sta_stop(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700209
210 /*
211 * Make sure that the previously registered inactivity timer
212 * will not remove the STA immediately.
213 */
214 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700215 } else {
216 sta = ap_sta_add(hapd, addr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700217 if (sta == NULL) {
218 hostapd_drv_sta_disassoc(hapd, addr,
219 WLAN_REASON_DISASSOC_AP_BUSY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700221 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800223 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700224
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700225 /*
226 * ACL configurations to the drivers (implementing AP SME and ACL
227 * offload) without hostapd's knowledge, can result in a disconnection
228 * though the driver accepts the connection. Skip the hostapd check for
229 * ACL if the driver supports ACL offload to avoid potentially
230 * conflicting ACL rules.
231 */
232 if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
233 hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800234 wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
235 MAC2STR(addr));
236 reason = WLAN_REASON_UNSPECIFIED;
237 goto fail;
238 }
239
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700240#ifdef CONFIG_P2P
241 if (elems.p2p) {
242 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800243 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700244 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700245 if (sta->p2p_ie)
246 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700247 }
248#endif /* CONFIG_P2P */
249
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700250#ifdef NEED_AP_MLME
251 if (elems.ht_capabilities &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700252 (hapd->iface->conf->ht_capab &
253 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
254 struct ieee80211_ht_capabilities *ht_cap =
255 (struct ieee80211_ht_capabilities *)
256 elems.ht_capabilities;
257
258 if (le_to_host16(ht_cap->ht_capabilities_info) &
259 HT_CAP_INFO_40MHZ_INTOLERANT)
260 ht40_intolerant_add(hapd->iface, sta);
261 }
262#endif /* NEED_AP_MLME */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700263
Sunil Ravia04bd252022-05-02 22:54:18 -0700264 check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
Dmitry Shmidt051af732013-10-22 13:52:46 -0700265
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800266#ifdef CONFIG_HS20
267 wpabuf_free(sta->hs20_ie);
268 if (elems.hs20 && elems.hs20_len > 4) {
269 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
270 elems.hs20_len - 4);
271 } else
272 sta->hs20_ie = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700273
274 wpabuf_free(sta->roaming_consortium);
275 if (elems.roaming_cons_sel)
276 sta->roaming_consortium = wpabuf_alloc_copy(
277 elems.roaming_cons_sel + 4,
278 elems.roaming_cons_sel_len - 4);
279 else
280 sta->roaming_consortium = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800281#endif /* CONFIG_HS20 */
282
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800283#ifdef CONFIG_FST
284 wpabuf_free(sta->mb_ies);
285 if (hapd->iface->fst)
286 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
287 else
288 sta->mb_ies = NULL;
289#endif /* CONFIG_FST */
290
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800291 mbo_ap_check_sta_assoc(hapd, sta, &elems);
292
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800293 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
294 elems.supp_op_classes_len);
295
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700296 if (hapd->conf->wpa) {
297 if (ie == NULL || ielen == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800298#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299 if (hapd->conf->wps_state) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800300 wpa_printf(MSG_DEBUG,
301 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700302 sta->flags |= WLAN_STA_MAYBE_WPS;
303 goto skip_wpa_check;
304 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800305#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700306
307 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700308 reason = WLAN_REASON_INVALID_IE;
309 status = WLAN_STATUS_INVALID_IE;
310 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700311 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800312#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700313 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
314 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800315 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800316
Hai Shalom899fcc72020-10-19 14:38:18 -0700317 if (check_sa_query_need(hapd, sta)) {
318 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
319
320 p = hostapd_eid_assoc_comeback_time(hapd, sta,
321 p);
322
323 hostapd_sta_assoc(hapd, addr, reassoc, status,
324 buf, p - buf);
325 return 0;
326 }
327
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700328 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800329 wps = ieee802_11_vendor_ie_concat(ie, ielen,
330 WPS_IE_VENDOR_TYPE);
331 if (wps) {
332 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800333 wpa_printf(MSG_DEBUG,
334 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800335 sta->flags |= WLAN_STA_WPS2;
336 }
337 wpabuf_free(wps);
338 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700339 goto skip_wpa_check;
340 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800341#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342
Sunil8cd6f4d2022-06-28 18:40:46 +0000343 if (check_sa_query_need(hapd, sta)) {
344 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
345
346 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
347
348 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
349 p - buf);
350 return 0;
351 }
352
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700353 if (sta->wpa_sm == NULL)
354 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700355 sta->addr,
356 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700357 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800358 wpa_printf(MSG_ERROR,
359 "Failed to initialize WPA state machine");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700360 return -1;
361 }
362 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Hai Shalom021b0b52019-04-10 11:17:58 -0700363 hapd->iface->freq,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700364 ie, ielen,
Hai Shalomc3565922019-10-28 11:58:20 -0700365 elems.rsnxe ? elems.rsnxe - 2 : NULL,
366 elems.rsnxe ? elems.rsnxe_len + 2 : 0,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700367 elems.mdie, elems.mdie_len,
368 elems.owe_dh, elems.owe_dh_len);
Hai Shalomfdcde762020-04-02 11:19:20 -0700369 reason = WLAN_REASON_INVALID_IE;
370 status = WLAN_STATUS_INVALID_IE;
371 switch (res) {
372 case WPA_IE_OK:
373 reason = WLAN_REASON_UNSPECIFIED;
374 status = WLAN_STATUS_SUCCESS;
375 break;
376 case WPA_INVALID_IE:
377 reason = WLAN_REASON_INVALID_IE;
378 status = WLAN_STATUS_INVALID_IE;
379 break;
380 case WPA_INVALID_GROUP:
381 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
382 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
383 break;
384 case WPA_INVALID_PAIRWISE:
385 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
386 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
387 break;
388 case WPA_INVALID_AKMP:
389 reason = WLAN_REASON_AKMP_NOT_VALID;
390 status = WLAN_STATUS_AKMP_NOT_VALID;
391 break;
392 case WPA_NOT_ENABLED:
393 reason = WLAN_REASON_INVALID_IE;
394 status = WLAN_STATUS_INVALID_IE;
395 break;
396 case WPA_ALLOC_FAIL:
397 reason = WLAN_REASON_UNSPECIFIED;
398 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
399 break;
400 case WPA_MGMT_FRAME_PROTECTION_VIOLATION:
401 reason = WLAN_REASON_INVALID_IE;
402 status = WLAN_STATUS_INVALID_IE;
403 break;
404 case WPA_INVALID_MGMT_GROUP_CIPHER:
405 reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
406 status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
407 break;
408 case WPA_INVALID_MDIE:
409 reason = WLAN_REASON_INVALID_MDE;
410 status = WLAN_STATUS_INVALID_MDIE;
411 break;
412 case WPA_INVALID_PROTO:
413 reason = WLAN_REASON_INVALID_IE;
414 status = WLAN_STATUS_INVALID_IE;
415 break;
416 case WPA_INVALID_PMKID:
417 reason = WLAN_REASON_INVALID_PMKID;
418 status = WLAN_STATUS_INVALID_PMKID;
419 break;
420 case WPA_DENIED_OTHER_REASON:
421 reason = WLAN_REASON_UNSPECIFIED;
422 status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
423 break;
424 }
425 if (status != WLAN_STATUS_SUCCESS) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800426 wpa_printf(MSG_DEBUG,
427 "WPA/RSN information element rejected? (res %u)",
428 res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700429 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800430 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700431 }
Hai Shalomc3565922019-10-28 11:58:20 -0700432
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700433 if (wpa_auth_uses_mfp(sta->wpa_sm))
434 sta->flags |= WLAN_STA_MFP;
435 else
436 sta->flags &= ~WLAN_STA_MFP;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700437
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800438#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700439 if (sta->auth_alg == WLAN_AUTH_FT) {
440 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
441 req_ies_len);
442 if (status != WLAN_STATUS_SUCCESS) {
443 if (status == WLAN_STATUS_INVALID_PMKID)
444 reason = WLAN_REASON_INVALID_IE;
445 if (status == WLAN_STATUS_INVALID_MDIE)
446 reason = WLAN_REASON_INVALID_IE;
447 if (status == WLAN_STATUS_INVALID_FTIE)
448 reason = WLAN_REASON_INVALID_IE;
449 goto fail;
450 }
451 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800452#endif /* CONFIG_IEEE80211R_AP */
Hai Shalomc3565922019-10-28 11:58:20 -0700453#ifdef CONFIG_SAE
454 if (hapd->conf->sae_pwe == 2 &&
455 sta->auth_alg == WLAN_AUTH_SAE &&
Hai Shalom899fcc72020-10-19 14:38:18 -0700456 sta->sae && !sta->sae->h2e &&
Hai Shaloma20dcd72022-02-04 13:43:00 -0800457 ieee802_11_rsnx_capab_len(elems.rsnxe, elems.rsnxe_len,
458 WLAN_RSNX_CAPAB_SAE_H2E)) {
Hai Shalomc3565922019-10-28 11:58:20 -0700459 wpa_printf(MSG_INFO, "SAE: " MACSTR
460 " indicates support for SAE H2E, but did not use it",
461 MAC2STR(sta->addr));
462 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
463 reason = WLAN_REASON_UNSPECIFIED;
464 goto fail;
465 }
466#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700467 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800468#ifdef CONFIG_WPS
469 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800470
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800471 if (req_ies)
472 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700473 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800474 else
475 wps = NULL;
476#ifdef CONFIG_WPS_STRICT
477 if (wps && wps_validate_assoc_req(wps) < 0) {
478 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700479 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700480 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800481 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700482 }
483#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800484 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700485 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800486 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800487 wpa_printf(MSG_DEBUG,
488 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800489 sta->flags |= WLAN_STA_WPS2;
490 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700491 } else
492 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800493 wpabuf_free(wps);
494#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800495#ifdef CONFIG_HS20
496 } else if (hapd->conf->osen) {
497 if (elems.osen == NULL) {
498 hostapd_logger(
499 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
500 HOSTAPD_LEVEL_INFO,
501 "No HS 2.0 OSEN element in association request");
502 return WLAN_STATUS_INVALID_IE;
503 }
504
505 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
506 if (sta->wpa_sm == NULL)
507 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
508 sta->addr, NULL);
509 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800510 wpa_printf(MSG_WARNING,
511 "Failed to initialize WPA state machine");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800512 return WLAN_STATUS_UNSPECIFIED_FAILURE;
513 }
514 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
515 elems.osen - 2, elems.osen_len + 2) < 0)
516 return WLAN_STATUS_INVALID_IE;
517#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700519#ifdef CONFIG_WPS
520skip_wpa_check:
521#endif /* CONFIG_WPS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800522
523#ifdef CONFIG_MBO
524 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
525 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
526 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
527 wpa_printf(MSG_INFO,
528 "MBO: Reject WPA2 association without PMF");
529 return WLAN_STATUS_UNSPECIFIED_FAILURE;
530 }
531#endif /* CONFIG_MBO */
532
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800533#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700534 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
Hai Shalomfdcde762020-04-02 11:19:20 -0700535 sta->auth_alg, req_ies, req_ies_len,
536 !elems.rsnxe);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700537 if (!p) {
538 wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs");
539 return WLAN_STATUS_UNSPECIFIED_FAILURE;
540 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700541#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700542
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700543#ifdef CONFIG_FILS
544 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
545 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
546 sta->auth_alg == WLAN_AUTH_FILS_PK) {
547 int delay_assoc = 0;
548
549 if (!req_ies)
550 return WLAN_STATUS_UNSPECIFIED_FAILURE;
551
552 if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies,
553 req_ies_len,
554 sta->fils_session)) {
555 wpa_printf(MSG_DEBUG,
556 "FILS: Session validation failed");
557 return WLAN_STATUS_UNSPECIFIED_FAILURE;
558 }
559
560 res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies,
561 req_ies_len);
562 if (res < 0) {
563 wpa_printf(MSG_DEBUG,
564 "FILS: Key Confirm validation failed");
565 return WLAN_STATUS_UNSPECIFIED_FAILURE;
566 }
567
568 if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) {
569 wpa_printf(MSG_DEBUG,
570 "FILS: Delaying Assoc Response (HLP)");
571 delay_assoc = 1;
572 } else {
573 wpa_printf(MSG_DEBUG,
574 "FILS: Going ahead with Assoc Response (no HLP)");
575 }
576
577 if (sta) {
578 wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup");
579 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
580 os_free(sta->fils_pending_assoc_req);
581 sta->fils_pending_assoc_req = NULL;
582 sta->fils_pending_assoc_req_len = 0;
583 wpabuf_free(sta->fils_hlp_resp);
584 sta->fils_hlp_resp = NULL;
585 sta->fils_drv_assoc_finish = 0;
586 }
587
588 if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) {
589 u8 *req_tmp;
590
591 req_tmp = os_malloc(req_ies_len);
592 if (!req_tmp) {
593 wpa_printf(MSG_DEBUG,
594 "FILS: buffer allocation failed for assoc req");
595 goto fail;
596 }
597 os_memcpy(req_tmp, req_ies, req_ies_len);
598 sta->fils_pending_assoc_req = req_tmp;
599 sta->fils_pending_assoc_req_len = req_ies_len;
600 sta->fils_pending_assoc_is_reassoc = reassoc;
601 sta->fils_drv_assoc_finish = 1;
602 wpa_printf(MSG_DEBUG,
603 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
604 MACSTR, MAC2STR(sta->addr));
605 eloop_register_timeout(
606 0, hapd->conf->fils_hlp_wait_time * 1024,
607 fils_hlp_timeout, hapd, sta);
608 return 0;
609 }
610 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
611 elems.fils_session,
612 sta->fils_hlp_resp);
613 wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)",
614 buf, p - buf);
615 }
616#endif /* CONFIG_FILS */
617
Roshan Pius3a1667e2018-07-03 15:17:14 -0700618#ifdef CONFIG_OWE
619 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
620 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
621 elems.owe_dh) {
622 u8 *npos;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700623 u16 ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700624
625 npos = owe_assoc_req_process(hapd, sta,
626 elems.owe_dh, elems.owe_dh_len,
627 p, sizeof(buf) - (p - buf),
Hai Shalomb755a2a2020-04-23 21:49:02 -0700628 &ret_status);
629 status = ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700630 if (npos)
631 p = npos;
Hai Shalomfdcde762020-04-02 11:19:20 -0700632
Roshan Pius3a1667e2018-07-03 15:17:14 -0700633 if (!npos &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700634 status == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
Hai Shalomb755a2a2020-04-23 21:49:02 -0700635 hostapd_sta_assoc(hapd, addr, reassoc, ret_status, buf,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700636 p - buf);
637 return 0;
638 }
639
Hai Shalomfdcde762020-04-02 11:19:20 -0700640 if (!npos || status != WLAN_STATUS_SUCCESS)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700641 goto fail;
642 }
643#endif /* CONFIG_OWE */
644
Hai Shalom021b0b52019-04-10 11:17:58 -0700645#ifdef CONFIG_DPP2
646 dpp_pfs_free(sta->dpp_pfs);
647 sta->dpp_pfs = NULL;
648
649 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
650 hapd->conf->dpp_netaccesskey && sta->wpa_sm &&
651 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP &&
652 elems.owe_dh) {
653 sta->dpp_pfs = dpp_pfs_init(
654 wpabuf_head(hapd->conf->dpp_netaccesskey),
655 wpabuf_len(hapd->conf->dpp_netaccesskey));
656 if (!sta->dpp_pfs) {
657 wpa_printf(MSG_DEBUG,
658 "DPP: Could not initialize PFS");
659 /* Try to continue without PFS */
660 goto pfs_fail;
661 }
662
663 if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh,
664 elems.owe_dh_len) < 0) {
665 dpp_pfs_free(sta->dpp_pfs);
666 sta->dpp_pfs = NULL;
667 reason = WLAN_REASON_UNSPECIFIED;
668 goto fail;
669 }
670 }
671
672 wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ?
673 sta->dpp_pfs->secret : NULL);
674 pfs_fail:
675#endif /* CONFIG_DPP2 */
676
Hai Shalomfdcde762020-04-02 11:19:20 -0700677 if (elems.rrm_enabled &&
678 elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
679 os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
680 sizeof(sta->rrm_enabled_capa));
681
Roshan Pius3a1667e2018-07-03 15:17:14 -0700682#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700683 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700684
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700685 if (sta->auth_alg == WLAN_AUTH_FT ||
686 sta->auth_alg == WLAN_AUTH_FILS_SK ||
687 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
688 sta->auth_alg == WLAN_AUTH_FILS_PK)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700689 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700690#else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700691 /* Keep compiler silent about unused variables */
692 if (status) {
693 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700694#endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700695
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700696 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
697 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800698 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700699
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700700 hostapd_set_sta_flags(hapd, sta);
701
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700702 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
703 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700704#ifdef CONFIG_FILS
705 else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
706 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
707 sta->auth_alg == WLAN_AUTH_FILS_PK)
708 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
709#endif /* CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700710 else
711 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700712
713 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
714
715 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
716
717#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800718 if (req_ies) {
719 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
720 req_ies, req_ies_len);
721 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700722#endif /* CONFIG_P2P */
723
724 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800725
726fail:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800727#ifdef CONFIG_IEEE80211R_AP
Hai Shalomb755a2a2020-04-23 21:49:02 -0700728 if (status >= 0)
729 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800730#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800731 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
732 ap_free_sta(hapd, sta);
733 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700734}
735
736
737void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
738{
739 struct sta_info *sta;
740
741 if (addr == NULL) {
742 /*
743 * This could potentially happen with unexpected event from the
744 * driver wrapper. This was seen at least in one case where the
745 * driver ended up reporting a station mode event while hostapd
746 * was running, so better make sure we stop processing such an
747 * event here.
748 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800749 wpa_printf(MSG_DEBUG,
750 "hostapd_notif_disassoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700751 return;
752 }
753
754 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
755 HOSTAPD_LEVEL_INFO, "disassociated");
756
757 sta = ap_get_sta(hapd, addr);
758 if (sta == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800759 wpa_printf(MSG_DEBUG,
760 "Disassociation notification for unknown STA "
761 MACSTR, MAC2STR(addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762 return;
763 }
764
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800765 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700766 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Hai Shalomfdcde762020-04-02 11:19:20 -0700767 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700768 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
769 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
770 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
771 ap_free_sta(hapd, sta);
772}
773
774
775void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
776{
777 struct sta_info *sta = ap_get_sta(hapd, addr);
778
Roshan Pius3a1667e2018-07-03 15:17:14 -0700779 if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780 return;
781
782 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800783 HOSTAPD_LEVEL_INFO,
784 "disconnected due to excessive missing ACKs");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800786 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700787}
788
789
Roshan Pius3a1667e2018-07-03 15:17:14 -0700790void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr,
791 enum smps_mode smps_mode,
792 enum chan_width chan_width, u8 rx_nss)
793{
794 struct sta_info *sta = ap_get_sta(hapd, addr);
795 const char *txt;
796
797 if (!sta)
798 return;
799
800 switch (smps_mode) {
801 case SMPS_AUTOMATIC:
802 txt = "automatic";
803 break;
804 case SMPS_OFF:
805 txt = "off";
806 break;
807 case SMPS_DYNAMIC:
808 txt = "dynamic";
809 break;
810 case SMPS_STATIC:
811 txt = "static";
812 break;
813 default:
814 txt = NULL;
815 break;
816 }
817 if (txt) {
818 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED
819 MACSTR " %s", MAC2STR(addr), txt);
820 }
821
822 switch (chan_width) {
823 case CHAN_WIDTH_20_NOHT:
824 txt = "20(no-HT)";
825 break;
826 case CHAN_WIDTH_20:
827 txt = "20";
828 break;
829 case CHAN_WIDTH_40:
830 txt = "40";
831 break;
832 case CHAN_WIDTH_80:
833 txt = "80";
834 break;
835 case CHAN_WIDTH_80P80:
836 txt = "80+80";
837 break;
838 case CHAN_WIDTH_160:
839 txt = "160";
840 break;
Sunil8cd6f4d2022-06-28 18:40:46 +0000841 case CHAN_WIDTH_320:
842 txt = "320";
843 break;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700844 default:
845 txt = NULL;
846 break;
847 }
848 if (txt) {
849 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED
850 MACSTR " %s", MAC2STR(addr), txt);
851 }
852
853 if (rx_nss != 0xff) {
854 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED
855 MACSTR " %d", MAC2STR(addr), rx_nss);
856 }
857}
858
859
Dmitry Shmidt04949592012-07-19 12:16:46 -0700860void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -0700861 int offset, int width, int cf1, int cf2,
862 int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700863{
864#ifdef NEED_AP_MLME
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800865 int channel, chwidth, is_dfs;
866 u8 seg0_idx = 0, seg1_idx = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800867 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700868
869 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800870 HOSTAPD_LEVEL_INFO,
Sunil Ravia04bd252022-05-02 22:54:18 -0700871 "driver %s channel switch: 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",
Hai Shalom81f62d82019-07-22 12:10:00 -0700872 finished ? "had" : "starting",
Hai Shalom60840252021-02-19 19:02:11 -0800873 freq, ht, hapd->iconf->ch_switch_vht_config,
Sunil Ravia04bd252022-05-02 22:54:18 -0700874 hapd->iconf->ch_switch_he_config,
875 hapd->iconf->ch_switch_eht_config, offset,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700876 width, channel_width_to_string(width), cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700877
Hai Shalom1dc4d202019-04-29 16:22:27 -0700878 if (!hapd->iface->current_mode) {
879 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
880 HOSTAPD_LEVEL_WARNING,
881 "ignore channel switch since the interface is not yet ready");
882 return;
883 }
884
Dmitry Shmidt04949592012-07-19 12:16:46 -0700885 hapd->iface->freq = freq;
886
887 channel = hostapd_hw_get_channel(hapd, freq);
888 if (!channel) {
889 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800890 HOSTAPD_LEVEL_WARNING,
891 "driver switched to bad channel!");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700892 return;
893 }
894
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800895 switch (width) {
896 case CHAN_WIDTH_80:
Sunil8cd6f4d2022-06-28 18:40:46 +0000897 chwidth = CONF_OPER_CHWIDTH_80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800898 break;
899 case CHAN_WIDTH_80P80:
Sunil8cd6f4d2022-06-28 18:40:46 +0000900 chwidth = CONF_OPER_CHWIDTH_80P80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800901 break;
902 case CHAN_WIDTH_160:
Sunil8cd6f4d2022-06-28 18:40:46 +0000903 chwidth = CONF_OPER_CHWIDTH_160MHZ;
904 break;
905 case CHAN_WIDTH_320:
906 chwidth = CONF_OPER_CHWIDTH_320MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800907 break;
908 case CHAN_WIDTH_20_NOHT:
909 case CHAN_WIDTH_20:
910 case CHAN_WIDTH_40:
911 default:
Sunil8cd6f4d2022-06-28 18:40:46 +0000912 chwidth = CONF_OPER_CHWIDTH_USE_HT;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800913 break;
914 }
915
916 switch (hapd->iface->current_mode->mode) {
917 case HOSTAPD_MODE_IEEE80211A:
Hai Shalom899fcc72020-10-19 14:38:18 -0700918 if (cf1 == 5935)
919 seg0_idx = (cf1 - 5925) / 5;
920 else if (cf1 > 5950)
921 seg0_idx = (cf1 - 5950) / 5;
922 else if (cf1 > 5000)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800923 seg0_idx = (cf1 - 5000) / 5;
Hai Shalom899fcc72020-10-19 14:38:18 -0700924
925 if (cf2 == 5935)
926 seg1_idx = (cf2 - 5925) / 5;
927 else if (cf2 > 5950)
928 seg1_idx = (cf2 - 5950) / 5;
929 else if (cf2 > 5000)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800930 seg1_idx = (cf2 - 5000) / 5;
931 break;
932 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800933 ieee80211_freq_to_chan(cf1, &seg0_idx);
934 ieee80211_freq_to_chan(cf2, &seg1_idx);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800935 break;
936 }
937
Dmitry Shmidt04949592012-07-19 12:16:46 -0700938 hapd->iconf->channel = channel;
939 hapd->iconf->ieee80211n = ht;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700940 if (!ht) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800941 hapd->iconf->ieee80211ac = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700942 } else if (hapd->iconf->ch_switch_vht_config) {
943 /* CHAN_SWITCH VHT config */
944 if (hapd->iconf->ch_switch_vht_config &
945 CH_SWITCH_VHT_ENABLED)
946 hapd->iconf->ieee80211ac = 1;
947 else if (hapd->iconf->ch_switch_vht_config &
948 CH_SWITCH_VHT_DISABLED)
949 hapd->iconf->ieee80211ac = 0;
Hai Shalom60840252021-02-19 19:02:11 -0800950 } else if (hapd->iconf->ch_switch_he_config) {
951 /* CHAN_SWITCH HE config */
952 if (hapd->iconf->ch_switch_he_config &
953 CH_SWITCH_HE_ENABLED)
954 hapd->iconf->ieee80211ax = 1;
955 else if (hapd->iconf->ch_switch_he_config &
956 CH_SWITCH_HE_DISABLED)
957 hapd->iconf->ieee80211ax = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -0700958#ifdef CONFIG_IEEE80211BE
959 } else if (hapd->iconf->ch_switch_eht_config) {
960 /* CHAN_SWITCH EHT config */
961 if (hapd->iconf->ch_switch_eht_config &
962 CH_SWITCH_EHT_ENABLED) {
963 hapd->iconf->ieee80211be = 1;
964 hapd->iconf->ieee80211ax = 1;
965 if (!is_6ghz_freq(hapd->iface->freq))
966 hapd->iconf->ieee80211ac = 1;
967 } else if (hapd->iconf->ch_switch_eht_config &
968 CH_SWITCH_EHT_DISABLED)
969 hapd->iconf->ieee80211be = 0;
970#endif /* CONFIG_IEEE80211BE */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700971 }
972 hapd->iconf->ch_switch_vht_config = 0;
Hai Shalom60840252021-02-19 19:02:11 -0800973 hapd->iconf->ch_switch_he_config = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -0700974 hapd->iconf->ch_switch_eht_config = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700975
Hai Shaloma20dcd72022-02-04 13:43:00 -0800976 if (width == CHAN_WIDTH_40 || width == CHAN_WIDTH_80 ||
977 width == CHAN_WIDTH_80P80 || width == CHAN_WIDTH_160)
978 hapd->iconf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
979 else if (width == CHAN_WIDTH_20 || width == CHAN_WIDTH_20_NOHT)
980 hapd->iconf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
981
Dmitry Shmidt04949592012-07-19 12:16:46 -0700982 hapd->iconf->secondary_channel = offset;
Hai Shalom81f62d82019-07-22 12:10:00 -0700983 hostapd_set_oper_chwidth(hapd->iconf, chwidth);
984 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, seg0_idx);
985 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, seg1_idx);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800986 if (hapd->iconf->ieee80211ac) {
987 hapd->iconf->vht_capab &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
Sunil8cd6f4d2022-06-28 18:40:46 +0000988 if (chwidth == CONF_OPER_CHWIDTH_160MHZ)
Hai Shaloma20dcd72022-02-04 13:43:00 -0800989 hapd->iconf->vht_capab |=
990 VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
Sunil8cd6f4d2022-06-28 18:40:46 +0000991 else if (chwidth == CONF_OPER_CHWIDTH_80P80MHZ)
Hai Shaloma20dcd72022-02-04 13:43:00 -0800992 hapd->iconf->vht_capab |=
993 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
994 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800995
Roshan Pius3a1667e2018-07-03 15:17:14 -0700996 is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features,
997 hapd->iface->num_hw_features);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800998
Hai Shalom81f62d82019-07-22 12:10:00 -0700999 wpa_msg(hapd->msg_ctx, MSG_INFO,
1000 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d dfs=%d",
1001 finished ? WPA_EVENT_CHANNEL_SWITCH :
1002 WPA_EVENT_CHANNEL_SWITCH_STARTED,
1003 freq, ht, offset, channel_width_to_string(width),
1004 cf1, cf2, is_dfs);
1005 if (!finished)
1006 return;
1007
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001008 if (hapd->csa_in_progress &&
1009 freq == hapd->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001010 hostapd_cleanup_cs_params(hapd);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001011 ieee802_11_set_beacon(hapd);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001012
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001013 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
1014 "freq=%d dfs=%d", freq, is_dfs);
1015 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
1016 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
1017 "freq=%d dfs=%d", freq, is_dfs);
Hai Shalomfdcde762020-04-02 11:19:20 -07001018 } else if (is_dfs &&
1019 hostapd_is_dfs_required(hapd->iface) &&
1020 !hostapd_is_dfs_chan_available(hapd->iface) &&
1021 !hapd->iface->cac_started) {
1022 hostapd_disable_iface(hapd->iface);
1023 hostapd_enable_iface(hapd->iface);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001024 }
Hai Shalom74f70d42019-02-11 14:42:39 -08001025
1026 for (i = 0; i < hapd->iface->num_bss; i++)
1027 hostapd_neighbor_set_own_report(hapd->iface->bss[i]);
Hai Shalom899fcc72020-10-19 14:38:18 -07001028
1029#ifdef CONFIG_OCV
Sunil Ravia04bd252022-05-02 22:54:18 -07001030 if (hapd->conf->ocv &&
1031 !(hapd->iface->drv_flags2 &
1032 WPA_DRIVER_FLAGS2_SA_QUERY_OFFLOAD_AP)) {
Hai Shalom899fcc72020-10-19 14:38:18 -07001033 struct sta_info *sta;
1034 bool check_sa_query = false;
1035
1036 for (sta = hapd->sta_list; sta; sta = sta->next) {
1037 if (wpa_auth_uses_ocv(sta->wpa_sm) &&
1038 !(sta->flags & WLAN_STA_WNM_SLEEP_MODE)) {
1039 sta->post_csa_sa_query = 1;
1040 check_sa_query = true;
1041 }
1042 }
1043
1044 if (check_sa_query) {
1045 wpa_printf(MSG_DEBUG,
1046 "OCV: Check post-CSA SA Query initiation in 15 seconds");
1047 eloop_register_timeout(15, 0,
1048 hostapd_ocv_check_csa_sa_query,
1049 hapd, NULL);
1050 }
1051 }
1052#endif /* CONFIG_OCV */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001053#endif /* NEED_AP_MLME */
1054}
1055
1056
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001057void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
1058 const u8 *addr, int reason_code)
1059{
1060 switch (reason_code) {
1061 case MAX_CLIENT_REACHED:
1062 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
1063 MAC2STR(addr));
1064 break;
1065 case BLOCKED_CLIENT:
1066 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
1067 MAC2STR(addr));
1068 break;
1069 }
1070}
1071
1072
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001073#ifdef CONFIG_ACS
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001074void hostapd_acs_channel_selected(struct hostapd_data *hapd,
1075 struct acs_selected_channels *acs_res)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001076{
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001077 int ret, i;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001078 int err = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001079 struct hostapd_channel_data *pri_chan;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001080
1081 if (hapd->iconf->channel) {
1082 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
1083 hapd->iconf->channel);
1084 return;
1085 }
1086
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001087 hapd->iface->freq = acs_res->pri_freq;
1088
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001089 if (!hapd->iface->current_mode) {
1090 for (i = 0; i < hapd->iface->num_hw_features; i++) {
1091 struct hostapd_hw_modes *mode =
1092 &hapd->iface->hw_features[i];
1093
1094 if (mode->mode == acs_res->hw_mode) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001095 if (hapd->iface->freq > 0 &&
1096 !hw_get_chan(mode->mode,
1097 hapd->iface->freq,
1098 hapd->iface->hw_features,
1099 hapd->iface->num_hw_features))
1100 continue;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001101 hapd->iface->current_mode = mode;
1102 break;
1103 }
1104 }
1105 if (!hapd->iface->current_mode) {
1106 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1107 HOSTAPD_LEVEL_WARNING,
1108 "driver selected to bad hw_mode");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001109 err = 1;
1110 goto out;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001111 }
1112 }
1113
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001114 if (!acs_res->pri_freq) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001115 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1116 HOSTAPD_LEVEL_WARNING,
1117 "driver switched to bad channel");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001118 err = 1;
1119 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001120 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001121 pri_chan = hw_get_channel_freq(hapd->iface->current_mode->mode,
1122 acs_res->pri_freq, NULL,
1123 hapd->iface->hw_features,
1124 hapd->iface->num_hw_features);
1125 if (!pri_chan) {
1126 wpa_printf(MSG_ERROR,
1127 "ACS: Could not determine primary channel number from pri_freq %u",
1128 acs_res->pri_freq);
1129 err = 1;
1130 goto out;
1131 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001132
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001133 hapd->iconf->channel = pri_chan->chan;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001134 hapd->iconf->acs = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001135
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001136 if (acs_res->sec_freq == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001137 hapd->iconf->secondary_channel = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001138 else if (acs_res->sec_freq < acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001139 hapd->iconf->secondary_channel = -1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001140 else if (acs_res->sec_freq > acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001141 hapd->iconf->secondary_channel = 1;
1142 else {
1143 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001144 err = 1;
1145 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001146 }
1147
Hai Shalomfdcde762020-04-02 11:19:20 -07001148 hapd->iconf->edmg_channel = acs_res->edmg_channel;
1149
Hai Shalom81f62d82019-07-22 12:10:00 -07001150 if (hapd->iface->conf->ieee80211ac || hapd->iface->conf->ieee80211ax) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001151 /* set defaults for backwards compatibility */
Hai Shalom81f62d82019-07-22 12:10:00 -07001152 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1153 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, 0);
Sunil8cd6f4d2022-06-28 18:40:46 +00001154 hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_USE_HT);
Hai Shalomfdcde762020-04-02 11:19:20 -07001155 if (acs_res->ch_width == 40) {
1156 if (is_6ghz_freq(acs_res->pri_freq))
1157 hostapd_set_oper_centr_freq_seg0_idx(
1158 hapd->iconf,
1159 acs_res->vht_seg0_center_ch);
1160 } else if (acs_res->ch_width == 80) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001161 hostapd_set_oper_centr_freq_seg0_idx(
1162 hapd->iconf, acs_res->vht_seg0_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001163 if (acs_res->vht_seg1_center_ch == 0) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001164 hostapd_set_oper_chwidth(
1165 hapd->iconf, CONF_OPER_CHWIDTH_80MHZ);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001166 } else {
Sunil8cd6f4d2022-06-28 18:40:46 +00001167 hostapd_set_oper_chwidth(
1168 hapd->iconf,
1169 CONF_OPER_CHWIDTH_80P80MHZ);
Hai Shalom81f62d82019-07-22 12:10:00 -07001170 hostapd_set_oper_centr_freq_seg1_idx(
1171 hapd->iconf,
1172 acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001173 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001174 } else if (acs_res->ch_width == 160) {
Sunil8cd6f4d2022-06-28 18:40:46 +00001175 hostapd_set_oper_chwidth(hapd->iconf,
1176 CONF_OPER_CHWIDTH_160MHZ);
Hai Shalomfdcde762020-04-02 11:19:20 -07001177 hostapd_set_oper_centr_freq_seg0_idx(
1178 hapd->iconf, acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001179 }
1180 }
1181
Sunil8cd6f4d2022-06-28 18:40:46 +00001182#ifdef CONFIG_IEEE80211BE
1183 if (hapd->iface->conf->ieee80211be && acs_res->ch_width == 320) {
1184 hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_320MHZ);
1185 hostapd_set_oper_centr_freq_seg0_idx(
1186 hapd->iconf, acs_res->vht_seg1_center_ch);
1187 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1188 }
1189#endif /* CONFIG_IEEE80211BE */
1190
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001191out:
1192 ret = hostapd_acs_completed(hapd->iface, err);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001193 if (ret) {
1194 wpa_printf(MSG_ERROR,
1195 "ACS: Possibly channel configuration is invalid");
1196 }
1197}
1198#endif /* CONFIG_ACS */
1199
1200
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001201int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001202 const u8 *bssid, const u8 *ie, size_t ie_len,
1203 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001204{
1205 size_t i;
1206 int ret = 0;
1207
1208 if (sa == NULL || ie == NULL)
1209 return -1;
1210
1211 random_add_randomness(sa, ETH_ALEN);
1212 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
1213 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001214 sa, da, bssid, ie, ie_len,
1215 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001216 ret = 1;
1217 break;
1218 }
1219 }
1220 return ret;
1221}
1222
1223
1224#ifdef HOSTAPD
1225
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001226#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001227static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
1228 const u8 *bssid,
1229 u16 auth_transaction, u16 status,
1230 const u8 *ies, size_t ies_len)
1231{
1232 struct hostapd_data *hapd = ctx;
1233 struct sta_info *sta;
1234
1235 sta = ap_get_sta(hapd, dst);
1236 if (sta == NULL)
1237 return;
1238
1239 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
1240 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
1241 sta->flags |= WLAN_STA_AUTH;
1242
1243 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
1244}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001245#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001246
1247
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001248#ifdef CONFIG_FILS
1249static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
1250 struct sta_info *sta, u16 resp,
1251 struct wpabuf *data, int pub)
1252{
1253 if (resp == WLAN_STATUS_SUCCESS) {
1254 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1255 HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
1256 sta->flags |= WLAN_STA_AUTH;
1257 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1258 sta->auth_alg = WLAN_AUTH_FILS_SK;
1259 mlme_authenticate_indication(hapd, sta);
1260 } else {
1261 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1262 HOSTAPD_LEVEL_DEBUG,
1263 "authentication failed (FILS)");
1264 }
1265
1266 hostapd_sta_auth(hapd, sta->addr, 2, resp,
1267 data ? wpabuf_head(data) : NULL,
1268 data ? wpabuf_len(data) : 0);
1269 wpabuf_free(data);
1270}
1271#endif /* CONFIG_FILS */
1272
1273
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001274static void hostapd_notif_auth(struct hostapd_data *hapd,
1275 struct auth_info *rx_auth)
1276{
1277 struct sta_info *sta;
1278 u16 status = WLAN_STATUS_SUCCESS;
1279 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1280 size_t resp_ies_len = 0;
1281
1282 sta = ap_get_sta(hapd, rx_auth->peer);
1283 if (!sta) {
1284 sta = ap_sta_add(hapd, rx_auth->peer);
1285 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -07001286 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001287 goto fail;
1288 }
1289 }
1290 sta->flags &= ~WLAN_STA_PREAUTH;
1291 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001292#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001293 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
1294 sta->auth_alg = WLAN_AUTH_FT;
1295 if (sta->wpa_sm == NULL)
1296 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001297 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001298 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001299 wpa_printf(MSG_DEBUG,
1300 "FT: Failed to initialize WPA state machine");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001301 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1302 goto fail;
1303 }
1304 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
1305 rx_auth->auth_transaction, rx_auth->ies,
1306 rx_auth->ies_len,
1307 hostapd_notify_auth_ft_finish, hapd);
1308 return;
1309 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001310#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001311
1312#ifdef CONFIG_FILS
1313 if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
1314 sta->auth_alg = WLAN_AUTH_FILS_SK;
1315 handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
1316 rx_auth->auth_type, rx_auth->auth_transaction,
1317 rx_auth->status_code,
1318 hostapd_notify_auth_fils_finish);
1319 return;
1320 }
1321#endif /* CONFIG_FILS */
1322
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001323fail:
1324 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
1325 status, resp_ies, resp_ies_len);
1326}
1327
1328
Hai Shalom021b0b52019-04-10 11:17:58 -07001329#ifndef NEED_AP_MLME
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001330static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001331 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001332{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001333 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001334 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001335 size_t plen __maybe_unused;
1336 u16 fc;
Hai Shalom74f70d42019-02-11 14:42:39 -08001337 u8 *action __maybe_unused;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001338
Hai Shalom74f70d42019-02-11 14:42:39 -08001339 if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001340 return;
1341
Hai Shalom021b0b52019-04-10 11:17:58 -07001342 plen = drv_mgmt->frame_len - IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001343
1344 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
1345 fc = le_to_host16(mgmt->frame_control);
1346 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
1347 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001348
Hai Shalom74f70d42019-02-11 14:42:39 -08001349 action = (u8 *) &mgmt->u.action.u;
1350 wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
1351 " da " MACSTR " plen %d",
1352 mgmt->u.action.category, *action,
1353 MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001354
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001355 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001356 if (sta == NULL) {
1357 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
1358 return;
1359 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001360#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001361 if (mgmt->u.action.category == WLAN_ACTION_FT) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001362 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, plen);
1363 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001364 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001365#endif /* CONFIG_IEEE80211R_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001366 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001367 ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001368 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001369 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001370#ifdef CONFIG_WNM_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001371 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
1372 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001373 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001374 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001375#endif /* CONFIG_WNM_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001376#ifdef CONFIG_FST
1377 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
1378 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
1379 return;
1380 }
1381#endif /* CONFIG_FST */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001382#ifdef CONFIG_DPP
Hai Shalom021b0b52019-04-10 11:17:58 -07001383 if (plen >= 2 + 4 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001384 mgmt->u.action.u.vs_public_action.action ==
1385 WLAN_PA_VENDOR_SPECIFIC &&
1386 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1387 OUI_WFA &&
1388 mgmt->u.action.u.vs_public_action.variable[0] ==
1389 DPP_OUI_TYPE) {
1390 const u8 *pos, *end;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001391
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001392 pos = mgmt->u.action.u.vs_public_action.oui;
1393 end = drv_mgmt->frame + drv_mgmt->frame_len;
1394 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
1395 drv_mgmt->freq);
1396 return;
1397 }
1398#endif /* CONFIG_DPP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001399}
Hai Shalom021b0b52019-04-10 11:17:58 -07001400#endif /* NEED_AP_MLME */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001401
1402
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001403#ifdef NEED_AP_MLME
1404
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001405#define HAPD_BROADCAST ((struct hostapd_data *) -1)
1406
1407static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
1408 const u8 *bssid)
1409{
1410 size_t i;
1411
1412 if (bssid == NULL)
1413 return NULL;
1414 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1415 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1416 return HAPD_BROADCAST;
1417
1418 for (i = 0; i < iface->num_bss; i++) {
1419 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
1420 return iface->bss[i];
1421 }
1422
1423 return NULL;
1424}
1425
1426
1427static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001428 const u8 *bssid, const u8 *addr,
1429 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001430{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001431 hapd = get_hapd_bssid(hapd->iface, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001432 if (hapd == NULL || hapd == HAPD_BROADCAST)
1433 return;
1434
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001435 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001436}
1437
1438
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001439static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001440{
1441 struct hostapd_iface *iface = hapd->iface;
1442 const struct ieee80211_hdr *hdr;
1443 const u8 *bssid;
1444 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001445 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001446
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001447#ifdef CONFIG_TESTING_OPTIONS
1448 if (hapd->ext_mgmt_frame_handling) {
1449 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
1450 char *hex = os_malloc(hex_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001451
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001452 if (hex) {
1453 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
1454 rx_mgmt->frame_len);
1455 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1456 os_free(hex);
1457 }
1458 return 1;
1459 }
1460#endif /* CONFIG_TESTING_OPTIONS */
1461
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001462 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1463 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
1464 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001465 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001466
1467 hapd = get_hapd_bssid(iface, bssid);
1468 if (hapd == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001469 u16 fc = le_to_host16(hdr->frame_control);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001470
1471 /*
1472 * Drop frames to unknown BSSIDs except for Beacon frames which
1473 * could be used to update neighbor information.
1474 */
1475 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1476 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1477 hapd = iface->bss[0];
1478 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001479 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001480 }
1481
1482 os_memset(&fi, 0, sizeof(fi));
Roshan Pius3a1667e2018-07-03 15:17:14 -07001483 fi.freq = rx_mgmt->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001484 fi.datarate = rx_mgmt->datarate;
1485 fi.ssi_signal = rx_mgmt->ssi_signal;
1486
1487 if (hapd == HAPD_BROADCAST) {
1488 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001489
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001490 ret = 0;
1491 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -07001492 /* if bss is set, driver will call this function for
1493 * each bss individually. */
1494 if (rx_mgmt->drv_priv &&
1495 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
1496 continue;
1497
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001498 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
1499 rx_mgmt->frame_len, &fi) > 0)
1500 ret = 1;
1501 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001502 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001503 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
1504 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001505
1506 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001507
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001508 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001509}
1510
1511
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001512static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
1513 size_t len, u16 stype, int ok)
1514{
1515 struct ieee80211_hdr *hdr;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001516 struct hostapd_data *orig_hapd = hapd;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001517
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001518 hdr = (struct ieee80211_hdr *) buf;
1519 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001520 if (!hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001521 return;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001522 if (hapd == HAPD_BROADCAST) {
1523 if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
1524 buf[24] != WLAN_ACTION_PUBLIC)
1525 return;
1526 hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2);
1527 if (!hapd || hapd == HAPD_BROADCAST)
1528 return;
1529 /*
1530 * Allow processing of TX status for a Public Action frame that
1531 * used wildcard BBSID.
1532 */
1533 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001534 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1535}
1536
1537#endif /* NEED_AP_MLME */
1538
1539
1540static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
1541{
1542 struct sta_info *sta = ap_get_sta(hapd, addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001543
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001544 if (sta)
1545 return 0;
1546
1547 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
1548 " - adding a new STA", MAC2STR(addr));
1549 sta = ap_sta_add(hapd, addr);
1550 if (sta) {
1551 hostapd_new_assoc_sta(hapd, sta, 0);
1552 } else {
1553 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
1554 MAC2STR(addr));
1555 return -1;
1556 }
1557
1558 return 0;
1559}
1560
1561
1562static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
Sunil8cd6f4d2022-06-28 18:40:46 +00001563 const u8 *data, size_t data_len,
1564 enum frame_encryption encrypted)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001565{
1566 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001567 struct sta_info *sta;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001568 size_t j;
1569
1570 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001571 sta = ap_get_sta(iface->bss[j], src);
1572 if (sta && sta->flags & WLAN_STA_ASSOC) {
1573 hapd = iface->bss[j];
1574 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001575 }
1576 }
1577
Sunil8cd6f4d2022-06-28 18:40:46 +00001578 ieee802_1x_receive(hapd, src, data, data_len, encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001579}
1580
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001581#endif /* HOSTAPD */
1582
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001583
Hai Shalomfdcde762020-04-02 11:19:20 -07001584static struct hostapd_channel_data *
1585hostapd_get_mode_chan(struct hostapd_hw_modes *mode, unsigned int freq)
1586{
1587 int i;
1588 struct hostapd_channel_data *chan;
1589
1590 for (i = 0; i < mode->num_channels; i++) {
1591 chan = &mode->channels[i];
1592 if ((unsigned int) chan->freq == freq)
1593 return chan;
1594 }
1595
1596 return NULL;
1597}
1598
1599
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001600static struct hostapd_channel_data * hostapd_get_mode_channel(
1601 struct hostapd_iface *iface, unsigned int freq)
1602{
1603 int i;
1604 struct hostapd_channel_data *chan;
1605
Hai Shalomfdcde762020-04-02 11:19:20 -07001606 for (i = 0; i < iface->num_hw_features; i++) {
1607 if (hostapd_hw_skip_mode(iface, &iface->hw_features[i]))
1608 continue;
1609 chan = hostapd_get_mode_chan(&iface->hw_features[i], freq);
1610 if (chan)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001611 return chan;
1612 }
1613
1614 return NULL;
1615}
1616
1617
1618static void hostapd_update_nf(struct hostapd_iface *iface,
1619 struct hostapd_channel_data *chan,
1620 struct freq_survey *survey)
1621{
1622 if (!iface->chans_surveyed) {
1623 chan->min_nf = survey->nf;
1624 iface->lowest_nf = survey->nf;
1625 } else {
1626 if (dl_list_empty(&chan->survey_list))
1627 chan->min_nf = survey->nf;
1628 else if (survey->nf < chan->min_nf)
1629 chan->min_nf = survey->nf;
1630 if (survey->nf < iface->lowest_nf)
1631 iface->lowest_nf = survey->nf;
1632 }
1633}
1634
1635
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001636static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
1637 struct survey_results *survey_res)
1638{
1639 struct hostapd_channel_data *chan;
1640 struct freq_survey *survey;
1641 u64 divisor, dividend;
1642
1643 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
1644 list);
1645 if (!survey || !survey->freq)
1646 return;
1647
1648 chan = hostapd_get_mode_channel(iface, survey->freq);
1649 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
1650 return;
1651
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001652 wpa_printf(MSG_DEBUG,
1653 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001654 survey->freq,
1655 (unsigned long int) survey->channel_time,
1656 (unsigned long int) survey->channel_time_busy);
1657
1658 if (survey->channel_time > iface->last_channel_time &&
1659 survey->channel_time > survey->channel_time_busy) {
1660 dividend = survey->channel_time_busy -
1661 iface->last_channel_time_busy;
1662 divisor = survey->channel_time - iface->last_channel_time;
1663
1664 iface->channel_utilization = dividend * 255 / divisor;
1665 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
1666 iface->channel_utilization);
1667 }
1668 iface->last_channel_time = survey->channel_time;
1669 iface->last_channel_time_busy = survey->channel_time_busy;
1670}
1671
1672
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001673void hostapd_event_get_survey(struct hostapd_iface *iface,
1674 struct survey_results *survey_results)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001675{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001676 struct freq_survey *survey, *tmp;
1677 struct hostapd_channel_data *chan;
1678
1679 if (dl_list_empty(&survey_results->survey_list)) {
1680 wpa_printf(MSG_DEBUG, "No survey data received");
1681 return;
1682 }
1683
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001684 if (survey_results->freq_filter) {
1685 hostapd_single_channel_get_survey(iface, survey_results);
1686 return;
1687 }
1688
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001689 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
1690 struct freq_survey, list) {
1691 chan = hostapd_get_mode_channel(iface, survey->freq);
1692 if (!chan)
1693 continue;
1694 if (chan->flag & HOSTAPD_CHAN_DISABLED)
1695 continue;
1696
1697 dl_list_del(&survey->list);
1698 dl_list_add_tail(&chan->survey_list, &survey->list);
1699
1700 hostapd_update_nf(iface, chan, survey);
1701
1702 iface->chans_surveyed++;
1703 }
1704}
1705
1706
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001707#ifdef HOSTAPD
Dmitry Shmidt051af732013-10-22 13:52:46 -07001708#ifdef NEED_AP_MLME
1709
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001710static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
1711{
1712 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
1713 hapd->conf->iface);
1714
1715 if (hapd->csa_in_progress) {
1716 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
1717 hapd->conf->iface);
1718 hostapd_switch_channel_fallback(hapd->iface,
1719 &hapd->cs_freq_params);
1720 }
Yu Ouyang378d3c42021-08-20 17:31:08 +08001721
1722 // inform framework that interface is unavailable
1723 hostapd_disable_iface(hapd->iface);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001724}
1725
1726
Dmitry Shmidt051af732013-10-22 13:52:46 -07001727static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
1728 struct dfs_event *radar)
1729{
1730 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001731 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001732 radar->chan_offset, radar->chan_width,
1733 radar->cf1, radar->cf2);
1734}
1735
1736
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001737static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
1738 struct dfs_event *radar)
1739{
1740 wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
1741 hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
1742 radar->chan_offset, radar->chan_width,
1743 radar->cf1, radar->cf2);
1744}
1745
1746
Dmitry Shmidt051af732013-10-22 13:52:46 -07001747static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
1748 struct dfs_event *radar)
1749{
1750 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001751 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001752 radar->chan_offset, radar->chan_width,
1753 radar->cf1, radar->cf2);
1754}
1755
1756
1757static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
1758 struct dfs_event *radar)
1759{
1760 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001761 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001762 radar->chan_offset, radar->chan_width,
1763 radar->cf1, radar->cf2);
1764}
1765
1766
1767static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
1768 struct dfs_event *radar)
1769{
1770 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001771 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001772 radar->chan_offset, radar->chan_width,
1773 radar->cf1, radar->cf2);
1774}
1775
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001776
1777static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
1778 struct dfs_event *radar)
1779{
1780 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
1781 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
1782 radar->chan_offset, radar->chan_width,
1783 radar->cf1, radar->cf2);
1784}
1785
Dmitry Shmidt051af732013-10-22 13:52:46 -07001786#endif /* NEED_AP_MLME */
1787
1788
Roshan Pius3a1667e2018-07-03 15:17:14 -07001789static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd,
1790 int istatus,
1791 const char *ifname,
1792 const u8 *addr)
1793{
1794 struct sta_info *sta = ap_get_sta(hapd, addr);
1795
1796 if (sta) {
1797 os_free(sta->ifname_wds);
1798 if (istatus == INTERFACE_ADDED)
1799 sta->ifname_wds = os_strdup(ifname);
1800 else
1801 sta->ifname_wds = NULL;
1802 }
1803
1804 wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR,
1805 istatus == INTERFACE_ADDED ?
1806 WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED,
1807 ifname, MAC2STR(addr));
1808}
1809
1810
Hai Shalom81f62d82019-07-22 12:10:00 -07001811#ifdef CONFIG_OWE
1812static int hostapd_notif_update_dh_ie(struct hostapd_data *hapd,
1813 const u8 *peer, const u8 *ie,
1814 size_t ie_len)
1815{
1816 u16 status;
1817 struct sta_info *sta;
1818 struct ieee802_11_elems elems;
1819
1820 if (!hapd || !hapd->wpa_auth) {
1821 wpa_printf(MSG_DEBUG, "OWE: Invalid hapd context");
1822 return -1;
1823 }
1824 if (!peer) {
1825 wpa_printf(MSG_DEBUG, "OWE: Peer unknown");
1826 return -1;
1827 }
1828 if (!(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) {
1829 wpa_printf(MSG_DEBUG, "OWE: No OWE AKM configured");
1830 status = WLAN_STATUS_AKMP_NOT_VALID;
1831 goto err;
1832 }
1833 if (ieee802_11_parse_elems(ie, ie_len, &elems, 1) == ParseFailed) {
1834 wpa_printf(MSG_DEBUG, "OWE: Failed to parse OWE IE for "
1835 MACSTR, MAC2STR(peer));
1836 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1837 goto err;
1838 }
1839 status = owe_validate_request(hapd, peer, elems.rsn_ie,
1840 elems.rsn_ie_len,
1841 elems.owe_dh, elems.owe_dh_len);
1842 if (status != WLAN_STATUS_SUCCESS)
1843 goto err;
1844
1845 sta = ap_get_sta(hapd, peer);
1846 if (sta) {
1847 ap_sta_no_session_timeout(hapd, sta);
1848 accounting_sta_stop(hapd, sta);
1849
1850 /*
1851 * Make sure that the previously registered inactivity timer
1852 * will not remove the STA immediately.
1853 */
1854 sta->timeout_next = STA_NULLFUNC;
1855 } else {
1856 sta = ap_sta_add(hapd, peer);
1857 if (!sta) {
1858 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1859 goto err;
1860 }
1861 }
1862 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
1863
1864 status = owe_process_rsn_ie(hapd, sta, elems.rsn_ie,
1865 elems.rsn_ie_len, elems.owe_dh,
1866 elems.owe_dh_len);
1867 if (status != WLAN_STATUS_SUCCESS)
1868 ap_free_sta(hapd, sta);
1869
1870 return 0;
1871err:
1872 hostapd_drv_update_dh_ie(hapd, peer, status, NULL, 0);
1873 return 0;
1874}
1875#endif /* CONFIG_OWE */
1876
1877
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001878void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1879 union wpa_event_data *data)
1880{
1881 struct hostapd_data *hapd = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001882#ifndef CONFIG_NO_STDOUT_DEBUG
1883 int level = MSG_DEBUG;
1884
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001885 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001886 data->rx_mgmt.frame_len >= 24) {
1887 const struct ieee80211_hdr *hdr;
1888 u16 fc;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001889
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001890 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
1891 fc = le_to_host16(hdr->frame_control);
1892 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1893 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1894 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001895 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1896 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
1897 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001898 }
1899
1900 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
1901 event_to_string(event), event);
1902#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001903
1904 switch (event) {
1905 case EVENT_MICHAEL_MIC_FAILURE:
1906 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
1907 break;
1908 case EVENT_SCAN_RESULTS:
1909 if (hapd->iface->scan_cb)
1910 hapd->iface->scan_cb(hapd->iface);
1911 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001912 case EVENT_WPS_BUTTON_PUSHED:
1913 hostapd_wps_button_pushed(hapd, NULL);
1914 break;
1915#ifdef NEED_AP_MLME
1916 case EVENT_TX_STATUS:
1917 switch (data->tx_status.type) {
1918 case WLAN_FC_TYPE_MGMT:
1919 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
1920 data->tx_status.data_len,
1921 data->tx_status.stype,
1922 data->tx_status.ack);
1923 break;
1924 case WLAN_FC_TYPE_DATA:
1925 hostapd_tx_status(hapd, data->tx_status.dst,
1926 data->tx_status.data,
1927 data->tx_status.data_len,
1928 data->tx_status.ack);
1929 break;
1930 }
1931 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001932 case EVENT_EAPOL_TX_STATUS:
1933 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
1934 data->eapol_tx_status.data,
1935 data->eapol_tx_status.data_len,
1936 data->eapol_tx_status.ack);
1937 break;
1938 case EVENT_DRIVER_CLIENT_POLL_OK:
1939 hostapd_client_poll_ok(hapd, data->client_poll.addr);
1940 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001941 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001942 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
1943 data->rx_from_unknown.addr,
1944 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001945 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001946#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001947 case EVENT_RX_MGMT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001948 if (!data->rx_mgmt.frame)
1949 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001950#ifdef NEED_AP_MLME
Hai Shalom021b0b52019-04-10 11:17:58 -07001951 hostapd_mgmt_rx(hapd, &data->rx_mgmt);
1952#else /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001953 hostapd_action_rx(hapd, &data->rx_mgmt);
Hai Shalom021b0b52019-04-10 11:17:58 -07001954#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001955 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001956 case EVENT_RX_PROBE_REQ:
1957 if (data->rx_probe_req.sa == NULL ||
1958 data->rx_probe_req.ie == NULL)
1959 break;
1960 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001961 data->rx_probe_req.da,
1962 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001963 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001964 data->rx_probe_req.ie_len,
1965 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001966 break;
1967 case EVENT_NEW_STA:
1968 hostapd_event_new_sta(hapd, data->new_sta.addr);
1969 break;
1970 case EVENT_EAPOL_RX:
1971 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1972 data->eapol_rx.data,
Sunil8cd6f4d2022-06-28 18:40:46 +00001973 data->eapol_rx.data_len,
1974 data->eapol_rx.encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001975 break;
1976 case EVENT_ASSOC:
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001977 if (!data)
1978 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001979 hostapd_notif_assoc(hapd, data->assoc_info.addr,
1980 data->assoc_info.req_ies,
1981 data->assoc_info.req_ies_len,
1982 data->assoc_info.reassoc);
1983 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07001984#ifdef CONFIG_OWE
1985 case EVENT_UPDATE_DH:
1986 if (!data)
1987 return;
1988 hostapd_notif_update_dh_ie(hapd, data->update_dh.peer,
1989 data->update_dh.ie,
1990 data->update_dh.ie_len);
1991 break;
1992#endif /* CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001993 case EVENT_DISASSOC:
1994 if (data)
1995 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1996 break;
1997 case EVENT_DEAUTH:
1998 if (data)
1999 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
2000 break;
2001 case EVENT_STATION_LOW_ACK:
2002 if (!data)
2003 break;
2004 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
2005 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002006 case EVENT_AUTH:
2007 hostapd_notif_auth(hapd, &data->auth);
2008 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07002009 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07002010 case EVENT_CH_SWITCH:
2011 if (!data)
2012 break;
2013 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
2014 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08002015 data->ch_switch.ch_offset,
2016 data->ch_switch.ch_width,
2017 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07002018 data->ch_switch.cf2,
2019 event == EVENT_CH_SWITCH);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002020 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08002021 case EVENT_CONNECT_FAILED_REASON:
2022 if (!data)
2023 break;
2024 hostapd_event_connect_failed_reason(
2025 hapd, data->connect_failed_reason.addr,
2026 data->connect_failed_reason.code);
2027 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002028 case EVENT_SURVEY:
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002029 hostapd_event_get_survey(hapd->iface, &data->survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002030 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002031#ifdef NEED_AP_MLME
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002032 case EVENT_INTERFACE_UNAVAILABLE:
2033 hostapd_event_iface_unavailable(hapd);
2034 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002035 case EVENT_DFS_RADAR_DETECTED:
2036 if (!data)
2037 break;
2038 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
2039 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002040 case EVENT_DFS_PRE_CAC_EXPIRED:
2041 if (!data)
2042 break;
2043 hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
2044 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002045 case EVENT_DFS_CAC_FINISHED:
2046 if (!data)
2047 break;
2048 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
2049 break;
2050 case EVENT_DFS_CAC_ABORTED:
2051 if (!data)
2052 break;
2053 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
2054 break;
2055 case EVENT_DFS_NOP_FINISHED:
2056 if (!data)
2057 break;
2058 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
2059 break;
2060 case EVENT_CHANNEL_LIST_CHANGED:
2061 /* channel list changed (regulatory?), update channel list */
2062 /* TODO: check this. hostapd_get_hw_features() initializes
2063 * too much stuff. */
2064 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002065 hostapd_channel_list_updated(
2066 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002067 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002068 case EVENT_DFS_CAC_STARTED:
2069 if (!data)
2070 break;
2071 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
2072 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002073#endif /* NEED_AP_MLME */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002074 case EVENT_INTERFACE_ENABLED:
2075 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002076 if (hapd->disabled && hapd->started) {
2077 hapd->disabled = 0;
2078 /*
2079 * Try to re-enable interface if the driver stopped it
2080 * when the interface got disabled.
2081 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07002082 if (hapd->wpa_auth)
2083 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
2084 else
2085 hostapd_reconfig_encryption(hapd);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002086 hapd->reenable_beacon = 1;
2087 ieee802_11_set_beacon(hapd);
Hai Shalom74f70d42019-02-11 14:42:39 -08002088#ifdef NEED_AP_MLME
2089 } else if (hapd->disabled && hapd->iface->cac_started) {
2090 wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC");
2091 hostapd_handle_dfs(hapd->iface);
2092#endif /* NEED_AP_MLME */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002093 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002094 break;
2095 case EVENT_INTERFACE_DISABLED:
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002096 hostapd_free_stas(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002097 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002098 hapd->disabled = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002099 break;
2100#ifdef CONFIG_ACS
2101 case EVENT_ACS_CHANNEL_SELECTED:
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002102 hostapd_acs_channel_selected(hapd,
2103 &data->acs_selected_channels);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002104 break;
2105#endif /* CONFIG_ACS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002106 case EVENT_STATION_OPMODE_CHANGED:
2107 hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr,
2108 data->sta_opmode.smps_mode,
2109 data->sta_opmode.chan_width,
2110 data->sta_opmode.rx_nss);
2111 break;
2112 case EVENT_WDS_STA_INTERFACE_STATUS:
2113 hostapd_event_wds_sta_interface_status(
2114 hapd, data->wds_sta_interface.istatus,
2115 data->wds_sta_interface.ifname,
2116 data->wds_sta_interface.sta_addr);
2117 break;
Sunil Ravia04bd252022-05-02 22:54:18 -07002118#ifdef CONFIG_IEEE80211AX
2119 case EVENT_BSS_COLOR_COLLISION:
2120 /* The BSS color is shared amongst all BBSs on a specific phy.
2121 * Therefore we always start the color change on the primary
2122 * BSS. */
2123 wpa_printf(MSG_DEBUG, "BSS color collision on %s",
2124 hapd->conf->iface);
2125 hostapd_switch_color(hapd->iface->bss[0],
2126 data->bss_color_collision.bitmap);
2127 break;
2128 case EVENT_CCA_STARTED_NOTIFY:
2129 wpa_printf(MSG_DEBUG, "CCA started on on %s",
2130 hapd->conf->iface);
2131 break;
2132 case EVENT_CCA_ABORTED_NOTIFY:
2133 wpa_printf(MSG_DEBUG, "CCA aborted on on %s",
2134 hapd->conf->iface);
2135 hostapd_cleanup_cca_params(hapd);
2136 break;
2137 case EVENT_CCA_NOTIFY:
2138 wpa_printf(MSG_DEBUG, "CCA finished on on %s",
2139 hapd->conf->iface);
2140 hapd->iface->conf->he_op.he_bss_color = hapd->cca_color;
2141 hostapd_cleanup_cca_params(hapd);
2142 break;
2143#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002144 default:
2145 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
2146 break;
2147 }
2148}
2149
Dmitry Shmidte4663042016-04-04 10:07:49 -07002150
2151void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
2152 union wpa_event_data *data)
2153{
2154 struct hapd_interfaces *interfaces = ctx;
2155 struct hostapd_data *hapd;
2156
2157 if (event != EVENT_INTERFACE_STATUS)
2158 return;
2159
2160 hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
2161 if (hapd && hapd->driver && hapd->driver->get_ifindex &&
2162 hapd->drv_priv) {
2163 unsigned int ifindex;
2164
2165 ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
2166 if (ifindex != data->interface_status.ifindex) {
2167 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
2168 "interface status ifindex %d mismatch (%d)",
2169 ifindex, data->interface_status.ifindex);
2170 return;
2171 }
2172 }
2173 if (hapd)
2174 wpa_supplicant_event(hapd, event, data);
2175}
2176
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002177#endif /* HOSTAPD */