Commit Graph

90 Commits (master)

Author SHA1 Message Date
Oliver Hartkopp 374fecde09 cangen: disable generation of unsupported CAN frame types in mixed mode
The mixed mode is able to automatically detect the potential supported
CAN frame types CAN CC/FD/XL by checking the CAN device MTU at startup.

Usually the MTU shows which CAN frame types can be sent but in the case of
CAN XL in CANXL-only mode CC and FD frames can not be sent on the CAN_RAW
socket.

Since this patch [1] the CAN_RAW socket rejects unsupported CAN frames and
returns -EINVAL as error code. With this change in cangen the CC and FD
frame generation can be disabled in mixed mode at runtime.

[1] https://lore.kernel.org/linux-can/20251125123859.3924-17-socketcan@hartkopp.net/T/#u

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2025-12-03 16:09:12 +01:00
Oliver Hartkopp bfbf0c851f cangen: auto enable FD/XL content in mixed mode
Automatically create FD/XL content in mixed mode when the CAN interface
is capable to deal with it.

Suggested-by: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2025-12-03 16:09:12 +01:00
Oliver Hartkopp 6b46063eee cangen: add CAN XL RRS bit generation
Allow to generate Remote Request Substitution bit content.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2025-06-24 19:48:14 +02:00
Zhu Yi 6eb97b57c5 cangen: support socket priority
Add '-P' option for allow user to set the socket priority. This can be
useful in conjuction with queuing discipline.

Signed-off-by: Zhu Yi <yi.zhu5@cn.bosch.com>
Signed-off-by: Hubert Streidl <hubert.streidl@de.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
Link: https://lore.kernel.org/r/20250120162332.19157-1-mark.jonas@de.bosch.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2025-01-20 18:01:10 +01:00
Oliver Hartkopp 8d7d7650d4
can-utils: fix sign-compare warnings (#513)
Fixing several build issues reported by Gary Bisson when he was building
can-utils with clang (AOSP14).

URL: https://github.com/linux-can/can-utils/pull/512
Reported-by: Gary Bisson (https://github.com/gibsson)

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-04-24 20:02:02 +02:00
Oliver Hartkopp 001b230b10 cangen: initialize reserved struct CAN(FD) frame elements
With 'cansend' and other tools the reserved elements are set to zero.
Fix this missing initialization in 'cangen'.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-03-18 12:35:29 +01:00
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 6f7b146166 cangen: unify curly brackets and apply review feedback
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-03-06 11:57:54 +01:00
Oliver Hartkopp 87a3058019 cangen: support generation features for CAN XL specific content
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-03-04 22:50:52 +01:00
Oliver Hartkopp 443312d6ce cangen: add initial CAN XL support
TODO:
- Test all features
- make CAN XL content variable

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-03-03 21:29:49 +01:00
Oliver Hartkopp 09b8a6431f cangen: add missing long CAN frame view for len8_dlc and eff
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-03-02 22:36:49 +01:00
Oliver Hartkopp 9a21de13f8 cangen: convert to CAN frame unit type
As preparation for CAN XL support.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-03-02 22:36:36 +01:00
Oliver Hartkopp 1da219922d unify buffer size for ASCII CAN frame string representations
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-29 07:10:34 +01:00
Oliver Hartkopp 3644a54d5b candump/lib: make sprint_long_canframe CAN XL aware
The 'long' CAN frame representation does not really fit for CAN XL content.
Therefore just a cropped output is provided to be able to see the CAN XL
header information and up to 64 byte of data (without binary or swap
formating options). To get the full qualified CAN XL content use the log
file format.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-27 20:11:46 +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 9d900f913c cangen: remove fprint_(long_)canframe usage
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-27 10:57:55 +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
Marc Kleine-Budde f73ad6a613 cangen: convert towards kernel coding style 2023-12-11 09:37:09 +01:00
Oliver Hartkopp a3b60a70fe cangen: update CAN FD check to cope with CAN XL interfaces
The check for CAN FD capable interfaces only checked for CANFD_MTU to
enable the generation of CAN FD frame content. As CAN XL capable CAN
interfaces are able to handle CAN FD frames too the check has to be
extended for CANXL_MTU interfaces.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2023-05-09 14:30:16 +02:00
Marc Kleine-Budde 085b5546a5 cangen: main(): avoid loop initial declaration
| cangen.c: In function ‘parse_dataoptarg’:
| cangen.c:422:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
|   for (int i = 0; i < CANFD_MAX_DLEN && i < arglen / 2; i++) {
|   ^
| cangen.c:422:2: note: use option -std=c99 or -std=gnu99 to compile your code
| cangen.c: In function ‘main’:
| cangen.c:796:4: error: ‘for’ loop initial declarations are only allowed in C99 mode
|     for (int i = 0; i < frame.len; i++) {
|     ^

Reported-by: https://github.com/yannS2016
Link: https://github.com/linux-can/can-utils/issues/428
Fixes: e409aa4c8c ("cangen: new generation mode - partially randomized payload (-D)")
2023-04-30 21:01:19 +02:00
Marc Kleine-Budde 3c9fd96881 cangen: parse_dataoptarg(): avoid loop initial declaration
| cangen.c: In function ‘parse_dataoptarg’:
| cangen.c:422:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
|   for (int i = 0; i < CANFD_MAX_DLEN && i < arglen / 2; i++) {
|   ^
| cangen.c:422:2: note: use option -std=c99 or -std=gnu99 to compile your code
| cangen.c: In function ‘main’:
| cangen.c:796:4: error: ‘for’ loop initial declarations are only allowed in C99 mode
|     for (int i = 0; i < frame.len; i++) {
|     ^

Reported-by: https://github.com/yannS2016
Link: https://github.com/linux-can/can-utils/issues/428
Fixes: e409aa4c8c ("cangen: new generation mode - partially randomized payload (-D)")
2023-04-30 20:07:24 +02:00
Yasushi SHOJI 74e0d28d1a cangen: Follow Bash exit status when signaled
Bash and many other shells use 128 + signum as the exit status when a
program get signal and exit.  Follow the common behavior so that we
know how the programs are killed.

Signed-off-by: Yasushi SHOJI <yashi@spacecubics.com>
2023-03-20 10:22:01 +09:00
Marc Kleine-Budde cdc617545f cangen: print_usage(): add missing newlines
Fixes: f55ea38d14 ("cangen: add option for absolute timeouts")
Fixes: c6f2cf7c2f ("cangen: add support for SO_TXTIME")
2023-02-07 19:57:08 +01:00
majkk1 e409aa4c8c cangen: new generation mode - partially randomized payload (-D)
Part of the fixed data payload can be randomized using the 'x' character.
Nibbles marked with 'x' will be randomized.

For example $ vcan0 -D 11xx3344DEADBEEF -L 8:
 -> second byte of the payload will be randomized.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2023-01-28 19:00:57 +01:00
Marc Kleine-Budde 77ec9b3c2d Revert "cangen: use if_nametoindex() to avoid overflows"
This reverts commit 1f96d674c0.

Link: https://github.com/linux-can/can-utils/pull/396
Link: 1f96d674c0 (commitcomment-97455025)
2023-01-20 09:58:44 +01:00
Marc Kleine-Budde c6f2cf7c2f cangen: add support for SO_TXTIME
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-09 19:47:21 +01:00
Marc Kleine-Budde 9dff4b6393 cangen: do_send_one(): use sendmsg() instead of write()
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-08 10:55:19 +01:00
Marc Kleine-Budde 759524f02c cangen: move write() into separate function
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-08 10:55:18 +01:00
Marc Kleine-Budde f55ea38d14 cangen: add option for absolute timeouts
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-08 10:49:21 +01:00
Marc Kleine-Budde df232c845a cangen: import timespec helper functions
Imported from:

0b5b9845eb

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 16:45:21 +01:00
Marc Kleine-Budde 1ec8eb9ca1 cangen: move sleep directly in font of send()
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 16:45:21 +01:00
Marc Kleine-Budde b6a65b8105 cangen: sort getopt() by order of option in usage
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 99686af630 cangen: print_usage() don't hardcode default burst size
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 4b6f8d62dd cangen: move scope of variable ret
... so that it can be used in other parts of the main() functions, too.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 8fb0e954b3 cangen: remove unneeded masking
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 29b05de39d cangen: mark setsockopt() options as const
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 1f96d674c0 cangen: use if_nametoindex() to avoid overflows
This patch replaces strcpy() + ioctl() by if_nametoindex() to avoid
overflows caused by long user input.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 0f7c1aa23a cangen: use consistent indention scheme of 1 space
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde a130ab5e8d cangen: mark functions as static
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 11a0f19244 cangen: properly initialize struct sockaddr_can addr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 8d493edbbe cangen: checkpatch: put braces on all arms of if statement
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 59c87f149b cangen: checkpatch: don't assign in if statement
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde ad638db75d cangen: checkpatch: remove break after return
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 1d55d085c9 cangen: checkpatch: fix comment style
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 77e785b022 cangen: checkpatch: fix space and newline usage
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 144d77180e cangen: checkpatch: don't split strings over multiple lines
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:28:18 +01:00
Marc Kleine-Budde 213a814da6 cangen: don't compare floating-point gap with ‘==’
Fixes the following warning:

| cangen.c:524:7: warning: comparing floating-point with ‘==’ or ‘!=’ is unsafe [-Wfloat-equal]
|   524 |   if (gap && burst_sent_count >= burst_count) /* gap == 0 => performance test :-] */
|       |       ^~~

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-12-07 15:26:42 +01:00
Stefan Herbrechtsmeier 3342eb42e7 cangen: Do not treat -EINTR as error 2022-01-27 15:53:10 +01:00
Stefan Herbrechtsmeier c142ca63c9 cangen: exit program with failure in case of poll timeout
The poll function returns 0 to indicate a call timed out.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
2022-01-27 14:31:37 +01:00
Oliver Hartkopp 0edab8a402 cangen: improve help text to point out decimal places for the gap value
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2021-10-20 06:12:27 +02:00