Skip to content

Commit bc9ea0b

Browse files
committed
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.
2 parents 70e49b6 + 06a74e0 commit bc9ea0b

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

libc-test/build.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,6 +2921,8 @@ fn test_linux(target: &str) {
29212921
"asm/mman.h",
29222922
"linux/can.h",
29232923
"linux/can/raw.h",
2924+
// FIXME: requires kernel headers >= 5.4.1.
2925+
[!musl]: "linux/can/j1939.h",
29242926
"linux/dccp.h",
29252927
"linux/errqueue.h",
29262928
"linux/falloc.h",
@@ -3046,6 +3048,11 @@ fn test_linux(target: &str) {
30463048
// For internal use only, to define architecture specific ioctl constants with a libc specific type.
30473049
"Ioctl" => true,
30483050

3051+
// FIXME: requires >= 5.4.1 kernel headers
3052+
"pgn_t" if musl => true,
3053+
"priority_t" if musl => true,
3054+
"name_t" if musl => true,
3055+
30493056
_ => false,
30503057
}
30513058
});
@@ -3107,6 +3114,9 @@ fn test_linux(target: &str) {
31073114
// Might differ between kernel versions
31083115
"open_how" => true,
31093116

3117+
// FIXME: requires >= 5.4.1 kernel headers
3118+
"j1939_filter" if musl => true,
3119+
31103120
_ => false,
31113121
}
31123122
});
@@ -3141,6 +3151,12 @@ fn test_linux(target: &str) {
31413151
|| name.starts_with("TCP_")
31423152
|| name.starts_with("UINPUT_")
31433153
|| name.starts_with("VMADDR_")
3154+
// FIXME: Requires >= 5.4.1 kernel headers
3155+
|| name.starts_with("J1939")
3156+
// FIXME: Requires >= 5.4.1 kernel headers
3157+
|| name.starts_with("SO_J1939")
3158+
// FIXME: Requires >= 5.4.1 kernel headers
3159+
|| name.starts_with("SCM_J1939")
31443160
{
31453161
return true;
31463162
}
@@ -3237,6 +3253,18 @@ fn test_linux(target: &str) {
32373253
| "CAN_RAW_FILTER_MAX"
32383254
| "CAN_NPROTO" => true,
32393255

3256+
// FIXME: Requires recent kernel headers (5.15)
3257+
| "J1939_NLA_TOTAL_SIZE"
3258+
| "J1939_NLA_PGN"
3259+
| "J1939_NLA_SRC_NAME"
3260+
| "J1939_NLA_DEST_NAME"
3261+
| "J1939_NLA_SRC_ADDR"
3262+
| "J1939_NLA_DEST_ADDR"
3263+
| "J1939_EE_INFO_RX_RTS"
3264+
| "J1939_EE_INFO_RX_DPO"
3265+
| "J1939_EE_INFO_RX_ABORT"
3266+
| "SOL_CAN_J1939" => true,
3267+
32403268
// FIXME: Requires recent kernel headers (5.8):
32413269
"STATX_MNT_ID" => true,
32423270

libc-test/semver/linux.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,24 @@ ITIMER_PROF
988988
ITIMER_REAL
989989
ITIMER_VIRTUAL
990990
IUTF8
991+
J1939_IDLE_ADDR
992+
J1939_MAX_UNICAST_ADDR
993+
J1939_NLA_BYTES_ACKED
994+
J1939_NLA_DEST_ADDR
995+
J1939_NLA_DEST_NAME
996+
J1939_NLA_PAD
997+
J1939_NLA_PGN
998+
J1939_NLA_SRC_ADDR
999+
J1939_NLA_SRC_NAME
1000+
J1939_NLA_TOTAL_SIZE
1001+
J1939_NO_ADDR
1002+
J1939_NO_NAME
1003+
J1939_NO_PGN
1004+
J1939_PGN_ADDRESS_CLAIMED
1005+
J1939_PGN_ADDRESS_COMMANDED
1006+
J1939_PGN_MAX
1007+
J1939_PGN_PDU1_MAX
1008+
J1939_PGN_REQUEST
9911009
KEYCTL_ASSUME_AUTHORITY
9921010
KEYCTL_CHOWN
9931011
KEYCTL_CLEAR
@@ -1947,6 +1965,10 @@ SCHED_RESET_ON_FORK
19471965
SCHED_RR
19481966
SCM_CREDENTIALS
19491967
SCM_RIGHTS
1968+
SCM_J1939_DEST_ADDR
1969+
SCM_J1939_DEST_NAME
1970+
SCM_J1939_ERRQUEUE
1971+
SCM_J1939_PRIO
19501972
SCM_TIMESTAMP
19511973
SCM_TIMESTAMPING
19521974
SECCOMP_FILTER_FLAG_LOG
@@ -2049,6 +2071,7 @@ SOL_ALG
20492071
SOL_ATM
20502072
SOL_BLUETOOTH
20512073
SOL_CAN_BASE
2074+
SOL_CAN_J1939
20522075
SOL_CAN_RAW
20532076
SOL_DCCP
20542077
SOL_DECNET
@@ -2075,6 +2098,10 @@ SO_EE_ORIGIN_NONE
20752098
SO_EE_ORIGIN_TIMESTAMPING
20762099
SO_EE_ORIGIN_TXSTATUS
20772100
SO_MARK
2101+
SO_J1939_ERRQUEUE
2102+
SO_J1939_FILTER
2103+
SO_J1939_PROMISC
2104+
SO_J1939_SEND_PRIO
20782105
SO_ORIGINAL_DST
20792106
SO_PASSCRED
20802107
SO_PASSSEC
@@ -2801,6 +2828,7 @@ ip_mreqn
28012828
ip_mreq_source
28022829
ipc_perm
28032830
itimerspec
2831+
j1939_filter
28042832
key_t
28052833
killpg
28062834
labs
@@ -2854,6 +2882,7 @@ msgqnum_t
28542882
msgrcv
28552883
msgsnd
28562884
msqid_ds
2885+
name_t
28572886
newlocale
28582887
nice
28592888
nl_item
@@ -2872,6 +2901,7 @@ openpty
28722901
packet_mreq
28732902
pause
28742903
personality
2904+
pgn_t
28752905
pipe2
28762906
popen
28772907
posix_fadvise
@@ -2904,6 +2934,7 @@ posix_spawnattr_t
29042934
posix_spawnp
29052935
ppoll
29062936
prctl
2937+
priority_t
29072938
pread64
29082939
preadv
29092940
pthread_attr_getguardsize

src/unix/linux_like/linux/mod.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ pub type Elf64_Section = u16;
3939

4040
// linux/can.h
4141
pub type canid_t = u32;
42+
43+
// linux/can/j1939.h
4244
pub type can_err_mask_t = u32;
45+
pub type pgn_t = u32;
46+
pub type priority_t = u8;
47+
pub type name_t = u64;
4348

4449
pub type iconv_t = *mut ::c_void;
4550

@@ -543,6 +548,16 @@ s! {
543548
pub can_mask: canid_t,
544549
}
545550

551+
// linux/can/j1939.h
552+
pub struct j1939_filter {
553+
pub name: name_t,
554+
pub name_mask: name_t,
555+
pub pgn: pgn_t,
556+
pub pgn_mask: pgn_t,
557+
pub addr: u8,
558+
pub addr_mask: u8,
559+
}
560+
546561
// linux/filter.h
547562
pub struct sock_filter {
548563
pub code: ::__u16,
@@ -3185,6 +3200,47 @@ pub const CAN_RAW_RECV_OWN_MSGS: ::c_int = 4;
31853200
pub const CAN_RAW_FD_FRAMES: ::c_int = 5;
31863201
pub const CAN_RAW_JOIN_FILTERS: ::c_int = 6;
31873202

3203+
// linux/can/j1939.h
3204+
pub const SOL_CAN_J1939: ::c_int = SOL_CAN_BASE + CAN_J1939;
3205+
3206+
pub const J1939_MAX_UNICAST_ADDR: ::c_uchar = 0xfd;
3207+
pub const J1939_IDLE_ADDR: ::c_uchar = 0xfe;
3208+
pub const J1939_NO_ADDR: ::c_uchar = 0xff;
3209+
pub const J1939_NO_NAME: ::c_ulong = 0;
3210+
pub const J1939_PGN_REQUEST: ::c_uint = 0x0ea00;
3211+
pub const J1939_PGN_ADDRESS_CLAIMED: ::c_uint = 0x0ee00;
3212+
pub const J1939_PGN_ADDRESS_COMMANDED: ::c_uint = 0x0fed8;
3213+
pub const J1939_PGN_PDU1_MAX: ::c_uint = 0x3ff00;
3214+
pub const J1939_PGN_MAX: ::c_uint = 0x3ffff;
3215+
pub const J1939_NO_PGN: ::c_uint = 0x40000;
3216+
3217+
pub const SO_J1939_FILTER: ::c_int = 1;
3218+
pub const SO_J1939_PROMISC: ::c_int = 2;
3219+
pub const SO_J1939_SEND_PRIO: ::c_int = 3;
3220+
pub const SO_J1939_ERRQUEUE: ::c_int = 4;
3221+
3222+
pub const SCM_J1939_DEST_ADDR: ::c_int = 1;
3223+
pub const SCM_J1939_DEST_NAME: ::c_int = 2;
3224+
pub const SCM_J1939_PRIO: ::c_int = 3;
3225+
pub const SCM_J1939_ERRQUEUE: ::c_int = 4;
3226+
3227+
pub const J1939_NLA_PAD: ::c_int = 0;
3228+
pub const J1939_NLA_BYTES_ACKED: ::c_int = 1;
3229+
pub const J1939_NLA_TOTAL_SIZE: ::c_int = 2;
3230+
pub const J1939_NLA_PGN: ::c_int = 3;
3231+
pub const J1939_NLA_SRC_NAME: ::c_int = 4;
3232+
pub const J1939_NLA_DEST_NAME: ::c_int = 5;
3233+
pub const J1939_NLA_SRC_ADDR: ::c_int = 6;
3234+
pub const J1939_NLA_DEST_ADDR: ::c_int = 7;
3235+
3236+
pub const J1939_EE_INFO_NONE: ::c_int = 0;
3237+
pub const J1939_EE_INFO_TX_ABORT: ::c_int = 1;
3238+
pub const J1939_EE_INFO_RX_RTS: ::c_int = 2;
3239+
pub const J1939_EE_INFO_RX_DPO: ::c_int = 3;
3240+
pub const J1939_EE_INFO_RX_ABORT: ::c_int = 4;
3241+
3242+
pub const J1939_FILTER_MAX: ::c_int = 512;
3243+
31883244
f! {
31893245
pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
31903246
return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1)

0 commit comments

Comments
 (0)