From patchwork Mon Sep 5 20:34:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 12966525 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 58795ECAAD5 for ; Mon, 5 Sep 2022 20:34:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232113AbiIEUeY (ORCPT ); Mon, 5 Sep 2022 16:34:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230216AbiIEUeW (ORCPT ); Mon, 5 Sep 2022 16:34:22 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13F4C2EF; Mon, 5 Sep 2022 13:34:20 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 81398FF802; Mon, 5 Sep 2022 20:34:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1662410059; 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=7MK4V10vbFBI3AVz/S5EIiJ3u8faPmx5sl9OTZrAey8=; b=cNImhS9jhci2cRFZUbPEPWaVKVjqULevcEuuoIMZ8u6ezqkLUs7XLu5wxul7FMWUQCtR3c h34VAWe1+Kf+nRO3IXXDOs5S09LEYdbEpG5O/BB5Ctp+uA0ELKCDvGAmvFtK27pyroG/0n 0rWW5zDq6/cEEd7TJnq2/DxAp4SYctw6qV7tUcPUHd9CGUlujGPHVLpEK/WpKrzNqiLr3h +Rm2SQSkDRwUYAjaG41sc5/TfdwqSDmuL8jb6vODtVsoqdDrFjIjdsxJpYXEGIFr/k8+vn RuVy3J9mR9u6ZIyoNCnHp0dMQkz9YVVVaNOYPLNuWlk7/0DvkpBCoiYHQGHvtg== 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 , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan/next v3 1/9] net: mac802154: Introduce filtering levels Date: Mon, 5 Sep 2022 22:34:04 +0200 Message-Id: <20220905203412.1322947-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905203412.1322947-1-miquel.raynal@bootlin.com> References: <20220905203412.1322947-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org The 802154 specification details several filtering levels in which the PHY and the MAC could be. The amount of filtering will vary if they are in promiscuous mode or in scanning mode. Otherwise they are expected to do some very basic checks, such as enforcing the frame validity. Either the PHY is able to do so, and the MAC has nothing to do, or the PHY has a lower filtering level than expected and the MAC should take over. For now we just define these levels in an enumeration. In a second time, we will add a per-PHY parameter showing the expected filtering level as well as a per device current filtering level, and will initialize all these fields. In a third time, we will use them to apply more filtering by software when the PHY is limited. Indeed, if the drivers know they cannot reach the requested level of filtering, they will overwrite the "current filtering" parameter so that it reflects what they do. Then, in the core, the expected filtering level will be used to decide whether some additional software processing is needed or not. Signed-off-by: Miquel Raynal --- include/linux/ieee802154.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/linux/ieee802154.h b/include/linux/ieee802154.h index f1f9412b6ac6..0303eb84d596 100644 --- a/include/linux/ieee802154.h +++ b/include/linux/ieee802154.h @@ -276,6 +276,30 @@ enum { IEEE802154_SYSTEM_ERROR = 0xff, }; +/** + * enum ieee802154_filtering_level - Filtering levels applicable to a PHY + * + * @IEEE802154_FILTERING_NONE: No filtering at all, what is received is + * forwarded to the softMAC + * @IEEE802154_FILTERING_1_FCS: First filtering level, frames with an invalid + * FCS should be dropped + * @IEEE802154_FILTERING_2_PROMISCUOUS: Second filtering level, promiscuous + * mode as described in the spec, identical in terms of filtering to the + * level one on PHY side, but at the MAC level the frame should be + * forwarded to the upper layer directly + * @IEEE802154_FILTERING_3_SCAN: Third filtering level, scan related, where + * only beacons must be processed, all remaining traffic gets dropped + * @IEEE802154_FILTERING_4_FRAME_FIELDS: Fourth filtering level actually + * enforcing the validity of the content of the frame with various checks + */ +enum ieee802154_filtering_level { + IEEE802154_FILTERING_NONE, + IEEE802154_FILTERING_1_FCS, + IEEE802154_FILTERING_2_PROMISCUOUS, + IEEE802154_FILTERING_3_SCAN, + IEEE802154_FILTERING_4_FRAME_FIELDS, +}; + /* frame control handling */ #define IEEE802154_FCTL_FTYPE 0x0003 #define IEEE802154_FCTL_ACKREQ 0x0020 From patchwork Mon Sep 5 20:34:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 12966526 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 AF27AC6FA83 for ; Mon, 5 Sep 2022 20:34:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230315AbiIEUe3 (ORCPT ); Mon, 5 Sep 2022 16:34:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232144AbiIEUeZ (ORCPT ); Mon, 5 Sep 2022 16:34:25 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9B90E64; Mon, 5 Sep 2022 13:34:22 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 7AD78FF809; Mon, 5 Sep 2022 20:34:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1662410061; 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=qAhlBTLSk9kODXAxIVraXLcKuNjmfn5Ql30eDQkz2Zk=; b=F7dbBqQeLohlKaxvA16xpkFZwVZp9KWZ7g5fnyLXGiSj6jP9ICw0JBOztE/KACoYlxfgAw 4o187xEuTfSvr0kB/arQI7UlFslljr9e6wcQDfeTyXLkCpymLH519aBBmkmK1Z4szvgNtv q3b5ancPHNR2Pi5+INhdptk8EKqOcWOWGPgYrKDO8ml55G9Y/w9uvDb/rojh1iMCdeZizB H14OlKhTfNDhbVpxv/cNj0i1BauPaAD15qN3zJRldhjFop8A+vRhq3T1tpod7NwAjM+myK uboq6LIL5mhog+d/SOOzTGgiC+o2mPdIN8jn+OslyfLGQi/vF3QrD9srHhlOLg== 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 , Thomas Petazzoni , Alexander Aring , Miquel Raynal Subject: [PATCH wpan/next v3 2/9] net: mac802154: move receive parameters above start Date: Mon, 5 Sep 2022 22:34:05 +0200 Message-Id: <20220905203412.1322947-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905203412.1322947-1-miquel.raynal@bootlin.com> References: <20220905203412.1322947-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org From: Alexander Aring This patch moves all receive parameters above the drv_start() functionality to make it accessibile in the drv_start() function. Signed-off-by: Alexander Aring Signed-off-by: Miquel Raynal --- net/mac802154/driver-ops.h | 210 ++++++++++++++++++------------------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/net/mac802154/driver-ops.h b/net/mac802154/driver-ops.h index d23f0db98015..c9d54088a567 100644 --- a/net/mac802154/driver-ops.h +++ b/net/mac802154/driver-ops.h @@ -24,6 +24,111 @@ drv_xmit_sync(struct ieee802154_local *local, struct sk_buff *skb) return local->ops->xmit_sync(&local->hw, skb); } +static inline int drv_set_pan_id(struct ieee802154_local *local, __le16 pan_id) +{ + struct ieee802154_hw_addr_filt filt; + int ret; + + might_sleep(); + + if (!local->ops->set_hw_addr_filt) { + WARN_ON(1); + return -EOPNOTSUPP; + } + + filt.pan_id = pan_id; + + trace_802154_drv_set_pan_id(local, pan_id); + ret = local->ops->set_hw_addr_filt(&local->hw, &filt, + IEEE802154_AFILT_PANID_CHANGED); + trace_802154_drv_return_int(local, ret); + return ret; +} + +static inline int +drv_set_extended_addr(struct ieee802154_local *local, __le64 extended_addr) +{ + struct ieee802154_hw_addr_filt filt; + int ret; + + might_sleep(); + + if (!local->ops->set_hw_addr_filt) { + WARN_ON(1); + return -EOPNOTSUPP; + } + + filt.ieee_addr = extended_addr; + + trace_802154_drv_set_extended_addr(local, extended_addr); + ret = local->ops->set_hw_addr_filt(&local->hw, &filt, + IEEE802154_AFILT_IEEEADDR_CHANGED); + trace_802154_drv_return_int(local, ret); + return ret; +} + +static inline int +drv_set_short_addr(struct ieee802154_local *local, __le16 short_addr) +{ + struct ieee802154_hw_addr_filt filt; + int ret; + + might_sleep(); + + if (!local->ops->set_hw_addr_filt) { + WARN_ON(1); + return -EOPNOTSUPP; + } + + filt.short_addr = short_addr; + + trace_802154_drv_set_short_addr(local, short_addr); + ret = local->ops->set_hw_addr_filt(&local->hw, &filt, + IEEE802154_AFILT_SADDR_CHANGED); + trace_802154_drv_return_int(local, ret); + return ret; +} + +static inline int +drv_set_pan_coord(struct ieee802154_local *local, bool is_coord) +{ + struct ieee802154_hw_addr_filt filt; + int ret; + + might_sleep(); + + if (!local->ops->set_hw_addr_filt) { + WARN_ON(1); + return -EOPNOTSUPP; + } + + filt.pan_coord = is_coord; + + trace_802154_drv_set_pan_coord(local, is_coord); + ret = local->ops->set_hw_addr_filt(&local->hw, &filt, + IEEE802154_AFILT_PANC_CHANGED); + trace_802154_drv_return_int(local, ret); + return ret; +} + +static inline int +drv_set_promiscuous_mode(struct ieee802154_local *local, bool on) +{ + int ret; + + might_sleep(); + + if (!local->ops->set_promiscuous_mode) { + WARN_ON(1); + return -EOPNOTSUPP; + } + + trace_802154_drv_set_promiscuous_mode(local, on); + ret = local->ops->set_promiscuous_mode(&local->hw, on); + trace_802154_drv_return_int(local, ret); + return ret; +} + static inline int drv_start(struct ieee802154_local *local) { int ret; @@ -138,93 +243,6 @@ drv_set_cca_ed_level(struct ieee802154_local *local, s32 mbm) return ret; } -static inline int drv_set_pan_id(struct ieee802154_local *local, __le16 pan_id) -{ - struct ieee802154_hw_addr_filt filt; - int ret; - - might_sleep(); - - if (!local->ops->set_hw_addr_filt) { - WARN_ON(1); - return -EOPNOTSUPP; - } - - filt.pan_id = pan_id; - - trace_802154_drv_set_pan_id(local, pan_id); - ret = local->ops->set_hw_addr_filt(&local->hw, &filt, - IEEE802154_AFILT_PANID_CHANGED); - trace_802154_drv_return_int(local, ret); - return ret; -} - -static inline int -drv_set_extended_addr(struct ieee802154_local *local, __le64 extended_addr) -{ - struct ieee802154_hw_addr_filt filt; - int ret; - - might_sleep(); - - if (!local->ops->set_hw_addr_filt) { - WARN_ON(1); - return -EOPNOTSUPP; - } - - filt.ieee_addr = extended_addr; - - trace_802154_drv_set_extended_addr(local, extended_addr); - ret = local->ops->set_hw_addr_filt(&local->hw, &filt, - IEEE802154_AFILT_IEEEADDR_CHANGED); - trace_802154_drv_return_int(local, ret); - return ret; -} - -static inline int -drv_set_short_addr(struct ieee802154_local *local, __le16 short_addr) -{ - struct ieee802154_hw_addr_filt filt; - int ret; - - might_sleep(); - - if (!local->ops->set_hw_addr_filt) { - WARN_ON(1); - return -EOPNOTSUPP; - } - - filt.short_addr = short_addr; - - trace_802154_drv_set_short_addr(local, short_addr); - ret = local->ops->set_hw_addr_filt(&local->hw, &filt, - IEEE802154_AFILT_SADDR_CHANGED); - trace_802154_drv_return_int(local, ret); - return ret; -} - -static inline int -drv_set_pan_coord(struct ieee802154_local *local, bool is_coord) -{ - struct ieee802154_hw_addr_filt filt; - int ret; - - might_sleep(); - - if (!local->ops->set_hw_addr_filt) { - WARN_ON(1); - return -EOPNOTSUPP; - } - - filt.pan_coord = is_coord; - - trace_802154_drv_set_pan_coord(local, is_coord); - ret = local->ops->set_hw_addr_filt(&local->hw, &filt, - IEEE802154_AFILT_PANC_CHANGED); - trace_802154_drv_return_int(local, ret); - return ret; -} - static inline int drv_set_csma_params(struct ieee802154_local *local, u8 min_be, u8 max_be, u8 max_csma_backoffs) @@ -264,22 +282,4 @@ drv_set_max_frame_retries(struct ieee802154_local *local, s8 max_frame_retries) return ret; } -static inline int -drv_set_promiscuous_mode(struct ieee802154_local *local, bool on) -{ - int ret; - - might_sleep(); - - if (!local->ops->set_promiscuous_mode) { - WARN_ON(1); - return -EOPNOTSUPP; - } - - trace_802154_drv_set_promiscuous_mode(local, on); - ret = local->ops->set_promiscuous_mode(&local->hw, on); - trace_802154_drv_return_int(local, ret); - return ret; -} - #endif /* __MAC802154_DRIVER_OPS */ From patchwork Mon Sep 5 20:34:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 12966527 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 DBA06ECAAD3 for ; Mon, 5 Sep 2022 20:34:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232385AbiIEUeh (ORCPT ); Mon, 5 Sep 2022 16:34:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232206AbiIEUe1 (ORCPT ); Mon, 5 Sep 2022 16:34:27 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F39CE63A9; Mon, 5 Sep 2022 13:34:24 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 6A388FF80B; Mon, 5 Sep 2022 20:34:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1662410063; 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=pCOyVUT9nPRDqNBS6Kq1WeNEeLZAsG/UCFJ9RQuXs1A=; b=Bg7nftqoGZ5MiWnjG9lBQItMPOl5rfnkSqqV63LbWYXdk+lH76J6EL8JD3/ZFGLFZ2Os/4 JNPVmUAwAKfKi0B4qaRcJvMMnD2IbfeZX6wvTqVzD4xPWP9FO0BoSHcjjF789yZHKBRFwg pcVxyUnZvOqhK+lYv4V4t6yMemIK3mLfcjTjWhGfvBVpfdkU4kmY717nbzkG+3oG4bxN9E L80KEWUs5AaVNyHR0uSRmeQmYG9kLasRPFkUay+5zL6yIpYYwaFj9B6YbI/9mxkyAjnFwE I18FvyCWbqNjYoAucPiQ/kRZQx5WR7qi0RqkLec+jtj5nvFge7IKkEAVVrNFoA== 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 , Thomas Petazzoni , Alexander Aring , Miquel Raynal Subject: [PATCH wpan/next v3 3/9] net: mac802154: set filter at drv_start() Date: Mon, 5 Sep 2022 22:34:06 +0200 Message-Id: <20220905203412.1322947-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905203412.1322947-1-miquel.raynal@bootlin.com> References: <20220905203412.1322947-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org From: Alexander Aring The current filtering level is set on the first interface up on a wpan phy. If we support scan functionality we need to change the filtering level on the fly on an operational phy and switching back again. This patch will move the receive mode parameter e.g. address filter and promiscuous mode to the drv_start() functionality to allow changing the receive mode on an operational phy not on first ifup only. In future this should be handled on driver layer because each hardware has it's own way to enter a specific filtering level. However this should offer to switch to mode IEEE802154_FILTERING_NONE and back to IEEE802154_FILTERING_4_FRAME_FIELDS. Only IEEE802154_FILTERING_4_FRAME_FIELDS and IEEE802154_FILTERING_NONE are somewhat supported by current hardware. All other filtering levels can be supported in future but will end in IEEE802154_FILTERING_NONE as the receive part can kind of "emulate" those receive paths by doing additional filtering routines. Signed-off-by: Alexander Aring Signed-off-by: Miquel Raynal --- include/net/cfg802154.h | 7 +++- net/mac802154/cfg.c | 3 +- net/mac802154/driver-ops.h | 74 +++++++++++++++++++++++++++++++++++- net/mac802154/ieee802154_i.h | 4 ++ net/mac802154/iface.c | 44 ++++++++------------- net/mac802154/rx.c | 7 +++- 6 files changed, 106 insertions(+), 33 deletions(-) diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h index 04b996895fc1..7129b404871e 100644 --- a/include/net/cfg802154.h +++ b/include/net/cfg802154.h @@ -223,6 +223,11 @@ struct wpan_phy { atomic_t hold_txs; wait_queue_head_t sync_txq; + /* Current filtering level on reception. + * Only allowed to be changed if phy is not operational. + */ + enum ieee802154_filtering_level filtering; + char priv[] __aligned(NETDEV_ALIGN); }; @@ -374,8 +379,6 @@ struct wpan_dev { bool lbt; - bool promiscuous_mode; - /* fallback for acknowledgment bit setting */ bool ackreq; }; diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c index 93df24f75572..363d465f816a 100644 --- a/net/mac802154/cfg.c +++ b/net/mac802154/cfg.c @@ -67,7 +67,8 @@ static int ieee802154_resume(struct wpan_phy *wpan_phy) goto wake_up; /* restart hardware */ - ret = drv_start(local); + ret = drv_start(local, local->phy->filtering, + &local->addr_filt); if (ret) return ret; diff --git a/net/mac802154/driver-ops.h b/net/mac802154/driver-ops.h index c9d54088a567..1cace614ba11 100644 --- a/net/mac802154/driver-ops.h +++ b/net/mac802154/driver-ops.h @@ -129,12 +129,84 @@ drv_set_promiscuous_mode(struct ieee802154_local *local, bool on) return ret; } -static inline int drv_start(struct ieee802154_local *local) +static inline int drv_start(struct ieee802154_local *local, + enum ieee802154_filtering_level level, + const struct ieee802154_hw_addr_filt *addr_filt) { int ret; might_sleep(); + /* setup receive mode parameters e.g. address mode */ + if (local->hw.flags & IEEE802154_HW_AFILT) { + ret = drv_set_pan_id(local, addr_filt->pan_id); + if (ret < 0) + return ret; + + ret = drv_set_short_addr(local, addr_filt->short_addr); + if (ret < 0) + return ret; + + ret = drv_set_extended_addr(local, addr_filt->ieee_addr); + if (ret < 0) + return ret; + } + + switch (level) { + case IEEE802154_FILTERING_NONE: + fallthrough; + case IEEE802154_FILTERING_1_FCS: + fallthrough; + case IEEE802154_FILTERING_2_PROMISCUOUS: + /* TODO requires a different receive mode setup e.g. + * at86rf233 hardware. + */ + fallthrough; + case IEEE802154_FILTERING_3_SCAN: + if (local->hw.flags & IEEE802154_HW_PROMISCUOUS) { + ret = drv_set_promiscuous_mode(local, true); + if (ret < 0) + return ret; + } else { + return -EOPNOTSUPP; + } + + /* may requested other filtering but for now + * all hardware can support + * IEEE802154_FILTERING_NONE only which is a kind of + * "compatible" mode we just need to filter more in + * mac802154 receive path. + * + * TODO: move to driver and hardware may return more + * higher level filter if supported. Hardware may + * require also a different order how register are + * set which could currently be buggy, so all receive + * parameter need to be moved to the start() callback + * and let the driver go into the mode before it will + * turn on receive handling. + */ + local->phy->filtering = IEEE802154_FILTERING_NONE; + break; + case IEEE802154_FILTERING_4_FRAME_FIELDS: + /* not error out here for now as if hw doesn't support + * IEEE802154_HW_PROMISCUOUS it's in + * IEEE802154_FILTERING_4_FRAME_FIELDS + * we have only a problem if some user switches and do not + * support IEEE802154_HW_PROMISCUOUS. + */ + if (local->hw.flags & IEEE802154_HW_PROMISCUOUS) { + ret = drv_set_promiscuous_mode(local, false); + if (ret < 0) + return ret; + } + + local->phy->filtering = IEEE802154_FILTERING_4_FRAME_FIELDS; + break; + default: + WARN_ON(1); + return -EINVAL; + } + trace_802154_drv_start(local); local->started = true; smp_mb(); diff --git a/net/mac802154/ieee802154_i.h b/net/mac802154/ieee802154_i.h index 010365a6364e..6c6da0d624e0 100644 --- a/net/mac802154/ieee802154_i.h +++ b/net/mac802154/ieee802154_i.h @@ -26,6 +26,8 @@ struct ieee802154_local { struct ieee802154_hw hw; const struct ieee802154_ops *ops; + /* hardware address filter */ + struct ieee802154_hw_addr_filt addr_filt; /* ieee802154 phy */ struct wpan_phy *phy; @@ -82,6 +84,8 @@ struct ieee802154_sub_if_data { struct ieee802154_local *local; struct net_device *dev; + enum ieee802154_filtering_level required_filtering; + unsigned long state; char name[IFNAMSIZ]; diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c index 500ed1b81250..bf95e710becc 100644 --- a/net/mac802154/iface.c +++ b/net/mac802154/iface.c @@ -147,25 +147,12 @@ static int ieee802154_setup_hw(struct ieee802154_sub_if_data *sdata) struct wpan_dev *wpan_dev = &sdata->wpan_dev; int ret; - if (local->hw.flags & IEEE802154_HW_PROMISCUOUS) { - ret = drv_set_promiscuous_mode(local, - wpan_dev->promiscuous_mode); - if (ret < 0) - return ret; - } + local->phy->filtering = sdata->required_filtering; if (local->hw.flags & IEEE802154_HW_AFILT) { - ret = drv_set_pan_id(local, wpan_dev->pan_id); - if (ret < 0) - return ret; - - ret = drv_set_extended_addr(local, wpan_dev->extended_addr); - if (ret < 0) - return ret; - - ret = drv_set_short_addr(local, wpan_dev->short_addr); - if (ret < 0) - return ret; + local->addr_filt.pan_id = wpan_dev->pan_id; + local->addr_filt.ieee_addr = wpan_dev->extended_addr; + local->addr_filt.short_addr = wpan_dev->short_addr; } if (local->hw.flags & IEEE802154_HW_LBT) { @@ -206,7 +193,8 @@ static int mac802154_slave_open(struct net_device *dev) if (res) goto err; - res = drv_start(local); + res = drv_start(local, local->phy->filtering, + &local->addr_filt); if (res) goto err; } @@ -223,15 +211,16 @@ static int mac802154_slave_open(struct net_device *dev) static int ieee802154_check_mac_settings(struct ieee802154_local *local, - struct wpan_dev *wpan_dev, - struct wpan_dev *nwpan_dev) + struct ieee802154_sub_if_data *sdata, + struct ieee802154_sub_if_data *nsdata) { + struct wpan_dev *nwpan_dev = &nsdata->wpan_dev; + struct wpan_dev *wpan_dev = &sdata->wpan_dev; + ASSERT_RTNL(); - if (local->hw.flags & IEEE802154_HW_PROMISCUOUS) { - if (wpan_dev->promiscuous_mode != nwpan_dev->promiscuous_mode) - return -EBUSY; - } + if (sdata->required_filtering != nsdata->required_filtering) + return -EBUSY; if (local->hw.flags & IEEE802154_HW_AFILT) { if (wpan_dev->pan_id != nwpan_dev->pan_id || @@ -285,8 +274,7 @@ ieee802154_check_concurrent_iface(struct ieee802154_sub_if_data *sdata, /* check all phy mac sublayer settings are the same. * We have only one phy, different values makes trouble. */ - ret = ieee802154_check_mac_settings(local, wpan_dev, - &nsdata->wpan_dev); + ret = ieee802154_check_mac_settings(local, sdata, nsdata); if (ret < 0) return ret; } @@ -586,7 +574,7 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, sdata->dev->priv_destructor = mac802154_wpan_free; sdata->dev->netdev_ops = &mac802154_wpan_ops; sdata->dev->ml_priv = &mac802154_mlme_wpan; - wpan_dev->promiscuous_mode = false; + sdata->required_filtering = IEEE802154_FILTERING_4_FRAME_FIELDS; wpan_dev->header_ops = &ieee802154_header_ops; mutex_init(&sdata->sec_mtx); @@ -600,7 +588,7 @@ ieee802154_setup_sdata(struct ieee802154_sub_if_data *sdata, case NL802154_IFTYPE_MONITOR: sdata->dev->needs_free_netdev = true; sdata->dev->netdev_ops = &mac802154_monitor_ops; - wpan_dev->promiscuous_mode = true; + sdata->required_filtering = IEEE802154_FILTERING_NONE; break; default: BUG(); diff --git a/net/mac802154/rx.c b/net/mac802154/rx.c index c0fd8d0c7f03..369ffd800abf 100644 --- a/net/mac802154/rx.c +++ b/net/mac802154/rx.c @@ -273,7 +273,12 @@ void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb) /* Check if transceiver doesn't validate the checksum. * If not we validate the checksum here. */ - if (local->hw.flags & IEEE802154_HW_RX_DROP_BAD_CKSUM) { + /* TODO do whatever you want here if necessary to filter by + * check on IEEE802154_FILTERING_NONE. And upcomming receive + * path in which state the phy is e.g. scanning. + */ + if (local->hw.flags & IEEE802154_HW_RX_DROP_BAD_CKSUM || + local->phy->filtering == IEEE802154_FILTERING_NONE) { crc = crc_ccitt(0, skb->data, skb->len); if (crc) { rcu_read_unlock(); From patchwork Mon Sep 5 20:34:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 12966530 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 0A395C6FA89 for ; Mon, 5 Sep 2022 20:34:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232416AbiIEUei (ORCPT ); Mon, 5 Sep 2022 16:34:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232224AbiIEUe2 (ORCPT ); Mon, 5 Sep 2022 16:34:28 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49C85AE50; Mon, 5 Sep 2022 13:34:26 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 5A978FF80C; Mon, 5 Sep 2022 20:34:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1662410064; 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=qOwEBqWSFv6kqHl05QgPEGEPciYgTjI5729Ojch0GuU=; b=QB6eeuRDk0sSZfz7s8136xKWV7pJvOIif/bw71LWA1nJaqPx3GWttL+Zhmp1LJ3FbPWJwq 1KsxtYa18fuS6ZMqIpmYIJimjs6dv4lSky4hKBO2yf+4EYIf0rhPZ8Pb0lXia2ORxXo5jT 89+sTSgL1PFVQG5yOt59j5kDD2dXohpHrIjOiD37z03k2O3tBwHcoVk5XOxr/VPOcpVDgE c3thoffn2j8YR1xcCjgEJsocnnNYcXr2UH5ZfjwWbh4A9lPqfO0sml2gVL+IYb/y0UGt7L YzpREsMxli5tvqoUl1SHi343dPfQcqDN29z8axMx/uwnZmSQsnkY/hlIbKziVA== 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 , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan/next v3 4/9] net: mac802154: Don't limit the FILTER_NONE level to monitors Date: Mon, 5 Sep 2022 22:34:07 +0200 Message-Id: <20220905203412.1322947-5-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905203412.1322947-1-miquel.raynal@bootlin.com> References: <20220905203412.1322947-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org Historically, only monitors were using promiscuous mode and this promiscuous mode was not the one from the spec but actually implied no filtering at all (sniffers). Now that we have a more fine grained approach, we can ensure all interfaces which would be expecting no filter at all could get it without being a monitor interface. Having this in place will allow us to clarify the additional software checks compared to the hardware capabilities. Signed-off-by: Miquel Raynal --- net/mac802154/rx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/mac802154/rx.c b/net/mac802154/rx.c index 369ffd800abf..26df79911f3e 100644 --- a/net/mac802154/rx.c +++ b/net/mac802154/rx.c @@ -205,10 +205,10 @@ __ieee802154_rx_handle_packet(struct ieee802154_local *local, } list_for_each_entry_rcu(sdata, &local->interfaces, list) { - if (sdata->wpan_dev.iftype != NL802154_IFTYPE_NODE) + if (!ieee802154_sdata_running(sdata)) continue; - if (!ieee802154_sdata_running(sdata)) + if (sdata->required_filtering == IEEE802154_FILTERING_NONE) continue; ieee802154_subif_frame(sdata, skb, &hdr); @@ -231,10 +231,10 @@ ieee802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb) skb->protocol = htons(ETH_P_IEEE802154); list_for_each_entry_rcu(sdata, &local->interfaces, list) { - if (sdata->wpan_dev.iftype != NL802154_IFTYPE_MONITOR) + if (!ieee802154_sdata_running(sdata)) continue; - if (!ieee802154_sdata_running(sdata)) + if (sdata->required_filtering > IEEE802154_FILTERING_NONE) continue; skb2 = skb_clone(skb, GFP_ATOMIC); From patchwork Mon Sep 5 20:34:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 12966528 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 59744C6FA8B for ; Mon, 5 Sep 2022 20:34:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230216AbiIEUek (ORCPT ); Mon, 5 Sep 2022 16:34:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232144AbiIEUeb (ORCPT ); Mon, 5 Sep 2022 16:34:31 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3207ABC9D; Mon, 5 Sep 2022 13:34:27 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 0E7D4FF80D; Mon, 5 Sep 2022 20:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1662410066; 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=/e293u4SAALQGFw2YMCR7A1y/RTvMly0aNfu43ICJMU=; b=JGxS9e1pyjStB26Q+drkPY9ybTCC7nsoW4GtESNzWqYc09ifNlsheHQJwX6pQFiw0NxGYZ sev7D/bDHXD/ZCnWh+VNufECACvWGT7w6P5Nu3mYtEqvoxM1sqYurc/k8Op0RV+PAsAIY3 3nVdGSWXYX0P7D15TVstonrwFGpQsGKT8FauOebXBeORM37NpulEnlO9YT55Lict1zMrAK MejU4UijXbqLOpRKay3gqeCB7XM7FsPMwkCdoxsXcyqaYHkEeeqAmrfabc5fzlMmE6+LaO UVmfLi4/j/4PUASjpYeUWbStdGEKVevsCuh+9RSeNZQmVuYNWrqirPeKPmqJnQ== 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 , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan/next v3 5/9] net: mac802154: Drop IEEE802154_HW_RX_DROP_BAD_CKSUM Date: Mon, 5 Sep 2022 22:34:08 +0200 Message-Id: <20220905203412.1322947-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905203412.1322947-1-miquel.raynal@bootlin.com> References: <20220905203412.1322947-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org This IEEE802154_HW_RX_DROP_BAD_CKSUM flag was only used by hwsim to reflect the fact that it would not validate the checksum (FCS). In other words, the filtering level of hwsim is always "NONE" while the core expects it to be higher. Now that we have access to real filtering levels, we can actually use them and always enforce the "NONE" level in hwsim. This case is already correctly handled in the receive so we can drop the flag. Signed-off-by: Miquel Raynal --- drivers/net/ieee802154/mac802154_hwsim.c | 3 ++- include/net/mac802154.h | 4 ---- net/mac802154/rx.c | 7 ++----- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c index 38c217bd7c82..d18a1391b61f 100644 --- a/drivers/net/ieee802154/mac802154_hwsim.c +++ b/drivers/net/ieee802154/mac802154_hwsim.c @@ -148,6 +148,7 @@ static int hwsim_hw_start(struct ieee802154_hw *hw) struct hwsim_phy *phy = hw->priv; phy->suspended = false; + hw->phy->filtering = IEEE802154_FILTERING_NONE; return 0; } @@ -791,7 +792,7 @@ static int hwsim_add_one(struct genl_info *info, struct device *dev, phy->idx = idx; INIT_LIST_HEAD(&phy->edges); - hw->flags = IEEE802154_HW_PROMISCUOUS | IEEE802154_HW_RX_DROP_BAD_CKSUM; + hw->flags = IEEE802154_HW_PROMISCUOUS; hw->parent = dev; err = ieee802154_register_hw(hw); diff --git a/include/net/mac802154.h b/include/net/mac802154.h index 357d25ef627a..4a3a9de9da73 100644 --- a/include/net/mac802154.h +++ b/include/net/mac802154.h @@ -111,9 +111,6 @@ struct ieee802154_hw { * promiscuous mode setting. * * @IEEE802154_HW_RX_OMIT_CKSUM: Indicates that receiver omits FCS. - * - * @IEEE802154_HW_RX_DROP_BAD_CKSUM: Indicates that receiver will not filter - * frames with bad checksum. */ enum ieee802154_hw_flags { IEEE802154_HW_TX_OMIT_CKSUM = BIT(0), @@ -123,7 +120,6 @@ enum ieee802154_hw_flags { IEEE802154_HW_AFILT = BIT(4), IEEE802154_HW_PROMISCUOUS = BIT(5), IEEE802154_HW_RX_OMIT_CKSUM = BIT(6), - IEEE802154_HW_RX_DROP_BAD_CKSUM = BIT(7), }; /* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */ diff --git a/net/mac802154/rx.c b/net/mac802154/rx.c index 26df79911f3e..bd1a92fceef7 100644 --- a/net/mac802154/rx.c +++ b/net/mac802154/rx.c @@ -270,15 +270,12 @@ void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb) ieee802154_monitors_rx(local, skb); - /* Check if transceiver doesn't validate the checksum. - * If not we validate the checksum here. - */ + /* Level 1 filtering: Check the FCS by software when relevant */ /* TODO do whatever you want here if necessary to filter by * check on IEEE802154_FILTERING_NONE. And upcomming receive * path in which state the phy is e.g. scanning. */ - if (local->hw.flags & IEEE802154_HW_RX_DROP_BAD_CKSUM || - local->phy->filtering == IEEE802154_FILTERING_NONE) { + if (local->hw.phy->filtering == IEEE802154_FILTERING_NONE) { crc = crc_ccitt(0, skb->data, skb->len); if (crc) { rcu_read_unlock(); From patchwork Mon Sep 5 20:34:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 12966529 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 93A12ECAAD5 for ; Mon, 5 Sep 2022 20:34:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232261AbiIEUej (ORCPT ); Mon, 5 Sep 2022 16:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232262AbiIEUeb (ORCPT ); Mon, 5 Sep 2022 16:34:31 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA4F963C4; Mon, 5 Sep 2022 13:34:29 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id D5137FF80E; Mon, 5 Sep 2022 20:34:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1662410068; 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=DNNdmI66tnHE7JkGyA+dXRGyooXsRfbcjOPzeUejA5I=; b=h0cqncYmilzr5paY0ZE6NPApkSALeLXbc0w5jQ/rcEPWvcEifrnvjs3jWhGrxHnGWIkPzi FOGaqnDH/2cxjb2l3Tg1KtBxcJrwaShwZIZ6HCfPZ8yC/TcFazbVCfAP8kNtblcR8dsIFF 7gysXOC5ZDOM087RUUNI3ZBa8KPTKA5wLHjsOVP2uqJnNGydKZKcm4Tqat6KlzH3Y5np0o u6iVTulB2Fsu8dPoNfcaCKkAUTMr/nNxlPIlGK4kIb6pGiFkoQ2Td9ayDZDRGbHyPeUXdm CFsJ0H4upvxUQa0F2ZfNUQsrWjENmJDJXyKeOoH6MIASFGE+pqTY1S3kY/zSWg== 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 , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan/next v3 6/9] net: mac802154: Add promiscuous software filtering Date: Mon, 5 Sep 2022 22:34:09 +0200 Message-Id: <20220905203412.1322947-7-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905203412.1322947-1-miquel.raynal@bootlin.com> References: <20220905203412.1322947-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org Currently, the promiscuous mode was not as open as it should. It was not a big deal because until now promiscuous modes were only used on monitor interfaces, which would never go this far in the filtering. But as we might now use this promiscuous mode with NODEs or COORDs, it becomes necessary to really forward the packets to the upper layers without additional filtering when relevant. Let's add the necessary logic to handle this situation. Signed-off-by: Miquel Raynal --- net/mac802154/rx.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/net/mac802154/rx.c b/net/mac802154/rx.c index bd1a92fceef7..8a8c5a4a2f28 100644 --- a/net/mac802154/rx.c +++ b/net/mac802154/rx.c @@ -196,10 +196,31 @@ __ieee802154_rx_handle_packet(struct ieee802154_local *local, int ret; struct ieee802154_sub_if_data *sdata; struct ieee802154_hdr hdr; + struct sk_buff *skb2; + /* Level 2 filtering: Avoid further processing in IEEE 802.15.4 promiscuous modes */ + list_for_each_entry_rcu(sdata, &local->interfaces, list) { + if (!ieee802154_sdata_running(sdata)) + continue; + + if (sdata->required_filtering < IEEE802154_FILTERING_1_FCS || + sdata->required_filtering > IEEE802154_FILTERING_2_PROMISCUOUS) + continue; + + skb2 = skb_clone(skb, GFP_ATOMIC); + if (skb2) { + skb2->dev = sdata->dev; + ieee802154_deliver_skb(skb2); + + sdata->dev->stats.rx_packets++; + sdata->dev->stats.rx_bytes += skb->len; + } + } + + /* Common filtering between level 3 and 4: frame headers validity */ ret = ieee802154_parse_frame_start(skb, &hdr); if (ret) { - pr_debug("got invalid frame\n"); + dev_dbg(&sdata->dev->dev, "invalid frame headers\n"); kfree_skb(skb); return; } @@ -208,7 +229,7 @@ __ieee802154_rx_handle_packet(struct ieee802154_local *local, if (!ieee802154_sdata_running(sdata)) continue; - if (sdata->required_filtering == IEEE802154_FILTERING_NONE) + if (sdata->required_filtering <= IEEE802154_FILTERING_2_PROMISCUOUS) continue; ieee802154_subif_frame(sdata, skb, &hdr); From patchwork Mon Sep 5 20:34:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 12966531 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 654BAC6FA8C for ; Mon, 5 Sep 2022 20:34:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232299AbiIEUek (ORCPT ); Mon, 5 Sep 2022 16:34:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232312AbiIEUeh (ORCPT ); Mon, 5 Sep 2022 16:34:37 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5B2E11C14; Mon, 5 Sep 2022 13:34:31 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 716D4FF810; Mon, 5 Sep 2022 20:34:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1662410069; 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=Slc468LkgD295RmgjsCMDnQxSjqHHsk9OAskcoT/osI=; b=mEQCKY4LgagvNOTC2/zUD/oEjt0zguGgI7g78AGr6ycg3BBcnQln/keuViDD9VTDyvZ24P NQwvPK13YthEabDCDH07BzraCQpnGPX3opBnnAqUwFdc9DiM0Qq5DSNOj4qf/DajsTos96 wT24Jh23TyxYRHnlAXXOXCbxL0WnBuPTjS/lXSDUyFCM6/dn16Wcty3vb7V+hsr6Zq4Y4v z2MNKa2qbe1Zu80TNSSeLPXjDFlspmCWTrqNL01us3TwFWqrfbQqN9GP4JGiGFc+uGTG70 h+Y0HCBPcFXC4mNn93/EssTBEKaxycnNrxsYmxhX74I3O1+v62oYp9Mnio0OHQ== 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 , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan/next v3 7/9] net: mac802154: Ensure proper scan-level filtering Date: Mon, 5 Sep 2022 22:34:10 +0200 Message-Id: <20220905203412.1322947-8-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905203412.1322947-1-miquel.raynal@bootlin.com> References: <20220905203412.1322947-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org We now have a fine grained filtering information so let's ensure proper filtering in scan mode, which means that only beacons are processed. Signed-off-by: Miquel Raynal --- net/mac802154/rx.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/mac802154/rx.c b/net/mac802154/rx.c index 8a8c5a4a2f28..c43289c0fdd7 100644 --- a/net/mac802154/rx.c +++ b/net/mac802154/rx.c @@ -34,6 +34,7 @@ ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata, struct sk_buff *skb, const struct ieee802154_hdr *hdr) { struct wpan_dev *wpan_dev = &sdata->wpan_dev; + struct wpan_phy *wpan_phy = sdata->local->hw.phy; __le16 span, sshort; int rc; @@ -42,6 +43,17 @@ ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata, span = wpan_dev->pan_id; sshort = wpan_dev->short_addr; + /* Level 3 filtering: Only beacons are accepted during scans */ + if (sdata->required_filtering == IEEE802154_FILTERING_3_SCAN && + sdata->required_filtering > wpan_phy->filtering) { + if (mac_cb(skb)->type != IEEE802154_FC_TYPE_BEACON) { + dev_dbg(&sdata->dev->dev, + "drop !beacon frame (0x%x) during scan\n", + mac_cb(skb)->type); + goto fail; + } + } + switch (mac_cb(skb)->dest.mode) { case IEEE802154_ADDR_NONE: if (hdr->source.mode != IEEE802154_ADDR_NONE) From patchwork Mon Sep 5 20:34:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 12966532 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 62912C6FA83 for ; Mon, 5 Sep 2022 20:34:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232164AbiIEUel (ORCPT ); Mon, 5 Sep 2022 16:34:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232304AbiIEUeh (ORCPT ); Mon, 5 Sep 2022 16:34:37 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 626B61274C; Mon, 5 Sep 2022 13:34:33 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 0AE70FF806; Mon, 5 Sep 2022 20:34:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1662410071; 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=QbxqkGaHKi0NxH/H0WQJBiuO9z2O2S8Yads0Qpz0QKw=; b=IEnznJlP6m6MD1ueUX+CWufchrzSj58xBil1KfC1Q9WM/sL5G6KtNZoQFUqPufAhP2Exqr YlqSRKpNdTuYpGOPnwBUGeihFT8Xowls9g3ovM2bXtx5MHsacRluCta0vg8uArelzE8BQm VCOyffqBUz3lXM1cspl3ZIBPgrX75vW6iKKArApUdQ9vPTYraq9+M6lZkcltjdyTQPjYz5 7v3pLUOTTEALlztt6C+uji1nY32Wq67dblyLHdZ5vkRAQOK22r12IqtvSFdsn7JgYJLGln 9nwWWRM1bGelgqcSei/8uvbBFfBTF8Yo9w/rQ7kw+LzJH+Ml99OLVLsBe/QLig== 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 , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan/next v3 8/9] net: mac802154: Ensure proper general purpose frame filtering Date: Mon, 5 Sep 2022 22:34:11 +0200 Message-Id: <20220905203412.1322947-9-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905203412.1322947-1-miquel.raynal@bootlin.com> References: <20220905203412.1322947-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org Most of the PHYs seem to cope with the standard filtering rules by default. Some of them might not, like hwsim which is only software, and in this case advertises its real filtering level with the new "filtering" internal value. The core then needs to check what is expected by looking at the PHY requested filtering level and possibly apply additional filtering rules. Signed-off-by: Miquel Raynal --- include/net/ieee802154_netdev.h | 8 ++++ net/mac802154/rx.c | 78 +++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/include/net/ieee802154_netdev.h b/include/net/ieee802154_netdev.h index d0d188c3294b..1b82bbafe8c7 100644 --- a/include/net/ieee802154_netdev.h +++ b/include/net/ieee802154_netdev.h @@ -69,6 +69,14 @@ struct ieee802154_hdr_fc { #endif }; +enum ieee802154_frame_version { + IEEE802154_2003_STD, + IEEE802154_2006_STD, + IEEE802154_STD, + IEEE802154_RESERVED_STD, + IEEE802154_MULTIPURPOSE_STD = IEEE802154_2003_STD, +}; + struct ieee802154_hdr { struct ieee802154_hdr_fc fc; u8 seq; diff --git a/net/mac802154/rx.c b/net/mac802154/rx.c index c43289c0fdd7..bc46e4a7669d 100644 --- a/net/mac802154/rx.c +++ b/net/mac802154/rx.c @@ -52,6 +52,84 @@ ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata, mac_cb(skb)->type); goto fail; } + } else if (sdata->required_filtering == IEEE802154_FILTERING_4_FRAME_FIELDS && + sdata->required_filtering > wpan_phy->filtering) { + /* Level 4 filtering: Frame fields validity */ + + /* a) Drop reserved frame types */ + switch (mac_cb(skb)->type) { + case IEEE802154_FC_TYPE_BEACON: + case IEEE802154_FC_TYPE_DATA: + case IEEE802154_FC_TYPE_ACK: + case IEEE802154_FC_TYPE_MAC_CMD: + break; + default: + dev_dbg(&sdata->dev->dev, "unrecognized frame type 0x%x\n", + mac_cb(skb)->type); + goto fail; + } + + /* b) Drop reserved frame versions */ + switch (hdr->fc.version) { + case IEEE802154_2003_STD: + case IEEE802154_2006_STD: + case IEEE802154_STD: + break; + default: + dev_dbg(&sdata->dev->dev, + "unrecognized frame version 0x%x\n", + hdr->fc.version); + goto fail; + } + + /* c) PAN ID constraints */ + if ((mac_cb(skb)->dest.mode == IEEE802154_ADDR_LONG || + mac_cb(skb)->dest.mode == IEEE802154_ADDR_SHORT) && + mac_cb(skb)->dest.pan_id != span && + mac_cb(skb)->dest.pan_id != cpu_to_le16(IEEE802154_PANID_BROADCAST)) { + dev_dbg(&sdata->dev->dev, + "unrecognized PAN ID %04x\n", + le16_to_cpu(mac_cb(skb)->dest.pan_id)); + goto fail; + } + + /* d1) Short address constraints */ + if (mac_cb(skb)->dest.mode == IEEE802154_ADDR_SHORT && + mac_cb(skb)->dest.short_addr != sshort && + mac_cb(skb)->dest.short_addr != cpu_to_le16(IEEE802154_ADDR_BROADCAST)) { + dev_dbg(&sdata->dev->dev, + "unrecognized short address %04x\n", + le16_to_cpu(mac_cb(skb)->dest.short_addr)); + goto fail; + } + + /* d2) Extended address constraints */ + if (mac_cb(skb)->dest.mode == IEEE802154_ADDR_LONG && + mac_cb(skb)->dest.extended_addr != wpan_dev->extended_addr) { + dev_dbg(&sdata->dev->dev, + "unrecognized long address 0x%016llx\n", + mac_cb(skb)->dest.extended_addr); + goto fail; + } + + /* d4) Specific PAN coordinator case (no parent) */ + if ((mac_cb(skb)->type == IEEE802154_FC_TYPE_DATA || + mac_cb(skb)->type == IEEE802154_FC_TYPE_MAC_CMD) && + mac_cb(skb)->dest.mode == IEEE802154_ADDR_NONE) { + dev_dbg(&sdata->dev->dev, + "relaying is not supported\n"); + goto fail; + } + } + + /* e) Beacon frames follow specific PAN ID rules */ + if (mac_cb(skb)->type == IEEE802154_FC_TYPE_BEACON && + span != cpu_to_le16(IEEE802154_PANID_BROADCAST) && + mac_cb(skb)->dest.pan_id != span) { + dev_dbg(&sdata->dev->dev, + "invalid beacon PAN ID %04x\n", + le16_to_cpu(mac_cb(skb)->dest.pan_id)); + goto fail; } switch (mac_cb(skb)->dest.mode) { From patchwork Mon Sep 5 20:34:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 12966533 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 2409DECAAD3 for ; Mon, 5 Sep 2022 20:34:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231958AbiIEUer (ORCPT ); Mon, 5 Sep 2022 16:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232411AbiIEUei (ORCPT ); Mon, 5 Sep 2022 16:34:38 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC74912D37; Mon, 5 Sep 2022 13:34:34 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id BFDDBFF809; Mon, 5 Sep 2022 20:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1662410073; 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=mZKlFR7u8gogbm+qAE1RDrSenefC4AOY9IMlFnB/ekA=; b=QttuPNS7Ri3mqoAhBpR6UahSQorD5vkevf/N0yUG/5WwdbSfOOnDxNfWH4X1voGQt3Jbqi aWqDQ+j6CmjplxvjqhsHZ8Qqu9unU6/Iqo3iCyi4RKn4lZcyL8uQ3uyvZsIZR6gzvRhc07 z5cm6HOdGMH0Z3N5x2XXv8JLQnJqEvUjTQZujvJaaNtkAW3gmAMPCFy4fI3/Lzz22tGCVs wbYU+RdkQ9fk6LeyuCD61gXBYOJEv16JR73uFuqGL5C68k7dQi9O4J00Re6N9CdRgOV0tA 1snt8bauGROyxVLorKgVoN0uY2PMsDrlm8R+G3TQU5FzHpoNRwkrJ86SU77HZg== 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 , Thomas Petazzoni , Alexander Aring , Miquel Raynal Subject: [PATCH wpan/next v3 9/9] ieee802154: atusb: add support for trac feature Date: Mon, 5 Sep 2022 22:34:12 +0200 Message-Id: <20220905203412.1322947-10-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220905203412.1322947-1-miquel.raynal@bootlin.com> References: <20220905203412.1322947-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org From: Alexander Aring This patch adds support for reading the trac register if atusb firmware reports tx done. There is currently a feature to compare a sequence number, if the payload is 1 it tells the driver only the sequence number is available if it's two there is additional the trac status register as payload. Currently the atusb_in_good() function determines if it's a tx done or rx done if according the payload length. This patch is doing the same and assumes this behaviour. Signed-off-by: Alexander Aring Signed-off-by: Miquel Raynal --- drivers/net/ieee802154/atusb.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/drivers/net/ieee802154/atusb.c b/drivers/net/ieee802154/atusb.c index 2c338783893d..95a4a3cdc8a4 100644 --- a/drivers/net/ieee802154/atusb.c +++ b/drivers/net/ieee802154/atusb.c @@ -191,7 +191,7 @@ static void atusb_work_urbs(struct work_struct *work) /* ----- Asynchronous USB -------------------------------------------------- */ -static void atusb_tx_done(struct atusb *atusb, u8 seq) +static void atusb_tx_done(struct atusb *atusb, u8 seq, int reason) { struct usb_device *usb_dev = atusb->usb_dev; u8 expect = atusb->tx_ack_seq; @@ -199,7 +199,10 @@ static void atusb_tx_done(struct atusb *atusb, u8 seq) dev_dbg(&usb_dev->dev, "%s (0x%02x/0x%02x)\n", __func__, seq, expect); if (seq == expect) { /* TODO check for ifs handling in firmware */ - ieee802154_xmit_complete(atusb->hw, atusb->tx_skb, false); + if (reason == IEEE802154_SUCCESS) + ieee802154_xmit_complete(atusb->hw, atusb->tx_skb, false); + else + ieee802154_xmit_error(atusb->hw, atusb->tx_skb, reason); } else { /* TODO I experience this case when atusb has a tx complete * irq before probing, we should fix the firmware it's an @@ -215,7 +218,8 @@ static void atusb_in_good(struct urb *urb) struct usb_device *usb_dev = urb->dev; struct sk_buff *skb = urb->context; struct atusb *atusb = SKB_ATUSB(skb); - u8 len, lqi; + int result = IEEE802154_SUCCESS; + u8 len, lqi, trac; if (!urb->actual_length) { dev_dbg(&usb_dev->dev, "atusb_in: zero-sized URB ?\n"); @@ -224,8 +228,27 @@ static void atusb_in_good(struct urb *urb) len = *skb->data; - if (urb->actual_length == 1) { - atusb_tx_done(atusb, len); + switch (urb->actual_length) { + case 2: + trac = TRAC_MASK(*(skb->data + 1)); + switch (trac) { + case TRAC_SUCCESS: + case TRAC_SUCCESS_DATA_PENDING: + /* already IEEE802154_SUCCESS */ + break; + case TRAC_CHANNEL_ACCESS_FAILURE: + result = IEEE802154_CHANNEL_ACCESS_FAILURE; + break; + case TRAC_NO_ACK: + result = IEEE802154_NO_ACK; + break; + default: + result = IEEE802154_SYSTEM_ERROR; + } + + fallthrough; + case 1: + atusb_tx_done(atusb, len, result); return; }