Browse Source

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.
Jouni Malinen 14 years ago
parent
commit
57f7d03f91
4 changed files with 43 additions and 17 deletions
  1. 16 4
      wlantest/bss.c
  2. 9 9
      wlantest/ctrl.c
  3. 16 4
      wlantest/sta.c
  4. 2 0
      wlantest/wlantest.h

+ 16 - 4
wlantest/bss.c

@@ -21,18 +21,30 @@
 #include "wlantest.h"
 
 
-struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid)
+struct wlantest_bss * bss_find(struct wlantest *wt, const u8 *bssid)
 {
 	struct wlantest_bss *bss;
 
-	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;
 	}
 
+	return NULL;
+}
+
+
+struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid)
+{
+	struct wlantest_bss *bss;
+
+	if (bssid[0] & 0x01)
+		return NULL; /* Skip group addressed frames */
+
+	bss = bss_find(wt, bssid);
+	if (bss)
+		return bss;
+
 	bss = os_zalloc(sizeof(*bss));
 	if (bss == NULL)
 		return NULL;

+ 9 - 9
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");

+ 16 - 4
wlantest/sta.c

@@ -20,18 +20,30 @@
 #include "wlantest.h"
 
 
-struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr)
+struct wlantest_sta * sta_find(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;
 	}
 
+	return NULL;
+}
+
+
+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 */
+
+	sta = sta_find(bss, addr);
+	if (sta)
+		return sta;
+
 	sta = os_zalloc(sizeof(*sta));
 	if (sta == NULL)
 		return NULL;

+ 2 - 0
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,