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);
235 wpabuf_free(sta->hs20_ie);
237 os_free(sta->ht_capabilities);
239 os_free(sta->identity);
240 os_free(sta->radius_cui);
246 void hostapd_free_stas(struct hostapd_data *hapd)
248 struct sta_info *sta, *prev;
250 sta = hapd->sta_list;
254 if (sta->flags & WLAN_STA_AUTH) {
255 mlme_deauthenticate_indication(
256 hapd, sta, WLAN_REASON_UNSPECIFIED);
259 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
260 MAC2STR(prev->addr));
261 ap_free_sta(hapd, prev);
267 * ap_handle_timer - Per STA timer handler
268 * @eloop_ctx: struct hostapd_data *
269 * @timeout_ctx: struct sta_info *
271 * This function is called to check station activity and to remove inactive
274 void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
276 struct hostapd_data *hapd = eloop_ctx;
277 struct sta_info *sta = timeout_ctx;
278 unsigned long next_time = 0;
280 wpa_printf(MSG_DEBUG, "%s: " MACSTR " flags=0x%x timeout_next=%d",
281 __func__, MAC2STR(sta->addr), sta->flags,
283 if (sta->timeout_next == STA_REMOVE) {
284 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
285 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
286 "local deauth request");
287 ap_free_sta(hapd, sta);
291 if ((sta->flags & WLAN_STA_ASSOC) &&
292 (sta->timeout_next == STA_NULLFUNC ||
293 sta->timeout_next == STA_DISASSOC)) {
296 * Add random value to timeout so that we don't end up bouncing
297 * all stations at the same time if we have lots of associated
298 * stations that are idle (but keep re-associating).
300 int fuzz = os_random() % 20;
301 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
302 if (inactive_sec == -1) {
303 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
304 "Check inactivity: Could not "
305 "get station info from kernel driver for "
306 MACSTR, MAC2STR(sta->addr));
308 * The driver may not support this functionality.
309 * Anyway, try again after the next inactivity timeout,
310 * but do not disconnect the station now.
312 next_time = hapd->conf->ap_max_inactivity + fuzz;
313 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
314 sta->flags & WLAN_STA_ASSOC) {
315 /* station activity detected; reset timeout state */
316 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
317 "Station " MACSTR " has been active %is ago",
318 MAC2STR(sta->addr), inactive_sec);
319 sta->timeout_next = STA_NULLFUNC;
320 next_time = hapd->conf->ap_max_inactivity + fuzz -
323 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
324 "Station " MACSTR " has been "
325 "inactive too long: %d sec, max allowed: %d",
326 MAC2STR(sta->addr), inactive_sec,
327 hapd->conf->ap_max_inactivity);
329 if (hapd->conf->skip_inactivity_poll)
330 sta->timeout_next = STA_DISASSOC;
334 if ((sta->flags & WLAN_STA_ASSOC) &&
335 sta->timeout_next == STA_DISASSOC &&
336 !(sta->flags & WLAN_STA_PENDING_POLL) &&
337 !hapd->conf->skip_inactivity_poll) {
338 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
339 " has ACKed data poll", MAC2STR(sta->addr));
340 /* data nullfunc frame poll did not produce TX errors; assume
341 * station ACKed it */
342 sta->timeout_next = STA_NULLFUNC;
343 next_time = hapd->conf->ap_max_inactivity;
347 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
348 "for " MACSTR " (%lu seconds)",
349 __func__, MAC2STR(sta->addr), next_time);
350 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
355 if (sta->timeout_next == STA_NULLFUNC &&
356 (sta->flags & WLAN_STA_ASSOC)) {
357 wpa_printf(MSG_DEBUG, " Polling STA");
358 sta->flags |= WLAN_STA_PENDING_POLL;
359 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
360 sta->flags & WLAN_STA_WMM);
361 } else if (sta->timeout_next != STA_REMOVE) {
362 int deauth = sta->timeout_next == STA_DEAUTH;
364 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
365 "Timeout, sending %s info to STA " MACSTR,
366 deauth ? "deauthentication" : "disassociation",
370 hostapd_drv_sta_deauth(
372 WLAN_REASON_PREV_AUTH_NOT_VALID);
374 hostapd_drv_sta_disassoc(
376 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
380 switch (sta->timeout_next) {
382 sta->timeout_next = STA_DISASSOC;
383 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
384 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
385 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
386 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
390 ap_sta_set_authorized(hapd, sta, 0);
391 sta->flags &= ~WLAN_STA_ASSOC;
392 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
393 if (!sta->acct_terminate_cause)
394 sta->acct_terminate_cause =
395 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
396 accounting_sta_stop(hapd, sta);
397 ieee802_1x_free_station(sta);
398 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
399 HOSTAPD_LEVEL_INFO, "disassociated due to "
401 sta->timeout_next = STA_DEAUTH;
402 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
403 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
404 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
405 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
407 mlme_disassociate_indication(
408 hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
412 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
413 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
414 "inactivity (timer DEAUTH/REMOVE)");
415 if (!sta->acct_terminate_cause)
416 sta->acct_terminate_cause =
417 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
418 mlme_deauthenticate_indication(
420 WLAN_REASON_PREV_AUTH_NOT_VALID);
421 ap_free_sta(hapd, sta);
427 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
429 struct hostapd_data *hapd = eloop_ctx;
430 struct sta_info *sta = timeout_ctx;
433 if (!(sta->flags & WLAN_STA_AUTH)) {
434 if (sta->flags & WLAN_STA_GAS) {
435 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
436 "entry " MACSTR, MAC2STR(sta->addr));
437 ap_free_sta(hapd, sta);
442 mlme_deauthenticate_indication(hapd, sta,
443 WLAN_REASON_PREV_AUTH_NOT_VALID);
444 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
445 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
447 sta->acct_terminate_cause =
448 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
449 os_memcpy(addr, sta->addr, ETH_ALEN);
450 ap_free_sta(hapd, sta);
451 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
455 void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
458 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
459 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
460 "seconds", session_timeout);
461 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
462 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
467 void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
469 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
473 struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
475 struct sta_info *sta;
477 sta = ap_get_sta(hapd, addr);
481 wpa_printf(MSG_DEBUG, " New STA");
482 if (hapd->num_sta >= hapd->conf->max_num_sta) {
483 /* FIX: might try to remove some old STAs first? */
484 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
485 hapd->num_sta, hapd->conf->max_num_sta);
489 sta = os_zalloc(sizeof(struct sta_info));
491 wpa_printf(MSG_ERROR, "malloc failed");
494 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
496 /* initialize STA info data */
497 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
498 "for " MACSTR " (%d seconds - ap_max_inactivity)",
499 __func__, MAC2STR(addr),
500 hapd->conf->ap_max_inactivity);
501 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
502 ap_handle_timer, hapd, sta);
503 os_memcpy(sta->addr, addr, ETH_ALEN);
504 sta->next = hapd->sta_list;
505 hapd->sta_list = sta;
507 ap_sta_hash_add(hapd, sta);
508 sta->ssid = &hapd->conf->ssid;
509 ap_sta_remove_in_other_bss(hapd, sta);
515 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
517 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
519 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
521 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
522 sta->flags & WLAN_STA_ASSOC) {
523 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
524 " from kernel driver.", MAC2STR(sta->addr));
531 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
532 struct sta_info *sta)
534 struct hostapd_iface *iface = hapd->iface;
537 for (i = 0; i < iface->num_bss; i++) {
538 struct hostapd_data *bss = iface->bss[i];
539 struct sta_info *sta2;
540 /* bss should always be set during operation, but it may be
541 * NULL during reconfiguration. Assume the STA is not
542 * associated to another BSS in that case to avoid NULL pointer
544 if (bss == hapd || bss == NULL)
546 sta2 = ap_get_sta(bss, sta->addr);
550 ap_sta_disconnect(bss, sta2, sta2->addr,
551 WLAN_REASON_PREV_AUTH_NOT_VALID);
556 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
558 struct hostapd_data *hapd = eloop_ctx;
559 struct sta_info *sta = timeout_ctx;
561 ap_sta_remove(hapd, sta);
562 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
566 void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
569 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
570 hapd->conf->iface, MAC2STR(sta->addr));
571 sta->flags &= ~WLAN_STA_ASSOC;
572 ap_sta_set_authorized(hapd, sta, 0);
573 sta->timeout_next = STA_DEAUTH;
574 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
575 "for " MACSTR " (%d seconds - "
576 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
577 __func__, MAC2STR(sta->addr),
578 AP_MAX_INACTIVITY_AFTER_DISASSOC);
579 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
580 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
581 ap_handle_timer, hapd, sta);
582 accounting_sta_stop(hapd, sta);
583 ieee802_1x_free_station(sta);
585 sta->disassoc_reason = reason;
586 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
587 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
588 eloop_register_timeout(hapd->iface->drv_flags &
589 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
590 ap_sta_disassoc_cb_timeout, hapd, sta);
594 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
596 struct hostapd_data *hapd = eloop_ctx;
597 struct sta_info *sta = timeout_ctx;
599 ap_sta_remove(hapd, sta);
600 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
604 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
607 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
608 hapd->conf->iface, MAC2STR(sta->addr));
609 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
610 ap_sta_set_authorized(hapd, sta, 0);
611 sta->timeout_next = STA_REMOVE;
612 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
613 "for " MACSTR " (%d seconds - "
614 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
615 __func__, MAC2STR(sta->addr),
616 AP_MAX_INACTIVITY_AFTER_DEAUTH);
617 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
618 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
619 ap_handle_timer, hapd, sta);
620 accounting_sta_stop(hapd, sta);
621 ieee802_1x_free_station(sta);
623 sta->deauth_reason = reason;
624 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
625 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
626 eloop_register_timeout(hapd->iface->drv_flags &
627 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
628 ap_sta_deauth_cb_timeout, hapd, sta);
633 int ap_sta_wps_cancel(struct hostapd_data *hapd,
634 struct sta_info *sta, void *ctx)
636 if (sta && (sta->flags & WLAN_STA_WPS)) {
637 ap_sta_deauthenticate(hapd, sta,
638 WLAN_REASON_PREV_AUTH_NOT_VALID);
639 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
640 __func__, MAC2STR(sta->addr));
646 #endif /* CONFIG_WPS */
649 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
652 #ifndef CONFIG_NO_VLAN
654 struct hostapd_vlan *vlan = NULL;
658 * Do not proceed furthur if the vlan id remains same. We do not want
659 * duplicate dynamic vlan entries.
661 if (sta->vlan_id == old_vlanid)
665 * During 1x reauth, if the vlan id changes, then remove the old id and
666 * proceed furthur to add the new one.
669 vlan_remove_dynamic(hapd, old_vlanid);
671 iface = hapd->conf->iface;
672 if (sta->ssid->vlan[0])
673 iface = sta->ssid->vlan;
675 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
677 else if (sta->vlan_id > 0) {
678 vlan = hapd->conf->vlan;
680 if (vlan->vlan_id == sta->vlan_id ||
681 vlan->vlan_id == VLAN_ID_WILDCARD) {
682 iface = vlan->ifname;
689 if (sta->vlan_id > 0 && vlan == NULL) {
690 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
691 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
692 "binding station to (vlan_id=%d)",
695 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
696 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
698 hostapd_logger(hapd, sta->addr,
699 HOSTAPD_MODULE_IEEE80211,
700 HOSTAPD_LEVEL_DEBUG, "could not add "
701 "dynamic VLAN interface for vlan_id=%d",
706 iface = vlan->ifname;
707 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
708 hostapd_logger(hapd, sta->addr,
709 HOSTAPD_MODULE_IEEE80211,
710 HOSTAPD_LEVEL_DEBUG, "could not "
711 "configure encryption for dynamic VLAN "
712 "interface for vlan_id=%d",
716 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
717 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
718 "interface '%s'", iface);
719 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
720 if (sta->vlan_id > 0) {
721 vlan->dynamic_vlan++;
722 hostapd_logger(hapd, sta->addr,
723 HOSTAPD_MODULE_IEEE80211,
724 HOSTAPD_LEVEL_DEBUG, "updated existing "
725 "dynamic VLAN interface '%s'", iface);
729 * Update encryption configuration for statically generated
730 * VLAN interface. This is only used for static WEP
731 * configuration for the case where hostapd did not yet know
732 * which keys are to be used when the interface was added.
734 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
735 hostapd_logger(hapd, sta->addr,
736 HOSTAPD_MODULE_IEEE80211,
737 HOSTAPD_LEVEL_DEBUG, "could not "
738 "configure encryption for VLAN "
739 "interface for vlan_id=%d",
744 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
745 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
748 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
749 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
751 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
753 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
754 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
755 "entry to vlan_id=%d", sta->vlan_id);
758 #else /* CONFIG_NO_VLAN */
760 #endif /* CONFIG_NO_VLAN */
764 #ifdef CONFIG_IEEE80211W
766 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
769 struct os_time now, passed;
771 os_time_sub(&now, &sta->sa_query_start, &passed);
772 tu = (passed.sec * 1000000 + passed.usec) / 1024;
773 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
774 hostapd_logger(hapd, sta->addr,
775 HOSTAPD_MODULE_IEEE80211,
777 "association SA Query timed out");
778 sta->sa_query_timed_out = 1;
779 os_free(sta->sa_query_trans_id);
780 sta->sa_query_trans_id = NULL;
781 sta->sa_query_count = 0;
782 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
790 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
792 struct hostapd_data *hapd = eloop_ctx;
793 struct sta_info *sta = timeout_ctx;
794 unsigned int timeout, sec, usec;
797 if (sta->sa_query_count > 0 &&
798 ap_check_sa_query_timeout(hapd, sta))
801 nbuf = os_realloc_array(sta->sa_query_trans_id,
802 sta->sa_query_count + 1,
803 WLAN_SA_QUERY_TR_ID_LEN);
806 if (sta->sa_query_count == 0) {
807 /* Starting a new SA Query procedure */
808 os_get_time(&sta->sa_query_start);
810 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
811 sta->sa_query_trans_id = nbuf;
812 sta->sa_query_count++;
814 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
816 timeout = hapd->conf->assoc_sa_query_retry_timeout;
817 sec = ((timeout / 1000) * 1024) / 1000;
818 usec = (timeout % 1000) * 1024;
819 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
821 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
823 "association SA Query attempt %d", sta->sa_query_count);
825 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
829 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
831 ap_sa_query_timer(hapd, sta);
835 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
837 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
838 os_free(sta->sa_query_trans_id);
839 sta->sa_query_trans_id = NULL;
840 sta->sa_query_count = 0;
843 #endif /* CONFIG_IEEE80211W */
846 void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
849 const u8 *dev_addr = NULL;
852 #endif /* CONFIG_P2P */
854 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
858 if (hapd->p2p_group == NULL) {
859 if (sta->p2p_ie != NULL &&
860 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
863 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
864 #endif /* CONFIG_P2P */
868 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
869 MACSTR " p2p_dev_addr=" MACSTR,
870 MAC2STR(sta->addr), MAC2STR(dev_addr));
872 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
873 MACSTR, MAC2STR(sta->addr));
874 if (hapd->msg_ctx_parent &&
875 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
876 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
877 AP_STA_CONNECTED MACSTR " p2p_dev_addr="
879 MAC2STR(sta->addr), MAC2STR(dev_addr));
880 else if (hapd->msg_ctx_parent &&
881 hapd->msg_ctx_parent != hapd->msg_ctx)
882 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
883 AP_STA_CONNECTED MACSTR, MAC2STR(sta->addr));
885 sta->flags |= WLAN_STA_AUTHORIZED;
888 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
889 MACSTR " p2p_dev_addr=" MACSTR,
890 MAC2STR(sta->addr), MAC2STR(dev_addr));
892 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
893 MACSTR, MAC2STR(sta->addr));
894 if (hapd->msg_ctx_parent &&
895 hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
896 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
897 AP_STA_DISCONNECTED MACSTR " p2p_dev_addr="
898 MACSTR, MAC2STR(sta->addr), MAC2STR(dev_addr));
899 else if (hapd->msg_ctx_parent &&
900 hapd->msg_ctx_parent != hapd->msg_ctx)
901 wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
902 AP_STA_DISCONNECTED MACSTR,
904 sta->flags &= ~WLAN_STA_AUTHORIZED;
907 if (hapd->sta_authorized_cb)
908 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
909 sta->addr, authorized, dev_addr);
913 void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
914 const u8 *addr, u16 reason)
917 if (sta == NULL && addr)
918 sta = ap_get_sta(hapd, addr);
921 hostapd_drv_sta_deauth(hapd, addr, reason);
925 ap_sta_set_authorized(hapd, sta, 0);
926 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
927 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
928 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
929 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
930 "for " MACSTR " (%d seconds - "
931 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
932 __func__, MAC2STR(sta->addr),
933 AP_MAX_INACTIVITY_AFTER_DEAUTH);
934 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
935 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
936 ap_handle_timer, hapd, sta);
937 sta->timeout_next = STA_REMOVE;
939 sta->deauth_reason = reason;
940 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
941 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
942 eloop_register_timeout(hapd->iface->drv_flags &
943 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
944 ap_sta_deauth_cb_timeout, hapd, sta);
948 void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
950 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
951 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
954 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
955 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
956 ap_sta_deauth_cb_timeout(hapd, sta);
960 void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
962 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
963 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
966 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
967 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
968 ap_sta_disassoc_cb_timeout(hapd, sta);