48
48
49
49
#include <linux/types.h>
50
50
#include <linux/socket.h>
51
+ #include <linux/stddef.h> /* for offsetof */
51
52
52
53
/* controller area network (CAN) kernel definitions */
53
54
60
61
#define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
61
62
#define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
62
63
#define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
64
+ #define CANXL_PRIO_MASK CAN_SFF_MASK /* 11 bit priority mask */
63
65
64
66
/*
65
67
* Controller Area Network Identifier structure
@@ -73,6 +75,7 @@ typedef __u32 canid_t;
73
75
74
76
#define CAN_SFF_ID_BITS 11
75
77
#define CAN_EFF_ID_BITS 29
78
+ #define CANXL_PRIO_BITS CAN_SFF_ID_BITS
76
79
77
80
/*
78
81
* Controller Area Network Error Message Frame Mask structure
@@ -91,6 +94,16 @@ typedef __u32 can_err_mask_t;
91
94
#define CANFD_MAX_DLC 15
92
95
#define CANFD_MAX_DLEN 64
93
96
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
+
94
107
/**
95
108
* struct can_frame - Classical CAN frame structure (aka CAN 2.0B)
96
109
* @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
@@ -141,8 +154,8 @@ struct can_frame {
141
154
* When this is done the former differentiation via CAN_MTU / CANFD_MTU gets
142
155
* lost. CANFD_FDF allows programmers to mark CAN FD frames in the case of
143
156
* 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 .
146
159
*/
147
160
#define CANFD_BRS 0x01 /* bit rate switch (second bitrate for payload data) */
148
161
#define CANFD_ESI 0x02 /* error state indicator of the transmitting node */
@@ -166,8 +179,46 @@ struct canfd_frame {
166
179
__u8 data [CANFD_MAX_DLEN ] __attribute__((aligned (8 )));
167
180
};
168
181
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
+
169
216
#define CAN_MTU (sizeof(struct can_frame))
170
217
#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
171
222
172
223
/* particular protocols of the protocol family PF_CAN */
173
224
#define CAN_RAW 1 /* RAW sockets */
0 commit comments