2008-02-27 20:34:43 -05:00
|
|
|
/*
|
|
|
|
* hostapd / Station table
|
2013-09-01 10:37:22 -04:00
|
|
|
* Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
|
2008-02-27 20:34:43 -05:00
|
|
|
*
|
2012-02-11 09:46:35 -05:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2008-02-27 20:34:43 -05:00
|
|
|
*/
|
|
|
|
|
2009-12-25 17:05:40 -05:00
|
|
|
#include "utils/includes.h"
|
2008-02-27 20:34:43 -05:00
|
|
|
|
2009-12-25 17:05:40 -05:00
|
|
|
#include "utils/common.h"
|
|
|
|
#include "utils/eloop.h"
|
2009-12-25 17:31:51 -05:00
|
|
|
#include "common/ieee802_11_defs.h"
|
2011-11-03 15:58:22 -04:00
|
|
|
#include "common/wpa_ctrl.h"
|
2013-01-01 04:29:53 -05:00
|
|
|
#include "common/sae.h"
|
2009-12-24 17:30:16 -05:00
|
|
|
#include "radius/radius.h"
|
|
|
|
#include "radius/radius_client.h"
|
|
|
|
#include "drivers/driver.h"
|
2010-07-18 17:30:25 -04:00
|
|
|
#include "p2p/p2p.h"
|
2008-02-27 20:34:43 -05:00
|
|
|
#include "hostapd.h"
|
|
|
|
#include "accounting.h"
|
|
|
|
#include "ieee802_1x.h"
|
|
|
|
#include "ieee802_11.h"
|
2012-11-25 11:01:55 -05:00
|
|
|
#include "ieee802_11_auth.h"
|
2009-12-25 17:05:40 -05:00
|
|
|
#include "wpa_auth.h"
|
|
|
|
#include "preauth_auth.h"
|
|
|
|
#include "ap_config.h"
|
2008-02-27 20:34:43 -05:00
|
|
|
#include "beacon.h"
|
2009-12-25 17:05:40 -05:00
|
|
|
#include "ap_mlme.h"
|
2008-02-27 20:34:43 -05:00
|
|
|
#include "vlan_init.h"
|
2010-07-08 20:14:24 -04:00
|
|
|
#include "p2p_hostapd.h"
|
2010-11-24 08:19:50 -05:00
|
|
|
#include "ap_drv_ops.h"
|
2012-02-26 15:34:19 -05:00
|
|
|
#include "gas_serv.h"
|
2009-12-25 17:05:40 -05:00
|
|
|
#include "sta_info.h"
|
2008-02-27 20:34:43 -05:00
|
|
|
|
2010-03-06 15:30:25 -05:00
|
|
|
static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
|
|
|
|
struct sta_info *sta);
|
2008-02-27 20:34:43 -05:00
|
|
|
static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
|
2011-08-28 16:07:02 -04:00
|
|
|
static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
|
|
|
|
static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
|
2008-08-31 04:04:47 -04:00
|
|
|
#ifdef CONFIG_IEEE80211W
|
2008-12-26 04:46:21 -05:00
|
|
|
static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
|
2008-08-31 04:04:47 -04:00
|
|
|
#endif /* CONFIG_IEEE80211W */
|
2011-08-28 16:07:02 -04:00
|
|
|
static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
int ap_for_each_sta(struct hostapd_data *hapd,
|
|
|
|
int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
|
|
|
|
void *ctx),
|
|
|
|
void *ctx)
|
|
|
|
{
|
|
|
|
struct sta_info *sta;
|
|
|
|
|
|
|
|
for (sta = hapd->sta_list; sta; sta = sta->next) {
|
|
|
|
if (cb(hapd, sta, ctx))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
|
|
|
|
{
|
|
|
|
struct sta_info *s;
|
|
|
|
|
|
|
|
s = hapd->sta_hash[STA_HASH(sta)];
|
|
|
|
while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
|
|
|
|
s = s->hnext;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-01 10:37:22 -04:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
struct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr)
|
|
|
|
{
|
|
|
|
struct sta_info *sta;
|
|
|
|
|
|
|
|
for (sta = hapd->sta_list; sta; sta = sta->next) {
|
|
|
|
const u8 *p2p_dev_addr;
|
|
|
|
|
|
|
|
if (sta->p2p_ie == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
|
|
|
|
if (p2p_dev_addr == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (os_memcmp(p2p_dev_addr, addr, ETH_ALEN) == 0)
|
|
|
|
return sta;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
|
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
|
|
|
|
{
|
|
|
|
struct sta_info *tmp;
|
|
|
|
|
|
|
|
if (hapd->sta_list == sta) {
|
|
|
|
hapd->sta_list = sta->next;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = hapd->sta_list;
|
|
|
|
while (tmp != NULL && tmp->next != sta)
|
|
|
|
tmp = tmp->next;
|
|
|
|
if (tmp == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
|
|
|
|
"list.", MAC2STR(sta->addr));
|
|
|
|
} else
|
|
|
|
tmp->next = sta->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
|
|
|
|
{
|
|
|
|
sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
|
|
|
|
hapd->sta_hash[STA_HASH(sta->addr)] = sta;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
|
|
|
|
{
|
|
|
|
struct sta_info *s;
|
|
|
|
|
|
|
|
s = hapd->sta_hash[STA_HASH(sta->addr)];
|
|
|
|
if (s == NULL) return;
|
|
|
|
if (os_memcmp(s->addr, sta->addr, 6) == 0) {
|
|
|
|
hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (s->hnext != NULL &&
|
|
|
|
os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
|
|
|
|
s = s->hnext;
|
|
|
|
if (s->hnext != NULL)
|
|
|
|
s->hnext = s->hnext->hnext;
|
|
|
|
else
|
|
|
|
wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
|
|
|
|
" from hash table", MAC2STR(sta->addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
|
|
|
|
{
|
|
|
|
int set_beacon = 0;
|
|
|
|
|
|
|
|
accounting_sta_stop(hapd, sta);
|
|
|
|
|
2011-02-02 09:52:32 -05:00
|
|
|
/* just in case */
|
|
|
|
ap_sta_set_authorized(hapd, sta, 0);
|
|
|
|
|
2010-03-06 13:52:22 -05:00
|
|
|
if (sta->flags & WLAN_STA_WDS)
|
2013-07-20 10:41:22 -04:00
|
|
|
hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0);
|
2010-03-06 15:30:25 -05:00
|
|
|
|
|
|
|
if (!(sta->flags & WLAN_STA_PREAUTH))
|
2010-11-24 08:36:02 -05:00
|
|
|
hostapd_drv_sta_remove(hapd, sta->addr);
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
ap_sta_hash_del(hapd, sta);
|
|
|
|
ap_sta_list_del(hapd, sta);
|
|
|
|
|
|
|
|
if (sta->aid > 0)
|
2009-03-25 09:54:25 -04:00
|
|
|
hapd->sta_aid[(sta->aid - 1) / 32] &=
|
|
|
|
~BIT((sta->aid - 1) % 32);
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
hapd->num_sta--;
|
|
|
|
if (sta->nonerp_set) {
|
|
|
|
sta->nonerp_set = 0;
|
|
|
|
hapd->iface->num_sta_non_erp--;
|
|
|
|
if (hapd->iface->num_sta_non_erp == 0)
|
|
|
|
set_beacon++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sta->no_short_slot_time_set) {
|
|
|
|
sta->no_short_slot_time_set = 0;
|
|
|
|
hapd->iface->num_sta_no_short_slot_time--;
|
|
|
|
if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
|
|
|
|
&& hapd->iface->num_sta_no_short_slot_time == 0)
|
|
|
|
set_beacon++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sta->no_short_preamble_set) {
|
|
|
|
sta->no_short_preamble_set = 0;
|
|
|
|
hapd->iface->num_sta_no_short_preamble--;
|
|
|
|
if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
|
|
|
|
&& hapd->iface->num_sta_no_short_preamble == 0)
|
|
|
|
set_beacon++;
|
|
|
|
}
|
|
|
|
|
2008-12-02 07:32:05 -05:00
|
|
|
if (sta->no_ht_gf_set) {
|
|
|
|
sta->no_ht_gf_set = 0;
|
|
|
|
hapd->iface->num_sta_ht_no_gf--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sta->no_ht_set) {
|
|
|
|
sta->no_ht_set = 0;
|
2008-08-21 11:18:38 -04:00
|
|
|
hapd->iface->num_sta_no_ht--;
|
2008-12-02 07:32:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sta->ht_20mhz_set) {
|
|
|
|
sta->ht_20mhz_set = 0;
|
|
|
|
hapd->iface->num_sta_ht_20mhz--;
|
|
|
|
}
|
2008-08-21 11:18:38 -04:00
|
|
|
|
2010-07-08 20:14:24 -04:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
if (sta->no_p2p_set) {
|
|
|
|
sta->no_p2p_set = 0;
|
|
|
|
hapd->num_sta_no_p2p--;
|
|
|
|
if (hapd->num_sta_no_p2p == 0)
|
|
|
|
hostapd_p2p_non_p2p_sta_disconnected(hapd);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
|
2009-12-06 12:41:47 -05:00
|
|
|
#if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
|
2008-08-21 11:18:38 -04:00
|
|
|
if (hostapd_ht_operation_update(hapd->iface) > 0)
|
|
|
|
set_beacon++;
|
2009-12-06 12:41:47 -05:00
|
|
|
#endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
|
2008-08-21 11:18:38 -04:00
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
if (set_beacon)
|
|
|
|
ieee802_11_set_beacons(hapd->iface);
|
|
|
|
|
2012-04-11 07:09:40 -04:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
|
|
|
|
__func__, MAC2STR(sta->addr));
|
2008-02-27 20:34:43 -05:00
|
|
|
eloop_cancel_timeout(ap_handle_timer, hapd, sta);
|
|
|
|
eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
|
2011-08-28 16:07:02 -04:00
|
|
|
eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
|
|
|
|
eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
ieee802_1x_free_station(sta);
|
|
|
|
wpa_auth_sta_deinit(sta->wpa_sm);
|
|
|
|
rsn_preauth_free_station(hapd, sta);
|
2009-12-06 10:53:59 -05:00
|
|
|
#ifndef CONFIG_NO_RADIUS
|
2008-02-27 20:34:43 -05:00
|
|
|
radius_client_flush_auth(hapd->radius, sta->addr);
|
2009-12-06 10:53:59 -05:00
|
|
|
#endif /* CONFIG_NO_RADIUS */
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
os_free(sta->last_assoc_req);
|
|
|
|
os_free(sta->challenge);
|
2008-08-31 04:04:47 -04:00
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211W
|
2008-12-26 04:46:21 -05:00
|
|
|
os_free(sta->sa_query_trans_id);
|
|
|
|
eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
|
2008-08-31 04:04:47 -04:00
|
|
|
#endif /* CONFIG_IEEE80211W */
|
|
|
|
|
2010-07-18 17:30:25 -04:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
|
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
|
2012-02-26 15:34:19 -05:00
|
|
|
#ifdef CONFIG_INTERWORKING
|
|
|
|
if (sta->gas_dialog) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < GAS_DIALOG_MAX; i++)
|
|
|
|
gas_serv_dialog_clear(&sta->gas_dialog[i]);
|
|
|
|
os_free(sta->gas_dialog);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_INTERWORKING */
|
|
|
|
|
2008-11-29 05:11:56 -05:00
|
|
|
wpabuf_free(sta->wps_ie);
|
2010-07-18 17:30:25 -04:00
|
|
|
wpabuf_free(sta->p2p_ie);
|
2012-11-21 17:19:17 -05:00
|
|
|
wpabuf_free(sta->hs20_ie);
|
2008-11-29 05:11:56 -05:00
|
|
|
|
2009-11-29 14:07:52 -05:00
|
|
|
os_free(sta->ht_capabilities);
|
2012-11-25 11:01:55 -05:00
|
|
|
hostapd_free_psk_list(sta->psk);
|
2012-08-19 07:20:10 -04:00
|
|
|
os_free(sta->identity);
|
|
|
|
os_free(sta->radius_cui);
|
2009-11-29 14:07:52 -05:00
|
|
|
|
2012-12-30 14:48:19 -05:00
|
|
|
#ifdef CONFIG_SAE
|
2013-01-01 04:29:53 -05:00
|
|
|
sae_clear_data(sta->sae);
|
2012-12-30 14:48:19 -05:00
|
|
|
os_free(sta->sae);
|
|
|
|
#endif /* CONFIG_SAE */
|
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
os_free(sta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void hostapd_free_stas(struct hostapd_data *hapd)
|
|
|
|
{
|
|
|
|
struct sta_info *sta, *prev;
|
|
|
|
|
|
|
|
sta = hapd->sta_list;
|
|
|
|
|
|
|
|
while (sta) {
|
|
|
|
prev = sta;
|
|
|
|
if (sta->flags & WLAN_STA_AUTH) {
|
|
|
|
mlme_deauthenticate_indication(
|
|
|
|
hapd, sta, WLAN_REASON_UNSPECIFIED);
|
|
|
|
}
|
|
|
|
sta = sta->next;
|
|
|
|
wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
|
|
|
|
MAC2STR(prev->addr));
|
|
|
|
ap_free_sta(hapd, prev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 09:33:00 -05:00
|
|
|
/**
|
|
|
|
* ap_handle_timer - Per STA timer handler
|
|
|
|
* @eloop_ctx: struct hostapd_data *
|
|
|
|
* @timeout_ctx: struct sta_info *
|
|
|
|
*
|
|
|
|
* This function is called to check station activity and to remove inactive
|
|
|
|
* stations.
|
|
|
|
*/
|
2008-02-27 20:34:43 -05:00
|
|
|
void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = eloop_ctx;
|
|
|
|
struct sta_info *sta = timeout_ctx;
|
|
|
|
unsigned long next_time = 0;
|
2013-04-05 11:41:26 -04:00
|
|
|
int reason;
|
2008-02-27 20:34:43 -05:00
|
|
|
|
2012-04-11 07:09:40 -04:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: " MACSTR " flags=0x%x timeout_next=%d",
|
|
|
|
__func__, MAC2STR(sta->addr), sta->flags,
|
|
|
|
sta->timeout_next);
|
2008-02-27 20:34:43 -05:00
|
|
|
if (sta->timeout_next == STA_REMOVE) {
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO, "deauthenticated due to "
|
|
|
|
"local deauth request");
|
|
|
|
ap_free_sta(hapd, sta);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((sta->flags & WLAN_STA_ASSOC) &&
|
|
|
|
(sta->timeout_next == STA_NULLFUNC ||
|
|
|
|
sta->timeout_next == STA_DISASSOC)) {
|
|
|
|
int inactive_sec;
|
2012-04-06 04:47:29 -04:00
|
|
|
/*
|
|
|
|
* Add random value to timeout so that we don't end up bouncing
|
|
|
|
* all stations at the same time if we have lots of associated
|
|
|
|
* stations that are idle (but keep re-associating).
|
|
|
|
*/
|
|
|
|
int fuzz = os_random() % 20;
|
2010-11-24 08:36:02 -05:00
|
|
|
inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
|
2008-02-27 20:34:43 -05:00
|
|
|
if (inactive_sec == -1) {
|
2011-11-03 16:04:17 -04:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_DEBUG,
|
|
|
|
"Check inactivity: Could not "
|
2012-01-02 14:27:06 -05:00
|
|
|
"get station info from kernel driver for "
|
2011-02-24 10:44:45 -05:00
|
|
|
MACSTR, MAC2STR(sta->addr));
|
2012-01-02 14:27:06 -05:00
|
|
|
/*
|
|
|
|
* The driver may not support this functionality.
|
|
|
|
* Anyway, try again after the next inactivity timeout,
|
|
|
|
* but do not disconnect the station now.
|
|
|
|
*/
|
2012-04-06 04:47:29 -04:00
|
|
|
next_time = hapd->conf->ap_max_inactivity + fuzz;
|
2008-02-27 20:34:43 -05:00
|
|
|
} else if (inactive_sec < hapd->conf->ap_max_inactivity &&
|
|
|
|
sta->flags & WLAN_STA_ASSOC) {
|
|
|
|
/* station activity detected; reset timeout state */
|
2011-11-03 16:04:17 -04:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_DEBUG,
|
|
|
|
"Station " MACSTR " has been active %is ago",
|
2011-02-24 10:44:45 -05:00
|
|
|
MAC2STR(sta->addr), inactive_sec);
|
2008-02-27 20:34:43 -05:00
|
|
|
sta->timeout_next = STA_NULLFUNC;
|
2012-04-06 04:47:29 -04:00
|
|
|
next_time = hapd->conf->ap_max_inactivity + fuzz -
|
2008-02-27 20:34:43 -05:00
|
|
|
inactive_sec;
|
2011-02-24 10:44:45 -05:00
|
|
|
} else {
|
2011-11-03 16:04:17 -04:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_DEBUG,
|
|
|
|
"Station " MACSTR " has been "
|
2011-02-24 10:44:45 -05:00
|
|
|
"inactive too long: %d sec, max allowed: %d",
|
|
|
|
MAC2STR(sta->addr), inactive_sec,
|
|
|
|
hapd->conf->ap_max_inactivity);
|
2011-12-25 13:57:01 -05:00
|
|
|
|
|
|
|
if (hapd->conf->skip_inactivity_poll)
|
|
|
|
sta->timeout_next = STA_DISASSOC;
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((sta->flags & WLAN_STA_ASSOC) &&
|
|
|
|
sta->timeout_next == STA_DISASSOC &&
|
2011-12-25 13:57:01 -05:00
|
|
|
!(sta->flags & WLAN_STA_PENDING_POLL) &&
|
|
|
|
!hapd->conf->skip_inactivity_poll) {
|
2011-11-03 16:04:17 -04:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
|
|
|
|
" has ACKed data poll", MAC2STR(sta->addr));
|
2008-02-27 20:34:43 -05:00
|
|
|
/* data nullfunc frame poll did not produce TX errors; assume
|
|
|
|
* station ACKed it */
|
|
|
|
sta->timeout_next = STA_NULLFUNC;
|
|
|
|
next_time = hapd->conf->ap_max_inactivity;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next_time) {
|
2012-04-11 07:09:40 -04:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
|
|
|
|
"for " MACSTR " (%lu seconds)",
|
|
|
|
__func__, MAC2STR(sta->addr), next_time);
|
2008-02-27 20:34:43 -05:00
|
|
|
eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
|
|
|
|
sta);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sta->timeout_next == STA_NULLFUNC &&
|
|
|
|
(sta->flags & WLAN_STA_ASSOC)) {
|
2011-10-20 14:03:08 -04:00
|
|
|
wpa_printf(MSG_DEBUG, " Polling STA");
|
2008-02-27 20:34:43 -05:00
|
|
|
sta->flags |= WLAN_STA_PENDING_POLL;
|
2011-10-20 14:03:08 -04:00
|
|
|
hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
|
|
|
|
sta->flags & WLAN_STA_WMM);
|
2008-02-27 20:34:43 -05:00
|
|
|
} else if (sta->timeout_next != STA_REMOVE) {
|
|
|
|
int deauth = sta->timeout_next == STA_DEAUTH;
|
|
|
|
|
2011-12-10 09:34:52 -05:00
|
|
|
wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
|
|
|
|
"Timeout, sending %s info to STA " MACSTR,
|
|
|
|
deauth ? "deauthentication" : "disassociation",
|
|
|
|
MAC2STR(sta->addr));
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
if (deauth) {
|
2010-11-24 08:36:02 -05:00
|
|
|
hostapd_drv_sta_deauth(
|
|
|
|
hapd, sta->addr,
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID);
|
2008-02-27 20:34:43 -05:00
|
|
|
} else {
|
2013-04-05 11:41:26 -04:00
|
|
|
reason = (sta->timeout_next == STA_DISASSOC) ?
|
|
|
|
WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID;
|
|
|
|
|
|
|
|
hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (sta->timeout_next) {
|
|
|
|
case STA_NULLFUNC:
|
|
|
|
sta->timeout_next = STA_DISASSOC;
|
2012-04-11 07:09:40 -04:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
|
|
|
|
"for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
|
|
|
|
__func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
|
2008-02-27 20:34:43 -05:00
|
|
|
eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
|
|
|
|
hapd, sta);
|
|
|
|
break;
|
|
|
|
case STA_DISASSOC:
|
2013-04-05 11:41:26 -04:00
|
|
|
case STA_DISASSOC_FROM_CLI:
|
2011-11-03 16:17:41 -04:00
|
|
|
ap_sta_set_authorized(hapd, sta, 0);
|
2008-02-27 20:34:43 -05:00
|
|
|
sta->flags &= ~WLAN_STA_ASSOC;
|
|
|
|
ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
|
|
|
|
if (!sta->acct_terminate_cause)
|
|
|
|
sta->acct_terminate_cause =
|
|
|
|
RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
|
|
|
|
accounting_sta_stop(hapd, sta);
|
|
|
|
ieee802_1x_free_station(sta);
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO, "disassociated due to "
|
|
|
|
"inactivity");
|
2013-04-05 11:41:26 -04:00
|
|
|
reason = (sta->timeout_next == STA_DISASSOC) ?
|
|
|
|
WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID;
|
2008-02-27 20:34:43 -05:00
|
|
|
sta->timeout_next = STA_DEAUTH;
|
2012-04-11 07:09:40 -04:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
|
|
|
|
"for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
|
|
|
|
__func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
|
2008-02-27 20:34:43 -05:00
|
|
|
eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
|
|
|
|
hapd, sta);
|
2013-04-05 11:41:26 -04:00
|
|
|
mlme_disassociate_indication(hapd, sta, reason);
|
2008-02-27 20:34:43 -05:00
|
|
|
break;
|
|
|
|
case STA_DEAUTH:
|
|
|
|
case STA_REMOVE:
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO, "deauthenticated due to "
|
2011-12-10 09:34:52 -05:00
|
|
|
"inactivity (timer DEAUTH/REMOVE)");
|
2008-02-27 20:34:43 -05:00
|
|
|
if (!sta->acct_terminate_cause)
|
|
|
|
sta->acct_terminate_cause =
|
|
|
|
RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
|
|
|
|
mlme_deauthenticate_indication(
|
|
|
|
hapd, sta,
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID);
|
|
|
|
ap_free_sta(hapd, sta);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = eloop_ctx;
|
|
|
|
struct sta_info *sta = timeout_ctx;
|
|
|
|
u8 addr[ETH_ALEN];
|
|
|
|
|
2012-02-26 15:34:19 -05:00
|
|
|
if (!(sta->flags & WLAN_STA_AUTH)) {
|
|
|
|
if (sta->flags & WLAN_STA_GAS) {
|
|
|
|
wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
|
|
|
|
"entry " MACSTR, MAC2STR(sta->addr));
|
|
|
|
ap_free_sta(hapd, sta);
|
|
|
|
}
|
2008-02-27 20:34:43 -05:00
|
|
|
return;
|
2012-02-26 15:34:19 -05:00
|
|
|
}
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
mlme_deauthenticate_indication(hapd, sta,
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID);
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO, "deauthenticated due to "
|
|
|
|
"session timeout");
|
|
|
|
sta->acct_terminate_cause =
|
|
|
|
RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
|
|
|
|
os_memcpy(addr, sta->addr, ETH_ALEN);
|
|
|
|
ap_free_sta(hapd, sta);
|
2010-11-24 08:36:02 -05:00
|
|
|
hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
|
|
|
|
u32 session_timeout)
|
|
|
|
{
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
|
|
|
|
"seconds", session_timeout);
|
|
|
|
eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
|
|
|
|
eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
|
|
|
|
hapd, sta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
|
|
|
|
{
|
|
|
|
eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
|
|
|
|
{
|
|
|
|
struct sta_info *sta;
|
|
|
|
|
|
|
|
sta = ap_get_sta(hapd, addr);
|
|
|
|
if (sta)
|
|
|
|
return sta;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, " New STA");
|
|
|
|
if (hapd->num_sta >= hapd->conf->max_num_sta) {
|
|
|
|
/* FIX: might try to remove some old STAs first? */
|
|
|
|
wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
|
|
|
|
hapd->num_sta, hapd->conf->max_num_sta);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sta = os_zalloc(sizeof(struct sta_info));
|
|
|
|
if (sta == NULL) {
|
|
|
|
wpa_printf(MSG_ERROR, "malloc failed");
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-11-28 16:03:20 -05:00
|
|
|
sta->acct_interim_interval = hapd->conf->acct_interim_interval;
|
2012-12-18 11:13:31 -05:00
|
|
|
accounting_sta_get_id(hapd, sta);
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
/* initialize STA info data */
|
2012-04-11 07:09:40 -04:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
|
|
|
|
"for " MACSTR " (%d seconds - ap_max_inactivity)",
|
|
|
|
__func__, MAC2STR(addr),
|
|
|
|
hapd->conf->ap_max_inactivity);
|
2008-02-27 20:34:43 -05:00
|
|
|
eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
|
|
|
|
ap_handle_timer, hapd, sta);
|
|
|
|
os_memcpy(sta->addr, addr, ETH_ALEN);
|
|
|
|
sta->next = hapd->sta_list;
|
|
|
|
hapd->sta_list = sta;
|
|
|
|
hapd->num_sta++;
|
|
|
|
ap_sta_hash_add(hapd, sta);
|
|
|
|
sta->ssid = &hapd->conf->ssid;
|
2010-03-06 15:30:25 -05:00
|
|
|
ap_sta_remove_in_other_bss(hapd, sta);
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
return sta;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
|
|
|
|
{
|
|
|
|
ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
|
|
|
|
MAC2STR(sta->addr));
|
2010-11-24 08:36:02 -05:00
|
|
|
if (hostapd_drv_sta_remove(hapd, sta->addr) &&
|
2008-02-27 20:34:43 -05:00
|
|
|
sta->flags & WLAN_STA_ASSOC) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
|
|
|
|
" from kernel driver.", MAC2STR(sta->addr));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-06 15:30:25 -05:00
|
|
|
static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
|
|
|
|
struct sta_info *sta)
|
2008-02-27 20:34:43 -05:00
|
|
|
{
|
|
|
|
struct hostapd_iface *iface = hapd->iface;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < iface->num_bss; i++) {
|
|
|
|
struct hostapd_data *bss = iface->bss[i];
|
|
|
|
struct sta_info *sta2;
|
|
|
|
/* bss should always be set during operation, but it may be
|
|
|
|
* NULL during reconfiguration. Assume the STA is not
|
|
|
|
* associated to another BSS in that case to avoid NULL pointer
|
|
|
|
* dereferences. */
|
|
|
|
if (bss == hapd || bss == NULL)
|
|
|
|
continue;
|
|
|
|
sta2 = ap_get_sta(bss, sta->addr);
|
2010-03-06 15:30:25 -05:00
|
|
|
if (!sta2)
|
|
|
|
continue;
|
2008-02-27 20:34:43 -05:00
|
|
|
|
2010-03-06 15:30:25 -05:00
|
|
|
ap_sta_disconnect(bss, sta2, sta2->addr,
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID);
|
|
|
|
}
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-28 16:07:02 -04:00
|
|
|
static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = eloop_ctx;
|
|
|
|
struct sta_info *sta = timeout_ctx;
|
|
|
|
|
|
|
|
ap_sta_remove(hapd, sta);
|
|
|
|
mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
|
|
|
|
u16 reason)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
|
|
|
|
hapd->conf->iface, MAC2STR(sta->addr));
|
2013-03-16 06:35:49 -04:00
|
|
|
sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
|
2011-08-28 16:07:02 -04:00
|
|
|
ap_sta_set_authorized(hapd, sta, 0);
|
2008-02-27 20:34:43 -05:00
|
|
|
sta->timeout_next = STA_DEAUTH;
|
2012-04-11 07:09:40 -04:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
|
|
|
|
"for " MACSTR " (%d seconds - "
|
|
|
|
"AP_MAX_INACTIVITY_AFTER_DISASSOC)",
|
|
|
|
__func__, MAC2STR(sta->addr),
|
|
|
|
AP_MAX_INACTIVITY_AFTER_DISASSOC);
|
2008-02-27 20:34:43 -05:00
|
|
|
eloop_cancel_timeout(ap_handle_timer, hapd, sta);
|
|
|
|
eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
|
|
|
|
ap_handle_timer, hapd, sta);
|
|
|
|
accounting_sta_stop(hapd, sta);
|
|
|
|
ieee802_1x_free_station(sta);
|
|
|
|
|
2011-08-28 16:07:02 -04:00
|
|
|
sta->disassoc_reason = reason;
|
2011-09-06 14:03:02 -04:00
|
|
|
sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
|
2011-08-28 16:07:02 -04:00
|
|
|
eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
|
|
|
|
eloop_register_timeout(hapd->iface->drv_flags &
|
|
|
|
WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
|
|
|
|
ap_sta_disassoc_cb_timeout, hapd, sta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = eloop_ctx;
|
|
|
|
struct sta_info *sta = timeout_ctx;
|
|
|
|
|
|
|
|
ap_sta_remove(hapd, sta);
|
|
|
|
mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
|
|
|
|
u16 reason)
|
|
|
|
{
|
|
|
|
wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
|
|
|
|
hapd->conf->iface, MAC2STR(sta->addr));
|
|
|
|
sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
|
2011-08-28 16:07:02 -04:00
|
|
|
ap_sta_set_authorized(hapd, sta, 0);
|
2008-02-27 20:34:43 -05:00
|
|
|
sta->timeout_next = STA_REMOVE;
|
2012-04-11 07:09:40 -04:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
|
|
|
|
"for " MACSTR " (%d seconds - "
|
|
|
|
"AP_MAX_INACTIVITY_AFTER_DEAUTH)",
|
|
|
|
__func__, MAC2STR(sta->addr),
|
|
|
|
AP_MAX_INACTIVITY_AFTER_DEAUTH);
|
2008-02-27 20:34:43 -05:00
|
|
|
eloop_cancel_timeout(ap_handle_timer, hapd, sta);
|
|
|
|
eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
|
|
|
|
ap_handle_timer, hapd, sta);
|
|
|
|
accounting_sta_stop(hapd, sta);
|
|
|
|
ieee802_1x_free_station(sta);
|
|
|
|
|
2011-08-28 16:07:02 -04:00
|
|
|
sta->deauth_reason = reason;
|
2011-09-06 14:03:02 -04:00
|
|
|
sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
|
2011-08-28 16:07:02 -04:00
|
|
|
eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
|
|
|
|
eloop_register_timeout(hapd->iface->drv_flags &
|
|
|
|
WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
|
|
|
|
ap_sta_deauth_cb_timeout, hapd, sta);
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-19 02:23:31 -04:00
|
|
|
#ifdef CONFIG_WPS
|
|
|
|
int ap_sta_wps_cancel(struct hostapd_data *hapd,
|
|
|
|
struct sta_info *sta, void *ctx)
|
|
|
|
{
|
|
|
|
if (sta && (sta->flags & WLAN_STA_WPS)) {
|
|
|
|
ap_sta_deauthenticate(hapd, sta,
|
|
|
|
WLAN_REASON_PREV_AUTH_NOT_VALID);
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
|
|
|
|
__func__, MAC2STR(sta->addr));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS */
|
|
|
|
|
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
|
|
|
|
int old_vlanid)
|
|
|
|
{
|
2009-01-12 14:39:19 -05:00
|
|
|
#ifndef CONFIG_NO_VLAN
|
2008-02-27 20:34:43 -05:00
|
|
|
const char *iface;
|
|
|
|
struct hostapd_vlan *vlan = NULL;
|
2010-04-15 16:44:10 -04:00
|
|
|
int ret;
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not proceed furthur if the vlan id remains same. We do not want
|
|
|
|
* duplicate dynamic vlan entries.
|
|
|
|
*/
|
|
|
|
if (sta->vlan_id == old_vlanid)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* During 1x reauth, if the vlan id changes, then remove the old id and
|
|
|
|
* proceed furthur to add the new one.
|
|
|
|
*/
|
|
|
|
if (old_vlanid > 0)
|
|
|
|
vlan_remove_dynamic(hapd, old_vlanid);
|
|
|
|
|
|
|
|
iface = hapd->conf->iface;
|
|
|
|
if (sta->ssid->vlan[0])
|
|
|
|
iface = sta->ssid->vlan;
|
|
|
|
|
|
|
|
if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
|
|
|
|
sta->vlan_id = 0;
|
|
|
|
else if (sta->vlan_id > 0) {
|
2013-08-04 14:45:50 -04:00
|
|
|
struct hostapd_vlan *wildcard_vlan = NULL;
|
2008-02-27 20:34:43 -05:00
|
|
|
vlan = hapd->conf->vlan;
|
|
|
|
while (vlan) {
|
2013-08-04 14:45:50 -04:00
|
|
|
if (vlan->vlan_id == sta->vlan_id)
|
2008-02-27 20:34:43 -05:00
|
|
|
break;
|
2013-08-04 14:45:50 -04:00
|
|
|
if (vlan->vlan_id == VLAN_ID_WILDCARD)
|
|
|
|
wildcard_vlan = vlan;
|
2008-02-27 20:34:43 -05:00
|
|
|
vlan = vlan->next;
|
|
|
|
}
|
2013-08-04 14:45:50 -04:00
|
|
|
if (!vlan)
|
|
|
|
vlan = wildcard_vlan;
|
|
|
|
if (vlan)
|
|
|
|
iface = vlan->ifname;
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sta->vlan_id > 0 && vlan == NULL) {
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
|
|
|
|
"binding station to (vlan_id=%d)",
|
|
|
|
sta->vlan_id);
|
|
|
|
return -1;
|
|
|
|
} else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
|
|
|
|
vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
|
|
|
|
if (vlan == NULL) {
|
|
|
|
hostapd_logger(hapd, sta->addr,
|
|
|
|
HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG, "could not add "
|
|
|
|
"dynamic VLAN interface for vlan_id=%d",
|
|
|
|
sta->vlan_id);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface = vlan->ifname;
|
|
|
|
if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
|
|
|
|
hostapd_logger(hapd, sta->addr,
|
|
|
|
HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG, "could not "
|
|
|
|
"configure encryption for dynamic VLAN "
|
|
|
|
"interface for vlan_id=%d",
|
|
|
|
sta->vlan_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
|
|
|
|
"interface '%s'", iface);
|
|
|
|
} else if (vlan && vlan->vlan_id == sta->vlan_id) {
|
|
|
|
if (sta->vlan_id > 0) {
|
|
|
|
vlan->dynamic_vlan++;
|
|
|
|
hostapd_logger(hapd, sta->addr,
|
|
|
|
HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG, "updated existing "
|
|
|
|
"dynamic VLAN interface '%s'", iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update encryption configuration for statically generated
|
|
|
|
* VLAN interface. This is only used for static WEP
|
|
|
|
* configuration for the case where hostapd did not yet know
|
|
|
|
* which keys are to be used when the interface was added.
|
|
|
|
*/
|
|
|
|
if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
|
|
|
|
hostapd_logger(hapd, sta->addr,
|
|
|
|
HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG, "could not "
|
|
|
|
"configure encryption for VLAN "
|
|
|
|
"interface for vlan_id=%d",
|
|
|
|
sta->vlan_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG, "binding station to interface "
|
|
|
|
"'%s'", iface);
|
|
|
|
|
|
|
|
if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
|
|
|
|
wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
|
|
|
|
|
2010-11-24 08:36:02 -05:00
|
|
|
ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
|
2010-04-15 16:44:10 -04:00
|
|
|
if (ret < 0) {
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
|
|
|
|
"entry to vlan_id=%d", sta->vlan_id);
|
|
|
|
}
|
|
|
|
return ret;
|
2009-01-12 14:39:19 -05:00
|
|
|
#else /* CONFIG_NO_VLAN */
|
|
|
|
return 0;
|
|
|
|
#endif /* CONFIG_NO_VLAN */
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
2008-08-31 04:04:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211W
|
|
|
|
|
2008-12-26 05:30:34 -05:00
|
|
|
int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
|
2008-08-31 04:04:47 -04:00
|
|
|
{
|
2008-12-26 05:30:34 -05:00
|
|
|
u32 tu;
|
|
|
|
struct os_time now, passed;
|
|
|
|
os_get_time(&now);
|
|
|
|
os_time_sub(&now, &sta->sa_query_start, &passed);
|
|
|
|
tu = (passed.sec * 1000000 + passed.usec) / 1024;
|
|
|
|
if (hapd->conf->assoc_sa_query_max_timeout < tu) {
|
|
|
|
hostapd_logger(hapd, sta->addr,
|
|
|
|
HOSTAPD_MODULE_IEEE80211,
|
2008-08-31 04:04:47 -04:00
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
2008-12-26 04:46:21 -05:00
|
|
|
"association SA Query timed out");
|
|
|
|
sta->sa_query_timed_out = 1;
|
|
|
|
os_free(sta->sa_query_trans_id);
|
|
|
|
sta->sa_query_trans_id = NULL;
|
|
|
|
sta->sa_query_count = 0;
|
2008-12-26 05:30:34 -05:00
|
|
|
eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
|
|
|
|
return 1;
|
2008-08-31 04:04:47 -04:00
|
|
|
}
|
|
|
|
|
2008-12-26 05:30:34 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = eloop_ctx;
|
|
|
|
struct sta_info *sta = timeout_ctx;
|
|
|
|
unsigned int timeout, sec, usec;
|
|
|
|
u8 *trans_id, *nbuf;
|
|
|
|
|
|
|
|
if (sta->sa_query_count > 0 &&
|
|
|
|
ap_check_sa_query_timeout(hapd, sta))
|
|
|
|
return;
|
|
|
|
|
2012-08-13 14:21:23 -04:00
|
|
|
nbuf = os_realloc_array(sta->sa_query_trans_id,
|
|
|
|
sta->sa_query_count + 1,
|
|
|
|
WLAN_SA_QUERY_TR_ID_LEN);
|
2008-08-31 04:04:47 -04:00
|
|
|
if (nbuf == NULL)
|
|
|
|
return;
|
2008-12-26 05:30:34 -05:00
|
|
|
if (sta->sa_query_count == 0) {
|
|
|
|
/* Starting a new SA Query procedure */
|
|
|
|
os_get_time(&sta->sa_query_start);
|
|
|
|
}
|
2008-12-26 04:46:21 -05:00
|
|
|
trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
|
|
|
|
sta->sa_query_trans_id = nbuf;
|
|
|
|
sta->sa_query_count++;
|
2008-08-31 04:04:47 -04:00
|
|
|
|
2008-12-26 04:46:21 -05:00
|
|
|
os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
|
2008-08-31 04:04:47 -04:00
|
|
|
|
2008-12-26 05:30:34 -05:00
|
|
|
timeout = hapd->conf->assoc_sa_query_retry_timeout;
|
|
|
|
sec = ((timeout / 1000) * 1024) / 1000;
|
|
|
|
usec = (timeout % 1000) * 1024;
|
|
|
|
eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
|
|
|
|
|
2008-08-31 04:04:47 -04:00
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
2008-12-26 04:46:21 -05:00
|
|
|
"association SA Query attempt %d", sta->sa_query_count);
|
2008-08-31 04:04:47 -04:00
|
|
|
|
2008-12-26 04:46:21 -05:00
|
|
|
ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
|
2008-08-31 04:04:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-26 04:46:21 -05:00
|
|
|
void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
|
2008-08-31 04:04:47 -04:00
|
|
|
{
|
2008-12-26 04:46:21 -05:00
|
|
|
ap_sa_query_timer(hapd, sta);
|
2008-08-31 04:04:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-26 04:46:21 -05:00
|
|
|
void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
|
2008-08-31 04:04:47 -04:00
|
|
|
{
|
2008-12-26 04:46:21 -05:00
|
|
|
eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
|
|
|
|
os_free(sta->sa_query_trans_id);
|
|
|
|
sta->sa_query_trans_id = NULL;
|
|
|
|
sta->sa_query_count = 0;
|
2008-08-31 04:04:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_IEEE80211W */
|
2009-12-24 13:41:30 -05:00
|
|
|
|
|
|
|
|
2011-02-02 09:52:32 -05:00
|
|
|
void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
|
|
|
|
int authorized)
|
|
|
|
{
|
2011-12-10 05:26:00 -05:00
|
|
|
const u8 *dev_addr = NULL;
|
2013-05-18 12:09:41 -04:00
|
|
|
char buf[100];
|
2012-06-17 04:58:46 -04:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
u8 addr[ETH_ALEN];
|
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
|
2011-02-02 09:52:32 -05:00
|
|
|
if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
|
|
|
|
return;
|
|
|
|
|
2011-11-03 16:17:41 -04:00
|
|
|
#ifdef CONFIG_P2P
|
2012-06-17 04:58:46 -04:00
|
|
|
if (hapd->p2p_group == NULL) {
|
|
|
|
if (sta->p2p_ie != NULL &&
|
|
|
|
p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
|
|
|
|
dev_addr = addr;
|
|
|
|
} else
|
|
|
|
dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
|
2011-11-03 16:17:41 -04:00
|
|
|
#endif /* CONFIG_P2P */
|
2011-12-10 05:26:00 -05:00
|
|
|
|
2013-05-18 12:09:41 -04:00
|
|
|
if (dev_addr)
|
|
|
|
os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
|
|
|
|
MAC2STR(sta->addr), MAC2STR(dev_addr));
|
|
|
|
else
|
|
|
|
os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
|
|
|
|
|
2011-12-10 05:26:00 -05:00
|
|
|
if (authorized) {
|
2013-05-18 12:09:41 -04:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s", buf);
|
|
|
|
|
2011-07-21 18:19:46 -04:00
|
|
|
if (hapd->msg_ctx_parent &&
|
2013-05-18 12:09:41 -04:00
|
|
|
hapd->msg_ctx_parent != hapd->msg_ctx)
|
2013-05-18 12:18:31 -04:00
|
|
|
wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
|
|
|
|
AP_STA_CONNECTED "%s", buf);
|
2011-11-03 16:17:41 -04:00
|
|
|
|
2011-02-02 09:52:32 -05:00
|
|
|
sta->flags |= WLAN_STA_AUTHORIZED;
|
2011-11-03 16:17:41 -04:00
|
|
|
} else {
|
2013-05-18 12:09:41 -04:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
|
|
|
|
|
2011-07-21 18:19:46 -04:00
|
|
|
if (hapd->msg_ctx_parent &&
|
2013-05-18 12:09:41 -04:00
|
|
|
hapd->msg_ctx_parent != hapd->msg_ctx)
|
2013-05-18 12:18:31 -04:00
|
|
|
wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
|
|
|
|
AP_STA_DISCONNECTED "%s", buf);
|
2013-05-18 12:09:41 -04:00
|
|
|
|
2011-02-02 09:52:32 -05:00
|
|
|
sta->flags &= ~WLAN_STA_AUTHORIZED;
|
2011-11-03 16:17:41 -04:00
|
|
|
}
|
2011-02-02 09:56:59 -05:00
|
|
|
|
|
|
|
if (hapd->sta_authorized_cb)
|
|
|
|
hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
|
2011-12-22 15:47:41 -05:00
|
|
|
sta->addr, authorized, dev_addr);
|
2011-02-02 09:52:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-24 13:41:30 -05:00
|
|
|
void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
|
|
|
|
const u8 *addr, u16 reason)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (sta == NULL && addr)
|
|
|
|
sta = ap_get_sta(hapd, addr);
|
|
|
|
|
|
|
|
if (addr)
|
2010-11-24 08:36:02 -05:00
|
|
|
hostapd_drv_sta_deauth(hapd, addr, reason);
|
2009-12-24 13:41:30 -05:00
|
|
|
|
|
|
|
if (sta == NULL)
|
|
|
|
return;
|
2011-02-02 09:52:32 -05:00
|
|
|
ap_sta_set_authorized(hapd, sta, 0);
|
2012-01-25 15:32:58 -05:00
|
|
|
wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
|
|
|
|
ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
|
2011-02-02 09:52:32 -05:00
|
|
|
sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
|
2012-04-11 07:09:40 -04:00
|
|
|
wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
|
|
|
|
"for " MACSTR " (%d seconds - "
|
|
|
|
"AP_MAX_INACTIVITY_AFTER_DEAUTH)",
|
|
|
|
__func__, MAC2STR(sta->addr),
|
|
|
|
AP_MAX_INACTIVITY_AFTER_DEAUTH);
|
2009-12-24 13:41:30 -05:00
|
|
|
eloop_cancel_timeout(ap_handle_timer, hapd, sta);
|
2011-08-28 16:07:02 -04:00
|
|
|
eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
|
|
|
|
ap_handle_timer, hapd, sta);
|
2009-12-24 13:41:30 -05:00
|
|
|
sta->timeout_next = STA_REMOVE;
|
2011-08-28 16:07:02 -04:00
|
|
|
|
|
|
|
sta->deauth_reason = reason;
|
2011-09-06 14:03:02 -04:00
|
|
|
sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
|
2011-08-28 16:07:02 -04:00
|
|
|
eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
|
|
|
|
eloop_register_timeout(hapd->iface->drv_flags &
|
|
|
|
WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
|
|
|
|
ap_sta_deauth_cb_timeout, hapd, sta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
|
|
|
|
{
|
2011-09-06 14:03:02 -04:00
|
|
|
if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
|
2011-08-28 16:07:02 -04:00
|
|
|
eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
|
|
|
|
ap_sta_deauth_cb_timeout(hapd, sta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
|
|
|
|
{
|
2011-09-06 14:03:02 -04:00
|
|
|
if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
|
|
|
|
eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
|
|
|
|
ap_sta_disassoc_cb_timeout(hapd, sta);
|
2009-12-24 13:41:30 -05:00
|
|
|
}
|