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