4

I'm trying to write a slightly modified CAN protocol for SocketCAN. The SocketCAN documentation has a short section about this:

5.3 writing own CAN protocol modules

To implement a new protocol in the protocol family PF_CAN a new
protocol has to be defined in include/linux/can.h .
The prototypes and definitions to use the SocketCAN core can be
accessed by including include/linux/can/core.h .
In addition to functions that register the CAN protocol and the
CAN device notifier chain there are functions to subscribe CAN
frames received by CAN interfaces and to send CAN frames:

can_rx_register   - subscribe CAN frames from a specific interface
can_rx_unregister - unsubscribe CAN frames from a specific interface
can_send          - transmit a CAN frame (optional with local loopback)

For details see the kerneldoc documentation in net/can/af_can.c or
the source code of net/can/raw.c or net/can/bcm.c .

(https://www.kernel.org/doc/Documentation/networking/can.txt)

The problem is I can't find some of the files referenced here. I'm not super familiar with the Linux kernel, so I don't know if I'm looking in the wrong place. I can find include/linux/can.h and the directory include/linux/can/ but there is no core.h file there. Additionally, I can't locate the net/ directory that is referenced.

Other info:

  • I am able to send and receive raw CAN frames, so I believe I have SocketCAN set up correctly

  • Contents of directory (where core.h should be):

     beaglebone:~# ls /usr/include/linux/can/
     bcm.h  error.h  gw.h  netlink.h  raw.h
    
  • I'm using Debian on a BeagleBone Black (I'm not sure if the embeddedness of my system makes a difference)

If someone can help point me to where I should be looking for these files, I would be very obliged.

Many thanks!

RuthSB
  • 49
  • 3
  • 1
    You need to look within the source code of the kernel, not in /usr/include. which are header files for user space applications – nos Jul 28 '15 at 19:51
  • Ah! Does that mean that after I make my modifications I will have to recompile the kernel? – RuthSB Jul 28 '15 at 20:46
  • Perhaps. It might be you only need to change existing kernel modules (and add your own), and reload just those modules - but I don't know enough of the details of the CAN subsystem. Depending on what you need to do, you might be able to write your own protocol in userspace if you're using a CAN_RAW socket though. – nos Jul 28 '15 at 20:48
  • I've tried using the CAN_RAW option but my protocol has a slightly longer frame length so the socket was complaining when I tried to write to it. I'll have a look into what modules I'd need to change. Thanks for your help! – RuthSB Jul 28 '15 at 21:02
  • See if you can enable CAN_RAW_FD_FRAMES, which enables larger frames.(see e.g chapter 4.1.5 in that can.txt documentation) – nos Jul 28 '15 at 21:17

1 Answers1

0

The CAN protocol is implemented in hardware; attempts to make packets that don't comply with the standard won't work with compliant hardware.

Ned Konz
  • 21
  • 2