From patchwork Tue Oct 18 18:32:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13010923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1692C4332F for ; Tue, 18 Oct 2022 18:32:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230121AbiJRSc4 (ORCPT ); Tue, 18 Oct 2022 14:32:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230108AbiJRScz (ORCPT ); Tue, 18 Oct 2022 14:32:55 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 885C192F4D; Tue, 18 Oct 2022 11:32:53 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 2CC1F20003; Tue, 18 Oct 2022 18:32:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1666117970; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fcNlh4YYDUmBXasaCeDeHRaIml7estVWt8prgBYpz1U=; b=Ub3RBnjTIhZr0Zz4XjuW8OHzU9qVLvT3ers+VuTa9uy2gXGFdKX7lR85r1EzxtsiToOcdx v6cuGICM+ork4sD4Fq9qUU2oxxbC8f+xKd67HvlCr/CYKGiN28ip2XvQ67tLQtXtReJ1Ib KFTl6LsNJqOm9mhmp4QN1lJ6gM5QOMQKenhS0ZE6uUUlqWAF7Fb+C4Xof0x/6HFHVT1zTT +WKlt4dZV6yEhD1Qk+MJUd0G862AVPBeB4ol6A9mNtzaBa7dnmoJNK3LTye9gd27Kbe0qH wjiN/nvSe5P2llG9JP+pClUtbr+6SCN/F7vfxuWp/+57uTcPEyntFSMiSvpb2A== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , netdev@vger.kernel.org, David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan-next 1/2] ieee802154: hwsim: Introduce a helper to update all the PIB attributes Date: Tue, 18 Oct 2022 20:32:46 +0200 Message-Id: <20221018183247.806108-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org Perform the update of the PIB structure only in a single place. This way we can have much simpler functions when updating the page, channel or address filters. This helper will become even more useful when we will update the ->set_promiscuous() callback to actually save the filtering level in the PIB structure. Signed-off-by: Miquel Raynal --- drivers/net/ieee802154/mac802154_hwsim.c | 66 +++++++++++++----------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c index 1db7da3ccc1a..44dbd5f27dc5 100644 --- a/drivers/net/ieee802154/mac802154_hwsim.c +++ b/drivers/net/ieee802154/mac802154_hwsim.c @@ -90,46 +90,20 @@ static int hwsim_hw_ed(struct ieee802154_hw *hw, u8 *level) return 0; } -static int hwsim_hw_channel(struct ieee802154_hw *hw, u8 page, u8 channel) +static int hwsim_update_pib(struct ieee802154_hw *hw, u8 page, u8 channel, + struct ieee802154_hw_addr_filt *filt) { struct hwsim_phy *phy = hw->priv; struct hwsim_pib *pib, *pib_old; - pib = kzalloc(sizeof(*pib), GFP_KERNEL); + pib = kzalloc(sizeof(*pib), GFP_ATOMIC); if (!pib) return -ENOMEM; + pib_old = rtnl_dereference(phy->pib); + pib->page = page; pib->channel = channel; - - pib_old = rtnl_dereference(phy->pib); - - pib->filt.short_addr = pib_old->filt.short_addr; - pib->filt.pan_id = pib_old->filt.pan_id; - pib->filt.ieee_addr = pib_old->filt.ieee_addr; - pib->filt.pan_coord = pib_old->filt.pan_coord; - - rcu_assign_pointer(phy->pib, pib); - kfree_rcu(pib_old, rcu); - return 0; -} - -static int hwsim_hw_addr_filt(struct ieee802154_hw *hw, - struct ieee802154_hw_addr_filt *filt, - unsigned long changed) -{ - struct hwsim_phy *phy = hw->priv; - struct hwsim_pib *pib, *pib_old; - - pib = kzalloc(sizeof(*pib), GFP_KERNEL); - if (!pib) - return -ENOMEM; - - pib_old = rtnl_dereference(phy->pib); - - pib->page = pib_old->page; - pib->channel = pib_old->channel; - pib->filt.short_addr = filt->short_addr; pib->filt.pan_id = filt->pan_id; pib->filt.ieee_addr = filt->ieee_addr; @@ -140,6 +114,36 @@ static int hwsim_hw_addr_filt(struct ieee802154_hw *hw, return 0; } +static int hwsim_hw_channel(struct ieee802154_hw *hw, u8 page, u8 channel) +{ + struct hwsim_phy *phy = hw->priv; + struct hwsim_pib *pib; + int ret; + + rcu_read_lock(); + pib = rcu_dereference(phy->pib); + ret = hwsim_update_pib(hw, page, channel, &pib->filt); + rcu_read_unlock(); + + return ret; +} + +static int hwsim_hw_addr_filt(struct ieee802154_hw *hw, + struct ieee802154_hw_addr_filt *filt, + unsigned long changed) +{ + struct hwsim_phy *phy = hw->priv; + struct hwsim_pib *pib; + int ret; + + rcu_read_lock(); + pib = rcu_dereference(phy->pib); + ret = hwsim_update_pib(hw, pib->page, pib->channel, filt); + rcu_read_unlock(); + + return ret; +} + static void hwsim_hw_receive(struct ieee802154_hw *hw, struct sk_buff *skb, u8 lqi) { From patchwork Tue Oct 18 18:32:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13010924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E722CC4332F for ; Tue, 18 Oct 2022 18:33:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230153AbiJRSc6 (ORCPT ); Tue, 18 Oct 2022 14:32:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230109AbiJRSc5 (ORCPT ); Tue, 18 Oct 2022 14:32:57 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90E3690817; Tue, 18 Oct 2022 11:32:55 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id E1D2720005; Tue, 18 Oct 2022 18:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1666117972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XFEjhfGI7zVY3yb93JDUDXRMNuuwpASEFUI1ft70yyk=; b=e3D4tyZ5oPxJyn/hsYFh16QZNgUP/TgQUK9CTVcFF6ryPES2DdCTMDwnzJcZw4GXQWu6pb RiCDqjIx+6IDahHnwmsf8FXOsiNVpH56uGJvE4J4GVPF2JBMx/MZoZsS/qaAsTfLLGy2uj hFTY8ZWlt/iMybRAm2a2GkGV+G6I1FL64SHTfODjbi2lGkUeRBBvwqbF0wEMa4pwvYldsR fuTmCZZIaYKXAvUi8PkSRwFwonHEuUdb5MoBRN871LPkBJApJ/uWdORE/XjlXyVys4mN7v rliYTDkLkDs8v8eDXAyOVQPQ8CoB5HdT3LYblBS+Tl1DG1P4Sa3xCiJWCUUeyw== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , netdev@vger.kernel.org, David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan-next 2/2] ieee802154: hwsim: Save the current filtering level and use it Date: Tue, 18 Oct 2022 20:32:47 +0200 Message-Id: <20221018183247.806108-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221018183247.806108-1-miquel.raynal@bootlin.com> References: <20221018183247.806108-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org Save the requested filtering level in the ->set_promiscuous() helper. The logic is: either we want to enable promiscuous mode and we want to disable filters entirely, or we want to use the highest filtering level by default. This is of course an assumption that only works today, but if in the future intermediate levels (such as scan filtering level) are implemented in the core, this logic will need to be updated. This would imply replacing ->set_promiscuous() by something more fine grained anyway, so we are probably safe with this assumption. Once saved in the PIB structure, we can use this value instead of trying to access the PHY structure to know what hardware filtering level has been advertised. Suggested-by: Alexander Aring Signed-off-by: Miquel Raynal --- drivers/net/ieee802154/mac802154_hwsim.c | 28 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c index 44dbd5f27dc5..9034706d4a53 100644 --- a/drivers/net/ieee802154/mac802154_hwsim.c +++ b/drivers/net/ieee802154/mac802154_hwsim.c @@ -49,6 +49,7 @@ struct hwsim_pib { u8 page; u8 channel; struct ieee802154_hw_addr_filt filt; + enum ieee802154_filtering_level filt_level; struct rcu_head rcu; }; @@ -91,7 +92,8 @@ static int hwsim_hw_ed(struct ieee802154_hw *hw, u8 *level) } static int hwsim_update_pib(struct ieee802154_hw *hw, u8 page, u8 channel, - struct ieee802154_hw_addr_filt *filt) + struct ieee802154_hw_addr_filt *filt, + enum ieee802154_filtering_level filt_level) { struct hwsim_phy *phy = hw->priv; struct hwsim_pib *pib, *pib_old; @@ -108,6 +110,7 @@ static int hwsim_update_pib(struct ieee802154_hw *hw, u8 page, u8 channel, pib->filt.pan_id = filt->pan_id; pib->filt.ieee_addr = filt->ieee_addr; pib->filt.pan_coord = filt->pan_coord; + pib->filt_level = filt_level; rcu_assign_pointer(phy->pib, pib); kfree_rcu(pib_old, rcu); @@ -122,7 +125,7 @@ static int hwsim_hw_channel(struct ieee802154_hw *hw, u8 page, u8 channel) rcu_read_lock(); pib = rcu_dereference(phy->pib); - ret = hwsim_update_pib(hw, page, channel, &pib->filt); + ret = hwsim_update_pib(hw, page, channel, &pib->filt, pib->filt_level); rcu_read_unlock(); return ret; @@ -138,7 +141,7 @@ static int hwsim_hw_addr_filt(struct ieee802154_hw *hw, rcu_read_lock(); pib = rcu_dereference(phy->pib); - ret = hwsim_update_pib(hw, pib->page, pib->channel, filt); + ret = hwsim_update_pib(hw, pib->page, pib->channel, filt, pib->filt_level); rcu_read_unlock(); return ret; @@ -162,7 +165,7 @@ static void hwsim_hw_receive(struct ieee802154_hw *hw, struct sk_buff *skb, memcpy(&hdr, skb->data, 3); /* Level 4 filtering: Frame fields validity */ - if (hw->phy->filtering == IEEE802154_FILTERING_4_FRAME_FIELDS) { + if (pib->filt_level == IEEE802154_FILTERING_4_FRAME_FIELDS) { /* a) Drop reserved frame types */ switch (mac_cb(skb)->type) { case IEEE802154_FC_TYPE_BEACON: @@ -305,7 +308,22 @@ static void hwsim_hw_stop(struct ieee802154_hw *hw) static int hwsim_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on) { - return 0; + enum ieee802154_filtering_level filt_level; + struct hwsim_phy *phy = hw->priv; + struct hwsim_pib *pib; + int ret; + + if (on) + filt_level = IEEE802154_FILTERING_NONE; + else + filt_level = IEEE802154_FILTERING_4_FRAME_FIELDS; + + rcu_read_lock(); + pib = rcu_dereference(phy->pib); + ret = hwsim_update_pib(hw, pib->page, pib->channel, &pib->filt, filt_level); + rcu_read_unlock(); + + return ret; } static const struct ieee802154_ops hwsim_ops = {