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