LINKTYPE_CAN_SOCKETCAN

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.

Software that reads LINKTYPE_CAN_SOCKETCAN frames must determine the frame type in the following fashion.

CAN CC and CAN FD frames

Packet structure

+---------------------------+
|      CAN ID and flags     |
|         (4 Octets)        |
+---------------------------+
|       Payload length      |
|         (1 Octet)         |
+---------------------------+
|     FD flags (CAN FD)     |
|         (1 Octet)         |
+---------------------------+
|      Reserved/Padding     |
|         (1 Octet)         |
+---------------------------+
|     Len 8 DLC (CAN CC)    |
|         (1 Octet)         |
+---------------------------+
|          Payload          |
.                           .
.                           .
.                           .
+---------------------------+
|          Padding          |
.                           .
.                           .
.                           .

Description

The CAN ID and flags field is in big-endian byte order. The bottom 29 bits contain the CAN ID of the frame. The remaining bits are:

  • 0x20000000 - set if the frame is an error message rather than a data frame (CAN CC only).
  • 0x40000000 - set if the frame is a remote transmission request frame (CAN CC only).
  • 0x80000000 - set if the frame is an extended 29-bit frame rather than a standard 11-bit frame.

The payload length indicates the number of octets of payload following the header. All packet octets after those octets of payload are padding.

The FD flags field contains CAN FD specific flags; for CAN CC frames, this field is 0. The bits are:

  • CANFD_BRS (0x01) - bit rate switch (second bitrate for payload data).
  • CANFD_ESI (0x02) - error state indicator of the transmitting node.
  • CANFD_FDF (0x04) - 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.

The Len 8 DLC value is described for CAN CC frames in section 8.4.2.4 "DLC field" of ISO 11898-1:2015 and has a value range from 9 to 15. The Len 8 DLC value is only evaluated when the payload length of the CAN CC frame is set to 8.

Software that generates LINKTYPE_CAN_SOCKETCAN CAN CC and CAN FD frames:

  • Must set the "Payload length" field to a value from 0 to 8 (CAN CC) or 0 to 64 (CAN FD).
  • In the "FD flags" field:
    • in CAN CC frames, must clear all bits.
    • in CAN FD frames, must set the CANFD_FDF bit, set or clear the CANFD_BRS and CANFD_ESI appropriately for the frame, and clear all other bits.
  • Must set the "Reserved/Padding" field to 0.
  • May set a Len 8 DLC value for CAN CC frames or set this field to 0.
  • May strip trailing padding octets to save disk space if all above statements are satisfied.

For a data frame, the payload is the data field of the CAN CC or CAN FD packet.

In CAN CC remote retransmission request (RTR) frames, no payload data is sent on the wire. But a data length code (DLC) can still be set in those data-less CAN CC RTR frames. This length information is then stored in the payload length and optionally in the Len 8 DLC value. A non-zero payload length does therefore not indicate the presence of payload data.

For an error message, the payload is always 8 octets. The lower bits of the CAN ID field contain an error class value, with bits specified by the first set of CAN_ERR_ values in the Linux uapi/can/error.h header. The octets in the payload are:

  • first octet - if arbitration was lost, the bit number in the bitstream in which it was lost; otherwise 0.
  • second octet - the error status of the CAN controller, with bits specified by the CAN_ERR_CTRL_ bits in the Linux uapi/can/error.h header.
  • third octet - flags indicating a CAN protocol error type, with bits specified by the CAN_ERR_PROT_ bits in the Linux uapi/can/error.h header.
  • fourth octet - flags indicating a CAN protocol error location, with bits specified by the CAN_ERR_LOC_ bits in the Linux uapi/can/error.h header.
  • fifth octet - the error status of the CAN transceiver, with values specified by the CAN_ERR_TRX_ values in the Linux uapi/can/error.h header.
  • sixth, seventh, and eighth octets - controller-specific additional information.

CAN XL frames

Packet structure

+---------------------------+
|      Priority ID/VCID     |
|         (4 Octets)        |
+---------------------------+
|         XL Flags          |
|         (1 Octet)         |
+---------------------------+
|         SDU type          |
|         (1 Octet)         |
+---------------------------+
|       Payload length      |
|         (2 Octets)        |
+---------------------------+
|      Acceptance Field     |
|         (4 Octets)        |
+---------------------------+
|          Payload          |
.                           .
.                           .
.                           .
+---------------------------+
|          Padding          |
.                           .
.                           .
.                           .

Description

The Priority ID/VCID field is big-endian, but the payload length and acceptance field are little-endian.

The Priority ID/VCID field is in big-endian byte order. The bottom 11 bits contain the priority of the frame. The 5 bits above that are reserved. The 8 bits above that contain a virtual CAN network identifier (VCID). The 8 bits above that are reserved.

The XL Flags field contains CAN XL specific flags. The bits are:

  • CANXL_SEC (0x01) - Simple Extended Content.
  • CANXL_RRS (0x02) - Remote Request Substitution.
  • CANXL_XLF (0x80) - if set, the frame is a CAN XL frame; if not set, the frame is a CAN CC frame or a CAN FD frame.

The SDU type field contains an indication of the higher-layer protocol used by the payload. The values of this field are specified by CAN in Automation (CiA) specification 611-1 "CAN XL higher-layer functions - Part 1: Definition of service data unit types (SDT)".

The frame payload length is in little-endian byte order. It indicates the number of octets of payload following the header. All packet octets after those octets of payload are padding.

The Acceptance Field is in little-endian byte order.

Software that generates LINKTYPE_CAN_SOCKETCAN CAN XL frames:

  • Must set the "Payload length" field to a value from 1 to 2048.
  • In the "XL Flags" field:
    • must set the CANXL_XLF bit.
    • must set the CANFD_SEC bit as appropriate for the frame and clear all other bits.
  • May strip trailing padding octets to save disk space if all above statements are satisfied.
The payload is the data field of the CAN XL packet.