From 520651661ad412fdf3bb12965f80037efee35143 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Fri, 26 Aug 2016 15:08:20 +0200 Subject: [PATCH] candump: Enable HW timestamping before using it If HW timestamping is not supported by the driver, candump exits with an error message. Signed-off-by: Michal Sojka --- candump.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/candump.c b/candump.c index bd9a3cd..c983b71 100644 --- a/candump.c +++ b/candump.c @@ -66,6 +66,10 @@ #include "terminal.h" #include "lib.h" +#ifndef SIOCSHWTSTAMP +# define SIOCSHWTSTAMP 0x89b0 +#endif + #define MAXSOCK 16 /* max. number of CAN interfaces given on the cmdline */ #define MAXIFNAMES 30 /* size of receive name index to omit ioctls */ #define MAXCOL 6 /* number of different colors for colorized output */ @@ -564,6 +568,21 @@ int main(int argc, char **argv) return 1; } } else { + struct ifreq hwtstamp; + struct hwtstamp_config hwconfig; + + memset(&hwtstamp, 0, sizeof(hwtstamp)); + strncpy(hwtstamp.ifr_name, ifr.ifr_name, sizeof(hwtstamp.ifr_name)); + hwtstamp.ifr_data = (void *)&hwconfig; + memset(&hwconfig, 0, sizeof(hwconfig)); + hwconfig.tx_type = HWTSTAMP_TX_OFF; + hwconfig.rx_filter = HWTSTAMP_FILTER_ALL; + + if (ioctl(s[i], SIOCSHWTSTAMP, &hwtstamp) < 0) { + perror("SIOCSHWTSTAMP"); + return 1; + } + const int so_timestamping_flags = SOF_TIMESTAMPING_RAW_HARDWARE; if (setsockopt(s[i], SOL_SOCKET, SO_TIMESTAMPING, -- 2.39.2