diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-07-11 00:25:35 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-07-11 00:25:35 +0200 |
| commit | 069a57fcf85c725d000e03163716edb4ae3922ca (patch) | |
| tree | e0b672124cdfc0c8d4a58896d887496f5dec7d1d /src/structs.rs | |
| parent | e560415fde967483573d42f628e52501768584e0 (diff) | |
async ioctls working.
Diffstat (limited to 'src/structs.rs')
| -rw-r--r-- | src/structs.rs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/structs.rs b/src/structs.rs new file mode 100644 index 000000000..fe5e89a37 --- /dev/null +++ b/src/structs.rs | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | #[derive(Clone, Copy)] | ||
| 2 | #[repr(C)] | ||
| 3 | pub struct SdpcmHeader { | ||
| 4 | pub len: u16, | ||
| 5 | pub len_inv: u16, | ||
| 6 | /// Rx/Tx sequence number | ||
| 7 | pub sequence: u8, | ||
| 8 | /// 4 MSB Channel number, 4 LSB arbitrary flag | ||
| 9 | pub channel_and_flags: u8, | ||
| 10 | /// Length of next data frame, reserved for Tx | ||
| 11 | pub next_length: u8, | ||
| 12 | /// Data offset | ||
| 13 | pub header_length: u8, | ||
| 14 | /// Flow control bits, reserved for Tx | ||
| 15 | pub wireless_flow_control: u8, | ||
| 16 | /// Maximum Sequence number allowed by firmware for Tx | ||
| 17 | pub bus_data_credit: u8, | ||
| 18 | /// Reserved | ||
| 19 | pub reserved: [u8; 2], | ||
| 20 | } | ||
| 21 | |||
| 22 | #[derive(Clone, Copy)] | ||
| 23 | #[repr(C)] | ||
| 24 | pub struct CdcHeader { | ||
| 25 | pub cmd: u32, | ||
| 26 | pub out_len: u16, | ||
| 27 | pub in_len: u16, | ||
| 28 | pub flags: u16, | ||
| 29 | pub id: u16, | ||
| 30 | pub status: u32, | ||
| 31 | } | ||
| 32 | |||
| 33 | #[derive(Clone, Copy)] | ||
| 34 | #[repr(C)] | ||
| 35 | pub struct BdcHeader { | ||
| 36 | pub flags: u8, | ||
| 37 | /// 802.1d Priority (low 3 bits) | ||
| 38 | pub priority: u8, | ||
| 39 | pub flags2: u8, | ||
| 40 | /// Offset from end of BDC header to packet data, in 4-uint8_t words. Leaves room for optional headers. | ||
| 41 | pub data_offset: u8, | ||
| 42 | } | ||
| 43 | |||
| 44 | #[derive(Clone, Copy)] | ||
| 45 | #[repr(C)] | ||
| 46 | pub struct DownloadHeader { | ||
| 47 | pub flag: u16, | ||
| 48 | pub dload_type: u16, | ||
| 49 | pub len: u32, | ||
| 50 | pub crc: u32, | ||
| 51 | } | ||
| 52 | |||
| 53 | macro_rules! impl_bytes { | ||
| 54 | ($t:ident) => { | ||
| 55 | impl $t { | ||
| 56 | pub const SIZE: usize = core::mem::size_of::<Self>(); | ||
| 57 | |||
| 58 | pub fn to_bytes(&self) -> [u8; Self::SIZE] { | ||
| 59 | unsafe { core::mem::transmute(*self) } | ||
| 60 | } | ||
| 61 | |||
| 62 | pub fn from_bytes(bytes: &[u8; Self::SIZE]) -> Self { | ||
| 63 | unsafe { core::mem::transmute(*bytes) } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | }; | ||
| 67 | } | ||
| 68 | impl_bytes!(SdpcmHeader); | ||
| 69 | impl_bytes!(CdcHeader); | ||
| 70 | impl_bytes!(BdcHeader); | ||
| 71 | impl_bytes!(DownloadHeader); | ||
