diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-25 10:11:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-25 10:11:35 +0000 |
commit | ea118db2ec2df22446216c9bf32c025dc4a805f5 (patch) | |
tree | c58f9ae40e2fae18926daa6befac69ebe6027888 /src/transport | |
parent | 87cbb6dba24959428c7a71e1aa125f80584e0249 (diff) | |
download | gnunet-ea118db2ec2df22446216c9bf32c025dc4a805f5.tar.gz gnunet-ea118db2ec2df22446216c9bf32c025dc4a805f5.zip |
some more wlan code cleanup
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-transport-wlan-helper.c | 2069 |
1 files changed, 776 insertions, 1293 deletions
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index d86af27de..c8f5a03fb 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c | |||
@@ -3,17 +3,17 @@ | |||
3 | (C) 2010, 2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2010, 2011 Christian Grothoff (and other contributing authors) |
4 | Copyright (c) 2007, 2008, Andy Green <andy@warmcat.com> | 4 | Copyright (c) 2007, 2008, Andy Green <andy@warmcat.com> |
5 | Copyright (C) 2009 Thomas d'Otreppe | 5 | Copyright (C) 2009 Thomas d'Otreppe |
6 | 6 | ||
7 | GNUnet is free software; you can redistribute it and/or modify | 7 | GNUnet is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published | 8 | it under the terms of the GNU General Public License as published |
9 | by the Free Software Foundation; either version 3, or (at your | 9 | by the Free Software Foundation; either version 3, or (at your |
10 | option) any later version. | 10 | option) any later version. |
11 | 11 | ||
12 | GNUnet is distributed in the hope that it will be useful, but | 12 | GNUnet is distributed in the hope that it will be useful, but |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | General Public License for more details. | 15 | General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License |
18 | along with GNUnet; see the file COPYING. If not, write to the | 18 | along with GNUnet; see the file COPYING. If not, write to the |
19 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
@@ -96,69 +96,32 @@ | |||
96 | #include <errno.h> | 96 | #include <errno.h> |
97 | #include <dirent.h> | 97 | #include <dirent.h> |
98 | #include <sys/param.h> | 98 | #include <sys/param.h> |
99 | #include <endian.h> | ||
100 | #include <unistd.h> | ||
101 | #include <stdint.h> | ||
102 | |||
99 | #include "gnunet_protocols.h" | 103 | #include "gnunet_protocols.h" |
100 | #include "gnunet_server_lib.h" | 104 | #include "gnunet_server_lib.h" |
101 | #include "plugin_transport_wlan.h" | 105 | #include "plugin_transport_wlan.h" |
102 | 106 | ||
103 | typedef uint64_t u64; | 107 | #define DEBUG 1 |
104 | typedef uint32_t u32; | ||
105 | typedef uint16_t u16; | ||
106 | typedef uint8_t u8; | ||
107 | |||
108 | |||
109 | 108 | ||
110 | /* Radiotap header version (from official NetBSD feed) */ | 109 | #define ARPHRD_IEEE80211 801 |
111 | #define IEEE80211RADIOTAP_VERSION "1.5" | 110 | #define ARPHRD_IEEE80211_PRISM 802 |
112 | /* Base version of the radiotap packet header data */ | 111 | #define ARPHRD_IEEE80211_FULL 803 |
113 | #define PKTHDR_RADIOTAP_VERSION 0 | ||
114 | 112 | ||
115 | /* A generic radio capture format is desirable. There is one for | 113 | #define MAC_ADDR_SIZE 6 |
116 | * Linux, but it is neither rigidly defined (there were not even | ||
117 | * units given for some fields) nor easily extensible. | ||
118 | * | ||
119 | * I suggest the following extensible radio capture format. It is | ||
120 | * based on a bitmap indicating which fields are present. | ||
121 | * | ||
122 | * I am trying to describe precisely what the application programmer | ||
123 | * should expect in the following, and for that reason I tell the | ||
124 | * units and origin of each measurement (where it applies), or else I | ||
125 | * use sufficiently weaselly language ("is a monotonically nondecreasing | ||
126 | * function of...") that I cannot set false expectations for lawyerly | ||
127 | * readers. | ||
128 | */ | ||
129 | 114 | ||
130 | /* XXX tcpdump/libpcap do not tolerate variable-length headers, | 115 | /** |
131 | * yet, so we pad every radiotap header to 64 bytes. Ugh. | 116 | * size of 802.11 address |
132 | */ | 117 | */ |
133 | #define IEEE80211_RADIOTAP_HDRLEN 64 | 118 | #define IEEE80211_ADDR_LEN 6 |
134 | 119 | ||
135 | /* The radio capture header precedes the 802.11 header. | 120 | #define MAXLINE 4096 |
136 | * All data in the header is little endian on all platforms. | ||
137 | */ | ||
138 | struct ieee80211_radiotap_header | ||
139 | { | ||
140 | u8 it_version; /* Version 0. Only increases | ||
141 | * for drastic changes, | ||
142 | * introduction of compatible | ||
143 | * new fields does not count. | ||
144 | */ | ||
145 | u8 it_pad; | ||
146 | u16 it_len; /* length of the whole | ||
147 | * header in bytes, including | ||
148 | * it_version, it_pad, | ||
149 | * it_len, and data fields. | ||
150 | */ | ||
151 | u32 it_present; /* A bitmap telling which | ||
152 | * fields are present. Set bit 31 | ||
153 | * (0x80000000) to extend the | ||
154 | * bitmap by another 32 bits. | ||
155 | * Additional extensions are made | ||
156 | * by setting bit 31. | ||
157 | */ | ||
158 | }; | ||
159 | 121 | ||
160 | #define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK 0x80000000 | 122 | #define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK 0x80000000 |
161 | 123 | ||
124 | |||
162 | /* Name Data type Units | 125 | /* Name Data type Units |
163 | * ---- --------- ----- | 126 | * ---- --------- ----- |
164 | * | 127 | * |
@@ -177,7 +140,7 @@ struct ieee80211_radiotap_header | |||
177 | * For frequency-hopping radios, the hop set (first byte) | 140 | * For frequency-hopping radios, the hop set (first byte) |
178 | * and pattern (second byte). | 141 | * and pattern (second byte). |
179 | * | 142 | * |
180 | * IEEE80211_RADIOTAP_RATE u8 500kb/s | 143 | * IEEE80211_RADIOTAP_RATE uint8_t 500kb/s |
181 | * | 144 | * |
182 | * Tx/Rx data rate | 145 | * Tx/Rx data rate |
183 | * | 146 | * |
@@ -193,12 +156,12 @@ struct ieee80211_radiotap_header | |||
193 | * RF noise power at the antenna, decibel difference from one | 156 | * RF noise power at the antenna, decibel difference from one |
194 | * milliwatt. | 157 | * milliwatt. |
195 | * | 158 | * |
196 | * IEEE80211_RADIOTAP_DB_ANTSIGNAL u8 decibel (dB) | 159 | * IEEE80211_RADIOTAP_DB_ANTSIGNAL uint8_t decibel (dB) |
197 | * | 160 | * |
198 | * RF signal power at the antenna, decibel difference from an | 161 | * RF signal power at the antenna, decibel difference from an |
199 | * arbitrary, fixed reference. | 162 | * arbitrary, fixed reference. |
200 | * | 163 | * |
201 | * IEEE80211_RADIOTAP_DB_ANTNOISE u8 decibel (dB) | 164 | * IEEE80211_RADIOTAP_DB_ANTNOISE uint8_t decibel (dB) |
202 | * | 165 | * |
203 | * RF noise power at the antenna, decibel difference from an | 166 | * RF noise power at the antenna, decibel difference from an |
204 | * arbitrary, fixed reference point. | 167 | * arbitrary, fixed reference point. |
@@ -229,12 +192,12 @@ struct ieee80211_radiotap_header | |||
229 | * reference). This is the absolute power level measured at | 192 | * reference). This is the absolute power level measured at |
230 | * the antenna port. | 193 | * the antenna port. |
231 | * | 194 | * |
232 | * IEEE80211_RADIOTAP_FLAGS u8 bitmap | 195 | * IEEE80211_RADIOTAP_FLAGS uint8_t bitmap |
233 | * | 196 | * |
234 | * Properties of transmitted and received frames. See flags | 197 | * Properties of transmitted and received frames. See flags |
235 | * defined below. | 198 | * defined below. |
236 | * | 199 | * |
237 | * IEEE80211_RADIOTAP_ANTENNA u8 antenna index | 200 | * IEEE80211_RADIOTAP_ANTENNA uint8_t antenna index |
238 | * | 201 | * |
239 | * Unitless indication of the Rx/Tx antenna for this packet. | 202 | * Unitless indication of the Rx/Tx antenna for this packet. |
240 | * The first antenna is antenna 0. | 203 | * The first antenna is antenna 0. |
@@ -247,11 +210,11 @@ struct ieee80211_radiotap_header | |||
247 | * | 210 | * |
248 | * Properties of transmitted frames. See flags defined below. | 211 | * Properties of transmitted frames. See flags defined below. |
249 | * | 212 | * |
250 | * IEEE80211_RADIOTAP_RTS_RETRIES u8 data | 213 | * IEEE80211_RADIOTAP_RTS_RETRIES uint8_t data |
251 | * | 214 | * |
252 | * Number of rts retries a transmitted frame used. | 215 | * Number of rts retries a transmitted frame used. |
253 | * | 216 | * |
254 | * IEEE80211_RADIOTAP_DATA_RETRIES u8 data | 217 | * IEEE80211_RADIOTAP_DATA_RETRIES uint8_t data |
255 | * | 218 | * |
256 | * Number of unicast retries a transmitted frame used. | 219 | * Number of unicast retries a transmitted frame used. |
257 | * | 220 | * |
@@ -279,54 +242,140 @@ enum ieee80211_radiotap_type | |||
279 | IEEE80211_RADIOTAP_EXT = 31 | 242 | IEEE80211_RADIOTAP_EXT = 31 |
280 | }; | 243 | }; |
281 | 244 | ||
282 | /* Channel flags. */ | ||
283 | #define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */ | ||
284 | #define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */ | ||
285 | #define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */ | ||
286 | #define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */ | ||
287 | #define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */ | ||
288 | #define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */ | ||
289 | #define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */ | ||
290 | #define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */ | ||
291 | |||
292 | /* For IEEE80211_RADIOTAP_FLAGS */ | 245 | /* For IEEE80211_RADIOTAP_FLAGS */ |
293 | #define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received | 246 | #define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received |
294 | * during CFP | 247 | * during CFP |
295 | */ | 248 | */ |
296 | #define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received | 249 | #define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received |
297 | * with short | 250 | * with short |
298 | * preamble | 251 | * preamble |
299 | */ | 252 | */ |
300 | #define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received | 253 | #define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received |
301 | * with WEP encryption | 254 | * with WEP encryption |
302 | */ | 255 | */ |
303 | #define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received | 256 | #define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received |
304 | * with fragmentation | 257 | * with fragmentation |
305 | */ | 258 | */ |
306 | #define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */ | 259 | #define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */ |
307 | #define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between | 260 | #define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between |
308 | * 802.11 header and payload | 261 | * 802.11 header and payload |
309 | * (to 32-bit boundary) | 262 | * (to 32-bit boundary) |
310 | */ | 263 | */ |
311 | /* For IEEE80211_RADIOTAP_RX_FLAGS */ | 264 | /* For IEEE80211_RADIOTAP_RX_FLAGS */ |
312 | #define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */ | 265 | #define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */ |
313 | 266 | ||
314 | /* For IEEE80211_RADIOTAP_TX_FLAGS */ | 267 | /* For IEEE80211_RADIOTAP_TX_FLAGS */ |
315 | #define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive | 268 | #define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive |
316 | * retries */ | 269 | * retries */ |
317 | #define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */ | 270 | #define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */ |
318 | #define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */ | 271 | #define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */ |
319 | #define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008 /* frame should not be ACKed */ | 272 | #define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008 /* frame should not be ACKed */ |
320 | #define IEEE80211_RADIOTAP_F_TX_NOSEQ 0x0010 /* sequence number handled | 273 | #define IEEE80211_RADIOTAP_F_TX_NOSEQ 0x0010 /* sequence number handled |
321 | * by userspace */ | 274 | * by userspace */ |
275 | |||
276 | |||
277 | /** | ||
278 | * A generic radio capture format is desirable. There is one for | ||
279 | * Linux, but it is neither rigidly defined (there were not even | ||
280 | * units given for some fields) nor easily extensible. | ||
281 | * | ||
282 | * I suggest the following extensible radio capture format. It is | ||
283 | * based on a bitmap indicating which fields are present. | ||
284 | * | ||
285 | * I am trying to describe precisely what the application programmer | ||
286 | * should expect in the following, and for that reason I tell the | ||
287 | * units and origin of each measurement (where it applies), or else I | ||
288 | * use sufficiently weaselly language ("is a monotonically nondecreasing | ||
289 | * function of...") that I cannot set false expectations for lawyerly | ||
290 | * readers. | ||
291 | * | ||
292 | * The radio capture header precedes the 802.11 header. | ||
293 | * All data in the header is little endian on all platforms. | ||
294 | */ | ||
295 | struct ieee80211_radiotap_header | ||
296 | { | ||
297 | /** | ||
298 | * Version 0. Only increases for drastic changes, introduction of | ||
299 | * compatible new fields does not count. | ||
300 | */ | ||
301 | uint8_t it_version; | ||
302 | uint8_t it_pad; | ||
303 | |||
304 | /** | ||
305 | * length of the whole header in bytes, including it_version, | ||
306 | * it_pad, it_len, and data fields. | ||
307 | */ | ||
308 | uint16_t it_len; | ||
309 | |||
310 | /** | ||
311 | * A bitmap telling which fields are present. Set bit 31 | ||
312 | * (0x80000000) to extend the bitmap by another 32 bits. Additional | ||
313 | * extensions are made by setting bit 31. | ||
314 | */ | ||
315 | uint32_t it_present; | ||
316 | }; | ||
317 | |||
318 | struct RadioTapheader | ||
319 | { | ||
320 | struct ieee80211_radiotap_header header; | ||
321 | uint8_t rate; | ||
322 | uint8_t pad1; | ||
323 | uint16_t txflags; | ||
324 | }; | ||
325 | |||
326 | |||
327 | /** | ||
328 | * FIXME. | ||
329 | */ | ||
330 | struct sendbuf | ||
331 | { | ||
332 | unsigned int pos; | ||
333 | unsigned int size; | ||
334 | char buf[MAXLINE * 2]; | ||
335 | }; | ||
336 | |||
337 | |||
338 | /** | ||
339 | * generic definitions for IEEE 802.11 frames | ||
340 | */ | ||
341 | struct ieee80211_frame | ||
342 | { | ||
343 | uint8_t i_fc[2]; | ||
344 | uint8_t i_dur[2]; | ||
345 | uint8_t i_addr1[IEEE80211_ADDR_LEN]; | ||
346 | uint8_t i_addr2[IEEE80211_ADDR_LEN]; | ||
347 | uint8_t i_addr3[IEEE80211_ADDR_LEN]; | ||
348 | uint8_t i_seq[2]; | ||
349 | /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */ | ||
350 | /* see below */ | ||
351 | } GNUNET_PACKED; | ||
352 | |||
353 | |||
354 | /** | ||
355 | * struct for storing the information of the hardware | ||
356 | */ | ||
357 | struct Hardware_Infos | ||
358 | { | ||
359 | |||
360 | /** | ||
361 | * send buffer | ||
362 | */ | ||
363 | struct sendbuf write_pout; | ||
364 | /** | ||
365 | * file descriptor for the raw socket | ||
366 | */ | ||
367 | int fd_raw; | ||
368 | |||
369 | int arptype_in; | ||
370 | |||
371 | /** | ||
372 | * Name of the interface, not necessarily 0-terminated (!). | ||
373 | */ | ||
374 | char iface[IFNAMSIZ]; | ||
375 | |||
376 | struct MacAddress pl_mac; | ||
377 | }; | ||
322 | 378 | ||
323 | /* Ugly macro to convert literal channel numbers into their mhz equivalents | ||
324 | * There are certianly some conditions that will break this (like feeding it '30') | ||
325 | * but they shouldn't arise since nothing talks on channel 30. */ | ||
326 | #define ieee80211chan2mhz(x) \ | ||
327 | (((x) <= 14) ? \ | ||
328 | (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \ | ||
329 | ((x) + 1000) * 5) | ||
330 | 379 | ||
331 | 380 | ||
332 | 381 | ||
@@ -353,362 +402,26 @@ enum ieee80211_radiotap_type | |||
353 | (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \ | 402 | (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \ |
354 | (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) )) | 403 | (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) )) |
355 | /* *INDENT-ON* */ | 404 | /* *INDENT-ON* */ |
356 | /* | ||
357 | * Linux | ||
358 | */ | ||
359 | #if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux__) | ||
360 | #include <endian.h> | ||
361 | #include <unistd.h> | ||
362 | #include <stdint.h> | ||
363 | |||
364 | #ifndef __int8_t_defined | ||
365 | typedef uint64_t u_int64_t; | ||
366 | typedef uint32_t u_int32_t; | ||
367 | typedef uint16_t u_int16_t; | ||
368 | typedef uint8_t u_int8_t; | ||
369 | |||
370 | |||
371 | #endif /* */ | ||
372 | 405 | ||
373 | #ifndef htole16 | 406 | #ifndef htole16 |
374 | #if __BYTE_ORDER == __LITTLE_ENDIAN | 407 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
375 | #define htobe16(x) ___my_swab16 (x) | ||
376 | #define htole16(x) (x) | 408 | #define htole16(x) (x) |
377 | #define be16toh(x) ___my_swab16 (x) | ||
378 | #define le16toh(x) (x) | 409 | #define le16toh(x) (x) |
379 | |||
380 | #define htobe32(x) ___my_swab32 (x) | ||
381 | #define htole32(x) (x) | 410 | #define htole32(x) (x) |
382 | #define be32toh(x) ___my_swab32 (x) | ||
383 | #define le32toh(x) (x) | 411 | #define le32toh(x) (x) |
384 | |||
385 | #define htobe64(x) ___my_swab64 (x) | ||
386 | #define htole64(x) (x) | 412 | #define htole64(x) (x) |
387 | #define be64toh(x) ___my_swab64 (x) | ||
388 | #define le64toh(x) (x) | 413 | #define le64toh(x) (x) |
389 | #else /* */ | 414 | #else |
390 | #define htobe16(x) (x) | ||
391 | #define htole16(x) ___my_swab16 (x) | 415 | #define htole16(x) ___my_swab16 (x) |
392 | #define be16toh(x) (x) | ||
393 | #define le16toh(x) ___my_swab16 (x) | 416 | #define le16toh(x) ___my_swab16 (x) |
394 | |||
395 | #define htobe32(x) (x) | ||
396 | #define htole32(x) ___my_swab32 (x) | 417 | #define htole32(x) ___my_swab32 (x) |
397 | #define be32toh(x) (x) | ||
398 | #define le32toh(x) ___my_swab32 (x) | 418 | #define le32toh(x) ___my_swab32 (x) |
399 | |||
400 | #define htobe64(x) (x) | ||
401 | #define htole64(x) ___my_swab64 (x) | 419 | #define htole64(x) ___my_swab64 (x) |
402 | #define be64toh(x) (x) | ||
403 | #define le64toh(x) ___my_swab64 (x) | 420 | #define le64toh(x) ___my_swab64 (x) |
404 | #endif /* */ | 421 | #endif |
405 | #endif /* */ | 422 | #endif |
406 | |||
407 | #endif /* */ | ||
408 | /* | ||
409 | * Cygwin | ||
410 | */ | ||
411 | #if defined(__CYGWIN32__) | ||
412 | #include <asm/byteorder.h> | ||
413 | #include <unistd.h> | ||
414 | #define __be64_to_cpu(x) ___my_swab64(x) | ||
415 | #define __be32_to_cpu(x) ___my_swab32(x) | ||
416 | #define __be16_to_cpu(x) ___my_swab16(x) | ||
417 | #define __cpu_to_be64(x) ___my_swab64(x) | ||
418 | #define __cpu_to_be32(x) ___my_swab32(x) | ||
419 | #define __cpu_to_be16(x) ___my_swab16(x) | ||
420 | #define __le64_to_cpu(x) (x) | ||
421 | #define __le32_to_cpu(x) (x) | ||
422 | #define __le16_to_cpu(x) (x) | ||
423 | #define __cpu_to_le64(x) (x) | ||
424 | #define __cpu_to_le32(x) (x) | ||
425 | #define __cpu_to_le16(x) (x) | ||
426 | #define AIRCRACK_NG_BYTE_ORDER_DEFINED | ||
427 | #endif /* */ | ||
428 | /* | ||
429 | * Windows (DDK) | ||
430 | */ | ||
431 | #if defined(__WIN__) | ||
432 | #include <io.h> | ||
433 | #define __be64_to_cpu(x) ___my_swab64(x) | ||
434 | #define __be32_to_cpu(x) ___my_swab32(x) | ||
435 | #define __be16_to_cpu(x) ___my_swab16(x) | ||
436 | #define __cpu_to_be64(x) ___my_swab64(x) | ||
437 | #define __cpu_to_be32(x) ___my_swab32(x) | ||
438 | #define __cpu_to_be16(x) ___my_swab16(x) | ||
439 | #define __le64_to_cpu(x) (x) | ||
440 | #define __le32_to_cpu(x) (x) | ||
441 | #define __le16_to_cpu(x) (x) | ||
442 | #define __cpu_to_le64(x) (x) | ||
443 | #define __cpu_to_le32(x) (x) | ||
444 | #define __cpu_to_le16(x) (x) | ||
445 | #define AIRCRACK_NG_BYTE_ORDER_DEFINED | ||
446 | #endif /* */ | ||
447 | /* | ||
448 | * MAC (Darwin) | ||
449 | */ | ||
450 | #if defined(__APPLE_CC__) | ||
451 | #if defined(__x86_64__) && defined(__APPLE__) | ||
452 | #include <libkern/OSByteOrder.h> | ||
453 | #define __swab64(x) (unsigned long long) OSSwapInt64((uint64_t)x) | ||
454 | #define __swab32(x) (unsigned long) OSSwapInt32((uint32_t)x) | ||
455 | #define __swab16(x) (unsigned short) OSSwapInt16((uint16_t)x) | ||
456 | #define __be64_to_cpu(x) (unsigned long long) OSSwapBigToHostInt64((uint64_t)x) | ||
457 | #define __be32_to_cpu(x) (unsigned long) OSSwapBigToHostInt32((uint32_t)x) | ||
458 | #define __be16_to_cpu(x) (unsigned short) OSSwapBigToHostInt16((uint16_t)x) | ||
459 | #define __le64_to_cpu(x) (unsigned long long) OSSwapLittleToHostInt64((uint64_t)x) | ||
460 | #define __le32_to_cpu(x) (unsigned long) OSSwapLittleToHostInt32((uint32_t)x) | ||
461 | #define __le16_to_cpu(x) (unsigned short) OSSwapLittleToHostInt16((uint16_t)x) | ||
462 | #define __cpu_to_be64(x) (unsigned long long) OSSwapHostToBigInt64((uint64_t)x) | ||
463 | #define __cpu_to_be32(x) (unsigned long) OSSwapHostToBigInt32((uint32_t)x) | ||
464 | #define __cpu_to_be16(x) (unsigned short) OSSwapHostToBigInt16((uint16_t)x) | ||
465 | #define __cpu_to_le64(x) (unsigned long long) OSSwapHostToLittleInt64((uint64_t)x) | ||
466 | #define __cpu_to_le32(x) (unsigned long) OSSwapHostToLittleInt32((uint32_t)x) | ||
467 | #define __cpu_to_le16(x) (unsigned short) OSSwapHostToLittleInt16((uint16_t)x) | ||
468 | #else /* */ | ||
469 | #include <architecture/byte_order.h> | ||
470 | #define __swab64(x) NXSwapLongLong(x) | ||
471 | #define __swab32(x) NXSwapLong(x) | ||
472 | #define __swab16(x) NXSwapShort(x) | ||
473 | #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x) | ||
474 | #define __be32_to_cpu(x) NXSwapBigLongToHost(x) | ||
475 | #define __be16_to_cpu(x) NXSwapBigShortToHost(x) | ||
476 | #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x) | ||
477 | #define __le32_to_cpu(x) NXSwapLittleLongToHost(x) | ||
478 | #define __le16_to_cpu(x) NXSwapLittleShortToHost(x) | ||
479 | #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x) | ||
480 | #define __cpu_to_be32(x) NXSwapHostLongToBig(x) | ||
481 | #define __cpu_to_be16(x) NXSwapHostShortToBig(x) | ||
482 | #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x) | ||
483 | #define __cpu_to_le32(x) NXSwapHostLongToLittle(x) | ||
484 | #define __cpu_to_le16(x) NXSwapHostShortToLittle(x) | ||
485 | #endif /* */ | ||
486 | #define __LITTLE_ENDIAN 1234 | ||
487 | #define __BIG_ENDIAN 4321 | ||
488 | #define __PDP_ENDIAN 3412 | ||
489 | #define __BYTE_ORDER __BIG_ENDIAN | ||
490 | #define AIRCRACK_NG_BYTE_ORDER_DEFINED | ||
491 | #endif /* */ | ||
492 | /* | ||
493 | * Solaris | ||
494 | * ------- | ||
495 | */ | ||
496 | #if defined(__sparc__) && defined(__sun__) | ||
497 | #include <sys/byteorder.h> | ||
498 | #include <sys/types.h> | ||
499 | #include <unistd.h> | ||
500 | #define __be64_to_cpu(x) (x) | ||
501 | #define __be32_to_cpu(x) (x) | ||
502 | #define __be16_to_cpu(x) (x) | ||
503 | #define __cpu_to_be64(x) (x) | ||
504 | #define __cpu_to_be32(x) (x) | ||
505 | #define __cpu_to_be16(x) (x) | ||
506 | #define __le64_to_cpu(x) ___my_swab64(x) | ||
507 | #define __le32_to_cpu(x) ___my_swab32(x) | ||
508 | #define __le16_to_cpu(x) ___my_swab16(x) | ||
509 | #define __cpu_to_le64(x) ___my_swab64(x) | ||
510 | #define __cpu_to_le32(x) ___my_swab32(x) | ||
511 | #define __cpu_to_le16(x) ___my_swab16(x) | ||
512 | typedef uint64_t u_int64_t; | ||
513 | typedef uint32_t u_int32_t; | ||
514 | typedef uint16_t u_int16_t; | ||
515 | typedef uint8_t u_int8_t; | ||
516 | |||
517 | |||
518 | #define AIRCRACK_NG_BYTE_ORDER_DEFINED | ||
519 | #endif /* */ | ||
520 | /* | ||
521 | * Custom stuff | ||
522 | */ | ||
523 | #if defined(__MACH__) && !defined(__APPLE_CC__) | ||
524 | #include <libkern/OSByteOrder.h> | ||
525 | #define __cpu_to_be64(x) = OSSwapHostToBigInt64(x) | ||
526 | #define __cpu_to_be32(x) = OSSwapHostToBigInt32(x) | ||
527 | #define AIRCRACK_NG_BYTE_ORDER_DEFINED | ||
528 | #endif /* */ | ||
529 | |||
530 | // FreeBSD | ||
531 | #ifdef __FreeBSD__ | ||
532 | #include <machine/endian.h> | ||
533 | #endif /* */ | ||
534 | // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...? | ||
535 | |||
536 | // XXX: Mac: Check http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h | ||
537 | // http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html | ||
538 | // Write to apple to ask what should be used. | ||
539 | #if defined(LITTLE_ENDIAN) | ||
540 | #define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN | ||
541 | #elif defined(__LITTLE_ENDIAN) | ||
542 | #define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN | ||
543 | #elif defined(_LITTLE_ENDIAN) | ||
544 | #define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN | ||
545 | #endif /* */ | ||
546 | #if defined(BIG_ENDIAN) | ||
547 | #define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN | ||
548 | #elif defined(__BIG_ENDIAN) | ||
549 | #define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN | ||
550 | #elif defined(_BIG_ENDIAN) | ||
551 | #define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN | ||
552 | #endif /* */ | ||
553 | #if !defined(AIRCRACK_NG_LITTLE_ENDIAN) && !defined(AIRCRACK_NG_BIG_ENDIAN) | ||
554 | #error Impossible to determine endianness (Little or Big endian), please contact the author. | ||
555 | #endif /* */ | ||
556 | #if defined(BYTE_ORDER) | ||
557 | #if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN) | ||
558 | #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN | ||
559 | #elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN) | ||
560 | #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN | ||
561 | #endif /* */ | ||
562 | #elif defined(__BYTE_ORDER) | ||
563 | #if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN) | ||
564 | #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN | ||
565 | #elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN) | ||
566 | #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN | ||
567 | #endif /* */ | ||
568 | #elif defined(_BYTE_ORDER) | ||
569 | #if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN) | ||
570 | #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN | ||
571 | #elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN) | ||
572 | #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN | ||
573 | #endif /* */ | ||
574 | #endif /* */ | ||
575 | #ifndef AIRCRACK_NG_BYTE_ORDER | ||
576 | #error Impossible to determine endianness (Little or Big endian), please contact the author. | ||
577 | #endif /* */ | ||
578 | #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN) | ||
579 | #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED | ||
580 | #define __be64_to_cpu(x) ___my_swab64(x) | ||
581 | #define __be32_to_cpu(x) ___my_swab32(x) | ||
582 | #define __be16_to_cpu(x) ___my_swab16(x) | ||
583 | #define __cpu_to_be64(x) ___my_swab64(x) | ||
584 | #define __cpu_to_be32(x) ___my_swab32(x) | ||
585 | #define __cpu_to_be16(x) ___my_swab16(x) | ||
586 | #define __le64_to_cpu(x) (x) | ||
587 | #define __le32_to_cpu(x) (x) | ||
588 | #define __le16_to_cpu(x) (x) | ||
589 | #define __cpu_to_le64(x) (x) | ||
590 | #define __cpu_to_le32(x) (x) | ||
591 | #define __cpu_to_le16(x) (x) | ||
592 | #endif /* */ | ||
593 | #ifndef htobe16 | ||
594 | #define htobe16 ___my_swab16 | ||
595 | #endif /* */ | ||
596 | #ifndef htobe32 | ||
597 | #define htobe32 ___my_swab32 | ||
598 | #endif /* */ | ||
599 | #ifndef betoh16 | ||
600 | #define betoh16 ___my_swab16 | ||
601 | #endif /* */ | ||
602 | #ifndef betoh32 | ||
603 | #define betoh32 ___my_swab32 | ||
604 | #endif /* */ | ||
605 | #ifndef htole16 | ||
606 | #define htole16(x) (x) | ||
607 | #endif /* */ | ||
608 | #ifndef htole32 | ||
609 | #define htole32(x) (x) | ||
610 | #endif /* */ | ||
611 | #ifndef letoh16 | ||
612 | #define letoh16(x) (x) | ||
613 | #endif /* */ | ||
614 | #ifndef letoh32 | ||
615 | #define letoh32(x) (x) | ||
616 | #endif /* */ | ||
617 | #endif /* */ | ||
618 | #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN) | ||
619 | #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED | ||
620 | #define __be64_to_cpu(x) (x) | ||
621 | #define __be32_to_cpu(x) (x) | ||
622 | #define __be16_to_cpu(x) (x) | ||
623 | #define __cpu_to_be64(x) (x) | ||
624 | #define __cpu_to_be32(x) (x) | ||
625 | #define __cpu_to_be16(x) (x) | ||
626 | #define __le64_to_cpu(x) ___my_swab64(x) | ||
627 | #define __le32_to_cpu(x) ___my_swab32(x) | ||
628 | #define __le16_to_cpu(x) ___my_swab16(x) | ||
629 | #define __cpu_to_le64(x) ___my_swab64(x) | ||
630 | #define __cpu_to_le32(x) ___my_swab32(x) | ||
631 | #define __cpu_to_le16(x) ___my_swab16(x) | ||
632 | #endif /* */ | ||
633 | #ifndef htobe16 | ||
634 | #define htobe16(x) (x) | ||
635 | #endif /* */ | ||
636 | #ifndef htobe32 | ||
637 | #define htobe32(x) (x) | ||
638 | #endif /* */ | ||
639 | #ifndef betoh16 | ||
640 | #define betoh16(x) (x) | ||
641 | #endif /* */ | ||
642 | #ifndef betoh32 | ||
643 | #define betoh32(x) (x) | ||
644 | #endif /* */ | ||
645 | #ifndef htole16 | ||
646 | #define htole16 ___my_swab16 | ||
647 | #endif /* */ | ||
648 | #ifndef htole32 | ||
649 | #define htole32 ___my_swab32 | ||
650 | #endif /* */ | ||
651 | #ifndef letoh16 | ||
652 | #define letoh16 ___my_swab16 | ||
653 | #endif /* */ | ||
654 | #ifndef letoh32 | ||
655 | #define letoh32 ___my_swab32 | ||
656 | #endif /* */ | ||
657 | #endif /* */ | ||
658 | // Common defines | ||
659 | #define cpu_to_le64 __cpu_to_le64 | ||
660 | #define le64_to_cpu __le64_to_cpu | ||
661 | #define cpu_to_le32 __cpu_to_le32 | ||
662 | #define le32_to_cpu __le32_to_cpu | ||
663 | #define cpu_to_le16 __cpu_to_le16 | ||
664 | #define le16_to_cpu __le16_to_cpu | ||
665 | #define cpu_to_be64 __cpu_to_be64 | ||
666 | #define be64_to_cpu __be64_to_cpu | ||
667 | #define cpu_to_be32 __cpu_to_be32 | ||
668 | #define be32_to_cpu __be32_to_cpu | ||
669 | #define cpu_to_be16 __cpu_to_be16 | ||
670 | #define be16_to_cpu __be16_to_cpu | ||
671 | #ifndef le16toh | ||
672 | #define le16toh le16_to_cpu | ||
673 | #endif /* */ | ||
674 | #ifndef be16toh | ||
675 | #define be16toh be16_to_cpu | ||
676 | #endif /* */ | ||
677 | #ifndef le32toh | ||
678 | #define le32toh le32_to_cpu | ||
679 | #endif /* */ | ||
680 | #ifndef be32toh | ||
681 | #define be32toh be32_to_cpu | ||
682 | #endif /* */ | ||
683 | |||
684 | #ifndef htons | ||
685 | #define htons be16_to_cpu | ||
686 | #endif /* */ | ||
687 | #ifndef htonl | ||
688 | #define htonl cpu_to_be16 | ||
689 | #endif /* */ | ||
690 | #ifndef ntohs | ||
691 | #define ntohs cpu_to_be16 | ||
692 | #endif /* */ | ||
693 | #ifndef ntohl | ||
694 | #define ntohl cpu_to_be32 | ||
695 | #endif /* */ | ||
696 | |||
697 | 423 | ||
698 | 424 | ||
699 | /* | ||
700 | * Radiotap header iteration | ||
701 | * implemented in src/radiotap-parser.c | ||
702 | * | ||
703 | * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator | ||
704 | * struct ieee80211_radiotap_iterator (no need to init the struct beforehand) | ||
705 | * then loop calling __ieee80211_radiotap_iterator_next()... it returns -1 | ||
706 | * if there are no more args in the header, or the next argument type index | ||
707 | * that is present. The iterator's this_arg member points to the start of the | ||
708 | * argument associated with the current argument index that is present, | ||
709 | * which can be found in the iterator's this_arg_index member. This arg | ||
710 | * index corresponds to the IEEE80211_RADIOTAP_... defines. | ||
711 | */ | ||
712 | /** | 425 | /** |
713 | * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args | 426 | * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args |
714 | * @rtheader: pointer to the radiotap header we are walking through | 427 | * @rtheader: pointer to the radiotap header we are walking through |
@@ -717,27 +430,24 @@ typedef uint8_t u_int8_t; | |||
717 | * @this_arg: pointer to current radiotap arg | 430 | * @this_arg: pointer to current radiotap arg |
718 | * @arg_index: internal next argument index | 431 | * @arg_index: internal next argument index |
719 | * @arg: internal next argument pointer | 432 | * @arg: internal next argument pointer |
720 | * @next_bitmap: internal pointer to next present u32 | 433 | * @next_bitmap: internal pointer to next present uint32_t |
721 | * @bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present | 434 | * @bitmap_shifter: internal shifter for curr uint32_t bitmap, b0 set == arg present |
722 | */ | 435 | */ |
723 | |||
724 | struct ieee80211_radiotap_iterator | 436 | struct ieee80211_radiotap_iterator |
725 | { | 437 | { |
726 | struct ieee80211_radiotap_header *rtheader; | 438 | struct ieee80211_radiotap_header *rtheader; |
727 | int max_length; | 439 | int max_length; |
728 | int this_arg_index; | 440 | int this_arg_index; |
729 | u8 *this_arg; | 441 | uint8_t *this_arg; |
730 | |||
731 | int arg_index; | 442 | int arg_index; |
732 | u8 *arg; | 443 | uint8_t *arg; |
733 | u32 *next_bitmap; | 444 | uint32_t *next_bitmap; |
734 | u32 bitmap_shifter; | 445 | uint32_t bitmap_shifter; |
735 | }; | 446 | }; |
736 | 447 | ||
737 | 448 | ||
738 | /* | 449 | /** |
739 | * Radiotap header iteration | 450 | * Radiotap header iteration |
740 | * implemented in src/radiotap-parser.c | ||
741 | * | 451 | * |
742 | * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator | 452 | * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator |
743 | * struct ieee80211_radiotap_iterator (no need to init the struct beforehand) | 453 | * struct ieee80211_radiotap_iterator (no need to init the struct beforehand) |
@@ -748,12 +458,11 @@ struct ieee80211_radiotap_iterator | |||
748 | * which can be found in the iterator's this_arg_index member. This arg | 458 | * which can be found in the iterator's this_arg_index member. This arg |
749 | * index corresponds to the IEEE80211_RADIOTAP_... defines. | 459 | * index corresponds to the IEEE80211_RADIOTAP_... defines. |
750 | */ | 460 | */ |
751 | |||
752 | |||
753 | int | 461 | int |
754 | ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator, | 462 | ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator |
755 | struct ieee80211_radiotap_header | 463 | *iterator, |
756 | *radiotap_header, int max_length) | 464 | struct ieee80211_radiotap_header |
465 | *radiotap_header, int max_length) | ||
757 | { | 466 | { |
758 | if (iterator == NULL) | 467 | if (iterator == NULL) |
759 | return (-EINVAL); | 468 | return (-EINVAL); |
@@ -767,51 +476,50 @@ ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator, | |||
767 | 476 | ||
768 | /* sanity check for allowed length and radiotap length field */ | 477 | /* sanity check for allowed length and radiotap length field */ |
769 | 478 | ||
770 | if (max_length < (le16_to_cpu (radiotap_header->it_len))) | 479 | if (max_length < (le16toh (radiotap_header->it_len))) |
771 | return (-EINVAL); | 480 | return (-EINVAL); |
772 | 481 | ||
773 | iterator->rtheader = radiotap_header; | 482 | iterator->rtheader = radiotap_header; |
774 | iterator->max_length = le16_to_cpu (radiotap_header->it_len); | 483 | iterator->max_length = le16toh (radiotap_header->it_len); |
775 | iterator->arg_index = 0; | 484 | iterator->arg_index = 0; |
776 | iterator->bitmap_shifter = le32_to_cpu (radiotap_header->it_present); | 485 | iterator->bitmap_shifter = le32toh (radiotap_header->it_present); |
777 | iterator->arg = | 486 | iterator->arg = |
778 | ((u8 *) radiotap_header) + sizeof (struct ieee80211_radiotap_header); | 487 | ((uint8_t *) radiotap_header) + sizeof (struct ieee80211_radiotap_header); |
779 | iterator->this_arg = 0; | 488 | iterator->this_arg = 0; |
780 | 489 | ||
781 | /* find payload start allowing for extended bitmap(s) */ | 490 | /* find payload start allowing for extended bitmap(s) */ |
782 | 491 | ||
783 | if ((iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) | 492 | if ((iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) |
784 | { | ||
785 | while (le32_to_cpu (*((u32 *) iterator->arg)) & | ||
786 | IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK) | ||
787 | { | 493 | { |
788 | iterator->arg += sizeof (u32); | 494 | while (le32toh (*((uint32_t *) iterator->arg)) & |
495 | IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK) | ||
496 | { | ||
497 | iterator->arg += sizeof (uint32_t); | ||
789 | 498 | ||
790 | /* | 499 | /* |
791 | * check for insanity where the present bitmaps | 500 | * check for insanity where the present bitmaps |
792 | * keep claiming to extend up to or even beyond the | 501 | * keep claiming to extend up to or even beyond the |
793 | * stated radiotap header length | 502 | * stated radiotap header length |
794 | */ | 503 | */ |
795 | 504 | ||
796 | if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) > | 505 | if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) > |
797 | iterator->max_length) | 506 | iterator->max_length) |
798 | return (-EINVAL); | 507 | return (-EINVAL); |
799 | 508 | ||
800 | } | 509 | } |
801 | 510 | ||
802 | iterator->arg += sizeof (u32); | 511 | iterator->arg += sizeof (uint32_t); |
803 | 512 | ||
804 | /* | 513 | /* |
805 | * no need to check again for blowing past stated radiotap | 514 | * no need to check again for blowing past stated radiotap |
806 | * header length, becuase ieee80211_radiotap_iterator_next | 515 | * header length, becuase ieee80211_radiotap_iterator_next |
807 | * checks it before it is dereferenced | 516 | * checks it before it is dereferenced |
808 | */ | 517 | */ |
809 | 518 | ||
810 | } | 519 | } |
811 | 520 | ||
812 | /* we are all initialized happily */ | 521 | /* we are all initialized happily */ |
813 | 522 | return 0; | |
814 | return (0); | ||
815 | } | 523 | } |
816 | 524 | ||
817 | 525 | ||
@@ -827,9 +535,9 @@ ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator, | |||
827 | * can be changed by the caller. The args pointed to are in little-endian | 535 | * can be changed by the caller. The args pointed to are in little-endian |
828 | * format. | 536 | * format. |
829 | */ | 537 | */ |
830 | |||
831 | int | 538 | int |
832 | ieee80211_radiotap_iterator_next (struct ieee80211_radiotap_iterator *iterator) | 539 | ieee80211_radiotap_iterator_next (struct ieee80211_radiotap_iterator |
540 | *iterator) | ||
833 | { | 541 | { |
834 | 542 | ||
835 | /* | 543 | /* |
@@ -839,7 +547,7 @@ ieee80211_radiotap_iterator_next (struct ieee80211_radiotap_iterator *iterator) | |||
839 | * | 547 | * |
840 | * There is a requirement to pad args, so that args | 548 | * There is a requirement to pad args, so that args |
841 | * of a given length must begin at a boundary of that length | 549 | * of a given length must begin at a boundary of that length |
842 | * -- but note that compound args are allowed (eg, 2 x u16 | 550 | * -- but note that compound args are allowed (eg, 2 x uint16_t |
843 | * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not | 551 | * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not |
844 | * a reliable indicator of alignment requirement. | 552 | * a reliable indicator of alignment requirement. |
845 | * | 553 | * |
@@ -847,7 +555,7 @@ ieee80211_radiotap_iterator_next (struct ieee80211_radiotap_iterator *iterator) | |||
847 | * lower nybble: content length for arg | 555 | * lower nybble: content length for arg |
848 | */ | 556 | */ |
849 | 557 | ||
850 | static const u8 rt_sizes[] = { | 558 | static const uint8_t rt_sizes[] = { |
851 | [IEEE80211_RADIOTAP_TSFT] = 0x88, | 559 | [IEEE80211_RADIOTAP_TSFT] = 0x88, |
852 | [IEEE80211_RADIOTAP_FLAGS] = 0x11, | 560 | [IEEE80211_RADIOTAP_FLAGS] = 0x11, |
853 | [IEEE80211_RADIOTAP_RATE] = 0x11, | 561 | [IEEE80211_RADIOTAP_RATE] = 0x11, |
@@ -866,10 +574,10 @@ ieee80211_radiotap_iterator_next (struct ieee80211_radiotap_iterator *iterator) | |||
866 | [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22, | 574 | [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22, |
867 | [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11, | 575 | [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11, |
868 | [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11 | 576 | [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11 |
869 | /* | 577 | /* |
870 | * add more here as they are defined in | 578 | * add more here as they are defined in |
871 | * include/net/ieee80211_radiotap.h | 579 | * include/net/ieee80211_radiotap.h |
872 | */ | 580 | */ |
873 | }; | 581 | }; |
874 | 582 | ||
875 | /* | 583 | /* |
@@ -878,237 +586,97 @@ ieee80211_radiotap_iterator_next (struct ieee80211_radiotap_iterator *iterator) | |||
878 | */ | 586 | */ |
879 | 587 | ||
880 | while (iterator->arg_index < (int) sizeof (rt_sizes)) | 588 | while (iterator->arg_index < (int) sizeof (rt_sizes)) |
881 | { | ||
882 | int hit = 0; | ||
883 | |||
884 | if (!(iterator->bitmap_shifter & 1)) | ||
885 | goto next_entry; /* arg not present */ | ||
886 | |||
887 | /* | ||
888 | * arg is present, account for alignment padding | ||
889 | * 8-bit args can be at any alignment | ||
890 | * 16-bit args must start on 16-bit boundary | ||
891 | * 32-bit args must start on 32-bit boundary | ||
892 | * 64-bit args must start on 64-bit boundary | ||
893 | * | ||
894 | * note that total arg size can differ from alignment of | ||
895 | * elements inside arg, so we use upper nybble of length | ||
896 | * table to base alignment on | ||
897 | * | ||
898 | * also note: these alignments are ** relative to the | ||
899 | * start of the radiotap header **. There is no guarantee | ||
900 | * that the radiotap header itself is aligned on any | ||
901 | * kind of boundary. | ||
902 | */ | ||
903 | |||
904 | if ((((void *) iterator->arg) - | ||
905 | ((void *) iterator->rtheader)) & ((rt_sizes[iterator->arg_index] >> 4) | ||
906 | - 1)) | ||
907 | iterator->arg_index += | ||
908 | (rt_sizes[iterator->arg_index] >> 4) - | ||
909 | ((((void *) iterator->arg) - | ||
910 | ((void *) iterator->rtheader)) & ((rt_sizes[iterator->arg_index] >> | ||
911 | 4) - 1)); | ||
912 | |||
913 | /* | ||
914 | * this is what we will return to user, but we need to | ||
915 | * move on first so next call has something fresh to test | ||
916 | */ | ||
917 | |||
918 | iterator->this_arg_index = iterator->arg_index; | ||
919 | iterator->this_arg = iterator->arg; | ||
920 | hit = 1; | ||
921 | |||
922 | /* internally move on the size of this arg */ | ||
923 | |||
924 | iterator->arg += rt_sizes[iterator->arg_index] & 0x0f; | ||
925 | |||
926 | /* | ||
927 | * check for insanity where we are given a bitmap that | ||
928 | * claims to have more arg content than the length of the | ||
929 | * radiotap section. We will normally end up equalling this | ||
930 | * max_length on the last arg, never exceeding it. | ||
931 | */ | ||
932 | |||
933 | if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) > | ||
934 | iterator->max_length) | ||
935 | return (-EINVAL); | ||
936 | |||
937 | next_entry: | ||
938 | |||
939 | iterator->arg_index++; | ||
940 | if (((iterator->arg_index & 31) == 0)) | ||
941 | { | 589 | { |
942 | /* completed current u32 bitmap */ | 590 | int hit = 0; |
943 | if (iterator->bitmap_shifter & 1) | ||
944 | { | ||
945 | /* b31 was set, there is more */ | ||
946 | /* move to next u32 bitmap */ | ||
947 | iterator->bitmap_shifter = le32_to_cpu (*iterator->next_bitmap); | ||
948 | iterator->next_bitmap++; | ||
949 | } | ||
950 | else | ||
951 | { | ||
952 | /* no more bitmaps: end */ | ||
953 | iterator->arg_index = sizeof (rt_sizes); | ||
954 | } | ||
955 | } | ||
956 | else | ||
957 | { /* just try the next bit */ | ||
958 | iterator->bitmap_shifter >>= 1; | ||
959 | } | ||
960 | |||
961 | /* if we found a valid arg earlier, return it now */ | ||
962 | |||
963 | if (hit) | ||
964 | return (iterator->this_arg_index); | ||
965 | |||
966 | } | ||
967 | |||
968 | /* we don't know how to handle any more args, we're done */ | ||
969 | |||
970 | return (-1); | ||
971 | } | ||
972 | 591 | ||
592 | if (!(iterator->bitmap_shifter & 1)) | ||
593 | goto next_entry; /* arg not present */ | ||
973 | 594 | ||
974 | const unsigned long int crc_tbl_osdep[256] = { | 595 | /* |
975 | 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, | 596 | * arg is present, account for alignment padding |
976 | 0xE963A535, 0x9E6495A3, | 597 | * 8-bit args can be at any alignment |
977 | 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, | 598 | * 16-bit args must start on 16-bit boundary |
978 | 0xE7B82D07, 0x90BF1D91, | 599 | * 32-bit args must start on 32-bit boundary |
979 | 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, | 600 | * 64-bit args must start on 64-bit boundary |
980 | 0xF4D4B551, 0x83D385C7, | 601 | * |
981 | 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, | 602 | * note that total arg size can differ from alignment of |
982 | 0xFA0F3D63, 0x8D080DF5, | 603 | * elements inside arg, so we use upper nybble of length |
983 | 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, | 604 | * table to base alignment on |
984 | 0xD20D85FD, 0xA50AB56B, | 605 | * |
985 | 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, | 606 | * also note: these alignments are ** relative to the |
986 | 0xDCD60DCF, 0xABD13D59, | 607 | * start of the radiotap header **. There is no guarantee |
987 | 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, | 608 | * that the radiotap header itself is aligned on any |
988 | 0xCFBA9599, 0xB8BDA50F, | 609 | * kind of boundary. |
989 | 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, | 610 | */ |
990 | 0xC1611DAB, 0xB6662D3D, | ||
991 | 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, | ||
992 | 0x9FBFE4A5, 0xE8B8D433, | ||
993 | 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, | ||
994 | 0x91646C97, 0xE6635C01, | ||
995 | 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, | ||
996 | 0x8208F4C1, 0xF50FC457, | ||
997 | 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, | ||
998 | 0x8CD37CF3, 0xFBD44C65, | ||
999 | 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, | ||
1000 | 0xA4D1C46D, 0xD3D6F4FB, | ||
1001 | 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, | ||
1002 | 0xAA0A4C5F, 0xDD0D7CC9, | ||
1003 | 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, | ||
1004 | 0xB966D409, 0xCE61E49F, | ||
1005 | 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, | ||
1006 | 0xB7BD5C3B, 0xC0BA6CAD, | ||
1007 | 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, | ||
1008 | 0x04DB2615, 0x73DC1683, | ||
1009 | 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, | ||
1010 | 0x0A00AE27, 0x7D079EB1, | ||
1011 | 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, | ||
1012 | 0x196C3671, 0x6E6B06E7, | ||
1013 | 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, | ||
1014 | 0x17B7BE43, 0x60B08ED5, | ||
1015 | 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, | ||
1016 | 0x3FB506DD, 0x48B2364B, | ||
1017 | 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, | ||
1018 | 0x316E8EEF, 0x4669BE79, | ||
1019 | 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, | ||
1020 | 0x220216B9, 0x5505262F, | ||
1021 | 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, | ||
1022 | 0x2CD99E8B, 0x5BDEAE1D, | ||
1023 | 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, | ||
1024 | 0x72076785, 0x05005713, | ||
1025 | 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, | ||
1026 | 0x7CDCEFB7, 0x0BDBDF21, | ||
1027 | 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, | ||
1028 | 0x6FB077E1, 0x18B74777, | ||
1029 | 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, | ||
1030 | 0x616BFFD3, 0x166CCF45, | ||
1031 | 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, | ||
1032 | 0x4969474D, 0x3E6E77DB, | ||
1033 | 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, | ||
1034 | 0x47B2CF7F, 0x30B5FFE9, | ||
1035 | 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, | ||
1036 | 0x54DE5729, 0x23D967BF, | ||
1037 | 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, | ||
1038 | 0x5A05DF1B, 0x2D02EF8D | ||
1039 | }; | ||
1040 | |||
1041 | |||
1042 | #define ARPHRD_IEEE80211 801 | ||
1043 | #define ARPHRD_IEEE80211_PRISM 802 | ||
1044 | #define ARPHRD_IEEE80211_FULL 803 | ||
1045 | |||
1046 | #define DEBUG 1 | ||
1047 | 611 | ||
1048 | #define MAC_ADDR_SIZE 6 | 612 | if ((((void *) iterator->arg) - |
613 | ((void *) iterator->rtheader)) & ((rt_sizes[iterator->arg_index] >> | ||
614 | 4) - 1)) | ||
615 | iterator->arg_index += | ||
616 | (rt_sizes[iterator->arg_index] >> 4) - | ||
617 | ((((void *) iterator->arg) - | ||
618 | ((void *) iterator->rtheader)) & ((rt_sizes[iterator->arg_index] | ||
619 | >> 4) - 1)); | ||
1049 | 620 | ||
621 | /* | ||
622 | * this is what we will return to user, but we need to | ||
623 | * move on first so next call has something fresh to test | ||
624 | */ | ||
1050 | 625 | ||
1051 | #define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ | 626 | iterator->this_arg_index = iterator->arg_index; |
627 | iterator->this_arg = iterator->arg; | ||
628 | hit = 1; | ||
1052 | 629 | ||
1053 | #define MAXLINE 4096 | 630 | /* internally move on the size of this arg */ |
1054 | 631 | ||
1055 | struct sendbuf | 632 | iterator->arg += rt_sizes[iterator->arg_index] & 0x0f; |
1056 | { | ||
1057 | unsigned int pos; | ||
1058 | unsigned int size; | ||
1059 | char buf[MAXLINE * 2]; | ||
1060 | }; | ||
1061 | 633 | ||
1062 | /* | 634 | /* |
1063 | * generic definitions for IEEE 802.11 frames | 635 | * check for insanity where we are given a bitmap that |
1064 | */ | 636 | * claims to have more arg content than the length of the |
1065 | struct ieee80211_frame | 637 | * radiotap section. We will normally end up equalling this |
1066 | { | 638 | * max_length on the last arg, never exceeding it. |
1067 | u_int8_t i_fc[2]; | 639 | */ |
1068 | u_int8_t i_dur[2]; | ||
1069 | u_int8_t i_addr1[IEEE80211_ADDR_LEN]; | ||
1070 | u_int8_t i_addr2[IEEE80211_ADDR_LEN]; | ||
1071 | u_int8_t i_addr3[IEEE80211_ADDR_LEN]; | ||
1072 | u_int8_t i_seq[2]; | ||
1073 | /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */ | ||
1074 | /* see below */ | ||
1075 | } GNUNET_PACKED; | ||
1076 | |||
1077 | /** | ||
1078 | * struct for storing the information of the hardware | ||
1079 | */ | ||
1080 | struct Hardware_Infos | ||
1081 | { | ||
1082 | |||
1083 | /** | ||
1084 | * send buffer | ||
1085 | */ | ||
1086 | struct sendbuf write_pout; | ||
1087 | /** | ||
1088 | * file descriptor for the raw socket | ||
1089 | */ | ||
1090 | int fd_raw; | ||
1091 | 640 | ||
1092 | int arptype_in; | 641 | if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) > |
642 | iterator->max_length) | ||
643 | return (-EINVAL); | ||
644 | |||
645 | next_entry: | ||
646 | |||
647 | iterator->arg_index++; | ||
648 | if (((iterator->arg_index & 31) == 0)) | ||
649 | { | ||
650 | /* completed current uint32_t bitmap */ | ||
651 | if (iterator->bitmap_shifter & 1) | ||
652 | { | ||
653 | /* b31 was set, there is more */ | ||
654 | /* move to next uint32_t bitmap */ | ||
655 | iterator->bitmap_shifter = le32toh (*iterator->next_bitmap); | ||
656 | iterator->next_bitmap++; | ||
657 | } | ||
658 | else | ||
659 | { | ||
660 | /* no more bitmaps: end */ | ||
661 | iterator->arg_index = sizeof (rt_sizes); | ||
662 | } | ||
663 | } | ||
664 | else | ||
665 | { /* just try the next bit */ | ||
666 | iterator->bitmap_shifter >>= 1; | ||
667 | } | ||
1093 | 668 | ||
1094 | /** | 669 | /* if we found a valid arg earlier, return it now */ |
1095 | * Name of the interface, not necessarily 0-terminated (!). | ||
1096 | */ | ||
1097 | char iface[IFNAMSIZ]; | ||
1098 | 670 | ||
1099 | struct MacAddress pl_mac; | 671 | if (hit) |
1100 | }; | 672 | return (iterator->this_arg_index); |
1101 | |||
1102 | struct RadioTapheader | ||
1103 | { | ||
1104 | struct ieee80211_radiotap_header header; | ||
1105 | u8 rate; | ||
1106 | u8 pad1; | ||
1107 | u16 txflags; | ||
1108 | }; | ||
1109 | 673 | ||
674 | } | ||
1110 | 675 | ||
676 | /* we don't know how to handle any more args, we're done */ | ||
1111 | 677 | ||
678 | return (-1); | ||
679 | } | ||
1112 | 680 | ||
1113 | 681 | ||
1114 | /** | 682 | /** |
@@ -1117,7 +685,7 @@ struct RadioTapheader | |||
1117 | * @param mac pointer to the mac address | 685 | * @param mac pointer to the mac address |
1118 | * @return number of bytes written | 686 | * @return number of bytes written |
1119 | */ | 687 | */ |
1120 | int | 688 | static int |
1121 | send_mac_to_plugin (char *buffer, struct MacAddress *mac) | 689 | send_mac_to_plugin (char *buffer, struct MacAddress *mac) |
1122 | { | 690 | { |
1123 | 691 | ||
@@ -1132,12 +700,25 @@ send_mac_to_plugin (char *buffer, struct MacAddress *mac) | |||
1132 | } | 700 | } |
1133 | 701 | ||
1134 | 702 | ||
703 | /** | ||
704 | * Return the channel from the frequency (in Mhz) | ||
705 | * @param frequency of the channel | ||
706 | * @return number of the channel | ||
707 | */ | ||
708 | static int | ||
709 | getChannelFromFrequency (int frequency) | ||
710 | { | ||
711 | if (frequency >= 2412 && frequency <= 2472) | ||
712 | return (frequency - 2407) / 5; | ||
713 | else if (frequency == 2484) | ||
714 | return 14; | ||
715 | else if (frequency >= 5000 && frequency <= 6100) | ||
716 | return (frequency - 5000) / 5; | ||
717 | else | ||
718 | return -1; | ||
719 | } | ||
1135 | 720 | ||
1136 | // FIXME: inline? | ||
1137 | int | ||
1138 | getChannelFromFrequency (int frequency); | ||
1139 | 721 | ||
1140 | // FIXME: make nice... | ||
1141 | /** | 722 | /** |
1142 | * function to calculate the crc, the start of the calculation | 723 | * function to calculate the crc, the start of the calculation |
1143 | * @param buf buffer to calc the crc | 724 | * @param buf buffer to calc the crc |
@@ -1145,8 +726,75 @@ getChannelFromFrequency (int frequency); | |||
1145 | * @return crc sum | 726 | * @return crc sum |
1146 | */ | 727 | */ |
1147 | static unsigned long | 728 | static unsigned long |
1148 | calc_crc_osdep (unsigned char *buf, int len) | 729 | calc_crc_osdep (const unsigned char *buf, size_t len) |
1149 | { | 730 | { |
731 | static const unsigned long int crc_tbl_osdep[256] = { | ||
732 | 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, | ||
733 | 0xE963A535, 0x9E6495A3, | ||
734 | 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, | ||
735 | 0xE7B82D07, 0x90BF1D91, | ||
736 | 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, | ||
737 | 0xF4D4B551, 0x83D385C7, | ||
738 | 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, | ||
739 | 0xFA0F3D63, 0x8D080DF5, | ||
740 | 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, | ||
741 | 0xD20D85FD, 0xA50AB56B, | ||
742 | 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, | ||
743 | 0xDCD60DCF, 0xABD13D59, | ||
744 | 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, | ||
745 | 0xCFBA9599, 0xB8BDA50F, | ||
746 | 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, | ||
747 | 0xC1611DAB, 0xB6662D3D, | ||
748 | 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, | ||
749 | 0x9FBFE4A5, 0xE8B8D433, | ||
750 | 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, | ||
751 | 0x91646C97, 0xE6635C01, | ||
752 | 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, | ||
753 | 0x8208F4C1, 0xF50FC457, | ||
754 | 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, | ||
755 | 0x8CD37CF3, 0xFBD44C65, | ||
756 | 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, | ||
757 | 0xA4D1C46D, 0xD3D6F4FB, | ||
758 | 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, | ||
759 | 0xAA0A4C5F, 0xDD0D7CC9, | ||
760 | 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, | ||
761 | 0xB966D409, 0xCE61E49F, | ||
762 | 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, | ||
763 | 0xB7BD5C3B, 0xC0BA6CAD, | ||
764 | 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, | ||
765 | 0x04DB2615, 0x73DC1683, | ||
766 | 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, | ||
767 | 0x0A00AE27, 0x7D079EB1, | ||
768 | 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, | ||
769 | 0x196C3671, 0x6E6B06E7, | ||
770 | 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, | ||
771 | 0x17B7BE43, 0x60B08ED5, | ||
772 | 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, | ||
773 | 0x3FB506DD, 0x48B2364B, | ||
774 | 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, | ||
775 | 0x316E8EEF, 0x4669BE79, | ||
776 | 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, | ||
777 | 0x220216B9, 0x5505262F, | ||
778 | 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, | ||
779 | 0x2CD99E8B, 0x5BDEAE1D, | ||
780 | 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, | ||
781 | 0x72076785, 0x05005713, | ||
782 | 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, | ||
783 | 0x7CDCEFB7, 0x0BDBDF21, | ||
784 | 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, | ||
785 | 0x6FB077E1, 0x18B74777, | ||
786 | 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, | ||
787 | 0x616BFFD3, 0x166CCF45, | ||
788 | 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, | ||
789 | 0x4969474D, 0x3E6E77DB, | ||
790 | 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, | ||
791 | 0x47B2CF7F, 0x30B5FFE9, | ||
792 | 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, | ||
793 | 0x54DE5729, 0x23D967BF, | ||
794 | 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, | ||
795 | 0x5A05DF1B, 0x2D02EF8D | ||
796 | }; | ||
797 | |||
1150 | unsigned long crc = 0xFFFFFFFF; | 798 | unsigned long crc = 0xFFFFFFFF; |
1151 | 799 | ||
1152 | for (; len > 0; len--, buf++) | 800 | for (; len > 0; len--, buf++) |
@@ -1155,9 +803,7 @@ calc_crc_osdep (unsigned char *buf, int len) | |||
1155 | return (~crc); | 803 | return (~crc); |
1156 | } | 804 | } |
1157 | 805 | ||
1158 | /* CRC checksum verification routine */ | ||
1159 | 806 | ||
1160 | // FIXME: make nice... | ||
1161 | /** | 807 | /** |
1162 | * Function to check crc of the wlan packet | 808 | * Function to check crc of the wlan packet |
1163 | * @param buf buffer of the packet | 809 | * @param buf buffer of the packet |
@@ -1165,7 +811,7 @@ calc_crc_osdep (unsigned char *buf, int len) | |||
1165 | * @return crc sum of the data | 811 | * @return crc sum of the data |
1166 | */ | 812 | */ |
1167 | static int | 813 | static int |
1168 | check_crc_buf_osdep (unsigned char *buf, int len) | 814 | check_crc_buf_osdep (const unsigned char *buf, size_t len) |
1169 | { | 815 | { |
1170 | unsigned long crc; | 816 | unsigned long crc; |
1171 | 817 | ||
@@ -1175,22 +821,22 @@ check_crc_buf_osdep (unsigned char *buf, int len) | |||
1175 | crc = calc_crc_osdep (buf, len); | 821 | crc = calc_crc_osdep (buf, len); |
1176 | buf += len; | 822 | buf += len; |
1177 | return (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && | 823 | return (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && |
1178 | ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]); | 824 | ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]); |
1179 | } | 825 | } |
1180 | 826 | ||
1181 | 827 | ||
1182 | // FIXME: make nice... | ||
1183 | /** | 828 | /** |
1184 | * function to get the channel of a specific wlan card | 829 | * function to get the channel of a specific wlan card |
1185 | * @param dev pointer to the dev struct of the card | 830 | * @param dev pointer to the dev struct of the card |
1186 | * @return channel number | 831 | * @return channel number |
1187 | */ | 832 | */ |
1188 | static int | 833 | static int |
1189 | linux_get_channel (struct Hardware_Infos *dev) | 834 | linux_get_channel (const struct Hardware_Infos *dev) |
1190 | { | 835 | { |
1191 | struct iwreq wrq; | 836 | struct iwreq wrq; |
1192 | int fd, frequency; | 837 | int fd; |
1193 | int chan = 0; | 838 | int frequency; |
839 | int chan; | ||
1194 | 840 | ||
1195 | memset (&wrq, 0, sizeof (struct iwreq)); | 841 | memset (&wrq, 0, sizeof (struct iwreq)); |
1196 | 842 | ||
@@ -1215,7 +861,6 @@ linux_get_channel (struct Hardware_Infos *dev) | |||
1215 | } | 861 | } |
1216 | 862 | ||
1217 | 863 | ||
1218 | // FIXME: make nice... | ||
1219 | /** | 864 | /** |
1220 | * function to read from a wlan card | 865 | * function to read from a wlan card |
1221 | * @param dev pointer to the struct of the wlan card | 866 | * @param dev pointer to the struct of the wlan card |
@@ -1225,8 +870,8 @@ linux_get_channel (struct Hardware_Infos *dev) | |||
1225 | * @return size read from the buffer | 870 | * @return size read from the buffer |
1226 | */ | 871 | */ |
1227 | static ssize_t | 872 | static ssize_t |
1228 | linux_read (struct Hardware_Infos *dev, unsigned char *buf, /* FIXME: void*? */ | 873 | linux_read (struct Hardware_Infos *dev, unsigned char *buf, |
1229 | size_t buf_size, struct Radiotap_rx *ri) | 874 | size_t buf_size, struct Radiotap_rx *ri) |
1230 | { | 875 | { |
1231 | unsigned char tmpbuf[buf_size]; | 876 | unsigned char tmpbuf[buf_size]; |
1232 | ssize_t caplen; | 877 | ssize_t caplen; |
@@ -1236,170 +881,172 @@ linux_read (struct Hardware_Infos *dev, unsigned char *buf, /* FIXME: void*? | |||
1236 | 881 | ||
1237 | caplen = read (dev->fd_raw, tmpbuf, buf_size); | 882 | caplen = read (dev->fd_raw, tmpbuf, buf_size); |
1238 | if (0 > caplen) | 883 | if (0 > caplen) |
1239 | { | 884 | { |
1240 | if (EAGAIN == errno) | 885 | if (EAGAIN == errno) |
1241 | return 0; | 886 | return 0; |
1242 | fprintf (stderr, "Failed to read from RAW socket: %s\n", strerror (errno)); | 887 | fprintf (stderr, "Failed to read from RAW socket: %s\n", |
1243 | return -1; | 888 | strerror (errno)); |
1244 | } | 889 | return -1; |
890 | } | ||
1245 | 891 | ||
1246 | memset (buf, 0, buf_size); | 892 | memset (buf, 0, buf_size); |
1247 | memset (ri, 0, sizeof (*ri)); | 893 | memset (ri, 0, sizeof (*ri)); |
1248 | 894 | ||
1249 | switch (dev->arptype_in) | 895 | switch (dev->arptype_in) |
1250 | { | ||
1251 | case ARPHRD_IEEE80211_PRISM: | ||
1252 | { | ||
1253 | /* skip the prism header */ | ||
1254 | if (tmpbuf[7] == 0x40) | ||
1255 | { | ||
1256 | /* prism54 uses a different format */ | ||
1257 | ri->ri_power = tmpbuf[0x33]; | ||
1258 | ri->ri_noise = *(unsigned int *) (tmpbuf + 0x33 + 12); | ||
1259 | ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x33 + 24)) * 500000; | ||
1260 | got_signal = 1; | ||
1261 | got_noise = 1; | ||
1262 | n = 0x40; | ||
1263 | } | ||
1264 | else | ||
1265 | { | 896 | { |
1266 | ri->ri_mactime = *(u_int64_t *) (tmpbuf + 0x5C - 48); | 897 | case ARPHRD_IEEE80211_PRISM: |
1267 | ri->ri_channel = *(unsigned int *) (tmpbuf + 0x5C - 36); | ||
1268 | ri->ri_power = *(unsigned int *) (tmpbuf + 0x5C); | ||
1269 | ri->ri_noise = *(unsigned int *) (tmpbuf + 0x5C + 12); | ||
1270 | ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x5C + 24)) * 500000; | ||
1271 | got_channel = 1; | ||
1272 | got_signal = 1; | ||
1273 | got_noise = 1; | ||
1274 | n = *(int *) (tmpbuf + 4); | ||
1275 | } | ||
1276 | |||
1277 | if (n < 8 || n >= caplen) | ||
1278 | return (0); | ||
1279 | } | ||
1280 | break; | ||
1281 | |||
1282 | case ARPHRD_IEEE80211_FULL: | ||
1283 | { | ||
1284 | struct ieee80211_radiotap_iterator iterator; | ||
1285 | struct ieee80211_radiotap_header *rthdr; | ||
1286 | |||
1287 | rthdr = (struct ieee80211_radiotap_header *) tmpbuf; | ||
1288 | |||
1289 | if (ieee80211_radiotap_iterator_init (&iterator, rthdr, caplen) < 0) | ||
1290 | return (0); | ||
1291 | |||
1292 | /* go through the radiotap arguments we have been given | ||
1293 | * by the driver | ||
1294 | */ | ||
1295 | |||
1296 | while (ieee80211_radiotap_iterator_next (&iterator) >= 0) | ||
1297 | { | ||
1298 | |||
1299 | switch (iterator.this_arg_index) | ||
1300 | { | 898 | { |
899 | /* skip the prism header */ | ||
900 | if (tmpbuf[7] == 0x40) | ||
901 | { | ||
902 | /* prism54 uses a different format */ | ||
903 | ri->ri_power = tmpbuf[0x33]; | ||
904 | ri->ri_noise = *(unsigned int *) (tmpbuf + 0x33 + 12); | ||
905 | ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x33 + 24)) * 500000; | ||
906 | got_signal = 1; | ||
907 | got_noise = 1; | ||
908 | n = 0x40; | ||
909 | } | ||
910 | else | ||
911 | { | ||
912 | ri->ri_mactime = *(uint64_t *) (tmpbuf + 0x5C - 48); | ||
913 | ri->ri_channel = *(unsigned int *) (tmpbuf + 0x5C - 36); | ||
914 | ri->ri_power = *(unsigned int *) (tmpbuf + 0x5C); | ||
915 | ri->ri_noise = *(unsigned int *) (tmpbuf + 0x5C + 12); | ||
916 | ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x5C + 24)) * 500000; | ||
917 | got_channel = 1; | ||
918 | got_signal = 1; | ||
919 | got_noise = 1; | ||
920 | n = *(int *) (tmpbuf + 4); | ||
921 | } | ||
922 | |||
923 | if (n < 8 || n >= caplen) | ||
924 | return (0); | ||
925 | } | ||
926 | break; | ||
1301 | 927 | ||
1302 | case IEEE80211_RADIOTAP_TSFT: | 928 | case ARPHRD_IEEE80211_FULL: |
1303 | ri->ri_mactime = le64_to_cpu (*((uint64_t *) iterator.this_arg)); | 929 | { |
1304 | break; | 930 | struct ieee80211_radiotap_iterator iterator; |
1305 | 931 | struct ieee80211_radiotap_header *rthdr; | |
1306 | case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: | 932 | |
1307 | if (!got_signal) | 933 | rthdr = (struct ieee80211_radiotap_header *) tmpbuf; |
1308 | { | 934 | |
1309 | if (*iterator.this_arg < 127) | 935 | if (ieee80211_radiotap_iterator_init (&iterator, rthdr, caplen) < 0) |
1310 | ri->ri_power = *iterator.this_arg; | 936 | return (0); |
1311 | else | 937 | |
1312 | ri->ri_power = *iterator.this_arg - 255; | 938 | /* go through the radiotap arguments we have been given |
1313 | 939 | * by the driver | |
1314 | got_signal = 1; | 940 | */ |
1315 | } | 941 | |
1316 | break; | 942 | while (ieee80211_radiotap_iterator_next (&iterator) >= 0) |
1317 | 943 | { | |
1318 | case IEEE80211_RADIOTAP_DB_ANTSIGNAL: | 944 | |
1319 | if (!got_signal) | 945 | switch (iterator.this_arg_index) |
1320 | { | 946 | { |
1321 | if (*iterator.this_arg < 127) | 947 | |
1322 | ri->ri_power = *iterator.this_arg; | 948 | case IEEE80211_RADIOTAP_TSFT: |
1323 | else | 949 | ri->ri_mactime = le64toh (*((uint64_t *) iterator.this_arg)); |
1324 | ri->ri_power = *iterator.this_arg - 255; | 950 | break; |
1325 | 951 | ||
1326 | got_signal = 1; | 952 | case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: |
1327 | } | 953 | if (!got_signal) |
1328 | break; | 954 | { |
1329 | 955 | if (*iterator.this_arg < 127) | |
1330 | case IEEE80211_RADIOTAP_DBM_ANTNOISE: | 956 | ri->ri_power = *iterator.this_arg; |
1331 | if (!got_noise) | 957 | else |
1332 | { | 958 | ri->ri_power = *iterator.this_arg - 255; |
1333 | if (*iterator.this_arg < 127) | 959 | |
1334 | ri->ri_noise = *iterator.this_arg; | 960 | got_signal = 1; |
1335 | else | 961 | } |
1336 | ri->ri_noise = *iterator.this_arg - 255; | 962 | break; |
1337 | 963 | ||
1338 | got_noise = 1; | 964 | case IEEE80211_RADIOTAP_DB_ANTSIGNAL: |
1339 | } | 965 | if (!got_signal) |
1340 | break; | 966 | { |
1341 | 967 | if (*iterator.this_arg < 127) | |
1342 | case IEEE80211_RADIOTAP_DB_ANTNOISE: | 968 | ri->ri_power = *iterator.this_arg; |
1343 | if (!got_noise) | 969 | else |
1344 | { | 970 | ri->ri_power = *iterator.this_arg - 255; |
1345 | if (*iterator.this_arg < 127) | 971 | |
1346 | ri->ri_noise = *iterator.this_arg; | 972 | got_signal = 1; |
1347 | else | 973 | } |
1348 | ri->ri_noise = *iterator.this_arg - 255; | 974 | break; |
1349 | 975 | ||
1350 | got_noise = 1; | 976 | case IEEE80211_RADIOTAP_DBM_ANTNOISE: |
1351 | } | 977 | if (!got_noise) |
1352 | break; | 978 | { |
1353 | 979 | if (*iterator.this_arg < 127) | |
1354 | case IEEE80211_RADIOTAP_ANTENNA: | 980 | ri->ri_noise = *iterator.this_arg; |
1355 | ri->ri_antenna = *iterator.this_arg; | 981 | else |
1356 | break; | 982 | ri->ri_noise = *iterator.this_arg - 255; |
1357 | 983 | ||
1358 | case IEEE80211_RADIOTAP_CHANNEL: | 984 | got_noise = 1; |
1359 | ri->ri_channel = *iterator.this_arg; | 985 | } |
1360 | got_channel = 1; | 986 | break; |
1361 | break; | 987 | |
1362 | 988 | case IEEE80211_RADIOTAP_DB_ANTNOISE: | |
1363 | case IEEE80211_RADIOTAP_RATE: | 989 | if (!got_noise) |
1364 | ri->ri_rate = (*iterator.this_arg) * 500000; | 990 | { |
1365 | break; | 991 | if (*iterator.this_arg < 127) |
1366 | 992 | ri->ri_noise = *iterator.this_arg; | |
1367 | case IEEE80211_RADIOTAP_FLAGS: | 993 | else |
1368 | /* is the CRC visible at the end? | 994 | ri->ri_noise = *iterator.this_arg - 255; |
1369 | * remove | 995 | |
1370 | */ | 996 | got_noise = 1; |
1371 | if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) | 997 | } |
1372 | { | 998 | break; |
1373 | fcs_removed = 1; | 999 | |
1374 | caplen -= 4; | 1000 | case IEEE80211_RADIOTAP_ANTENNA: |
1375 | } | 1001 | ri->ri_antenna = *iterator.this_arg; |
1376 | 1002 | break; | |
1377 | if (*iterator.this_arg & IEEE80211_RADIOTAP_F_RX_BADFCS) | 1003 | |
1378 | return (0); | 1004 | case IEEE80211_RADIOTAP_CHANNEL: |
1379 | 1005 | ri->ri_channel = *iterator.this_arg; | |
1380 | break; | 1006 | got_channel = 1; |
1007 | break; | ||
1008 | |||
1009 | case IEEE80211_RADIOTAP_RATE: | ||
1010 | ri->ri_rate = (*iterator.this_arg) * 500000; | ||
1011 | break; | ||
1012 | |||
1013 | case IEEE80211_RADIOTAP_FLAGS: | ||
1014 | /* is the CRC visible at the end? | ||
1015 | * remove | ||
1016 | */ | ||
1017 | if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) | ||
1018 | { | ||
1019 | fcs_removed = 1; | ||
1020 | caplen -= 4; | ||
1021 | } | ||
1022 | |||
1023 | if (*iterator.this_arg & IEEE80211_RADIOTAP_F_RX_BADFCS) | ||
1024 | return (0); | ||
1025 | |||
1026 | break; | ||
1027 | } | ||
1028 | } | ||
1029 | n = le16toh (rthdr->it_len); | ||
1030 | if (n <= 0 || n >= caplen) | ||
1031 | return 0; | ||
1381 | } | 1032 | } |
1033 | break; | ||
1034 | case ARPHRD_IEEE80211: | ||
1035 | /* do nothing? */ | ||
1036 | break; | ||
1037 | default: | ||
1038 | errno = ENOTSUP; | ||
1039 | return -1; | ||
1382 | } | 1040 | } |
1383 | n = le16_to_cpu (rthdr->it_len); | ||
1384 | if (n <= 0 || n >= caplen) | ||
1385 | return 0; | ||
1386 | } | ||
1387 | break; | ||
1388 | case ARPHRD_IEEE80211: | ||
1389 | /* do nothing? */ | ||
1390 | break; | ||
1391 | default: | ||
1392 | errno = ENOTSUP; | ||
1393 | return -1; | ||
1394 | } | ||
1395 | 1041 | ||
1396 | caplen -= n; | 1042 | caplen -= n; |
1397 | 1043 | ||
1398 | //detect fcs at the end, even if the flag wasn't set and remove it | 1044 | //detect fcs at the end, even if the flag wasn't set and remove it |
1399 | if ((0 == fcs_removed) && (1 == check_crc_buf_osdep (tmpbuf + n, caplen - 4))) | 1045 | if ((0 == fcs_removed) |
1400 | { | 1046 | && (1 == check_crc_buf_osdep (tmpbuf + n, caplen - 4))) |
1401 | caplen -= 4; | 1047 | { |
1402 | } | 1048 | caplen -= 4; |
1049 | } | ||
1403 | memcpy (buf, tmpbuf + n, caplen); | 1050 | memcpy (buf, tmpbuf + n, caplen); |
1404 | if (!got_channel) | 1051 | if (!got_channel) |
1405 | ri->ri_channel = linux_get_channel (dev); | 1052 | ri->ri_channel = linux_get_channel (dev); |
@@ -1407,6 +1054,7 @@ linux_read (struct Hardware_Infos *dev, unsigned char *buf, /* FIXME: void*? | |||
1407 | return caplen; | 1054 | return caplen; |
1408 | } | 1055 | } |
1409 | 1056 | ||
1057 | |||
1410 | /** | 1058 | /** |
1411 | * function to open the device for read/write | 1059 | * function to open the device for read/write |
1412 | * @param dev pointer to the device struct | 1060 | * @param dev pointer to the device struct |
@@ -1424,12 +1072,12 @@ openraw (struct Hardware_Infos *dev) | |||
1424 | memset (&ifr, 0, sizeof (ifr)); | 1072 | memset (&ifr, 0, sizeof (ifr)); |
1425 | strncpy (ifr.ifr_name, dev->iface, IFNAMSIZ); | 1073 | strncpy (ifr.ifr_name, dev->iface, IFNAMSIZ); |
1426 | if (-1 == ioctl (dev->fd_raw, SIOCGIFINDEX, &ifr)) | 1074 | if (-1 == ioctl (dev->fd_raw, SIOCGIFINDEX, &ifr)) |
1427 | { | 1075 | { |
1428 | fprintf (stderr, | 1076 | fprintf (stderr, |
1429 | "Line: 381 ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n", | 1077 | "ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n", |
1430 | IFNAMSIZ, dev->iface, strerror (errno)); | 1078 | IFNAMSIZ, dev->iface, strerror (errno)); |
1431 | return 1; | 1079 | return 1; |
1432 | } | 1080 | } |
1433 | 1081 | ||
1434 | /* lookup the hardware type */ | 1082 | /* lookup the hardware type */ |
1435 | memset (&sll, 0, sizeof (sll)); | 1083 | memset (&sll, 0, sizeof (sll)); |
@@ -1437,74 +1085,78 @@ openraw (struct Hardware_Infos *dev) | |||
1437 | sll.sll_ifindex = ifr.ifr_ifindex; | 1085 | sll.sll_ifindex = ifr.ifr_ifindex; |
1438 | sll.sll_protocol = htons (ETH_P_ALL); | 1086 | sll.sll_protocol = htons (ETH_P_ALL); |
1439 | if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr)) | 1087 | if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr)) |
1440 | { | 1088 | { |
1441 | fprintf (stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", | 1089 | fprintf (stderr, |
1442 | IFNAMSIZ, dev->iface, strerror (errno)); | 1090 | "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", |
1443 | return 1; | 1091 | IFNAMSIZ, dev->iface, strerror (errno)); |
1444 | } | 1092 | return 1; |
1093 | } | ||
1445 | 1094 | ||
1446 | /* lookup iw mode */ | 1095 | /* lookup iw mode */ |
1447 | memset (&wrq, 0, sizeof (struct iwreq)); | 1096 | memset (&wrq, 0, sizeof (struct iwreq)); |
1448 | strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ); | 1097 | strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ); |
1449 | if (-1 == ioctl (dev->fd_raw, SIOCGIWMODE, &wrq)) | 1098 | if (-1 == ioctl (dev->fd_raw, SIOCGIWMODE, &wrq)) |
1450 | { | 1099 | { |
1451 | /* most probably not supported (ie for rtap ipw interface) * | 1100 | /* most probably not supported (ie for rtap ipw interface) * |
1452 | * so just assume its correctly set... */ | 1101 | * so just assume its correctly set... */ |
1453 | wrq.u.mode = IW_MODE_MONITOR; | 1102 | wrq.u.mode = IW_MODE_MONITOR; |
1454 | } | 1103 | } |
1455 | 1104 | ||
1456 | if (((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) && | 1105 | if (((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) && |
1457 | (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) && | 1106 | (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) && |
1458 | (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) || | 1107 | (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) || |
1459 | (wrq.u.mode != IW_MODE_MONITOR)) | 1108 | (wrq.u.mode != IW_MODE_MONITOR)) |
1460 | { | 1109 | { |
1461 | fprintf (stderr, "Error: interface `%.*s' is not in monitor mode\n", | 1110 | fprintf (stderr, |
1462 | IFNAMSIZ, dev->iface); | 1111 | "Error: interface `%.*s' is not in monitor mode\n", |
1463 | return 1; | 1112 | IFNAMSIZ, dev->iface); |
1464 | } | 1113 | return 1; |
1114 | } | ||
1465 | 1115 | ||
1466 | /* Is interface st to up, broadcast & running ? */ | 1116 | /* Is interface st to up, broadcast & running ? */ |
1467 | if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags) | 1117 | if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags) |
1468 | { | ||
1469 | /* Bring interface up */ | ||
1470 | ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING; | ||
1471 | |||
1472 | if (-1 == ioctl (dev->fd_raw, SIOCSIFFLAGS, &ifr)) | ||
1473 | { | 1118 | { |
1474 | fprintf (stderr, | 1119 | /* Bring interface up */ |
1475 | "Line: 434 ioctl(SIOCSIFFLAGS) on interface `%.*s' failed: %s\n", | 1120 | ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING; |
1476 | IFNAMSIZ, dev->iface, strerror (errno)); | 1121 | |
1477 | return 1; | 1122 | if (-1 == ioctl (dev->fd_raw, SIOCSIFFLAGS, &ifr)) |
1123 | { | ||
1124 | fprintf (stderr, | ||
1125 | "ioctl(SIOCSIFFLAGS) on interface `%.*s' failed: %s\n", | ||
1126 | IFNAMSIZ, dev->iface, strerror (errno)); | ||
1127 | return 1; | ||
1128 | } | ||
1478 | } | 1129 | } |
1479 | } | ||
1480 | 1130 | ||
1481 | /* bind the raw socket to the interface */ | 1131 | /* bind the raw socket to the interface */ |
1482 | if (-1 == bind (dev->fd_raw, (struct sockaddr *) &sll, sizeof (sll))) | 1132 | if (-1 == bind (dev->fd_raw, (struct sockaddr *) &sll, sizeof (sll))) |
1483 | { | 1133 | { |
1484 | fprintf (stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ, | 1134 | fprintf (stderr, |
1485 | dev->iface, strerror (errno)); | 1135 | "Failed to bind interface `%.*s': %s\n", IFNAMSIZ, |
1486 | return 1; | 1136 | dev->iface, strerror (errno)); |
1487 | } | 1137 | return 1; |
1138 | } | ||
1488 | 1139 | ||
1489 | /* lookup the hardware type */ | 1140 | /* lookup the hardware type */ |
1490 | if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr)) | 1141 | if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr)) |
1491 | { | 1142 | { |
1492 | fprintf (stderr, | 1143 | fprintf (stderr, |
1493 | "Line: 457 ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", | 1144 | "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", |
1494 | IFNAMSIZ, dev->iface, strerror (errno)); | 1145 | IFNAMSIZ, dev->iface, strerror (errno)); |
1495 | return 1; | 1146 | return 1; |
1496 | } | 1147 | } |
1497 | 1148 | ||
1498 | memcpy (&dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE); | 1149 | memcpy (&dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE); |
1499 | dev->arptype_in = ifr.ifr_hwaddr.sa_family; | 1150 | dev->arptype_in = ifr.ifr_hwaddr.sa_family; |
1500 | if ((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) && | 1151 | if ((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) && |
1501 | (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) && | 1152 | (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) && |
1502 | (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) | 1153 | (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) |
1503 | { | 1154 | { |
1504 | fprintf (stderr, "Unsupported hardware link type %d on interface `%.*s'\n", | 1155 | fprintf (stderr, |
1505 | ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface); | 1156 | "Unsupported hardware link type %d on interface `%.*s'\n", |
1506 | return 1; | 1157 | ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface); |
1507 | } | 1158 | return 1; |
1159 | } | ||
1508 | 1160 | ||
1509 | /* enable promiscuous mode */ | 1161 | /* enable promiscuous mode */ |
1510 | memset (&mr, 0, sizeof (mr)); | 1162 | memset (&mr, 0, sizeof (mr)); |
@@ -1512,16 +1164,18 @@ openraw (struct Hardware_Infos *dev) | |||
1512 | mr.mr_type = PACKET_MR_PROMISC; | 1164 | mr.mr_type = PACKET_MR_PROMISC; |
1513 | if (0 != | 1165 | if (0 != |
1514 | setsockopt (dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, | 1166 | setsockopt (dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, |
1515 | sizeof (mr))) | 1167 | sizeof (mr))) |
1516 | { | 1168 | { |
1517 | fprintf (stderr, "Failed to enable promiscuous mode on interface `%.*s'\n", | 1169 | fprintf (stderr, |
1518 | IFNAMSIZ, dev->iface); | 1170 | "Failed to enable promiscuous mode on interface `%.*s'\n", |
1519 | return 1; | 1171 | IFNAMSIZ, dev->iface); |
1520 | } | 1172 | return 1; |
1173 | } | ||
1521 | 1174 | ||
1522 | return 0; | 1175 | return 0; |
1523 | } | 1176 | } |
1524 | 1177 | ||
1178 | |||
1525 | /** | 1179 | /** |
1526 | * function to prepare the helper, e.g. sockets, device... | 1180 | * function to prepare the helper, e.g. sockets, device... |
1527 | * @param dev struct for the device | 1181 | * @param dev struct for the device |
@@ -1537,34 +1191,36 @@ wlaninit (struct Hardware_Infos *dev, const char *iface) | |||
1537 | 1191 | ||
1538 | dev->fd_raw = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL)); | 1192 | dev->fd_raw = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL)); |
1539 | if (0 > dev->fd_raw) | 1193 | if (0 > dev->fd_raw) |
1540 | { | 1194 | { |
1541 | fprintf (stderr, "Failed to create raw socket: %s\n", strerror (errno)); | 1195 | fprintf (stderr, "Failed to create raw socket: %s\n", strerror (errno)); |
1542 | return 1; | 1196 | return 1; |
1543 | } | 1197 | } |
1544 | if (dev->fd_raw >= FD_SETSIZE) | 1198 | if (dev->fd_raw >= FD_SETSIZE) |
1545 | { | 1199 | { |
1546 | fprintf (stderr, "File descriptor too large for select (%d > %d)\n", | 1200 | fprintf (stderr, |
1547 | dev->fd_raw, FD_SETSIZE); | 1201 | "File descriptor too large for select (%d > %d)\n", |
1548 | close (dev->fd_raw); | 1202 | dev->fd_raw, FD_SETSIZE); |
1549 | return 1; | 1203 | close (dev->fd_raw); |
1550 | } | 1204 | return 1; |
1205 | } | ||
1551 | 1206 | ||
1552 | /* mac80211 stack detection */ | 1207 | /* mac80211 stack detection */ |
1553 | ret = | 1208 | ret = |
1554 | snprintf (strbuf, sizeof (strbuf), "/sys/class/net/%s/phy80211/subsystem", | 1209 | snprintf (strbuf, |
1555 | iface); | 1210 | sizeof (strbuf), "/sys/class/net/%s/phy80211/subsystem", iface); |
1556 | if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf))) | 1211 | if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf))) |
1557 | { | 1212 | { |
1558 | fprintf (stderr, "Did not find 802.11 interface `%s'. Exiting.\n", iface); | 1213 | fprintf (stderr, |
1559 | close (dev->fd_raw); | 1214 | "Did not find 802.11 interface `%s'. Exiting.\n", iface); |
1560 | return 1; | 1215 | close (dev->fd_raw); |
1561 | } | 1216 | return 1; |
1217 | } | ||
1562 | strncpy (dev->iface, iface, IFNAMSIZ); | 1218 | strncpy (dev->iface, iface, IFNAMSIZ); |
1563 | if (0 != openraw (dev)) | 1219 | if (0 != openraw (dev)) |
1564 | { | 1220 | { |
1565 | close (dev->fd_raw); | 1221 | close (dev->fd_raw); |
1566 | return 1; | 1222 | return 1; |
1567 | } | 1223 | } |
1568 | return 0; | 1224 | return 0; |
1569 | } | 1225 | } |
1570 | 1226 | ||
@@ -1572,19 +1228,19 @@ wlaninit (struct Hardware_Infos *dev, const char *iface) | |||
1572 | /** | 1228 | /** |
1573 | * Function to test incoming packets mac for being our own. | 1229 | * Function to test incoming packets mac for being our own. |
1574 | * | 1230 | * |
1575 | * @param u8aIeeeHeader buffer of the packet | 1231 | * @param uint8_taIeeeHeader buffer of the packet |
1576 | * @param dev the Hardware_Infos struct | 1232 | * @param dev the Hardware_Infos struct |
1577 | * @return 0 if mac belongs to us, 1 if mac is for another target | 1233 | * @return 0 if mac belongs to us, 1 if mac is for another target |
1578 | */ | 1234 | */ |
1579 | static int | 1235 | static int |
1580 | mac_test (const struct ieee80211_frame *u8aIeeeHeader, | 1236 | mac_test (const struct ieee80211_frame *uint8_taIeeeHeader, |
1581 | const struct Hardware_Infos *dev) | 1237 | const struct Hardware_Infos *dev) |
1582 | { | 1238 | { |
1583 | if (0 != memcmp (u8aIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE)) | 1239 | if (0 != memcmp (uint8_taIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE)) |
1584 | return 1; | 1240 | return 1; |
1585 | if (0 == memcmp (u8aIeeeHeader->i_addr1, &dev->pl_mac, MAC_ADDR_SIZE)) | 1241 | if (0 == memcmp (uint8_taIeeeHeader->i_addr1, &dev->pl_mac, MAC_ADDR_SIZE)) |
1586 | return 0; | 1242 | return 0; |
1587 | if (0 == memcmp (u8aIeeeHeader->i_addr1, &bc_all_mac, MAC_ADDR_SIZE)) | 1243 | if (0 == memcmp (uint8_taIeeeHeader->i_addr1, &bc_all_mac, MAC_ADDR_SIZE)) |
1588 | return 0; | 1244 | return 0; |
1589 | return 1; | 1245 | return 1; |
1590 | } | 1246 | } |
@@ -1592,20 +1248,20 @@ mac_test (const struct ieee80211_frame *u8aIeeeHeader, | |||
1592 | 1248 | ||
1593 | /** | 1249 | /** |
1594 | * function to set the wlan header to make attacks more difficult | 1250 | * function to set the wlan header to make attacks more difficult |
1595 | * @param u8aIeeeHeader pointer to the header of the packet | 1251 | * @param uint8_taIeeeHeader pointer to the header of the packet |
1596 | * @param dev pointer to the Hardware_Infos struct | 1252 | * @param dev pointer to the Hardware_Infos struct |
1597 | */ | 1253 | */ |
1598 | static void | 1254 | static void |
1599 | mac_set (struct ieee80211_frame *u8aIeeeHeader, | 1255 | mac_set (struct ieee80211_frame *uint8_taIeeeHeader, |
1600 | const struct Hardware_Infos *dev) | 1256 | const struct Hardware_Infos *dev) |
1601 | { | 1257 | { |
1602 | u8aIeeeHeader->i_fc[0] = 0x08; | 1258 | uint8_taIeeeHeader->i_fc[0] = 0x08; |
1603 | u8aIeeeHeader->i_fc[1] = 0x00; | 1259 | uint8_taIeeeHeader->i_fc[1] = 0x00; |
1604 | memcpy (u8aIeeeHeader->i_addr2, &dev->pl_mac, MAC_ADDR_SIZE); | 1260 | memcpy (uint8_taIeeeHeader->i_addr2, &dev->pl_mac, MAC_ADDR_SIZE); |
1605 | memcpy (u8aIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE); | 1261 | memcpy (uint8_taIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE); |
1606 | |||
1607 | } | 1262 | } |
1608 | 1263 | ||
1264 | |||
1609 | /** | 1265 | /** |
1610 | * function to process the data from the stdin | 1266 | * function to process the data from the stdin |
1611 | * @param cls pointer to the device struct | 1267 | * @param cls pointer to the device struct |
@@ -1613,15 +1269,14 @@ mac_set (struct ieee80211_frame *u8aIeeeHeader, | |||
1613 | * @param hdr pointer to the start of the packet | 1269 | * @param hdr pointer to the start of the packet |
1614 | */ | 1270 | */ |
1615 | static void | 1271 | static void |
1616 | stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | 1272 | stdin_send_hw (void *cls, void *client, |
1273 | const struct GNUNET_MessageHeader *hdr) | ||
1617 | { | 1274 | { |
1618 | struct Hardware_Infos *dev = cls; | 1275 | struct Hardware_Infos *dev = cls; |
1619 | struct sendbuf *write_pout = &dev->write_pout; | 1276 | struct sendbuf *write_pout = &dev->write_pout; |
1620 | struct Radiotap_Send *header = (struct Radiotap_Send *) &hdr[1]; | 1277 | struct Radiotap_Send *header = (struct Radiotap_Send *) &hdr[1]; |
1621 | struct ieee80211_frame *wlanheader; | 1278 | struct ieee80211_frame *wlanheader; |
1622 | size_t sendsize; | 1279 | size_t sendsize; |
1623 | |||
1624 | // struct? // FIXME: make nice... | ||
1625 | struct RadioTapheader rtheader; | 1280 | struct RadioTapheader rtheader; |
1626 | 1281 | ||
1627 | rtheader.header.it_version = 0; | 1282 | rtheader.header.it_version = 0; |
@@ -1630,7 +1285,7 @@ stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1630 | rtheader.rate = 0x00; | 1285 | rtheader.rate = 0x00; |
1631 | rtheader.pad1 = 0x00; | 1286 | rtheader.pad1 = 0x00; |
1632 | rtheader.txflags = | 1287 | rtheader.txflags = |
1633 | htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ); | 1288 | htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ); |
1634 | 1289 | ||
1635 | /* { 0x00, 0x00, <-- radiotap version | 1290 | /* { 0x00, 0x00, <-- radiotap version |
1636 | * 0x0c, 0x00, <- radiotap header length | 1291 | * 0x0c, 0x00, <- radiotap header length |
@@ -1643,23 +1298,24 @@ stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1643 | sendsize = ntohs (hdr->size); | 1298 | sendsize = ntohs (hdr->size); |
1644 | if (sendsize < | 1299 | if (sendsize < |
1645 | sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader)) | 1300 | sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader)) |
1646 | { | 1301 | { |
1647 | fprintf (stderr, "Function stdin_send_hw: malformed packet (too small)\n"); | 1302 | fprintf (stderr, |
1648 | exit (1); | 1303 | "Function stdin_send_hw: malformed packet (too small)\n"); |
1649 | } | 1304 | exit (1); |
1305 | } | ||
1650 | sendsize -= | 1306 | sendsize -= |
1651 | sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader); | 1307 | sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader); |
1652 | 1308 | ||
1653 | if (MAXLINE < sendsize) | 1309 | if (MAXLINE < sendsize) |
1654 | { | 1310 | { |
1655 | fprintf (stderr, "Function stdin_send_hw: Packet too big for buffer\n"); | 1311 | fprintf (stderr, "Function stdin_send_hw: Packet too big for buffer\n"); |
1656 | exit (1); | 1312 | exit (1); |
1657 | } | 1313 | } |
1658 | if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type)) | 1314 | if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type)) |
1659 | { | 1315 | { |
1660 | fprintf (stderr, "Function stdin_send: wrong packet type\n"); | 1316 | fprintf (stderr, "Function stdin_send: wrong packet type\n"); |
1661 | exit (1); | 1317 | exit (1); |
1662 | } | 1318 | } |
1663 | 1319 | ||
1664 | rtheader.header.it_len = htole16 (sizeof (rtheader)); | 1320 | rtheader.header.it_len = htole16 (sizeof (rtheader)); |
1665 | rtheader.rate = header->rate; | 1321 | rtheader.rate = header->rate; |
@@ -1667,105 +1323,21 @@ stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1667 | memcpy (write_pout->buf + sizeof (rtheader), &header[1], sendsize); | 1323 | memcpy (write_pout->buf + sizeof (rtheader), &header[1], sendsize); |
1668 | /* payload contains MAC address, but we don't trust it, so we'll | 1324 | /* payload contains MAC address, but we don't trust it, so we'll |
1669 | * overwrite it with OUR MAC address again to prevent mischief */ | 1325 | * overwrite it with OUR MAC address again to prevent mischief */ |
1670 | wlanheader = (struct ieee80211_frame *) (write_pout->buf + sizeof (rtheader)); | 1326 | wlanheader = |
1327 | (struct ieee80211_frame *) (write_pout->buf + sizeof (rtheader)); | ||
1671 | mac_set (wlanheader, dev); | 1328 | mac_set (wlanheader, dev); |
1672 | write_pout->size = sendsize + sizeof (rtheader); | 1329 | write_pout->size = sendsize + sizeof (rtheader); |
1673 | } | 1330 | } |
1674 | 1331 | ||
1675 | #if 0 | ||
1676 | /** | ||
1677 | * Function to make test packets with special options | ||
1678 | * @param buf buffer to write the data to | ||
1679 | * @param dev device to send the data from | ||
1680 | * @return size of packet (what should be send) | ||
1681 | */ | ||
1682 | static int | ||
1683 | maketest (unsigned char *buf, struct Hardware_Infos *dev) | ||
1684 | { | ||
1685 | uint16_t *tmp16; | ||
1686 | static uint16_t seqenz = 0; | ||
1687 | static int first = 0; | ||
1688 | |||
1689 | const int rate = 11000000; | ||
1690 | static const char txt[] = | ||
1691 | "Hallo1Hallo2 Hallo3 Hallo4...998877665544332211Hallo1Hallo2 Hallo3 Hallo4...998877665544332211"; | ||
1692 | |||
1693 | unsigned char u8aRadiotap[] = { 0x00, 0x00, // <-- radiotap version | ||
1694 | 0x00, 0x00, // <- radiotap header length | ||
1695 | 0x04, 0x80, 0x02, 0x00, // <-- bitmap | ||
1696 | 0x00, // <-- rate | ||
1697 | 0x00, // <-- padding for natural alignment | ||
1698 | 0x10, 0x00, // <-- TX flags | ||
1699 | 0x04 //retries | ||
1700 | }; | ||
1701 | |||
1702 | /*uint8_t u8aRadiotap[] = | ||
1703 | * { | ||
1704 | * 0x00, 0x00, // <-- radiotap version | ||
1705 | * 0x19, 0x00, // <- radiotap header length | ||
1706 | * 0x6f, 0x08, 0x00, 0x00, // <-- bitmap | ||
1707 | * 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp | ||
1708 | * 0x00, // <-- flags (Offset +0x10) | ||
1709 | * 0x6c, // <-- rate (0ffset +0x11) | ||
1710 | * 0x71, 0x09, 0xc0, 0x00, // <-- channel | ||
1711 | * 0xde, // <-- antsignal | ||
1712 | * 0x00, // <-- antnoise | ||
1713 | * 0x01, // <-- antenna | ||
1714 | * }; */ | ||
1715 | |||
1716 | u8aRadiotap[8] = (rate / 500000); | ||
1717 | u8aRadiotap[2] = htole16 (sizeof (u8aRadiotap)); | ||
1718 | |||
1719 | static struct ieee80211_frame u8aIeeeHeader; | ||
1720 | |||
1721 | uint8_t u8aIeeeHeader_def[] = { 0x08, 0x00, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0; | ||
1722 | // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data | ||
1723 | // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS; | ||
1724 | 0x00, 0x00, // Duration/ID | ||
1725 | |||
1726 | //0x00, 0x1f, 0x3f, 0xd1, 0x8e, 0xe6, // mac1 - in this case receiver | ||
1727 | 0x00, 0x1d, 0xe0, 0xb0, 0x17, 0xdf, // mac1 - in this case receiver | ||
1728 | 0xC0, 0x3F, 0x0E, 0x44, 0x2D, 0x51, // mac2 - in this case sender | ||
1729 | //0x02, 0x1d, 0xe0, 0x00, 0x01, 0xc4, | ||
1730 | 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid | ||
1731 | 0x10, 0x86, //Sequence Control | ||
1732 | }; | ||
1733 | if (0 == first) | ||
1734 | { | ||
1735 | memcpy (&u8aIeeeHeader, u8aIeeeHeader_def, sizeof (struct ieee80211_frame)); | ||
1736 | memcpy (u8aIeeeHeader.i_addr2, &dev->pl_mac, MAC_ADDR_SIZE); | ||
1737 | first = 1; | ||
1738 | } | ||
1739 | |||
1740 | tmp16 = (uint16_t *) u8aIeeeHeader.i_dur; | ||
1741 | *tmp16 = | ||
1742 | (uint16_t) | ||
1743 | htole16 ((sizeof (txt) + | ||
1744 | sizeof (struct ieee80211_frame) * 1000000) / rate + 290); | ||
1745 | tmp16 = (uint16_t *) u8aIeeeHeader.i_seq; | ||
1746 | *tmp16 = | ||
1747 | (*tmp16 & IEEE80211_SEQ_FRAG_MASK) | (htole16 (seqenz) << | ||
1748 | IEEE80211_SEQ_SEQ_SHIFT); | ||
1749 | seqenz++; | ||
1750 | |||
1751 | memcpy (buf, u8aRadiotap, sizeof (u8aRadiotap)); | ||
1752 | memcpy (buf + sizeof (u8aRadiotap), &u8aIeeeHeader, sizeof (u8aIeeeHeader)); | ||
1753 | memcpy (buf + sizeof (u8aRadiotap) + sizeof (u8aIeeeHeader), txt, | ||
1754 | sizeof (txt)); | ||
1755 | return sizeof (u8aRadiotap) + sizeof (u8aIeeeHeader) + sizeof (txt); | ||
1756 | |||
1757 | } | ||
1758 | #endif | ||
1759 | |||
1760 | 1332 | ||
1761 | /** | 1333 | /** |
1762 | * Function to start the hardware for the wlan helper | 1334 | * main function of the helper |
1763 | * @param argc number of arguments | 1335 | * @param argc number of arguments |
1764 | * @param argv arguments | 1336 | * @param argv arguments |
1765 | * @return returns one on error | 1337 | * @return 0 on success, 1 on error |
1766 | */ | 1338 | */ |
1767 | static int | 1339 | int |
1768 | hardwaremode (int argc, char *argv[]) | 1340 | main (int argc, char *argv[]) |
1769 | { | 1341 | { |
1770 | uid_t uid; | 1342 | uid_t uid; |
1771 | struct Hardware_Infos dev; | 1343 | struct Hardware_Infos dev; |
@@ -1779,14 +1351,20 @@ hardwaremode (int argc, char *argv[]) | |||
1779 | int stdin_open; | 1351 | int stdin_open; |
1780 | struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst; | 1352 | struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst; |
1781 | 1353 | ||
1354 | if (2 != argc) | ||
1355 | { | ||
1356 | fprintf (stderr, | ||
1357 | "You must specify the name of the interface as the first and only argument to this program.\n"); | ||
1358 | return 1; | ||
1359 | } | ||
1782 | if (0 != wlaninit (&dev, argv[1])) | 1360 | if (0 != wlaninit (&dev, argv[1])) |
1783 | return 1; | 1361 | return 1; |
1784 | uid = getuid (); | 1362 | uid = getuid (); |
1785 | if (0 != setresuid (uid, uid, uid)) | 1363 | if (0 != setresuid (uid, uid, uid)) |
1786 | { | 1364 | { |
1787 | fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); | 1365 | fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); |
1788 | /* not critical, continue anyway */ | 1366 | /* not critical, continue anyway */ |
1789 | } | 1367 | } |
1790 | 1368 | ||
1791 | dev.write_pout.size = 0; | 1369 | dev.write_pout.size = 0; |
1792 | dev.write_pout.pos = 0; | 1370 | dev.write_pout.pos = 0; |
@@ -1798,230 +1376,135 @@ hardwaremode (int argc, char *argv[]) | |||
1798 | stdin_open = 1; | 1376 | stdin_open = 1; |
1799 | 1377 | ||
1800 | while (1) | 1378 | while (1) |
1801 | { | ||
1802 | maxfd = -1; | ||
1803 | FD_ZERO (&rfds); | ||
1804 | if ((0 == dev.write_pout.size) && (1 == stdin_open)) | ||
1805 | { | ||
1806 | FD_SET (STDIN_FILENO, &rfds); | ||
1807 | maxfd = MAX (maxfd, STDIN_FILENO); | ||
1808 | } | ||
1809 | if (0 == write_std.size) | ||
1810 | { | ||
1811 | FD_SET (dev.fd_raw, &rfds); | ||
1812 | maxfd = MAX (maxfd, dev.fd_raw); | ||
1813 | } | ||
1814 | FD_ZERO (&wfds); | ||
1815 | if (0 < write_std.size) | ||
1816 | { | ||
1817 | FD_SET (STDOUT_FILENO, &wfds); | ||
1818 | maxfd = MAX (maxfd, STDOUT_FILENO); | ||
1819 | } | ||
1820 | if (0 < dev.write_pout.size) | ||
1821 | { | 1379 | { |
1822 | FD_SET (dev.fd_raw, &wfds); | 1380 | maxfd = -1; |
1823 | maxfd = MAX (maxfd, dev.fd_raw); | 1381 | FD_ZERO (&rfds); |
1824 | } | 1382 | if ((0 == dev.write_pout.size) && (1 == stdin_open)) |
1825 | retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL); | 1383 | { |
1826 | if ((-1 == retval) && (EINTR == errno)) | 1384 | FD_SET (STDIN_FILENO, &rfds); |
1827 | continue; | 1385 | maxfd = MAX (maxfd, STDIN_FILENO); |
1828 | if (0 > retval) | 1386 | } |
1829 | { | 1387 | if (0 == write_std.size) |
1830 | fprintf (stderr, "select failed: %s\n", strerror (errno)); | 1388 | { |
1831 | break; | 1389 | FD_SET (dev.fd_raw, &rfds); |
1832 | } | 1390 | maxfd = MAX (maxfd, dev.fd_raw); |
1391 | } | ||
1392 | FD_ZERO (&wfds); | ||
1393 | if (0 < write_std.size) | ||
1394 | { | ||
1395 | FD_SET (STDOUT_FILENO, &wfds); | ||
1396 | maxfd = MAX (maxfd, STDOUT_FILENO); | ||
1397 | } | ||
1398 | if (0 < dev.write_pout.size) | ||
1399 | { | ||
1400 | FD_SET (dev.fd_raw, &wfds); | ||
1401 | maxfd = MAX (maxfd, dev.fd_raw); | ||
1402 | } | ||
1403 | retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL); | ||
1404 | if ((-1 == retval) && (EINTR == errno)) | ||
1405 | continue; | ||
1406 | if (0 > retval) | ||
1407 | { | ||
1408 | fprintf (stderr, "select failed: %s\n", strerror (errno)); | ||
1409 | break; | ||
1410 | } | ||
1411 | if (FD_ISSET (STDOUT_FILENO, &wfds)) | ||
1412 | { | ||
1413 | ret = | ||
1414 | write (STDOUT_FILENO, | ||
1415 | write_std.buf + write_std.pos, | ||
1416 | write_std.size - write_std.pos); | ||
1417 | if (0 > ret) | ||
1418 | { | ||
1419 | fprintf (stderr, | ||
1420 | "Failed to write to STDOUT: %s\n", strerror (errno)); | ||
1421 | break; | ||
1422 | } | ||
1423 | write_std.pos += ret; | ||
1424 | if (write_std.pos == write_std.size) | ||
1425 | { | ||
1426 | write_std.pos = 0; | ||
1427 | write_std.size = 0; | ||
1428 | } | ||
1429 | } | ||
1430 | if (FD_ISSET (dev.fd_raw, &wfds)) | ||
1431 | { | ||
1432 | ret = write (dev.fd_raw, dev.write_pout.buf, dev.write_pout.size); | ||
1433 | if (0 > ret) | ||
1434 | { | ||
1435 | fprintf (stderr, | ||
1436 | "Failed to write to WLAN device: %s\n", | ||
1437 | strerror (errno)); | ||
1438 | break; | ||
1439 | } | ||
1440 | dev.write_pout.pos += ret; | ||
1441 | if ((dev.write_pout.pos != dev.write_pout.size) && (ret != 0)) | ||
1442 | { | ||
1443 | /* we should not get partial sends with packet-oriented devices... */ | ||
1444 | fprintf (stderr, | ||
1445 | "Write error, partial send: %u/%u\n", | ||
1446 | dev.write_pout.pos, dev.write_pout.size); | ||
1447 | break; | ||
1448 | } | ||
1449 | if (dev.write_pout.pos == dev.write_pout.size) | ||
1450 | { | ||
1451 | dev.write_pout.pos = 0; | ||
1452 | dev.write_pout.size = 0; | ||
1453 | } | ||
1454 | } | ||
1455 | |||
1456 | if (FD_ISSET (STDIN_FILENO, &rfds)) | ||
1457 | { | ||
1458 | ret = read (STDIN_FILENO, readbuf, sizeof (readbuf)); | ||
1459 | if (0 > ret) | ||
1460 | { | ||
1461 | fprintf (stderr, | ||
1462 | "Read error from STDIN: %s\n", strerror (errno)); | ||
1463 | break; | ||
1464 | } | ||
1465 | if (0 == ret) | ||
1466 | { | ||
1467 | /* stop reading... */ | ||
1468 | stdin_open = 0; | ||
1469 | } | ||
1470 | GNUNET_SERVER_mst_receive (stdin_mst, NULL, readbuf, ret, GNUNET_NO, | ||
1471 | GNUNET_NO); | ||
1472 | } | ||
1473 | |||
1474 | if (FD_ISSET (dev.fd_raw, &rfds)) | ||
1475 | { | ||
1476 | struct GNUNET_MessageHeader *header; | ||
1477 | struct Radiotap_rx *rxinfo; | ||
1478 | struct ieee80211_frame *datastart; | ||
1479 | |||
1480 | header = (struct GNUNET_MessageHeader *) write_std.buf; | ||
1481 | rxinfo = (struct Radiotap_rx *) &header[1]; | ||
1482 | datastart = (struct ieee80211_frame *) &rxinfo[1]; | ||
1483 | ret = | ||
1484 | linux_read (&dev, (unsigned char *) datastart, | ||
1485 | sizeof (write_std.buf) - sizeof (struct Radiotap_rx) - | ||
1486 | sizeof (struct GNUNET_MessageHeader), rxinfo); | ||
1487 | if (0 > ret) | ||
1488 | { | ||
1489 | fprintf (stderr, | ||
1490 | "Read error from raw socket: %s\n", strerror (errno)); | ||
1491 | break; | ||
1492 | } | ||
1493 | if ((0 < ret) && (0 == mac_test (datastart, &dev))) | ||
1494 | { | ||
1495 | write_std.size = | ||
1496 | ret + sizeof (struct GNUNET_MessageHeader) + | ||
1497 | sizeof (struct Radiotap_rx); | ||
1498 | header->size = htons (write_std.size); | ||
1499 | header->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); | ||
1500 | } | ||
1501 | } | ||
1833 | 1502 | ||
1834 | if (FD_ISSET (STDOUT_FILENO, &wfds)) | ||
1835 | { | ||
1836 | ret = | ||
1837 | write (STDOUT_FILENO, write_std.buf + write_std.pos, | ||
1838 | write_std.size - write_std.pos); | ||
1839 | if (0 > ret) | ||
1840 | { | ||
1841 | fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno)); | ||
1842 | break; | ||
1843 | } | ||
1844 | write_std.pos += ret; | ||
1845 | if (write_std.pos == write_std.size) | ||
1846 | { | ||
1847 | write_std.pos = 0; | ||
1848 | write_std.size = 0; | ||
1849 | } | ||
1850 | } | ||
1851 | |||
1852 | if (FD_ISSET (dev.fd_raw, &wfds)) | ||
1853 | { | ||
1854 | ret = write (dev.fd_raw, dev.write_pout.buf, dev.write_pout.size); | ||
1855 | if (0 > ret) | ||
1856 | { | ||
1857 | fprintf (stderr, | ||
1858 | "Line %u: Failed to write to WLAN device: %s, Message-Size: %u\n", | ||
1859 | __LINE__, strerror (errno), dev.write_pout.size); | ||
1860 | break; | ||
1861 | } | ||
1862 | dev.write_pout.pos += ret; | ||
1863 | if ((dev.write_pout.pos != dev.write_pout.size) && (ret != 0)) | ||
1864 | { | ||
1865 | fprintf (stderr, "Line %u: Write error, partial send: %u/%u\n", | ||
1866 | __LINE__, dev.write_pout.pos, dev.write_pout.size); | ||
1867 | break; | ||
1868 | } | ||
1869 | if (dev.write_pout.pos == dev.write_pout.size) | ||
1870 | { | ||
1871 | dev.write_pout.pos = 0; | ||
1872 | dev.write_pout.size = 0; | ||
1873 | } | ||
1874 | } | 1503 | } |
1875 | |||
1876 | if (FD_ISSET (STDIN_FILENO, &rfds)) | ||
1877 | { | ||
1878 | ret = read (STDIN_FILENO, readbuf, sizeof (readbuf)); | ||
1879 | if (0 > ret) | ||
1880 | { | ||
1881 | fprintf (stderr, "Read error from STDIN: %s\n", strerror (errno)); | ||
1882 | break; | ||
1883 | } | ||
1884 | if (0 == ret) | ||
1885 | { | ||
1886 | /* stop reading... */ | ||
1887 | stdin_open = 0; | ||
1888 | } | ||
1889 | GNUNET_SERVER_mst_receive (stdin_mst, NULL, readbuf, ret, GNUNET_NO, | ||
1890 | GNUNET_NO); | ||
1891 | } | ||
1892 | |||
1893 | if (FD_ISSET (dev.fd_raw, &rfds)) | ||
1894 | { | ||
1895 | struct GNUNET_MessageHeader *header; | ||
1896 | struct Radiotap_rx *rxinfo; | ||
1897 | struct ieee80211_frame *datastart; | ||
1898 | |||
1899 | header = (struct GNUNET_MessageHeader *) write_std.buf; | ||
1900 | rxinfo = (struct Radiotap_rx *) &header[1]; | ||
1901 | datastart = (struct ieee80211_frame *) &rxinfo[1]; | ||
1902 | ret = | ||
1903 | linux_read (&dev, (unsigned char *) datastart, | ||
1904 | sizeof (write_std.buf) - sizeof (struct Radiotap_rx) - | ||
1905 | sizeof (struct GNUNET_MessageHeader), rxinfo); | ||
1906 | if (0 > ret) | ||
1907 | { | ||
1908 | fprintf (stderr, "Read error from raw socket: %s\n", strerror (errno)); | ||
1909 | break; | ||
1910 | } | ||
1911 | if ((0 < ret) && (0 == mac_test (datastart, &dev))) | ||
1912 | { | ||
1913 | write_std.size = | ||
1914 | ret + sizeof (struct GNUNET_MessageHeader) + | ||
1915 | sizeof (struct Radiotap_rx); | ||
1916 | header->size = htons (write_std.size); | ||
1917 | header->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); | ||
1918 | } | ||
1919 | } | ||
1920 | |||
1921 | } | ||
1922 | /* Error handling, try to clean up a bit at least */ | 1504 | /* Error handling, try to clean up a bit at least */ |
1923 | GNUNET_SERVER_mst_destroy (stdin_mst); | 1505 | GNUNET_SERVER_mst_destroy (stdin_mst); |
1924 | close (dev.fd_raw); | 1506 | close (dev.fd_raw); |
1925 | return 1; | 1507 | return 1; /* we never exit 'normally' */ |
1926 | } | ||
1927 | |||
1928 | /** | ||
1929 | * main function of the helper | ||
1930 | * @param argc number of arguments | ||
1931 | * @param argv arguments | ||
1932 | * @return 0 on success, 1 on error | ||
1933 | */ | ||
1934 | int | ||
1935 | main (int argc, char *argv[]) | ||
1936 | { | ||
1937 | if (2 != argc) | ||
1938 | { | ||
1939 | fprintf (stderr, | ||
1940 | "This program must be started with the interface as argument.\nThis program was compiled at ----- %s ----\n", | ||
1941 | __TIMESTAMP__); | ||
1942 | fprintf (stderr, "Usage: interface-name\n" "\n"); | ||
1943 | return 1; | ||
1944 | } | ||
1945 | return hardwaremode (argc, argv); | ||
1946 | } | ||
1947 | |||
1948 | /* | ||
1949 | * Copyright (c) 2008, Thomas d'Otreppe | ||
1950 | * | ||
1951 | * Common OSdep stuff | ||
1952 | * | ||
1953 | * This program is free software; you can redistribute it and/or modify | ||
1954 | * it under the terms of the GNU General Public License as published by | ||
1955 | * the Free Software Foundation; either version 2 of the License, or | ||
1956 | * (at your option) any later version. | ||
1957 | * | ||
1958 | * This program is distributed in the hope that it will be useful, | ||
1959 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1960 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1961 | * GNU General Public License for more details. | ||
1962 | * | ||
1963 | * You should have received a copy of the GNU General Public License | ||
1964 | * along with this program; if not, write to the Free Software | ||
1965 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
1966 | */ | ||
1967 | |||
1968 | /** | ||
1969 | * Return the frequency in Mhz from a channel number | ||
1970 | * @param channel number of the channel | ||
1971 | * @return frequency of the channel | ||
1972 | */ | ||
1973 | int | ||
1974 | getFrequencyFromChannel (int channel) | ||
1975 | { | ||
1976 | static int frequencies[] = { | ||
1977 | -1, // No channel 0 | ||
1978 | 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, | ||
1979 | 2472, 2484, | ||
1980 | -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) | ||
1981 | 5170, 5175, 5180, 5185, 5190, 5195, 5200, 5205, 5210, 5215, 5220, 5225, | ||
1982 | 5230, 5235, 5240, 5245, | ||
1983 | 5250, 5255, 5260, 5265, 5270, 5275, 5280, 5285, 5290, 5295, 5300, 5305, | ||
1984 | 5310, 5315, 5320, 5325, | ||
1985 | 5330, 5335, 5340, 5345, 5350, 5355, 5360, 5365, 5370, 5375, 5380, 5385, | ||
1986 | 5390, 5395, 5400, 5405, | ||
1987 | 5410, 5415, 5420, 5425, 5430, 5435, 5440, 5445, 5450, 5455, 5460, 5465, | ||
1988 | 5470, 5475, 5480, 5485, | ||
1989 | 5490, 5495, 5500, 5505, 5510, 5515, 5520, 5525, 5530, 5535, 5540, 5545, | ||
1990 | 5550, 5555, 5560, 5565, | ||
1991 | 5570, 5575, 5580, 5585, 5590, 5595, 5600, 5605, 5610, 5615, 5620, 5625, | ||
1992 | 5630, 5635, 5640, 5645, | ||
1993 | 5650, 5655, 5660, 5665, 5670, 5675, 5680, 5685, 5690, 5695, 5700, 5705, | ||
1994 | 5710, 5715, 5720, 5725, | ||
1995 | 5730, 5735, 5740, 5745, 5750, 5755, 5760, 5765, 5770, 5775, 5780, 5785, | ||
1996 | 5790, 5795, 5800, 5805, | ||
1997 | 5810, 5815, 5820, 5825, 5830, 5835, 5840, 5845, 5850, 5855, 5860, 5865, | ||
1998 | 5870, 5875, 5880, 5885, | ||
1999 | 5890, 5895, 5900, 5905, 5910, 5915, 5920, 5925, 5930, 5935, 5940, 5945, | ||
2000 | 5950, 5955, 5960, 5965, | ||
2001 | 5970, 5975, 5980, 5985, 5990, 5995, 6000, 6005, 6010, 6015, 6020, 6025, | ||
2002 | 6030, 6035, 6040, 6045, | ||
2003 | 6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095, 6100 | ||
2004 | }; | ||
2005 | |||
2006 | return ((channel > 0) && | ||
2007 | (channel < | ||
2008 | sizeof (frequencies) / sizeof (int))) ? frequencies[channel] : -1; | ||
2009 | } | 1508 | } |
2010 | 1509 | ||
2011 | /** | 1510 | /* end of gnunet-transport-wlan-helper.c */ |
2012 | * Return the channel from the frequency (in Mhz) | ||
2013 | * @param frequency of the channel | ||
2014 | * @return number of the channel | ||
2015 | */ | ||
2016 | int | ||
2017 | getChannelFromFrequency (int frequency) | ||
2018 | { | ||
2019 | if (frequency >= 2412 && frequency <= 2472) | ||
2020 | return (frequency - 2407) / 5; | ||
2021 | else if (frequency == 2484) | ||
2022 | return 14; | ||
2023 | else if (frequency >= 5000 && frequency <= 6100) | ||
2024 | return (frequency - 5000) / 5; | ||
2025 | else | ||
2026 | return -1; | ||
2027 | } | ||