]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - hostapd/hostapd_cli.c
tests: DPP netAccessKey for reconfig
[thirdparty/hostap.git] / hostapd / hostapd_cli.c
index 42edb7b25bcb4671e3039e9fcaded774ec2a41e1..440664e9b0527ec27ede99742406e547dd588daf 100644 (file)
@@ -54,7 +54,7 @@ static void usage(void)
        fprintf(stderr, "%s\n", hostapd_cli_version);
        fprintf(stderr,
                "\n"
-               "usage: hostapd_cli [-p<path>] [-i<ifname>] [-hvB] "
+               "usage: hostapd_cli [-p<path>] [-i<ifname>] [-hvBr] "
                "[-a<path>] \\\n"
                "                   [-P<pid file>] [-G<ping interval>] [command..]\n"
                "\n"
@@ -68,6 +68,9 @@ static void usage(void)
                "   -a<file>     run in daemon mode executing the action file "
                "based on events\n"
                "                from hostapd\n"
+               "   -r           try to reconnect when client socket is "
+               "disconnected.\n"
+               "                This is useful only when used with -a.\n"
                "   -B           run a daemon in the background\n"
                "   -i<ifname>   Interface to listen on (default: first "
                "interface found in the\n"
@@ -1309,24 +1312,17 @@ static int hostapd_cli_cmd_set_neighbor(struct wpa_ctrl *ctrl, int argc,
 }
 
 
-static int hostapd_cli_cmd_remove_neighbor(struct wpa_ctrl *ctrl, int argc,
-                                          char *argv[])
+static int hostapd_cli_cmd_show_neighbor(struct wpa_ctrl *ctrl, int argc,
+                                        char *argv[])
 {
-       char cmd[400];
-       int res;
+       return wpa_ctrl_command(ctrl, "SHOW_NEIGHBOR");
+}
 
-       if (argc != 2) {
-               printf("Invalid remove_neighbor command: needs 2 arguments\n");
-               return -1;
-       }
 
-       res = os_snprintf(cmd, sizeof(cmd), "REMOVE_NEIGHBOR %s %s",
-                         argv[0], argv[1]);
-       if (os_snprintf_error(sizeof(cmd), res)) {
-               printf("Too long REMOVE_NEIGHBOR command.\n");
-               return -1;
-       }
-       return wpa_ctrl_command(ctrl, cmd);
+static int hostapd_cli_cmd_remove_neighbor(struct wpa_ctrl *ctrl, int argc,
+                                          char *argv[])
+{
+       return hostapd_cli_cmd(ctrl, "REMOVE_NEIGHBOR", 1, argc, argv);
 }
 
 
@@ -1633,8 +1629,10 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
        { "set_neighbor", hostapd_cli_cmd_set_neighbor, NULL,
          "<addr> <ssid=> <nr=> [lci=] [civic=] [stat]\n"
          "  = add AP to neighbor database" },
+       { "show_neighbor", hostapd_cli_cmd_show_neighbor, NULL,
+         "  = show neighbor database entries" },
        { "remove_neighbor", hostapd_cli_cmd_remove_neighbor, NULL,
-         "<addr> <ssid=> = remove AP from neighbor database" },
+         "<addr> [ssid=<hex>] = remove AP from neighbor database" },
        { "req_lci", hostapd_cli_cmd_req_lci, hostapd_complete_stations,
          "<addr> = send LCI request to a station"},
        { "req_range", hostapd_cli_cmd_req_range, NULL,
@@ -2007,12 +2005,13 @@ int main(int argc, char *argv[])
        int warning_displayed = 0;
        int c;
        int daemonize = 0;
+       int reconnect = 0;
 
        if (os_program_init())
                return -1;
 
        for (;;) {
-               c = getopt(argc, argv, "a:BhG:i:p:P:s:v");
+               c = getopt(argc, argv, "a:BhG:i:p:P:rs:v");
                if (c < 0)
                        break;
                switch (c) {
@@ -2041,6 +2040,9 @@ int main(int argc, char *argv[])
                case 'P':
                        pid_file = optarg;
                        break;
+               case 'r':
+                       reconnect = 1;
+                       break;
                case 's':
                        client_socket_dir = optarg;
                        break;
@@ -2083,8 +2085,7 @@ int main(int argc, char *argv[])
                                printf("Connection established.\n");
                        break;
                }
-
-               if (!interactive) {
+               if (!interactive && !reconnect) {
                        perror("Failed to connect to hostapd - "
                               "wpa_ctrl_open");
                        return -1;
@@ -2102,8 +2103,14 @@ int main(int argc, char *argv[])
                return -1;
        if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue())
                return -1;
-
-       if (interactive)
+       if (reconnect && action_file && ctrl_ifname) {
+               while (!hostapd_cli_quit) {
+                       if (ctrl_conn)
+                               hostapd_cli_action(ctrl_conn);
+                       os_sleep(1, 0);
+                       hostapd_cli_reconnect(ctrl_ifname);
+               }
+       } else if (interactive)
                hostapd_cli_interactive();
        else if (action_file)
                hostapd_cli_action(ctrl_conn);