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
235 radius_client_flush_auth(hapd->radius, sta->addr);
236 #endif /* CONFIG_NO_RADIUS */
238 os_free(sta->last_assoc_req);
239 os_free(sta->challenge);
241 #ifdef CONFIG_IEEE80211W
242 os_free(sta->sa_query_trans_id);
243 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
244 #endif /* CONFIG_IEEE80211W */
247 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
248 #endif /* CONFIG_P2P */
250 #ifdef CONFIG_INTERWORKING
251 if (sta->gas_dialog) {
253 for (i = 0; i < GAS_DIALOG_MAX; i++)
254 gas_serv_dialog_clear(&sta->gas_dialog[i]);
255 os_free(sta->gas_dialog);
257 #endif /* CONFIG_INTERWORKING */
259 wpabuf_free(sta->wps_ie);
260 wpabuf_free(sta->p2p_ie);
261 wpabuf_free(sta->hs20_ie);
263 os_free(sta->ht_capabilities);
264 hostapd_free_psk_list(sta->psk);
265 os_free(sta->identity);
266 os_free(sta->radius_cui);
269 sae_clear_data(sta->sae);
271 #endif /* CONFIG_SAE */
277 void hostapd_free_stas(struct hostapd_data *hapd)
279 struct sta_info *sta, *prev;
281 sta = hapd->sta_list;
285 if (sta->flags & WLAN_STA_AUTH) {
286 mlme_deauthenticate_indication(
287 hapd, sta, WLAN_REASON_UNSPECIFIED);
290 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
291 MAC2STR(prev->addr));
292 ap_free_sta(hapd, prev);
298 * ap_handle_timer - Per STA timer handler
299 * @eloop_ctx: struct hostapd_data *
300 * @timeout_ctx: struct sta_info *
302 * This function is called to check station activity and to remove inactive
305 void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
307 struct hostapd_data *hapd = eloop_ctx;
308 struct sta_info *sta = timeout_ctx;
309 unsigned long next_time = 0;
312 wpa_printf(MSG_DEBUG, "%s: " MACSTR " flags=0x%x timeout_next=%d",
313 __func__, MAC2STR(sta->addr), sta->flags,
315 if (sta->timeout_next == STA_REMOVE) {
316 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
317 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
318 "local deauth request");
319 ap_free_sta(hapd, sta);
323 if ((sta->flags & WLAN_STA_ASSOC) &&
324 (sta->timeout_next == STA_NULLFUNC ||
325 sta->timeout_next == STA_DISASSOC)) {
328 * Add random value to timeout so that we don't end up bouncing
329 * all stations at the same time if we have lots of associated
330 * stations that are idle (but keep re-associating).
332 int fuzz = os_random() % 20;
333 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
334 if (inactive_sec == -1) {
335 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
336 "Check inactivity: Could not "
337 "get station info from kernel driver for "
338 MACSTR, MAC2STR(sta->addr));
340 * The driver may not support this functionality.
341 * Anyway, try again after the next inactivity timeout,
342 * but do not disconnect the station now.
344 next_time = hapd->conf->ap_max_inactivity + fuzz;
345 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
346 sta->flags & WLAN_STA_ASSOC) {
347 /* station activity detected; reset timeout state */
348 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
349 "Station " MACSTR " has been active %is ago",
350 MAC2STR(sta->addr), inactive_sec);
351 sta->timeout_next = STA_NULLFUNC;
352 next_time = hapd->conf->ap_max_inactivity + fuzz -
355 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
356 "Station " MACSTR " has been "
357 "inactive too long: %d sec, max allowed: %d",
358 MAC2STR(sta->addr), inactive_sec,
359 hapd->conf->ap_max_inactivity);
361 if (hapd->conf->skip_inactivity_poll)
362 sta->timeout_next = STA_DISASSOC;
366 if ((sta->flags & WLAN_STA_ASSOC) &&
367 sta->timeout_next == STA_DISASSOC &&
368 !(sta->flags & WLAN_STA_PENDING_POLL) &&
369 !hapd->conf->skip_inactivity_poll) {
370 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
371 " has ACKed data poll", MAC2STR(sta->addr));
372 /* data nullfunc frame poll did not produce TX errors; assume
373 * station ACKed it */
374 sta->timeout_next = STA_NULLFUNC;
375 next_time = hapd->conf->ap_max_inactivity;
379 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
380 "for " MACSTR " (%lu seconds)",
381 __func__, MAC2STR(sta->addr), next_time);
382 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
387 if (sta->timeout_next == STA_NULLFUNC &&
388 (sta->flags & WLAN_STA_ASSOC)) {
389 wpa_printf(MSG_DEBUG, " Polling STA");
390 sta->flags |= WLAN_STA_PENDING_POLL;
391 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
392 sta->flags & WLAN_STA_WMM);
393 } else if (sta->timeout_next != STA_REMOVE) {
394 int deauth = sta->timeout_next == STA_DEAUTH;
396 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
397 "Timeout, sending %s info to STA " MACSTR,
398 deauth ? "deauthentication" : "disassociation",
402 hostapd_drv_sta_deauth(
404 WLAN_REASON_PREV_AUTH_NOT_VALID);
406 reason = (sta->timeout_next == STA_DISASSOC) ?
407 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
408 WLAN_REASON_PREV_AUTH_NOT_VALID;
410 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
414 switch (sta->timeout_next) {
416 sta->timeout_next = STA_DISASSOC;
417 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
418 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
419 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
420 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
424 case STA_DISASSOC_FROM_CLI:
425 ap_sta_set_authorized(hapd, sta, 0);
426 sta->flags &= ~WLAN_STA_ASSOC;
427 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
428 if (!sta->acct_terminate_cause)
429 sta->acct_terminate_cause =
430 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
431 accounting_sta_stop(hapd, sta);
432 ieee802_1x_free_station(sta);
433 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
434 HOSTAPD_LEVEL_INFO, "disassociated due to "
436 reason = (sta->timeout_next == STA_DISASSOC) ?
437 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
438 WLAN_REASON_PREV_AUTH_NOT_VALID;
439 sta->timeout_next = STA_DEAUTH;
440 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
441 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
442 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
443 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
445 mlme_disassociate_indication(hapd, sta, reason);
449 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
450 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
451 "inactivity (timer DEAUTH/REMOVE)");
452 if (!sta->acct_terminate_cause)
453 sta->acct_terminate_cause =
454 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
455 mlme_deauthenticate_indication(
457 WLAN_REASON_PREV_AUTH_NOT_VALID);
458 ap_free_sta(hapd, sta);
464 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
466 struct hostapd_data *hapd = eloop_ctx;
467 struct sta_info *sta = timeout_ctx;
470 if (!(sta->flags & WLAN_STA_AUTH)) {
471 if (sta->flags & WLAN_STA_GAS) {
472 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
473 "entry " MACSTR, MAC2STR(sta->addr));
474 ap_free_sta(hapd, sta);
479 mlme_deauthenticate_indication(hapd, sta,
480 WLAN_REASON_PREV_AUTH_NOT_VALID);
481 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
482 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
484 sta->acct_terminate_cause =
485 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
486 os_memcpy(addr, sta->addr, ETH_ALEN);
487 ap_free_sta(hapd, sta);
488 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
492 void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
495 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
496 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
497 "seconds", session_timeout);
498 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
499 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
504 void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
506 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
510 struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
512 struct sta_info *sta;
514 sta = ap_get_sta(hapd, addr);
518 wpa_printf(MSG_DEBUG, " New STA");
519 if (hapd->num_sta >= hapd->conf->max_num_sta) {
520 /* FIX: might try to remove some old STAs first? */
521 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
522 hapd->num_sta, hapd->conf->max_num_sta);
526 sta = os_zalloc(sizeof(struct sta_info));
528 wpa_printf(MSG_ERROR, "malloc failed");
531 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
532 accounting_sta_get_id(hapd, sta);
534 /* initialize STA info data */
535 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
536 "for " MACSTR " (%d seconds - ap_max_inactivity)",
537 __func__, MAC2STR(addr),
538 hapd->conf->ap_max_inactivity);
539 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
540 ap_handle_timer, hapd, sta);
541 os_memcpy(sta->addr, addr, ETH_ALEN);
542 sta->next = hapd->sta_list;
543 hapd->sta_list = sta;
545 ap_sta_hash_add(hapd, sta);
546 sta->ssid = &hapd->conf->ssid;
547 ap_sta_remove_in_other_bss(hapd, sta);
553 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
555 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
557 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
559 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
560 sta->flags & WLAN_STA_ASSOC) {
561 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
562 " from kernel driver.", MAC2STR(sta->addr));
569 static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
570 struct sta_info *sta)
572 struct hostapd_iface *iface = hapd->iface;
575 for (i = 0; i < iface->num_bss; i++) {
576 struct hostapd_data *bss = iface->bss[i];
577 struct sta_info *sta2;
578 /* bss should always be set during operation, but it may be
579 * NULL during reconfiguration. Assume the STA is not
580 * associated to another BSS in that case to avoid NULL pointer
582 if (bss == hapd || bss == NULL)
584 sta2 = ap_get_sta(bss, sta->addr);
588 ap_sta_disconnect(bss, sta2, sta2->addr,
589 WLAN_REASON_PREV_AUTH_NOT_VALID);
594 static void ap_sta_disassoc_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_disassociate_indication(hapd, sta, sta->disassoc_reason);
604 void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
607 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
608 hapd->conf->iface, MAC2STR(sta->addr));
609 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
610 ap_sta_set_authorized(hapd, sta, 0);
611 sta->timeout_next = STA_DEAUTH;
612 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
613 "for " MACSTR " (%d seconds - "
614 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
615 __func__, MAC2STR(sta->addr),
616 AP_MAX_INACTIVITY_AFTER_DISASSOC);
617 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
618 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
619 ap_handle_timer, hapd, sta);
620 accounting_sta_stop(hapd, sta);
621 ieee802_1x_free_station(sta);
623 sta->disassoc_reason = reason;
624 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
625 eloop_cancel_timeout(ap_sta_disassoc_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_disassoc_cb_timeout, hapd, sta);
632 static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
634 struct hostapd_data *hapd = eloop_ctx;
635 struct sta_info *sta = timeout_ctx;
637 ap_sta_remove(hapd, sta);
638 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
642 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
645 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
646 hapd->conf->iface, MAC2STR(sta->addr));
647 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
648 ap_sta_set_authorized(hapd, sta, 0);
649 sta->timeout_next = STA_REMOVE;
650 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
651 "for " MACSTR " (%d seconds - "
652 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
653 __func__, MAC2STR(sta->addr),
654 AP_MAX_INACTIVITY_AFTER_DEAUTH);
655 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
656 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
657 ap_handle_timer, hapd, sta);
658 accounting_sta_stop(hapd, sta);
659 ieee802_1x_free_station(sta);
661 sta->deauth_reason = reason;
662 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
663 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
664 eloop_register_timeout(hapd->iface->drv_flags &
665 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
666 ap_sta_deauth_cb_timeout, hapd, sta);
671 int ap_sta_wps_cancel(struct hostapd_data *hapd,
672 struct sta_info *sta, void *ctx)
674 if (sta && (sta->flags & WLAN_STA_WPS)) {
675 ap_sta_deauthenticate(hapd, sta,
676 WLAN_REASON_PREV_AUTH_NOT_VALID);
677 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
678 __func__, MAC2STR(sta->addr));
684 #endif /* CONFIG_WPS */
687 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
690 #ifndef CONFIG_NO_VLAN
692 struct hostapd_vlan *vlan = NULL;
696 * Do not proceed furthur if the vlan id remains same. We do not want
697 * duplicate dynamic vlan entries.
699 if (sta->vlan_id == old_vlanid)
703 * During 1x reauth, if the vlan id changes, then remove the old id and
704 * proceed furthur to add the new one.
707 vlan_remove_dynamic(hapd, old_vlanid);
709 iface = hapd->conf->iface;
710 if (sta->ssid->vlan[0])
711 iface = sta->ssid->vlan;
713 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
715 else if (sta->vlan_id > 0) {
716 struct hostapd_vlan *wildcard_vlan = NULL;
717 vlan = hapd->conf->vlan;
719 if (vlan->vlan_id == sta->vlan_id)
721 if (vlan->vlan_id == VLAN_ID_WILDCARD)
722 wildcard_vlan = vlan;
726 vlan = wildcard_vlan;
728 iface = vlan->ifname;
731 if (sta->vlan_id > 0 && vlan == NULL) {
732 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
733 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
734 "binding station to (vlan_id=%d)",
737 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
738 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
740 hostapd_logger(hapd, sta->addr,
741 HOSTAPD_MODULE_IEEE80211,
742 HOSTAPD_LEVEL_DEBUG, "could not add "
743 "dynamic VLAN interface for vlan_id=%d",
748 iface = vlan->ifname;
749 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
750 hostapd_logger(hapd, sta->addr,
751 HOSTAPD_MODULE_IEEE80211,
752 HOSTAPD_LEVEL_DEBUG, "could not "
753 "configure encryption for dynamic VLAN "
754 "interface for vlan_id=%d",
758 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
759 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
760 "interface '%s'", iface);
761 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
762 if (sta->vlan_id > 0) {
763 vlan->dynamic_vlan++;
764 hostapd_logger(hapd, sta->addr,
765 HOSTAPD_MODULE_IEEE80211,
766 HOSTAPD_LEVEL_DEBUG, "updated existing "
767 "dynamic VLAN interface '%s'", iface);
771 * Update encryption configuration for statically generated
772 * VLAN interface. This is only used for static WEP
773 * configuration for the case where hostapd did not yet know
774 * which keys are to be used when the interface was added.
776 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
777 hostapd_logger(hapd, sta->addr,
778 HOSTAPD_MODULE_IEEE80211,
779 HOSTAPD_LEVEL_DEBUG, "could not "
780 "configure encryption for VLAN "
781 "interface for vlan_id=%d",
786 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
787 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
790 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
791 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
793 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
795 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
796 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
797 "entry to vlan_id=%d", sta->vlan_id);
800 #else /* CONFIG_NO_VLAN */
802 #endif /* CONFIG_NO_VLAN */
806 #ifdef CONFIG_IEEE80211W
808 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
811 struct os_time now, passed;
813 os_time_sub(&now, &sta->sa_query_start, &passed);
814 tu = (passed.sec * 1000000 + passed.usec) / 1024;
815 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
816 hostapd_logger(hapd, sta->addr,
817 HOSTAPD_MODULE_IEEE80211,
819 "association SA Query timed out");
820 sta->sa_query_timed_out = 1;
821 os_free(sta->sa_query_trans_id);
822 sta->sa_query_trans_id = NULL;
823 sta->sa_query_count = 0;
824 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
832 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
834 struct hostapd_data *hapd = eloop_ctx;
835 struct sta_info *sta = timeout_ctx;
836 unsigned int timeout, sec, usec;
839 if (sta->sa_query_count > 0 &&
840 ap_check_sa_query_timeout(hapd, sta))
843 nbuf = os_realloc_array(sta->sa_query_trans_id,
844 sta->sa_query_count + 1,
845 WLAN_SA_QUERY_TR_ID_LEN);
848 if (sta->sa_query_count == 0) {
849 /* Starting a new SA Query procedure */
850 os_get_time(&sta->sa_query_start);
852 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
853 sta->sa_query_trans_id = nbuf;
854 sta->sa_query_count++;
856 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
858 timeout = hapd->conf->assoc_sa_query_retry_timeout;
859 sec = ((timeout / 1000) * 1024) / 1000;
860 usec = (timeout % 1000) * 1024;
861 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
863 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
865 "association SA Query attempt %d", sta->sa_query_count);
867 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
871 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
873 ap_sa_query_timer(hapd, sta);
877 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
879 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
880 os_free(sta->sa_query_trans_id);
881 sta->sa_query_trans_id = NULL;
882 sta->sa_query_count = 0;
885 #endif /* CONFIG_IEEE80211W */
888 void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
891 const u8 *dev_addr = NULL;
895 #endif /* CONFIG_P2P */
897 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
901 if (hapd->p2p_group == NULL) {
902 if (sta->p2p_ie != NULL &&
903 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
906 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
907 #endif /* CONFIG_P2P */
910 os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
911 MAC2STR(sta->addr), MAC2STR(dev_addr));
913 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
916 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s", buf);
918 if (hapd->msg_ctx_parent &&
919 hapd->msg_ctx_parent != hapd->msg_ctx)
920 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
921 AP_STA_CONNECTED "%s", buf);
923 sta->flags |= WLAN_STA_AUTHORIZED;
925 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
927 if (hapd->msg_ctx_parent &&
928 hapd->msg_ctx_parent != hapd->msg_ctx)
929 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
930 AP_STA_DISCONNECTED "%s", buf);
932 sta->flags &= ~WLAN_STA_AUTHORIZED;
935 if (hapd->sta_authorized_cb)
936 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
937 sta->addr, authorized, dev_addr);
941 void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
942 const u8 *addr, u16 reason)
945 if (sta == NULL && addr)
946 sta = ap_get_sta(hapd, addr);
949 hostapd_drv_sta_deauth(hapd, addr, reason);
953 ap_sta_set_authorized(hapd, sta, 0);
954 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
955 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
956 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
957 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
958 "for " MACSTR " (%d seconds - "
959 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
960 __func__, MAC2STR(sta->addr),
961 AP_MAX_INACTIVITY_AFTER_DEAUTH);
962 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
963 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
964 ap_handle_timer, hapd, sta);
965 sta->timeout_next = STA_REMOVE;
967 sta->deauth_reason = reason;
968 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
969 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
970 eloop_register_timeout(hapd->iface->drv_flags &
971 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
972 ap_sta_deauth_cb_timeout, hapd, sta);
976 void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
978 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
979 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
982 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
983 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
984 ap_sta_deauth_cb_timeout(hapd, sta);
988 void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
990 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
991 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
994 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
995 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
996 ap_sta_disassoc_cb_timeout(hapd, sta);