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