-
Notifications
You must be signed in to change notification settings - Fork 1
/
ieee802_11.h
369 lines (315 loc) · 9.34 KB
/
ieee802_11.h
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/* @(#) $Header: /tcpdump/master/tcpdump/ieee802_11.h,v 1.9 2003/07/22 17:36:57 guy Exp $ (LBL) */
/*
* Copyright (c) 2001
* Fortress Technologies
* Charlie Lenahan ( [email protected] )
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorseeeeee
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <stdint.h>
#ifndef __PACMAP_80211_H__
#define __PACMAP_80211_H__
#define BROADCAST (u_char*)"\xFF\xFF\xFF\xFF\xFF\xFF"
#define IEEE80211_LLC_SNAP \
"\x08\x00\x00\x00\xDD\xDD\xDD\xDD\xDD\xDD\xBB\xBB\xBB\xBB\xBB\xBB" \
"\xCC\xCC\xCC\xCC\xCC\xCC\xE0\x32\xAA\xAA\x03\x00\x00\x00\x08\x00"
/* Lengths of 802.11 header components. */
#define IEEE802_11_FC_LEN 2
#define IEEE802_11_DUR_LEN 2
#define IEEE802_11_DA_LEN 6
#define IEEE802_11_SA_LEN 6
#define IEEE802_11_BSSID_LEN 6
#define IEEE802_11_RA_LEN 6
#define IEEE802_11_TA_LEN 6
#define IEEE802_11_SEQ_LEN 2
#define IEEE802_11_IV_LEN 3
#define IEEE802_11_KID_LEN 1
#define IEEE802_11_QOS_PARMS_LEN 2
/* Frame check sequence length. */
#define IEEE802_11_FCS_LEN 4
/* Lengths of beacon components. */
#define IEEE802_11_TSTAMP_LEN 8
#define IEEE802_11_BCNINT_LEN 2
#define IEEE802_11_CAPINFO_LEN 2
#define IEEE802_11_LISTENINT_LEN 2
#define IEEE802_11_AID_LEN 2
#define IEEE802_11_STATUS_LEN 2
#define IEEE802_11_REASON_LEN 2
/* Length of previous AP in reassocation frame */
#define IEEE802_11_AP_LEN 6
#define T_MGMT 0x0 /* management */
#define T_CTRL 0x1 /* control */
#define T_DATA 0x2 /* data */
#define T_RESV 0x3 /* reserved */
#define ST_ASSOC_REQUEST 0x0
#define ST_ASSOC_RESPONSE 0x1
#define ST_REASSOC_REQUEST 0x2
#define ST_REASSOC_RESPONSE 0x3
#define ST_PROBE_REQUEST 0x4
#define ST_PROBE_RESPONSE 0x5
/* RESERVED 0x6 */
/* RESERVED 0x7 */
#define ST_BEACON 0x8
#define ST_ATIM 0x9
#define ST_DISASSOC 0xA
#define ST_AUTH 0xB
#define ST_DEAUTH 0xC
/* RESERVED 0xD */
/* RESERVED 0xE */
/* RESERVED 0xF */
#define CTRL_PS_POLL 0xA
#define CTRL_RTS 0xB
#define CTRL_CTS 0xC
#define CTRL_ACK 0xD4
#define CTRL_CF_END 0xE
#define CTRL_END_ACK 0xF
#define DATA_DATA 0x08
#define DATA_DATA_CF_ACK 0x1
#define DATA_DATA_CF_POLL 0x2
#define DATA_DATA_CF_ACK_POLL 0x3
#define DATA_NODATA 0x4
#define DATA_NODATA_CF_ACK 0x5
#define DATA_NODATA_CF_POLL 0x6
#define DATA_NODATA_CF_ACK_POLL 0x7
#define DATA_QOS_DATA 0x8
/*
* Bits in the frame control field.
*/
#define FC_VERSION(fc) ((fc) & 0x3)
#define FC_TYPE(fc) (((fc) >> 2) & 0x3)
#define FC_SUBTYPE(fc) (((fc) >> 4) & 0xf)
#define FC_TO_DS(fc) ((fc) & 0x0100) >> 8
#define FC_FROM_DS(fc) ((fc) & 0x0200) >> 9
#define FC_MORE_FLAG(fc) ((fc) & 0x0400) >> 10
#define FC_RETRY(fc) ((fc) & 0x0800) >> 11
#define FC_POWER_MGMT(fc) ((fc) & 0x1000) >> 12
#define FC_MORE_DATA(fc) ((fc) & 0x2000) >> 13
#define FC_WEP(fc) ((fc) & 0x4000) >> 14
#define FC_ORDER(fc) ((fc) & 0x8000) >> 15
#define FC_TO_DS_BIT 0x0100
#define FC_FROM_DS_BIT 0x0200
#define FC_MGMT_ASSOC_REQUEST ST_ASSOC_REQUEST << 4 | T_MGMT << 2
#define FC_MGMT_ASSOC_RESPONSE ST_ASSOC_RESPONSE << 4 | T_MGMT << 2
#define FC_MGMT_REASSOC_REQUEST ST_REASSOC_REQUEST << 4 | T_MGMT << 2
#define FC_MGMT_REASSOC_RESPONSE ST_REASSOC_RESPONSE << 4 | T_MGMT << 2
#define FC_MGMT_PROBE_REQUEST ST_PROBE_REQUEST << 4 | T_MGMT << 2
#define FC_MGMT_PROBE_RESPONSE ST_PROBE_RESPONSE << 4 | T_MGMT << 2
#define FC_MGMT_BEACON ST_BEACON << 4 | T_MGMT << 2
#define FC_MGMT_ATIM ST_ATIM << 4 | T_MGMT << 2
#define FC_MGMT_DISASSOC ST_DISASSOC << 4 | T_MGMT << 2
#define FC_MGMT_AUTH ST_AUTH << 4 | T_MGMT << 2
#define FC_MGMT_DEAUTH ST_DEAUTH << 4 | T_MGMT << 2
#define FC_CTRL_ACK CTRL_ACK << 4 | T_CTRL << 2
#define FC_DATA_DATA DATA_DATA << 4 | T_DATA << 2
#define FC_DATA_NODATA DATA_NODATA << 4 | T_DATA << 2
struct mgmt_header_t {
u_int16_t fc;
u_int16_t duration;
u_int8_t da[6];
u_int8_t sa[6];
u_int8_t bssid[6];
u_int16_t seq_ctrl;
}__attribute__((packed));
u_int16_t qos_params;
#define MGMT_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
IEEE802_11_DA_LEN+IEEE802_11_SA_LEN+\
IEEE802_11_BSSID_LEN+IEEE802_11_SEQ_LEN)
#define NO_CHANNEL 0
#define NO_ESSID ""
#define NO_CAPABILITY 0
#define CAPABILITY_ESS(cap) ((cap) & 0x0001)
#define CAPABILITY_IBSS(cap) ((cap) & 0x0002)
#define CAPABILITY_CFP(cap) ((cap) & 0x0004)
#define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008)
#define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010)
#define ELEMENT_ID_SSID 0
#define ELEMENT_ID_SUPPORTED_RATES 1
#define ELEMENT_ID_FH 2
#define ELEMENT_ID_CHANNEL 3
#define ELEMENT_ID_CF 4
#define ELEMENT_ID_TIM 5
#define ELEMENT_ID_IBSS 6
#define ELEMENT_ID_EDCA 12
#define ELEMENT_ID_CHALLENGE 16
#define ELEMENT_ID_CHANSWITCHANN 37
#define ELEMENT_ID_EXT_SUPPORTED_RATES 50
#define ELEMENT_ID_CHALLENGE_TEXT 16
#define ELEMENT_PACMAP_RSSI 0xDD
#define ELEMENT_PACMAP_SEQ 0xDE
#define AUTH_ALGO_OPEN_SYSTEM 0x0000
#define AUTH_ALGO_SHARED_KEY 0x0001
enum {
IEEE80211_AUTH_OPEN_REQUEST = 1,
IEEE80211_AUTH_OPEN_RESPONSE = 2,
};
/*
* Reason codes
*
* Unlisted codes are reserved
*/
enum {
IEEE80211_STATUS_SUCCESS = 0,
IEEE80211_STATUS_UNSPECIFIED = 1,
};
struct ssid_t {
u_int8_t element_id;
u_int8_t length;
u_char ssid[33]; /* 32 + 1 for null */
};
struct rates_t {
u_int8_t element_id;
u_int8_t length;
u_int8_t rate[8];
};
struct challenge_t {
u_int8_t element_id;
u_int8_t length;
u_int8_t text[254]; /* 1-253 + 1 for null */
};
struct fh_t {
u_int8_t element_id;
u_int8_t length;
u_int16_t dwell_time;
u_int8_t hop_set;
u_int8_t hop_pattern;
u_int8_t hop_index;
};
struct ds_t {
u_int8_t element_id;
u_int8_t length;
u_int8_t channel;
};
struct cf_t {
u_int8_t element_id;
u_int8_t length;
u_int8_t count;
u_int8_t period;
u_int16_t max_duration;
u_int16_t dur_remaing;
};
struct tim_t {
u_int8_t element_id;
u_int8_t length;
u_int8_t count;
u_int8_t period;
u_int8_t bitmap_control;
u_int8_t bitmap[251];
};
struct channel_switch_t {
u_int8_t element_id;
u_int8_t length;
u_int8_t mode;
u_int8_t new_channel;
u_int8_t count;
};
struct beacon_body_t {
u_int8_t timestamp[8];
u_int16_t beacon_interval;
u_int16_t capability_info;
};
struct mgmt_body_t {
u_int64_t timestamp;
u_int16_t beacon_interval;
/* u_int16_t listen_interval;
u_int16_t status_code;
u_int16_t aid;
u_char ap[6];
u_int16_t reason_code;
u_int16_t auth_alg;
u_int16_t auth_trans_seq_num;
struct challenge_t challenge;*/
u_int16_t capability_info;
struct ssid_t ssid;
struct rates_t rates;
struct ds_t ds;
struct cf_t cf;
struct fh_t fh;
struct tim_t tim;
struct channel_switch_t channel_switch;
u_int8_t pacmap_rssi;
int pacmap_seq;
int channel;
};
struct ctrl_rts_t {
u_int16_t fc;
u_int16_t duration;
u_int8_t ra[6];
u_int8_t ta[6];
u_int8_t fcs[4];
};
#define CTRL_RTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
IEEE802_11_RA_LEN+IEEE802_11_TA_LEN)
struct ctrl_cts_t {
u_int16_t fc;
u_int16_t duration;
u_int8_t ra[6];
u_int8_t fcs[4];
};
#define CTRL_CTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
struct ctrl_ack_t {
u_int16_t fc;
u_int16_t duration;
u_int8_t ra[6];
u_int8_t fcs[4];
};
#define CTRL_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
struct ctrl_ps_poll_t {
u_int16_t fc;
u_int16_t aid;
u_int8_t bssid[6];
u_int8_t ta[6];
u_int8_t fcs[4];
};
#define CTRL_PS_POLL_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_AID_LEN+\
IEEE802_11_BSSID_LEN+IEEE802_11_TA_LEN)
struct ctrl_end_t {
u_int16_t fc;
u_int16_t duration;
u_int8_t ra[6];
u_int8_t bssid[6];
u_int8_t fcs[4];
};
#define CTRL_END_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
struct ctrl_end_ack_t {
u_int16_t fc;
u_int16_t duration;
u_int8_t ra[6];
u_int8_t bssid[6];
u_int8_t fcs[4];
};
#define CTRL_END_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
#define IV_IV(iv) ((iv) & 0xFFFFFF)
#define IV_PAD(iv) (((iv) >> 24) & 0x3F)
#define IV_KEYID(iv) (((iv) >> 30) & 0x03)
#define BEACON_INTERVAL 0x064
#define BEACON_INTERVAL_TIMER (BEACON_INTERVAL*1000)
#define RATE_NUM 12
#define RATE_1M 1000000
#define RATE_2M 2000000
#define RATE_5_5M 5500000
#define RATE_11M 11000000
#define RATE_6M 6000000
#define RATE_9M 9000000
#define RATE_12M 12000000
#define RATE_18M 18000000
#define RATE_24M 24000000
#define RATE_36M 36000000
#define RATE_48M 48000000
#define RATE_54M 54000000
#endif /* __PACMAP_80211_H__ */