From patchwork Fri Feb 26 09:38:18 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: 588715 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 78D30140271 for ; Fri, 26 Feb 2016 20:39:58 +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=YdZxl6vq; 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 1aZEry-0004Dx-R2; Fri, 26 Feb 2016 09:39:30 +0000 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aZErt-000489-BR for hostap@lists.infradead.org; Fri, 26 Feb 2016 09:39:27 +0000 Received: by mail-wm0-x236.google.com with SMTP id a4so62187747wme.1 for ; Fri, 26 Feb 2016 01:39:04 -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=YdZxl6vqqfo7ZGa7zy3UlCqU9N0smX5eP48ho+RqFISPlLfVJ+vEcbMD2K9bH8kSvL Z+jjaT3srwn//MLQMCsH9r/R2DjsNXAvU0gscazlH0CFSXqsU4lQaDTdtNLterKTsFok tJeiWlySaY0eOd1gwbAoejMdsfZFeGt63U+3I= 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=MSTH8liottHfM8QUCoNUskbi+qiix86L83fndPh6meN2SEmxPiO8ntX/v52qSMJ06w Ah4XRYv0+4Dp4Kiw8IRZ8whIQlYjRy7ItQSKu0O2ZwTZTlXWm6HoCEZui1PtxLriSuhA 9MO0VOjexBqcpnw4O5gZ8mksbwu2lDI4T6B2C2COkrycWMWIf+ONmc7C/RVUsj4gi3oV KECM//IlJc8oLiHwo3AVW9afwfop3NsqrupzRa++x2yDkdtjoBZGkYIuV4rPbS+t9uTy pZ6ieE+TLHL9so1bSVJc7yLpNhX8fovlRyhN/hoYvrW+7oIW5p+qEW9rA1zR8iMjmBFo tisw== X-Gm-Message-State: AD7BkJJo1gHa/N0Am0Vury5b+OmF5RFPoF1bUDbQ8VYQ+j7b4KAsKvPGgHNcDBPHYmPqYGTNlI/4MRZOJDLmaZfrKQVh//mnsO2QDbhNqTwCRdBWhPToHUI2YXkkqYFNDAx0NjLPJKyau57T4C4H+BeKJpHxLY2CcCyklzwvhNxZS/enHczfUHejKyoVKOnWuCP3 X-Received: by 10.194.121.99 with SMTP id lj3mr709087wjb.55.1456479542876; Fri, 26 Feb 2016 01:39:02 -0800 (PST) Received: from dell6430.guest.wifi ([91.198.246.8]) by smtp.gmail.com with ESMTPSA id z65sm1915950wmg.1.2016.02.26.01.39.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Feb 2016 01:39:02 -0800 (PST) From: Janusz Dziedzic To: hostap@lists.infradead.org Subject: [PATCH v4 03/29] wpa_supplicant: add monitor support for global ctrl UDP iface Date: Fri, 26 Feb 2016 10:38:18 +0100 Message-Id: <1456479524-14185-4-git-send-email-janusz.dziedzic@tieto.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456479524-14185-1-git-send-email-janusz.dziedzic@tieto.com> References: <1456479524-14185-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-20160226_013925_639980_29D15950 X-CRM114-Status: GOOD ( 12.63 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -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 Message has at least one valid DKIM or DK signature -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 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); }