diff --git a/wlantest/bss.c b/wlantest/bss.c index 20e4f207b..b3a744153 100644 --- a/wlantest/bss.c +++ b/wlantest/bss.c @@ -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) diff --git a/wlantest/ctrl.c b/wlantest/ctrl.c index 156b0000f..ac6efe911 100644 --- a/wlantest/ctrl.c +++ b/wlantest/ctrl.c @@ -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"); diff --git a/wlantest/sta.c b/wlantest/sta.c index f264d36ee..bec494dab 100644 --- a/wlantest/sta.c +++ b/wlantest/sta.c @@ -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) diff --git a/wlantest/wlantest.h b/wlantest/wlantest.h index 9f91b754a..0cbc53239 100644 --- a/wlantest/wlantest.h +++ b/wlantest/wlantest.h @@ -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,