]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
cli: Add list_sta command
authorMikael Kanstrup <mikael.kanstrup@sonymobile.com>
Wed, 12 Oct 2016 12:18:59 +0000 (14:18 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 16 Oct 2016 09:28:02 +0000 (12:28 +0300)
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>
hostapd/hostapd_cli.c
wpa_supplicant/wpa_cli.c

index e5670104678dd02231ef6c0aac62eeaee5ff2103..88a5ee14b529dff228cc835e9e3e35862b160408 100644 (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[])
 {
        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" },
        { "all_sta", hostapd_cli_cmd_all_sta, NULL,
           "= 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,
          "<addr> = add a new station" },
        { "deauthenticate", hostapd_cli_cmd_deauthenticate,
index a848b7737db51d32759513cd6e0b5e9ef96947fb..5ec22d1e249c70772908bc0fe963ea116c897cb9 100644 (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,
-                               char *addr, size_t addr_len)
+                               char *addr, size_t addr_len, int print)
 {
        char buf[4096], *pos;
        size_t len;
@@ -1767,7 +1767,8 @@ static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, char *cmd,
        buf[len] = '\0';
        if (os_memcmp(buf, "FAIL", 4) == 0)
                return -1;
-       printf("%s", buf);
+       if (print)
+               printf("%s", buf);
 
        pos = buf;
        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];
 
-       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;
        do {
                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;
 }
 
 
+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,
                                      char *argv[])
 {
@@ -3035,6 +3053,9 @@ static const struct wpa_cli_cmd wpa_cli_commands[] = {
        { "all_sta", wpa_cli_cmd_all_sta, NULL,
          cli_cmd_flag_none,
          "= 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,
          cli_cmd_flag_none,
          "<addr> = deauthenticate a station" },