blob: 179cf43b60b17c267d9fe9622370c3c82fad9e4b [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--;
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);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800331 hostapd_free_psk_list(sta->psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700332 os_free(sta->identity);
333 os_free(sta->radius_cui);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800334 os_free(sta->remediation_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700335 os_free(sta->t_c_url);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800336 wpabuf_free(sta->hs20_deauth_req);
337 os_free(sta->hs20_session_info_url);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800339#ifdef CONFIG_SAE
340 sae_clear_data(sta->sae);
341 os_free(sta->sae);
342#endif /* CONFIG_SAE */
343
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800344 mbo_ap_sta_free(sta);
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800345 os_free(sta->supp_op_classes);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800346
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800347#ifdef CONFIG_FILS
348 os_free(sta->fils_pending_assoc_req);
349 wpabuf_free(sta->fils_hlp_resp);
350 wpabuf_free(sta->hlp_dhcp_discover);
351 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700352#ifdef CONFIG_FILS_SK_PFS
353 crypto_ecdh_deinit(sta->fils_ecdh);
354 wpabuf_clear_free(sta->fils_dh_ss);
355 wpabuf_free(sta->fils_g_sta);
356#endif /* CONFIG_FILS_SK_PFS */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800357#endif /* CONFIG_FILS */
358
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700359#ifdef CONFIG_OWE
360 bin_clear_free(sta->owe_pmk, sta->owe_pmk_len);
361 crypto_ecdh_deinit(sta->owe_ecdh);
362#endif /* CONFIG_OWE */
363
Roshan Pius3a1667e2018-07-03 15:17:14 -0700364 os_free(sta->ext_capability);
365
366#ifdef CONFIG_WNM_AP
367 eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta);
368#endif /* CONFIG_WNM_AP */
369
370 os_free(sta->ifname_wds);
371
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700372 os_free(sta);
373}
374
375
376void hostapd_free_stas(struct hostapd_data *hapd)
377{
378 struct sta_info *sta, *prev;
379
380 sta = hapd->sta_list;
381
382 while (sta) {
383 prev = sta;
384 if (sta->flags & WLAN_STA_AUTH) {
385 mlme_deauthenticate_indication(
386 hapd, sta, WLAN_REASON_UNSPECIFIED);
387 }
388 sta = sta->next;
389 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
390 MAC2STR(prev->addr));
391 ap_free_sta(hapd, prev);
392 }
393}
394
395
396/**
397 * ap_handle_timer - Per STA timer handler
398 * @eloop_ctx: struct hostapd_data *
399 * @timeout_ctx: struct sta_info *
400 *
401 * This function is called to check station activity and to remove inactive
402 * stations.
403 */
404void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
405{
406 struct hostapd_data *hapd = eloop_ctx;
407 struct sta_info *sta = timeout_ctx;
408 unsigned long next_time = 0;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700409 int reason;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700410
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800411 wpa_printf(MSG_DEBUG, "%s: %s: " MACSTR " flags=0x%x timeout_next=%d",
412 hapd->conf->iface, __func__, MAC2STR(sta->addr), sta->flags,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700413 sta->timeout_next);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700414 if (sta->timeout_next == STA_REMOVE) {
415 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
416 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
417 "local deauth request");
418 ap_free_sta(hapd, sta);
419 return;
420 }
421
422 if ((sta->flags & WLAN_STA_ASSOC) &&
423 (sta->timeout_next == STA_NULLFUNC ||
424 sta->timeout_next == STA_DISASSOC)) {
425 int inactive_sec;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700426 /*
427 * Add random value to timeout so that we don't end up bouncing
428 * all stations at the same time if we have lots of associated
429 * stations that are idle (but keep re-associating).
430 */
431 int fuzz = os_random() % 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700432 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
433 if (inactive_sec == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800434 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
435 "Check inactivity: Could not "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800436 "get station info from kernel driver for "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700437 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800438 /*
439 * The driver may not support this functionality.
440 * Anyway, try again after the next inactivity timeout,
441 * but do not disconnect the station now.
442 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700443 next_time = hapd->conf->ap_max_inactivity + fuzz;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800444 } else if (inactive_sec == -ENOENT) {
445 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
446 "Station " MACSTR " has lost its driver entry",
447 MAC2STR(sta->addr));
448
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800449 /* Avoid sending client probe on removed client */
450 sta->timeout_next = STA_DISASSOC;
451 goto skip_poll;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800452 } else if (inactive_sec < hapd->conf->ap_max_inactivity) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700453 /* station activity detected; reset timeout state */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800454 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
455 "Station " MACSTR " has been active %is ago",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700456 MAC2STR(sta->addr), inactive_sec);
457 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700458 next_time = hapd->conf->ap_max_inactivity + fuzz -
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700459 inactive_sec;
460 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800461 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
462 "Station " MACSTR " has been "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700463 "inactive too long: %d sec, max allowed: %d",
464 MAC2STR(sta->addr), inactive_sec,
465 hapd->conf->ap_max_inactivity);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800466
467 if (hapd->conf->skip_inactivity_poll)
468 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700469 }
470 }
471
472 if ((sta->flags & WLAN_STA_ASSOC) &&
473 sta->timeout_next == STA_DISASSOC &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800474 !(sta->flags & WLAN_STA_PENDING_POLL) &&
475 !hapd->conf->skip_inactivity_poll) {
476 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
477 " has ACKed data poll", MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700478 /* data nullfunc frame poll did not produce TX errors; assume
479 * station ACKed it */
480 sta->timeout_next = STA_NULLFUNC;
481 next_time = hapd->conf->ap_max_inactivity;
482 }
483
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800484skip_poll:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700485 if (next_time) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700486 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
487 "for " MACSTR " (%lu seconds)",
488 __func__, MAC2STR(sta->addr), next_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700489 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
490 sta);
491 return;
492 }
493
494 if (sta->timeout_next == STA_NULLFUNC &&
495 (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800496 wpa_printf(MSG_DEBUG, " Polling STA");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700497 sta->flags |= WLAN_STA_PENDING_POLL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800498 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
499 sta->flags & WLAN_STA_WMM);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700500 } else if (sta->timeout_next != STA_REMOVE) {
501 int deauth = sta->timeout_next == STA_DEAUTH;
502
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800503 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
504 "Timeout, sending %s info to STA " MACSTR,
505 deauth ? "deauthentication" : "disassociation",
506 MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700507
508 if (deauth) {
509 hostapd_drv_sta_deauth(
510 hapd, sta->addr,
511 WLAN_REASON_PREV_AUTH_NOT_VALID);
512 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700513 reason = (sta->timeout_next == STA_DISASSOC) ?
514 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
515 WLAN_REASON_PREV_AUTH_NOT_VALID;
516
517 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518 }
519 }
520
521 switch (sta->timeout_next) {
522 case STA_NULLFUNC:
523 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700524 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
525 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
526 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700527 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
528 hapd, sta);
529 break;
530 case STA_DISASSOC:
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700531 case STA_DISASSOC_FROM_CLI:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800532 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700533 sta->flags &= ~WLAN_STA_ASSOC;
534 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
535 if (!sta->acct_terminate_cause)
536 sta->acct_terminate_cause =
537 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
538 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800539 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700540 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
541 HOSTAPD_LEVEL_INFO, "disassociated due to "
542 "inactivity");
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700543 reason = (sta->timeout_next == STA_DISASSOC) ?
544 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
545 WLAN_REASON_PREV_AUTH_NOT_VALID;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700546 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700547 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
548 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
549 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700550 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
551 hapd, sta);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700552 mlme_disassociate_indication(hapd, sta, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700553 break;
554 case STA_DEAUTH:
555 case STA_REMOVE:
556 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
557 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800558 "inactivity (timer DEAUTH/REMOVE)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700559 if (!sta->acct_terminate_cause)
560 sta->acct_terminate_cause =
561 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
562 mlme_deauthenticate_indication(
563 hapd, sta,
564 WLAN_REASON_PREV_AUTH_NOT_VALID);
565 ap_free_sta(hapd, sta);
566 break;
567 }
568}
569
570
571static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
572{
573 struct hostapd_data *hapd = eloop_ctx;
574 struct sta_info *sta = timeout_ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700575
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800576 wpa_printf(MSG_DEBUG, "%s: Session timer for STA " MACSTR,
577 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700578 if (!(sta->flags & WLAN_STA_AUTH)) {
579 if (sta->flags & WLAN_STA_GAS) {
580 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
581 "entry " MACSTR, MAC2STR(sta->addr));
582 ap_free_sta(hapd, sta);
583 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700585 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700586
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700587 hostapd_drv_sta_deauth(hapd, sta->addr,
588 WLAN_REASON_PREV_AUTH_NOT_VALID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589 mlme_deauthenticate_indication(hapd, sta,
590 WLAN_REASON_PREV_AUTH_NOT_VALID);
591 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
592 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
593 "session timeout");
594 sta->acct_terminate_cause =
595 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700596 ap_free_sta(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700597}
598
599
Dmitry Shmidt54605472013-11-08 11:10:19 -0800600void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta,
601 u32 session_timeout)
602{
603 if (eloop_replenish_timeout(session_timeout, 0,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800604 ap_handle_session_timer, hapd, sta) == 1) {
Dmitry Shmidt54605472013-11-08 11:10:19 -0800605 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
606 HOSTAPD_LEVEL_DEBUG, "setting session timeout "
607 "to %d seconds", session_timeout);
608 }
609}
610
611
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700612void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
613 u32 session_timeout)
614{
615 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
616 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
617 "seconds", session_timeout);
618 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
619 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
620 hapd, sta);
621}
622
623
624void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
625{
626 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
627}
628
629
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800630static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx)
631{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700632#ifdef CONFIG_WNM_AP
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800633 struct hostapd_data *hapd = eloop_ctx;
634 struct sta_info *sta = timeout_ctx;
635
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800636 wpa_printf(MSG_DEBUG, "%s: WNM: Session warning time reached for "
637 MACSTR, hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800638 if (sta->hs20_session_info_url == NULL)
639 return;
640
641 wnm_send_ess_disassoc_imminent(hapd, sta, sta->hs20_session_info_url,
642 sta->hs20_disassoc_timer);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700643#endif /* CONFIG_WNM_AP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800644}
645
646
647void ap_sta_session_warning_timeout(struct hostapd_data *hapd,
648 struct sta_info *sta, int warning_time)
649{
650 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
651 eloop_register_timeout(warning_time, 0, ap_handle_session_warning_timer,
652 hapd, sta);
653}
654
655
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
657{
658 struct sta_info *sta;
659
660 sta = ap_get_sta(hapd, addr);
661 if (sta)
662 return sta;
663
664 wpa_printf(MSG_DEBUG, " New STA");
665 if (hapd->num_sta >= hapd->conf->max_num_sta) {
666 /* FIX: might try to remove some old STAs first? */
667 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
668 hapd->num_sta, hapd->conf->max_num_sta);
669 return NULL;
670 }
671
672 sta = os_zalloc(sizeof(struct sta_info));
673 if (sta == NULL) {
674 wpa_printf(MSG_ERROR, "malloc failed");
675 return NULL;
676 }
677 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800678 if (accounting_sta_get_id(hapd, sta) < 0) {
679 os_free(sta);
680 return NULL;
681 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700682
Dmitry Shmidt01904cf2013-12-05 11:08:35 -0800683 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
684 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
685 "for " MACSTR " (%d seconds - ap_max_inactivity)",
686 __func__, MAC2STR(addr),
687 hapd->conf->ap_max_inactivity);
688 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
689 ap_handle_timer, hapd, sta);
690 }
691
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700692 /* initialize STA info data */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700693 os_memcpy(sta->addr, addr, ETH_ALEN);
694 sta->next = hapd->sta_list;
695 hapd->sta_list = sta;
696 hapd->num_sta++;
697 ap_sta_hash_add(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698 ap_sta_remove_in_other_bss(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800699 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
700 dl_list_init(&sta->ip6addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700702#ifdef CONFIG_TAXONOMY
703 sta_track_claim_taxonomy_info(hapd->iface, addr,
704 &sta->probe_ie_taxonomy);
705#endif /* CONFIG_TAXONOMY */
706
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700707 return sta;
708}
709
710
711static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
712{
713 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
714
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800715 if (sta->ipaddr)
716 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
717 ap_sta_ip6addr_del(hapd, sta);
718
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800719 wpa_printf(MSG_DEBUG, "%s: Removing STA " MACSTR " from kernel driver",
720 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
722 sta->flags & WLAN_STA_ASSOC) {
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800723 wpa_printf(MSG_DEBUG, "%s: Could not remove station " MACSTR
724 " from kernel driver",
725 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700726 return -1;
727 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800728 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729 return 0;
730}
731
732
733static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
734 struct sta_info *sta)
735{
736 struct hostapd_iface *iface = hapd->iface;
737 size_t i;
738
739 for (i = 0; i < iface->num_bss; i++) {
740 struct hostapd_data *bss = iface->bss[i];
741 struct sta_info *sta2;
742 /* bss should always be set during operation, but it may be
743 * NULL during reconfiguration. Assume the STA is not
744 * associated to another BSS in that case to avoid NULL pointer
745 * dereferences. */
746 if (bss == hapd || bss == NULL)
747 continue;
748 sta2 = ap_get_sta(bss, sta->addr);
749 if (!sta2)
750 continue;
751
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800752 wpa_printf(MSG_DEBUG, "%s: disconnect old STA " MACSTR
753 " association from another BSS %s",
754 hapd->conf->iface, MAC2STR(sta2->addr),
755 bss->conf->iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700756 ap_sta_disconnect(bss, sta2, sta2->addr,
757 WLAN_REASON_PREV_AUTH_NOT_VALID);
758 }
759}
760
761
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800762static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
763{
764 struct hostapd_data *hapd = eloop_ctx;
765 struct sta_info *sta = timeout_ctx;
766
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800767 wpa_printf(MSG_DEBUG, "%s: Disassociation callback for STA " MACSTR,
768 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800769 ap_sta_remove(hapd, sta);
770 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
771}
772
773
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700774void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
775 u16 reason)
776{
777 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
778 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800779 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800780 if (hapd->iface->current_mode &&
781 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
782 /* Skip deauthentication in DMG/IEEE 802.11ad */
783 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
784 WLAN_STA_ASSOC_REQ_OK);
785 sta->timeout_next = STA_REMOVE;
786 } else {
787 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
788 sta->timeout_next = STA_DEAUTH;
789 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800790 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700791 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
792 "for " MACSTR " (%d seconds - "
793 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
794 __func__, MAC2STR(sta->addr),
795 AP_MAX_INACTIVITY_AFTER_DISASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700796 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
797 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
798 ap_handle_timer, hapd, sta);
799 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800800 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800802 sta->disassoc_reason = reason;
803 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
804 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
805 eloop_register_timeout(hapd->iface->drv_flags &
806 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
807 ap_sta_disassoc_cb_timeout, hapd, sta);
808}
809
810
811static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
812{
813 struct hostapd_data *hapd = eloop_ctx;
814 struct sta_info *sta = timeout_ctx;
815
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800816 wpa_printf(MSG_DEBUG, "%s: Deauthentication callback for STA " MACSTR,
817 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800818 ap_sta_remove(hapd, sta);
819 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700820}
821
822
823void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
824 u16 reason)
825{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800826 if (hapd->iface->current_mode &&
827 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
828 /* Deauthentication is not used in DMG/IEEE 802.11ad;
829 * disassociate the STA instead. */
830 ap_sta_disassociate(hapd, sta, reason);
831 return;
832 }
833
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700834 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
835 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800836 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
837 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800838 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700839 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700840 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
841 "for " MACSTR " (%d seconds - "
842 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
843 __func__, MAC2STR(sta->addr),
844 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
846 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
847 ap_handle_timer, hapd, sta);
848 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800849 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700850
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800851 sta->deauth_reason = reason;
852 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
853 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
854 eloop_register_timeout(hapd->iface->drv_flags &
855 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
856 ap_sta_deauth_cb_timeout, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700857}
858
859
Dmitry Shmidt04949592012-07-19 12:16:46 -0700860#ifdef CONFIG_WPS
861int ap_sta_wps_cancel(struct hostapd_data *hapd,
862 struct sta_info *sta, void *ctx)
863{
864 if (sta && (sta->flags & WLAN_STA_WPS)) {
865 ap_sta_deauthenticate(hapd, sta,
866 WLAN_REASON_PREV_AUTH_NOT_VALID);
867 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
868 __func__, MAC2STR(sta->addr));
869 return 1;
870 }
871
872 return 0;
873}
874#endif /* CONFIG_WPS */
875
876
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800877static int ap_sta_get_free_vlan_id(struct hostapd_data *hapd)
878{
879 struct hostapd_vlan *vlan;
880 int vlan_id = MAX_VLAN_ID + 2;
881
882retry:
883 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
884 if (vlan->vlan_id == vlan_id) {
885 vlan_id++;
886 goto retry;
887 }
888 }
889 return vlan_id;
890}
891
892
893int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta,
894 struct vlan_description *vlan_desc)
895{
896 struct hostapd_vlan *vlan = NULL, *wildcard_vlan = NULL;
897 int old_vlan_id, vlan_id = 0, ret = 0;
898
899 if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED)
900 vlan_desc = NULL;
901
902 /* Check if there is something to do */
903 if (hapd->conf->ssid.per_sta_vif && !sta->vlan_id) {
904 /* This sta is lacking its own vif */
905 } else if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED &&
906 !hapd->conf->ssid.per_sta_vif && sta->vlan_id) {
907 /* sta->vlan_id needs to be reset */
908 } else if (!vlan_compare(vlan_desc, sta->vlan_desc)) {
909 return 0; /* nothing to change */
910 }
911
912 /* Now the real VLAN changed or the STA just needs its own vif */
913 if (hapd->conf->ssid.per_sta_vif) {
914 /* Assign a new vif, always */
915 /* find a free vlan_id sufficiently big */
916 vlan_id = ap_sta_get_free_vlan_id(hapd);
917 /* Get wildcard VLAN */
918 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
919 if (vlan->vlan_id == VLAN_ID_WILDCARD)
920 break;
921 }
922 if (!vlan) {
923 hostapd_logger(hapd, sta->addr,
924 HOSTAPD_MODULE_IEEE80211,
925 HOSTAPD_LEVEL_DEBUG,
926 "per_sta_vif missing wildcard");
927 vlan_id = 0;
928 ret = -1;
929 goto done;
930 }
931 } else if (vlan_desc && vlan_desc->notempty) {
932 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
933 if (!vlan_compare(&vlan->vlan_desc, vlan_desc))
934 break;
935 if (vlan->vlan_id == VLAN_ID_WILDCARD)
936 wildcard_vlan = vlan;
937 }
938 if (vlan) {
939 vlan_id = vlan->vlan_id;
940 } else if (wildcard_vlan) {
941 vlan = wildcard_vlan;
942 vlan_id = vlan_desc->untagged;
943 if (vlan_desc->tagged[0]) {
944 /* Tagged VLAN configuration */
945 vlan_id = ap_sta_get_free_vlan_id(hapd);
946 }
947 } else {
948 hostapd_logger(hapd, sta->addr,
949 HOSTAPD_MODULE_IEEE80211,
950 HOSTAPD_LEVEL_DEBUG,
951 "missing vlan and wildcard for vlan=%d%s",
952 vlan_desc->untagged,
953 vlan_desc->tagged[0] ? "+" : "");
954 vlan_id = 0;
955 ret = -1;
956 goto done;
957 }
958 }
959
960 if (vlan && vlan->vlan_id == VLAN_ID_WILDCARD) {
961 vlan = vlan_add_dynamic(hapd, vlan, vlan_id, vlan_desc);
962 if (vlan == NULL) {
963 hostapd_logger(hapd, sta->addr,
964 HOSTAPD_MODULE_IEEE80211,
965 HOSTAPD_LEVEL_DEBUG,
966 "could not add dynamic VLAN interface for vlan=%d%s",
967 vlan_desc ? vlan_desc->untagged : -1,
968 (vlan_desc && vlan_desc->tagged[0]) ?
969 "+" : "");
970 vlan_id = 0;
971 ret = -1;
972 goto done;
973 }
974
975 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
976 HOSTAPD_LEVEL_DEBUG,
977 "added new dynamic VLAN interface '%s'",
978 vlan->ifname);
979 } else if (vlan && vlan->dynamic_vlan > 0) {
980 vlan->dynamic_vlan++;
981 hostapd_logger(hapd, sta->addr,
982 HOSTAPD_MODULE_IEEE80211,
983 HOSTAPD_LEVEL_DEBUG,
984 "updated existing dynamic VLAN interface '%s'",
985 vlan->ifname);
986 }
987done:
988 old_vlan_id = sta->vlan_id;
989 sta->vlan_id = vlan_id;
990 sta->vlan_desc = vlan ? &vlan->vlan_desc : NULL;
991
992 if (vlan_id != old_vlan_id && old_vlan_id)
993 vlan_remove_dynamic(hapd, old_vlan_id);
994
995 return ret;
996}
997
998
Dmitry Shmidt83474442015-04-15 13:47:09 -0700999int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001000{
1001#ifndef CONFIG_NO_VLAN
1002 const char *iface;
1003 struct hostapd_vlan *vlan = NULL;
1004 int ret;
Dmitry Shmidt83474442015-04-15 13:47:09 -07001005 int old_vlanid = sta->vlan_id_bound;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001006
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001007 iface = hapd->conf->iface;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001008 if (hapd->conf->ssid.vlan[0])
1009 iface = hapd->conf->ssid.vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001010
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001011 if (sta->vlan_id > 0) {
1012 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001013 if (vlan->vlan_id == sta->vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001014 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001015 }
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001016 if (vlan)
1017 iface = vlan->ifname;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001018 }
1019
Dmitry Shmidt83474442015-04-15 13:47:09 -07001020 /*
1021 * Do not increment ref counters if the VLAN ID remains same, but do
1022 * not skip hostapd_drv_set_sta_vlan() as hostapd_drv_sta_remove() might
1023 * have been called before.
1024 */
1025 if (sta->vlan_id == old_vlanid)
1026 goto skip_counting;
1027
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001028 if (sta->vlan_id > 0 && vlan == NULL) {
1029 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1030 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
1031 "binding station to (vlan_id=%d)",
1032 sta->vlan_id);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001033 ret = -1;
1034 goto done;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001035 } else if (vlan && vlan->dynamic_vlan > 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001036 vlan->dynamic_vlan++;
1037 hostapd_logger(hapd, sta->addr,
1038 HOSTAPD_MODULE_IEEE80211,
1039 HOSTAPD_LEVEL_DEBUG,
1040 "updated existing dynamic VLAN interface '%s'",
1041 iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001042 }
1043
Dmitry Shmidt83474442015-04-15 13:47:09 -07001044 /* ref counters have been increased, so mark the station */
1045 sta->vlan_id_bound = sta->vlan_id;
1046
1047skip_counting:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001048 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1049 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
1050 "'%s'", iface);
1051
1052 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
1053 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
1054
1055 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
1056 if (ret < 0) {
1057 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1058 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
1059 "entry to vlan_id=%d", sta->vlan_id);
1060 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001061
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001062 /* During 1x reauth, if the vlan id changes, then remove the old id. */
Dmitry Shmidt83474442015-04-15 13:47:09 -07001063 if (old_vlanid > 0 && old_vlanid != sta->vlan_id)
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001064 vlan_remove_dynamic(hapd, old_vlanid);
Dmitry Shmidt83474442015-04-15 13:47:09 -07001065done:
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001066
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001067 return ret;
1068#else /* CONFIG_NO_VLAN */
1069 return 0;
1070#endif /* CONFIG_NO_VLAN */
1071}
1072
1073
1074#ifdef CONFIG_IEEE80211W
1075
1076int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
1077{
1078 u32 tu;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001079 struct os_reltime now, passed;
1080 os_get_reltime(&now);
1081 os_reltime_sub(&now, &sta->sa_query_start, &passed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001082 tu = (passed.sec * 1000000 + passed.usec) / 1024;
1083 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
1084 hostapd_logger(hapd, sta->addr,
1085 HOSTAPD_MODULE_IEEE80211,
1086 HOSTAPD_LEVEL_DEBUG,
1087 "association SA Query timed out");
1088 sta->sa_query_timed_out = 1;
1089 os_free(sta->sa_query_trans_id);
1090 sta->sa_query_trans_id = NULL;
1091 sta->sa_query_count = 0;
1092 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1093 return 1;
1094 }
1095
1096 return 0;
1097}
1098
1099
1100static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
1101{
1102 struct hostapd_data *hapd = eloop_ctx;
1103 struct sta_info *sta = timeout_ctx;
1104 unsigned int timeout, sec, usec;
1105 u8 *trans_id, *nbuf;
1106
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001107 wpa_printf(MSG_DEBUG, "%s: SA Query timer for STA " MACSTR
1108 " (count=%d)",
1109 hapd->conf->iface, MAC2STR(sta->addr), sta->sa_query_count);
1110
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111 if (sta->sa_query_count > 0 &&
1112 ap_check_sa_query_timeout(hapd, sta))
1113 return;
1114
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001115 nbuf = os_realloc_array(sta->sa_query_trans_id,
1116 sta->sa_query_count + 1,
1117 WLAN_SA_QUERY_TR_ID_LEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001118 if (nbuf == NULL)
1119 return;
1120 if (sta->sa_query_count == 0) {
1121 /* Starting a new SA Query procedure */
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001122 os_get_reltime(&sta->sa_query_start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001123 }
1124 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
1125 sta->sa_query_trans_id = nbuf;
1126 sta->sa_query_count++;
1127
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001128 if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) {
1129 /*
1130 * We don't really care which ID is used here, so simply
1131 * hardcode this if the mostly theoretical os_get_random()
1132 * failure happens.
1133 */
1134 trans_id[0] = 0x12;
1135 trans_id[1] = 0x34;
1136 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001137
1138 timeout = hapd->conf->assoc_sa_query_retry_timeout;
1139 sec = ((timeout / 1000) * 1024) / 1000;
1140 usec = (timeout % 1000) * 1024;
1141 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
1142
1143 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1144 HOSTAPD_LEVEL_DEBUG,
1145 "association SA Query attempt %d", sta->sa_query_count);
1146
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001147 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001148}
1149
1150
1151void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1152{
1153 ap_sa_query_timer(hapd, sta);
1154}
1155
1156
1157void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1158{
1159 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1160 os_free(sta->sa_query_trans_id);
1161 sta->sa_query_trans_id = NULL;
1162 sta->sa_query_count = 0;
1163}
1164
1165#endif /* CONFIG_IEEE80211W */
1166
1167
1168void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
1169 int authorized)
1170{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001171 const u8 *dev_addr = NULL;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001172 char buf[100];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001173#ifdef CONFIG_P2P
1174 u8 addr[ETH_ALEN];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001175 u8 ip_addr_buf[4];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001176#endif /* CONFIG_P2P */
1177
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001178 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
1179 return;
1180
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001181 if (authorized)
1182 sta->flags |= WLAN_STA_AUTHORIZED;
1183 else
1184 sta->flags &= ~WLAN_STA_AUTHORIZED;
1185
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001186#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001187 if (hapd->p2p_group == NULL) {
1188 if (sta->p2p_ie != NULL &&
1189 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
1190 dev_addr = addr;
1191 } else
1192 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001193
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001194 if (dev_addr)
1195 os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
1196 MAC2STR(sta->addr), MAC2STR(dev_addr));
1197 else
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001198#endif /* CONFIG_P2P */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001199 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
1200
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001201 if (hapd->sta_authorized_cb)
1202 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
1203 sta->addr, authorized, dev_addr);
1204
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001205 if (authorized) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001206 char ip_addr[100];
1207 ip_addr[0] = '\0';
1208#ifdef CONFIG_P2P
1209 if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) {
1210 os_snprintf(ip_addr, sizeof(ip_addr),
1211 " ip_addr=%u.%u.%u.%u",
1212 ip_addr_buf[0], ip_addr_buf[1],
1213 ip_addr_buf[2], ip_addr_buf[3]);
1214 }
1215#endif /* CONFIG_P2P */
1216
1217 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s",
1218 buf, ip_addr);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001219
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001220 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001221 hapd->msg_ctx_parent != hapd->msg_ctx)
1222 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001223 AP_STA_CONNECTED "%s%s",
1224 buf, ip_addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001225 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001226 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
1227
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001228 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001229 hapd->msg_ctx_parent != hapd->msg_ctx)
1230 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
1231 AP_STA_DISCONNECTED "%s", buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001232 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001233
1234#ifdef CONFIG_FST
1235 if (hapd->iface->fst) {
1236 if (authorized)
1237 fst_notify_peer_connected(hapd->iface->fst, sta->addr);
1238 else
1239 fst_notify_peer_disconnected(hapd->iface->fst,
1240 sta->addr);
1241 }
1242#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001243}
1244
1245
1246void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
1247 const u8 *addr, u16 reason)
1248{
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001249 if (sta)
1250 wpa_printf(MSG_DEBUG, "%s: %s STA " MACSTR " reason=%u",
1251 hapd->conf->iface, __func__, MAC2STR(sta->addr),
1252 reason);
1253 else if (addr)
1254 wpa_printf(MSG_DEBUG, "%s: %s addr " MACSTR " reason=%u",
1255 hapd->conf->iface, __func__, MAC2STR(addr),
1256 reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001257
1258 if (sta == NULL && addr)
1259 sta = ap_get_sta(hapd, addr);
1260
1261 if (addr)
1262 hostapd_drv_sta_deauth(hapd, addr, reason);
1263
1264 if (sta == NULL)
1265 return;
1266 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001267 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1268 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001269 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001270 wpa_printf(MSG_DEBUG, "%s: %s: reschedule ap_handle_timer timeout "
Dmitry Shmidt04949592012-07-19 12:16:46 -07001271 "for " MACSTR " (%d seconds - "
1272 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001273 hapd->conf->iface, __func__, MAC2STR(sta->addr),
Dmitry Shmidt04949592012-07-19 12:16:46 -07001274 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001275 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001276 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
1277 ap_handle_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001278 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001279
Dmitry Shmidt29333592017-01-09 12:27:11 -08001280 if (hapd->iface->current_mode &&
1281 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
1282 /* Deauthentication is not used in DMG/IEEE 802.11ad;
1283 * disassociate the STA instead. */
1284 sta->disassoc_reason = reason;
1285 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
1286 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1287 eloop_register_timeout(hapd->iface->drv_flags &
1288 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ?
1289 2 : 0, 0, ap_sta_disassoc_cb_timeout,
1290 hapd, sta);
1291 return;
1292 }
1293
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001294 sta->deauth_reason = reason;
1295 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
1296 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1297 eloop_register_timeout(hapd->iface->drv_flags &
1298 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
1299 ap_sta_deauth_cb_timeout, hapd, sta);
1300}
1301
1302
1303void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
1304{
1305 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
1306 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
1307 return;
1308 }
1309 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
1310 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1311 ap_sta_deauth_cb_timeout(hapd, sta);
1312}
1313
1314
1315void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
1316{
1317 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
1318 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
1319 return;
1320 }
1321 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
1322 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1323 ap_sta_disassoc_cb_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001324}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001325
1326
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001327void ap_sta_clear_disconnect_timeouts(struct hostapd_data *hapd,
1328 struct sta_info *sta)
1329{
1330 if (eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta) > 0)
1331 wpa_printf(MSG_DEBUG,
1332 "%s: Removed ap_sta_deauth_cb_timeout timeout for "
1333 MACSTR,
1334 hapd->conf->iface, MAC2STR(sta->addr));
1335 if (eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta) > 0)
1336 wpa_printf(MSG_DEBUG,
1337 "%s: Removed ap_sta_disassoc_cb_timeout timeout for "
1338 MACSTR,
1339 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt29333592017-01-09 12:27:11 -08001340 if (eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta) > 0)
1341 {
1342 wpa_printf(MSG_DEBUG,
1343 "%s: Removed ap_sta_delayed_1x_auth_fail_cb timeout for "
1344 MACSTR,
1345 hapd->conf->iface, MAC2STR(sta->addr));
1346 if (sta->flags & WLAN_STA_WPS)
1347 hostapd_wps_eap_completed(hapd);
1348 }
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001349}
1350
1351
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001352int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen)
1353{
1354 int res;
1355
1356 buf[0] = '\0';
Roshan Pius3a1667e2018-07-03 15:17:14 -07001357 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 -08001358 (flags & WLAN_STA_AUTH ? "[AUTH]" : ""),
1359 (flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""),
1360 (flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : ""),
1361 (flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
1362 ""),
1363 (flags & WLAN_STA_SHORT_PREAMBLE ?
1364 "[SHORT_PREAMBLE]" : ""),
1365 (flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
1366 (flags & WLAN_STA_WMM ? "[WMM]" : ""),
1367 (flags & WLAN_STA_MFP ? "[MFP]" : ""),
1368 (flags & WLAN_STA_WPS ? "[WPS]" : ""),
1369 (flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""),
1370 (flags & WLAN_STA_WDS ? "[WDS]" : ""),
1371 (flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
1372 (flags & WLAN_STA_WPS2 ? "[WPS2]" : ""),
1373 (flags & WLAN_STA_GAS ? "[GAS]" : ""),
Roshan Pius3a1667e2018-07-03 15:17:14 -07001374 (flags & WLAN_STA_HT ? "[HT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001375 (flags & WLAN_STA_VHT ? "[VHT]" : ""),
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001376 (flags & WLAN_STA_VENDOR_VHT ? "[VENDOR_VHT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001377 (flags & WLAN_STA_WNM_SLEEP_MODE ?
1378 "[WNM_SLEEP_MODE]" : ""));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001379 if (os_snprintf_error(buflen, res))
1380 res = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001381
1382 return res;
1383}
Dmitry Shmidt29333592017-01-09 12:27:11 -08001384
1385
1386static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx)
1387{
1388 struct hostapd_data *hapd = eloop_ctx;
1389 struct sta_info *sta = timeout_ctx;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001390 u16 reason;
Dmitry Shmidt29333592017-01-09 12:27:11 -08001391
1392 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1393 "IEEE 802.1X: Scheduled disconnection of " MACSTR
1394 " after EAP-Failure", MAC2STR(sta->addr));
1395
Roshan Pius3a1667e2018-07-03 15:17:14 -07001396 reason = sta->disconnect_reason_code;
1397 if (!reason)
1398 reason = WLAN_REASON_IEEE_802_1X_AUTH_FAILED;
1399 ap_sta_disconnect(hapd, sta, sta->addr, reason);
Dmitry Shmidt29333592017-01-09 12:27:11 -08001400 if (sta->flags & WLAN_STA_WPS)
1401 hostapd_wps_eap_completed(hapd);
1402}
1403
1404
1405void ap_sta_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1406 struct sta_info *sta)
1407{
1408 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1409 "IEEE 802.1X: Force disconnection of " MACSTR
1410 " after EAP-Failure in 10 ms", MAC2STR(sta->addr));
1411
1412 /*
1413 * Add a small sleep to increase likelihood of previously requested
1414 * EAP-Failure TX getting out before this should the driver reorder
1415 * operations.
1416 */
1417 eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta);
1418 eloop_register_timeout(0, 10000, ap_sta_delayed_1x_auth_fail_cb,
1419 hapd, sta);
1420}
1421
1422
1423int ap_sta_pending_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1424 struct sta_info *sta)
1425{
1426 return eloop_is_timeout_registered(ap_sta_delayed_1x_auth_fail_cb,
1427 hapd, sta);
1428}