blob: a00f8967a7cfeaf9b673c06f1e6c70414e8d14ee [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
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 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 &&
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 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
183 bin_clear_free(sta->pasn, sizeof(*sta->pasn));
184 sta->pasn = NULL;
185 }
186}
187
188#endif /* CONFIG_PASN */
189
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700190void 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 Shalomfdcde762020-04-02 11:19:20 -0700198 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700199
Sunil Ravi640215c2023-06-28 23:08:09 +0000200 if ((sta->flags & WLAN_STA_WDS) ||
201 (sta->flags & WLAN_STA_MULTI_AP &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000202 (hapd->conf->multi_ap & BACKHAUL_BSS) &&
Sunil Ravi640215c2023-06-28 23:08:09 +0000203 !(sta->flags & WLAN_STA_WPS)))
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700204 hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700205
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800206 if (sta->ipaddr)
207 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
208 ap_sta_ip6addr_del(hapd, sta);
209
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800210 if (!hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800211 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700212 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800213 sta->added_unassoc = 0;
214 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700215
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 Pius3a1667e2018-07-03 15:17:14 -0700234 if (hapd->iface->current_mode &&
235 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700236 && 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 Pius3a1667e2018-07-03 15:17:14 -0700243 if (hapd->iface->current_mode &&
244 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700245 && 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 Shmidtaca489e2016-09-28 15:44:14 -0700264#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 Shmidt7832adb2014-04-29 10:53:02 -0700271 ht40_intolerant_remove(hapd->iface, sta);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700272
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700273#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 Shalomfdcde762020-04-02 11:19:20 -0700282#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700283 if (hostapd_ht_operation_update(hapd->iface) > 0)
284 set_beacon++;
Hai Shalomfdcde762020-04-02 11:19:20 -0700285#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700286
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800287#ifdef CONFIG_MESH
288 if (hapd->mesh_sta_free_cb)
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800289 hapd->mesh_sta_free_cb(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800290#endif /* CONFIG_MESH */
291
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292 if (set_beacon)
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000293 ieee802_11_update_beacons(hapd->iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700294
Dmitry Shmidt04949592012-07-19 12:16:46 -0700295 wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
296 __func__, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700297 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
298 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800299 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800300 ap_sta_clear_disconnect_timeouts(hapd, sta);
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800301 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700302
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800303 ieee802_1x_free_station(hapd, sta);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000304
305#ifdef CONFIG_IEEE80211BE
306 if (!hapd->conf->mld_ap || !sta->mld_info.mld_sta ||
307 hapd->mld_link_id == sta->mld_assoc_link_id)
308 wpa_auth_sta_deinit(sta->wpa_sm);
309#else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310 wpa_auth_sta_deinit(sta->wpa_sm);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000311#endif /* CONFIG_IEEE80211BE */
312
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700313 rsn_preauth_free_station(hapd, sta);
314#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt96571392013-10-14 12:54:46 -0700315 if (hapd->radius)
316 radius_client_flush_auth(hapd->radius, sta->addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700317#endif /* CONFIG_NO_RADIUS */
318
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800319#ifndef CONFIG_NO_VLAN
320 /*
321 * sta->wpa_sm->group needs to be released before so that
322 * vlan_remove_dynamic() can check that no stations are left on the
323 * AP_VLAN netdev.
324 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800325 if (sta->vlan_id)
326 vlan_remove_dynamic(hapd, sta->vlan_id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800327 if (sta->vlan_id_bound) {
328 /*
329 * Need to remove the STA entry before potentially removing the
330 * VLAN.
331 */
332 if (hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800333 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800334 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800335 sta->added_unassoc = 0;
336 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800337 vlan_remove_dynamic(hapd, sta->vlan_id_bound);
338 }
339#endif /* CONFIG_NO_VLAN */
340
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700341 os_free(sta->challenge);
342
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700343 os_free(sta->sa_query_trans_id);
344 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700345
346#ifdef CONFIG_P2P
347 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
348#endif /* CONFIG_P2P */
349
Dmitry Shmidt04949592012-07-19 12:16:46 -0700350#ifdef CONFIG_INTERWORKING
351 if (sta->gas_dialog) {
352 int i;
353 for (i = 0; i < GAS_DIALOG_MAX; i++)
354 gas_serv_dialog_clear(&sta->gas_dialog[i]);
355 os_free(sta->gas_dialog);
356 }
357#endif /* CONFIG_INTERWORKING */
358
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700359 wpabuf_free(sta->wps_ie);
360 wpabuf_free(sta->p2p_ie);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800361 wpabuf_free(sta->hs20_ie);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700362 wpabuf_free(sta->roaming_consortium);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800363#ifdef CONFIG_FST
364 wpabuf_free(sta->mb_ies);
365#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700366
367 os_free(sta->ht_capabilities);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -0800368 os_free(sta->vht_capabilities);
Hai Shalom74f70d42019-02-11 14:42:39 -0800369 os_free(sta->vht_operation);
Hai Shalom81f62d82019-07-22 12:10:00 -0700370 os_free(sta->he_capab);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700371 os_free(sta->he_6ghz_capab);
Sunil Ravia04bd252022-05-02 22:54:18 -0700372 os_free(sta->eht_capab);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800373 hostapd_free_psk_list(sta->psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700374 os_free(sta->identity);
375 os_free(sta->radius_cui);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800376 os_free(sta->remediation_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700377 os_free(sta->t_c_url);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800378 wpabuf_free(sta->hs20_deauth_req);
379 os_free(sta->hs20_session_info_url);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700380
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800381#ifdef CONFIG_SAE
382 sae_clear_data(sta->sae);
383 os_free(sta->sae);
384#endif /* CONFIG_SAE */
385
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800386 mbo_ap_sta_free(sta);
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800387 os_free(sta->supp_op_classes);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800388
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800389#ifdef CONFIG_FILS
390 os_free(sta->fils_pending_assoc_req);
391 wpabuf_free(sta->fils_hlp_resp);
392 wpabuf_free(sta->hlp_dhcp_discover);
393 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700394#ifdef CONFIG_FILS_SK_PFS
395 crypto_ecdh_deinit(sta->fils_ecdh);
396 wpabuf_clear_free(sta->fils_dh_ss);
397 wpabuf_free(sta->fils_g_sta);
398#endif /* CONFIG_FILS_SK_PFS */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800399#endif /* CONFIG_FILS */
400
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700401#ifdef CONFIG_OWE
402 bin_clear_free(sta->owe_pmk, sta->owe_pmk_len);
403 crypto_ecdh_deinit(sta->owe_ecdh);
404#endif /* CONFIG_OWE */
405
Hai Shalom021b0b52019-04-10 11:17:58 -0700406#ifdef CONFIG_DPP2
407 dpp_pfs_free(sta->dpp_pfs);
408 sta->dpp_pfs = NULL;
409#endif /* CONFIG_DPP2 */
410
Roshan Pius3a1667e2018-07-03 15:17:14 -0700411 os_free(sta->ext_capability);
412
413#ifdef CONFIG_WNM_AP
414 eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta);
415#endif /* CONFIG_WNM_AP */
416
Hai Shalom60840252021-02-19 19:02:11 -0800417#ifdef CONFIG_PASN
418 ap_free_sta_pasn(hapd, sta);
419#endif /* CONFIG_PASN */
420
Roshan Pius3a1667e2018-07-03 15:17:14 -0700421 os_free(sta->ifname_wds);
422
Hai Shalomfdcde762020-04-02 11:19:20 -0700423#ifdef CONFIG_TESTING_OPTIONS
424 os_free(sta->sae_postponed_commit);
Sunil Ravia04bd252022-05-02 22:54:18 -0700425 forced_memzero(sta->last_tk, WPA_TK_MAX_LEN);
Hai Shalomfdcde762020-04-02 11:19:20 -0700426#endif /* CONFIG_TESTING_OPTIONS */
427
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700428 os_free(sta);
429}
430
431
432void hostapd_free_stas(struct hostapd_data *hapd)
433{
434 struct sta_info *sta, *prev;
435
436 sta = hapd->sta_list;
437
438 while (sta) {
439 prev = sta;
440 if (sta->flags & WLAN_STA_AUTH) {
441 mlme_deauthenticate_indication(
442 hapd, sta, WLAN_REASON_UNSPECIFIED);
443 }
444 sta = sta->next;
445 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
446 MAC2STR(prev->addr));
447 ap_free_sta(hapd, prev);
448 }
449}
450
451
452/**
453 * ap_handle_timer - Per STA timer handler
454 * @eloop_ctx: struct hostapd_data *
455 * @timeout_ctx: struct sta_info *
456 *
457 * This function is called to check station activity and to remove inactive
458 * stations.
459 */
460void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
461{
462 struct hostapd_data *hapd = eloop_ctx;
463 struct sta_info *sta = timeout_ctx;
464 unsigned long next_time = 0;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700465 int reason;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800467 wpa_printf(MSG_DEBUG, "%s: %s: " MACSTR " flags=0x%x timeout_next=%d",
468 hapd->conf->iface, __func__, MAC2STR(sta->addr), sta->flags,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700469 sta->timeout_next);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700470 if (sta->timeout_next == STA_REMOVE) {
471 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
472 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
473 "local deauth request");
474 ap_free_sta(hapd, sta);
475 return;
476 }
477
478 if ((sta->flags & WLAN_STA_ASSOC) &&
479 (sta->timeout_next == STA_NULLFUNC ||
480 sta->timeout_next == STA_DISASSOC)) {
481 int inactive_sec;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700482 /*
483 * Add random value to timeout so that we don't end up bouncing
484 * all stations at the same time if we have lots of associated
485 * stations that are idle (but keep re-associating).
486 */
487 int fuzz = os_random() % 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700488 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
489 if (inactive_sec == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800490 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
491 "Check inactivity: Could not "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800492 "get station info from kernel driver for "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700493 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800494 /*
495 * The driver may not support this functionality.
496 * Anyway, try again after the next inactivity timeout,
497 * but do not disconnect the station now.
498 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700499 next_time = hapd->conf->ap_max_inactivity + fuzz;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800500 } else if (inactive_sec == -ENOENT) {
501 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
502 "Station " MACSTR " has lost its driver entry",
503 MAC2STR(sta->addr));
504
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800505 /* Avoid sending client probe on removed client */
506 sta->timeout_next = STA_DISASSOC;
507 goto skip_poll;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800508 } else if (inactive_sec < hapd->conf->ap_max_inactivity) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700509 /* station activity detected; reset timeout state */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800510 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
511 "Station " MACSTR " has been active %is ago",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700512 MAC2STR(sta->addr), inactive_sec);
513 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700514 next_time = hapd->conf->ap_max_inactivity + fuzz -
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700515 inactive_sec;
516 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800517 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
518 "Station " MACSTR " has been "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700519 "inactive too long: %d sec, max allowed: %d",
520 MAC2STR(sta->addr), inactive_sec,
521 hapd->conf->ap_max_inactivity);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800522
523 if (hapd->conf->skip_inactivity_poll)
524 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700525 }
526 }
527
528 if ((sta->flags & WLAN_STA_ASSOC) &&
529 sta->timeout_next == STA_DISASSOC &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800530 !(sta->flags & WLAN_STA_PENDING_POLL) &&
531 !hapd->conf->skip_inactivity_poll) {
532 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
533 " has ACKed data poll", MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700534 /* data nullfunc frame poll did not produce TX errors; assume
535 * station ACKed it */
536 sta->timeout_next = STA_NULLFUNC;
537 next_time = hapd->conf->ap_max_inactivity;
538 }
539
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800540skip_poll:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541 if (next_time) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700542 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
543 "for " MACSTR " (%lu seconds)",
544 __func__, MAC2STR(sta->addr), next_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700545 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
546 sta);
547 return;
548 }
549
550 if (sta->timeout_next == STA_NULLFUNC &&
551 (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800552 wpa_printf(MSG_DEBUG, " Polling STA");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700553 sta->flags |= WLAN_STA_PENDING_POLL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800554 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
555 sta->flags & WLAN_STA_WMM);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700556 } else if (sta->timeout_next != STA_REMOVE) {
557 int deauth = sta->timeout_next == STA_DEAUTH;
558
Hai Shalom74f70d42019-02-11 14:42:39 -0800559 if (!deauth && !(sta->flags & WLAN_STA_ASSOC)) {
560 /* Cannot disassociate not-associated STA, so move
561 * directly to deauthentication. */
562 sta->timeout_next = STA_DEAUTH;
563 deauth = 1;
564 }
565
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800566 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
567 "Timeout, sending %s info to STA " MACSTR,
568 deauth ? "deauthentication" : "disassociation",
569 MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700570
571 if (deauth) {
572 hostapd_drv_sta_deauth(
573 hapd, sta->addr,
574 WLAN_REASON_PREV_AUTH_NOT_VALID);
575 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700576 reason = (sta->timeout_next == STA_DISASSOC) ?
577 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
578 WLAN_REASON_PREV_AUTH_NOT_VALID;
579
580 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700581 }
582 }
583
584 switch (sta->timeout_next) {
585 case STA_NULLFUNC:
586 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700587 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
588 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
589 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700590 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
591 hapd, sta);
592 break;
593 case STA_DISASSOC:
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700594 case STA_DISASSOC_FROM_CLI:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800595 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700596 sta->flags &= ~WLAN_STA_ASSOC;
Hai Shalomfdcde762020-04-02 11:19:20 -0700597 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700598 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
599 if (!sta->acct_terminate_cause)
600 sta->acct_terminate_cause =
601 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
602 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800603 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700604 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
605 HOSTAPD_LEVEL_INFO, "disassociated due to "
606 "inactivity");
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700607 reason = (sta->timeout_next == STA_DISASSOC) ?
608 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
609 WLAN_REASON_PREV_AUTH_NOT_VALID;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700610 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700611 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
612 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
613 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700614 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
615 hapd, sta);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700616 mlme_disassociate_indication(hapd, sta, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700617 break;
618 case STA_DEAUTH:
619 case STA_REMOVE:
620 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
621 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800622 "inactivity (timer DEAUTH/REMOVE)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700623 if (!sta->acct_terminate_cause)
624 sta->acct_terminate_cause =
625 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
626 mlme_deauthenticate_indication(
627 hapd, sta,
628 WLAN_REASON_PREV_AUTH_NOT_VALID);
629 ap_free_sta(hapd, sta);
630 break;
631 }
632}
633
634
635static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
636{
637 struct hostapd_data *hapd = eloop_ctx;
638 struct sta_info *sta = timeout_ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800640 wpa_printf(MSG_DEBUG, "%s: Session timer for STA " MACSTR,
641 hapd->conf->iface, MAC2STR(sta->addr));
Hai Shalomfdcde762020-04-02 11:19:20 -0700642 if (!(sta->flags & (WLAN_STA_AUTH | WLAN_STA_ASSOC |
643 WLAN_STA_AUTHORIZED))) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700644 if (sta->flags & WLAN_STA_GAS) {
645 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
646 "entry " MACSTR, MAC2STR(sta->addr));
647 ap_free_sta(hapd, sta);
648 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700649 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700650 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700651
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700652 hostapd_drv_sta_deauth(hapd, sta->addr,
653 WLAN_REASON_PREV_AUTH_NOT_VALID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700654 mlme_deauthenticate_indication(hapd, sta,
655 WLAN_REASON_PREV_AUTH_NOT_VALID);
656 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
657 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
658 "session timeout");
659 sta->acct_terminate_cause =
660 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661 ap_free_sta(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662}
663
664
Dmitry Shmidt54605472013-11-08 11:10:19 -0800665void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta,
666 u32 session_timeout)
667{
668 if (eloop_replenish_timeout(session_timeout, 0,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800669 ap_handle_session_timer, hapd, sta) == 1) {
Dmitry Shmidt54605472013-11-08 11:10:19 -0800670 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
671 HOSTAPD_LEVEL_DEBUG, "setting session timeout "
672 "to %d seconds", session_timeout);
673 }
674}
675
676
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700677void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
678 u32 session_timeout)
679{
680 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
681 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
682 "seconds", session_timeout);
683 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
684 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
685 hapd, sta);
686}
687
688
689void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
690{
691 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
692}
693
694
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800695static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx)
696{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700697#ifdef CONFIG_WNM_AP
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800698 struct hostapd_data *hapd = eloop_ctx;
699 struct sta_info *sta = timeout_ctx;
700
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800701 wpa_printf(MSG_DEBUG, "%s: WNM: Session warning time reached for "
702 MACSTR, hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800703 if (sta->hs20_session_info_url == NULL)
704 return;
705
706 wnm_send_ess_disassoc_imminent(hapd, sta, sta->hs20_session_info_url,
707 sta->hs20_disassoc_timer);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700708#endif /* CONFIG_WNM_AP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800709}
710
711
712void ap_sta_session_warning_timeout(struct hostapd_data *hapd,
713 struct sta_info *sta, int warning_time)
714{
715 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
716 eloop_register_timeout(warning_time, 0, ap_handle_session_warning_timer,
717 hapd, sta);
718}
719
720
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
722{
723 struct sta_info *sta;
Hai Shalom81f62d82019-07-22 12:10:00 -0700724 int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725
726 sta = ap_get_sta(hapd, addr);
727 if (sta)
728 return sta;
729
730 wpa_printf(MSG_DEBUG, " New STA");
731 if (hapd->num_sta >= hapd->conf->max_num_sta) {
732 /* FIX: might try to remove some old STAs first? */
733 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
734 hapd->num_sta, hapd->conf->max_num_sta);
735 return NULL;
736 }
737
738 sta = os_zalloc(sizeof(struct sta_info));
739 if (sta == NULL) {
740 wpa_printf(MSG_ERROR, "malloc failed");
741 return NULL;
742 }
743 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800744 if (accounting_sta_get_id(hapd, sta) < 0) {
745 os_free(sta);
746 return NULL;
747 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700748
Hai Shalom81f62d82019-07-22 12:10:00 -0700749 for (i = 0; i < WLAN_SUPP_RATES_MAX; i++) {
750 if (!hapd->iface->basic_rates)
751 break;
752 if (hapd->iface->basic_rates[i] < 0)
753 break;
754 sta->supported_rates[i] = hapd->iface->basic_rates[i] / 5;
755 }
756 sta->supported_rates_len = i;
757
Dmitry Shmidt01904cf2013-12-05 11:08:35 -0800758 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
759 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
760 "for " MACSTR " (%d seconds - ap_max_inactivity)",
761 __func__, MAC2STR(addr),
762 hapd->conf->ap_max_inactivity);
763 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
764 ap_handle_timer, hapd, sta);
765 }
766
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767 /* initialize STA info data */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700768 os_memcpy(sta->addr, addr, ETH_ALEN);
769 sta->next = hapd->sta_list;
770 hapd->sta_list = sta;
771 hapd->num_sta++;
772 ap_sta_hash_add(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 ap_sta_remove_in_other_bss(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800774 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
775 dl_list_init(&sta->ip6addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700777#ifdef CONFIG_TAXONOMY
778 sta_track_claim_taxonomy_info(hapd->iface, addr,
779 &sta->probe_ie_taxonomy);
780#endif /* CONFIG_TAXONOMY */
781
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700782 return sta;
783}
784
785
786static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
787{
788 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
789
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800790 if (sta->ipaddr)
791 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
792 ap_sta_ip6addr_del(hapd, sta);
793
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800794 wpa_printf(MSG_DEBUG, "%s: Removing STA " MACSTR " from kernel driver",
795 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700796 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
797 sta->flags & WLAN_STA_ASSOC) {
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800798 wpa_printf(MSG_DEBUG, "%s: Could not remove station " MACSTR
799 " from kernel driver",
800 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801 return -1;
802 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800803 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804 return 0;
805}
806
807
808static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
809 struct sta_info *sta)
810{
811 struct hostapd_iface *iface = hapd->iface;
812 size_t i;
813
814 for (i = 0; i < iface->num_bss; i++) {
815 struct hostapd_data *bss = iface->bss[i];
816 struct sta_info *sta2;
817 /* bss should always be set during operation, but it may be
818 * NULL during reconfiguration. Assume the STA is not
819 * associated to another BSS in that case to avoid NULL pointer
820 * dereferences. */
821 if (bss == hapd || bss == NULL)
822 continue;
823 sta2 = ap_get_sta(bss, sta->addr);
824 if (!sta2)
825 continue;
826
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800827 wpa_printf(MSG_DEBUG, "%s: disconnect old STA " MACSTR
828 " association from another BSS %s",
829 hapd->conf->iface, MAC2STR(sta2->addr),
830 bss->conf->iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700831 ap_sta_disconnect(bss, sta2, sta2->addr,
832 WLAN_REASON_PREV_AUTH_NOT_VALID);
833 }
834}
835
836
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800837static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
838{
839 struct hostapd_data *hapd = eloop_ctx;
840 struct sta_info *sta = timeout_ctx;
841
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800842 wpa_printf(MSG_DEBUG, "%s: Disassociation callback for STA " MACSTR,
843 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800844 ap_sta_remove(hapd, sta);
845 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
846}
847
848
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700849void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
850 u16 reason)
851{
852 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
853 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800854 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800855 if (hapd->iface->current_mode &&
856 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
857 /* Skip deauthentication in DMG/IEEE 802.11ad */
858 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
859 WLAN_STA_ASSOC_REQ_OK);
860 sta->timeout_next = STA_REMOVE;
861 } else {
862 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
863 sta->timeout_next = STA_DEAUTH;
864 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800865 ap_sta_set_authorized(hapd, sta, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700866 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700867 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
868 "for " MACSTR " (%d seconds - "
869 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
870 __func__, MAC2STR(sta->addr),
871 AP_MAX_INACTIVITY_AFTER_DISASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700872 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
873 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
874 ap_handle_timer, hapd, sta);
875 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800876 ieee802_1x_free_station(hapd, sta);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000877#ifdef CONFIG_IEEE80211BE
878 if (!hapd->conf->mld_ap ||
879 hapd->mld_link_id == sta->mld_assoc_link_id)
880 wpa_auth_sta_deinit(sta->wpa_sm);
881#else
Hai Shalom81f62d82019-07-22 12:10:00 -0700882 wpa_auth_sta_deinit(sta->wpa_sm);
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000883#endif /* CONFIG_IEEE80211BE */
884
Hai Shalom81f62d82019-07-22 12:10:00 -0700885 sta->wpa_sm = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700886
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800887 sta->disassoc_reason = reason;
888 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
889 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
890 eloop_register_timeout(hapd->iface->drv_flags &
891 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
892 ap_sta_disassoc_cb_timeout, hapd, sta);
893}
894
895
896static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
897{
898 struct hostapd_data *hapd = eloop_ctx;
899 struct sta_info *sta = timeout_ctx;
900
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800901 wpa_printf(MSG_DEBUG, "%s: Deauthentication callback for STA " MACSTR,
902 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800903 ap_sta_remove(hapd, sta);
904 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700905}
906
907
908void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
909 u16 reason)
910{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800911 if (hapd->iface->current_mode &&
912 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
913 /* Deauthentication is not used in DMG/IEEE 802.11ad;
914 * disassociate the STA instead. */
915 ap_sta_disassociate(hapd, sta, reason);
916 return;
917 }
918
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700919 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
920 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800921 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
922 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800923 ap_sta_set_authorized(hapd, sta, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -0700924 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700925 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700926 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
927 "for " MACSTR " (%d seconds - "
928 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
929 __func__, MAC2STR(sta->addr),
930 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700931 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
932 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
933 ap_handle_timer, hapd, sta);
934 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800935 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700936
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800937 sta->deauth_reason = reason;
938 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
939 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
940 eloop_register_timeout(hapd->iface->drv_flags &
941 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
942 ap_sta_deauth_cb_timeout, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700943}
944
945
Dmitry Shmidt04949592012-07-19 12:16:46 -0700946#ifdef CONFIG_WPS
947int ap_sta_wps_cancel(struct hostapd_data *hapd,
948 struct sta_info *sta, void *ctx)
949{
950 if (sta && (sta->flags & WLAN_STA_WPS)) {
951 ap_sta_deauthenticate(hapd, sta,
952 WLAN_REASON_PREV_AUTH_NOT_VALID);
953 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
954 __func__, MAC2STR(sta->addr));
955 return 1;
956 }
957
958 return 0;
959}
960#endif /* CONFIG_WPS */
961
962
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800963static int ap_sta_get_free_vlan_id(struct hostapd_data *hapd)
964{
965 struct hostapd_vlan *vlan;
966 int vlan_id = MAX_VLAN_ID + 2;
967
968retry:
969 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
970 if (vlan->vlan_id == vlan_id) {
971 vlan_id++;
972 goto retry;
973 }
974 }
975 return vlan_id;
976}
977
978
979int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta,
980 struct vlan_description *vlan_desc)
981{
982 struct hostapd_vlan *vlan = NULL, *wildcard_vlan = NULL;
983 int old_vlan_id, vlan_id = 0, ret = 0;
984
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800985 /* Check if there is something to do */
986 if (hapd->conf->ssid.per_sta_vif && !sta->vlan_id) {
987 /* This sta is lacking its own vif */
988 } else if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED &&
989 !hapd->conf->ssid.per_sta_vif && sta->vlan_id) {
990 /* sta->vlan_id needs to be reset */
991 } else if (!vlan_compare(vlan_desc, sta->vlan_desc)) {
992 return 0; /* nothing to change */
993 }
994
995 /* Now the real VLAN changed or the STA just needs its own vif */
996 if (hapd->conf->ssid.per_sta_vif) {
997 /* Assign a new vif, always */
998 /* find a free vlan_id sufficiently big */
999 vlan_id = ap_sta_get_free_vlan_id(hapd);
1000 /* Get wildcard VLAN */
1001 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
1002 if (vlan->vlan_id == VLAN_ID_WILDCARD)
1003 break;
1004 }
1005 if (!vlan) {
1006 hostapd_logger(hapd, sta->addr,
1007 HOSTAPD_MODULE_IEEE80211,
1008 HOSTAPD_LEVEL_DEBUG,
1009 "per_sta_vif missing wildcard");
1010 vlan_id = 0;
1011 ret = -1;
1012 goto done;
1013 }
1014 } else if (vlan_desc && vlan_desc->notempty) {
1015 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
1016 if (!vlan_compare(&vlan->vlan_desc, vlan_desc))
1017 break;
1018 if (vlan->vlan_id == VLAN_ID_WILDCARD)
1019 wildcard_vlan = vlan;
1020 }
1021 if (vlan) {
1022 vlan_id = vlan->vlan_id;
1023 } else if (wildcard_vlan) {
1024 vlan = wildcard_vlan;
1025 vlan_id = vlan_desc->untagged;
1026 if (vlan_desc->tagged[0]) {
1027 /* Tagged VLAN configuration */
1028 vlan_id = ap_sta_get_free_vlan_id(hapd);
1029 }
1030 } else {
1031 hostapd_logger(hapd, sta->addr,
1032 HOSTAPD_MODULE_IEEE80211,
1033 HOSTAPD_LEVEL_DEBUG,
1034 "missing vlan and wildcard for vlan=%d%s",
1035 vlan_desc->untagged,
1036 vlan_desc->tagged[0] ? "+" : "");
1037 vlan_id = 0;
1038 ret = -1;
1039 goto done;
1040 }
1041 }
1042
1043 if (vlan && vlan->vlan_id == VLAN_ID_WILDCARD) {
1044 vlan = vlan_add_dynamic(hapd, vlan, vlan_id, vlan_desc);
1045 if (vlan == NULL) {
1046 hostapd_logger(hapd, sta->addr,
1047 HOSTAPD_MODULE_IEEE80211,
1048 HOSTAPD_LEVEL_DEBUG,
1049 "could not add dynamic VLAN interface for vlan=%d%s",
1050 vlan_desc ? vlan_desc->untagged : -1,
1051 (vlan_desc && vlan_desc->tagged[0]) ?
1052 "+" : "");
1053 vlan_id = 0;
1054 ret = -1;
1055 goto done;
1056 }
1057
1058 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1059 HOSTAPD_LEVEL_DEBUG,
1060 "added new dynamic VLAN interface '%s'",
1061 vlan->ifname);
1062 } else if (vlan && vlan->dynamic_vlan > 0) {
1063 vlan->dynamic_vlan++;
1064 hostapd_logger(hapd, sta->addr,
1065 HOSTAPD_MODULE_IEEE80211,
1066 HOSTAPD_LEVEL_DEBUG,
1067 "updated existing dynamic VLAN interface '%s'",
1068 vlan->ifname);
1069 }
1070done:
1071 old_vlan_id = sta->vlan_id;
1072 sta->vlan_id = vlan_id;
1073 sta->vlan_desc = vlan ? &vlan->vlan_desc : NULL;
1074
1075 if (vlan_id != old_vlan_id && old_vlan_id)
1076 vlan_remove_dynamic(hapd, old_vlan_id);
1077
1078 return ret;
1079}
1080
1081
Dmitry Shmidt83474442015-04-15 13:47:09 -07001082int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083{
1084#ifndef CONFIG_NO_VLAN
1085 const char *iface;
1086 struct hostapd_vlan *vlan = NULL;
1087 int ret;
Dmitry Shmidt83474442015-04-15 13:47:09 -07001088 int old_vlanid = sta->vlan_id_bound;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001089 int mld_link_id = -1;
1090
1091#ifdef CONFIG_IEEE80211BE
1092 if (hapd->conf->mld_ap)
1093 mld_link_id = hapd->mld_link_id;
1094#endif /* CONFIG_IEEE80211BE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001095
Hai Shalomfdcde762020-04-02 11:19:20 -07001096 if ((sta->flags & WLAN_STA_WDS) && sta->vlan_id == 0) {
1097 wpa_printf(MSG_DEBUG,
1098 "Do not override WDS VLAN assignment for STA "
1099 MACSTR, MAC2STR(sta->addr));
1100 return 0;
1101 }
1102
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001103 iface = hapd->conf->iface;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001104 if (hapd->conf->ssid.vlan[0])
1105 iface = hapd->conf->ssid.vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001106
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001107 if (sta->vlan_id > 0) {
1108 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001109 if (vlan->vlan_id == sta->vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001110 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111 }
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001112 if (vlan)
1113 iface = vlan->ifname;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001114 }
1115
Dmitry Shmidt83474442015-04-15 13:47:09 -07001116 /*
1117 * Do not increment ref counters if the VLAN ID remains same, but do
1118 * not skip hostapd_drv_set_sta_vlan() as hostapd_drv_sta_remove() might
1119 * have been called before.
1120 */
1121 if (sta->vlan_id == old_vlanid)
1122 goto skip_counting;
1123
Hai Shalomfdcde762020-04-02 11:19:20 -07001124 if (sta->vlan_id > 0 && !vlan &&
1125 !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001126 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1127 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
1128 "binding station to (vlan_id=%d)",
1129 sta->vlan_id);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001130 ret = -1;
1131 goto done;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001132 } else if (vlan && vlan->dynamic_vlan > 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001133 vlan->dynamic_vlan++;
1134 hostapd_logger(hapd, sta->addr,
1135 HOSTAPD_MODULE_IEEE80211,
1136 HOSTAPD_LEVEL_DEBUG,
1137 "updated existing dynamic VLAN interface '%s'",
1138 iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001139 }
1140
Dmitry Shmidt83474442015-04-15 13:47:09 -07001141 /* ref counters have been increased, so mark the station */
1142 sta->vlan_id_bound = sta->vlan_id;
1143
1144skip_counting:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001145 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1146 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
1147 "'%s'", iface);
1148
1149 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
1150 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
1151
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001152 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id,
1153 mld_link_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001154 if (ret < 0) {
1155 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1156 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
1157 "entry to vlan_id=%d", sta->vlan_id);
1158 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001159
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001160 /* During 1x reauth, if the vlan id changes, then remove the old id. */
Dmitry Shmidt83474442015-04-15 13:47:09 -07001161 if (old_vlanid > 0 && old_vlanid != sta->vlan_id)
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001162 vlan_remove_dynamic(hapd, old_vlanid);
Dmitry Shmidt83474442015-04-15 13:47:09 -07001163done:
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001164
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001165 return ret;
1166#else /* CONFIG_NO_VLAN */
1167 return 0;
1168#endif /* CONFIG_NO_VLAN */
1169}
1170
1171
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001172int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
1173{
1174 u32 tu;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001175 struct os_reltime now, passed;
1176 os_get_reltime(&now);
1177 os_reltime_sub(&now, &sta->sa_query_start, &passed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001178 tu = (passed.sec * 1000000 + passed.usec) / 1024;
1179 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
1180 hostapd_logger(hapd, sta->addr,
1181 HOSTAPD_MODULE_IEEE80211,
1182 HOSTAPD_LEVEL_DEBUG,
1183 "association SA Query timed out");
1184 sta->sa_query_timed_out = 1;
1185 os_free(sta->sa_query_trans_id);
1186 sta->sa_query_trans_id = NULL;
1187 sta->sa_query_count = 0;
1188 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1189 return 1;
1190 }
1191
1192 return 0;
1193}
1194
1195
1196static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
1197{
1198 struct hostapd_data *hapd = eloop_ctx;
1199 struct sta_info *sta = timeout_ctx;
1200 unsigned int timeout, sec, usec;
1201 u8 *trans_id, *nbuf;
1202
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001203 wpa_printf(MSG_DEBUG, "%s: SA Query timer for STA " MACSTR
1204 " (count=%d)",
1205 hapd->conf->iface, MAC2STR(sta->addr), sta->sa_query_count);
1206
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001207 if (sta->sa_query_count > 0 &&
1208 ap_check_sa_query_timeout(hapd, sta))
1209 return;
Hai Shalomfdcde762020-04-02 11:19:20 -07001210 if (sta->sa_query_count >= 1000)
1211 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001212
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001213 nbuf = os_realloc_array(sta->sa_query_trans_id,
1214 sta->sa_query_count + 1,
1215 WLAN_SA_QUERY_TR_ID_LEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001216 if (nbuf == NULL)
1217 return;
1218 if (sta->sa_query_count == 0) {
1219 /* Starting a new SA Query procedure */
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001220 os_get_reltime(&sta->sa_query_start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001221 }
1222 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
1223 sta->sa_query_trans_id = nbuf;
1224 sta->sa_query_count++;
1225
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001226 if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) {
1227 /*
1228 * We don't really care which ID is used here, so simply
1229 * hardcode this if the mostly theoretical os_get_random()
1230 * failure happens.
1231 */
1232 trans_id[0] = 0x12;
1233 trans_id[1] = 0x34;
1234 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001235
1236 timeout = hapd->conf->assoc_sa_query_retry_timeout;
1237 sec = ((timeout / 1000) * 1024) / 1000;
1238 usec = (timeout % 1000) * 1024;
1239 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
1240
1241 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1242 HOSTAPD_LEVEL_DEBUG,
1243 "association SA Query attempt %d", sta->sa_query_count);
1244
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246}
1247
1248
1249void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1250{
1251 ap_sa_query_timer(hapd, sta);
1252}
1253
1254
1255void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1256{
1257 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1258 os_free(sta->sa_query_trans_id);
1259 sta->sa_query_trans_id = NULL;
1260 sta->sa_query_count = 0;
1261}
1262
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001263
Hai Shalom74f70d42019-02-11 14:42:39 -08001264const char * ap_sta_wpa_get_keyid(struct hostapd_data *hapd,
1265 struct sta_info *sta)
1266{
1267 struct hostapd_wpa_psk *psk;
1268 struct hostapd_ssid *ssid;
1269 const u8 *pmk;
1270 int pmk_len;
1271
1272 ssid = &hapd->conf->ssid;
1273
1274 pmk = wpa_auth_get_pmk(sta->wpa_sm, &pmk_len);
1275 if (!pmk || pmk_len != PMK_LEN)
1276 return NULL;
1277
1278 for (psk = ssid->wpa_psk; psk; psk = psk->next)
1279 if (os_memcmp(pmk, psk->psk, PMK_LEN) == 0)
1280 break;
Hai Shalom74f70d42019-02-11 14:42:39 -08001281 if (!psk || !psk->keyid[0])
1282 return NULL;
1283
1284 return psk->keyid;
1285}
1286
1287
Sunil Ravi77d572f2023-01-17 23:58:31 +00001288const u8 * ap_sta_wpa_get_dpp_pkhash(struct hostapd_data *hapd,
1289 struct sta_info *sta)
1290{
1291 return wpa_auth_get_dpp_pkhash(sta->wpa_sm);
1292}
1293
1294
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001295void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
1296 int authorized)
1297{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001298 const u8 *dev_addr = NULL;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001299 char buf[100];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001300#ifdef CONFIG_P2P
1301 u8 addr[ETH_ALEN];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001302 u8 ip_addr_buf[4];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001303#endif /* CONFIG_P2P */
Sunil Ravid8128a22023-11-06 23:53:58 +00001304 u8 *ip_ptr = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001305
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001306 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
1307 return;
1308
Sunil Ravi640215c2023-06-28 23:08:09 +00001309 if (authorized) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001310 int mld_assoc_link_id = -1;
1311
1312#ifdef CONFIG_IEEE80211BE
1313 if (hapd->conf->mld_ap && sta->mld_info.mld_sta) {
1314 if (sta->mld_assoc_link_id == hapd->mld_link_id)
1315 mld_assoc_link_id = sta->mld_assoc_link_id;
1316 else
1317 mld_assoc_link_id = -2;
1318 }
1319#endif /* CONFIG_IEEE80211BE */
1320 if (mld_assoc_link_id != -2)
1321 hostapd_prune_associations(hapd, sta->addr,
1322 mld_assoc_link_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001323 sta->flags |= WLAN_STA_AUTHORIZED;
Sunil Ravi640215c2023-06-28 23:08:09 +00001324 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001325 sta->flags &= ~WLAN_STA_AUTHORIZED;
Sunil Ravi640215c2023-06-28 23:08:09 +00001326 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001327
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001328#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001329 if (hapd->p2p_group == NULL) {
1330 if (sta->p2p_ie != NULL &&
1331 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
1332 dev_addr = addr;
1333 } else
1334 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001335
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001336 if (dev_addr)
1337 os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
1338 MAC2STR(sta->addr), MAC2STR(dev_addr));
1339 else
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001340#endif /* CONFIG_P2P */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001341 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
1342
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001343 if (authorized) {
Sunil Ravi77d572f2023-01-17 23:58:31 +00001344 const u8 *dpp_pkhash;
Hai Shalom74f70d42019-02-11 14:42:39 -08001345 const char *keyid;
Sunil Ravi77d572f2023-01-17 23:58:31 +00001346 char dpp_pkhash_buf[100];
Hai Shalom74f70d42019-02-11 14:42:39 -08001347 char keyid_buf[100];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001348 char ip_addr[100];
Hai Shalom74f70d42019-02-11 14:42:39 -08001349
Sunil Ravi77d572f2023-01-17 23:58:31 +00001350 dpp_pkhash_buf[0] = '\0';
Hai Shalom74f70d42019-02-11 14:42:39 -08001351 keyid_buf[0] = '\0';
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001352 ip_addr[0] = '\0';
1353#ifdef CONFIG_P2P
1354 if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) {
1355 os_snprintf(ip_addr, sizeof(ip_addr),
1356 " ip_addr=%u.%u.%u.%u",
1357 ip_addr_buf[0], ip_addr_buf[1],
1358 ip_addr_buf[2], ip_addr_buf[3]);
Sunil Ravid8128a22023-11-06 23:53:58 +00001359 ip_ptr = ip_addr_buf;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001360 }
1361#endif /* CONFIG_P2P */
1362
Hai Shalom74f70d42019-02-11 14:42:39 -08001363 keyid = ap_sta_wpa_get_keyid(hapd, sta);
1364 if (keyid) {
1365 os_snprintf(keyid_buf, sizeof(keyid_buf),
1366 " keyid=%s", keyid);
1367 }
1368
Sunil Ravi77d572f2023-01-17 23:58:31 +00001369 dpp_pkhash = ap_sta_wpa_get_dpp_pkhash(hapd, sta);
1370 if (dpp_pkhash) {
1371 const char *prefix = " dpp_pkhash=";
1372 size_t plen = os_strlen(prefix);
1373
1374 os_strlcpy(dpp_pkhash_buf, prefix,
1375 sizeof(dpp_pkhash_buf));
1376 wpa_snprintf_hex(&dpp_pkhash_buf[plen],
1377 sizeof(dpp_pkhash_buf) - plen,
1378 dpp_pkhash, SHA256_MAC_LEN);
1379 }
1380
1381 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s%s",
1382 buf, ip_addr, keyid_buf, dpp_pkhash_buf);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001383
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001384 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001385 hapd->msg_ctx_parent != hapd->msg_ctx)
1386 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
Sunil Ravi77d572f2023-01-17 23:58:31 +00001387 AP_STA_CONNECTED "%s%s%s%s",
1388 buf, ip_addr, keyid_buf,
1389 dpp_pkhash_buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001390 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001391 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
1392
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001393 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001394 hapd->msg_ctx_parent != hapd->msg_ctx)
1395 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
1396 AP_STA_DISCONNECTED "%s", buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001397 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001398
Sunil Ravid8128a22023-11-06 23:53:58 +00001399 if (hapd->sta_authorized_cb)
1400 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
1401 sta->addr, authorized, dev_addr,
1402 ip_ptr);
1403
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001404#ifdef CONFIG_FST
1405 if (hapd->iface->fst) {
1406 if (authorized)
1407 fst_notify_peer_connected(hapd->iface->fst, sta->addr);
1408 else
1409 fst_notify_peer_disconnected(hapd->iface->fst,
1410 sta->addr);
1411 }
1412#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001413}
1414
1415
1416void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
1417 const u8 *addr, u16 reason)
1418{
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001419 if (sta)
1420 wpa_printf(MSG_DEBUG, "%s: %s STA " MACSTR " reason=%u",
1421 hapd->conf->iface, __func__, MAC2STR(sta->addr),
1422 reason);
1423 else if (addr)
1424 wpa_printf(MSG_DEBUG, "%s: %s addr " MACSTR " reason=%u",
1425 hapd->conf->iface, __func__, MAC2STR(addr),
1426 reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001427
1428 if (sta == NULL && addr)
1429 sta = ap_get_sta(hapd, addr);
1430
1431 if (addr)
1432 hostapd_drv_sta_deauth(hapd, addr, reason);
1433
1434 if (sta == NULL)
1435 return;
1436 ap_sta_set_authorized(hapd, sta, 0);
Hai Shalomfdcde762020-04-02 11:19:20 -07001437 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1438 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001439 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1440 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001441 wpa_printf(MSG_DEBUG, "%s: %s: reschedule ap_handle_timer timeout "
Dmitry Shmidt04949592012-07-19 12:16:46 -07001442 "for " MACSTR " (%d seconds - "
1443 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001444 hapd->conf->iface, __func__, MAC2STR(sta->addr),
Dmitry Shmidt04949592012-07-19 12:16:46 -07001445 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001446 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001447 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
1448 ap_handle_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001449 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001450
Dmitry Shmidt29333592017-01-09 12:27:11 -08001451 if (hapd->iface->current_mode &&
1452 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
1453 /* Deauthentication is not used in DMG/IEEE 802.11ad;
1454 * disassociate the STA instead. */
1455 sta->disassoc_reason = reason;
1456 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
1457 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1458 eloop_register_timeout(hapd->iface->drv_flags &
1459 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ?
1460 2 : 0, 0, ap_sta_disassoc_cb_timeout,
1461 hapd, sta);
1462 return;
1463 }
1464
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001465 sta->deauth_reason = reason;
1466 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
1467 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1468 eloop_register_timeout(hapd->iface->drv_flags &
1469 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
1470 ap_sta_deauth_cb_timeout, hapd, sta);
1471}
1472
1473
1474void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
1475{
1476 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
1477 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
1478 return;
1479 }
1480 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
1481 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1482 ap_sta_deauth_cb_timeout(hapd, sta);
1483}
1484
1485
1486void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
1487{
1488 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
1489 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
1490 return;
1491 }
1492 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
1493 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1494 ap_sta_disassoc_cb_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001495}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001496
1497
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001498void ap_sta_clear_disconnect_timeouts(struct hostapd_data *hapd,
1499 struct sta_info *sta)
1500{
1501 if (eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta) > 0)
1502 wpa_printf(MSG_DEBUG,
1503 "%s: Removed ap_sta_deauth_cb_timeout timeout for "
1504 MACSTR,
1505 hapd->conf->iface, MAC2STR(sta->addr));
1506 if (eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta) > 0)
1507 wpa_printf(MSG_DEBUG,
1508 "%s: Removed ap_sta_disassoc_cb_timeout timeout for "
1509 MACSTR,
1510 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt29333592017-01-09 12:27:11 -08001511 if (eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta) > 0)
1512 {
1513 wpa_printf(MSG_DEBUG,
1514 "%s: Removed ap_sta_delayed_1x_auth_fail_cb timeout for "
1515 MACSTR,
1516 hapd->conf->iface, MAC2STR(sta->addr));
1517 if (sta->flags & WLAN_STA_WPS)
1518 hostapd_wps_eap_completed(hapd);
1519 }
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001520}
1521
1522
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001523int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen)
1524{
1525 int res;
1526
1527 buf[0] = '\0';
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001528 res = os_snprintf(buf, buflen,
Sunil Ravia04bd252022-05-02 22:54:18 -07001529 "%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 -08001530 (flags & WLAN_STA_AUTH ? "[AUTH]" : ""),
1531 (flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""),
1532 (flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : ""),
1533 (flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
1534 ""),
1535 (flags & WLAN_STA_SHORT_PREAMBLE ?
1536 "[SHORT_PREAMBLE]" : ""),
1537 (flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
1538 (flags & WLAN_STA_WMM ? "[WMM]" : ""),
1539 (flags & WLAN_STA_MFP ? "[MFP]" : ""),
1540 (flags & WLAN_STA_WPS ? "[WPS]" : ""),
1541 (flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""),
1542 (flags & WLAN_STA_WDS ? "[WDS]" : ""),
1543 (flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
1544 (flags & WLAN_STA_WPS2 ? "[WPS2]" : ""),
1545 (flags & WLAN_STA_GAS ? "[GAS]" : ""),
Roshan Pius3a1667e2018-07-03 15:17:14 -07001546 (flags & WLAN_STA_HT ? "[HT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001547 (flags & WLAN_STA_VHT ? "[VHT]" : ""),
Hai Shalomc3565922019-10-28 11:58:20 -07001548 (flags & WLAN_STA_HE ? "[HE]" : ""),
Sunil Ravia04bd252022-05-02 22:54:18 -07001549 (flags & WLAN_STA_EHT ? "[EHT]" : ""),
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001550 (flags & WLAN_STA_6GHZ ? "[6GHZ]" : ""),
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001551 (flags & WLAN_STA_VENDOR_VHT ? "[VENDOR_VHT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001552 (flags & WLAN_STA_WNM_SLEEP_MODE ?
1553 "[WNM_SLEEP_MODE]" : ""));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001554 if (os_snprintf_error(buflen, res))
1555 res = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001556
1557 return res;
1558}
Dmitry Shmidt29333592017-01-09 12:27:11 -08001559
1560
1561static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx)
1562{
1563 struct hostapd_data *hapd = eloop_ctx;
1564 struct sta_info *sta = timeout_ctx;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001565 u16 reason;
Dmitry Shmidt29333592017-01-09 12:27:11 -08001566
1567 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1568 "IEEE 802.1X: Scheduled disconnection of " MACSTR
1569 " after EAP-Failure", MAC2STR(sta->addr));
1570
Roshan Pius3a1667e2018-07-03 15:17:14 -07001571 reason = sta->disconnect_reason_code;
1572 if (!reason)
1573 reason = WLAN_REASON_IEEE_802_1X_AUTH_FAILED;
1574 ap_sta_disconnect(hapd, sta, sta->addr, reason);
Dmitry Shmidt29333592017-01-09 12:27:11 -08001575 if (sta->flags & WLAN_STA_WPS)
1576 hostapd_wps_eap_completed(hapd);
1577}
1578
1579
1580void ap_sta_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
Sunil Ravi640215c2023-06-28 23:08:09 +00001581 struct sta_info *sta,
1582 unsigned timeout)
Dmitry Shmidt29333592017-01-09 12:27:11 -08001583{
1584 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1585 "IEEE 802.1X: Force disconnection of " MACSTR
Sunil Ravi640215c2023-06-28 23:08:09 +00001586 " after EAP-Failure in %u ms", MAC2STR(sta->addr), timeout);
Dmitry Shmidt29333592017-01-09 12:27:11 -08001587
1588 /*
1589 * Add a small sleep to increase likelihood of previously requested
1590 * EAP-Failure TX getting out before this should the driver reorder
1591 * operations.
1592 */
1593 eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta);
Sunil Ravi640215c2023-06-28 23:08:09 +00001594 eloop_register_timeout(0, timeout * 1000,
1595 ap_sta_delayed_1x_auth_fail_cb, hapd, sta);
Dmitry Shmidt29333592017-01-09 12:27:11 -08001596}
1597
1598
1599int ap_sta_pending_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1600 struct sta_info *sta)
1601{
1602 return eloop_is_timeout_registered(ap_sta_delayed_1x_auth_fail_cb,
1603 hapd, sta);
1604}
Hai Shalomb755a2a2020-04-23 21:49:02 -07001605
1606
1607int ap_sta_re_add(struct hostapd_data *hapd, struct sta_info *sta)
1608{
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001609 const u8 *mld_link_addr = NULL;
1610 bool mld_link_sta = false;
1611
Hai Shalomb755a2a2020-04-23 21:49:02 -07001612 /*
1613 * If a station that is already associated to the AP, is trying to
1614 * authenticate again, remove the STA entry, in order to make sure the
1615 * STA PS state gets cleared and configuration gets updated. To handle
1616 * this, station's added_unassoc flag is cleared once the station has
1617 * completed association.
1618 */
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001619
1620#ifdef CONFIG_IEEE80211BE
1621 if (hapd->conf->mld_ap && sta->mld_info.mld_sta) {
1622 u8 mld_link_id = hapd->mld_link_id;
1623
1624 mld_link_sta = sta->mld_assoc_link_id != mld_link_id;
1625 mld_link_addr = sta->mld_info.links[mld_link_id].peer_addr;
1626 }
1627#endif /* CONFIG_IEEE80211BE */
1628
Hai Shalomb755a2a2020-04-23 21:49:02 -07001629 ap_sta_set_authorized(hapd, sta, 0);
1630 hostapd_drv_sta_remove(hapd, sta->addr);
1631 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH | WLAN_STA_AUTHORIZED);
1632
1633 if (hostapd_sta_add(hapd, sta->addr, 0, 0,
1634 sta->supported_rates,
1635 sta->supported_rates_len,
Sunil Ravia04bd252022-05-02 22:54:18 -07001636 0, NULL, NULL, NULL, 0, NULL, 0, NULL,
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001637 sta->flags, 0, 0, 0, 0,
1638 mld_link_addr, mld_link_sta)) {
Hai Shalomb755a2a2020-04-23 21:49:02 -07001639 hostapd_logger(hapd, sta->addr,
1640 HOSTAPD_MODULE_IEEE80211,
1641 HOSTAPD_LEVEL_NOTICE,
1642 "Could not add STA to kernel driver");
1643 return -1;
1644 }
1645
1646 sta->added_unassoc = 1;
1647 return 0;
1648}