using j1939
Hi Kurt,
I am sorry it is me again. I cloned the three repositories, can-j1939-modules, can-j1939, iproute2-1939 as you told me. Now I want to create new packages out of this repositories (I hope this is the right way). But now I am facing the next problem, what type of packages do I have to create for each particular repository?
Sorry for your trouble,
Wolfgang
Signature · 2 lines
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie! Jetzt informieren: http://www.gmx.net/de/go/freephone
Quoted 1 line
I cloned the three repositories, can-j1939-modules, can-j1939, iproute2-1939 as you told me.
I suppose you meant 'can-j1939-modules', 'can-j1939-utils' and 'iproute2-j1939' ...
Quoted 1 line
Now I want to create new packages out of this repositories (I hope this is the right way).
Packages?
I'm afraid you lost me on this. Using your (cross)toolchain, you do
$ make etc. to compile (& install) the binaries.
Quoted 1 line
But now I am facing the next problem, what type of packages do I have to create for each particular repository?
I believe you're asking something for a specific build system, but I do not know which one.
What build system do you use?
Would it be interesting to setup things on your (linux) host PC on a virtual CAN bus? Then several things may be a lot easier.
Kurt
Quoted 3 lines · Kurt Van Dijck
I believe you're asking something for a specific build system, but I do not know which one.
What build system do you use?
I was too quick, I got the answer in history: you're using OSELAS.... Isn't that a Pengutronix toolchain? They may know how to do stuff... Since linux-can now moved to git repositories, replacing 'can' with 'can-j1939' _could_ be easy...
Kurt
Quoted 3 lines
I'm afraid you lost me on this. Using your (cross)toolchain, you do
$ make etc. to compile (& install) the binaries.
The guys from pengutronix (I am using ptxdist 2010.07.1) told me that I have to know how the things in the repositories have to be built.
Quoted 1 line
Quoted 1 line
But now I am facing the next problem, what type of packages do
I have to
create for each particular repository?
Quoted 3 lines
I believe you're asking something for a specific build system, but I do not know which one.
What build system do you use?
found and using toolchain:
'/opt/OSELAS.Toolchain-1.99.3/powerpc-603e-linux-gnu/ gcc-4.3.2-glibc-2.8-binutils-2.18-kernel-2.6.27-sanitized/bin'
Quoted 3 lines
Would it be interesting to setup things on your (linux) host PC on a virtual CAN bus?
Then several things may be a lot easier.
It should or have to run on the target phyCore MPC5121etiny
Wolfgang
Quoted 4 lines
The guys from pengutronix (I am using ptxdist 2010.07.1) told me that I have to know how the things in the repositories have to be built.
can-j1939-utils: (Similar to can-utils)
I think you need to do this:
$ ./autogen.sh $ ./configure --host=powerpc-603e-linux-gnu --prefix=/usr $ make $ make install DESTDIR=...
iproute2-j1939: (Similar to iproute2, which is for sure present in your toolchain) I think you need to do this:
$ make KERNEL_INCLUDE=<KERNEL_HEADER_PATH> CC=powerpc-603e-linux-gnu-gcc $ make install DESTDIR=...
can-j1939-modules:
I'm not sure. Building this package with a cross-toolchain is something I never did. I patched the kernel source itself in a 'cross' situation.
I only used can-j1939-modules for my own host.
anyone?
Quoted 3 lines
Quoted 1 line
Quoted 1 line
But now I am facing the next problem, what type of packages do
I have to
create for each particular repository?
Yes, I think so.
Kurt
Quoted 11 lines · Wolfgang
Quoted 3 lines
I'm afraid you lost me on this. Using your (cross)toolchain, you do
$ make etc. to compile (& install) the binaries.The guys from pengutronix (I am using ptxdist 2010.07.1) told me that I have to know how the things in the repositories have to be built.
Quoted 1 line
Quoted 1 line
But now I am facing the next problem, what type of packages do
I have to
create for each particular repository?
Quoted 8 lines
Quoted 3 lines
I believe you're asking something for a specific build system, but I do not know which one.
What build system do you use?found and using toolchain:
'/opt/OSELAS.Toolchain-1.99.3/powerpc-603e-linux-gnu/gcc-4.3.2-glibc-2.8-binutils-2.18-kernel-2.6.27-sanitized/bin'
Hello Wolfgang,
when you build your BSP e.g. with
ptxdist images
in the directory 'build-target/linux-2.6.xx' your Linux kernel is unpacked, patched and compiled.
For a quick hack you can just try to update the files in
build-target/linux-2.6.xx/net/can/*
build-target/linux-2.6.xx/include/linux/can/*
with the files from Kurt (can-j1939-modules).
The you need to drop the compile stage with
pxtdist drop kernel.compile
And then build the stuff again (with 'ptxdist images')
Btw. the idea from Kurt with cross-compiling is also good.
But you should define the KERNELDIR= .../build-target/linux-2.6.xx then as THIS is the real kernel you are building for your system.
Regards,
Oliver
Quoted 6 lines
can-j1939-utils: (Similar to can-utils)
I think you need to do this:$ ./autogen.sh $ ./configure --host=powerpc-603e-linux-gnu --prefix=/usr $ make $ make install DESTDIR=...
it is working but nothing is built in the directory /test
.......
libtool: install: /usr/bin/install -c slcanpty /usr/bin/slcanpty make[1]: Nothing to be done for install-data-am'. make[1]: Leaving directory /can-j1939-utils'
make: Nothing to be done for `/test'
Quoted 1 line
iproute2-j1939: (Similar to iproute2, which is for sure present
in your toolchain)
Quoted 3 lines
I think you need to do this:
$ make KERNEL_INCLUDE=<KERNEL_HEADER_PATH> CC=powerpc-603e-linux-gnu -gcc
utils.c: In function ‘rt_addrpr_n2a’:
utils.c:518: error: ‘AF_CAN’ undeclared (first use in this function) utils.c:518: error: (Each undeclared identifier is reported only once utils.c:518: error: for each function it appears in.) make[1]: *** [utils.o] Error 1
make: *** [all] Error 2
Quoted 4 lines
$ make install DESTDIR=...can-j1939-modules:
I'm not sure. Building this package with a cross-toolchain
is something I never did.
Quoted 2 lines
I patched the kernel source itself in a 'cross' situation. I only used can-j1939-modules for my own host.
Are these mandatory or what files do I have to use?
--Wolfgang
using j1939: j1939.h
On Wed, Dec 07, 2011 at 08:55:58AM +0000, Wolfgang wrote:
I forgot to mention the modifications to your toolchain:include/linux/can.h and include/linux/can/j1939.h must be taken accordingly to what you'll find in can-j1939-modules (under include/socketcan/{can.h,can/j1939.h}.
Otherwise, you will not build any of j1939 I think...
@Oliver,
How can one use the headers of an external can-modules repository for CAN?
Quoted 3 lines
Quoted 3 lines
can-j1939-utils: (Similar to can-utils)
I think you need to do this:$ ./autogen.sh
do not forget to
$ export PATH=$PATH:YOUR_PATH_TO_POWERPC_TOOLCHAIN_BIN
Quoted 1 line
Quoted 1 line
$ ./configure --host=powerpc-603e-linux-gnu --prefix=/usr
I see (using some arm compiler)
...
checking for strtoul... yes
checking for linux/can/gw.h... no
checking for linux/can/j1939.h... yes
...
Quoted 1 line
Quoted 1 line
$ make
...
canbusload.c:(.text+0x890): undefined reference to `pselect'
...
So, I edited GNUmakefile, and removed canbusload from the program list. and then, all gets compiled.
Quoted 3 lines
Quoted 1 line
$ make install DESTDIR=...it is working but nothing is built in the directory /test
"/test" ?
Quoted 5 lines
.......
libtool: install:/usr/bin/install-c slcanpty/usr/bin/slcanptymake[1]: Nothing to be done forinstall-data-am'. make[1]: Leaving directory/can-j1939-utils'
make: Nothing to be done for `/test'
Now I'm sure, you forgot the j1939 header in the toolchain.
I'm gonna work to indicate j1939.h status during ./configure ... It's these kind of small problems that I never encountered during development ...
Quoted 1 line
Kurt
Re: using j1939: j1939.h
Quoted 3 lines
I'm gonna work to indicate
j1939.hstatus during ./configure ... It's these kind of small problems that I never encountered during development ...
I pushed 1 commit to can-j1939-utils.
$ ./autogen.sh must be issued again. It will now show more explicit that SAE J1939 will be built or not.
Quoted 3 lines
Quoted 1 line
Kurt
Re: using j1939: j1939.h
Now everything worked fine and I was able compile can-j1939-utils, iproute2-j1939 and I got two directories with $.../usr/bin.
Where do I have to place this 2 folders now or how do I get it proper to the target?
Thanks!!
using j1939: userspace binaries
Quoted 2 lines · Wolfgang
Now everything worked fine and I was able compile can-j1939-utils, iproute2-j1939 and I got two directories with $.../usr/bin.
great!
Quoted 2 lines
Where do I have to place this 2 folders now
all binaries in ..../usr/bin should go in /usr/bin on the target.
Kurt
Re: using j1939: userspace binaries
Quoted 2 lines
Quoted 1 line
Where do I have to place this 2 folders now
all binaries in ..../usr/bin should go in
/usr/binon the target.
ok just copy and paste? But from which directory the one generated by can-j1939-utils or iproute2-j1939 because they contain both all the same binaries.
--Wolfgang
Re: using j1939: userspace binaries
Quoted 4 lines · Wolfgang
Quoted 2 lines
Quoted 1 line
Where do I have to place this 2 folders now
all binaries in ..../usr/bin should go in
/usr/binon the target.ok just copy and paste?
for example
Quoted 3 lines
But from which directory the one generated
by can-j1939-utils or iproute2-j1939 because they contain both all the same binaries.
that sounds not good.
can-j1939-utils should have binaries like candump, can..., jspy, jacd, ...
iproute2-j1939 should have (at least) ip.
what files (binaries) exist in your .../usr/bin ?
Kurt
Re: using j1939: userspace binaries
Quoted 2 lines
that sounds not good.
can-j1939-utils should have binaries like candump, can..., jspy, jacd, ...
^^yes, that is true
Quoted 1 line
iproute2-j1939 should have (at least) ip.
gosh, it seems that I was a bit puzzled.
I wanted to make
$ make KERNEL_INCLUDE=<KERNEL_HEADER_PATH> CC=powerpc-603e-linux-gnu-gcc then
utils.c: In function ‘rt_addrpr_n2a’:
utils.c:518: error: ‘AF_CAN’ undeclared (first use in this function) utils.c:518: error: (Each undeclared identifier is reported only once utils.c:518: error: for each function it appears in.) make[1]: *** [utils.o] Error 1
make: *** [all] Error 2
occured
using j1939: AF_CAN missing
Quoted 7 lines · Wolfgang
Quoted 2 lines
that sounds not good.
can-j1939-utils should have binaries like candump, can..., jspy, jacd, ...^^yes, that is true
Quoted 8 lines
Quoted 1 line
iproute2-j1939 should have (at least) ip.
gosh, it seems that I was a bit puzzled.
I wanted to make
$ make KERNEL_INCLUDE=<KERNEL_HEADER_PATH> CC=powerpc-603e-linux-gnu-gcc then
I went back to this. I think I indeed puzzled you a bit.
For can-(j1939-)modules, you have to 'KERNEL_INCLUDE=<KERNEL_HEADER_PATH>' or even better, KERNEL_DIR=...,
For iproute2(-j1939),
$ make CC=powerpc-603e-linux-gnu-gcc will do.
But I believe you almost there.
Quoted 3 lines
utils.c: In function ‘rt_addrpr_n2a’:
utils.c:518: error: ‘AF_CAN’ undeclared (first use in this function)
It appears your toolchain isn't even aware of CAN. I'm not sure how to solve that one.
Anyone?
Kurt
iproute2-j1939
In reply to WolfgangWolfgang,
While playing with iproute2-j1939, I detected an outdated header j1939.h.
please pull.
Kurt
Re: using j1939: AF_CAN missing
In reply to Kurt Van DijckAm 08.12.2011 16:17, schrieb Kurt Van Dijck:
Quoted 7 lines
utils.c: In function ‘rt_addrpr_n2a’:
utils.c:518: error: ‘AF_CAN’ undeclared (first use in this function) It appears your toolchain isn't even aware of CAN.
I'm not sure how to solve that one.Anyone?
Yep. As i written before the include files of the BSP itself are outdated.
You need to specifiy the Kernel includes directory to be taken from the cross built Kernel.
---
in the directory 'build-target/linux-2.6.xx' your Linux kernel is unpacked, patched and compiled.
For a quick hack you can just try to update the files in
build-target/linux-2.6.xx/net/can/*
build-target/linux-2.6.xx/include/linux/can/*
---
This kernel supports CAN.
Your modules will not match (and load) if you build the modules against a different kernel.
And also the can-utils are happy when having the 'right' kernel includes ;-)
Regards,
Oliver
Re: iproute2-j1939
In reply to Kurt Van DijckI pulled it, but the error remains.
Is it possible that
I am using the wrong kernel_header_path:
/.../OSELAS.BSP-Phytec-phyCORE-MPC512x-tiny-PD10.1.0\
/platform-phyCORE-MPC5121e/sysroot-target/kernel-headers
Re: iproute2-j1939
In reply to Kurt Van DijckOK, I should read all posts not only the last one.
I made:
with the new one
$iproute2-j1939> make CC=powerpc-603e-linux-gnu-gcc
same error "AF-CAN" undeclared
$can-j1939-modules>make KERNEL_DIR=<...> C=powerpc-603e-linux\
-gnu-gcc
make[1]: *** No rule to make target `modules'. Stop.
make: *** [modules] Error 2
So do you think I have to replace the can.h in the kernel_header_path (/,.../sysroot-target/kernel-headers/include/linux)?
--Wolfgang
Re: iproute2-j1939
Am 08.12.2011 17:44, schrieb Wolfgang:
Quoted 14 lines
OK, I should read all posts not only the last one.
I made:
with the new one$iproute2-j1939> make CC=powerpc-603e-linux-gnu-gcc
same error "AF-CAN" undeclared
$can-j1939-modules>make KERNEL_DIR=<...> C=powerpc-603e-linux\
-gnu-gcc
Quoted 6 lines
make[1]: *** No rule to make target `modules'. Stop.
make: *** [modules] Error 2So do you think I have to replace the
can.hin thekernel_header_path(/,.../sysroot-target/kernel-headers/include/linux)?
What do you use for KERNEL_DIR=<..> ??
Can you send the complete line?
Regards,
Oliver
Re: iproute2-j1939
Morning,
Quoted 3 lines
What do you use for KERNEL_DIR=<..> ??
Can you send the complete line?
I have build the BSP (which is supporting socketcan) some time ago;
I make in ip2route-j1939:
$ make KERNEL_DIR=</home/wolfgang/phytec/kernel/OSELAS.BSP-Phytec-\ phyCORE-MPC512x-tiny-PD09.1.0/platform-phyCORE-MPC5121e/build-target\ /linux-2.6.31> CC=powerpc-603e-linux-gnu-gcc
Re: iproute2-j1939
Am 09.12.2011 08:28, schrieb Wolfgang:
Quoted 5 lines
Morning,
Quoted 3 lines
What do you use for KERNEL_DIR=<..> ??
Can you send the complete line?
Quoted 7 lines
I have build the BSP (which is supporting socketcan) some time ago;
I make in ip2route-j1939:
$ make KERNEL_DIR=</home/wolfgang/phytec/kernel/OSELAS.BSP-Phytec-\ phyCORE-MPC512x-tiny-PD09.1.0/platform-phyCORE-MPC5121e/build-target\ /linux-2.6.31> CC=powerpc-603e-linux-gnu-gcc
Hm:
Try to remove the < > and/or try to define an extra define for the include path to catch
|
|.../build-target/linux-2.6.31/include
e.g. like in this EXTRA_CFLAGS
|EXTRA_CFLAGS += \ || -I$(TOPDIR)/include \ || -I$(TOPDIR)/drivers/net/can/hal \ || \ || -DETH_P_CAN=0x000C \ || -DARPHRD_CAN=280|
Regards,
Oliver
Re: iproute2-j1939
In reply to WolfgangQuoted 2 lines
So do you think I have to replace the
can.hin thekernel_header_path
can.h got updated (struct can_addr extended), but I'm not sure exactly which paths must be updated.
Kurt
Re: iproute2-j1939
Am 09.12.2011 09:07, schrieb Kurt Van Dijck:
Quoted 4 lines
Quoted 2 lines
So do you think I have to replace the
can.hin thekernel_header_path
can.hgot updated (structcan_addrextended), but I'm not sure exactly which paths must be updated.
Argh - right. I missed that.
So my written ideas missed this detail :-(
Sorry,
Oliver
Re: iproute2-j1939
In reply to Kurt Van DijckQuoted 2 lines
can.hgot updated (structcan_addrextended), but I'm not sure exactly which paths must be updated.
OK, so do you think I have to replace the existing can.h with the can.h from can-j1939-modules?
Or is it possible that the af_can.h (found in can-j1939-modules/net/can) has to be included in the utils.c file (utils.c:518: error: 'AF_CAN'\
undeclared (first use in this function), it's just an idea?
Re: iproute2-j1939
Quoted 5 lines · Wolfgang
Quoted 2 lines
can.hgot updated (structcan_addrextended), but I'm not sure exactly which paths must be updated.OK, so do you think I have to replace the existing
can.hwith thecan.hfrom can-j1939-modules?
Yes, I think so.
Quoted 4 lines
Or is it possible that the
af_can.h(found in can-j1939-modules/net/can) has to be included in theutils.cfile (utils.c:518: error: 'AF_CAN'\
undeclared (first use in this function), it's just an idea?
No, you don't need CAN.
the macro AF_CAN for userspace applications is in bits/socket.h (of the toolchain), included by sys/socket.h.
If AF_CAN is unknown, even when "#include <sys/socket.h>", you need to modify bits/socket.h IMO. "#include <linux/socket.h>" would work, but feels a bit dirty.
You can safely add "#define AF_CAN 29" and "#define AF_CAN PF_CAN" in "sys/socket.h"
Kurt
Re: iproute2-j1939
Quoted 1 line
You can safely add "#define
AF_CAN29" and "#defineAF_CANPF_CAN" in
"sys/socket.h"
Ok, I have, done that and it worked but now the next error occured, next thing was not declared. So I thought, I will build the newer oselas toolchain? Does this make sense?
new one: old one: gcc-4.5.2 gcc-4.3.2 glibc-2.13-binutils-2.21 glibc-2.8-binutils-2.18 linux-2.6.36 linux-2.6.27
--Wolfgang
Re: iproute2-j1939
Quoted 5 lines · Wolfgang
Quoted 1 line
You can safely add "#define
AF_CAN29" and "#defineAF_CANPF_CAN" in"
sys/socket.h"Ok, I have, done that and it worked but now the next error occured, next thing was not declared. So I thought, I will build the newer oselas toolchain? Does
What was not declared?
Quoted 7 lines
this make sense?
new one: old one: gcc-4.5.2 gcc-4.3.2 glibc-2.13-binutils-2.21 glibc-2.8-binutils-2.18 linux-2.6.36 linux-2.6.27
I'm not aware of the integration of linux-can in glibc's headers. Anyone experience with this configuration?
I'm asking myself, do you got regular iproute2 compiled (with CAN)? I believe you facing problems not related to my j1939 port of them.
Kurt
Re: iproute2-j1939
Quoted 2 lines
I'm asking myself, do you got regular iproute2 compiled (with CAN)? I believe you facing problems not related to my j1939 port of them.
Do you mean the iproute2 which is included in the BSP?
--Wolfgang
Re: iproute2-j1939
Quoted 4 lines · Wolfgang
Quoted 2 lines
I'm asking myself, do you got regular iproute2 compiled (with CAN)? I believe you facing problems not related to my j1939 port of them.
Do you mean the iproute2 which is included in the BSP?
Yes.
It must have been compiled, and I assume it carries CAN support. The j1939 port of iproute2 does fail on things like AF_CAN etc. Something must be different.
Kurt
Re: iproute2-j1939
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I'm asking myself, do you got regular iproute2 compiled (with CAN)? I believe you facing problems not related to my j1939 port of them.
Do you mean the iproute2 which is included in the BSP?
Yes.
It must have been compiled, and I assume it carries CAN support. The j1939 port of iproute2 does fail on things likeAF_CANetc. Something must be different.
Ok, I see it is really tough.
At the moment I am building the new toolchain, afterwards I will build a new BSP. Maybe I have spoilt anything, in the BSP src directory is the ordinary iproute2-2.6.29-1.tar.bz2 in fact, but maybe a new BSP will help!
--Wolfgang
Wolfgang et.al.,
I created git://gitorious.org:~kurt-vd/linux-can/linux-can-j1939.git
This is a clone of linux-can (currently 3.2.0-rc2+), with can-j1939 built in.
Kurt
Quoted 57 lines · Oliver Hartkopp
Quoted 11 lines · Wolfgang
Quoted 3 lines
I'm afraid you lost me on this. Using your (cross)toolchain, you do
$ make etc. to compile (& install) the binaries.The guys from pengutronix (I am using ptxdist 2010.07.1) told me that I have to know how the things in the repositories have to be built.
Quoted 1 line
Quoted 1 line
But now I am facing the next problem, what type of packages do
I have to
create for each particular repository?Quoted 8 lines
Quoted 3 lines
I believe you're asking something for a specific build system, but I do not know which one.
What build system do you use?found and using toolchain:
'/opt/OSELAS.Toolchain-1.99.3/powerpc-603e-linux-gnu/gcc-4.3.2-glibc-2.8-binutils-2.18-kernel-2.6.27-sanitized/bin'Hello Wolfgang,
when you build your BSP e.g. with
ptxdist images
in the directory 'build-target/linux-2.6.xx' your Linux kernel is unpacked, patched and compiled.
For a quick hack you can just try to update the files in
build-target/linux-2.6.xx/net/can/*
build-target/linux-2.6.xx/include/linux/can/*with the files from Kurt (can-j1939-modules).
The you need to drop the compile stage with
pxtdist drop kernel.compile
And then build the stuff again (with 'ptxdist images')
Btw. the idea from Kurt with cross-compiling is also good.
But you should define the KERNELDIR= .../build-target/linux-2.6.xx then as THIS is the real kernel you are building for your system.
Regards,
Oliver--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines
I created
git://gitorious.org:~kurt-vd/linux-can/linux-can-j1939.git
This is a clone of linux-can (currently 3.2.0-rc2+), with can-j1939 built in.
Thanks, I am wondering how or what can I use?
Quoted 4 lines · Wolfgang Wagner
Quoted 2 lines
I don't understand your question.
Yes, you may use it.I cloned the linux-can-j1939 repository, but how do I get it to the target or what I have to do to get it setup for the target?
Ok, I suppose you do not compile your kernel yourself. I don't know that for your system.
Let's stick to the original plan then and get can-j1939-modules working (after getting iproute2-j1939 up).
Kurt
Quoted 6 lines
Thanks!
Signature · 2 lines
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie! Jetzt informieren: http://www.gmx.net/de/go/freephone
Quoted 1 line
Ok, I suppose you do not compile your kernel yourself.
Yes, ptxdist compiles everything automatic, but as Oliver suggest for my system I can can drop the kernel and compile it again with
$ ptxdist drop kernel compile $ ptxdist go
So is there a possibility to modify my kernel with files of your linux-can-j1939 repository and compile it again?
Quoted 1 line
Let's stick to the original plan then and get can-j1939-modules working
(after getting iproute2-j1939 up).
So if I use the tarball iproute2-2.6.39.tar.gz, you can find everywhere, it should work? Or is there the possibility, that I possibly can faulty one?
Quoted 10 lines · Wolfgang Wagner
Quoted 1 line
Ok, I suppose you do not compile your kernel yourself.
Yes, ptxdist compiles everything automatic, but as Oliver suggest for my system I can can drop the kernel and compile it again with
$ ptxdist drop kernel compile $ ptxdist goSo is there a possibility to modify my kernel with files of your linux-can-j1939 repository and compile it again?
Yes, that must work. Take everything in net/can/*.
I'm not sure on the drivers. They may use other subsystems (like USB) that have differences accross versions.
I'd first try to core CAN itself(net/can) and leave the drivers (drivers/net/can) as is.
The header is a bit a mixture:
copy include/linux/can.h, all include/linux/can/*.h but dev.h, and _no_ include/linux/can/platform/*.h
Quoted 8 lines
Quoted 3 lines
Let's stick to the original plan then and get can-j1939-modules working
(after getting iproute2-j1939 up).
So if I use the tarball iproute2-2.6.39.tar.gz, you can find everywhere, it should work? Or is there the possibility, that I possibly can faulty one?
I think a iproute2-2.6.39.tar.gz should compile.
Iproute2-j1939 did fail because of CAN definitions, that are in a standard iproute2 also.
If that one compiles, my iproute2-j1939 should work as.
Quoted 1 line
Kurt
Quoted 4 lines
Yes, that must work. Take everything in
net/can/*.
I'm not sure on the drivers. They may use other subsystems (like USB) that have differences accross versions.
I'd first try to core CAN itself(net/can) and leave the drivers
(drivers/net/can)
Quoted 4 lines
as is.
The header is a bit a mixture:
copyinclude/linux/can.h, allinclude/linux/can/*.hbutdev.h, and _no_include/linux/can/platform/*.h
Ok I replaced everything as you told me, but while compiling
make[1]: Entering directory `/home/wolfgang/phytec/kernel/OSELAS.BSP-Phytec-phyCORE-MPC512x-tiny-\
PD09.1.0/platform-phyCORE-MPC5121e/build-target/linux-2.6.31'
CHK include/linux/version.h
CHK include/linux/utsrelease.h
SYMLINK include/asm -> include/asm-powerpc
CALL scripts/checksyscalls.sh CHK include/linux/compile.h CALL arch/powerpc/kernel/systbl_chk.sh CC net/can/bcm.o
In file included from net/can/bcm.c:55:include/linux/can.h:80: error: expected specifier-qualifier-list \
before'__kernel_sa_family_t'net/can/bcm.c: In function 'bcm_proc_getifname':net/can/bcm.c:150: error: implicit declaration of function 'dev_get_by_index_rcu'net/can/bcm.c:150: warning: assignment makes pointer from integer \
without a castnet/can/bcm.c: In function 'bcm_send_to_user':net/can/bcm.c:332: error: 'struct sockaddr_can' has no member named\can_family'net/can/bcm.c:333: error: 'struct sockaddr_can' has no member named can_ifindex'net/can/bcm.c: In function 'bcm_sendmsg':net/can/bcm.c:1253: error: 'struct sockaddr_can' has no member named 'can_ifindex'net/can/bcm.c:1253: error: 'struct sockaddr_can' has no member named 'can_ifindex'net/can/bcm.c:1256: error: 'struct sockaddr_can' has no member named 'can_family'net/can/bcm.c:1260: error: 'struct sockaddr_can' has no member named 'can_ifindex'net/can/bcm.c: In function 'bcm_connect':net/can/bcm.c:1495: error: 'struct sockaddr_can' has no member named 'can_ifindex'net/can/bcm.c:1495: error: 'struct sockaddr_can' has no member named 'can_ifindex'net/can/bcm.c:1502: error: 'struct sockaddr_can' has no member named 'can_ifindex'net/can/bcm.c:1505: error: 'struct sockaddr_can' has no member named 'can_ifindex'net/can/bcm.c: In function 'bcm_recvmsg':net/can/bcm.c:1559: error: implicit declaration of function 'sock_recv_ts_and_drops'
make[3]: *** [net/can/bcm.o] Error 1
make[2]: *** [net/can] Error 2
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [net] Error 2
make[1]: *** Waiting for unfinished jobs....
Quoted 18 lines · Wolfgang
Quoted 4 lines
Yes, that must work. Take everything in
net/can/*.
I'm not sure on the drivers. They may use other subsystems (like USB) that have differences accross versions.
I'd first try to core CAN itself(net/can) and leave the drivers(
drivers/net/can)Quoted 4 lines
as is.
The header is a bit a mixture:
copyinclude/linux/can.h, allinclude/linux/can/*.hbutdev.h, and _no_include/linux/can/platform/*.hOk I replaced everything as you told me, but while compiling
make[1]: Entering directory `/home/wolfgang/phytec/kernel/OSELAS.BSP-Phytec-phyCORE-MPC512x-tiny-\
PD09.1.0/platform-phyCORE-MPC5121e/build-target/linux-2.6.31'
CHKinclude/linux/version.h
CHKinclude/linux/utsrelease.h
SYMLINKinclude/asm->include/asm-powerpc
Quoted 7 lines
CALL scripts/checksyscalls.sh CHK include/linux/compile.h CALL arch/powerpc/kernel/systbl_chk.sh CC net/can/bcm.oIn file included from
net/can/bcm.c:55:include/linux/can.h:80: error: expected specifier-qualifier-list \
before'__kernel_sa_family_t'
I've noticed in recent kernels that 'sa_family_t' got replaced by '__kernel_sa_family_t'.
I see no harm in undoing this, thus modifying the new include/linux/can.h, making sockaddr_can.can_family of type sa_family_t again.
Kurt
I am sorry next error:
CHK include/linux/version.h
CHK include/linux/utsrelease.h
SYMLINK include/asm -> include/asm-powerpc
CALL scripts/checksyscalls.sh
CHK include/linux/compile.h
CALL arch/powerpc/kernel/systbl_chk.sh
CC net/can/bcm.o
net/can/bcm.c: In function 'bcm_proc_getifname':
net/can/bcm.c:150: error: implicit declaration of function 'dev_get_by_index_rcu'
net/can/bcm.c:150: warning: assignment makes pointer from integer without a cast
CC net/can/gw.o
net/can/bcm.c: In function 'bcm_recvmsg':
net/can/bcm.c:1559: error: implicit declaration of function 'sock_recv_ts_and_drops'
make[3]: *** [net/can/bcm.o] Error 1
make[3]: *** Waiting for unfinished jobs....
CC drivers/net/can/dev.onet/can/gw.c: In function 'cgw_module_init':net/can/gw.c:928: error: too many arguments to function '__rtnl_register' net/can/gw.c:935: error: too many arguments to function '__rtnl_register' net/can/gw.c:936: error: too many arguments to function '__rtnl_register' make[3]: *** [net/can/gw.o] Error 1
make[2]: *** [net/can] Error 2
make[1]: *** [net] Error 2
make[1]: *** Waiting for unfinished jobs....
CC drivers/net/can/mscan/mscan.o CC drivers/net/can/mscan/mpc52xx_can.o LD drivers/net/can/can-dev.o LD drivers/net/can/mscan/mscan-mpc52xx.o LD drivers/net/can/mscan/built-in.o LD drivers/net/can/built-in.o LD drivers/net/built-in.o LD drivers/built-in.o
--Wolfgang
backporting can & can-j1939
Wolfgang,
I tried myself a little backport of net/can/ into 2.6.31. It appears quite complex. It may be better to start over with a fresh kernel, and copy those files from my can-j1939-modules, since this repository contains #if KERNEL_VERSION macros that will make it work on 2.6.31.
I'm even using this on 2.6.25, so don't worry, it _will_ work sooner or later.
I'm not sure exactly how the include/socketcan from can-j1939-modules should be merged into the kernel source.
I think this is a bit of a manual job to do for the header files.
Anyone better ideas?
Kind regards,
Kurt
Re: backporting can & can-j1939
Quoted 4 lines
It appears quite complex. It may be better to start over with a fresh kernel, and copy those files from my can-j1939-modules, since this repository contains #if
KERNEL_VERSIONmacros that will make it work on 2.6.31.
I am not really sure, so I ask, should I build a new kernel and after building replace the things from can-j1939-modules or should I place the things from can-j1939-modules before building the kernel?
And what particular things should I copy?
--Wolfgang
Re: backporting can & can-j1939
Quoted 9 lines · Wolfgang
Quoted 4 lines
It appears quite complex. It may be better to start over with a fresh kernel, and copy those files from my can-j1939-modules, since this repository contains #if
KERNEL_VERSIONmacros that will make it work on 2.6.31.I am not really sure, so I ask, should I build a new kernel and after building replace the things from can-j1939-modules or should I place the things from can-j1939-modules before building the kernel?
And what particular things should I copy?
Ok, Maybe I did explain it a bit fuzzy.
Like Oliver suggested earlier, you will ultimately build a new kernel.
1. You extract the kernel source (I believe $ptxdist prepare <kernel>).
2. You copy from can-j1939-modules into the extracted kernel sources:
$ cp -r <can-j1939>/net/can/* <kernel>/net/can/
$ cp <can-j1939>/include/socketcan/can.h <kernel>/include/linux/can.h
$ cp <can-j1939>/include/socketcan/can/{bcm,core,error,gw,isotp,j1939,netlink,raw}.h \
<kernel>/include/linux/can/
and replace all "#include <socketcan/xxx.h>"
with "#include <linux/xxx.h>".
This "#include" thing will appear in files you just copies (net/can/* and include/linux/can*)
3. Continue the build processSorry for not making this clear the first time :-). I hope it is clear now?
Kurt
Re: backporting can & can-j1939
Quoted 2 lines
Sorry for not making this clear the first time .
I hope it is clear now?
That is absolutly no problem, I am really glad that you are helping me that much.
I hope this will work with less trouble!
--Wolfgang
Re: backporting can & can-j1939
In reply to Kurt Van DijckYour proposal worked perfect, I can still hardly believe it.
on the target:
$ dmesg | fgrep -i can
mpc52xx_can 80001300.mscan: MSCAN at 0xd1080300, irq 16, clock 100000000 Hz mpc52xx_can 80001380.mscan: MSCAN at 0xd1084380, irq 17, clock 100000000 Hz
can: controller area network core (rev 20090105 abi 8)
can: raw protocol (rev 20090105)
can: broadcast manager protocol (rev 20090105 t)
can: netlink gateway (rev 20101209)
can: SAE J1939
but when I type (according to the j1939.txt)
$ ip link set can0 j1939 on
it says:
Error: either "dev" is duplicate, or "j1939" is a garbage.
What have I done wrong, or how is it made right?
Thank you very much so far!!
--Wolfgang
Re: backporting can & can-j1939
Quoted 1 line · Wolfgang
Your proposal worked perfect, I can still hardly believe it.
Ok, that relieves a bit the pressure.
Quoted 14 lines
on the target:
$ dmesg | fgrep -i can
mpc52xx_can80001300.mscan: MSCAN at0xd1080300, irq 16, clock 100000000 Hzmpc52xx_can80001380.mscan: MSCAN at0xd1084380, irq 17, clock 100000000 Hz
can: controller area network core (rev 20090105 abi 8)
can: raw protocol (rev 20090105)
can: broadcast manager protocol (rev 20090105 t)
can: netlink gateway (rev 20101209)
can: SAE J1939
Quoted 3 lines
but when I type (according to the j1939.txt)
$ ip link set can0 j1939 on
Hold here: Your 2.6.31 is too old for this feature. You must do : $ echo can0 > /proc/net/can-j1939/net as a legacy measure.
You will be able to use $ip for adding/removing addressing info.
Quoted 4 lines
it says:
Error: either "dev" is duplicate, or "j1939" is a garbage.
This makes me think you have the original 'stock' iproute2, and not the iproute2-j1939 one (but I'm not sure yet today).
I'll come back on this tomorrow...
Kurt
Quoted 2 lines
Thank you very much so far!!
Thank you for the patience with operating as a 'test user'!
Kurt
Re: backporting can & can-j1939
Quoted 5 lines
Hold here: Your 2.6.31 is too old for this feature. You must do : $ echo can0 >
/proc/net/can-j1939/netas a legacy measure.You will be able to use $ip for adding/removing addressing info.
Ok, I will try that.
Quoted 4 lines
Quoted 1 line
Error: either "dev" is duplicate, or "j1939" is a garbage.
This makes me think you have the original 'stock' iproute2, and not the iproute2-j1939 one (but I'm not sure yet today).
Yes, you are right I was using the 'stock' iproute2, should I replace the stock with the j1939 iproute2, before compiling the kernel? I think I understood that wrong.
Do I have to replace the can-utils as well; I am still not complete aware how the respitories differ from each other
--Wolfgang
Using can & can-j1939
Quoted 6 lines · Wolfgang
Quoted 4 lines
Quoted 1 line
Error: either "dev" is duplicate, or "j1939" is a garbage.
This makes me think you have the original 'stock' iproute2, and not the iproute2-j1939 one (but I'm not sure yet today).
Yes, you are right I was using the 'stock' iproute2
That explains things :-)
Quoted 2 lines
should I replace the stock
with the j1939 iproute2, before compiling the kernel?
No, not before 'compiling' the kernel.
But before 'using' the j1939 options from the newly compiled kernel.
Quoted 1 line
I think I understood that wrong.
Not really..., see below
Quoted 1 line
Do I have to replace the can-utils as well;
Yes,
Quoted 2 lines
I am still not complete aware how
the respitories differ from each other
I did never really explain this, therefore:
I added j1939 into the kernel => recompile kernel.
I added j1939 configuration to iproute2 => replace iproute2 for using j1939 I added some specific j1939 support & monitoring tools (jacd, ...) =>
replace can-utils for using j1939
Summarize: the real core of j1939 is in kernel space.
To get it up & running, you need some (smaller) userspace modifications.
I hope this demistifies a tiny bit
Kind regards,
Kurt
Re: Using can & can-j1939
Quoted 1 line
I hope this demistifies a tiny bit
OK, I think things got a bit clearer for me.
1. You have to get the j1939 'into' the kernel space (check).
2. You have to cross compile the utils (check) and iproute2(remaining) and copy it in the running target user space.
Hope I got that right!?
Now let's handle the problem with compilation of the iproute2, I did,
$make CC=powerpc-603e-linux-gnu-gcc error:
powerpc-603e-linux-gnu-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 /opt/OSELAS.Toolchain-1.99.3/powerpc-603e-linux-gnu/gcc-4.3.2-glibc-2.8-binutils- 2.18-kernel-2.6.27-sanitized/lib/gcc/powerpc-603e-linux-gnu/4.3.2/../../../.. /powerpc-603e-linux-gnu/bin/ld: cannot find -ldb
collect2: ld returned 1 exit status
make[1]: *** [arpd] Error 1
make[1]: Leaving directory `/home/wolfgang/iproute2-j1939/misc'
make: *** [all] Error 2
Could that be a problem, because of an previous error a copied the db_185 header from the host to the toolchain usr/include directory?
--Wolfgang
Cross-compiling iproute2-j1939
Quoted 9 lines · Wolfgang
Quoted 1 line
I hope this demistifies a tiny bit
OK, I think things got a bit clearer for me.
1. You have to get the j1939 'into' the kernel space (check).
2. You have to cross compile the utils (check) and iproute2(remaining) and copy it in the running target user space.Hope I got that right!?
Yes, that's it.
You summarized it well, I'll reuse this for documentation eventually.
Quoted 17 lines
Now let's handle the problem with compilation of the iproute2, I did,
$make CC=powerpc-603e-linux-gnu-gcc error:powerpc-603e-linux-gnu-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/opt/OSELAS.Toolchain-1.99.3/powerpc-603e-linux-gnu/gcc-4.3.2-glibc-2.8-binutils-2.18-kernel-2.6.27-sanitized/lib/gcc/powerpc-603e-linux-gnu/4.3.2/../../../.. /powerpc-603e-linux-gnu/bin/ld: cannot find -ldb
collect2: ld returned 1 exit status
make[1]: *** [arpd] Error 1
make[1]: Leaving directory `/home/wolfgang/iproute2-j1939/misc'
make: *** [all] Error 2
Quoted 2 lines
Could that be a problem, because of an previous error a copied the
db_185header from the host to the toolchain usr/include directory?
I think you got really far now, and reached 'arpd' (on my system, 'ip' is compiled then). 'arpd' needs 'libdb'. I don't think copying the db_185 header is a problem, but the libdb.so or libdb.a remains absent.
I think Pengutronix supports compiling iproute2 _with_ some patches. I think you better apply those too.
As an alternative, you could get rid of arpd (I'm not using it on our target) with following patch or similar:
Kurt
misc/Makefile +2 -2
@@ -1,10 +1,10 @@ SSOBJ=ss.o ssfilter.o LNSTATOBJ=lnstat.o lnstat_util.o -TARGETS=ss nstat ifstat rtacct arpd lnstat - include ../Config +TARGETS=ss nstat ifstat rtacct lnstat $(MISC_EXTRA) + all: $(TARGETS) ss: $(SSOBJ) $(LIBUTIL)
Re: Cross-compiling iproute2-j1939
Quoted 2 lines
I think Pengutronix supports compiling iproute2 _with_ some patches. think you better apply those too.
When you can use it I could send you the bash compiling iproute2 with pengutronix
I don't know which or what they patched, so I applied your proposal (I had to change it in the iproute2-j1939, not in the BSP?) - and it worked.
When I have it to change it in the BSP, I am wondering how it get reference, because I do $make KERNEL_INCLUDE=<KERNEL_HEADER_PATH> CC=...
but the kernel header path is .../built-target/linux-2.6.31 and the iproute2 path is ../built-target/iproute2-2.6.29-1 so they aren't in touch, as I understand that.
But I hope I did it right!! So can I now copy and/or replace the things which I created from compiling iproute2-j1939 and can-utils-j1939 to the target or all of it?
(iproute2 created 6 directories etc, lib, sbin, share, usr, var)
--Wolfgang
replacing iproute2 & can-utils with j1939 variants
Quoted 4 lines · Wolfgang
but the kernel header path is .../built-target/linux-2.6.31 and the iproute2 path is ../built-target/iproute2-2.6.29-1 so they aren't in touch, as I understand that.
Kernel does not alter the ABI in an incompatible way. So iprout2-2.6.29 will work with linux-2.6.29 and higher.
The other way (like iproute2-2.6.35 on linux-2.6.31) works as long as iproute2 does not use features introduced since 2.6.31 :-)
Quoted 4 lines
But I hope I did it right!! So can I now copy and/or replace the things which I created from compiling iproute2-j1939 and can-utils-j1939 to the target or all of it?
You can.
To be more precise, you :
* _must_ replace the original 'ip' with the one from iproute2-j1939
* _must_ add 'jacd', 'jspy' and 'jsr' from can-j1939-utils
You _may_ replace other binaries, but that is not necessary.
Kurt
Re: replacing iproute2 & can-utils with j1939 variants
I copied all things as you told me, I think/hope the hardest part is over now. Thank you!!
What do I have to do afterwards I did
$ echo can0 /proc/net/can-j1939/net
because if I do '$ifconfig can0 up' it responses with
mpc52xx_can 80001300.mscan: bit-timing not yet defined
ifconfig: SIOCSIFFLAGS: Invalid argument
(Just for information this time different answer:
$ ip link set can0 j1939 on RTNETLINK answers: Invalid argument )
Is there any documentation or is it possible to use cangw with API?
--Wolfgang
using can-j1939
Quoted 7 lines · Wolfgang
I copied all things as you told me, I think/hope the hardest part is over now. Thank you!!
What do I have to do afterwards I did
$ echo can0 /proc/net/can-j1939/net
$ echo can0 > /proc/net/can-j1939/net
Quoted 5 lines
because if I do '$ifconfig can0 up' it responses with
mpc52xx_can80001300.mscan: bit-timing not yet defined
ifconfig: SIOCSIFFLAGS: Invalid argument
try:
$ ip link set can0 up type can bitrate 250000
Quoted 6 lines
(Just for information this time different answer:
$ ip link set can0 j1939 on RTNETLINK answers: Invalid argument )
now, you can:
$ jspy -P to see all j1939 packets. Transport Protocol sessions are assembled into big packets.
Quoted 1 line
Is there any documentation
There isn't much documenation yet of jspy & jsr, but they are basic tools.
$ jspy -? produces: jspy: An SAE J1939 spy utility Usage: jspy [OPTION...] [[IFACE:][NAME|SA][,PGN]]
-v, --verbose Increase verbosity
-P, --promisc Run in promiscuous mode
(= receive traffic not for this ECU)
-b, --block=SIZE Use a receive buffer of SIZE (default 1024)
-t, --time[=a|d|z|A] Show time: (a)bsolute, (d)elta, (z)ero, (A)bsolute w date$ jsr -? produces: jsr: An SAE J1939 send/recv utility Usage: jsr [OPTION...] SOURCE [DEST]
-v, --verbose Increase verbosity -p, --priority=VAL J1939 priority (0..7, default 6) -S, --serialize Strictly serialize outgoing packets -s, --size Packet size, default autodetected
SOURCE [IFACE:][NAME|SA][,PGN]
DEST [NAME|SA]
jsr allows you to put stdin into transmitted j1939 packets, and received j1939 packets onto stdout.
jacd is used for dynamic address claiming. I believe it's a bit early to start with.
$ ip can now be used to: * add SA 0x80 to can0
$ ip addr add j1939 0x80 dev can0
from that point, 0x80 can be used to send packets with.
and likewise
$ ip addr del j1939 0x80 dev can0
$ ip addr may show things like:
4: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN qlen 10
link/can
can-j1939 0x80 scope link Quoted 1 line
or is it possible to use cangw with API?
cangw (like can-j1939) is not present in your 2.6.31 kernel.
Since you managed importing can-j1939, importing cangw will succeed definitely. cangw requires less modification in userspace tools ...
Before proceeding however, what exactly is the application? Will you bridge j1939 packets unmodified?
Are transport sessions involved?
Is information repacked into different packets?
...
Kurt
Re: using can-j1939
Quoted 2 lines
Before proceeding however, what exactly is the application? Will you bridge j1939 packets unmodified?
I want read from one bus modify the data field of the j1939 frame and write the modified packet on the other bus.
--Wolfgang
Re: using can-j1939
Quoted 5 lines · Wolfgang
Quoted 2 lines
Before proceeding however, what exactly is the application? Will you bridge j1939 packets unmodified?
I want read from one bus modify the data field of the j1939 frame and write the modified packet on the other bus.
So only 1 PGN is bridged? No other PGN's.
Kurt
Re: using can-j1939
Quoted 1 line
So only 1 PGN is bridged? No other PGN's.
For the first steps I would be happy with 1 but finally and if it isn't 'impossible' 3.
--Wolfgang
Re: using can-j1939
Quoted 4 lines · Wolfgang
Quoted 1 line
So only 1 PGN is bridged? No other PGN's.
For the first steps I would be happy with 1 but finally and if it isn't 'impossible' 3.
ok. a limited number :-)
Do you relay them (on the second bus) using the same source address, i.e. to all 3 PGN's use the same source address when sent out?
The source addresses of the 3 received PGN's (on the first bus) do not matter.
In fact, a limited number here is fine too.
The thing is, my can-j1939 stack is (BSD sockets alike) assigned a limited number of J1939 source addresses. Only those source addresses are allowed in outgoing packets (a bit like IP networks, and probably others)
You can do unmodified relaying even from the command line by piping 2 instances of jsr, like
$ ip addr add j1939 0x80 dev can1 $ jsr can0:80,feda | jsr can1:80,feda
This should do some basics already.
Kurt
Re: using can-j1939
Quoted 4 lines
Do you relay them (on the second bus) using the same source address, i.e.to all 3 PGN's use the same source address when sent out? The source addresses of the 3 received PGN's (on the first bus) do not matter.
In fact, a limited number here is fine too.
The thing is, my can-j1939 stack is (BSD sockets alike) assigned a
limited number of J1939 source addresses. Only those source addresses are allowed in outgoing packets (a bit like IP networks, and probably others)
No, all 3 PGNs are sent by one sender(source)!
--Wolfgang
Re: using can-j1939
In reply to WolfgangQuoted 2 lines
I want read from one bus modify the data field of the j1939 frame and write the modified packet on the other bus.
Are the packets 'broadcasted' or destination specific?
Kurt
Re: using can-j1939
Quoted 1 line
Are the packets 'broadcasted' or destination specific?
The packets are destination specific. But I was wrong the, it should read and write from both bus' - sorry, but only 2 specific address'!
--Wolfgang
Re: using can-j1939
Quoted 5 lines · Wolfgang
Quoted 1 line
Are the packets 'broadcasted' or destination specific?
The packets are destination specific.
But I was wrong the, it should read and
write from both bus' - sorry, but only 2 specific address'!
Even that is no problem...
Re: using can-j1939
Quoted 4 lines
Quoted 3 lines
The packets are destination specific.
But I was wrong the, it should read and
write from both bus' - sorry, but only 2 specific address'!Even that is no problem...
OK, this sounds great. I am just browsing through the documentation and wondering if it is possible to activate j1939 per default, that it would be possible to use the target as stand alone.
--Wolfgang
Re: using can-j1939
Quoted 7 lines · Wolfgang
Quoted 4 lines
Quoted 3 lines
The packets are destination specific.
But I was wrong the, it should read and
write from both bus' - sorry, but only 2 specific address'!Even that is no problem...
OK, this sounds great. I am just browsing through the documentation and wondering if it is possible to activate j1939 per default,
Of course this is possible, but unwanted.
This choice is comparable to "not setting 250Kb per default". Read more below.
Quoted 2 lines
that it would be possible to use
the target as stand alone.
You should initialize the CAN bus(ses) on powerup:
* set baudrate
* set j1939 on
* set iface up.
Typically this is done in some init scripts.
Kind regards,
Kurt
API calls
Hi Kurt,
I am sorry, but I am not too much in socket programming yet, and I can't find much information about socketCAN. I am using the j1939.txt.
I am trying to create a socket and send something, the addr 0x80 I have defined before. What have I done wrong or how is it made right?
#include <sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <linux/can/j1939.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
int main ()
{
int s;
s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
struct sockaddr_can addr;
memset(&addr, 0, sizeof(addr));
addr.can_ifindex = ifindex("can0");
addr.can_addr.j1939.name = TEST;
addr.can_addr.j1939.addr = 0x80;
addr.can_addr.j1939.pgn = 0x12300;
bind(s, (void *)&addr, sizeof(addr));
sendto(s, data, sizeof(data), 0, (void *)&addr, sizeof(addr));}
Kind regards,
Wolfgang
Re: API calls
Quoted 4 lines · Wolfgang
Hi Kurt,
I am sorry, but I am not too much in socket programming yet, and I can't find much information about socketCAN. I am using the j1939.txt.
man socket
man bind
man sendto
man recv
....
Socket programming (not CAN specific) wasn't very easy for me neither the first time.
Since you seem to have gottten pretty far with a first test program, I've corrected some mistakes/bad practices.
Quoted 7 lines
I am trying to create a socket and send something, the addr
0x80I have defined before. What have I done wrong or how is it made right?#include <
sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <linux/can.h>
Quoted 4 lines
#include <
linux/can/j1939.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
/* for if_nametoindex() */
#include <net/if.h>
Quoted 4 lines
int main ()
Quoted 8 lines
{
int s;
s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
struct sockaddr_can addr;
memset(&addr, 0, sizeof(addr));
addr.can_ifindex = ifindex("can0"); addr.can_ifindex = if_nametoindex("can0");Quoted 1 line
addr.can_addr.j1939.name = TEST;
@name is used for dynamic addressing.
If you're using static addressing, assign J1939_NO_NAME (== 0, so leaving is fine too).
addr.can_addr.j1939.name = J1939_NO_NAME;
Quoted 4 lines
addr.can_addr.j1939.addr = 0x80;
addr.can_addr.j1939.pgn = 0x12300;
bind(s, (void *)&addr, sizeof(addr));better is:
int ret;
if (bind(...) < 0)
perror("bind failed");
if (send(s, data, sizeof(data), 0) < 0)
perror("send failed");If sizeof(data) <= 8, then this
will broadcast a message with _can_id_ 0x1923ff80:
* (/*priority*/6 << 26) | (/*pgn*/0x12300 << 8) | (/*source*/0x80).
* PGN 0x123 is of type PDU1 => destination address in PDU-specific
* no destination given => broadcast (0xff).
Quoted 2 lines
sendto(s, data, sizeof(data), 0, (void *)&addr, sizeof(addr));likewise, this would send the message to ..., yourself again. can_id will be 0x19238080
I hope this clears up a bit.
J1939 isn't very transparent on the composition of it's CAN identifiers. The can-j1939 stack deals with all issues, safeguarding you from protocol violations on the bus, but the stack may return error codes when you try something illegal. You should check them (i.e. doing "if (send(...) < 0) perror(...);")
Kind regards,
Kurt
Re: API calls
Quoted 4 lines
man socket
man bind
man sendto
man recv
I've forgotten those, thanks.
#include <sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <linux/can/j1939.h>
#include <linux/can.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
int main (void)
{
int s;
s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
struct sockaddr_can addr;
memset(&addr, 0, sizeof(addr));
addr.can_ifindex = if_nametoindex("can0");
addr.can_addr.j1939.name = J1939_NO_NAME;
addr.can_addr.j1939.addr = 0x80;
addr.can_addr.j1939.pgn = 0x12300;
if (bind(s, (void *)&addr, sizeof(addr))<0)
{
perror ("bind failed");
}
if (send(s, data, sizeof(data), 0) < 0)
{
perror ("send failed");
}return 0;
}
I changed the program, but I am wondering how to send an entire j1939 frame with the data?
--Wolfgang
Re: API calls
Quoted 3 lines · Wolfgang
I changed the program, but I am wondering how to send an entire j1939 frame with the data?
send(s, data, sizeof(data), 0) does send. But I see 'data' not defined?
I'm afraid I don't really understand the question this time ... Can you explain a bit more?
Kurt
Re: API calls
I was a bit hasty. It is not working, but I don't get it. Eclipse is saying bind failed: Invalid argument
send failed: Destination address required
How is a frame send with id and data, like when you do $cansend can0 -ei0x123ff80 0xFF. Because only data is sent now?
#include <sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <linux/can/j1939.h>
#include <linux/can.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
int main (void)
{
int s;
s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
struct sockaddr_can addr;
memset(&addr, 0, sizeof(addr));
addr.can_ifindex = if_nametoindex("can0");
addr.can_addr.j1939.name = J1939_NO_NAME;
addr.can_addr.j1939.addr = 0x80;
addr.can_addr.j1939.pgn = 0x12300;struct can_frame frame; frame.data[1] = 0xFF;
if (bind(s, (void *)&addr, sizeof(addr))<0)
{
perror ("bind failed");
} if (send(s, frame.data, sizeof(frame.data), 0) < 0)
{
perror ("send failed");
}return 0;
}
Re: API calls
Quoted 2 lines · Wolfgang
I was a bit hasty. It is not working, but I don't get it. Eclipse is saying bind failed: Invalid argument
I went into the code. I forgot to add:
addr.can_family = AF_CAN;
I think this is what is missing.
Quoted 1 line
send failed: Destination address required
Yep, since bind failed, you will not be able to use the socket already (man socket).
I just pushed a commit into linux-can-j1939. You may decide to merge it into your kernel. I found that the test for 'bind succeeded' is wrong in sendmsg. Therefore, you get some error because you really did not bind yet, but after the patch, you will get the error ENOTCONN, which is very appropriate.
Quoted 3 lines
How is a frame send with id and data, like when you do $cansend can0 -ei0x123ff80
0xFF. Because only data is sent now?
The ID is composed from the address information you supplied earlier with bind(), connect() and/or sendto().
This is different with CAN raw, but remind that CAN raw does not imply addressing on the bus neither.
can-j1939 does export an address concept to userspace, and verifies that you're not cheating on the bus. And the modules thus allow to do transport protocol with addressing verified.
So, to summarize, you may later on start using sendto(), and supply an address structure with destination address and/or PGN set.
Kurt
Re: API calls
#include <sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <linux/can/j1939.h>
#include <linux/can.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
int main (void)
{
int s;
s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
struct sockaddr_can addr;
memset(&addr, 0, sizeof(addr));
addr.can_ifindex = if_nametoindex("can0");
addr.can_addr.j1939.name = J1939_NO_NAME;
addr.can_addr.j1939.addr = 0x80;
addr.can_addr.j1939.pgn = 0xFFD0;
addr.can_family = AF_CAN;
struct can_frame frame;
if (bind(s, (void *)&addr, sizeof(addr))<0)
{
perror ("bind failed");
}
if (send(s, frame.data, sizeof(frame.data), 0)<0) {
perror ("send failed");
}
return 0;
}
It is working, the ID is composed 18FFD080, thanks. I also tried recv() - it is working as well.
Is it possible to implement only the bytes you really need from the data array, because the dlc is always 8.
So sendto() is used to send to a specific address, at the moment I am always doing broadcast?
--Wolfgang
using can-j1939
Quoted 3 lines · Wolfgang
It is working, the ID is composed 18FFD080, thanks. I also tried
recv()- it is working as well.
Great!!
Quoted 2 lines
Is it possible to implement only the bytes you really need from the data array, because the dlc is always 8.
I bet len (= sizeof(frame.data) in your example) is 8. If you want to send 3 bytes, then supply 3 bytes to the kernel!
Quoted 2 lines
So
sendto()is used to send to a specific address, at the moment I am always doing broadcast?
yes.
Quoted 8 lines
--Wolfgang
--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: using can-j1939
Quoted 2 lines
I bet len (= sizeof(frame.data) in your example) is 8. If you want to send 3 bytes, then supply 3 bytes to the kernel!
OK, so I set the unused bytes 0 and don't care.
Quoted 3 lines
Quoted 2 lines
So
sendto()is used to send to a specific address, at the moment I am always doing broadcast?yes.
Maybe you can give me a hint what I did wrong
...
addr.can_addr.j1939.name = 0x81;
....
if (sendto(s, frame.data, strlen(frame.data), 0, (void *)&addr, \
sizeof(frame.data))<0)
{
perror ("sendto failed");
}One general question, am I right, you have to create for every different struct sockaddr_can (different pgn etc.) one socket per interface?
Gratefully,
Wolfgang
Re: using can-j1939
Quoted 3 lines · Wolfgang
Quoted 2 lines
I bet len (= sizeof(frame.data) in your example) is 8. If you want to send 3 bytes, then supply 3 bytes to the kernel!
OK, so I set the unused bytes 0 and don't care.
you should not have unused bytes, but I believe you get the picture...
Quoted 11 lines
Quoted 5 lines
Quoted 4 lines
So
sendto()is used to send to a specific address, at the moment I am always doing broadcast?yes.
Maybe you can give me a hint what I did wrong
...
addr.can_addr.j1939.name =0x81;
....
if (sendto(s, frame.data, strlen(frame.data), 0, (void *)&addr, \
sizeof(frame.data))<0)
sendto(s, frame.data, strlen(frame.data), 0, (void *)&addr, sizeof(addr)/*!!!*/) you supplied the sizeof frame.data, where you should supply the size of addr.
Quoted 8 lines
{ perror ("sendto failed"); }One general question, am I right, you have to create for every different struct
sockaddr_can(different pgn etc.) one socket per interface?
You will want to create 1 socket per interface and per used source address.
You bind with can_addr.j1939.addr = 0x80 and can_addr.j1939.pgn = J1939_NO_PGN then you can do sendto with dest_addr.j1939.sa = DEST address & dest_addr.j1939.pgn = YOUR_PGN.
So, the latter YOUR_PGN may vary with each call.
The option to preset a PGN during bind() allows to use write & send on the socket but is an inferior option in this regard.
Kurt
Re: using can-j1939
Quoted 1 line
You will want to create 1 socket per interface and per used source address.
OK, 2 source address, 2 interfaces = 4 sockets?!
Quoted 3 lines
You bind with can_addr.j1939.addr =
0x80and can_addr.j1939.pgn =J1939_NO_PGNthen you can do sendto with dest_addr.j1939.sa = DEST address & dest_addr.j1939.pgn =YOUR_PGN.
#include <sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <linux/can/j1939.h>
#include <linux/can.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/types.h>
int main (void)
{
int s;
s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
struct sockaddr_can addr;
memset(&addr, 0, sizeof(addr));
addr.can_ifindex = if_nametoindex("can0");
addr.can_addr.j1939.name = J1939_NO_NAME;
addr.can_addr.j1939.addr = 0x80;
addr.can_addr.j1939.pgn = J1939_NO_PGN;
addr.can_family = AF_CAN;
if (bind(s, (void *)&addr, sizeof(addr))<0)
{
perror ("bind failed");
} struct sockaddr_can dest_addr;
memset(&dest_addr, 0, sizeof(dest_addr));
dest_addr.can_addr.j1939.name = 0x9ABCDEFULL;
dest_addr.can_addr.j1939.pgn = 0x12300;
if (sendto(s, frame.data, sizeof (frame.data), 0, (void *)&dest_addr, \
sizeof(dest_addr))<0)
{
perror ("sendto failed");
} return 0;
}
I hope I get that right, with the new struct sockaddr_can. But anything is wrong $sendto failed: Invalid argument. Sure I got the solution?!?
Thanks,
--Wolfgang
Re: using can-j1939
Quoted 3 lines · Wolfgang
Quoted 1 line
You will want to create 1 socket per interface and per used source address.
OK, 2 source address, 2 interfaces = 4 sockets?!
I assume you utilize 2 source addresses, one on each interface? In that case, you need only 2 sockets.
Quoted 36 lines
Quoted 4 lines
You bind with can_addr.j1939.addr =
0x80and can_addr.j1939.pgn =J1939_NO_PGNthen you can do sendto with dest_addr.j1939.sa = DEST address & dest_addr.j1939.pgn =YOUR_PGN.#include <
sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <linux/can/j1939.h>
#include <linux/can.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/types.h>int main (void)
{ int s; s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939); struct sockaddr_can addr; memset(&addr, 0, sizeof(addr)); addr.can_ifindex = if_nametoindex("can0"); addr.can_addr.j1939.name = J1939_NO_NAME; addr.can_addr.j1939.addr = 0x80; addr.can_addr.j1939.pgn = J1939_NO_PGN; addr.can_family = AF_CAN; if (bind(s, (void *)&addr, sizeof(addr))<0) { perror ("bind failed"); }
Quoted 3 lines
struct
sockaddr_candest_addr;memset(&dest_addr, 0, sizeof(dest_addr));
please set the can_family type, to avoid EINVAL
dest_addr.can_family = AF_CAN; Since I suppose you do not use dynamic address claiming, do: dest_addr.can_addr.j1939.name = J1939_NO_NAME; for broadcasted messages: dest_addr.can_addr.j1939.addr = J1939_NO_ADDR;
for destination specific messages, set .addr to the destination address.
Quoted 10 lines
dest_addr.can_addr.j1939.name = 0x9ABCDEFULL;
dest_addr.can_addr.j1939.pgn = 0x12300;
if (sendto(s, frame.data, sizeof (frame.data), 0, (void *)&dest_addr, \
sizeof(dest_addr))<0)
{
perror ("sendto failed");
}Quoted 5 lines
return 0;
}I hope I get that right, with the new struct
sockaddr_can. But anything is wrong $sendto failed: Invalid argument. Sure I got the solution?!?
We're getting there ...
Kurt
Quoted 12 lines
Thanks,
--Wolfgang--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: using can-j1939
Hi,
am I right, if I start for every pgn I want to bridge a new process? Or will it work if all pgns to be bridged are in one process? I'm just wondering what will bring a better performance?
--Wolfgang
Re: using can-j1939
Quoted 5 lines · Wolfgang
Hi,
am I right, if I start for every pgn I want to bridge a new process? Or will it work if all pgns to be bridged are in one process? I'm just wondering what will bring a better performance?
A third option is to start 1 process, with different sockets, each socket bridging 1 pgn.
They all work.
I have no idea what will bring the best performance.
I think your second option will bring:
* the most understandable source code...
* less memory consumption
* less scheduler load
* more transparency (FIFO operation is lost when using different processes)
Kurt
Quoted 7 lines
--Wolfgang
--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
recv list
Hi,
OK, I create 1 socket for one source address (what is the maximum of pgns per socket?).
So if I use recvfrom for one specific pgn - while waiting for that specific pgn the other pgns from that src address are stored in the buffer of the socket and will be later "recvfrom"? So no can frame will be lost?
Am I right, with this, only the j1939 frame with id<0x19233000> should be received, but nothing is done, (just waiting for anything), what have I done wrong?
#include <sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <linux/can/j1939.h>
#include <linux/can.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/types.h>
int main (void)
{
int s;
s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
struct sockaddr_can addr;
memset(&addr, 0, sizeof(addr));
addr.can_ifindex = if_nametoindex("can0");
addr.can_addr.j1939.name = J1939_NO_NAME;
addr.can_addr.j1939.addr = 0x00;
addr.can_addr.j1939.pgn = J1939_NO_PGN;
addr.can_family = AF_CAN;
if (bind(s, (void *)&addr, sizeof(addr))<0)
{
perror ("bind failed");
}
struct can_frame frame struct sockaddr_can dest_addr;
memset(&dest_addr, 0, sizeof(dest_addr)); dest_addr.can_family = AF_CAN; dest_addr.can_addr.j1939.name = J1939_NO_NAME; dest_addr.can_addr.j1939.addr = 0x30; dest_addr.can_addr.j1939.pgn = 0x12300;
if (recvfrom(s, frame.data, sizeof(frame.data), 0, (void *)&dest_addr,\
sizeof(dest_addr))<0)
{ perror ("recvfrom failed");
}
return 0;
}
Wolfgang
Re: recv list
Quoted 4 lines · Wolfgang
Hi,
OK, I create 1 socket for one source address (what is the maximum of pgns per socket?).
a bit unlimited, use filters there.
Quoted 1 line
So if I use recvfrom for one specific pgn - while waiting for that specific pgn
Nope,
man recvfrom ....
can-j1939 will store the source address & PGN into the 'src_addr' (called dest_addr in your example).
You cannot pick a specific PGN from the incoming queue.
Quoted 34 lines
the other pgns from that src address are stored in the buffer of the socket and will be later "recvfrom"? So no can frame will be lost?
Am I right, with this, only the j1939 frame with id<0x19233000> should be received, but nothing is done, (just waiting for anything), what have I done wrong?
#include <
sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <linux/can/j1939.h>
#include <linux/can.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/types.h>int main (void)
{ int s; s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939); struct sockaddr_can addr; memset(&addr, 0, sizeof(addr)); addr.can_ifindex = if_nametoindex("can0"); addr.can_addr.j1939.name = J1939_NO_NAME; addr.can_addr.j1939.addr = 0x00; addr.can_addr.j1939.pgn = J1939_NO_PGN; addr.can_family = AF_CAN;
Quoted 7 lines
if (bind(s, (void *)&addr, sizeof(addr))<0)
{
perror ("bind failed");
}
struct can_frame frame you should do now:
int ret;
socklen_t len;
struct sockaddr_can src_addr;
char buf[128];
while (1) {
len = sizeof(src_addr);
ret = recvfrom(s, buf, sizeof(buf), 0, (void *)&src_addr, &len);
if (ret < 0)
perror ("recvfrom failed");
/* now, ret contains the received size */
/* do things with data */
/* set broadcast */
src_addr.can_addr.j1939.addr = J1939_NO_ADDR;
src_addr.can_addr.j1939.name = J1939_NO_NAME;
if (sendto(s2, buf, ret, 0, (void *)&src_addr, len) < 0)
perror("sendto failed");
}Quoted 27 lines
struct sockaddr_can dest_addr; memset(&dest_addr, 0, sizeof(dest_addr)); dest_addr.can_family = AF_CAN; dest_addr.can_addr.j1939.name = J1939_NO_NAME; dest_addr.can_addr.j1939.addr = 0x30; dest_addr.can_addr.j1939.pgn = 0x12300; if (recvfrom(s, frame.data, sizeof(frame.data), 0, (void *)&dest_addr,\ sizeof(dest_addr))<0) {perror ("recvfrom failed");
}return 0;
}Wolfgang
--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: recv list
OK, I hope I understood it right now, 'recvfrom' returns me more information than 'recv', I thought I can filter with it. But I have to do this before with struct 'j1939_filter' and 'setsockopt' to choose which frames from the bus are cared about.
So if I unterstand it right this should bridge from can0 to can1 and if the sender is 0x30 it prints the first data byte?
#include <sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <linux/can/j1939.h>
#include <linux/can.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/types.h>
int main (void)
{
int s;
s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
struct sockaddr_can addr;
memset(&addr, 0, sizeof(addr));
addr.can_ifindex = if_nametoindex("can0");
addr.can_addr.j1939.name = J1939_NO_NAME;
addr.can_addr.j1939.addr = 0x00;
addr.can_addr.j1939.pgn = J1939_NO_PGN;
addr.can_family = AF_CAN;
if (bind(s, (void *)&addr, sizeof(addr))<0)
{
perror ("bind failed");
}
int s2;
s2 = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
struct sockaddr_can addr2;
memset(&addr2, 0, sizeof(addr2));
addr2.can_ifindex = if_nametoindex("can1");
addr2.can_addr.j1939.name = J1939_NO_NAME;
addr2.can_addr.j1939.addr = 0x3D;
addr2.can_addr.j1939.pgn = J1939_NO_PGN;
addr2.can_family = AF_CAN;
if (bind(s2, (void *)&addr2, sizeof(addr2))<0)
{
perror ("bind2 failed");
}
int ret;
socklen_t len;
struct sockaddr_can src_addr;
char buf[128];
src_addr.can_family = AF_CAN;
while (1) {
len = sizeof(src_addr);
ret = recvfrom(s, buf, sizeof(buf), 0, (void *)&src_addr, &len);
if (ret < 0)
perror ("recvfrom failed");
/*if the frame is sent by 0x30 do this*/
if (src_addr.can_addr.j1939.addr == 0x30)
{
printf("%x\n", buf[0]);
if (sendto(s2, buf, ret, 0, (void *)&src_addr, len) < 0)
perror("sendto failed");
}
/*else just bridge it*/
else
{
if (sendto(s2, buf, ret, 0, (void *)&src_addr, len) < 0)
perror("sendto failed");
}
} return 0;
}
Thanks so far!
Re: recv list
Quoted 4 lines · Wolfgang
OK, I hope I understood it right now, 'recvfrom' returns me more information than 'recv', I thought I can filter with it. But I have to do this before with struct '
j1939_filter' and 'setsockopt' to choose which frames from the bus are cared about.
right!
Quoted 3 lines
So if I unterstand it right this should bridge from can0 to can1 and if the sender is
0x30it prints the first data byte?
pretty good. I did point a few minor remarks.
Quoted 49 lines
#include <
sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <linux/can/j1939.h>
#include <linux/can.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/types.h>int main (void)
{ int s; s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939); struct sockaddr_can addr; memset(&addr, 0, sizeof(addr)); addr.can_ifindex = if_nametoindex("can0"); addr.can_addr.j1939.name = J1939_NO_NAME; addr.can_addr.j1939.addr = 0x00; addr.can_addr.j1939.pgn = J1939_NO_PGN; addr.can_family = AF_CAN; if (bind(s, (void *)&addr, sizeof(addr))<0) { perror ("bind failed"); } int s2; s2 = socket(PF_CAN, SOCK_DGRAM, CAN_J1939); struct sockaddr_can addr2; memset(&addr2, 0, sizeof(addr2)); addr2.can_ifindex = if_nametoindex("can1"); addr2.can_addr.j1939.name = J1939_NO_NAME; addr2.can_addr.j1939.addr = 0x3D; addr2.can_addr.j1939.pgn = J1939_NO_PGN; addr2.can_family = AF_CAN; if (bind(s2, (void *)&addr2, sizeof(addr2))<0) {
Quoted 8 lines
perror ("bind2 failed");
}
int ret;
socklen_t len;
struct sockaddr_can src_addr;
char buf[128];
src_addr.can_family = AF_CAN;This assignment is useless...
Quoted 12 lines
while (1) {
len = sizeof(src_addr);
ret = recvfrom(s, buf, sizeof(buf), 0, (void *)&src_addr, &len);
if (ret < 0)
perror ("recvfrom failed");
/*if the frame is sent by 0x30 do this*/
if (src_addr.can_addr.j1939.addr == 0x30)
{you could test if 'ret' > 0, since 'ret' may be 0. Altough sending frames without data is rare in j1939...
Quoted 2 lines
printf("%x\n", buf[0]);In this example, the remainder of the 'if' is equal as the 'else' ...
Quoted 15 lines
if (sendto(s2, buf, ret, 0, (void *)&src_addr, len) < 0)
perror("sendto failed");
}
/*else just bridge it*/
else
{
if (sendto(s2, buf, ret, 0, (void *)&src_addr, len) < 0)
perror("sendto failed");
}
}Quoted 5 lines
return 0;
}Thanks so far!
Note that this bridge puts the originating source address as bridged destination address. This does not matter for PDU2 type of PGN's (== PDU-specific is not the destination address), it may not be completely right.
I'd expect to 'empty' (== put J1939_NO_ADDR) the src_addr.can_addr.j1939.addr member before sendto(), resulting in a broadcasted PGN.
In a later iteration, You could (if necessary, since I have no clue what kind of traffic you will bridge):
* make the receiving socket (s) 'promiscuous', i.e. receiving all traffic.
* fetch the original destination by using recvmsg() as illustrated in jspy.
I think you're bridge will work. great job!
Kurt
Quoted 6 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: recv list
Quoted 1 line
Note that this bridge puts the originating source address as bridged
destination address.
Quoted 5 lines
This does not matter for PDU2 type of PGN's (== PDU-specific is not the destination address), it may not be completely right.
I'd expect to 'empty' (== put
J1939_NO_ADDR) the src_addr.can_addr.j1939.addr member beforesendto(), resulting in a broadcasted PGN.
OK I hope I fixed that, I want to keep the originating source address and it should stay PDU2 type.
Quoted 4 lines
In a later iteration, You could (if necessary, since I have no clue what kind of traffic you will bridge):
* make the receiving socket (s) 'promiscuous', i.e. receiving all traffic.
* fetch the original destination by usingrecvmsg()as illustrated in jspy.
At the moment I am also not aware what particular traffic I will bridge, I am still 'playing' around. But the target is to place that bridge between an existing engine bus and an existing ECU. So different source address' the existing ECU is 'interested' in (but I think not in all in the network) and one source address from the ECU.
In the example below, I wanted, if the pgn is 0xFEF5 (this is a pgn I will definitely need) to print the first byte otherwise just bridge it. But it is not working! Could you see an error? Sorry!
int main (void)
{
int s;
s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
struct sockaddr_can addr;
memset(&addr, 0, sizeof(addr));
addr.can_ifindex = if_nametoindex("can0");
addr.can_addr.j1939.name = J1939_NO_NAME;
addr.can_addr.j1939.addr = 0x00;
addr.can_addr.j1939.pgn = J1939_NO_PGN;
addr.can_family = AF_CAN;
if (bind(s, (void *)&addr, sizeof(addr))<0)
{
perror ("bind failed");
}
int s2;
s2 = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
struct sockaddr_can addr2;
memset(&addr2, 0, sizeof(addr2));
addr2.can_ifindex = if_nametoindex("can1");
addr2.can_addr.j1939.name = J1939_NO_NAME;
addr2.can_addr.j1939.addr = 0x3D;
addr2.can_addr.j1939.pgn = J1939_NO_PGN;
addr2.can_family = AF_CAN;
if (bind(s2, (void *)&addr2, sizeof(addr2))<0)
{
perror ("bind2 failed");
}
int ret;
socklen_t len;
struct sockaddr_can src_addr;
char buf[128];
while (1) {
len = sizeof(src_addr);
ret = recvfrom(s, buf, sizeof(buf), 0, (void *)&src_addr, &len);
if (ret < 0)
perror ("recvfrom failed");
src_addr.can_addr.j1939.addr = J1939_NO_ADDR;
/*if the frame is sent by 0x30 do this*/
if (src_addr.can_addr.j1939.pgn == 0xFEF5)
{
if (ret < 0)
perror ("no data");
printf("%x\n", buf[0]);/*I didn't get it what you wanted to tell me with the remainder*/
if (sendto(s2, buf, ret, 0, (void *)&src_addr, len) < 0)
perror("sendto failed");
}
/*else just bridge it*/
else
{
if (sendto(s2, buf, ret, 0, (void *)&src_addr, len) < 0)
perror("sendto failed");
}
} return 0;
}
--Wolfgang
Re: recv list
Quoted 10 lines · Wolfgang
Quoted 1 line
Note that this bridge puts the originating source address as bridged
destination address.
Quoted 5 lines
This does not matter for PDU2 type of PGN's (== PDU-specific is not the destination address), it may not be completely right.
I'd expect to 'empty' (== put
J1939_NO_ADDR) the src_addr.can_addr.j1939.addr member beforesendto(), resulting in a broadcasted PGN.OK I hope I fixed that, I want to keep the originating source address and it should stay PDU2 type.
The source address of outgoing packets is the one you gave with bind().
Quoted 12 lines
Quoted 5 lines
In a later iteration, You could (if necessary, since I have no clue what kind of traffic you will bridge):
* make the receiving socket (s) 'promiscuous', i.e. receiving all traffic.
* fetch the original destination by usingrecvmsg()as illustrated in jspy.At the moment I am also not aware what particular traffic I will bridge, I am still 'playing' around. But the target is to place that bridge between an existing engine bus and an existing ECU. So different source address' the existing ECU is 'interested' in (but I think not in all in the network) and one source address from the ECU.
Quoted 3 lines
In the example below, I wanted, if the pgn is
0xFEF5(this is a pgn I will definitely need) to print the first byte otherwise just bridge it. But it is not working! Could you see an error? Sorry!
strange.
I see 1 problem still: you will need to bind with 0x00 on can1 & with 0x3d on can0 probably. In fact, there's no need yet to bind with a valid source address on can0 since you're listening only.
That does however not explain the problem.
tried 'jspy' yet?
Quoted 93 lines
int main (void)
{ int s; s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939); struct sockaddr_can addr; memset(&addr, 0, sizeof(addr)); addr.can_ifindex = if_nametoindex("can0"); addr.can_addr.j1939.name = J1939_NO_NAME; addr.can_addr.j1939.addr = 0x00; addr.can_addr.j1939.pgn = J1939_NO_PGN; addr.can_family = AF_CAN; if (bind(s, (void *)&addr, sizeof(addr))<0) { perror ("bind failed"); } int s2; s2 = socket(PF_CAN, SOCK_DGRAM, CAN_J1939); struct sockaddr_can addr2; memset(&addr2, 0, sizeof(addr2)); addr2.can_ifindex = if_nametoindex("can1"); addr2.can_addr.j1939.name = J1939_NO_NAME; addr2.can_addr.j1939.addr = 0x3D; addr2.can_addr.j1939.pgn = J1939_NO_PGN; addr2.can_family = AF_CAN; if (bind(s2, (void *)&addr2, sizeof(addr2))<0) { perror ("bind2 failed"); } int ret; socklen_t len; struct sockaddr_can src_addr; char buf[128]; while (1) { len = sizeof(src_addr); ret = recvfrom(s, buf, sizeof(buf), 0, (void *)&src_addr, &len); if (ret < 0) perror ("recvfrom failed"); src_addr.can_addr.j1939.addr = J1939_NO_ADDR; /*if the frame is sent by 0x30 do this*/ if (src_addr.can_addr.j1939.pgn == 0xFEF5) { if (ret < 0) perror ("no data"); printf("%x\n", buf[0]);/*I didn't get it what you wanted to tell me with the remainder*/
if (sendto(s2, buf, ret, 0, (void *)&src_addr, len) < 0) perror("sendto failed"); } /*else just bridge it*/ else { if (sendto(s2, buf, ret, 0, (void *)&src_addr, len) < 0) perror("sendto failed"); } }return 0;
}--Wolfgang
--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: recv list
Quoted 1 line
tried 'jspy' yet?
It is not possible because at the moment I am working with a simulation tool, to get out how things are working, is this a problem?
Now I have a different question, is it possible to bind different sockets with different src.addr to one interface. Because it is saying 'bind failed: Device or resource busy' if I want to do this ('$ip addr add j1939 0x01 dev can0' is working, of course) Or do I have to do this with recvmsg()? Because as you know I want keep the various src address'.
Kind regards,
Wolfgang
Re: recv list
Quoted 3 lines · Wolfgang
Now I have a different question, is it possible to bind different sockets with different src.addr to one interface.
of course, yes.
Quoted 3 lines
Because it is saying 'bind failed: Device
or resource busy' if I want to do this ('$ip addr add j19390x01dev can0' is working, of course)
It should work. Since '$ ip addr add ...' worked, there must be something in the code. I look in the code for this. Did I understand well that only the first bind() succeeds?
Quoted 1 line
Or do I have to do this with
recvmsg()?
no, wrong idea.
Quoted 1 line
Because as you know I want keep the various src address'.
I understand your goal...
Quoted 10 lines
Kind regards,
Wolfgang--
To unsubscribe from this list: send the line "unsubscribe linux-can" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Changing addr with bind()
Quoted 10 lines · Kurt Van Dijck
Quoted 3 lines · Wolfgang
Now I have a different question, is it possible to bind different sockets with different src.addr to one interface.
of course, yes.
Quoted 3 lines
Because it is saying 'bind failed: Device
or resource busy' if I want to do this ('$ip addr add j19390x01dev can0' is working, of course)It should work. Since '$ ip addr add ...' worked, there must be something in the code. I look in the code for this. Did I understand well that only the first
bind()succeeds?
Stop searching. It's explicitely disabled in can-j1939 kernel code, and I remember it was not easy to fix in the first versions, but things have changed since. I'll try to make a fix...
Kurt
Re: Changing addr with bind()
Quoted 9 lines · Kurt Van Dijck
Quoted 8 lines · Kurt Van Dijck
Quoted 3 lines · Wolfgang
Now I have a different question, is it possible to bind different sockets with different src.addr to one interface.
of course, yes.
Quoted 3 lines
Because it is saying 'bind failed: Device
or resource busy' if I want to do this ('$ip addr add j19390x01dev can0' is working, of course)
Quoted 6 lines
Quoted 2 lines
It should work. Since '$ ip addr add ...' worked, there must be something in the code. I look in the code for this. Did I understand well that only the first
bind()succeeds?Stop searching. It's explicitely disabled in can-j1939 kernel code, and I remember it was not easy to fix in the first versions, but things have changed since. I'll try to make a fix...
I pushed 2 commits to can-j1939-modules repository. You may want to upgrade your sources. Please note I had no time to test these.
Kurt
Re: recv list
In reply to Kurt Van DijckHi,
now it is saying 'sendto failed: Machine is not on the network', when I am sending a message with id 0x15FFD000
#include <sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <linux/can/j1939.h>
#include <linux/can.h>
#include <unistd.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/types.h>
int main (void)
{
int s;
s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
struct sockaddr_can addr;
memset(&addr, 0, sizeof(addr));
addr.can_ifindex = if_nametoindex("can0");
addr.can_addr.j1939.name = J1939_NO_NAME;
addr.can_addr.j1939.addr = 0x00;
addr.can_addr.j1939.pgn = J1939_NO_PGN;
addr.can_family = AF_CAN;
if (bind(s, (void *)&addr, sizeof(addr))<0)
perror ("bind failed");
else
printf("bind of s1 on can0 successful\n");
int s2;
s2 = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
struct sockaddr_can addr2;
memset(&addr2, 0, sizeof(addr2));
addr2.can_ifindex = if_nametoindex("can1");
addr2.can_addr.j1939.name = J1939_NO_NAME;
addr2.can_addr.j1939.addr = 0x3d;
addr2.can_addr.j1939.pgn = J1939_NO_PGN;
addr2.can_family = AF_CAN;
if (bind(s2, (void *)&addr2, sizeof(addr2))<0)
perror ("bind2 failed");
else
printf("bind of s2 on can1 successful\n");
int ret;
socklen_t len;
struct sockaddr_can src_addr;
char buf[128];
while (1) {
len = sizeof(src_addr);
ret = recvfrom(s, buf, sizeof(buf), 0, (void *)&src_addr, &len);
if (ret < 0)
perror ("recvfrom failed");
src_addr.can_addr.j1939.addr = J1939_NO_ADDR;
if (sendto(s2, buf, ret, 0, (void *)&src_addr, len) < 0)
perror("sendto failed");
} return 0;
}