blob: cbb8752ea681cfff67f358cc3126d31389da8153 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Station table
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003 * Copyright (c) 2002-2017, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "utils/eloop.h"
13#include "common/ieee802_11_defs.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014#include "common/wpa_ctrl.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080015#include "common/sae.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070016#include "common/dpp.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070017#include "radius/radius.h"
18#include "radius/radius_client.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080020#include "fst/fst.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070021#include "crypto/crypto.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include "hostapd.h"
23#include "accounting.h"
24#include "ieee802_1x.h"
25#include "ieee802_11.h"
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080026#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "wpa_auth.h"
28#include "preauth_auth.h"
29#include "ap_config.h"
30#include "beacon.h"
31#include "ap_mlme.h"
32#include "vlan_init.h"
33#include "p2p_hostapd.h"
34#include "ap_drv_ops.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070035#include "gas_serv.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080036#include "wnm_ap.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080037#include "mbo_ap.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080038#include "ndisc_snoop.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070039#include "sta_info.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080040#include "vlan.h"
Dmitry Shmidt29333592017-01-09 12:27:11 -080041#include "wps_hostapd.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042
43static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
44 struct sta_info *sta);
45static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080046static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080047static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
48static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070049static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080050static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
Dmitry Shmidt29333592017-01-09 12:27:11 -080051static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070052
53int ap_for_each_sta(struct hostapd_data *hapd,
54 int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
55 void *ctx),
56 void *ctx)
57{
58 struct sta_info *sta;
59
60 for (sta = hapd->sta_list; sta; sta = sta->next) {
61 if (cb(hapd, sta, ctx))
62 return 1;
63 }
64
65 return 0;
66}
67
68
69struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
70{
71 struct sta_info *s;
72
73 s = hapd->sta_hash[STA_HASH(sta)];
74 while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
75 s = s->hnext;
76 return s;
77}
78
79
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070080#ifdef CONFIG_P2P
81struct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr)
82{
83 struct sta_info *sta;
84
85 for (sta = hapd->sta_list; sta; sta = sta->next) {
86 const u8 *p2p_dev_addr;
87
88 if (sta->p2p_ie == NULL)
89 continue;
90
91 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
92 if (p2p_dev_addr == NULL)
93 continue;
94
95 if (os_memcmp(p2p_dev_addr, addr, ETH_ALEN) == 0)
96 return sta;
97 }
98
99 return NULL;
100}
101#endif /* CONFIG_P2P */
102
103
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
105{
106 struct sta_info *tmp;
107
108 if (hapd->sta_list == sta) {
109 hapd->sta_list = sta->next;
110 return;
111 }
112
113 tmp = hapd->sta_list;
114 while (tmp != NULL && tmp->next != sta)
115 tmp = tmp->next;
116 if (tmp == NULL) {
117 wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
118 "list.", MAC2STR(sta->addr));
119 } else
120 tmp->next = sta->next;
121}
122
123
124void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
125{
126 sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
127 hapd->sta_hash[STA_HASH(sta->addr)] = sta;
128}
129
130
131static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
132{
133 struct sta_info *s;
134
135 s = hapd->sta_hash[STA_HASH(sta->addr)];
136 if (s == NULL) return;
137 if (os_memcmp(s->addr, sta->addr, 6) == 0) {
138 hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
139 return;
140 }
141
142 while (s->hnext != NULL &&
143 os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
144 s = s->hnext;
145 if (s->hnext != NULL)
146 s->hnext = s->hnext->hnext;
147 else
148 wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
149 " from hash table", MAC2STR(sta->addr));
150}
151
152
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800153void ap_sta_ip6addr_del(struct hostapd_data *hapd, struct sta_info *sta)
154{
155 sta_ip6addr_del(hapd, sta);
156}
157
158
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
160{
161 int set_beacon = 0;
162
163 accounting_sta_stop(hapd, sta);
164
165 /* just in case */
166 ap_sta_set_authorized(hapd, sta, 0);
167
Hai Shalom74f70d42019-02-11 14:42:39 -0800168 if (sta->flags & (WLAN_STA_WDS | WLAN_STA_MULTI_AP))
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700169 hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700170
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800171 if (sta->ipaddr)
172 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
173 ap_sta_ip6addr_del(hapd, sta);
174
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800175 if (!hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800176 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700177 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800178 sta->added_unassoc = 0;
179 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180
181 ap_sta_hash_del(hapd, sta);
182 ap_sta_list_del(hapd, sta);
183
184 if (sta->aid > 0)
185 hapd->sta_aid[(sta->aid - 1) / 32] &=
186 ~BIT((sta->aid - 1) % 32);
187
188 hapd->num_sta--;
189 if (sta->nonerp_set) {
190 sta->nonerp_set = 0;
191 hapd->iface->num_sta_non_erp--;
192 if (hapd->iface->num_sta_non_erp == 0)
193 set_beacon++;
194 }
195
196 if (sta->no_short_slot_time_set) {
197 sta->no_short_slot_time_set = 0;
198 hapd->iface->num_sta_no_short_slot_time--;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700199 if (hapd->iface->current_mode &&
200 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700201 && hapd->iface->num_sta_no_short_slot_time == 0)
202 set_beacon++;
203 }
204
205 if (sta->no_short_preamble_set) {
206 sta->no_short_preamble_set = 0;
207 hapd->iface->num_sta_no_short_preamble--;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700208 if (hapd->iface->current_mode &&
209 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700210 && hapd->iface->num_sta_no_short_preamble == 0)
211 set_beacon++;
212 }
213
214 if (sta->no_ht_gf_set) {
215 sta->no_ht_gf_set = 0;
216 hapd->iface->num_sta_ht_no_gf--;
217 }
218
219 if (sta->no_ht_set) {
220 sta->no_ht_set = 0;
221 hapd->iface->num_sta_no_ht--;
222 }
223
224 if (sta->ht_20mhz_set) {
225 sta->ht_20mhz_set = 0;
226 hapd->iface->num_sta_ht_20mhz--;
227 }
228
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700229#ifdef CONFIG_TAXONOMY
230 wpabuf_free(sta->probe_ie_taxonomy);
231 sta->probe_ie_taxonomy = NULL;
232 wpabuf_free(sta->assoc_ie_taxonomy);
233 sta->assoc_ie_taxonomy = NULL;
234#endif /* CONFIG_TAXONOMY */
235
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700236#ifdef CONFIG_IEEE80211N
237 ht40_intolerant_remove(hapd->iface, sta);
238#endif /* CONFIG_IEEE80211N */
239
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700240#ifdef CONFIG_P2P
241 if (sta->no_p2p_set) {
242 sta->no_p2p_set = 0;
243 hapd->num_sta_no_p2p--;
244 if (hapd->num_sta_no_p2p == 0)
245 hostapd_p2p_non_p2p_sta_disconnected(hapd);
246 }
247#endif /* CONFIG_P2P */
248
249#if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
250 if (hostapd_ht_operation_update(hapd->iface) > 0)
251 set_beacon++;
252#endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
253
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800254#ifdef CONFIG_MESH
255 if (hapd->mesh_sta_free_cb)
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800256 hapd->mesh_sta_free_cb(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800257#endif /* CONFIG_MESH */
258
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700259 if (set_beacon)
260 ieee802_11_set_beacons(hapd->iface);
261
Dmitry Shmidt04949592012-07-19 12:16:46 -0700262 wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
263 __func__, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700264 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
265 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800266 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800267 ap_sta_clear_disconnect_timeouts(hapd, sta);
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800268 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700269
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800270 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271 wpa_auth_sta_deinit(sta->wpa_sm);
272 rsn_preauth_free_station(hapd, sta);
273#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt96571392013-10-14 12:54:46 -0700274 if (hapd->radius)
275 radius_client_flush_auth(hapd->radius, sta->addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700276#endif /* CONFIG_NO_RADIUS */
277
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800278#ifndef CONFIG_NO_VLAN
279 /*
280 * sta->wpa_sm->group needs to be released before so that
281 * vlan_remove_dynamic() can check that no stations are left on the
282 * AP_VLAN netdev.
283 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800284 if (sta->vlan_id)
285 vlan_remove_dynamic(hapd, sta->vlan_id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800286 if (sta->vlan_id_bound) {
287 /*
288 * Need to remove the STA entry before potentially removing the
289 * VLAN.
290 */
291 if (hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800292 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800293 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800294 sta->added_unassoc = 0;
295 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800296 vlan_remove_dynamic(hapd, sta->vlan_id_bound);
297 }
298#endif /* CONFIG_NO_VLAN */
299
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700300 os_free(sta->challenge);
301
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700302 os_free(sta->sa_query_trans_id);
303 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304
305#ifdef CONFIG_P2P
306 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
307#endif /* CONFIG_P2P */
308
Dmitry Shmidt04949592012-07-19 12:16:46 -0700309#ifdef CONFIG_INTERWORKING
310 if (sta->gas_dialog) {
311 int i;
312 for (i = 0; i < GAS_DIALOG_MAX; i++)
313 gas_serv_dialog_clear(&sta->gas_dialog[i]);
314 os_free(sta->gas_dialog);
315 }
316#endif /* CONFIG_INTERWORKING */
317
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700318 wpabuf_free(sta->wps_ie);
319 wpabuf_free(sta->p2p_ie);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800320 wpabuf_free(sta->hs20_ie);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700321 wpabuf_free(sta->roaming_consortium);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800322#ifdef CONFIG_FST
323 wpabuf_free(sta->mb_ies);
324#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700325
326 os_free(sta->ht_capabilities);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -0800327 os_free(sta->vht_capabilities);
Hai Shalom74f70d42019-02-11 14:42:39 -0800328 os_free(sta->vht_operation);
Hai Shalom81f62d82019-07-22 12:10:00 -0700329 os_free(sta->he_capab);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800330 hostapd_free_psk_list(sta->psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700331 os_free(sta->identity);
332 os_free(sta->radius_cui);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800333 os_free(sta->remediation_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700334 os_free(sta->t_c_url);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800335 wpabuf_free(sta->hs20_deauth_req);
336 os_free(sta->hs20_session_info_url);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700337
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800338#ifdef CONFIG_SAE
339 sae_clear_data(sta->sae);
340 os_free(sta->sae);
341#endif /* CONFIG_SAE */
342
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800343 mbo_ap_sta_free(sta);
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800344 os_free(sta->supp_op_classes);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800345
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800346#ifdef CONFIG_FILS
347 os_free(sta->fils_pending_assoc_req);
348 wpabuf_free(sta->fils_hlp_resp);
349 wpabuf_free(sta->hlp_dhcp_discover);
350 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700351#ifdef CONFIG_FILS_SK_PFS
352 crypto_ecdh_deinit(sta->fils_ecdh);
353 wpabuf_clear_free(sta->fils_dh_ss);
354 wpabuf_free(sta->fils_g_sta);
355#endif /* CONFIG_FILS_SK_PFS */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800356#endif /* CONFIG_FILS */
357
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700358#ifdef CONFIG_OWE
359 bin_clear_free(sta->owe_pmk, sta->owe_pmk_len);
360 crypto_ecdh_deinit(sta->owe_ecdh);
361#endif /* CONFIG_OWE */
362
Hai Shalom021b0b52019-04-10 11:17:58 -0700363#ifdef CONFIG_DPP2
364 dpp_pfs_free(sta->dpp_pfs);
365 sta->dpp_pfs = NULL;
366#endif /* CONFIG_DPP2 */
367
Roshan Pius3a1667e2018-07-03 15:17:14 -0700368 os_free(sta->ext_capability);
369
370#ifdef CONFIG_WNM_AP
371 eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta);
372#endif /* CONFIG_WNM_AP */
373
374 os_free(sta->ifname_wds);
375
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700376 os_free(sta);
377}
378
379
380void hostapd_free_stas(struct hostapd_data *hapd)
381{
382 struct sta_info *sta, *prev;
383
384 sta = hapd->sta_list;
385
386 while (sta) {
387 prev = sta;
388 if (sta->flags & WLAN_STA_AUTH) {
389 mlme_deauthenticate_indication(
390 hapd, sta, WLAN_REASON_UNSPECIFIED);
391 }
392 sta = sta->next;
393 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
394 MAC2STR(prev->addr));
395 ap_free_sta(hapd, prev);
396 }
397}
398
399
400/**
401 * ap_handle_timer - Per STA timer handler
402 * @eloop_ctx: struct hostapd_data *
403 * @timeout_ctx: struct sta_info *
404 *
405 * This function is called to check station activity and to remove inactive
406 * stations.
407 */
408void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
409{
410 struct hostapd_data *hapd = eloop_ctx;
411 struct sta_info *sta = timeout_ctx;
412 unsigned long next_time = 0;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700413 int reason;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700414
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800415 wpa_printf(MSG_DEBUG, "%s: %s: " MACSTR " flags=0x%x timeout_next=%d",
416 hapd->conf->iface, __func__, MAC2STR(sta->addr), sta->flags,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700417 sta->timeout_next);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700418 if (sta->timeout_next == STA_REMOVE) {
419 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
420 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
421 "local deauth request");
422 ap_free_sta(hapd, sta);
423 return;
424 }
425
426 if ((sta->flags & WLAN_STA_ASSOC) &&
427 (sta->timeout_next == STA_NULLFUNC ||
428 sta->timeout_next == STA_DISASSOC)) {
429 int inactive_sec;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700430 /*
431 * Add random value to timeout so that we don't end up bouncing
432 * all stations at the same time if we have lots of associated
433 * stations that are idle (but keep re-associating).
434 */
435 int fuzz = os_random() % 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700436 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
437 if (inactive_sec == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800438 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
439 "Check inactivity: Could not "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800440 "get station info from kernel driver for "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700441 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800442 /*
443 * The driver may not support this functionality.
444 * Anyway, try again after the next inactivity timeout,
445 * but do not disconnect the station now.
446 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700447 next_time = hapd->conf->ap_max_inactivity + fuzz;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800448 } else if (inactive_sec == -ENOENT) {
449 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
450 "Station " MACSTR " has lost its driver entry",
451 MAC2STR(sta->addr));
452
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800453 /* Avoid sending client probe on removed client */
454 sta->timeout_next = STA_DISASSOC;
455 goto skip_poll;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800456 } else if (inactive_sec < hapd->conf->ap_max_inactivity) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 /* station activity detected; reset timeout state */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800458 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
459 "Station " MACSTR " has been active %is ago",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700460 MAC2STR(sta->addr), inactive_sec);
461 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700462 next_time = hapd->conf->ap_max_inactivity + fuzz -
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700463 inactive_sec;
464 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800465 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
466 "Station " MACSTR " has been "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700467 "inactive too long: %d sec, max allowed: %d",
468 MAC2STR(sta->addr), inactive_sec,
469 hapd->conf->ap_max_inactivity);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800470
471 if (hapd->conf->skip_inactivity_poll)
472 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700473 }
474 }
475
476 if ((sta->flags & WLAN_STA_ASSOC) &&
477 sta->timeout_next == STA_DISASSOC &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800478 !(sta->flags & WLAN_STA_PENDING_POLL) &&
479 !hapd->conf->skip_inactivity_poll) {
480 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
481 " has ACKed data poll", MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700482 /* data nullfunc frame poll did not produce TX errors; assume
483 * station ACKed it */
484 sta->timeout_next = STA_NULLFUNC;
485 next_time = hapd->conf->ap_max_inactivity;
486 }
487
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800488skip_poll:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700489 if (next_time) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700490 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
491 "for " MACSTR " (%lu seconds)",
492 __func__, MAC2STR(sta->addr), next_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700493 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
494 sta);
495 return;
496 }
497
498 if (sta->timeout_next == STA_NULLFUNC &&
499 (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800500 wpa_printf(MSG_DEBUG, " Polling STA");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501 sta->flags |= WLAN_STA_PENDING_POLL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800502 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
503 sta->flags & WLAN_STA_WMM);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504 } else if (sta->timeout_next != STA_REMOVE) {
505 int deauth = sta->timeout_next == STA_DEAUTH;
506
Hai Shalom74f70d42019-02-11 14:42:39 -0800507 if (!deauth && !(sta->flags & WLAN_STA_ASSOC)) {
508 /* Cannot disassociate not-associated STA, so move
509 * directly to deauthentication. */
510 sta->timeout_next = STA_DEAUTH;
511 deauth = 1;
512 }
513
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800514 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
515 "Timeout, sending %s info to STA " MACSTR,
516 deauth ? "deauthentication" : "disassociation",
517 MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518
519 if (deauth) {
520 hostapd_drv_sta_deauth(
521 hapd, sta->addr,
522 WLAN_REASON_PREV_AUTH_NOT_VALID);
523 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700524 reason = (sta->timeout_next == STA_DISASSOC) ?
525 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
526 WLAN_REASON_PREV_AUTH_NOT_VALID;
527
528 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529 }
530 }
531
532 switch (sta->timeout_next) {
533 case STA_NULLFUNC:
534 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700535 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
536 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
537 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700538 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
539 hapd, sta);
540 break;
541 case STA_DISASSOC:
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700542 case STA_DISASSOC_FROM_CLI:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800543 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700544 sta->flags &= ~WLAN_STA_ASSOC;
545 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
546 if (!sta->acct_terminate_cause)
547 sta->acct_terminate_cause =
548 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
549 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800550 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700551 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
552 HOSTAPD_LEVEL_INFO, "disassociated due to "
553 "inactivity");
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700554 reason = (sta->timeout_next == STA_DISASSOC) ?
555 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
556 WLAN_REASON_PREV_AUTH_NOT_VALID;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700557 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700558 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
559 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
560 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700561 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
562 hapd, sta);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700563 mlme_disassociate_indication(hapd, sta, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700564 break;
565 case STA_DEAUTH:
566 case STA_REMOVE:
567 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
568 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800569 "inactivity (timer DEAUTH/REMOVE)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700570 if (!sta->acct_terminate_cause)
571 sta->acct_terminate_cause =
572 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
573 mlme_deauthenticate_indication(
574 hapd, sta,
575 WLAN_REASON_PREV_AUTH_NOT_VALID);
576 ap_free_sta(hapd, sta);
577 break;
578 }
579}
580
581
582static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
583{
584 struct hostapd_data *hapd = eloop_ctx;
585 struct sta_info *sta = timeout_ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700586
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800587 wpa_printf(MSG_DEBUG, "%s: Session timer for STA " MACSTR,
588 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700589 if (!(sta->flags & WLAN_STA_AUTH)) {
590 if (sta->flags & WLAN_STA_GAS) {
591 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
592 "entry " MACSTR, MAC2STR(sta->addr));
593 ap_free_sta(hapd, sta);
594 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700595 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700596 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700597
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700598 hostapd_drv_sta_deauth(hapd, sta->addr,
599 WLAN_REASON_PREV_AUTH_NOT_VALID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700600 mlme_deauthenticate_indication(hapd, sta,
601 WLAN_REASON_PREV_AUTH_NOT_VALID);
602 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
603 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
604 "session timeout");
605 sta->acct_terminate_cause =
606 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700607 ap_free_sta(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700608}
609
610
Dmitry Shmidt54605472013-11-08 11:10:19 -0800611void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta,
612 u32 session_timeout)
613{
614 if (eloop_replenish_timeout(session_timeout, 0,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800615 ap_handle_session_timer, hapd, sta) == 1) {
Dmitry Shmidt54605472013-11-08 11:10:19 -0800616 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
617 HOSTAPD_LEVEL_DEBUG, "setting session timeout "
618 "to %d seconds", session_timeout);
619 }
620}
621
622
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700623void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
624 u32 session_timeout)
625{
626 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
627 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
628 "seconds", session_timeout);
629 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
630 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
631 hapd, sta);
632}
633
634
635void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
636{
637 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
638}
639
640
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800641static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx)
642{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700643#ifdef CONFIG_WNM_AP
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800644 struct hostapd_data *hapd = eloop_ctx;
645 struct sta_info *sta = timeout_ctx;
646
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800647 wpa_printf(MSG_DEBUG, "%s: WNM: Session warning time reached for "
648 MACSTR, hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800649 if (sta->hs20_session_info_url == NULL)
650 return;
651
652 wnm_send_ess_disassoc_imminent(hapd, sta, sta->hs20_session_info_url,
653 sta->hs20_disassoc_timer);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700654#endif /* CONFIG_WNM_AP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800655}
656
657
658void ap_sta_session_warning_timeout(struct hostapd_data *hapd,
659 struct sta_info *sta, int warning_time)
660{
661 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
662 eloop_register_timeout(warning_time, 0, ap_handle_session_warning_timer,
663 hapd, sta);
664}
665
666
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700667struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
668{
669 struct sta_info *sta;
Hai Shalom81f62d82019-07-22 12:10:00 -0700670 int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700671
672 sta = ap_get_sta(hapd, addr);
673 if (sta)
674 return sta;
675
676 wpa_printf(MSG_DEBUG, " New STA");
677 if (hapd->num_sta >= hapd->conf->max_num_sta) {
678 /* FIX: might try to remove some old STAs first? */
679 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
680 hapd->num_sta, hapd->conf->max_num_sta);
681 return NULL;
682 }
683
684 sta = os_zalloc(sizeof(struct sta_info));
685 if (sta == NULL) {
686 wpa_printf(MSG_ERROR, "malloc failed");
687 return NULL;
688 }
689 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800690 if (accounting_sta_get_id(hapd, sta) < 0) {
691 os_free(sta);
692 return NULL;
693 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700694
Hai Shalom81f62d82019-07-22 12:10:00 -0700695 for (i = 0; i < WLAN_SUPP_RATES_MAX; i++) {
696 if (!hapd->iface->basic_rates)
697 break;
698 if (hapd->iface->basic_rates[i] < 0)
699 break;
700 sta->supported_rates[i] = hapd->iface->basic_rates[i] / 5;
701 }
702 sta->supported_rates_len = i;
703
Dmitry Shmidt01904cf2013-12-05 11:08:35 -0800704 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
705 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
706 "for " MACSTR " (%d seconds - ap_max_inactivity)",
707 __func__, MAC2STR(addr),
708 hapd->conf->ap_max_inactivity);
709 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
710 ap_handle_timer, hapd, sta);
711 }
712
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700713 /* initialize STA info data */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700714 os_memcpy(sta->addr, addr, ETH_ALEN);
715 sta->next = hapd->sta_list;
716 hapd->sta_list = sta;
717 hapd->num_sta++;
718 ap_sta_hash_add(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700719 ap_sta_remove_in_other_bss(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800720 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
721 dl_list_init(&sta->ip6addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700722
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700723#ifdef CONFIG_TAXONOMY
724 sta_track_claim_taxonomy_info(hapd->iface, addr,
725 &sta->probe_ie_taxonomy);
726#endif /* CONFIG_TAXONOMY */
727
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700728 return sta;
729}
730
731
732static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
733{
734 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
735
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800736 if (sta->ipaddr)
737 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
738 ap_sta_ip6addr_del(hapd, sta);
739
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800740 wpa_printf(MSG_DEBUG, "%s: Removing STA " MACSTR " from kernel driver",
741 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700742 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
743 sta->flags & WLAN_STA_ASSOC) {
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800744 wpa_printf(MSG_DEBUG, "%s: Could not remove station " MACSTR
745 " from kernel driver",
746 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700747 return -1;
748 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800749 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700750 return 0;
751}
752
753
754static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
755 struct sta_info *sta)
756{
757 struct hostapd_iface *iface = hapd->iface;
758 size_t i;
759
760 for (i = 0; i < iface->num_bss; i++) {
761 struct hostapd_data *bss = iface->bss[i];
762 struct sta_info *sta2;
763 /* bss should always be set during operation, but it may be
764 * NULL during reconfiguration. Assume the STA is not
765 * associated to another BSS in that case to avoid NULL pointer
766 * dereferences. */
767 if (bss == hapd || bss == NULL)
768 continue;
769 sta2 = ap_get_sta(bss, sta->addr);
770 if (!sta2)
771 continue;
772
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800773 wpa_printf(MSG_DEBUG, "%s: disconnect old STA " MACSTR
774 " association from another BSS %s",
775 hapd->conf->iface, MAC2STR(sta2->addr),
776 bss->conf->iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700777 ap_sta_disconnect(bss, sta2, sta2->addr,
778 WLAN_REASON_PREV_AUTH_NOT_VALID);
779 }
780}
781
782
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800783static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
784{
785 struct hostapd_data *hapd = eloop_ctx;
786 struct sta_info *sta = timeout_ctx;
787
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800788 wpa_printf(MSG_DEBUG, "%s: Disassociation callback for STA " MACSTR,
789 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800790 ap_sta_remove(hapd, sta);
791 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
792}
793
794
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700795void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
796 u16 reason)
797{
798 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
799 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800800 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800801 if (hapd->iface->current_mode &&
802 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
803 /* Skip deauthentication in DMG/IEEE 802.11ad */
804 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
805 WLAN_STA_ASSOC_REQ_OK);
806 sta->timeout_next = STA_REMOVE;
807 } else {
808 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
809 sta->timeout_next = STA_DEAUTH;
810 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800811 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700812 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
813 "for " MACSTR " (%d seconds - "
814 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
815 __func__, MAC2STR(sta->addr),
816 AP_MAX_INACTIVITY_AFTER_DISASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
818 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
819 ap_handle_timer, hapd, sta);
820 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800821 ieee802_1x_free_station(hapd, sta);
Hai Shalom81f62d82019-07-22 12:10:00 -0700822 wpa_auth_sta_deinit(sta->wpa_sm);
823 sta->wpa_sm = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700824
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800825 sta->disassoc_reason = reason;
826 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
827 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
828 eloop_register_timeout(hapd->iface->drv_flags &
829 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
830 ap_sta_disassoc_cb_timeout, hapd, sta);
831}
832
833
834static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
835{
836 struct hostapd_data *hapd = eloop_ctx;
837 struct sta_info *sta = timeout_ctx;
838
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800839 wpa_printf(MSG_DEBUG, "%s: Deauthentication callback for STA " MACSTR,
840 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800841 ap_sta_remove(hapd, sta);
842 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700843}
844
845
846void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
847 u16 reason)
848{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800849 if (hapd->iface->current_mode &&
850 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
851 /* Deauthentication is not used in DMG/IEEE 802.11ad;
852 * disassociate the STA instead. */
853 ap_sta_disassociate(hapd, sta, reason);
854 return;
855 }
856
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700857 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
858 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800859 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
860 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800861 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700863 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
864 "for " MACSTR " (%d seconds - "
865 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
866 __func__, MAC2STR(sta->addr),
867 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700868 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
869 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
870 ap_handle_timer, hapd, sta);
871 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800872 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700873
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800874 sta->deauth_reason = reason;
875 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
876 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
877 eloop_register_timeout(hapd->iface->drv_flags &
878 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
879 ap_sta_deauth_cb_timeout, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880}
881
882
Dmitry Shmidt04949592012-07-19 12:16:46 -0700883#ifdef CONFIG_WPS
884int ap_sta_wps_cancel(struct hostapd_data *hapd,
885 struct sta_info *sta, void *ctx)
886{
887 if (sta && (sta->flags & WLAN_STA_WPS)) {
888 ap_sta_deauthenticate(hapd, sta,
889 WLAN_REASON_PREV_AUTH_NOT_VALID);
890 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
891 __func__, MAC2STR(sta->addr));
892 return 1;
893 }
894
895 return 0;
896}
897#endif /* CONFIG_WPS */
898
899
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800900static int ap_sta_get_free_vlan_id(struct hostapd_data *hapd)
901{
902 struct hostapd_vlan *vlan;
903 int vlan_id = MAX_VLAN_ID + 2;
904
905retry:
906 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
907 if (vlan->vlan_id == vlan_id) {
908 vlan_id++;
909 goto retry;
910 }
911 }
912 return vlan_id;
913}
914
915
916int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta,
917 struct vlan_description *vlan_desc)
918{
919 struct hostapd_vlan *vlan = NULL, *wildcard_vlan = NULL;
920 int old_vlan_id, vlan_id = 0, ret = 0;
921
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800922 /* Check if there is something to do */
923 if (hapd->conf->ssid.per_sta_vif && !sta->vlan_id) {
924 /* This sta is lacking its own vif */
925 } else if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED &&
926 !hapd->conf->ssid.per_sta_vif && sta->vlan_id) {
927 /* sta->vlan_id needs to be reset */
928 } else if (!vlan_compare(vlan_desc, sta->vlan_desc)) {
929 return 0; /* nothing to change */
930 }
931
932 /* Now the real VLAN changed or the STA just needs its own vif */
933 if (hapd->conf->ssid.per_sta_vif) {
934 /* Assign a new vif, always */
935 /* find a free vlan_id sufficiently big */
936 vlan_id = ap_sta_get_free_vlan_id(hapd);
937 /* Get wildcard VLAN */
938 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
939 if (vlan->vlan_id == VLAN_ID_WILDCARD)
940 break;
941 }
942 if (!vlan) {
943 hostapd_logger(hapd, sta->addr,
944 HOSTAPD_MODULE_IEEE80211,
945 HOSTAPD_LEVEL_DEBUG,
946 "per_sta_vif missing wildcard");
947 vlan_id = 0;
948 ret = -1;
949 goto done;
950 }
951 } else if (vlan_desc && vlan_desc->notempty) {
952 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
953 if (!vlan_compare(&vlan->vlan_desc, vlan_desc))
954 break;
955 if (vlan->vlan_id == VLAN_ID_WILDCARD)
956 wildcard_vlan = vlan;
957 }
958 if (vlan) {
959 vlan_id = vlan->vlan_id;
960 } else if (wildcard_vlan) {
961 vlan = wildcard_vlan;
962 vlan_id = vlan_desc->untagged;
963 if (vlan_desc->tagged[0]) {
964 /* Tagged VLAN configuration */
965 vlan_id = ap_sta_get_free_vlan_id(hapd);
966 }
967 } else {
968 hostapd_logger(hapd, sta->addr,
969 HOSTAPD_MODULE_IEEE80211,
970 HOSTAPD_LEVEL_DEBUG,
971 "missing vlan and wildcard for vlan=%d%s",
972 vlan_desc->untagged,
973 vlan_desc->tagged[0] ? "+" : "");
974 vlan_id = 0;
975 ret = -1;
976 goto done;
977 }
978 }
979
980 if (vlan && vlan->vlan_id == VLAN_ID_WILDCARD) {
981 vlan = vlan_add_dynamic(hapd, vlan, vlan_id, vlan_desc);
982 if (vlan == NULL) {
983 hostapd_logger(hapd, sta->addr,
984 HOSTAPD_MODULE_IEEE80211,
985 HOSTAPD_LEVEL_DEBUG,
986 "could not add dynamic VLAN interface for vlan=%d%s",
987 vlan_desc ? vlan_desc->untagged : -1,
988 (vlan_desc && vlan_desc->tagged[0]) ?
989 "+" : "");
990 vlan_id = 0;
991 ret = -1;
992 goto done;
993 }
994
995 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
996 HOSTAPD_LEVEL_DEBUG,
997 "added new dynamic VLAN interface '%s'",
998 vlan->ifname);
999 } else if (vlan && vlan->dynamic_vlan > 0) {
1000 vlan->dynamic_vlan++;
1001 hostapd_logger(hapd, sta->addr,
1002 HOSTAPD_MODULE_IEEE80211,
1003 HOSTAPD_LEVEL_DEBUG,
1004 "updated existing dynamic VLAN interface '%s'",
1005 vlan->ifname);
1006 }
1007done:
1008 old_vlan_id = sta->vlan_id;
1009 sta->vlan_id = vlan_id;
1010 sta->vlan_desc = vlan ? &vlan->vlan_desc : NULL;
1011
1012 if (vlan_id != old_vlan_id && old_vlan_id)
1013 vlan_remove_dynamic(hapd, old_vlan_id);
1014
1015 return ret;
1016}
1017
1018
Dmitry Shmidt83474442015-04-15 13:47:09 -07001019int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020{
1021#ifndef CONFIG_NO_VLAN
1022 const char *iface;
1023 struct hostapd_vlan *vlan = NULL;
1024 int ret;
Dmitry Shmidt83474442015-04-15 13:47:09 -07001025 int old_vlanid = sta->vlan_id_bound;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001026
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001027 iface = hapd->conf->iface;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001028 if (hapd->conf->ssid.vlan[0])
1029 iface = hapd->conf->ssid.vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001030
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001031 if (sta->vlan_id > 0) {
1032 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001033 if (vlan->vlan_id == sta->vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001035 }
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001036 if (vlan)
1037 iface = vlan->ifname;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001038 }
1039
Dmitry Shmidt83474442015-04-15 13:47:09 -07001040 /*
1041 * Do not increment ref counters if the VLAN ID remains same, but do
1042 * not skip hostapd_drv_set_sta_vlan() as hostapd_drv_sta_remove() might
1043 * have been called before.
1044 */
1045 if (sta->vlan_id == old_vlanid)
1046 goto skip_counting;
1047
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001048 if (sta->vlan_id > 0 && vlan == NULL) {
1049 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1050 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
1051 "binding station to (vlan_id=%d)",
1052 sta->vlan_id);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001053 ret = -1;
1054 goto done;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001055 } else if (vlan && vlan->dynamic_vlan > 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001056 vlan->dynamic_vlan++;
1057 hostapd_logger(hapd, sta->addr,
1058 HOSTAPD_MODULE_IEEE80211,
1059 HOSTAPD_LEVEL_DEBUG,
1060 "updated existing dynamic VLAN interface '%s'",
1061 iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001062 }
1063
Dmitry Shmidt83474442015-04-15 13:47:09 -07001064 /* ref counters have been increased, so mark the station */
1065 sta->vlan_id_bound = sta->vlan_id;
1066
1067skip_counting:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001068 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1069 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
1070 "'%s'", iface);
1071
1072 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
1073 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
1074
1075 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
1076 if (ret < 0) {
1077 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1078 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
1079 "entry to vlan_id=%d", sta->vlan_id);
1080 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001081
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001082 /* During 1x reauth, if the vlan id changes, then remove the old id. */
Dmitry Shmidt83474442015-04-15 13:47:09 -07001083 if (old_vlanid > 0 && old_vlanid != sta->vlan_id)
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001084 vlan_remove_dynamic(hapd, old_vlanid);
Dmitry Shmidt83474442015-04-15 13:47:09 -07001085done:
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001086
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087 return ret;
1088#else /* CONFIG_NO_VLAN */
1089 return 0;
1090#endif /* CONFIG_NO_VLAN */
1091}
1092
1093
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001094int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
1095{
1096 u32 tu;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001097 struct os_reltime now, passed;
1098 os_get_reltime(&now);
1099 os_reltime_sub(&now, &sta->sa_query_start, &passed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001100 tu = (passed.sec * 1000000 + passed.usec) / 1024;
1101 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
1102 hostapd_logger(hapd, sta->addr,
1103 HOSTAPD_MODULE_IEEE80211,
1104 HOSTAPD_LEVEL_DEBUG,
1105 "association SA Query timed out");
1106 sta->sa_query_timed_out = 1;
1107 os_free(sta->sa_query_trans_id);
1108 sta->sa_query_trans_id = NULL;
1109 sta->sa_query_count = 0;
1110 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1111 return 1;
1112 }
1113
1114 return 0;
1115}
1116
1117
1118static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
1119{
1120 struct hostapd_data *hapd = eloop_ctx;
1121 struct sta_info *sta = timeout_ctx;
1122 unsigned int timeout, sec, usec;
1123 u8 *trans_id, *nbuf;
1124
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001125 wpa_printf(MSG_DEBUG, "%s: SA Query timer for STA " MACSTR
1126 " (count=%d)",
1127 hapd->conf->iface, MAC2STR(sta->addr), sta->sa_query_count);
1128
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001129 if (sta->sa_query_count > 0 &&
1130 ap_check_sa_query_timeout(hapd, sta))
1131 return;
1132
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001133 nbuf = os_realloc_array(sta->sa_query_trans_id,
1134 sta->sa_query_count + 1,
1135 WLAN_SA_QUERY_TR_ID_LEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001136 if (nbuf == NULL)
1137 return;
1138 if (sta->sa_query_count == 0) {
1139 /* Starting a new SA Query procedure */
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001140 os_get_reltime(&sta->sa_query_start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001141 }
1142 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
1143 sta->sa_query_trans_id = nbuf;
1144 sta->sa_query_count++;
1145
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001146 if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) {
1147 /*
1148 * We don't really care which ID is used here, so simply
1149 * hardcode this if the mostly theoretical os_get_random()
1150 * failure happens.
1151 */
1152 trans_id[0] = 0x12;
1153 trans_id[1] = 0x34;
1154 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001155
1156 timeout = hapd->conf->assoc_sa_query_retry_timeout;
1157 sec = ((timeout / 1000) * 1024) / 1000;
1158 usec = (timeout % 1000) * 1024;
1159 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
1160
1161 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1162 HOSTAPD_LEVEL_DEBUG,
1163 "association SA Query attempt %d", sta->sa_query_count);
1164
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001165 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001166}
1167
1168
1169void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1170{
1171 ap_sa_query_timer(hapd, sta);
1172}
1173
1174
1175void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1176{
1177 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1178 os_free(sta->sa_query_trans_id);
1179 sta->sa_query_trans_id = NULL;
1180 sta->sa_query_count = 0;
1181}
1182
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001183
Hai Shalom74f70d42019-02-11 14:42:39 -08001184const char * ap_sta_wpa_get_keyid(struct hostapd_data *hapd,
1185 struct sta_info *sta)
1186{
1187 struct hostapd_wpa_psk *psk;
1188 struct hostapd_ssid *ssid;
1189 const u8 *pmk;
1190 int pmk_len;
1191
1192 ssid = &hapd->conf->ssid;
1193
1194 pmk = wpa_auth_get_pmk(sta->wpa_sm, &pmk_len);
1195 if (!pmk || pmk_len != PMK_LEN)
1196 return NULL;
1197
1198 for (psk = ssid->wpa_psk; psk; psk = psk->next)
1199 if (os_memcmp(pmk, psk->psk, PMK_LEN) == 0)
1200 break;
1201 if (!psk)
1202 return NULL;
1203 if (!psk || !psk->keyid[0])
1204 return NULL;
1205
1206 return psk->keyid;
1207}
1208
1209
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001210void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
1211 int authorized)
1212{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001213 const u8 *dev_addr = NULL;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001214 char buf[100];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001215#ifdef CONFIG_P2P
1216 u8 addr[ETH_ALEN];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001217 u8 ip_addr_buf[4];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001218#endif /* CONFIG_P2P */
1219
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001220 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
1221 return;
1222
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001223 if (authorized)
1224 sta->flags |= WLAN_STA_AUTHORIZED;
1225 else
1226 sta->flags &= ~WLAN_STA_AUTHORIZED;
1227
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001228#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001229 if (hapd->p2p_group == NULL) {
1230 if (sta->p2p_ie != NULL &&
1231 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
1232 dev_addr = addr;
1233 } else
1234 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001235
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001236 if (dev_addr)
1237 os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
1238 MAC2STR(sta->addr), MAC2STR(dev_addr));
1239 else
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001240#endif /* CONFIG_P2P */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001241 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
1242
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001243 if (hapd->sta_authorized_cb)
1244 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
1245 sta->addr, authorized, dev_addr);
1246
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001247 if (authorized) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001248 const char *keyid;
1249 char keyid_buf[100];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001250 char ip_addr[100];
Hai Shalom74f70d42019-02-11 14:42:39 -08001251
1252 keyid_buf[0] = '\0';
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001253 ip_addr[0] = '\0';
1254#ifdef CONFIG_P2P
1255 if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) {
1256 os_snprintf(ip_addr, sizeof(ip_addr),
1257 " ip_addr=%u.%u.%u.%u",
1258 ip_addr_buf[0], ip_addr_buf[1],
1259 ip_addr_buf[2], ip_addr_buf[3]);
1260 }
1261#endif /* CONFIG_P2P */
1262
Hai Shalom74f70d42019-02-11 14:42:39 -08001263 keyid = ap_sta_wpa_get_keyid(hapd, sta);
1264 if (keyid) {
1265 os_snprintf(keyid_buf, sizeof(keyid_buf),
1266 " keyid=%s", keyid);
1267 }
1268
1269 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s",
1270 buf, ip_addr, keyid_buf);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001271
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001272 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001273 hapd->msg_ctx_parent != hapd->msg_ctx)
1274 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
Hai Shalom74f70d42019-02-11 14:42:39 -08001275 AP_STA_CONNECTED "%s%s%s",
1276 buf, ip_addr, keyid_buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001277 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001278 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
1279
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001280 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001281 hapd->msg_ctx_parent != hapd->msg_ctx)
1282 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
1283 AP_STA_DISCONNECTED "%s", buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001284 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001285
1286#ifdef CONFIG_FST
1287 if (hapd->iface->fst) {
1288 if (authorized)
1289 fst_notify_peer_connected(hapd->iface->fst, sta->addr);
1290 else
1291 fst_notify_peer_disconnected(hapd->iface->fst,
1292 sta->addr);
1293 }
1294#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001295}
1296
1297
1298void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
1299 const u8 *addr, u16 reason)
1300{
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001301 if (sta)
1302 wpa_printf(MSG_DEBUG, "%s: %s STA " MACSTR " reason=%u",
1303 hapd->conf->iface, __func__, MAC2STR(sta->addr),
1304 reason);
1305 else if (addr)
1306 wpa_printf(MSG_DEBUG, "%s: %s addr " MACSTR " reason=%u",
1307 hapd->conf->iface, __func__, MAC2STR(addr),
1308 reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001309
1310 if (sta == NULL && addr)
1311 sta = ap_get_sta(hapd, addr);
1312
1313 if (addr)
1314 hostapd_drv_sta_deauth(hapd, addr, reason);
1315
1316 if (sta == NULL)
1317 return;
1318 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001319 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1320 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001321 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001322 wpa_printf(MSG_DEBUG, "%s: %s: reschedule ap_handle_timer timeout "
Dmitry Shmidt04949592012-07-19 12:16:46 -07001323 "for " MACSTR " (%d seconds - "
1324 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001325 hapd->conf->iface, __func__, MAC2STR(sta->addr),
Dmitry Shmidt04949592012-07-19 12:16:46 -07001326 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001327 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001328 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
1329 ap_handle_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001330 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001331
Dmitry Shmidt29333592017-01-09 12:27:11 -08001332 if (hapd->iface->current_mode &&
1333 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
1334 /* Deauthentication is not used in DMG/IEEE 802.11ad;
1335 * disassociate the STA instead. */
1336 sta->disassoc_reason = reason;
1337 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
1338 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1339 eloop_register_timeout(hapd->iface->drv_flags &
1340 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ?
1341 2 : 0, 0, ap_sta_disassoc_cb_timeout,
1342 hapd, sta);
1343 return;
1344 }
1345
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001346 sta->deauth_reason = reason;
1347 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
1348 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1349 eloop_register_timeout(hapd->iface->drv_flags &
1350 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
1351 ap_sta_deauth_cb_timeout, hapd, sta);
1352}
1353
1354
1355void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
1356{
1357 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
1358 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
1359 return;
1360 }
1361 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
1362 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1363 ap_sta_deauth_cb_timeout(hapd, sta);
1364}
1365
1366
1367void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
1368{
1369 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
1370 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
1371 return;
1372 }
1373 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
1374 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1375 ap_sta_disassoc_cb_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001376}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001377
1378
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001379void ap_sta_clear_disconnect_timeouts(struct hostapd_data *hapd,
1380 struct sta_info *sta)
1381{
1382 if (eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta) > 0)
1383 wpa_printf(MSG_DEBUG,
1384 "%s: Removed ap_sta_deauth_cb_timeout timeout for "
1385 MACSTR,
1386 hapd->conf->iface, MAC2STR(sta->addr));
1387 if (eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta) > 0)
1388 wpa_printf(MSG_DEBUG,
1389 "%s: Removed ap_sta_disassoc_cb_timeout timeout for "
1390 MACSTR,
1391 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt29333592017-01-09 12:27:11 -08001392 if (eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta) > 0)
1393 {
1394 wpa_printf(MSG_DEBUG,
1395 "%s: Removed ap_sta_delayed_1x_auth_fail_cb timeout for "
1396 MACSTR,
1397 hapd->conf->iface, MAC2STR(sta->addr));
1398 if (sta->flags & WLAN_STA_WPS)
1399 hostapd_wps_eap_completed(hapd);
1400 }
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001401}
1402
1403
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001404int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen)
1405{
1406 int res;
1407
1408 buf[0] = '\0';
Hai Shalomc3565922019-10-28 11:58:20 -07001409 res = os_snprintf(buf, buflen, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001410 (flags & WLAN_STA_AUTH ? "[AUTH]" : ""),
1411 (flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""),
1412 (flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : ""),
1413 (flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
1414 ""),
1415 (flags & WLAN_STA_SHORT_PREAMBLE ?
1416 "[SHORT_PREAMBLE]" : ""),
1417 (flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
1418 (flags & WLAN_STA_WMM ? "[WMM]" : ""),
1419 (flags & WLAN_STA_MFP ? "[MFP]" : ""),
1420 (flags & WLAN_STA_WPS ? "[WPS]" : ""),
1421 (flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""),
1422 (flags & WLAN_STA_WDS ? "[WDS]" : ""),
1423 (flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
1424 (flags & WLAN_STA_WPS2 ? "[WPS2]" : ""),
1425 (flags & WLAN_STA_GAS ? "[GAS]" : ""),
Roshan Pius3a1667e2018-07-03 15:17:14 -07001426 (flags & WLAN_STA_HT ? "[HT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001427 (flags & WLAN_STA_VHT ? "[VHT]" : ""),
Hai Shalomc3565922019-10-28 11:58:20 -07001428 (flags & WLAN_STA_HE ? "[HE]" : ""),
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001429 (flags & WLAN_STA_VENDOR_VHT ? "[VENDOR_VHT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001430 (flags & WLAN_STA_WNM_SLEEP_MODE ?
1431 "[WNM_SLEEP_MODE]" : ""));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001432 if (os_snprintf_error(buflen, res))
1433 res = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001434
1435 return res;
1436}
Dmitry Shmidt29333592017-01-09 12:27:11 -08001437
1438
1439static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx)
1440{
1441 struct hostapd_data *hapd = eloop_ctx;
1442 struct sta_info *sta = timeout_ctx;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001443 u16 reason;
Dmitry Shmidt29333592017-01-09 12:27:11 -08001444
1445 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1446 "IEEE 802.1X: Scheduled disconnection of " MACSTR
1447 " after EAP-Failure", MAC2STR(sta->addr));
1448
Roshan Pius3a1667e2018-07-03 15:17:14 -07001449 reason = sta->disconnect_reason_code;
1450 if (!reason)
1451 reason = WLAN_REASON_IEEE_802_1X_AUTH_FAILED;
1452 ap_sta_disconnect(hapd, sta, sta->addr, reason);
Dmitry Shmidt29333592017-01-09 12:27:11 -08001453 if (sta->flags & WLAN_STA_WPS)
1454 hostapd_wps_eap_completed(hapd);
1455}
1456
1457
1458void ap_sta_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1459 struct sta_info *sta)
1460{
1461 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1462 "IEEE 802.1X: Force disconnection of " MACSTR
1463 " after EAP-Failure in 10 ms", MAC2STR(sta->addr));
1464
1465 /*
1466 * Add a small sleep to increase likelihood of previously requested
1467 * EAP-Failure TX getting out before this should the driver reorder
1468 * operations.
1469 */
1470 eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta);
1471 eloop_register_timeout(0, 10000, ap_sta_delayed_1x_auth_fail_cb,
1472 hapd, sta);
1473}
1474
1475
1476int ap_sta_pending_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1477 struct sta_info *sta)
1478{
1479 return eloop_is_timeout_registered(ap_sta_delayed_1x_auth_fail_cb,
1480 hapd, sta);
1481}