cli: Add list_sta command

Add list_sta command to print addresses of all stations. Command
added to both wpa_cli and hostapd_cli.

Signed-off-by: Mikael Kanstrup <mikael.kanstrup@sonymobile.com>
This commit is contained in:
Mikael Kanstrup 2016-10-12 14:18:59 +02:00 committed by Jouni Malinen
parent 85bab32522
commit 4c43f44b29
2 changed files with 44 additions and 4 deletions

View file

@ -802,6 +802,23 @@ static int hostapd_cli_cmd_all_sta(struct wpa_ctrl *ctrl, int argc,
} }
static int hostapd_cli_cmd_list_sta(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char addr[32], cmd[64];
if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 0))
return 0;
do {
if (os_strcmp(addr, "") != 0)
printf("%s\n", addr);
os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
} while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 0) == 0);
return 0;
}
static int hostapd_cli_cmd_help(struct wpa_ctrl *ctrl, int argc, char *argv[]) static int hostapd_cli_cmd_help(struct wpa_ctrl *ctrl, int argc, char *argv[])
{ {
print_help(stdout, argc > 0 ? argv[0] : NULL); print_help(stdout, argc > 0 ? argv[0] : NULL);
@ -1332,6 +1349,8 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
"<addr> = get MIB variables for one station" }, "<addr> = get MIB variables for one station" },
{ "all_sta", hostapd_cli_cmd_all_sta, NULL, { "all_sta", hostapd_cli_cmd_all_sta, NULL,
"= get MIB variables for all stations" }, "= get MIB variables for all stations" },
{ "list_sta", hostapd_cli_cmd_list_sta, NULL,
"= list all stations" },
{ "new_sta", hostapd_cli_cmd_new_sta, NULL, { "new_sta", hostapd_cli_cmd_new_sta, NULL,
"<addr> = add a new station" }, "<addr> = add a new station" },
{ "deauthenticate", hostapd_cli_cmd_deauthenticate, { "deauthenticate", hostapd_cli_cmd_deauthenticate,

View file

@ -1737,7 +1737,7 @@ static int wpa_cli_cmd_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, char *cmd, static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, char *cmd,
char *addr, size_t addr_len) char *addr, size_t addr_len, int print)
{ {
char buf[4096], *pos; char buf[4096], *pos;
size_t len; size_t len;
@ -1767,7 +1767,8 @@ static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, char *cmd,
buf[len] = '\0'; buf[len] = '\0';
if (os_memcmp(buf, "FAIL", 4) == 0) if (os_memcmp(buf, "FAIL", 4) == 0)
return -1; return -1;
printf("%s", buf); if (print)
printf("%s", buf);
pos = buf; pos = buf;
while (*pos != '\0' && *pos != '\n') while (*pos != '\0' && *pos != '\n')
@ -1782,16 +1783,33 @@ static int wpa_cli_cmd_all_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
{ {
char addr[32], cmd[64]; char addr[32], cmd[64];
if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr))) if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 1))
return 0; return 0;
do { do {
os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr); os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
} while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr)) == 0); } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 1) == 0);
return -1; return -1;
} }
static int wpa_cli_cmd_list_sta(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char addr[32], cmd[64];
if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 0))
return 0;
do {
if (os_strcmp(addr, "") != 0)
printf("%s\n", addr);
os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
} while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 0) == 0);
return 0;
}
static int wpa_cli_cmd_deauthenticate(struct wpa_ctrl *ctrl, int argc, static int wpa_cli_cmd_deauthenticate(struct wpa_ctrl *ctrl, int argc,
char *argv[]) char *argv[])
{ {
@ -3035,6 +3053,9 @@ static const struct wpa_cli_cmd wpa_cli_commands[] = {
{ "all_sta", wpa_cli_cmd_all_sta, NULL, { "all_sta", wpa_cli_cmd_all_sta, NULL,
cli_cmd_flag_none, cli_cmd_flag_none,
"= get information about all associated stations (AP)" }, "= get information about all associated stations (AP)" },
{ "list_sta", wpa_cli_cmd_list_sta, NULL,
cli_cmd_flag_none,
"= list all stations (AP)" },
{ "deauthenticate", wpa_cli_cmd_deauthenticate, NULL, { "deauthenticate", wpa_cli_cmd_deauthenticate, NULL,
cli_cmd_flag_none, cli_cmd_flag_none,
"<addr> = deauthenticate a station" }, "<addr> = deauthenticate a station" },