Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / Callback functions for driver wrappers |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3 | * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "utils/includes.h" |
| 10 | |
| 11 | #include "utils/common.h" |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 12 | #include "utils/eloop.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13 | #include "radius/radius.h" |
| 14 | #include "drivers/driver.h" |
| 15 | #include "common/ieee802_11_defs.h" |
| 16 | #include "common/ieee802_11_common.h" |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 17 | #include "common/wpa_ctrl.h" |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 18 | #include "common/dpp.h" |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 19 | #include "common/sae.h" |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 20 | #include "common/hw_features_common.h" |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 21 | #include "common/nan_de.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 22 | #include "crypto/random.h" |
| 23 | #include "p2p/p2p.h" |
| 24 | #include "wps/wps.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 25 | #include "fst/fst.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 26 | #include "wnm_ap.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 27 | #include "hostapd.h" |
| 28 | #include "ieee802_11.h" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 29 | #include "ieee802_11_auth.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 30 | #include "sta_info.h" |
| 31 | #include "accounting.h" |
| 32 | #include "tkip_countermeasures.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 33 | #include "ieee802_1x.h" |
| 34 | #include "wpa_auth.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 35 | #include "wps_hostapd.h" |
| 36 | #include "ap_drv_ops.h" |
| 37 | #include "ap_config.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 38 | #include "ap_mlme.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 39 | #include "hw_features.h" |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 40 | #include "dfs.h" |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 41 | #include "beacon.h" |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 42 | #include "mbo_ap.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 43 | #include "dpp_hostapd.h" |
| 44 | #include "fils_hlp.h" |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 45 | #include "neighbor_db.h" |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 46 | #include "nan_usd_ap.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 47 | |
| 48 | |
| 49 | #ifdef CONFIG_FILS |
| 50 | void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd, |
| 51 | struct sta_info *sta) |
| 52 | { |
| 53 | u16 reply_res = WLAN_STATUS_SUCCESS; |
| 54 | struct ieee802_11_elems elems; |
| 55 | u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf; |
| 56 | int new_assoc; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 57 | bool updated; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 58 | |
| 59 | wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR, |
| 60 | __func__, MAC2STR(sta->addr)); |
| 61 | eloop_cancel_timeout(fils_hlp_timeout, hapd, sta); |
| 62 | if (!sta->fils_pending_assoc_req) |
| 63 | return; |
| 64 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 65 | if (ieee802_11_parse_elems(sta->fils_pending_assoc_req, |
| 66 | sta->fils_pending_assoc_req_len, &elems, |
| 67 | 0) == ParseFailed || |
| 68 | !elems.fils_session) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 69 | wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element", |
| 70 | __func__); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p, |
| 75 | elems.fils_session, |
| 76 | sta->fils_hlp_resp); |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 77 | if (!p) |
| 78 | return; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 79 | |
| 80 | reply_res = hostapd_sta_assoc(hapd, sta->addr, |
| 81 | sta->fils_pending_assoc_is_reassoc, |
| 82 | WLAN_STATUS_SUCCESS, |
| 83 | buf, p - buf); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 84 | updated = ap_sta_set_authorized_flag(hapd, sta, 1); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 85 | new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0; |
| 86 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC; |
| 87 | sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; |
| 88 | hostapd_set_sta_flags(hapd, sta); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 89 | if (updated) |
| 90 | ap_sta_set_authorized_event(hapd, sta, 1); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 91 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS); |
| 92 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); |
| 93 | hostapd_new_assoc_sta(hapd, sta, !new_assoc); |
| 94 | os_free(sta->fils_pending_assoc_req); |
| 95 | sta->fils_pending_assoc_req = NULL; |
| 96 | sta->fils_pending_assoc_req_len = 0; |
| 97 | wpabuf_free(sta->fils_hlp_resp); |
| 98 | sta->fils_hlp_resp = NULL; |
| 99 | wpabuf_free(sta->hlp_dhcp_discover); |
| 100 | sta->hlp_dhcp_discover = NULL; |
| 101 | fils_hlp_deinit(hapd); |
| 102 | |
| 103 | /* |
| 104 | * Remove the station in case transmission of a success response fails |
| 105 | * (the STA was added associated to the driver) or if the station was |
| 106 | * previously added unassociated. |
| 107 | */ |
| 108 | if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) { |
| 109 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 110 | sta->added_unassoc = 0; |
| 111 | } |
| 112 | } |
| 113 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 114 | |
| 115 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 116 | static bool check_sa_query_need(struct hostapd_data *hapd, struct sta_info *sta) |
| 117 | { |
| 118 | if ((sta->flags & |
| 119 | (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED)) != |
| 120 | (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED)) |
| 121 | return false; |
| 122 | |
| 123 | if (!sta->sa_query_timed_out && sta->sa_query_count > 0) |
| 124 | ap_check_sa_query_timeout(hapd, sta); |
| 125 | |
| 126 | if (!sta->sa_query_timed_out && (sta->auth_alg != WLAN_AUTH_FT)) { |
| 127 | /* |
| 128 | * STA has already been associated with MFP and SA Query timeout |
| 129 | * has not been reached. Reject the association attempt |
| 130 | * temporarily and start SA Query, if one is not pending. |
| 131 | */ |
| 132 | if (sta->sa_query_count == 0) |
| 133 | ap_sta_start_sa_query(hapd, sta); |
| 134 | |
| 135 | return true; |
| 136 | } |
| 137 | |
| 138 | return false; |
| 139 | } |
| 140 | |
| 141 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 142 | #ifdef CONFIG_IEEE80211BE |
| 143 | static int hostapd_update_sta_links_status(struct hostapd_data *hapd, |
| 144 | struct sta_info *sta, |
| 145 | const u8 *resp_ies, |
| 146 | size_t resp_ies_len) |
| 147 | { |
| 148 | struct mld_info *info = &sta->mld_info; |
| 149 | struct wpabuf *mlebuf; |
| 150 | const u8 *mle, *pos; |
| 151 | struct ieee802_11_elems elems; |
| 152 | size_t mle_len, rem_len; |
| 153 | int ret = 0; |
| 154 | |
| 155 | if (!resp_ies) { |
| 156 | wpa_printf(MSG_DEBUG, |
| 157 | "MLO: (Re)Association Response frame elements not available"); |
| 158 | return -1; |
| 159 | } |
| 160 | |
| 161 | if (ieee802_11_parse_elems(resp_ies, resp_ies_len, &elems, 0) == |
| 162 | ParseFailed) { |
| 163 | wpa_printf(MSG_DEBUG, |
| 164 | "MLO: Failed to parse (Re)Association Response frame elements"); |
| 165 | return -1; |
| 166 | } |
| 167 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 168 | mlebuf = ieee802_11_defrag(elems.basic_mle, elems.basic_mle_len, true); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 169 | if (!mlebuf) { |
| 170 | wpa_printf(MSG_ERROR, |
| 171 | "MLO: Basic Multi-Link element not found in (Re)Association Response frame"); |
| 172 | return -1; |
| 173 | } |
| 174 | |
| 175 | mle = wpabuf_head(mlebuf); |
| 176 | mle_len = wpabuf_len(mlebuf); |
| 177 | if (mle_len < MULTI_LINK_CONTROL_LEN + 1 || |
| 178 | mle_len - MULTI_LINK_CONTROL_LEN < mle[MULTI_LINK_CONTROL_LEN]) { |
| 179 | wpa_printf(MSG_ERROR, |
| 180 | "MLO: Invalid Multi-Link element in (Re)Association Response frame"); |
| 181 | ret = -1; |
| 182 | goto out; |
| 183 | } |
| 184 | |
| 185 | /* Skip Common Info */ |
| 186 | pos = mle + MULTI_LINK_CONTROL_LEN + mle[MULTI_LINK_CONTROL_LEN]; |
| 187 | rem_len = mle_len - |
| 188 | (MULTI_LINK_CONTROL_LEN + mle[MULTI_LINK_CONTROL_LEN]); |
| 189 | |
| 190 | /* Parse Subelements */ |
| 191 | while (rem_len > 2) { |
| 192 | size_t ie_len = 2 + pos[1]; |
| 193 | |
| 194 | if (rem_len < ie_len) |
| 195 | break; |
| 196 | |
| 197 | if (pos[0] == MULTI_LINK_SUB_ELEM_ID_PER_STA_PROFILE) { |
| 198 | u8 link_id; |
| 199 | const u8 *sta_profile; |
| 200 | size_t sta_profile_len; |
| 201 | u16 sta_ctrl; |
| 202 | |
| 203 | if (pos[1] < BASIC_MLE_STA_CTRL_LEN + 1) { |
| 204 | wpa_printf(MSG_DEBUG, |
| 205 | "MLO: Invalid per-STA profile IE"); |
| 206 | goto next_subelem; |
| 207 | } |
| 208 | |
| 209 | sta_profile_len = pos[1]; |
| 210 | sta_profile = &pos[2]; |
| 211 | sta_ctrl = WPA_GET_LE16(sta_profile); |
| 212 | link_id = sta_ctrl & BASIC_MLE_STA_CTRL_LINK_ID_MASK; |
| 213 | if (link_id >= MAX_NUM_MLD_LINKS) { |
| 214 | wpa_printf(MSG_DEBUG, |
| 215 | "MLO: Invalid link ID in per-STA profile IE"); |
| 216 | goto next_subelem; |
| 217 | } |
| 218 | |
| 219 | /* Skip STA Control and STA Info */ |
| 220 | if (sta_profile_len - BASIC_MLE_STA_CTRL_LEN < |
| 221 | sta_profile[BASIC_MLE_STA_CTRL_LEN]) { |
| 222 | wpa_printf(MSG_DEBUG, |
| 223 | "MLO: Invalid STA info in per-STA profile IE"); |
| 224 | goto next_subelem; |
| 225 | } |
| 226 | |
| 227 | sta_profile_len = sta_profile_len - |
| 228 | (BASIC_MLE_STA_CTRL_LEN + |
| 229 | sta_profile[BASIC_MLE_STA_CTRL_LEN]); |
| 230 | sta_profile = sta_profile + BASIC_MLE_STA_CTRL_LEN + |
| 231 | sta_profile[BASIC_MLE_STA_CTRL_LEN]; |
| 232 | |
| 233 | /* Skip Capabilities Information field */ |
| 234 | if (sta_profile_len < 2) |
| 235 | goto next_subelem; |
| 236 | sta_profile_len -= 2; |
| 237 | sta_profile += 2; |
| 238 | |
| 239 | /* Get status of the link */ |
| 240 | info->links[link_id].status = WPA_GET_LE16(sta_profile); |
| 241 | } |
| 242 | next_subelem: |
| 243 | pos += ie_len; |
| 244 | rem_len -= ie_len; |
| 245 | } |
| 246 | |
| 247 | out: |
| 248 | wpabuf_free(mlebuf); |
| 249 | return ret; |
| 250 | } |
| 251 | #endif /* CONFIG_IEEE80211BE */ |
| 252 | |
| 253 | |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 254 | #if defined(HOSTAPD) || defined(CONFIG_IEEE80211BE) |
| 255 | static struct hostapd_data * hostapd_find_by_sta(struct hostapd_iface *iface, |
| 256 | const u8 *src, bool rsn, |
| 257 | struct sta_info **sta_ret) |
| 258 | { |
| 259 | struct hostapd_data *hapd; |
| 260 | struct sta_info *sta; |
| 261 | unsigned int j; |
| 262 | |
| 263 | if (sta_ret) |
| 264 | *sta_ret = NULL; |
| 265 | |
| 266 | for (j = 0; j < iface->num_bss; j++) { |
| 267 | hapd = iface->bss[j]; |
| 268 | sta = ap_get_sta(hapd, src); |
| 269 | if (sta && (sta->flags & WLAN_STA_ASSOC) && |
| 270 | (!rsn || sta->wpa_sm)) { |
| 271 | if (sta_ret) |
| 272 | *sta_ret = sta; |
| 273 | return hapd; |
| 274 | } |
| 275 | #ifdef CONFIG_IEEE80211BE |
| 276 | if (hapd->conf->mld_ap) { |
| 277 | struct hostapd_data *p_hapd; |
| 278 | |
| 279 | for_each_mld_link(p_hapd, hapd) { |
| 280 | if (p_hapd == hapd) |
| 281 | continue; |
| 282 | |
| 283 | sta = ap_get_sta(p_hapd, src); |
| 284 | if (sta && (sta->flags & WLAN_STA_ASSOC) && |
| 285 | (!rsn || sta->wpa_sm)) { |
| 286 | if (sta_ret) |
| 287 | *sta_ret = sta; |
| 288 | return p_hapd; |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | #endif /* CONFIG_IEEE80211BE */ |
| 293 | } |
| 294 | |
| 295 | return NULL; |
| 296 | } |
| 297 | #endif /* HOSTAPD || CONFIG_IEEE80211BE */ |
| 298 | |
| 299 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 300 | int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 301 | const u8 *req_ies, size_t req_ies_len, |
| 302 | const u8 *resp_ies, size_t resp_ies_len, |
| 303 | const u8 *link_addr, int reassoc) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 304 | { |
| 305 | struct sta_info *sta; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 306 | int new_assoc; |
| 307 | enum wpa_validate_result res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 308 | struct ieee802_11_elems elems; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 309 | const u8 *ie; |
| 310 | size_t ielen; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 311 | u8 buf[sizeof(struct ieee80211_mgmt) + 1024]; |
| 312 | u8 *p = buf; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 313 | u16 reason = WLAN_REASON_UNSPECIFIED; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 314 | int status = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 315 | const u8 *p2p_dev_addr = NULL; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 316 | #ifdef CONFIG_OWE |
| 317 | struct hostapd_iface *iface = hapd->iface; |
| 318 | #endif /* CONFIG_OWE */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 319 | bool updated = false; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 320 | |
| 321 | if (addr == NULL) { |
| 322 | /* |
| 323 | * This could potentially happen with unexpected event from the |
| 324 | * driver wrapper. This was seen at least in one case where the |
| 325 | * driver ended up being set to station mode while hostapd was |
| 326 | * running, so better make sure we stop processing such an |
| 327 | * event here. |
| 328 | */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 329 | wpa_printf(MSG_DEBUG, |
| 330 | "hostapd_notif_assoc: Skip event with no address"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 331 | return -1; |
| 332 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 333 | |
| 334 | if (is_multicast_ether_addr(addr) || |
| 335 | is_zero_ether_addr(addr) || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 336 | ether_addr_equal(addr, hapd->own_addr)) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 337 | /* Do not process any frames with unexpected/invalid SA so that |
| 338 | * we do not add any state for unexpected STA addresses or end |
| 339 | * up sending out frames to unexpected destination. */ |
| 340 | wpa_printf(MSG_DEBUG, "%s: Invalid SA=" MACSTR |
| 341 | " in received indication - ignore this indication silently", |
| 342 | __func__, MAC2STR(addr)); |
| 343 | return 0; |
| 344 | } |
| 345 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 346 | random_add_randomness(addr, ETH_ALEN); |
| 347 | |
| 348 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
| 349 | HOSTAPD_LEVEL_INFO, "associated"); |
| 350 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 351 | if (ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0) == |
| 352 | ParseFailed) { |
| 353 | wpa_printf(MSG_DEBUG, "%s: Could not parse elements", __func__); |
| 354 | return -1; |
| 355 | } |
| 356 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 357 | if (elems.wps_ie) { |
| 358 | ie = elems.wps_ie - 2; |
| 359 | ielen = elems.wps_ie_len + 2; |
| 360 | wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq"); |
| 361 | } else if (elems.rsn_ie) { |
| 362 | ie = elems.rsn_ie - 2; |
| 363 | ielen = elems.rsn_ie_len + 2; |
| 364 | wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq"); |
| 365 | } else if (elems.wpa_ie) { |
| 366 | ie = elems.wpa_ie - 2; |
| 367 | ielen = elems.wpa_ie_len + 2; |
| 368 | wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq"); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 369 | #ifdef CONFIG_HS20 |
| 370 | } else if (elems.osen) { |
| 371 | ie = elems.osen - 2; |
| 372 | ielen = elems.osen_len + 2; |
| 373 | wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq"); |
| 374 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 375 | } else { |
| 376 | ie = NULL; |
| 377 | ielen = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 378 | wpa_printf(MSG_DEBUG, |
| 379 | "STA did not include WPS/RSN/WPA IE in (Re)AssocReq"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | sta = ap_get_sta(hapd, addr); |
| 383 | if (sta) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 384 | ap_sta_no_session_timeout(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 385 | accounting_sta_stop(hapd, sta); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 386 | |
| 387 | /* |
| 388 | * Make sure that the previously registered inactivity timer |
| 389 | * will not remove the STA immediately. |
| 390 | */ |
| 391 | sta->timeout_next = STA_NULLFUNC; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 392 | } else { |
| 393 | sta = ap_sta_add(hapd, addr); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 394 | if (sta == NULL) { |
| 395 | hostapd_drv_sta_disassoc(hapd, addr, |
| 396 | WLAN_REASON_DISASSOC_AP_BUSY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 397 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 398 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 399 | } |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 400 | |
| 401 | if (hapd->conf->wpa && check_sa_query_need(hapd, sta)) { |
| 402 | status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; |
| 403 | p = hostapd_eid_assoc_comeback_time(hapd, sta, p); |
| 404 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf); |
| 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | #ifdef CONFIG_IEEE80211BE |
| 410 | if (link_addr) { |
| 411 | struct mld_info *info = &sta->mld_info; |
| 412 | int i, num_valid_links = 0; |
| 413 | u8 link_id = hapd->mld_link_id; |
| 414 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 415 | ap_sta_set_mld(sta, true); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 416 | sta->mld_assoc_link_id = link_id; |
| 417 | os_memcpy(info->common_info.mld_addr, addr, ETH_ALEN); |
| 418 | info->links[link_id].valid = true; |
| 419 | os_memcpy(info->links[link_id].peer_addr, link_addr, ETH_ALEN); |
| 420 | os_memcpy(info->links[link_id].local_addr, hapd->own_addr, |
| 421 | ETH_ALEN); |
| 422 | |
| 423 | if (!elems.basic_mle || |
| 424 | hostapd_process_ml_assoc_req(hapd, &elems, sta) != |
| 425 | WLAN_STATUS_SUCCESS) { |
| 426 | reason = WLAN_REASON_UNSPECIFIED; |
| 427 | wpa_printf(MSG_DEBUG, |
| 428 | "Failed to get STA non-assoc links info"); |
| 429 | goto fail; |
| 430 | } |
| 431 | |
| 432 | for (i = 0 ; i < MAX_NUM_MLD_LINKS; i++) { |
| 433 | if (info->links[i].valid) |
| 434 | num_valid_links++; |
| 435 | } |
| 436 | if (num_valid_links > 1 && |
| 437 | hostapd_update_sta_links_status(hapd, sta, resp_ies, |
| 438 | resp_ies_len)) { |
| 439 | wpa_printf(MSG_DEBUG, |
| 440 | "Failed to get STA non-assoc links status info"); |
| 441 | reason = WLAN_REASON_UNSPECIFIED; |
| 442 | goto fail; |
| 443 | } |
| 444 | } |
| 445 | #endif /* CONFIG_IEEE80211BE */ |
| 446 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 447 | sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 448 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 449 | /* |
| 450 | * ACL configurations to the drivers (implementing AP SME and ACL |
| 451 | * offload) without hostapd's knowledge, can result in a disconnection |
| 452 | * though the driver accepts the connection. Skip the hostapd check for |
| 453 | * ACL if the driver supports ACL offload to avoid potentially |
| 454 | * conflicting ACL rules. |
| 455 | */ |
| 456 | if (hapd->iface->drv_max_acl_mac_addrs == 0 && |
| 457 | hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 458 | wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect", |
| 459 | MAC2STR(addr)); |
| 460 | reason = WLAN_REASON_UNSPECIFIED; |
| 461 | goto fail; |
| 462 | } |
| 463 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 464 | #ifdef CONFIG_P2P |
| 465 | if (elems.p2p) { |
| 466 | wpabuf_free(sta->p2p_ie); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 467 | sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 468 | P2P_IE_VENDOR_TYPE); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 469 | if (sta->p2p_ie) |
| 470 | p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 471 | } |
| 472 | #endif /* CONFIG_P2P */ |
| 473 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 474 | #ifdef NEED_AP_MLME |
| 475 | if (elems.ht_capabilities && |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 476 | (hapd->iface->conf->ht_capab & |
| 477 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) { |
| 478 | struct ieee80211_ht_capabilities *ht_cap = |
| 479 | (struct ieee80211_ht_capabilities *) |
| 480 | elems.ht_capabilities; |
| 481 | |
| 482 | if (le_to_host16(ht_cap->ht_capabilities_info) & |
| 483 | HT_CAP_INFO_40MHZ_INTOLERANT) |
| 484 | ht40_intolerant_add(hapd->iface, sta); |
| 485 | } |
| 486 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 487 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 488 | check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 489 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 490 | #ifdef CONFIG_HS20 |
| 491 | wpabuf_free(sta->hs20_ie); |
| 492 | if (elems.hs20 && elems.hs20_len > 4) { |
| 493 | sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4, |
| 494 | elems.hs20_len - 4); |
| 495 | } else |
| 496 | sta->hs20_ie = NULL; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 497 | |
| 498 | wpabuf_free(sta->roaming_consortium); |
| 499 | if (elems.roaming_cons_sel) |
| 500 | sta->roaming_consortium = wpabuf_alloc_copy( |
| 501 | elems.roaming_cons_sel + 4, |
| 502 | elems.roaming_cons_sel_len - 4); |
| 503 | else |
| 504 | sta->roaming_consortium = NULL; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 505 | #endif /* CONFIG_HS20 */ |
| 506 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 507 | #ifdef CONFIG_FST |
| 508 | wpabuf_free(sta->mb_ies); |
| 509 | if (hapd->iface->fst) |
| 510 | sta->mb_ies = mb_ies_by_info(&elems.mb_ies); |
| 511 | else |
| 512 | sta->mb_ies = NULL; |
| 513 | #endif /* CONFIG_FST */ |
| 514 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 515 | mbo_ap_check_sta_assoc(hapd, sta, &elems); |
| 516 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 517 | ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes, |
| 518 | elems.supp_op_classes_len); |
| 519 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 520 | if (hapd->conf->wpa) { |
| 521 | if (ie == NULL || ielen == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 522 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 523 | if (hapd->conf->wps_state) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 524 | wpa_printf(MSG_DEBUG, |
| 525 | "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 526 | sta->flags |= WLAN_STA_MAYBE_WPS; |
| 527 | goto skip_wpa_check; |
| 528 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 529 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 530 | |
| 531 | wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 532 | reason = WLAN_REASON_INVALID_IE; |
| 533 | status = WLAN_STATUS_INVALID_IE; |
| 534 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 535 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 536 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 537 | if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 && |
| 538 | os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 539 | struct wpabuf *wps; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 540 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 541 | sta->flags |= WLAN_STA_WPS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 542 | wps = ieee802_11_vendor_ie_concat(ie, ielen, |
| 543 | WPS_IE_VENDOR_TYPE); |
| 544 | if (wps) { |
| 545 | if (wps_is_20(wps)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 546 | wpa_printf(MSG_DEBUG, |
| 547 | "WPS: STA supports WPS 2.0"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 548 | sta->flags |= WLAN_STA_WPS2; |
| 549 | } |
| 550 | wpabuf_free(wps); |
| 551 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 552 | goto skip_wpa_check; |
| 553 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 554 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 555 | |
| 556 | if (sta->wpa_sm == NULL) |
| 557 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 558 | sta->addr, |
| 559 | p2p_dev_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 560 | if (sta->wpa_sm == NULL) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 561 | wpa_printf(MSG_ERROR, |
| 562 | "Failed to initialize WPA state machine"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 563 | return -1; |
| 564 | } |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 565 | wpa_auth_set_rsn_selection(sta->wpa_sm, elems.rsn_selection, |
| 566 | elems.rsn_selection_len); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 567 | #ifdef CONFIG_IEEE80211BE |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 568 | if (ap_sta_is_mld(hapd, sta)) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 569 | wpa_printf(MSG_DEBUG, |
| 570 | "MLD: Set ML info in RSN Authenticator"); |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 571 | wpa_auth_set_ml_info(sta->wpa_sm, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 572 | sta->mld_assoc_link_id, |
| 573 | &sta->mld_info); |
| 574 | } |
| 575 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 576 | res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 577 | hapd->iface->freq, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 578 | ie, ielen, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 579 | elems.rsnxe ? elems.rsnxe - 2 : NULL, |
| 580 | elems.rsnxe ? elems.rsnxe_len + 2 : 0, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 581 | elems.mdie, elems.mdie_len, |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 582 | elems.owe_dh, elems.owe_dh_len, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 583 | reason = WLAN_REASON_INVALID_IE; |
| 584 | status = WLAN_STATUS_INVALID_IE; |
| 585 | switch (res) { |
| 586 | case WPA_IE_OK: |
| 587 | reason = WLAN_REASON_UNSPECIFIED; |
| 588 | status = WLAN_STATUS_SUCCESS; |
| 589 | break; |
| 590 | case WPA_INVALID_IE: |
| 591 | reason = WLAN_REASON_INVALID_IE; |
| 592 | status = WLAN_STATUS_INVALID_IE; |
| 593 | break; |
| 594 | case WPA_INVALID_GROUP: |
| 595 | reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID; |
| 596 | status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID; |
| 597 | break; |
| 598 | case WPA_INVALID_PAIRWISE: |
| 599 | reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID; |
| 600 | status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID; |
| 601 | break; |
| 602 | case WPA_INVALID_AKMP: |
| 603 | reason = WLAN_REASON_AKMP_NOT_VALID; |
| 604 | status = WLAN_STATUS_AKMP_NOT_VALID; |
| 605 | break; |
| 606 | case WPA_NOT_ENABLED: |
| 607 | reason = WLAN_REASON_INVALID_IE; |
| 608 | status = WLAN_STATUS_INVALID_IE; |
| 609 | break; |
| 610 | case WPA_ALLOC_FAIL: |
| 611 | reason = WLAN_REASON_UNSPECIFIED; |
| 612 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 613 | break; |
| 614 | case WPA_MGMT_FRAME_PROTECTION_VIOLATION: |
| 615 | reason = WLAN_REASON_INVALID_IE; |
| 616 | status = WLAN_STATUS_INVALID_IE; |
| 617 | break; |
| 618 | case WPA_INVALID_MGMT_GROUP_CIPHER: |
| 619 | reason = WLAN_REASON_CIPHER_SUITE_REJECTED; |
| 620 | status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY; |
| 621 | break; |
| 622 | case WPA_INVALID_MDIE: |
| 623 | reason = WLAN_REASON_INVALID_MDE; |
| 624 | status = WLAN_STATUS_INVALID_MDIE; |
| 625 | break; |
| 626 | case WPA_INVALID_PROTO: |
| 627 | reason = WLAN_REASON_INVALID_IE; |
| 628 | status = WLAN_STATUS_INVALID_IE; |
| 629 | break; |
| 630 | case WPA_INVALID_PMKID: |
| 631 | reason = WLAN_REASON_INVALID_PMKID; |
| 632 | status = WLAN_STATUS_INVALID_PMKID; |
| 633 | break; |
| 634 | case WPA_DENIED_OTHER_REASON: |
| 635 | reason = WLAN_REASON_UNSPECIFIED; |
| 636 | status = WLAN_STATUS_ASSOC_DENIED_UNSPEC; |
| 637 | break; |
| 638 | } |
| 639 | if (status != WLAN_STATUS_SUCCESS) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 640 | wpa_printf(MSG_DEBUG, |
| 641 | "WPA/RSN information element rejected? (res %u)", |
| 642 | res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 643 | wpa_hexdump(MSG_DEBUG, "IE", ie, ielen); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 644 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 645 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 646 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 647 | if (wpa_auth_uses_mfp(sta->wpa_sm)) |
| 648 | sta->flags |= WLAN_STA_MFP; |
| 649 | else |
| 650 | sta->flags &= ~WLAN_STA_MFP; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 651 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 652 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 653 | if (sta->auth_alg == WLAN_AUTH_FT) { |
| 654 | status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies, |
| 655 | req_ies_len); |
| 656 | if (status != WLAN_STATUS_SUCCESS) { |
| 657 | if (status == WLAN_STATUS_INVALID_PMKID) |
| 658 | reason = WLAN_REASON_INVALID_IE; |
| 659 | if (status == WLAN_STATUS_INVALID_MDIE) |
| 660 | reason = WLAN_REASON_INVALID_IE; |
| 661 | if (status == WLAN_STATUS_INVALID_FTIE) |
| 662 | reason = WLAN_REASON_INVALID_IE; |
| 663 | goto fail; |
| 664 | } |
| 665 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 666 | #endif /* CONFIG_IEEE80211R_AP */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 667 | #ifdef CONFIG_SAE |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 668 | if (hapd->conf->sae_pwe == SAE_PWE_BOTH && |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 669 | sta->auth_alg == WLAN_AUTH_SAE && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 670 | sta->sae && !sta->sae->h2e && |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 671 | ieee802_11_rsnx_capab_len(elems.rsnxe, elems.rsnxe_len, |
| 672 | WLAN_RSNX_CAPAB_SAE_H2E)) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 673 | wpa_printf(MSG_INFO, "SAE: " MACSTR |
| 674 | " indicates support for SAE H2E, but did not use it", |
| 675 | MAC2STR(sta->addr)); |
| 676 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 677 | reason = WLAN_REASON_UNSPECIFIED; |
| 678 | goto fail; |
| 679 | } |
| 680 | #endif /* CONFIG_SAE */ |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 681 | |
| 682 | wpa_auth_set_ssid_protection( |
| 683 | sta->wpa_sm, |
| 684 | hapd->conf->ssid_protection && |
| 685 | ieee802_11_rsnx_capab_len( |
| 686 | elems.rsnxe, elems.rsnxe_len, |
| 687 | WLAN_RSNX_CAPAB_SSID_PROTECTION)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 688 | } else if (hapd->conf->wps_state) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 689 | #ifdef CONFIG_WPS |
| 690 | struct wpabuf *wps; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 691 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 692 | if (req_ies) |
| 693 | wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 694 | WPS_IE_VENDOR_TYPE); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 695 | else |
| 696 | wps = NULL; |
| 697 | #ifdef CONFIG_WPS_STRICT |
| 698 | if (wps && wps_validate_assoc_req(wps) < 0) { |
| 699 | reason = WLAN_REASON_INVALID_IE; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 700 | status = WLAN_STATUS_INVALID_IE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 701 | wpabuf_free(wps); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 702 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 703 | } |
| 704 | #endif /* CONFIG_WPS_STRICT */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 705 | if (wps) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 706 | sta->flags |= WLAN_STA_WPS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 707 | if (wps_is_20(wps)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 708 | wpa_printf(MSG_DEBUG, |
| 709 | "WPS: STA supports WPS 2.0"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 710 | sta->flags |= WLAN_STA_WPS2; |
| 711 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 712 | } else |
| 713 | sta->flags |= WLAN_STA_MAYBE_WPS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 714 | wpabuf_free(wps); |
| 715 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 716 | #ifdef CONFIG_HS20 |
| 717 | } else if (hapd->conf->osen) { |
| 718 | if (elems.osen == NULL) { |
| 719 | hostapd_logger( |
| 720 | hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 721 | HOSTAPD_LEVEL_INFO, |
| 722 | "No HS 2.0 OSEN element in association request"); |
| 723 | return WLAN_STATUS_INVALID_IE; |
| 724 | } |
| 725 | |
| 726 | wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association"); |
| 727 | if (sta->wpa_sm == NULL) |
| 728 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
| 729 | sta->addr, NULL); |
| 730 | if (sta->wpa_sm == NULL) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 731 | wpa_printf(MSG_WARNING, |
| 732 | "Failed to initialize WPA state machine"); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 733 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 734 | } |
| 735 | if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm, |
| 736 | elems.osen - 2, elems.osen_len + 2) < 0) |
| 737 | return WLAN_STATUS_INVALID_IE; |
| 738 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 739 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 740 | #ifdef CONFIG_WPS |
| 741 | skip_wpa_check: |
| 742 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 743 | |
| 744 | #ifdef CONFIG_MBO |
| 745 | if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) && |
| 746 | elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) && |
| 747 | hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) { |
| 748 | wpa_printf(MSG_INFO, |
| 749 | "MBO: Reject WPA2 association without PMF"); |
| 750 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 751 | } |
| 752 | #endif /* CONFIG_MBO */ |
| 753 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 754 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 755 | p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf), |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 756 | sta->auth_alg, req_ies, req_ies_len, |
| 757 | !elems.rsnxe); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 758 | if (!p) { |
| 759 | wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs"); |
| 760 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 761 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 762 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 763 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 764 | #ifdef CONFIG_FILS |
| 765 | if (sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 766 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 767 | sta->auth_alg == WLAN_AUTH_FILS_PK) { |
| 768 | int delay_assoc = 0; |
| 769 | |
| 770 | if (!req_ies) |
| 771 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 772 | |
| 773 | if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies, |
| 774 | req_ies_len, |
| 775 | sta->fils_session)) { |
| 776 | wpa_printf(MSG_DEBUG, |
| 777 | "FILS: Session validation failed"); |
| 778 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 779 | } |
| 780 | |
| 781 | res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies, |
| 782 | req_ies_len); |
| 783 | if (res < 0) { |
| 784 | wpa_printf(MSG_DEBUG, |
| 785 | "FILS: Key Confirm validation failed"); |
| 786 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 787 | } |
| 788 | |
| 789 | if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) { |
| 790 | wpa_printf(MSG_DEBUG, |
| 791 | "FILS: Delaying Assoc Response (HLP)"); |
| 792 | delay_assoc = 1; |
| 793 | } else { |
| 794 | wpa_printf(MSG_DEBUG, |
| 795 | "FILS: Going ahead with Assoc Response (no HLP)"); |
| 796 | } |
| 797 | |
| 798 | if (sta) { |
| 799 | wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup"); |
| 800 | eloop_cancel_timeout(fils_hlp_timeout, hapd, sta); |
| 801 | os_free(sta->fils_pending_assoc_req); |
| 802 | sta->fils_pending_assoc_req = NULL; |
| 803 | sta->fils_pending_assoc_req_len = 0; |
| 804 | wpabuf_free(sta->fils_hlp_resp); |
| 805 | sta->fils_hlp_resp = NULL; |
| 806 | sta->fils_drv_assoc_finish = 0; |
| 807 | } |
| 808 | |
| 809 | if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) { |
| 810 | u8 *req_tmp; |
| 811 | |
| 812 | req_tmp = os_malloc(req_ies_len); |
| 813 | if (!req_tmp) { |
| 814 | wpa_printf(MSG_DEBUG, |
| 815 | "FILS: buffer allocation failed for assoc req"); |
| 816 | goto fail; |
| 817 | } |
| 818 | os_memcpy(req_tmp, req_ies, req_ies_len); |
| 819 | sta->fils_pending_assoc_req = req_tmp; |
| 820 | sta->fils_pending_assoc_req_len = req_ies_len; |
| 821 | sta->fils_pending_assoc_is_reassoc = reassoc; |
| 822 | sta->fils_drv_assoc_finish = 1; |
| 823 | wpa_printf(MSG_DEBUG, |
| 824 | "FILS: Waiting for HLP processing before sending (Re)Association Response frame to " |
| 825 | MACSTR, MAC2STR(sta->addr)); |
| 826 | eloop_register_timeout( |
| 827 | 0, hapd->conf->fils_hlp_wait_time * 1024, |
| 828 | fils_hlp_timeout, hapd, sta); |
| 829 | return 0; |
| 830 | } |
| 831 | p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p, |
| 832 | elems.fils_session, |
| 833 | sta->fils_hlp_resp); |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 834 | if (!p) |
| 835 | goto fail; |
| 836 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 837 | wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)", |
| 838 | buf, p - buf); |
| 839 | } |
| 840 | #endif /* CONFIG_FILS */ |
| 841 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 842 | #ifdef CONFIG_OWE |
| 843 | if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) && |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 844 | !(iface->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_AP) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 845 | wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE && |
| 846 | elems.owe_dh) { |
| 847 | u8 *npos; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 848 | u16 ret_status; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 849 | |
| 850 | npos = owe_assoc_req_process(hapd, sta, |
| 851 | elems.owe_dh, elems.owe_dh_len, |
| 852 | p, sizeof(buf) - (p - buf), |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 853 | &ret_status); |
| 854 | status = ret_status; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 855 | if (npos) |
| 856 | p = npos; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 857 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 858 | if (!npos && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 859 | status == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) { |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 860 | hostapd_sta_assoc(hapd, addr, reassoc, ret_status, buf, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 861 | p - buf); |
| 862 | return 0; |
| 863 | } |
| 864 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 865 | if (!npos || status != WLAN_STATUS_SUCCESS) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 866 | goto fail; |
| 867 | } |
| 868 | #endif /* CONFIG_OWE */ |
| 869 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 870 | #ifdef CONFIG_DPP2 |
| 871 | dpp_pfs_free(sta->dpp_pfs); |
| 872 | sta->dpp_pfs = NULL; |
| 873 | |
| 874 | if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) && |
| 875 | hapd->conf->dpp_netaccesskey && sta->wpa_sm && |
| 876 | wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP && |
| 877 | elems.owe_dh) { |
| 878 | sta->dpp_pfs = dpp_pfs_init( |
| 879 | wpabuf_head(hapd->conf->dpp_netaccesskey), |
| 880 | wpabuf_len(hapd->conf->dpp_netaccesskey)); |
| 881 | if (!sta->dpp_pfs) { |
| 882 | wpa_printf(MSG_DEBUG, |
| 883 | "DPP: Could not initialize PFS"); |
| 884 | /* Try to continue without PFS */ |
| 885 | goto pfs_fail; |
| 886 | } |
| 887 | |
| 888 | if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh, |
| 889 | elems.owe_dh_len) < 0) { |
| 890 | dpp_pfs_free(sta->dpp_pfs); |
| 891 | sta->dpp_pfs = NULL; |
| 892 | reason = WLAN_REASON_UNSPECIFIED; |
| 893 | goto fail; |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ? |
| 898 | sta->dpp_pfs->secret : NULL); |
| 899 | pfs_fail: |
| 900 | #endif /* CONFIG_DPP2 */ |
| 901 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 902 | if (elems.rrm_enabled && |
| 903 | elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa)) |
| 904 | os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled, |
| 905 | sizeof(sta->rrm_enabled_capa)); |
| 906 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 907 | #if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 908 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 909 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 910 | if (sta->auth_alg == WLAN_AUTH_FT || |
| 911 | sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 912 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 913 | sta->auth_alg == WLAN_AUTH_FILS_PK) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 914 | updated = ap_sta_set_authorized_flag(hapd, sta, 1); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 915 | #else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 916 | /* Keep compiler silent about unused variables */ |
| 917 | if (status) { |
| 918 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 919 | #endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 920 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 921 | #ifdef CONFIG_IEEE80211BE |
| 922 | if (hostapd_process_assoc_ml_info(hapd, sta, req_ies, req_ies_len, |
| 923 | !!reassoc, WLAN_STATUS_SUCCESS, |
| 924 | true)) { |
| 925 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 926 | reason = WLAN_REASON_UNSPECIFIED; |
| 927 | goto fail; |
| 928 | } |
| 929 | #endif /* CONFIG_IEEE80211BE */ |
| 930 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 931 | new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0; |
| 932 | sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 933 | sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 934 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 935 | hostapd_set_sta_flags(hapd, sta); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 936 | if (updated) |
| 937 | ap_sta_set_authorized_event(hapd, sta, 1); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 938 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 939 | if (reassoc && (sta->auth_alg == WLAN_AUTH_FT)) |
| 940 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 941 | #ifdef CONFIG_FILS |
| 942 | else if (sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 943 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 944 | sta->auth_alg == WLAN_AUTH_FILS_PK) |
| 945 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS); |
| 946 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 947 | else |
| 948 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 949 | |
| 950 | hostapd_new_assoc_sta(hapd, sta, !new_assoc); |
| 951 | |
| 952 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); |
| 953 | |
| 954 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 955 | if (req_ies) { |
| 956 | p2p_group_notif_assoc(hapd->p2p_group, sta->addr, |
| 957 | req_ies, req_ies_len); |
| 958 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 959 | #endif /* CONFIG_P2P */ |
| 960 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 961 | if (elems.wfa_capab) |
| 962 | hostapd_wfa_capab(hapd, sta, elems.wfa_capab, |
| 963 | elems.wfa_capab + elems.wfa_capab_len); |
| 964 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 965 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 966 | |
| 967 | fail: |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 968 | #ifdef CONFIG_IEEE80211R_AP |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 969 | if (status >= 0) |
| 970 | hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 971 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 972 | hostapd_drv_sta_disassoc(hapd, sta->addr, reason); |
| 973 | ap_free_sta(hapd, sta); |
| 974 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 978 | static void hostapd_remove_sta(struct hostapd_data *hapd, struct sta_info *sta) |
| 979 | { |
| 980 | ap_sta_set_authorized(hapd, sta, 0); |
| 981 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); |
| 982 | hostapd_set_sta_flags(hapd, sta); |
| 983 | wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC); |
| 984 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; |
| 985 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 986 | ap_free_sta(hapd, sta); |
| 987 | } |
| 988 | |
| 989 | |
| 990 | #ifdef CONFIG_IEEE80211BE |
| 991 | static void hostapd_notif_disassoc_mld(struct hostapd_data *assoc_hapd, |
| 992 | struct sta_info *sta, |
| 993 | const u8 *addr) |
| 994 | { |
| 995 | unsigned int link_id, i; |
| 996 | struct hostapd_data *tmp_hapd; |
| 997 | struct hapd_interfaces *interfaces = assoc_hapd->iface->interfaces; |
| 998 | |
| 999 | /* Remove STA entry in non-assoc links */ |
| 1000 | for (link_id = 0; link_id < MAX_NUM_MLD_LINKS; link_id++) { |
| 1001 | if (!sta->mld_info.links[link_id].valid) |
| 1002 | continue; |
| 1003 | |
| 1004 | for (i = 0; i < interfaces->count; i++) { |
| 1005 | struct sta_info *tmp_sta; |
| 1006 | |
| 1007 | tmp_hapd = interfaces->iface[i]->bss[0]; |
| 1008 | |
| 1009 | if (!tmp_hapd->conf->mld_ap || |
| 1010 | assoc_hapd == tmp_hapd || |
| 1011 | assoc_hapd->conf->mld_id != tmp_hapd->conf->mld_id) |
| 1012 | continue; |
| 1013 | |
| 1014 | tmp_sta = ap_get_sta(tmp_hapd, addr); |
| 1015 | if (tmp_sta) |
| 1016 | ap_free_sta(tmp_hapd, tmp_sta); |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | /* Remove STA in assoc link */ |
| 1021 | hostapd_remove_sta(assoc_hapd, sta); |
| 1022 | } |
| 1023 | #endif /* CONFIG_IEEE80211BE */ |
| 1024 | |
| 1025 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1026 | void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr) |
| 1027 | { |
| 1028 | struct sta_info *sta; |
| 1029 | |
| 1030 | if (addr == NULL) { |
| 1031 | /* |
| 1032 | * This could potentially happen with unexpected event from the |
| 1033 | * driver wrapper. This was seen at least in one case where the |
| 1034 | * driver ended up reporting a station mode event while hostapd |
| 1035 | * was running, so better make sure we stop processing such an |
| 1036 | * event here. |
| 1037 | */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1038 | wpa_printf(MSG_DEBUG, |
| 1039 | "hostapd_notif_disassoc: Skip event with no address"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1040 | return; |
| 1041 | } |
| 1042 | |
| 1043 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
| 1044 | HOSTAPD_LEVEL_INFO, "disassociated"); |
| 1045 | |
| 1046 | sta = ap_get_sta(hapd, addr); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1047 | #ifdef CONFIG_IEEE80211BE |
| 1048 | if (hostapd_is_mld_ap(hapd)) { |
| 1049 | struct hostapd_data *assoc_hapd; |
| 1050 | unsigned int i; |
| 1051 | |
| 1052 | if (!sta) { |
| 1053 | /* Find non-MLO cases from any of the affiliated AP |
| 1054 | * links. */ |
| 1055 | for (i = 0; i < hapd->iface->interfaces->count; ++i) { |
| 1056 | struct hostapd_iface *h = |
| 1057 | hapd->iface->interfaces->iface[i]; |
| 1058 | struct hostapd_data *h_hapd = h->bss[0]; |
| 1059 | struct hostapd_bss_config *hconf = h_hapd->conf; |
| 1060 | |
| 1061 | if (!hconf->mld_ap || |
| 1062 | hconf->mld_id != hapd->conf->mld_id) |
| 1063 | continue; |
| 1064 | |
| 1065 | sta = ap_get_sta(h_hapd, addr); |
| 1066 | if (sta) { |
| 1067 | if (!sta->mld_info.mld_sta) { |
| 1068 | hapd = h_hapd; |
| 1069 | goto legacy; |
| 1070 | } |
| 1071 | break; |
| 1072 | } |
| 1073 | } |
| 1074 | } else if (!sta->mld_info.mld_sta) { |
| 1075 | goto legacy; |
| 1076 | } |
| 1077 | if (!sta) { |
| 1078 | wpa_printf(MSG_DEBUG, |
| 1079 | "Disassociation notification for unknown STA " |
| 1080 | MACSTR, MAC2STR(addr)); |
| 1081 | return; |
| 1082 | } |
| 1083 | sta = hostapd_ml_get_assoc_sta(hapd, sta, &assoc_hapd); |
| 1084 | if (sta) |
| 1085 | hostapd_notif_disassoc_mld(assoc_hapd, sta, addr); |
| 1086 | return; |
| 1087 | } |
| 1088 | |
| 1089 | legacy: |
| 1090 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1091 | if (sta == NULL) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1092 | wpa_printf(MSG_DEBUG, |
| 1093 | "Disassociation notification for unknown STA " |
| 1094 | MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1095 | return; |
| 1096 | } |
| 1097 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1098 | hostapd_remove_sta(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | |
| 1102 | void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr) |
| 1103 | { |
| 1104 | struct sta_info *sta = ap_get_sta(hapd, addr); |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 1105 | #ifdef CONFIG_IEEE80211BE |
| 1106 | struct hostapd_data *orig_hapd = hapd; |
| 1107 | |
| 1108 | if (!sta && hapd->conf->mld_ap) { |
| 1109 | hapd = hostapd_find_by_sta(hapd->iface, addr, true, &sta); |
| 1110 | if (!hapd) { |
| 1111 | wpa_printf(MSG_DEBUG, |
| 1112 | "No partner link BSS found for STA " MACSTR |
| 1113 | " - fallback to received context", |
| 1114 | MAC2STR(addr)); |
| 1115 | hapd = orig_hapd; |
| 1116 | } |
| 1117 | } |
| 1118 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1119 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1120 | if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1121 | return; |
| 1122 | |
| 1123 | hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1124 | HOSTAPD_LEVEL_INFO, |
| 1125 | "disconnected due to excessive missing ACKs"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1126 | hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1127 | ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1131 | void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr, |
| 1132 | enum smps_mode smps_mode, |
| 1133 | enum chan_width chan_width, u8 rx_nss) |
| 1134 | { |
| 1135 | struct sta_info *sta = ap_get_sta(hapd, addr); |
| 1136 | const char *txt; |
| 1137 | |
| 1138 | if (!sta) |
| 1139 | return; |
| 1140 | |
| 1141 | switch (smps_mode) { |
| 1142 | case SMPS_AUTOMATIC: |
| 1143 | txt = "automatic"; |
| 1144 | break; |
| 1145 | case SMPS_OFF: |
| 1146 | txt = "off"; |
| 1147 | break; |
| 1148 | case SMPS_DYNAMIC: |
| 1149 | txt = "dynamic"; |
| 1150 | break; |
| 1151 | case SMPS_STATIC: |
| 1152 | txt = "static"; |
| 1153 | break; |
| 1154 | default: |
| 1155 | txt = NULL; |
| 1156 | break; |
| 1157 | } |
| 1158 | if (txt) { |
| 1159 | wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED |
| 1160 | MACSTR " %s", MAC2STR(addr), txt); |
| 1161 | } |
| 1162 | |
| 1163 | switch (chan_width) { |
| 1164 | case CHAN_WIDTH_20_NOHT: |
| 1165 | txt = "20(no-HT)"; |
| 1166 | break; |
| 1167 | case CHAN_WIDTH_20: |
| 1168 | txt = "20"; |
| 1169 | break; |
| 1170 | case CHAN_WIDTH_40: |
| 1171 | txt = "40"; |
| 1172 | break; |
| 1173 | case CHAN_WIDTH_80: |
| 1174 | txt = "80"; |
| 1175 | break; |
| 1176 | case CHAN_WIDTH_80P80: |
| 1177 | txt = "80+80"; |
| 1178 | break; |
| 1179 | case CHAN_WIDTH_160: |
| 1180 | txt = "160"; |
| 1181 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1182 | case CHAN_WIDTH_320: |
| 1183 | txt = "320"; |
| 1184 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1185 | default: |
| 1186 | txt = NULL; |
| 1187 | break; |
| 1188 | } |
| 1189 | if (txt) { |
| 1190 | wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED |
| 1191 | MACSTR " %s", MAC2STR(addr), txt); |
| 1192 | } |
| 1193 | |
| 1194 | if (rx_nss != 0xff) { |
| 1195 | wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED |
| 1196 | MACSTR " %d", MAC2STR(addr), rx_nss); |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1201 | void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1202 | int offset, int width, int cf1, int cf2, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1203 | u16 punct_bitmap, int finished) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1204 | { |
| 1205 | #ifdef NEED_AP_MLME |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1206 | int channel, chwidth, is_dfs0, is_dfs; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1207 | u8 seg0_idx = 0, seg1_idx = 0, op_class, chan_no; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1208 | size_t i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1209 | |
| 1210 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1211 | HOSTAPD_LEVEL_INFO, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1212 | "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 Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1213 | finished ? "had" : "starting", |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1214 | hapd->iface->freq, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1215 | freq, ht, hapd->iconf->ch_switch_vht_config, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1216 | hapd->iconf->ch_switch_he_config, |
| 1217 | hapd->iconf->ch_switch_eht_config, offset, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1218 | width, channel_width_to_string(width), cf1, cf2, |
| 1219 | punct_bitmap); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1220 | |
Hai Shalom | 1dc4d20 | 2019-04-29 16:22:27 -0700 | [diff] [blame] | 1221 | if (!hapd->iface->current_mode) { |
| 1222 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
| 1223 | HOSTAPD_LEVEL_WARNING, |
| 1224 | "ignore channel switch since the interface is not yet ready"); |
| 1225 | return; |
| 1226 | } |
| 1227 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1228 | /* Check if any of configured channels require DFS */ |
| 1229 | is_dfs0 = hostapd_is_dfs_required(hapd->iface); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1230 | hapd->iface->freq = freq; |
| 1231 | |
| 1232 | channel = hostapd_hw_get_channel(hapd, freq); |
| 1233 | if (!channel) { |
| 1234 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1235 | HOSTAPD_LEVEL_WARNING, |
| 1236 | "driver switched to bad channel!"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1237 | return; |
| 1238 | } |
| 1239 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1240 | switch (width) { |
| 1241 | case CHAN_WIDTH_80: |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1242 | chwidth = CONF_OPER_CHWIDTH_80MHZ; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1243 | break; |
| 1244 | case CHAN_WIDTH_80P80: |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1245 | chwidth = CONF_OPER_CHWIDTH_80P80MHZ; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1246 | break; |
| 1247 | case CHAN_WIDTH_160: |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1248 | chwidth = CONF_OPER_CHWIDTH_160MHZ; |
| 1249 | break; |
| 1250 | case CHAN_WIDTH_320: |
| 1251 | chwidth = CONF_OPER_CHWIDTH_320MHZ; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1252 | break; |
| 1253 | case CHAN_WIDTH_20_NOHT: |
| 1254 | case CHAN_WIDTH_20: |
| 1255 | case CHAN_WIDTH_40: |
| 1256 | default: |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1257 | chwidth = CONF_OPER_CHWIDTH_USE_HT; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1258 | break; |
| 1259 | } |
| 1260 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1261 | /* The operating channel changed when CSA finished, so need to update |
| 1262 | * hw_mode for all following operations to cover the cases where the |
| 1263 | * driver changed the operating band. */ |
| 1264 | if (finished && hostapd_csa_update_hwmode(hapd->iface)) |
| 1265 | return; |
| 1266 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1267 | switch (hapd->iface->current_mode->mode) { |
| 1268 | case HOSTAPD_MODE_IEEE80211A: |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1269 | if (cf1 == 5935) |
| 1270 | seg0_idx = (cf1 - 5925) / 5; |
| 1271 | else if (cf1 > 5950) |
| 1272 | seg0_idx = (cf1 - 5950) / 5; |
| 1273 | else if (cf1 > 5000) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1274 | seg0_idx = (cf1 - 5000) / 5; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1275 | |
| 1276 | if (cf2 == 5935) |
| 1277 | seg1_idx = (cf2 - 5925) / 5; |
| 1278 | else if (cf2 > 5950) |
| 1279 | seg1_idx = (cf2 - 5950) / 5; |
| 1280 | else if (cf2 > 5000) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1281 | seg1_idx = (cf2 - 5000) / 5; |
| 1282 | break; |
| 1283 | default: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1284 | ieee80211_freq_to_chan(cf1, &seg0_idx); |
| 1285 | ieee80211_freq_to_chan(cf2, &seg1_idx); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1286 | break; |
| 1287 | } |
| 1288 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1289 | hapd->iconf->channel = channel; |
| 1290 | hapd->iconf->ieee80211n = ht; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1291 | if (!ht) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1292 | hapd->iconf->ieee80211ac = 0; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1293 | if (hapd->iconf->ch_switch_vht_config) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1294 | /* CHAN_SWITCH VHT config */ |
| 1295 | if (hapd->iconf->ch_switch_vht_config & |
| 1296 | CH_SWITCH_VHT_ENABLED) |
| 1297 | hapd->iconf->ieee80211ac = 1; |
| 1298 | else if (hapd->iconf->ch_switch_vht_config & |
| 1299 | CH_SWITCH_VHT_DISABLED) |
| 1300 | hapd->iconf->ieee80211ac = 0; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1301 | } |
| 1302 | if (hapd->iconf->ch_switch_he_config) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1303 | /* CHAN_SWITCH HE config */ |
| 1304 | if (hapd->iconf->ch_switch_he_config & |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1305 | CH_SWITCH_HE_ENABLED) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1306 | hapd->iconf->ieee80211ax = 1; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1307 | if (hapd->iface->freq > 4000 && |
| 1308 | hapd->iface->freq < 5895) |
| 1309 | hapd->iconf->ieee80211ac = 1; |
| 1310 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1311 | else if (hapd->iconf->ch_switch_he_config & |
| 1312 | CH_SWITCH_HE_DISABLED) |
| 1313 | hapd->iconf->ieee80211ax = 0; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1314 | } |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1315 | #ifdef CONFIG_IEEE80211BE |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1316 | if (hapd->iconf->ch_switch_eht_config) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1317 | /* CHAN_SWITCH EHT config */ |
| 1318 | if (hapd->iconf->ch_switch_eht_config & |
| 1319 | CH_SWITCH_EHT_ENABLED) { |
| 1320 | hapd->iconf->ieee80211be = 1; |
| 1321 | hapd->iconf->ieee80211ax = 1; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1322 | if (!is_6ghz_freq(hapd->iface->freq) && |
| 1323 | hapd->iface->freq > 4000) |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1324 | hapd->iconf->ieee80211ac = 1; |
| 1325 | } else if (hapd->iconf->ch_switch_eht_config & |
| 1326 | CH_SWITCH_EHT_DISABLED) |
| 1327 | hapd->iconf->ieee80211be = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1328 | } |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1329 | #endif /* CONFIG_IEEE80211BE */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1330 | hapd->iconf->ch_switch_vht_config = 0; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1331 | hapd->iconf->ch_switch_he_config = 0; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1332 | hapd->iconf->ch_switch_eht_config = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1333 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1334 | if (width == CHAN_WIDTH_40 || width == CHAN_WIDTH_80 || |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 1335 | width == CHAN_WIDTH_80P80 || width == CHAN_WIDTH_160 || |
| 1336 | width == CHAN_WIDTH_320) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1337 | hapd->iconf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; |
| 1338 | else if (width == CHAN_WIDTH_20 || width == CHAN_WIDTH_20_NOHT) |
| 1339 | hapd->iconf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; |
| 1340 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1341 | hapd->iconf->secondary_channel = offset; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1342 | if (ieee80211_freq_to_channel_ext(freq, offset, chwidth, |
| 1343 | &op_class, &chan_no) != |
| 1344 | NUM_HOSTAPD_MODES) |
| 1345 | hapd->iconf->op_class = op_class; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1346 | hostapd_set_oper_chwidth(hapd->iconf, chwidth); |
| 1347 | hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, seg0_idx); |
| 1348 | hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, seg1_idx); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1349 | /* Auto-detect new bw320_offset */ |
| 1350 | hostapd_set_and_check_bw320_offset(hapd->iconf, 0); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1351 | #ifdef CONFIG_IEEE80211BE |
| 1352 | hapd->iconf->punct_bitmap = punct_bitmap; |
| 1353 | #endif /* CONFIG_IEEE80211BE */ |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1354 | if (hapd->iconf->ieee80211ac) { |
| 1355 | hapd->iconf->vht_capab &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1356 | if (chwidth == CONF_OPER_CHWIDTH_160MHZ) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1357 | hapd->iconf->vht_capab |= |
| 1358 | VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1359 | else if (chwidth == CONF_OPER_CHWIDTH_80P80MHZ) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1360 | hapd->iconf->vht_capab |= |
| 1361 | VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; |
| 1362 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1363 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1364 | is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features, |
| 1365 | hapd->iface->num_hw_features); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1366 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1367 | wpa_msg(hapd->msg_ctx, MSG_INFO, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1368 | "%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 Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1369 | finished ? WPA_EVENT_CHANNEL_SWITCH : |
| 1370 | WPA_EVENT_CHANNEL_SWITCH_STARTED, |
| 1371 | freq, ht, offset, channel_width_to_string(width), |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1372 | cf1, cf2, is_dfs0, is_dfs, punct_bitmap); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1373 | if (!finished) |
| 1374 | return; |
| 1375 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 1376 | if (hapd->csa_in_progress && |
| 1377 | freq == hapd->cs_freq_params.freq) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1378 | hostapd_cleanup_cs_params(hapd); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 1379 | ieee802_11_set_beacon(hapd); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1380 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1381 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED |
| 1382 | "freq=%d dfs=%d", freq, is_dfs); |
| 1383 | } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1384 | /* Complete AP configuration for the first bring up. */ |
| 1385 | if (is_dfs0 > 0 && |
| 1386 | hostapd_is_dfs_required(hapd->iface) <= 0 && |
| 1387 | hapd->iface->state != HAPD_IFACE_ENABLED) { |
| 1388 | /* Fake a CAC start bit to skip setting channel */ |
| 1389 | hapd->iface->cac_started = 1; |
| 1390 | hostapd_setup_interface_complete(hapd->iface, 0); |
| 1391 | } |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1392 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED |
| 1393 | "freq=%d dfs=%d", freq, is_dfs); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1394 | } else if (is_dfs && |
| 1395 | hostapd_is_dfs_required(hapd->iface) && |
| 1396 | !hostapd_is_dfs_chan_available(hapd->iface) && |
| 1397 | !hapd->iface->cac_started) { |
| 1398 | hostapd_disable_iface(hapd->iface); |
| 1399 | hostapd_enable_iface(hapd->iface); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1400 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1401 | |
| 1402 | for (i = 0; i < hapd->iface->num_bss; i++) |
| 1403 | hostapd_neighbor_set_own_report(hapd->iface->bss[i]); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1404 | |
| 1405 | #ifdef CONFIG_OCV |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1406 | if (hapd->conf->ocv && |
| 1407 | !(hapd->iface->drv_flags2 & |
| 1408 | WPA_DRIVER_FLAGS2_SA_QUERY_OFFLOAD_AP)) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1409 | struct sta_info *sta; |
| 1410 | bool check_sa_query = false; |
| 1411 | |
| 1412 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 1413 | if (wpa_auth_uses_ocv(sta->wpa_sm) && |
| 1414 | !(sta->flags & WLAN_STA_WNM_SLEEP_MODE)) { |
| 1415 | sta->post_csa_sa_query = 1; |
| 1416 | check_sa_query = true; |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | if (check_sa_query) { |
| 1421 | wpa_printf(MSG_DEBUG, |
| 1422 | "OCV: Check post-CSA SA Query initiation in 15 seconds"); |
| 1423 | eloop_register_timeout(15, 0, |
| 1424 | hostapd_ocv_check_csa_sa_query, |
| 1425 | hapd, NULL); |
| 1426 | } |
| 1427 | } |
| 1428 | #endif /* CONFIG_OCV */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1429 | #endif /* NEED_AP_MLME */ |
| 1430 | } |
| 1431 | |
| 1432 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1433 | void hostapd_event_connect_failed_reason(struct hostapd_data *hapd, |
| 1434 | const u8 *addr, int reason_code) |
| 1435 | { |
| 1436 | switch (reason_code) { |
| 1437 | case MAX_CLIENT_REACHED: |
| 1438 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR, |
| 1439 | MAC2STR(addr)); |
| 1440 | break; |
| 1441 | case BLOCKED_CLIENT: |
| 1442 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR, |
| 1443 | MAC2STR(addr)); |
| 1444 | break; |
| 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1449 | #ifdef CONFIG_ACS |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 1450 | void hostapd_acs_channel_selected(struct hostapd_data *hapd, |
| 1451 | struct acs_selected_channels *acs_res) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1452 | { |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 1453 | int ret, i; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1454 | int err = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1455 | struct hostapd_channel_data *pri_chan; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1456 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1457 | #ifdef CONFIG_IEEE80211BE |
| 1458 | if (acs_res->link_id != -1) { |
| 1459 | hapd = hostapd_mld_get_link_bss(hapd, acs_res->link_id); |
| 1460 | if (!hapd) { |
| 1461 | wpa_printf(MSG_ERROR, |
| 1462 | "MLD: Failed to get link BSS for EVENT_ACS_CHANNEL_SELECTED link_id=%d", |
| 1463 | acs_res->link_id); |
| 1464 | return; |
| 1465 | } |
| 1466 | } |
| 1467 | #endif /* CONFIG_IEEE80211BE */ |
| 1468 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1469 | if (hapd->iconf->channel) { |
| 1470 | wpa_printf(MSG_INFO, "ACS: Channel was already set to %d", |
| 1471 | hapd->iconf->channel); |
| 1472 | return; |
| 1473 | } |
| 1474 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1475 | hapd->iface->freq = acs_res->pri_freq; |
| 1476 | |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 1477 | if (!hapd->iface->current_mode) { |
| 1478 | for (i = 0; i < hapd->iface->num_hw_features; i++) { |
| 1479 | struct hostapd_hw_modes *mode = |
| 1480 | &hapd->iface->hw_features[i]; |
| 1481 | |
| 1482 | if (mode->mode == acs_res->hw_mode) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1483 | if (hapd->iface->freq > 0 && |
| 1484 | !hw_get_chan(mode->mode, |
| 1485 | hapd->iface->freq, |
| 1486 | hapd->iface->hw_features, |
| 1487 | hapd->iface->num_hw_features)) |
| 1488 | continue; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 1489 | hapd->iface->current_mode = mode; |
| 1490 | break; |
| 1491 | } |
| 1492 | } |
| 1493 | if (!hapd->iface->current_mode) { |
| 1494 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
| 1495 | HOSTAPD_LEVEL_WARNING, |
| 1496 | "driver selected to bad hw_mode"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1497 | err = 1; |
| 1498 | goto out; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 1499 | } |
| 1500 | } |
| 1501 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1502 | if (!acs_res->pri_freq) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1503 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
| 1504 | HOSTAPD_LEVEL_WARNING, |
| 1505 | "driver switched to bad channel"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1506 | err = 1; |
| 1507 | goto out; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1508 | } |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1509 | pri_chan = hw_get_channel_freq(hapd->iface->current_mode->mode, |
| 1510 | acs_res->pri_freq, NULL, |
| 1511 | hapd->iface->hw_features, |
| 1512 | hapd->iface->num_hw_features); |
| 1513 | if (!pri_chan) { |
| 1514 | wpa_printf(MSG_ERROR, |
| 1515 | "ACS: Could not determine primary channel number from pri_freq %u", |
| 1516 | acs_res->pri_freq); |
| 1517 | err = 1; |
| 1518 | goto out; |
| 1519 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1520 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1521 | hapd->iconf->channel = pri_chan->chan; |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 1522 | hapd->iconf->acs = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1523 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1524 | if (acs_res->sec_freq == 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1525 | hapd->iconf->secondary_channel = 0; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1526 | else if (acs_res->sec_freq < acs_res->pri_freq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1527 | hapd->iconf->secondary_channel = -1; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1528 | else if (acs_res->sec_freq > acs_res->pri_freq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1529 | hapd->iconf->secondary_channel = 1; |
| 1530 | else { |
| 1531 | wpa_printf(MSG_ERROR, "Invalid secondary channel!"); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1532 | err = 1; |
| 1533 | goto out; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1534 | } |
| 1535 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1536 | hapd->iconf->edmg_channel = acs_res->edmg_channel; |
| 1537 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1538 | if (hapd->iface->conf->ieee80211ac || hapd->iface->conf->ieee80211ax) { |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 1539 | /* set defaults for backwards compatibility */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1540 | hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0); |
| 1541 | hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, 0); |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1542 | hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_USE_HT); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1543 | if (acs_res->ch_width == 40) { |
| 1544 | if (is_6ghz_freq(acs_res->pri_freq)) |
| 1545 | hostapd_set_oper_centr_freq_seg0_idx( |
| 1546 | hapd->iconf, |
| 1547 | acs_res->vht_seg0_center_ch); |
| 1548 | } else if (acs_res->ch_width == 80) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1549 | hostapd_set_oper_centr_freq_seg0_idx( |
| 1550 | hapd->iconf, acs_res->vht_seg0_center_ch); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 1551 | if (acs_res->vht_seg1_center_ch == 0) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1552 | hostapd_set_oper_chwidth( |
| 1553 | hapd->iconf, CONF_OPER_CHWIDTH_80MHZ); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 1554 | } else { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1555 | hostapd_set_oper_chwidth( |
| 1556 | hapd->iconf, |
| 1557 | CONF_OPER_CHWIDTH_80P80MHZ); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1558 | hostapd_set_oper_centr_freq_seg1_idx( |
| 1559 | hapd->iconf, |
| 1560 | acs_res->vht_seg1_center_ch); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 1561 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1562 | } else if (acs_res->ch_width == 160) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1563 | hostapd_set_oper_chwidth(hapd->iconf, |
| 1564 | CONF_OPER_CHWIDTH_160MHZ); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1565 | hostapd_set_oper_centr_freq_seg0_idx( |
| 1566 | hapd->iconf, acs_res->vht_seg1_center_ch); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 1567 | } |
| 1568 | } |
| 1569 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1570 | #ifdef CONFIG_IEEE80211BE |
| 1571 | if (hapd->iface->conf->ieee80211be && acs_res->ch_width == 320) { |
| 1572 | hostapd_set_oper_chwidth(hapd->iconf, CONF_OPER_CHWIDTH_320MHZ); |
| 1573 | hostapd_set_oper_centr_freq_seg0_idx( |
| 1574 | hapd->iconf, acs_res->vht_seg1_center_ch); |
| 1575 | hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0); |
| 1576 | } |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1577 | |
| 1578 | if (hapd->iface->conf->ieee80211be && acs_res->puncture_bitmap) |
| 1579 | hapd->iconf->punct_bitmap = acs_res->puncture_bitmap; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1580 | #endif /* CONFIG_IEEE80211BE */ |
| 1581 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1582 | out: |
| 1583 | ret = hostapd_acs_completed(hapd->iface, err); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1584 | if (ret) { |
| 1585 | wpa_printf(MSG_ERROR, |
| 1586 | "ACS: Possibly channel configuration is invalid"); |
| 1587 | } |
| 1588 | } |
| 1589 | #endif /* CONFIG_ACS */ |
| 1590 | |
| 1591 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1592 | int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1593 | const u8 *bssid, const u8 *ie, size_t ie_len, |
| 1594 | int ssi_signal) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1595 | { |
| 1596 | size_t i; |
| 1597 | int ret = 0; |
| 1598 | |
| 1599 | if (sa == NULL || ie == NULL) |
| 1600 | return -1; |
| 1601 | |
| 1602 | random_add_randomness(sa, ETH_ALEN); |
| 1603 | for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) { |
| 1604 | if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1605 | sa, da, bssid, ie, ie_len, |
| 1606 | ssi_signal) > 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1607 | ret = 1; |
| 1608 | break; |
| 1609 | } |
| 1610 | } |
| 1611 | return ret; |
| 1612 | } |
| 1613 | |
| 1614 | |
| 1615 | #ifdef HOSTAPD |
| 1616 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1617 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1618 | static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1619 | u16 auth_transaction, u16 status, |
| 1620 | const u8 *ies, size_t ies_len) |
| 1621 | { |
| 1622 | struct hostapd_data *hapd = ctx; |
| 1623 | struct sta_info *sta; |
| 1624 | |
| 1625 | sta = ap_get_sta(hapd, dst); |
| 1626 | if (sta == NULL) |
| 1627 | return; |
| 1628 | |
| 1629 | hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211, |
| 1630 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)"); |
| 1631 | sta->flags |= WLAN_STA_AUTH; |
| 1632 | |
| 1633 | hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len); |
| 1634 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1635 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1636 | |
| 1637 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1638 | #ifdef CONFIG_FILS |
| 1639 | static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd, |
| 1640 | struct sta_info *sta, u16 resp, |
| 1641 | struct wpabuf *data, int pub) |
| 1642 | { |
| 1643 | if (resp == WLAN_STATUS_SUCCESS) { |
| 1644 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1645 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)"); |
| 1646 | sta->flags |= WLAN_STA_AUTH; |
| 1647 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
| 1648 | sta->auth_alg = WLAN_AUTH_FILS_SK; |
| 1649 | mlme_authenticate_indication(hapd, sta); |
| 1650 | } else { |
| 1651 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1652 | HOSTAPD_LEVEL_DEBUG, |
| 1653 | "authentication failed (FILS)"); |
| 1654 | } |
| 1655 | |
| 1656 | hostapd_sta_auth(hapd, sta->addr, 2, resp, |
| 1657 | data ? wpabuf_head(data) : NULL, |
| 1658 | data ? wpabuf_len(data) : 0); |
| 1659 | wpabuf_free(data); |
| 1660 | } |
| 1661 | #endif /* CONFIG_FILS */ |
| 1662 | |
| 1663 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1664 | static void hostapd_notif_auth(struct hostapd_data *hapd, |
| 1665 | struct auth_info *rx_auth) |
| 1666 | { |
| 1667 | struct sta_info *sta; |
| 1668 | u16 status = WLAN_STATUS_SUCCESS; |
| 1669 | u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN]; |
| 1670 | size_t resp_ies_len = 0; |
| 1671 | |
| 1672 | sta = ap_get_sta(hapd, rx_auth->peer); |
| 1673 | if (!sta) { |
| 1674 | sta = ap_sta_add(hapd, rx_auth->peer); |
| 1675 | if (sta == NULL) { |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 1676 | status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1677 | goto fail; |
| 1678 | } |
| 1679 | } |
| 1680 | sta->flags &= ~WLAN_STA_PREAUTH; |
| 1681 | ieee802_1x_notify_pre_auth(sta->eapol_sm, 0); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1682 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1683 | if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) { |
| 1684 | sta->auth_alg = WLAN_AUTH_FT; |
| 1685 | if (sta->wpa_sm == NULL) |
| 1686 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1687 | sta->addr, NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1688 | if (sta->wpa_sm == NULL) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1689 | wpa_printf(MSG_DEBUG, |
| 1690 | "FT: Failed to initialize WPA state machine"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1691 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1692 | goto fail; |
| 1693 | } |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 1694 | wpa_ft_process_auth(sta->wpa_sm, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1695 | rx_auth->auth_transaction, rx_auth->ies, |
| 1696 | rx_auth->ies_len, |
| 1697 | hostapd_notify_auth_ft_finish, hapd); |
| 1698 | return; |
| 1699 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1700 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1701 | |
| 1702 | #ifdef CONFIG_FILS |
| 1703 | if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) { |
| 1704 | sta->auth_alg = WLAN_AUTH_FILS_SK; |
| 1705 | handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len, |
| 1706 | rx_auth->auth_type, rx_auth->auth_transaction, |
| 1707 | rx_auth->status_code, |
| 1708 | hostapd_notify_auth_fils_finish); |
| 1709 | return; |
| 1710 | } |
| 1711 | #endif /* CONFIG_FILS */ |
| 1712 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1713 | fail: |
| 1714 | hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1, |
| 1715 | status, resp_ies, resp_ies_len); |
| 1716 | } |
| 1717 | |
| 1718 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1719 | #ifndef NEED_AP_MLME |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1720 | static void hostapd_action_rx(struct hostapd_data *hapd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1721 | struct rx_mgmt *drv_mgmt) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1722 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1723 | struct ieee80211_mgmt *mgmt; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1724 | struct sta_info *sta; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1725 | size_t plen __maybe_unused; |
| 1726 | u16 fc; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1727 | u8 *action __maybe_unused; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1728 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1729 | if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1730 | return; |
| 1731 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1732 | plen = drv_mgmt->frame_len - IEEE80211_HDRLEN; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1733 | |
| 1734 | mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame; |
| 1735 | fc = le_to_host16(mgmt->frame_control); |
| 1736 | if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) |
| 1737 | return; /* handled by the driver */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1738 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1739 | action = (u8 *) &mgmt->u.action.u; |
| 1740 | wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR |
| 1741 | " da " MACSTR " plen %d", |
| 1742 | mgmt->u.action.category, *action, |
| 1743 | MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1744 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1745 | sta = ap_get_sta(hapd, mgmt->sa); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1746 | if (sta == NULL) { |
| 1747 | wpa_printf(MSG_DEBUG, "%s: station not found", __func__); |
| 1748 | return; |
| 1749 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1750 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1751 | if (mgmt->u.action.category == WLAN_ACTION_FT) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1752 | wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, plen); |
| 1753 | return; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1754 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1755 | #endif /* CONFIG_IEEE80211R_AP */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1756 | if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1757 | ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1758 | return; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1759 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1760 | #ifdef CONFIG_WNM_AP |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1761 | if (mgmt->u.action.category == WLAN_ACTION_WNM) { |
| 1762 | ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1763 | return; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1764 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1765 | #endif /* CONFIG_WNM_AP */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1766 | #ifdef CONFIG_FST |
| 1767 | if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) { |
| 1768 | fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len); |
| 1769 | return; |
| 1770 | } |
| 1771 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1772 | #ifdef CONFIG_DPP |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1773 | if (plen >= 2 + 4 && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1774 | mgmt->u.action.category == WLAN_ACTION_PUBLIC && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1775 | mgmt->u.action.u.vs_public_action.action == |
| 1776 | WLAN_PA_VENDOR_SPECIFIC && |
| 1777 | WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) == |
| 1778 | OUI_WFA && |
| 1779 | mgmt->u.action.u.vs_public_action.variable[0] == |
| 1780 | DPP_OUI_TYPE) { |
| 1781 | const u8 *pos, *end; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1782 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1783 | pos = mgmt->u.action.u.vs_public_action.oui; |
| 1784 | end = drv_mgmt->frame + drv_mgmt->frame_len; |
| 1785 | hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos, |
| 1786 | drv_mgmt->freq); |
| 1787 | return; |
| 1788 | } |
| 1789 | #endif /* CONFIG_DPP */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1790 | #ifdef CONFIG_NAN_USD |
| 1791 | if (mgmt->u.action.category == WLAN_ACTION_PUBLIC && plen >= 5 && |
| 1792 | mgmt->u.action.u.vs_public_action.action == |
| 1793 | WLAN_PA_VENDOR_SPECIFIC && |
| 1794 | WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) == |
| 1795 | OUI_WFA && |
| 1796 | mgmt->u.action.u.vs_public_action.variable[0] == NAN_OUI_TYPE) { |
| 1797 | const u8 *pos, *end; |
| 1798 | |
| 1799 | pos = mgmt->u.action.u.vs_public_action.variable; |
| 1800 | end = drv_mgmt->frame + drv_mgmt->frame_len; |
| 1801 | pos++; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1802 | hostapd_nan_usd_rx_sdf(hapd, mgmt->sa, mgmt->bssid, |
| 1803 | drv_mgmt->freq, pos, end - pos); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1804 | return; |
| 1805 | } |
| 1806 | #endif /* CONFIG_NAN_USD */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1807 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1808 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1809 | |
| 1810 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1811 | #ifdef NEED_AP_MLME |
| 1812 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1813 | static struct hostapd_data * |
| 1814 | switch_link_hapd(struct hostapd_data *hapd, int link_id) |
| 1815 | { |
| 1816 | #ifdef CONFIG_IEEE80211BE |
| 1817 | if (hapd->conf->mld_ap && link_id >= 0) { |
| 1818 | struct hostapd_data *link_bss; |
| 1819 | |
| 1820 | link_bss = hostapd_mld_get_link_bss(hapd, link_id); |
| 1821 | if (link_bss) |
| 1822 | return link_bss; |
| 1823 | } |
| 1824 | #endif /* CONFIG_IEEE80211BE */ |
| 1825 | |
| 1826 | return hapd; |
| 1827 | } |
| 1828 | |
| 1829 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1830 | static struct hostapd_data * |
| 1831 | switch_link_scan(struct hostapd_data *hapd, u64 scan_cookie) |
| 1832 | { |
| 1833 | #ifdef CONFIG_IEEE80211BE |
| 1834 | if (hapd->conf->mld_ap && scan_cookie != 0) { |
| 1835 | unsigned int i; |
| 1836 | |
| 1837 | for (i = 0; i < hapd->iface->interfaces->count; i++) { |
| 1838 | struct hostapd_iface *h; |
| 1839 | struct hostapd_data *h_hapd; |
| 1840 | |
| 1841 | h = hapd->iface->interfaces->iface[i]; |
| 1842 | h_hapd = h->bss[0]; |
| 1843 | if (!hostapd_is_ml_partner(hapd, h_hapd)) |
| 1844 | continue; |
| 1845 | |
| 1846 | if (h_hapd->scan_cookie == scan_cookie) { |
| 1847 | h_hapd->scan_cookie = 0; |
| 1848 | return h_hapd; |
| 1849 | } |
| 1850 | } |
| 1851 | } |
| 1852 | #endif /* CONFIG_IEEE80211BE */ |
| 1853 | |
| 1854 | return hapd; |
| 1855 | } |
| 1856 | |
| 1857 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1858 | #define HAPD_BROADCAST ((struct hostapd_data *) -1) |
| 1859 | |
| 1860 | static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface, |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 1861 | const u8 *bssid, int link_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1862 | { |
| 1863 | size_t i; |
| 1864 | |
| 1865 | if (bssid == NULL) |
| 1866 | return NULL; |
| 1867 | if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff && |
| 1868 | bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff) |
| 1869 | return HAPD_BROADCAST; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1870 | #ifdef CONFIG_NAN_USD |
| 1871 | if (nan_de_is_nan_network_id(bssid)) |
| 1872 | return HAPD_BROADCAST; /* Process NAN Network ID like broadcast |
| 1873 | */ |
| 1874 | #endif /* CONFIG_NAN_USD */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1875 | |
| 1876 | for (i = 0; i < iface->num_bss; i++) { |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 1877 | struct hostapd_data *hapd; |
| 1878 | #ifdef CONFIG_IEEE80211BE |
| 1879 | struct hostapd_data *p_hapd; |
| 1880 | #endif /* CONFIG_IEEE80211BE */ |
| 1881 | |
| 1882 | hapd = iface->bss[i]; |
| 1883 | if (ether_addr_equal(bssid, hapd->own_addr)) |
| 1884 | return hapd; |
| 1885 | |
| 1886 | #ifdef CONFIG_IEEE80211BE |
| 1887 | if (ether_addr_equal(bssid, hapd->own_addr) || |
| 1888 | (hapd->conf->mld_ap && |
| 1889 | ether_addr_equal(bssid, hapd->mld->mld_addr) && |
| 1890 | link_id == hapd->mld_link_id)) |
| 1891 | return hapd; |
| 1892 | |
| 1893 | if (!hapd->conf->mld_ap) |
| 1894 | continue; |
| 1895 | |
| 1896 | for_each_mld_link(p_hapd, hapd) { |
| 1897 | if (p_hapd == hapd) |
| 1898 | continue; |
| 1899 | |
| 1900 | if (ether_addr_equal(bssid, p_hapd->own_addr) || |
| 1901 | (ether_addr_equal(bssid, p_hapd->mld->mld_addr) && |
| 1902 | link_id == p_hapd->mld_link_id)) |
| 1903 | return p_hapd; |
| 1904 | } |
| 1905 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | return NULL; |
| 1909 | } |
| 1910 | |
| 1911 | |
| 1912 | static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1913 | const u8 *bssid, const u8 *addr, |
| 1914 | int wds) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1915 | { |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 1916 | hapd = get_hapd_bssid(hapd->iface, bssid, -1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1917 | if (hapd == NULL || hapd == HAPD_BROADCAST) |
| 1918 | return; |
| 1919 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1920 | ieee802_11_rx_from_unknown(hapd, addr, wds); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1924 | static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1925 | { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1926 | struct hostapd_iface *iface; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1927 | const struct ieee80211_hdr *hdr; |
| 1928 | const u8 *bssid; |
| 1929 | struct hostapd_frame_info fi; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1930 | int ret; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1931 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 1932 | if (rx_mgmt->ctx) |
| 1933 | hapd = rx_mgmt->ctx; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1934 | hapd = switch_link_hapd(hapd, rx_mgmt->link_id); |
| 1935 | iface = hapd->iface; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1936 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 1937 | #ifdef CONFIG_TESTING_OPTIONS |
| 1938 | if (hapd->ext_mgmt_frame_handling) { |
| 1939 | size_t hex_len = 2 * rx_mgmt->frame_len + 1; |
| 1940 | char *hex = os_malloc(hex_len); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1941 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 1942 | if (hex) { |
| 1943 | wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame, |
| 1944 | rx_mgmt->frame_len); |
| 1945 | wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex); |
| 1946 | os_free(hex); |
| 1947 | } |
| 1948 | return 1; |
| 1949 | } |
| 1950 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1951 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1952 | hdr = (const struct ieee80211_hdr *) rx_mgmt->frame; |
| 1953 | bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len); |
| 1954 | if (bssid == NULL) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1955 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1956 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 1957 | hapd = get_hapd_bssid(iface, bssid, rx_mgmt->link_id); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1958 | |
| 1959 | if (!hapd) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1960 | u16 fc = le_to_host16(hdr->frame_control); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1961 | |
| 1962 | /* |
| 1963 | * Drop frames to unknown BSSIDs except for Beacon frames which |
| 1964 | * could be used to update neighbor information. |
| 1965 | */ |
| 1966 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 1967 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) |
| 1968 | hapd = iface->bss[0]; |
| 1969 | else |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1970 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | os_memset(&fi, 0, sizeof(fi)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1974 | fi.freq = rx_mgmt->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1975 | fi.datarate = rx_mgmt->datarate; |
| 1976 | fi.ssi_signal = rx_mgmt->ssi_signal; |
| 1977 | |
| 1978 | if (hapd == HAPD_BROADCAST) { |
| 1979 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1980 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1981 | ret = 0; |
| 1982 | for (i = 0; i < iface->num_bss; i++) { |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 1983 | /* if bss is set, driver will call this function for |
| 1984 | * each bss individually. */ |
| 1985 | if (rx_mgmt->drv_priv && |
| 1986 | (iface->bss[i]->drv_priv != rx_mgmt->drv_priv)) |
| 1987 | continue; |
| 1988 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1989 | if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame, |
| 1990 | rx_mgmt->frame_len, &fi) > 0) |
| 1991 | ret = 1; |
| 1992 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1993 | } else |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1994 | ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len, |
| 1995 | &fi); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1996 | |
| 1997 | random_add_randomness(&fi, sizeof(fi)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1998 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1999 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2003 | static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2004 | size_t len, u16 stype, int ok, int link_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2005 | { |
| 2006 | struct ieee80211_hdr *hdr; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2007 | struct hostapd_data *orig_hapd, *tmp_hapd; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 2008 | const u8 *bssid; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2009 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2010 | orig_hapd = hapd; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2011 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2012 | hdr = (struct ieee80211_hdr *) buf; |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2013 | hapd = switch_link_hapd(hapd, link_id); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 2014 | bssid = get_hdr_bssid(hdr, len); |
| 2015 | tmp_hapd = get_hapd_bssid(hapd->iface, bssid, link_id); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2016 | if (tmp_hapd) { |
| 2017 | hapd = tmp_hapd; |
| 2018 | #ifdef CONFIG_IEEE80211BE |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 2019 | } else if (hapd->conf->mld_ap && bssid && |
| 2020 | ether_addr_equal(hapd->mld->mld_addr, bssid)) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2021 | /* AP MLD address match - use hapd pointer as-is */ |
| 2022 | #endif /* CONFIG_IEEE80211BE */ |
| 2023 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2024 | return; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2025 | } |
| 2026 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2027 | if (hapd == HAPD_BROADCAST) { |
| 2028 | if (stype != WLAN_FC_STYPE_ACTION || len <= 25 || |
| 2029 | buf[24] != WLAN_ACTION_PUBLIC) |
| 2030 | return; |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2031 | hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2, link_id); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2032 | if (!hapd || hapd == HAPD_BROADCAST) |
| 2033 | return; |
| 2034 | /* |
| 2035 | * Allow processing of TX status for a Public Action frame that |
| 2036 | * used wildcard BBSID. |
| 2037 | */ |
| 2038 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2039 | ieee802_11_mgmt_cb(hapd, buf, len, stype, ok); |
| 2040 | } |
| 2041 | |
| 2042 | #endif /* NEED_AP_MLME */ |
| 2043 | |
| 2044 | |
| 2045 | static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr) |
| 2046 | { |
| 2047 | struct sta_info *sta = ap_get_sta(hapd, addr); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2048 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2049 | if (sta) |
| 2050 | return 0; |
| 2051 | |
| 2052 | wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR |
| 2053 | " - adding a new STA", MAC2STR(addr)); |
| 2054 | sta = ap_sta_add(hapd, addr); |
| 2055 | if (sta) { |
| 2056 | hostapd_new_assoc_sta(hapd, sta, 0); |
| 2057 | } else { |
| 2058 | wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR, |
| 2059 | MAC2STR(addr)); |
| 2060 | return -1; |
| 2061 | } |
| 2062 | |
| 2063 | return 0; |
| 2064 | } |
| 2065 | |
| 2066 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2067 | static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src, |
| 2068 | const u8 *data, size_t data_len, |
| 2069 | enum frame_encryption encrypted, |
| 2070 | int link_id) |
| 2071 | { |
| 2072 | struct hostapd_data *orig_hapd = hapd; |
| 2073 | |
| 2074 | #ifdef CONFIG_IEEE80211BE |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2075 | hapd = switch_link_hapd(hapd, link_id); |
| 2076 | hapd = hostapd_find_by_sta(hapd->iface, src, true, NULL); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2077 | #else /* CONFIG_IEEE80211BE */ |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2078 | hapd = hostapd_find_by_sta(hapd->iface, src, false, NULL); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2079 | #endif /* CONFIG_IEEE80211BE */ |
| 2080 | |
| 2081 | if (!hapd) { |
| 2082 | /* WLAN cases need to have an existing association, but non-WLAN |
| 2083 | * cases (mainly, wired IEEE 802.1X) need to be able to process |
| 2084 | * EAPOL frames from new devices that do not yet have a STA |
| 2085 | * entry and as such, do not get a match in |
| 2086 | * hostapd_find_by_sta(). */ |
| 2087 | wpa_printf(MSG_DEBUG, |
| 2088 | "No STA-specific hostapd instance for EAPOL RX found - fall back to initial context"); |
| 2089 | hapd = orig_hapd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2090 | } |
| 2091 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 2092 | ieee802_1x_receive(hapd, src, data, data_len, encrypted); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2095 | #endif /* HOSTAPD */ |
| 2096 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2097 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2098 | static struct hostapd_channel_data * |
| 2099 | hostapd_get_mode_chan(struct hostapd_hw_modes *mode, unsigned int freq) |
| 2100 | { |
| 2101 | int i; |
| 2102 | struct hostapd_channel_data *chan; |
| 2103 | |
| 2104 | for (i = 0; i < mode->num_channels; i++) { |
| 2105 | chan = &mode->channels[i]; |
| 2106 | if ((unsigned int) chan->freq == freq) |
| 2107 | return chan; |
| 2108 | } |
| 2109 | |
| 2110 | return NULL; |
| 2111 | } |
| 2112 | |
| 2113 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2114 | static struct hostapd_channel_data * hostapd_get_mode_channel( |
| 2115 | struct hostapd_iface *iface, unsigned int freq) |
| 2116 | { |
| 2117 | int i; |
| 2118 | struct hostapd_channel_data *chan; |
| 2119 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2120 | for (i = 0; i < iface->num_hw_features; i++) { |
| 2121 | if (hostapd_hw_skip_mode(iface, &iface->hw_features[i])) |
| 2122 | continue; |
| 2123 | chan = hostapd_get_mode_chan(&iface->hw_features[i], freq); |
| 2124 | if (chan) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2125 | return chan; |
| 2126 | } |
| 2127 | |
| 2128 | return NULL; |
| 2129 | } |
| 2130 | |
| 2131 | |
| 2132 | static void hostapd_update_nf(struct hostapd_iface *iface, |
| 2133 | struct hostapd_channel_data *chan, |
| 2134 | struct freq_survey *survey) |
| 2135 | { |
| 2136 | if (!iface->chans_surveyed) { |
| 2137 | chan->min_nf = survey->nf; |
| 2138 | iface->lowest_nf = survey->nf; |
| 2139 | } else { |
| 2140 | if (dl_list_empty(&chan->survey_list)) |
| 2141 | chan->min_nf = survey->nf; |
| 2142 | else if (survey->nf < chan->min_nf) |
| 2143 | chan->min_nf = survey->nf; |
| 2144 | if (survey->nf < iface->lowest_nf) |
| 2145 | iface->lowest_nf = survey->nf; |
| 2146 | } |
| 2147 | } |
| 2148 | |
| 2149 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2150 | static void hostapd_single_channel_get_survey(struct hostapd_iface *iface, |
| 2151 | struct survey_results *survey_res) |
| 2152 | { |
| 2153 | struct hostapd_channel_data *chan; |
| 2154 | struct freq_survey *survey; |
| 2155 | u64 divisor, dividend; |
| 2156 | |
| 2157 | survey = dl_list_first(&survey_res->survey_list, struct freq_survey, |
| 2158 | list); |
| 2159 | if (!survey || !survey->freq) |
| 2160 | return; |
| 2161 | |
| 2162 | chan = hostapd_get_mode_channel(iface, survey->freq); |
| 2163 | if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED) |
| 2164 | return; |
| 2165 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2166 | wpa_printf(MSG_DEBUG, |
| 2167 | "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)", |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2168 | survey->freq, |
| 2169 | (unsigned long int) survey->channel_time, |
| 2170 | (unsigned long int) survey->channel_time_busy); |
| 2171 | |
| 2172 | if (survey->channel_time > iface->last_channel_time && |
| 2173 | survey->channel_time > survey->channel_time_busy) { |
| 2174 | dividend = survey->channel_time_busy - |
| 2175 | iface->last_channel_time_busy; |
| 2176 | divisor = survey->channel_time - iface->last_channel_time; |
| 2177 | |
| 2178 | iface->channel_utilization = dividend * 255 / divisor; |
| 2179 | wpa_printf(MSG_DEBUG, "Channel Utilization: %d", |
| 2180 | iface->channel_utilization); |
| 2181 | } |
| 2182 | iface->last_channel_time = survey->channel_time; |
| 2183 | iface->last_channel_time_busy = survey->channel_time_busy; |
| 2184 | } |
| 2185 | |
| 2186 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2187 | void hostapd_event_get_survey(struct hostapd_iface *iface, |
| 2188 | struct survey_results *survey_results) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2189 | { |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2190 | struct freq_survey *survey, *tmp; |
| 2191 | struct hostapd_channel_data *chan; |
| 2192 | |
| 2193 | if (dl_list_empty(&survey_results->survey_list)) { |
| 2194 | wpa_printf(MSG_DEBUG, "No survey data received"); |
| 2195 | return; |
| 2196 | } |
| 2197 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2198 | if (survey_results->freq_filter) { |
| 2199 | hostapd_single_channel_get_survey(iface, survey_results); |
| 2200 | return; |
| 2201 | } |
| 2202 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2203 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 2204 | struct freq_survey, list) { |
| 2205 | chan = hostapd_get_mode_channel(iface, survey->freq); |
| 2206 | if (!chan) |
| 2207 | continue; |
| 2208 | if (chan->flag & HOSTAPD_CHAN_DISABLED) |
| 2209 | continue; |
| 2210 | |
| 2211 | dl_list_del(&survey->list); |
| 2212 | dl_list_add_tail(&chan->survey_list, &survey->list); |
| 2213 | |
| 2214 | hostapd_update_nf(iface, chan, survey); |
| 2215 | |
| 2216 | iface->chans_surveyed++; |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2221 | #ifdef HOSTAPD |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2222 | #ifdef NEED_AP_MLME |
| 2223 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 2224 | static void hostapd_event_iface_unavailable(struct hostapd_data *hapd) |
| 2225 | { |
| 2226 | wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped", |
| 2227 | hapd->conf->iface); |
| 2228 | |
| 2229 | if (hapd->csa_in_progress) { |
| 2230 | wpa_printf(MSG_INFO, "CSA failed (%s was stopped)", |
| 2231 | hapd->conf->iface); |
| 2232 | hostapd_switch_channel_fallback(hapd->iface, |
| 2233 | &hapd->cs_freq_params); |
| 2234 | } |
Yu Ouyang | 378d3c4 | 2021-08-20 17:31:08 +0800 | [diff] [blame] | 2235 | |
| 2236 | // inform framework that interface is unavailable |
| 2237 | hostapd_disable_iface(hapd->iface); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2241 | static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd, |
| 2242 | struct dfs_event *radar) |
| 2243 | { |
| 2244 | wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2245 | hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2246 | radar->chan_offset, radar->chan_width, |
| 2247 | radar->cf1, radar->cf2); |
| 2248 | } |
| 2249 | |
| 2250 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2251 | static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd, |
| 2252 | struct dfs_event *radar) |
| 2253 | { |
| 2254 | wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq); |
| 2255 | hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled, |
| 2256 | radar->chan_offset, radar->chan_width, |
| 2257 | radar->cf1, radar->cf2); |
| 2258 | } |
| 2259 | |
| 2260 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2261 | static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd, |
| 2262 | struct dfs_event *radar) |
| 2263 | { |
| 2264 | wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2265 | hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2266 | radar->chan_offset, radar->chan_width, |
| 2267 | radar->cf1, radar->cf2); |
| 2268 | } |
| 2269 | |
| 2270 | |
| 2271 | static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd, |
| 2272 | struct dfs_event *radar) |
| 2273 | { |
| 2274 | wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2275 | hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2276 | radar->chan_offset, radar->chan_width, |
| 2277 | radar->cf1, radar->cf2); |
| 2278 | } |
| 2279 | |
| 2280 | |
| 2281 | static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd, |
| 2282 | struct dfs_event *radar) |
| 2283 | { |
| 2284 | wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2285 | hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2286 | radar->chan_offset, radar->chan_width, |
| 2287 | radar->cf1, radar->cf2); |
| 2288 | } |
| 2289 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2290 | |
| 2291 | static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd, |
| 2292 | struct dfs_event *radar) |
| 2293 | { |
| 2294 | wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq); |
| 2295 | hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled, |
| 2296 | radar->chan_offset, radar->chan_width, |
| 2297 | radar->cf1, radar->cf2); |
| 2298 | } |
| 2299 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2300 | #endif /* NEED_AP_MLME */ |
| 2301 | |
| 2302 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2303 | static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd, |
| 2304 | int istatus, |
| 2305 | const char *ifname, |
| 2306 | const u8 *addr) |
| 2307 | { |
| 2308 | struct sta_info *sta = ap_get_sta(hapd, addr); |
| 2309 | |
| 2310 | if (sta) { |
| 2311 | os_free(sta->ifname_wds); |
| 2312 | if (istatus == INTERFACE_ADDED) |
| 2313 | sta->ifname_wds = os_strdup(ifname); |
| 2314 | else |
| 2315 | sta->ifname_wds = NULL; |
| 2316 | } |
| 2317 | |
| 2318 | wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR, |
| 2319 | istatus == INTERFACE_ADDED ? |
| 2320 | WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED, |
| 2321 | ifname, MAC2STR(addr)); |
| 2322 | } |
| 2323 | |
| 2324 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2325 | #ifdef CONFIG_OWE |
| 2326 | static int hostapd_notif_update_dh_ie(struct hostapd_data *hapd, |
| 2327 | const u8 *peer, const u8 *ie, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2328 | size_t ie_len, const u8 *link_addr) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2329 | { |
| 2330 | u16 status; |
| 2331 | struct sta_info *sta; |
| 2332 | struct ieee802_11_elems elems; |
| 2333 | |
| 2334 | if (!hapd || !hapd->wpa_auth) { |
| 2335 | wpa_printf(MSG_DEBUG, "OWE: Invalid hapd context"); |
| 2336 | return -1; |
| 2337 | } |
| 2338 | if (!peer) { |
| 2339 | wpa_printf(MSG_DEBUG, "OWE: Peer unknown"); |
| 2340 | return -1; |
| 2341 | } |
| 2342 | if (!(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) { |
| 2343 | wpa_printf(MSG_DEBUG, "OWE: No OWE AKM configured"); |
| 2344 | status = WLAN_STATUS_AKMP_NOT_VALID; |
| 2345 | goto err; |
| 2346 | } |
| 2347 | if (ieee802_11_parse_elems(ie, ie_len, &elems, 1) == ParseFailed) { |
| 2348 | wpa_printf(MSG_DEBUG, "OWE: Failed to parse OWE IE for " |
| 2349 | MACSTR, MAC2STR(peer)); |
| 2350 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2351 | goto err; |
| 2352 | } |
| 2353 | status = owe_validate_request(hapd, peer, elems.rsn_ie, |
| 2354 | elems.rsn_ie_len, |
| 2355 | elems.owe_dh, elems.owe_dh_len); |
| 2356 | if (status != WLAN_STATUS_SUCCESS) |
| 2357 | goto err; |
| 2358 | |
| 2359 | sta = ap_get_sta(hapd, peer); |
| 2360 | if (sta) { |
| 2361 | ap_sta_no_session_timeout(hapd, sta); |
| 2362 | accounting_sta_stop(hapd, sta); |
| 2363 | |
| 2364 | /* |
| 2365 | * Make sure that the previously registered inactivity timer |
| 2366 | * will not remove the STA immediately. |
| 2367 | */ |
| 2368 | sta->timeout_next = STA_NULLFUNC; |
| 2369 | } else { |
| 2370 | sta = ap_sta_add(hapd, peer); |
| 2371 | if (!sta) { |
| 2372 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2373 | goto err; |
| 2374 | } |
| 2375 | } |
| 2376 | sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); |
| 2377 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2378 | #ifdef CONFIG_IEEE80211BE |
| 2379 | if (link_addr) { |
| 2380 | struct mld_info *info = &sta->mld_info; |
| 2381 | u8 link_id = hapd->mld_link_id; |
| 2382 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2383 | ap_sta_set_mld(sta, true); |
| 2384 | sta->mld_assoc_link_id = link_id; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2385 | os_memcpy(info->common_info.mld_addr, peer, ETH_ALEN); |
| 2386 | info->links[link_id].valid = true; |
| 2387 | os_memcpy(info->links[link_id].local_addr, hapd->own_addr, |
| 2388 | ETH_ALEN); |
| 2389 | os_memcpy(info->links[link_id].peer_addr, link_addr, ETH_ALEN); |
| 2390 | } |
| 2391 | #endif /* CONFIG_IEEE80211BE */ |
| 2392 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2393 | status = owe_process_rsn_ie(hapd, sta, elems.rsn_ie, |
| 2394 | elems.rsn_ie_len, elems.owe_dh, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2395 | elems.owe_dh_len, link_addr); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2396 | if (status != WLAN_STATUS_SUCCESS) |
| 2397 | ap_free_sta(hapd, sta); |
| 2398 | |
| 2399 | return 0; |
| 2400 | err: |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2401 | hostapd_drv_update_dh_ie(hapd, link_addr ? link_addr : peer, status, |
| 2402 | NULL, 0); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2403 | return 0; |
| 2404 | } |
| 2405 | #endif /* CONFIG_OWE */ |
| 2406 | |
| 2407 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2408 | #ifdef NEED_AP_MLME |
| 2409 | static void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst, |
| 2410 | const u8 *data, size_t len, int ack, |
| 2411 | int link_id) |
| 2412 | { |
| 2413 | struct sta_info *sta; |
| 2414 | |
| 2415 | hapd = switch_link_hapd(hapd, link_id); |
| 2416 | hapd = hostapd_find_by_sta(hapd->iface, dst, false, &sta); |
| 2417 | |
| 2418 | if (!sta) { |
| 2419 | wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA " |
| 2420 | MACSTR " that is not currently associated", |
| 2421 | MAC2STR(dst)); |
| 2422 | return; |
| 2423 | } |
| 2424 | |
| 2425 | ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack); |
| 2426 | } |
| 2427 | #endif /* NEED_AP_MLME */ |
| 2428 | |
| 2429 | |
| 2430 | #ifdef CONFIG_IEEE80211AX |
| 2431 | static void hostapd_event_color_change(struct hostapd_data *hapd, bool success) |
| 2432 | { |
| 2433 | struct hostapd_data *bss; |
| 2434 | size_t i; |
| 2435 | |
| 2436 | for (i = 0; i < hapd->iface->num_bss; i++) { |
| 2437 | bss = hapd->iface->bss[i]; |
| 2438 | if (bss->cca_color == 0) |
| 2439 | continue; |
| 2440 | |
| 2441 | if (success) |
| 2442 | hapd->iface->conf->he_op.he_bss_color = bss->cca_color; |
| 2443 | |
| 2444 | bss->cca_in_progress = 0; |
| 2445 | if (ieee802_11_set_beacon(bss)) { |
| 2446 | wpa_printf(MSG_ERROR, "Failed to remove BCCA element"); |
| 2447 | bss->cca_in_progress = 1; |
| 2448 | } else { |
| 2449 | hostapd_cleanup_cca_params(bss); |
| 2450 | } |
| 2451 | } |
| 2452 | } |
| 2453 | #endif /* CONFIG_IEEE80211AX */ |
| 2454 | |
| 2455 | |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 2456 | static void hostapd_iface_enable(struct hostapd_data *hapd) |
| 2457 | { |
| 2458 | wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED); |
| 2459 | if (hapd->disabled && hapd->started) { |
| 2460 | hapd->disabled = 0; |
| 2461 | /* |
| 2462 | * Try to re-enable interface if the driver stopped it |
| 2463 | * when the interface got disabled. |
| 2464 | */ |
| 2465 | if (hapd->wpa_auth) |
| 2466 | wpa_auth_reconfig_group_keys(hapd->wpa_auth); |
| 2467 | else |
| 2468 | hostapd_reconfig_encryption(hapd); |
| 2469 | hapd->reenable_beacon = 1; |
| 2470 | ieee802_11_set_beacon(hapd); |
| 2471 | #ifdef NEED_AP_MLME |
| 2472 | } else if (hapd->disabled && hapd->iface->cac_started) { |
| 2473 | wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC"); |
| 2474 | hostapd_handle_dfs(hapd->iface); |
| 2475 | #endif /* NEED_AP_MLME */ |
| 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | |
| 2480 | static void hostapd_iface_disable(struct hostapd_data *hapd) |
| 2481 | { |
| 2482 | hostapd_free_stas(hapd); |
| 2483 | wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED); |
| 2484 | hapd->disabled = 1; |
| 2485 | } |
| 2486 | |
| 2487 | |
| 2488 | #ifdef CONFIG_IEEE80211BE |
| 2489 | |
| 2490 | static void hostapd_mld_iface_enable(struct hostapd_data *hapd) |
| 2491 | { |
| 2492 | struct hostapd_data *first_link, *link_bss; |
| 2493 | |
| 2494 | first_link = hostapd_mld_is_first_bss(hapd) ? hapd : |
| 2495 | hostapd_mld_get_first_bss(hapd); |
| 2496 | |
| 2497 | /* Links have been removed. Re-add all links and enable them, but |
| 2498 | * enable the first link BSS before doing that. */ |
| 2499 | if (hostapd_drv_link_add(first_link, first_link->mld_link_id, |
| 2500 | first_link->own_addr)) { |
| 2501 | wpa_printf(MSG_ERROR, "MLD: Failed to re-add link %d in MLD %s", |
| 2502 | first_link->mld_link_id, first_link->conf->iface); |
| 2503 | return; |
| 2504 | } |
| 2505 | |
| 2506 | hostapd_iface_enable(first_link); |
| 2507 | |
| 2508 | /* Add other affiliated links */ |
| 2509 | for_each_mld_link(link_bss, first_link) { |
| 2510 | if (link_bss == first_link) |
| 2511 | continue; |
| 2512 | |
| 2513 | if (hostapd_drv_link_add(link_bss, link_bss->mld_link_id, |
| 2514 | link_bss->own_addr)) { |
| 2515 | wpa_printf(MSG_ERROR, |
| 2516 | "MLD: Failed to re-add link %d in MLD %s", |
| 2517 | link_bss->mld_link_id, |
| 2518 | link_bss->conf->iface); |
| 2519 | continue; |
| 2520 | } |
| 2521 | |
| 2522 | hostapd_iface_enable(link_bss); |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | |
| 2527 | static void hostapd_mld_iface_disable(struct hostapd_data *hapd) |
| 2528 | { |
| 2529 | struct hostapd_data *link_bss; |
| 2530 | |
| 2531 | for_each_mld_link(link_bss, hapd) |
| 2532 | hostapd_iface_disable(link_bss); |
| 2533 | } |
| 2534 | |
| 2535 | #endif /* CONFIG_IEEE80211BE */ |
| 2536 | |
| 2537 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2538 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
| 2539 | union wpa_event_data *data) |
| 2540 | { |
| 2541 | struct hostapd_data *hapd = ctx; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2542 | struct sta_info *sta; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2543 | #ifndef CONFIG_NO_STDOUT_DEBUG |
| 2544 | int level = MSG_DEBUG; |
| 2545 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2546 | if (event == EVENT_RX_MGMT && data->rx_mgmt.frame && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2547 | data->rx_mgmt.frame_len >= 24) { |
| 2548 | const struct ieee80211_hdr *hdr; |
| 2549 | u16 fc; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2550 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2551 | hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; |
| 2552 | fc = le_to_host16(hdr->frame_control); |
| 2553 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 2554 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) |
| 2555 | level = MSG_EXCESSIVE; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2556 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 2557 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ) |
| 2558 | level = MSG_EXCESSIVE; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received", |
| 2562 | event_to_string(event), event); |
| 2563 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2564 | |
| 2565 | switch (event) { |
| 2566 | case EVENT_MICHAEL_MIC_FAILURE: |
| 2567 | michael_mic_failure(hapd, data->michael_mic_failure.src, 1); |
| 2568 | break; |
| 2569 | case EVENT_SCAN_RESULTS: |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2570 | #ifdef NEED_AP_MLME |
| 2571 | if (data) |
| 2572 | hapd = switch_link_scan(hapd, |
| 2573 | data->scan_info.scan_cookie); |
| 2574 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2575 | if (hapd->iface->scan_cb) |
| 2576 | hapd->iface->scan_cb(hapd->iface); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2577 | #ifdef CONFIG_IEEE80211BE |
| 2578 | if (!hapd->iface->scan_cb && hapd->conf->mld_ap) { |
| 2579 | /* Other links may be waiting for HT scan result */ |
| 2580 | unsigned int i; |
| 2581 | |
| 2582 | for (i = 0; i < hapd->iface->interfaces->count; i++) { |
| 2583 | struct hostapd_iface *h = |
| 2584 | hapd->iface->interfaces->iface[i]; |
| 2585 | struct hostapd_data *h_hapd = h->bss[0]; |
| 2586 | |
| 2587 | if (hostapd_is_ml_partner(hapd, h_hapd) && |
| 2588 | h_hapd->iface->scan_cb) |
| 2589 | h_hapd->iface->scan_cb(h_hapd->iface); |
| 2590 | } |
| 2591 | } |
| 2592 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2593 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2594 | case EVENT_WPS_BUTTON_PUSHED: |
| 2595 | hostapd_wps_button_pushed(hapd, NULL); |
| 2596 | break; |
| 2597 | #ifdef NEED_AP_MLME |
| 2598 | case EVENT_TX_STATUS: |
| 2599 | switch (data->tx_status.type) { |
| 2600 | case WLAN_FC_TYPE_MGMT: |
| 2601 | hostapd_mgmt_tx_cb(hapd, data->tx_status.data, |
| 2602 | data->tx_status.data_len, |
| 2603 | data->tx_status.stype, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2604 | data->tx_status.ack, |
| 2605 | data->tx_status.link_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2606 | break; |
| 2607 | case WLAN_FC_TYPE_DATA: |
| 2608 | hostapd_tx_status(hapd, data->tx_status.dst, |
| 2609 | data->tx_status.data, |
| 2610 | data->tx_status.data_len, |
| 2611 | data->tx_status.ack); |
| 2612 | break; |
| 2613 | } |
| 2614 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2615 | case EVENT_EAPOL_TX_STATUS: |
| 2616 | hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst, |
| 2617 | data->eapol_tx_status.data, |
| 2618 | data->eapol_tx_status.data_len, |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2619 | data->eapol_tx_status.ack, |
| 2620 | data->eapol_tx_status.link_id); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2621 | break; |
| 2622 | case EVENT_DRIVER_CLIENT_POLL_OK: |
| 2623 | hostapd_client_poll_ok(hapd, data->client_poll.addr); |
| 2624 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2625 | case EVENT_RX_FROM_UNKNOWN: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2626 | hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid, |
| 2627 | data->rx_from_unknown.addr, |
| 2628 | data->rx_from_unknown.wds); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2629 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2630 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2631 | case EVENT_RX_MGMT: |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2632 | if (!data->rx_mgmt.frame) |
| 2633 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2634 | #ifdef NEED_AP_MLME |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2635 | hostapd_mgmt_rx(hapd, &data->rx_mgmt); |
| 2636 | #else /* NEED_AP_MLME */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2637 | hostapd_action_rx(hapd, &data->rx_mgmt); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2638 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2639 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2640 | case EVENT_RX_PROBE_REQ: |
| 2641 | if (data->rx_probe_req.sa == NULL || |
| 2642 | data->rx_probe_req.ie == NULL) |
| 2643 | break; |
| 2644 | hostapd_probe_req_rx(hapd, data->rx_probe_req.sa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2645 | data->rx_probe_req.da, |
| 2646 | data->rx_probe_req.bssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2647 | data->rx_probe_req.ie, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2648 | data->rx_probe_req.ie_len, |
| 2649 | data->rx_probe_req.ssi_signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2650 | break; |
| 2651 | case EVENT_NEW_STA: |
| 2652 | hostapd_event_new_sta(hapd, data->new_sta.addr); |
| 2653 | break; |
| 2654 | case EVENT_EAPOL_RX: |
| 2655 | hostapd_event_eapol_rx(hapd, data->eapol_rx.src, |
| 2656 | data->eapol_rx.data, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 2657 | data->eapol_rx.data_len, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2658 | data->eapol_rx.encrypted, |
| 2659 | data->eapol_rx.link_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2660 | break; |
| 2661 | case EVENT_ASSOC: |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2662 | if (!data) |
| 2663 | return; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2664 | #ifdef CONFIG_IEEE80211BE |
| 2665 | if (data->assoc_info.assoc_link_id != -1) { |
| 2666 | hapd = hostapd_mld_get_link_bss( |
| 2667 | hapd, data->assoc_info.assoc_link_id); |
| 2668 | if (!hapd) { |
| 2669 | wpa_printf(MSG_ERROR, |
| 2670 | "MLD: Failed to get link BSS for EVENT_ASSOC"); |
| 2671 | return; |
| 2672 | } |
| 2673 | } |
| 2674 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2675 | hostapd_notif_assoc(hapd, data->assoc_info.addr, |
| 2676 | data->assoc_info.req_ies, |
| 2677 | data->assoc_info.req_ies_len, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2678 | data->assoc_info.resp_ies, |
| 2679 | data->assoc_info.resp_ies_len, |
| 2680 | data->assoc_info.link_addr, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2681 | data->assoc_info.reassoc); |
| 2682 | break; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2683 | case EVENT_PORT_AUTHORIZED: |
| 2684 | /* Port authorized event for an associated STA */ |
| 2685 | sta = ap_get_sta(hapd, data->port_authorized.sta_addr); |
| 2686 | if (sta) |
| 2687 | ap_sta_set_authorized(hapd, sta, 1); |
| 2688 | else |
| 2689 | wpa_printf(MSG_DEBUG, |
| 2690 | "No STA info matching port authorized event found"); |
| 2691 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2692 | #ifdef CONFIG_OWE |
| 2693 | case EVENT_UPDATE_DH: |
| 2694 | if (!data) |
| 2695 | return; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2696 | #ifdef CONFIG_IEEE80211BE |
| 2697 | if (data->update_dh.assoc_link_id != -1) { |
| 2698 | hapd = hostapd_mld_get_link_bss( |
| 2699 | hapd, data->update_dh.assoc_link_id); |
| 2700 | if (!hapd) { |
| 2701 | wpa_printf(MSG_ERROR, |
| 2702 | "MLD: Failed to get link BSS for EVENT_UPDATE_DH assoc_link_id=%d", |
| 2703 | data->update_dh.assoc_link_id); |
| 2704 | return; |
| 2705 | } |
| 2706 | } |
| 2707 | #endif /* CONFIG_IEEE80211BE */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2708 | hostapd_notif_update_dh_ie(hapd, data->update_dh.peer, |
| 2709 | data->update_dh.ie, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2710 | data->update_dh.ie_len, |
| 2711 | data->update_dh.link_addr); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2712 | break; |
| 2713 | #endif /* CONFIG_OWE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2714 | case EVENT_DISASSOC: |
| 2715 | if (data) |
| 2716 | hostapd_notif_disassoc(hapd, data->disassoc_info.addr); |
| 2717 | break; |
| 2718 | case EVENT_DEAUTH: |
| 2719 | if (data) |
| 2720 | hostapd_notif_disassoc(hapd, data->deauth_info.addr); |
| 2721 | break; |
| 2722 | case EVENT_STATION_LOW_ACK: |
| 2723 | if (!data) |
| 2724 | break; |
| 2725 | hostapd_event_sta_low_ack(hapd, data->low_ack.addr); |
| 2726 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2727 | case EVENT_AUTH: |
| 2728 | hostapd_notif_auth(hapd, &data->auth); |
| 2729 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2730 | case EVENT_CH_SWITCH_STARTED: |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2731 | case EVENT_CH_SWITCH: |
| 2732 | if (!data) |
| 2733 | break; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2734 | #ifdef CONFIG_IEEE80211BE |
| 2735 | if (data->ch_switch.link_id != -1) { |
| 2736 | hapd = hostapd_mld_get_link_bss( |
| 2737 | hapd, data->ch_switch.link_id); |
| 2738 | if (!hapd) { |
| 2739 | wpa_printf(MSG_ERROR, |
| 2740 | "MLD: Failed to get link (ID %d) BSS for EVENT_CH_SWITCH/EVENT_CH_SWITCH_STARTED", |
| 2741 | data->ch_switch.link_id); |
| 2742 | break; |
| 2743 | } |
| 2744 | } |
| 2745 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2746 | hostapd_event_ch_switch(hapd, data->ch_switch.freq, |
| 2747 | data->ch_switch.ht_enabled, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2748 | data->ch_switch.ch_offset, |
| 2749 | data->ch_switch.ch_width, |
| 2750 | data->ch_switch.cf1, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2751 | data->ch_switch.cf2, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2752 | data->ch_switch.punct_bitmap, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2753 | event == EVENT_CH_SWITCH); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2754 | break; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2755 | case EVENT_CONNECT_FAILED_REASON: |
| 2756 | if (!data) |
| 2757 | break; |
| 2758 | hostapd_event_connect_failed_reason( |
| 2759 | hapd, data->connect_failed_reason.addr, |
| 2760 | data->connect_failed_reason.code); |
| 2761 | break; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2762 | case EVENT_SURVEY: |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2763 | hostapd_event_get_survey(hapd->iface, &data->survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2764 | break; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2765 | #ifdef NEED_AP_MLME |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 2766 | case EVENT_INTERFACE_UNAVAILABLE: |
| 2767 | hostapd_event_iface_unavailable(hapd); |
| 2768 | break; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2769 | case EVENT_DFS_RADAR_DETECTED: |
| 2770 | if (!data) |
| 2771 | break; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2772 | hapd = switch_link_hapd(hapd, data->dfs_event.link_id); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2773 | hostapd_event_dfs_radar_detected(hapd, &data->dfs_event); |
| 2774 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2775 | case EVENT_DFS_PRE_CAC_EXPIRED: |
| 2776 | if (!data) |
| 2777 | break; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2778 | hapd = switch_link_hapd(hapd, data->dfs_event.link_id); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2779 | hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event); |
| 2780 | break; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2781 | case EVENT_DFS_CAC_FINISHED: |
| 2782 | if (!data) |
| 2783 | break; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2784 | hapd = switch_link_hapd(hapd, data->dfs_event.link_id); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2785 | hostapd_event_dfs_cac_finished(hapd, &data->dfs_event); |
| 2786 | break; |
| 2787 | case EVENT_DFS_CAC_ABORTED: |
| 2788 | if (!data) |
| 2789 | break; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2790 | hapd = switch_link_hapd(hapd, data->dfs_event.link_id); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2791 | hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event); |
| 2792 | break; |
| 2793 | case EVENT_DFS_NOP_FINISHED: |
| 2794 | if (!data) |
| 2795 | break; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2796 | hapd = switch_link_hapd(hapd, data->dfs_event.link_id); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2797 | hostapd_event_dfs_nop_finished(hapd, &data->dfs_event); |
| 2798 | break; |
| 2799 | case EVENT_CHANNEL_LIST_CHANGED: |
| 2800 | /* channel list changed (regulatory?), update channel list */ |
| 2801 | /* TODO: check this. hostapd_get_hw_features() initializes |
| 2802 | * too much stuff. */ |
| 2803 | /* hostapd_get_hw_features(hapd->iface); */ |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2804 | hostapd_channel_list_updated( |
| 2805 | hapd->iface, data->channel_list_changed.initiator); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2806 | break; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2807 | case EVENT_DFS_CAC_STARTED: |
| 2808 | if (!data) |
| 2809 | break; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2810 | hapd = switch_link_hapd(hapd, data->dfs_event.link_id); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2811 | hostapd_event_dfs_cac_started(hapd, &data->dfs_event); |
| 2812 | break; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2813 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2814 | case EVENT_INTERFACE_ENABLED: |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 2815 | #ifdef CONFIG_IEEE80211BE |
| 2816 | if (hapd->conf->mld_ap) { |
| 2817 | hostapd_mld_iface_enable(hapd); |
| 2818 | break; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2819 | } |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 2820 | #endif /* CONFIG_IEEE80211BE */ |
| 2821 | hostapd_iface_enable(hapd); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2822 | break; |
| 2823 | case EVENT_INTERFACE_DISABLED: |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 2824 | #ifdef CONFIG_IEEE80211BE |
| 2825 | if (hapd->conf->mld_ap) { |
| 2826 | hostapd_mld_iface_disable(hapd); |
| 2827 | break; |
| 2828 | } |
| 2829 | #endif /* CONFIG_IEEE80211BE */ |
| 2830 | hostapd_iface_disable(hapd); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2831 | break; |
| 2832 | #ifdef CONFIG_ACS |
| 2833 | case EVENT_ACS_CHANNEL_SELECTED: |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 2834 | hostapd_acs_channel_selected(hapd, |
| 2835 | &data->acs_selected_channels); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2836 | break; |
| 2837 | #endif /* CONFIG_ACS */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2838 | case EVENT_STATION_OPMODE_CHANGED: |
| 2839 | hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr, |
| 2840 | data->sta_opmode.smps_mode, |
| 2841 | data->sta_opmode.chan_width, |
| 2842 | data->sta_opmode.rx_nss); |
| 2843 | break; |
| 2844 | case EVENT_WDS_STA_INTERFACE_STATUS: |
| 2845 | hostapd_event_wds_sta_interface_status( |
| 2846 | hapd, data->wds_sta_interface.istatus, |
| 2847 | data->wds_sta_interface.ifname, |
| 2848 | data->wds_sta_interface.sta_addr); |
| 2849 | break; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2850 | #ifdef CONFIG_IEEE80211AX |
| 2851 | case EVENT_BSS_COLOR_COLLISION: |
| 2852 | /* The BSS color is shared amongst all BBSs on a specific phy. |
| 2853 | * Therefore we always start the color change on the primary |
| 2854 | * BSS. */ |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2855 | hapd = switch_link_hapd(hapd, |
| 2856 | data->bss_color_collision.link_id); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2857 | wpa_printf(MSG_DEBUG, "BSS color collision on %s", |
| 2858 | hapd->conf->iface); |
| 2859 | hostapd_switch_color(hapd->iface->bss[0], |
| 2860 | data->bss_color_collision.bitmap); |
| 2861 | break; |
| 2862 | case EVENT_CCA_STARTED_NOTIFY: |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2863 | hapd = switch_link_hapd(hapd, |
| 2864 | data->bss_color_collision.link_id); |
| 2865 | wpa_printf(MSG_DEBUG, "CCA started on %s", |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2866 | hapd->conf->iface); |
| 2867 | break; |
| 2868 | case EVENT_CCA_ABORTED_NOTIFY: |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2869 | hapd = switch_link_hapd(hapd, |
| 2870 | data->bss_color_collision.link_id); |
| 2871 | wpa_printf(MSG_DEBUG, "CCA aborted on %s", |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2872 | hapd->conf->iface); |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2873 | hostapd_event_color_change(hapd, false); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2874 | break; |
| 2875 | case EVENT_CCA_NOTIFY: |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2876 | hapd = switch_link_hapd(hapd, |
| 2877 | data->bss_color_collision.link_id); |
| 2878 | wpa_printf(MSG_DEBUG, "CCA finished on %s", |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2879 | hapd->conf->iface); |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 2880 | hostapd_event_color_change(hapd, true); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2881 | break; |
| 2882 | #endif /* CONFIG_IEEE80211AX */ |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 2883 | #ifdef CONFIG_IEEE80211BE |
| 2884 | case EVENT_MLD_INTERFACE_FREED: |
| 2885 | wpa_printf(MSG_DEBUG, "MLD: Interface %s freed", |
| 2886 | hapd->conf->iface); |
| 2887 | hostapd_mld_interface_freed(hapd); |
| 2888 | break; |
| 2889 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2890 | default: |
| 2891 | wpa_printf(MSG_DEBUG, "Unknown event %d", event); |
| 2892 | break; |
| 2893 | } |
| 2894 | } |
| 2895 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 2896 | |
| 2897 | void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event, |
| 2898 | union wpa_event_data *data) |
| 2899 | { |
| 2900 | struct hapd_interfaces *interfaces = ctx; |
| 2901 | struct hostapd_data *hapd; |
| 2902 | |
| 2903 | if (event != EVENT_INTERFACE_STATUS) |
| 2904 | return; |
| 2905 | |
| 2906 | hapd = hostapd_get_iface(interfaces, data->interface_status.ifname); |
| 2907 | if (hapd && hapd->driver && hapd->driver->get_ifindex && |
| 2908 | hapd->drv_priv) { |
| 2909 | unsigned int ifindex; |
| 2910 | |
| 2911 | ifindex = hapd->driver->get_ifindex(hapd->drv_priv); |
| 2912 | if (ifindex != data->interface_status.ifindex) { |
| 2913 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, |
| 2914 | "interface status ifindex %d mismatch (%d)", |
| 2915 | ifindex, data->interface_status.ifindex); |
| 2916 | return; |
| 2917 | } |
| 2918 | } |
| 2919 | if (hapd) |
| 2920 | wpa_supplicant_event(hapd, event, data); |
| 2921 | } |
| 2922 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2923 | #endif /* HOSTAPD */ |