2 * hostapd / Station table
3 * Copyright (c) 2002-2013, 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 "common/sae.h"
16 #include "radius/radius.h"
17 #include "radius/radius_client.h"
18 #include "drivers/driver.h"
21 #include "accounting.h"
22 #include "ieee802_1x.h"
23 #include "ieee802_11.h"
24 #include "ieee802_11_auth.h"
26 #include "preauth_auth.h"
27 #include "ap_config.h"
30 #include "vlan_init.h"
31 #include "p2p_hostapd.h"
32 #include "ap_drv_ops.h"
36 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
37 struct sta_info *sta);
38 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
39 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
40 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
41 #ifdef CONFIG_IEEE80211W
42 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
43 #endif /* CONFIG_IEEE80211W */
44 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
46 int ap_for_each_sta(struct hostapd_data *hapd,
47 int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
53 for (sta = hapd->sta_list; sta; sta = sta->next) {
54 if (cb(hapd, sta, ctx))
62 struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
66 s = hapd->sta_hash[STA_HASH(sta)];
67 while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
74 struct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr)
78 for (sta = hapd->sta_list; sta; sta = sta->next) {
79 const u8 *p2p_dev_addr;
81 if (sta->p2p_ie == NULL)
84 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
85 if (p2p_dev_addr == NULL)
88 if (os_memcmp(p2p_dev_addr, addr, ETH_ALEN) == 0)
94 #endif /* CONFIG_P2P */
97 static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
101 if (hapd->sta_list == sta) {
102 hapd->sta_list = sta->next;
106 tmp = hapd->sta_list;
107 while (tmp != NULL && tmp->next != sta)
110 wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
111 "list.", MAC2STR(sta->addr));
113 tmp->next = sta->next;
117 void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
119 sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
120 hapd->sta_hash[STA_HASH(sta->addr)] = sta;
124 static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
128 s = hapd->sta_hash[STA_HASH(sta->addr)];
129 if (s == NULL) return;
130 if (os_memcmp(s->addr, sta->addr, 6) == 0) {
131 hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
135 while (s->hnext != NULL &&
136 os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
138 if (s->hnext != NULL)
139 s->hnext = s->hnext->hnext;
141 wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
142 " from hash table", MAC2STR(sta->addr));
146 void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
150 accounting_sta_stop(hapd, sta);
153 ap_sta_set_authorized(hapd, sta, 0);
155 if (sta->flags & WLAN_STA_WDS)
156 hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0);
158 if (!(sta->flags & WLAN_STA_PREAUTH))
159 hostapd_drv_sta_remove(hapd, sta->addr);
161 ap_sta_hash_del(hapd, sta);
162 ap_sta_list_del(hapd, sta);
165 hapd->sta_aid[(sta->aid - 1) / 32] &=
166 ~BIT((sta->aid - 1) % 32);
169 if (sta->nonerp_set) {
171 hapd->iface->num_sta_non_erp--;
172 if (hapd->iface->num_sta_non_erp == 0)
176 if (sta->no_short_slot_time_set) {
177 sta->no_short_slot_time_set = 0;
178 hapd->iface->num_sta_no_short_slot_time--;
179 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
180 && hapd->iface->num_sta_no_short_slot_time == 0)
184 if (sta->no_short_preamble_set) {
185 sta->no_short_preamble_set = 0;
186 hapd->iface->num_sta_no_short_preamble--;
187 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
188 && hapd->iface->num_sta_no_short_preamble == 0)
192 if (sta->no_ht_gf_set) {
193 sta->no_ht_gf_set = 0;
194 hapd->iface->num_sta_ht_no_gf--;
197 if (sta->no_ht_set) {
199 hapd->iface->num_sta_no_ht--;
202 if (sta->ht_20mhz_set) {
203 sta->ht_20mhz_set = 0;
204 hapd->iface->num_sta_ht_20mhz--;
208 if (sta->no_p2p_set) {
210 hapd->num_sta_no_p2p--;
211 if (hapd->num_sta_no_p2p == 0)
212 hostapd_p2p_non_p2p_sta_disconnected(hapd);
214 #endif /* CONFIG_P2P */
216 #if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
217 if (hostapd_ht_operation_update(hapd->iface) > 0)
219 #endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
222 ieee802_11_set_beacons(hapd->iface);
224 wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
225 __func__, MAC2STR(sta->addr));
226 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
227 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
228 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
229 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
231 ieee802_1x_free_station(sta);
232 wpa_auth_sta_deinit(sta->wpa_sm);
233 rsn_preauth_free_station(hapd, sta);
234 #ifndef CONFIG_NO_RADIUS
236 radius_client_flush_auth(hapd->radius, sta->addr);
237 #endif /* CONFIG_NO_RADIUS */
239 os_free(sta->last_assoc_req);
240 os_free(sta->challenge);
242 #ifdef CONFIG_IEEE80211W
243 os_free(sta->sa_query_trans_id);
244 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
245 #endif /* CONFIG_IEEE80211W */
248 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
249 #endif /* CONFIG_P2P */
251 #ifdef CONFIG_INTERWORKING
252 if (sta->gas_dialog) {
254 for (i = 0; i < GAS_DIALOG_MAX; i++)
255 gas_serv_dialog_clear(&sta->gas_dialog[i]);
256 os_free(sta->gas_dialog);
258 #endif /* CONFIG_INTERWORKING */
260 wpabuf_free(sta->wps_ie);
261 wpabuf_free(sta->p2p_ie);
262 wpabuf_free(sta->hs20_ie);
264 os_free(sta->ht_capabilities);
265 hostapd_free_psk_list(sta->psk);
266 os_free(sta->identity);
267 os_free(sta->radius_cui);
270 sae_clear_data(sta->sae);
272 #endif /* CONFIG_SAE */
278 void hostapd_free_stas(struct hostapd_data *hapd)
280 struct sta_info *sta, *prev;
282 sta = hapd->sta_list;
286 if (sta->flags & WLAN_STA_AUTH) {
287 mlme_deauthenticate_indication(
288 hapd, sta, WLAN_REASON_UNSPECIFIED);
291 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
292 MAC2STR(prev->addr));
293 ap_free_sta(hapd, prev);
299 * ap_handle_timer - Per STA timer handler
300 * @eloop_ctx: struct hostapd_data *
301 * @timeout_ctx: struct sta_info *
303 * This function is called to check station activity and to remove inactive
306 void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
308 struct hostapd_data *hapd = eloop_ctx;
309 struct sta_info *sta = timeout_ctx;
310 unsigned long next_time = 0;
313 wpa_printf(MSG_DEBUG, "%s: " MACSTR " flags=0x%x timeout_next=%d",
314 __func__, MAC2STR(sta->addr), sta->flags,
316 if (sta->timeout_next == STA_REMOVE) {
317 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
318 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
319 "local deauth request");
320 ap_free_sta(hapd, sta);
324 if ((sta->flags & WLAN_STA_ASSOC) &&
325 (sta->timeout_next == STA_NULLFUNC ||
326 sta->timeout_next == STA_DISASSOC)) {
329 * Add random value to timeout so that we don't end up bouncing
330 * all stations at the same time if we have lots of associated
331 * stations that are idle (but keep re-associating).
333 int fuzz = os_random() % 20;
334 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
335 if (inactive_sec == -1) {
336 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
337 "Check inactivity: Could not "
338 "get station info from kernel driver for "
339 MACSTR, MAC2STR(sta->addr));
341 * The driver may not support this functionality.
342 * Anyway, try again after the next inactivity timeout,
343 * but do not disconnect the station now.
345 next_time = hapd->conf->ap_max_inactivity + fuzz;
346 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
347 sta->flags & WLAN_STA_ASSOC) {
348 /* station activity detected; reset timeout state */
349 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
350 "Station " MACSTR " has been active %is ago",
351 MAC2STR(sta->addr), inactive_sec);
352 sta->timeout_next = STA_NULLFUNC;
353 next_time = hapd->conf->ap_max_inactivity + fuzz -
356 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
357 "Station " MACSTR " has been "
358 "inactive too long: %d sec, max allowed: %d",
359 MAC2STR(sta->addr), inactive_sec,
360 hapd->conf->ap_max_inactivity);
362 if (hapd->conf->skip_inactivity_poll)
363 sta->timeout_next = STA_DISASSOC;
367 if ((sta->flags & WLAN_STA_ASSOC) &&
368 sta->timeout_next == STA_DISASSOC &&
369 !(sta->flags & WLAN_STA_PENDING_POLL) &&
370 !hapd->conf->skip_inactivity_poll) {
371 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
372 " has ACKed data poll", MAC2STR(sta->addr));
373 /* data nullfunc frame poll did not produce TX errors; assume
374 * station ACKed it */
375 sta->timeout_next = STA_NULLFUNC;
376 next_time = hapd->conf->ap_max_inactivity;
380 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
381 "for " MACSTR " (%lu seconds)",
382 __func__, MAC2STR(sta->addr), next_time);
383 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
388 if (sta->timeout_next == STA_NULLFUNC &&
389 (sta->flags & WLAN_STA_ASSOC)) {
390 wpa_printf(MSG_DEBUG, " Polling STA");
391 sta->flags |= WLAN_STA_PENDING_POLL;
392 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
393 sta->flags & WLAN_STA_WMM);
394 } else if (sta->timeout_next != STA_REMOVE) {
395 int deauth = sta->timeout_next == STA_DEAUTH;
397 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
398 "Timeout, sending %s info to STA " MACSTR,
399 deauth ? "deauthentication" : "disassociation",
403 hostapd_drv_sta_deauth(
405 WLAN_REASON_PREV_AUTH_NOT_VALID);
407 reason = (sta->timeout_next == STA_DISASSOC) ?
408 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
409 WLAN_REASON_PREV_AUTH_NOT_VALID;
411 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
415 switch (sta->timeout_next) {
417 sta->timeout_next = STA_DISASSOC;
418 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
419 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
420 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
421 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
425 case STA_DISASSOC_FROM_CLI:
426 ap_sta_set_authorized(hapd, sta, 0);
427 sta->flags &= ~WLAN_STA_ASSOC;
428 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
429 if (!sta->acct_terminate_cause)
430 sta->acct_terminate_cause =
431 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
432 accounting_sta_stop(hapd, sta);
433 ieee802_1x_free_station(sta);
434 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
435 HOSTAPD_LEVEL_INFO, "disassociated due to "
437 reason = (sta->timeout_next == STA_DISASSOC) ?
438 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
439 WLAN_REASON_PREV_AUTH_NOT_VALID;
440 sta->timeout_next = STA_DEAUTH;
441 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
442 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
443 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
444 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
446 mlme_disassociate_indication(hapd, sta, reason);
450 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
451 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
452 "inactivity (timer DEAUTH/REMOVE)");
453 if (!sta->acct_terminate_cause)
454 sta->acct_terminate_cause =
455 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
456 mlme_deauthenticate_indication(
458 WLAN_REASON_PREV_AUTH_NOT_VALID);
459 ap_free_sta(hapd, sta);
465 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
467 struct hostapd_data *hapd = eloop_ctx;
468 struct sta_info *sta = timeout_ctx;
471 if (!(sta->flags & WLAN_STA_AUTH)) {
472 if (sta->flags & WLAN_STA_GAS) {
473 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
474 "entry " MACSTR, MAC2STR(sta->addr));
475 ap_free_sta(hapd, sta);
480 mlme_deauthenticate_indication(hapd, sta,
481 WLAN_REASON_PREV_AUTH_NOT_VALID);
482 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
483 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
485 sta->acct_terminate_cause =
486 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
487 os_memcpy(addr, sta->addr, ETH_ALEN);
488 ap_free_sta(hapd, sta);
489 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
493 void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
496 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
497 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
498 "seconds", session_timeout);
499 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
500 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
505 void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
507 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
511 struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
513 struct sta_info *sta;
515 sta = ap_get_sta(hapd, addr);
519 wpa_printf(MSG_DEBUG, " New STA");
520 if (hapd->num_sta >= hapd->conf->max_num_sta) {
521 /* FIX: might try to remove some old STAs first? */
522 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
523 hapd->num_sta, hapd->conf->max_num_sta);
527 sta = os_zalloc(sizeof(struct sta_info));
529 wpa_printf(MSG_ERROR, "malloc failed");
532 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
533 accounting_sta_get_id(hapd, sta);
535 /* initialize STA info data */
536 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
537 "for " MACSTR " (%d seconds - ap_max_inactivity)",
538 __func__, MAC2STR(addr),
539 hapd->conf->ap_max_inactivity);
540 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
541 ap_handle_timer, hapd, sta);
542 os_memcpy(sta->addr, addr, ETH_ALEN);
543 sta->next = hapd->sta_list;
544 hapd->sta_list = sta;
546 ap_sta_hash_add(hapd, sta);
547 sta->ssid = &hapd->conf->ssid;
548 ap_sta_remove_in_other_bss(hapd, sta);
554 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
556 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
558 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
560 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
561 sta->flags & WLAN_STA_ASSOC) {
562 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
563 " from kernel driver.", MAC2STR(sta->addr));
570 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
571 struct sta_info *sta)
573 struct hostapd_iface *iface = hapd->iface;
576 for (i = 0; i < iface->num_bss; i++) {
577 struct hostapd_data *bss = iface->bss[i];
578 struct sta_info *sta2;
579 /* bss should always be set during operation, but it may be
580 * NULL during reconfiguration. Assume the STA is not
581 * associated to another BSS in that case to avoid NULL pointer
583 if (bss == hapd || bss == NULL)
585 sta2 = ap_get_sta(bss, sta->addr);
589 ap_sta_disconnect(bss, sta2, sta2->addr,
590 WLAN_REASON_PREV_AUTH_NOT_VALID);
595 static void ap_sta_disassoc_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_disassociate_indication(hapd, sta, sta->disassoc_reason);
605 void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
608 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
609 hapd->conf->iface, MAC2STR(sta->addr));
610 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
611 ap_sta_set_authorized(hapd, sta, 0);
612 sta->timeout_next = STA_DEAUTH;
613 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
614 "for " MACSTR " (%d seconds - "
615 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
616 __func__, MAC2STR(sta->addr),
617 AP_MAX_INACTIVITY_AFTER_DISASSOC);
618 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
619 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
620 ap_handle_timer, hapd, sta);
621 accounting_sta_stop(hapd, sta);
622 ieee802_1x_free_station(sta);
624 sta->disassoc_reason = reason;
625 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
626 eloop_cancel_timeout(ap_sta_disassoc_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_disassoc_cb_timeout, hapd, sta);
633 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
635 struct hostapd_data *hapd = eloop_ctx;
636 struct sta_info *sta = timeout_ctx;
638 ap_sta_remove(hapd, sta);
639 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
643 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
646 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
647 hapd->conf->iface, MAC2STR(sta->addr));
648 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
649 ap_sta_set_authorized(hapd, sta, 0);
650 sta->timeout_next = STA_REMOVE;
651 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
652 "for " MACSTR " (%d seconds - "
653 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
654 __func__, MAC2STR(sta->addr),
655 AP_MAX_INACTIVITY_AFTER_DEAUTH);
656 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
657 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
658 ap_handle_timer, hapd, sta);
659 accounting_sta_stop(hapd, sta);
660 ieee802_1x_free_station(sta);
662 sta->deauth_reason = reason;
663 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
664 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
665 eloop_register_timeout(hapd->iface->drv_flags &
666 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
667 ap_sta_deauth_cb_timeout, hapd, sta);
672 int ap_sta_wps_cancel(struct hostapd_data *hapd,
673 struct sta_info *sta, void *ctx)
675 if (sta && (sta->flags & WLAN_STA_WPS)) {
676 ap_sta_deauthenticate(hapd, sta,
677 WLAN_REASON_PREV_AUTH_NOT_VALID);
678 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
679 __func__, MAC2STR(sta->addr));
685 #endif /* CONFIG_WPS */
688 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
691 #ifndef CONFIG_NO_VLAN
693 struct hostapd_vlan *vlan = NULL;
697 * Do not proceed furthur if the vlan id remains same. We do not want
698 * duplicate dynamic vlan entries.
700 if (sta->vlan_id == old_vlanid)
704 * During 1x reauth, if the vlan id changes, then remove the old id and
705 * proceed furthur to add the new one.
708 vlan_remove_dynamic(hapd, old_vlanid);
710 iface = hapd->conf->iface;
711 if (sta->ssid->vlan[0])
712 iface = sta->ssid->vlan;
714 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
716 else if (sta->vlan_id > 0) {
717 struct hostapd_vlan *wildcard_vlan = NULL;
718 vlan = hapd->conf->vlan;
720 if (vlan->vlan_id == sta->vlan_id)
722 if (vlan->vlan_id == VLAN_ID_WILDCARD)
723 wildcard_vlan = vlan;
727 vlan = wildcard_vlan;
729 iface = vlan->ifname;
732 if (sta->vlan_id > 0 && vlan == NULL) {
733 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
734 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
735 "binding station to (vlan_id=%d)",
738 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
739 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
741 hostapd_logger(hapd, sta->addr,
742 HOSTAPD_MODULE_IEEE80211,
743 HOSTAPD_LEVEL_DEBUG, "could not add "
744 "dynamic VLAN interface for vlan_id=%d",
749 iface = vlan->ifname;
750 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
751 hostapd_logger(hapd, sta->addr,
752 HOSTAPD_MODULE_IEEE80211,
753 HOSTAPD_LEVEL_DEBUG, "could not "
754 "configure encryption for dynamic VLAN "
755 "interface for vlan_id=%d",
759 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
760 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
761 "interface '%s'", iface);
762 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
763 if (sta->vlan_id > 0) {
764 vlan->dynamic_vlan++;
765 hostapd_logger(hapd, sta->addr,
766 HOSTAPD_MODULE_IEEE80211,
767 HOSTAPD_LEVEL_DEBUG, "updated existing "
768 "dynamic VLAN interface '%s'", iface);
772 * Update encryption configuration for statically generated
773 * VLAN interface. This is only used for static WEP
774 * configuration for the case where hostapd did not yet know
775 * which keys are to be used when the interface was added.
777 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
778 hostapd_logger(hapd, sta->addr,
779 HOSTAPD_MODULE_IEEE80211,
780 HOSTAPD_LEVEL_DEBUG, "could not "
781 "configure encryption for VLAN "
782 "interface for vlan_id=%d",
787 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
788 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
791 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
792 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
794 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
796 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
797 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
798 "entry to vlan_id=%d", sta->vlan_id);
801 #else /* CONFIG_NO_VLAN */
803 #endif /* CONFIG_NO_VLAN */
807 #ifdef CONFIG_IEEE80211W
809 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
812 struct os_time now, passed;
814 os_time_sub(&now, &sta->sa_query_start, &passed);
815 tu = (passed.sec * 1000000 + passed.usec) / 1024;
816 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
817 hostapd_logger(hapd, sta->addr,
818 HOSTAPD_MODULE_IEEE80211,
820 "association SA Query timed out");
821 sta->sa_query_timed_out = 1;
822 os_free(sta->sa_query_trans_id);
823 sta->sa_query_trans_id = NULL;
824 sta->sa_query_count = 0;
825 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
833 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
835 struct hostapd_data *hapd = eloop_ctx;
836 struct sta_info *sta = timeout_ctx;
837 unsigned int timeout, sec, usec;
840 if (sta->sa_query_count > 0 &&
841 ap_check_sa_query_timeout(hapd, sta))
844 nbuf = os_realloc_array(sta->sa_query_trans_id,
845 sta->sa_query_count + 1,
846 WLAN_SA_QUERY_TR_ID_LEN);
849 if (sta->sa_query_count == 0) {
850 /* Starting a new SA Query procedure */
851 os_get_time(&sta->sa_query_start);
853 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
854 sta->sa_query_trans_id = nbuf;
855 sta->sa_query_count++;
857 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
859 timeout = hapd->conf->assoc_sa_query_retry_timeout;
860 sec = ((timeout / 1000) * 1024) / 1000;
861 usec = (timeout % 1000) * 1024;
862 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
864 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
866 "association SA Query attempt %d", sta->sa_query_count);
868 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
872 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
874 ap_sa_query_timer(hapd, sta);
878 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
880 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
881 os_free(sta->sa_query_trans_id);
882 sta->sa_query_trans_id = NULL;
883 sta->sa_query_count = 0;
886 #endif /* CONFIG_IEEE80211W */
889 void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
892 const u8 *dev_addr = NULL;
896 #endif /* CONFIG_P2P */
898 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
902 if (hapd->p2p_group == NULL) {
903 if (sta->p2p_ie != NULL &&
904 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
907 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
908 #endif /* CONFIG_P2P */
911 os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
912 MAC2STR(sta->addr), MAC2STR(dev_addr));
914 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
917 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s", buf);
919 if (hapd->msg_ctx_parent &&
920 hapd->msg_ctx_parent != hapd->msg_ctx)
921 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
922 AP_STA_CONNECTED "%s", buf);
924 sta->flags |= WLAN_STA_AUTHORIZED;
926 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
928 if (hapd->msg_ctx_parent &&
929 hapd->msg_ctx_parent != hapd->msg_ctx)
930 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
931 AP_STA_DISCONNECTED "%s", buf);
933 sta->flags &= ~WLAN_STA_AUTHORIZED;
936 if (hapd->sta_authorized_cb)
937 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
938 sta->addr, authorized, dev_addr);
942 void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
943 const u8 *addr, u16 reason)
946 if (sta == NULL && addr)
947 sta = ap_get_sta(hapd, addr);
950 hostapd_drv_sta_deauth(hapd, addr, reason);
954 ap_sta_set_authorized(hapd, sta, 0);
955 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
956 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
957 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
958 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
959 "for " MACSTR " (%d seconds - "
960 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
961 __func__, MAC2STR(sta->addr),
962 AP_MAX_INACTIVITY_AFTER_DEAUTH);
963 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
964 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
965 ap_handle_timer, hapd, sta);
966 sta->timeout_next = STA_REMOVE;
968 sta->deauth_reason = reason;
969 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
970 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
971 eloop_register_timeout(hapd->iface->drv_flags &
972 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
973 ap_sta_deauth_cb_timeout, hapd, sta);
977 void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
979 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
980 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
983 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
984 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
985 ap_sta_deauth_cb_timeout(hapd, sta);
989 void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
991 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
992 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
995 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
996 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
997 ap_sta_disassoc_cb_timeout(hapd, sta);