From patchwork Wed Feb 17 12:14:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz.Dziedzic@tieto.com X-Patchwork-Id: 584097 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 2EB57140082 for ; Wed, 17 Feb 2016 23:15:51 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=tieto.com header.i=@tieto.com header.b=qWxCWiPA; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aW10m-0007xn-8I; Wed, 17 Feb 2016 12:15:16 +0000 Received: from mail-lb0-x230.google.com ([2a00:1450:4010:c04::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aW10c-0006yB-KC for hostap@lists.infradead.org; Wed, 17 Feb 2016 12:15:09 +0000 Received: by mail-lb0-x230.google.com with SMTP id x1so8231039lbj.3 for ; Wed, 17 Feb 2016 04:14:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tieto.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cWGie0uFZYHuSpEOP/qkEL+QP3XIR/gxbSFc7MYB2zM=; b=qWxCWiPAmjmVhx6DL8rQ/jaSrmgGi7GjiXEAI2sM3rdtrz+OYmjeE/J5jKLlvnjSnc LsTvrEIwzYKCzesfm/YWzSBa/D2iJDplp7jRU5T83z14sXdIBgieMcpzPabZySj+BPGr E8b4BEEKzHrrMAj1NmZMJ8gISM7ICsO4XH+RQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cWGie0uFZYHuSpEOP/qkEL+QP3XIR/gxbSFc7MYB2zM=; b=jNfrMF6D6Ut8E8N/ptsCdk6LKCFj+TiEt7y+Ci/7+/uqPMsEme55t+Z85SvjuUaIzG btxtmT+hstkw6tAhLewWFSs7oiqURxqO2bLB4S5FC0VnBHjndcBsZuGxsyGu7YbxrRAH t9NNFNUBWYH33pf4aUDA774EvW3riWiewI1kl0gMaZQWnFZbDtXia7QRbEZGMZ/HFHZy sIOxjapKXhWq0B/Pk/4rBSr3o26LH+6YMoN5AdMSlk+/9utbr52GCygE1mFFoVzTcX8s AVw35wvy/yGlsubYnYuGtroLGQ2lOBGmkCTr/bKPbpeIL5Ft8nYld/ZSSRTLiRw14z5n 7yUw== X-Gm-Message-State: AG10YORdPp1CIYcFvr5ICpVFOCFZqM7QYaY5Ugh7DSO9BtuWi+vKrxzd3YyEsY2uYMg8QDVK1Oy7VtDCw9O8vPyvyQsMs39S0YxyMUhK/1k4vhfuhk1rmNKcHDzAfW/CY9AThjBiKgQX+PjRWBrOod+jQWcU5XhjiAMPlHqEP04bY9TGQzZe8CAjCvauj0nkXGGv X-Received: by 10.112.198.65 with SMTP id ja1mr575100lbc.123.1455711283781; Wed, 17 Feb 2016 04:14:43 -0800 (PST) Received: from dell6430.guest.wifi ([91.198.246.8]) by smtp.gmail.com with ESMTPSA id t5sm169075lbg.15.2016.02.17.04.14.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Feb 2016 04:14:42 -0800 (PST) From: Janusz Dziedzic To: hostap@lists.infradead.org Subject: [PATCH v3 04/26] wpa_supplicant: add monitor support for global ctrl UDP iface Date: Wed, 17 Feb 2016 13:14:07 +0100 Message-Id: <1455711269-12929-5-git-send-email-janusz.dziedzic@tieto.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455711269-12929-1-git-send-email-janusz.dziedzic@tieto.com> References: <1455711269-12929-1-git-send-email-janusz.dziedzic@tieto.com> X-DomainID: tieto.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160217_041506_928935_39BBF73A X-CRM114-Status: GOOD ( 12.77 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:4010:c04:0:0:0:230 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.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: , Cc: j@w1.fi, Janusz Dziedzic MIME-Version: 1.0 Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add monitor support (ATTACH/DETACH) for global ctrl iface and UDP. Signed-off-by: Janusz Dziedzic --- wpa_supplicant/ctrl_iface_udp.c | 64 ++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/wpa_supplicant/ctrl_iface_udp.c b/wpa_supplicant/ctrl_iface_udp.c index d4f378a..8ab8ee8 100644 --- a/wpa_supplicant/ctrl_iface_udp.c +++ b/wpa_supplicant/ctrl_iface_udp.c @@ -49,6 +49,12 @@ struct ctrl_iface_priv { }; +struct ctrl_iface_global_priv { + int sock; + struct wpa_ctrl_dst *ctrl_dst; + u8 cookie[COOKIE_LEN]; +}; + static void wpa_supplicant_ctrl_iface_send(struct wpa_supplicant *wpa_s, const char *ifname, int sock, struct wpa_ctrl_dst **head, @@ -329,8 +335,24 @@ static void wpa_supplicant_ctrl_iface_msg_cb(void *ctx, int level, const char *txt, size_t len) { struct wpa_supplicant *wpa_s = ctx; - if (wpa_s == NULL || wpa_s->ctrl_iface == NULL) + + if (wpa_s == NULL) + return; + + if (type != WPA_MSG_NO_GLOBAL && wpa_s->global->ctrl_iface) { + struct ctrl_iface_global_priv *priv = wpa_s->global->ctrl_iface; + if (priv->ctrl_dst) { + wpa_supplicant_ctrl_iface_send( + wpa_s, + type != WPA_MSG_PER_INTERFACE ? + NULL : wpa_s->ifname, + priv->sock, &priv->ctrl_dst, level, txt, len); + } + } + + if (type == WPA_MSG_ONLY_GLOBAL || wpa_s->ctrl_iface == NULL) return; + wpa_supplicant_ctrl_iface_send(wpa_s, NULL, wpa_s->ctrl_iface->sock, &wpa_s->ctrl_iface->ctrl_dst, level, txt, len); @@ -535,11 +557,6 @@ void wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv) /* Global ctrl_iface */ -struct ctrl_iface_global_priv { - int sock; - u8 cookie[COOKIE_LEN]; -}; - static char * wpa_supplicant_global_get_cookie(struct ctrl_iface_global_priv *priv, @@ -570,7 +587,7 @@ static void wpa_supplicant_global_ctrl_iface_receive(int sock, void *eloop_ctx, int res; struct sockaddr_in from; socklen_t fromlen = sizeof(from); - char *reply; + char *reply = NULL; size_t reply_len; u8 cookie[COOKIE_LEN]; @@ -625,17 +642,32 @@ static void wpa_supplicant_global_ctrl_iface_receive(int sock, void *eloop_ctx, while (*pos == ' ') pos++; - reply = wpa_supplicant_global_ctrl_iface_process(global, pos, - &reply_len); + if (os_strcmp(pos, "ATTACH") == 0) { + if (wpa_supplicant_ctrl_iface_attach(&priv->ctrl_dst, &from, fromlen)) + reply_len = 1; + else + reply_len = 2; + } else if (os_strcmp(pos, "DETACH") == 0) { + if (wpa_supplicant_ctrl_iface_detach(&priv->ctrl_dst, &from, fromlen)) + reply_len = 1; + else + reply_len = 2; + } else { + reply = wpa_supplicant_global_ctrl_iface_process(global, pos, + &reply_len); + } done: if (reply) { sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from, fromlen); os_free(reply); - } else if (reply_len) { + } else if (reply_len == 1) { sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from, fromlen); + } else if (reply_len == 2) { + sendto(sock, "OK\n", 3, 0, (struct sockaddr *) &from, + fromlen); } } @@ -703,6 +735,8 @@ try_again: wpa_supplicant_global_ctrl_iface_receive, global, priv); + wpa_msg_register_cb(wpa_supplicant_ctrl_iface_msg_cb); + return priv; fail: @@ -716,9 +750,19 @@ fail: void wpa_supplicant_global_ctrl_iface_deinit(struct ctrl_iface_global_priv *priv) { + struct wpa_ctrl_dst *dst, *prev; + if (priv->sock >= 0) { eloop_unregister_read_sock(priv->sock); close(priv->sock); } + + dst = priv->ctrl_dst; + while (dst) { + prev = dst; + dst = dst->next; + os_free(prev); + } + os_free(priv); }