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 "common/wpa_ctrl.h"
21 #include "radius/radius.h"
22 #include "radius/radius_client.h"
23 #include "drivers/driver.h"
26 #include "accounting.h"
27 #include "ieee802_1x.h"
28 #include "ieee802_11.h"
30 #include "preauth_auth.h"
31 #include "ap_config.h"
34 #include "vlan_init.h"
35 #include "p2p_hostapd.h"
36 #include "ap_drv_ops.h"
39 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
40 struct sta_info *sta);
41 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
42 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
43 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
44 #ifdef CONFIG_IEEE80211W
45 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
46 #endif /* CONFIG_IEEE80211W */
47 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
49 int ap_for_each_sta(struct hostapd_data *hapd,
50 int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
56 for (sta = hapd->sta_list; sta; sta = sta->next) {
57 if (cb(hapd, sta, ctx))
65 struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
69 s = hapd->sta_hash[STA_HASH(sta)];
70 while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
76 static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
80 if (hapd->sta_list == sta) {
81 hapd->sta_list = sta->next;
86 while (tmp != NULL && tmp->next != sta)
89 wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
90 "list.", MAC2STR(sta->addr));
92 tmp->next = sta->next;
96 void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
98 sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
99 hapd->sta_hash[STA_HASH(sta->addr)] = sta;
103 static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
107 s = hapd->sta_hash[STA_HASH(sta->addr)];
108 if (s == NULL) return;
109 if (os_memcmp(s->addr, sta->addr, 6) == 0) {
110 hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
114 while (s->hnext != NULL &&
115 os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
117 if (s->hnext != NULL)
118 s->hnext = s->hnext->hnext;
120 wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
121 " from hash table", MAC2STR(sta->addr));
125 void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
129 accounting_sta_stop(hapd, sta);
132 ap_sta_set_authorized(hapd, sta, 0);
134 if (sta->flags & WLAN_STA_WDS)
135 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 0);
137 if (!(sta->flags & WLAN_STA_PREAUTH))
138 hostapd_drv_sta_remove(hapd, sta->addr);
140 ap_sta_hash_del(hapd, sta);
141 ap_sta_list_del(hapd, sta);
144 hapd->sta_aid[(sta->aid - 1) / 32] &=
145 ~BIT((sta->aid - 1) % 32);
148 if (sta->nonerp_set) {
150 hapd->iface->num_sta_non_erp--;
151 if (hapd->iface->num_sta_non_erp == 0)
155 if (sta->no_short_slot_time_set) {
156 sta->no_short_slot_time_set = 0;
157 hapd->iface->num_sta_no_short_slot_time--;
158 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
159 && hapd->iface->num_sta_no_short_slot_time == 0)
163 if (sta->no_short_preamble_set) {
164 sta->no_short_preamble_set = 0;
165 hapd->iface->num_sta_no_short_preamble--;
166 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
167 && hapd->iface->num_sta_no_short_preamble == 0)
171 if (sta->no_ht_gf_set) {
172 sta->no_ht_gf_set = 0;
173 hapd->iface->num_sta_ht_no_gf--;
176 if (sta->no_ht_set) {
178 hapd->iface->num_sta_no_ht--;
181 if (sta->ht_20mhz_set) {
182 sta->ht_20mhz_set = 0;
183 hapd->iface->num_sta_ht_20mhz--;
187 if (sta->no_p2p_set) {
189 hapd->num_sta_no_p2p--;
190 if (hapd->num_sta_no_p2p == 0)
191 hostapd_p2p_non_p2p_sta_disconnected(hapd);
193 #endif /* CONFIG_P2P */
195 #if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
196 if (hostapd_ht_operation_update(hapd->iface) > 0)
198 #endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
201 ieee802_11_set_beacons(hapd->iface);
203 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
204 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
205 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
206 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
208 ieee802_1x_free_station(sta);
209 wpa_auth_sta_deinit(sta->wpa_sm);
210 rsn_preauth_free_station(hapd, sta);
211 #ifndef CONFIG_NO_RADIUS
212 radius_client_flush_auth(hapd->radius, sta->addr);
213 #endif /* CONFIG_NO_RADIUS */
215 os_free(sta->last_assoc_req);
216 os_free(sta->challenge);
218 #ifdef CONFIG_IEEE80211W
219 os_free(sta->sa_query_trans_id);
220 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
221 #endif /* CONFIG_IEEE80211W */
224 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
225 #endif /* CONFIG_P2P */
227 wpabuf_free(sta->wps_ie);
228 wpabuf_free(sta->p2p_ie);
230 os_free(sta->ht_capabilities);
237 void hostapd_free_stas(struct hostapd_data *hapd)
239 struct sta_info *sta, *prev;
241 sta = hapd->sta_list;
245 if (sta->flags & WLAN_STA_AUTH) {
246 mlme_deauthenticate_indication(
247 hapd, sta, WLAN_REASON_UNSPECIFIED);
250 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
251 MAC2STR(prev->addr));
252 ap_free_sta(hapd, prev);
258 * ap_handle_timer - Per STA timer handler
259 * @eloop_ctx: struct hostapd_data *
260 * @timeout_ctx: struct sta_info *
262 * This function is called to check station activity and to remove inactive
265 void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
267 struct hostapd_data *hapd = eloop_ctx;
268 struct sta_info *sta = timeout_ctx;
269 unsigned long next_time = 0;
271 if (sta->timeout_next == STA_REMOVE) {
272 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
273 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
274 "local deauth request");
275 ap_free_sta(hapd, sta);
279 if ((sta->flags & WLAN_STA_ASSOC) &&
280 (sta->timeout_next == STA_NULLFUNC ||
281 sta->timeout_next == STA_DISASSOC)) {
283 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
284 if (inactive_sec == -1) {
285 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
286 "Check inactivity: Could not "
287 "get station info from kernel driver for "
288 MACSTR, MAC2STR(sta->addr));
290 * The driver may not support this functionality.
291 * Anyway, try again after the next inactivity timeout,
292 * but do not disconnect the station now.
294 next_time = hapd->conf->ap_max_inactivity;
295 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
296 sta->flags & WLAN_STA_ASSOC) {
297 /* station activity detected; reset timeout state */
298 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
299 "Station " MACSTR " has been active %is ago",
300 MAC2STR(sta->addr), inactive_sec);
301 sta->timeout_next = STA_NULLFUNC;
302 next_time = hapd->conf->ap_max_inactivity -
305 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
306 "Station " MACSTR " has been "
307 "inactive too long: %d sec, max allowed: %d",
308 MAC2STR(sta->addr), inactive_sec,
309 hapd->conf->ap_max_inactivity);
311 if (hapd->conf->skip_inactivity_poll)
312 sta->timeout_next = STA_DISASSOC;
316 if ((sta->flags & WLAN_STA_ASSOC) &&
317 sta->timeout_next == STA_DISASSOC &&
318 !(sta->flags & WLAN_STA_PENDING_POLL) &&
319 !hapd->conf->skip_inactivity_poll) {
320 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
321 " has ACKed data poll", MAC2STR(sta->addr));
322 /* data nullfunc frame poll did not produce TX errors; assume
323 * station ACKed it */
324 sta->timeout_next = STA_NULLFUNC;
325 next_time = hapd->conf->ap_max_inactivity;
329 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
334 if (sta->timeout_next == STA_NULLFUNC &&
335 (sta->flags & WLAN_STA_ASSOC)) {
336 wpa_printf(MSG_DEBUG, " Polling STA");
337 sta->flags |= WLAN_STA_PENDING_POLL;
338 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
339 sta->flags & WLAN_STA_WMM);
340 } else if (sta->timeout_next != STA_REMOVE) {
341 int deauth = sta->timeout_next == STA_DEAUTH;
343 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
344 "Timeout, sending %s info to STA " MACSTR,
345 deauth ? "deauthentication" : "disassociation",
349 hostapd_drv_sta_deauth(
351 WLAN_REASON_PREV_AUTH_NOT_VALID);
353 hostapd_drv_sta_disassoc(
355 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
359 switch (sta->timeout_next) {
361 sta->timeout_next = STA_DISASSOC;
362 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
366 ap_sta_set_authorized(hapd, sta, 0);
367 sta->flags &= ~WLAN_STA_ASSOC;
368 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
369 if (!sta->acct_terminate_cause)
370 sta->acct_terminate_cause =
371 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
372 accounting_sta_stop(hapd, sta);
373 ieee802_1x_free_station(sta);
374 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
375 HOSTAPD_LEVEL_INFO, "disassociated due to "
377 sta->timeout_next = STA_DEAUTH;
378 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
380 mlme_disassociate_indication(
381 hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
385 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
386 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
387 "inactivity (timer DEAUTH/REMOVE)");
388 if (!sta->acct_terminate_cause)
389 sta->acct_terminate_cause =
390 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
391 mlme_deauthenticate_indication(
393 WLAN_REASON_PREV_AUTH_NOT_VALID);
394 ap_free_sta(hapd, sta);
400 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
402 struct hostapd_data *hapd = eloop_ctx;
403 struct sta_info *sta = timeout_ctx;
406 if (!(sta->flags & WLAN_STA_AUTH))
409 mlme_deauthenticate_indication(hapd, sta,
410 WLAN_REASON_PREV_AUTH_NOT_VALID);
411 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
412 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
414 sta->acct_terminate_cause =
415 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
416 os_memcpy(addr, sta->addr, ETH_ALEN);
417 ap_free_sta(hapd, sta);
418 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
422 void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
425 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
426 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
427 "seconds", session_timeout);
428 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
429 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
434 void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
436 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
440 struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
442 struct sta_info *sta;
444 sta = ap_get_sta(hapd, addr);
448 wpa_printf(MSG_DEBUG, " New STA");
449 if (hapd->num_sta >= hapd->conf->max_num_sta) {
450 /* FIX: might try to remove some old STAs first? */
451 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
452 hapd->num_sta, hapd->conf->max_num_sta);
456 sta = os_zalloc(sizeof(struct sta_info));
458 wpa_printf(MSG_ERROR, "malloc failed");
461 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
463 /* initialize STA info data */
464 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
465 ap_handle_timer, hapd, sta);
466 os_memcpy(sta->addr, addr, ETH_ALEN);
467 sta->next = hapd->sta_list;
468 hapd->sta_list = sta;
470 ap_sta_hash_add(hapd, sta);
471 sta->ssid = &hapd->conf->ssid;
472 ap_sta_remove_in_other_bss(hapd, sta);
478 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
480 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
482 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
484 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
485 sta->flags & WLAN_STA_ASSOC) {
486 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
487 " from kernel driver.", MAC2STR(sta->addr));
494 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
495 struct sta_info *sta)
497 struct hostapd_iface *iface = hapd->iface;
500 for (i = 0; i < iface->num_bss; i++) {
501 struct hostapd_data *bss = iface->bss[i];
502 struct sta_info *sta2;
503 /* bss should always be set during operation, but it may be
504 * NULL during reconfiguration. Assume the STA is not
505 * associated to another BSS in that case to avoid NULL pointer
507 if (bss == hapd || bss == NULL)
509 sta2 = ap_get_sta(bss, sta->addr);
513 ap_sta_disconnect(bss, sta2, sta2->addr,
514 WLAN_REASON_PREV_AUTH_NOT_VALID);
519 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
521 struct hostapd_data *hapd = eloop_ctx;
522 struct sta_info *sta = timeout_ctx;
524 ap_sta_remove(hapd, sta);
525 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
529 void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
532 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
533 hapd->conf->iface, MAC2STR(sta->addr));
534 sta->flags &= ~WLAN_STA_ASSOC;
535 ap_sta_set_authorized(hapd, sta, 0);
536 sta->timeout_next = STA_DEAUTH;
537 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
538 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
539 ap_handle_timer, hapd, sta);
540 accounting_sta_stop(hapd, sta);
541 ieee802_1x_free_station(sta);
543 sta->disassoc_reason = reason;
544 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
545 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
546 eloop_register_timeout(hapd->iface->drv_flags &
547 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
548 ap_sta_disassoc_cb_timeout, hapd, sta);
552 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
554 struct hostapd_data *hapd = eloop_ctx;
555 struct sta_info *sta = timeout_ctx;
557 ap_sta_remove(hapd, sta);
558 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
562 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
565 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
566 hapd->conf->iface, MAC2STR(sta->addr));
567 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
568 ap_sta_set_authorized(hapd, sta, 0);
569 sta->timeout_next = STA_REMOVE;
570 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
571 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
572 ap_handle_timer, hapd, sta);
573 accounting_sta_stop(hapd, sta);
574 ieee802_1x_free_station(sta);
576 sta->deauth_reason = reason;
577 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
578 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
579 eloop_register_timeout(hapd->iface->drv_flags &
580 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
581 ap_sta_deauth_cb_timeout, hapd, sta);
585 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
588 #ifndef CONFIG_NO_VLAN
590 struct hostapd_vlan *vlan = NULL;
594 * Do not proceed furthur if the vlan id remains same. We do not want
595 * duplicate dynamic vlan entries.
597 if (sta->vlan_id == old_vlanid)
601 * During 1x reauth, if the vlan id changes, then remove the old id and
602 * proceed furthur to add the new one.
605 vlan_remove_dynamic(hapd, old_vlanid);
607 iface = hapd->conf->iface;
608 if (sta->ssid->vlan[0])
609 iface = sta->ssid->vlan;
611 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
613 else if (sta->vlan_id > 0) {
614 vlan = hapd->conf->vlan;
616 if (vlan->vlan_id == sta->vlan_id ||
617 vlan->vlan_id == VLAN_ID_WILDCARD) {
618 iface = vlan->ifname;
625 if (sta->vlan_id > 0 && vlan == NULL) {
626 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
627 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
628 "binding station to (vlan_id=%d)",
631 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
632 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
634 hostapd_logger(hapd, sta->addr,
635 HOSTAPD_MODULE_IEEE80211,
636 HOSTAPD_LEVEL_DEBUG, "could not add "
637 "dynamic VLAN interface for vlan_id=%d",
642 iface = vlan->ifname;
643 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
644 hostapd_logger(hapd, sta->addr,
645 HOSTAPD_MODULE_IEEE80211,
646 HOSTAPD_LEVEL_DEBUG, "could not "
647 "configure encryption for dynamic VLAN "
648 "interface for vlan_id=%d",
652 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
653 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
654 "interface '%s'", iface);
655 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
656 if (sta->vlan_id > 0) {
657 vlan->dynamic_vlan++;
658 hostapd_logger(hapd, sta->addr,
659 HOSTAPD_MODULE_IEEE80211,
660 HOSTAPD_LEVEL_DEBUG, "updated existing "
661 "dynamic VLAN interface '%s'", iface);
665 * Update encryption configuration for statically generated
666 * VLAN interface. This is only used for static WEP
667 * configuration for the case where hostapd did not yet know
668 * which keys are to be used when the interface was added.
670 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
671 hostapd_logger(hapd, sta->addr,
672 HOSTAPD_MODULE_IEEE80211,
673 HOSTAPD_LEVEL_DEBUG, "could not "
674 "configure encryption for VLAN "
675 "interface for vlan_id=%d",
680 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
681 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
684 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
685 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
687 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
689 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
690 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
691 "entry to vlan_id=%d", sta->vlan_id);
694 #else /* CONFIG_NO_VLAN */
696 #endif /* CONFIG_NO_VLAN */
700 #ifdef CONFIG_IEEE80211W
702 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
705 struct os_time now, passed;
707 os_time_sub(&now, &sta->sa_query_start, &passed);
708 tu = (passed.sec * 1000000 + passed.usec) / 1024;
709 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
710 hostapd_logger(hapd, sta->addr,
711 HOSTAPD_MODULE_IEEE80211,
713 "association SA Query timed out");
714 sta->sa_query_timed_out = 1;
715 os_free(sta->sa_query_trans_id);
716 sta->sa_query_trans_id = NULL;
717 sta->sa_query_count = 0;
718 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
726 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
728 struct hostapd_data *hapd = eloop_ctx;
729 struct sta_info *sta = timeout_ctx;
730 unsigned int timeout, sec, usec;
733 if (sta->sa_query_count > 0 &&
734 ap_check_sa_query_timeout(hapd, sta))
737 nbuf = os_realloc(sta->sa_query_trans_id,
738 (sta->sa_query_count + 1) * WLAN_SA_QUERY_TR_ID_LEN);
741 if (sta->sa_query_count == 0) {
742 /* Starting a new SA Query procedure */
743 os_get_time(&sta->sa_query_start);
745 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
746 sta->sa_query_trans_id = nbuf;
747 sta->sa_query_count++;
749 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
751 timeout = hapd->conf->assoc_sa_query_retry_timeout;
752 sec = ((timeout / 1000) * 1024) / 1000;
753 usec = (timeout % 1000) * 1024;
754 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
756 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
758 "association SA Query attempt %d", sta->sa_query_count);
761 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
762 #endif /* NEED_AP_MLME */
766 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
768 ap_sa_query_timer(hapd, sta);
772 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
774 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
775 os_free(sta->sa_query_trans_id);
776 sta->sa_query_trans_id = NULL;
777 sta->sa_query_count = 0;
780 #endif /* CONFIG_IEEE80211W */
783 void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
786 const u8 *dev_addr = NULL;
787 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
791 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
792 #endif /* CONFIG_P2P */
796 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
797 MACSTR " p2p_dev_addr=" MACSTR,
798 MAC2STR(sta->addr), MAC2STR(dev_addr));
800 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
801 MACSTR, MAC2STR(sta->addr));
802 if (hapd->msg_ctx_parent &&
803 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
804 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
805 AP_STA_CONNECTED MACSTR " p2p_dev_addr="
807 MAC2STR(sta->addr), MAC2STR(dev_addr));
808 else if (hapd->msg_ctx_parent &&
809 hapd->msg_ctx_parent != hapd->msg_ctx)
810 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
811 AP_STA_CONNECTED MACSTR, MAC2STR(sta->addr));
813 sta->flags |= WLAN_STA_AUTHORIZED;
816 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
817 MACSTR " p2p_dev_addr=" MACSTR,
818 MAC2STR(sta->addr), MAC2STR(dev_addr));
820 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
821 MACSTR, MAC2STR(sta->addr));
822 if (hapd->msg_ctx_parent &&
823 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
824 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
825 AP_STA_DISCONNECTED MACSTR " p2p_dev_addr="
826 MACSTR, MAC2STR(sta->addr), MAC2STR(dev_addr));
827 else if (hapd->msg_ctx_parent &&
828 hapd->msg_ctx_parent != hapd->msg_ctx)
829 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
830 AP_STA_DISCONNECTED MACSTR,
832 sta->flags &= ~WLAN_STA_AUTHORIZED;
835 if (hapd->sta_authorized_cb)
836 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
837 sta->addr, authorized, dev_addr);
841 void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
842 const u8 *addr, u16 reason)
845 if (sta == NULL && addr)
846 sta = ap_get_sta(hapd, addr);
849 hostapd_drv_sta_deauth(hapd, addr, reason);
853 ap_sta_set_authorized(hapd, sta, 0);
854 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
855 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
856 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
857 ap_handle_timer, hapd, sta);
858 sta->timeout_next = STA_REMOVE;
860 sta->deauth_reason = reason;
861 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
862 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
863 eloop_register_timeout(hapd->iface->drv_flags &
864 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
865 ap_sta_deauth_cb_timeout, hapd, sta);
869 void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
871 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
872 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
875 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
876 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
877 ap_sta_deauth_cb_timeout(hapd, sta);
881 void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
883 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
884 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
887 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
888 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
889 ap_sta_disassoc_cb_timeout(hapd, sta);