Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / Station table |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3 | * Copyright (c) 2002-2017, 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" |
| 12 | #include "utils/eloop.h" |
| 13 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 14 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 15 | #include "common/sae.h" |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 16 | #include "common/dpp.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 17 | #include "radius/radius.h" |
| 18 | #include "radius/radius_client.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 19 | #include "p2p/p2p.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 20 | #include "fst/fst.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 21 | #include "crypto/crypto.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 22 | #include "hostapd.h" |
| 23 | #include "accounting.h" |
| 24 | #include "ieee802_1x.h" |
| 25 | #include "ieee802_11.h" |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 26 | #include "ieee802_11_auth.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 27 | #include "wpa_auth.h" |
| 28 | #include "preauth_auth.h" |
| 29 | #include "ap_config.h" |
| 30 | #include "beacon.h" |
| 31 | #include "ap_mlme.h" |
| 32 | #include "vlan_init.h" |
| 33 | #include "p2p_hostapd.h" |
| 34 | #include "ap_drv_ops.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 35 | #include "gas_serv.h" |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 36 | #include "wnm_ap.h" |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 37 | #include "mbo_ap.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 38 | #include "ndisc_snoop.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 39 | #include "sta_info.h" |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 40 | #include "vlan.h" |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 41 | #include "wps_hostapd.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 42 | |
| 43 | static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd, |
| 44 | struct sta_info *sta); |
| 45 | static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 46 | static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 47 | static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx); |
| 48 | static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 49 | static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 50 | static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 51 | static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 52 | |
| 53 | int ap_for_each_sta(struct hostapd_data *hapd, |
| 54 | int (*cb)(struct hostapd_data *hapd, struct sta_info *sta, |
| 55 | void *ctx), |
| 56 | void *ctx) |
| 57 | { |
| 58 | struct sta_info *sta; |
| 59 | |
| 60 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 61 | if (cb(hapd, sta, ctx)) |
| 62 | return 1; |
| 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta) |
| 70 | { |
| 71 | struct sta_info *s; |
| 72 | |
| 73 | s = hapd->sta_hash[STA_HASH(sta)]; |
| 74 | while (s != NULL && os_memcmp(s->addr, sta, 6) != 0) |
| 75 | s = s->hnext; |
| 76 | return s; |
| 77 | } |
| 78 | |
| 79 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 80 | #ifdef CONFIG_P2P |
| 81 | struct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr) |
| 82 | { |
| 83 | struct sta_info *sta; |
| 84 | |
| 85 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 86 | const u8 *p2p_dev_addr; |
| 87 | |
| 88 | if (sta->p2p_ie == NULL) |
| 89 | continue; |
| 90 | |
| 91 | p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); |
| 92 | if (p2p_dev_addr == NULL) |
| 93 | continue; |
| 94 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 95 | if (ether_addr_equal(p2p_dev_addr, addr)) |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 96 | return sta; |
| 97 | } |
| 98 | |
| 99 | return NULL; |
| 100 | } |
| 101 | #endif /* CONFIG_P2P */ |
| 102 | |
| 103 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 104 | static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta) |
| 105 | { |
| 106 | struct sta_info *tmp; |
| 107 | |
| 108 | if (hapd->sta_list == sta) { |
| 109 | hapd->sta_list = sta->next; |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | tmp = hapd->sta_list; |
| 114 | while (tmp != NULL && tmp->next != sta) |
| 115 | tmp = tmp->next; |
| 116 | if (tmp == NULL) { |
| 117 | wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from " |
| 118 | "list.", MAC2STR(sta->addr)); |
| 119 | } else |
| 120 | tmp->next = sta->next; |
| 121 | } |
| 122 | |
| 123 | |
| 124 | void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta) |
| 125 | { |
| 126 | sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)]; |
| 127 | hapd->sta_hash[STA_HASH(sta->addr)] = sta; |
| 128 | } |
| 129 | |
| 130 | |
| 131 | static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta) |
| 132 | { |
| 133 | struct sta_info *s; |
| 134 | |
| 135 | s = hapd->sta_hash[STA_HASH(sta->addr)]; |
| 136 | if (s == NULL) return; |
| 137 | if (os_memcmp(s->addr, sta->addr, 6) == 0) { |
| 138 | hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext; |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | while (s->hnext != NULL && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 143 | !ether_addr_equal(s->hnext->addr, sta->addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 144 | s = s->hnext; |
| 145 | if (s->hnext != NULL) |
| 146 | s->hnext = s->hnext->hnext; |
| 147 | else |
| 148 | wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR |
| 149 | " from hash table", MAC2STR(sta->addr)); |
| 150 | } |
| 151 | |
| 152 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 153 | void ap_sta_ip6addr_del(struct hostapd_data *hapd, struct sta_info *sta) |
| 154 | { |
| 155 | sta_ip6addr_del(hapd, sta); |
| 156 | } |
| 157 | |
| 158 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 159 | #ifdef CONFIG_PASN |
| 160 | |
| 161 | void ap_free_sta_pasn(struct hostapd_data *hapd, struct sta_info *sta) |
| 162 | { |
| 163 | if (sta->pasn) { |
| 164 | wpa_printf(MSG_DEBUG, "PASN: Free PASN context: " MACSTR, |
| 165 | MAC2STR(sta->addr)); |
| 166 | |
| 167 | if (sta->pasn->ecdh) |
| 168 | crypto_ecdh_deinit(sta->pasn->ecdh); |
| 169 | |
| 170 | wpabuf_free(sta->pasn->secret); |
| 171 | sta->pasn->secret = NULL; |
| 172 | |
| 173 | #ifdef CONFIG_SAE |
| 174 | sae_clear_data(&sta->pasn->sae); |
| 175 | #endif /* CONFIG_SAE */ |
| 176 | |
| 177 | #ifdef CONFIG_FILS |
| 178 | /* In practice this pointer should be NULL */ |
| 179 | wpabuf_free(sta->pasn->fils.erp_resp); |
| 180 | sta->pasn->fils.erp_resp = NULL; |
| 181 | #endif /* CONFIG_FILS */ |
| 182 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 183 | pasn_data_deinit(sta->pasn); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 184 | sta->pasn = NULL; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | #endif /* CONFIG_PASN */ |
| 189 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 190 | |
| 191 | static void __ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta) |
| 192 | { |
| 193 | #ifdef CONFIG_IEEE80211BE |
| 194 | if (hostapd_sta_is_link_sta(hapd, sta) && |
| 195 | !hostapd_drv_link_sta_remove(hapd, sta->addr)) |
| 196 | return; |
| 197 | #endif /* CONFIG_IEEE80211BE */ |
| 198 | |
| 199 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 200 | } |
| 201 | |
| 202 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 203 | #ifdef CONFIG_IEEE80211BE |
| 204 | static void clear_wpa_sm_for_each_partner_link(struct hostapd_data *hapd, |
| 205 | struct sta_info *psta) |
| 206 | { |
| 207 | struct sta_info *lsta; |
| 208 | struct hostapd_data *lhapd; |
| 209 | |
| 210 | if (!ap_sta_is_mld(hapd, psta)) |
| 211 | return; |
| 212 | |
| 213 | for_each_mld_link(lhapd, hapd) { |
| 214 | if (lhapd == hapd) |
| 215 | continue; |
| 216 | |
| 217 | lsta = ap_get_sta(lhapd, psta->addr); |
| 218 | if (lsta) |
| 219 | lsta->wpa_sm = NULL; |
| 220 | } |
| 221 | } |
| 222 | #endif /* CONFIG_IEEE80211BE */ |
| 223 | |
| 224 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 225 | void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta) |
| 226 | { |
| 227 | int set_beacon = 0; |
| 228 | |
| 229 | accounting_sta_stop(hapd, sta); |
| 230 | |
| 231 | /* just in case */ |
| 232 | ap_sta_set_authorized(hapd, sta, 0); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 233 | hostapd_set_sta_flags(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 234 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 235 | if ((sta->flags & WLAN_STA_WDS) || |
| 236 | (sta->flags & WLAN_STA_MULTI_AP && |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 237 | (hapd->conf->multi_ap & BACKHAUL_BSS) && |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 238 | hapd->conf->wds_sta && |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 239 | !(sta->flags & WLAN_STA_WPS))) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 240 | hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 241 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 242 | if (sta->ipaddr) |
| 243 | hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr); |
| 244 | ap_sta_ip6addr_del(hapd, sta); |
| 245 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 246 | if (!hapd->iface->driver_ap_teardown && |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 247 | !(sta->flags & WLAN_STA_PREAUTH)) { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 248 | __ap_free_sta(hapd, sta); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 249 | sta->added_unassoc = 0; |
| 250 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 251 | |
| 252 | ap_sta_hash_del(hapd, sta); |
| 253 | ap_sta_list_del(hapd, sta); |
| 254 | |
| 255 | if (sta->aid > 0) |
| 256 | hapd->sta_aid[(sta->aid - 1) / 32] &= |
| 257 | ~BIT((sta->aid - 1) % 32); |
| 258 | |
| 259 | hapd->num_sta--; |
| 260 | if (sta->nonerp_set) { |
| 261 | sta->nonerp_set = 0; |
| 262 | hapd->iface->num_sta_non_erp--; |
| 263 | if (hapd->iface->num_sta_non_erp == 0) |
| 264 | set_beacon++; |
| 265 | } |
| 266 | |
| 267 | if (sta->no_short_slot_time_set) { |
| 268 | sta->no_short_slot_time_set = 0; |
| 269 | hapd->iface->num_sta_no_short_slot_time--; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 270 | if (hapd->iface->current_mode && |
| 271 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 272 | && hapd->iface->num_sta_no_short_slot_time == 0) |
| 273 | set_beacon++; |
| 274 | } |
| 275 | |
| 276 | if (sta->no_short_preamble_set) { |
| 277 | sta->no_short_preamble_set = 0; |
| 278 | hapd->iface->num_sta_no_short_preamble--; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 279 | if (hapd->iface->current_mode && |
| 280 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 281 | && hapd->iface->num_sta_no_short_preamble == 0) |
| 282 | set_beacon++; |
| 283 | } |
| 284 | |
| 285 | if (sta->no_ht_gf_set) { |
| 286 | sta->no_ht_gf_set = 0; |
| 287 | hapd->iface->num_sta_ht_no_gf--; |
| 288 | } |
| 289 | |
| 290 | if (sta->no_ht_set) { |
| 291 | sta->no_ht_set = 0; |
| 292 | hapd->iface->num_sta_no_ht--; |
| 293 | } |
| 294 | |
| 295 | if (sta->ht_20mhz_set) { |
| 296 | sta->ht_20mhz_set = 0; |
| 297 | hapd->iface->num_sta_ht_20mhz--; |
| 298 | } |
| 299 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 300 | #ifdef CONFIG_TAXONOMY |
| 301 | wpabuf_free(sta->probe_ie_taxonomy); |
| 302 | sta->probe_ie_taxonomy = NULL; |
| 303 | wpabuf_free(sta->assoc_ie_taxonomy); |
| 304 | sta->assoc_ie_taxonomy = NULL; |
| 305 | #endif /* CONFIG_TAXONOMY */ |
| 306 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 307 | ht40_intolerant_remove(hapd->iface, sta); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 308 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 309 | #ifdef CONFIG_P2P |
| 310 | if (sta->no_p2p_set) { |
| 311 | sta->no_p2p_set = 0; |
| 312 | hapd->num_sta_no_p2p--; |
| 313 | if (hapd->num_sta_no_p2p == 0) |
| 314 | hostapd_p2p_non_p2p_sta_disconnected(hapd); |
| 315 | } |
| 316 | #endif /* CONFIG_P2P */ |
| 317 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 318 | #ifdef NEED_AP_MLME |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 319 | if (hostapd_ht_operation_update(hapd->iface) > 0) |
| 320 | set_beacon++; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 321 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 322 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 323 | #ifdef CONFIG_MESH |
| 324 | if (hapd->mesh_sta_free_cb) |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 325 | hapd->mesh_sta_free_cb(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 326 | #endif /* CONFIG_MESH */ |
| 327 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 328 | if (set_beacon) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 329 | ieee802_11_update_beacons(hapd->iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 330 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 331 | wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR, |
| 332 | __func__, MAC2STR(sta->addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 333 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
| 334 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 335 | eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta); |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 336 | ap_sta_clear_disconnect_timeouts(hapd, sta); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 337 | ap_sta_clear_assoc_timeout(hapd, sta); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 338 | sae_clear_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 339 | |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 340 | ieee802_1x_free_station(hapd, sta); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 341 | |
| 342 | #ifdef CONFIG_IEEE80211BE |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 343 | if (!ap_sta_is_mld(hapd, sta) || |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 344 | hapd->mld_link_id == sta->mld_assoc_link_id) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 345 | wpa_auth_sta_deinit(sta->wpa_sm); |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 346 | /* Remove references from partner links. */ |
| 347 | clear_wpa_sm_for_each_partner_link(hapd, sta); |
| 348 | } |
| 349 | |
| 350 | /* Release group references in case non-association link STA is removed |
| 351 | * before association link STA */ |
| 352 | if (hostapd_sta_is_link_sta(hapd, sta)) |
| 353 | wpa_release_link_auth_ref(sta->wpa_sm, hapd->mld_link_id); |
| 354 | #else /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 355 | wpa_auth_sta_deinit(sta->wpa_sm); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 356 | #endif /* CONFIG_IEEE80211BE */ |
| 357 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 358 | rsn_preauth_free_station(hapd, sta); |
| 359 | #ifndef CONFIG_NO_RADIUS |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 360 | if (hapd->radius) |
| 361 | radius_client_flush_auth(hapd->radius, sta->addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 362 | #endif /* CONFIG_NO_RADIUS */ |
| 363 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 364 | #ifndef CONFIG_NO_VLAN |
| 365 | /* |
| 366 | * sta->wpa_sm->group needs to be released before so that |
| 367 | * vlan_remove_dynamic() can check that no stations are left on the |
| 368 | * AP_VLAN netdev. |
| 369 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 370 | if (sta->vlan_id) |
| 371 | vlan_remove_dynamic(hapd, sta->vlan_id); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 372 | if (sta->vlan_id_bound) { |
| 373 | /* |
| 374 | * Need to remove the STA entry before potentially removing the |
| 375 | * VLAN. |
| 376 | */ |
| 377 | if (hapd->iface->driver_ap_teardown && |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 378 | !(sta->flags & WLAN_STA_PREAUTH)) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 379 | hostapd_drv_sta_remove(hapd, sta->addr); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 380 | sta->added_unassoc = 0; |
| 381 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 382 | vlan_remove_dynamic(hapd, sta->vlan_id_bound); |
| 383 | } |
| 384 | #endif /* CONFIG_NO_VLAN */ |
| 385 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 386 | os_free(sta->challenge); |
| 387 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 388 | os_free(sta->sa_query_trans_id); |
| 389 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 390 | |
| 391 | #ifdef CONFIG_P2P |
| 392 | p2p_group_notif_disassoc(hapd->p2p_group, sta->addr); |
| 393 | #endif /* CONFIG_P2P */ |
| 394 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 395 | #ifdef CONFIG_INTERWORKING |
| 396 | if (sta->gas_dialog) { |
| 397 | int i; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 398 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 399 | for (i = 0; i < GAS_DIALOG_MAX; i++) |
| 400 | gas_serv_dialog_clear(&sta->gas_dialog[i]); |
| 401 | os_free(sta->gas_dialog); |
| 402 | } |
| 403 | #endif /* CONFIG_INTERWORKING */ |
| 404 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 405 | wpabuf_free(sta->wps_ie); |
| 406 | wpabuf_free(sta->p2p_ie); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 407 | wpabuf_free(sta->hs20_ie); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 408 | wpabuf_free(sta->roaming_consortium); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 409 | #ifdef CONFIG_FST |
| 410 | wpabuf_free(sta->mb_ies); |
| 411 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 412 | |
| 413 | os_free(sta->ht_capabilities); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 414 | os_free(sta->vht_capabilities); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 415 | os_free(sta->vht_operation); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 416 | os_free(sta->he_capab); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 417 | os_free(sta->he_6ghz_capab); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 418 | os_free(sta->eht_capab); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 419 | hostapd_free_psk_list(sta->psk); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 420 | os_free(sta->identity); |
| 421 | os_free(sta->radius_cui); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 422 | os_free(sta->remediation_url); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 423 | os_free(sta->t_c_url); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 424 | wpabuf_free(sta->hs20_deauth_req); |
| 425 | os_free(sta->hs20_session_info_url); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 426 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 427 | #ifdef CONFIG_SAE |
| 428 | sae_clear_data(sta->sae); |
| 429 | os_free(sta->sae); |
| 430 | #endif /* CONFIG_SAE */ |
| 431 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 432 | mbo_ap_sta_free(sta); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 433 | os_free(sta->supp_op_classes); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 434 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 435 | #ifdef CONFIG_FILS |
| 436 | os_free(sta->fils_pending_assoc_req); |
| 437 | wpabuf_free(sta->fils_hlp_resp); |
| 438 | wpabuf_free(sta->hlp_dhcp_discover); |
| 439 | eloop_cancel_timeout(fils_hlp_timeout, hapd, sta); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 440 | #ifdef CONFIG_FILS_SK_PFS |
| 441 | crypto_ecdh_deinit(sta->fils_ecdh); |
| 442 | wpabuf_clear_free(sta->fils_dh_ss); |
| 443 | wpabuf_free(sta->fils_g_sta); |
| 444 | #endif /* CONFIG_FILS_SK_PFS */ |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 445 | #endif /* CONFIG_FILS */ |
| 446 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 447 | #ifdef CONFIG_OWE |
| 448 | bin_clear_free(sta->owe_pmk, sta->owe_pmk_len); |
| 449 | crypto_ecdh_deinit(sta->owe_ecdh); |
| 450 | #endif /* CONFIG_OWE */ |
| 451 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 452 | #ifdef CONFIG_DPP2 |
| 453 | dpp_pfs_free(sta->dpp_pfs); |
| 454 | sta->dpp_pfs = NULL; |
| 455 | #endif /* CONFIG_DPP2 */ |
| 456 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 457 | os_free(sta->ext_capability); |
| 458 | |
| 459 | #ifdef CONFIG_WNM_AP |
| 460 | eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta); |
| 461 | #endif /* CONFIG_WNM_AP */ |
| 462 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 463 | #ifdef CONFIG_PASN |
| 464 | ap_free_sta_pasn(hapd, sta); |
| 465 | #endif /* CONFIG_PASN */ |
| 466 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 467 | os_free(sta->ifname_wds); |
| 468 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 469 | #ifdef CONFIG_IEEE80211BE |
| 470 | ap_sta_free_sta_profile(&sta->mld_info); |
| 471 | #endif /* CONFIG_IEEE80211BE */ |
| 472 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 473 | #ifdef CONFIG_TESTING_OPTIONS |
| 474 | os_free(sta->sae_postponed_commit); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 475 | forced_memzero(sta->last_tk, WPA_TK_MAX_LEN); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 476 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 477 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 478 | os_free(sta); |
| 479 | } |
| 480 | |
| 481 | |
| 482 | void hostapd_free_stas(struct hostapd_data *hapd) |
| 483 | { |
| 484 | struct sta_info *sta, *prev; |
| 485 | |
| 486 | sta = hapd->sta_list; |
| 487 | |
| 488 | while (sta) { |
| 489 | prev = sta; |
| 490 | if (sta->flags & WLAN_STA_AUTH) { |
| 491 | mlme_deauthenticate_indication( |
| 492 | hapd, sta, WLAN_REASON_UNSPECIFIED); |
| 493 | } |
| 494 | sta = sta->next; |
| 495 | wpa_printf(MSG_DEBUG, "Removing station " MACSTR, |
| 496 | MAC2STR(prev->addr)); |
| 497 | ap_free_sta(hapd, prev); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 502 | #ifdef CONFIG_IEEE80211BE |
| 503 | void hostapd_free_link_stas(struct hostapd_data *hapd) |
| 504 | { |
| 505 | struct sta_info *sta, *prev; |
| 506 | |
| 507 | sta = hapd->sta_list; |
| 508 | while (sta) { |
| 509 | prev = sta; |
| 510 | sta = sta->next; |
| 511 | |
| 512 | if (!hostapd_sta_is_link_sta(hapd, prev)) |
| 513 | continue; |
| 514 | |
| 515 | wpa_printf(MSG_DEBUG, "Removing link station from MLD " MACSTR, |
| 516 | MAC2STR(prev->addr)); |
| 517 | ap_free_sta(hapd, prev); |
| 518 | } |
| 519 | } |
| 520 | #endif /* CONFIG_IEEE80211BE */ |
| 521 | |
| 522 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 523 | /** |
| 524 | * ap_handle_timer - Per STA timer handler |
| 525 | * @eloop_ctx: struct hostapd_data * |
| 526 | * @timeout_ctx: struct sta_info * |
| 527 | * |
| 528 | * This function is called to check station activity and to remove inactive |
| 529 | * stations. |
| 530 | */ |
| 531 | void ap_handle_timer(void *eloop_ctx, void *timeout_ctx) |
| 532 | { |
| 533 | struct hostapd_data *hapd = eloop_ctx; |
| 534 | struct sta_info *sta = timeout_ctx; |
| 535 | unsigned long next_time = 0; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 536 | int reason; |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 537 | int max_inactivity = hapd->conf->ap_max_inactivity; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 538 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 539 | wpa_printf(MSG_DEBUG, "%s: %s: " MACSTR " flags=0x%x timeout_next=%d", |
| 540 | hapd->conf->iface, __func__, MAC2STR(sta->addr), sta->flags, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 541 | sta->timeout_next); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 542 | if (sta->timeout_next == STA_REMOVE) { |
| 543 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 544 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " |
| 545 | "local deauth request"); |
| 546 | ap_free_sta(hapd, sta); |
| 547 | return; |
| 548 | } |
| 549 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 550 | if (sta->max_idle_period) |
| 551 | max_inactivity = (sta->max_idle_period * 1024 + 999) / 1000; |
| 552 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 553 | if ((sta->flags & WLAN_STA_ASSOC) && |
| 554 | (sta->timeout_next == STA_NULLFUNC || |
| 555 | sta->timeout_next == STA_DISASSOC)) { |
| 556 | int inactive_sec; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 557 | /* |
| 558 | * Add random value to timeout so that we don't end up bouncing |
| 559 | * all stations at the same time if we have lots of associated |
| 560 | * stations that are idle (but keep re-associating). |
| 561 | */ |
| 562 | int fuzz = os_random() % 20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 563 | inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr); |
| 564 | if (inactive_sec == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 565 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 566 | "Check inactivity: Could not " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 567 | "get station info from kernel driver for " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 568 | MACSTR, MAC2STR(sta->addr)); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 569 | /* |
| 570 | * The driver may not support this functionality. |
| 571 | * Anyway, try again after the next inactivity timeout, |
| 572 | * but do not disconnect the station now. |
| 573 | */ |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 574 | next_time = max_inactivity + fuzz; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 575 | } else if (inactive_sec == -ENOENT) { |
| 576 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 577 | "Station " MACSTR " has lost its driver entry", |
| 578 | MAC2STR(sta->addr)); |
| 579 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 580 | /* Avoid sending client probe on removed client */ |
| 581 | sta->timeout_next = STA_DISASSOC; |
| 582 | goto skip_poll; |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 583 | } else if (inactive_sec < max_inactivity) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 584 | /* station activity detected; reset timeout state */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 585 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 586 | "Station " MACSTR " has been active %is ago", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 587 | MAC2STR(sta->addr), inactive_sec); |
| 588 | sta->timeout_next = STA_NULLFUNC; |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 589 | next_time = max_inactivity + fuzz - inactive_sec; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 590 | } else { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 591 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 592 | "Station " MACSTR " has been " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 593 | "inactive too long: %d sec, max allowed: %d", |
| 594 | MAC2STR(sta->addr), inactive_sec, |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 595 | max_inactivity); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 596 | |
| 597 | if (hapd->conf->skip_inactivity_poll) |
| 598 | sta->timeout_next = STA_DISASSOC; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
| 602 | if ((sta->flags & WLAN_STA_ASSOC) && |
| 603 | sta->timeout_next == STA_DISASSOC && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 604 | !(sta->flags & WLAN_STA_PENDING_POLL) && |
| 605 | !hapd->conf->skip_inactivity_poll) { |
| 606 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR |
| 607 | " has ACKed data poll", MAC2STR(sta->addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 608 | /* data nullfunc frame poll did not produce TX errors; assume |
| 609 | * station ACKed it */ |
| 610 | sta->timeout_next = STA_NULLFUNC; |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 611 | next_time = max_inactivity; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 614 | skip_poll: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 615 | if (next_time) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 616 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
| 617 | "for " MACSTR " (%lu seconds)", |
| 618 | __func__, MAC2STR(sta->addr), next_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 619 | eloop_register_timeout(next_time, 0, ap_handle_timer, hapd, |
| 620 | sta); |
| 621 | return; |
| 622 | } |
| 623 | |
| 624 | if (sta->timeout_next == STA_NULLFUNC && |
| 625 | (sta->flags & WLAN_STA_ASSOC)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 626 | wpa_printf(MSG_DEBUG, " Polling STA"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 627 | sta->flags |= WLAN_STA_PENDING_POLL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 628 | hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr, |
| 629 | sta->flags & WLAN_STA_WMM); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 630 | } else if (sta->timeout_next != STA_REMOVE) { |
| 631 | int deauth = sta->timeout_next == STA_DEAUTH; |
| 632 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 633 | if (!deauth && !(sta->flags & WLAN_STA_ASSOC)) { |
| 634 | /* Cannot disassociate not-associated STA, so move |
| 635 | * directly to deauthentication. */ |
| 636 | sta->timeout_next = STA_DEAUTH; |
| 637 | deauth = 1; |
| 638 | } |
| 639 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 640 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, |
| 641 | "Timeout, sending %s info to STA " MACSTR, |
| 642 | deauth ? "deauthentication" : "disassociation", |
| 643 | MAC2STR(sta->addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 644 | |
| 645 | if (deauth) { |
| 646 | hostapd_drv_sta_deauth( |
| 647 | hapd, sta->addr, |
| 648 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 649 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 650 | reason = (sta->timeout_next == STA_DISASSOC) ? |
| 651 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY : |
| 652 | WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 653 | |
| 654 | hostapd_drv_sta_disassoc(hapd, sta->addr, reason); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | |
| 658 | switch (sta->timeout_next) { |
| 659 | case STA_NULLFUNC: |
| 660 | sta->timeout_next = STA_DISASSOC; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 661 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
| 662 | "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)", |
| 663 | __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 664 | eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer, |
| 665 | hapd, sta); |
| 666 | break; |
| 667 | case STA_DISASSOC: |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 668 | case STA_DISASSOC_FROM_CLI: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 669 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 670 | sta->flags &= ~WLAN_STA_ASSOC; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 671 | hostapd_set_sta_flags(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 672 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 673 | if (!sta->acct_terminate_cause) |
| 674 | sta->acct_terminate_cause = |
| 675 | RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; |
| 676 | accounting_sta_stop(hapd, sta); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 677 | ieee802_1x_free_station(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 678 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 679 | HOSTAPD_LEVEL_INFO, "disassociated due to " |
| 680 | "inactivity"); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 681 | reason = (sta->timeout_next == STA_DISASSOC) ? |
| 682 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY : |
| 683 | WLAN_REASON_PREV_AUTH_NOT_VALID; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 684 | sta->timeout_next = STA_DEAUTH; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 685 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
| 686 | "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)", |
| 687 | __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 688 | eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer, |
| 689 | hapd, sta); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 690 | mlme_disassociate_indication(hapd, sta, reason); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 691 | break; |
| 692 | case STA_DEAUTH: |
| 693 | case STA_REMOVE: |
| 694 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 695 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 696 | "inactivity (timer DEAUTH/REMOVE)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 697 | if (!sta->acct_terminate_cause) |
| 698 | sta->acct_terminate_cause = |
| 699 | RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; |
| 700 | mlme_deauthenticate_indication( |
| 701 | hapd, sta, |
| 702 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 703 | ap_free_sta(hapd, sta); |
| 704 | break; |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | |
| 709 | static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx) |
| 710 | { |
| 711 | struct hostapd_data *hapd = eloop_ctx; |
| 712 | struct sta_info *sta = timeout_ctx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 713 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 714 | wpa_printf(MSG_DEBUG, "%s: Session timer for STA " MACSTR, |
| 715 | hapd->conf->iface, MAC2STR(sta->addr)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 716 | if (!(sta->flags & (WLAN_STA_AUTH | WLAN_STA_ASSOC | |
| 717 | WLAN_STA_AUTHORIZED))) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 718 | if (sta->flags & WLAN_STA_GAS) { |
| 719 | wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA " |
| 720 | "entry " MACSTR, MAC2STR(sta->addr)); |
| 721 | ap_free_sta(hapd, sta); |
| 722 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 723 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 724 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 725 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 726 | hostapd_drv_sta_deauth(hapd, sta->addr, |
| 727 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 728 | mlme_deauthenticate_indication(hapd, sta, |
| 729 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 730 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 731 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " |
| 732 | "session timeout"); |
| 733 | sta->acct_terminate_cause = |
| 734 | RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 735 | ap_free_sta(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 739 | void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta, |
| 740 | u32 session_timeout) |
| 741 | { |
| 742 | if (eloop_replenish_timeout(session_timeout, 0, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 743 | ap_handle_session_timer, hapd, sta) == 1) { |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 744 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 745 | HOSTAPD_LEVEL_DEBUG, "setting session timeout " |
| 746 | "to %d seconds", session_timeout); |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 751 | void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta, |
| 752 | u32 session_timeout) |
| 753 | { |
| 754 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 755 | HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d " |
| 756 | "seconds", session_timeout); |
| 757 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); |
| 758 | eloop_register_timeout(session_timeout, 0, ap_handle_session_timer, |
| 759 | hapd, sta); |
| 760 | } |
| 761 | |
| 762 | |
| 763 | void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta) |
| 764 | { |
| 765 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); |
| 766 | } |
| 767 | |
| 768 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 769 | static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx) |
| 770 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 771 | #ifdef CONFIG_WNM_AP |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 772 | struct hostapd_data *hapd = eloop_ctx; |
| 773 | struct sta_info *sta = timeout_ctx; |
| 774 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 775 | wpa_printf(MSG_DEBUG, "%s: WNM: Session warning time reached for " |
| 776 | MACSTR, hapd->conf->iface, MAC2STR(sta->addr)); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 777 | if (sta->hs20_session_info_url == NULL) |
| 778 | return; |
| 779 | |
| 780 | wnm_send_ess_disassoc_imminent(hapd, sta, sta->hs20_session_info_url, |
| 781 | sta->hs20_disassoc_timer); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 782 | #endif /* CONFIG_WNM_AP */ |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | |
| 786 | void ap_sta_session_warning_timeout(struct hostapd_data *hapd, |
| 787 | struct sta_info *sta, int warning_time) |
| 788 | { |
| 789 | eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta); |
| 790 | eloop_register_timeout(warning_time, 0, ap_handle_session_warning_timer, |
| 791 | hapd, sta); |
| 792 | } |
| 793 | |
| 794 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 795 | static void ap_sta_assoc_timeout(void *eloop_ctx, void *timeout_ctx) |
| 796 | { |
| 797 | struct hostapd_data *hapd = eloop_ctx; |
| 798 | struct sta_info *sta = timeout_ctx; |
| 799 | |
| 800 | if (sta->flags & WLAN_STA_ASSOC) |
| 801 | return; |
| 802 | |
| 803 | wpa_printf(MSG_DEBUG, "STA " MACSTR |
| 804 | " did not complete association in time - remove it", |
| 805 | MAC2STR(sta->addr)); |
| 806 | if (sta->flags & WLAN_STA_AUTH) |
| 807 | ap_sta_deauthenticate(hapd, sta, |
| 808 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 809 | else |
| 810 | ap_free_sta(hapd, sta); |
| 811 | } |
| 812 | |
| 813 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 814 | struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr) |
| 815 | { |
| 816 | struct sta_info *sta; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 817 | int i; |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 818 | int max_inactivity = hapd->conf->ap_max_inactivity; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 819 | |
| 820 | sta = ap_get_sta(hapd, addr); |
| 821 | if (sta) |
| 822 | return sta; |
| 823 | |
| 824 | wpa_printf(MSG_DEBUG, " New STA"); |
| 825 | if (hapd->num_sta >= hapd->conf->max_num_sta) { |
| 826 | /* FIX: might try to remove some old STAs first? */ |
| 827 | wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)", |
| 828 | hapd->num_sta, hapd->conf->max_num_sta); |
| 829 | return NULL; |
| 830 | } |
| 831 | |
| 832 | sta = os_zalloc(sizeof(struct sta_info)); |
| 833 | if (sta == NULL) { |
| 834 | wpa_printf(MSG_ERROR, "malloc failed"); |
| 835 | return NULL; |
| 836 | } |
| 837 | sta->acct_interim_interval = hapd->conf->acct_interim_interval; |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 838 | if (accounting_sta_get_id(hapd, sta) < 0) { |
| 839 | os_free(sta); |
| 840 | return NULL; |
| 841 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 842 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 843 | for (i = 0; i < WLAN_SUPP_RATES_MAX; i++) { |
| 844 | if (!hapd->iface->basic_rates) |
| 845 | break; |
| 846 | if (hapd->iface->basic_rates[i] < 0) |
| 847 | break; |
| 848 | sta->supported_rates[i] = hapd->iface->basic_rates[i] / 5; |
| 849 | } |
| 850 | sta->supported_rates_len = i; |
| 851 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 852 | if (sta->max_idle_period) |
| 853 | max_inactivity = (sta->max_idle_period * 1024 + 999) / 1000; |
| 854 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 855 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) { |
| 856 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
| 857 | "for " MACSTR " (%d seconds - ap_max_inactivity)", |
| 858 | __func__, MAC2STR(addr), |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 859 | max_inactivity); |
| 860 | eloop_register_timeout(max_inactivity, 0, |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 861 | ap_handle_timer, hapd, sta); |
| 862 | } |
| 863 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 864 | /* initialize STA info data */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 865 | os_memcpy(sta->addr, addr, ETH_ALEN); |
| 866 | sta->next = hapd->sta_list; |
| 867 | hapd->sta_list = sta; |
| 868 | hapd->num_sta++; |
| 869 | ap_sta_hash_add(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 870 | ap_sta_remove_in_other_bss(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 871 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
| 872 | dl_list_init(&sta->ip6addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 873 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 874 | #ifdef CONFIG_TAXONOMY |
| 875 | sta_track_claim_taxonomy_info(hapd->iface, addr, |
| 876 | &sta->probe_ie_taxonomy); |
| 877 | #endif /* CONFIG_TAXONOMY */ |
| 878 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 879 | if (!(hapd->conf->mesh & MESH_ENABLED)) |
| 880 | eloop_register_timeout(60, 0, ap_sta_assoc_timeout, hapd, sta); |
| 881 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 882 | return sta; |
| 883 | } |
| 884 | |
| 885 | |
| 886 | static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta) |
| 887 | { |
| 888 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 889 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 890 | if (sta->ipaddr) |
| 891 | hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr); |
| 892 | ap_sta_ip6addr_del(hapd, sta); |
| 893 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 894 | wpa_printf(MSG_DEBUG, "%s: Removing STA " MACSTR " from kernel driver", |
| 895 | hapd->conf->iface, MAC2STR(sta->addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 896 | if (hostapd_drv_sta_remove(hapd, sta->addr) && |
| 897 | sta->flags & WLAN_STA_ASSOC) { |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 898 | wpa_printf(MSG_DEBUG, "%s: Could not remove station " MACSTR |
| 899 | " from kernel driver", |
| 900 | hapd->conf->iface, MAC2STR(sta->addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 901 | return -1; |
| 902 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 903 | sta->added_unassoc = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 904 | return 0; |
| 905 | } |
| 906 | |
| 907 | |
| 908 | static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd, |
| 909 | struct sta_info *sta) |
| 910 | { |
| 911 | struct hostapd_iface *iface = hapd->iface; |
| 912 | size_t i; |
| 913 | |
| 914 | for (i = 0; i < iface->num_bss; i++) { |
| 915 | struct hostapd_data *bss = iface->bss[i]; |
| 916 | struct sta_info *sta2; |
| 917 | /* bss should always be set during operation, but it may be |
| 918 | * NULL during reconfiguration. Assume the STA is not |
| 919 | * associated to another BSS in that case to avoid NULL pointer |
| 920 | * dereferences. */ |
| 921 | if (bss == hapd || bss == NULL) |
| 922 | continue; |
| 923 | sta2 = ap_get_sta(bss, sta->addr); |
| 924 | if (!sta2) |
| 925 | continue; |
| 926 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 927 | wpa_printf(MSG_DEBUG, "%s: disconnect old STA " MACSTR |
| 928 | " association from another BSS %s", |
| 929 | hapd->conf->iface, MAC2STR(sta2->addr), |
| 930 | bss->conf->iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 931 | ap_sta_disconnect(bss, sta2, sta2->addr, |
| 932 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 937 | static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx) |
| 938 | { |
| 939 | struct hostapd_data *hapd = eloop_ctx; |
| 940 | struct sta_info *sta = timeout_ctx; |
| 941 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 942 | wpa_printf(MSG_DEBUG, "%s: Disassociation callback for STA " MACSTR, |
| 943 | hapd->conf->iface, MAC2STR(sta->addr)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 944 | ap_sta_remove(hapd, sta); |
| 945 | mlme_disassociate_indication(hapd, sta, sta->disassoc_reason); |
| 946 | } |
| 947 | |
| 948 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 949 | static void ap_sta_disconnect_common(struct hostapd_data *hapd, |
| 950 | struct sta_info *sta, unsigned int timeout) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 951 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 952 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 953 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 954 | ap_sta_set_authorized(hapd, sta, 0); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 955 | hostapd_set_sta_flags(hapd, sta); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 956 | |
| 957 | wpa_printf(MSG_DEBUG, |
| 958 | "reschedule ap_handle_timer timeout (%u sec) for " MACSTR, |
| 959 | MAC2STR(sta->addr), timeout); |
| 960 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 961 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 962 | eloop_register_timeout(timeout, 0, ap_handle_timer, hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 963 | accounting_sta_stop(hapd, sta); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 964 | ieee802_1x_free_station(hapd, sta); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 965 | #ifdef CONFIG_IEEE80211BE |
| 966 | if (!hapd->conf->mld_ap || |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 967 | hapd->mld_link_id == sta->mld_assoc_link_id) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 968 | wpa_auth_sta_deinit(sta->wpa_sm); |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 969 | clear_wpa_sm_for_each_partner_link(hapd, sta); |
| 970 | } |
| 971 | #else /* CONFIG_IEEE80211BE */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 972 | wpa_auth_sta_deinit(sta->wpa_sm); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 973 | #endif /* CONFIG_IEEE80211BE */ |
| 974 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 975 | sta->wpa_sm = NULL; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 979 | static void ap_sta_disassociate_common(struct hostapd_data *hapd, |
| 980 | struct sta_info *sta, u16 reason) |
| 981 | { |
| 982 | sta->disassoc_reason = reason; |
| 983 | sta->flags |= WLAN_STA_PENDING_DISASSOC_CB; |
| 984 | eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); |
| 985 | eloop_register_timeout(hapd->iface->drv_flags & |
| 986 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, |
| 987 | ap_sta_disassoc_cb_timeout, hapd, sta); |
| 988 | } |
| 989 | |
| 990 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 991 | static void ap_sta_handle_disassociate(struct hostapd_data *hapd, |
| 992 | struct sta_info *sta, u16 reason) |
| 993 | { |
| 994 | wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR, |
| 995 | hapd->conf->iface, MAC2STR(sta->addr)); |
| 996 | |
| 997 | if (hapd->iface->current_mode && |
| 998 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) { |
| 999 | /* Skip deauthentication in DMG/IEEE 802.11ad */ |
| 1000 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | |
| 1001 | WLAN_STA_ASSOC_REQ_OK); |
| 1002 | sta->timeout_next = STA_REMOVE; |
| 1003 | } else { |
| 1004 | sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); |
| 1005 | sta->timeout_next = STA_DEAUTH; |
| 1006 | } |
| 1007 | |
| 1008 | ap_sta_disconnect_common(hapd, sta, AP_MAX_INACTIVITY_AFTER_DISASSOC); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1009 | ap_sta_disassociate_common(hapd, sta, reason); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | |
| 1013 | static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx) |
| 1014 | { |
| 1015 | struct hostapd_data *hapd = eloop_ctx; |
| 1016 | struct sta_info *sta = timeout_ctx; |
| 1017 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 1018 | wpa_printf(MSG_DEBUG, "%s: Deauthentication callback for STA " MACSTR, |
| 1019 | hapd->conf->iface, MAC2STR(sta->addr)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1020 | ap_sta_remove(hapd, sta); |
| 1021 | mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1025 | static void ap_sta_deauthenticate_common(struct hostapd_data *hapd, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1026 | struct sta_info *sta, u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1027 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1028 | sta->deauth_reason = reason; |
| 1029 | sta->flags |= WLAN_STA_PENDING_DEAUTH_CB; |
| 1030 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
| 1031 | eloop_register_timeout(hapd->iface->drv_flags & |
| 1032 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, |
| 1033 | ap_sta_deauth_cb_timeout, hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1037 | static void ap_sta_handle_deauthenticate(struct hostapd_data *hapd, |
| 1038 | struct sta_info *sta, u16 reason) |
| 1039 | { |
| 1040 | wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR, |
| 1041 | hapd->conf->iface, MAC2STR(sta->addr)); |
| 1042 | |
| 1043 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); |
| 1044 | |
| 1045 | sta->timeout_next = STA_REMOVE; |
| 1046 | ap_sta_disconnect_common(hapd, sta, AP_MAX_INACTIVITY_AFTER_DEAUTH); |
| 1047 | ap_sta_deauthenticate_common(hapd, sta, reason); |
| 1048 | } |
| 1049 | |
| 1050 | |
| 1051 | static void ap_sta_handle_disconnect(struct hostapd_data *hapd, |
| 1052 | struct sta_info *sta, u16 reason) |
| 1053 | { |
| 1054 | wpa_printf(MSG_DEBUG, "%s: disconnect STA " MACSTR, |
| 1055 | hapd->conf->iface, MAC2STR(sta->addr)); |
| 1056 | |
| 1057 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); |
| 1058 | wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH); |
| 1059 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 1060 | sta->timeout_next = STA_REMOVE; |
| 1061 | |
| 1062 | sta->deauth_reason = reason; |
| 1063 | ap_sta_disconnect_common(hapd, sta, AP_MAX_INACTIVITY_AFTER_DEAUTH); |
| 1064 | ap_sta_deauthenticate_common(hapd, sta, reason); |
| 1065 | } |
| 1066 | |
| 1067 | |
| 1068 | enum ap_sta_disconnect_op { |
| 1069 | AP_STA_DEAUTHENTICATE, |
| 1070 | AP_STA_DISASSOCIATE, |
| 1071 | AP_STA_DISCONNECT |
| 1072 | }; |
| 1073 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1074 | static bool ap_sta_ml_disconnect(struct hostapd_data *hapd, |
| 1075 | struct sta_info *sta, u16 reason, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1076 | enum ap_sta_disconnect_op op) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1077 | { |
| 1078 | #ifdef CONFIG_IEEE80211BE |
| 1079 | struct hostapd_data *assoc_hapd, *tmp_hapd; |
| 1080 | struct sta_info *assoc_sta; |
| 1081 | unsigned int i, link_id; |
| 1082 | struct hapd_interfaces *interfaces; |
| 1083 | |
| 1084 | if (!hostapd_is_mld_ap(hapd)) |
| 1085 | return false; |
| 1086 | |
| 1087 | /* |
| 1088 | * Get the station on which the association was performed, as it holds |
| 1089 | * the information about all the other links. |
| 1090 | */ |
| 1091 | assoc_sta = hostapd_ml_get_assoc_sta(hapd, sta, &assoc_hapd); |
| 1092 | if (!assoc_sta) |
| 1093 | return false; |
| 1094 | interfaces = assoc_hapd->iface->interfaces; |
| 1095 | |
| 1096 | for (link_id = 0; link_id < MAX_NUM_MLD_LINKS; link_id++) { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1097 | if (!assoc_sta->mld_info.links[link_id].valid) |
| 1098 | continue; |
| 1099 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1100 | for (i = 0; i < interfaces->count; i++) { |
| 1101 | struct sta_info *tmp_sta; |
| 1102 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1103 | tmp_hapd = interfaces->iface[i]->bss[0]; |
| 1104 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1105 | if (!hostapd_is_ml_partner(tmp_hapd, assoc_hapd)) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1106 | continue; |
| 1107 | |
| 1108 | for (tmp_sta = tmp_hapd->sta_list; tmp_sta; |
| 1109 | tmp_sta = tmp_sta->next) { |
| 1110 | /* |
| 1111 | * Handle the station on which the association |
| 1112 | * was done only after all other link station |
| 1113 | * are removed. Since there is a only a single |
| 1114 | * station per hapd with the same association |
| 1115 | * link simply break; |
| 1116 | */ |
| 1117 | if (tmp_sta == assoc_sta) |
| 1118 | break; |
| 1119 | |
| 1120 | if (tmp_sta->mld_assoc_link_id != |
| 1121 | assoc_sta->mld_assoc_link_id || |
| 1122 | tmp_sta->aid != assoc_sta->aid) |
| 1123 | continue; |
| 1124 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1125 | if (op == AP_STA_DISASSOCIATE) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1126 | ap_sta_handle_disassociate(tmp_hapd, |
| 1127 | tmp_sta, |
| 1128 | reason); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1129 | else if (op == AP_STA_DEAUTHENTICATE) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1130 | ap_sta_handle_deauthenticate(tmp_hapd, |
| 1131 | tmp_sta, |
| 1132 | reason); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1133 | else |
| 1134 | ap_sta_handle_disconnect(tmp_hapd, |
| 1135 | tmp_sta, |
| 1136 | reason); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1137 | break; |
| 1138 | } |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | /* Disconnect the station on which the association was performed. */ |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1143 | if (op == AP_STA_DISASSOCIATE) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1144 | ap_sta_handle_disassociate(assoc_hapd, assoc_sta, reason); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1145 | else if (op == AP_STA_DEAUTHENTICATE) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1146 | ap_sta_handle_deauthenticate(assoc_hapd, assoc_sta, reason); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1147 | else |
| 1148 | ap_sta_handle_disconnect(assoc_hapd, assoc_sta, reason); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1149 | |
| 1150 | return true; |
| 1151 | #else /* CONFIG_IEEE80211BE */ |
| 1152 | return false; |
| 1153 | #endif /* CONFIG_IEEE80211BE */ |
| 1154 | } |
| 1155 | |
| 1156 | |
| 1157 | void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta, |
| 1158 | u16 reason) |
| 1159 | { |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1160 | if (ap_sta_ml_disconnect(hapd, sta, reason, AP_STA_DISASSOCIATE)) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1161 | return; |
| 1162 | |
| 1163 | ap_sta_handle_disassociate(hapd, sta, reason); |
| 1164 | } |
| 1165 | |
| 1166 | |
| 1167 | void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta, |
| 1168 | u16 reason) |
| 1169 | { |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1170 | if (hapd->iface->current_mode && |
| 1171 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) { |
| 1172 | /* Deauthentication is not used in DMG/IEEE 802.11ad; |
| 1173 | * disassociate the STA instead. */ |
| 1174 | ap_sta_disassociate(hapd, sta, reason); |
| 1175 | return; |
| 1176 | } |
| 1177 | |
| 1178 | if (ap_sta_ml_disconnect(hapd, sta, reason, AP_STA_DEAUTHENTICATE)) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1179 | return; |
| 1180 | |
| 1181 | ap_sta_handle_deauthenticate(hapd, sta, reason); |
| 1182 | } |
| 1183 | |
| 1184 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1185 | #ifdef CONFIG_WPS |
| 1186 | int ap_sta_wps_cancel(struct hostapd_data *hapd, |
| 1187 | struct sta_info *sta, void *ctx) |
| 1188 | { |
| 1189 | if (sta && (sta->flags & WLAN_STA_WPS)) { |
| 1190 | ap_sta_deauthenticate(hapd, sta, |
| 1191 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 1192 | wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR, |
| 1193 | __func__, MAC2STR(sta->addr)); |
| 1194 | return 1; |
| 1195 | } |
| 1196 | |
| 1197 | return 0; |
| 1198 | } |
| 1199 | #endif /* CONFIG_WPS */ |
| 1200 | |
| 1201 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1202 | static int ap_sta_get_free_vlan_id(struct hostapd_data *hapd) |
| 1203 | { |
| 1204 | struct hostapd_vlan *vlan; |
| 1205 | int vlan_id = MAX_VLAN_ID + 2; |
| 1206 | |
| 1207 | retry: |
| 1208 | for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) { |
| 1209 | if (vlan->vlan_id == vlan_id) { |
| 1210 | vlan_id++; |
| 1211 | goto retry; |
| 1212 | } |
| 1213 | } |
| 1214 | return vlan_id; |
| 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta, |
| 1219 | struct vlan_description *vlan_desc) |
| 1220 | { |
| 1221 | struct hostapd_vlan *vlan = NULL, *wildcard_vlan = NULL; |
| 1222 | int old_vlan_id, vlan_id = 0, ret = 0; |
| 1223 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1224 | /* Check if there is something to do */ |
| 1225 | if (hapd->conf->ssid.per_sta_vif && !sta->vlan_id) { |
| 1226 | /* This sta is lacking its own vif */ |
| 1227 | } else if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED && |
| 1228 | !hapd->conf->ssid.per_sta_vif && sta->vlan_id) { |
| 1229 | /* sta->vlan_id needs to be reset */ |
| 1230 | } else if (!vlan_compare(vlan_desc, sta->vlan_desc)) { |
| 1231 | return 0; /* nothing to change */ |
| 1232 | } |
| 1233 | |
| 1234 | /* Now the real VLAN changed or the STA just needs its own vif */ |
| 1235 | if (hapd->conf->ssid.per_sta_vif) { |
| 1236 | /* Assign a new vif, always */ |
| 1237 | /* find a free vlan_id sufficiently big */ |
| 1238 | vlan_id = ap_sta_get_free_vlan_id(hapd); |
| 1239 | /* Get wildcard VLAN */ |
| 1240 | for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) { |
| 1241 | if (vlan->vlan_id == VLAN_ID_WILDCARD) |
| 1242 | break; |
| 1243 | } |
| 1244 | if (!vlan) { |
| 1245 | hostapd_logger(hapd, sta->addr, |
| 1246 | HOSTAPD_MODULE_IEEE80211, |
| 1247 | HOSTAPD_LEVEL_DEBUG, |
| 1248 | "per_sta_vif missing wildcard"); |
| 1249 | vlan_id = 0; |
| 1250 | ret = -1; |
| 1251 | goto done; |
| 1252 | } |
| 1253 | } else if (vlan_desc && vlan_desc->notempty) { |
| 1254 | for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) { |
| 1255 | if (!vlan_compare(&vlan->vlan_desc, vlan_desc)) |
| 1256 | break; |
| 1257 | if (vlan->vlan_id == VLAN_ID_WILDCARD) |
| 1258 | wildcard_vlan = vlan; |
| 1259 | } |
| 1260 | if (vlan) { |
| 1261 | vlan_id = vlan->vlan_id; |
| 1262 | } else if (wildcard_vlan) { |
| 1263 | vlan = wildcard_vlan; |
| 1264 | vlan_id = vlan_desc->untagged; |
| 1265 | if (vlan_desc->tagged[0]) { |
| 1266 | /* Tagged VLAN configuration */ |
| 1267 | vlan_id = ap_sta_get_free_vlan_id(hapd); |
| 1268 | } |
| 1269 | } else { |
| 1270 | hostapd_logger(hapd, sta->addr, |
| 1271 | HOSTAPD_MODULE_IEEE80211, |
| 1272 | HOSTAPD_LEVEL_DEBUG, |
| 1273 | "missing vlan and wildcard for vlan=%d%s", |
| 1274 | vlan_desc->untagged, |
| 1275 | vlan_desc->tagged[0] ? "+" : ""); |
| 1276 | vlan_id = 0; |
| 1277 | ret = -1; |
| 1278 | goto done; |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | if (vlan && vlan->vlan_id == VLAN_ID_WILDCARD) { |
| 1283 | vlan = vlan_add_dynamic(hapd, vlan, vlan_id, vlan_desc); |
| 1284 | if (vlan == NULL) { |
| 1285 | hostapd_logger(hapd, sta->addr, |
| 1286 | HOSTAPD_MODULE_IEEE80211, |
| 1287 | HOSTAPD_LEVEL_DEBUG, |
| 1288 | "could not add dynamic VLAN interface for vlan=%d%s", |
| 1289 | vlan_desc ? vlan_desc->untagged : -1, |
| 1290 | (vlan_desc && vlan_desc->tagged[0]) ? |
| 1291 | "+" : ""); |
| 1292 | vlan_id = 0; |
| 1293 | ret = -1; |
| 1294 | goto done; |
| 1295 | } |
| 1296 | |
| 1297 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1298 | HOSTAPD_LEVEL_DEBUG, |
| 1299 | "added new dynamic VLAN interface '%s'", |
| 1300 | vlan->ifname); |
| 1301 | } else if (vlan && vlan->dynamic_vlan > 0) { |
| 1302 | vlan->dynamic_vlan++; |
| 1303 | hostapd_logger(hapd, sta->addr, |
| 1304 | HOSTAPD_MODULE_IEEE80211, |
| 1305 | HOSTAPD_LEVEL_DEBUG, |
| 1306 | "updated existing dynamic VLAN interface '%s'", |
| 1307 | vlan->ifname); |
| 1308 | } |
| 1309 | done: |
| 1310 | old_vlan_id = sta->vlan_id; |
| 1311 | sta->vlan_id = vlan_id; |
| 1312 | sta->vlan_desc = vlan ? &vlan->vlan_desc : NULL; |
| 1313 | |
| 1314 | if (vlan_id != old_vlan_id && old_vlan_id) |
| 1315 | vlan_remove_dynamic(hapd, old_vlan_id); |
| 1316 | |
| 1317 | return ret; |
| 1318 | } |
| 1319 | |
| 1320 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 1321 | int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1322 | { |
| 1323 | #ifndef CONFIG_NO_VLAN |
| 1324 | const char *iface; |
| 1325 | struct hostapd_vlan *vlan = NULL; |
| 1326 | int ret; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 1327 | int old_vlanid = sta->vlan_id_bound; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1328 | int mld_link_id = -1; |
| 1329 | |
| 1330 | #ifdef CONFIG_IEEE80211BE |
| 1331 | if (hapd->conf->mld_ap) |
| 1332 | mld_link_id = hapd->mld_link_id; |
| 1333 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1334 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1335 | if ((sta->flags & WLAN_STA_WDS) && sta->vlan_id == 0) { |
| 1336 | wpa_printf(MSG_DEBUG, |
| 1337 | "Do not override WDS VLAN assignment for STA " |
| 1338 | MACSTR, MAC2STR(sta->addr)); |
| 1339 | return 0; |
| 1340 | } |
| 1341 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1342 | iface = hapd->conf->iface; |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1343 | if (hapd->conf->ssid.vlan[0]) |
| 1344 | iface = hapd->conf->ssid.vlan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1345 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1346 | if (sta->vlan_id > 0) { |
| 1347 | for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) { |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 1348 | if (vlan->vlan_id == sta->vlan_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1349 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1350 | } |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 1351 | if (vlan) |
| 1352 | iface = vlan->ifname; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 1355 | /* |
| 1356 | * Do not increment ref counters if the VLAN ID remains same, but do |
| 1357 | * not skip hostapd_drv_set_sta_vlan() as hostapd_drv_sta_remove() might |
| 1358 | * have been called before. |
| 1359 | */ |
| 1360 | if (sta->vlan_id == old_vlanid) |
| 1361 | goto skip_counting; |
| 1362 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1363 | if (sta->vlan_id > 0 && !vlan && |
| 1364 | !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1365 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1366 | HOSTAPD_LEVEL_DEBUG, "could not find VLAN for " |
| 1367 | "binding station to (vlan_id=%d)", |
| 1368 | sta->vlan_id); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1369 | ret = -1; |
| 1370 | goto done; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1371 | } else if (vlan && vlan->dynamic_vlan > 0) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1372 | vlan->dynamic_vlan++; |
| 1373 | hostapd_logger(hapd, sta->addr, |
| 1374 | HOSTAPD_MODULE_IEEE80211, |
| 1375 | HOSTAPD_LEVEL_DEBUG, |
| 1376 | "updated existing dynamic VLAN interface '%s'", |
| 1377 | iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 1380 | /* ref counters have been increased, so mark the station */ |
| 1381 | sta->vlan_id_bound = sta->vlan_id; |
| 1382 | |
| 1383 | skip_counting: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1384 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1385 | HOSTAPD_LEVEL_DEBUG, "binding station to interface " |
| 1386 | "'%s'", iface); |
| 1387 | |
| 1388 | if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0) |
| 1389 | wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA"); |
| 1390 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1391 | ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id, |
| 1392 | mld_link_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1393 | if (ret < 0) { |
| 1394 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1395 | HOSTAPD_LEVEL_DEBUG, "could not bind the STA " |
| 1396 | "entry to vlan_id=%d", sta->vlan_id); |
| 1397 | } |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1398 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1399 | /* During 1x reauth, if the vlan id changes, then remove the old id. */ |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 1400 | if (old_vlanid > 0 && old_vlanid != sta->vlan_id) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1401 | vlan_remove_dynamic(hapd, old_vlanid); |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 1402 | done: |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 1403 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1404 | return ret; |
| 1405 | #else /* CONFIG_NO_VLAN */ |
| 1406 | return 0; |
| 1407 | #endif /* CONFIG_NO_VLAN */ |
| 1408 | } |
| 1409 | |
| 1410 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1411 | int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta) |
| 1412 | { |
| 1413 | u32 tu; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1414 | struct os_reltime now, passed; |
| 1415 | os_get_reltime(&now); |
| 1416 | os_reltime_sub(&now, &sta->sa_query_start, &passed); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1417 | tu = (passed.sec * 1000000 + passed.usec) / 1024; |
| 1418 | if (hapd->conf->assoc_sa_query_max_timeout < tu) { |
| 1419 | hostapd_logger(hapd, sta->addr, |
| 1420 | HOSTAPD_MODULE_IEEE80211, |
| 1421 | HOSTAPD_LEVEL_DEBUG, |
| 1422 | "association SA Query timed out"); |
| 1423 | sta->sa_query_timed_out = 1; |
| 1424 | os_free(sta->sa_query_trans_id); |
| 1425 | sta->sa_query_trans_id = NULL; |
| 1426 | sta->sa_query_count = 0; |
| 1427 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
| 1428 | return 1; |
| 1429 | } |
| 1430 | |
| 1431 | return 0; |
| 1432 | } |
| 1433 | |
| 1434 | |
| 1435 | static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx) |
| 1436 | { |
| 1437 | struct hostapd_data *hapd = eloop_ctx; |
| 1438 | struct sta_info *sta = timeout_ctx; |
| 1439 | unsigned int timeout, sec, usec; |
| 1440 | u8 *trans_id, *nbuf; |
| 1441 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 1442 | wpa_printf(MSG_DEBUG, "%s: SA Query timer for STA " MACSTR |
| 1443 | " (count=%d)", |
| 1444 | hapd->conf->iface, MAC2STR(sta->addr), sta->sa_query_count); |
| 1445 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1446 | if (sta->sa_query_count > 0 && |
| 1447 | ap_check_sa_query_timeout(hapd, sta)) |
| 1448 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1449 | if (sta->sa_query_count >= 1000) |
| 1450 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1451 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1452 | nbuf = os_realloc_array(sta->sa_query_trans_id, |
| 1453 | sta->sa_query_count + 1, |
| 1454 | WLAN_SA_QUERY_TR_ID_LEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1455 | if (nbuf == NULL) |
| 1456 | return; |
| 1457 | if (sta->sa_query_count == 0) { |
| 1458 | /* Starting a new SA Query procedure */ |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1459 | os_get_reltime(&sta->sa_query_start); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1460 | } |
| 1461 | trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN; |
| 1462 | sta->sa_query_trans_id = nbuf; |
| 1463 | sta->sa_query_count++; |
| 1464 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1465 | if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) { |
| 1466 | /* |
| 1467 | * We don't really care which ID is used here, so simply |
| 1468 | * hardcode this if the mostly theoretical os_get_random() |
| 1469 | * failure happens. |
| 1470 | */ |
| 1471 | trans_id[0] = 0x12; |
| 1472 | trans_id[1] = 0x34; |
| 1473 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1474 | |
| 1475 | timeout = hapd->conf->assoc_sa_query_retry_timeout; |
| 1476 | sec = ((timeout / 1000) * 1024) / 1000; |
| 1477 | usec = (timeout % 1000) * 1024; |
| 1478 | eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta); |
| 1479 | |
| 1480 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1481 | HOSTAPD_LEVEL_DEBUG, |
| 1482 | "association SA Query attempt %d", sta->sa_query_count); |
| 1483 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1484 | ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | |
| 1488 | void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta) |
| 1489 | { |
| 1490 | ap_sa_query_timer(hapd, sta); |
| 1491 | } |
| 1492 | |
| 1493 | |
| 1494 | void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta) |
| 1495 | { |
| 1496 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
| 1497 | os_free(sta->sa_query_trans_id); |
| 1498 | sta->sa_query_trans_id = NULL; |
| 1499 | sta->sa_query_count = 0; |
| 1500 | } |
| 1501 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1502 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1503 | const char * ap_sta_wpa_get_keyid(struct hostapd_data *hapd, |
| 1504 | struct sta_info *sta) |
| 1505 | { |
| 1506 | struct hostapd_wpa_psk *psk; |
| 1507 | struct hostapd_ssid *ssid; |
| 1508 | const u8 *pmk; |
| 1509 | int pmk_len; |
| 1510 | |
| 1511 | ssid = &hapd->conf->ssid; |
| 1512 | |
| 1513 | pmk = wpa_auth_get_pmk(sta->wpa_sm, &pmk_len); |
| 1514 | if (!pmk || pmk_len != PMK_LEN) |
| 1515 | return NULL; |
| 1516 | |
| 1517 | for (psk = ssid->wpa_psk; psk; psk = psk->next) |
| 1518 | if (os_memcmp(pmk, psk->psk, PMK_LEN) == 0) |
| 1519 | break; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1520 | if (!psk || !psk->keyid[0]) |
| 1521 | return NULL; |
| 1522 | |
| 1523 | return psk->keyid; |
| 1524 | } |
| 1525 | |
| 1526 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1527 | const u8 * ap_sta_wpa_get_dpp_pkhash(struct hostapd_data *hapd, |
| 1528 | struct sta_info *sta) |
| 1529 | { |
| 1530 | return wpa_auth_get_dpp_pkhash(sta->wpa_sm); |
| 1531 | } |
| 1532 | |
| 1533 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1534 | bool ap_sta_set_authorized_flag(struct hostapd_data *hapd, struct sta_info *sta, |
| 1535 | int authorized) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1536 | { |
| 1537 | if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED)) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1538 | return false; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1539 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 1540 | if (authorized) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1541 | int mld_assoc_link_id = -1; |
| 1542 | |
| 1543 | #ifdef CONFIG_IEEE80211BE |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1544 | if (ap_sta_is_mld(hapd, sta)) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1545 | if (sta->mld_assoc_link_id == hapd->mld_link_id) |
| 1546 | mld_assoc_link_id = sta->mld_assoc_link_id; |
| 1547 | else |
| 1548 | mld_assoc_link_id = -2; |
| 1549 | } |
| 1550 | #endif /* CONFIG_IEEE80211BE */ |
| 1551 | if (mld_assoc_link_id != -2) |
| 1552 | hostapd_prune_associations(hapd, sta->addr, |
| 1553 | mld_assoc_link_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1554 | sta->flags |= WLAN_STA_AUTHORIZED; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 1555 | } else { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1556 | sta->flags &= ~WLAN_STA_AUTHORIZED; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 1557 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1558 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1559 | return true; |
| 1560 | } |
| 1561 | |
| 1562 | |
| 1563 | void ap_sta_set_authorized_event(struct hostapd_data *hapd, |
| 1564 | struct sta_info *sta, int authorized) |
| 1565 | { |
| 1566 | const u8 *dev_addr = NULL; |
| 1567 | char buf[100]; |
| 1568 | #ifdef CONFIG_P2P |
| 1569 | u8 addr[ETH_ALEN]; |
| 1570 | u8 ip_addr_buf[4]; |
| 1571 | #endif /* CONFIG_P2P */ |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1572 | const u8 *ip_ptr = NULL; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1573 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1574 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1575 | if (hapd->p2p_group == NULL) { |
| 1576 | if (sta->p2p_ie != NULL && |
| 1577 | p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0) |
| 1578 | dev_addr = addr; |
| 1579 | } else |
| 1580 | dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1581 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1582 | if (dev_addr) |
| 1583 | os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR, |
| 1584 | MAC2STR(sta->addr), MAC2STR(dev_addr)); |
| 1585 | else |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1586 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1587 | os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr)); |
| 1588 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1589 | if (authorized) { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1590 | const u8 *dpp_pkhash; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1591 | const char *keyid; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1592 | char dpp_pkhash_buf[100]; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1593 | char keyid_buf[100]; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1594 | char ip_addr[100]; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1595 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1596 | dpp_pkhash_buf[0] = '\0'; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1597 | keyid_buf[0] = '\0'; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1598 | ip_addr[0] = '\0'; |
| 1599 | #ifdef CONFIG_P2P |
| 1600 | if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) { |
| 1601 | os_snprintf(ip_addr, sizeof(ip_addr), |
| 1602 | " ip_addr=%u.%u.%u.%u", |
| 1603 | ip_addr_buf[0], ip_addr_buf[1], |
| 1604 | ip_addr_buf[2], ip_addr_buf[3]); |
Sunil Ravi | d8128a2 | 2023-11-06 23:53:58 +0000 | [diff] [blame] | 1605 | ip_ptr = ip_addr_buf; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1606 | } |
| 1607 | #endif /* CONFIG_P2P */ |
| 1608 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1609 | keyid = ap_sta_wpa_get_keyid(hapd, sta); |
| 1610 | if (keyid) { |
| 1611 | os_snprintf(keyid_buf, sizeof(keyid_buf), |
| 1612 | " keyid=%s", keyid); |
| 1613 | } |
| 1614 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1615 | dpp_pkhash = ap_sta_wpa_get_dpp_pkhash(hapd, sta); |
| 1616 | if (dpp_pkhash) { |
| 1617 | const char *prefix = " dpp_pkhash="; |
| 1618 | size_t plen = os_strlen(prefix); |
| 1619 | |
| 1620 | os_strlcpy(dpp_pkhash_buf, prefix, |
| 1621 | sizeof(dpp_pkhash_buf)); |
| 1622 | wpa_snprintf_hex(&dpp_pkhash_buf[plen], |
| 1623 | sizeof(dpp_pkhash_buf) - plen, |
| 1624 | dpp_pkhash, SHA256_MAC_LEN); |
| 1625 | } |
| 1626 | |
| 1627 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s%s", |
| 1628 | buf, ip_addr, keyid_buf, dpp_pkhash_buf); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1629 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1630 | if (hapd->msg_ctx_parent && |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1631 | hapd->msg_ctx_parent != hapd->msg_ctx) |
| 1632 | wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1633 | AP_STA_CONNECTED "%s%s%s%s", |
| 1634 | buf, ip_addr, keyid_buf, |
| 1635 | dpp_pkhash_buf); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1636 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1637 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf); |
| 1638 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1639 | if (hapd->msg_ctx_parent && |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1640 | hapd->msg_ctx_parent != hapd->msg_ctx) |
| 1641 | wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO, |
| 1642 | AP_STA_DISCONNECTED "%s", buf); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1643 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1644 | |
Sunil Ravi | d8128a2 | 2023-11-06 23:53:58 +0000 | [diff] [blame] | 1645 | if (hapd->sta_authorized_cb) |
| 1646 | hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx, |
| 1647 | sta->addr, authorized, dev_addr, |
| 1648 | ip_ptr); |
| 1649 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1650 | #ifdef CONFIG_FST |
| 1651 | if (hapd->iface->fst) { |
| 1652 | if (authorized) |
| 1653 | fst_notify_peer_connected(hapd->iface->fst, sta->addr); |
| 1654 | else |
| 1655 | fst_notify_peer_disconnected(hapd->iface->fst, |
| 1656 | sta->addr); |
| 1657 | } |
| 1658 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1662 | bool ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1663 | int authorized) |
| 1664 | { |
| 1665 | if (!ap_sta_set_authorized_flag(hapd, sta, authorized)) |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1666 | return false; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1667 | ap_sta_set_authorized_event(hapd, sta, authorized); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1668 | return true; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1672 | void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta, |
| 1673 | const u8 *addr, u16 reason) |
| 1674 | { |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 1675 | if (sta) |
| 1676 | wpa_printf(MSG_DEBUG, "%s: %s STA " MACSTR " reason=%u", |
| 1677 | hapd->conf->iface, __func__, MAC2STR(sta->addr), |
| 1678 | reason); |
| 1679 | else if (addr) |
| 1680 | wpa_printf(MSG_DEBUG, "%s: %s addr " MACSTR " reason=%u", |
| 1681 | hapd->conf->iface, __func__, MAC2STR(addr), |
| 1682 | reason); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1683 | |
| 1684 | if (sta == NULL && addr) |
| 1685 | sta = ap_get_sta(hapd, addr); |
| 1686 | |
| 1687 | if (addr) |
| 1688 | hostapd_drv_sta_deauth(hapd, addr, reason); |
| 1689 | |
| 1690 | if (sta == NULL) |
| 1691 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1692 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 1693 | if (hapd->iface->current_mode && |
| 1694 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) { |
| 1695 | /* Deauthentication is not used in DMG/IEEE 802.11ad; |
| 1696 | * disassociate the STA instead. */ |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1697 | ap_sta_disassociate_common(hapd, sta, reason); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 1698 | return; |
| 1699 | } |
| 1700 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1701 | if (ap_sta_ml_disconnect(hapd, sta, reason, AP_STA_DISCONNECT)) |
| 1702 | return; |
| 1703 | |
| 1704 | ap_sta_handle_disconnect(hapd, sta, reason); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | |
| 1708 | void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta) |
| 1709 | { |
| 1710 | if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) { |
| 1711 | wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame"); |
| 1712 | return; |
| 1713 | } |
| 1714 | sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB; |
| 1715 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
| 1716 | ap_sta_deauth_cb_timeout(hapd, sta); |
| 1717 | } |
| 1718 | |
| 1719 | |
| 1720 | void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta) |
| 1721 | { |
| 1722 | if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) { |
| 1723 | wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame"); |
| 1724 | return; |
| 1725 | } |
| 1726 | sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB; |
| 1727 | eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); |
| 1728 | ap_sta_disassoc_cb_timeout(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1729 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1730 | |
| 1731 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 1732 | void ap_sta_clear_disconnect_timeouts(struct hostapd_data *hapd, |
| 1733 | struct sta_info *sta) |
| 1734 | { |
| 1735 | if (eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta) > 0) |
| 1736 | wpa_printf(MSG_DEBUG, |
| 1737 | "%s: Removed ap_sta_deauth_cb_timeout timeout for " |
| 1738 | MACSTR, |
| 1739 | hapd->conf->iface, MAC2STR(sta->addr)); |
| 1740 | if (eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta) > 0) |
| 1741 | wpa_printf(MSG_DEBUG, |
| 1742 | "%s: Removed ap_sta_disassoc_cb_timeout timeout for " |
| 1743 | MACSTR, |
| 1744 | hapd->conf->iface, MAC2STR(sta->addr)); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 1745 | if (eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta) > 0) |
| 1746 | { |
| 1747 | wpa_printf(MSG_DEBUG, |
| 1748 | "%s: Removed ap_sta_delayed_1x_auth_fail_cb timeout for " |
| 1749 | MACSTR, |
| 1750 | hapd->conf->iface, MAC2STR(sta->addr)); |
| 1751 | if (sta->flags & WLAN_STA_WPS) |
| 1752 | hostapd_wps_eap_completed(hapd); |
| 1753 | } |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1757 | void ap_sta_clear_assoc_timeout(struct hostapd_data *hapd, |
| 1758 | struct sta_info *sta) |
| 1759 | { |
| 1760 | eloop_cancel_timeout(ap_sta_assoc_timeout, hapd, sta); |
| 1761 | } |
| 1762 | |
| 1763 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1764 | int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen) |
| 1765 | { |
| 1766 | int res; |
| 1767 | |
| 1768 | buf[0] = '\0'; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1769 | res = os_snprintf(buf, buflen, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1770 | "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1771 | (flags & WLAN_STA_AUTH ? "[AUTH]" : ""), |
| 1772 | (flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""), |
| 1773 | (flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : ""), |
| 1774 | (flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" : |
| 1775 | ""), |
| 1776 | (flags & WLAN_STA_SHORT_PREAMBLE ? |
| 1777 | "[SHORT_PREAMBLE]" : ""), |
| 1778 | (flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""), |
| 1779 | (flags & WLAN_STA_WMM ? "[WMM]" : ""), |
| 1780 | (flags & WLAN_STA_MFP ? "[MFP]" : ""), |
| 1781 | (flags & WLAN_STA_WPS ? "[WPS]" : ""), |
| 1782 | (flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""), |
| 1783 | (flags & WLAN_STA_WDS ? "[WDS]" : ""), |
| 1784 | (flags & WLAN_STA_NONERP ? "[NonERP]" : ""), |
| 1785 | (flags & WLAN_STA_WPS2 ? "[WPS2]" : ""), |
| 1786 | (flags & WLAN_STA_GAS ? "[GAS]" : ""), |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1787 | (flags & WLAN_STA_HT ? "[HT]" : ""), |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1788 | (flags & WLAN_STA_VHT ? "[VHT]" : ""), |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1789 | (flags & WLAN_STA_HE ? "[HE]" : ""), |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1790 | (flags & WLAN_STA_EHT ? "[EHT]" : ""), |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1791 | (flags & WLAN_STA_6GHZ ? "[6GHZ]" : ""), |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1792 | (flags & WLAN_STA_VENDOR_VHT ? "[VENDOR_VHT]" : ""), |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1793 | (flags & WLAN_STA_WNM_SLEEP_MODE ? |
| 1794 | "[WNM_SLEEP_MODE]" : "")); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1795 | if (os_snprintf_error(buflen, res)) |
| 1796 | res = -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1797 | |
| 1798 | return res; |
| 1799 | } |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 1800 | |
| 1801 | |
| 1802 | static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx) |
| 1803 | { |
| 1804 | struct hostapd_data *hapd = eloop_ctx; |
| 1805 | struct sta_info *sta = timeout_ctx; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1806 | u16 reason; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 1807 | |
| 1808 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, |
| 1809 | "IEEE 802.1X: Scheduled disconnection of " MACSTR |
| 1810 | " after EAP-Failure", MAC2STR(sta->addr)); |
| 1811 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1812 | reason = sta->disconnect_reason_code; |
| 1813 | if (!reason) |
| 1814 | reason = WLAN_REASON_IEEE_802_1X_AUTH_FAILED; |
| 1815 | ap_sta_disconnect(hapd, sta, sta->addr, reason); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 1816 | if (sta->flags & WLAN_STA_WPS) |
| 1817 | hostapd_wps_eap_completed(hapd); |
| 1818 | } |
| 1819 | |
| 1820 | |
| 1821 | void ap_sta_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 1822 | struct sta_info *sta, |
| 1823 | unsigned timeout) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 1824 | { |
| 1825 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, |
| 1826 | "IEEE 802.1X: Force disconnection of " MACSTR |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 1827 | " after EAP-Failure in %u ms", MAC2STR(sta->addr), timeout); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 1828 | |
| 1829 | /* |
| 1830 | * Add a small sleep to increase likelihood of previously requested |
| 1831 | * EAP-Failure TX getting out before this should the driver reorder |
| 1832 | * operations. |
| 1833 | */ |
| 1834 | eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta); |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 1835 | eloop_register_timeout(0, timeout * 1000, |
| 1836 | ap_sta_delayed_1x_auth_fail_cb, hapd, sta); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | |
| 1840 | int ap_sta_pending_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd, |
| 1841 | struct sta_info *sta) |
| 1842 | { |
| 1843 | return eloop_is_timeout_registered(ap_sta_delayed_1x_auth_fail_cb, |
| 1844 | hapd, sta); |
| 1845 | } |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 1846 | |
| 1847 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1848 | #ifdef CONFIG_IEEE80211BE |
| 1849 | static void ap_sta_remove_link_sta(struct hostapd_data *hapd, |
| 1850 | struct sta_info *sta) |
| 1851 | { |
| 1852 | struct hostapd_data *tmp_hapd; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1853 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 1854 | for_each_mld_link(tmp_hapd, hapd) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1855 | struct sta_info *tmp_sta; |
| 1856 | |
| 1857 | if (hapd == tmp_hapd) |
| 1858 | continue; |
| 1859 | |
| 1860 | for (tmp_sta = tmp_hapd->sta_list; tmp_sta; |
| 1861 | tmp_sta = tmp_sta->next) { |
| 1862 | if (tmp_sta == sta || |
| 1863 | !ether_addr_equal(tmp_sta->addr, sta->addr)) |
| 1864 | continue; |
| 1865 | |
| 1866 | ap_free_sta(tmp_hapd, tmp_sta); |
| 1867 | break; |
| 1868 | } |
| 1869 | } |
| 1870 | } |
| 1871 | #endif /* CONFIG_IEEE80211BE */ |
| 1872 | |
| 1873 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 1874 | int ap_sta_re_add(struct hostapd_data *hapd, struct sta_info *sta) |
| 1875 | { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1876 | const u8 *mld_link_addr = NULL; |
| 1877 | bool mld_link_sta = false; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1878 | u16 eml_cap = 0; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1879 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 1880 | /* |
| 1881 | * If a station that is already associated to the AP, is trying to |
| 1882 | * authenticate again, remove the STA entry, in order to make sure the |
| 1883 | * STA PS state gets cleared and configuration gets updated. To handle |
| 1884 | * this, station's added_unassoc flag is cleared once the station has |
| 1885 | * completed association. |
| 1886 | */ |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1887 | |
| 1888 | #ifdef CONFIG_IEEE80211BE |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1889 | if (ap_sta_is_mld(hapd, sta)) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1890 | u8 mld_link_id = hapd->mld_link_id; |
| 1891 | |
| 1892 | mld_link_sta = sta->mld_assoc_link_id != mld_link_id; |
| 1893 | mld_link_addr = sta->mld_info.links[mld_link_id].peer_addr; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1894 | eml_cap = sta->mld_info.common_info.eml_capa; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1895 | |
| 1896 | /* |
| 1897 | * In case the AP is affiliated with an AP MLD, we need to |
| 1898 | * remove the station from all relevant links/APs. |
| 1899 | */ |
| 1900 | ap_sta_remove_link_sta(hapd, sta); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1901 | } |
| 1902 | #endif /* CONFIG_IEEE80211BE */ |
| 1903 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 1904 | ap_sta_set_authorized(hapd, sta, 0); |
| 1905 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 1906 | sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH | WLAN_STA_AUTHORIZED); |
| 1907 | |
| 1908 | if (hostapd_sta_add(hapd, sta->addr, 0, 0, |
| 1909 | sta->supported_rates, |
| 1910 | sta->supported_rates_len, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1911 | 0, NULL, NULL, NULL, 0, NULL, 0, NULL, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1912 | sta->flags, 0, 0, 0, 0, |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 1913 | mld_link_addr, mld_link_sta, eml_cap)) { |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 1914 | hostapd_logger(hapd, sta->addr, |
| 1915 | HOSTAPD_MODULE_IEEE80211, |
| 1916 | HOSTAPD_LEVEL_NOTICE, |
| 1917 | "Could not add STA to kernel driver"); |
| 1918 | return -1; |
| 1919 | } |
| 1920 | |
| 1921 | sta->added_unassoc = 1; |
| 1922 | return 0; |
| 1923 | } |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1924 | |
| 1925 | |
| 1926 | #ifdef CONFIG_IEEE80211BE |
| 1927 | void ap_sta_free_sta_profile(struct mld_info *info) |
| 1928 | { |
| 1929 | int i; |
| 1930 | |
| 1931 | if (!info) |
| 1932 | return; |
| 1933 | |
| 1934 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 1935 | os_free(info->links[i].resp_sta_profile); |
| 1936 | info->links[i].resp_sta_profile = NULL; |
| 1937 | } |
| 1938 | } |
| 1939 | #endif /* CONFIG_IEEE80211BE */ |