1e28a4053SRui Paulo /*
2e28a4053SRui Paulo * hostapd / Station table
385732ac8SCy Schubert * Copyright (c) 2002-2017, Jouni Malinen <j@w1.fi>
4e28a4053SRui Paulo *
5f05cddf9SRui Paulo * This software may be distributed under the terms of the BSD license.
6f05cddf9SRui Paulo * See README for more details.
7e28a4053SRui Paulo */
8e28a4053SRui Paulo
9e28a4053SRui Paulo #include "utils/includes.h"
10e28a4053SRui Paulo
11e28a4053SRui Paulo #include "utils/common.h"
12e28a4053SRui Paulo #include "utils/eloop.h"
13e28a4053SRui Paulo #include "common/ieee802_11_defs.h"
14f05cddf9SRui Paulo #include "common/wpa_ctrl.h"
155b9c547cSRui Paulo #include "common/sae.h"
164bc52338SCy Schubert #include "common/dpp.h"
17e28a4053SRui Paulo #include "radius/radius.h"
18e28a4053SRui Paulo #include "radius/radius_client.h"
19f05cddf9SRui Paulo #include "p2p/p2p.h"
20325151a3SRui Paulo #include "fst/fst.h"
2185732ac8SCy Schubert #include "crypto/crypto.h"
22e28a4053SRui Paulo #include "hostapd.h"
23e28a4053SRui Paulo #include "accounting.h"
24e28a4053SRui Paulo #include "ieee802_1x.h"
25e28a4053SRui Paulo #include "ieee802_11.h"
26f05cddf9SRui Paulo #include "ieee802_11_auth.h"
27e28a4053SRui Paulo #include "wpa_auth.h"
28e28a4053SRui Paulo #include "preauth_auth.h"
29e28a4053SRui Paulo #include "ap_config.h"
30e28a4053SRui Paulo #include "beacon.h"
31e28a4053SRui Paulo #include "ap_mlme.h"
32e28a4053SRui Paulo #include "vlan_init.h"
33f05cddf9SRui Paulo #include "p2p_hostapd.h"
34f05cddf9SRui Paulo #include "ap_drv_ops.h"
35f05cddf9SRui Paulo #include "gas_serv.h"
365b9c547cSRui Paulo #include "wnm_ap.h"
37780fb4a2SCy Schubert #include "mbo_ap.h"
385b9c547cSRui Paulo #include "ndisc_snoop.h"
39e28a4053SRui Paulo #include "sta_info.h"
40780fb4a2SCy Schubert #include "vlan.h"
4185732ac8SCy Schubert #include "wps_hostapd.h"
42e28a4053SRui Paulo
43e28a4053SRui Paulo static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
44e28a4053SRui Paulo struct sta_info *sta);
45e28a4053SRui Paulo static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
465b9c547cSRui Paulo static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx);
47f05cddf9SRui Paulo static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
48f05cddf9SRui Paulo static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
49e28a4053SRui Paulo static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
50f05cddf9SRui Paulo static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
5185732ac8SCy Schubert static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx);
52e28a4053SRui Paulo
ap_for_each_sta(struct hostapd_data * hapd,int (* cb)(struct hostapd_data * hapd,struct sta_info * sta,void * ctx),void * ctx)53e28a4053SRui Paulo int ap_for_each_sta(struct hostapd_data *hapd,
54e28a4053SRui Paulo int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
55e28a4053SRui Paulo void *ctx),
56e28a4053SRui Paulo void *ctx)
57e28a4053SRui Paulo {
58e28a4053SRui Paulo struct sta_info *sta;
59e28a4053SRui Paulo
60e28a4053SRui Paulo for (sta = hapd->sta_list; sta; sta = sta->next) {
61e28a4053SRui Paulo if (cb(hapd, sta, ctx))
62e28a4053SRui Paulo return 1;
63e28a4053SRui Paulo }
64e28a4053SRui Paulo
65e28a4053SRui Paulo return 0;
66e28a4053SRui Paulo }
67e28a4053SRui Paulo
68e28a4053SRui Paulo
ap_get_sta(struct hostapd_data * hapd,const u8 * sta)69e28a4053SRui Paulo struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
70e28a4053SRui Paulo {
71e28a4053SRui Paulo struct sta_info *s;
72e28a4053SRui Paulo
73e28a4053SRui Paulo s = hapd->sta_hash[STA_HASH(sta)];
74e28a4053SRui Paulo while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
75e28a4053SRui Paulo s = s->hnext;
76e28a4053SRui Paulo return s;
77e28a4053SRui Paulo }
78e28a4053SRui Paulo
79e28a4053SRui Paulo
805b9c547cSRui Paulo #ifdef CONFIG_P2P
ap_get_sta_p2p(struct hostapd_data * hapd,const u8 * addr)815b9c547cSRui Paulo struct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr)
825b9c547cSRui Paulo {
835b9c547cSRui Paulo struct sta_info *sta;
845b9c547cSRui Paulo
855b9c547cSRui Paulo for (sta = hapd->sta_list; sta; sta = sta->next) {
865b9c547cSRui Paulo const u8 *p2p_dev_addr;
875b9c547cSRui Paulo
885b9c547cSRui Paulo if (sta->p2p_ie == NULL)
895b9c547cSRui Paulo continue;
905b9c547cSRui Paulo
915b9c547cSRui Paulo p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
925b9c547cSRui Paulo if (p2p_dev_addr == NULL)
935b9c547cSRui Paulo continue;
945b9c547cSRui Paulo
95*a90b9d01SCy Schubert if (ether_addr_equal(p2p_dev_addr, addr))
965b9c547cSRui Paulo return sta;
975b9c547cSRui Paulo }
985b9c547cSRui Paulo
995b9c547cSRui Paulo return NULL;
1005b9c547cSRui Paulo }
1015b9c547cSRui Paulo #endif /* CONFIG_P2P */
1025b9c547cSRui Paulo
1035b9c547cSRui Paulo
ap_sta_list_del(struct hostapd_data * hapd,struct sta_info * sta)104e28a4053SRui Paulo static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
105e28a4053SRui Paulo {
106e28a4053SRui Paulo struct sta_info *tmp;
107e28a4053SRui Paulo
108e28a4053SRui Paulo if (hapd->sta_list == sta) {
109e28a4053SRui Paulo hapd->sta_list = sta->next;
110e28a4053SRui Paulo return;
111e28a4053SRui Paulo }
112e28a4053SRui Paulo
113e28a4053SRui Paulo tmp = hapd->sta_list;
114e28a4053SRui Paulo while (tmp != NULL && tmp->next != sta)
115e28a4053SRui Paulo tmp = tmp->next;
116e28a4053SRui Paulo if (tmp == NULL) {
117e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
118e28a4053SRui Paulo "list.", MAC2STR(sta->addr));
119e28a4053SRui Paulo } else
120e28a4053SRui Paulo tmp->next = sta->next;
121e28a4053SRui Paulo }
122e28a4053SRui Paulo
123e28a4053SRui Paulo
ap_sta_hash_add(struct hostapd_data * hapd,struct sta_info * sta)124e28a4053SRui Paulo void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
125e28a4053SRui Paulo {
126e28a4053SRui Paulo sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
127e28a4053SRui Paulo hapd->sta_hash[STA_HASH(sta->addr)] = sta;
128e28a4053SRui Paulo }
129e28a4053SRui Paulo
130e28a4053SRui Paulo
ap_sta_hash_del(struct hostapd_data * hapd,struct sta_info * sta)131e28a4053SRui Paulo static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
132e28a4053SRui Paulo {
133e28a4053SRui Paulo struct sta_info *s;
134e28a4053SRui Paulo
135e28a4053SRui Paulo s = hapd->sta_hash[STA_HASH(sta->addr)];
136e28a4053SRui Paulo if (s == NULL) return;
137e28a4053SRui Paulo if (os_memcmp(s->addr, sta->addr, 6) == 0) {
138e28a4053SRui Paulo hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
139e28a4053SRui Paulo return;
140e28a4053SRui Paulo }
141e28a4053SRui Paulo
142e28a4053SRui Paulo while (s->hnext != NULL &&
143*a90b9d01SCy Schubert !ether_addr_equal(s->hnext->addr, sta->addr))
144e28a4053SRui Paulo s = s->hnext;
145e28a4053SRui Paulo if (s->hnext != NULL)
146e28a4053SRui Paulo s->hnext = s->hnext->hnext;
147e28a4053SRui Paulo else
148e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
149e28a4053SRui Paulo " from hash table", MAC2STR(sta->addr));
150e28a4053SRui Paulo }
151e28a4053SRui Paulo
152e28a4053SRui Paulo
ap_sta_ip6addr_del(struct hostapd_data * hapd,struct sta_info * sta)1535b9c547cSRui Paulo void ap_sta_ip6addr_del(struct hostapd_data *hapd, struct sta_info *sta)
1545b9c547cSRui Paulo {
1555b9c547cSRui Paulo sta_ip6addr_del(hapd, sta);
1565b9c547cSRui Paulo }
1575b9c547cSRui Paulo
1585b9c547cSRui Paulo
159c1d255d3SCy Schubert #ifdef CONFIG_PASN
160c1d255d3SCy Schubert
ap_free_sta_pasn(struct hostapd_data * hapd,struct sta_info * sta)161c1d255d3SCy Schubert void ap_free_sta_pasn(struct hostapd_data *hapd, struct sta_info *sta)
162c1d255d3SCy Schubert {
163c1d255d3SCy Schubert if (sta->pasn) {
164c1d255d3SCy Schubert wpa_printf(MSG_DEBUG, "PASN: Free PASN context: " MACSTR,
165c1d255d3SCy Schubert MAC2STR(sta->addr));
166c1d255d3SCy Schubert
167c1d255d3SCy Schubert if (sta->pasn->ecdh)
168c1d255d3SCy Schubert crypto_ecdh_deinit(sta->pasn->ecdh);
169c1d255d3SCy Schubert
170c1d255d3SCy Schubert wpabuf_free(sta->pasn->secret);
171c1d255d3SCy Schubert sta->pasn->secret = NULL;
172c1d255d3SCy Schubert
173c1d255d3SCy Schubert #ifdef CONFIG_SAE
174c1d255d3SCy Schubert sae_clear_data(&sta->pasn->sae);
175c1d255d3SCy Schubert #endif /* CONFIG_SAE */
176c1d255d3SCy Schubert
177c1d255d3SCy Schubert #ifdef CONFIG_FILS
178c1d255d3SCy Schubert /* In practice this pointer should be NULL */
179c1d255d3SCy Schubert wpabuf_free(sta->pasn->fils.erp_resp);
180c1d255d3SCy Schubert sta->pasn->fils.erp_resp = NULL;
181c1d255d3SCy Schubert #endif /* CONFIG_FILS */
182c1d255d3SCy Schubert
183*a90b9d01SCy Schubert pasn_data_deinit(sta->pasn);
184c1d255d3SCy Schubert sta->pasn = NULL;
185c1d255d3SCy Schubert }
186c1d255d3SCy Schubert }
187c1d255d3SCy Schubert
188c1d255d3SCy Schubert #endif /* CONFIG_PASN */
189c1d255d3SCy Schubert
190*a90b9d01SCy Schubert
__ap_free_sta(struct hostapd_data * hapd,struct sta_info * sta)191*a90b9d01SCy Schubert static void __ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
192*a90b9d01SCy Schubert {
193*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
194*a90b9d01SCy Schubert if (hostapd_sta_is_link_sta(hapd, sta) &&
195*a90b9d01SCy Schubert !hostapd_drv_link_sta_remove(hapd, sta->addr))
196*a90b9d01SCy Schubert return;
197*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
198*a90b9d01SCy Schubert
199*a90b9d01SCy Schubert hostapd_drv_sta_remove(hapd, sta->addr);
200*a90b9d01SCy Schubert }
201*a90b9d01SCy Schubert
202*a90b9d01SCy Schubert
203*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
clear_wpa_sm_for_each_partner_link(struct hostapd_data * hapd,struct sta_info * psta)204*a90b9d01SCy Schubert static void clear_wpa_sm_for_each_partner_link(struct hostapd_data *hapd,
205*a90b9d01SCy Schubert struct sta_info *psta)
206*a90b9d01SCy Schubert {
207*a90b9d01SCy Schubert struct sta_info *lsta;
208*a90b9d01SCy Schubert struct hostapd_data *lhapd;
209*a90b9d01SCy Schubert
210*a90b9d01SCy Schubert if (!ap_sta_is_mld(hapd, psta))
211*a90b9d01SCy Schubert return;
212*a90b9d01SCy Schubert
213*a90b9d01SCy Schubert for_each_mld_link(lhapd, hapd) {
214*a90b9d01SCy Schubert if (lhapd == hapd)
215*a90b9d01SCy Schubert continue;
216*a90b9d01SCy Schubert
217*a90b9d01SCy Schubert lsta = ap_get_sta(lhapd, psta->addr);
218*a90b9d01SCy Schubert if (lsta)
219*a90b9d01SCy Schubert lsta->wpa_sm = NULL;
220*a90b9d01SCy Schubert }
221*a90b9d01SCy Schubert }
222*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
223*a90b9d01SCy Schubert
224*a90b9d01SCy Schubert
ap_free_sta(struct hostapd_data * hapd,struct sta_info * sta)225e28a4053SRui Paulo void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
226e28a4053SRui Paulo {
227e28a4053SRui Paulo int set_beacon = 0;
228e28a4053SRui Paulo
229e28a4053SRui Paulo accounting_sta_stop(hapd, sta);
230e28a4053SRui Paulo
231f05cddf9SRui Paulo /* just in case */
232f05cddf9SRui Paulo ap_sta_set_authorized(hapd, sta, 0);
233c1d255d3SCy Schubert hostapd_set_sta_flags(hapd, sta);
234f05cddf9SRui Paulo
235*a90b9d01SCy Schubert if ((sta->flags & WLAN_STA_WDS) ||
236*a90b9d01SCy Schubert (sta->flags & WLAN_STA_MULTI_AP &&
237*a90b9d01SCy Schubert (hapd->conf->multi_ap & BACKHAUL_BSS) &&
238*a90b9d01SCy Schubert hapd->conf->wds_sta &&
239*a90b9d01SCy Schubert !(sta->flags & WLAN_STA_WPS)))
2405b9c547cSRui Paulo hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0);
241e28a4053SRui Paulo
2425b9c547cSRui Paulo if (sta->ipaddr)
2435b9c547cSRui Paulo hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
2445b9c547cSRui Paulo ap_sta_ip6addr_del(hapd, sta);
2455b9c547cSRui Paulo
2465b9c547cSRui Paulo if (!hapd->iface->driver_ap_teardown &&
247780fb4a2SCy Schubert !(sta->flags & WLAN_STA_PREAUTH)) {
248*a90b9d01SCy Schubert __ap_free_sta(hapd, sta);
249780fb4a2SCy Schubert sta->added_unassoc = 0;
250325151a3SRui Paulo }
251325151a3SRui Paulo
252e28a4053SRui Paulo ap_sta_hash_del(hapd, sta);
253e28a4053SRui Paulo ap_sta_list_del(hapd, sta);
254e28a4053SRui Paulo
255e28a4053SRui Paulo if (sta->aid > 0)
256e28a4053SRui Paulo hapd->sta_aid[(sta->aid - 1) / 32] &=
257e28a4053SRui Paulo ~BIT((sta->aid - 1) % 32);
258e28a4053SRui Paulo
259e28a4053SRui Paulo hapd->num_sta--;
260e28a4053SRui Paulo if (sta->nonerp_set) {
261e28a4053SRui Paulo sta->nonerp_set = 0;
262e28a4053SRui Paulo hapd->iface->num_sta_non_erp--;
263e28a4053SRui Paulo if (hapd->iface->num_sta_non_erp == 0)
264e28a4053SRui Paulo set_beacon++;
265e28a4053SRui Paulo }
266e28a4053SRui Paulo
267e28a4053SRui Paulo if (sta->no_short_slot_time_set) {
268e28a4053SRui Paulo sta->no_short_slot_time_set = 0;
269e28a4053SRui Paulo hapd->iface->num_sta_no_short_slot_time--;
27085732ac8SCy Schubert if (hapd->iface->current_mode &&
27185732ac8SCy Schubert hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
272e28a4053SRui Paulo && hapd->iface->num_sta_no_short_slot_time == 0)
273e28a4053SRui Paulo set_beacon++;
274e28a4053SRui Paulo }
275e28a4053SRui Paulo
276e28a4053SRui Paulo if (sta->no_short_preamble_set) {
277e28a4053SRui Paulo sta->no_short_preamble_set = 0;
278e28a4053SRui Paulo hapd->iface->num_sta_no_short_preamble--;
27985732ac8SCy Schubert if (hapd->iface->current_mode &&
28085732ac8SCy Schubert hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
281e28a4053SRui Paulo && hapd->iface->num_sta_no_short_preamble == 0)
282e28a4053SRui Paulo set_beacon++;
283e28a4053SRui Paulo }
284e28a4053SRui Paulo
285e28a4053SRui Paulo if (sta->no_ht_gf_set) {
286e28a4053SRui Paulo sta->no_ht_gf_set = 0;
287e28a4053SRui Paulo hapd->iface->num_sta_ht_no_gf--;
288e28a4053SRui Paulo }
289e28a4053SRui Paulo
290e28a4053SRui Paulo if (sta->no_ht_set) {
291e28a4053SRui Paulo sta->no_ht_set = 0;
292e28a4053SRui Paulo hapd->iface->num_sta_no_ht--;
293e28a4053SRui Paulo }
294e28a4053SRui Paulo
295e28a4053SRui Paulo if (sta->ht_20mhz_set) {
296e28a4053SRui Paulo sta->ht_20mhz_set = 0;
297e28a4053SRui Paulo hapd->iface->num_sta_ht_20mhz--;
298e28a4053SRui Paulo }
299e28a4053SRui Paulo
300780fb4a2SCy Schubert #ifdef CONFIG_TAXONOMY
301780fb4a2SCy Schubert wpabuf_free(sta->probe_ie_taxonomy);
302780fb4a2SCy Schubert sta->probe_ie_taxonomy = NULL;
303780fb4a2SCy Schubert wpabuf_free(sta->assoc_ie_taxonomy);
304780fb4a2SCy Schubert sta->assoc_ie_taxonomy = NULL;
305780fb4a2SCy Schubert #endif /* CONFIG_TAXONOMY */
306780fb4a2SCy Schubert
3075b9c547cSRui Paulo ht40_intolerant_remove(hapd->iface, sta);
3085b9c547cSRui Paulo
309f05cddf9SRui Paulo #ifdef CONFIG_P2P
310f05cddf9SRui Paulo if (sta->no_p2p_set) {
311f05cddf9SRui Paulo sta->no_p2p_set = 0;
312f05cddf9SRui Paulo hapd->num_sta_no_p2p--;
313f05cddf9SRui Paulo if (hapd->num_sta_no_p2p == 0)
314f05cddf9SRui Paulo hostapd_p2p_non_p2p_sta_disconnected(hapd);
315f05cddf9SRui Paulo }
316f05cddf9SRui Paulo #endif /* CONFIG_P2P */
317f05cddf9SRui Paulo
318c1d255d3SCy Schubert #ifdef NEED_AP_MLME
319e28a4053SRui Paulo if (hostapd_ht_operation_update(hapd->iface) > 0)
320e28a4053SRui Paulo set_beacon++;
321c1d255d3SCy Schubert #endif /* NEED_AP_MLME */
322e28a4053SRui Paulo
3235b9c547cSRui Paulo #ifdef CONFIG_MESH
3245b9c547cSRui Paulo if (hapd->mesh_sta_free_cb)
325780fb4a2SCy Schubert hapd->mesh_sta_free_cb(hapd, sta);
3265b9c547cSRui Paulo #endif /* CONFIG_MESH */
3275b9c547cSRui Paulo
328e28a4053SRui Paulo if (set_beacon)
329*a90b9d01SCy Schubert ieee802_11_update_beacons(hapd->iface);
330e28a4053SRui Paulo
331f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
332f05cddf9SRui Paulo __func__, MAC2STR(sta->addr));
333e28a4053SRui Paulo eloop_cancel_timeout(ap_handle_timer, hapd, sta);
334e28a4053SRui Paulo eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
3355b9c547cSRui Paulo eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
336780fb4a2SCy Schubert ap_sta_clear_disconnect_timeouts(hapd, sta);
3375b9c547cSRui Paulo sae_clear_retransmit_timer(hapd, sta);
338e28a4053SRui Paulo
339780fb4a2SCy Schubert ieee802_1x_free_station(hapd, sta);
340*a90b9d01SCy Schubert
341*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
342*a90b9d01SCy Schubert if (!ap_sta_is_mld(hapd, sta) ||
343*a90b9d01SCy Schubert hapd->mld_link_id == sta->mld_assoc_link_id) {
344e28a4053SRui Paulo wpa_auth_sta_deinit(sta->wpa_sm);
345*a90b9d01SCy Schubert /* Remove references from partner links. */
346*a90b9d01SCy Schubert clear_wpa_sm_for_each_partner_link(hapd, sta);
347*a90b9d01SCy Schubert }
348*a90b9d01SCy Schubert
349*a90b9d01SCy Schubert /* Release group references in case non-association link STA is removed
350*a90b9d01SCy Schubert * before association link STA */
351*a90b9d01SCy Schubert if (hostapd_sta_is_link_sta(hapd, sta))
352*a90b9d01SCy Schubert wpa_release_link_auth_ref(sta->wpa_sm, hapd->mld_link_id);
353*a90b9d01SCy Schubert #else /* CONFIG_IEEE80211BE */
354*a90b9d01SCy Schubert wpa_auth_sta_deinit(sta->wpa_sm);
355*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
356*a90b9d01SCy Schubert
357e28a4053SRui Paulo rsn_preauth_free_station(hapd, sta);
358e28a4053SRui Paulo #ifndef CONFIG_NO_RADIUS
3595b9c547cSRui Paulo if (hapd->radius)
360e28a4053SRui Paulo radius_client_flush_auth(hapd->radius, sta->addr);
361e28a4053SRui Paulo #endif /* CONFIG_NO_RADIUS */
362e28a4053SRui Paulo
363780fb4a2SCy Schubert #ifndef CONFIG_NO_VLAN
364780fb4a2SCy Schubert /*
365780fb4a2SCy Schubert * sta->wpa_sm->group needs to be released before so that
366780fb4a2SCy Schubert * vlan_remove_dynamic() can check that no stations are left on the
367780fb4a2SCy Schubert * AP_VLAN netdev.
368780fb4a2SCy Schubert */
369780fb4a2SCy Schubert if (sta->vlan_id)
370780fb4a2SCy Schubert vlan_remove_dynamic(hapd, sta->vlan_id);
371780fb4a2SCy Schubert if (sta->vlan_id_bound) {
372780fb4a2SCy Schubert /*
373780fb4a2SCy Schubert * Need to remove the STA entry before potentially removing the
374780fb4a2SCy Schubert * VLAN.
375780fb4a2SCy Schubert */
376780fb4a2SCy Schubert if (hapd->iface->driver_ap_teardown &&
377780fb4a2SCy Schubert !(sta->flags & WLAN_STA_PREAUTH)) {
378780fb4a2SCy Schubert hostapd_drv_sta_remove(hapd, sta->addr);
379780fb4a2SCy Schubert sta->added_unassoc = 0;
380780fb4a2SCy Schubert }
381780fb4a2SCy Schubert vlan_remove_dynamic(hapd, sta->vlan_id_bound);
382780fb4a2SCy Schubert }
383780fb4a2SCy Schubert #endif /* CONFIG_NO_VLAN */
384780fb4a2SCy Schubert
385e28a4053SRui Paulo os_free(sta->challenge);
386e28a4053SRui Paulo
387e28a4053SRui Paulo os_free(sta->sa_query_trans_id);
388e28a4053SRui Paulo eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
389e28a4053SRui Paulo
390f05cddf9SRui Paulo #ifdef CONFIG_P2P
391f05cddf9SRui Paulo p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
392f05cddf9SRui Paulo #endif /* CONFIG_P2P */
393f05cddf9SRui Paulo
394f05cddf9SRui Paulo #ifdef CONFIG_INTERWORKING
395f05cddf9SRui Paulo if (sta->gas_dialog) {
396f05cddf9SRui Paulo int i;
397*a90b9d01SCy Schubert
398f05cddf9SRui Paulo for (i = 0; i < GAS_DIALOG_MAX; i++)
399f05cddf9SRui Paulo gas_serv_dialog_clear(&sta->gas_dialog[i]);
400f05cddf9SRui Paulo os_free(sta->gas_dialog);
401f05cddf9SRui Paulo }
402f05cddf9SRui Paulo #endif /* CONFIG_INTERWORKING */
403f05cddf9SRui Paulo
404e28a4053SRui Paulo wpabuf_free(sta->wps_ie);
405f05cddf9SRui Paulo wpabuf_free(sta->p2p_ie);
406f05cddf9SRui Paulo wpabuf_free(sta->hs20_ie);
40785732ac8SCy Schubert wpabuf_free(sta->roaming_consortium);
408325151a3SRui Paulo #ifdef CONFIG_FST
409325151a3SRui Paulo wpabuf_free(sta->mb_ies);
410325151a3SRui Paulo #endif /* CONFIG_FST */
411e28a4053SRui Paulo
412e28a4053SRui Paulo os_free(sta->ht_capabilities);
4135b9c547cSRui Paulo os_free(sta->vht_capabilities);
4144bc52338SCy Schubert os_free(sta->vht_operation);
415206b73d0SCy Schubert os_free(sta->he_capab);
416c1d255d3SCy Schubert os_free(sta->he_6ghz_capab);
417*a90b9d01SCy Schubert os_free(sta->eht_capab);
418f05cddf9SRui Paulo hostapd_free_psk_list(sta->psk);
419f05cddf9SRui Paulo os_free(sta->identity);
420f05cddf9SRui Paulo os_free(sta->radius_cui);
4215b9c547cSRui Paulo os_free(sta->remediation_url);
42285732ac8SCy Schubert os_free(sta->t_c_url);
4235b9c547cSRui Paulo wpabuf_free(sta->hs20_deauth_req);
4245b9c547cSRui Paulo os_free(sta->hs20_session_info_url);
4255b9c547cSRui Paulo
4265b9c547cSRui Paulo #ifdef CONFIG_SAE
4275b9c547cSRui Paulo sae_clear_data(sta->sae);
4285b9c547cSRui Paulo os_free(sta->sae);
4295b9c547cSRui Paulo #endif /* CONFIG_SAE */
430e28a4053SRui Paulo
431780fb4a2SCy Schubert mbo_ap_sta_free(sta);
432780fb4a2SCy Schubert os_free(sta->supp_op_classes);
433780fb4a2SCy Schubert
43485732ac8SCy Schubert #ifdef CONFIG_FILS
43585732ac8SCy Schubert os_free(sta->fils_pending_assoc_req);
43685732ac8SCy Schubert wpabuf_free(sta->fils_hlp_resp);
43785732ac8SCy Schubert wpabuf_free(sta->hlp_dhcp_discover);
43885732ac8SCy Schubert eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
43985732ac8SCy Schubert #ifdef CONFIG_FILS_SK_PFS
44085732ac8SCy Schubert crypto_ecdh_deinit(sta->fils_ecdh);
44185732ac8SCy Schubert wpabuf_clear_free(sta->fils_dh_ss);
44285732ac8SCy Schubert wpabuf_free(sta->fils_g_sta);
44385732ac8SCy Schubert #endif /* CONFIG_FILS_SK_PFS */
44485732ac8SCy Schubert #endif /* CONFIG_FILS */
44585732ac8SCy Schubert
44685732ac8SCy Schubert #ifdef CONFIG_OWE
44785732ac8SCy Schubert bin_clear_free(sta->owe_pmk, sta->owe_pmk_len);
44885732ac8SCy Schubert crypto_ecdh_deinit(sta->owe_ecdh);
44985732ac8SCy Schubert #endif /* CONFIG_OWE */
45085732ac8SCy Schubert
4514bc52338SCy Schubert #ifdef CONFIG_DPP2
4524bc52338SCy Schubert dpp_pfs_free(sta->dpp_pfs);
4534bc52338SCy Schubert sta->dpp_pfs = NULL;
4544bc52338SCy Schubert #endif /* CONFIG_DPP2 */
4554bc52338SCy Schubert
45685732ac8SCy Schubert os_free(sta->ext_capability);
45785732ac8SCy Schubert
45885732ac8SCy Schubert #ifdef CONFIG_WNM_AP
45985732ac8SCy Schubert eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta);
46085732ac8SCy Schubert #endif /* CONFIG_WNM_AP */
46185732ac8SCy Schubert
462c1d255d3SCy Schubert #ifdef CONFIG_PASN
463c1d255d3SCy Schubert ap_free_sta_pasn(hapd, sta);
464c1d255d3SCy Schubert #endif /* CONFIG_PASN */
465c1d255d3SCy Schubert
46685732ac8SCy Schubert os_free(sta->ifname_wds);
46785732ac8SCy Schubert
468*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
469*a90b9d01SCy Schubert ap_sta_free_sta_profile(&sta->mld_info);
470*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
471*a90b9d01SCy Schubert
472c1d255d3SCy Schubert #ifdef CONFIG_TESTING_OPTIONS
473c1d255d3SCy Schubert os_free(sta->sae_postponed_commit);
474*a90b9d01SCy Schubert forced_memzero(sta->last_tk, WPA_TK_MAX_LEN);
475c1d255d3SCy Schubert #endif /* CONFIG_TESTING_OPTIONS */
476c1d255d3SCy Schubert
477e28a4053SRui Paulo os_free(sta);
478e28a4053SRui Paulo }
479e28a4053SRui Paulo
480e28a4053SRui Paulo
hostapd_free_stas(struct hostapd_data * hapd)481e28a4053SRui Paulo void hostapd_free_stas(struct hostapd_data *hapd)
482e28a4053SRui Paulo {
483e28a4053SRui Paulo struct sta_info *sta, *prev;
484e28a4053SRui Paulo
485e28a4053SRui Paulo sta = hapd->sta_list;
486e28a4053SRui Paulo
487e28a4053SRui Paulo while (sta) {
488e28a4053SRui Paulo prev = sta;
489e28a4053SRui Paulo if (sta->flags & WLAN_STA_AUTH) {
490e28a4053SRui Paulo mlme_deauthenticate_indication(
491e28a4053SRui Paulo hapd, sta, WLAN_REASON_UNSPECIFIED);
492e28a4053SRui Paulo }
493e28a4053SRui Paulo sta = sta->next;
494e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
495e28a4053SRui Paulo MAC2STR(prev->addr));
496e28a4053SRui Paulo ap_free_sta(hapd, prev);
497e28a4053SRui Paulo }
498e28a4053SRui Paulo }
499e28a4053SRui Paulo
500e28a4053SRui Paulo
501*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
hostapd_free_link_stas(struct hostapd_data * hapd)502*a90b9d01SCy Schubert void hostapd_free_link_stas(struct hostapd_data *hapd)
503*a90b9d01SCy Schubert {
504*a90b9d01SCy Schubert struct sta_info *sta, *prev;
505*a90b9d01SCy Schubert
506*a90b9d01SCy Schubert sta = hapd->sta_list;
507*a90b9d01SCy Schubert while (sta) {
508*a90b9d01SCy Schubert prev = sta;
509*a90b9d01SCy Schubert sta = sta->next;
510*a90b9d01SCy Schubert
511*a90b9d01SCy Schubert if (!hostapd_sta_is_link_sta(hapd, prev))
512*a90b9d01SCy Schubert continue;
513*a90b9d01SCy Schubert
514*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG, "Removing link station from MLD " MACSTR,
515*a90b9d01SCy Schubert MAC2STR(prev->addr));
516*a90b9d01SCy Schubert ap_free_sta(hapd, prev);
517*a90b9d01SCy Schubert }
518*a90b9d01SCy Schubert }
519*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
520*a90b9d01SCy Schubert
521*a90b9d01SCy Schubert
522e28a4053SRui Paulo /**
523e28a4053SRui Paulo * ap_handle_timer - Per STA timer handler
524e28a4053SRui Paulo * @eloop_ctx: struct hostapd_data *
525e28a4053SRui Paulo * @timeout_ctx: struct sta_info *
526e28a4053SRui Paulo *
527e28a4053SRui Paulo * This function is called to check station activity and to remove inactive
528e28a4053SRui Paulo * stations.
529e28a4053SRui Paulo */
ap_handle_timer(void * eloop_ctx,void * timeout_ctx)530e28a4053SRui Paulo void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
531e28a4053SRui Paulo {
532e28a4053SRui Paulo struct hostapd_data *hapd = eloop_ctx;
533e28a4053SRui Paulo struct sta_info *sta = timeout_ctx;
534e28a4053SRui Paulo unsigned long next_time = 0;
5355b9c547cSRui Paulo int reason;
536*a90b9d01SCy Schubert int max_inactivity = hapd->conf->ap_max_inactivity;
537e28a4053SRui Paulo
538780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, "%s: %s: " MACSTR " flags=0x%x timeout_next=%d",
539780fb4a2SCy Schubert hapd->conf->iface, __func__, MAC2STR(sta->addr), sta->flags,
540f05cddf9SRui Paulo sta->timeout_next);
541e28a4053SRui Paulo if (sta->timeout_next == STA_REMOVE) {
542e28a4053SRui Paulo hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
543e28a4053SRui Paulo HOSTAPD_LEVEL_INFO, "deauthenticated due to "
544e28a4053SRui Paulo "local deauth request");
545e28a4053SRui Paulo ap_free_sta(hapd, sta);
546e28a4053SRui Paulo return;
547e28a4053SRui Paulo }
548e28a4053SRui Paulo
549*a90b9d01SCy Schubert if (sta->max_idle_period)
550*a90b9d01SCy Schubert max_inactivity = (sta->max_idle_period * 1024 + 999) / 1000;
551*a90b9d01SCy Schubert
552e28a4053SRui Paulo if ((sta->flags & WLAN_STA_ASSOC) &&
553e28a4053SRui Paulo (sta->timeout_next == STA_NULLFUNC ||
554e28a4053SRui Paulo sta->timeout_next == STA_DISASSOC)) {
555e28a4053SRui Paulo int inactive_sec;
556f05cddf9SRui Paulo /*
557f05cddf9SRui Paulo * Add random value to timeout so that we don't end up bouncing
558f05cddf9SRui Paulo * all stations at the same time if we have lots of associated
559f05cddf9SRui Paulo * stations that are idle (but keep re-associating).
560f05cddf9SRui Paulo */
561f05cddf9SRui Paulo int fuzz = os_random() % 20;
562f05cddf9SRui Paulo inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
563e28a4053SRui Paulo if (inactive_sec == -1) {
564f05cddf9SRui Paulo wpa_msg(hapd->msg_ctx, MSG_DEBUG,
565f05cddf9SRui Paulo "Check inactivity: Could not "
566f05cddf9SRui Paulo "get station info from kernel driver for "
567f05cddf9SRui Paulo MACSTR, MAC2STR(sta->addr));
568f05cddf9SRui Paulo /*
569f05cddf9SRui Paulo * The driver may not support this functionality.
570f05cddf9SRui Paulo * Anyway, try again after the next inactivity timeout,
571f05cddf9SRui Paulo * but do not disconnect the station now.
572f05cddf9SRui Paulo */
573*a90b9d01SCy Schubert next_time = max_inactivity + fuzz;
5745b9c547cSRui Paulo } else if (inactive_sec == -ENOENT) {
5755b9c547cSRui Paulo wpa_msg(hapd->msg_ctx, MSG_DEBUG,
5765b9c547cSRui Paulo "Station " MACSTR " has lost its driver entry",
5775b9c547cSRui Paulo MAC2STR(sta->addr));
5785b9c547cSRui Paulo
5795b9c547cSRui Paulo /* Avoid sending client probe on removed client */
5805b9c547cSRui Paulo sta->timeout_next = STA_DISASSOC;
5815b9c547cSRui Paulo goto skip_poll;
582*a90b9d01SCy Schubert } else if (inactive_sec < max_inactivity) {
583e28a4053SRui Paulo /* station activity detected; reset timeout state */
584f05cddf9SRui Paulo wpa_msg(hapd->msg_ctx, MSG_DEBUG,
585f05cddf9SRui Paulo "Station " MACSTR " has been active %is ago",
586f05cddf9SRui Paulo MAC2STR(sta->addr), inactive_sec);
587e28a4053SRui Paulo sta->timeout_next = STA_NULLFUNC;
588*a90b9d01SCy Schubert next_time = max_inactivity + fuzz - inactive_sec;
589f05cddf9SRui Paulo } else {
590f05cddf9SRui Paulo wpa_msg(hapd->msg_ctx, MSG_DEBUG,
591f05cddf9SRui Paulo "Station " MACSTR " has been "
592f05cddf9SRui Paulo "inactive too long: %d sec, max allowed: %d",
593f05cddf9SRui Paulo MAC2STR(sta->addr), inactive_sec,
594*a90b9d01SCy Schubert max_inactivity);
595f05cddf9SRui Paulo
596f05cddf9SRui Paulo if (hapd->conf->skip_inactivity_poll)
597f05cddf9SRui Paulo sta->timeout_next = STA_DISASSOC;
598e28a4053SRui Paulo }
599e28a4053SRui Paulo }
600e28a4053SRui Paulo
601e28a4053SRui Paulo if ((sta->flags & WLAN_STA_ASSOC) &&
602e28a4053SRui Paulo sta->timeout_next == STA_DISASSOC &&
603f05cddf9SRui Paulo !(sta->flags & WLAN_STA_PENDING_POLL) &&
604f05cddf9SRui Paulo !hapd->conf->skip_inactivity_poll) {
605f05cddf9SRui Paulo wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
606f05cddf9SRui Paulo " has ACKed data poll", MAC2STR(sta->addr));
607e28a4053SRui Paulo /* data nullfunc frame poll did not produce TX errors; assume
608e28a4053SRui Paulo * station ACKed it */
609e28a4053SRui Paulo sta->timeout_next = STA_NULLFUNC;
610*a90b9d01SCy Schubert next_time = max_inactivity;
611e28a4053SRui Paulo }
612e28a4053SRui Paulo
6135b9c547cSRui Paulo skip_poll:
614e28a4053SRui Paulo if (next_time) {
615f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
616f05cddf9SRui Paulo "for " MACSTR " (%lu seconds)",
617f05cddf9SRui Paulo __func__, MAC2STR(sta->addr), next_time);
618e28a4053SRui Paulo eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
619e28a4053SRui Paulo sta);
620e28a4053SRui Paulo return;
621e28a4053SRui Paulo }
622e28a4053SRui Paulo
623e28a4053SRui Paulo if (sta->timeout_next == STA_NULLFUNC &&
624e28a4053SRui Paulo (sta->flags & WLAN_STA_ASSOC)) {
625f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, " Polling STA");
626e28a4053SRui Paulo sta->flags |= WLAN_STA_PENDING_POLL;
627f05cddf9SRui Paulo hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
628f05cddf9SRui Paulo sta->flags & WLAN_STA_WMM);
629e28a4053SRui Paulo } else if (sta->timeout_next != STA_REMOVE) {
630e28a4053SRui Paulo int deauth = sta->timeout_next == STA_DEAUTH;
631e28a4053SRui Paulo
6324bc52338SCy Schubert if (!deauth && !(sta->flags & WLAN_STA_ASSOC)) {
6334bc52338SCy Schubert /* Cannot disassociate not-associated STA, so move
6344bc52338SCy Schubert * directly to deauthentication. */
6354bc52338SCy Schubert sta->timeout_next = STA_DEAUTH;
6364bc52338SCy Schubert deauth = 1;
6374bc52338SCy Schubert }
6384bc52338SCy Schubert
639f05cddf9SRui Paulo wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
640f05cddf9SRui Paulo "Timeout, sending %s info to STA " MACSTR,
641e28a4053SRui Paulo deauth ? "deauthentication" : "disassociation",
642e28a4053SRui Paulo MAC2STR(sta->addr));
643e28a4053SRui Paulo
644e28a4053SRui Paulo if (deauth) {
645f05cddf9SRui Paulo hostapd_drv_sta_deauth(
646f05cddf9SRui Paulo hapd, sta->addr,
647e28a4053SRui Paulo WLAN_REASON_PREV_AUTH_NOT_VALID);
648e28a4053SRui Paulo } else {
6495b9c547cSRui Paulo reason = (sta->timeout_next == STA_DISASSOC) ?
6505b9c547cSRui Paulo WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
6515b9c547cSRui Paulo WLAN_REASON_PREV_AUTH_NOT_VALID;
6525b9c547cSRui Paulo
6535b9c547cSRui Paulo hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
654e28a4053SRui Paulo }
655e28a4053SRui Paulo }
656e28a4053SRui Paulo
657e28a4053SRui Paulo switch (sta->timeout_next) {
658e28a4053SRui Paulo case STA_NULLFUNC:
659e28a4053SRui Paulo sta->timeout_next = STA_DISASSOC;
660f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
661f05cddf9SRui Paulo "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
662f05cddf9SRui Paulo __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
663e28a4053SRui Paulo eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
664e28a4053SRui Paulo hapd, sta);
665e28a4053SRui Paulo break;
666e28a4053SRui Paulo case STA_DISASSOC:
6675b9c547cSRui Paulo case STA_DISASSOC_FROM_CLI:
668f05cddf9SRui Paulo ap_sta_set_authorized(hapd, sta, 0);
669e28a4053SRui Paulo sta->flags &= ~WLAN_STA_ASSOC;
670c1d255d3SCy Schubert hostapd_set_sta_flags(hapd, sta);
671e28a4053SRui Paulo ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
672e28a4053SRui Paulo if (!sta->acct_terminate_cause)
673e28a4053SRui Paulo sta->acct_terminate_cause =
674e28a4053SRui Paulo RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
675e28a4053SRui Paulo accounting_sta_stop(hapd, sta);
676780fb4a2SCy Schubert ieee802_1x_free_station(hapd, sta);
677e28a4053SRui Paulo hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
678e28a4053SRui Paulo HOSTAPD_LEVEL_INFO, "disassociated due to "
679e28a4053SRui Paulo "inactivity");
6805b9c547cSRui Paulo reason = (sta->timeout_next == STA_DISASSOC) ?
6815b9c547cSRui Paulo WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
6825b9c547cSRui Paulo WLAN_REASON_PREV_AUTH_NOT_VALID;
683e28a4053SRui Paulo sta->timeout_next = STA_DEAUTH;
684f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
685f05cddf9SRui Paulo "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
686f05cddf9SRui Paulo __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
687e28a4053SRui Paulo eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
688e28a4053SRui Paulo hapd, sta);
6895b9c547cSRui Paulo mlme_disassociate_indication(hapd, sta, reason);
690e28a4053SRui Paulo break;
691e28a4053SRui Paulo case STA_DEAUTH:
692e28a4053SRui Paulo case STA_REMOVE:
693e28a4053SRui Paulo hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
694e28a4053SRui Paulo HOSTAPD_LEVEL_INFO, "deauthenticated due to "
695f05cddf9SRui Paulo "inactivity (timer DEAUTH/REMOVE)");
696e28a4053SRui Paulo if (!sta->acct_terminate_cause)
697e28a4053SRui Paulo sta->acct_terminate_cause =
698e28a4053SRui Paulo RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
699e28a4053SRui Paulo mlme_deauthenticate_indication(
700e28a4053SRui Paulo hapd, sta,
701e28a4053SRui Paulo WLAN_REASON_PREV_AUTH_NOT_VALID);
702e28a4053SRui Paulo ap_free_sta(hapd, sta);
703e28a4053SRui Paulo break;
704e28a4053SRui Paulo }
705e28a4053SRui Paulo }
706e28a4053SRui Paulo
707e28a4053SRui Paulo
ap_handle_session_timer(void * eloop_ctx,void * timeout_ctx)708e28a4053SRui Paulo static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
709e28a4053SRui Paulo {
710e28a4053SRui Paulo struct hostapd_data *hapd = eloop_ctx;
711e28a4053SRui Paulo struct sta_info *sta = timeout_ctx;
712e28a4053SRui Paulo
713780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, "%s: Session timer for STA " MACSTR,
714780fb4a2SCy Schubert hapd->conf->iface, MAC2STR(sta->addr));
715c1d255d3SCy Schubert if (!(sta->flags & (WLAN_STA_AUTH | WLAN_STA_ASSOC |
716c1d255d3SCy Schubert WLAN_STA_AUTHORIZED))) {
717f05cddf9SRui Paulo if (sta->flags & WLAN_STA_GAS) {
718f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
719f05cddf9SRui Paulo "entry " MACSTR, MAC2STR(sta->addr));
720f05cddf9SRui Paulo ap_free_sta(hapd, sta);
721f05cddf9SRui Paulo }
722e28a4053SRui Paulo return;
723f05cddf9SRui Paulo }
724e28a4053SRui Paulo
7255b9c547cSRui Paulo hostapd_drv_sta_deauth(hapd, sta->addr,
7265b9c547cSRui Paulo WLAN_REASON_PREV_AUTH_NOT_VALID);
727e28a4053SRui Paulo mlme_deauthenticate_indication(hapd, sta,
728e28a4053SRui Paulo WLAN_REASON_PREV_AUTH_NOT_VALID);
729e28a4053SRui Paulo hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
730e28a4053SRui Paulo HOSTAPD_LEVEL_INFO, "deauthenticated due to "
731e28a4053SRui Paulo "session timeout");
732e28a4053SRui Paulo sta->acct_terminate_cause =
733e28a4053SRui Paulo RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
734e28a4053SRui Paulo ap_free_sta(hapd, sta);
7355b9c547cSRui Paulo }
7365b9c547cSRui Paulo
7375b9c547cSRui Paulo
ap_sta_replenish_timeout(struct hostapd_data * hapd,struct sta_info * sta,u32 session_timeout)7385b9c547cSRui Paulo void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta,
7395b9c547cSRui Paulo u32 session_timeout)
7405b9c547cSRui Paulo {
7415b9c547cSRui Paulo if (eloop_replenish_timeout(session_timeout, 0,
7425b9c547cSRui Paulo ap_handle_session_timer, hapd, sta) == 1) {
7435b9c547cSRui Paulo hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
7445b9c547cSRui Paulo HOSTAPD_LEVEL_DEBUG, "setting session timeout "
7455b9c547cSRui Paulo "to %d seconds", session_timeout);
7465b9c547cSRui Paulo }
747e28a4053SRui Paulo }
748e28a4053SRui Paulo
749e28a4053SRui Paulo
ap_sta_session_timeout(struct hostapd_data * hapd,struct sta_info * sta,u32 session_timeout)750e28a4053SRui Paulo void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
751e28a4053SRui Paulo u32 session_timeout)
752e28a4053SRui Paulo {
753e28a4053SRui Paulo hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
754e28a4053SRui Paulo HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
755e28a4053SRui Paulo "seconds", session_timeout);
756e28a4053SRui Paulo eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
757e28a4053SRui Paulo eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
758e28a4053SRui Paulo hapd, sta);
759e28a4053SRui Paulo }
760e28a4053SRui Paulo
761e28a4053SRui Paulo
ap_sta_no_session_timeout(struct hostapd_data * hapd,struct sta_info * sta)762e28a4053SRui Paulo void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
763e28a4053SRui Paulo {
764e28a4053SRui Paulo eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
765e28a4053SRui Paulo }
766e28a4053SRui Paulo
767e28a4053SRui Paulo
ap_handle_session_warning_timer(void * eloop_ctx,void * timeout_ctx)7685b9c547cSRui Paulo static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx)
7695b9c547cSRui Paulo {
77085732ac8SCy Schubert #ifdef CONFIG_WNM_AP
7715b9c547cSRui Paulo struct hostapd_data *hapd = eloop_ctx;
7725b9c547cSRui Paulo struct sta_info *sta = timeout_ctx;
7735b9c547cSRui Paulo
774780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, "%s: WNM: Session warning time reached for "
775780fb4a2SCy Schubert MACSTR, hapd->conf->iface, MAC2STR(sta->addr));
7765b9c547cSRui Paulo if (sta->hs20_session_info_url == NULL)
7775b9c547cSRui Paulo return;
7785b9c547cSRui Paulo
7795b9c547cSRui Paulo wnm_send_ess_disassoc_imminent(hapd, sta, sta->hs20_session_info_url,
7805b9c547cSRui Paulo sta->hs20_disassoc_timer);
78185732ac8SCy Schubert #endif /* CONFIG_WNM_AP */
7825b9c547cSRui Paulo }
7835b9c547cSRui Paulo
7845b9c547cSRui Paulo
ap_sta_session_warning_timeout(struct hostapd_data * hapd,struct sta_info * sta,int warning_time)7855b9c547cSRui Paulo void ap_sta_session_warning_timeout(struct hostapd_data *hapd,
7865b9c547cSRui Paulo struct sta_info *sta, int warning_time)
7875b9c547cSRui Paulo {
7885b9c547cSRui Paulo eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
7895b9c547cSRui Paulo eloop_register_timeout(warning_time, 0, ap_handle_session_warning_timer,
7905b9c547cSRui Paulo hapd, sta);
7915b9c547cSRui Paulo }
7925b9c547cSRui Paulo
7935b9c547cSRui Paulo
ap_sta_add(struct hostapd_data * hapd,const u8 * addr)794e28a4053SRui Paulo struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
795e28a4053SRui Paulo {
796e28a4053SRui Paulo struct sta_info *sta;
797206b73d0SCy Schubert int i;
798*a90b9d01SCy Schubert int max_inactivity = hapd->conf->ap_max_inactivity;
799e28a4053SRui Paulo
800e28a4053SRui Paulo sta = ap_get_sta(hapd, addr);
801e28a4053SRui Paulo if (sta)
802e28a4053SRui Paulo return sta;
803e28a4053SRui Paulo
804e28a4053SRui Paulo wpa_printf(MSG_DEBUG, " New STA");
805e28a4053SRui Paulo if (hapd->num_sta >= hapd->conf->max_num_sta) {
806e28a4053SRui Paulo /* FIX: might try to remove some old STAs first? */
807e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
808e28a4053SRui Paulo hapd->num_sta, hapd->conf->max_num_sta);
809e28a4053SRui Paulo return NULL;
810e28a4053SRui Paulo }
811e28a4053SRui Paulo
812e28a4053SRui Paulo sta = os_zalloc(sizeof(struct sta_info));
813e28a4053SRui Paulo if (sta == NULL) {
814e28a4053SRui Paulo wpa_printf(MSG_ERROR, "malloc failed");
815e28a4053SRui Paulo return NULL;
816e28a4053SRui Paulo }
817e28a4053SRui Paulo sta->acct_interim_interval = hapd->conf->acct_interim_interval;
818780fb4a2SCy Schubert if (accounting_sta_get_id(hapd, sta) < 0) {
819780fb4a2SCy Schubert os_free(sta);
820780fb4a2SCy Schubert return NULL;
821780fb4a2SCy Schubert }
822e28a4053SRui Paulo
823206b73d0SCy Schubert for (i = 0; i < WLAN_SUPP_RATES_MAX; i++) {
824206b73d0SCy Schubert if (!hapd->iface->basic_rates)
825206b73d0SCy Schubert break;
826206b73d0SCy Schubert if (hapd->iface->basic_rates[i] < 0)
827206b73d0SCy Schubert break;
828206b73d0SCy Schubert sta->supported_rates[i] = hapd->iface->basic_rates[i] / 5;
829206b73d0SCy Schubert }
830206b73d0SCy Schubert sta->supported_rates_len = i;
831206b73d0SCy Schubert
832*a90b9d01SCy Schubert if (sta->max_idle_period)
833*a90b9d01SCy Schubert max_inactivity = (sta->max_idle_period * 1024 + 999) / 1000;
834*a90b9d01SCy Schubert
8355b9c547cSRui Paulo if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
836f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
837f05cddf9SRui Paulo "for " MACSTR " (%d seconds - ap_max_inactivity)",
838f05cddf9SRui Paulo __func__, MAC2STR(addr),
839*a90b9d01SCy Schubert max_inactivity);
840*a90b9d01SCy Schubert eloop_register_timeout(max_inactivity, 0,
841e28a4053SRui Paulo ap_handle_timer, hapd, sta);
8425b9c547cSRui Paulo }
8435b9c547cSRui Paulo
8445b9c547cSRui Paulo /* initialize STA info data */
845e28a4053SRui Paulo os_memcpy(sta->addr, addr, ETH_ALEN);
846e28a4053SRui Paulo sta->next = hapd->sta_list;
847e28a4053SRui Paulo hapd->sta_list = sta;
848e28a4053SRui Paulo hapd->num_sta++;
849e28a4053SRui Paulo ap_sta_hash_add(hapd, sta);
850e28a4053SRui Paulo ap_sta_remove_in_other_bss(hapd, sta);
8515b9c547cSRui Paulo sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
8525b9c547cSRui Paulo dl_list_init(&sta->ip6addr);
853e28a4053SRui Paulo
854780fb4a2SCy Schubert #ifdef CONFIG_TAXONOMY
855780fb4a2SCy Schubert sta_track_claim_taxonomy_info(hapd->iface, addr,
856780fb4a2SCy Schubert &sta->probe_ie_taxonomy);
857780fb4a2SCy Schubert #endif /* CONFIG_TAXONOMY */
858780fb4a2SCy Schubert
859e28a4053SRui Paulo return sta;
860e28a4053SRui Paulo }
861e28a4053SRui Paulo
862e28a4053SRui Paulo
ap_sta_remove(struct hostapd_data * hapd,struct sta_info * sta)863e28a4053SRui Paulo static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
864e28a4053SRui Paulo {
865e28a4053SRui Paulo ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
866e28a4053SRui Paulo
8675b9c547cSRui Paulo if (sta->ipaddr)
8685b9c547cSRui Paulo hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
8695b9c547cSRui Paulo ap_sta_ip6addr_del(hapd, sta);
8705b9c547cSRui Paulo
871780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, "%s: Removing STA " MACSTR " from kernel driver",
872780fb4a2SCy Schubert hapd->conf->iface, MAC2STR(sta->addr));
873f05cddf9SRui Paulo if (hostapd_drv_sta_remove(hapd, sta->addr) &&
874e28a4053SRui Paulo sta->flags & WLAN_STA_ASSOC) {
875780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, "%s: Could not remove station " MACSTR
876780fb4a2SCy Schubert " from kernel driver",
877780fb4a2SCy Schubert hapd->conf->iface, MAC2STR(sta->addr));
878e28a4053SRui Paulo return -1;
879e28a4053SRui Paulo }
880780fb4a2SCy Schubert sta->added_unassoc = 0;
881e28a4053SRui Paulo return 0;
882e28a4053SRui Paulo }
883e28a4053SRui Paulo
884e28a4053SRui Paulo
ap_sta_remove_in_other_bss(struct hostapd_data * hapd,struct sta_info * sta)885e28a4053SRui Paulo static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
886e28a4053SRui Paulo struct sta_info *sta)
887e28a4053SRui Paulo {
888e28a4053SRui Paulo struct hostapd_iface *iface = hapd->iface;
889e28a4053SRui Paulo size_t i;
890e28a4053SRui Paulo
891e28a4053SRui Paulo for (i = 0; i < iface->num_bss; i++) {
892e28a4053SRui Paulo struct hostapd_data *bss = iface->bss[i];
893e28a4053SRui Paulo struct sta_info *sta2;
894e28a4053SRui Paulo /* bss should always be set during operation, but it may be
895e28a4053SRui Paulo * NULL during reconfiguration. Assume the STA is not
896e28a4053SRui Paulo * associated to another BSS in that case to avoid NULL pointer
897e28a4053SRui Paulo * dereferences. */
898e28a4053SRui Paulo if (bss == hapd || bss == NULL)
899e28a4053SRui Paulo continue;
900e28a4053SRui Paulo sta2 = ap_get_sta(bss, sta->addr);
901e28a4053SRui Paulo if (!sta2)
902e28a4053SRui Paulo continue;
903e28a4053SRui Paulo
904780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, "%s: disconnect old STA " MACSTR
905780fb4a2SCy Schubert " association from another BSS %s",
906780fb4a2SCy Schubert hapd->conf->iface, MAC2STR(sta2->addr),
907780fb4a2SCy Schubert bss->conf->iface);
908e28a4053SRui Paulo ap_sta_disconnect(bss, sta2, sta2->addr,
909e28a4053SRui Paulo WLAN_REASON_PREV_AUTH_NOT_VALID);
910e28a4053SRui Paulo }
911e28a4053SRui Paulo }
912e28a4053SRui Paulo
913e28a4053SRui Paulo
ap_sta_disassoc_cb_timeout(void * eloop_ctx,void * timeout_ctx)914f05cddf9SRui Paulo static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
915f05cddf9SRui Paulo {
916f05cddf9SRui Paulo struct hostapd_data *hapd = eloop_ctx;
917f05cddf9SRui Paulo struct sta_info *sta = timeout_ctx;
918f05cddf9SRui Paulo
919780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, "%s: Disassociation callback for STA " MACSTR,
920780fb4a2SCy Schubert hapd->conf->iface, MAC2STR(sta->addr));
921f05cddf9SRui Paulo ap_sta_remove(hapd, sta);
922f05cddf9SRui Paulo mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
923f05cddf9SRui Paulo }
924f05cddf9SRui Paulo
925f05cddf9SRui Paulo
ap_sta_disconnect_common(struct hostapd_data * hapd,struct sta_info * sta,unsigned int timeout)926*a90b9d01SCy Schubert static void ap_sta_disconnect_common(struct hostapd_data *hapd,
927*a90b9d01SCy Schubert struct sta_info *sta, unsigned int timeout)
928*a90b9d01SCy Schubert {
929*a90b9d01SCy Schubert sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
930*a90b9d01SCy Schubert
931*a90b9d01SCy Schubert ap_sta_set_authorized(hapd, sta, 0);
932*a90b9d01SCy Schubert hostapd_set_sta_flags(hapd, sta);
933*a90b9d01SCy Schubert
934*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
935*a90b9d01SCy Schubert "reschedule ap_handle_timer timeout (%u sec) for " MACSTR,
936*a90b9d01SCy Schubert MAC2STR(sta->addr), timeout);
937*a90b9d01SCy Schubert
938*a90b9d01SCy Schubert eloop_cancel_timeout(ap_handle_timer, hapd, sta);
939*a90b9d01SCy Schubert eloop_register_timeout(timeout, 0, ap_handle_timer, hapd, sta);
940*a90b9d01SCy Schubert accounting_sta_stop(hapd, sta);
941*a90b9d01SCy Schubert ieee802_1x_free_station(hapd, sta);
942*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
943*a90b9d01SCy Schubert if (!hapd->conf->mld_ap ||
944*a90b9d01SCy Schubert hapd->mld_link_id == sta->mld_assoc_link_id) {
945*a90b9d01SCy Schubert wpa_auth_sta_deinit(sta->wpa_sm);
946*a90b9d01SCy Schubert clear_wpa_sm_for_each_partner_link(hapd, sta);
947*a90b9d01SCy Schubert }
948*a90b9d01SCy Schubert #else /* CONFIG_IEEE80211BE */
949*a90b9d01SCy Schubert wpa_auth_sta_deinit(sta->wpa_sm);
950*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
951*a90b9d01SCy Schubert
952*a90b9d01SCy Schubert sta->wpa_sm = NULL;
953*a90b9d01SCy Schubert }
954*a90b9d01SCy Schubert
955*a90b9d01SCy Schubert
ap_sta_handle_disassociate(struct hostapd_data * hapd,struct sta_info * sta,u16 reason)956*a90b9d01SCy Schubert static void ap_sta_handle_disassociate(struct hostapd_data *hapd,
957*a90b9d01SCy Schubert struct sta_info *sta, u16 reason)
958e28a4053SRui Paulo {
959e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
960e28a4053SRui Paulo hapd->conf->iface, MAC2STR(sta->addr));
961*a90b9d01SCy Schubert
96285732ac8SCy Schubert if (hapd->iface->current_mode &&
96385732ac8SCy Schubert hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
96485732ac8SCy Schubert /* Skip deauthentication in DMG/IEEE 802.11ad */
96585732ac8SCy Schubert sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
96685732ac8SCy Schubert WLAN_STA_ASSOC_REQ_OK);
96785732ac8SCy Schubert sta->timeout_next = STA_REMOVE;
96885732ac8SCy Schubert } else {
9695b9c547cSRui Paulo sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
970e28a4053SRui Paulo sta->timeout_next = STA_DEAUTH;
97185732ac8SCy Schubert }
972*a90b9d01SCy Schubert
973*a90b9d01SCy Schubert ap_sta_disconnect_common(hapd, sta, AP_MAX_INACTIVITY_AFTER_DISASSOC);
974e28a4053SRui Paulo
975f05cddf9SRui Paulo sta->disassoc_reason = reason;
976f05cddf9SRui Paulo sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
977f05cddf9SRui Paulo eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
978f05cddf9SRui Paulo eloop_register_timeout(hapd->iface->drv_flags &
979f05cddf9SRui Paulo WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
980f05cddf9SRui Paulo ap_sta_disassoc_cb_timeout, hapd, sta);
981f05cddf9SRui Paulo }
982f05cddf9SRui Paulo
983f05cddf9SRui Paulo
ap_sta_deauth_cb_timeout(void * eloop_ctx,void * timeout_ctx)984f05cddf9SRui Paulo static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
985f05cddf9SRui Paulo {
986f05cddf9SRui Paulo struct hostapd_data *hapd = eloop_ctx;
987f05cddf9SRui Paulo struct sta_info *sta = timeout_ctx;
988f05cddf9SRui Paulo
989780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, "%s: Deauthentication callback for STA " MACSTR,
990780fb4a2SCy Schubert hapd->conf->iface, MAC2STR(sta->addr));
991f05cddf9SRui Paulo ap_sta_remove(hapd, sta);
992f05cddf9SRui Paulo mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
993e28a4053SRui Paulo }
994e28a4053SRui Paulo
995e28a4053SRui Paulo
ap_sta_handle_deauthenticate(struct hostapd_data * hapd,struct sta_info * sta,u16 reason)996*a90b9d01SCy Schubert static void ap_sta_handle_deauthenticate(struct hostapd_data *hapd,
997*a90b9d01SCy Schubert struct sta_info *sta, u16 reason)
998e28a4053SRui Paulo {
99985732ac8SCy Schubert if (hapd->iface->current_mode &&
100085732ac8SCy Schubert hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
100185732ac8SCy Schubert /* Deauthentication is not used in DMG/IEEE 802.11ad;
100285732ac8SCy Schubert * disassociate the STA instead. */
100385732ac8SCy Schubert ap_sta_disassociate(hapd, sta, reason);
100485732ac8SCy Schubert return;
100585732ac8SCy Schubert }
100685732ac8SCy Schubert
1007e28a4053SRui Paulo wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
1008e28a4053SRui Paulo hapd->conf->iface, MAC2STR(sta->addr));
1009*a90b9d01SCy Schubert
10105b9c547cSRui Paulo sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
1011*a90b9d01SCy Schubert
1012e28a4053SRui Paulo sta->timeout_next = STA_REMOVE;
1013*a90b9d01SCy Schubert ap_sta_disconnect_common(hapd, sta, AP_MAX_INACTIVITY_AFTER_DEAUTH);
1014e28a4053SRui Paulo
1015f05cddf9SRui Paulo sta->deauth_reason = reason;
1016f05cddf9SRui Paulo sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
1017f05cddf9SRui Paulo eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1018f05cddf9SRui Paulo eloop_register_timeout(hapd->iface->drv_flags &
1019f05cddf9SRui Paulo WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
1020f05cddf9SRui Paulo ap_sta_deauth_cb_timeout, hapd, sta);
1021e28a4053SRui Paulo }
1022e28a4053SRui Paulo
1023e28a4053SRui Paulo
ap_sta_ml_disconnect(struct hostapd_data * hapd,struct sta_info * sta,u16 reason,bool disassoc)1024*a90b9d01SCy Schubert static bool ap_sta_ml_disconnect(struct hostapd_data *hapd,
1025*a90b9d01SCy Schubert struct sta_info *sta, u16 reason,
1026*a90b9d01SCy Schubert bool disassoc)
1027*a90b9d01SCy Schubert {
1028*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1029*a90b9d01SCy Schubert struct hostapd_data *assoc_hapd, *tmp_hapd;
1030*a90b9d01SCy Schubert struct sta_info *assoc_sta;
1031*a90b9d01SCy Schubert unsigned int i, link_id;
1032*a90b9d01SCy Schubert struct hapd_interfaces *interfaces;
1033*a90b9d01SCy Schubert
1034*a90b9d01SCy Schubert if (!hostapd_is_mld_ap(hapd))
1035*a90b9d01SCy Schubert return false;
1036*a90b9d01SCy Schubert
1037*a90b9d01SCy Schubert /*
1038*a90b9d01SCy Schubert * Get the station on which the association was performed, as it holds
1039*a90b9d01SCy Schubert * the information about all the other links.
1040*a90b9d01SCy Schubert */
1041*a90b9d01SCy Schubert assoc_sta = hostapd_ml_get_assoc_sta(hapd, sta, &assoc_hapd);
1042*a90b9d01SCy Schubert if (!assoc_sta)
1043*a90b9d01SCy Schubert return false;
1044*a90b9d01SCy Schubert interfaces = assoc_hapd->iface->interfaces;
1045*a90b9d01SCy Schubert
1046*a90b9d01SCy Schubert for (link_id = 0; link_id < MAX_NUM_MLD_LINKS; link_id++) {
1047*a90b9d01SCy Schubert if (!assoc_sta->mld_info.links[link_id].valid)
1048*a90b9d01SCy Schubert continue;
1049*a90b9d01SCy Schubert
1050*a90b9d01SCy Schubert for (i = 0; i < interfaces->count; i++) {
1051*a90b9d01SCy Schubert struct sta_info *tmp_sta;
1052*a90b9d01SCy Schubert
1053*a90b9d01SCy Schubert tmp_hapd = interfaces->iface[i]->bss[0];
1054*a90b9d01SCy Schubert
1055*a90b9d01SCy Schubert if (!hostapd_is_ml_partner(tmp_hapd, assoc_hapd))
1056*a90b9d01SCy Schubert continue;
1057*a90b9d01SCy Schubert
1058*a90b9d01SCy Schubert for (tmp_sta = tmp_hapd->sta_list; tmp_sta;
1059*a90b9d01SCy Schubert tmp_sta = tmp_sta->next) {
1060*a90b9d01SCy Schubert /*
1061*a90b9d01SCy Schubert * Handle the station on which the association
1062*a90b9d01SCy Schubert * was done only after all other link station
1063*a90b9d01SCy Schubert * are removed. Since there is a only a single
1064*a90b9d01SCy Schubert * station per hapd with the same association
1065*a90b9d01SCy Schubert * link simply break;
1066*a90b9d01SCy Schubert */
1067*a90b9d01SCy Schubert if (tmp_sta == assoc_sta)
1068*a90b9d01SCy Schubert break;
1069*a90b9d01SCy Schubert
1070*a90b9d01SCy Schubert if (tmp_sta->mld_assoc_link_id !=
1071*a90b9d01SCy Schubert assoc_sta->mld_assoc_link_id ||
1072*a90b9d01SCy Schubert tmp_sta->aid != assoc_sta->aid)
1073*a90b9d01SCy Schubert continue;
1074*a90b9d01SCy Schubert
1075*a90b9d01SCy Schubert if (disassoc)
1076*a90b9d01SCy Schubert ap_sta_handle_disassociate(tmp_hapd,
1077*a90b9d01SCy Schubert tmp_sta,
1078*a90b9d01SCy Schubert reason);
1079*a90b9d01SCy Schubert else
1080*a90b9d01SCy Schubert ap_sta_handle_deauthenticate(tmp_hapd,
1081*a90b9d01SCy Schubert tmp_sta,
1082*a90b9d01SCy Schubert reason);
1083*a90b9d01SCy Schubert
1084*a90b9d01SCy Schubert break;
1085*a90b9d01SCy Schubert }
1086*a90b9d01SCy Schubert }
1087*a90b9d01SCy Schubert }
1088*a90b9d01SCy Schubert
1089*a90b9d01SCy Schubert /* Disconnect the station on which the association was performed. */
1090*a90b9d01SCy Schubert if (disassoc)
1091*a90b9d01SCy Schubert ap_sta_handle_disassociate(assoc_hapd, assoc_sta, reason);
1092*a90b9d01SCy Schubert else
1093*a90b9d01SCy Schubert ap_sta_handle_deauthenticate(assoc_hapd, assoc_sta, reason);
1094*a90b9d01SCy Schubert
1095*a90b9d01SCy Schubert return true;
1096*a90b9d01SCy Schubert #else /* CONFIG_IEEE80211BE */
1097*a90b9d01SCy Schubert return false;
1098*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1099*a90b9d01SCy Schubert }
1100*a90b9d01SCy Schubert
1101*a90b9d01SCy Schubert
ap_sta_disassociate(struct hostapd_data * hapd,struct sta_info * sta,u16 reason)1102*a90b9d01SCy Schubert void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
1103*a90b9d01SCy Schubert u16 reason)
1104*a90b9d01SCy Schubert {
1105*a90b9d01SCy Schubert if (ap_sta_ml_disconnect(hapd, sta, reason, true))
1106*a90b9d01SCy Schubert return;
1107*a90b9d01SCy Schubert
1108*a90b9d01SCy Schubert ap_sta_handle_disassociate(hapd, sta, reason);
1109*a90b9d01SCy Schubert }
1110*a90b9d01SCy Schubert
1111*a90b9d01SCy Schubert
ap_sta_deauthenticate(struct hostapd_data * hapd,struct sta_info * sta,u16 reason)1112*a90b9d01SCy Schubert void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
1113*a90b9d01SCy Schubert u16 reason)
1114*a90b9d01SCy Schubert {
1115*a90b9d01SCy Schubert if (ap_sta_ml_disconnect(hapd, sta, reason, false))
1116*a90b9d01SCy Schubert return;
1117*a90b9d01SCy Schubert
1118*a90b9d01SCy Schubert ap_sta_handle_deauthenticate(hapd, sta, reason);
1119*a90b9d01SCy Schubert }
1120*a90b9d01SCy Schubert
1121*a90b9d01SCy Schubert
1122f05cddf9SRui Paulo #ifdef CONFIG_WPS
ap_sta_wps_cancel(struct hostapd_data * hapd,struct sta_info * sta,void * ctx)1123f05cddf9SRui Paulo int ap_sta_wps_cancel(struct hostapd_data *hapd,
1124f05cddf9SRui Paulo struct sta_info *sta, void *ctx)
1125f05cddf9SRui Paulo {
1126f05cddf9SRui Paulo if (sta && (sta->flags & WLAN_STA_WPS)) {
1127f05cddf9SRui Paulo ap_sta_deauthenticate(hapd, sta,
1128f05cddf9SRui Paulo WLAN_REASON_PREV_AUTH_NOT_VALID);
1129f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
1130f05cddf9SRui Paulo __func__, MAC2STR(sta->addr));
1131f05cddf9SRui Paulo return 1;
1132f05cddf9SRui Paulo }
1133f05cddf9SRui Paulo
1134f05cddf9SRui Paulo return 0;
1135f05cddf9SRui Paulo }
1136f05cddf9SRui Paulo #endif /* CONFIG_WPS */
1137f05cddf9SRui Paulo
1138f05cddf9SRui Paulo
ap_sta_get_free_vlan_id(struct hostapd_data * hapd)1139780fb4a2SCy Schubert static int ap_sta_get_free_vlan_id(struct hostapd_data *hapd)
1140780fb4a2SCy Schubert {
1141780fb4a2SCy Schubert struct hostapd_vlan *vlan;
1142780fb4a2SCy Schubert int vlan_id = MAX_VLAN_ID + 2;
1143780fb4a2SCy Schubert
1144780fb4a2SCy Schubert retry:
1145780fb4a2SCy Schubert for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
1146780fb4a2SCy Schubert if (vlan->vlan_id == vlan_id) {
1147780fb4a2SCy Schubert vlan_id++;
1148780fb4a2SCy Schubert goto retry;
1149780fb4a2SCy Schubert }
1150780fb4a2SCy Schubert }
1151780fb4a2SCy Schubert return vlan_id;
1152780fb4a2SCy Schubert }
1153780fb4a2SCy Schubert
1154780fb4a2SCy Schubert
ap_sta_set_vlan(struct hostapd_data * hapd,struct sta_info * sta,struct vlan_description * vlan_desc)1155780fb4a2SCy Schubert int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta,
1156780fb4a2SCy Schubert struct vlan_description *vlan_desc)
1157780fb4a2SCy Schubert {
1158780fb4a2SCy Schubert struct hostapd_vlan *vlan = NULL, *wildcard_vlan = NULL;
1159780fb4a2SCy Schubert int old_vlan_id, vlan_id = 0, ret = 0;
1160780fb4a2SCy Schubert
1161780fb4a2SCy Schubert /* Check if there is something to do */
1162780fb4a2SCy Schubert if (hapd->conf->ssid.per_sta_vif && !sta->vlan_id) {
1163780fb4a2SCy Schubert /* This sta is lacking its own vif */
1164780fb4a2SCy Schubert } else if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED &&
1165780fb4a2SCy Schubert !hapd->conf->ssid.per_sta_vif && sta->vlan_id) {
1166780fb4a2SCy Schubert /* sta->vlan_id needs to be reset */
1167780fb4a2SCy Schubert } else if (!vlan_compare(vlan_desc, sta->vlan_desc)) {
1168780fb4a2SCy Schubert return 0; /* nothing to change */
1169780fb4a2SCy Schubert }
1170780fb4a2SCy Schubert
1171780fb4a2SCy Schubert /* Now the real VLAN changed or the STA just needs its own vif */
1172780fb4a2SCy Schubert if (hapd->conf->ssid.per_sta_vif) {
1173780fb4a2SCy Schubert /* Assign a new vif, always */
1174780fb4a2SCy Schubert /* find a free vlan_id sufficiently big */
1175780fb4a2SCy Schubert vlan_id = ap_sta_get_free_vlan_id(hapd);
1176780fb4a2SCy Schubert /* Get wildcard VLAN */
1177780fb4a2SCy Schubert for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
1178780fb4a2SCy Schubert if (vlan->vlan_id == VLAN_ID_WILDCARD)
1179780fb4a2SCy Schubert break;
1180780fb4a2SCy Schubert }
1181780fb4a2SCy Schubert if (!vlan) {
1182780fb4a2SCy Schubert hostapd_logger(hapd, sta->addr,
1183780fb4a2SCy Schubert HOSTAPD_MODULE_IEEE80211,
1184780fb4a2SCy Schubert HOSTAPD_LEVEL_DEBUG,
1185780fb4a2SCy Schubert "per_sta_vif missing wildcard");
1186780fb4a2SCy Schubert vlan_id = 0;
1187780fb4a2SCy Schubert ret = -1;
1188780fb4a2SCy Schubert goto done;
1189780fb4a2SCy Schubert }
1190780fb4a2SCy Schubert } else if (vlan_desc && vlan_desc->notempty) {
1191780fb4a2SCy Schubert for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
1192780fb4a2SCy Schubert if (!vlan_compare(&vlan->vlan_desc, vlan_desc))
1193780fb4a2SCy Schubert break;
1194780fb4a2SCy Schubert if (vlan->vlan_id == VLAN_ID_WILDCARD)
1195780fb4a2SCy Schubert wildcard_vlan = vlan;
1196780fb4a2SCy Schubert }
1197780fb4a2SCy Schubert if (vlan) {
1198780fb4a2SCy Schubert vlan_id = vlan->vlan_id;
1199780fb4a2SCy Schubert } else if (wildcard_vlan) {
1200780fb4a2SCy Schubert vlan = wildcard_vlan;
1201780fb4a2SCy Schubert vlan_id = vlan_desc->untagged;
1202780fb4a2SCy Schubert if (vlan_desc->tagged[0]) {
1203780fb4a2SCy Schubert /* Tagged VLAN configuration */
1204780fb4a2SCy Schubert vlan_id = ap_sta_get_free_vlan_id(hapd);
1205780fb4a2SCy Schubert }
1206780fb4a2SCy Schubert } else {
1207780fb4a2SCy Schubert hostapd_logger(hapd, sta->addr,
1208780fb4a2SCy Schubert HOSTAPD_MODULE_IEEE80211,
1209780fb4a2SCy Schubert HOSTAPD_LEVEL_DEBUG,
1210780fb4a2SCy Schubert "missing vlan and wildcard for vlan=%d%s",
1211780fb4a2SCy Schubert vlan_desc->untagged,
1212780fb4a2SCy Schubert vlan_desc->tagged[0] ? "+" : "");
1213780fb4a2SCy Schubert vlan_id = 0;
1214780fb4a2SCy Schubert ret = -1;
1215780fb4a2SCy Schubert goto done;
1216780fb4a2SCy Schubert }
1217780fb4a2SCy Schubert }
1218780fb4a2SCy Schubert
1219780fb4a2SCy Schubert if (vlan && vlan->vlan_id == VLAN_ID_WILDCARD) {
1220780fb4a2SCy Schubert vlan = vlan_add_dynamic(hapd, vlan, vlan_id, vlan_desc);
1221780fb4a2SCy Schubert if (vlan == NULL) {
1222780fb4a2SCy Schubert hostapd_logger(hapd, sta->addr,
1223780fb4a2SCy Schubert HOSTAPD_MODULE_IEEE80211,
1224780fb4a2SCy Schubert HOSTAPD_LEVEL_DEBUG,
1225780fb4a2SCy Schubert "could not add dynamic VLAN interface for vlan=%d%s",
1226780fb4a2SCy Schubert vlan_desc ? vlan_desc->untagged : -1,
1227780fb4a2SCy Schubert (vlan_desc && vlan_desc->tagged[0]) ?
1228780fb4a2SCy Schubert "+" : "");
1229780fb4a2SCy Schubert vlan_id = 0;
1230780fb4a2SCy Schubert ret = -1;
1231780fb4a2SCy Schubert goto done;
1232780fb4a2SCy Schubert }
1233780fb4a2SCy Schubert
1234780fb4a2SCy Schubert hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1235780fb4a2SCy Schubert HOSTAPD_LEVEL_DEBUG,
1236780fb4a2SCy Schubert "added new dynamic VLAN interface '%s'",
1237780fb4a2SCy Schubert vlan->ifname);
1238780fb4a2SCy Schubert } else if (vlan && vlan->dynamic_vlan > 0) {
1239780fb4a2SCy Schubert vlan->dynamic_vlan++;
1240780fb4a2SCy Schubert hostapd_logger(hapd, sta->addr,
1241780fb4a2SCy Schubert HOSTAPD_MODULE_IEEE80211,
1242780fb4a2SCy Schubert HOSTAPD_LEVEL_DEBUG,
1243780fb4a2SCy Schubert "updated existing dynamic VLAN interface '%s'",
1244780fb4a2SCy Schubert vlan->ifname);
1245780fb4a2SCy Schubert }
1246780fb4a2SCy Schubert done:
1247780fb4a2SCy Schubert old_vlan_id = sta->vlan_id;
1248780fb4a2SCy Schubert sta->vlan_id = vlan_id;
1249780fb4a2SCy Schubert sta->vlan_desc = vlan ? &vlan->vlan_desc : NULL;
1250780fb4a2SCy Schubert
1251780fb4a2SCy Schubert if (vlan_id != old_vlan_id && old_vlan_id)
1252780fb4a2SCy Schubert vlan_remove_dynamic(hapd, old_vlan_id);
1253780fb4a2SCy Schubert
1254780fb4a2SCy Schubert return ret;
1255780fb4a2SCy Schubert }
1256780fb4a2SCy Schubert
1257780fb4a2SCy Schubert
ap_sta_bind_vlan(struct hostapd_data * hapd,struct sta_info * sta)1258325151a3SRui Paulo int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta)
1259e28a4053SRui Paulo {
1260e28a4053SRui Paulo #ifndef CONFIG_NO_VLAN
1261e28a4053SRui Paulo const char *iface;
1262e28a4053SRui Paulo struct hostapd_vlan *vlan = NULL;
1263e28a4053SRui Paulo int ret;
1264325151a3SRui Paulo int old_vlanid = sta->vlan_id_bound;
1265*a90b9d01SCy Schubert int mld_link_id = -1;
1266*a90b9d01SCy Schubert
1267*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1268*a90b9d01SCy Schubert if (hapd->conf->mld_ap)
1269*a90b9d01SCy Schubert mld_link_id = hapd->mld_link_id;
1270*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1271e28a4053SRui Paulo
1272c1d255d3SCy Schubert if ((sta->flags & WLAN_STA_WDS) && sta->vlan_id == 0) {
1273c1d255d3SCy Schubert wpa_printf(MSG_DEBUG,
1274c1d255d3SCy Schubert "Do not override WDS VLAN assignment for STA "
1275c1d255d3SCy Schubert MACSTR, MAC2STR(sta->addr));
1276c1d255d3SCy Schubert return 0;
1277c1d255d3SCy Schubert }
1278c1d255d3SCy Schubert
1279e28a4053SRui Paulo iface = hapd->conf->iface;
1280325151a3SRui Paulo if (hapd->conf->ssid.vlan[0])
1281325151a3SRui Paulo iface = hapd->conf->ssid.vlan;
1282e28a4053SRui Paulo
1283780fb4a2SCy Schubert if (sta->vlan_id > 0) {
1284780fb4a2SCy Schubert for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
12855b9c547cSRui Paulo if (vlan->vlan_id == sta->vlan_id)
1286e28a4053SRui Paulo break;
1287e28a4053SRui Paulo }
12885b9c547cSRui Paulo if (vlan)
12895b9c547cSRui Paulo iface = vlan->ifname;
1290e28a4053SRui Paulo }
1291e28a4053SRui Paulo
1292325151a3SRui Paulo /*
1293325151a3SRui Paulo * Do not increment ref counters if the VLAN ID remains same, but do
1294325151a3SRui Paulo * not skip hostapd_drv_set_sta_vlan() as hostapd_drv_sta_remove() might
1295325151a3SRui Paulo * have been called before.
1296325151a3SRui Paulo */
1297325151a3SRui Paulo if (sta->vlan_id == old_vlanid)
1298325151a3SRui Paulo goto skip_counting;
1299325151a3SRui Paulo
1300c1d255d3SCy Schubert if (sta->vlan_id > 0 && !vlan &&
1301c1d255d3SCy Schubert !(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) {
1302e28a4053SRui Paulo hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1303e28a4053SRui Paulo HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
1304e28a4053SRui Paulo "binding station to (vlan_id=%d)",
1305e28a4053SRui Paulo sta->vlan_id);
13065b9c547cSRui Paulo ret = -1;
13075b9c547cSRui Paulo goto done;
1308780fb4a2SCy Schubert } else if (vlan && vlan->dynamic_vlan > 0) {
1309e28a4053SRui Paulo vlan->dynamic_vlan++;
1310e28a4053SRui Paulo hostapd_logger(hapd, sta->addr,
1311e28a4053SRui Paulo HOSTAPD_MODULE_IEEE80211,
1312780fb4a2SCy Schubert HOSTAPD_LEVEL_DEBUG,
1313780fb4a2SCy Schubert "updated existing dynamic VLAN interface '%s'",
1314780fb4a2SCy Schubert iface);
1315e28a4053SRui Paulo }
1316e28a4053SRui Paulo
1317325151a3SRui Paulo /* ref counters have been increased, so mark the station */
1318325151a3SRui Paulo sta->vlan_id_bound = sta->vlan_id;
1319325151a3SRui Paulo
1320325151a3SRui Paulo skip_counting:
1321e28a4053SRui Paulo hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1322e28a4053SRui Paulo HOSTAPD_LEVEL_DEBUG, "binding station to interface "
1323e28a4053SRui Paulo "'%s'", iface);
1324e28a4053SRui Paulo
1325e28a4053SRui Paulo if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
1326e28a4053SRui Paulo wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
1327e28a4053SRui Paulo
1328*a90b9d01SCy Schubert ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id,
1329*a90b9d01SCy Schubert mld_link_id);
1330e28a4053SRui Paulo if (ret < 0) {
1331e28a4053SRui Paulo hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1332e28a4053SRui Paulo HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
1333e28a4053SRui Paulo "entry to vlan_id=%d", sta->vlan_id);
1334e28a4053SRui Paulo }
13355b9c547cSRui Paulo
13365b9c547cSRui Paulo /* During 1x reauth, if the vlan id changes, then remove the old id. */
1337325151a3SRui Paulo if (old_vlanid > 0 && old_vlanid != sta->vlan_id)
13385b9c547cSRui Paulo vlan_remove_dynamic(hapd, old_vlanid);
1339325151a3SRui Paulo done:
13405b9c547cSRui Paulo
1341e28a4053SRui Paulo return ret;
1342e28a4053SRui Paulo #else /* CONFIG_NO_VLAN */
1343e28a4053SRui Paulo return 0;
1344e28a4053SRui Paulo #endif /* CONFIG_NO_VLAN */
1345e28a4053SRui Paulo }
1346e28a4053SRui Paulo
1347e28a4053SRui Paulo
ap_check_sa_query_timeout(struct hostapd_data * hapd,struct sta_info * sta)1348e28a4053SRui Paulo int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
1349e28a4053SRui Paulo {
1350e28a4053SRui Paulo u32 tu;
13515b9c547cSRui Paulo struct os_reltime now, passed;
13525b9c547cSRui Paulo os_get_reltime(&now);
13535b9c547cSRui Paulo os_reltime_sub(&now, &sta->sa_query_start, &passed);
1354e28a4053SRui Paulo tu = (passed.sec * 1000000 + passed.usec) / 1024;
1355e28a4053SRui Paulo if (hapd->conf->assoc_sa_query_max_timeout < tu) {
1356e28a4053SRui Paulo hostapd_logger(hapd, sta->addr,
1357e28a4053SRui Paulo HOSTAPD_MODULE_IEEE80211,
1358e28a4053SRui Paulo HOSTAPD_LEVEL_DEBUG,
1359e28a4053SRui Paulo "association SA Query timed out");
1360e28a4053SRui Paulo sta->sa_query_timed_out = 1;
1361e28a4053SRui Paulo os_free(sta->sa_query_trans_id);
1362e28a4053SRui Paulo sta->sa_query_trans_id = NULL;
1363e28a4053SRui Paulo sta->sa_query_count = 0;
1364e28a4053SRui Paulo eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1365e28a4053SRui Paulo return 1;
1366e28a4053SRui Paulo }
1367e28a4053SRui Paulo
1368e28a4053SRui Paulo return 0;
1369e28a4053SRui Paulo }
1370e28a4053SRui Paulo
1371e28a4053SRui Paulo
ap_sa_query_timer(void * eloop_ctx,void * timeout_ctx)1372e28a4053SRui Paulo static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
1373e28a4053SRui Paulo {
1374e28a4053SRui Paulo struct hostapd_data *hapd = eloop_ctx;
1375e28a4053SRui Paulo struct sta_info *sta = timeout_ctx;
1376e28a4053SRui Paulo unsigned int timeout, sec, usec;
1377e28a4053SRui Paulo u8 *trans_id, *nbuf;
1378e28a4053SRui Paulo
1379780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, "%s: SA Query timer for STA " MACSTR
1380780fb4a2SCy Schubert " (count=%d)",
1381780fb4a2SCy Schubert hapd->conf->iface, MAC2STR(sta->addr), sta->sa_query_count);
1382780fb4a2SCy Schubert
1383e28a4053SRui Paulo if (sta->sa_query_count > 0 &&
1384e28a4053SRui Paulo ap_check_sa_query_timeout(hapd, sta))
1385e28a4053SRui Paulo return;
1386c1d255d3SCy Schubert if (sta->sa_query_count >= 1000)
1387c1d255d3SCy Schubert return;
1388e28a4053SRui Paulo
1389f05cddf9SRui Paulo nbuf = os_realloc_array(sta->sa_query_trans_id,
1390f05cddf9SRui Paulo sta->sa_query_count + 1,
1391f05cddf9SRui Paulo WLAN_SA_QUERY_TR_ID_LEN);
1392e28a4053SRui Paulo if (nbuf == NULL)
1393e28a4053SRui Paulo return;
1394e28a4053SRui Paulo if (sta->sa_query_count == 0) {
1395e28a4053SRui Paulo /* Starting a new SA Query procedure */
13965b9c547cSRui Paulo os_get_reltime(&sta->sa_query_start);
1397e28a4053SRui Paulo }
1398e28a4053SRui Paulo trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
1399e28a4053SRui Paulo sta->sa_query_trans_id = nbuf;
1400e28a4053SRui Paulo sta->sa_query_count++;
1401e28a4053SRui Paulo
14025b9c547cSRui Paulo if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) {
14035b9c547cSRui Paulo /*
14045b9c547cSRui Paulo * We don't really care which ID is used here, so simply
14055b9c547cSRui Paulo * hardcode this if the mostly theoretical os_get_random()
14065b9c547cSRui Paulo * failure happens.
14075b9c547cSRui Paulo */
14085b9c547cSRui Paulo trans_id[0] = 0x12;
14095b9c547cSRui Paulo trans_id[1] = 0x34;
14105b9c547cSRui Paulo }
1411e28a4053SRui Paulo
1412e28a4053SRui Paulo timeout = hapd->conf->assoc_sa_query_retry_timeout;
1413e28a4053SRui Paulo sec = ((timeout / 1000) * 1024) / 1000;
1414e28a4053SRui Paulo usec = (timeout % 1000) * 1024;
1415e28a4053SRui Paulo eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
1416e28a4053SRui Paulo
1417e28a4053SRui Paulo hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1418e28a4053SRui Paulo HOSTAPD_LEVEL_DEBUG,
1419e28a4053SRui Paulo "association SA Query attempt %d", sta->sa_query_count);
1420e28a4053SRui Paulo
1421e28a4053SRui Paulo ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
1422e28a4053SRui Paulo }
1423e28a4053SRui Paulo
1424e28a4053SRui Paulo
ap_sta_start_sa_query(struct hostapd_data * hapd,struct sta_info * sta)1425e28a4053SRui Paulo void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1426e28a4053SRui Paulo {
1427e28a4053SRui Paulo ap_sa_query_timer(hapd, sta);
1428e28a4053SRui Paulo }
1429e28a4053SRui Paulo
1430e28a4053SRui Paulo
ap_sta_stop_sa_query(struct hostapd_data * hapd,struct sta_info * sta)1431e28a4053SRui Paulo void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1432e28a4053SRui Paulo {
1433e28a4053SRui Paulo eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1434e28a4053SRui Paulo os_free(sta->sa_query_trans_id);
1435e28a4053SRui Paulo sta->sa_query_trans_id = NULL;
1436e28a4053SRui Paulo sta->sa_query_count = 0;
1437e28a4053SRui Paulo }
1438e28a4053SRui Paulo
1439e28a4053SRui Paulo
ap_sta_wpa_get_keyid(struct hostapd_data * hapd,struct sta_info * sta)14404bc52338SCy Schubert const char * ap_sta_wpa_get_keyid(struct hostapd_data *hapd,
14414bc52338SCy Schubert struct sta_info *sta)
14424bc52338SCy Schubert {
14434bc52338SCy Schubert struct hostapd_wpa_psk *psk;
14444bc52338SCy Schubert struct hostapd_ssid *ssid;
14454bc52338SCy Schubert const u8 *pmk;
14464bc52338SCy Schubert int pmk_len;
14474bc52338SCy Schubert
14484bc52338SCy Schubert ssid = &hapd->conf->ssid;
14494bc52338SCy Schubert
14504bc52338SCy Schubert pmk = wpa_auth_get_pmk(sta->wpa_sm, &pmk_len);
14514bc52338SCy Schubert if (!pmk || pmk_len != PMK_LEN)
14524bc52338SCy Schubert return NULL;
14534bc52338SCy Schubert
14544bc52338SCy Schubert for (psk = ssid->wpa_psk; psk; psk = psk->next)
14554bc52338SCy Schubert if (os_memcmp(pmk, psk->psk, PMK_LEN) == 0)
14564bc52338SCy Schubert break;
14574bc52338SCy Schubert if (!psk || !psk->keyid[0])
14584bc52338SCy Schubert return NULL;
14594bc52338SCy Schubert
14604bc52338SCy Schubert return psk->keyid;
14614bc52338SCy Schubert }
14624bc52338SCy Schubert
14634bc52338SCy Schubert
ap_sta_wpa_get_dpp_pkhash(struct hostapd_data * hapd,struct sta_info * sta)1464*a90b9d01SCy Schubert const u8 * ap_sta_wpa_get_dpp_pkhash(struct hostapd_data *hapd,
1465*a90b9d01SCy Schubert struct sta_info *sta)
1466*a90b9d01SCy Schubert {
1467*a90b9d01SCy Schubert return wpa_auth_get_dpp_pkhash(sta->wpa_sm);
1468*a90b9d01SCy Schubert }
1469*a90b9d01SCy Schubert
1470*a90b9d01SCy Schubert
ap_sta_set_authorized_flag(struct hostapd_data * hapd,struct sta_info * sta,int authorized)1471*a90b9d01SCy Schubert bool ap_sta_set_authorized_flag(struct hostapd_data *hapd, struct sta_info *sta,
1472f05cddf9SRui Paulo int authorized)
1473f05cddf9SRui Paulo {
1474*a90b9d01SCy Schubert if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
1475*a90b9d01SCy Schubert return false;
1476*a90b9d01SCy Schubert
1477*a90b9d01SCy Schubert if (authorized) {
1478*a90b9d01SCy Schubert int mld_assoc_link_id = -1;
1479*a90b9d01SCy Schubert
1480*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1481*a90b9d01SCy Schubert if (ap_sta_is_mld(hapd, sta)) {
1482*a90b9d01SCy Schubert if (sta->mld_assoc_link_id == hapd->mld_link_id)
1483*a90b9d01SCy Schubert mld_assoc_link_id = sta->mld_assoc_link_id;
1484*a90b9d01SCy Schubert else
1485*a90b9d01SCy Schubert mld_assoc_link_id = -2;
1486*a90b9d01SCy Schubert }
1487*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1488*a90b9d01SCy Schubert if (mld_assoc_link_id != -2)
1489*a90b9d01SCy Schubert hostapd_prune_associations(hapd, sta->addr,
1490*a90b9d01SCy Schubert mld_assoc_link_id);
1491*a90b9d01SCy Schubert sta->flags |= WLAN_STA_AUTHORIZED;
1492*a90b9d01SCy Schubert } else {
1493*a90b9d01SCy Schubert sta->flags &= ~WLAN_STA_AUTHORIZED;
1494*a90b9d01SCy Schubert }
1495*a90b9d01SCy Schubert
1496*a90b9d01SCy Schubert return true;
1497*a90b9d01SCy Schubert }
1498*a90b9d01SCy Schubert
1499*a90b9d01SCy Schubert
ap_sta_set_authorized_event(struct hostapd_data * hapd,struct sta_info * sta,int authorized)1500*a90b9d01SCy Schubert void ap_sta_set_authorized_event(struct hostapd_data *hapd,
1501*a90b9d01SCy Schubert struct sta_info *sta, int authorized)
1502*a90b9d01SCy Schubert {
1503f05cddf9SRui Paulo const u8 *dev_addr = NULL;
15045b9c547cSRui Paulo char buf[100];
1505f05cddf9SRui Paulo #ifdef CONFIG_P2P
1506f05cddf9SRui Paulo u8 addr[ETH_ALEN];
15075b9c547cSRui Paulo u8 ip_addr_buf[4];
1508f05cddf9SRui Paulo #endif /* CONFIG_P2P */
1509*a90b9d01SCy Schubert const u8 *ip_ptr = NULL;
15105b9c547cSRui Paulo
1511f05cddf9SRui Paulo #ifdef CONFIG_P2P
1512f05cddf9SRui Paulo if (hapd->p2p_group == NULL) {
1513f05cddf9SRui Paulo if (sta->p2p_ie != NULL &&
1514f05cddf9SRui Paulo p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
1515f05cddf9SRui Paulo dev_addr = addr;
1516f05cddf9SRui Paulo } else
1517f05cddf9SRui Paulo dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
15185b9c547cSRui Paulo
15195b9c547cSRui Paulo if (dev_addr)
15205b9c547cSRui Paulo os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
15215b9c547cSRui Paulo MAC2STR(sta->addr), MAC2STR(dev_addr));
15225b9c547cSRui Paulo else
1523f05cddf9SRui Paulo #endif /* CONFIG_P2P */
15245b9c547cSRui Paulo os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
1525f05cddf9SRui Paulo
15265b9c547cSRui Paulo if (authorized) {
1527*a90b9d01SCy Schubert const u8 *dpp_pkhash;
15284bc52338SCy Schubert const char *keyid;
1529*a90b9d01SCy Schubert char dpp_pkhash_buf[100];
15304bc52338SCy Schubert char keyid_buf[100];
15315b9c547cSRui Paulo char ip_addr[100];
15324bc52338SCy Schubert
1533*a90b9d01SCy Schubert dpp_pkhash_buf[0] = '\0';
15344bc52338SCy Schubert keyid_buf[0] = '\0';
15355b9c547cSRui Paulo ip_addr[0] = '\0';
15365b9c547cSRui Paulo #ifdef CONFIG_P2P
15375b9c547cSRui Paulo if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) {
15385b9c547cSRui Paulo os_snprintf(ip_addr, sizeof(ip_addr),
15395b9c547cSRui Paulo " ip_addr=%u.%u.%u.%u",
15405b9c547cSRui Paulo ip_addr_buf[0], ip_addr_buf[1],
15415b9c547cSRui Paulo ip_addr_buf[2], ip_addr_buf[3]);
1542*a90b9d01SCy Schubert ip_ptr = ip_addr_buf;
15435b9c547cSRui Paulo }
15445b9c547cSRui Paulo #endif /* CONFIG_P2P */
15455b9c547cSRui Paulo
15464bc52338SCy Schubert keyid = ap_sta_wpa_get_keyid(hapd, sta);
15474bc52338SCy Schubert if (keyid) {
15484bc52338SCy Schubert os_snprintf(keyid_buf, sizeof(keyid_buf),
15494bc52338SCy Schubert " keyid=%s", keyid);
15504bc52338SCy Schubert }
15514bc52338SCy Schubert
1552*a90b9d01SCy Schubert dpp_pkhash = ap_sta_wpa_get_dpp_pkhash(hapd, sta);
1553*a90b9d01SCy Schubert if (dpp_pkhash) {
1554*a90b9d01SCy Schubert const char *prefix = " dpp_pkhash=";
1555*a90b9d01SCy Schubert size_t plen = os_strlen(prefix);
1556*a90b9d01SCy Schubert
1557*a90b9d01SCy Schubert os_strlcpy(dpp_pkhash_buf, prefix,
1558*a90b9d01SCy Schubert sizeof(dpp_pkhash_buf));
1559*a90b9d01SCy Schubert wpa_snprintf_hex(&dpp_pkhash_buf[plen],
1560*a90b9d01SCy Schubert sizeof(dpp_pkhash_buf) - plen,
1561*a90b9d01SCy Schubert dpp_pkhash, SHA256_MAC_LEN);
1562*a90b9d01SCy Schubert }
1563*a90b9d01SCy Schubert
1564*a90b9d01SCy Schubert wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s%s",
1565*a90b9d01SCy Schubert buf, ip_addr, keyid_buf, dpp_pkhash_buf);
15665b9c547cSRui Paulo
15675b9c547cSRui Paulo if (hapd->msg_ctx_parent &&
15685b9c547cSRui Paulo hapd->msg_ctx_parent != hapd->msg_ctx)
15695b9c547cSRui Paulo wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
1570*a90b9d01SCy Schubert AP_STA_CONNECTED "%s%s%s%s",
1571*a90b9d01SCy Schubert buf, ip_addr, keyid_buf,
1572*a90b9d01SCy Schubert dpp_pkhash_buf);
15735b9c547cSRui Paulo } else {
15745b9c547cSRui Paulo wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
15755b9c547cSRui Paulo
15765b9c547cSRui Paulo if (hapd->msg_ctx_parent &&
15775b9c547cSRui Paulo hapd->msg_ctx_parent != hapd->msg_ctx)
15785b9c547cSRui Paulo wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
15795b9c547cSRui Paulo AP_STA_DISCONNECTED "%s", buf);
15805b9c547cSRui Paulo }
1581325151a3SRui Paulo
1582*a90b9d01SCy Schubert if (hapd->sta_authorized_cb)
1583*a90b9d01SCy Schubert hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
1584*a90b9d01SCy Schubert sta->addr, authorized, dev_addr,
1585*a90b9d01SCy Schubert ip_ptr);
1586*a90b9d01SCy Schubert
1587325151a3SRui Paulo #ifdef CONFIG_FST
1588325151a3SRui Paulo if (hapd->iface->fst) {
1589325151a3SRui Paulo if (authorized)
1590325151a3SRui Paulo fst_notify_peer_connected(hapd->iface->fst, sta->addr);
1591325151a3SRui Paulo else
1592325151a3SRui Paulo fst_notify_peer_disconnected(hapd->iface->fst,
1593325151a3SRui Paulo sta->addr);
1594325151a3SRui Paulo }
1595325151a3SRui Paulo #endif /* CONFIG_FST */
1596f05cddf9SRui Paulo }
1597f05cddf9SRui Paulo
1598f05cddf9SRui Paulo
ap_sta_set_authorized(struct hostapd_data * hapd,struct sta_info * sta,int authorized)1599*a90b9d01SCy Schubert void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
1600*a90b9d01SCy Schubert int authorized)
1601*a90b9d01SCy Schubert {
1602*a90b9d01SCy Schubert if (!ap_sta_set_authorized_flag(hapd, sta, authorized))
1603*a90b9d01SCy Schubert return;
1604*a90b9d01SCy Schubert ap_sta_set_authorized_event(hapd, sta, authorized);
1605*a90b9d01SCy Schubert }
1606*a90b9d01SCy Schubert
1607*a90b9d01SCy Schubert
ap_sta_disconnect(struct hostapd_data * hapd,struct sta_info * sta,const u8 * addr,u16 reason)1608e28a4053SRui Paulo void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
1609e28a4053SRui Paulo const u8 *addr, u16 reason)
1610e28a4053SRui Paulo {
1611780fb4a2SCy Schubert if (sta)
1612780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, "%s: %s STA " MACSTR " reason=%u",
1613780fb4a2SCy Schubert hapd->conf->iface, __func__, MAC2STR(sta->addr),
1614780fb4a2SCy Schubert reason);
1615780fb4a2SCy Schubert else if (addr)
1616780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, "%s: %s addr " MACSTR " reason=%u",
1617780fb4a2SCy Schubert hapd->conf->iface, __func__, MAC2STR(addr),
1618780fb4a2SCy Schubert reason);
1619e28a4053SRui Paulo
1620e28a4053SRui Paulo if (sta == NULL && addr)
1621e28a4053SRui Paulo sta = ap_get_sta(hapd, addr);
1622e28a4053SRui Paulo
1623e28a4053SRui Paulo if (addr)
1624f05cddf9SRui Paulo hostapd_drv_sta_deauth(hapd, addr, reason);
1625e28a4053SRui Paulo
1626e28a4053SRui Paulo if (sta == NULL)
1627e28a4053SRui Paulo return;
1628f05cddf9SRui Paulo ap_sta_set_authorized(hapd, sta, 0);
1629c1d255d3SCy Schubert sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1630c1d255d3SCy Schubert hostapd_set_sta_flags(hapd, sta);
1631f05cddf9SRui Paulo wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1632f05cddf9SRui Paulo ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1633780fb4a2SCy Schubert wpa_printf(MSG_DEBUG, "%s: %s: reschedule ap_handle_timer timeout "
1634f05cddf9SRui Paulo "for " MACSTR " (%d seconds - "
1635f05cddf9SRui Paulo "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
1636780fb4a2SCy Schubert hapd->conf->iface, __func__, MAC2STR(sta->addr),
1637f05cddf9SRui Paulo AP_MAX_INACTIVITY_AFTER_DEAUTH);
1638e28a4053SRui Paulo eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1639f05cddf9SRui Paulo eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
1640f05cddf9SRui Paulo ap_handle_timer, hapd, sta);
1641e28a4053SRui Paulo sta->timeout_next = STA_REMOVE;
1642f05cddf9SRui Paulo
164385732ac8SCy Schubert if (hapd->iface->current_mode &&
164485732ac8SCy Schubert hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
164585732ac8SCy Schubert /* Deauthentication is not used in DMG/IEEE 802.11ad;
164685732ac8SCy Schubert * disassociate the STA instead. */
164785732ac8SCy Schubert sta->disassoc_reason = reason;
164885732ac8SCy Schubert sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
164985732ac8SCy Schubert eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
165085732ac8SCy Schubert eloop_register_timeout(hapd->iface->drv_flags &
165185732ac8SCy Schubert WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ?
165285732ac8SCy Schubert 2 : 0, 0, ap_sta_disassoc_cb_timeout,
165385732ac8SCy Schubert hapd, sta);
165485732ac8SCy Schubert return;
165585732ac8SCy Schubert }
165685732ac8SCy Schubert
1657f05cddf9SRui Paulo sta->deauth_reason = reason;
1658f05cddf9SRui Paulo sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
1659f05cddf9SRui Paulo eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1660f05cddf9SRui Paulo eloop_register_timeout(hapd->iface->drv_flags &
1661f05cddf9SRui Paulo WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
1662f05cddf9SRui Paulo ap_sta_deauth_cb_timeout, hapd, sta);
1663f05cddf9SRui Paulo }
1664f05cddf9SRui Paulo
1665f05cddf9SRui Paulo
ap_sta_deauth_cb(struct hostapd_data * hapd,struct sta_info * sta)1666f05cddf9SRui Paulo void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
1667f05cddf9SRui Paulo {
1668f05cddf9SRui Paulo if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
1669f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
1670f05cddf9SRui Paulo return;
1671f05cddf9SRui Paulo }
1672f05cddf9SRui Paulo sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
1673f05cddf9SRui Paulo eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1674f05cddf9SRui Paulo ap_sta_deauth_cb_timeout(hapd, sta);
1675f05cddf9SRui Paulo }
1676f05cddf9SRui Paulo
1677f05cddf9SRui Paulo
ap_sta_disassoc_cb(struct hostapd_data * hapd,struct sta_info * sta)1678f05cddf9SRui Paulo void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
1679f05cddf9SRui Paulo {
1680f05cddf9SRui Paulo if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
1681f05cddf9SRui Paulo wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
1682f05cddf9SRui Paulo return;
1683f05cddf9SRui Paulo }
1684f05cddf9SRui Paulo sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
1685f05cddf9SRui Paulo eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1686f05cddf9SRui Paulo ap_sta_disassoc_cb_timeout(hapd, sta);
1687e28a4053SRui Paulo }
16885b9c547cSRui Paulo
16895b9c547cSRui Paulo
ap_sta_clear_disconnect_timeouts(struct hostapd_data * hapd,struct sta_info * sta)1690780fb4a2SCy Schubert void ap_sta_clear_disconnect_timeouts(struct hostapd_data *hapd,
1691780fb4a2SCy Schubert struct sta_info *sta)
1692780fb4a2SCy Schubert {
1693780fb4a2SCy Schubert if (eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta) > 0)
1694780fb4a2SCy Schubert wpa_printf(MSG_DEBUG,
1695780fb4a2SCy Schubert "%s: Removed ap_sta_deauth_cb_timeout timeout for "
1696780fb4a2SCy Schubert MACSTR,
1697780fb4a2SCy Schubert hapd->conf->iface, MAC2STR(sta->addr));
1698780fb4a2SCy Schubert if (eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta) > 0)
1699780fb4a2SCy Schubert wpa_printf(MSG_DEBUG,
1700780fb4a2SCy Schubert "%s: Removed ap_sta_disassoc_cb_timeout timeout for "
1701780fb4a2SCy Schubert MACSTR,
1702780fb4a2SCy Schubert hapd->conf->iface, MAC2STR(sta->addr));
170385732ac8SCy Schubert if (eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta) > 0)
170485732ac8SCy Schubert {
170585732ac8SCy Schubert wpa_printf(MSG_DEBUG,
170685732ac8SCy Schubert "%s: Removed ap_sta_delayed_1x_auth_fail_cb timeout for "
170785732ac8SCy Schubert MACSTR,
170885732ac8SCy Schubert hapd->conf->iface, MAC2STR(sta->addr));
170985732ac8SCy Schubert if (sta->flags & WLAN_STA_WPS)
171085732ac8SCy Schubert hostapd_wps_eap_completed(hapd);
171185732ac8SCy Schubert }
1712780fb4a2SCy Schubert }
1713780fb4a2SCy Schubert
1714780fb4a2SCy Schubert
ap_sta_flags_txt(u32 flags,char * buf,size_t buflen)17155b9c547cSRui Paulo int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen)
17165b9c547cSRui Paulo {
17175b9c547cSRui Paulo int res;
17185b9c547cSRui Paulo
17195b9c547cSRui Paulo buf[0] = '\0';
1720c1d255d3SCy Schubert res = os_snprintf(buf, buflen,
1721*a90b9d01SCy Schubert "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
17225b9c547cSRui Paulo (flags & WLAN_STA_AUTH ? "[AUTH]" : ""),
17235b9c547cSRui Paulo (flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""),
17245b9c547cSRui Paulo (flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : ""),
17255b9c547cSRui Paulo (flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
17265b9c547cSRui Paulo ""),
17275b9c547cSRui Paulo (flags & WLAN_STA_SHORT_PREAMBLE ?
17285b9c547cSRui Paulo "[SHORT_PREAMBLE]" : ""),
17295b9c547cSRui Paulo (flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
17305b9c547cSRui Paulo (flags & WLAN_STA_WMM ? "[WMM]" : ""),
17315b9c547cSRui Paulo (flags & WLAN_STA_MFP ? "[MFP]" : ""),
17325b9c547cSRui Paulo (flags & WLAN_STA_WPS ? "[WPS]" : ""),
17335b9c547cSRui Paulo (flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""),
17345b9c547cSRui Paulo (flags & WLAN_STA_WDS ? "[WDS]" : ""),
17355b9c547cSRui Paulo (flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
17365b9c547cSRui Paulo (flags & WLAN_STA_WPS2 ? "[WPS2]" : ""),
17375b9c547cSRui Paulo (flags & WLAN_STA_GAS ? "[GAS]" : ""),
173885732ac8SCy Schubert (flags & WLAN_STA_HT ? "[HT]" : ""),
17395b9c547cSRui Paulo (flags & WLAN_STA_VHT ? "[VHT]" : ""),
1740c1d255d3SCy Schubert (flags & WLAN_STA_HE ? "[HE]" : ""),
1741*a90b9d01SCy Schubert (flags & WLAN_STA_EHT ? "[EHT]" : ""),
1742c1d255d3SCy Schubert (flags & WLAN_STA_6GHZ ? "[6GHZ]" : ""),
17435b9c547cSRui Paulo (flags & WLAN_STA_VENDOR_VHT ? "[VENDOR_VHT]" : ""),
17445b9c547cSRui Paulo (flags & WLAN_STA_WNM_SLEEP_MODE ?
17455b9c547cSRui Paulo "[WNM_SLEEP_MODE]" : ""));
17465b9c547cSRui Paulo if (os_snprintf_error(buflen, res))
17475b9c547cSRui Paulo res = -1;
17485b9c547cSRui Paulo
17495b9c547cSRui Paulo return res;
17505b9c547cSRui Paulo }
175185732ac8SCy Schubert
175285732ac8SCy Schubert
ap_sta_delayed_1x_auth_fail_cb(void * eloop_ctx,void * timeout_ctx)175385732ac8SCy Schubert static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx)
175485732ac8SCy Schubert {
175585732ac8SCy Schubert struct hostapd_data *hapd = eloop_ctx;
175685732ac8SCy Schubert struct sta_info *sta = timeout_ctx;
175785732ac8SCy Schubert u16 reason;
175885732ac8SCy Schubert
175985732ac8SCy Schubert wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
176085732ac8SCy Schubert "IEEE 802.1X: Scheduled disconnection of " MACSTR
176185732ac8SCy Schubert " after EAP-Failure", MAC2STR(sta->addr));
176285732ac8SCy Schubert
176385732ac8SCy Schubert reason = sta->disconnect_reason_code;
176485732ac8SCy Schubert if (!reason)
176585732ac8SCy Schubert reason = WLAN_REASON_IEEE_802_1X_AUTH_FAILED;
176685732ac8SCy Schubert ap_sta_disconnect(hapd, sta, sta->addr, reason);
176785732ac8SCy Schubert if (sta->flags & WLAN_STA_WPS)
176885732ac8SCy Schubert hostapd_wps_eap_completed(hapd);
176985732ac8SCy Schubert }
177085732ac8SCy Schubert
177185732ac8SCy Schubert
ap_sta_delayed_1x_auth_fail_disconnect(struct hostapd_data * hapd,struct sta_info * sta,unsigned timeout)177285732ac8SCy Schubert void ap_sta_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1773*a90b9d01SCy Schubert struct sta_info *sta,
1774*a90b9d01SCy Schubert unsigned timeout)
177585732ac8SCy Schubert {
177685732ac8SCy Schubert wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
177785732ac8SCy Schubert "IEEE 802.1X: Force disconnection of " MACSTR
1778*a90b9d01SCy Schubert " after EAP-Failure in %u ms", MAC2STR(sta->addr), timeout);
177985732ac8SCy Schubert
178085732ac8SCy Schubert /*
178185732ac8SCy Schubert * Add a small sleep to increase likelihood of previously requested
178285732ac8SCy Schubert * EAP-Failure TX getting out before this should the driver reorder
178385732ac8SCy Schubert * operations.
178485732ac8SCy Schubert */
178585732ac8SCy Schubert eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta);
1786*a90b9d01SCy Schubert eloop_register_timeout(0, timeout * 1000,
1787*a90b9d01SCy Schubert ap_sta_delayed_1x_auth_fail_cb, hapd, sta);
178885732ac8SCy Schubert }
178985732ac8SCy Schubert
179085732ac8SCy Schubert
ap_sta_pending_delayed_1x_auth_fail_disconnect(struct hostapd_data * hapd,struct sta_info * sta)179185732ac8SCy Schubert int ap_sta_pending_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
179285732ac8SCy Schubert struct sta_info *sta)
179385732ac8SCy Schubert {
179485732ac8SCy Schubert return eloop_is_timeout_registered(ap_sta_delayed_1x_auth_fail_cb,
179585732ac8SCy Schubert hapd, sta);
179685732ac8SCy Schubert }
1797c1d255d3SCy Schubert
1798c1d255d3SCy Schubert
1799*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
ap_sta_remove_link_sta(struct hostapd_data * hapd,struct sta_info * sta)1800*a90b9d01SCy Schubert static void ap_sta_remove_link_sta(struct hostapd_data *hapd,
1801*a90b9d01SCy Schubert struct sta_info *sta)
1802*a90b9d01SCy Schubert {
1803*a90b9d01SCy Schubert struct hostapd_data *tmp_hapd;
1804*a90b9d01SCy Schubert
1805*a90b9d01SCy Schubert for_each_mld_link(tmp_hapd, hapd) {
1806*a90b9d01SCy Schubert struct sta_info *tmp_sta;
1807*a90b9d01SCy Schubert
1808*a90b9d01SCy Schubert if (hapd == tmp_hapd)
1809*a90b9d01SCy Schubert continue;
1810*a90b9d01SCy Schubert
1811*a90b9d01SCy Schubert for (tmp_sta = tmp_hapd->sta_list; tmp_sta;
1812*a90b9d01SCy Schubert tmp_sta = tmp_sta->next) {
1813*a90b9d01SCy Schubert if (tmp_sta == sta ||
1814*a90b9d01SCy Schubert !ether_addr_equal(tmp_sta->addr, sta->addr))
1815*a90b9d01SCy Schubert continue;
1816*a90b9d01SCy Schubert
1817*a90b9d01SCy Schubert ap_free_sta(tmp_hapd, tmp_sta);
1818*a90b9d01SCy Schubert break;
1819*a90b9d01SCy Schubert }
1820*a90b9d01SCy Schubert }
1821*a90b9d01SCy Schubert }
1822*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1823*a90b9d01SCy Schubert
1824*a90b9d01SCy Schubert
ap_sta_re_add(struct hostapd_data * hapd,struct sta_info * sta)1825c1d255d3SCy Schubert int ap_sta_re_add(struct hostapd_data *hapd, struct sta_info *sta)
1826c1d255d3SCy Schubert {
1827*a90b9d01SCy Schubert const u8 *mld_link_addr = NULL;
1828*a90b9d01SCy Schubert bool mld_link_sta = false;
1829*a90b9d01SCy Schubert
1830c1d255d3SCy Schubert /*
1831c1d255d3SCy Schubert * If a station that is already associated to the AP, is trying to
1832c1d255d3SCy Schubert * authenticate again, remove the STA entry, in order to make sure the
1833c1d255d3SCy Schubert * STA PS state gets cleared and configuration gets updated. To handle
1834c1d255d3SCy Schubert * this, station's added_unassoc flag is cleared once the station has
1835c1d255d3SCy Schubert * completed association.
1836c1d255d3SCy Schubert */
1837*a90b9d01SCy Schubert
1838*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1839*a90b9d01SCy Schubert if (ap_sta_is_mld(hapd, sta)) {
1840*a90b9d01SCy Schubert u8 mld_link_id = hapd->mld_link_id;
1841*a90b9d01SCy Schubert
1842*a90b9d01SCy Schubert mld_link_sta = sta->mld_assoc_link_id != mld_link_id;
1843*a90b9d01SCy Schubert mld_link_addr = sta->mld_info.links[mld_link_id].peer_addr;
1844*a90b9d01SCy Schubert
1845*a90b9d01SCy Schubert /*
1846*a90b9d01SCy Schubert * In case the AP is affiliated with an AP MLD, we need to
1847*a90b9d01SCy Schubert * remove the station from all relevant links/APs.
1848*a90b9d01SCy Schubert */
1849*a90b9d01SCy Schubert ap_sta_remove_link_sta(hapd, sta);
1850*a90b9d01SCy Schubert }
1851*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1852*a90b9d01SCy Schubert
1853c1d255d3SCy Schubert ap_sta_set_authorized(hapd, sta, 0);
1854c1d255d3SCy Schubert hostapd_drv_sta_remove(hapd, sta->addr);
1855c1d255d3SCy Schubert sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH | WLAN_STA_AUTHORIZED);
1856c1d255d3SCy Schubert
1857c1d255d3SCy Schubert if (hostapd_sta_add(hapd, sta->addr, 0, 0,
1858c1d255d3SCy Schubert sta->supported_rates,
1859c1d255d3SCy Schubert sta->supported_rates_len,
1860*a90b9d01SCy Schubert 0, NULL, NULL, NULL, 0, NULL, 0, NULL,
1861*a90b9d01SCy Schubert sta->flags, 0, 0, 0, 0,
1862*a90b9d01SCy Schubert mld_link_addr, mld_link_sta)) {
1863c1d255d3SCy Schubert hostapd_logger(hapd, sta->addr,
1864c1d255d3SCy Schubert HOSTAPD_MODULE_IEEE80211,
1865c1d255d3SCy Schubert HOSTAPD_LEVEL_NOTICE,
1866c1d255d3SCy Schubert "Could not add STA to kernel driver");
1867c1d255d3SCy Schubert return -1;
1868c1d255d3SCy Schubert }
1869c1d255d3SCy Schubert
1870c1d255d3SCy Schubert sta->added_unassoc = 1;
1871c1d255d3SCy Schubert return 0;
1872c1d255d3SCy Schubert }
1873*a90b9d01SCy Schubert
1874*a90b9d01SCy Schubert
1875*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
ap_sta_free_sta_profile(struct mld_info * info)1876*a90b9d01SCy Schubert void ap_sta_free_sta_profile(struct mld_info *info)
1877*a90b9d01SCy Schubert {
1878*a90b9d01SCy Schubert int i;
1879*a90b9d01SCy Schubert
1880*a90b9d01SCy Schubert if (!info)
1881*a90b9d01SCy Schubert return;
1882*a90b9d01SCy Schubert
1883*a90b9d01SCy Schubert for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
1884*a90b9d01SCy Schubert os_free(info->links[i].resp_sta_profile);
1885*a90b9d01SCy Schubert info->links[i].resp_sta_profile = NULL;
1886*a90b9d01SCy Schubert }
1887*a90b9d01SCy Schubert }
1888*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
1889