From patchwork Thu Nov 3 01:03:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintao Lin X-Patchwork-Id: 1699003 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ar9WBd9E; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=JoEjea0H; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N37fx0tvnz20KC for ; Fri, 4 Nov 2022 02:56:56 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :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=6czWyNuSXttnR0wI4wtEy8W0a3zSL9KDB/3H+8baFWY=; b=ar9WBd9E9rmvrC LwFOtObJpUgDPa2yrfuXwwFW+javVEAuz7Rs6e0mwJme3UBWIq+qvNS4ep+20A62YuT3kGerms8BW J8PIP21HihjEn6kTmLC8BkkOQRuHmWatuJ049VOb40V18c7R+EsGwt15C0XKZ/C88tz+aaDJhsGZp qIgiTYzGRgux6khXh08dooxBwXC66h1RpgZNcPuTgDzZulUfTwxcf/O1Zcz+pG441sctGX3w3JVkU rSwrdZQvLkuadOaeHk3qr7raM3Zx3Np/ammV+6QdK2XOTsCMhqO9x6g0PuZZpDOo3uN+R8TU/E4f0 CMcec5XOtdJNExJ7qsvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqcZR-000Xhc-Mh; Thu, 03 Nov 2022 15:55:57 +0000 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqOeD-00FTJa-Tb for hostap@lists.infradead.org; Thu, 03 Nov 2022 01:03:59 +0000 Received: by mail-pg1-x534.google.com with SMTP id s196so341934pgs.3 for ; Wed, 02 Nov 2022 18:03:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=08SL9ELMeCTSS2Pr0vUuHBrHt7wktgzPN6K2VhuUg2Y=; b=JoEjea0HDOQDSoCyewKeS0hCN1z0v5OHccRxj6xttnmKb+eS9YcUXQ2PVT/uTIS0tb sbTzEiFaG1oVy1/vRz4YXVscMZes+Q5CS8EaMhUS0Pw4fk9ustnK7Q1aI/pu420grtZv t4+NY+SQkJgci4s66huD/6Y2K/GOAPCnSm1j4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=08SL9ELMeCTSS2Pr0vUuHBrHt7wktgzPN6K2VhuUg2Y=; b=apssRmkrNLj/DCM+tnicx0jp5nO79dnzdYEgFm3e0OUlTfOTA0zhHvCM2Se6NiwRnn TyGrqT/OiwXZIedwvss+GBOr4qRtkJGm0YiXcmybr1qiBiws4TC6qQ2VqJrBaMZX0CPn ntVdcGrUAu4iY9cO35noQm21nBTsIQeVXSHPP8DnJI3P5VXAdYoJnBMsG7R3nEfbJjxp PoLBN93pOFK7We28S7PsS+hoQvqyYKPLpRA7nKkEwBQiXPzWRkT1N9L1CDxdeLcUA5+U a60VlkzqatzDrw0zpXYB10vAwWka/Si98nHE3C2BoECJum+z3LADK+5kOuNd3Q2BwknT 89xA== X-Gm-Message-State: ACrzQf37Ge3hTgws3hVmzpFltzSFYQy1+5j3WLd6m1oyg0Vhh64hqwOO iJ3qbrlSfEoX1hodJ6sTKmD4FA== X-Google-Smtp-Source: AMsMyM4GtdbVtonuTUQHeOSbhA+MNY4LDn2junklPACyVhkozzsSRL6eJJWpGDClqjM/kPAh/DBUqw== X-Received: by 2002:a63:81c6:0:b0:470:905:bc34 with SMTP id t189-20020a6381c6000000b004700905bc34mr4986712pgd.499.1667437430322; Wed, 02 Nov 2022 18:03:50 -0700 (PDT) Received: from jintaolin.c.googlers.com.com (139.60.82.34.bc.googleusercontent.com. [34.82.60.139]) by smtp.gmail.com with ESMTPSA id e10-20020aa798ca000000b0056286c552ecsm8989829pfm.184.2022.11.02.18.03.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 18:03:41 -0700 (PDT) From: Jintao Lin To: j@w1.fi Cc: hostap@lists.infradead.org, matthewmwang@chromium.org, Jintao Lin Subject: [PATCH] CHROMIUM: dbus: Add virtual interface create/remove logic to be inline with ctrl_iface Date: Thu, 3 Nov 2022 01:03:36 +0000 Message-Id: <20221103010336.3459408-1-jintaolin@chromium.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221102_180358_027732_290864B5 X-CRM114-Status: GOOD ( 18.25 ) X-Spam-Score: -0.4 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Signed-off-by: Jintao Lin BUG=b:254714993 TEST=on device, check the interface creation and removal by using dbus command, > gdbus call --system --dest fi.w1.wpa_supplicant1 --object-path /fi/w1/wpa_supplicant1 --method fi.w1.w [...] Content analysis details: (-0.4 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:534 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.2 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-Mailman-Approved-At: Thu, 03 Nov 2022 08:55:52 -0700 X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.34 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 Signed-off-by: Jintao Lin BUG=b:254714993 TEST=on device, check the interface creation and removal by using dbus command, > gdbus call --system --dest fi.w1.wpa_supplicant1 --object-path /fi/w1/wpa_supplicant1 --method fi.w1.wpa_supplicant1.CreateInterface "{'Ifname':<'wlan1'>, 'Driver':<'nl80211'>, 'ConfigFile':<'/usr/lib64/shill/shims/wpa_supplicant.conf'>, 'Create':, 'Type':<'ap'>}" > iwconfig wlan1 > gdbus call --system --dest fi.w1.wpa_supplicant1 --object-path /fi/w1/wpa_supplicant1 --method fi.w1.wpa_supplicant1.RemoveInterface '/fi/w1/wpa_supplicant1/Interfaces/1' > ifconfig -a Change-Id: Idc987db638cdc68fc13fe34d430e212f6ce37e13 --- doc/dbus.doxygen | 2 + wpa_supplicant/dbus/dbus_new_handlers.c | 63 ++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/doc/dbus.doxygen b/doc/dbus.doxygen index 075c2d5bf..b2e267605 100644 --- a/doc/dbus.doxygen +++ b/doc/dbus.doxygen @@ -41,6 +41,8 @@ registered in the bus with fi.w1.wpa_supplicant1 name. BridgeIfnamesName of the bridge interface to control, e.g., br0No DriversDriver name which the interface uses, e.g., nl80211No ConfigFilesConfiguration file pathNo + CreatebWhether to create a new interface in the kernelNo + TypesInterface type to createNo diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index c1f147398..ed27d5d64 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -755,6 +755,10 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message, char *ifname = NULL; char *confname = NULL; char *bridge_ifname = NULL; + char *type = NULL; + bool create_iface = false; + enum wpa_driver_if_type if_type = WPA_IF_STATION; + u8 mac_addr[ETH_ALEN]; dbus_message_iter_init(message, &iter); @@ -791,6 +795,17 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message, wpa_dbus_dict_entry_clear(&entry); if (bridge_ifname == NULL) goto oom; + } else if (os_strcmp(entry.key, "Create") == 0 && + entry.type == DBUS_TYPE_BOOLEAN) { + create_iface = entry.bool_value; + wpa_dbus_dict_entry_clear(&entry); + } else if (os_strcmp(entry.key, "Type") == 0 && + entry.type == DBUS_TYPE_STRING) { + os_free(type); + type = os_strdup(entry.str_value); + wpa_dbus_dict_entry_clear(&entry); + if (type == NULL) + goto oom; } else { wpa_dbus_dict_entry_clear(&entry); goto error; @@ -800,6 +815,26 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message, if (ifname == NULL) goto error; /* Required Ifname argument missing */ + if (create_iface) { + if (os_strcmp(type, "sta") == 0) { + if_type = WPA_IF_STATION; + } else if (os_strcmp(type, "ap") == 0) { + if_type = WPA_IF_AP_BSS; + } else { + goto error; + } + + wpa_printf(MSG_DEBUG, "%s[dbus]: creating an interface '%s'", + __func__, ifname); + if (!global->ifaces || wpa_drv_if_add(global->ifaces, if_type, ifname, + NULL, NULL, NULL, mac_addr, NULL) < 0) { + reply = wpas_dbus_error_unknown_error( + message, + "interface creation failed."); + goto out; + } + } + /* * Try to get the wpa_supplicant record for this iface, return * an error if we already control it. @@ -808,6 +843,7 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message, reply = dbus_message_new_error( message, WPAS_DBUS_ERROR_IFACE_EXISTS, "wpa_supplicant already controls this interface."); + goto fail; } else { struct wpa_supplicant *wpa_s; struct wpa_interface iface; @@ -822,6 +858,7 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message, if (wpa_s && wpa_s->dbus_new_path) { const char *path = wpa_s->dbus_new_path; + wpa_s->added_vif = create_iface; reply = dbus_message_new_method_return(message); dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); @@ -829,6 +866,7 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message, reply = wpas_dbus_error_unknown_error( message, "wpa_supplicant couldn't grab this interface."); + goto fail; } } @@ -837,6 +875,7 @@ out: os_free(ifname); os_free(confname); os_free(bridge_ifname); + os_free(type); return reply; error: @@ -845,6 +884,10 @@ error: oom: reply = wpas_dbus_error_no_memory(message); goto out; +fail: + if (create_iface) + wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, ifname); + goto out; } @@ -865,19 +908,35 @@ DBusMessage * wpas_dbus_handler_remove_interface(DBusMessage *message, struct wpa_supplicant *wpa_s; char *path; DBusMessage *reply = NULL; + unsigned int delete_iface; dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); wpa_s = get_iface_by_dbus_path(global, path); - if (wpa_s == NULL) + if (wpa_s == NULL) { reply = wpas_dbus_error_iface_unknown(message); - else if (wpa_supplicant_remove_iface(global, wpa_s, 0)) { + goto out; + } + delete_iface = wpa_s->added_vif; + if (wpa_supplicant_remove_iface(global, wpa_s, 0)) { reply = wpas_dbus_error_unknown_error( message, "wpa_supplicant couldn't remove this interface."); + goto out; } + if (delete_iface) { + wpa_printf(MSG_DEBUG, "%s[dbus]: deleting the interface '%s'", + __func__, wpa_s->ifname); + if (wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, wpa_s->ifname)) { + reply = wpas_dbus_error_unknown_error( + message, + "wpa_supplicant couldn't delete this interface."); + } + } + +out: return reply; }