libwifi/frame/data/
data.rs1use libwifi_macros::AddressHeader;
2
3use crate::frame::components::*;
4
5use super::{DataFrame, EapolKey, NullDataFrame};
6
7#[derive(Clone, Debug, AddressHeader)]
8pub struct Data {
9 pub header: DataHeader,
10 pub eapol_key: Option<EapolKey>,
11 pub data: Vec<u8>,
12}
13
14impl Data {
15 pub fn encode(&self) -> Vec<u8> {
16 let mut bytes = Vec::new();
17
18 bytes.extend_from_slice(&self.header.encode());
20
21 let eapol_llc_header: [u8; 8] = [0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e];
22
23 if let Some(eapol_key) = &self.eapol_key {
25 bytes.extend(eapol_llc_header);
26 bytes.extend(eapol_key.encode().unwrap()); }
28
29 bytes.extend_from_slice(&self.data);
31
32 bytes
33 }
34}
35
36impl DataFrame for Data {
37 fn header(&self) -> &DataHeader {
38 &self.header
39 }
40 fn eapol_key(&self) -> &Option<EapolKey> {
41 &self.eapol_key
42 }
43 fn data(&self) -> &Vec<u8> {
44 &self.data
45 }
46}
47
48#[derive(Clone, Debug, AddressHeader)]
49pub struct DataCfAck {
50 pub header: DataHeader,
51 pub eapol_key: Option<EapolKey>,
52 pub data: Vec<u8>,
53}
54
55impl DataFrame for DataCfAck {
56 fn header(&self) -> &DataHeader {
57 &self.header
58 }
59 fn eapol_key(&self) -> &Option<EapolKey> {
60 &self.eapol_key
61 }
62 fn data(&self) -> &Vec<u8> {
63 &self.data
64 }
65}
66
67#[derive(Clone, Debug, AddressHeader)]
68pub struct DataCfPoll {
69 pub header: DataHeader,
70 pub eapol_key: Option<EapolKey>,
71 pub data: Vec<u8>,
72}
73
74impl DataFrame for DataCfPoll {
75 fn header(&self) -> &DataHeader {
76 &self.header
77 }
78 fn eapol_key(&self) -> &Option<EapolKey> {
79 &self.eapol_key
80 }
81 fn data(&self) -> &Vec<u8> {
82 &self.data
83 }
84}
85
86#[derive(Clone, Debug, AddressHeader)]
87pub struct DataCfAckCfPoll {
88 pub header: DataHeader,
89 pub eapol_key: Option<EapolKey>,
90 pub data: Vec<u8>,
91}
92
93impl DataFrame for DataCfAckCfPoll {
94 fn header(&self) -> &DataHeader {
95 &self.header
96 }
97 fn eapol_key(&self) -> &Option<EapolKey> {
98 &self.eapol_key
99 }
100 fn data(&self) -> &Vec<u8> {
101 &self.data
102 }
103}
104
105#[derive(Clone, Debug, AddressHeader)]
106pub struct CfAck {
107 pub header: DataHeader,
108}
109
110impl NullDataFrame for CfAck {
111 fn header(&self) -> &DataHeader {
112 &self.header
113 }
114}
115
116#[derive(Clone, Debug, AddressHeader)]
117pub struct CfPoll {
118 pub header: DataHeader,
119}
120
121impl NullDataFrame for CfPoll {
122 fn header(&self) -> &DataHeader {
123 &self.header
124 }
125}
126
127#[derive(Clone, Debug, AddressHeader)]
128pub struct CfAckCfPoll {
129 pub header: DataHeader,
130}
131
132impl NullDataFrame for CfAckCfPoll {
133 fn header(&self) -> &DataHeader {
134 &self.header
135 }
136}
137
138#[derive(Clone, Debug, AddressHeader)]
139pub struct NullData {
140 pub header: DataHeader,
141}
142
143impl NullDataFrame for NullData {
144 fn header(&self) -> &DataHeader {
145 &self.header
146 }
147}