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 wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
199 __func__, MAC2STR(sta->addr));
200 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
201 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
202 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
203 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
205 ieee802_1x_free_station(sta);
206 wpa_auth_sta_deinit(sta->wpa_sm);
207 rsn_preauth_free_station(hapd, sta);
208 #ifndef CONFIG_NO_RADIUS
209 radius_client_flush_auth(hapd->radius, sta->addr);
210 #endif /* CONFIG_NO_RADIUS */
212 os_free(sta->last_assoc_req);
213 os_free(sta->challenge);
215 #ifdef CONFIG_IEEE80211W
216 os_free(sta->sa_query_trans_id);
217 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
218 #endif /* CONFIG_IEEE80211W */
221 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
222 #endif /* CONFIG_P2P */
224 #ifdef CONFIG_INTERWORKING
225 if (sta->gas_dialog) {
227 for (i = 0; i < GAS_DIALOG_MAX; i++)
228 gas_serv_dialog_clear(&sta->gas_dialog[i]);
229 os_free(sta->gas_dialog);
231 #endif /* CONFIG_INTERWORKING */
233 wpabuf_free(sta->wps_ie);
234 wpabuf_free(sta->p2p_ie);
236 os_free(sta->ht_capabilities);
238 os_free(sta->identity);
239 os_free(sta->radius_cui);
245 void hostapd_free_stas(struct hostapd_data *hapd)
247 struct sta_info *sta, *prev;
249 sta = hapd->sta_list;
253 if (sta->flags & WLAN_STA_AUTH) {
254 mlme_deauthenticate_indication(
255 hapd, sta, WLAN_REASON_UNSPECIFIED);
258 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
259 MAC2STR(prev->addr));
260 ap_free_sta(hapd, prev);
266 * ap_handle_timer - Per STA timer handler
267 * @eloop_ctx: struct hostapd_data *
268 * @timeout_ctx: struct sta_info *
270 * This function is called to check station activity and to remove inactive
273 void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
275 struct hostapd_data *hapd = eloop_ctx;
276 struct sta_info *sta = timeout_ctx;
277 unsigned long next_time = 0;
279 wpa_printf(MSG_DEBUG, "%s: " MACSTR " flags=0x%x timeout_next=%d",
280 __func__, MAC2STR(sta->addr), sta->flags,
282 if (sta->timeout_next == STA_REMOVE) {
283 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
284 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
285 "local deauth request");
286 ap_free_sta(hapd, sta);
290 if ((sta->flags & WLAN_STA_ASSOC) &&
291 (sta->timeout_next == STA_NULLFUNC ||
292 sta->timeout_next == STA_DISASSOC)) {
295 * Add random value to timeout so that we don't end up bouncing
296 * all stations at the same time if we have lots of associated
297 * stations that are idle (but keep re-associating).
299 int fuzz = os_random() % 20;
300 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
301 if (inactive_sec == -1) {
302 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
303 "Check inactivity: Could not "
304 "get station info from kernel driver for "
305 MACSTR, MAC2STR(sta->addr));
307 * The driver may not support this functionality.
308 * Anyway, try again after the next inactivity timeout,
309 * but do not disconnect the station now.
311 next_time = hapd->conf->ap_max_inactivity + fuzz;
312 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
313 sta->flags & WLAN_STA_ASSOC) {
314 /* station activity detected; reset timeout state */
315 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
316 "Station " MACSTR " has been active %is ago",
317 MAC2STR(sta->addr), inactive_sec);
318 sta->timeout_next = STA_NULLFUNC;
319 next_time = hapd->conf->ap_max_inactivity + fuzz -
322 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
323 "Station " MACSTR " has been "
324 "inactive too long: %d sec, max allowed: %d",
325 MAC2STR(sta->addr), inactive_sec,
326 hapd->conf->ap_max_inactivity);
328 if (hapd->conf->skip_inactivity_poll)
329 sta->timeout_next = STA_DISASSOC;
333 if ((sta->flags & WLAN_STA_ASSOC) &&
334 sta->timeout_next == STA_DISASSOC &&
335 !(sta->flags & WLAN_STA_PENDING_POLL) &&
336 !hapd->conf->skip_inactivity_poll) {
337 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
338 " has ACKed data poll", MAC2STR(sta->addr));
339 /* data nullfunc frame poll did not produce TX errors; assume
340 * station ACKed it */
341 sta->timeout_next = STA_NULLFUNC;
342 next_time = hapd->conf->ap_max_inactivity;
346 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
347 "for " MACSTR " (%lu seconds)",
348 __func__, MAC2STR(sta->addr), next_time);
349 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
354 if (sta->timeout_next == STA_NULLFUNC &&
355 (sta->flags & WLAN_STA_ASSOC)) {
356 wpa_printf(MSG_DEBUG, " Polling STA");
357 sta->flags |= WLAN_STA_PENDING_POLL;
358 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
359 sta->flags & WLAN_STA_WMM);
360 } else if (sta->timeout_next != STA_REMOVE) {
361 int deauth = sta->timeout_next == STA_DEAUTH;
363 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
364 "Timeout, sending %s info to STA " MACSTR,
365 deauth ? "deauthentication" : "disassociation",
369 hostapd_drv_sta_deauth(
371 WLAN_REASON_PREV_AUTH_NOT_VALID);
373 hostapd_drv_sta_disassoc(
375 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
379 switch (sta->timeout_next) {
381 sta->timeout_next = STA_DISASSOC;
382 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
383 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
384 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
385 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
389 ap_sta_set_authorized(hapd, sta, 0);
390 sta->flags &= ~WLAN_STA_ASSOC;
391 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
392 if (!sta->acct_terminate_cause)
393 sta->acct_terminate_cause =
394 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
395 accounting_sta_stop(hapd, sta);
396 ieee802_1x_free_station(sta);
397 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
398 HOSTAPD_LEVEL_INFO, "disassociated due to "
400 sta->timeout_next = STA_DEAUTH;
401 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
402 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
403 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
404 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
406 mlme_disassociate_indication(
407 hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
411 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
412 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
413 "inactivity (timer DEAUTH/REMOVE)");
414 if (!sta->acct_terminate_cause)
415 sta->acct_terminate_cause =
416 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
417 mlme_deauthenticate_indication(
419 WLAN_REASON_PREV_AUTH_NOT_VALID);
420 ap_free_sta(hapd, sta);
426 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
428 struct hostapd_data *hapd = eloop_ctx;
429 struct sta_info *sta = timeout_ctx;
432 if (!(sta->flags & WLAN_STA_AUTH)) {
433 if (sta->flags & WLAN_STA_GAS) {
434 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
435 "entry " MACSTR, MAC2STR(sta->addr));
436 ap_free_sta(hapd, sta);
441 mlme_deauthenticate_indication(hapd, sta,
442 WLAN_REASON_PREV_AUTH_NOT_VALID);
443 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
444 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
446 sta->acct_terminate_cause =
447 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
448 os_memcpy(addr, sta->addr, ETH_ALEN);
449 ap_free_sta(hapd, sta);
450 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
454 void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
457 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
458 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
459 "seconds", session_timeout);
460 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
461 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
466 void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
468 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
472 struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
474 struct sta_info *sta;
476 sta = ap_get_sta(hapd, addr);
480 wpa_printf(MSG_DEBUG, " New STA");
481 if (hapd->num_sta >= hapd->conf->max_num_sta) {
482 /* FIX: might try to remove some old STAs first? */
483 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
484 hapd->num_sta, hapd->conf->max_num_sta);
488 sta = os_zalloc(sizeof(struct sta_info));
490 wpa_printf(MSG_ERROR, "malloc failed");
493 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
495 /* initialize STA info data */
496 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
497 "for " MACSTR " (%d seconds - ap_max_inactivity)",
498 __func__, MAC2STR(addr),
499 hapd->conf->ap_max_inactivity);
500 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
501 ap_handle_timer, hapd, sta);
502 os_memcpy(sta->addr, addr, ETH_ALEN);
503 sta->next = hapd->sta_list;
504 hapd->sta_list = sta;
506 ap_sta_hash_add(hapd, sta);
507 sta->ssid = &hapd->conf->ssid;
508 ap_sta_remove_in_other_bss(hapd, sta);
514 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
516 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
518 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
520 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
521 sta->flags & WLAN_STA_ASSOC) {
522 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
523 " from kernel driver.", MAC2STR(sta->addr));
530 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
531 struct sta_info *sta)
533 struct hostapd_iface *iface = hapd->iface;
536 for (i = 0; i < iface->num_bss; i++) {
537 struct hostapd_data *bss = iface->bss[i];
538 struct sta_info *sta2;
539 /* bss should always be set during operation, but it may be
540 * NULL during reconfiguration. Assume the STA is not
541 * associated to another BSS in that case to avoid NULL pointer
543 if (bss == hapd || bss == NULL)
545 sta2 = ap_get_sta(bss, sta->addr);
549 ap_sta_disconnect(bss, sta2, sta2->addr,
550 WLAN_REASON_PREV_AUTH_NOT_VALID);
555 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
557 struct hostapd_data *hapd = eloop_ctx;
558 struct sta_info *sta = timeout_ctx;
560 ap_sta_remove(hapd, sta);
561 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
565 void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
568 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
569 hapd->conf->iface, MAC2STR(sta->addr));
570 sta->flags &= ~WLAN_STA_ASSOC;
571 ap_sta_set_authorized(hapd, sta, 0);
572 sta->timeout_next = STA_DEAUTH;
573 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
574 "for " MACSTR " (%d seconds - "
575 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
576 __func__, MAC2STR(sta->addr),
577 AP_MAX_INACTIVITY_AFTER_DISASSOC);
578 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
579 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
580 ap_handle_timer, hapd, sta);
581 accounting_sta_stop(hapd, sta);
582 ieee802_1x_free_station(sta);
584 sta->disassoc_reason = reason;
585 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
586 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
587 eloop_register_timeout(hapd->iface->drv_flags &
588 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
589 ap_sta_disassoc_cb_timeout, hapd, sta);
593 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
595 struct hostapd_data *hapd = eloop_ctx;
596 struct sta_info *sta = timeout_ctx;
598 ap_sta_remove(hapd, sta);
599 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
603 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
606 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
607 hapd->conf->iface, MAC2STR(sta->addr));
608 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
609 ap_sta_set_authorized(hapd, sta, 0);
610 sta->timeout_next = STA_REMOVE;
611 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
612 "for " MACSTR " (%d seconds - "
613 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
614 __func__, MAC2STR(sta->addr),
615 AP_MAX_INACTIVITY_AFTER_DEAUTH);
616 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
617 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
618 ap_handle_timer, hapd, sta);
619 accounting_sta_stop(hapd, sta);
620 ieee802_1x_free_station(sta);
622 sta->deauth_reason = reason;
623 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
624 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
625 eloop_register_timeout(hapd->iface->drv_flags &
626 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
627 ap_sta_deauth_cb_timeout, hapd, sta);
632 int ap_sta_wps_cancel(struct hostapd_data *hapd,
633 struct sta_info *sta, void *ctx)
635 if (sta && (sta->flags & WLAN_STA_WPS)) {
636 ap_sta_deauthenticate(hapd, sta,
637 WLAN_REASON_PREV_AUTH_NOT_VALID);
638 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
639 __func__, MAC2STR(sta->addr));
645 #endif /* CONFIG_WPS */
648 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
651 #ifndef CONFIG_NO_VLAN
653 struct hostapd_vlan *vlan = NULL;
657 * Do not proceed furthur if the vlan id remains same. We do not want
658 * duplicate dynamic vlan entries.
660 if (sta->vlan_id == old_vlanid)
664 * During 1x reauth, if the vlan id changes, then remove the old id and
665 * proceed furthur to add the new one.
668 vlan_remove_dynamic(hapd, old_vlanid);
670 iface = hapd->conf->iface;
671 if (sta->ssid->vlan[0])
672 iface = sta->ssid->vlan;
674 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
676 else if (sta->vlan_id > 0) {
677 vlan = hapd->conf->vlan;
679 if (vlan->vlan_id == sta->vlan_id ||
680 vlan->vlan_id == VLAN_ID_WILDCARD) {
681 iface = vlan->ifname;
688 if (sta->vlan_id > 0 && vlan == NULL) {
689 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
690 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
691 "binding station to (vlan_id=%d)",
694 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
695 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
697 hostapd_logger(hapd, sta->addr,
698 HOSTAPD_MODULE_IEEE80211,
699 HOSTAPD_LEVEL_DEBUG, "could not add "
700 "dynamic VLAN interface for vlan_id=%d",
705 iface = vlan->ifname;
706 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
707 hostapd_logger(hapd, sta->addr,
708 HOSTAPD_MODULE_IEEE80211,
709 HOSTAPD_LEVEL_DEBUG, "could not "
710 "configure encryption for dynamic VLAN "
711 "interface for vlan_id=%d",
715 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
716 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
717 "interface '%s'", iface);
718 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
719 if (sta->vlan_id > 0) {
720 vlan->dynamic_vlan++;
721 hostapd_logger(hapd, sta->addr,
722 HOSTAPD_MODULE_IEEE80211,
723 HOSTAPD_LEVEL_DEBUG, "updated existing "
724 "dynamic VLAN interface '%s'", iface);
728 * Update encryption configuration for statically generated
729 * VLAN interface. This is only used for static WEP
730 * configuration for the case where hostapd did not yet know
731 * which keys are to be used when the interface was added.
733 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
734 hostapd_logger(hapd, sta->addr,
735 HOSTAPD_MODULE_IEEE80211,
736 HOSTAPD_LEVEL_DEBUG, "could not "
737 "configure encryption for VLAN "
738 "interface for vlan_id=%d",
743 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
744 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
747 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
748 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
750 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
752 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
753 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
754 "entry to vlan_id=%d", sta->vlan_id);
757 #else /* CONFIG_NO_VLAN */
759 #endif /* CONFIG_NO_VLAN */
763 #ifdef CONFIG_IEEE80211W
765 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
768 struct os_time now, passed;
770 os_time_sub(&now, &sta->sa_query_start, &passed);
771 tu = (passed.sec * 1000000 + passed.usec) / 1024;
772 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
773 hostapd_logger(hapd, sta->addr,
774 HOSTAPD_MODULE_IEEE80211,
776 "association SA Query timed out");
777 sta->sa_query_timed_out = 1;
778 os_free(sta->sa_query_trans_id);
779 sta->sa_query_trans_id = NULL;
780 sta->sa_query_count = 0;
781 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
789 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
791 struct hostapd_data *hapd = eloop_ctx;
792 struct sta_info *sta = timeout_ctx;
793 unsigned int timeout, sec, usec;
796 if (sta->sa_query_count > 0 &&
797 ap_check_sa_query_timeout(hapd, sta))
800 nbuf = os_realloc_array(sta->sa_query_trans_id,
801 sta->sa_query_count + 1,
802 WLAN_SA_QUERY_TR_ID_LEN);
805 if (sta->sa_query_count == 0) {
806 /* Starting a new SA Query procedure */
807 os_get_time(&sta->sa_query_start);
809 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
810 sta->sa_query_trans_id = nbuf;
811 sta->sa_query_count++;
813 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
815 timeout = hapd->conf->assoc_sa_query_retry_timeout;
816 sec = ((timeout / 1000) * 1024) / 1000;
817 usec = (timeout % 1000) * 1024;
818 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
820 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
822 "association SA Query attempt %d", sta->sa_query_count);
824 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
828 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
830 ap_sa_query_timer(hapd, sta);
834 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
836 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
837 os_free(sta->sa_query_trans_id);
838 sta->sa_query_trans_id = NULL;
839 sta->sa_query_count = 0;
842 #endif /* CONFIG_IEEE80211W */
845 void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
848 const u8 *dev_addr = NULL;
851 #endif /* CONFIG_P2P */
853 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
857 if (hapd->p2p_group == NULL) {
858 if (sta->p2p_ie != NULL &&
859 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
862 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
863 #endif /* CONFIG_P2P */
867 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
868 MACSTR " p2p_dev_addr=" MACSTR,
869 MAC2STR(sta->addr), MAC2STR(dev_addr));
871 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
872 MACSTR, MAC2STR(sta->addr));
873 if (hapd->msg_ctx_parent &&
874 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
875 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
876 AP_STA_CONNECTED MACSTR " p2p_dev_addr="
878 MAC2STR(sta->addr), MAC2STR(dev_addr));
879 else if (hapd->msg_ctx_parent &&
880 hapd->msg_ctx_parent != hapd->msg_ctx)
881 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
882 AP_STA_CONNECTED MACSTR, MAC2STR(sta->addr));
884 sta->flags |= WLAN_STA_AUTHORIZED;
887 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
888 MACSTR " p2p_dev_addr=" MACSTR,
889 MAC2STR(sta->addr), MAC2STR(dev_addr));
891 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
892 MACSTR, MAC2STR(sta->addr));
893 if (hapd->msg_ctx_parent &&
894 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
895 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
896 AP_STA_DISCONNECTED MACSTR " p2p_dev_addr="
897 MACSTR, MAC2STR(sta->addr), MAC2STR(dev_addr));
898 else if (hapd->msg_ctx_parent &&
899 hapd->msg_ctx_parent != hapd->msg_ctx)
900 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
901 AP_STA_DISCONNECTED MACSTR,
903 sta->flags &= ~WLAN_STA_AUTHORIZED;
906 if (hapd->sta_authorized_cb)
907 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
908 sta->addr, authorized, dev_addr);
912 void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
913 const u8 *addr, u16 reason)
916 if (sta == NULL && addr)
917 sta = ap_get_sta(hapd, addr);
920 hostapd_drv_sta_deauth(hapd, addr, reason);
924 ap_sta_set_authorized(hapd, sta, 0);
925 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
926 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
927 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
928 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
929 "for " MACSTR " (%d seconds - "
930 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
931 __func__, MAC2STR(sta->addr),
932 AP_MAX_INACTIVITY_AFTER_DEAUTH);
933 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
934 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
935 ap_handle_timer, hapd, sta);
936 sta->timeout_next = STA_REMOVE;
938 sta->deauth_reason = reason;
939 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
940 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
941 eloop_register_timeout(hapd->iface->drv_flags &
942 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
943 ap_sta_deauth_cb_timeout, hapd, sta);
947 void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
949 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
950 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
953 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
954 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
955 ap_sta_deauth_cb_timeout(hapd, sta);
959 void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
961 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
962 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
965 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
966 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
967 ap_sta_disassoc_cb_timeout(hapd, sta);