wlantest: Do not add new BSS/STA entries based on ctrl commands

Introduce bss_find()/sta_find() as an alternative bss_get()/sta_get()
command that do not allocate new BSS/STA entry if no existing entry
is found.
This commit is contained in:
Jouni Malinen 2010-11-19 22:00:10 +02:00
parent fbdd21327e
commit 57f7d03f91
4 changed files with 43 additions and 17 deletions

View file

@ -21,6 +21,19 @@
#include "wlantest.h"
struct wlantest_bss * bss_find(struct wlantest *wt, const u8 *bssid)
{
struct wlantest_bss *bss;
dl_list_for_each(bss, &wt->bss, struct wlantest_bss, list) {
if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
return bss;
}
return NULL;
}
struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid)
{
struct wlantest_bss *bss;
@ -28,10 +41,9 @@ struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid)
if (bssid[0] & 0x01)
return NULL; /* Skip group addressed frames */
dl_list_for_each(bss, &wt->bss, struct wlantest_bss, list) {
if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
return bss;
}
bss = bss_find(wt, bssid);
if (bss)
return bss;
bss = os_zalloc(sizeof(*bss));
if (bss == NULL)

View file

@ -180,7 +180,7 @@ static void ctrl_list_sta(struct wlantest *wt, int sock, u8 *cmd, size_t clen)
return;
}
bss = bss_get(wt, bssid);
bss = bss_find(wt, bssid);
if (bss == NULL) {
ctrl_send_simple(wt, sock, WLANTEST_CTRL_FAILURE);
return;
@ -228,7 +228,7 @@ static void ctrl_clear_sta_counters(struct wlantest *wt, int sock, u8 *cmd,
return;
}
bss = bss_get(wt, addr);
bss = bss_find(wt, addr);
if (bss == NULL) {
ctrl_send_simple(wt, sock, WLANTEST_CTRL_FAILURE);
return;
@ -240,7 +240,7 @@ static void ctrl_clear_sta_counters(struct wlantest *wt, int sock, u8 *cmd,
return;
}
sta = sta_get(bss, addr);
sta = sta_find(bss, addr);
if (sta == NULL) {
ctrl_send_simple(wt, sock, WLANTEST_CTRL_FAILURE);
return;
@ -264,7 +264,7 @@ static void ctrl_clear_bss_counters(struct wlantest *wt, int sock, u8 *cmd,
return;
}
bss = bss_get(wt, addr);
bss = bss_find(wt, addr);
if (bss == NULL) {
ctrl_send_simple(wt, sock, WLANTEST_CTRL_FAILURE);
return;
@ -291,7 +291,7 @@ static void ctrl_get_sta_counter(struct wlantest *wt, int sock, u8 *cmd,
return;
}
bss = bss_get(wt, addr);
bss = bss_find(wt, addr);
if (bss == NULL) {
ctrl_send_simple(wt, sock, WLANTEST_CTRL_FAILURE);
return;
@ -303,7 +303,7 @@ static void ctrl_get_sta_counter(struct wlantest *wt, int sock, u8 *cmd,
return;
}
sta = sta_get(bss, addr);
sta = sta_find(bss, addr);
if (sta == NULL) {
ctrl_send_simple(wt, sock, WLANTEST_CTRL_FAILURE);
return;
@ -345,7 +345,7 @@ static void ctrl_get_bss_counter(struct wlantest *wt, int sock, u8 *cmd,
return;
}
bss = bss_get(wt, addr);
bss = bss_find(wt, addr);
if (bss == NULL) {
ctrl_send_simple(wt, sock, WLANTEST_CTRL_FAILURE);
return;
@ -614,7 +614,7 @@ static void ctrl_inject(struct wlantest *wt, int sock, u8 *cmd, size_t clen)
return;
}
bss = bss_get(wt, bssid);
bss = bss_find(wt, bssid);
if (bss == NULL) {
wpa_printf(MSG_INFO, "BSS not found for inject command");
ctrl_send_simple(wt, sock, WLANTEST_CTRL_FAILURE);
@ -629,7 +629,7 @@ static void ctrl_inject(struct wlantest *wt, int sock, u8 *cmd, size_t clen)
return;
} sta = NULL;
} else {
sta = sta_get(bss, sta_addr);
sta = sta_find(bss, sta_addr);
if (sta == NULL) {
wpa_printf(MSG_INFO, "Station not found for inject "
"command");

View file

@ -20,6 +20,19 @@
#include "wlantest.h"
struct wlantest_sta * sta_find(struct wlantest_bss *bss, const u8 *addr)
{
struct wlantest_sta *sta;
dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) {
if (os_memcmp(sta->addr, addr, ETH_ALEN) == 0)
return sta;
}
return NULL;
}
struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr)
{
struct wlantest_sta *sta;
@ -27,10 +40,9 @@ struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr)
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 = sta_find(bss, addr);
if (sta)
return sta;
sta = os_zalloc(sizeof(*sta));
if (sta == NULL)

View file

@ -153,6 +153,7 @@ void monitor_deinit(struct wlantest *wt);
void rx_mgmt(struct wlantest *wt, const u8 *data, size_t len);
void rx_data(struct wlantest *wt, const u8 *data, size_t len);
struct wlantest_bss * bss_find(struct wlantest *wt, const u8 *bssid);
struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid);
void bss_deinit(struct wlantest_bss *bss);
void bss_update(struct wlantest *wt, struct wlantest_bss *bss,
@ -160,6 +161,7 @@ void bss_update(struct wlantest *wt, struct wlantest_bss *bss,
void bss_flush(struct wlantest *wt);
void pmk_deinit(struct wlantest_pmk *pmk);
struct wlantest_sta * sta_find(struct wlantest_bss *bss, const u8 *addr);
struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr);
void sta_deinit(struct wlantest_sta *sta);
void sta_update_assoc(struct wlantest_sta *sta,