From b9d26ae6fa6803f026715edae73fe7084d60c802 Mon Sep 17 00:00:00 2001 From: Georg von Zengen Date: Thu, 9 Aug 2018 14:52:53 +0200 Subject: [PATCH 1/4] CRC checks: added crc to netdef and netif hdr --- drivers/include/net/netdev.h | 1 + sys/include/net/gnrc/netif/hdr.h | 1 + sys/net/gnrc/link_layer/lwmac/lwmac.c | 1 + sys/net/gnrc/netif/gnrc_netif_ieee802154.c | 1 + sys/net/gnrc/netif/hdr/gnrc_netif_hdr_print.c | 3 ++- 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/include/net/netdev.h b/drivers/include/net/netdev.h index e5424bb3f454..56d5ab0c8bc4 100644 --- a/drivers/include/net/netdev.h +++ b/drivers/include/net/netdev.h @@ -249,6 +249,7 @@ typedef enum { struct netdev_radio_rx_info { int16_t rssi; /**< RSSI of a received packet in dBm */ uint8_t lqi; /**< LQI of a received packet */ + uint16_t crc_ok; /**< CRC Ok of received packet */ }; /** diff --git a/sys/include/net/gnrc/netif/hdr.h b/sys/include/net/gnrc/netif/hdr.h index 3e6aef7eaa53..f1e31c871c45 100644 --- a/sys/include/net/gnrc/netif/hdr.h +++ b/sys/include/net/gnrc/netif/hdr.h @@ -87,6 +87,7 @@ typedef struct { uint8_t flags; /**< flags as defined above */ uint8_t lqi; /**< lqi of received packet (optional) */ int16_t rssi; /**< rssi of received packet in dBm (optional) */ + uint8_t crc_ok; /**< crc valid indicator (optional) */ } gnrc_netif_hdr_t; /** diff --git a/sys/net/gnrc/link_layer/lwmac/lwmac.c b/sys/net/gnrc/link_layer/lwmac/lwmac.c index 402e20779955..082ef40d14d3 100644 --- a/sys/net/gnrc/link_layer/lwmac/lwmac.c +++ b/sys/net/gnrc/link_layer/lwmac/lwmac.c @@ -173,6 +173,7 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif) hdr->lqi = rx_info.lqi; hdr->rssi = rx_info.rssi; + hdr->crc_ok = rx_info.crc_ok; hdr->if_pid = thread_getpid(); pkt->type = state->proto; #if ENABLE_DEBUG diff --git a/sys/net/gnrc/netif/gnrc_netif_ieee802154.c b/sys/net/gnrc/netif/gnrc_netif_ieee802154.c index cb9c629d6c22..ef07c734233a 100644 --- a/sys/net/gnrc/netif/gnrc_netif_ieee802154.c +++ b/sys/net/gnrc/netif/gnrc_netif_ieee802154.c @@ -139,6 +139,7 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif) hdr->lqi = rx_info.lqi; hdr->rssi = rx_info.rssi; + hdr->crc_ok = rx_info.crc_ok; hdr->if_pid = thread_getpid(); pkt->type = state->proto; #if ENABLE_DEBUG diff --git a/sys/net/gnrc/netif/hdr/gnrc_netif_hdr_print.c b/sys/net/gnrc/netif/hdr/gnrc_netif_hdr_print.c index 275ea31705bf..444a893147bc 100644 --- a/sys/net/gnrc/netif/hdr/gnrc_netif_hdr_print.c +++ b/sys/net/gnrc/netif/hdr/gnrc_netif_hdr_print.c @@ -24,7 +24,8 @@ void gnrc_netif_hdr_print(gnrc_netif_hdr_t *hdr) printf("if_pid: %u ", (unsigned) hdr->if_pid); printf("rssi: %d ", (signed) hdr->rssi); - printf("lqi: %u\n", (unsigned) hdr->lqi); + printf("lqi: %u ", (unsigned) hdr->lqi); + printf("crc_ok: %u\n", (unsigned) hdr->crc_ok); printf("flags: "); if (hdr->flags) { From df2180178af5640067bef86d0b39bdfaa45aae38 Mon Sep 17 00:00:00 2001 From: Georg von Zengen Date: Thu, 9 Aug 2018 14:52:53 +0200 Subject: [PATCH 2/4] CRC checks: reading crc_ok form cc2420 and at86rf2xx --- drivers/at86rf2xx/at86rf2xx_netdev.c | 10 ++++++++++ drivers/cc2420/cc2420.c | 1 + 2 files changed, 11 insertions(+) diff --git a/drivers/at86rf2xx/at86rf2xx_netdev.c b/drivers/at86rf2xx/at86rf2xx_netdev.c index 24a959227b4e..ea01da9cb8a6 100644 --- a/drivers/at86rf2xx/at86rf2xx_netdev.c +++ b/drivers/at86rf2xx/at86rf2xx_netdev.c @@ -168,16 +168,26 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info) if (info != NULL) { uint8_t rssi = 0; + int8_t crc_ok = -1; netdev_ieee802154_rx_info_t *radio_info = info; at86rf2xx_fb_read(dev, &(radio_info->lqi), 1); #ifndef MODULE_AT86RF231 at86rf2xx_fb_read(dev, &(rssi), 1); + uint8_t rx_status = 0xFF; + at86rf2xx_fb_read(dev, &(rx_status), 1); + if((rx_status & 0xF) == 0) { + crc_ok = (rx_status & AT86RF2XX_PHY_RSSI_MASK__RX_CRC_VALID) ? 1 : 0; + } at86rf2xx_fb_stop(dev); #else at86rf2xx_fb_stop(dev); rssi = at86rf2xx_reg_read(dev, AT86RF2XX_REG__PHY_ED_LEVEL); + crc_ok = at86rf2xx_reg_read(dev, AT86RF2XX_REG__PHY_RSSI) & AT86RF2XX_PHY_RSSI_MASK__RX_CRC_VALID ? 1 : 0; + rssi &= AT86RF2XX_PHY_RSSI_MASK__RSSI; #endif radio_info->rssi = RSSI_BASE_VAL + rssi; + radio_info->crc_ok = crc_ok; + (void)crc_ok; } else { at86rf2xx_fb_stop(dev); diff --git a/drivers/cc2420/cc2420.c b/drivers/cc2420/cc2420.c index 24c159255ab4..cd2a9dbca75e 100644 --- a/drivers/cc2420/cc2420.c +++ b/drivers/cc2420/cc2420.c @@ -200,6 +200,7 @@ int cc2420_rx(cc2420_t *dev, uint8_t *buf, size_t max_len, void *info) netdev_ieee802154_rx_info_t *radio_info = info; radio_info->rssi = CC2420_RSSI_OFFSET + rssi; radio_info->lqi = crc_corr & CC2420_CRCCOR_COR_MASK; + radio_info->crc_ok = (uint16_t) ((crc_corr & ~CC2420_CRCCOR_COR_MASK)>>7); } /* finally flush the FIFO */ From 75e25566833f60a3a5f7613bed63ce45d6adcc2c Mon Sep 17 00:00:00 2001 From: Georg von Zengen Date: Thu, 9 Aug 2018 14:54:23 +0200 Subject: [PATCH 3/4] CRC checks: added FCS to netif hdr and netdef info --- drivers/include/net/netdev.h | 3 ++- sys/include/net/gnrc/netif/hdr.h | 3 ++- sys/net/gnrc/link_layer/lwmac/lwmac.c | 1 + sys/net/gnrc/netif/gnrc_netif_ieee802154.c | 1 + sys/net/gnrc/netif/hdr/gnrc_netif_hdr_print.c | 3 ++- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/include/net/netdev.h b/drivers/include/net/netdev.h index 56d5ab0c8bc4..08e1035edd13 100644 --- a/drivers/include/net/netdev.h +++ b/drivers/include/net/netdev.h @@ -249,7 +249,8 @@ typedef enum { struct netdev_radio_rx_info { int16_t rssi; /**< RSSI of a received packet in dBm */ uint8_t lqi; /**< LQI of a received packet */ - uint16_t crc_ok; /**< CRC Ok of received packet */ + uint16_t crc_ok; /**< CRC Ok of received packet */ + uint16_t fcs; /**< FCS of received packet */ }; /** diff --git a/sys/include/net/gnrc/netif/hdr.h b/sys/include/net/gnrc/netif/hdr.h index f1e31c871c45..5f2c9df9f4ce 100644 --- a/sys/include/net/gnrc/netif/hdr.h +++ b/sys/include/net/gnrc/netif/hdr.h @@ -87,7 +87,8 @@ typedef struct { uint8_t flags; /**< flags as defined above */ uint8_t lqi; /**< lqi of received packet (optional) */ int16_t rssi; /**< rssi of received packet in dBm (optional) */ - uint8_t crc_ok; /**< crc valid indicator (optional) */ + uint8_t crc_ok; /**< crc valid indicator (optional) */ + uint16_t fcs; /**< FCS of received packet */ } gnrc_netif_hdr_t; /** diff --git a/sys/net/gnrc/link_layer/lwmac/lwmac.c b/sys/net/gnrc/link_layer/lwmac/lwmac.c index 082ef40d14d3..647c5a42faa4 100644 --- a/sys/net/gnrc/link_layer/lwmac/lwmac.c +++ b/sys/net/gnrc/link_layer/lwmac/lwmac.c @@ -174,6 +174,7 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif) hdr->lqi = rx_info.lqi; hdr->rssi = rx_info.rssi; hdr->crc_ok = rx_info.crc_ok; + hdr->fcs = rx_info.fcs; hdr->if_pid = thread_getpid(); pkt->type = state->proto; #if ENABLE_DEBUG diff --git a/sys/net/gnrc/netif/gnrc_netif_ieee802154.c b/sys/net/gnrc/netif/gnrc_netif_ieee802154.c index ef07c734233a..f3a8b9c66277 100644 --- a/sys/net/gnrc/netif/gnrc_netif_ieee802154.c +++ b/sys/net/gnrc/netif/gnrc_netif_ieee802154.c @@ -140,6 +140,7 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif) hdr->lqi = rx_info.lqi; hdr->rssi = rx_info.rssi; hdr->crc_ok = rx_info.crc_ok; + hdr->fcs = rx_info.fcs; hdr->if_pid = thread_getpid(); pkt->type = state->proto; #if ENABLE_DEBUG diff --git a/sys/net/gnrc/netif/hdr/gnrc_netif_hdr_print.c b/sys/net/gnrc/netif/hdr/gnrc_netif_hdr_print.c index 444a893147bc..d332025dbf38 100644 --- a/sys/net/gnrc/netif/hdr/gnrc_netif_hdr_print.c +++ b/sys/net/gnrc/netif/hdr/gnrc_netif_hdr_print.c @@ -25,7 +25,8 @@ void gnrc_netif_hdr_print(gnrc_netif_hdr_t *hdr) printf("if_pid: %u ", (unsigned) hdr->if_pid); printf("rssi: %d ", (signed) hdr->rssi); printf("lqi: %u ", (unsigned) hdr->lqi); - printf("crc_ok: %u\n", (unsigned) hdr->crc_ok); + printf("crc_ok: %u ", (unsigned) hdr->crc_ok); + printf("fcs: %04x\n", (unsigned) hdr->fcs); printf("flags: "); if (hdr->flags) { From 4671e959069f759be75537d15a4ed309cb091b6e Mon Sep 17 00:00:00 2001 From: Georg von Zengen Date: Thu, 9 Aug 2018 13:59:05 +0200 Subject: [PATCH 4/4] at86rf2xx: implemented reading of FCS to netdev info --- drivers/at86rf2xx/at86rf2xx_netdev.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/at86rf2xx/at86rf2xx_netdev.c b/drivers/at86rf2xx/at86rf2xx_netdev.c index ea01da9cb8a6..b9158e11ea8d 100644 --- a/drivers/at86rf2xx/at86rf2xx_netdev.c +++ b/drivers/at86rf2xx/at86rf2xx_netdev.c @@ -132,6 +132,7 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info) at86rf2xx_t *dev = (at86rf2xx_t *)netdev; uint8_t phr; size_t pkt_len; + uint16_t fcs; /* frame buffer protection will be unlocked as soon as at86rf2xx_fb_stop() * is called*/ @@ -159,12 +160,8 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info) #endif /* copy payload */ at86rf2xx_fb_read(dev, (uint8_t *)buf, pkt_len); - - /* Ignore FCS but advance fb read - we must give a temporary buffer here, - * as we are not allowed to issue SPI transfers without any buffer */ - uint8_t tmp[2]; - at86rf2xx_fb_read(dev, tmp, 2); - (void)tmp; + /* copy fcs */ + at86rf2xx_fb_read(dev, (uint8_t *)&fcs, sizeof(uint16_t)); if (info != NULL) { uint8_t rssi = 0; @@ -187,6 +184,7 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info) #endif radio_info->rssi = RSSI_BASE_VAL + rssi; radio_info->crc_ok = crc_ok; + radio_info->fcs = fcs; (void)crc_ok; } else {