* AW: Need support J1939 protocol support to my kernel (v3.8 on BeagleBone Black)
@ 2013-11-11 16:14 Michael Luxen
2013-11-12 1:10 ` swapnil
0 siblings, 1 reply; 9+ messages in thread
From: Michael Luxen @ 2013-11-11 16:14 UTC (permalink / raw
To: linux-can@vger.kernel.org, patilswa@gmail.com
Hello Swapnil,
I've success with building the J1939 stack on my BBB based on Debian using these steps:
git clone git://gitorious.org/linux-can/can-utils.git
cd can-utils
--- get J1939 stuff ---
git remote add j1939 git://gitorious.org/~kurt-vd/linux-can/linux-can-j1939.git
git remote update j1939
--- depending on kernel ---
git merge j1939/v3.6
...or…
git merge j1939/v3.8
Regards
Mike
-----Ursprüngliche Nachricht-----
Von: Swapnil Patil <patilswa@gmail.com>
Gesendet: Mo 11.11.2013 16:46
Betreff: Need support J1939 protocol support to my kernel (v3.8 on BeagleBone Black)
An: linux-can@vger.kernel.org;
> Hi Kurt,
>
> Thanks for your reply.
> I am using Begalbone Black with Ubuntu 13.04
> I am able to transmit the RAW and extended can message over the can
> bus using can utility
> Now I want to use J1939 stack.
> I downloaded the
> Linux-can-can-j1939-modules and Linux-can-iproute2-j1939 and tried to
> build them but it failed
>
> Log of iproute2-j1939$ make
>
> make[1]: Entering directory `/home/ubuntu/BBB/iproute2-j1939/misc'
> gcc -D_GNU_SOURCE -O2 -Wstrict-prototypes -Wall -I../include
> -DRESOLVE_HOSTNAM -DLIBDIR=\"/usr/lib/\" -I -o arpdarpd.c
> ../lib/libnetlink.a ../lib/libutil.-ldb -lpthread
> gcc: error: arpd: No such file or directory
>
> Log of can-j1939-modules: make
> /home/ubuntu/BBB/can-j1939-modules/net/can/j1939/rtnl.c:232:25: error:
> âstruct netlink_skb_parmsâ has no member namedâpidâ
> /
>
> If someone already build this on Begalbone black with ubuntu
> 13.04 or angstrom kernel Please add the steps
>
> Thanks
> Swapnil
> --
> To unsubscribe from this list: send the line "unsubscribe linux-can" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: AW: Need support J1939 protocol support to my kernel (v3.8 on BeagleBone Black)
2013-11-11 16:14 AW: Need support J1939 protocol support to my kernel (v3.8 on BeagleBone Black) Michael Luxen
@ 2013-11-12 1:10 ` swapnil
2013-11-12 10:02 ` Kurt Van Dijck
0 siblings, 1 reply; 9+ messages in thread
From: swapnil @ 2013-11-12 1:10 UTC (permalink / raw
To: linux-can
Michael Luxen <mluxen <at> gmx.net> writes:
>
> Hello Swapnil,
>
> I've success with building the J1939 stack on my BBB based on Debian using
these steps:
>
> git clone git://gitorious.org/linux-can/can-utils.git
> cd can-utils
> --- get J1939 stuff ---
> git remote add j1939 git://gitorious.org/~kurt-vd/linux-can/linux-can-
j1939.git
> git remote update j1939
> --- depending on kernel ---
> git merge j1939/v3.6
> ...or…
> git merge j1939/v3.8
git merge j1939/j1939-v3.8
after this step
ubuntu@arm:~/BBB/can-utils$ git merge j1939/j1939-v3.8
error: The following untracked working tree files would be overwritten by
merge:
.mailmap
COPYING
CREDITS
Documentation/.gitignore
Documentation/00-INDEX
Documentation/ABI/README
Documentation/ABI/obsolete/sysfs-bus-usb
Documentation/ABI/obsolete/sysfs-class-rfkill
Documentation/ABI/obsolete/sysfs-driver-hid-roccat-koneplus
Documentation/ABI/removed/devfs
Documentation/ABI/removed/dv1394
Documentation/ABI/removed/o2cb
Documentation/ABI/removed/raw1394
Documentation/ABI/removed/video1394
Documentation/ABI/stable/firewire-cdev
Documentation/ABI/stable/o2cb
Documentation/ABI/stable/syscalls
Documentation/ABI/stable/sysfs-acpi-pmprofile
Documentation/ABI/stable/sysfs-bus-firewire
Documentation/ABI/stable/sysfs-bus-xen-backend
Documentation/ABI/stable/sysfs-class-backlight
Documentation/ABI/stable/sysfs-class-rfkill
Documentation/ABI/stable/sysfs-class-ubi
Documentation/ABI/stable/sysfs-devices-node
Documentation/ABI/stable/sysfs-devices-system-xen_memory
Documentation/ABI/stable/sysfs-driver-qla2xxx
Documentation/ABI/stable/sysfs-driver-usb-usbtmc
Documentation/ABI/stable/sysfs-firmware-efi-vars
Documentation/ABI/stable/sysfs-module
Documentation/ABI/stable/thermal-notification
Documentation/ABI/stable/vdso
Documentation/ABI/testing/configfs-spear-pcie-gadget
Documentation/ABI/testing/debugfs-ec
Documentation/ABI/testing/debugfs-ideapad
Documentation/ABI/testing/debugfs-pktcdvd
Documentation/ABI/testing/evm
Documentation/ABI/testing/ima_policy
Documentation/ABI/testing/procfs-diskstats
Documentation/ABI/testing/pstore
Documentation/ABI/testing/sysfs-ata
Documentation/ABI/testing/sysfs-block
Documentation/ABI/testing/sysfs-block-zram
Documentation/ABI/testing/sysfs-bus-bcma
Documentation/ABI/testing/sysfs-bus-css
Documentation/ABI/testing/sysfs-bus-i2c-devices-fsa9480
Documentation/ABI/testing/sysfs-bus-i2c-devices-hm6352
Documentation/ABI/testing/sysfs-bus-media
Documentation/ABI/testing/sysfs-bus-pci
Documentation/ABI/testing/sysfs-bus-pci-devices-cciss
Documentation/ABI/testing/sysfs-bus-pci-drivers-ehci_hcd
Documentation/ABI/testing/sysfs-bus-rbd
Documentation/ABI/testing/sysfs-bus-umc
Documentation/ABI/testing/sysfs-bus-usb
Documentation/ABI/testing/sysfs-bus-usb-devices-usbsevseg
Documentation/ABI/testing/sysfs-c2port
Documentation/ABI/testing/sysfs-class
Documentation/ABI/testing/sysfs-class-backlight-driver-adp8870
Documentation/ABI/testing/sysfs-class-bdi
Documentation/ABI/testing/sysfs-class-devfreq
Documentation/ABI/testing/sysfs-class-lcd
Documentation/ABI/testing/sysfs-class-led
Documentation/ABI/testing/sysfs-class-mtd
Documentation/ABI/testing/sysfs-class-net-batman-adv
Documentation/ABI/testing/sysfs-class-net-mesh
Documentation/ABI/testing/sysfs-class-pktcdvd
Documentation/ABI/testing/sysfs-class-power
Documentation/ABI/testing/sysfs-class-regulator
Documentation/ABI/testing/sysfs-class-rtc-rtc0-device-
rtc_calibration
Documentation/ABI/testing/sysfs-class-scsi_host
Documentation/ABI/testing/sysfs-class-uwb_rc
Documentation/ABI/testing/sysfs-class-uwb_rc-wusbhc
Documentation/ABI/testing/sysfs-dev
Documentation/ABI/testing/sysfs-devices
Documentation/ABI/testing/sysfs-devices-memory
Documentation/ABI/testing/sysfs-devices-mmc
Documentation/ABI/testing/sysfs-devices-platform-_UDC_-gadget
Documentation/ABI/testing/sysfs-devices-platform-docg3
Documentation/ABI/testing/sysfs-devices-power
Documentation/ABI/testing/sysfs-devices-system-cpu
Documentation/ABI/testing/sysfs-devices-system-ibm-rtl
Documentation/ABI/testing/sysfs-driver-hid
Documentation/ABI/testing/sysfs-driver-hid-logitech-lg4ff
Documentation/ABI/testing/sysfs-driver-hid-multitouch
Documentation/ABI/testing/sysfs-driver-hid-picolcd
Documentation/ABI/testing/sysfs-driver-hid-prodikeys
Documentation/ABI/testing/sysfs-driver-hid-roccat-arvo
Documentation/ABI/testing/sysfs-driver-hid-roccat-isku
Documentation/ABI/testing/sysfs-driver-hid-roccat-kone
Documentation/ABI/testing/sysfs-driver-hid-roccat-koneplus
Documentation/ABI/testing/sysfs-driver-hid-roccat-kovaplus
Docume
Aborting
didn't understand ??
what is the next step
>
> Regards
> Mike
>
> -----Ursprüngliche Nachricht-----
> Von: Swapnil Patil <patilswa <at> gmail.com>
> Gesendet: Mo 11.11.2013 16:46
> Betreff: Need support J1939 protocol support to my kernel (v3.8 on
BeagleBone Black)
> An: linux-can <at> vger.kernel.org;
> > Hi Kurt,
> >
> > Thanks for your reply.
> > I am using Begalbone Black with Ubuntu 13.04
> > I am able to transmit the RAW and extended can message over the can
> > bus using can utility
> > Now I want to use J1939 stack.
> > I downloaded the
> > Linux-can-can-j1939-modules and Linux-can-iproute2-j1939 and tried to
> > build them but it failed
> >
> > Log of iproute2-j1939$ make
> >
> > make[1]: Entering directory `/home/ubuntu/BBB/iproute2-j1939/misc'
> > gcc -D_GNU_SOURCE -O2 -Wstrict-prototypes -Wall -I../include
> > -DRESOLVE_HOSTNAM -DLIBDIR=\"/usr/lib/\" -I -o arpdarpd.c
> > ../lib/libnetlink.a ../lib/libutil.-ldb -lpthread
> > gcc: error: arpd: No such file or directory
> >
> > Log of can-j1939-modules: make
> > /home/ubuntu/BBB/can-j1939-modules/net/can/j1939/rtnl.c:232:25: error:
> > âstruct netlink_skb_parmsâ has no member namedâpidâ
> > /
> >
> > If someone already build this on Begalbone black with ubuntu
> > 13.04 or angstrom kernel Please add the steps
> >
> > Thanks
> > Swapnil
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-can" in
> > the body of a message to majordomo <at> vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> >
> --
> To unsubscribe from this list: send the line "unsubscribe linux-can" in
> the body of a message to majordomo <at> vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: AW: Need support J1939 protocol support to my kernel (v3.8 on BeagleBone Black)
2013-11-12 1:10 ` swapnil
@ 2013-11-12 10:02 ` Kurt Van Dijck
2013-11-28 4:49 ` swapnil
0 siblings, 1 reply; 9+ messages in thread
From: Kurt Van Dijck @ 2013-11-12 10:02 UTC (permalink / raw
To: swapnil, Michael Luxen; +Cc: linux-can
Hey all,
Maybe Michael was a bit too fast.
I suspect you tried to merge the j1939 linux kernel into can-utils ?
On Tue, Nov 12, 2013 at 01:10:04AM +0000, swapnil wrote:
> Michael Luxen <mluxen <at> gmx.net> writes:
>
> >
> > Hello Swapnil,
> >
> > I've success with building the J1939 stack on my BBB based on Debian using
> these steps:
> >
> > git clone git://gitorious.org/linux-can/can-utils.git
> > cd can-utils
> > --- get J1939 stuff ---
So you're in the can-utils directory now. Merge can-utils-j1939
$ git remote add j1939 git://gitorious.org/~kurt-vd/linux-can/can-j1939-utils.git
$ git remote update j1939
$ git merge j1939/master
build can-utils now.
And then:
$ cd ..
$ git clone <your kernel>
$ cd linux (or your linux kernel directory)
and then these steps apply.
> > git remote add j1939 git://gitorious.org/~kurt-vd/linux-can/linux-can-j1939.git
> > git remote update j1939
> > --- depending on kernel ---
> > git merge j1939/v3.6
> > ...or…
> > git merge j1939/v3.8
Maybe this will work better.
Kind regards,
Kurt
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: AW: Need support J1939 protocol support to my kernel (v3.8 on BeagleBone Black)
2013-11-12 10:02 ` Kurt Van Dijck
@ 2013-11-28 4:49 ` swapnil
2013-11-28 8:52 ` Kurt Van Dijck
0 siblings, 1 reply; 9+ messages in thread
From: swapnil @ 2013-11-28 4:49 UTC (permalink / raw
To: linux-can
Kurt Van Dijck <kurt.van.dijck <at> eia.be> writes:
>
> Hey all,
>
> Maybe Michael was a bit too fast.
> I suspect you tried to merge the j1939 linux kernel into can-utils ?
>
> On Tue, Nov 12, 2013 at 01:10:04AM +0000, swapnil wrote:
> > Michael Luxen <mluxen <at> gmx.net> writes:
> >
> > >
> > > Hello Swapnil,
> > >
> > > I've success with building the J1939 stack on my BBB based on Debian
using
> > these steps:
> > >
> > > git clone git://gitorious.org/linux-can/can-utils.git
> > > cd can-utils
> > > --- get J1939 stuff ---
>
> So you're in the can-utils directory now. Merge can-utils-j1939
>
> $ git remote add j1939 git://gitorious.org/~kurt-vd/linux-can/can-j1939-
utils.git
> $ git remote update j1939
> $ git merge j1939/master
>
> build can-utils now.
> And then:
>
> $ cd ..
> $ git clone <your kernel>
> $ cd linux (or your linux kernel directory)
>
> and then these steps apply.
>
> > > git remote add j1939 git://gitorious.org/~kurt-vd/linux-can/linux-can-
j1939.git
> > > git remote update j1939
> > > --- depending on kernel ---
> > > git merge j1939/v3.6
> > > ...or…
> > > git merge j1939/v3.8
>
> Maybe this will work better.
>
> Kind regards,
> Kurt
> --
> To unsubscribe from this list: send the line "unsubscribe linux-can" in
> the body of a message to majordomo <at> vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
Hi Kurt ,
Thanks for adding the information on elinux.org/J1939
I am able to build the kernal for begabone black using j1939
but when i tried to build iproute2-j1939
root@arm:/home/ubuntu/OBDscan/iproute2-j1939# make
make[1]: Entering directory `/home/ubuntu/OBDscan/iproute2-j1939/misc'
gcc -D_GNU_SOURCE -O2 -Wstrict-prototypes -Wall -I../include -
DRESOLVE_HOSTNAMES -DLIBDIR=\"/usr/lib/\" -I/usr//usr/include -o arpd
arpd.c ../lib/libnetlink.a ../lib/libutil.a -ldb -lpthread
arpd.c:19:20: fatal error: db_185.h: No such file or directory
#include <db_185.h>
^
compilation terminated.
make[1]: *** [arpd] Error 1
make[1]: Leaving directory `/home/ubuntu/OBDscan/iproute2-j1939/misc'
make: *** [all] Error 2
i am getting above error.
i tried to install sudo apt-get install db4.7-util
but did not worked
if y
>ip link set can0 j1939 on
Error: either "dev" is duplicate, or "j1939" is a garbage.
can you please help me.
I am really trying hard to build it on begalbone black
Thank You
Swapnil
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: AW: Need support J1939 protocol support to my kernel (v3.8 on BeagleBone Black)
2013-11-28 4:49 ` swapnil
@ 2013-11-28 8:52 ` Kurt Van Dijck
2013-12-04 22:10 ` swapnil
0 siblings, 1 reply; 9+ messages in thread
From: Kurt Van Dijck @ 2013-11-28 8:52 UTC (permalink / raw
To: swapnil; +Cc: linux-can
Hey,
> Hi Kurt ,
> Thanks for adding the information on elinux.org/J1939
> I am able to build the kernal for begabone black using j1939
> but when i tried to build iproute2-j1939
>
> root@arm:/home/ubuntu/OBDscan/iproute2-j1939# make
> make[1]: Entering directory `/home/ubuntu/OBDscan/iproute2-j1939/misc'
> gcc -D_GNU_SOURCE -O2 -Wstrict-prototypes -Wall -I../include -
> DRESOLVE_HOSTNAMES -DLIBDIR=\"/usr/lib/\" -I/usr//usr/include -o arpd
> arpd.c ../lib/libnetlink.a ../lib/libutil.a -ldb -lpthread
> arpd.c:19:20: fatal error: db_185.h: No such file or directory
> #include <db_185.h>
> ^
> compilation terminated.
> make[1]: *** [arpd] Error 1
> make[1]: Leaving directory `/home/ubuntu/OBDscan/iproute2-j1939/misc'
> make: *** [all] Error 2
>
> i am getting above error.
> i tried to install sudo apt-get install db4.7-util
> but did not worked
you'd need some sort of db-devel package, as explained in README of iprout2.
Another trick I initially did is disable arpd from building:
in misc/Makefile, drop 'arpd' from TARGETS.
Kind regards,
Kurt
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: AW: Need support J1939 protocol support to my kernel (v3.8 on BeagleBone Black)
2013-11-28 8:52 ` Kurt Van Dijck
@ 2013-12-04 22:10 ` swapnil
2013-12-05 19:59 ` Kurt Van Dijck
0 siblings, 1 reply; 9+ messages in thread
From: swapnil @ 2013-12-04 22:10 UTC (permalink / raw
To: linux-can
Kurt Van Dijck <kurt.van.dijck <at> eia.be> writes:
>
> Hey,
>
> > Hi Kurt ,
> > Thanks for adding the information on elinux.org/J1939
> > I am able to build the kernal for begabone black using j1939
> > but when i tried to build iproute2-j1939
> >
> > root <at> arm:/home/ubuntu/OBDscan/iproute2-j1939# make
> > make[1]: Entering directory `/home/ubuntu/OBDscan/iproute2-j1939/misc'
> > gcc -D_GNU_SOURCE -O2 -Wstrict-prototypes -Wall -I../include -
> > DRESOLVE_HOSTNAMES -DLIBDIR=\"/usr/lib/\" -I/usr//usr/include -o arpd
> > arpd.c ../lib/libnetlink.a ../lib/libutil.a -ldb -lpthread
> > arpd.c:19:20: fatal error: db_185.h: No such file or directory
> > #include <db_185.h>
> > ^
> > compilation terminated.
> > make[1]: *** [arpd] Error 1
> > make[1]: Leaving directory `/home/ubuntu/OBDscan/iproute2-j1939/misc'
> > make: *** [all] Error 2
> >
> > i am getting above error.
> > i tried to install sudo apt-get install db4.7-util
> > but did not worked
>
> you'd need some sort of db-devel package, as explained in README of
iprout2.
> Another trick I initially did is disable arpd from building:
> in misc/Makefile, drop 'arpd' from TARGETS.
>
> Kind regards,
> Kurt
> --
> To unsubscribe from this list: send the line "unsubscribe linux-can" in
> the body of a message to majordomo <at> vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
Hi Kurt,
I commented out arpd part from building and it worked
after that i replaced current IP with the new one.
After that i tried the sample program jspy it worked as expected on
beaglebone black.
I have few questions
1.I want to transmit more than 8 bytes on can and want to check
RTS->CTS->EOM flow
2.I a able to receive 900 messages/sec on begalbone with 250k baud rate
actually it should receive 1600 messages ? i will try to figure it out?
I think JSR program is used to transmit and receive j1939 packet
but i am not able to figure out how to send TP message
can u give me simple example to send and receive J1939 tp message
I have canAlyzer.
Also i want to post the document how I build j1939 for begalbone
black.
Thank you for your support
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: AW: Need support J1939 protocol support to my kernel (v3.8 on BeagleBone Black)
2013-12-04 22:10 ` swapnil
@ 2013-12-05 19:59 ` Kurt Van Dijck
0 siblings, 0 replies; 9+ messages in thread
From: Kurt Van Dijck @ 2013-12-05 19:59 UTC (permalink / raw
To: swapnil; +Cc: linux-can
[-- Attachment #1: Type: text/plain, Size: 1708 bytes --]
2nd try, without HTML guide
Hey,
>
> After that i tried the sample program jspy it worked as expected on
> beaglebone black.
> I have few questions
> 1.I want to transmit more than 8 bytes on can and want to check
> RTS->CTS->EOM flow
One of the major reasons of putting j1939 in kernel is that multiple
transport sessions must be serialized due to CAN-id reuse.
As such, userspace will not have to worry about the RTS->CTS->EOM flow.
Instead, userspace does sendto() of more than 8 bytes, and kernel
will activate the transport protocol (fragmentation).
If kernel is able to attempt delivery of the packet, the call to sendto()
succeeds, as needed for DGRAM sockets. If transport protocol aborts later
in the process, userspace is not alerted.
> 2.I a able to receive 900 messages/sec on begalbone with 250k baud rate
> actually it should receive 1600 messages ? i will try to figure it out?
You're welcome to post your throughput measurements.
I'm actually very interested.
>
>
> I think JSR program is used to transmit and receive j1939 packet
> but i am not able to figure out how to send TP message
> can u give me simple example to send and receive J1939 tp message
sendto(sock, dat, 9, 0, &peername, sizeof(peername));
will need to engage transport protocol with 2 datapackets :-)
It does not need to be difficult.
I added my preliminary 'kickstarter guide to j1939' and accompanying test program.
You could give it a try.
I'm still looking how to host it on elinux.org. The syntax is markdown :-(
> I have canAlyzer.
> Also i want to post the document how I build j1939 for begalbone
> black.
Euhm? You mean, adding the steps on elinux.org? You're welcome.
Kurt
[-- Attachment #2: testj1939.c --]
[-- Type: text/x-csrc, Size: 6596 bytes --]
/*
* Copyright (c) 2013 EIA Electronics
*
* Authors:
* Kurt Van Dijck <kurt.van.dijck@eia.be>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the version 2 of the GNU General Public License
* as published by the Free Software Foundation
*/
#include <signal.h>
#include <time.h>
#include <inttypes.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include <error.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <net/if.h>
#include <linux/can.h>
#include <linux/can/j1939.h>
static const char help_msg[] =
"testj1939: demonstrate j1939 use\n"
"Usage: testj1939 FROM TO\n"
" FROM / TO - or [IFACE][:[SA][,[PGN][,NAME]]]\n"
"Options:\n"
" -v Print relevant API calls\n"
" -s[=LEN] Initial send of LEN bytes dummy data\n"
" -r Receive (and print) data\n"
" -e Echo incoming packets back\n"
" This atually receives packets\n"
" -c Issue connect()\n"
" -p=PRIO Set priority to PRIO\n"
" -n Emit 64bit NAMEs in output\n"
"\n"
"Example:\n"
"testj1939 can1 20\n"
"\n"
;
static const char optstring[] = "?vs::rep:cn";
static void parse_canaddr(char *spec, struct sockaddr_can *paddr)
{
char *str;
str = strsep(&spec, ":");
if (strlen(str))
paddr->can_ifindex = if_nametoindex(str);
str = strsep(&spec, ",");
if (str && strlen(str))
paddr->can_addr.j1939.addr = strtoul(str, NULL, 0);
str = strsep(&spec, ",");
if (str && strlen(str))
paddr->can_addr.j1939.pgn = strtoul(str, NULL, 0);
str = strsep(&spec, ",");
if (str && strlen(str))
paddr->can_addr.j1939.name = strtoul(str, NULL, 0);
}
static const char *canaddr2str(const struct sockaddr_can *paddr)
{
static char buf[128];
char *str = buf;
char ifname[IF_NAMESIZE];
if (paddr->can_ifindex)
str += sprintf(str, "%s", if_indextoname(paddr->can_ifindex, ifname));
*str++ = ':';
if (paddr->can_addr.j1939.addr != J1939_NO_ADDR)
str += sprintf(str, "%02x", paddr->can_addr.j1939.addr);
*str++ = ',';
if (paddr->can_addr.j1939.pgn != J1939_NO_PGN)
str += sprintf(str, "%05x", paddr->can_addr.j1939.pgn);
*str++ = ',';
if (paddr->can_addr.j1939.name != J1939_NO_NAME)
str += sprintf(str, "%016llx", paddr->can_addr.j1939.name);
*str++ = 0;
return buf;
}
/* main */
int main(int argc, char *argv[])
{
int ret, sock, opt, j, verbose;
socklen_t peernamelen;
struct sockaddr_can sockname = {
.can_family = AF_CAN,
.can_addr.j1939 = {
.addr = J1939_NO_ADDR,
.name = J1939_NO_NAME,
.pgn = J1939_NO_PGN,
},
}, peername = {
.can_family = AF_CAN,
.can_addr.j1939 = {
.addr = J1939_NO_ADDR,
.name = J1939_NO_NAME,
.pgn = J1939_NO_PGN,
},
};
uint8_t dat[128];
int valid_peername = 0;
int todo_send = 0, todo_recv = 0, todo_echo = 0, todo_prio = -1;
int todo_connect = 0, todo_names = 0;
/* argument parsing */
while ((opt = getopt(argc, argv, optstring)) != -1)
switch (opt) {
case 'v':
verbose = 1;
break;
case 's':
todo_send = strtoul(optarg ?: "8", NULL, 0);
break;
case 'r':
todo_recv = 1;
break;
case 'e':
todo_echo = 1;
break;
case 'p':
todo_prio = strtoul(optarg, NULL, 0);
break;
case 'c':
todo_connect = 1;
break;
case 'n':
todo_names = 1;
break;
default:
fputs(help_msg, stderr);
exit(1);
break;
}
if (argv[optind]) {
if (strcmp("-", argv[optind]))
parse_canaddr(argv[optind], &sockname);
++optind;
}
if (argv[optind]) {
if (strcmp("-", argv[optind])) {
parse_canaddr(argv[optind], &peername);
valid_peername = 1;
}
++optind;
}
/* open socket */
if (verbose)
fprintf(stderr, "- socket(PF_CAN, SOCK_DGRAM, CAN_J1939);\n");
sock = ret = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
if (ret < 0)
error(1, errno, "socket(j1939)");
if (todo_prio >= 0) {
if (verbose)
fprintf(stderr, "- setsockopt(, SOL_CAN_J1939, SO_J1939_SEND_PRIO, &%i);\n", todo_prio);
ret = setsockopt(sock, SOL_CAN_J1939, SO_J1939_SEND_PRIO,
&todo_prio, sizeof(todo_prio));
if (ret < 0)
error(1, errno, "set priority %i", todo_prio);
}
if (verbose)
fprintf(stderr, "- bind(, %s, %li);\n", canaddr2str(&sockname), sizeof(sockname));
ret = bind(sock, (void *)&sockname, sizeof(sockname));
if (ret < 0)
error(1, errno, "bind()");
if (todo_connect) {
if (!valid_peername)
error(1, 0, "no peername supplied");
if (verbose)
fprintf(stderr, "- connect(, %s, %li);\n", canaddr2str(&peername), sizeof(peername));
ret = connect(sock, (void *)&peername, sizeof(peername));
if (ret < 0)
error(1, errno, "connect()");
}
if (todo_send) {
/* initialize test vector */
for (j = 0; j < sizeof(dat); ++j)
dat[j] = ((2*j) << 4) + ((2*j+1) & 0xf);
/* send data */
/*
* when using connect, do not provide additional
* destination information and use send()
*/
if (valid_peername && !todo_connect) {
if (verbose)
fprintf(stderr, "- sendto(, <dat>, %i, 0, %s, %li);\n", todo_send, canaddr2str(&peername), sizeof(peername));
ret = sendto(sock, dat, todo_send, 0,
(void *)&peername, sizeof(peername));
} else {
/*
* we may do sendto(sock, dat, todo_send, 0, NULL, 0)
* as well, but using send() demonstrates the API better
*/
if (verbose)
fprintf(stderr, "- send(, <dat>, %i, 0);\n", todo_send);
ret = send(sock, dat, todo_send, 0);
}
if (ret < 0)
error(1, errno, "sendto");
}
/* main loop */
if ((todo_echo || todo_recv) && verbose)
fprintf(stderr, "- while (1)\n");
while (todo_echo || todo_recv) {
/*
* re-use peername for storing the sender's peername of
* received packets
*/
if (verbose)
fprintf(stderr, "- recvfrom(, <dat>, %li, 0, &<peername>, %li);\n", sizeof(peername), sizeof(peername));
peernamelen = sizeof(peername);
ret = recvfrom(sock, dat, sizeof(dat), 0,
(void *)&peername, &peernamelen);
if (ret < 0) {
if (EINTR == errno) {
if (verbose)
fprintf(stderr, "-\t<interrupted>\n");
continue;
}
error(1, errno, "recvfrom()");
}
if (todo_echo) {
if (verbose)
fprintf(stderr, "- sendto(, <dat>, %i, 0, %s, %i);\n", ret, canaddr2str(&peername), peernamelen);
ret = sendto(sock, dat, ret, 0,
(void *)&peername, peernamelen);
if (ret < 0)
error(1, errno, "sendto");
}
if (todo_recv) {
if (todo_names && peername.can_addr.j1939.name)
printf("%016llx ", peername.can_addr.j1939.name);
printf("%02x %05x:", peername.can_addr.j1939.addr,
peername.can_addr.j1939.pgn);
for (j = 0; j < ret; ++j)
printf(" %02x", dat[j]);
printf("\n");
}
}
return 0;
}
[-- Attachment #3: j1939.page --]
[-- Type: text/plain, Size: 7638 bytes --]
# CAN-J1939 on linux
## CAN on linux
See [Wikipedia:socketcan](http://en.wikipedia.org/wiki/Socketcan)
## J1939 networking in short
* Add addressing on top of CAN (destination address & broadcast)
* Any (max 1780) length packets.
Packets of 9 or more use **Transport Protocol** (fragmentation)
Such packets use different CANid for the same PGN.
* only **29**bit, non-**RTR** CAN frames
* CAN id is composed of
* 0..8: SA (source address)
* 9..26:
* PDU1: PGN+DA (destionation address)
* PDU2: PGN
* 27..29: PRIO
* SA / DA may be dynamically assigned via j1939-81
Fixed rules of precedence in Specification, no master necessary
## J1939 on SocketCAN
J1939 is *just another protocol* that fits
in the Berkely sockets.
socket(AF_CAN, SOCK_DGRAM, CAN_J1939)
## differences from CAN_RAW
### addressing
SA, DA & PGN are used, not CAN id.
Berkeley socket API is used to communicate these to userspace:
* SA+PGN is put in sockname ([getsockname](http://man7.org/linux/man-pages/man2/getsockname.2.html))
* DA+PGN is put in peername ([getpeername](http://man7.org/linux/man-pages/man2/getpeername.2.html))
PGN is put in both structs
PRIO is a datalink property, and irrelevant for interpretation
Therefore, PRIO is not in *sockname* or *peername*.
The *data* that is [recv][recvfrom] or [send][sendto] is the real payload.
Unlike CAN_RAW, where addressing info is data.
### Packet size
J1939 handles packets of 8+ bytes with **Transport Protocol** fragmentation transparently.
No fixed data size is necessary.
send(sock, data, 8, 0);
will emit a single CAN frame.
send(sock, data, 9, 0);
will use fragementation, emitting 1+ CAN frames.
# Enable j1939
CAN has no protocol id field.
Enabling protocols must be done manually
### netlink
ip link set can0 j1939 on
### procfs for legacy kernel (2.6.25)
This API is dropped for kernels with netlink support!
echo can0 > /proc/net/can-j1939/net
# Using J1939
## BSD socket implementation
* socket
* bind / connect
* recvfrom / sendto
* getsockname / getpeername
## Modified *struct sockaddr_can*
struct sockaddr_can {
sa_family_t can_family;
int can_ifindex;
union {
struct {
__u64 name;
__u32 pgn;
__u8 addr;
} j1939;
} can_addr;
}
* *can_addr.j1939.pgn* is PGN
* *can_addr.j1939.addr* & *can_addr.j1939.name*
determine the ECU
* receiving address information,
*addr* is always set,
*name* is set when available.
* When providing address information,
*name* != 0 indicates dynamic addressing
## iproute2
### Static addressing
ip addr add j1939 0x80 dev can0
### Dynamic addressing
ip addr add j1939 name 0x012345678abcdef dev can0
# Kickstart guide to j1939 on linux
## Prepare using VCAN
You may skip this step entirely if you have a functional
**can0** bus on your system.
Load module, when *vcan* is not in-kernel
modprobe vcan
Create a virtual can0 device and start the device
ip link add can0 type vcan
ip link set can0 up
## First steps with j1939
Use [testj1939](testj1939.c)
When *can-j1939* is compiled as module, load it.
modprobe can-j1939
Enable the j1939 protocol stack on the CAN device
ip link set can0 j1939 on
Most of the subsequent examples will use 2 sockets programs (in 2 terminals).
One will use CAN_J1939 sockets using *testj1939*,
and the other will use CAN_RAW sockets using cansend+candump.
testj1939 can be told to print the used API calls by adding **-v** program argument.
### receive without source address
Do in terminal 1
./testj1939 -r can0:
Send raw CAN in terminal 2
cansend can0 1823ff40#0123
You should have this output in terminal 1
40 02300: 01 23
This means, from NAME 0, SA 40, PGN 02300 was received,
with 2 databytes, *01* & *02*.
now emit this CAN message:
cansend can0 18234140#0123
In J1939, this means that ECU 0x40 sends directly to ECU 0x41
Since we did not bind to address 0x41, this traffic
is not meant for us and *testj1939* does not receive it.
### Use source address
./testj1939 can0:0x80
will say
./testj1939: bind(): Cannot assign requested address
Since J1939 maintains addressing, **0x80** has not yet been assigned
as an address on **can0** . This behaviour is very similar to IP
addressing: you cannot bind to an address that is not your own.
Now tell the kernel that we *own* address 0x80.
It will be available from now on.
ip addr add j1939 0x80 dev can0
./testj1939 can0:0x80
now succeeds.
### receive with source address
Terminal 1:
./testj1939 -r can0:0x80
Terminal 2:
cansend can0 18238040#0123
Will emit this output
40 02300: 01 23
This is because the traffic had destination address __0x80__ .
### send
Open in terminal 1:
candump -L can0
And to these test in another terminal
./testj1939 -s can0:0x80
This produces **1BFFFF80#0123456789ABCDEF** on CAN.
./testj1939 -s can0:
will produce exactly the same because **0x80** is the only
address currently assigned to **can0:** and is used by default.
### Multiple source addresses on 1 CAN device
ip addr add j1939 0x90 dev can0
./testj1939 -s can0:0x90
produces **1BFFFF90#0123456789ABCDEF** ,
./testj1939 -s can0:
still produces **1BFFFF80#0123456789ABCDEF** , since **0x80**
is the default _source address_.
Check
ip addr show can0
emits
X: can0: <NOARP,UP,LOWER_UP> mtu 16 qdisc noqueue state UNKNOWN
link/can
can-j1939 0x80 scope link
can-j1939 0x90 scope link
0x80 is the first address on can0.
### Use specific PGN
./testj1939 -s can0:,0x12345
emits **1923FF80#0123456789ABCDEF** .
Note that the real PGN is **0x12300**, and destination address is **0xff**.
### Emit destination specific packets
The destination field may be set during sendto().
*testj1939* implements that like this
./testj1939 -s can0:,0x12345 can0:0x40
emits **19234080#0123456789ABCDEF** .
The destination CAN iface __must__ always match the source CAN iface.
Specifing one during bind is therefore sufficient.
./testj1939 -s can0:,0x12300 :0x40
emits the very same.
### Emit different PGNs using the same socket
The PGN is provided in both __bind( *sockname* )__ and
__sendto( *peername* )__ , and only one is used.
*peername* PGN has highest precedence.
For broadcasted transmissions
./testj1939 -s can0:,0x12300 :,0x32100
emits **1B21FF80#0123456789ABCDEF** rather than 1923FF80#012345678ABCDEF
Desitination specific transmissions
./testj1939 -s can0:,0x12300 :0x40,0x32100
emits **1B214080#0123456789ABCDEF** .
It makes sometimes sense to omit the PGN in __bind( *sockname* )__ .
### Larger packets
J1939 transparently switches to *Transport Protocol* when packets
do not fit into single CAN packets.
./testj1939 -s20 can0:0x80 :,0x12300
emits:
18ECFF80#20140003FF002301
18EBFF80#010123456789ABCD
18EBFF80#02EF0123456789AB
18EBFF80#03CDEF01234567
The fragments for broadcasted *Transport Protocol* are seperated
__50ms__ from each other.
Destination specific *Transport Protocol* applies flow control
and may emit CAN packets much faster.
./testj1939 -s20 can0:0x80 :0x90,0x12300
emits:
18EC9080#1014000303002301
18EC8090#110301FFFF002301
18EB9080#010123456789ABCD
18EB9080#02EF0123456789AB
18EB9080#03CDEF01234567
18EC8090#13140003FF002301
The flow control causes a bit overhead.
This overhead scales very good for larger J1939 packets.
## Advanced topics with j1939
### Change priority of J1939 packets
./testj1939 -s can0:0x80,0x0100
./testj1939 -s -p3 can0:0x80,0x0200
emits
1801FF80#0123456789ABCDEF
0C02FF80#0123456789ABCDEF
### using connect
### advanced filtering
## dynamic addressing
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: AW: Need support J1939 protocol support to my kernel (v3.8 on BeagleBone Black)
@ 2014-01-15 16:14 swapnil
2014-01-16 21:43 ` Kurt Van Dijck
0 siblings, 1 reply; 9+ messages in thread
From: swapnil @ 2014-01-15 16:14 UTC (permalink / raw
To: linux-can
Hi Kurt,
Using the test code given by you I have developed an app but I am
facing some issues i don't know its j1939 limitation or the stack.
1.I want to transmit and single frame message RACM message
canId--18EAFEFF data 00EE00FFFFFFFFFFFF it asks to bind address with 0xFE
note -can i transmit single frame message like raw can from any source
address
to any dest address.
I think address claim is needed for only TP message
2. In case of multiple address claims like 0x80 and 0x90 if i want to
transmit the data from both address parallel y do i need to create different
socket for each address?
3.It don't reply for RACM message if i send from different adapter
example: 18EAFEFF#00EE00FFFFFFFFFFFF j1939 stack should reply with claimed
address Like 80 and 90
I was busy in creating the app to test the linux j1939 stack on
begalbone Black. thank you very much for the test programs those helped me
a lot
Thank
Swapnil
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: AW: Need support J1939 protocol support to my kernel (v3.8 on BeagleBone Black)
2014-01-15 16:14 swapnil
@ 2014-01-16 21:43 ` Kurt Van Dijck
0 siblings, 0 replies; 9+ messages in thread
From: Kurt Van Dijck @ 2014-01-16 21:43 UTC (permalink / raw
To: swapnil; +Cc: linux-can
Hi Swapnil,
> Using the test code given by you I have developed an app but I am
> facing some issues i don't know its j1939 limitation or the stack.
>
> 1.I want to transmit and single frame message RACM message
RACM?
I don't know the RACM acronym. Can you explain a bit?
> canId--18EAFEFF data 00EE00FFFFFFFFFFFF it asks to bind address with 0xFE
I guess you want 18eafffe#00ee (PGN 0ea00 is per J1939 only 3 bytes long).
Because FF is not allowed as source, and 0xfe is fuzzy to use as destination.
Likewise, 0xfe as source is common thing to do for requesting others address
claims, and FF as destination is, well, a broadcast.
>
> note -can i transmit single frame message like raw can from any source
> address
> to any dest address.
That is true, but not every combination is a 'legal' withing J1939 context.
> I think address claim is needed for only TP message
Address claim is needed for dynamic addressing (j1939-81).
This can be combined, but it really unrelated to TP (transport protocol).
Your story is valid without address claims also, using static addressing.
>
> 2. In case of multiple address claims like 0x80 and 0x90 if i want to
> transmit the data from both address parallel y do i need to create different
> socket for each address?
s/multiple address claims/multiple addresses/
If you want to transmit both 18000080#xxxx & 18000090#xxxx, you need a different
socket for each address.
Note that a single source address indicates a logical node.
It's quite uncommon to combine different logical nodes into 1 program,
but if you'd want to, different sockets is the way to go ...
>
> 3.It don't reply for RACM message if i send from different adapter
> example: 18EAFEFF#00EE00FFFFFFFFFFFF j1939 stack should reply with claimed
> address Like 80 and 90
I see what you mean.
18eafffe#00ee00 from a remote should be replied with the address claims.
You should really consider using jacd then.
That will deal with j1939-81 (1 instance for each SA).
Do you need dynamic addresses? Static addresses make things a lot simpler.
And static addresses allow Transport Protocol :-).
>
> I was busy in creating the app to test the linux j1939 stack on
> begalbone Black. thank you very much for the test programs those helped me
> a lot
That's cool! It feels fine that it helps others.
--
Kurt Van Dijck
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-01-16 21:43 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-11 16:14 AW: Need support J1939 protocol support to my kernel (v3.8 on BeagleBone Black) Michael Luxen
2013-11-12 1:10 ` swapnil
2013-11-12 10:02 ` Kurt Van Dijck
2013-11-28 4:49 ` swapnil
2013-11-28 8:52 ` Kurt Van Dijck
2013-12-04 22:10 ` swapnil
2013-12-05 19:59 ` Kurt Van Dijck
-- strict thread matches above, loose matches on Subject: below --
2014-01-15 16:14 swapnil
2014-01-16 21:43 ` Kurt Van Dijck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.