From patchwork Sun Jan 24 14:18:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ircama X-Patchwork-Id: 1430909 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=KhJnSDZS; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=tiscali.it header.i=@tiscali.it header.a=rsa-sha256 header.s=smtp header.b=Wd1CsqFp; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DNwBt2dZ2z9sSs for ; Mon, 25 Jan 2021 01:20:38 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:References:To:From:Subject:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xyvxhiOpwHazXhy7Dw5vEAM2AS9wcIFp3IB0A5ydQWA=; b=KhJnSDZSSEFZRQMaD5JPGu1iR miJl/0nss7nZgmWiMIOjUxme/TiuqqlGFLxZtkALivtiyPcU6R2cqN6jCyXNaFCvXXDLhvfCyhvbA IG/YchI0sSqmDSHTTHXneqEMH223fSaxysDXZ8AO4H6bJhhLl2g6eWicPUiJmfKr8AKKmBVzKTaeB stht3EZ4HShED+fJbD9HzGXl7mQ3GVKYNxPPBgmD7fbM+A4w0W4Ge6PTPqqO7zn0hGhbyTg5vskDZ grz4JVJl6KoKKS4rxAElAMmXvZg4dqrnTYOYZ/KP+2A36SSmvPSpmCKEZias/of920kCl948CePo8 4vUq7a0DQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l3gDx-0001pi-Hu; Sun, 24 Jan 2021 14:18:41 +0000 Received: from michael-notr.mail.tiscali.it ([213.205.33.216] helo=smtp.tiscali.it) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l3gDs-0001ob-Hb for hostap@lists.infradead.org; Sun, 24 Jan 2021 14:18:38 +0000 Received: from [192.168.1.6] ([79.17.174.141]) by michael.mail.tiscali.it with id LeJN2401A33QcRr01eJPgo; Sun, 24 Jan 2021 14:18:25 +0000 X-Spam-Final-Verdict: clean X-Spam-State: 0 X-Spam-Score: 0 X-Spam-Verdict: clean x-auth-user: amacri@tiscali.it Subject: [PATCH] Adding p2p_device_random_mac_addr=2 to manage device drivers that create random MAC addresses From: =?utf-8?q?Macr=C3=AC_Alberto?= To: hostap@lists.infradead.org References: <05cf4e6b-51a0-4e31-ce10-0d3b36753a3d@tiscali.it> Message-ID: <8d17db13-0100-ffd8-b65f-379e7fddcb5a@tiscali.it> Date: Sun, 24 Jan 2021 15:18:22 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tiscali.it; s=smtp; t=1611497905; bh=1Cxgu4FM3MVxudpUWDfI6HryYFBP7E7siT4kJq1Gq8M=; h=Subject:From:To:References:Date:In-Reply-To; b=Wd1CsqFp0Y0EfkSbdJv/IJ/DobtezZLBr43RWGdnHgK3upCXqbDyZ05JIU1sHv6Rp k9kPOXwEd4PmEf3A4m2Pjhiw5TkHqcQr6gZsIz49ANeQXo+vQ8an2aYSGcGAbcoV0P DxXt1ujMRU4pUluyXtoJUcsPoAOSmPpc8LDKHcI4= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210124_091836_989922_10DC35D3 X-CRM114-Status: GOOD ( 24.48 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [213.205.33.216 listed in wl.mailspike.net] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [213.205.33.216 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [amacri[at]tiscali.it] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.29 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 Adding option 2 to the "p2p_device_random_mac_addr" configuration option in order to support device drivers which use by default random MAC adresses when creating a new P2P Device interface (for instance, the BCM2711 80211 wireless device driver included in Raspberry Pi 4 Model B); in such case, this option allows to create the P2P Device interface correctly when using P2P permanent groups, enabling wpa_supplicant to reuse the same MAC address when re-invoking a P2P permanent group. update_config=1 is required. Some notes and the patch itself follow. Adding also it in attachment. Regards Alberto ---------------- NOTES p2p_device_random_mac_addr=0 This is the default option and uses permanent MAC address (the one set by default by the device driver). Notice that, if the device driver is configured to always use random MAC adresses, this flag breaks reinvoking a persistent group, so flags 1 or 2 should be used instead. p2p_device_random_mac_addr=1 This option uses random MAC address on creating the interface if there is no persistent group. Besides, if a persistent group is created, p2p_device_persistent_mac_addr is set to the MAC address of the P2P Device interface, so that this address will be subsequently used to change the MAC address of the P2P Device interface. With no persistent group, the random MAC address is created by wpa_supplicant, changing the one set by the device driver. The device driver shall support SIOCGIFFLAGS/SIOCSIFFLAGS ioctl interface control operations. p2p_device_random_mac_addr=2 This flag should be used when the device driver uses random MAC addresses by default when a P2P Device interface is created. If p2p_device_persistent_mac_addr is set, use this MAC address on creating the P2P Device interface. If not set, use the default method adopted by the device driver (e.g., random MAC address). Besides, if a persistent group is created, p2p_device_persistent_mac_addr is set to the MAC address of the P2P Device interface, so that this address will be subsequently used in place of the default address set by the device driver. (This option does not need support of SIOCGIFFLAGS/SIOCSIFFLAGS ioctl interface control operations and uses NL80211_ATTR_MAC). Signed-off-by: Ircama > ---  src/drivers/driver_nl80211.c    |  9 +++++++++  wpa_supplicant/config.h         | 25 +++++++++++++++++++++++--  wpa_supplicant/p2p_supplicant.c | 17 ++++++++++++++++-  3 files changed, 48 insertions(+), 3 deletions(-)                wpa_s->ifname); @@ -3991,7 +3992,12 @@ int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s,      ifname[IFNAMSIZ - 1] = '\0';      force_name[0] = '\0';      wpa_s->pending_interface_type = WPA_IF_P2P_DEVICE; -    ret = wpa_drv_if_add(wpa_s, WPA_IF_P2P_DEVICE, ifname, NULL, NULL, + +    if (wpa_s->conf->p2p_device_random_mac_addr == 2 && + !is_zero_ether_addr(wpa_s->conf->p2p_device_persistent_mac_addr)) +        if_addr = wpa_s->conf->p2p_device_persistent_mac_addr; + +    ret = wpa_drv_if_add(wpa_s, WPA_IF_P2P_DEVICE, ifname, if_addr, NULL,                   force_name, wpa_s->pending_interface_addr, NULL);      if (ret < 0) {          wpa_printf(MSG_DEBUG, "P2P: Failed to create P2P Device interface"); @@ -4568,6 +4574,15 @@ int wpas_p2p_mac_setup(struct wpa_supplicant *wpa_s)      if (wpa_s->conf->p2p_device_random_mac_addr == 0)          return 0; +    if (wpa_s->conf->p2p_device_random_mac_addr == 2) { +        if (is_zero_ether_addr(wpa_s->conf->p2p_device_persistent_mac_addr) && +            !is_zero_ether_addr(wpa_s->own_addr)) { + os_memcpy(wpa_s->conf->p2p_device_persistent_mac_addr, +                  wpa_s->own_addr, ETH_ALEN); +        } +        return 0; +    } +      if (!wpa_s->conf->ssid) {          if (random_mac_addr(addr) < 0) {              wpa_msg(wpa_s, MSG_INFO, diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index 13ecd11d3..1eb65f9e7 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -5242,6 +5242,15 @@ static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,      if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))          goto fail; +    if (addr && (iftype == NL80211_IFTYPE_P2P_DEVICE)) { +        if(nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { +            wpa_printf(MSG_ERROR, "Failed to set MAC address " MACSTR +                   " to P2P Device interface %s: %d (%s)", +                   MAC2STR(addr), ifname, ret, strerror(-ret)); +            goto fail; +        } +    } +      ret = send_and_recv_msgs(drv, msg, handler, arg, NULL, NULL);      msg = NULL;      if (ret) { diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h index 611b99318..09a802a52 100644 --- a/wpa_supplicant/config.h +++ b/wpa_supplicant/config.h @@ -1554,9 +1554,30 @@ struct wpa_config {      /**       * p2p_device_random_mac_addr - P2P Device MAC address policy default       * -     * 0 = use permanent MAC address +     * 0 = use permanent MAC address (the one set by default by the device +     *     driver). Notice that, if the device driver is configured to +     *     always use random MAC adresses, this flag breaks reinvoking a +     *     persistent group, so flags 1 or 2 should be used instead.       * 1 = use random MAC address on creating the interface if there is no -     * persistent groups. +     *     persistent group. Besides, if a persistent group is created, +     *     p2p_device_persistent_mac_addr is set to the MAC address of the +     *     P2P Device interface, so that this address will be subsequently +     *     used to change the MAC address of the P2P Device interface. With +     *     no persistent group, the random MAC address is created by +     *     wpa_supplicant, changing the one set by the device driver. +     *     The device driver shall support SIOCGIFFLAGS/SIOCSIFFLAGS ioctl +     *     interface control operations. +     * 2 = this flag should be used when the device driver uses random MAC +     *     addresses by default when a P2P Device interface is created. +     *     If p2p_device_persistent_mac_addr is set, use this MAC address +     *     on creating the P2P Device interface. If not set, use the +     *     default method adopted by the device driver (e.g., random MAC +     *     address). Besides, if a persistent group is created, +     *     p2p_device_persistent_mac_addr is set to the MAC address of the +     *     P2P Device interface, so that this address will be subsequently +     *     used in place of the default address set by the device driver. +     *     (This option does not need support of SIOCGIFFLAGS/SIOCSIFFLAGS +     *     ioctl interface control operations and uses NL80211_ATTR_MAC).       *       * By default, permanent MAC address is used.       */ diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index a1eaaf128..6f27e6cc3 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -3980,6 +3980,7 @@ int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s,      char ifname[100];      char force_name[100];      int ret; +    const u8 *if_addr = NULL;      ret = os_snprintf(ifname, sizeof(ifname), P2P_MGMT_DEVICE_PREFIX "%s",