diff --git a/wlantest/Makefile b/wlantest/Makefile index 983b330e1..cdd00a5bf 100644 --- a/wlantest/Makefile +++ b/wlantest/Makefile @@ -46,6 +46,7 @@ OBJS += readpcap.o OBJS += monitor.o OBJS += process.o OBJS += bss.o +OBJS += sta.o OBJS += crc32.o LIBS += -lpcap diff --git a/wlantest/bss.c b/wlantest/bss.c index 11b9248c7..70eb888fe 100644 --- a/wlantest/bss.c +++ b/wlantest/bss.c @@ -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); } diff --git a/wlantest/process.c b/wlantest/process.c index 448317e84..d47b43403 100644 --- a/wlantest/process.c +++ b/wlantest/process.c @@ -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; } } diff --git a/wlantest/sta.c b/wlantest/sta.c new file mode 100644 index 000000000..fc84ee1d0 --- /dev/null +++ b/wlantest/sta.c @@ -0,0 +1,48 @@ +/* + * STA list + * Copyright (c) 2010, Jouni Malinen + * + * 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); +} diff --git a/wlantest/wlantest.h b/wlantest/wlantest.h index a6ad4eb19..e65ca522d 100644 --- a/wlantest/wlantest.h +++ b/wlantest/wlantest.h @@ -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 */