blob: b87ddeac3be13f6a25cba3aad3fec61092ac5728 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Station table
Dmitry Shmidt29333592017-01-09 12:27:11 -08003 * Copyright (c) 2002-2016, 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 Shmidt8d520ff2011-05-09 14:06:53 -070020#include "hostapd.h"
21#include "accounting.h"
22#include "ieee802_1x.h"
23#include "ieee802_11.h"
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080024#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025#include "wpa_auth.h"
26#include "preauth_auth.h"
27#include "ap_config.h"
28#include "beacon.h"
29#include "ap_mlme.h"
30#include "vlan_init.h"
31#include "p2p_hostapd.h"
32#include "ap_drv_ops.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070033#include "gas_serv.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080034#include "wnm_ap.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080035#include "mbo_ap.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080036#include "ndisc_snoop.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037#include "sta_info.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080038#include "vlan.h"
Dmitry Shmidt29333592017-01-09 12:27:11 -080039#include "wps_hostapd.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040
41static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
42 struct sta_info *sta);
43static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080044static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080045static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
46static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070047#ifdef CONFIG_IEEE80211W
48static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
49#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080050static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
Dmitry Shmidt29333592017-01-09 12:27:11 -080051static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070052
53int ap_for_each_sta(struct hostapd_data *hapd,
54 int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
55 void *ctx),
56 void *ctx)
57{
58 struct sta_info *sta;
59
60 for (sta = hapd->sta_list; sta; sta = sta->next) {
61 if (cb(hapd, sta, ctx))
62 return 1;
63 }
64
65 return 0;
66}
67
68
69struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
70{
71 struct sta_info *s;
72
73 s = hapd->sta_hash[STA_HASH(sta)];
74 while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
75 s = s->hnext;
76 return s;
77}
78
79
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070080#ifdef CONFIG_P2P
81struct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr)
82{
83 struct sta_info *sta;
84
85 for (sta = hapd->sta_list; sta; sta = sta->next) {
86 const u8 *p2p_dev_addr;
87
88 if (sta->p2p_ie == NULL)
89 continue;
90
91 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
92 if (p2p_dev_addr == NULL)
93 continue;
94
95 if (os_memcmp(p2p_dev_addr, addr, ETH_ALEN) == 0)
96 return sta;
97 }
98
99 return NULL;
100}
101#endif /* CONFIG_P2P */
102
103
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
105{
106 struct sta_info *tmp;
107
108 if (hapd->sta_list == sta) {
109 hapd->sta_list = sta->next;
110 return;
111 }
112
113 tmp = hapd->sta_list;
114 while (tmp != NULL && tmp->next != sta)
115 tmp = tmp->next;
116 if (tmp == NULL) {
117 wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
118 "list.", MAC2STR(sta->addr));
119 } else
120 tmp->next = sta->next;
121}
122
123
124void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
125{
126 sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
127 hapd->sta_hash[STA_HASH(sta->addr)] = sta;
128}
129
130
131static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
132{
133 struct sta_info *s;
134
135 s = hapd->sta_hash[STA_HASH(sta->addr)];
136 if (s == NULL) return;
137 if (os_memcmp(s->addr, sta->addr, 6) == 0) {
138 hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
139 return;
140 }
141
142 while (s->hnext != NULL &&
143 os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
144 s = s->hnext;
145 if (s->hnext != NULL)
146 s->hnext = s->hnext->hnext;
147 else
148 wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
149 " from hash table", MAC2STR(sta->addr));
150}
151
152
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800153void ap_sta_ip6addr_del(struct hostapd_data *hapd, struct sta_info *sta)
154{
155 sta_ip6addr_del(hapd, sta);
156}
157
158
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
160{
161 int set_beacon = 0;
162
163 accounting_sta_stop(hapd, sta);
164
165 /* just in case */
166 ap_sta_set_authorized(hapd, sta, 0);
167
168 if (sta->flags & WLAN_STA_WDS)
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700169 hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700170
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800171 if (sta->ipaddr)
172 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
173 ap_sta_ip6addr_del(hapd, sta);
174
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800175 if (!hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800176 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700177 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800178 sta->added_unassoc = 0;
179 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180
181 ap_sta_hash_del(hapd, sta);
182 ap_sta_list_del(hapd, sta);
183
184 if (sta->aid > 0)
185 hapd->sta_aid[(sta->aid - 1) / 32] &=
186 ~BIT((sta->aid - 1) % 32);
187
188 hapd->num_sta--;
189 if (sta->nonerp_set) {
190 sta->nonerp_set = 0;
191 hapd->iface->num_sta_non_erp--;
192 if (hapd->iface->num_sta_non_erp == 0)
193 set_beacon++;
194 }
195
196 if (sta->no_short_slot_time_set) {
197 sta->no_short_slot_time_set = 0;
198 hapd->iface->num_sta_no_short_slot_time--;
199 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
200 && hapd->iface->num_sta_no_short_slot_time == 0)
201 set_beacon++;
202 }
203
204 if (sta->no_short_preamble_set) {
205 sta->no_short_preamble_set = 0;
206 hapd->iface->num_sta_no_short_preamble--;
207 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
208 && hapd->iface->num_sta_no_short_preamble == 0)
209 set_beacon++;
210 }
211
212 if (sta->no_ht_gf_set) {
213 sta->no_ht_gf_set = 0;
214 hapd->iface->num_sta_ht_no_gf--;
215 }
216
217 if (sta->no_ht_set) {
218 sta->no_ht_set = 0;
219 hapd->iface->num_sta_no_ht--;
220 }
221
222 if (sta->ht_20mhz_set) {
223 sta->ht_20mhz_set = 0;
224 hapd->iface->num_sta_ht_20mhz--;
225 }
226
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700227#ifdef CONFIG_TAXONOMY
228 wpabuf_free(sta->probe_ie_taxonomy);
229 sta->probe_ie_taxonomy = NULL;
230 wpabuf_free(sta->assoc_ie_taxonomy);
231 sta->assoc_ie_taxonomy = NULL;
232#endif /* CONFIG_TAXONOMY */
233
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700234#ifdef CONFIG_IEEE80211N
235 ht40_intolerant_remove(hapd->iface, sta);
236#endif /* CONFIG_IEEE80211N */
237
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700238#ifdef CONFIG_P2P
239 if (sta->no_p2p_set) {
240 sta->no_p2p_set = 0;
241 hapd->num_sta_no_p2p--;
242 if (hapd->num_sta_no_p2p == 0)
243 hostapd_p2p_non_p2p_sta_disconnected(hapd);
244 }
245#endif /* CONFIG_P2P */
246
247#if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
248 if (hostapd_ht_operation_update(hapd->iface) > 0)
249 set_beacon++;
250#endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
251
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800252#ifdef CONFIG_MESH
253 if (hapd->mesh_sta_free_cb)
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800254 hapd->mesh_sta_free_cb(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800255#endif /* CONFIG_MESH */
256
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700257 if (set_beacon)
258 ieee802_11_set_beacons(hapd->iface);
259
Dmitry Shmidt04949592012-07-19 12:16:46 -0700260 wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
261 __func__, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700262 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
263 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800264 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800265 ap_sta_clear_disconnect_timeouts(hapd, sta);
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800266 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700267
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800268 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700269 wpa_auth_sta_deinit(sta->wpa_sm);
270 rsn_preauth_free_station(hapd, sta);
271#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt96571392013-10-14 12:54:46 -0700272 if (hapd->radius)
273 radius_client_flush_auth(hapd->radius, sta->addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700274#endif /* CONFIG_NO_RADIUS */
275
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800276#ifndef CONFIG_NO_VLAN
277 /*
278 * sta->wpa_sm->group needs to be released before so that
279 * vlan_remove_dynamic() can check that no stations are left on the
280 * AP_VLAN netdev.
281 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800282 if (sta->vlan_id)
283 vlan_remove_dynamic(hapd, sta->vlan_id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800284 if (sta->vlan_id_bound) {
285 /*
286 * Need to remove the STA entry before potentially removing the
287 * VLAN.
288 */
289 if (hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800290 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800291 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800292 sta->added_unassoc = 0;
293 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800294 vlan_remove_dynamic(hapd, sta->vlan_id_bound);
295 }
296#endif /* CONFIG_NO_VLAN */
297
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700298 os_free(sta->challenge);
299
300#ifdef CONFIG_IEEE80211W
301 os_free(sta->sa_query_trans_id);
302 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
303#endif /* CONFIG_IEEE80211W */
304
305#ifdef CONFIG_P2P
306 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
307#endif /* CONFIG_P2P */
308
Dmitry Shmidt04949592012-07-19 12:16:46 -0700309#ifdef CONFIG_INTERWORKING
310 if (sta->gas_dialog) {
311 int i;
312 for (i = 0; i < GAS_DIALOG_MAX; i++)
313 gas_serv_dialog_clear(&sta->gas_dialog[i]);
314 os_free(sta->gas_dialog);
315 }
316#endif /* CONFIG_INTERWORKING */
317
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700318 wpabuf_free(sta->wps_ie);
319 wpabuf_free(sta->p2p_ie);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800320 wpabuf_free(sta->hs20_ie);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800321#ifdef CONFIG_FST
322 wpabuf_free(sta->mb_ies);
323#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324
325 os_free(sta->ht_capabilities);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -0800326 os_free(sta->vht_capabilities);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800327 hostapd_free_psk_list(sta->psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700328 os_free(sta->identity);
329 os_free(sta->radius_cui);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800330 os_free(sta->remediation_url);
331 wpabuf_free(sta->hs20_deauth_req);
332 os_free(sta->hs20_session_info_url);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800334#ifdef CONFIG_SAE
335 sae_clear_data(sta->sae);
336 os_free(sta->sae);
337#endif /* CONFIG_SAE */
338
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800339 mbo_ap_sta_free(sta);
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800340 os_free(sta->supp_op_classes);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800341
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342 os_free(sta);
343}
344
345
346void hostapd_free_stas(struct hostapd_data *hapd)
347{
348 struct sta_info *sta, *prev;
349
350 sta = hapd->sta_list;
351
352 while (sta) {
353 prev = sta;
354 if (sta->flags & WLAN_STA_AUTH) {
355 mlme_deauthenticate_indication(
356 hapd, sta, WLAN_REASON_UNSPECIFIED);
357 }
358 sta = sta->next;
359 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
360 MAC2STR(prev->addr));
361 ap_free_sta(hapd, prev);
362 }
363}
364
365
366/**
367 * ap_handle_timer - Per STA timer handler
368 * @eloop_ctx: struct hostapd_data *
369 * @timeout_ctx: struct sta_info *
370 *
371 * This function is called to check station activity and to remove inactive
372 * stations.
373 */
374void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
375{
376 struct hostapd_data *hapd = eloop_ctx;
377 struct sta_info *sta = timeout_ctx;
378 unsigned long next_time = 0;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700379 int reason;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700380
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800381 wpa_printf(MSG_DEBUG, "%s: %s: " MACSTR " flags=0x%x timeout_next=%d",
382 hapd->conf->iface, __func__, MAC2STR(sta->addr), sta->flags,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700383 sta->timeout_next);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700384 if (sta->timeout_next == STA_REMOVE) {
385 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
386 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
387 "local deauth request");
388 ap_free_sta(hapd, sta);
389 return;
390 }
391
392 if ((sta->flags & WLAN_STA_ASSOC) &&
393 (sta->timeout_next == STA_NULLFUNC ||
394 sta->timeout_next == STA_DISASSOC)) {
395 int inactive_sec;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700396 /*
397 * Add random value to timeout so that we don't end up bouncing
398 * all stations at the same time if we have lots of associated
399 * stations that are idle (but keep re-associating).
400 */
401 int fuzz = os_random() % 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700402 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
403 if (inactive_sec == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800404 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
405 "Check inactivity: Could not "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800406 "get station info from kernel driver for "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700407 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800408 /*
409 * The driver may not support this functionality.
410 * Anyway, try again after the next inactivity timeout,
411 * but do not disconnect the station now.
412 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700413 next_time = hapd->conf->ap_max_inactivity + fuzz;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800414 } else if (inactive_sec == -ENOENT) {
415 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
416 "Station " MACSTR " has lost its driver entry",
417 MAC2STR(sta->addr));
418
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800419 /* Avoid sending client probe on removed client */
420 sta->timeout_next = STA_DISASSOC;
421 goto skip_poll;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800422 } else if (inactive_sec < hapd->conf->ap_max_inactivity) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700423 /* station activity detected; reset timeout state */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800424 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
425 "Station " MACSTR " has been active %is ago",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700426 MAC2STR(sta->addr), inactive_sec);
427 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700428 next_time = hapd->conf->ap_max_inactivity + fuzz -
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700429 inactive_sec;
430 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800431 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
432 "Station " MACSTR " has been "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700433 "inactive too long: %d sec, max allowed: %d",
434 MAC2STR(sta->addr), inactive_sec,
435 hapd->conf->ap_max_inactivity);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800436
437 if (hapd->conf->skip_inactivity_poll)
438 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700439 }
440 }
441
442 if ((sta->flags & WLAN_STA_ASSOC) &&
443 sta->timeout_next == STA_DISASSOC &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800444 !(sta->flags & WLAN_STA_PENDING_POLL) &&
445 !hapd->conf->skip_inactivity_poll) {
446 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
447 " has ACKed data poll", MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700448 /* data nullfunc frame poll did not produce TX errors; assume
449 * station ACKed it */
450 sta->timeout_next = STA_NULLFUNC;
451 next_time = hapd->conf->ap_max_inactivity;
452 }
453
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800454skip_poll:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700455 if (next_time) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700456 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
457 "for " MACSTR " (%lu seconds)",
458 __func__, MAC2STR(sta->addr), next_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700459 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
460 sta);
461 return;
462 }
463
464 if (sta->timeout_next == STA_NULLFUNC &&
465 (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800466 wpa_printf(MSG_DEBUG, " Polling STA");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700467 sta->flags |= WLAN_STA_PENDING_POLL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800468 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
469 sta->flags & WLAN_STA_WMM);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700470 } else if (sta->timeout_next != STA_REMOVE) {
471 int deauth = sta->timeout_next == STA_DEAUTH;
472
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800473 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
474 "Timeout, sending %s info to STA " MACSTR,
475 deauth ? "deauthentication" : "disassociation",
476 MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700477
478 if (deauth) {
479 hostapd_drv_sta_deauth(
480 hapd, sta->addr,
481 WLAN_REASON_PREV_AUTH_NOT_VALID);
482 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700483 reason = (sta->timeout_next == STA_DISASSOC) ?
484 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
485 WLAN_REASON_PREV_AUTH_NOT_VALID;
486
487 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700488 }
489 }
490
491 switch (sta->timeout_next) {
492 case STA_NULLFUNC:
493 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700494 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
495 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
496 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700497 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
498 hapd, sta);
499 break;
500 case STA_DISASSOC:
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700501 case STA_DISASSOC_FROM_CLI:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800502 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700503 sta->flags &= ~WLAN_STA_ASSOC;
504 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
505 if (!sta->acct_terminate_cause)
506 sta->acct_terminate_cause =
507 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
508 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800509 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700510 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
511 HOSTAPD_LEVEL_INFO, "disassociated due to "
512 "inactivity");
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;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700516 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700517 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
518 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
519 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
521 hapd, sta);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700522 mlme_disassociate_indication(hapd, sta, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700523 break;
524 case STA_DEAUTH:
525 case STA_REMOVE:
526 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
527 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800528 "inactivity (timer DEAUTH/REMOVE)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529 if (!sta->acct_terminate_cause)
530 sta->acct_terminate_cause =
531 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
532 mlme_deauthenticate_indication(
533 hapd, sta,
534 WLAN_REASON_PREV_AUTH_NOT_VALID);
535 ap_free_sta(hapd, sta);
536 break;
537 }
538}
539
540
541static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
542{
543 struct hostapd_data *hapd = eloop_ctx;
544 struct sta_info *sta = timeout_ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700545
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800546 wpa_printf(MSG_DEBUG, "%s: Session timer for STA " MACSTR,
547 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700548 if (!(sta->flags & WLAN_STA_AUTH)) {
549 if (sta->flags & WLAN_STA_GAS) {
550 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
551 "entry " MACSTR, MAC2STR(sta->addr));
552 ap_free_sta(hapd, sta);
553 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700554 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700555 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700556
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700557 hostapd_drv_sta_deauth(hapd, sta->addr,
558 WLAN_REASON_PREV_AUTH_NOT_VALID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700559 mlme_deauthenticate_indication(hapd, sta,
560 WLAN_REASON_PREV_AUTH_NOT_VALID);
561 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
562 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
563 "session timeout");
564 sta->acct_terminate_cause =
565 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700566 ap_free_sta(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700567}
568
569
Dmitry Shmidt54605472013-11-08 11:10:19 -0800570void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta,
571 u32 session_timeout)
572{
573 if (eloop_replenish_timeout(session_timeout, 0,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800574 ap_handle_session_timer, hapd, sta) == 1) {
Dmitry Shmidt54605472013-11-08 11:10:19 -0800575 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
576 HOSTAPD_LEVEL_DEBUG, "setting session timeout "
577 "to %d seconds", session_timeout);
578 }
579}
580
581
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700582void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
583 u32 session_timeout)
584{
585 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
586 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
587 "seconds", session_timeout);
588 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
589 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
590 hapd, sta);
591}
592
593
594void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
595{
596 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
597}
598
599
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800600static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx)
601{
602#ifdef CONFIG_WNM
603 struct hostapd_data *hapd = eloop_ctx;
604 struct sta_info *sta = timeout_ctx;
605
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800606 wpa_printf(MSG_DEBUG, "%s: WNM: Session warning time reached for "
607 MACSTR, hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800608 if (sta->hs20_session_info_url == NULL)
609 return;
610
611 wnm_send_ess_disassoc_imminent(hapd, sta, sta->hs20_session_info_url,
612 sta->hs20_disassoc_timer);
613#endif /* CONFIG_WNM */
614}
615
616
617void ap_sta_session_warning_timeout(struct hostapd_data *hapd,
618 struct sta_info *sta, int warning_time)
619{
620 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
621 eloop_register_timeout(warning_time, 0, ap_handle_session_warning_timer,
622 hapd, sta);
623}
624
625
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700626struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
627{
628 struct sta_info *sta;
629
630 sta = ap_get_sta(hapd, addr);
631 if (sta)
632 return sta;
633
634 wpa_printf(MSG_DEBUG, " New STA");
635 if (hapd->num_sta >= hapd->conf->max_num_sta) {
636 /* FIX: might try to remove some old STAs first? */
637 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
638 hapd->num_sta, hapd->conf->max_num_sta);
639 return NULL;
640 }
641
642 sta = os_zalloc(sizeof(struct sta_info));
643 if (sta == NULL) {
644 wpa_printf(MSG_ERROR, "malloc failed");
645 return NULL;
646 }
647 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800648 if (accounting_sta_get_id(hapd, sta) < 0) {
649 os_free(sta);
650 return NULL;
651 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652
Dmitry Shmidt01904cf2013-12-05 11:08:35 -0800653 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
654 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
655 "for " MACSTR " (%d seconds - ap_max_inactivity)",
656 __func__, MAC2STR(addr),
657 hapd->conf->ap_max_inactivity);
658 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
659 ap_handle_timer, hapd, sta);
660 }
661
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662 /* initialize STA info data */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700663 os_memcpy(sta->addr, addr, ETH_ALEN);
664 sta->next = hapd->sta_list;
665 hapd->sta_list = sta;
666 hapd->num_sta++;
667 ap_sta_hash_add(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 ap_sta_remove_in_other_bss(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800669 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
670 dl_list_init(&sta->ip6addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700671
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700672#ifdef CONFIG_TAXONOMY
673 sta_track_claim_taxonomy_info(hapd->iface, addr,
674 &sta->probe_ie_taxonomy);
675#endif /* CONFIG_TAXONOMY */
676
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700677 return sta;
678}
679
680
681static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
682{
683 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
684
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800685 if (sta->ipaddr)
686 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
687 ap_sta_ip6addr_del(hapd, sta);
688
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800689 wpa_printf(MSG_DEBUG, "%s: Removing STA " MACSTR " from kernel driver",
690 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700691 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
692 sta->flags & WLAN_STA_ASSOC) {
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800693 wpa_printf(MSG_DEBUG, "%s: Could not remove station " MACSTR
694 " from kernel driver",
695 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700696 return -1;
697 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800698 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700699 return 0;
700}
701
702
703static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
704 struct sta_info *sta)
705{
706 struct hostapd_iface *iface = hapd->iface;
707 size_t i;
708
709 for (i = 0; i < iface->num_bss; i++) {
710 struct hostapd_data *bss = iface->bss[i];
711 struct sta_info *sta2;
712 /* bss should always be set during operation, but it may be
713 * NULL during reconfiguration. Assume the STA is not
714 * associated to another BSS in that case to avoid NULL pointer
715 * dereferences. */
716 if (bss == hapd || bss == NULL)
717 continue;
718 sta2 = ap_get_sta(bss, sta->addr);
719 if (!sta2)
720 continue;
721
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800722 wpa_printf(MSG_DEBUG, "%s: disconnect old STA " MACSTR
723 " association from another BSS %s",
724 hapd->conf->iface, MAC2STR(sta2->addr),
725 bss->conf->iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700726 ap_sta_disconnect(bss, sta2, sta2->addr,
727 WLAN_REASON_PREV_AUTH_NOT_VALID);
728 }
729}
730
731
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800732static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
733{
734 struct hostapd_data *hapd = eloop_ctx;
735 struct sta_info *sta = timeout_ctx;
736
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800737 wpa_printf(MSG_DEBUG, "%s: Disassociation callback for STA " MACSTR,
738 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800739 ap_sta_remove(hapd, sta);
740 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
741}
742
743
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700744void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
745 u16 reason)
746{
747 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
748 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800749 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800750 if (hapd->iface->current_mode &&
751 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
752 /* Skip deauthentication in DMG/IEEE 802.11ad */
753 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
754 WLAN_STA_ASSOC_REQ_OK);
755 sta->timeout_next = STA_REMOVE;
756 } else {
757 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
758 sta->timeout_next = STA_DEAUTH;
759 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800760 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700761 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
762 "for " MACSTR " (%d seconds - "
763 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
764 __func__, MAC2STR(sta->addr),
765 AP_MAX_INACTIVITY_AFTER_DISASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700766 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
767 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
768 ap_handle_timer, hapd, sta);
769 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800770 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800772 sta->disassoc_reason = reason;
773 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
774 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
775 eloop_register_timeout(hapd->iface->drv_flags &
776 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
777 ap_sta_disassoc_cb_timeout, hapd, sta);
778}
779
780
781static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
782{
783 struct hostapd_data *hapd = eloop_ctx;
784 struct sta_info *sta = timeout_ctx;
785
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800786 wpa_printf(MSG_DEBUG, "%s: Deauthentication callback for STA " MACSTR,
787 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800788 ap_sta_remove(hapd, sta);
789 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700790}
791
792
793void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
794 u16 reason)
795{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800796 if (hapd->iface->current_mode &&
797 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
798 /* Deauthentication is not used in DMG/IEEE 802.11ad;
799 * disassociate the STA instead. */
800 ap_sta_disassociate(hapd, sta, reason);
801 return;
802 }
803
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
805 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800806 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
807 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800808 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700810 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
811 "for " MACSTR " (%d seconds - "
812 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
813 __func__, MAC2STR(sta->addr),
814 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700815 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
816 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
817 ap_handle_timer, hapd, sta);
818 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800819 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700820
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800821 sta->deauth_reason = reason;
822 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
823 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
824 eloop_register_timeout(hapd->iface->drv_flags &
825 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
826 ap_sta_deauth_cb_timeout, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700827}
828
829
Dmitry Shmidt04949592012-07-19 12:16:46 -0700830#ifdef CONFIG_WPS
831int ap_sta_wps_cancel(struct hostapd_data *hapd,
832 struct sta_info *sta, void *ctx)
833{
834 if (sta && (sta->flags & WLAN_STA_WPS)) {
835 ap_sta_deauthenticate(hapd, sta,
836 WLAN_REASON_PREV_AUTH_NOT_VALID);
837 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
838 __func__, MAC2STR(sta->addr));
839 return 1;
840 }
841
842 return 0;
843}
844#endif /* CONFIG_WPS */
845
846
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800847static int ap_sta_get_free_vlan_id(struct hostapd_data *hapd)
848{
849 struct hostapd_vlan *vlan;
850 int vlan_id = MAX_VLAN_ID + 2;
851
852retry:
853 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
854 if (vlan->vlan_id == vlan_id) {
855 vlan_id++;
856 goto retry;
857 }
858 }
859 return vlan_id;
860}
861
862
863int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta,
864 struct vlan_description *vlan_desc)
865{
866 struct hostapd_vlan *vlan = NULL, *wildcard_vlan = NULL;
867 int old_vlan_id, vlan_id = 0, ret = 0;
868
869 if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED)
870 vlan_desc = NULL;
871
872 /* Check if there is something to do */
873 if (hapd->conf->ssid.per_sta_vif && !sta->vlan_id) {
874 /* This sta is lacking its own vif */
875 } else if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED &&
876 !hapd->conf->ssid.per_sta_vif && sta->vlan_id) {
877 /* sta->vlan_id needs to be reset */
878 } else if (!vlan_compare(vlan_desc, sta->vlan_desc)) {
879 return 0; /* nothing to change */
880 }
881
882 /* Now the real VLAN changed or the STA just needs its own vif */
883 if (hapd->conf->ssid.per_sta_vif) {
884 /* Assign a new vif, always */
885 /* find a free vlan_id sufficiently big */
886 vlan_id = ap_sta_get_free_vlan_id(hapd);
887 /* Get wildcard VLAN */
888 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
889 if (vlan->vlan_id == VLAN_ID_WILDCARD)
890 break;
891 }
892 if (!vlan) {
893 hostapd_logger(hapd, sta->addr,
894 HOSTAPD_MODULE_IEEE80211,
895 HOSTAPD_LEVEL_DEBUG,
896 "per_sta_vif missing wildcard");
897 vlan_id = 0;
898 ret = -1;
899 goto done;
900 }
901 } else if (vlan_desc && vlan_desc->notempty) {
902 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
903 if (!vlan_compare(&vlan->vlan_desc, vlan_desc))
904 break;
905 if (vlan->vlan_id == VLAN_ID_WILDCARD)
906 wildcard_vlan = vlan;
907 }
908 if (vlan) {
909 vlan_id = vlan->vlan_id;
910 } else if (wildcard_vlan) {
911 vlan = wildcard_vlan;
912 vlan_id = vlan_desc->untagged;
913 if (vlan_desc->tagged[0]) {
914 /* Tagged VLAN configuration */
915 vlan_id = ap_sta_get_free_vlan_id(hapd);
916 }
917 } else {
918 hostapd_logger(hapd, sta->addr,
919 HOSTAPD_MODULE_IEEE80211,
920 HOSTAPD_LEVEL_DEBUG,
921 "missing vlan and wildcard for vlan=%d%s",
922 vlan_desc->untagged,
923 vlan_desc->tagged[0] ? "+" : "");
924 vlan_id = 0;
925 ret = -1;
926 goto done;
927 }
928 }
929
930 if (vlan && vlan->vlan_id == VLAN_ID_WILDCARD) {
931 vlan = vlan_add_dynamic(hapd, vlan, vlan_id, vlan_desc);
932 if (vlan == NULL) {
933 hostapd_logger(hapd, sta->addr,
934 HOSTAPD_MODULE_IEEE80211,
935 HOSTAPD_LEVEL_DEBUG,
936 "could not add dynamic VLAN interface for vlan=%d%s",
937 vlan_desc ? vlan_desc->untagged : -1,
938 (vlan_desc && vlan_desc->tagged[0]) ?
939 "+" : "");
940 vlan_id = 0;
941 ret = -1;
942 goto done;
943 }
944
945 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
946 HOSTAPD_LEVEL_DEBUG,
947 "added new dynamic VLAN interface '%s'",
948 vlan->ifname);
949 } else if (vlan && vlan->dynamic_vlan > 0) {
950 vlan->dynamic_vlan++;
951 hostapd_logger(hapd, sta->addr,
952 HOSTAPD_MODULE_IEEE80211,
953 HOSTAPD_LEVEL_DEBUG,
954 "updated existing dynamic VLAN interface '%s'",
955 vlan->ifname);
956 }
957done:
958 old_vlan_id = sta->vlan_id;
959 sta->vlan_id = vlan_id;
960 sta->vlan_desc = vlan ? &vlan->vlan_desc : NULL;
961
962 if (vlan_id != old_vlan_id && old_vlan_id)
963 vlan_remove_dynamic(hapd, old_vlan_id);
964
965 return ret;
966}
967
968
Dmitry Shmidt83474442015-04-15 13:47:09 -0700969int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700970{
971#ifndef CONFIG_NO_VLAN
972 const char *iface;
973 struct hostapd_vlan *vlan = NULL;
974 int ret;
Dmitry Shmidt83474442015-04-15 13:47:09 -0700975 int old_vlanid = sta->vlan_id_bound;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700976
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700977 iface = hapd->conf->iface;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700978 if (hapd->conf->ssid.vlan[0])
979 iface = hapd->conf->ssid.vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800981 if (sta->vlan_id > 0) {
982 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700983 if (vlan->vlan_id == sta->vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700984 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700985 }
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700986 if (vlan)
987 iface = vlan->ifname;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988 }
989
Dmitry Shmidt83474442015-04-15 13:47:09 -0700990 /*
991 * Do not increment ref counters if the VLAN ID remains same, but do
992 * not skip hostapd_drv_set_sta_vlan() as hostapd_drv_sta_remove() might
993 * have been called before.
994 */
995 if (sta->vlan_id == old_vlanid)
996 goto skip_counting;
997
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700998 if (sta->vlan_id > 0 && vlan == NULL) {
999 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1000 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
1001 "binding station to (vlan_id=%d)",
1002 sta->vlan_id);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001003 ret = -1;
1004 goto done;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001005 } else if (vlan && vlan->dynamic_vlan > 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001006 vlan->dynamic_vlan++;
1007 hostapd_logger(hapd, sta->addr,
1008 HOSTAPD_MODULE_IEEE80211,
1009 HOSTAPD_LEVEL_DEBUG,
1010 "updated existing dynamic VLAN interface '%s'",
1011 iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001012 }
1013
Dmitry Shmidt83474442015-04-15 13:47:09 -07001014 /* ref counters have been increased, so mark the station */
1015 sta->vlan_id_bound = sta->vlan_id;
1016
1017skip_counting:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001018 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1019 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
1020 "'%s'", iface);
1021
1022 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
1023 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
1024
1025 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
1026 if (ret < 0) {
1027 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1028 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
1029 "entry to vlan_id=%d", sta->vlan_id);
1030 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001031
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001032 /* During 1x reauth, if the vlan id changes, then remove the old id. */
Dmitry Shmidt83474442015-04-15 13:47:09 -07001033 if (old_vlanid > 0 && old_vlanid != sta->vlan_id)
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001034 vlan_remove_dynamic(hapd, old_vlanid);
Dmitry Shmidt83474442015-04-15 13:47:09 -07001035done:
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001036
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037 return ret;
1038#else /* CONFIG_NO_VLAN */
1039 return 0;
1040#endif /* CONFIG_NO_VLAN */
1041}
1042
1043
1044#ifdef CONFIG_IEEE80211W
1045
1046int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
1047{
1048 u32 tu;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001049 struct os_reltime now, passed;
1050 os_get_reltime(&now);
1051 os_reltime_sub(&now, &sta->sa_query_start, &passed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001052 tu = (passed.sec * 1000000 + passed.usec) / 1024;
1053 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
1054 hostapd_logger(hapd, sta->addr,
1055 HOSTAPD_MODULE_IEEE80211,
1056 HOSTAPD_LEVEL_DEBUG,
1057 "association SA Query timed out");
1058 sta->sa_query_timed_out = 1;
1059 os_free(sta->sa_query_trans_id);
1060 sta->sa_query_trans_id = NULL;
1061 sta->sa_query_count = 0;
1062 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1063 return 1;
1064 }
1065
1066 return 0;
1067}
1068
1069
1070static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
1071{
1072 struct hostapd_data *hapd = eloop_ctx;
1073 struct sta_info *sta = timeout_ctx;
1074 unsigned int timeout, sec, usec;
1075 u8 *trans_id, *nbuf;
1076
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001077 wpa_printf(MSG_DEBUG, "%s: SA Query timer for STA " MACSTR
1078 " (count=%d)",
1079 hapd->conf->iface, MAC2STR(sta->addr), sta->sa_query_count);
1080
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001081 if (sta->sa_query_count > 0 &&
1082 ap_check_sa_query_timeout(hapd, sta))
1083 return;
1084
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001085 nbuf = os_realloc_array(sta->sa_query_trans_id,
1086 sta->sa_query_count + 1,
1087 WLAN_SA_QUERY_TR_ID_LEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088 if (nbuf == NULL)
1089 return;
1090 if (sta->sa_query_count == 0) {
1091 /* Starting a new SA Query procedure */
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001092 os_get_reltime(&sta->sa_query_start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001093 }
1094 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
1095 sta->sa_query_trans_id = nbuf;
1096 sta->sa_query_count++;
1097
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001098 if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) {
1099 /*
1100 * We don't really care which ID is used here, so simply
1101 * hardcode this if the mostly theoretical os_get_random()
1102 * failure happens.
1103 */
1104 trans_id[0] = 0x12;
1105 trans_id[1] = 0x34;
1106 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001107
1108 timeout = hapd->conf->assoc_sa_query_retry_timeout;
1109 sec = ((timeout / 1000) * 1024) / 1000;
1110 usec = (timeout % 1000) * 1024;
1111 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
1112
1113 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1114 HOSTAPD_LEVEL_DEBUG,
1115 "association SA Query attempt %d", sta->sa_query_count);
1116
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001117 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001118}
1119
1120
1121void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1122{
1123 ap_sa_query_timer(hapd, sta);
1124}
1125
1126
1127void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1128{
1129 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1130 os_free(sta->sa_query_trans_id);
1131 sta->sa_query_trans_id = NULL;
1132 sta->sa_query_count = 0;
1133}
1134
1135#endif /* CONFIG_IEEE80211W */
1136
1137
1138void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
1139 int authorized)
1140{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001141 const u8 *dev_addr = NULL;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001142 char buf[100];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001143#ifdef CONFIG_P2P
1144 u8 addr[ETH_ALEN];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001145 u8 ip_addr_buf[4];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001146#endif /* CONFIG_P2P */
1147
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001148 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
1149 return;
1150
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001151 if (authorized)
1152 sta->flags |= WLAN_STA_AUTHORIZED;
1153 else
1154 sta->flags &= ~WLAN_STA_AUTHORIZED;
1155
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001156#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001157 if (hapd->p2p_group == NULL) {
1158 if (sta->p2p_ie != NULL &&
1159 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
1160 dev_addr = addr;
1161 } else
1162 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001163
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001164 if (dev_addr)
1165 os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
1166 MAC2STR(sta->addr), MAC2STR(dev_addr));
1167 else
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001168#endif /* CONFIG_P2P */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001169 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
1170
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001171 if (hapd->sta_authorized_cb)
1172 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
1173 sta->addr, authorized, dev_addr);
1174
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001175 if (authorized) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001176 char ip_addr[100];
1177 ip_addr[0] = '\0';
1178#ifdef CONFIG_P2P
1179 if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) {
1180 os_snprintf(ip_addr, sizeof(ip_addr),
1181 " ip_addr=%u.%u.%u.%u",
1182 ip_addr_buf[0], ip_addr_buf[1],
1183 ip_addr_buf[2], ip_addr_buf[3]);
1184 }
1185#endif /* CONFIG_P2P */
1186
1187 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s",
1188 buf, ip_addr);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001189
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001190 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001191 hapd->msg_ctx_parent != hapd->msg_ctx)
1192 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001193 AP_STA_CONNECTED "%s%s",
1194 buf, ip_addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001195 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001196 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
1197
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001198 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001199 hapd->msg_ctx_parent != hapd->msg_ctx)
1200 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
1201 AP_STA_DISCONNECTED "%s", buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001202 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001203
1204#ifdef CONFIG_FST
1205 if (hapd->iface->fst) {
1206 if (authorized)
1207 fst_notify_peer_connected(hapd->iface->fst, sta->addr);
1208 else
1209 fst_notify_peer_disconnected(hapd->iface->fst,
1210 sta->addr);
1211 }
1212#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001213}
1214
1215
1216void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
1217 const u8 *addr, u16 reason)
1218{
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001219 if (sta)
1220 wpa_printf(MSG_DEBUG, "%s: %s STA " MACSTR " reason=%u",
1221 hapd->conf->iface, __func__, MAC2STR(sta->addr),
1222 reason);
1223 else if (addr)
1224 wpa_printf(MSG_DEBUG, "%s: %s addr " MACSTR " reason=%u",
1225 hapd->conf->iface, __func__, MAC2STR(addr),
1226 reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001227
1228 if (sta == NULL && addr)
1229 sta = ap_get_sta(hapd, addr);
1230
1231 if (addr)
1232 hostapd_drv_sta_deauth(hapd, addr, reason);
1233
1234 if (sta == NULL)
1235 return;
1236 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001237 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1238 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001239 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001240 wpa_printf(MSG_DEBUG, "%s: %s: reschedule ap_handle_timer timeout "
Dmitry Shmidt04949592012-07-19 12:16:46 -07001241 "for " MACSTR " (%d seconds - "
1242 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001243 hapd->conf->iface, __func__, MAC2STR(sta->addr),
Dmitry Shmidt04949592012-07-19 12:16:46 -07001244 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001246 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
1247 ap_handle_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001248 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001249
Dmitry Shmidt29333592017-01-09 12:27:11 -08001250 if (hapd->iface->current_mode &&
1251 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
1252 /* Deauthentication is not used in DMG/IEEE 802.11ad;
1253 * disassociate the STA instead. */
1254 sta->disassoc_reason = reason;
1255 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
1256 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1257 eloop_register_timeout(hapd->iface->drv_flags &
1258 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ?
1259 2 : 0, 0, ap_sta_disassoc_cb_timeout,
1260 hapd, sta);
1261 return;
1262 }
1263
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001264 sta->deauth_reason = reason;
1265 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
1266 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1267 eloop_register_timeout(hapd->iface->drv_flags &
1268 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
1269 ap_sta_deauth_cb_timeout, hapd, sta);
1270}
1271
1272
1273void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
1274{
1275 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
1276 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
1277 return;
1278 }
1279 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
1280 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1281 ap_sta_deauth_cb_timeout(hapd, sta);
1282}
1283
1284
1285void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
1286{
1287 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
1288 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
1289 return;
1290 }
1291 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
1292 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1293 ap_sta_disassoc_cb_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001294}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001295
1296
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001297void ap_sta_clear_disconnect_timeouts(struct hostapd_data *hapd,
1298 struct sta_info *sta)
1299{
1300 if (eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta) > 0)
1301 wpa_printf(MSG_DEBUG,
1302 "%s: Removed ap_sta_deauth_cb_timeout timeout for "
1303 MACSTR,
1304 hapd->conf->iface, MAC2STR(sta->addr));
1305 if (eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta) > 0)
1306 wpa_printf(MSG_DEBUG,
1307 "%s: Removed ap_sta_disassoc_cb_timeout timeout for "
1308 MACSTR,
1309 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt29333592017-01-09 12:27:11 -08001310 if (eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta) > 0)
1311 {
1312 wpa_printf(MSG_DEBUG,
1313 "%s: Removed ap_sta_delayed_1x_auth_fail_cb timeout for "
1314 MACSTR,
1315 hapd->conf->iface, MAC2STR(sta->addr));
1316 if (sta->flags & WLAN_STA_WPS)
1317 hostapd_wps_eap_completed(hapd);
1318 }
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001319}
1320
1321
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001322int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen)
1323{
1324 int res;
1325
1326 buf[0] = '\0';
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001327 res = os_snprintf(buf, buflen, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001328 (flags & WLAN_STA_AUTH ? "[AUTH]" : ""),
1329 (flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""),
1330 (flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : ""),
1331 (flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
1332 ""),
1333 (flags & WLAN_STA_SHORT_PREAMBLE ?
1334 "[SHORT_PREAMBLE]" : ""),
1335 (flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
1336 (flags & WLAN_STA_WMM ? "[WMM]" : ""),
1337 (flags & WLAN_STA_MFP ? "[MFP]" : ""),
1338 (flags & WLAN_STA_WPS ? "[WPS]" : ""),
1339 (flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""),
1340 (flags & WLAN_STA_WDS ? "[WDS]" : ""),
1341 (flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
1342 (flags & WLAN_STA_WPS2 ? "[WPS2]" : ""),
1343 (flags & WLAN_STA_GAS ? "[GAS]" : ""),
1344 (flags & WLAN_STA_VHT ? "[VHT]" : ""),
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001345 (flags & WLAN_STA_VENDOR_VHT ? "[VENDOR_VHT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001346 (flags & WLAN_STA_WNM_SLEEP_MODE ?
1347 "[WNM_SLEEP_MODE]" : ""));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001348 if (os_snprintf_error(buflen, res))
1349 res = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001350
1351 return res;
1352}
Dmitry Shmidt29333592017-01-09 12:27:11 -08001353
1354
1355static void ap_sta_delayed_1x_auth_fail_cb(void *eloop_ctx, void *timeout_ctx)
1356{
1357 struct hostapd_data *hapd = eloop_ctx;
1358 struct sta_info *sta = timeout_ctx;
1359
1360 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1361 "IEEE 802.1X: Scheduled disconnection of " MACSTR
1362 " after EAP-Failure", MAC2STR(sta->addr));
1363
1364 ap_sta_disconnect(hapd, sta, sta->addr,
1365 WLAN_REASON_IEEE_802_1X_AUTH_FAILED);
1366 if (sta->flags & WLAN_STA_WPS)
1367 hostapd_wps_eap_completed(hapd);
1368}
1369
1370
1371void ap_sta_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1372 struct sta_info *sta)
1373{
1374 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1375 "IEEE 802.1X: Force disconnection of " MACSTR
1376 " after EAP-Failure in 10 ms", MAC2STR(sta->addr));
1377
1378 /*
1379 * Add a small sleep to increase likelihood of previously requested
1380 * EAP-Failure TX getting out before this should the driver reorder
1381 * operations.
1382 */
1383 eloop_cancel_timeout(ap_sta_delayed_1x_auth_fail_cb, hapd, sta);
1384 eloop_register_timeout(0, 10000, ap_sta_delayed_1x_auth_fail_cb,
1385 hapd, sta);
1386}
1387
1388
1389int ap_sta_pending_delayed_1x_auth_fail_disconnect(struct hostapd_data *hapd,
1390 struct sta_info *sta)
1391{
1392 return eloop_is_timeout_registered(ap_sta_delayed_1x_auth_fail_cb,
1393 hapd, sta);
1394}