From patchwork Thu Jun 8 17:58:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Greear X-Patchwork-Id: 773411 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wkCqt4nVtz9s74 for ; Fri, 9 Jun 2017 03:59:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nmt8j/Zb"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=12w0FxBTwnGn26pN34npAqBngSjNq1TH+jSjxPhrSb0=; b=nmt 8j/Zb7Qq+m7HBE/6Fj/vQSKUlSgLunMt4oAB3WUNb5v/ePVuMHtXwSRskduJu8GxQviY3n2wXPzJB X2ZgTrUUky5QhgHp58A5UXamRgZE4HFoElA9K2+imCAvf4E+8FaqGgn2z5LWb34EVX8sQ26UykRo9 ZJQeJTWNShyZTdz5gQUbINISlB8TxYK+3p2UxYWuOwJLWLdAM+auXhl3n7l76bbFMZBFbaZZW7bDX p6gFhDRuoWs4V8d6e9VsSH71rGX8dT/kGqUzSAGf2i1YJsh8yI8m5NWLG6A42l+xYMIsYroKvPwHe CtMWs/vVsrGBRUKlT3Dj4b+h0IZxfpw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dJ1iL-0000JJ-HA; Thu, 08 Jun 2017 17:59:21 +0000 Received: from mail2.candelatech.com ([208.74.158.173]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dJ1iI-0000Gs-FT for hostap@lists.infradead.org; Thu, 08 Jun 2017 17:59:19 +0000 Received: from v-f24-64.candelatech.com (firewall.candelatech.com [50.251.239.81]) by mail2.candelatech.com (Postfix) with ESMTP id A8F12409E08; Thu, 8 Jun 2017 10:58:56 -0700 (PDT) From: greearb@candelatech.com To: hostap@lists.infradead.org Subject: [PATCH] wpa_cli: Allow reconnect to global interface. Date: Thu, 8 Jun 2017 10:58:54 -0700 Message-Id: <1496944734-18849-1-git-send-email-greearb@candelatech.com> X-Mailer: git-send-email 2.7.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170608_105918_552077_6EEEEFCB X-CRM114-Status: GOOD ( 10.60 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ben Greear MIME-Version: 1.0 Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Ben Greear Old code would just re-connect to a particular interface, even if user had started wpa_cli with the '-g' option. This duplicates some code, but appears to work. Signed-off-by: Ben Greear --- wpa_supplicant/wpa_cli.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index 1680c54..4cdc4fb 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -49,6 +49,7 @@ static int wpa_cli_last_id = 0; static const char *ctrl_iface_dir = CONFIG_CTRL_IFACE_DIR; static const char *client_socket_dir = NULL; static char *ctrl_ifname = NULL; +static char *global = NULL; static const char *pid_file = NULL; static const char *action_file = NULL; static int ping_interval = 5; @@ -3798,16 +3799,52 @@ static void wpa_cli_action_cb(char *msg, size_t len) } #endif /* CONFIG_ANSI_C_EXTRA */ +static void update_ifnames(struct wpa_ctrl *ctrl); static void wpa_cli_reconnect(void) { wpa_cli_close_connection(); - if (wpa_cli_open_connection(ctrl_ifname, 1) < 0) - return; + + if (global) { +#ifdef CONFIG_CTRL_IFACE_NAMED_PIPE + ctrl_conn = wpa_ctrl_open(NULL); +#else /* CONFIG_CTRL_IFACE_NAMED_PIPE */ + ctrl_conn = wpa_ctrl_open(global); +#endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */ + if (ctrl_conn == NULL) { + fprintf(stderr, "Failed to re-connect to wpa_supplicant " + "global interface: %s error: %s\n", + global, strerror(errno)); + return; + } + + if (interactive) { + update_ifnames(ctrl_conn); + mon_conn = wpa_ctrl_open(global); + if (mon_conn) { + if (wpa_ctrl_attach(mon_conn) == 0) { + wpa_cli_attached = 1; + eloop_register_read_sock( + wpa_ctrl_get_fd(mon_conn), + wpa_cli_mon_receive, + NULL, NULL); + } else { + printf("Failed to re-open monitor " + "connection through global " + "control interface\n"); + } + } + } + printf("\rConnection to wpa_supplicant re-established, global: %s\n", global); + } + else { + if (wpa_cli_open_connection(ctrl_ifname, 1) < 0) + return; + printf("\rConnection to wpa_supplicant re-established, ctrl-ifname: %s\n", ctrl_ifname); + } if (interactive) { edit_clear_line(); - printf("\rConnection to wpa_supplicant re-established\n"); edit_redraw(); update_stations(ctrl_conn); } @@ -4327,7 +4364,6 @@ int main(int argc, char *argv[]) int c; int daemonize = 0; int ret = 0; - const char *global = NULL; if (os_program_init()) return -1; @@ -4344,7 +4380,7 @@ int main(int argc, char *argv[]) daemonize = 1; break; case 'g': - global = optarg; + global = os_strdup(optarg); break; case 'G': ping_interval = atoi(optarg);