All of lore.kernel.org
 help / color / mirror / Atom feed
* BCM loopback - Information request
@ 2016-09-20  9:42 Angeloni Andrea
  2016-09-20  9:53 ` Alexander Stein
  0 siblings, 1 reply; 9+ messages in thread
From: Angeloni Andrea @ 2016-09-20  9:42 UTC (permalink / raw)
  To: linux-can@vger.kernel.org

Good morning,

my name is Andrea Angeloni, I'm working for an Italian company manufacturing test benches for several industries.
At the moment I'm developing a C application on ARM Linux to communicate with DUT over CAN. I'm using SocketCAN APIs.

In my application there is a thread for each initialized CAN interface that sends over TCP all the read data to a Windows Client. Data are read using Socket RAW.
Application is also capable to send cyclic messages using Broadcast manager.

Here is my question: how can I configure my application so that reading thread does not get messages sent by BCM on the same interface?

Filtering by ID is not a viable solution because a priori I'm not able to know whether or not someone on the network will send data over the same IDs of BCM.

Thanks for a feedback, regards.
Andrea Angeloni


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

* Re: BCM loopback - Information request
  2016-09-20  9:42 BCM loopback - Information request Angeloni Andrea
@ 2016-09-20  9:53 ` Alexander Stein
  2016-09-20 10:19   ` Angeloni Andrea
  0 siblings, 1 reply; 9+ messages in thread
From: Alexander Stein @ 2016-09-20  9:53 UTC (permalink / raw)
  To: Angeloni Andrea; +Cc: linux-can@vger.kernel.org

Hi Andrea,

On Tuesday 20 September 2016 09:42:53, Angeloni Andrea wrote:
> In my application there is a thread for each initialized CAN interface that
> sends over TCP all the read data to a Windows Client. Data are read using
> Socket RAW. Application is also capable to send cyclic messages using
> Broadcast manager.
> 
> Here is my question: how can I configure my application so that reading
> thread does not get messages sent by BCM on the same interface?

I think the socket option CAN_RAW_LOOPBACK is what you need. Please refer to 
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/can.txt#n536
You will not receive CAN frames sent from interface (BCM and other CAN 
frames), thus only messages from other CAN nodes.

HTH
Alexander


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

* RE: BCM loopback - Information request
  2016-09-20  9:53 ` Alexander Stein
@ 2016-09-20 10:19   ` Angeloni Andrea
  2016-09-20 15:06     ` Oliver Hartkopp
  0 siblings, 1 reply; 9+ messages in thread
From: Angeloni Andrea @ 2016-09-20 10:19 UTC (permalink / raw)
  To: Alexander Stein; +Cc: linux-can@vger.kernel.org

Ciao Alexander,

thanks for your answer.

Unfortunately, CAN_RAW_LOOPBACK is not working. Option is indeed referring to socket and not device, while BCM messages are coming from a different socket.

Andrea

-----Original Message-----
From: Alexander Stein [mailto:alexander.stein@systec-electronic.com] 
Sent: martedì 20 settembre 2016 11:54
To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>
Cc: linux-can@vger.kernel.org
Subject: Re: BCM loopback - Information request

Hi Andrea,

On Tuesday 20 September 2016 09:42:53, Angeloni Andrea wrote:
> In my application there is a thread for each initialized CAN interface 
> that sends over TCP all the read data to a Windows Client. Data are 
> read using Socket RAW. Application is also capable to send cyclic 
> messages using Broadcast manager.
> 
> Here is my question: how can I configure my application so that 
> reading thread does not get messages sent by BCM on the same interface?

I think the socket option CAN_RAW_LOOPBACK is what you need. Please refer to
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/can.txt#n536
You will not receive CAN frames sent from interface (BCM and other CAN frames), thus only messages from other CAN nodes.

HTH
Alexander



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

* Re: BCM loopback - Information request
  2016-09-20 10:19   ` Angeloni Andrea
@ 2016-09-20 15:06     ` Oliver Hartkopp
  2016-09-20 15:19       ` Angeloni Andrea
  0 siblings, 1 reply; 9+ messages in thread
From: Oliver Hartkopp @ 2016-09-20 15:06 UTC (permalink / raw)
  To: Angeloni Andrea, Alexander Stein; +Cc: linux-can@vger.kernel.org

Hi Andrea,

the CAN_BCM sets the loopback by default:

http://lxr.linux.no/#linux+v4.7.4/net/can/bcm.c#L1229

So it is not configurable by now.

An possibility could be to implement socket options for the CAN_BCM so 
that a setsockopt() with a new CAN_BCM_LOOPBACK becomes available.

But this is not in mainline Linux now.

Alternatively you can check for the fames you received on a CAN_RAW 
socket whether these frames have been created on the local host:

http://lxr.linux.no/#linux+v4.7.4/Documentation/networking/can.txt#L632

Which means that you have to use recvmsg() to read from CAN_RAW.

'candump' does it here:
https://github.com/linux-can/can-utils/blob/master/candump.c#L793

Regards,
Oliver

On 09/20/2016 12:19 PM, Angeloni Andrea wrote:
> Ciao Alexander,
>
> thanks for your answer.
>
> Unfortunately, CAN_RAW_LOOPBACK is not working. Option is indeed referring to socket and not device, while BCM messages are coming from a different socket.
>
> Andrea
>
> -----Original Message-----
> From: Alexander Stein [mailto:alexander.stein@systec-electronic.com]
> Sent: martedì 20 settembre 2016 11:54
> To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>
> Cc: linux-can@vger.kernel.org
> Subject: Re: BCM loopback - Information request
>
> Hi Andrea,
>
> On Tuesday 20 September 2016 09:42:53, Angeloni Andrea wrote:
>> In my application there is a thread for each initialized CAN interface
>> that sends over TCP all the read data to a Windows Client. Data are
>> read using Socket RAW. Application is also capable to send cyclic
>> messages using Broadcast manager.
>>
>> Here is my question: how can I configure my application so that
>> reading thread does not get messages sent by BCM on the same interface?
>
> I think the socket option CAN_RAW_LOOPBACK is what you need. Please refer to
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/networking/can.txt#n536
> You will not receive CAN frames sent from interface (BCM and other CAN frames), thus only messages from other CAN nodes.
>
> HTH
> Alexander
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-can" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

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

* RE: BCM loopback - Information request
  2016-09-20 15:06     ` Oliver Hartkopp
@ 2016-09-20 15:19       ` Angeloni Andrea
  2016-09-20 15:29         ` Oliver Hartkopp
  0 siblings, 1 reply; 9+ messages in thread
From: Angeloni Andrea @ 2016-09-20 15:19 UTC (permalink / raw)
  To: Oliver Hartkopp, Alexander Stein; +Cc: linux-can@vger.kernel.org

Ok clear.

With local host you mean same Linux system or same CAN interface? On the uPC I'm currently using there are two CAN interfaces, and it could happen that one sends data to be processed to the other.

Regards,
Andrea

-----Original Message-----
From: Oliver Hartkopp [mailto:socketcan@hartkopp.net] 
Sent: martedì 20 settembre 2016 17:07
To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>; Alexander Stein <alexander.stein@systec-electronic.com>
Cc: linux-can@vger.kernel.org
Subject: Re: BCM loopback - Information request

Hi Andrea,

the CAN_BCM sets the loopback by default:

http://lxr.linux.no/#linux+v4.7.4/net/can/bcm.c#L1229

So it is not configurable by now.

An possibility could be to implement socket options for the CAN_BCM so that a setsockopt() with a new CAN_BCM_LOOPBACK becomes available.

But this is not in mainline Linux now.

Alternatively you can check for the fames you received on a CAN_RAW socket whether these frames have been created on the local host:

http://lxr.linux.no/#linux+v4.7.4/Documentation/networking/can.txt#L632

Which means that you have to use recvmsg() to read from CAN_RAW.

'candump' does it here:
https://github.com/linux-can/can-utils/blob/master/candump.c#L793

Regards,
Oliver

On 09/20/2016 12:19 PM, Angeloni Andrea wrote:
> Ciao Alexander,
>
> thanks for your answer.
>
> Unfortunately, CAN_RAW_LOOPBACK is not working. Option is indeed referring to socket and not device, while BCM messages are coming from a different socket.
>
> Andrea
>
> -----Original Message-----
> From: Alexander Stein [mailto:alexander.stein@systec-electronic.com]
> Sent: martedì 20 settembre 2016 11:54
> To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>
> Cc: linux-can@vger.kernel.org
> Subject: Re: BCM loopback - Information request
>
> Hi Andrea,
>
> On Tuesday 20 September 2016 09:42:53, Angeloni Andrea wrote:
>> In my application there is a thread for each initialized CAN 
>> interface that sends over TCP all the read data to a Windows Client. 
>> Data are read using Socket RAW. Application is also capable to send 
>> cyclic messages using Broadcast manager.
>>
>> Here is my question: how can I configure my application so that 
>> reading thread does not get messages sent by BCM on the same interface?
>
> I think the socket option CAN_RAW_LOOPBACK is what you need. Please 
> refer to
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/D
> ocumentation/networking/can.txt#n536
> You will not receive CAN frames sent from interface (BCM and other CAN frames), thus only messages from other CAN nodes.
>
> HTH
> Alexander
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-can" 
> in the body of a message to majordomo@vger.kernel.org More majordomo 
> info at  http://vger.kernel.org/majordomo-info.html
>



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

* Re: BCM loopback - Information request
  2016-09-20 15:19       ` Angeloni Andrea
@ 2016-09-20 15:29         ` Oliver Hartkopp
  2016-09-20 15:43           ` Angeloni Andrea
                             ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Oliver Hartkopp @ 2016-09-20 15:29 UTC (permalink / raw)
  To: Angeloni Andrea, Alexander Stein; +Cc: linux-can@vger.kernel.org



On 09/20/2016 05:19 PM, Angeloni Andrea wrote:
> Ok clear.
>
> With local host you mean same Linux system

Yes.

"MSG_DONTROUTE: set when the received frame was created on the local host."


or same CAN interface? On the uPC I'm currently using there are two CAN 
interfaces, and it could happen that one sends data to be processed to 
the other.

When the CAN frame is physically received by the CAN controller it comes 
'from outer space' and not from the local host.

When you sent a frame with CAN ID 0x123 with the CAN_BCM on can0 and you 
have can0 and can1 connected together the received frame on can0 will 
have MSG_DONTROUTE set and the frame received from can1 will have 
MSG_DONTROUTE unset.

Regards,
Oliver

>
> Regards,
> Andrea
>
> -----Original Message-----
> From: Oliver Hartkopp [mailto:socketcan@hartkopp.net]
> Sent: martedì 20 settembre 2016 17:07
> To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>; Alexander Stein <alexander.stein@systec-electronic.com>
> Cc: linux-can@vger.kernel.org
> Subject: Re: BCM loopback - Information request
>
> Hi Andrea,
>
> the CAN_BCM sets the loopback by default:
>
> http://lxr.linux.no/#linux+v4.7.4/net/can/bcm.c#L1229
>
> So it is not configurable by now.
>
> An possibility could be to implement socket options for the CAN_BCM so that a setsockopt() with a new CAN_BCM_LOOPBACK becomes available.
>
> But this is not in mainline Linux now.
>
> Alternatively you can check for the fames you received on a CAN_RAW socket whether these frames have been created on the local host:
>
> http://lxr.linux.no/#linux+v4.7.4/Documentation/networking/can.txt#L632
>
> Which means that you have to use recvmsg() to read from CAN_RAW.
>
> 'candump' does it here:
> https://github.com/linux-can/can-utils/blob/master/candump.c#L793
>
> Regards,
> Oliver
>
> On 09/20/2016 12:19 PM, Angeloni Andrea wrote:
>> Ciao Alexander,
>>
>> thanks for your answer.
>>
>> Unfortunately, CAN_RAW_LOOPBACK is not working. Option is indeed referring to socket and not device, while BCM messages are coming from a different socket.
>>
>> Andrea
>>
>> -----Original Message-----
>> From: Alexander Stein [mailto:alexander.stein@systec-electronic.com]
>> Sent: martedì 20 settembre 2016 11:54
>> To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>
>> Cc: linux-can@vger.kernel.org
>> Subject: Re: BCM loopback - Information request
>>
>> Hi Andrea,
>>
>> On Tuesday 20 September 2016 09:42:53, Angeloni Andrea wrote:
>>> In my application there is a thread for each initialized CAN
>>> interface that sends over TCP all the read data to a Windows Client.
>>> Data are read using Socket RAW. Application is also capable to send
>>> cyclic messages using Broadcast manager.
>>>
>>> Here is my question: how can I configure my application so that
>>> reading thread does not get messages sent by BCM on the same interface?
>>
>> I think the socket option CAN_RAW_LOOPBACK is what you need. Please
>> refer to
>> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/D
>> ocumentation/networking/can.txt#n536
>> You will not receive CAN frames sent from interface (BCM and other CAN frames), thus only messages from other CAN nodes.
>>
>> HTH
>> Alexander
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-can"
>> in the body of a message to majordomo@vger.kernel.org More majordomo
>> info at  http://vger.kernel.org/majordomo-info.html
>>
>
>

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

* RE: BCM loopback - Information request
  2016-09-20 15:29         ` Oliver Hartkopp
@ 2016-09-20 15:43           ` Angeloni Andrea
  2016-09-21 13:35           ` Angeloni Andrea
  2016-09-21 15:03           ` Angeloni Andrea
  2 siblings, 0 replies; 9+ messages in thread
From: Angeloni Andrea @ 2016-09-20 15:43 UTC (permalink / raw)
  To: Oliver Hartkopp, Alexander Stein; +Cc: linux-can@vger.kernel.org

It solves perfectly my issue.

Thanks for your piece of software, good  luck sirs.

Andrea

-----Original Message-----
From: Oliver Hartkopp [mailto:socketcan@hartkopp.net] 
Sent: martedì 20 settembre 2016 17:29
To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>; Alexander Stein <alexander.stein@systec-electronic.com>
Cc: linux-can@vger.kernel.org
Subject: Re: BCM loopback - Information request



On 09/20/2016 05:19 PM, Angeloni Andrea wrote:
> Ok clear.
>
> With local host you mean same Linux system

Yes.

"MSG_DONTROUTE: set when the received frame was created on the local host."


or same CAN interface? On the uPC I'm currently using there are two CAN interfaces, and it could happen that one sends data to be processed to the other.

When the CAN frame is physically received by the CAN controller it comes 'from outer space' and not from the local host.

When you sent a frame with CAN ID 0x123 with the CAN_BCM on can0 and you have can0 and can1 connected together the received frame on can0 will have MSG_DONTROUTE set and the frame received from can1 will have MSG_DONTROUTE unset.

Regards,
Oliver

>
> Regards,
> Andrea
>
> -----Original Message-----
> From: Oliver Hartkopp [mailto:socketcan@hartkopp.net]
> Sent: martedì 20 settembre 2016 17:07
> To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>; Alexander 
> Stein <alexander.stein@systec-electronic.com>
> Cc: linux-can@vger.kernel.org
> Subject: Re: BCM loopback - Information request
>
> Hi Andrea,
>
> the CAN_BCM sets the loopback by default:
>
> http://lxr.linux.no/#linux+v4.7.4/net/can/bcm.c#L1229
>
> So it is not configurable by now.
>
> An possibility could be to implement socket options for the CAN_BCM so that a setsockopt() with a new CAN_BCM_LOOPBACK becomes available.
>
> But this is not in mainline Linux now.
>
> Alternatively you can check for the fames you received on a CAN_RAW socket whether these frames have been created on the local host:
>
> http://lxr.linux.no/#linux+v4.7.4/Documentation/networking/can.txt#L63
> 2
>
> Which means that you have to use recvmsg() to read from CAN_RAW.
>
> 'candump' does it here:
> https://github.com/linux-can/can-utils/blob/master/candump.c#L793
>
> Regards,
> Oliver
>
> On 09/20/2016 12:19 PM, Angeloni Andrea wrote:
>> Ciao Alexander,
>>
>> thanks for your answer.
>>
>> Unfortunately, CAN_RAW_LOOPBACK is not working. Option is indeed referring to socket and not device, while BCM messages are coming from a different socket.
>>
>> Andrea
>>
>> -----Original Message-----
>> From: Alexander Stein [mailto:alexander.stein@systec-electronic.com]
>> Sent: martedì 20 settembre 2016 11:54
>> To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>
>> Cc: linux-can@vger.kernel.org
>> Subject: Re: BCM loopback - Information request
>>
>> Hi Andrea,
>>
>> On Tuesday 20 September 2016 09:42:53, Angeloni Andrea wrote:
>>> In my application there is a thread for each initialized CAN 
>>> interface that sends over TCP all the read data to a Windows Client.
>>> Data are read using Socket RAW. Application is also capable to send 
>>> cyclic messages using Broadcast manager.
>>>
>>> Here is my question: how can I configure my application so that 
>>> reading thread does not get messages sent by BCM on the same interface?
>>
>> I think the socket option CAN_RAW_LOOPBACK is what you need. Please 
>> refer to 
>> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/
>> D
>> ocumentation/networking/can.txt#n536
>> You will not receive CAN frames sent from interface (BCM and other CAN frames), thus only messages from other CAN nodes.
>>
>> HTH
>> Alexander
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-can"
>> in the body of a message to majordomo@vger.kernel.org More majordomo 
>> info at  http://vger.kernel.org/majordomo-info.html
>>
>
>


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

* RE: BCM loopback - Information request
  2016-09-20 15:29         ` Oliver Hartkopp
  2016-09-20 15:43           ` Angeloni Andrea
@ 2016-09-21 13:35           ` Angeloni Andrea
  2016-09-21 15:03           ` Angeloni Andrea
  2 siblings, 0 replies; 9+ messages in thread
From: Angeloni Andrea @ 2016-09-21 13:35 UTC (permalink / raw)
  To: Oliver Hartkopp, Alexander Stein; +Cc: linux-can@vger.kernel.org

Dears,

sorry to bother you again with newby questions.

I changed my code so that "read" is replaced by "recvmsg". After reading, flag MSG_DONTROUTE is checked to understand if data is coming from same CAN device. Now I correctly do not see on CAN[i] messages sent by CAN[i], but whatever I send, via socket RAW or BCM, is read (i.e. n = recvmsg() > 0) twice by recvmsg.

Any hint?

Thanks,
Andrea

-----Original Message-----
From: Angeloni Andrea 
Sent: martedì 20 settembre 2016 17:44
To: 'Oliver Hartkopp' <socketcan@hartkopp.net>; Alexander Stein <alexander.stein@systec-electronic.com>
Cc: linux-can@vger.kernel.org
Subject: RE: BCM loopback - Information request

It solves perfectly my issue.

Thanks for your piece of software, good  luck sirs.

Andrea

-----Original Message-----
From: Oliver Hartkopp [mailto:socketcan@hartkopp.net] 
Sent: martedì 20 settembre 2016 17:29
To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>; Alexander Stein <alexander.stein@systec-electronic.com>
Cc: linux-can@vger.kernel.org
Subject: Re: BCM loopback - Information request



On 09/20/2016 05:19 PM, Angeloni Andrea wrote:
> Ok clear.
>
> With local host you mean same Linux system

Yes.

"MSG_DONTROUTE: set when the received frame was created on the local host."


or same CAN interface? On the uPC I'm currently using there are two CAN interfaces, and it could happen that one sends data to be processed to the other.

When the CAN frame is physically received by the CAN controller it comes 'from outer space' and not from the local host.

When you sent a frame with CAN ID 0x123 with the CAN_BCM on can0 and you have can0 and can1 connected together the received frame on can0 will have MSG_DONTROUTE set and the frame received from can1 will have MSG_DONTROUTE unset.

Regards,
Oliver

>
> Regards,
> Andrea
>
> -----Original Message-----
> From: Oliver Hartkopp [mailto:socketcan@hartkopp.net]
> Sent: martedì 20 settembre 2016 17:07
> To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>; Alexander 
> Stein <alexander.stein@systec-electronic.com>
> Cc: linux-can@vger.kernel.org
> Subject: Re: BCM loopback - Information request
>
> Hi Andrea,
>
> the CAN_BCM sets the loopback by default:
>
> http://lxr.linux.no/#linux+v4.7.4/net/can/bcm.c#L1229
>
> So it is not configurable by now.
>
> An possibility could be to implement socket options for the CAN_BCM so that a setsockopt() with a new CAN_BCM_LOOPBACK becomes available.
>
> But this is not in mainline Linux now.
>
> Alternatively you can check for the fames you received on a CAN_RAW socket whether these frames have been created on the local host:
>
> http://lxr.linux.no/#linux+v4.7.4/Documentation/networking/can.txt#L63
> 2
>
> Which means that you have to use recvmsg() to read from CAN_RAW.
>
> 'candump' does it here:
> https://github.com/linux-can/can-utils/blob/master/candump.c#L793
>
> Regards,
> Oliver
>
> On 09/20/2016 12:19 PM, Angeloni Andrea wrote:
>> Ciao Alexander,
>>
>> thanks for your answer.
>>
>> Unfortunately, CAN_RAW_LOOPBACK is not working. Option is indeed referring to socket and not device, while BCM messages are coming from a different socket.
>>
>> Andrea
>>
>> -----Original Message-----
>> From: Alexander Stein [mailto:alexander.stein@systec-electronic.com]
>> Sent: martedì 20 settembre 2016 11:54
>> To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>
>> Cc: linux-can@vger.kernel.org
>> Subject: Re: BCM loopback - Information request
>>
>> Hi Andrea,
>>
>> On Tuesday 20 September 2016 09:42:53, Angeloni Andrea wrote:
>>> In my application there is a thread for each initialized CAN 
>>> interface that sends over TCP all the read data to a Windows Client.
>>> Data are read using Socket RAW. Application is also capable to send 
>>> cyclic messages using Broadcast manager.
>>>
>>> Here is my question: how can I configure my application so that 
>>> reading thread does not get messages sent by BCM on the same interface?
>>
>> I think the socket option CAN_RAW_LOOPBACK is what you need. Please 
>> refer to 
>> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/
>> D
>> ocumentation/networking/can.txt#n536
>> You will not receive CAN frames sent from interface (BCM and other CAN frames), thus only messages from other CAN nodes.
>>
>> HTH
>> Alexander
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-can"
>> in the body of a message to majordomo@vger.kernel.org More majordomo 
>> info at  http://vger.kernel.org/majordomo-info.html
>>
>
>


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

* RE: BCM loopback - Information request
  2016-09-20 15:29         ` Oliver Hartkopp
  2016-09-20 15:43           ` Angeloni Andrea
  2016-09-21 13:35           ` Angeloni Andrea
@ 2016-09-21 15:03           ` Angeloni Andrea
  2 siblings, 0 replies; 9+ messages in thread
From: Angeloni Andrea @ 2016-09-21 15:03 UTC (permalink / raw)
  To: Oliver Hartkopp, Alexander Stein; +Cc: linux-can@vger.kernel.org

As usual, problem exists between chair and keyboard.

I changed during debug the CAN filters. Same message was matching two of them, thus returning two different reads. Nothing related to recvmsg as wrongly reported by me.

Regards,
Andrea

-----Original Message-----
From: Angeloni Andrea 
Sent: mercoledì 21 settembre 2016 15:35
To: 'Oliver Hartkopp' <socketcan@hartkopp.net>; 'Alexander Stein' <alexander.stein@systec-electronic.com>
Cc: 'linux-can@vger.kernel.org' <linux-can@vger.kernel.org>
Subject: RE: BCM loopback - Information request

Dears,

sorry to bother you again with newby questions.

I changed my code so that "read" is replaced by "recvmsg". After reading, flag MSG_DONTROUTE is checked to understand if data is coming from same CAN device. Now I correctly do not see on CAN[i] messages sent by CAN[i], but whatever I send, via socket RAW or BCM, is read (i.e. n = recvmsg() > 0) twice by recvmsg.

Any hint?

Thanks,
Andrea

-----Original Message-----
From: Angeloni Andrea 
Sent: martedì 20 settembre 2016 17:44
To: 'Oliver Hartkopp' <socketcan@hartkopp.net>; Alexander Stein <alexander.stein@systec-electronic.com>
Cc: linux-can@vger.kernel.org
Subject: RE: BCM loopback - Information request

It solves perfectly my issue.

Thanks for your piece of software, good  luck sirs.

Andrea

-----Original Message-----
From: Oliver Hartkopp [mailto:socketcan@hartkopp.net] 
Sent: martedì 20 settembre 2016 17:29
To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>; Alexander Stein <alexander.stein@systec-electronic.com>
Cc: linux-can@vger.kernel.org
Subject: Re: BCM loopback - Information request



On 09/20/2016 05:19 PM, Angeloni Andrea wrote:
> Ok clear.
>
> With local host you mean same Linux system

Yes.

"MSG_DONTROUTE: set when the received frame was created on the local host."


or same CAN interface? On the uPC I'm currently using there are two CAN interfaces, and it could happen that one sends data to be processed to the other.

When the CAN frame is physically received by the CAN controller it comes 'from outer space' and not from the local host.

When you sent a frame with CAN ID 0x123 with the CAN_BCM on can0 and you have can0 and can1 connected together the received frame on can0 will have MSG_DONTROUTE set and the frame received from can1 will have MSG_DONTROUTE unset.

Regards,
Oliver

>
> Regards,
> Andrea
>
> -----Original Message-----
> From: Oliver Hartkopp [mailto:socketcan@hartkopp.net]
> Sent: martedì 20 settembre 2016 17:07
> To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>; Alexander 
> Stein <alexander.stein@systec-electronic.com>
> Cc: linux-can@vger.kernel.org
> Subject: Re: BCM loopback - Information request
>
> Hi Andrea,
>
> the CAN_BCM sets the loopback by default:
>
> http://lxr.linux.no/#linux+v4.7.4/net/can/bcm.c#L1229
>
> So it is not configurable by now.
>
> An possibility could be to implement socket options for the CAN_BCM so that a setsockopt() with a new CAN_BCM_LOOPBACK becomes available.
>
> But this is not in mainline Linux now.
>
> Alternatively you can check for the fames you received on a CAN_RAW socket whether these frames have been created on the local host:
>
> http://lxr.linux.no/#linux+v4.7.4/Documentation/networking/can.txt#L63
> 2
>
> Which means that you have to use recvmsg() to read from CAN_RAW.
>
> 'candump' does it here:
> https://github.com/linux-can/can-utils/blob/master/candump.c#L793
>
> Regards,
> Oliver
>
> On 09/20/2016 12:19 PM, Angeloni Andrea wrote:
>> Ciao Alexander,
>>
>> thanks for your answer.
>>
>> Unfortunately, CAN_RAW_LOOPBACK is not working. Option is indeed referring to socket and not device, while BCM messages are coming from a different socket.
>>
>> Andrea
>>
>> -----Original Message-----
>> From: Alexander Stein [mailto:alexander.stein@systec-electronic.com]
>> Sent: martedì 20 settembre 2016 11:54
>> To: Angeloni Andrea <andrea.angeloni@alfamationglobal.com>
>> Cc: linux-can@vger.kernel.org
>> Subject: Re: BCM loopback - Information request
>>
>> Hi Andrea,
>>
>> On Tuesday 20 September 2016 09:42:53, Angeloni Andrea wrote:
>>> In my application there is a thread for each initialized CAN 
>>> interface that sends over TCP all the read data to a Windows Client.
>>> Data are read using Socket RAW. Application is also capable to send 
>>> cyclic messages using Broadcast manager.
>>>
>>> Here is my question: how can I configure my application so that 
>>> reading thread does not get messages sent by BCM on the same interface?
>>
>> I think the socket option CAN_RAW_LOOPBACK is what you need. Please 
>> refer to 
>> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/
>> D
>> ocumentation/networking/can.txt#n536
>> You will not receive CAN frames sent from interface (BCM and other CAN frames), thus only messages from other CAN nodes.
>>
>> HTH
>> Alexander
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-can"
>> in the body of a message to majordomo@vger.kernel.org More majordomo 
>> info at  http://vger.kernel.org/majordomo-info.html
>>
>
>


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

end of thread, other threads:[~2016-09-21 15:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-20  9:42 BCM loopback - Information request Angeloni Andrea
2016-09-20  9:53 ` Alexander Stein
2016-09-20 10:19   ` Angeloni Andrea
2016-09-20 15:06     ` Oliver Hartkopp
2016-09-20 15:19       ` Angeloni Andrea
2016-09-20 15:29         ` Oliver Hartkopp
2016-09-20 15:43           ` Angeloni Andrea
2016-09-21 13:35           ` Angeloni Andrea
2016-09-21 15:03           ` Angeloni Andrea

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.