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);
236 void hostapd_free_stas(struct hostapd_data *hapd)
238 struct sta_info *sta, *prev;
240 sta = hapd->sta_list;
244 if (sta->flags & WLAN_STA_AUTH) {
245 mlme_deauthenticate_indication(
246 hapd, sta, WLAN_REASON_UNSPECIFIED);
249 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
250 MAC2STR(prev->addr));
251 ap_free_sta(hapd, prev);
257 * ap_handle_timer - Per STA timer handler
258 * @eloop_ctx: struct hostapd_data *
259 * @timeout_ctx: struct sta_info *
261 * This function is called to check station activity and to remove inactive
264 void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
266 struct hostapd_data *hapd = eloop_ctx;
267 struct sta_info *sta = timeout_ctx;
268 unsigned long next_time = 0;
270 if (sta->timeout_next == STA_REMOVE) {
271 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
272 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
273 "local deauth request");
274 ap_free_sta(hapd, sta);
278 if ((sta->flags & WLAN_STA_ASSOC) &&
279 (sta->timeout_next == STA_NULLFUNC ||
280 sta->timeout_next == STA_DISASSOC)) {
282 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
283 if (inactive_sec == -1) {
284 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
285 "Check inactivity: Could not "
286 "get station info rom kernel driver for "
287 MACSTR, MAC2STR(sta->addr));
288 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
289 sta->flags & WLAN_STA_ASSOC) {
290 /* station activity detected; reset timeout state */
291 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
292 "Station " MACSTR " has been active %is ago",
293 MAC2STR(sta->addr), inactive_sec);
294 sta->timeout_next = STA_NULLFUNC;
295 next_time = hapd->conf->ap_max_inactivity -
298 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
299 "Station " MACSTR " has been "
300 "inactive too long: %d sec, max allowed: %d",
301 MAC2STR(sta->addr), inactive_sec,
302 hapd->conf->ap_max_inactivity);
306 if ((sta->flags & WLAN_STA_ASSOC) &&
307 sta->timeout_next == STA_DISASSOC &&
308 !(sta->flags & WLAN_STA_PENDING_POLL)) {
309 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
310 " has ACKed data poll", MAC2STR(sta->addr));
311 /* data nullfunc frame poll did not produce TX errors; assume
312 * station ACKed it */
313 sta->timeout_next = STA_NULLFUNC;
314 next_time = hapd->conf->ap_max_inactivity;
318 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
323 if (sta->timeout_next == STA_NULLFUNC &&
324 (sta->flags & WLAN_STA_ASSOC)) {
325 wpa_printf(MSG_DEBUG, " Polling STA");
326 sta->flags |= WLAN_STA_PENDING_POLL;
327 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
328 sta->flags & WLAN_STA_WMM);
329 } else if (sta->timeout_next != STA_REMOVE) {
330 int deauth = sta->timeout_next == STA_DEAUTH;
332 wpa_printf(MSG_DEBUG, "Sending %s info to STA " MACSTR,
333 deauth ? "deauthentication" : "disassociation",
337 hostapd_drv_sta_deauth(
339 WLAN_REASON_PREV_AUTH_NOT_VALID);
341 hostapd_drv_sta_disassoc(
343 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
347 switch (sta->timeout_next) {
349 sta->timeout_next = STA_DISASSOC;
350 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
354 ap_sta_set_authorized(hapd, sta, 0);
355 sta->flags &= ~WLAN_STA_ASSOC;
356 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
357 if (!sta->acct_terminate_cause)
358 sta->acct_terminate_cause =
359 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
360 accounting_sta_stop(hapd, sta);
361 ieee802_1x_free_station(sta);
362 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
363 HOSTAPD_LEVEL_INFO, "disassociated due to "
365 sta->timeout_next = STA_DEAUTH;
366 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
368 mlme_disassociate_indication(
369 hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
373 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
374 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
376 if (!sta->acct_terminate_cause)
377 sta->acct_terminate_cause =
378 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
379 mlme_deauthenticate_indication(
381 WLAN_REASON_PREV_AUTH_NOT_VALID);
382 ap_free_sta(hapd, sta);
388 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
390 struct hostapd_data *hapd = eloop_ctx;
391 struct sta_info *sta = timeout_ctx;
394 if (!(sta->flags & WLAN_STA_AUTH))
397 mlme_deauthenticate_indication(hapd, sta,
398 WLAN_REASON_PREV_AUTH_NOT_VALID);
399 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
400 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
402 sta->acct_terminate_cause =
403 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
404 os_memcpy(addr, sta->addr, ETH_ALEN);
405 ap_free_sta(hapd, sta);
406 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
410 void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
413 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
414 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
415 "seconds", session_timeout);
416 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
417 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
422 void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
424 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
428 struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
430 struct sta_info *sta;
432 sta = ap_get_sta(hapd, addr);
436 wpa_printf(MSG_DEBUG, " New STA");
437 if (hapd->num_sta >= hapd->conf->max_num_sta) {
438 /* FIX: might try to remove some old STAs first? */
439 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
440 hapd->num_sta, hapd->conf->max_num_sta);
444 sta = os_zalloc(sizeof(struct sta_info));
446 wpa_printf(MSG_ERROR, "malloc failed");
449 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
451 /* initialize STA info data */
452 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
453 ap_handle_timer, hapd, sta);
454 os_memcpy(sta->addr, addr, ETH_ALEN);
455 sta->next = hapd->sta_list;
456 hapd->sta_list = sta;
458 ap_sta_hash_add(hapd, sta);
459 sta->ssid = &hapd->conf->ssid;
460 ap_sta_remove_in_other_bss(hapd, sta);
466 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
468 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
470 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
472 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
473 sta->flags & WLAN_STA_ASSOC) {
474 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
475 " from kernel driver.", MAC2STR(sta->addr));
482 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
483 struct sta_info *sta)
485 struct hostapd_iface *iface = hapd->iface;
488 for (i = 0; i < iface->num_bss; i++) {
489 struct hostapd_data *bss = iface->bss[i];
490 struct sta_info *sta2;
491 /* bss should always be set during operation, but it may be
492 * NULL during reconfiguration. Assume the STA is not
493 * associated to another BSS in that case to avoid NULL pointer
495 if (bss == hapd || bss == NULL)
497 sta2 = ap_get_sta(bss, sta->addr);
501 ap_sta_disconnect(bss, sta2, sta2->addr,
502 WLAN_REASON_PREV_AUTH_NOT_VALID);
507 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
509 struct hostapd_data *hapd = eloop_ctx;
510 struct sta_info *sta = timeout_ctx;
512 ap_sta_remove(hapd, sta);
513 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
517 void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
520 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
521 hapd->conf->iface, MAC2STR(sta->addr));
522 sta->flags &= ~WLAN_STA_ASSOC;
523 ap_sta_set_authorized(hapd, sta, 0);
524 sta->timeout_next = STA_DEAUTH;
525 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
526 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
527 ap_handle_timer, hapd, sta);
528 accounting_sta_stop(hapd, sta);
529 ieee802_1x_free_station(sta);
531 sta->disassoc_reason = reason;
532 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
533 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
534 eloop_register_timeout(hapd->iface->drv_flags &
535 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
536 ap_sta_disassoc_cb_timeout, hapd, sta);
540 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
542 struct hostapd_data *hapd = eloop_ctx;
543 struct sta_info *sta = timeout_ctx;
545 ap_sta_remove(hapd, sta);
546 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
550 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
553 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
554 hapd->conf->iface, MAC2STR(sta->addr));
555 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
556 ap_sta_set_authorized(hapd, sta, 0);
557 sta->timeout_next = STA_REMOVE;
558 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
559 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
560 ap_handle_timer, hapd, sta);
561 accounting_sta_stop(hapd, sta);
562 ieee802_1x_free_station(sta);
564 sta->deauth_reason = reason;
565 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
566 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
567 eloop_register_timeout(hapd->iface->drv_flags &
568 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
569 ap_sta_deauth_cb_timeout, hapd, sta);
573 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
576 #ifndef CONFIG_NO_VLAN
578 struct hostapd_vlan *vlan = NULL;
582 * Do not proceed furthur if the vlan id remains same. We do not want
583 * duplicate dynamic vlan entries.
585 if (sta->vlan_id == old_vlanid)
589 * During 1x reauth, if the vlan id changes, then remove the old id and
590 * proceed furthur to add the new one.
593 vlan_remove_dynamic(hapd, old_vlanid);
595 iface = hapd->conf->iface;
596 if (sta->ssid->vlan[0])
597 iface = sta->ssid->vlan;
599 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
601 else if (sta->vlan_id > 0) {
602 vlan = hapd->conf->vlan;
604 if (vlan->vlan_id == sta->vlan_id ||
605 vlan->vlan_id == VLAN_ID_WILDCARD) {
606 iface = vlan->ifname;
613 if (sta->vlan_id > 0 && vlan == NULL) {
614 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
615 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
616 "binding station to (vlan_id=%d)",
619 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
620 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
622 hostapd_logger(hapd, sta->addr,
623 HOSTAPD_MODULE_IEEE80211,
624 HOSTAPD_LEVEL_DEBUG, "could not add "
625 "dynamic VLAN interface for vlan_id=%d",
630 iface = vlan->ifname;
631 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
632 hostapd_logger(hapd, sta->addr,
633 HOSTAPD_MODULE_IEEE80211,
634 HOSTAPD_LEVEL_DEBUG, "could not "
635 "configure encryption for dynamic VLAN "
636 "interface for vlan_id=%d",
640 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
641 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
642 "interface '%s'", iface);
643 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
644 if (sta->vlan_id > 0) {
645 vlan->dynamic_vlan++;
646 hostapd_logger(hapd, sta->addr,
647 HOSTAPD_MODULE_IEEE80211,
648 HOSTAPD_LEVEL_DEBUG, "updated existing "
649 "dynamic VLAN interface '%s'", iface);
653 * Update encryption configuration for statically generated
654 * VLAN interface. This is only used for static WEP
655 * configuration for the case where hostapd did not yet know
656 * which keys are to be used when the interface was added.
658 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
659 hostapd_logger(hapd, sta->addr,
660 HOSTAPD_MODULE_IEEE80211,
661 HOSTAPD_LEVEL_DEBUG, "could not "
662 "configure encryption for VLAN "
663 "interface for vlan_id=%d",
668 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
669 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
672 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
673 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
675 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
677 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
678 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
679 "entry to vlan_id=%d", sta->vlan_id);
682 #else /* CONFIG_NO_VLAN */
684 #endif /* CONFIG_NO_VLAN */
688 #ifdef CONFIG_IEEE80211W
690 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
693 struct os_time now, passed;
695 os_time_sub(&now, &sta->sa_query_start, &passed);
696 tu = (passed.sec * 1000000 + passed.usec) / 1024;
697 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
698 hostapd_logger(hapd, sta->addr,
699 HOSTAPD_MODULE_IEEE80211,
701 "association SA Query timed out");
702 sta->sa_query_timed_out = 1;
703 os_free(sta->sa_query_trans_id);
704 sta->sa_query_trans_id = NULL;
705 sta->sa_query_count = 0;
706 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
714 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
716 struct hostapd_data *hapd = eloop_ctx;
717 struct sta_info *sta = timeout_ctx;
718 unsigned int timeout, sec, usec;
721 if (sta->sa_query_count > 0 &&
722 ap_check_sa_query_timeout(hapd, sta))
725 nbuf = os_realloc(sta->sa_query_trans_id,
726 (sta->sa_query_count + 1) * WLAN_SA_QUERY_TR_ID_LEN);
729 if (sta->sa_query_count == 0) {
730 /* Starting a new SA Query procedure */
731 os_get_time(&sta->sa_query_start);
733 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
734 sta->sa_query_trans_id = nbuf;
735 sta->sa_query_count++;
737 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
739 timeout = hapd->conf->assoc_sa_query_retry_timeout;
740 sec = ((timeout / 1000) * 1024) / 1000;
741 usec = (timeout % 1000) * 1024;
742 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
744 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
746 "association SA Query attempt %d", sta->sa_query_count);
749 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
750 #endif /* NEED_AP_MLME */
754 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
756 ap_sa_query_timer(hapd, sta);
760 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
762 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
763 os_free(sta->sa_query_trans_id);
764 sta->sa_query_trans_id = NULL;
765 sta->sa_query_count = 0;
768 #endif /* CONFIG_IEEE80211W */
771 void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
774 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
778 const u8 *dev_addr = NULL;
780 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
781 #endif /* CONFIG_P2P */
783 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
784 MACSTR " dev_addr=" MACSTR,
785 MAC2STR(sta->addr), MAC2STR(dev_addr));
787 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
788 MACSTR, MAC2STR(sta->addr));
790 sta->flags |= WLAN_STA_AUTHORIZED;
792 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED MACSTR,
794 sta->flags &= ~WLAN_STA_AUTHORIZED;
797 if (hapd->sta_authorized_cb)
798 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
799 sta->addr, authorized);
803 void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
804 const u8 *addr, u16 reason)
807 if (sta == NULL && addr)
808 sta = ap_get_sta(hapd, addr);
811 hostapd_drv_sta_deauth(hapd, addr, reason);
815 ap_sta_set_authorized(hapd, sta, 0);
816 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
817 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
818 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
819 ap_handle_timer, hapd, sta);
820 sta->timeout_next = STA_REMOVE;
822 sta->deauth_reason = reason;
823 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
824 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
825 eloop_register_timeout(hapd->iface->drv_flags &
826 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
827 ap_sta_deauth_cb_timeout, hapd, sta);
831 void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
833 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
834 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
837 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
838 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
839 ap_sta_deauth_cb_timeout(hapd, sta);
843 void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
845 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
846 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
849 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
850 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
851 ap_sta_disassoc_cb_timeout(hapd, sta);