From 037618a638ec9be1c89511972d89622213f6ee2c Mon Sep 17 00:00:00 2001 From: Gerson Fernando Budke Date: Sun, 24 Sep 2023 17:57:28 +0200 Subject: [PATCH] drivers: ieee802154: rf2xx: Fix rx promiscuous behaviour When radio is set to promiscuous mode it is desirable to receive invalid frames. This skip a few checks and allow an invalid and non-standard frames be delivered for diagnose. Signed-off-by: Gerson Fernando Budke --- drivers/ieee802154/ieee802154_rf2xx.c | 12 ++++++++---- drivers/ieee802154/ieee802154_rf2xx.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/ieee802154/ieee802154_rf2xx.c b/drivers/ieee802154/ieee802154_rf2xx.c index 8f6f4a37656..cdefa26f66e 100644 --- a/drivers/ieee802154/ieee802154_rf2xx.c +++ b/drivers/ieee802154/ieee802154_rf2xx.c @@ -179,7 +179,7 @@ static void rf2xx_trx_rx(const struct device *dev) pkt_len = rx_buf[RX2XX_FRAME_PHR_INDEX]; } - if (pkt_len < RX2XX_FRAME_MIN_PHR_SIZE) { + if (!ctx->promiscuous && pkt_len < RX2XX_FRAME_MIN_PHR_SIZE) { LOG_ERR("Invalid RX frame length"); return; } @@ -203,14 +203,14 @@ static void rf2xx_trx_rx(const struct device *dev) } ctx->pkt_lqi = rx_buf[pkt_len + RX2XX_FRAME_LQI_INDEX]; - if (trac == RF2XX_TRX_PHY_STATE_TRAC_INVALID) { + if (!ctx->promiscuous && trac == RF2XX_TRX_PHY_STATE_TRAC_INVALID) { LOG_ERR("Invalid RX frame"); - return; } if (!IS_ENABLED(CONFIG_IEEE802154_RAW_MODE) && - !IS_ENABLED(CONFIG_NET_L2_OPENTHREAD)) { + !IS_ENABLED(CONFIG_NET_L2_OPENTHREAD) && + pkt_len >= RX2XX_FRAME_FCS_LENGTH) { pkt_len -= RX2XX_FRAME_FCS_LENGTH; } @@ -775,8 +775,11 @@ static int rf2xx_pan_coord_set(const struct device *dev, bool pan_coordinator) static int rf2xx_promiscuous_set(const struct device *dev, bool promiscuous) { + struct rf2xx_context *ctx = dev->data; uint8_t reg; + ctx->promiscuous = promiscuous; + if (promiscuous) { reg = rf2xx_iface_reg_read(dev, RF2XX_XAH_CTRL_1_REG); reg |= (1 << RF2XX_AACK_PROM_MODE); @@ -903,6 +906,7 @@ static int power_on_and_setup(const struct device *dev) } ctx->tx_mode = IEEE802154_TX_MODE_CSMA_CA; + ctx->promiscuous = false; /* Configure INT behaviour */ config = (1 << RF2XX_RX_START) | diff --git a/drivers/ieee802154/ieee802154_rf2xx.h b/drivers/ieee802154/ieee802154_rf2xx.h index 04d15533c78..b77ec254d3a 100644 --- a/drivers/ieee802154/ieee802154_rf2xx.h +++ b/drivers/ieee802154/ieee802154_rf2xx.h @@ -122,6 +122,7 @@ struct rf2xx_context { int8_t trx_rssi_base; uint8_t trx_version; uint8_t rx_phr; + bool promiscuous; }; #endif /* ZEPHYR_DRIVERS_IEEE802154_IEEE802154_RF2XX_H_ */