aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Brodski <david@brodski.eu>2011-03-28 21:52:47 +0000
committerDavid Brodski <david@brodski.eu>2011-03-28 21:52:47 +0000
commit76b1f350c95e6f4e28a0bc9d915f20e354fff1ab (patch)
tree939433ea0a6937ae5326539a62d1ea9e0ebb9597 /src
parentc31a1ce379ec7ade3225ddda0364cf09a65d1689 (diff)
downloadgnunet-76b1f350c95e6f4e28a0bc9d915f20e354fff1ab.tar.gz
gnunet-76b1f350c95e6f4e28a0bc9d915f20e354fff1ab.zip
First test of wlan driver, sends beacon every 2 seconds
Diffstat (limited to 'src')
-rw-r--r--src/transport/Makefile.am4
-rw-r--r--src/transport/gnunet-transport-wlan-helper.c2043
-rw-r--r--src/transport/gnunet-transport-wlan-helper.h55
-rw-r--r--src/transport/plugin_transport_wlan.c137
-rw-r--r--src/transport/plugin_transport_wlan.h69
-rw-r--r--src/transport/wlan/byteorder.h397
-rw-r--r--src/transport/wlan/crctable_osdep.h40
-rw-r--r--src/transport/wlan/helper_common.c110
-rw-r--r--src/transport/wlan/helper_common.h15
-rw-r--r--src/transport/wlan/ieee80211.h663
-rw-r--r--src/transport/wlan/ieee80211_radiotap.h260
-rw-r--r--src/transport/wlan/loopback_helper.c428
-rw-r--r--src/transport/wlan/loopback_helper.h20
-rw-r--r--src/transport/wlan/radiotap-parser.c251
-rw-r--r--src/transport/wlan/radiotap-parser.h78
15 files changed, 3472 insertions, 1098 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 550b54d10..6b1a7c9f5 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -88,7 +88,11 @@ gnunet_nat_server_SOURCES = \
88 88
89 89
90gnunet_transport_wlan_helper_SOURCES = \ 90gnunet_transport_wlan_helper_SOURCES = \
91 wlan/radiotap-parser.c \
92 wlan/helper_common.c \
93 wlan/loopback_helper.c \
91 gnunet-transport-wlan-helper.c 94 gnunet-transport-wlan-helper.c
95
92gnunet_transport_wlan_helper_LDADD = \ 96gnunet_transport_wlan_helper_LDADD = \
93 $(top_builddir)/src/util/libgnunetutil.la \ 97 $(top_builddir)/src/util/libgnunetutil.la \
94 -lpcap 98 -lpcap
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c
index 088a1fc85..5220ff067 100644
--- a/src/transport/gnunet-transport-wlan-helper.c
+++ b/src/transport/gnunet-transport-wlan-helper.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors) 3 (C) 2010 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19 */
20 20
21/** 21/**
22 * @file src/transport/gnunet-transport-wlan-helper.c 22 * @file src/transport/gnunet-transport-wlan-helper.c
@@ -28,8 +28,36 @@
28 * gnunet 28 * gnunet
29 */ 29 */
30 30
31#include <sys/socket.h>
32#include <sys/ioctl.h>
33#include <sys/types.h>
34#include <sys/wait.h>
35#include <sys/time.h>
36#include <sys/stat.h>
37#include <netpacket/packet.h>
38#include <linux/if_ether.h>
39#include <linux/if.h>
40#include <linux/wireless.h>
41#include <netinet/in.h>
42#include <linux/if_tun.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <string.h>
46#include <unistd.h>
47#include <fcntl.h>
48#include <errno.h>
49#include <dirent.h>
50//#include <sys/utsname.h>
51#include <sys/param.h>
31 52
32#include "platform.h" 53/*
54 //#include <resolv.h>
55 #include <string.h>
56 #include <utime.h>
57 //#include <unistd.h>
58 #include <getopt.h>
59 */
60//#include "platform.h"
33#include "gnunet_constants.h" 61#include "gnunet_constants.h"
34#include "gnunet_os_lib.h" 62#include "gnunet_os_lib.h"
35#include "gnunet_transport_plugin.h" 63#include "gnunet_transport_plugin.h"
@@ -39,15 +67,91 @@
39#include "gnunet_common.h" 67#include "gnunet_common.h"
40#include "gnunet-transport-wlan-helper.h" 68#include "gnunet-transport-wlan-helper.h"
41#include "gnunet_crypto_lib.h" 69#include "gnunet_crypto_lib.h"
42#include "ieee80211_radiotap.h" 70
43#include <pcap.h> 71#include <pcap.h>
44#include <stdio.h> 72#include <stdio.h>
45#include <stdlib.h> 73#include <stdlib.h>
46#include <sys/stat.h> 74#include <sys/stat.h>
47 75
76#include "wlan/radiotap-parser.h"
77/* radiotap-parser defines types like u8 that
78 * ieee80211_radiotap.h needs
79 *
80 * we use our local copy of ieee80211_radiotap.h
81 *
82 * - since we can't support extensions we don't understand
83 * - since linux does not include it in userspace headers
84 */
85#include "wlan/ieee80211_radiotap.h"
86#include "wlan/crctable_osdep.h"
87#include "wlan/loopback_helper.h"
88
89#define ARPHRD_IEEE80211 801
90#define ARPHRD_IEEE80211_PRISM 802
91#define ARPHRD_IEEE80211_FULL 803
48 92
93int first;
94int closeprog;
49 95
96#include "wlan/helper_common.h"
97#include "wlan/loopback_helper.h"
50 98
99#define DEBUG 1
100
101typedef enum
102{
103 DT_NULL = 0,
104 DT_WLANNG,
105 DT_HOSTAP,
106 DT_MADWIFI,
107 DT_MADWIFING,
108 DT_BCM43XX,
109 DT_ORINOCO,
110 DT_ZD1211RW,
111 DT_ACX,
112 DT_MAC80211_RT,
113 DT_AT76USB,
114 DT_IPW2200
115
116} DRIVER_TYPE;
117
118static const char * szaDriverTypes[] =
119 { [DT_NULL] = "Unknown", [DT_WLANNG] = "Wlan-NG", [DT_HOSTAP] = "HostAP",
120 [DT_MADWIFI] = "Madwifi", [DT_MADWIFING] = "Madwifi-NG",
121 [DT_BCM43XX] = "BCM43xx", [DT_ORINOCO] = "Orinoco",
122 [DT_ZD1211RW] = "ZD1211RW", [DT_ACX] = "ACX",
123 [DT_MAC80211_RT] = "Mac80211-Radiotap", [DT_AT76USB] = "Atmel 76_usb",
124 [DT_IPW2200] = "ipw2200" };
125
126struct Hardware_Infos
127{
128
129 struct sendbuf *write_pout;
130 int fd_in, arptype_in;
131 int fd_out, arptype_out;
132 int fd_main;
133 int fd_rtc;
134
135 DRIVER_TYPE drivertype; /* inited to DT_UNKNOWN on allocation by wi_alloc */
136
137 FILE *f_cap_in;
138
139 struct pcap_file_header pfh_in;
140
141 int sysfs_inject;
142 int channel;
143 int freq;
144 int rate;
145 int tx_power;
146 char *wlanctlng; /* XXX never set */
147 char *iwpriv;
148 char *iwconfig;
149 char *ifconfig;
150 char *iface;
151 char *main_if;
152 unsigned char pl_mac[6];
153 int inject_wlanng;
154};
51 155
52//#include "radiotap.h" 156//#include "radiotap.h"
53 157
@@ -57,20 +161,11 @@ char mac[] =
57 161
58/* wifi bitrate to use in 500kHz units */ 162/* wifi bitrate to use in 500kHz units */
59 163
60static const u8 u8aRatesToUse[] = { 164static const u8 u8aRatesToUse[] =
61 165 {
62 54*2, 166
63 48*2, 167 54 * 2, 48 * 2, 36 * 2, 24 * 2, 18 * 2, 12 * 2, 9 * 2, 11 * 2, 11, // 5.5
64 36*2, 168 2 * 2, 1 * 2 };
65 24*2,
66 18*2,
67 12*2,
68 9*2,
69 11*2,
70 11, // 5.5
71 2*2,
72 1*2
73};
74 169
75#define OFFSET_FLAGS 0x10 170#define OFFSET_FLAGS 0x10
76#define OFFSET_RATE 0x11 171#define OFFSET_RATE 0x11
@@ -78,809 +173,813 @@ static const u8 u8aRatesToUse[] = {
78// this is where we store a summary of the 173// this is where we store a summary of the
79// information from the radiotap header 174// information from the radiotap header
80 175
81typedef struct { 176typedef struct
82 int m_nChannel; 177{
83 int m_nChannelFlags; 178 int m_nChannel;
84 int m_nRate; 179 int m_nChannelFlags;
85 int m_nAntenna; 180 int m_nRate;
86 int m_nRadiotapFlags; 181 int m_nAntenna;
87} __attribute__((packed)) PENUMBRA_RADIOTAP_DATA; 182 int m_nRadiotapFlags;
183}__attribute__((packed)) PENUMBRA_RADIOTAP_DATA;
88 184
89void 185static void
90Dump(u8 * pu8, int nLength) 186sigfunc_hw(int sig)
91{ 187{
92 char sz[256], szBuf[512], szChar[17], *buf, fFirst = 1; 188 closeprog = 1;
93 unsigned char baaLast[2][16];
94 uint n, nPos = 0, nStart = 0, nLine = 0, nSameCount = 0;
95
96 buf = szBuf;
97 szChar[0] = '\0';
98
99 for (n = 0; n < nLength; n++) {
100 baaLast[(nLine&1)^1][n&0xf] = pu8[n];
101 if ((pu8[n] < 32) || (pu8[n] >= 0x7f))
102 szChar[n&0xf] = '.';
103 else
104 szChar[n&0xf] = pu8[n];
105 szChar[(n&0xf)+1] = '\0';
106 nPos += sprintf(&sz[nPos], "%02X ",
107 baaLast[(nLine&1)^1][n&0xf]);
108 if ((n&15) != 15)
109 continue;
110 if ((memcmp(baaLast[0], baaLast[1], 16) == 0) && (!fFirst)) {
111 nSameCount++;
112 } else {
113 if (nSameCount)
114 buf += sprintf(buf, "(repeated %d times)\n",
115 nSameCount);
116 buf += sprintf(buf, "%04x: %s %s\n",
117 nStart, sz, szChar);
118 nSameCount = 0;
119 printf("%s", szBuf);
120 buf = szBuf;
121 }
122 nPos = 0; nStart = n+1; nLine++;
123 fFirst = 0; sz[0] = '\0'; szChar[0] = '\0';
124 }
125 if (nSameCount)
126 buf += sprintf(buf, "(repeated %d times)\n", nSameCount);
127
128 buf += sprintf(buf, "%04x: %s", nStart, sz);
129 if (n & 0xf) {
130 *buf++ = ' ';
131 while (n & 0xf) {
132 buf += sprintf(buf, " ");
133 n++;
134 }
135 }
136 buf += sprintf(buf, "%s\n", szChar);
137 printf("%s", szBuf);
138} 189}
139 190
140
141void 191void
142usage() 192Dump(u8 * pu8, int nLength)
143{ 193{
144 printf( 194 char sz[256], szBuf[512], szChar[17], *buf, fFirst = 1;
145 "Usage: wlan-hwd [options] <interface>\n\nOptions\n" 195 unsigned char baaLast[2][16];
146 "-f/--fcs Mark as having FCS (CRC) already\n" 196 uint n, nPos = 0, nStart = 0, nLine = 0, nSameCount = 0;
147 " (pkt ends with 4 x sacrificial - chars)\n"
148 "Example:\n"
149 " echo -n mon0 > /sys/class/ieee80211/phy0/add_iface\n"
150 " iwconfig mon0 mode monitor\n"
151 " ifconfig mon0 up\n"
152 " wlan-hwd mon0 Spam down mon0 with\n"
153 " radiotap header first\n"
154 "\n");
155 exit(1);
156}
157 197
158int flagHelp = 0, flagMarkWithFCS = 0; 198 buf = szBuf;
159int flagVerbose = 0; 199 szChar[0] = '\0';
160 200
201 for (n = 0; n < nLength; n++)
202 {
203 baaLast[(nLine & 1) ^ 1][n & 0xf] = pu8[n];
204 if ((pu8[n] < 32) || (pu8[n] >= 0x7f))
205 szChar[n & 0xf] = '.';
206 else
207 szChar[n & 0xf] = pu8[n];
208 szChar[(n & 0xf) + 1] = '\0';
209 nPos += sprintf(&sz[nPos], "%02X ", baaLast[(nLine & 1) ^ 1][n & 0xf]);
210 if ((n & 15) != 15)
211 continue;
212 if ((memcmp(baaLast[0], baaLast[1], 16) == 0) && (!fFirst))
213 {
214 nSameCount++;
215 }
216 else
217 {
218 if (nSameCount)
219 buf += sprintf(buf, "(repeated %d times)\n", nSameCount);
220 buf += sprintf(buf, "%04x: %s %s\n", nStart, sz, szChar);
221 nSameCount = 0;
222 printf("%s", szBuf);
223 buf = szBuf;
224 }
225 nPos = 0;
226 nStart = n + 1;
227 nLine++;
228 fFirst = 0;
229 sz[0] = '\0';
230 szChar[0] = '\0';
231 }
232 if (nSameCount)
233 buf += sprintf(buf, "(repeated %d times)\n", nSameCount);
161 234
162/* 235 buf += sprintf(buf, "%04x: %s", nStart, sz);
163 * Radiotap parser 236 if (n & 0xf)
164 * 237 {
165 * Copyright 2007 Andy Green <andy@warmcat.com> 238 *buf++ = ' ';
166 */ 239 while (n & 0xf)
167 240 {
168/** 241 buf += sprintf(buf, " ");
169 * ieee80211_radiotap_iterator_init - radiotap parser iterator initialization 242 n++;
170 * @param iterator: radiotap_iterator to initialize 243 }
171 * @param radiotap_header: radiotap header to parse 244 }
172 * @param max_length: total length we can parse into (eg, whole packet length) 245 buf += sprintf(buf, "%s\n", szChar);
173 * 246 printf("%s", szBuf);
174 * @return 0 or a negative error code if there is a problem. 247}
175 *
176 * This function initializes an opaque iterator struct which can then
177 * be passed to ieee80211_radiotap_iterator_next() to visit every radiotap
178 * argument which is present in the header. It knows about extended
179 * present headers and handles them.
180 *
181 * How to use:
182 * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator
183 * struct ieee80211_radiotap_iterator (no need to init the struct beforehand)
184 * checking for a good 0 return code. Then loop calling
185 * __ieee80211_radiotap_iterator_next()... it returns either 0,
186 * -ENOENT if there are no more args to parse, or -EINVAL if there is a problem.
187 * The iterator's this_arg member points to the start of the argument
188 * associated with the current argument index that is present, which can be
189 * found in the iterator's this_arg_index member. This arg index corresponds
190 * to the IEEE80211_RADIOTAP_... defines.
191 *
192 * Radiotap header length:
193 * You can find the CPU-endian total radiotap header length in
194 * iterator->max_length after executing ieee80211_radiotap_iterator_init()
195 * successfully.
196 *
197 * Example code:
198 * See Documentation/networking/radiotap-headers.txt
199 */
200 248
201int ieee80211_radiotap_iterator_init( 249void
202 struct ieee80211_radiotap_iterator *iterator, 250usage()
203 struct ieee80211_radiotap_header *radiotap_header,
204 int max_length)
205{ 251{
206 /* Linux only supports version 0 radiotap format */ 252 printf("Usage: wlan-hwd [options] <interface>\n\nOptions\n"
207 if (radiotap_header->it_version) 253 "-f/--fcs Mark as having FCS (CRC) already\n"
208 return -EINVAL; 254 " (pkt ends with 4 x sacrificial - chars)\n"
209 255 "Example:\n"
210 /* sanity check for allowed length and radiotap length field */ 256 " echo -n mon0 > /sys/class/ieee80211/phy0/add_iface\n"
211 if (max_length < le16_to_cpu(radiotap_header->it_len)) 257 " iwconfig mon0 mode monitor\n"
212 return -EINVAL; 258 " ifconfig mon0 up\n"
213 259 " wlan-hwd mon0 Spam down mon0 with\n"
214 iterator->rtheader = radiotap_header; 260 " radiotap header first\n"
215 iterator->max_length = le16_to_cpu(radiotap_header->it_len); 261 "\n");
216 iterator->arg_index = 0; 262 exit(1);
217 iterator->bitmap_shifter = le32_to_cpu(radiotap_header->it_present);
218 iterator->arg = (u8 *)radiotap_header + sizeof(*radiotap_header);
219 iterator->this_arg = 0;
220
221 /* find payload start allowing for extended bitmap(s) */
222
223 if (unlikely(iterator->bitmap_shifter & (1<<IEEE80211_RADIOTAP_EXT))) {
224 while (le32_to_cpu(*((u32 *)iterator->arg)) &
225 (1<<IEEE80211_RADIOTAP_EXT)) {
226 iterator->arg += sizeof(u32);
227
228 /*
229 * check for insanity where the present bitmaps
230 * keep claiming to extend up to or even beyond the
231 * stated radiotap header length
232 */
233
234 if (((ulong)iterator->arg -
235 (ulong)iterator->rtheader) > iterator->max_length)
236 return -EINVAL;
237 }
238
239 iterator->arg += sizeof(u32);
240
241 /*
242 * no need to check again for blowing past stated radiotap
243 * header length, because ieee80211_radiotap_iterator_next
244 * checks it before it is dereferenced
245 */
246 }
247
248 /* we are all initialized happily */
249
250 return 0;
251} 263}
252 264
253 265void
254/** 266packet_callback(unsigned char *Args, const struct pcap_pkthdr* Pkthdr,
255 * ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg 267 unsigned char *Packet)
256 * @param iterator: radiotap_iterator to move to next arg (if any)
257 *
258 * @return 0 if there is an argument to handle,
259 * -ENOENT if there are no more args or -EINVAL
260 * if there is something else wrong.
261 *
262 * This function provides the next radiotap arg index (IEEE80211_RADIOTAP_*)
263 * in this_arg_index and sets this_arg to point to the
264 * payload for the field. It takes care of alignment handling and extended
265 * present fields. this_arg can be changed by the caller (eg,
266 * incremented to move inside a compound argument like
267 * IEEE80211_RADIOTAP_CHANNEL). The args pointed to are in
268 * little-endian format whatever the endianess of your CPU.
269 */
270
271int ieee80211_radiotap_iterator_next(
272 struct ieee80211_radiotap_iterator *iterator)
273{ 268{
274 269 fprintf(stderr, "+");
275 /* 270 fflush(stderr);
276 * small length lookup table for all radiotap types we heard of
277 * starting from b0 in the bitmap, so we can walk the payload
278 * area of the radiotap header
279 *
280 * There is a requirement to pad args, so that args
281 * of a given length must begin at a boundary of that length
282 * -- but note that compound args are allowed (eg, 2 x u16
283 * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not
284 * a reliable indicator of alignment requirement.
285 *
286 * upper nybble: content alignment for arg
287 * lower nybble: content length for arg
288 */
289
290 static const u8 rt_sizes[] = {
291 [IEEE80211_RADIOTAP_TSFT] = 0x88,
292 [IEEE80211_RADIOTAP_FLAGS] = 0x11,
293 [IEEE80211_RADIOTAP_RATE] = 0x11,
294 [IEEE80211_RADIOTAP_CHANNEL] = 0x24,
295 [IEEE80211_RADIOTAP_FHSS] = 0x22,
296 [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 0x11,
297 [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 0x11,
298 [IEEE80211_RADIOTAP_LOCK_QUALITY] = 0x22,
299 [IEEE80211_RADIOTAP_TX_ATTENUATION] = 0x22,
300 [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 0x22,
301 [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11,
302 [IEEE80211_RADIOTAP_ANTENNA] = 0x11,
303 [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11,
304 [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11,
305 [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22,
306 [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
307 [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11,
308 [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11
309 /*
310 * add more here as they are defined in
311 * include/net/ieee80211_radiotap.h
312 */
313 };
314
315 /*
316 * for every radiotap entry we can at
317 * least skip (by knowing the length)...
318 */
319
320 while (iterator->arg_index < sizeof(rt_sizes)) {
321 int hit = 0;
322 int pad;
323
324 if (!(iterator->bitmap_shifter & 1))
325 goto next_entry; /* arg not present */
326
327 /*
328 * arg is present, account for alignment padding
329 * 8-bit args can be at any alignment
330 * 16-bit args must start on 16-bit boundary
331 * 32-bit args must start on 32-bit boundary
332 * 64-bit args must start on 64-bit boundary
333 *
334 * note that total arg size can differ from alignment of
335 * elements inside arg, so we use upper nybble of length
336 * table to base alignment on
337 *
338 * also note: these alignments are ** relative to the
339 * start of the radiotap header **. There is no guarantee
340 * that the radiotap header itself is aligned on any
341 * kind of boundary.
342 */
343
344 pad = (((ulong)iterator->arg) -
345 ((ulong)iterator->rtheader)) &
346 ((rt_sizes[iterator->arg_index] >> 4) - 1);
347
348 if (pad)
349 iterator->arg_index +=
350 (rt_sizes[iterator->arg_index] >> 4) - pad;
351
352 /*
353 * this is what we will return to user, but we need to
354 * move on first so next call has something fresh to test
355 */
356 iterator->this_arg_index = iterator->arg_index;
357 iterator->this_arg = iterator->arg;
358 hit = 1;
359
360 /* internally move on the size of this arg */
361 iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
362
363 /*
364 * check for insanity where we are given a bitmap that
365 * claims to have more arg content than the length of the
366 * radiotap section. We will normally end up equalling this
367 * max_length on the last arg, never exceeding it.
368 */
369
370 if (((ulong)iterator->arg - (ulong)iterator->rtheader) >
371 iterator->max_length)
372 return -EINVAL;
373
374 next_entry:
375 iterator->arg_index++;
376 if (unlikely((iterator->arg_index & 31) == 0)) {
377 /* completed current u32 bitmap */
378 if (iterator->bitmap_shifter & 1) {
379 /* b31 was set, there is more */
380 /* move to next u32 bitmap */
381 iterator->bitmap_shifter =
382 le32_to_cpu(*iterator->next_bitmap);
383 iterator->next_bitmap++;
384 } else {
385 /* no more bitmaps: end */
386 iterator->arg_index = sizeof(rt_sizes);
387 }
388 } else { /* just try the next bit */
389 iterator->bitmap_shifter >>= 1;
390 }
391
392 /* if we found a valid arg earlier, return it now */
393 if (hit)
394 return 0;
395 }
396
397 /* we don't know how to handle any more args, we're done */
398 return -ENOENT;
399} 271}
400 272
401#define FIFO_FILE1 "/tmp/MYFIFOin" 273unsigned long
402#define FIFO_FILE2 "/tmp/MYFIFOout" 274calc_crc_osdep(unsigned char * buf, int len)
403#define MAXLINE 4096 275{
276 unsigned long crc = 0xFFFFFFFF;
404 277
405static int first; 278 for (; len > 0; len--, buf++)
406static int closeprog; 279 crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8);
407 280
408static void 281 return (~crc);
409sigfunc(int sig)
410{
411 closeprog = 1;
412 unlink(FIFO_FILE1);
413 unlink(FIFO_FILE2);
414} 282}
415 283
416struct sendbuf { 284/* CRC checksum verification routine */
417 int pos;
418 int size;
419 char buf[MAXLINE * 2];
420};
421 285
422static void 286int
423stdin_send (void *cls, 287check_crc_buf_osdep(unsigned char *buf, int len)
424 void *client,
425 const struct GNUNET_MessageHeader *hdr)
426{ 288{
427 struct sendbuf *write_pout = cls; 289 unsigned long crc;
428 int sendsize;
429 struct GNUNET_MessageHeader newheader;
430 char * from;
431 char * to;
432 290
433 sendsize = ntohs(hdr->size) - sizeof(struct RadiotapHeader) ; 291 if (len < 0)
292 return 0;
434 293
294 crc = calc_crc_osdep(buf, len);
295 buf += len;
296 return (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && ((crc
297 >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]);
298}
435 299
436 if(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)){ 300/* Search a file recursively */
437 fprintf(stderr, "Function stdin_send: wrong packet type\n"); 301static char *
438 exit(1); 302searchInside(const char * dir, const char * filename)
439 } 303{
440 if((sendsize + write_pout->size) > MAXLINE * 2){ 304 char * ret;
441 fprintf(stderr, "Function stdin_send: Packet too big for buffer\n"); 305 char * curfile;
442 exit(1); 306 struct stat sb;
443 } 307 int len, lentot;
308 DIR *dp;
309 struct dirent *ep;
310
311 dp = opendir(dir);
312 if (dp == NULL)
313 {
314 return NULL;
315 }
444 316
317 len = strlen(filename);
318 lentot = strlen(dir) + 256 + 2;
319 curfile = (char *) calloc(1, lentot);
445 320
446 newheader.size = htons(sendsize); 321 while ((ep = readdir(dp)) != NULL)
447 newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 322 {
448 323
324 memset(curfile, 0, lentot);
325 sprintf(curfile, "%s/%s", dir, ep->d_name);
449 326
450 to = write_pout->buf + write_pout->size; 327 //Checking if it's the good file
451 memcpy(to, &newheader, sizeof(struct GNUNET_MessageHeader)); 328 if ((int) strlen(ep->d_name) == len && !strcmp(ep->d_name, filename))
452 write_pout->size += sizeof(struct GNUNET_MessageHeader); 329 {
330 (void) closedir(dp);
331 return curfile;
332 }
333 lstat(curfile, &sb);
453 334
454 from = ((char *) hdr) + sizeof(struct RadiotapHeader) + sizeof(struct GNUNET_MessageHeader); 335 //If it's a directory and not a link, try to go inside to search
455 to = write_pout->buf + write_pout->size; 336 if (S_ISDIR(sb.st_mode) && !S_ISLNK(sb.st_mode))
456 memcpy(to, from, sendsize - sizeof(struct GNUNET_MessageHeader)); 337 {
457 write_pout->size += sendsize - sizeof(struct GNUNET_MessageHeader); 338 //Check if the directory isn't "." or ".."
339 if (strcmp(".", ep->d_name) && strcmp("..", ep->d_name))
340 {
341 //Recursive call
342 ret = searchInside(curfile, filename);
343 if (ret != NULL)
344 {
345 (void) closedir(dp);
346 free(curfile);
347 return ret;
348 }
349 }
350 }
351 }
352 (void) closedir(dp);
353 free(curfile);
354 return NULL;
458} 355}
459 356
460static void 357/* Search a wireless tool and return its path */
461file_in_send (void *cls, 358static char *
462 void *client, 359wiToolsPath(const char * tool)
463 const struct GNUNET_MessageHeader *hdr)
464{ 360{
465 struct sendbuf * write_std = cls; 361 char * path;
466 uint16_t sendsize; 362 int i, nbelems;
363 static const char * paths[] =
364 { "/sbin", "/usr/sbin", "/usr/local/sbin", "/bin", "/usr/bin",
365 "/usr/local/bin", "/tmp" };
467 366
468 sendsize = ntohs(hdr->size); 367 nbelems = sizeof(paths) / sizeof(char *);
469 368
470 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)) 369 for (i = 0; i < nbelems; i++)
471 { 370 {
472 fprintf (stderr, 371 path = searchInside(paths[i], tool);
473 "Function file_in_send: wrong packet type\n"); 372 if (path != NULL)
474 exit(1); 373 return path;
475 } 374 }
476 if((sendsize + write_std->size) > MAXLINE * 2){
477 fprintf(stderr, "Function file_in_send: Packet too big for buffer\n");
478 exit(1);
479 }
480 375
481 memcpy(write_std->buf + write_std->size, hdr, sendsize); 376 return NULL;
482 write_std->size += sendsize;
483} 377}
484 378
485/** 379static int
486 * function to create GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL message for plugin 380linux_get_channel(struct Hardware_Infos *dev)
487 * @param buffer pointer to buffer for the message 381{
488 * @param mac pointer to the mac address 382 struct iwreq wrq;
489 * @return number of bytes written 383 int fd, frequency;
490 */ 384 int chan = 0;
491 385
492int 386 memset(&wrq, 0, sizeof(struct iwreq));
493send_mac_to_plugin(char* buffer, char * mac){
494 387
495 struct Wlan_Helper_Control_Message macmsg; 388 if (dev->main_if)
389 strncpy(wrq.ifr_name, dev->main_if, IFNAMSIZ );
390 else
391 strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ );
392
393 fd = dev->fd_in;
394 if (dev->drivertype == DT_IPW2200)
395 fd = dev->fd_main;
496 396
397 if (ioctl(fd, SIOCGIWFREQ, &wrq) < 0)
398 return (-1);
497 399
400 frequency = wrq.u.freq.m;
401 if (frequency > 100000000)
402 frequency /= 100000;
403 else if (frequency > 1000000)
404 frequency /= 1000;
498 405
499 memcpy(macmsg.mac.mac, mac, sizeof(struct MacAddress)); 406 if (frequency > 1000)
500 macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message)); 407 chan = getChannelFromFrequency(frequency);
501 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 408 else
409 chan = frequency;
502 410
503 memcpy(buffer, &macmsg, sizeof(struct Wlan_Helper_Control_Message)); 411 return chan;
504 return sizeof(struct Wlan_Helper_Control_Message);
505} 412}
506 413
507int 414static int
508testmode(int argc, char *argv[]) 415linux_read(struct Hardware_Infos * dev, unsigned char *buf, int count,
416 struct rx_info * ri)
509{ 417{
510 struct stat st; 418 unsigned char tmpbuf[4096];
511 int erg; 419
420 int caplen, n, got_signal, got_noise, got_channel, fcs_removed;
421
422 caplen = n = got_signal = got_noise = got_channel = fcs_removed = 0;
423
424 if ((unsigned) count > sizeof(tmpbuf))
425 return (-1);
426 caplen = read(dev->fd_in, tmpbuf, count);
427 if (0 > caplen)
428 {
429 if (errno == EAGAIN)
430 return (0);
431
432 perror("read failed");
433 return (-1);
434 }
512 435
513 FILE *fpin; 436 memset(buf, 0, sizeof(buf));
514 FILE *fpout;
515 437
516 int fdpin; 438 /* XXX */
517 int fdpout; 439 if (ri)
440 memset(ri, 0, sizeof(*ri));
518 441
519 //make the fifos if needed 442 if (dev->arptype_in == ARPHRD_IEEE80211_PRISM)
520 if (0 != stat(FIFO_FILE1, &st))
521 { 443 {
522 if (0 == stat(FIFO_FILE2, &st)) 444 /* skip the prism header */
445 if (tmpbuf[7] == 0x40)
523 { 446 {
524 fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n"); 447 /* prism54 uses a different format */
525 exit(1); 448 if (ri)
449 {
450 ri->ri_power = tmpbuf[0x33];
451 ri->ri_noise = *(unsigned int *) (tmpbuf + 0x33 + 12);
452 ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x33 + 24)) * 500000;
453
454 got_signal = 1;
455 got_noise = 1;
456 }
457
458 n = 0x40;
526 } 459 }
460 else
461 {
462 if (ri)
463 {
464 ri->ri_mactime = *(u_int64_t*) (tmpbuf + 0x5C - 48);
465 ri->ri_channel = *(unsigned int *) (tmpbuf + 0x5C - 36);
466 ri->ri_power = *(unsigned int *) (tmpbuf + 0x5C);
467 ri->ri_noise = *(unsigned int *) (tmpbuf + 0x5C + 12);
468 ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x5C + 24)) * 500000;
469
470 got_channel = 1;
471 got_signal = 1;
472 got_noise = 1;
473 }
527 474
528 umask(0); 475 n = *(int *) (tmpbuf + 4);
529 erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0); 476 }
530 erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0);
531 477
478 if (n < 8 || n >= caplen)
479 return (0);
532 } 480 }
533 else 481
482 if (dev->arptype_in == ARPHRD_IEEE80211_FULL)
534 { 483 {
484 struct ieee80211_radiotap_iterator iterator;
485 struct ieee80211_radiotap_header *rthdr;
486
487 rthdr = (struct ieee80211_radiotap_header *) tmpbuf;
488
489 if (ieee80211_radiotap_iterator_init(&iterator, rthdr, caplen) < 0)
490 return (0);
535 491
536 if (0 != stat(FIFO_FILE2, &st)) 492 /* go through the radiotap arguments we have been given
493 * by the driver
494 */
495
496 while (ri && (ieee80211_radiotap_iterator_next(&iterator) >= 0))
537 { 497 {
538 fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n"); 498
539 exit(1); 499 switch (iterator.this_arg_index)
500 {
501
502 case IEEE80211_RADIOTAP_TSFT:
503 ri->ri_mactime = le64_to_cpu(*((uint64_t*) iterator.this_arg));
504 break;
505
506 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
507 if (!got_signal)
508 {
509 if (*iterator.this_arg < 127)
510 ri->ri_power = *iterator.this_arg;
511 else
512 ri->ri_power = *iterator.this_arg - 255;
513
514 got_signal = 1;
515 }
516 break;
517
518 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
519 if (!got_signal)
520 {
521 if (*iterator.this_arg < 127)
522 ri->ri_power = *iterator.this_arg;
523 else
524 ri->ri_power = *iterator.this_arg - 255;
525
526 got_signal = 1;
527 }
528 break;
529
530 case IEEE80211_RADIOTAP_DBM_ANTNOISE:
531 if (!got_noise)
532 {
533 if (*iterator.this_arg < 127)
534 ri->ri_noise = *iterator.this_arg;
535 else
536 ri->ri_noise = *iterator.this_arg - 255;
537
538 got_noise = 1;
539 }
540 break;
541
542 case IEEE80211_RADIOTAP_DB_ANTNOISE:
543 if (!got_noise)
544 {
545 if (*iterator.this_arg < 127)
546 ri->ri_noise = *iterator.this_arg;
547 else
548 ri->ri_noise = *iterator.this_arg - 255;
549
550 got_noise = 1;
551 }
552 break;
553
554 case IEEE80211_RADIOTAP_ANTENNA:
555 ri->ri_antenna = *iterator.this_arg;
556 break;
557
558 case IEEE80211_RADIOTAP_CHANNEL:
559 ri->ri_channel = *iterator.this_arg;
560 got_channel = 1;
561 break;
562
563 case IEEE80211_RADIOTAP_RATE:
564 ri->ri_rate = (*iterator.this_arg) * 500000;
565 break;
566
567 case IEEE80211_RADIOTAP_FLAGS:
568 /* is the CRC visible at the end?
569 * remove
570 */
571 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS)
572 {
573 fcs_removed = 1;
574 caplen -= 4;
575 }
576
577 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_RX_BADFCS)
578 return (0);
579
580 break;
581
582 }
540 } 583 }
541 584
585 n = le16_to_cpu(rthdr->it_len);
586
587 if (n <= 0 || n >= caplen)
588 return (0);
542 } 589 }
543 590
544 if (strstr(argv[2], "1")) 591 caplen -= n;
592
593 //detect fcs at the end, even if the flag wasn't set and remove it
594 if (fcs_removed == 0 && check_crc_buf_osdep(tmpbuf + n, caplen - 4) == 1)
545 { 595 {
546 //fprintf(stderr, "First\n"); 596 caplen -= 4;
547 first = 1; 597 }
548 fpin = fopen(FIFO_FILE1, "r"); 598
549 if (NULL == fpin) 599 memcpy(buf, tmpbuf + n, caplen);
550 { 600
551 fprintf(stderr, "fopen of read FIFO_FILE1\n"); 601 if (ri && !got_channel)
552 exit(1); 602 ri->ri_channel = linux_get_channel(dev);
553 } 603
554 if (NULL == (fpout = fopen(FIFO_FILE2, "w"))) 604 return (caplen);
605}
606
607static int
608linux_write(struct Hardware_Infos * dev, unsigned char *buf, unsigned int count)
609{
610 int ret, usedrtap = 0;
611 unsigned short int *p_rtlen;
612
613 unsigned char * u8aRadiotap = buf;
614
615 /* Pointer to the radiotap header length field for later use. */
616 p_rtlen = (unsigned short int*) (u8aRadiotap + 2);
617 usedrtap = 0;
618 ret = write(dev->fd_out, buf, count);
619
620 if (ret < 0)
621 {
622 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || errno
623 == ENOMEM)
555 { 624 {
556 fprintf(stderr, "fopen of write FIFO_FILE2\n"); 625 usleep(10000);
557 exit(1); 626 return (0);
558 } 627 }
559 628
629 perror("write failed");
630 return (-1);
560 } 631 }
561 else 632
633 /* radiotap header length is stored little endian on all systems */
634 if (usedrtap)
635 ret -= letoh16(*p_rtlen);
636
637 if (ret < 0)
562 { 638 {
563 first = 0; 639 if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || errno
564 //fprintf(stderr, "Second\n"); 640 == ENOMEM)
565 if (NULL == (fpout = fopen(FIFO_FILE1, "w")))
566 { 641 {
567 fprintf(stderr, "fopen of write FIFO_FILE1\n"); 642 usleep(10000);
568 exit(1); 643 return (0);
569 }
570 if (NULL == (fpin = fopen(FIFO_FILE2, "r")))
571 {
572 fprintf(stderr, "fopen of read FIFO_FILE2\n");
573 exit(1);
574 } 644 }
575 645
646 perror("write failed");
647 return (-1);
576 } 648 }
577 649
578 fdpin = fileno(fpin); 650 return (ret);
579 if (fdpin >= FD_SETSIZE) 651}
652
653static int
654openraw(struct Hardware_Infos * dev, char * iface, int fd, int * arptype,
655 uint8_t *mac)
656{
657 struct ifreq ifr;
658 struct iwreq wrq;
659 struct packet_mreq mr;
660 struct sockaddr_ll sll;
661
662 /* find the interface index */
663
664 memset(&ifr, 0, sizeof(ifr));
665 strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name) - 1);
666
667 if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0)
580 { 668 {
581 fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin, 669 printf("Interface %s: \n", iface);
582 (unsigned int) FD_SETSIZE); 670 perror("ioctl(SIOCGIFINDEX) failed");
583 close(fdpin); 671 return (1);
584 return -1;
585 } 672 }
586 673
587 fdpout = fileno(fpout); 674 memset(&sll, 0, sizeof(sll));
588 if (fdpout >= FD_SETSIZE) 675 sll.sll_family = AF_PACKET;
676 sll.sll_ifindex = ifr.ifr_ifindex;
677
678 switch (dev->drivertype)
589 { 679 {
590 fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout, 680 default:
591 (unsigned int) FD_SETSIZE); 681 sll.sll_protocol = htons(ETH_P_ALL);
592 close(fdpout); 682 break;
593 return -1; 683 }
594 684
685 /* lookup the hardware type */
686
687 if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
688 {
689 printf("Interface %s: \n", iface);
690 perror("ioctl(SIOCGIFHWADDR) failed");
691 return (1);
595 } 692 }
596 693
597 signal(SIGINT, &sigfunc); 694 /* lookup iw mode */
598 signal(SIGTERM, &sigfunc); 695 memset(&wrq, 0, sizeof(struct iwreq));
696 strncpy(wrq.ifr_name, iface, IFNAMSIZ);
599 697
600 char readbuf[MAXLINE]; 698 if (ioctl(fd, SIOCGIWMODE, &wrq) < 0)
601 int readsize = 0; 699 {
602 struct sendbuf write_std; 700 /* most probably not supported (ie for rtap ipw interface) *
603 write_std.size = 0; 701 * so just assume its correctly set... */
604 write_std.pos = 0; 702 wrq.u.mode = IW_MODE_MONITOR;
703 }
605 704
606 struct sendbuf write_pout; 705 if ((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211 && ifr.ifr_hwaddr.sa_family
607 write_pout.size = 0; 706 != ARPHRD_IEEE80211_PRISM && ifr.ifr_hwaddr.sa_family
608 write_pout.pos = 0; 707 != ARPHRD_IEEE80211_FULL) || (wrq.u.mode != IW_MODE_MONITOR))
708 {
709 printf("Error: %s not in monitor mode\n", iface);
710 return (1);
711 }
609 712
610 int ret = 0; 713 /* Is interface st to up, broadcast & running ? */
611 int maxfd = 0; 714 if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags)
715 {
716 /* Bring interface up*/
717 ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING;
612 718
613 fd_set rfds; 719 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)
614 fd_set wfds; 720 {
615 struct timeval tv; 721 perror("ioctl(SIOCSIFFLAGS) failed");
616 int retval; 722 return (1);
723 }
724 }
725 /* bind the raw socket to the interface */
617 726
727 if (bind(fd, (struct sockaddr *) &sll, sizeof(sll)) < 0)
728 {
729 printf("Interface %s: \n", iface);
730 perror("bind(ETH_P_ALL) failed");
731 return (1);
732 }
618 733
734 /* lookup the hardware type */
619 735
620 struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst; 736 if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0)
621 struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst; 737 {
738 printf("Interface %s: \n", iface);
739 perror("ioctl(SIOCGIFHWADDR) failed");
740 return (1);
741 }
622 742
623 stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout); 743 memcpy(mac, (unsigned char*) ifr.ifr_hwaddr.sa_data, 6);
624 file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std);
625 744
626 //send mac first 745 *arptype = ifr.ifr_hwaddr.sa_family;
627 746
628 struct MacAddress macaddr; 747 if (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211 && ifr.ifr_hwaddr.sa_family
748 != ARPHRD_IEEE80211_PRISM && ifr.ifr_hwaddr.sa_family
749 != ARPHRD_IEEE80211_FULL)
750 {
751 if (ifr.ifr_hwaddr.sa_family == 1)
752 fprintf(stderr, "\nARP linktype is set to 1 (Ethernet) ");
753 else
754 fprintf(stderr, "\nUnsupported hardware link type %4d ",
755 ifr.ifr_hwaddr.sa_family);
756
757 fprintf(stderr, "- expected ARPHRD_IEEE80211,\nARPHRD_IEEE80211_"
758 "FULL or ARPHRD_IEEE80211_PRISM instead. Make\n"
759 "sure RFMON is enabled: run 'airmon-ng start %s"
760 " <#>'\nSysfs injection support was not found "
761 "either.\n\n", iface);
762 return (1);
763 }
629 764
630 //Send random mac address 765 /* enable promiscuous mode */
631 macaddr.mac[0] = 0x13;
632 macaddr.mac[1] = 0x22;
633 macaddr.mac[2] = 0x33;
634 macaddr.mac[3] = 0x44;
635 macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256);
636 macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256);
637 766
638 write_std.size = send_mac_to_plugin((char *) &write_std.buf, macaddr.mac); 767 memset(&mr, 0, sizeof(mr));
768 mr.mr_ifindex = sll.sll_ifindex;
769 mr.mr_type = PACKET_MR_PROMISC;
639 770
640 /* 771 if (setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, sizeof(mr)) < 0)
641 //wait 772 {
642 tv.tv_sec = 2; 773 perror("setsockopt(PACKET_MR_PROMISC) failed");
643 tv.tv_usec = 0; 774 return (1);
644 retval = select(0, NULL, NULL, NULL, &tv); 775 }
645 776
777 return (0);
778}
646 779
647 tv.tv_sec = 3; 780int
648 tv.tv_usec = 0; 781wlaninit(struct Hardware_Infos * dev, char *iface)
649 // if there is something to write 782{
650 FD_ZERO(&wfds);
651 FD_SET(STDOUT_FILENO, &wfds);
652 783
653 retval = select(STDOUT_FILENO + 1, NULL, &wfds, NULL, &tv); 784 char *iwpriv;
785 char strbuf[512];
786 dev->inject_wlanng = 1;
787 dev->rate = 2; /* default to 1Mbps if nothing is set */
654 788
655 if (FD_ISSET(STDOUT_FILENO, &wfds)) 789 /* open raw socks */
790 dev->fd_in = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
791 if (0 > dev->fd_in)
656 { 792 {
657 ret = write(STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size 793 perror("socket(PF_PACKET) failed at fd_in");
658 - write_std.pos); 794 if (getuid() != 0)
659 795 fprintf(stderr, "This program requires root privileges.\n");
660 if (0 > ret) 796 return (1);
661 {
662 closeprog = 1;
663 fprintf(stderr, "Write ERROR to STDOUT");
664 exit(1);
665 }
666 else
667 {
668 write_std.pos += ret;
669 // check if finished
670 if (write_std.pos == write_std.size)
671 {
672 write_std.pos = 0;
673 write_std.size = 0;
674 }
675 }
676 } 797 }
677 798
678 memcpy(&write_std.buf, &macmsg, sizeof(struct Wlan_Helper_Control_Message)); 799 dev->fd_main = socket(PF_PACKET, SOCK_RAW, htons( ETH_P_ALL ) );
679 write_std.size = sizeof(struct Wlan_Helper_Control_Message); 800 if (0 > dev->fd_main)
680 */
681
682 //wait
683 tv.tv_sec = 2;
684 tv.tv_usec = 0;
685 retval = select(0, NULL, NULL, NULL, &tv);
686
687 while (0 == closeprog)
688 { 801 {
802 perror("socket(PF_PACKET) failed at fd_main");
803 if (getuid() != 0)
804 fprintf(stderr, "This program requires root privileges.\n");
805 return (1);
806 }
689 807
690 maxfd = 0; 808 /* Check iwpriv existence */
691 809
692 //set timeout 810 iwpriv = wiToolsPath("iwpriv");
693 tv.tv_sec = 5; 811 dev->iwpriv = iwpriv;
694 tv.tv_usec = 0; 812 dev->iwconfig = wiToolsPath("iwconfig");
813 dev->ifconfig = wiToolsPath("ifconfig");
695 814
696 FD_ZERO(&rfds); 815 if (!iwpriv)
697 // if output queue is empty 816 {
698 if (0 == write_pout.size) 817 fprintf(stderr, "Can't find wireless tools, exiting.\n");
699 { 818 goto close_in;
700 FD_SET(STDIN_FILENO, &rfds); 819 }
701 820
702 } 821 dev->fd_out = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
703 if (0 == write_std.size) 822 if (0 > dev->fd_out)
704 { 823 {
705 FD_SET(fdpin, &rfds); 824 perror("socket(PF_PACKET) failed at fd_out");
706 maxfd = fdpin; 825 goto close_in;
707 } 826 }
708 FD_ZERO(&wfds);
709 // if there is something to write
710 if (0 < write_std.size){
711 FD_SET(STDOUT_FILENO, &wfds);
712 maxfd = MAX(maxfd, STDOUT_FILENO);
713 }
714 827
715 if (0 < write_pout.size){ 828 /* figure out device type */
716 FD_SET(fdpout, &wfds);
717 maxfd = MAX(maxfd, fdpout);
718 }
719 829
830 /* mac80211 radiotap injection
831 * detected based on interface called mon...
832 * since mac80211 allows multiple virtual interfaces
833 *
834 * note though that the virtual interfaces are ultimately using a
835 * single physical radio: that means for example they must all
836 * operate on the same channel
837 */
720 838
721 retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv); 839 /* mac80211 stack detection */
840 memset(strbuf, 0, sizeof(strbuf));
841 snprintf(strbuf, sizeof(strbuf) - 1,
842 "ls /sys/class/net/%s/phy80211/subsystem >/dev/null 2>/dev/null", iface);
722 843
723 if (-1 == retval && EINTR == errno) 844 if (system(strbuf) == 0)
724 { 845 dev->drivertype = DT_MAC80211_RT;
725 continue;
726 }
727 if (0 > retval)
728 {
729 fprintf(stderr, "select failed: %s\n", strerror(errno));
730 exit(1);
731 }
732 846
733 if (FD_ISSET(STDOUT_FILENO, &wfds)) 847 else
734 { 848 {
735 ret = write(STDOUT_FILENO, write_std.buf + write_std.pos, 849 // At the moment only mac80211 tested
736 write_std.size - write_std.pos); 850 return 1;
851 }
737 852
738 if (0 > ret) 853#ifdef DEBUG
739 { 854 fprintf(stderr, "Interface %s -> driver: %s\n", iface,
740 closeprog = 1; 855 szaDriverTypes[dev->drivertype]);
741 fprintf(stderr, "Write ERROR to STDOUT\n"); 856#endif
742 exit(1);
743 }
744 else
745 {
746 write_std.pos += ret;
747 // check if finished
748 if (write_std.pos == write_std.size)
749 {
750 write_std.pos = 0;
751 write_std.size = 0;
752 }
753 }
754 }
755 857
756 if (FD_ISSET(fdpout, &wfds)) 858 if (openraw(dev, iface, dev->fd_out, &dev->arptype_out, dev->pl_mac) != 0)
757 { 859 {
758 ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size 860 goto close_out;
759 - write_pout.pos); 861 }
760 862
761 if (0 > ret) 863 dev->fd_in = dev->fd_out;
762 {
763 closeprog = 1;
764 fprintf(stderr, "Write ERROR to fdpout\n");
765 }
766 else
767 {
768 write_pout.pos += ret;
769 // check if finished
770 if (write_pout.pos == write_pout.size)
771 {
772 write_pout.pos = 0;
773 write_pout.size = 0;
774 }
775 }
776 }
777 864
778 if (FD_ISSET(STDIN_FILENO, &rfds)) 865 dev->arptype_in = dev->arptype_out;
779 {
780 readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf));
781 866
782 if (0 > readsize) 867 return 0;
783 { 868 close_out: close(dev->fd_out);
784 closeprog = 1; 869 close_in: close(dev->fd_in);
785 fprintf(stderr, "Read ERROR to STDIN_FILENO\n"); 870 return 1;
786 } 871}
787 else if (0 < readsize)
788 {
789 GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize,
790 GNUNET_NO, GNUNET_NO);
791 872
792 } 873static void
793 else 874stdin_send_hw(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
794 { 875{
795 //eof 876 struct Hardware_Infos * dev = cls;
796 closeprog = 1; 877 struct sendbuf *write_pout = dev->write_pout;
797 } 878 struct Radiotap_Send * header = (struct Radiotap_Send *) &hdr[1];
798 } 879 int sendsize;
799 880
800 if (FD_ISSET(fdpin, &rfds)) 881 unsigned char u8aRadiotap[] =
801 { 882 { 0x00, 0x00, // <-- radiotap version
802 readsize = read(fdpin, readbuf, sizeof(readbuf)); 883 0x0c, 0x00, // <- radiotap header length
884 0x04, 0x80, 0x00, 0x00, // <-- bitmap
885 0x00, // <-- rate
886 0x00, // <-- padding for natural alignment
887 0x18, 0x00, // <-- TX flags
888 };
803 889
804 if (0 > readsize) 890 sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send)
805 { 891 - sizeof(struct GNUNET_MessageHeader);
806 closeprog = 1;
807 fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno));
808 closeprog = 1;
809 }
810 else if (0 < readsize)
811 {
812 GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize,
813 GNUNET_NO, GNUNET_NO);
814 892
815 } 893 if ((sendsize) > MAXLINE * 2)
816 else 894 {
817 { 895 fprintf(stderr, "Function stdin_send: Packet too big for buffer\n");
818 //eof 896 exit(1);
819 closeprog = 1; 897 }
820 }
821 }
822 898
899 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type))
900 {
901 fprintf(stderr, "Function stdin_send: wrong packet type\n");
902 exit(1);
823 } 903 }
824 904
825 //clean up 905 u8aRadiotap[8] = header->rate;
826 fclose(fpout);
827 fclose(fpin);
828 906
829 if (1 == first) 907 switch (dev->drivertype)
830 { 908 {
831 unlink(FIFO_FILE1); 909
832 unlink(FIFO_FILE2); 910 case DT_MAC80211_RT:
911 memcpy(write_pout->buf, u8aRadiotap, sizeof(u8aRadiotap));
912 memcpy(write_pout->buf + sizeof(u8aRadiotap), write_pout->buf
913 + sizeof(struct Radiotap_Send) + sizeof(struct GNUNET_MessageHeader),
914 sendsize);
915 sendsize += sizeof(u8aRadiotap);
916
917 //usedrtap = 1;
918 break;
919 default:
920 break;
833 } 921 }
834 922
835 return (0); 923 write_pout->size = sendsize;
836} 924}
837 925
838void packet_callback(unsigned char *Args, 926int
839 const struct pcap_pkthdr* Pkthdr, 927maketest(unsigned char * buf)
840 unsigned char *Packet)
841{ 928{
842fprintf(stderr, "+"); fflush(stderr); 929 unsigned char u8aRadiotap[] =
843} 930 { 0x00, 0x00, // <-- radiotap version
931 0x0c, 0x00, // <- radiotap header length
932 0x04, 0x80, 0x00, 0x00, // <-- bitmap
933 0x00, // <-- rate
934 0x00, // <-- padding for natural alignment
935 0x18, 0x00, // <-- TX flags
936 };
937
938 static const uint8_t u8aIeeeHeader[] =
939 { 0x08, 0x01, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0;
940 // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data
941 // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS;
942 0x00, 0x00, // Duration/ID
943 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // mac1 - in this case receiver
944 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac2 - in this case sender
945 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
946 0x10, 0x86, //Sequence Control
947 };
948
949 static const char txt[] = "Hallo1Hallo2 Hallo3 Hallo4...998877665544332211";
950
951 u8aRadiotap[8] = 8;
952 memcpy(buf, u8aRadiotap, sizeof(u8aRadiotap));
953 struct ieee80211_frame * ieee = (struct ieee80211_frame *) u8aIeeeHeader;
954 memcpy(buf + sizeof(u8aRadiotap), ieee, sizeof(u8aIeeeHeader));
955 memcpy(buf + sizeof(u8aRadiotap) + sizeof(u8aIeeeHeader), txt, sizeof(txt));
956 return sizeof(u8aRadiotap) + sizeof(u8aIeeeHeader) + sizeof(txt);
844 957
958}
845 959
846int 960int
847hardwaremode(int argc, char *argv[]) 961hardwaremode(int argc, char *argv[])
848{ 962{
849 963
964 struct Hardware_Infos dev;
850 struct ifreq ifreq; 965 struct ifreq ifreq;
851 char mac[6]; 966 struct rx_info * rxinfo;
852 int SockFD; 967 uint8_t * mac = dev.pl_mac;
968 int fdpin, fdpout;
853 969
854 int fdpin; 970 signal(SIGINT, &sigfunc_hw);
855 int fdpout; 971 signal(SIGTERM, &sigfunc_hw);
856 972
857 pcap_t *ppcap = NULL; 973 if (wlaninit(&dev, argv[1]))
858 char szErrbuf[PCAP_ERRBUF_SIZE];
859
860 SockFD = socket(AF_INET, SOCK_DGRAM, 0);
861
862 strcpy(ifreq.ifr_name, argv[1]);
863 if (ioctl(SockFD, SIOCGIFHWADDR, &ifreq) < 0)
864 { 974 {
865 printf("SIOCGIFHWADDR(%s): %m\n", ifreq.ifr_name); 975 return 1;
866 return 0;
867 } 976 }
868 977
869 //copy mac to mac array
870 memcpy(mac, ifreq.ifr_hwaddr.sa_data, sizeof(struct MacAddress));
871
872 printf("Device %s -> Ethernet %02x:%02x:%02x:%02x:%02x:%02x\n", 978 printf("Device %s -> Ethernet %02x:%02x:%02x:%02x:%02x:%02x\n",
873 ifreq.ifr_name, (int) mac[0], (int) mac[1], (int) mac[2], (int) mac[3], 979 ifreq.ifr_name, (int) mac[0], (int) mac[1], (int) mac[2], (int) mac[3],
874 (int) mac[4], (int) mac[5]); 980 (int) mac[4], (int) mac[5]);
875 981
876 return 0; 982 //return 0;
877 // open the interface in pcap
878 ppcap = pcap_open_live(argv[1], 800, 1, 20, szErrbuf);
879 if (ppcap == NULL)
880 {
881 printf("Unable to open interface %s in pcap: %s\n", argv[1], szErrbuf);
882 return (1);
883 }
884 983
885 char readbuf[MAXLINE]; 984 char readbuf[MAXLINE];
886 int readsize = 0; 985 int readsize = 0;
@@ -892,6 +991,8 @@ hardwaremode(int argc, char *argv[])
892 write_pout.size = 0; 991 write_pout.size = 0;
893 write_pout.pos = 0; 992 write_pout.pos = 0;
894 993
994 dev.write_pout = &write_pout;
995
895 int ret = 0; 996 int ret = 0;
896 int maxfd = 0; 997 int maxfd = 0;
897 998
@@ -901,13 +1002,11 @@ hardwaremode(int argc, char *argv[])
901 int retval; 1002 int retval;
902 1003
903 struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst; 1004 struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst;
904 struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst;
905 1005
906 fdpin = pcap_fileno(ppcap); 1006 fdpin = dev.fd_in;
907 fdpout = pcap_fileno(ppcap); 1007 fdpout = dev.fd_out;
908 1008
909 stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout); 1009 stdin_mst = GNUNET_SERVER_mst_create(&stdin_send_hw, &dev);
910 file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std);
911 1010
912 //send mac first 1011 //send mac first
913 1012
@@ -921,6 +1020,11 @@ hardwaremode(int argc, char *argv[])
921 while (0 == closeprog) 1020 while (0 == closeprog)
922 { 1021 {
923 1022
1023 write_pout.size = maketest(write_pout.buf);
1024 tv.tv_sec = 2;
1025 tv.tv_usec = 0;
1026 retval = select(0, NULL, NULL, NULL, &tv);
1027
924 maxfd = 0; 1028 maxfd = 0;
925 1029
926 //set timeout 1030 //set timeout
@@ -936,8 +1040,8 @@ hardwaremode(int argc, char *argv[])
936 } 1040 }
937 if (0 == write_std.size) 1041 if (0 == write_std.size)
938 { 1042 {
939 FD_SET(fdpin, &rfds); 1043 //FD_SET(fdpin, &rfds);
940 maxfd = fdpin; 1044 //maxfd = fdpin;
941 } 1045 }
942 FD_ZERO(&wfds); 1046 FD_ZERO(&wfds);
943 // if there is something to write 1047 // if there is something to write
@@ -990,8 +1094,10 @@ hardwaremode(int argc, char *argv[])
990 1094
991 if (FD_ISSET(fdpout, &wfds)) 1095 if (FD_ISSET(fdpout, &wfds))
992 { 1096 {
993 ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size 1097
994 - write_pout.pos); 1098 ret = linux_write(&dev, write_pout.buf, write_pout.size);
1099 //ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size
1100 // - write_pout.pos);
995 1101
996 if (0 > ret) 1102 if (0 > ret)
997 { 1103 {
@@ -1002,11 +1108,17 @@ hardwaremode(int argc, char *argv[])
1002 { 1108 {
1003 write_pout.pos += ret; 1109 write_pout.pos += ret;
1004 // check if finished 1110 // check if finished
1005 if (write_pout.pos == write_pout.size) 1111 if (write_pout.pos != write_pout.size && ret != 0)
1112 {
1113 closeprog = 1;
1114 fprintf(stderr, "Write ERROR packet not in one piece send: %u, %u\n", write_pout.pos, write_pout.size);
1115 }
1116 else if (write_pout.pos == write_pout.size)
1006 { 1117 {
1007 write_pout.pos = 0; 1118 write_pout.pos = 0;
1008 write_pout.size = 0; 1119 write_pout.size = 0;
1009 } 1120 }
1121
1010 } 1122 }
1011 } 1123 }
1012 1124
@@ -1034,7 +1146,13 @@ hardwaremode(int argc, char *argv[])
1034 1146
1035 if (FD_ISSET(fdpin, &rfds)) 1147 if (FD_ISSET(fdpin, &rfds))
1036 { 1148 {
1037 readsize = read(fdpin, readbuf, sizeof(readbuf)); 1149 rxinfo = (struct rx_info *) (write_pout.buf
1150 + sizeof(struct GNUNET_MessageHeader));
1151 readsize = linux_read(&dev, (unsigned char *) readbuf
1152 + sizeof(struct rx_info) + sizeof(struct GNUNET_MessageHeader),
1153 sizeof(readbuf) - sizeof(struct rx_info)
1154 - sizeof(struct GNUNET_MessageHeader), rxinfo);
1155 //readsize = read(fdpin, readbuf, sizeof(readbuf));
1038 1156
1039 if (0 > readsize) 1157 if (0 > readsize)
1040 { 1158 {
@@ -1044,19 +1162,19 @@ hardwaremode(int argc, char *argv[])
1044 } 1162 }
1045 else if (0 < readsize) 1163 else if (0 < readsize)
1046 { 1164 {
1047 GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize,
1048 GNUNET_NO, GNUNET_NO);
1049 1165
1050 } 1166 }
1051 else 1167 else
1052 { 1168 {
1053 //eof 1169 //eof
1054 closeprog = 1; 1170 //closeprog = 1;
1055 } 1171 }
1056 } 1172 }
1057 1173
1058 } 1174 }
1059 1175
1176 return 0;
1177
1060} 1178}
1061 1179
1062int 1180int
@@ -1074,269 +1192,274 @@ main(int argc, char *argv[])
1074 { 1192 {
1075 1193
1076 return testmode(argc, argv); 1194 return testmode(argc, argv);
1077 } else { 1195 }
1196 else
1197 {
1078 hardwaremode(argc, argv); 1198 hardwaremode(argc, argv);
1079 } 1199 }
1080 1200
1081#if 0 1201#if 0
1082 u8 u8aSendBuffer[500]; 1202 u8 u8aSendBuffer[500];
1083 char szErrbuf[PCAP_ERRBUF_SIZE]; 1203 char szErrbuf[PCAP_ERRBUF_SIZE];
1084 int nCaptureHeaderLength = 0, n80211HeaderLength = 0, nLinkEncap = 0; 1204 int nCaptureHeaderLength = 0, n80211HeaderLength = 0, nLinkEncap = 0;
1085 int nOrdinal = 0, r, nDelay = 100000; 1205 int nOrdinal = 0, r, nDelay = 100000;
1086 int nRateIndex = 0, retval, bytes; 1206 int nRateIndex = 0, retval, bytes;
1087 pcap_t *ppcap = NULL; 1207 pcap_t *ppcap = NULL;
1088 struct bpf_program bpfprogram; 1208 struct bpf_program bpfprogram;
1089 char * szProgram = "", fBrokenSocket = 0; 1209 char * szProgram = "", fBrokenSocket = 0;
1090 u16 u16HeaderLen; 1210 u16 u16HeaderLen;
1091 char szHostname[PATH_MAX]; 1211 char szHostname[PATH_MAX];
1092 1212
1093 if (gethostname(szHostname, sizeof (szHostname) - 1)) { 1213 if (gethostname(szHostname, sizeof (szHostname) - 1))
1094 perror("unable to get hostname"); 1214 {
1095 } 1215 perror("unable to get hostname");
1096 szHostname[sizeof (szHostname) - 1] = '\0'; 1216 }
1097 1217 szHostname[sizeof (szHostname) - 1] = '\0';
1098 1218
1099 printf("Packetspammer (c)2007 Andy Green <andy@warmcat.com> GPL2\n"); 1219 printf("Packetspammer (c)2007 Andy Green <andy@warmcat.com> GPL2\n");
1100 1220
1101 while (1) { 1221 while (1)
1102 int nOptionIndex; 1222 {
1103 static const struct option optiona[] = { 1223 int nOptionIndex;
1104 { "delay", required_argument, NULL, 'd' }, 1224 static const struct option optiona[] =
1105 { "fcs", no_argument, &flagMarkWithFCS, 1 }, 1225 {
1106 { "help", no_argument, &flagHelp, 1 }, 1226 { "delay", required_argument, NULL, 'd'},
1107 { "verbose", no_argument, &flagVerbose, 1}, 1227 { "fcs", no_argument, &flagMarkWithFCS, 1},
1108 { 0, 0, 0, 0 } 1228 { "help", no_argument, &flagHelp, 1},
1109 }; 1229 { "verbose", no_argument, &flagVerbose, 1},
1110 int c = getopt_long(argc, argv, "d:hf", 1230 { 0, 0, 0, 0}
1111 optiona, &nOptionIndex); 1231 };
1112 1232 int c = getopt_long(argc, argv, "d:hf",
1113 if (c == -1) 1233 optiona, &nOptionIndex);
1114 break; 1234
1115 switch (c) { 1235 if (c == -1)
1116 case 0: // long option 1236 break;
1117 break; 1237 switch (c)
1118 1238 {
1119 case 'h': // help 1239 case 0: // long option
1120 usage(); 1240 break;
1121 1241
1122 case 'd': // delay 1242 case 'h': // help
1123 nDelay = atoi(optarg); 1243 usage();
1124 break; 1244
1125 1245 case 'd': // delay
1126 case 'f': // mark as FCS attached 1246 nDelay = atoi(optarg);
1127 flagMarkWithFCS = 1; 1247 break;
1128 break; 1248
1129 1249 case 'f': // mark as FCS attached
1130 case 'v': //Verbose / readable output to cout 1250 flagMarkWithFCS = 1;
1131 flagVerbose = 1; 1251 break;
1132 break; 1252
1133 1253 case 'v': //Verbose / readable output to cout
1134 default: 1254 flagVerbose = 1;
1135 printf("unknown switch %c\n", c); 1255 break;
1136 usage(); 1256
1137 break; 1257 default:
1138 } 1258 printf("unknown switch %c\n", c);
1139 } 1259 usage();
1140 1260 break;
1141 if (optind >= argc) 1261 }
1142 usage(); 1262 }
1143 1263
1144 1264 if (optind >= argc)
1145 // open the interface in pcap 1265 usage();
1146
1147 szErrbuf[0] = '\0';
1148 ppcap = pcap_open_live(argv[optind], 800, 1, 20, szErrbuf);
1149 if (ppcap == NULL) {
1150 printf("Unable to open interface %s in pcap: %s\n",
1151 argv[optind], szErrbuf);
1152 return (1);
1153 }
1154
1155 //get mac from interface
1156
1157 /*int sock, j, k;
1158 char mac[32];
1159
1160 sock=socket(PF_INET, SOCK_STREAM, 0);
1161 if (-1==sock) {
1162 perror("can not open socket\n");
1163 return 1;
1164 }
1165
1166 if (-1==ioctl(sock, SIOCGIFHWADDR, &ifr)) {
1167 perror("ioctl(SIOCGIFHWADDR) ");
1168 return 1;
1169 }
1170 for (j=0, k=0; j<6; j++) {
1171 k+=snprintf(mac+k, sizeof(mac)-k-1, j ? ":%02X" : "%02X",
1172 (int)(unsigned int)(unsigned char)ifr.ifr_hwaddr.sa_data[j]);
1173 }
1174 mac[sizeof(mac)-1]='\0';
1175 */
1176
1177 //get header type
1178 nLinkEncap = pcap_datalink(ppcap);
1179 nCaptureHeaderLength = 0;
1180
1181 switch (nLinkEncap) {
1182
1183 case DLT_PRISM_HEADER:
1184 printf("DLT_PRISM_HEADER Encap\n");
1185 nCaptureHeaderLength = 0x40;
1186 n80211HeaderLength = 0x20; // ieee80211 comes after this
1187 szProgram = "radio[0x4a:4]==0x13223344";
1188 break;
1189
1190 case DLT_IEEE802_11_RADIO:
1191 printf("DLT_IEEE802_11_RADIO Encap\n");
1192 nCaptureHeaderLength = 0x40;
1193 n80211HeaderLength = 0x18; // ieee80211 comes after this
1194 szProgram = "ether[0x0a:4]==0x13223344";
1195 break;
1196
1197 default:
1198 printf("!!! unknown encapsulation on %s !\n", argv[1]);
1199 return (1);
1200
1201 }
1202
1203 if (pcap_compile(ppcap, &bpfprogram, szProgram, 1, 0) == -1) {
1204 puts(szProgram);
1205 puts(pcap_geterr(ppcap));
1206 return (1);
1207 } else {
1208 if (pcap_setfilter(ppcap, &bpfprogram) == -1) {
1209 puts(szProgram);
1210 puts(pcap_geterr(ppcap));
1211 } else {
1212 printf("RX Filter applied\n");
1213 }
1214 pcap_freecode(&bpfprogram);
1215 }
1216
1217 pcap_setnonblock(ppcap, 1, szErrbuf);
1218
1219 printf(" (delay between packets %dus)\n", nDelay);
1220
1221 memset(u8aSendBuffer, 0, sizeof (u8aSendBuffer));
1222
1223 while (!fBrokenSocket) {
1224 u8 * pu8 = u8aSendBuffer;
1225 struct pcap_pkthdr * ppcapPacketHeader = NULL;
1226 struct ieee80211_radiotap_iterator rti;
1227 PENUMBRA_RADIOTAP_DATA prd;
1228 //init of the values
1229 prd.m_nRate = 255;
1230 prd.m_nChannel = 255;
1231 prd.m_nAntenna = 255;
1232 prd.m_nRadiotapFlags = 255;
1233 u8 * pu8Payload = u8aSendBuffer;
1234 int n, nRate;
1235
1236 // receive
1237
1238 retval = pcap_next_ex(ppcap, &ppcapPacketHeader,
1239 (const u_char**)&pu8Payload);
1240
1241 if (retval < 0) {
1242 fBrokenSocket = 1;
1243 continue;
1244 }
1245
1246 if (retval != 1)
1247 goto do_tx;
1248
1249 u16HeaderLen = (pu8Payload[2] + (pu8Payload[3] << 8));
1250
1251 printf("rtap: ");
1252 Dump(pu8Payload, u16HeaderLen);
1253
1254 if (ppcapPacketHeader->len <
1255 (u16HeaderLen + n80211HeaderLength))
1256 continue;
1257
1258 bytes = ppcapPacketHeader->len -
1259 (u16HeaderLen + n80211HeaderLength);
1260 if (bytes < 0)
1261 continue;
1262
1263 if (ieee80211_radiotap_iterator_init(&rti,
1264 (struct ieee80211_radiotap_header *)pu8Payload,
1265 bytes) < 0)
1266 continue;
1267
1268 while ((n = ieee80211_radiotap_iterator_next(&rti)) == 0) {
1269
1270 switch (rti.this_arg_index) {
1271 case IEEE80211_RADIOTAP_RATE:
1272 prd.m_nRate = (*rti.this_arg);
1273 break;
1274
1275 case IEEE80211_RADIOTAP_CHANNEL:
1276 prd.m_nChannel =
1277 le16_to_cpu(*((u16 *)rti.this_arg));
1278 prd.m_nChannelFlags =
1279 le16_to_cpu(*((u16 *)(rti.this_arg + 2)));
1280 break;
1281
1282 case IEEE80211_RADIOTAP_ANTENNA:
1283 prd.m_nAntenna = (*rti.this_arg) + 1;
1284 break;
1285
1286 case IEEE80211_RADIOTAP_FLAGS:
1287 prd.m_nRadiotapFlags = *rti.this_arg;
1288 break;
1289
1290 }
1291 }
1292
1293 pu8Payload += u16HeaderLen + n80211HeaderLength;
1294
1295 if (prd.m_nRadiotapFlags & IEEE80211_RADIOTAP_F_FCS)
1296 bytes -= 4;
1297
1298 printf("RX: Rate: %2d.%dMbps, Freq: %d.%dGHz, "
1299 "Ant: %d, Flags: 0x%X\n",
1300 prd.m_nRate / 2, 5 * (prd.m_nRate & 1),
1301 prd.m_nChannel / 1000,
1302 prd.m_nChannel - ((prd.m_nChannel / 1000) * 1000),
1303 prd.m_nAntenna,
1304 prd.m_nRadiotapFlags);
1305
1306 Dump(pu8Payload, bytes);
1307
1308 do_tx:
1309
1310 // transmit
1311
1312 memcpy(u8aSendBuffer, u8aRadiotapHeader,
1313 sizeof (u8aRadiotapHeader));
1314 if (flagMarkWithFCS)
1315 pu8[OFFSET_FLAGS] |= IEEE80211_RADIOTAP_F_FCS;
1316 nRate = pu8[OFFSET_RATE] = u8aRatesToUse[nRateIndex++];
1317 if (nRateIndex >= sizeof (u8aRatesToUse))
1318 nRateIndex = 0;
1319 pu8 += sizeof (u8aRadiotapHeader);
1320
1321 memcpy(pu8, u8aIeeeHeader, sizeof (u8aIeeeHeader));
1322 pu8 += sizeof (u8aIeeeHeader);
1323
1324 pu8 += sprintf((char *)u8aSendBuffer,
1325 "Packetspammer %02d"
1326 "broadcast packet"
1327 "#%05d -- :-D --%s ----",
1328 nRate/2, nOrdinal++, szHostname);
1329 r = pcap_inject(ppcap, u8aSendBuffer, pu8 - u8aSendBuffer);
1330 if (r != (pu8-u8aSendBuffer)) {
1331 perror("Trouble injecting packet");
1332 return (1);
1333 }
1334 if (nDelay)
1335 usleep(nDelay);
1336 }
1337 1266
1267 // open the interface in pcap
1268
1269 szErrbuf[0] = '\0';
1270 ppcap = pcap_open_live(argv[optind], 800, 1, 20, szErrbuf);
1271 if (ppcap == NULL)
1272 {
1273 printf("Unable to open interface %s in pcap: %s\n",
1274 argv[optind], szErrbuf);
1275 return (1);
1276 }
1277
1278 //get mac from interface
1279
1280 /*int sock, j, k;
1281 char mac[32];
1282
1283 sock=socket(PF_INET, SOCK_STREAM, 0);
1284 if (-1==sock) {
1285 perror("can not open socket\n");
1286 return 1;
1287 }
1288
1289 if (-1==ioctl(sock, SIOCGIFHWADDR, &ifr)) {
1290 perror("ioctl(SIOCGIFHWADDR) ");
1291 return 1;
1292 }
1293 for (j=0, k=0; j<6; j++) {
1294 k+=snprintf(mac+k, sizeof(mac)-k-1, j ? ":%02X" : "%02X",
1295 (int)(unsigned int)(unsigned char)ifr.ifr_hwaddr.sa_data[j]);
1296 }
1297 mac[sizeof(mac)-1]='\0';
1298 */
1299
1300 //get header type
1301 nLinkEncap = pcap_datalink(ppcap);
1302 nCaptureHeaderLength = 0;
1303
1304 switch (nLinkEncap)
1305 {
1306
1307 case DLT_PRISM_HEADER:
1308 printf("DLT_PRISM_HEADER Encap\n");
1309 nCaptureHeaderLength = 0x40;
1310 n80211HeaderLength = 0x20; // ieee80211 comes after this
1311 szProgram = "radio[0x4a:4]==0x13223344";
1312 break;
1313
1314 case DLT_IEEE802_11_RADIO:
1315 printf("DLT_IEEE802_11_RADIO Encap\n");
1316 nCaptureHeaderLength = 0x40;
1317 n80211HeaderLength = 0x18; // ieee80211 comes after this
1318 szProgram = "ether[0x0a:4]==0x13223344";
1319 break;
1320
1321 default:
1322 printf("!!! unknown encapsulation on %s !\n", argv[1]);
1323 return (1);
1324
1325 }
1326
1327 if (pcap_compile(ppcap, &bpfprogram, szProgram, 1, 0) == -1)
1328 {
1329 puts(szProgram);
1330 puts(pcap_geterr(ppcap));
1331 return (1);
1332 }
1333 else
1334 {
1335 if (pcap_setfilter(ppcap, &bpfprogram) == -1)
1336 {
1337 puts(szProgram);
1338 puts(pcap_geterr(ppcap));
1339 }
1340 else
1341 {
1342 printf("RX Filter applied\n");
1343 }
1344 pcap_freecode(&bpfprogram);
1345 }
1346
1347 pcap_setnonblock(ppcap, 1, szErrbuf);
1348
1349 printf(" (delay between packets %dus)\n", nDelay);
1350
1351 memset(u8aSendBuffer, 0, sizeof(u8aSendBuffer));
1352
1353 while (!fBrokenSocket)
1354 {
1355 u8 * pu8 = u8aSendBuffer;
1356 struct pcap_pkthdr * ppcapPacketHeader = NULL;
1357 struct ieee80211_radiotap_iterator rti;
1358 PENUMBRA_RADIOTAP_DATA prd;
1359 //init of the values
1360 prd.m_nRate = 255;
1361 prd.m_nChannel = 255;
1362 prd.m_nAntenna = 255;
1363 prd.m_nRadiotapFlags = 255;
1364 u8 * pu8Payload = u8aSendBuffer;
1365 int n, nRate;
1366
1367 // receive
1368
1369 retval = pcap_next_ex(ppcap, &ppcapPacketHeader,
1370 (const u_char**) &pu8Payload);
1371
1372 if (retval < 0)
1373 {
1374 fBrokenSocket = 1;
1375 continue;
1376 }
1377
1378 if (retval != 1)
1379 goto do_tx;
1380
1381 u16HeaderLen = (pu8Payload[2] + (pu8Payload[3] << 8));
1382
1383 printf("rtap: ");
1384 Dump(pu8Payload, u16HeaderLen);
1385
1386 if (ppcapPacketHeader->len < (u16HeaderLen + n80211HeaderLength))
1387 continue;
1388
1389 bytes = ppcapPacketHeader->len - (u16HeaderLen + n80211HeaderLength);
1390 if (bytes < 0)
1391 continue;
1392
1393 if (ieee80211_radiotap_iterator_init(&rti,
1394 (struct ieee80211_radiotap_header *) pu8Payload, bytes) < 0)
1395 continue;
1396
1397 while ((n = ieee80211_radiotap_iterator_next(&rti)) == 0)
1398 {
1399
1400 switch (rti.this_arg_index)
1401 {
1402 case IEEE80211_RADIOTAP_RATE:
1403 prd.m_nRate = (*rti.this_arg);
1404 break;
1405
1406 case IEEE80211_RADIOTAP_CHANNEL:
1407 prd.m_nChannel = le16_to_cpu(*((u16 *)rti.this_arg));
1408 prd.m_nChannelFlags = le16_to_cpu(*((u16 *)(rti.this_arg + 2)));
1409 break;
1410
1411 case IEEE80211_RADIOTAP_ANTENNA:
1412 prd.m_nAntenna = (*rti.this_arg) + 1;
1413 break;
1414
1415 case IEEE80211_RADIOTAP_FLAGS:
1416 prd.m_nRadiotapFlags = *rti.this_arg;
1417 break;
1418
1419 }
1420 }
1421
1422 pu8Payload += u16HeaderLen + n80211HeaderLength;
1423
1424 if (prd.m_nRadiotapFlags & IEEE80211_RADIOTAP_F_FCS)
1425 bytes -= 4;
1426
1427 printf("RX: Rate: %2d.%dMbps, Freq: %d.%dGHz, "
1428 "Ant: %d, Flags: 0x%X\n", prd.m_nRate / 2, 5 * (prd.m_nRate & 1),
1429 prd.m_nChannel / 1000, prd.m_nChannel - ((prd.m_nChannel / 1000)
1430 * 1000), prd.m_nAntenna, prd.m_nRadiotapFlags);
1431
1432 Dump(pu8Payload, bytes);
1433
1434 do_tx:
1435
1436 // transmit
1437
1438 memcpy(u8aSendBuffer, u8aRadiotapHeader, sizeof(u8aRadiotapHeader));
1439 if (flagMarkWithFCS)
1440 pu8[OFFSET_FLAGS] |= IEEE80211_RADIOTAP_F_FCS;
1441 nRate = pu8[OFFSET_RATE] = u8aRatesToUse[nRateIndex++];
1442 if (nRateIndex >= sizeof(u8aRatesToUse))
1443 nRateIndex = 0;
1444 pu8 += sizeof(u8aRadiotapHeader);
1445
1446 memcpy(pu8, u8aIeeeHeader, sizeof(u8aIeeeHeader));
1447 pu8 += sizeof(u8aIeeeHeader);
1448
1449 pu8 += sprintf((char *) u8aSendBuffer, "Packetspammer %02d"
1450 "broadcast packet"
1451 "#%05d -- :-D --%s ----", nRate / 2, nOrdinal++, szHostname);
1452 r = pcap_inject(ppcap, u8aSendBuffer, pu8 - u8aSendBuffer);
1453 if (r != (pu8 - u8aSendBuffer))
1454 {
1455 perror("Trouble injecting packet");
1456 return (1);
1457 }
1458 if (nDelay)
1459 usleep(nDelay);
1460 }
1338 1461
1339#endif 1462#endif
1340 return (0); 1463 return (0);
1341} 1464}
1342 1465
diff --git a/src/transport/gnunet-transport-wlan-helper.h b/src/transport/gnunet-transport-wlan-helper.h
index e4d13275c..d4845af5a 100644
--- a/src/transport/gnunet-transport-wlan-helper.h
+++ b/src/transport/gnunet-transport-wlan-helper.h
@@ -27,6 +27,7 @@
27#ifndef gnunet_wlan_H 27#ifndef gnunet_wlan_H
28#define gnunet_wlan_H 28#define gnunet_wlan_H
29 29
30/*
30#include <stdio.h> 31#include <stdio.h>
31#include <stdlib.h> 32#include <stdlib.h>
32#include <errno.h> 33#include <errno.h>
@@ -35,16 +36,16 @@
35#include <utime.h> 36#include <utime.h>
36#include <unistd.h> 37#include <unistd.h>
37#include <getopt.h> 38#include <getopt.h>
38#include <pcap.h> 39#include <pcap.h>*/
39//#include <endian.h> 40//#include <endian.h>
40#include <pcap.h>
41
42 41
42/*
43typedef unsigned int u32; 43typedef unsigned int u32;
44typedef unsigned short u16; 44typedef unsigned short u16;
45typedef unsigned char u8; 45typedef unsigned char u8;
46typedef u32 __le32; 46typedef u32 __le32;
47 47*/
48/*
48#if __BYTE_ORDER == __LITTLE_ENDIAN 49#if __BYTE_ORDER == __LITTLE_ENDIAN
49#define le16_to_cpu(x) (x) 50#define le16_to_cpu(x) (x)
50#define le32_to_cpu(x) (x) 51#define le32_to_cpu(x) (x)
@@ -53,44 +54,22 @@ typedef u32 __le32;
53#define le32_to_cpu(x) \ 54#define le32_to_cpu(x) \
54((((x)&0xff)<<24)|(((x)&0xff00)<<8)|(((x)&0xff0000)>>8)|(((x)&0xff000000)>>24)) 55((((x)&0xff)<<24)|(((x)&0xff00)<<8)|(((x)&0xff0000)>>8)|(((x)&0xff000000)>>24))
55#endif 56#endif
57*/
56#define unlikely(x) (x) 58#define unlikely(x) (x)
57 59
60#define FIFO_FILE1 "/tmp/MYFIFOin"
61#define FIFO_FILE2 "/tmp/MYFIFOout"
62#define MAXLINE 4096
58 63
59#endif /* gnunet_wlan_H */ 64extern int closeprog;
60
61
62/* Radiotap header iteration
63 * implemented in net/wireless/radiotap.c
64 * docs in Documentation/networking/radiotap-headers.txt
65 */
66/**
67 * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args
68 * rtheader: pointer to the radiotap header we are walking through
69 * max_length: length of radiotap header in cpu byte ordering
70 * this_arg_index: IEEE80211_RADIOTAP_... index of current arg
71 * this_arg: pointer to current radiotap arg
72 * arg_index: internal next argument index
73 * arg: internal next argument pointer
74 * next_bitmap: internal pointer to next present u32
75 * bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present
76 */
77
78struct ieee80211_radiotap_iterator {
79 struct ieee80211_radiotap_header *rtheader;
80 int max_length;
81 int this_arg_index;
82 u8 *this_arg;
83 65
84 int arg_index; 66struct sendbuf
85 u8 *arg; 67{
86 __le32 *next_bitmap; 68 unsigned int pos;
87 u32 bitmap_shifter; 69 unsigned int size;
70 unsigned char buf[MAXLINE * 2];
88}; 71};
89 72
90extern int ieee80211_radiotap_iterator_init(
91 struct ieee80211_radiotap_iterator *iterator,
92 struct ieee80211_radiotap_header *radiotap_header,
93 int max_length);
94 73
95extern int ieee80211_radiotap_iterator_next( 74#endif /* gnunet_wlan_H */
96 struct ieee80211_radiotap_iterator *iterator); 75
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index b96414a71..245f0d795 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -34,6 +34,7 @@
34#include "plugin_transport_wlan.h" 34#include "plugin_transport_wlan.h"
35#include "gnunet_common.h" 35#include "gnunet_common.h"
36#include "gnunet_crypto_lib.h" 36#include "gnunet_crypto_lib.h"
37#include "wlan/ieee80211.h"
37 38
38#define PROTOCOL_PREFIX "wlan" 39#define PROTOCOL_PREFIX "wlan"
39 40
@@ -473,6 +474,11 @@ struct Session
473 474
474 int fragment_messages_in_count; 475 int fragment_messages_in_count;
475 476
477 //TODO DOXIGEN
478 uint8_t rate;
479 uint16_t tx_power;
480 uint8_t antenna;
481
476}; 482};
477 483
478/** 484/**
@@ -606,10 +612,11 @@ struct FragmentationAckHeader
606}; 612};
607 613
608int 614int
609getRadiotapHeader(struct RadiotapHeader * Header); 615getRadiotapHeader(struct Plugin * plugin, struct Session * session,
616 struct Radiotap_Send * Header);
610 617
611int 618int
612getWlanHeader(struct IeeeHeader * Header, const char * to_mac_addr, 619getWlanHeader(struct ieee80211_frame * Header, const char * to_mac_addr,
613 struct Plugin * plugin); 620 struct Plugin * plugin);
614 621
615static int 622static int
@@ -696,15 +703,15 @@ setBit(char *bitArray, unsigned int bitIdx)
696 * @param bitIdx which bit to unset 703 * @param bitIdx which bit to unset
697 */ 704 */
698/*static void 705/*static void
699clearBit(char *bitArray, unsigned int bitIdx) 706 clearBit(char *bitArray, unsigned int bitIdx)
700{ 707 {
701 size_t slot; 708 size_t slot;
702 unsigned int targetBit; 709 unsigned int targetBit;
703 710
704 slot = bitIdx / 8; 711 slot = bitIdx / 8;
705 targetBit = (1L << (bitIdx % 8)); 712 targetBit = (1L << (bitIdx % 8));
706 bitArray[slot] = bitArray[slot] & (~targetBit); 713 bitArray[slot] = bitArray[slot] & (~targetBit);
707}*/ 714 }*/
708 715
709/** 716/**
710 * Checks if a bit is active in the bitArray 717 * Checks if a bit is active in the bitArray
@@ -1012,12 +1019,14 @@ get_next_queue_Session(struct Plugin * plugin)
1012 session = sessionqueue->content; 1019 session = sessionqueue->content;
1013 1020
1014 pm = session->pending_message; 1021 pm = session->pending_message;
1015 if (pm == NULL){ 1022 if (pm == NULL)
1023 {
1016#if DEBUG_wlan 1024#if DEBUG_wlan
1017 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1025 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1018 "pending message is empty, should not happen. session %p\n", session); 1026 "pending message is empty, should not happen. session %p\n",
1027 session);
1019#endif 1028#endif
1020 } 1029 }
1021 GNUNET_assert(pm != NULL); 1030 GNUNET_assert(pm != NULL);
1022 1031
1023 //check for message timeout 1032 //check for message timeout
@@ -1180,12 +1189,13 @@ check_fragment_queue(struct Plugin * plugin)
1180 } 1189 }
1181 GNUNET_free(pm); 1190 GNUNET_free(pm);
1182 1191
1183 if (session->pending_message2 != NULL){ 1192 if (session->pending_message2 != NULL)
1184 session->pending_message = session->pending_message2; 1193 {
1185 session->pending_message2 = NULL; 1194 session->pending_message = session->pending_message2;
1186 //requeue session 1195 session->pending_message2 = NULL;
1187 queue_Session(plugin, session); 1196 //requeue session
1188 } 1197 queue_Session(plugin, session);
1198 }
1189 1199
1190 //check if timeout changed 1200 //check if timeout changed
1191 check_next_fragment_timeout(plugin); 1201 check_next_fragment_timeout(plugin);
@@ -1270,23 +1280,23 @@ send_hello_beacon(struct Plugin * plugin)
1270 uint16_t size = 0; 1280 uint16_t size = 0;
1271 ssize_t bytes; 1281 ssize_t bytes;
1272 struct GNUNET_MessageHeader * msgheader = NULL; 1282 struct GNUNET_MessageHeader * msgheader = NULL;
1273 struct IeeeHeader * ieeewlanheader = NULL; 1283 struct ieee80211_frame * ieeewlanheader = NULL;
1274 struct RadiotapHeader * radioHeader = NULL; 1284 struct Radiotap_Send * radioHeader = NULL;
1275 struct GNUNET_MessageHeader * msgheader2 = NULL; 1285 struct GNUNET_MessageHeader * msgheader2 = NULL;
1276 1286
1277 GNUNET_assert(sizeof(struct WlanHeader) + GNUNET_HELLO_size( 1287 GNUNET_assert(sizeof(struct WlanHeader) + GNUNET_HELLO_size(
1278 *(plugin->env->our_hello)) <= WLAN_MTU); 1288 *(plugin->env->our_hello)) <= WLAN_MTU);
1279 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct RadiotapHeader) 1289 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send)
1280 + sizeof(struct IeeeHeader) + sizeof(struct GNUNET_MessageHeader) 1290 + sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader)
1281 + GNUNET_HELLO_size(*(plugin->env->our_hello)); 1291 + GNUNET_HELLO_size(*(plugin->env->our_hello));
1282 1292
1283 msgheader = GNUNET_malloc(size); 1293 msgheader = GNUNET_malloc(size);
1284 msgheader->size = htons(size); 1294 msgheader->size = htons(size);
1285 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 1295 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1286 1296
1287 radioHeader = (struct RadiotapHeader*) &msgheader[1]; 1297 radioHeader = (struct Radiotap_Send*) &msgheader[1];
1288 getRadiotapHeader(radioHeader); 1298 getRadiotapHeader(plugin, NULL, radioHeader);
1289 ieeewlanheader = (struct IeeeHeader*) &radioHeader[1]; 1299 ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1];
1290 getWlanHeader(ieeewlanheader, bc_all_mac, plugin); 1300 getWlanHeader(ieeewlanheader, bc_all_mac, plugin);
1291 1301
1292 msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1]; 1302 msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1];
@@ -1321,8 +1331,8 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
1321 uint16_t size = 0; 1331 uint16_t size = 0;
1322 ssize_t bytes; 1332 ssize_t bytes;
1323 struct GNUNET_MessageHeader * msgheader = NULL; 1333 struct GNUNET_MessageHeader * msgheader = NULL;
1324 struct IeeeHeader * ieeewlanheader = NULL; 1334 struct ieee80211_frame * ieeewlanheader = NULL;
1325 struct RadiotapHeader * radioHeader = NULL; 1335 struct Radiotap_Send * radioHeader = NULL;
1326 struct FragmentationAckHeader * msgheader2 = NULL; 1336 struct FragmentationAckHeader * msgheader2 = NULL;
1327 1337
1328 GNUNET_assert(sizeof(struct FragmentationAckHeader) <= WLAN_MTU); 1338 GNUNET_assert(sizeof(struct FragmentationAckHeader) <= WLAN_MTU);
@@ -1333,15 +1343,15 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
1333 ack->message_id, ack->fragments_field); 1343 ack->message_id, ack->fragments_field);
1334#endif 1344#endif
1335 1345
1336 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct RadiotapHeader) 1346 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send)
1337 + sizeof(struct IeeeHeader) + sizeof(struct FragmentationAckHeader); 1347 + sizeof(struct ieee80211_frame) + sizeof(struct FragmentationAckHeader);
1338 msgheader = GNUNET_malloc(size); 1348 msgheader = GNUNET_malloc(size);
1339 msgheader->size = htons(size); 1349 msgheader->size = htons(size);
1340 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 1350 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1341 1351
1342 radioHeader = (struct RadiotapHeader*) &msgheader[1]; 1352 radioHeader = (struct Radiotap_Send*) &msgheader[1];
1343 getRadiotapHeader(radioHeader); 1353 getRadiotapHeader(plugin, ack->session, radioHeader);
1344 ieeewlanheader = (struct IeeeHeader*) &radioHeader[1]; 1354 ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1];
1345 getWlanHeader(ieeewlanheader, ack->session->addr, plugin); 1355 getWlanHeader(ieeewlanheader, ack->session->addr, plugin);
1346 1356
1347 msgheader2 = (struct FragmentationAckHeader*) &ieeewlanheader[1]; 1357 msgheader2 = (struct FragmentationAckHeader*) &ieeewlanheader[1];
@@ -1383,8 +1393,8 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1383 1393
1384 struct Session * session = NULL; 1394 struct Session * session = NULL;
1385 struct FragmentMessage * fm = NULL; 1395 struct FragmentMessage * fm = NULL;
1386 struct IeeeHeader * ieeewlanheader = NULL; 1396 struct ieee80211_frame * ieeewlanheader = NULL;
1387 struct RadiotapHeader * radioHeader = NULL; 1397 struct Radiotap_Send * radioHeader = NULL;
1388 struct GNUNET_MessageHeader * msgheader = NULL; 1398 struct GNUNET_MessageHeader * msgheader = NULL;
1389 1399
1390 struct FragmentationHeader fragheader; 1400 struct FragmentationHeader fragheader;
@@ -1486,16 +1496,16 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1486 }*/ 1496 }*/
1487 1497
1488 size += copysize; 1498 size += copysize;
1489 size += sizeof(struct RadiotapHeader) + sizeof(struct IeeeHeader) 1499 size += sizeof(struct Radiotap_Send) + sizeof(struct ieee80211_frame)
1490 + sizeof(struct GNUNET_MessageHeader); 1500 + sizeof(struct GNUNET_MessageHeader);
1491 msgheader = GNUNET_malloc(size); 1501 msgheader = GNUNET_malloc(size);
1492 msgheader->size = htons(size); 1502 msgheader->size = htons(size);
1493 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 1503 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1494 1504
1495 radioHeader = (struct RadiotapHeader*) &msgheader[1]; 1505 radioHeader = (struct Radiotap_Send*) &msgheader[1];
1496 getRadiotapHeader(radioHeader); 1506 getRadiotapHeader(plugin, session, radioHeader);
1497 1507
1498 ieeewlanheader = (struct IeeeHeader *) &radioHeader[1]; 1508 ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1];
1499 getWlanHeader(ieeewlanheader, fm->session->addr, plugin); 1509 getWlanHeader(ieeewlanheader, fm->session->addr, plugin);
1500 1510
1501 //could be faster if content is just send and not copyed before 1511 //could be faster if content is just send and not copyed before
@@ -1607,8 +1617,13 @@ finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1607} 1617}
1608 1618
1609int 1619int
1610getRadiotapHeader(struct RadiotapHeader * Header) 1620getRadiotapHeader(struct Plugin * plugin, struct Session * session,
1621 struct Radiotap_Send * header)
1611{ 1622{
1623
1624 header->rate = session->rate;
1625 header->tx_power = session->tx_power;
1626 header->antenna = session->antenna;
1612 return GNUNET_YES; 1627 return GNUNET_YES;
1613} 1628}
1614; 1629;
@@ -1622,12 +1637,12 @@ getRadiotapHeader(struct RadiotapHeader * Header)
1622 */ 1637 */
1623 1638
1624int 1639int
1625getWlanHeader(struct IeeeHeader * Header, const char * const to_mac_addr, 1640getWlanHeader(struct ieee80211_frame * Header, const char * const to_mac_addr,
1626 struct Plugin * plugin) 1641 struct Plugin * plugin)
1627{ 1642{
1628 memcpy(&Header->mac3, mac_bssid, sizeof(mac_bssid)); 1643 memcpy(&Header->i_addr3, mac_bssid, sizeof(mac_bssid));
1629 memcpy(&Header->mac2, plugin->mac_address.mac, sizeof(plugin->mac_address)); 1644 memcpy(&Header->i_addr2, plugin->mac_address.mac, sizeof(plugin->mac_address));
1630 memcpy(&Header->mac1, to_mac_addr, sizeof(plugin->mac_address)); 1645 memcpy(&Header->i_addr1, to_mac_addr, sizeof(plugin->mac_address));
1631 return GNUNET_YES; 1646 return GNUNET_YES;
1632} 1647}
1633 1648
@@ -1722,7 +1737,7 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1722 //if (session->target != NULL){ 1737 //if (session->target != NULL){
1723 // GNUNET_assert(session->target == *target); 1738 // GNUNET_assert(session->target == *target);
1724 //} else { 1739 //} else {
1725 session->target = *target; 1740 session->target = *target;
1726 //} 1741 //}
1727 1742
1728 1743
@@ -1781,7 +1796,6 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1781 newmsg->message_size); 1796 newmsg->message_size);
1782#endif 1797#endif
1783 1798
1784
1785 //queue session 1799 //queue session
1786 queue_Session(plugin, session); 1800 queue_Session(plugin, session);
1787 1801
@@ -2494,7 +2508,7 @@ insert_fragment_in_in_message_queue(struct Plugin * plugin,
2494 rec_queue->num = ntohs(fh->fragment_off_or_num); 2508 rec_queue->num = ntohs(fh->fragment_off_or_num);
2495 rec_queue->msg = (char*) &(rec_queue[1]); 2509 rec_queue->msg = (char*) &(rec_queue[1]);
2496 //copy msg to buffer 2510 //copy msg to buffer
2497 memcpy((char *)rec_queue->msg, tempmsg, rec_queue->size); 2511 memcpy((char *) rec_queue->msg, tempmsg, rec_queue->size);
2498 insert_fragment_in_queue(rec_message, rec_queue); 2512 insert_fragment_in_queue(rec_message, rec_queue);
2499 //save bitfield 2513 //save bitfield
2500 retval = rec_message->received_fragments; 2514 retval = rec_message->received_fragments;
@@ -2679,10 +2693,9 @@ wlan_data_helper(void *cls, struct Session_light * session_light,
2679} 2693}
2680 2694
2681char * 2695char *
2682macprinter(struct MacAddress macx) 2696macprinter(u_int8_t * mac)
2683{ 2697{
2684 static char macstr[20]; 2698 static char macstr[20];
2685 char * mac = macx.mac;
2686 sprintf(macstr, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", mac[0], mac[1], mac[2], 2699 sprintf(macstr, "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", mac[0], mac[1], mac[2],
2687 mac[3], mac[4], mac[5]); 2700 mac[3], mac[4], mac[5]);
2688 return macstr; 2701 return macstr;
@@ -2701,7 +2714,7 @@ wlan_process_helper(void *cls, void *client,
2701 const struct GNUNET_MessageHeader *hdr) 2714 const struct GNUNET_MessageHeader *hdr)
2702{ 2715{
2703 struct Plugin *plugin = cls; 2716 struct Plugin *plugin = cls;
2704 struct IeeeHeader * wlanIeeeHeader = NULL; 2717 struct ieee80211_frame * wlanIeeeHeader = NULL;
2705 struct Session_light * session_light = NULL; 2718 struct Session_light * session_light = NULL;
2706 const struct GNUNET_MessageHeader * temp_hdr = NULL; 2719 const struct GNUNET_MessageHeader * temp_hdr = NULL;
2707 2720
@@ -2718,30 +2731,30 @@ wlan_process_helper(void *cls, void *client,
2718#endif 2731#endif
2719 2732
2720 //call wlan_process_helper with the message inside, later with wlan: analyze signal 2733 //call wlan_process_helper with the message inside, later with wlan: analyze signal
2721 GNUNET_assert(ntohs(hdr->size) >= sizeof(struct IeeeHeader) + sizeof(struct GNUNET_MessageHeader)); 2734 GNUNET_assert(ntohs(hdr->size) >= sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader));
2722 wlanIeeeHeader = (struct IeeeHeader *) &hdr[1]; 2735 wlanIeeeHeader = (struct ieee80211_frame *) &hdr[1];
2723 2736
2724 //process only if it is an broadcast or for this computer both with the gnunet bssid 2737 //process only if it is an broadcast or for this computer both with the gnunet bssid
2725 2738
2726 //check for bssid 2739 //check for bssid
2727 if (memcmp(&(wlanIeeeHeader->mac3), mac_bssid, sizeof(struct MacAddress)) 2740 if (memcmp(&(wlanIeeeHeader->i_addr3), mac_bssid,
2728 == 0) 2741 sizeof(struct MacAddress)) == 0)
2729 { 2742 {
2730 //check for broadcast or mac 2743 //check for broadcast or mac
2731 if (memcmp(&(wlanIeeeHeader->mac1), bc_all_mac, 2744 if (memcmp(&(wlanIeeeHeader->i_addr1), bc_all_mac,
2732 sizeof(struct MacAddress) == 0) || memcmp( 2745 sizeof(struct MacAddress) == 0) || memcmp(
2733 &(wlanIeeeHeader->mac1), &(plugin->mac_address), 2746 &(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
2734 sizeof(struct MacAddress)) == 0) 2747 sizeof(struct MacAddress)) == 0)
2735 { 2748 {
2736 2749
2737 // process the inner data 2750 // process the inner data
2738 2751
2739 2752
2740 datasize = ntohs(hdr->size) - sizeof(struct IeeeHeader) 2753 datasize = ntohs(hdr->size) - sizeof(struct ieee80211_frame)
2741 - sizeof(struct GNUNET_MessageHeader); 2754 - sizeof(struct GNUNET_MessageHeader);
2742 2755
2743 session_light = GNUNET_malloc(sizeof(struct Session_light)); 2756 session_light = GNUNET_malloc(sizeof(struct Session_light));
2744 memcpy(session_light->addr, &(wlanIeeeHeader->mac2), 2757 memcpy(session_light->addr, &(wlanIeeeHeader->i_addr2),
2745 sizeof(struct MacAddress)); 2758 sizeof(struct MacAddress));
2746 //session_light->session = search_session(plugin,session_light->addr); 2759 //session_light->session = search_session(plugin,session_light->addr);
2747 2760
@@ -2765,7 +2778,7 @@ wlan_process_helper(void *cls, void *client,
2765#if DEBUG_wlan 2778#if DEBUG_wlan
2766 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2779 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2767 "Func wlan_process_helper got wrong MAC: %s\n", macprinter( 2780 "Func wlan_process_helper got wrong MAC: %s\n", macprinter(
2768 wlanIeeeHeader->mac1)); 2781 wlanIeeeHeader->i_addr1));
2769#endif 2782#endif
2770 } 2783 }
2771 } 2784 }
@@ -2774,7 +2787,7 @@ wlan_process_helper(void *cls, void *client,
2774#if DEBUG_wlan 2787#if DEBUG_wlan
2775 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2788 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2776 "Func wlan_process_helper got wrong BSSID: %s\n", macprinter( 2789 "Func wlan_process_helper got wrong BSSID: %s\n", macprinter(
2777 wlanIeeeHeader->mac2)); 2790 wlanIeeeHeader->i_addr2));
2778#endif 2791#endif
2779 } 2792 }
2780 2793
@@ -2807,7 +2820,7 @@ wlan_process_helper(void *cls, void *client,
2807 else 2820 else
2808 { 2821 {
2809 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Wrong wlan mac address %s\n", 2822 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Wrong wlan mac address %s\n",
2810 macprinter(plugin->mac_address)); 2823 macprinter(plugin->mac_address.mac));
2811 } 2824 }
2812 2825
2813 } 2826 }
diff --git a/src/transport/plugin_transport_wlan.h b/src/transport/plugin_transport_wlan.h
index ac214a07c..2f811809f 100644
--- a/src/transport/plugin_transport_wlan.h
+++ b/src/transport/plugin_transport_wlan.h
@@ -34,7 +34,7 @@
34 34
35struct MacAddress 35struct MacAddress
36{ 36{
37 char mac[6]; 37 u_int8_t mac[6];
38}; 38};
39 39
40struct Wlan_Helper_Control_Message 40struct Wlan_Helper_Control_Message
@@ -67,43 +67,6 @@ static const char mac_bssid[] =
67static const char bc_all_mac[] = 67static const char bc_all_mac[] =
68 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 68 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
69 69
70/**
71 * Wlan header
72 */
73
74struct IeeeHeader
75{
76 /**
77 * Wlan flags
78 */
79 uint16_t frame_control GNUNET_PACKED;
80
81 /**
82 * Duration / ID
83 */
84 uint16_t duration_id GNUNET_PACKED;
85
86 /**
87 * first mac byte 1
88 */
89 struct MacAddress mac1;
90
91
92 /**
93 * second mac
94 */
95 struct MacAddress mac2;
96
97 /**
98 * third mac
99 */
100 struct MacAddress mac3;
101
102 /**
103 * Wlan Sequence Control
104 */
105 uint16_t sequence_control GNUNET_PACKED;
106};
107 70
108/* this is the template radiotap header we send packets out with */ 71/* this is the template radiotap header we send packets out with */
109 72
@@ -121,6 +84,36 @@ static const uint8_t u8aRadiotapHeader[] =
121 0x01, // <-- antenna 84 0x01, // <-- antenna
122}; 85};
123 86
87struct Radiotap_Send
88{
89 /**
90 * wlan send rate
91 */
92 uint8_t rate;
93
94 /**
95 * antenna
96 */
97 uint8_t antenna;
98
99 /**
100 * Transmit power expressed as unitless distance from max power set at factory calibration.
101 * 0 is max power. Monotonically nondecreasing with lower power levels.
102 */
103
104 uint16_t tx_power;
105};
106
107struct rx_info {
108 uint64_t ri_mactime;
109 int32_t ri_power;
110 int32_t ri_noise;
111 uint32_t ri_channel;
112 uint32_t ri_freq;
113 uint32_t ri_rate;
114 uint32_t ri_antenna;
115};
116
124/** 117/**
125 * Radiotap Header 118 * Radiotap Header
126 */ 119 */
diff --git a/src/transport/wlan/byteorder.h b/src/transport/wlan/byteorder.h
new file mode 100644
index 000000000..75dc5e5d5
--- /dev/null
+++ b/src/transport/wlan/byteorder.h
@@ -0,0 +1,397 @@
1/*
2 * Compatibility header
3 *
4 * Copyright (C) 2009 Thomas d'Otreppe
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef _AIRCRACK_NG_BYTEORDER_H_
22#define _AIRCRACK_NG_BYTEORDER_H_
23
24 #define ___my_swab16(x) \
25 ((u_int16_t)( \
26 (((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | \
27 (((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8) ))
28 #define ___my_swab32(x) \
29 ((u_int32_t)( \
30 (((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | \
31 (((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) << 8) | \
32 (((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >> 8) | \
33 (((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24) ))
34 #define ___my_swab64(x) \
35 ((u_int64_t)( \
36 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000000000ffULL) << 56) | \
37 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000000000ff00ULL) << 40) | \
38 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000000000ff0000ULL) << 24) | \
39 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000ff000000ULL) << 8) | \
40 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000ff00000000ULL) >> 8) | \
41 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000ff0000000000ULL) >> 24) | \
42 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \
43 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) ))
44
45
46 /*
47 * Linux
48 */
49 #if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux__)
50 #include <endian.h>
51 #include <unistd.h>
52 #include <stdint.h>
53
54 #ifndef __int8_t_defined
55 typedef uint64_t u_int64_t;
56 typedef uint32_t u_int32_t;
57 typedef uint16_t u_int16_t;
58 typedef uint8_t u_int8_t;
59 #endif
60
61 #endif
62
63 /*
64 * Cygwin
65 */
66 #if defined(__CYGWIN32__)
67 #include <asm/byteorder.h>
68 #include <unistd.h>
69
70 #define __be64_to_cpu(x) ___my_swab64(x)
71 #define __be32_to_cpu(x) ___my_swab32(x)
72 #define __be16_to_cpu(x) ___my_swab16(x)
73 #define __cpu_to_be64(x) ___my_swab64(x)
74 #define __cpu_to_be32(x) ___my_swab32(x)
75 #define __cpu_to_be16(x) ___my_swab16(x)
76 #define __le64_to_cpu(x) (x)
77 #define __le32_to_cpu(x) (x)
78 #define __le16_to_cpu(x) (x)
79 #define __cpu_to_le64(x) (x)
80 #define __cpu_to_le32(x) (x)
81 #define __cpu_to_le16(x) (x)
82
83 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
84
85 #endif
86
87 /*
88 * Windows (DDK)
89 */
90 #if defined(__WIN__)
91
92 #include <io.h>
93
94 #define __be64_to_cpu(x) ___my_swab64(x)
95 #define __be32_to_cpu(x) ___my_swab32(x)
96 #define __be16_to_cpu(x) ___my_swab16(x)
97 #define __cpu_to_be64(x) ___my_swab64(x)
98 #define __cpu_to_be32(x) ___my_swab32(x)
99 #define __cpu_to_be16(x) ___my_swab16(x)
100 #define __le64_to_cpu(x) (x)
101 #define __le32_to_cpu(x) (x)
102 #define __le16_to_cpu(x) (x)
103 #define __cpu_to_le64(x) (x)
104 #define __cpu_to_le32(x) (x)
105 #define __cpu_to_le16(x) (x)
106
107 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
108
109 #endif
110
111 /*
112 * MAC (Darwin)
113 */
114 #if defined(__APPLE_CC__)
115 #if defined(__x86_64__) && defined(__APPLE__)
116
117 #include <libkern/OSByteOrder.h>
118
119 #define __swab64(x) (unsigned long long) OSSwapInt64((uint64_t)x)
120 #define __swab32(x) (unsigned long) OSSwapInt32((uint32_t)x)
121 #define __swab16(x) (unsigned short) OSSwapInt16((uint16_t)x)
122 #define __be64_to_cpu(x) (unsigned long long) OSSwapBigToHostInt64((uint64_t)x)
123 #define __be32_to_cpu(x) (unsigned long) OSSwapBigToHostInt32((uint32_t)x)
124 #define __be16_to_cpu(x) (unsigned short) OSSwapBigToHostInt16((uint16_t)x)
125 #define __le64_to_cpu(x) (unsigned long long) OSSwapLittleToHostInt64((uint64_t)x)
126 #define __le32_to_cpu(x) (unsigned long) OSSwapLittleToHostInt32((uint32_t)x)
127 #define __le16_to_cpu(x) (unsigned short) OSSwapLittleToHostInt16((uint16_t)x)
128 #define __cpu_to_be64(x) (unsigned long long) OSSwapHostToBigInt64((uint64_t)x)
129 #define __cpu_to_be32(x) (unsigned long) OSSwapHostToBigInt32((uint32_t)x)
130 #define __cpu_to_be16(x) (unsigned short) OSSwapHostToBigInt16((uint16_t)x)
131 #define __cpu_to_le64(x) (unsigned long long) OSSwapHostToLittleInt64((uint64_t)x)
132 #define __cpu_to_le32(x) (unsigned long) OSSwapHostToLittleInt32((uint32_t)x)
133 #define __cpu_to_le16(x) (unsigned short) OSSwapHostToLittleInt16((uint16_t)x)
134
135 #else
136
137 #include <architecture/byte_order.h>
138
139 #define __swab64(x) NXSwapLongLong(x)
140 #define __swab32(x) NXSwapLong(x)
141 #define __swab16(x) NXSwapShort(x)
142 #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)
143 #define __be32_to_cpu(x) NXSwapBigLongToHost(x)
144 #define __be16_to_cpu(x) NXSwapBigShortToHost(x)
145 #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)
146 #define __le32_to_cpu(x) NXSwapLittleLongToHost(x)
147 #define __le16_to_cpu(x) NXSwapLittleShortToHost(x)
148 #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)
149 #define __cpu_to_be32(x) NXSwapHostLongToBig(x)
150 #define __cpu_to_be16(x) NXSwapHostShortToBig(x)
151 #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)
152 #define __cpu_to_le32(x) NXSwapHostLongToLittle(x)
153 #define __cpu_to_le16(x) NXSwapHostShortToLittle(x)
154
155 #endif
156
157 #define __LITTLE_ENDIAN 1234
158 #define __BIG_ENDIAN 4321
159 #define __PDP_ENDIAN 3412
160 #define __BYTE_ORDER __BIG_ENDIAN
161
162 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
163
164 #endif
165
166 /*
167 * Solaris
168 * -------
169 */
170 #if defined(__sparc__)
171 #include <sys/byteorder.h>
172 #include <sys/types.h>
173 #include <unistd.h>
174
175 #define __be64_to_cpu(x) (x)
176 #define __be32_to_cpu(x) (x)
177 #define __be16_to_cpu(x) (x)
178 #define __cpu_to_be64(x) (x)
179 #define __cpu_to_be32(x) (x)
180 #define __cpu_to_be16(x) (x)
181 #define __le64_to_cpu(x) ___my_swab64(x)
182 #define __le32_to_cpu(x) ___my_swab32(x)
183 #define __le16_to_cpu(x) ___my_swab16(x)
184 #define __cpu_to_le64(x) ___my_swab64(x)
185 #define __cpu_to_le32(x) ___my_swab32(x)
186 #define __cpu_to_le16(x) ___my_swab16(x)
187
188 typedef uint64_t u_int64_t;
189 typedef uint32_t u_int32_t;
190 typedef uint16_t u_int16_t;
191 typedef uint8_t u_int8_t;
192
193 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
194
195 #endif
196
197 /*
198 * Custom stuff
199 */
200 #if defined(__MACH__) && !defined(__APPLE_CC__)
201 #include <libkern/OSByteOrder.h>
202 #define __cpu_to_be64(x) = OSSwapHostToBigInt64(x)
203 #define __cpu_to_be32(x) = OSSwapHostToBigInt32(x)
204
205 #define AIRCRACK_NG_BYTE_ORDER_DEFINED
206
207 #endif
208
209
210 // FreeBSD
211 #ifdef __FreeBSD__
212 #include <machine/endian.h>
213 #endif
214
215 // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...?
216
217
218 // XXX: Mac: Check http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h
219 // http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html
220 // Write to apple to ask what should be used.
221
222 #if defined(LITTLE_ENDIAN)
223 #define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN
224 #elif defined(__LITTLE_ENDIAN)
225 #define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN
226 #elif defined(_LITTLE_ENDIAN)
227 #define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN
228 #endif
229
230 #if defined(BIG_ENDIAN)
231 #define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN
232 #elif defined(__BIG_ENDIAN)
233 #define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN
234 #elif defined(_BIG_ENDIAN)
235 #define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN
236 #endif
237
238 #if !defined(AIRCRACK_NG_LITTLE_ENDIAN) && !defined(AIRCRACK_NG_BIG_ENDIAN)
239 #error Impossible to determine endianness (Little or Big endian), please contact the author.
240 #endif
241
242 #if defined(BYTE_ORDER)
243 #if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
244 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
245 #elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
246 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
247 #endif
248 #elif defined(__BYTE_ORDER)
249 #if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
250 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
251 #elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
252 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
253 #endif
254 #elif defined(_BYTE_ORDER)
255 #if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
256 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
257 #elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
258 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
259 #endif
260 #endif
261
262 #ifndef AIRCRACK_NG_BYTE_ORDER
263 #error Impossible to determine endianness (Little or Big endian), please contact the author.
264 #endif
265
266 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
267
268 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
269 #define __be64_to_cpu(x) ___my_swab64(x)
270 #define __be32_to_cpu(x) ___my_swab32(x)
271 #define __be16_to_cpu(x) ___my_swab16(x)
272 #define __cpu_to_be64(x) ___my_swab64(x)
273 #define __cpu_to_be32(x) ___my_swab32(x)
274 #define __cpu_to_be16(x) ___my_swab16(x)
275 #define __le64_to_cpu(x) (x)
276 #define __le32_to_cpu(x) (x)
277 #define __le16_to_cpu(x) (x)
278 #define __cpu_to_le64(x) (x)
279 #define __cpu_to_le32(x) (x)
280 #define __cpu_to_le16(x) (x)
281 #endif
282
283 #ifndef htobe16
284 #define htobe16 ___my_swab16
285 #endif
286 #ifndef htobe32
287 #define htobe32 ___my_swab32
288 #endif
289 #ifndef betoh16
290 #define betoh16 ___my_swab16
291 #endif
292 #ifndef betoh32
293 #define betoh32 ___my_swab32
294 #endif
295
296 #ifndef htole16
297 #define htole16(x) (x)
298 #endif
299 #ifndef htole32
300 #define htole32(x) (x)
301 #endif
302 #ifndef letoh16
303 #define letoh16(x) (x)
304 #endif
305 #ifndef letoh32
306 #define letoh32(x) (x)
307 #endif
308
309 #endif
310
311 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
312
313 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
314 #define __be64_to_cpu(x) (x)
315 #define __be32_to_cpu(x) (x)
316 #define __be16_to_cpu(x) (x)
317 #define __cpu_to_be64(x) (x)
318 #define __cpu_to_be32(x) (x)
319 #define __cpu_to_be16(x) (x)
320 #define __le64_to_cpu(x) ___my_swab64(x)
321 #define __le32_to_cpu(x) ___my_swab32(x)
322 #define __le16_to_cpu(x) ___my_swab16(x)
323 #define __cpu_to_le64(x) ___my_swab64(x)
324 #define __cpu_to_le32(x) ___my_swab32(x)
325 #define __cpu_to_le16(x) ___my_swab16(x)
326 #endif
327
328 #ifndef htobe16
329 #define htobe16(x) (x)
330 #endif
331 #ifndef htobe32
332 #define htobe32(x) (x)
333 #endif
334 #ifndef betoh16
335 #define betoh16(x) (x)
336 #endif
337 #ifndef betoh32
338 #define betoh32(x) (x)
339 #endif
340
341 #ifndef htole16
342 #define htole16 ___my_swab16
343 #endif
344 #ifndef htole32
345 #define htole32 ___my_swab32
346 #endif
347 #ifndef letoh16
348 #define letoh16 ___my_swab16
349 #endif
350 #ifndef letoh32
351 #define letoh32 ___my_swab32
352 #endif
353
354 #endif
355
356 // Common defines
357 #define cpu_to_le64 __cpu_to_le64
358 #define le64_to_cpu __le64_to_cpu
359 #define cpu_to_le32 __cpu_to_le32
360 #define le32_to_cpu __le32_to_cpu
361 #define cpu_to_le16 __cpu_to_le16
362 #define le16_to_cpu __le16_to_cpu
363 #define cpu_to_be64 __cpu_to_be64
364 #define be64_to_cpu __be64_to_cpu
365 #define cpu_to_be32 __cpu_to_be32
366 #define be32_to_cpu __be32_to_cpu
367 #define cpu_to_be16 __cpu_to_be16
368 #define be16_to_cpu __be16_to_cpu
369
370 #ifndef le16toh
371 #define le16toh le16_to_cpu
372 #endif
373 #ifndef be16toh
374 #define be16toh be16_to_cpu
375 #endif
376 #ifndef le32toh
377 #define le32toh le32_to_cpu
378 #endif
379 #ifndef be32toh
380 #define be32toh be32_to_cpu
381 #endif
382
383
384 #ifndef htons
385 #define htons be16_to_cpu
386 #endif
387 #ifndef htonl
388 #define htonl cpu_to_be16
389 #endif
390 #ifndef ntohs
391 #define ntohs cpu_to_be16
392 #endif
393 #ifndef ntohl
394 #define ntohl cpu_to_be32
395 #endif
396
397#endif
diff --git a/src/transport/wlan/crctable_osdep.h b/src/transport/wlan/crctable_osdep.h
new file mode 100644
index 000000000..4f14d245b
--- /dev/null
+++ b/src/transport/wlan/crctable_osdep.h
@@ -0,0 +1,40 @@
1#ifndef _CRCTABLE_OSDEP_H
2#define _CRCTABLE_OSDEP_H
3
4const unsigned long int crc_tbl_osdep[256] =
5{
6 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
7 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
8 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
9 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
10 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
11 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
12 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
13 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
14 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
15 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
16 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
17 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
18 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
19 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
20 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
21 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
22 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
23 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
24 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
25 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
26 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
27 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
28 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
29 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
30 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
31 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
32 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
33 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
34 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
35 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
36 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
37 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
38};
39
40#endif /* crctable_osdep.h */
diff --git a/src/transport/wlan/helper_common.c b/src/transport/wlan/helper_common.c
new file mode 100644
index 000000000..5171403c8
--- /dev/null
+++ b/src/transport/wlan/helper_common.c
@@ -0,0 +1,110 @@
1/*
2 * helper_common.c
3 *
4 * Created on: 28.03.2011
5 * Author: David Brodski
6 */
7
8#include <sys/socket.h>
9#include <stdint.h>
10#include <stdio.h>
11#include <stdlib.h>
12#include <errno.h>
13#include <resolv.h>
14#include <string.h>
15#include <utime.h>
16#include <unistd.h>
17#include <getopt.h>
18
19//#include "platform.h"
20#include "gnunet_constants.h"
21#include "gnunet_os_lib.h"
22#include "gnunet_transport_plugin.h"
23#include "transport.h"
24#include "gnunet_util_lib.h"
25#include "plugin_transport_wlan.h"
26#include "gnunet_common.h"
27#include "gnunet_transport_plugin.h"
28//#include "gnunet_util_lib.h"
29
30/**
31 * function to create GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL message for plugin
32 * @param buffer pointer to buffer for the message
33 * @param mac pointer to the mac address
34 * @return number of bytes written
35 */
36
37int
38send_mac_to_plugin(char * buffer, uint8_t * mac)
39{
40
41 struct Wlan_Helper_Control_Message macmsg;
42
43 memcpy(macmsg.mac.mac, mac, sizeof(struct MacAddress));
44 macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message));
45 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
46
47 memcpy(buffer, &macmsg, sizeof(struct Wlan_Helper_Control_Message));
48 return sizeof(struct Wlan_Helper_Control_Message);
49}
50
51/*
52 * Copyright (c) 2008, Thomas d'Otreppe
53 *
54 * Common OSdep stuff
55 *
56 * This program is free software; you can redistribute it and/or modify
57 * it under the terms of the GNU General Public License as published by
58 * the Free Software Foundation; either version 2 of the License, or
59 * (at your option) any later version.
60 *
61 * This program is distributed in the hope that it will be useful,
62 * but WITHOUT ANY WARRANTY; without even the implied warranty of
63 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64 * GNU General Public License for more details.
65 *
66 * You should have received a copy of the GNU General Public License
67 * along with this program; if not, write to the Free Software
68 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
69 */
70
71/**
72 * Return the frequency in Mhz from a channel number
73 */
74int getFrequencyFromChannel(int channel)
75{
76 static int frequencies[] = {
77 -1, // No channel 0
78 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
79 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // Nothing from channel 15 to 34 (exclusive)
80 5170, 5175, 5180, 5185, 5190, 5195, 5200, 5205, 5210, 5215, 5220, 5225, 5230, 5235, 5240, 5245,
81 5250, 5255, 5260, 5265, 5270, 5275, 5280, 5285, 5290, 5295, 5300, 5305, 5310, 5315, 5320, 5325,
82 5330, 5335, 5340, 5345, 5350, 5355, 5360, 5365, 5370, 5375, 5380, 5385, 5390, 5395, 5400, 5405,
83 5410, 5415, 5420, 5425, 5430, 5435, 5440, 5445, 5450, 5455, 5460, 5465, 5470, 5475, 5480, 5485,
84 5490, 5495, 5500, 5505, 5510, 5515, 5520, 5525, 5530, 5535, 5540, 5545, 5550, 5555, 5560, 5565,
85 5570, 5575, 5580, 5585, 5590, 5595, 5600, 5605, 5610, 5615, 5620, 5625, 5630, 5635, 5640, 5645,
86 5650, 5655, 5660, 5665, 5670, 5675, 5680, 5685, 5690, 5695, 5700, 5705, 5710, 5715, 5720, 5725,
87 5730, 5735, 5740, 5745, 5750, 5755, 5760, 5765, 5770, 5775, 5780, 5785, 5790, 5795, 5800, 5805,
88 5810, 5815, 5820, 5825, 5830, 5835, 5840, 5845, 5850, 5855, 5860, 5865, 5870, 5875, 5880, 5885,
89 5890, 5895, 5900, 5905, 5910, 5915, 5920, 5925, 5930, 5935, 5940, 5945, 5950, 5955, 5960, 5965,
90 5970, 5975, 5980, 5985, 5990, 5995, 6000, 6005, 6010, 6015, 6020, 6025, 6030, 6035, 6040, 6045,
91 6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095, 6100
92 };
93
94 return (channel > 0 && channel <= 221) ? frequencies[channel] : -1;
95}
96
97/**
98 * Return the channel from the frequency (in Mhz)
99 */
100int getChannelFromFrequency(int frequency)
101{
102 if (frequency >= 2412 && frequency <= 2472)
103 return (frequency - 2407) / 5;
104 else if (frequency == 2484)
105 return 14;
106 else if (frequency >= 5000 && frequency <= 6100)
107 return (frequency - 5000) / 5;
108 else
109 return -1;
110}
diff --git a/src/transport/wlan/helper_common.h b/src/transport/wlan/helper_common.h
new file mode 100644
index 000000000..71c3e1b9b
--- /dev/null
+++ b/src/transport/wlan/helper_common.h
@@ -0,0 +1,15 @@
1/*
2 * helper_common.h
3 *
4 * Created on: 28.03.2011
5 * Author: david
6 */
7
8#ifndef HELPER_COMMON_H_
9#define HELPER_COMMON_H_
10
11int getFrequencyFromChannel(int channel);
12int getChannelFromFrequency(int frequency);
13int send_mac_to_plugin(char * buffer, uint8_t * mac);
14
15#endif /* HELPER_COMMON_H_ */
diff --git a/src/transport/wlan/ieee80211.h b/src/transport/wlan/ieee80211.h
new file mode 100644
index 000000000..8df1d2c29
--- /dev/null
+++ b/src/transport/wlan/ieee80211.h
@@ -0,0 +1,663 @@
1/*-
2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * Alternatively, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2 as published by the Free
19 * Software Foundation.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * $FreeBSD: src/sys/net80211/ieee80211.h,v 1.12 2006/12/01 18:40:51 imp Exp $
33 */
34#ifndef _NET80211_IEEE80211_H_
35#define _NET80211_IEEE80211_H_
36
37/*
38 * 802.11 protocol definitions.
39 */
40
41#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
42/* is 802.11 address multicast/broadcast? */
43#define IEEE80211_IS_MULTICAST(_a) (*(_a) & 0x01)
44
45/* IEEE 802.11 PLCP header */
46struct ieee80211_plcp_hdr {
47 u_int16_t i_sfd;
48 u_int8_t i_signal;
49 u_int8_t i_service;
50 u_int16_t i_length;
51 u_int16_t i_crc;
52} GNUNET_PACKED;
53
54#define IEEE80211_PLCP_SFD 0xF3A0
55#define IEEE80211_PLCP_SERVICE 0x00
56
57/*
58 * generic definitions for IEEE 802.11 frames
59 */
60struct ieee80211_frame {
61 u_int8_t i_fc[2];
62 u_int8_t i_dur[2];
63 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
64 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
65 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
66 u_int8_t i_seq[2];
67 /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
68 /* see below */
69} GNUNET_PACKED;
70
71struct ieee80211_qosframe {
72 u_int8_t i_fc[2];
73 u_int8_t i_dur[2];
74 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
75 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
76 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
77 u_int8_t i_seq[2];
78 u_int8_t i_qos[2];
79 /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
80 /* see below */
81} GNUNET_PACKED;
82
83struct ieee80211_qoscntl {
84 u_int8_t i_qos[2];
85};
86
87struct ieee80211_frame_addr4 {
88 u_int8_t i_fc[2];
89 u_int8_t i_dur[2];
90 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
91 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
92 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
93 u_int8_t i_seq[2];
94 u_int8_t i_addr4[IEEE80211_ADDR_LEN];
95} GNUNET_PACKED;
96
97
98struct ieee80211_qosframe_addr4 {
99 u_int8_t i_fc[2];
100 u_int8_t i_dur[2];
101 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
102 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
103 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
104 u_int8_t i_seq[2];
105 u_int8_t i_addr4[IEEE80211_ADDR_LEN];
106 u_int8_t i_qos[2];
107} GNUNET_PACKED;
108
109#define IEEE80211_FC0_VERSION_MASK 0x03
110#define IEEE80211_FC0_VERSION_SHIFT 0
111#define IEEE80211_FC0_VERSION_0 0x00
112#define IEEE80211_FC0_TYPE_MASK 0x0c
113#define IEEE80211_FC0_TYPE_SHIFT 2
114#define IEEE80211_FC0_TYPE_MGT 0x00
115#define IEEE80211_FC0_TYPE_CTL 0x04
116#define IEEE80211_FC0_TYPE_DATA 0x08
117
118#define IEEE80211_FC0_SUBTYPE_MASK 0xf0
119#define IEEE80211_FC0_SUBTYPE_SHIFT 4
120/* for TYPE_MGT */
121#define IEEE80211_FC0_SUBTYPE_ASSOC_REQ 0x00
122#define IEEE80211_FC0_SUBTYPE_ASSOC_RESP 0x10
123#define IEEE80211_FC0_SUBTYPE_REASSOC_REQ 0x20
124#define IEEE80211_FC0_SUBTYPE_REASSOC_RESP 0x30
125#define IEEE80211_FC0_SUBTYPE_PROBE_REQ 0x40
126#define IEEE80211_FC0_SUBTYPE_PROBE_RESP 0x50
127#define IEEE80211_FC0_SUBTYPE_BEACON 0x80
128#define IEEE80211_FC0_SUBTYPE_ATIM 0x90
129#define IEEE80211_FC0_SUBTYPE_DISASSOC 0xa0
130#define IEEE80211_FC0_SUBTYPE_AUTH 0xb0
131#define IEEE80211_FC0_SUBTYPE_DEAUTH 0xc0
132/* for TYPE_CTL */
133#define IEEE80211_FC0_SUBTYPE_PS_POLL 0xa0
134#define IEEE80211_FC0_SUBTYPE_RTS 0xb0
135#define IEEE80211_FC0_SUBTYPE_CTS 0xc0
136#define IEEE80211_FC0_SUBTYPE_ACK 0xd0
137#define IEEE80211_FC0_SUBTYPE_CF_END 0xe0
138#define IEEE80211_FC0_SUBTYPE_CF_END_ACK 0xf0
139/* for TYPE_DATA (bit combination) */
140#define IEEE80211_FC0_SUBTYPE_DATA 0x00
141#define IEEE80211_FC0_SUBTYPE_CF_ACK 0x10
142#define IEEE80211_FC0_SUBTYPE_CF_POLL 0x20
143#define IEEE80211_FC0_SUBTYPE_CF_ACPL 0x30
144#define IEEE80211_FC0_SUBTYPE_NODATA 0x40
145#define IEEE80211_FC0_SUBTYPE_CFACK 0x50
146#define IEEE80211_FC0_SUBTYPE_CFPOLL 0x60
147#define IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK 0x70
148#define IEEE80211_FC0_SUBTYPE_QOS 0x80
149#define IEEE80211_FC0_SUBTYPE_QOS_NULL 0xc0
150
151#define IEEE80211_FC1_DIR_MASK 0x03
152#define IEEE80211_FC1_DIR_NODS 0x00 /* STA->STA */
153#define IEEE80211_FC1_DIR_TODS 0x01 /* STA->AP */
154#define IEEE80211_FC1_DIR_FROMDS 0x02 /* AP ->STA */
155#define IEEE80211_FC1_DIR_DSTODS 0x03 /* AP ->AP */
156
157#define IEEE80211_FC1_MORE_FRAG 0x04
158#define IEEE80211_FC1_RETRY 0x08
159#define IEEE80211_FC1_PWR_MGT 0x10
160#define IEEE80211_FC1_MORE_DATA 0x20
161#define IEEE80211_FC1_WEP 0x40
162#define IEEE80211_FC1_ORDER 0x80
163
164#define IEEE80211_SEQ_FRAG_MASK 0x000f
165#define IEEE80211_SEQ_FRAG_SHIFT 0
166#define IEEE80211_SEQ_SEQ_MASK 0xfff0
167#define IEEE80211_SEQ_SEQ_SHIFT 4
168
169#define IEEE80211_NWID_LEN 32
170
171#define IEEE80211_QOS_TXOP 0x00ff
172/* bit 8 is reserved */
173#define IEEE80211_QOS_ACKPOLICY 0x60
174#define IEEE80211_QOS_ACKPOLICY_S 5
175#define IEEE80211_QOS_ESOP 0x10
176#define IEEE80211_QOS_ESOP_S 4
177#define IEEE80211_QOS_TID 0x0f
178
179/* does frame have QoS sequence control data */
180#define IEEE80211_QOS_HAS_SEQ(wh) \
181 (((wh)->i_fc[0] & \
182 (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) == \
183 (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
184
185/*
186 * WME/802.11e information element.
187 */
188struct ieee80211_wme_info {
189 u_int8_t wme_id; /* IEEE80211_ELEMID_VENDOR */
190 u_int8_t wme_len; /* length in bytes */
191 u_int8_t wme_oui[3]; /* 0x00, 0x50, 0xf2 */
192 u_int8_t wme_type; /* OUI type */
193 u_int8_t wme_subtype; /* OUI subtype */
194 u_int8_t wme_version; /* spec revision */
195 u_int8_t wme_info; /* QoS info */
196} GNUNET_PACKED;
197
198/*
199 * WME/802.11e Tspec Element
200 */
201struct ieee80211_wme_tspec {
202 u_int8_t ts_id;
203 u_int8_t ts_len;
204 u_int8_t ts_oui[3];
205 u_int8_t ts_oui_type;
206 u_int8_t ts_oui_subtype;
207 u_int8_t ts_version;
208 u_int8_t ts_tsinfo[3];
209 u_int8_t ts_nom_msdu[2];
210 u_int8_t ts_max_msdu[2];
211 u_int8_t ts_min_svc[4];
212 u_int8_t ts_max_svc[4];
213 u_int8_t ts_inactv_intv[4];
214 u_int8_t ts_susp_intv[4];
215 u_int8_t ts_start_svc[4];
216 u_int8_t ts_min_rate[4];
217 u_int8_t ts_mean_rate[4];
218 u_int8_t ts_max_burst[4];
219 u_int8_t ts_min_phy[4];
220 u_int8_t ts_peak_rate[4];
221 u_int8_t ts_delay[4];
222 u_int8_t ts_surplus[2];
223 u_int8_t ts_medium_time[2];
224} GNUNET_PACKED;
225
226/*
227 * WME AC parameter field
228 */
229struct ieee80211_wme_acparams {
230 u_int8_t acp_aci_aifsn;
231 u_int8_t acp_logcwminmax;
232 u_int16_t acp_txop;
233} GNUNET_PACKED;
234
235#define WME_NUM_AC 4 /* 4 AC categories */
236
237#define WME_PARAM_ACI 0x60 /* Mask for ACI field */
238#define WME_PARAM_ACI_S 5 /* Shift for ACI field */
239#define WME_PARAM_ACM 0x10 /* Mask for ACM bit */
240#define WME_PARAM_ACM_S 4 /* Shift for ACM bit */
241#define WME_PARAM_AIFSN 0x0f /* Mask for aifsn field */
242#define WME_PARAM_AIFSN_S 0 /* Shift for aifsn field */
243#define WME_PARAM_LOGCWMIN 0x0f /* Mask for CwMin field (in log) */
244#define WME_PARAM_LOGCWMIN_S 0 /* Shift for CwMin field */
245#define WME_PARAM_LOGCWMAX 0xf0 /* Mask for CwMax field (in log) */
246#define WME_PARAM_LOGCWMAX_S 4 /* Shift for CwMax field */
247
248#define WME_AC_TO_TID(_ac) ( \
249 ((_ac) == WME_AC_VO) ? 6 : \
250 ((_ac) == WME_AC_VI) ? 5 : \
251 ((_ac) == WME_AC_BK) ? 1 : \
252 0)
253
254#define TID_TO_WME_AC(_tid) ( \
255 ((_tid) < 1) ? WME_AC_BE : \
256 ((_tid) < 3) ? WME_AC_BK : \
257 ((_tid) < 6) ? WME_AC_VI : \
258 WME_AC_VO)
259
260/*
261 * WME Parameter Element
262 */
263struct ieee80211_wme_param {
264 u_int8_t param_id;
265 u_int8_t param_len;
266 u_int8_t param_oui[3];
267 u_int8_t param_oui_type;
268 u_int8_t param_oui_sybtype;
269 u_int8_t param_version;
270 u_int8_t param_qosInfo;
271#define WME_QOSINFO_COUNT 0x0f /* Mask for param count field */
272 u_int8_t param_reserved;
273 struct ieee80211_wme_acparams params_acParams[WME_NUM_AC];
274} GNUNET_PACKED;
275
276/*
277 * Management Notification Frame
278 */
279struct ieee80211_mnf {
280 u_int8_t mnf_category;
281 u_int8_t mnf_action;
282 u_int8_t mnf_dialog;
283 u_int8_t mnf_status;
284} GNUNET_PACKED;
285#define MNF_SETUP_REQ 0
286#define MNF_SETUP_RESP 1
287#define MNF_TEARDOWN 2
288
289/*
290 * Control frames.
291 */
292struct ieee80211_frame_min {
293 u_int8_t i_fc[2];
294 u_int8_t i_dur[2];
295 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
296 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
297 /* FCS */
298} GNUNET_PACKED;
299
300struct ieee80211_frame_rts {
301 u_int8_t i_fc[2];
302 u_int8_t i_dur[2];
303 u_int8_t i_ra[IEEE80211_ADDR_LEN];
304 u_int8_t i_ta[IEEE80211_ADDR_LEN];
305 /* FCS */
306} GNUNET_PACKED;
307
308struct ieee80211_frame_cts {
309 u_int8_t i_fc[2];
310 u_int8_t i_dur[2];
311 u_int8_t i_ra[IEEE80211_ADDR_LEN];
312 /* FCS */
313} GNUNET_PACKED;
314
315struct ieee80211_frame_ack {
316 u_int8_t i_fc[2];
317 u_int8_t i_dur[2];
318 u_int8_t i_ra[IEEE80211_ADDR_LEN];
319 /* FCS */
320} GNUNET_PACKED;
321
322struct ieee80211_frame_pspoll {
323 u_int8_t i_fc[2];
324 u_int8_t i_aid[2];
325 u_int8_t i_bssid[IEEE80211_ADDR_LEN];
326 u_int8_t i_ta[IEEE80211_ADDR_LEN];
327 /* FCS */
328} GNUNET_PACKED;
329
330struct ieee80211_frame_cfend { /* NB: also CF-End+CF-Ack */
331 u_int8_t i_fc[2];
332 u_int8_t i_dur[2]; /* should be zero */
333 u_int8_t i_ra[IEEE80211_ADDR_LEN];
334 u_int8_t i_bssid[IEEE80211_ADDR_LEN];
335 /* FCS */
336} GNUNET_PACKED;
337
338/*
339 * BEACON management packets
340 *
341 * octet timestamp[8]
342 * octet beacon interval[2]
343 * octet capability information[2]
344 * information element
345 * octet elemid
346 * octet length
347 * octet information[length]
348 */
349
350typedef u_int8_t *ieee80211_mgt_beacon_t;
351
352#define IEEE80211_BEACON_INTERVAL(beacon) \
353 ((beacon)[8] | ((beacon)[9] << 8))
354#define IEEE80211_BEACON_CAPABILITY(beacon) \
355 ((beacon)[10] | ((beacon)[11] << 8))
356
357#define IEEE80211_CAPINFO_ESS 0x0001
358#define IEEE80211_CAPINFO_IBSS 0x0002
359#define IEEE80211_CAPINFO_CF_POLLABLE 0x0004
360#define IEEE80211_CAPINFO_CF_POLLREQ 0x0008
361#define IEEE80211_CAPINFO_PRIVACY 0x0010
362#define IEEE80211_CAPINFO_SHORT_PREAMBLE 0x0020
363#define IEEE80211_CAPINFO_PBCC 0x0040
364#define IEEE80211_CAPINFO_CHNL_AGILITY 0x0080
365/* bits 8-9 are reserved */
366#define IEEE80211_CAPINFO_SHORT_SLOTTIME 0x0400
367#define IEEE80211_CAPINFO_RSN 0x0800
368/* bit 12 is reserved */
369#define IEEE80211_CAPINFO_DSSSOFDM 0x2000
370/* bits 14-15 are reserved */
371
372/*
373 * 802.11i/WPA information element (maximally sized).
374 */
375struct ieee80211_ie_wpa {
376 u_int8_t wpa_id; /* IEEE80211_ELEMID_VENDOR */
377 u_int8_t wpa_len; /* length in bytes */
378 u_int8_t wpa_oui[3]; /* 0x00, 0x50, 0xf2 */
379 u_int8_t wpa_type; /* OUI type */
380 u_int16_t wpa_version; /* spec revision */
381 u_int32_t wpa_mcipher[1]; /* multicast/group key cipher */
382 u_int16_t wpa_uciphercnt; /* # pairwise key ciphers */
383 u_int32_t wpa_uciphers[8];/* ciphers */
384 u_int16_t wpa_authselcnt; /* authentication selector cnt*/
385 u_int32_t wpa_authsels[8];/* selectors */
386 u_int16_t wpa_caps; /* 802.11i capabilities */
387 u_int16_t wpa_pmkidcnt; /* 802.11i pmkid count */
388 u_int16_t wpa_pmkids[8]; /* 802.11i pmkids */
389} GNUNET_PACKED;
390
391/*
392 * Management information element payloads.
393 */
394
395enum {
396 IEEE80211_ELEMID_SSID = 0,
397 IEEE80211_ELEMID_RATES = 1,
398 IEEE80211_ELEMID_FHPARMS = 2,
399 IEEE80211_ELEMID_DSPARMS = 3,
400 IEEE80211_ELEMID_CFPARMS = 4,
401 IEEE80211_ELEMID_TIM = 5,
402 IEEE80211_ELEMID_IBSSPARMS = 6,
403 IEEE80211_ELEMID_COUNTRY = 7,
404 IEEE80211_ELEMID_CHALLENGE = 16,
405 /* 17-31 reserved for challenge text extension */
406 IEEE80211_ELEMID_ERP = 42,
407 IEEE80211_ELEMID_RSN = 48,
408 IEEE80211_ELEMID_XRATES = 50,
409 IEEE80211_ELEMID_TPC = 150,
410 IEEE80211_ELEMID_CCKM = 156,
411 IEEE80211_ELEMID_VENDOR = 221, /* vendor private */
412};
413
414struct ieee80211_tim_ie {
415 u_int8_t tim_ie; /* IEEE80211_ELEMID_TIM */
416 u_int8_t tim_len;
417 u_int8_t tim_count; /* DTIM count */
418 u_int8_t tim_period; /* DTIM period */
419 u_int8_t tim_bitctl; /* bitmap control */
420 u_int8_t tim_bitmap[1]; /* variable-length bitmap */
421} GNUNET_PACKED;
422
423struct ieee80211_country_ie {
424 u_int8_t ie; /* IEEE80211_ELEMID_COUNTRY */
425 u_int8_t len;
426 u_int8_t cc[3]; /* ISO CC+(I)ndoor/(O)utdoor */
427 struct {
428 u_int8_t schan; /* starting channel */
429 u_int8_t nchan; /* number channels */
430 u_int8_t maxtxpwr; /* tx power cap */
431 } GNUNET_PACKED band[4]; /* up to 4 sub bands */
432} GNUNET_PACKED;
433
434#define IEEE80211_CHALLENGE_LEN 128
435
436#define IEEE80211_RATE_BASIC 0x80
437#define IEEE80211_RATE_VAL 0x7f
438
439/* EPR information element flags */
440#define IEEE80211_ERP_NON_ERP_PRESENT 0x01
441#define IEEE80211_ERP_USE_PROTECTION 0x02
442#define IEEE80211_ERP_LONG_PREAMBLE 0x04
443
444/* Atheros private advanced capabilities info */
445#define ATHEROS_CAP_TURBO_PRIME 0x01
446#define ATHEROS_CAP_COMPRESSION 0x02
447#define ATHEROS_CAP_FAST_FRAME 0x04
448/* bits 3-6 reserved */
449#define ATHEROS_CAP_BOOST 0x80
450
451#define ATH_OUI 0x7f0300 /* Atheros OUI */
452#define ATH_OUI_TYPE 0x01
453#define ATH_OUI_VERSION 0x01
454
455#define WPA_OUI 0xf25000
456#define WPA_OUI_TYPE 0x01
457#define WPA_VERSION 1 /* current supported version */
458
459#define WPA_CSE_NULL 0x00
460#define WPA_CSE_WEP40 0x01
461#define WPA_CSE_TKIP 0x02
462#define WPA_CSE_CCMP 0x04
463#define WPA_CSE_WEP104 0x05
464
465#define WPA_ASE_NONE 0x00
466#define WPA_ASE_8021X_UNSPEC 0x01
467#define WPA_ASE_8021X_PSK 0x02
468
469#define RSN_OUI 0xac0f00
470#define RSN_VERSION 1 /* current supported version */
471
472#define RSN_CSE_NULL 0x00
473#define RSN_CSE_WEP40 0x01
474#define RSN_CSE_TKIP 0x02
475#define RSN_CSE_WRAP 0x03
476#define RSN_CSE_CCMP 0x04
477#define RSN_CSE_WEP104 0x05
478
479#define RSN_ASE_NONE 0x00
480#define RSN_ASE_8021X_UNSPEC 0x01
481#define RSN_ASE_8021X_PSK 0x02
482
483#define RSN_CAP_PREAUTH 0x01
484
485#define WME_OUI 0xf25000
486#define WME_OUI_TYPE 0x02
487#define WME_INFO_OUI_SUBTYPE 0x00
488#define WME_PARAM_OUI_SUBTYPE 0x01
489#define WME_VERSION 1
490
491/* WME stream classes */
492#define WME_AC_BE 0 /* best effort */
493#define WME_AC_BK 1 /* background */
494#define WME_AC_VI 2 /* video */
495#define WME_AC_VO 3 /* voice */
496
497/*
498 * AUTH management packets
499 *
500 * octet algo[2]
501 * octet seq[2]
502 * octet status[2]
503 * octet chal.id
504 * octet chal.length
505 * octet chal.text[253]
506 */
507
508typedef u_int8_t *ieee80211_mgt_auth_t;
509
510#define IEEE80211_AUTH_ALGORITHM(auth) \
511 ((auth)[0] | ((auth)[1] << 8))
512#define IEEE80211_AUTH_TRANSACTION(auth) \
513 ((auth)[2] | ((auth)[3] << 8))
514#define IEEE80211_AUTH_STATUS(auth) \
515 ((auth)[4] | ((auth)[5] << 8))
516
517#define IEEE80211_AUTH_ALG_OPEN 0x0000
518#define IEEE80211_AUTH_ALG_SHARED 0x0001
519#define IEEE80211_AUTH_ALG_LEAP 0x0080
520
521enum {
522 IEEE80211_AUTH_OPEN_REQUEST = 1,
523 IEEE80211_AUTH_OPEN_RESPONSE = 2,
524};
525
526enum {
527 IEEE80211_AUTH_SHARED_REQUEST = 1,
528 IEEE80211_AUTH_SHARED_CHALLENGE = 2,
529 IEEE80211_AUTH_SHARED_RESPONSE = 3,
530 IEEE80211_AUTH_SHARED_PASS = 4,
531};
532
533/*
534 * Reason codes
535 *
536 * Unlisted codes are reserved
537 */
538
539enum {
540 IEEE80211_REASON_UNSPECIFIED = 1,
541 IEEE80211_REASON_AUTH_EXPIRE = 2,
542 IEEE80211_REASON_AUTH_LEAVE = 3,
543 IEEE80211_REASON_ASSOC_EXPIRE = 4,
544 IEEE80211_REASON_ASSOC_TOOMANY = 5,
545 IEEE80211_REASON_NOT_AUTHED = 6,
546 IEEE80211_REASON_NOT_ASSOCED = 7,
547 IEEE80211_REASON_ASSOC_LEAVE = 8,
548 IEEE80211_REASON_ASSOC_NOT_AUTHED = 9,
549
550 IEEE80211_REASON_RSN_REQUIRED = 11,
551 IEEE80211_REASON_RSN_INCONSISTENT = 12,
552 IEEE80211_REASON_IE_INVALID = 13,
553 IEEE80211_REASON_MIC_FAILURE = 14,
554
555 IEEE80211_STATUS_SUCCESS = 0,
556 IEEE80211_STATUS_UNSPECIFIED = 1,
557 IEEE80211_STATUS_CAPINFO = 10,
558 IEEE80211_STATUS_NOT_ASSOCED = 11,
559 IEEE80211_STATUS_OTHER = 12,
560 IEEE80211_STATUS_ALG = 13,
561 IEEE80211_STATUS_SEQUENCE = 14,
562 IEEE80211_STATUS_CHALLENGE = 15,
563 IEEE80211_STATUS_TIMEOUT = 16,
564 IEEE80211_STATUS_TOOMANY = 17,
565 IEEE80211_STATUS_BASIC_RATE = 18,
566 IEEE80211_STATUS_SP_REQUIRED = 19,
567 IEEE80211_STATUS_PBCC_REQUIRED = 20,
568 IEEE80211_STATUS_CA_REQUIRED = 21,
569 IEEE80211_STATUS_TOO_MANY_STATIONS = 22,
570 IEEE80211_STATUS_RATES = 23,
571 IEEE80211_STATUS_SHORTSLOT_REQUIRED = 25,
572 IEEE80211_STATUS_DSSSOFDM_REQUIRED = 26,
573};
574
575#define IEEE80211_WEP_KEYLEN 5 /* 40bit */
576#define IEEE80211_WEP_IVLEN 3 /* 24bit */
577#define IEEE80211_WEP_KIDLEN 1 /* 1 octet */
578#define IEEE80211_WEP_CRCLEN 4 /* CRC-32 */
579#define IEEE80211_WEP_NKID 4 /* number of key ids */
580
581/*
582 * 802.11i defines an extended IV for use with non-WEP ciphers.
583 * When the EXTIV bit is set in the key id byte an additional
584 * 4 bytes immediately follow the IV for TKIP. For CCMP the
585 * EXTIV bit is likewise set but the 8 bytes represent the
586 * CCMP header rather than IV+extended-IV.
587 */
588#define IEEE80211_WEP_EXTIV 0x20
589#define IEEE80211_WEP_EXTIVLEN 4 /* extended IV length */
590#define IEEE80211_WEP_MICLEN 8 /* trailing MIC */
591
592#define IEEE80211_CRC_LEN 4
593
594/*
595 * Maximum acceptable MTU is:
596 * IEEE80211_MAX_LEN - WEP overhead - CRC -
597 * QoS overhead - RSN/WPA overhead
598 * Min is arbitrarily chosen > IEEE80211_MIN_LEN. The default
599 * mtu is Ethernet-compatible; it's set by ether_ifattach.
600 */
601#define IEEE80211_MTU_MAX 2290
602#define IEEE80211_MTU_MIN 32
603
604#define IEEE80211_MAX_LEN (2300 + IEEE80211_CRC_LEN + \
605 (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN))
606#define IEEE80211_ACK_LEN \
607 (sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN)
608#define IEEE80211_MIN_LEN \
609 (sizeof(struct ieee80211_frame_min) + IEEE80211_CRC_LEN)
610
611/*
612 * The 802.11 spec says at most 2007 stations may be
613 * associated at once. For most AP's this is way more
614 * than is feasible so we use a default of 128. This
615 * number may be overridden by the driver and/or by
616 * user configuration.
617 */
618#define IEEE80211_AID_MAX 2007
619#define IEEE80211_AID_DEF 128
620
621#define IEEE80211_AID(b) ((b) &~ 0xc000)
622
623/*
624 * RTS frame length parameters. The default is specified in
625 * the 802.11 spec as 512; we treat it as implementation-dependent
626 * so it's defined in ieee80211_var.h. The max may be wrong
627 * for jumbo frames.
628 */
629#define IEEE80211_RTS_MIN 1
630#define IEEE80211_RTS_MAX 2346
631
632/*
633 * TX fragmentation parameters. As above for RTS, we treat
634 * default as implementation-dependent so define it elsewhere.
635 */
636#define IEEE80211_FRAG_MIN 256
637#define IEEE80211_FRAG_MAX 2346
638
639/*
640 * Beacon interval (TU's). Min+max come from WiFi requirements.
641 * As above, we treat default as implementation-dependent so
642 * define it elsewhere.
643 */
644#define IEEE80211_BINTVAL_MAX 1000 /* max beacon interval (TU's) */
645#define IEEE80211_BINTVAL_MIN 25 /* min beacon interval (TU's) */
646
647/*
648 * DTIM period (beacons). Min+max are not really defined
649 * by the protocol but we want them publicly visible so
650 * define them here.
651 */
652#define IEEE80211_DTIM_MAX 15 /* max DTIM period */
653#define IEEE80211_DTIM_MIN 1 /* min DTIM period */
654
655/*
656 * Beacon miss threshold (beacons). As for DTIM, we define
657 * them here to be publicly visible. Note the max may be
658 * clamped depending on device capabilities.
659 */
660#define IEEE80211_HWBMISS_MIN 1
661#define IEEE80211_HWBMISS_MAX 255
662
663#endif /* _NET80211_IEEE80211_H_ */
diff --git a/src/transport/wlan/ieee80211_radiotap.h b/src/transport/wlan/ieee80211_radiotap.h
new file mode 100644
index 000000000..b132d402d
--- /dev/null
+++ b/src/transport/wlan/ieee80211_radiotap.h
@@ -0,0 +1,260 @@
1/* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 sam Exp $ */
2/* $NetBSD: ieee80211_radiotap.h,v 1.11 2005/06/22 06:16:02 dyoung Exp $ */
3
4/*-
5 * Copyright (c) 2003, 2004 David Young. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of David Young may not be used to endorse or promote
16 * products derived from this software without specific prior
17 * written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
23 * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
25 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 * OF SUCH DAMAGE.
31 */
32
33/*
34 * Modifications to fit into the linux IEEE 802.11 stack,
35 * Mike Kershaw (dragorn@kismetwireless.net)
36 */
37
38#ifndef IEEE80211RADIOTAP_H
39#define IEEE80211RADIOTAP_H
40
41/* Radiotap header version (from official NetBSD feed) */
42#define IEEE80211RADIOTAP_VERSION "1.5"
43/* Base version of the radiotap packet header data */
44#define PKTHDR_RADIOTAP_VERSION 0
45
46/* A generic radio capture format is desirable. There is one for
47 * Linux, but it is neither rigidly defined (there were not even
48 * units given for some fields) nor easily extensible.
49 *
50 * I suggest the following extensible radio capture format. It is
51 * based on a bitmap indicating which fields are present.
52 *
53 * I am trying to describe precisely what the application programmer
54 * should expect in the following, and for that reason I tell the
55 * units and origin of each measurement (where it applies), or else I
56 * use sufficiently weaselly language ("is a monotonically nondecreasing
57 * function of...") that I cannot set false expectations for lawyerly
58 * readers.
59 */
60
61/* XXX tcpdump/libpcap do not tolerate variable-length headers,
62 * yet, so we pad every radiotap header to 64 bytes. Ugh.
63 */
64#define IEEE80211_RADIOTAP_HDRLEN 64
65
66/* The radio capture header precedes the 802.11 header.
67 * All data in the header is little endian on all platforms.
68 */
69struct ieee80211_radiotap_header {
70 u8 it_version; /* Version 0. Only increases
71 * for drastic changes,
72 * introduction of compatible
73 * new fields does not count.
74 */
75 u8 it_pad;
76 u16 it_len; /* length of the whole
77 * header in bytes, including
78 * it_version, it_pad,
79 * it_len, and data fields.
80 */
81 u32 it_present; /* A bitmap telling which
82 * fields are present. Set bit 31
83 * (0x80000000) to extend the
84 * bitmap by another 32 bits.
85 * Additional extensions are made
86 * by setting bit 31.
87 */
88};
89
90#define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK 0x80000000
91
92/* Name Data type Units
93 * ---- --------- -----
94 *
95 * IEEE80211_RADIOTAP_TSFT __le64 microseconds
96 *
97 * Value in microseconds of the MAC's 64-bit 802.11 Time
98 * Synchronization Function timer when the first bit of the
99 * MPDU arrived at the MAC. For received frames, only.
100 *
101 * IEEE80211_RADIOTAP_CHANNEL 2 x __le16 MHz, bitmap
102 *
103 * Tx/Rx frequency in MHz, followed by flags (see below).
104 *
105 * IEEE80211_RADIOTAP_FHSS __le16 see below
106 *
107 * For frequency-hopping radios, the hop set (first byte)
108 * and pattern (second byte).
109 *
110 * IEEE80211_RADIOTAP_RATE u8 500kb/s
111 *
112 * Tx/Rx data rate
113 *
114 * IEEE80211_RADIOTAP_DBM_ANTSIGNAL s8 decibels from
115 * one milliwatt (dBm)
116 *
117 * RF signal power at the antenna, decibel difference from
118 * one milliwatt.
119 *
120 * IEEE80211_RADIOTAP_DBM_ANTNOISE s8 decibels from
121 * one milliwatt (dBm)
122 *
123 * RF noise power at the antenna, decibel difference from one
124 * milliwatt.
125 *
126 * IEEE80211_RADIOTAP_DB_ANTSIGNAL u8 decibel (dB)
127 *
128 * RF signal power at the antenna, decibel difference from an
129 * arbitrary, fixed reference.
130 *
131 * IEEE80211_RADIOTAP_DB_ANTNOISE u8 decibel (dB)
132 *
133 * RF noise power at the antenna, decibel difference from an
134 * arbitrary, fixed reference point.
135 *
136 * IEEE80211_RADIOTAP_LOCK_QUALITY __le16 unitless
137 *
138 * Quality of Barker code lock. Unitless. Monotonically
139 * nondecreasing with "better" lock strength. Called "Signal
140 * Quality" in datasheets. (Is there a standard way to measure
141 * this?)
142 *
143 * IEEE80211_RADIOTAP_TX_ATTENUATION __le16 unitless
144 *
145 * Transmit power expressed as unitless distance from max
146 * power set at factory calibration. 0 is max power.
147 * Monotonically nondecreasing with lower power levels.
148 *
149 * IEEE80211_RADIOTAP_DB_TX_ATTENUATION __le16 decibels (dB)
150 *
151 * Transmit power expressed as decibel distance from max power
152 * set at factory calibration. 0 is max power. Monotonically
153 * nondecreasing with lower power levels.
154 *
155 * IEEE80211_RADIOTAP_DBM_TX_POWER s8 decibels from
156 * one milliwatt (dBm)
157 *
158 * Transmit power expressed as dBm (decibels from a 1 milliwatt
159 * reference). This is the absolute power level measured at
160 * the antenna port.
161 *
162 * IEEE80211_RADIOTAP_FLAGS u8 bitmap
163 *
164 * Properties of transmitted and received frames. See flags
165 * defined below.
166 *
167 * IEEE80211_RADIOTAP_ANTENNA u8 antenna index
168 *
169 * Unitless indication of the Rx/Tx antenna for this packet.
170 * The first antenna is antenna 0.
171 *
172 * IEEE80211_RADIOTAP_RX_FLAGS __le16 bitmap
173 *
174 * Properties of received frames. See flags defined below.
175 *
176 * IEEE80211_RADIOTAP_TX_FLAGS __le16 bitmap
177 *
178 * Properties of transmitted frames. See flags defined below.
179 *
180 * IEEE80211_RADIOTAP_RTS_RETRIES u8 data
181 *
182 * Number of rts retries a transmitted frame used.
183 *
184 * IEEE80211_RADIOTAP_DATA_RETRIES u8 data
185 *
186 * Number of unicast retries a transmitted frame used.
187 *
188 */
189enum ieee80211_radiotap_type {
190 IEEE80211_RADIOTAP_TSFT = 0,
191 IEEE80211_RADIOTAP_FLAGS = 1,
192 IEEE80211_RADIOTAP_RATE = 2,
193 IEEE80211_RADIOTAP_CHANNEL = 3,
194 IEEE80211_RADIOTAP_FHSS = 4,
195 IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
196 IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
197 IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
198 IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
199 IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
200 IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
201 IEEE80211_RADIOTAP_ANTENNA = 11,
202 IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
203 IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
204 IEEE80211_RADIOTAP_RX_FLAGS = 14,
205 IEEE80211_RADIOTAP_TX_FLAGS = 15,
206 IEEE80211_RADIOTAP_RTS_RETRIES = 16,
207 IEEE80211_RADIOTAP_DATA_RETRIES = 17,
208 IEEE80211_RADIOTAP_EXT = 31
209};
210
211/* Channel flags. */
212#define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */
213#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */
214#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */
215#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */
216#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */
217#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */
218#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */
219#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */
220
221/* For IEEE80211_RADIOTAP_FLAGS */
222#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
223 * during CFP
224 */
225#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
226 * with short
227 * preamble
228 */
229#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
230 * with WEP encryption
231 */
232#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
233 * with fragmentation
234 */
235#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
236#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
237 * 802.11 header and payload
238 * (to 32-bit boundary)
239 */
240/* For IEEE80211_RADIOTAP_RX_FLAGS */
241#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */
242
243/* For IEEE80211_RADIOTAP_TX_FLAGS */
244#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive
245 * retries */
246#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */
247#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
248#define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008 /* frame should not be ACKed */
249#define IEEE80211_RADIOTAP_F_TX_NOSEQ 0x0010 /* sequence number handled
250 * by userspace */
251
252/* Ugly macro to convert literal channel numbers into their mhz equivalents
253 * There are certianly some conditions that will break this (like feeding it '30')
254 * but they shouldn't arise since nothing talks on channel 30. */
255#define ieee80211chan2mhz(x) \
256 (((x) <= 14) ? \
257 (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \
258 ((x) + 1000) * 5)
259
260#endif /* IEEE80211_RADIOTAP_H */
diff --git a/src/transport/wlan/loopback_helper.c b/src/transport/wlan/loopback_helper.c
new file mode 100644
index 000000000..adeff06a2
--- /dev/null
+++ b/src/transport/wlan/loopback_helper.c
@@ -0,0 +1,428 @@
1
2
3#include <sys/socket.h>
4#include <sys/ioctl.h>
5#include <sys/types.h>
6#include <sys/wait.h>
7#include <sys/time.h>
8#include <sys/stat.h>
9#include <stdio.h>
10#include <stdlib.h>
11
12#include <errno.h>
13#include <resolv.h>
14#include <string.h>
15#include <utime.h>
16#include <unistd.h>
17#include <getopt.h>
18
19#include "gnunet_constants.h"
20#include "gnunet_os_lib.h"
21#include "gnunet_transport_plugin.h"
22#include "transport.h"
23#include "gnunet_util_lib.h"
24#include "plugin_transport_wlan.h"
25#include "gnunet_common.h"
26#include "gnunet-transport-wlan-helper.h"
27#include "gnunet_crypto_lib.h"
28#include "loopback_helper.h"
29#include "helper_common.h"
30
31extern int first;
32
33static void
34sigfunc(int sig)
35{
36 closeprog = 1;
37 unlink(FIFO_FILE1);
38 unlink(FIFO_FILE2);
39}
40
41static void
42stdin_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
43{
44 struct sendbuf *write_pout = cls;
45 int sendsize;
46 struct GNUNET_MessageHeader newheader;
47 unsigned char * from;
48 unsigned char * to;
49
50 sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send);
51
52 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type))
53 {
54 fprintf(stderr, "Function stdin_send: wrong packet type\n");
55 exit(1);
56 }
57 if ((sendsize + write_pout->size) > MAXLINE * 2)
58 {
59 fprintf(stderr, "Function stdin_send: Packet too big for buffer\n");
60 exit(1);
61 }
62
63 newheader.size = htons(sendsize);
64 newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
65
66 to = write_pout->buf + write_pout->size;
67 memcpy(to, &newheader, sizeof(struct GNUNET_MessageHeader));
68 write_pout->size += sizeof(struct GNUNET_MessageHeader);
69
70 from = ((unsigned char *) hdr) + sizeof(struct Radiotap_Send)
71 + sizeof(struct GNUNET_MessageHeader);
72 to = write_pout->buf + write_pout->size;
73 memcpy(to, from, sendsize - sizeof(struct GNUNET_MessageHeader));
74 write_pout->size += sendsize - sizeof(struct GNUNET_MessageHeader);
75}
76
77static void
78file_in_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
79{
80 struct sendbuf * write_std = cls;
81 uint16_t sendsize;
82
83 sendsize = ntohs(hdr->size);
84
85 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type))
86 {
87 fprintf(stderr, "Function file_in_send: wrong packet type\n");
88 exit(1);
89 }
90 if ((sendsize + write_std->size) > MAXLINE * 2)
91 {
92 fprintf(stderr, "Function file_in_send: Packet too big for buffer\n");
93 exit(1);
94 }
95
96 memcpy(write_std->buf + write_std->size, hdr, sendsize);
97 write_std->size += sendsize;
98}
99
100int
101testmode(int argc, char *argv[])
102{
103 struct stat st;
104 int erg;
105
106 FILE *fpin;
107 FILE *fpout;
108
109 int fdpin;
110 int fdpout;
111
112 //make the fifos if needed
113 if (0 != stat(FIFO_FILE1, &st))
114 {
115 if (0 == stat(FIFO_FILE2, &st))
116 {
117 fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n");
118 exit(1);
119 }
120
121 umask(0);
122 erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0);
123 erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0);
124
125 }
126 else
127 {
128
129 if (0 != stat(FIFO_FILE2, &st))
130 {
131 fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n");
132 exit(1);
133 }
134
135 }
136
137 if (strstr(argv[2], "1"))
138 {
139 //fprintf(stderr, "First\n");
140 first = 1;
141 fpin = fopen(FIFO_FILE1, "r");
142 if (NULL == fpin)
143 {
144 fprintf(stderr, "fopen of read FIFO_FILE1\n");
145 exit(1);
146 }
147 if (NULL == (fpout = fopen(FIFO_FILE2, "w")))
148 {
149 fprintf(stderr, "fopen of write FIFO_FILE2\n");
150 exit(1);
151 }
152
153 }
154 else
155 {
156 first = 0;
157 //fprintf(stderr, "Second\n");
158 if (NULL == (fpout = fopen(FIFO_FILE1, "w")))
159 {
160 fprintf(stderr, "fopen of write FIFO_FILE1\n");
161 exit(1);
162 }
163 if (NULL == (fpin = fopen(FIFO_FILE2, "r")))
164 {
165 fprintf(stderr, "fopen of read FIFO_FILE2\n");
166 exit(1);
167 }
168
169 }
170
171 fdpin = fileno(fpin);
172 if (fdpin >= FD_SETSIZE)
173 {
174 fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin,
175 (unsigned int) FD_SETSIZE);
176 close(fdpin);
177 return -1;
178 }
179
180 fdpout = fileno(fpout);
181 if (fdpout >= FD_SETSIZE)
182 {
183 fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout,
184 (unsigned int) FD_SETSIZE);
185 close(fdpout);
186 return -1;
187
188 }
189
190 signal(SIGINT, &sigfunc);
191 signal(SIGTERM, &sigfunc);
192
193 char readbuf[MAXLINE];
194 int readsize = 0;
195 struct sendbuf write_std;
196 write_std.size = 0;
197 write_std.pos = 0;
198
199 struct sendbuf write_pout;
200 write_pout.size = 0;
201 write_pout.pos = 0;
202
203 int ret = 0;
204 int maxfd = 0;
205
206 fd_set rfds;
207 fd_set wfds;
208 struct timeval tv;
209 int retval;
210
211 struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst;
212 struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst;
213
214 stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout);
215 file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std);
216
217 //send mac first
218
219 struct MacAddress macaddr;
220
221 //Send random mac address
222 macaddr.mac[0] = 0x13;
223 macaddr.mac[1] = 0x22;
224 macaddr.mac[2] = 0x33;
225 macaddr.mac[3] = 0x44;
226 macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256);
227 macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256);
228
229 write_std.size = send_mac_to_plugin((char *) write_std.buf, macaddr.mac);
230
231 /*
232 //wait
233 tv.tv_sec = 2;
234 tv.tv_usec = 0;
235 retval = select(0, NULL, NULL, NULL, &tv);
236
237
238 tv.tv_sec = 3;
239 tv.tv_usec = 0;
240 // if there is something to write
241 FD_ZERO(&wfds);
242 FD_SET(STDOUT_FILENO, &wfds);
243
244 retval = select(STDOUT_FILENO + 1, NULL, &wfds, NULL, &tv);
245
246 if (FD_ISSET(STDOUT_FILENO, &wfds))
247 {
248 ret = write(STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size
249 - write_std.pos);
250
251 if (0 > ret)
252 {
253 closeprog = 1;
254 fprintf(stderr, "Write ERROR to STDOUT");
255 exit(1);
256 }
257 else
258 {
259 write_std.pos += ret;
260 // check if finished
261 if (write_std.pos == write_std.size)
262 {
263 write_std.pos = 0;
264 write_std.size = 0;
265 }
266 }
267 }
268
269 memcpy(&write_std.buf, &macmsg, sizeof(struct Wlan_Helper_Control_Message));
270 write_std.size = sizeof(struct Wlan_Helper_Control_Message);
271 */
272
273 //wait
274 tv.tv_sec = 2;
275 tv.tv_usec = 0;
276 retval = select(0, NULL, NULL, NULL, &tv);
277
278 while (0 == closeprog)
279 {
280
281 maxfd = 0;
282
283 //set timeout
284 tv.tv_sec = 5;
285 tv.tv_usec = 0;
286
287 FD_ZERO(&rfds);
288 // if output queue is empty
289 if (0 == write_pout.size)
290 {
291 FD_SET(STDIN_FILENO, &rfds);
292
293 }
294 if (0 == write_std.size)
295 {
296 FD_SET(fdpin, &rfds);
297 maxfd = fdpin;
298 }
299 FD_ZERO(&wfds);
300 // if there is something to write
301 if (0 < write_std.size)
302 {
303 FD_SET(STDOUT_FILENO, &wfds);
304 maxfd = MAX(maxfd, STDOUT_FILENO);
305 }
306
307 if (0 < write_pout.size)
308 {
309 FD_SET(fdpout, &wfds);
310 maxfd = MAX(maxfd, fdpout);
311 }
312
313 retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv);
314
315 if (-1 == retval && EINTR == errno)
316 {
317 continue;
318 }
319 if (0 > retval)
320 {
321 fprintf(stderr, "select failed: %s\n", strerror(errno));
322 exit(1);
323 }
324
325 if (FD_ISSET(STDOUT_FILENO, &wfds))
326 {
327 ret = write(STDOUT_FILENO, write_std.buf + write_std.pos,
328 write_std.size - write_std.pos);
329
330 if (0 > ret)
331 {
332 closeprog = 1;
333 fprintf(stderr, "Write ERROR to STDOUT\n");
334 exit(1);
335 }
336 else
337 {
338 write_std.pos += ret;
339 // check if finished
340 if (write_std.pos == write_std.size)
341 {
342 write_std.pos = 0;
343 write_std.size = 0;
344 }
345 }
346 }
347
348 if (FD_ISSET(fdpout, &wfds))
349 {
350 ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size
351 - write_pout.pos);
352
353 if (0 > ret)
354 {
355 closeprog = 1;
356 fprintf(stderr, "Write ERROR to fdpout\n");
357 }
358 else
359 {
360 write_pout.pos += ret;
361 // check if finished
362 if (write_pout.pos == write_pout.size)
363 {
364 write_pout.pos = 0;
365 write_pout.size = 0;
366 }
367 }
368 }
369
370 if (FD_ISSET(STDIN_FILENO, &rfds))
371 {
372 readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf));
373
374 if (0 > readsize)
375 {
376 closeprog = 1;
377 fprintf(stderr, "Read ERROR to STDIN_FILENO\n");
378 }
379 else if (0 < readsize)
380 {
381 GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize,
382 GNUNET_NO, GNUNET_NO);
383
384 }
385 else
386 {
387 //eof
388 closeprog = 1;
389 }
390 }
391
392 if (FD_ISSET(fdpin, &rfds))
393 {
394 readsize = read(fdpin, readbuf, sizeof(readbuf));
395
396 if (0 > readsize)
397 {
398 closeprog = 1;
399 fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno));
400 closeprog = 1;
401 }
402 else if (0 < readsize)
403 {
404 GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize,
405 GNUNET_NO, GNUNET_NO);
406
407 }
408 else
409 {
410 //eof
411 closeprog = 1;
412 }
413 }
414
415 }
416
417 //clean up
418 fclose(fpout);
419 fclose(fpin);
420
421 if (1 == first)
422 {
423 unlink(FIFO_FILE1);
424 unlink(FIFO_FILE2);
425 }
426
427 return (0);
428}
diff --git a/src/transport/wlan/loopback_helper.h b/src/transport/wlan/loopback_helper.h
new file mode 100644
index 000000000..7c9fd5d07
--- /dev/null
+++ b/src/transport/wlan/loopback_helper.h
@@ -0,0 +1,20 @@
1/*
2 * loopback_helper.h
3 *
4 * Created on: 28.03.2011
5 * Author: David Brodski
6 */
7
8#ifndef LOOPBACK_HELPER_H_
9#define LOOPBACK_HELPER_H_
10
11//static void sigfunc(int sig);
12
13//static void stdin_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr);
14
15//static void file_in_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr);
16
17int
18testmode(int argc, char *argv[]);
19
20#endif /* LOOPBACK_HELPER_H_ */
diff --git a/src/transport/wlan/radiotap-parser.c b/src/transport/wlan/radiotap-parser.c
new file mode 100644
index 000000000..46ea6d542
--- /dev/null
+++ b/src/transport/wlan/radiotap-parser.c
@@ -0,0 +1,251 @@
1 /*
2 * Copyright (c) 2007, 2008, Andy Green <andy@warmcat.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19#include <sys/types.h>
20#include <stdio.h>
21#include <errno.h>
22
23#include "radiotap-parser.h"
24
25
26/*
27 * Radiotap header iteration
28 * implemented in src/radiotap-parser.c
29 *
30 * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator
31 * struct ieee80211_radiotap_iterator (no need to init the struct beforehand)
32 * then loop calling __ieee80211_radiotap_iterator_next()... it returns -1
33 * if there are no more args in the header, or the next argument type index
34 * that is present. The iterator's this_arg member points to the start of the
35 * argument associated with the current argument index that is present,
36 * which can be found in the iterator's this_arg_index member. This arg
37 * index corresponds to the IEEE80211_RADIOTAP_... defines.
38 */
39
40
41int ieee80211_radiotap_iterator_init(
42 struct ieee80211_radiotap_iterator * iterator,
43 struct ieee80211_radiotap_header * radiotap_header,
44 int max_length)
45{
46 if(iterator == NULL)
47 return (-EINVAL);
48
49 if(radiotap_header == NULL)
50 return (-EINVAL);
51 /* Linux only supports version 0 radiotap format */
52
53 if (radiotap_header->it_version)
54 return (-EINVAL);
55
56 /* sanity check for allowed length and radiotap length field */
57
58 if (max_length < (le16_to_cpu(radiotap_header->it_len)))
59 return (-EINVAL);
60
61 iterator->rtheader = radiotap_header;
62 iterator->max_length = le16_to_cpu(radiotap_header->it_len);
63 iterator->arg_index = 0;
64 iterator->bitmap_shifter = le32_to_cpu(radiotap_header->it_present);
65 iterator->arg = ((u8 *)radiotap_header) +
66 sizeof (struct ieee80211_radiotap_header);
67 iterator->this_arg = 0;
68
69 /* find payload start allowing for extended bitmap(s) */
70
71 if (unlikely(iterator->bitmap_shifter &
72 IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) {
73 while (le32_to_cpu(*((u32 *)iterator->arg)) &
74 IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK) {
75 iterator->arg += sizeof (u32);
76
77 /*
78 * check for insanity where the present bitmaps
79 * keep claiming to extend up to or even beyond the
80 * stated radiotap header length
81 */
82
83 if ((((void*)iterator->arg) - ((void*)iterator->rtheader)) >
84 iterator->max_length)
85 return (-EINVAL);
86
87 }
88
89 iterator->arg += sizeof (u32);
90
91 /*
92 * no need to check again for blowing past stated radiotap
93 * header length, becuase ieee80211_radiotap_iterator_next
94 * checks it before it is dereferenced
95 */
96
97 }
98
99 /* we are all initialized happily */
100
101 return (0);
102}
103
104
105/**
106 * ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg
107 * @iterator: radiotap_iterator to move to next arg (if any)
108 *
109 * Returns: next present arg index on success or negative if no more or error
110 *
111 * This function returns the next radiotap arg index (IEEE80211_RADIOTAP_...)
112 * and sets iterator->this_arg to point to the payload for the arg. It takes
113 * care of alignment handling and extended present fields. interator->this_arg
114 * can be changed by the caller. The args pointed to are in little-endian
115 * format.
116 */
117
118int ieee80211_radiotap_iterator_next(
119 struct ieee80211_radiotap_iterator * iterator)
120{
121
122 /*
123 * small length lookup table for all radiotap types we heard of
124 * starting from b0 in the bitmap, so we can walk the payload
125 * area of the radiotap header
126 *
127 * There is a requirement to pad args, so that args
128 * of a given length must begin at a boundary of that length
129 * -- but note that compound args are allowed (eg, 2 x u16
130 * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not
131 * a reliable indicator of alignment requirement.
132 *
133 * upper nybble: content alignment for arg
134 * lower nybble: content length for arg
135 */
136
137 static const u8 rt_sizes[] = {
138 [IEEE80211_RADIOTAP_TSFT] = 0x88,
139 [IEEE80211_RADIOTAP_FLAGS] = 0x11,
140 [IEEE80211_RADIOTAP_RATE] = 0x11,
141 [IEEE80211_RADIOTAP_CHANNEL] = 0x24,
142 [IEEE80211_RADIOTAP_FHSS] = 0x22,
143 [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 0x11,
144 [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 0x11,
145 [IEEE80211_RADIOTAP_LOCK_QUALITY] = 0x22,
146 [IEEE80211_RADIOTAP_TX_ATTENUATION] = 0x22,
147 [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 0x22,
148 [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11,
149 [IEEE80211_RADIOTAP_ANTENNA] = 0x11,
150 [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11,
151 [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11,
152 [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22,
153 [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
154 [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11,
155 [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11
156 /*
157 * add more here as they are defined in
158 * include/net/ieee80211_radiotap.h
159 */
160 };
161
162 /*
163 * for every radiotap entry we can at
164 * least skip (by knowing the length)...
165 */
166
167 while (iterator->arg_index < (int)sizeof (rt_sizes)) {
168 int hit = 0;
169
170 if (!(iterator->bitmap_shifter & 1))
171 goto next_entry; /* arg not present */
172
173 /*
174 * arg is present, account for alignment padding
175 * 8-bit args can be at any alignment
176 * 16-bit args must start on 16-bit boundary
177 * 32-bit args must start on 32-bit boundary
178 * 64-bit args must start on 64-bit boundary
179 *
180 * note that total arg size can differ from alignment of
181 * elements inside arg, so we use upper nybble of length
182 * table to base alignment on
183 *
184 * also note: these alignments are ** relative to the
185 * start of the radiotap header **. There is no guarantee
186 * that the radiotap header itself is aligned on any
187 * kind of boundary.
188 */
189
190 if ((((void*)iterator->arg)-((void*)iterator->rtheader)) &
191 ((rt_sizes[iterator->arg_index] >> 4) - 1))
192 iterator->arg_index +=
193 (rt_sizes[iterator->arg_index] >> 4) -
194 ((((void*)iterator->arg) -
195 ((void*)iterator->rtheader)) &
196 ((rt_sizes[iterator->arg_index] >> 4) - 1));
197
198 /*
199 * this is what we will return to user, but we need to
200 * move on first so next call has something fresh to test
201 */
202
203 iterator->this_arg_index = iterator->arg_index;
204 iterator->this_arg = iterator->arg;
205 hit = 1;
206
207 /* internally move on the size of this arg */
208
209 iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
210
211 /*
212 * check for insanity where we are given a bitmap that
213 * claims to have more arg content than the length of the
214 * radiotap section. We will normally end up equalling this
215 * max_length on the last arg, never exceeding it.
216 */
217
218 if ((((void*)iterator->arg) - ((void*)iterator->rtheader)) >
219 iterator->max_length)
220 return (-EINVAL);
221
222 next_entry:
223
224 iterator->arg_index++;
225 if (unlikely((iterator->arg_index & 31) == 0)) {
226 /* completed current u32 bitmap */
227 if (iterator->bitmap_shifter & 1) {
228 /* b31 was set, there is more */
229 /* move to next u32 bitmap */
230 iterator->bitmap_shifter = le32_to_cpu(
231 *iterator->next_bitmap);
232 iterator->next_bitmap++;
233 } else {
234 /* no more bitmaps: end */
235 iterator->arg_index = sizeof (rt_sizes);
236 }
237 } else { /* just try the next bit */
238 iterator->bitmap_shifter >>= 1;
239 }
240
241 /* if we found a valid arg earlier, return it now */
242
243 if (hit)
244 return (iterator->this_arg_index);
245
246 }
247
248 /* we don't know how to handle any more args, we're done */
249
250 return (-1);
251}
diff --git a/src/transport/wlan/radiotap-parser.h b/src/transport/wlan/radiotap-parser.h
new file mode 100644
index 000000000..b36037369
--- /dev/null
+++ b/src/transport/wlan/radiotap-parser.h
@@ -0,0 +1,78 @@
1/*
2 * Copyright (c) 2007, 2008, Andy Green <andy@warmcat.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18
19#define __user
20#include "byteorder.h"
21#include <stdint.h>
22
23typedef uint64_t u64;
24typedef uint32_t u32;
25typedef uint16_t u16;
26typedef uint8_t u8;
27
28#ifndef unlikely
29#define unlikely(x) (x)
30#endif
31
32#include "ieee80211_radiotap.h"
33
34
35/*
36 * Radiotap header iteration
37 * implemented in src/radiotap-parser.c
38 *
39 * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator
40 * struct ieee80211_radiotap_iterator (no need to init the struct beforehand)
41 * then loop calling __ieee80211_radiotap_iterator_next()... it returns -1
42 * if there are no more args in the header, or the next argument type index
43 * that is present. The iterator's this_arg member points to the start of the
44 * argument associated with the current argument index that is present,
45 * which can be found in the iterator's this_arg_index member. This arg
46 * index corresponds to the IEEE80211_RADIOTAP_... defines.
47 */
48/**
49 * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args
50 * @rtheader: pointer to the radiotap header we are walking through
51 * @max_length: length of radiotap header in cpu byte ordering
52 * @this_arg_index: IEEE80211_RADIOTAP_... index of current arg
53 * @this_arg: pointer to current radiotap arg
54 * @arg_index: internal next argument index
55 * @arg: internal next argument pointer
56 * @next_bitmap: internal pointer to next present u32
57 * @bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present
58 */
59
60struct ieee80211_radiotap_iterator {
61 struct ieee80211_radiotap_header *rtheader;
62 int max_length;
63 int this_arg_index;
64 u8 * this_arg;
65
66 int arg_index;
67 u8 * arg;
68 u32 *next_bitmap;
69 u32 bitmap_shifter;
70};
71
72int ieee80211_radiotap_iterator_init(
73 struct ieee80211_radiotap_iterator * iterator,
74 struct ieee80211_radiotap_header * radiotap_header,
75 int max_length);
76
77int ieee80211_radiotap_iterator_next(
78 struct ieee80211_radiotap_iterator * iterator);