-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update LINKTYPE_CAN_SOCKETCAN #40
Open
hartkopp
wants to merge
1
commit into
the-tcpdump-group:master
Choose a base branch
from
hartkopp:SocketCAN-DLT-update-2025-rebased
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ <h2 class="title"> | |
</h2> | ||
|
||
<p> | ||
This format supports CAN CC (classic CAN), CAN FD, and CAN XL frames. | ||
This format supports CAN CC (Classical CAN), CAN FD, and CAN XL frames. | ||
The same header is used for CAN CC and CAN FD frames; a different header | ||
is used for CAN XL frames. | ||
</p> | ||
|
@@ -25,13 +25,13 @@ <h4>Packet structure</h4> | |
| Payload length | | ||
| (1 Octet) | | ||
+---------------------------+ | ||
| FD flags | | ||
| FD flags (CAN FD) | | ||
| (1 Octet) | | ||
+---------------------------+ | ||
| Reserved/Padding | | ||
| (1 Octet) | | ||
+---------------------------+ | ||
| Reserved/Padding | | ||
| Len 8 DLC (CAN CC) | | ||
| (1 Octet) | | ||
+---------------------------+ | ||
| Payload | | ||
|
@@ -53,8 +53,8 @@ <h4>Description</h4> | |
The remaining bits are: | ||
</p> | ||
<ul> | ||
<li><code>0x20000000</code> - set if the frame is an error message rather than a data frame.</li> | ||
<li><code>0x40000000</code> - set if the frame is a remote transmission request frame.</li> | ||
<li><code>0x20000000</code> - set if the frame is an error message rather than a data frame (CAN CC only).</li> | ||
<li><code>0x40000000</code> - set if the frame is a remote transmission request frame (CAN CC only).</li> | ||
<li><code>0x80000000</code> - set if the frame is an extended 29-bit frame rather than a standard 11-bit frame.</li> | ||
</ul> | ||
|
||
|
@@ -65,63 +65,48 @@ <h4>Description</h4> | |
</p> | ||
|
||
<p> | ||
The FD flags field contains CAN FD specific flags; for CAN CC frames, | ||
this field is 0. The bits are: | ||
</p> | ||
The CAN frame types CAN CC and CAN FD can be distinguished by the frame length: | ||
<ul> | ||
<li><code>CANFD_BRS</code> (<code>0x01</code>) - bit rate switch (second bitrate for payload data).</li> | ||
<li><code>CANFD_ESI</code> (<code>0x02</code>) - error state indicator of the transmitting node.</li> | ||
<li><code>CANFD_FDF</code> (<code>0x04</code>) - if set, the frame is a CAN FD frame; if not set, | ||
the frame may be a CAN CC frame or a CAN FD frame.</li> | ||
<li>if the frame size (including the header and padding) is 16, it's a CAN CC frame | ||
<li>if the frame size (including the header and padding) is 72, it's a CAN FD frame | ||
</ul> | ||
</p> | ||
|
||
<p> | ||
Older software and firmware writing packets with this link type did not | ||
use the <code>CANFD_FDF</code> flag for CAN FD frames, so if the | ||
<code>CANFD_FDF</code> flag is not set, the frame is not guaranteed to | ||
be a CAN CC frame. If that flag is not set: | ||
The FD flags field contains CAN FD specific flags; for CAN CC frames, this | ||
field is 0. The bits are: | ||
</p> | ||
<ul> | ||
<li>if the frame size (including the header and padding) is 16, it's | ||
a CAN CC frame; | ||
<li>if the frame size (including the header and padding) is 72, it's | ||
a CAN FD frame. | ||
<li><code>CANFD_BRS</code> (<code>0x01</code>) - bit rate switch (second bitrate for payload data).</li> | ||
<li><code>CANFD_ESI</code> (<code>0x02</code>) - error state indicator of the transmitting node.</li> | ||
<li><code>CANFD_FDF</code> (<code>0x04</code>) - mark CAN FD for dual use of struct canfd_frame.</li> | ||
</ul> | ||
|
||
<p> | ||
In addition, older software and firmware may not have explicitly set | ||
that field, so that the bit corresponding to the <code>CANFD_FDF</code> | ||
flag might be set even for CAN CC frames. Therefore, code that reads | ||
<code>LINKTYPE_CAN_SOCKETCAN</code> frames must perform some heuristic | ||
checks to make sure that it doesn't incorrectly interpret a CAN CC frame | ||
as a CAN FD frame, and code that generates | ||
<code>LINKTYPE_CAN_SOCKETCAN</code> frames must follow certain rules to | ||
make sure that those checks don't cause software that reads those fromes | ||
to treat a CAN FD frame as a CAN CC frame. | ||
As the <code>CANFD_FDF</code> flag for CAN FD frames is not set reliably by the Linux kernel, | ||
this flag can be used to identify CAN FD frames when using the struct canfd_frame as a container | ||
for CAN FD and CAN CC frames in user space applications. | ||
</p> | ||
|
||
<p> | ||
Software that reads <code>LINKTYPE_CAN_SOCKETCAN</code> frames must not | ||
treat a frame with the <code>CANFD_FDF</code> bit set as a CAN FD frame | ||
if any bits other than <code>CANFD_BRS</code> and <code>CANFD_ESI</code> | ||
are set in that field, or if either of the Reserved/Padding fields are | ||
non-zero, as that is an indication that the header fields might not have | ||
been explicitly set, and the <code>CANFD_FDF</code> flag might happen to | ||
be set even thugh the frame is not a CAN FD frame. | ||
Software that reads <code>LINKTYPE_CAN_SOCKETCAN</code> frames must distinguish between CAN CC and CAN FD | ||
ONLY by the frame length (16 or 72). Additionally the <code>0x80</code> bit of the fifth octet of the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The algorithm for frame type detection in Wireshark, proposed in this comment on Wireshark merge request 18710, does use the
|
||
header has to be clear for CAN CC and CAN FD frames. | ||
</p> | ||
|
||
<p> | ||
Software that generates <code>LINKTYPE_CAN_SOCKETCAN</code> frames: | ||
Software that generates <code>LINKTYPE_CAN_SOCKETCAN</code> CAN CC and CAN FD frames: | ||
</p> | ||
<ul> | ||
<li>Must check the frame MTU when receiving frames from the Linux | ||
kernel in order to classify them as CAN CC frames or CAN FD frames.</li> | ||
<li>Must create a the frame length according to the Linux kernel MTU definitions in order | ||
to classify them as CAN CC frames (MTU = 16) or CAN FD frames (MTU = 72).</li> | ||
<li>Must make the "FD flags" field 0 for CAN CC frames.</li> | ||
<li>Must set the <code>CANFD_FDF</code> bit of the "FD flags" field in CAN FD frames, | ||
and don't set any bits in that field other than the <code>CANFD_BRS</code> and <code>CANFD_ESI</code> bits | ||
unless and until Linux assigns them a meaning.</li> | ||
and <code>CANFD_BRS</code> and <code>CANFD_ESI</code> bits when needed. Unassigned bits in | ||
the "FD flags" field should be set to 0</li> | ||
<li>Must make the "Reserved/Padding" fields 0 unless and until Linux assigns | ||
that particular field a meaning.</li> | ||
that particular field a meaning.</li> | ||
<li>Might set a Len 8 DLC value for CAN CC frames or set this field to 0.</li> | ||
<li>May strip trailing padding bytes to save disk space if all above statements are satisfied.</li> | ||
</ul> | ||
|
||
|
@@ -131,8 +116,15 @@ <h4>Description</h4> | |
<p> | ||
|
||
<p> | ||
For a remote retransmission request, the payload length must be 0, so | ||
the payload is empty. | ||
A remote retransmission request (RTR) is only possible with CAN CC frames and the | ||
(real) payload length on the CAN bus is always 0. | ||
But as the 4-bit DLC value is always send inside a CAN CC frame all possible values (0 .. 15) | ||
can be defined by the Linktype protocol. | ||
<ul> | ||
<li> DLC 0 .. 8: The data length value is set to 0 .. 8. The Len 8 DLC value is set to 0.</li> | ||
<li> DLC 9 .. 15: The data length value is set to 8. The Len 8 DLC value is set to 9 .. 15.</li> | ||
</ul> | ||
The Len 8 DLC value is applicable to CAN CC data frames and CAN CC RTR frames. | ||
<p> | ||
|
||
<p> | ||
|
@@ -209,7 +201,7 @@ <h4>Description</h4> | |
The flags field contains CAN XL specific flags. The bits are: | ||
</p> | ||
<ul> | ||
<li><code>CANFD_SEC</code> (<code>0x01</code>) - Simple Extended Context.</li> | ||
<li><code>CANXL_SEC</code> (<code>0x01</code>) - Simple Extended Context.</li> | ||
<li><code>CANXL_XLF</code> (<code>0x80</code>) - if set, the frame is a CAN XL frame; if not set, | ||
the frame is a CAN CC frame or a CAN FD frame.</li> | ||
</ul> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the frame size is neither 16 nor 72? As noted, there may be files in which that's the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in existing files, so adding an ex post facto restriction that the frame size for CAN CC frames must be 16 and CAN FD frames must be 72 doesn't fix that problem.