]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wpa_cli: Allow reconnect to global interface
authorBen Greear <greearb@candelatech.com>
Thu, 8 Jun 2017 17:58:54 +0000 (10:58 -0700)
committerJouni Malinen <j@w1.fi>
Mon, 31 Dec 2018 10:32:14 +0000 (12:32 +0200)
Old code would just re-connect to a particular interface, even if user
had started wpa_cli with the '-g' option. Refactor global control
interface connection routine to allow it to be used in
wpa_cli_reconnect().

Signed-off-by: Ben Greear <greearb@candelatech.com>
wpa_supplicant/wpa_cli.c

index 983a1498754d5d59809b0743813676fcc3111aa0..bd7360df96aa90549bee3681a698d612431c5246 100644 (file)
@@ -49,6 +49,7 @@ static int wpa_cli_last_id = 0;
 static const char *ctrl_iface_dir = CONFIG_CTRL_IFACE_DIR;
 static const char *client_socket_dir = NULL;
 static char *ctrl_ifname = NULL;
+static const char *global = NULL;
 static const char *pid_file = NULL;
 static const char *action_file = NULL;
 static int ping_interval = 5;
@@ -74,6 +75,7 @@ static char ** wpa_list_cmd_list(void);
 static void update_creds(struct wpa_ctrl *ctrl);
 static void update_networks(struct wpa_ctrl *ctrl);
 static void update_stations(struct wpa_ctrl *ctrl);
+static void update_ifnames(struct wpa_ctrl *ctrl);
 
 
 static void usage(void)
@@ -3984,10 +3986,46 @@ static void wpa_cli_action_cb(char *msg, size_t len)
 #endif /* CONFIG_ANSI_C_EXTRA */
 
 
+static int wpa_cli_open_global_ctrl(void)
+{
+#ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
+       ctrl_conn = wpa_ctrl_open(NULL);
+#else /* CONFIG_CTRL_IFACE_NAMED_PIPE */
+       ctrl_conn = wpa_ctrl_open(global);
+#endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
+       if (!ctrl_conn) {
+               fprintf(stderr,
+                       "Failed to connect to wpa_supplicant global interface: %s  error: %s\n",
+                       global, strerror(errno));
+               return -1;
+       }
+
+       if (interactive) {
+               update_ifnames(ctrl_conn);
+               mon_conn = wpa_ctrl_open(global);
+               if (mon_conn) {
+                       if (wpa_ctrl_attach(mon_conn) == 0) {
+                               wpa_cli_attached = 1;
+                               eloop_register_read_sock(
+                                       wpa_ctrl_get_fd(mon_conn),
+                                       wpa_cli_mon_receive,
+                                       NULL, NULL);
+                       } else {
+                               printf("Failed to open monitor connection through global control interface\n");
+                       }
+               }
+               update_stations(ctrl_conn);
+       }
+
+       return 0;
+}
+
+
 static void wpa_cli_reconnect(void)
 {
        wpa_cli_close_connection();
-       if (wpa_cli_open_connection(ctrl_ifname, 1) < 0)
+       if ((global && wpa_cli_open_global_ctrl() < 0) ||
+           (!global && wpa_cli_open_connection(ctrl_ifname, 1) < 0))
                return;
 
        if (interactive) {
@@ -4546,7 +4584,6 @@ int main(int argc, char *argv[])
        int c;
        int daemonize = 0;
        int ret = 0;
-       const char *global = NULL;
 
        if (os_program_init())
                return -1;
@@ -4601,38 +4638,8 @@ int main(int argc, char *argv[])
        if (eloop_init())
                return -1;
 
-       if (global) {
-#ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
-               ctrl_conn = wpa_ctrl_open(NULL);
-#else /* CONFIG_CTRL_IFACE_NAMED_PIPE */
-               ctrl_conn = wpa_ctrl_open(global);
-#endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
-               if (ctrl_conn == NULL) {
-                       fprintf(stderr, "Failed to connect to wpa_supplicant "
-                               "global interface: %s  error: %s\n",
-                               global, strerror(errno));
-                       return -1;
-               }
-
-               if (interactive) {
-                       update_ifnames(ctrl_conn);
-                       mon_conn = wpa_ctrl_open(global);
-                       if (mon_conn) {
-                               if (wpa_ctrl_attach(mon_conn) == 0) {
-                                       wpa_cli_attached = 1;
-                                       eloop_register_read_sock(
-                                               wpa_ctrl_get_fd(mon_conn),
-                                               wpa_cli_mon_receive,
-                                               NULL, NULL);
-                               } else {
-                                       printf("Failed to open monitor "
-                                              "connection through global "
-                                              "control interface\n");
-                               }
-                       }
-                       update_stations(ctrl_conn);
-               }
-       }
+       if (global && wpa_cli_open_global_ctrl() < 0)
+               return -1;
 
        eloop_register_signal_terminate(wpa_cli_terminate, NULL);