Click
Loading...
Searching...
No Matches
wifi.h
1/*
2 * <clicknet/wifi.h> - contains the definitions for 802.11 frames.
3 * It was originally taken from freebsd and modified for click use.
4 * John Bicket
5 */
6
7/* $NetBSD: if_ieee80211.h,v 1.5 2000/07/21 04:47:40 onoe Exp $ */
8/* $FreeBSD: src/sys/net/if_ieee80211.h,v 1.3.2.3 2001/07/04 00:12:38 brooks Exp $ */
9
10#ifndef _CLICKNET_WIFI_H_
11#define _CLICKNET_WIFI_H_
12
13
14#define WIFI_EXTRA_MAGIC 0x7492001
15
16enum {
17 WIFI_EXTRA_TX = (1<<0), /* packet transmission */
18 WIFI_EXTRA_TX_FAIL = (1<<1), /* transmission failed */
19 WIFI_EXTRA_TX_USED_ALT_RATE = (1<<2), /* used alternate bitrate */
20 WIFI_EXTRA_RX_ERR = (1<<3), /* failed crc check */
21 WIFI_EXTRA_RX_MORE = (1<<4), /* first part of a fragmented skb */
22 WIFI_EXTRA_NO_SEQ = (1<<5),
23 WIFI_EXTRA_NO_TXF = (1<<6),
24 WIFI_EXTRA_DO_RTS_CTS = (1<<7),
25 WIFI_EXTRA_DO_CTS = (1<<8),
26 WIFI_EXTRA_TX_NOACK = (1<<9)
27};
28
29
30
31struct click_wifi_extra {
32 uint32_t magic;
33 uint32_t flags;
34
35 uint8_t rssi;
36 uint8_t silence;
37 uint8_t power;
38 uint8_t pad;
39
40 uint8_t rate; /* bitrate in Mbps*2 */
41 uint8_t rate1; /* bitrate in Mbps*2 */
42 uint8_t rate2; /* bitrate in Mbps*2 */
43 uint8_t rate3; /* bitrate in Mbps*2 */
44
45 uint8_t max_tries;
46 uint8_t max_tries1;
47 uint8_t max_tries2;
48 uint8_t max_tries3;
49
50 uint8_t virt_col;
51 uint8_t retries;
52 uint16_t len;
53} CLICK_SIZE_PACKED_ATTRIBUTE;
54
55
56/*
57 * generic definitions for IEEE 802.11 frames
58 */
59#define WIFI_ADDR_LEN 6
60
61struct click_wifi {
62 uint8_t i_fc[2];
63 uint16_t i_dur;
64 uint8_t i_addr1[WIFI_ADDR_LEN];
65 uint8_t i_addr2[WIFI_ADDR_LEN];
66 uint8_t i_addr3[WIFI_ADDR_LEN];
67 uint16_t i_seq;
68} CLICK_SIZE_PACKED_ATTRIBUTE;
69
70#define WIFI_FC0_VERSION_MASK 0x03
71#define WIFI_FC0_VERSION_0 0x00
72#define WIFI_FC0_TYPE_MASK 0x0c
73#define WIFI_FC0_TYPE_MGT 0x00
74#define WIFI_FC0_TYPE_CTL 0x04
75#define WIFI_FC0_TYPE_DATA 0x08
76
77#define WIFI_FC0_SUBTYPE_MASK 0xf0
78/* for TYPE_MGT */
79#define WIFI_FC0_SUBTYPE_ASSOC_REQ 0x00
80#define WIFI_FC0_SUBTYPE_ASSOC_RESP 0x10
81#define WIFI_FC0_SUBTYPE_REASSOC_REQ 0x20
82#define WIFI_FC0_SUBTYPE_REASSOC_RESP 0x30
83#define WIFI_FC0_SUBTYPE_PROBE_REQ 0x40
84#define WIFI_FC0_SUBTYPE_PROBE_RESP 0x50
85#define WIFI_FC0_SUBTYPE_BEACON 0x80
86#define WIFI_FC0_SUBTYPE_ATIM 0x90
87#define WIFI_FC0_SUBTYPE_DISASSOC 0xa0
88#define WIFI_FC0_SUBTYPE_AUTH 0xb0
89#define WIFI_FC0_SUBTYPE_DEAUTH 0xc0
90/* for TYPE_CTL */
91#define WIFI_FC0_SUBTYPE_PS_POLL 0xa0
92#define WIFI_FC0_SUBTYPE_RTS 0xb0
93#define WIFI_FC0_SUBTYPE_CTS 0xc0
94#define WIFI_FC0_SUBTYPE_ACK 0xd0
95#define WIFI_FC0_SUBTYPE_CF_END 0xe0
96#define WIFI_FC0_SUBTYPE_CF_END_ACK 0xf0
97/* for TYPE_DATA (bit combination) */
98#define WIFI_FC0_SUBTYPE_DATA 0x00
99#define WIFI_FC0_SUBTYPE_CF_ACK 0x10
100#define WIFI_FC0_SUBTYPE_CF_POLL 0x20
101#define WIFI_FC0_SUBTYPE_CF_ACPL 0x30
102#define WIFI_FC0_SUBTYPE_NODATA 0x40
103#define WIFI_FC0_SUBTYPE_CFACK 0x50
104#define WIFI_FC0_SUBTYPE_CFPOLL 0x60
105#define WIFI_FC0_SUBTYPE_CF_ACK_CF_ACK 0x70
106#define WIFI_FC0_SUBTYPE_QOS 0x80
107#define WIFI_FC0_SUBTYPE_QOS_NULL 0xc0
108
109
110#define WIFI_FC1_DIR_MASK 0x03
111#define WIFI_FC1_DIR_NODS 0x00 /* STA->STA */
112#define WIFI_FC1_DIR_TODS 0x01 /* STA->AP */
113#define WIFI_FC1_DIR_FROMDS 0x02 /* AP ->STA */
114#define WIFI_FC1_DIR_DSTODS 0x03 /* AP ->AP */
115
116#define WIFI_FC1_MORE_FRAG 0x04
117#define WIFI_FC1_RETRY 0x08
118#define WIFI_FC1_PWR_MGT 0x10
119#define WIFI_FC1_MORE_DATA 0x20
120#define WIFI_FC1_WEP 0x40
121#define WIFI_FC1_ORDER 0x80
122
123#define WIFI_NWID_LEN 32
124
125/*
126 * BEACON management packets
127 *
128 * octect timestamp[8]
129 * octect beacon interval[2]
130 * octect capability information[2]
131 * information element
132 * octect elemid
133 * octect length
134 * octect information[length]
135 */
136typedef uint8_t * wifi_mgt_beacon_t;
137
138#define WIFI_BEACON_INTERVAL(beacon) \
139 (beacon[8] + (beacon[9] << 8))
140#define WIFI_BEACON_CAPABILITY(beacon) \
141 (beacon[10] + (beacon[11] << 8))
142
143#define WIFI_CAPINFO_ESS 0x01
144#define WIFI_CAPINFO_IBSS 0x02
145#define WIFI_CAPINFO_CF_POLLABLE 0x04
146#define WIFI_CAPINFO_CF_POLLREQ 0x08
147#define WIFI_CAPINFO_PRIVACY 0x10
148
149
150
151#define WIFI_MAX_RETRIES 11
152
153#define WIFI_QOS_HAS_SEQ(wh) \
154 (((wh)->i_fc[0] & \
155 (WIFI_FC0_TYPE_MASK | WIFI_FC0_SUBTYPE_QOS)) == \
156 (WIFI_FC0_TYPE_DATA | WIFI_FC0_SUBTYPE_QOS))
157
158
159/*
160 * Management information elements
161 */
162struct wifi_information {
163 char ssid[WIFI_NWID_LEN+1];
164 struct rates {
165 uint8_t *p;
166 } rates;
167 struct fh {
168 uint16_t dwell;
169 uint8_t set;
170 uint8_t pattern;
171 uint8_t index;
172 } fh;
173 struct ds {
174 uint8_t channel;
175 } ds;
176 struct cf {
177 uint8_t count;
178 uint8_t period;
179 uint8_t maxdur[2];
180 uint8_t dur[2];
181 } cf;
182 struct tim {
183 uint8_t count;
184 uint8_t period;
185 uint8_t bitctl;
186 /* uint8_t pvt[251]; The driver never needs to use this */
187 } tim;
188 struct ibss {
189 uint16_t atim;
190 } ibss;
191 struct challenge {
192 uint8_t *p;
193 uint8_t len;
194 } challenge;
195};
196
197#define WIFI_RATES_MAXSIZE 15
198#define WIFI_NWID_MAXSIZE 32
199
200enum {
201 WIFI_ELEMID_SSID = 0,
202 WIFI_ELEMID_RATES = 1,
203 WIFI_ELEMID_FHPARMS = 2,
204 WIFI_ELEMID_DSPARMS = 3,
205 WIFI_ELEMID_CFPARMS = 4,
206 WIFI_ELEMID_TIM = 5,
207 WIFI_ELEMID_IBSSPARMS = 6,
208 WIFI_ELEMID_CHALLENGE = 16,
209 WIFI_ELEMID_ERP = 42,
210 WIFI_ELEMID_XRATES = 50,
211 WIFI_ELEMID_VENDOR = 221
212};
213/*
214 * AUTH management packets
215 *
216 * octect algo[2]
217 * octect seq[2]
218 * octect status[2]
219 * octect chal.id
220 * octect chal.length
221 * octect chal.text[253]
222 */
223typedef uint8_t * wifi_mgt_auth_t;
224
225#define WIFI_AUTH_ALGORITHM(auth) \
226 (auth[0] + (auth[1] << 8))
227#define WIFI_AUTH_TRANSACTION(auth) \
228 (auth[2] + (auth[3] << 8))
229#define WIFI_AUTH_STATUS(auth) \
230 (auth[4] + (auth[5] << 8))
231
232#define WIFI_AUTH_ALG_OPEN 0x0000
233#define WIFI_AUTH_ALG_SHARED 0x0001
234
235#define WIFI_AUTH_OPEN_REQUEST 1
236#define WIFI_AUTH_OPEN_RESPONSE 2
237
238#define WIFI_AUTH_SHARED_REQUEST 1
239#define WIFI_AUTH_SHARED_CHALLENGE 2
240#define WIFI_AUTH_SHARED_RESPONSE 3
241#define WIFI_AUTH_SHARED_PASS 4
242
243/*
244 * Reason codes
245 *
246 * Unlisted codes are reserved
247 */
248#define WIFI_REASON_UNSPECIFIED 1
249#define WIFI_REASON_AUTH_EXPIRE 2
250#define WIFI_REASON_AUTH_LEAVE 3
251#define WIFI_REASON_ASSOC_EXPIRE 4
252#define WIFI_REASON_ASSOC_TOOMANY 5
253#define WIFI_REASON_NOT_AUTHED 6
254#define WIFI_REASON_NOT_ASSOCED 7
255#define WIFI_REASON_ASSOC_LEAVE 8
256#define WIFI_REASON_ASSOC_NOT_AUTHED 9
257
258/*
259 * Status code
260 *
261 * Unlisted codes are reserved
262 */
263#define WIFI_STATUS_SUCCESS 0x0000
264#define WIFI_STATUS_UNSPECIFIED 1
265#define WIFI_STATUS_CAPINFO 10
266#define WIFI_STATUS_NOT_ASSOCED 11
267#define WIFI_STATUS_OTHER 12
268#define WIFI_STATUS_ALG 13
269#define WIFI_STATUS_SEQUENCE 14
270#define WIFI_STATUS_CHALLENGE 15
271#define WIFI_STATUS_TIMEOUT 16
272#define WIFI_STATUS_BASIC_RATES 18
273#define WIFI_STATUS_TOO_MANY_STATIONS 22
274#define WIFI_STATUS_RATES 23
275#define WIFI_STATUS_SHORTSLOT_REQUIRED 25
276
277
278#define WIFI_WEP_KEYLEN 5 /* 40bit */
279#define WIFI_WEP_IVLEN 3 /* 24bit */
280#define WIFI_WEP_KIDLEN 1 /* 1 octet */
281#define WIFI_WEP_CRCLEN 4 /* CRC-32 */
282#define WIFI_WEP_NKID 4 /* number of key ids */
283
284#define WIFI_WEP_HEADERSIZE (WIFI_WEP_IVLEN + WIFI_WEP_KIDLEN)
285
286
287#define WIFI_WEP_NOSUP -1
288#define WIFI_WEP_OFF 0
289#define WIFI_WEP_ON 1
290#define WIFI_WEP_MIXED 2
291
292#define WIFI_AUTH_NONE 0
293#define WIFI_AUTH_OPEN 1
294#define WIFI_AUTH_SHARED 2
295
296#define WIFI_POWERSAVE_NOSUP -1
297#define WIFI_POWERSAVE_OFF 0
298#define WIFI_POWERSAVE_CAM 1
299#define WIFI_POWERSAVE_PSP 2
300#define WIFI_POWERSAVE_PSP_CAM 3
301#define WIFI_POWERSAVE_ON WIFI_POWERSAVE_CAM
302
303#define WIFI_RATE_BASIC 0x80
304#define WIFI_RATE_VAL 0x7f
305
306#define WIFI_RATE_SIZE 0x08
307
308#define WIFI_SEQ_FRAG_MASK 0x000f
309#define WIFI_SEQ_FRAG_SHIFT 0
310#define WIFI_SEQ_SEQ_MASK 0xfff0
311#define WIFI_SEQ_SEQ_SHIFT 4
312
313
314/*
315 * 802.11 protocol crypto-related definitions.
316 */
317#define WIFI_KEYBUF_SIZE 16
318#define WIFI_MICBUF_SIZE (8+8) /* space for both tx+rx keys */
319
320
321#ifndef WIFI_MAX
322#define WIFI_MAX(a, b) ((a) > (b) ? (a) : (b))
323#endif
324#ifndef WIFI_MIN
325#define WIFI_MIN(a, b) ((a) < (b) ? (a) : (b))
326#endif
327
328
329
330/* ARPHRD_IEEE80211_PRISM uses a bloated version of Prism2 RX frame header
331 * (from linux-wlan-ng) */
332
333/*
334 * For packet capture, define the same physical layer packet header
335 * structure as used in the wlan-ng driver
336 */
337enum {
338 DIDmsg_lnxind_wlansniffrm = 0x00000044,
339 DIDmsg_lnxind_wlansniffrm_hosttime = 0x00010044,
340 DIDmsg_lnxind_wlansniffrm_mactime = 0x00020044,
341 DIDmsg_lnxind_wlansniffrm_channel = 0x00030044,
342 DIDmsg_lnxind_wlansniffrm_rssi = 0x00040044,
343 DIDmsg_lnxind_wlansniffrm_sq = 0x00050044,
344 DIDmsg_lnxind_wlansniffrm_signal = 0x00060044,
345 DIDmsg_lnxind_wlansniffrm_noise = 0x00070044,
346 DIDmsg_lnxind_wlansniffrm_rate = 0x00080044,
347 DIDmsg_lnxind_wlansniffrm_istx = 0x00090044,
348 DIDmsg_lnxind_wlansniffrm_frmlen = 0x000A0044
349};
350enum {
351 P80211ENUM_msgitem_status_no_value = 0x00
352};
353enum {
354 P80211ENUM_truth_false = 0x00
355};
356
357
358typedef struct {
359 uint32_t did;
360 uint16_t status;
361 uint16_t len;
362 uint32_t data;
363} p80211item_uint32_t;
364
365typedef struct {
366 uint32_t msgcode;
367 uint32_t msglen;
368#define WLAN_DEVNAMELEN_MAX 16
369 uint8_t devname[WLAN_DEVNAMELEN_MAX];
370 p80211item_uint32_t hosttime;
371 p80211item_uint32_t mactime;
372 p80211item_uint32_t channel;
373 p80211item_uint32_t rssi;
374 p80211item_uint32_t sq;
375 p80211item_uint32_t signal;
376 p80211item_uint32_t noise;
377 p80211item_uint32_t rate;
378 p80211item_uint32_t istx;
379 p80211item_uint32_t frmlen;
380} wlan_ng_prism2_header;
381
382
383#define LWNG_CAP_DID_BASE (4 | (1 << 6)) /* section 4, group 1 */
384#define LWNG_CAPHDR_VERSION 0x80211001
385
386#define WIFI_SLOT_B 20
387#define WIFI_DIFS_B 50
388#define WIFI_SIFS_B 10
389#define WIFI_ACK_B 304
390#define WIFI_PLCP_HEADER_LONG_B 192
391#define WIFI_PLCP_HEADER_SHORT_B 192
392
393#define WIFI_SLOT_A 9
394#define WIFI_DIFS_A 28
395#define WIFI_SIFS_A 9
396#define WIFI_ACK_A 30
397#define WIFI_PLCP_HEADER_A 20
398
399
400#define is_b_rate(b) ((b == 2) || (b == 4) || (b == 11) || (b == 22))
401
402#define WIFI_CW_MIN 31
403#define WIFI_CW_MAX 1023
404
405// 6-byte LLC header (last byte is terminating NUL)
406#define WIFI_LLC_HEADER ((const uint8_t *) "\xAA\xAA\x03\x00\x00")
407#define WIFI_LLC_HEADER_LEN 6
408
409#endif /* !_CLICKNET_WIFI_H_ */