blob: 32944edff5c44f90b7854b66f5da78e4b82467ba [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Station table
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003 * Copyright (c) 2002-2017, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "utils/eloop.h"
13#include "common/ieee802_11_defs.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014#include "common/wpa_ctrl.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080015#include "common/sae.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070016#include "common/dpp.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070017#include "radius/radius.h"
18#include "radius/radius_client.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080020#include "fst/fst.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070021#include "crypto/crypto.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include "hostapd.h"
23#include "accounting.h"
24#include "ieee802_1x.h"
25#include "ieee802_11.h"
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080026#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#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 Shmidt04949592012-07-19 12:16:46 -070035#include "gas_serv.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080036#include "wnm_ap.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080037#include "mbo_ap.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080038#include "ndisc_snoop.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070039#include "sta_info.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080040#include "vlan.h"
Dmitry Shmidt29333592017-01-09 12:27:11 -080041#include "wps_hostapd.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042
43static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
44 struct sta_info *sta);
45static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080046static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080047static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
48static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070049static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080050static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
Dmitry Shmidt29333592017-01-09 12:27:11 -080051static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070052
53int 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
69struct 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 Shmidt391c59f2013-09-03 12:16:28 -070080#ifdef CONFIG_P2P
81struct 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 Ravib0ac25f2024-07-12 01:42:03 +000095 if (ether_addr_equal(p2p_dev_addr, addr))
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070096 return sta;
97 }
98
99 return NULL;
100}
101#endif /* CONFIG_P2P */
102
103
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104static 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
124void 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
131static 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 Ravib0ac25f2024-07-12 01:42:03 +0000143 !ether_addr_equal(s->hnext->addr, sta->addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700144 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 Shmidt6c0da2b2015-01-05 13:08:17 -0800153void ap_sta_ip6addr_del(struct hostapd_data *hapd, struct sta_info *sta)
154{
155 sta_ip6addr_del(hapd, sta);
156}
157
158
Hai Shalom60840252021-02-19 19:02:11 -0800159#ifdef CONFIG_PASN
160
161void 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 Ravi99c035e2024-07-12 01:42:03 +0000183 pasn_data_deinit(sta->pasn);
Hai Shalom60840252021-02-19 19:02:11 -0800184 sta->pasn = NULL;
185 }
186}
187
188#endif /* CONFIG_PASN */
189
Sunil Ravi99c035e2024-07-12 01:42:03 +0000190
191static 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 Shmidt8d520ff2011-05-09 14:06:53 -0700203void 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 Shalomfdcde762020-04-02 11:19:20 -0700211 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700212
Sunil Ravi640215c2023-06-28 23:08:09 +0000213 if ((sta->flags & WLAN_STA_WDS) ||
214 (sta->flags & WLAN_STA_MULTI_AP &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000215 (hapd->conf->multi_ap & BACKHAUL_BSS) &&
Sunil Ravi640215c2023-06-28 23:08:09 +0000216 !(sta->flags & WLAN_STA_WPS)))
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700217 hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700218
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800219 if (sta->ipaddr)
220 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
221 ap_sta_ip6addr_del(hapd, sta);
222
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800223 if (!hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800224 !(sta->flags & WLAN_STA_PREAUTH)) {
Sunil Ravi99c035e2024-07-12 01:42:03 +0000225 __ap_free_sta(hapd, sta);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800226 sta->added_unassoc = 0;
227 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700228
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 Pius3a1667e2018-07-03 15:17:14 -0700247 if (hapd->iface->current_mode &&
248 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700249 && 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 Pius3a1667e2018-07-03 15:17:14 -0700256 if (hapd->iface->current_mode &&
257 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700258 && 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 Shmidtaca489e2016-09-28 15:44:14 -0700277#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 Shmidt7832adb2014-04-29 10:53:02 -0700284 ht40_intolerant_remove(hapd->iface, sta);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700285
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700286#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 Shalomfdcde762020-04-02 11:19:20 -0700295#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700296 if (hostapd_ht_operation_update(hapd->iface) > 0)
297 set_beacon++;
Hai Shalomfdcde762020-04-02 11:19:20 -0700298#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800300#ifdef CONFIG_MESH
301 if (hapd->mesh_sta_free_cb)
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800302 hapd->mesh_sta_free_cb(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800303#endif /* CONFIG_MESH */
304
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700305 if (set_beacon)
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000306 ieee802_11_update_beacons(hapd->iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307
Dmitry Shmidt04949592012-07-19 12:16:46 -0700308 wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
309 __func__, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
311 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800312 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800313 ap_sta_clear_disconnect_timeouts(hapd, sta);
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800314 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800316 ieee802_1x_free_station(hapd, sta);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000317
318#ifdef CONFIG_IEEE80211BE
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000319 if (!ap_sta_is_mld(hapd, sta) ||
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000320 hapd->mld_link_id == sta->mld_assoc_link_id)
321 wpa_auth_sta_deinit(sta->wpa_sm);
322#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700323 wpa_auth_sta_deinit(sta->wpa_sm);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000324#endif /* CONFIG_IEEE80211BE */
325
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700326 rsn_preauth_free_station(hapd, sta);
327#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt96571392013-10-14 12:54:46 -0700328 if (hapd->radius)
329 radius_client_flush_auth(hapd->radius, sta->addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700330#endif /* CONFIG_NO_RADIUS */
331
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800332#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 Shmidt57c2d392016-02-23 13:40:19 -0800338 if (sta->vlan_id)
339 vlan_remove_dynamic(hapd, sta->vlan_id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800340 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 Shmidt57c2d392016-02-23 13:40:19 -0800346 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800347 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800348 sta->added_unassoc = 0;
349 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800350 vlan_remove_dynamic(hapd, sta->vlan_id_bound);
351 }
352#endif /* CONFIG_NO_VLAN */
353
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700354 os_free(sta->challenge);
355
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700356 os_free(sta->sa_query_trans_id);
357 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700358
359#ifdef CONFIG_P2P
360 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
361#endif /* CONFIG_P2P */
362
Dmitry Shmidt04949592012-07-19 12:16:46 -0700363#ifdef CONFIG_INTERWORKING
364 if (sta->gas_dialog) {
365 int i;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000366
Dmitry Shmidt04949592012-07-19 12:16:46 -0700367 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 Shmidt8d520ff2011-05-09 14:06:53 -0700373 wpabuf_free(sta->wps_ie);
374 wpabuf_free(sta->p2p_ie);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800375 wpabuf_free(sta->hs20_ie);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700376 wpabuf_free(sta->roaming_consortium);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800377#ifdef CONFIG_FST
378 wpabuf_free(sta->mb_ies);
379#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700380
381 os_free(sta->ht_capabilities);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -0800382 os_free(sta->vht_capabilities);
Hai Shalom74f70d42019-02-11 14:42:39 -0800383 os_free(sta->vht_operation);
Hai Shalom81f62d82019-07-22 12:10:00 -0700384 os_free(sta->he_capab);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700385 os_free(sta->he_6ghz_capab);
Sunil Ravia04bd252022-05-02 22:54:18 -0700386 os_free(sta->eht_capab);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800387 hostapd_free_psk_list(sta->psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700388 os_free(sta->identity);
389 os_free(sta->radius_cui);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800390 os_free(sta->remediation_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700391 os_free(sta->t_c_url);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800392 wpabuf_free(sta->hs20_deauth_req);
393 os_free(sta->hs20_session_info_url);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700394
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800395#ifdef CONFIG_SAE
396 sae_clear_data(sta->sae);
397 os_free(sta->sae);
398#endif /* CONFIG_SAE */
399
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800400 mbo_ap_sta_free(sta);
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800401 os_free(sta->supp_op_classes);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800402
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800403#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 Shmidtd2986c22017-10-23 14:22:09 -0700408#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 Shmidtebd93af2017-02-21 13:40:44 -0800413#endif /* CONFIG_FILS */
414
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700415#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 Shalom021b0b52019-04-10 11:17:58 -0700420#ifdef CONFIG_DPP2
421 dpp_pfs_free(sta->dpp_pfs);
422 sta->dpp_pfs = NULL;
423#endif /* CONFIG_DPP2 */
424
Roshan Pius3a1667e2018-07-03 15:17:14 -0700425 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 Shalom60840252021-02-19 19:02:11 -0800431#ifdef CONFIG_PASN
432 ap_free_sta_pasn(hapd, sta);
433#endif /* CONFIG_PASN */
434
Roshan Pius3a1667e2018-07-03 15:17:14 -0700435 os_free(sta->ifname_wds);
436
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000437#ifdef CONFIG_IEEE80211BE
438 ap_sta_free_sta_profile(&sta->mld_info);
439#endif /* CONFIG_IEEE80211BE */
440
Hai Shalomfdcde762020-04-02 11:19:20 -0700441#ifdef CONFIG_TESTING_OPTIONS
442 os_free(sta->sae_postponed_commit);
Sunil Ravia04bd252022-05-02 22:54:18 -0700443 forced_memzero(sta->last_tk, WPA_TK_MAX_LEN);
Hai Shalomfdcde762020-04-02 11:19:20 -0700444#endif /* CONFIG_TESTING_OPTIONS */
445
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446 os_free(sta);
447}
448
449
450void 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 Ravi99c035e2024-07-12 01:42:03 +0000470#ifdef CONFIG_IEEE80211BE
471void 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 Shmidt8d520ff2011-05-09 14:06:53 -0700491/**
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 */
499void 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 Shmidtb6e9aaf2013-05-20 14:49:44 -0700504 int reason;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700505
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800506 wpa_printf(MSG_DEBUG, "%s: %s: " MACSTR " flags=0x%x timeout_next=%d",
507 hapd->conf->iface, __func__, MAC2STR(sta->addr), sta->flags,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700508 sta->timeout_next);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700509 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 Shmidt04949592012-07-19 12:16:46 -0700521 /*
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 Shmidt8d520ff2011-05-09 14:06:53 -0700527 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
528 if (inactive_sec == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800529 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
530 "Check inactivity: Could not "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800531 "get station info from kernel driver for "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700532 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800533 /*
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 Shmidt04949592012-07-19 12:16:46 -0700538 next_time = hapd->conf->ap_max_inactivity + fuzz;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800539 } 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 Shmidt7f656022015-02-25 14:36:37 -0800544 /* Avoid sending client probe on removed client */
545 sta->timeout_next = STA_DISASSOC;
546 goto skip_poll;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800547 } else if (inactive_sec < hapd->conf->ap_max_inactivity) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700548 /* station activity detected; reset timeout state */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800549 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
550 "Station " MACSTR " has been active %is ago",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700551 MAC2STR(sta->addr), inactive_sec);
552 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700553 next_time = hapd->conf->ap_max_inactivity + fuzz -
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700554 inactive_sec;
555 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800556 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
557 "Station " MACSTR " has been "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700558 "inactive too long: %d sec, max allowed: %d",
559 MAC2STR(sta->addr), inactive_sec,
560 hapd->conf->ap_max_inactivity);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800561
562 if (hapd->conf->skip_inactivity_poll)
563 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700564 }
565 }
566
567 if ((sta->flags & WLAN_STA_ASSOC) &&
568 sta->timeout_next == STA_DISASSOC &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800569 !(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 Shmidt8d520ff2011-05-09 14:06:53 -0700573 /* 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 Shmidt7f656022015-02-25 14:36:37 -0800579skip_poll:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700580 if (next_time) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700581 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
582 "for " MACSTR " (%lu seconds)",
583 __func__, MAC2STR(sta->addr), next_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584 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 Shmidt1f69aa52012-01-24 16:10:04 -0800591 wpa_printf(MSG_DEBUG, " Polling STA");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700592 sta->flags |= WLAN_STA_PENDING_POLL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800593 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
594 sta->flags & WLAN_STA_WMM);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700595 } else if (sta->timeout_next != STA_REMOVE) {
596 int deauth = sta->timeout_next == STA_DEAUTH;
597
Hai Shalom74f70d42019-02-11 14:42:39 -0800598 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 Shmidt1f69aa52012-01-24 16:10:04 -0800605 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
606 "Timeout, sending %s info to STA " MACSTR,
607 deauth ? "deauthentication" : "disassociation",
608 MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700609
610 if (deauth) {
611 hostapd_drv_sta_deauth(
612 hapd, sta->addr,
613 WLAN_REASON_PREV_AUTH_NOT_VALID);
614 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700615 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 Shmidt8d520ff2011-05-09 14:06:53 -0700620 }
621 }
622
623 switch (sta->timeout_next) {
624 case STA_NULLFUNC:
625 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700626 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 Shmidt8d520ff2011-05-09 14:06:53 -0700629 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
630 hapd, sta);
631 break;
632 case STA_DISASSOC:
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700633 case STA_DISASSOC_FROM_CLI:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800634 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700635 sta->flags &= ~WLAN_STA_ASSOC;
Hai Shalomfdcde762020-04-02 11:19:20 -0700636 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700637 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 Shmidtde47be72016-01-07 12:52:55 -0800642 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700643 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
644 HOSTAPD_LEVEL_INFO, "disassociated due to "
645 "inactivity");
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700646 reason = (sta->timeout_next == STA_DISASSOC) ?
647 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
648 WLAN_REASON_PREV_AUTH_NOT_VALID;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700649 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700650 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 Shmidt8d520ff2011-05-09 14:06:53 -0700653 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
654 hapd, sta);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700655 mlme_disassociate_indication(hapd, sta, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656 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 Shmidt1f69aa52012-01-24 16:10:04 -0800661 "inactivity (timer DEAUTH/REMOVE)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662 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
674static 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 Shmidt8d520ff2011-05-09 14:06:53 -0700678
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800679 wpa_printf(MSG_DEBUG, "%s: Session timer for STA " MACSTR,
680 hapd->conf->iface, MAC2STR(sta->addr));
Hai Shalomfdcde762020-04-02 11:19:20 -0700681 if (!(sta->flags & (WLAN_STA_AUTH | WLAN_STA_ASSOC |
682 WLAN_STA_AUTHORIZED))) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700683 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 Shmidt8d520ff2011-05-09 14:06:53 -0700688 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700689 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700690
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700691 hostapd_drv_sta_deauth(hapd, sta->addr,
692 WLAN_REASON_PREV_AUTH_NOT_VALID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700693 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 Shmidt8d520ff2011-05-09 14:06:53 -0700700 ap_free_sta(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701}
702
703
Dmitry Shmidt54605472013-11-08 11:10:19 -0800704void 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 Shmidtfb79edc2014-01-10 10:45:54 -0800708 ap_handle_session_timer, hapd, sta) == 1) {
Dmitry Shmidt54605472013-11-08 11:10:19 -0800709 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 Shmidt8d520ff2011-05-09 14:06:53 -0700716void 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
728void 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 Shmidtf21452a2014-02-26 10:55:25 -0800734static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx)
735{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700736#ifdef CONFIG_WNM_AP
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800737 struct hostapd_data *hapd = eloop_ctx;
738 struct sta_info *sta = timeout_ctx;
739
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800740 wpa_printf(MSG_DEBUG, "%s: WNM: Session warning time reached for "
741 MACSTR, hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800742 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 Shmidtd2986c22017-10-23 14:22:09 -0700747#endif /* CONFIG_WNM_AP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800748}
749
750
751void 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 Shmidt8d520ff2011-05-09 14:06:53 -0700760struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
761{
762 struct sta_info *sta;
Hai Shalom81f62d82019-07-22 12:10:00 -0700763 int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764
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 Shmidtb97e4282016-02-08 10:16:07 -0800783 if (accounting_sta_get_id(hapd, sta) < 0) {
784 os_free(sta);
785 return NULL;
786 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700787
Hai Shalom81f62d82019-07-22 12:10:00 -0700788 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 Shmidt01904cf2013-12-05 11:08:35 -0800797 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 Shmidt8d520ff2011-05-09 14:06:53 -0700806 /* initialize STA info data */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700807 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 Shmidt8d520ff2011-05-09 14:06:53 -0700812 ap_sta_remove_in_other_bss(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800813 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
814 dl_list_init(&sta->ip6addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700815
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700816#ifdef CONFIG_TAXONOMY
817 sta_track_claim_taxonomy_info(hapd->iface, addr,
818 &sta->probe_ie_taxonomy);
819#endif /* CONFIG_TAXONOMY */
820
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700821 return sta;
822}
823
824
825static 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 Shmidt6c0da2b2015-01-05 13:08:17 -0800829 if (sta->ipaddr)
830 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
831 ap_sta_ip6addr_del(hapd, sta);
832
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800833 wpa_printf(MSG_DEBUG, "%s: Removing STA " MACSTR " from kernel driver",
834 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700835 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
836 sta->flags & WLAN_STA_ASSOC) {
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800837 wpa_printf(MSG_DEBUG, "%s: Could not remove station " MACSTR
838 " from kernel driver",
839 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700840 return -1;
841 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800842 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700843 return 0;
844}
845
846
847static 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 Shmidt1d6bf422016-01-19 15:51:35 -0800866 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 Shmidt8d520ff2011-05-09 14:06:53 -0700870 ap_sta_disconnect(bss, sta2, sta2->addr,
871 WLAN_REASON_PREV_AUTH_NOT_VALID);
872 }
873}
874
875
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800876static 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 Shmidt1d6bf422016-01-19 15:51:35 -0800881 wpa_printf(MSG_DEBUG, "%s: Disassociation callback for STA " MACSTR,
882 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800883 ap_sta_remove(hapd, sta);
884 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
885}
886
887
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000888static void ap_sta_disconnect_common(struct hostapd_data *hapd,
889 struct sta_info *sta, unsigned int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700890{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800891 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000892
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800893 ap_sta_set_authorized(hapd, sta, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700894 hostapd_set_sta_flags(hapd, sta);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000895
896 wpa_printf(MSG_DEBUG,
897 "reschedule ap_handle_timer timeout (%u sec) for " MACSTR,
898 MAC2STR(sta->addr), timeout);
899
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700900 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000901 eloop_register_timeout(timeout, 0, ap_handle_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700902 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800903 ieee802_1x_free_station(hapd, sta);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000904#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 Shalom81f62d82019-07-22 12:10:00 -0700909 wpa_auth_sta_deinit(sta->wpa_sm);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000910#endif /* CONFIG_IEEE80211BE */
911
Hai Shalom81f62d82019-07-22 12:10:00 -0700912 sta->wpa_sm = NULL;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000913}
914
915
916static 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 Shmidt8d520ff2011-05-09 14:06:53 -0700934
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800935 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
944static 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 Shmidt1d6bf422016-01-19 15:51:35 -0800949 wpa_printf(MSG_DEBUG, "%s: Deauthentication callback for STA " MACSTR,
950 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800951 ap_sta_remove(hapd, sta);
952 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700953}
954
955
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000956static void ap_sta_handle_deauthenticate(struct hostapd_data *hapd,
957 struct sta_info *sta, u16 reason)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700958{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800959 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 Shmidt8d520ff2011-05-09 14:06:53 -0700967 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
968 hapd->conf->iface, MAC2STR(sta->addr));
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000969
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800970 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000971
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700972 sta->timeout_next = STA_REMOVE;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000973 ap_sta_disconnect_common(hapd, sta, AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700974
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800975 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 Shmidt8d520ff2011-05-09 14:06:53 -0700981}
982
983
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000984static 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 Ravi99c035e2024-07-12 01:42:03 +00001007 if (!assoc_sta->mld_info.links[link_id].valid)
1008 continue;
1009
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001010 for (i = 0; i < interfaces->count; i++) {
1011 struct sta_info *tmp_sta;
1012
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001013 tmp_hapd = interfaces->iface[i]->bss[0];
1014
Sunil Ravi99c035e2024-07-12 01:42:03 +00001015 if (!hostapd_is_ml_partner(tmp_hapd, assoc_hapd))
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001016 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
1062void 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
1072void 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 Shmidt04949592012-07-19 12:16:46 -07001082#ifdef CONFIG_WPS
1083int 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 Shmidt57c2d392016-02-23 13:40:19 -08001099static 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
1104retry:
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
1115int 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 Shmidt57c2d392016-02-23 13:40:19 -08001121 /* 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 }
1206done:
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 Shmidt83474442015-04-15 13:47:09 -07001218int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001219{
1220#ifndef CONFIG_NO_VLAN
1221 const char *iface;
1222 struct hostapd_vlan *vlan = NULL;
1223 int ret;
Dmitry Shmidt83474442015-04-15 13:47:09 -07001224 int old_vlanid = sta->vlan_id_bound;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001225 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 Shmidt8d520ff2011-05-09 14:06:53 -07001231
Hai Shalomfdcde762020-04-02 11:19:20 -07001232 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 Shmidt8d520ff2011-05-09 14:06:53 -07001239 iface = hapd->conf->iface;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001240 if (hapd->conf->ssid.vlan[0])
1241 iface = hapd->conf->ssid.vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001242
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001243 if (sta->vlan_id > 0) {
1244 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001245 if (vlan->vlan_id == sta->vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001247 }
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001248 if (vlan)
1249 iface = vlan->ifname;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001250 }
1251
Dmitry Shmidt83474442015-04-15 13:47:09 -07001252 /*
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 Shalomfdcde762020-04-02 11:19:20 -07001260 if (sta->vlan_id > 0 && !vlan &&
1261 !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001262 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 Shmidt216983b2015-02-06 10:50:36 -08001266 ret = -1;
1267 goto done;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001268 } else if (vlan && vlan->dynamic_vlan > 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001269 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 Shmidt8d520ff2011-05-09 14:06:53 -07001275 }
1276
Dmitry Shmidt83474442015-04-15 13:47:09 -07001277 /* ref counters have been increased, so mark the station */
1278 sta->vlan_id_bound = sta->vlan_id;
1279
1280skip_counting:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001281 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 Ravi2a14cf12023-11-21 00:54:38 +00001288 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id,
1289 mld_link_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001290 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 Shmidt216983b2015-02-06 10:50:36 -08001295
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001296 /* During 1x reauth, if the vlan id changes, then remove the old id. */
Dmitry Shmidt83474442015-04-15 13:47:09 -07001297 if (old_vlanid > 0 && old_vlanid != sta->vlan_id)
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001298 vlan_remove_dynamic(hapd, old_vlanid);
Dmitry Shmidt83474442015-04-15 13:47:09 -07001299done:
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001300
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001301 return ret;
1302#else /* CONFIG_NO_VLAN */
1303 return 0;
1304#endif /* CONFIG_NO_VLAN */
1305}
1306
1307
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
1309{
1310 u32 tu;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001311 struct os_reltime now, passed;
1312 os_get_reltime(&now);
1313 os_reltime_sub(&now, &sta->sa_query_start, &passed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001314 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
1332static 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 Shmidt1d6bf422016-01-19 15:51:35 -08001339 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 Shmidt8d520ff2011-05-09 14:06:53 -07001343 if (sta->sa_query_count > 0 &&
1344 ap_check_sa_query_timeout(hapd, sta))
1345 return;
Hai Shalomfdcde762020-04-02 11:19:20 -07001346 if (sta->sa_query_count >= 1000)
1347 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001348
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001349 nbuf = os_realloc_array(sta->sa_query_trans_id,
1350 sta->sa_query_count + 1,
1351 WLAN_SA_QUERY_TR_ID_LEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001352 if (nbuf == NULL)
1353 return;
1354 if (sta->sa_query_count == 0) {
1355 /* Starting a new SA Query procedure */
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001356 os_get_reltime(&sta->sa_query_start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001357 }
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 Shmidt6c0da2b2015-01-05 13:08:17 -08001362 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 Shmidt8d520ff2011-05-09 14:06:53 -07001371
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 Shmidt8d520ff2011-05-09 14:06:53 -07001381 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001382}
1383
1384
1385void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1386{
1387 ap_sa_query_timer(hapd, sta);
1388}
1389
1390
1391void 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 Shmidt8d520ff2011-05-09 14:06:53 -07001399
Hai Shalom74f70d42019-02-11 14:42:39 -08001400const 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 Shalom74f70d42019-02-11 14:42:39 -08001417 if (!psk || !psk->keyid[0])
1418 return NULL;
1419
1420 return psk->keyid;
1421}
1422
1423
Sunil Ravi77d572f2023-01-17 23:58:31 +00001424const 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 Ravib0ac25f2024-07-12 01:42:03 +00001431bool ap_sta_set_authorized_flag(struct hostapd_data *hapd, struct sta_info *sta,
1432 int authorized)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001433{
1434 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001435 return false;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001436
Sunil Ravi640215c2023-06-28 23:08:09 +00001437 if (authorized) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001438 int mld_assoc_link_id = -1;
1439
1440#ifdef CONFIG_IEEE80211BE
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001441 if (ap_sta_is_mld(hapd, sta)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001442 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 Shmidt6c0da2b2015-01-05 13:08:17 -08001451 sta->flags |= WLAN_STA_AUTHORIZED;
Sunil Ravi640215c2023-06-28 23:08:09 +00001452 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001453 sta->flags &= ~WLAN_STA_AUTHORIZED;
Sunil Ravi640215c2023-06-28 23:08:09 +00001454 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001455
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001456 return true;
1457}
1458
1459
1460void 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 Ravi99c035e2024-07-12 01:42:03 +00001469 const u8 *ip_ptr = NULL;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001470
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001471#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001472 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 Shmidt1f69aa52012-01-24 16:10:04 -08001478
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001479 if (dev_addr)
1480 os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
1481 MAC2STR(sta->addr), MAC2STR(dev_addr));
1482 else
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001483#endif /* CONFIG_P2P */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001484 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
1485
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001486 if (authorized) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00001487 const u8 *dpp_pkhash;
Hai Shalom74f70d42019-02-11 14:42:39 -08001488 const char *keyid;
Sunil Ravi77d572f2023-01-17 23:58:31 +00001489 char dpp_pkhash_buf[100];
Hai Shalom74f70d42019-02-11 14:42:39 -08001490 char keyid_buf[100];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001491 char ip_addr[100];
Hai Shalom74f70d42019-02-11 14:42:39 -08001492
Sunil Ravi77d572f2023-01-17 23:58:31 +00001493 dpp_pkhash_buf[0] = '\0';
Hai Shalom74f70d42019-02-11 14:42:39 -08001494 keyid_buf[0] = '\0';
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001495 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 Ravid8128a22023-11-06 23:53:58 +00001502 ip_ptr = ip_addr_buf;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001503 }
1504#endif /* CONFIG_P2P */
1505
Hai Shalom74f70d42019-02-11 14:42:39 -08001506 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 Ravi77d572f2023-01-17 23:58:31 +00001512 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 Shmidtb6e9aaf2013-05-20 14:49:44 -07001526
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001527 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001528 hapd->msg_ctx_parent != hapd->msg_ctx)
1529 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
Sunil Ravi77d572f2023-01-17 23:58:31 +00001530 AP_STA_CONNECTED "%s%s%s%s",
1531 buf, ip_addr, keyid_buf,
1532 dpp_pkhash_buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001533 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001534 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
1535
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001536 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001537 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 Shmidt1f69aa52012-01-24 16:10:04 -08001540 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001541
Sunil Ravid8128a22023-11-06 23:53:58 +00001542 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 Shmidtd80a4012015-11-05 16:35:40 -08001547#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 Shmidt8d520ff2011-05-09 14:06:53 -07001556}
1557
1558
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001559void 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 Shmidt8d520ff2011-05-09 14:06:53 -07001568void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
1569 const u8 *addr, u16 reason)
1570{
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001571 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 Shmidt8d520ff2011-05-09 14:06:53 -07001579
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 Shalomfdcde762020-04-02 11:19:20 -07001589 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1590 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001591 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1592 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001593 wpa_printf(MSG_DEBUG, "%s: %s: reschedule ap_handle_timer timeout "
Dmitry Shmidt04949592012-07-19 12:16:46 -07001594 "for " MACSTR " (%d seconds - "
1595 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001596 hapd->conf->iface, __func__, MAC2STR(sta->addr),
Dmitry Shmidt04949592012-07-19 12:16:46 -07001597 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001598 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001599 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
1600 ap_handle_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001601 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001602
Dmitry Shmidt29333592017-01-09 12:27:11 -08001603 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 Shmidt1f69aa52012-01-24 16:10:04 -08001617 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
1626void 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
1638void 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 Shmidt8d520ff2011-05-09 14:06:53 -07001647}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001648
1649
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001650void 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 Shmidt29333592017-01-09 12:27:11 -08001663 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 Shmidt1d6bf422016-01-19 15:51:35 -08001672}
1673
1674
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001675int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen)
1676{
1677 int res;
1678
1679 buf[0] = '\0';
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001680 res = os_snprintf(buf, buflen,
Sunil Ravia04bd252022-05-02 22:54:18 -07001681 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001682 (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 Pius3a1667e2018-07-03 15:17:14 -07001698 (flags & WLAN_STA_HT ? "[HT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001699 (flags & WLAN_STA_VHT ? "[VHT]" : ""),
Hai Shalomc3565922019-10-28 11:58:20 -07001700 (flags & WLAN_STA_HE ? "[HE]" : ""),
Sunil Ravia04bd252022-05-02 22:54:18 -07001701 (flags & WLAN_STA_EHT ? "[EHT]" : ""),
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001702 (flags & WLAN_STA_6GHZ ? "[6GHZ]" : ""),
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001703 (flags & WLAN_STA_VENDOR_VHT ? "[VENDOR_VHT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001704 (flags & WLAN_STA_WNM_SLEEP_MODE ?
1705 "[WNM_SLEEP_MODE]" : ""));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001706 if (os_snprintf_error(buflen, res))
1707 res = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001708
1709 return res;
1710}
Dmitry Shmidt29333592017-01-09 12:27:11 -08001711
1712
1713static 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 Pius3a1667e2018-07-03 15:17:14 -07001717 u16 reason;
Dmitry Shmidt29333592017-01-09 12:27:11 -08001718
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 Pius3a1667e2018-07-03 15:17:14 -07001723 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 Shmidt29333592017-01-09 12:27:11 -08001727 if (sta->flags & WLAN_STA_WPS)
1728 hostapd_wps_eap_completed(hapd);
1729}
1730
1731
1732void ap_sta_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
Sunil Ravi640215c2023-06-28 23:08:09 +00001733 struct sta_info *sta,
1734 unsigned timeout)
Dmitry Shmidt29333592017-01-09 12:27:11 -08001735{
1736 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1737 "IEEE 802.1X: Force disconnection of " MACSTR
Sunil Ravi640215c2023-06-28 23:08:09 +00001738 " after EAP-Failure in %u ms", MAC2STR(sta->addr), timeout);
Dmitry Shmidt29333592017-01-09 12:27:11 -08001739
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 Ravi640215c2023-06-28 23:08:09 +00001746 eloop_register_timeout(0, timeout * 1000,
1747 ap_sta_delayed_1x_auth_fail_cb, hapd, sta);
Dmitry Shmidt29333592017-01-09 12:27:11 -08001748}
1749
1750
1751int 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 Shalomb755a2a2020-04-23 21:49:02 -07001757
1758
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001759#ifdef CONFIG_IEEE80211BE
1760static 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 Ravi99c035e2024-07-12 01:42:03 +00001767 hostapd_get_mld_id(hapd)) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001768 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 Shalomb755a2a2020-04-23 21:49:02 -07001787int ap_sta_re_add(struct hostapd_data *hapd, struct sta_info *sta)
1788{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001789 const u8 *mld_link_addr = NULL;
1790 bool mld_link_sta = false;
1791
Hai Shalomb755a2a2020-04-23 21:49:02 -07001792 /*
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 Ravi2a14cf12023-11-21 00:54:38 +00001799
1800#ifdef CONFIG_IEEE80211BE
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001801 if (ap_sta_is_mld(hapd, sta)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001802 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 Ravib0ac25f2024-07-12 01:42:03 +00001806
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 Ravi2a14cf12023-11-21 00:54:38 +00001812 }
1813#endif /* CONFIG_IEEE80211BE */
1814
Hai Shalomb755a2a2020-04-23 21:49:02 -07001815 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 Ravia04bd252022-05-02 22:54:18 -07001822 0, NULL, NULL, NULL, 0, NULL, 0, NULL,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001823 sta->flags, 0, 0, 0, 0,
1824 mld_link_addr, mld_link_sta)) {
Hai Shalomb755a2a2020-04-23 21:49:02 -07001825 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 Ravib0ac25f2024-07-12 01:42:03 +00001835
1836
1837#ifdef CONFIG_IEEE80211BE
1838void 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 */