From patchwork Tue Mar 24 16:10:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Kanstrup X-Patchwork-Id: 453937 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]) by ozlabs.org (Postfix) with ESMTP id 4EB5C140083 for ; Wed, 25 Mar 2015 03:11:47 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 2206117C12F; Tue, 24 Mar 2015 12:11:37 -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 dxncdsk5pRUo; Tue, 24 Mar 2015 12:11:36 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 8EBBA17C21A; Tue, 24 Mar 2015 12:10:58 -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 A72A217C12F for ; Tue, 24 Mar 2015 12:10:54 -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 JcqECcvYvnwC for ; Tue, 24 Mar 2015 12:10:49 -0400 (EDT) Received: from seldrel01.sonyericsson.com (seldrel01.sonyericsson.com [212.209.106.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id A3CE317C0B8 for ; Tue, 24 Mar 2015 12:10:42 -0400 (EDT) From: Mikael Kanstrup To: Subject: [PATCH 2/5] wpa_cli: Keep track of available networks Date: Tue, 24 Mar 2015 17:10:37 +0100 Message-ID: <1427213440-31040-2-git-send-email-mikael.kanstrup@sonymobile.com> X-Mailer: git-send-email 1.8.2.2 In-Reply-To: <1427213440-31040-1-git-send-email-mikael.kanstrup@sonymobile.com> References: <1427213440-31040-1-git-send-email-mikael.kanstrup@sonymobile.com> MIME-Version: 1.0 X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 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 Keep track of available networks for easy use in command completion routines Signed-off-by: Mikael Kanstrup --- wpa_supplicant/wpa_cli.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index 73fc592..fa943af 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -92,6 +92,7 @@ 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 DEFINE_DL_LIST(ifnames); /* struct cli_txt_entry */ +static DEFINE_DL_LIST(networks); /* struct cli_txt_entry */ static void print_help(const char *cmd); @@ -99,6 +100,7 @@ static void wpa_cli_mon_receive(int sock, void *eloop_ctx, void *sock_ctx); static void wpa_cli_close_connection(void); static char * wpa_cli_get_default_ifname(void); static char ** wpa_list_cmd_list(void); +static void update_networks(struct wpa_ctrl *ctrl); static void usage(void) @@ -215,6 +217,7 @@ static int cli_txt_list_add_addr(struct dl_list *txt_list, const char *txt) os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr)); return cli_txt_list_add(txt_list, buf); } +#endif /* CONFIG_P2P */ static int cli_txt_list_add_word(struct dl_list *txt_list, const char *txt) @@ -234,7 +237,6 @@ static int cli_txt_list_add_word(struct dl_list *txt_list, const char *txt) os_free(buf); return ret; } -#endif /* CONFIG_P2P */ static char ** cli_txt_list_array(struct dl_list *txt_list) @@ -1455,14 +1457,18 @@ static int wpa_cli_cmd_disable_network(struct wpa_ctrl *ctrl, int argc, static int wpa_cli_cmd_add_network(struct wpa_ctrl *ctrl, int argc, char *argv[]) { - return wpa_ctrl_command(ctrl, "ADD_NETWORK"); + int res = wpa_ctrl_command(ctrl, "ADD_NETWORK"); + update_networks(ctrl); + return res; } static int wpa_cli_cmd_remove_network(struct wpa_ctrl *ctrl, int argc, char *argv[]) { - return wpa_cli_cmd(ctrl, "REMOVE_NETWORK", 1, argc, argv); + int res = wpa_cli_cmd(ctrl, "REMOVE_NETWORK", 1, argc, argv); + update_networks(ctrl); + return res; } @@ -3867,6 +3873,36 @@ static void update_ifnames(struct wpa_ctrl *ctrl) } } +static void update_networks(struct wpa_ctrl *ctrl) +{ + char buf[4096]; + size_t len = sizeof(buf); + int ret; + char *cmd = "LIST_NETWORKS"; + char *pos, *end; + int header = 1; + + cli_txt_list_flush(&networks); + + if (ctrl == NULL) + return; + ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len, NULL); + if (ret < 0) + return; + buf[len] = '\0'; + + pos = buf; + while (pos) { + end = os_strchr(pos, '\n'); + if (end == NULL) + break; + *end = '\0'; + if (!header) + cli_txt_list_add_word(&networks, pos); + header = 0; + pos = end + 1; + } +} static void try_connection(void *eloop_ctx, void *timeout_ctx) { @@ -3888,6 +3924,7 @@ static void try_connection(void *eloop_ctx, void *timeout_ctx) } update_bssid_list(ctrl_conn); + update_networks(ctrl_conn); if (warning_displayed) printf("Connection established.\n");