Commit Graph

42 Commits (27030b3e54911727142d71c60c93ea57699fa592)

Author SHA1 Message Date
Oliver Hartkopp 27030b3e54 lib: make sprint_canframe the buffer size aware snprintf_canframe
Make sure the library functions to convert CAN frames into ASCII
represenation do not exceed the given buffer size. This also applies
to the long CAN frame output library function.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-03-12 19:11:58 +01:00
Oliver Hartkopp 09aa4d55bf asc2log: unify curly brackets at function definition
Move the curly brackets to the start of the next line to follow the
common coding style in can-utils.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-03-06 11:42:13 +01:00
Oliver Hartkopp 04312e5a10 candump/lib: make sprint_canframe CAN XL aware
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-27 18:23:29 +01:00
Oliver Hartkopp 8d8d17e25d asc2log: remove fprint_canframe usage
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-27 10:11:17 +01:00
Oliver Hartkopp 2522ec127b lib: integrate CAN FD indicator into dual-use struct canfd_frame
Replace maxdlen parameter and use CANFD_FDF flags instead.

Since the CANFD_FDF flag has been introduced in can.h the struct canfd_frame
can be used for CAN CC and CAN FD frames as a dual-use data structure.

Remove the extra maxdlen parameter in library calls and only use the
CANFD_FDF flag to differentiate the two CAN CC/FD frames.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-24 11:28:35 +01:00
TyK ceda93bd5c timestamp formatting: always use 64-bit for timesstamp formatting.
Using C99 `unsigned long long` to format `struct timeval`'s `tv_sec`
and `tv_usec`, fix incorrect print under some 32bit platform which
 using time64.
2023-11-28 08:30:27 +08:00
weichslgartner 34732eddeb fixed signed integer overflow in asc2log.c:100
Issue:
echo "0.0000 0  Rx   d 8 8D 00 10 01 00 82 01 00
      0.200000000000000000 0- 0000  Rx   d 8 8D 00 10 01 00 82 01 00" |
./asc2log

can-utils/asc2log.c💯20: runtime error: signed integer overflow:
200000000000000000 * 100 cannot be represented in type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior asc2log.c💯20
2022-06-13 17:42:33 +02:00
Oliver Hartkopp d320a4a871 asc2log: reduce code duplication
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2022-05-01 13:57:25 +02:00
Oliver Hartkopp 81e76a7a0d log asc converter: support len8_dlc for Classical CAN frames part 2
In commit 6799180bd0 ("log asc converter: support len8_dlc for Classical
CAN frames") the len8_dlc support was accidentally only implemented for
the new CANFD asc format. This patch adds len8_dlc support for the 'old'
Classical CAN asc format which in fact always supported len8_dlc.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2022-05-01 13:47:57 +02:00
Oliver Hartkopp 2bdb93924e asc2log: make sure we have read the dlc value with sscanf()
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2022-05-01 13:02:08 +02:00
Oliver Hartkopp afc6a324da asc2log: move check for error frames
We need to check for different sscanf() failures and the number of read
items in the data frames. So move the simple check to the beginning.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2022-05-01 12:55:49 +02:00
Simon Tegelid 9c2de072a0 asc2log: Correct usec overflow handling
This commit fixes these lines
(1614188635.1000000) can1 4A8##28001E9A318ACC0 R
to become this
(1614188636.000000) can1 4A8##28001E9A318ACC0 R
2021-04-16 14:30:50 +02:00
Oliver Hartkopp 972054446a can: rename CAN FD related can_len2dlc and can_dlc2len helpers
The helper functions can_len2dlc and can_dlc2len are only relevant for
CAN FD data length code (DLC) conversion.

Update to latest in-kernel naming scheme:

can_dlc2len -> can_fd_dlc2len to get the payload length from the DLC
can_len2dlc -> can_fd_len2dlc to get the DLC from the payload length

Suggested-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-11-22 19:54:58 +01:00
Oliver Hartkopp 6799180bd0 log asc converter: support len8_dlc for Classical CAN frames
The CANFD format in asc logfiles can be used to describe Classical CAN
frame content too. As this CANFD format has two different elements to
transport the payload length and the 'raw data length code' the new
len8_dlc option now allows to support the full qualified conversion.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-11-22 19:47:24 +01:00
Rosen Penev 204235c9ce make struct initialization C99 compatible again
Mainly change {} to { 0 } to remove a pedantic warning.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-14 13:29:13 +02:00
Rosen Penev f766174677
custom if statement reordering
It makes more sense to return before hitting else.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-12 23:48:38 -07:00
Rosen Penev 48bb69bc7b
remove basic usages of memset with {}
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-12 23:28:58 -07: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 3e67b5cbd1
clang-tidy: remove pointless return
Found with readability-redundant-control-flow

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-12 23:28:57 -07:00
Rosen Penev 17a5fe6022
clang-tidy: do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-12 23:28:22 -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
Oliver Hartkopp 9b75c6020f asc2log: support milliseconds resolution in date/time string
While strptime() does not support fractions of seconds in the date/time
string some new asc files support the milliseconds resolution.

When detecting this new format the msecs are retrieved by a separate
sscanf() invocation and added to the timeval's tv_usec element.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-05-10 19:22:53 +02:00
Oliver Hartkopp 3bb659d18d asc2log: fix handling for RTR frames in Classic CAN mode
Fix reading of the RTR representation without and with DLC (v8.5+ tools).

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-05-10 15:09:55 +02:00
Oliver Hartkopp 9cde2ebe8f asc2log: fix date string detection
The former check was too complex and did not catch all valid cases.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-05-10 14:41:34 +02:00
Oliver Hartkopp ad9fc28f9e asc2log: add sanity checks for search pattern
Add some more sanity checks and increase readability for the sscanf()
procedure to read a CANFD tagged line.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-05-10 10:44:11 +02:00
Oliver Hartkopp df0b25c17e asc2log: support CANFD tagged asc file content
Handles CANFD asc files with classic CAN and CAN FD frames.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-05-09 18:42:55 +02:00
Oliver Hartkopp 3c8197e4d1 asc2log: make date time sting milliseconds aware
strptime() does not support milliseconds but the latest ASC logfile
also provides a fraction of seconds, e.g.

date Fri May 8 08:49:04.052 pm 2020

Read the value into the year variable before parsing the real year.
We will therefore omit the milliseconds resolution for now.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-05-09 18:19:24 +02:00
Oliver Hartkopp 43a3cca54d asc2log: reorder code to prepare CAN FD support
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-05-09 13:10:27 +02:00
Alexander Gerasiov b740fb7fab asc2log.c: Reformat help/usage output to be compatible with help2man.
Signed-off-by: Alexander Gerasiov <gq@debian.org>

Gbp-Pq: Name 0001-asc2log.c-Reformat-help-usage-output-to-be-compatibl.patch
2020-04-27 08:20:08 +03:00
Yegor Yefremov 7b7331976a Add SPDX identifiers
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2019-06-19 12:24:24 +02:00
Marc Kleine-Budde cf949a926a unconditionally define _GNU_SOURCE
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2018-01-09 14:42:17 +01:00
Robert Schwebel dfabea6120 janitorial: asc2log: properly close infile
outfile is closed as well, so do this symmetrically for infile.

Signed-off-by: Robert Schwebel <r.schwebel@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2015-03-06 10:02:35 +01:00
Oliver Hartkopp 61733e322a asc2log: inform about uninstalled locales at date conversion failures
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2013-11-28 16:12:17 +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 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
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
Oliver Hartkopp c8247c8a57 Allow to have 4, 5 or 6 decimal places instead of only 4 & 6. 2010-05-11 10:01:49 +00:00
Oliver Hartkopp 4369ac1c55 Consistencely allow '-?' to get a help text. 2009-01-13 09:32:45 +00:00
Oliver Hartkopp adbe6f9bee Whitespace fixes. Indented the code following Linux styleguide to fix
the mess between tabs and spaces.
2008-06-03 08:46:57 +00:00
Oliver Hartkopp d0b24ffc10 Fixed contradiction in Sourcecode discalimer.
See details at
http://marc.info/?l=linux-netdev&m=119074747913703&w=2
2007-09-27 12:29:32 +00:00
Oliver Hartkopp 3d26e6f710 Fixed typo in log2asc.c
Added asc2log.c to convert existing CANoe/CANalyser logfiles into socketcan
logfiles (with absolute and full qualified timestamps).
The date and the other settings (dec/hex absolute/relative) are taken from
the head of the ASC files.
2007-01-10 17:18:01 +00:00