blob: 6704c09c04eb4605e2772612c3a03600c2a041ce [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Station table
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003 * Copyright (c) 2002-2013, 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"
18#include "drivers/driver.h"
19#include "p2p/p2p.h"
20#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 Shmidt8d520ff2011-05-09 14:06:53 -070034#include "sta_info.h"
35
36static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
37 struct sta_info *sta);
38static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080039static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
40static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041#ifdef CONFIG_IEEE80211W
42static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
43#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080044static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070045
46int ap_for_each_sta(struct hostapd_data *hapd,
47 int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
48 void *ctx),
49 void *ctx)
50{
51 struct sta_info *sta;
52
53 for (sta = hapd->sta_list; sta; sta = sta->next) {
54 if (cb(hapd, sta, ctx))
55 return 1;
56 }
57
58 return 0;
59}
60
61
62struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
63{
64 struct sta_info *s;
65
66 s = hapd->sta_hash[STA_HASH(sta)];
67 while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
68 s = s->hnext;
69 return s;
70}
71
72
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070073#ifdef CONFIG_P2P
74struct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr)
75{
76 struct sta_info *sta;
77
78 for (sta = hapd->sta_list; sta; sta = sta->next) {
79 const u8 *p2p_dev_addr;
80
81 if (sta->p2p_ie == NULL)
82 continue;
83
84 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
85 if (p2p_dev_addr == NULL)
86 continue;
87
88 if (os_memcmp(p2p_dev_addr, addr, ETH_ALEN) == 0)
89 return sta;
90 }
91
92 return NULL;
93}
94#endif /* CONFIG_P2P */
95
96
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070097static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
98{
99 struct sta_info *tmp;
100
101 if (hapd->sta_list == sta) {
102 hapd->sta_list = sta->next;
103 return;
104 }
105
106 tmp = hapd->sta_list;
107 while (tmp != NULL && tmp->next != sta)
108 tmp = tmp->next;
109 if (tmp == NULL) {
110 wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
111 "list.", MAC2STR(sta->addr));
112 } else
113 tmp->next = sta->next;
114}
115
116
117void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
118{
119 sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
120 hapd->sta_hash[STA_HASH(sta->addr)] = sta;
121}
122
123
124static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
125{
126 struct sta_info *s;
127
128 s = hapd->sta_hash[STA_HASH(sta->addr)];
129 if (s == NULL) return;
130 if (os_memcmp(s->addr, sta->addr, 6) == 0) {
131 hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
132 return;
133 }
134
135 while (s->hnext != NULL &&
136 os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
137 s = s->hnext;
138 if (s->hnext != NULL)
139 s->hnext = s->hnext->hnext;
140 else
141 wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
142 " from hash table", MAC2STR(sta->addr));
143}
144
145
146void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
147{
148 int set_beacon = 0;
149
150 accounting_sta_stop(hapd, sta);
151
152 /* just in case */
153 ap_sta_set_authorized(hapd, sta, 0);
154
155 if (sta->flags & WLAN_STA_WDS)
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700156 hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700157
158 if (!(sta->flags & WLAN_STA_PREAUTH))
159 hostapd_drv_sta_remove(hapd, sta->addr);
160
161 ap_sta_hash_del(hapd, sta);
162 ap_sta_list_del(hapd, sta);
163
164 if (sta->aid > 0)
165 hapd->sta_aid[(sta->aid - 1) / 32] &=
166 ~BIT((sta->aid - 1) % 32);
167
168 hapd->num_sta--;
169 if (sta->nonerp_set) {
170 sta->nonerp_set = 0;
171 hapd->iface->num_sta_non_erp--;
172 if (hapd->iface->num_sta_non_erp == 0)
173 set_beacon++;
174 }
175
176 if (sta->no_short_slot_time_set) {
177 sta->no_short_slot_time_set = 0;
178 hapd->iface->num_sta_no_short_slot_time--;
179 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
180 && hapd->iface->num_sta_no_short_slot_time == 0)
181 set_beacon++;
182 }
183
184 if (sta->no_short_preamble_set) {
185 sta->no_short_preamble_set = 0;
186 hapd->iface->num_sta_no_short_preamble--;
187 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
188 && hapd->iface->num_sta_no_short_preamble == 0)
189 set_beacon++;
190 }
191
192 if (sta->no_ht_gf_set) {
193 sta->no_ht_gf_set = 0;
194 hapd->iface->num_sta_ht_no_gf--;
195 }
196
197 if (sta->no_ht_set) {
198 sta->no_ht_set = 0;
199 hapd->iface->num_sta_no_ht--;
200 }
201
202 if (sta->ht_20mhz_set) {
203 sta->ht_20mhz_set = 0;
204 hapd->iface->num_sta_ht_20mhz--;
205 }
206
207#ifdef CONFIG_P2P
208 if (sta->no_p2p_set) {
209 sta->no_p2p_set = 0;
210 hapd->num_sta_no_p2p--;
211 if (hapd->num_sta_no_p2p == 0)
212 hostapd_p2p_non_p2p_sta_disconnected(hapd);
213 }
214#endif /* CONFIG_P2P */
215
216#if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
217 if (hostapd_ht_operation_update(hapd->iface) > 0)
218 set_beacon++;
219#endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
220
221 if (set_beacon)
222 ieee802_11_set_beacons(hapd->iface);
223
Dmitry Shmidt04949592012-07-19 12:16:46 -0700224 wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
225 __func__, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
227 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800228 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
229 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700230
231 ieee802_1x_free_station(sta);
232 wpa_auth_sta_deinit(sta->wpa_sm);
233 rsn_preauth_free_station(hapd, sta);
234#ifndef CONFIG_NO_RADIUS
235 radius_client_flush_auth(hapd->radius, sta->addr);
236#endif /* CONFIG_NO_RADIUS */
237
238 os_free(sta->last_assoc_req);
239 os_free(sta->challenge);
240
241#ifdef CONFIG_IEEE80211W
242 os_free(sta->sa_query_trans_id);
243 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
244#endif /* CONFIG_IEEE80211W */
245
246#ifdef CONFIG_P2P
247 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
248#endif /* CONFIG_P2P */
249
Dmitry Shmidt04949592012-07-19 12:16:46 -0700250#ifdef CONFIG_INTERWORKING
251 if (sta->gas_dialog) {
252 int i;
253 for (i = 0; i < GAS_DIALOG_MAX; i++)
254 gas_serv_dialog_clear(&sta->gas_dialog[i]);
255 os_free(sta->gas_dialog);
256 }
257#endif /* CONFIG_INTERWORKING */
258
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700259 wpabuf_free(sta->wps_ie);
260 wpabuf_free(sta->p2p_ie);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800261 wpabuf_free(sta->hs20_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700262
263 os_free(sta->ht_capabilities);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800264 hostapd_free_psk_list(sta->psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700265 os_free(sta->identity);
266 os_free(sta->radius_cui);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700267
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800268#ifdef CONFIG_SAE
269 sae_clear_data(sta->sae);
270 os_free(sta->sae);
271#endif /* CONFIG_SAE */
272
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700273 os_free(sta);
274}
275
276
277void hostapd_free_stas(struct hostapd_data *hapd)
278{
279 struct sta_info *sta, *prev;
280
281 sta = hapd->sta_list;
282
283 while (sta) {
284 prev = sta;
285 if (sta->flags & WLAN_STA_AUTH) {
286 mlme_deauthenticate_indication(
287 hapd, sta, WLAN_REASON_UNSPECIFIED);
288 }
289 sta = sta->next;
290 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
291 MAC2STR(prev->addr));
292 ap_free_sta(hapd, prev);
293 }
294}
295
296
297/**
298 * ap_handle_timer - Per STA timer handler
299 * @eloop_ctx: struct hostapd_data *
300 * @timeout_ctx: struct sta_info *
301 *
302 * This function is called to check station activity and to remove inactive
303 * stations.
304 */
305void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
306{
307 struct hostapd_data *hapd = eloop_ctx;
308 struct sta_info *sta = timeout_ctx;
309 unsigned long next_time = 0;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700310 int reason;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700311
Dmitry Shmidt04949592012-07-19 12:16:46 -0700312 wpa_printf(MSG_DEBUG, "%s: " MACSTR " flags=0x%x timeout_next=%d",
313 __func__, MAC2STR(sta->addr), sta->flags,
314 sta->timeout_next);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 if (sta->timeout_next == STA_REMOVE) {
316 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
317 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
318 "local deauth request");
319 ap_free_sta(hapd, sta);
320 return;
321 }
322
323 if ((sta->flags & WLAN_STA_ASSOC) &&
324 (sta->timeout_next == STA_NULLFUNC ||
325 sta->timeout_next == STA_DISASSOC)) {
326 int inactive_sec;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700327 /*
328 * Add random value to timeout so that we don't end up bouncing
329 * all stations at the same time if we have lots of associated
330 * stations that are idle (but keep re-associating).
331 */
332 int fuzz = os_random() % 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
334 if (inactive_sec == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800335 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
336 "Check inactivity: Could not "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800337 "get station info from kernel driver for "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800339 /*
340 * The driver may not support this functionality.
341 * Anyway, try again after the next inactivity timeout,
342 * but do not disconnect the station now.
343 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700344 next_time = hapd->conf->ap_max_inactivity + fuzz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700345 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
346 sta->flags & WLAN_STA_ASSOC) {
347 /* station activity detected; reset timeout state */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800348 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
349 "Station " MACSTR " has been active %is ago",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700350 MAC2STR(sta->addr), inactive_sec);
351 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700352 next_time = hapd->conf->ap_max_inactivity + fuzz -
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700353 inactive_sec;
354 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800355 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
356 "Station " MACSTR " has been "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700357 "inactive too long: %d sec, max allowed: %d",
358 MAC2STR(sta->addr), inactive_sec,
359 hapd->conf->ap_max_inactivity);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800360
361 if (hapd->conf->skip_inactivity_poll)
362 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700363 }
364 }
365
366 if ((sta->flags & WLAN_STA_ASSOC) &&
367 sta->timeout_next == STA_DISASSOC &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800368 !(sta->flags & WLAN_STA_PENDING_POLL) &&
369 !hapd->conf->skip_inactivity_poll) {
370 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
371 " has ACKed data poll", MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700372 /* data nullfunc frame poll did not produce TX errors; assume
373 * station ACKed it */
374 sta->timeout_next = STA_NULLFUNC;
375 next_time = hapd->conf->ap_max_inactivity;
376 }
377
378 if (next_time) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700379 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
380 "for " MACSTR " (%lu seconds)",
381 __func__, MAC2STR(sta->addr), next_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700382 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
383 sta);
384 return;
385 }
386
387 if (sta->timeout_next == STA_NULLFUNC &&
388 (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800389 wpa_printf(MSG_DEBUG, " Polling STA");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700390 sta->flags |= WLAN_STA_PENDING_POLL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800391 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
392 sta->flags & WLAN_STA_WMM);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700393 } else if (sta->timeout_next != STA_REMOVE) {
394 int deauth = sta->timeout_next == STA_DEAUTH;
395
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800396 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
397 "Timeout, sending %s info to STA " MACSTR,
398 deauth ? "deauthentication" : "disassociation",
399 MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700400
401 if (deauth) {
402 hostapd_drv_sta_deauth(
403 hapd, sta->addr,
404 WLAN_REASON_PREV_AUTH_NOT_VALID);
405 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700406 reason = (sta->timeout_next == STA_DISASSOC) ?
407 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
408 WLAN_REASON_PREV_AUTH_NOT_VALID;
409
410 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411 }
412 }
413
414 switch (sta->timeout_next) {
415 case STA_NULLFUNC:
416 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700417 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
418 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
419 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700420 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
421 hapd, sta);
422 break;
423 case STA_DISASSOC:
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700424 case STA_DISASSOC_FROM_CLI:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800425 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700426 sta->flags &= ~WLAN_STA_ASSOC;
427 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
428 if (!sta->acct_terminate_cause)
429 sta->acct_terminate_cause =
430 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
431 accounting_sta_stop(hapd, sta);
432 ieee802_1x_free_station(sta);
433 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
434 HOSTAPD_LEVEL_INFO, "disassociated due to "
435 "inactivity");
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700436 reason = (sta->timeout_next == STA_DISASSOC) ?
437 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
438 WLAN_REASON_PREV_AUTH_NOT_VALID;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700439 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700440 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
441 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
442 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700443 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
444 hapd, sta);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700445 mlme_disassociate_indication(hapd, sta, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446 break;
447 case STA_DEAUTH:
448 case STA_REMOVE:
449 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
450 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800451 "inactivity (timer DEAUTH/REMOVE)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700452 if (!sta->acct_terminate_cause)
453 sta->acct_terminate_cause =
454 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
455 mlme_deauthenticate_indication(
456 hapd, sta,
457 WLAN_REASON_PREV_AUTH_NOT_VALID);
458 ap_free_sta(hapd, sta);
459 break;
460 }
461}
462
463
464static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
465{
466 struct hostapd_data *hapd = eloop_ctx;
467 struct sta_info *sta = timeout_ctx;
468 u8 addr[ETH_ALEN];
469
Dmitry Shmidt04949592012-07-19 12:16:46 -0700470 if (!(sta->flags & WLAN_STA_AUTH)) {
471 if (sta->flags & WLAN_STA_GAS) {
472 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
473 "entry " MACSTR, MAC2STR(sta->addr));
474 ap_free_sta(hapd, sta);
475 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700476 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700477 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700478
479 mlme_deauthenticate_indication(hapd, sta,
480 WLAN_REASON_PREV_AUTH_NOT_VALID);
481 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
482 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
483 "session timeout");
484 sta->acct_terminate_cause =
485 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
486 os_memcpy(addr, sta->addr, ETH_ALEN);
487 ap_free_sta(hapd, sta);
488 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
489}
490
491
492void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
493 u32 session_timeout)
494{
495 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
496 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
497 "seconds", session_timeout);
498 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
499 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
500 hapd, sta);
501}
502
503
504void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
505{
506 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
507}
508
509
510struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
511{
512 struct sta_info *sta;
513
514 sta = ap_get_sta(hapd, addr);
515 if (sta)
516 return sta;
517
518 wpa_printf(MSG_DEBUG, " New STA");
519 if (hapd->num_sta >= hapd->conf->max_num_sta) {
520 /* FIX: might try to remove some old STAs first? */
521 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
522 hapd->num_sta, hapd->conf->max_num_sta);
523 return NULL;
524 }
525
526 sta = os_zalloc(sizeof(struct sta_info));
527 if (sta == NULL) {
528 wpa_printf(MSG_ERROR, "malloc failed");
529 return NULL;
530 }
531 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800532 accounting_sta_get_id(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700533
534 /* initialize STA info data */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700535 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
536 "for " MACSTR " (%d seconds - ap_max_inactivity)",
537 __func__, MAC2STR(addr),
538 hapd->conf->ap_max_inactivity);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700539 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
540 ap_handle_timer, hapd, sta);
541 os_memcpy(sta->addr, addr, ETH_ALEN);
542 sta->next = hapd->sta_list;
543 hapd->sta_list = sta;
544 hapd->num_sta++;
545 ap_sta_hash_add(hapd, sta);
546 sta->ssid = &hapd->conf->ssid;
547 ap_sta_remove_in_other_bss(hapd, sta);
548
549 return sta;
550}
551
552
553static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
554{
555 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
556
557 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
558 MAC2STR(sta->addr));
559 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
560 sta->flags & WLAN_STA_ASSOC) {
561 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
562 " from kernel driver.", MAC2STR(sta->addr));
563 return -1;
564 }
565 return 0;
566}
567
568
569static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
570 struct sta_info *sta)
571{
572 struct hostapd_iface *iface = hapd->iface;
573 size_t i;
574
575 for (i = 0; i < iface->num_bss; i++) {
576 struct hostapd_data *bss = iface->bss[i];
577 struct sta_info *sta2;
578 /* bss should always be set during operation, but it may be
579 * NULL during reconfiguration. Assume the STA is not
580 * associated to another BSS in that case to avoid NULL pointer
581 * dereferences. */
582 if (bss == hapd || bss == NULL)
583 continue;
584 sta2 = ap_get_sta(bss, sta->addr);
585 if (!sta2)
586 continue;
587
588 ap_sta_disconnect(bss, sta2, sta2->addr,
589 WLAN_REASON_PREV_AUTH_NOT_VALID);
590 }
591}
592
593
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800594static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
595{
596 struct hostapd_data *hapd = eloop_ctx;
597 struct sta_info *sta = timeout_ctx;
598
599 ap_sta_remove(hapd, sta);
600 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
601}
602
603
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700604void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
605 u16 reason)
606{
607 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
608 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt700a1372013-03-15 14:14:44 -0700609 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800610 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700611 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700612 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
613 "for " MACSTR " (%d seconds - "
614 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
615 __func__, MAC2STR(sta->addr),
616 AP_MAX_INACTIVITY_AFTER_DISASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700617 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
618 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
619 ap_handle_timer, hapd, sta);
620 accounting_sta_stop(hapd, sta);
621 ieee802_1x_free_station(sta);
622
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800623 sta->disassoc_reason = reason;
624 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
625 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
626 eloop_register_timeout(hapd->iface->drv_flags &
627 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
628 ap_sta_disassoc_cb_timeout, hapd, sta);
629}
630
631
632static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
633{
634 struct hostapd_data *hapd = eloop_ctx;
635 struct sta_info *sta = timeout_ctx;
636
637 ap_sta_remove(hapd, sta);
638 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639}
640
641
642void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
643 u16 reason)
644{
645 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
646 hapd->conf->iface, MAC2STR(sta->addr));
647 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800648 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700649 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700650 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
651 "for " MACSTR " (%d seconds - "
652 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
653 __func__, MAC2STR(sta->addr),
654 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700655 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
656 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
657 ap_handle_timer, hapd, sta);
658 accounting_sta_stop(hapd, sta);
659 ieee802_1x_free_station(sta);
660
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800661 sta->deauth_reason = reason;
662 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
663 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
664 eloop_register_timeout(hapd->iface->drv_flags &
665 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
666 ap_sta_deauth_cb_timeout, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700667}
668
669
Dmitry Shmidt04949592012-07-19 12:16:46 -0700670#ifdef CONFIG_WPS
671int ap_sta_wps_cancel(struct hostapd_data *hapd,
672 struct sta_info *sta, void *ctx)
673{
674 if (sta && (sta->flags & WLAN_STA_WPS)) {
675 ap_sta_deauthenticate(hapd, sta,
676 WLAN_REASON_PREV_AUTH_NOT_VALID);
677 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
678 __func__, MAC2STR(sta->addr));
679 return 1;
680 }
681
682 return 0;
683}
684#endif /* CONFIG_WPS */
685
686
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700687int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
688 int old_vlanid)
689{
690#ifndef CONFIG_NO_VLAN
691 const char *iface;
692 struct hostapd_vlan *vlan = NULL;
693 int ret;
694
695 /*
696 * Do not proceed furthur if the vlan id remains same. We do not want
697 * duplicate dynamic vlan entries.
698 */
699 if (sta->vlan_id == old_vlanid)
700 return 0;
701
702 /*
703 * During 1x reauth, if the vlan id changes, then remove the old id and
704 * proceed furthur to add the new one.
705 */
706 if (old_vlanid > 0)
707 vlan_remove_dynamic(hapd, old_vlanid);
708
709 iface = hapd->conf->iface;
710 if (sta->ssid->vlan[0])
711 iface = sta->ssid->vlan;
712
713 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
714 sta->vlan_id = 0;
715 else if (sta->vlan_id > 0) {
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700716 struct hostapd_vlan *wildcard_vlan = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717 vlan = hapd->conf->vlan;
718 while (vlan) {
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700719 if (vlan->vlan_id == sta->vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700720 break;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700721 if (vlan->vlan_id == VLAN_ID_WILDCARD)
722 wildcard_vlan = vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700723 vlan = vlan->next;
724 }
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700725 if (!vlan)
726 vlan = wildcard_vlan;
727 if (vlan)
728 iface = vlan->ifname;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729 }
730
731 if (sta->vlan_id > 0 && vlan == NULL) {
732 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
733 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
734 "binding station to (vlan_id=%d)",
735 sta->vlan_id);
736 return -1;
737 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
738 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
739 if (vlan == NULL) {
740 hostapd_logger(hapd, sta->addr,
741 HOSTAPD_MODULE_IEEE80211,
742 HOSTAPD_LEVEL_DEBUG, "could not add "
743 "dynamic VLAN interface for vlan_id=%d",
744 sta->vlan_id);
745 return -1;
746 }
747
748 iface = vlan->ifname;
749 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
750 hostapd_logger(hapd, sta->addr,
751 HOSTAPD_MODULE_IEEE80211,
752 HOSTAPD_LEVEL_DEBUG, "could not "
753 "configure encryption for dynamic VLAN "
754 "interface for vlan_id=%d",
755 sta->vlan_id);
756 }
757
758 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
759 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
760 "interface '%s'", iface);
761 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
762 if (sta->vlan_id > 0) {
763 vlan->dynamic_vlan++;
764 hostapd_logger(hapd, sta->addr,
765 HOSTAPD_MODULE_IEEE80211,
766 HOSTAPD_LEVEL_DEBUG, "updated existing "
767 "dynamic VLAN interface '%s'", iface);
768 }
769
770 /*
771 * Update encryption configuration for statically generated
772 * VLAN interface. This is only used for static WEP
773 * configuration for the case where hostapd did not yet know
774 * which keys are to be used when the interface was added.
775 */
776 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
777 hostapd_logger(hapd, sta->addr,
778 HOSTAPD_MODULE_IEEE80211,
779 HOSTAPD_LEVEL_DEBUG, "could not "
780 "configure encryption for VLAN "
781 "interface for vlan_id=%d",
782 sta->vlan_id);
783 }
784 }
785
786 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
787 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
788 "'%s'", iface);
789
790 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
791 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
792
793 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
794 if (ret < 0) {
795 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
796 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
797 "entry to vlan_id=%d", sta->vlan_id);
798 }
799 return ret;
800#else /* CONFIG_NO_VLAN */
801 return 0;
802#endif /* CONFIG_NO_VLAN */
803}
804
805
806#ifdef CONFIG_IEEE80211W
807
808int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
809{
810 u32 tu;
811 struct os_time now, passed;
812 os_get_time(&now);
813 os_time_sub(&now, &sta->sa_query_start, &passed);
814 tu = (passed.sec * 1000000 + passed.usec) / 1024;
815 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
816 hostapd_logger(hapd, sta->addr,
817 HOSTAPD_MODULE_IEEE80211,
818 HOSTAPD_LEVEL_DEBUG,
819 "association SA Query timed out");
820 sta->sa_query_timed_out = 1;
821 os_free(sta->sa_query_trans_id);
822 sta->sa_query_trans_id = NULL;
823 sta->sa_query_count = 0;
824 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
825 return 1;
826 }
827
828 return 0;
829}
830
831
832static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
833{
834 struct hostapd_data *hapd = eloop_ctx;
835 struct sta_info *sta = timeout_ctx;
836 unsigned int timeout, sec, usec;
837 u8 *trans_id, *nbuf;
838
839 if (sta->sa_query_count > 0 &&
840 ap_check_sa_query_timeout(hapd, sta))
841 return;
842
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700843 nbuf = os_realloc_array(sta->sa_query_trans_id,
844 sta->sa_query_count + 1,
845 WLAN_SA_QUERY_TR_ID_LEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700846 if (nbuf == NULL)
847 return;
848 if (sta->sa_query_count == 0) {
849 /* Starting a new SA Query procedure */
850 os_get_time(&sta->sa_query_start);
851 }
852 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
853 sta->sa_query_trans_id = nbuf;
854 sta->sa_query_count++;
855
856 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
857
858 timeout = hapd->conf->assoc_sa_query_retry_timeout;
859 sec = ((timeout / 1000) * 1024) / 1000;
860 usec = (timeout % 1000) * 1024;
861 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
862
863 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
864 HOSTAPD_LEVEL_DEBUG,
865 "association SA Query attempt %d", sta->sa_query_count);
866
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700867 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700868}
869
870
871void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
872{
873 ap_sa_query_timer(hapd, sta);
874}
875
876
877void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
878{
879 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
880 os_free(sta->sa_query_trans_id);
881 sta->sa_query_trans_id = NULL;
882 sta->sa_query_count = 0;
883}
884
885#endif /* CONFIG_IEEE80211W */
886
887
888void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
889 int authorized)
890{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800891 const u8 *dev_addr = NULL;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700892 char buf[100];
Dmitry Shmidt04949592012-07-19 12:16:46 -0700893#ifdef CONFIG_P2P
894 u8 addr[ETH_ALEN];
895#endif /* CONFIG_P2P */
896
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700897 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
898 return;
899
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800900#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -0700901 if (hapd->p2p_group == NULL) {
902 if (sta->p2p_ie != NULL &&
903 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
904 dev_addr = addr;
905 } else
906 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800907#endif /* CONFIG_P2P */
908
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700909 if (dev_addr)
910 os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
911 MAC2STR(sta->addr), MAC2STR(dev_addr));
912 else
913 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
914
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800915 if (authorized) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700916 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s", buf);
917
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800918 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700919 hapd->msg_ctx_parent != hapd->msg_ctx)
920 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
921 AP_STA_CONNECTED "%s", buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800922
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700923 sta->flags |= WLAN_STA_AUTHORIZED;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800924 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700925 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
926
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800927 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700928 hapd->msg_ctx_parent != hapd->msg_ctx)
929 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
930 AP_STA_DISCONNECTED "%s", buf);
931
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700932 sta->flags &= ~WLAN_STA_AUTHORIZED;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800933 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700934
935 if (hapd->sta_authorized_cb)
936 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800937 sta->addr, authorized, dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700938}
939
940
941void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
942 const u8 *addr, u16 reason)
943{
944
945 if (sta == NULL && addr)
946 sta = ap_get_sta(hapd, addr);
947
948 if (addr)
949 hostapd_drv_sta_deauth(hapd, addr, reason);
950
951 if (sta == NULL)
952 return;
953 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800954 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
955 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700956 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700957 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
958 "for " MACSTR " (%d seconds - "
959 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
960 __func__, MAC2STR(sta->addr),
961 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700962 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800963 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
964 ap_handle_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700965 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800966
967 sta->deauth_reason = reason;
968 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
969 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
970 eloop_register_timeout(hapd->iface->drv_flags &
971 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
972 ap_sta_deauth_cb_timeout, hapd, sta);
973}
974
975
976void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
977{
978 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
979 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
980 return;
981 }
982 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
983 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
984 ap_sta_deauth_cb_timeout(hapd, sta);
985}
986
987
988void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
989{
990 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
991 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
992 return;
993 }
994 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
995 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
996 ap_sta_disassoc_cb_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700997}