wpa_cli: Allow reconnect to global interface

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>
This commit is contained in:
Ben Greear 2017-06-08 10:58:54 -07:00 committed by Jouni Malinen
parent 4fb6963b39
commit 3518e3623f

View 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 *ctrl_iface_dir = CONFIG_CTRL_IFACE_DIR;
static const char *client_socket_dir = NULL; static const char *client_socket_dir = NULL;
static char *ctrl_ifname = NULL; static char *ctrl_ifname = NULL;
static const char *global = NULL;
static const char *pid_file = NULL; static const char *pid_file = NULL;
static const char *action_file = NULL; static const char *action_file = NULL;
static int ping_interval = 5; 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_creds(struct wpa_ctrl *ctrl);
static void update_networks(struct wpa_ctrl *ctrl); static void update_networks(struct wpa_ctrl *ctrl);
static void update_stations(struct wpa_ctrl *ctrl); static void update_stations(struct wpa_ctrl *ctrl);
static void update_ifnames(struct wpa_ctrl *ctrl);
static void usage(void) static void usage(void)
@ -3984,10 +3986,46 @@ static void wpa_cli_action_cb(char *msg, size_t len)
#endif /* CONFIG_ANSI_C_EXTRA */ #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) static void wpa_cli_reconnect(void)
{ {
wpa_cli_close_connection(); 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; return;
if (interactive) { if (interactive) {
@ -4546,7 +4584,6 @@ int main(int argc, char *argv[])
int c; int c;
int daemonize = 0; int daemonize = 0;
int ret = 0; int ret = 0;
const char *global = NULL;
if (os_program_init()) if (os_program_init())
return -1; return -1;
@ -4601,38 +4638,8 @@ int main(int argc, char *argv[])
if (eloop_init()) if (eloop_init())
return -1; return -1;
if (global) { if (global && wpa_cli_open_global_ctrl() < 0)
#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; 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);
}
}
eloop_register_signal_terminate(wpa_cli_terminate, NULL); eloop_register_signal_terminate(wpa_cli_terminate, NULL);