【发布时间】:2015-10-19 13:20:56
【问题描述】:
我正在尝试为 SocketCAN 编写稍微修改的 CAN 协议。 SocketCAN 文档对此有一个简短的部分:
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)
问题是我找不到这里引用的一些文件。我对Linux内核不是很熟悉,所以我不知道我是不是找错地方了。我可以找到include/linux/can.h 和目录include/linux/can/,但那里没有core.h 文件。此外,我找不到引用的 net/ 目录。
其他信息:
我能够发送和接收原始 CAN 帧,所以我相信我已经正确设置了 SocketCAN
-
目录的内容(应该是
core.h):beaglebone:~# ls /usr/include/linux/can/ bcm.h error.h gw.h netlink.h raw.h 我在 BeagleBone Black 上使用 Debian(我不确定我的系统的嵌入性是否会产生影响)
如果有人能帮我指出我应该在哪里寻找这些文件,我将非常感激。
非常感谢!
【问题讨论】:
-
你需要查看内核的源代码,而不是/usr/include。这是用户空间应用程序的头文件
-
啊!这是否意味着在我进行修改后我必须重新编译内核?
-
也许吧。您可能只需要更改现有的内核模块(并添加您自己的),然后只重新加载这些模块 - 但我对 CAN 子系统的详细信息知之甚少。根据您需要做的事情,如果您使用的是 CAN_RAW 套接字,您也许可以在用户空间中编写自己的协议。
-
我尝试使用 CAN_RAW 选项,但我的协议的帧长度稍长,因此当我尝试写入时套接字会抱怨。我会看看我需要更改哪些模块。感谢您的帮助!
-
查看是否可以启用 CAN_RAW_FD_FRAMES,它可以启用更大的帧。(例如,参见 can.txt 文档中的第 4.1.5 章)
标签: linux beagleboneblack can-bus socketcan