wip
[oweals/gnunet.git] / src / transport / plugin_transport_wlan.h
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.h
23  * @brief header for transport plugin and the helper for wlan
24  * @author David Brodski
25  */
26
27 #ifndef PLUGIN_TRANSPORT_WLAN
28 #define PLUGIN_TRANSPORT_WLAN
29
30 #include <stdint.h>
31 #include "gnunet_common.h"
32
33
34
35 struct MacAddress
36 {
37   u_int8_t mac[6];
38 };
39
40 struct Wlan_Helper_Control_Message
41 {
42   struct GNUNET_MessageHeader hdr;
43   struct MacAddress mac;
44 };
45
46 /**
47  * Header for messages which need fragmentation
48  */
49 struct FragmentationHeader
50 {
51
52   struct GNUNET_MessageHeader header;
53
54   /**
55    * ID of message, to distinguish between the messages, picked randomly.
56    */
57   uint32_t message_id GNUNET_PACKED;
58
59   /**
60    * Offset or number of this fragment, for fragmentation/segmentation (design choice, TBD)
61    */
62   uint16_t fragment_off_or_num GNUNET_PACKED;
63
64   /**
65    * CRC of fragment (for error checking)
66    */
67   uint16_t message_crc GNUNET_PACKED;
68
69 // followed by payload
70
71 };
72
73 /**
74  * Header for messages which need fragmentation
75  */
76 struct WlanHeader
77 {
78
79   struct GNUNET_MessageHeader header;
80
81   /**
82    * checksum/error correction
83    */
84   uint32_t crc GNUNET_PACKED;
85
86   /**
87    * To whom are we talking to (set to our identity
88    * if we are still waiting for the welcome message)
89    */
90   struct GNUNET_PeerIdentity target;
91
92 // followed by payload
93
94 };
95
96 /* Wlan IEEE80211 header default */
97 //Informations (in German) http://www.umtslink.at/content/WLAN_macheader-196.html
98 static const uint8_t u8aIeeeHeader[] = 
99   {
100     0x08, 0x01, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0;
101                 //      b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data
102                 //      0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS;
103     0x00, 0x00, // Duration/ID
104     0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // mac1 - in this case receiver
105     0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac2 - in this case sender
106     0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
107     0x10, 0x86, //Sequence Control
108   };
109
110 // gnunet bssid
111 static const struct MacAddress mac_bssid =
112   {  { 0x13, 0x22, 0x33, 0x44, 0x55, 0x66 } } ; 
113
114 // broadcast mac
115 static const struct MacAddress bc_all_mac =
116   { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } };
117
118
119 /* this is the template radiotap header we send packets out with */
120
121 static const uint8_t u8aRadiotapHeader[] = 
122   {
123     0x00, 0x00, // <-- radiotap version
124     0x19, 0x00, // <- radiotap header length
125     0x6f, 0x08, 0x00, 0x00, // <-- bitmap
126     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
127     0x00, // <-- flags (Offset +0x10)
128     0x6c, // <-- rate (0ffset +0x11)
129     0x71, 0x09, 0xc0, 0x00, // <-- channel
130     0xde, // <-- antsignal
131     0x00, // <-- antnoise
132     0x01, // <-- antenna
133 };
134
135 struct Radiotap_Send
136 {
137   /**
138      * wlan send rate
139      */
140     uint8_t rate;
141
142     /**
143      * antenna
144      */
145     uint8_t antenna;
146
147     /**
148      * Transmit power expressed as unitless distance from max power set at factory calibration.
149      * 0 is max power. Monotonically nondecreasing with lower power levels.
150      */
151
152     uint16_t tx_power;
153 };
154
155 // bit field defines for ri_present
156
157 #define has_noise 1
158 #define has_power 2
159 #define has_channel 4
160
161 /**
162  * struct to represent infos gathered form the radiotap fields
163  */
164
165 struct Radiotap_rx {
166         uint32_t ri_present;
167         uint64_t ri_mactime;
168         int32_t ri_power;
169         int32_t ri_noise;
170         uint32_t ri_channel;
171         uint32_t ri_freq;
172         uint32_t ri_rate;
173         uint32_t ri_antenna;
174 };
175
176 /**
177  * Radiotap Header
178  */
179 struct RadiotapHeader
180 {
181   /**
182    * radiotap version
183    */
184   u_int8_t version;
185
186   u_int8_t pad_version;
187   
188   /**
189    * radiotap header length
190    */
191   uint16_t length GNUNET_PACKED;
192   
193   /**
194    * bitmap, fields present
195    */
196   uint32_t bitmap GNUNET_PACKED;
197   
198   /**
199    * timestamp
200    */
201   uint64_t timestamp GNUNET_PACKED;
202   
203   /**
204    * radiotap flags
205    */
206   uint8_t flags;
207   
208   /**
209    * wlan send rate
210    */
211   uint8_t rate;
212   
213   // FIXME: unaligned here, is this OK?
214   /**
215    * Wlan channel
216    */
217   uint32_t channel GNUNET_PACKED;
218   
219   /**
220    * antsignal
221    */
222   uint8_t antsignal;
223   
224   /**
225    * antnoise
226    */
227   uint8_t antnoise;
228   
229   /**
230    * antenna
231    */
232   uint8_t antenna;
233 };
234
235 #endif