Skip to content

Commit e2454c9

Browse files
committed
update the socketcan uapi headers
1 parent 3e3a482 commit e2454c9

7 files changed

Lines changed: 136 additions & 34 deletions

File tree

core/src/include/linux/can.h

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
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

@@ -60,6 +61,7 @@
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 */

core/src/include/linux/can/bcm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct bcm_msg_head {
7171
struct bcm_timeval ival1, ival2;
7272
canid_t can_id;
7373
__u32 nframes;
74-
struct can_frame frames[0];
74+
struct can_frame frames[];
7575
};
7676

7777
enum {

core/src/include/linux/can/error.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
#define CAN_ERR_BUSOFF 0x00000040U /* bus off */
5858
#define CAN_ERR_BUSERROR 0x00000080U /* bus error (may flood!) */
5959
#define CAN_ERR_RESTARTED 0x00000100U /* controller restarted */
60+
#define CAN_ERR_CNT 0x00000200U /* TX error counter / data[6] */
61+
/* RX error counter / data[7] */
6062

6163
/* arbitration lost in bit ... / data[0] */
6264
#define CAN_ERR_LOSTARB_UNSPEC 0x00 /* unspecified */
@@ -120,6 +122,22 @@
120122
#define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70 /* 0111 0000 */
121123
#define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80 /* 1000 0000 */
122124

123-
/* controller specific additional information / data[5..7] */
125+
/* data[5] is reserved (do not use) */
126+
127+
/* TX error counter / data[6] */
128+
/* RX error counter / data[7] */
129+
130+
/* CAN state thresholds
131+
*
132+
* Error counter Error state
133+
* -----------------------------------
134+
* 0 - 95 Error-active
135+
* 96 - 127 Error-warning
136+
* 128 - 255 Error-passive
137+
* 256 and greater Bus-off
138+
*/
139+
#define CAN_ERROR_WARNING_THRESHOLD 96
140+
#define CAN_ERROR_PASSIVE_THRESHOLD 128
141+
#define CAN_BUS_OFF_THRESHOLD 256
124142

125143
#endif /* _UAPI_CAN_ERROR_H */

core/src/include/linux/can/isotp.h

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -124,33 +124,30 @@ struct can_isotp_ll_options {
124124

125125
/* flags for isotp behaviour */
126126

127-
#define CAN_ISOTP_LISTEN_MODE 0x001 /* listen only (do not send FC) */
128-
#define CAN_ISOTP_EXTEND_ADDR 0x002 /* enable extended addressing */
129-
#define CAN_ISOTP_TX_PADDING 0x004 /* enable CAN frame padding tx path */
130-
#define CAN_ISOTP_RX_PADDING 0x008 /* enable CAN frame padding rx path */
131-
#define CAN_ISOTP_CHK_PAD_LEN 0x010 /* check received CAN frame padding */
132-
#define CAN_ISOTP_CHK_PAD_DATA 0x020 /* check received CAN frame padding */
133-
#define CAN_ISOTP_HALF_DUPLEX 0x040 /* half duplex error state handling */
134-
#define CAN_ISOTP_FORCE_TXSTMIN 0x080 /* ignore stmin from received FC */
135-
#define CAN_ISOTP_FORCE_RXSTMIN 0x100 /* ignore CFs depending on rx stmin */
136-
#define CAN_ISOTP_RX_EXT_ADDR 0x200 /* different rx extended addressing */
137-
#define CAN_ISOTP_WAIT_TX_DONE 0x400 /* wait for tx completion */
138-
#define CAN_ISOTP_SF_BROADCAST 0x800 /* 1-to-N functional addressing */
139-
140-
/* default values */
127+
#define CAN_ISOTP_LISTEN_MODE 0x0001 /* listen only (do not send FC) */
128+
#define CAN_ISOTP_EXTEND_ADDR 0x0002 /* enable extended addressing */
129+
#define CAN_ISOTP_TX_PADDING 0x0004 /* enable CAN frame padding tx path */
130+
#define CAN_ISOTP_RX_PADDING 0x0008 /* enable CAN frame padding rx path */
131+
#define CAN_ISOTP_CHK_PAD_LEN 0x0010 /* check received CAN frame padding */
132+
#define CAN_ISOTP_CHK_PAD_DATA 0x0020 /* check received CAN frame padding */
133+
#define CAN_ISOTP_HALF_DUPLEX 0x0040 /* half duplex error state handling */
134+
#define CAN_ISOTP_FORCE_TXSTMIN 0x0080 /* ignore stmin from received FC */
135+
#define CAN_ISOTP_FORCE_RXSTMIN 0x0100 /* ignore CFs depending on rx stmin */
136+
#define CAN_ISOTP_RX_EXT_ADDR 0x0200 /* different rx extended addressing */
137+
#define CAN_ISOTP_WAIT_TX_DONE 0x0400 /* wait for tx completion */
138+
#define CAN_ISOTP_SF_BROADCAST 0x0800 /* 1-to-N functional addressing */
139+
#define CAN_ISOTP_CF_BROADCAST 0x1000 /* 1-to-N transmission w/o FC */
140+
141+
/* protocol machine default values */
141142

142143
#define CAN_ISOTP_DEFAULT_FLAGS 0
143144
#define CAN_ISOTP_DEFAULT_EXT_ADDRESS 0x00
144145
#define CAN_ISOTP_DEFAULT_PAD_CONTENT 0xCC /* prevent bit-stuffing */
145-
#define CAN_ISOTP_DEFAULT_FRAME_TXTIME 0
146+
#define CAN_ISOTP_DEFAULT_FRAME_TXTIME 50000 /* 50 micro seconds */
146147
#define CAN_ISOTP_DEFAULT_RECV_BS 0
147148
#define CAN_ISOTP_DEFAULT_RECV_STMIN 0x00
148149
#define CAN_ISOTP_DEFAULT_RECV_WFTMAX 0
149150

150-
#define CAN_ISOTP_DEFAULT_LL_MTU CAN_MTU
151-
#define CAN_ISOTP_DEFAULT_LL_TX_DL CAN_MAX_DLEN
152-
#define CAN_ISOTP_DEFAULT_LL_TX_FLAGS 0
153-
154151
/*
155152
* Remark on CAN_ISOTP_DEFAULT_RECV_* values:
156153
*
@@ -162,4 +159,24 @@ struct can_isotp_ll_options {
162159
* consistency and copied directly into the flow control (FC) frame.
163160
*/
164161

162+
/* link layer default values => make use of Classical CAN frames */
163+
164+
#define CAN_ISOTP_DEFAULT_LL_MTU CAN_MTU
165+
#define CAN_ISOTP_DEFAULT_LL_TX_DL CAN_MAX_DLEN
166+
#define CAN_ISOTP_DEFAULT_LL_TX_FLAGS 0
167+
168+
/*
169+
* The CAN_ISOTP_DEFAULT_FRAME_TXTIME has become a non-zero value as
170+
* it only makes sense for isotp implementation tests to run without
171+
* a N_As value. As user space applications usually do not set the
172+
* frame_txtime element of struct can_isotp_options the new in-kernel
173+
* default is very likely overwritten with zero when the sockopt()
174+
* CAN_ISOTP_OPTS is invoked.
175+
* To make sure that a N_As value of zero is only set intentional the
176+
* value '0' is now interpreted as 'do not change the current value'.
177+
* When a frame_txtime of zero is required for testing purposes this
178+
* CAN_ISOTP_FRAME_TXTIME_ZERO u32 value has to be set in frame_txtime.
179+
*/
180+
#define CAN_ISOTP_FRAME_TXTIME_ZERO 0xFFFFFFFF
181+
165182
#endif /* !_UAPI_CAN_ISOTP_H */

core/src/include/linux/can/netlink.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ enum {
137137
IFLA_CAN_DATA_BITRATE_CONST,
138138
IFLA_CAN_BITRATE_MAX,
139139
IFLA_CAN_TDC,
140+
IFLA_CAN_CTRLMODE_EXT,
140141

141142
/* add new constants above here */
142143
__IFLA_CAN_MAX,
@@ -166,6 +167,18 @@ enum {
166167
IFLA_CAN_TDC_MAX = __IFLA_CAN_TDC - 1
167168
};
168169

170+
/*
171+
* IFLA_CAN_CTRLMODE_EXT nest: controller mode extended parameters
172+
*/
173+
enum {
174+
IFLA_CAN_CTRLMODE_UNSPEC,
175+
IFLA_CAN_CTRLMODE_SUPPORTED, /* u32 */
176+
177+
/* add new constants above here */
178+
__IFLA_CAN_CTRLMODE,
179+
IFLA_CAN_CTRLMODE_MAX = __IFLA_CAN_CTRLMODE - 1
180+
};
181+
169182
/* u16 termination range: 1..65535 Ohms */
170183
#define CAN_TERMINATION_DISABLED 0
171184

core/src/include/linux/can/raw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ enum {
6262
CAN_RAW_RECV_OWN_MSGS, /* receive my own msgs (default:off) */
6363
CAN_RAW_FD_FRAMES, /* allow CAN FD frames (default:off) */
6464
CAN_RAW_JOIN_FILTERS, /* all filters must match to trigger */
65+
CAN_RAW_XL_FRAMES, /* allow CAN XL frames (default:off) */
6566
};
6667

6768
#endif /* !_UAPI_CAN_RAW_H */

core/src/main/java/tel/schich/javacan/IsotpOptions.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,19 @@ public String toString() {
256256
}
257257

258258
public enum Flag {
259-
LISTEN_MODE(0x001, "listen only (do not send FC)"),
260-
EXTEND_ADDR(0x002, "enable extended addressing"),
261-
TX_PADDING(0x004, "enable CAN frame padding tx path"),
262-
RX_PADDING(0x008, "enable CAN frame padding rx path"),
263-
CHK_PAD_LEN(0x010, "check received CAN frame padding"),
264-
CHK_PAD_DATA(0x020, "check received CAN frame padding"),
265-
HALF_DUPLEX(0x040, "half duplex error state handling"),
266-
FORCE_TXSTMIN(0x080, "ignore stmin from received FC"),
267-
FORCE_RXSTMIN(0x100, "ignore CFs depending on rx stmin"),
268-
RX_EXT_ADDR(0x200, "different rx extended addressing"),
269-
WAIT_TX_DONE(0x400, "wait for tx completion");
259+
LISTEN_MODE(0x0001, "listen only (do not send FC)"),
260+
EXTEND_ADDR(0x0002, "enable extended addressing"),
261+
TX_PADDING(0x0004, "enable CAN frame padding tx path"),
262+
RX_PADDING(0x0008, "enable CAN frame padding rx path"),
263+
CHK_PAD_LEN(0x0010, "check received CAN frame padding"),
264+
CHK_PAD_DATA(0x0020, "check received CAN frame padding"),
265+
HALF_DUPLEX(0x0040, "half duplex error state handling"),
266+
FORCE_TXSTMIN(0x0080, "ignore stmin from received FC"),
267+
FORCE_RXSTMIN(0x0100, "ignore CFs depending on rx stmin"),
268+
RX_EXT_ADDR(0x0200, "different rx extended addressing"),
269+
WAIT_TX_DONE(0x0400, "wait for tx completion"),
270+
SF_BROADCAST(0x0800, "1-to-N functional addressing"),
271+
CF_BROADCAST(0x1000, "1-to-N transmission w/o FC");
270272

271273
private final int bit;
272274
private final String description;

0 commit comments

Comments
 (0)