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