The can subsystem communicates with user space using a bcm_msg_head
header, which contains two timestamps. This is problematic for
multiple reasons:
a) The structure layout is currently incompatible between 64-bit
user space and 32-bit user space, and cannot work in compat
mode (other than x32).
b) The timeval structure layout will change in 32-bit user
space when we fix the y2038 overflow problem by redefining
time_t to 64-bit, making new 32-bit user space incompatible
with the current kernel interface.
Cars last a long time and often use old kernels, so the actual
users of this code are the most likely ones to migrate to y2038
safe user space.
This tries to work around part of the problem by changing the
publicly visible user interface in the header, but not the binary
interface. Fortunately, the values passed around in the structure
are relative times and do not actually suffer from the y2038
overflow, so 32-bit is enough here.
We replace the use of 'struct timeval' with a newly defined
'struct bcm_timeval' that uses the exact same binary layout
as before and that still suffers from problem a) but not problem
b).
The downside of this approach is that any user space program
that currently assigns a timeval structure to these members
rather than writing the tv_sec/tv_usec portions individually
will suffer a compile-time error when built with an updated
kernel header. Fixing this error makes it work fine with old
and new headers though.
We could address problem a) by using '__u32' or 'int' members
rather than 'long', but that would have a more significant
downside in also breaking support for all existing 64-bit user
binaries that might be using this interface, which is likely
not acceptable.
Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net> Cc: linux-can@vger.kernel.org Cc: linux-api@vger.kernel.org Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Maximilian Pachl [Sun, 11 Oct 2015 06:48:24 +0000 (08:48 +0200)]
slcan: added listen-only flag
Signed-off-by: Maximilian Pachl <m@ximilian.info> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Sven Schmitt [Sun, 11 Oct 2015 19:08:45 +0000 (21:08 +0200)]
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>
Sven Schmitt [Tue, 13 Oct 2015 07:33:08 +0000 (09:33 +0200)]
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>
Oliver Hartkopp [Thu, 11 Jun 2015 18:48:43 +0000 (20:48 +0200)]
cangw: introduce uid command line option
Similar to referencing iptables rules by their line number this UID allows to
reference created routing jobs, e.g. to alter configured data modifications.
The UID is an optional non-zero value which can be provided at routing job
creation time. When the UID is set the UID replaces the data modification
configuration as job identification attribute e.g. at job removal time.
The UID option is provided by mainline Linux 4.2+
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
The result of (last_log_tv.tv_sec - log_tv.tv_sec) is
unsigned long, so use labs() in order not to trim the
value to int. Make skipgap to unsigned long for the same
reason.
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Oliver Hartkopp [Tue, 17 Mar 2015 19:30:54 +0000 (20:30 +0100)]
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.
Jeremiah Mahler [Fri, 19 Dec 2014 15:22:16 +0000 (07:22 -0800)]
slcand: improve usage examples
The examples in the usage of slcand use a 'ttyslcan0' device which
is an uncommon name. Use a more common ttyUSB0 name which is seen
with CANUSB devices. Also, add an example showing that /dev/ttyUSB0
can be use as well.
Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Oliver Hartkopp [Thu, 20 Nov 2014 22:13:37 +0000 (23:13 +0100)]
isotp[send|recv]: change command line option for padding bytes
Allow to specify the TX and RX padding content separately.
Due to the optional values it is possible to provide either TX or RX values
which enables and set the given values.
Oliver Hartkopp [Sun, 16 Nov 2014 19:38:31 +0000 (20:38 +0100)]
isotp: added support for separate extended address in rx path
As requested by Laurent Vaudoit the extended address can be different in the
tx and he rx path:
(..) how can i have a segmented transfer like this:
0x6a7 0x55 0x10 0x08 ........
0x687 0xAA 0x30 0x00 0x00
0x6a7 0x55 0x21 .....
The connection i need is between two ECU, using IDs 0x6a7/687 and one has
adress extension 0x55, the other 0xAA (this adressing method is used on some
FIAT ECUs for example).
Urs Thuermann [Thu, 23 Oct 2014 17:23:00 +0000 (19:23 +0200)]
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>
Andre Naujoks [Wed, 2 Jul 2014 12:12:58 +0000 (14:12 +0200)]
do not use --symlink for autoreconf
When packaging the can-utils, I understand, that the generation step for
autoconf should be done beforehand. However using the --symlink option in the
autoreconf step installs links instead of the actual files, which leads to a
build failure when trying to build on another host with different autotools
installed.
Signed-off-by: Andre Naujoks <nautsch2@gmail.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
cansniffer: increase resolution for timeout values
As requested by Felix Seitz the timeout for screen updates should be
configurable to values smaller than 100ms. Marc Kleine-Budde provided the
original patch to increase the resolution of the timing relevant variables.
The rotating animation was replaced by a rolling screen update counter.
Additionally the CAN-ID is now printed in the same ASCII hex representation
as the CAN data.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Oliver Hartkopp [Mon, 5 May 2014 20:13:38 +0000 (22:13 +0200)]
lib: optimize sprint_[long_]canframe()
Inspired by the SLCAN rework from Andre Naujoks this patch replaces the
extensive use of sprintf() with simple and efficient ASCII helpers.
valgrind/kcachegrind reported a cyle estimation of about 5.3 million cycles
before and about 1.5 million cycles after the rework (factor 3.55) for the
logging of the exact same CAN content.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Oliver Hartkopp [Mon, 5 May 2014 19:29:56 +0000 (21:29 +0200)]
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>
Oliver Hartkopp [Fri, 21 Feb 2014 20:21:04 +0000 (21:21 +0100)]
Makefile: add large file support (LFS)
Large file support (LFS) in recent C libraries allows 32 bit applications to
create large files with file length values > 0x7FFFFFFF when the filesystem
supports it.
This patch adds large file support to the Makefile, if you don't want LFS use
the autotools version and call configure like this:
./configure --disable-largefile
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Android.mk: canbusload: fix compilation, make use of libcan
In commit
2206f92 canbusload: Add exact CAN frame length calculation (including bitstuffing)
the function to calculate the can_frame_length was moved into a seperate file
(canframelen.c). This patch for the Android makefile adds canframelen.c to the
lib, too and lets canbusload link against the lib.
Tested-by: Yegor Yefremov <yegorslists@googlemail.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Michal Sojka [Thu, 30 Jan 2014 13:38:58 +0000 (14:38 +0100)]
canbusload: Add exact CAN frame length calculation (including bitstuffing)
This adds an algorithm for calculating the exact number of bits a CAN
frame occupies on the bus and uses this algorithm in canbusload. It
also moves the other methods for CAN frame length calculation, already
present in canbusload, to the new file.
The added algorithm calculates the exact number of stuffed bit in a
CAN frame. Note that in order to calculate that correctly, we must
also know the frame's CRC. Hence, the algorithm also includes CRC
calculation routine.
The correctness of the algorithm was verified on an oscilloscope for
several different SFF and EFF frames.
Currently only CAN frames are supported. For CANFD frames, a different
algorithm is needed. CANFD uses different CRC polynomials and
calculates the CRC from the staffed bit-stream (CAN calculates CRC
from de-stuffed bit-stream).
Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
include: can.h: add typedef for __kernel_sa_family_t to make headers self-contained
This patch adds the typedef for __kernel_sa_family_t that was introduced in
Linux v3.1-rc2 (commit 6602a4b net: Make userland include of netlink.h more sane)
in <linux/socket.h>. It must be duplicated here to make the CAN headers
self-contained.
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Uwe Kleine-König [Mon, 13 Jan 2014 21:57:13 +0000 (22:57 +0100)]
include: Remove two unused header files
These seem to have never been used. They entered can-utils in commit 77de10356fe0 (include: import kernel header files into tree) and already
back then only consisted in an #include of a non-existing file.
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Yegor Yefremov [Mon, 13 Jan 2014 08:54:05 +0000 (09:54 +0100)]
slcand: reimplement daemonize routine
Replace daemonize() routine with daemone() system call, because of
conflicting licenses. daemonize() routine was derived from under
GNU Free Documentation License licensed code. This license is
incompatible with GPL-2+.
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Yegor Yefremov [Mon, 13 Jan 2014 13:29:16 +0000 (14:29 +0100)]
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>
Oliver Hartkopp [Mon, 16 Sep 2013 07:08:56 +0000 (09:08 +0200)]
slcand: silence warning about set but unused variable
The dummyFile pointer was only needed to redirect stdxxx streams but it's
content was never used. Re-use the pFile pointer for this reason which is
unused at that point to silent the compiler warning about the set and unused
dummyFile variable.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Oliver Hartkopp [Sun, 15 Sep 2013 19:54:37 +0000 (21:54 +0200)]
slcand: fix whitespace issues and unify coding style
Fixed coding style inspired by Linux checkpatch.pl
Additionally removed a comment in the write() result check in the 'if (speed)'
statement to make sure the write() is not optimized away as the executed code
was empty.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Oliver Hartkopp [Wed, 4 Sep 2013 18:30:34 +0000 (20:30 +0200)]
cangw: add an option for the per rule limitation of frame hops
Usually the received CAN frames can be processed/routed as much as 'max_hops'
times (which is given at module load time of the can-gw module).
Introduce a new configuration option ( -l <hops> ) to reduce the number of
possible hops for a specific gateway rule to a value smaller then max_hops.
Uwe Kleine-König [Sat, 17 Aug 2013 19:28:10 +0000 (21:28 +0200)]
can-utils: Don't overwrite PREFIX and DESTDIR when provided via the environment
For creating a Debian package providing PREFIX and DESTDIR via the
environment is the easiest option. So use ?= to assign these two
variables to honor the values in the environment.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Oliver Hartkopp [Tue, 11 Jun 2013 20:21:38 +0000 (22:21 +0200)]
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>
Oliver Hartkopp [Fri, 7 Jun 2013 18:02:57 +0000 (20:02 +0200)]
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>
Oliver Hartkopp [Thu, 20 Dec 2012 10:37:43 +0000 (11:37 +0100)]
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/*).