Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linux canxl constants and canxl frame struct #3247

Merged
merged 4 commits into from May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion libc-test/build.rs
Expand Up @@ -3469,6 +3469,8 @@ fn test_linux(target: &str) {
"sctp_initmsg" | "sctp_sndrcvinfo" | "sctp_sndinfo" | "sctp_rcvinfo"
| "sctp_nxtinfo" | "sctp_prinfo" | "sctp_authinfo" => true,

// FIXME: requires >= 6.1 kernel headers
"canxl_frame" => true,
_ => false,
}
});
Expand Down Expand Up @@ -3651,7 +3653,22 @@ fn test_linux(target: &str) {
"FUTEX_LOCK_PI2" => true,

// Added in linux 6.1
"STATX_DIOALIGN" => true,
"STATX_DIOALIGN"
| "CAN_RAW_XL_FRAMES"
| "CANXL_HDR_SIZE"
| "CANXL_MAX_DLC"
| "CANXL_MAX_DLC_MASK"
| "CANXL_MAX_DLEN"
| "CANXL_MAX_MTU"
| "CANXL_MIN_DLC"
| "CANXL_MIN_DLEN"
| "CANXL_MIN_MTU"
| "CANXL_MTU"
| "CANXL_PRIO_BITS"
| "CANXL_PRIO_MASK"
| "CANXL_SEC"
| "CANXL_XLF"
=> true,

// FIXME: Parts of netfilter/nfnetlink*.h require more recent kernel headers:
| "RTNLGRP_MCTP_IFADDR" // linux v5.17+
Expand Down
15 changes: 15 additions & 0 deletions libc-test/semver/linux.txt
Expand Up @@ -237,6 +237,20 @@ CAN_RAW_LOOPBACK
CAN_RAW_RECV_OWN_MSGS
CAN_RAW_FD_FRAMES
CAN_RAW_JOIN_FILTERS
CAN_RAW_XL_FRAMES
CANXL_HDR_SIZE
CANXL_MAX_DLC
CANXL_MAX_DLC_MASK
CANXL_MAX_DLEN
CANXL_MAX_MTU
CANXL_MIN_DLC
CANXL_MIN_DLEN
CANXL_MIN_MTU
CANXL_MTU
CANXL_PRIO_BITS
CANXL_PRIO_MASK
CANXL_SEC
CANXL_XLF
CBAUD
CBAUDEX
CLD_CONTINUED
Expand Down Expand Up @@ -3056,6 +3070,7 @@ can_err_mask_t
can_filter
can_frame
canfd_frame
canxl_frame
canid_t
chroot
clearenv
Expand Down
11 changes: 11 additions & 0 deletions src/unix/linux_like/linux/align.rs
Expand Up @@ -176,6 +176,17 @@ macro_rules! expand_align {
__res1: u8,
pub data: [u8; CANFD_MAX_DLEN],
}

#[repr(align(8))]
#[allow(missing_debug_implementations)]
pub struct canxl_frame {
pub prio: canid_t,
pub flags: u8,
pub sdt: u8,
pub len: u16,
pub af: u32,
pub data: [u8; CANXL_MAX_DLEN],
}
}
};
}
19 changes: 19 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Expand Up @@ -3723,9 +3723,11 @@ pub const CAN_ERR_FLAG: canid_t = 0x20000000;
pub const CAN_SFF_MASK: canid_t = 0x000007FF;
pub const CAN_EFF_MASK: canid_t = 0x1FFFFFFF;
pub const CAN_ERR_MASK: canid_t = 0x1FFFFFFF;
pub const CANXL_PRIO_MASK: ::canid_t = CAN_SFF_MASK;

pub const CAN_SFF_ID_BITS: ::c_int = 11;
pub const CAN_EFF_ID_BITS: ::c_int = 29;
pub const CANXL_PRIO_BITS: ::c_int = CAN_SFF_ID_BITS;

pub const CAN_MAX_DLC: ::c_int = 8;
pub const CAN_MAX_DLEN: usize = 8;
Expand All @@ -3735,10 +3737,26 @@ pub const CANFD_MAX_DLEN: usize = 64;
pub const CANFD_BRS: ::c_int = 0x01;
pub const CANFD_ESI: ::c_int = 0x02;

pub const CANXL_MIN_DLC: ::c_int = 0;
pub const CANXL_MAX_DLC: ::c_int = 2047;
pub const CANXL_MAX_DLC_MASK: ::c_int = 0x07FF;
pub const CANXL_MIN_DLEN: usize = 1;
pub const CANXL_MAX_DLEN: usize = 2048;

pub const CANXL_XLF: ::c_int = 0x80;
pub const CANXL_SEC: ::c_int = 0x01;

cfg_if! {
if #[cfg(libc_align)] {
pub const CAN_MTU: usize = ::mem::size_of::<can_frame>();
pub const CANFD_MTU: usize = ::mem::size_of::<canfd_frame>();
pub const CANXL_MTU: usize = ::mem::size_of::<canxl_frame>();
// FIXME: use `core::mem::offset_of!` once that is available
// https://github.com/rust-lang/rfcs/pull/3308
// pub const CANXL_HDR_SIZE: usize = core::mem::offset_of!(canxl_frame, data);
pub const CANXL_HDR_SIZE: usize = 12;
pub const CANXL_MIN_MTU: usize = CANXL_HDR_SIZE + 64;
pub const CANXL_MAX_MTU: usize = CANXL_MTU;
}
}

Expand All @@ -3764,6 +3782,7 @@ pub const CAN_RAW_LOOPBACK: ::c_int = 3;
pub const CAN_RAW_RECV_OWN_MSGS: ::c_int = 4;
pub const CAN_RAW_FD_FRAMES: ::c_int = 5;
pub const CAN_RAW_JOIN_FILTERS: ::c_int = 6;
pub const CAN_RAW_XL_FRAMES: ::c_int = 7;

// linux/can/j1939.h
pub const SOL_CAN_J1939: ::c_int = SOL_CAN_BASE + CAN_J1939;
Expand Down