sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget"/translations/zh_CN/networking/canmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/zh_TW/networking/canmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/it_IT/networking/canmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/ja_JP/networking/canmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/ko_KR/networking/canmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/sp_SP/networking/canmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(h#SocketCAN - Controller Area Networkh]h#SocketCAN - Controller Area Network}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhhhubh bullet_list)}(hhh](h list_item)}(h**Intricate usage:** Instead of passing a protocol argument to socket(2) and using bind(2) to select a CAN interface and CAN ID, an application would have to do all these operations using ioctl(2)s. h]h)}(h**Intricate usage:** Instead of passing a protocol argument to socket(2) and using bind(2) to select a CAN interface and CAN ID, an application would have to do all these operations using ioctl(2)s.h](hstrong)}(h**Intricate usage:**h]hIntricate usage:}(hj:hhhNhNubah}(h]h ]h"]h$]h&]uh1j8hj4ubh Instead of passing a protocol argument to socket(2) and using bind(2) to select a CAN interface and CAN ID, an application would have to do all these operations using ioctl(2)s.}(hj4hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKBhj0ubah}(h]h ]h"]h$]h&]uh1j.hj+hhhhhNubj/)}(h**Code duplication:** A character device cannot make use of the Linux network queueing code, so all that code would have to be duplicated for CAN networking. h]h)}(h**Code duplication:** A character device cannot make use of the Linux network queueing code, so all that code would have to be duplicated for CAN networking.h](j9)}(h**Code duplication:**h]hCode duplication:}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1j8hj\ubh A character device cannot make use of the Linux network queueing code, so all that code would have to be duplicated for CAN networking.}(hj\hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKFhjXubah}(h]h ]h"]h$]h&]uh1j.hj+hhhhhNubj/)}(hX**Abstraction:** In most existing character-device implementations, the hardware-specific device driver for a CAN controller directly provides the character device for the application to work with. This is at least very unusual in Unix systems for both, char and block devices. For example you don't have a character device for a certain UART of a serial interface, a certain sound chip in your computer, a SCSI or IDE controller providing access to your hard disk or tape streamer device. Instead, you have abstraction layers which provide a unified character or block device interface to the application on the one hand, and a interface for hardware-specific device drivers on the other hand. These abstractions are provided by subsystems like the tty layer, the audio subsystem or the SCSI and IDE subsystems for the devices mentioned above. The easiest way to implement a CAN device driver is as a character device without such a (complete) abstraction layer, as is done by most existing drivers. The right way, however, would be to add such a layer with all the functionality like registering for certain CAN IDs, supporting several open file descriptors and (de)multiplexing CAN frames between them, (sophisticated) queueing of CAN frames, and providing an API for device drivers to register with. However, then it would be no more difficult, or may be even easier, to use the networking framework provided by the Linux kernel, and this is what SocketCAN does. h](h)}(hXP**Abstraction:** In most existing character-device implementations, the hardware-specific device driver for a CAN controller directly provides the character device for the application to work with. This is at least very unusual in Unix systems for both, char and block devices. For example you don't have a character device for a certain UART of a serial interface, a certain sound chip in your computer, a SCSI or IDE controller providing access to your hard disk or tape streamer device. Instead, you have abstraction layers which provide a unified character or block device interface to the application on the one hand, and a interface for hardware-specific device drivers on the other hand. These abstractions are provided by subsystems like the tty layer, the audio subsystem or the SCSI and IDE subsystems for the devices mentioned above.h](j9)}(h**Abstraction:**h]h Abstraction:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j8hjubhXB In most existing character-device implementations, the hardware-specific device driver for a CAN controller directly provides the character device for the application to work with. This is at least very unusual in Unix systems for both, char and block devices. For example you don’t have a character device for a certain UART of a serial interface, a certain sound chip in your computer, a SCSI or IDE controller providing access to your hard disk or tape streamer device. Instead, you have abstraction layers which provide a unified character or block device interface to the application on the one hand, and a interface for hardware-specific device drivers on the other hand. These abstractions are provided by subsystems like the tty layer, the audio subsystem or the SCSI and IDE subsystems for the devices mentioned above.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKJhj~ubh)}(hXoThe easiest way to implement a CAN device driver is as a character device without such a (complete) abstraction layer, as is done by most existing drivers. The right way, however, would be to add such a layer with all the functionality like registering for certain CAN IDs, supporting several open file descriptors and (de)multiplexing CAN frames between them, (sophisticated) queueing of CAN frames, and providing an API for device drivers to register with. However, then it would be no more difficult, or may be even easier, to use the networking framework provided by the Linux kernel, and this is what SocketCAN does.h]hXoThe easiest way to implement a CAN device driver is as a character device without such a (complete) abstraction layer, as is done by most existing drivers. The right way, however, would be to add such a layer with all the functionality like registering for certain CAN IDs, supporting several open file descriptors and (de)multiplexing CAN frames between them, (sophisticated) queueing of CAN frames, and providing an API for device drivers to register with. However, then it would be no more difficult, or may be even easier, to use the networking framework provided by the Linux kernel, and this is what SocketCAN does.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKXhj~ubeh}(h]h ]h"]h$]h&]uh1j.hj+hhhhhNubeh}(h]h ]h"]h$]h&]bullet*uh1j)hhhKBhhhhubh)}(hThe use of the networking framework of the Linux kernel is just the natural and most appropriate way to implement CAN for Linux.h]hThe use of the networking framework of the Linux kernel is just the natural and most appropriate way to implement CAN for Linux.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKchhhhubh)}(h.. _socketcan-concept:h]h}(h]h ]h"]h$]h&]hsocketcan-conceptuh1hhKghhhhhhubeh}(h](#motivation-why-using-the-socket-apiheh ]h"](%motivation / why using the socket apisocketcan-motivationeh$]h&]uh1hhhhhhhhKexpect_referenced_by_name}jhsexpect_referenced_by_id}hhsubh)}(hhh](h)}(hSocketCAN Concepth]hSocketCAN Concept}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKjubh)}(hXjAs described in :ref:`socketcan-motivation` the main goal of SocketCAN is to provide a socket interface to user space applications which builds upon the Linux network layer. In contrast to the commonly known TCP/IP and ethernet networking, the CAN bus is a broadcast-only(!) medium that has no MAC-layer addressing like ethernet. The CAN-identifier (can_id) is used for arbitration on the CAN-bus. Therefore the CAN-IDs have to be chosen uniquely on the bus. When designing a CAN-ECU network the CAN-IDs are mapped to be sent by a specific ECU. For this reason a CAN-ID can be treated best as a kind of source address.h](hAs described in }(hjhhhNhNubh)}(h:ref:`socketcan-motivation`h]hinline)}(hjh]hsocketcan-motivation}(hjhhhNhNubah}(h]h ](xrefstdstd-refeh"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]refdocnetworking/can refdomainj reftyperef refexplicitrefwarn reftargetsocketcan-motivationuh1hhhhKlhjubhX? the main goal of SocketCAN is to provide a socket interface to user space applications which builds upon the Linux network layer. In contrast to the commonly known TCP/IP and ethernet networking, the CAN bus is a broadcast-only(!) medium that has no MAC-layer addressing like ethernet. The CAN-identifier (can_id) is used for arbitration on the CAN-bus. Therefore the CAN-IDs have to be chosen uniquely on the bus. When designing a CAN-ECU network the CAN-IDs are mapped to be sent by a specific ECU. For this reason a CAN-ID can be treated best as a kind of source address.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKlhjhhubh)}(h.. _socketcan-receive-lists:h]h}(h]h ]h"]h$]h&]hsocketcan-receive-listsuh1hhKwhjhhhhubh)}(hhh](h)}(h Receive Listsh]h Receive Lists}(hj6hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj3hhhhhKzubh)}(hXThe network transparent access of multiple applications leads to the problem that different applications may be interested in the same CAN-IDs from the same CAN network interface. The SocketCAN core module - which implements the protocol family CAN - provides several high efficient receive lists for this reason. If e.g. a user space application opens a CAN RAW socket, the raw protocol module itself requests the (range of) CAN-IDs from the SocketCAN core that are requested by the user. The subscription and unsubscription of CAN-IDs can be done for specific CAN interfaces or for all(!) known CAN interfaces with the can_rx_(un)register() functions provided to CAN protocol modules by the SocketCAN core (see :ref:`socketcan-core-module`). To optimize the CPU usage at runtime the receive lists are split up into several specific lists per device that match the requested filter complexity for a given use-case.h](hXThe network transparent access of multiple applications leads to the problem that different applications may be interested in the same CAN-IDs from the same CAN network interface. The SocketCAN core module - which implements the protocol family CAN - provides several high efficient receive lists for this reason. If e.g. a user space application opens a CAN RAW socket, the raw protocol module itself requests the (range of) CAN-IDs from the SocketCAN core that are requested by the user. The subscription and unsubscription of CAN-IDs can be done for specific CAN interfaces or for all(!) known CAN interfaces with the can_rx_(un)register() functions provided to CAN protocol modules by the SocketCAN core (see }(hjDhhhNhNubh)}(h:ref:`socketcan-core-module`h]j)}(hjNh]hsocketcan-core-module}(hjPhhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhjLubah}(h]h ]h"]h$]h&]refdocj refdomainjZreftyperef refexplicitrefwarnjsocketcan-core-moduleuh1hhhhK|hjDubh). To optimize the CPU usage at runtime the receive lists are split up into several specific lists per device that match the requested filter complexity for a given use-case.}(hjDhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK|hj3hhubh)}(h.. _socketcan-local-loopback1:h]h}(h]h ]h"]h$]h&]hsocketcan-local-loopback1uh1hhKhj3hhhhubeh}(h]( receive-listsj2eh ]h"]( receive listssocketcan-receive-listseh$]h&]uh1hhjhhhhhKzj}jj(sj}j2j(subh)}(hhh](h)}(hLocal Loopback of Sent Framesh]hLocal Loopback of Sent Frames}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hAs known from other networking concepts the data exchanging applications may run on the same or different nodes without any change (except for the according addressing information):h]hAs known from other networking concepts the data exchanging applications may run on the same or different nodes without any change (except for the according addressing information):}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh literal_block)}(hX( ___ ___ ___ _______ ___ | _ | | _ | | _ | | _ _ | | _ | ||A|| ||B|| ||C|| ||A| |B|| ||C|| |___| |___| |___| |_______| |___| | | | | | -----------------(1)- CAN bus -(2)---------------h]hX( ___ ___ ___ _______ ___ | _ | | _ | | _ | | _ _ | | _ | ||A|| ||B|| ||C|| ||A| |B|| ||C|| |___| |___| |___| |_______| |___| | | | | | -----------------(1)- CAN bus -(2)---------------}hjsbah}(h]h ]h"]h$]h&]forcehighlight_args} xml:spacepreservelanguagenoneuh1jhhhKhjhhubh)}(hTo ensure that application A receives the same information in the example (2) as it would receive in example (1) there is need for some kind of local loopback of the sent CAN frames on the appropriate node.h]hTo ensure that application A receives the same information in the example (2) as it would receive in example (1) there is need for some kind of local loopback of the sent CAN frames on the appropriate node.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXTThe Linux network devices (by default) just can handle the transmission and reception of media dependent frames. Due to the arbitration on the CAN bus the transmission of a low prio CAN-ID may be delayed by the reception of a high prio CAN frame. To reflect the correct [#f1]_ traffic on the node the loopback of the sent data has to be performed right after a successful transmission. If the CAN network interface is not capable of performing the loopback for some reason the SocketCAN core can do this task as a fallback solution. See :ref:`socketcan-local-loopback2` for details (recommended).h](hXThe Linux network devices (by default) just can handle the transmission and reception of media dependent frames. Due to the arbitration on the CAN bus the transmission of a low prio CAN-ID may be delayed by the reception of a high prio CAN frame. To reflect the correct }(hjhhhNhNubhfootnote_reference)}(h[#f1]_h]h1}(hjhhhNhNubah}(h]id2ah ]h"]h$]h&]autoKhf1docnamejuh1jhjresolvedKubhX traffic on the node the loopback of the sent data has to be performed right after a successful transmission. If the CAN network interface is not capable of performing the loopback for some reason the SocketCAN core can do this task as a fallback solution. See }(hjhhhNhNubh)}(h :ref:`socketcan-local-loopback2`h]j)}(hjh]hsocketcan-local-loopback2}(hjhhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]refdocj refdomainjreftyperef refexplicitrefwarnjsocketcan-local-loopback2uh1hhhhKhjubh for details (recommended).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hX)The loopback functionality is enabled by default to reflect standard networking behaviour for CAN applications. Due to some requests from the RT-SocketCAN group the loopback optionally may be disabled for each separate socket. See sockopts from the CAN RAW sockets in :ref:`socketcan-raw-sockets`.h](hX The loopback functionality is enabled by default to reflect standard networking behaviour for CAN applications. Due to some requests from the RT-SocketCAN group the loopback optionally may be disabled for each separate socket. See sockopts from the CAN RAW sockets in }(hjhhhNhNubh)}(h:ref:`socketcan-raw-sockets`h]j)}(hj%h]hsocketcan-raw-sockets}(hj'hhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhj#ubah}(h]h ]h"]h$]h&]refdocj refdomainj1reftyperef refexplicitrefwarnjsocketcan-raw-socketsuh1hhhhKhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubhfootnote)}(htyou really like to have this when you're running analyser tools like 'candump' or 'cansniffer' on the (same) node. h](hlabel)}(hhh]h1}(hjUhhhNhNubah}(h]h ]h"]h$]h&]uh1jShjOhhhNhNubh)}(hryou really like to have this when you're running analyser tools like 'candump' or 'cansniffer' on the (same) node.h]h|you really like to have this when you’re running analyser tools like ‘candump’ or ‘cansniffer’ on the (same) node.}(hjbhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjOubeh}(h]jah ]h"]f1ah$]h&]jajKjjuh1jMhhhKhjhhubh)}(h,.. _socketcan-network-problem-notifications:h]h}(h]h ]h"]h$]h&]h'socketcan-network-problem-notificationsuh1hhKhjhhhhubeh}(h](local-loopback-of-sent-framesjeh ]h"]socketcan-local-loopback1ah$]local loopback of sent framesah&]uh1hhjhhhhhK referencedKj}jjvsj}jjvsubh)}(hhh](h)}(hNetwork Problem Notificationsh]hNetwork Problem Notifications}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hXqThe use of the CAN bus may lead to several problems on the physical and media access control layer. Detecting and logging of these lower layer problems is a vital requirement for CAN users to identify hardware issues on the physical transceiver layer as well as arbitration problems and error frames caused by the different ECUs. The occurrence of detected errors are important for diagnosis and have to be logged together with the exact timestamp. For this reason the CAN interface driver can generate so called Error Message Frames that can optionally be passed to the user application in the same way as other CAN frames. Whenever an error on the physical layer or the MAC layer is detected (e.g. by the CAN controller) the driver creates an appropriate error message frame. Error messages frames can be requested by the user application using the common CAN filter mechanisms. Inside this filter definition the (interested) type of errors may be selected. The reception of error messages is disabled by default. The format of the CAN error message frame is briefly described in the Linux header file "include/uapi/linux/can/error.h".h]hXuThe use of the CAN bus may lead to several problems on the physical and media access control layer. Detecting and logging of these lower layer problems is a vital requirement for CAN users to identify hardware issues on the physical transceiver layer as well as arbitration problems and error frames caused by the different ECUs. The occurrence of detected errors are important for diagnosis and have to be logged together with the exact timestamp. For this reason the CAN interface driver can generate so called Error Message Frames that can optionally be passed to the user application in the same way as other CAN frames. Whenever an error on the physical layer or the MAC layer is detected (e.g. by the CAN controller) the driver creates an appropriate error message frame. Error messages frames can be requested by the user application using the common CAN filter mechanisms. Inside this filter definition the (interested) type of errors may be selected. The reception of error messages is disabled by default. The format of the CAN error message frame is briefly described in the Linux header file “include/uapi/linux/can/error.h”.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h](network-problem-notificationsjeh ]h"](network problem notifications'socketcan-network-problem-notificationseh$]h&]uh1hhjhhhhhKj}jjwsj}jjwsubeh}(h](jid1eh ]h"](socketcan conceptsocketcan-concepteh$]h&]uh1hhhhhhhhKjj}jjsj}jjsubh)}(hhh](h)}(hHow to use SocketCANh]hHow to use SocketCAN}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hXgLike TCP/IP, you first need to open a socket for communicating over a CAN network. Since SocketCAN implements a new protocol family, you need to pass PF_CAN as the first argument to the socket(2) system call. Currently, there are two CAN protocols to choose from, the raw socket protocol and the broadcast manager (BCM). So to open a socket, you would write::h]hXfLike TCP/IP, you first need to open a socket for communicating over a CAN network. Since SocketCAN implements a new protocol family, you need to pass PF_CAN as the first argument to the socket(2) system call. Currently, there are two CAN protocols to choose from, the raw socket protocol and the broadcast manager (BCM). So to open a socket, you would write:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(h&s = socket(PF_CAN, SOCK_RAW, CAN_RAW);h]h&s = socket(PF_CAN, SOCK_RAW, CAN_RAW);}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhKhjhhubh)}(hand::h]hand:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(h(s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM);h]h(s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM);}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhKhjhhubh)}(hXrespectively. After the successful creation of the socket, you would normally use the bind(2) system call to bind the socket to a CAN interface (which is different from TCP/IP due to different addressing - see :ref:`socketcan-concept`). After binding (CAN_RAW) or connecting (CAN_BCM) the socket, you can read(2) and write(2) from/to the socket or use send(2), sendto(2), sendmsg(2) and the recv* counterpart operations on the socket as usual. There are also CAN specific socket options described below.h](hrespectively. After the successful creation of the socket, you would normally use the bind(2) system call to bind the socket to a CAN interface (which is different from TCP/IP due to different addressing - see }(hj hhhNhNubh)}(h:ref:`socketcan-concept`h]j)}(hjh]hsocketcan-concept}(hjhhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]refdocj refdomainj"reftyperef refexplicitrefwarnjsocketcan-conceptuh1hhhhKhj ubhX ). After binding (CAN_RAW) or connecting (CAN_BCM) the socket, you can read(2) and write(2) from/to the socket or use send(2), sendto(2), sendmsg(2) and the recv* counterpart operations on the socket as usual. There are also CAN specific socket options described below.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hThe Classical CAN frame structure (aka CAN 2.0B), the CAN FD frame structure and the sockaddr structure are defined in include/linux/can.h:h]hThe Classical CAN frame structure (aka CAN 2.0B), the CAN FD frame structure and the sockaddr structure are defined in include/linux/can.h:}(hj>hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hXistruct can_frame { canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ union { /* CAN frame payload length in byte (0 .. CAN_MAX_DLEN) * was previously named can_dlc so we need to carry that * name for legacy support */ __u8 len; __u8 can_dlc; /* deprecated */ }; __u8 __pad; /* padding */ __u8 __res0; /* reserved / padding */ __u8 len8_dlc; /* optional DLC for 8 byte payload length (9 .. 15) */ __u8 data[8] __attribute__((aligned(8))); };h]hXistruct can_frame { canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ union { /* CAN frame payload length in byte (0 .. CAN_MAX_DLEN) * was previously named can_dlc so we need to carry that * name for legacy support */ __u8 len; __u8 can_dlc; /* deprecated */ }; __u8 __pad; /* padding */ __u8 __res0; /* reserved / padding */ __u8 len8_dlc; /* optional DLC for 8 byte payload length (9 .. 15) */ __u8 data[8] __attribute__((aligned(8))); };}hjLsbah}(h]h ]h"]h$]h&]jjforcejChighlight_args}uh1jhhhKhjhhubh)}(hRemark: The len element contains the payload length in bytes and should be used instead of can_dlc. The deprecated can_dlc was misleadingly named as it always contained the plain payload length in bytes and not the so called 'data length code' (DLC).h]hRemark: The len element contains the payload length in bytes and should be used instead of can_dlc. The deprecated can_dlc was misleadingly named as it always contained the plain payload length in bytes and not the so called ‘data length code’ (DLC).}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hTo pass the raw DLC from/to a Classical CAN network device the len8_dlc element can contain values 9 .. 15 when the len element is 8 (the real payload length for all DLC values greater or equal to 8).h]hTo pass the raw DLC from/to a Classical CAN network device the len8_dlc element can contain values 9 .. 15 when the len element is 8 (the real payload length for all DLC values greater or equal to 8).}(hjlhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hX*The alignment of the (linear) payload data[] to a 64bit boundary allows the user to define their own structs and unions to easily access the CAN payload. There is no given byteorder on the CAN bus by default. A read(2) system call on a CAN_RAW socket transfers a struct can_frame to the user space.h]hX*The alignment of the (linear) payload data[] to a 64bit boundary allows the user to define their own structs and unions to easily access the CAN payload. There is no given byteorder on the CAN bus by default. A read(2) system call on a CAN_RAW socket transfers a struct can_frame to the user space.}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(huThe sockaddr_can structure has an interface index like the PF_PACKET socket, that also binds to a specific interface:h]huThe sockaddr_can structure has an interface index like the PF_PACKET socket, that also binds to a specific interface:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjhhubj)}(hXwstruct sockaddr_can { sa_family_t can_family; int can_ifindex; union { /* transport protocol class address info (e.g. ISOTP) */ struct { canid_t rx_id, tx_id; } tp; /* J1939 address information */ struct { /* 8 byte name when using dynamic addressing */ __u64 name; /* pgn: * 8 bit: PS in PDU2 case, else 0 * 8 bit: PF * 1 bit: DP * 1 bit: reserved */ __u32 pgn; /* 1 byte address */ __u8 addr; } j1939; /* reserved for future CAN protocols address information */ } can_addr; };h]hXwstruct sockaddr_can { sa_family_t can_family; int can_ifindex; union { /* transport protocol class address info (e.g. ISOTP) */ struct { canid_t rx_id, tx_id; } tp; /* J1939 address information */ struct { /* 8 byte name when using dynamic addressing */ __u64 name; /* pgn: * 8 bit: PS in PDU2 case, else 0 * 8 bit: PF * 1 bit: DP * 1 bit: reserved */ __u32 pgn; /* 1 byte address */ __u8 addr; } j1939; /* reserved for future CAN protocols address information */ } can_addr; };}hjsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhjhhubh)}(h|To determine the interface index an appropriate ioctl() has to be used (example for CAN_RAW sockets without error checking):h]h|To determine the interface index an appropriate ioctl() has to be used (example for CAN_RAW sockets without error checking):}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM,hjhhubj)}(hXint s; struct sockaddr_can addr; struct ifreq ifr; s = socket(PF_CAN, SOCK_RAW, CAN_RAW); strcpy(ifr.ifr_name, "can0" ); ioctl(s, SIOCGIFINDEX, &ifr); addr.can_family = AF_CAN; addr.can_ifindex = ifr.ifr_ifindex; bind(s, (struct sockaddr *)&addr, sizeof(addr)); (..)h]hXint s; struct sockaddr_can addr; struct ifreq ifr; s = socket(PF_CAN, SOCK_RAW, CAN_RAW); strcpy(ifr.ifr_name, "can0" ); ioctl(s, SIOCGIFINDEX, &ifr); addr.can_family = AF_CAN; addr.can_ifindex = ifr.ifr_ifindex; bind(s, (struct sockaddr *)&addr, sizeof(addr)); (..)}hjsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhM/hjhhubh)}(hXpTo bind a socket to all(!) CAN interfaces the interface index must be 0 (zero). In this case the socket receives CAN frames from every enabled CAN interface. To determine the originating CAN interface the system call recvfrom(2) may be used instead of read(2). To send on a socket that is bound to 'any' interface sendto(2) is needed to specify the outgoing interface.h]hXtTo bind a socket to all(!) CAN interfaces the interface index must be 0 (zero). In this case the socket receives CAN frames from every enabled CAN interface. To determine the originating CAN interface the system call recvfrom(2) may be used instead of read(2). To send on a socket that is bound to ‘any’ interface sendto(2) is needed to specify the outgoing interface.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMAhjhhubh)}(hbReading CAN frames from a bound CAN_RAW socket (see above) consists of reading a struct can_frame:h]hbReading CAN frames from a bound CAN_RAW socket (see above) consists of reading a struct can_frame:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMHhjhhubj)}(hXZstruct can_frame frame; nbytes = read(s, &frame, sizeof(struct can_frame)); if (nbytes < 0) { perror("can raw socket read"); return 1; } /* paranoid check ... */ if (nbytes < sizeof(struct can_frame)) { fprintf(stderr, "read: incomplete CAN frame\n"); return 1; } /* do something with the received CAN frame */h]hXZstruct can_frame frame; nbytes = read(s, &frame, sizeof(struct can_frame)); if (nbytes < 0) { perror("can raw socket read"); return 1; } /* paranoid check ... */ if (nbytes < sizeof(struct can_frame)) { fprintf(stderr, "read: incomplete CAN frame\n"); return 1; } /* do something with the received CAN frame */}hjsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMKhjhhubh)}(hIWriting CAN frames can be done similarly, with the write(2) system call::h]hHWriting CAN frames can be done similarly, with the write(2) system call:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM^hjhhubj)}(h4nbytes = write(s, &frame, sizeof(struct can_frame));h]h4nbytes = write(s, &frame, sizeof(struct can_frame));}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhM`hjhhubh)}(hWhen the CAN interface is bound to 'any' existing CAN interface (addr.can_ifindex = 0) it is recommended to use recvfrom(2) if the information about the originating CAN interface is needed:h]hWhen the CAN interface is bound to ‘any’ existing CAN interface (addr.can_ifindex = 0) it is recommended to use recvfrom(2) if the information about the originating CAN interface is needed:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMbhjhhubj)}(hXstruct sockaddr_can addr; struct ifreq ifr; socklen_t len = sizeof(addr); struct can_frame frame; nbytes = recvfrom(s, &frame, sizeof(struct can_frame), 0, (struct sockaddr*)&addr, &len); /* get interface name of the received CAN frame */ ifr.ifr_ifindex = addr.can_ifindex; ioctl(s, SIOCGIFNAME, &ifr); printf("Received a CAN frame from interface %s", ifr.ifr_name);h]hXstruct sockaddr_can addr; struct ifreq ifr; socklen_t len = sizeof(addr); struct can_frame frame; nbytes = recvfrom(s, &frame, sizeof(struct can_frame), 0, (struct sockaddr*)&addr, &len); /* get interface name of the received CAN frame */ ifr.ifr_ifindex = addr.can_ifindex; ioctl(s, SIOCGIFNAME, &ifr); printf("Received a CAN frame from interface %s", ifr.ifr_name);}hjsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMfhjhhubh)}(hoTo write CAN frames on sockets bound to 'any' CAN interface the outgoing interface has to be defined certainly:h]hsTo write CAN frames on sockets bound to ‘any’ CAN interface the outgoing interface has to be defined certainly:}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMuhjhhubj)}(hstrcpy(ifr.ifr_name, "can0"); ioctl(s, SIOCGIFINDEX, &ifr); addr.can_ifindex = ifr.ifr_ifindex; addr.can_family = AF_CAN; nbytes = sendto(s, &frame, sizeof(struct can_frame), 0, (struct sockaddr*)&addr, sizeof(addr));h]hstrcpy(ifr.ifr_name, "can0"); ioctl(s, SIOCGIFINDEX, &ifr); addr.can_ifindex = ifr.ifr_ifindex; addr.can_family = AF_CAN; nbytes = sendto(s, &frame, sizeof(struct can_frame), 0, (struct sockaddr*)&addr, sizeof(addr));}hj4sbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMxhjhhubh)}(hdAn accurate timestamp can be obtained with an ioctl(2) call after reading a message from the socket:h]hdAn accurate timestamp can be obtained with an ioctl(2) call after reading a message from the socket:}(hjChhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h-struct timeval tv; ioctl(s, SIOCGSTAMP, &tv);h]h-struct timeval tv; ioctl(s, SIOCGSTAMP, &tv);}hjQsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhjhhubh)}(hkThe timestamp has a resolution of one microsecond and is set automatically at the reception of a CAN frame.h]hkThe timestamp has a resolution of one microsecond and is set automatically at the reception of a CAN frame.}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h1Remark about CAN FD (flexible data rate) support:h]h1Remark about CAN FD (flexible data rate) support:}(hjnhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXGenerally the handling of CAN FD is very similar to the formerly described examples. The new CAN FD capable CAN controllers support two different bitrates for the arbitration phase and the payload phase of the CAN FD frame and up to 64 bytes of payload. This extended payload length breaks all the kernel interfaces (ABI) which heavily rely on the CAN frame with fixed eight bytes of payload (struct can_frame) like the CAN_RAW socket. Therefore e.g. the CAN_RAW socket supports a new socket option CAN_RAW_FD_FRAMES that switches the socket into a mode that allows the handling of CAN FD frames and Classical CAN frames simultaneously (see :ref:`socketcan-rawfd`).h](hXGenerally the handling of CAN FD is very similar to the formerly described examples. The new CAN FD capable CAN controllers support two different bitrates for the arbitration phase and the payload phase of the CAN FD frame and up to 64 bytes of payload. This extended payload length breaks all the kernel interfaces (ABI) which heavily rely on the CAN frame with fixed eight bytes of payload (struct can_frame) like the CAN_RAW socket. Therefore e.g. the CAN_RAW socket supports a new socket option CAN_RAW_FD_FRAMES that switches the socket into a mode that allows the handling of CAN FD frames and Classical CAN frames simultaneously (see }(hj|hhhNhNubh)}(h:ref:`socketcan-rawfd`h]j)}(hjh]hsocketcan-rawfd}(hjhhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]refdocj refdomainjreftyperef refexplicitrefwarnjsocketcan-rawfduh1hhhhMhj|ubh).}(hj|hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h9The struct canfd_frame is defined in include/linux/can.h:h]h9The struct canfd_frame is defined in include/linux/can.h:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hXsstruct canfd_frame { canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ __u8 len; /* frame payload length in byte (0 .. 64) */ __u8 flags; /* additional flags for CAN FD */ __u8 __res0; /* reserved / padding */ __u8 __res1; /* reserved / padding */ __u8 data[64] __attribute__((aligned(8))); };h]hXsstruct canfd_frame { canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ __u8 len; /* frame payload length in byte (0 .. 64) */ __u8 flags; /* additional flags for CAN FD */ __u8 __res0; /* reserved / padding */ __u8 __res1; /* reserved / padding */ __u8 data[64] __attribute__((aligned(8))); };}hjsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhjhhubh)}(hXrThe struct canfd_frame and the existing struct can_frame have the can_id, the payload length and the payload data at the same offset inside their structures. This allows to handle the different structures very similar. When the content of a struct can_frame is copied into a struct canfd_frame all structure elements can be used as-is - only the data[] becomes extended.h]hXrThe struct canfd_frame and the existing struct can_frame have the can_id, the payload length and the payload data at the same offset inside their structures. This allows to handle the different structures very similar. When the content of a struct can_frame is copied into a struct canfd_frame all structure elements can be used as-is - only the data[] becomes extended.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXWWhen introducing the struct canfd_frame it turned out that the data length code (DLC) of the struct can_frame was used as a length information as the length and the DLC has a 1:1 mapping in the range of 0 .. 8. To preserve the easy handling of the length information the canfd_frame.len element contains a plain length value from 0 .. 64. So both canfd_frame.len and can_frame.len are equal and contain a length information and no DLC. For details about the distinction of CAN and CAN FD capable devices and the mapping to the bus-relevant data length code (DLC), see :ref:`socketcan-can-fd-driver`.h](hX8When introducing the struct canfd_frame it turned out that the data length code (DLC) of the struct can_frame was used as a length information as the length and the DLC has a 1:1 mapping in the range of 0 .. 8. To preserve the easy handling of the length information the canfd_frame.len element contains a plain length value from 0 .. 64. So both canfd_frame.len and can_frame.len are equal and contain a length information and no DLC. For details about the distinction of CAN and CAN FD capable devices and the mapping to the bus-relevant data length code (DLC), see }(hjhhhNhNubh)}(h:ref:`socketcan-can-fd-driver`h]j)}(hjh]hsocketcan-can-fd-driver}(hjhhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]refdocj refdomainjreftyperef refexplicitrefwarnjsocketcan-can-fd-driveruh1hhhhMhjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hThe length of the two CAN(FD) frame structures define the maximum transfer unit (MTU) of the CAN(FD) network interface and skbuff data length. Two definitions are specified for CAN specific MTUs in include/linux/can.h:h]hThe length of the two CAN(FD) frame structures define the maximum transfer unit (MTU) of the CAN(FD) network interface and skbuff data length. Two definitions are specified for CAN specific MTUs in include/linux/can.h:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h#define CAN_MTU (sizeof(struct can_frame)) == 16 => Classical CAN frame #define CANFD_MTU (sizeof(struct canfd_frame)) == 72 => CAN FD frameh]h#define CAN_MTU (sizeof(struct can_frame)) == 16 => Classical CAN frame #define CANFD_MTU (sizeof(struct canfd_frame)) == 72 => CAN FD frame}hjsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhjhhubh)}(hhh](h)}(hReturned Message Flagsh]hReturned Message Flags}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj(hhhhhMubh)}(hyWhen using the system call recvmsg(2) on a RAW or a BCM socket, the msg->msg_flags field may contain the following flags:h]hyWhen using the system call recvmsg(2) on a RAW or a BCM socket, the msg->msg_flags field may contain the following flags:}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj(hhubhdefinition_list)}(hhh](hdefinition_list_item)}(hJMSG_DONTROUTE: set when the received frame was created on the local host. h](hterm)}(hMSG_DONTROUTE:h]hMSG_DONTROUTE:}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMhjNubh definition)}(hhh]h)}(h:set when the received frame was created on the local host.h]h:set when the received frame was created on the local host.}(hjghhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjdubah}(h]h ]h"]h$]h&]uh1jbhjNubeh}(h]h ]h"]h$]h&]uh1jLhhhMhjIubjM)}(hXtMSG_CONFIRM: set when the frame was sent via the socket it is received on. This flag can be interpreted as a 'transmission confirmation' when the CAN driver supports the echo of frames on driver level, see :ref:`socketcan-local-loopback1` and :ref:`socketcan-local-loopback2`. (Note: In order to receive such messages on a RAW socket, CAN_RAW_RECV_OWN_MSGS must be set.) h](jS)}(h MSG_CONFIRM:h]h MSG_CONFIRM:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMhjubjc)}(hhh]h)}(hXeset when the frame was sent via the socket it is received on. This flag can be interpreted as a 'transmission confirmation' when the CAN driver supports the echo of frames on driver level, see :ref:`socketcan-local-loopback1` and :ref:`socketcan-local-loopback2`. (Note: In order to receive such messages on a RAW socket, CAN_RAW_RECV_OWN_MSGS must be set.)h](hset when the frame was sent via the socket it is received on. This flag can be interpreted as a ‘transmission confirmation’ when the CAN driver supports the echo of frames on driver level, see }(hjhhhNhNubh)}(h :ref:`socketcan-local-loopback1`h]j)}(hjh]hsocketcan-local-loopback1}(hjhhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]refdocj refdomainjreftyperef refexplicitrefwarnjsocketcan-local-loopback1uh1hhhhMhjubh and }(hjhhhNhNubh)}(h :ref:`socketcan-local-loopback2`h]j)}(hjh]hsocketcan-local-loopback2}(hjhhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]refdocj refdomainjreftyperef refexplicitrefwarnjsocketcan-local-loopback2uh1hhhhMhjubh_. (Note: In order to receive such messages on a RAW socket, CAN_RAW_RECV_OWN_MSGS must be set.)}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhMhjIhhubeh}(h]h ]h"]h$]h&]uh1jGhj(hhhhhNubh)}(h.. _socketcan-raw-sockets:h]h}(h]h ]h"]h$]h&]hsocketcan-raw-socketsuh1hhMhj(hhhhubeh}(h]returned-message-flagsah ]h"]returned message flagsah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h0RAW Protocol Sockets with can_filters (SOCK_RAW)h]h0RAW Protocol Sockets with can_filters (SOCK_RAW)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hUsing CAN_RAW sockets is extensively comparable to the commonly known access to CAN character devices. To meet the new possibilities provided by the multi user SocketCAN approach, some reasonable defaults are set at RAW socket binding time:h]hUsing CAN_RAW sockets is extensively comparable to the commonly known access to CAN character devices. To meet the new possibilities provided by the multi user SocketCAN approach, some reasonable defaults are set at RAW socket binding time:}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj*)}(hhh](j/)}(h>The filters are set to exactly one filter receiving everythingh]h)}(hj5h]h>The filters are set to exactly one filter receiving everything}(hj7hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj3ubah}(h]h ]h"]h$]h&]uh1j.hj0hhhhhNubj/)}(hGThe socket only receives valid data frames (=> no error message frames)h]h)}(hjLh]hGThe socket only receives valid data frames (=> no error message frames)}(hjNhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjJubah}(h]h ]h"]h$]h&]uh1j.hj0hhhhhNubj/)}(hQThe loopback of sent CAN frames is enabled (see :ref:`socketcan-local-loopback2`)h]h)}(hjch](h0The loopback of sent CAN frames is enabled (see }(hjehhhNhNubh)}(h :ref:`socketcan-local-loopback2`h]j)}(hjnh]hsocketcan-local-loopback2}(hjphhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhjlubah}(h]h ]h"]h$]h&]refdocj refdomainjzreftyperef refexplicitrefwarnjsocketcan-local-loopback2uh1hhhhMhjeubh)}(hjehhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjaubah}(h]h ]h"]h$]h&]uh1j.hj0hhhhhNubj/)}(hCThe socket does not receive its own sent frames (in loopback mode) h]h)}(hBThe socket does not receive its own sent frames (in loopback mode)h]hBThe socket does not receive its own sent frames (in loopback mode)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hj0hhhhhNubeh}(h]h ]h"]h$]h&]j-uh1j)hhhMhjhhubh)}(hThese default settings may be changed before or after binding the socket. To use the referenced definitions of the socket options for CAN_RAW sockets, include .h]hThese default settings may be changed before or after binding the socket. To use the referenced definitions of the socket options for CAN_RAW sockets, include .}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h.. _socketcan-rawfilter:h]h}(h]h ]h"]h$]h&]hsocketcan-rawfilteruh1hhMhjhhhhubh)}(hhh](h)}(h RAW socket option CAN_RAW_FILTERh]h RAW socket option CAN_RAW_FILTER}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hThe reception of CAN frames using CAN_RAW sockets can be controlled by defining 0 .. n filters with the CAN_RAW_FILTER socket option.h]hThe reception of CAN frames using CAN_RAW sockets can be controlled by defining 0 .. n filters with the CAN_RAW_FILTER socket option.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h;The CAN filter structure is defined in include/linux/can.h:h]h;The CAN filter structure is defined in include/linux/can.h:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hHstruct can_filter { canid_t can_id; canid_t can_mask; };h]hHstruct can_filter { canid_t can_id; canid_t can_mask; };}hjsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhjhhubh)}(hA filter matches, when:h]hA filter matches, when:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h) & mask == can_id & maskh]h) & mask == can_id & mask}hjsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhjhhubh)}(hX=which is analogous to known CAN controllers hardware filter semantics. The filter can be inverted in this semantic, when the CAN_INV_FILTER bit is set in can_id element of the can_filter structure. In contrast to CAN controller hardware filters the user may set 0 .. n receive filters for each open socket separately:h]hX=which is analogous to known CAN controllers hardware filter semantics. The filter can be inverted in this semantic, when the CAN_INV_FILTER bit is set in can_id element of the can_filter structure. In contrast to CAN controller hardware filters the user may set 0 .. n receive filters for each open socket separately:}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hstruct can_filter rfilter[2]; rfilter[0].can_id = 0x123; rfilter[0].can_mask = CAN_SFF_MASK; rfilter[1].can_id = 0x200; rfilter[1].can_mask = 0x700; setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));h]hstruct can_filter rfilter[2]; rfilter[0].can_id = 0x123; rfilter[0].can_mask = CAN_SFF_MASK; rfilter[1].can_id = 0x200; rfilter[1].can_mask = 0x700; setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));}hj;sbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhjhhubh)}(hFTo disable the reception of CAN frames on the selected CAN_RAW socket:h]hFTo disable the reception of CAN frames on the selected CAN_RAW socket:}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjhhubj)}(h4setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);h]h4setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);}hjXsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhjhhubh)}(hXTo set the filters to zero filters is quite obsolete as to not read data causes the raw socket to discard the received CAN frames. But having this 'send only' use-case we may remove the receive list in the Kernel to save a little (really a very little!) CPU usage.h]hX To set the filters to zero filters is quite obsolete as to not read data causes the raw socket to discard the received CAN frames. But having this ‘send only’ use-case we may remove the receive list in the Kernel to save a little (really a very little!) CPU usage.}(hjghhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hhh](h)}(hCAN Filter Usage Optimisationh]hCAN Filter Usage Optimisation}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjuhhhhhMubh)}(hX"The CAN filters are processed in per-device filter lists at CAN frame reception time. To reduce the number of checks that need to be performed while walking through the filter lists the CAN core provides an optimized filter handling when the filter subscription focusses on a single CAN ID.h]hX"The CAN filters are processed in per-device filter lists at CAN frame reception time. To reduce the number of checks that need to be performed while walking through the filter lists the CAN core provides an optimized filter handling when the filter subscription focusses on a single CAN ID.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjuhhubh)}(hXFor the possible 2048 SFF CAN identifiers the identifier is used as an index to access the corresponding subscription list without any further checks. For the 2^29 possible EFF CAN identifiers a 10 bit XOR folding is used as hash function to retrieve the EFF table index.h]hXFor the possible 2048 SFF CAN identifiers the identifier is used as an index to access the corresponding subscription list without any further checks. For the 2^29 possible EFF CAN identifiers a 10 bit XOR folding is used as hash function to retrieve the EFF table index.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjuhhubh)}(hXPTo benefit from the optimized filters for single CAN identifiers the CAN_SFF_MASK or CAN_EFF_MASK have to be set into can_filter.mask together with set CAN_EFF_FLAG and CAN_RTR_FLAG bits. A set CAN_EFF_FLAG bit in the can_filter.mask makes clear that it matters whether a SFF or EFF CAN ID is subscribed. E.g. in the example from above:h]hXPTo benefit from the optimized filters for single CAN identifiers the CAN_SFF_MASK or CAN_EFF_MASK have to be set into can_filter.mask together with set CAN_EFF_FLAG and CAN_RTR_FLAG bits. A set CAN_EFF_FLAG bit in the can_filter.mask makes clear that it matters whether a SFF or EFF CAN ID is subscribed. E.g. in the example from above:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM%hjuhhubj)}(h@rfilter[0].can_id = 0x123; rfilter[0].can_mask = CAN_SFF_MASK;h]h@rfilter[0].can_id = 0x123; rfilter[0].can_mask = CAN_SFF_MASK;}hjsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhM+hjuhhubh)}(hJboth SFF frames with CAN ID 0x123 and EFF frames with 0xXXXXX123 can pass.h]hJboth SFF frames with CAN ID 0x123 and EFF frames with 0xXXXXX123 can pass.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM0hjuhhubh)}(hTo filter for only 0x123 (SFF) and 0x12345678 (EFF) CAN identifiers the filter has to be defined in this way to benefit from the optimized filters:h]hTo filter for only 0x123 (SFF) and 0x12345678 (EFF) CAN identifiers the filter has to be defined in this way to benefit from the optimized filters:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM2hjuhhubj)}(hX<struct can_filter rfilter[2]; rfilter[0].can_id = 0x123; rfilter[0].can_mask = (CAN_EFF_FLAG | CAN_RTR_FLAG | CAN_SFF_MASK); rfilter[1].can_id = 0x12345678 | CAN_EFF_FLAG; rfilter[1].can_mask = (CAN_EFF_FLAG | CAN_RTR_FLAG | CAN_EFF_MASK); setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));h]hX<struct can_filter rfilter[2]; rfilter[0].can_id = 0x123; rfilter[0].can_mask = (CAN_EFF_FLAG | CAN_RTR_FLAG | CAN_SFF_MASK); rfilter[1].can_id = 0x12345678 | CAN_EFF_FLAG; rfilter[1].can_mask = (CAN_EFF_FLAG | CAN_RTR_FLAG | CAN_EFF_MASK); setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));}hjsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhM5hjuhhubeh}(h]can-filter-usage-optimisationah ]h"]can filter usage optimisationah$]h&]uh1hhjhhhhhMubeh}(h]( raw-socket-option-can-raw-filterjeh ]h"]( raw socket option can_raw_filtersocketcan-rawfiltereh$]h&]uh1hhjhhhhhMj}jjsj}jjsubh)}(hhh](h)}(h$RAW Socket Option CAN_RAW_ERR_FILTERh]h$RAW Socket Option CAN_RAW_ERR_FILTER}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMBubh)}(hXAs described in :ref:`socketcan-network-problem-notifications` the CAN interface driver can generate so called Error Message Frames that can optionally be passed to the user application in the same way as other CAN frames. The possible errors are divided into different error classes that may be filtered using the appropriate error mask. To register for every possible error condition CAN_ERR_MASK can be used as value for the error mask. The values for the error mask are defined in linux/can/error.h:h](hAs described in }(hj hhhNhNubh)}(h.:ref:`socketcan-network-problem-notifications`h]j)}(hj h]h'socketcan-network-problem-notifications}(hj hhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhj ubah}(h]h ]h"]h$]h&]refdocj refdomainj$ reftyperef refexplicitrefwarnj'socketcan-network-problem-notificationsuh1hhhhMDhj ubhX the CAN interface driver can generate so called Error Message Frames that can optionally be passed to the user application in the same way as other CAN frames. The possible errors are divided into different error classes that may be filtered using the appropriate error mask. To register for every possible error condition CAN_ERR_MASK can be used as value for the error mask. The values for the error mask are defined in linux/can/error.h:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMDhjhhubj)}(hcan_err_mask_t err_mask = ( CAN_ERR_TX_TIMEOUT | CAN_ERR_BUSOFF ); setsockopt(s, SOL_CAN_RAW, CAN_RAW_ERR_FILTER, &err_mask, sizeof(err_mask));h]hcan_err_mask_t err_mask = ( CAN_ERR_TX_TIMEOUT | CAN_ERR_BUSOFF ); setsockopt(s, SOL_CAN_RAW, CAN_RAW_ERR_FILTER, &err_mask, sizeof(err_mask));}hj@ sbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMLhjhhubeh}(h]$raw-socket-option-can-raw-err-filterah ]h"]$raw socket option can_raw_err_filterah$]h&]uh1hhjhhhhhMBubh)}(hhh](h)}(h"RAW Socket Option CAN_RAW_LOOPBACKh]h"RAW Socket Option CAN_RAW_LOOPBACK}(hjZ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjW hhhhhMUubh)}(hXTo meet multi user needs the local loopback is enabled by default (see :ref:`socketcan-local-loopback1` for details). But in some embedded use-cases (e.g. when only one application uses the CAN bus) this loopback functionality can be disabled (separately for each socket):h](hGTo meet multi user needs the local loopback is enabled by default (see }(hjh hhhNhNubh)}(h :ref:`socketcan-local-loopback1`h]j)}(hjr h]hsocketcan-local-loopback1}(hjt hhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhjp ubah}(h]h ]h"]h$]h&]refdocj refdomainj~ reftyperef refexplicitrefwarnjsocketcan-local-loopback1uh1hhhhMWhjh ubh for details). But in some embedded use-cases (e.g. when only one application uses the CAN bus) this loopback functionality can be disabled (separately for each socket):}(hjh hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMWhjW hhubj)}(hint loopback = 0; /* 0 = disabled, 1 = enabled (default) */ setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK, &loopback, sizeof(loopback));h]hint loopback = 0; /* 0 = disabled, 1 = enabled (default) */ setsockopt(s, SOL_CAN_RAW, CAN_RAW_LOOPBACK, &loopback, sizeof(loopback));}hj sbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhM\hjW hhubeh}(h]"raw-socket-option-can-raw-loopbackah ]h"]"raw socket option can_raw_loopbackah$]h&]uh1hhjhhhhhMUubh)}(hhh](h)}(h'RAW socket option CAN_RAW_RECV_OWN_MSGSh]h'RAW socket option CAN_RAW_RECV_OWN_MSGS}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMdubh)}(hXWhen the local loopback is enabled, all the sent CAN frames are looped back to the open CAN sockets that registered for the CAN frames' CAN-ID on this given interface to meet the multi user needs. The reception of the CAN frames on the same socket that was sending the CAN frame is assumed to be unwanted and therefore disabled by default. This default behaviour may be changed on demand:h]hXWhen the local loopback is enabled, all the sent CAN frames are looped back to the open CAN sockets that registered for the CAN frames’ CAN-ID on this given interface to meet the multi user needs. The reception of the CAN frames on the same socket that was sending the CAN frame is assumed to be unwanted and therefore disabled by default. This default behaviour may be changed on demand:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMfhj hhubj)}(hint recv_own_msgs = 1; /* 0 = disabled (default), 1 = enabled */ setsockopt(s, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS, &recv_own_msgs, sizeof(recv_own_msgs));h]hint recv_own_msgs = 1; /* 0 = disabled (default), 1 = enabled */ setsockopt(s, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS, &recv_own_msgs, sizeof(recv_own_msgs));}hj sbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMnhj hhubh)}(hNote that reception of a socket's own CAN frames are subject to the same filtering as other CAN frames (see :ref:`socketcan-rawfilter`).h](hnNote that reception of a socket’s own CAN frames are subject to the same filtering as other CAN frames (see }(hj hhhNhNubh)}(h:ref:`socketcan-rawfilter`h]j)}(hj h]hsocketcan-rawfilter}(hj hhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhj ubah}(h]h ]h"]h$]h&]refdocj refdomainj reftyperef refexplicitrefwarnjsocketcan-rawfilteruh1hhhhMuhj ubh).}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMuhj hhubh)}(h.. _socketcan-rawfd:h]h}(h]h ]h"]h$]h&]hsocketcan-rawfduh1hhMxhj hhhhubeh}(h]'raw-socket-option-can-raw-recv-own-msgsah ]h"]'raw socket option can_raw_recv_own_msgsah$]h&]uh1hhjhhhhhMdubh)}(hhh](h)}(h#RAW Socket Option CAN_RAW_FD_FRAMESh]h#RAW Socket Option CAN_RAW_FD_FRAMES}(hj' hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj$ hhhhhM{ubh)}(hXCAN FD support in CAN_RAW sockets can be enabled with a new socket option CAN_RAW_FD_FRAMES which is off by default. When the new socket option is not supported by the CAN_RAW socket (e.g. on older kernels), switching the CAN_RAW_FD_FRAMES option returns the error -ENOPROTOOPT.h]hXCAN FD support in CAN_RAW sockets can be enabled with a new socket option CAN_RAW_FD_FRAMES which is off by default. When the new socket option is not supported by the CAN_RAW socket (e.g. on older kernels), switching the CAN_RAW_FD_FRAMES option returns the error -ENOPROTOOPT.}(hj5 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM}hj$ hhubh)}(hOnce CAN_RAW_FD_FRAMES is enabled the application can send both CAN frames and CAN FD frames. OTOH the application has to handle CAN and CAN FD frames when reading from the socket:h]hOnce CAN_RAW_FD_FRAMES is enabled the application can send both CAN frames and CAN FD frames. OTOH the application has to handle CAN and CAN FD frames when reading from the socket:}(hjC hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj$ hhubj)}(h{CAN_RAW_FD_FRAMES enabled: CAN_MTU and CANFD_MTU are allowed CAN_RAW_FD_FRAMES disabled: only CAN_MTU is allowed (default)h]h{CAN_RAW_FD_FRAMES enabled: CAN_MTU and CANFD_MTU are allowed CAN_RAW_FD_FRAMES disabled: only CAN_MTU is allowed (default)}hjQ sbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhj$ hhubh)}(hExample:h]hExample:}(hj` hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj$ hhubj)}(hX[ remember: CANFD_MTU == sizeof(struct canfd_frame) ] struct canfd_frame cfd; nbytes = read(s, &cfd, CANFD_MTU); if (nbytes == CANFD_MTU) { printf("got CAN FD frame with length %d\n", cfd.len); /* cfd.flags contains valid data */ } else if (nbytes == CAN_MTU) { printf("got Classical CAN frame with length %d\n", cfd.len); /* cfd.flags is undefined */ } else { fprintf(stderr, "read: invalid CAN(FD) frame\n"); return 1; } /* the content can be handled independently from the received MTU size */ printf("can_id: %X data length: %d data: ", cfd.can_id, cfd.len); for (i = 0; i < cfd.len; i++) printf("%02X ", cfd.data[i]);h]hX[ remember: CANFD_MTU == sizeof(struct canfd_frame) ] struct canfd_frame cfd; nbytes = read(s, &cfd, CANFD_MTU); if (nbytes == CANFD_MTU) { printf("got CAN FD frame with length %d\n", cfd.len); /* cfd.flags contains valid data */ } else if (nbytes == CAN_MTU) { printf("got Classical CAN frame with length %d\n", cfd.len); /* cfd.flags is undefined */ } else { fprintf(stderr, "read: invalid CAN(FD) frame\n"); return 1; } /* the content can be handled independently from the received MTU size */ printf("can_id: %X data length: %d data: ", cfd.can_id, cfd.len); for (i = 0; i < cfd.len; i++) printf("%02X ", cfd.data[i]);}hjn sbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhj$ hhubh)}(hX@When reading with size CANFD_MTU only returns CAN_MTU bytes that have been received from the socket a Classical CAN frame has been read into the provided CAN FD structure. Note that the canfd_frame.flags data field is not specified in the struct can_frame and therefore it is only valid in CANFD_MTU sized CAN FD frames.h]hX@When reading with size CANFD_MTU only returns CAN_MTU bytes that have been received from the socket a Classical CAN frame has been read into the provided CAN FD structure. Note that the canfd_frame.flags data field is not specified in the struct can_frame and therefore it is only valid in CANFD_MTU sized CAN FD frames.}(hj} hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj$ hhubh)}(h-Implementation hint for new CAN applications:h]h-Implementation hint for new CAN applications:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj$ hhubh)}(hXTTo build a CAN FD aware application use struct canfd_frame as basic CAN data structure for CAN_RAW based applications. When the application is executed on an older Linux kernel and switching the CAN_RAW_FD_FRAMES socket option returns an error: No problem. You'll get Classical CAN frames or CAN FD frames and can process them the same way.h]hXVTo build a CAN FD aware application use struct canfd_frame as basic CAN data structure for CAN_RAW based applications. When the application is executed on an older Linux kernel and switching the CAN_RAW_FD_FRAMES socket option returns an error: No problem. You’ll get Classical CAN frames or CAN FD frames and can process them the same way.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj$ hhubh)}(hWhen sending to CAN devices make sure that the device is capable to handle CAN FD frames by checking if the device maximum transfer unit is CANFD_MTU. The CAN device MTU can be retrieved e.g. with a SIOCGIFMTU ioctl() syscall.h]hWhen sending to CAN devices make sure that the device is capable to handle CAN FD frames by checking if the device maximum transfer unit is CANFD_MTU. The CAN device MTU can be retrieved e.g. with a SIOCGIFMTU ioctl() syscall.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj$ hhubeh}(h](#raw-socket-option-can-raw-fd-framesj eh ]h"](#raw socket option can_raw_fd_framessocketcan-rawfdeh$]h&]uh1hhjhhhhhM{j}j j sj}j j subh)}(hhh](h)}(h&RAW socket option CAN_RAW_JOIN_FILTERSh]h&RAW socket option CAN_RAW_JOIN_FILTERS}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMubh)}(hXThe CAN_RAW socket can set multiple CAN identifier specific filters that lead to multiple filters in the af_can.c filter processing. These filters are independent from each other which leads to logical OR'ed filters when applied (see :ref:`socketcan-rawfilter`).h](hThe CAN_RAW socket can set multiple CAN identifier specific filters that lead to multiple filters in the af_can.c filter processing. These filters are independent from each other which leads to logical OR’ed filters when applied (see }(hj hhhNhNubh)}(h:ref:`socketcan-rawfilter`h]j)}(hj h]hsocketcan-rawfilter}(hj hhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhj ubah}(h]h ]h"]h$]h&]refdocj refdomainj reftyperef refexplicitrefwarnjsocketcan-rawfilteruh1hhhhMhj ubh).}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hThis socket option joins the given CAN filters in the way that only CAN frames are passed to user space that matched *all* given CAN filters. The semantic for the applied filters is therefore changed to a logical AND.h](huThis socket option joins the given CAN filters in the way that only CAN frames are passed to user space that matched }(hj hhhNhNubhemphasis)}(h*all*h]hall}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh_ given CAN filters. The semantic for the applied filters is therefore changed to a logical AND.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(hThis is useful especially when the filterset is a combination of filters where the CAN_INV_FILTER flag is set in order to notch single CAN IDs or CAN ID ranges from the incoming traffic.h]hThis is useful especially when the filterset is a combination of filters where the CAN_INV_FILTER flag is set in order to notch single CAN IDs or CAN ID ranges from the incoming traffic.}(hj% hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubeh}(h]&raw-socket-option-can-raw-join-filtersah ]h"]&raw socket option can_raw_join_filtersah$]h&]uh1hhjhhhhhMubeh}(h](.raw-protocol-sockets-with-can-filters-sock-rawjeh ]h"](0raw protocol sockets with can_filters (sock_raw)socketcan-raw-socketseh$]h&]uh1hhjhhhhhMj}jA jsj}jjsubh)}(hhh](h)}(h/Broadcast Manager Protocol Sockets (SOCK_DGRAM)h]h/Broadcast Manager Protocol Sockets (SOCK_DGRAM)}(hjI hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjF hhhhhMubh)}(hThe Broadcast Manager protocol provides a command based configuration interface to filter and send (e.g. cyclic) CAN messages in kernel space.h]hThe Broadcast Manager protocol provides a command based configuration interface to filter and send (e.g. cyclic) CAN messages in kernel space.}(hjW hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjF hhubh)}(hReceive filters can be used to down sample frequent messages; detect events such as message contents changes, packet length changes, and do time-out monitoring of received messages.h]hReceive filters can be used to down sample frequent messages; detect events such as message contents changes, packet length changes, and do time-out monitoring of received messages.}(hje hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjF hhubh)}(hPeriodic transmission tasks of CAN frames or a sequence of CAN frames can be created and modified at runtime; both the message content and the two possible transmit intervals can be altered.h]hPeriodic transmission tasks of CAN frames or a sequence of CAN frames can be created and modified at runtime; both the message content and the two possible transmit intervals can be altered.}(hjs hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjF hhubh)}(hXA BCM socket is not intended for sending individual CAN frames using the struct can_frame as known from the CAN_RAW socket. Instead a special BCM configuration message is defined. The basic BCM configuration message used to communicate with the broadcast manager and the available operations are defined in the linux/can/bcm.h include. The BCM message consists of a message header with a command ('opcode') followed by zero or more CAN frames. The broadcast manager sends responses to user space in the same form:h]hXA BCM socket is not intended for sending individual CAN frames using the struct can_frame as known from the CAN_RAW socket. Instead a special BCM configuration message is defined. The basic BCM configuration message used to communicate with the broadcast manager and the available operations are defined in the linux/can/bcm.h include. The BCM message consists of a message header with a command (‘opcode’) followed by zero or more CAN frames. The broadcast manager sends responses to user space in the same form:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjF hhubj)}(hXstruct bcm_msg_head { __u32 opcode; /* command */ __u32 flags; /* special flags */ __u32 count; /* run 'count' times with ival1 */ struct timeval ival1, ival2; /* count and subsequent interval */ canid_t can_id; /* unique can_id for task */ __u32 nframes; /* number of can_frames following */ struct can_frame frames[0]; };h]hXstruct bcm_msg_head { __u32 opcode; /* command */ __u32 flags; /* special flags */ __u32 count; /* run 'count' times with ival1 */ struct timeval ival1, ival2; /* count and subsequent interval */ canid_t can_id; /* unique can_id for task */ __u32 nframes; /* number of can_frames following */ struct can_frame frames[0]; };}hj sbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhjF hhubh)}(hThe aligned payload 'frames' uses the same basic CAN frame structure defined at the beginning of :ref:`socketcan-rawfd` and in the include/linux/can.h include. All messages to the broadcast manager from user space have this structure.h](heThe aligned payload ‘frames’ uses the same basic CAN frame structure defined at the beginning of }(hj hhhNhNubh)}(h:ref:`socketcan-rawfd`h]j)}(hj h]hsocketcan-rawfd}(hj hhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhj ubah}(h]h ]h"]h$]h&]refdocj refdomainj reftyperef refexplicitrefwarnjsocketcan-rawfduh1hhhhMhj ubhs and in the include/linux/can.h include. All messages to the broadcast manager from user space have this structure.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjF hhubh)}(hpNote a CAN_BCM socket must be connected instead of bound after socket creation (example without error checking):h]hpNote a CAN_BCM socket must be connected instead of bound after socket creation (example without error checking):}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjF hhubj)}(hXint s; struct sockaddr_can addr; struct ifreq ifr; s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM); strcpy(ifr.ifr_name, "can0"); ioctl(s, SIOCGIFINDEX, &ifr); addr.can_family = AF_CAN; addr.can_ifindex = ifr.ifr_ifindex; connect(s, (struct sockaddr *)&addr, sizeof(addr)); (..)h]hXint s; struct sockaddr_can addr; struct ifreq ifr; s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM); strcpy(ifr.ifr_name, "can0"); ioctl(s, SIOCGIFINDEX, &ifr); addr.can_family = AF_CAN; addr.can_ifindex = ifr.ifr_ifindex; connect(s, (struct sockaddr *)&addr, sizeof(addr)); (..)}hj sbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhjF hhubh)}(hXThe broadcast manager socket is able to handle any number of in flight transmissions or receive filters concurrently. The different RX/TX jobs are distinguished by the unique can_id in each BCM message. However additional CAN_BCM sockets are recommended to communicate on multiple CAN interfaces. When the broadcast manager socket is bound to 'any' CAN interface (=> the interface index is set to zero) the configured receive filters apply to any CAN interface unless the sendto() syscall is used to overrule the 'any' CAN interface index. When using recvfrom() instead of read() to retrieve BCM socket messages the originating CAN interface is provided in can_ifindex.h]hXThe broadcast manager socket is able to handle any number of in flight transmissions or receive filters concurrently. The different RX/TX jobs are distinguished by the unique can_id in each BCM message. However additional CAN_BCM sockets are recommended to communicate on multiple CAN interfaces. When the broadcast manager socket is bound to ‘any’ CAN interface (=> the interface index is set to zero) the configured receive filters apply to any CAN interface unless the sendto() syscall is used to overrule the ‘any’ CAN interface index. When using recvfrom() instead of read() to retrieve BCM socket messages the originating CAN interface is provided in can_ifindex.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjF hhubh)}(hhh](h)}(hBroadcast Manager Operationsh]hBroadcast Manager Operations}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMubh)}(hThe opcode defines the operation for the broadcast manager to carry out, or details the broadcast managers response to several events, including user requests.h]hThe opcode defines the operation for the broadcast manager to carry out, or details the broadcast managers response to several events, including user requests.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubh)}(h6Transmit Operations (user space to broadcast manager):h]h6Transmit Operations (user space to broadcast manager):}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubjH)}(hhh](jM)}(h-TX_SETUP: Create (cyclic) transmission task. h](jS)}(h TX_SETUP:h]h TX_SETUP:}(hj/ hhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMhj+ ubjc)}(hhh]h)}(h"Create (cyclic) transmission task.h]h"Create (cyclic) transmission task.}(hj@ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj= ubah}(h]h ]h"]h$]h&]uh1jbhj+ ubeh}(h]h ]h"]h$]h&]uh1jLhhhMhj( ubjM)}(hDTX_DELETE: Remove (cyclic) transmission task, requires only can_id. h](jS)}(h TX_DELETE:h]h TX_DELETE:}(hj^ hhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMhjZ ubjc)}(hhh]h)}(h8Remove (cyclic) transmission task, requires only can_id.h]h8Remove (cyclic) transmission task, requires only can_id.}(hjo hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjl ubah}(h]h ]h"]h$]h&]uh1jbhjZ ubeh}(h]h ]h"]h$]h&]uh1jLhhhMhj( hhubjM)}(hCTX_READ: Read properties of (cyclic) transmission task for can_id. h](jS)}(hTX_READ:h]hTX_READ:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhM hj ubjc)}(hhh]h)}(h9Read properties of (cyclic) transmission task for can_id.h]h9Read properties of (cyclic) transmission task for can_id.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj ubah}(h]h ]h"]h$]h&]uh1jbhj ubeh}(h]h ]h"]h$]h&]uh1jLhhhM hj( hhubjM)}(hTX_SEND: Send one CAN frame. h](jS)}(hTX_SEND:h]hTX_SEND:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhM#hj ubjc)}(hhh]h)}(hSend one CAN frame.h]hSend one CAN frame.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM#hj ubah}(h]h ]h"]h$]h&]uh1jbhj ubeh}(h]h ]h"]h$]h&]uh1jLhhhM#hj( hhubeh}(h]h ]h"]h$]h&]uh1jGhj hhhhhNubh)}(h5Transmit Responses (broadcast manager to user space):h]h5Transmit Responses (broadcast manager to user space):}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM%hj hhubjH)}(hhh](jM)}(hGTX_STATUS: Reply to TX_READ request (transmission task configuration). h](jS)}(h TX_STATUS:h]h TX_STATUS:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhM(hj ubjc)}(hhh]h)}(h;Reply to TX_READ request (transmission task configuration).h]h;Reply to TX_READ request (transmission task configuration).}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM(hj ubah}(h]h ]h"]h$]h&]uh1jbhj ubeh}(h]h ]h"]h$]h&]uh1jLhhhM(hj ubjM)}(hTX_EXPIRED: Notification when counter finishes sending at initial interval 'ival1'. Requires the TX_COUNTEVT flag to be set at TX_SETUP. h](jS)}(h TX_EXPIRED:h]h TX_EXPIRED:}(hj1 hhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhM,hj- ubjc)}(hhh]h)}(h|Notification when counter finishes sending at initial interval 'ival1'. Requires the TX_COUNTEVT flag to be set at TX_SETUP.h]hNotification when counter finishes sending at initial interval ‘ival1’. Requires the TX_COUNTEVT flag to be set at TX_SETUP.}(hjB hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM+hj? ubah}(h]h ]h"]h$]h&]uh1jbhj- ubeh}(h]h ]h"]h$]h&]uh1jLhhhM,hj hhubeh}(h]h ]h"]h$]h&]uh1jGhj hhhhhNubh)}(h5Receive Operations (user space to broadcast manager):h]h5Receive Operations (user space to broadcast manager):}(hjb hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM.hj hhubjH)}(hhh](jM)}(h1RX_SETUP: Create RX content filter subscription. h](jS)}(h RX_SETUP:h]h RX_SETUP:}(hjw hhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhM1hjs ubjc)}(hhh]h)}(h&Create RX content filter subscription.h]h&Create RX content filter subscription.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM1hj ubah}(h]h ]h"]h$]h&]uh1jbhjs ubeh}(h]h ]h"]h$]h&]uh1jLhhhM1hjp ubjM)}(hHRX_DELETE: Remove RX content filter subscription, requires only can_id. h](jS)}(h RX_DELETE:h]h RX_DELETE:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhM4hj ubjc)}(hhh]h)}(hCyclic message is detected to be absent (timer ival1 expired).h]h>Cyclic message is detected to be absent (timer ival1 expired).}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM?hjXubah}(h]h ]h"]h$]h&]uh1jbhjFubeh}(h]h ]h"]h$]h&]uh1jLhhhM?hjhhubjM)}(hRX_CHANGED: BCM message with updated CAN frame (detected content change). Sent on first message received or on receipt of revised CAN messages. h](jS)}(h RX_CHANGED:h]h RX_CHANGED:}(hjyhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMDhjuubjc)}(hhh]h)}(hBCM message with updated CAN frame (detected content change). Sent on first message received or on receipt of revised CAN messages.h]hBCM message with updated CAN frame (detected content change). Sent on first message received or on receipt of revised CAN messages.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMBhjubah}(h]h ]h"]h$]h&]uh1jbhjuubeh}(h]h ]h"]h$]h&]uh1jLhhhMDhjhhubeh}(h]h ]h"]h$]h&]uh1jGhj hhhhhNubeh}(h]broadcast-manager-operationsah ]h"]broadcast manager operationsah$]h&]uh1hhjF hhhhhMubh)}(hhh](h)}(hBroadcast Manager Message Flagsh]hBroadcast Manager Message Flags}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMGubh)}(hWhen sending a message to the broadcast manager the 'flags' element may contain the following flag definitions which influence the behaviour:h]hWhen sending a message to the broadcast manager the ‘flags’ element may contain the following flag definitions which influence the behaviour:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMIhjhhubjH)}(hhh](jM)}(h3SETTIMER: Set the values of ival1, ival2 and count h](jS)}(h SETTIMER:h]h SETTIMER:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMMhjubjc)}(hhh]h)}(h(Set the values of ival1, ival2 and counth]h(Set the values of ival1, ival2 and count}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMMhjubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhMMhjubjM)}(hSTARTTIMER: Start the timer with the actual values of ival1, ival2 and count. Starting the timer leads simultaneously to emit a CAN frame. h](jS)}(h STARTTIMER:h]h STARTTIMER:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMQhjubjc)}(hhh]h)}(h~Start the timer with the actual values of ival1, ival2 and count. Starting the timer leads simultaneously to emit a CAN frame.h]h~Start the timer with the actual values of ival1, ival2 and count. Starting the timer leads simultaneously to emit a CAN frame.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMPhjubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhMQhjhhubjM)}(h>TX_COUNTEVT: Create the message TX_EXPIRED when count expires h](jS)}(h TX_COUNTEVT:h]h TX_COUNTEVT:}(hj6hhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMThj2ubjc)}(hhh]h)}(h0Create the message TX_EXPIRED when count expiresh]h0Create the message TX_EXPIRED when count expires}(hjGhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMThjDubah}(h]h ]h"]h$]h&]uh1jbhj2ubeh}(h]h ]h"]h$]h&]uh1jLhhhMThjhhubjM)}(hETX_ANNOUNCE: A change of data by the process is emitted immediately. h](jS)}(h TX_ANNOUNCE:h]h TX_ANNOUNCE:}(hjehhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMWhjaubjc)}(hhh]h)}(h7A change of data by the process is emitted immediately.h]h7A change of data by the process is emitted immediately.}(hjvhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMWhjsubah}(h]h ]h"]h$]h&]uh1jbhjaubeh}(h]h ]h"]h$]h&]uh1jLhhhMWhjhhubjM)}(hXTX_CP_CAN_ID: Copies the can_id from the message header to each subsequent frame in frames. This is intended as usage simplification. For TX tasks the unique can_id from the message header may differ from the can_id(s) stored for transmission in the subsequent struct can_frame(s). h](jS)}(h TX_CP_CAN_ID:h]h TX_CP_CAN_ID:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhM]hjubjc)}(hhh]h)}(hX Copies the can_id from the message header to each subsequent frame in frames. This is intended as usage simplification. For TX tasks the unique can_id from the message header may differ from the can_id(s) stored for transmission in the subsequent struct can_frame(s).h]hX Copies the can_id from the message header to each subsequent frame in frames. This is intended as usage simplification. For TX tasks the unique can_id from the message header may differ from the can_id(s) stored for transmission in the subsequent struct can_frame(s).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMZhjubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhM]hjhhubjM)}(hFRX_FILTER_ID: Filter by can_id alone, no frames required (nframes=0). h](jS)}(h RX_FILTER_ID:h]h RX_FILTER_ID:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhM`hjubjc)}(hhh]h)}(h7Filter by can_id alone, no frames required (nframes=0).h]h7Filter by can_id alone, no frames required (nframes=0).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM`hjubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhM`hjhhubjM)}(h:RX_CHECK_DLC: A change of the DLC leads to an RX_CHANGED. h](jS)}(h RX_CHECK_DLC:h]h RX_CHECK_DLC:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMchjubjc)}(hhh]h)}(h+A change of the DLC leads to an RX_CHANGED.h]h+A change of the DLC leads to an RX_CHANGED.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMchjubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhMchjhhubjM)}(hERX_NO_AUTOTIMER: Prevent automatically starting the timeout monitor. h](jS)}(hRX_NO_AUTOTIMER:h]hRX_NO_AUTOTIMER:}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMfhjubjc)}(hhh]h)}(h3Prevent automatically starting the timeout monitor.h]h3Prevent automatically starting the timeout monitor.}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMfhj/ubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhMfhjhhubjM)}(hRX_ANNOUNCE_RESUME: If passed at RX_SETUP and a receive timeout occurred, a RX_CHANGED message will be generated when the (cyclic) receive restarts. h](jS)}(hRX_ANNOUNCE_RESUME:h]hRX_ANNOUNCE_RESUME:}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMjhjLubjc)}(hhh]h)}(hIf passed at RX_SETUP and a receive timeout occurred, a RX_CHANGED message will be generated when the (cyclic) receive restarts.h]hIf passed at RX_SETUP and a receive timeout occurred, a RX_CHANGED message will be generated when the (cyclic) receive restarts.}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMihj^ubah}(h]h ]h"]h$]h&]uh1jbhjLubeh}(h]h ]h"]h$]h&]uh1jLhhhMjhjhhubjM)}(hITX_RESET_MULTI_IDX: Reset the index for the multiple frame transmission. h](jS)}(hTX_RESET_MULTI_IDX:h]hTX_RESET_MULTI_IDX:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMmhj{ubjc)}(hhh]h)}(h4Reset the index for the multiple frame transmission.h]h4Reset the index for the multiple frame transmission.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMmhjubah}(h]h ]h"]h$]h&]uh1jbhj{ubeh}(h]h ]h"]h$]h&]uh1jLhhhMmhjhhubjM)}(hDRX_RTR_FRAME: Send reply for RTR-request (placed in op->frames[0]). h](jS)}(h RX_RTR_FRAME:h]h RX_RTR_FRAME:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMphjubjc)}(hhh]h)}(h5Send reply for RTR-request (placed in op->frames[0]).h]h5Send reply for RTR-request (placed in op->frames[0]).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMphjubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhMphjhhubjM)}(hQCAN_FD_FRAME: The CAN frames following the bcm_msg_head are struct canfd_frame's h](jS)}(h CAN_FD_FRAME:h]h CAN_FD_FRAME:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMshjubjc)}(hhh]h)}(hBThe CAN frames following the bcm_msg_head are struct canfd_frame'sh]hDThe CAN frames following the bcm_msg_head are struct canfd_frame’s}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMshjubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhMshjhhubeh}(h]h ]h"]h$]h&]uh1jGhjhhhhhNubeh}(h]broadcast-manager-message-flagsah ]h"]broadcast manager message flagsah$]h&]uh1hhjF hhhhhMGubh)}(hhh](h)}(h%Broadcast Manager Transmission Timersh]h%Broadcast Manager Transmission Timers}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMvubh)}(hXPeriodic transmission configurations may use up to two interval timers. In this case the BCM sends a number of messages ('count') at an interval 'ival1', then continuing to send at another given interval 'ival2'. When only one timer is needed 'count' is set to zero and only 'ival2' is used. When SET_TIMER and START_TIMER flag were set the timers are activated. The timer values can be altered at runtime when only SET_TIMER is set.h]hXPeriodic transmission configurations may use up to two interval timers. In this case the BCM sends a number of messages (‘count’) at an interval ‘ival1’, then continuing to send at another given interval ‘ival2’. When only one timer is needed ‘count’ is set to zero and only ‘ival2’ is used. When SET_TIMER and START_TIMER flag were set the timers are activated. The timer values can be altered at runtime when only SET_TIMER is set.}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMxhjhhubeh}(h]%broadcast-manager-transmission-timersah ]h"]%broadcast manager transmission timersah$]h&]uh1hhjF hhhhhMvubh)}(hhh](h)}(h/Broadcast Manager message sequence transmissionh]h/Broadcast Manager message sequence transmission}(hj@hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj=hhhhhMubh)}(hXUp to 256 CAN frames can be transmitted in a sequence in the case of a cyclic TX task configuration. The number of CAN frames is provided in the 'nframes' element of the BCM message head. The defined number of CAN frames are added as array to the TX_SETUP BCM configuration message:h]hXUp to 256 CAN frames can be transmitted in a sequence in the case of a cyclic TX task configuration. The number of CAN frames is provided in the ‘nframes’ element of the BCM message head. The defined number of CAN frames are added as array to the TX_SETUP BCM configuration message:}(hjNhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj=hhubj)}(h/* create a struct to set up a sequence of four CAN frames */ struct { struct bcm_msg_head msg_head; struct can_frame frame[4]; } mytxmsg; (..) mytxmsg.msg_head.nframes = 4; (..) write(s, &mytxmsg, sizeof(mytxmsg));h]h/* create a struct to set up a sequence of four CAN frames */ struct { struct bcm_msg_head msg_head; struct can_frame frame[4]; } mytxmsg; (..) mytxmsg.msg_head.nframes = 4; (..) write(s, &mytxmsg, sizeof(mytxmsg));}hj\sbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhj=hhubh)}(hlWith every transmission the index in the array of CAN frames is increased and set to zero at index overflow.h]hlWith every transmission the index in the array of CAN frames is increased and set to zero at index overflow.}(hjkhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj=hhubeh}(h]/broadcast-manager-message-sequence-transmissionah ]h"]/broadcast manager message sequence transmissionah$]h&]uh1hhjF hhhhhMubh)}(hhh](h)}(h'Broadcast Manager Receive Filter Timersh]h'Broadcast Manager Receive Filter Timers}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hThe timer values ival1 or ival2 may be set to non-zero values at RX_SETUP. When the SET_TIMER flag is set the timers are enabled:h]hThe timer values ival1 or ival2 may be set to non-zero values at RX_SETUP. When the SET_TIMER flag is set the timers are enabled:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubjH)}(hhh](jM)}(hival1: Send RX_TIMEOUT when a received message is not received again within the given time. When START_TIMER is set at RX_SETUP the timeout detection is activated directly - even without a former CAN frame reception. h](jS)}(hival1:h]hival1:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMhjubjc)}(hhh]h)}(hSend RX_TIMEOUT when a received message is not received again within the given time. When START_TIMER is set at RX_SETUP the timeout detection is activated directly - even without a former CAN frame reception.h]hSend RX_TIMEOUT when a received message is not received again within the given time. When START_TIMER is set at RX_SETUP the timeout detection is activated directly - even without a former CAN frame reception.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhMhjubjM)}(hival2: Throttle the received message rate down to the value of ival2. This is useful to reduce messages for the application when the signal inside the CAN frame is stateless as state changes within the ival2 period may get lost. h](jS)}(hival2:h]hival2:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMhjubjc)}(hhh]h)}(hThrottle the received message rate down to the value of ival2. This is useful to reduce messages for the application when the signal inside the CAN frame is stateless as state changes within the ival2 period may get lost.h]hThrottle the received message rate down to the value of ival2. This is useful to reduce messages for the application when the signal inside the CAN frame is stateless as state changes within the ival2 period may get lost.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhMhjhhubeh}(h]h ]h"]h$]h&]uh1jGhjhhhhhNubeh}(h]'broadcast-manager-receive-filter-timersah ]h"]'broadcast manager receive filter timersah$]h&]uh1hhjF hhhhhMubh)}(hhh](h)}(h2Broadcast Manager Multiplex Message Receive Filterh]h2Broadcast Manager Multiplex Message Receive Filter}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hXSTo filter for content changes in multiplex message sequences an array of more than one CAN frames can be passed in a RX_SETUP configuration message. The data bytes of the first CAN frame contain the mask of relevant bits that have to match in the subsequent CAN frames with the received CAN frame. If one of the subsequent CAN frames is matching the bits in that frame data mark the relevant content to be compared with the previous received content. Up to 257 CAN frames (multiplex filter bit mask CAN frame plus 256 CAN filters) can be added as array to the TX_SETUP BCM configuration message:h]hXSTo filter for content changes in multiplex message sequences an array of more than one CAN frames can be passed in a RX_SETUP configuration message. The data bytes of the first CAN frame contain the mask of relevant bits that have to match in the subsequent CAN frames with the received CAN frame. If one of the subsequent CAN frames is matching the bits in that frame data mark the relevant content to be compared with the previous received content. Up to 257 CAN frames (multiplex filter bit mask CAN frame plus 256 CAN filters) can be added as array to the TX_SETUP BCM configuration message:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hX/* usually used to clear CAN frame data[] - beware of endian problems! */ #define U64_DATA(p) (*(unsigned long long*)(p)->data) struct { struct bcm_msg_head msg_head; struct can_frame frame[5]; } msg; msg.msg_head.opcode = RX_SETUP; msg.msg_head.can_id = 0x42; msg.msg_head.flags = 0; msg.msg_head.nframes = 5; U64_DATA(&msg.frame[0]) = 0xFF00000000000000ULL; /* MUX mask */ U64_DATA(&msg.frame[1]) = 0x01000000000000FFULL; /* data mask (MUX 0x01) */ U64_DATA(&msg.frame[2]) = 0x0200FFFF000000FFULL; /* data mask (MUX 0x02) */ U64_DATA(&msg.frame[3]) = 0x330000FFFFFF0003ULL; /* data mask (MUX 0x33) */ U64_DATA(&msg.frame[4]) = 0x4F07FC0FF0000000ULL; /* data mask (MUX 0x4F) */ write(s, &msg, sizeof(msg));h]hX/* usually used to clear CAN frame data[] - beware of endian problems! */ #define U64_DATA(p) (*(unsigned long long*)(p)->data) struct { struct bcm_msg_head msg_head; struct can_frame frame[5]; } msg; msg.msg_head.opcode = RX_SETUP; msg.msg_head.can_id = 0x42; msg.msg_head.flags = 0; msg.msg_head.nframes = 5; U64_DATA(&msg.frame[0]) = 0xFF00000000000000ULL; /* MUX mask */ U64_DATA(&msg.frame[1]) = 0x01000000000000FFULL; /* data mask (MUX 0x01) */ U64_DATA(&msg.frame[2]) = 0x0200FFFF000000FFULL; /* data mask (MUX 0x02) */ U64_DATA(&msg.frame[3]) = 0x330000FFFFFF0003ULL; /* data mask (MUX 0x33) */ U64_DATA(&msg.frame[4]) = 0x4F07FC0FF0000000ULL; /* data mask (MUX 0x4F) */ write(s, &msg, sizeof(msg));}hj.sbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhjhhubeh}(h]2broadcast-manager-multiplex-message-receive-filterah ]h"]2broadcast manager multiplex message receive filterah$]h&]uh1hhjF hhhhhMubh)}(hhh](h)}(h Broadcast Manager CAN FD Supporth]h Broadcast Manager CAN FD Support}(hjHhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjEhhhhhMubh)}(hXRThe programming API of the CAN_BCM depends on struct can_frame which is given as array directly behind the bcm_msg_head structure. To follow this schema for the CAN FD frames a new flag 'CAN_FD_FRAME' in the bcm_msg_head flags indicates that the concatenated CAN frame structures behind the bcm_msg_head are defined as struct canfd_frame:h]hXVThe programming API of the CAN_BCM depends on struct can_frame which is given as array directly behind the bcm_msg_head structure. To follow this schema for the CAN FD frames a new flag ‘CAN_FD_FRAME’ in the bcm_msg_head flags indicates that the concatenated CAN frame structures behind the bcm_msg_head are defined as struct canfd_frame:}(hjVhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjEhhubj)}(hstruct { struct bcm_msg_head msg_head; struct canfd_frame frame[5]; } msg; msg.msg_head.opcode = RX_SETUP; msg.msg_head.can_id = 0x42; msg.msg_head.flags = CAN_FD_FRAME; msg.msg_head.nframes = 5; (..)h]hstruct { struct bcm_msg_head msg_head; struct canfd_frame frame[5]; } msg; msg.msg_head.opcode = RX_SETUP; msg.msg_head.can_id = 0x42; msg.msg_head.flags = CAN_FD_FRAME; msg.msg_head.nframes = 5; (..)}hjdsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMhjEhhubh)}(hWhen using CAN FD frames for multiplex filtering the MUX mask is still expected in the first 64 bit of the struct canfd_frame data section.h]hWhen using CAN FD frames for multiplex filtering the MUX mask is still expected in the first 64 bit of the struct canfd_frame data section.}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjEhhubeh}(h] broadcast-manager-can-fd-supportah ]h"] broadcast manager can fd supportah$]h&]uh1hhjF hhhhhMubeh}(h]-broadcast-manager-protocol-sockets-sock-dgramah ]h"]/broadcast manager protocol sockets (sock_dgram)ah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h.Connected Transport Protocols (SOCK_SEQPACKET)h]h.Connected Transport Protocols (SOCK_SEQPACKET)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(h(to be written)h]h(to be written)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h],connected-transport-protocols-sock-seqpacketah ]h"].connected transport protocols (sock_seqpacket)ah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h,Unconnected Transport Protocols (SOCK_DGRAM)h]h,Unconnected Transport Protocols (SOCK_DGRAM)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(h(to be written)h]h(to be written)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h.. _socketcan-core-module:h]h}(h]h ]h"]h$]h&]hsocketcan-core-moduleuh1hhMhjhhhhubeh}(h]*unconnected-transport-protocols-sock-dgramah ]h"],unconnected transport protocols (sock_dgram)ah$]h&]uh1hhjhhhhhMubeh}(h]how-to-use-socketcanah ]h"]how to use socketcanah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hSocketCAN Core Moduleh]hSocketCAN Core Module}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hXThe SocketCAN core module implements the protocol family PF_CAN. CAN protocol modules are loaded by the core module at runtime. The core module provides an interface for CAN protocol modules to subscribe needed CAN IDs (see :ref:`socketcan-receive-lists`).h](hThe SocketCAN core module implements the protocol family PF_CAN. CAN protocol modules are loaded by the core module at runtime. The core module provides an interface for CAN protocol modules to subscribe needed CAN IDs (see }(hjhhhNhNubh)}(h:ref:`socketcan-receive-lists`h]j)}(hj h]hsocketcan-receive-lists}(hjhhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhj ubah}(h]h ]h"]h$]h&]refdocj refdomainjreftyperef refexplicitrefwarnjsocketcan-receive-listsuh1hhhhMhjubh).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hhh](h)}(hcan.ko Module Paramsh]hcan.ko Module Params}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj5hhhhhMubj*)}(hhh](j/)}(h**stats_timer**: To calculate the SocketCAN core statistics (e.g. current/maximum frames per second) this 1 second timer is invoked at can.ko module start time by default. This timer can be disabled by using stattimer=0 on the module commandline. h]h)}(h**stats_timer**: To calculate the SocketCAN core statistics (e.g. current/maximum frames per second) this 1 second timer is invoked at can.ko module start time by default. This timer can be disabled by using stattimer=0 on the module commandline.h](j9)}(h**stats_timer**h]h stats_timer}(hjQhhhNhNubah}(h]h ]h"]h$]h&]uh1j8hjMubh: To calculate the SocketCAN core statistics (e.g. current/maximum frames per second) this 1 second timer is invoked at can.ko module start time by default. This timer can be disabled by using stattimer=0 on the module commandline.}(hjMhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjIubah}(h]h ]h"]h$]h&]uh1j.hjFhhhhhNubj/)}(h/**debug**: (removed since SocketCAN SVN r546) h]h)}(h-**debug**: (removed since SocketCAN SVN r546)h](j9)}(h **debug**h]hdebug}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1j8hjsubh$: (removed since SocketCAN SVN r546)}(hjshhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjoubah}(h]h ]h"]h$]h&]uh1j.hjFhhhhhNubeh}(h]h ]h"]h$]h&]jjuh1j)hhhMhj5hhubeh}(h]can-ko-module-paramsah ]h"]can.ko module paramsah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(hprocfs contenth]hprocfs content}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhM ubh)}(hXHAs described in :ref:`socketcan-receive-lists` the SocketCAN core uses several filter lists to deliver received CAN frames to CAN protocol modules. These receive lists, their filters and the count of filter matches can be checked in the appropriate receive list. All entries contain the device and a protocol module identifier::h](hAs described in }(hjhhhNhNubh)}(h:ref:`socketcan-receive-lists`h]j)}(hjh]hsocketcan-receive-lists}(hjhhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]refdocj refdomainjreftyperef refexplicitrefwarnjsocketcan-receive-listsuh1hhhhMhjubhX the SocketCAN core uses several filter lists to deliver received CAN frames to CAN protocol modules. These receive lists, their filters and the count of filter matches can be checked in the appropriate receive list. All entries contain the device and a protocol module identifier:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hXfoo@bar:~$ cat /proc/net/can/rcvlist_all receive list 'rx_all': (vcan3: no entry) (vcan2: no entry) (vcan1: no entry) device can_id can_mask function userdata matches ident vcan0 000 00000000 f88e6370 f6c6f400 0 raw (any: no entry)h]hXfoo@bar:~$ cat /proc/net/can/rcvlist_all receive list 'rx_all': (vcan3: no entry) (vcan2: no entry) (vcan1: no entry) device can_id can_mask function userdata matches ident vcan0 000 00000000 f88e6370 f6c6f400 0 raw (any: no entry)}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(hDIn this example an application requests any CAN traffic from vcan0::h]hCIn this example an application requests any CAN traffic from vcan0:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hXOrcvlist_all - list for unfiltered entries (no filter operations) rcvlist_eff - list for single extended frame (EFF) entries rcvlist_err - list for error message frames masks rcvlist_fil - list for mask/value filters rcvlist_inv - list for mask/value filters (inverse semantic) rcvlist_sff - list for single standard frame (SFF) entriesh]hXOrcvlist_all - list for unfiltered entries (no filter operations) rcvlist_eff - list for single extended frame (EFF) entries rcvlist_err - list for error message frames masks rcvlist_fil - list for mask/value filters rcvlist_inv - list for mask/value filters (inverse semantic) rcvlist_sff - list for single standard frame (SFF) entries}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhM!hjhhubh)}(h*Additional procfs files in /proc/net/can::h]h)Additional procfs files in /proc/net/can:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM(hjhhubj)}(hstats - SocketCAN core statistics (rx/tx frames, match ratios, ...) reset_stats - manual statistic reset version - prints SocketCAN core and ABI version (removed in Linux 5.10)h]hstats - SocketCAN core statistics (rx/tx frames, match ratios, ...) reset_stats - manual statistic reset version - prints SocketCAN core and ABI version (removed in Linux 5.10)}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhM*hjhhubeh}(h]procfs-contentah ]h"]procfs contentah$]h&]uh1hhjhhhhhM ubh)}(hhh](h)}(h Writing Own CAN Protocol Modulesh]h Writing Own CAN Protocol Modules}(hj7hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj4hhhhhM0ubh)}(hXTo 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::h]hXTo 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:}(hjEhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM2hj4hhubj)}(hcan_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)h]hcan_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)}hjSsbah}(h]h ]h"]h$]h&]jjuh1jhhhM:hj4hhubh)}(hvFor 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 .h]hvFor 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 .}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM>hj4hhubeh}(h] writing-own-can-protocol-modulesah ]h"] writing own can protocol modulesah$]h&]uh1hhjhhhhhM0ubeh}(h](jid3eh ]h"](socketcan core modulesocketcan-core-moduleeh$]h&]uh1hhhhhhhhMj}j}jsj}jjsubh)}(hhh](h)}(hCAN Network Driversh]hCAN Network Drivers}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMCubh)}(hWriting a CAN network device driver is much easier than writing a CAN character device driver. Similar to other known network device drivers you mainly have to deal with:h]hWriting a CAN network device driver is much easier than writing a CAN character device driver. Similar to other known network device drivers you mainly have to deal with:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMEhjhhubj*)}(hhh](j/)}(hCTX: Put the CAN frame from the socket buffer to the CAN controller.h]h)}(hjh]hCTX: Put the CAN frame from the socket buffer to the CAN controller.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMIhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(hDRX: Put the CAN frame from the CAN controller to the socket buffer. h]h)}(hCRX: Put the CAN frame from the CAN controller to the socket buffer.h]hCRX: Put the CAN frame from the CAN controller to the socket buffer.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMJhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubeh}(h]h ]h"]h$]h&]jjuh1j)hhhMIhjhhubh)}(hSee e.g. at Documentation/networking/netdevices.rst . The differences for writing CAN network device driver are described below:h]hSee e.g. at Documentation/networking/netdevices.rst . The differences for writing CAN network device driver are described below:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMLhjhhubh)}(hhh](h)}(hGeneral Settingsh]hGeneral Settings}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMQubj)}(hXMdev->type = ARPHRD_CAN; /* the netdevice hardware type */ dev->flags = IFF_NOARP; /* CAN has no arp */ dev->mtu = CAN_MTU; /* sizeof(struct can_frame) -> Classical CAN interface */ or alternative, when the controller supports CAN with flexible data rate: dev->mtu = CANFD_MTU; /* sizeof(struct canfd_frame) -> CAN FD interface */h]hXMdev->type = ARPHRD_CAN; /* the netdevice hardware type */ dev->flags = IFF_NOARP; /* CAN has no arp */ dev->mtu = CAN_MTU; /* sizeof(struct can_frame) -> Classical CAN interface */ or alternative, when the controller supports CAN with flexible data rate: dev->mtu = CANFD_MTU; /* sizeof(struct canfd_frame) -> CAN FD interface */}hjsbah}(h]h ]h"]h$]h&]jjjZjj[j\}uh1jhhhMShjhhubh)}(hwThe struct can_frame or struct canfd_frame is the payload of each socket buffer (skbuff) in the protocol family PF_CAN.h]hwThe struct can_frame or struct canfd_frame is the payload of each socket buffer (skbuff) in the protocol family PF_CAN.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM]hjhhubh)}(h.. _socketcan-local-loopback2:h]h}(h]h ]h"]h$]h&]hsocketcan-local-loopback2uh1hhMahjhhhhubeh}(h]general-settingsah ]h"]general settingsah$]h&]uh1hhjhhhhhMQubh)}(hhh](h)}(hLocal Loopback of Sent Framesh]hLocal Loopback of Sent Frames}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj(hhhhhMdubh)}(hXAAs described in :ref:`socketcan-local-loopback1` the CAN network device driver should support a local loopback functionality similar to the local echo e.g. of tty devices. In this case the driver flag IFF_ECHO has to be set to prevent the PF_CAN core from locally echoing sent frames (aka loopback) as fallback solution::h](hAs described in }(hj9hhhNhNubh)}(h :ref:`socketcan-local-loopback1`h]j)}(hjCh]hsocketcan-local-loopback1}(hjEhhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhjAubah}(h]h ]h"]h$]h&]refdocj refdomainjOreftyperef refexplicitrefwarnjsocketcan-local-loopback1uh1hhhhMfhj9ubhX the CAN network device driver should support a local loopback functionality similar to the local echo e.g. of tty devices. In this case the driver flag IFF_ECHO has to be set to prevent the PF_CAN core from locally echoing sent frames (aka loopback) as fallback solution:}(hj9hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMfhj(hhubj)}(h$dev->flags = (IFF_NOARP | IFF_ECHO);h]h$dev->flags = (IFF_NOARP | IFF_ECHO);}hjksbah}(h]h ]h"]h$]h&]jjuh1jhhhMlhj(hhubeh}(h](jid4eh ]h"]socketcan-local-loopback2ah$]jah&]uh1hhjhhhhhMdjKj}j~jsj}jjsubh)}(hhh](h)}(hCAN Controller Hardware Filtersh]hCAN Controller Hardware Filters}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMpubh)}(hX.To reduce the interrupt load on deep embedded systems some CAN controllers support the filtering of CAN IDs or ranges of CAN IDs. These hardware filter capabilities vary from controller to controller and have to be identified as not feasible in a multi-user networking approach. The use of the very controller specific hardware filters could make sense in a very dedicated use-case, as a filter on driver level would affect all users in the multi-user system. The high efficient filter sets inside the PF_CAN core allow to set different multiple filters for each socket separately. Therefore the use of hardware filters goes to the category 'handmade tuning on deep embedded systems'. The author is running a MPC603e @133MHz with four SJA1000 CAN controllers from 2002 under heavy bus load without any problems ...h]hX2To reduce the interrupt load on deep embedded systems some CAN controllers support the filtering of CAN IDs or ranges of CAN IDs. These hardware filter capabilities vary from controller to controller and have to be identified as not feasible in a multi-user networking approach. The use of the very controller specific hardware filters could make sense in a very dedicated use-case, as a filter on driver level would affect all users in the multi-user system. The high efficient filter sets inside the PF_CAN core allow to set different multiple filters for each socket separately. Therefore the use of hardware filters goes to the category ‘handmade tuning on deep embedded systems’. The author is running a MPC603e @133MHz with four SJA1000 CAN controllers from 2002 under heavy bus load without any problems ...}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMrhjhhubeh}(h]can-controller-hardware-filtersah ]h"]can controller hardware filtersah$]h&]uh1hhjhhhhhMpubh)}(hhh](h)}(h Switchable Termination Resistorsh]h Switchable Termination Resistors}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hXCAN bus requires a specific impedance across the differential pair, typically provided by two 120Ohm resistors on the farthest nodes of the bus. Some CAN controllers support activating / deactivating a termination resistor(s) to provide the correct impedance.h]hXCAN bus requires a specific impedance across the differential pair, typically provided by two 120Ohm resistors on the farthest nodes of the bus. Some CAN controllers support activating / deactivating a termination resistor(s) to provide the correct impedance.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h!Query the available resistances::h]h Query the available resistances:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h;$ ip -details link show can0 ... termination 120 [ 0, 120 ]h]h;$ ip -details link show can0 ... termination 120 [ 0, 120 ]}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(h#Activate the terminating resistor::h]h"Activate the terminating resistor:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h/$ ip link set dev can0 type can termination 120h]h/$ ip link set dev can0 type can termination 120}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(h%Deactivate the terminating resistor::h]h$Deactivate the terminating resistor:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h-$ ip link set dev can0 type can termination 0h]h-$ ip link set dev can0 type can termination 0}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(hrTo enable termination resistor support to a can-controller, either implement in the controller's struct can-priv::h]hsTo enable termination resistor support to a can-controller, either implement in the controller’s struct can-priv:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(h:termination_const termination_const_cnt do_set_terminationh]h:termination_const termination_const_cnt do_set_termination}hj+sbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(hsor add gpio control with the device tree entries from Documentation/devicetree/bindings/net/can/can-controller.yamlh]hsor add gpio control with the device tree entries from Documentation/devicetree/bindings/net/can/can-controller.yaml}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h] switchable-termination-resistorsah ]h"] switchable termination resistorsah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(hThe Virtual CAN Driver (vcan)h]hThe Virtual CAN Driver (vcan)}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjOhhhhhMubh)}(hSimilar to the network loopback devices, vcan offers a virtual local CAN interface. A full qualified address on CAN consists ofh]hSimilar to the network loopback devices, vcan offers a virtual local CAN interface. A full qualified address on CAN consists of}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjOhhubj*)}(hhh](j/)}(h a unique CAN Identifier (CAN ID)h]h)}(hjsh]h a unique CAN Identifier (CAN ID)}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjqubah}(h]h ]h"]h$]h&]uh1j.hjnhhhhhNubj/)}(h6the CAN bus this CAN ID is transmitted on (e.g. can0) h]h)}(h5the CAN bus this CAN ID is transmitted on (e.g. can0)h]h5the CAN bus this CAN ID is transmitted on (e.g. can0)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjnhhhhhNubeh}(h]h ]h"]h$]h&]jjuh1j)hhhMhjOhhubh)}(hEso in common use cases more than one virtual CAN interface is needed.h]hEso in common use cases more than one virtual CAN interface is needed.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjOhhubh)}(hXThe virtual CAN interfaces allow the transmission and reception of CAN frames without real CAN controller hardware. Virtual CAN network devices are usually named 'vcanX', like vcan0 vcan1 vcan2 ... When compiled as a module the virtual CAN driver module is called vcan.koh]hXThe virtual CAN interfaces allow the transmission and reception of CAN frames without real CAN controller hardware. Virtual CAN network devices are usually named ‘vcanX’, like vcan0 vcan1 vcan2 ... When compiled as a module the virtual CAN driver module is called vcan.ko}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjOhhubh)}(hSince Linux Kernel version 2.6.24 the vcan driver supports the Kernel netlink interface to create vcan network devices. The creation and removal of vcan network devices can be managed with the ip(8) tool::h]hSince Linux Kernel version 2.6.24 the vcan driver supports the Kernel netlink interface to create vcan network devices. The creation and removal of vcan network devices can be managed with the ip(8) tool:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjOhhubj)}(hX- Create a virtual CAN network interface: $ ip link add type vcan - Create a virtual CAN network interface with a specific name 'vcan42': $ ip link add dev vcan42 type vcan - Remove a (virtual CAN) network interface 'vcan42': $ ip link del vcan42h]hX- Create a virtual CAN network interface: $ ip link add type vcan - Create a virtual CAN network interface with a specific name 'vcan42': $ ip link add dev vcan42 type vcan - Remove a (virtual CAN) network interface 'vcan42': $ ip link del vcan42}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjOhhubeh}(h]the-virtual-can-driver-vcanah ]h"]the virtual can driver (vcan)ah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h'The CAN Network Device Driver Interfaceh]h'The CAN Network Device Driver Interface}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hXdThe CAN network device driver interface provides a generic interface to setup, configure and monitor CAN network devices. The user can then configure the CAN device, like setting the bit-timing parameters, via the netlink interface using the program "ip" from the "IPROUTE2" utility suite. The following chapter describes briefly how to use it. Furthermore, the interface uses a common data structure and exports a set of common functions, which all real CAN network device drivers should use. Please have a look to the SJA1000 or MSCAN driver to understand how to use them. The name of the module is can-dev.ko.h]hXlThe CAN network device driver interface provides a generic interface to setup, configure and monitor CAN network devices. The user can then configure the CAN device, like setting the bit-timing parameters, via the netlink interface using the program “ip” from the “IPROUTE2” utility suite. The following chapter describes briefly how to use it. Furthermore, the interface uses a common data structure and exports a set of common functions, which all real CAN network device drivers should use. Please have a look to the SJA1000 or MSCAN driver to understand how to use them. The name of the module is can-dev.ko.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hhh](h)}(h/Netlink interface to set/get devices propertiesh]h/Netlink interface to set/get devices properties}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hXThe CAN device must be configured via netlink interface. The supported netlink message types are defined and briefly described in "include/linux/can/netlink.h". CAN link support for the program "ip" of the IPROUTE2 utility suite is available and it can be used as shown below:h]hXThe CAN device must be configured via netlink interface. The supported netlink message types are defined and briefly described in “include/linux/can/netlink.h”. CAN link support for the program “ip” of the IPROUTE2 utility suite is available and it can be used as shown below:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hSetting CAN device properties::h]hSetting CAN device properties:}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hX$ ip link set can0 type can help Usage: ip link set DEVICE type can [ bitrate BITRATE [ sample-point SAMPLE-POINT] ] | [ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1 phase-seg2 PHASE-SEG2 [ sjw SJW ] ] [ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] | [ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1 dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ] [ loopback { on | off } ] [ listen-only { on | off } ] [ triple-sampling { on | off } ] [ one-shot { on | off } ] [ berr-reporting { on | off } ] [ fd { on | off } ] [ fd-non-iso { on | off } ] [ presume-ack { on | off } ] [ cc-len8-dlc { on | off } ] [ restart-ms TIME-MS ] [ restart ] Where: BITRATE := { 1..1000000 } SAMPLE-POINT := { 0.000..0.999 } TQ := { NUMBER } PROP-SEG := { 1..8 } PHASE-SEG1 := { 1..8 } PHASE-SEG2 := { 1..8 } SJW := { 1..4 } RESTART-MS := { 0 | NUMBER }h]hX$ ip link set can0 type can help Usage: ip link set DEVICE type can [ bitrate BITRATE [ sample-point SAMPLE-POINT] ] | [ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1 phase-seg2 PHASE-SEG2 [ sjw SJW ] ] [ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] | [ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1 dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ] [ loopback { on | off } ] [ listen-only { on | off } ] [ triple-sampling { on | off } ] [ one-shot { on | off } ] [ berr-reporting { on | off } ] [ fd { on | off } ] [ fd-non-iso { on | off } ] [ presume-ack { on | off } ] [ cc-len8-dlc { on | off } ] [ restart-ms TIME-MS ] [ restart ] Where: BITRATE := { 1..1000000 } SAMPLE-POINT := { 0.000..0.999 } TQ := { NUMBER } PROP-SEG := { 1..8 } PHASE-SEG1 := { 1..8 } PHASE-SEG2 := { 1..8 } SJW := { 1..4 } RESTART-MS := { 0 | NUMBER }}hj2sbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(h+Display CAN device details and statistics::h]h*Display CAN device details and statistics:}(hj@hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hX$ ip -details -statistics link show can0 2: can0: mtu 16 qdisc pfifo_fast state UP qlen 10 link/can can state ERROR-ACTIVE restart-ms 100 bitrate 125000 sample_point 0.875 tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1 sja1000: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1 clock 8000000 re-started bus-errors arbit-lost error-warn error-pass bus-off 41 17457 0 41 42 41 RX: bytes packets errors dropped overrun mcast 140859 17608 17457 0 0 0 TX: bytes packets errors dropped carrier collsns 861 112 0 41 0 0h]hX$ ip -details -statistics link show can0 2: can0: mtu 16 qdisc pfifo_fast state UP qlen 10 link/can can state ERROR-ACTIVE restart-ms 100 bitrate 125000 sample_point 0.875 tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1 sja1000: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1 clock 8000000 re-started bus-errors arbit-lost error-warn error-pass bus-off 41 17457 0 41 42 41 RX: bytes packets errors dropped overrun mcast 140859 17608 17457 0 0 0 TX: bytes packets errors dropped carrier collsns 861 112 0 41 0 0}hjNsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(hMore info to the above output:h]hMore info to the above output:}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjhhubjH)}(hhh](jM)}(hp"" Shows the list of selected CAN controller modes: LOOPBACK, LISTEN-ONLY, or TRIPLE-SAMPLING. h](jS)}(h""h]h“”}(hjqhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMhjmubjc)}(hhh]h)}(h[Shows the list of selected CAN controller modes: LOOPBACK, LISTEN-ONLY, or TRIPLE-SAMPLING.h]h[Shows the list of selected CAN controller modes: LOOPBACK, LISTEN-ONLY, or TRIPLE-SAMPLING.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjubah}(h]h ]h"]h$]h&]uh1jbhjmubeh}(h]h ]h"]h$]h&]uh1jLhhhMhjjubjM)}(h"state ERROR-ACTIVE" The current state of the CAN controller: "ERROR-ACTIVE", "ERROR-WARNING", "ERROR-PASSIVE", "BUS-OFF" or "STOPPED" h](jS)}(h"state ERROR-ACTIVE"h]h“state ERROR-ACTIVE”}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMhjubjc)}(hhh]h)}(hqThe current state of the CAN controller: "ERROR-ACTIVE", "ERROR-WARNING", "ERROR-PASSIVE", "BUS-OFF" or "STOPPED"h]hThe current state of the CAN controller: “ERROR-ACTIVE”, “ERROR-WARNING”, “ERROR-PASSIVE”, “BUS-OFF” or “STOPPED”}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhMhjjhhubjM)}(h"restart-ms 100" Automatic restart delay time. If set to a non-zero value, a restart of the CAN controller will be triggered automatically in case of a bus-off condition after the specified delay time in milliseconds. By default it's off. h](jS)}(h"restart-ms 100"h]h“restart-ms 100”}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhMhjubjc)}(hhh]h)}(hAutomatic restart delay time. If set to a non-zero value, a restart of the CAN controller will be triggered automatically in case of a bus-off condition after the specified delay time in milliseconds. By default it's off.h]hAutomatic restart delay time. If set to a non-zero value, a restart of the CAN controller will be triggered automatically in case of a bus-off condition after the specified delay time in milliseconds. By default it’s off.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhMhjjhhubjM)}(hX"bitrate 125000 sample-point 0.875" Shows the real bit-rate in bits/sec and the sample-point in the range 0.000..0.999. If the calculation of bit-timing parameters is enabled in the kernel (CONFIG_CAN_CALC_BITTIMING=y), the bit-timing can be defined by setting the "bitrate" argument. Optionally the "sample-point" can be specified. By default it's 0.000 assuming CIA-recommended sample-points. h](jS)}(h#"bitrate 125000 sample-point 0.875"h]h'“bitrate 125000 sample-point 0.875”}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhM hjubjc)}(hhh]h)}(hXfShows the real bit-rate in bits/sec and the sample-point in the range 0.000..0.999. If the calculation of bit-timing parameters is enabled in the kernel (CONFIG_CAN_CALC_BITTIMING=y), the bit-timing can be defined by setting the "bitrate" argument. Optionally the "sample-point" can be specified. By default it's 0.000 assuming CIA-recommended sample-points.h]hXpShows the real bit-rate in bits/sec and the sample-point in the range 0.000..0.999. If the calculation of bit-timing parameters is enabled in the kernel (CONFIG_CAN_CALC_BITTIMING=y), the bit-timing can be defined by setting the “bitrate” argument. Optionally the “sample-point” can be specified. By default it’s 0.000 assuming CIA-recommended sample-points.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhM hjjhhubjM)}(hXm"tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1" Shows the time quanta in ns, propagation segment, phase buffer segment 1 and 2 and the synchronisation jump width in units of tq. They allow to define the CAN bit-timing in a hardware independent format as proposed by the Bosch CAN 2.0 spec (see chapter 8 of http://www.semiconductors.bosch.de/pdf/can2spec.pdf). h](jS)}(h3"tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1"h]h7“tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1”}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhM'hj)ubjc)}(hhh]h)}(hX8Shows the time quanta in ns, propagation segment, phase buffer segment 1 and 2 and the synchronisation jump width in units of tq. They allow to define the CAN bit-timing in a hardware independent format as proposed by the Bosch CAN 2.0 spec (see chapter 8 of http://www.semiconductors.bosch.de/pdf/can2spec.pdf).h](hXShows the time quanta in ns, propagation segment, phase buffer segment 1 and 2 and the synchronisation jump width in units of tq. They allow to define the CAN bit-timing in a hardware independent format as proposed by the Bosch CAN 2.0 spec (see chapter 8 of }(hj>hhhNhNubh reference)}(h3http://www.semiconductors.bosch.de/pdf/can2spec.pdfh]h3http://www.semiconductors.bosch.de/pdf/can2spec.pdf}(hjHhhhNhNubah}(h]h ]h"]h$]h&]refurijJuh1jFhj>ubh).}(hj>hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM#hj;ubah}(h]h ]h"]h$]h&]uh1jbhj)ubeh}(h]h ]h"]h$]h&]uh1jLhhhM'hjjhhubjM)}(hX"sja1000: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1 clock 8000000" Shows the bit-timing constants of the CAN controller, here the "sja1000". The minimum and maximum values of the time segment 1 and 2, the synchronisation jump width in units of tq, the bitrate pre-scaler and the CAN system clock frequency in Hz. These constants could be used for user-defined (non-standard) bit-timing calculation algorithms in user-space. h](jS)}(hL"sja1000: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1 clock 8000000"h]hP“sja1000: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1 clock 8000000”}(hjqhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhM/hjmubjc)}(hhh]h)}(hXdShows the bit-timing constants of the CAN controller, here the "sja1000". The minimum and maximum values of the time segment 1 and 2, the synchronisation jump width in units of tq, the bitrate pre-scaler and the CAN system clock frequency in Hz. These constants could be used for user-defined (non-standard) bit-timing calculation algorithms in user-space.h]hXhShows the bit-timing constants of the CAN controller, here the “sja1000”. The minimum and maximum values of the time segment 1 and 2, the synchronisation jump width in units of tq, the bitrate pre-scaler and the CAN system clock frequency in Hz. These constants could be used for user-defined (non-standard) bit-timing calculation algorithms in user-space.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM*hjubah}(h]h ]h"]h$]h&]uh1jbhjmubeh}(h]h ]h"]h$]h&]uh1jLhhhM/hjjhhubjM)}(hX%"re-started bus-errors arbit-lost error-warn error-pass bus-off" Shows the number of restarts, bus and arbitration lost errors, and the state changes to the error-warning, error-passive and bus-off state. RX overrun errors are listed in the "overrun" field of the standard network statistics. h](jS)}(h@"re-started bus-errors arbit-lost error-warn error-pass bus-off"h]hD“re-started bus-errors arbit-lost error-warn error-pass bus-off”}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jRhhhM5hjubjc)}(hhh]h)}(hShows the number of restarts, bus and arbitration lost errors, and the state changes to the error-warning, error-passive and bus-off state. RX overrun errors are listed in the "overrun" field of the standard network statistics.h]hShows the number of restarts, bus and arbitration lost errors, and the state changes to the error-warning, error-passive and bus-off state. RX overrun errors are listed in the “overrun” field of the standard network statistics.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM2hjubah}(h]h ]h"]h$]h&]uh1jbhjubeh}(h]h ]h"]h$]h&]uh1jLhhhM5hjjhhubeh}(h]h ]h"]h$]h&]uh1jGhjhhhhhNubeh}(h]/netlink-interface-to-set-get-devices-propertiesah ]h"]/netlink interface to set/get devices propertiesah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(hSetting the CAN Bit-Timingh]hSetting the CAN Bit-Timing}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhM8ubh)}(hThe CAN bit-timing parameters can always be defined in a hardware independent format as proposed in the Bosch CAN 2.0 specification specifying the arguments "tq", "prop_seg", "phase_seg1", "phase_seg2" and "sjw"::h]hThe CAN bit-timing parameters can always be defined in a hardware independent format as proposed in the Bosch CAN 2.0 specification specifying the arguments “tq”, “prop_seg”, “phase_seg1”, “phase_seg2” and “sjw”:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM:hjhhubj)}(hk$ ip link set canX type can tq 125 prop-seg 6 \ phase-seg1 7 phase-seg2 2 sjw 1h]hk$ ip link set canX type can tq 125 prop-seg 6 \ phase-seg1 7 phase-seg2 2 sjw 1}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhM?hjhhubh)}(hIf the kernel option CONFIG_CAN_CALC_BITTIMING is enabled, CIA recommended CAN bit-timing parameters will be calculated if the bit- rate is specified with the argument "bitrate"::h]hIf the kernel option CONFIG_CAN_CALC_BITTIMING is enabled, CIA recommended CAN bit-timing parameters will be calculated if the bit- rate is specified with the argument “bitrate”:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMBhjhhubj)}(h*$ ip link set canX type can bitrate 125000h]h*$ ip link set canX type can bitrate 125000}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMFhjhhubh)}(hXNote that this works fine for the most common CAN controllers with standard bit-rates but may *fail* for exotic bit-rates or CAN system clock frequencies. Disabling CONFIG_CAN_CALC_BITTIMING saves some space and allows user-space tools to solely determine and set the bit-timing parameters. The CAN controller specific bit-timing constants can be used for that purpose. They are listed by the following command::h](h^Note that this works fine for the most common CAN controllers with standard bit-rates but may }(hj"hhhNhNubj )}(h*fail*h]hfail}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj"ubhX7 for exotic bit-rates or CAN system clock frequencies. Disabling CONFIG_CAN_CALC_BITTIMING saves some space and allows user-space tools to solely determine and set the bit-timing parameters. The CAN controller specific bit-timing constants can be used for that purpose. They are listed by the following command:}(hj"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMHhjhhubj)}(hm$ ip -details link show can0 ... sja1000: clock 8000000 tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1h]hm$ ip -details link show can0 ... sja1000: clock 8000000 tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1}hjBsbah}(h]h ]h"]h$]h&]jjuh1jhhhMPhjhhubeh}(h]setting-the-can-bit-timingah ]h"]setting the can bit-timingah$]h&]uh1hhjhhhhhM8ubh)}(hhh](h)}(h,Starting and Stopping the CAN Network Deviceh]h,Starting and Stopping the CAN Network Device}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjXhhhhhMVubh)}(hX A CAN network device is started or stopped as usual with the command "ifconfig canX up/down" or "ip link set canX up/down". Be aware that you *must* define proper bit-timing parameters for real CAN devices before you can start it to avoid error-prone default settings::h](hA CAN network device is started or stopped as usual with the command “ifconfig canX up/down” or “ip link set canX up/down”. Be aware that you }(hjihhhNhNubj )}(h*must*h]hmust}(hjqhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjiubhx define proper bit-timing parameters for real CAN devices before you can start it to avoid error-prone default settings:}(hjihhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMXhjXhhubj)}(h-$ ip link set canX up type can bitrate 125000h]h-$ ip link set canX up type can bitrate 125000}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhM]hjXhhubh)}(hA device may enter the "bus-off" state if too many errors occurred on the CAN bus. Then no more messages are received or sent. An automatic bus-off recovery can be enabled by setting the "restart-ms" to a non-zero value, e.g.::h]hA device may enter the “bus-off” state if too many errors occurred on the CAN bus. Then no more messages are received or sent. An automatic bus-off recovery can be enabled by setting the “restart-ms” to a non-zero value, e.g.:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM_hjXhhubj)}(h*$ ip link set canX type can restart-ms 100h]h*$ ip link set canX type can restart-ms 100}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMdhjXhhubh)}(hAlternatively, the application may realize the "bus-off" condition by monitoring CAN error message frames and do a restart when appropriate with the command::h]hAlternatively, the application may realize the “bus-off” condition by monitoring CAN error message frames and do a restart when appropriate with the command:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMfhjXhhubj)}(h#$ ip link set canX type can restarth]h#$ ip link set canX type can restart}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhMjhjXhhubh)}(hyNote that a restart will also create a CAN error message frame (see also :ref:`socketcan-network-problem-notifications`).h](hINote that a restart will also create a CAN error message frame (see also }(hjhhhNhNubh)}(h.:ref:`socketcan-network-problem-notifications`h]j)}(hjh]h'socketcan-network-problem-notifications}(hjhhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]refdocj refdomainjreftyperef refexplicitrefwarnj'socketcan-network-problem-notificationsuh1hhhhMlhjubh).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMlhjXhhubh)}(h.. _socketcan-can-fd-driver:h]h}(h]h ]h"]h$]h&]hsocketcan-can-fd-driveruh1hhMphjXhhhhubeh}(h],starting-and-stopping-the-can-network-deviceah ]h"],starting and stopping the can network deviceah$]h&]uh1hhjhhhhhMVubeh}(h]'the-can-network-device-driver-interfaceah ]h"]'the can network device driver interfaceah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h*CAN FD (Flexible Data Rate) Driver Supporth]h*CAN FD (Flexible Data Rate) Driver Support}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMsubh)}(hCAN FD capable CAN controllers support two different bitrates for the arbitration phase and the payload phase of the CAN FD frame. Therefore a second bit timing has to be specified in order to enable the CAN FD bitrate.h]hCAN FD capable CAN controllers support two different bitrates for the arbitration phase and the payload phase of the CAN FD frame. Therefore a second bit timing has to be specified in order to enable the CAN FD bitrate.}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMuhjhhubh)}(hX"Additionally CAN FD capable CAN controllers support up to 64 bytes of payload. The representation of this length in can_frame.len and canfd_frame.len for userspace applications and inside the Linux network layer is a plain value from 0 .. 64 instead of the CAN 'data length code'. The data length code was a 1:1 mapping to the payload length in the Classical CAN frames anyway. The payload length to the bus-relevant DLC mapping is only performed inside the CAN drivers, preferably with the helper functions can_fd_dlc2len() and can_fd_len2dlc().h]hX&Additionally CAN FD capable CAN controllers support up to 64 bytes of payload. The representation of this length in can_frame.len and canfd_frame.len for userspace applications and inside the Linux network layer is a plain value from 0 .. 64 instead of the CAN ‘data length code’. The data length code was a 1:1 mapping to the payload length in the Classical CAN frames anyway. The payload length to the bus-relevant DLC mapping is only performed inside the CAN drivers, preferably with the helper functions can_fd_dlc2len() and can_fd_len2dlc().}(hj;hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMyhjhhubh)}(hoThe CAN netdevice driver capabilities can be distinguished by the network devices maximum transfer unit (MTU)::h]hnThe CAN netdevice driver capabilities can be distinguished by the network devices maximum transfer unit (MTU):}(hjIhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hMTU = 16 (CAN_MTU) => sizeof(struct can_frame) => Classical CAN device MTU = 72 (CANFD_MTU) => sizeof(struct canfd_frame) => CAN FD capable deviceh]hMTU = 16 (CAN_MTU) => sizeof(struct can_frame) => Classical CAN device MTU = 72 (CANFD_MTU) => sizeof(struct canfd_frame) => CAN FD capable device}hjWsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(hThe CAN device MTU can be retrieved e.g. with a SIOCGIFMTU ioctl() syscall. N.B. CAN FD capable devices can also handle and send Classical CAN frames.h]hThe CAN device MTU can be retrieved e.g. with a SIOCGIFMTU ioctl() syscall. N.B. CAN FD capable devices can also handle and send Classical CAN frames.}(hjehhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXWhen configuring CAN FD capable CAN controllers an additional 'data' bitrate has to be set. This bitrate for the data phase of the CAN FD frame has to be at least the bitrate which was configured for the arbitration phase. This second bitrate is specified analogue to the first bitrate but the bitrate setting keywords for the 'data' bitrate start with 'd' e.g. dbitrate, dsample-point, dsjw or dtq and similar settings. When a data bitrate is set within the configuration process the controller option "fd on" can be specified to enable the CAN FD mode in the CAN controller. This controller option also switches the device MTU to 72 (CANFD_MTU).h]hXWhen configuring CAN FD capable CAN controllers an additional ‘data’ bitrate has to be set. This bitrate for the data phase of the CAN FD frame has to be at least the bitrate which was configured for the arbitration phase. This second bitrate is specified analogue to the first bitrate but the bitrate setting keywords for the ‘data’ bitrate start with ‘d’ e.g. dbitrate, dsample-point, dsjw or dtq and similar settings. When a data bitrate is set within the configuration process the controller option “fd on” can be specified to enable the CAN FD mode in the CAN controller. This controller option also switches the device MTU to 72 (CANFD_MTU).}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hThe first CAN FD specification presented as whitepaper at the International CAN Conference 2012 needed to be improved for data integrity reasons. Therefore two CAN FD implementations have to be distinguished today:h]hThe first CAN FD specification presented as whitepaper at the International CAN Conference 2012 needed to be improved for data integrity reasons. Therefore two CAN FD implementations have to be distinguished today:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj*)}(hhh](j/)}(hGISO compliant: The ISO 11898-1:2015 CAN FD implementation (default)h]h)}(hjh]hGISO compliant: The ISO 11898-1:2015 CAN FD implementation (default)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(hKnon-ISO compliant: The CAN FD implementation following the 2012 whitepaper h]h)}(hJnon-ISO compliant: The CAN FD implementation following the 2012 whitepaperh]hJnon-ISO compliant: The CAN FD implementation following the 2012 whitepaper}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubeh}(h]h ]h"]h$]h&]jjuh1j)hhhMhjhhubh)}(h4Finally there are three types of CAN FD controllers:h]h4Finally there are three types of CAN FD controllers:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubhenumerated_list)}(hhh](j/)}(hISO compliant (fixed)h]h)}(hjh]hISO compliant (fixed)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(hCnon-ISO compliant (fixed, like the M_CAN IP core v3.0.1 in m_can.c)h]h)}(hjh]hCnon-ISO compliant (fixed, like the M_CAN IP core v3.0.1 in m_can.c)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(hGISO/non-ISO CAN FD controllers (switchable, like the PEAK PCAN-USB FD) h]h)}(hFISO/non-ISO CAN FD controllers (switchable, like the PEAK PCAN-USB FD)h]hFISO/non-ISO CAN FD controllers (switchable, like the PEAK PCAN-USB FD)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubeh}(h]h ]h"]h$]h&]enumtypearabicprefixhsuffix.uh1jhjhhhhhMubh)}(hThe current ISO/non-ISO mode is announced by the CAN controller driver via netlink and displayed by the 'ip' tool (controller option FD-NON-ISO). The ISO/non-ISO-mode can be altered by setting 'fd-non-iso {on|off}' for switchable CAN FD controllers only.h]hXThe current ISO/non-ISO mode is announced by the CAN controller driver via netlink and displayed by the ‘ip’ tool (controller option FD-NON-ISO). The ISO/non-ISO-mode can be altered by setting ‘fd-non-iso {on|off}’ for switchable CAN FD controllers only.}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hNExample configuring 500 kbit/s arbitration bitrate and 4 Mbit/s data bitrate::h]hMExample configuring 500 kbit/s arbitration bitrate and 4 Mbit/s data bitrate:}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hX$ ip link set can0 up type can bitrate 500000 sample-point 0.75 \ dbitrate 4000000 dsample-point 0.8 fd on $ ip -details link show can0 5: can0: mtu 72 qdisc pfifo_fast state UNKNOWN \ mode DEFAULT group default qlen 10 link/can promiscuity 0 can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 bitrate 500000 sample-point 0.750 tq 50 prop-seg 14 phase-seg1 15 phase-seg2 10 sjw 1 pcan_usb_pro_fd: tseg1 1..64 tseg2 1..16 sjw 1..16 brp 1..1024 \ brp-inc 1 dbitrate 4000000 dsample-point 0.800 dtq 12 dprop-seg 7 dphase-seg1 8 dphase-seg2 4 dsjw 1 pcan_usb_pro_fd: dtseg1 1..16 dtseg2 1..8 dsjw 1..4 dbrp 1..1024 \ dbrp-inc 1 clock 80000000h]hX$ ip link set can0 up type can bitrate 500000 sample-point 0.75 \ dbitrate 4000000 dsample-point 0.8 fd on $ ip -details link show can0 5: can0: mtu 72 qdisc pfifo_fast state UNKNOWN \ mode DEFAULT group default qlen 10 link/can promiscuity 0 can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 bitrate 500000 sample-point 0.750 tq 50 prop-seg 14 phase-seg1 15 phase-seg2 10 sjw 1 pcan_usb_pro_fd: tseg1 1..64 tseg2 1..16 sjw 1..16 brp 1..1024 \ brp-inc 1 dbitrate 4000000 dsample-point 0.800 dtq 12 dprop-seg 7 dphase-seg1 8 dphase-seg2 4 dsjw 1 pcan_usb_pro_fd: dtseg1 1..16 dtseg2 1..8 dsjw 1..4 dbrp 1..1024 \ dbrp-inc 1 clock 80000000}hjGsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubh)}(hIExample when 'fd-non-iso on' is added on this switchable CAN FD adapter::h]hLExample when ‘fd-non-iso on’ is added on this switchable CAN FD adapter:}(hjUhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hLcan state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0h]hLcan state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0}hjcsbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjhhubeh}(h]((can-fd-flexible-data-rate-driver-supportj eh ]h"](*can fd (flexible data rate) driver supportsocketcan-can-fd-drivereh$]h&]uh1hhjhhhhhMsj}jwjsj}j jsubh)}(hhh](h)}(hSupported CAN Hardwareh]hSupported CAN Hardware}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj|hhhhhMubh)}(hPlease check the "Kconfig" file in "drivers/net/can" to get an actual list of the support CAN hardware. On the SocketCAN project website (see :ref:`socketcan-resources`) there might be further drivers available, also for older kernel versions.h](hPlease check the “Kconfig” file in “drivers/net/can” to get an actual list of the support CAN hardware. On the SocketCAN project website (see }(hjhhhNhNubh)}(h:ref:`socketcan-resources`h]j)}(hjh]hsocketcan-resources}(hjhhhNhNubah}(h]h ](j stdstd-refeh"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]refdocj refdomainjreftyperef refexplicitrefwarnjsocketcan-resourcesuh1hhhhMhjubhK) there might be further drivers available, also for older kernel versions.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj|hhubh)}(h.. _socketcan-resources:h]h}(h]h ]h"]h$]h&]hsocketcan-resourcesuh1hhMhj|hhhhubeh}(h]supported-can-hardwareah ]h"]supported can hardwareah$]h&]uh1hhjhhhhhMubeh}(h]can-network-driversah ]h"]can network driversah$]h&]uh1hhhhhhhhMCubh)}(hhh](h)}(hSocketCAN Resourcesh]hSocketCAN Resources}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hThe Linux CAN / SocketCAN project resources (project site / mailing list) are referenced in the MAINTAINERS file in the Linux source tree. Search for CAN NETWORK [LAYERS|DRIVERS].h]hThe Linux CAN / SocketCAN project resources (project site / mailing list) are referenced in the MAINTAINERS file in the Linux source tree. Search for CAN NETWORK [LAYERS|DRIVERS].}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h](jid5eh ]h"](socketcan resourcessocketcan-resourceseh$]h&]uh1hhhhhhhhMj}jjsj}jjsubh)}(hhh](h)}(hCreditsh]hCredits}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubj*)}(hhh](j/)}(hDOliver Hartkopp (PF_CAN core, filters, drivers, bcm, SJA1000 driver)h]h)}(hjh]hDOliver Hartkopp (PF_CAN core, filters, drivers, bcm, SJA1000 driver)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(hMUrs Thuermann (PF_CAN core, kernel integration, socket interfaces, raw, vcan)h]h)}(hj1h]hMUrs Thuermann (PF_CAN core, kernel integration, socket interfaces, raw, vcan)}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj/ubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(h8Jan Kizka (RT-SocketCAN core, Socket-API reconciliation)h]h)}(hjHh]h8Jan Kizka (RT-SocketCAN core, Socket-API reconciliation)}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjFubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(htWolfgang Grandegger (RT-SocketCAN core & drivers, Raw Socket-API reviews, CAN device driver interface, MSCAN driver)h]h)}(hj_h]htWolfgang Grandegger (RT-SocketCAN core & drivers, Raw Socket-API reviews, CAN device driver interface, MSCAN driver)}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj]ubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(h5Robert Schwebel (design reviews, PTXdist integration)h]h)}(hjvh]h5Robert Schwebel (design reviews, PTXdist integration)}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjtubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(h@Marc Kleine-Budde (design reviews, Kernel 2.6 cleanups, drivers)h]h)}(hjh]h@Marc Kleine-Budde (design reviews, Kernel 2.6 cleanups, drivers)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(hBenedikt Spranger (reviews)h]h)}(hjh]hBenedikt Spranger (reviews)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(h;Thomas Gleixner (LKML reviews, coding style, posting hints)h]h)}(hjh]h;Thomas Gleixner (LKML reviews, coding style, posting hints)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(h>Andrey Volkov (kernel subtree structure, ioctls, MSCAN driver)h]h)}(hjh]h>Andrey Volkov (kernel subtree structure, ioctls, MSCAN driver)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(hEMatthias Brukner (first SJA1000 CAN netdevice implementation Q2/2003)h]h)}(hjh]hEMatthias Brukner (first SJA1000 CAN netdevice implementation Q2/2003)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(h)Klaus Hitschler (PEAK driver integration)h]h)}(hjh]h)Klaus Hitschler (PEAK driver integration)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(h2Uwe Koppe (CAN netdevices with PF_PACKET approach)h]h)}(hjh]h2Uwe Koppe (CAN netdevices with PF_PACKET approach)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(hJMichael Schulze (driver layer loopback requirement, RT CAN drivers review)h]h)}(hj.h]hJMichael Schulze (driver layer loopback requirement, RT CAN drivers review)}(hj0hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj,ubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(h#Pavel Pisa (Bit-timing calculation)h]h)}(hjEh]h#Pavel Pisa (Bit-timing calculation)}(hjGhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjCubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(h&Sascha Hauer (SJA1000 platform driver)h]h)}(hj\h]h&Sascha Hauer (SJA1000 platform driver)}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjZubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(h'Sebastian Haas (SJA1000 EMS PCI driver)h]h)}(hjsh]h'Sebastian Haas (SJA1000 EMS PCI driver)}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjqubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(h(Markus Plessing (SJA1000 EMS PCI driver)h]h)}(hjh]h(Markus Plessing (SJA1000 EMS PCI driver)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(h%Per Dalen (SJA1000 Kvaser PCI driver)h]h)}(hjh]h%Per Dalen (SJA1000 Kvaser PCI driver)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubj/)}(h1Sam Ravnborg (reviews, coding style, kbuild help)h]h)}(hjh]h1Sam Ravnborg (reviews, coding style, kbuild help)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1j.hjhhhhhNubeh}(h]h ]h"]h$]h&]jjuh1j)hhhMhjhhubeh}(h]creditsah ]h"]creditsah$]h&]uh1hhhhhhhhMubeh}(h]!socketcan-controller-area-networkah ]h"]#socketcan - controller area networkah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}f1]jasrefids}(h]haj]jaj2]j(aj]jvaj]jwaj]jaj]jaj ]j aj]jaj]jaj ]jaj]jaj]jaunameids}(jjhhjhjjjjjjjj2jjjjlocal loopback of sent framesNjtjjjjjjjjj jA jj@ j= jjjjjjjT jQ j j j! j j j j j j8 j5 jjjjjjj:j7j~j{j j jBj?jjjjjjj}jj|jyjjj1j.jtjqjjj%j"j~jjjjLjIjjjjjjjUjRjjjwj jvjsjjjjjjjju nametypes}(jhjjjjjjjjYjtjjjjjA j@ jjjjT j j! j j j8 jjjj:j~j jBjjjj}j|jj1jtjj%j~jjLjjjjUjjwjvjjjjuh}(jhhhhhjhjjjjj2j3jj3jjjjjjjjOjjjjjjj j(jjj= jjjjjjjujQ jj jW j j j j$ j j$ j5 j jjF jj jjj7jj{j=j jj?jjjEjjjjjjjyjjj5j.jjqj4jjj"jjj(j{j(jjjIjjjOjjjjjRjjjXj jjsjjj|jjjjjju footnote_refs}jF]jas citation_refs} autofootnotes]jOaautofootnote_refs]jasymbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}jKsRparse_messages]hsystem_message)}(hhh]h)}(h@Duplicate implicit target name: "local loopback of sent frames".h]hDDuplicate implicit target name: “local loopback of sent frames”.}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj{ubah}(h]h ]h"]h$]h&]j{alevelKtypeINFOsourcehlineMduh1jyhj(hhhhhMdubatransform_messages](jz)}(hhh]h)}(hhh]h:Hyperlink target "socketcan-motivation" is not referenced.}hjsbah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]levelKtypejsourcehlineKuh1jyubjz)}(hhh]h)}(hhh]h7Hyperlink target "socketcan-concept" is not referenced.}hjsbah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]levelKtypejsourcehlineKguh1jyubjz)}(hhh]h)}(hhh]h=Hyperlink target "socketcan-receive-lists" is not referenced.}hjsbah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]levelKtypejsourcehlineKwuh1jyubjz)}(hhh]h)}(hhh]h?Hyperlink target "socketcan-local-loopback1" is not referenced.}hjsbah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]levelKtypejsourcehlineKuh1jyubjz)}(hhh]h)}(hhh]hMHyperlink target "socketcan-network-problem-notifications" is not referenced.}hjsbah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]levelKtypejsourcehlineKuh1jyubjz)}(hhh]h)}(hhh]h;Hyperlink target "socketcan-raw-sockets" is not referenced.}hjsbah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]levelKtypejsourcehlineMuh1jyubjz)}(hhh]h)}(hhh]h9Hyperlink target "socketcan-rawfilter" is not referenced.}hj8sbah}(h]h ]h"]h$]h&]uh1hhj5ubah}(h]h ]h"]h$]h&]levelKtypejsourcehlineMuh1jyubjz)}(hhh]h)}(hhh]h5Hyperlink target "socketcan-rawfd" is not referenced.}hjRsbah}(h]h ]h"]h$]h&]uh1hhjOubah}(h]h ]h"]h$]h&]levelKtypejsourcehlineMxuh1jyubjz)}(hhh]h)}(hhh]h;Hyperlink target "socketcan-core-module" is not referenced.}hjlsbah}(h]h ]h"]h$]h&]uh1hhjiubah}(h]h ]h"]h$]h&]levelKtypejsourcehlineMuh1jyubjz)}(hhh]h)}(hhh]h?Hyperlink target "socketcan-local-loopback2" is not referenced.}hjsbah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]levelKtypejsourcehlineMauh1jyubjz)}(hhh]h)}(hhh]h=Hyperlink target "socketcan-can-fd-driver" is not referenced.}hjsbah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]levelKtypejsourcehlineMpuh1jyubjz)}(hhh]h)}(hhh]h9Hyperlink target "socketcan-resources" is not referenced.}hjsbah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]levelKtypejsourcehlineMuh1jyube transformerN include_log] decorationNhhub.