@@ -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);
}
@@ -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
@@ -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);
@@ -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);
@@ -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;
@@ -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;
@@ -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();
@@ -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