diff --git a/cpu/cc2538/radio/cc2538_rf_netdev.c b/cpu/cc2538/radio/cc2538_rf_netdev.c index 0a8548922411402a068dae7c9b7e11f3836b8738..b48d5d22820ce55d1d6702c4388af666c6e78d86 100644 --- a/cpu/cc2538/radio/cc2538_rf_netdev.c +++ b/cpu/cc2538/radio/cc2538_rf_netdev.c @@ -277,7 +277,9 @@ static int _send(netdev2_t *netdev, const struct iovec *vector, unsigned count) rfcore_write_fifo(vector[i].iov_base, vector[i].iov_len); } - + #ifdef MODULE_NETSTATS_L2 + netdev->stats.tx_bytes += pkt_len; + #endif /* Set first byte of TX FIFO to the packet length */ rfcore_poke_tx_fifo(0, pkt_len + CC2538_AUTOCRC_LEN); @@ -323,7 +325,10 @@ static int _recv(netdev2_t *netdev, void *buf, size_t len, void *info) /* GNRC is expecting len bytes of data */ pkt_len = len; } - + #ifdef MODULE_NETSTATS_L2 + netdev->stats.rx_count++; + netdev->stats.rx_bytes += pkt_len; + #endif rfcore_read_fifo(buf, pkt_len); if (info != NULL && RFCORE->XREG_RSSISTATbits.RSSI_VALID) { @@ -389,6 +394,9 @@ static int _init(netdev2_t *netdev) #elif MODULE_GNRC dev->netdev.proto = GNRC_NETTYPE_UNDEF; #endif +#ifdef MODULE_NETSTATS_L2 + memset(&netdev->stats, 0, sizeof(netstats_t)); +#endif return 0; } diff --git a/drivers/at86rf2xx/at86rf2xx_netdev.c b/drivers/at86rf2xx/at86rf2xx_netdev.c index 827225b8def410dc64075508979d547849db0dc6..ad1f036433d8c1ee0262913acf4ca5f9601820e2 100644 --- a/drivers/at86rf2xx/at86rf2xx_netdev.c +++ b/drivers/at86rf2xx/at86rf2xx_netdev.c @@ -148,15 +148,15 @@ static int _recv(netdev2_t *netdev, void *buf, size_t len, void *info) at86rf2xx_fb_stop(dev); return pkt_len; } -#ifdef MODULE_NETSTATS_L2 - netdev->stats.rx_count++; - netdev->stats.rx_bytes += pkt_len; -#endif /* not enough space in buf */ if (pkt_len > len) { at86rf2xx_fb_stop(dev); return -ENOBUFS; } + #ifdef MODULE_NETSTATS_L2 + netdev->stats.rx_count++; + netdev->stats.rx_bytes += pkt_len; + #endif /* copy payload */ at86rf2xx_fb_read(dev, (uint8_t *)buf, pkt_len);