4848
4949#include <linux/types.h>
5050#include <linux/socket.h>
51+ #include <linux/stddef.h> /* for offsetof */
5152
5253/* controller area network (CAN) kernel definitions */
5354
6061#define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
6162#define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
6263#define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
64+ #define CANXL_PRIO_MASK CAN_SFF_MASK /* 11 bit priority mask */
6365
6466/*
6567 * Controller Area Network Identifier structure
@@ -73,6 +75,7 @@ typedef __u32 canid_t;
7375
7476#define CAN_SFF_ID_BITS 11
7577#define CAN_EFF_ID_BITS 29
78+ #define CANXL_PRIO_BITS CAN_SFF_ID_BITS
7679
7780/*
7881 * Controller Area Network Error Message Frame Mask structure
@@ -91,6 +94,16 @@ typedef __u32 can_err_mask_t;
9194#define CANFD_MAX_DLC 15
9295#define CANFD_MAX_DLEN 64
9396
97+ /*
98+ * CAN XL payload length and DLC definitions according to ISO 11898-1
99+ * CAN XL DLC ranges from 0 .. 2047 => data length from 1 .. 2048 byte
100+ */
101+ #define CANXL_MIN_DLC 0
102+ #define CANXL_MAX_DLC 2047
103+ #define CANXL_MAX_DLC_MASK 0x07FF
104+ #define CANXL_MIN_DLEN 1
105+ #define CANXL_MAX_DLEN 2048
106+
94107/**
95108 * struct can_frame - Classical CAN frame structure (aka CAN 2.0B)
96109 * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
@@ -141,8 +154,8 @@ struct can_frame {
141154 * When this is done the former differentiation via CAN_MTU / CANFD_MTU gets
142155 * lost. CANFD_FDF allows programmers to mark CAN FD frames in the case of
143156 * using struct canfd_frame for mixed CAN / CAN FD content (dual use).
144- * N.B. the Kernel APIs do NOT provide mixed CAN / CAN FD content inside of
145- * struct canfd_frame therefore the CANFD_FDF flag is disregarded by Linux.
157+ * Since the introduction of CAN XL the CANFD_FDF flag is set in all CAN FD
158+ * frame structures provided by the CAN subsystem of the Linux kernel .
146159 */
147160#define CANFD_BRS 0x01 /* bit rate switch (second bitrate for payload data) */
148161#define CANFD_ESI 0x02 /* error state indicator of the transmitting node */
@@ -166,8 +179,46 @@ struct canfd_frame {
166179 __u8 data [CANFD_MAX_DLEN ] __attribute__((aligned (8 )));
167180};
168181
182+ /*
183+ * defined bits for canxl_frame.flags
184+ *
185+ * The canxl_frame.flags element contains two bits CANXL_XLF and CANXL_SEC
186+ * and shares the relative position of the struct can[fd]_frame.len element.
187+ * The CANXL_XLF bit ALWAYS needs to be set to indicate a valid CAN XL frame.
188+ * As a side effect setting this bit intentionally breaks the length checks
189+ * for Classical CAN and CAN FD frames.
190+ *
191+ * Undefined bits in canxl_frame.flags are reserved and shall be set to zero.
192+ */
193+ #define CANXL_XLF 0x80 /* mandatory CAN XL frame flag (must always be set!) */
194+ #define CANXL_SEC 0x01 /* Simple Extended Content (security/segmentation) */
195+
196+ /**
197+ * struct canxl_frame - CAN with e'X'tended frame 'L'ength frame structure
198+ * @prio: 11 bit arbitration priority with zero'ed CAN_*_FLAG flags
199+ * @flags: additional flags for CAN XL
200+ * @sdt: SDU (service data unit) type
201+ * @len: frame payload length in byte (CANXL_MIN_DLEN .. CANXL_MAX_DLEN)
202+ * @af: acceptance field
203+ * @data: CAN XL frame payload (CANXL_MIN_DLEN .. CANXL_MAX_DLEN byte)
204+ *
205+ * @prio shares the same position as @can_id from struct can[fd]_frame.
206+ */
207+ struct canxl_frame {
208+ canid_t prio ; /* 11 bit priority for arbitration (canid_t) */
209+ __u8 flags ; /* additional flags for CAN XL */
210+ __u8 sdt ; /* SDU (service data unit) type */
211+ __u16 len ; /* frame payload length in byte */
212+ __u32 af ; /* acceptance field */
213+ __u8 data [CANXL_MAX_DLEN ];
214+ };
215+
169216#define CAN_MTU (sizeof(struct can_frame))
170217#define CANFD_MTU (sizeof(struct canfd_frame))
218+ #define CANXL_MTU (sizeof(struct canxl_frame))
219+ #define CANXL_HDR_SIZE (offsetof(struct canxl_frame, data))
220+ #define CANXL_MIN_MTU (CANXL_HDR_SIZE + 64)
221+ #define CANXL_MAX_MTU CANXL_MTU
171222
172223/* particular protocols of the protocol family PF_CAN */
173224#define CAN_RAW 1 /* RAW sockets */
0 commit comments