False-Positives while binding to CAN-interfaces on Colibri-iMX6

Hi All.

I am observing an issue on the default image for Colibri-iMX6.

Whenever I try binding to any interface-name via SocketCAN (on Colibri-iMX6), it is always successful.
Even binding to a vague interface-name like “can0-ajay is successful” :frowning:

Same SocketCAN application-code when compiled and run on Ubuntu-16.04 on x86_64, works fine (binding is successful only for proper CAN-interfaces as listed via ifconfig).

Why these false-positives on Colibri-iMX6?

One important point I noticed.
When I do a dmesg |grep can on Ubuntu-16.04 on x86_64, following is
seen ::

[ 6659.988375] can: controller area network core (rev 20170425 abi 9)
[ 6660.009573] can: raw protocol (rev 20170425)
[ 6660.034786] vcan: Virtual CAN interface driver

Upon doing the same on Colibri board, following is seen ::

root@colibri-imx6:~# dmesg | grep can
[    0.140425] i2c i2c-1: can't use DMA
[    0.141107] i2c i2c-2: can't use DMA
[    1.246205] vcan: Virtual CAN interface driver
[    2.057051] snvs-secvio 20cc000.caam-snvs: can't get snvs clock
[    2.215509] can: controller area network core (rev 20120528 abi 9)
[    2.229952] can: raw protocol (rev 20120528)
[    2.236099] can: broadcast manager protocol (rev 20120528 t)
[    2.243668] can: netlink gateway (rev 20130117) max_hops=1

As is seen, CAN-drivers on Colibri are wayyy too older (difference of 5 years).
Could this be the cause?

Looking forward to experts’ opinions :slight_smile:

Thanks and Regards,
Ajay

hi ajay,
what is exactly the problem? can you provide your hardware and software details?

Hi jaski.

Thanks for the reply.

The carrier-board is a Colabri-Evaluation-V3.1a.

Our application requires writing/reading CAN-packets via SocketCAN.

But bind is successful even for vague interface-names like can0-ajay.
Such false-positives break confidence :expressionless:

Thanks and Regards,
Ajay

Hi

You missed to provide information on your software versions.

Whatever, with the following kernel:

root@colibri-imx6:~# uname -a
Linux colibri-imx6 4.1.44-00002-g57cad58f1ccd-dirty #3 SMP Fri Feb 9 17:54:24 CET 2018 armv7l armv7l armv7l GNU/Linux

I don’t see the behavior you describe.
After boot there is no virtual can device configured (e.g. no vcan0), this example code errors out during bind:

root@colibri-imx6:~# ./can
vcan0 at index 1995826768
Error in socket bind: No such device
root@colibri-imx6:~#

If I then configure a virtual can device, start candump on that interface the same code succeeds and candump receives the data and prints it:

root@colibri-imx6:~# ip link add dev vcan0 type vcan
root@colibri-imx6:~# ip link set up vcan0
root@colibri-imx6:~# ip link show vcan0
3: vcan0: <NOARP,UP,LOWER_UP> mtu 16 qdisc noqueue state UNKNOWN mode DEFAULT group default
    link/can
root@colibri-imx6:~#
root@colibri-imx6:~# candump vcan0 &
[1] 587
root@colibri-imx6:~# interface = vcan0, family = 29, type = 3, proto = 1

root@colibri-imx6:~# ./can
vcan0 at index 3
<0x123> [2] 11 22
Wrote 16 bytes

So what is different in your case?
What is the code you use to handle CAN?

Note that the dates wayyy older are constants in code which are changed whenever the relevant API changed and not when the code has been changed the last time. So rare changes here mean a stable API.

Max

Hi Max.
Thanks for taking out the time for such a detailed reply; really grateful !!

Actually, I am worried about the false-positives about binding to any interface-name (the sending/receiving of CAN-packets work fine as such).

The false-positives come on the default-image, whose details are :

root@colibri-imx6:~# uname -a                                                  
Linux colibri-imx6 4.1.44-2.7.4+gb1555bf #1 SMP Thu Oct 5 04:34:40 UTC 2017 armv7l GNU/Linux

The same false-positives appear even after installing the latest kernel (of branch toradex_4.1-2.0.x-imx with commit 18717e2b1ca9b0fbf8bafa2717719e1f2c8f1114) :

root@colibri-imx6:~# uname -a
Linux colibri-imx6 4.1.44-dirty #2 SMP Mon Feb 12 10:18:59 IST 2018 armv7l GNU/Linux

Other than the false-positive above, sending/receiving of CAN-packets work fine.

Thanks a ton again for your time !!

Thanks and Regards,
Ajay

Hi Ajay

As outlined in my post, I do not see that. If the code binds to a non existing interface the call returns an error. So my questions again:

What is different in your case?
What is the code you use to handle CAN?

Max

Hi Max.

I use the same code as per the link https://en.wikipedia.org/wiki/SocketCAN

I noticed that the bind is unsuccessful for a non-existent interface first time.
Second time onwards, it is successful.

Does the false-positives appear at your side from second time onwards?
If not, I will probably end my search-for-perfectness :slight_smile: (since the business-logic is working fine, so I can kinda live with the false-positive).

Thanks and Regards,
Ajay

Hi Ajay

No, they do not.

If I start that program a second (and third) time, bind errors out on all invocations.

root@colibri-imx6:~# ./can
vcan0 at index 1995515472
Error in socket bind: No such device
root@colibri-imx6:~# ./can
vcan0 at index 1995986512
Error in socket bind: No such device
root@colibri-imx6:~# ./can
vcan0 at index 1995888208
Error in socket bind: No such device

If I add a second call to bind in the program, that second call does fail too.

if (bind (s, (struct sockaddr *) &addr, sizeof (addr)) < 0)
{
  perror ("Error in socket bind");
  if (bind (s, (struct sockaddr *) &addr, sizeof (addr)) < 0)
  {
    perror ("Error in socket bind, 2nd time");
    return -2;
  }
}

.

root@colibri-imx6:~# ./can2
vcan0 at index 1996314192
Error in socket bind: No such device
Error in socket bind, 2nd time: No such device

Max