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 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
559 eloop_register_timeout(hapd->iface->drv_flags &
560 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
561 ap_sta_disassoc_cb_timeout, hapd, sta);
565 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
567 struct hostapd_data *hapd = eloop_ctx;
568 struct sta_info *sta = timeout_ctx;
570 ap_sta_remove(hapd, sta);
571 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
575 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
578 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
579 hapd->conf->iface, MAC2STR(sta->addr));
580 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
581 ap_sta_set_authorized(hapd, sta, 0);
582 sta->timeout_next = STA_REMOVE;
583 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
584 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
585 ap_handle_timer, hapd, sta);
586 accounting_sta_stop(hapd, sta);
587 ieee802_1x_free_station(sta);
589 sta->deauth_reason = reason;
590 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
591 eloop_register_timeout(hapd->iface->drv_flags &
592 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
593 ap_sta_deauth_cb_timeout, hapd, sta);
597 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
600 #ifndef CONFIG_NO_VLAN
602 struct hostapd_vlan *vlan = NULL;
606 * Do not proceed furthur if the vlan id remains same. We do not want
607 * duplicate dynamic vlan entries.
609 if (sta->vlan_id == old_vlanid)
613 * During 1x reauth, if the vlan id changes, then remove the old id and
614 * proceed furthur to add the new one.
617 vlan_remove_dynamic(hapd, old_vlanid);
619 iface = hapd->conf->iface;
620 if (sta->ssid->vlan[0])
621 iface = sta->ssid->vlan;
623 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
625 else if (sta->vlan_id > 0) {
626 vlan = hapd->conf->vlan;
628 if (vlan->vlan_id == sta->vlan_id ||
629 vlan->vlan_id == VLAN_ID_WILDCARD) {
630 iface = vlan->ifname;
637 if (sta->vlan_id > 0 && vlan == NULL) {
638 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
639 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
640 "binding station to (vlan_id=%d)",
643 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
644 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
646 hostapd_logger(hapd, sta->addr,
647 HOSTAPD_MODULE_IEEE80211,
648 HOSTAPD_LEVEL_DEBUG, "could not add "
649 "dynamic VLAN interface for vlan_id=%d",
654 iface = vlan->ifname;
655 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
656 hostapd_logger(hapd, sta->addr,
657 HOSTAPD_MODULE_IEEE80211,
658 HOSTAPD_LEVEL_DEBUG, "could not "
659 "configure encryption for dynamic VLAN "
660 "interface for vlan_id=%d",
664 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
665 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
666 "interface '%s'", iface);
667 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
668 if (sta->vlan_id > 0) {
669 vlan->dynamic_vlan++;
670 hostapd_logger(hapd, sta->addr,
671 HOSTAPD_MODULE_IEEE80211,
672 HOSTAPD_LEVEL_DEBUG, "updated existing "
673 "dynamic VLAN interface '%s'", iface);
677 * Update encryption configuration for statically generated
678 * VLAN interface. This is only used for static WEP
679 * configuration for the case where hostapd did not yet know
680 * which keys are to be used when the interface was added.
682 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
683 hostapd_logger(hapd, sta->addr,
684 HOSTAPD_MODULE_IEEE80211,
685 HOSTAPD_LEVEL_DEBUG, "could not "
686 "configure encryption for VLAN "
687 "interface for vlan_id=%d",
692 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
693 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
696 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
697 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
699 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
701 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
702 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
703 "entry to vlan_id=%d", sta->vlan_id);
706 #else /* CONFIG_NO_VLAN */
708 #endif /* CONFIG_NO_VLAN */
712 #ifdef CONFIG_IEEE80211W
714 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
717 struct os_time now, passed;
719 os_time_sub(&now, &sta->sa_query_start, &passed);
720 tu = (passed.sec * 1000000 + passed.usec) / 1024;
721 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
722 hostapd_logger(hapd, sta->addr,
723 HOSTAPD_MODULE_IEEE80211,
725 "association SA Query timed out");
726 sta->sa_query_timed_out = 1;
727 os_free(sta->sa_query_trans_id);
728 sta->sa_query_trans_id = NULL;
729 sta->sa_query_count = 0;
730 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
738 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
740 struct hostapd_data *hapd = eloop_ctx;
741 struct sta_info *sta = timeout_ctx;
742 unsigned int timeout, sec, usec;
745 if (sta->sa_query_count > 0 &&
746 ap_check_sa_query_timeout(hapd, sta))
749 nbuf = os_realloc(sta->sa_query_trans_id,
750 (sta->sa_query_count + 1) * WLAN_SA_QUERY_TR_ID_LEN);
753 if (sta->sa_query_count == 0) {
754 /* Starting a new SA Query procedure */
755 os_get_time(&sta->sa_query_start);
757 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
758 sta->sa_query_trans_id = nbuf;
759 sta->sa_query_count++;
761 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
763 timeout = hapd->conf->assoc_sa_query_retry_timeout;
764 sec = ((timeout / 1000) * 1024) / 1000;
765 usec = (timeout % 1000) * 1024;
766 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
768 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
770 "association SA Query attempt %d", sta->sa_query_count);
773 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
774 #endif /* NEED_AP_MLME */
778 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
780 ap_sa_query_timer(hapd, sta);
784 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
786 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
787 os_free(sta->sa_query_trans_id);
788 sta->sa_query_trans_id = NULL;
789 sta->sa_query_count = 0;
792 #endif /* CONFIG_IEEE80211W */
795 void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
798 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
802 sta->flags |= WLAN_STA_AUTHORIZED;
804 sta->flags &= ~WLAN_STA_AUTHORIZED;
806 if (hapd->sta_authorized_cb)
807 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
808 sta->addr, authorized);
812 void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
813 const u8 *addr, u16 reason)
816 if (sta == NULL && addr)
817 sta = ap_get_sta(hapd, addr);
820 hostapd_drv_sta_deauth(hapd, addr, reason);
824 ap_sta_set_authorized(hapd, sta, 0);
825 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
826 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
827 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
828 ap_handle_timer, hapd, sta);
829 sta->timeout_next = STA_REMOVE;
831 sta->deauth_reason = reason;
832 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
833 eloop_register_timeout(hapd->iface->drv_flags &
834 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
835 ap_sta_deauth_cb_timeout, hapd, sta);
839 void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
841 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
842 ap_sta_deauth_cb_timeout(hapd, sta);
846 void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)