]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wpa_cli: Add all_bss command to print all scan results (BSS entries)
authorPurushottam Kushwaha <pkushwah@codeaurora.org>
Thu, 28 May 2020 06:37:37 +0000 (12:07 +0530)
committerJouni Malinen <j@w1.fi>
Sat, 6 Jun 2020 14:07:24 +0000 (17:07 +0300)
The wpa_supplicant control interface returns maximum of 4 kB of response
data and, thus, limits maximum number of scan entries as part of
SCAN_RESULTS to approximately 60. Add a new all_bss command to use a
more robust iteration of the BSS table entries with the BSS command to
to get all scan entries and print them in the same format as the
scan_results command.

Signed-off-by: Purushottam Kushwaha <pkushwah@codeaurora.org>
wpa_supplicant/wpa_cli.c

index 6a2d2c3d65e742601b883d4db1de54eef4f6b1fb..f5b02f662274b4dcdcf000377fe93546c66bdfa7 100644 (file)
@@ -3059,6 +3059,78 @@ static int wpa_cli_cmd_dpp_pkex_remove(struct wpa_ctrl *ctrl, int argc,
 #endif /* CONFIG_DPP */
 
 
+static int wpa_ctrl_command_bss(struct wpa_ctrl *ctrl, const char *cmd)
+{
+       char buf[512], *pos, *bssid, *freq, *level, *flags, *ssid;
+       size_t len;
+       int ret, id = -1;
+
+       if (!ctrl_conn)
+               return -1;
+       len = sizeof(buf) - 1;
+       ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
+                              wpa_cli_msg_cb);
+       if (ret == -2) {
+               printf("'%s' command timed out.\n", cmd);
+               return -2;
+       } else if (ret < 0) {
+               printf("'%s' command failed.\n", cmd);
+               return -1;
+       }
+
+       buf[len] = '\0';
+       if (os_memcmp(buf, "FAIL", 4) == 0)
+               return -1;
+
+       pos = buf;
+       while (*pos != '\0') {
+               if (str_starts(pos, "id="))
+                       id = atoi(pos + 3);
+               if (str_starts(pos, "bssid="))
+                       bssid = pos + 6;
+               if (str_starts(pos, "freq="))
+                       freq = pos + 5;
+               if (str_starts(pos, "level="))
+                       level = pos + 6;
+               if (str_starts(pos, "flags="))
+                       flags = pos + 6;
+               if (str_starts(pos, "ssid="))
+                       ssid = pos + 5;
+
+               while (*pos != '\0' && *pos != '\n')
+                       pos++;
+               *pos++ = '\0';
+       }
+       if (id != -1)
+               printf("%s\t%s\t%s\t%s\t%s\n", bssid, freq, level, flags, ssid);
+       return id;
+}
+
+
+static int wpa_cli_cmd_all_bss(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+       char cmd[64];
+       int id = -1;
+       unsigned int mask;
+
+       printf("bssid / frequency / signal level / flags / ssid\n");
+
+       mask = WPA_BSS_MASK_ID | WPA_BSS_MASK_BSSID | WPA_BSS_MASK_FREQ |
+               WPA_BSS_MASK_LEVEL | WPA_BSS_MASK_FLAGS | WPA_BSS_MASK_SSID;
+       do {
+               if (id < 0)
+                       os_snprintf(cmd, sizeof(cmd), "BSS FIRST MASK=0x%x",
+                                   mask);
+               else
+                       os_snprintf(cmd, sizeof(cmd), "BSS NEXT-%d MASK=0x%x",
+                                   id, mask);
+               id = wpa_ctrl_command_bss(ctrl, cmd);
+       } while (id >= 0);
+
+       return 0;
+}
+
+
 enum wpa_cli_cmd_flags {
        cli_cmd_flag_none               = 0x00,
        cli_cmd_flag_sensitive          = 0x01
@@ -3718,6 +3790,8 @@ static const struct wpa_cli_cmd wpa_cli_commands[] = {
          cli_cmd_flag_none,
          "*|<id> = remove DPP pkex information" },
 #endif /* CONFIG_DPP */
+       { "all_bss", wpa_cli_cmd_all_bss, NULL, cli_cmd_flag_none,
+         "= list all BSS entries (scan results)" },
        { NULL, NULL, NULL, cli_cmd_flag_none, NULL }
 };