Commit Graph

84 Commits (dfb607c80700f1735a4c5037253bdd79a6f13b31)

Author SHA1 Message Date
Oliver Hartkopp 5e0895981b candump: fix accidentally disabled traffic timeout feature
With the option '-T <msecs>' candump terminates after getting no CAN traffic
for a specific time. With the introduction of epoll_wait() this feature
has been accidentally disabled.

This patch adds an extra check to detect the timeout again.

Fixes: 639498bc80 ("candump: use epoll_wait() instead of select()")
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2022-03-07 10:32:41 +01:00
Oliver Hartkopp ad250a68dc candump: add option to define individual filename for logfile
Link: https://github.com/linux-can/can-utils/pull/345
Suggested-by: https://github.com/xR3b0rn
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2022-02-16 11:46:46 +01:00
Oliver Hartkopp a705182b28 candump: trivial typo exchange sentence point with closing bracket
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2021-11-28 20:14:43 +01:00
Marc Kleine-Budde 1b4e317083 candump: fix epoll_wait() returning -1, errno == -EINTR
-EINTR is not an error, just restart the syscall.

Fixes: 639498bc80 ("candump: use epoll_wait() instead of select()")
Link: https://github.com/linux-can/can-utils/issues/296
Reported-by: Joakim Zhang <qiangqing.zhang@nxp.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2021-05-28 11:57:38 +02:00
Egor Kurnev bdf3e96ef9
Update candump.c 2021-04-14 18:49:49 +03:00
Richard Young eb66451df2 candump: Enable zero relative timestamps to be used in log files
The logfile format which is generated with '-l' and '-L' consists of an
absolute epoch timestamp. In some use cases (e.g. for documentation) a
zero relative timestamp can be useful which was only configurable with
the '-tz' option for the classic output.

'-tz' and '-ta' are now valid options for the logfile format.

Signed-off-by: Richard Young <code@richyoung.ca>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-12-08 20:52:54 +01:00
Marc Kleine-Budde bfaa44fa91 candump: convert to kernel codeing style
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2020-12-06 10:09:36 +01:00
Marc Kleine-Budde 305b2e8b79 candump: fix indention
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2020-12-06 09:58:52 +01:00
Marc Kleine-Budde 15f3a2e385 candump: remove trailing whitespace
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2020-12-06 09:57:52 +01:00
Jörg Hohensohn 639498bc80 candump: use epoll_wait() instead of select()
Using epoll_wait() instead of select() gives higher
performance for listening on multiple interfaces.
Additionally, the read order has a higher chance
to resemble the true temporal order.
select() gives implicit priority to the lower index socket.

Signed-off-by: Jörg Hohensohn <joerg.hohensohn@gmx.de>
2020-12-06 08:32:36 +01:00
Oliver Hartkopp 11edd1d05e candump: support len8_dlc for standard candump output
The display of Classical CAN raw DLC values is an expert feature which is
not enabled by default to not break toolchains that use the candump
standard output for further processing. (N.B. using the log file format and
the functions from lib.h/lib.c provide convenient CAN frame conversions)

After enabling the raw DLC for Classical CAN with the '-8' option the raw
DLC value is printed in 'unusual' curly braces {}.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-11-22 19:42:38 +01:00
Rosen Penev b153fe3f35
clang-tidy: sort includes alphabetically
Found with llvm-include-order

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-12 23:28:58 -07:00
Rosen Penev 3e85fc5422
clang-tidy: fix cmp function usage
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-12 23:28:58 -07:00
Oliver Hartkopp 7cb3e760fe logfile: add new extra info field
This patch adds a fourth string field in the can logfile format.
This new field contains the rx/tx direction information R/T as the
first entry (only one character separated from the CAN frame by space).

To generate the logfile format with this extra field candump has to be
called with the '-x' option for extra message infos,
e.g. 'candump -x -l can0' or 'candump -x -L can0'

log2asc and asc2log are extended to support the direction information
but still support the previous format without direction information.

The format extension does not affect legacy tools, e.g. the existing
canplayer ignores this extra information and does not need to be changed.

Therefore the existing logfiles remain valid and usable.

The extra message infos will be colon separated when there's need for
additional content beyond the rx/tx direction information, e.g. R:xx:yyy

Suggested-by: Pallavi Revanna https://github.com/brpallu
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-08-18 13:29:36 +02:00
Oliver Hartkopp a4905ed7c8 fix timeval to ASCII unsigned value conversion
As reported by Oleksij Rempel here
https://github.com/linux-can/can-utils/issues/233#issuecomment-674818935
the representation of timeval timestamps are signed values which leads to
negative values on 32 bit machines addressing the year 2038 unix sec counter
overflow.

Fix the issue on 32 bit systems by converting the timeval values to unsigned
ASCII value representations.

Fixes: https://github.com/linux-can/can-utils/issues/234
Reported-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-08-18 12:51:35 +02:00
Gary Bisson 46895a41c5 Fix comparison type mismatch warnings
Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com>
2020-05-28 20:54:37 +02:00
Oliver Hartkopp 819a03f6e2 candump: fix/unify help text indention
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-04-28 18:59:37 +02:00
Alexander GQ Gerasiov 6db632531d candump.c: Reformat help/usage output to be compatible with help2man.
Gbp-Pq: Name 0004-candump.c-Reformat-help-usage-output-to-be-compatibl.patch
2020-04-27 08:20:08 +03:00
Oliver Hartkopp a9985c7652 candump: remove bridging functionality
The tool 'candump' is used to dump CAN traffic to stdout or logfile.
In early days where the in-kernel CAN gateway (can-gw) with the cangw tool was
not yet implemented the bridging functionality allowed to send received (and
filtered) CAN frames to another outgoing CAN interface.

As we now have can-gw and sending CAN frames from a 'reading tool' seems wrong
especially from the Unix philosophy "Write programs that do one thing and do
it well." this patch removes the obsolete functionality from candump.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-01-04 14:11:34 +01:00
Yegor Yefremov 14ccc06eba Fix spelling in various files
codespell parameters:

codespell -q 3 --skip="*.in,*.sh,*.m4,config,configure,autom4te.cache"

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2019-11-11 14:21:49 +01:00
Oliver Hartkopp 319bd5de45 candump: silence format-overflow warning
When -Wformat-overflow= is enabled the gcc notes ...
"‘sprintf’ output between 30 and 82 bytes into a destination of size xx"
Increasing the buffer for the file name to 83 bytes removes the warning.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2019-08-23 19:57:06 +02:00
Oliver Hartkopp 83a1210b75 candump: preserve silent mode with enabled log file output format
As seen in https://github.com/linux-can/can-utils/issues/150 the logfile
format switch ignores the silent mode switch.

Fix this by checking the silent mode when using logfile format on stdout.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2019-08-23 19:40:27 +02:00
Oliver Hartkopp 818dacd78f candump: fix formatting of status messages regarding standard output
As remarked by Victor in https://github.com/linux-can/can-utils/issues/150
the output in the case of silent mode has puzzled line feeds.

Reported-by: Victor Cushman <VictorSCushman@gmail.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2019-08-23 19:34:10 +02:00
Yegor Yefremov 7b7331976a Add SPDX identifiers
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2019-06-19 12:24:24 +02:00
Oliver Hartkopp c45a17e96b candump: try to switch bridge socket into CAN FD mode
When using the -b/-B option to send received CAN frames to the brigde interface
the sending failed when processing CAN FD frames. This patch enables CAN FD on
the socket for the bridging interface.

https://github.com/linux-can/can-utils/issues/104

Reported-by: https://github.com/jm3lee
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2018-10-24 09:36:55 +02:00
Oliver Hartkopp 8681e57230 candump: fix EFF CAN ID representation in CAN filter parameter
The documentation stated that the CAN ID is assumed to be an extended CAN
identifier (29 bit ID / EFF) when "can_id and can_mask are both 8 digits".
The check for the CAN ID length to be 8 is common in other CAN utils
(e.g. cansend) but it has never been implemented in candump.

This patch adds that check for EFF CAN IDs and clarifies the documentation.

Thanks to Nick for pointing out this inconsistency!

Reported-by: Nick Elmschig <nick@ikerobotics.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2018-10-23 21:22:11 +02:00
Nick Elmschig 371d8e6da4 Fix CAN ID in candump usage, should be 12345678 2018-10-08 13:26:15 -07:00
Oliver Hartkopp 33640c8643 candump: make hardware timestamps Linux version agnostic
Hardware timestamps have been introduced in Linux 2.6.30. Check for the
availability of SO_TIMESTAMPING and print an appropriate error message if
missing. Additionally fix some style issues and define the proper length
of ctrlmsg[].

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2017-12-06 10:16:09 +01:00
Fabián Inostroza eeb0dc2390 Fix style and add reference to timestamps struct offset. 2017-12-02 16:43:52 -03:00
Fabián Inostroza 3195717961 Remove deprecated flag. See timestamping.txt 2017-12-02 16:07:04 -03:00
Fabián Inostroza fbebc61881 Add option to read hardware timestamps. 2017-12-02 03:33:43 -03:00
Oliver Hartkopp 4c8fb05cb4 can-utils: remove strict-aliasing compiler warning
GitHub user 'crossband' raised an issue regarding the strict-aliasing compiler
warning in his specific setup: https://github.com/linux-can/can-utils/issues/42

In fact memcpy() and memset() are a better solution than the former pointer
magics, so remove the issues and the compiler warning flag too.

Reported-by: crossband (https://github.com/crossband)
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2017-07-01 19:01:01 +02:00
Oliver Hartkopp cddb2612b1 candump: print correct interface names on stderr
The cmdlinename[i] output contains the filter definitions e.g.
'can0,300:700' but you want to see only 'can0' when printing on stderr.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2016-08-31 19:14:07 +02:00
ajneu 7a9e10173a don't exit when device goes down 2016-08-30 20:04:39 +02:00
Oliver Hartkopp 47fbe8fec2 candump: check for joined filter support at runtime
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2015-04-01 12:58:27 +02:00
Oliver Hartkopp 1a2467ed29 candump: support new raw socket option to join the given CAN filters
The CAN_RAW socket can set multiple CAN identifier specific filters that lead
to multiple filters in the af_can.c filter processing. These filters are
indenpendent from each other which leads to logical OR'ed filters when applied.

This socket option joines the given CAN filters in the way that only CAN frames
are passed to user space that matched *all* given CAN filters. The semantic for
the applied filters is therefore changed to a logical AND.

This is useful especially when the filterset is a combination of filters where
the CAN_INV_FILTER flag is set in order to notch single CAN IDs or CAN ID
ranges from the incoming traffic.

Example:
	candump can0,100~7FF,200~7FF,400~7FF	(logical OR'ed filters)
	candump can0,100~7FF,200~7FF,400~7FF,J	(logical AND'ed filters)

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2015-03-17 20:30:54 +01:00
Urs Thuermann 0c61f2ac4c candump: fix off-by-one error in dropcount calculation
Calculations using unsigned integer types are done modulo U*INT_MAX+1,
so you get the correct difference of two values by simply subtracting.
No special handling for overflow is neccessary.

Signed-off-by: Urs Thuermann <urs@isnogud.escape.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2014-10-23 19:27:09 +02:00
Oliver Hartkopp 53779e43eb candump: use UINT32_MAX define from stdint.h
Use the UINT32_MAX define from stdint.h instead of writing it into a comment.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2014-05-24 21:44:51 +02:00
Oliver Hartkopp 31ccf45dc4 candump: reduce printf calls for logfile format
The creation of the logfile format was using fprint_canframe() and two other
fprintf() calls to produce a single logfile format line. Instead of using
fprint_canframe() use sprint_canframe() directly and reduce the printf() calls
from three to one.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2014-05-05 21:29:56 +02:00
Uwe Kleine-König 03c1bacfde can-utils: trivial: fix typos concerning "separation" and "useful"
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2013-08-15 21:09:27 +02:00
Alexander Stein e5c81aa221 candump: Add timeout option if no message has been received
Signed-off-by: Alexander Stein <alexander.stein@systec-electronic.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2013-02-12 17:56:35 +01:00
Oliver Hartkopp d547068185 candump: unify displayed timestamp length to 10 digits
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2012-11-24 21:31:01 +01:00
Oliver Hartkopp 836d3cc012 remove obsolete SVN ID tags
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2012-11-14 20:57:16 +01:00
Oliver Hartkopp d166ecc8a3 candump: new option to print extra message information
Added -x option to print extra message infos per frame:

  RX/TX : Indicates whether the frame was sent or received from the local host
  BRS   : bit rate setting enabled (CAN FD only)
  ESI   : error state indicator (CAN FD only)

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2012-11-14 20:06:50 +01:00
Oliver Hartkopp fcbdf71f1a Add new format option when mixing EFF/SFF frame output
Added new view CANLIB_VIEW_INDENT_SFF flags to fix the sloppy output of
fprint_long_canframe() when mixing EFF & SFF CAN identifiers.

candump: Once an EFF frame is detected the indention is enabled.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2012-11-14 19:59:18 +01:00
Oliver Hartkopp e7631bd7f9 canfd: upgrade tools to support CAN FD for Linux 3.6
This is a major upgrade of the basic tools to handle CAN FD frames.
The library to parse and print CAN frames and logfiles has been extended.

In detail:

 asc2log.c      |    5 +
 candump.c      |   24 ++++---
 cangen.c       |  172 +++++++++++++++++++++++++++++++++------------------
 canlogserver.c |   28 +++++---
 canplayer.c    |   25 ++++---
 cansend.c      |   55 ++++++++++++----
 lib.c          |  189 ++++++++++++++++++++++++++++++++++++++-------------------
 lib.h          |  109 ++++++++++++++++++++++++--------
 log2asc.c      |    8 +-
 log2long.c     |   26 ++++++-
 10 files changed, 440 insertions(+), 201 deletions(-)

asc2log.c / log2asc.c
- updates for new lib functions
- still can only handle CAN2.0 frames (no new info about ASC file layout)

log2long.c / canlogserver.c / canplayer.c
- updates for new lib functions to handle CAN FD

lib.h / lib.c
- reworked lib functions to handle CAN FD
- parse_canframe() now returns CAN_MTU and CANFD_MTU on success, 0 at failure
- added can_dlc2len() and can_len2dlc() helpers
- moved hexstring2candata to hexstring2data to support simple byte buffers
- in the long CAN frame representation use %03X/%08X instead of %3X/%8X
- introduced unified buffer size definitions for ASCII CAN frames
- updated documentation

cangen.c
- support CAN FD frames (added -f option to create CAN FD frames)
- added -m option ('mix') to create random extended / RTR / CAN FD frames
- fixed the 'fixed data' option which was zero'ing the payload by the time
- updated help text

candump.c
- support CAN FD frames (print, bridge, log)
- distinguish frame types by length info: [0] = CAN2.0 [00] = CAN FD frame

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2012-11-14 19:47:21 +01:00
Yegor Yefremov 5d2964c5ff Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2012-04-19 17:39:53 +02:00
Marc Kleine-Budde 722a09116d treewide: replace berlios contact email by linux-can@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2012-01-11 12:14:15 +01:00
Wolfgang Grandegger 796475677a candump: add option -e to dump error messages in human readable format
If "candump" is called with the option "-e", the error messages are
dumped in human readable format:

  # candump -e any,0:0,#FFFFFFFF
  ...
  can0  20000088  [8] 00 00 80 19 00 00 00 00   ERRORFRAME
        protocol-violation{{error-on-tx}{acknowledge-slot}}
        bus-error
        error-counter{tx{128}rx{97}}
  ...
  can0  2000008C  [8] 00 08 80 19 00 00 00 00   ERRORFRAME
        controller-problem{tx-error-warning}
        protocol-violation{{error-on-tx}{acknowledge-slot}}
        bus-error
        error-counter{tx{128}rx{97}}

"candump" actually calles a library function snprintf_can_error_frame()
to do the formatting. It could be used for other purposes as well.

Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
Acked-by: Kurt Van Dijck <kurt.van.dijck@eia.be>
2011-02-14 15:49:27 +00:00
Oliver Hartkopp c9e79e55c3 candump: Avoid ragged output of timestamp values when printing differential
timestamps (commandline option -td).
Idea & original patch by Uwe Bonnes.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2011-01-19 17:43:07 +00:00