blob: 4a7722c28bcaca85d6f8e559a238de83af3f86f6 [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"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070016#include "radius/radius.h"
17#include "radius/radius_client.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080019#include "fst/fst.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070020#include "crypto/crypto.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070021#include "hostapd.h"
22#include "accounting.h"
23#include "ieee802_1x.h"
24#include "ieee802_11.h"
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080025#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070026#include "wpa_auth.h"
27#include "preauth_auth.h"
28#include "ap_config.h"
29#include "beacon.h"
30#include "ap_mlme.h"
31#include "vlan_init.h"
32#include "p2p_hostapd.h"
33#include "ap_drv_ops.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070034#include "gas_serv.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080035#include "wnm_ap.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080036#include "mbo_ap.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080037#include "ndisc_snoop.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070038#include "sta_info.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080039#include "vlan.h"
Dmitry Shmidt29333592017-01-09 12:27:11 -080040#include "wps_hostapd.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041
42static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
43 struct sta_info *sta);
44static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080045static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080046static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
47static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070048#ifdef CONFIG_IEEE80211W
49static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
50#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080051static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
Dmitry Shmidt29333592017-01-09 12:27:11 -080052static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070053
54int ap_for_each_sta(struct hostapd_data *hapd,
55 int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
56 void *ctx),
57 void *ctx)
58{
59 struct sta_info *sta;
60
61 for (sta = hapd->sta_list; sta; sta = sta->next) {
62 if (cb(hapd, sta, ctx))
63 return 1;
64 }
65
66 return 0;
67}
68
69
70struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
71{
72 struct sta_info *s;
73
74 s = hapd->sta_hash[STA_HASH(sta)];
75 while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
76 s = s->hnext;
77 return s;
78}
79
80
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070081#ifdef CONFIG_P2P
82struct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr)
83{
84 struct sta_info *sta;
85
86 for (sta = hapd->sta_list; sta; sta = sta->next) {
87 const u8 *p2p_dev_addr;
88
89 if (sta->p2p_ie == NULL)
90 continue;
91
92 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
93 if (p2p_dev_addr == NULL)
94 continue;
95
96 if (os_memcmp(p2p_dev_addr, addr, ETH_ALEN) == 0)
97 return sta;
98 }
99
100 return NULL;
101}
102#endif /* CONFIG_P2P */
103
104
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700105static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
106{
107 struct sta_info *tmp;
108
109 if (hapd->sta_list == sta) {
110 hapd->sta_list = sta->next;
111 return;
112 }
113
114 tmp = hapd->sta_list;
115 while (tmp != NULL && tmp->next != sta)
116 tmp = tmp->next;
117 if (tmp == NULL) {
118 wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
119 "list.", MAC2STR(sta->addr));
120 } else
121 tmp->next = sta->next;
122}
123
124
125void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
126{
127 sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
128 hapd->sta_hash[STA_HASH(sta->addr)] = sta;
129}
130
131
132static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
133{
134 struct sta_info *s;
135
136 s = hapd->sta_hash[STA_HASH(sta->addr)];
137 if (s == NULL) return;
138 if (os_memcmp(s->addr, sta->addr, 6) == 0) {
139 hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
140 return;
141 }
142
143 while (s->hnext != NULL &&
144 os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
145 s = s->hnext;
146 if (s->hnext != NULL)
147 s->hnext = s->hnext->hnext;
148 else
149 wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
150 " from hash table", MAC2STR(sta->addr));
151}
152
153
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800154void ap_sta_ip6addr_del(struct hostapd_data *hapd, struct sta_info *sta)
155{
156 sta_ip6addr_del(hapd, sta);
157}
158
159
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700160void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
161{
162 int set_beacon = 0;
163
164 accounting_sta_stop(hapd, sta);
165
166 /* just in case */
167 ap_sta_set_authorized(hapd, sta, 0);
168
Hai Shalom74f70d42019-02-11 14:42:39 -0800169 if (sta->flags & (WLAN_STA_WDS | WLAN_STA_MULTI_AP))
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700170 hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800172 if (sta->ipaddr)
173 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
174 ap_sta_ip6addr_del(hapd, sta);
175
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800176 if (!hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800177 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800179 sta->added_unassoc = 0;
180 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181
182 ap_sta_hash_del(hapd, sta);
183 ap_sta_list_del(hapd, sta);
184
185 if (sta->aid > 0)
186 hapd->sta_aid[(sta->aid - 1) / 32] &=
187 ~BIT((sta->aid - 1) % 32);
188
189 hapd->num_sta--;
190 if (sta->nonerp_set) {
191 sta->nonerp_set = 0;
192 hapd->iface->num_sta_non_erp--;
193 if (hapd->iface->num_sta_non_erp == 0)
194 set_beacon++;
195 }
196
197 if (sta->no_short_slot_time_set) {
198 sta->no_short_slot_time_set = 0;
199 hapd->iface->num_sta_no_short_slot_time--;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700200 if (hapd->iface->current_mode &&
201 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700202 && hapd->iface->num_sta_no_short_slot_time == 0)
203 set_beacon++;
204 }
205
206 if (sta->no_short_preamble_set) {
207 sta->no_short_preamble_set = 0;
208 hapd->iface->num_sta_no_short_preamble--;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700209 if (hapd->iface->current_mode &&
210 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700211 && hapd->iface->num_sta_no_short_preamble == 0)
212 set_beacon++;
213 }
214
215 if (sta->no_ht_gf_set) {
216 sta->no_ht_gf_set = 0;
217 hapd->iface->num_sta_ht_no_gf--;
218 }
219
220 if (sta->no_ht_set) {
221 sta->no_ht_set = 0;
222 hapd->iface->num_sta_no_ht--;
223 }
224
225 if (sta->ht_20mhz_set) {
226 sta->ht_20mhz_set = 0;
227 hapd->iface->num_sta_ht_20mhz--;
228 }
229
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700230#ifdef CONFIG_TAXONOMY
231 wpabuf_free(sta->probe_ie_taxonomy);
232 sta->probe_ie_taxonomy = NULL;
233 wpabuf_free(sta->assoc_ie_taxonomy);
234 sta->assoc_ie_taxonomy = NULL;
235#endif /* CONFIG_TAXONOMY */
236
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700237#ifdef CONFIG_IEEE80211N
238 ht40_intolerant_remove(hapd->iface, sta);
239#endif /* CONFIG_IEEE80211N */
240
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700241#ifdef CONFIG_P2P
242 if (sta->no_p2p_set) {
243 sta->no_p2p_set = 0;
244 hapd->num_sta_no_p2p--;
245 if (hapd->num_sta_no_p2p == 0)
246 hostapd_p2p_non_p2p_sta_disconnected(hapd);
247 }
248#endif /* CONFIG_P2P */
249
250#if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
251 if (hostapd_ht_operation_update(hapd->iface) > 0)
252 set_beacon++;
253#endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
254
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800255#ifdef CONFIG_MESH
256 if (hapd->mesh_sta_free_cb)
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800257 hapd->mesh_sta_free_cb(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800258#endif /* CONFIG_MESH */
259
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700260 if (set_beacon)
261 ieee802_11_set_beacons(hapd->iface);
262
Dmitry Shmidt04949592012-07-19 12:16:46 -0700263 wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
264 __func__, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
266 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800267 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800268 ap_sta_clear_disconnect_timeouts(hapd, sta);
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800269 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700270
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800271 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700272 wpa_auth_sta_deinit(sta->wpa_sm);
273 rsn_preauth_free_station(hapd, sta);
274#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt96571392013-10-14 12:54:46 -0700275 if (hapd->radius)
276 radius_client_flush_auth(hapd->radius, sta->addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700277#endif /* CONFIG_NO_RADIUS */
278
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800279#ifndef CONFIG_NO_VLAN
280 /*
281 * sta->wpa_sm->group needs to be released before so that
282 * vlan_remove_dynamic() can check that no stations are left on the
283 * AP_VLAN netdev.
284 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800285 if (sta->vlan_id)
286 vlan_remove_dynamic(hapd, sta->vlan_id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800287 if (sta->vlan_id_bound) {
288 /*
289 * Need to remove the STA entry before potentially removing the
290 * VLAN.
291 */
292 if (hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800293 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800294 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800295 sta->added_unassoc = 0;
296 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800297 vlan_remove_dynamic(hapd, sta->vlan_id_bound);
298 }
299#endif /* CONFIG_NO_VLAN */
300
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700301 os_free(sta->challenge);
302
303#ifdef CONFIG_IEEE80211W
304 os_free(sta->sa_query_trans_id);
305 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
306#endif /* CONFIG_IEEE80211W */
307
308#ifdef CONFIG_P2P
309 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
310#endif /* CONFIG_P2P */
311
Dmitry Shmidt04949592012-07-19 12:16:46 -0700312#ifdef CONFIG_INTERWORKING
313 if (sta->gas_dialog) {
314 int i;
315 for (i = 0; i < GAS_DIALOG_MAX; i++)
316 gas_serv_dialog_clear(&sta->gas_dialog[i]);
317 os_free(sta->gas_dialog);
318 }
319#endif /* CONFIG_INTERWORKING */
320
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700321 wpabuf_free(sta->wps_ie);
322 wpabuf_free(sta->p2p_ie);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800323 wpabuf_free(sta->hs20_ie);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700324 wpabuf_free(sta->roaming_consortium);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800325#ifdef CONFIG_FST
326 wpabuf_free(sta->mb_ies);
327#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700328
329 os_free(sta->ht_capabilities);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -0800330 os_free(sta->vht_capabilities);
Hai Shalom74f70d42019-02-11 14:42:39 -0800331 os_free(sta->vht_operation);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800332 hostapd_free_psk_list(sta->psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700333 os_free(sta->identity);
334 os_free(sta->radius_cui);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800335 os_free(sta->remediation_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700336 os_free(sta->t_c_url);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800337 wpabuf_free(sta->hs20_deauth_req);
338 os_free(sta->hs20_session_info_url);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700339
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800340#ifdef CONFIG_SAE
341 sae_clear_data(sta->sae);
342 os_free(sta->sae);
343#endif /* CONFIG_SAE */
344
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800345 mbo_ap_sta_free(sta);
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800346 os_free(sta->supp_op_classes);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800347
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800348#ifdef CONFIG_FILS
349 os_free(sta->fils_pending_assoc_req);
350 wpabuf_free(sta->fils_hlp_resp);
351 wpabuf_free(sta->hlp_dhcp_discover);
352 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700353#ifdef CONFIG_FILS_SK_PFS
354 crypto_ecdh_deinit(sta->fils_ecdh);
355 wpabuf_clear_free(sta->fils_dh_ss);
356 wpabuf_free(sta->fils_g_sta);
357#endif /* CONFIG_FILS_SK_PFS */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800358#endif /* CONFIG_FILS */
359
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700360#ifdef CONFIG_OWE
361 bin_clear_free(sta->owe_pmk, sta->owe_pmk_len);
362 crypto_ecdh_deinit(sta->owe_ecdh);
363#endif /* CONFIG_OWE */
364
Roshan Pius3a1667e2018-07-03 15:17:14 -0700365 os_free(sta->ext_capability);
366
367#ifdef CONFIG_WNM_AP
368 eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta);
369#endif /* CONFIG_WNM_AP */
370
371 os_free(sta->ifname_wds);
372
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700373 os_free(sta);
374}
375
376
377void hostapd_free_stas(struct hostapd_data *hapd)
378{
379 struct sta_info *sta, *prev;
380
381 sta = hapd->sta_list;
382
383 while (sta) {
384 prev = sta;
385 if (sta->flags & WLAN_STA_AUTH) {
386 mlme_deauthenticate_indication(
387 hapd, sta, WLAN_REASON_UNSPECIFIED);
388 }
389 sta = sta->next;
390 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
391 MAC2STR(prev->addr));
392 ap_free_sta(hapd, prev);
393 }
394}
395
396
397/**
398 * ap_handle_timer - Per STA timer handler
399 * @eloop_ctx: struct hostapd_data *
400 * @timeout_ctx: struct sta_info *
401 *
402 * This function is called to check station activity and to remove inactive
403 * stations.
404 */
405void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
406{
407 struct hostapd_data *hapd = eloop_ctx;
408 struct sta_info *sta = timeout_ctx;
409 unsigned long next_time = 0;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700410 int reason;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800412 wpa_printf(MSG_DEBUG, "%s: %s: " MACSTR " flags=0x%x timeout_next=%d",
413 hapd->conf->iface, __func__, MAC2STR(sta->addr), sta->flags,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700414 sta->timeout_next);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700415 if (sta->timeout_next == STA_REMOVE) {
416 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
417 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
418 "local deauth request");
419 ap_free_sta(hapd, sta);
420 return;
421 }
422
423 if ((sta->flags & WLAN_STA_ASSOC) &&
424 (sta->timeout_next == STA_NULLFUNC ||
425 sta->timeout_next == STA_DISASSOC)) {
426 int inactive_sec;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700427 /*
428 * Add random value to timeout so that we don't end up bouncing
429 * all stations at the same time if we have lots of associated
430 * stations that are idle (but keep re-associating).
431 */
432 int fuzz = os_random() % 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700433 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
434 if (inactive_sec == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800435 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
436 "Check inactivity: Could not "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800437 "get station info from kernel driver for "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700438 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800439 /*
440 * The driver may not support this functionality.
441 * Anyway, try again after the next inactivity timeout,
442 * but do not disconnect the station now.
443 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700444 next_time = hapd->conf->ap_max_inactivity + fuzz;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800445 } else if (inactive_sec == -ENOENT) {
446 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
447 "Station " MACSTR " has lost its driver entry",
448 MAC2STR(sta->addr));
449
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800450 /* Avoid sending client probe on removed client */
451 sta->timeout_next = STA_DISASSOC;
452 goto skip_poll;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800453 } else if (inactive_sec < hapd->conf->ap_max_inactivity) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700454 /* station activity detected; reset timeout state */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800455 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
456 "Station " MACSTR " has been active %is ago",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 MAC2STR(sta->addr), inactive_sec);
458 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700459 next_time = hapd->conf->ap_max_inactivity + fuzz -
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700460 inactive_sec;
461 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800462 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
463 "Station " MACSTR " has been "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700464 "inactive too long: %d sec, max allowed: %d",
465 MAC2STR(sta->addr), inactive_sec,
466 hapd->conf->ap_max_inactivity);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800467
468 if (hapd->conf->skip_inactivity_poll)
469 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700470 }
471 }
472
473 if ((sta->flags & WLAN_STA_ASSOC) &&
474 sta->timeout_next == STA_DISASSOC &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800475 !(sta->flags & WLAN_STA_PENDING_POLL) &&
476 !hapd->conf->skip_inactivity_poll) {
477 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
478 " has ACKed data poll", MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479 /* data nullfunc frame poll did not produce TX errors; assume
480 * station ACKed it */
481 sta->timeout_next = STA_NULLFUNC;
482 next_time = hapd->conf->ap_max_inactivity;
483 }
484
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800485skip_poll:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700486 if (next_time) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700487 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
488 "for " MACSTR " (%lu seconds)",
489 __func__, MAC2STR(sta->addr), next_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700490 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
491 sta);
492 return;
493 }
494
495 if (sta->timeout_next == STA_NULLFUNC &&
496 (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800497 wpa_printf(MSG_DEBUG, " Polling STA");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700498 sta->flags |= WLAN_STA_PENDING_POLL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800499 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
500 sta->flags & WLAN_STA_WMM);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501 } else if (sta->timeout_next != STA_REMOVE) {
502 int deauth = sta->timeout_next == STA_DEAUTH;
503
Hai Shalom74f70d42019-02-11 14:42:39 -0800504 if (!deauth && !(sta->flags & WLAN_STA_ASSOC)) {
505 /* Cannot disassociate not-associated STA, so move
506 * directly to deauthentication. */
507 sta->timeout_next = STA_DEAUTH;
508 deauth = 1;
509 }
510
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800511 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
512 "Timeout, sending %s info to STA " MACSTR,
513 deauth ? "deauthentication" : "disassociation",
514 MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700515
516 if (deauth) {
517 hostapd_drv_sta_deauth(
518 hapd, sta->addr,
519 WLAN_REASON_PREV_AUTH_NOT_VALID);
520 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700521 reason = (sta->timeout_next == STA_DISASSOC) ?
522 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
523 WLAN_REASON_PREV_AUTH_NOT_VALID;
524
525 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700526 }
527 }
528
529 switch (sta->timeout_next) {
530 case STA_NULLFUNC:
531 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700532 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
533 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
534 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700535 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
536 hapd, sta);
537 break;
538 case STA_DISASSOC:
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700539 case STA_DISASSOC_FROM_CLI:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800540 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541 sta->flags &= ~WLAN_STA_ASSOC;
542 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
543 if (!sta->acct_terminate_cause)
544 sta->acct_terminate_cause =
545 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
546 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800547 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700548 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
549 HOSTAPD_LEVEL_INFO, "disassociated due to "
550 "inactivity");
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700551 reason = (sta->timeout_next == STA_DISASSOC) ?
552 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
553 WLAN_REASON_PREV_AUTH_NOT_VALID;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700554 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700555 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
556 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
557 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700558 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
559 hapd, sta);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700560 mlme_disassociate_indication(hapd, sta, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700561 break;
562 case STA_DEAUTH:
563 case STA_REMOVE:
564 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
565 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800566 "inactivity (timer DEAUTH/REMOVE)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700567 if (!sta->acct_terminate_cause)
568 sta->acct_terminate_cause =
569 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
570 mlme_deauthenticate_indication(
571 hapd, sta,
572 WLAN_REASON_PREV_AUTH_NOT_VALID);
573 ap_free_sta(hapd, sta);
574 break;
575 }
576}
577
578
579static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
580{
581 struct hostapd_data *hapd = eloop_ctx;
582 struct sta_info *sta = timeout_ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700583
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800584 wpa_printf(MSG_DEBUG, "%s: Session timer for STA " MACSTR,
585 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700586 if (!(sta->flags & WLAN_STA_AUTH)) {
587 if (sta->flags & WLAN_STA_GAS) {
588 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
589 "entry " MACSTR, MAC2STR(sta->addr));
590 ap_free_sta(hapd, sta);
591 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700592 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700593 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700594
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700595 hostapd_drv_sta_deauth(hapd, sta->addr,
596 WLAN_REASON_PREV_AUTH_NOT_VALID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700597 mlme_deauthenticate_indication(hapd, sta,
598 WLAN_REASON_PREV_AUTH_NOT_VALID);
599 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
600 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
601 "session timeout");
602 sta->acct_terminate_cause =
603 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700604 ap_free_sta(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700605}
606
607
Dmitry Shmidt54605472013-11-08 11:10:19 -0800608void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta,
609 u32 session_timeout)
610{
611 if (eloop_replenish_timeout(session_timeout, 0,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800612 ap_handle_session_timer, hapd, sta) == 1) {
Dmitry Shmidt54605472013-11-08 11:10:19 -0800613 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
614 HOSTAPD_LEVEL_DEBUG, "setting session timeout "
615 "to %d seconds", session_timeout);
616 }
617}
618
619
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700620void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
621 u32 session_timeout)
622{
623 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
624 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
625 "seconds", session_timeout);
626 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
627 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
628 hapd, sta);
629}
630
631
632void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
633{
634 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
635}
636
637
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800638static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx)
639{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700640#ifdef CONFIG_WNM_AP
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800641 struct hostapd_data *hapd = eloop_ctx;
642 struct sta_info *sta = timeout_ctx;
643
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800644 wpa_printf(MSG_DEBUG, "%s: WNM: Session warning time reached for "
645 MACSTR, hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800646 if (sta->hs20_session_info_url == NULL)
647 return;
648
649 wnm_send_ess_disassoc_imminent(hapd, sta, sta->hs20_session_info_url,
650 sta->hs20_disassoc_timer);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700651#endif /* CONFIG_WNM_AP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800652}
653
654
655void ap_sta_session_warning_timeout(struct hostapd_data *hapd,
656 struct sta_info *sta, int warning_time)
657{
658 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
659 eloop_register_timeout(warning_time, 0, ap_handle_session_warning_timer,
660 hapd, sta);
661}
662
663
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
665{
666 struct sta_info *sta;
667
668 sta = ap_get_sta(hapd, addr);
669 if (sta)
670 return sta;
671
672 wpa_printf(MSG_DEBUG, " New STA");
673 if (hapd->num_sta >= hapd->conf->max_num_sta) {
674 /* FIX: might try to remove some old STAs first? */
675 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
676 hapd->num_sta, hapd->conf->max_num_sta);
677 return NULL;
678 }
679
680 sta = os_zalloc(sizeof(struct sta_info));
681 if (sta == NULL) {
682 wpa_printf(MSG_ERROR, "malloc failed");
683 return NULL;
684 }
685 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800686 if (accounting_sta_get_id(hapd, sta) < 0) {
687 os_free(sta);
688 return NULL;
689 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700690
Dmitry Shmidt01904cf2013-12-05 11:08:35 -0800691 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
692 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
693 "for " MACSTR " (%d seconds - ap_max_inactivity)",
694 __func__, MAC2STR(addr),
695 hapd->conf->ap_max_inactivity);
696 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
697 ap_handle_timer, hapd, sta);
698 }
699
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700700 /* initialize STA info data */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701 os_memcpy(sta->addr, addr, ETH_ALEN);
702 sta->next = hapd->sta_list;
703 hapd->sta_list = sta;
704 hapd->num_sta++;
705 ap_sta_hash_add(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 ap_sta_remove_in_other_bss(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800707 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
708 dl_list_init(&sta->ip6addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700709
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700710#ifdef CONFIG_TAXONOMY
711 sta_track_claim_taxonomy_info(hapd->iface, addr,
712 &sta->probe_ie_taxonomy);
713#endif /* CONFIG_TAXONOMY */
714
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700715 return sta;
716}
717
718
719static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
720{
721 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
722
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800723 if (sta->ipaddr)
724 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
725 ap_sta_ip6addr_del(hapd, sta);
726
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800727 wpa_printf(MSG_DEBUG, "%s: Removing STA " MACSTR " from kernel driver",
728 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
730 sta->flags & WLAN_STA_ASSOC) {
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800731 wpa_printf(MSG_DEBUG, "%s: Could not remove station " MACSTR
732 " from kernel driver",
733 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700734 return -1;
735 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800736 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700737 return 0;
738}
739
740
741static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
742 struct sta_info *sta)
743{
744 struct hostapd_iface *iface = hapd->iface;
745 size_t i;
746
747 for (i = 0; i < iface->num_bss; i++) {
748 struct hostapd_data *bss = iface->bss[i];
749 struct sta_info *sta2;
750 /* bss should always be set during operation, but it may be
751 * NULL during reconfiguration. Assume the STA is not
752 * associated to another BSS in that case to avoid NULL pointer
753 * dereferences. */
754 if (bss == hapd || bss == NULL)
755 continue;
756 sta2 = ap_get_sta(bss, sta->addr);
757 if (!sta2)
758 continue;
759
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800760 wpa_printf(MSG_DEBUG, "%s: disconnect old STA " MACSTR
761 " association from another BSS %s",
762 hapd->conf->iface, MAC2STR(sta2->addr),
763 bss->conf->iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764 ap_sta_disconnect(bss, sta2, sta2->addr,
765 WLAN_REASON_PREV_AUTH_NOT_VALID);
766 }
767}
768
769
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800770static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
771{
772 struct hostapd_data *hapd = eloop_ctx;
773 struct sta_info *sta = timeout_ctx;
774
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800775 wpa_printf(MSG_DEBUG, "%s: Disassociation callback for STA " MACSTR,
776 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800777 ap_sta_remove(hapd, sta);
778 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
779}
780
781
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700782void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
783 u16 reason)
784{
785 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
786 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800787 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800788 if (hapd->iface->current_mode &&
789 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
790 /* Skip deauthentication in DMG/IEEE 802.11ad */
791 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
792 WLAN_STA_ASSOC_REQ_OK);
793 sta->timeout_next = STA_REMOVE;
794 } else {
795 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
796 sta->timeout_next = STA_DEAUTH;
797 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800798 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700799 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
800 "for " MACSTR " (%d seconds - "
801 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
802 __func__, MAC2STR(sta->addr),
803 AP_MAX_INACTIVITY_AFTER_DISASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
805 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
806 ap_handle_timer, hapd, sta);
807 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800808 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800810 sta->disassoc_reason = reason;
811 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
812 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
813 eloop_register_timeout(hapd->iface->drv_flags &
814 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
815 ap_sta_disassoc_cb_timeout, hapd, sta);
816}
817
818
819static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
820{
821 struct hostapd_data *hapd = eloop_ctx;
822 struct sta_info *sta = timeout_ctx;
823
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800824 wpa_printf(MSG_DEBUG, "%s: Deauthentication callback for STA " MACSTR,
825 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800826 ap_sta_remove(hapd, sta);
827 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700828}
829
830
831void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
832 u16 reason)
833{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800834 if (hapd->iface->current_mode &&
835 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
836 /* Deauthentication is not used in DMG/IEEE 802.11ad;
837 * disassociate the STA instead. */
838 ap_sta_disassociate(hapd, sta, reason);
839 return;
840 }
841
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700842 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
843 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800844 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
845 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800846 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700848 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
849 "for " MACSTR " (%d seconds - "
850 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
851 __func__, MAC2STR(sta->addr),
852 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700853 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
854 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
855 ap_handle_timer, hapd, sta);
856 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800857 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700858
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800859 sta->deauth_reason = reason;
860 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
861 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
862 eloop_register_timeout(hapd->iface->drv_flags &
863 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
864 ap_sta_deauth_cb_timeout, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700865}
866
867
Dmitry Shmidt04949592012-07-19 12:16:46 -0700868#ifdef CONFIG_WPS
869int ap_sta_wps_cancel(struct hostapd_data *hapd,
870 struct sta_info *sta, void *ctx)
871{
872 if (sta && (sta->flags & WLAN_STA_WPS)) {
873 ap_sta_deauthenticate(hapd, sta,
874 WLAN_REASON_PREV_AUTH_NOT_VALID);
875 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
876 __func__, MAC2STR(sta->addr));
877 return 1;
878 }
879
880 return 0;
881}
882#endif /* CONFIG_WPS */
883
884
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800885static int ap_sta_get_free_vlan_id(struct hostapd_data *hapd)
886{
887 struct hostapd_vlan *vlan;
888 int vlan_id = MAX_VLAN_ID + 2;
889
890retry:
891 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
892 if (vlan->vlan_id == vlan_id) {
893 vlan_id++;
894 goto retry;
895 }
896 }
897 return vlan_id;
898}
899
900
901int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta,
902 struct vlan_description *vlan_desc)
903{
904 struct hostapd_vlan *vlan = NULL, *wildcard_vlan = NULL;
905 int old_vlan_id, vlan_id = 0, ret = 0;
906
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800907 /* Check if there is something to do */
908 if (hapd->conf->ssid.per_sta_vif && !sta->vlan_id) {
909 /* This sta is lacking its own vif */
910 } else if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED &&
911 !hapd->conf->ssid.per_sta_vif && sta->vlan_id) {
912 /* sta->vlan_id needs to be reset */
913 } else if (!vlan_compare(vlan_desc, sta->vlan_desc)) {
914 return 0; /* nothing to change */
915 }
916
917 /* Now the real VLAN changed or the STA just needs its own vif */
918 if (hapd->conf->ssid.per_sta_vif) {
919 /* Assign a new vif, always */
920 /* find a free vlan_id sufficiently big */
921 vlan_id = ap_sta_get_free_vlan_id(hapd);
922 /* Get wildcard VLAN */
923 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
924 if (vlan->vlan_id == VLAN_ID_WILDCARD)
925 break;
926 }
927 if (!vlan) {
928 hostapd_logger(hapd, sta->addr,
929 HOSTAPD_MODULE_IEEE80211,
930 HOSTAPD_LEVEL_DEBUG,
931 "per_sta_vif missing wildcard");
932 vlan_id = 0;
933 ret = -1;
934 goto done;
935 }
936 } else if (vlan_desc && vlan_desc->notempty) {
937 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
938 if (!vlan_compare(&vlan->vlan_desc, vlan_desc))
939 break;
940 if (vlan->vlan_id == VLAN_ID_WILDCARD)
941 wildcard_vlan = vlan;
942 }
943 if (vlan) {
944 vlan_id = vlan->vlan_id;
945 } else if (wildcard_vlan) {
946 vlan = wildcard_vlan;
947 vlan_id = vlan_desc->untagged;
948 if (vlan_desc->tagged[0]) {
949 /* Tagged VLAN configuration */
950 vlan_id = ap_sta_get_free_vlan_id(hapd);
951 }
952 } else {
953 hostapd_logger(hapd, sta->addr,
954 HOSTAPD_MODULE_IEEE80211,
955 HOSTAPD_LEVEL_DEBUG,
956 "missing vlan and wildcard for vlan=%d%s",
957 vlan_desc->untagged,
958 vlan_desc->tagged[0] ? "+" : "");
959 vlan_id = 0;
960 ret = -1;
961 goto done;
962 }
963 }
964
965 if (vlan && vlan->vlan_id == VLAN_ID_WILDCARD) {
966 vlan = vlan_add_dynamic(hapd, vlan, vlan_id, vlan_desc);
967 if (vlan == NULL) {
968 hostapd_logger(hapd, sta->addr,
969 HOSTAPD_MODULE_IEEE80211,
970 HOSTAPD_LEVEL_DEBUG,
971 "could not add dynamic VLAN interface for vlan=%d%s",
972 vlan_desc ? vlan_desc->untagged : -1,
973 (vlan_desc && vlan_desc->tagged[0]) ?
974 "+" : "");
975 vlan_id = 0;
976 ret = -1;
977 goto done;
978 }
979
980 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
981 HOSTAPD_LEVEL_DEBUG,
982 "added new dynamic VLAN interface '%s'",
983 vlan->ifname);
984 } else if (vlan && vlan->dynamic_vlan > 0) {
985 vlan->dynamic_vlan++;
986 hostapd_logger(hapd, sta->addr,
987 HOSTAPD_MODULE_IEEE80211,
988 HOSTAPD_LEVEL_DEBUG,
989 "updated existing dynamic VLAN interface '%s'",
990 vlan->ifname);
991 }
992done:
993 old_vlan_id = sta->vlan_id;
994 sta->vlan_id = vlan_id;
995 sta->vlan_desc = vlan ? &vlan->vlan_desc : NULL;
996
997 if (vlan_id != old_vlan_id && old_vlan_id)
998 vlan_remove_dynamic(hapd, old_vlan_id);
999
1000 return ret;
1001}
1002
1003
Dmitry Shmidt83474442015-04-15 13:47:09 -07001004int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001005{
1006#ifndef CONFIG_NO_VLAN
1007 const char *iface;
1008 struct hostapd_vlan *vlan = NULL;
1009 int ret;
Dmitry Shmidt83474442015-04-15 13:47:09 -07001010 int old_vlanid = sta->vlan_id_bound;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001011
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001012 iface = hapd->conf->iface;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001013 if (hapd->conf->ssid.vlan[0])
1014 iface = hapd->conf->ssid.vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001015
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001016 if (sta->vlan_id > 0) {
1017 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001018 if (vlan->vlan_id == sta->vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001019 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020 }
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001021 if (vlan)
1022 iface = vlan->ifname;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001023 }
1024
Dmitry Shmidt83474442015-04-15 13:47:09 -07001025 /*
1026 * Do not increment ref counters if the VLAN ID remains same, but do
1027 * not skip hostapd_drv_set_sta_vlan() as hostapd_drv_sta_remove() might
1028 * have been called before.
1029 */
1030 if (sta->vlan_id == old_vlanid)
1031 goto skip_counting;
1032
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001033 if (sta->vlan_id > 0 && vlan == NULL) {
1034 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1035 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
1036 "binding station to (vlan_id=%d)",
1037 sta->vlan_id);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001038 ret = -1;
1039 goto done;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001040 } else if (vlan && vlan->dynamic_vlan > 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001041 vlan->dynamic_vlan++;
1042 hostapd_logger(hapd, sta->addr,
1043 HOSTAPD_MODULE_IEEE80211,
1044 HOSTAPD_LEVEL_DEBUG,
1045 "updated existing dynamic VLAN interface '%s'",
1046 iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001047 }
1048
Dmitry Shmidt83474442015-04-15 13:47:09 -07001049 /* ref counters have been increased, so mark the station */
1050 sta->vlan_id_bound = sta->vlan_id;
1051
1052skip_counting:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001053 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1054 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
1055 "'%s'", iface);
1056
1057 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
1058 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
1059
1060 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
1061 if (ret < 0) {
1062 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1063 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
1064 "entry to vlan_id=%d", sta->vlan_id);
1065 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001066
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001067 /* During 1x reauth, if the vlan id changes, then remove the old id. */
Dmitry Shmidt83474442015-04-15 13:47:09 -07001068 if (old_vlanid > 0 && old_vlanid != sta->vlan_id)
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001069 vlan_remove_dynamic(hapd, old_vlanid);
Dmitry Shmidt83474442015-04-15 13:47:09 -07001070done:
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001071
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001072 return ret;
1073#else /* CONFIG_NO_VLAN */
1074 return 0;
1075#endif /* CONFIG_NO_VLAN */
1076}
1077
1078
1079#ifdef CONFIG_IEEE80211W
1080
1081int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
1082{
1083 u32 tu;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001084 struct os_reltime now, passed;
1085 os_get_reltime(&now);
1086 os_reltime_sub(&now, &sta->sa_query_start, &passed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087 tu = (passed.sec * 1000000 + passed.usec) / 1024;
1088 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
1089 hostapd_logger(hapd, sta->addr,
1090 HOSTAPD_MODULE_IEEE80211,
1091 HOSTAPD_LEVEL_DEBUG,
1092 "association SA Query timed out");
1093 sta->sa_query_timed_out = 1;
1094 os_free(sta->sa_query_trans_id);
1095 sta->sa_query_trans_id = NULL;
1096 sta->sa_query_count = 0;
1097 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1098 return 1;
1099 }
1100
1101 return 0;
1102}
1103
1104
1105static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
1106{
1107 struct hostapd_data *hapd = eloop_ctx;
1108 struct sta_info *sta = timeout_ctx;
1109 unsigned int timeout, sec, usec;
1110 u8 *trans_id, *nbuf;
1111
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001112 wpa_printf(MSG_DEBUG, "%s: SA Query timer for STA " MACSTR
1113 " (count=%d)",
1114 hapd->conf->iface, MAC2STR(sta->addr), sta->sa_query_count);
1115
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001116 if (sta->sa_query_count > 0 &&
1117 ap_check_sa_query_timeout(hapd, sta))
1118 return;
1119
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001120 nbuf = os_realloc_array(sta->sa_query_trans_id,
1121 sta->sa_query_count + 1,
1122 WLAN_SA_QUERY_TR_ID_LEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001123 if (nbuf == NULL)
1124 return;
1125 if (sta->sa_query_count == 0) {
1126 /* Starting a new SA Query procedure */
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001127 os_get_reltime(&sta->sa_query_start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001128 }
1129 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
1130 sta->sa_query_trans_id = nbuf;
1131 sta->sa_query_count++;
1132
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001133 if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) {
1134 /*
1135 * We don't really care which ID is used here, so simply
1136 * hardcode this if the mostly theoretical os_get_random()
1137 * failure happens.
1138 */
1139 trans_id[0] = 0x12;
1140 trans_id[1] = 0x34;
1141 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001142
1143 timeout = hapd->conf->assoc_sa_query_retry_timeout;
1144 sec = ((timeout / 1000) * 1024) / 1000;
1145 usec = (timeout % 1000) * 1024;
1146 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
1147
1148 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1149 HOSTAPD_LEVEL_DEBUG,
1150 "association SA Query attempt %d", sta->sa_query_count);
1151
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001152 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001153}
1154
1155
1156void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1157{
1158 ap_sa_query_timer(hapd, sta);
1159}
1160
1161
1162void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1163{
1164 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1165 os_free(sta->sa_query_trans_id);
1166 sta->sa_query_trans_id = NULL;
1167 sta->sa_query_count = 0;
1168}
1169
1170#endif /* CONFIG_IEEE80211W */
1171
1172
Hai Shalom74f70d42019-02-11 14:42:39 -08001173const char * ap_sta_wpa_get_keyid(struct hostapd_data *hapd,
1174 struct sta_info *sta)
1175{
1176 struct hostapd_wpa_psk *psk;
1177 struct hostapd_ssid *ssid;
1178 const u8 *pmk;
1179 int pmk_len;
1180
1181 ssid = &hapd->conf->ssid;
1182
1183 pmk = wpa_auth_get_pmk(sta->wpa_sm, &pmk_len);
1184 if (!pmk || pmk_len != PMK_LEN)
1185 return NULL;
1186
1187 for (psk = ssid->wpa_psk; psk; psk = psk->next)
1188 if (os_memcmp(pmk, psk->psk, PMK_LEN) == 0)
1189 break;
1190 if (!psk)
1191 return NULL;
1192 if (!psk || !psk->keyid[0])
1193 return NULL;
1194
1195 return psk->keyid;
1196}
1197
1198
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
1200 int authorized)
1201{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001202 const u8 *dev_addr = NULL;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001203 char buf[100];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001204#ifdef CONFIG_P2P
1205 u8 addr[ETH_ALEN];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001206 u8 ip_addr_buf[4];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001207#endif /* CONFIG_P2P */
1208
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001209 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
1210 return;
1211
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001212 if (authorized)
1213 sta->flags |= WLAN_STA_AUTHORIZED;
1214 else
1215 sta->flags &= ~WLAN_STA_AUTHORIZED;
1216
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001217#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001218 if (hapd->p2p_group == NULL) {
1219 if (sta->p2p_ie != NULL &&
1220 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
1221 dev_addr = addr;
1222 } else
1223 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001224
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001225 if (dev_addr)
1226 os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
1227 MAC2STR(sta->addr), MAC2STR(dev_addr));
1228 else
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001229#endif /* CONFIG_P2P */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001230 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
1231
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001232 if (hapd->sta_authorized_cb)
1233 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
1234 sta->addr, authorized, dev_addr);
1235
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001236 if (authorized) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001237 const char *keyid;
1238 char keyid_buf[100];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001239 char ip_addr[100];
Hai Shalom74f70d42019-02-11 14:42:39 -08001240
1241 keyid_buf[0] = '\0';
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001242 ip_addr[0] = '\0';
1243#ifdef CONFIG_P2P
1244 if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) {
1245 os_snprintf(ip_addr, sizeof(ip_addr),
1246 " ip_addr=%u.%u.%u.%u",
1247 ip_addr_buf[0], ip_addr_buf[1],
1248 ip_addr_buf[2], ip_addr_buf[3]);
1249 }
1250#endif /* CONFIG_P2P */
1251
Hai Shalom74f70d42019-02-11 14:42:39 -08001252 keyid = ap_sta_wpa_get_keyid(hapd, sta);
1253 if (keyid) {
1254 os_snprintf(keyid_buf, sizeof(keyid_buf),
1255 " keyid=%s", keyid);
1256 }
1257
1258 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s",
1259 buf, ip_addr, keyid_buf);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001260
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001261 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001262 hapd->msg_ctx_parent != hapd->msg_ctx)
1263 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
Hai Shalom74f70d42019-02-11 14:42:39 -08001264 AP_STA_CONNECTED "%s%s%s",
1265 buf, ip_addr, keyid_buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001266 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001267 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
1268
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001269 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001270 hapd->msg_ctx_parent != hapd->msg_ctx)
1271 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
1272 AP_STA_DISCONNECTED "%s", buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001273 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001274
1275#ifdef CONFIG_FST
1276 if (hapd->iface->fst) {
1277 if (authorized)
1278 fst_notify_peer_connected(hapd->iface->fst, sta->addr);
1279 else
1280 fst_notify_peer_disconnected(hapd->iface->fst,
1281 sta->addr);
1282 }
1283#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001284}
1285
1286
1287void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
1288 const u8 *addr, u16 reason)
1289{
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001290 if (sta)
1291 wpa_printf(MSG_DEBUG, "%s: %s STA " MACSTR " reason=%u",
1292 hapd->conf->iface, __func__, MAC2STR(sta->addr),
1293 reason);
1294 else if (addr)
1295 wpa_printf(MSG_DEBUG, "%s: %s addr " MACSTR " reason=%u",
1296 hapd->conf->iface, __func__, MAC2STR(addr),
1297 reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001298
1299 if (sta == NULL && addr)
1300 sta = ap_get_sta(hapd, addr);
1301
1302 if (addr)
1303 hostapd_drv_sta_deauth(hapd, addr, reason);
1304
1305 if (sta == NULL)
1306 return;
1307 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001308 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1309 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001310 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001311 wpa_printf(MSG_DEBUG, "%s: %s: reschedule ap_handle_timer timeout "
Dmitry Shmidt04949592012-07-19 12:16:46 -07001312 "for " MACSTR " (%d seconds - "
1313 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001314 hapd->conf->iface, __func__, MAC2STR(sta->addr),
Dmitry Shmidt04949592012-07-19 12:16:46 -07001315 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001316 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001317 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
1318 ap_handle_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001319 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001320
Dmitry Shmidt29333592017-01-09 12:27:11 -08001321 if (hapd->iface->current_mode &&
1322 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
1323 /* Deauthentication is not used in DMG/IEEE 802.11ad;
1324 * disassociate the STA instead. */
1325 sta->disassoc_reason = reason;
1326 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
1327 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1328 eloop_register_timeout(hapd->iface->drv_flags &
1329 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ?
1330 2 : 0, 0, ap_sta_disassoc_cb_timeout,
1331 hapd, sta);
1332 return;
1333 }
1334
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001335 sta->deauth_reason = reason;
1336 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
1337 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1338 eloop_register_timeout(hapd->iface->drv_flags &
1339 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
1340 ap_sta_deauth_cb_timeout, hapd, sta);
1341}
1342
1343
1344void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
1345{
1346 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
1347 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
1348 return;
1349 }
1350 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
1351 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1352 ap_sta_deauth_cb_timeout(hapd, sta);
1353}
1354
1355
1356void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
1357{
1358 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
1359 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
1360 return;
1361 }
1362 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
1363 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1364 ap_sta_disassoc_cb_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001365}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001366
1367
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001368void ap_sta_clear_disconnect_timeouts(struct hostapd_data *hapd,
1369 struct sta_info *sta)
1370{
1371 if (eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta) > 0)
1372 wpa_printf(MSG_DEBUG,
1373 "%s: Removed ap_sta_deauth_cb_timeout timeout for "
1374 MACSTR,
1375 hapd->conf->iface, MAC2STR(sta->addr));
1376 if (eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta) > 0)
1377 wpa_printf(MSG_DEBUG,
1378 "%s: Removed ap_sta_disassoc_cb_timeout timeout for "
1379 MACSTR,
1380 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt29333592017-01-09 12:27:11 -08001381 if (eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta) > 0)
1382 {
1383 wpa_printf(MSG_DEBUG,
1384 "%s: Removed ap_sta_delayed_1x_auth_fail_cb timeout for "
1385 MACSTR,
1386 hapd->conf->iface, MAC2STR(sta->addr));
1387 if (sta->flags & WLAN_STA_WPS)
1388 hostapd_wps_eap_completed(hapd);
1389 }
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001390}
1391
1392
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001393int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen)
1394{
1395 int res;
1396
1397 buf[0] = '\0';
Roshan Pius3a1667e2018-07-03 15:17:14 -07001398 res = os_snprintf(buf, buflen, "%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 -08001399 (flags & WLAN_STA_AUTH ? "[AUTH]" : ""),
1400 (flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""),
1401 (flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : ""),
1402 (flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
1403 ""),
1404 (flags & WLAN_STA_SHORT_PREAMBLE ?
1405 "[SHORT_PREAMBLE]" : ""),
1406 (flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
1407 (flags & WLAN_STA_WMM ? "[WMM]" : ""),
1408 (flags & WLAN_STA_MFP ? "[MFP]" : ""),
1409 (flags & WLAN_STA_WPS ? "[WPS]" : ""),
1410 (flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""),
1411 (flags & WLAN_STA_WDS ? "[WDS]" : ""),
1412 (flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
1413 (flags & WLAN_STA_WPS2 ? "[WPS2]" : ""),
1414 (flags & WLAN_STA_GAS ? "[GAS]" : ""),
Roshan Pius3a1667e2018-07-03 15:17:14 -07001415 (flags & WLAN_STA_HT ? "[HT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001416 (flags & WLAN_STA_VHT ? "[VHT]" : ""),
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001417 (flags & WLAN_STA_VENDOR_VHT ? "[VENDOR_VHT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001418 (flags & WLAN_STA_WNM_SLEEP_MODE ?
1419 "[WNM_SLEEP_MODE]" : ""));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001420 if (os_snprintf_error(buflen, res))
1421 res = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001422
1423 return res;
1424}
Dmitry Shmidt29333592017-01-09 12:27:11 -08001425
1426
1427static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx)
1428{
1429 struct hostapd_data *hapd = eloop_ctx;
1430 struct sta_info *sta = timeout_ctx;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001431 u16 reason;
Dmitry Shmidt29333592017-01-09 12:27:11 -08001432
1433 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1434 "IEEE 802.1X: Scheduled disconnection of " MACSTR
1435 " after EAP-Failure", MAC2STR(sta->addr));
1436
Roshan Pius3a1667e2018-07-03 15:17:14 -07001437 reason = sta->disconnect_reason_code;
1438 if (!reason)
1439 reason = WLAN_REASON_IEEE_802_1X_AUTH_FAILED;
1440 ap_sta_disconnect(hapd, sta, sta->addr, reason);
Dmitry Shmidt29333592017-01-09 12:27:11 -08001441 if (sta->flags & WLAN_STA_WPS)
1442 hostapd_wps_eap_completed(hapd);
1443}
1444
1445
1446void ap_sta_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1447 struct sta_info *sta)
1448{
1449 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1450 "IEEE 802.1X: Force disconnection of " MACSTR
1451 " after EAP-Failure in 10 ms", MAC2STR(sta->addr));
1452
1453 /*
1454 * Add a small sleep to increase likelihood of previously requested
1455 * EAP-Failure TX getting out before this should the driver reorder
1456 * operations.
1457 */
1458 eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta);
1459 eloop_register_timeout(0, 10000, ap_sta_delayed_1x_auth_fail_cb,
1460 hapd, sta);
1461}
1462
1463
1464int ap_sta_pending_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1465 struct sta_info *sta)
1466{
1467 return eloop_is_timeout_registered(ap_sta_delayed_1x_auth_fail_cb,
1468 hapd, sta);
1469}