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]hPortuguese (Brazilian)}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/pt_BR/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}(hjhhhNhNubah}(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&]uh1jhjhhhhhNubj)}(h!SAE J1939-81 : network managementh]h)}(hj/h]h!SAE J1939-81 : network management}(hj1hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj-ubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(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)}(hjHhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjDubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]bullet*uh1jhhhKhhhhubhtarget)}(h.. _j1939-motivation:h]h}(h]h ]h"]h$]h&]refidj1939-motivationuh1jdhKhhhhhhubeh}(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}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(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&]uh1hhhhKhjhhubj)}(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&]jbjcuh1jhhhK"hjhhubh)}(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.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK7hjhhubh)}(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.}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK;hjhhubeh}(h]( motivationjqeh ]h"]( motivationj1939-motivationeh$]h&]uh1hhhhhhhhKexpect_referenced_by_name}j@jfsexpect_referenced_by_id}jqjfsubh)}(hhh](h)}(hJ1939 conceptsh]hJ1939 concepts}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjGhhhhhKCubh)}(hhh](h)}(hData Sent to the J1939 Stackh]hData Sent to the J1939 Stack}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjXhhhhhKFubh)}(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.}(hjihhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKHhjXhhubh)}(h'**Handling of Different Buffer Sizes:**h]j)}(hjyh]h#Handling of Different Buffer Sizes:}(hj{hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjwubah}(h]h ]h"]h$]h&]uh1hhhhKNhjXhhubj)}(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&]uh1hhhhKPhjubj)}(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&]jb-uh1jhhhKRhjubeh}(h]h ]h"]h$]h&]uh1jhjhhhNhNubj)}(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)}(hj h]hBuffers up to 1785 bytes:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhKZhjubj)}(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.}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK\hj"ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(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&]uh1jhjubj)}(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.}(hjVhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK`hjRubah}(h]h ]h"]h$]h&]uh1jhjubj)}(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:}(hjrhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjnubhV Does not require a receiver on the other side and can be used in broadcast scenarios.}(hjnhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKbhjjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(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&]uh1hhhhKehjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]jbjuh1jhhhK\hjubeh}(h]h ]h"]h$]h&]uh1jhjhhhNhNubj)}(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&]uh1hhhhKhhjubj)}(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&]uh1hhhhKrhj6ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]jbjuh1jhhhKjhjubeh}(h]h ]h"]h$]h&]uh1jhjhhhNhNubeh}(h]h ]h"]h$]h&]jbjuh1jhhhKPhjXhhubh)}(h/**Non-Blocking Operation with `MSG_DONTWAIT`:**h]j)}(hjbh]h+Non-Blocking Operation with `MSG_DONTWAIT`:}(hjdhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj`ubah}(h]h ]h"]h$]h&]uh1hhhhKuhjXhhubh)}(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 }(hjwhhhNhNubhtitle_reference)}(h`MSG_DONTWAIT`h]h MSG_DONTWAIT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjwubhX 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.}(hjwhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKwhjXhhubj)}(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 }(hjhhhNhNubj)}(h`MSG_DONTWAIT`h]h MSG_DONTWAIT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhK, 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&]jbjuh1jhhhK}hjXhhubh)}(h**Behavior and Requirements:**h]j)}(hjh]hBehavior and Requirements:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1hhhhKhjXhhubj)}(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):}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj"ubh Do not require a receiver on the other side, making them easy to send without needing address claiming or coordination with a destination.}(hj"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(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:}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjHubh Requires a receiver on the other side to complete the transfer. The receiver must acknowledge the transfer for the session to proceed successfully.}(hjHhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjDubah}(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:}(hjrhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjnubh Allows sending data without a receiver, but only works for TP transfers. ETP cannot be broadcast and always needs a receiving client.}(hjnhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]jbjuh1jhhhKhjXhhubh)}(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&]uh1hhhhKhjXhhubeh}(h]data-sent-to-the-j1939-stackah ]h"]data sent to the j1939 stackah$]h&]uh1hhjGhhhhhKFubh)}(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}(hj hhhNhNubah}(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}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj(ubah}(h]h ]h"]h$]h&]morecolsKuh1jhj%ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(h 28 ... 26h]h 28 ... 26}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjIubah}(h]h ]h"]h$]h&]uh1jhjFubj)}(hhh]h)}(h25 ... 8h]h25 ... 8}(hjchhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj`ubah}(h]h ]h"]h$]h&]uh1jhjFubj)}(hhh]h)}(h7 ... 0h]h7 ... 0}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjwubah}(h]h ]h"]h$]h&]uh1jhjFubeh}(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}(hjOhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjLubah}(h]h ]h"]h$]h&]morecolsKuh1jhjIubah}(h]h ]h"]h$]h&]uh1jhjFubj)}(hhh]j)}(hhh]h)}(hBit positions within the CAN-IDh]hBit positions within the CAN-ID}(hjphhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjmubah}(h]h ]h"]h$]h&]morecolsKuh1jhjjubah}(h]h ]h"]h$]h&]uh1jhjFubj)}(hhh](j)}(hhh]h)}(h25h]h25}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h24h]h24}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(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&]uh1jhjFubeh}(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)}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj*ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hPS (PDU Specific)h]hPS (PDU Specific)}(hjDhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjAubah}(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.}(hjwhhhNhNubah}(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&]colwidthKuh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjubj)}(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}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(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)}(hjE hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjB ubah}(h]h ]h"]h$]h&]uh1jhj( ubeh}(h]h ]h"]h$]h&]uh1jhj% ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]colsKuh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhju ubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhju 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&]uh1jhj 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&]uh1jhj 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&]uh1jhj ubeh}(h]h ]h"]h$]h&]uh1jhju 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&]uh1jhju ubeh}(h]h ]h"]h$]h&]colsKuh1jhjr ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(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.}(hja 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.}(hjo hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]pgnah ]h"]pgnah$]h&]uh1hhjGhhhhhKubh)}(hhh](h)}(h Addressingh]h Addressing}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj 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&]uh1hhhhKhj 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&]uh1hhhhKhj 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&]uh1hhhhKhj 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&]uh1hhhhKhj hhubeh}(h] addressingah ]h"] addressingah$]h&]uh1hhjGhhhhhKubh)}(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 hhubj)}(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&]jbjcuh1jhhhKhj 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.}(hjD hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubeh}(h] filteringah ]h"] filteringah$]h&]uh1hhjGhhhhhKubeh}(h]j1939-conceptsah ]h"]j1939 conceptsah$]h&]uh1hhhhhhhhKCubh)}(hhh](h)}(hHow to Use J1939h]hHow to Use J1939}(hje hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjb hhhhhKubh)}(hhh](h)}(h API Callsh]h API Calls}(hjv hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjs 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, }(hj hhhNhNubhliteral)}(h ``#include ``h]h#include }(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh. From there, }(hj hhhNhNubj )}(h````h]h }(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh- will be included too. To open a socket, use:}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjs 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&]hhƌforcelanguageChighlight_args}uh1j hhhMhjs 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 hhhNhNubj )}(h``SOCK_DGRAM``h]h SOCK_DGRAM}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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 hhhNhNubj )}(h``SOCK_STREAM``h]h SOCK_STREAM}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh is not supported.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjs 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 hhhNhNubj )}(h ``bind(2)``h]hbind(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh and/or }(hj hhhNhNubj )}(h``connect(2)``h]h connect(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubhh system call to bind the socket to a CAN interface. After binding and/or connecting the socket, you can }(hj hhhNhNubj )}(h ``read(2)``h]hread(2)}(hj+ hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh and }(hj hhhNhNubj )}(h ``write(2)``h]hwrite(2)}(hj= hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh from/to the socket or use }(hj hhhNhNubj )}(h ``send(2)``h]hsend(2)}(hjO hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh, }(hj hhhNhNubj )}(h ``sendto(2)``h]h sendto(2)}(hja hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh, }hj sbj )}(h``sendmsg(2)``h]h sendmsg(2)}(hjs hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh and the }(hj hhhNhNubj )}(h ``recv*()``h]hrecv*()}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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 hjs 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 hhhNhNubj )}(h ``bind(2)``h]hbind(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh must have been successful. }(hj hhhNhNubj )}(h ``bind(2)``h]hbind(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh% assigns a local address to a socket.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjs 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 hhhNhNubj )}(h ``bind(2)``h]hbind(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh, }(hj hhhNhNubj )}(h``connect(2)``h]h connect(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh, }hj sbj )}(h ``sendto(2)``h]h sendto(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh and }(hj hhhNhNubj )}(h``recvfrom(2)``h]h recvfrom(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh. A }(hj hhhNhNubj )}(h ``write(2)``h]hwrite(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh2 with size 4 will result in a packet with 4 bytes.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjs 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:}(hj7 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjs 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; }}hjE sbah}(h]h ]h"]h$]h&]hhj j j j }uh1j hhhMhjs hhubh)}(hW``can_family`` & ``can_ifindex`` serve the same purpose as for other SocketCAN sockets.h](j )}(h``can_family``h]h can_family}(hjX hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjT ubh & }(hjT hhhNhNubj )}(h``can_ifindex``h]h can_ifindex}(hjj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjT ubh7 serve the same purpose as for other SocketCAN sockets.}(hjT hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM1hjs hhubh)}(h\``can_addr.j1939.pgn`` specifies the PGN (max 0x3ffff). Individual bits are specified above.h](j )}(h``can_addr.j1939.pgn``h]hcan_addr.j1939.pgn}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubhF specifies the PGN (max 0x3ffff). Individual bits are specified above.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM3hjs hhubh)}(h7``can_addr.j1939.name`` contains the 64-bit J1939 NAME.h](j )}(h``can_addr.j1939.name``h]hcan_addr.j1939.name}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh contains the 64-bit J1939 NAME.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM6hjs hhubh)}(h-``can_addr.j1939.addr`` contains the address.h](j )}(h``can_addr.j1939.addr``h]hcan_addr.j1939.addr}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh contains the address.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM8hjs 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 hhhNhNubj )}(h ``bind(2)``h]hbind(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubhg system call assigns the local address, i.e. the source address when sending packages. If a PGN during }(hj hhhNhNubj )}(h ``bind(2)``h]hbind(2)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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:hjs 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 }(hjhhhNhNubj )}(h``connect(2)``h]h connect(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhH assigns the remote address, i.e. the destination address. The PGN from }(hjhhhNhNubj )}(h``connect(2)``h]h connect(2)}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh 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 }(hjhhhNhNubj )}(h``connect(2)``h]h connect(2)}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh[ is used as a receive filter. It will match the source NAME or ADDR of the incoming packet.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMBhjs 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 }(hjLhhhNhNubj )}(h ``write(2)``h]hwrite(2)}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1j hjLubh and }(hjLhhhNhNubj )}(h ``send(2)``h]hsend(2)}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjLubh, will send a packet with local address from }(hjLhhhNhNubj )}(h ``bind(2)``h]hbind(2)}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjLubh and the remote address from }(hjLhhhNhNubj )}(h``connect(2)``h]h connect(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjLubh. Use }(hjLhhhNhNubj )}(h ``sendto(2)``h]h sendto(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjLubh& to overwrite the destination address.}(hjLhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMHhjs 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 }(hjhhhNhNubj )}(h``can_addr.j1939.name``h]hcan_addr.j1939.name}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhZ is set (!= 0) the NAME is looked up by the kernel and the corresponding ADDR is used. If }(hjhhhNhNubj )}(h``can_addr.j1939.name``h]hcan_addr.j1939.name}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh is not set (== 0), }(hjhhhNhNubj )}(h``can_addr.j1939.addr``h]hcan_addr.j1939.addr}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh is used.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMLhjs 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 }(hjhhhNhNubj )}(h``setsockopt(2)``h]h setsockopt(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh & }(hjhhhNhNubj )}(h``getsockopt(2)``h]h getsockopt(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMPhjs hhubh)}(hRX path related options:h]hRX path related options:}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMShjs hhubj)}(hhh](j)}(h0``SO_J1939_FILTER`` - configure array of filtersh]h)}(hj=h](j )}(h``SO_J1939_FILTER``h]hSO_J1939_FILTER}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj?ubh - configure array of filters}(hj?hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMUhj;ubah}(h]h ]h"]h$]h&]uh1jhj8hhhhhNubj)}(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](j )}(h``SO_J1939_PROMISC``h]hSO_J1939_PROMISC}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjdubh - disable filters set by }(hjdhhhNhNubj )}(h ``bind(2)``h]hbind(2)}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjdubh and }(hjdhhhNhNubj )}(h``connect(2)``h]h connect(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjdubeh}(h]h ]h"]h$]h&]uh1hhhhMVhj`ubah}(h]h ]h"]h$]h&]uh1jhj8hhhhhNubeh}(h]h ]h"]h$]h&]jbjuh1jhhhMUhjs 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 }(hjhhhNhNubj )}(h``SO_BROADCAST``h]h SO_BROADCAST}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMXhjs 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[hjs 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`hjs 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 hhhMbhjs hhubh)}(h]TX path related options: ``SO_J1939_SEND_PRIO`` - change default send priority for the socketh](hTX path related options: }(hjhhhNhNubj )}(h``SO_J1939_SEND_PRIO``h]hSO_J1939_SEND_PRIO}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh. - change default send priority for the socket}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjs hhubh)}(hhh](h)}(h4Message Flags during send() and Related System Callsh]h4Message Flags during send() and Related System Calls}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubh)}(he``send(2)``, ``sendto(2)`` and ``sendmsg(2)`` take a 'flags' argument. Currently supported flags are:h](j )}(h ``send(2)``h]hsend(2)}(hj0hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj,ubh, }(hj,hhhNhNubj )}(h ``sendto(2)``h]h sendto(2)}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj,ubh and }(hj,hhhNhNubj )}(h``sendmsg(2)``h]h sendmsg(2)}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1j hj,ubh< take a ‘flags’ argument. Currently supported flags are:}(hj,hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hhh]j)}(h/``MSG_DONTWAIT``, i.e. non-blocking operation. h]h)}(h.``MSG_DONTWAIT``, i.e. non-blocking operation.h](j )}(h``MSG_DONTWAIT``h]h MSG_DONTWAIT}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjsubh, i.e. non-blocking operation.}(hjshhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjoubah}(h]h ]h"]h$]h&]uh1jhjlhhhhhNubah}(h]h ]h"]h$]h&]jbjcuh1jhhhMhjhhubeh}(h]2message-flags-during-send-and-related-system-callsah ]h"]4message flags during send() and related system callsah$]h&]uh1hhjs 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``.h](hIn most cases }(hjhhhNhNubj )}(h``recvmsg(2)``h]h recvmsg(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh8 is needed if you want to extract more information than }(hjhhhNhNubj )}(h``recvfrom(2)``h]h recvfrom(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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 }(hjhhhNhNubj )}(h``recvmsg(2)``h]h recvmsg(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh# call. They can be extracted using }(hjhhhNhNubj )}(h ``cmsg(3)``h]hcmsg(3)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh macros, with }(hjhhhNhNubj )}(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&]uh1j hjubh, }(hjhhhNhNubj )}(h``SCM_J1939_DEST_NAME``h]hSCM_J1939_DEST_NAME}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh or }(hjhhhNhNubj )}(h``SCM_J1939_PRIO``h]hSCM_J1939_PRIO}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh. The returned data is a }(hjhhhNhNubj )}(h ``uint8_t``h]huint8_t}(hj:hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh for }(hjhhhNhNubj )}(h ``priority``h]hpriority}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h ``dst_addr``h]hdst_addr}(hj^hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh, and }(hjhhhNhNubj )}(h ``uint64_t``h]huint64_t}(hjphhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh for }(hjhhhNhNubj )}(h ``dst_name``h]hdst_name}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]uh1hhjs 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 }(hjhhhNhNubj )}(h``setsockopt(2)``h]h setsockopt(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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]j )}(hjh]hSO_J1939_FILTER}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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 }(hjhhhNhNubj )}(h``SO_J1939_FILTER``h]hSO_J1939_FILTER}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh2 option is essential when the default behavior of }(hjhhhNhNubj )}(h ``bind(2)``h]hbind(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h``connect(2)``h]h connect(2)}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh5 is insufficient for specific use cases. By default, }(hjhhhNhNubj )}(h ``bind(2)``h]hbind(2)}(hj:hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }hjsbj )}(h``connect(2)``h]h connect(2)}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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.}(hjdhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hMBy applying the ``SO_J1939_FILTER`` option, you can filter messages based on:h](hBy applying the }(hjrhhhNhNubj )}(h``SO_J1939_FILTER``h]hSO_J1939_FILTER}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjrubh* option, you can filter messages based on:}(hjrhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(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&]uh1jhjhhhhhNubj)}(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&]uh1jhjhhhhhNubj)}(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&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]jbjuh1jhhhMhjhhubh)}(h5This filtering mechanism is particularly useful when:h]h5This filtering mechanism is particularly useful when:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(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.}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(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&]uh1hhhhMhj6ubah}(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 }(hjRhhhNhNubj )}(h ``bind(2)``h]hbind(2)}(hjZhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjRubh and }(hjRhhhNhNubj )}(h``connect(2)``h]h connect(2)}(hjlhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjRubh 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.}(hjRhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjNubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]jbjuh1jhhhMhjhhubh)}(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 }(hjhhhNhNubj )}(h``optval == NULL``h]hoptval == NULL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh or }(hjhhhNhNubj )}(h``optlen == 0``h]h optlen == 0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh to }(hjhhhNhNubj )}(h``setsockopt(2)``h]h setsockopt(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh<. This will clear all currently set filters. If you want to }(hjhhhNhNubj)}(h **update**h]hupdate}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh= the set of filters, you must pass the updated filter set to }(hjhhhNhNubj )}(h``setsockopt(2)``h]h setsockopt(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh, as the new filter set will }(hjhhhNhNubj)}(h **replace**h]hreplace}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh the old one entirely. This behavior ensures that any previous filter configuration is discarded and only the new set is applied.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h Example of removing all filters:h]h Example of removing all filters:}(hj hhhNhNubah}(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:}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj(ubh9 The maximum amount of filters that can be applied using }(hj(hhhNhNubj )}(h``SO_J1939_FILTER``h]hSO_J1939_FILTER}(hj>hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj(ubh is defined by }(hj(hhhNhNubj )}(h``J1939_FILTER_MAX``h]hJ1939_FILTER_MAX}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj(ubhx, which is set to 512. This means you can configure up to 512 individual filters to match your specific filtering needs.}(hj(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(h3Practical use case: **Monitoring Address Claiming**h](hPractical use case: }(hjhhhhNhNubj)}(h**Monitoring Address Claiming**h]hMonitoring Address Claiming}(hjphhhNhNubah}(h]h ]h"]h$]h&]uh1jhjhubeh}(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.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubh)}(hExample:h]hExample:}(hjhhhNhNubah}(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 j&j }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: }(hjhhhNhNubj )}(h``J1939_PGN_ADDRESS_CLAIMED``h]hJ1939_PGN_ADDRESS_CLAIMED}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh, }(hjhhhNhNubj )}(h``J1939_PGN_REQUEST``h]hJ1939_PGN_REQUEST}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh, and }(hjhhhNhNubj )}(h``J1939_PGN_ADDRESS_COMMANDED``h]hJ1939_PGN_ADDRESS_COMMANDED}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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]j )}(hjh]hSO_J1939_PROMISC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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 }(hjhhhNhNubj )}(h``SO_J1939_PROMISC``h]hSO_J1939_PROMISC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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 }(hjhhhNhNubj )}(h ``bind()``h]hbind()}(hj/hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh or }(hjhhhNhNubj )}(h ``connect()``h]h connect()}(hjAhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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, }(hjYhhhNhNubj)}(h+**`SO_J1939_FILTER` has a higher priority**h]h'`SO_J1939_FILTER` has a higher priority}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1jhjYubh compared to }(hjYhhhNhNubj )}(h``SO_J1939_PROMISC``h]hSO_J1939_PROMISC}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1j hjYubh|. This means that even in promiscuous mode, you can reduce the number of packets received by applying specific filters with }(hjYhhhNhNubj)}(h`SO_J1939_FILTER`h]hSO_J1939_FILTER}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjYubh. The filters will limit which packets are passed to the socket, allowing for more refined traffic selection while promiscuous mode is active.}(hjYhhhNhNubeh}(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 }(hjhhhNhNubj )}(h``sizeof(int)``h]h sizeof(int)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh/, and the value is only differentiated between }(hjhhhNhNubj)}(h`0`h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh and non-zero. A value of }(hjhhhNhNubj)}(h`0`h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh@ 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 j&j }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 }(hj hhhNhNubj )}(h ``value``h]hvalue}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh to any non-zero value (e.g., }(hj hhhNhNubj)}(h`1`h]h1}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh\) enables promiscuous mode, allowing the socket to receive all J1939 traffic on the network.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM#hjhhubeh}(h]so-j1939-promiscah ]h"]so_j1939_promiscah$]h&]uh1hhjhhhhhMubh)}(hhh](h)}(h``SO_BROADCAST``h]j )}(hjKh]h SO_BROADCAST}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjIubah}(h]h ]h"]h$]h&]uh1hhjFhhhhhM(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 }(hj`hhhNhNubj )}(h``SO_BROADCAST``h]h SO_BROADCAST}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj`ubh 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.}(hj`hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM*hjFhhubh)}(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.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM/hjFhhubh)}(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 }(hjhhhNhNubj )}(h``sizeof(int)``h]h sizeof(int)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh/, and the value is only differentiated between }(hjhhhNhNubj)}(h`0`h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh and non-zero. A value of }(hjhhhNhNubj)}(h`0`h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhb disables the ability to send and receive broadcast messages, while any non-zero value enables it.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM6hjFhhubh)}(hExample:h]hExample:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM;hjFhhubj )}(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=hjFhhubh)}(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 }(hjhhhNhNubj )}(h ``value``h]hvalue}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh to any non-zero value (e.g., }(hjhhhNhNubj)}(h`1`h]h1}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh<) enables the socket to send and receive broadcast messages.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMBhjFhhubeh}(h] so-broadcastah ]h"] so_broadcastah$]h&]uh1hhjhhhhhM(ubh)}(hhh](h)}(h``SO_J1939_SEND_PRIO``h]j )}(hj.h]hSO_J1939_SEND_PRIO}(hj0hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj,ubah}(h]h ]h"]h$]h&]uh1hhj)hhhhhMFubh)}(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 }(hjChhhNhNubj )}(h``SO_J1939_SEND_PRIO``h]hSO_J1939_SEND_PRIO}(hjKhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjCubhX6 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.}(hjChhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMHhj)hhubh)}(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 }(hjchhhNhNubj)}(h**size**h]hsize}(hjkhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjcubh for this option is }(hjchhhNhNubj )}(h``sizeof(int)``h]h sizeof(int)}(hj}hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjcubh@, and the value is expected to be in the range of 0 to 7, where }(hjchhhNhNubj)}(h`0`h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjcubh is the highest priority, and }(hjchhhNhNubj)}(h`7`h]h7}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjcubh3 is the lowest. By default, the priority is set to }(hjchhhNhNubj)}(h`6`h]h6}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjcubh- if this option is not explicitly configured.}(hjchhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMNhj)hhubh)}(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 }(hjhhhNhNubj)}(h`0`h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh and }(hjhhhNhNubj)}(h`1`h]h1}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh( can only be set if the process has the }(hjhhhNhNubj)}(h`CAP_NET_ADMIN`h]h CAP_NET_ADMIN}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh` capability. These are reserved for high-priority traffic and require administrative privileges.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMShj)hhubh)}(hExample:h]hExample:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMWhj)hhubj )}(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));}hjsbah}(h]h ]h"]h$]h&]hhj j j&j }uh1j hhhMYhj)hhubh)}(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 }(hj,hhhNhNubj)}(h`3`h]h3}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj,ubhL, meaning the outgoing messages will be sent with a moderate priority level.}(hj,hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM^hj)hhubeh}(h]so-j1939-send-prioah ]h"]so_j1939_send_prioah$]h&]uh1hhjhhhhhMFubh)}(hhh](h)}(h``SO_J1939_ERRQUEUE``h]j )}(hjYh]hSO_J1939_ERRQUEUE}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjWubah}(h]h ]h"]h$]h&]uh1hhjThhhhhMbubh)}(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 }(hjnhhhNhNubj )}(h``SO_J1939_ERRQUEUE``h]hSO_J1939_ERRQUEUE}(hjvhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjnubhX 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 }(hjnhhhNhNubj )}(h``MSG_ERRQUEUE``h]h MSG_ERRQUEUE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjnubh messages.}(hjnhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMdhjThhubh)}(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 }(hjhhhNhNubj )}(h``SO_J1939_ERRQUEUE``h]hSO_J1939_ERRQUEUE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh to }(hjhhhNhNubj )}(h``0``h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh} will purge any currently present error messages in the error queue. When enabled, error messages can be retrieved using the }(hjhhhNhNubj )}(h``recvmsg(2)``h]h recvmsg(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh system call.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMjhjThhubh)}(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&]uh1hhhhMnhjThhubj)}(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``}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh4: Reception of RTS (Request to Send) control frames.}(hjhhhNhNubeh}(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``}(hjHhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjDubh8: Reception of data packets with Data Page Offset (DPO).}(hjDhhhNhNubeh}(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``}(hjnhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjjubh: Reception abort errors.}(hjjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMvhjfubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]jbjuh1jhhhMqhjThhubh)}(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 (}(hjhhhNhNubj )}(h ``tskey``h]htskey}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh&). The session ID is assigned via the }(hjhhhNhNubj )}(h``SOF_TIMESTAMPING_OPT_ID``h]hSOF_TIMESTAMPING_OPT_ID}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh$ flag, which is set by enabling the }(hjhhhNhNubj )}(h``SO_TIMESTAMPING``h]hSO_TIMESTAMPING}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh option.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMxhjThhubh)}(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 }(hjhhhNhNubj )}(h``SO_J1939_ERRQUEUE``h]hSO_J1939_ERRQUEUE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhd is activated, the user is required to pull messages from the error queue, meaning that using plain }(hjhhhNhNubj )}(h ``recv(2)``h]hrecv(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh. is not sufficient anymore. The user must use }(hjhhhNhNubj )}(h``recvmsg(2)``h]h recvmsg(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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}hjThhubh)}(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}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh that }(hjhhhNhNubj )}(h``SO_J1939_ERRQUEUE``h]hSO_J1939_ERRQUEUE}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh be used in combination with }(hjhhhNhNubj )}(h``SO_TIMESTAMPING``h]hSO_TIMESTAMPING}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]uh1hhhhMhjThhubh)}(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 }(hj^hhhNhNubj)}(h**size**h]hsize}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj^ubh for this option is }(hj^hhhNhNubj )}(h``sizeof(int)``h]h sizeof(int)}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj^ubh/, and the value is only differentiated between }(hj^hhhNhNubj )}(h``0``h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj^ubh and non-zero. A value of }(hj^hhhNhNubj )}(h``0``h]h0}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj^ubhl disables error queue reception and purges any existing error messages, while any non-zero value enables it.}(hj^hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjThhubh)}(hExample:h]hExample:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjThhubj )}(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 j&j }uh1j hhhMhjThhubh)}(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 }(hjhhhNhNubj )}(h``recvmsg(2)``h]h recvmsg(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh. By combining }(hjhhhNhNubj )}(h``SO_J1939_ERRQUEUE``h]hSO_J1939_ERRQUEUE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh with }(hjhhhNhNubj )}(h``SO_TIMESTAMPING``h]hSO_TIMESTAMPING}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh (with }(hjhhhNhNubj )}(h``SOF_TIMESTAMPING_OPT_ID``h]hSOF_TIMESTAMPING_OPT_ID}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh and }(hjhhhNhNubj )}(h``SOF_TIMESTAMPING_OPT_CMSG``h]hSOF_TIMESTAMPING_OPT_CMSG}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhz enabled), the user can track message transfers, retrieve precise timestamps, and correlate errors with specific sessions.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjThhubh)}(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 }(hj9hhhNhNubj)}(h`SO_TIMESTAMPING`h]hSO_TIMESTAMPING}(hjAhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj9ubh section.}(hj9hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjThhubeh}(h]so-j1939-errqueueah ]h"]so_j1939_errqueueah$]h&]uh1hhjhhhhhMbubh)}(hhh](h)}(h``SO_TIMESTAMPING``h]j )}(hjfh]hSO_TIMESTAMPING}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjdubah}(h]h ]h"]h$]h&]uh1hhjahhhhhMubh)}(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 }(hj{hhhNhNubj )}(h``SO_TIMESTAMPING``h]hSO_TIMESTAMPING}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj{ubh 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 }(hj{hhhNhNubj )}(h``SO_J1939_ERRQUEUE``h]hSO_J1939_ERRQUEUE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj{ubhm to provide detailed diagnostic information, session tracking, and precise timing data for message transfers.}(hj{hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjahhubh)}(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&]uh1hhhhMhjahhubh)}(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 }(hjhhhNhNubj)}(h`struct sock_extended_err`h]hstruct sock_extended_err}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh&, accessible via the control message (}(hjhhhNhNubj )}(h``cmsg``h]hcmsg}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh) retrieved using the }(hjhhhNhNubj )}(h``recvmsg(2)``h]h recvmsg(2)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh system call.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjahhubh)}(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&]uh1hhhhMhjahhubhenumerated_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](j )}(h0``serr->ee_origin == SO_EE_ORIGIN_TIMESTAMPING``h]h,serr->ee_origin == SO_EE_ORIGIN_TIMESTAMPING}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj(ubh:}(hj(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj$ubh)}(hZIn this case, the `serr->ee_info` field will contain one of the following timestamp types:h](hIn this case, the }(hjDhhhNhNubj)}(h`serr->ee_info`h]h serr->ee_info}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjDubh9 field will contain one of the following timestamp types:}(hjDhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj$ubj)}(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](j )}(h``SCM_TSTAMP_SCHED``h]hSCM_TSTAMP_SCHED}(hjohhhNhNubah}(h]h ]h"]h$]h&]uh1j hjkubh: 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.}(hjkhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjgubj)}(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.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(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&]uh1jhjubj)}(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&]uh1jhjubj)}(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 }(hjhhhNhNubj )}(h``J1939_EE_INFO_RX_DPO``h]hJ1939_EE_INFO_RX_DPO}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]uh1jhjubeh}(h]h ]h"]h$]h&]jbjuh1jhhhMhjgubeh}(h]h ]h"]h$]h&]uh1jhjdubj)}(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](j )}(h``SCM_TSTAMP_ACK``h]hSCM_TSTAMP_ACK}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubhH: This timestamp indicates the acknowledgment of the message or session.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubj)}(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.}(hj/hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj+ubah}(h]h ]h"]h$]h&]uh1jhj(ubj)}(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.}(hjGhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjCubah}(h]h ]h"]h$]h&]uh1jhj(ubeh}(h]h ]h"]h$]h&]jbjuh1jhhhMhjubeh}(h]h ]h"]h$]h&]uh1jhjdubeh}(h]h ]h"]h$]h&]jbjuh1jhhhMhj$ubeh}(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](j )}(h)``serr->ee_origin == SO_EE_ORIGIN_LOCAL``h]h%serr->ee_origin == SO_EE_ORIGIN_LOCAL}(hj{hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjwubh:}(hjwhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjsubh)}(hmIn this case, the `serr->ee_info` field will contain one of the following J1939 stack-specific message types:h](hIn this case, the }(hjhhhNhNubj)}(h`serr->ee_info`h]h serr->ee_info}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhL field will contain one of the following J1939 stack-specific message types:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjsubj)}(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](j )}(h``J1939_EE_INFO_TX_ABORT``h]hJ1939_EE_INFO_TX_ABORT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]uh1hhhhMhjubj)}(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}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj)ubh: 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.}(hj)hhhNhNubeh}(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 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 }(hjOhhhNhNubj )}(h``serr->ee_data``h]h serr->ee_data}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjOubh (}(hjOhhhNhNubj )}(h``session->err``h]h session->err}(hjihhhNhNubah}(h]h ]h"]h$]h&]uh1j hjOubhW on kernel side), providing additional details about the specific reason for the abort.}(hjOhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjKubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]jbjuh1jhhhMhjubeh}(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](j )}(h``J1939_EE_INFO_RX_RTS``h]hJ1939_EE_INFO_RX_RTS}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]uh1hhhhMhjubj)}(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 }(hjhhhNhNubj )}(h``J1939_NLA_TOTAL_SIZE``h]hJ1939_NLA_TOTAL_SIZE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh, }(hjhhhNhNubj )}(h``J1939_NLA_PGN``h]h J1939_NLA_PGN}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh, }(hjhhhNhNubj )}(h``J1939_NLA_SRC_NAME``h]hJ1939_NLA_SRC_NAME}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh, and }(hjhhhNhNubj )}(h``J1939_NLA_DEST_NAME``h]hJ1939_NLA_DEST_NAME}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubh are provided along with the }(hjhhhNhNubj )}(h``J1939_EE_INFO_RX_RTS``h]hJ1939_EE_INFO_RX_RTS}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]jbjuh1jhhhMhjubeh}(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](j )}(h``J1939_EE_INFO_RX_DPO``h]hJ1939_EE_INFO_RX_DPO}(hjThhhNhNubah}(h]h ]h"]h$]h&]uh1j hjPubh: 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).}(hjPhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjLubj)}(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.}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hjoubah}(h]h ]h"]h$]h&]uh1jhjlubj)}(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 }(hjhhhNhNubj )}(h``SCM_TSTAMP_SCHED``h]hSCM_TSTAMP_SCHED}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j hjubhe event on the sender side, which indicates when the next set of frames is scheduled for transmission.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjubah}(h]h ]h"]h$]h&]uh1jhjlubj)}(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 }(hjhhhNhNubj )}(h``J1939_NLA_BYTES_ACKED``h]hJ1939_NLA_BYTES_ACKED}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]uh1jhjlubeh}(h]h ]h"]h$]h&]jbjuh1jhhhM hjLubeh}(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](j )}(h``J1939_EE_INFO_RX_ABORT``h]hJ1939_EE_INFO_RX_ABORT}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]uh1hhhhMhjubj)}(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.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1jhj ubj)}(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&]uh1jhj ubj)}(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> hhhNhNubj )}(h``serr->ee_data``h]h serr->ee_data}(hjF hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj> ubh (}(hj> hhhNhNubj )}(h``session->err``h]h session->err}(hjX hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]uh1jhj ubj)}(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.}(hjz hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM$hjv ubah}(h]h ]h"]h$]h&]uh1jhj ubeh}(h]h ]h"]h$]h&]jbjuh1jhhhMhjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]jbjuh1jhhhMhjsubeh}(h]h ]h"]h$]h&]uh1jhj!hhhNhNubeh}(h]h ]h"]h$]h&]enumtypearabicprefixhsuffix.uh1jhjahhhhhMubh)}(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 hhhNhNubj )}(h``SOF_TIMESTAMPING_OPT_ID``h]hSOF_TIMESTAMPING_OPT_ID}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh is enabled, }(hj hhhNhNubj )}(h``serr->ee_data``h]h serr->ee_data}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh3 will be set to the session’s unique identifier (}(hj hhhNhNubj )}(h``session->tskey``h]hsession->tskey}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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'hjahhubh)}(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 hhhNhNubj )}(h``serr->ee_errno``h]hserr->ee_errno}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh will be set to }(hj hhhNhNubj )}(h ``ENOMSG``h]hENOMSG}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh, except for the }(hj hhhNhNubj )}(h``J1939_EE_INFO_TX_ABORT``h]hJ1939_EE_INFO_TX_ABORT}(hj!!hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh and }(hj hhhNhNubj )}(h``J1939_EE_INFO_RX_ABORT``h]hJ1939_EE_INFO_RX_ABORT}(hj3!hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh cases, where the kernel sets }(hj hhhNhNubj )}(h``serr->ee_data``h]h serr->ee_data}(hjE!hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh to the error stored in }(hj hhhNhNubj )}(h``session->err``h]h session->err}(hjW!hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh\. All protocol-specific errors are converted to standard kernel error values and stored in }(hj hhhNhNubj )}(h``session->err``h]h session->err}(hji!hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh9. These error values are unified across system calls and }(hj hhhNhNubj )}(h``serr->ee_errno``h]hserr->ee_errno}(hj{!hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj ubh7. Some of the known error values are described in the }(hj hhhNhNubj)}(h `Error Codes in the J1939 Stack`h]hError Codes in the J1939 Stack}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj ubh section.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM,hjahhubh)}(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!hhhNhNubj)}(h`J1939_EE_INFO_RX_RTS`h]hJ1939_EE_INFO_RX_RTS}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj!ubhe message is provided, it will include the following statistics for multi-frame messages (TP and ETP):}(hj!hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM4hjahhubj)}(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]j)}(hhh](j)}(hC``J1939_NLA_TOTAL_SIZE``: Total size of the message in the session.h]h)}(hj!h](j )}(h``J1939_NLA_TOTAL_SIZE``h]hJ1939_NLA_TOTAL_SIZE}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h``J1939_NLA_PGN``h]h J1939_NLA_PGN}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h``J1939_NLA_SRC_NAME``h]hJ1939_NLA_SRC_NAME}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h``J1939_NLA_DEST_NAME``h]hJ1939_NLA_DEST_NAME}(hjB"hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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)}(hjb"h](j )}(h``J1939_NLA_SRC_ADDR``h]hJ1939_NLA_SRC_ADDR}(hjg"hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjd"ubh*: 8-bit source address of the sending ECU.}(hjd"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM;hj`"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](j )}(h``J1939_NLA_DEST_ADDR``h]hJ1939_NLA_DEST_ADDR}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj"ubh1: 8-bit destination address of the receiving ECU.}(hj"hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM<hj"ubah}(h]h ]h"]h$]h&]uh1jhj!ubeh}(h]h ]h"]h$]h&]jbjuh1jhhhM7hj!ubah}(h]h ]h"]h$]h&]uh1jhhhM7hjahhubj)}(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"ubj)}(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](j )}(h``J1939_NLA_BYTES_ACKED``h]hJ1939_NLA_BYTES_ACKED}(hj"hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]jbjuh1jhhhMAhj"ubeh}(h]h ]h"]h$]h&]uh1jhj"hhhNhNubah}(h]h ]h"]h$]h&]jbjuh1jhhhM>hjahhubh)}(h.The key flags for ``SO_TIMESTAMPING`` include:h](hThe key flags for }(hj#hhhNhNubj )}(h``SO_TIMESTAMPING``h]hSO_TIMESTAMPING}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj#ubh include:}(hj#hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMDhjahhubj)}(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](j )}(h``SOF_TIMESTAMPING_OPT_ID``h]hSOF_TIMESTAMPING_OPT_ID}(hj2#hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj.#ubh2: Enables the use of a unique session identifier (}(hj.#hhhNhNubj )}(h ``tskey``h]htskey}(hjD#hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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.#hhhNhNubj )}(h``serr->ee_data``h]h serr->ee_data}(hjV#hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj.#ubh will be set to }(hj.#hhhNhNubj )}(h``session->tskey``h]hsession->tskey}(hjh#hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h``SOF_TIMESTAMPING_OPT_CMSG``h]hSOF_TIMESTAMPING_OPT_CMSG}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj#ubh8: Sends timestamp information through control messages (}(hj#hhhNhNubj )}(h``struct scm_timestamping``h]hstruct scm_timestamping}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj#ubhF), allowing the application to retrieve timestamps alongside the data.}(hj#hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMKhj#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](j )}(h``SOF_TIMESTAMPING_TX_SCHED``h]hSOF_TIMESTAMPING_TX_SCHED}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj#ubhK: Provides the timestamp for when a message is scheduled for transmission (}(hj#hhhNhNubj )}(h``SCM_TSTAMP_SCHED``h]hSCM_TSTAMP_SCHED}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h``SOF_TIMESTAMPING_TX_ACK``h]hSOF_TIMESTAMPING_TX_ACK}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj#ubhP: Provides the timestamp for when a message transmission is fully acknowledged (}(hj#hhhNhNubj )}(h``SCM_TSTAMP_ACK``h]hSCM_TSTAMP_ACK}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h ``SOF_TIMESTAMPING_RX_SOFTWARE``h]hSOF_TIMESTAMPING_RX_SOFTWARE}(hj6$hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj2$ubh:: Provides timestamps for reception-related events (e.g., }(hj2$hhhNhNubj )}(h``J1939_EE_INFO_RX_RTS``h]hJ1939_EE_INFO_RX_RTS}(hjH$hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj2$ubh, }(hj2$hhhNhNubj )}(h``J1939_EE_INFO_RX_DPO``h]hJ1939_EE_INFO_RX_DPO}(hjZ$hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj2$ubh, }(hj2$hhhNhNubj )}(h``J1939_EE_INFO_RX_ABORT``h]hJ1939_EE_INFO_RX_ABORT}(hjl$hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj2$ubh).}(hj2$hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMUhj.$ubah}(h]h ]h"]h$]h&]uh1jhj'#hhhhhNubeh}(h]h ]h"]h$]h&]jbjuh1jhhhMFhjahhubh)}(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&]uh1hhhhMYhjahhubh)}(hExample:h]hExample:}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM^hjahhubj )}(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 j&j }uh1j hhhM`hjahhubeh}(h]so-timestampingah ]h"]so_timestampingah$]h&]uh1hhjhhhhhMubeh}(h] setsockopt-2ah ]h"] setsockopt(2)ah$]h&]uh1hhjs hhhhhMubeh}(h] api-callsah ]h"] api callsah$]h&]uh1hhjb 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$hhhNhNubj )}(h``j1939.name``h]h j1939.name}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj$ubh member and provide it to }(hj$hhhNhNubj )}(h ``bind(2)``h]hbind(2)}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj$ubhm. If the name had claimed an address earlier, all further messages being sent will use that address. And the }(hj$hhhNhNubj )}(h``j1939.addr``h]h j1939.addr}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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(%hhhNhNubj )}(h``j1939.addr``h]h j1939.addr}(hj0%hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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:}(hjH%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));}hjV%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.}(hje%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 }(hjs%hhhNhNubj )}(h ``bind(2)``h]hbind(2)}(hj{%hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjs%ubh again, but with only }(hjs%hhhNhNubj )}(h``j1939.addr``h]h j1939.addr}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjs%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.}(hjs%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](j )}(h ``can-utils``h]h can-utils}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj%ubh also include the }(hj%hhhNhNubj )}(h ``j1939acd``h]hj1939acd}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]uh1hhjb 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(&hhhNhNubj )}(h``connect(2)``h]h connect(2)}(hj0&hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj(&ubh+ was called, at this point we can use only }(hj(&hhhNhNubj )}(h ``sendto(2)``h]h sendto(2)}(hjB&hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj(&ubh or }(hj(&hhhNhNubj )}(h``sendmsg(2)``h]h sendmsg(2)}(hjT&hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj(&ubh.}(hj(&hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj%hhubh)}(hSend:h]hSend:}(hjl&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));}hjz&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&]uh1hhjb 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&hhubj)}(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](j )}(h ``EAGAIN``h]hEAGAIN}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h ``ENETDOWN``h]hENETDOWN}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h ``ENOBUFS``h]hENOBUFS}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h ``EOVERFLOW``h]h EOVERFLOW}(hj5'hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj1'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.}(hj1'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](j )}(h ``EBUSY``h]hEBUSY}(hj['hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjW'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.}(hjW'hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjS'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](j )}(h ``EACCES``h]hEACCES}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj}'ubh: Permission denied. This error can occur, for example, when attempting to send broadcast messages, but the socket is not configured with }(hj}'hhhNhNubj )}(h``SO_BROADCAST``h]h SO_BROADCAST}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj}'ubh.}(hj}'hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjy'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](j )}(h``EADDRNOTAVAIL``h]h EADDRNOTAVAIL}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj'ubh<: Address not available. This error occurs in cases such as:}(hj'hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj'ubj)}(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'hhhNhNubj )}(h``getsockname(2)``h]hgetsockname(2)}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]jbjuh1jhhhMhj'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](j )}(h ``EBADFD``h]hEBADFD}(hj*(hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj&(ubh8: File descriptor in bad state. This error can occur if:}(hj&(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj"(ubj)}(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.}(hjI(hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjE(ubah}(h]h ]h"]h$]h&]uh1jhjB(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 }(hja(hhhNhNubj )}(h``J1939_NO_ADDR``h]h J1939_NO_ADDR}(hji(hhhNhNubah}(h]h ]h"]h$]h&]uh1j hja(ubh.}(hja(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj](ubah}(h]h ]h"]h$]h&]uh1jhjB(ubj)}(h"The ``can_ifindex`` is incorrect. h]h)}(h!The ``can_ifindex`` is incorrect.h](hThe }(hj(hhhNhNubj )}(h``can_ifindex``h]h can_ifindex}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj(ubh is incorrect.}(hj(hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj(ubah}(h]h ]h"]h$]h&]uh1jhjB(ubeh}(h]h ]h"]h$]h&]jbjuh1jhhhMhj"(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](j )}(h ``EFAULT``h]hEFAULT}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h ``EINTR``h]hEINTR}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj(ubh9: A signal occurred before any data was transmitted; see }(hj(hhhNhNubj )}(h ``signal(7)``h]h signal(7)}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h ``EINVAL``h]hEINVAL}(hj#)hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj)ubh': Invalid argument passed. For example:}(hj)hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhj)ubj)}(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](j )}(h``msg->msg_namelen``h]hmsg->msg_namelen}(hjF)hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjB)ubh is less than }(hjB)hhhNhNubj )}(h``J1939_MIN_NAMELEN``h]hJ1939_MIN_NAMELEN}(hjX)hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjB)ubh.}(hjB)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](j )}(h``addr->can_family``h]haddr->can_family}(hj~)hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjz)ubh is not equal to }(hjz)hhhNhNubj )}(h ``AF_CAN``h]hAF_CAN}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjz)ubh.}(hjz)hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM!hjv)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&]jbjuh1jhhhMhj)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](j )}(h ``ENODEV``h]hENODEV}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj)ubh\: No such device. This happens when the CAN network device cannot be found for the provided }(hj)hhhNhNubj )}(h``can_ifindex``h]h can_ifindex}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj)ubh or if }(hj)hhhNhNubj )}(h``can_ifindex``h]h can_ifindex}(hj)hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h ``ENOMEM``h]hENOMEM}(hj$*hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h``ENOPROTOOPT``h]h ENOPROTOOPT}(hjJ*hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjF*ubh4: Protocol not available. This can occur when using }(hjF*hhhNhNubj )}(h``getsockopt(2)``h]h getsockopt(2)}(hj\*hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjF*ubh or }(hjF*hhhNhNubj )}(h``setsockopt(2)``h]h setsockopt(2)}(hjn*hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjF*ubh1 if the requested socket option is not available.}(hjF*hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM+hjB*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](j )}(h``EDESTADDRREQ``h]h EDESTADDRREQ}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj*ubh2: Destination address required. This error occurs:}(hj*hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM/hj*ubj)}(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*hhhNhNubj )}(h``connect(2)``h]h connect(2)}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj*ubh , if the }(hj*hhhNhNubj )}(h``struct sockaddr *uaddr``h]hstruct sockaddr *uaddr}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj*ubh is }(hj*hhhNhNubj )}(h``NULL``h]hNULL}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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+hhhNhNubj )}(h ``send*(2)``h]hsend*(2)}(hj +hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]jbjuh1jhhhM1hj*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](j )}(h``EDOM``h]hEDOM}(hj;+hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj7+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.}(hj7+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM6hj3+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](j )}(h``EIO``h]hEIO}(hja+hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj]+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.}(hj]+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM:hjY+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](j )}(h ``ENOENT``h]hENOENT}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj+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.}(hj+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM>hj+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](j )}(h``ENOIOCTLCMD``h]h ENOIOCTLCMD}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h ``EPERM``h]hEPERM}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj+ubhV: Operation not permitted. For example, this can occur if a requested action requires }(hj+hhhNhNubj )}(h``CAP_NET_ADMIN``h]h CAP_NET_ADMIN}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h``ENETUNREACH``h]h ENETUNREACH}(hj ,hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h ``ETIME``h]hETIME}(hj1,hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h ``EPROTO``h]hEPROTO}(hjW,hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjS,ubh: Protocol error.}(hjS,hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMNhjO,ubj)}(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:}(hjv,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMPhjr,ubj)}(hhh](j)}(hDuplicate sequence number. h]h)}(hDuplicate sequence number.h]hDuplicate sequence number.}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMRhj,ubah}(h]h ]h"]h$]h&]uh1jhj,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&]uh1jhj,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&]uh1jhj,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&]uh1jhj,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&]uh1jhj,ubeh}(h]h ]h"]h$]h&]jbjuh1jhhhMRhjr,ubeh}(h]h ]h"]h$]h&]uh1jhjo,ubah}(h]h ]h"]h$]h&]jbjuh1jhhhMPhjO,ubeh}(h]h ]h"]h$]h&]uh1jhj&hhhNhNubj)}(h ``EMSGSIZE``: Message too long. h]h)}(h``EMSGSIZE``: Message too long.h](j )}(h ``EMSGSIZE``h]hEMSGSIZE}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h ``ENOMSG``h]hENOMSG}(hjE-hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjA-ubh: No message available.}(hjA-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](j )}(h ``EALREADY``,h]hEALREADY}(hjk-hhhNhNubah}(h]h ]h"]h$]h&]uh1j hjg-ubhc: The ECU is already engaged in one or more connection-managed sessions and cannot support another.}(hjg-hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM`hjc-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](j )}(h``EHOSTUNREACH``h]h EHOSTUNREACH}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1j hj-ubh2: A timeout occurred, and the session was aborted.}(hj-hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMchj-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](j )}(h ``EBADMSG``h]hEBADMSG}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h``ENOTRECOVERABLE``h]hENOTRECOVERABLE}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h ``ENOTCONN``h]hENOTCONN}(hj.hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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](j )}(h ``EILSEQ``h]hEILSEQ}(hj).hhhNhNubah}(h]h ]h"]h$]h&]uh1j 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&]jbjuh1jhhhMhj&hhubeh}(h]error-codes-in-the-j1939-stackah ]h"]error codes in the j1939 stackah$]h&]uh1hhjb 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_handlerj.error_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourcehnj _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}jq]jfasnameids}(jb.j_.jj|jwjtj@jqj?j<j_ j\ jjj j j j jW jT jZ.jW.j$j$jjjjj$j$jjjCj@j&j#jQjNj^j[j$j$j%j%j&j&j&j&jR.jO.u nametypes}(jb.jjwj@j?j_ jj j jW jZ.j$jjj$jjCj&jQj^j$j%j&j&jR.uh}(j_.hj|hjthjqjj<jj\ jGjjXj jj j jT j jW.jb j$js jjjjj$jjjj@jj#jFjNj)j[jTj$jaj%j$j&j%j&j%jO.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&]levelKtypeINFOsourcehnjlineKuh1j.uba transformerN include_log] decorationNhhub.