sys/net/gnrc/netif/ethernet: Support RX timestamp

This commit is contained in:
Marian Buschsieweke 2020-07-29 10:56:07 +02:00
parent 08d86295d2
commit f6bca70d11
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F
2 changed files with 26 additions and 2 deletions

View File

@ -29,6 +29,25 @@
extern "C" { extern "C" {
#endif #endif
/**
* @name Flags for use in @ref netdev_eth_rx_info_t::flags
* @{
*/
#define NETDEV_ETH_RX_INFO_FLAG_TIMESTAMP (0x01) /**< Timestamp valid */
/** @} */
/**
* @brief Received frame status information for Ethernet devices
*/
typedef struct {
/**
* @brief Time of the reception of the start of frame delimiter in
* nanoseconds since epoch
*/
uint64_t timestamp;
uint8_t flags; /**< Flags e.g. used to mark other fields as valid */
} netdev_eth_rx_info_t;
/** /**
* @brief Fallback function for netdev ethernet devices' _get function * @brief Fallback function for netdev ethernet devices' _get function
* *

View File

@ -21,6 +21,7 @@
#include "net/ethernet/hdr.h" #include "net/ethernet/hdr.h"
#include "net/gnrc.h" #include "net/gnrc.h"
#include "net/gnrc/netif/ethernet.h" #include "net/gnrc/netif/ethernet.h"
#include "net/netdev/eth.h"
#ifdef MODULE_GNRC_IPV6 #ifdef MODULE_GNRC_IPV6
#include "net/ipv6/hdr.h" #include "net/ipv6/hdr.h"
#endif #endif
@ -169,8 +170,9 @@ static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif) static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif)
{ {
netdev_t *dev = netif->dev; netdev_t *dev = netif->dev;
int bytes_expected = dev->driver->recv(dev, NULL, 0, NULL);
gnrc_pktsnip_t *pkt = NULL; gnrc_pktsnip_t *pkt = NULL;
netdev_eth_rx_info_t rx_info = { .flags = 0 };
int bytes_expected = dev->driver->recv(dev, NULL, 0, NULL);
if (bytes_expected > 0) { if (bytes_expected > 0) {
pkt = gnrc_pktbuf_add(NULL, NULL, pkt = gnrc_pktbuf_add(NULL, NULL,
@ -186,7 +188,7 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif)
goto out; goto out;
} }
int nread = dev->driver->recv(dev, pkt->data, bytes_expected, NULL); int nread = dev->driver->recv(dev, pkt->data, bytes_expected, &rx_info);
if (nread <= 0) { if (nread <= 0) {
DEBUG("gnrc_netif_ethernet: read error.\n"); DEBUG("gnrc_netif_ethernet: read error.\n");
goto safe_out; goto safe_out;
@ -245,6 +247,9 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif)
gnrc_netif_hdr_set_src_addr(netif_hdr->data, hdr->src, ETHERNET_ADDR_LEN); gnrc_netif_hdr_set_src_addr(netif_hdr->data, hdr->src, ETHERNET_ADDR_LEN);
gnrc_netif_hdr_set_dst_addr(netif_hdr->data, hdr->dst, ETHERNET_ADDR_LEN); gnrc_netif_hdr_set_dst_addr(netif_hdr->data, hdr->dst, ETHERNET_ADDR_LEN);
gnrc_netif_hdr_set_netif(netif_hdr->data, netif); gnrc_netif_hdr_set_netif(netif_hdr->data, netif);
if (rx_info.flags & NETDEV_ETH_RX_INFO_FLAG_TIMESTAMP) {
gnrc_netif_hdr_set_timestamp(netif_hdr->data, rx_info.timestamp);
}
gnrc_pktbuf_remove_snip(pkt, eth_hdr); gnrc_pktbuf_remove_snip(pkt, eth_hdr);
pkt = gnrc_pkt_append(pkt, netif_hdr); pkt = gnrc_pkt_append(pkt, netif_hdr);