libwifi 0.0.3
An 802.11 Frame Parsing and Generation library in C
frame.h
Go to the documentation of this file.
1/* Copyright 2021 The libwifi Authors
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
16#ifndef LIBWIFI_CORE_FRAME_H
17#define LIBWIFI_CORE_FRAME_H
18
19#include "../../core/misc/byteswap.h"
20
21#include <stdint.h>
22#include <sys/types.h>
23
24/* libwifi_frame Flags */
25#define LIBWIFI_FLAGS_FCS_PRESENT (1 << 0)
26#define LIBWIFI_FLAGS_IS_QOS (1 << 1)
27#define LIBWIFI_FLAGS_IS_ORDERED (1 << 2)
28
29/* Defined frame types and sub-types */
35};
44 // Reserved = 7,
52 // Reserved = 15,
53};
55 // Reserved = 0-3,
69};
71 // Reserved = 0-1,
81 // Reserved = 11-15,
82};
85 // Reserved = 1-3,
87 // Reserved = 4-7,
93 // Reserved = 13,
96};
100 // Reserved = 2-15
101};
102
103/*
104 * libwifi Representation of an 802.11 Frame Control Field's Flags.
105 */
106
108 unsigned int to_ds : 1;
109 unsigned int from_ds : 1;
110 unsigned int more_frags : 1;
111 unsigned int retry : 1;
112 unsigned int power_mgmt : 1;
113 unsigned int more_data : 1;
114 unsigned int protect : 1;
115 unsigned int ordered : 1;
116} __attribute__((packed));
117
118/*
119 * libwifi Representation of an 802.11 Frame Control Field.
120 */
122 unsigned int version : 2;
123 unsigned int type : 2;
124 unsigned int subtype : 4;
126} __attribute__((packed));
127
128/*
129 * libwifi Representation of an 802.11 Sequence Control Field.
130 */
132 unsigned int fragment_number : 4;
133 unsigned int sequence_number : 12;
134} __attribute__((packed));
135
136/*
137 * libwifi Representation of an 802.11 Data QoS Control Field.
138 *
139 * As the bits of the QoS Control Field can vary depending on other
140 * factors, generic bit names are used here.
141 */
143 unsigned int bit1 : 1;
144 unsigned int bit2 : 1;
145 unsigned int bit3 : 1;
146 unsigned int bit4 : 1;
147 unsigned int bit5 : 1;
148 unsigned int bit6 : 1;
149 unsigned int bit7 : 1;
150 unsigned int bit8 : 1;
151 unsigned int bit9 : 1;
152 unsigned int bit10 : 1;
153 unsigned int bit11 : 1;
154 unsigned int bit12 : 1;
155 unsigned int bit13 : 1;
156 unsigned int bit14 : 1;
157 unsigned int bit15 : 1;
158 unsigned int bit16 : 1;
159} __attribute__((packed));
160
161/*
162 * libwifi Representation of an ordered Management Frame header.
163 *
164 * ┌───────────────────────────┐
165 * │ Frame Control Field │ ── 2 Bytes
166 * ├───────────────────────────┤
167 * │ Duration │ ── 2 Bytes
168 * ├───────────────────────────┤
169 * │ Address 1 │ ── 6 Bytes
170 * ├───────────────────────────┤
171 * │ Address 2 │ ── 6 Bytes
172 * ├───────────────────────────┤
173 * │ Address 3 │ ── 6 Bytes
174 * ├───────────────────────────┤
175 * │ Sequence Control │ ── 2 Bytes
176 * ├───────────────────────────┤
177 * │ HT Control │ ── 4 Bytes
178 * └───────────────────────────┘
179 */
182 uint16_t duration;
183 unsigned char addr1[6];
184 unsigned char addr2[6];
185 unsigned char addr3[6];
187 uint32_t ht_control;
188} __attribute__((packed));
189
190/*
191 * libwifi Representation of an unordered Management Frame header.
192 *
193 * ┌───────────────────────────┐
194 * │ Frame Control Field │ ── 2 Bytes
195 * ├───────────────────────────┤
196 * │ Duration │ ── 2 Bytes
197 * ├───────────────────────────┤
198 * │ Address 1 │ ── 6 Bytes
199 * ├───────────────────────────┤
200 * │ Address 2 │ ── 6 Bytes
201 * ├───────────────────────────┤
202 * │ Address 3 │ ── 6 Bytes
203 * ├───────────────────────────┤
204 * │ Sequence Control │ ── 2 Bytes
205 * └───────────────────────────┘
206 */
209 uint16_t duration;
210 unsigned char addr1[6];
211 unsigned char addr2[6];
212 unsigned char addr3[6];
214} __attribute__((packed));
215
216/*
217 * libwifi Representation of a Control Frame header.
218 *
219 * ┌───────────────────────────┐
220 * │ Frame Control Field │ ── 2 Bytes
221 * ├───────────────────────────┤
222 * │ Duration │ ── 2 Bytes
223 * └───────────────────────────┘
224 */
227 uint16_t duration;
228} __attribute__((packed));
229
230/*
231 * libwifi Representation of a non-QoS Data Frame header.
232 *
233 * ┌───────────────────────────┐
234 * │ Frame Control Field │ ── 2 Bytes
235 * ├───────────────────────────┤
236 * │ Duration │ ── 2 Bytes
237 * ├───────────────────────────┤
238 * │ Address 1 │ ── 6 Bytes
239 * ├───────────────────────────┤
240 * │ Address 2 │ ── 6 Bytes
241 * ├───────────────────────────┤
242 * │ Address 3 │ ── 6 Bytes
243 * ├───────────────────────────┤
244 * │ Sequence Control │ ── 2 Bytes
245 * └───────────────────────────┘
246 */
249 uint16_t duration;
250 unsigned char addr1[6];
251 unsigned char addr2[6];
252 unsigned char addr3[6];
254} __attribute__((packed));
255
256/*
257 * libwifi Representation of a QoS Data Frame header.
258 *
259 * ┌───────────────────────────┐
260 * │ Frame Control Field │ ── 2 Bytes
261 * ├───────────────────────────┤
262 * │ Duration │ ── 2 Bytes
263 * ├───────────────────────────┤
264 * │ Address 1 │ ── 6 Bytes
265 * ├───────────────────────────┤
266 * │ Address 2 │ ── 6 Bytes
267 * ├───────────────────────────┤
268 * │ Address 3 │ ── 6 Bytes
269 * ├───────────────────────────┤
270 * │ Sequence Control │ ── 2 Bytes
271 * ├───────────────────────────┤
272 * │ QoS Control │ ── 2 Bytes
273 * └───────────────────────────┘
274 */
277 uint16_t duration;
278 unsigned char addr1[6];
279 unsigned char addr2[6];
280 unsigned char addr3[6];
283} __attribute__((packed));
284
285/*
286 * Union of all frame type headers for use with a libwifi_frame struct
287 */
295
296/*
297 * Union of all Management Frame headers
298 */
302};
303
304/*
305 * A libwifi_frame struct is used to represent any type of 802.11
306 * frame in libwifi.
307 */
309 uint16_t flags;
311 size_t len;
314 unsigned char *body;
315};
316
325int libwifi_get_wifi_frame(struct libwifi_frame *fi, const unsigned char *frame, size_t frame_len,
326 int radiotap);
327
334
335#endif /* LIBWIFI_CORE_FRAME_H */
void libwifi_free_wifi_frame(struct libwifi_frame *fi)
Free any dynamically allocated data inside a libwifi_frame.
Definition: frame.c:144
libwifi_mgmt_subtypes
Definition: frame.h:36
@ SUBTYPE_ACTION_NOACK
Definition: frame.h:51
@ SUBTYPE_ASSOC_REQ
Definition: frame.h:37
@ SUBTYPE_DEAUTH
Definition: frame.h:49
@ SUBTYPE_TIME_ADV
Definition: frame.h:43
@ SUBTYPE_AUTH
Definition: frame.h:48
@ SUBTYPE_PROBE_RESP
Definition: frame.h:42
@ SUBTYPE_DISASSOC
Definition: frame.h:47
@ SUBTYPE_ACTION
Definition: frame.h:50
@ SUBTYPE_PROBE_REQ
Definition: frame.h:41
@ SUBTYPE_BEACON
Definition: frame.h:45
@ SUBTYPE_REASSOC_RESP
Definition: frame.h:40
@ SUBTYPE_ATIM
Definition: frame.h:46
@ SUBTYPE_ASSOC_RESP
Definition: frame.h:38
@ SUBTYPE_REASSOC_REQ
Definition: frame.h:39
libwifi_data_subtypes
Definition: frame.h:83
@ SUBTYPE_DATA_QOS_CF_ACK_CF_POLL
Definition: frame.h:95
@ SUBTYPE_DATA_QOS_CF_POLL
Definition: frame.h:94
@ SUBTYPE_DATA_QOS_DATA_CF_POLL
Definition: frame.h:90
@ SUBTYPE_DATA_QOS_NULL
Definition: frame.h:92
@ SUBTYPE_DATA_QOS_DATA_CF_ACK
Definition: frame.h:89
@ SUBTYPE_DATA
Definition: frame.h:84
@ SUBTYPE_DATA_QOS_DATA
Definition: frame.h:88
@ SUBTYPE_DATA_NULL
Definition: frame.h:86
@ SUBTYPE_DATA_QOS_DATA_CF_ACK_CF_POLL
Definition: frame.h:91
libwifi_frame_type
Definition: frame.h:30
@ TYPE_EXTENSION
Definition: frame.h:34
@ TYPE_DATA
Definition: frame.h:33
@ TYPE_MANAGEMENT
Definition: frame.h:31
@ TYPE_CONTROL
Definition: frame.h:32
libwifi_extension_subtypes
Definition: frame.h:97
@ SUBTYPE_EXTENSION_DMG_BEACON
Definition: frame.h:98
@ SUBTYPE_EXTENSION_SIG_BEACON
Definition: frame.h:99
union libwifi_frame_header __attribute__
int libwifi_get_wifi_frame(struct libwifi_frame *fi, const unsigned char *frame, size_t frame_len, int radiotap)
Convert a sniffed 802.11 frame into a libwifi_frame.
Definition: frame.c:35
libwifi_control_subtypes
Definition: frame.h:54
@ SUBTYPE_BLOCK_ACK_REQ
Definition: frame.h:61
@ SUBTYPE_BLOCK_ACK
Definition: frame.h:62
@ SUBTYPE_ACK
Definition: frame.h:66
@ SUBTYPE_CF_EXTENSION
Definition: frame.h:59
@ SUBTYPE_PS_POLL
Definition: frame.h:63
@ SUBTYPE_RTS
Definition: frame.h:64
@ SUBTYPE_BEAMFORM_REPORT_POLL
Definition: frame.h:57
@ SUBTYPE_CTS
Definition: frame.h:65
@ SUBTYPE_WRAPPER
Definition: frame.h:60
@ SUBTYPE_VHT_NDP_ANNOUNCE
Definition: frame.h:58
@ SUBTYPE_TACK
Definition: frame.h:56
@ SUBTYPE_CF_END
Definition: frame.h:67
@ SUBTYPE_CF_END_CF_ACK
Definition: frame.h:68
libwifi_control_extension_subtypes
Definition: frame.h:70
@ SUBTYPE_CF_EXT_DMG_CTS
Definition: frame.h:75
@ SUBTYPE_CF_EXT_SSW_ACK
Definition: frame.h:80
@ SUBTYPE_CF_EXT_SSW_FEEDBACK
Definition: frame.h:79
@ SUBTYPE_CF_EXT_GRANT_ACK
Definition: frame.h:77
@ SUBTYPE_CF_EXT_GRANT
Definition: frame.h:74
@ SUBTYPE_CF_EXT_POLL
Definition: frame.h:72
@ SUBTYPE_CF_EXT_SSW
Definition: frame.h:78
@ SUBTYPE_CF_EXT_SPR
Definition: frame.h:73
@ SUBTYPE_CF_EXT_DMG_DTS
Definition: frame.h:76
struct libwifi_frame_ctrl frame_control
Definition: frame.h:226
unsigned char addr3[6]
Definition: frame.h:252
struct libwifi_seq_control seq_control
Definition: frame.h:253
struct libwifi_frame_ctrl frame_control
Definition: frame.h:248
unsigned char addr2[6]
Definition: frame.h:251
unsigned char addr1[6]
Definition: frame.h:250
struct libwifi_qos_control qos_control
Definition: frame.h:282
unsigned char addr3[6]
Definition: frame.h:280
struct libwifi_seq_control seq_control
Definition: frame.h:281
struct libwifi_frame_ctrl frame_control
Definition: frame.h:276
unsigned char addr2[6]
Definition: frame.h:279
unsigned char addr1[6]
Definition: frame.h:278
unsigned int power_mgmt
Definition: frame.h:112
unsigned int more_data
Definition: frame.h:113
unsigned int protect
Definition: frame.h:114
unsigned int to_ds
Definition: frame.h:108
unsigned int more_frags
Definition: frame.h:110
unsigned int retry
Definition: frame.h:111
unsigned int from_ds
Definition: frame.h:109
unsigned int ordered
Definition: frame.h:115
unsigned int type
Definition: frame.h:123
unsigned int version
Definition: frame.h:122
struct libwifi_frame_ctrl_flags flags
Definition: frame.h:125
unsigned int subtype
Definition: frame.h:124
union libwifi_frame_header header
Definition: frame.h:312
uint16_t flags
Definition: frame.h:309
unsigned char * body
Definition: frame.h:314
size_t len
Definition: frame.h:311
struct libwifi_frame_ctrl frame_control
Definition: frame.h:310
size_t header_len
Definition: frame.h:313
unsigned char addr3[6]
Definition: frame.h:185
struct libwifi_seq_control seq_control
Definition: frame.h:186
struct libwifi_frame_ctrl frame_control
Definition: frame.h:181
unsigned char addr2[6]
Definition: frame.h:184
unsigned char addr1[6]
Definition: frame.h:183
struct libwifi_seq_control seq_control
Definition: frame.h:213
struct libwifi_frame_ctrl frame_control
Definition: frame.h:208
unsigned int bit7
Definition: frame.h:149
unsigned int bit6
Definition: frame.h:148
unsigned int bit3
Definition: frame.h:145
unsigned int bit2
Definition: frame.h:144
unsigned int bit8
Definition: frame.h:150
unsigned int bit15
Definition: frame.h:157
unsigned int bit16
Definition: frame.h:158
unsigned int bit11
Definition: frame.h:153
unsigned int bit1
Definition: frame.h:143
unsigned int bit12
Definition: frame.h:154
unsigned int bit13
Definition: frame.h:155
unsigned int bit14
Definition: frame.h:156
unsigned int bit4
Definition: frame.h:146
unsigned int bit10
Definition: frame.h:152
unsigned int bit9
Definition: frame.h:151
unsigned int bit5
Definition: frame.h:147
unsigned int sequence_number
Definition: frame.h:133
unsigned int fragment_number
Definition: frame.h:132
struct libwifi_ctrl_frame_header ctrl
Definition: frame.h:291
struct libwifi_mgmt_unordered_frame_header mgmt_unordered
Definition: frame.h:290
struct libwifi_mgmt_ordered_frame_header mgmt_ordered
Definition: frame.h:289
struct libwifi_data_qos_frame_header data_qos
Definition: frame.h:293
struct libwifi_data_frame_header data
Definition: frame.h:292
struct libwifi_mgmt_ordered_frame_header ordered
Definition: frame.h:300
struct libwifi_mgmt_unordered_frame_header unordered
Definition: frame.h:301