diff --git a/cpu/native/netdev2_tap/netdev2_tap.c b/cpu/native/netdev2_tap/netdev2_tap.c index b12631af571a..6c1a39b83332 100644 --- a/cpu/native/netdev2_tap/netdev2_tap.c +++ b/cpu/native/netdev2_tap/netdev2_tap.c @@ -296,7 +296,9 @@ static int _send(netdev2_t *netdev, const struct iovec *vector, int n) } netdev->stats.tx_bytes += bytes; #endif - netdev->event_callback(netdev, NETDEV2_EVENT_TX_COMPLETE, NULL); + if (netdev->event_callback) { + netdev->event_callback(netdev, NETDEV2_EVENT_TX_COMPLETE, NULL); + } return res; } diff --git a/drivers/enc28j60/enc28j60.c b/drivers/enc28j60/enc28j60.c index 2dc4e7598dbd..384aba522829 100644 --- a/drivers/enc28j60/enc28j60.c +++ b/drivers/enc28j60/enc28j60.c @@ -230,6 +230,7 @@ static int nd_send(netdev2_t *netdev, const struct iovec *data, int count) #ifdef MODULE_NETSTATS_L2 netdev->stats.tx_bytes += count; #endif + /* set write pointer */ cmd_w_addr(dev, ADDR_WRITE_PTR, BUF_TX_START); /* write control byte and the actual data into the buffer */ @@ -380,6 +381,9 @@ static int nd_init(netdev2_t *netdev) /* allow receiving bytes from now on */ cmd_bfs(dev, REG_ECON1, -1, ECON1_RXEN); +#ifdef MODULE_NETSTATS_L2 + memset(&netdev->stats, 0, sizeof(netstats_t)); +#endif mutex_unlock(&dev->devlock); return 0; } @@ -424,9 +428,6 @@ static void nd_isr(netdev2_t *netdev) } eir = cmd_rcr(dev, REG_EIR, -1); } -#ifdef MODULE_NETSTATS_L2 - memset(&netdev->stats, 0, sizeof(netstats_t)); -#endif } static int nd_get(netdev2_t *netdev, netopt_t opt, void *value, size_t max_len) diff --git a/drivers/encx24j600/encx24j600.c b/drivers/encx24j600/encx24j600.c index 1c855eb0ba97..399d76c3839d 100644 --- a/drivers/encx24j600/encx24j600.c +++ b/drivers/encx24j600/encx24j600.c @@ -32,7 +32,7 @@ #include "net/netdev2/eth.h" #include "net/eui64.h" #include "net/ethernet.h" -//#include "net/ethernet/hdr.h" +#include "net/netstats.h" #define ENABLE_DEBUG (0) #include "debug.h" @@ -298,6 +298,9 @@ static int _init(netdev2_t *encdev) unlock(dev); +#ifdef MODULE_NETSTATS_L2 + memset(&netdev->stats, 0, sizeof(netstats_t)); +#endif return 0; } @@ -305,6 +308,10 @@ static int _send(netdev2_t *netdev, const struct iovec *vector, int count) { encx24j600_t * dev = (encx24j600_t *) netdev; lock(dev); +#ifdef MODULE_NETSTATS_L2 + netdev->stats.tx_bytes += count; +#endif + /* wait until previous packet has been sent */ while ((reg_get(dev, ECON1) & TXRTS)); @@ -367,6 +374,10 @@ static int _recv(netdev2_t *netdev, char* buf, int len, void *info) size_t payload_len = hdr.frame_len - 4; if (buf) { +#ifdef MODULE_NETSTATS_L2 + netdev->stats.rx_count++; + netdev2->stats.rx_bytes += len; +#endif /* read packet (without 4 bytes checksum) */ sram_op(dev, RRXDATA, 0xFFFF, buf, payload_len);