blob: 8858a3425907468f871d449e84e950daa3614259 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Station table
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003 * Copyright (c) 2002-2017, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "utils/eloop.h"
13#include "common/ieee802_11_defs.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014#include "common/wpa_ctrl.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080015#include "common/sae.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070016#include "radius/radius.h"
17#include "radius/radius_client.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080019#include "fst/fst.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070020#include "crypto/crypto.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070021#include "hostapd.h"
22#include "accounting.h"
23#include "ieee802_1x.h"
24#include "ieee802_11.h"
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080025#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070026#include "wpa_auth.h"
27#include "preauth_auth.h"
28#include "ap_config.h"
29#include "beacon.h"
30#include "ap_mlme.h"
31#include "vlan_init.h"
32#include "p2p_hostapd.h"
33#include "ap_drv_ops.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070034#include "gas_serv.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080035#include "wnm_ap.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080036#include "mbo_ap.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080037#include "ndisc_snoop.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070038#include "sta_info.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080039#include "vlan.h"
Dmitry Shmidt29333592017-01-09 12:27:11 -080040#include "wps_hostapd.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041
42static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
43 struct sta_info *sta);
44static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080045static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080046static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
47static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070048#ifdef CONFIG_IEEE80211W
49static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
50#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080051static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
Dmitry Shmidt29333592017-01-09 12:27:11 -080052static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070053
54int ap_for_each_sta(struct hostapd_data *hapd,
55 int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
56 void *ctx),
57 void *ctx)
58{
59 struct sta_info *sta;
60
61 for (sta = hapd->sta_list; sta; sta = sta->next) {
62 if (cb(hapd, sta, ctx))
63 return 1;
64 }
65
66 return 0;
67}
68
69
70struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
71{
72 struct sta_info *s;
73
74 s = hapd->sta_hash[STA_HASH(sta)];
75 while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
76 s = s->hnext;
77 return s;
78}
79
80
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070081#ifdef CONFIG_P2P
82struct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr)
83{
84 struct sta_info *sta;
85
86 for (sta = hapd->sta_list; sta; sta = sta->next) {
87 const u8 *p2p_dev_addr;
88
89 if (sta->p2p_ie == NULL)
90 continue;
91
92 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
93 if (p2p_dev_addr == NULL)
94 continue;
95
96 if (os_memcmp(p2p_dev_addr, addr, ETH_ALEN) == 0)
97 return sta;
98 }
99
100 return NULL;
101}
102#endif /* CONFIG_P2P */
103
104
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700105static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
106{
107 struct sta_info *tmp;
108
109 if (hapd->sta_list == sta) {
110 hapd->sta_list = sta->next;
111 return;
112 }
113
114 tmp = hapd->sta_list;
115 while (tmp != NULL && tmp->next != sta)
116 tmp = tmp->next;
117 if (tmp == NULL) {
118 wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
119 "list.", MAC2STR(sta->addr));
120 } else
121 tmp->next = sta->next;
122}
123
124
125void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
126{
127 sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
128 hapd->sta_hash[STA_HASH(sta->addr)] = sta;
129}
130
131
132static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
133{
134 struct sta_info *s;
135
136 s = hapd->sta_hash[STA_HASH(sta->addr)];
137 if (s == NULL) return;
138 if (os_memcmp(s->addr, sta->addr, 6) == 0) {
139 hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
140 return;
141 }
142
143 while (s->hnext != NULL &&
144 os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
145 s = s->hnext;
146 if (s->hnext != NULL)
147 s->hnext = s->hnext->hnext;
148 else
149 wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
150 " from hash table", MAC2STR(sta->addr));
151}
152
153
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800154void ap_sta_ip6addr_del(struct hostapd_data *hapd, struct sta_info *sta)
155{
156 sta_ip6addr_del(hapd, sta);
157}
158
159
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700160void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
161{
162 int set_beacon = 0;
163
164 accounting_sta_stop(hapd, sta);
165
166 /* just in case */
167 ap_sta_set_authorized(hapd, sta, 0);
168
Hai Shalom39bc25d2019-02-06 16:32:13 -0800169 if (sta->flags & (WLAN_STA_WDS | WLAN_STA_MULTI_AP))
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700170 hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800172 if (sta->ipaddr)
173 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
174 ap_sta_ip6addr_del(hapd, sta);
175
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800176 if (!hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800177 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800179 sta->added_unassoc = 0;
180 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181
182 ap_sta_hash_del(hapd, sta);
183 ap_sta_list_del(hapd, sta);
184
185 if (sta->aid > 0)
186 hapd->sta_aid[(sta->aid - 1) / 32] &=
187 ~BIT((sta->aid - 1) % 32);
188
189 hapd->num_sta--;
190 if (sta->nonerp_set) {
191 sta->nonerp_set = 0;
192 hapd->iface->num_sta_non_erp--;
193 if (hapd->iface->num_sta_non_erp == 0)
194 set_beacon++;
195 }
196
197 if (sta->no_short_slot_time_set) {
198 sta->no_short_slot_time_set = 0;
199 hapd->iface->num_sta_no_short_slot_time--;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700200 if (hapd->iface->current_mode &&
201 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700202 && hapd->iface->num_sta_no_short_slot_time == 0)
203 set_beacon++;
204 }
205
206 if (sta->no_short_preamble_set) {
207 sta->no_short_preamble_set = 0;
208 hapd->iface->num_sta_no_short_preamble--;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700209 if (hapd->iface->current_mode &&
210 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700211 && hapd->iface->num_sta_no_short_preamble == 0)
212 set_beacon++;
213 }
214
215 if (sta->no_ht_gf_set) {
216 sta->no_ht_gf_set = 0;
217 hapd->iface->num_sta_ht_no_gf--;
218 }
219
220 if (sta->no_ht_set) {
221 sta->no_ht_set = 0;
222 hapd->iface->num_sta_no_ht--;
223 }
224
225 if (sta->ht_20mhz_set) {
226 sta->ht_20mhz_set = 0;
227 hapd->iface->num_sta_ht_20mhz--;
228 }
229
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700230#ifdef CONFIG_TAXONOMY
231 wpabuf_free(sta->probe_ie_taxonomy);
232 sta->probe_ie_taxonomy = NULL;
233 wpabuf_free(sta->assoc_ie_taxonomy);
234 sta->assoc_ie_taxonomy = NULL;
235#endif /* CONFIG_TAXONOMY */
236
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700237#ifdef CONFIG_IEEE80211N
238 ht40_intolerant_remove(hapd->iface, sta);
239#endif /* CONFIG_IEEE80211N */
240
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700241#ifdef CONFIG_P2P
242 if (sta->no_p2p_set) {
243 sta->no_p2p_set = 0;
244 hapd->num_sta_no_p2p--;
245 if (hapd->num_sta_no_p2p == 0)
246 hostapd_p2p_non_p2p_sta_disconnected(hapd);
247 }
248#endif /* CONFIG_P2P */
249
250#if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
251 if (hostapd_ht_operation_update(hapd->iface) > 0)
252 set_beacon++;
253#endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
254
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800255#ifdef CONFIG_MESH
256 if (hapd->mesh_sta_free_cb)
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800257 hapd->mesh_sta_free_cb(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800258#endif /* CONFIG_MESH */
259
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700260 if (set_beacon)
261 ieee802_11_set_beacons(hapd->iface);
262
Dmitry Shmidt04949592012-07-19 12:16:46 -0700263 wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
264 __func__, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
266 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800267 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800268 ap_sta_clear_disconnect_timeouts(hapd, sta);
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800269 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700270
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800271 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700272 wpa_auth_sta_deinit(sta->wpa_sm);
273 rsn_preauth_free_station(hapd, sta);
274#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt96571392013-10-14 12:54:46 -0700275 if (hapd->radius)
276 radius_client_flush_auth(hapd->radius, sta->addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700277#endif /* CONFIG_NO_RADIUS */
278
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800279#ifndef CONFIG_NO_VLAN
280 /*
281 * sta->wpa_sm->group needs to be released before so that
282 * vlan_remove_dynamic() can check that no stations are left on the
283 * AP_VLAN netdev.
284 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800285 if (sta->vlan_id)
286 vlan_remove_dynamic(hapd, sta->vlan_id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800287 if (sta->vlan_id_bound) {
288 /*
289 * Need to remove the STA entry before potentially removing the
290 * VLAN.
291 */
292 if (hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800293 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800294 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800295 sta->added_unassoc = 0;
296 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800297 vlan_remove_dynamic(hapd, sta->vlan_id_bound);
298 }
299#endif /* CONFIG_NO_VLAN */
300
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700301 os_free(sta->challenge);
302
303#ifdef CONFIG_IEEE80211W
304 os_free(sta->sa_query_trans_id);
305 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
306#endif /* CONFIG_IEEE80211W */
307
308#ifdef CONFIG_P2P
309 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
310#endif /* CONFIG_P2P */
311
Dmitry Shmidt04949592012-07-19 12:16:46 -0700312#ifdef CONFIG_INTERWORKING
313 if (sta->gas_dialog) {
314 int i;
315 for (i = 0; i < GAS_DIALOG_MAX; i++)
316 gas_serv_dialog_clear(&sta->gas_dialog[i]);
317 os_free(sta->gas_dialog);
318 }
319#endif /* CONFIG_INTERWORKING */
320
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700321 wpabuf_free(sta->wps_ie);
322 wpabuf_free(sta->p2p_ie);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800323 wpabuf_free(sta->hs20_ie);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700324 wpabuf_free(sta->roaming_consortium);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800325#ifdef CONFIG_FST
326 wpabuf_free(sta->mb_ies);
327#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700328
329 os_free(sta->ht_capabilities);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -0800330 os_free(sta->vht_capabilities);
Hai Shalom39bc25d2019-02-06 16:32:13 -0800331 os_free(sta->vht_operation);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800332 hostapd_free_psk_list(sta->psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700333 os_free(sta->identity);
334 os_free(sta->radius_cui);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800335 os_free(sta->remediation_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700336 os_free(sta->t_c_url);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800337 wpabuf_free(sta->hs20_deauth_req);
338 os_free(sta->hs20_session_info_url);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700339
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800340#ifdef CONFIG_SAE
341 sae_clear_data(sta->sae);
342 os_free(sta->sae);
343#endif /* CONFIG_SAE */
344
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800345 mbo_ap_sta_free(sta);
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800346 os_free(sta->supp_op_classes);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800347
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800348#ifdef CONFIG_FILS
349 os_free(sta->fils_pending_assoc_req);
350 wpabuf_free(sta->fils_hlp_resp);
351 wpabuf_free(sta->hlp_dhcp_discover);
352 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700353#ifdef CONFIG_FILS_SK_PFS
354 crypto_ecdh_deinit(sta->fils_ecdh);
355 wpabuf_clear_free(sta->fils_dh_ss);
356 wpabuf_free(sta->fils_g_sta);
357#endif /* CONFIG_FILS_SK_PFS */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800358#endif /* CONFIG_FILS */
359
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700360#ifdef CONFIG_OWE
361 bin_clear_free(sta->owe_pmk, sta->owe_pmk_len);
362 crypto_ecdh_deinit(sta->owe_ecdh);
363#endif /* CONFIG_OWE */
364
Roshan Pius3a1667e2018-07-03 15:17:14 -0700365 os_free(sta->ext_capability);
366
367#ifdef CONFIG_WNM_AP
368 eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta);
369#endif /* CONFIG_WNM_AP */
370
371 os_free(sta->ifname_wds);
372
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700373 os_free(sta);
374}
375
376
377void hostapd_free_stas(struct hostapd_data *hapd)
378{
379 struct sta_info *sta, *prev;
380
381 sta = hapd->sta_list;
382
383 while (sta) {
384 prev = sta;
385 if (sta->flags & WLAN_STA_AUTH) {
386 mlme_deauthenticate_indication(
387 hapd, sta, WLAN_REASON_UNSPECIFIED);
388 }
389 sta = sta->next;
390 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
391 MAC2STR(prev->addr));
392 ap_free_sta(hapd, prev);
393 }
394}
395
396
397/**
398 * ap_handle_timer - Per STA timer handler
399 * @eloop_ctx: struct hostapd_data *
400 * @timeout_ctx: struct sta_info *
401 *
402 * This function is called to check station activity and to remove inactive
403 * stations.
404 */
405void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
406{
407 struct hostapd_data *hapd = eloop_ctx;
408 struct sta_info *sta = timeout_ctx;
409 unsigned long next_time = 0;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700410 int reason;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800412 wpa_printf(MSG_DEBUG, "%s: %s: " MACSTR " flags=0x%x timeout_next=%d",
413 hapd->conf->iface, __func__, MAC2STR(sta->addr), sta->flags,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700414 sta->timeout_next);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700415 if (sta->timeout_next == STA_REMOVE) {
416 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
417 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
418 "local deauth request");
419 ap_free_sta(hapd, sta);
420 return;
421 }
422
423 if ((sta->flags & WLAN_STA_ASSOC) &&
424 (sta->timeout_next == STA_NULLFUNC ||
425 sta->timeout_next == STA_DISASSOC)) {
426 int inactive_sec;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700427 /*
428 * Add random value to timeout so that we don't end up bouncing
429 * all stations at the same time if we have lots of associated
430 * stations that are idle (but keep re-associating).
431 */
432 int fuzz = os_random() % 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700433 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
434 if (inactive_sec == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800435 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
436 "Check inactivity: Could not "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800437 "get station info from kernel driver for "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700438 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800439 /*
440 * The driver may not support this functionality.
441 * Anyway, try again after the next inactivity timeout,
442 * but do not disconnect the station now.
443 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700444 next_time = hapd->conf->ap_max_inactivity + fuzz;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800445 } else if (inactive_sec == -ENOENT) {
446 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
447 "Station " MACSTR " has lost its driver entry",
448 MAC2STR(sta->addr));
449
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800450 /* Avoid sending client probe on removed client */
451 sta->timeout_next = STA_DISASSOC;
452 goto skip_poll;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800453 } else if (inactive_sec < hapd->conf->ap_max_inactivity) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700454 /* station activity detected; reset timeout state */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800455 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
456 "Station " MACSTR " has been active %is ago",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 MAC2STR(sta->addr), inactive_sec);
458 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700459 next_time = hapd->conf->ap_max_inactivity + fuzz -
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700460 inactive_sec;
461 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800462 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
463 "Station " MACSTR " has been "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700464 "inactive too long: %d sec, max allowed: %d",
465 MAC2STR(sta->addr), inactive_sec,
466 hapd->conf->ap_max_inactivity);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800467
468 if (hapd->conf->skip_inactivity_poll)
469 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700470 }
471 }
472
473 if ((sta->flags & WLAN_STA_ASSOC) &&
474 sta->timeout_next == STA_DISASSOC &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800475 !(sta->flags & WLAN_STA_PENDING_POLL) &&
476 !hapd->conf->skip_inactivity_poll) {
477 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
478 " has ACKed data poll", MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479 /* data nullfunc frame poll did not produce TX errors; assume
480 * station ACKed it */
481 sta->timeout_next = STA_NULLFUNC;
482 next_time = hapd->conf->ap_max_inactivity;
483 }
484
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800485skip_poll:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700486 if (next_time) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700487 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
488 "for " MACSTR " (%lu seconds)",
489 __func__, MAC2STR(sta->addr), next_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700490 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
491 sta);
492 return;
493 }
494
495 if (sta->timeout_next == STA_NULLFUNC &&
496 (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800497 wpa_printf(MSG_DEBUG, " Polling STA");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700498 sta->flags |= WLAN_STA_PENDING_POLL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800499 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
500 sta->flags & WLAN_STA_WMM);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501 } else if (sta->timeout_next != STA_REMOVE) {
502 int deauth = sta->timeout_next == STA_DEAUTH;
503
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800504 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
505 "Timeout, sending %s info to STA " MACSTR,
506 deauth ? "deauthentication" : "disassociation",
507 MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700508
509 if (deauth) {
510 hostapd_drv_sta_deauth(
511 hapd, sta->addr,
512 WLAN_REASON_PREV_AUTH_NOT_VALID);
513 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700514 reason = (sta->timeout_next == STA_DISASSOC) ?
515 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
516 WLAN_REASON_PREV_AUTH_NOT_VALID;
517
518 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700519 }
520 }
521
522 switch (sta->timeout_next) {
523 case STA_NULLFUNC:
524 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700525 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
526 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
527 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700528 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
529 hapd, sta);
530 break;
531 case STA_DISASSOC:
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700532 case STA_DISASSOC_FROM_CLI:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800533 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700534 sta->flags &= ~WLAN_STA_ASSOC;
535 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
536 if (!sta->acct_terminate_cause)
537 sta->acct_terminate_cause =
538 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
539 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800540 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
542 HOSTAPD_LEVEL_INFO, "disassociated due to "
543 "inactivity");
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700544 reason = (sta->timeout_next == STA_DISASSOC) ?
545 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
546 WLAN_REASON_PREV_AUTH_NOT_VALID;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700547 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700548 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
549 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
550 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700551 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
552 hapd, sta);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700553 mlme_disassociate_indication(hapd, sta, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700554 break;
555 case STA_DEAUTH:
556 case STA_REMOVE:
557 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
558 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800559 "inactivity (timer DEAUTH/REMOVE)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700560 if (!sta->acct_terminate_cause)
561 sta->acct_terminate_cause =
562 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
563 mlme_deauthenticate_indication(
564 hapd, sta,
565 WLAN_REASON_PREV_AUTH_NOT_VALID);
566 ap_free_sta(hapd, sta);
567 break;
568 }
569}
570
571
572static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
573{
574 struct hostapd_data *hapd = eloop_ctx;
575 struct sta_info *sta = timeout_ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700576
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800577 wpa_printf(MSG_DEBUG, "%s: Session timer for STA " MACSTR,
578 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700579 if (!(sta->flags & WLAN_STA_AUTH)) {
580 if (sta->flags & WLAN_STA_GAS) {
581 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
582 "entry " MACSTR, MAC2STR(sta->addr));
583 ap_free_sta(hapd, sta);
584 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700585 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700586 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700587
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700588 hostapd_drv_sta_deauth(hapd, sta->addr,
589 WLAN_REASON_PREV_AUTH_NOT_VALID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700590 mlme_deauthenticate_indication(hapd, sta,
591 WLAN_REASON_PREV_AUTH_NOT_VALID);
592 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
593 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
594 "session timeout");
595 sta->acct_terminate_cause =
596 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700597 ap_free_sta(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700598}
599
600
Dmitry Shmidt54605472013-11-08 11:10:19 -0800601void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta,
602 u32 session_timeout)
603{
604 if (eloop_replenish_timeout(session_timeout, 0,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800605 ap_handle_session_timer, hapd, sta) == 1) {
Dmitry Shmidt54605472013-11-08 11:10:19 -0800606 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
607 HOSTAPD_LEVEL_DEBUG, "setting session timeout "
608 "to %d seconds", session_timeout);
609 }
610}
611
612
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700613void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
614 u32 session_timeout)
615{
616 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
617 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
618 "seconds", session_timeout);
619 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
620 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
621 hapd, sta);
622}
623
624
625void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
626{
627 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
628}
629
630
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800631static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx)
632{
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700633#ifdef CONFIG_WNM_AP
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800634 struct hostapd_data *hapd = eloop_ctx;
635 struct sta_info *sta = timeout_ctx;
636
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800637 wpa_printf(MSG_DEBUG, "%s: WNM: Session warning time reached for "
638 MACSTR, hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800639 if (sta->hs20_session_info_url == NULL)
640 return;
641
642 wnm_send_ess_disassoc_imminent(hapd, sta, sta->hs20_session_info_url,
643 sta->hs20_disassoc_timer);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700644#endif /* CONFIG_WNM_AP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800645}
646
647
648void ap_sta_session_warning_timeout(struct hostapd_data *hapd,
649 struct sta_info *sta, int warning_time)
650{
651 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
652 eloop_register_timeout(warning_time, 0, ap_handle_session_warning_timer,
653 hapd, sta);
654}
655
656
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700657struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
658{
659 struct sta_info *sta;
660
661 sta = ap_get_sta(hapd, addr);
662 if (sta)
663 return sta;
664
665 wpa_printf(MSG_DEBUG, " New STA");
666 if (hapd->num_sta >= hapd->conf->max_num_sta) {
667 /* FIX: might try to remove some old STAs first? */
668 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
669 hapd->num_sta, hapd->conf->max_num_sta);
670 return NULL;
671 }
672
673 sta = os_zalloc(sizeof(struct sta_info));
674 if (sta == NULL) {
675 wpa_printf(MSG_ERROR, "malloc failed");
676 return NULL;
677 }
678 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800679 if (accounting_sta_get_id(hapd, sta) < 0) {
680 os_free(sta);
681 return NULL;
682 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700683
Dmitry Shmidt01904cf2013-12-05 11:08:35 -0800684 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
685 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
686 "for " MACSTR " (%d seconds - ap_max_inactivity)",
687 __func__, MAC2STR(addr),
688 hapd->conf->ap_max_inactivity);
689 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
690 ap_handle_timer, hapd, sta);
691 }
692
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700693 /* initialize STA info data */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700694 os_memcpy(sta->addr, addr, ETH_ALEN);
695 sta->next = hapd->sta_list;
696 hapd->sta_list = sta;
697 hapd->num_sta++;
698 ap_sta_hash_add(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700699 ap_sta_remove_in_other_bss(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800700 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
701 dl_list_init(&sta->ip6addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700702
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700703#ifdef CONFIG_TAXONOMY
704 sta_track_claim_taxonomy_info(hapd->iface, addr,
705 &sta->probe_ie_taxonomy);
706#endif /* CONFIG_TAXONOMY */
707
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700708 return sta;
709}
710
711
712static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
713{
714 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
715
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800716 if (sta->ipaddr)
717 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
718 ap_sta_ip6addr_del(hapd, sta);
719
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800720 wpa_printf(MSG_DEBUG, "%s: Removing STA " MACSTR " from kernel driver",
721 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700722 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
723 sta->flags & WLAN_STA_ASSOC) {
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800724 wpa_printf(MSG_DEBUG, "%s: Could not remove station " MACSTR
725 " from kernel driver",
726 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700727 return -1;
728 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800729 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 return 0;
731}
732
733
734static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
735 struct sta_info *sta)
736{
737 struct hostapd_iface *iface = hapd->iface;
738 size_t i;
739
740 for (i = 0; i < iface->num_bss; i++) {
741 struct hostapd_data *bss = iface->bss[i];
742 struct sta_info *sta2;
743 /* bss should always be set during operation, but it may be
744 * NULL during reconfiguration. Assume the STA is not
745 * associated to another BSS in that case to avoid NULL pointer
746 * dereferences. */
747 if (bss == hapd || bss == NULL)
748 continue;
749 sta2 = ap_get_sta(bss, sta->addr);
750 if (!sta2)
751 continue;
752
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800753 wpa_printf(MSG_DEBUG, "%s: disconnect old STA " MACSTR
754 " association from another BSS %s",
755 hapd->conf->iface, MAC2STR(sta2->addr),
756 bss->conf->iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700757 ap_sta_disconnect(bss, sta2, sta2->addr,
758 WLAN_REASON_PREV_AUTH_NOT_VALID);
759 }
760}
761
762
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800763static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
764{
765 struct hostapd_data *hapd = eloop_ctx;
766 struct sta_info *sta = timeout_ctx;
767
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800768 wpa_printf(MSG_DEBUG, "%s: Disassociation callback for STA " MACSTR,
769 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800770 ap_sta_remove(hapd, sta);
771 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
772}
773
774
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700775void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
776 u16 reason)
777{
778 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
779 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800780 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800781 if (hapd->iface->current_mode &&
782 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
783 /* Skip deauthentication in DMG/IEEE 802.11ad */
784 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
785 WLAN_STA_ASSOC_REQ_OK);
786 sta->timeout_next = STA_REMOVE;
787 } else {
788 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
789 sta->timeout_next = STA_DEAUTH;
790 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800791 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700792 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
793 "for " MACSTR " (%d seconds - "
794 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
795 __func__, MAC2STR(sta->addr),
796 AP_MAX_INACTIVITY_AFTER_DISASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700797 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
798 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
799 ap_handle_timer, hapd, sta);
800 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800801 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700802
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800803 sta->disassoc_reason = reason;
804 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
805 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
806 eloop_register_timeout(hapd->iface->drv_flags &
807 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
808 ap_sta_disassoc_cb_timeout, hapd, sta);
809}
810
811
812static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
813{
814 struct hostapd_data *hapd = eloop_ctx;
815 struct sta_info *sta = timeout_ctx;
816
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800817 wpa_printf(MSG_DEBUG, "%s: Deauthentication callback for STA " MACSTR,
818 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800819 ap_sta_remove(hapd, sta);
820 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700821}
822
823
824void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
825 u16 reason)
826{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800827 if (hapd->iface->current_mode &&
828 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
829 /* Deauthentication is not used in DMG/IEEE 802.11ad;
830 * disassociate the STA instead. */
831 ap_sta_disassociate(hapd, sta, reason);
832 return;
833 }
834
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700835 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
836 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800837 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
838 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800839 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700840 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700841 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
842 "for " MACSTR " (%d seconds - "
843 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
844 __func__, MAC2STR(sta->addr),
845 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700846 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
847 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
848 ap_handle_timer, hapd, sta);
849 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800850 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700851
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800852 sta->deauth_reason = reason;
853 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
854 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
855 eloop_register_timeout(hapd->iface->drv_flags &
856 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
857 ap_sta_deauth_cb_timeout, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700858}
859
860
Dmitry Shmidt04949592012-07-19 12:16:46 -0700861#ifdef CONFIG_WPS
862int ap_sta_wps_cancel(struct hostapd_data *hapd,
863 struct sta_info *sta, void *ctx)
864{
865 if (sta && (sta->flags & WLAN_STA_WPS)) {
866 ap_sta_deauthenticate(hapd, sta,
867 WLAN_REASON_PREV_AUTH_NOT_VALID);
868 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
869 __func__, MAC2STR(sta->addr));
870 return 1;
871 }
872
873 return 0;
874}
875#endif /* CONFIG_WPS */
876
877
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800878static int ap_sta_get_free_vlan_id(struct hostapd_data *hapd)
879{
880 struct hostapd_vlan *vlan;
881 int vlan_id = MAX_VLAN_ID + 2;
882
883retry:
884 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
885 if (vlan->vlan_id == vlan_id) {
886 vlan_id++;
887 goto retry;
888 }
889 }
890 return vlan_id;
891}
892
893
894int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta,
895 struct vlan_description *vlan_desc)
896{
897 struct hostapd_vlan *vlan = NULL, *wildcard_vlan = NULL;
898 int old_vlan_id, vlan_id = 0, ret = 0;
899
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800900 /* Check if there is something to do */
901 if (hapd->conf->ssid.per_sta_vif && !sta->vlan_id) {
902 /* This sta is lacking its own vif */
903 } else if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED &&
904 !hapd->conf->ssid.per_sta_vif && sta->vlan_id) {
905 /* sta->vlan_id needs to be reset */
906 } else if (!vlan_compare(vlan_desc, sta->vlan_desc)) {
907 return 0; /* nothing to change */
908 }
909
910 /* Now the real VLAN changed or the STA just needs its own vif */
911 if (hapd->conf->ssid.per_sta_vif) {
912 /* Assign a new vif, always */
913 /* find a free vlan_id sufficiently big */
914 vlan_id = ap_sta_get_free_vlan_id(hapd);
915 /* Get wildcard VLAN */
916 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
917 if (vlan->vlan_id == VLAN_ID_WILDCARD)
918 break;
919 }
920 if (!vlan) {
921 hostapd_logger(hapd, sta->addr,
922 HOSTAPD_MODULE_IEEE80211,
923 HOSTAPD_LEVEL_DEBUG,
924 "per_sta_vif missing wildcard");
925 vlan_id = 0;
926 ret = -1;
927 goto done;
928 }
929 } else if (vlan_desc && vlan_desc->notempty) {
930 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
931 if (!vlan_compare(&vlan->vlan_desc, vlan_desc))
932 break;
933 if (vlan->vlan_id == VLAN_ID_WILDCARD)
934 wildcard_vlan = vlan;
935 }
936 if (vlan) {
937 vlan_id = vlan->vlan_id;
938 } else if (wildcard_vlan) {
939 vlan = wildcard_vlan;
940 vlan_id = vlan_desc->untagged;
941 if (vlan_desc->tagged[0]) {
942 /* Tagged VLAN configuration */
943 vlan_id = ap_sta_get_free_vlan_id(hapd);
944 }
945 } else {
946 hostapd_logger(hapd, sta->addr,
947 HOSTAPD_MODULE_IEEE80211,
948 HOSTAPD_LEVEL_DEBUG,
949 "missing vlan and wildcard for vlan=%d%s",
950 vlan_desc->untagged,
951 vlan_desc->tagged[0] ? "+" : "");
952 vlan_id = 0;
953 ret = -1;
954 goto done;
955 }
956 }
957
958 if (vlan && vlan->vlan_id == VLAN_ID_WILDCARD) {
959 vlan = vlan_add_dynamic(hapd, vlan, vlan_id, vlan_desc);
960 if (vlan == NULL) {
961 hostapd_logger(hapd, sta->addr,
962 HOSTAPD_MODULE_IEEE80211,
963 HOSTAPD_LEVEL_DEBUG,
964 "could not add dynamic VLAN interface for vlan=%d%s",
965 vlan_desc ? vlan_desc->untagged : -1,
966 (vlan_desc && vlan_desc->tagged[0]) ?
967 "+" : "");
968 vlan_id = 0;
969 ret = -1;
970 goto done;
971 }
972
973 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
974 HOSTAPD_LEVEL_DEBUG,
975 "added new dynamic VLAN interface '%s'",
976 vlan->ifname);
977 } else if (vlan && vlan->dynamic_vlan > 0) {
978 vlan->dynamic_vlan++;
979 hostapd_logger(hapd, sta->addr,
980 HOSTAPD_MODULE_IEEE80211,
981 HOSTAPD_LEVEL_DEBUG,
982 "updated existing dynamic VLAN interface '%s'",
983 vlan->ifname);
984 }
985done:
986 old_vlan_id = sta->vlan_id;
987 sta->vlan_id = vlan_id;
988 sta->vlan_desc = vlan ? &vlan->vlan_desc : NULL;
989
990 if (vlan_id != old_vlan_id && old_vlan_id)
991 vlan_remove_dynamic(hapd, old_vlan_id);
992
993 return ret;
994}
995
996
Dmitry Shmidt83474442015-04-15 13:47:09 -0700997int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700998{
999#ifndef CONFIG_NO_VLAN
1000 const char *iface;
1001 struct hostapd_vlan *vlan = NULL;
1002 int ret;
Dmitry Shmidt83474442015-04-15 13:47:09 -07001003 int old_vlanid = sta->vlan_id_bound;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001004
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001005 iface = hapd->conf->iface;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07001006 if (hapd->conf->ssid.vlan[0])
1007 iface = hapd->conf->ssid.vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001008
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001009 if (sta->vlan_id > 0) {
1010 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001011 if (vlan->vlan_id == sta->vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001012 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001013 }
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07001014 if (vlan)
1015 iface = vlan->ifname;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001016 }
1017
Dmitry Shmidt83474442015-04-15 13:47:09 -07001018 /*
1019 * Do not increment ref counters if the VLAN ID remains same, but do
1020 * not skip hostapd_drv_set_sta_vlan() as hostapd_drv_sta_remove() might
1021 * have been called before.
1022 */
1023 if (sta->vlan_id == old_vlanid)
1024 goto skip_counting;
1025
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001026 if (sta->vlan_id > 0 && vlan == NULL) {
1027 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1028 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
1029 "binding station to (vlan_id=%d)",
1030 sta->vlan_id);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001031 ret = -1;
1032 goto done;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001033 } else if (vlan && vlan->dynamic_vlan > 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001034 vlan->dynamic_vlan++;
1035 hostapd_logger(hapd, sta->addr,
1036 HOSTAPD_MODULE_IEEE80211,
1037 HOSTAPD_LEVEL_DEBUG,
1038 "updated existing dynamic VLAN interface '%s'",
1039 iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040 }
1041
Dmitry Shmidt83474442015-04-15 13:47:09 -07001042 /* ref counters have been increased, so mark the station */
1043 sta->vlan_id_bound = sta->vlan_id;
1044
1045skip_counting:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001046 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1047 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
1048 "'%s'", iface);
1049
1050 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
1051 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
1052
1053 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
1054 if (ret < 0) {
1055 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1056 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
1057 "entry to vlan_id=%d", sta->vlan_id);
1058 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001059
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001060 /* During 1x reauth, if the vlan id changes, then remove the old id. */
Dmitry Shmidt83474442015-04-15 13:47:09 -07001061 if (old_vlanid > 0 && old_vlanid != sta->vlan_id)
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001062 vlan_remove_dynamic(hapd, old_vlanid);
Dmitry Shmidt83474442015-04-15 13:47:09 -07001063done:
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001064
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001065 return ret;
1066#else /* CONFIG_NO_VLAN */
1067 return 0;
1068#endif /* CONFIG_NO_VLAN */
1069}
1070
1071
1072#ifdef CONFIG_IEEE80211W
1073
1074int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
1075{
1076 u32 tu;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001077 struct os_reltime now, passed;
1078 os_get_reltime(&now);
1079 os_reltime_sub(&now, &sta->sa_query_start, &passed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001080 tu = (passed.sec * 1000000 + passed.usec) / 1024;
1081 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
1082 hostapd_logger(hapd, sta->addr,
1083 HOSTAPD_MODULE_IEEE80211,
1084 HOSTAPD_LEVEL_DEBUG,
1085 "association SA Query timed out");
1086 sta->sa_query_timed_out = 1;
1087 os_free(sta->sa_query_trans_id);
1088 sta->sa_query_trans_id = NULL;
1089 sta->sa_query_count = 0;
1090 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1091 return 1;
1092 }
1093
1094 return 0;
1095}
1096
1097
1098static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
1099{
1100 struct hostapd_data *hapd = eloop_ctx;
1101 struct sta_info *sta = timeout_ctx;
1102 unsigned int timeout, sec, usec;
1103 u8 *trans_id, *nbuf;
1104
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001105 wpa_printf(MSG_DEBUG, "%s: SA Query timer for STA " MACSTR
1106 " (count=%d)",
1107 hapd->conf->iface, MAC2STR(sta->addr), sta->sa_query_count);
1108
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001109 if (sta->sa_query_count > 0 &&
1110 ap_check_sa_query_timeout(hapd, sta))
1111 return;
1112
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001113 nbuf = os_realloc_array(sta->sa_query_trans_id,
1114 sta->sa_query_count + 1,
1115 WLAN_SA_QUERY_TR_ID_LEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001116 if (nbuf == NULL)
1117 return;
1118 if (sta->sa_query_count == 0) {
1119 /* Starting a new SA Query procedure */
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001120 os_get_reltime(&sta->sa_query_start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001121 }
1122 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
1123 sta->sa_query_trans_id = nbuf;
1124 sta->sa_query_count++;
1125
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001126 if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) {
1127 /*
1128 * We don't really care which ID is used here, so simply
1129 * hardcode this if the mostly theoretical os_get_random()
1130 * failure happens.
1131 */
1132 trans_id[0] = 0x12;
1133 trans_id[1] = 0x34;
1134 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001135
1136 timeout = hapd->conf->assoc_sa_query_retry_timeout;
1137 sec = ((timeout / 1000) * 1024) / 1000;
1138 usec = (timeout % 1000) * 1024;
1139 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
1140
1141 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1142 HOSTAPD_LEVEL_DEBUG,
1143 "association SA Query attempt %d", sta->sa_query_count);
1144
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001145 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001146}
1147
1148
1149void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1150{
1151 ap_sa_query_timer(hapd, sta);
1152}
1153
1154
1155void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1156{
1157 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1158 os_free(sta->sa_query_trans_id);
1159 sta->sa_query_trans_id = NULL;
1160 sta->sa_query_count = 0;
1161}
1162
1163#endif /* CONFIG_IEEE80211W */
1164
1165
Hai Shalom39bc25d2019-02-06 16:32:13 -08001166const char * ap_sta_wpa_get_keyid(struct hostapd_data *hapd,
1167 struct sta_info *sta)
1168{
1169 struct hostapd_wpa_psk *psk;
1170 struct hostapd_ssid *ssid;
1171 const u8 *pmk;
1172 int pmk_len;
1173
1174 ssid = &hapd->conf->ssid;
1175
1176 pmk = wpa_auth_get_pmk(sta->wpa_sm, &pmk_len);
1177 if (!pmk || pmk_len != PMK_LEN)
1178 return NULL;
1179
1180 for (psk = ssid->wpa_psk; psk; psk = psk->next)
1181 if (os_memcmp(pmk, psk->psk, PMK_LEN) == 0)
1182 break;
1183 if (!psk)
1184 return NULL;
1185 if (!psk || !psk->keyid[0])
1186 return NULL;
1187
1188 return psk->keyid;
1189}
1190
1191
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001192void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
1193 int authorized)
1194{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001195 const u8 *dev_addr = NULL;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001196 char buf[100];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001197#ifdef CONFIG_P2P
1198 u8 addr[ETH_ALEN];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001199 u8 ip_addr_buf[4];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001200#endif /* CONFIG_P2P */
1201
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001202 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
1203 return;
1204
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001205 if (authorized)
1206 sta->flags |= WLAN_STA_AUTHORIZED;
1207 else
1208 sta->flags &= ~WLAN_STA_AUTHORIZED;
1209
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001210#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001211 if (hapd->p2p_group == NULL) {
1212 if (sta->p2p_ie != NULL &&
1213 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
1214 dev_addr = addr;
1215 } else
1216 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001217
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001218 if (dev_addr)
1219 os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
1220 MAC2STR(sta->addr), MAC2STR(dev_addr));
1221 else
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001222#endif /* CONFIG_P2P */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001223 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
1224
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001225 if (hapd->sta_authorized_cb)
1226 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
1227 sta->addr, authorized, dev_addr);
1228
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001229 if (authorized) {
Hai Shalom39bc25d2019-02-06 16:32:13 -08001230 const char *keyid;
1231 char keyid_buf[100];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001232 char ip_addr[100];
Hai Shalom39bc25d2019-02-06 16:32:13 -08001233
1234 keyid_buf[0] = '\0';
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001235 ip_addr[0] = '\0';
1236#ifdef CONFIG_P2P
1237 if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) {
1238 os_snprintf(ip_addr, sizeof(ip_addr),
1239 " ip_addr=%u.%u.%u.%u",
1240 ip_addr_buf[0], ip_addr_buf[1],
1241 ip_addr_buf[2], ip_addr_buf[3]);
1242 }
1243#endif /* CONFIG_P2P */
1244
Hai Shalom39bc25d2019-02-06 16:32:13 -08001245 keyid = ap_sta_wpa_get_keyid(hapd, sta);
1246 if (keyid) {
1247 os_snprintf(keyid_buf, sizeof(keyid_buf),
1248 " keyid=%s", keyid);
1249 }
1250
1251 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s",
1252 buf, ip_addr, keyid_buf);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001253
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001254 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001255 hapd->msg_ctx_parent != hapd->msg_ctx)
1256 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
Hai Shalom39bc25d2019-02-06 16:32:13 -08001257 AP_STA_CONNECTED "%s%s%s",
1258 buf, ip_addr, keyid_buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001259 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001260 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
1261
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001262 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001263 hapd->msg_ctx_parent != hapd->msg_ctx)
1264 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
1265 AP_STA_DISCONNECTED "%s", buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001266 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001267
1268#ifdef CONFIG_FST
1269 if (hapd->iface->fst) {
1270 if (authorized)
1271 fst_notify_peer_connected(hapd->iface->fst, sta->addr);
1272 else
1273 fst_notify_peer_disconnected(hapd->iface->fst,
1274 sta->addr);
1275 }
1276#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001277}
1278
1279
1280void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
1281 const u8 *addr, u16 reason)
1282{
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001283 if (sta)
1284 wpa_printf(MSG_DEBUG, "%s: %s STA " MACSTR " reason=%u",
1285 hapd->conf->iface, __func__, MAC2STR(sta->addr),
1286 reason);
1287 else if (addr)
1288 wpa_printf(MSG_DEBUG, "%s: %s addr " MACSTR " reason=%u",
1289 hapd->conf->iface, __func__, MAC2STR(addr),
1290 reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001291
1292 if (sta == NULL && addr)
1293 sta = ap_get_sta(hapd, addr);
1294
1295 if (addr)
1296 hostapd_drv_sta_deauth(hapd, addr, reason);
1297
1298 if (sta == NULL)
1299 return;
1300 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001301 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1302 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001303 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001304 wpa_printf(MSG_DEBUG, "%s: %s: reschedule ap_handle_timer timeout "
Dmitry Shmidt04949592012-07-19 12:16:46 -07001305 "for " MACSTR " (%d seconds - "
1306 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001307 hapd->conf->iface, __func__, MAC2STR(sta->addr),
Dmitry Shmidt04949592012-07-19 12:16:46 -07001308 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001309 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001310 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
1311 ap_handle_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001312 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001313
Dmitry Shmidt29333592017-01-09 12:27:11 -08001314 if (hapd->iface->current_mode &&
1315 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
1316 /* Deauthentication is not used in DMG/IEEE 802.11ad;
1317 * disassociate the STA instead. */
1318 sta->disassoc_reason = reason;
1319 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
1320 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1321 eloop_register_timeout(hapd->iface->drv_flags &
1322 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ?
1323 2 : 0, 0, ap_sta_disassoc_cb_timeout,
1324 hapd, sta);
1325 return;
1326 }
1327
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001328 sta->deauth_reason = reason;
1329 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
1330 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1331 eloop_register_timeout(hapd->iface->drv_flags &
1332 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
1333 ap_sta_deauth_cb_timeout, hapd, sta);
1334}
1335
1336
1337void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
1338{
1339 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
1340 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
1341 return;
1342 }
1343 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
1344 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1345 ap_sta_deauth_cb_timeout(hapd, sta);
1346}
1347
1348
1349void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
1350{
1351 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
1352 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
1353 return;
1354 }
1355 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
1356 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1357 ap_sta_disassoc_cb_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001358}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001359
1360
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001361void ap_sta_clear_disconnect_timeouts(struct hostapd_data *hapd,
1362 struct sta_info *sta)
1363{
1364 if (eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta) > 0)
1365 wpa_printf(MSG_DEBUG,
1366 "%s: Removed ap_sta_deauth_cb_timeout timeout for "
1367 MACSTR,
1368 hapd->conf->iface, MAC2STR(sta->addr));
1369 if (eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta) > 0)
1370 wpa_printf(MSG_DEBUG,
1371 "%s: Removed ap_sta_disassoc_cb_timeout timeout for "
1372 MACSTR,
1373 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt29333592017-01-09 12:27:11 -08001374 if (eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta) > 0)
1375 {
1376 wpa_printf(MSG_DEBUG,
1377 "%s: Removed ap_sta_delayed_1x_auth_fail_cb timeout for "
1378 MACSTR,
1379 hapd->conf->iface, MAC2STR(sta->addr));
1380 if (sta->flags & WLAN_STA_WPS)
1381 hostapd_wps_eap_completed(hapd);
1382 }
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001383}
1384
1385
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001386int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen)
1387{
1388 int res;
1389
1390 buf[0] = '\0';
Roshan Pius3a1667e2018-07-03 15:17:14 -07001391 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 -08001392 (flags & WLAN_STA_AUTH ? "[AUTH]" : ""),
1393 (flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""),
1394 (flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : ""),
1395 (flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
1396 ""),
1397 (flags & WLAN_STA_SHORT_PREAMBLE ?
1398 "[SHORT_PREAMBLE]" : ""),
1399 (flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
1400 (flags & WLAN_STA_WMM ? "[WMM]" : ""),
1401 (flags & WLAN_STA_MFP ? "[MFP]" : ""),
1402 (flags & WLAN_STA_WPS ? "[WPS]" : ""),
1403 (flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""),
1404 (flags & WLAN_STA_WDS ? "[WDS]" : ""),
1405 (flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
1406 (flags & WLAN_STA_WPS2 ? "[WPS2]" : ""),
1407 (flags & WLAN_STA_GAS ? "[GAS]" : ""),
Roshan Pius3a1667e2018-07-03 15:17:14 -07001408 (flags & WLAN_STA_HT ? "[HT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001409 (flags & WLAN_STA_VHT ? "[VHT]" : ""),
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001410 (flags & WLAN_STA_VENDOR_VHT ? "[VENDOR_VHT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001411 (flags & WLAN_STA_WNM_SLEEP_MODE ?
1412 "[WNM_SLEEP_MODE]" : ""));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001413 if (os_snprintf_error(buflen, res))
1414 res = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001415
1416 return res;
1417}
Dmitry Shmidt29333592017-01-09 12:27:11 -08001418
1419
1420static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx)
1421{
1422 struct hostapd_data *hapd = eloop_ctx;
1423 struct sta_info *sta = timeout_ctx;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001424 u16 reason;
Dmitry Shmidt29333592017-01-09 12:27:11 -08001425
1426 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1427 "IEEE 802.1X: Scheduled disconnection of " MACSTR
1428 " after EAP-Failure", MAC2STR(sta->addr));
1429
Roshan Pius3a1667e2018-07-03 15:17:14 -07001430 reason = sta->disconnect_reason_code;
1431 if (!reason)
1432 reason = WLAN_REASON_IEEE_802_1X_AUTH_FAILED;
1433 ap_sta_disconnect(hapd, sta, sta->addr, reason);
Dmitry Shmidt29333592017-01-09 12:27:11 -08001434 if (sta->flags & WLAN_STA_WPS)
1435 hostapd_wps_eap_completed(hapd);
1436}
1437
1438
1439void ap_sta_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1440 struct sta_info *sta)
1441{
1442 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1443 "IEEE 802.1X: Force disconnection of " MACSTR
1444 " after EAP-Failure in 10 ms", MAC2STR(sta->addr));
1445
1446 /*
1447 * Add a small sleep to increase likelihood of previously requested
1448 * EAP-Failure TX getting out before this should the driver reorder
1449 * operations.
1450 */
1451 eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta);
1452 eloop_register_timeout(0, 10000, ap_sta_delayed_1x_auth_fail_cb,
1453 hapd, sta);
1454}
1455
1456
1457int ap_sta_pending_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1458 struct sta_info *sta)
1459{
1460 return eloop_is_timeout_registered(ap_sta_delayed_1x_auth_fail_cb,
1461 hapd, sta);
1462}