awdl_frame_parser/tlvs/data_path/data_path_state_tlv/
misc.rs1use macro_bits::{bit, bitfield, check_bit};
2use scroll::{
3 ctx::{TryFromCtx, TryIntoCtx},
4 Endian, Pread, Pwrite,
5};
6
7#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
8pub struct DataPathStats {
9 pub msec_since_activation: u32,
10 pub aw_seq_counter: u32,
11 pub pay_update_coutner: u32,
12}
13impl TryFromCtx<'_> for DataPathStats {
14 type Error = scroll::Error;
15 fn try_from_ctx(from: &'_ [u8], _ctx: ()) -> Result<(Self, usize), Self::Error> {
16 let mut offset = 0;
17 Ok((
18 Self {
19 msec_since_activation: from.gread_with(&mut offset, Endian::Little)?,
20 aw_seq_counter: from.gread_with(&mut offset, Endian::Little)?,
21 pay_update_coutner: from.gread_with(&mut offset, Endian::Little)?,
22 },
23 offset,
24 ))
25 }
26}
27impl TryIntoCtx for DataPathStats {
28 type Error = scroll::Error;
29 fn try_into_ctx(self, buf: &mut [u8], _ctx: ()) -> Result<usize, Self::Error> {
30 let mut offset = 0;
31 buf.gwrite_with(self.msec_since_activation, &mut offset, Endian::Little)?;
32 buf.gwrite_with(self.aw_seq_counter, &mut offset, Endian::Little)?;
33 buf.gwrite_with(self.pay_update_coutner, &mut offset, Endian::Little)?;
34 Ok(offset)
35 }
36}
37bitfield! {
38 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
39 pub struct ChannelMap: u16 {
40 pub channel_6: bool => bit!(0),
41 pub channel_44: bool => bit!(1),
42 pub channel_149: bool => bit!(2)
43 }
44}
45#[derive(Clone, Copy, Debug, PartialEq, Eq)]
46pub enum DataPathChannel {
47 SingleChannel { channel: u8 },
48 ChannelMap(ChannelMap),
49}
50impl DataPathChannel {
51 pub fn from_u16(value: u16) -> Self {
52 if !check_bit!(value, bit!(0)) {
53 Self::SingleChannel {
54 channel: value as u8,
55 }
56 } else {
57 Self::ChannelMap(ChannelMap::from_bits(value))
58 }
59 }
60 pub fn as_u16(&self) -> u16 {
61 match *self {
62 DataPathChannel::SingleChannel { channel } => channel as u16,
63 DataPathChannel::ChannelMap(channel_map) => channel_map.into_bits(),
64 }
65 }
66}
67bitfield! {
68 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
69 pub struct UnicastOptions: u32 {
70 pub start_airplay: bool => bit!(1),
71 pub cache_request: bool => bit!(3),
72 pub jumpstart_dfs_proxy: bool => bit!(5),
73 pub airplay_on_dfs_channel: bool => bit!(6),
74 pub start_sidecar: bool => bit!(9),
75 pub sidecar_bg_request: bool => bit!(10),
76 pub sidecar_fg_request: bool => bit!(11),
77 pub stop_sidecar: bool => bit!(12),
78 pub start_multi_peer_steering: bool => bit!(13),
79 pub start_real_time_mode: bool => bit!(14),
80 pub stop_real_time_mode: bool => bit!(15),
81 pub start_airplay_recovery: bool => bit!(16),
82 pub start_ht_mode: bool => bit!(17),
83 pub stop_ht_mode: bool => bit!(18),
84 pub stop_airplay: bool => bit!(19),
85 pub failed_multi_peer_steering: bool => bit!(20),
86 pub unknown: u8 => bit!(21, 22, 23),
87 pub start_rtg_ensemble: bool => bit!(24),
88 pub stop_rtg_ensemble: bool => bit!(25),
89 pub start_airplay_in_rtg_mode: bool => bit!(26),
90 pub stop_airplay_in_rtg_mode: bool => bit!(27),
91 pub start_sidecar_in_rtg_mode: bool => bit!(28),
92 pub stop_sidecar_in_rtg_mode: bool => bit!(29),
93 pub start_remote_camera: bool => bit!(30),
94 pub stop_remote_camera: bool => bit!(31)
95 }
96}