1*67711e04SFrancesco Valla.. SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2*67711e04SFrancesco Valla
3*67711e04SFrancesco Valla====================
4*67711e04SFrancesco VallaISO 15765-2 (ISO-TP)
5*67711e04SFrancesco Valla====================
6*67711e04SFrancesco Valla
7*67711e04SFrancesco VallaOverview
8*67711e04SFrancesco Valla========
9*67711e04SFrancesco Valla
10*67711e04SFrancesco VallaISO 15765-2, also known as ISO-TP, is a transport protocol specifically defined
11*67711e04SFrancesco Vallafor diagnostic communication on CAN. It is widely used in the automotive
12*67711e04SFrancesco Vallaindustry, for example as the transport protocol for UDSonCAN (ISO 14229-3) or
13*67711e04SFrancesco Vallaemission-related diagnostic services (ISO 15031-5).
14*67711e04SFrancesco Valla
15*67711e04SFrancesco VallaISO-TP can be used both on CAN CC (aka Classical CAN) and CAN FD (CAN with
16*67711e04SFrancesco VallaFlexible Datarate) based networks. It is also designed to be compatible with a
17*67711e04SFrancesco VallaCAN network using SAE J1939 as data link layer (however, this is not a
18*67711e04SFrancesco Vallarequirement).
19*67711e04SFrancesco Valla
20*67711e04SFrancesco VallaSpecifications used
21*67711e04SFrancesco Valla-------------------
22*67711e04SFrancesco Valla
23*67711e04SFrancesco Valla* ISO 15765-2:2024 : Road vehicles - Diagnostic communication over Controller
24*67711e04SFrancesco Valla  Area Network (DoCAN). Part 2: Transport protocol and network layer services.
25*67711e04SFrancesco Valla
26*67711e04SFrancesco VallaAddressing
27*67711e04SFrancesco Valla----------
28*67711e04SFrancesco Valla
29*67711e04SFrancesco VallaIn its simplest form, ISO-TP is based on two kinds of addressing modes for the
30*67711e04SFrancesco Vallanodes connected to the same network:
31*67711e04SFrancesco Valla
32*67711e04SFrancesco Valla* physical addressing is implemented by two node-specific addresses and is used
33*67711e04SFrancesco Valla  in 1-to-1 communication.
34*67711e04SFrancesco Valla
35*67711e04SFrancesco Valla* functional addressing is implemented by one node-specific address and is used
36*67711e04SFrancesco Valla  in 1-to-N communication.
37*67711e04SFrancesco Valla
38*67711e04SFrancesco VallaThree different addressing formats can be employed:
39*67711e04SFrancesco Valla
40*67711e04SFrancesco Valla* "normal" : each address is represented simply by a CAN ID.
41*67711e04SFrancesco Valla
42*67711e04SFrancesco Valla* "extended": each address is represented by a CAN ID plus the first byte of
43*67711e04SFrancesco Valla  the CAN payload; both the CAN ID and the byte inside the payload shall be
44*67711e04SFrancesco Valla  different between two addresses.
45*67711e04SFrancesco Valla
46*67711e04SFrancesco Valla* "mixed": each address is represented by a CAN ID plus the first byte of
47*67711e04SFrancesco Valla  the CAN payload; the CAN ID is different between two addresses, but the
48*67711e04SFrancesco Valla  additional byte is the same.
49*67711e04SFrancesco Valla
50*67711e04SFrancesco VallaTransport protocol and associated frame types
51*67711e04SFrancesco Valla---------------------------------------------
52*67711e04SFrancesco Valla
53*67711e04SFrancesco VallaWhen transmitting data using the ISO-TP protocol, the payload can either fit
54*67711e04SFrancesco Vallainside one single CAN message or not, also considering the overhead the protocol
55*67711e04SFrancesco Vallais generating and the optional extended addressing. In the first case, the data
56*67711e04SFrancesco Vallais transmitted at once using a so-called Single Frame (SF). In the second case,
57*67711e04SFrancesco VallaISO-TP defines a multi-frame protocol, in which the sender provides (through a
58*67711e04SFrancesco VallaFirst Frame - FF) the PDU length which is to be transmitted and also asks for a
59*67711e04SFrancesco VallaFlow Control (FC) frame, which provides the maximum supported size of a macro
60*67711e04SFrancesco Valladata block (``blocksize``) and the minimum time between the single CAN messages
61*67711e04SFrancesco Vallacomposing such block (``stmin``). Once this information has been received, the
62*67711e04SFrancesco Vallasender starts to send frames containing fragments of the data payload (called
63*67711e04SFrancesco VallaConsecutive Frames - CF), stopping after every ``blocksize``-sized block to wait
64*67711e04SFrancesco Vallaconfirmation from the receiver which should then send another Flow Control
65*67711e04SFrancesco Vallaframe to inform the sender about its availability to receive more data.
66*67711e04SFrancesco Valla
67*67711e04SFrancesco VallaHow to Use ISO-TP
68*67711e04SFrancesco Valla=================
69*67711e04SFrancesco Valla
70*67711e04SFrancesco VallaAs with others CAN protocols, the ISO-TP stack support is built into the
71*67711e04SFrancesco VallaLinux network subsystem for the CAN bus, aka. Linux-CAN or SocketCAN, and
72*67711e04SFrancesco Vallathus follows the same socket API.
73*67711e04SFrancesco Valla
74*67711e04SFrancesco VallaCreation and basic usage of an ISO-TP socket
75*67711e04SFrancesco Valla--------------------------------------------
76*67711e04SFrancesco Valla
77*67711e04SFrancesco VallaTo use the ISO-TP stack, ``#include <linux/can/isotp.h>`` shall be used. A
78*67711e04SFrancesco Vallasocket can then be created using the ``PF_CAN`` protocol family, the
79*67711e04SFrancesco Valla``SOCK_DGRAM`` type (as the underlying protocol is datagram-based by design)
80*67711e04SFrancesco Vallaand the ``CAN_ISOTP`` protocol:
81*67711e04SFrancesco Valla
82*67711e04SFrancesco Valla.. code-block:: C
83*67711e04SFrancesco Valla
84*67711e04SFrancesco Valla    s = socket(PF_CAN, SOCK_DGRAM, CAN_ISOTP);
85*67711e04SFrancesco Valla
86*67711e04SFrancesco VallaAfter the socket has been successfully created, ``bind(2)`` shall be called to
87*67711e04SFrancesco Vallabind the socket to the desired CAN interface; to do so:
88*67711e04SFrancesco Valla
89*67711e04SFrancesco Valla* a TX CAN ID shall be specified as part of the sockaddr supplied to the call
90*67711e04SFrancesco Valla  itself.
91*67711e04SFrancesco Valla
92*67711e04SFrancesco Valla* a RX CAN ID shall also be specified, unless broadcast flags have been set
93*67711e04SFrancesco Valla  through socket option (explained below).
94*67711e04SFrancesco Valla
95*67711e04SFrancesco VallaOnce bound to an interface, the socket can be read from and written to using
96*67711e04SFrancesco Vallathe usual ``read(2)`` and ``write(2)`` system calls, as well as ``send(2)``,
97*67711e04SFrancesco Valla``sendmsg(2)``, ``recv(2)`` and ``recvmsg(2)``.
98*67711e04SFrancesco VallaUnlike the CAN_RAW socket API, only the ISO-TP data field (the actual payload)
99*67711e04SFrancesco Vallais sent and received by the userspace application using these calls. The address
100*67711e04SFrancesco Vallainformation and the protocol information are automatically filled by the ISO-TP
101*67711e04SFrancesco Vallastack using the configuration supplied during socket creation. In the same way,
102*67711e04SFrancesco Vallathe stack will use the transport mechanism when required (i.e., when the size
103*67711e04SFrancesco Vallaof the data payload exceeds the MTU of the underlying CAN bus).
104*67711e04SFrancesco Valla
105*67711e04SFrancesco VallaThe sockaddr structure used for SocketCAN has extensions for use with ISO-TP,
106*67711e04SFrancesco Vallaas specified below:
107*67711e04SFrancesco Valla
108*67711e04SFrancesco Valla.. code-block:: C
109*67711e04SFrancesco Valla
110*67711e04SFrancesco Valla    struct sockaddr_can {
111*67711e04SFrancesco Valla        sa_family_t can_family;
112*67711e04SFrancesco Valla        int         can_ifindex;
113*67711e04SFrancesco Valla        union {
114*67711e04SFrancesco Valla            struct { canid_t rx_id, tx_id; } tp;
115*67711e04SFrancesco Valla        ...
116*67711e04SFrancesco Valla        } can_addr;
117*67711e04SFrancesco Valla    }
118*67711e04SFrancesco Valla
119*67711e04SFrancesco Valla* ``can_family`` and ``can_ifindex`` serve the same purpose as for other
120*67711e04SFrancesco Valla  SocketCAN sockets.
121*67711e04SFrancesco Valla
122*67711e04SFrancesco Valla* ``can_addr.tp.rx_id`` specifies the receive (RX) CAN ID and will be used as
123*67711e04SFrancesco Valla  a RX filter.
124*67711e04SFrancesco Valla
125*67711e04SFrancesco Valla* ``can_addr.tp.tx_id`` specifies the transmit (TX) CAN ID
126*67711e04SFrancesco Valla
127*67711e04SFrancesco VallaISO-TP socket options
128*67711e04SFrancesco Valla---------------------
129*67711e04SFrancesco Valla
130*67711e04SFrancesco VallaWhen creating an ISO-TP socket, reasonable defaults are set. Some options can
131*67711e04SFrancesco Vallabe modified with ``setsockopt(2)`` and/or read back with ``getsockopt(2)``.
132*67711e04SFrancesco Valla
133*67711e04SFrancesco VallaGeneral options
134*67711e04SFrancesco Valla~~~~~~~~~~~~~~~
135*67711e04SFrancesco Valla
136*67711e04SFrancesco VallaGeneral socket options can be passed using the ``CAN_ISOTP_OPTS`` optname:
137*67711e04SFrancesco Valla
138*67711e04SFrancesco Valla.. code-block:: C
139*67711e04SFrancesco Valla
140*67711e04SFrancesco Valla    struct can_isotp_options opts;
141*67711e04SFrancesco Valla    ret = setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_OPTS, &opts, sizeof(opts))
142*67711e04SFrancesco Valla
143*67711e04SFrancesco Vallawhere the ``can_isotp_options`` structure has the following contents:
144*67711e04SFrancesco Valla
145*67711e04SFrancesco Valla.. code-block:: C
146*67711e04SFrancesco Valla
147*67711e04SFrancesco Valla    struct can_isotp_options {
148*67711e04SFrancesco Valla        u32 flags;
149*67711e04SFrancesco Valla        u32 frame_txtime;
150*67711e04SFrancesco Valla        u8  ext_address;
151*67711e04SFrancesco Valla        u8  txpad_content;
152*67711e04SFrancesco Valla        u8  rxpad_content;
153*67711e04SFrancesco Valla        u8  rx_ext_address;
154*67711e04SFrancesco Valla    };
155*67711e04SFrancesco Valla
156*67711e04SFrancesco Valla* ``flags``: modifiers to be applied to the default behaviour of the ISO-TP
157*67711e04SFrancesco Valla  stack. Following flags are available:
158*67711e04SFrancesco Valla
159*67711e04SFrancesco Valla  * ``CAN_ISOTP_LISTEN_MODE``: listen only (do not send FC frames); normally
160*67711e04SFrancesco Valla    used as a testing feature.
161*67711e04SFrancesco Valla
162*67711e04SFrancesco Valla  * ``CAN_ISOTP_EXTEND_ADDR``: use the byte specified in ``ext_address`` as an
163*67711e04SFrancesco Valla    additional address component. This enables the "mixed" addressing format if
164*67711e04SFrancesco Valla    used alone, or the "extended" addressing format if used in conjunction with
165*67711e04SFrancesco Valla    ``CAN_ISOTP_RX_EXT_ADDR``.
166*67711e04SFrancesco Valla
167*67711e04SFrancesco Valla  * ``CAN_ISOTP_TX_PADDING``: enable padding for transmitted frames, using
168*67711e04SFrancesco Valla    ``txpad_content`` as value for the padding bytes.
169*67711e04SFrancesco Valla
170*67711e04SFrancesco Valla  * ``CAN_ISOTP_RX_PADDING``: enable padding for the received frames, using
171*67711e04SFrancesco Valla    ``rxpad_content`` as value for the padding bytes.
172*67711e04SFrancesco Valla
173*67711e04SFrancesco Valla  * ``CAN_ISOTP_CHK_PAD_LEN``: check for correct padding length on the received
174*67711e04SFrancesco Valla    frames.
175*67711e04SFrancesco Valla
176*67711e04SFrancesco Valla  * ``CAN_ISOTP_CHK_PAD_DATA``: check padding bytes on the received frames
177*67711e04SFrancesco Valla    against ``rxpad_content``; if ``CAN_ISOTP_RX_PADDING`` is not specified,
178*67711e04SFrancesco Valla    this flag is ignored.
179*67711e04SFrancesco Valla
180*67711e04SFrancesco Valla  * ``CAN_ISOTP_HALF_DUPLEX``: force ISO-TP socket in half duplex mode
181*67711e04SFrancesco Valla    (that is, transport mechanism can only be incoming or outgoing at the same
182*67711e04SFrancesco Valla    time, not both).
183*67711e04SFrancesco Valla
184*67711e04SFrancesco Valla  * ``CAN_ISOTP_FORCE_TXSTMIN``: ignore stmin from received FC; normally
185*67711e04SFrancesco Valla    used as a testing feature.
186*67711e04SFrancesco Valla
187*67711e04SFrancesco Valla  * ``CAN_ISOTP_FORCE_RXSTMIN``: ignore CFs depending on rx stmin; normally
188*67711e04SFrancesco Valla    used as a testing feature.
189*67711e04SFrancesco Valla
190*67711e04SFrancesco Valla  * ``CAN_ISOTP_RX_EXT_ADDR``: use ``rx_ext_address`` instead of ``ext_address``
191*67711e04SFrancesco Valla    as extended addressing byte on the reception path. If used in conjunction
192*67711e04SFrancesco Valla    with ``CAN_ISOTP_EXTEND_ADDR``, this flag effectively enables the "extended"
193*67711e04SFrancesco Valla    addressing format.
194*67711e04SFrancesco Valla
195*67711e04SFrancesco Valla  * ``CAN_ISOTP_WAIT_TX_DONE``: wait until the frame is sent before returning
196*67711e04SFrancesco Valla    from ``write(2)`` and ``send(2)`` calls (i.e., blocking write operations).
197*67711e04SFrancesco Valla
198*67711e04SFrancesco Valla  * ``CAN_ISOTP_SF_BROADCAST``: use 1-to-N functional addressing (cannot be
199*67711e04SFrancesco Valla    specified alongside ``CAN_ISOTP_CF_BROADCAST``).
200*67711e04SFrancesco Valla
201*67711e04SFrancesco Valla  * ``CAN_ISOTP_CF_BROADCAST``: use 1-to-N transmission without flow control
202*67711e04SFrancesco Valla    (cannot be specified alongside ``CAN_ISOTP_SF_BROADCAST``).
203*67711e04SFrancesco Valla    NOTE: this is not covered by the ISO 15765-2 standard.
204*67711e04SFrancesco Valla
205*67711e04SFrancesco Valla  * ``CAN_ISOTP_DYN_FC_PARMS``: enable dynamic update of flow control
206*67711e04SFrancesco Valla    parameters.
207*67711e04SFrancesco Valla
208*67711e04SFrancesco Valla* ``frame_txtime``: frame transmission time (defined as N_As/N_Ar inside the
209*67711e04SFrancesco Valla  ISO standard); if ``0``, the default (or the last set value) is used.
210*67711e04SFrancesco Valla  To set the transmission time to ``0``, the ``CAN_ISOTP_FRAME_TXTIME_ZERO``
211*67711e04SFrancesco Valla  macro (equal to 0xFFFFFFFF) shall be used.
212*67711e04SFrancesco Valla
213*67711e04SFrancesco Valla* ``ext_address``: extended addressing byte, used if the
214*67711e04SFrancesco Valla  ``CAN_ISOTP_EXTEND_ADDR`` flag is specified.
215*67711e04SFrancesco Valla
216*67711e04SFrancesco Valla* ``txpad_content``: byte used as padding value for transmitted frames.
217*67711e04SFrancesco Valla
218*67711e04SFrancesco Valla* ``rxpad_content``: byte used as padding value for received frames.
219*67711e04SFrancesco Valla
220*67711e04SFrancesco Valla* ``rx_ext_address``: extended addressing byte for the reception path, used if
221*67711e04SFrancesco Valla  the ``CAN_ISOTP_RX_EXT_ADDR`` flag is specified.
222*67711e04SFrancesco Valla
223*67711e04SFrancesco VallaFlow Control options
224*67711e04SFrancesco Valla~~~~~~~~~~~~~~~~~~~~
225*67711e04SFrancesco Valla
226*67711e04SFrancesco VallaFlow Control (FC) options can be passed using the ``CAN_ISOTP_RECV_FC`` optname
227*67711e04SFrancesco Vallato provide the communication parameters for receiving ISO-TP PDUs.
228*67711e04SFrancesco Valla
229*67711e04SFrancesco Valla.. code-block:: C
230*67711e04SFrancesco Valla
231*67711e04SFrancesco Valla    struct can_isotp_fc_options fc_opts;
232*67711e04SFrancesco Valla    ret = setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_RECV_FC, &fc_opts, sizeof(fc_opts));
233*67711e04SFrancesco Valla
234*67711e04SFrancesco Vallawhere the ``can_isotp_fc_options`` structure has the following contents:
235*67711e04SFrancesco Valla
236*67711e04SFrancesco Valla.. code-block:: C
237*67711e04SFrancesco Valla
238*67711e04SFrancesco Valla    struct can_isotp_options {
239*67711e04SFrancesco Valla        u8 bs;
240*67711e04SFrancesco Valla        u8 stmin;
241*67711e04SFrancesco Valla        u8 wftmax;
242*67711e04SFrancesco Valla    };
243*67711e04SFrancesco Valla
244*67711e04SFrancesco Valla* ``bs``: blocksize provided in flow control frames.
245*67711e04SFrancesco Valla
246*67711e04SFrancesco Valla* ``stmin``: minimum separation time provided in flow control frames; can
247*67711e04SFrancesco Valla  have the following values (others are reserved):
248*67711e04SFrancesco Valla
249*67711e04SFrancesco Valla  * 0x00 - 0x7F : 0 - 127 ms
250*67711e04SFrancesco Valla
251*67711e04SFrancesco Valla  * 0xF1 - 0xF9 : 100 us - 900 us
252*67711e04SFrancesco Valla
253*67711e04SFrancesco Valla* ``wftmax``: maximum number of wait frames provided in flow control frames.
254*67711e04SFrancesco Valla
255*67711e04SFrancesco VallaLink Layer options
256*67711e04SFrancesco Valla~~~~~~~~~~~~~~~~~~
257*67711e04SFrancesco Valla
258*67711e04SFrancesco VallaLink Layer (LL) options can be passed using the ``CAN_ISOTP_LL_OPTS`` optname:
259*67711e04SFrancesco Valla
260*67711e04SFrancesco Valla.. code-block:: C
261*67711e04SFrancesco Valla
262*67711e04SFrancesco Valla    struct can_isotp_ll_options ll_opts;
263*67711e04SFrancesco Valla    ret = setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_LL_OPTS, &ll_opts, sizeof(ll_opts));
264*67711e04SFrancesco Valla
265*67711e04SFrancesco Vallawhere the ``can_isotp_ll_options`` structure has the following contents:
266*67711e04SFrancesco Valla
267*67711e04SFrancesco Valla.. code-block:: C
268*67711e04SFrancesco Valla
269*67711e04SFrancesco Valla    struct can_isotp_ll_options {
270*67711e04SFrancesco Valla        u8 mtu;
271*67711e04SFrancesco Valla        u8 tx_dl;
272*67711e04SFrancesco Valla        u8 tx_flags;
273*67711e04SFrancesco Valla    };
274*67711e04SFrancesco Valla
275*67711e04SFrancesco Valla* ``mtu``: generated and accepted CAN frame type, can be equal to ``CAN_MTU``
276*67711e04SFrancesco Valla  for classical CAN frames or ``CANFD_MTU`` for CAN FD frames.
277*67711e04SFrancesco Valla
278*67711e04SFrancesco Valla* ``tx_dl``: maximum payload length for transmitted frames, can have one value
279*67711e04SFrancesco Valla  among: 8, 12, 16, 20, 24, 32, 48, 64. Values above 8 only apply to CAN FD
280*67711e04SFrancesco Valla  traffic (i.e.: ``mtu = CANFD_MTU``).
281*67711e04SFrancesco Valla
282*67711e04SFrancesco Valla* ``tx_flags``: flags set into ``struct canfd_frame.flags`` at frame creation.
283*67711e04SFrancesco Valla  Only applies to CAN FD traffic (i.e.: ``mtu = CANFD_MTU``).
284*67711e04SFrancesco Valla
285*67711e04SFrancesco VallaTransmission stmin
286*67711e04SFrancesco Valla~~~~~~~~~~~~~~~~~~
287*67711e04SFrancesco Valla
288*67711e04SFrancesco VallaThe transmission minimum separation time (stmin) can be forced using the
289*67711e04SFrancesco Valla``CAN_ISOTP_TX_STMIN`` optname and providing an stmin value in microseconds as
290*67711e04SFrancesco Vallaa 32bit unsigned integer; this will overwrite the value sent by the receiver in
291*67711e04SFrancesco Vallaflow control frames:
292*67711e04SFrancesco Valla
293*67711e04SFrancesco Valla.. code-block:: C
294*67711e04SFrancesco Valla
295*67711e04SFrancesco Valla    uint32_t stmin;
296*67711e04SFrancesco Valla    ret = setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_TX_STMIN, &stmin, sizeof(stmin));
297*67711e04SFrancesco Valla
298*67711e04SFrancesco VallaReception stmin
299*67711e04SFrancesco Valla~~~~~~~~~~~~~~~
300*67711e04SFrancesco Valla
301*67711e04SFrancesco VallaThe reception minimum separation time (stmin) can be forced using the
302*67711e04SFrancesco Valla``CAN_ISOTP_RX_STMIN`` optname and providing an stmin value in microseconds as
303*67711e04SFrancesco Vallaa 32bit unsigned integer; received Consecutive Frames (CF) which timestamps
304*67711e04SFrancesco Valladiffer less than this value will be ignored:
305*67711e04SFrancesco Valla
306*67711e04SFrancesco Valla.. code-block:: C
307*67711e04SFrancesco Valla
308*67711e04SFrancesco Valla    uint32_t stmin;
309*67711e04SFrancesco Valla    ret = setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_RX_STMIN, &stmin, sizeof(stmin));
310*67711e04SFrancesco Valla
311*67711e04SFrancesco VallaMulti-frame transport support
312*67711e04SFrancesco Valla-----------------------------
313*67711e04SFrancesco Valla
314*67711e04SFrancesco VallaThe ISO-TP stack contained inside the Linux kernel supports the multi-frame
315*67711e04SFrancesco Vallatransport mechanism defined by the standard, with the following constraints:
316*67711e04SFrancesco Valla
317*67711e04SFrancesco Valla* the maximum size of a PDU is defined by a module parameter, with an hard
318*67711e04SFrancesco Valla  limit imposed at build time.
319*67711e04SFrancesco Valla
320*67711e04SFrancesco Valla* when a transmission is in progress, subsequent calls to ``write(2)`` will
321*67711e04SFrancesco Valla  block, while calls to ``send(2)`` will either block or fail depending on the
322*67711e04SFrancesco Valla  presence of the ``MSG_DONTWAIT`` flag.
323*67711e04SFrancesco Valla
324*67711e04SFrancesco Valla* no support is present for sending "wait frames": whether a PDU can be fully
325*67711e04SFrancesco Valla  received or not is decided when the First Frame is received.
326*67711e04SFrancesco Valla
327*67711e04SFrancesco VallaErrors
328*67711e04SFrancesco Valla------
329*67711e04SFrancesco Valla
330*67711e04SFrancesco VallaFollowing errors are reported to userspace:
331*67711e04SFrancesco Valla
332*67711e04SFrancesco VallaRX path errors
333*67711e04SFrancesco Valla~~~~~~~~~~~~~~
334*67711e04SFrancesco Valla
335*67711e04SFrancesco Valla============ ===============================================================
336*67711e04SFrancesco Valla-ETIMEDOUT   timeout of data reception
337*67711e04SFrancesco Valla-EILSEQ      sequence number mismatch during a multi-frame reception
338*67711e04SFrancesco Valla-EBADMSG     data reception with wrong padding
339*67711e04SFrancesco Valla============ ===============================================================
340*67711e04SFrancesco Valla
341*67711e04SFrancesco VallaTX path errors
342*67711e04SFrancesco Valla~~~~~~~~~~~~~~
343*67711e04SFrancesco Valla
344*67711e04SFrancesco Valla========== =================================================================
345*67711e04SFrancesco Valla-ECOMM     flow control reception timeout
346*67711e04SFrancesco Valla-EMSGSIZE  flow control reception overflow
347*67711e04SFrancesco Valla-EBADMSG   flow control reception with wrong layout/padding
348*67711e04SFrancesco Valla========== =================================================================
349*67711e04SFrancesco Valla
350*67711e04SFrancesco VallaExamples
351*67711e04SFrancesco Valla========
352*67711e04SFrancesco Valla
353*67711e04SFrancesco VallaBasic node example
354*67711e04SFrancesco Valla------------------
355*67711e04SFrancesco Valla
356*67711e04SFrancesco VallaFollowing example implements a node using "normal" physical addressing, with
357*67711e04SFrancesco VallaRX ID equal to 0x18DAF142 and a TX ID equal to 0x18DA42F1. All options are left
358*67711e04SFrancesco Vallato their default.
359*67711e04SFrancesco Valla
360*67711e04SFrancesco Valla.. code-block:: C
361*67711e04SFrancesco Valla
362*67711e04SFrancesco Valla  int s;
363*67711e04SFrancesco Valla  struct sockaddr_can addr;
364*67711e04SFrancesco Valla  int ret;
365*67711e04SFrancesco Valla
366*67711e04SFrancesco Valla  s = socket(PF_CAN, SOCK_DGRAM, CAN_ISOTP);
367*67711e04SFrancesco Valla  if (s < 0)
368*67711e04SFrancesco Valla      exit(1);
369*67711e04SFrancesco Valla
370*67711e04SFrancesco Valla  addr.can_family = AF_CAN;
371*67711e04SFrancesco Valla  addr.can_ifindex = if_nametoindex("can0");
372*67711e04SFrancesco Valla  addr.tp.tx_id = 0x18DA42F1 | CAN_EFF_FLAG;
373*67711e04SFrancesco Valla  addr.tp.rx_id = 0x18DAF142 | CAN_EFF_FLAG;
374*67711e04SFrancesco Valla
375*67711e04SFrancesco Valla  ret = bind(s, (struct sockaddr *)&addr, sizeof(addr));
376*67711e04SFrancesco Valla  if (ret < 0)
377*67711e04SFrancesco Valla      exit(1);
378*67711e04SFrancesco Valla
379*67711e04SFrancesco Valla  /* Data can now be received using read(s, ...) and sent using write(s, ...) */
380*67711e04SFrancesco Valla
381*67711e04SFrancesco VallaAdditional examples
382*67711e04SFrancesco Valla-------------------
383*67711e04SFrancesco Valla
384*67711e04SFrancesco VallaMore complete (and complex) examples can be found inside the ``isotp*`` userland
385*67711e04SFrancesco Vallatools, distributed as part of the ``can-utils`` utilities at:
386*67711e04SFrancesco Vallahttps://github.com/linux-can/can-utils
387