]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - build-utilities/hostap.git/blobdiff - wpa_supplicant/wpa_cli.c
Select the BSD license terms as the only license alternative
[build-utilities/hostap.git] / wpa_supplicant / wpa_cli.c
index c6d7e80f73e095e82ec1471834219ec4dcc0e4eb..cc9f6cc27aed6813a9d9ed10f8a923d4e5e0480e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * WPA Supplicant - command line interface for wpa_supplicant daemon
- * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2011, Jouni Malinen <j@w1.fi>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
 #ifdef CONFIG_CTRL_IFACE_UNIX
 #include <dirent.h>
 #endif /* CONFIG_CTRL_IFACE_UNIX */
-#ifdef CONFIG_READLINE
-#include <readline/readline.h>
-#include <readline/history.h>
-#endif /* CONFIG_READLINE */
 
 #include "common/wpa_ctrl.h"
 #include "utils/common.h"
 #include "utils/eloop.h"
 #include "utils/edit.h"
+#include "utils/list.h"
 #include "common/version.h"
+#ifdef ANDROID
+#include <cutils/properties.h>
+#endif /* ANDROID */
 
 
 static const char *wpa_cli_version =
 "wpa_cli v" VERSION_STR "\n"
-"Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi> and contributors";
+"Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi> and contributors";
 
 
 static const char *wpa_cli_license =
-"This program is free software. You can distribute it and/or modify it\n"
-"under the terms of the GNU General Public License version 2.\n"
-"\n"
-"Alternatively, this software may be distributed under the terms of the\n"
-"BSD license. See README and COPYING for more details.\n";
+"This software may be distributed under the terms of the BSD license.\n"
+"See README for more details.\n";
 
 static const char *wpa_cli_full_license =
-"This program is free software; you can redistribute it and/or modify\n"
-"it under the terms of the GNU General Public License version 2 as\n"
-"published by the Free Software Foundation.\n"
-"\n"
-"This program is distributed in the hope that it will be useful,\n"
-"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
-"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
-"GNU General Public License for more details.\n"
-"\n"
-"You should have received a copy of the GNU General Public License\n"
-"along with this program; if not, write to the Free Software\n"
-"Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\n"
-"\n"
-"Alternatively, this software may be distributed under the terms of the\n"
-"BSD license.\n"
+"This software may be distributed under the terms of the BSD license.\n"
 "\n"
 "Redistribution and use in source and binary forms, with or without\n"
 "modification, are permitted provided that the following conditions are\n"
@@ -94,13 +77,25 @@ static int wpa_cli_quit = 0;
 static int wpa_cli_attached = 0;
 static int wpa_cli_connected = 0;
 static int wpa_cli_last_id = 0;
-static const char *ctrl_iface_dir = "/var/run/wpa_supplicant";
+#ifndef CONFIG_CTRL_IFACE_DIR
+#define CONFIG_CTRL_IFACE_DIR "/var/run/wpa_supplicant"
+#endif /* CONFIG_CTRL_IFACE_DIR */
+static const char *ctrl_iface_dir = CONFIG_CTRL_IFACE_DIR;
 static char *ctrl_ifname = NULL;
 static const char *pid_file = NULL;
 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;
+};
+
+static DEFINE_DL_LIST(bsses); /* struct cli_txt_entry */
+static DEFINE_DL_LIST(p2p_peers); /* struct cli_txt_entry */
+static DEFINE_DL_LIST(p2p_groups); /* struct cli_txt_entry */
+
 
 static void print_help(void);
 static void wpa_cli_mon_receive(int sock, void *eloop_ctx, void *sock_ctx);
@@ -118,20 +113,167 @@ static void usage(void)
               "events from\n"
               "       wpa_supplicant\n"
               "  -B = run a daemon in the background\n"
-              "  default path: /var/run/wpa_supplicant\n"
+              "  default path: " CONFIG_CTRL_IFACE_DIR "\n"
               "  default interface: first interface found in socket path\n");
        print_help();
 }
 
 
-static void readline_redraw()
+static void cli_txt_list_free(struct cli_txt_entry *e)
+{
+       dl_list_del(&e->list);
+       os_free(e->txt);
+       os_free(e);
+}
+
+
+static void cli_txt_list_flush(struct dl_list *list)
+{
+       struct cli_txt_entry *e;
+       while ((e = dl_list_first(list, struct cli_txt_entry, list)))
+               cli_txt_list_free(e);
+}
+
+
+static struct cli_txt_entry * cli_txt_list_get(struct dl_list *txt_list,
+                                              const char *txt)
+{
+       struct cli_txt_entry *e;
+       dl_list_for_each(e, txt_list, struct cli_txt_entry, list) {
+               if (os_strcmp(e->txt, txt) == 0)
+                       return e;
+       }
+       return NULL;
+}
+
+
+static void cli_txt_list_del(struct dl_list *txt_list, const char *txt)
+{
+       struct cli_txt_entry *e;
+       e = cli_txt_list_get(txt_list, txt);
+       if (e)
+               cli_txt_list_free(e);
+}
+
+
+static void cli_txt_list_del_addr(struct dl_list *txt_list, const char *txt)
+{
+       u8 addr[ETH_ALEN];
+       char buf[18];
+       if (hwaddr_aton(txt, addr) < 0)
+               return;
+       os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
+       cli_txt_list_del(txt_list, buf);
+}
+
+
+#ifdef CONFIG_P2P
+static void cli_txt_list_del_word(struct dl_list *txt_list, const char *txt)
+{
+       const char *end;
+       char *buf;
+       end = os_strchr(txt, ' ');
+       if (end == NULL)
+               end = txt + os_strlen(txt);
+       buf = os_malloc(end - txt + 1);
+       if (buf == NULL)
+               return;
+       os_memcpy(buf, txt, end - txt);
+       buf[end - txt] = '\0';
+       cli_txt_list_del(txt_list, buf);
+       os_free(buf);
+}
+#endif /* CONFIG_P2P */
+
+
+static int cli_txt_list_add(struct dl_list *txt_list, const char *txt)
+{
+       struct cli_txt_entry *e;
+       e = cli_txt_list_get(txt_list, txt);
+       if (e)
+               return 0;
+       e = os_zalloc(sizeof(*e));
+       if (e == NULL)
+               return -1;
+       e->txt = os_strdup(txt);
+       if (e->txt == NULL) {
+               os_free(e);
+               return -1;
+       }
+       dl_list_add(txt_list, &e->list);
+       return 0;
+}
+
+
+#ifdef CONFIG_P2P
+static int cli_txt_list_add_addr(struct dl_list *txt_list, const char *txt)
+{
+       u8 addr[ETH_ALEN];
+       char buf[18];
+       if (hwaddr_aton(txt, addr) < 0)
+               return -1;
+       os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
+       return cli_txt_list_add(txt_list, buf);
+}
+
+
+static int cli_txt_list_add_word(struct dl_list *txt_list, const char *txt)
+{
+       const char *end;
+       char *buf;
+       int ret;
+       end = os_strchr(txt, ' ');
+       if (end == NULL)
+               end = txt + os_strlen(txt);
+       buf = os_malloc(end - txt + 1);
+       if (buf == NULL)
+               return -1;
+       os_memcpy(buf, txt, end - txt);
+       buf[end - txt] = '\0';
+       ret = cli_txt_list_add(txt_list, buf);
+       os_free(buf);
+       return ret;
+}
+#endif /* CONFIG_P2P */
+
+
+static char ** cli_txt_list_array(struct dl_list *txt_list)
+{
+       unsigned int i, count = dl_list_len(txt_list);
+       char **res;
+       struct cli_txt_entry *e;
+
+       res = os_zalloc((count + 1) * sizeof(char *));
+       if (res == NULL)
+               return NULL;
+
+       i = 0;
+       dl_list_for_each(e, txt_list, struct cli_txt_entry, list) {
+               res[i] = os_strdup(e->txt);
+               if (res[i] == NULL)
+                       break;
+               i++;
+       }
+
+       return res;
+}
+
+
+static int get_cmd_arg_num(const char *str, int pos)
 {
-#ifdef CONFIG_READLINE
-       rl_on_new_line();
-       rl_redisplay();
-#else /* CONFIG_READLINE */
-       edit_redraw();
-#endif /* CONFIG_READLINE */
+       int arg = 0, i;
+
+       for (i = 0; i <= pos; i++) {
+               if (str[i] != ' ') {
+                       arg++;
+                       while (i <= pos && str[i] != ' ')
+                               i++;
+               }
+       }
+
+       if (arg > 0)
+               arg--;
+       return arg;
 }
 
 
@@ -174,20 +316,31 @@ static int wpa_cli_open_connection(const char *ifname, int attach)
        else
                mon_conn = NULL;
 #else /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
-       char *cfile;
+       char *cfile = NULL;
        int flen, res;
 
        if (ifname == NULL)
                return -1;
 
-       flen = os_strlen(ctrl_iface_dir) + os_strlen(ifname) + 2;
-       cfile = os_malloc(flen);
-       if (cfile == NULL)
-               return -1L;
-       res = os_snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, ifname);
-       if (res < 0 || res >= flen) {
-               os_free(cfile);
-               return -1;
+#ifdef ANDROID
+       if (access(ctrl_iface_dir, F_OK) < 0) {
+               cfile = os_strdup(ifname);
+               if (cfile == NULL)
+                       return -1;
+       }
+#endif /* ANDROID */
+
+       if (cfile == NULL) {
+               flen = os_strlen(ctrl_iface_dir) + os_strlen(ifname) + 2;
+               cfile = os_malloc(flen);
+               if (cfile == NULL)
+                       return -1;
+               res = os_snprintf(cfile, flen, "%s/%s", ctrl_iface_dir,
+                                 ifname);
+               if (res < 0 || res >= flen) {
+                       os_free(cfile);
+                       return -1;
+               }
        }
 
        ctrl_conn = wpa_ctrl_open(cfile);
@@ -269,6 +422,8 @@ static int _wpa_ctrl_command(struct wpa_ctrl *ctrl, char *cmd, int print)
        if (print) {
                buf[len] = '\0';
                printf("%s", buf);
+               if (interactive && len > 0 && buf[len - 1] != '\n')
+                       printf("\n");
        }
        return 0;
 }
@@ -282,8 +437,11 @@ static int wpa_ctrl_command(struct wpa_ctrl *ctrl, char *cmd)
 
 static int wpa_cli_cmd_status(struct wpa_ctrl *ctrl, int argc, char *argv[])
 {
-       int verbose = argc > 0 && os_strcmp(argv[0], "verbose") == 0;
-       return wpa_ctrl_command(ctrl, verbose ? "STATUS-VERBOSE" : "STATUS");
+       if (argc > 0 && os_strcmp(argv[0], "verbose") == 0)
+               return wpa_ctrl_command(ctrl, "STATUS-VERBOSE");
+       if (argc > 0 && os_strcmp(argv[0], "wps") == 0)
+               return wpa_ctrl_command(ctrl, "STATUS-WPS");
+       return wpa_ctrl_command(ctrl, "STATUS");
 }
 
 
@@ -293,6 +451,12 @@ static int wpa_cli_cmd_ping(struct wpa_ctrl *ctrl, int argc, char *argv[])
 }
 
 
+static int wpa_cli_cmd_relog(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+       return wpa_ctrl_command(ctrl, "RELOG");
+}
+
+
 static int wpa_cli_cmd_note(struct wpa_ctrl *ctrl, int argc, char *argv[])
 {
        char cmd[256];
@@ -371,13 +535,17 @@ static int wpa_cli_cmd_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
                return 0;
        }
 
-       if (argc != 2) {
+       if (argc != 1 && argc != 2) {
                printf("Invalid SET command: needs two arguments (variable "
                       "name and value)\n");
                return -1;
        }
 
-       res = os_snprintf(cmd, sizeof(cmd), "SET %s %s", argv[0], argv[1]);
+       if (argc == 1)
+               res = os_snprintf(cmd, sizeof(cmd), "SET %s ", argv[0]);
+       else
+               res = os_snprintf(cmd, sizeof(cmd), "SET %s %s",
+                                 argv[0], argv[1]);
        if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
                printf("Too long SET command.\n");
                return -1;
@@ -465,6 +633,66 @@ static int wpa_cli_cmd_ap_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
 }
 
 
+static int wpa_cli_cmd_scan_interval(struct wpa_ctrl *ctrl, int argc,
+                                    char *argv[])
+{
+       char cmd[256];
+       int res;
+
+       if (argc != 1) {
+               printf("Invalid SCAN_INTERVAL command: needs one argument "
+                      "scan_interval value)\n");
+               return -1;
+       }
+       res = os_snprintf(cmd, sizeof(cmd), "SCAN_INTERVAL %s", argv[0]);
+       if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+               printf("Too long SCAN_INTERVAL command.\n");
+               return -1;
+       }
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_bss_expire_age(struct wpa_ctrl *ctrl, int argc,
+                                     char *argv[])
+{
+       char cmd[256];
+       int res;
+
+       if (argc != 1) {
+               printf("Invalid BSS_EXPIRE_AGE command: needs one argument "
+                      "(bss_expire_age value)\n");
+               return -1;
+       }
+       res = os_snprintf(cmd, sizeof(cmd), "BSS_EXPIRE_AGE %s", argv[0]);
+       if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+               printf("Too long BSS_EXPIRE_AGE command.\n");
+               return -1;
+       }
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_bss_expire_count(struct wpa_ctrl *ctrl, int argc,
+                                       char *argv[])
+{
+       char cmd[256];
+       int res;
+
+       if (argc != 1) {
+               printf("Invalid BSS_EXPIRE_COUNT command: needs one argument "
+                      "(bss_expire_count value)\n");
+               return -1;
+       }
+       res = os_snprintf(cmd, sizeof(cmd), "BSS_EXPIRE_COUNT %s", argv[0]);
+       if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+               printf("Too long BSS_EXPIRE_COUNT command.\n");
+               return -1;
+       }
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
 static int wpa_cli_cmd_stkstart(struct wpa_ctrl *ctrl, int argc,
                                char *argv[])
 {
@@ -682,6 +910,35 @@ static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
 }
 
 
+static int wpa_cli_cmd_wps_ap_pin(struct wpa_ctrl *ctrl, int argc,
+                                 char *argv[])
+{
+       char cmd[256];
+       int res;
+
+       if (argc < 1) {
+               printf("Invalid WPS_AP_PIN command: needs at least one "
+                      "argument\n");
+               return -1;
+       }
+
+       if (argc > 2)
+               res = os_snprintf(cmd, sizeof(cmd), "WPS_AP_PIN %s %s %s",
+                                 argv[0], argv[1], argv[2]);
+       else if (argc > 1)
+               res = os_snprintf(cmd, sizeof(cmd), "WPS_AP_PIN %s %s",
+                                 argv[0], argv[1]);
+       else
+               res = os_snprintf(cmd, sizeof(cmd), "WPS_AP_PIN %s",
+                                 argv[0]);
+       if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+               printf("Too long WPS_AP_PIN command.\n");
+               return -1;
+       }
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
 static int wpa_cli_cmd_wps_er_start(struct wpa_ctrl *ctrl, int argc,
                                    char *argv[])
 {
@@ -1121,6 +1378,58 @@ static int wpa_cli_cmd_bssid(struct wpa_ctrl *ctrl, int argc, char *argv[])
 }
 
 
+static int wpa_cli_cmd_blacklist(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+       char cmd[256], *pos, *end;
+       int i, ret;
+
+       end = cmd + sizeof(cmd);
+       pos = cmd;
+       ret = os_snprintf(pos, end - pos, "BLACKLIST");
+       if (ret < 0 || ret >= end - pos) {
+               printf("Too long BLACKLIST command.\n");
+               return -1;
+       }
+       pos += ret;
+       for (i = 0; i < argc; i++) {
+               ret = os_snprintf(pos, end - pos, " %s", argv[i]);
+               if (ret < 0 || ret >= end - pos) {
+                       printf("Too long BLACKLIST command.\n");
+                       return -1;
+               }
+               pos += ret;
+       }
+
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_log_level(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+       char cmd[256], *pos, *end;
+       int i, ret;
+
+       end = cmd + sizeof(cmd);
+       pos = cmd;
+       ret = os_snprintf(pos, end - pos, "LOG_LEVEL");
+       if (ret < 0 || ret >= end - pos) {
+               printf("Too long LOG_LEVEL command.\n");
+               return -1;
+       }
+       pos += ret;
+       for (i = 0; i < argc; i++) {
+               ret = os_snprintf(pos, end - pos, " %s", argv[i]);
+               if (ret < 0 || ret >= end - pos) {
+                       printf("Too long LOG_LEVEL command.\n");
+                       return -1;
+               }
+               pos += ret;
+       }
+
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
 static int wpa_cli_cmd_list_networks(struct wpa_ctrl *ctrl, int argc,
                                     char *argv[])
 {
@@ -1348,6 +1657,21 @@ static int wpa_cli_cmd_bss(struct wpa_ctrl *ctrl, int argc, char *argv[])
 }
 
 
+static char ** wpa_cli_complete_bss(const char *str, int pos)
+{
+       int arg = get_cmd_arg_num(str, pos);
+       char **res = NULL;
+
+       switch (arg) {
+       case 1:
+               res = cli_txt_list_array(&bsses);
+               break;
+       }
+
+       return res;
+}
+
+
 static int wpa_cli_cmd_get_capability(struct wpa_ctrl *ctrl, int argc,
                                      char *argv[])
 {
@@ -1589,7 +1913,10 @@ static int wpa_cli_cmd_p2p_find(struct wpa_ctrl *ctrl, int argc, char *argv[])
        if (argc == 0)
                return wpa_ctrl_command(ctrl, "P2P_FIND");
 
-       if (argc > 1)
+       if (argc > 2)
+               res = os_snprintf(cmd, sizeof(cmd), "P2P_FIND %s %s %s",
+                                 argv[0], argv[1], argv[2]);
+       else if (argc > 1)
                res = os_snprintf(cmd, sizeof(cmd), "P2P_FIND %s %s",
                                  argv[0], argv[1]);
        else
@@ -1641,6 +1968,21 @@ static int wpa_cli_cmd_p2p_connect(struct wpa_ctrl *ctrl, int argc,
 }
 
 
+static char ** wpa_cli_complete_p2p_connect(const char *str, int pos)
+{
+       int arg = get_cmd_arg_num(str, pos);
+       char **res = NULL;
+
+       switch (arg) {
+       case 1:
+               res = cli_txt_list_array(&p2p_peers);
+               break;
+       }
+
+       return res;
+}
+
+
 static int wpa_cli_cmd_p2p_listen(struct wpa_ctrl *ctrl, int argc,
                                  char *argv[])
 {
@@ -1678,6 +2020,21 @@ static int wpa_cli_cmd_p2p_group_remove(struct wpa_ctrl *ctrl, int argc,
 }
 
 
+static char ** wpa_cli_complete_p2p_group_remove(const char *str, int pos)
+{
+       int arg = get_cmd_arg_num(str, pos);
+       char **res = NULL;
+
+       switch (arg) {
+       case 1:
+               res = cli_txt_list_array(&p2p_groups);
+               break;
+       }
+
+       return res;
+}
+
+
 static int wpa_cli_cmd_p2p_group_add(struct wpa_ctrl *ctrl, int argc,
                                        char *argv[])
 {
@@ -1687,7 +2044,12 @@ static int wpa_cli_cmd_p2p_group_add(struct wpa_ctrl *ctrl, int argc,
        if (argc == 0)
                return wpa_ctrl_command(ctrl, "P2P_GROUP_ADD");
 
-       res = os_snprintf(cmd, sizeof(cmd), "P2P_GROUP_ADD %s", argv[0]);
+       if (argc > 1)
+               res = os_snprintf(cmd, sizeof(cmd), "P2P_GROUP_ADD %s %s",
+                                 argv[0], argv[1]);
+       else
+               res = os_snprintf(cmd, sizeof(cmd), "P2P_GROUP_ADD %s",
+                                 argv[0]);
        if (res < 0 || (size_t) res >= sizeof(cmd))
                return -1;
        cmd[sizeof(cmd) - 1] = '\0';
@@ -1701,15 +2063,19 @@ static int wpa_cli_cmd_p2p_prov_disc(struct wpa_ctrl *ctrl, int argc,
        char cmd[128];
        int res;
 
-       if (argc != 2) {
-               printf("Invalid P2P_PROV_DISC command: needs two arguments "
-                      "(address and config method\n"
-                      "(display, keypad, or pbc)\n");
+       if (argc != 2 && argc != 3) {
+               printf("Invalid P2P_PROV_DISC command: needs at least "
+                      "two arguments, address and config method\n"
+                      "(display, keypad, or pbc) and an optional join\n");
                return -1;
        }
 
-       res = os_snprintf(cmd, sizeof(cmd), "P2P_PROV_DISC %s %s",
-                         argv[0], argv[1]);
+       if (argc == 3)
+               res = os_snprintf(cmd, sizeof(cmd), "P2P_PROV_DISC %s %s %s",
+                                 argv[0], argv[1], argv[2]);
+       else
+               res = os_snprintf(cmd, sizeof(cmd), "P2P_PROV_DISC %s %s",
+                                 argv[0], argv[1]);
        if (res < 0 || (size_t) res >= sizeof(cmd))
                return -1;
        cmd[sizeof(cmd) - 1] = '\0';
@@ -1943,6 +2309,21 @@ static int wpa_cli_cmd_p2p_peer(struct wpa_ctrl *ctrl, int argc, char *argv[])
 }
 
 
+static char ** wpa_cli_complete_p2p_peer(const char *str, int pos)
+{
+       int arg = get_cmd_arg_num(str, pos);
+       char **res = NULL;
+
+       switch (arg) {
+       case 1:
+               res = cli_txt_list_array(&p2p_peers);
+               break;
+       }
+
+       return res;
+}
+
+
 static int wpa_ctrl_command_p2p_peer(struct wpa_ctrl *ctrl, char *cmd,
                                     char *addr, size_t addr_len,
                                     int discovered)
@@ -1988,13 +2369,13 @@ static int wpa_cli_cmd_p2p_peers(struct wpa_ctrl *ctrl, int argc, char *argv[])
 
        if (wpa_ctrl_command_p2p_peer(ctrl, "P2P_PEER FIRST",
                                      addr, sizeof(addr), discovered))
-               return 0;
+               return -1;
        do {
                os_snprintf(cmd, sizeof(cmd), "P2P_PEER NEXT-%s", addr);
        } while (wpa_ctrl_command_p2p_peer(ctrl, cmd, addr, sizeof(addr),
                         discovered) == 0);
 
-       return -1;
+       return 0;
 }
 
 
@@ -2030,14 +2411,36 @@ static int wpa_cli_cmd_p2p_cancel(struct wpa_ctrl *ctrl, int argc,
 }
 
 
-static int wpa_cli_cmd_p2p_presence_req(struct wpa_ctrl *ctrl, int argc,
-                                       char *argv[])
+static int wpa_cli_cmd_p2p_unauthorize(struct wpa_ctrl *ctrl, int argc,
+                                      char *argv[])
 {
        char cmd[100];
        int res;
 
-       if (argc != 0 && argc != 2 && argc != 4) {
-               printf("Invalid P2P_PRESENCE_REQ command: needs two arguments "
+       if (argc != 1) {
+               printf("Invalid P2P_UNAUTHORIZE command: needs one argument "
+                      "(peer address)\n");
+               return -1;
+       }
+
+       res = os_snprintf(cmd, sizeof(cmd), "P2P_UNAUTHORIZE %s", argv[0]);
+
+       if (res < 0 || (size_t) res >= sizeof(cmd))
+               return -1;
+
+       cmd[sizeof(cmd) - 1] = '\0';
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_p2p_presence_req(struct wpa_ctrl *ctrl, int argc,
+                                       char *argv[])
+{
+       char cmd[100];
+       int res;
+
+       if (argc != 0 && argc != 2 && argc != 4) {
+               printf("Invalid P2P_PRESENCE_REQ command: needs two arguments "
                       "(preferred duration, interval; in microsecods).\n"
                       "Optional second pair can be used to provide "
                       "acceptable values.\n");
@@ -2089,6 +2492,80 @@ static int wpa_cli_cmd_p2p_ext_listen(struct wpa_ctrl *ctrl, int argc,
 #endif /* CONFIG_P2P */
 
 
+#ifdef CONFIG_INTERWORKING
+static int wpa_cli_cmd_fetch_anqp(struct wpa_ctrl *ctrl, int argc,
+                                 char *argv[])
+{
+       return wpa_ctrl_command(ctrl, "FETCH_ANQP");
+}
+
+
+static int wpa_cli_cmd_stop_fetch_anqp(struct wpa_ctrl *ctrl, int argc,
+                                      char *argv[])
+{
+       return wpa_ctrl_command(ctrl, "STOP_FETCH_ANQP");
+}
+
+
+static int wpa_cli_cmd_interworking_select(struct wpa_ctrl *ctrl, int argc,
+                                          char *argv[])
+{
+       char cmd[100];
+       int res;
+
+       if (argc == 0)
+               return wpa_ctrl_command(ctrl, "INTERWORKING_SELECT");
+
+       res = os_snprintf(cmd, sizeof(cmd), "INTERWORKING_SELECT %s", argv[0]);
+       if (res < 0 || (size_t) res >= sizeof(cmd))
+               return -1;
+       cmd[sizeof(cmd) - 1] = '\0';
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_interworking_connect(struct wpa_ctrl *ctrl, int argc,
+                                           char *argv[])
+{
+       char cmd[100];
+       int res;
+
+       if (argc != 1) {
+               printf("Invalid INTERWORKING_CONNECT commands: needs one "
+                      "argument (BSSID)\n");
+               return -1;
+       }
+
+       res = os_snprintf(cmd, sizeof(cmd), "INTERWORKING_CONNECT %s",
+                         argv[0]);
+       if (res < 0 || (size_t) res >= sizeof(cmd))
+               return -1;
+       cmd[sizeof(cmd) - 1] = '\0';
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_anqp_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+       char cmd[100];
+       int res;
+
+       if (argc != 2) {
+               printf("Invalid ANQP_GET command: needs two arguments "
+                      "(addr and info id list)\n");
+               return -1;
+       }
+
+       res = os_snprintf(cmd, sizeof(cmd), "ANQP_GET %s %s",
+                         argv[0], argv[1]);
+       if (res < 0 || (size_t) res >= sizeof(cmd))
+               return -1;
+       cmd[sizeof(cmd) - 1] = '\0';
+       return wpa_ctrl_command(ctrl, cmd);
+}
+#endif /* CONFIG_INTERWORKING */
+
+
 static int wpa_cli_cmd_sta_autoconnect(struct wpa_ctrl *ctrl, int argc,
                                       char *argv[])
 {
@@ -2109,6 +2586,83 @@ static int wpa_cli_cmd_sta_autoconnect(struct wpa_ctrl *ctrl, int argc,
 }
 
 
+static int wpa_cli_cmd_tdls_discover(struct wpa_ctrl *ctrl, int argc,
+                                    char *argv[])
+{
+       char cmd[256];
+       int res;
+
+       if (argc != 1) {
+               printf("Invalid TDLS_DISCOVER command: needs one argument "
+                      "(Peer STA MAC address)\n");
+               return -1;
+       }
+
+       res = os_snprintf(cmd, sizeof(cmd), "TDLS_DISCOVER %s", argv[0]);
+       if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+               printf("Too long TDLS_DISCOVER command.\n");
+               return -1;
+       }
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_tdls_setup(struct wpa_ctrl *ctrl, int argc,
+                                 char *argv[])
+{
+       char cmd[256];
+       int res;
+
+       if (argc != 1) {
+               printf("Invalid TDLS_SETUP command: needs one argument "
+                      "(Peer STA MAC address)\n");
+               return -1;
+       }
+
+       res = os_snprintf(cmd, sizeof(cmd), "TDLS_SETUP %s", argv[0]);
+       if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+               printf("Too long TDLS_SETUP command.\n");
+               return -1;
+       }
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_tdls_teardown(struct wpa_ctrl *ctrl, int argc,
+                                    char *argv[])
+{
+       char cmd[256];
+       int res;
+
+       if (argc != 1) {
+               printf("Invalid TDLS_TEARDOWN command: needs one argument "
+                      "(Peer STA MAC address)\n");
+               return -1;
+       }
+
+       res = os_snprintf(cmd, sizeof(cmd), "TDLS_TEARDOWN %s", argv[0]);
+       if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+               printf("Too long TDLS_TEARDOWN command.\n");
+               return -1;
+       }
+       return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_signal_poll(struct wpa_ctrl *ctrl, int argc,
+                                  char *argv[])
+{
+       return wpa_ctrl_command(ctrl, "SIGNAL_POLL");
+}
+
+
+static int wpa_cli_cmd_reauthenticate(struct wpa_ctrl *ctrl, int argc,
+                                     char *argv[])
+{
+       return wpa_ctrl_command(ctrl, "REAUTHENTICATE");
+}
+
+
 enum wpa_cli_cmd_flags {
        cli_cmd_flag_none               = 0x00,
        cli_cmd_flag_sensitive          = 0x01
@@ -2128,6 +2682,9 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
        { "ping", wpa_cli_cmd_ping,
          cli_cmd_flag_none,
          "= pings wpa_supplicant" },
+       { "relog", wpa_cli_cmd_relog,
+         cli_cmd_flag_none,
+         "= re-open log-file (allow rolling logs)" },
        { "note", wpa_cli_cmd_note,
          cli_cmd_flag_none,
          "<text> = add a note to wpa_supplicant debug log" },
@@ -2194,6 +2751,15 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
        { "bssid", wpa_cli_cmd_bssid,
          cli_cmd_flag_none,
          "<network id> <BSSID> = set preferred BSSID for an SSID" },
+       { "blacklist", wpa_cli_cmd_blacklist,
+         cli_cmd_flag_none,
+         "<BSSID> = add a BSSID to the blacklist\n"
+         "blacklist clear = clear the blacklist\n"
+         "blacklist = display the blacklist" },
+       { "log_level", wpa_cli_cmd_log_level,
+         cli_cmd_flag_none,
+         "<level> [<timestamp>] = update the log level/timestamp\n"
+         "log_level = display the current log level and log options" },
        { "list_networks", wpa_cli_cmd_list_networks,
          cli_cmd_flag_none,
          "= list configured networks" },
@@ -2262,6 +2828,15 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
        { "ap_scan", wpa_cli_cmd_ap_scan,
          cli_cmd_flag_none,
          "<value> = set ap_scan parameter" },
+       { "scan_interval", wpa_cli_cmd_scan_interval,
+         cli_cmd_flag_none,
+         "<value> = set scan_interval parameter (in seconds)" },
+       { "bss_expire_age", wpa_cli_cmd_bss_expire_age,
+         cli_cmd_flag_none,
+         "<value> = set BSS expiration age parameter" },
+       { "bss_expire_count", wpa_cli_cmd_bss_expire_count,
+         cli_cmd_flag_none,
+         "<value> = set BSS expiration scan count parameter" },
        { "stkstart", wpa_cli_cmd_stkstart,
          cli_cmd_flag_none,
          "<addr> = request STK negotiation with <addr>" },
@@ -2288,6 +2863,9 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
        { "wps_reg", wpa_cli_cmd_wps_reg,
          cli_cmd_flag_sensitive,
          "<BSSID> <AP PIN> = start WPS Registrar to configure an AP" },
+       { "wps_ap_pin", wpa_cli_cmd_wps_ap_pin,
+         cli_cmd_flag_sensitive,
+         "[params..] = enable/disable AP PIN" },
        { "wps_er_start", wpa_cli_cmd_wps_er_start,
          cli_cmd_flag_none,
          "[IP address] = start Wi-Fi Protected Setup External Registrar" },
@@ -2339,7 +2917,7 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
        { "p2p_listen", wpa_cli_cmd_p2p_listen, cli_cmd_flag_none,
          "[timeout] = listen for P2P Devices for up-to timeout seconds" },
        { "p2p_group_remove", wpa_cli_cmd_p2p_group_remove, cli_cmd_flag_none,
-         "<ifname> = remote P2P group interface (terminate group if GO)" },
+         "<ifname> = remove P2P group interface (terminate group if GO)" },
        { "p2p_group_add", wpa_cli_cmd_p2p_group_add, cli_cmd_flag_none,
          "= add a new P2P group (local end as GO)" },
        { "p2p_prov_disc", wpa_cli_cmd_p2p_prov_disc, cli_cmd_flag_none,
@@ -2390,14 +2968,45 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
          "= flush P2P state" },
        { "p2p_cancel", wpa_cli_cmd_p2p_cancel, cli_cmd_flag_none,
          "= cancel P2P group formation" },
+       { "p2p_unauthorize", wpa_cli_cmd_p2p_unauthorize, cli_cmd_flag_none,
+         "<address> = unauthorize a peer" },
        { "p2p_presence_req", wpa_cli_cmd_p2p_presence_req, cli_cmd_flag_none,
          "[<duration> <interval>] [<duration> <interval>] = request GO "
          "presence" },
        { "p2p_ext_listen", wpa_cli_cmd_p2p_ext_listen, cli_cmd_flag_none,
          "[<period> <interval>] = set extended listen timing" },
 #endif /* CONFIG_P2P */
+
+#ifdef CONFIG_INTERWORKING
+       { "fetch_anqp", wpa_cli_cmd_fetch_anqp, cli_cmd_flag_none,
+         "= fetch ANQP information for all APs" },
+       { "stop_fetch_anqp", wpa_cli_cmd_stop_fetch_anqp, cli_cmd_flag_none,
+         "= stop fetch_anqp operation" },
+       { "interworking_select", wpa_cli_cmd_interworking_select,
+         cli_cmd_flag_none,
+         "[auto] = perform Interworking network selection" },
+       { "interworking_connect", wpa_cli_cmd_interworking_connect,
+         cli_cmd_flag_none,
+         "<BSSID> = connect using Interworking credentials" },
+       { "anqp_get", wpa_cli_cmd_anqp_get, cli_cmd_flag_none,
+         "<addr> <info id>[,<info id>]... = request ANQP information" },
+#endif /* CONFIG_INTERWORKING */
        { "sta_autoconnect", wpa_cli_cmd_sta_autoconnect, cli_cmd_flag_none,
          "<0/1> = disable/enable automatic reconnection" },
+       { "tdls_discover", wpa_cli_cmd_tdls_discover,
+         cli_cmd_flag_none,
+         "<addr> = request TDLS discovery with <addr>" },
+       { "tdls_setup", wpa_cli_cmd_tdls_setup,
+         cli_cmd_flag_none,
+         "<addr> = request TDLS setup with <addr>" },
+       { "tdls_teardown", wpa_cli_cmd_tdls_teardown,
+         cli_cmd_flag_none,
+         "<addr> = tear down TDLS with <addr>" },
+       { "signal_poll", wpa_cli_cmd_signal_poll,
+         cli_cmd_flag_none,
+         "= get signal parameters" },
+       { "reauthenticate", wpa_cli_cmd_reauthenticate, cli_cmd_flag_none,
+         "= trigger IEEE 802.1X/EAPOL reauthentication" },
        { NULL, NULL, cli_cmd_flag_none, NULL }
 };
 
@@ -2429,8 +3038,7 @@ static void print_help(void)
 }
 
 
-#ifdef CONFIG_READLINE
-static int cmd_has_sensitive_data(const char *cmd)
+static int wpa_cli_edit_filter_history_cb(void *ctx, const char *cmd)
 {
        const char *c, *delim;
        int n;
@@ -2449,7 +3057,76 @@ static int cmd_has_sensitive_data(const char *cmd)
        }
        return 0;
 }
-#endif /* CONFIG_READLINE */
+
+
+static char ** wpa_list_cmd_list(void)
+{
+       char **res;
+       int i, count;
+
+       count = sizeof(wpa_cli_commands) / sizeof(wpa_cli_commands[0]);
+       res = os_zalloc(count * sizeof(char *));
+       if (res == NULL)
+               return NULL;
+
+       for (i = 0; wpa_cli_commands[i].cmd; i++) {
+               res[i] = os_strdup(wpa_cli_commands[i].cmd);
+               if (res[i] == NULL)
+                       break;
+       }
+
+       return res;
+}
+
+
+static char ** wpa_cli_cmd_completion(const char *cmd, const char *str,
+                                     int pos)
+{
+       int i;
+
+       if (os_strcasecmp(cmd, "bss") == 0)
+               return wpa_cli_complete_bss(str, pos);
+#ifdef CONFIG_P2P
+       if (os_strcasecmp(cmd, "p2p_connect") == 0)
+               return wpa_cli_complete_p2p_connect(str, pos);
+       if (os_strcasecmp(cmd, "p2p_peer") == 0)
+               return wpa_cli_complete_p2p_peer(str, pos);
+       if (os_strcasecmp(cmd, "p2p_group_remove") == 0)
+               return wpa_cli_complete_p2p_group_remove(str, pos);
+#endif /* CONFIG_P2P */
+
+       for (i = 0; wpa_cli_commands[i].cmd; i++) {
+               if (os_strcasecmp(wpa_cli_commands[i].cmd, cmd) == 0) {
+                       edit_clear_line();
+                       printf("\r%s\n", wpa_cli_commands[i].usage);
+                       edit_redraw();
+                       break;
+               }
+       }
+
+       return NULL;
+}
+
+
+static char ** wpa_cli_edit_completion_cb(void *ctx, const char *str, int pos)
+{
+       char **res;
+       const char *end;
+       char *cmd;
+
+       end = os_strchr(str, ' ');
+       if (end == NULL || str + pos < end)
+               return wpa_list_cmd_list();
+
+       cmd = os_malloc(pos + 1);
+       if (cmd == NULL)
+               return NULL;
+       os_memcpy(cmd, str, pos);
+       cmd[end - str] = '\0';
+       res = wpa_cli_cmd_completion(cmd, str, pos);
+       os_free(cmd);
+       return res;
+}
 
 
 static int wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
@@ -2595,10 +3272,16 @@ static void wpa_cli_action_process(const char *msg)
                wpa_cli_exec(action_file, ctrl_ifname, pos);
        } else if (str_match(pos, P2P_EVENT_CROSS_CONNECT_DISABLE)) {
                wpa_cli_exec(action_file, ctrl_ifname, pos);
+       } else if (str_match(pos, P2P_EVENT_GO_NEG_FAILURE)) {
+               wpa_cli_exec(action_file, ctrl_ifname, pos);
        } else if (str_match(pos, WPS_EVENT_SUCCESS)) {
                wpa_cli_exec(action_file, ctrl_ifname, pos);
        } else if (str_match(pos, WPS_EVENT_FAIL)) {
                wpa_cli_exec(action_file, ctrl_ifname, pos);
+       } else if (str_match(pos, AP_STA_CONNECTED)) {
+               wpa_cli_exec(action_file, ctrl_ifname, pos);
+       } else if (str_match(pos, AP_STA_DISCONNECTED)) {
+               wpa_cli_exec(action_file, ctrl_ifname, pos);
        } else if (str_match(pos, WPA_EVENT_TERMINATING)) {
                printf("wpa_supplicant is terminating - stop monitoring\n");
                wpa_cli_quit = 1;
@@ -2621,6 +3304,74 @@ static void wpa_cli_reconnect(void)
 }
 
 
+static void cli_event(const char *str)
+{
+       const char *start, *s;
+
+       start = os_strchr(str, '>');
+       if (start == NULL)
+               return;
+
+       start++;
+
+       if (str_starts(start, WPA_EVENT_BSS_ADDED)) {
+               s = os_strchr(start, ' ');
+               if (s == NULL)
+                       return;
+               s = os_strchr(s + 1, ' ');
+               if (s == NULL)
+                       return;
+               cli_txt_list_add(&bsses, s + 1);
+               return;
+       }
+
+       if (str_starts(start, WPA_EVENT_BSS_REMOVED)) {
+               s = os_strchr(start, ' ');
+               if (s == NULL)
+                       return;
+               s = os_strchr(s + 1, ' ');
+               if (s == NULL)
+                       return;
+               cli_txt_list_del_addr(&bsses, s + 1);
+               return;
+       }
+
+#ifdef CONFIG_P2P
+       if (str_starts(start, P2P_EVENT_DEVICE_FOUND)) {
+               s = os_strstr(start, " p2p_dev_addr=");
+               if (s == NULL)
+                       return;
+               cli_txt_list_add_addr(&p2p_peers, s + 14);
+               return;
+       }
+
+       if (str_starts(start, P2P_EVENT_DEVICE_LOST)) {
+               s = os_strstr(start, " p2p_dev_addr=");
+               if (s == NULL)
+                       return;
+               cli_txt_list_del_addr(&p2p_peers, s + 14);
+               return;
+       }
+
+       if (str_starts(start, P2P_EVENT_GROUP_STARTED)) {
+               s = os_strchr(start, ' ');
+               if (s == NULL)
+                       return;
+               cli_txt_list_add_word(&p2p_groups, s + 1);
+               return;
+       }
+
+       if (str_starts(start, P2P_EVENT_GROUP_REMOVED)) {
+               s = os_strchr(start, ' ');
+               if (s == NULL)
+                       return;
+               cli_txt_list_del_word(&p2p_groups, s + 1);
+               return;
+       }
+#endif /* CONFIG_P2P */
+}
+
+
 static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int action_monitor)
 {
        if (ctrl_conn == NULL) {
@@ -2635,12 +3386,11 @@ static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int action_monitor)
                        if (action_monitor)
                                wpa_cli_action_process(buf);
                        else {
+                               cli_event(buf);
                                if (wpa_cli_show_event(buf)) {
-#ifndef CONFIG_READLINE
                                        edit_clear_line();
-#endif /* CONFIG_READLINE */
                                        printf("\r%s\n", buf);
-                                       readline_redraw();
+                                       edit_redraw();
                                }
                        }
                } else {
@@ -2713,196 +3463,6 @@ static void wpa_cli_mon_receive(int sock, void *eloop_ctx, void *sock_ctx)
 }
 
 
-#ifdef CONFIG_READLINE
-
-static char * wpa_cli_cmd_gen(const char *text, int state)
-{
-       static int i, len;
-       const char *cmd;
-
-       if (state == 0) {
-               i = 0;
-               len = os_strlen(text);
-       }
-
-       while ((cmd = wpa_cli_commands[i].cmd)) {
-               i++;
-               if (os_strncasecmp(cmd, text, len) == 0)
-                       return strdup(cmd);
-       }
-
-       return NULL;
-}
-
-
-static char * wpa_cli_dummy_gen(const char *text, int state)
-{
-       int i;
-
-       for (i = 0; wpa_cli_commands[i].cmd; i++) {
-               const char *cmd = wpa_cli_commands[i].cmd;
-               size_t len = os_strlen(cmd);
-               if (os_strncasecmp(rl_line_buffer, cmd, len) == 0 &&
-                   rl_line_buffer[len] == ' ') {
-                       printf("\n%s\n", wpa_cli_commands[i].usage);
-                       readline_redraw();
-                       break;
-               }
-       }
-
-       rl_attempted_completion_over = 1;
-       return NULL;
-}
-
-
-static char * wpa_cli_status_gen(const char *text, int state)
-{
-       static int i, len;
-       char *options[] = {
-               "verbose", NULL
-       };
-       char *t;
-
-       if (state == 0) {
-               i = 0;
-               len = os_strlen(text);
-       }
-
-       while ((t = options[i])) {
-               i++;
-               if (os_strncasecmp(t, text, len) == 0)
-                       return strdup(t);
-       }
-
-       rl_attempted_completion_over = 1;
-       return NULL;
-}
-
-
-static char ** wpa_cli_completion(const char *text, int start, int end)
-{
-       char * (*func)(const char *text, int state);
-
-       if (start == 0)
-               func = wpa_cli_cmd_gen;
-       else if (os_strncasecmp(rl_line_buffer, "status ", 7) == 0)
-               func = wpa_cli_status_gen;
-       else
-               func = wpa_cli_dummy_gen;
-       return rl_completion_matches(text, func);
-}
-
-
-static void wpa_cli_read_char(int sock, void *eloop_ctx, void *sock_ctx)
-{
-       rl_callback_read_char();
-}
-
-
-static void trunc_nl(char *str)
-{
-       char *pos = str;
-       while (*pos != '\0') {
-               if (*pos == '\n') {
-                       *pos = '\0';
-                       break;
-               }
-               pos++;
-       }
-}
-
-
-static void readline_cmd_handler(char *cmd)
-{
-       int argc;
-       char *argv[max_args];
-
-       if (cmd && *cmd) {
-               HIST_ENTRY *h;
-               while (next_history())
-                       ;
-               h = previous_history();
-               if (h == NULL || os_strcmp(cmd, h->line) != 0)
-                       add_history(cmd);
-               next_history();
-       }
-       if (cmd == NULL) {
-               eloop_terminate();
-               return;
-       }
-       trunc_nl(cmd);
-       argc = tokenize_cmd(cmd, argv);
-       if (argc)
-               wpa_request(ctrl_conn, argc, argv);
-}
-
-
-static void wpa_cli_interactive(void)
-{
-       char *home, *hfile = NULL;
-
-       printf("\nInteractive mode\n\n");
-
-       rl_attempted_completion_function = wpa_cli_completion;
-       home = getenv("HOME");
-       if (home) {
-               const char *fname = ".wpa_cli_history";
-               int hfile_len = os_strlen(home) + 1 + os_strlen(fname) + 1;
-               hfile = os_malloc(hfile_len);
-               if (hfile) {
-                       int res;
-                       res = os_snprintf(hfile, hfile_len, "%s/%s", home,
-                                         fname);
-                       if (res >= 0 && res < hfile_len) {
-                               hfile[hfile_len - 1] = '\0';
-                               read_history(hfile);
-                               stifle_history(100);
-                       }
-               }
-       }
-
-       eloop_register_signal_terminate(wpa_cli_eloop_terminate, NULL);
-       eloop_register_read_sock(STDIN_FILENO, wpa_cli_read_char, NULL, NULL);
-       eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL);
-
-       rl_callback_handler_install("> ", readline_cmd_handler);
-
-       eloop_run();
-
-       rl_callback_handler_remove();
-
-       eloop_unregister_read_sock(STDIN_FILENO);
-       eloop_cancel_timeout(wpa_cli_ping, NULL, NULL);
-       wpa_cli_close_connection();
-
-       if (hfile) {
-               /* Save command history, excluding lines that may contain
-                * passwords. */
-               HIST_ENTRY *h;
-               history_set_pos(0);
-               while ((h = current_history())) {
-                       char *p = h->line;
-                       while (*p == ' ' || *p == '\t')
-                               p++;
-                       if (cmd_has_sensitive_data(p)) {
-                               h = remove_history(where_history());
-                               if (h) {
-                                       os_free(h->line);
-                                       free(h->data);
-                                       os_free(h);
-                               } else
-                                       next_history();
-                       } else
-                               next_history();
-               }
-               write_history(hfile);
-               os_free(hfile);
-       }
-}
-
-#else /* CONFIG_READLINE */
-
-
 static void wpa_cli_edit_cmd_cb(void *ctx, char *cmd)
 {
        char *argv[max_args];
@@ -2921,25 +3481,35 @@ static void wpa_cli_edit_eof_cb(void *ctx)
 
 static void wpa_cli_interactive(void)
 {
+       char *home, *hfile = NULL;
 
        printf("\nInteractive mode\n\n");
 
+       home = getenv("HOME");
+       if (home) {
+               const char *fname = ".wpa_cli_history";
+               int hfile_len = os_strlen(home) + 1 + os_strlen(fname) + 1;
+               hfile = os_malloc(hfile_len);
+               if (hfile)
+                       os_snprintf(hfile, hfile_len, "%s/%s", home, fname);
+       }
+
        eloop_register_signal_terminate(wpa_cli_eloop_terminate, NULL);
-       edit_init(wpa_cli_edit_cmd_cb, wpa_cli_edit_eof_cb, NULL);
+       edit_init(wpa_cli_edit_cmd_cb, wpa_cli_edit_eof_cb,
+                 wpa_cli_edit_completion_cb, NULL, hfile);
        eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL);
 
-       printf("> ");
-       fflush(stdout);
-
        eloop_run();
 
-       edit_deinit();
+       cli_txt_list_flush(&p2p_peers);
+       cli_txt_list_flush(&p2p_groups);
+       cli_txt_list_flush(&bsses);
+       edit_deinit(hfile, wpa_cli_edit_filter_history_cb);
+       os_free(hfile);
        eloop_cancel_timeout(wpa_cli_ping, NULL, NULL);
        wpa_cli_close_connection();
 }
 
-#endif /* CONFIG_READLINE */
-
 
 static void wpa_cli_action(struct wpa_ctrl *ctrl)
 {
@@ -3007,8 +3577,17 @@ static char * wpa_cli_get_default_ifname(void)
 #ifdef CONFIG_CTRL_IFACE_UNIX
        struct dirent *dent;
        DIR *dir = opendir(ctrl_iface_dir);
-       if (!dir)
+       if (!dir) {
+#ifdef ANDROID
+               char ifprop[PROPERTY_VALUE_MAX];
+               if (property_get("wifi.interface", ifprop, NULL) != 0) {
+                       ifname = os_strdup(ifprop);
+                       printf("Using interface '%s'\n", ifname);
+                       return ifname;
+               }
+#endif /* ANDROID */
                return NULL;
+       }
        while ((dent = readdir(dir))) {
 #ifdef _DIRENT_HAVE_D_TYPE
                /*