2008-02-28 02:34:43 +01:00
|
|
|
/*
|
|
|
|
* hostapd / AP table
|
2009-12-25 00:12:50 +01:00
|
|
|
* Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
|
2008-08-22 08:15:05 +02:00
|
|
|
* Copyright (c) 2003-2004, Instant802 Networks, Inc.
|
|
|
|
* Copyright (c) 2006, Devicescape Software, Inc.
|
2008-02-28 02:34:43 +01:00
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2008-02-28 02:34:43 +01:00
|
|
|
*/
|
|
|
|
|
2009-12-25 00:12:50 +01:00
|
|
|
#include "utils/includes.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2009-12-25 00:12:50 +01:00
|
|
|
#include "utils/common.h"
|
|
|
|
#include "utils/eloop.h"
|
2009-12-25 23:31:51 +01:00
|
|
|
#include "common/ieee802_11_defs.h"
|
|
|
|
#include "common/ieee802_11_common.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
#include "hostapd.h"
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "ap_config.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
#include "ieee802_11.h"
|
2009-03-25 15:13:35 +01:00
|
|
|
#include "sta_info.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
#include "beacon.h"
|
2009-12-25 00:12:50 +01:00
|
|
|
#include "ap_list.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* AP list is a double linked list with head->prev pointing to the end of the
|
|
|
|
* list and tail->next = NULL. Entries are moved to the head of the list
|
|
|
|
* whenever a beacon has been received from the AP in question. The tail entry
|
|
|
|
* in this link will thus be the least recently used entry. */
|
|
|
|
|
|
|
|
|
|
|
|
static int ap_list_beacon_olbc(struct hostapd_iface *iface, struct ap_info *ap)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2014-02-06 14:22:06 +01:00
|
|
|
if (iface->current_mode == NULL ||
|
|
|
|
iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G ||
|
2008-02-28 02:34:43 +01:00
|
|
|
iface->conf->channel != ap->channel)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ap->erp != -1 && (ap->erp & ERP_INFO_NON_ERP_PRESENT))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
for (i = 0; i < WLAN_SUPP_RATES_MAX; i++) {
|
|
|
|
int rate = (ap->supported_rates[i] & 0x7f) * 5;
|
|
|
|
if (rate == 60 || rate == 90 || rate > 110)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-30 16:06:50 +01:00
|
|
|
static struct ap_info * ap_get_ap(struct hostapd_iface *iface, const u8 *ap)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
struct ap_info *s;
|
|
|
|
|
|
|
|
s = iface->ap_hash[STA_HASH(ap)];
|
|
|
|
while (s != NULL && os_memcmp(s->addr, ap, ETH_ALEN) != 0)
|
|
|
|
s = s->hnext;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ap_ap_list_add(struct hostapd_iface *iface, struct ap_info *ap)
|
|
|
|
{
|
|
|
|
if (iface->ap_list) {
|
|
|
|
ap->prev = iface->ap_list->prev;
|
|
|
|
iface->ap_list->prev = ap;
|
|
|
|
} else
|
|
|
|
ap->prev = ap;
|
|
|
|
ap->next = iface->ap_list;
|
|
|
|
iface->ap_list = ap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ap_ap_list_del(struct hostapd_iface *iface, struct ap_info *ap)
|
|
|
|
{
|
|
|
|
if (iface->ap_list == ap)
|
|
|
|
iface->ap_list = ap->next;
|
|
|
|
else
|
|
|
|
ap->prev->next = ap->next;
|
|
|
|
|
|
|
|
if (ap->next)
|
|
|
|
ap->next->prev = ap->prev;
|
|
|
|
else if (iface->ap_list)
|
|
|
|
iface->ap_list->prev = ap->prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ap_ap_hash_add(struct hostapd_iface *iface, struct ap_info *ap)
|
|
|
|
{
|
|
|
|
ap->hnext = iface->ap_hash[STA_HASH(ap->addr)];
|
|
|
|
iface->ap_hash[STA_HASH(ap->addr)] = ap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ap_ap_hash_del(struct hostapd_iface *iface, struct ap_info *ap)
|
|
|
|
{
|
|
|
|
struct ap_info *s;
|
|
|
|
|
|
|
|
s = iface->ap_hash[STA_HASH(ap->addr)];
|
|
|
|
if (s == NULL) return;
|
|
|
|
if (os_memcmp(s->addr, ap->addr, ETH_ALEN) == 0) {
|
|
|
|
iface->ap_hash[STA_HASH(ap->addr)] = s->hnext;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (s->hnext != NULL &&
|
|
|
|
os_memcmp(s->hnext->addr, ap->addr, ETH_ALEN) != 0)
|
|
|
|
s = s->hnext;
|
|
|
|
if (s->hnext != NULL)
|
|
|
|
s->hnext = s->hnext->hnext;
|
|
|
|
else
|
2015-01-29 20:12:51 +01:00
|
|
|
wpa_printf(MSG_INFO, "AP: could not remove AP " MACSTR
|
|
|
|
" from hash table", MAC2STR(ap->addr));
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ap_free_ap(struct hostapd_iface *iface, struct ap_info *ap)
|
|
|
|
{
|
|
|
|
ap_ap_hash_del(iface, ap);
|
|
|
|
ap_ap_list_del(iface, ap);
|
|
|
|
|
|
|
|
iface->num_ap--;
|
|
|
|
os_free(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void hostapd_free_aps(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
struct ap_info *ap, *prev;
|
|
|
|
|
|
|
|
ap = iface->ap_list;
|
|
|
|
|
|
|
|
while (ap) {
|
|
|
|
prev = ap;
|
|
|
|
ap = ap->next;
|
|
|
|
ap_free_ap(iface, prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
iface->ap_list = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-13 22:25:30 +01:00
|
|
|
static struct ap_info * ap_ap_add(struct hostapd_iface *iface, const u8 *addr)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
struct ap_info *ap;
|
|
|
|
|
|
|
|
ap = os_zalloc(sizeof(struct ap_info));
|
|
|
|
if (ap == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* initialize AP info data */
|
|
|
|
os_memcpy(ap->addr, addr, ETH_ALEN);
|
|
|
|
ap_ap_list_add(iface, ap);
|
|
|
|
iface->num_ap++;
|
|
|
|
ap_ap_hash_add(iface, ap);
|
|
|
|
|
|
|
|
if (iface->num_ap > iface->conf->ap_table_max_size && ap != ap->prev) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Removing the least recently used AP "
|
|
|
|
MACSTR " from AP table", MAC2STR(ap->prev->addr));
|
|
|
|
ap_free_ap(iface, ap->prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ap_list_process_beacon(struct hostapd_iface *iface,
|
2009-12-13 22:25:30 +01:00
|
|
|
const struct ieee80211_mgmt *mgmt,
|
2008-02-28 02:34:43 +01:00
|
|
|
struct ieee802_11_elems *elems,
|
|
|
|
struct hostapd_frame_info *fi)
|
|
|
|
{
|
|
|
|
struct ap_info *ap;
|
|
|
|
int new_ap = 0;
|
2008-08-21 17:18:38 +02:00
|
|
|
int set_beacon = 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (iface->conf->ap_table_max_size < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ap = ap_get_ap(iface, mgmt->bssid);
|
|
|
|
if (!ap) {
|
|
|
|
ap = ap_ap_add(iface, mgmt->bssid);
|
|
|
|
if (!ap) {
|
2015-01-29 20:12:51 +01:00
|
|
|
wpa_printf(MSG_INFO,
|
|
|
|
"Failed to allocate AP information entry");
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
new_ap = 1;
|
|
|
|
}
|
|
|
|
|
2012-08-19 16:52:41 +02:00
|
|
|
merge_byte_arrays(ap->supported_rates, WLAN_SUPP_RATES_MAX,
|
|
|
|
elems->supp_rates, elems->supp_rates_len,
|
|
|
|
elems->ext_supp_rates, elems->ext_supp_rates_len);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (elems->erp_info && elems->erp_info_len == 1)
|
|
|
|
ap->erp = elems->erp_info[0];
|
|
|
|
else
|
|
|
|
ap->erp = -1;
|
|
|
|
|
|
|
|
if (elems->ds_params && elems->ds_params_len == 1)
|
|
|
|
ap->channel = elems->ds_params[0];
|
2013-03-30 17:05:18 +01:00
|
|
|
else if (elems->ht_operation && elems->ht_operation_len >= 1)
|
|
|
|
ap->channel = elems->ht_operation[0];
|
2008-02-28 02:34:43 +01:00
|
|
|
else if (fi)
|
|
|
|
ap->channel = fi->channel;
|
|
|
|
|
2008-08-21 17:18:38 +02:00
|
|
|
if (elems->ht_capabilities)
|
|
|
|
ap->ht_support = 1;
|
|
|
|
else
|
|
|
|
ap->ht_support = 0;
|
|
|
|
|
2013-11-25 21:56:06 +01:00
|
|
|
os_get_reltime(&ap->last_beacon);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2009-04-17 14:47:37 +02:00
|
|
|
if (!new_ap && ap != iface->ap_list) {
|
2008-02-28 02:34:43 +01:00
|
|
|
/* move AP entry into the beginning of the list so that the
|
|
|
|
* oldest entry is always in the end of the list */
|
|
|
|
ap_ap_list_del(iface, ap);
|
|
|
|
ap_ap_list_add(iface, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!iface->olbc &&
|
|
|
|
ap_list_beacon_olbc(iface, ap)) {
|
|
|
|
iface->olbc = 1;
|
2013-03-30 17:05:18 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "OLBC AP detected: " MACSTR
|
|
|
|
" (channel %d) - enable protection",
|
|
|
|
MAC2STR(ap->addr), ap->channel);
|
2008-08-21 17:18:38 +02:00
|
|
|
set_beacon++;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
2008-08-21 17:18:38 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211N
|
2013-03-30 17:05:18 +01:00
|
|
|
if (!iface->olbc_ht && !ap->ht_support &&
|
|
|
|
(ap->channel == 0 ||
|
|
|
|
ap->channel == iface->conf->channel ||
|
|
|
|
ap->channel == iface->conf->channel +
|
|
|
|
iface->conf->secondary_channel * 4)) {
|
2008-08-21 17:18:38 +02:00
|
|
|
iface->olbc_ht = 1;
|
|
|
|
hostapd_ht_operation_update(iface);
|
|
|
|
wpa_printf(MSG_DEBUG, "OLBC HT AP detected: " MACSTR
|
2013-03-30 17:05:18 +01:00
|
|
|
" (channel %d) - enable protection",
|
|
|
|
MAC2STR(ap->addr), ap->channel);
|
2008-08-21 17:18:38 +02:00
|
|
|
set_beacon++;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211N */
|
|
|
|
|
|
|
|
if (set_beacon)
|
2012-04-01 17:12:04 +02:00
|
|
|
ieee802_11_update_beacons(iface);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ap_list_timer(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct hostapd_iface *iface = eloop_ctx;
|
2013-11-25 21:56:06 +01:00
|
|
|
struct os_reltime now;
|
2008-02-28 02:34:43 +01:00
|
|
|
struct ap_info *ap;
|
2008-08-21 17:18:38 +02:00
|
|
|
int set_beacon = 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
eloop_register_timeout(10, 0, ap_list_timer, iface, NULL);
|
|
|
|
|
|
|
|
if (!iface->ap_list)
|
|
|
|
return;
|
|
|
|
|
2013-11-25 21:56:06 +01:00
|
|
|
os_get_reltime(&now);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
while (iface->ap_list) {
|
|
|
|
ap = iface->ap_list->prev;
|
2013-11-25 21:56:06 +01:00
|
|
|
if (!os_reltime_expired(&now, &ap->last_beacon,
|
|
|
|
iface->conf->ap_table_expiration_time))
|
2008-02-28 02:34:43 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
ap_free_ap(iface, ap);
|
|
|
|
}
|
|
|
|
|
2008-08-21 17:18:38 +02:00
|
|
|
if (iface->olbc || iface->olbc_ht) {
|
2008-02-28 02:34:43 +01:00
|
|
|
int olbc = 0;
|
2008-08-21 17:18:38 +02:00
|
|
|
int olbc_ht = 0;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
ap = iface->ap_list;
|
2008-08-21 17:18:38 +02:00
|
|
|
while (ap && (olbc == 0 || olbc_ht == 0)) {
|
|
|
|
if (ap_list_beacon_olbc(iface, ap))
|
2008-02-28 02:34:43 +01:00
|
|
|
olbc = 1;
|
2009-12-06 18:17:54 +01:00
|
|
|
if (!ap->ht_support)
|
2008-08-21 17:18:38 +02:00
|
|
|
olbc_ht = 1;
|
2008-02-28 02:34:43 +01:00
|
|
|
ap = ap->next;
|
|
|
|
}
|
2008-08-21 17:18:38 +02:00
|
|
|
if (!olbc && iface->olbc) {
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "OLBC not detected anymore");
|
|
|
|
iface->olbc = 0;
|
2008-08-21 17:18:38 +02:00
|
|
|
set_beacon++;
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_IEEE80211N
|
|
|
|
if (!olbc_ht && iface->olbc_ht) {
|
|
|
|
wpa_printf(MSG_DEBUG, "OLBC HT not detected anymore");
|
|
|
|
iface->olbc_ht = 0;
|
|
|
|
hostapd_ht_operation_update(iface);
|
|
|
|
set_beacon++;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
2008-08-21 17:18:38 +02:00
|
|
|
#endif /* CONFIG_IEEE80211N */
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
2008-08-21 17:18:38 +02:00
|
|
|
|
|
|
|
if (set_beacon)
|
2012-04-01 17:12:04 +02:00
|
|
|
ieee802_11_update_beacons(iface);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ap_list_init(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
eloop_register_timeout(10, 0, ap_list_timer, iface, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ap_list_deinit(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
eloop_cancel_timeout(ap_list_timer, iface, NULL);
|
|
|
|
hostapd_free_aps(iface);
|
|
|
|
}
|