1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/// CAN netlink functionality for interface configuration
/* controller area network (CAN) kernel definitions */
/* special address description flags for the CAN_ID */
/// Extended frame format flag, set in the MSB of CAN ID
pub const CAN_EFF_FLAG: u32 = 0x80000000u32; /* EFF/SFF is set in the MSB */
/// Remote transmission request flag
pub const CAN_RTR_FLAG: u32 = 0x40000000u32; /* remote transmission request */
/// Error message frame flag
pub const CAN_ERR_FLAG: u32 = 0x20000000u32; /* error message frame */
/* valid bits in CAN ID for frame formats */
/// Standard frame format (SFF) ID mask (11 bits)
pub const CAN_SFF_MASK: u32 = 0x000007FFu32; /* standard frame format (SFF) */
/// Extended frame format (EFF) ID mask (29 bits)
pub const CAN_EFF_MASK: u32 = 0x1FFFFFFFu32; /* extended frame format (EFF) */
/// Error frame mask (omits EFF, RTR, ERR flags)
pub const CAN_ERR_MASK: u32 = 0x1FFFFFFFu32; /* omit EFF, RTR, ERR flags */
/// CAN XL priority mask (11 bits)
pub const CANXL_PRIO_MASK: u32 = CAN_SFF_MASK; /* 11 bit priority mask */
/*
* Controller Area Network Identifier structure
*
* bit 0-28 : CAN identifier (11/29 bit)
* bit 29 : error message frame flag (0 = data frame, 1 = error message)
* bit 30 : remote transmission request flag (1 = rtr frame)
* bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit)
*/
/// CAN identifier type (32-bit value with embedded flags)
pub type canid_t = u32;
/// Number of bits in a standard frame format identifier
pub const CAN_SFF_ID_BITS: u32 = 11;
/// Number of bits in an extended frame format identifier
pub const CAN_EFF_ID_BITS: u32 = 29;
/// Number of bits in CAN XL priority field
pub const CANXL_PRIO_BITS: u32 = CAN_SFF_ID_BITS;
/*
* Controller Area Network Error Message Frame Mask structure
*
* bit 0-28 : error class mask (see include/uapi/linux/can/error.h)
* bit 29-31 : set to zero
*/
/// CAN error message frame mask type
pub type can_err_mask_t = u32;
/* CAN payload length and DLC definitions according to ISO 11898-1 */
/// Maximum data length code for Classical CAN
pub const CAN_MAX_DLC: u32 = 8;
/// Maximum raw DLC value
pub const CAN_MAX_RAW_DLC: u32 = 15;
/// Maximum data length for Classical CAN in bytes
pub const CAN_MAX_DLEN: u32 = 8;
/* CAN FD payload length and DLC definitions according to ISO 11898-7 */
/// Maximum data length code for CAN FD
pub const CANFD_MAX_DLC: u32 = 15;
/// Maximum data length for CAN FD in bytes
pub const CANFD_MAX_DLEN: u32 = 64;
/*
* CAN XL payload length and DLC definitions according to ISO 11898-1
* CAN XL DLC ranges from 0 .. 2047 => data length from 1 .. 2048 byte
*/
/// Minimum data length code for CAN XL
pub const CANXL_MIN_DLC: u32 = 0;
/// Maximum data length code for CAN XL
pub const CANXL_MAX_DLC: u32 = 2047;
/// Mask for CAN XL DLC field
pub const CANXL_MAX_DLC_MASK: u32 = 0x07FF;
/// Minimum data length for CAN XL in bytes
pub const CANXL_MIN_DLEN: u32 = 1;
/// Maximum data length for CAN XL in bytes
pub const CANXL_MAX_DLEN: u32 = 2048;
/*
* defined bits for canfd_frame.flags
*
* The use of struct canfd_frame implies the FD Frame (FDF) bit to
* be set in the CAN frame bitstream on the wire. The FDF bit switch turns
* the CAN controllers bitstream processor into the CAN FD mode which creates
* two new options within the CAN FD frame specification:
*
* Bit Rate Switch - to indicate a second bitrate is/was used for the payload
* Error State Indicator - represents the error state of the transmitting node
*
* As the CANFD_ESI bit is internally generated by the transmitting CAN
* controller only the CANFD_BRS bit is relevant for real CAN controllers when
* building a CAN FD frame for transmission. Setting the CANFD_ESI bit can make
* sense for virtual CAN interfaces to test applications with echoed frames.
*
* The struct can_frame and struct canfd_frame intentionally share the same
* layout to be able to write CAN frame content into a CAN FD frame structure.
* When this is done the former differentiation via CAN_MTU / CANFD_MTU gets
* lost. CANFD_FDF allows programmers to mark CAN FD frames in the case of
* using struct canfd_frame for mixed CAN / CAN FD content (dual use).
* Since the introduction of CAN XL the CANFD_FDF flag is set in all CAN FD
* frame structures provided by the CAN subsystem of the Linux kernel.
*/
/// Bit rate switch flag (second bitrate for payload data)
pub const CANFD_BRS: u32 = 0x01; /* bit rate switch (second bitrate for payload data) */
/// Error state indicator flag of the transmitting node
pub const CANFD_ESI: u32 = 0x02; /* error state indicator of the transmitting node */
/// Flag to mark CAN FD for dual use of struct canfd_frame
pub const CANFD_FDF: u32 = 0x04; /* mark CAN FD for dual use of struct canfd_frame */
/*
* defined bits for canxl_frame.flags
*
* The canxl_frame.flags element contains two bits CANXL_XLF and CANXL_SEC
* and shares the relative position of the struct can[fd]_frame.len element.
* The CANXL_XLF bit ALWAYS needs to be set to indicate a valid CAN XL frame.
* As a side effect setting this bit intentionally breaks the length checks
* for Classical CAN and CAN FD frames.
*
* Undefined bits in canxl_frame.flags are reserved and shall be set to zero.
*/
/// Mandatory CAN XL frame flag (must always be set)
pub const CANXL_XLF: u32 = 0x80; /* mandatory CAN XL frame flag (must always be set!) */
/// Simple Extended Content flag (security/segmentation)
pub const CANXL_SEC: u32 = 0x01; /* Simple Extended Content (security/segmentation) */
/// MTU size for Classical CAN frames
pub const CAN_MTU: usize = ;
/// MTU size for CAN FD frames
pub const CANFD_MTU: usize = ;
/// MTU size for CAN XL frames
pub const CANXL_MTU: usize = ;
/// Header size for CAN XL frames
pub const CANXL_HDR_SIZE: usize = offset_of!;
/// Minimum MTU size for CAN XL frames
pub const CANXL_MIN_MTU: usize = CANXL_HDR_SIZE + 64;
/// Maximum MTU size for CAN XL frames
pub const CANXL_MAX_MTU: usize = CANXL_MTU;
/// Raw CAN protocol
pub const CAN_RAW: u32 = 1;
/// Broadcast Manager CAN protocol
pub const CAN_BCM: u32 = 2;
/// Virtual Terminal Protocol
pub const CAN_TP16: u32 = 3;
/// ISO 15765-2 Transport Protocol
pub const CAN_TP20: u32 = 4;
/// Bosch MCNet protocol
pub const CAN_MCNET: u32 = 5;
/// ISO 15765-2 Transport Protocol
pub const CAN_ISOTP: u32 = 6;
/// SAE J1939 protocol
pub const CAN_J1939: u32 = 7;
/// Number of CAN protocols
pub const CAN_NPROTO: u32 = 8;
/// CAN frame structure for Classical CAN
/// CAN frame header union for compatibility
pub union can_word_hdr
/// CAN FD frame structure
/// CAN XL frame structure
/// Socket address structure for CAN sockets
/// J1939 address information structure
/// Transport protocol address information structure
/// Union of different address types for CAN sockets
pub union can_addr
/// CAN filter structure