awdl_frame_parser/tlvs/data_path/
ieee80211_cntr_tlv.rs

1use scroll::{
2    ctx::{MeasureWith, TryFromCtx, TryIntoCtx},
3    Endian,
4};
5use tlv_rs::raw_tlv::RawTLV;
6
7use crate::tlvs::{AWDLTLVType, AwdlTlv};
8
9pub type IEEE80211TLV<'a> = RawTLV<'a, u8, u8>;
10
11#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
12/// This TLV just encapsulates an IEEE802.11 TLV.
13///
14/// In reality, this just contains a VHT capabilities TLV, but for future compatibility we'll just make it do this now.
15/// Maybe there will be a parser for IEEE802.11 frames, relying on bin-utils and tlv-rs in the future(foreshadowing).
16pub struct IEEE80211ContainerTLV<'a> {
17    pub tlv: IEEE80211TLV<'a>,
18}
19impl AwdlTlv for IEEE80211ContainerTLV<'_> {
20    const TLV_TYPE: AWDLTLVType = AWDLTLVType::IEEE80211Container;
21}
22impl<'a> MeasureWith<()> for IEEE80211ContainerTLV<'a> {
23    fn measure_with(&self, _ctx: &()) -> usize {
24        2 + self.tlv.slice.len()
25    }
26}
27impl<'a> TryFromCtx<'a> for IEEE80211ContainerTLV<'a> {
28    type Error = scroll::Error;
29    fn try_from_ctx(from: &'a [u8], _ctx: ()) -> Result<(Self, usize), Self::Error> {
30        IEEE80211TLV::try_from_ctx(from, Endian::Little).map(|(tlv, offset)| (Self { tlv }, offset))
31    }
32}
33impl<'a> TryIntoCtx for IEEE80211ContainerTLV<'a> {
34    type Error = scroll::Error;
35    fn try_into_ctx(self, buf: &mut [u8], _ctx: ()) -> Result<usize, Self::Error> {
36        IEEE80211TLV::try_into_ctx(self.tlv, buf, Endian::Little)
37    }
38}