blob: b1fde3cf932ff4bc0c445bcbb4f345e5a01221f8 [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
169 if (sta->flags & WLAN_STA_WDS)
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--;
200 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
201 && 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--;
208 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
209 && hapd->iface->num_sta_no_short_preamble == 0)
210 set_beacon++;
211 }
212
213 if (sta->no_ht_gf_set) {
214 sta->no_ht_gf_set = 0;
215 hapd->iface->num_sta_ht_no_gf--;
216 }
217
218 if (sta->no_ht_set) {
219 sta->no_ht_set = 0;
220 hapd->iface->num_sta_no_ht--;
221 }
222
223 if (sta->ht_20mhz_set) {
224 sta->ht_20mhz_set = 0;
225 hapd->iface->num_sta_ht_20mhz--;
226 }
227
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700228#ifdef CONFIG_TAXONOMY
229 wpabuf_free(sta->probe_ie_taxonomy);
230 sta->probe_ie_taxonomy = NULL;
231 wpabuf_free(sta->assoc_ie_taxonomy);
232 sta->assoc_ie_taxonomy = NULL;
233#endif /* CONFIG_TAXONOMY */
234
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700235#ifdef CONFIG_IEEE80211N
236 ht40_intolerant_remove(hapd->iface, sta);
237#endif /* CONFIG_IEEE80211N */
238
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700239#ifdef CONFIG_P2P
240 if (sta->no_p2p_set) {
241 sta->no_p2p_set = 0;
242 hapd->num_sta_no_p2p--;
243 if (hapd->num_sta_no_p2p == 0)
244 hostapd_p2p_non_p2p_sta_disconnected(hapd);
245 }
246#endif /* CONFIG_P2P */
247
248#if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
249 if (hostapd_ht_operation_update(hapd->iface) > 0)
250 set_beacon++;
251#endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
252
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800253#ifdef CONFIG_MESH
254 if (hapd->mesh_sta_free_cb)
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800255 hapd->mesh_sta_free_cb(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800256#endif /* CONFIG_MESH */
257
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700258 if (set_beacon)
259 ieee802_11_set_beacons(hapd->iface);
260
Dmitry Shmidt04949592012-07-19 12:16:46 -0700261 wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
262 __func__, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700263 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
264 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800265 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800266 ap_sta_clear_disconnect_timeouts(hapd, sta);
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800267 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700268
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800269 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700270 wpa_auth_sta_deinit(sta->wpa_sm);
271 rsn_preauth_free_station(hapd, sta);
272#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt96571392013-10-14 12:54:46 -0700273 if (hapd->radius)
274 radius_client_flush_auth(hapd->radius, sta->addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700275#endif /* CONFIG_NO_RADIUS */
276
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800277#ifndef CONFIG_NO_VLAN
278 /*
279 * sta->wpa_sm->group needs to be released before so that
280 * vlan_remove_dynamic() can check that no stations are left on the
281 * AP_VLAN netdev.
282 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800283 if (sta->vlan_id)
284 vlan_remove_dynamic(hapd, sta->vlan_id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800285 if (sta->vlan_id_bound) {
286 /*
287 * Need to remove the STA entry before potentially removing the
288 * VLAN.
289 */
290 if (hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800291 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800292 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800293 sta->added_unassoc = 0;
294 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800295 vlan_remove_dynamic(hapd, sta->vlan_id_bound);
296 }
297#endif /* CONFIG_NO_VLAN */
298
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299 os_free(sta->challenge);
300
301#ifdef CONFIG_IEEE80211W
302 os_free(sta->sa_query_trans_id);
303 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
304#endif /* CONFIG_IEEE80211W */
305
306#ifdef CONFIG_P2P
307 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
308#endif /* CONFIG_P2P */
309
Dmitry Shmidt04949592012-07-19 12:16:46 -0700310#ifdef CONFIG_INTERWORKING
311 if (sta->gas_dialog) {
312 int i;
313 for (i = 0; i < GAS_DIALOG_MAX; i++)
314 gas_serv_dialog_clear(&sta->gas_dialog[i]);
315 os_free(sta->gas_dialog);
316 }
317#endif /* CONFIG_INTERWORKING */
318
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319 wpabuf_free(sta->wps_ie);
320 wpabuf_free(sta->p2p_ie);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800321 wpabuf_free(sta->hs20_ie);
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);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800328 hostapd_free_psk_list(sta->psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700329 os_free(sta->identity);
330 os_free(sta->radius_cui);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800331 os_free(sta->remediation_url);
332 wpabuf_free(sta->hs20_deauth_req);
333 os_free(sta->hs20_session_info_url);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700334
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800335#ifdef CONFIG_SAE
336 sae_clear_data(sta->sae);
337 os_free(sta->sae);
338#endif /* CONFIG_SAE */
339
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800340 mbo_ap_sta_free(sta);
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800341 os_free(sta->supp_op_classes);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800342
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800343#ifdef CONFIG_FILS
344 os_free(sta->fils_pending_assoc_req);
345 wpabuf_free(sta->fils_hlp_resp);
346 wpabuf_free(sta->hlp_dhcp_discover);
347 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700348#ifdef CONFIG_FILS_SK_PFS
349 crypto_ecdh_deinit(sta->fils_ecdh);
350 wpabuf_clear_free(sta->fils_dh_ss);
351 wpabuf_free(sta->fils_g_sta);
352#endif /* CONFIG_FILS_SK_PFS */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800353#endif /* CONFIG_FILS */
354
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700355#ifdef CONFIG_OWE
356 bin_clear_free(sta->owe_pmk, sta->owe_pmk_len);
357 crypto_ecdh_deinit(sta->owe_ecdh);
358#endif /* CONFIG_OWE */
359
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700360 os_free(sta);
361}
362
363
364void hostapd_free_stas(struct hostapd_data *hapd)
365{
366 struct sta_info *sta, *prev;
367
368 sta = hapd->sta_list;
369
370 while (sta) {
371 prev = sta;
372 if (sta->flags & WLAN_STA_AUTH) {
373 mlme_deauthenticate_indication(
374 hapd, sta, WLAN_REASON_UNSPECIFIED);
375 }
376 sta = sta->next;
377 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
378 MAC2STR(prev->addr));
379 ap_free_sta(hapd, prev);
380 }
381}
382
383
384/**
385 * ap_handle_timer - Per STA timer handler
386 * @eloop_ctx: struct hostapd_data *
387 * @timeout_ctx: struct sta_info *
388 *
389 * This function is called to check station activity and to remove inactive
390 * stations.
391 */
392void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
393{
394 struct hostapd_data *hapd = eloop_ctx;
395 struct sta_info *sta = timeout_ctx;
396 unsigned long next_time = 0;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700397 int reason;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700398
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800399 wpa_printf(MSG_DEBUG, "%s: %s: " MACSTR " flags=0x%x timeout_next=%d",
400 hapd->conf->iface, __func__, MAC2STR(sta->addr), sta->flags,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700401 sta->timeout_next);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700402 if (sta->timeout_next == STA_REMOVE) {
403 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
404 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
405 "local deauth request");
406 ap_free_sta(hapd, sta);
407 return;
408 }
409
410 if ((sta->flags & WLAN_STA_ASSOC) &&
411 (sta->timeout_next == STA_NULLFUNC ||
412 sta->timeout_next == STA_DISASSOC)) {
413 int inactive_sec;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700414 /*
415 * Add random value to timeout so that we don't end up bouncing
416 * all stations at the same time if we have lots of associated
417 * stations that are idle (but keep re-associating).
418 */
419 int fuzz = os_random() % 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700420 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
421 if (inactive_sec == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800422 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
423 "Check inactivity: Could not "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800424 "get station info from kernel driver for "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700425 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800426 /*
427 * The driver may not support this functionality.
428 * Anyway, try again after the next inactivity timeout,
429 * but do not disconnect the station now.
430 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700431 next_time = hapd->conf->ap_max_inactivity + fuzz;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800432 } else if (inactive_sec == -ENOENT) {
433 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
434 "Station " MACSTR " has lost its driver entry",
435 MAC2STR(sta->addr));
436
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800437 /* Avoid sending client probe on removed client */
438 sta->timeout_next = STA_DISASSOC;
439 goto skip_poll;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800440 } else if (inactive_sec < hapd->conf->ap_max_inactivity) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700441 /* station activity detected; reset timeout state */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800442 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
443 "Station " MACSTR " has been active %is ago",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700444 MAC2STR(sta->addr), inactive_sec);
445 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700446 next_time = hapd->conf->ap_max_inactivity + fuzz -
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700447 inactive_sec;
448 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800449 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
450 "Station " MACSTR " has been "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700451 "inactive too long: %d sec, max allowed: %d",
452 MAC2STR(sta->addr), inactive_sec,
453 hapd->conf->ap_max_inactivity);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800454
455 if (hapd->conf->skip_inactivity_poll)
456 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 }
458 }
459
460 if ((sta->flags & WLAN_STA_ASSOC) &&
461 sta->timeout_next == STA_DISASSOC &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800462 !(sta->flags & WLAN_STA_PENDING_POLL) &&
463 !hapd->conf->skip_inactivity_poll) {
464 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
465 " has ACKed data poll", MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466 /* data nullfunc frame poll did not produce TX errors; assume
467 * station ACKed it */
468 sta->timeout_next = STA_NULLFUNC;
469 next_time = hapd->conf->ap_max_inactivity;
470 }
471
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800472skip_poll:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700473 if (next_time) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700474 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
475 "for " MACSTR " (%lu seconds)",
476 __func__, MAC2STR(sta->addr), next_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700477 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
478 sta);
479 return;
480 }
481
482 if (sta->timeout_next == STA_NULLFUNC &&
483 (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800484 wpa_printf(MSG_DEBUG, " Polling STA");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700485 sta->flags |= WLAN_STA_PENDING_POLL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800486 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
487 sta->flags & WLAN_STA_WMM);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700488 } else if (sta->timeout_next != STA_REMOVE) {
489 int deauth = sta->timeout_next == STA_DEAUTH;
490
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800491 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
492 "Timeout, sending %s info to STA " MACSTR,
493 deauth ? "deauthentication" : "disassociation",
494 MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700495
496 if (deauth) {
497 hostapd_drv_sta_deauth(
498 hapd, sta->addr,
499 WLAN_REASON_PREV_AUTH_NOT_VALID);
500 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700501 reason = (sta->timeout_next == STA_DISASSOC) ?
502 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
503 WLAN_REASON_PREV_AUTH_NOT_VALID;
504
505 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700506 }
507 }
508
509 switch (sta->timeout_next) {
510 case STA_NULLFUNC:
511 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700512 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
513 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
514 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700515 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
516 hapd, sta);
517 break;
518 case STA_DISASSOC:
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700519 case STA_DISASSOC_FROM_CLI:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800520 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521 sta->flags &= ~WLAN_STA_ASSOC;
522 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
523 if (!sta->acct_terminate_cause)
524 sta->acct_terminate_cause =
525 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
526 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800527 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700528 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
529 HOSTAPD_LEVEL_INFO, "disassociated due to "
530 "inactivity");
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700531 reason = (sta->timeout_next == STA_DISASSOC) ?
532 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
533 WLAN_REASON_PREV_AUTH_NOT_VALID;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700534 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700535 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
536 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
537 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700538 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
539 hapd, sta);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700540 mlme_disassociate_indication(hapd, sta, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541 break;
542 case STA_DEAUTH:
543 case STA_REMOVE:
544 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
545 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800546 "inactivity (timer DEAUTH/REMOVE)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700547 if (!sta->acct_terminate_cause)
548 sta->acct_terminate_cause =
549 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
550 mlme_deauthenticate_indication(
551 hapd, sta,
552 WLAN_REASON_PREV_AUTH_NOT_VALID);
553 ap_free_sta(hapd, sta);
554 break;
555 }
556}
557
558
559static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
560{
561 struct hostapd_data *hapd = eloop_ctx;
562 struct sta_info *sta = timeout_ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800564 wpa_printf(MSG_DEBUG, "%s: Session timer for STA " MACSTR,
565 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700566 if (!(sta->flags & WLAN_STA_AUTH)) {
567 if (sta->flags & WLAN_STA_GAS) {
568 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
569 "entry " MACSTR, MAC2STR(sta->addr));
570 ap_free_sta(hapd, sta);
571 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700572 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700573 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700574
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700575 hostapd_drv_sta_deauth(hapd, sta->addr,
576 WLAN_REASON_PREV_AUTH_NOT_VALID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700577 mlme_deauthenticate_indication(hapd, sta,
578 WLAN_REASON_PREV_AUTH_NOT_VALID);
579 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
580 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
581 "session timeout");
582 sta->acct_terminate_cause =
583 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584 ap_free_sta(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700585}
586
587
Dmitry Shmidt54605472013-11-08 11:10:19 -0800588void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta,
589 u32 session_timeout)
590{
591 if (eloop_replenish_timeout(session_timeout, 0,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800592 ap_handle_session_timer, hapd, sta) == 1) {
Dmitry Shmidt54605472013-11-08 11:10:19 -0800593 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
594 HOSTAPD_LEVEL_DEBUG, "setting session timeout "
595 "to %d seconds", session_timeout);
596 }
597}
598
599
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700600void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
601 u32 session_timeout)
602{
603 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
604 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
605 "seconds", session_timeout);
606 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
607 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
608 hapd, sta);
609}
610
611
612void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
613{
614 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
615}
616
617
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800618static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx)
619{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700620#ifdef CONFIG_WNM_AP
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800621 struct hostapd_data *hapd = eloop_ctx;
622 struct sta_info *sta = timeout_ctx;
623
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800624 wpa_printf(MSG_DEBUG, "%s: WNM: Session warning time reached for "
625 MACSTR, hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800626 if (sta->hs20_session_info_url == NULL)
627 return;
628
629 wnm_send_ess_disassoc_imminent(hapd, sta, sta->hs20_session_info_url,
630 sta->hs20_disassoc_timer);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700631#endif /* CONFIG_WNM_AP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800632}
633
634
635void ap_sta_session_warning_timeout(struct hostapd_data *hapd,
636 struct sta_info *sta, int warning_time)
637{
638 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
639 eloop_register_timeout(warning_time, 0, ap_handle_session_warning_timer,
640 hapd, sta);
641}
642
643
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700644struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
645{
646 struct sta_info *sta;
647
648 sta = ap_get_sta(hapd, addr);
649 if (sta)
650 return sta;
651
652 wpa_printf(MSG_DEBUG, " New STA");
653 if (hapd->num_sta >= hapd->conf->max_num_sta) {
654 /* FIX: might try to remove some old STAs first? */
655 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
656 hapd->num_sta, hapd->conf->max_num_sta);
657 return NULL;
658 }
659
660 sta = os_zalloc(sizeof(struct sta_info));
661 if (sta == NULL) {
662 wpa_printf(MSG_ERROR, "malloc failed");
663 return NULL;
664 }
665 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800666 if (accounting_sta_get_id(hapd, sta) < 0) {
667 os_free(sta);
668 return NULL;
669 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700670
Dmitry Shmidt01904cf2013-12-05 11:08:35 -0800671 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
672 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
673 "for " MACSTR " (%d seconds - ap_max_inactivity)",
674 __func__, MAC2STR(addr),
675 hapd->conf->ap_max_inactivity);
676 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
677 ap_handle_timer, hapd, sta);
678 }
679
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700680 /* initialize STA info data */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700681 os_memcpy(sta->addr, addr, ETH_ALEN);
682 sta->next = hapd->sta_list;
683 hapd->sta_list = sta;
684 hapd->num_sta++;
685 ap_sta_hash_add(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700686 ap_sta_remove_in_other_bss(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800687 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
688 dl_list_init(&sta->ip6addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700689
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700690#ifdef CONFIG_TAXONOMY
691 sta_track_claim_taxonomy_info(hapd->iface, addr,
692 &sta->probe_ie_taxonomy);
693#endif /* CONFIG_TAXONOMY */
694
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700695 return sta;
696}
697
698
699static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
700{
701 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
702
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800703 if (sta->ipaddr)
704 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
705 ap_sta_ip6addr_del(hapd, sta);
706
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800707 wpa_printf(MSG_DEBUG, "%s: Removing STA " MACSTR " from kernel driver",
708 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700709 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
710 sta->flags & WLAN_STA_ASSOC) {
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800711 wpa_printf(MSG_DEBUG, "%s: Could not remove station " MACSTR
712 " from kernel driver",
713 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700714 return -1;
715 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800716 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717 return 0;
718}
719
720
721static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
722 struct sta_info *sta)
723{
724 struct hostapd_iface *iface = hapd->iface;
725 size_t i;
726
727 for (i = 0; i < iface->num_bss; i++) {
728 struct hostapd_data *bss = iface->bss[i];
729 struct sta_info *sta2;
730 /* bss should always be set during operation, but it may be
731 * NULL during reconfiguration. Assume the STA is not
732 * associated to another BSS in that case to avoid NULL pointer
733 * dereferences. */
734 if (bss == hapd || bss == NULL)
735 continue;
736 sta2 = ap_get_sta(bss, sta->addr);
737 if (!sta2)
738 continue;
739
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800740 wpa_printf(MSG_DEBUG, "%s: disconnect old STA " MACSTR
741 " association from another BSS %s",
742 hapd->conf->iface, MAC2STR(sta2->addr),
743 bss->conf->iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700744 ap_sta_disconnect(bss, sta2, sta2->addr,
745 WLAN_REASON_PREV_AUTH_NOT_VALID);
746 }
747}
748
749
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800750static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
751{
752 struct hostapd_data *hapd = eloop_ctx;
753 struct sta_info *sta = timeout_ctx;
754
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800755 wpa_printf(MSG_DEBUG, "%s: Disassociation callback for STA " MACSTR,
756 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800757 ap_sta_remove(hapd, sta);
758 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
759}
760
761
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
763 u16 reason)
764{
765 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
766 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800767 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800768 if (hapd->iface->current_mode &&
769 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
770 /* Skip deauthentication in DMG/IEEE 802.11ad */
771 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
772 WLAN_STA_ASSOC_REQ_OK);
773 sta->timeout_next = STA_REMOVE;
774 } else {
775 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
776 sta->timeout_next = STA_DEAUTH;
777 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800778 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700779 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
780 "for " MACSTR " (%d seconds - "
781 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
782 __func__, MAC2STR(sta->addr),
783 AP_MAX_INACTIVITY_AFTER_DISASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700784 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
785 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
786 ap_handle_timer, hapd, sta);
787 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800788 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700789
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800790 sta->disassoc_reason = reason;
791 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
792 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
793 eloop_register_timeout(hapd->iface->drv_flags &
794 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
795 ap_sta_disassoc_cb_timeout, hapd, sta);
796}
797
798
799static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
800{
801 struct hostapd_data *hapd = eloop_ctx;
802 struct sta_info *sta = timeout_ctx;
803
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800804 wpa_printf(MSG_DEBUG, "%s: Deauthentication callback for STA " MACSTR,
805 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800806 ap_sta_remove(hapd, sta);
807 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808}
809
810
811void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
812 u16 reason)
813{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800814 if (hapd->iface->current_mode &&
815 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
816 /* Deauthentication is not used in DMG/IEEE 802.11ad;
817 * disassociate the STA instead. */
818 ap_sta_disassociate(hapd, sta, reason);
819 return;
820 }
821
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700822 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
823 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800824 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
825 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800826 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700827 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700828 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
829 "for " MACSTR " (%d seconds - "
830 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
831 __func__, MAC2STR(sta->addr),
832 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700833 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
834 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
835 ap_handle_timer, hapd, sta);
836 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800837 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800839 sta->deauth_reason = reason;
840 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
841 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
842 eloop_register_timeout(hapd->iface->drv_flags &
843 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
844 ap_sta_deauth_cb_timeout, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845}
846
847
Dmitry Shmidt04949592012-07-19 12:16:46 -0700848#ifdef CONFIG_WPS
849int ap_sta_wps_cancel(struct hostapd_data *hapd,
850 struct sta_info *sta, void *ctx)
851{
852 if (sta && (sta->flags & WLAN_STA_WPS)) {
853 ap_sta_deauthenticate(hapd, sta,
854 WLAN_REASON_PREV_AUTH_NOT_VALID);
855 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
856 __func__, MAC2STR(sta->addr));
857 return 1;
858 }
859
860 return 0;
861}
862#endif /* CONFIG_WPS */
863
864
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800865static int ap_sta_get_free_vlan_id(struct hostapd_data *hapd)
866{
867 struct hostapd_vlan *vlan;
868 int vlan_id = MAX_VLAN_ID + 2;
869
870retry:
871 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
872 if (vlan->vlan_id == vlan_id) {
873 vlan_id++;
874 goto retry;
875 }
876 }
877 return vlan_id;
878}
879
880
881int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta,
882 struct vlan_description *vlan_desc)
883{
884 struct hostapd_vlan *vlan = NULL, *wildcard_vlan = NULL;
885 int old_vlan_id, vlan_id = 0, ret = 0;
886
887 if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED)
888 vlan_desc = NULL;
889
890 /* Check if there is something to do */
891 if (hapd->conf->ssid.per_sta_vif && !sta->vlan_id) {
892 /* This sta is lacking its own vif */
893 } else if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED &&
894 !hapd->conf->ssid.per_sta_vif && sta->vlan_id) {
895 /* sta->vlan_id needs to be reset */
896 } else if (!vlan_compare(vlan_desc, sta->vlan_desc)) {
897 return 0; /* nothing to change */
898 }
899
900 /* Now the real VLAN changed or the STA just needs its own vif */
901 if (hapd->conf->ssid.per_sta_vif) {
902 /* Assign a new vif, always */
903 /* find a free vlan_id sufficiently big */
904 vlan_id = ap_sta_get_free_vlan_id(hapd);
905 /* Get wildcard VLAN */
906 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
907 if (vlan->vlan_id == VLAN_ID_WILDCARD)
908 break;
909 }
910 if (!vlan) {
911 hostapd_logger(hapd, sta->addr,
912 HOSTAPD_MODULE_IEEE80211,
913 HOSTAPD_LEVEL_DEBUG,
914 "per_sta_vif missing wildcard");
915 vlan_id = 0;
916 ret = -1;
917 goto done;
918 }
919 } else if (vlan_desc && vlan_desc->notempty) {
920 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
921 if (!vlan_compare(&vlan->vlan_desc, vlan_desc))
922 break;
923 if (vlan->vlan_id == VLAN_ID_WILDCARD)
924 wildcard_vlan = vlan;
925 }
926 if (vlan) {
927 vlan_id = vlan->vlan_id;
928 } else if (wildcard_vlan) {
929 vlan = wildcard_vlan;
930 vlan_id = vlan_desc->untagged;
931 if (vlan_desc->tagged[0]) {
932 /* Tagged VLAN configuration */
933 vlan_id = ap_sta_get_free_vlan_id(hapd);
934 }
935 } else {
936 hostapd_logger(hapd, sta->addr,
937 HOSTAPD_MODULE_IEEE80211,
938 HOSTAPD_LEVEL_DEBUG,
939 "missing vlan and wildcard for vlan=%d%s",
940 vlan_desc->untagged,
941 vlan_desc->tagged[0] ? "+" : "");
942 vlan_id = 0;
943 ret = -1;
944 goto done;
945 }
946 }
947
948 if (vlan && vlan->vlan_id == VLAN_ID_WILDCARD) {
949 vlan = vlan_add_dynamic(hapd, vlan, vlan_id, vlan_desc);
950 if (vlan == NULL) {
951 hostapd_logger(hapd, sta->addr,
952 HOSTAPD_MODULE_IEEE80211,
953 HOSTAPD_LEVEL_DEBUG,
954 "could not add dynamic VLAN interface for vlan=%d%s",
955 vlan_desc ? vlan_desc->untagged : -1,
956 (vlan_desc && vlan_desc->tagged[0]) ?
957 "+" : "");
958 vlan_id = 0;
959 ret = -1;
960 goto done;
961 }
962
963 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
964 HOSTAPD_LEVEL_DEBUG,
965 "added new dynamic VLAN interface '%s'",
966 vlan->ifname);
967 } else if (vlan && vlan->dynamic_vlan > 0) {
968 vlan->dynamic_vlan++;
969 hostapd_logger(hapd, sta->addr,
970 HOSTAPD_MODULE_IEEE80211,
971 HOSTAPD_LEVEL_DEBUG,
972 "updated existing dynamic VLAN interface '%s'",
973 vlan->ifname);
974 }
975done:
976 old_vlan_id = sta->vlan_id;
977 sta->vlan_id = vlan_id;
978 sta->vlan_desc = vlan ? &vlan->vlan_desc : NULL;
979
980 if (vlan_id != old_vlan_id && old_vlan_id)
981 vlan_remove_dynamic(hapd, old_vlan_id);
982
983 return ret;
984}
985
986
Dmitry Shmidt83474442015-04-15 13:47:09 -0700987int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988{
989#ifndef CONFIG_NO_VLAN
990 const char *iface;
991 struct hostapd_vlan *vlan = NULL;
992 int ret;
Dmitry Shmidt83474442015-04-15 13:47:09 -0700993 int old_vlanid = sta->vlan_id_bound;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700994
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700995 iface = hapd->conf->iface;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700996 if (hapd->conf->ssid.vlan[0])
997 iface = hapd->conf->ssid.vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700998
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800999 if (sta->vlan_id > 0) {
1000 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001001 if (vlan->vlan_id == sta->vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001002 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001003 }
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001004 if (vlan)
1005 iface = vlan->ifname;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001006 }
1007
Dmitry Shmidt83474442015-04-15 13:47:09 -07001008 /*
1009 * Do not increment ref counters if the VLAN ID remains same, but do
1010 * not skip hostapd_drv_set_sta_vlan() as hostapd_drv_sta_remove() might
1011 * have been called before.
1012 */
1013 if (sta->vlan_id == old_vlanid)
1014 goto skip_counting;
1015
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001016 if (sta->vlan_id > 0 && vlan == NULL) {
1017 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1018 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
1019 "binding station to (vlan_id=%d)",
1020 sta->vlan_id);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001021 ret = -1;
1022 goto done;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001023 } else if (vlan && vlan->dynamic_vlan > 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001024 vlan->dynamic_vlan++;
1025 hostapd_logger(hapd, sta->addr,
1026 HOSTAPD_MODULE_IEEE80211,
1027 HOSTAPD_LEVEL_DEBUG,
1028 "updated existing dynamic VLAN interface '%s'",
1029 iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001030 }
1031
Dmitry Shmidt83474442015-04-15 13:47:09 -07001032 /* ref counters have been increased, so mark the station */
1033 sta->vlan_id_bound = sta->vlan_id;
1034
1035skip_counting:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001036 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1037 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
1038 "'%s'", iface);
1039
1040 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
1041 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
1042
1043 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
1044 if (ret < 0) {
1045 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1046 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
1047 "entry to vlan_id=%d", sta->vlan_id);
1048 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001049
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001050 /* During 1x reauth, if the vlan id changes, then remove the old id. */
Dmitry Shmidt83474442015-04-15 13:47:09 -07001051 if (old_vlanid > 0 && old_vlanid != sta->vlan_id)
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001052 vlan_remove_dynamic(hapd, old_vlanid);
Dmitry Shmidt83474442015-04-15 13:47:09 -07001053done:
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001054
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001055 return ret;
1056#else /* CONFIG_NO_VLAN */
1057 return 0;
1058#endif /* CONFIG_NO_VLAN */
1059}
1060
1061
1062#ifdef CONFIG_IEEE80211W
1063
1064int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
1065{
1066 u32 tu;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001067 struct os_reltime now, passed;
1068 os_get_reltime(&now);
1069 os_reltime_sub(&now, &sta->sa_query_start, &passed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001070 tu = (passed.sec * 1000000 + passed.usec) / 1024;
1071 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
1072 hostapd_logger(hapd, sta->addr,
1073 HOSTAPD_MODULE_IEEE80211,
1074 HOSTAPD_LEVEL_DEBUG,
1075 "association SA Query timed out");
1076 sta->sa_query_timed_out = 1;
1077 os_free(sta->sa_query_trans_id);
1078 sta->sa_query_trans_id = NULL;
1079 sta->sa_query_count = 0;
1080 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1081 return 1;
1082 }
1083
1084 return 0;
1085}
1086
1087
1088static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
1089{
1090 struct hostapd_data *hapd = eloop_ctx;
1091 struct sta_info *sta = timeout_ctx;
1092 unsigned int timeout, sec, usec;
1093 u8 *trans_id, *nbuf;
1094
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001095 wpa_printf(MSG_DEBUG, "%s: SA Query timer for STA " MACSTR
1096 " (count=%d)",
1097 hapd->conf->iface, MAC2STR(sta->addr), sta->sa_query_count);
1098
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001099 if (sta->sa_query_count > 0 &&
1100 ap_check_sa_query_timeout(hapd, sta))
1101 return;
1102
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001103 nbuf = os_realloc_array(sta->sa_query_trans_id,
1104 sta->sa_query_count + 1,
1105 WLAN_SA_QUERY_TR_ID_LEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001106 if (nbuf == NULL)
1107 return;
1108 if (sta->sa_query_count == 0) {
1109 /* Starting a new SA Query procedure */
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001110 os_get_reltime(&sta->sa_query_start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111 }
1112 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
1113 sta->sa_query_trans_id = nbuf;
1114 sta->sa_query_count++;
1115
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001116 if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) {
1117 /*
1118 * We don't really care which ID is used here, so simply
1119 * hardcode this if the mostly theoretical os_get_random()
1120 * failure happens.
1121 */
1122 trans_id[0] = 0x12;
1123 trans_id[1] = 0x34;
1124 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001125
1126 timeout = hapd->conf->assoc_sa_query_retry_timeout;
1127 sec = ((timeout / 1000) * 1024) / 1000;
1128 usec = (timeout % 1000) * 1024;
1129 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
1130
1131 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1132 HOSTAPD_LEVEL_DEBUG,
1133 "association SA Query attempt %d", sta->sa_query_count);
1134
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001135 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001136}
1137
1138
1139void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1140{
1141 ap_sa_query_timer(hapd, sta);
1142}
1143
1144
1145void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1146{
1147 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1148 os_free(sta->sa_query_trans_id);
1149 sta->sa_query_trans_id = NULL;
1150 sta->sa_query_count = 0;
1151}
1152
1153#endif /* CONFIG_IEEE80211W */
1154
1155
1156void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
1157 int authorized)
1158{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001159 const u8 *dev_addr = NULL;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001160 char buf[100];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001161#ifdef CONFIG_P2P
1162 u8 addr[ETH_ALEN];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001163 u8 ip_addr_buf[4];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001164#endif /* CONFIG_P2P */
1165
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001166 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
1167 return;
1168
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001169 if (authorized)
1170 sta->flags |= WLAN_STA_AUTHORIZED;
1171 else
1172 sta->flags &= ~WLAN_STA_AUTHORIZED;
1173
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001174#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001175 if (hapd->p2p_group == NULL) {
1176 if (sta->p2p_ie != NULL &&
1177 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
1178 dev_addr = addr;
1179 } else
1180 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001181
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001182 if (dev_addr)
1183 os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
1184 MAC2STR(sta->addr), MAC2STR(dev_addr));
1185 else
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001186#endif /* CONFIG_P2P */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001187 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
1188
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001189 if (hapd->sta_authorized_cb)
1190 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
1191 sta->addr, authorized, dev_addr);
1192
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001193 if (authorized) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001194 char ip_addr[100];
1195 ip_addr[0] = '\0';
1196#ifdef CONFIG_P2P
1197 if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) {
1198 os_snprintf(ip_addr, sizeof(ip_addr),
1199 " ip_addr=%u.%u.%u.%u",
1200 ip_addr_buf[0], ip_addr_buf[1],
1201 ip_addr_buf[2], ip_addr_buf[3]);
1202 }
1203#endif /* CONFIG_P2P */
1204
1205 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s",
1206 buf, ip_addr);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001207
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001208 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001209 hapd->msg_ctx_parent != hapd->msg_ctx)
1210 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001211 AP_STA_CONNECTED "%s%s",
1212 buf, ip_addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001213 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001214 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
1215
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001216 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001217 hapd->msg_ctx_parent != hapd->msg_ctx)
1218 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
1219 AP_STA_DISCONNECTED "%s", buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001220 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001221
1222#ifdef CONFIG_FST
1223 if (hapd->iface->fst) {
1224 if (authorized)
1225 fst_notify_peer_connected(hapd->iface->fst, sta->addr);
1226 else
1227 fst_notify_peer_disconnected(hapd->iface->fst,
1228 sta->addr);
1229 }
1230#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001231}
1232
1233
1234void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
1235 const u8 *addr, u16 reason)
1236{
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001237 if (sta)
1238 wpa_printf(MSG_DEBUG, "%s: %s STA " MACSTR " reason=%u",
1239 hapd->conf->iface, __func__, MAC2STR(sta->addr),
1240 reason);
1241 else if (addr)
1242 wpa_printf(MSG_DEBUG, "%s: %s addr " MACSTR " reason=%u",
1243 hapd->conf->iface, __func__, MAC2STR(addr),
1244 reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245
1246 if (sta == NULL && addr)
1247 sta = ap_get_sta(hapd, addr);
1248
1249 if (addr)
1250 hostapd_drv_sta_deauth(hapd, addr, reason);
1251
1252 if (sta == NULL)
1253 return;
1254 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001255 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1256 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001257 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001258 wpa_printf(MSG_DEBUG, "%s: %s: reschedule ap_handle_timer timeout "
Dmitry Shmidt04949592012-07-19 12:16:46 -07001259 "for " MACSTR " (%d seconds - "
1260 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001261 hapd->conf->iface, __func__, MAC2STR(sta->addr),
Dmitry Shmidt04949592012-07-19 12:16:46 -07001262 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001263 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001264 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
1265 ap_handle_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001266 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001267
Dmitry Shmidt29333592017-01-09 12:27:11 -08001268 if (hapd->iface->current_mode &&
1269 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
1270 /* Deauthentication is not used in DMG/IEEE 802.11ad;
1271 * disassociate the STA instead. */
1272 sta->disassoc_reason = reason;
1273 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
1274 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1275 eloop_register_timeout(hapd->iface->drv_flags &
1276 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ?
1277 2 : 0, 0, ap_sta_disassoc_cb_timeout,
1278 hapd, sta);
1279 return;
1280 }
1281
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001282 sta->deauth_reason = reason;
1283 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
1284 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1285 eloop_register_timeout(hapd->iface->drv_flags &
1286 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
1287 ap_sta_deauth_cb_timeout, hapd, sta);
1288}
1289
1290
1291void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
1292{
1293 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
1294 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
1295 return;
1296 }
1297 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
1298 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1299 ap_sta_deauth_cb_timeout(hapd, sta);
1300}
1301
1302
1303void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
1304{
1305 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
1306 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
1307 return;
1308 }
1309 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
1310 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1311 ap_sta_disassoc_cb_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001312}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001313
1314
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001315void ap_sta_clear_disconnect_timeouts(struct hostapd_data *hapd,
1316 struct sta_info *sta)
1317{
1318 if (eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta) > 0)
1319 wpa_printf(MSG_DEBUG,
1320 "%s: Removed ap_sta_deauth_cb_timeout timeout for "
1321 MACSTR,
1322 hapd->conf->iface, MAC2STR(sta->addr));
1323 if (eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta) > 0)
1324 wpa_printf(MSG_DEBUG,
1325 "%s: Removed ap_sta_disassoc_cb_timeout timeout for "
1326 MACSTR,
1327 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt29333592017-01-09 12:27:11 -08001328 if (eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta) > 0)
1329 {
1330 wpa_printf(MSG_DEBUG,
1331 "%s: Removed ap_sta_delayed_1x_auth_fail_cb timeout for "
1332 MACSTR,
1333 hapd->conf->iface, MAC2STR(sta->addr));
1334 if (sta->flags & WLAN_STA_WPS)
1335 hostapd_wps_eap_completed(hapd);
1336 }
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001337}
1338
1339
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001340int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen)
1341{
1342 int res;
1343
1344 buf[0] = '\0';
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001345 res = os_snprintf(buf, buflen, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001346 (flags & WLAN_STA_AUTH ? "[AUTH]" : ""),
1347 (flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""),
1348 (flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : ""),
1349 (flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
1350 ""),
1351 (flags & WLAN_STA_SHORT_PREAMBLE ?
1352 "[SHORT_PREAMBLE]" : ""),
1353 (flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
1354 (flags & WLAN_STA_WMM ? "[WMM]" : ""),
1355 (flags & WLAN_STA_MFP ? "[MFP]" : ""),
1356 (flags & WLAN_STA_WPS ? "[WPS]" : ""),
1357 (flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""),
1358 (flags & WLAN_STA_WDS ? "[WDS]" : ""),
1359 (flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
1360 (flags & WLAN_STA_WPS2 ? "[WPS2]" : ""),
1361 (flags & WLAN_STA_GAS ? "[GAS]" : ""),
1362 (flags & WLAN_STA_VHT ? "[VHT]" : ""),
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001363 (flags & WLAN_STA_VENDOR_VHT ? "[VENDOR_VHT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001364 (flags & WLAN_STA_WNM_SLEEP_MODE ?
1365 "[WNM_SLEEP_MODE]" : ""));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001366 if (os_snprintf_error(buflen, res))
1367 res = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001368
1369 return res;
1370}
Dmitry Shmidt29333592017-01-09 12:27:11 -08001371
1372
1373static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx)
1374{
1375 struct hostapd_data *hapd = eloop_ctx;
1376 struct sta_info *sta = timeout_ctx;
1377
1378 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1379 "IEEE 802.1X: Scheduled disconnection of " MACSTR
1380 " after EAP-Failure", MAC2STR(sta->addr));
1381
1382 ap_sta_disconnect(hapd, sta, sta->addr,
1383 WLAN_REASON_IEEE_802_1X_AUTH_FAILED);
1384 if (sta->flags & WLAN_STA_WPS)
1385 hostapd_wps_eap_completed(hapd);
1386}
1387
1388
1389void ap_sta_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1390 struct sta_info *sta)
1391{
1392 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1393 "IEEE 802.1X: Force disconnection of " MACSTR
1394 " after EAP-Failure in 10 ms", MAC2STR(sta->addr));
1395
1396 /*
1397 * Add a small sleep to increase likelihood of previously requested
1398 * EAP-Failure TX getting out before this should the driver reorder
1399 * operations.
1400 */
1401 eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta);
1402 eloop_register_timeout(0, 10000, ap_sta_delayed_1x_auth_fail_cb,
1403 hapd, sta);
1404}
1405
1406
1407int ap_sta_pending_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1408 struct sta_info *sta)
1409{
1410 return eloop_is_timeout_registered(ap_sta_delayed_1x_auth_fail_cb,
1411 hapd, sta);
1412}