Commit Graph

72 Commits (97c8ccdbbf94d32091c1f79cf7699e88a349c730)

Author SHA1 Message Date
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
Oliver Hartkopp 02b330a87d cangen: fix help text for burst send option
The option '-c' requires a value. Add this hint to the help text.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2021-04-07 13:42:28 +02:00
Thomas Kopp fe07dc5837 cangen: add possibility to generate random ID odd/even
Use this for stress testing, when sending with two CAN controllers on
the same CAN bus to avoid broken CAN frames due sending the same
CAN-id.
2021-02-10 21:16:29 +01: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 1ba0c576ae cangen: add support for Classic CAN raw DLC values
A new option '-8' has been added to generate Classical CAN frames with
DLC codes from 0 .. 15.

Fixed and random mode implemented by Oliver Hartkopp.
Incremental DLC mode 'cangen -8 -Li can0' implemented by Vincent Mailhol.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-11-22 19:13:21 +01:00
Oliver Hartkopp 5d5ccf38ee fix include order and unify local include placement
In commit https://github.com/linux-can/can-utils/commit/b153fe3f3591
("clang-tidy: sort includes alphabetically") the position of the "lib.h"
include has been moved in a way that struct canfd_frame has not been
defined anymore and lead to a warning when compiling cangen.c

This patch reverts that specific move and unifies the location of local
includes at the end of the include list.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-10-13 10:03:19 +02: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 33f3593436
clang-tidy: use uppercase literal
Found with readability-uppercase-literal-suffix

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 7729c046c5 cangen: support ESI bit for CAN FD frame generation
The CAN FD frames support BTR and ESI as special flags. While BTR could
be generated by cangen the ESI bit could not be generated so far.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-05-10 12:03:35 +02:00
Rasmus Pedersen 729e346d31
cangen.c: added -c option for bursty output. (#201)
added -c option for bursty output.
specify -c 100 to have 100 packets sent in burst before a gap.
use for example -p 1000 to avoid TX buffer full errors
2020-05-05 10:14:58 +02:00
Oliver Hartkopp 7575d43fd2 cangen: fix doubled description in help text
The help2man conversion created a second application description.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-04-29 19:11:41 +02:00
Alexander Gerasiov f503097a38 cangen.c: Reformat help/usage output to be compatible with help2man.
Signed-off-by: Alexander Gerasiov <gq@debian.org>

Gbp-Pq: Name 0006-cangen.c-Reformat-help-usage-output-to-be-compatible.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
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 5109ca4f3c cangen/cansend: fix typo 'ist' -> 'is'
Reported-by: Stanislavs Rogozins <stanislavs.rogozins@gmail.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2017-06-29 19:55:52 +02:00
Ramesh Shanmugasundaram 42ee04ff64 cangen: reset frame flags at the start of iteration (#16)
This patch fixes a bug in cangen.c

Bug: When used with -m option, if a CAN FD frame with BRS option set is
sent, that flag never gets cleared for the subsequent frames.

Fix: Reset frame.flags at the start of iteration.

Signed-off-by: Ramesh Shanmugasundaram <ramesh.shanmugasundaram@bp.renesas.com>
2016-06-30 21:33:16 +02:00
Sven Schmitt 4a154cf3c4 cangen: added -b switch enabling bitrate switch in canfd frames.
Signed-off-by: Sven Schmitt <sven.schmitt@gmx.net>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2015-10-14 21:22:35 +02:00
Sven Schmitt 3f04e8a1fe cangen: fixed coding style
Signed-off-by: Sven Schmitt <sven.schmitt@gmx.net>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2015-10-14 21:21:20 +02:00