Question

I have received a driver (PCAN driver for PCI card, using rtdm), that creates /dev/pcan0 and /dev/pcan1 is compiled as a netdev driver.

There are many facilities that come with this driver, but they are all targeted at a user-level program reading CAN messages. What I need however is to read these messages from a kernel module. The PCAN driver doesn't export any variables/functions which means it doesn't provide a kernel-level API for me to use.

I looked briefly at the code and reading from the /dev device and writing to it don't use copy_from_user or copy_to_user. Therefore, I thought it should be safe for me to open the /dev/pcan0 from my kernel module and read from it.

Now my question is, how do I open/read from a /dev device from a kernel module?

P.S. I want to read from the CAN bus from an RTAI real-time thread, do you think that would cause a problem (for example every read passing through linux kernel and thus breaking real-time conditions?)

Was it helpful?

Solution 2

Given that I was using RTDM, there were two options:

  • Using RTDM direct functions, such rt_dev_open, rt_dev_read etc
    • This is not implemented in the current version of pcan driver
  • Using RTDM ioctl
    • This was the solution and it worked

OTHER TIPS

You can use syscalls directly from kernel space: sys_open(), sys_read(), sys_close(). There's Linuxjournal article about that.

P/S: copy_from_user() works perfectly with kernel-space addresses.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top