From 4307bb8c850bbec350f51978d4442ae320079b2e Mon Sep 17 00:00:00 2001 From: Janusz Dziedzic Date: Sun, 5 Aug 2012 20:50:17 +0300 Subject: [PATCH] wpa_cli: Print nice prompt when using remote UDP When CONFIG_CTRL_IFACE=udp-remote is used, print user frendly PS in wpa_cli. E.g., localhost/wlan0> 192.168.1.1/p2p-wlan-0-0> Signed-hostap: Janusz Dziedzic --- src/common/wpa_ctrl.c | 25 ++++++++++++++++++++++++- src/common/wpa_ctrl.h | 2 ++ wpa_supplicant/wpa_cli.c | 3 ++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/common/wpa_ctrl.c b/src/common/wpa_ctrl.c index 9b67278ba..58cbe6a0d 100644 --- a/src/common/wpa_ctrl.c +++ b/src/common/wpa_ctrl.c @@ -49,6 +49,8 @@ struct wpa_ctrl { struct sockaddr_in local; struct sockaddr_in dest; char *cookie; + char *remote_ifname; + char *remote_ip; #endif /* CONFIG_CTRL_IFACE_UDP */ #ifdef CONFIG_CTRL_IFACE_UNIX int s; @@ -302,23 +304,27 @@ struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path) port_id = WPA_CTRL_IFACE_PORT; h = gethostbyname(name); + ctrl->remote_ip = os_strdup(name); os_free(name); if (h == NULL) { perror("gethostbyname"); close(ctrl->s); + os_free(ctrl->remote_ip); os_free(ctrl); return NULL; } ctrl->dest.sin_port = htons(port_id); os_memcpy(h->h_addr, (char *) &ctrl->dest.sin_addr.s_addr, h->h_length); - } + } else + ctrl->remote_ip = os_strdup("localhost"); #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */ if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest, sizeof(ctrl->dest)) < 0) { perror("connect"); close(ctrl->s); + os_free(ctrl->remote_ip); os_free(ctrl); return NULL; } @@ -329,14 +335,31 @@ struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path) ctrl->cookie = os_strdup(buf); } + if (wpa_ctrl_request(ctrl, "IFNAME", 6, buf, &len, NULL) == 0) { + buf[len] = '\0'; + ctrl->remote_ifname = os_strdup(buf); + } + return ctrl; } +char * wpa_ctrl_get_remote_ifname(struct wpa_ctrl *ctrl) +{ +#define WPA_CTRL_MAX_PS_NAME 100 + static char ps[WPA_CTRL_MAX_PS_NAME] = {}; + os_snprintf(ps, WPA_CTRL_MAX_PS_NAME, "%s/%s", + ctrl->remote_ip, ctrl->remote_ifname); + return ps; +} + + void wpa_ctrl_close(struct wpa_ctrl *ctrl) { close(ctrl->s); os_free(ctrl->cookie); + os_free(ctrl->remote_ifname); + os_free(ctrl->remote_ip); os_free(ctrl); } diff --git a/src/common/wpa_ctrl.h b/src/common/wpa_ctrl.h index 27b828276..59a42563a 100644 --- a/src/common/wpa_ctrl.h +++ b/src/common/wpa_ctrl.h @@ -286,6 +286,8 @@ int wpa_ctrl_pending(struct wpa_ctrl *ctrl); */ int wpa_ctrl_get_fd(struct wpa_ctrl *ctrl); +char * wpa_ctrl_get_remote_ifname(struct wpa_ctrl *ctrl); + #ifdef ANDROID /** * wpa_ctrl_cleanup() - Delete any local UNIX domain socket files that diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index 21f473f89..b220443be 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -3806,6 +3806,7 @@ static void wpa_cli_edit_eof_cb(void *ctx) static void wpa_cli_interactive(void) { char *home, *hfile = NULL; + const char *ps = wpa_ctrl_get_remote_ifname(ctrl_conn); printf("\nInteractive mode\n\n"); @@ -3820,7 +3821,7 @@ static void wpa_cli_interactive(void) eloop_register_signal_terminate(wpa_cli_eloop_terminate, NULL); edit_init(wpa_cli_edit_cmd_cb, wpa_cli_edit_eof_cb, - wpa_cli_edit_completion_cb, NULL, hfile, NULL); + wpa_cli_edit_completion_cb, NULL, hfile, ps); eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL); eloop_run();