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"
23 #include "ieee802_11_auth.h"
25 #include "preauth_auth.h"
26 #include "ap_config.h"
29 #include "vlan_init.h"
30 #include "p2p_hostapd.h"
31 #include "ap_drv_ops.h"
35 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
36 struct sta_info *sta);
37 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
38 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
39 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
40 #ifdef CONFIG_IEEE80211W
41 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
42 #endif /* CONFIG_IEEE80211W */
43 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
45 int ap_for_each_sta(struct hostapd_data *hapd,
46 int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
52 for (sta = hapd->sta_list; sta; sta = sta->next) {
53 if (cb(hapd, sta, ctx))
61 struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
65 s = hapd->sta_hash[STA_HASH(sta)];
66 while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
72 static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
76 if (hapd->sta_list == sta) {
77 hapd->sta_list = sta->next;
82 while (tmp != NULL && tmp->next != sta)
85 wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
86 "list.", MAC2STR(sta->addr));
88 tmp->next = sta->next;
92 void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
94 sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
95 hapd->sta_hash[STA_HASH(sta->addr)] = sta;
99 static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
103 s = hapd->sta_hash[STA_HASH(sta->addr)];
104 if (s == NULL) return;
105 if (os_memcmp(s->addr, sta->addr, 6) == 0) {
106 hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
110 while (s->hnext != NULL &&
111 os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
113 if (s->hnext != NULL)
114 s->hnext = s->hnext->hnext;
116 wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
117 " from hash table", MAC2STR(sta->addr));
121 void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
125 accounting_sta_stop(hapd, sta);
128 ap_sta_set_authorized(hapd, sta, 0);
130 if (sta->flags & WLAN_STA_WDS)
131 hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 0);
133 if (!(sta->flags & WLAN_STA_PREAUTH))
134 hostapd_drv_sta_remove(hapd, sta->addr);
136 ap_sta_hash_del(hapd, sta);
137 ap_sta_list_del(hapd, sta);
140 hapd->sta_aid[(sta->aid - 1) / 32] &=
141 ~BIT((sta->aid - 1) % 32);
144 if (sta->nonerp_set) {
146 hapd->iface->num_sta_non_erp--;
147 if (hapd->iface->num_sta_non_erp == 0)
151 if (sta->no_short_slot_time_set) {
152 sta->no_short_slot_time_set = 0;
153 hapd->iface->num_sta_no_short_slot_time--;
154 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
155 && hapd->iface->num_sta_no_short_slot_time == 0)
159 if (sta->no_short_preamble_set) {
160 sta->no_short_preamble_set = 0;
161 hapd->iface->num_sta_no_short_preamble--;
162 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
163 && hapd->iface->num_sta_no_short_preamble == 0)
167 if (sta->no_ht_gf_set) {
168 sta->no_ht_gf_set = 0;
169 hapd->iface->num_sta_ht_no_gf--;
172 if (sta->no_ht_set) {
174 hapd->iface->num_sta_no_ht--;
177 if (sta->ht_20mhz_set) {
178 sta->ht_20mhz_set = 0;
179 hapd->iface->num_sta_ht_20mhz--;
183 if (sta->no_p2p_set) {
185 hapd->num_sta_no_p2p--;
186 if (hapd->num_sta_no_p2p == 0)
187 hostapd_p2p_non_p2p_sta_disconnected(hapd);
189 #endif /* CONFIG_P2P */
191 #if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
192 if (hostapd_ht_operation_update(hapd->iface) > 0)
194 #endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
197 ieee802_11_set_beacons(hapd->iface);
199 wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
200 __func__, MAC2STR(sta->addr));
201 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
202 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
203 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
204 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
206 ieee802_1x_free_station(sta);
207 wpa_auth_sta_deinit(sta->wpa_sm);
208 rsn_preauth_free_station(hapd, sta);
209 #ifndef CONFIG_NO_RADIUS
210 radius_client_flush_auth(hapd->radius, sta->addr);
211 #endif /* CONFIG_NO_RADIUS */
213 os_free(sta->last_assoc_req);
214 os_free(sta->challenge);
216 #ifdef CONFIG_IEEE80211W
217 os_free(sta->sa_query_trans_id);
218 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
219 #endif /* CONFIG_IEEE80211W */
222 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
223 #endif /* CONFIG_P2P */
225 #ifdef CONFIG_INTERWORKING
226 if (sta->gas_dialog) {
228 for (i = 0; i < GAS_DIALOG_MAX; i++)
229 gas_serv_dialog_clear(&sta->gas_dialog[i]);
230 os_free(sta->gas_dialog);
232 #endif /* CONFIG_INTERWORKING */
234 wpabuf_free(sta->wps_ie);
235 wpabuf_free(sta->p2p_ie);
236 wpabuf_free(sta->hs20_ie);
238 os_free(sta->ht_capabilities);
239 hostapd_free_psk_list(sta->psk);
240 os_free(sta->identity);
241 os_free(sta->radius_cui);
247 void hostapd_free_stas(struct hostapd_data *hapd)
249 struct sta_info *sta, *prev;
251 sta = hapd->sta_list;
255 if (sta->flags & WLAN_STA_AUTH) {
256 mlme_deauthenticate_indication(
257 hapd, sta, WLAN_REASON_UNSPECIFIED);
260 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
261 MAC2STR(prev->addr));
262 ap_free_sta(hapd, prev);
268 * ap_handle_timer - Per STA timer handler
269 * @eloop_ctx: struct hostapd_data *
270 * @timeout_ctx: struct sta_info *
272 * This function is called to check station activity and to remove inactive
275 void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
277 struct hostapd_data *hapd = eloop_ctx;
278 struct sta_info *sta = timeout_ctx;
279 unsigned long next_time = 0;
281 wpa_printf(MSG_DEBUG, "%s: " MACSTR " flags=0x%x timeout_next=%d",
282 __func__, MAC2STR(sta->addr), sta->flags,
284 if (sta->timeout_next == STA_REMOVE) {
285 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
286 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
287 "local deauth request");
288 ap_free_sta(hapd, sta);
292 if ((sta->flags & WLAN_STA_ASSOC) &&
293 (sta->timeout_next == STA_NULLFUNC ||
294 sta->timeout_next == STA_DISASSOC)) {
297 * Add random value to timeout so that we don't end up bouncing
298 * all stations at the same time if we have lots of associated
299 * stations that are idle (but keep re-associating).
301 int fuzz = os_random() % 20;
302 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
303 if (inactive_sec == -1) {
304 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
305 "Check inactivity: Could not "
306 "get station info from kernel driver for "
307 MACSTR, MAC2STR(sta->addr));
309 * The driver may not support this functionality.
310 * Anyway, try again after the next inactivity timeout,
311 * but do not disconnect the station now.
313 next_time = hapd->conf->ap_max_inactivity + fuzz;
314 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
315 sta->flags & WLAN_STA_ASSOC) {
316 /* station activity detected; reset timeout state */
317 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
318 "Station " MACSTR " has been active %is ago",
319 MAC2STR(sta->addr), inactive_sec);
320 sta->timeout_next = STA_NULLFUNC;
321 next_time = hapd->conf->ap_max_inactivity + fuzz -
324 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
325 "Station " MACSTR " has been "
326 "inactive too long: %d sec, max allowed: %d",
327 MAC2STR(sta->addr), inactive_sec,
328 hapd->conf->ap_max_inactivity);
330 if (hapd->conf->skip_inactivity_poll)
331 sta->timeout_next = STA_DISASSOC;
335 if ((sta->flags & WLAN_STA_ASSOC) &&
336 sta->timeout_next == STA_DISASSOC &&
337 !(sta->flags & WLAN_STA_PENDING_POLL) &&
338 !hapd->conf->skip_inactivity_poll) {
339 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
340 " has ACKed data poll", MAC2STR(sta->addr));
341 /* data nullfunc frame poll did not produce TX errors; assume
342 * station ACKed it */
343 sta->timeout_next = STA_NULLFUNC;
344 next_time = hapd->conf->ap_max_inactivity;
348 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
349 "for " MACSTR " (%lu seconds)",
350 __func__, MAC2STR(sta->addr), next_time);
351 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
356 if (sta->timeout_next == STA_NULLFUNC &&
357 (sta->flags & WLAN_STA_ASSOC)) {
358 wpa_printf(MSG_DEBUG, " Polling STA");
359 sta->flags |= WLAN_STA_PENDING_POLL;
360 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
361 sta->flags & WLAN_STA_WMM);
362 } else if (sta->timeout_next != STA_REMOVE) {
363 int deauth = sta->timeout_next == STA_DEAUTH;
365 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
366 "Timeout, sending %s info to STA " MACSTR,
367 deauth ? "deauthentication" : "disassociation",
371 hostapd_drv_sta_deauth(
373 WLAN_REASON_PREV_AUTH_NOT_VALID);
375 hostapd_drv_sta_disassoc(
377 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
381 switch (sta->timeout_next) {
383 sta->timeout_next = STA_DISASSOC;
384 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
385 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
386 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
387 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
391 ap_sta_set_authorized(hapd, sta, 0);
392 sta->flags &= ~WLAN_STA_ASSOC;
393 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
394 if (!sta->acct_terminate_cause)
395 sta->acct_terminate_cause =
396 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
397 accounting_sta_stop(hapd, sta);
398 ieee802_1x_free_station(sta);
399 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
400 HOSTAPD_LEVEL_INFO, "disassociated due to "
402 sta->timeout_next = STA_DEAUTH;
403 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
404 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
405 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
406 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
408 mlme_disassociate_indication(
409 hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
413 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
414 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
415 "inactivity (timer DEAUTH/REMOVE)");
416 if (!sta->acct_terminate_cause)
417 sta->acct_terminate_cause =
418 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
419 mlme_deauthenticate_indication(
421 WLAN_REASON_PREV_AUTH_NOT_VALID);
422 ap_free_sta(hapd, sta);
428 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
430 struct hostapd_data *hapd = eloop_ctx;
431 struct sta_info *sta = timeout_ctx;
434 if (!(sta->flags & WLAN_STA_AUTH)) {
435 if (sta->flags & WLAN_STA_GAS) {
436 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
437 "entry " MACSTR, MAC2STR(sta->addr));
438 ap_free_sta(hapd, sta);
443 mlme_deauthenticate_indication(hapd, sta,
444 WLAN_REASON_PREV_AUTH_NOT_VALID);
445 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
446 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
448 sta->acct_terminate_cause =
449 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
450 os_memcpy(addr, sta->addr, ETH_ALEN);
451 ap_free_sta(hapd, sta);
452 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
456 void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
459 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
460 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
461 "seconds", session_timeout);
462 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
463 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
468 void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
470 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
474 struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
476 struct sta_info *sta;
478 sta = ap_get_sta(hapd, addr);
482 wpa_printf(MSG_DEBUG, " New STA");
483 if (hapd->num_sta >= hapd->conf->max_num_sta) {
484 /* FIX: might try to remove some old STAs first? */
485 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
486 hapd->num_sta, hapd->conf->max_num_sta);
490 sta = os_zalloc(sizeof(struct sta_info));
492 wpa_printf(MSG_ERROR, "malloc failed");
495 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
497 /* initialize STA info data */
498 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
499 "for " MACSTR " (%d seconds - ap_max_inactivity)",
500 __func__, MAC2STR(addr),
501 hapd->conf->ap_max_inactivity);
502 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
503 ap_handle_timer, hapd, sta);
504 os_memcpy(sta->addr, addr, ETH_ALEN);
505 sta->next = hapd->sta_list;
506 hapd->sta_list = sta;
508 ap_sta_hash_add(hapd, sta);
509 sta->ssid = &hapd->conf->ssid;
510 ap_sta_remove_in_other_bss(hapd, sta);
516 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
518 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
520 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
522 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
523 sta->flags & WLAN_STA_ASSOC) {
524 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
525 " from kernel driver.", MAC2STR(sta->addr));
532 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
533 struct sta_info *sta)
535 struct hostapd_iface *iface = hapd->iface;
538 for (i = 0; i < iface->num_bss; i++) {
539 struct hostapd_data *bss = iface->bss[i];
540 struct sta_info *sta2;
541 /* bss should always be set during operation, but it may be
542 * NULL during reconfiguration. Assume the STA is not
543 * associated to another BSS in that case to avoid NULL pointer
545 if (bss == hapd || bss == NULL)
547 sta2 = ap_get_sta(bss, sta->addr);
551 ap_sta_disconnect(bss, sta2, sta2->addr,
552 WLAN_REASON_PREV_AUTH_NOT_VALID);
557 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
559 struct hostapd_data *hapd = eloop_ctx;
560 struct sta_info *sta = timeout_ctx;
562 ap_sta_remove(hapd, sta);
563 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
567 void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
570 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
571 hapd->conf->iface, MAC2STR(sta->addr));
572 sta->flags &= ~WLAN_STA_ASSOC;
573 ap_sta_set_authorized(hapd, sta, 0);
574 sta->timeout_next = STA_DEAUTH;
575 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
576 "for " MACSTR " (%d seconds - "
577 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
578 __func__, MAC2STR(sta->addr),
579 AP_MAX_INACTIVITY_AFTER_DISASSOC);
580 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
581 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
582 ap_handle_timer, hapd, sta);
583 accounting_sta_stop(hapd, sta);
584 ieee802_1x_free_station(sta);
586 sta->disassoc_reason = reason;
587 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
588 eloop_cancel_timeout(ap_sta_disassoc_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_disassoc_cb_timeout, hapd, sta);
595 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
597 struct hostapd_data *hapd = eloop_ctx;
598 struct sta_info *sta = timeout_ctx;
600 ap_sta_remove(hapd, sta);
601 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
605 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
608 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
609 hapd->conf->iface, MAC2STR(sta->addr));
610 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
611 ap_sta_set_authorized(hapd, sta, 0);
612 sta->timeout_next = STA_REMOVE;
613 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
614 "for " MACSTR " (%d seconds - "
615 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
616 __func__, MAC2STR(sta->addr),
617 AP_MAX_INACTIVITY_AFTER_DEAUTH);
618 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
619 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
620 ap_handle_timer, hapd, sta);
621 accounting_sta_stop(hapd, sta);
622 ieee802_1x_free_station(sta);
624 sta->deauth_reason = reason;
625 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
626 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
627 eloop_register_timeout(hapd->iface->drv_flags &
628 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
629 ap_sta_deauth_cb_timeout, hapd, sta);
634 int ap_sta_wps_cancel(struct hostapd_data *hapd,
635 struct sta_info *sta, void *ctx)
637 if (sta && (sta->flags & WLAN_STA_WPS)) {
638 ap_sta_deauthenticate(hapd, sta,
639 WLAN_REASON_PREV_AUTH_NOT_VALID);
640 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
641 __func__, MAC2STR(sta->addr));
647 #endif /* CONFIG_WPS */
650 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
653 #ifndef CONFIG_NO_VLAN
655 struct hostapd_vlan *vlan = NULL;
659 * Do not proceed furthur if the vlan id remains same. We do not want
660 * duplicate dynamic vlan entries.
662 if (sta->vlan_id == old_vlanid)
666 * During 1x reauth, if the vlan id changes, then remove the old id and
667 * proceed furthur to add the new one.
670 vlan_remove_dynamic(hapd, old_vlanid);
672 iface = hapd->conf->iface;
673 if (sta->ssid->vlan[0])
674 iface = sta->ssid->vlan;
676 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
678 else if (sta->vlan_id > 0) {
679 vlan = hapd->conf->vlan;
681 if (vlan->vlan_id == sta->vlan_id ||
682 vlan->vlan_id == VLAN_ID_WILDCARD) {
683 iface = vlan->ifname;
690 if (sta->vlan_id > 0 && vlan == NULL) {
691 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
692 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
693 "binding station to (vlan_id=%d)",
696 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
697 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
699 hostapd_logger(hapd, sta->addr,
700 HOSTAPD_MODULE_IEEE80211,
701 HOSTAPD_LEVEL_DEBUG, "could not add "
702 "dynamic VLAN interface for vlan_id=%d",
707 iface = vlan->ifname;
708 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
709 hostapd_logger(hapd, sta->addr,
710 HOSTAPD_MODULE_IEEE80211,
711 HOSTAPD_LEVEL_DEBUG, "could not "
712 "configure encryption for dynamic VLAN "
713 "interface for vlan_id=%d",
717 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
718 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
719 "interface '%s'", iface);
720 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
721 if (sta->vlan_id > 0) {
722 vlan->dynamic_vlan++;
723 hostapd_logger(hapd, sta->addr,
724 HOSTAPD_MODULE_IEEE80211,
725 HOSTAPD_LEVEL_DEBUG, "updated existing "
726 "dynamic VLAN interface '%s'", iface);
730 * Update encryption configuration for statically generated
731 * VLAN interface. This is only used for static WEP
732 * configuration for the case where hostapd did not yet know
733 * which keys are to be used when the interface was added.
735 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
736 hostapd_logger(hapd, sta->addr,
737 HOSTAPD_MODULE_IEEE80211,
738 HOSTAPD_LEVEL_DEBUG, "could not "
739 "configure encryption for VLAN "
740 "interface for vlan_id=%d",
745 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
746 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
749 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
750 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
752 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
754 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
755 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
756 "entry to vlan_id=%d", sta->vlan_id);
759 #else /* CONFIG_NO_VLAN */
761 #endif /* CONFIG_NO_VLAN */
765 #ifdef CONFIG_IEEE80211W
767 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
770 struct os_time now, passed;
772 os_time_sub(&now, &sta->sa_query_start, &passed);
773 tu = (passed.sec * 1000000 + passed.usec) / 1024;
774 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
775 hostapd_logger(hapd, sta->addr,
776 HOSTAPD_MODULE_IEEE80211,
778 "association SA Query timed out");
779 sta->sa_query_timed_out = 1;
780 os_free(sta->sa_query_trans_id);
781 sta->sa_query_trans_id = NULL;
782 sta->sa_query_count = 0;
783 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
791 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
793 struct hostapd_data *hapd = eloop_ctx;
794 struct sta_info *sta = timeout_ctx;
795 unsigned int timeout, sec, usec;
798 if (sta->sa_query_count > 0 &&
799 ap_check_sa_query_timeout(hapd, sta))
802 nbuf = os_realloc_array(sta->sa_query_trans_id,
803 sta->sa_query_count + 1,
804 WLAN_SA_QUERY_TR_ID_LEN);
807 if (sta->sa_query_count == 0) {
808 /* Starting a new SA Query procedure */
809 os_get_time(&sta->sa_query_start);
811 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
812 sta->sa_query_trans_id = nbuf;
813 sta->sa_query_count++;
815 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
817 timeout = hapd->conf->assoc_sa_query_retry_timeout;
818 sec = ((timeout / 1000) * 1024) / 1000;
819 usec = (timeout % 1000) * 1024;
820 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
822 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
824 "association SA Query attempt %d", sta->sa_query_count);
826 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
830 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
832 ap_sa_query_timer(hapd, sta);
836 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
838 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
839 os_free(sta->sa_query_trans_id);
840 sta->sa_query_trans_id = NULL;
841 sta->sa_query_count = 0;
844 #endif /* CONFIG_IEEE80211W */
847 void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
850 const u8 *dev_addr = NULL;
853 #endif /* CONFIG_P2P */
855 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
859 if (hapd->p2p_group == NULL) {
860 if (sta->p2p_ie != NULL &&
861 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
864 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
865 #endif /* CONFIG_P2P */
869 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
870 MACSTR " p2p_dev_addr=" MACSTR,
871 MAC2STR(sta->addr), MAC2STR(dev_addr));
873 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
874 MACSTR, MAC2STR(sta->addr));
875 if (hapd->msg_ctx_parent &&
876 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
877 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
878 AP_STA_CONNECTED MACSTR " p2p_dev_addr="
880 MAC2STR(sta->addr), MAC2STR(dev_addr));
881 else if (hapd->msg_ctx_parent &&
882 hapd->msg_ctx_parent != hapd->msg_ctx)
883 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
884 AP_STA_CONNECTED MACSTR, MAC2STR(sta->addr));
886 sta->flags |= WLAN_STA_AUTHORIZED;
889 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
890 MACSTR " p2p_dev_addr=" MACSTR,
891 MAC2STR(sta->addr), MAC2STR(dev_addr));
893 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
894 MACSTR, MAC2STR(sta->addr));
895 if (hapd->msg_ctx_parent &&
896 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
897 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
898 AP_STA_DISCONNECTED MACSTR " p2p_dev_addr="
899 MACSTR, MAC2STR(sta->addr), MAC2STR(dev_addr));
900 else if (hapd->msg_ctx_parent &&
901 hapd->msg_ctx_parent != hapd->msg_ctx)
902 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
903 AP_STA_DISCONNECTED MACSTR,
905 sta->flags &= ~WLAN_STA_AUTHORIZED;
908 if (hapd->sta_authorized_cb)
909 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
910 sta->addr, authorized, dev_addr);
914 void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
915 const u8 *addr, u16 reason)
918 if (sta == NULL && addr)
919 sta = ap_get_sta(hapd, addr);
922 hostapd_drv_sta_deauth(hapd, addr, reason);
926 ap_sta_set_authorized(hapd, sta, 0);
927 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
928 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
929 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
930 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
931 "for " MACSTR " (%d seconds - "
932 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
933 __func__, MAC2STR(sta->addr),
934 AP_MAX_INACTIVITY_AFTER_DEAUTH);
935 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
936 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
937 ap_handle_timer, hapd, sta);
938 sta->timeout_next = STA_REMOVE;
940 sta->deauth_reason = reason;
941 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
942 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
943 eloop_register_timeout(hapd->iface->drv_flags &
944 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
945 ap_sta_deauth_cb_timeout, hapd, sta);
949 void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
951 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
952 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
955 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
956 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
957 ap_sta_deauth_cb_timeout(hapd, sta);
961 void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
963 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
964 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
967 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
968 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
969 ap_sta_disassoc_cb_timeout(hapd, sta);