History

can: add optional DLC element to Classical CAN frame structure

ISO 11898-1 Chapter 8.4.2.3 defines a 4 bit data length code (DLC) table which maps the DLC to the payload length of the CAN frame in bytes: DLC -> payload length 0 .. 8 -> 0 .. 8 9 .. 15 -> 8 Although the DLC values 8 .. 15 in Classical CAN always result in a payload length of 8 bytes these DLC values are transparently transmitted on the CAN bus. As the struct can_frame only provides a 'len' element (formerly 'can_dlc') which contains the plain payload length ( 0 .. 8 ) of the CAN frame, the raw DLC is not visible to the application programmer, e.g. for testing use-cases. To access the raw DLC values 9 .. 15 the len8_dlc element is introduced, which is only valid when the payload length 'len' is 8 and the DLC is greater than 8. The len8_dlc element is filled by the CAN interface driver and used for CAN frame creation by the CAN driver when the CAN_CTRLMODE_CC_LEN8_DLC flag is supported by the driver and enabled via netlink configuration interface.

Oliver Hartkopp committed 6 years ago

Commit ea780051 parent b7d3c0e2 files · +25 −14Browse files

Showing the changes to include/uapi/linux (2 of 2 files). Show all

Unified · Split

2 files
  1. include/uapi/linux/can.h +24 −14
  2. include/uapi/linux/can/netlink.h +1 −0
include/uapi/linux/can.h+24−14
@@ -84,6 +84,7 @@ typedef __u32 can_err_mask_t; · 83 unmodified lines
84 84
85/* CAN payload length and DLC definitions according to ISO 11898-1 */85/* CAN payload length and DLC definitions according to ISO 11898-1 */
86#define CAN_MAX_DLC 886#define CAN_MAX_DLC 8
87#define CAN_MAX_RAW_DLC 15
87#define CAN_MAX_DLEN 888#define CAN_MAX_DLEN 8
88 89
89/* CAN FD payload length and DLC definitions according to ISO 11898-7 */90/* CAN FD payload length and DLC definitions according to ISO 11898-7 */
@@ -91,23 +92,32 @@ typedef __u32 can_err_mask_t; · 1 unmodified line
91#define CANFD_MAX_DLEN 6492#define CANFD_MAX_DLEN 64
92 93
93/**94/**
94 * struct can_frame - basic CAN frame structure95 * struct can_frame - Classical CAN frame structure (aka CAN 2.0B)
95 * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition96 * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
96 * @can_dlc: frame payload length in byte (0 .. 8) aka data length code97 * @len: CAN frame payload length in byte (0 .. 8)
97 * N.B. the DLC field from ISO 11898-1 Chapter 8.4.2.3 has a 1:198 * @can_dlc: deprecated name for CAN frame payload length in byte (0 .. 8)
98 * mapping of the 'data length code' to the real payload length99 * @__pad: padding
99 * @__pad: padding100 * @__res0: reserved / padding
100 * @__res0: reserved / padding101 * @len8_dlc: optional DLC value (9 .. 15) at 8 byte payload length
101 * @__res1: reserved / padding102 * len8_dlc contains values from 9 .. 15 when the payload length is
102 * @data: CAN frame payload (up to 8 byte)103 * 8 bytes but the DLC value (see ISO 11898-1) is greater then 8.
104 * CAN_CTRLMODE_CC_LEN8_DLC flag has to be enabled in CAN driver.
105 * @data: CAN frame payload (up to 8 byte)
103 */106 */
104struct can_frame {107struct can_frame {
105 canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */108 canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
106 __u8 can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */109 union {
107 __u8 __pad; /* padding */110 /* CAN frame payload length in byte (0 .. CAN_MAX_DLEN)
108 __u8 __res0; /* reserved / padding */111 * was previously named can_dlc so we need to carry that
109 __u8 __res1; /* reserved / padding */112 * name for legacy support
110 __u8 data[CAN_MAX_DLEN] __attribute__((aligned(8)));113 */
114 __u8 len;
115 __u8 can_dlc; /* deprecated */
116 };
117 __u8 __pad; /* padding */
118 __u8 __res0; /* reserved / padding */
119 __u8 len8_dlc; /* optional DLC for 8 byte payload length (9 .. 15) */
120 __u8 data[CAN_MAX_DLEN] __attribute__((aligned(8)));
111};121};
112 122
113/*123/*
include/uapi/linux/can/netlink.h+1−0
@@ -100,6 +100,7 @@ struct can_ctrlmode { · 99 unmodified lines
100#define CAN_CTRLMODE_FD 0x20 /* CAN FD mode */100#define CAN_CTRLMODE_FD 0x20 /* CAN FD mode */
101#define CAN_CTRLMODE_PRESUME_ACK 0x40 /* Ignore missing CAN ACKs */101#define CAN_CTRLMODE_PRESUME_ACK 0x40 /* Ignore missing CAN ACKs */
102#define CAN_CTRLMODE_FD_NON_ISO 0x80 /* CAN FD in non-ISO mode */102#define CAN_CTRLMODE_FD_NON_ISO 0x80 /* CAN FD in non-ISO mode */
103#define CAN_CTRLMODE_CC_LEN8_DLC 0x100 /* Classic CAN DLC option */
103 104
104/*105/*
105 * CAN device statistics106 * CAN device statistics