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 rom kernel driver for "
288 MACSTR, MAC2STR(sta->addr));
289 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
290 sta->flags & WLAN_STA_ASSOC) {
291 /* station activity detected; reset timeout state */
292 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
293 "Station " MACSTR " has been active %is ago",
294 MAC2STR(sta->addr), inactive_sec);
295 sta->timeout_next = STA_NULLFUNC;
296 next_time = hapd->conf->ap_max_inactivity -
299 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
300 "Station " MACSTR " has been "
301 "inactive too long: %d sec, max allowed: %d",
302 MAC2STR(sta->addr), inactive_sec,
303 hapd->conf->ap_max_inactivity);
307 if ((sta->flags & WLAN_STA_ASSOC) &&
308 sta->timeout_next == STA_DISASSOC &&
309 !(sta->flags & WLAN_STA_PENDING_POLL)) {
310 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
311 " has ACKed data poll", MAC2STR(sta->addr));
312 /* data nullfunc frame poll did not produce TX errors; assume
313 * station ACKed it */
314 sta->timeout_next = STA_NULLFUNC;
315 next_time = hapd->conf->ap_max_inactivity;
319 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
324 if (sta->timeout_next == STA_NULLFUNC &&
325 (sta->flags & WLAN_STA_ASSOC)) {
326 wpa_printf(MSG_DEBUG, " Polling STA");
327 sta->flags |= WLAN_STA_PENDING_POLL;
328 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
329 sta->flags & WLAN_STA_WMM);
330 } else if (sta->timeout_next != STA_REMOVE) {
331 int deauth = sta->timeout_next == STA_DEAUTH;
333 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
334 "Timeout, sending %s info to STA " MACSTR,
335 deauth ? "deauthentication" : "disassociation",
339 hostapd_drv_sta_deauth(
341 WLAN_REASON_PREV_AUTH_NOT_VALID);
343 hostapd_drv_sta_disassoc(
345 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
349 switch (sta->timeout_next) {
351 sta->timeout_next = STA_DISASSOC;
352 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
356 ap_sta_set_authorized(hapd, sta, 0);
357 sta->flags &= ~WLAN_STA_ASSOC;
358 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
359 if (!sta->acct_terminate_cause)
360 sta->acct_terminate_cause =
361 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
362 accounting_sta_stop(hapd, sta);
363 ieee802_1x_free_station(sta);
364 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
365 HOSTAPD_LEVEL_INFO, "disassociated due to "
367 sta->timeout_next = STA_DEAUTH;
368 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
370 mlme_disassociate_indication(
371 hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
375 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
376 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
377 "inactivity (timer DEAUTH/REMOVE)");
378 if (!sta->acct_terminate_cause)
379 sta->acct_terminate_cause =
380 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
381 mlme_deauthenticate_indication(
383 WLAN_REASON_PREV_AUTH_NOT_VALID);
384 ap_free_sta(hapd, sta);
390 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
392 struct hostapd_data *hapd = eloop_ctx;
393 struct sta_info *sta = timeout_ctx;
396 if (!(sta->flags & WLAN_STA_AUTH))
399 mlme_deauthenticate_indication(hapd, sta,
400 WLAN_REASON_PREV_AUTH_NOT_VALID);
401 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
402 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
404 sta->acct_terminate_cause =
405 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
406 os_memcpy(addr, sta->addr, ETH_ALEN);
407 ap_free_sta(hapd, sta);
408 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
412 void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
415 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
416 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
417 "seconds", session_timeout);
418 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
419 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
424 void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
426 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
430 struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
432 struct sta_info *sta;
434 sta = ap_get_sta(hapd, addr);
438 wpa_printf(MSG_DEBUG, " New STA");
439 if (hapd->num_sta >= hapd->conf->max_num_sta) {
440 /* FIX: might try to remove some old STAs first? */
441 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
442 hapd->num_sta, hapd->conf->max_num_sta);
446 sta = os_zalloc(sizeof(struct sta_info));
448 wpa_printf(MSG_ERROR, "malloc failed");
451 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
453 /* initialize STA info data */
454 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
455 ap_handle_timer, hapd, sta);
456 os_memcpy(sta->addr, addr, ETH_ALEN);
457 sta->next = hapd->sta_list;
458 hapd->sta_list = sta;
460 ap_sta_hash_add(hapd, sta);
461 sta->ssid = &hapd->conf->ssid;
462 ap_sta_remove_in_other_bss(hapd, sta);
468 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
470 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
472 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
474 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
475 sta->flags & WLAN_STA_ASSOC) {
476 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
477 " from kernel driver.", MAC2STR(sta->addr));
484 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
485 struct sta_info *sta)
487 struct hostapd_iface *iface = hapd->iface;
490 for (i = 0; i < iface->num_bss; i++) {
491 struct hostapd_data *bss = iface->bss[i];
492 struct sta_info *sta2;
493 /* bss should always be set during operation, but it may be
494 * NULL during reconfiguration. Assume the STA is not
495 * associated to another BSS in that case to avoid NULL pointer
497 if (bss == hapd || bss == NULL)
499 sta2 = ap_get_sta(bss, sta->addr);
503 ap_sta_disconnect(bss, sta2, sta2->addr,
504 WLAN_REASON_PREV_AUTH_NOT_VALID);
509 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
511 struct hostapd_data *hapd = eloop_ctx;
512 struct sta_info *sta = timeout_ctx;
514 ap_sta_remove(hapd, sta);
515 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
519 void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
522 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
523 hapd->conf->iface, MAC2STR(sta->addr));
524 sta->flags &= ~WLAN_STA_ASSOC;
525 ap_sta_set_authorized(hapd, sta, 0);
526 sta->timeout_next = STA_DEAUTH;
527 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
528 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
529 ap_handle_timer, hapd, sta);
530 accounting_sta_stop(hapd, sta);
531 ieee802_1x_free_station(sta);
533 sta->disassoc_reason = reason;
534 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
535 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
536 eloop_register_timeout(hapd->iface->drv_flags &
537 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
538 ap_sta_disassoc_cb_timeout, hapd, sta);
542 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
544 struct hostapd_data *hapd = eloop_ctx;
545 struct sta_info *sta = timeout_ctx;
547 ap_sta_remove(hapd, sta);
548 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
552 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
555 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
556 hapd->conf->iface, MAC2STR(sta->addr));
557 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
558 ap_sta_set_authorized(hapd, sta, 0);
559 sta->timeout_next = STA_REMOVE;
560 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
561 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
562 ap_handle_timer, hapd, sta);
563 accounting_sta_stop(hapd, sta);
564 ieee802_1x_free_station(sta);
566 sta->deauth_reason = reason;
567 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
568 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
569 eloop_register_timeout(hapd->iface->drv_flags &
570 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
571 ap_sta_deauth_cb_timeout, hapd, sta);
575 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
578 #ifndef CONFIG_NO_VLAN
580 struct hostapd_vlan *vlan = NULL;
584 * Do not proceed furthur if the vlan id remains same. We do not want
585 * duplicate dynamic vlan entries.
587 if (sta->vlan_id == old_vlanid)
591 * During 1x reauth, if the vlan id changes, then remove the old id and
592 * proceed furthur to add the new one.
595 vlan_remove_dynamic(hapd, old_vlanid);
597 iface = hapd->conf->iface;
598 if (sta->ssid->vlan[0])
599 iface = sta->ssid->vlan;
601 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
603 else if (sta->vlan_id > 0) {
604 vlan = hapd->conf->vlan;
606 if (vlan->vlan_id == sta->vlan_id ||
607 vlan->vlan_id == VLAN_ID_WILDCARD) {
608 iface = vlan->ifname;
615 if (sta->vlan_id > 0 && vlan == NULL) {
616 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
617 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
618 "binding station to (vlan_id=%d)",
621 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
622 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
624 hostapd_logger(hapd, sta->addr,
625 HOSTAPD_MODULE_IEEE80211,
626 HOSTAPD_LEVEL_DEBUG, "could not add "
627 "dynamic VLAN interface for vlan_id=%d",
632 iface = vlan->ifname;
633 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
634 hostapd_logger(hapd, sta->addr,
635 HOSTAPD_MODULE_IEEE80211,
636 HOSTAPD_LEVEL_DEBUG, "could not "
637 "configure encryption for dynamic VLAN "
638 "interface for vlan_id=%d",
642 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
643 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
644 "interface '%s'", iface);
645 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
646 if (sta->vlan_id > 0) {
647 vlan->dynamic_vlan++;
648 hostapd_logger(hapd, sta->addr,
649 HOSTAPD_MODULE_IEEE80211,
650 HOSTAPD_LEVEL_DEBUG, "updated existing "
651 "dynamic VLAN interface '%s'", iface);
655 * Update encryption configuration for statically generated
656 * VLAN interface. This is only used for static WEP
657 * configuration for the case where hostapd did not yet know
658 * which keys are to be used when the interface was added.
660 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
661 hostapd_logger(hapd, sta->addr,
662 HOSTAPD_MODULE_IEEE80211,
663 HOSTAPD_LEVEL_DEBUG, "could not "
664 "configure encryption for VLAN "
665 "interface for vlan_id=%d",
670 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
671 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
674 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
675 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
677 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
679 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
680 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
681 "entry to vlan_id=%d", sta->vlan_id);
684 #else /* CONFIG_NO_VLAN */
686 #endif /* CONFIG_NO_VLAN */
690 #ifdef CONFIG_IEEE80211W
692 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
695 struct os_time now, passed;
697 os_time_sub(&now, &sta->sa_query_start, &passed);
698 tu = (passed.sec * 1000000 + passed.usec) / 1024;
699 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
700 hostapd_logger(hapd, sta->addr,
701 HOSTAPD_MODULE_IEEE80211,
703 "association SA Query timed out");
704 sta->sa_query_timed_out = 1;
705 os_free(sta->sa_query_trans_id);
706 sta->sa_query_trans_id = NULL;
707 sta->sa_query_count = 0;
708 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
716 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
718 struct hostapd_data *hapd = eloop_ctx;
719 struct sta_info *sta = timeout_ctx;
720 unsigned int timeout, sec, usec;
723 if (sta->sa_query_count > 0 &&
724 ap_check_sa_query_timeout(hapd, sta))
727 nbuf = os_realloc(sta->sa_query_trans_id,
728 (sta->sa_query_count + 1) * WLAN_SA_QUERY_TR_ID_LEN);
731 if (sta->sa_query_count == 0) {
732 /* Starting a new SA Query procedure */
733 os_get_time(&sta->sa_query_start);
735 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
736 sta->sa_query_trans_id = nbuf;
737 sta->sa_query_count++;
739 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
741 timeout = hapd->conf->assoc_sa_query_retry_timeout;
742 sec = ((timeout / 1000) * 1024) / 1000;
743 usec = (timeout % 1000) * 1024;
744 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
746 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
748 "association SA Query attempt %d", sta->sa_query_count);
751 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
752 #endif /* NEED_AP_MLME */
756 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
758 ap_sa_query_timer(hapd, sta);
762 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
764 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
765 os_free(sta->sa_query_trans_id);
766 sta->sa_query_trans_id = NULL;
767 sta->sa_query_count = 0;
770 #endif /* CONFIG_IEEE80211W */
773 void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
776 const u8 *dev_addr = NULL;
777 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
781 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
782 #endif /* CONFIG_P2P */
786 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
787 MACSTR " p2p_dev_addr=" MACSTR,
788 MAC2STR(sta->addr), MAC2STR(dev_addr));
790 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
791 MACSTR, MAC2STR(sta->addr));
792 if (hapd->msg_ctx_parent &&
793 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
794 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
795 AP_STA_CONNECTED MACSTR " p2p_dev_addr="
797 MAC2STR(sta->addr), MAC2STR(dev_addr));
798 else if (hapd->msg_ctx_parent &&
799 hapd->msg_ctx_parent != hapd->msg_ctx)
800 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
801 AP_STA_CONNECTED MACSTR, MAC2STR(sta->addr));
803 sta->flags |= WLAN_STA_AUTHORIZED;
806 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
807 MACSTR " p2p_dev_addr=" MACSTR,
808 MAC2STR(sta->addr), MAC2STR(dev_addr));
810 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
811 MACSTR, MAC2STR(sta->addr));
812 if (hapd->msg_ctx_parent &&
813 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
814 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
815 AP_STA_DISCONNECTED MACSTR " p2p_dev_addr="
816 MACSTR, MAC2STR(sta->addr), MAC2STR(dev_addr));
817 else if (hapd->msg_ctx_parent &&
818 hapd->msg_ctx_parent != hapd->msg_ctx)
819 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
820 AP_STA_DISCONNECTED MACSTR,
822 sta->flags &= ~WLAN_STA_AUTHORIZED;
825 if (hapd->sta_authorized_cb)
826 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
827 sta->addr, authorized, dev_addr);
831 void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
832 const u8 *addr, u16 reason)
835 if (sta == NULL && addr)
836 sta = ap_get_sta(hapd, addr);
839 hostapd_drv_sta_deauth(hapd, addr, reason);
843 ap_sta_set_authorized(hapd, sta, 0);
844 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
845 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
846 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
847 ap_handle_timer, hapd, sta);
848 sta->timeout_next = STA_REMOVE;
850 sta->deauth_reason = reason;
851 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
852 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
853 eloop_register_timeout(hapd->iface->drv_flags &
854 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
855 ap_sta_deauth_cb_timeout, hapd, sta);
859 void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
861 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
862 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
865 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
866 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
867 ap_sta_deauth_cb_timeout(hapd, sta);
871 void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
873 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
874 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
877 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
878 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
879 ap_sta_disassoc_cb_timeout(hapd, sta);