From patchwork Thu Aug 2 11:01:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz.Dziedzic@tieto.com X-Patchwork-Id: 174731 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id E78AB2C00A0 for ; Thu, 2 Aug 2012 21:05:54 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 97FD917C010; Thu, 2 Aug 2012 07:05:52 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sPjxjFUM9HHz; Thu, 2 Aug 2012 07:05:52 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 0AB739D24A; Thu, 2 Aug 2012 07:05:32 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id EF20F9D24A for ; Thu, 2 Aug 2012 07:05:30 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id w8yQSJprvBit for ; Thu, 2 Aug 2012 07:05:25 -0400 (EDT) Received: from ebb05.tieto.com (ebb05.tieto.com [131.207.168.36]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "ebb05.tieto.com", Issuer "VeriSign Class 3 Secure Server CA - G3" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id CC8F217C012 for ; Thu, 2 Aug 2012 07:04:55 -0400 (EDT) X-AuditID: 83cfa824-b7c81ae000000a96-13-501a5ed77713 Received: from FIVLA-EXHUB02.eu.tieto.com ( [131.207.136.42]) by ebb05.tieto.com (SMTP Mailer) with SMTP id 62.B7.02710.7DE5A105; Thu, 2 Aug 2012 14:04:55 +0300 (EEST) Received: from EXMB01.eu.tieto.com ([169.254.1.121]) by FIVLA-EXHUB02.eu.tieto.com ([131.207.136.42]) with mapi; Thu, 2 Aug 2012 14:04:55 +0300 From: To: Date: Thu, 2 Aug 2012 14:01:41 +0300 Subject: [RFC 4/4] wpa_cli: print nice prompt when remote udp Thread-Topic: [RFC 4/4] wpa_cli: print nice prompt when remote udp Thread-Index: Ac1wnjJ9iylKpiDyQpW3IEQ86r0t5g== Message-ID: <3078A9B976EF864C8DDD0C499FFD07912150C655E7@EXMB01.eu.tieto.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 X-Brightmail-Tracker: AAAAAA== Cc: j@w1.fi X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com When CONFIG_CTRL_IFACE=udp-remote is used print user frendly PS in wpa_cli. eg. localhost/wlan0> 192.168.1.1/p2p-wlan-0-0> Signed-hostap: Janusz Dziedzic --- src/common/wpa_ctrl.c | 19 +++++++++++++++++++ src/common/wpa_ctrl.h | 2 ++ src/utils/edit.c | 2 +- src/utils/edit.h | 2 +- src/utils/edit_readline.c | 2 +- src/utils/edit_simple.c | 12 ++++++++---- wlantest/wlantest_cli.c | 2 +- wpa_supplicant/wpa_cli.c | 11 ++++++++--- 8 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/common/wpa_ctrl.c b/src/common/wpa_ctrl.c index fe07c02..bba42c1 100644 --- a/src/common/wpa_ctrl.c +++ b/src/common/wpa_ctrl.c @@ -47,6 +47,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; @@ -282,10 +284,12 @@ struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path) printf("UDP remote host: %s, port: %d\n", name, port_id); h = gethostbyname(name); + ctrl->remote_ip = strdup(name); free(name); if (h == NULL) { perror("gethostbyname"); close(ctrl->s); + free(ctrl->remote_ip); os_free(ctrl); return NULL; } @@ -308,14 +312,29 @@ 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 0f306dd..e69a425 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/src/utils/edit.c b/src/utils/edit.c index 280d244..4ccef21 100644 --- a/src/utils/edit.c +++ b/src/utils/edit.c @@ -1112,7 +1112,7 @@ static void edit_read_char(int sock, void *eloop_ctx, void *sock_ctx) int edit_init(void (*cmd_cb)(void *ctx, char *cmd), void (*eof_cb)(void *ctx), char ** (*completion_cb)(void *ctx, const char *cmd, int pos), - void *ctx, const char *history_file) + void *ctx, const char *history_file, const char *ps) { currbuf[0] = '\0'; dl_list_init(&history_list); diff --git a/src/utils/edit.h b/src/utils/edit.h index e8d04e7..ad27f1c 100644 --- a/src/utils/edit.h +++ b/src/utils/edit.h @@ -12,7 +12,7 @@ int edit_init(void (*cmd_cb)(void *ctx, char *cmd), void (*eof_cb)(void *ctx), char ** (*completion_cb)(void *ctx, const char *cmd, int pos), - void *ctx, const char *history_file); + void *ctx, const char *history_file, const char *ps); void edit_deinit(const char *history_file, int (*filter_cb)(void *ctx, const char *cmd)); void edit_clear_line(void); diff --git a/src/utils/edit_readline.c b/src/utils/edit_readline.c index c9ff0e6..9c27d72 100644 --- a/src/utils/edit_readline.c +++ b/src/utils/edit_readline.c @@ -112,7 +112,7 @@ static void readline_cmd_handler(char *cmd) int edit_init(void (*cmd_cb)(void *ctx, char *cmd), void (*eof_cb)(void *ctx), char ** (*completion_cb)(void *ctx, const char *cmd, int pos), - void *ctx, const char *history_file) + void *ctx, const char *history_file, const char *ps) { edit_cb_ctx = ctx; edit_cmd_cb = cmd_cb; diff --git a/src/utils/edit_simple.c b/src/utils/edit_simple.c index 0e3637c..740d346 100644 --- a/src/utils/edit_simple.c +++ b/src/utils/edit_simple.c @@ -22,6 +22,7 @@ static void (*edit_cmd_cb)(void *ctx, char *cmd); static void (*edit_eof_cb)(void *ctx); +static const char *ps2 = NULL; static void edit_read_char(int sock, void *eloop_ctx, void *sock_ctx) { int c; @@ -41,7 +42,7 @@ static void edit_read_char(int sock, void *eloop_ctx, void *sock_ctx) cmdbuf[cmdbuf_pos] = '\0'; cmdbuf_pos = 0; edit_cmd_cb(edit_cb_ctx, cmdbuf); - printf("> "); + printf("%s> ", ps2); fflush(stdout); return; } @@ -53,18 +54,21 @@ static void edit_read_char(int sock, void *eloop_ctx, void *sock_ctx) } } - int edit_init(void (*cmd_cb)(void *ctx, char *cmd), void (*eof_cb)(void *ctx), char ** (*completion_cb)(void *ctx, const char *cmd, int pos), - void *ctx, const char *history_file) + void *ctx, const char *history_file, const char *ps) { edit_cb_ctx = ctx; edit_cmd_cb = cmd_cb; edit_eof_cb = eof_cb; eloop_register_read_sock(STDIN_FILENO, edit_read_char, NULL, NULL); + if (ps) + ps2 = ps; + else + ps2 = ""; - printf("> "); + printf("%s> ", ps2); fflush(stdout); return 0; diff --git a/wlantest/wlantest_cli.c b/wlantest/wlantest_cli.c index ce95081..a417b3c 100644 --- a/wlantest/wlantest_cli.c +++ b/wlantest/wlantest_cli.c @@ -1663,7 +1663,7 @@ static void wlantest_cli_interactive(int s) cli.s = s; eloop_register_signal_terminate(wlantest_cli_eloop_terminate, &cli); edit_init(wlantest_cli_edit_cmd_cb, wlantest_cli_edit_eof_cb, - wlantest_cli_edit_completion_cb, &cli, hfile); + wlantest_cli_edit_completion_cb, &cli, hfile, NULL); eloop_run(); diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index 7a06f09..fe3b7eb 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -82,6 +82,7 @@ static const char *action_file = NULL; static int ping_interval = 5; static int interactive = 0; + struct cli_txt_entry { struct dl_list list; char *txt; @@ -3801,7 +3802,7 @@ static void wpa_cli_edit_eof_cb(void *ctx) } -static void wpa_cli_interactive(void) +static void wpa_cli_interactive(const char *ps) { char *home, *hfile = NULL; @@ -3818,7 +3819,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); + wpa_cli_edit_completion_cb, NULL, hfile, ps); eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL); eloop_run(); @@ -4076,7 +4077,11 @@ int main(int argc, char *argv[]) return -1; if (interactive) - wpa_cli_interactive(); +#ifdef CONFIG_CTRL_IFACE_UDP_REMOTE + wpa_cli_interactive(wpa_ctrl_get_remote_ifname(ctrl_conn)); +#else + wpa_cli_interactive(NULL); +#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */ else if (action_file) wpa_cli_action(ctrl_conn); else