2 * hostapd / Station table
3 * Copyright (c) 2002-2011, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
14 #include "common/wpa_ctrl.h"
15 #include "radius/radius.h"
16 #include "radius/radius_client.h"
17 #include "drivers/driver.h"
20 #include "accounting.h"
21 #include "ieee802_1x.h"
22 #include "ieee802_11.h"
24 #include "preauth_auth.h"
25 #include "ap_config.h"
28 #include "vlan_init.h"
29 #include "p2p_hostapd.h"
30 #include "ap_drv_ops.h"
34 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
35 struct sta_info *sta);
36 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
37 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
38 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
39 #ifdef CONFIG_IEEE80211W
40 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
41 #endif /* CONFIG_IEEE80211W */
42 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
44 int ap_for_each_sta(struct hostapd_data *hapd,
45 int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
51 for (sta = hapd->sta_list; sta; sta = sta->next) {
52 if (cb(hapd, sta, ctx))
60 struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
64 s = hapd->sta_hash[STA_HASH(sta)];
65 while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
71 static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
75 if (hapd->sta_list == sta) {
76 hapd->sta_list = sta->next;
81 while (tmp != NULL && tmp->next != sta)
84 wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
85 "list.", MAC2STR(sta->addr));
87 tmp->next = sta->next;
91 void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
93 sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
94 hapd->sta_hash[STA_HASH(sta->addr)] = sta;
98 static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
102 s = hapd->sta_hash[STA_HASH(sta->addr)];
103 if (s == NULL) return;
104 if (os_memcmp(s->addr, sta->addr, 6) == 0) {
105 hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
109 while (s->hnext != NULL &&
110 os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
112 if (s->hnext != NULL)
113 s->hnext = s->hnext->hnext;
115 wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
116 " from hash table", MAC2STR(sta->addr));
120 void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
124 accounting_sta_stop(hapd, sta);
127 ap_sta_set_authorized(hapd, sta, 0);
129 if (sta->flags & WLAN_STA_WDS)
130 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 0);
132 if (!(sta->flags & WLAN_STA_PREAUTH))
133 hostapd_drv_sta_remove(hapd, sta->addr);
135 ap_sta_hash_del(hapd, sta);
136 ap_sta_list_del(hapd, sta);
139 hapd->sta_aid[(sta->aid - 1) / 32] &=
140 ~BIT((sta->aid - 1) % 32);
143 if (sta->nonerp_set) {
145 hapd->iface->num_sta_non_erp--;
146 if (hapd->iface->num_sta_non_erp == 0)
150 if (sta->no_short_slot_time_set) {
151 sta->no_short_slot_time_set = 0;
152 hapd->iface->num_sta_no_short_slot_time--;
153 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
154 && hapd->iface->num_sta_no_short_slot_time == 0)
158 if (sta->no_short_preamble_set) {
159 sta->no_short_preamble_set = 0;
160 hapd->iface->num_sta_no_short_preamble--;
161 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
162 && hapd->iface->num_sta_no_short_preamble == 0)
166 if (sta->no_ht_gf_set) {
167 sta->no_ht_gf_set = 0;
168 hapd->iface->num_sta_ht_no_gf--;
171 if (sta->no_ht_set) {
173 hapd->iface->num_sta_no_ht--;
176 if (sta->ht_20mhz_set) {
177 sta->ht_20mhz_set = 0;
178 hapd->iface->num_sta_ht_20mhz--;
182 if (sta->no_p2p_set) {
184 hapd->num_sta_no_p2p--;
185 if (hapd->num_sta_no_p2p == 0)
186 hostapd_p2p_non_p2p_sta_disconnected(hapd);
188 #endif /* CONFIG_P2P */
190 #if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
191 if (hostapd_ht_operation_update(hapd->iface) > 0)
193 #endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
196 ieee802_11_set_beacons(hapd->iface);
198 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
199 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
200 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
201 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
203 ieee802_1x_free_station(sta);
204 wpa_auth_sta_deinit(sta->wpa_sm);
205 rsn_preauth_free_station(hapd, sta);
206 #ifndef CONFIG_NO_RADIUS
207 radius_client_flush_auth(hapd->radius, sta->addr);
208 #endif /* CONFIG_NO_RADIUS */
210 os_free(sta->last_assoc_req);
211 os_free(sta->challenge);
213 #ifdef CONFIG_IEEE80211W
214 os_free(sta->sa_query_trans_id);
215 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
216 #endif /* CONFIG_IEEE80211W */
219 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
220 #endif /* CONFIG_P2P */
222 #ifdef CONFIG_INTERWORKING
223 if (sta->gas_dialog) {
225 for (i = 0; i < GAS_DIALOG_MAX; i++)
226 gas_serv_dialog_clear(&sta->gas_dialog[i]);
227 os_free(sta->gas_dialog);
229 #endif /* CONFIG_INTERWORKING */
231 wpabuf_free(sta->wps_ie);
232 wpabuf_free(sta->p2p_ie);
234 os_free(sta->ht_capabilities);
241 void hostapd_free_stas(struct hostapd_data *hapd)
243 struct sta_info *sta, *prev;
245 sta = hapd->sta_list;
249 if (sta->flags & WLAN_STA_AUTH) {
250 mlme_deauthenticate_indication(
251 hapd, sta, WLAN_REASON_UNSPECIFIED);
254 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
255 MAC2STR(prev->addr));
256 ap_free_sta(hapd, prev);
262 * ap_handle_timer - Per STA timer handler
263 * @eloop_ctx: struct hostapd_data *
264 * @timeout_ctx: struct sta_info *
266 * This function is called to check station activity and to remove inactive
269 void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
271 struct hostapd_data *hapd = eloop_ctx;
272 struct sta_info *sta = timeout_ctx;
273 unsigned long next_time = 0;
275 if (sta->timeout_next == STA_REMOVE) {
276 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
277 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
278 "local deauth request");
279 ap_free_sta(hapd, sta);
283 if ((sta->flags & WLAN_STA_ASSOC) &&
284 (sta->timeout_next == STA_NULLFUNC ||
285 sta->timeout_next == STA_DISASSOC)) {
287 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
288 if (inactive_sec == -1) {
289 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
290 "Check inactivity: Could not "
291 "get station info from kernel driver for "
292 MACSTR, MAC2STR(sta->addr));
294 * The driver may not support this functionality.
295 * Anyway, try again after the next inactivity timeout,
296 * but do not disconnect the station now.
298 next_time = hapd->conf->ap_max_inactivity;
299 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
300 sta->flags & WLAN_STA_ASSOC) {
301 /* station activity detected; reset timeout state */
302 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
303 "Station " MACSTR " has been active %is ago",
304 MAC2STR(sta->addr), inactive_sec);
305 sta->timeout_next = STA_NULLFUNC;
306 next_time = hapd->conf->ap_max_inactivity -
309 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
310 "Station " MACSTR " has been "
311 "inactive too long: %d sec, max allowed: %d",
312 MAC2STR(sta->addr), inactive_sec,
313 hapd->conf->ap_max_inactivity);
315 if (hapd->conf->skip_inactivity_poll)
316 sta->timeout_next = STA_DISASSOC;
320 if ((sta->flags & WLAN_STA_ASSOC) &&
321 sta->timeout_next == STA_DISASSOC &&
322 !(sta->flags & WLAN_STA_PENDING_POLL) &&
323 !hapd->conf->skip_inactivity_poll) {
324 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
325 " has ACKed data poll", MAC2STR(sta->addr));
326 /* data nullfunc frame poll did not produce TX errors; assume
327 * station ACKed it */
328 sta->timeout_next = STA_NULLFUNC;
329 next_time = hapd->conf->ap_max_inactivity;
333 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
338 if (sta->timeout_next == STA_NULLFUNC &&
339 (sta->flags & WLAN_STA_ASSOC)) {
340 wpa_printf(MSG_DEBUG, " Polling STA");
341 sta->flags |= WLAN_STA_PENDING_POLL;
342 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
343 sta->flags & WLAN_STA_WMM);
344 } else if (sta->timeout_next != STA_REMOVE) {
345 int deauth = sta->timeout_next == STA_DEAUTH;
347 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
348 "Timeout, sending %s info to STA " MACSTR,
349 deauth ? "deauthentication" : "disassociation",
353 hostapd_drv_sta_deauth(
355 WLAN_REASON_PREV_AUTH_NOT_VALID);
357 hostapd_drv_sta_disassoc(
359 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
363 switch (sta->timeout_next) {
365 sta->timeout_next = STA_DISASSOC;
366 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
370 ap_sta_set_authorized(hapd, sta, 0);
371 sta->flags &= ~WLAN_STA_ASSOC;
372 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
373 if (!sta->acct_terminate_cause)
374 sta->acct_terminate_cause =
375 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
376 accounting_sta_stop(hapd, sta);
377 ieee802_1x_free_station(sta);
378 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
379 HOSTAPD_LEVEL_INFO, "disassociated due to "
381 sta->timeout_next = STA_DEAUTH;
382 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
384 mlme_disassociate_indication(
385 hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
389 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
390 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
391 "inactivity (timer DEAUTH/REMOVE)");
392 if (!sta->acct_terminate_cause)
393 sta->acct_terminate_cause =
394 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
395 mlme_deauthenticate_indication(
397 WLAN_REASON_PREV_AUTH_NOT_VALID);
398 ap_free_sta(hapd, sta);
404 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
406 struct hostapd_data *hapd = eloop_ctx;
407 struct sta_info *sta = timeout_ctx;
410 if (!(sta->flags & WLAN_STA_AUTH)) {
411 if (sta->flags & WLAN_STA_GAS) {
412 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
413 "entry " MACSTR, MAC2STR(sta->addr));
414 ap_free_sta(hapd, sta);
419 mlme_deauthenticate_indication(hapd, sta,
420 WLAN_REASON_PREV_AUTH_NOT_VALID);
421 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
422 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
424 sta->acct_terminate_cause =
425 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
426 os_memcpy(addr, sta->addr, ETH_ALEN);
427 ap_free_sta(hapd, sta);
428 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
432 void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
435 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
436 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
437 "seconds", session_timeout);
438 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
439 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
444 void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
446 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
450 struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
452 struct sta_info *sta;
454 sta = ap_get_sta(hapd, addr);
458 wpa_printf(MSG_DEBUG, " New STA");
459 if (hapd->num_sta >= hapd->conf->max_num_sta) {
460 /* FIX: might try to remove some old STAs first? */
461 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
462 hapd->num_sta, hapd->conf->max_num_sta);
466 sta = os_zalloc(sizeof(struct sta_info));
468 wpa_printf(MSG_ERROR, "malloc failed");
471 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
473 /* initialize STA info data */
474 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
475 ap_handle_timer, hapd, sta);
476 os_memcpy(sta->addr, addr, ETH_ALEN);
477 sta->next = hapd->sta_list;
478 hapd->sta_list = sta;
480 ap_sta_hash_add(hapd, sta);
481 sta->ssid = &hapd->conf->ssid;
482 ap_sta_remove_in_other_bss(hapd, sta);
488 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
490 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
492 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
494 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
495 sta->flags & WLAN_STA_ASSOC) {
496 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
497 " from kernel driver.", MAC2STR(sta->addr));
504 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
505 struct sta_info *sta)
507 struct hostapd_iface *iface = hapd->iface;
510 for (i = 0; i < iface->num_bss; i++) {
511 struct hostapd_data *bss = iface->bss[i];
512 struct sta_info *sta2;
513 /* bss should always be set during operation, but it may be
514 * NULL during reconfiguration. Assume the STA is not
515 * associated to another BSS in that case to avoid NULL pointer
517 if (bss == hapd || bss == NULL)
519 sta2 = ap_get_sta(bss, sta->addr);
523 ap_sta_disconnect(bss, sta2, sta2->addr,
524 WLAN_REASON_PREV_AUTH_NOT_VALID);
529 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
531 struct hostapd_data *hapd = eloop_ctx;
532 struct sta_info *sta = timeout_ctx;
534 ap_sta_remove(hapd, sta);
535 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
539 void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
542 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
543 hapd->conf->iface, MAC2STR(sta->addr));
544 sta->flags &= ~WLAN_STA_ASSOC;
545 ap_sta_set_authorized(hapd, sta, 0);
546 sta->timeout_next = STA_DEAUTH;
547 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
548 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
549 ap_handle_timer, hapd, sta);
550 accounting_sta_stop(hapd, sta);
551 ieee802_1x_free_station(sta);
553 sta->disassoc_reason = reason;
554 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
555 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
556 eloop_register_timeout(hapd->iface->drv_flags &
557 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
558 ap_sta_disassoc_cb_timeout, hapd, sta);
562 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
564 struct hostapd_data *hapd = eloop_ctx;
565 struct sta_info *sta = timeout_ctx;
567 ap_sta_remove(hapd, sta);
568 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
572 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
575 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
576 hapd->conf->iface, MAC2STR(sta->addr));
577 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
578 ap_sta_set_authorized(hapd, sta, 0);
579 sta->timeout_next = STA_REMOVE;
580 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
581 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
582 ap_handle_timer, hapd, sta);
583 accounting_sta_stop(hapd, sta);
584 ieee802_1x_free_station(sta);
586 sta->deauth_reason = reason;
587 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
588 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
589 eloop_register_timeout(hapd->iface->drv_flags &
590 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
591 ap_sta_deauth_cb_timeout, hapd, sta);
595 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
598 #ifndef CONFIG_NO_VLAN
600 struct hostapd_vlan *vlan = NULL;
604 * Do not proceed furthur if the vlan id remains same. We do not want
605 * duplicate dynamic vlan entries.
607 if (sta->vlan_id == old_vlanid)
611 * During 1x reauth, if the vlan id changes, then remove the old id and
612 * proceed furthur to add the new one.
615 vlan_remove_dynamic(hapd, old_vlanid);
617 iface = hapd->conf->iface;
618 if (sta->ssid->vlan[0])
619 iface = sta->ssid->vlan;
621 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
623 else if (sta->vlan_id > 0) {
624 vlan = hapd->conf->vlan;
626 if (vlan->vlan_id == sta->vlan_id ||
627 vlan->vlan_id == VLAN_ID_WILDCARD) {
628 iface = vlan->ifname;
635 if (sta->vlan_id > 0 && vlan == NULL) {
636 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
637 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
638 "binding station to (vlan_id=%d)",
641 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
642 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
644 hostapd_logger(hapd, sta->addr,
645 HOSTAPD_MODULE_IEEE80211,
646 HOSTAPD_LEVEL_DEBUG, "could not add "
647 "dynamic VLAN interface for vlan_id=%d",
652 iface = vlan->ifname;
653 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
654 hostapd_logger(hapd, sta->addr,
655 HOSTAPD_MODULE_IEEE80211,
656 HOSTAPD_LEVEL_DEBUG, "could not "
657 "configure encryption for dynamic VLAN "
658 "interface for vlan_id=%d",
662 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
663 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
664 "interface '%s'", iface);
665 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
666 if (sta->vlan_id > 0) {
667 vlan->dynamic_vlan++;
668 hostapd_logger(hapd, sta->addr,
669 HOSTAPD_MODULE_IEEE80211,
670 HOSTAPD_LEVEL_DEBUG, "updated existing "
671 "dynamic VLAN interface '%s'", iface);
675 * Update encryption configuration for statically generated
676 * VLAN interface. This is only used for static WEP
677 * configuration for the case where hostapd did not yet know
678 * which keys are to be used when the interface was added.
680 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
681 hostapd_logger(hapd, sta->addr,
682 HOSTAPD_MODULE_IEEE80211,
683 HOSTAPD_LEVEL_DEBUG, "could not "
684 "configure encryption for VLAN "
685 "interface for vlan_id=%d",
690 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
691 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
694 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
695 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
697 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
699 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
700 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
701 "entry to vlan_id=%d", sta->vlan_id);
704 #else /* CONFIG_NO_VLAN */
706 #endif /* CONFIG_NO_VLAN */
710 #ifdef CONFIG_IEEE80211W
712 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
715 struct os_time now, passed;
717 os_time_sub(&now, &sta->sa_query_start, &passed);
718 tu = (passed.sec * 1000000 + passed.usec) / 1024;
719 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
720 hostapd_logger(hapd, sta->addr,
721 HOSTAPD_MODULE_IEEE80211,
723 "association SA Query timed out");
724 sta->sa_query_timed_out = 1;
725 os_free(sta->sa_query_trans_id);
726 sta->sa_query_trans_id = NULL;
727 sta->sa_query_count = 0;
728 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
736 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
738 struct hostapd_data *hapd = eloop_ctx;
739 struct sta_info *sta = timeout_ctx;
740 unsigned int timeout, sec, usec;
743 if (sta->sa_query_count > 0 &&
744 ap_check_sa_query_timeout(hapd, sta))
747 nbuf = os_realloc(sta->sa_query_trans_id,
748 (sta->sa_query_count + 1) * WLAN_SA_QUERY_TR_ID_LEN);
751 if (sta->sa_query_count == 0) {
752 /* Starting a new SA Query procedure */
753 os_get_time(&sta->sa_query_start);
755 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
756 sta->sa_query_trans_id = nbuf;
757 sta->sa_query_count++;
759 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
761 timeout = hapd->conf->assoc_sa_query_retry_timeout;
762 sec = ((timeout / 1000) * 1024) / 1000;
763 usec = (timeout % 1000) * 1024;
764 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
766 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
768 "association SA Query attempt %d", sta->sa_query_count);
771 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
772 #endif /* NEED_AP_MLME */
776 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
778 ap_sa_query_timer(hapd, sta);
782 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
784 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
785 os_free(sta->sa_query_trans_id);
786 sta->sa_query_trans_id = NULL;
787 sta->sa_query_count = 0;
790 #endif /* CONFIG_IEEE80211W */
793 void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
796 const u8 *dev_addr = NULL;
797 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
801 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
802 #endif /* CONFIG_P2P */
806 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
807 MACSTR " p2p_dev_addr=" MACSTR,
808 MAC2STR(sta->addr), MAC2STR(dev_addr));
810 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
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_CONNECTED MACSTR " p2p_dev_addr="
817 MAC2STR(sta->addr), MAC2STR(dev_addr));
818 else if (hapd->msg_ctx_parent &&
819 hapd->msg_ctx_parent != hapd->msg_ctx)
820 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
821 AP_STA_CONNECTED MACSTR, MAC2STR(sta->addr));
823 sta->flags |= WLAN_STA_AUTHORIZED;
826 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
827 MACSTR " p2p_dev_addr=" MACSTR,
828 MAC2STR(sta->addr), MAC2STR(dev_addr));
830 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
831 MACSTR, MAC2STR(sta->addr));
832 if (hapd->msg_ctx_parent &&
833 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
834 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
835 AP_STA_DISCONNECTED MACSTR " p2p_dev_addr="
836 MACSTR, MAC2STR(sta->addr), MAC2STR(dev_addr));
837 else if (hapd->msg_ctx_parent &&
838 hapd->msg_ctx_parent != hapd->msg_ctx)
839 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
840 AP_STA_DISCONNECTED MACSTR,
842 sta->flags &= ~WLAN_STA_AUTHORIZED;
845 if (hapd->sta_authorized_cb)
846 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
847 sta->addr, authorized, dev_addr);
851 void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
852 const u8 *addr, u16 reason)
855 if (sta == NULL && addr)
856 sta = ap_get_sta(hapd, addr);
859 hostapd_drv_sta_deauth(hapd, addr, reason);
863 ap_sta_set_authorized(hapd, sta, 0);
864 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
865 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
866 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
867 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
868 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
869 ap_handle_timer, hapd, sta);
870 sta->timeout_next = STA_REMOVE;
872 sta->deauth_reason = reason;
873 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
874 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
875 eloop_register_timeout(hapd->iface->drv_flags &
876 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
877 ap_sta_deauth_cb_timeout, hapd, sta);
881 void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
883 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
884 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
887 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
888 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
889 ap_sta_deauth_cb_timeout(hapd, sta);
893 void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
895 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
896 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
899 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
900 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
901 ap_sta_disassoc_cb_timeout(hapd, sta);