From patchwork Wed Oct 12 12:18:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Kanstrup X-Patchwork-Id: 681148 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3svCcB1tz0z9s9c for ; Wed, 12 Oct 2016 23:20:10 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1buIVo-0002Op-UX; Wed, 12 Oct 2016 12:19:56 +0000 Received: from seldsegrel01.sonyericsson.com ([37.139.156.29]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1buIVj-0002GC-Ir for hostap@lists.infradead.org; Wed, 12 Oct 2016 12:19:52 +0000 From: Mikael Kanstrup To: Subject: [PATCH 05/10] hostapd_cli: Refresh stations list on control interface reconnect Date: Wed, 12 Oct 2016 14:18:56 +0200 Message-ID: <20161012121901.444-6-mikael.kanstrup@sonymobile.com> X-Mailer: git-send-email 2.9.0.137.gcf4c2cf In-Reply-To: <20161012121901.444-1-mikael.kanstrup@sonymobile.com> References: <20161012121901.444-1-mikael.kanstrup@sonymobile.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161012_051951_834257_F2C084CE X-CRM114-Status: UNSURE ( 8.85 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [37.139.156.29 listed in wl.mailspike.net] -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [37.139.156.29 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Whenever reconnecting the control interface the hostapd station list is unknown as stations might have dropped or connected. Refresh the list of stations used for command completion on cli connect, reconnect and interface change. Signed-off-by: Mikael Kanstrup --- hostapd/hostapd_cli.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c index 1d8ba7a..9317fdc 100644 --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -717,7 +717,7 @@ static int hostapd_cli_cmd_get_config(struct wpa_ctrl *ctrl, int argc, static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, char *cmd, - char *addr, size_t addr_len) + char *addr, size_t addr_len, int print) { char buf[4096], *pos; size_t len; @@ -741,7 +741,8 @@ static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, char *cmd, buf[len] = '\0'; if (memcmp(buf, "FAIL", 4) == 0) return -1; - printf("%s", buf); + if (print) + printf("%s", buf); pos = buf; while (*pos != '\0' && *pos != '\n') @@ -757,11 +758,11 @@ static int hostapd_cli_cmd_all_sta(struct wpa_ctrl *ctrl, int argc, { char addr[32], cmd[64]; - if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr))) + if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 1)) return 0; do { snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr); - } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr)) == 0); + } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 1) == 0); return -1; } @@ -903,6 +904,25 @@ static int hostapd_cli_cmd_level(struct wpa_ctrl *ctrl, int argc, char *argv[]) } +static void update_stations(struct wpa_ctrl *ctrl) +{ + char addr[32], cmd[64]; + + if (!ctrl || !interactive) + return; + + cli_txt_list_flush(&stations); + + if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 0)) + return; + do { + if (os_strcmp(addr, "")) + cli_txt_list_add(&stations, addr); + snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr); + } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 0) == 0); +} + + static void hostapd_cli_get_interfaces(struct wpa_ctrl *ctrl, struct dl_list *interfaces) { @@ -967,6 +987,7 @@ static int hostapd_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc, if (wpa_ctrl_attach(ctrl_conn) == 0) { hostapd_cli_attached = 1; register_event_handler(ctrl_conn); + update_stations(ctrl_conn); } else { printf("Warning: Failed to attach to " "hostapd.\n"); @@ -1526,6 +1547,7 @@ static void hostapd_cli_ping(void *eloop_ctx, void *timeout_ctx) if (wpa_ctrl_attach(ctrl_conn) == 0) { hostapd_cli_attached = 1; register_event_handler(ctrl_conn); + update_stations(ctrl_conn); } else { printf("Warning: Failed to attach to " "hostapd.\n"); @@ -1805,6 +1827,7 @@ int main(int argc, char *argv[]) if (wpa_ctrl_attach(ctrl_conn) == 0) { hostapd_cli_attached = 1; register_event_handler(ctrl_conn); + update_stations(ctrl_conn); } else { printf("Warning: Failed to attach to hostapd.\n"); if (action_file)