Skip to content

Add SocketCan J1939 constants and structs #2706

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

Merged
merged 6 commits into from
Mar 11, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2917,6 +2917,8 @@ fn test_linux(target: &str) {
"asm/mman.h",
"linux/can.h",
"linux/can/raw.h",
// FIXME: requires kernel headers >= 5.4.1.
[!musl]: "linux/can/j1939.h",
"linux/dccp.h",
"linux/errqueue.h",
"linux/falloc.h",
Expand Down Expand Up @@ -3042,6 +3044,11 @@ fn test_linux(target: &str) {
// For internal use only, to define architecture specific ioctl constants with a libc specific type.
"Ioctl" => true,

// FIXME: requires >= 5.4.1 kernel headers
"pgn_t" if musl => true,
"priority_t" if musl => true,
"name_t" if musl => true,

_ => false,
}
});
Expand Down Expand Up @@ -3103,6 +3110,9 @@ fn test_linux(target: &str) {
// Might differ between kernel versions
"open_how" => true,

// FIXME: requires >= 5.4.1 kernel headers
"j1939_filter" if musl => true,

_ => false,
}
});
Expand Down Expand Up @@ -3137,6 +3147,12 @@ fn test_linux(target: &str) {
|| name.starts_with("TCP_")
|| name.starts_with("UINPUT_")
|| name.starts_with("VMADDR_")
// FIXME: Requires >= 5.4.1 kernel headers
|| name.starts_with("J1939")
// FIXME: Requires >= 5.4.1 kernel headers
|| name.starts_with("SO_J1939")
// FIXME: Requires >= 5.4.1 kernel headers
|| name.starts_with("SCM_J1939")
{
return true;
}
Expand Down Expand Up @@ -3233,6 +3249,18 @@ fn test_linux(target: &str) {
| "CAN_RAW_FILTER_MAX"
| "CAN_NPROTO" => true,

// FIXME: Requires recent kernel headers (5.15)
| "J1939_NLA_TOTAL_SIZE"
| "J1939_NLA_PGN"
| "J1939_NLA_SRC_NAME"
| "J1939_NLA_DEST_NAME"
| "J1939_NLA_SRC_ADDR"
| "J1939_NLA_DEST_ADDR"
| "J1939_EE_INFO_RX_RTS"
| "J1939_EE_INFO_RX_DPO"
| "J1939_EE_INFO_RX_ABORT"
| "SOL_CAN_J1939" => true,

// FIXME: Requires recent kernel headers (5.8):
"STATX_MNT_ID" => true,

Expand Down
31 changes: 31 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,24 @@ ITIMER_PROF
ITIMER_REAL
ITIMER_VIRTUAL
IUTF8
J1939_IDLE_ADDR
J1939_MAX_UNICAST_ADDR
J1939_NLA_BYTES_ACKED
J1939_NLA_DEST_ADDR
J1939_NLA_DEST_NAME
J1939_NLA_PAD
J1939_NLA_PGN
J1939_NLA_SRC_ADDR
J1939_NLA_SRC_NAME
J1939_NLA_TOTAL_SIZE
J1939_NO_ADDR
J1939_NO_NAME
J1939_NO_PGN
J1939_PGN_ADDRESS_CLAIMED
J1939_PGN_ADDRESS_COMMANDED
J1939_PGN_MAX
J1939_PGN_PDU1_MAX
J1939_PGN_REQUEST
KEYCTL_ASSUME_AUTHORITY
KEYCTL_CHOWN
KEYCTL_CLEAR
Expand Down Expand Up @@ -1945,6 +1963,10 @@ SCHED_RESET_ON_FORK
SCHED_RR
SCM_CREDENTIALS
SCM_RIGHTS
SCM_J1939_DEST_ADDR
SCM_J1939_DEST_NAME
SCM_J1939_ERRQUEUE
SCM_J1939_PRIO
SCM_TIMESTAMP
SCM_TIMESTAMPING
SECCOMP_FILTER_FLAG_LOG
Expand Down Expand Up @@ -2047,6 +2069,7 @@ SOL_ALG
SOL_ATM
SOL_BLUETOOTH
SOL_CAN_BASE
SOL_CAN_J1939
SOL_CAN_RAW
SOL_DCCP
SOL_DECNET
Expand All @@ -2073,6 +2096,10 @@ SO_EE_ORIGIN_NONE
SO_EE_ORIGIN_TIMESTAMPING
SO_EE_ORIGIN_TXSTATUS
SO_MARK
SO_J1939_ERRQUEUE
SO_J1939_FILTER
SO_J1939_PROMISC
SO_J1939_SEND_PRIO
SO_ORIGINAL_DST
SO_PASSCRED
SO_PASSSEC
Expand Down Expand Up @@ -2799,6 +2826,7 @@ ip_mreqn
ip_mreq_source
ipc_perm
itimerspec
j1939_filter
key_t
killpg
labs
Expand Down Expand Up @@ -2852,6 +2880,7 @@ msgqnum_t
msgrcv
msgsnd
msqid_ds
name_t
newlocale
nice
nl_item
Expand All @@ -2870,6 +2899,7 @@ openpty
packet_mreq
pause
personality
pgn_t
pipe2
popen
posix_fadvise
Expand Down Expand Up @@ -2902,6 +2932,7 @@ posix_spawnattr_t
posix_spawnp
ppoll
prctl
priority_t
pread64
preadv
pthread_attr_getguardsize
Expand Down
56 changes: 56 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ pub type Elf64_Section = u16;

// linux/can.h
pub type canid_t = u32;

// linux/can/j1939.h
pub type can_err_mask_t = u32;
pub type pgn_t = u32;
pub type priority_t = u8;
pub type name_t = u64;

pub type iconv_t = *mut ::c_void;

Expand Down Expand Up @@ -543,6 +548,16 @@ s! {
pub can_mask: canid_t,
}

// linux/can/j1939.h
pub struct j1939_filter {
pub name: name_t,
pub name_mask: name_t,
pub pgn: pgn_t,
pub pgn_mask: pgn_t,
pub addr: u8,
pub addr_mask: u8,
}

// linux/filter.h
pub struct sock_filter {
pub code: ::__u16,
Expand Down Expand Up @@ -3185,6 +3200,47 @@ 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;

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

pub const J1939_MAX_UNICAST_ADDR: ::c_uchar = 0xfd;
pub const J1939_IDLE_ADDR: ::c_uchar = 0xfe;
pub const J1939_NO_ADDR: ::c_uchar = 0xff;
pub const J1939_NO_NAME: ::c_ulong = 0;
pub const J1939_PGN_REQUEST: ::c_uint = 0x0ea00;
pub const J1939_PGN_ADDRESS_CLAIMED: ::c_uint = 0x0ee00;
pub const J1939_PGN_ADDRESS_COMMANDED: ::c_uint = 0x0fed8;
pub const J1939_PGN_PDU1_MAX: ::c_uint = 0x3ff00;
pub const J1939_PGN_MAX: ::c_uint = 0x3ffff;
pub const J1939_NO_PGN: ::c_uint = 0x40000;

pub const SO_J1939_FILTER: ::c_int = 1;
pub const SO_J1939_PROMISC: ::c_int = 2;
pub const SO_J1939_SEND_PRIO: ::c_int = 3;
pub const SO_J1939_ERRQUEUE: ::c_int = 4;

pub const SCM_J1939_DEST_ADDR: ::c_int = 1;
pub const SCM_J1939_DEST_NAME: ::c_int = 2;
pub const SCM_J1939_PRIO: ::c_int = 3;
pub const SCM_J1939_ERRQUEUE: ::c_int = 4;

pub const J1939_NLA_PAD: ::c_int = 0;
pub const J1939_NLA_BYTES_ACKED: ::c_int = 1;
pub const J1939_NLA_TOTAL_SIZE: ::c_int = 2;
pub const J1939_NLA_PGN: ::c_int = 3;
pub const J1939_NLA_SRC_NAME: ::c_int = 4;
pub const J1939_NLA_DEST_NAME: ::c_int = 5;
pub const J1939_NLA_SRC_ADDR: ::c_int = 6;
pub const J1939_NLA_DEST_ADDR: ::c_int = 7;

pub const J1939_EE_INFO_NONE: ::c_int = 0;
pub const J1939_EE_INFO_TX_ABORT: ::c_int = 1;
pub const J1939_EE_INFO_RX_RTS: ::c_int = 2;
pub const J1939_EE_INFO_RX_DPO: ::c_int = 3;
pub const J1939_EE_INFO_RX_ABORT: ::c_int = 4;

pub const J1939_FILTER_MAX: ::c_int = 512;

f! {
pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1)
Expand Down