blob: a6775f3f91580d4aa9c229cd63a89b9a59e1ca62 [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
Dmitry Shmidt96571392013-10-14 12:54:46 -0700235 if (hapd->radius)
236 radius_client_flush_auth(hapd->radius, sta->addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700237#endif /* CONFIG_NO_RADIUS */
238
239 os_free(sta->last_assoc_req);
240 os_free(sta->challenge);
241
242#ifdef CONFIG_IEEE80211W
243 os_free(sta->sa_query_trans_id);
244 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
245#endif /* CONFIG_IEEE80211W */
246
247#ifdef CONFIG_P2P
248 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
249#endif /* CONFIG_P2P */
250
Dmitry Shmidt04949592012-07-19 12:16:46 -0700251#ifdef CONFIG_INTERWORKING
252 if (sta->gas_dialog) {
253 int i;
254 for (i = 0; i < GAS_DIALOG_MAX; i++)
255 gas_serv_dialog_clear(&sta->gas_dialog[i]);
256 os_free(sta->gas_dialog);
257 }
258#endif /* CONFIG_INTERWORKING */
259
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700260 wpabuf_free(sta->wps_ie);
261 wpabuf_free(sta->p2p_ie);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800262 wpabuf_free(sta->hs20_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700263
264 os_free(sta->ht_capabilities);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800265 hostapd_free_psk_list(sta->psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700266 os_free(sta->identity);
267 os_free(sta->radius_cui);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700268
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800269#ifdef CONFIG_SAE
270 sae_clear_data(sta->sae);
271 os_free(sta->sae);
272#endif /* CONFIG_SAE */
273
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700274 os_free(sta);
275}
276
277
278void hostapd_free_stas(struct hostapd_data *hapd)
279{
280 struct sta_info *sta, *prev;
281
282 sta = hapd->sta_list;
283
284 while (sta) {
285 prev = sta;
286 if (sta->flags & WLAN_STA_AUTH) {
287 mlme_deauthenticate_indication(
288 hapd, sta, WLAN_REASON_UNSPECIFIED);
289 }
290 sta = sta->next;
291 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
292 MAC2STR(prev->addr));
293 ap_free_sta(hapd, prev);
294 }
295}
296
297
298/**
299 * ap_handle_timer - Per STA timer handler
300 * @eloop_ctx: struct hostapd_data *
301 * @timeout_ctx: struct sta_info *
302 *
303 * This function is called to check station activity and to remove inactive
304 * stations.
305 */
306void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
307{
308 struct hostapd_data *hapd = eloop_ctx;
309 struct sta_info *sta = timeout_ctx;
310 unsigned long next_time = 0;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700311 int reason;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700312
Dmitry Shmidt04949592012-07-19 12:16:46 -0700313 wpa_printf(MSG_DEBUG, "%s: " MACSTR " flags=0x%x timeout_next=%d",
314 __func__, MAC2STR(sta->addr), sta->flags,
315 sta->timeout_next);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316 if (sta->timeout_next == STA_REMOVE) {
317 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
318 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
319 "local deauth request");
320 ap_free_sta(hapd, sta);
321 return;
322 }
323
324 if ((sta->flags & WLAN_STA_ASSOC) &&
325 (sta->timeout_next == STA_NULLFUNC ||
326 sta->timeout_next == STA_DISASSOC)) {
327 int inactive_sec;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700328 /*
329 * Add random value to timeout so that we don't end up bouncing
330 * all stations at the same time if we have lots of associated
331 * stations that are idle (but keep re-associating).
332 */
333 int fuzz = os_random() % 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700334 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
335 if (inactive_sec == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800336 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
337 "Check inactivity: Could not "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800338 "get station info from kernel driver for "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700339 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800340 /*
341 * The driver may not support this functionality.
342 * Anyway, try again after the next inactivity timeout,
343 * but do not disconnect the station now.
344 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700345 next_time = hapd->conf->ap_max_inactivity + fuzz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700346 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
347 sta->flags & WLAN_STA_ASSOC) {
348 /* station activity detected; reset timeout state */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800349 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
350 "Station " MACSTR " has been active %is ago",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700351 MAC2STR(sta->addr), inactive_sec);
352 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700353 next_time = hapd->conf->ap_max_inactivity + fuzz -
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700354 inactive_sec;
355 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800356 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
357 "Station " MACSTR " has been "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700358 "inactive too long: %d sec, max allowed: %d",
359 MAC2STR(sta->addr), inactive_sec,
360 hapd->conf->ap_max_inactivity);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800361
362 if (hapd->conf->skip_inactivity_poll)
363 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364 }
365 }
366
367 if ((sta->flags & WLAN_STA_ASSOC) &&
368 sta->timeout_next == STA_DISASSOC &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800369 !(sta->flags & WLAN_STA_PENDING_POLL) &&
370 !hapd->conf->skip_inactivity_poll) {
371 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
372 " has ACKed data poll", MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700373 /* data nullfunc frame poll did not produce TX errors; assume
374 * station ACKed it */
375 sta->timeout_next = STA_NULLFUNC;
376 next_time = hapd->conf->ap_max_inactivity;
377 }
378
379 if (next_time) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700380 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
381 "for " MACSTR " (%lu seconds)",
382 __func__, MAC2STR(sta->addr), next_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700383 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
384 sta);
385 return;
386 }
387
388 if (sta->timeout_next == STA_NULLFUNC &&
389 (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800390 wpa_printf(MSG_DEBUG, " Polling STA");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700391 sta->flags |= WLAN_STA_PENDING_POLL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800392 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
393 sta->flags & WLAN_STA_WMM);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700394 } else if (sta->timeout_next != STA_REMOVE) {
395 int deauth = sta->timeout_next == STA_DEAUTH;
396
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800397 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
398 "Timeout, sending %s info to STA " MACSTR,
399 deauth ? "deauthentication" : "disassociation",
400 MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700401
402 if (deauth) {
403 hostapd_drv_sta_deauth(
404 hapd, sta->addr,
405 WLAN_REASON_PREV_AUTH_NOT_VALID);
406 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700407 reason = (sta->timeout_next == STA_DISASSOC) ?
408 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
409 WLAN_REASON_PREV_AUTH_NOT_VALID;
410
411 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700412 }
413 }
414
415 switch (sta->timeout_next) {
416 case STA_NULLFUNC:
417 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700418 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
419 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
420 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700421 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
422 hapd, sta);
423 break;
424 case STA_DISASSOC:
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700425 case STA_DISASSOC_FROM_CLI:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800426 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700427 sta->flags &= ~WLAN_STA_ASSOC;
428 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
429 if (!sta->acct_terminate_cause)
430 sta->acct_terminate_cause =
431 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
432 accounting_sta_stop(hapd, sta);
433 ieee802_1x_free_station(sta);
434 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
435 HOSTAPD_LEVEL_INFO, "disassociated due to "
436 "inactivity");
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700437 reason = (sta->timeout_next == STA_DISASSOC) ?
438 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
439 WLAN_REASON_PREV_AUTH_NOT_VALID;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700441 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
442 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
443 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700444 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
445 hapd, sta);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700446 mlme_disassociate_indication(hapd, sta, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700447 break;
448 case STA_DEAUTH:
449 case STA_REMOVE:
450 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
451 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800452 "inactivity (timer DEAUTH/REMOVE)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700453 if (!sta->acct_terminate_cause)
454 sta->acct_terminate_cause =
455 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
456 mlme_deauthenticate_indication(
457 hapd, sta,
458 WLAN_REASON_PREV_AUTH_NOT_VALID);
459 ap_free_sta(hapd, sta);
460 break;
461 }
462}
463
464
465static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
466{
467 struct hostapd_data *hapd = eloop_ctx;
468 struct sta_info *sta = timeout_ctx;
469 u8 addr[ETH_ALEN];
470
Dmitry Shmidt04949592012-07-19 12:16:46 -0700471 if (!(sta->flags & WLAN_STA_AUTH)) {
472 if (sta->flags & WLAN_STA_GAS) {
473 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
474 "entry " MACSTR, MAC2STR(sta->addr));
475 ap_free_sta(hapd, sta);
476 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700477 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700478 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479
480 mlme_deauthenticate_indication(hapd, sta,
481 WLAN_REASON_PREV_AUTH_NOT_VALID);
482 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
483 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
484 "session timeout");
485 sta->acct_terminate_cause =
486 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
487 os_memcpy(addr, sta->addr, ETH_ALEN);
488 ap_free_sta(hapd, sta);
489 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
490}
491
492
Dmitry Shmidt54605472013-11-08 11:10:19 -0800493void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta,
494 u32 session_timeout)
495{
496 if (eloop_replenish_timeout(session_timeout, 0,
497 ap_handle_session_timer, hapd, sta)) {
498 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
499 HOSTAPD_LEVEL_DEBUG, "setting session timeout "
500 "to %d seconds", session_timeout);
501 }
502}
503
504
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700505void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
506 u32 session_timeout)
507{
508 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
509 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
510 "seconds", session_timeout);
511 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
512 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
513 hapd, sta);
514}
515
516
517void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
518{
519 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
520}
521
522
523struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
524{
525 struct sta_info *sta;
526
527 sta = ap_get_sta(hapd, addr);
528 if (sta)
529 return sta;
530
531 wpa_printf(MSG_DEBUG, " New STA");
532 if (hapd->num_sta >= hapd->conf->max_num_sta) {
533 /* FIX: might try to remove some old STAs first? */
534 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
535 hapd->num_sta, hapd->conf->max_num_sta);
536 return NULL;
537 }
538
539 sta = os_zalloc(sizeof(struct sta_info));
540 if (sta == NULL) {
541 wpa_printf(MSG_ERROR, "malloc failed");
542 return NULL;
543 }
544 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800545 accounting_sta_get_id(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700546
547 /* initialize STA info data */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700548 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
549 "for " MACSTR " (%d seconds - ap_max_inactivity)",
550 __func__, MAC2STR(addr),
551 hapd->conf->ap_max_inactivity);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700552 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
553 ap_handle_timer, hapd, sta);
554 os_memcpy(sta->addr, addr, ETH_ALEN);
555 sta->next = hapd->sta_list;
556 hapd->sta_list = sta;
557 hapd->num_sta++;
558 ap_sta_hash_add(hapd, sta);
559 sta->ssid = &hapd->conf->ssid;
560 ap_sta_remove_in_other_bss(hapd, sta);
561
562 return sta;
563}
564
565
566static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
567{
568 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
569
570 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
571 MAC2STR(sta->addr));
572 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
573 sta->flags & WLAN_STA_ASSOC) {
574 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
575 " from kernel driver.", MAC2STR(sta->addr));
576 return -1;
577 }
578 return 0;
579}
580
581
582static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
583 struct sta_info *sta)
584{
585 struct hostapd_iface *iface = hapd->iface;
586 size_t i;
587
588 for (i = 0; i < iface->num_bss; i++) {
589 struct hostapd_data *bss = iface->bss[i];
590 struct sta_info *sta2;
591 /* bss should always be set during operation, but it may be
592 * NULL during reconfiguration. Assume the STA is not
593 * associated to another BSS in that case to avoid NULL pointer
594 * dereferences. */
595 if (bss == hapd || bss == NULL)
596 continue;
597 sta2 = ap_get_sta(bss, sta->addr);
598 if (!sta2)
599 continue;
600
601 ap_sta_disconnect(bss, sta2, sta2->addr,
602 WLAN_REASON_PREV_AUTH_NOT_VALID);
603 }
604}
605
606
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800607static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
608{
609 struct hostapd_data *hapd = eloop_ctx;
610 struct sta_info *sta = timeout_ctx;
611
612 ap_sta_remove(hapd, sta);
613 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
614}
615
616
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700617void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
618 u16 reason)
619{
620 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
621 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt700a1372013-03-15 14:14:44 -0700622 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800623 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700624 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700625 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
626 "for " MACSTR " (%d seconds - "
627 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
628 __func__, MAC2STR(sta->addr),
629 AP_MAX_INACTIVITY_AFTER_DISASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700630 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
631 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
632 ap_handle_timer, hapd, sta);
633 accounting_sta_stop(hapd, sta);
634 ieee802_1x_free_station(sta);
635
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800636 sta->disassoc_reason = reason;
637 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
638 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
639 eloop_register_timeout(hapd->iface->drv_flags &
640 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
641 ap_sta_disassoc_cb_timeout, hapd, sta);
642}
643
644
645static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
646{
647 struct hostapd_data *hapd = eloop_ctx;
648 struct sta_info *sta = timeout_ctx;
649
650 ap_sta_remove(hapd, sta);
651 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652}
653
654
655void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
656 u16 reason)
657{
658 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
659 hapd->conf->iface, MAC2STR(sta->addr));
660 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800661 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700663 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
664 "for " MACSTR " (%d seconds - "
665 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
666 __func__, MAC2STR(sta->addr),
667 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
669 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
670 ap_handle_timer, hapd, sta);
671 accounting_sta_stop(hapd, sta);
672 ieee802_1x_free_station(sta);
673
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800674 sta->deauth_reason = reason;
675 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
676 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
677 eloop_register_timeout(hapd->iface->drv_flags &
678 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
679 ap_sta_deauth_cb_timeout, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700680}
681
682
Dmitry Shmidt04949592012-07-19 12:16:46 -0700683#ifdef CONFIG_WPS
684int ap_sta_wps_cancel(struct hostapd_data *hapd,
685 struct sta_info *sta, void *ctx)
686{
687 if (sta && (sta->flags & WLAN_STA_WPS)) {
688 ap_sta_deauthenticate(hapd, sta,
689 WLAN_REASON_PREV_AUTH_NOT_VALID);
690 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
691 __func__, MAC2STR(sta->addr));
692 return 1;
693 }
694
695 return 0;
696}
697#endif /* CONFIG_WPS */
698
699
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700700int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
701 int old_vlanid)
702{
703#ifndef CONFIG_NO_VLAN
704 const char *iface;
705 struct hostapd_vlan *vlan = NULL;
706 int ret;
707
708 /*
709 * Do not proceed furthur if the vlan id remains same. We do not want
710 * duplicate dynamic vlan entries.
711 */
712 if (sta->vlan_id == old_vlanid)
713 return 0;
714
715 /*
716 * During 1x reauth, if the vlan id changes, then remove the old id and
717 * proceed furthur to add the new one.
718 */
719 if (old_vlanid > 0)
720 vlan_remove_dynamic(hapd, old_vlanid);
721
722 iface = hapd->conf->iface;
723 if (sta->ssid->vlan[0])
724 iface = sta->ssid->vlan;
725
726 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
727 sta->vlan_id = 0;
728 else if (sta->vlan_id > 0) {
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700729 struct hostapd_vlan *wildcard_vlan = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 vlan = hapd->conf->vlan;
731 while (vlan) {
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700732 if (vlan->vlan_id == sta->vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733 break;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700734 if (vlan->vlan_id == VLAN_ID_WILDCARD)
735 wildcard_vlan = vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700736 vlan = vlan->next;
737 }
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700738 if (!vlan)
739 vlan = wildcard_vlan;
740 if (vlan)
741 iface = vlan->ifname;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700742 }
743
744 if (sta->vlan_id > 0 && vlan == NULL) {
745 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
746 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
747 "binding station to (vlan_id=%d)",
748 sta->vlan_id);
749 return -1;
750 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
751 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
752 if (vlan == NULL) {
753 hostapd_logger(hapd, sta->addr,
754 HOSTAPD_MODULE_IEEE80211,
755 HOSTAPD_LEVEL_DEBUG, "could not add "
756 "dynamic VLAN interface for vlan_id=%d",
757 sta->vlan_id);
758 return -1;
759 }
760
761 iface = vlan->ifname;
762 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
763 hostapd_logger(hapd, sta->addr,
764 HOSTAPD_MODULE_IEEE80211,
765 HOSTAPD_LEVEL_DEBUG, "could not "
766 "configure encryption for dynamic VLAN "
767 "interface for vlan_id=%d",
768 sta->vlan_id);
769 }
770
771 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
772 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
773 "interface '%s'", iface);
774 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
775 if (sta->vlan_id > 0) {
776 vlan->dynamic_vlan++;
777 hostapd_logger(hapd, sta->addr,
778 HOSTAPD_MODULE_IEEE80211,
779 HOSTAPD_LEVEL_DEBUG, "updated existing "
780 "dynamic VLAN interface '%s'", iface);
781 }
782
783 /*
784 * Update encryption configuration for statically generated
785 * VLAN interface. This is only used for static WEP
786 * configuration for the case where hostapd did not yet know
787 * which keys are to be used when the interface was added.
788 */
789 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
790 hostapd_logger(hapd, sta->addr,
791 HOSTAPD_MODULE_IEEE80211,
792 HOSTAPD_LEVEL_DEBUG, "could not "
793 "configure encryption for VLAN "
794 "interface for vlan_id=%d",
795 sta->vlan_id);
796 }
797 }
798
799 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
800 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
801 "'%s'", iface);
802
803 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
804 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
805
806 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
807 if (ret < 0) {
808 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
809 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
810 "entry to vlan_id=%d", sta->vlan_id);
811 }
812 return ret;
813#else /* CONFIG_NO_VLAN */
814 return 0;
815#endif /* CONFIG_NO_VLAN */
816}
817
818
819#ifdef CONFIG_IEEE80211W
820
821int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
822{
823 u32 tu;
824 struct os_time now, passed;
825 os_get_time(&now);
826 os_time_sub(&now, &sta->sa_query_start, &passed);
827 tu = (passed.sec * 1000000 + passed.usec) / 1024;
828 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
829 hostapd_logger(hapd, sta->addr,
830 HOSTAPD_MODULE_IEEE80211,
831 HOSTAPD_LEVEL_DEBUG,
832 "association SA Query timed out");
833 sta->sa_query_timed_out = 1;
834 os_free(sta->sa_query_trans_id);
835 sta->sa_query_trans_id = NULL;
836 sta->sa_query_count = 0;
837 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
838 return 1;
839 }
840
841 return 0;
842}
843
844
845static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
846{
847 struct hostapd_data *hapd = eloop_ctx;
848 struct sta_info *sta = timeout_ctx;
849 unsigned int timeout, sec, usec;
850 u8 *trans_id, *nbuf;
851
852 if (sta->sa_query_count > 0 &&
853 ap_check_sa_query_timeout(hapd, sta))
854 return;
855
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700856 nbuf = os_realloc_array(sta->sa_query_trans_id,
857 sta->sa_query_count + 1,
858 WLAN_SA_QUERY_TR_ID_LEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700859 if (nbuf == NULL)
860 return;
861 if (sta->sa_query_count == 0) {
862 /* Starting a new SA Query procedure */
863 os_get_time(&sta->sa_query_start);
864 }
865 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
866 sta->sa_query_trans_id = nbuf;
867 sta->sa_query_count++;
868
869 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
870
871 timeout = hapd->conf->assoc_sa_query_retry_timeout;
872 sec = ((timeout / 1000) * 1024) / 1000;
873 usec = (timeout % 1000) * 1024;
874 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
875
876 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
877 HOSTAPD_LEVEL_DEBUG,
878 "association SA Query attempt %d", sta->sa_query_count);
879
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700881}
882
883
884void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
885{
886 ap_sa_query_timer(hapd, sta);
887}
888
889
890void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
891{
892 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
893 os_free(sta->sa_query_trans_id);
894 sta->sa_query_trans_id = NULL;
895 sta->sa_query_count = 0;
896}
897
898#endif /* CONFIG_IEEE80211W */
899
900
901void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
902 int authorized)
903{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800904 const u8 *dev_addr = NULL;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700905 char buf[100];
Dmitry Shmidt04949592012-07-19 12:16:46 -0700906#ifdef CONFIG_P2P
907 u8 addr[ETH_ALEN];
908#endif /* CONFIG_P2P */
909
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700910 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
911 return;
912
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800913#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -0700914 if (hapd->p2p_group == NULL) {
915 if (sta->p2p_ie != NULL &&
916 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
917 dev_addr = addr;
918 } else
919 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800920#endif /* CONFIG_P2P */
921
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700922 if (dev_addr)
923 os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
924 MAC2STR(sta->addr), MAC2STR(dev_addr));
925 else
926 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
927
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800928 if (authorized) {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700929 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s", buf);
930
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800931 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700932 hapd->msg_ctx_parent != hapd->msg_ctx)
933 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
934 AP_STA_CONNECTED "%s", buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800935
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700936 sta->flags |= WLAN_STA_AUTHORIZED;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800937 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700938 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
939
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800940 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700941 hapd->msg_ctx_parent != hapd->msg_ctx)
942 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
943 AP_STA_DISCONNECTED "%s", buf);
944
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700945 sta->flags &= ~WLAN_STA_AUTHORIZED;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800946 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700947
948 if (hapd->sta_authorized_cb)
949 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800950 sta->addr, authorized, dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951}
952
953
954void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
955 const u8 *addr, u16 reason)
956{
957
958 if (sta == NULL && addr)
959 sta = ap_get_sta(hapd, addr);
960
961 if (addr)
962 hostapd_drv_sta_deauth(hapd, addr, reason);
963
964 if (sta == NULL)
965 return;
966 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800967 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
968 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700969 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700970 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
971 "for " MACSTR " (%d seconds - "
972 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
973 __func__, MAC2STR(sta->addr),
974 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700975 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800976 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
977 ap_handle_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700978 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800979
980 sta->deauth_reason = reason;
981 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
982 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
983 eloop_register_timeout(hapd->iface->drv_flags &
984 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
985 ap_sta_deauth_cb_timeout, hapd, sta);
986}
987
988
989void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
990{
991 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
992 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
993 return;
994 }
995 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
996 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
997 ap_sta_deauth_cb_timeout(hapd, sta);
998}
999
1000
1001void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
1002{
1003 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
1004 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
1005 return;
1006 }
1007 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
1008 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1009 ap_sta_disassoc_cb_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001010}