aboutsummaryrefslogtreecommitdiffstats
path: root/wlantest/wlantest_cli.c
diff options
context:
space:
mode:
authorJouni Malinen <jouni.malinen@atheros.com>2010-11-18 15:17:18 (GMT)
committerJouni Malinen <j@w1.fi>2010-11-18 15:17:18 (GMT)
commit6f2346c144f8f7ee8973f0db841558e339fb9b15 (patch)
treec5ef78c41344288295995315e04c1fa8df67bba4 /wlantest/wlantest_cli.c
parenta6c1810297ad59fcb2261e5192a6367de6d47cee (diff)
downloadhostap-6f2346c144f8f7ee8973f0db841558e339fb9b15.zip
hostap-6f2346c144f8f7ee8973f0db841558e339fb9b15.tar.gz
hostap-6f2346c144f8f7ee8973f0db841558e339fb9b15.tar.bz2
wlantest: Add list_bss and list_sta commands
These can be used to list the current BSS and STA information maintained in wlantest.
Diffstat (limited to 'wlantest/wlantest_cli.c')
-rw-r--r--wlantest/wlantest_cli.c138
1 files changed, 123 insertions, 15 deletions
diff --git a/wlantest/wlantest_cli.c b/wlantest/wlantest_cli.c
index 024626c..7ba5ff1 100644
--- a/wlantest/wlantest_cli.c
+++ b/wlantest/wlantest_cli.c
@@ -19,34 +19,74 @@
#include "wlantest_ctrl.h"
-static int cmd_simple(int s, enum wlantest_ctrl_cmd cmd)
+static u8 * attr_get(u8 *buf, size_t buflen, enum wlantest_ctrl_attr attr,
+ size_t *len)
+{
+ u8 *pos = buf;
+
+ while (pos + 8 <= buf + buflen) {
+ enum wlantest_ctrl_attr a;
+ size_t alen;
+ a = WPA_GET_BE32(pos);
+ pos += 4;
+ alen = WPA_GET_BE32(pos);
+ pos += 4;
+ if (pos + alen > buf + buflen) {
+ printf("Invalid control message attribute\n");
+ return NULL;
+ }
+ if (a == attr) {
+ *len = alen;
+ return pos;
+ }
+ pos += alen;
+ }
+
+ return NULL;
+}
+
+
+static int cmd_send_and_recv(int s, const u8 *cmd, size_t cmd_len,
+ u8 *resp, size_t max_resp_len)
{
- char buf[4];
int res;
- enum wlantest_ctrl_cmd resp;
+ enum wlantest_ctrl_cmd cmd_resp;
- WPA_PUT_BE32(buf, cmd);
- if (send(s, buf, 4, 0) < 0)
+ if (send(s, cmd, cmd_len, 0) < 0)
return -1;
- res = recv(s, buf, sizeof(buf), 0);
+ res = recv(s, resp, max_resp_len, 0);
if (res < 4)
return -1;
- resp = WPA_GET_BE32(buf);
- if (resp == WLANTEST_CTRL_SUCCESS)
- printf("OK\n");
- else if (resp == WLANTEST_CTRL_FAILURE)
- printf("FAIL\n");
- else if (resp == WLANTEST_CTRL_UNKNOWN_CMD)
+ cmd_resp = WPA_GET_BE32(resp);
+ if (cmd_resp == WLANTEST_CTRL_SUCCESS)
+ return res;
+
+ if (cmd_resp == WLANTEST_CTRL_UNKNOWN_CMD)
printf("Unknown command\n");
+ else if (cmd_resp == WLANTEST_CTRL_INVALID_CMD)
+ printf("Invalid command\n");
- return resp == WLANTEST_CTRL_SUCCESS ? 0 : -1;
+ return -1;
+}
+
+
+static int cmd_simple(int s, enum wlantest_ctrl_cmd cmd)
+{
+ u8 buf[4];
+ int res;
+ WPA_PUT_BE32(buf, cmd);
+ res = cmd_send_and_recv(s, buf, sizeof(buf), buf, sizeof(buf));
+ return res < 0 ? -1 : 0;
}
static int cmd_ping(int s, int argc, char *argv[])
{
- return cmd_simple(s, WLANTEST_CTRL_PING) == 0;
+ int res = cmd_simple(s, WLANTEST_CTRL_PING);
+ if (res == 0)
+ printf("PONG\n");
+ return res == 0;
}
@@ -56,6 +96,73 @@ static int cmd_terminate(int s, int argc, char *argv[])
}
+static int cmd_list_bss(int s, int argc, char *argv[])
+{
+ u8 resp[WLANTEST_CTRL_MAX_RESP_LEN];
+ u8 buf[4];
+ u8 *bssid;
+ size_t len;
+ int rlen, i;
+
+ WPA_PUT_BE32(buf, WLANTEST_CTRL_LIST_BSS);
+ rlen = cmd_send_and_recv(s, buf, sizeof(buf), resp, sizeof(resp));
+ if (rlen < 0)
+ return -1;
+
+ bssid = attr_get(resp + 4, rlen - 4, WLANTEST_ATTR_BSSID, &len);
+ if (bssid == NULL)
+ return -1;
+
+ for (i = 0; i < len / ETH_ALEN; i++)
+ printf(MACSTR " ", MAC2STR(bssid + ETH_ALEN * i));
+ printf("\n");
+
+ return 0;
+}
+
+
+static int cmd_list_sta(int s, int argc, char *argv[])
+{
+ u8 resp[WLANTEST_CTRL_MAX_RESP_LEN];
+ u8 buf[100], *pos;
+ u8 *addr;
+ size_t len;
+ int rlen, i;
+
+ if (argc < 1) {
+ printf("list_sta needs one argument: BSSID\n");
+ return -1;
+ }
+
+ pos = buf;
+ WPA_PUT_BE32(pos, WLANTEST_CTRL_LIST_STA);
+ pos += 4;
+ WPA_PUT_BE32(pos, WLANTEST_ATTR_BSSID);
+ pos += 4;
+ WPA_PUT_BE32(pos, ETH_ALEN);
+ pos += 4;
+ if (hwaddr_aton(argv[0], pos) < 0) {
+ printf("Invalid BSSID '%s'\n", argv[0]);
+ return -1;
+ }
+ pos += ETH_ALEN;
+
+ rlen = cmd_send_and_recv(s, buf, pos - buf, resp, sizeof(resp));
+ if (rlen < 0)
+ return -1;
+
+ addr = attr_get(resp + 4, rlen - 4, WLANTEST_ATTR_STA_ADDR, &len);
+ if (addr == NULL)
+ return -1;
+
+ for (i = 0; i < len / ETH_ALEN; i++)
+ printf(MACSTR " ", MAC2STR(addr + ETH_ALEN * i));
+ printf("\n");
+
+ return 0;
+}
+
+
struct wlantest_cli_cmd {
const char *cmd;
int (*handler)(int s, int argc, char *argv[]);
@@ -65,6 +172,8 @@ struct wlantest_cli_cmd {
static const struct wlantest_cli_cmd wlantest_cli_commands[] = {
{ "ping", cmd_ping, "= test connection to wlantest" },
{ "terminate", cmd_terminate, "= terminate wlantest" },
+ { "list_bss", cmd_list_bss, "= get BSS list" },
+ { "list_sta", cmd_list_sta, "<BSSID> = get STA list" },
{ NULL, NULL, NULL }
};
@@ -95,7 +204,6 @@ static int ctrl_command(int s, int argc, char *argv[])
os_strlen(argv[0])) == 0) {
printf(" %s", cmd->cmd);
}
- cmd++;
}
printf("\n");
ret = 1;