candev: allow SJW user setting for bittiming calculation
This patch adds support for SJW user settings to not set the synchronization
jump width (SJW) to 1 in any case when using the in-kernel bittiming
calculation.
The ip-tool from iproute2 already supports to pass the user defined SJW
value. The given SJW value is sanitized with the controller specific sjw_max
and the calculated tseg2 value. As the SJW can have values up to 4 providing
this value will lead to the maximum possible SJW automatically. A higher SJW
allows higher controller oscillator tolerances.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Acked-by: Wolfgang Grandegger <wg@grandegger.com> Signed-off-by: David S. Miller <davem@davemloft.net> Acked-by: Kurt Van Dijck <kurt.van.dijck@eia.be>
git-svn-id: svn://svn.berlios.de//socketcan/trunk@1276 030b6a49-0b11-0410-94ab-b0dab22257f2
The commit aabdcb0b553b9c9547b1a506b34d55a764745870 ("can bcm: fix tx_setup
off-by-one errors") fixed only a part of the original problem reported by
Andre Naujoks. It turned out that the original code needed to be re-ordered
to reduce complexity and to finally fix the reported frame counting issues.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Upstream commit: https://github.com/davem330/net/commit/12d0d0d3a7349daa95dbfd5d7df8146255bc7c67
This patch fixes two off-by-one errors that canceled each other out.
Checking for the same condition two times in bcm_tx_timeout_tsklet() reduced
the count of frames to be sent by one. This did not show up the first time
tx_setup is invoked as an additional frame is sent due to TX_ANNONCE.
Invoking a second tx_setup on the same item led to a reduced (by 1) number of
sent frames.
Reported-by: Andre Naujoks <nautsch@gmail.com> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Upstream commit https://github.com/davem330/net/commit/aabdcb0b553b9c9547b1a506b34d55a764745870
hartkopp [Wed, 31 Aug 2011 19:43:11 +0000 (19:43 +0000)]
As we're using skb_mac_header() functions which rely on the fact, that CAN
netdevices do not use the header_ops, we should test if these header_ops are
really not in use.
Added new programm to test the CAN filters in af_can.c .
As the formerly test bench consisting of
- tst-filter-master.c
- tst-filter-server.c
- tst-filter-server.result
is pretty hard to use, this new tst-filter tool is intended to replace these
tools in the Linux test project LTP.
Together with tst-rcv-own-msgs, tst-filter is a complete new test bench then.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
git-svn-id: svn://svn.berlios.de//socketcan/trunk@1263 030b6a49-0b11-0410-94ab-b0dab22257f2
hartkopp [Wed, 29 Jun 2011 16:54:18 +0000 (16:54 +0000)]
The two options "CAN bit-timing calculation" and
"Platform CAN drivers with Netlink support" have a "default Y". In order to
activate them by default, change to "default y".
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Acked-by: Wolfgang Grandegger <wg@grandegger.com> Acked-by: Kurt Van Dijck <kurt.van.dijck@eia.be> Signed-off-by: David S. Miller <davem@davemloft.net>
git-svn-id: svn://svn.berlios.de//socketcan/trunk@1262 030b6a49-0b11-0410-94ab-b0dab22257f2
hartkopp [Sat, 21 May 2011 12:03:55 +0000 (12:03 +0000)]
can: avoids a false warning
At this point optlen == sizeof(sfilter) but some compilers are dumb.
Reported-by: Németh Márton <nm127@freemail.h Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Acked-by: Oliver Hartkopp <oliver@hartkopp.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Upstream commit:
http://git.kernel.org/?p=linux/kernel/git/davem/net-next-2.6.git;a=commitdiff;h=4ffa87012efd7b664762b579213d4663560ef4a3
hartkopp [Thu, 5 May 2011 14:55:40 +0000 (14:55 +0000)]
can: rename can_try_module_get to can_get_proto
can_try_module_get does return a struct can_proto.
The name explains what is done in so much detail that a caller
may not notice that a struct can_proto is locked/unlocked.
Signed-off-by: Kurt Van Dijck <kurt.van.dijck@eia.be> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
git-svn-id: svn://svn.berlios.de//socketcan/trunk@1253 030b6a49-0b11-0410-94ab-b0dab22257f2
Signed-off-by: Kurt Van Dijck <kurt.van.dijck@eia.be> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
git-svn-id: svn://svn.berlios.de//socketcan/trunk@1252 030b6a49-0b11-0410-94ab-b0dab22257f2
hartkopp [Tue, 3 May 2011 11:39:23 +0000 (11:39 +0000)]
net: check the length of the socket address passed to connect(2)
I missed that upstream commit from Changli Gao.
http://git.kernel.org/?p=linux/kernel/git/davem/net-next-2.6.git;a=commitdiff;h=6503d96168f891ffa3b70ae6c9698a1a722025a0
So here it comes for the BerliOS trunk also ... (in branches/j1939 it is already included)
Check the length of the socket address passed to connect(2). If the
length is invalid, -EINVAL will be returned.
Fixes generated by 'codespell' and manually reviewed.
Signed-off-by: Lucas De Marchi <lucas.demarchi@profusion.mobi>
Upstream commit: http://git.kernel.org/?p=linux/kernel/git/davem/net-next-2.6.git;a=commitdiff;h=25985edcedea6396277003854657b5f3cb31a628
This patch removes spin_locks at CAN socket creation time by using RCU.
Inspired by the discussion with Kurt van Dijck and Eric Dumazet the RCU code
was partly derived from af_phonet.c
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Reviewed-by: Eric Dumazet <eric.dumazet@gmail.com> Acked-by: Kurt Van Dijck <kurt.van.dijck@eia.be> Signed-off-by: David S. Miller <davem@davemloft.net>
git-svn-id: svn://svn.berlios.de//socketcan/trunk@1238 030b6a49-0b11-0410-94ab-b0dab22257f2
can_ioctl is the only reason for struct proto to be non-const.
script/check-patch.pl suggests struct proto be const.
Setting the reference to the common can_ioctl() in all CAN protocols directly
removes the need to make the struct proto writable in af_can.c
Signed-off-by: Kurt Van Dijck <kurt.van.dijck@eia.be> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: David S. Miller <davem@davemloft.net>
git-svn-id: svn://svn.berlios.de//socketcan/trunk@1237 030b6a49-0b11-0410-94ab-b0dab22257f2
This patch makes the CAN socket code conform to the manpage of sendmsg.
Signed-off-by: Kurt Van Dijck <kurt.van.dijck@eia.be> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: David S. Miller <davem@davemloft.net>
git-svn-id: svn://svn.berlios.de//socketcan/trunk@1236 030b6a49-0b11-0410-94ab-b0dab22257f2
"candump" actually calles a library function snprintf_can_error_frame()
to do the formatting. It could be used for other purposes as well.
Signed-off-by: Wolfgang Grandegger <wg@grandegger.com> Acked-by: Kurt Van Dijck <kurt.van.dijck@eia.be>
git-svn-id: svn://svn.berlios.de//socketcan/trunk@1234 030b6a49-0b11-0410-94ab-b0dab22257f2
hartkopp [Sat, 1 Jan 2011 17:14:20 +0000 (17:14 +0000)]
can-bcm: Use inode instead of kernel address for /proc file
Since the socket address is just being used as a unique identifier, its
inode number is an alternative that does not leak potentially sensitive
information.
CC-ing stable because MITRE has assigned CVE-2010-4565 to the issue.
Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com> Acked-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Upstream commit:
http://git.kernel.org/?p=linux/kernel/git/davem/net-2.6.git;a=commitdiff;h=9f260e0efa4766e56d0ac14f1aeea6ee5eb8fe83
hartkopp [Thu, 9 Dec 2010 18:58:59 +0000 (18:58 +0000)]
cangw: Do not use skb->sk to detect already routed CAN frames.
As the latest changes to the can-gw have shown, the use of skb->sk created
several problems and still looks like a bad hack.
While checking the struct skbuff for usable containers to detect routed CAN-
frames that do not interfere with other sophisticated network technique, the
pointers to the [transport|network|mac]_header looked interesting.
So we mark routed frames by setting some mac header length which is not
relevant for the CAN frames located in the skb->data section.
As dev->header_ops is not set in CAN netdevices no one is ever accessing the
various header offsets in the CAN skbuffs anyway. E.g. using the packet socket
to read CAN frames is still working after this change to gw.c .
hartkopp [Thu, 9 Dec 2010 18:03:47 +0000 (18:03 +0000)]
slcan: Add missing linux/sched.h include.
drivers/net/can/slcan.c: In function 'slcan_open':
drivers/net/can/slcan.c:568: error: dereferencing pointer to incomplete type
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Upstream commit:
http://git.kernel.org/?p=linux/kernel/git/davem/net-next-2.6.git;a=commitdiff;h=84b3cdc38cd2882d7ac3c2ae4b6faf5c199874e3
hartkopp [Mon, 6 Dec 2010 16:44:00 +0000 (16:44 +0000)]
skb->sk is used in dev_pick_tx() which is called from dev_queue_xmit(). If
sk points to an arbitrary magic value, dev_pick_tx() returns a wrong value,
which can lead to various memory corruption bugs.
hartkopp [Sun, 5 Dec 2010 19:37:16 +0000 (19:37 +0000)]
RTNL is used as a global lock for all changes to network configuration.
Therefore the cgw_list_lock was obvoiusly over-engineered 8-)
This patch makes use of the rtnl_lock to protect cangw route entry changes.
hartkopp [Tue, 30 Nov 2010 19:27:36 +0000 (19:27 +0000)]
capabilities have been dropped in 2.6.33
http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.33.y.git;a=commitdiff;h=13f18aa05f5abe135f47b6417537ae2b2fedc18c
hartkopp [Thu, 18 Nov 2010 20:19:23 +0000 (20:19 +0000)]
slcan: This commit reverts commit rev1171 that has been done to
enable the swtc char hack. Once swtc has gone the upstream commit
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=5342b77c4123ba39f911d92a813295fb3bb21f69
is restored now to his original extend.
hartkopp [Thu, 18 Nov 2010 19:51:14 +0000 (19:51 +0000)]
Mostly cosmetic changes to make the code look similar to the latest
net-next-2.6/drivers/net/slip.c code where it has been updated since
we branched slcan.c.
hartkopp [Mon, 15 Nov 2010 15:08:36 +0000 (15:08 +0000)]
isotp: the timestamp for rx stmin enforcement was reset in the function that
receives the flow control. Of course it has to be in the funtion that sends
the FC to the sender of the data. :-(
This patch fixes the rx/tx issue.
hartkopp [Sun, 14 Nov 2010 08:55:06 +0000 (08:55 +0000)]
Added new socketoptions to force the isotp protocol to intentionally
misbehave for regression tests.
CAN_ISOTP_TX_STMIN:
Set a value in nano secs that's used as minimum CF gap by the sender.
This value is used instead of the value provided by the receiver inside the FC.
CAN_ISOTP_RX_STMIN:
Ignores received CF frames which timestamps differ less than this value in nano
secs. This is used to test the receivers misbehaviour when the receiver
provides a lower stmin value that he's able to cope with. Received CF frames
are silently dropped when they come faster than specified by this value.
Reported-by: Dan Rosenberg <drosenberg@vsecurity.com> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> CC: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Upstream Commit:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=0597d1b99fcfc2c0eada09a698f85ed413d4ba84
hartkopp [Fri, 22 Oct 2010 05:24:03 +0000 (05:24 +0000)]
can-raw: add msg_flags to distinguish local traffic
CAN has no addressing scheme. It is currently impossible for userspace
to tell is a received CAN frame comes from another process on the local
host, or from a remote CAN device.
This patch add support for userspace applications to distinguish between
'own', 'local' and 'remote' CAN traffic. The distinction is made by returning
flags in msg->msg_flags in the call to recvmsg().
The added documentation explains the introduced flags.
Signed-off-by: Kurt Van Dijck <kurt.van.dijck@eia.be> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Upstream commit:
http://git.kernel.org/?p=linux/kernel/git/davem/net-next-2.6.git;a=commitdiff;h=1e55659ce6ddb5247cee0b1f720d77a799902b85
Added information how to obtain timestamps as suggested by
Daniele Venzano <venza@brownhat.org>. Extended the possibility
to get timestamps via recvmsg().
On 64bit systems a 'long' is a 64bit value but the target values of scanf()
are always 32bit in the affected code - which means just an 'unsigned int'.
Unsigned int is fine on 32 and 64 bit systems.
Fixed calculation of needed bits on the physical wire according Ken Tindells
*worst* case calculation for stuff-bits.
(see "Guaranteeing Message Latencies on Controller Area Network" 1st ICC'94)
Due to the bitstuffing estimation the calculated busload may exceed 100%.
hartkopp [Fri, 13 Aug 2010 16:15:16 +0000 (16:15 +0000)]
can: add limit for nframes and clean up signed/unsigned variables
This patch adds a limit for nframes as the number of frames in TX_SETUP and
RX_SETUP are derived from a single byte multiplex value by default.
Use-cases that would require to send/filter more than 256 CAN frames should
be implemented in userspace for complexity reasons anyway.
Additionally the assignments of unsigned values from userspace to signed
values in kernelspace and vice versa are fixed by using unsigned values in
kernelspace consistently.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Reported-by: Ben Hawkes <hawkes@google.com> Acked-by: Urs Thuermann <urs.thuermann@volkswagen.de> Signed-off-by: David S. Miller <davem@davemloft.net>
Upstream commit:
http://git.kernel.org/?p=linux/kernel/git/davem/net-2.6.git;a=commitdiff;h=5b75c4973ce779520b9d1e392483207d6f842cde
can-calc-bit-timing: calculate bit timings for all known controllers by default
When testing or improving the bit timing algorithm, you're probably
interested in the values of all can controllers. Further you might not
know the all reference clocks of the controllers.
This patch add a "ref_clock" member to the "struct can_bittiming_const"
that holds the reference clock of the controller in Hz.
By default now the bit timing is calculated for all known can
controllers with the default ref_clock defined in "can_bittiming_const".
It's still possible to overwrite the ref clock with the command line
option "-c".
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
git-svn-id: svn://svn.berlios.de//socketcan/trunk@1188 030b6a49-0b11-0410-94ab-b0dab22257f2
can-calc-bit-timing: improve printing of bit timing parameters
This patch adds additional fields when printing the bit timing
parameters. Now the real bitrate the nominal and the real sample point
as well as the error of the sample point is displayed.
can-calc-bit-timing: use algorithm from the kernel
This patch copies the algorithm functions (can_update_spt and
can_calc_bittiming) from the kernel. Then some glue code is added that
these functions compile in userspace.
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
git-svn-id: svn://svn.berlios.de//socketcan/trunk@1186 030b6a49-0b11-0410-94ab-b0dab22257f2
The cleanup of slc_alloc() integrated in SVN Rev1095 based on upstream commit
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=5342b77c4123ba39f911d92a813295fb3bb21f69
was not really Kernel-version depended ...
So far this code section is needed for the changes added in SVN Rev1170 so we
would need to revisit this code when mainlining the driver.
Added possibility to force the slcan driver to use a specific device number
when set via SWTC char (e.g. with stty). See thread
https://lists.berlios.de/pipermail/socketcan-users/2010-April/001378.html
Provided by Stephen Hellriegel <Stephen.Hellriegel@verari.com>
So far this change only applies for Kernels < 2.6.32 ...
There is no reason why the 'real' SLCAN interfaces should have a different
naming scheme than other 'real' CAN interfaces.
So create canX instead of slcX network device names with the slcan driver.
As Stephen Hellriegel pointed out in
https://lists.berlios.de/pipermail/socketcan-users/2010-April/001378.html
it does not make sense to monitor the tx data flow in the slcan driver as
we do not know anything about the CAN specific problems that may occur in the
slcan device.
Therefore we just wait until the ASCII data is sent on the serial line without
having a separate timeout handler in the slcan driver.
- rework internal structures to prepare routings and modifications of CAN traffic also to non-CAN interfaces
- fix reading of netlink messages in cangw.c (added RTCAN_RTA / RTCAN_PAYLOAD macros)
- rework reading of gw-job lists in cgw_dump_jobs()
- rename of functions and API definitions to have a common namespace cgw_
- added infrastructure to perform crc8 and xor checksums in CAN frame data[]
TODO:
- add and test functionality for crc8 and xor checksums in CAN frame data[]
- add help text for crc8 and xor checksums in CAN frame data[]