Exposing CAN hardware from userspace
Hi,
I am attempting to interface with the CAN hardware in a remote device over a network and expose it locally as a SocketCAN bus. The remote device does not run Linux, but I am able to fully expose the CAN hardware over the network using a custom protocol. Latency in itself is not an issue for this use case, but accurate timestamping and reliable transmission to the remote is.
So far I have found a few userspace tools which could handle the network communication aspect (such as socketcand[1] and cannelloni[2]), but these all seem to expose the remote side as a local node on a SocketCAN bus and not a bus in itself.
As there is no CAN hardware locally in my use case, the only option is to create a virtual CAN bus via vcan if using the above userspace tools. This presents a few issues:
* The remote timestamp information is not propagated to the local SocketCAN bus. I.e. the accurate remote hardware timestamp is replaced by a local software timestamp.
* The direction of messages is lost, as all messages are sent into the vcan bus and thus marked as tx in e.g. candump.
* Flow control from the remote side is lost, such that local nodes can send CAN frames even though the remote side is fully loaded.
Overall, vcan is likely the wrong tool for this job, but I am not aware of any alternatives. Are there any options I have missed which can solve the above issues without providing a new kernel module? The use case seems closely related to the tun/tap driver in the networking stack in general, but I am unsure if these could be extended to handle the SocketCAN case.
If I were to take the route of a new kernel module, what options do I have for exposing the data and control structures of a SocketCAN bus to userspace? So far I know of file descriptors as in the tun/tap case, but I am not knowledgeable enough in the kernel systems in general to see if there are other options which would be a better fit for bidirectional data and/or asynchronous messages?
Any advice is appreciated.
Regards,
Magnus.
[1]: https://github.com/linux-can/socketcand
[2]: https://github.com/mguentner/cannelloni
Marc Kleine-Budde
maintainerQuoted 22 lines · Magnus Aagaard Sørensen
I am attempting to interface with the CAN hardware in a remote device over a network and expose it locally as a SocketCAN bus. The remote device does not run Linux, but I am able to fully expose the CAN hardware over the network using a custom protocol. Latency in itself is not an issue for this use case, but accurate timestamping and reliable transmission to the remote is.
So far I have found a few userspace tools which could handle the network communication aspect (such as socketcand[1] and cannelloni[2]), but these all seem to expose the remote side as a local node on a SocketCAN bus and not a bus in itself.
As there is no CAN hardware locally in my use case, the only option is to create a virtual CAN bus via vcan if using the above userspace tools. This presents a few issues:
* The remote timestamp information is not propagated to the local SocketCAN bus. I.e. the accurate remote hardware timestamp is replaced by a local software timestamp.
* The direction of messages is lost, as all messages are sent into the vcan bus and thus marked as tx in e.g. candump.
* Flow control from the remote side is lost, such that local nodes can send CAN frames even though the remote side is fully loaded.
Quoted 5 lines
Overall, vcan is likely the wrong tool for this job, but I am not aware of any alternatives. Are there any options I have missed which can solve the above issues without providing a new kernel module? The use case seems closely related to the tun/tap driver in the networking stack in general, but I am unsure if these could be extended to handle the SocketCAN case.
If I remember correctly the Linux kernel fuzzer sysbot already uses the tap interface to inject CAN frames into the kernel. Let me see.
Quoted 6 lines
If I were to take the route of a new kernel module, what options do I have for exposing the data and control structures of a SocketCAN bus to userspace? So far I know of file descriptors as in the tun/tap case, but I am not knowledgeable enough in the kernel systems in general to see if there are other options which would be a better fit for bidirectional data and/or asynchronous messages?
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |