diff options
-rw-r--r-- | src/include/gnunet_protocols.h | 27 | ||||
-rw-r--r-- | src/transport/Makefile.am | 16 | ||||
-rw-r--r-- | src/transport/gnunet-transport-wlan-helper.c | 5 | ||||
-rw-r--r-- | src/transport/gnunet-transport-wlan-helper.h | 269 | ||||
-rw-r--r-- | src/transport/ieee80211_radiotap.h | 265 | ||||
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 532 |
6 files changed, 843 insertions, 271 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 8b1d630a5..b5d743114 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -643,6 +643,33 @@ extern "C" | |||
643 | */ | 643 | */ |
644 | #define GNUNET_MESSAGE_TYPE_VPN_HELPER 185 | 644 | #define GNUNET_MESSAGE_TYPE_VPN_HELPER 185 |
645 | 645 | ||
646 | |||
647 | |||
648 | /** | ||
649 | * Type of messages between the gnunet-wlan-helper and the daemon | ||
650 | * | ||
651 | * data messages | ||
652 | */ | ||
653 | |||
654 | #define GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA 195 | ||
655 | |||
656 | /** | ||
657 | * Control messages between the gnunet-wlan-helper and the daemon | ||
658 | */ | ||
659 | |||
660 | #define GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL 196 | ||
661 | |||
662 | /** | ||
663 | * Type of messages for advertisement over wlan | ||
664 | */ | ||
665 | #define GNUNET_MESSAGE_TYPE_WLAN_HELPER_ADVERTISEMENT 196 | ||
666 | |||
667 | /** | ||
668 | * Type of messages for wlan | ||
669 | */ | ||
670 | |||
671 | |||
672 | |||
646 | /** | 673 | /** |
647 | * Type used to match 'all' message types. | 674 | * Type used to match 'all' message types. |
648 | */ | 675 | */ |
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index db5a76cfd..223f271ba 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -32,6 +32,7 @@ endif | |||
32 | if HAVE_PCAP | 32 | if HAVE_PCAP |
33 | if LINUX | 33 | if LINUX |
34 | WANBIN = gnunet-transport-wlan-helper | 34 | WANBIN = gnunet-transport-wlan-helper |
35 | WLAN_PLUGIN_LA = libgnunet_plugin_transport_wlan.la | ||
35 | endif | 36 | endif |
36 | endif | 37 | endif |
37 | 38 | ||
@@ -103,6 +104,7 @@ plugin_LTLIBRARIES = \ | |||
103 | libgnunet_plugin_transport_udp.la \ | 104 | libgnunet_plugin_transport_udp.la \ |
104 | $(HTTP_PLUGIN_LA) \ | 105 | $(HTTP_PLUGIN_LA) \ |
105 | $(HTTPS_PLUGIN_LA) \ | 106 | $(HTTPS_PLUGIN_LA) \ |
107 | $(WLAN_PLUGIN_LA) \ | ||
106 | libgnunet_plugin_transport_template.la | 108 | libgnunet_plugin_transport_template.la |
107 | # TODO: add nat, etc. | 109 | # TODO: add nat, etc. |
108 | 110 | ||
@@ -123,6 +125,20 @@ libgnunet_plugin_transport_template_la_LIBADD = \ | |||
123 | libgnunet_plugin_transport_template_la_LDFLAGS = \ | 125 | libgnunet_plugin_transport_template_la_LDFLAGS = \ |
124 | $(GN_PLUGIN_LDFLAGS) | 126 | $(GN_PLUGIN_LDFLAGS) |
125 | 127 | ||
128 | if HAVE_PCAP | ||
129 | if LINUX | ||
130 | libgnunet_plugin_transport_wlan_la_SOURCES = \ | ||
131 | plugin_transport_wlan.c | ||
132 | libgnunet_plugin_transport_wlan_la_LIBADD = \ | ||
133 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
134 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
135 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ | ||
136 | $(top_builddir)/src/util/libgnunetutil.la | ||
137 | libgnunet_plugin_transport_wlan_la_LDFLAGS = \ | ||
138 | $(GN_PLUGIN_LDFLAGS) | ||
139 | endif | ||
140 | endif | ||
141 | |||
126 | libgnunet_plugin_transport_udp_la_SOURCES = \ | 142 | libgnunet_plugin_transport_udp_la_SOURCES = \ |
127 | plugin_transport_udp.c | 143 | plugin_transport_udp.c |
128 | libgnunet_plugin_transport_udp_la_LIBADD = \ | 144 | libgnunet_plugin_transport_udp_la_LIBADD = \ |
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index 660103fb1..af49f9833 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c | |||
@@ -27,8 +27,9 @@ | |||
27 | * This program serves as the mediator between the wlan interface and | 27 | * This program serves as the mediator between the wlan interface and |
28 | * gnunet | 28 | * gnunet |
29 | */ | 29 | */ |
30 | |||
31 | #include "gnunet-transport-wlan-helper.h" | 30 | #include "gnunet-transport-wlan-helper.h" |
31 | #include "ieee80211_radiotap.h" | ||
32 | |||
32 | #include <pcap.h> | 33 | #include <pcap.h> |
33 | 34 | ||
34 | //#include "radiotap.h" | 35 | //#include "radiotap.h" |
@@ -645,7 +646,7 @@ main(int argc, char *argv[]) | |||
645 | memcpy(pu8, u8aIeeeHeader, sizeof (u8aIeeeHeader)); | 646 | memcpy(pu8, u8aIeeeHeader, sizeof (u8aIeeeHeader)); |
646 | pu8 += sizeof (u8aIeeeHeader); | 647 | pu8 += sizeof (u8aIeeeHeader); |
647 | 648 | ||
648 | pu8 += sprintf((char *)pu8, | 649 | pu8 += sprintf((char *)u8aSendBuffer, |
649 | "Packetspammer %02d" | 650 | "Packetspammer %02d" |
650 | "broadcast packet" | 651 | "broadcast packet" |
651 | "#%05d -- :-D --%s ----", | 652 | "#%05d -- :-D --%s ----", |
diff --git a/src/transport/gnunet-transport-wlan-helper.h b/src/transport/gnunet-transport-wlan-helper.h index 84f7fc9a8..757e3dd2c 100644 --- a/src/transport/gnunet-transport-wlan-helper.h +++ b/src/transport/gnunet-transport-wlan-helper.h | |||
@@ -59,275 +59,6 @@ typedef u32 __le32; | |||
59 | #endif /* gnunet_wlan_H */ | 59 | #endif /* gnunet_wlan_H */ |
60 | 60 | ||
61 | 61 | ||
62 | /* | ||
63 | * Copyright (c) 2003, 2004 David Young. All rights reserved. | ||
64 | * | ||
65 | * Redistribution and use in source and binary forms, with or without | ||
66 | * modification, are permitted provided that the following conditions | ||
67 | * are met: | ||
68 | * 1. Redistributions of source code must retain the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer. | ||
70 | * 2. Redistributions in binary form must reproduce the above copyright | ||
71 | * notice, this list of conditions and the following disclaimer in the | ||
72 | * documentation and/or other materials provided with the distribution. | ||
73 | * 3. The name of David Young may not be used to endorse or promote | ||
74 | * products derived from this software without specific prior | ||
75 | * written permission. | ||
76 | * | ||
77 | * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY | ||
78 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
79 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
80 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID | ||
81 | * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
82 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
83 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
84 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
85 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
86 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
87 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | ||
88 | * OF SUCH DAMAGE. | ||
89 | */ | ||
90 | |||
91 | /* | ||
92 | * Modifications to fit into the linux IEEE 802.11 stack, | ||
93 | * Mike Kershaw (dragorn@kismetwireless.net) | ||
94 | */ | ||
95 | |||
96 | #ifndef IEEE80211RADIOTAP_H | ||
97 | #define IEEE80211RADIOTAP_H | ||
98 | |||
99 | #include <linux/if_ether.h> | ||
100 | #include <linux/kernel.h> | ||
101 | //#include <asm/unaligned.h> | ||
102 | |||
103 | /* Base version of the radiotap packet header data */ | ||
104 | #define PKTHDR_RADIOTAP_VERSION 0 | ||
105 | |||
106 | /* A generic radio capture format is desirable. There is one for | ||
107 | * Linux, but it is neither rigidly defined (there were not even | ||
108 | * units given for some fields) nor easily extensible. | ||
109 | * | ||
110 | * I suggest the following extensible radio capture format. It is | ||
111 | * based on a bitmap indicating which fields are present. | ||
112 | * | ||
113 | * I am trying to describe precisely what the application programmer | ||
114 | * should expect in the following, and for that reason I tell the | ||
115 | * units and origin of each measurement (where it applies), or else I | ||
116 | * use sufficiently weaselly language ("is a monotonically nondecreasing | ||
117 | * function of...") that I cannot set false expectations for lawyerly | ||
118 | * readers. | ||
119 | */ | ||
120 | |||
121 | /* | ||
122 | * The radio capture header precedes the 802.11 header. | ||
123 | * All data in the header is little endian on all platforms. | ||
124 | */ | ||
125 | struct ieee80211_radiotap_header { | ||
126 | u8 it_version; /* Version 0. Only increases | ||
127 | * for drastic changes, | ||
128 | * introduction of compatible | ||
129 | * new fields does not count. | ||
130 | */ | ||
131 | u8 it_pad; | ||
132 | __le16 it_len; /* length of the whole | ||
133 | * header in bytes, including | ||
134 | * it_version, it_pad, | ||
135 | * it_len, and data fields. | ||
136 | */ | ||
137 | __le32 it_present; /* A bitmap telling which | ||
138 | * fields are present. Set bit 31 | ||
139 | * (0x80000000) to extend the | ||
140 | * bitmap by another 32 bits. | ||
141 | * Additional extensions are made | ||
142 | * by setting bit 31. | ||
143 | */ | ||
144 | } __packed; | ||
145 | |||
146 | /* Name Data type Units | ||
147 | * ---- --------- ----- | ||
148 | * | ||
149 | * IEEE80211_RADIOTAP_TSFT __le64 microseconds | ||
150 | * | ||
151 | * Value in microseconds of the MAC's 64-bit 802.11 Time | ||
152 | * Synchronization Function timer when the first bit of the | ||
153 | * MPDU arrived at the MAC. For received frames, only. | ||
154 | * | ||
155 | * IEEE80211_RADIOTAP_CHANNEL 2 x __le16 MHz, bitmap | ||
156 | * | ||
157 | * Tx/Rx frequency in MHz, followed by flags (see below). | ||
158 | * | ||
159 | * IEEE80211_RADIOTAP_FHSS __le16 see below | ||
160 | * | ||
161 | * For frequency-hopping radios, the hop set (first byte) | ||
162 | * and pattern (second byte). | ||
163 | * | ||
164 | * IEEE80211_RADIOTAP_RATE u8 500kb/s | ||
165 | * | ||
166 | * Tx/Rx data rate | ||
167 | * | ||
168 | * IEEE80211_RADIOTAP_DBM_ANTSIGNAL s8 decibels from | ||
169 | * one milliwatt (dBm) | ||
170 | * | ||
171 | * RF signal power at the antenna, decibel difference from | ||
172 | * one milliwatt. | ||
173 | * | ||
174 | * IEEE80211_RADIOTAP_DBM_ANTNOISE s8 decibels from | ||
175 | * one milliwatt (dBm) | ||
176 | * | ||
177 | * RF noise power at the antenna, decibel difference from one | ||
178 | * milliwatt. | ||
179 | * | ||
180 | * IEEE80211_RADIOTAP_DB_ANTSIGNAL u8 decibel (dB) | ||
181 | * | ||
182 | * RF signal power at the antenna, decibel difference from an | ||
183 | * arbitrary, fixed reference. | ||
184 | * | ||
185 | * IEEE80211_RADIOTAP_DB_ANTNOISE u8 decibel (dB) | ||
186 | * | ||
187 | * RF noise power at the antenna, decibel difference from an | ||
188 | * arbitrary, fixed reference point. | ||
189 | * | ||
190 | * IEEE80211_RADIOTAP_LOCK_QUALITY __le16 unitless | ||
191 | * | ||
192 | * Quality of Barker code lock. Unitless. Monotonically | ||
193 | * nondecreasing with "better" lock strength. Called "Signal | ||
194 | * Quality" in datasheets. (Is there a standard way to measure | ||
195 | * this?) | ||
196 | * | ||
197 | * IEEE80211_RADIOTAP_TX_ATTENUATION __le16 unitless | ||
198 | * | ||
199 | * Transmit power expressed as unitless distance from max | ||
200 | * power set at factory calibration. 0 is max power. | ||
201 | * Monotonically nondecreasing with lower power levels. | ||
202 | * | ||
203 | * IEEE80211_RADIOTAP_DB_TX_ATTENUATION __le16 decibels (dB) | ||
204 | * | ||
205 | * Transmit power expressed as decibel distance from max power | ||
206 | * set at factory calibration. 0 is max power. Monotonically | ||
207 | * nondecreasing with lower power levels. | ||
208 | * | ||
209 | * IEEE80211_RADIOTAP_DBM_TX_POWER s8 decibels from | ||
210 | * one milliwatt (dBm) | ||
211 | * | ||
212 | * Transmit power expressed as dBm (decibels from a 1 milliwatt | ||
213 | * reference). This is the absolute power level measured at | ||
214 | * the antenna port. | ||
215 | * | ||
216 | * IEEE80211_RADIOTAP_FLAGS u8 bitmap | ||
217 | * | ||
218 | * Properties of transmitted and received frames. See flags | ||
219 | * defined below. | ||
220 | * | ||
221 | * IEEE80211_RADIOTAP_ANTENNA u8 antenna index | ||
222 | * | ||
223 | * Unitless indication of the Rx/Tx antenna for this packet. | ||
224 | * The first antenna is antenna 0. | ||
225 | * | ||
226 | * IEEE80211_RADIOTAP_RX_FLAGS __le16 bitmap | ||
227 | * | ||
228 | * Properties of received frames. See flags defined below. | ||
229 | * | ||
230 | * IEEE80211_RADIOTAP_TX_FLAGS __le16 bitmap | ||
231 | * | ||
232 | * Properties of transmitted frames. See flags defined below. | ||
233 | * | ||
234 | * IEEE80211_RADIOTAP_RTS_RETRIES u8 data | ||
235 | * | ||
236 | * Number of rts retries a transmitted frame used. | ||
237 | * | ||
238 | * IEEE80211_RADIOTAP_DATA_RETRIES u8 data | ||
239 | * | ||
240 | * Number of unicast retries a transmitted frame used. | ||
241 | * | ||
242 | */ | ||
243 | enum ieee80211_radiotap_type { | ||
244 | IEEE80211_RADIOTAP_TSFT = 0, | ||
245 | IEEE80211_RADIOTAP_FLAGS = 1, | ||
246 | IEEE80211_RADIOTAP_RATE = 2, | ||
247 | IEEE80211_RADIOTAP_CHANNEL = 3, | ||
248 | IEEE80211_RADIOTAP_FHSS = 4, | ||
249 | IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5, | ||
250 | IEEE80211_RADIOTAP_DBM_ANTNOISE = 6, | ||
251 | IEEE80211_RADIOTAP_LOCK_QUALITY = 7, | ||
252 | IEEE80211_RADIOTAP_TX_ATTENUATION = 8, | ||
253 | IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9, | ||
254 | IEEE80211_RADIOTAP_DBM_TX_POWER = 10, | ||
255 | IEEE80211_RADIOTAP_ANTENNA = 11, | ||
256 | IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12, | ||
257 | IEEE80211_RADIOTAP_DB_ANTNOISE = 13, | ||
258 | IEEE80211_RADIOTAP_RX_FLAGS = 14, | ||
259 | IEEE80211_RADIOTAP_TX_FLAGS = 15, | ||
260 | IEEE80211_RADIOTAP_RTS_RETRIES = 16, | ||
261 | IEEE80211_RADIOTAP_DATA_RETRIES = 17, | ||
262 | |||
263 | /* valid in every it_present bitmap, even vendor namespaces */ | ||
264 | IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE = 29, | ||
265 | IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30, | ||
266 | IEEE80211_RADIOTAP_EXT = 31 | ||
267 | }; | ||
268 | |||
269 | /* Channel flags. */ | ||
270 | #define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */ | ||
271 | #define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */ | ||
272 | #define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */ | ||
273 | #define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */ | ||
274 | #define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */ | ||
275 | #define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */ | ||
276 | #define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */ | ||
277 | #define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */ | ||
278 | |||
279 | /* For IEEE80211_RADIOTAP_FLAGS */ | ||
280 | #define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received | ||
281 | * during CFP | ||
282 | */ | ||
283 | #define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received | ||
284 | * with short | ||
285 | * preamble | ||
286 | */ | ||
287 | #define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received | ||
288 | * with WEP encryption | ||
289 | */ | ||
290 | #define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received | ||
291 | * with fragmentation | ||
292 | */ | ||
293 | #define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */ | ||
294 | #define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between | ||
295 | * 802.11 header and payload | ||
296 | * (to 32-bit boundary) | ||
297 | */ | ||
298 | #define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* bad FCS */ | ||
299 | |||
300 | /* For IEEE80211_RADIOTAP_RX_FLAGS */ | ||
301 | #define IEEE80211_RADIOTAP_F_RX_BADPLCP 0x0002 /* frame has bad PLCP */ | ||
302 | |||
303 | /* For IEEE80211_RADIOTAP_TX_FLAGS */ | ||
304 | #define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive | ||
305 | * retries */ | ||
306 | #define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */ | ||
307 | #define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */ | ||
308 | |||
309 | /* Ugly macro to convert literal channel numbers into their mhz equivalents | ||
310 | * There are certianly some conditions that will break this (like feeding it '30') | ||
311 | * but they shouldn't arise since nothing talks on channel 30. */ | ||
312 | #define ieee80211chan2mhz(x) \ | ||
313 | (((x) <= 14) ? \ | ||
314 | (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \ | ||
315 | ((x) + 1000) * 5) | ||
316 | |||
317 | #if BROKEN | ||
318 | /* helpers */ | ||
319 | static inline int ieee80211_get_radiotap_len(unsigned char *data) | ||
320 | { | ||
321 | struct ieee80211_radiotap_header *hdr = | ||
322 | (struct ieee80211_radiotap_header *)data; | ||
323 | |||
324 | return get_unaligned_le16(&hdr->it_len); | ||
325 | } | ||
326 | #endif | ||
327 | #endif /* IEEE80211_RADIOTAP_H */ | ||
328 | |||
329 | |||
330 | |||
331 | /* Radiotap header iteration | 62 | /* Radiotap header iteration |
332 | * implemented in net/wireless/radiotap.c | 63 | * implemented in net/wireless/radiotap.c |
333 | * docs in Documentation/networking/radiotap-headers.txt | 64 | * docs in Documentation/networking/radiotap-headers.txt |
diff --git a/src/transport/ieee80211_radiotap.h b/src/transport/ieee80211_radiotap.h new file mode 100644 index 000000000..bfcc2180c --- /dev/null +++ b/src/transport/ieee80211_radiotap.h | |||
@@ -0,0 +1,265 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2003, 2004 David Young. All rights reserved. | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions | ||
6 | * are met: | ||
7 | * 1. Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * 2. Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * 3. The name of David Young may not be used to endorse or promote | ||
13 | * products derived from this software without specific prior | ||
14 | * written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
18 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID | ||
20 | * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
22 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | ||
27 | * OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | /* | ||
31 | * Modifications to fit into the linux IEEE 802.11 stack, | ||
32 | * Mike Kershaw (dragorn@kismetwireless.net) | ||
33 | */ | ||
34 | |||
35 | #ifndef IEEE80211RADIOTAP_H | ||
36 | #define IEEE80211RADIOTAP_H | ||
37 | |||
38 | #include <linux/if_ether.h> | ||
39 | #include <linux/kernel.h> | ||
40 | //#include <asm/unaligned.h> | ||
41 | |||
42 | /* Base version of the radiotap packet header data */ | ||
43 | #define PKTHDR_RADIOTAP_VERSION 0 | ||
44 | |||
45 | /* A generic radio capture format is desirable. There is one for | ||
46 | * Linux, but it is neither rigidly defined (there were not even | ||
47 | * units given for some fields) nor easily extensible. | ||
48 | * | ||
49 | * I suggest the following extensible radio capture format. It is | ||
50 | * based on a bitmap indicating which fields are present. | ||
51 | * | ||
52 | * I am trying to describe precisely what the application programmer | ||
53 | * should expect in the following, and for that reason I tell the | ||
54 | * units and origin of each measurement (where it applies), or else I | ||
55 | * use sufficiently weaselly language ("is a monotonically nondecreasing | ||
56 | * function of...") that I cannot set false expectations for lawyerly | ||
57 | * readers. | ||
58 | */ | ||
59 | |||
60 | /* | ||
61 | * The radio capture header precedes the 802.11 header. | ||
62 | * All data in the header is little endian on all platforms. | ||
63 | */ | ||
64 | struct ieee80211_radiotap_header { | ||
65 | u8 it_version; /* Version 0. Only increases | ||
66 | * for drastic changes, | ||
67 | * introduction of compatible | ||
68 | * new fields does not count. | ||
69 | */ | ||
70 | u8 it_pad; | ||
71 | __le16 it_len; /* length of the whole | ||
72 | * header in bytes, including | ||
73 | * it_version, it_pad, | ||
74 | * it_len, and data fields. | ||
75 | */ | ||
76 | __le32 it_present; /* A bitmap telling which | ||
77 | * fields are present. Set bit 31 | ||
78 | * (0x80000000) to extend the | ||
79 | * bitmap by another 32 bits. | ||
80 | * Additional extensions are made | ||
81 | * by setting bit 31. | ||
82 | */ | ||
83 | } __packed; | ||
84 | |||
85 | /* Name Data type Units | ||
86 | * ---- --------- ----- | ||
87 | * | ||
88 | * IEEE80211_RADIOTAP_TSFT __le64 microseconds | ||
89 | * | ||
90 | * Value in microseconds of the MAC's 64-bit 802.11 Time | ||
91 | * Synchronization Function timer when the first bit of the | ||
92 | * MPDU arrived at the MAC. For received frames, only. | ||
93 | * | ||
94 | * IEEE80211_RADIOTAP_CHANNEL 2 x __le16 MHz, bitmap | ||
95 | * | ||
96 | * Tx/Rx frequency in MHz, followed by flags (see below). | ||
97 | * | ||
98 | * IEEE80211_RADIOTAP_FHSS __le16 see below | ||
99 | * | ||
100 | * For frequency-hopping radios, the hop set (first byte) | ||
101 | * and pattern (second byte). | ||
102 | * | ||
103 | * IEEE80211_RADIOTAP_RATE u8 500kb/s | ||
104 | * | ||
105 | * Tx/Rx data rate | ||
106 | * | ||
107 | * IEEE80211_RADIOTAP_DBM_ANTSIGNAL s8 decibels from | ||
108 | * one milliwatt (dBm) | ||
109 | * | ||
110 | * RF signal power at the antenna, decibel difference from | ||
111 | * one milliwatt. | ||
112 | * | ||
113 | * IEEE80211_RADIOTAP_DBM_ANTNOISE s8 decibels from | ||
114 | * one milliwatt (dBm) | ||
115 | * | ||
116 | * RF noise power at the antenna, decibel difference from one | ||
117 | * milliwatt. | ||
118 | * | ||
119 | * IEEE80211_RADIOTAP_DB_ANTSIGNAL u8 decibel (dB) | ||
120 | * | ||
121 | * RF signal power at the antenna, decibel difference from an | ||
122 | * arbitrary, fixed reference. | ||
123 | * | ||
124 | * IEEE80211_RADIOTAP_DB_ANTNOISE u8 decibel (dB) | ||
125 | * | ||
126 | * RF noise power at the antenna, decibel difference from an | ||
127 | * arbitrary, fixed reference point. | ||
128 | * | ||
129 | * IEEE80211_RADIOTAP_LOCK_QUALITY __le16 unitless | ||
130 | * | ||
131 | * Quality of Barker code lock. Unitless. Monotonically | ||
132 | * nondecreasing with "better" lock strength. Called "Signal | ||
133 | * Quality" in datasheets. (Is there a standard way to measure | ||
134 | * this?) | ||
135 | * | ||
136 | * IEEE80211_RADIOTAP_TX_ATTENUATION __le16 unitless | ||
137 | * | ||
138 | * Transmit power expressed as unitless distance from max | ||
139 | * power set at factory calibration. 0 is max power. | ||
140 | * Monotonically nondecreasing with lower power levels. | ||
141 | * | ||
142 | * IEEE80211_RADIOTAP_DB_TX_ATTENUATION __le16 decibels (dB) | ||
143 | * | ||
144 | * Transmit power expressed as decibel distance from max power | ||
145 | * set at factory calibration. 0 is max power. Monotonically | ||
146 | * nondecreasing with lower power levels. | ||
147 | * | ||
148 | * IEEE80211_RADIOTAP_DBM_TX_POWER s8 decibels from | ||
149 | * one milliwatt (dBm) | ||
150 | * | ||
151 | * Transmit power expressed as dBm (decibels from a 1 milliwatt | ||
152 | * reference). This is the absolute power level measured at | ||
153 | * the antenna port. | ||
154 | * | ||
155 | * IEEE80211_RADIOTAP_FLAGS u8 bitmap | ||
156 | * | ||
157 | * Properties of transmitted and received frames. See flags | ||
158 | * defined below. | ||
159 | * | ||
160 | * IEEE80211_RADIOTAP_ANTENNA u8 antenna index | ||
161 | * | ||
162 | * Unitless indication of the Rx/Tx antenna for this packet. | ||
163 | * The first antenna is antenna 0. | ||
164 | * | ||
165 | * IEEE80211_RADIOTAP_RX_FLAGS __le16 bitmap | ||
166 | * | ||
167 | * Properties of received frames. See flags defined below. | ||
168 | * | ||
169 | * IEEE80211_RADIOTAP_TX_FLAGS __le16 bitmap | ||
170 | * | ||
171 | * Properties of transmitted frames. See flags defined below. | ||
172 | * | ||
173 | * IEEE80211_RADIOTAP_RTS_RETRIES u8 data | ||
174 | * | ||
175 | * Number of rts retries a transmitted frame used. | ||
176 | * | ||
177 | * IEEE80211_RADIOTAP_DATA_RETRIES u8 data | ||
178 | * | ||
179 | * Number of unicast retries a transmitted frame used. | ||
180 | * | ||
181 | */ | ||
182 | enum ieee80211_radiotap_type { | ||
183 | IEEE80211_RADIOTAP_TSFT = 0, | ||
184 | IEEE80211_RADIOTAP_FLAGS = 1, | ||
185 | IEEE80211_RADIOTAP_RATE = 2, | ||
186 | IEEE80211_RADIOTAP_CHANNEL = 3, | ||
187 | IEEE80211_RADIOTAP_FHSS = 4, | ||
188 | IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5, | ||
189 | IEEE80211_RADIOTAP_DBM_ANTNOISE = 6, | ||
190 | IEEE80211_RADIOTAP_LOCK_QUALITY = 7, | ||
191 | IEEE80211_RADIOTAP_TX_ATTENUATION = 8, | ||
192 | IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9, | ||
193 | IEEE80211_RADIOTAP_DBM_TX_POWER = 10, | ||
194 | IEEE80211_RADIOTAP_ANTENNA = 11, | ||
195 | IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12, | ||
196 | IEEE80211_RADIOTAP_DB_ANTNOISE = 13, | ||
197 | IEEE80211_RADIOTAP_RX_FLAGS = 14, | ||
198 | IEEE80211_RADIOTAP_TX_FLAGS = 15, | ||
199 | IEEE80211_RADIOTAP_RTS_RETRIES = 16, | ||
200 | IEEE80211_RADIOTAP_DATA_RETRIES = 17, | ||
201 | |||
202 | /* valid in every it_present bitmap, even vendor namespaces */ | ||
203 | IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE = 29, | ||
204 | IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30, | ||
205 | IEEE80211_RADIOTAP_EXT = 31 | ||
206 | }; | ||
207 | |||
208 | /* Channel flags. */ | ||
209 | #define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */ | ||
210 | #define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */ | ||
211 | #define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */ | ||
212 | #define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */ | ||
213 | #define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */ | ||
214 | #define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */ | ||
215 | #define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */ | ||
216 | #define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */ | ||
217 | |||
218 | /* For IEEE80211_RADIOTAP_FLAGS */ | ||
219 | #define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received | ||
220 | * during CFP | ||
221 | */ | ||
222 | #define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received | ||
223 | * with short | ||
224 | * preamble | ||
225 | */ | ||
226 | #define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received | ||
227 | * with WEP encryption | ||
228 | */ | ||
229 | #define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received | ||
230 | * with fragmentation | ||
231 | */ | ||
232 | #define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */ | ||
233 | #define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between | ||
234 | * 802.11 header and payload | ||
235 | * (to 32-bit boundary) | ||
236 | */ | ||
237 | #define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* bad FCS */ | ||
238 | |||
239 | /* For IEEE80211_RADIOTAP_RX_FLAGS */ | ||
240 | #define IEEE80211_RADIOTAP_F_RX_BADPLCP 0x0002 /* frame has bad PLCP */ | ||
241 | |||
242 | /* For IEEE80211_RADIOTAP_TX_FLAGS */ | ||
243 | #define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive | ||
244 | * retries */ | ||
245 | #define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */ | ||
246 | #define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */ | ||
247 | |||
248 | /* Ugly macro to convert literal channel numbers into their mhz equivalents | ||
249 | * There are certianly some conditions that will break this (like feeding it '30') | ||
250 | * but they shouldn't arise since nothing talks on channel 30. */ | ||
251 | #define ieee80211chan2mhz(x) \ | ||
252 | (((x) <= 14) ? \ | ||
253 | (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \ | ||
254 | ((x) + 1000) * 5) | ||
255 | |||
256 | /* helpers */ | ||
257 | static inline int ieee80211_get_radiotap_len(unsigned char *data) | ||
258 | { | ||
259 | struct ieee80211_radiotap_header *hdr = | ||
260 | (struct ieee80211_radiotap_header *)data; | ||
261 | |||
262 | return get_unaligned_le16(&hdr->it_len); | ||
263 | } | ||
264 | |||
265 | #endif /* IEEE80211_RADIOTAP_H */ | ||
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c new file mode 100644 index 000000000..824ebf12c --- /dev/null +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -0,0 +1,532 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
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 | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
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 | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file transport/plugin_transport_wlan.c | ||
23 | * @brief template for a new transport service | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_protocols.h" | ||
29 | #include "gnunet_connection_lib.h" | ||
30 | #include "gnunet_server_lib.h" | ||
31 | #include "gnunet_service_lib.h" | ||
32 | #include "gnunet_statistics_service.h" | ||
33 | #include "gnunet_transport_service.h" | ||
34 | #include "plugin_transport.h" | ||
35 | |||
36 | #define PROTOCOL_PREFIX "wlan" | ||
37 | |||
38 | #define DEBUG_wlan GNUNET_NO | ||
39 | |||
40 | static void | ||
41 | wlan_plugin_helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
42 | |||
43 | /** | ||
44 | * After how long do we expire an address that we | ||
45 | * learned from another peer if it is not reconfirmed | ||
46 | * by anyone? | ||
47 | */ | ||
48 | #define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6) | ||
49 | |||
50 | |||
51 | /** | ||
52 | * Encapsulation of all of the state of the plugin. | ||
53 | */ | ||
54 | struct Plugin; | ||
55 | |||
56 | |||
57 | /** | ||
58 | * Session handle for connections. | ||
59 | */ | ||
60 | struct Session | ||
61 | { | ||
62 | |||
63 | /** | ||
64 | * Stored in a linked list. | ||
65 | */ | ||
66 | struct Session *next; | ||
67 | |||
68 | /** | ||
69 | * Pointer to the global plugin struct. | ||
70 | */ | ||
71 | struct Plugin *plugin; | ||
72 | |||
73 | /** | ||
74 | * The client (used to identify this connection) | ||
75 | */ | ||
76 | /* void *client; */ | ||
77 | |||
78 | /** | ||
79 | * Continuation function to call once the transmission buffer | ||
80 | * has again space available. NULL if there is no | ||
81 | * continuation to call. | ||
82 | */ | ||
83 | GNUNET_TRANSPORT_TransmitContinuation transmit_cont; | ||
84 | |||
85 | /** | ||
86 | * Closure for transmit_cont. | ||
87 | */ | ||
88 | void *transmit_cont_cls; | ||
89 | |||
90 | /** | ||
91 | * To whom are we talking to (set to our identity | ||
92 | * if we are still waiting for the welcome message) | ||
93 | */ | ||
94 | struct GNUNET_PeerIdentity sender; | ||
95 | |||
96 | /** | ||
97 | * At what time did we reset last_received last? | ||
98 | */ | ||
99 | struct GNUNET_TIME_Absolute last_quota_update; | ||
100 | |||
101 | /** | ||
102 | * How many bytes have we received since the "last_quota_update" | ||
103 | * timestamp? | ||
104 | */ | ||
105 | uint64_t last_received; | ||
106 | |||
107 | /** | ||
108 | * Number of bytes per ms that this peer is allowed | ||
109 | * to send to us. | ||
110 | */ | ||
111 | uint32_t quota; | ||
112 | |||
113 | }; | ||
114 | |||
115 | /** | ||
116 | * Encapsulation of all of the state of the plugin. | ||
117 | */ | ||
118 | struct Plugin | ||
119 | { | ||
120 | /** | ||
121 | * Our environment. | ||
122 | */ | ||
123 | struct GNUNET_TRANSPORT_PluginEnvironment *env; | ||
124 | |||
125 | /** | ||
126 | * List of open sessions. | ||
127 | * TODO? | ||
128 | */ | ||
129 | struct Session *sessions; | ||
130 | |||
131 | /** | ||
132 | * encapsulation to the local wlan server prog | ||
133 | */ | ||
134 | |||
135 | struct GNUNET_SERVER_MessageStreamTokenizer * consoltoken; | ||
136 | |||
137 | /** | ||
138 | * encapsulation of the data | ||
139 | */ | ||
140 | |||
141 | struct GNUNET_SERVER_MessageStreamTokenizer * datatoken; | ||
142 | |||
143 | /** | ||
144 | * stdout pipe handle for the gnunet-wlan-helper process | ||
145 | */ | ||
146 | struct GNUNET_DISK_PipeHandle *server_stdout; | ||
147 | |||
148 | /** | ||
149 | * stdout file handle for the gnunet-wlan-helper process | ||
150 | */ | ||
151 | const struct GNUNET_DISK_FileHandle *server_stdout_handle; | ||
152 | |||
153 | /** | ||
154 | * stdin pipe handle for the gnunet-wlan-helper process | ||
155 | */ | ||
156 | struct GNUNET_DISK_PipeHandle *server_stdin; | ||
157 | |||
158 | /** | ||
159 | * stdin file handle for the gnunet-wlan-helper process | ||
160 | */ | ||
161 | const struct GNUNET_DISK_FileHandle *server_stdin_handle; | ||
162 | |||
163 | /** | ||
164 | * ID of select gnunet-nat-server std read task | ||
165 | */ | ||
166 | GNUNET_SCHEDULER_TaskIdentifier server_read_task; | ||
167 | |||
168 | /** | ||
169 | * The process id of the server process (if behind NAT) | ||
170 | */ | ||
171 | pid_t server_pid; | ||
172 | |||
173 | /** | ||
174 | * The interface of the wlan card given to us by the user. | ||
175 | */ | ||
176 | char *interface; | ||
177 | |||
178 | /** | ||
179 | * The mac_address of the wlan card given to us by the helper. | ||
180 | */ | ||
181 | char *mac_address; | ||
182 | |||
183 | }; | ||
184 | |||
185 | struct Plugin* plugin; | ||
186 | |||
187 | /** | ||
188 | * Function that can be used by the transport service to transmit | ||
189 | * a message using the plugin. | ||
190 | * | ||
191 | * @param cls closure | ||
192 | * @param target who should receive this message | ||
193 | * @param priority how important is the message | ||
194 | * @param msgbuf the message to transmit | ||
195 | * @param msgbuf_size number of bytes in 'msgbuf' | ||
196 | * @param timeout when should we time out | ||
197 | * @param session which session must be used (or NULL for "any") | ||
198 | * @param addr the address to use (can be NULL if the plugin | ||
199 | * is "on its own" (i.e. re-use existing TCP connection)) | ||
200 | * @param addrlen length of the address in bytes | ||
201 | * @param force_address GNUNET_YES if the plugin MUST use the given address, | ||
202 | * otherwise the plugin may use other addresses or | ||
203 | * existing connections (if available) | ||
204 | * @param cont continuation to call once the message has | ||
205 | * been transmitted (or if the transport is ready | ||
206 | * for the next transmission call; or if the | ||
207 | * peer disconnected...) | ||
208 | * @param cont_cls closure for cont | ||
209 | * @return number of bytes used (on the physical network, with overheads); | ||
210 | * -1 on hard errors (i.e. address invalid); 0 is a legal value | ||
211 | * and does NOT mean that the message was not transmitted (DV) | ||
212 | */ | ||
213 | static ssize_t | ||
214 | wlan_plugin_send (void *cls, | ||
215 | const struct GNUNET_PeerIdentity * | ||
216 | target, | ||
217 | const char *msgbuf, | ||
218 | size_t msgbuf_size, | ||
219 | unsigned int priority, | ||
220 | struct GNUNET_TIME_Relative timeout, | ||
221 | struct Session *session, | ||
222 | const void *addr, | ||
223 | size_t addrlen, | ||
224 | int force_address, | ||
225 | GNUNET_TRANSPORT_TransmitContinuation | ||
226 | cont, void *cont_cls) | ||
227 | { | ||
228 | int bytes_sent = 0; | ||
229 | /* struct Plugin *plugin = cls; */ | ||
230 | return bytes_sent; | ||
231 | } | ||
232 | |||
233 | |||
234 | |||
235 | /** | ||
236 | * Function that can be used to force the plugin to disconnect | ||
237 | * from the given peer and cancel all previous transmissions | ||
238 | * (and their continuationc). | ||
239 | * | ||
240 | * @param cls closure | ||
241 | * @param target peer from which to disconnect | ||
242 | */ | ||
243 | static void | ||
244 | wlan_plugin_disconnect (void *cls, | ||
245 | const struct GNUNET_PeerIdentity *target) | ||
246 | { | ||
247 | // struct Plugin *plugin = cls; | ||
248 | // FIXME | ||
249 | } | ||
250 | |||
251 | |||
252 | /** | ||
253 | * Convert the transports address to a nice, human-readable | ||
254 | * format. | ||
255 | * | ||
256 | * @param cls closure | ||
257 | * @param type name of the transport that generated the address | ||
258 | * @param addr one of the addresses of the host, NULL for the last address | ||
259 | * the specific address format depends on the transport | ||
260 | * @param addrlen length of the address | ||
261 | * @param numeric should (IP) addresses be displayed in numeric form? | ||
262 | * @param timeout after how long should we give up? | ||
263 | * @param asc function to call on each string | ||
264 | * @param asc_cls closure for asc | ||
265 | */ | ||
266 | static void | ||
267 | wlan_plugin_address_pretty_printer (void *cls, | ||
268 | const char *type, | ||
269 | const void *addr, | ||
270 | size_t addrlen, | ||
271 | int numeric, | ||
272 | struct GNUNET_TIME_Relative timeout, | ||
273 | GNUNET_TRANSPORT_AddressStringCallback | ||
274 | asc, void *asc_cls) | ||
275 | { | ||
276 | unsigned int res; | ||
277 | char * ret; | ||
278 | char * input; | ||
279 | |||
280 | GNUNET_assert(cls !=NULL); | ||
281 | //Mac Adress has 6 bytes | ||
282 | if (addrlen == 6){ | ||
283 | input = addr; | ||
284 | res = GNUNET_asprintf(&ret,"%s Mac-Adress %X:%X:%X:%X:%X:%X", PROTOCOL_PREFIX, input[0], input[1],input[2],input[3],input[4],input[5]); | ||
285 | |||
286 | GNUNET_assert(res != 0); | ||
287 | asc (asc_cls, ret); | ||
288 | GNUNET_free_non_null (ret); | ||
289 | |||
290 | } else { | ||
291 | /* invalid address */ | ||
292 | GNUNET_break_op (0); | ||
293 | asc (asc_cls, NULL); | ||
294 | return; | ||
295 | } | ||
296 | } | ||
297 | |||
298 | |||
299 | |||
300 | /** | ||
301 | * Another peer has suggested an address for this | ||
302 | * peer and transport plugin. Check that this could be a valid | ||
303 | * address. If so, consider adding it to the list | ||
304 | * of addresses. | ||
305 | * | ||
306 | * @param cls closure | ||
307 | * @param addr pointer to the address | ||
308 | * @param addrlen length of addr | ||
309 | * @return GNUNET_OK if this is a plausible address for this peer | ||
310 | * and transport | ||
311 | */ | ||
312 | static int | ||
313 | wlan_plugin_address_suggested (void *cls, | ||
314 | const void *addr, | ||
315 | size_t addrlen) | ||
316 | { | ||
317 | /* struct Plugin *plugin = cls; */ | ||
318 | |||
319 | /* check if the address is plausible; if so, | ||
320 | add it to our list! */ | ||
321 | |||
322 | GNUNET_assert(cls !=NULL); | ||
323 | |||
324 | //Mac Adress has 6 bytes | ||
325 | if (addrlen == 6){ | ||
326 | /* TODO check for bad addresses like milticast, broadcast, etc */ | ||
327 | return GNUNET_OK; | ||
328 | } else { | ||
329 | return GNUNET_SYSERR; | ||
330 | } | ||
331 | |||
332 | } | ||
333 | |||
334 | |||
335 | /** | ||
336 | * Function called for a quick conversion of the binary address to | ||
337 | * a numeric address. Note that the caller must not free the | ||
338 | * address and that the next call to this function is allowed | ||
339 | * to override the address again. | ||
340 | * | ||
341 | * @param cls closure | ||
342 | * @param addr binary address | ||
343 | * @param addrlen length of the address | ||
344 | * @return string representing the same address | ||
345 | */ | ||
346 | static const char* | ||
347 | wlan_plugin_address_to_string (void *cls, | ||
348 | const void *addr, | ||
349 | size_t addrlen) | ||
350 | { | ||
351 | unsigned int res; | ||
352 | char * ret; | ||
353 | char * input; | ||
354 | |||
355 | GNUNET_assert(cls !=NULL); | ||
356 | //Mac Adress has 6 bytes | ||
357 | if (addrlen == 6){ | ||
358 | input = addr; | ||
359 | res = GNUNET_asprintf(&ret,"%X:%X:%X:%X:%X:%X", input[0], input[1],input[2],input[3],input[4],input[5]); | ||
360 | |||
361 | GNUNET_assert(res != 0); | ||
362 | return ret; | ||
363 | |||
364 | } else { | ||
365 | /* invalid address */ | ||
366 | GNUNET_break (0); | ||
367 | return NULL; | ||
368 | } | ||
369 | } | ||
370 | |||
371 | |||
372 | /** | ||
373 | * Function for used to process the data from the suid process | ||
374 | */ | ||
375 | static void | ||
376 | wlan_process_helper (void *cls, | ||
377 | void *client_identity, | ||
378 | struct GNUNET_MessageHeader *hdr) | ||
379 | { | ||
380 | if (hdr->type == GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA){ | ||
381 | //TODO DATA | ||
382 | } else if (hdr->type == GNUNET_MESSAGE_TYPE_WLAN_HELPER_ADVERTISEMENT){ | ||
383 | //TODO ADV | ||
384 | } else if (hdr->type == GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL){ | ||
385 | //TODO Control | ||
386 | if (hdr->size == 6){ | ||
387 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Notifying transport of address %s\n", wlan_plugin_address_to_string(cls, plugin->mac_address, hdr->size)); | ||
388 | plugin->env->notify_address (plugin->env->cls, | ||
389 | "wlan", | ||
390 | &plugin->mac_address, sizeof(plugin->mac_address), GNUNET_TIME_UNIT_FOREVER_REL); | ||
391 | } else { | ||
392 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Wrong wlan mac address %s\n", plugin->mac_address); | ||
393 | } | ||
394 | |||
395 | |||
396 | } else { | ||
397 | // TODO Wrong data? | ||
398 | } | ||
399 | } | ||
400 | |||
401 | |||
402 | |||
403 | /** | ||
404 | * Start the gnunet-wlan-helper process for users behind NAT. | ||
405 | * | ||
406 | * @param plugin the transport plugin | ||
407 | * | ||
408 | * @return GNUNET_YES if process was started, GNUNET_SYSERR on error | ||
409 | */ | ||
410 | |||
411 | static int | ||
412 | wlan_transport_start_wlan_helper(struct Plugin *plugin) | ||
413 | { | ||
414 | |||
415 | plugin->server_stdout = GNUNET_DISK_pipe(GNUNET_YES); | ||
416 | if (plugin->server_stdout == NULL) | ||
417 | return GNUNET_SYSERR; | ||
418 | |||
419 | plugin->server_stdin = GNUNET_DISK_pipe(GNUNET_YES); | ||
420 | if (plugin->server_stdin == NULL) | ||
421 | return GNUNET_SYSERR; | ||
422 | |||
423 | #if DEBUG_TCP_NAT | ||
424 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
425 | "Starting gnunet-wlan-helper process cmd: %s %s\n", "gnunet-wlan-helper", plugin->interface); | ||
426 | #endif | ||
427 | /* Start the server process */ | ||
428 | plugin->server_pid = GNUNET_OS_start_process(plugin->server_stdin, plugin->server_stdout, "gnunet-transport-wlan-helper", "gnunet-transport-wlan-helper", plugin->interface, NULL); | ||
429 | if (plugin->server_pid == GNUNET_SYSERR) | ||
430 | { | ||
431 | #if DEBUG_TCP_NAT | ||
432 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
433 | "Failed to start gnunet-wlan-helper process\n"); | ||
434 | #endif | ||
435 | return GNUNET_SYSERR; | ||
436 | } | ||
437 | /* Close the write end of the read pipe */ | ||
438 | GNUNET_DISK_pipe_close_end(plugin->server_stdout, GNUNET_DISK_PIPE_END_WRITE); | ||
439 | |||
440 | /* Close the read end of the write pipe */ | ||
441 | GNUNET_DISK_pipe_close_end(plugin->server_stdout, GNUNET_DISK_PIPE_END_READ); | ||
442 | |||
443 | plugin->server_stdout_handle = GNUNET_DISK_pipe_handle(plugin->server_stdout, GNUNET_DISK_PIPE_END_READ); | ||
444 | plugin->server_stdin_handle = GNUNET_DISK_pipe_handle(plugin->server_stdin, GNUNET_DISK_PIPE_END_WRITE); | ||
445 | |||
446 | plugin->server_read_task = | ||
447 | GNUNET_SCHEDULER_add_read_file (plugin->env->sched, | ||
448 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
449 | plugin->server_stdout_handle, &wlan_plugin_helper_read, plugin); | ||
450 | return GNUNET_YES; | ||
451 | } | ||
452 | |||
453 | |||
454 | |||
455 | |||
456 | static void | ||
457 | wlan_plugin_helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
458 | { | ||
459 | struct Plugin *plugin = cls; | ||
460 | char mybuf[3000]; //max size of packet from helper | ||
461 | ssize_t bytes; | ||
462 | //memset(&mybuf, 0, sizeof(mybuf)); //? | ||
463 | int i; | ||
464 | |||
465 | |||
466 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | ||
467 | return; | ||
468 | |||
469 | bytes = GNUNET_DISK_file_read(plugin->server_stdout_handle, &mybuf, sizeof(mybuf)); | ||
470 | |||
471 | if (bytes < 1) | ||
472 | { | ||
473 | #if DEBUG_TCP_NAT | ||
474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
475 | _("Finished reading from wlan-helper stdout with code: %d\n"), bytes); | ||
476 | #endif | ||
477 | return; | ||
478 | } | ||
479 | |||
480 | plugin->server_read_task = | ||
481 | GNUNET_SCHEDULER_add_read_file (plugin->env->sched, | ||
482 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
483 | plugin->server_stdout_handle, &wlan_plugin_helper_read, plugin); | ||
484 | |||
485 | } | ||
486 | |||
487 | |||
488 | /** | ||
489 | * Entry point for the plugin. | ||
490 | */ | ||
491 | void * | ||
492 | gnunet_plugin_transport_wlan_init (void *cls) | ||
493 | { | ||
494 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; | ||
495 | struct GNUNET_TRANSPORT_PluginFunctions *api; | ||
496 | struct Plugin *plugin; | ||
497 | |||
498 | GNUNET_assert(cls !=NULL); | ||
499 | |||
500 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | ||
501 | plugin->env = env; | ||
502 | |||
503 | |||
504 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | ||
505 | api->cls = plugin; | ||
506 | api->send = &wlan_plugin_send; | ||
507 | api->disconnect = &wlan_plugin_disconnect; | ||
508 | api->address_pretty_printer = &wlan_plugin_address_pretty_printer; | ||
509 | api->check_address = &wlan_plugin_address_suggested; | ||
510 | api->address_to_string = &wlan_plugin_address_to_string; | ||
511 | |||
512 | return api; | ||
513 | } | ||
514 | |||
515 | |||
516 | /** | ||
517 | * Exit point from the plugin. | ||
518 | */ | ||
519 | void * | ||
520 | gnunet_plugin_transport_wlan_done (void *cls) | ||
521 | { | ||
522 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | ||
523 | struct Plugin *plugin = api->cls; | ||
524 | |||
525 | GNUNET_assert(cls !=NULL); | ||
526 | |||
527 | GNUNET_free (plugin); | ||
528 | GNUNET_free (api); | ||
529 | return NULL; | ||
530 | } | ||
531 | |||
532 | /* end of plugin_transport_wlan.c */ | ||