From nobody Fri Nov 29 17:34:26 2024 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFC48187856 for ; Wed, 18 Sep 2024 11:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726657850; cv=none; b=o2hTCHEKrcUJtmR329/EZABreVUBEFPjNULf4kncOdd3fgSWPvmIL4VAgt8uBWLbaLMIr8ULz+E7NTp+ywmnyn7pqxvJAPxXyUTOzGUUDoJWOEp2QB65lKQ8UTNjQpksQJ6Ab2ODShC6clP2a4zAWYjHceGGNbXMxKlRfwb/vEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726657850; c=relaxed/simple; bh=KS72d0ZEGRYTFdYR6T+6p1PGNEzCWGqS/6xdjrFeQbg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JU1Z1C3EGcbPxzSXw6caVnbjLvp/+P3+k3CdBxL1Sk+qFAdXQ3Q1qayK7WUzpoI9HmnljqeSvocTnlnXCUnOlMslgoLoLNMLrxsgx1/pnu7uNnHVoLhcDVTRI+xBP5WXcjc9AcZhn8iy6hT17YWD21t995hYJuVfajKbGXMZt78= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sqsZs-0007wg-Fz; Wed, 18 Sep 2024 13:10:32 +0200 Received: from [2a0a:edc0:0:1101:1d::28] (helo=dude02.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sqsZr-008nT7-EV; Wed, 18 Sep 2024 13:10:31 +0200 Received: from localhost ([::1] helo=dude02.red.stw.pengutronix.de) by dude02.red.stw.pengutronix.de with esmtp (Exim 4.96) (envelope-from ) id 1sqsZr-0086AC-15; Wed, 18 Sep 2024 13:10:31 +0200 From: Sascha Hauer Date: Wed, 18 Sep 2024 13:10:27 +0200 Subject: [PATCH v2 02/12] wifi: mwifiex: fix MAC address handling Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240918-mwifiex-cleanup-1-v2-2-2d0597187d3c@pengutronix.de> References: <20240918-mwifiex-cleanup-1-v2-0-2d0597187d3c@pengutronix.de> In-Reply-To: <20240918-mwifiex-cleanup-1-v2-0-2d0597187d3c@pengutronix.de> To: Brian Norris , Francesco Dolcini , Kalle Valo Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, David Lin , kernel@pengutronix.de, Sascha Hauer , stable@vger.kernel.org X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1726657831; l=7233; i=s.hauer@pengutronix.de; s=20230412; h=from:subject:message-id; bh=KS72d0ZEGRYTFdYR6T+6p1PGNEzCWGqS/6xdjrFeQbg=; b=gZ96CbXVT+4f6VwoTrDd7s6hde/FcpMy3U/smM0KXjAHd5TA7XVHXRxHeQO1g5x32cwbKTXGx Fex7gX2o9ohCqF1NC6uoMnw3pWNHIqoCmZfY49cj3ZRrTKuapDx0urO X-Developer-Key: i=s.hauer@pengutronix.de; a=ed25519; pk=4kuc9ocmECiBJKWxYgqyhtZOHj5AWi7+d0n/UjhkwTg= X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: s.hauer@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org The mwifiex driver tries to derive the MAC addresses of the virtual interfaces from the permanent address by adding the bss_num of the particular interface used. It does so each time the virtual interface is changed from AP to station or the other way round. This means that the devices MAC address changes during a change_virtual_intf call which is pretty unexpected by userspace. Furthermore the driver doesn't use the permanent address to add the bss_num to, but instead the current MAC address increases each time we do a change_virtual_intf. Fix this by initializing the MAC address once from the permanent MAC address during creation of the virtual interface and never touch it again. This also means that userspace can set a different MAC address which then stays like this forever and is not unexpectedly changed by the driver. It is not clear how many (if any) MAC addresses after the permanent MAC address are reserved for a device, so set the locally admistered bit for all MAC addresses derived from the permanent address. With this patch MWIFIEX_BSS_TYPE_ANY becomes unused, so it's removed. Signed-off-by: Sascha Hauer Cc: stable@vger.kernel.org --- drivers/net/wireless/marvell/mwifiex/cfg80211.c | 4 +- drivers/net/wireless/marvell/mwifiex/decl.h | 1 - drivers/net/wireless/marvell/mwifiex/init.c | 1 - drivers/net/wireless/marvell/mwifiex/main.c | 54 ++++++++++++---------= ---- drivers/net/wireless/marvell/mwifiex/main.h | 5 ++- 5 files changed, 30 insertions(+), 35 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/= wireless/marvell/mwifiex/cfg80211.c index 5697a02e6b8d3..d3e1424bea390 100644 --- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c +++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c @@ -962,8 +962,6 @@ mwifiex_init_new_priv_params(struct mwifiex_private *pr= iv, adapter->rx_locked =3D false; spin_unlock_bh(&adapter->rx_proc_lock); =20 - mwifiex_set_mac_address(priv, dev, false, NULL); - return 0; } =20 @@ -3115,7 +3113,7 @@ struct wireless_dev *mwifiex_add_virtual_intf(struct = wiphy *wiphy, priv->netdev =3D dev; =20 if (!adapter->mfg_mode) { - mwifiex_set_mac_address(priv, dev, false, NULL); + mwifiex_set_default_mac_address(priv, dev); =20 ret =3D mwifiex_send_cmd(priv, HostCmd_CMD_SET_BSS_MODE, HostCmd_ACT_GEN_SET, 0, NULL, true); diff --git a/drivers/net/wireless/marvell/mwifiex/decl.h b/drivers/net/wire= less/marvell/mwifiex/decl.h index 84603f1e7f6e0..d84773321dc47 100644 --- a/drivers/net/wireless/marvell/mwifiex/decl.h +++ b/drivers/net/wireless/marvell/mwifiex/decl.h @@ -139,7 +139,6 @@ enum mwifiex_bss_type { MWIFIEX_BSS_TYPE_STA =3D 0, MWIFIEX_BSS_TYPE_UAP =3D 1, MWIFIEX_BSS_TYPE_P2P =3D 2, - MWIFIEX_BSS_TYPE_ANY =3D 0xff, }; =20 enum mwifiex_bss_role { diff --git a/drivers/net/wireless/marvell/mwifiex/init.c b/drivers/net/wire= less/marvell/mwifiex/init.c index 8b61e45cd6678..0259c9f88486b 100644 --- a/drivers/net/wireless/marvell/mwifiex/init.c +++ b/drivers/net/wireless/marvell/mwifiex/init.c @@ -71,7 +71,6 @@ int mwifiex_init_priv(struct mwifiex_private *priv) u32 i; =20 priv->media_connected =3D false; - eth_broadcast_addr(priv->curr_addr); priv->port_open =3D false; priv->usb_port =3D MWIFIEX_USB_EP_DATA; priv->pkt_tx_ctrl =3D 0; diff --git a/drivers/net/wireless/marvell/mwifiex/main.c b/drivers/net/wire= less/marvell/mwifiex/main.c index 96d1f6039fbca..46acddd03ffd1 100644 --- a/drivers/net/wireless/marvell/mwifiex/main.c +++ b/drivers/net/wireless/marvell/mwifiex/main.c @@ -971,34 +971,16 @@ mwifiex_hard_start_xmit(struct sk_buff *skb, struct n= et_device *dev) } =20 int mwifiex_set_mac_address(struct mwifiex_private *priv, - struct net_device *dev, bool external, - u8 *new_mac) + struct net_device *dev, u8 *new_mac) { int ret; - u64 mac_addr, old_mac_addr; + u64 old_mac_addr; =20 - old_mac_addr =3D ether_addr_to_u64(priv->curr_addr); + netdev_info(dev, "%s: old: %pM new: %pM\n", __func__, priv->curr_addr, ne= w_mac); =20 - if (external) { - mac_addr =3D ether_addr_to_u64(new_mac); - } else { - /* Internal mac address change */ - if (priv->bss_type =3D=3D MWIFIEX_BSS_TYPE_ANY) - return -EOPNOTSUPP; - - mac_addr =3D old_mac_addr; - - if (priv->bss_type =3D=3D MWIFIEX_BSS_TYPE_P2P) { - mac_addr |=3D BIT_ULL(MWIFIEX_MAC_LOCAL_ADMIN_BIT); - mac_addr +=3D priv->bss_num; - } else if (priv->adapter->priv[0] !=3D priv) { - /* Set mac address based on bss_type/bss_num */ - mac_addr ^=3D BIT_ULL(priv->bss_type + 8); - mac_addr +=3D priv->bss_num; - } - } + old_mac_addr =3D ether_addr_to_u64(priv->curr_addr); =20 - u64_to_ether_addr(mac_addr, priv->curr_addr); + ether_addr_copy(priv->curr_addr, new_mac); =20 /* Send request to firmware */ ret =3D mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS, @@ -1015,6 +997,26 @@ int mwifiex_set_mac_address(struct mwifiex_private *p= riv, return 0; } =20 +int mwifiex_set_default_mac_address(struct mwifiex_private *priv, + struct net_device *dev) +{ + int priv_num; + u8 mac[ETH_ALEN]; + + ether_addr_copy(mac, priv->adapter->perm_addr); + + for (priv_num =3D 0; priv_num < priv->adapter->priv_num; priv_num++) + if (priv =3D=3D priv->adapter->priv[priv_num]) + break; + + if (priv_num) { + eth_addr_add(mac, priv_num); + mac[0] |=3D 0x2; + } + + return mwifiex_set_mac_address(priv, dev, mac); +} + /* CFG802.11 network device handler for setting MAC address. */ static int @@ -1023,7 +1025,7 @@ mwifiex_ndo_set_mac_address(struct net_device *dev, v= oid *addr) struct mwifiex_private *priv =3D mwifiex_netdev_get_priv(dev); struct sockaddr *hw_addr =3D addr; =20 - return mwifiex_set_mac_address(priv, dev, true, hw_addr->sa_data); + return mwifiex_set_mac_address(priv, dev, hw_addr->sa_data); } =20 /* @@ -1364,10 +1366,6 @@ void mwifiex_init_priv_params(struct mwifiex_private= *priv, priv->assocresp_idx =3D MWIFIEX_AUTO_IDX_MASK; priv->gen_idx =3D MWIFIEX_AUTO_IDX_MASK; priv->num_tx_timeout =3D 0; - if (is_valid_ether_addr(dev->dev_addr)) - ether_addr_copy(priv->curr_addr, dev->dev_addr); - else - ether_addr_copy(priv->curr_addr, priv->adapter->perm_addr); =20 if (GET_BSS_ROLE(priv) =3D=3D MWIFIEX_BSS_ROLE_STA || GET_BSS_ROLE(priv) =3D=3D MWIFIEX_BSS_ROLE_UAP) { diff --git a/drivers/net/wireless/marvell/mwifiex/main.h b/drivers/net/wire= less/marvell/mwifiex/main.h index 529863edd7a25..dc07eb11f7752 100644 --- a/drivers/net/wireless/marvell/mwifiex/main.h +++ b/drivers/net/wireless/marvell/mwifiex/main.h @@ -1694,8 +1694,9 @@ void mwifiex_process_multi_chan_event(struct mwifiex_= private *priv, struct sk_buff *event_skb); void mwifiex_multi_chan_resync(struct mwifiex_adapter *adapter); int mwifiex_set_mac_address(struct mwifiex_private *priv, - struct net_device *dev, - bool external, u8 *new_mac); + struct net_device *dev, u8 *new_mac); +int mwifiex_set_default_mac_address(struct mwifiex_private *priv, + struct net_device *dev); void mwifiex_devdump_tmo_func(unsigned long function_context); =20 #ifdef CONFIG_DEBUG_FS --=20 2.39.5