aboutsummaryrefslogtreecommitdiff
path: root/src/transport/wlan
diff options
context:
space:
mode:
authorDavid Brodski <david@brodski.eu>2011-03-28 21:52:47 +0000
committerDavid Brodski <david@brodski.eu>2011-03-28 21:52:47 +0000
commit76b1f350c95e6f4e28a0bc9d915f20e354fff1ab (patch)
tree939433ea0a6937ae5326539a62d1ea9e0ebb9597 /src/transport/wlan
parentc31a1ce379ec7ade3225ddda0364cf09a65d1689 (diff)
downloadgnunet-76b1f350c95e6f4e28a0bc9d915f20e354fff1ab.tar.gz
gnunet-76b1f350c95e6f4e28a0bc9d915f20e354fff1ab.zip
First test of wlan driver, sends beacon every 2 seconds
Diffstat (limited to 'src/transport/wlan')
-rw-r--r--src/transport/wlan/byteorder.h397
-rw-r--r--src/transport/wlan/crctable_osdep.h40
-rw-r--r--src/transport/wlan/helper_common.c110
-rw-r--r--src/transport/wlan/helper_common.h15
-rw-r--r--src/transport/wlan/ieee80211.h663
-rw-r--r--src/transport/wlan/ieee80211_radiotap.h260
-rw-r--r--src/transport/wlan/loopback_helper.c428
-rw-r--r--src/transport/wlan/loopback_helper.h20
-rw-r--r--src/transport/wlan/radiotap-parser.c251
-rw-r--r--src/transport/wlan/radiotap-parser.h78
10 files changed, 2262 insertions, 0 deletions
diff --git a/src/transport/wlan/byteorder.h b/src/transport/wlan/byteorder.h
new file mode 100644
index 000000000..75dc5e5d5
--- /dev/null
+++ b/src/transport/wlan/byteorder.h
@@ -0,0 +1,397 @@
1/*
2 * Compatibility header
3 *
4 * Copyright (C) 2009 Thomas d'Otreppe
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef _AIRCRACK_NG_BYTEORDER_H_
22#define _AIRCRACK_NG_BYTEORDER_H_
23
24 #define ___my_swab16(x) \
25 ((u_int16_t)( \
26 (((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | \
27 (((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8) ))
28 #define ___my_swab32(x) \
29 ((u_int32_t)( \
30 (((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | \
31 (((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) << 8) | \
32 (((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >> 8) | \
33 (((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24) ))
34 #define ___my_swab64(x) \
35 ((u_int64_t)( \
36 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000000000ffULL) << 56) | \
37 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000000000ff00ULL) << 40) | \
38 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000000000ff0000ULL) << 24) | \
39 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000ff000000ULL) << 8) | \
40 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000ff00000000ULL) >> 8) | \
41 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000ff0000000000ULL) >> 24) | \
42 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \
43 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) ))
44
45
46 /*
47 * Linux
48 */
49 #if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux__)
50 #include <endian.h>
51 #include <unistd.h>
52 #include <stdint.h>
53
54 #ifndef __int8_t_defined
55 typedef uint64_t u_int64_t;
56 typedef uint32_t u_int32_t;
57 typedef uint16_t u_int16_t;
58 typedef uint8_t u_int8_t;
59 #endif
60
61 #endif
62
63 /*
64 * Cygwin
65 */
66 #if defined(__CYGWIN32__)
67 #include <asm/byteorder.h>
68 #include <unistd.h>
69
70 #define __be64_to_cpu(x) ___my_swab64(x)
71 #define __be32_to_cpu(x) ___my_swab32(x)
72 #define __be16_to_cpu(x) ___my_swab16(x)
73 #define __cpu_to_be64(x) ___my_swab64(x)
74 #define __cpu_to_be32(x) ___my_swab32(x)
75 #define __cpu_to_be16(x) ___my_swab16(x)
76 #define __le64_to_cpu(x) (x)
77 #define __le32_to_cpu(x) (x)
78 #define __le16_to_cpu(x) (x)
79 #define __cpu_to_le64(x) (x)
80 #define __cpu_to_le32(x) (x)
81 #define __cpu_to_le16(x) (x)
82
83 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
84
85 #endif
86
87 /*
88 * Windows (DDK)
89 */
90 #if defined(__WIN__)
91
92 #include <io.h>
93
94 #define __be64_to_cpu(x) ___my_swab64(x)
95 #define __be32_to_cpu(x) ___my_swab32(x)
96 #define __be16_to_cpu(x) ___my_swab16(x)
97 #define __cpu_to_be64(x) ___my_swab64(x)
98 #define __cpu_to_be32(x) ___my_swab32(x)
99 #define __cpu_to_be16(x) ___my_swab16(x)
100 #define __le64_to_cpu(x) (x)
101 #define __le32_to_cpu(x) (x)
102 #define __le16_to_cpu(x) (x)
103 #define __cpu_to_le64(x) (x)
104 #define __cpu_to_le32(x) (x)
105 #define __cpu_to_le16(x) (x)
106
107 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
108
109 #endif
110
111 /*
112 * MAC (Darwin)
113 */
114 #if defined(__APPLE_CC__)
115 #if defined(__x86_64__) && defined(__APPLE__)
116
117 #include <libkern/OSByteOrder.h>
118
119 #define __swab64(x) (unsigned long long) OSSwapInt64((uint64_t)x)
120 #define __swab32(x) (unsigned long) OSSwapInt32((uint32_t)x)
121 #define __swab16(x) (unsigned short) OSSwapInt16((uint16_t)x)
122 #define __be64_to_cpu(x) (unsigned long long) OSSwapBigToHostInt64((uint64_t)x)
123 #define __be32_to_cpu(x) (unsigned long) OSSwapBigToHostInt32((uint32_t)x)
124 #define __be16_to_cpu(x) (unsigned short) OSSwapBigToHostInt16((uint16_t)x)
125 #define __le64_to_cpu(x) (unsigned long long) OSSwapLittleToHostInt64((uint64_t)x)
126 #define __le32_to_cpu(x) (unsigned long) OSSwapLittleToHostInt32((uint32_t)x)
127 #define __le16_to_cpu(x) (unsigned short) OSSwapLittleToHostInt16((uint16_t)x)
128 #define __cpu_to_be64(x) (unsigned long long) OSSwapHostToBigInt64((uint64_t)x)
129 #define __cpu_to_be32(x) (unsigned long) OSSwapHostToBigInt32((uint32_t)x)
130 #define __cpu_to_be16(x) (unsigned short) OSSwapHostToBigInt16((uint16_t)x)
131 #define __cpu_to_le64(x) (unsigned long long) OSSwapHostToLittleInt64((uint64_t)x)
132 #define __cpu_to_le32(x) (unsigned long) OSSwapHostToLittleInt32((uint32_t)x)
133 #define __cpu_to_le16(x) (unsigned short) OSSwapHostToLittleInt16((uint16_t)x)
134
135 #else
136
137 #include <architecture/byte_order.h>
138
139 #define __swab64(x) NXSwapLongLong(x)
140 #define __swab32(x) NXSwapLong(x)
141 #define __swab16(x) NXSwapShort(x)
142 #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)
143 #define __be32_to_cpu(x) NXSwapBigLongToHost(x)
144 #define __be16_to_cpu(x) NXSwapBigShortToHost(x)
145 #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)
146 #define __le32_to_cpu(x) NXSwapLittleLongToHost(x)
147 #define __le16_to_cpu(x) NXSwapLittleShortToHost(x)
148 #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)
149 #define __cpu_to_be32(x) NXSwapHostLongToBig(x)
150 #define __cpu_to_be16(x) NXSwapHostShortToBig(x)
151 #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)
152 #define __cpu_to_le32(x) NXSwapHostLongToLittle(x)
153 #define __cpu_to_le16(x) NXSwapHostShortToLittle(x)
154
155 #endif
156
157 #define __LITTLE_ENDIAN 1234
158 #define __BIG_ENDIAN 4321
159 #define __PDP_ENDIAN 3412
160 #define __BYTE_ORDER __BIG_ENDIAN
161
162 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
163
164 #endif
165
166 /*
167 * Solaris
168 * -------
169 */
170 #if defined(__sparc__)
171 #include <sys/byteorder.h>
172 #include <sys/types.h>
173 #include <unistd.h>
174
175 #define __be64_to_cpu(x) (x)
176 #define __be32_to_cpu(x) (x)
177 #define __be16_to_cpu(x) (x)
178 #define __cpu_to_be64(x) (x)
179 #define __cpu_to_be32(x) (x)
180 #define __cpu_to_be16(x) (x)
181 #define __le64_to_cpu(x) ___my_swab64(x)
182 #define __le32_to_cpu(x) ___my_swab32(x)
183 #define __le16_to_cpu(x) ___my_swab16(x)
184 #define __cpu_to_le64(x) ___my_swab64(x)
185 #define __cpu_to_le32(x) ___my_swab32(x)
186 #define __cpu_to_le16(x) ___my_swab16(x)
187
188 typedef uint64_t u_int64_t;
189 typedef uint32_t u_int32_t;
190 typedef uint16_t u_int16_t;
191 typedef uint8_t u_int8_t;
192
193 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
194
195 #endif
196
197 /*
198 * Custom stuff
199 */
200 #if defined(__MACH__) && !defined(__APPLE_CC__)
201 #include <libkern/OSByteOrder.h>
202 #define __cpu_to_be64(x) = OSSwapHostToBigInt64(x)
203 #define __cpu_to_be32(x) = OSSwapHostToBigInt32(x)
204
205 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
206
207 #endif
208
209
210 // FreeBSD
211 #ifdef __FreeBSD__
212 #include <machine/endian.h>
213 #endif
214
215 // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...?
216
217
218 // XXX: Mac: Check http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h
219 // http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html
220 // Write to apple to ask what should be used.
221
222 #if defined(LITTLE_ENDIAN)
223 #define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN
224 #elif defined(__LITTLE_ENDIAN)
225 #define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN
226 #elif defined(_LITTLE_ENDIAN)
227 #define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN
228 #endif
229
230 #if defined(BIG_ENDIAN)
231 #define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN
232 #elif defined(__BIG_ENDIAN)
233 #define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN
234 #elif defined(_BIG_ENDIAN)
235 #define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN
236 #endif
237
238 #if !defined(AIRCRACK_NG_LITTLE_ENDIAN) && !defined(AIRCRACK_NG_BIG_ENDIAN)
239 #error Impossible to determine endianness (Little or Big endian), please contact the author.
240 #endif
241
242 #if defined(BYTE_ORDER)
243 #if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
244 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
245 #elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
246 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
247 #endif
248 #elif defined(__BYTE_ORDER)
249 #if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
250 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
251 #elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
252 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
253 #endif
254 #elif defined(_BYTE_ORDER)
255 #if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
256 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
257 #elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
258 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
259 #endif
260 #endif
261
262 #ifndef AIRCRACK_NG_BYTE_ORDER
263 #error Impossible to determine endianness (Little or Big endian), please contact the author.
264 #endif
265
266 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
267
268 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
269 #define __be64_to_cpu(x) ___my_swab64(x)
270 #define __be32_to_cpu(x) ___my_swab32(x)
271 #define __be16_to_cpu(x) ___my_swab16(x)
272 #define __cpu_to_be64(x) ___my_swab64(x)
273 #define __cpu_to_be32(x) ___my_swab32(x)
274 #define __cpu_to_be16(x) ___my_swab16(x)
275 #define __le64_to_cpu(x) (x)
276 #define __le32_to_cpu(x) (x)
277 #define __le16_to_cpu(x) (x)
278 #define __cpu_to_le64(x) (x)
279 #define __cpu_to_le32(x) (x)
280 #define __cpu_to_le16(x) (x)
281 #endif
282
283 #ifndef htobe16
284 #define htobe16 ___my_swab16
285 #endif
286 #ifndef htobe32
287 #define htobe32 ___my_swab32
288 #endif
289 #ifndef betoh16
290 #define betoh16 ___my_swab16
291 #endif
292 #ifndef betoh32
293 #define betoh32 ___my_swab32
294 #endif
295
296 #ifndef htole16
297 #define htole16(x) (x)
298 #endif
299 #ifndef htole32
300 #define htole32(x) (x)
301 #endif
302 #ifndef letoh16
303 #define letoh16(x) (x)
304 #endif
305 #ifndef letoh32
306 #define letoh32(x) (x)
307 #endif
308
309 #endif
310
311 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
312
313 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
314 #define __be64_to_cpu(x) (x)
315 #define __be32_to_cpu(x) (x)
316 #define __be16_to_cpu(x) (x)
317 #define __cpu_to_be64(x) (x)
318 #define __cpu_to_be32(x) (x)
319 #define __cpu_to_be16(x) (x)
320 #define __le64_to_cpu(x) ___my_swab64(x)
321 #define __le32_to_cpu(x) ___my_swab32(x)
322 #define __le16_to_cpu(x) ___my_swab16(x)
323 #define __cpu_to_le64(x) ___my_swab64(x)
324 #define __cpu_to_le32(x) ___my_swab32(x)
325 #define __cpu_to_le16(x) ___my_swab16(x)
326 #endif
327
328 #ifndef htobe16
329 #define htobe16(x) (x)
330 #endif
331 #ifndef htobe32
332 #define htobe32(x) (x)
333 #endif
334 #ifndef betoh16
335 #define betoh16(x) (x)
336 #endif
337 #ifndef betoh32
338 #define betoh32(x) (x)
339 #endif
340
341 #ifndef htole16
342 #define htole16 ___my_swab16
343 #endif
344 #ifndef htole32
345 #define htole32 ___my_swab32
346 #endif
347 #ifndef letoh16
348 #define letoh16 ___my_swab16
349 #endif
350 #ifndef letoh32
351 #define letoh32 ___my_swab32
352 #endif
353
354 #endif
355
356 // Common defines
357 #define cpu_to_le64 __cpu_to_le64
358 #define le64_to_cpu __le64_to_cpu
359 #define cpu_to_le32 __cpu_to_le32
360 #define le32_to_cpu __le32_to_cpu
361 #define cpu_to_le16 __cpu_to_le16
362 #define le16_to_cpu __le16_to_cpu
363 #define cpu_to_be64 __cpu_to_be64
364 #define be64_to_cpu __be64_to_cpu
365 #define cpu_to_be32 __cpu_to_be32
366 #define be32_to_cpu __be32_to_cpu
367 #define cpu_to_be16 __cpu_to_be16
368 #define be16_to_cpu __be16_to_cpu
369
370 #ifndef le16toh
371 #define le16toh le16_to_cpu
372 #endif
373 #ifndef be16toh
374 #define be16toh be16_to_cpu
375 #endif
376 #ifndef le32toh
377 #define le32toh le32_to_cpu
378 #endif
379 #ifndef be32toh
380 #define be32toh be32_to_cpu
381 #endif
382
383
384 #ifndef htons
385 #define htons be16_to_cpu
386 #endif
387 #ifndef htonl
388 #define htonl cpu_to_be16
389 #endif
390 #ifndef ntohs
391 #define ntohs cpu_to_be16
392 #endif
393 #ifndef ntohl
394 #define ntohl cpu_to_be32
395 #endif
396
397#endif
diff --git a/src/transport/wlan/crctable_osdep.h b/src/transport/wlan/crctable_osdep.h
new file mode 100644
index 000000000..4f14d245b
--- /dev/null
+++ b/src/transport/wlan/crctable_osdep.h
@@ -0,0 +1,40 @@
1#ifndef _CRCTABLE_OSDEP_H
2#define _CRCTABLE_OSDEP_H
3
4const unsigned long int crc_tbl_osdep[256] =
5{
6 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
7 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
8 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
9 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
10 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
11 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
12 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
13 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
14 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
15 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
16 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
17 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
18 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
19 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
20 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
21 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
22 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
23 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
24 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
25 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
26 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
27 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
28 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
29 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
30 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
31 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
32 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
33 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
34 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
35 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
36 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
37 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
38};
39
40#endif /* crctable_osdep.h */
diff --git a/src/transport/wlan/helper_common.c b/src/transport/wlan/helper_common.c
new file mode 100644
index 000000000..5171403c8
--- /dev/null
+++ b/src/transport/wlan/helper_common.c
@@ -0,0 +1,110 @@
1/*
2 * helper_common.c
3 *
4 * Created on: 28.03.2011
5 * Author: David Brodski
6 */
7
8#include <sys/socket.h>
9#include <stdint.h>
10#include <stdio.h>
11#include <stdlib.h>
12#include <errno.h>
13#include <resolv.h>
14#include <string.h>
15#include <utime.h>
16#include <unistd.h>
17#include <getopt.h>
18
19//#include "platform.h"
20#include "gnunet_constants.h"
21#include "gnunet_os_lib.h"
22#include "gnunet_transport_plugin.h"
23#include "transport.h"
24#include "gnunet_util_lib.h"
25#include "plugin_transport_wlan.h"
26#include "gnunet_common.h"
27#include "gnunet_transport_plugin.h"
28//#include "gnunet_util_lib.h"
29
30/**
31 * function to create GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL message for plugin
32 * @param buffer pointer to buffer for the message
33 * @param mac pointer to the mac address
34 * @return number of bytes written
35 */
36
37int
38send_mac_to_plugin(char * buffer, uint8_t * mac)
39{
40
41 struct Wlan_Helper_Control_Message macmsg;
42
43 memcpy(macmsg.mac.mac, mac, sizeof(struct MacAddress));
44 macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message));
45 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
46
47 memcpy(buffer, &macmsg, sizeof(struct Wlan_Helper_Control_Message));
48 return sizeof(struct Wlan_Helper_Control_Message);
49}
50
51/*
52 * Copyright (c) 2008, Thomas d'Otreppe
53 *
54 * Common OSdep stuff
55 *
56 * This program is free software; you can redistribute it and/or modify
57 * it under the terms of the GNU General Public License as published by
58 * the Free Software Foundation; either version 2 of the License, or
59 * (at your option) any later version.
60 *
61 * This program is distributed in the hope that it will be useful,
62 * but WITHOUT ANY WARRANTY; without even the implied warranty of
63 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64 * GNU General Public License for more details.
65 *
66 * You should have received a copy of the GNU General Public License
67 * along with this program; if not, write to the Free Software
68 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
69 */
70
71/**
72 * Return the frequency in Mhz from a channel number
73 */
74int getFrequencyFromChannel(int channel)
75{
76 static int frequencies[] = {
77 -1, // No channel 0
78 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
79 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // Nothing from channel 15 to 34 (exclusive)
80 5170, 5175, 5180, 5185, 5190, 5195, 5200, 5205, 5210, 5215, 5220, 5225, 5230, 5235, 5240, 5245,
81 5250, 5255, 5260, 5265, 5270, 5275, 5280, 5285, 5290, 5295, 5300, 5305, 5310, 5315, 5320, 5325,
82 5330, 5335, 5340, 5345, 5350, 5355, 5360, 5365, 5370, 5375, 5380, 5385, 5390, 5395, 5400, 5405,
83 5410, 5415, 5420, 5425, 5430, 5435, 5440, 5445, 5450, 5455, 5460, 5465, 5470, 5475, 5480, 5485,
84 5490, 5495, 5500, 5505, 5510, 5515, 5520, 5525, 5530, 5535, 5540, 5545, 5550, 5555, 5560, 5565,
85 5570, 5575, 5580, 5585, 5590, 5595, 5600, 5605, 5610, 5615, 5620, 5625, 5630, 5635, 5640, 5645,
86 5650, 5655, 5660, 5665, 5670, 5675, 5680, 5685, 5690, 5695, 5700, 5705, 5710, 5715, 5720, 5725,
87 5730, 5735, 5740, 5745, 5750, 5755, 5760, 5765, 5770, 5775, 5780, 5785, 5790, 5795, 5800, 5805,
88 5810, 5815, 5820, 5825, 5830, 5835, 5840, 5845, 5850, 5855, 5860, 5865, 5870, 5875, 5880, 5885,
89 5890, 5895, 5900, 5905, 5910, 5915, 5920, 5925, 5930, 5935, 5940, 5945, 5950, 5955, 5960, 5965,
90 5970, 5975, 5980, 5985, 5990, 5995, 6000, 6005, 6010, 6015, 6020, 6025, 6030, 6035, 6040, 6045,
91 6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095, 6100
92 };
93
94 return (channel > 0 && channel <= 221) ? frequencies[channel] : -1;
95}
96
97/**
98 * Return the channel from the frequency (in Mhz)
99 */
100int getChannelFromFrequency(int frequency)
101{
102 if (frequency >= 2412 && frequency <= 2472)
103 return (frequency - 2407) / 5;
104 else if (frequency == 2484)
105 return 14;
106 else if (frequency >= 5000 && frequency <= 6100)
107 return (frequency - 5000) / 5;
108 else
109 return -1;
110}
diff --git a/src/transport/wlan/helper_common.h b/src/transport/wlan/helper_common.h
new file mode 100644
index 000000000..71c3e1b9b
--- /dev/null
+++ b/src/transport/wlan/helper_common.h
@@ -0,0 +1,15 @@
1/*
2 * helper_common.h
3 *
4 * Created on: 28.03.2011
5 * Author: david
6 */
7
8#ifndef HELPER_COMMON_H_
9#define HELPER_COMMON_H_
10
11int getFrequencyFromChannel(int channel);
12int getChannelFromFrequency(int frequency);
13int send_mac_to_plugin(char * buffer, uint8_t * mac);
14
15#endif /* HELPER_COMMON_H_ */
diff --git a/src/transport/wlan/ieee80211.h b/src/transport/wlan/ieee80211.h
new file mode 100644
index 000000000..8df1d2c29
--- /dev/null
+++ b/src/transport/wlan/ieee80211.h
@@ -0,0 +1,663 @@
1/*-
2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * Alternatively, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2 as published by the Free
19 * Software Foundation.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * $FreeBSD: src/sys/net80211/ieee80211.h,v 1.12 2006/12/01 18:40:51 imp Exp $
33 */
34#ifndef _NET80211_IEEE80211_H_
35#define _NET80211_IEEE80211_H_
36
37/*
38 * 802.11 protocol definitions.
39 */
40
41#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
42/* is 802.11 address multicast/broadcast? */
43#define IEEE80211_IS_MULTICAST(_a) (*(_a) & 0x01)
44
45/* IEEE 802.11 PLCP header */
46struct ieee80211_plcp_hdr {
47 u_int16_t i_sfd;
48 u_int8_t i_signal;
49 u_int8_t i_service;
50 u_int16_t i_length;
51 u_int16_t i_crc;
52} GNUNET_PACKED;
53
54#define IEEE80211_PLCP_SFD 0xF3A0
55#define IEEE80211_PLCP_SERVICE 0x00
56
57/*
58 * generic definitions for IEEE 802.11 frames
59 */
60struct ieee80211_frame {
61 u_int8_t i_fc[2];
62 u_int8_t i_dur[2];
63 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
64 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
65 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
66 u_int8_t i_seq[2];
67 /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
68 /* see below */
69} GNUNET_PACKED;
70
71struct ieee80211_qosframe {
72 u_int8_t i_fc[2];
73 u_int8_t i_dur[2];
74 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
75 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
76 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
77 u_int8_t i_seq[2];
78 u_int8_t i_qos[2];
79 /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
80 /* see below */
81} GNUNET_PACKED;
82
83struct ieee80211_qoscntl {
84 u_int8_t i_qos[2];
85};
86
87struct ieee80211_frame_addr4 {
88 u_int8_t i_fc[2];
89 u_int8_t i_dur[2];
90 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
91 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
92 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
93 u_int8_t i_seq[2];
94 u_int8_t i_addr4[IEEE80211_ADDR_LEN];
95} GNUNET_PACKED;
96
97
98struct ieee80211_qosframe_addr4 {
99 u_int8_t i_fc[2];
100 u_int8_t i_dur[2];
101 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
102 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
103 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
104 u_int8_t i_seq[2];
105 u_int8_t i_addr4[IEEE80211_ADDR_LEN];
106 u_int8_t i_qos[2];
107} GNUNET_PACKED;
108
109#define IEEE80211_FC0_VERSION_MASK 0x03
110#define IEEE80211_FC0_VERSION_SHIFT 0
111#define IEEE80211_FC0_VERSION_0 0x00
112#define IEEE80211_FC0_TYPE_MASK 0x0c
113#define IEEE80211_FC0_TYPE_SHIFT 2
114#define IEEE80211_FC0_TYPE_MGT 0x00
115#define IEEE80211_FC0_TYPE_CTL 0x04
116#define IEEE80211_FC0_TYPE_DATA 0x08
117
118#define IEEE80211_FC0_SUBTYPE_MASK 0xf0
119#define IEEE80211_FC0_SUBTYPE_SHIFT 4
120/* for TYPE_MGT */
121#define IEEE80211_FC0_SUBTYPE_ASSOC_REQ 0x00
122#define IEEE80211_FC0_SUBTYPE_ASSOC_RESP 0x10
123#define IEEE80211_FC0_SUBTYPE_REASSOC_REQ 0x20
124#define IEEE80211_FC0_SUBTYPE_REASSOC_RESP 0x30
125#define IEEE80211_FC0_SUBTYPE_PROBE_REQ 0x40
126#define IEEE80211_FC0_SUBTYPE_PROBE_RESP 0x50
127#define IEEE80211_FC0_SUBTYPE_BEACON 0x80
128#define IEEE80211_FC0_SUBTYPE_ATIM 0x90
129#define IEEE80211_FC0_SUBTYPE_DISASSOC 0xa0
130#define IEEE80211_FC0_SUBTYPE_AUTH 0xb0
131#define IEEE80211_FC0_SUBTYPE_DEAUTH 0xc0
132/* for TYPE_CTL */
133#define IEEE80211_FC0_SUBTYPE_PS_POLL 0xa0
134#define IEEE80211_FC0_SUBTYPE_RTS 0xb0
135#define IEEE80211_FC0_SUBTYPE_CTS 0xc0
136#define IEEE80211_FC0_SUBTYPE_ACK 0xd0
137#define IEEE80211_FC0_SUBTYPE_CF_END 0xe0
138#define IEEE80211_FC0_SUBTYPE_CF_END_ACK 0xf0
139/* for TYPE_DATA (bit combination) */
140#define IEEE80211_FC0_SUBTYPE_DATA 0x00
141#define IEEE80211_FC0_SUBTYPE_CF_ACK 0x10
142#define IEEE80211_FC0_SUBTYPE_CF_POLL 0x20
143#define IEEE80211_FC0_SUBTYPE_CF_ACPL 0x30
144#define IEEE80211_FC0_SUBTYPE_NODATA 0x40
145#define IEEE80211_FC0_SUBTYPE_CFACK 0x50
146#define IEEE80211_FC0_SUBTYPE_CFPOLL 0x60
147#define IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK 0x70
148#define IEEE80211_FC0_SUBTYPE_QOS 0x80
149#define IEEE80211_FC0_SUBTYPE_QOS_NULL 0xc0
150
151#define IEEE80211_FC1_DIR_MASK 0x03
152#define IEEE80211_FC1_DIR_NODS 0x00 /* STA->STA */
153#define IEEE80211_FC1_DIR_TODS 0x01 /* STA->AP */
154#define IEEE80211_FC1_DIR_FROMDS 0x02 /* AP ->STA */
155#define IEEE80211_FC1_DIR_DSTODS 0x03 /* AP ->AP */
156
157#define IEEE80211_FC1_MORE_FRAG 0x04
158#define IEEE80211_FC1_RETRY 0x08
159#define IEEE80211_FC1_PWR_MGT 0x10
160#define IEEE80211_FC1_MORE_DATA 0x20
161#define IEEE80211_FC1_WEP 0x40
162#define IEEE80211_FC1_ORDER 0x80
163
164#define IEEE80211_SEQ_FRAG_MASK 0x000f
165#define IEEE80211_SEQ_FRAG_SHIFT 0
166#define IEEE80211_SEQ_SEQ_MASK 0xfff0
167#define IEEE80211_SEQ_SEQ_SHIFT 4
168
169#define IEEE80211_NWID_LEN 32
170
171#define IEEE80211_QOS_TXOP 0x00ff
172/* bit 8 is reserved */
173#define IEEE80211_QOS_ACKPOLICY 0x60
174#define IEEE80211_QOS_ACKPOLICY_S 5
175#define IEEE80211_QOS_ESOP 0x10
176#define IEEE80211_QOS_ESOP_S 4
177#define IEEE80211_QOS_TID 0x0f
178
179/* does frame have QoS sequence control data */
180#define IEEE80211_QOS_HAS_SEQ(wh) \
181 (((wh)->i_fc[0] & \
182 (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) == \
183 (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
184
185/*
186 * WME/802.11e information element.
187 */
188struct ieee80211_wme_info {
189 u_int8_t wme_id; /* IEEE80211_ELEMID_VENDOR */
190 u_int8_t wme_len; /* length in bytes */
191 u_int8_t wme_oui[3]; /* 0x00, 0x50, 0xf2 */
192 u_int8_t wme_type; /* OUI type */
193 u_int8_t wme_subtype; /* OUI subtype */
194 u_int8_t wme_version; /* spec revision */
195 u_int8_t wme_info; /* QoS info */
196} GNUNET_PACKED;
197
198/*
199 * WME/802.11e Tspec Element
200 */
201struct ieee80211_wme_tspec {
202 u_int8_t ts_id;
203 u_int8_t ts_len;
204 u_int8_t ts_oui[3];
205 u_int8_t ts_oui_type;
206 u_int8_t ts_oui_subtype;
207 u_int8_t ts_version;
208 u_int8_t ts_tsinfo[3];
209 u_int8_t ts_nom_msdu[2];
210 u_int8_t ts_max_msdu[2];
211 u_int8_t ts_min_svc[4];
212 u_int8_t ts_max_svc[4];
213 u_int8_t ts_inactv_intv[4];
214 u_int8_t ts_susp_intv[4];
215 u_int8_t ts_start_svc[4];
216 u_int8_t ts_min_rate[4];
217 u_int8_t ts_mean_rate[4];
218 u_int8_t ts_max_burst[4];
219 u_int8_t ts_min_phy[4];
220 u_int8_t ts_peak_rate[4];
221 u_int8_t ts_delay[4];
222 u_int8_t ts_surplus[2];
223 u_int8_t ts_medium_time[2];
224} GNUNET_PACKED;
225
226/*
227 * WME AC parameter field
228 */
229struct ieee80211_wme_acparams {
230 u_int8_t acp_aci_aifsn;
231 u_int8_t acp_logcwminmax;
232 u_int16_t acp_txop;
233} GNUNET_PACKED;
234
235#define WME_NUM_AC 4 /* 4 AC categories */
236
237#define WME_PARAM_ACI 0x60 /* Mask for ACI field */
238#define WME_PARAM_ACI_S 5 /* Shift for ACI field */
239#define WME_PARAM_ACM 0x10 /* Mask for ACM bit */
240#define WME_PARAM_ACM_S 4 /* Shift for ACM bit */
241#define WME_PARAM_AIFSN 0x0f /* Mask for aifsn field */
242#define WME_PARAM_AIFSN_S 0 /* Shift for aifsn field */
243#define WME_PARAM_LOGCWMIN 0x0f /* Mask for CwMin field (in log) */
244#define WME_PARAM_LOGCWMIN_S 0 /* Shift for CwMin field */
245#define WME_PARAM_LOGCWMAX 0xf0 /* Mask for CwMax field (in log) */
246#define WME_PARAM_LOGCWMAX_S 4 /* Shift for CwMax field */
247
248#define WME_AC_TO_TID(_ac) ( \
249 ((_ac) == WME_AC_VO) ? 6 : \
250 ((_ac) == WME_AC_VI) ? 5 : \
251 ((_ac) == WME_AC_BK) ? 1 : \
252 0)
253
254#define TID_TO_WME_AC(_tid) ( \
255 ((_tid) < 1) ? WME_AC_BE : \
256 ((_tid) < 3) ? WME_AC_BK : \
257 ((_tid) < 6) ? WME_AC_VI : \
258 WME_AC_VO)
259
260/*
261 * WME Parameter Element
262 */
263struct ieee80211_wme_param {
264 u_int8_t param_id;
265 u_int8_t param_len;
266 u_int8_t param_oui[3];
267 u_int8_t param_oui_type;
268 u_int8_t param_oui_sybtype;
269 u_int8_t param_version;
270 u_int8_t param_qosInfo;
271#define WME_QOSINFO_COUNT 0x0f /* Mask for param count field */
272 u_int8_t param_reserved;
273 struct ieee80211_wme_acparams params_acParams[WME_NUM_AC];
274} GNUNET_PACKED;
275
276/*
277 * Management Notification Frame
278 */
279struct ieee80211_mnf {
280 u_int8_t mnf_category;
281 u_int8_t mnf_action;
282 u_int8_t mnf_dialog;
283 u_int8_t mnf_status;
284} GNUNET_PACKED;
285#define MNF_SETUP_REQ 0
286#define MNF_SETUP_RESP 1
287#define MNF_TEARDOWN 2
288
289/*
290 * Control frames.
291 */
292struct ieee80211_frame_min {
293 u_int8_t i_fc[2];
294 u_int8_t i_dur[2];
295 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
296 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
297 /* FCS */
298} GNUNET_PACKED;
299
300struct ieee80211_frame_rts {
301 u_int8_t i_fc[2];
302 u_int8_t i_dur[2];
303 u_int8_t i_ra[IEEE80211_ADDR_LEN];
304 u_int8_t i_ta[IEEE80211_ADDR_LEN];
305 /* FCS */
306} GNUNET_PACKED;
307
308struct ieee80211_frame_cts {
309 u_int8_t i_fc[2];
310 u_int8_t i_dur[2];
311 u_int8_t i_ra[IEEE80211_ADDR_LEN];
312 /* FCS */
313} GNUNET_PACKED;
314
315struct ieee80211_frame_ack {
316 u_int8_t i_fc[2];
317 u_int8_t i_dur[2];
318 u_int8_t i_ra[IEEE80211_ADDR_LEN];
319 /* FCS */
320} GNUNET_PACKED;
321
322struct ieee80211_frame_pspoll {
323 u_int8_t i_fc[2];
324 u_int8_t i_aid[2];
325 u_int8_t i_bssid[IEEE80211_ADDR_LEN];
326 u_int8_t i_ta[IEEE80211_ADDR_LEN];
327 /* FCS */
328} GNUNET_PACKED;
329
330struct ieee80211_frame_cfend { /* NB: also CF-End+CF-Ack */
331 u_int8_t i_fc[2];
332 u_int8_t i_dur[2]; /* should be zero */
333 u_int8_t i_ra[IEEE80211_ADDR_LEN];
334 u_int8_t i_bssid[IEEE80211_ADDR_LEN];
335 /* FCS */
336} GNUNET_PACKED;
337
338/*
339 * BEACON management packets
340 *
341 * octet timestamp[8]
342 * octet beacon interval[2]
343 * octet capability information[2]
344 * information element
345 * octet elemid
346 * octet length
347 * octet information[length]
348 */
349
350typedef u_int8_t *ieee80211_mgt_beacon_t;
351
352#define IEEE80211_BEACON_INTERVAL(beacon) \
353 ((beacon)[8] | ((beacon)[9] << 8))
354#define IEEE80211_BEACON_CAPABILITY(beacon) \
355 ((beacon)[10] | ((beacon)[11] << 8))
356
357#define IEEE80211_CAPINFO_ESS 0x0001
358#define IEEE80211_CAPINFO_IBSS 0x0002
359#define IEEE80211_CAPINFO_CF_POLLABLE 0x0004
360#define IEEE80211_CAPINFO_CF_POLLREQ 0x0008
361#define IEEE80211_CAPINFO_PRIVACY 0x0010
362#define IEEE80211_CAPINFO_SHORT_PREAMBLE 0x0020
363#define IEEE80211_CAPINFO_PBCC 0x0040
364#define IEEE80211_CAPINFO_CHNL_AGILITY 0x0080
365/* bits 8-9 are reserved */
366#define IEEE80211_CAPINFO_SHORT_SLOTTIME 0x0400
367#define IEEE80211_CAPINFO_RSN 0x0800
368/* bit 12 is reserved */
369#define IEEE80211_CAPINFO_DSSSOFDM 0x2000
370/* bits 14-15 are reserved */
371
372/*
373 * 802.11i/WPA information element (maximally sized).
374 */
375struct ieee80211_ie_wpa {
376 u_int8_t wpa_id; /* IEEE80211_ELEMID_VENDOR */
377 u_int8_t wpa_len; /* length in bytes */
378 u_int8_t wpa_oui[3]; /* 0x00, 0x50, 0xf2 */
379 u_int8_t wpa_type; /* OUI type */
380 u_int16_t wpa_version; /* spec revision */
381 u_int32_t wpa_mcipher[1]; /* multicast/group key cipher */
382 u_int16_t wpa_uciphercnt; /* # pairwise key ciphers */
383 u_int32_t wpa_uciphers[8];/* ciphers */
384 u_int16_t wpa_authselcnt; /* authentication selector cnt*/
385 u_int32_t wpa_authsels[8];/* selectors */
386 u_int16_t wpa_caps; /* 802.11i capabilities */
387 u_int16_t wpa_pmkidcnt; /* 802.11i pmkid count */
388 u_int16_t wpa_pmkids[8]; /* 802.11i pmkids */
389} GNUNET_PACKED;
390
391/*
392 * Management information element payloads.
393 */
394
395enum {
396 IEEE80211_ELEMID_SSID = 0,
397 IEEE80211_ELEMID_RATES = 1,
398 IEEE80211_ELEMID_FHPARMS = 2,
399 IEEE80211_ELEMID_DSPARMS = 3,
400 IEEE80211_ELEMID_CFPARMS = 4,
401 IEEE80211_ELEMID_TIM = 5,
402 IEEE80211_ELEMID_IBSSPARMS = 6,
403 IEEE80211_ELEMID_COUNTRY = 7,
404 IEEE80211_ELEMID_CHALLENGE = 16,
405 /* 17-31 reserved for challenge text extension */
406 IEEE80211_ELEMID_ERP = 42,
407 IEEE80211_ELEMID_RSN = 48,
408 IEEE80211_ELEMID_XRATES = 50,
409 IEEE80211_ELEMID_TPC = 150,
410 IEEE80211_ELEMID_CCKM = 156,
411 IEEE80211_ELEMID_VENDOR = 221, /* vendor private */
412};
413
414struct ieee80211_tim_ie {
415 u_int8_t tim_ie; /* IEEE80211_ELEMID_TIM */
416 u_int8_t tim_len;
417 u_int8_t tim_count; /* DTIM count */
418 u_int8_t tim_period; /* DTIM period */
419 u_int8_t tim_bitctl; /* bitmap control */
420 u_int8_t tim_bitmap[1]; /* variable-length bitmap */
421} GNUNET_PACKED;
422
423struct ieee80211_country_ie {
424 u_int8_t ie; /* IEEE80211_ELEMID_COUNTRY */
425 u_int8_t len;
426 u_int8_t cc[3]; /* ISO CC+(I)ndoor/(O)utdoor */
427 struct {
428 u_int8_t schan; /* starting channel */
429 u_int8_t nchan; /* number channels */
430 u_int8_t maxtxpwr; /* tx power cap */
431 } GNUNET_PACKED band[4]; /* up to 4 sub bands */
432} GNUNET_PACKED;
433
434#define IEEE80211_CHALLENGE_LEN 128
435
436#define IEEE80211_RATE_BASIC 0x80
437#define IEEE80211_RATE_VAL 0x7f
438
439/* EPR information element flags */
440#define IEEE80211_ERP_NON_ERP_PRESENT 0x01
441#define IEEE80211_ERP_USE_PROTECTION 0x02
442#define IEEE80211_ERP_LONG_PREAMBLE 0x04
443
444/* Atheros private advanced capabilities info */
445#define ATHEROS_CAP_TURBO_PRIME 0x01
446#define ATHEROS_CAP_COMPRESSION 0x02
447#define ATHEROS_CAP_FAST_FRAME 0x04
448/* bits 3-6 reserved */
449#define ATHEROS_CAP_BOOST 0x80
450
451#define ATH_OUI 0x7f0300 /* Atheros OUI */
452#define ATH_OUI_TYPE 0x01
453#define ATH_OUI_VERSION 0x01
454
455#define WPA_OUI 0xf25000
456#define WPA_OUI_TYPE 0x01
457#define WPA_VERSION 1 /* current supported version */
458
459#define WPA_CSE_NULL 0x00
460#define WPA_CSE_WEP40 0x01
461#define WPA_CSE_TKIP 0x02
462#define WPA_CSE_CCMP 0x04
463#define WPA_CSE_WEP104 0x05
464
465#define WPA_ASE_NONE 0x00
466#define WPA_ASE_8021X_UNSPEC 0x01
467#define WPA_ASE_8021X_PSK 0x02
468
469#define RSN_OUI 0xac0f00
470#define RSN_VERSION 1 /* current supported version */
471
472#define RSN_CSE_NULL 0x00
473#define RSN_CSE_WEP40 0x01
474#define RSN_CSE_TKIP 0x02
475#define RSN_CSE_WRAP 0x03
476#define RSN_CSE_CCMP 0x04
477#define RSN_CSE_WEP104 0x05
478
479#define RSN_ASE_NONE 0x00
480#define RSN_ASE_8021X_UNSPEC 0x01
481#define RSN_ASE_8021X_PSK 0x02
482
483#define RSN_CAP_PREAUTH 0x01
484
485#define WME_OUI 0xf25000
486#define WME_OUI_TYPE 0x02
487#define WME_INFO_OUI_SUBTYPE 0x00
488#define WME_PARAM_OUI_SUBTYPE 0x01
489#define WME_VERSION 1
490
491/* WME stream classes */
492#define WME_AC_BE 0 /* best effort */
493#define WME_AC_BK 1 /* background */
494#define WME_AC_VI 2 /* video */
495#define WME_AC_VO 3 /* voice */
496
497/*
498 * AUTH management packets
499 *
500 * octet algo[2]
501 * octet seq[2]
502 * octet status[2]
503 * octet chal.id
504 * octet chal.length
505 * octet chal.text[253]
506 */
507
508typedef u_int8_t *ieee80211_mgt_auth_t;
509
510#define IEEE80211_AUTH_ALGORITHM(auth) \
511 ((auth)[0] | ((auth)[1] << 8))
512#define IEEE80211_AUTH_TRANSACTION(auth) \
513 ((auth)[2] | ((auth)[3] << 8))
514#define IEEE80211_AUTH_STATUS(auth) \
515 ((auth)[4] | ((auth)[5] << 8))
516
517#define IEEE80211_AUTH_ALG_OPEN 0x0000
518#define IEEE80211_AUTH_ALG_SHARED 0x0001
519#define IEEE80211_AUTH_ALG_LEAP 0x0080
520
521enum {
522 IEEE80211_AUTH_OPEN_REQUEST = 1,
523 IEEE80211_AUTH_OPEN_RESPONSE = 2,
524};
525
526enum {
527 IEEE80211_AUTH_SHARED_REQUEST = 1,
528 IEEE80211_AUTH_SHARED_CHALLENGE = 2,
529 IEEE80211_AUTH_SHARED_RESPONSE = 3,
530 IEEE80211_AUTH_SHARED_PASS = 4,
531};
532
533/*
534 * Reason codes
535 *
536 * Unlisted codes are reserved
537 */
538
539enum {
540 IEEE80211_REASON_UNSPECIFIED = 1,
541 IEEE80211_REASON_AUTH_EXPIRE = 2,
542 IEEE80211_REASON_AUTH_LEAVE = 3,
543 IEEE80211_REASON_ASSOC_EXPIRE = 4,
544 IEEE80211_REASON_ASSOC_TOOMANY = 5,
545 IEEE80211_REASON_NOT_AUTHED = 6,
546 IEEE80211_REASON_NOT_ASSOCED = 7,
547 IEEE80211_REASON_ASSOC_LEAVE = 8,
548 IEEE80211_REASON_ASSOC_NOT_AUTHED = 9,
549
550 IEEE80211_REASON_RSN_REQUIRED = 11,
551 IEEE80211_REASON_RSN_INCONSISTENT = 12,
552 IEEE80211_REASON_IE_INVALID = 13,
553 IEEE80211_REASON_MIC_FAILURE = 14,
554
555 IEEE80211_STATUS_SUCCESS = 0,
556 IEEE80211_STATUS_UNSPECIFIED = 1,
557 IEEE80211_STATUS_CAPINFO = 10,
558 IEEE80211_STATUS_NOT_ASSOCED = 11,
559 IEEE80211_STATUS_OTHER = 12,
560 IEEE80211_STATUS_ALG = 13,
561 IEEE80211_STATUS_SEQUENCE = 14,
562 IEEE80211_STATUS_CHALLENGE = 15,
563 IEEE80211_STATUS_TIMEOUT = 16,
564 IEEE80211_STATUS_TOOMANY = 17,
565 IEEE80211_STATUS_BASIC_RATE = 18,
566 IEEE80211_STATUS_SP_REQUIRED = 19,
567 IEEE80211_STATUS_PBCC_REQUIRED = 20,
568 IEEE80211_STATUS_CA_REQUIRED = 21,
569 IEEE80211_STATUS_TOO_MANY_STATIONS = 22,
570 IEEE80211_STATUS_RATES = 23,
571 IEEE80211_STATUS_SHORTSLOT_REQUIRED = 25,
572 IEEE80211_STATUS_DSSSOFDM_REQUIRED = 26,
573};
574
575#define IEEE80211_WEP_KEYLEN 5 /* 40bit */
576#define IEEE80211_WEP_IVLEN 3 /* 24bit */
577#define IEEE80211_WEP_KIDLEN 1 /* 1 octet */
578#define IEEE80211_WEP_CRCLEN 4 /* CRC-32 */
579#define IEEE80211_WEP_NKID 4 /* number of key ids */
580
581/*
582 * 802.11i defines an extended IV for use with non-WEP ciphers.
583 * When the EXTIV bit is set in the key id byte an additional
584 * 4 bytes immediately follow the IV for TKIP. For CCMP the
585 * EXTIV bit is likewise set but the 8 bytes represent the
586 * CCMP header rather than IV+extended-IV.
587 */
588#define IEEE80211_WEP_EXTIV 0x20
589#define IEEE80211_WEP_EXTIVLEN 4 /* extended IV length */
590#define IEEE80211_WEP_MICLEN 8 /* trailing MIC */
591
592#define IEEE80211_CRC_LEN 4
593
594/*
595 * Maximum acceptable MTU is:
596 * IEEE80211_MAX_LEN - WEP overhead - CRC -
597 * QoS overhead - RSN/WPA overhead
598 * Min is arbitrarily chosen > IEEE80211_MIN_LEN. The default
599 * mtu is Ethernet-compatible; it's set by ether_ifattach.
600 */
601#define IEEE80211_MTU_MAX 2290
602#define IEEE80211_MTU_MIN 32
603
604#define IEEE80211_MAX_LEN (2300 + IEEE80211_CRC_LEN + \
605 (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN))
606#define IEEE80211_ACK_LEN \
607 (sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN)
608#define IEEE80211_MIN_LEN \
609 (sizeof(struct ieee80211_frame_min) + IEEE80211_CRC_LEN)
610
611/*
612 * The 802.11 spec says at most 2007 stations may be
613 * associated at once. For most AP's this is way more
614 * than is feasible so we use a default of 128. This
615 * number may be overridden by the driver and/or by
616 * user configuration.
617 */
618#define IEEE80211_AID_MAX 2007
619#define IEEE80211_AID_DEF 128
620
621#define IEEE80211_AID(b) ((b) &~ 0xc000)
622
623/*
624 * RTS frame length parameters. The default is specified in
625 * the 802.11 spec as 512; we treat it as implementation-dependent
626 * so it's defined in ieee80211_var.h. The max may be wrong
627 * for jumbo frames.
628 */
629#define IEEE80211_RTS_MIN 1
630#define IEEE80211_RTS_MAX 2346
631
632/*
633 * TX fragmentation parameters. As above for RTS, we treat
634 * default as implementation-dependent so define it elsewhere.
635 */
636#define IEEE80211_FRAG_MIN 256
637#define IEEE80211_FRAG_MAX 2346
638
639/*
640 * Beacon interval (TU's). Min+max come from WiFi requirements.
641 * As above, we treat default as implementation-dependent so
642 * define it elsewhere.
643 */
644#define IEEE80211_BINTVAL_MAX 1000 /* max beacon interval (TU's) */
645#define IEEE80211_BINTVAL_MIN 25 /* min beacon interval (TU's) */
646
647/*
648 * DTIM period (beacons). Min+max are not really defined
649 * by the protocol but we want them publicly visible so
650 * define them here.
651 */
652#define IEEE80211_DTIM_MAX 15 /* max DTIM period */
653#define IEEE80211_DTIM_MIN 1 /* min DTIM period */
654
655/*
656 * Beacon miss threshold (beacons). As for DTIM, we define
657 * them here to be publicly visible. Note the max may be
658 * clamped depending on device capabilities.
659 */
660#define IEEE80211_HWBMISS_MIN 1
661#define IEEE80211_HWBMISS_MAX 255
662
663#endif /* _NET80211_IEEE80211_H_ */
diff --git a/src/transport/wlan/ieee80211_radiotap.h b/src/transport/wlan/ieee80211_radiotap.h
new file mode 100644
index 000000000..b132d402d
--- /dev/null
+++ b/src/transport/wlan/ieee80211_radiotap.h
@@ -0,0 +1,260 @@
1/* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 sam Exp $ */
2/* $NetBSD: ieee80211_radiotap.h,v 1.11 2005/06/22 06:16:02 dyoung Exp $ */
3
4/*-
5 * Copyright (c) 2003, 2004 David Young. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of David Young may not be used to endorse or promote
16 * products derived from this software without specific prior
17 * written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
23 * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 * OF SUCH DAMAGE.
31 */
32
33/*
34 * Modifications to fit into the linux IEEE 802.11 stack,
35 * Mike Kershaw (dragorn@kismetwireless.net)
36 */
37
38#ifndef IEEE80211RADIOTAP_H
39#define IEEE80211RADIOTAP_H
40
41/* Radiotap header version (from official NetBSD feed) */
42#define IEEE80211RADIOTAP_VERSION "1.5"
43/* Base version of the radiotap packet header data */
44#define PKTHDR_RADIOTAP_VERSION 0
45
46/* A generic radio capture format is desirable. There is one for
47 * Linux, but it is neither rigidly defined (there were not even
48 * units given for some fields) nor easily extensible.
49 *
50 * I suggest the following extensible radio capture format. It is
51 * based on a bitmap indicating which fields are present.
52 *
53 * I am trying to describe precisely what the application programmer
54 * should expect in the following, and for that reason I tell the
55 * units and origin of each measurement (where it applies), or else I
56 * use sufficiently weaselly language ("is a monotonically nondecreasing
57 * function of...") that I cannot set false expectations for lawyerly
58 * readers.
59 */
60
61/* XXX tcpdump/libpcap do not tolerate variable-length headers,
62 * yet, so we pad every radiotap header to 64 bytes. Ugh.
63 */
64#define IEEE80211_RADIOTAP_HDRLEN 64
65
66/* The radio capture header precedes the 802.11 header.
67 * All data in the header is little endian on all platforms.
68 */
69struct ieee80211_radiotap_header {
70 u8 it_version; /* Version 0. Only increases
71 * for drastic changes,
72 * introduction of compatible
73 * new fields does not count.
74 */
75 u8 it_pad;
76 u16 it_len; /* length of the whole
77 * header in bytes, including
78 * it_version, it_pad,
79 * it_len, and data fields.
80 */
81 u32 it_present; /* A bitmap telling which
82 * fields are present. Set bit 31
83 * (0x80000000) to extend the
84 * bitmap by another 32 bits.
85 * Additional extensions are made
86 * by setting bit 31.
87 */
88};
89
90#define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK 0x80000000
91
92/* Name Data type Units
93 * ---- --------- -----
94 *
95 * IEEE80211_RADIOTAP_TSFT __le64 microseconds
96 *
97 * Value in microseconds of the MAC's 64-bit 802.11 Time
98 * Synchronization Function timer when the first bit of the
99 * MPDU arrived at the MAC. For received frames, only.
100 *
101 * IEEE80211_RADIOTAP_CHANNEL 2 x __le16 MHz, bitmap
102 *
103 * Tx/Rx frequency in MHz, followed by flags (see below).
104 *
105 * IEEE80211_RADIOTAP_FHSS __le16 see below
106 *
107 * For frequency-hopping radios, the hop set (first byte)
108 * and pattern (second byte).
109 *
110 * IEEE80211_RADIOTAP_RATE u8 500kb/s
111 *
112 * Tx/Rx data rate
113 *
114 * IEEE80211_RADIOTAP_DBM_ANTSIGNAL s8 decibels from
115 * one milliwatt (dBm)
116 *
117 * RF signal power at the antenna, decibel difference from
118 * one milliwatt.
119 *
120 * IEEE80211_RADIOTAP_DBM_ANTNOISE s8 decibels from
121 * one milliwatt (dBm)
122 *
123 * RF noise power at the antenna, decibel difference from one
124 * milliwatt.
125 *
126 * IEEE80211_RADIOTAP_DB_ANTSIGNAL u8 decibel (dB)
127 *
128 * RF signal power at the antenna, decibel difference from an
129 * arbitrary, fixed reference.
130 *
131 * IEEE80211_RADIOTAP_DB_ANTNOISE u8 decibel (dB)
132 *
133 * RF noise power at the antenna, decibel difference from an
134 * arbitrary, fixed reference point.
135 *
136 * IEEE80211_RADIOTAP_LOCK_QUALITY __le16 unitless
137 *
138 * Quality of Barker code lock. Unitless. Monotonically
139 * nondecreasing with "better" lock strength. Called "Signal
140 * Quality" in datasheets. (Is there a standard way to measure
141 * this?)
142 *
143 * IEEE80211_RADIOTAP_TX_ATTENUATION __le16 unitless
144 *
145 * Transmit power expressed as unitless distance from max
146 * power set at factory calibration. 0 is max power.
147 * Monotonically nondecreasing with lower power levels.
148 *
149 * IEEE80211_RADIOTAP_DB_TX_ATTENUATION __le16 decibels (dB)
150 *
151 * Transmit power expressed as decibel distance from max power
152 * set at factory calibration. 0 is max power. Monotonically
153 * nondecreasing with lower power levels.
154 *
155 * IEEE80211_RADIOTAP_DBM_TX_POWER s8 decibels from
156 * one milliwatt (dBm)
157 *
158 * Transmit power expressed as dBm (decibels from a 1 milliwatt
159 * reference). This is the absolute power level measured at
160 * the antenna port.
161 *
162 * IEEE80211_RADIOTAP_FLAGS u8 bitmap
163 *
164 * Properties of transmitted and received frames. See flags
165 * defined below.
166 *
167 * IEEE80211_RADIOTAP_ANTENNA u8 antenna index
168 *
169 * Unitless indication of the Rx/Tx antenna for this packet.
170 * The first antenna is antenna 0.
171 *
172 * IEEE80211_RADIOTAP_RX_FLAGS __le16 bitmap
173 *
174 * Properties of received frames. See flags defined below.
175 *
176 * IEEE80211_RADIOTAP_TX_FLAGS __le16 bitmap
177 *
178 * Properties of transmitted frames. See flags defined below.
179 *
180 * IEEE80211_RADIOTAP_RTS_RETRIES u8 data
181 *
182 * Number of rts retries a transmitted frame used.
183 *
184 * IEEE80211_RADIOTAP_DATA_RETRIES u8 data
185 *
186 * Number of unicast retries a transmitted frame used.
187 *
188 */
189enum ieee80211_radiotap_type {
190 IEEE80211_RADIOTAP_TSFT = 0,
191 IEEE80211_RADIOTAP_FLAGS = 1,
192 IEEE80211_RADIOTAP_RATE = 2,
193 IEEE80211_RADIOTAP_CHANNEL = 3,
194 IEEE80211_RADIOTAP_FHSS = 4,
195 IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
196 IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
197 IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
198 IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
199 IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
200 IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
201 IEEE80211_RADIOTAP_ANTENNA = 11,
202 IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
203 IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
204 IEEE80211_RADIOTAP_RX_FLAGS = 14,
205 IEEE80211_RADIOTAP_TX_FLAGS = 15,
206 IEEE80211_RADIOTAP_RTS_RETRIES = 16,
207 IEEE80211_RADIOTAP_DATA_RETRIES = 17,
208 IEEE80211_RADIOTAP_EXT = 31
209};
210
211/* Channel flags. */
212#define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */
213#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */
214#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */
215#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */
216#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */
217#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */
218#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */
219#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */
220
221/* For IEEE80211_RADIOTAP_FLAGS */
222#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
223 * during CFP
224 */
225#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
226 * with short
227 * preamble
228 */
229#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
230 * with WEP encryption
231 */
232#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
233 * with fragmentation
234 */
235#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
236#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
237 * 802.11 header and payload
238 * (to 32-bit boundary)
239 */
240/* For IEEE80211_RADIOTAP_RX_FLAGS */
241#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */
242
243/* For IEEE80211_RADIOTAP_TX_FLAGS */
244#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive
245 * retries */
246#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */
247#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
248#define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008 /* frame should not be ACKed */
249#define IEEE80211_RADIOTAP_F_TX_NOSEQ 0x0010 /* sequence number handled
250 * by userspace */
251
252/* Ugly macro to convert literal channel numbers into their mhz equivalents
253 * There are certianly some conditions that will break this (like feeding it '30')
254 * but they shouldn't arise since nothing talks on channel 30. */
255#define ieee80211chan2mhz(x) \
256 (((x) <= 14) ? \
257 (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \
258 ((x) + 1000) * 5)
259
260#endif /* IEEE80211_RADIOTAP_H */
diff --git a/src/transport/wlan/loopback_helper.c b/src/transport/wlan/loopback_helper.c
new file mode 100644
index 000000000..adeff06a2
--- /dev/null
+++ b/src/transport/wlan/loopback_helper.c
@@ -0,0 +1,428 @@
1
2
3#include <sys/socket.h>
4#include <sys/ioctl.h>
5#include <sys/types.h>
6#include <sys/wait.h>
7#include <sys/time.h>
8#include <sys/stat.h>
9#include <stdio.h>
10#include <stdlib.h>
11
12#include <errno.h>
13#include <resolv.h>
14#include <string.h>
15#include <utime.h>
16#include <unistd.h>
17#include <getopt.h>
18
19#include "gnunet_constants.h"
20#include "gnunet_os_lib.h"
21#include "gnunet_transport_plugin.h"
22#include "transport.h"
23#include "gnunet_util_lib.h"
24#include "plugin_transport_wlan.h"
25#include "gnunet_common.h"
26#include "gnunet-transport-wlan-helper.h"
27#include "gnunet_crypto_lib.h"
28#include "loopback_helper.h"
29#include "helper_common.h"
30
31extern int first;
32
33static void
34sigfunc(int sig)
35{
36 closeprog = 1;
37 unlink(FIFO_FILE1);
38 unlink(FIFO_FILE2);
39}
40
41static void
42stdin_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
43{
44 struct sendbuf *write_pout = cls;
45 int sendsize;
46 struct GNUNET_MessageHeader newheader;
47 unsigned char * from;
48 unsigned char * to;
49
50 sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send);
51
52 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type))
53 {
54 fprintf(stderr, "Function stdin_send: wrong packet type\n");
55 exit(1);
56 }
57 if ((sendsize + write_pout->size) > MAXLINE * 2)
58 {
59 fprintf(stderr, "Function stdin_send: Packet too big for buffer\n");
60 exit(1);
61 }
62
63 newheader.size = htons(sendsize);
64 newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
65
66 to = write_pout->buf + write_pout->size;
67 memcpy(to, &newheader, sizeof(struct GNUNET_MessageHeader));
68 write_pout->size += sizeof(struct GNUNET_MessageHeader);
69
70 from = ((unsigned char *) hdr) + sizeof(struct Radiotap_Send)
71 + sizeof(struct GNUNET_MessageHeader);
72 to = write_pout->buf + write_pout->size;
73 memcpy(to, from, sendsize - sizeof(struct GNUNET_MessageHeader));
74 write_pout->size += sendsize - sizeof(struct GNUNET_MessageHeader);
75}
76
77static void
78file_in_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
79{
80 struct sendbuf * write_std = cls;
81 uint16_t sendsize;
82
83 sendsize = ntohs(hdr->size);
84
85 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type))
86 {
87 fprintf(stderr, "Function file_in_send: wrong packet type\n");
88 exit(1);
89 }
90 if ((sendsize + write_std->size) > MAXLINE * 2)
91 {
92 fprintf(stderr, "Function file_in_send: Packet too big for buffer\n");
93 exit(1);
94 }
95
96 memcpy(write_std->buf + write_std->size, hdr, sendsize);
97 write_std->size += sendsize;
98}
99
100int
101testmode(int argc, char *argv[])
102{
103 struct stat st;
104 int erg;
105
106 FILE *fpin;
107 FILE *fpout;
108
109 int fdpin;
110 int fdpout;
111
112 //make the fifos if needed
113 if (0 != stat(FIFO_FILE1, &st))
114 {
115 if (0 == stat(FIFO_FILE2, &st))
116 {
117 fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n");
118 exit(1);
119 }
120
121 umask(0);
122 erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0);
123 erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0);
124
125 }
126 else
127 {
128
129 if (0 != stat(FIFO_FILE2, &st))
130 {
131 fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n");
132 exit(1);
133 }
134
135 }
136
137 if (strstr(argv[2], "1"))
138 {
139 //fprintf(stderr, "First\n");
140 first = 1;
141 fpin = fopen(FIFO_FILE1, "r");
142 if (NULL == fpin)
143 {
144 fprintf(stderr, "fopen of read FIFO_FILE1\n");
145 exit(1);
146 }
147 if (NULL == (fpout = fopen(FIFO_FILE2, "w")))
148 {
149 fprintf(stderr, "fopen of write FIFO_FILE2\n");
150 exit(1);
151 }
152
153 }
154 else
155 {
156 first = 0;
157 //fprintf(stderr, "Second\n");
158 if (NULL == (fpout = fopen(FIFO_FILE1, "w")))
159 {
160 fprintf(stderr, "fopen of write FIFO_FILE1\n");
161 exit(1);
162 }
163 if (NULL == (fpin = fopen(FIFO_FILE2, "r")))
164 {
165 fprintf(stderr, "fopen of read FIFO_FILE2\n");
166 exit(1);
167 }
168
169 }
170
171 fdpin = fileno(fpin);
172 if (fdpin >= FD_SETSIZE)
173 {
174 fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin,
175 (unsigned int) FD_SETSIZE);
176 close(fdpin);
177 return -1;
178 }
179
180 fdpout = fileno(fpout);
181 if (fdpout >= FD_SETSIZE)
182 {
183 fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout,
184 (unsigned int) FD_SETSIZE);
185 close(fdpout);
186 return -1;
187
188 }
189
190 signal(SIGINT, &sigfunc);
191 signal(SIGTERM, &sigfunc);
192
193 char readbuf[MAXLINE];
194 int readsize = 0;
195 struct sendbuf write_std;
196 write_std.size = 0;
197 write_std.pos = 0;
198
199 struct sendbuf write_pout;
200 write_pout.size = 0;
201 write_pout.pos = 0;
202
203 int ret = 0;
204 int maxfd = 0;
205
206 fd_set rfds;
207 fd_set wfds;
208 struct timeval tv;
209 int retval;
210
211 struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst;
212 struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst;
213
214 stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout);
215 file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std);
216
217 //send mac first
218
219 struct MacAddress macaddr;
220
221 //Send random mac address
222 macaddr.mac[0] = 0x13;
223 macaddr.mac[1] = 0x22;
224 macaddr.mac[2] = 0x33;
225 macaddr.mac[3] = 0x44;
226 macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256);
227 macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256);
228
229 write_std.size = send_mac_to_plugin((char *) write_std.buf, macaddr.mac);
230
231 /*
232 //wait
233 tv.tv_sec = 2;
234 tv.tv_usec = 0;
235 retval = select(0, NULL, NULL, NULL, &tv);
236
237
238 tv.tv_sec = 3;
239 tv.tv_usec = 0;
240 // if there is something to write
241 FD_ZERO(&wfds);
242 FD_SET(STDOUT_FILENO, &wfds);
243
244 retval = select(STDOUT_FILENO + 1, NULL, &wfds, NULL, &tv);
245
246 if (FD_ISSET(STDOUT_FILENO, &wfds))
247 {
248 ret = write(STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size
249 - write_std.pos);
250
251 if (0 > ret)
252 {
253 closeprog = 1;
254 fprintf(stderr, "Write ERROR to STDOUT");
255 exit(1);
256 }
257 else
258 {
259 write_std.pos += ret;
260 // check if finished
261 if (write_std.pos == write_std.size)
262 {
263 write_std.pos = 0;
264 write_std.size = 0;
265 }
266 }
267 }
268
269 memcpy(&write_std.buf, &macmsg, sizeof(struct Wlan_Helper_Control_Message));
270 write_std.size = sizeof(struct Wlan_Helper_Control_Message);
271 */
272
273 //wait
274 tv.tv_sec = 2;
275 tv.tv_usec = 0;
276 retval = select(0, NULL, NULL, NULL, &tv);
277
278 while (0 == closeprog)
279 {
280
281 maxfd = 0;
282
283 //set timeout
284 tv.tv_sec = 5;
285 tv.tv_usec = 0;
286
287 FD_ZERO(&rfds);
288 // if output queue is empty
289 if (0 == write_pout.size)
290 {
291 FD_SET(STDIN_FILENO, &rfds);
292
293 }
294 if (0 == write_std.size)
295 {
296 FD_SET(fdpin, &rfds);
297 maxfd = fdpin;
298 }
299 FD_ZERO(&wfds);
300 // if there is something to write
301 if (0 < write_std.size)
302 {
303 FD_SET(STDOUT_FILENO, &wfds);
304 maxfd = MAX(maxfd, STDOUT_FILENO);
305 }
306
307 if (0 < write_pout.size)
308 {
309 FD_SET(fdpout, &wfds);
310 maxfd = MAX(maxfd, fdpout);
311 }
312
313 retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv);
314
315 if (-1 == retval && EINTR == errno)
316 {
317 continue;
318 }
319 if (0 > retval)
320 {
321 fprintf(stderr, "select failed: %s\n", strerror(errno));
322 exit(1);
323 }
324
325 if (FD_ISSET(STDOUT_FILENO, &wfds))
326 {
327 ret = write(STDOUT_FILENO, write_std.buf + write_std.pos,
328 write_std.size - write_std.pos);
329
330 if (0 > ret)
331 {
332 closeprog = 1;
333 fprintf(stderr, "Write ERROR to STDOUT\n");
334 exit(1);
335 }
336 else
337 {
338 write_std.pos += ret;
339 // check if finished
340 if (write_std.pos == write_std.size)
341 {
342 write_std.pos = 0;
343 write_std.size = 0;
344 }
345 }
346 }
347
348 if (FD_ISSET(fdpout, &wfds))
349 {
350 ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size
351 - write_pout.pos);
352
353 if (0 > ret)
354 {
355 closeprog = 1;
356 fprintf(stderr, "Write ERROR to fdpout\n");
357 }
358 else
359 {
360 write_pout.pos += ret;
361 // check if finished
362 if (write_pout.pos == write_pout.size)
363 {
364 write_pout.pos = 0;
365 write_pout.size = 0;
366 }
367 }
368 }
369
370 if (FD_ISSET(STDIN_FILENO, &rfds))
371 {
372 readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf));
373
374 if (0 > readsize)
375 {
376 closeprog = 1;
377 fprintf(stderr, "Read ERROR to STDIN_FILENO\n");
378 }
379 else if (0 < readsize)
380 {
381 GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize,
382 GNUNET_NO, GNUNET_NO);
383
384 }
385 else
386 {
387 //eof
388 closeprog = 1;
389 }
390 }
391
392 if (FD_ISSET(fdpin, &rfds))
393 {
394 readsize = read(fdpin, readbuf, sizeof(readbuf));
395
396 if (0 > readsize)
397 {
398 closeprog = 1;
399 fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno));
400 closeprog = 1;
401 }
402 else if (0 < readsize)
403 {
404 GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize,
405 GNUNET_NO, GNUNET_NO);
406
407 }
408 else
409 {
410 //eof
411 closeprog = 1;
412 }
413 }
414
415 }
416
417 //clean up
418 fclose(fpout);
419 fclose(fpin);
420
421 if (1 == first)
422 {
423 unlink(FIFO_FILE1);
424 unlink(FIFO_FILE2);
425 }
426
427 return (0);
428}
diff --git a/src/transport/wlan/loopback_helper.h b/src/transport/wlan/loopback_helper.h
new file mode 100644
index 000000000..7c9fd5d07
--- /dev/null
+++ b/src/transport/wlan/loopback_helper.h
@@ -0,0 +1,20 @@
1/*
2 * loopback_helper.h
3 *
4 * Created on: 28.03.2011
5 * Author: David Brodski
6 */
7
8#ifndef LOOPBACK_HELPER_H_
9#define LOOPBACK_HELPER_H_
10
11//static void sigfunc(int sig);
12
13//static void stdin_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr);
14
15//static void file_in_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr);
16
17int
18testmode(int argc, char *argv[]);
19
20#endif /* LOOPBACK_HELPER_H_ */
diff --git a/src/transport/wlan/radiotap-parser.c b/src/transport/wlan/radiotap-parser.c
new file mode 100644
index 000000000..46ea6d542
--- /dev/null
+++ b/src/transport/wlan/radiotap-parser.c
@@ -0,0 +1,251 @@
1 /*
2 * Copyright (c) 2007, 2008, Andy Green <andy@warmcat.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19#include <sys/types.h>
20#include <stdio.h>
21#include <errno.h>
22
23#include "radiotap-parser.h"
24
25
26/*
27 * Radiotap header iteration
28 * implemented in src/radiotap-parser.c
29 *
30 * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator
31 * struct ieee80211_radiotap_iterator (no need to init the struct beforehand)
32 * then loop calling __ieee80211_radiotap_iterator_next()... it returns -1
33 * if there are no more args in the header, or the next argument type index
34 * that is present. The iterator's this_arg member points to the start of the
35 * argument associated with the current argument index that is present,
36 * which can be found in the iterator's this_arg_index member. This arg
37 * index corresponds to the IEEE80211_RADIOTAP_... defines.
38 */
39
40
41int ieee80211_radiotap_iterator_init(
42 struct ieee80211_radiotap_iterator * iterator,
43 struct ieee80211_radiotap_header * radiotap_header,
44 int max_length)
45{
46 if(iterator == NULL)
47 return (-EINVAL);
48
49 if(radiotap_header == NULL)
50 return (-EINVAL);
51 /* Linux only supports version 0 radiotap format */
52
53 if (radiotap_header->it_version)
54 return (-EINVAL);
55
56 /* sanity check for allowed length and radiotap length field */
57
58 if (max_length < (le16_to_cpu(radiotap_header->it_len)))
59 return (-EINVAL);
60
61 iterator->rtheader = radiotap_header;
62 iterator->max_length = le16_to_cpu(radiotap_header->it_len);
63 iterator->arg_index = 0;
64 iterator->bitmap_shifter = le32_to_cpu(radiotap_header->it_present);
65 iterator->arg = ((u8 *)radiotap_header) +
66 sizeof (struct ieee80211_radiotap_header);
67 iterator->this_arg = 0;
68
69 /* find payload start allowing for extended bitmap(s) */
70
71 if (unlikely(iterator->bitmap_shifter &
72 IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) {
73 while (le32_to_cpu(*((u32 *)iterator->arg)) &
74 IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK) {
75 iterator->arg += sizeof (u32);
76
77 /*
78 * check for insanity where the present bitmaps
79 * keep claiming to extend up to or even beyond the
80 * stated radiotap header length
81 */
82
83 if ((((void*)iterator->arg) - ((void*)iterator->rtheader)) >
84 iterator->max_length)
85 return (-EINVAL);
86
87 }
88
89 iterator->arg += sizeof (u32);
90
91 /*
92 * no need to check again for blowing past stated radiotap
93 * header length, becuase ieee80211_radiotap_iterator_next
94 * checks it before it is dereferenced
95 */
96
97 }
98
99 /* we are all initialized happily */
100
101 return (0);
102}
103
104
105/**
106 * ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg
107 * @iterator: radiotap_iterator to move to next arg (if any)
108 *
109 * Returns: next present arg index on success or negative if no more or error
110 *
111 * This function returns the next radiotap arg index (IEEE80211_RADIOTAP_...)
112 * and sets iterator->this_arg to point to the payload for the arg. It takes
113 * care of alignment handling and extended present fields. interator->this_arg
114 * can be changed by the caller. The args pointed to are in little-endian
115 * format.
116 */
117
118int ieee80211_radiotap_iterator_next(
119 struct ieee80211_radiotap_iterator * iterator)
120{
121
122 /*
123 * small length lookup table for all radiotap types we heard of
124 * starting from b0 in the bitmap, so we can walk the payload
125 * area of the radiotap header
126 *
127 * There is a requirement to pad args, so that args
128 * of a given length must begin at a boundary of that length
129 * -- but note that compound args are allowed (eg, 2 x u16
130 * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not
131 * a reliable indicator of alignment requirement.
132 *
133 * upper nybble: content alignment for arg
134 * lower nybble: content length for arg
135 */
136
137 static const u8 rt_sizes[] = {
138 [IEEE80211_RADIOTAP_TSFT] = 0x88,
139 [IEEE80211_RADIOTAP_FLAGS] = 0x11,
140 [IEEE80211_RADIOTAP_RATE] = 0x11,
141 [IEEE80211_RADIOTAP_CHANNEL] = 0x24,
142 [IEEE80211_RADIOTAP_FHSS] = 0x22,
143 [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 0x11,
144 [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 0x11,
145 [IEEE80211_RADIOTAP_LOCK_QUALITY] = 0x22,
146 [IEEE80211_RADIOTAP_TX_ATTENUATION] = 0x22,
147 [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 0x22,
148 [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11,
149 [IEEE80211_RADIOTAP_ANTENNA] = 0x11,
150 [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11,
151 [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11,
152 [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22,
153 [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
154 [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11,
155 [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11
156 /*
157 * add more here as they are defined in
158 * include/net/ieee80211_radiotap.h
159 */
160 };
161
162 /*
163 * for every radiotap entry we can at
164 * least skip (by knowing the length)...
165 */
166
167 while (iterator->arg_index < (int)sizeof (rt_sizes)) {
168 int hit = 0;
169
170 if (!(iterator->bitmap_shifter & 1))
171 goto next_entry; /* arg not present */
172
173 /*
174 * arg is present, account for alignment padding
175 * 8-bit args can be at any alignment
176 * 16-bit args must start on 16-bit boundary
177 * 32-bit args must start on 32-bit boundary
178 * 64-bit args must start on 64-bit boundary
179 *
180 * note that total arg size can differ from alignment of
181 * elements inside arg, so we use upper nybble of length
182 * table to base alignment on
183 *
184 * also note: these alignments are ** relative to the
185 * start of the radiotap header **. There is no guarantee
186 * that the radiotap header itself is aligned on any
187 * kind of boundary.
188 */
189
190 if ((((void*)iterator->arg)-((void*)iterator->rtheader)) &
191 ((rt_sizes[iterator->arg_index] >> 4) - 1))
192 iterator->arg_index +=
193 (rt_sizes[iterator->arg_index] >> 4) -
194 ((((void*)iterator->arg) -
195 ((void*)iterator->rtheader)) &
196 ((rt_sizes[iterator->arg_index] >> 4) - 1));
197
198 /*
199 * this is what we will return to user, but we need to
200 * move on first so next call has something fresh to test
201 */
202
203 iterator->this_arg_index = iterator->arg_index;
204 iterator->this_arg = iterator->arg;
205 hit = 1;
206
207 /* internally move on the size of this arg */
208
209 iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
210
211 /*
212 * check for insanity where we are given a bitmap that
213 * claims to have more arg content than the length of the
214 * radiotap section. We will normally end up equalling this
215 * max_length on the last arg, never exceeding it.
216 */
217
218 if ((((void*)iterator->arg) - ((void*)iterator->rtheader)) >
219 iterator->max_length)
220 return (-EINVAL);
221
222 next_entry:
223
224 iterator->arg_index++;
225 if (unlikely((iterator->arg_index & 31) == 0)) {
226 /* completed current u32 bitmap */
227 if (iterator->bitmap_shifter & 1) {
228 /* b31 was set, there is more */
229 /* move to next u32 bitmap */
230 iterator->bitmap_shifter = le32_to_cpu(
231 *iterator->next_bitmap);
232 iterator->next_bitmap++;
233 } else {
234 /* no more bitmaps: end */
235 iterator->arg_index = sizeof (rt_sizes);
236 }
237 } else { /* just try the next bit */
238 iterator->bitmap_shifter >>= 1;
239 }
240
241 /* if we found a valid arg earlier, return it now */
242
243 if (hit)
244 return (iterator->this_arg_index);
245
246 }
247
248 /* we don't know how to handle any more args, we're done */
249
250 return (-1);
251}
diff --git a/src/transport/wlan/radiotap-parser.h b/src/transport/wlan/radiotap-parser.h
new file mode 100644
index 000000000..b36037369
--- /dev/null
+++ b/src/transport/wlan/radiotap-parser.h
@@ -0,0 +1,78 @@
1/*
2 * Copyright (c) 2007, 2008, Andy Green <andy@warmcat.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18
19#define __user
20#include "byteorder.h"
21#include <stdint.h>
22
23typedef uint64_t u64;
24typedef uint32_t u32;
25typedef uint16_t u16;
26typedef uint8_t u8;
27
28#ifndef unlikely
29#define unlikely(x) (x)
30#endif
31
32#include "ieee80211_radiotap.h"
33
34
35/*
36 * Radiotap header iteration
37 * implemented in src/radiotap-parser.c
38 *
39 * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator
40 * struct ieee80211_radiotap_iterator (no need to init the struct beforehand)
41 * then loop calling __ieee80211_radiotap_iterator_next()... it returns -1
42 * if there are no more args in the header, or the next argument type index
43 * that is present. The iterator's this_arg member points to the start of the
44 * argument associated with the current argument index that is present,
45 * which can be found in the iterator's this_arg_index member. This arg
46 * index corresponds to the IEEE80211_RADIOTAP_... defines.
47 */
48/**
49 * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args
50 * @rtheader: pointer to the radiotap header we are walking through
51 * @max_length: length of radiotap header in cpu byte ordering
52 * @this_arg_index: IEEE80211_RADIOTAP_... index of current arg
53 * @this_arg: pointer to current radiotap arg
54 * @arg_index: internal next argument index
55 * @arg: internal next argument pointer
56 * @next_bitmap: internal pointer to next present u32
57 * @bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present
58 */
59
60struct ieee80211_radiotap_iterator {
61 struct ieee80211_radiotap_header *rtheader;
62 int max_length;
63 int this_arg_index;
64 u8 * this_arg;
65
66 int arg_index;
67 u8 * arg;
68 u32 *next_bitmap;
69 u32 bitmap_shifter;
70};
71
72int ieee80211_radiotap_iterator_init(
73 struct ieee80211_radiotap_iterator * iterator,
74 struct ieee80211_radiotap_header * radiotap_header,
75 int max_length);
76
77int ieee80211_radiotap_iterator_next(
78 struct ieee80211_radiotap_iterator * iterator);