Skip to content

File tree

8 files changed

+240
-189
lines changed

8 files changed

+240
-189
lines changed

src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#[macro_use]
3131
mod macros;
32+
mod reorg;
3233

3334
cfg_if! {
3435
if #[cfg(feature = "rustc-dep-of-std")] {
@@ -38,6 +39,9 @@ cfg_if! {
3839

3940
pub use core::ffi::c_void;
4041

42+
#[allow(unused_imports)] // needed while the module is empty on some platforms
43+
pub use reorg::*;
44+
4145
cfg_if! {
4246
if #[cfg(windows)] {
4347
mod primitives;

src/reorg/linux_uapi/linux/can.rs

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

+15
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/reorg/linux_uapi/linux/mod.rs

+4
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/reorg/linux_uapi/mod.rs

+4
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/reorg/mod.rs

+12
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)