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