All of lore.kernel.org
 help / color / mirror / Atom feed
* Using CAN_FD_FRAME with BCM socket
@ 2017-04-26  9:19 Romain Forlot [IoT.bzh]
  2017-04-26 18:44 ` Oliver Hartkopp
  0 siblings, 1 reply; 9+ messages in thread
From: Romain Forlot [IoT.bzh] @ 2017-04-26  9:19 UTC (permalink / raw)
  To: linux-can

Hi all,

I must miss something because I don't get it BCM socket uses 
canfd_frame. If I use classic can_frame, it works without problems and I 
don't get it.

Is there someone use canfd_frame with broadcast manager ? Every example 
or source code I browse just use can_frame, only documentation talks 
about that.

Here is the code :

  38         struct {
  39           struct bcm_msg_head msg_head;
  40           struct canfd_frame frame[4]; /* just an example */
  41         } msg;
  42
  43         memset(msg.frame, 0, sizeof(msg.frame));
  44
  45         msg.msg_head.opcode  = RX_SETUP;
  46         msg.msg_head.can_id  = 0x620;
  47         msg.msg_head.flags   = SETTIMER|STARTTIMER|CAN_FD_FRAME;
  48         msg.msg_head.nframes = 1;
  49         msg.msg_head.count = 0;
  50         msg.msg_head.ival1.tv_sec = 0;
  51         msg.msg_head.ival1.tv_usec = 500000;
  52 //      msg.msg_head.ival2.tv_sec = 0;
  53 //      msg.msg_head.ival2.tv_usec = 100000;
  54         msg.frame[0].data[0]   = 0x00;
  55         msg.frame[0].data[1]   = 0x00;
  56         msg.frame[0].data[2]   = 0x00;
  57         msg.frame[0].data[3]   = 0x00;
  58         msg.frame[0].data[4]   = 0x00;
  59         msg.frame[0].data[5]   = 0x3C;
  60         msg.frame[0].data[6]   = 0x00;
  61         msg.frame[0].data[7]   = 0x00;
  62
  63         if(write(s, &msg, sizeof(msg)) < 0)
  64                 printf("This is the end!\n%s\n", strerror(errno));

Then I use select on socket to read frames. In fact, if I remove 
CAN_FD_FRAME it work even if my concatenated struct after bcm_msg_head 
is canfd_frame structure but it will only read size of can_frame which 
is normal.

Thanks by advance.

BR

-- 
Romain Forlot - Embedded Engineer - IoT.bzh
claneys@iot.bzh - www.iot.bzh - +33257620298


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using CAN_FD_FRAME with BCM socket
  2017-04-26  9:19 Using CAN_FD_FRAME with BCM socket Romain Forlot [IoT.bzh]
@ 2017-04-26 18:44 ` Oliver Hartkopp
  2017-04-27  8:23   ` Romain Forlot [IoT.bzh]
  2017-05-04 18:04   ` Romain Forlot [IoT.bzh]
  0 siblings, 2 replies; 9+ messages in thread
From: Oliver Hartkopp @ 2017-04-26 18:44 UTC (permalink / raw)
  To: Romain Forlot [IoT.bzh], linux-can

Hi Romain,

On 04/26/2017 11:19 AM, Romain Forlot [IoT.bzh] wrote:
> I must miss something because I don't get it BCM socket uses
> canfd_frame. If I use classic can_frame, it works without problems and I
> don't get it.

Can you send your Linux Kernel version?

I just want to make sure that it contains this fix:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=5499a6b22e5508b921c447757685b0a5e40a07ed

> Is there someone use canfd_frame with broadcast manager ? Every example
> or source code I browse just use can_frame, only documentation talks
> about that.

Yes, here:

https://github.com/linux-can/can-tests

Namely:

https://github.com/linux-can/can-tests/blob/master/tst-bcmfd-cycle.c
https://github.com/linux-can/can-tests/blob/master/tst-bcmfd-filter.c
https://github.com/linux-can/can-tests/blob/master/tst-bcm-tx_delete.c

>
> Here is the code :
>
>  38         struct {
>  39           struct bcm_msg_head msg_head;
>  40           struct canfd_frame frame[4]; /* just an example */
>  41         } msg;
>  42
>  43         memset(msg.frame, 0, sizeof(msg.frame));
>  44
>  45         msg.msg_head.opcode  = RX_SETUP;
>  46         msg.msg_head.can_id  = 0x620;
>  47         msg.msg_head.flags   = SETTIMER|STARTTIMER|CAN_FD_FRAME;
>  48         msg.msg_head.nframes = 1;
>  49         msg.msg_head.count = 0;
>  50         msg.msg_head.ival1.tv_sec = 0;
>  51         msg.msg_head.ival1.tv_usec = 500000;
>  52 //      msg.msg_head.ival2.tv_sec = 0;
>  53 //      msg.msg_head.ival2.tv_usec = 100000;

This is dangerous!

You set SETTIMER|STARTTIMER but leave these values potentially 
uninitialized.

>  54         msg.frame[0].data[0]   = 0x00;
>  55         msg.frame[0].data[1]   = 0x00;
>  56         msg.frame[0].data[2]   = 0x00;
>  57         msg.frame[0].data[3]   = 0x00;
>  58         msg.frame[0].data[4]   = 0x00;
>  59         msg.frame[0].data[5]   = 0x3C;
>  60         msg.frame[0].data[6]   = 0x00;
>  61         msg.frame[0].data[7]   = 0x00;
>  62
>  63         if(write(s, &msg, sizeof(msg)) < 0)
>  64                 printf("This is the end!\n%s\n", strerror(errno));
>
> Then I use select on socket to read frames. In fact, if I remove
> CAN_FD_FRAME it work even if my concatenated struct after bcm_msg_head
> is canfd_frame structure but it will only read size of can_frame which
> is normal.

You always get the concatenated struct depending on CAN_FD_FRAME:
http://lxr.free-electrons.com/source/Documentation/networking/can.txt?v=4.9#L856

What length do you get back from the read() syscall?

Regards,
Oliver

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using CAN_FD_FRAME with BCM socket
  2017-04-26 18:44 ` Oliver Hartkopp
@ 2017-04-27  8:23   ` Romain Forlot [IoT.bzh]
  2017-05-04 18:04   ` Romain Forlot [IoT.bzh]
  1 sibling, 0 replies; 9+ messages in thread
From: Romain Forlot [IoT.bzh] @ 2017-04-27  8:23 UTC (permalink / raw)
  To: Oliver Hartkopp, linux-can

Hi Oliver,

On 04/26/2017 08:44 PM, Oliver Hartkopp wrote:
> Hi Romain,
>
> On 04/26/2017 11:19 AM, Romain Forlot [IoT.bzh] wrote:
>> I must miss something because I don't get it BCM socket uses
>> canfd_frame. If I use classic can_frame, it works without problems and I
>> don't get it.
>
> Can you send your Linux Kernel version?
Yes, I'm running  4.10.11-200.fc25.x86_64. This patch has been applied 
to the kernel ?
>
> I just want to make sure that it contains this fix:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=5499a6b22e5508b921c447757685b0a5e40a07ed 
>
>
>> Is there someone use canfd_frame with broadcast manager ? Every example
>> or source code I browse just use can_frame, only documentation talks
>> about that.
>
> Yes, here:
>
> https://github.com/linux-can/can-tests
>
> Namely:
>
> https://github.com/linux-can/can-tests/blob/master/tst-bcmfd-cycle.c
> https://github.com/linux-can/can-tests/blob/master/tst-bcmfd-filter.c
> https://github.com/linux-can/can-tests/blob/master/tst-bcm-tx_delete.c
>
Damned, I pass over them... Thanks you !
>>
>> Here is the code :
>>
>>  38         struct {
>>  39           struct bcm_msg_head msg_head;
>>  40           struct canfd_frame frame[4]; /* just an example */
>>  41         } msg;
>>  42
>>  43         memset(msg.frame, 0, sizeof(msg.frame));
>>  44
>>  45         msg.msg_head.opcode  = RX_SETUP;
>>  46         msg.msg_head.can_id  = 0x620;
>>  47         msg.msg_head.flags   = SETTIMER|STARTTIMER|CAN_FD_FRAME;
>>  48         msg.msg_head.nframes = 1;
>>  49         msg.msg_head.count = 0;
>>  50         msg.msg_head.ival1.tv_sec = 0;
>>  51         msg.msg_head.ival1.tv_usec = 500000;
>>  52 //      msg.msg_head.ival2.tv_sec = 0;
>>  53 //      msg.msg_head.ival2.tv_usec = 100000;
>
> This is dangerous!
>
> You set SETTIMER|STARTTIMER but leave these values potentially 
> uninitialized.
This was just a sandbox piece of code, I do a memset before to 
initialize my struct :)
>
>>  54         msg.frame[0].data[0]   = 0x00;
>>  55         msg.frame[0].data[1]   = 0x00;
>>  56         msg.frame[0].data[2]   = 0x00;
>>  57         msg.frame[0].data[3]   = 0x00;
>>  58         msg.frame[0].data[4]   = 0x00;
>>  59         msg.frame[0].data[5]   = 0x3C;
>>  60         msg.frame[0].data[6]   = 0x00;
>>  61         msg.frame[0].data[7]   = 0x00;
>>  62
>>  63         if(write(s, &msg, sizeof(msg)) < 0)
>>  64                 printf("This is the end!\n%s\n", strerror(errno));
>>
>> Then I use select on socket to read frames. In fact, if I remove
>> CAN_FD_FRAME it work even if my concatenated struct after bcm_msg_head
>> is canfd_frame structure but it will only read size of can_frame which
>> is normal.
>
> You always get the concatenated struct depending on CAN_FD_FRAME:
> http://lxr.free-electrons.com/source/Documentation/networking/can.txt?v=4.9#L856 
>
>
> What length do you get back from the read() syscall?
It's the heck, I don't get anything :) I'm stuck at select but I'll just 
take a look at the code you send me before and see what I'm doing wrong.
>
> Regards,
> Oliver

-- 
Romain Forlot - Embedded Engineer - IoT.bzh
claneys@iot.bzh - www.iot.bzh - +33257620298


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using CAN_FD_FRAME with BCM socket
  2017-04-26 18:44 ` Oliver Hartkopp
  2017-04-27  8:23   ` Romain Forlot [IoT.bzh]
@ 2017-05-04 18:04   ` Romain Forlot [IoT.bzh]
  2017-05-04 18:21     ` Oliver Hartkopp
  1 sibling, 1 reply; 9+ messages in thread
From: Romain Forlot [IoT.bzh] @ 2017-05-04 18:04 UTC (permalink / raw)
  To: Oliver Hartkopp, linux-can

Hi here,

Testing with can-tests, tst-bcmfd-filter, I got the following output :

<*>Writing RX_SETUP with RX_FILTER_ID for can_id <042>
<*>Writing RX_DELETE for can_id <042>
<*>Writing RX_SETUP with RX_FILTER_ID for can_id <042>
<2>Writing TX_SEND with wrong can_id <043>
write: Message too long
<3>Writing TX_SEND with correct can_id <042>
write: Message too long

tst-bcm-filter with classic CAN frame, it is running fine.

I check that patch your pointed out is applied at my kernel, do you have 
an idea what could be the problem ? Thanks you.

I continue investigation and let you know if i found anything else.

Best regards.

On 04/26/2017 08:44 PM, Oliver Hartkopp wrote:
> Hi Romain,
>
> On 04/26/2017 11:19 AM, Romain Forlot [IoT.bzh] wrote:
>> I must miss something because I don't get it BCM socket uses
>> canfd_frame. If I use classic can_frame, it works without problems and I
>> don't get it.
>
> Can you send your Linux Kernel version?
>
> I just want to make sure that it contains this fix:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=5499a6b22e5508b921c447757685b0a5e40a07ed 
>
>
>> Is there someone use canfd_frame with broadcast manager ? Every example
>> or source code I browse just use can_frame, only documentation talks
>> about that.
>
> Yes, here:
>
> https://github.com/linux-can/can-tests
>
> Namely:
>
> https://github.com/linux-can/can-tests/blob/master/tst-bcmfd-cycle.c
> https://github.com/linux-can/can-tests/blob/master/tst-bcmfd-filter.c
> https://github.com/linux-can/can-tests/blob/master/tst-bcm-tx_delete.c
>
>>
>> Here is the code :
>>
>>  38         struct {
>>  39           struct bcm_msg_head msg_head;
>>  40           struct canfd_frame frame[4]; /* just an example */
>>  41         } msg;
>>  42
>>  43         memset(msg.frame, 0, sizeof(msg.frame));
>>  44
>>  45         msg.msg_head.opcode  = RX_SETUP;
>>  46         msg.msg_head.can_id  = 0x620;
>>  47         msg.msg_head.flags   = SETTIMER|STARTTIMER|CAN_FD_FRAME;
>>  48         msg.msg_head.nframes = 1;
>>  49         msg.msg_head.count = 0;
>>  50         msg.msg_head.ival1.tv_sec = 0;
>>  51         msg.msg_head.ival1.tv_usec = 500000;
>>  52 //      msg.msg_head.ival2.tv_sec = 0;
>>  53 //      msg.msg_head.ival2.tv_usec = 100000;
>
> This is dangerous!
>
> You set SETTIMER|STARTTIMER but leave these values potentially 
> uninitialized.
>
>>  54         msg.frame[0].data[0]   = 0x00;
>>  55         msg.frame[0].data[1]   = 0x00;
>>  56         msg.frame[0].data[2]   = 0x00;
>>  57         msg.frame[0].data[3]   = 0x00;
>>  58         msg.frame[0].data[4]   = 0x00;
>>  59         msg.frame[0].data[5]   = 0x3C;
>>  60         msg.frame[0].data[6]   = 0x00;
>>  61         msg.frame[0].data[7]   = 0x00;
>>  62
>>  63         if(write(s, &msg, sizeof(msg)) < 0)
>>  64                 printf("This is the end!\n%s\n", strerror(errno));
>>
>> Then I use select on socket to read frames. In fact, if I remove
>> CAN_FD_FRAME it work even if my concatenated struct after bcm_msg_head
>> is canfd_frame structure but it will only read size of can_frame which
>> is normal.
>
> You always get the concatenated struct depending on CAN_FD_FRAME:
> http://lxr.free-electrons.com/source/Documentation/networking/can.txt?v=4.9#L856 
>
>
> What length do you get back from the read() syscall?
>
> Regards,
> Oliver

-- 
Romain Forlot - Embedded Engineer - IoT.bzh
claneys@iot.bzh - www.iot.bzh - +33257620298


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using CAN_FD_FRAME with BCM socket
  2017-05-04 18:04   ` Romain Forlot [IoT.bzh]
@ 2017-05-04 18:21     ` Oliver Hartkopp
  2017-05-04 19:27       ` Romain Forlot [IoT.bzh]
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Hartkopp @ 2017-05-04 18:21 UTC (permalink / raw)
  To: Romain Forlot [IoT.bzh], linux-can

Hi Romain,

On 05/04/2017 08:04 PM, Romain Forlot [IoT.bzh] wrote:
> Message too long

you are using CAN FD frames on a non CAN FD capable CAN interface.

Right?

Regards,
Oliver

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using CAN_FD_FRAME with BCM socket
  2017-05-04 18:21     ` Oliver Hartkopp
@ 2017-05-04 19:27       ` Romain Forlot [IoT.bzh]
  2017-05-05  8:31         ` Oliver Hartkopp
  0 siblings, 1 reply; 9+ messages in thread
From: Romain Forlot [IoT.bzh] @ 2017-05-04 19:27 UTC (permalink / raw)
  To: Oliver Hartkopp, linux-can

It is a virtual can interface. I will check how to enable it.


On 05/04/2017 08:21 PM, Oliver Hartkopp wrote:
> Hi Romain,
>
> On 05/04/2017 08:04 PM, Romain Forlot [IoT.bzh] wrote:
>> Message too long
>
> you are using CAN FD frames on a non CAN FD capable CAN interface.
>
> Right?
>
> Regards,
> Oliver

-- 
Romain Forlot - Embedded Engineer - IoT.bzh
claneys@iot.bzh - www.iot.bzh - +33257620298


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using CAN_FD_FRAME with BCM socket
  2017-05-04 19:27       ` Romain Forlot [IoT.bzh]
@ 2017-05-05  8:31         ` Oliver Hartkopp
  2017-05-05 10:19           ` Romain Forlot [IoT.bzh]
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Hartkopp @ 2017-05-05  8:31 UTC (permalink / raw)
  To: Romain Forlot [IoT.bzh], linux-can

Hi Romain,

On 05/04/2017 09:27 PM, Romain Forlot [IoT.bzh] wrote:
> It is a virtual can interface. I will check how to enable it.

https://github.com/linux-can/can-misc/blob/master/etc/can_if#L37

http://lxr.linux.no/#linux+v4.10.1/Documentation/networking/can.txt#L1197

http://lxr.linux.no/#linux+v4.10.1/Documentation/networking/can.txt#L605

Regards,
Oliver

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using CAN_FD_FRAME with BCM socket
  2017-05-05  8:31         ` Oliver Hartkopp
@ 2017-05-05 10:19           ` Romain Forlot [IoT.bzh]
  2017-05-05 17:26             ` Oliver Hartkopp
  0 siblings, 1 reply; 9+ messages in thread
From: Romain Forlot [IoT.bzh] @ 2017-05-05 10:19 UTC (permalink / raw)
  To: Oliver Hartkopp, linux-can

Hi Oliver,

Thanks for the links, I found out the same and make my test against the 
wrong device... My bad, once MTU correctly set, it works.

I hoping that even if BCM socket filter use of FD frames, it could 
handle classic CAN frame too, like the RAW socket do. It doesn't, so I 
guess that description about signals must specify if it's using FD 
frames or not. Be able to also handle classic CAN frames avoid that.

There is a limitation to not handle both ?

Best regards.

On 05/05/2017 10:31 AM, Oliver Hartkopp wrote:
> Hi Romain,
>
> On 05/04/2017 09:27 PM, Romain Forlot [IoT.bzh] wrote:
>> It is a virtual can interface. I will check how to enable it.
>
> https://github.com/linux-can/can-misc/blob/master/etc/can_if#L37
>
> http://lxr.linux.no/#linux+v4.10.1/Documentation/networking/can.txt#L1197
>
> http://lxr.linux.no/#linux+v4.10.1/Documentation/networking/can.txt#L605
>
> Regards,
> Oliver

-- 
Romain Forlot - Embedded Engineer - IoT.bzh
claneys@iot.bzh - www.iot.bzh - +33257620298


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Using CAN_FD_FRAME with BCM socket
  2017-05-05 10:19           ` Romain Forlot [IoT.bzh]
@ 2017-05-05 17:26             ` Oliver Hartkopp
  0 siblings, 0 replies; 9+ messages in thread
From: Oliver Hartkopp @ 2017-05-05 17:26 UTC (permalink / raw)
  To: Romain Forlot [IoT.bzh], linux-can

Hi Romain,

On 05/05/2017 12:19 PM, Romain Forlot [IoT.bzh] wrote:

> Thanks for the links, I found out the same and make my test against the
> wrong device... My bad, once MTU correctly set, it works.
>
> I hoping that even if BCM socket filter use of FD frames, it could
> handle classic CAN frame too, like the RAW socket do.

You obviously think CAN FD is 'just longer' than CAN which is wrong.

A CAN frame with CAN ID 0x123 is something completely different than a 
CAN FD frame with CAN ID 0x123. It has a different representation on the 
wire and it can have a different signal descriptions.

Even a CAN FD frame with 8 bytes is something different than a CAN frame 
with 8 bytes.

> It doesn't, so I
> guess that description about signals must specify if it's using FD
> frames or not.

Yes you have to treat it different.

> Be able to also handle classic CAN frames avoid that.
>
> There is a limitation to not handle both ?

A single CAN BCM socket *can* handle both at the same time.

You have to specify two RX_SETUP jobs then:
One for CAN and one for CAN FD

The fact whether a BCM job is CAN_FD_FRAME type is a relevant distinction:

/*
  * helpers for bcm_op handling: find & delete bcm [rx|tx] op elements
  */
static struct bcm_op *bcm_find_op(struct list_head *ops,
                                   struct bcm_msg_head *mh, int ifindex)
{
         struct bcm_op *op;

         list_for_each_entry(op, ops, list) {
                 if ((op->can_id == mh->can_id) && (op->ifindex == 
ifindex) &&
                     (op->flags & CAN_FD_FRAME) == (mh->flags & 
CAN_FD_FRAME))
                         return op;
         }

         return NULL;
}


http://lxr.linux.no/#linux+v4.10.1/net/can/bcm.c#L717

Regards,
Oliver

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-05-05 17:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-26  9:19 Using CAN_FD_FRAME with BCM socket Romain Forlot [IoT.bzh]
2017-04-26 18:44 ` Oliver Hartkopp
2017-04-27  8:23   ` Romain Forlot [IoT.bzh]
2017-05-04 18:04   ` Romain Forlot [IoT.bzh]
2017-05-04 18:21     ` Oliver Hartkopp
2017-05-04 19:27       ` Romain Forlot [IoT.bzh]
2017-05-05  8:31         ` Oliver Hartkopp
2017-05-05 10:19           ` Romain Forlot [IoT.bzh]
2017-05-05 17:26             ` Oliver Hartkopp

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.