Documentation: networking: document CAN ISO-TP
Subsystems (4)
cover Documentation: networking: document CAN ISO-TP
While the in-kernel ISO-TP stack is fully functional and easy to use, no documentation exists for it. This patch adds such documentation, containing the very basics of the protocol, the APIs and a basic example.
Sending as RFC because my experience with the stack is as user and not as its developer, and also because it's my first kernel contribution.
Thank you,
Francesco
Francesco Valla (1):
Documentation: networking: document CAN ISO-TP
Documentation/networking/index.rst | 1 + Documentation/networking/isotp.rst | 347 +++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+) create mode 100644 Documentation/networking/isotp.rst
Signature · 1 line
2.44.0
PATCH 1/1 Documentation: networking: document CAN ISO-TP
Document basic concepts, APIs and behaviour of the CAN ISO-TP (ISO 15765-2) stack.
--- Documentation/networking/index.rst | 1 + Documentation/networking/isotp.rst | 347 +++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+) create mode 100644 Documentation/networking/isotp.rst
Documentation/networking/index.rst +1 -0
@@ -19,6 +19,7 @@ Contents: caif/index ethtool-netlink ieee802154 + isotp j1939 kapi msg_zerocopy
Documentation/networking/isotp.rst new file +347 -0
347 lines not on this page · raw message
Signature · 1 line
2.44.0
Marc Kleine-Budde
maintainerHello Francesco,
thanks for your contribution! I've some remarks to make it a valid rst file.
Quoted 28 lines · Francesco Valla
Document basic concepts, APIs and behaviour of the CAN ISO-TP (ISO 15765-2) stack.
Signed-off-by Francesco Valla <[email protected]>--- Documentation/networking/index.rst | 1 + Documentation/networking/isotp.rst | 347 +++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+) create mode 100644 Documentation/networking/isotp.rstDocumentation/networking/index.rst +1
-0@@ -19,6 +19,7 @@ Contents: caif/index ethtool-netlink ieee802154 + isotp j1939 kapi msg_zerocopyDocumentation/networking/isotp.rst new file +0
-0
Documentation/networking/isotp.rst line 5
Quoted 5 lines
Documentation/networking/isotp.rst new file +5
-0@@ -0,0 +1,347 @@ +.. SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) + +==================== +ISO-TP (ISO 15765-2) Transport Protocol +====================
Please make the "=" as long as the text it encloses.
Documentation/networking/isotp.rst line 8
Quoted 3 lines
Documentation/networking/isotp.rst new file +3
-0+ +Overview +=========================
Same here
[...]
Quoted 5 lines
Documentation/networking/isotp.rst new file +5
-0+Reception stmin +~~~~~~~~~~~~~~~ + +The reception minimum separaton time (stmin) can be forced using the +``CAN_ISOTP_RX_STMIN`` optname and providing an stmin value in microseconds as
Documentation/networking/isotp.rst line 275
Quoted 10 lines
Documentation/networking/isotp.rst new file +10
-0+a 32bit unsigned integer; received Consecutive Frames (CF) which timestamps +differ less than this value will be ignored: + +.. code-block:: C + + uint32_t stmin; + ret = setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_RX_STMIN, &stmin, sizeof(stmin)); + +Multi-frame transport support +--------------------------
same here
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
Quoted 5 lines · Marc Kleine-Budde
Hello Francesco,
thanks for your contribution! I've some remarks to make it a valid rst file.
I did a bit of rework on section titles just before sending and obviously forgot to update the separators. Will do that in the v2 patch.
Thanks for the review!
Regards,
Francesco
-- (reduced the distribution list to Linux-CAN relevant receivers)
Hello Francesco,
many thanks for your contribution!
Additionally to the editorial remarks from Marc I would like to add some technical feedback.
Quoted 15 lines · Francesco Valla
Document basic concepts, APIs and behaviour of the CAN ISO-TP (ISO 15765-2) stack.
Signed-off-by Francesco Valla <[email protected]>--- Documentation/networking/index.rst | 1 + Documentation/networking/isotp.rst | 347 +++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+)create mode 100644
Documentation/networking/isotp.rstDocumentation/networking/index.rst +0
-0
Documentation/networking/index.rst Contents: · line 22
Quoted 4 lines
Documentation/networking/index.rst +1
-0@@ -19,6 +19,7 @@ Contents: caif/index ethtool-netlink ieee802154 + isotp
I'm not sure whether to name this file "iso15765-2" instead of just "isotp". IIRC there are some more transport protocols inside the ISO universe.
Documentation/networking/isotp.rst line 4
Quoted 13 lines
Documentation/networking/index.rst +0
-0j1939 kapi msg_zerocopyDocumentation/networking/isotp.rst new file +4
-0@@ -0,0 +1,347 @@ +.. SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) + +==================== +ISO-TP (ISO 15765-2) Transport Protocol
ISO 15765-2:2016
Documentation/networking/isotp.rst line 10
Quoted 6 lines
Documentation/networking/isotp.rst new file +6
-0+==================== + +Overview +========================= + +ISO-TP, also known as ISO 15765-2 from the ISO standard it is defined in, is a
CAN ISO-TP , also known as ISO 15765-2:2016 ...
Documentation/networking/isotp.rst line 16
Quoted 6 lines
Documentation/networking/isotp.rst new file +6
-0+transport protocol specifically defined for diagnostic communication on CAN. +It is widely used in the automotive industry, for example as the transport +protocol for UDSonCAN (ISO 14229-3) or emission-related diagnostic services +(ISO 15031-5). + +ISO-TP can be used both on classical (2.0B) CAN and CAN-FD based networks.
CAN CC (aka Classical CAN, CAN 2.0B) and CAN FD (CAN with Flexible Datarate)
Documentation/networking/isotp.rst line 23
Quoted 7 lines
Documentation/networking/isotp.rst new file +7
-0+It is also designed to be compatible with a CAN network using SAE J1939 as data +link layer (however, this is not a requirement). + +Addressing +---------- + +In its simplest form, ISO-TP is based on two kinds of addresses for the nodes
two kinds of addressing-modes
Documentation/networking/isotp.rst line 27
Quoted 4 lines
Documentation/networking/isotp.rst new file +4
-0+connected to the same network: + +- a physical address, which identifies a single node and is used in 1-to-1 + communication
physical addressing is implemented by two node-specific addresses (CAN identifiers) and is used ...
Documentation/networking/isotp.rst line 29
Quoted 2 lines
Documentation/networking/isotp.rst new file +2
-0+- a functional addess, which identifies a group of nodes and is used in 1-to-N + communication
functional addressing is implemented by one node-specific address (CAN identifier) and is used ...
Documentation/networking/isotp.rst
Quoted 3 lines
Documentation/networking/isotp.rst new file +3
-0+ +In a so-called "normal" addressing scenario, both these addresses are +represented by a single byte
No. The normal addressing always needs two CAN IDs (assigned to two different CAN nodes) or you have functional addressing which needs only the sender CAN ID for the 1:N unconfirmed transmission.
and can be inserted inside the 29-bit version of
Documentation/networking/isotp.rst line 36
Quoted 7 lines
Documentation/networking/isotp.rst new file +1
-0+the CAN ID.However, in order to support larger networks, an "extended"
Documentation/networking/isotp.rst new file +3
-0+addressing scheme can be adopted; in this case, the first byte of the data +payload is used as an additional component of the address (both for the +physical and functional cases).
Yes. This is called extended addressing.
It still needs the normal addressing scheme with the one or two CAN IDs.
Documentation/networking/isotp.rst line 45
Quoted 9 lines
Documentation/networking/isotp.rst new file +9
-0+ +Transport protocol and associated frame types +--------------------------------------------- + +When transmitting data using the ISO-TP protocol, the payload can either fit +inside one single CAN message or not, also considering the overhead the protocol +is generating and the optional extended addressing. In the first case, the data +is transmitted at once using a so-called Single Frame (SF). In the second case, +ISO-TP defines a multi-frame protocol, in which the sender asks (through a First
... in which the sender provided the PDU length which is to be transmitted and also asks for a Flow Control frame which provides the blocksize and stmin stuff
Documentation/networking/isotp.rst line 57
Quoted 12 lines
Documentation/networking/isotp.rst new file +12
-0+Frame - FF) to the receiver the maximum supported size of a macro data block +(``blocksize``) and the minimum time time between the single CAN messages +composing such block (``stmin``). Once these informations have been received, +the sender starts to send frames containing fragments of the data payload +(called Consecutive Frames - CF), stopping after every ``blocksize``-sized block +to wait confirmation from the receiver (which should then send a Flow Control +frame - FC - to inform the sender about its availability to receive more data). + +Specifications used +------------------- + +* ISO 15765-2 : Road vehicles - Diagnostic communication over Controller Area
ISO 15765-2:2016
Documentation/networking/isotp.rst line 64
Quoted 7 lines
Documentation/networking/isotp.rst new file +7
-0+ Network (DoCAN). Part 2: Transport protocol and network layer services. + +How to Use ISO-TP +================= + +As with others CAN protocols, the ISO-TP stack support is built as a variant of +the SocketCAN communication, and thus uses the socket APIs.
As with others CAN protocols, the ISO-TP stack support is built into the Linux network subsystem for the CAN bus, aka. Linux-CAN or SocketCAN and thus follows the same socket API.
Quoted 9 lines
Documentation/networking/isotp.rst new file +9
-0+ +Creation and basic usage of an ISO-TP socket +-------------------------------------------- + +To use the ISO-TP stack, ``#include <linux/can/isotp.h>`` shall be used. A +socket can then be created using the ``PF_CAN`` protocol family, the +``SOCK_DGRAM`` type (as the underlying protocol is datagram-based by design) +and the ``CAN_ISOTP`` protocol: +
Documentation/networking/isotp.rst line 83
Quoted 10 lines
Documentation/networking/isotp.rst new file +10
-0+.. code-block:: C + + s = socket(PF_CAN, SOCK_DGRAM, CAN_ISOTP); + +After the socket has been successfully created, ``bind(2)`` shall be called to +bind the socket to the desired CAN interface, either: + +* specifying at least one RX or TX address, as part of the sockaddr supplied + to the call itself, or +* after specifying broadcast flags through socket option (explained below)
You always need at least ONE CAN ID for sending (tx_id).
When you do not use the broadcasting modes CAN_ISOTP_SF_BROADCAST nor CAN_ISOTP_CF_BROADCAST you need the rx_id (for receiving the FC) too.
Documentation/networking/isotp.rst line 88
Quoted 5 lines
Documentation/networking/isotp.rst new file +5
-0+ +Once bound to an interface, the socket can be read from and written to using +the usual ``read(2)`` and ``write(2)`` system calls, as well as ``send(2)``, +``sendmsg(2)``, ``recv(2)`` and ``recvmsg(2)``. +Unlike raw SocketCAN sockets, only the data payload shall be specified in all
Unlike the CAN_RAW socket API ...
Quoted 50 lines
Documentation/networking/isotp.rst new file +50
-0+these calls, as the CAN header is automatically filled by the ISO-TP stack +using information supplied during socket creation. In the same way, the stack +will use the transport mechanism when required (i.e., when the size of the data +payload exceeds the MTU of the underlying CAN bus). + +The sockaddr structure used for SocketCAN has extensions for use with ISO-TP, +as specified below: + +.. code-block:: C + + struct sockaddr_can { + sa_family_t can_family; + int can_ifindex; + union { + struct { canid_t rx_id, tx_id; } tp; + ... + } can_addr; + } + +* ``can_family`` and ``can_ifindex`` serve the same purpose as for other + SocketCAN sockets. + +* ``can_addr.tp.rx_id`` specifies the receive (RX) CAN ID and will be used as + a RX filter. + +* ``can_addr.tp.tx_id`` specifies the transmit (TX) CAN ID + +ISO-TP socket options +--------------------- + +When creating an ISO-TP socket, reasonable defaults are set. Some options can +be modified with ``setsockopt(2)`` and/or read back with ``getsockopt(2)``. + +General options +~~~~~~~~~~~~~~~ + +General socket options can be passed using the ``CAN_ISOTP_OPTS`` optname: + +.. code-block:: C + + struct can_isotp_options opts; + ret = setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_OPTS, &opts, sizeof(opts)) + +where the ``can_isotp_options`` structure has the following contents: + +.. code-block:: C + + struct can_isotp_options { + u32 flags; + u32 frame_txtime;
Documentation/networking/isotp.rst line 148
Quoted 10 lines
Documentation/networking/isotp.rst new file +10
-0+ u8 ext_address; + u8 txpad_content; + u8 rxpad_content; + u8 rx_ext_address; + }; + +* ``flags``: modifiers to be applied to the default behaviour of the ISO-TP + stack. Following flags are available: + + - ``CAN_ISOTP_LISTEN_MODE``: listen only (do not send FC frames)
a testing feature
Quoted 5 lines
Documentation/networking/isotp.rst new file +5
-0+ - ``CAN_ISOTP_EXTEND_ADDR``: enable extended addressing, using the byte + specified in ``ext_address`` as additional address byte. + - ``CAN_ISOTP_TX_PADDING``: enable padding for tranmsitted frames, using + ``txpad_content`` as value for the padding bytes. + - ``CAN_ISOTP_RX_PADDING``: enable padding for the received frames, using
Documentation/networking/isotp.rst line 163
Quoted 10 lines
Documentation/networking/isotp.rst new file +10
-0+ ``rxpad_content`` as value for the padding bytes. + - ``CAN_ISOTP_CHK_PAD_LEN``: check for correct padding length on the received + frames. + - ``CAN_ISOTP_CHK_PAD_DATA``: check padding bytes on the received frames + against ``rxpad_content``; if ``CAN_ISOTP_RX_PADDING`` is not specified, + this flag is ignored. + - ``CAN_ISOTP_HALF_DUPLEX``: force ISO-TP socket in half duples mode + (that is, transport mechanism can only be incoming or outgoing at the same + time, not both) + - ``CAN_ISOTP_FORCE_TXSTMIN``: ignore stmin from received FC
a testing feature
Quoted 1 line
+ - ``CAN_ISOTP_FORCE_RXSTMIN``: ignore CFs depending on rx stmin
a testing feature
Documentation/networking/isotp.rst line 172
Quoted 8 lines
Documentation/networking/isotp.rst new file +8
-0+ - ``CAN_ISOTP_RX_EXT_ADDR``: use ``rx_ext_address`` instead of ``ext_address`` + as extended addressing byte on the reception path. + - ``CAN_ISOTP_WAIT_TX_DONE``: wait until the frame is sent before returning + from ``write(2)`` and ``send(2)`` calls (i.e., blocking write operations). + - ``CAN_ISOTP_SF_BROADCAST``: use 1-to-N functional addressing (cannot be + specified alongside ``CAN_ISOTP_CF_BROADCAST``) + - ``CAN_ISOTP_CF_BROADCAST``: use 1-to-N transmission without flow control + (cannot be specified alongside ``CAN_ISOTP_SF_BROADCAST``)
Btw. this mode is not covered by the ISO 15765-2 standard yet.
Quoted 11 lines
Documentation/networking/isotp.rst new file +11
-0+ - ``CAN_ISOTP_DYN_FC_PARMS``: enable dynamic update of flow control parameters + +* ``frame_txtime``: frame transmission time (defined as N_As/N_Ar inside the + ISO standard); if ``0``, the default (or the last set value) is used. + To set the transmission time to ``0``, the ``CAN_ISOTP_FRAME_TXTIME_ZERO`` + macro (equal to 0xFFFFFFFF) shall be used. + +* ``ext_address``: extended addressing byte, used if the + ``CAN_ISOTP_EXTEND_ADDR`` flag is specified. + +* ``txpad_content``: byte used as padding value for transmitted frames
Documentation/networking/isotp.rst line 193
Quoted 10 lines
Documentation/networking/isotp.rst new file +10
-0+ +* ``rxpad_content``: byte used as padding value for received frames + +* ``rx_ext_address``: extended addressing byte for the reception path, used if + the ``CAN_ISOTP_RX_EXT_ADDR`` flag is specified. + +Flow Control options +~~~~~~~~~~~~~~~~~~~~ + +Flow Control (FC) options can be passed using the ``CAN_ISOTP_RECV_FC`` optname:
to provide the communication parameters for receiving ISO-TP PDUs.
Quoted 40 lines
Documentation/networking/isotp.rst new file +40
-0+ +.. code-block:: C + + struct can_isotp_fc_options fc_opts; + ret = setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_RECV_FC, &fc_opts, sizeof(fc_opts)); + +where the ``can_isotp_fc_options`` structure has the following contents: + +.. code-block:: C + + struct can_isotp_options { + u8 bs; + u8 stmin; + u8 wftmax; + }; + +* ``bs``: blocksize provided in flow control frames. + +* ``stmin``: minimum separation time provided in flow control frames; can + have the following values (others are reserved): + - 0x00 - 0x7F : 0 - 127 ms + - 0xF1 - 0xF9 : 100 us - 900 us + +* ``wftmax``: maximum number of wait frames provided in flow control frames. + +Link Layer options +~~~~~~~~~~~~~~~~~~ + +Link Layer (LL) options can be passed using the ``CAN_ISOTP_LL_OPTS`` optname: + +.. code-block:: C + + struct can_isotp_ll_options ll_opts; + ret = setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_LL_OPTS, &ll_opts, sizeof(ll_opts)); + +where the ``can_isotp_ll_options`` structure has the following contents: + +.. code-block:: C + + struct can_isotp_ll_options {
Documentation/networking/isotp.rst line 243
Quoted 10 lines
Documentation/networking/isotp.rst new file +10
-0+ u8 mtu; + u8 tx_dl; + u8 tx_flags; + }; + +* ``mtu``: generated and accepted CAN frame type, can be equal to ``CAN_MTU`` + for classical CAN frames or ``CANFD_MTU`` for CAN FD frames. + +* ``tx_dl``: maximum payload length for transmitted frames, can have one value + among: 8, 12, 16, 20, 24, 32, 48, 64.
Values above 8 only apply to CAN FD traffic (mtu = CANFD_MTU).
Documentation/networking/isotp.rst line 246
Quoted 3 lines
Documentation/networking/isotp.rst new file +3
-0+ +* ``tx_flags``: flags set set into ``struct canfd_frame.flags`` at frame + creation.
Only applies to CAN FD traffic (mtu = CANFD_MTU).
Quoted 78 lines
Documentation/networking/isotp.rst new file +78
-0+ +Transmission stmin +~~~~~~~~~~~~~~~~~~ + +The transmission minimum separaton time (stmin) can be forced using the +``CAN_ISOTP_TX_STMIN`` optname and providing an stmin value in microseconds as +a 32bit unsigned integer; this will overwrite the value sent by the receiver in +flow control frames: + +.. code-block:: C + + uint32_t stmin; + ret = setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_TX_STMIN, &stmin, sizeof(stmin)); + +Reception stmin +~~~~~~~~~~~~~~~ + +The reception minimum separaton time (stmin) can be forced using the +``CAN_ISOTP_RX_STMIN`` optname and providing an stmin value in microseconds as +a 32bit unsigned integer; received Consecutive Frames (CF) which timestamps +differ less than this value will be ignored: + +.. code-block:: C + + uint32_t stmin; + ret = setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_RX_STMIN, &stmin, sizeof(stmin)); + +Multi-frame transport support +-------------------------- + +The ISO-TP stack contained inside the Linux kernel supports the multi-frame +transport mechanism defined by the standard, with the following contraints: + +* the maximum size of a PDU is defined by a module parameter, with an hard + limit imposed at build time +* when a transmission is in progress, subsequent calls to ``write(2)`` will + block, while calls to ``send(2)`` will either block or fail depending on the + presence of the ``MSG_DONTWAIT`` flag +* no support is present for sending "wait frames": wheter a PDU can be fully + received or not is decided when the First Frame is received + +Errors +------ + +Following errors are reported to userspace: + +RX path errors +~~~~~~~~~~~~~~ + +============ ================================================================= +-ETIMEDOUT timeout of data reception +-EILSEQ sequence number mismatch during a multi-frame reception +-EBADMSG data reception with wrong padding +============ ================================================================= + +TX path errors +~~~~~~~~~~~~~~ + +========== ================================================================= +-ECOMM flow control reception timeout +-EMSGSIZE flow control reception overflow +-EBADMSG flow control reception with wrong layout/padding +========== ================================================================= + +Examples +======== + +Basic node example +------------------ + +Following example implements a node using "normal" physical addressing, with +RX ID equal to 0x18DAF142 and a TX ID equal to 0x18DA42F1. All options are left +to their default. + +.. code-block:: C + + int s; + struct sockaddr_can addr;
Documentation/networking/isotp.rst line 334
Quoted 10 lines
Documentation/networking/isotp.rst new file +10
-0+ int ret; + + s = socket(PF_CAN, SOCK_DGRAM, CAN_ISOTP); + if (s < 0) + exit(1); + + addr.can_family = AF_CAN; + addr.can_ifindex = if_nametoindex("can0"); + addr.tp.tx_id = 0x18DA42F1; + addr.tp.rx_id = 0x18DAF142;
Shouldn't this be (0x18DA42F1 | CAN_EFF_FLAG) for 29 bit IDs?
When you provide an example with 11 bit IDs (e.g. 0x700 and 0x714) you don't need to care about the CAN_EFF_FLAG.
Documentation/networking/isotp.rst line 347
Quoted 13 lines
Documentation/networking/isotp.rst new file +13
-0+ + ret = bind(s, (struct sockaddr *)&addr, sizeof(addr)); + if (ret < 0) + exit(1); + + // Data can now be received using read(s, ...) and sent using write(s, ...) + +Additional examples +------------------- + +More complete (and complex) examples can be found inside the ``isotp*`` userland +tools, distributed as part of the ``can-utils`` utilities at: +https://github.com/linux-can/can-utils
Many thanks,
Oliver
Hi Oliver,
Quoted 4 lines · Oliver Hartkopp
Quoted 4 lines
Documentation/networking/index.rst +0
-0
Quoted 9 lines
Documentation/networking/index.rst Contents: · line 22
Quoted 5 lines
Documentation/networking/index.rst +1
-0@@ -19,6 +19,7 @@ Contents: caif/index ethtool-netlink ieee802154 + isotpI'm not sure whether to name this file "iso15765-2" instead of just "isotp". IIRC there are some more transport protocols inside the ISO universe.
This was my doubt as well, I decided to name it "isotp" to be aligned with the source file that contains the implementation. But I can rename it if you think is better / more understandable.
There are for sure other ISO protocols implementing a transport - first that comes to my mind is the transport part inside ISO11783/ISOBUS.
Quoted 5 lines
Documentation/networking/index.rst Contents: · line 24
Quoted 2 lines
Documentation/networking/index.rst +2
-0+==================== +ISO-TP (ISO 15765-2) Transport ProtocolISO 15765-2:2016
Noted.
Quoted 9 lines
Documentation/networking/index.rst Contents:
Quoted 6 lines
Documentation/networking/index.rst +6
-0+==================== + +Overview +========================= + +ISO-TP, also known as ISO 15765-2 from the ISO standard it is defined in, is aCAN ISO-TP , also known as ISO 15765-2:2016 ...
Noted, as before.
Quoted 9 lines
Documentation/networking/index.rst
Quoted 6 lines
Documentation/networking/index.rst +6
-0+transport protocol specifically defined for diagnostic communication on CAN. +It is widely used in the automotive industry, for example as the transport +protocol for UDSonCAN (ISO 14229-3) or emission-related diagnostic services +(ISO 15031-5). + +ISO-TP can be used both on classical (2.0B) CAN and CAN-FD based networks.CAN CC (aka Classical CAN, CAN 2.0B) and CAN FD (CAN with Flexible Datarate)
Ok
Quoted 10 lines
Documentation/networking/index.rst
Quoted 7 lines
Documentation/networking/index.rst +7
-0+It is also designed to be compatible with a CAN network using SAE J1939 as data +link layer (however, this is not a requirement). + +Addressing +---------- + +In its simplest form, ISO-TP is based on two kinds of addresses for the nodestwo kinds of addressing-modes
Ok
Quoted 8 lines
Documentation/networking/index.rst
Quoted 4 lines
Documentation/networking/index.rst +4
-0+connected to the same network: + +- a physical address, which identifies a single node and is used in 1-to-1 + communicationphysical addressing is implemented by two node-specific addresses (CAN identifiers) and is used ...
(see below)
Quoted 6 lines
Quoted 2 lines
+- a functional addess, which identifies a group of nodes and is used in 1-to-N + communicationfunctional addressing is implemented by one node-specific address (CAN identifier) and is used ...
(see below)
Quoted 8 lines
Documentation/networking/index.rst
Quoted 3 lines
Documentation/networking/index.rst +3
-0+ +In a so-called "normal" addressing scenario, both these addresses are +represented by a single byteNo. The normal addressing always needs two CAN IDs (assigned to two different CAN nodes) or you have functional addressing which needs only the sender CAN ID for the 1:N unconfirmed transmission.
Here I was referring to the N_TA address defined by the standard, which is defined as 8 bits long and can identify either one single node (in physical addressing) or a group of nodes (in functional addressing). But from the point of view of a user and not a network planner referring to CAN IDs is probably a better approach.
Quoted 11 lines
Documentation/networking/index.rst
Quoted 6 lines
However, in order to support larger networks, an "extended"
Documentation/networking/index.rst +3
-0+addressing scheme can be adopted; in this case, the first byte of the data +payload is used as an additional component of the address (both for the +physical and functional cases).Yes. This is called extended addressing.
It still needs the normal addressing scheme with the one or two CAN IDs.
I'll add this note to the description of the extended addressing.
Quoted 5 lines
Quoted 5 lines
Documentation/networking/index.rst +5
-0+ +Transport protocol and associated frame types +--------------------------------------------- + +When transmitting data using the ISO-TP protocol, the payload can either fit
Quoted 9 lines
Documentation/networking/index.rst
Quoted 4 lines
Documentation/networking/index.rst +4
-0+inside one single CAN message or not, also considering the overhead the protocol +is generating and the optional extended addressing. In the first case, the data +is transmitted at once using a so-called Single Frame (SF). In the second case, +ISO-TP defines a multi-frame protocol, in which the sender asks (through a First... in which the sender provided the PDU length which is to be transmitted and also asks for a Flow Control frame which provides the blocksize and stmin stuff
Ok
Quoted 7 lines
Documentation/networking/index.rst
Quoted 5 lines
Documentation/networking/index.rst +5
-0+ +Specifications used +------------------- + +* ISO 15765-2 : Road vehicles - Diagnostic communication over Controller AreaISO 15765-2:2016
Noted
Quoted 11 lines
Documentation/networking/index.rst
Quoted 6 lines
Documentation/networking/index.rst +6
-0+ +How to Use ISO-TP +================= + +As with others CAN protocols, the ISO-TP stack support is built as a variant of +the SocketCAN communication, and thus uses the socket APIs.As with others CAN protocols, the ISO-TP stack support is built into the Linux network subsystem for the CAN bus, aka. Linux-CAN or SocketCAN and thus follows the same socket API.
Ok
Quoted 9 lines
Documentation/networking/index.rst
Quoted 6 lines
Documentation/networking/index.rst +6
-0+After the socket has been successfully created, ``bind(2)`` shall be called to +bind the socket to the desired CAN interface, either: + +* specifying at least one RX or TX address, as part of the sockaddr supplied + to the call itself, or +* after specifying broadcast flags through socket option (explained below)You always need at least ONE CAN ID for sending (
tx_id).
Quoted 3 lines
When you do not use the broadcasting modes
CAN_ISOTP_SF_BROADCASTnorCAN_ISOTP_CF_BROADCASTyou need therx_id(for receiving the FC) too.
Couldn't listen-only mode be used without specifying a tx_id?
Nevertheless, I'll reword "address" as "CAN ID".
Quoted 8 lines
Documentation/networking/index.rst
Quoted 5 lines
Documentation/networking/index.rst +5
-0+ +Once bound to an interface, the socket can be read from and written to using +the usual ``read(2)`` and ``write(2)`` system calls, as well as ``send(2)``, +``sendmsg(2)``, ``recv(2)`` and ``recvmsg(2)``. +Unlike raw SocketCAN sockets, only the data payload shall be specified in allUnlike the
CAN_RAWsocket API ...
Ok
Quoted 4 lines
Documentation/networking/index.rst
Quoted 2 lines
Documentation/networking/index.rst +2
-0+ + - ``CAN_ISOTP_LISTEN_MODE``: listen only (do not send FC frames)a testing feature
I'll add "normally used as a testing feature".
Quoted 15 lines
Quoted 5 lines
Documentation/networking/index.rst +5
-0+ - ``CAN_ISOTP_EXTEND_ADDR``: enable extended addressing, using the byte + specified in ``ext_address`` as additional address byte. + - ``CAN_ISOTP_TX_PADDING``: enable padding for tranmsitted frames, using + ``txpad_content`` as value for the padding bytes. + - ``CAN_ISOTP_RX_PADDING``: enable padding for the received frames, usingDocumentation/networking/index.rst
Quoted 10 lines
Documentation/networking/index.rst +10
-0+ ``rxpad_content`` as value for the padding bytes. + - ``CAN_ISOTP_CHK_PAD_LEN``: check for correct padding length on the received + frames. + - ``CAN_ISOTP_CHK_PAD_DATA``: check padding bytes on the received frames + against ``rxpad_content``; if ``CAN_ISOTP_RX_PADDING`` is not specified, + this flag is ignored. + - ``CAN_ISOTP_HALF_DUPLEX``: force ISO-TP socket in half duples mode + (that is, transport mechanism can only be incoming or outgoing at the same + time, not both) + - ``CAN_ISOTP_FORCE_TXSTMIN``: ignore stmin from received FC
Quoted 2 lines
a testing feature
(see above)
Quoted 3 lines
Quoted 1 line
+ - ``CAN_ISOTP_FORCE_RXSTMIN``: ignore CFs depending on rx stmin
a testing feature
(again, see above)
Quoted 10 lines
Documentation/networking/index.rst
Quoted 8 lines
Documentation/networking/index.rst +8
-0+ - ``CAN_ISOTP_RX_EXT_ADDR``: use ``rx_ext_address`` instead of ``ext_address`` + as extended addressing byte on the reception path. + - ``CAN_ISOTP_WAIT_TX_DONE``: wait until the frame is sent before returning + from ``write(2)`` and ``send(2)`` calls (i.e., blocking write operations). + - ``CAN_ISOTP_SF_BROADCAST``: use 1-to-N functional addressing (cannot be + specified alongside ``CAN_ISOTP_CF_BROADCAST``) + - ``CAN_ISOTP_CF_BROADCAST``: use 1-to-N transmission without flow control + (cannot be specified alongside ``CAN_ISOTP_SF_BROADCAST``)Btw. this mode is not covered by the ISO 15765-2 standard yet.
Good to know, I was wondering why this was introduced, as I was not remembering it from when I read the standard a couple of years ago. Will it be part of the next revision (which is saw is under publication)?
Quoted 8 lines
Documentation/networking/index.rst
Quoted 5 lines
Documentation/networking/index.rst +5
-0+ +Flow Control options +~~~~~~~~~~~~~~~~~~~~ + +Flow Control (FC) options can be passed using the ``CAN_ISOTP_RECV_FC`` optname:to provide the communication parameters for receiving ISO-TP PDUs.
Ok
Quoted 9 lines
Documentation/networking/index.rst
Quoted 6 lines
Documentation/networking/index.rst +6
-0+ +* ``mtu``: generated and accepted CAN frame type, can be equal to ``CAN_MTU`` + for classical CAN frames or ``CANFD_MTU`` for CAN FD frames. + +* ``tx_dl``: maximum payload length for transmitted frames, can have one value + among: 8, 12, 16, 20, 24, 32, 48, 64.Values above 8 only apply to CAN FD traffic (mtu =
CANFD_MTU).
Right, I'll add a note.
Quoted 6 lines
Documentation/networking/index.rst
Quoted 3 lines
Documentation/networking/index.rst +3
-0+ +* ``tx_flags``: flags set set into ``struct canfd_frame.flags`` at frame + creation.Only applies to CAN FD traffic (mtu =
CANFD_MTU).
(see above)
Quoted 25 lines
Quoted 12 lines
Documentation/networking/index.rst +12
-0+ +Basic node example +------------------ + +Following example implements a node using "normal" physical addressing, with +RX ID equal to 0x18DAF142 and a TX ID equal to 0x18DA42F1. All options are left +to their default. + +.. code-block:: C + + int s; + struct sockaddr_can addr;Documentation/networking/index.rst
Quoted 10 lines
Documentation/networking/index.rst +10
-0+ int ret; + + s = socket(PF_CAN, SOCK_DGRAM, CAN_ISOTP); + if (s < 0) + exit(1); + + addr.can_family = AF_CAN; + addr.can_ifindex = if_nametoindex("can0"); + addr.tp.tx_id = 0x18DA42F1; + addr.tp.rx_id = 0x18DAF142;Shouldn't this be (
0x18DA42F1|CAN_EFF_FLAG) for 29 bit IDs?
Quoted 3 lines
When you provide an example with 11 bit IDs (e.g.
0x700and0x714) you don't need to care about theCAN_EFF_FLAG.
Correct, I always forget the CAN_EFF_FLAG.
Thank you for the very thorough review! I'll wait for other feedbacks (if any) and then start working on the v2.
Regards,
Francesco
Quoted 28 lines · Francesco Valla
Document basic concepts, APIs and behaviour of the CAN ISO-TP (ISO 15765-2) stack.
Signed-off-by Francesco Valla <[email protected]>--- Documentation/networking/index.rst | 1 + Documentation/networking/isotp.rst | 347 +++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+) create mode 100644 Documentation/networking/isotp.rstDocumentation/networking/index.rst +1
-0@@ -19,6 +19,7 @@ Contents: caif/index ethtool-netlink ieee802154 + isotp j1939 kapi msg_zerocopyDocumentation/networking/isotp.rst new file +0
-0
Documentation/networking/isotp.rst line 9
Quoted 9 lines
Documentation/networking/isotp.rst new file +9
-0@@ -0,0 +1,347 @@ +.. SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) + +==================== +ISO-TP (ISO 15765-2) Transport Protocol +==================== + +Overview +========================= +
<snipped>...
Documentation/networking/isotp.rst line 12
Quoted 3 lines
Documentation/networking/isotp.rst new file +3
-0+Multi-frame transport support +-------------------------- +
htmldocs build reports new warnings:
/home/bagas/repo/linux-kernel/Documentation/networking/isotp.rst:3: WARNING: Title overline too short.
====================
ISO-TP (ISO 15765-2) Transport Protocol
====================/home/bagas/repo/linux-kernel/Documentation/networking/isotp.rst:275: WARNING: Title underline too short.
Multi-frame transport support
--------------------------/home/bagas/repo/linux-kernel/Documentation/networking/isotp.rst:275: WARNING: Title underline too short.
Multi-frame transport support
--------------------------
I have applied the fixup:
---- >8 ----
Documentation/networking/isotp.rst +4 -4
@@ -1,11 +1,11 @@ .. SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) -==================== +======================================= ISO-TP (ISO 15765-2) Transport Protocol -==================== +======================================= Overview -========================= +======== ISO-TP, also known as ISO 15765-2 from the ISO standard it is defined in, is a transport protocol specifically defined for diagnostic communication on CAN.
@@ -272,7 +272,7 @@ differ less than this value will be ignored: ret = setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_RX_STMIN, &stmin, sizeof(stmin)); Multi-frame transport support --------------------------- +----------------------------- The ISO-TP stack contained inside the Linux kernel supports the multi-frame transport mechanism defined by the standard, with the following contraints:
Thanks.
Signature · 1 line
An old man doll... just what I always wanted! - Clara
On Fri, Mar 15, 2024 at 11:55:04AM +0700, Bagas Sanjaya wrote:
<snip>
Quoted 49 lines
htmldocs build reports new warnings:
/home/bagas/repo/linux-kernel/Documentation/networking/isotp.rst:3: WARNING: Title overline too short.====================
ISO-TP (ISO 15765-2) Transport Protocol
====================/home/bagas/repo/linux-kernel/Documentation/networking/isotp.rst:275: WARNING: Title underline too short.Multi-frame transport support
--------------------------/home/bagas/repo/linux-kernel/Documentation/networking/isotp.rst:275: WARNING: Title underline too short.Multi-frame transport support
--------------------------I have applied the fixup:
---- >8 ----
Documentation/networking/isotp.rst +4
-4@@ -1,11 +1,11 @@ .. SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) -==================== +======================================= ISO-TP (ISO 15765-2) Transport Protocol -==================== +======================================= Overview -========================= +======== ISO-TP, also known as ISO 15765-2 from the ISO standard it is defined in, is a transport protocol specifically defined for diagnostic communication on CAN.@@ -272,7 +272,7 @@ differ less than this value will be ignored: ret = setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_RX_STMIN, &stmin, sizeof(stmin)); Multi-frame transport support --------------------------- +----------------------------- The ISO-TP stack contained inside the Linux kernel supports the multi-frame transport mechanism defined by the standard, with the following contraints:
Quoted 4 lines
Thanks.
Signature · 1 line
An old man doll... just what I always wanted! - Clara
Thank you! Fixes (along with some rework) will be applied to the v2.
Regards,
Francesco
Simon Horman
reviewerQuoted 4 lines · Francesco Valla
Document basic concepts, APIs and behaviour of the CAN ISO-TP (ISO 15765-2) stack.
Signed-off-by Francesco Valla <[email protected]>
Hi Francesco,
As it looks like there will be a v2 of this patchset please consider running checkpatch.pl --codespell and addressing the warnings it reports.
...
Documentation/networking/isotp.rst line 48
Quoted 11 lines
Documentation/networking/isotp.rst new file +11
-0+Transport protocol and associated frame types +--------------------------------------------- + +When transmitting data using the ISO-TP protocol, the payload can either fit +inside one single CAN message or not, also considering the overhead the protocol +is generating and the optional extended addressing. In the first case, the data +is transmitted at once using a so-called Single Frame (SF). In the second case, +ISO-TP defines a multi-frame protocol, in which the sender asks (through a First +Frame - FF) to the receiver the maximum supported size of a macro data block +(``blocksize``) and the minimum time time between the single CAN messages +composing such block (``stmin``). Once these informations have been received,
nit: Once this information has
Quoted 5 lines
Documentation/networking/isotp.rst new file +5
-0+the sender starts to send frames containing fragments of the data payload +(called Consecutive Frames - CF), stopping after every ``blocksize``-sized block +to wait confirmation from the receiver (which should then send a Flow Control +frame - FC - to inform the sender about its availability to receive more data). +
...
Hi Simon,
Quoted 4 lines · Simon Horman
Quoted 3 lines · Francesco Valla
Document basic concepts, APIs and behaviour of the CAN ISO-TP (ISO 15765-2) stack.
Quoted 8 lines
Quoted 1 line
Signed-off-by Francesco Valla <[email protected]>Hi Francesco,
As it looks like there will be a v2 of this patchset please consider running checkpatch.pl --codespell and addressing the warnings it reports.
Will do before v2, thanks for the suggestion.
Quoted 15 lines
...
Documentation/networking/isotp.rst line 48
Quoted 11 lines
Documentation/networking/isotp.rst new file +11
-0+Transport protocol and associated frame types +--------------------------------------------- + +When transmitting data using the ISO-TP protocol, the payload can either fit +inside one single CAN message or not, also considering the overhead the protocol +is generating and the optional extended addressing. In the first case, the data +is transmitted at once using a so-called Single Frame (SF). In the second case, +ISO-TP defines a multi-frame protocol, in which the sender asks (through a First +Frame - FF) to the receiver the maximum supported size of a macro data block +(``blocksize``) and the minimum time time between the single CAN messages +composing such block (``stmin``). Once these informations have been received,nit: Once this information has
I never grasped the usage of "information" in English, which is not my first language. I'll make this correction here.
Quoted 8 lines
Quoted 6 lines
Documentation/networking/isotp.rst new file +5
-0+the sender starts to send frames containing fragments of the data payload +(called Consecutive Frames - CF), stopping after every ``blocksize``-sized block +to wait confirmation from the receiver (which should then send a Flow Control +frame - FC - to inform the sender about its availability to receive more data). +...
Thanks for the review!
Regards,
Francesco
Simon Horman
reviewerQuoted 35 lines · Francesco Valla
Hi Simon,
Quoted 4 lines · Simon Horman
Quoted 3 lines · Francesco Valla
Document basic concepts, APIs and behaviour of the CAN ISO-TP (ISO 15765-2) stack.
Quoted 8 lines
Quoted 1 line
Signed-off-by Francesco Valla <[email protected]>Hi Francesco,
As it looks like there will be a v2 of this patchset please consider running checkpatch.pl --codespell and addressing the warnings it reports.
Will do before v2, thanks for the suggestion.
Quoted 15 lines
...
Documentation/networking/isotp.rst line 48
Quoted 11 lines
Documentation/networking/isotp.rst new file +11
-0+Transport protocol and associated frame types +--------------------------------------------- + +When transmitting data using the ISO-TP protocol, the payload can either fit +inside one single CAN message or not, also considering the overhead the protocol +is generating and the optional extended addressing. In the first case, the data +is transmitted at once using a so-called Single Frame (SF). In the second case, +ISO-TP defines a multi-frame protocol, in which the sender asks (through a First +Frame - FF) to the receiver the maximum supported size of a macro data block +(``blocksize``) and the minimum time time between the single CAN messages +composing such block (``stmin``). Once these informations have been received,nit: Once this information has
Quoted 2 lines
I never grasped the usage of "information" in English, which is not my first language. I'll make this correction here.
I can't explain it properly, but my basic understanding
is that in English information is non-countable and thus has no plural. Water is another example of a non-countable noun.
Quoted 13 lines
Quoted 7 lines
Quoted 5 lines
Documentation/networking/isotp.rst new file +5
-0+the sender starts to send frames containing fragments of the data payload +(called Consecutive Frames - CF), stopping after every ``blocksize``-sized block +to wait confirmation from the receiver (which should then send a Flow Control +frame - FC - to inform the sender about its availability to receive more data). +...
Thanks for the review!
Regards,
Francesco