wlantest: Create station list for each BSS

This commit is contained in:
Jouni Malinen 2010-11-06 17:31:02 +02:00
parent d84d389351
commit 422ef7d205
5 changed files with 97 additions and 0 deletions

View file

@ -46,6 +46,7 @@ OBJS += readpcap.o
OBJS += monitor.o
OBJS += process.o
OBJS += bss.o
OBJS += sta.o
OBJS += crc32.o
LIBS += -lpcap

View file

@ -33,6 +33,7 @@ struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid)
bss = os_zalloc(sizeof(*bss));
if (bss == NULL)
return NULL;
dl_list_init(&bss->sta);
os_memcpy(bss->bssid, bssid, ETH_ALEN);
dl_list_add(&wt->bss, &bss->list);
wpa_printf(MSG_DEBUG, "Discovered new BSS - " MACSTR,
@ -43,6 +44,9 @@ struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid)
void bss_deinit(struct wlantest_bss *bss)
{
struct wlantest_sta *sta, *n;
dl_list_for_each_safe(sta, n, &bss->sta, struct wlantest_sta, list)
sta_deinit(sta);
dl_list_del(&bss->list);
os_free(bss);
}

View file

@ -162,6 +162,38 @@ static void rx_mgmt_probe_resp(struct wlantest *wt, const u8 *data, size_t len)
}
static void rx_mgmt_auth(struct wlantest *wt, const u8 *data, size_t len)
{
const struct ieee80211_mgmt *mgmt;
struct wlantest_bss *bss;
struct wlantest_sta *sta;
mgmt = (const struct ieee80211_mgmt *) data;
bss = bss_get(wt, mgmt->bssid);
if (bss == NULL)
return;
if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0)
sta = sta_get(bss, mgmt->da);
else
sta = sta_get(bss, mgmt->sa);
if (sta == NULL)
return;
if (len < 24 + 6) {
wpa_printf(MSG_INFO, "Too short Authentication frame from "
MACSTR, MAC2STR(mgmt->sa));
return;
}
wpa_printf(MSG_DEBUG, "AUTH " MACSTR " -> " MACSTR
" (alg=%u trans=%u status=%u)",
MAC2STR(mgmt->sa), MAC2STR(mgmt->da),
le_to_host16(mgmt->u.auth.auth_alg),
le_to_host16(mgmt->u.auth.auth_transaction),
le_to_host16(mgmt->u.auth.status_code));
}
static void rx_mgmt(struct wlantest *wt, const u8 *data, size_t len)
{
const struct ieee80211_hdr *hdr;
@ -193,6 +225,9 @@ static void rx_mgmt(struct wlantest *wt, const u8 *data, size_t len)
case WLAN_FC_STYPE_PROBE_RESP:
rx_mgmt_probe_resp(wt, data, len);
break;
case WLAN_FC_STYPE_AUTH:
rx_mgmt_auth(wt, data, len);
break;
}
}

48
wlantest/sta.c Normal file
View file

@ -0,0 +1,48 @@
/*
* STA list
* Copyright (c) 2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* See README and COPYING for more details.
*/
#include "utils/includes.h"
#include "utils/common.h"
#include "wlantest.h"
struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr)
{
struct wlantest_sta *sta;
if (addr[0] & 0x01)
return NULL; /* Skip group addressed frames */
dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) {
if (os_memcmp(sta->addr, addr, ETH_ALEN) == 0)
return sta;
}
sta = os_zalloc(sizeof(*sta));
if (sta == NULL)
return NULL;
os_memcpy(sta->addr, addr, ETH_ALEN);
dl_list_add(&bss->sta, &sta->list);
wpa_printf(MSG_DEBUG, "Discovered new STA " MACSTR " in BSS " MACSTR,
MAC2STR(sta->addr), MAC2STR(bss->bssid));
return sta;
}
void sta_deinit(struct wlantest_sta *sta)
{
dl_list_del(&sta->list);
os_free(sta);
}

View file

@ -18,6 +18,11 @@
#include "utils/list.h"
struct wlantest_sta {
struct dl_list list;
u8 addr[ETH_ALEN];
};
struct wlantest_bss {
struct dl_list list;
u8 bssid[ETH_ALEN];
@ -28,6 +33,7 @@ struct wlantest_bss {
int parse_error_reported;
u8 wpaie[257];
u8 rsnie[257];
struct dl_list sta; /* struct wlantest_sta */
};
struct wlantest {
@ -50,4 +56,7 @@ void monitor_deinit(struct wlantest *wt);
struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid);
void bss_deinit(struct wlantest_bss *bss);
struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr);
void sta_deinit(struct wlantest_sta *sta);
#endif /* WLANTEST_H */