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)) {
288 * Add random value to timeout so that we don't end up bouncing
289 * all stations at the same time if we have lots of associated
290 * stations that are idle (but keep re-associating).
292 int fuzz = os_random() % 20;
293 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
294 if (inactive_sec == -1) {
295 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
296 "Check inactivity: Could not "
297 "get station info from kernel driver for "
298 MACSTR, MAC2STR(sta->addr));
300 * The driver may not support this functionality.
301 * Anyway, try again after the next inactivity timeout,
302 * but do not disconnect the station now.
304 next_time = hapd->conf->ap_max_inactivity + fuzz;
305 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
306 sta->flags & WLAN_STA_ASSOC) {
307 /* station activity detected; reset timeout state */
308 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
309 "Station " MACSTR " has been active %is ago",
310 MAC2STR(sta->addr), inactive_sec);
311 sta->timeout_next = STA_NULLFUNC;
312 next_time = hapd->conf->ap_max_inactivity + fuzz -
315 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
316 "Station " MACSTR " has been "
317 "inactive too long: %d sec, max allowed: %d",
318 MAC2STR(sta->addr), inactive_sec,
319 hapd->conf->ap_max_inactivity);
321 if (hapd->conf->skip_inactivity_poll)
322 sta->timeout_next = STA_DISASSOC;
326 if ((sta->flags & WLAN_STA_ASSOC) &&
327 sta->timeout_next == STA_DISASSOC &&
328 !(sta->flags & WLAN_STA_PENDING_POLL) &&
329 !hapd->conf->skip_inactivity_poll) {
330 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
331 " has ACKed data poll", MAC2STR(sta->addr));
332 /* data nullfunc frame poll did not produce TX errors; assume
333 * station ACKed it */
334 sta->timeout_next = STA_NULLFUNC;
335 next_time = hapd->conf->ap_max_inactivity;
339 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
344 if (sta->timeout_next == STA_NULLFUNC &&
345 (sta->flags & WLAN_STA_ASSOC)) {
346 wpa_printf(MSG_DEBUG, " Polling STA");
347 sta->flags |= WLAN_STA_PENDING_POLL;
348 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
349 sta->flags & WLAN_STA_WMM);
350 } else if (sta->timeout_next != STA_REMOVE) {
351 int deauth = sta->timeout_next == STA_DEAUTH;
353 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
354 "Timeout, sending %s info to STA " MACSTR,
355 deauth ? "deauthentication" : "disassociation",
359 hostapd_drv_sta_deauth(
361 WLAN_REASON_PREV_AUTH_NOT_VALID);
363 hostapd_drv_sta_disassoc(
365 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
369 switch (sta->timeout_next) {
371 sta->timeout_next = STA_DISASSOC;
372 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
376 ap_sta_set_authorized(hapd, sta, 0);
377 sta->flags &= ~WLAN_STA_ASSOC;
378 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
379 if (!sta->acct_terminate_cause)
380 sta->acct_terminate_cause =
381 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
382 accounting_sta_stop(hapd, sta);
383 ieee802_1x_free_station(sta);
384 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
385 HOSTAPD_LEVEL_INFO, "disassociated due to "
387 sta->timeout_next = STA_DEAUTH;
388 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
390 mlme_disassociate_indication(
391 hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
395 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
396 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
397 "inactivity (timer DEAUTH/REMOVE)");
398 if (!sta->acct_terminate_cause)
399 sta->acct_terminate_cause =
400 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
401 mlme_deauthenticate_indication(
403 WLAN_REASON_PREV_AUTH_NOT_VALID);
404 ap_free_sta(hapd, sta);
410 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
412 struct hostapd_data *hapd = eloop_ctx;
413 struct sta_info *sta = timeout_ctx;
416 if (!(sta->flags & WLAN_STA_AUTH)) {
417 if (sta->flags & WLAN_STA_GAS) {
418 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
419 "entry " MACSTR, MAC2STR(sta->addr));
420 ap_free_sta(hapd, sta);
425 mlme_deauthenticate_indication(hapd, sta,
426 WLAN_REASON_PREV_AUTH_NOT_VALID);
427 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
428 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
430 sta->acct_terminate_cause =
431 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
432 os_memcpy(addr, sta->addr, ETH_ALEN);
433 ap_free_sta(hapd, sta);
434 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
438 void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
441 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
442 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
443 "seconds", session_timeout);
444 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
445 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
450 void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
452 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
456 struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
458 struct sta_info *sta;
460 sta = ap_get_sta(hapd, addr);
464 wpa_printf(MSG_DEBUG, " New STA");
465 if (hapd->num_sta >= hapd->conf->max_num_sta) {
466 /* FIX: might try to remove some old STAs first? */
467 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
468 hapd->num_sta, hapd->conf->max_num_sta);
472 sta = os_zalloc(sizeof(struct sta_info));
474 wpa_printf(MSG_ERROR, "malloc failed");
477 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
479 /* initialize STA info data */
480 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
481 ap_handle_timer, hapd, sta);
482 os_memcpy(sta->addr, addr, ETH_ALEN);
483 sta->next = hapd->sta_list;
484 hapd->sta_list = sta;
486 ap_sta_hash_add(hapd, sta);
487 sta->ssid = &hapd->conf->ssid;
488 ap_sta_remove_in_other_bss(hapd, sta);
494 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
496 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
498 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
500 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
501 sta->flags & WLAN_STA_ASSOC) {
502 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
503 " from kernel driver.", MAC2STR(sta->addr));
510 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
511 struct sta_info *sta)
513 struct hostapd_iface *iface = hapd->iface;
516 for (i = 0; i < iface->num_bss; i++) {
517 struct hostapd_data *bss = iface->bss[i];
518 struct sta_info *sta2;
519 /* bss should always be set during operation, but it may be
520 * NULL during reconfiguration. Assume the STA is not
521 * associated to another BSS in that case to avoid NULL pointer
523 if (bss == hapd || bss == NULL)
525 sta2 = ap_get_sta(bss, sta->addr);
529 ap_sta_disconnect(bss, sta2, sta2->addr,
530 WLAN_REASON_PREV_AUTH_NOT_VALID);
535 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
537 struct hostapd_data *hapd = eloop_ctx;
538 struct sta_info *sta = timeout_ctx;
540 ap_sta_remove(hapd, sta);
541 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
545 void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
548 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
549 hapd->conf->iface, MAC2STR(sta->addr));
550 sta->flags &= ~WLAN_STA_ASSOC;
551 ap_sta_set_authorized(hapd, sta, 0);
552 sta->timeout_next = STA_DEAUTH;
553 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
554 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
555 ap_handle_timer, hapd, sta);
556 accounting_sta_stop(hapd, sta);
557 ieee802_1x_free_station(sta);
559 sta->disassoc_reason = reason;
560 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
561 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
562 eloop_register_timeout(hapd->iface->drv_flags &
563 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
564 ap_sta_disassoc_cb_timeout, hapd, sta);
568 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
570 struct hostapd_data *hapd = eloop_ctx;
571 struct sta_info *sta = timeout_ctx;
573 ap_sta_remove(hapd, sta);
574 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
578 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
581 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
582 hapd->conf->iface, MAC2STR(sta->addr));
583 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
584 ap_sta_set_authorized(hapd, sta, 0);
585 sta->timeout_next = STA_REMOVE;
586 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
587 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
588 ap_handle_timer, hapd, sta);
589 accounting_sta_stop(hapd, sta);
590 ieee802_1x_free_station(sta);
592 sta->deauth_reason = reason;
593 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
594 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
595 eloop_register_timeout(hapd->iface->drv_flags &
596 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
597 ap_sta_deauth_cb_timeout, hapd, sta);
602 int ap_sta_wps_cancel(struct hostapd_data *hapd,
603 struct sta_info *sta, void *ctx)
605 if (sta && (sta->flags & WLAN_STA_WPS)) {
606 ap_sta_deauthenticate(hapd, sta,
607 WLAN_REASON_PREV_AUTH_NOT_VALID);
608 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
609 __func__, MAC2STR(sta->addr));
615 #endif /* CONFIG_WPS */
618 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
621 #ifndef CONFIG_NO_VLAN
623 struct hostapd_vlan *vlan = NULL;
627 * Do not proceed furthur if the vlan id remains same. We do not want
628 * duplicate dynamic vlan entries.
630 if (sta->vlan_id == old_vlanid)
634 * During 1x reauth, if the vlan id changes, then remove the old id and
635 * proceed furthur to add the new one.
638 vlan_remove_dynamic(hapd, old_vlanid);
640 iface = hapd->conf->iface;
641 if (sta->ssid->vlan[0])
642 iface = sta->ssid->vlan;
644 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
646 else if (sta->vlan_id > 0) {
647 vlan = hapd->conf->vlan;
649 if (vlan->vlan_id == sta->vlan_id ||
650 vlan->vlan_id == VLAN_ID_WILDCARD) {
651 iface = vlan->ifname;
658 if (sta->vlan_id > 0 && vlan == NULL) {
659 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
660 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
661 "binding station to (vlan_id=%d)",
664 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
665 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
667 hostapd_logger(hapd, sta->addr,
668 HOSTAPD_MODULE_IEEE80211,
669 HOSTAPD_LEVEL_DEBUG, "could not add "
670 "dynamic VLAN interface for vlan_id=%d",
675 iface = vlan->ifname;
676 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
677 hostapd_logger(hapd, sta->addr,
678 HOSTAPD_MODULE_IEEE80211,
679 HOSTAPD_LEVEL_DEBUG, "could not "
680 "configure encryption for dynamic VLAN "
681 "interface for vlan_id=%d",
685 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
686 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
687 "interface '%s'", iface);
688 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
689 if (sta->vlan_id > 0) {
690 vlan->dynamic_vlan++;
691 hostapd_logger(hapd, sta->addr,
692 HOSTAPD_MODULE_IEEE80211,
693 HOSTAPD_LEVEL_DEBUG, "updated existing "
694 "dynamic VLAN interface '%s'", iface);
698 * Update encryption configuration for statically generated
699 * VLAN interface. This is only used for static WEP
700 * configuration for the case where hostapd did not yet know
701 * which keys are to be used when the interface was added.
703 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
704 hostapd_logger(hapd, sta->addr,
705 HOSTAPD_MODULE_IEEE80211,
706 HOSTAPD_LEVEL_DEBUG, "could not "
707 "configure encryption for VLAN "
708 "interface for vlan_id=%d",
713 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
714 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
717 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
718 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
720 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
722 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
723 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
724 "entry to vlan_id=%d", sta->vlan_id);
727 #else /* CONFIG_NO_VLAN */
729 #endif /* CONFIG_NO_VLAN */
733 #ifdef CONFIG_IEEE80211W
735 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
738 struct os_time now, passed;
740 os_time_sub(&now, &sta->sa_query_start, &passed);
741 tu = (passed.sec * 1000000 + passed.usec) / 1024;
742 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
743 hostapd_logger(hapd, sta->addr,
744 HOSTAPD_MODULE_IEEE80211,
746 "association SA Query timed out");
747 sta->sa_query_timed_out = 1;
748 os_free(sta->sa_query_trans_id);
749 sta->sa_query_trans_id = NULL;
750 sta->sa_query_count = 0;
751 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
759 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
761 struct hostapd_data *hapd = eloop_ctx;
762 struct sta_info *sta = timeout_ctx;
763 unsigned int timeout, sec, usec;
766 if (sta->sa_query_count > 0 &&
767 ap_check_sa_query_timeout(hapd, sta))
770 nbuf = os_realloc(sta->sa_query_trans_id,
771 (sta->sa_query_count + 1) * WLAN_SA_QUERY_TR_ID_LEN);
774 if (sta->sa_query_count == 0) {
775 /* Starting a new SA Query procedure */
776 os_get_time(&sta->sa_query_start);
778 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
779 sta->sa_query_trans_id = nbuf;
780 sta->sa_query_count++;
782 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
784 timeout = hapd->conf->assoc_sa_query_retry_timeout;
785 sec = ((timeout / 1000) * 1024) / 1000;
786 usec = (timeout % 1000) * 1024;
787 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
789 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
791 "association SA Query attempt %d", sta->sa_query_count);
794 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
795 #endif /* NEED_AP_MLME */
799 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
801 ap_sa_query_timer(hapd, sta);
805 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
807 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
808 os_free(sta->sa_query_trans_id);
809 sta->sa_query_trans_id = NULL;
810 sta->sa_query_count = 0;
813 #endif /* CONFIG_IEEE80211W */
816 void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
819 const u8 *dev_addr = NULL;
820 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
824 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
825 #endif /* CONFIG_P2P */
829 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
830 MACSTR " p2p_dev_addr=" MACSTR,
831 MAC2STR(sta->addr), MAC2STR(dev_addr));
833 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
834 MACSTR, MAC2STR(sta->addr));
835 if (hapd->msg_ctx_parent &&
836 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
837 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
838 AP_STA_CONNECTED MACSTR " p2p_dev_addr="
840 MAC2STR(sta->addr), MAC2STR(dev_addr));
841 else if (hapd->msg_ctx_parent &&
842 hapd->msg_ctx_parent != hapd->msg_ctx)
843 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
844 AP_STA_CONNECTED MACSTR, MAC2STR(sta->addr));
846 sta->flags |= WLAN_STA_AUTHORIZED;
849 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
850 MACSTR " p2p_dev_addr=" MACSTR,
851 MAC2STR(sta->addr), MAC2STR(dev_addr));
853 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
854 MACSTR, MAC2STR(sta->addr));
855 if (hapd->msg_ctx_parent &&
856 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
857 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
858 AP_STA_DISCONNECTED MACSTR " p2p_dev_addr="
859 MACSTR, MAC2STR(sta->addr), MAC2STR(dev_addr));
860 else if (hapd->msg_ctx_parent &&
861 hapd->msg_ctx_parent != hapd->msg_ctx)
862 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
863 AP_STA_DISCONNECTED MACSTR,
865 sta->flags &= ~WLAN_STA_AUTHORIZED;
868 if (hapd->sta_authorized_cb)
869 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
870 sta->addr, authorized, dev_addr);
874 void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
875 const u8 *addr, u16 reason)
878 if (sta == NULL && addr)
879 sta = ap_get_sta(hapd, addr);
882 hostapd_drv_sta_deauth(hapd, addr, reason);
886 ap_sta_set_authorized(hapd, sta, 0);
887 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
888 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
889 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
890 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
891 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
892 ap_handle_timer, hapd, sta);
893 sta->timeout_next = STA_REMOVE;
895 sta->deauth_reason = reason;
896 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
897 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
898 eloop_register_timeout(hapd->iface->drv_flags &
899 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
900 ap_sta_deauth_cb_timeout, hapd, sta);
904 void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
906 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
907 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
910 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
911 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
912 ap_sta_deauth_cb_timeout(hapd, sta);
916 void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
918 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
919 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
922 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
923 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
924 ap_sta_disassoc_cb_timeout(hapd, sta);