2 * hostapd / Station table
3 * Copyright (c) 2002-2011, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
17 #include "utils/common.h"
18 #include "utils/eloop.h"
19 #include "common/ieee802_11_defs.h"
20 #include "radius/radius.h"
21 #include "radius/radius_client.h"
22 #include "drivers/driver.h"
25 #include "accounting.h"
26 #include "ieee802_1x.h"
27 #include "ieee802_11.h"
29 #include "preauth_auth.h"
30 #include "ap_config.h"
33 #include "vlan_init.h"
34 #include "p2p_hostapd.h"
35 #include "ap_drv_ops.h"
38 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
39 struct sta_info *sta);
40 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
41 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
42 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
43 #ifdef CONFIG_IEEE80211W
44 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
45 #endif /* CONFIG_IEEE80211W */
46 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
48 int ap_for_each_sta(struct hostapd_data *hapd,
49 int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
55 for (sta = hapd->sta_list; sta; sta = sta->next) {
56 if (cb(hapd, sta, ctx))
64 struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
68 s = hapd->sta_hash[STA_HASH(sta)];
69 while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
75 static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
79 if (hapd->sta_list == sta) {
80 hapd->sta_list = sta->next;
85 while (tmp != NULL && tmp->next != sta)
88 wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
89 "list.", MAC2STR(sta->addr));
91 tmp->next = sta->next;
95 void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
97 sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
98 hapd->sta_hash[STA_HASH(sta->addr)] = sta;
102 static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
106 s = hapd->sta_hash[STA_HASH(sta->addr)];
107 if (s == NULL) return;
108 if (os_memcmp(s->addr, sta->addr, 6) == 0) {
109 hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
113 while (s->hnext != NULL &&
114 os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
116 if (s->hnext != NULL)
117 s->hnext = s->hnext->hnext;
119 wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
120 " from hash table", MAC2STR(sta->addr));
124 void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
128 accounting_sta_stop(hapd, sta);
131 ap_sta_set_authorized(hapd, sta, 0);
133 if (sta->flags & WLAN_STA_WDS)
134 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 0);
136 if (!(sta->flags & WLAN_STA_PREAUTH))
137 hostapd_drv_sta_remove(hapd, sta->addr);
139 ap_sta_hash_del(hapd, sta);
140 ap_sta_list_del(hapd, sta);
143 hapd->sta_aid[(sta->aid - 1) / 32] &=
144 ~BIT((sta->aid - 1) % 32);
147 if (sta->nonerp_set) {
149 hapd->iface->num_sta_non_erp--;
150 if (hapd->iface->num_sta_non_erp == 0)
154 if (sta->no_short_slot_time_set) {
155 sta->no_short_slot_time_set = 0;
156 hapd->iface->num_sta_no_short_slot_time--;
157 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
158 && hapd->iface->num_sta_no_short_slot_time == 0)
162 if (sta->no_short_preamble_set) {
163 sta->no_short_preamble_set = 0;
164 hapd->iface->num_sta_no_short_preamble--;
165 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
166 && hapd->iface->num_sta_no_short_preamble == 0)
170 if (sta->no_ht_gf_set) {
171 sta->no_ht_gf_set = 0;
172 hapd->iface->num_sta_ht_no_gf--;
175 if (sta->no_ht_set) {
177 hapd->iface->num_sta_no_ht--;
180 if (sta->ht_20mhz_set) {
181 sta->ht_20mhz_set = 0;
182 hapd->iface->num_sta_ht_20mhz--;
186 if (sta->no_p2p_set) {
188 hapd->num_sta_no_p2p--;
189 if (hapd->num_sta_no_p2p == 0)
190 hostapd_p2p_non_p2p_sta_disconnected(hapd);
192 #endif /* CONFIG_P2P */
194 #if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
195 if (hostapd_ht_operation_update(hapd->iface) > 0)
197 #endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
200 ieee802_11_set_beacons(hapd->iface);
202 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
203 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
204 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
205 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
207 ieee802_1x_free_station(sta);
208 wpa_auth_sta_deinit(sta->wpa_sm);
209 rsn_preauth_free_station(hapd, sta);
210 #ifndef CONFIG_NO_RADIUS
211 radius_client_flush_auth(hapd->radius, sta->addr);
212 #endif /* CONFIG_NO_RADIUS */
214 os_free(sta->last_assoc_req);
215 os_free(sta->challenge);
217 #ifdef CONFIG_IEEE80211W
218 os_free(sta->sa_query_trans_id);
219 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
220 #endif /* CONFIG_IEEE80211W */
223 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
224 #endif /* CONFIG_P2P */
226 wpabuf_free(sta->wps_ie);
227 wpabuf_free(sta->p2p_ie);
229 os_free(sta->ht_capabilities);
235 void hostapd_free_stas(struct hostapd_data *hapd)
237 struct sta_info *sta, *prev;
239 sta = hapd->sta_list;
243 if (sta->flags & WLAN_STA_AUTH) {
244 mlme_deauthenticate_indication(
245 hapd, sta, WLAN_REASON_UNSPECIFIED);
248 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
249 MAC2STR(prev->addr));
250 ap_free_sta(hapd, prev);
256 * ap_handle_timer - Per STA timer handler
257 * @eloop_ctx: struct hostapd_data *
258 * @timeout_ctx: struct sta_info *
260 * This function is called to check station activity and to remove inactive
263 void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
265 struct hostapd_data *hapd = eloop_ctx;
266 struct sta_info *sta = timeout_ctx;
267 unsigned long next_time = 0;
269 if (sta->timeout_next == STA_REMOVE) {
270 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
271 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
272 "local deauth request");
273 ap_free_sta(hapd, sta);
277 if ((sta->flags & WLAN_STA_ASSOC) &&
278 (sta->timeout_next == STA_NULLFUNC ||
279 sta->timeout_next == STA_DISASSOC)) {
281 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
282 if (inactive_sec == -1) {
283 wpa_msg(hapd, MSG_DEBUG, "Check inactivity: Could not "
284 "get station info rom kernel driver for "
285 MACSTR, MAC2STR(sta->addr));
286 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
287 sta->flags & WLAN_STA_ASSOC) {
288 /* station activity detected; reset timeout state */
289 wpa_msg(hapd, MSG_DEBUG, "Station " MACSTR " has been "
291 MAC2STR(sta->addr), inactive_sec);
292 sta->timeout_next = STA_NULLFUNC;
293 next_time = hapd->conf->ap_max_inactivity -
296 wpa_msg(hapd, MSG_DEBUG, "Station " MACSTR " has been "
297 "inactive too long: %d sec, max allowed: %d",
298 MAC2STR(sta->addr), inactive_sec,
299 hapd->conf->ap_max_inactivity);
303 if ((sta->flags & WLAN_STA_ASSOC) &&
304 sta->timeout_next == STA_DISASSOC &&
305 !(sta->flags & WLAN_STA_PENDING_POLL)) {
306 wpa_msg(hapd, MSG_DEBUG, "Station " MACSTR " has ACKed data "
307 "poll", MAC2STR(sta->addr));
308 /* data nullfunc frame poll did not produce TX errors; assume
309 * station ACKed it */
310 sta->timeout_next = STA_NULLFUNC;
311 next_time = hapd->conf->ap_max_inactivity;
315 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
320 if (sta->timeout_next == STA_NULLFUNC &&
321 (sta->flags & WLAN_STA_ASSOC)) {
322 #ifndef CONFIG_NATIVE_WINDOWS
323 /* send data frame to poll STA and check whether this frame
325 struct ieee80211_hdr hdr;
327 wpa_printf(MSG_DEBUG, " Polling STA with data frame");
328 sta->flags |= WLAN_STA_PENDING_POLL;
330 os_memset(&hdr, 0, sizeof(hdr));
332 os_strcmp(hapd->driver->name, "hostap") == 0) {
334 * WLAN_FC_STYPE_NULLFUNC would be more appropriate,
335 * but it is apparently not retried so TX Exc events
336 * are not received for it.
339 IEEE80211_FC(WLAN_FC_TYPE_DATA,
343 IEEE80211_FC(WLAN_FC_TYPE_DATA,
344 WLAN_FC_STYPE_NULLFUNC);
347 hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
348 os_memcpy(hdr.IEEE80211_DA_FROMDS, sta->addr, ETH_ALEN);
349 os_memcpy(hdr.IEEE80211_BSSID_FROMDS, hapd->own_addr,
351 os_memcpy(hdr.IEEE80211_SA_FROMDS, hapd->own_addr, ETH_ALEN);
353 if (hostapd_drv_send_mlme(hapd, &hdr, sizeof(hdr)) < 0)
354 perror("ap_handle_timer: send");
355 #endif /* CONFIG_NATIVE_WINDOWS */
356 } else if (sta->timeout_next != STA_REMOVE) {
357 int deauth = sta->timeout_next == STA_DEAUTH;
359 wpa_printf(MSG_DEBUG, "Sending %s info to STA " MACSTR,
360 deauth ? "deauthentication" : "disassociation",
364 hostapd_drv_sta_deauth(
366 WLAN_REASON_PREV_AUTH_NOT_VALID);
368 hostapd_drv_sta_disassoc(
370 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
374 switch (sta->timeout_next) {
376 sta->timeout_next = STA_DISASSOC;
377 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
381 sta->flags &= ~WLAN_STA_ASSOC;
382 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
383 if (!sta->acct_terminate_cause)
384 sta->acct_terminate_cause =
385 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
386 accounting_sta_stop(hapd, sta);
387 ieee802_1x_free_station(sta);
388 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
389 HOSTAPD_LEVEL_INFO, "disassociated due to "
391 sta->timeout_next = STA_DEAUTH;
392 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
394 mlme_disassociate_indication(
395 hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
399 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
400 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
402 if (!sta->acct_terminate_cause)
403 sta->acct_terminate_cause =
404 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
405 mlme_deauthenticate_indication(
407 WLAN_REASON_PREV_AUTH_NOT_VALID);
408 ap_free_sta(hapd, sta);
414 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
416 struct hostapd_data *hapd = eloop_ctx;
417 struct sta_info *sta = timeout_ctx;
420 if (!(sta->flags & WLAN_STA_AUTH))
423 mlme_deauthenticate_indication(hapd, sta,
424 WLAN_REASON_PREV_AUTH_NOT_VALID);
425 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
426 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
428 sta->acct_terminate_cause =
429 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
430 os_memcpy(addr, sta->addr, ETH_ALEN);
431 ap_free_sta(hapd, sta);
432 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
436 void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
439 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
440 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
441 "seconds", session_timeout);
442 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
443 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
448 void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
450 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
454 struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
456 struct sta_info *sta;
458 sta = ap_get_sta(hapd, addr);
462 wpa_printf(MSG_DEBUG, " New STA");
463 if (hapd->num_sta >= hapd->conf->max_num_sta) {
464 /* FIX: might try to remove some old STAs first? */
465 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
466 hapd->num_sta, hapd->conf->max_num_sta);
470 sta = os_zalloc(sizeof(struct sta_info));
472 wpa_printf(MSG_ERROR, "malloc failed");
475 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
477 /* initialize STA info data */
478 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
479 ap_handle_timer, hapd, sta);
480 os_memcpy(sta->addr, addr, ETH_ALEN);
481 sta->next = hapd->sta_list;
482 hapd->sta_list = sta;
484 ap_sta_hash_add(hapd, sta);
485 sta->ssid = &hapd->conf->ssid;
486 ap_sta_remove_in_other_bss(hapd, sta);
492 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
494 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
496 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
498 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
499 sta->flags & WLAN_STA_ASSOC) {
500 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
501 " from kernel driver.", MAC2STR(sta->addr));
508 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
509 struct sta_info *sta)
511 struct hostapd_iface *iface = hapd->iface;
514 for (i = 0; i < iface->num_bss; i++) {
515 struct hostapd_data *bss = iface->bss[i];
516 struct sta_info *sta2;
517 /* bss should always be set during operation, but it may be
518 * NULL during reconfiguration. Assume the STA is not
519 * associated to another BSS in that case to avoid NULL pointer
521 if (bss == hapd || bss == NULL)
523 sta2 = ap_get_sta(bss, sta->addr);
527 ap_sta_disconnect(bss, sta2, sta2->addr,
528 WLAN_REASON_PREV_AUTH_NOT_VALID);
533 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
535 struct hostapd_data *hapd = eloop_ctx;
536 struct sta_info *sta = timeout_ctx;
538 ap_sta_remove(hapd, sta);
539 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
543 void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
546 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
547 hapd->conf->iface, MAC2STR(sta->addr));
548 sta->flags &= ~WLAN_STA_ASSOC;
549 ap_sta_set_authorized(hapd, sta, 0);
550 sta->timeout_next = STA_DEAUTH;
551 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
552 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
553 ap_handle_timer, hapd, sta);
554 accounting_sta_stop(hapd, sta);
555 ieee802_1x_free_station(sta);
557 sta->disassoc_reason = reason;
558 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
559 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
560 eloop_register_timeout(hapd->iface->drv_flags &
561 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
562 ap_sta_disassoc_cb_timeout, hapd, sta);
566 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
568 struct hostapd_data *hapd = eloop_ctx;
569 struct sta_info *sta = timeout_ctx;
571 ap_sta_remove(hapd, sta);
572 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
576 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
579 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
580 hapd->conf->iface, MAC2STR(sta->addr));
581 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
582 ap_sta_set_authorized(hapd, sta, 0);
583 sta->timeout_next = STA_REMOVE;
584 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
585 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
586 ap_handle_timer, hapd, sta);
587 accounting_sta_stop(hapd, sta);
588 ieee802_1x_free_station(sta);
590 sta->deauth_reason = reason;
591 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
592 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
593 eloop_register_timeout(hapd->iface->drv_flags &
594 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
595 ap_sta_deauth_cb_timeout, hapd, sta);
599 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
602 #ifndef CONFIG_NO_VLAN
604 struct hostapd_vlan *vlan = NULL;
608 * Do not proceed furthur if the vlan id remains same. We do not want
609 * duplicate dynamic vlan entries.
611 if (sta->vlan_id == old_vlanid)
615 * During 1x reauth, if the vlan id changes, then remove the old id and
616 * proceed furthur to add the new one.
619 vlan_remove_dynamic(hapd, old_vlanid);
621 iface = hapd->conf->iface;
622 if (sta->ssid->vlan[0])
623 iface = sta->ssid->vlan;
625 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
627 else if (sta->vlan_id > 0) {
628 vlan = hapd->conf->vlan;
630 if (vlan->vlan_id == sta->vlan_id ||
631 vlan->vlan_id == VLAN_ID_WILDCARD) {
632 iface = vlan->ifname;
639 if (sta->vlan_id > 0 && vlan == NULL) {
640 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
641 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
642 "binding station to (vlan_id=%d)",
645 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
646 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
648 hostapd_logger(hapd, sta->addr,
649 HOSTAPD_MODULE_IEEE80211,
650 HOSTAPD_LEVEL_DEBUG, "could not add "
651 "dynamic VLAN interface for vlan_id=%d",
656 iface = vlan->ifname;
657 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
658 hostapd_logger(hapd, sta->addr,
659 HOSTAPD_MODULE_IEEE80211,
660 HOSTAPD_LEVEL_DEBUG, "could not "
661 "configure encryption for dynamic VLAN "
662 "interface for vlan_id=%d",
666 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
667 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
668 "interface '%s'", iface);
669 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
670 if (sta->vlan_id > 0) {
671 vlan->dynamic_vlan++;
672 hostapd_logger(hapd, sta->addr,
673 HOSTAPD_MODULE_IEEE80211,
674 HOSTAPD_LEVEL_DEBUG, "updated existing "
675 "dynamic VLAN interface '%s'", iface);
679 * Update encryption configuration for statically generated
680 * VLAN interface. This is only used for static WEP
681 * configuration for the case where hostapd did not yet know
682 * which keys are to be used when the interface was added.
684 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
685 hostapd_logger(hapd, sta->addr,
686 HOSTAPD_MODULE_IEEE80211,
687 HOSTAPD_LEVEL_DEBUG, "could not "
688 "configure encryption for VLAN "
689 "interface for vlan_id=%d",
694 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
695 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
698 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
699 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
701 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
703 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
704 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
705 "entry to vlan_id=%d", sta->vlan_id);
708 #else /* CONFIG_NO_VLAN */
710 #endif /* CONFIG_NO_VLAN */
714 #ifdef CONFIG_IEEE80211W
716 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
719 struct os_time now, passed;
721 os_time_sub(&now, &sta->sa_query_start, &passed);
722 tu = (passed.sec * 1000000 + passed.usec) / 1024;
723 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
724 hostapd_logger(hapd, sta->addr,
725 HOSTAPD_MODULE_IEEE80211,
727 "association SA Query timed out");
728 sta->sa_query_timed_out = 1;
729 os_free(sta->sa_query_trans_id);
730 sta->sa_query_trans_id = NULL;
731 sta->sa_query_count = 0;
732 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
740 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
742 struct hostapd_data *hapd = eloop_ctx;
743 struct sta_info *sta = timeout_ctx;
744 unsigned int timeout, sec, usec;
747 if (sta->sa_query_count > 0 &&
748 ap_check_sa_query_timeout(hapd, sta))
751 nbuf = os_realloc(sta->sa_query_trans_id,
752 (sta->sa_query_count + 1) * WLAN_SA_QUERY_TR_ID_LEN);
755 if (sta->sa_query_count == 0) {
756 /* Starting a new SA Query procedure */
757 os_get_time(&sta->sa_query_start);
759 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
760 sta->sa_query_trans_id = nbuf;
761 sta->sa_query_count++;
763 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
765 timeout = hapd->conf->assoc_sa_query_retry_timeout;
766 sec = ((timeout / 1000) * 1024) / 1000;
767 usec = (timeout % 1000) * 1024;
768 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
770 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
772 "association SA Query attempt %d", sta->sa_query_count);
775 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
776 #endif /* NEED_AP_MLME */
780 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
782 ap_sa_query_timer(hapd, sta);
786 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
788 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
789 os_free(sta->sa_query_trans_id);
790 sta->sa_query_trans_id = NULL;
791 sta->sa_query_count = 0;
794 #endif /* CONFIG_IEEE80211W */
797 void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
800 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
804 sta->flags |= WLAN_STA_AUTHORIZED;
806 sta->flags &= ~WLAN_STA_AUTHORIZED;
808 if (hapd->sta_authorized_cb)
809 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
810 sta->addr, authorized);
814 void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
815 const u8 *addr, u16 reason)
818 if (sta == NULL && addr)
819 sta = ap_get_sta(hapd, addr);
822 hostapd_drv_sta_deauth(hapd, addr, reason);
826 ap_sta_set_authorized(hapd, sta, 0);
827 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
828 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
829 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
830 ap_handle_timer, hapd, sta);
831 sta->timeout_next = STA_REMOVE;
833 sta->deauth_reason = reason;
834 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
835 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
836 eloop_register_timeout(hapd->iface->drv_flags &
837 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
838 ap_sta_deauth_cb_timeout, hapd, sta);
842 void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
844 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
845 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
848 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
849 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
850 ap_sta_deauth_cb_timeout(hapd, sta);
854 void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
856 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
857 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
860 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
861 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
862 ap_sta_disassoc_cb_timeout(hapd, sta);