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/j1939modnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/zh_TW/networking/j1939modnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/it_IT/networking/j1939modnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/ja_JP/networking/j1939modnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/ko_KR/networking/j1939modnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/sp_SP/networking/j1939modnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h)SPDX-License-Identifier: (GPL-2.0 OR MIT)h]h)SPDX-License-Identifier: (GPL-2.0 OR MIT)}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhh>/var/lib/git/docbuild/linux/Documentation/networking/j1939.rsthKubhsection)}(hhh](htitle)}(hJ1939 Documentationh]hJ1939 Documentation}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hOverview / What Is J1939h]hOverview / What Is J1939}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hXSAE J1939 defines a higher layer protocol on CAN. It implements a more sophisticated addressing scheme and extends the maximum packet size above 8 bytes. Several derived specifications exist, which differ from the original J1939 on the application level, like MilCAN A, NMEA2000, and especially ISO-11783 (ISOBUS). This last one specifies the so-called ETP (Extended Transport Protocol), which has been included in this implementation. This results in a maximum packet size of ((2 ^ 24) - 1) * 7 bytes == 111 MiB.h]hXSAE J1939 defines a higher layer protocol on CAN. It implements a more sophisticated addressing scheme and extends the maximum packet size above 8 bytes. Several derived specifications exist, which differ from the original J1939 on the application level, like MilCAN A, NMEA2000, and especially ISO-11783 (ISOBUS). This last one specifies the so-called ETP (Extended Transport Protocol), which has been included in this implementation. This results in a maximum packet size of ((2 ^ 24) - 1) * 7 bytes == 111 MiB.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hhh](h)}(hSpecifications usedh]hSpecifications used}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh bullet_list)}(hhh](h list_item)}(hSAE J1939-21 : data link layerh]h)}(hjh]hSAE J1939-21 : data link layer}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhhhhhhhNubj)}(h!SAE J1939-81 : network managementh]h)}(hjh]h!SAE J1939-81 : network management}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhhhhhhhNubj)}(h>ISO 11783-6 : Virtual Terminal (Extended Transport Protocol) h]h)}(h=ISO 11783-6 : Virtual Terminal (Extended Transport Protocol)h]h=ISO 11783-6 : Virtual Terminal (Extended Transport Protocol)}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj0ubah}(h]h ]h"]h$]h&]uh1jhhhhhhhNubeh}(h]h ]h"]h$]h&]bullet*uh1hhhhKhhhhubhtarget)}(h.. _j1939-motivation:h]h}(h]h ]h"]h$]h&]refidj1939-motivationuh1jPhKhhhhhhubeh}(h]specifications-usedah ]h"]specifications usedah$]h&]uh1hhhhhhhhKubeh}(h]overview-what-is-j1939ah ]h"]overview / what is j1939ah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Motivationh]h Motivation}(hjqhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjnhhhhhKubh)}(hGiven the fact there's something like SocketCAN with an API similar to BSD sockets, we found some reasons to justify a kernel implementation for the addressing and transport methods used by J1939.h]hGiven the fact there’s something like SocketCAN with an API similar to BSD sockets, we found some reasons to justify a kernel implementation for the addressing and transport methods used by J1939.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjnhhubh)}(hhh](j)}(hX**Addressing:** when a process on an ECU communicates via J1939, it should not necessarily know its source address. Although, at least one process per ECU should know the source address. Other processes should be able to reuse that address. This way, address parameters for different processes cooperating for the same ECU, are not duplicated. This way of working is closely related to the UNIX concept, where programs do just one thing and do it well. h]h)}(hX**Addressing:** when a process on an ECU communicates via J1939, it should not necessarily know its source address. Although, at least one process per ECU should know the source address. Other processes should be able to reuse that address. This way, address parameters for different processes cooperating for the same ECU, are not duplicated. This way of working is closely related to the UNIX concept, where programs do just one thing and do it well.h](hstrong)}(h**Addressing:**h]h Addressing:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhX when a process on an ECU communicates via J1939, it should not necessarily know its source address. Although, at least one process per ECU should know the source address. Other processes should be able to reuse that address. This way, address parameters for different processes cooperating for the same ECU, are not duplicated. This way of working is closely related to the UNIX concept, where programs do just one thing and do it well.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK"hjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hX^**Dynamic addressing:** Address Claiming in J1939 is time critical. Furthermore, data transport should be handled properly during the address negotiation. Putting this functionality in the kernel eliminates it as a requirement for _every_ user space process that communicates via J1939. This results in a consistent J1939 bus with proper addressing. h]h)}(hX]**Dynamic addressing:** Address Claiming in J1939 is time critical. Furthermore, data transport should be handled properly during the address negotiation. Putting this functionality in the kernel eliminates it as a requirement for _every_ user space process that communicates via J1939. This results in a consistent J1939 bus with proper addressing.h](j)}(h**Dynamic addressing:**h]hDynamic addressing:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhXF Address Claiming in J1939 is time critical. Furthermore, data transport should be handled properly during the address negotiation. Putting this functionality in the kernel eliminates it as a requirement for _every_ user space process that communicates via J1939. This results in a consistent J1939 bus with proper addressing.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK*hjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hX**Transport:** both TP & ETP reuse some PGNs to relay big packets over them. Different processes may thus use the same TP & ETP PGNs without actually knowing it. The individual TP & ETP sessions _must_ be serialized (synchronized) between different processes. The kernel solves this problem properly and eliminates the serialization (synchronization) as a requirement for _every_ user space process that communicates via J1939. h]h)}(hX**Transport:** both TP & ETP reuse some PGNs to relay big packets over them. Different processes may thus use the same TP & ETP PGNs without actually knowing it. The individual TP & ETP sessions _must_ be serialized (synchronized) between different processes. The kernel solves this problem properly and eliminates the serialization (synchronization) as a requirement for _every_ user space process that communicates via J1939.h](j)}(h**Transport:**h]h Transport:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhX both TP & ETP reuse some PGNs to relay big packets over them. Different processes may thus use the same TP & ETP PGNs without actually knowing it. The individual TP & ETP sessions _must_ be serialized (synchronized) between different processes. The kernel solves this problem properly and eliminates the serialization (synchronization) as a requirement for _every_ user space process that communicates via J1939.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK0hjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]jNjOuh1hhhhK"hjnhhubh)}(hJ1939 defines some other features (relaying, gateway, fast packet transport, ...). In-kernel code for these would not contribute to protocol stability. Therefore, these parts are left to user space.h]hJ1939 defines some other features (relaying, gateway, fast packet transport, ...). In-kernel code for these would not contribute to protocol stability. Therefore, these parts are left to user space.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK7hjnhhubh)}(hXThe J1939 sockets operate on CAN network devices (see SocketCAN). Any J1939 user space library operating on CAN raw sockets will still operate properly. Since such a library does not communicate with the in-kernel implementation, care must be taken that these two do not interfere. In practice, this means they cannot share ECU addresses. A single ECU (or virtual ECU) address is used by the library exclusively, or by the in-kernel system exclusively.h]hXThe J1939 sockets operate on CAN network devices (see SocketCAN). Any J1939 user space library operating on CAN raw sockets will still operate properly. Since such a library does not communicate with the in-kernel implementation, care must be taken that these two do not interfere. In practice, this means they cannot share ECU addresses. A single ECU (or virtual ECU) address is used by the library exclusively, or by the in-kernel system exclusively.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK;hjnhhubeh}(h]( motivationj]eh ]h"]( motivationj1939-motivationeh$]h&]uh1hhhhhhhhKexpect_referenced_by_name}j,jRsexpect_referenced_by_id}j]jRsubh)}(hhh](h)}(hJ1939 conceptsh]hJ1939 concepts}(hj6hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj3hhhhhKCubh)}(hhh](h)}(hData Sent to the J1939 Stackh]hData Sent to the J1939 Stack}(hjGhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjDhhhhhKFubh)}(hXaThe data buffers sent to the J1939 stack from user space are not CAN frames themselves. Instead, they are payloads that the J1939 stack converts into proper CAN frames based on the size of the buffer and the type of transfer. The size of the buffer influences how the stack processes the data and determines the internal code path used for the transfer.h]hXaThe data buffers sent to the J1939 stack from user space are not CAN frames themselves. Instead, they are payloads that the J1939 stack converts into proper CAN frames based on the size of the buffer and the type of transfer. The size of the buffer influences how the stack processes the data and determines the internal code path used for the transfer.}(hjUhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKHhjDhhubh)}(h'**Handling of Different Buffer Sizes:**h]j)}(hjeh]h#Handling of Different Buffer Sizes:}(hjghhhNhNubah}(h]h ]h"]h$]h&]uh1jhjcubah}(h]h ]h"]h$]h&]uh1hhhhKNhjDhhubh)}(hhh](j)}(hX+**Buffers with a size of 8 bytes or less:** - These are handled as simple sessions internally within the stack. - The stack converts the buffer directly into a single CAN frame without fragmentation. - This type of transfer does not require an actual client (receiver) on the receiving side. h](h)}(h+**Buffers with a size of 8 bytes or less:**h]j)}(hjh]h'Buffers with a size of 8 bytes or less:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhKPhj}ubh)}(hhh](j)}(hBThese are handled as simple sessions internally within the stack. h]h)}(hAThese are handled as simple sessions internally within the stack.h]hAThese are handled as simple sessions internally within the stack.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKRhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hVThe stack converts the buffer directly into a single CAN frame without fragmentation. h]h)}(hUThe stack converts the buffer directly into a single CAN frame without fragmentation.h]hUThe stack converts the buffer directly into a single CAN frame without fragmentation.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKThjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hZThis type of transfer does not require an actual client (receiver) on the receiving side. h]h)}(hYThis type of transfer does not require an actual client (receiver) on the receiving side.h]hYThis type of transfer does not require an actual client (receiver) on the receiving side.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKWhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]jN-uh1hhhhKRhj}ubeh}(h]h ]h"]h$]h&]uh1jhjzhhhNhNubj)}(hX**Buffers up to 1785 bytes:** - These are automatically handled as J1939 Transport Protocol (TP) transfers. - Internally, the stack splits the buffer into multiple 8-byte CAN frames. - TP transfers can be unicast or broadcast. - **Broadcast TP:** Does not require a receiver on the other side and can be used in broadcast scenarios. - **Unicast TP:** Requires an active receiver (client) on the other side to acknowledge the transfer. h](h)}(h**Buffers up to 1785 bytes:**h]j)}(hjh]hBuffers up to 1785 bytes:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhKZhjubh)}(hhh](j)}(hLThese are automatically handled as J1939 Transport Protocol (TP) transfers. h]h)}(hKThese are automatically handled as J1939 Transport Protocol (TP) transfers.h]hKThese are automatically handled as J1939 Transport Protocol (TP) transfers.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK\hjubah}(h]h ]h"]h$]h&]uh1jhj ubj)}(hIInternally, the stack splits the buffer into multiple 8-byte CAN frames. h]h)}(hHInternally, the stack splits the buffer into multiple 8-byte CAN frames.h]hHInternally, the stack splits the buffer into multiple 8-byte CAN frames.}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK^hj&ubah}(h]h ]h"]h$]h&]uh1jhj ubj)}(h*TP transfers can be unicast or broadcast. h]h)}(h)TP transfers can be unicast or broadcast.h]h)TP transfers can be unicast or broadcast.}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK`hj>ubah}(h]h ]h"]h$]h&]uh1jhj ubj)}(hh**Broadcast TP:** Does not require a receiver on the other side and can be used in broadcast scenarios. h]h)}(hg**Broadcast TP:** Does not require a receiver on the other side and can be used in broadcast scenarios.h](j)}(h**Broadcast TP:**h]h Broadcast TP:}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjZubhV Does not require a receiver on the other side and can be used in broadcast scenarios.}(hjZhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKbhjVubah}(h]h ]h"]h$]h&]uh1jhj ubj)}(hd**Unicast TP:** Requires an active receiver (client) on the other side to acknowledge the transfer. h]h)}(hc**Unicast TP:** Requires an active receiver (client) on the other side to acknowledge the transfer.h](j)}(h**Unicast TP:**h]h Unicast TP:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhT Requires an active receiver (client) on the other side to acknowledge the transfer.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKehj|ubah}(h]h ]h"]h$]h&]uh1jhj ubeh}(h]h ]h"]h$]h&]jNjuh1hhhhK\hjubeh}(h]h ]h"]h$]h&]uh1jhjzhhhNhNubj)}(hX**Buffers from 1786 bytes up to 111 MiB:** - These are handled as ISO 11783 Extended Transport Protocol (ETP) transfers. - ETP transfers are used for larger payloads and are split into multiple CAN frames internally. - **ETP transfers (unicast):** Require a receiver on the other side to process the incoming data and acknowledge each step of the transfer. - ETP transfers cannot be broadcast like TP transfers, and always require a receiver for operation. h](h)}(h***Buffers from 1786 bytes up to 111 MiB:**h]j)}(hjh]h&Buffers from 1786 bytes up to 111 MiB:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhKhhjubh)}(hhh](j)}(hLThese are handled as ISO 11783 Extended Transport Protocol (ETP) transfers. h]h)}(hKThese are handled as ISO 11783 Extended Transport Protocol (ETP) transfers.h]hKThese are handled as ISO 11783 Extended Transport Protocol (ETP) transfers.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKjhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(h^ETP transfers are used for larger payloads and are split into multiple CAN frames internally. h]h)}(h]ETP transfers are used for larger payloads and are split into multiple CAN frames internally.h]h]ETP transfers are used for larger payloads and are split into multiple CAN frames internally.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKlhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(h**ETP transfers (unicast):** Require a receiver on the other side to process the incoming data and acknowledge each step of the transfer. h]h)}(h**ETP transfers (unicast):** Require a receiver on the other side to process the incoming data and acknowledge each step of the transfer.h](j)}(h**ETP transfers (unicast):**h]hETP transfers (unicast):}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhm Require a receiver on the other side to process the incoming data and acknowledge each step of the transfer.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKohjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hbETP transfers cannot be broadcast like TP transfers, and always require a receiver for operation. h]h)}(haETP transfers cannot be broadcast like TP transfers, and always require a receiver for operation.h]haETP transfers cannot be broadcast like TP transfers, and always require a receiver for operation.}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKrhj"ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]jNjuh1hhhhKjhjubeh}(h]h ]h"]h$]h&]uh1jhjzhhhNhNubeh}(h]h ]h"]h$]h&]jNjuh1hhhhKPhjDhhubh)}(h/**Non-Blocking Operation with `MSG_DONTWAIT`:**h]j)}(hjNh]h+Non-Blocking Operation with `MSG_DONTWAIT`:}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjLubah}(h]h ]h"]h$]h&]uh1hhhhKuhjDhhubh)}(hXeThe J1939 stack supports non-blocking operation when used in combination with the `MSG_DONTWAIT` flag. In this mode, the stack attempts to take as much data as the available memory for the socket allows. It returns the amount of data that was successfully taken, and it is the responsibility of user space to monitor this value and handle partial transfers.h](hRThe J1939 stack supports non-blocking operation when used in combination with the }(hjchhhNhNubhtitle_reference)}(h`MSG_DONTWAIT`h]h MSG_DONTWAIT}(hjmhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjcubhX flag. In this mode, the stack attempts to take as much data as the available memory for the socket allows. It returns the amount of data that was successfully taken, and it is the responsibility of user space to monitor this value and handle partial transfers.}(hjchhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKwhjDhhubh)}(hhh](j)}(hIf the stack cannot take the entire buffer, it returns the number of bytes successfully taken, and user space should handle the remainder. h]h)}(hIf the stack cannot take the entire buffer, it returns the number of bytes successfully taken, and user space should handle the remainder.h]hIf the stack cannot take the entire buffer, it returns the number of bytes successfully taken, and user space should handle the remainder.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK}hjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hXN**Error handling:** When using `MSG_DONTWAIT`, the user must rely on the error queue to detect transfer errors. See the **SO_J1939_ERRQUEUE** section for details on how to subscribe to error notifications. Without the error queue, there is no other way for user space to be notified of transfer errors during non-blocking operations. h]h)}(hXM**Error handling:** When using `MSG_DONTWAIT`, the user must rely on the error queue to detect transfer errors. See the **SO_J1939_ERRQUEUE** section for details on how to subscribe to error notifications. Without the error queue, there is no other way for user space to be notified of transfer errors during non-blocking operations.h](j)}(h**Error handling:**h]hError handling:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh When using }(hjhhhNhNubjl)}(h`MSG_DONTWAIT`h]h MSG_DONTWAIT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjubhK, the user must rely on the error queue to detect transfer errors. See the }(hjhhhNhNubj)}(h**SO_J1939_ERRQUEUE**h]hSO_J1939_ERRQUEUE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh section for details on how to subscribe to error notifications. Without the error queue, there is no other way for user space to be notified of transfer errors during non-blocking operations.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]jNjuh1hhhhK}hjDhhubh)}(h**Behavior and Requirements:**h]j)}(hjh]hBehavior and Requirements:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhKhjDhhubh)}(hhh](j)}(h**Simple transfers (<= 8 bytes):** Do not require a receiver on the other side, making them easy to send without needing address claiming or coordination with a destination. h]h)}(h**Simple transfers (<= 8 bytes):** Do not require a receiver on the other side, making them easy to send without needing address claiming or coordination with a destination.h](j)}(h"**Simple transfers (<= 8 bytes):**h]hSimple transfers (<= 8 bytes):}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh Do not require a receiver on the other side, making them easy to send without needing address claiming or coordination with a destination.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(h**Unicast TP/ETP:** Requires a receiver on the other side to complete the transfer. The receiver must acknowledge the transfer for the session to proceed successfully. h]h)}(h**Unicast TP/ETP:** Requires a receiver on the other side to complete the transfer. The receiver must acknowledge the transfer for the session to proceed successfully.h](j)}(h**Unicast TP/ETP:**h]hUnicast TP/ETP:}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj4ubh Requires a receiver on the other side to complete the transfer. The receiver must acknowledge the transfer for the session to proceed successfully.}(hj4hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj0ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(h**Broadcast TP:** Allows sending data without a receiver, but only works for TP transfers. ETP cannot be broadcast and always needs a receiving client. h]h)}(h**Broadcast TP:** Allows sending data without a receiver, but only works for TP transfers. ETP cannot be broadcast and always needs a receiving client.h](j)}(h**Broadcast TP:**h]h Broadcast TP:}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjZubh Allows sending data without a receiver, but only works for TP transfers. ETP cannot be broadcast and always needs a receiving client.}(hjZhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjVubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]jNjuh1hhhhKhjDhhubh)}(hX_These different behaviors depend heavily on the size of the buffer provided to the stack, and the appropriate transport mechanism (TP or ETP) is selected based on the payload size. The stack automatically manages the fragmentation and reassembly of large payloads and ensures that the correct CAN frames are generated and transmitted for each session.h]hX_These different behaviors depend heavily on the size of the buffer provided to the stack, and the appropriate transport mechanism (TP or ETP) is selected based on the payload size. The stack automatically manages the fragmentation and reassembly of large payloads and ensures that the correct CAN frames are generated and transmitted for each session.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjDhhubeh}(h]data-sent-to-the-j1939-stackah ]h"]data sent to the j1939 stackah$]h&]uh1hhj3hhhhhKFubh)}(hhh](h)}(hPGNh]hPGN}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hOThe J1939 protocol uses the 29-bit CAN identifier with the following structure:h]hOThe J1939 protocol uses the 29-bit CAN identifier with the following structure:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh block_quote)}(hX============ ============== ==================== 29 bit CAN-ID -------------------------------------------------- Bit positions within the CAN-ID -------------------------------------------------- 28 ... 26 25 ... 8 7 ... 0 ============ ============== ==================== Priority PGN SA (Source Address) ============ ============== ==================== h]htable)}(hhh]htgroup)}(hhh](hcolspec)}(hhh]h}(h]h ]h"]h$]h&]colwidthK uh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjubhthead)}(hhh](hrow)}(hhh]hentry)}(hhh]h)}(h 29 bit CAN-IDh]h 29 bit CAN-ID}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]morecolsKuh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]j)}(hhh]h)}(hBit positions within the CAN-IDh]hBit positions within the CAN-ID}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]morecolsKuh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(h 28 ... 26h]h 28 ... 26}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj5ubah}(h]h ]h"]h$]h&]uh1jhj2ubj)}(hhh]h)}(h25 ... 8h]h25 ... 8}(hjOhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjLubah}(h]h ]h"]h$]h&]uh1jhj2ubj)}(hhh]h)}(h7 ... 0h]h7 ... 0}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjcubah}(h]h ]h"]h$]h&]uh1jhj2ubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubhtbody)}(hhh]j)}(hhh](j)}(hhh]h)}(hPriorityh]hPriority}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hPGNh]hPGN}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hSA (Source Address)h]hSA (Source Address)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]colsKuh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjhhubh)}(hbThe PGN (Parameter Group Number) is a number to identify a packet. The PGN is composed as follows:h]hbThe PGN (Parameter Group Number) is a number to identify a packet. The PGN is composed as follows:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hX============ ============== ================= ================= PGN ------------------------------------------------------------------ Bit positions within the CAN-ID ------------------------------------------------------------------ 25 24 23 ... 16 15 ... 8 ============ ============== ================= ================= R (Reserved) DP (Data Page) PF (PDU Format) PS (PDU Specific) ============ ============== ================= ================= h]j)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthK uh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjubj)}(hhh](j)}(hhh]j)}(hhh]h)}(hPGNh]hPGN}(hj;hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj8ubah}(h]h ]h"]h$]h&]morecolsKuh1jhj5ubah}(h]h ]h"]h$]h&]uh1jhj2ubj)}(hhh]j)}(hhh]h)}(hBit positions within the CAN-IDh]hBit positions within the CAN-ID}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjYubah}(h]h ]h"]h$]h&]morecolsKuh1jhjVubah}(h]h ]h"]h$]h&]uh1jhj2ubj)}(hhh](j)}(hhh]h)}(h25h]h25}(hj}hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjzubah}(h]h ]h"]h$]h&]uh1jhjwubj)}(hhh]h)}(h24h]h24}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjwubj)}(hhh]h)}(h 23 ... 16h]h 23 ... 16}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjwubj)}(hhh]h)}(h15 ... 8h]h15 ... 8}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjwubeh}(h]h ]h"]h$]h&]uh1jhj2ubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]j)}(hhh](j)}(hhh]h)}(h R (Reserved)h]h R (Reserved)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hDP (Data Page)h]hDP (Data Page)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hPF (PDU Format)h]hPF (PDU Format)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hPS (PDU Specific)h]hPS (PDU Specific)}(hj0hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj-ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]colsKuh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjhhubh)}(hX!In J1939-21 distinction is made between PDU1 format (where PF < 240) and PDU2 format (where PF >= 240). Furthermore, when using the PDU2 format, the PS-field contains a so-called Group Extension, which is part of the PGN. When using PDU2 format, the Group Extension is set in the PS-field.h]hX!In J1939-21 distinction is made between PDU1 format (where PF < 240) and PDU2 format (where PF >= 240). Furthermore, when using the PDU2 format, the PS-field contains a so-called Group Extension, which is part of the PGN. When using PDU2 format, the Group Extension is set in the PS-field.}(hjchhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hX============== ======================== PDU1 Format (specific) (peer to peer) ---------------------------------------- Bit positions within the CAN-ID ---------------------------------------- 23 ... 16 15 ... 8 ============== ======================== 00h ... EFh DA (Destination address) ============== ======================== ============== ======================== PDU2 Format (global) (broadcast) ---------------------------------------- Bit positions within the CAN-ID ---------------------------------------- 23 ... 16 15 ... 8 ============== ======================== F0h ... FFh GE (Group Extension) ============== ======================== h](j)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjxubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjxubj)}(hhh](j)}(hhh]j)}(hhh]h)}(h%PDU1 Format (specific) (peer to peer)h]h%PDU1 Format (specific) (peer to peer)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]morecolsKuh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]j)}(hhh]h)}(hBit positions within the CAN-IDh]hBit positions within the CAN-ID}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]morecolsKuh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(h 23 ... 16h]h 23 ... 16}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h15 ... 8h]h15 ... 8}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjxubj)}(hhh]j)}(hhh](j)}(hhh]h)}(h 00h ... EFhh]h 00h ... EFh}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj ubj)}(hhh]h)}(hDA (Destination address)h]hDA (Destination address)}(hj1 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj. ubah}(h]h ]h"]h$]h&]uh1jhj ubeh}(h]h ]h"]h$]h&]uh1jhj ubah}(h]h ]h"]h$]h&]uh1jhjxubeh}(h]h ]h"]h$]h&]colsKuh1jhjuubah}(h]h ]h"]h$]h&]uh1jhjqubj)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhja ubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhja ubj)}(hhh](j)}(hhh]j)}(hhh]h)}(h PDU2 Format (global) (broadcast)h]h PDU2 Format (global) (broadcast)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj~ ubah}(h]h ]h"]h$]h&]morecolsKuh1jhj{ ubah}(h]h ]h"]h$]h&]uh1jhjx ubj)}(hhh]j)}(hhh]h)}(hBit positions within the CAN-IDh]hBit positions within the CAN-ID}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]morecolsKuh1jhj ubah}(h]h ]h"]h$]h&]uh1jhjx ubj)}(hhh](j)}(hhh]h)}(h 23 ... 16h]h 23 ... 16}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj ubj)}(hhh]h)}(h15 ... 8h]h15 ... 8}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj ubeh}(h]h ]h"]h$]h&]uh1jhjx ubeh}(h]h ]h"]h$]h&]uh1jhja ubj)}(hhh]j)}(hhh](j)}(hhh]h)}(h F0h ... FFhh]h F0h ... FFh}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj ubj)}(hhh]h)}(hGE (Group Extension)h]hGE (Group Extension)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj ubeh}(h]h ]h"]h$]h&]uh1jhj ubah}(h]h ]h"]h$]h&]uh1jhja ubeh}(h]h ]h"]h$]h&]colsKuh1jhj^ ubah}(h]h ]h"]h$]h&]uh1jhjqubeh}(h]h ]h"]h$]h&]uh1jhhhKhjhhubh)}(hX;On the other hand, when using PDU1 format, the PS-field contains a so-called Destination Address, which is _not_ part of the PGN. When communicating a PGN from user space to kernel (or vice versa) and PDU1 format is used, the PS-field of the PGN shall be set to zero. The Destination Address shall be set elsewhere.h]hX;On the other hand, when using PDU1 format, the PS-field contains a so-called Destination Address, which is _not_ part of the PGN. When communicating a PGN from user space to kernel (or vice versa) and PDU1 format is used, the PS-field of the PGN shall be set to zero. The Destination Address shall be set elsewhere.}(hjM hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hRegarding PGN mapping to 29-bit CAN identifier, the Destination Address shall be get/set from/to the appropriate bits of the identifier by the kernel.h]hRegarding PGN mapping to 29-bit CAN identifier, the Destination Address shall be get/set from/to the appropriate bits of the identifier by the kernel.}(hj[ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]pgnah ]h"]pgnah$]h&]uh1hhj3hhhhhKubh)}(hhh](h)}(h Addressingh]h Addressing}(hjt hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjq hhhhhKubh)}(h7Both static and dynamic addressing methods can be used.h]h7Both static and dynamic addressing methods can be used.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjq hhubh)}(hFor static addresses, no extra checks are made by the kernel and provided addresses are considered right. This responsibility is for the OEM or system integrator.h]hFor static addresses, no extra checks are made by the kernel and provided addresses are considered right. This responsibility is for the OEM or system integrator.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjq hhubh)}(hXtFor dynamic addressing, so-called Address Claiming, extra support is foreseen in the kernel. In J1939 any ECU is known by its 64-bit NAME. At the moment of a successful address claim, the kernel keeps track of both NAME and source address being claimed. This serves as a base for filter schemes. By default, packets with a destination that is not locally will be rejected.h]hXtFor dynamic addressing, so-called Address Claiming, extra support is foreseen in the kernel. In J1939 any ECU is known by its 64-bit NAME. At the moment of a successful address claim, the kernel keeps track of both NAME and source address being claimed. This serves as a base for filter schemes. By default, packets with a destination that is not locally will be rejected.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjq hhubh)}(hMixed mode packets (from a static to a dynamic address or vice versa) are allowed. The BSD sockets define separate API calls for getting/setting the local & remote address and are applicable for J1939 sockets.h]hMixed mode packets (from a static to a dynamic address or vice versa) are allowed. The BSD sockets define separate API calls for getting/setting the local & remote address and are applicable for J1939 sockets.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjq hhubeh}(h] addressingah ]h"] addressingah$]h&]uh1hhj3hhhhhKubh)}(hhh](h)}(h Filteringh]h Filtering}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhKubh)}(hJ1939 defines white list filters per socket that a user can set in order to receive a subset of the J1939 traffic. Filtering can be based on:h]hJ1939 defines white list filters per socket that a user can set in order to receive a subset of the J1939 traffic. Filtering can be based on:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubh)}(hhh](j)}(hSAh]h)}(hj h]hSA}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubj)}(h SOURCE_NAMEh]h)}(hj h]h SOURCE_NAME}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubj)}(hPGN h]h)}(hPGNh]hPGN}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhj hhhhhNubeh}(h]h ]h"]h$]h&]jNjOuh1hhhhKhj hhubh)}(hWhen multiple filters are in place for a single socket, and a packet comes in that matches several of those filters, the packet is only received once for that socket.h]hWhen multiple filters are in place for a single socket, and a packet comes in that matches several of those filters, the packet is only received once for that socket.}(hj0 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubeh}(h] filteringah ]h"] filteringah$]h&]uh1hhj3hhhhhKubeh}(h]j1939-conceptsah ]h"]j1939 conceptsah$]h&]uh1hhhhhhhhKCubh)}(hhh](h)}(hHow to Use J1939h]hHow to Use J1939}(hjQ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjN hhhhhKubh)}(hhh](h)}(h API Callsh]h API Calls}(hjb hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj_ hhhhhKubh)}(hOn CAN, you first need to open a socket for communicating over a CAN network. To use J1939, ``#include ``. From there, ```` will be included too. To open a socket, use:h](h\On CAN, you first need to open a socket for communicating over a CAN network. To use J1939, }(hjp hhhNhNubhliteral)}(h ``#include ``h]h#include }(hjz hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjp ubh. From there, }(hjp hhhNhNubjy )}(h````h]h }(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjp ubh- will be included too. To open a socket, use:}(hjp hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj_ hhubh literal_block)}(h*s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);h]h*s = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);}hj sbah}(h]h ]h"]h$]h&]hhforcelanguageChighlight_args}uh1j hhhMhj_ hhubh)}(hJ1939 does use ``SOCK_DGRAM`` sockets. In the J1939 specification, connections are mentioned in the context of transport protocol sessions. These still deliver packets to the other end (using several CAN packets). ``SOCK_STREAM`` is not supported.h](hJ1939 does use }(hj hhhNhNubjy )}(h``SOCK_DGRAM``h]h SOCK_DGRAM}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh sockets. In the J1939 specification, connections are mentioned in the context of transport protocol sessions. These still deliver packets to the other end (using several CAN packets). }(hj hhhNhNubjy )}(h``SOCK_STREAM``h]h SOCK_STREAM}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh is not supported.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj_ hhubh)}(hXAfter the successful creation of the socket, you would normally use the ``bind(2)`` and/or ``connect(2)`` system call to bind the socket to a CAN interface. After binding and/or connecting 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 J1939 specific socket options described below.h](hHAfter the successful creation of the socket, you would normally use the }(hj hhhNhNubjy )}(h ``bind(2)``h]hbind(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh and/or }(hj hhhNhNubjy )}(h``connect(2)``h]h connect(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubhh system call to bind the socket to a CAN interface. After binding and/or connecting the socket, you can }(hj hhhNhNubjy )}(h ``read(2)``h]hread(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh and }(hj hhhNhNubjy )}(h ``write(2)``h]hwrite(2)}(hj) hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh from/to the socket or use }(hj hhhNhNubjy )}(h ``send(2)``h]hsend(2)}(hj; hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh, }(hj hhhNhNubjy )}(h ``sendto(2)``h]h sendto(2)}(hjM hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh, }hj sbjy )}(h``sendmsg(2)``h]h sendmsg(2)}(hj_ hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh and the }(hj hhhNhNubjy )}(h ``recv*()``h]hrecv*()}(hjq hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubhm counterpart operations on the socket as usual. There are also J1939 specific socket options described below.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM hj_ hhubh)}(hpIn order to send data, a ``bind(2)`` must have been successful. ``bind(2)`` assigns a local address to a socket.h](hIn order to send data, a }(hj hhhNhNubjy )}(h ``bind(2)``h]hbind(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh must have been successful. }(hj hhhNhNubjy )}(h ``bind(2)``h]hbind(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh% assigns a local address to a socket.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj_ hhubh)}(hXDifferent from CAN is that the payload data is just the data that get sends, without its header info. The header info is derived from the sockaddr supplied to ``bind(2)``, ``connect(2)``, ``sendto(2)`` and ``recvfrom(2)``. A ``write(2)`` with size 4 will result in a packet with 4 bytes.h](hDifferent from CAN is that the payload data is just the data that get sends, without its header info. The header info is derived from the sockaddr supplied to }(hj hhhNhNubjy )}(h ``bind(2)``h]hbind(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh, }(hj hhhNhNubjy )}(h``connect(2)``h]h connect(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh, }hj sbjy )}(h ``sendto(2)``h]h sendto(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh and }(hj hhhNhNubjy )}(h``recvfrom(2)``h]h recvfrom(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh. A }(hj hhhNhNubjy )}(h ``write(2)``h]hwrite(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh2 with size 4 will result in a packet with 4 bytes.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj_ hhubh)}(hLThe sockaddr structure has extensions for use with J1939 as specified below:h]hLThe sockaddr structure has extensions for use with J1939 as specified below:}(hj# hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj_ hhubj )}(hXstruct sockaddr_can { sa_family_t can_family; int can_ifindex; union { struct { __u64 name; /* pgn: * 8 bit: PS in PDU2 case, else 0 * 8 bit: PF * 1 bit: DP * 1 bit: reserved */ __u32 pgn; __u8 addr; } j1939; } can_addr; }h]hXstruct sockaddr_can { sa_family_t can_family; int can_ifindex; union { struct { __u64 name; /* pgn: * 8 bit: PS in PDU2 case, else 0 * 8 bit: PF * 1 bit: DP * 1 bit: reserved */ __u32 pgn; __u8 addr; } j1939; } can_addr; }}hj1 sbah}(h]h ]h"]h$]h&]hhj j j j }uh1j hhhMhj_ hhubh)}(hW``can_family`` & ``can_ifindex`` serve the same purpose as for other SocketCAN sockets.h](jy )}(h``can_family``h]h can_family}(hjD hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj@ ubh & }(hj@ hhhNhNubjy )}(h``can_ifindex``h]h can_ifindex}(hjV hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj@ ubh7 serve the same purpose as for other SocketCAN sockets.}(hj@ hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM1hj_ hhubh)}(h\``can_addr.j1939.pgn`` specifies the PGN (max 0x3ffff). Individual bits are specified above.h](jy )}(h``can_addr.j1939.pgn``h]hcan_addr.j1939.pgn}(hjr hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjn ubhF specifies the PGN (max 0x3ffff). Individual bits are specified above.}(hjn hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM3hj_ hhubh)}(h7``can_addr.j1939.name`` contains the 64-bit J1939 NAME.h](jy )}(h``can_addr.j1939.name``h]hcan_addr.j1939.name}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh contains the 64-bit J1939 NAME.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM6hj_ hhubh)}(h-``can_addr.j1939.addr`` contains the address.h](jy )}(h``can_addr.j1939.addr``h]hcan_addr.j1939.addr}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh contains the address.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM8hj_ hhubh)}(hXThe ``bind(2)`` system call assigns the local address, i.e. the source address when sending packages. If a PGN during ``bind(2)`` is set, it's used as a RX filter. I.e. only packets with a matching PGN are received. If an ADDR or NAME is set it is used as a receive filter, too. It will match the destination NAME or ADDR of the incoming packet. The NAME filter will work only if appropriate Address Claiming for this name was done on the CAN bus and registered/cached by the kernel.h](hThe }(hj hhhNhNubjy )}(h ``bind(2)``h]hbind(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubhg system call assigns the local address, i.e. the source address when sending packages. If a PGN during }(hj hhhNhNubjy )}(h ``bind(2)``h]hbind(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubhXd is set, it’s used as a RX filter. I.e. only packets with a matching PGN are received. If an ADDR or NAME is set it is used as a receive filter, too. It will match the destination NAME or ADDR of the incoming packet. The NAME filter will work only if appropriate Address Claiming for this name was done on the CAN bus and registered/cached by the kernel.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM:hj_ hhubh)}(hXOn the other hand ``connect(2)`` assigns the remote address, i.e. the destination address. The PGN from ``connect(2)`` is used as the default PGN when sending packets. If ADDR or NAME is set it will be used as the default destination ADDR or NAME. Further a set ADDR or NAME during ``connect(2)`` is used as a receive filter. It will match the source NAME or ADDR of the incoming packet.h](hOn the other hand }(hj hhhNhNubjy )}(h``connect(2)``h]h connect(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubhH assigns the remote address, i.e. the destination address. The PGN from }(hj hhhNhNubjy )}(h``connect(2)``h]h connect(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh is used as the default PGN when sending packets. If ADDR or NAME is set it will be used as the default destination ADDR or NAME. Further a set ADDR or NAME during }(hj hhhNhNubjy )}(h``connect(2)``h]h connect(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh[ is used as a receive filter. It will match the source NAME or ADDR of the incoming packet.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMBhj_ hhubh)}(hBoth ``write(2)`` and ``send(2)`` will send a packet with local address from ``bind(2)`` and the remote address from ``connect(2)``. Use ``sendto(2)`` to overwrite the destination address.h](hBoth }(hj8hhhNhNubjy )}(h ``write(2)``h]hwrite(2)}(hj@hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj8ubh and }(hj8hhhNhNubjy )}(h ``send(2)``h]hsend(2)}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj8ubh, will send a packet with local address from }(hj8hhhNhNubjy )}(h ``bind(2)``h]hbind(2)}(hjdhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj8ubh and the remote address from }(hj8hhhNhNubjy )}(h``connect(2)``h]h connect(2)}(hjvhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj8ubh. Use }(hj8hhhNhNubjy )}(h ``sendto(2)``h]h sendto(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj8ubh& to overwrite the destination address.}(hj8hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMHhj_ hhubh)}(hIf ``can_addr.j1939.name`` is set (!= 0) the NAME is looked up by the kernel and the corresponding ADDR is used. If ``can_addr.j1939.name`` is not set (== 0), ``can_addr.j1939.addr`` is used.h](hIf }(hjhhhNhNubjy )}(h``can_addr.j1939.name``h]hcan_addr.j1939.name}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubhZ is set (!= 0) the NAME is looked up by the kernel and the corresponding ADDR is used. If }(hjhhhNhNubjy )}(h``can_addr.j1939.name``h]hcan_addr.j1939.name}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh is not set (== 0), }(hjhhhNhNubjy )}(h``can_addr.j1939.addr``h]hcan_addr.j1939.addr}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh is used.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMLhj_ hhubh)}(h}When creating a socket, reasonable defaults are set. Some options can be modified with ``setsockopt(2)`` & ``getsockopt(2)``.h](hWWhen creating a socket, reasonable defaults are set. Some options can be modified with }(hjhhhNhNubjy )}(h``setsockopt(2)``h]h setsockopt(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh & }(hjhhhNhNubjy )}(h``getsockopt(2)``h]h getsockopt(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMPhj_ hhubh)}(hRX path related options:h]hRX path related options:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMShj_ hhubh)}(hhh](j)}(h0``SO_J1939_FILTER`` - configure array of filtersh]h)}(hj)h](jy )}(h``SO_J1939_FILTER``h]hSO_J1939_FILTER}(hj.hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj+ubh - configure array of filters}(hj+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMUhj'ubah}(h]h ]h"]h$]h&]uh1jhj$hhhhhNubj)}(hM``SO_J1939_PROMISC`` - disable filters set by ``bind(2)`` and ``connect(2)`` h]h)}(hL``SO_J1939_PROMISC`` - disable filters set by ``bind(2)`` and ``connect(2)``h](jy )}(h``SO_J1939_PROMISC``h]hSO_J1939_PROMISC}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjPubh - disable filters set by }(hjPhhhNhNubjy )}(h ``bind(2)``h]hbind(2)}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjPubh and }(hjPhhhNhNubjy )}(h``connect(2)``h]h connect(2)}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjPubeh}(h]h ]h"]h$]h&]uh1hhhhMVhjLubah}(h]h ]h"]h$]h&]uh1jhj$hhhhhNubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMUhj_ hhubh)}(hBy default no broadcast packets can be send or received. To enable sending or receiving broadcast packets use the socket option ``SO_BROADCAST``:h](hBy default no broadcast packets can be send or received. To enable sending or receiving broadcast packets use the socket option }(hjhhhNhNubjy )}(h``SO_BROADCAST``h]h SO_BROADCAST}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMXhj_ hhubj )}(hQint value = 1; setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &value, sizeof(value));h]hQint value = 1; setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &value, sizeof(value));}hjsbah}(h]h ]h"]h$]h&]hhj j j j }uh1j hhhM[hj_ hhubh)}(h.The following diagram illustrates the RX path:h]h.The following diagram illustrates the RX path:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM`hj_ hhubj )}(hX +--------------------+ | incoming packet | +--------------------+ | V +--------------------+ | SO_J1939_PROMISC? | +--------------------+ | | no | | yes | | .---------' `---------. | | +---------------------------+ | | bind() + connect() + | | | SOCK_BROADCAST filter | | +---------------------------+ | | | |<---------------------' V +---------------------------+ | SO_J1939_FILTER | +---------------------------+ | V +---------------------------+ | socket recv() | +---------------------------+h]hX +--------------------+ | incoming packet | +--------------------+ | V +--------------------+ | SO_J1939_PROMISC? | +--------------------+ | | no | | yes | | .---------' `---------. | | +---------------------------+ | | bind() + connect() + | | | SOCK_BROADCAST filter | | +---------------------------+ | | | |<---------------------' V +---------------------------+ | SO_J1939_FILTER | +---------------------------+ | V +---------------------------+ | socket recv() | +---------------------------+}hjsbah}(h]h ]h"]h$]h&]forcehighlight_args}hhj noneuh1j hhhMbhj_ hhubh)}(h]TX path related options: ``SO_J1939_SEND_PRIO`` - change default send priority for the socketh](hTX path related options: }(hjhhhNhNubjy )}(h``SO_J1939_SEND_PRIO``h]hSO_J1939_SEND_PRIO}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh. - change default send priority for the socket}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj_ hhubh)}(hhh](h)}(h4Message Flags during send() and Related System Callsh]h4Message Flags during send() and Related System Calls}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(he``send(2)``, ``sendto(2)`` and ``sendmsg(2)`` take a 'flags' argument. Currently supported flags are:h](jy )}(h ``send(2)``h]hsend(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh, }(hjhhhNhNubjy )}(h ``sendto(2)``h]h sendto(2)}(hj.hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh and }(hjhhhNhNubjy )}(h``sendmsg(2)``h]h sendmsg(2)}(hj@hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh< take a ‘flags’ argument. Currently supported flags are:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hhh]j)}(h/``MSG_DONTWAIT``, i.e. non-blocking operation. h]h)}(h.``MSG_DONTWAIT``, i.e. non-blocking operation.h](jy )}(h``MSG_DONTWAIT``h]h MSG_DONTWAIT}(hjchhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj_ubh, i.e. non-blocking operation.}(hj_hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj[ubah}(h]h ]h"]h$]h&]uh1jhjXhhhhhNubah}(h]h ]h"]h$]h&]jNjOuh1hhhhMhjhhubeh}(h]2message-flags-during-send-and-related-system-callsah ]h"]4message flags during send() and related system callsah$]h&]uh1hhj_ hhhhhMubh)}(hhh](h)}(h recvmsg(2)h]h recvmsg(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hX#In most cases ``recvmsg(2)`` is needed if you want to extract more information than ``recvfrom(2)`` can provide. For example package priority and timestamp. The Destination Address, name and packet priority (if applicable) are attached to the msghdr in the ``recvmsg(2)`` call. They can be extracted using ``cmsg(3)`` macros, with ``cmsg_level == SOL_J1939 && cmsg_type == SCM_J1939_DEST_ADDR``, ``SCM_J1939_DEST_NAME`` or ``SCM_J1939_PRIO``. The returned data is a ``uint8_t`` for ``priority`` and ``dst_addr``, and ``uint64_t`` for ``dst_name``.Vh](hIn most cases }(hjhhhNhNubjy )}(h``recvmsg(2)``h]h recvmsg(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh8 is needed if you want to extract more information than }(hjhhhNhNubjy )}(h``recvfrom(2)``h]h recvfrom(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh can provide. For example package priority and timestamp. The Destination Address, name and packet priority (if applicable) are attached to the msghdr in the }(hjhhhNhNubjy )}(h``recvmsg(2)``h]h recvmsg(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh# call. They can be extracted using }(hjhhhNhNubjy )}(h ``cmsg(3)``h]hcmsg(3)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh macros, with }(hjhhhNhNubjy )}(h?``cmsg_level == SOL_J1939 && cmsg_type == SCM_J1939_DEST_ADDR``h]h;cmsg_level == SOL_J1939 && cmsg_type == SCM_J1939_DEST_ADDR}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh, }(hjhhhNhNubjy )}(h``SCM_J1939_DEST_NAME``h]hSCM_J1939_DEST_NAME}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh or }(hjhhhNhNubjy )}(h``SCM_J1939_PRIO``h]hSCM_J1939_PRIO}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh. The returned data is a }(hjhhhNhNubjy )}(h ``uint8_t``h]huint8_t}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh for }(hjhhhNhNubjy )}(h ``priority``h]hpriority}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh and }(hjhhhNhNubjy )}(h ``dst_addr``h]hdst_addr}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh, and }(hjhhhNhNubjy )}(h ``uint64_t``h]huint64_t}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh for }(hjhhhNhNubjy )}(h ``dst_name``h]hdst_name}(hjnhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj )}(hXXuint8_t priority, dst_addr; uint64_t dst_name; for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { switch (cmsg->cmsg_level) { case SOL_CAN_J1939: if (cmsg->cmsg_type == SCM_J1939_DEST_ADDR) dst_addr = *CMSG_DATA(cmsg); else if (cmsg->cmsg_type == SCM_J1939_DEST_NAME) memcpy(&dst_name, CMSG_DATA(cmsg), cmsg->cmsg_len - CMSG_LEN(0)); else if (cmsg->cmsg_type == SCM_J1939_PRIO) priority = *CMSG_DATA(cmsg); break; } }h]hXXuint8_t priority, dst_addr; uint64_t dst_name; for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { switch (cmsg->cmsg_level) { case SOL_CAN_J1939: if (cmsg->cmsg_type == SCM_J1939_DEST_ADDR) dst_addr = *CMSG_DATA(cmsg); else if (cmsg->cmsg_type == SCM_J1939_DEST_NAME) memcpy(&dst_name, CMSG_DATA(cmsg), cmsg->cmsg_len - CMSG_LEN(0)); else if (cmsg->cmsg_type == SCM_J1939_PRIO) priority = *CMSG_DATA(cmsg); break; } }}hjsbah}(h]h ]h"]h$]h&]hhj j j j }uh1j hhhMhjhhubeh}(h] recvmsg-2ah ]h"] recvmsg(2)ah$]h&]uh1hhj_ hhhhhMubh)}(hhh](h)}(h setsockopt(2)h]h setsockopt(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hThe ``setsockopt(2)`` function is used to configure various socket-level options for J1939 communication. The following options are supported:h](hThe }(hjhhhNhNubjy )}(h``setsockopt(2)``h]h setsockopt(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubhy function is used to configure various socket-level options for J1939 communication. The following options are supported:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hhh](h)}(h``SO_J1939_FILTER``h]jy )}(hjh]hSO_J1939_FILTER}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hXThe ``SO_J1939_FILTER`` option is essential when the default behavior of ``bind(2)`` and ``connect(2)`` is insufficient for specific use cases. By default, ``bind(2)`` and ``connect(2)`` allow a socket to be associated with a single unicast or broadcast address. However, there are scenarios where finer control over the incoming messages is required, such as filtering by Parameter Group Number (PGN) rather than by addresses.h](hThe }(hjhhhNhNubjy )}(h``SO_J1939_FILTER``h]hSO_J1939_FILTER}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh2 option is essential when the default behavior of }(hjhhhNhNubjy )}(h ``bind(2)``h]hbind(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh and }(hjhhhNhNubjy )}(h``connect(2)``h]h connect(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh5 is insufficient for specific use cases. By default, }(hjhhhNhNubjy )}(h ``bind(2)``h]hbind(2)}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh and }hjsbjy )}(h``connect(2)``h]h connect(2)}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh allow a socket to be associated with a single unicast or broadcast address. However, there are scenarios where finer control over the incoming messages is required, such as filtering by Parameter Group Number (PGN) rather than by addresses.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXFor example, in a system where multiple types of J1939 messages are being transmitted, a process might only be interested in a subset of those messages, such as specific PGNs, and not want to receive all messages destined for its address or broadcast to the bus.h]hXFor example, in a system where multiple types of J1939 messages are being transmitted, a process might only be interested in a subset of those messages, such as specific PGNs, and not want to receive all messages destined for its address or broadcast to the bus.}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hMBy applying the ``SO_J1939_FILTER`` option, you can filter messages based on:h](hBy applying the }(hj^hhhNhNubjy )}(h``SO_J1939_FILTER``h]hSO_J1939_FILTER}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj^ubh* option, you can filter messages based on:}(hj^hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hhh](j)}(hP**Source Address (SA)**: Filter messages coming from specific source addresses. h]h)}(hO**Source Address (SA)**: Filter messages coming from specific source addresses.h](j)}(h**Source Address (SA)**h]hSource Address (SA)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh8: Filter messages coming from specific source addresses.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhj~hhhhhNubj)}(hR**Source Name**: Filter messages coming from ECUs with specific NAME identifiers. h]h)}(hQ**Source Name**: Filter messages coming from ECUs with specific NAME identifiers.h](j)}(h**Source Name**h]h Source Name}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhB: Filter messages coming from ECUs with specific NAME identifiers.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhj~hhhhhNubj)}(hq**Parameter Group Number (PGN)**: Focus on receiving messages with specific PGNs, filtering out irrelevant ones. h]h)}(hp**Parameter Group Number (PGN)**: Focus on receiving messages with specific PGNs, filtering out irrelevant ones.h](j)}(h **Parameter Group Number (PGN)**h]hParameter Group Number (PGN)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhP: Focus on receiving messages with specific PGNs, filtering out irrelevant ones.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhj~hhhhhNubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMhjhhubh)}(h5This filtering mechanism is particularly useful when:h]h5This filtering mechanism is particularly useful when:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hhh](j)}(h_You want to receive a subset of messages based on their PGNs, even if the address is the same. h]h)}(h^You want to receive a subset of messages based on their PGNs, even if the address is the same.h]h^You want to receive a subset of messages based on their PGNs, even if the address is the same.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hpYou need to handle both broadcast and unicast messages but only care about certain message types or parameters. h]h)}(hoYou need to handle both broadcast and unicast messages but only care about certain message types or parameters.h]hoYou need to handle both broadcast and unicast messages but only care about certain message types or parameters.}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj"ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hThe ``bind(2)`` and ``connect(2)`` functions only allow binding to a single address, which might not be sufficient if the process needs to handle multiple PGNs but does not want to open multiple sockets. h]h)}(hThe ``bind(2)`` and ``connect(2)`` functions only allow binding to a single address, which might not be sufficient if the process needs to handle multiple PGNs but does not want to open multiple sockets.h](hThe }(hj>hhhNhNubjy )}(h ``bind(2)``h]hbind(2)}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj>ubh and }(hj>hhhNhNubjy )}(h``connect(2)``h]h connect(2)}(hjXhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj>ubh functions only allow binding to a single address, which might not be sufficient if the process needs to handle multiple PGNs but does not want to open multiple sockets.}(hj>hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj:ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMhjhhubh)}(hXTo remove existing filters, you can pass ``optval == NULL`` or ``optlen == 0`` to ``setsockopt(2)``. This will clear all currently set filters. If you want to **update** the set of filters, you must pass the updated filter set to ``setsockopt(2)``, as the new filter set will **replace** the old one entirely. This behavior ensures that any previous filter configuration is discarded and only the new set is applied.h](h)To remove existing filters, you can pass }(hj|hhhNhNubjy )}(h``optval == NULL``h]hoptval == NULL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj|ubh or }(hj|hhhNhNubjy )}(h``optlen == 0``h]h optlen == 0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj|ubh to }(hj|hhhNhNubjy )}(h``setsockopt(2)``h]h setsockopt(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj|ubh<. This will clear all currently set filters. If you want to }(hj|hhhNhNubj)}(h **update**h]hupdate}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj|ubh= the set of filters, you must pass the updated filter set to }(hj|hhhNhNubjy )}(h``setsockopt(2)``h]h setsockopt(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj|ubh, as the new filter set will }(hj|hhhNhNubj)}(h **replace**h]hreplace}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj|ubh the old one entirely. This behavior ensures that any previous filter configuration is discarded and only the new set is applied.}(hj|hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h Example of removing all filters:h]h Example of removing all filters:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj )}(h:setsockopt(sock, SOL_CAN_J1939, SO_J1939_FILTER, NULL, 0);h]h:setsockopt(sock, SOL_CAN_J1939, SO_J1939_FILTER, NULL, 0);}hjsbah}(h]h ]h"]h$]h&]hhj j cj }uh1j hhhMhjhhubh)}(hX**Maximum number of filters:** The maximum amount of filters that can be applied using ``SO_J1939_FILTER`` is defined by ``J1939_FILTER_MAX``, which is set to 512. This means you can configure up to 512 individual filters to match your specific filtering needs.h](j)}(h**Maximum number of filters:**h]hMaximum number of filters:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh9 The maximum amount of filters that can be applied using }(hjhhhNhNubjy )}(h``SO_J1939_FILTER``h]hSO_J1939_FILTER}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh is defined by }(hjhhhNhNubjy )}(h``J1939_FILTER_MAX``h]hJ1939_FILTER_MAX}(hj<hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubhx, which is set to 512. This means you can configure up to 512 individual filters to match your specific filtering needs.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h3Practical use case: **Monitoring Address Claiming**h](hPractical use case: }(hjThhhNhNubj)}(h**Monitoring Address Claiming**h]hMonitoring Address Claiming}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjTubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hOne practical use case is monitoring the J1939 address claiming process by filtering for specific PGNs related to address claiming. This allows a process to monitor and handle address claims without processing unrelated messages.h]hOne practical use case is monitoring the J1939 address claiming process by filtering for specific PGNs related to address claiming. This allows a process to monitor and handle address claims without processing unrelated messages.}(hjphhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hExample:h]hExample:}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj )}(hXrstruct j1939_filter filt[] = { { .pgn = J1939_PGN_ADDRESS_CLAIMED, .pgn_mask = J1939_PGN_PDU1_MAX, }, { .pgn = J1939_PGN_REQUEST, .pgn_mask = J1939_PGN_PDU1_MAX, }, { .pgn = J1939_PGN_ADDRESS_COMMANDED, .pgn_mask = J1939_PGN_MAX, }, }; setsockopt(sock, SOL_CAN_J1939, SO_J1939_FILTER, &filt, sizeof(filt));h]hXrstruct j1939_filter filt[] = { { .pgn = J1939_PGN_ADDRESS_CLAIMED, .pgn_mask = J1939_PGN_PDU1_MAX, }, { .pgn = J1939_PGN_REQUEST, .pgn_mask = J1939_PGN_PDU1_MAX, }, { .pgn = J1939_PGN_ADDRESS_COMMANDED, .pgn_mask = J1939_PGN_MAX, }, }; setsockopt(sock, SOL_CAN_J1939, SO_J1939_FILTER, &filt, sizeof(filt));}hjsbah}(h]h ]h"]h$]h&]hhj j jj }uh1j hhhMhjhhubh)}(hX[In this example, the socket will only receive messages with the PGNs related to address claiming: ``J1939_PGN_ADDRESS_CLAIMED``, ``J1939_PGN_REQUEST``, and ``J1939_PGN_ADDRESS_COMMANDED``. This is particularly useful in scenarios where you want to monitor and process address claims without being overwhelmed by other traffic on the J1939 network.h](hbIn this example, the socket will only receive messages with the PGNs related to address claiming: }(hjhhhNhNubjy )}(h``J1939_PGN_ADDRESS_CLAIMED``h]hJ1939_PGN_ADDRESS_CLAIMED}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh, }(hjhhhNhNubjy )}(h``J1939_PGN_REQUEST``h]hJ1939_PGN_REQUEST}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh, and }(hjhhhNhNubjy )}(h``J1939_PGN_ADDRESS_COMMANDED``h]hJ1939_PGN_ADDRESS_COMMANDED}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh. This is particularly useful in scenarios where you want to monitor and process address claims without being overwhelmed by other traffic on the J1939 network.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h]so-j1939-filterah ]h"]so_j1939_filterah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h``SO_J1939_PROMISC``h]jy )}(hjh]hSO_J1939_PROMISC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(hXLThe ``SO_J1939_PROMISC`` option enables socket-level promiscuous mode. When this option is enabled, the socket will receive all J1939 traffic, regardless of any filters set by ``bind()`` or ``connect()``. This is analogous to enabling promiscuous mode for an Ethernet interface, where all traffic on the network segment is captured.h](hThe }(hjhhhNhNubjy )}(h``SO_J1939_PROMISC``h]hSO_J1939_PROMISC}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh option enables socket-level promiscuous mode. When this option is enabled, the socket will receive all J1939 traffic, regardless of any filters set by }(hjhhhNhNubjy )}(h ``bind()``h]hbind()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh or }(hjhhhNhNubjy )}(h ``connect()``h]h connect()}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh. This is analogous to enabling promiscuous mode for an Ethernet interface, where all traffic on the network segment is captured.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hXpHowever, **`SO_J1939_FILTER` has a higher priority** compared to ``SO_J1939_PROMISC``. This means that even in promiscuous mode, you can reduce the number of packets received by applying specific filters with `SO_J1939_FILTER`. The filters will limit which packets are passed to the socket, allowing for more refined traffic selection while promiscuous mode is active.h](h However, }(hjEhhhNhNubj)}(h+**`SO_J1939_FILTER` has a higher priority**h]h'`SO_J1939_FILTER` has a higher priority}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjEubh compared to }(hjEhhhNhNubjy )}(h``SO_J1939_PROMISC``h]hSO_J1939_PROMISC}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjEubh|. This means that even in promiscuous mode, you can reduce the number of packets received by applying specific filters with }(hjEhhhNhNubjl)}(h`SO_J1939_FILTER`h]hSO_J1939_FILTER}(hjqhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjEubh. The filters will limit which packets are passed to the socket, allowing for more refined traffic selection while promiscuous mode is active.}(hjEhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hThe acceptable value size for this option is ``sizeof(int)``, and the value is only differentiated between `0` and non-zero. A value of `0` disables promiscuous mode, while any non-zero value enables it.h](h-The acceptable value size for this option is }(hjhhhNhNubjy )}(h``sizeof(int)``h]h sizeof(int)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh/, and the value is only differentiated between }(hjhhhNhNubjl)}(h`0`h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjubh and non-zero. A value of }(hjhhhNhNubjl)}(h`0`h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjubh@ disables promiscuous mode, while any non-zero value enables it.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hThis combination can be useful for debugging or monitoring specific types of traffic while still capturing a broad set of messages.h]hThis combination can be useful for debugging or monitoring specific types of traffic while still capturing a broad set of messages.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hExample:h]hExample:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj )}(hXint value = 1; setsockopt(sock, SOL_CAN_J1939, SO_J1939_PROMISC, &value, sizeof(value));h]hXint value = 1; setsockopt(sock, SOL_CAN_J1939, SO_J1939_PROMISC, &value, sizeof(value));}hjsbah}(h]h ]h"]h$]h&]hhj j jj }uh1j hhhMhjhhubh)}(hIn this example, setting ``value`` to any non-zero value (e.g., `1`) enables promiscuous mode, allowing the socket to receive all J1939 traffic on the network.h](hIn this example, setting }(hjhhhNhNubjy )}(h ``value``h]hvalue}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh to any non-zero value (e.g., }(hjhhhNhNubjl)}(h`1`h]h1}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjubh\) enables promiscuous mode, allowing the socket to receive all J1939 traffic on the network.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM#hjhhubeh}(h]so-j1939-promiscah ]h"]so_j1939_promiscah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h``SO_BROADCAST``h]jy )}(hj7h]h SO_BROADCAST}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj5ubah}(h]h ]h"]h$]h&]uh1hhj2hhhhhM(ubh)}(hXThe ``SO_BROADCAST`` option enables the sending and receiving of broadcast messages. By default, broadcast messages are disabled for J1939 sockets. When this option is enabled, the socket will be allowed to send and receive broadcast packets on the J1939 network.h](hThe }(hjLhhhNhNubjy )}(h``SO_BROADCAST``h]h SO_BROADCAST}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjLubh option enables the sending and receiving of broadcast messages. By default, broadcast messages are disabled for J1939 sockets. When this option is enabled, the socket will be allowed to send and receive broadcast packets on the J1939 network.}(hjLhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM*hj2hhubh)}(hXDue to the nature of the CAN bus as a shared medium, all messages transmitted on the bus are visible to all participants. In the context of J1939, broadcasting refers to using a specific destination address field, where the destination address is set to a value that indicates the message is intended for all participants (usually a global address such as 0xFF). Enabling the broadcast option allows the socket to send and receive such broadcast messages.h]hXDue to the nature of the CAN bus as a shared medium, all messages transmitted on the bus are visible to all participants. In the context of J1939, broadcasting refers to using a specific destination address field, where the destination address is set to a value that indicates the message is intended for all participants (usually a global address such as 0xFF). Enabling the broadcast option allows the socket to send and receive such broadcast messages.}(hjlhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM/hj2hhubh)}(hThe acceptable value size for this option is ``sizeof(int)``, and the value is only differentiated between `0` and non-zero. A value of `0` disables the ability to send and receive broadcast messages, while any non-zero value enables it.h](h-The acceptable value size for this option is }(hjzhhhNhNubjy )}(h``sizeof(int)``h]h sizeof(int)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjzubh/, and the value is only differentiated between }(hjzhhhNhNubjl)}(h`0`h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjzubh and non-zero. A value of }(hjzhhhNhNubjl)}(h`0`h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjzubhb disables the ability to send and receive broadcast messages, while any non-zero value enables it.}(hjzhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM6hj2hhubh)}(hExample:h]hExample:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM;hj2hhubj )}(hQint value = 1; setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &value, sizeof(value));h]hQint value = 1; setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &value, sizeof(value));}hjsbah}(h]h ]h"]h$]h&]hhj j jj }uh1j hhhM=hj2hhubh)}(hIn this example, setting ``value`` to any non-zero value (e.g., `1`) enables the socket to send and receive broadcast messages.h](hIn this example, setting }(hjhhhNhNubjy )}(h ``value``h]hvalue}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh to any non-zero value (e.g., }(hjhhhNhNubjl)}(h`1`h]h1}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjubh<) enables the socket to send and receive broadcast messages.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMBhj2hhubeh}(h] so-broadcastah ]h"] so_broadcastah$]h&]uh1hhjhhhhhM(ubh)}(hhh](h)}(h``SO_J1939_SEND_PRIO``h]jy )}(hjh]hSO_J1939_SEND_PRIO}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMFubh)}(hXPThe ``SO_J1939_SEND_PRIO`` option sets the priority of outgoing J1939 messages for the socket. In J1939, messages can have different priorities, and lower numerical values indicate higher priority. This option allows the user to control the priority of messages sent from the socket by adjusting the priority bits in the CAN identifier.h](hThe }(hj/hhhNhNubjy )}(h``SO_J1939_SEND_PRIO``h]hSO_J1939_SEND_PRIO}(hj7hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj/ubhX6 option sets the priority of outgoing J1939 messages for the socket. In J1939, messages can have different priorities, and lower numerical values indicate higher priority. This option allows the user to control the priority of messages sent from the socket by adjusting the priority bits in the CAN identifier.}(hj/hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMHhjhhubh)}(hXThe acceptable value **size** for this option is ``sizeof(int)``, and the value is expected to be in the range of 0 to 7, where `0` is the highest priority, and `7` is the lowest. By default, the priority is set to `6` if this option is not explicitly configured.h](hThe acceptable value }(hjOhhhNhNubj)}(h**size**h]hsize}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjOubh for this option is }(hjOhhhNhNubjy )}(h``sizeof(int)``h]h sizeof(int)}(hjihhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjOubh@, and the value is expected to be in the range of 0 to 7, where }(hjOhhhNhNubjl)}(h`0`h]h0}(hj{hhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjOubh is the highest priority, and }(hjOhhhNhNubjl)}(h`7`h]h7}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjOubh3 is the lowest. By default, the priority is set to }(hjOhhhNhNubjl)}(h`6`h]h6}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjOubh- if this option is not explicitly configured.}(hjOhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMNhjhhubh)}(hNote that the priority values `0` and `1` can only be set if the process has the `CAP_NET_ADMIN` capability. These are reserved for high-priority traffic and require administrative privileges.h](hNote that the priority values }(hjhhhNhNubjl)}(h`0`h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjubh and }(hjhhhNhNubjl)}(h`1`h]h1}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjubh( can only be set if the process has the }(hjhhhNhNubjl)}(h`CAP_NET_ADMIN`h]h CAP_NET_ADMIN}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjubh` capability. These are reserved for high-priority traffic and require administrative privileges.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMShjhhubh)}(hExample:h]hExample:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMWhjhhubj )}(hint prio = 3; // Priority value between 0 (highest) and 7 (lowest) setsockopt(sock, SOL_CAN_J1939, SO_J1939_SEND_PRIO, &prio, sizeof(prio));h]hint prio = 3; // Priority value between 0 (highest) and 7 (lowest) setsockopt(sock, SOL_CAN_J1939, SO_J1939_SEND_PRIO, &prio, sizeof(prio));}hj sbah}(h]h ]h"]h$]h&]hhj j jj }uh1j hhhMYhjhhubh)}(hwIn this example, the priority is set to `3`, meaning the outgoing messages will be sent with a moderate priority level.h](h(In this example, the priority is set to }(hjhhhNhNubjl)}(h`3`h]h3}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjubhL, meaning the outgoing messages will be sent with a moderate priority level.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM^hjhhubeh}(h]so-j1939-send-prioah ]h"]so_j1939_send_prioah$]h&]uh1hhjhhhhhMFubh)}(hhh](h)}(h``SO_J1939_ERRQUEUE``h]jy )}(hjEh]hSO_J1939_ERRQUEUE}(hjGhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjCubah}(h]h ]h"]h$]h&]uh1hhj@hhhhhMbubh)}(hXBThe ``SO_J1939_ERRQUEUE`` option enables the socket to receive error messages from the error queue, providing diagnostic information about transmission failures, protocol violations, or other issues that occur during J1939 communication. Once this option is set, user space is required to handle ``MSG_ERRQUEUE`` messages.h](hThe }(hjZhhhNhNubjy )}(h``SO_J1939_ERRQUEUE``h]hSO_J1939_ERRQUEUE}(hjbhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjZubhX option enables the socket to receive error messages from the error queue, providing diagnostic information about transmission failures, protocol violations, or other issues that occur during J1939 communication. Once this option is set, user space is required to handle }(hjZhhhNhNubjy )}(h``MSG_ERRQUEUE``h]h MSG_ERRQUEUE}(hjthhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjZubh messages.}(hjZhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMdhj@hhubh)}(hSetting ``SO_J1939_ERRQUEUE`` to ``0`` will purge any currently present error messages in the error queue. When enabled, error messages can be retrieved using the ``recvmsg(2)`` system call.h](hSetting }(hjhhhNhNubjy )}(h``SO_J1939_ERRQUEUE``h]hSO_J1939_ERRQUEUE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh to }(hjhhhNhNubjy )}(h``0``h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh} will purge any currently present error messages in the error queue. When enabled, error messages can be retrieved using the }(hjhhhNhNubjy )}(h``recvmsg(2)``h]h recvmsg(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh system call.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMjhj@hhubh)}(hPWhen subscribing to the error queue, the following error events can be accessed:h]hPWhen subscribing to the error queue, the following error events can be accessed:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMnhj@hhubh)}(hhh](j)}(h:**``J1939_EE_INFO_TX_ABORT``**: Transmission abort errors.h]h)}(hjh](j)}(h**``J1939_EE_INFO_TX_ABORT``**h]h``J1939_EE_INFO_TX_ABORT``}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh: Transmission abort errors.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMqhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hP**``J1939_EE_INFO_RX_RTS``**: Reception of RTS (Request to Send) control frames.h]h)}(hP**``J1939_EE_INFO_RX_RTS``**: Reception of RTS (Request to Send) control frames.h](j)}(h**``J1939_EE_INFO_RX_RTS``**h]h``J1939_EE_INFO_RX_RTS``}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh4: Reception of RTS (Request to Send) control frames.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMrhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hT**``J1939_EE_INFO_RX_DPO``**: Reception of data packets with Data Page Offset (DPO).h]h)}(hT**``J1939_EE_INFO_RX_DPO``**: Reception of data packets with Data Page Offset (DPO).h](j)}(h**``J1939_EE_INFO_RX_DPO``**h]h``J1939_EE_INFO_RX_DPO``}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj0ubh8: Reception of data packets with Data Page Offset (DPO).}(hj0hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMthj,ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(h8**``J1939_EE_INFO_RX_ABORT``**: Reception abort errors. h]h)}(h7**``J1939_EE_INFO_RX_ABORT``**: Reception abort errors.h](j)}(h**``J1939_EE_INFO_RX_ABORT``**h]h``J1939_EE_INFO_RX_ABORT``}(hjZhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjVubh: Reception abort errors.}(hjVhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMvhjRubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMqhj@hhubh)}(hThe error queue can be used to correlate errors with specific message transfer sessions using the session ID (``tskey``). The session ID is assigned via the ``SOF_TIMESTAMPING_OPT_ID`` flag, which is set by enabling the ``SO_TIMESTAMPING`` option.h](hnThe error queue can be used to correlate errors with specific message transfer sessions using the session ID (}(hj~hhhNhNubjy )}(h ``tskey``h]htskey}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj~ubh&). The session ID is assigned via the }(hj~hhhNhNubjy )}(h``SOF_TIMESTAMPING_OPT_ID``h]hSOF_TIMESTAMPING_OPT_ID}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj~ubh$ flag, which is set by enabling the }(hj~hhhNhNubjy )}(h``SO_TIMESTAMPING``h]hSO_TIMESTAMPING}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj~ubh option.}(hj~hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMxhj@hhubh)}(hX]If ``SO_J1939_ERRQUEUE`` is activated, the user is required to pull messages from the error queue, meaning that using plain ``recv(2)`` is not sufficient anymore. The user must use ``recvmsg(2)`` with appropriate flags to handle error messages. Failure to do so can result in the socket becoming blocked with unprocessed error messages in the queue.h](hIf }(hjhhhNhNubjy )}(h``SO_J1939_ERRQUEUE``h]hSO_J1939_ERRQUEUE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubhd is activated, the user is required to pull messages from the error queue, meaning that using plain }(hjhhhNhNubjy )}(h ``recv(2)``h]hrecv(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh. is not sufficient anymore. The user must use }(hjhhhNhNubjy )}(h``recvmsg(2)``h]h recvmsg(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh with appropriate flags to handle error messages. Failure to do so can result in the socket becoming blocked with unprocessed error messages in the queue.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM}hj@hhubh)}(hXIt is **recommended** that ``SO_J1939_ERRQUEUE`` be used in combination with ``SO_TIMESTAMPING`` in most cases. This enables proper error handling along with session tracking and timestamping, providing a more detailed analysis of message transfers and errors.h](hIt is }(hjhhhNhNubj)}(h**recommended**h]h recommended}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh that }(hjhhhNhNubjy )}(h``SO_J1939_ERRQUEUE``h]hSO_J1939_ERRQUEUE}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh be used in combination with }(hjhhhNhNubjy )}(h``SO_TIMESTAMPING``h]hSO_TIMESTAMPING}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh in most cases. This enables proper error handling along with session tracking and timestamping, providing a more detailed analysis of message transfers and errors.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj@hhubh)}(hThe acceptable value **size** for this option is ``sizeof(int)``, and the value is only differentiated between ``0`` and non-zero. A value of ``0`` disables error queue reception and purges any existing error messages, while any non-zero value enables it.h](hThe acceptable value }(hjJhhhNhNubj)}(h**size**h]hsize}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjJubh for this option is }(hjJhhhNhNubjy )}(h``sizeof(int)``h]h sizeof(int)}(hjdhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjJubh/, and the value is only differentiated between }(hjJhhhNhNubjy )}(h``0``h]h0}(hjvhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjJubh and non-zero. A value of }(hjJhhhNhNubjy )}(h``0``h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjJubhl disables error queue reception and purges any existing error messages, while any non-zero value enables it.}(hjJhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj@hhubh)}(hExample:h]hExample:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj@hhubj )}(hXint enable = 1; // Enable error queue reception setsockopt(sock, SOL_CAN_J1939, SO_J1939_ERRQUEUE, &enable, sizeof(enable)); // Enable timestamping with session tracking via tskey int timestamping = SOF_TIMESTAMPING_OPT_ID | SOF_TIMESTAMPING_TX_ACK | SOF_TIMESTAMPING_TX_SCHED | SOF_TIMESTAMPING_RX_SOFTWARE | SOF_TIMESTAMPING_OPT_CMSG; setsockopt(sock, SOL_SOCKET, SO_TIMESTAMPING, ×tamping, sizeof(timestamping));h]hXint enable = 1; // Enable error queue reception setsockopt(sock, SOL_CAN_J1939, SO_J1939_ERRQUEUE, &enable, sizeof(enable)); // Enable timestamping with session tracking via tskey int timestamping = SOF_TIMESTAMPING_OPT_ID | SOF_TIMESTAMPING_TX_ACK | SOF_TIMESTAMPING_TX_SCHED | SOF_TIMESTAMPING_RX_SOFTWARE | SOF_TIMESTAMPING_OPT_CMSG; setsockopt(sock, SOL_SOCKET, SO_TIMESTAMPING, ×tamping, sizeof(timestamping));}hjsbah}(h]h ]h"]h$]h&]hhj j jj }uh1j hhhMhj@hhubh)}(hX=When enabled, error messages can be retrieved using ``recvmsg(2)``. By combining ``SO_J1939_ERRQUEUE`` with ``SO_TIMESTAMPING`` (with ``SOF_TIMESTAMPING_OPT_ID`` and ``SOF_TIMESTAMPING_OPT_CMSG`` enabled), the user can track message transfers, retrieve precise timestamps, and correlate errors with specific sessions.h](h4When enabled, error messages can be retrieved using }(hjhhhNhNubjy )}(h``recvmsg(2)``h]h recvmsg(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh. By combining }(hjhhhNhNubjy )}(h``SO_J1939_ERRQUEUE``h]hSO_J1939_ERRQUEUE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh with }(hjhhhNhNubjy )}(h``SO_TIMESTAMPING``h]hSO_TIMESTAMPING}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh (with }(hjhhhNhNubjy )}(h``SOF_TIMESTAMPING_OPT_ID``h]hSOF_TIMESTAMPING_OPT_ID}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh and }(hjhhhNhNubjy )}(h``SOF_TIMESTAMPING_OPT_CMSG``h]hSOF_TIMESTAMPING_OPT_CMSG}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubhz enabled), the user can track message transfers, retrieve precise timestamps, and correlate errors with specific sessions.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj@hhubh)}(hiFor more information on enabling timestamps and session tracking, refer to the `SO_TIMESTAMPING` section.h](hOFor more information on enabling timestamps and session tracking, refer to the }(hj%hhhNhNubjl)}(h`SO_TIMESTAMPING`h]hSO_TIMESTAMPING}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1jkhj%ubh section.}(hj%hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj@hhubeh}(h]so-j1939-errqueueah ]h"]so_j1939_errqueueah$]h&]uh1hhjhhhhhMbubh)}(hhh](h)}(h``SO_TIMESTAMPING``h]jy )}(hjRh]hSO_TIMESTAMPING}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjPubah}(h]h ]h"]h$]h&]uh1hhjMhhhhhMubh)}(hXDThe ``SO_TIMESTAMPING`` option allows the socket to receive timestamps for various events related to message transmissions and receptions in J1939. This option is often used in combination with ``SO_J1939_ERRQUEUE`` to provide detailed diagnostic information, session tracking, and precise timing data for message transfers.h](hThe }(hjghhhNhNubjy )}(h``SO_TIMESTAMPING``h]hSO_TIMESTAMPING}(hjohhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjgubh option allows the socket to receive timestamps for various events related to message transmissions and receptions in J1939. This option is often used in combination with }(hjghhhNhNubjy )}(h``SO_J1939_ERRQUEUE``h]hSO_J1939_ERRQUEUE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjgubhm to provide detailed diagnostic information, session tracking, and precise timing data for message transfers.}(hjghhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjMhhubh)}(hX$In J1939, all payloads provided by user space, regardless of size, are processed by the kernel as **sessions**. This includes both single-frame messages (up to 8 bytes) and multi-frame protocols such as the Transport Protocol (TP) and Extended Transport Protocol (ETP). Even for small, single-frame messages, the kernel creates a session to manage the transmission and reception. The concept of sessions allows the kernel to manage various aspects of the protocol, such as reassembling multi-frame messages and tracking the status of transmissions.h](hbIn J1939, all payloads provided by user space, regardless of size, are processed by the kernel as }(hjhhhNhNubj)}(h **sessions**h]hsessions}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhX. This includes both single-frame messages (up to 8 bytes) and multi-frame protocols such as the Transport Protocol (TP) and Extended Transport Protocol (ETP). Even for small, single-frame messages, the kernel creates a session to manage the transmission and reception. The concept of sessions allows the kernel to manage various aspects of the protocol, such as reassembling multi-frame messages and tracking the status of transmissions.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjMhhubh)}(hWhen receiving extended error messages from the error queue, the error information is delivered through a `struct sock_extended_err`, accessible via the control message (``cmsg``) retrieved using the ``recvmsg(2)`` system call.h](hjWhen receiving extended error messages from the error queue, the error information is delivered through a }(hjhhhNhNubjl)}(h`struct sock_extended_err`h]hstruct sock_extended_err}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjubh&, accessible via the control message (}(hjhhhNhNubjy )}(h``cmsg``h]hcmsg}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh) retrieved using the }(hjhhhNhNubjy )}(h``recvmsg(2)``h]h recvmsg(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh system call.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjMhhubh)}(hGThere are two typical origins for the extended error messages in J1939:h]hGThere are two typical origins for the extended error messages in J1939:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjMhhubhenumerated_list)}(hhh](j)}(hX``serr->ee_origin == SO_EE_ORIGIN_TIMESTAMPING``: In this case, the `serr->ee_info` field will contain one of the following timestamp types: - ``SCM_TSTAMP_SCHED``: This timestamp is valid for Extended Transport Protocol (ETP) transfers and simple transfers (8 bytes or less). It indicates when a message or set of frames has been scheduled for transmission. - For simple transfers (8 bytes or less), it marks the point when the message is queued and ready to be sent onto the CAN bus. - For ETP transfers, it is sent after receiving a CTS (Clear to Send) frame on the sender side, indicating that a new set of frames has been scheduled for transmission. - The Transport Protocol (TP) case is currently not implemented for this timestamp. - On the receiver side, the counterpart to this event for ETP is represented by the ``J1939_EE_INFO_RX_DPO`` message, which indicates the reception of a Data Page Offset (DPO) control frame. - ``SCM_TSTAMP_ACK``: This timestamp indicates the acknowledgment of the message or session. - For simple transfers (8 bytes or less), it marks when the message has been sent and an echo confirmation has been received from the CAN controller, indicating that the frame was transmitted onto the bus. - For multi-frame transfers (TP or ETP), it signifies that the entire session has been acknowledged, typically after receiving the End of Message Acknowledgment (EOMA) packet. h](h)}(h1``serr->ee_origin == SO_EE_ORIGIN_TIMESTAMPING``:h](jy )}(h0``serr->ee_origin == SO_EE_ORIGIN_TIMESTAMPING``h]h,serr->ee_origin == SO_EE_ORIGIN_TIMESTAMPING}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(hZIn this case, the `serr->ee_info` field will contain one of the following timestamp types:h](hIn this case, the }(hj0hhhNhNubjl)}(h`serr->ee_info`h]h serr->ee_info}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1jkhj0ubh9 field will contain one of the following timestamp types:}(hj0hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(hhh](j)}(hX#``SCM_TSTAMP_SCHED``: This timestamp is valid for Extended Transport Protocol (ETP) transfers and simple transfers (8 bytes or less). It indicates when a message or set of frames has been scheduled for transmission. - For simple transfers (8 bytes or less), it marks the point when the message is queued and ready to be sent onto the CAN bus. - For ETP transfers, it is sent after receiving a CTS (Clear to Send) frame on the sender side, indicating that a new set of frames has been scheduled for transmission. - The Transport Protocol (TP) case is currently not implemented for this timestamp. - On the receiver side, the counterpart to this event for ETP is represented by the ``J1939_EE_INFO_RX_DPO`` message, which indicates the reception of a Data Page Offset (DPO) control frame. h](h)}(h``SCM_TSTAMP_SCHED``: This timestamp is valid for Extended Transport Protocol (ETP) transfers and simple transfers (8 bytes or less). It indicates when a message or set of frames has been scheduled for transmission.h](jy )}(h``SCM_TSTAMP_SCHED``h]hSCM_TSTAMP_SCHED}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjWubh: This timestamp is valid for Extended Transport Protocol (ETP) transfers and simple transfers (8 bytes or less). It indicates when a message or set of frames has been scheduled for transmission.}(hjWhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjSubh)}(hhh](j)}(h}For simple transfers (8 bytes or less), it marks the point when the message is queued and ready to be sent onto the CAN bus. h]h)}(h|For simple transfers (8 bytes or less), it marks the point when the message is queued and ready to be sent onto the CAN bus.h]h|For simple transfers (8 bytes or less), it marks the point when the message is queued and ready to be sent onto the CAN bus.}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjvubah}(h]h ]h"]h$]h&]uh1jhjsubj)}(hFor ETP transfers, it is sent after receiving a CTS (Clear to Send) frame on the sender side, indicating that a new set of frames has been scheduled for transmission. h]h)}(hFor ETP transfers, it is sent after receiving a CTS (Clear to Send) frame on the sender side, indicating that a new set of frames has been scheduled for transmission.h]hFor ETP transfers, it is sent after receiving a CTS (Clear to Send) frame on the sender side, indicating that a new set of frames has been scheduled for transmission.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjsubj)}(hRThe Transport Protocol (TP) case is currently not implemented for this timestamp. h]h)}(hQThe Transport Protocol (TP) case is currently not implemented for this timestamp.h]hQThe Transport Protocol (TP) case is currently not implemented for this timestamp.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjsubj)}(hOn the receiver side, the counterpart to this event for ETP is represented by the ``J1939_EE_INFO_RX_DPO`` message, which indicates the reception of a Data Page Offset (DPO) control frame. h]h)}(hOn the receiver side, the counterpart to this event for ETP is represented by the ``J1939_EE_INFO_RX_DPO`` message, which indicates the reception of a Data Page Offset (DPO) control frame.h](hROn the receiver side, the counterpart to this event for ETP is represented by the }(hjhhhNhNubjy )}(h``J1939_EE_INFO_RX_DPO``h]hJ1939_EE_INFO_RX_DPO}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubhR message, which indicates the reception of a Data Page Offset (DPO) control frame.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjsubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMhjSubeh}(h]h ]h"]h$]h&]uh1jhjPubj)}(hX``SCM_TSTAMP_ACK``: This timestamp indicates the acknowledgment of the message or session. - For simple transfers (8 bytes or less), it marks when the message has been sent and an echo confirmation has been received from the CAN controller, indicating that the frame was transmitted onto the bus. - For multi-frame transfers (TP or ETP), it signifies that the entire session has been acknowledged, typically after receiving the End of Message Acknowledgment (EOMA) packet. h](h)}(hZ``SCM_TSTAMP_ACK``: This timestamp indicates the acknowledgment of the message or session.h](jy )}(h``SCM_TSTAMP_ACK``h]hSCM_TSTAMP_ACK}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubhH: This timestamp indicates the acknowledgment of the message or session.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(hhh](j)}(hFor simple transfers (8 bytes or less), it marks when the message has been sent and an echo confirmation has been received from the CAN controller, indicating that the frame was transmitted onto the bus. h]h)}(hFor simple transfers (8 bytes or less), it marks when the message has been sent and an echo confirmation has been received from the CAN controller, indicating that the frame was transmitted onto the bus.h]hFor simple transfers (8 bytes or less), it marks when the message has been sent and an echo confirmation has been received from the CAN controller, indicating that the frame was transmitted onto the bus.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hFor multi-frame transfers (TP or ETP), it signifies that the entire session has been acknowledged, typically after receiving the End of Message Acknowledgment (EOMA) packet. h]h)}(hFor multi-frame transfers (TP or ETP), it signifies that the entire session has been acknowledged, typically after receiving the End of Message Acknowledgment (EOMA) packet.h]hFor multi-frame transfers (TP or ETP), it signifies that the entire session has been acknowledged, typically after receiving the End of Message Acknowledgment (EOMA) packet.}(hj3hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj/ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1jhjPubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1jhj hhhNhNubj)}(hX ``serr->ee_origin == SO_EE_ORIGIN_LOCAL``: In this case, the `serr->ee_info` field will contain one of the following J1939 stack-specific message types: - ``J1939_EE_INFO_TX_ABORT``: This message indicates that the transmission of a message or session was aborted. The cause of the abort can come from various sources: - **CAN stack failure**: The J1939 stack was unable to pass the frame to the CAN framework for transmission. - **Echo failure**: The J1939 stack did not receive an echo confirmation from the CAN controller, meaning the frame may not have been successfully transmitted to the CAN bus. - **Protocol-level issues**: For multi-frame transfers (TP/ETP), this could include protocol-related errors, such as an abort signaled by the receiver or a timeout at the protocol level, which causes the session to terminate prematurely. - The corresponding error code is stored in ``serr->ee_data`` (``session->err`` on kernel side), providing additional details about the specific reason for the abort. - ``J1939_EE_INFO_RX_RTS``: This message indicates that the J1939 stack has received a Request to Send (RTS) control frame, signaling the start of a multi-frame transfer using the Transport Protocol (TP) or Extended Transport Protocol (ETP). - It informs the receiver that the sender is ready to transmit a multi-frame message and includes details about the total message size and the number of frames to be sent. - Statistics such as ``J1939_NLA_TOTAL_SIZE``, ``J1939_NLA_PGN``, ``J1939_NLA_SRC_NAME``, and ``J1939_NLA_DEST_NAME`` are provided along with the ``J1939_EE_INFO_RX_RTS`` message, giving detailed information about the incoming transfer. - ``J1939_EE_INFO_RX_DPO``: This message indicates that the J1939 stack has received a Data Page Offset (DPO) control frame, which is part of the Extended Transport Protocol (ETP). - The DPO frame signals the continuation of an ETP multi-frame message by indicating the offset position in the data being transferred. It helps the receiver manage large data sets by identifying which portion of the message is being received. - It is typically paired with a corresponding ``SCM_TSTAMP_SCHED`` event on the sender side, which indicates when the next set of frames is scheduled for transmission. - This event includes statistics such as ``J1939_NLA_BYTES_ACKED``, which tracks the number of bytes acknowledged up to that point in the session. - ``J1939_EE_INFO_RX_ABORT``: This message indicates that the reception of a multi-frame message (Transport Protocol or Extended Transport Protocol) has been aborted. - The abort can be triggered by protocol-level errors such as timeouts, an unexpected frame, or a specific abort request from the sender. - This message signals that the receiver cannot continue processing the transfer, and the session is terminated. - The corresponding error code is stored in ``serr->ee_data`` (``session->err`` on kernel side ), providing further details about the reason for the abort, such as protocol violations or timeouts. - After receiving this message, the receiver discards the partially received frames, and the multi-frame session is considered incomplete. h](h)}(h*``serr->ee_origin == SO_EE_ORIGIN_LOCAL``:h](jy )}(h)``serr->ee_origin == SO_EE_ORIGIN_LOCAL``h]h%serr->ee_origin == SO_EE_ORIGIN_LOCAL}(hjghhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjcubh:}(hjchhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj_ubh)}(hmIn this case, the `serr->ee_info` field will contain one of the following J1939 stack-specific message types:h](hIn this case, the }(hjhhhNhNubjl)}(h`serr->ee_info`h]h serr->ee_info}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jkhjubhL field will contain one of the following J1939 stack-specific message types:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj_ubh)}(hhh](j)}(hXi``J1939_EE_INFO_TX_ABORT``: This message indicates that the transmission of a message or session was aborted. The cause of the abort can come from various sources: - **CAN stack failure**: The J1939 stack was unable to pass the frame to the CAN framework for transmission. - **Echo failure**: The J1939 stack did not receive an echo confirmation from the CAN controller, meaning the frame may not have been successfully transmitted to the CAN bus. - **Protocol-level issues**: For multi-frame transfers (TP/ETP), this could include protocol-related errors, such as an abort signaled by the receiver or a timeout at the protocol level, which causes the session to terminate prematurely. - The corresponding error code is stored in ``serr->ee_data`` (``session->err`` on kernel side), providing additional details about the specific reason for the abort. h](h)}(h``J1939_EE_INFO_TX_ABORT``: This message indicates that the transmission of a message or session was aborted. The cause of the abort can come from various sources:h](jy )}(h``J1939_EE_INFO_TX_ABORT``h]hJ1939_EE_INFO_TX_ABORT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh: This message indicates that the transmission of a message or session was aborted. The cause of the abort can come from various sources:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(hhh](j)}(hk**CAN stack failure**: The J1939 stack was unable to pass the frame to the CAN framework for transmission. h]h)}(hj**CAN stack failure**: The J1939 stack was unable to pass the frame to the CAN framework for transmission.h](j)}(h**CAN stack failure**h]hCAN stack failure}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhU: The J1939 stack was unable to pass the frame to the CAN framework for transmission.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(h**Echo failure**: The J1939 stack did not receive an echo confirmation from the CAN controller, meaning the frame may not have been successfully transmitted to the CAN bus. h]h)}(h**Echo failure**: The J1939 stack did not receive an echo confirmation from the CAN controller, meaning the frame may not have been successfully transmitted to the CAN bus.h](j)}(h**Echo failure**h]h Echo failure}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh: The J1939 stack did not receive an echo confirmation from the CAN controller, meaning the frame may not have been successfully transmitted to the CAN bus.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(h**Protocol-level issues**: For multi-frame transfers (TP/ETP), this could include protocol-related errors, such as an abort signaled by the receiver or a timeout at the protocol level, which causes the session to terminate prematurely. h]h)}(h**Protocol-level issues**: For multi-frame transfers (TP/ETP), this could include protocol-related errors, such as an abort signaled by the receiver or a timeout at the protocol level, which causes the session to terminate prematurely.h](j)}(h**Protocol-level issues**h]hProtocol-level issues}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh: For multi-frame transfers (TP/ETP), this could include protocol-related errors, such as an abort signaled by the receiver or a timeout at the protocol level, which causes the session to terminate prematurely.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hThe corresponding error code is stored in ``serr->ee_data`` (``session->err`` on kernel side), providing additional details about the specific reason for the abort. h]h)}(hThe corresponding error code is stored in ``serr->ee_data`` (``session->err`` on kernel side), providing additional details about the specific reason for the abort.h](h*The corresponding error code is stored in }(hj;hhhNhNubjy )}(h``serr->ee_data``h]h serr->ee_data}(hjChhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj;ubh (}(hj;hhhNhNubjy )}(h``session->err``h]h session->err}(hjUhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj;ubhW on kernel side), providing additional details about the specific reason for the abort.}(hj;hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj7ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hX``J1939_EE_INFO_RX_RTS``: This message indicates that the J1939 stack has received a Request to Send (RTS) control frame, signaling the start of a multi-frame transfer using the Transport Protocol (TP) or Extended Transport Protocol (ETP). - It informs the receiver that the sender is ready to transmit a multi-frame message and includes details about the total message size and the number of frames to be sent. - Statistics such as ``J1939_NLA_TOTAL_SIZE``, ``J1939_NLA_PGN``, ``J1939_NLA_SRC_NAME``, and ``J1939_NLA_DEST_NAME`` are provided along with the ``J1939_EE_INFO_RX_RTS`` message, giving detailed information about the incoming transfer. -h](h)}(h``J1939_EE_INFO_RX_RTS``: This message indicates that the J1939 stack has received a Request to Send (RTS) control frame, signaling the start of a multi-frame transfer using the Transport Protocol (TP) or Extended Transport Protocol (ETP).h](jy )}(h``J1939_EE_INFO_RX_RTS``h]hJ1939_EE_INFO_RX_RTS}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh: This message indicates that the J1939 stack has received a Request to Send (RTS) control frame, signaling the start of a multi-frame transfer using the Transport Protocol (TP) or Extended Transport Protocol (ETP).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(hhh](j)}(hIt informs the receiver that the sender is ready to transmit a multi-frame message and includes details about the total message size and the number of frames to be sent. h]h)}(hIt informs the receiver that the sender is ready to transmit a multi-frame message and includes details about the total message size and the number of frames to be sent.h]hIt informs the receiver that the sender is ready to transmit a multi-frame message and includes details about the total message size and the number of frames to be sent.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hStatistics such as ``J1939_NLA_TOTAL_SIZE``, ``J1939_NLA_PGN``, ``J1939_NLA_SRC_NAME``, and ``J1939_NLA_DEST_NAME`` are provided along with the ``J1939_EE_INFO_RX_RTS`` message, giving detailed information about the incoming transfer. h]h)}(hStatistics such as ``J1939_NLA_TOTAL_SIZE``, ``J1939_NLA_PGN``, ``J1939_NLA_SRC_NAME``, and ``J1939_NLA_DEST_NAME`` are provided along with the ``J1939_EE_INFO_RX_RTS`` message, giving detailed information about the incoming transfer.h](hStatistics such as }(hjhhhNhNubjy )}(h``J1939_NLA_TOTAL_SIZE``h]hJ1939_NLA_TOTAL_SIZE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh, }(hjhhhNhNubjy )}(h``J1939_NLA_PGN``h]h J1939_NLA_PGN}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh, }(hjhhhNhNubjy )}(h``J1939_NLA_SRC_NAME``h]hJ1939_NLA_SRC_NAME}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh, and }(hjhhhNhNubjy )}(h``J1939_NLA_DEST_NAME``h]hJ1939_NLA_DEST_NAME}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh are provided along with the }(hjhhhNhNubjy )}(h``J1939_EE_INFO_RX_RTS``h]hJ1939_EE_INFO_RX_RTS}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubhB message, giving detailed information about the incoming transfer.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hX``J1939_EE_INFO_RX_DPO``: This message indicates that the J1939 stack has received a Data Page Offset (DPO) control frame, which is part of the Extended Transport Protocol (ETP). - The DPO frame signals the continuation of an ETP multi-frame message by indicating the offset position in the data being transferred. It helps the receiver manage large data sets by identifying which portion of the message is being received. - It is typically paired with a corresponding ``SCM_TSTAMP_SCHED`` event on the sender side, which indicates when the next set of frames is scheduled for transmission. - This event includes statistics such as ``J1939_NLA_BYTES_ACKED``, which tracks the number of bytes acknowledged up to that point in the session. h](h)}(h``J1939_EE_INFO_RX_DPO``: This message indicates that the J1939 stack has received a Data Page Offset (DPO) control frame, which is part of the Extended Transport Protocol (ETP).h](jy )}(h``J1939_EE_INFO_RX_DPO``h]hJ1939_EE_INFO_RX_DPO}(hj@hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj<ubh: This message indicates that the J1939 stack has received a Data Page Offset (DPO) control frame, which is part of the Extended Transport Protocol (ETP).}(hj<hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj8ubh)}(hhh](j)}(hThe DPO frame signals the continuation of an ETP multi-frame message by indicating the offset position in the data being transferred. It helps the receiver manage large data sets by identifying which portion of the message is being received. h]h)}(hThe DPO frame signals the continuation of an ETP multi-frame message by indicating the offset position in the data being transferred. It helps the receiver manage large data sets by identifying which portion of the message is being received.h]hThe DPO frame signals the continuation of an ETP multi-frame message by indicating the offset position in the data being transferred. It helps the receiver manage large data sets by identifying which portion of the message is being received.}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj[ubah}(h]h ]h"]h$]h&]uh1jhjXubj)}(hIt is typically paired with a corresponding ``SCM_TSTAMP_SCHED`` event on the sender side, which indicates when the next set of frames is scheduled for transmission. h]h)}(hIt is typically paired with a corresponding ``SCM_TSTAMP_SCHED`` event on the sender side, which indicates when the next set of frames is scheduled for transmission.h](h,It is typically paired with a corresponding }(hjwhhhNhNubjy )}(h``SCM_TSTAMP_SCHED``h]hSCM_TSTAMP_SCHED}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjwubhe event on the sender side, which indicates when the next set of frames is scheduled for transmission.}(hjwhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjsubah}(h]h ]h"]h$]h&]uh1jhjXubj)}(hThis event includes statistics such as ``J1939_NLA_BYTES_ACKED``, which tracks the number of bytes acknowledged up to that point in the session. h]h)}(hThis event includes statistics such as ``J1939_NLA_BYTES_ACKED``, which tracks the number of bytes acknowledged up to that point in the session.h](h'This event includes statistics such as }(hjhhhNhNubjy )}(h``J1939_NLA_BYTES_ACKED``h]hJ1939_NLA_BYTES_ACKED}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubhP, which tracks the number of bytes acknowledged up to that point in the session.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjXubeh}(h]h ]h"]h$]h&]jNjuh1hhhhM hj8ubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hX``J1939_EE_INFO_RX_ABORT``: This message indicates that the reception of a multi-frame message (Transport Protocol or Extended Transport Protocol) has been aborted. - The abort can be triggered by protocol-level errors such as timeouts, an unexpected frame, or a specific abort request from the sender. - This message signals that the receiver cannot continue processing the transfer, and the session is terminated. - The corresponding error code is stored in ``serr->ee_data`` (``session->err`` on kernel side ), providing further details about the reason for the abort, such as protocol violations or timeouts. - After receiving this message, the receiver discards the partially received frames, and the multi-frame session is considered incomplete. h](h)}(h``J1939_EE_INFO_RX_ABORT``: This message indicates that the reception of a multi-frame message (Transport Protocol or Extended Transport Protocol) has been aborted.h](jy )}(h``J1939_EE_INFO_RX_ABORT``h]hJ1939_EE_INFO_RX_ABORT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjubh: This message indicates that the reception of a multi-frame message (Transport Protocol or Extended Transport Protocol) has been aborted.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubh)}(hhh](j)}(hThe abort can be triggered by protocol-level errors such as timeouts, an unexpected frame, or a specific abort request from the sender. h]h)}(hThe abort can be triggered by protocol-level errors such as timeouts, an unexpected frame, or a specific abort request from the sender.h]hThe abort can be triggered by protocol-level errors such as timeouts, an unexpected frame, or a specific abort request from the sender.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hoThis message signals that the receiver cannot continue processing the transfer, and the session is terminated. h]h)}(hnThis message signals that the receiver cannot continue processing the transfer, and the session is terminated.h]hnThis message signals that the receiver cannot continue processing the transfer, and the session is terminated.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hThe corresponding error code is stored in ``serr->ee_data`` (``session->err`` on kernel side ), providing further details about the reason for the abort, such as protocol violations or timeouts. h]h)}(hThe corresponding error code is stored in ``serr->ee_data`` (``session->err`` on kernel side ), providing further details about the reason for the abort, such as protocol violations or timeouts.h](h*The corresponding error code is stored in }(hj* hhhNhNubjy )}(h``serr->ee_data``h]h serr->ee_data}(hj2 hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj* ubh (}(hj* hhhNhNubjy )}(h``session->err``h]h session->err}(hjD hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj* ubhu on kernel side ), providing further details about the reason for the abort, such as protocol violations or timeouts.}(hj* hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM hj& ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hAfter receiving this message, the receiver discards the partially received frames, and the multi-frame session is considered incomplete. h]h)}(hAfter receiving this message, the receiver discards the partially received frames, and the multi-frame session is considered incomplete.h]hAfter receiving this message, the receiver discards the partially received frames, and the multi-frame session is considered incomplete.}(hjf hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM$hjb ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMhjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMhj_ubeh}(h]h ]h"]h$]h&]uh1jhj hhhNhNubeh}(h]h ]h"]h$]h&]enumtypearabicprefixhsuffix.uh1j hjMhhhhhMubh)}(hXIn both cases, if ``SOF_TIMESTAMPING_OPT_ID`` is enabled, ``serr->ee_data`` will be set to the session’s unique identifier (``session->tskey``). This allows user space to track message transfers by their session identifier across multiple frames or stages.h](hIn both cases, if }(hj hhhNhNubjy )}(h``SOF_TIMESTAMPING_OPT_ID``h]hSOF_TIMESTAMPING_OPT_ID}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh is enabled, }(hj hhhNhNubjy )}(h``serr->ee_data``h]h serr->ee_data}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh3 will be set to the session’s unique identifier (}(hj hhhNhNubjy )}(h``session->tskey``h]hsession->tskey}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubhr). This allows user space to track message transfers by their session identifier across multiple frames or stages.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM'hjMhhubh)}(hXIn all other cases, ``serr->ee_errno`` will be set to ``ENOMSG``, except for the ``J1939_EE_INFO_TX_ABORT`` and ``J1939_EE_INFO_RX_ABORT`` cases, where the kernel sets ``serr->ee_data`` to the error stored in ``session->err``. All protocol-specific errors are converted to standard kernel error values and stored in ``session->err``. These error values are unified across system calls and ``serr->ee_errno``. Some of the known error values are described in the `Error Codes in the J1939 Stack` section.h](hIn all other cases, }(hj hhhNhNubjy )}(h``serr->ee_errno``h]hserr->ee_errno}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh will be set to }(hj hhhNhNubjy )}(h ``ENOMSG``h]hENOMSG}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh, except for the }(hj hhhNhNubjy )}(h``J1939_EE_INFO_TX_ABORT``h]hJ1939_EE_INFO_TX_ABORT}(hj !hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh and }(hj hhhNhNubjy )}(h``J1939_EE_INFO_RX_ABORT``h]hJ1939_EE_INFO_RX_ABORT}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh cases, where the kernel sets }(hj hhhNhNubjy )}(h``serr->ee_data``h]h serr->ee_data}(hj1!hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh to the error stored in }(hj hhhNhNubjy )}(h``session->err``h]h session->err}(hjC!hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh\. All protocol-specific errors are converted to standard kernel error values and stored in }(hj hhhNhNubjy )}(h``session->err``h]h session->err}(hjU!hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh9. These error values are unified across system calls and }(hj hhhNhNubjy )}(h``serr->ee_errno``h]hserr->ee_errno}(hjg!hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj ubh7. Some of the known error values are described in the }(hj hhhNhNubjl)}(h `Error Codes in the J1939 Stack`h]hError Codes in the J1939 Stack}(hjy!hhhNhNubah}(h]h ]h"]h$]h&]uh1jkhj ubh section.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM,hjMhhubh)}(hWhen the `J1939_EE_INFO_RX_RTS` message is provided, it will include the following statistics for multi-frame messages (TP and ETP):h](h When the }(hj!hhhNhNubjl)}(h`J1939_EE_INFO_RX_RTS`h]hJ1939_EE_INFO_RX_RTS}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1jkhj!ubhe message is provided, it will include the following statistics for multi-frame messages (TP and ETP):}(hj!hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM4hjMhhubj)}(hX- ``J1939_NLA_TOTAL_SIZE``: Total size of the message in the session. - ``J1939_NLA_PGN``: Parameter Group Number (PGN) identifying the message type. - ``J1939_NLA_SRC_NAME``: 64-bit name of the source ECU. - ``J1939_NLA_DEST_NAME``: 64-bit name of the destination ECU. - ``J1939_NLA_SRC_ADDR``: 8-bit source address of the sending ECU. - ``J1939_NLA_DEST_ADDR``: 8-bit destination address of the receiving ECU. h]h)}(hhh](j)}(hC``J1939_NLA_TOTAL_SIZE``: Total size of the message in the session.h]h)}(hj!h](jy )}(h``J1939_NLA_TOTAL_SIZE``h]hJ1939_NLA_TOTAL_SIZE}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj!ubh+: Total size of the message in the session.}(hj!hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM7hj!ubah}(h]h ]h"]h$]h&]uh1jhj!ubj)}(hM``J1939_NLA_PGN``: Parameter Group Number (PGN) identifying the message type.h]h)}(hj!h](jy )}(h``J1939_NLA_PGN``h]h J1939_NLA_PGN}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj!ubh<: Parameter Group Number (PGN) identifying the message type.}(hj!hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM8hj!ubah}(h]h ]h"]h$]h&]uh1jhj!ubj)}(h6``J1939_NLA_SRC_NAME``: 64-bit name of the source ECU.h]h)}(hj"h](jy )}(h``J1939_NLA_SRC_NAME``h]hJ1939_NLA_SRC_NAME}(hj "hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj"ubh : 64-bit name of the source ECU.}(hj"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM9hj"ubah}(h]h ]h"]h$]h&]uh1jhj!ubj)}(h<``J1939_NLA_DEST_NAME``: 64-bit name of the destination ECU.h]h)}(hj)"h](jy )}(h``J1939_NLA_DEST_NAME``h]hJ1939_NLA_DEST_NAME}(hj."hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj+"ubh%: 64-bit name of the destination ECU.}(hj+"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM:hj'"ubah}(h]h ]h"]h$]h&]uh1jhj!ubj)}(h@``J1939_NLA_SRC_ADDR``: 8-bit source address of the sending ECU.h]h)}(hjN"h](jy )}(h``J1939_NLA_SRC_ADDR``h]hJ1939_NLA_SRC_ADDR}(hjS"hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjP"ubh*: 8-bit source address of the sending ECU.}(hjP"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM;hjL"ubah}(h]h ]h"]h$]h&]uh1jhj!ubj)}(hI``J1939_NLA_DEST_ADDR``: 8-bit destination address of the receiving ECU. h]h)}(hH``J1939_NLA_DEST_ADDR``: 8-bit destination address of the receiving ECU.h](jy )}(h``J1939_NLA_DEST_ADDR``h]hJ1939_NLA_DEST_ADDR}(hjy"hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hju"ubh1: 8-bit destination address of the receiving ECU.}(hju"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM<hjq"ubah}(h]h ]h"]h$]h&]uh1jhj!ubeh}(h]h ]h"]h$]h&]jNjuh1hhhhM7hj!ubah}(h]h ]h"]h$]h&]uh1jhhhM7hjMhhubh)}(hhh]j)}(hFor other messages (including single-frame messages), only the following statistic is included: - ``J1939_NLA_BYTES_ACKED``: Number of bytes successfully acknowledged in the session. h](h)}(h_For other messages (including single-frame messages), only the following statistic is included:h]h_For other messages (including single-frame messages), only the following statistic is included:}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM>hj"ubh)}(hhh]j)}(hU``J1939_NLA_BYTES_ACKED``: Number of bytes successfully acknowledged in the session. h]h)}(hT``J1939_NLA_BYTES_ACKED``: Number of bytes successfully acknowledged in the session.h](jy )}(h``J1939_NLA_BYTES_ACKED``h]hJ1939_NLA_BYTES_ACKED}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj"ubh;: Number of bytes successfully acknowledged in the session.}(hj"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMAhj"ubah}(h]h ]h"]h$]h&]uh1jhj"ubah}(h]h ]h"]h$]h&]jNjuh1hhhhMAhj"ubeh}(h]h ]h"]h$]h&]uh1jhj"hhhNhNubah}(h]h ]h"]h$]h&]jNjuh1hhhhM>hjMhhubh)}(h.The key flags for ``SO_TIMESTAMPING`` include:h](hThe key flags for }(hj"hhhNhNubjy )}(h``SO_TIMESTAMPING``h]hSO_TIMESTAMPING}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj"ubh include:}(hj"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMDhjMhhubh)}(hhh](j)}(hX``SOF_TIMESTAMPING_OPT_ID``: Enables the use of a unique session identifier (``tskey``) for each transfer. This identifier helps track message transfers and errors as distinct sessions in user space. When this option is enabled, ``serr->ee_data`` will be set to ``session->tskey``. h]h)}(hX``SOF_TIMESTAMPING_OPT_ID``: Enables the use of a unique session identifier (``tskey``) for each transfer. This identifier helps track message transfers and errors as distinct sessions in user space. When this option is enabled, ``serr->ee_data`` will be set to ``session->tskey``.h](jy )}(h``SOF_TIMESTAMPING_OPT_ID``h]hSOF_TIMESTAMPING_OPT_ID}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj#ubh2: Enables the use of a unique session identifier (}(hj#hhhNhNubjy )}(h ``tskey``h]htskey}(hj0#hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj#ubh) for each transfer. This identifier helps track message transfers and errors as distinct sessions in user space. When this option is enabled, }(hj#hhhNhNubjy )}(h``serr->ee_data``h]h serr->ee_data}(hjB#hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj#ubh will be set to }(hj#hhhNhNubjy )}(h``session->tskey``h]hsession->tskey}(hjT#hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj#ubh.}(hj#hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMFhj#ubah}(h]h ]h"]h$]h&]uh1jhj#hhhhhNubj)}(h``SOF_TIMESTAMPING_OPT_CMSG``: Sends timestamp information through control messages (``struct scm_timestamping``), allowing the application to retrieve timestamps alongside the data. h]h)}(h``SOF_TIMESTAMPING_OPT_CMSG``: Sends timestamp information through control messages (``struct scm_timestamping``), allowing the application to retrieve timestamps alongside the data.h](jy )}(h``SOF_TIMESTAMPING_OPT_CMSG``h]hSOF_TIMESTAMPING_OPT_CMSG}(hjz#hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjv#ubh8: Sends timestamp information through control messages (}(hjv#hhhNhNubjy )}(h``struct scm_timestamping``h]hstruct scm_timestamping}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjv#ubhF), allowing the application to retrieve timestamps alongside the data.}(hjv#hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMKhjr#ubah}(h]h ]h"]h$]h&]uh1jhj#hhhhhNubj)}(h``SOF_TIMESTAMPING_TX_SCHED``: Provides the timestamp for when a message is scheduled for transmission (``SCM_TSTAMP_SCHED``). h]h)}(h~``SOF_TIMESTAMPING_TX_SCHED``: Provides the timestamp for when a message is scheduled for transmission (``SCM_TSTAMP_SCHED``).h](jy )}(h``SOF_TIMESTAMPING_TX_SCHED``h]hSOF_TIMESTAMPING_TX_SCHED}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj#ubhK: Provides the timestamp for when a message is scheduled for transmission (}(hj#hhhNhNubjy )}(h``SCM_TSTAMP_SCHED``h]hSCM_TSTAMP_SCHED}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj#ubh).}(hj#hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMOhj#ubah}(h]h ]h"]h$]h&]uh1jhj#hhhhhNubj)}(h``SOF_TIMESTAMPING_TX_ACK``: Provides the timestamp for when a message transmission is fully acknowledged (``SCM_TSTAMP_ACK``). h]h)}(h``SOF_TIMESTAMPING_TX_ACK``: Provides the timestamp for when a message transmission is fully acknowledged (``SCM_TSTAMP_ACK``).h](jy )}(h``SOF_TIMESTAMPING_TX_ACK``h]hSOF_TIMESTAMPING_TX_ACK}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj#ubhP: Provides the timestamp for when a message transmission is fully acknowledged (}(hj#hhhNhNubjy )}(h``SCM_TSTAMP_ACK``h]hSCM_TSTAMP_ACK}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj#ubh).}(hj#hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMRhj#ubah}(h]h ]h"]h$]h&]uh1jhj#hhhhhNubj)}(h``SOF_TIMESTAMPING_RX_SOFTWARE``: Provides timestamps for reception-related events (e.g., ``J1939_EE_INFO_RX_RTS``, ``J1939_EE_INFO_RX_DPO``, ``J1939_EE_INFO_RX_ABORT``). h]h)}(h``SOF_TIMESTAMPING_RX_SOFTWARE``: Provides timestamps for reception-related events (e.g., ``J1939_EE_INFO_RX_RTS``, ``J1939_EE_INFO_RX_DPO``, ``J1939_EE_INFO_RX_ABORT``).h](jy )}(h ``SOF_TIMESTAMPING_RX_SOFTWARE``h]hSOF_TIMESTAMPING_RX_SOFTWARE}(hj"$hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj$ubh:: Provides timestamps for reception-related events (e.g., }(hj$hhhNhNubjy )}(h``J1939_EE_INFO_RX_RTS``h]hJ1939_EE_INFO_RX_RTS}(hj4$hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj$ubh, }(hj$hhhNhNubjy )}(h``J1939_EE_INFO_RX_DPO``h]hJ1939_EE_INFO_RX_DPO}(hjF$hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj$ubh, }(hj$hhhNhNubjy )}(h``J1939_EE_INFO_RX_ABORT``h]hJ1939_EE_INFO_RX_ABORT}(hjX$hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj$ubh).}(hj$hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMUhj$ubah}(h]h ]h"]h$]h&]uh1jhj#hhhhhNubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMFhjMhhubh)}(hThese flags enable detailed monitoring of message lifecycles, including transmission scheduling, acknowledgments, reception timestamps, and gathering detailed statistics about the communication session, especially for multi-frame payloads like TP and ETP.h]hThese flags enable detailed monitoring of message lifecycles, including transmission scheduling, acknowledgments, reception timestamps, and gathering detailed statistics about the communication session, especially for multi-frame payloads like TP and ETP.}(hj|$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMYhjMhhubh)}(hExample:h]hExample:}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM^hjMhhubj )}(hX{// Enable timestamping with various options, including session tracking and // statistics int sock_opt = SOF_TIMESTAMPING_OPT_CMSG | SOF_TIMESTAMPING_TX_ACK | SOF_TIMESTAMPING_TX_SCHED | SOF_TIMESTAMPING_OPT_ID | SOF_TIMESTAMPING_RX_SOFTWARE; setsockopt(sock, SOL_SOCKET, SO_TIMESTAMPING, &sock_opt, sizeof(sock_opt));h]hX{// Enable timestamping with various options, including session tracking and // statistics int sock_opt = SOF_TIMESTAMPING_OPT_CMSG | SOF_TIMESTAMPING_TX_ACK | SOF_TIMESTAMPING_TX_SCHED | SOF_TIMESTAMPING_OPT_ID | SOF_TIMESTAMPING_RX_SOFTWARE; setsockopt(sock, SOL_SOCKET, SO_TIMESTAMPING, &sock_opt, sizeof(sock_opt));}hj$sbah}(h]h ]h"]h$]h&]hhj j jj }uh1j hhhM`hjMhhubeh}(h]so-timestampingah ]h"]so_timestampingah$]h&]uh1hhjhhhhhMubeh}(h] setsockopt-2ah ]h"] setsockopt(2)ah$]h&]uh1hhj_ hhhhhMubeh}(h] api-callsah ]h"] api callsah$]h&]uh1hhjN hhhhhKubh)}(hhh](h)}(hDynamic Addressingh]hDynamic Addressing}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj$hhhhhMoubh)}(hXYDistinction has to be made between using the claimed address and doing an address claim. To use an already claimed address, one has to fill in the ``j1939.name`` member and provide it to ``bind(2)``. If the name had claimed an address earlier, all further messages being sent will use that address. And the ``j1939.addr`` member will be ignored.h](hDistinction has to be made between using the claimed address and doing an address claim. To use an already claimed address, one has to fill in the }(hj$hhhNhNubjy )}(h``j1939.name``h]h j1939.name}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj$ubh member and provide it to }(hj$hhhNhNubjy )}(h ``bind(2)``h]hbind(2)}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj$ubhm. If the name had claimed an address earlier, all further messages being sent will use that address. And the }(hj$hhhNhNubjy )}(h``j1939.addr``h]h j1939.addr}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj$ubh member will be ignored.}(hj$hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMqhj$hhubh)}(hAn exception on this is PGN 0x0ee00. This is the "Address Claim/Cannot Claim Address" message and the kernel will use the ``j1939.addr`` member for that PGN if necessary.h](h~An exception on this is PGN 0x0ee00. This is the “Address Claim/Cannot Claim Address” message and the kernel will use the }(hj%hhhNhNubjy )}(h``j1939.addr``h]h j1939.addr}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj%ubh" member for that PGN if necessary.}(hj%hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMwhj$hhubh)}(h7To claim an address following code example can be used:h]h7To claim an address following code example can be used:}(hj4%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM{hj$hhubj )}(hXstruct sockaddr_can baddr = { .can_family = AF_CAN, .can_addr.j1939 = { .name = name, .addr = J1939_IDLE_ADDR, .pgn = J1939_NO_PGN, /* to disable bind() rx filter for PGN */ }, .can_ifindex = if_nametoindex("can0"), }; bind(sock, (struct sockaddr *)&baddr, sizeof(baddr)); /* for Address Claiming broadcast must be allowed */ int value = 1; setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &value, sizeof(value)); /* configured advanced RX filter with PGN needed for Address Claiming */ const struct j1939_filter filt[] = { { .pgn = J1939_PGN_ADDRESS_CLAIMED, .pgn_mask = J1939_PGN_PDU1_MAX, }, { .pgn = J1939_PGN_REQUEST, .pgn_mask = J1939_PGN_PDU1_MAX, }, { .pgn = J1939_PGN_ADDRESS_COMMANDED, .pgn_mask = J1939_PGN_MAX, }, }; setsockopt(sock, SOL_CAN_J1939, SO_J1939_FILTER, &filt, sizeof(filt)); uint64_t dat = htole64(name); const struct sockaddr_can saddr = { .can_family = AF_CAN, .can_addr.j1939 = { .pgn = J1939_PGN_ADDRESS_CLAIMED, .addr = J1939_NO_ADDR, }, }; /* Afterwards do a sendto(2) with data set to the NAME (Little Endian). If the * NAME provided, does not match the j1939.name provided to bind(2), EPROTO * will be returned. */ sendto(sock, dat, sizeof(dat), 0, (const struct sockaddr *)&saddr, sizeof(saddr));h]hXstruct sockaddr_can baddr = { .can_family = AF_CAN, .can_addr.j1939 = { .name = name, .addr = J1939_IDLE_ADDR, .pgn = J1939_NO_PGN, /* to disable bind() rx filter for PGN */ }, .can_ifindex = if_nametoindex("can0"), }; bind(sock, (struct sockaddr *)&baddr, sizeof(baddr)); /* for Address Claiming broadcast must be allowed */ int value = 1; setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &value, sizeof(value)); /* configured advanced RX filter with PGN needed for Address Claiming */ const struct j1939_filter filt[] = { { .pgn = J1939_PGN_ADDRESS_CLAIMED, .pgn_mask = J1939_PGN_PDU1_MAX, }, { .pgn = J1939_PGN_REQUEST, .pgn_mask = J1939_PGN_PDU1_MAX, }, { .pgn = J1939_PGN_ADDRESS_COMMANDED, .pgn_mask = J1939_PGN_MAX, }, }; setsockopt(sock, SOL_CAN_J1939, SO_J1939_FILTER, &filt, sizeof(filt)); uint64_t dat = htole64(name); const struct sockaddr_can saddr = { .can_family = AF_CAN, .can_addr.j1939 = { .pgn = J1939_PGN_ADDRESS_CLAIMED, .addr = J1939_NO_ADDR, }, }; /* Afterwards do a sendto(2) with data set to the NAME (Little Endian). If the * NAME provided, does not match the j1939.name provided to bind(2), EPROTO * will be returned. */ sendto(sock, dat, sizeof(dat), 0, (const struct sockaddr *)&saddr, sizeof(saddr));}hjB%sbah}(h]h ]h"]h$]h&]hhj j j j }uh1j hhhM}hj$hhubh)}(hXIf no-one else contests the address claim within 250ms after transmission, the kernel marks the NAME-SA assignment as valid. The valid assignment will be kept among other valid NAME-SA assignments. From that point, any socket bound to the NAME can send packets.h]hXIf no-one else contests the address claim within 250ms after transmission, the kernel marks the NAME-SA assignment as valid. The valid assignment will be kept among other valid NAME-SA assignments. From that point, any socket bound to the NAME can send packets.}(hjQ%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj$hhubh)}(hXIf another ECU claims the address, the kernel will mark the NAME-SA expired. No socket bound to the NAME can send packets (other than address claims). To claim another address, some socket bound to NAME, must ``bind(2)`` again, but with only ``j1939.addr`` changed to the new SA, and must then send a valid address claim packet. This restarts the state machine in the kernel (and any other participant on the bus) for this NAME.h](hIf another ECU claims the address, the kernel will mark the NAME-SA expired. No socket bound to the NAME can send packets (other than address claims). To claim another address, some socket bound to NAME, must }(hj_%hhhNhNubjy )}(h ``bind(2)``h]hbind(2)}(hjg%hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj_%ubh again, but with only }(hj_%hhhNhNubjy )}(h``j1939.addr``h]h j1939.addr}(hjy%hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj_%ubh changed to the new SA, and must then send a valid address claim packet. This restarts the state machine in the kernel (and any other participant on the bus) for this NAME.}(hj_%hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj$hhubh)}(hz``can-utils`` also include the ``j1939acd`` tool, so it can be used as code example or as default Address Claiming daemon.h](jy )}(h ``can-utils``h]h can-utils}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj%ubh also include the }(hj%hhhNhNubjy )}(h ``j1939acd``h]hj1939acd}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj%ubhO tool, so it can be used as code example or as default Address Claiming daemon.}(hj%hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj$hhubeh}(h]dynamic-addressingah ]h"]dynamic addressingah$]h&]uh1hhjN hhhhhMoubh)}(hhh](h)}(h Send Examplesh]h Send Examples}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj%hhhhhMubh)}(hhh](h)}(hStatic Addressingh]hStatic Addressing}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj%hhhhhMubh)}(h?This example will send a PGN (0x12300) from SA 0x20 to DA 0x30.h]h?This example will send a PGN (0x12300) from SA 0x20 to DA 0x30.}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj%hhubh)}(hBind:h]hBind:}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj%hhubj )}(hX5struct sockaddr_can baddr = { .can_family = AF_CAN, .can_addr.j1939 = { .name = J1939_NO_NAME, .addr = 0x20, .pgn = J1939_NO_PGN, }, .can_ifindex = if_nametoindex("can0"), }; bind(sock, (struct sockaddr *)&baddr, sizeof(baddr));h]hX5struct sockaddr_can baddr = { .can_family = AF_CAN, .can_addr.j1939 = { .name = J1939_NO_NAME, .addr = 0x20, .pgn = J1939_NO_PGN, }, .can_ifindex = if_nametoindex("can0"), }; bind(sock, (struct sockaddr *)&baddr, sizeof(baddr));}hj&sbah}(h]h ]h"]h$]h&]hhj j j j }uh1j hhhMhj%hhubh)}(hNow, the socket 'sock' is bound to the SA 0x20. Since no ``connect(2)`` was called, at this point we can use only ``sendto(2)`` or ``sendmsg(2)``.h](h=Now, the socket ‘sock’ is bound to the SA 0x20. Since no }(hj&hhhNhNubjy )}(h``connect(2)``h]h connect(2)}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj&ubh+ was called, at this point we can use only }(hj&hhhNhNubjy )}(h ``sendto(2)``h]h sendto(2)}(hj.&hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj&ubh or }(hj&hhhNhNubjy )}(h``sendmsg(2)``h]h sendmsg(2)}(hj@&hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj&ubh.}(hj&hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj%hhubh)}(hSend:h]hSend:}(hjX&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj%hhubj )}(hX$const struct sockaddr_can saddr = { .can_family = AF_CAN, .can_addr.j1939 = { .name = J1939_NO_NAME; .addr = 0x30, .pgn = 0x12300, }, }; sendto(sock, dat, sizeof(dat), 0, (const struct sockaddr *)&saddr, sizeof(saddr));h]hX$const struct sockaddr_can saddr = { .can_family = AF_CAN, .can_addr.j1939 = { .name = J1939_NO_NAME; .addr = 0x30, .pgn = 0x12300, }, }; sendto(sock, dat, sizeof(dat), 0, (const struct sockaddr *)&saddr, sizeof(saddr));}hjf&sbah}(h]h ]h"]h$]h&]hhj j j j }uh1j hhhMhj%hhubeh}(h]static-addressingah ]h"]static addressingah$]h&]uh1hhj%hhhhhMubeh}(h] send-examplesah ]h"] send examplesah$]h&]uh1hhjN hhhhhMubh)}(hhh](h)}(hError Codes in the J1939 Stackh]hError Codes in the J1939 Stack}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj&hhhhhMubh)}(hThis section lists all potential kernel error codes that can be exposed to user space when interacting with the J1939 stack. It includes both standard error codes and those derived from protocol-specific abort codes.h]hThis section lists all potential kernel error codes that can be exposed to user space when interacting with the J1939 stack. It includes both standard error codes and those derived from protocol-specific abort codes.}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj&hhubh)}(hhh](j)}(h``EAGAIN``: Operation would block; retry may succeed. One common reason is that an active TP or ETP session exists, and an attempt was made to start a new overlapping TP or ETP session between the same peers. h]h)}(h``EAGAIN``: Operation would block; retry may succeed. One common reason is that an active TP or ETP session exists, and an attempt was made to start a new overlapping TP or ETP session between the same peers.h](jy )}(h ``EAGAIN``h]hEAGAIN}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj&ubh: Operation would block; retry may succeed. One common reason is that an active TP or ETP session exists, and an attempt was made to start a new overlapping TP or ETP session between the same peers.}(hj&hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj&ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(hc``ENETDOWN``: Network is down. This occurs when the CAN interface is switched to the "down" state. h]h)}(hb``ENETDOWN``: Network is down. This occurs when the CAN interface is switched to the "down" state.h](jy )}(h ``ENETDOWN``h]hENETDOWN}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj&ubhZ: Network is down. This occurs when the CAN interface is switched to the “down” state.}(hj&hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj&ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h``ENOBUFS``: No buffer space available. This error occurs when the CAN interface's transmit (TX) queue is full, and no more messages can be queued. h]h)}(h``ENOBUFS``: No buffer space available. This error occurs when the CAN interface's transmit (TX) queue is full, and no more messages can be queued.h](jy )}(h ``ENOBUFS``h]hENOBUFS}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj&ubh: No buffer space available. This error occurs when the CAN interface’s transmit (TX) queue is full, and no more messages can be queued.}(hj&hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj&ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(hX``EOVERFLOW``: Value too large for defined data type. In J1939, this can happen if the requested data lies outside of the queued buffer. For example, if a CTS (Clear to Send) requests an offset not available in the kernel buffer because user space did not provide enough data. h]h)}(hX``EOVERFLOW``: Value too large for defined data type. In J1939, this can happen if the requested data lies outside of the queued buffer. For example, if a CTS (Clear to Send) requests an offset not available in the kernel buffer because user space did not provide enough data.h](jy )}(h ``EOVERFLOW``h]h EOVERFLOW}(hj!'hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj'ubhX: Value too large for defined data type. In J1939, this can happen if the requested data lies outside of the queued buffer. For example, if a CTS (Clear to Send) requests an offset not available in the kernel buffer because user space did not provide enough data.}(hj'hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj'ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h``EBUSY``: Device or resource is busy. For example, this occurs if an identical session is already active and the stack is unable to recover from the condition. h]h)}(h``EBUSY``: Device or resource is busy. For example, this occurs if an identical session is already active and the stack is unable to recover from the condition.h](jy )}(h ``EBUSY``h]hEBUSY}(hjG'hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjC'ubh: Device or resource is busy. For example, this occurs if an identical session is already active and the stack is unable to recover from the condition.}(hjC'hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj?'ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h``EACCES``: Permission denied. This error can occur, for example, when attempting to send broadcast messages, but the socket is not configured with ``SO_BROADCAST``. h]h)}(h``EACCES``: Permission denied. This error can occur, for example, when attempting to send broadcast messages, but the socket is not configured with ``SO_BROADCAST``.h](jy )}(h ``EACCES``h]hEACCES}(hjm'hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hji'ubh: Permission denied. This error can occur, for example, when attempting to send broadcast messages, but the socket is not configured with }(hji'hhhNhNubjy )}(h``SO_BROADCAST``h]h SO_BROADCAST}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hji'ubh.}(hji'hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhje'ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(hX=``EADDRNOTAVAIL``: Address not available. This error occurs in cases such as: - When attempting to use ``getsockname(2)`` to retrieve the peer's address, but the socket is not connected. - When trying to send data to or from a NAME, but address claiming for the NAME was not performed or detected by the stack. h](h)}(hM``EADDRNOTAVAIL``: Address not available. This error occurs in cases such as:h](jy )}(h``EADDRNOTAVAIL``h]h EADDRNOTAVAIL}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj'ubh<: Address not available. This error occurs in cases such as:}(hj'hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj'ubh)}(hhh](j)}(hkWhen attempting to use ``getsockname(2)`` to retrieve the peer's address, but the socket is not connected. h]h)}(hjWhen attempting to use ``getsockname(2)`` to retrieve the peer's address, but the socket is not connected.h](hWhen attempting to use }(hj'hhhNhNubjy )}(h``getsockname(2)``h]hgetsockname(2)}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj'ubhC to retrieve the peer’s address, but the socket is not connected.}(hj'hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj'ubah}(h]h ]h"]h$]h&]uh1jhj'ubj)}(hzWhen trying to send data to or from a NAME, but address claiming for the NAME was not performed or detected by the stack. h]h)}(hyWhen trying to send data to or from a NAME, but address claiming for the NAME was not performed or detected by the stack.h]hyWhen trying to send data to or from a NAME, but address claiming for the NAME was not performed or detected by the stack.}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj'ubah}(h]h ]h"]h$]h&]uh1jhj'ubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMhj'ubeh}(h]h ]h"]h$]h&]uh1jhj&hhhNhNubj)}(h``EBADFD``: File descriptor in bad state. This error can occur if: - Attempting to send data to an unbound socket. - The socket is bound but has no source name, and the source address is ``J1939_NO_ADDR``. - The ``can_ifindex`` is incorrect. h](h)}(hB``EBADFD``: File descriptor in bad state. This error can occur if:h](jy )}(h ``EBADFD``h]hEBADFD}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj(ubh8: File descriptor in bad state. This error can occur if:}(hj(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj(ubh)}(hhh](j)}(h.Attempting to send data to an unbound socket. h]h)}(h-Attempting to send data to an unbound socket.h]h-Attempting to send data to an unbound socket.}(hj5(hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj1(ubah}(h]h ]h"]h$]h&]uh1jhj.(ubj)}(hYThe socket is bound but has no source name, and the source address is ``J1939_NO_ADDR``. h]h)}(hXThe socket is bound but has no source name, and the source address is ``J1939_NO_ADDR``.h](hFThe socket is bound but has no source name, and the source address is }(hjM(hhhNhNubjy )}(h``J1939_NO_ADDR``h]h J1939_NO_ADDR}(hjU(hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjM(ubh.}(hjM(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjI(ubah}(h]h ]h"]h$]h&]uh1jhj.(ubj)}(h"The ``can_ifindex`` is incorrect. h]h)}(h!The ``can_ifindex`` is incorrect.h](hThe }(hjw(hhhNhNubjy )}(h``can_ifindex``h]h can_ifindex}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjw(ubh is incorrect.}(hjw(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjs(ubah}(h]h ]h"]h$]h&]uh1jhj.(ubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMhj(ubeh}(h]h ]h"]h$]h&]uh1jhj&hhhNhNubj)}(h``EFAULT``: Bad address. Occurs mostly when the stack can't copy from or to a sockptr, when there is insufficient data from user space, or when the buffer provided by user space is not large enough for the requested data. h]h)}(h``EFAULT``: Bad address. Occurs mostly when the stack can't copy from or to a sockptr, when there is insufficient data from user space, or when the buffer provided by user space is not large enough for the requested data.h](jy )}(h ``EFAULT``h]hEFAULT}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj(ubh: Bad address. Occurs mostly when the stack can’t copy from or to a sockptr, when there is insufficient data from user space, or when the buffer provided by user space is not large enough for the requested data.}(hj(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj(ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(hQ``EINTR``: A signal occurred before any data was transmitted; see ``signal(7)``. h]h)}(hP``EINTR``: A signal occurred before any data was transmitted; see ``signal(7)``.h](jy )}(h ``EINTR``h]hEINTR}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj(ubh9: A signal occurred before any data was transmitted; see }(hj(hhhNhNubjy )}(h ``signal(7)``h]h signal(7)}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj(ubh.}(hj(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj(ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h``EINVAL``: Invalid argument passed. For example: - ``msg->msg_namelen`` is less than ``J1939_MIN_NAMELEN``. - ``addr->can_family`` is not equal to ``AF_CAN``. - An incorrect PGN was provided. h](h)}(h1``EINVAL``: Invalid argument passed. For example:h](jy )}(h ``EINVAL``h]hEINVAL}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj )ubh': Invalid argument passed. For example:}(hj )hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj)ubh)}(hhh](j)}(h9``msg->msg_namelen`` is less than ``J1939_MIN_NAMELEN``. h]h)}(h8``msg->msg_namelen`` is less than ``J1939_MIN_NAMELEN``.h](jy )}(h``msg->msg_namelen``h]hmsg->msg_namelen}(hj2)hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj.)ubh is less than }(hj.)hhhNhNubjy )}(h``J1939_MIN_NAMELEN``h]hJ1939_MIN_NAMELEN}(hjD)hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj.)ubh.}(hj.)hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj*)ubah}(h]h ]h"]h$]h&]uh1jhj')ubj)}(h1``addr->can_family`` is not equal to ``AF_CAN``. h]h)}(h0``addr->can_family`` is not equal to ``AF_CAN``.h](jy )}(h``addr->can_family``h]haddr->can_family}(hjj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjf)ubh is not equal to }(hjf)hhhNhNubjy )}(h ``AF_CAN``h]hAF_CAN}(hj|)hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjf)ubh.}(hjf)hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM!hjb)ubah}(h]h ]h"]h$]h&]uh1jhj')ubj)}(hAn incorrect PGN was provided. h]h)}(hAn incorrect PGN was provided.h]hAn incorrect PGN was provided.}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM#hj)ubah}(h]h ]h"]h$]h&]uh1jhj')ubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMhj)ubeh}(h]h ]h"]h$]h&]uh1jhj&hhhNhNubj)}(h``ENODEV``: No such device. This happens when the CAN network device cannot be found for the provided ``can_ifindex`` or if ``can_ifindex`` is 0. h]h)}(h``ENODEV``: No such device. This happens when the CAN network device cannot be found for the provided ``can_ifindex`` or if ``can_ifindex`` is 0.h](jy )}(h ``ENODEV``h]hENODEV}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj)ubh\: No such device. This happens when the CAN network device cannot be found for the provided }(hj)hhhNhNubjy )}(h``can_ifindex``h]h can_ifindex}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj)ubh or if }(hj)hhhNhNubjy )}(h``can_ifindex``h]h can_ifindex}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj)ubh is 0.}(hj)hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM%hj)ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h\``ENOMEM``: Out of memory. Typically related to issues with memory allocation in the stack. h]h)}(h[``ENOMEM``: Out of memory. Typically related to issues with memory allocation in the stack.h](jy )}(h ``ENOMEM``h]hENOMEM}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj *ubhQ: Out of memory. Typically related to issues with memory allocation in the stack.}(hj *hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM(hj*ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h``ENOPROTOOPT``: Protocol not available. This can occur when using ``getsockopt(2)`` or ``setsockopt(2)`` if the requested socket option is not available. h]h)}(h``ENOPROTOOPT``: Protocol not available. This can occur when using ``getsockopt(2)`` or ``setsockopt(2)`` if the requested socket option is not available.h](jy )}(h``ENOPROTOOPT``h]h ENOPROTOOPT}(hj6*hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj2*ubh4: Protocol not available. This can occur when using }(hj2*hhhNhNubjy )}(h``getsockopt(2)``h]h getsockopt(2)}(hjH*hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj2*ubh or }(hj2*hhhNhNubjy )}(h``setsockopt(2)``h]h setsockopt(2)}(hjZ*hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj2*ubh1 if the requested socket option is not available.}(hj2*hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM+hj.*ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h``EDESTADDRREQ``: Destination address required. This error occurs: - In the case of ``connect(2)``, if the ``struct sockaddr *uaddr`` is ``NULL``. - In the case of ``send*(2)``, if there is an attempt to send an ETP message to a broadcast address. h](h)}(hB``EDESTADDRREQ``: Destination address required. This error occurs:h](jy )}(h``EDESTADDRREQ``h]h EDESTADDRREQ}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj|*ubh2: Destination address required. This error occurs:}(hj|*hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM/hjx*ubh)}(hhh](j)}(hNIn the case of ``connect(2)``, if the ``struct sockaddr *uaddr`` is ``NULL``. h]h)}(hMIn the case of ``connect(2)``, if the ``struct sockaddr *uaddr`` is ``NULL``.h](hIn the case of }(hj*hhhNhNubjy )}(h``connect(2)``h]h connect(2)}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj*ubh , if the }(hj*hhhNhNubjy )}(h``struct sockaddr *uaddr``h]hstruct sockaddr *uaddr}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj*ubh is }(hj*hhhNhNubjy )}(h``NULL``h]hNULL}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj*ubh.}(hj*hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM1hj*ubah}(h]h ]h"]h$]h&]uh1jhj*ubj)}(hcIn the case of ``send*(2)``, if there is an attempt to send an ETP message to a broadcast address. h]h)}(hbIn the case of ``send*(2)``, if there is an attempt to send an ETP message to a broadcast address.h](hIn the case of }(hj*hhhNhNubjy )}(h ``send*(2)``h]hsend*(2)}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj*ubhG, if there is an attempt to send an ETP message to a broadcast address.}(hj*hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM3hj*ubah}(h]h ]h"]h$]h&]uh1jhj*ubeh}(h]h ]h"]h$]h&]jNjuh1hhhhM1hjx*ubeh}(h]h ]h"]h$]h&]uh1jhj&hhhNhNubj)}(h``EDOM``: Argument out of domain. This error may happen if attempting to send a TP or ETP message to a PGN that is reserved for control PGNs for TP or ETP operations. h]h)}(h``EDOM``: Argument out of domain. This error may happen if attempting to send a TP or ETP message to a PGN that is reserved for control PGNs for TP or ETP operations.h](jy )}(h``EDOM``h]hEDOM}(hj'+hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj#+ubh: Argument out of domain. This error may happen if attempting to send a TP or ETP message to a PGN that is reserved for control PGNs for TP or ETP operations.}(hj#+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM6hj+ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h``EIO``: I/O error. This can occur if the amount of data provided to the socket for a TP or ETP session does not match the announced amount of data for the session. h]h)}(h``EIO``: I/O error. This can occur if the amount of data provided to the socket for a TP or ETP session does not match the announced amount of data for the session.h](jy )}(h``EIO``h]hEIO}(hjM+hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjI+ubh: I/O error. This can occur if the amount of data provided to the socket for a TP or ETP session does not match the announced amount of data for the session.}(hjI+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM:hjE+ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h``ENOENT``: No such file or directory. This can happen when the stack attempts to transfer CTS or EOMA but cannot find a matching receiving socket anymore. h]h)}(h``ENOENT``: No such file or directory. This can happen when the stack attempts to transfer CTS or EOMA but cannot find a matching receiving socket anymore.h](jy )}(h ``ENOENT``h]hENOENT}(hjs+hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjo+ubh: No such file or directory. This can happen when the stack attempts to transfer CTS or EOMA but cannot find a matching receiving socket anymore.}(hjo+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM>hjk+ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h?``ENOIOCTLCMD``: No ioctls are available for the socket layer. h]h)}(h>``ENOIOCTLCMD``: No ioctls are available for the socket layer.h](jy )}(h``ENOIOCTLCMD``h]h ENOIOCTLCMD}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj+ubh/: No ioctls are available for the socket layer.}(hj+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMBhj+ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h}``EPERM``: Operation not permitted. For example, this can occur if a requested action requires ``CAP_NET_ADMIN`` privileges. h]h)}(h|``EPERM``: Operation not permitted. For example, this can occur if a requested action requires ``CAP_NET_ADMIN`` privileges.h](jy )}(h ``EPERM``h]hEPERM}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj+ubhV: Operation not permitted. For example, this can occur if a requested action requires }(hj+hhhNhNubjy )}(h``CAP_NET_ADMIN``h]h CAP_NET_ADMIN}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj+ubh privileges.}(hj+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMDhj+ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(hq``ENETUNREACH``: Network unreachable. Most likely, this occurs when frames cannot be transmitted to the CAN bus. h]h)}(hp``ENETUNREACH``: Network unreachable. Most likely, this occurs when frames cannot be transmitted to the CAN bus.h](jy )}(h``ENETUNREACH``h]h ENETUNREACH}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj+ubha: Network unreachable. Most likely, this occurs when frames cannot be transmitted to the CAN bus.}(hj+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMGhj+ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h``ETIME``: Timer expired. This can happen if a timeout occurs while attempting to send a simple message, for example, when an echo message from the controller is not received. h]h)}(h``ETIME``: Timer expired. This can happen if a timeout occurs while attempting to send a simple message, for example, when an echo message from the controller is not received.h](jy )}(h ``ETIME``h]hETIME}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj,ubh: Timer expired. This can happen if a timeout occurs while attempting to send a simple message, for example, when an echo message from the controller is not received.}(hj,hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMJhj,ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(hX"``EPROTO``: Protocol error. - Used for various protocol-level errors in J1939, including: - Duplicate sequence number. - Unexpected EDPO or ECTS packet. - Invalid PGN or offset in EDPO/ECTS. - Number of EDPO packets exceeded CTS allowance. - Any other protocol-level error. h](h)}(h``EPROTO``: Protocol error.h](jy )}(h ``EPROTO``h]hEPROTO}(hjC,hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj?,ubh: Protocol error.}(hj?,hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMNhj;,ubh)}(hhh]j)}(hUsed for various protocol-level errors in J1939, including: - Duplicate sequence number. - Unexpected EDPO or ECTS packet. - Invalid PGN or offset in EDPO/ECTS. - Number of EDPO packets exceeded CTS allowance. - Any other protocol-level error. h](h)}(h;Used for various protocol-level errors in J1939, including:h]h;Used for various protocol-level errors in J1939, including:}(hjb,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMPhj^,ubh)}(hhh](j)}(hDuplicate sequence number. h]h)}(hDuplicate sequence number.h]hDuplicate sequence number.}(hjw,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMRhjs,ubah}(h]h ]h"]h$]h&]uh1jhjp,ubj)}(h Unexpected EDPO or ECTS packet. h]h)}(hUnexpected EDPO or ECTS packet.h]hUnexpected EDPO or ECTS packet.}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMThj,ubah}(h]h ]h"]h$]h&]uh1jhjp,ubj)}(h$Invalid PGN or offset in EDPO/ECTS. h]h)}(h#Invalid PGN or offset in EDPO/ECTS.h]h#Invalid PGN or offset in EDPO/ECTS.}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMVhj,ubah}(h]h ]h"]h$]h&]uh1jhjp,ubj)}(h/Number of EDPO packets exceeded CTS allowance. h]h)}(h.Number of EDPO packets exceeded CTS allowance.h]h.Number of EDPO packets exceeded CTS allowance.}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMXhj,ubah}(h]h ]h"]h$]h&]uh1jhjp,ubj)}(h Any other protocol-level error. h]h)}(hAny other protocol-level error.h]hAny other protocol-level error.}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMZhj,ubah}(h]h ]h"]h$]h&]uh1jhjp,ubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMRhj^,ubeh}(h]h ]h"]h$]h&]uh1jhj[,ubah}(h]h ]h"]h$]h&]jNjuh1hhhhMPhj;,ubeh}(h]h ]h"]h$]h&]uh1jhj&hhhNhNubj)}(h ``EMSGSIZE``: Message too long. h]h)}(h``EMSGSIZE``: Message too long.h](jy )}(h ``EMSGSIZE``h]hEMSGSIZE}(hj -hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj-ubh: Message too long.}(hj-hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM\hj-ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h"``ENOMSG``: No message available. h]h)}(h!``ENOMSG``: No message available.h](jy )}(h ``ENOMSG``h]hENOMSG}(hj1-hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj--ubh: No message available.}(hj--hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM^hj)-ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(hp``EALREADY``: The ECU is already engaged in one or more connection-managed sessions and cannot support another. h]h)}(ho``EALREADY``: The ECU is already engaged in one or more connection-managed sessions and cannot support another.h](jy )}(h ``EALREADY``h]hEALREADY}(hjW-hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjS-ubhc: The ECU is already engaged in one or more connection-managed sessions and cannot support another.}(hjS-hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM`hjO-ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(hC``EHOSTUNREACH``: A timeout occurred, and the session was aborted. h]h)}(hB``EHOSTUNREACH``: A timeout occurred, and the session was aborted.h](jy )}(h``EHOSTUNREACH``h]h EHOSTUNREACH}(hj}-hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hjy-ubh2: A timeout occurred, and the session was aborted.}(hjy-hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMchju-ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(hj``EBADMSG``: CTS (Clear to Send) messages were received during an active data transfer, causing an abort. h]h)}(hi``EBADMSG``: CTS (Clear to Send) messages were received during an active data transfer, causing an abort.h](jy )}(h ``EBADMSG``h]hEBADMSG}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj-ubh^: CTS (Clear to Send) messages were received during an active data transfer, causing an abort.}(hj-hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMehj-ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(hk``ENOTRECOVERABLE``: The maximum retransmission request limit was reached, and the session cannot recover. h]h)}(hj``ENOTRECOVERABLE``: The maximum retransmission request limit was reached, and the session cannot recover.h](jy )}(h``ENOTRECOVERABLE``h]hENOTRECOVERABLE}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj-ubhW: The maximum retransmission request limit was reached, and the session cannot recover.}(hj-hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhhj-ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(h?``ENOTCONN``: An unexpected data transfer packet was received. h]h)}(h>``ENOTCONN``: An unexpected data transfer packet was received.h](jy )}(h ``ENOTCONN``h]hENOTCONN}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj-ubh2: An unexpected data transfer packet was received.}(hj-hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMkhj-ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubj)}(hT``EILSEQ``: A bad sequence number was received, and the software could not recover. h]h)}(hS``EILSEQ``: A bad sequence number was received, and the software could not recover.h](jy )}(h ``EILSEQ``h]hEILSEQ}(hj.hhhNhNubah}(h]h ]h"]h$]h&]uh1jx hj.ubhI: A bad sequence number was received, and the software could not recover.}(hj.hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMmhj .ubah}(h]h ]h"]h$]h&]uh1jhj&hhhhhNubeh}(h]h ]h"]h$]h&]jNjuh1hhhhMhj&hhubeh}(h]error-codes-in-the-j1939-stackah ]h"]error codes in the j1939 stackah$]h&]uh1hhjN hhhhhMubeh}(h]how-to-use-j1939ah ]h"]how to use j1939ah$]h&]uh1hhhhhhhhKubeh}(h]j1939-documentationah ]h"]j1939 documentationah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksjfootnote_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_handlerjs.error_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}refids}j]]jRasnameids}(jN.jK.jkjhjcj`j,j]j+j(jK jH jjjn jk j j jC j@ jF.jC.j$j$jjjjj$j$jjj/j,jjj=j:jJjGj$j$j%j%j&j&jz&jw&j>.j;.u nametypes}(jN.jkjcj,j+jK jjn j jC jF.j$jjj$jj/jj=jJj$j%j&jz&j>.uh}(jK.hjhhj`hj]jnj(jnjH j3jjDjk jj jq j@ j jC.jN j$j_ jjjjj$jjjj,jjj2j:jjGj@j$jMj%j$j&j%jw&j%j;.j&u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages]hsystem_message)}(hhh]h)}(hhh]h6Hyperlink target "j1939-motivation" is not referenced.}hj.sbah}(h]h ]h"]h$]h&]uh1hhj.ubah}(h]h ]h"]h$]h&]levelKtypeINFOsourcehlineKuh1j.uba transformerN include_log] decorationNhhub.