Skip to content

File tree

9 files changed

+239
-186
lines changed

9 files changed

+239
-186
lines changed

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#[macro_use]
2424
mod macros;
25+
mod reorg;
2526

2627
cfg_if! {
2728
if #[cfg(feature = "rustc-dep-of-std")] {
@@ -31,6 +32,9 @@ cfg_if! {
3132

3233
pub use core::ffi::c_void;
3334

35+
#[allow(unused_imports)] // needed while the module is empty on some platforms
36+
pub use reorg::*;
37+
3438
cfg_if! {
3539
if #[cfg(windows)] {
3640
mod primitives;

src/new/linux_uapi/linux/can.rs

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//! Header: `uapi/linux/can.h`
2+
3+
#[path = "can/j1939.rs"]
4+
pub(crate) mod j1939;
5+
#[path = "can/raw.rs"]
6+
pub(crate) mod raw;
7+
8+
pub use j1939::*;
9+
pub use raw::*;
10+
11+
use crate::prelude::*;
12+
13+
pub const CAN_EFF_FLAG: canid_t = 0x80000000;
14+
pub const CAN_RTR_FLAG: canid_t = 0x40000000;
15+
pub const CAN_ERR_FLAG: canid_t = 0x20000000;
16+
17+
pub const CAN_SFF_MASK: canid_t = 0x000007FF;
18+
pub const CAN_EFF_MASK: canid_t = 0x1FFFFFFF;
19+
pub const CAN_ERR_MASK: canid_t = 0x1FFFFFFF;
20+
pub const CANXL_PRIO_MASK: crate::canid_t = CAN_SFF_MASK;
21+
22+
pub type canid_t = u32;
23+
24+
pub const CAN_SFF_ID_BITS: c_int = 11;
25+
pub const CAN_EFF_ID_BITS: c_int = 29;
26+
pub const CANXL_PRIO_BITS: c_int = CAN_SFF_ID_BITS;
27+
28+
pub type can_err_mask_t = u32;
29+
30+
pub const CAN_MAX_DLC: c_int = 8;
31+
pub const CAN_MAX_DLEN: usize = 8;
32+
33+
pub const CANFD_MAX_DLC: c_int = 15;
34+
pub const CANFD_MAX_DLEN: usize = 64;
35+
36+
pub const CANXL_MIN_DLC: c_int = 0;
37+
pub const CANXL_MAX_DLC: c_int = 2047;
38+
pub const CANXL_MAX_DLC_MASK: c_int = 0x07FF;
39+
pub const CANXL_MIN_DLEN: usize = 1;
40+
pub const CANXL_MAX_DLEN: usize = 2048;
41+
42+
s! {
43+
#[repr(align(8))]
44+
pub struct can_frame {
45+
pub can_id: canid_t,
46+
// FIXME(1.0): this field was renamed to `len` in Linux 5.11
47+
pub can_dlc: u8,
48+
__pad: u8,
49+
__res0: u8,
50+
pub len8_dlc: u8,
51+
pub data: [u8; CAN_MAX_DLEN],
52+
}
53+
}
54+
55+
pub const CANFD_BRS: c_int = 0x01;
56+
pub const CANFD_ESI: c_int = 0x02;
57+
pub const CANFD_FDF: c_int = 0x04;
58+
59+
s! {
60+
#[repr(align(8))]
61+
pub struct canfd_frame {
62+
pub can_id: canid_t,
63+
pub len: u8,
64+
pub flags: u8,
65+
__res0: u8,
66+
__res1: u8,
67+
pub data: [u8; CANFD_MAX_DLEN],
68+
}
69+
}
70+
71+
pub const CANXL_XLF: c_int = 0x80;
72+
pub const CANXL_SEC: c_int = 0x01;
73+
74+
s! {
75+
#[repr(align(8))]
76+
pub struct canxl_frame {
77+
pub prio: canid_t,
78+
pub flags: u8,
79+
pub sdt: u8,
80+
pub len: u16,
81+
pub af: u32,
82+
pub data: [u8; CANXL_MAX_DLEN],
83+
}
84+
}
85+
86+
pub const CAN_MTU: usize = size_of::<can_frame>();
87+
pub const CANFD_MTU: usize = size_of::<canfd_frame>();
88+
pub const CANXL_MTU: usize = size_of::<canxl_frame>();
89+
// FIXME(offset_of): use `core::mem::offset_of!` once that is available
90+
// https://github.com/rust-lang/rfcs/pull/3308
91+
// pub const CANXL_HDR_SIZE: usize = core::mem::offset_of!(canxl_frame, data);
92+
pub const CANXL_HDR_SIZE: usize = 12;
93+
pub const CANXL_MIN_MTU: usize = CANXL_HDR_SIZE + 64;
94+
pub const CANXL_MAX_MTU: usize = CANXL_MTU;
95+
96+
pub const CAN_RAW: c_int = 1;
97+
pub const CAN_BCM: c_int = 2;
98+
pub const CAN_TP16: c_int = 3;
99+
pub const CAN_TP20: c_int = 4;
100+
pub const CAN_MCNET: c_int = 5;
101+
pub const CAN_ISOTP: c_int = 6;
102+
pub const CAN_J1939: c_int = 7;
103+
pub const CAN_NPROTO: c_int = 8;
104+
105+
pub const SOL_CAN_BASE: c_int = 100;
106+
107+
s_no_extra_traits! {
108+
pub struct sockaddr_can {
109+
pub can_family: crate::sa_family_t,
110+
pub can_ifindex: c_int,
111+
pub can_addr: __c_anonymous_sockaddr_can_can_addr,
112+
}
113+
114+
pub union __c_anonymous_sockaddr_can_can_addr {
115+
pub tp: __c_anonymous_sockaddr_can_tp,
116+
pub j1939: __c_anonymous_sockaddr_can_j1939,
117+
}
118+
119+
pub struct __c_anonymous_sockaddr_can_tp {
120+
pub rx_id: canid_t,
121+
pub tx_id: canid_t,
122+
}
123+
124+
pub struct __c_anonymous_sockaddr_can_j1939 {
125+
pub name: u64,
126+
pub pgn: u32,
127+
pub addr: u8,
128+
}
129+
130+
pub struct can_filter {
131+
pub can_id: canid_t,
132+
pub can_mask: canid_t,
133+
}
134+
}
135+
136+
pub const CAN_INV_FILTER: canid_t = 0x20000000;

src/new/linux_uapi/linux/can/j1939.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//! `linux/can/j1939.h`
2+
3+
pub use crate::linux::can::*;
4+
5+
pub const J1939_MAX_UNICAST_ADDR: c_uchar = 0xfd;
6+
pub const J1939_IDLE_ADDR: c_uchar = 0xfe;
7+
pub const J1939_NO_ADDR: c_uchar = 0xff;
8+
pub const J1939_NO_NAME: c_ulong = 0;
9+
pub const J1939_PGN_REQUEST: c_uint = 0x0ea00;
10+
pub const J1939_PGN_ADDRESS_CLAIMED: c_uint = 0x0ee00;
11+
pub const J1939_PGN_ADDRESS_COMMANDED: c_uint = 0x0fed8;
12+
pub const J1939_PGN_PDU1_MAX: c_uint = 0x3ff00;
13+
pub const J1939_PGN_MAX: c_uint = 0x3ffff;
14+
pub const J1939_NO_PGN: c_uint = 0x40000;
15+
16+
pub type pgn_t = u32;
17+
pub type priority_t = u8;
18+
pub type name_t = u64;
19+
20+
pub const SOL_CAN_J1939: c_int = SOL_CAN_BASE + CAN_J1939;
21+
22+
// FIXME(cleanup): these could use c_enum if it can accept anonymous enums.
23+
24+
pub const SO_J1939_FILTER: c_int = 1;
25+
pub const SO_J1939_PROMISC: c_int = 2;
26+
pub const SO_J1939_SEND_PRIO: c_int = 3;
27+
pub const SO_J1939_ERRQUEUE: c_int = 4;
28+
29+
pub const SCM_J1939_DEST_ADDR: c_int = 1;
30+
pub const SCM_J1939_DEST_NAME: c_int = 2;
31+
pub const SCM_J1939_PRIO: c_int = 3;
32+
pub const SCM_J1939_ERRQUEUE: c_int = 4;
33+
34+
pub const J1939_NLA_PAD: c_int = 0;
35+
pub const J1939_NLA_BYTES_ACKED: c_int = 1;
36+
pub const J1939_NLA_TOTAL_SIZE: c_int = 2;
37+
pub const J1939_NLA_PGN: c_int = 3;
38+
pub const J1939_NLA_SRC_NAME: c_int = 4;
39+
pub const J1939_NLA_DEST_NAME: c_int = 5;
40+
pub const J1939_NLA_SRC_ADDR: c_int = 6;
41+
pub const J1939_NLA_DEST_ADDR: c_int = 7;
42+
43+
pub const J1939_EE_INFO_NONE: c_int = 0;
44+
pub const J1939_EE_INFO_TX_ABORT: c_int = 1;
45+
pub const J1939_EE_INFO_RX_RTS: c_int = 2;
46+
pub const J1939_EE_INFO_RX_DPO: c_int = 3;
47+
pub const J1939_EE_INFO_RX_ABORT: c_int = 4;
48+
49+
s! {
50+
pub struct j1939_filter {
51+
pub name: name_t,
52+
pub name_mask: name_t,
53+
pub pgn: pgn_t,
54+
pub pgn_mask: pgn_t,
55+
pub addr: u8,
56+
pub addr_mask: u8,
57+
}
58+
}
59+
60+
pub const J1939_FILTER_MAX: c_int = 512;

src/new/linux_uapi/linux/can/raw.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! `linux/can/raw.h`
2+
3+
pub use crate::linux::can::*;
4+
5+
pub const SOL_CAN_RAW: c_int = SOL_CAN_BASE + CAN_RAW;
6+
pub const CAN_RAW_FILTER_MAX: c_int = 512;
7+
8+
// FIXME(cleanup): use `c_enum!`, which needs to be adapted to allow omitting a type.
9+
pub const CAN_RAW_FILTER: c_int = 1;
10+
pub const CAN_RAW_ERR_FILTER: c_int = 2;
11+
pub const CAN_RAW_LOOPBACK: c_int = 3;
12+
pub const CAN_RAW_RECV_OWN_MSGS: c_int = 4;
13+
pub const CAN_RAW_FD_FRAMES: c_int = 5;
14+
pub const CAN_RAW_JOIN_FILTERS: c_int = 6;
15+
pub const CAN_RAW_XL_FRAMES: c_int = 7;

src/new/linux_uapi/linux/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! The `linux` directory within `include/uapi` in the Linux source tree.
2+
3+
pub(crate) mod can;
4+
pub use can::*;

src/new/linux_uapi/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//! This directory maps to `include/uapi` in the Linux source tree.
2+
3+
pub(crate) mod linux;
4+
pub use linux::*;

src/new/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! This module contains the future directory structure. If possible, new definitions should
2+
//! get added here.
3+
//!
4+
//! Eventually everything should be moved over, and we will move this directory to the top
5+
//! level in `src`.
6+
7+
cfg_if! {
8+
if #[cfg(target_os = "linux")] {
9+
mod linux_uapi;
10+
pub use linux_uapi::*;
11+
}
12+
}

0 commit comments

Comments
 (0)