glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / transport / plugin_transport_wlan.h
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2010, 2011 GNUnet e.V.
4
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your 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  Affero General Public License for more details.
14  */
15
16 /**
17  * @file transport/plugin_transport_wlan.h
18  * @brief header for transport plugin and the helper for wlan
19  * @author David Brodski
20  */
21 #ifndef PLUGIN_TRANSPORT_WLAN
22 #define PLUGIN_TRANSPORT_WLAN
23
24 #include "gnunet_crypto_lib.h"
25 #include "gnunet_common.h"
26
27 /**
28  * Number fo bytes in a mac address.
29  */
30 #ifdef MINGW
31   #define MAC_ADDR_SIZE 8
32   typedef uint8_t u_int8_t;
33 #else
34   #define MAC_ADDR_SIZE 6
35 #endif
36
37 /**
38  * Value for "Management" in the 'frame_control' field of the
39  * struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame.
40  */
41 #define IEEE80211_FC0_TYPE_MGT                  0x00
42
43 /**
44  * Value for "Control" in the 'frame_control' field of the
45  * struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame.
46  */
47 #define IEEE80211_FC0_TYPE_CTL                  0x04
48
49 /**
50  * Value for DATA in the 'frame_control' field of the
51  * struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame.
52  */
53 #define IEEE80211_FC0_TYPE_DATA                 0x08
54
55
56 GNUNET_NETWORK_STRUCT_BEGIN
57
58 /**
59  * A MAC Address.
60  */
61 struct GNUNET_TRANSPORT_WLAN_MacAddress
62 {
63   uint8_t mac[MAC_ADDR_SIZE];
64 };
65
66 /**
67  * Format of a WLAN Control Message.
68  */
69 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage
70 {
71   /**
72    * Message header.  Type is
73    * GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL
74    */
75   struct GNUNET_MessageHeader hdr;
76
77   /**
78    * MAC Address of the local WLAN interface.
79    */
80   struct GNUNET_TRANSPORT_WLAN_MacAddress mac;
81 };
82
83 /**
84  * generic definitions for IEEE 802.3 frames
85  */
86 struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame
87 {
88
89   /**
90    * Address 1: destination address in ad-hoc mode or AP, BSSID if station,
91    */
92   struct GNUNET_TRANSPORT_WLAN_MacAddress dst;
93
94   /**
95    * Address 2: source address if in ad-hoc-mode or station, BSSID if AP
96    */
97   struct GNUNET_TRANSPORT_WLAN_MacAddress src;
98
99   /**
100    * Packet type ID.
101    */
102   uint16_t type;
103
104 };
105
106
107 /**
108  * generic definitions for IEEE 802.11 frames
109  */
110 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame
111 {
112   /**
113    * 802.11 Frame Control field.  A bitmask.  The overall field is a
114    * 16-bit mask of the respecitve fields.  The lowest two bits should
115    * be 0, then comes the "type" (2 bits, see IEEE80211_FC0_TYPE_*
116    * constants), followed by 4-bit subtype (all zeros for ad-hoc),
117    * followed by various flags (to DS, from DS, more frag, retry,
118    * power management, more data, WEP, strict), all of which we also
119    * keep at zero.
120    */
121   uint16_t frame_control GNUNET_PACKED;
122
123   /**
124    * Microseconds to reserve link (duration), 0 by default
125    */
126   uint16_t duration GNUNET_PACKED;
127
128   /**
129    * Address 1: destination address in ad-hoc mode or AP, BSSID if station,
130    */
131   struct GNUNET_TRANSPORT_WLAN_MacAddress addr1;
132
133   /**
134    * Address 2: source address if in ad-hoc-mode or station, BSSID if AP
135    */
136   struct GNUNET_TRANSPORT_WLAN_MacAddress addr2;
137
138   /**
139    * Address 3: BSSID in ad-hoc mode, Destination if station, source if AP
140    */
141   struct GNUNET_TRANSPORT_WLAN_MacAddress addr3;
142
143   /**
144    * 802.11 sequence control field; contains fragment number an sequence
145    * number (we set this to all zeros).
146    */
147   uint16_t sequence_control GNUNET_PACKED;
148
149   /**
150    * Link layer control (LLC).  Set to a GNUnet-specific value.
151    */
152   u_int8_t llc[4];
153
154   /* payload */
155
156 } GNUNET_PACKED;
157
158
159
160 /**
161  * Message from the plugin to the WLAN helper: send the given message with the
162  * given connection parameters.
163  */
164 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage
165 {
166
167   /**
168    * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER'.
169    */
170   struct GNUNET_MessageHeader header;
171
172   /**
173    * wlan send rate
174    */
175   uint8_t rate;
176
177   /**
178    * Antenna; the first antenna is 0.
179    */
180   uint8_t antenna;
181
182   /**
183    * Transmit power expressed as unitless distance from max power set at factory calibration.
184    * 0 is max power. Monotonically nondecreasing with lower power levels.
185    */
186   uint16_t tx_power GNUNET_PACKED;
187
188   /**
189    * IEEE Frame to transmit (the sender MAC address will be overwritten by the helper as it does not
190    * trust the plugin to set it correctly).
191    */
192   struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame;
193
194   /* actual payload follows */
195 };
196
197
198 /**
199  * Message from the WLAN helper to the plugin: we have received the given message with the
200  * given performance characteristics.
201  */
202 /**
203  * struct to represent infos gathered form the radiotap fields, see RadiotapHeader for more Infos
204  */
205 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage
206 {
207
208   /**
209    * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER'.
210    */
211   struct GNUNET_MessageHeader header;
212
213   /**
214    * Information about which of the fields below are actually valid.
215    * 0 for none.  FIXME: not properly initialized so far (always zero).
216    */
217   uint32_t ri_present GNUNET_PACKED;
218
219   /**
220    * IEEE80211_RADIOTAP_TSFT, 0 if unknown.
221    */
222   uint64_t ri_mactime GNUNET_PACKED;
223
224   /**
225    * from radiotap
226    * either IEEE80211_RADIOTAP_DBM_ANTSIGNAL
227    * or IEEE80211_RADIOTAP_DB_ANTSIGNAL, 0 if unknown.
228    */
229   int32_t ri_power GNUNET_PACKED;
230
231   /**
232    * either IEEE80211_RADIOTAP_DBM_ANTNOISE
233    * or IEEE80211_RADIOTAP_DB_ANTNOISE, 0 if unknown.
234    */
235   int32_t ri_noise GNUNET_PACKED;
236
237   /**
238    * IEEE80211_RADIOTAP_CHANNEL, 0 if unknown.
239    */
240   uint32_t ri_channel GNUNET_PACKED;
241
242   /**
243    * Frequency we use.  0 if unknown.
244    */
245   uint32_t ri_freq GNUNET_PACKED;
246
247   /**
248    * IEEE80211_RADIOTAP_RATE * 50000, 0 if unknown.
249    */
250   uint32_t ri_rate GNUNET_PACKED;
251
252   /**
253    * IEEE80211_RADIOTAP_ANTENNA, 0 if unknown.
254    */
255   uint32_t ri_antenna GNUNET_PACKED;
256
257   /**
258    * IEEE Frame.
259    */
260   struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame;
261
262   /* followed by payload */
263 };
264
265 GNUNET_NETWORK_STRUCT_END
266
267 /**
268  * GNUnet bssid
269  */
270 static const struct GNUNET_TRANSPORT_WLAN_MacAddress mac_bssid_gnunet = {
271   {0x13, 0x22, 0x33, 0x44, 0x55, 0x66}
272 };
273
274
275 /**
276  * Broadcast MAC
277  */
278 static const struct GNUNET_TRANSPORT_WLAN_MacAddress bc_all_mac = {
279   {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
280 };
281
282 #endif