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"
33 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
34 struct sta_info *sta);
35 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
36 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
37 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
38 #ifdef CONFIG_IEEE80211W
39 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
40 #endif /* CONFIG_IEEE80211W */
41 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
43 int ap_for_each_sta(struct hostapd_data *hapd,
44 int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
50 for (sta = hapd->sta_list; sta; sta = sta->next) {
51 if (cb(hapd, sta, ctx))
59 struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
63 s = hapd->sta_hash[STA_HASH(sta)];
64 while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
70 static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
74 if (hapd->sta_list == sta) {
75 hapd->sta_list = sta->next;
80 while (tmp != NULL && tmp->next != sta)
83 wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
84 "list.", MAC2STR(sta->addr));
86 tmp->next = sta->next;
90 void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
92 sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
93 hapd->sta_hash[STA_HASH(sta->addr)] = sta;
97 static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
101 s = hapd->sta_hash[STA_HASH(sta->addr)];
102 if (s == NULL) return;
103 if (os_memcmp(s->addr, sta->addr, 6) == 0) {
104 hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
108 while (s->hnext != NULL &&
109 os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
111 if (s->hnext != NULL)
112 s->hnext = s->hnext->hnext;
114 wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
115 " from hash table", MAC2STR(sta->addr));
119 void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
123 accounting_sta_stop(hapd, sta);
126 ap_sta_set_authorized(hapd, sta, 0);
128 if (sta->flags & WLAN_STA_WDS)
129 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 0);
131 if (!(sta->flags & WLAN_STA_PREAUTH))
132 hostapd_drv_sta_remove(hapd, sta->addr);
134 ap_sta_hash_del(hapd, sta);
135 ap_sta_list_del(hapd, sta);
138 hapd->sta_aid[(sta->aid - 1) / 32] &=
139 ~BIT((sta->aid - 1) % 32);
142 if (sta->nonerp_set) {
144 hapd->iface->num_sta_non_erp--;
145 if (hapd->iface->num_sta_non_erp == 0)
149 if (sta->no_short_slot_time_set) {
150 sta->no_short_slot_time_set = 0;
151 hapd->iface->num_sta_no_short_slot_time--;
152 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
153 && hapd->iface->num_sta_no_short_slot_time == 0)
157 if (sta->no_short_preamble_set) {
158 sta->no_short_preamble_set = 0;
159 hapd->iface->num_sta_no_short_preamble--;
160 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
161 && hapd->iface->num_sta_no_short_preamble == 0)
165 if (sta->no_ht_gf_set) {
166 sta->no_ht_gf_set = 0;
167 hapd->iface->num_sta_ht_no_gf--;
170 if (sta->no_ht_set) {
172 hapd->iface->num_sta_no_ht--;
175 if (sta->ht_20mhz_set) {
176 sta->ht_20mhz_set = 0;
177 hapd->iface->num_sta_ht_20mhz--;
181 if (sta->no_p2p_set) {
183 hapd->num_sta_no_p2p--;
184 if (hapd->num_sta_no_p2p == 0)
185 hostapd_p2p_non_p2p_sta_disconnected(hapd);
187 #endif /* CONFIG_P2P */
189 #if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
190 if (hostapd_ht_operation_update(hapd->iface) > 0)
192 #endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
195 ieee802_11_set_beacons(hapd->iface);
197 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
198 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
199 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
200 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
202 ieee802_1x_free_station(sta);
203 wpa_auth_sta_deinit(sta->wpa_sm);
204 rsn_preauth_free_station(hapd, sta);
205 #ifndef CONFIG_NO_RADIUS
206 radius_client_flush_auth(hapd->radius, sta->addr);
207 #endif /* CONFIG_NO_RADIUS */
209 os_free(sta->last_assoc_req);
210 os_free(sta->challenge);
212 #ifdef CONFIG_IEEE80211W
213 os_free(sta->sa_query_trans_id);
214 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
215 #endif /* CONFIG_IEEE80211W */
218 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
219 #endif /* CONFIG_P2P */
221 wpabuf_free(sta->wps_ie);
222 wpabuf_free(sta->p2p_ie);
224 os_free(sta->ht_capabilities);
231 void hostapd_free_stas(struct hostapd_data *hapd)
233 struct sta_info *sta, *prev;
235 sta = hapd->sta_list;
239 if (sta->flags & WLAN_STA_AUTH) {
240 mlme_deauthenticate_indication(
241 hapd, sta, WLAN_REASON_UNSPECIFIED);
244 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
245 MAC2STR(prev->addr));
246 ap_free_sta(hapd, prev);
252 * ap_handle_timer - Per STA timer handler
253 * @eloop_ctx: struct hostapd_data *
254 * @timeout_ctx: struct sta_info *
256 * This function is called to check station activity and to remove inactive
259 void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
261 struct hostapd_data *hapd = eloop_ctx;
262 struct sta_info *sta = timeout_ctx;
263 unsigned long next_time = 0;
265 if (sta->timeout_next == STA_REMOVE) {
266 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
267 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
268 "local deauth request");
269 ap_free_sta(hapd, sta);
273 if ((sta->flags & WLAN_STA_ASSOC) &&
274 (sta->timeout_next == STA_NULLFUNC ||
275 sta->timeout_next == STA_DISASSOC)) {
277 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
278 if (inactive_sec == -1) {
279 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
280 "Check inactivity: Could not "
281 "get station info from kernel driver for "
282 MACSTR, MAC2STR(sta->addr));
284 * The driver may not support this functionality.
285 * Anyway, try again after the next inactivity timeout,
286 * but do not disconnect the station now.
288 next_time = hapd->conf->ap_max_inactivity;
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);
305 if (hapd->conf->skip_inactivity_poll)
306 sta->timeout_next = STA_DISASSOC;
310 if ((sta->flags & WLAN_STA_ASSOC) &&
311 sta->timeout_next == STA_DISASSOC &&
312 !(sta->flags & WLAN_STA_PENDING_POLL) &&
313 !hapd->conf->skip_inactivity_poll) {
314 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
315 " has ACKed data poll", MAC2STR(sta->addr));
316 /* data nullfunc frame poll did not produce TX errors; assume
317 * station ACKed it */
318 sta->timeout_next = STA_NULLFUNC;
319 next_time = hapd->conf->ap_max_inactivity;
323 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
328 if (sta->timeout_next == STA_NULLFUNC &&
329 (sta->flags & WLAN_STA_ASSOC)) {
330 wpa_printf(MSG_DEBUG, " Polling STA");
331 sta->flags |= WLAN_STA_PENDING_POLL;
332 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
333 sta->flags & WLAN_STA_WMM);
334 } else if (sta->timeout_next != STA_REMOVE) {
335 int deauth = sta->timeout_next == STA_DEAUTH;
337 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
338 "Timeout, sending %s info to STA " MACSTR,
339 deauth ? "deauthentication" : "disassociation",
343 hostapd_drv_sta_deauth(
345 WLAN_REASON_PREV_AUTH_NOT_VALID);
347 hostapd_drv_sta_disassoc(
349 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
353 switch (sta->timeout_next) {
355 sta->timeout_next = STA_DISASSOC;
356 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
360 ap_sta_set_authorized(hapd, sta, 0);
361 sta->flags &= ~WLAN_STA_ASSOC;
362 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
363 if (!sta->acct_terminate_cause)
364 sta->acct_terminate_cause =
365 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
366 accounting_sta_stop(hapd, sta);
367 ieee802_1x_free_station(sta);
368 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
369 HOSTAPD_LEVEL_INFO, "disassociated due to "
371 sta->timeout_next = STA_DEAUTH;
372 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
374 mlme_disassociate_indication(
375 hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
379 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
380 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
381 "inactivity (timer DEAUTH/REMOVE)");
382 if (!sta->acct_terminate_cause)
383 sta->acct_terminate_cause =
384 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
385 mlme_deauthenticate_indication(
387 WLAN_REASON_PREV_AUTH_NOT_VALID);
388 ap_free_sta(hapd, sta);
394 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
396 struct hostapd_data *hapd = eloop_ctx;
397 struct sta_info *sta = timeout_ctx;
400 if (!(sta->flags & WLAN_STA_AUTH))
403 mlme_deauthenticate_indication(hapd, sta,
404 WLAN_REASON_PREV_AUTH_NOT_VALID);
405 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
406 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
408 sta->acct_terminate_cause =
409 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
410 os_memcpy(addr, sta->addr, ETH_ALEN);
411 ap_free_sta(hapd, sta);
412 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
416 void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
419 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
420 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
421 "seconds", session_timeout);
422 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
423 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
428 void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
430 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
434 struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
436 struct sta_info *sta;
438 sta = ap_get_sta(hapd, addr);
442 wpa_printf(MSG_DEBUG, " New STA");
443 if (hapd->num_sta >= hapd->conf->max_num_sta) {
444 /* FIX: might try to remove some old STAs first? */
445 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
446 hapd->num_sta, hapd->conf->max_num_sta);
450 sta = os_zalloc(sizeof(struct sta_info));
452 wpa_printf(MSG_ERROR, "malloc failed");
455 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
457 /* initialize STA info data */
458 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
459 ap_handle_timer, hapd, sta);
460 os_memcpy(sta->addr, addr, ETH_ALEN);
461 sta->next = hapd->sta_list;
462 hapd->sta_list = sta;
464 ap_sta_hash_add(hapd, sta);
465 sta->ssid = &hapd->conf->ssid;
466 ap_sta_remove_in_other_bss(hapd, sta);
472 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
474 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
476 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
478 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
479 sta->flags & WLAN_STA_ASSOC) {
480 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
481 " from kernel driver.", MAC2STR(sta->addr));
488 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
489 struct sta_info *sta)
491 struct hostapd_iface *iface = hapd->iface;
494 for (i = 0; i < iface->num_bss; i++) {
495 struct hostapd_data *bss = iface->bss[i];
496 struct sta_info *sta2;
497 /* bss should always be set during operation, but it may be
498 * NULL during reconfiguration. Assume the STA is not
499 * associated to another BSS in that case to avoid NULL pointer
501 if (bss == hapd || bss == NULL)
503 sta2 = ap_get_sta(bss, sta->addr);
507 ap_sta_disconnect(bss, sta2, sta2->addr,
508 WLAN_REASON_PREV_AUTH_NOT_VALID);
513 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
515 struct hostapd_data *hapd = eloop_ctx;
516 struct sta_info *sta = timeout_ctx;
518 ap_sta_remove(hapd, sta);
519 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
523 void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
526 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
527 hapd->conf->iface, MAC2STR(sta->addr));
528 sta->flags &= ~WLAN_STA_ASSOC;
529 ap_sta_set_authorized(hapd, sta, 0);
530 sta->timeout_next = STA_DEAUTH;
531 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
532 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
533 ap_handle_timer, hapd, sta);
534 accounting_sta_stop(hapd, sta);
535 ieee802_1x_free_station(sta);
537 sta->disassoc_reason = reason;
538 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
539 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
540 eloop_register_timeout(hapd->iface->drv_flags &
541 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
542 ap_sta_disassoc_cb_timeout, hapd, sta);
546 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
548 struct hostapd_data *hapd = eloop_ctx;
549 struct sta_info *sta = timeout_ctx;
551 ap_sta_remove(hapd, sta);
552 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
556 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
559 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
560 hapd->conf->iface, MAC2STR(sta->addr));
561 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
562 ap_sta_set_authorized(hapd, sta, 0);
563 sta->timeout_next = STA_REMOVE;
564 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
565 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
566 ap_handle_timer, hapd, sta);
567 accounting_sta_stop(hapd, sta);
568 ieee802_1x_free_station(sta);
570 sta->deauth_reason = reason;
571 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
572 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
573 eloop_register_timeout(hapd->iface->drv_flags &
574 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
575 ap_sta_deauth_cb_timeout, hapd, sta);
579 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
582 #ifndef CONFIG_NO_VLAN
584 struct hostapd_vlan *vlan = NULL;
588 * Do not proceed furthur if the vlan id remains same. We do not want
589 * duplicate dynamic vlan entries.
591 if (sta->vlan_id == old_vlanid)
595 * During 1x reauth, if the vlan id changes, then remove the old id and
596 * proceed furthur to add the new one.
599 vlan_remove_dynamic(hapd, old_vlanid);
601 iface = hapd->conf->iface;
602 if (sta->ssid->vlan[0])
603 iface = sta->ssid->vlan;
605 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
607 else if (sta->vlan_id > 0) {
608 vlan = hapd->conf->vlan;
610 if (vlan->vlan_id == sta->vlan_id ||
611 vlan->vlan_id == VLAN_ID_WILDCARD) {
612 iface = vlan->ifname;
619 if (sta->vlan_id > 0 && vlan == NULL) {
620 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
621 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
622 "binding station to (vlan_id=%d)",
625 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
626 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
628 hostapd_logger(hapd, sta->addr,
629 HOSTAPD_MODULE_IEEE80211,
630 HOSTAPD_LEVEL_DEBUG, "could not add "
631 "dynamic VLAN interface for vlan_id=%d",
636 iface = vlan->ifname;
637 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
638 hostapd_logger(hapd, sta->addr,
639 HOSTAPD_MODULE_IEEE80211,
640 HOSTAPD_LEVEL_DEBUG, "could not "
641 "configure encryption for dynamic VLAN "
642 "interface for vlan_id=%d",
646 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
647 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
648 "interface '%s'", iface);
649 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
650 if (sta->vlan_id > 0) {
651 vlan->dynamic_vlan++;
652 hostapd_logger(hapd, sta->addr,
653 HOSTAPD_MODULE_IEEE80211,
654 HOSTAPD_LEVEL_DEBUG, "updated existing "
655 "dynamic VLAN interface '%s'", iface);
659 * Update encryption configuration for statically generated
660 * VLAN interface. This is only used for static WEP
661 * configuration for the case where hostapd did not yet know
662 * which keys are to be used when the interface was added.
664 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
665 hostapd_logger(hapd, sta->addr,
666 HOSTAPD_MODULE_IEEE80211,
667 HOSTAPD_LEVEL_DEBUG, "could not "
668 "configure encryption for VLAN "
669 "interface for vlan_id=%d",
674 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
675 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
678 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
679 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
681 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
683 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
684 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
685 "entry to vlan_id=%d", sta->vlan_id);
688 #else /* CONFIG_NO_VLAN */
690 #endif /* CONFIG_NO_VLAN */
694 #ifdef CONFIG_IEEE80211W
696 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
699 struct os_time now, passed;
701 os_time_sub(&now, &sta->sa_query_start, &passed);
702 tu = (passed.sec * 1000000 + passed.usec) / 1024;
703 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
704 hostapd_logger(hapd, sta->addr,
705 HOSTAPD_MODULE_IEEE80211,
707 "association SA Query timed out");
708 sta->sa_query_timed_out = 1;
709 os_free(sta->sa_query_trans_id);
710 sta->sa_query_trans_id = NULL;
711 sta->sa_query_count = 0;
712 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
720 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
722 struct hostapd_data *hapd = eloop_ctx;
723 struct sta_info *sta = timeout_ctx;
724 unsigned int timeout, sec, usec;
727 if (sta->sa_query_count > 0 &&
728 ap_check_sa_query_timeout(hapd, sta))
731 nbuf = os_realloc(sta->sa_query_trans_id,
732 (sta->sa_query_count + 1) * WLAN_SA_QUERY_TR_ID_LEN);
735 if (sta->sa_query_count == 0) {
736 /* Starting a new SA Query procedure */
737 os_get_time(&sta->sa_query_start);
739 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
740 sta->sa_query_trans_id = nbuf;
741 sta->sa_query_count++;
743 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
745 timeout = hapd->conf->assoc_sa_query_retry_timeout;
746 sec = ((timeout / 1000) * 1024) / 1000;
747 usec = (timeout % 1000) * 1024;
748 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
750 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
752 "association SA Query attempt %d", sta->sa_query_count);
755 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
756 #endif /* NEED_AP_MLME */
760 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
762 ap_sa_query_timer(hapd, sta);
766 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
768 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
769 os_free(sta->sa_query_trans_id);
770 sta->sa_query_trans_id = NULL;
771 sta->sa_query_count = 0;
774 #endif /* CONFIG_IEEE80211W */
777 void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
780 const u8 *dev_addr = NULL;
781 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
785 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
786 #endif /* CONFIG_P2P */
790 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
791 MACSTR " p2p_dev_addr=" MACSTR,
792 MAC2STR(sta->addr), MAC2STR(dev_addr));
794 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
795 MACSTR, MAC2STR(sta->addr));
796 if (hapd->msg_ctx_parent &&
797 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
798 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
799 AP_STA_CONNECTED MACSTR " p2p_dev_addr="
801 MAC2STR(sta->addr), MAC2STR(dev_addr));
802 else if (hapd->msg_ctx_parent &&
803 hapd->msg_ctx_parent != hapd->msg_ctx)
804 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
805 AP_STA_CONNECTED MACSTR, MAC2STR(sta->addr));
807 sta->flags |= WLAN_STA_AUTHORIZED;
810 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
811 MACSTR " p2p_dev_addr=" MACSTR,
812 MAC2STR(sta->addr), MAC2STR(dev_addr));
814 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
815 MACSTR, MAC2STR(sta->addr));
816 if (hapd->msg_ctx_parent &&
817 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
818 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
819 AP_STA_DISCONNECTED MACSTR " p2p_dev_addr="
820 MACSTR, MAC2STR(sta->addr), MAC2STR(dev_addr));
821 else if (hapd->msg_ctx_parent &&
822 hapd->msg_ctx_parent != hapd->msg_ctx)
823 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
824 AP_STA_DISCONNECTED MACSTR,
826 sta->flags &= ~WLAN_STA_AUTHORIZED;
829 if (hapd->sta_authorized_cb)
830 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
831 sta->addr, authorized, dev_addr);
835 void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
836 const u8 *addr, u16 reason)
839 if (sta == NULL && addr)
840 sta = ap_get_sta(hapd, addr);
843 hostapd_drv_sta_deauth(hapd, addr, reason);
847 ap_sta_set_authorized(hapd, sta, 0);
848 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
849 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
850 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
851 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
852 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
853 ap_handle_timer, hapd, sta);
854 sta->timeout_next = STA_REMOVE;
856 sta->deauth_reason = reason;
857 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
858 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
859 eloop_register_timeout(hapd->iface->drv_flags &
860 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
861 ap_sta_deauth_cb_timeout, hapd, sta);
865 void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
867 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
868 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
871 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
872 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
873 ap_sta_deauth_cb_timeout(hapd, sta);
877 void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
879 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
880 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
883 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
884 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
885 ap_sta_disassoc_cb_timeout(hapd, sta);