can.txt 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. ============================================================================
  2. can.txt
  3. Readme file for the Controller Area Network Protocol Family (aka Socket CAN)
  4. This file contains
  5. 1 Overview / What is Socket CAN
  6. 2 Motivation / Why using the socket API
  7. 3 Socket CAN concept
  8. 3.1 receive lists
  9. 3.2 local loopback of sent frames
  10. 3.3 network security issues (capabilities)
  11. 3.4 network problem notifications
  12. 4 How to use Socket CAN
  13. 4.1 RAW protocol sockets with can_filters (SOCK_RAW)
  14. 4.1.1 RAW socket option CAN_RAW_FILTER
  15. 4.1.2 RAW socket option CAN_RAW_ERR_FILTER
  16. 4.1.3 RAW socket option CAN_RAW_LOOPBACK
  17. 4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS
  18. 4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
  19. 4.3 connected transport protocols (SOCK_SEQPACKET)
  20. 4.4 unconnected transport protocols (SOCK_DGRAM)
  21. 5 Socket CAN core module
  22. 5.1 can.ko module params
  23. 5.2 procfs content
  24. 5.3 writing own CAN protocol modules
  25. 6 CAN network drivers
  26. 6.1 general settings
  27. 6.2 local loopback of sent frames
  28. 6.3 CAN controller hardware filters
  29. 6.4 currently supported CAN hardware
  30. 6.5 todo
  31. 7 Credits
  32. ============================================================================
  33. 1. Overview / What is Socket CAN
  34. --------------------------------
  35. The socketcan package is an implementation of CAN protocols
  36. (Controller Area Network) for Linux. CAN is a networking technology
  37. which has widespread use in automation, embedded devices, and
  38. automotive fields. While there have been other CAN implementations
  39. for Linux based on character devices, Socket CAN uses the Berkeley
  40. socket API, the Linux network stack and implements the CAN device
  41. drivers as network interfaces. The CAN socket API has been designed
  42. as similar as possible to the TCP/IP protocols to allow programmers,
  43. familiar with network programming, to easily learn how to use CAN
  44. sockets.
  45. 2. Motivation / Why using the socket API
  46. ----------------------------------------
  47. There have been CAN implementations for Linux before Socket CAN so the
  48. question arises, why we have started another project. Most existing
  49. implementations come as a device driver for some CAN hardware, they
  50. are based on character devices and provide comparatively little
  51. functionality. Usually, there is only a hardware-specific device
  52. driver which provides a character device interface to send and
  53. receive raw CAN frames, directly to/from the controller hardware.
  54. Queueing of frames and higher-level transport protocols like ISO-TP
  55. have to be implemented in user space applications. Also, most
  56. character-device implementations support only one single process to
  57. open the device at a time, similar to a serial interface. Exchanging
  58. the CAN controller requires employment of another device driver and
  59. often the need for adaption of large parts of the application to the
  60. new driver's API.
  61. Socket CAN was designed to overcome all of these limitations. A new
  62. protocol family has been implemented which provides a socket interface
  63. to user space applications and which builds upon the Linux network
  64. layer, so to use all of the provided queueing functionality. A device
  65. driver for CAN controller hardware registers itself with the Linux
  66. network layer as a network device, so that CAN frames from the
  67. controller can be passed up to the network layer and on to the CAN
  68. protocol family module and also vice-versa. Also, the protocol family
  69. module provides an API for transport protocol modules to register, so
  70. that any number of transport protocols can be loaded or unloaded
  71. dynamically. In fact, the can core module alone does not provide any
  72. protocol and cannot be used without loading at least one additional
  73. protocol module. Multiple sockets can be opened at the same time,
  74. on different or the same protocol module and they can listen/send
  75. frames on different or the same CAN IDs. Several sockets listening on
  76. the same interface for frames with the same CAN ID are all passed the
  77. same received matching CAN frames. An application wishing to
  78. communicate using a specific transport protocol, e.g. ISO-TP, just
  79. selects that protocol when opening the socket, and then can read and
  80. write application data byte streams, without having to deal with
  81. CAN-IDs, frames, etc.
  82. Similar functionality visible from user-space could be provided by a
  83. character device, too, but this would lead to a technically inelegant
  84. solution for a couple of reasons:
  85. * Intricate usage. Instead of passing a protocol argument to
  86. socket(2) and using bind(2) to select a CAN interface and CAN ID, an
  87. application would have to do all these operations using ioctl(2)s.
  88. * Code duplication. A character device cannot make use of the Linux
  89. network queueing code, so all that code would have to be duplicated
  90. for CAN networking.
  91. * Abstraction. In most existing character-device implementations, the
  92. hardware-specific device driver for a CAN controller directly
  93. provides the character device for the application to work with.
  94. This is at least very unusual in Unix systems for both, char and
  95. block devices. For example you don't have a character device for a
  96. certain UART of a serial interface, a certain sound chip in your
  97. computer, a SCSI or IDE controller providing access to your hard
  98. disk or tape streamer device. Instead, you have abstraction layers
  99. which provide a unified character or block device interface to the
  100. application on the one hand, and a interface for hardware-specific
  101. device drivers on the other hand. These abstractions are provided
  102. by subsystems like the tty layer, the audio subsystem or the SCSI
  103. and IDE subsystems for the devices mentioned above.
  104. The easiest way to implement a CAN device driver is as a character
  105. device without such a (complete) abstraction layer, as is done by most
  106. existing drivers. The right way, however, would be to add such a
  107. layer with all the functionality like registering for certain CAN
  108. IDs, supporting several open file descriptors and (de)multiplexing
  109. CAN frames between them, (sophisticated) queueing of CAN frames, and
  110. providing an API for device drivers to register with. However, then
  111. it would be no more difficult, or may be even easier, to use the
  112. networking framework provided by the Linux kernel, and this is what
  113. Socket CAN does.
  114. The use of the networking framework of the Linux kernel is just the
  115. natural and most appropriate way to implement CAN for Linux.
  116. 3. Socket CAN concept
  117. ---------------------
  118. As described in chapter 2 it is the main goal of Socket CAN to
  119. provide a socket interface to user space applications which builds
  120. upon the Linux network layer. In contrast to the commonly known
  121. TCP/IP and ethernet networking, the CAN bus is a broadcast-only(!)
  122. medium that has no MAC-layer addressing like ethernet. The CAN-identifier
  123. (can_id) is used for arbitration on the CAN-bus. Therefore the CAN-IDs
  124. have to be chosen uniquely on the bus. When designing a CAN-ECU
  125. network the CAN-IDs are mapped to be sent by a specific ECU.
  126. For this reason a CAN-ID can be treated best as a kind of source address.
  127. 3.1 receive lists
  128. The network transparent access of multiple applications leads to the
  129. problem that different applications may be interested in the same
  130. CAN-IDs from the same CAN network interface. The Socket CAN core
  131. module - which implements the protocol family CAN - provides several
  132. high efficient receive lists for this reason. If e.g. a user space
  133. application opens a CAN RAW socket, the raw protocol module itself
  134. requests the (range of) CAN-IDs from the Socket CAN core that are
  135. requested by the user. The subscription and unsubscription of
  136. CAN-IDs can be done for specific CAN interfaces or for all(!) known
  137. CAN interfaces with the can_rx_(un)register() functions provided to
  138. CAN protocol modules by the SocketCAN core (see chapter 5).
  139. To optimize the CPU usage at runtime the receive lists are split up
  140. into several specific lists per device that match the requested
  141. filter complexity for a given use-case.
  142. 3.2 local loopback of sent frames
  143. As known from other networking concepts the data exchanging
  144. applications may run on the same or different nodes without any
  145. change (except for the according addressing information):
  146. ___ ___ ___ _______ ___
  147. | _ | | _ | | _ | | _ _ | | _ |
  148. ||A|| ||B|| ||C|| ||A| |B|| ||C||
  149. |___| |___| |___| |_______| |___|
  150. | | | | |
  151. -----------------(1)- CAN bus -(2)---------------
  152. To ensure that application A receives the same information in the
  153. example (2) as it would receive in example (1) there is need for
  154. some kind of local loopback of the sent CAN frames on the appropriate
  155. node.
  156. The Linux network devices (by default) just can handle the
  157. transmission and reception of media dependent frames. Due to the
  158. arbritration on the CAN bus the transmission of a low prio CAN-ID
  159. may be delayed by the reception of a high prio CAN frame. To
  160. reflect the correct* traffic on the node the loopback of the sent
  161. data has to be performed right after a successful transmission. If
  162. the CAN network interface is not capable of performing the loopback for
  163. some reason the SocketCAN core can do this task as a fallback solution.
  164. See chapter 6.2 for details (recommended).
  165. The loopback functionality is enabled by default to reflect standard
  166. networking behaviour for CAN applications. Due to some requests from
  167. the RT-SocketCAN group the loopback optionally may be disabled for each
  168. separate socket. See sockopts from the CAN RAW sockets in chapter 4.1.
  169. * = you really like to have this when you're running analyser tools
  170. like 'candump' or 'cansniffer' on the (same) node.
  171. 3.3 network security issues (capabilities)
  172. The Controller Area Network is a local field bus transmitting only
  173. broadcast messages without any routing and security concepts.
  174. In the majority of cases the user application has to deal with
  175. raw CAN frames. Therefore it might be reasonable NOT to restrict
  176. the CAN access only to the user root, as known from other networks.
  177. Since the currently implemented CAN_RAW and CAN_BCM sockets can only
  178. send and receive frames to/from CAN interfaces it does not affect
  179. security of others networks to allow all users to access the CAN.
  180. To enable non-root users to access CAN_RAW and CAN_BCM protocol
  181. sockets the Kconfig options CAN_RAW_USER and/or CAN_BCM_USER may be
  182. selected at kernel compile time.
  183. 3.4 network problem notifications
  184. The use of the CAN bus may lead to several problems on the physical
  185. and media access control layer. Detecting and logging of these lower
  186. layer problems is a vital requirement for CAN users to identify
  187. hardware issues on the physical transceiver layer as well as
  188. arbitration problems and error frames caused by the different
  189. ECUs. The occurrence of detected errors are important for diagnosis
  190. and have to be logged together with the exact timestamp. For this
  191. reason the CAN interface driver can generate so called Error Frames
  192. that can optionally be passed to the user application in the same
  193. way as other CAN frames. Whenever an error on the physical layer
  194. or the MAC layer is detected (e.g. by the CAN controller) the driver
  195. creates an appropriate error frame. Error frames can be requested by
  196. the user application using the common CAN filter mechanisms. Inside
  197. this filter definition the (interested) type of errors may be
  198. selected. The reception of error frames is disabled by default.
  199. 4. How to use Socket CAN
  200. ------------------------
  201. Like TCP/IP, you first need to open a socket for communicating over a
  202. CAN network. Since Socket CAN implements a new protocol family, you
  203. need to pass PF_CAN as the first argument to the socket(2) system
  204. call. Currently, there are two CAN protocols to choose from, the raw
  205. socket protocol and the broadcast manager (BCM). So to open a socket,
  206. you would write
  207. s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
  208. and
  209. s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM);
  210. respectively. After the successful creation of the socket, you would
  211. normally use the bind(2) system call to bind the socket to a CAN
  212. interface (which is different from TCP/IP due to different addressing
  213. - see chapter 3). After binding (CAN_RAW) or connecting (CAN_BCM)
  214. the socket, you can read(2) and write(2) from/to the socket or use
  215. send(2), sendto(2), sendmsg(2) and the recv* counterpart operations
  216. on the socket as usual. There are also CAN specific socket options
  217. described below.
  218. The basic CAN frame structure and the sockaddr structure are defined
  219. in include/linux/can.h:
  220. struct can_frame {
  221. canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
  222. __u8 can_dlc; /* data length code: 0 .. 8 */
  223. __u8 data[8] __attribute__((aligned(8)));
  224. };
  225. The alignment of the (linear) payload data[] to a 64bit boundary
  226. allows the user to define own structs and unions to easily access the
  227. CAN payload. There is no given byteorder on the CAN bus by
  228. default. A read(2) system call on a CAN_RAW socket transfers a
  229. struct can_frame to the user space.
  230. The sockaddr_can structure has an interface index like the
  231. PF_PACKET socket, that also binds to a specific interface:
  232. struct sockaddr_can {
  233. sa_family_t can_family;
  234. int can_ifindex;
  235. union {
  236. /* transport protocol class address info (e.g. ISOTP) */
  237. struct { canid_t rx_id, tx_id; } tp;
  238. /* reserved for future CAN protocols address information */
  239. } can_addr;
  240. };
  241. To determine the interface index an appropriate ioctl() has to
  242. be used (example for CAN_RAW sockets without error checking):
  243. int s;
  244. struct sockaddr_can addr;
  245. struct ifreq ifr;
  246. s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
  247. strcpy(ifr.ifr_name, "can0" );
  248. ioctl(s, SIOCGIFINDEX, &ifr);
  249. addr.can_family = AF_CAN;
  250. addr.can_ifindex = ifr.ifr_ifindex;
  251. bind(s, (struct sockaddr *)&addr, sizeof(addr));
  252. (..)
  253. To bind a socket to all(!) CAN interfaces the interface index must
  254. be 0 (zero). In this case the socket receives CAN frames from every
  255. enabled CAN interface. To determine the originating CAN interface
  256. the system call recvfrom(2) may be used instead of read(2). To send
  257. on a socket that is bound to 'any' interface sendto(2) is needed to
  258. specify the outgoing interface.
  259. Reading CAN frames from a bound CAN_RAW socket (see above) consists
  260. of reading a struct can_frame:
  261. struct can_frame frame;
  262. nbytes = read(s, &frame, sizeof(struct can_frame));
  263. if (nbytes < 0) {
  264. perror("can raw socket read");
  265. return 1;
  266. }
  267. /* paraniod check ... */
  268. if (nbytes < sizeof(struct can_frame)) {
  269. fprintf(stderr, "read: incomplete CAN frame\n");
  270. return 1;
  271. }
  272. /* do something with the received CAN frame */
  273. Writing CAN frames can be done similarly, with the write(2) system call:
  274. nbytes = write(s, &frame, sizeof(struct can_frame));
  275. When the CAN interface is bound to 'any' existing CAN interface
  276. (addr.can_ifindex = 0) it is recommended to use recvfrom(2) if the
  277. information about the originating CAN interface is needed:
  278. struct sockaddr_can addr;
  279. struct ifreq ifr;
  280. socklen_t len = sizeof(addr);
  281. struct can_frame frame;
  282. nbytes = recvfrom(s, &frame, sizeof(struct can_frame),
  283. 0, (struct sockaddr*)&addr, &len);
  284. /* get interface name of the received CAN frame */
  285. ifr.ifr_ifindex = addr.can_ifindex;
  286. ioctl(s, SIOCGIFNAME, &ifr);
  287. printf("Received a CAN frame from interface %s", ifr.ifr_name);
  288. To write CAN frames on sockets bound to 'any' CAN interface the
  289. outgoing interface has to be defined certainly.
  290. strcpy(ifr.ifr_name, "can0");
  291. ioctl(s, SIOCGIFINDEX, &ifr);
  292. addr.can_ifindex = ifr.ifr_ifindex;
  293. addr.can_family = AF_CAN;
  294. nbytes = sendto(s, &frame, sizeof(struct can_frame),
  295. 0, (struct sockaddr*)&addr, sizeof(addr));
  296. 4.1 RAW protocol sockets with can_filters (SOCK_RAW)
  297. Using CAN_RAW sockets is extensively comparable to the commonly
  298. known access to CAN character devices. To meet the new possibilities
  299. provided by the multi user SocketCAN approach, some reasonable
  300. defaults are set at RAW socket binding time:
  301. - The filters are set to exactly one filter receiving everything
  302. - The socket only receives valid data frames (=> no error frames)
  303. - The loopback of sent CAN frames is enabled (see chapter 3.2)
  304. - The socket does not receive its own sent frames (in loopback mode)
  305. These default settings may be changed before or after binding the socket.
  306. To use the referenced definitions of the socket options for CAN_RAW
  307. sockets, include <linux/can/raw.h>.
  308. 4.1.1 RAW socket option CAN_RAW_FILTER
  309. The reception of CAN frames using CAN_RAW sockets can be controlled
  310. by defining 0 .. n filters with the CAN_RAW_FILTER socket option.
  311. The CAN filter structure is defined in include/linux/can.h:
  312. struct can_filter {
  313. canid_t can_id;
  314. canid_t can_mask;
  315. };
  316. A filter matches, when
  317. <received_can_id> & mask == can_id & mask
  318. which is analogous to known CAN controllers hardware filter semantics.
  319. The filter can be inverted in this semantic, when the CAN_INV_FILTER
  320. bit is set in can_id element of the can_filter structure. In
  321. contrast to CAN controller hardware filters the user may set 0 .. n
  322. receive filters for each open socket separately:
  323. struct can_filter rfilter[2];
  324. rfilter[0].can_id = 0x123;
  325. rfilter[0].can_mask = CAN_SFF_MASK;
  326. rfilter[1].can_id = 0x200;
  327. rfilter[1].can_mask = 0x700;
  328. setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));
  329. To disable the reception of CAN frames on the selected CAN_RAW socket:
  330. setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
  331. To set the filters to zero filters is quite obsolete as not read
  332. data causes the raw socket to discard the received CAN frames. But
  333. having this 'send only' use-case we may remove the receive list in the
  334. Kernel to save a little (really a very little!) CPU usage.
  335. 4.1.2 RAW socket option CAN_RAW_ERR_FILTER
  336. As described in chapter 3.4 the CAN interface driver can generate so
  337. called Error Frames that can optionally be passed to the user
  338. application in the same way as other CAN frames. The possible
  339. errors are divided into different error classes that may be filtered
  340. using the appropriate error mask. To register for every possible
  341. error condition CAN_ERR_MASK can be used as value for the error mask.
  342. The values for the error mask are defined in linux/can/error.h .
  343. can_err_mask_t err_mask = ( CAN_ERR_TX_TIMEOUT | CAN_ERR_BUSOFF );
  344. setsockopt(s, SOL_CAN_RAW, CAN_RAW_ERR_FILTER,
  345. &err_mask, sizeof(err_mask));
  346. 4.1.3 RAW socket option CAN_RAW_LOOPBACK
  347. To meet multi user needs the local loopback is enabled by default
  348. (see chapter 3.2 for details). But in some embedded use-cases
  349. (e.g. when only one application uses the CAN bus) this loopback
  350. functionality can be disabled (separately for each socket):
  351. int loopback = 0; /* 0 = disabled, 1 = enabled (default) */
  352. setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK, &loopback, sizeof(loopback));
  353. 4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS
  354. When the local loopback is enabled, all the sent CAN frames are
  355. looped back to the open CAN sockets that registered for the CAN
  356. frames' CAN-ID on this given interface to meet the multi user
  357. needs. The reception of the CAN frames on the same socket that was
  358. sending the CAN frame is assumed to be unwanted and therefore
  359. disabled by default. This default behaviour may be changed on
  360. demand:
  361. int recv_own_msgs = 1; /* 0 = disabled (default), 1 = enabled */
  362. setsockopt(s, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS,
  363. &recv_own_msgs, sizeof(recv_own_msgs));
  364. 4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
  365. 4.3 connected transport protocols (SOCK_SEQPACKET)
  366. 4.4 unconnected transport protocols (SOCK_DGRAM)
  367. 5. Socket CAN core module
  368. -------------------------
  369. The Socket CAN core module implements the protocol family
  370. PF_CAN. CAN protocol modules are loaded by the core module at
  371. runtime. The core module provides an interface for CAN protocol
  372. modules to subscribe needed CAN IDs (see chapter 3.1).
  373. 5.1 can.ko module params
  374. - stats_timer: To calculate the Socket CAN core statistics
  375. (e.g. current/maximum frames per second) this 1 second timer is
  376. invoked at can.ko module start time by default. This timer can be
  377. disabled by using stattimer=0 on the module comandline.
  378. - debug: (removed since SocketCAN SVN r546)
  379. 5.2 procfs content
  380. As described in chapter 3.1 the Socket CAN core uses several filter
  381. lists to deliver received CAN frames to CAN protocol modules. These
  382. receive lists, their filters and the count of filter matches can be
  383. checked in the appropriate receive list. All entries contain the
  384. device and a protocol module identifier:
  385. foo@bar:~$ cat /proc/net/can/rcvlist_all
  386. receive list 'rx_all':
  387. (vcan3: no entry)
  388. (vcan2: no entry)
  389. (vcan1: no entry)
  390. device can_id can_mask function userdata matches ident
  391. vcan0 000 00000000 f88e6370 f6c6f400 0 raw
  392. (any: no entry)
  393. In this example an application requests any CAN traffic from vcan0.
  394. rcvlist_all - list for unfiltered entries (no filter operations)
  395. rcvlist_eff - list for single extended frame (EFF) entries
  396. rcvlist_err - list for error frames masks
  397. rcvlist_fil - list for mask/value filters
  398. rcvlist_inv - list for mask/value filters (inverse semantic)
  399. rcvlist_sff - list for single standard frame (SFF) entries
  400. Additional procfs files in /proc/net/can
  401. stats - Socket CAN core statistics (rx/tx frames, match ratios, ...)
  402. reset_stats - manual statistic reset
  403. version - prints the Socket CAN core version and the ABI version
  404. 5.3 writing own CAN protocol modules
  405. To implement a new protocol in the protocol family PF_CAN a new
  406. protocol has to be defined in include/linux/can.h .
  407. The prototypes and definitions to use the Socket CAN core can be
  408. accessed by including include/linux/can/core.h .
  409. In addition to functions that register the CAN protocol and the
  410. CAN device notifier chain there are functions to subscribe CAN
  411. frames received by CAN interfaces and to send CAN frames:
  412. can_rx_register - subscribe CAN frames from a specific interface
  413. can_rx_unregister - unsubscribe CAN frames from a specific interface
  414. can_send - transmit a CAN frame (optional with local loopback)
  415. For details see the kerneldoc documentation in net/can/af_can.c or
  416. the source code of net/can/raw.c or net/can/bcm.c .
  417. 6. CAN network drivers
  418. ----------------------
  419. Writing a CAN network device driver is much easier than writing a
  420. CAN character device driver. Similar to other known network device
  421. drivers you mainly have to deal with:
  422. - TX: Put the CAN frame from the socket buffer to the CAN controller.
  423. - RX: Put the CAN frame from the CAN controller to the socket buffer.
  424. See e.g. at Documentation/networking/netdevices.txt . The differences
  425. for writing CAN network device driver are described below:
  426. 6.1 general settings
  427. dev->type = ARPHRD_CAN; /* the netdevice hardware type */
  428. dev->flags = IFF_NOARP; /* CAN has no arp */
  429. dev->mtu = sizeof(struct can_frame);
  430. The struct can_frame is the payload of each socket buffer in the
  431. protocol family PF_CAN.
  432. 6.2 local loopback of sent frames
  433. As described in chapter 3.2 the CAN network device driver should
  434. support a local loopback functionality similar to the local echo
  435. e.g. of tty devices. In this case the driver flag IFF_ECHO has to be
  436. set to prevent the PF_CAN core from locally echoing sent frames
  437. (aka loopback) as fallback solution:
  438. dev->flags = (IFF_NOARP | IFF_ECHO);
  439. 6.3 CAN controller hardware filters
  440. To reduce the interrupt load on deep embedded systems some CAN
  441. controllers support the filtering of CAN IDs or ranges of CAN IDs.
  442. These hardware filter capabilities vary from controller to
  443. controller and have to be identified as not feasible in a multi-user
  444. networking approach. The use of the very controller specific
  445. hardware filters could make sense in a very dedicated use-case, as a
  446. filter on driver level would affect all users in the multi-user
  447. system. The high efficient filter sets inside the PF_CAN core allow
  448. to set different multiple filters for each socket separately.
  449. Therefore the use of hardware filters goes to the category 'handmade
  450. tuning on deep embedded systems'. The author is running a MPC603e
  451. @133MHz with four SJA1000 CAN controllers from 2002 under heavy bus
  452. load without any problems ...
  453. 6.4 currently supported CAN hardware (September 2007)
  454. On the project website http://developer.berlios.de/projects/socketcan
  455. there are different drivers available:
  456. vcan: Virtual CAN interface driver (if no real hardware is available)
  457. sja1000: Philips SJA1000 CAN controller (recommended)
  458. i82527: Intel i82527 CAN controller
  459. mscan: Motorola/Freescale CAN controller (e.g. inside SOC MPC5200)
  460. ccan: CCAN controller core (e.g. inside SOC h7202)
  461. slcan: For a bunch of CAN adaptors that are attached via a
  462. serial line ASCII protocol (for serial / USB adaptors)
  463. Additionally the different CAN adaptors (ISA/PCI/PCMCIA/USB/Parport)
  464. from PEAK Systemtechnik support the CAN netdevice driver model
  465. since Linux driver v6.0: http://www.peak-system.com/linux/index.htm
  466. Please check the Mailing Lists on the berlios OSS project website.
  467. 6.5 todo (September 2007)
  468. The configuration interface for CAN network drivers is still an open
  469. issue that has not been finalized in the socketcan project. Also the
  470. idea of having a library module (candev.ko) that holds functions
  471. that are needed by all CAN netdevices is not ready to ship.
  472. Your contribution is welcome.
  473. 7. Credits
  474. ----------
  475. Oliver Hartkopp (PF_CAN core, filters, drivers, bcm)
  476. Urs Thuermann (PF_CAN core, kernel integration, socket interfaces, raw, vcan)
  477. Jan Kizka (RT-SocketCAN core, Socket-API reconciliation)
  478. Wolfgang Grandegger (RT-SocketCAN core & drivers, Raw Socket-API reviews)
  479. Robert Schwebel (design reviews, PTXdist integration)
  480. Marc Kleine-Budde (design reviews, Kernel 2.6 cleanups, drivers)
  481. Benedikt Spranger (reviews)
  482. Thomas Gleixner (LKML reviews, coding style, posting hints)
  483. Andrey Volkov (kernel subtree structure, ioctls, mscan driver)
  484. Matthias Brukner (first SJA1000 CAN netdevice implementation Q2/2003)
  485. Klaus Hitschler (PEAK driver integration)
  486. Uwe Koppe (CAN netdevices with PF_PACKET approach)
  487. Michael Schulze (driver layer loopback requirement, RT CAN drivers review)