name: "Pumpkin Entrance" panel_display_name: "East Area" panels { name: "JACK" path: "Panels/Pumpkin Room/pumpkin_2" clue: "jack" answer: "lantern" } ed' href='https://code.fourisland.com/libwifi/atom/src/libwifi/core/frame/frame.h?h=main' type='application/atom+xml'/>
about summary refs log tree commit diff stats
path: root/src/libwifi/core/frame/frame.h
blob: 5d44dbeeea2b77852dd1a026aa9491cd02148cbd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/* Copyright 2021 The libwifi Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef LIBWIFI_CORE_FRAME_H
#define LIBWIFI_CORE_FRAME_H

#include "../../core/misc/byteswap.h"

#include <stdint.h>
#include <sys/types.h>

/* libwifi_frame Flags */
#define LIBWIFI_FLAGS_FCS_PRESENT (1 << 0)
#define LIBWIFI_FLAGS_IS_QOS (1 << 1)
#define LIBWIFI_FLAGS_IS_ORDERED (1 << 2)

/* Defined frame types and sub-types */
enum libwifi_frame_type {
    TYPE_MANAGEMENT = 0,
    TYPE_CONTROL = 1,
    TYPE_DATA = 2,
    TYPE_EXTENSION = 3,
};
enum libwifi_mgmt_subtypes {
    SUBTYPE_ASSOC_REQ = 0,
    SUBTYPE_ASSOC_RESP = 1,
    SUBTYPE_REASSOC_REQ = 2,
    SUBTYPE_REASSOC_RESP = 3,
    SUBTYPE_PROBE_REQ = 4,
    SUBTYPE_PROBE_RESP = 5,
    SUBTYPE_TIME_ADV = 6,
    // Reserved = 7,
    SUBTYPE_BEACON = 8,
    SUBTYPE_ATIM = 9,
    SUBTYPE_DISASSOC = 10,
    SUBTYPE_AUTH = 11,
    SUBTYPE_DEAUTH = 12,
    SUBTYPE_ACTION = 13,
    SUBTYPE_ACTION_NOACK = 14,
    // Reserved = 15,
};
enum libwifi_control_subtypes {
    // Reserved = 0-3,
    SUBTYPE_TACK = 3,
    SUBTYPE_BEAMFORM_REPORT_POLL = 4,
    SUBTYPE_VHT_NDP_ANNOUNCE = 5,
    SUBTYPE_CF_EXTENSION = 6,
    SUBTYPE_WRAPPER = 7,
    SUBTYPE_BLOCK_ACK_REQ = 8,
    SUBTYPE_BLOCK_ACK = 9,
    SUBTYPE_PS_POLL = 10,
    SUBTYPE_RTS = 11,
    SUBTYPE_CTS = 12,
    SUBTYPE_ACK = 13,
    SUBTYPE_CF_END = 14,
    SUBTYPE_CF_END_CF_ACK = 15,
};
enum libwifi_control_extension_subtypes {
    // Reserved = 0-1,
    SUBTYPE_CF_EXT_POLL = 2,
    SUBTYPE_CF_EXT_SPR = 3,
    SUBTYPE_CF_EXT_GRANT = 4,
    SUBTYPE_CF_EXT_DMG_CTS = 5,
    SUBTYPE_CF_EXT_DMG_DTS = 6,
    SUBTYPE_CF_EXT_GRANT_ACK = 7,
    SUBTYPE_CF_EXT_SSW = 8,
    SUBTYPE_CF_EXT_SSW_FEEDBACK = 9,
    SUBTYPE_CF_EXT_SSW_ACK = 10,
    // Reserved = 11-15,
};
enum libwifi_data_subtypes {
    SUBTYPE_DATA = 0,
    // Reserved = 1-3,
    SUBTYPE_DATA_NULL = 4,
    // Reserved = 4-7,
    SUBTYPE_DATA_QOS_DATA = 8,
    SUBTYPE_DATA_QOS_DATA_CF_ACK = 9,
    SUBTYPE_DATA_QOS_DATA_CF_POLL = 10,
    SUBTYPE_DATA_QOS_DATA_CF_ACK_CF_POLL = 11,
    SUBTYPE_DATA_QOS_NULL = 12,
    // Reserved = 13,
    SUBTYPE_DATA_QOS_CF_POLL = 14,
    SUBTYPE_DATA_QOS_CF_ACK_CF_POLL = 15,
};
enum libwifi_extension_subtypes {
    SUBTYPE_EXTENSION_DMG_BEACON = 0,
    SUBTYPE_EXTENSION_SIG_BEACON = 1,
    // Reserved = 2-15
};

/*
 * libwifi Representation of an 802.11 Frame Control Field's Flags.
 */

struct libwifi_frame_ctrl_flags {
    unsigned int to_ds : 1;
    unsigned int from_ds : 1;
    unsigned int more_frags : 1;
    unsigned int retry : 1;
    unsigned int power_mgmt : 1;
    unsigned int more_data : 1;
    unsigned int protect : 1;
    unsigned int ordered : 1;
} __attribute__((packed));

/*
 * libwifi Representation of an 802.11 Frame Control Field.
 */
struct libwifi_frame_ctrl {
    unsigned int version : 2;
    unsigned int type : 2;
    unsigned int subtype : 4;
    struct libwifi_frame_ctrl_flags flags;
} __attribute__((packed));

/*
 * libwifi Representation of an 802.11 Sequence Control Field.
 */
struct libwifi_seq_control {
    unsigned int fragment_number : 4;
    unsigned int sequence_number : 12;
} __attribute__((packed));

/*
 * libwifi Representation of an 802.11 Data QoS Control Field.
 *
 * As the bits of the QoS Control Field can vary depending on other
 * factors, generic bit names are used here.
 */
struct libwifi_qos_control {
    unsigned int bit1 : 1;
    unsigned int bit2 : 1;
    unsigned int bit3 : 1;
    unsigned int bit4 : 1;
    unsigned int bit5 : 1;
    unsigned int bit6 : 1;
    unsigned int bit7 : 1;
    unsigned int bit8 : 1;
    unsigned int bit9 : 1;
    unsigned int bit10 : 1;
    unsigned int bit11 : 1;
    unsigned int bit12 : 1;
    unsigned int bit13 : 1;
    unsigned int bit14 : 1;
    unsigned int bit15 : 1;
    unsigned int bit16 : 1;
} __attribute__((packed));

/*
 * libwifi Representation of an ordered Management Frame header.
 *
 * ┌───────────────────────────┐
 * │    Frame Control Field    │  ── 2 Bytes
 * ├───────────────────────────┤
 * │          Duration         │  ── 2 Bytes
 * ├───────────────────────────┤
 * │          Address 1        │  ── 6 Bytes
 * ├───────────────────────────┤
 * │          Address 2        │  ── 6 Bytes
 * ├───────────────────────────┤
 * │          Address 3        │  ── 6 Bytes
 * ├───────────────────────────┤
 * │      Sequence Control     │  ── 2 Bytes
 * ├───────────────────────────┤
 * │         HT Control        │  ── 4 Bytes
 * └───────────────────────────┘
 */
struct libwifi_mgmt_ordered_frame_header {
    struct libwifi_frame_ctrl frame_control;
    uint16_t duration;
    unsigned char addr1[6];
    unsigned char addr2[6];
    unsigned char addr3[6];
    struct libwifi_seq_control seq_control;
    uint32_t ht_control;
} __attribute__((packed));

/*
 * libwifi Representation of an unordered Management Frame header.
 *
 * ┌───────────────────────────┐
 * │    Frame Control Field    │  ── 2 Bytes
 * ├───────────────────────────┤
 * │          Duration         │  ── 2 Bytes
 * ├───────────────────────────┤
 * │          Address 1        │  ── 6 Bytes
 * ├───────────────────────────┤
 * │          Address 2        │  ── 6 Bytes
 * ├───────────────────────────┤
 * │          Address 3        │  ── 6 Bytes
 * ├───────────────────────────┤
 * │      Sequence Control     │  ── 2 Bytes
 * └───────────────────────────┘
 */
struct libwifi_mgmt_unordered_frame_header {
    struct libwifi_frame_ctrl frame_control;
    uint16_t duration;
    unsigned char addr1[6];
    unsigned char addr2[6];
    unsigned char addr3[6];
    struct libwifi_seq_control seq_control;
} __attribute__((packed));

/*
 * libwifi Representation of a Control Frame header.
 *
 * ┌───────────────────────────┐
 * │    Frame Control Field    │  ── 2 Bytes
 * ├───────────────────────────┤
 * │          Duration         │  ── 2 Bytes
 * └───────────────────────────┘
 */
struct libwifi_ctrl_frame_header {
    struct libwifi_frame_ctrl frame_control;
    uint16_t duration;
} __attribute__((packed));

/*
 * libwifi Representation of a non-QoS Data Frame header.
 *
 * ┌───────────────────────────┐
 * │    Frame Control Field    │  ── 2 Bytes
 * ├───────────────────────────┤
 * │          Duration         │  ── 2 Bytes
 * ├───────────────────────────┤
 * │          Address 1        │  ── 6 Bytes
 * ├───────────────────────────┤
 * │          Address 2        │  ── 6 Bytes
 * ├───────────────────────────┤
 * │          Address 3        │  ── 6 Bytes
 * ├───────────────────────────┤
 * │      Sequence Control     │  ── 2 Bytes
 * └───────────────────────────┘
 */
struct libwifi_data_frame_header {
    struct libwifi_frame_ctrl frame_control;
    uint16_t duration;
    unsigned char addr1[6];
    unsigned char addr2[6];
    unsigned char addr3[6];
    struct libwifi_seq_control seq_control;
} __attribute__((packed));

/*
 * libwifi Representation of a QoS Data Frame header.
 *
 * ┌───────────────────────────┐
 * │    Frame Control Field    │  ── 2 Bytes
 * ├───────────────────────────┤
 * │          Duration         │  ── 2 Bytes
 * ├───────────────────────────┤
 * │          Address 1        │  ── 6 Bytes
 * ├───────────────────────────┤
 * │          Address 2        │  ── 6 Bytes
 * ├───────────────────────────┤
 * │          Address 3        │  ── 6 Bytes
 * ├───────────────────────────┤
 * │      Sequence Control     │  ── 2 Bytes
 * ├───────────────────────────┤
 * │         QoS Control       │  ── 2 Bytes
 * └───────────────────────────┘
 */
struct libwifi_data_qos_frame_header {
    struct libwifi_frame_ctrl frame_control;
    uint16_t duration;
    unsigned char addr1[6];
    unsigned char addr2[6];
    unsigned char addr3[6];
    struct libwifi_seq_control seq_control;
    struct libwifi_qos_control qos_control;
} __attribute__((packed));

/*
 * Union of all frame type headers for use with a libwifi_frame struct
 */
union libwifi_frame_header {
    struct libwifi_mgmt_ordered_frame_header mgmt_ordered;
    struct libwifi_mgmt_unordered_frame_header mgmt_unordered;
    struct libwifi_ctrl_frame_header ctrl;
    struct libwifi_data_frame_header data;
    struct libwifi_data_qos_frame_header data_qos;
};

/*
 * Union of all Management Frame headers
 */
union libwifi_mgmt_frame_header {
    struct libwifi_mgmt_ordered_frame_header ordered;
    struct libwifi_mgmt_unordered_frame_header unordered;
};

/*
 * A libwifi_frame struct is used to represent any type of 802.11
 * frame in libwifi.
 */
struct libwifi_frame {
    uint16_t flags;
    struct libwifi_frame_ctrl frame_control;
    size_t len;
    union libwifi_frame_header header;
    size_t header_len;
    unsigned char *body;
};

/**
 * Convert a sniffed 802.11 frame into a libwifi_frame.
 *
 * @param fi A libwifi_frame struct
 * @param frame An 802.11 frame
 * @param frame_len Length of the sniffed 802.11 frame
 * @return
 */
int libwifi_get_wifi_frame(struct libwifi_frame *fi, const unsigned char *frame, size_t frame_len,
                           int radiotap);

/**
 * Free any dynamically allocated data inside a libwifi_frame.
 *
 * @param fi A libwifi_frame struct
 */
void libwifi_free_wifi_frame(struct libwifi_frame *fi);

#endif /* LIBWIFI_CORE_FRAME_H */