summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-03-11 17:43:13 +0000
committerbors <bors@rust-lang.org>2022-03-11 17:43:13 +0000
commitbc9ea0bb6af452fd94b07de833aa6ee3ef839e5b (patch)
tree5afb5233f2cd12757a09add93b9f2df7ff6675df
parent70e49b693617ebc5f47b6d9b9c22d726e91200c4 (diff)
parent06a74e0308f7b6a07e8d92cc4f2c0a796d169e07 (diff)
downloadrust-libc-bc9ea0bb6af452fd94b07de833aa6ee3ef839e5b.tar.gz
Auto merge of #2706 - abalmos:add-j1939, r=Amanieu
Add SocketCan J1939 constants and structs Add SocketCan J1939 constants and structs. Blocking a PR to `nix` to wrap SocketCan's j1939 module.
-rw-r--r--libc-test/build.rs28
-rw-r--r--libc-test/semver/linux.txt31
-rw-r--r--src/unix/linux_like/linux/mod.rs56
3 files changed, 115 insertions, 0 deletions
diff --git a/libc-test/build.rs b/libc-test/build.rs
index 32537dc4f2..ceb3c0a313 100644
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -2921,6 +2921,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",
@@ -3046,6 +3048,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,
}
});
@@ -3107,6 +3114,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,
}
});
@@ -3141,6 +3151,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;
}
@@ -3237,6 +3253,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,
diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt
index 932b84e2a5..9eb096efe8 100644
--- a/libc-test/semver/linux.txt
+++ b/libc-test/semver/linux.txt
@@ -988,6 +988,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
@@ -1947,6 +1965,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
@@ -2049,6 +2071,7 @@ SOL_ALG
SOL_ATM
SOL_BLUETOOTH
SOL_CAN_BASE
+SOL_CAN_J1939
SOL_CAN_RAW
SOL_DCCP
SOL_DECNET
@@ -2075,6 +2098,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
@@ -2801,6 +2828,7 @@ ip_mreqn
ip_mreq_source
ipc_perm
itimerspec
+j1939_filter
key_t
killpg
labs
@@ -2854,6 +2882,7 @@ msgqnum_t
msgrcv
msgsnd
msqid_ds
+name_t
newlocale
nice
nl_item
@@ -2872,6 +2901,7 @@ openpty
packet_mreq
pause
personality
+pgn_t
pipe2
popen
posix_fadvise
@@ -2904,6 +2934,7 @@ posix_spawnattr_t
posix_spawnp
ppoll
prctl
+priority_t
pread64
preadv
pthread_attr_getguardsize
diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs
index 56e2082bb8..bbc76f5daa 100644
--- a/src/unix/linux_like/linux/mod.rs
+++ b/src/unix/linux_like/linux/mod.rs
@@ -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;
@@ -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,
@@ -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)