Commit Graph

41 Commits (ac4e9961f81cbb32ee2620a8a419521de352c6cc)

Author SHA1 Message Date
Oliver Hartkopp ac4e9961f8 can-utils: fix sign-compare warnings
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-13 09:05:52 +02:00
Oliver Hartkopp dd16f2603b can-utils: make local functions static
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-03-12 20:10:00 +01:00
Marc Kleine-Budde e4ba924b21 slcanpty: print_usage(): factor out help text into separate function
...and use single fprintf() call only.
2024-02-19 08:46:31 +01:00
Marc Kleine-Budde 7683efab41 slcanpty: convert towards kernel coding style 2024-02-19 08:45:55 +01:00
Oliver Hartkopp 2643d28a57 slcanpty: silence warning for signed index for the buf array
slcanpty.c: In function ‘pty2can’:
slcanpty.c:105:21: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
  105 |         buf[nbytes] = 0;
      |         ~~~~~~~~~~~~^~~
slcanpty.c:58:21: note: at offset [-2147483647, -1] into destination object ‘buf’ of size 200
   58 |         static char buf[200];
      |                     ^~~

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-02-14 21:03:11 +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
Vincent Mailhol 0cfd56d613 lib: add pr_debug() macro
Add the pr_debug() macro so that:

  #ifdef DEBUG
  	printf("foo");
  #endif

can be replaced by:

  	pr_debug("foo");

Apply the pr_debug() macro wherever relevant.

Currently, there is no consensus whether debug messages should be
printed on stdout or stderr. Most of the modules: canbusload.c,
candump.c and canlogserver.c use stdout but
mcp251xfd/mcp251xfd-dev-coredump.c uses stderr. Harmonize the behavior
by following the major trend and make
mcp251xfd/mcp251xfd-dev-coredump.c also output to stdout.

slcanpty.c does a #define DEBUG, meaning that debug is always turned
on for this file. Remove this and make debug an option like every
other files.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-5-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-11-15 09:49:52 +01:00
Vincent Mailhol 4c9f046615 slcanpty: remove redundant asc2nibble()
asc2nibble() is already defined in lib.h. Include lib.h in slcnpty.c
so that asc2nibble() does not need to be redefined a second time and
adjust the Makefile accordingly.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-2-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-11-15 09:44:51 +01:00
Oliver Hartkopp f7307b8290 can-utils: check for return values of if_nametoindex()
if_nametoindex() returns zero and a specific errno in the case the network
interface does not exist. The missing check leads to the use of the 'any'
CAN device but leaves the user alone as the user gets no error message.

Reported-by: Lothar Rubusch <lotophagon@protonmail.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2021-10-18 09:37:46 +02:00
Marc Kleine-Budde a5c049d37a slcanpty: add missing include sys/select.h
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2020-06-29 18:20:18 +02:00
Marc Kleine-Budde 57949154cc slcanpty: sort includes alphabetically
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2020-06-29 18:20:11 +02:00
Oliver Hartkopp 1665abf46f can-utils: fix missing include of libgen.h
The basename() function needs libgen.h to be included as otherwise this
will fail to compile in some environments.

Reported-by: Robert Schwebel <r.schwebel@pengutronix.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-04-28 19:14:52 +02:00
Oliver Hartkopp 5ca66d7bea slcanpty: simplify tool decription in help text
Simplify tool description and format the empty lines like in other
(e.g. slcand) tools.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2020-04-27 11:09:05 +02:00
Alexander GQ Gerasiov f638cdc79b slcanpty.c: Reformat help/usage output to be compatible with help2man.
Gbp-Pq: Name 0029-slcanpty.c-Reformat-help-usage-output-to-be-compatib.patch
2020-04-27 08:20:09 +03: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
Fabrice Fontaine e9590b1ca7 fix include to find SIOCGSTAMP with latest kernel
In linux kernel commit 0768e17073dc527ccd18ed5f96ce85f9985e9115
the asm-generic/sockios.h header no longer defines SIOCGSTAMP.
Instead it provides only SIOCGSTAMP_OLD.

The linux/sockios.h header now defines SIOCGSTAMP using either
SIOCGSTAMP_OLD or SIOCGSTAMP_NEW as appropriate. This linux only
header file is not pulled so we get a build failure.

canlogserver.c: In function 'main':
canlogserver.c:404:21: error: 'SIOCGSTAMP' undeclared (first use in this function); did you mean 'SIOCGRARP'?
     if (ioctl(s[i], SIOCGSTAMP, &tv) < 0)
                     ^~~~~~~~~~
                     SIOCGRARP
canlogserver.c:404:21: note: each undeclared identifier is reported only once for each function it appears in

Fixes:
 - http://autobuild.buildroot.org/results/363de7d9bf433be8bc47ba4ee52ae0bb80fa9021

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2019-07-14 22:14:10 +02:00
Yegor Yefremov 59f92965b9 Relicense GPL-2.0-or-later files to GPL-2.0-only
This way all licenses in the project will be homogenised.

Acked-by: Marc Kleine-Budde <mkl@pengutronix.de>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Acked-by: Sven Schmitt <sven.schmitt@gmx.net>
Acked-by: Oleksij Rempel <ore@pengutronix.de>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Brennan Ashton <bashton@brennanashton.com>
Acked-By: IOhannes m zmölnig <zmoelnig@iem.at>
Acked-by: Frank Theile <ftheile@grundfos.com>
Acked-by: Wolfgang Grandegger <wg@grandegger.com>
Acked-by: Jeremiah Mahler <jmmahler@gmail.com>
Acked-by: Jonathan Challinger <mr.challinger@gmail.com>
Acked-by: Cheng-Lung Lee <chenglung@gmail.com>
Acked-by: Ramesh Shanmugasundaram <rashanmu@gmail.com>
Acked-by: Mans Rullgard <mans@mansr.com>
Acked-by: Søren Holm <sgh@sgh.dk>
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2019-07-10 14:01:23 +02: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
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
Sven Schmitt f5fb7317aa treewide: use if_nametoindex to avoid overflows
replaced strcpy(if_name, argv[x]) + ioctl by if_idx = if_nametoindex(argv[x])
to avoid overflows caused by long user input.

Signed-off-by: Sven Schmitt <sven.schmitt@gmx.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2015-06-30 21:00:04 +02:00
bombilee dc374b074b add 'v' command response
add v command response. Some software like USBtinViewer using v for software version.
Tested on USBtinViewer 1.0

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2015-05-08 13:00:15 +02:00
Yegor Yefremov c7aa0b7051 slcanpty: declare command buffer static
ASCII command buffer char buf[200] must be declared as static,
because it holds incomplete commands between pty2can() calls.
Without static it is not guaranteed, that buf retains the same
data between calls.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2014-01-16 16:31:50 +01:00
Oliver Hartkopp c05267faca slcanpty: probe stdin capabilities at startup
/dev/null returns EOF therefore select() finishes immediately.
Now EOF is probed on start.

Other /dev/null as stdin workarounds:
- lscanpty ... < /dev/ptmx (dirty but works)
- cat </dev/null | slcanpty ... (doesn't work for me and even the patch
  is "disabled" then)

Signed-off-by: Janusz Uzycki <j.uzycki@elproma.com.pl>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2013-06-11 22:21:38 +02:00
Oliver Hartkopp d469336649 slcanpty: fix pty terminal flags for correct NL/CR handling
Signed-off-by: Janusz Uzycki <j.uzycki@elproma.com.pl>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2013-06-11 22:11:19 +02:00
Oliver Hartkopp c9422deb0b slcanpty: handle incomplete messages from pty correctly
Make sure that we have minimum one complete SLCAN messages from pty in the
receive buffer before we start processing the received SLCAN message.

Fragments of a received incomplete message are stored to be appended by the
next read() syscall in pty2can().

This patch is a rework of an initial patch from Ulrich Escher. Tnx!

Reported-by: Ulrich Escher <git@myvdr.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2013-06-08 12:57:17 +02:00
Oliver Hartkopp 704d5f22d1 slcanpty: detect that master PTY descriptor closed
Terminate slcanpty when the pty file descriptor is closed instead of performing
an endless loop in the select() statement.

Reported-by: Janusz Uzycki <j.uzycki@elproma.com.pl>
Signed-off-by: Janusz Uzycki <j.uzycki@elproma.com.pl>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2013-06-07 20:02:57 +02:00
Oliver Hartkopp 221794dbe8 slcanpty: Add support for the Unix 98 pseudo-terminal interface
Most Linux distributions do not configure their kernels to use the BSD
pseudo-terminal interface (/dev/pty* and /dev/tty*) anymore; they uses the
Unix 98 pseudo-terminal interface instead (/dev/ptmx and /dev/pts/*).

http://www.kernel.org/doc/man-pages/online/pages/man4/pts.4.html

This change follows the slcan_attach changes:
http://sourceforge.net/tracker/index.php?func=detail&aid=3467521&group_id=146269&atid=764681

Signed-off-by: Ulrich Escher<git@myvdr.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2012-12-20 11:37:43 +01:00
Oliver Hartkopp 0fb5680a61 slcanpty: fix wrong usage of nbytes variable
nbytes is used after writing the CAN frame to check for an additional command
in the string buffer. Therefore using nbytes while writing the CAN frame is
wrong. Replace it with 'tmp' which can be used here without problems.

Signed-off-by: ulrich escher<git@myvdr.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2012-11-26 21:44:22 +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
Yegor Yefremov 4d3a002ec1 can-utils: cleanup headers
- add missing sys/socket.h: on some systems (like Android)
have SOCK_RAW definition directly in sys/socket.h

- use sys/wait.h instead if wait.h

- include termios.h explicitly (Android)

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2012-03-20 11:16:43 +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 8975dcb574 Spagetti code cleanup:
Moved conversions into separate functions can2pty() and pty2can().
Updated and enhanced some comments.
Variable name cleanups inside the separate functions.
Fix handling on wrong pty commands (was a wrong 'continue' statement).
2009-02-15 17:40:32 +00:00
Oliver Hartkopp c588f0d0b2 Allow SLCAN RTR frames without data length code field. 2009-02-04 16:51:04 +00:00
Oliver Hartkopp 6cc05e08f0 Some more implementation to make it work with a certain application. 2009-02-04 13:18:44 +00:00
Oliver Hartkopp 4cf2b0f931 Use rxbuf[] for acknowledges. 2009-02-03 20:12:34 +00:00
Oliver Hartkopp afae11f1c8 Implemented ACK/NACK replies for ASCII commands.
Added 'O'pen and 'C'lose functionality.
2009-02-03 13:59:17 +00:00
Oliver Hartkopp af858087e6 Added timestamp handling with Z0 or Z1 command. 2009-02-03 11:59:53 +00:00
Oliver Hartkopp baa90a135a Add can_id/can_mask filter handling which is defined in the slcan protocol (m/M). 2009-01-21 09:17:20 +00:00
Oliver Hartkopp c8be6085a4 Removed sanity check for received slcan ASCII data
as this is done with ASCII comparision three lines above.
2009-01-21 07:38:18 +00:00
Oliver Hartkopp 9862da595d Added a proof of concept tool 'slcanpty' which
creates a pty for applications using the slcan ASCII protocol and
converts the data to a CAN network interface (and vice versa).

This can be used for existing applications to run on SocketCAN.
2009-01-20 23:06:01 +00:00