- implementation for mantis 0002485
[oweals/gnunet.git] / src / transport / plugin_transport_wlan.h
1 /*
2  This file is part of GNUnet
3  (C) 2010, 2011 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 #ifndef PLUGIN_TRANSPORT_WLAN
27 #define PLUGIN_TRANSPORT_WLAN
28
29 #include <stdint.h>
30 #include "gnunet_common.h"
31
32 /**
33  * Number fo bytes in a mac address.
34  */
35 #define MAC_ADDR_SIZE 6
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 /**
85  * generic definitions for IEEE 802.11 frames
86  */
87 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame
88 {
89   /**
90    * 802.11 Frame Control field.  A bitmask.  The overall field is a
91    * 16-bit mask of the respecitve fields.  The lowest two bits should
92    * be 0, then comes the "type" (2 bits, see IEEE80211_FC0_TYPE_*
93    * constants), followed by 4-bit subtype (all zeros for ad-hoc),
94    * followed by various flags (to DS, from DS, more frag, retry,
95    * power management, more data, WEP, strict), all of which we also
96    * keep at zero.
97    */
98   uint16_t frame_control GNUNET_PACKED;
99
100   /**
101    * Microseconds to reserve link (duration), 0 by default
102    */
103   uint16_t duration GNUNET_PACKED;
104
105   /**
106    * Address 1: destination address in ad-hoc mode or AP, BSSID if station,
107    */
108   struct GNUNET_TRANSPORT_WLAN_MacAddress addr1;
109
110   /**
111    * Address 2: source address if in ad-hoc-mode or station, BSSID if AP
112    */
113   struct GNUNET_TRANSPORT_WLAN_MacAddress addr2;
114
115   /**
116    * Address 3: BSSID in ad-hoc mode, Destination if station, source if AP
117    */
118   struct GNUNET_TRANSPORT_WLAN_MacAddress addr3;
119
120   /**
121    * 802.11 sequence control field; contains fragment number an sequence
122    * number (we set this to all zeros).
123    */
124   uint16_t sequence_control GNUNET_PACKED;
125
126   /**
127    * Link layer control (LLC).  Set to a GNUnet-specific value.
128    */
129   u_int8_t llc[4];
130
131   /* payload */
132
133 } GNUNET_PACKED;
134
135
136
137 /**
138  * Message from the plugin to the WLAN helper: send the given message with the
139  * given connection parameters.
140  */
141 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage
142 {
143
144   /**
145    * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER'.
146    */
147   struct GNUNET_MessageHeader header;
148
149   /**
150    * wlan send rate
151    */
152   uint8_t rate;
153
154   /**
155    * Antenna; the first antenna is 0.
156    */
157   uint8_t antenna;
158
159   /**
160    * Transmit power expressed as unitless distance from max power set at factory calibration.
161    * 0 is max power. Monotonically nondecreasing with lower power levels.
162    */
163   uint16_t tx_power GNUNET_PACKED;
164
165   /**
166    * IEEE Frame to transmit (the sender MAC address will be overwritten by the helper as it does not
167    * trust the plugin to set it correctly).
168    */
169   struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame;
170
171   /* actual payload follows */
172 };
173
174
175 /**
176  * Message from the WLAN helper to the plugin: we have received the given message with the
177  * given performance characteristics.
178  */
179 /**
180  * struct to represent infos gathered form the radiotap fields, see RadiotapHeader for more Infos
181  */
182 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage
183 {
184
185   /**
186    * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER'.
187    */
188   struct GNUNET_MessageHeader header;
189
190   /**
191    * Information about which of the fields below are actually valid.
192    * 0 for none.  FIXME: not properly initialized so far (always zero).
193    */
194   uint32_t ri_present GNUNET_PACKED;
195
196   /**
197    * IEEE80211_RADIOTAP_TSFT, 0 if unknown.
198    */
199   uint64_t ri_mactime GNUNET_PACKED;
200
201   /**
202    * from radiotap
203    * either IEEE80211_RADIOTAP_DBM_ANTSIGNAL
204    * or IEEE80211_RADIOTAP_DB_ANTSIGNAL, 0 if unknown.
205    */
206   int32_t ri_power GNUNET_PACKED;
207
208   /**
209    * either IEEE80211_RADIOTAP_DBM_ANTNOISE
210    * or IEEE80211_RADIOTAP_DB_ANTNOISE, 0 if unknown.
211    */
212   int32_t ri_noise GNUNET_PACKED;
213
214   /**
215    * IEEE80211_RADIOTAP_CHANNEL, 0 if unknown.
216    */
217   uint32_t ri_channel GNUNET_PACKED;
218
219   /**
220    * Frequency we use.  0 if unknown.
221    */
222   uint32_t ri_freq GNUNET_PACKED;
223
224   /**
225    * IEEE80211_RADIOTAP_RATE * 50000, 0 if unknown.
226    */
227   uint32_t ri_rate GNUNET_PACKED;
228
229   /**
230    * IEEE80211_RADIOTAP_ANTENNA, 0 if unknown.
231    */
232   uint32_t ri_antenna GNUNET_PACKED;
233
234   /**
235    * IEEE Frame.
236    */
237   struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame frame;
238
239   /* followed by payload */
240 };
241
242 GNUNET_NETWORK_STRUCT_END
243
244 /**
245  * GNUnet bssid
246  */
247 static const struct GNUNET_TRANSPORT_WLAN_MacAddress mac_bssid_gnunet = {
248   {0x13, 0x22, 0x33, 0x44, 0x55, 0x66}
249 };
250
251
252 /**
253  * Broadcast MAC
254  */
255 static const struct GNUNET_TRANSPORT_WLAN_MacAddress bc_all_mac = {
256   {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
257 };
258
259 #endif