canxl: add virtual CAN network identifier support
Subsystems (2)
Oliver Hartkopp
maintainerPATCH v5 1/1 canxl: add virtual CAN network identifier support
CAN XL data frames contain an 8-bit virtual CAN network identifier (VCID). A VCID value of zero represents an 'untagged' CAN XL frame.
To receive and send these optional VCIDs via CAN_RAW sockets a new socket option CAN_RAW_XL_VCID_OPTS is introduced to define/access VCID content:
- tx: set the outgoing VCID value by the kernel (one fixed 8-bit value)
- tx: pass through VCID values from the user space (e.g. for traffic replay)
- rx: apply VCID receive filter (value/mask) to be passed to the user space
With the 'tx pass through' option CAN_RAW_XL_VCID_TX_PASS all valid VCID values can be sent, e.g. to replay full qualified CAN XL traffic.
The VCID value provided for the CAN_RAW_XL_VCID_TX_SET option will override the VCID value in the struct canxl_frame.vcid element defined for CAN_RAW_XL_VCID_TX_PASS when both flags are set.
With a rx_vcid_mask of zero all possible VCID values (0x00 - 0xFF) are passed to the user space when the CAN_RAW_XL_VCID_RX_FILTER flag is set. Without this flag only untagged CAN XL frames (VCID = 0x00) are delivered to the user space (default).
--- include/uapi/linux/can.h | 41 +++++++++++------ include/uapi/linux/can/raw.h | 14 ++++++ net/can/af_can.c | 2 + net/can/raw.c | 86 ++++++++++++++++++++++++++++++++---- 4 files changed, 121 insertions(+), 22 deletions(-)
include/uapi/linux/can.h +27 -14
@@ -44,10 +44,11 @@*/ #ifndef _UAPI_CAN_H#define _UAPI_CAN_H +#include <asm/byteorder.h> #include <linux/types.h> #include <linux/socket.h> #include <linux/stddef.h> /* for offsetof */ /* controller area network (CAN) kernel definitions */
@@ -193,26 +194,38 @@ struct canfd_frame {#define CANXL_XLF 0x80/* mandatory CAN XL frame flag (must always be set!) */ #define CANXL_SEC 0x01/* Simple Extended Content (security/segmentation) */ /** * struct canxl_frame - CAN with e'X'tended frame 'L'ength frame structure -* @prio: 11 bit arbitration priority with zero'ed CAN_*_FLAG flags -* @flags: additional flags for CAN XL -* @sdt: SDU (service data unit) type -* @len: frame payload length in byte (CANXL_MIN_DLEN .. CANXL_MAX_DLEN) -* @af: acceptance field -* @data: CAN XL frame payload (CANXL_MIN_DLEN .. CANXL_MAX_DLEN byte) -* -* @prio shares the same position as @can_id from struct can[fd]_frame. +* @prio: 11 bit arbitration priority (unused 5 bits must be set to zero) +* Shares the lower 16 bits of @can_id from struct can[fd]_frame +* @vcid: CAN XL virtual CAN network identifier +* @__res0: reserved / padding must be set to zero to maintain the CAN filter +* functionality as it holds the @can_id flags CAN_xxx_FLAG +* @flags: additional flags for CAN XL +* @sdt: SDU (service data unit) type +* @len: frame payload length in byte (CANXL_MIN_DLEN .. CANXL_MAX_DLEN) +* @af: acceptance field +* @data: CAN XL frame payload (CANXL_MIN_DLEN .. CANXL_MAX_DLEN byte) */ struct canxl_frame { -canid_t prio;/* 11 bit priority for arbitration (canid_t) */ -__u8 flags;/* additional flags for CAN XL */ -__u8 sdt;/* SDU (service data unit) type */ -__u16 len;/* frame payload length in byte */ -__u32 af;/* acceptance field */ -__u8 data[CANXL_MAX_DLEN ]; +#if defined(__LITTLE_ENDIAN) +__u16 prio;/* 11 bit priority for arbitration */ +__u8 vcid;/* virtual CAN network identifier */ +__u8 __res0;/* reserved / padding must be set to zero */ +#elif defined(__BIG_ENDIAN) +__u8 __res0;/* reserved / padding must be set to zero */ +__u8 vcid;/* virtual CAN network identifier */ +__u16 prio;/* 11 bit priority for arbitration */ +#else +#error "Unknown endianness" +#endif +__u8 flags;/* additional flags for CAN XL */ +__u8 sdt;/* SDU (service data unit) type */ +__u16 len;/* frame payload length in byte */ +__u32 af;/* acceptance field */ +__u8 data[CANXL_MAX_DLEN ]; };#define CAN_MTU (sizeof(struct can_frame))#define CANFD_MTU (sizeof(struct canfd_frame))#define CANXL_MTU (sizeof(struct canxl_frame))
include/uapi/linux/can/raw.h +14 -0
@@ -63,8 +63,22 @@ enum {CAN_RAW_LOOPBACK ,/* local loopback (default:on) */ CAN_RAW_RECV_OWN_MSGS ,/* receive my own msgs (default:off) */ CAN_RAW_FD_FRAMES ,/* allow CAN FD frames (default:off) */ CAN_RAW_JOIN_FILTERS ,/* all filters must match to trigger */ CAN_RAW_XL_FRAMES ,/* allow CAN XL frames (default:off) */ + CAN_RAW_XL_VCID_OPTS, /* CAN XL VCID configuration options */ }; +/* configuration for CAN XL virtual CAN identifier (VCID) handling */ +struct can_raw_vcid_options { +__u8 flags;/* flags for vcid (filter) behaviour */ +__u8 tx_vcid;/* VCID value set into canxl_frame.vcid */ +__u8 rx_vcid;/* VCID value for VCID filter */ +__u8 rx_vcid_mask;/* VCID mask for VCID filter */ +}; + +/* can_raw_vcid_options.flags for CAN XL virtual CAN identifier handling */ +#define CAN_RAW_XL_VCID_TX_SET 0x01 +#define CAN_RAW_XL_VCID_TX_PASS 0x02 +#define CAN_RAW_XL_VCID_RX_FILTER 0x04 +#endif /* !_UAPI_CAN_RAW_H */
net/can/af_can.c +2 -0
@@ -863,10 +863,12 @@ static __init int can_init(void)int err;/* check for correct padding to be able to use the structs similarly */ BUILD_BUG_ON (offsetof(struct can_frame , len) != offsetof(struct canfd_frame , len) || + offsetof(struct can_frame , len) != + offsetof(struct canxl_frame , flags) || offsetof(struct can_frame , data) != offsetof(struct canfd_frame , data));pr_info ("can: controller area network core\n" );
net/can/raw.c +78 -8
171 lines not on this page · raw message
Signature · 1 line
2.39.2