Skip to contentSkip to conversation

ieee802154: fix checksum and monitor handling

PATCH In review Alexander Aring 2 participants 19 messages Oct 29, 2014

Subsystems (5)
lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

cover ieee802154: fix checksum and monitor handling

This patch series fix checksum and monitor handling. The checksum handling is currently a little bit weird, because all driver drops the checksum while delivering. In monitor mode we want to see the received checksum. This patch series contains various patches to fix the checksum handling and add basic support for real monitor mode with promiscuous mode setting.

The checksum handling is now in some state which should work also for monitor interfaces. There exist a better way to add runtime changeable flags to handle crc calculation via hardware or software. Also flags like if the monitor interface receiving is with or without checksum. This is only to introduce some behaviour which should working.

Alexander Aring (17):
mac802154: main: remove unnecessary include
mac802154: remove tab after define
mac802154: add IEEE802154_HW_ARET hw flag
mac802154: add hardware address filter flag
mac802154: add support for promiscuous mode
at86rf230: add support for promiscuous mode
mac802154: separate omit tx/rx flags
mac802154: rx: remove unnecessary parameter
mac802154: rx: simplify crc receive handling
mac802154: rx: add software checksum filtering check
mac802154: rx: remove override pkt_type set to PACKET_HOST
mac802154: rx: use netif_receive_skb
mac802154: rx: add rx stats incrementation
mac802154: rx: monitor receive cleanup
mac802154: rx: add error handling after skb_clone
at86rf230: deliver with checksum
mac802154: add basic support for monitor

 drivers/net/ieee802154/at86rf230.c | 35 +++++++++++++++++++--
 drivers/net/ieee802154/cc2520.c    |  3 +-
 drivers/net/ieee802154/mrf24j40.c  |  3 +-
 include/net/mac802154.h            | 40 ++++++++++++++++++------
 net/mac802154/driver-ops.h         | 13 ++++++++
 net/mac802154/ieee802154_i.h       |  1 +
 net/mac802154/iface.c              | 12 ++++++-
 net/mac802154/main.c               |  1 -
 net/mac802154/rx.c                 | 64 +++++++++++++++++++++-----------------
 net/mac802154/tx.c                 |  2 +-
 10 files changed, 127 insertions(+), 47 deletions(-)
Signature · 1 line
2.1.2
author maintainer
#1 lore raw

PATCH 1/17 mac802154: main: remove unnecessary include

This patch removes an unnecessary include of driver-ops header file.

---
 net/mac802154/main.c | 1 -
 1 file changed, 1 deletion(-)
net/mac802154/main.c +0 -1
index 21dcc56..86e533e 100644
@@ -28,7 +28,6 @@
 #include <net/cfg802154.h>
 
 #include "ieee802154_i.h"
-#include "driver-ops.h"
 
 static int
 mac802154_netdev_register(struct wpan_phy *phy, struct net_device *dev)
Signature · 1 line
2.1.2
author maintainer
#2 lore raw

PATCH 2/17 mac802154: remove tab after define

In reply to Alexander Aring

This patch removes tabs after define in hardware flags declarations.

---
 include/net/mac802154.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
include/net/mac802154.h +8 -8
index 85a4efc..fe14957 100644
@@ -74,22 +74,22 @@ struct ieee802154_hw {
  */
 
 /* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */
-#define	IEEE802154_HW_OMIT_CKSUM	0x00000001
+#define IEEE802154_HW_OMIT_CKSUM	0x00000001
 /* Indicates that receiver will autorespond with ACK frames. */
-#define	IEEE802154_HW_AACK		0x00000002
+#define IEEE802154_HW_AACK		0x00000002
 /* Indicates that transceiver will support transmit power setting. */
-#define	IEEE802154_HW_TXPOWER		0x00000004
+#define IEEE802154_HW_TXPOWER		0x00000004
 /* Indicates that transceiver will support listen before transmit. */
-#define	IEEE802154_HW_LBT		0x00000008
+#define IEEE802154_HW_LBT		0x00000008
 /* Indicates that transceiver will support cca mode setting. */
-#define	IEEE802154_HW_CCA_MODE		0x00000010
+#define IEEE802154_HW_CCA_MODE		0x00000010
 /* Indicates that transceiver will support cca ed level setting. */
-#define	IEEE802154_HW_CCA_ED_LEVEL	0x00000020
+#define IEEE802154_HW_CCA_ED_LEVEL	0x00000020
 /* Indicates that transceiver will support csma (max_be, min_be, csma retries)
  * settings. */
-#define	IEEE802154_HW_CSMA_PARAMS	0x00000040
+#define IEEE802154_HW_CSMA_PARAMS	0x00000040
 /* Indicates that transceiver will support ARET frame retries setting. */
-#define	IEEE802154_HW_FRAME_RETRIES	0x00000080
+#define IEEE802154_HW_FRAME_RETRIES	0x00000080
 
 /* This groups the most common CSMA support fields into one. */
 #define IEEE802154_HW_CSMA		(IEEE802154_HW_CCA_MODE | \
Signature · 1 line
2.1.2
author maintainer
#3 lore raw

PATCH 3/17 mac802154: add IEEE802154_HW_ARET hw flag

In reply to Alexander Aring

This patch adds a new IEEE802154_HW_ARET hardware flag for indicating that the transceiver supports ARET handling. Also remove the IEEE802154_HW_FRAME_RETRIES from IEEE802154_HW_CSMA flag. Frame retries handling is part of ARET.

---
 drivers/net/ieee802154/at86rf230.c | 2 +-
 include/net/mac802154.h            | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/net/ieee802154/at86rf230.c +1 -1
index b83ad0b..0054588 100644
@@ -1387,7 +1387,7 @@ at86rf230_detect_device(struct at86rf230_local *lp)
 
 	lp->hw->extra_tx_headroom = 0;
 	lp->hw->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK |
-			 IEEE802154_HW_TXPOWER | IEEE802154_HW_CSMA;
+			IEEE802154_HW_TXPOWER | IEEE802154_HW_ARET;
 
 	switch (part) {
 	case 2:
include/net/mac802154.h +4 -1
index fe14957..c5d7938 100644
@@ -94,7 +94,10 @@ struct ieee802154_hw {
 /* This groups the most common CSMA support fields into one. */
 #define IEEE802154_HW_CSMA		(IEEE802154_HW_CCA_MODE | \
 					 IEEE802154_HW_CCA_ED_LEVEL | \
-					 IEEE802154_HW_CSMA_PARAMS | \
+					 IEEE802154_HW_CSMA_PARAMS)
+
+/* This groups the most common ARET support fields into one. */
+#define IEEE802154_HW_ARET		(IEEE802154_HW_CSMA | \
 					 IEEE802154_HW_FRAME_RETRIES)
 
 /* struct ieee802154_ops - callbacks from mac802154 to the driver
Signature · 1 line
2.1.2
author maintainer
#4 lore raw

PATCH 4/17 mac802154: add hardware address filter flag

In reply to Alexander Aring

Overdue introduction for address filtering hardware flag. Furthermore we will check and set address filtering on interface up. This patch prepares that we can check if an transceiver supports address filtering option. Currently all mainline driver supports hardware address filtering.

---
 drivers/net/ieee802154/at86rf230.c | 3 ++-
 drivers/net/ieee802154/cc2520.c    | 3 ++-
 drivers/net/ieee802154/mrf24j40.c  | 3 ++-
 include/net/mac802154.h            | 2 ++
 4 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/ieee802154/at86rf230.c +2 -1
index 0054588..622c1b6 100644
@@ -1387,7 +1387,8 @@ at86rf230_detect_device(struct at86rf230_local *lp)
 
 	lp->hw->extra_tx_headroom = 0;
 	lp->hw->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK |
-			IEEE802154_HW_TXPOWER | IEEE802154_HW_ARET;
+			IEEE802154_HW_TXPOWER | IEEE802154_HW_ARET |
+			IEEE802154_HW_AFILT;
 
 	switch (part) {
 	case 2:
drivers/net/ieee802154/cc2520.c +2 -1
index c56d10c..340671b 100644
@@ -654,7 +654,8 @@ static int cc2520_register(struct cc2520_private *priv)
 
 	/* We do support only 2.4 Ghz */
 	priv->hw->phy->channels_supported[0] = 0x7FFF800;
-	priv->hw->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK;
+	priv->hw->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK |
+			  IEEE802154_HW_AFILT;
 
 	dev_vdbg(&priv->spi->dev, "registered cc2520\n");
 	ret = ieee802154_register_hw(priv->hw);
drivers/net/ieee802154/mrf24j40.c +2 -1
index 52b3d31..a200fa1 100644
@@ -751,7 +751,8 @@ static int mrf24j40_probe(struct spi_device *spi)
 	devrec->hw->priv = devrec;
 	devrec->hw->parent = &devrec->spi->dev;
 	devrec->hw->phy->channels_supported[0] = CHANNEL_MASK;
-	devrec->hw->flags = IEEE802154_HW_OMIT_CKSUM|IEEE802154_HW_AACK;
+	devrec->hw->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK |
+			    IEEE802154_HW_AFILT;
 
 	dev_dbg(printdev(devrec), "registered mrf24j40\n");
 	ret = ieee802154_register_hw(devrec->hw);
include/net/mac802154.h +2 -0
index c5d7938..2f523fc 100644
@@ -90,6 +90,8 @@ struct ieee802154_hw {
 #define IEEE802154_HW_CSMA_PARAMS	0x00000040
 /* Indicates that transceiver will support ARET frame retries setting. */
 #define IEEE802154_HW_FRAME_RETRIES	0x00000080
+/* Indicates that transceiver will support hardware address filter setting. */
+#define IEEE802154_HW_AFILT		0x00000100
 
 /* This groups the most common CSMA support fields into one. */
 #define IEEE802154_HW_CSMA		(IEEE802154_HW_CCA_MODE | \
Signature · 1 line
2.1.2
author maintainer
#5 lore raw

PATCH 5/17 mac802154: add support for promiscuous mode

In reply to Alexander Aring

This patch adds a new driver operation to bring the transceiver into promiscuous mode.

---
 include/net/mac802154.h    |  7 +++++++
 net/mac802154/driver-ops.h | 13 +++++++++++++
 2 files changed, 20 insertions(+)
include/net/mac802154.h +7 -0
index 2f523fc..166ef6c5 100644
@@ -92,6 +92,8 @@ struct ieee802154_hw {
 #define IEEE802154_HW_FRAME_RETRIES	0x00000080
 /* Indicates that transceiver will support hardware address filter setting. */
 #define IEEE802154_HW_AFILT		0x00000100
+/* Indicates that transceiver will support promiscuous mode setting. */
+#define IEEE802154_HW_PROMISCUOUS	0x00000200
 
 /* This groups the most common CSMA support fields into one. */
 #define IEEE802154_HW_CSMA		(IEEE802154_HW_CCA_MODE | \
@@ -173,6 +175,9 @@ struct ieee802154_hw {
  * set_frame_retries
  *	  Sets the retransmission attempt limit. Called with pib_lock held.
  *	  Returns either zero, or negative errno.
+ *
+ * set_promiscuous_mode
+ *	  Enables or disable promiscuous mode.
  */
 struct ieee802154_ops {
 	struct module	*owner;
@@ -197,6 +202,8 @@ struct ieee802154_ops {
 					   u8 min_be, u8 max_be, u8 retries);
 	int		(*set_frame_retries)(struct ieee802154_hw *hw,
 					     s8 retries);
+	int             (*set_promiscuous_mode)(struct ieee802154_hw *hw,
+						const bool on);
 };
 
 /* Basic interface to register ieee802154 hwice */
net/mac802154/driver-ops.h +13 -0
index 4b820cf..dfd29ff 100644
@@ -210,4 +210,17 @@ static inline int drv_set_max_frame_retries(struct ieee802154_local *local,
 	return local->ops->set_frame_retries(&local->hw, max_frame_retries);
 }
 
+static inline int drv_set_promiscuous_mode(struct ieee802154_local *local,
+					   const bool on)
+{
+	might_sleep();
+
+	if (!local->ops->set_promiscuous_mode) {
+		WARN_ON(1);
+		return -EOPNOTSUPP;
+	}
+
+	return local->ops->set_promiscuous_mode(&local->hw, on);
+}
+
 #endif /* __MAC802154_DRVIER_OPS */
Signature · 1 line
2.1.2
author maintainer
#6 lore raw

PATCH 6/17 at86rf230: add support for promiscuous mode

In reply to Alexander Aring

This patch adds support for promiscuous mode setting for the at86rf230 driver.

---
 drivers/net/ieee802154/at86rf230.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
drivers/net/ieee802154/at86rf230.c +29 -1
index 622c1b6..98c9437 100644
@@ -1211,6 +1211,33 @@ at86rf230_set_frame_retries(struct ieee802154_hw *hw, s8 retries)
 	return rc;
 }
 
+static int
+at86rf230_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on)
+{
+	struct at86rf230_local *lp = hw->priv;
+	int rc;
+
+	if (on) {
+		rc = at86rf230_write_subreg(lp, SR_AACK_DIS_ACK, 1);
+		if (rc < 0)
+			return rc;
+
+		rc = at86rf230_write_subreg(lp, SR_AACK_PROM_MODE, 1);
+		if (rc < 0)
+			return rc;
+	} else {
+		rc = at86rf230_write_subreg(lp, SR_AACK_PROM_MODE, 0);
+		if (rc < 0)
+			return rc;
+
+		rc = at86rf230_write_subreg(lp, SR_AACK_DIS_ACK, 0);
+		if (rc < 0)
+			return rc;
+	}
+
+	return 0;
+}
+
 static const struct ieee802154_ops at86rf230_ops = {
 	.owner = THIS_MODULE,
 	.xmit_async = at86rf230_xmit,
@@ -1225,6 +1252,7 @@ static const struct ieee802154_ops at86rf230_ops = {
 	.set_cca_ed_level = at86rf230_set_cca_ed_level,
 	.set_csma_params = at86rf230_set_csma_params,
 	.set_frame_retries = at86rf230_set_frame_retries,
+	.set_promiscuous_mode = at86rf230_set_promiscuous_mode,
 };
 
 static struct at86rf2xx_chip_data at86rf233_data = {
@@ -1388,7 +1416,7 @@ at86rf230_detect_device(struct at86rf230_local *lp)
 	lp->hw->extra_tx_headroom = 0;
 	lp->hw->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK |
 			IEEE802154_HW_TXPOWER | IEEE802154_HW_ARET |
-			IEEE802154_HW_AFILT;
+			IEEE802154_HW_AFILT | IEEE802154_HW_PROMISCUOUS;
 
 	switch (part) {
 	case 2:
Signature · 1 line
2.1.2
author maintainer
#7 lore raw

PATCH 7/17 mac802154: separate omit tx/rx flags

In reply to Alexander Aring

This patch splits the IEEE802154_HW_OMIT_CKSUM hardware flag into IEEE802154_HW_TX_OMIT_CKSUM and IEEE802154_HW_RX_OMIT_CKSUM. This is useful to deliver the received crc from the driver layer to the monitor interface. At the moment we can't do that without change the xmit handling.

The received checksum should be visible in monitor mode only.

---
 include/net/mac802154.h | 10 ++++++++--
 net/mac802154/rx.c      |  2 +-
 net/mac802154/tx.c      |  2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)
include/net/mac802154.h +8 -2
index 166ef6c5..bc1d40c 100644
@@ -73,8 +73,8 @@ struct ieee802154_hw {
  * however, so you are advised to review these flags carefully.
  */
 
-/* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */
-#define IEEE802154_HW_OMIT_CKSUM	0x00000001
+/* Indicates that xmitter will add FCS on it's own. */
+#define IEEE802154_HW_TX_OMIT_CKSUM	0x00000001
 /* Indicates that receiver will autorespond with ACK frames. */
 #define IEEE802154_HW_AACK		0x00000002
 /* Indicates that transceiver will support transmit power setting. */
@@ -94,6 +94,12 @@ struct ieee802154_hw {
 #define IEEE802154_HW_AFILT		0x00000100
 /* Indicates that transceiver will support promiscuous mode setting. */
 #define IEEE802154_HW_PROMISCUOUS	0x00000200
+/* Indicates that receiver omits FCS. */
+#define IEEE802154_HW_RX_OMIT_CKSUM	0x00000400
+
+/* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */
+#define IEEE802154_HW_OMIT_CKSUM	(IEEE802154_HW_TX_OMIT_CKSUM | \
+					 IEEE802154_HW_RX_OMIT_CKSUM)
 
 /* This groups the most common CSMA support fields into one. */
 #define IEEE802154_HW_CSMA		(IEEE802154_HW_CCA_MODE | \
net/mac802154/rx.c +1 -1
index 86394be..2aa80bd 100644
@@ -255,7 +255,7 @@ void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb)
 
 	WARN_ON_ONCE(softirq_count() == 0);
 
-	if (!(local->hw.flags & IEEE802154_HW_OMIT_CKSUM)) {
+	if (!(local->hw.flags & IEEE802154_HW_RX_OMIT_CKSUM)) {
 		u16 crc;
 
 		if (skb->len < 2) {
net/mac802154/tx.c +1 -1
index 77973a8..cc37b77 100644
@@ -83,7 +83,7 @@ ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
 	struct net_device *dev = skb->dev;
 	int ret;
 
-	if (!(local->hw.flags & IEEE802154_HW_OMIT_CKSUM)) {
+	if (!(local->hw.flags & IEEE802154_HW_TX_OMIT_CKSUM)) {
 		u16 crc = crc_ccitt(0, skb->data, skb->len);
 
 		put_unaligned_le16(crc, skb_put(skb, 2));
Signature · 1 line
2.1.2
author maintainer
#8 lore raw

PATCH 8/17 mac802154: rx: remove unnecessary parameter

In reply to Alexander Aring

This patch removes a not used parameter in ieee802154_deliver_skb.

---
 net/mac802154/rx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/mac802154/rx.c +2 -2
index 2aa80bd..51a55d9 100644
@@ -29,7 +29,7 @@
 
 #include "ieee802154_i.h"
 
-static int ieee802154_deliver_skb(struct net_device *dev, struct sk_buff *skb)
+static int ieee802154_deliver_skb(struct sk_buff *skb)
 {
 	skb->ip_summed = CHECKSUM_UNNECESSARY;
 	skb->protocol = htons(ETH_P_IEEE802154);
@@ -103,7 +103,7 @@ ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata,
 
 	switch (mac_cb(skb)->type) {
 	case IEEE802154_FC_TYPE_DATA:
-		return ieee802154_deliver_skb(sdata->dev, skb);
+		return ieee802154_deliver_skb(skb);
 	default:
 		pr_warn("ieee802154: bad frame received (type = %d)\n",
 			mac_cb(skb)->type);
Signature · 1 line
2.1.2
author maintainer
#9 lore raw

PATCH 9/17 mac802154: rx: simplify crc receive handling

In reply to Alexander Aring

This patch change the actual crc handling while receive. Currently the IEEE802154_HW_RX_OMIT_CKSUM flag is used to filter a frame with a bad crc. This patch changes the behaviour of IEEE802154_HW_RX_OMIT_CKSUM to add a crc while receiving for the monitor interface. After monitor receiving we remove the crc for frame parsing. This affect the driver layer because all drivers sets IEEE802154_HW_RX_OMIT_CKSUM and deliver without checksum.

---
 net/mac802154/rx.c | 34 ++++++++++++----------------------
 1 file changed, 12 insertions(+), 22 deletions(-)
net/mac802154/rx.c +12 -22
index 51a55d9..b6a4bbf 100644
@@ -21,6 +21,7 @@
 #include <linux/module.h>
 #include <linux/netdevice.h>
 #include <linux/crc-ccitt.h>
+#include <asm/unaligned.h>
 
 #include <net/mac802154.h>
 #include <net/ieee802154_netdev.h>
@@ -225,8 +226,6 @@ ieee802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb)
 {
 	struct sk_buff *skb2;
 	struct ieee802154_sub_if_data *sdata;
-	u16 crc = crc_ccitt(0, skb->data, skb->len);
-	u8 *data;
 
 	skb_reset_mac_header(skb);
 	skb->ip_summed = CHECKSUM_UNNECESSARY;
@@ -241,9 +240,6 @@ ieee802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb)
 		skb2 = skb_clone(skb, GFP_ATOMIC);
 		skb2->dev = sdata->dev;
 		skb2->pkt_type = PACKET_HOST;
-		data = skb_put(skb2, 2);
-		data[0] = crc & 0xff;
-		data[1] = crc >> 8;
 
 		netif_rx_ni(skb2);
 	}
@@ -255,32 +251,26 @@ void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb)
 
 	WARN_ON_ONCE(softirq_count() == 0);
 
-	if (!(local->hw.flags & IEEE802154_HW_RX_OMIT_CKSUM)) {
-		u16 crc;
+	/* TODO: When a transceiver omits the checksum here, we
+	 * add an own calculated one. This is currently an ugly
+	 * solution because the monitor needs a crc here.
+	 */
+	if (local->hw.flags & IEEE802154_HW_RX_OMIT_CKSUM) {
+		u16 crc = crc_ccitt(0, skb->data, skb->len);
 
-		if (skb->len < 2) {
-			pr_debug("got invalid frame\n");
-			goto fail;
-		}
-		crc = crc_ccitt(0, skb->data, skb->len);
-		if (crc) {
-			pr_debug("CRC mismatch\n");
-			goto fail;
-		}
-		skb_trim(skb, skb->len - 2); /* CRC */
+		put_unaligned_le16(crc, skb_put(skb, 2));
 	}
 
 	rcu_read_lock();
 
 	ieee802154_monitors_rx(local, skb);
-	__ieee802154_rx_handle_packet(local, skb);
 
-	rcu_read_unlock();
+	/* remove crc */
+	skb_trim(skb, skb->len - 2);
 
-	return;
+	__ieee802154_rx_handle_packet(local, skb);
 
-fail:
-	kfree_skb(skb);
+	rcu_read_unlock();
 }
 EXPORT_SYMBOL(ieee802154_rx);
 
Signature · 1 line
2.1.2
author maintainer
#10 lore raw

PATCH 10/17 mac802154: rx: add software checksum filtering check

In reply to Alexander Aring

This patch adds a new hardware flag which indicate that the transceiver doesn't support check for bad checksum via hardware. Also add a handling of this while receive.

---
 include/net/mac802154.h |  2 ++
 net/mac802154/rx.c      | 15 +++++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)
include/net/mac802154.h +2 -0
index bc1d40c..8f1de68 100644
@@ -96,6 +96,8 @@ struct ieee802154_hw {
 #define IEEE802154_HW_PROMISCUOUS	0x00000200
 /* Indicates that receiver omits FCS. */
 #define IEEE802154_HW_RX_OMIT_CKSUM	0x00000400
+/* Indicates that receiver will not filter frames with bad checksum. */
+#define IEEE802154_HW_RX_DROP_BAD_CKSUM	0x00000800
 
 /* Indicates that receiver omits FCS and xmitter will add FCS on it's own. */
 #define IEEE802154_HW_OMIT_CKSUM	(IEEE802154_HW_TX_OMIT_CKSUM | \
net/mac802154/rx.c +13 -2
index b6a4bbf..c9f1c72 100644
@@ -248,6 +248,7 @@ ieee802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb)
 void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb)
 {
 	struct ieee802154_local *local = hw_to_local(hw);
+	u16 crc;
 
 	WARN_ON_ONCE(softirq_count() == 0);
 
@@ -256,8 +257,7 @@ void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb)
 	 * solution because the monitor needs a crc here.
 	 */
 	if (local->hw.flags & IEEE802154_HW_RX_OMIT_CKSUM) {
-		u16 crc = crc_ccitt(0, skb->data, skb->len);
-
+		crc = crc_ccitt(0, skb->data, skb->len);
 		put_unaligned_le16(crc, skb_put(skb, 2));
 	}
 
@@ -265,6 +265,17 @@ void ieee802154_rx(struct ieee802154_hw *hw, struct sk_buff *skb)
 
 	ieee802154_monitors_rx(local, 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) {
+		crc = crc_ccitt(0, skb->data, skb->len);
+		if (crc) {
+			rcu_read_unlock();
+			kfree_skb(skb);
+			return;
+		}
+	}
 	/* remove crc */
 	skb_trim(skb, skb->len - 2);
 
Signature · 1 line
2.1.2
author maintainer
#11 lore raw

PATCH 11/17 mac802154: rx: remove override pkt_type set to PACKET_HOST

In reply to Alexander Aring

This patch removes pkt_type set to PACKET_HOST while monitor receiving. This should be PACKET_OTHERHOST on monitor mode which already set before.

---
 net/mac802154/rx.c | 1 -
 1 file changed, 1 deletion(-)
net/mac802154/rx.c +0 -1
index c9f1c72..f15c50b 100644
@@ -239,7 +239,6 @@ ieee802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb)
 
 		skb2 = skb_clone(skb, GFP_ATOMIC);
 		skb2->dev = sdata->dev;
-		skb2->pkt_type = PACKET_HOST;
 
 		netif_rx_ni(skb2);
 	}
Signature · 1 line
2.1.2
author maintainer
#12 lore raw

PATCH 12/17 mac802154: rx: use netif_receive_skb

In reply to Alexander Aring

This patch removes netif_rx_ni call. Instead we call netif_receive_skb, we can do that since commit c5c47e67bcd24638a059b1b5e9ec18c95f8634ca ("mac802154: rx: use tasklet instead workqueue").

---
 net/mac802154/rx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac802154/rx.c +1 -1
index f15c50b..7669cdb 100644
@@ -240,7 +240,7 @@ ieee802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb)
 		skb2 = skb_clone(skb, GFP_ATOMIC);
 		skb2->dev = sdata->dev;
 
-		netif_rx_ni(skb2);
+		ieee802154_deliver_skb(skb2);
 	}
 }
 
Signature · 1 line
2.1.2
author maintainer
#13 lore raw

PATCH 13/17 mac802154: rx: add rx stats incrementation

In reply to Alexander Aring

This patch adds rx stats incrementation when the monitor interface recevied a frame.

---
 net/mac802154/rx.c | 3 +++
 1 file changed, 3 insertions(+)
net/mac802154/rx.c +3 -0
index 7669cdb..6ba2769 100644
@@ -241,6 +241,9 @@ ieee802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb)
 		skb2->dev = sdata->dev;
 
 		ieee802154_deliver_skb(skb2);
+
+		sdata->dev->stats.rx_packets++;
+		sdata->dev->stats.rx_bytes += skb->len;
 	}
 }
 
Signature · 1 line
2.1.2
author maintainer
#14 lore raw

PATCH 14/17 mac802154: rx: monitor receive cleanup

In reply to Alexander Aring

This patch replace the !netif_running(sdata->dev) instead we doing a !ieee802154_sdata_running(sdata). Also move this in two separate if branches to compare with mac80211 code.

---
 net/mac802154/rx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/mac802154/rx.c +4 -2
index 6ba2769..971a855 100644
@@ -233,8 +233,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->type != IEEE802154_DEV_MONITOR ||
-		    !netif_running(sdata->dev))
+		if (sdata->type != IEEE802154_DEV_MONITOR)
+			continue;
+
+		if (!ieee802154_sdata_running(sdata))
 			continue;
 
 		skb2 = skb_clone(skb, GFP_ATOMIC);
Signature · 1 line
2.1.2
author maintainer
#15 lore raw

PATCH 15/17 mac802154: rx: add error handling after skb_clone

In reply to Alexander Aring

This patch adds error handling after skb_clone and deliver only if skb_clone was successful.

---
 net/mac802154/rx.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
net/mac802154/rx.c +6 -5
index 971a855..95961cc 100644
@@ -240,12 +240,13 @@ ieee802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb)
 			continue;
 
 		skb2 = skb_clone(skb, GFP_ATOMIC);
-		skb2->dev = sdata->dev;
+		if (skb2) {
+			skb2->dev = sdata->dev;
+			ieee802154_deliver_skb(skb2);
 
-		ieee802154_deliver_skb(skb2);
-
-		sdata->dev->stats.rx_packets++;
-		sdata->dev->stats.rx_bytes += skb->len;
+			sdata->dev->stats.rx_packets++;
+			sdata->dev->stats.rx_bytes += skb->len;
+		}
 	}
 }
 
Signature · 1 line
2.1.2
author maintainer
#16 lore raw

PATCH 16/17 at86rf230: deliver with checksum

In reply to Alexander Aring

This patch indicates that the at86rf230 driver deliver with checksum instead drop the crc before delivering.

---
 drivers/net/ieee802154/at86rf230.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ieee802154/at86rf230.c +2 -2
index 98c9437..9ad2d43 100644
@@ -819,7 +819,7 @@ at86rf230_rx_read_frame_complete(void *context)
 		len = IEEE802154_MTU;
 	}
 
-	at86rf230_rx(lp, buf + 2, len - 2, buf[2 + len]);
+	at86rf230_rx(lp, buf + 2, len, buf[2 + len]);
 }
 
 static void
@@ -1414,7 +1414,7 @@ at86rf230_detect_device(struct at86rf230_local *lp)
 	}
 
 	lp->hw->extra_tx_headroom = 0;
-	lp->hw->flags = IEEE802154_HW_OMIT_CKSUM | IEEE802154_HW_AACK |
+	lp->hw->flags = IEEE802154_HW_TX_OMIT_CKSUM | IEEE802154_HW_AACK |
 			IEEE802154_HW_TXPOWER | IEEE802154_HW_ARET |
 			IEEE802154_HW_AFILT | IEEE802154_HW_PROMISCUOUS;
 
Signature · 1 line
2.1.2
author maintainer
#17 lore raw

PATCH 17/17 mac802154: add basic support for monitor

In reply to Alexander Aring

This patch adds basic support for monitor mode. Also change the open call that we set the transceiver mac setting on an interface up. Futher patches will add a better handling while interface up an interface.

---
 net/mac802154/ieee802154_i.h |  1 +
 net/mac802154/iface.c        | 12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
net/mac802154/ieee802154_i.h +1 -0
index 7cebc98..1086a9d 100644
@@ -84,6 +84,7 @@ struct ieee802154_sub_if_data {
 	__le16 pan_id;
 	__le16 short_addr;
 	__le64 extended_addr;
+	bool promisuous_mode;
 
 	struct ieee802154_mac_params mac_params;
 
net/mac802154/iface.c +11 -1
index c0bf5f9..f7a6f83 100644
@@ -196,6 +196,12 @@ static int mac802154_wpan_open(struct net_device *dev)
 
 	mutex_lock(&phy->pib_lock);
 
+	if (local->hw.flags & IEEE802154_HW_PROMISCUOUS) {
+		rc = drv_set_promiscuous_mode(local, sdata->promisuous_mode);
+		if (rc < 0)
+			goto out;
+	}
+
 	if (local->hw.flags & IEEE802154_HW_TXPOWER) {
 		rc = drv_set_tx_power(local, sdata->mac_params.transmit_power);
 		if (rc < 0)
@@ -382,7 +388,7 @@ static const struct net_device_ops mac802154_wpan_ops = {
 };
 
 static const struct net_device_ops mac802154_monitor_ops = {
-	.ndo_open		= mac802154_slave_open,
+	.ndo_open		= mac802154_wpan_open,
 	.ndo_stop		= mac802154_slave_close,
 	.ndo_start_xmit		= ieee802154_monitor_start_xmit,
 };
@@ -434,6 +440,8 @@ void mac802154_wpan_setup(struct net_device *dev)
 	sdata->pan_id = cpu_to_le16(IEEE802154_PANID_BROADCAST);
 	sdata->short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
 
+	sdata->promisuous_mode = false;
+
 	mac802154_llsec_init(&sdata->sec);
 }
 
@@ -453,4 +461,6 @@ void mac802154_monitor_setup(struct net_device *dev)
 
 	sdata = IEEE802154_DEV_TO_SUB_IF(dev);
 	sdata->type = IEEE802154_DEV_MONITOR;
+
+	sdata->promisuous_mode = true;
 }
Signature · 1 line
2.1.2
#18 lore raw
In reply to Alexander Aring

Hi Alex,

Quoted 31 lines

This patch series fix checksum and monitor handling. The checksum handling is currently a little bit weird, because all driver drops the checksum while delivering. In monitor mode we want to see the received checksum. This patch series contains various patches to fix the checksum handling and add basic support for real monitor mode with promiscuous mode setting.

The checksum handling is now in some state which should work also for monitor interfaces. There exist a better way to add runtime changeable flags to handle crc calculation via hardware or software. Also flags like if the monitor interface receiving is with or without checksum. This is only to introduce some behaviour which should working.

Alexander Aring (17):
mac802154: main: remove unnecessary include
mac802154: remove tab after define
mac802154: add IEEE802154_HW_ARET hw flag
mac802154: add hardware address filter flag
mac802154: add support for promiscuous mode
at86rf230: add support for promiscuous mode
mac802154: separate omit tx/rx flags
mac802154: rx: remove unnecessary parameter
mac802154: rx: simplify crc receive handling
mac802154: rx: add software checksum filtering check
mac802154: rx: remove override pkt_type set to PACKET_HOST
mac802154: rx: use netif_receive_skb
mac802154: rx: add rx stats incrementation
mac802154: rx: monitor receive cleanup
mac802154: rx: add error handling after skb_clone
at86rf230: deliver with checksum
mac802154: add basic support for monitor

Quoted 11 lines
drivers/net/ieee802154/at86rf230.c | 35 +++++++++++++++++++--
drivers/net/ieee802154/cc2520.c    |  3 +-
drivers/net/ieee802154/mrf24j40.c  |  3 +-
include/net/mac802154.h            | 40 ++++++++++++++++++------
net/mac802154/driver-ops.h         | 13 ++++++++
net/mac802154/ieee802154_i.h       |  1 +
net/mac802154/iface.c              | 12 ++++++-
net/mac802154/main.c               |  1 -
net/mac802154/rx.c                 | 64 +++++++++++++++++++++-----------------
net/mac802154/tx.c                 |  2 +-
10 files changed, 127 insertions(+), 47 deletions(-)

all 17 patches have been applied to bluetooth-next tree.

Regards

Marcel