From patchwork Thu Jul 7 12:04:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Kanstrup X-Patchwork-Id: 645846 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 3rlbtb6lVmz9sXR for ; Thu, 7 Jul 2016 22:05:59 +1000 (AEST) 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 1bL83o-0003Iy-KJ; Thu, 07 Jul 2016 12:05:40 +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 1bL83j-0002tB-82 for hostap@lists.infradead.org; Thu, 07 Jul 2016 12:05:37 +0000 From: Mikael Kanstrup To: Subject: [PATCH 6/9] hostapd_cli: Implement event handler Date: Thu, 7 Jul 2016 14:04:35 +0200 Message-ID: <20160707120438.29740-7-mikael.kanstrup@sonymobile.com> X-Mailer: git-send-email 2.9.0.137.gcf4c2cf In-Reply-To: <20160707120438.29740-1-mikael.kanstrup@sonymobile.com> References: <20160707120438.29740-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-20160707_050535_621199_81634EBA X-CRM114-Status: UNSURE ( 8.83 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [37.139.156.29 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no 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 Add an empty event handler in preparation for additional command completion routines that will need to dynamically build parameters based on events received. Signed-off-by: Mikael Kanstrup --- hostapd/hostapd_cli.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c index 7efe4c0..a13d19c 100644 --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -74,9 +74,11 @@ static const char *pid_file = NULL; static const char *action_file = NULL; static int ping_interval = 5; static int interactive = 0; +static int event_handler_registered = 0; static void print_help(FILE *stream, const char *cmd); static char ** list_cmd_list(void); +static void hostapd_cli_receive(int sock, void *eloop_ctx, void *sock_ctx); static void usage(void) { @@ -129,6 +131,30 @@ static int str_starts(const char *src, const char *match) } +static void register_event_handler(struct wpa_ctrl *ctrl) +{ + if (!ctrl_conn) + return; + if (interactive) { + event_handler_registered = + !eloop_register_read_sock(wpa_ctrl_get_fd(ctrl), + hostapd_cli_receive, + NULL, NULL); + } +} + + +static void unregister_event_handler(struct wpa_ctrl *ctrl) +{ + if (!ctrl_conn) + return; + if (interactive && event_handler_registered) { + eloop_unregister_read_sock(wpa_ctrl_get_fd(ctrl)); + event_handler_registered = 0; + } +} + + static struct wpa_ctrl * hostapd_cli_open_connection(const char *ifname) { #ifndef CONFIG_CTRL_IFACE_UDP @@ -168,6 +194,7 @@ static void hostapd_cli_close_connection(void) if (ctrl_conn == NULL) return; + unregister_event_handler(ctrl_conn); if (hostapd_cli_attached) { wpa_ctrl_detach(ctrl_conn); hostapd_cli_attached = 0; @@ -925,6 +952,7 @@ static void hostapd_cli_list_interfaces(struct wpa_ctrl *ctrl) } + static int hostapd_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc, char *argv[]) { @@ -943,6 +971,7 @@ static int hostapd_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc, printf("Connected to interface '%s.\n", ctrl_ifname); if (wpa_ctrl_attach(ctrl_conn) == 0) { hostapd_cli_attached = 1; + register_event_handler(ctrl_conn); } else { printf("Warning: Failed to attach to " "hostapd.\n"); @@ -1420,6 +1449,11 @@ static void wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[]) } +static void cli_event(const char *str) +{ +} + + static void hostapd_cli_recv_pending(struct wpa_ctrl *ctrl, int in_read, int action_monitor) { @@ -1434,6 +1468,7 @@ static void hostapd_cli_recv_pending(struct wpa_ctrl *ctrl, int in_read, if (action_monitor) hostapd_cli_action_process(buf, len); else { + cli_event(buf); if (in_read && first) printf("\n"); first = 0; @@ -1447,6 +1482,12 @@ static void hostapd_cli_recv_pending(struct wpa_ctrl *ctrl, int in_read, } +static void hostapd_cli_receive(int sock, void *eloop_ctx, void *sock_ctx) +{ + hostapd_cli_recv_pending(ctrl_conn, 0, 0); +} + + #define max_args 10 static int tokenize_cmd(char *cmd, char *argv[]) @@ -1491,6 +1532,7 @@ static void hostapd_cli_ping(void *eloop_ctx, void *timeout_ctx) printf("Connection to hostapd re-established\n"); if (wpa_ctrl_attach(ctrl_conn) == 0) { hostapd_cli_attached = 1; + register_event_handler(ctrl_conn); } else { printf("Warning: Failed to attach to " "hostapd.\n"); @@ -1751,6 +1793,7 @@ int main(int argc, char *argv[]) if (interactive || action_file) { if (wpa_ctrl_attach(ctrl_conn) == 0) { hostapd_cli_attached = 1; + register_event_handler(ctrl_conn); } else { printf("Warning: Failed to attach to hostapd.\n"); if (action_file) @@ -1768,6 +1811,7 @@ int main(int argc, char *argv[]) else wpa_request(ctrl_conn, argc - optind, &argv[optind]); + unregister_event_handler(ctrl_conn); os_free(ctrl_ifname); eloop_destroy(); hostapd_cli_cleanup();