libc/new/linux_uapi/linux/
can.rs

1//! Header: `uapi/linux/can.h`
2
3pub(crate) mod j1939;
4pub(crate) mod raw;
5
6pub use j1939::*;
7pub use raw::*;
8
9use crate::prelude::*;
10
11pub const CAN_EFF_FLAG: canid_t = 0x80000000;
12pub const CAN_RTR_FLAG: canid_t = 0x40000000;
13pub const CAN_ERR_FLAG: canid_t = 0x20000000;
14
15pub const CAN_SFF_MASK: canid_t = 0x000007FF;
16pub const CAN_EFF_MASK: canid_t = 0x1FFFFFFF;
17pub const CAN_ERR_MASK: canid_t = 0x1FFFFFFF;
18pub const CANXL_PRIO_MASK: crate::canid_t = CAN_SFF_MASK;
19
20pub type canid_t = u32;
21
22pub const CAN_SFF_ID_BITS: c_int = 11;
23pub const CAN_EFF_ID_BITS: c_int = 29;
24pub const CANXL_PRIO_BITS: c_int = CAN_SFF_ID_BITS;
25
26pub type can_err_mask_t = u32;
27
28pub const CAN_MAX_DLC: c_int = 8;
29pub const CAN_MAX_DLEN: usize = 8;
30
31pub const CANFD_MAX_DLC: c_int = 15;
32pub const CANFD_MAX_DLEN: usize = 64;
33
34pub const CANXL_MIN_DLC: c_int = 0;
35pub const CANXL_MAX_DLC: c_int = 2047;
36pub const CANXL_MAX_DLC_MASK: c_int = 0x07FF;
37pub const CANXL_MIN_DLEN: usize = 1;
38pub const CANXL_MAX_DLEN: usize = 2048;
39
40#[repr(C)]
#[allow(deprecated)]
#[repr(align(8))]
pub struct can_frame {
    pub can_id: canid_t,
    pub can_dlc: u8,
    __pad: u8,
    __res0: u8,
    pub len8_dlc: u8,
    pub data: [u8; CAN_MAX_DLEN],
}
#[automatically_derived]
#[allow(deprecated)]
impl ::core::clone::Clone for can_frame {
    #[inline]
    fn clone(&self) -> can_frame {
        let _: ::core::clone::AssertParamIsClone<canid_t>;
        let _: ::core::clone::AssertParamIsClone<u8>;
        let _: ::core::clone::AssertParamIsClone<[u8; CAN_MAX_DLEN]>;
        *self
    }
}
#[automatically_derived]
#[allow(deprecated)]
impl ::core::marker::Copy for can_frame { }
#[automatically_derived]
#[allow(deprecated)]
impl ::core::fmt::Debug for can_frame {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        let names: &'static _ =
            &["can_id", "can_dlc", "__pad", "__res0", "len8_dlc", "data"];
        let values: &[&dyn ::core::fmt::Debug] =
            &[&self.can_id, &self.can_dlc, &self.__pad, &self.__res0,
                        &self.len8_dlc, &&self.data];
        ::core::fmt::Formatter::debug_struct_fields_finish(f, "can_frame",
            names, values)
    }
}s! {
41    #[repr(align(8))]
42    pub struct can_frame {
43        pub can_id: canid_t,
44        // FIXME(1.0): this field was renamed to `len` in Linux 5.11
45        pub can_dlc: u8,
46        __pad: u8,
47        __res0: u8,
48        pub len8_dlc: u8,
49        pub data: [u8; CAN_MAX_DLEN],
50    }
51}
52
53pub const CANFD_BRS: c_int = 0x01;
54pub const CANFD_ESI: c_int = 0x02;
55pub const CANFD_FDF: c_int = 0x04;
56
57#[repr(C)]
#[allow(deprecated)]
#[repr(align(8))]
pub struct canfd_frame {
    pub can_id: canid_t,
    pub len: u8,
    pub flags: u8,
    __res0: u8,
    __res1: u8,
    pub data: [u8; CANFD_MAX_DLEN],
}
#[automatically_derived]
#[allow(deprecated)]
impl ::core::clone::Clone for canfd_frame {
    #[inline]
    fn clone(&self) -> canfd_frame {
        let _: ::core::clone::AssertParamIsClone<canid_t>;
        let _: ::core::clone::AssertParamIsClone<u8>;
        let _: ::core::clone::AssertParamIsClone<[u8; CANFD_MAX_DLEN]>;
        *self
    }
}
#[automatically_derived]
#[allow(deprecated)]
impl ::core::marker::Copy for canfd_frame { }
#[automatically_derived]
#[allow(deprecated)]
impl ::core::fmt::Debug for canfd_frame {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        let names: &'static _ =
            &["can_id", "len", "flags", "__res0", "__res1", "data"];
        let values: &[&dyn ::core::fmt::Debug] =
            &[&self.can_id, &self.len, &self.flags, &self.__res0,
                        &self.__res1, &&self.data];
        ::core::fmt::Formatter::debug_struct_fields_finish(f, "canfd_frame",
            names, values)
    }
}s! {
58    #[repr(align(8))]
59    pub struct canfd_frame {
60        pub can_id: canid_t,
61        pub len: u8,
62        pub flags: u8,
63        __res0: u8,
64        __res1: u8,
65        pub data: [u8; CANFD_MAX_DLEN],
66    }
67}
68
69pub const CANXL_XLF: c_int = 0x80;
70pub const CANXL_SEC: c_int = 0x01;
71
72#[repr(C)]
#[allow(deprecated)]
#[repr(align(8))]
pub struct canxl_frame {
    pub prio: canid_t,
    pub flags: u8,
    pub sdt: u8,
    pub len: u16,
    pub af: u32,
    pub data: [u8; CANXL_MAX_DLEN],
}
#[automatically_derived]
#[allow(deprecated)]
impl ::core::clone::Clone for canxl_frame {
    #[inline]
    fn clone(&self) -> canxl_frame {
        let _: ::core::clone::AssertParamIsClone<canid_t>;
        let _: ::core::clone::AssertParamIsClone<u8>;
        let _: ::core::clone::AssertParamIsClone<u16>;
        let _: ::core::clone::AssertParamIsClone<u32>;
        let _: ::core::clone::AssertParamIsClone<[u8; CANXL_MAX_DLEN]>;
        *self
    }
}
#[automatically_derived]
#[allow(deprecated)]
impl ::core::marker::Copy for canxl_frame { }
#[automatically_derived]
#[allow(deprecated)]
impl ::core::fmt::Debug for canxl_frame {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        let names: &'static _ =
            &["prio", "flags", "sdt", "len", "af", "data"];
        let values: &[&dyn ::core::fmt::Debug] =
            &[&self.prio, &self.flags, &self.sdt, &self.len, &self.af,
                        &&self.data];
        ::core::fmt::Formatter::debug_struct_fields_finish(f, "canxl_frame",
            names, values)
    }
}s! {
73    #[repr(align(8))]
74    pub struct canxl_frame {
75        pub prio: canid_t,
76        pub flags: u8,
77        pub sdt: u8,
78        pub len: u16,
79        pub af: u32,
80        pub data: [u8; CANXL_MAX_DLEN],
81    }
82}
83
84pub const CAN_MTU: usize = size_of::<can_frame>();
85pub const CANFD_MTU: usize = size_of::<canfd_frame>();
86pub const CANXL_MTU: usize = size_of::<canxl_frame>();
87// FIXME(offset_of): use `core::mem::offset_of!` once that is available
88// https://github.com/rust-lang/rfcs/pull/3308
89// pub const CANXL_HDR_SIZE: usize = core::mem::offset_of!(canxl_frame, data);
90pub const CANXL_HDR_SIZE: usize = 12;
91pub const CANXL_MIN_MTU: usize = CANXL_HDR_SIZE + 64;
92pub const CANXL_MAX_MTU: usize = CANXL_MTU;
93
94pub const CAN_RAW: c_int = 1;
95pub const CAN_BCM: c_int = 2;
96pub const CAN_TP16: c_int = 3;
97pub const CAN_TP20: c_int = 4;
98pub const CAN_MCNET: c_int = 5;
99pub const CAN_ISOTP: c_int = 6;
100pub const CAN_J1939: c_int = 7;
101pub const CAN_NPROTO: c_int = 8;
102
103pub const SOL_CAN_BASE: c_int = 100;
104
105#[repr(C)]
pub struct sockaddr_can {
    pub can_family: crate::sa_family_t,
    pub can_ifindex: c_int,
    pub can_addr: __c_anonymous_sockaddr_can_can_addr,
}
#[automatically_derived]
impl ::core::clone::Clone for sockaddr_can {
    #[inline]
    fn clone(&self) -> sockaddr_can {
        let _: ::core::clone::AssertParamIsClone<crate::sa_family_t>;
        let _: ::core::clone::AssertParamIsClone<c_int>;
        let _:
                ::core::clone::AssertParamIsClone<__c_anonymous_sockaddr_can_can_addr>;
        *self
    }
}
#[automatically_derived]
impl ::core::marker::Copy for sockaddr_can { }
#[automatically_derived]
impl ::core::fmt::Debug for sockaddr_can {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f, "sockaddr_can",
            "can_family", &self.can_family, "can_ifindex", &self.can_ifindex,
            "can_addr", &&self.can_addr)
    }
}
#[repr(C)]
pub union __c_anonymous_sockaddr_can_can_addr {
    pub tp: __c_anonymous_sockaddr_can_tp,
    pub j1939: __c_anonymous_sockaddr_can_j1939,
}
#[automatically_derived]
impl ::core::clone::Clone for __c_anonymous_sockaddr_can_can_addr {
    #[inline]
    fn clone(&self) -> __c_anonymous_sockaddr_can_can_addr {
        let _: ::core::clone::AssertParamIsCopy<Self>;
        *self
    }
}
#[automatically_derived]
impl ::core::marker::Copy for __c_anonymous_sockaddr_can_can_addr { }
impl ::core::fmt::Debug for __c_anonymous_sockaddr_can_can_addr {
    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
        f.debug_struct("__c_anonymous_sockaddr_can_can_addr").finish_non_exhaustive()
    }
}s_no_extra_traits! {
106    pub struct sockaddr_can {
107        pub can_family: crate::sa_family_t,
108        pub can_ifindex: c_int,
109        pub can_addr: __c_anonymous_sockaddr_can_can_addr,
110    }
111
112    pub union __c_anonymous_sockaddr_can_can_addr {
113        pub tp: __c_anonymous_sockaddr_can_tp,
114        pub j1939: __c_anonymous_sockaddr_can_j1939,
115    }
116}
117
118#[automatically_derived]
#[allow(deprecated)]
impl ::core::clone::Clone for can_filter {
    #[inline]
    fn clone(&self) -> can_filter {
        let _: ::core::clone::AssertParamIsClone<canid_t>;
        *self
    }
}
#[automatically_derived]
#[allow(deprecated)]
impl ::core::marker::Copy for can_filter { }
#[automatically_derived]
#[allow(deprecated)]
impl ::core::fmt::Debug for can_filter {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "can_filter",
            "can_id", &self.can_id, "can_mask", &&self.can_mask)
    }
}s! {
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
136pub const CAN_INV_FILTER: canid_t = 0x20000000;