2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file transport/gnunet-wlan.h
23 * @brief common internal definitions for the wlan mediator
24 * @author David Brodski
43 typedef unsigned int u32;
44 typedef unsigned short u16;
45 typedef unsigned char u8;
48 #if __BYTE_ORDER == __LITTLE_ENDIAN
49 #define le16_to_cpu(x) (x)
50 #define le32_to_cpu(x) (x)
52 #define le16_to_cpu(x) ((((x)&0xff)<<8)|(((x)&0xff00)>>8))
53 #define le32_to_cpu(x) \
54 ((((x)&0xff)<<24)|(((x)&0xff00)<<8)|(((x)&0xff0000)>>8)|(((x)&0xff000000)>>24))
56 #define unlikely(x) (x)
59 #endif /* gnunet_wlan_H */
63 * Copyright (c) 2003, 2004 David Young. All rights reserved.
65 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions
68 * 1. Redistributions of source code must retain the above copyright
69 * notice, this list of conditions and the following disclaimer.
70 * 2. Redistributions in binary form must reproduce the above copyright
71 * notice, this list of conditions and the following disclaimer in the
72 * documentation and/or other materials provided with the distribution.
73 * 3. The name of David Young may not be used to endorse or promote
74 * products derived from this software without specific prior
77 * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
78 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
79 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
80 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
81 * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
82 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
83 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
84 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
85 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
86 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
87 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
92 * Modifications to fit into the linux IEEE 802.11 stack,
93 * Mike Kershaw (dragorn@kismetwireless.net)
96 #ifndef IEEE80211RADIOTAP_H
97 #define IEEE80211RADIOTAP_H
99 #include <linux/if_ether.h>
100 #include <linux/kernel.h>
101 //#include <asm/unaligned.h>
103 /* Base version of the radiotap packet header data */
104 #define PKTHDR_RADIOTAP_VERSION 0
106 /* A generic radio capture format is desirable. There is one for
107 * Linux, but it is neither rigidly defined (there were not even
108 * units given for some fields) nor easily extensible.
110 * I suggest the following extensible radio capture format. It is
111 * based on a bitmap indicating which fields are present.
113 * I am trying to describe precisely what the application programmer
114 * should expect in the following, and for that reason I tell the
115 * units and origin of each measurement (where it applies), or else I
116 * use sufficiently weaselly language ("is a monotonically nondecreasing
117 * function of...") that I cannot set false expectations for lawyerly
122 * The radio capture header precedes the 802.11 header.
123 * All data in the header is little endian on all platforms.
125 struct ieee80211_radiotap_header {
126 u8 it_version; /* Version 0. Only increases
127 * for drastic changes,
128 * introduction of compatible
129 * new fields does not count.
132 __le16 it_len; /* length of the whole
133 * header in bytes, including
134 * it_version, it_pad,
135 * it_len, and data fields.
137 __le32 it_present; /* A bitmap telling which
138 * fields are present. Set bit 31
139 * (0x80000000) to extend the
140 * bitmap by another 32 bits.
141 * Additional extensions are made
146 /* Name Data type Units
147 * ---- --------- -----
149 * IEEE80211_RADIOTAP_TSFT __le64 microseconds
151 * Value in microseconds of the MAC's 64-bit 802.11 Time
152 * Synchronization Function timer when the first bit of the
153 * MPDU arrived at the MAC. For received frames, only.
155 * IEEE80211_RADIOTAP_CHANNEL 2 x __le16 MHz, bitmap
157 * Tx/Rx frequency in MHz, followed by flags (see below).
159 * IEEE80211_RADIOTAP_FHSS __le16 see below
161 * For frequency-hopping radios, the hop set (first byte)
162 * and pattern (second byte).
164 * IEEE80211_RADIOTAP_RATE u8 500kb/s
168 * IEEE80211_RADIOTAP_DBM_ANTSIGNAL s8 decibels from
169 * one milliwatt (dBm)
171 * RF signal power at the antenna, decibel difference from
174 * IEEE80211_RADIOTAP_DBM_ANTNOISE s8 decibels from
175 * one milliwatt (dBm)
177 * RF noise power at the antenna, decibel difference from one
180 * IEEE80211_RADIOTAP_DB_ANTSIGNAL u8 decibel (dB)
182 * RF signal power at the antenna, decibel difference from an
183 * arbitrary, fixed reference.
185 * IEEE80211_RADIOTAP_DB_ANTNOISE u8 decibel (dB)
187 * RF noise power at the antenna, decibel difference from an
188 * arbitrary, fixed reference point.
190 * IEEE80211_RADIOTAP_LOCK_QUALITY __le16 unitless
192 * Quality of Barker code lock. Unitless. Monotonically
193 * nondecreasing with "better" lock strength. Called "Signal
194 * Quality" in datasheets. (Is there a standard way to measure
197 * IEEE80211_RADIOTAP_TX_ATTENUATION __le16 unitless
199 * Transmit power expressed as unitless distance from max
200 * power set at factory calibration. 0 is max power.
201 * Monotonically nondecreasing with lower power levels.
203 * IEEE80211_RADIOTAP_DB_TX_ATTENUATION __le16 decibels (dB)
205 * Transmit power expressed as decibel distance from max power
206 * set at factory calibration. 0 is max power. Monotonically
207 * nondecreasing with lower power levels.
209 * IEEE80211_RADIOTAP_DBM_TX_POWER s8 decibels from
210 * one milliwatt (dBm)
212 * Transmit power expressed as dBm (decibels from a 1 milliwatt
213 * reference). This is the absolute power level measured at
216 * IEEE80211_RADIOTAP_FLAGS u8 bitmap
218 * Properties of transmitted and received frames. See flags
221 * IEEE80211_RADIOTAP_ANTENNA u8 antenna index
223 * Unitless indication of the Rx/Tx antenna for this packet.
224 * The first antenna is antenna 0.
226 * IEEE80211_RADIOTAP_RX_FLAGS __le16 bitmap
228 * Properties of received frames. See flags defined below.
230 * IEEE80211_RADIOTAP_TX_FLAGS __le16 bitmap
232 * Properties of transmitted frames. See flags defined below.
234 * IEEE80211_RADIOTAP_RTS_RETRIES u8 data
236 * Number of rts retries a transmitted frame used.
238 * IEEE80211_RADIOTAP_DATA_RETRIES u8 data
240 * Number of unicast retries a transmitted frame used.
243 enum ieee80211_radiotap_type {
244 IEEE80211_RADIOTAP_TSFT = 0,
245 IEEE80211_RADIOTAP_FLAGS = 1,
246 IEEE80211_RADIOTAP_RATE = 2,
247 IEEE80211_RADIOTAP_CHANNEL = 3,
248 IEEE80211_RADIOTAP_FHSS = 4,
249 IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
250 IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
251 IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
252 IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
253 IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
254 IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
255 IEEE80211_RADIOTAP_ANTENNA = 11,
256 IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
257 IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
258 IEEE80211_RADIOTAP_RX_FLAGS = 14,
259 IEEE80211_RADIOTAP_TX_FLAGS = 15,
260 IEEE80211_RADIOTAP_RTS_RETRIES = 16,
261 IEEE80211_RADIOTAP_DATA_RETRIES = 17,
263 /* valid in every it_present bitmap, even vendor namespaces */
264 IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE = 29,
265 IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30,
266 IEEE80211_RADIOTAP_EXT = 31
270 #define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */
271 #define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */
272 #define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */
273 #define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */
274 #define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */
275 #define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */
276 #define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */
277 #define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */
279 /* For IEEE80211_RADIOTAP_FLAGS */
280 #define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
283 #define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
287 #define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
288 * with WEP encryption
290 #define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
293 #define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
294 #define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
295 * 802.11 header and payload
296 * (to 32-bit boundary)
298 #define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* bad FCS */
300 /* For IEEE80211_RADIOTAP_RX_FLAGS */
301 #define IEEE80211_RADIOTAP_F_RX_BADPLCP 0x0002 /* frame has bad PLCP */
303 /* For IEEE80211_RADIOTAP_TX_FLAGS */
304 #define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive
306 #define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */
307 #define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
309 /* Ugly macro to convert literal channel numbers into their mhz equivalents
310 * There are certianly some conditions that will break this (like feeding it '30')
311 * but they shouldn't arise since nothing talks on channel 30. */
312 #define ieee80211chan2mhz(x) \
314 (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \
319 static inline int ieee80211_get_radiotap_len(unsigned char *data)
321 struct ieee80211_radiotap_header *hdr =
322 (struct ieee80211_radiotap_header *)data;
324 return get_unaligned_le16(&hdr->it_len);
327 #endif /* IEEE80211_RADIOTAP_H */
331 /* Radiotap header iteration
332 * implemented in net/wireless/radiotap.c
333 * docs in Documentation/networking/radiotap-headers.txt
336 * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args
337 * @rtheader: pointer to the radiotap header we are walking through
338 * @max_length: length of radiotap header in cpu byte ordering
339 * @this_arg_index: IEEE80211_RADIOTAP_... index of current arg
340 * @this_arg: pointer to current radiotap arg
341 * @arg_index: internal next argument index
342 * @arg: internal next argument pointer
343 * @next_bitmap: internal pointer to next present u32
344 * @bitmap_shifter: internal shifter for curr u32 bitmap, 23344";
345 b0 set == arg present
348 struct ieee80211_radiotap_iterator {
349 struct ieee80211_radiotap_header *rtheader;
360 extern int ieee80211_radiotap_iterator_init(
361 struct ieee80211_radiotap_iterator *iterator,
362 struct ieee80211_radiotap_header *radiotap_header,
365 extern int ieee80211_radiotap_iterator_next(
366 struct ieee80211_radiotap_iterator *iterator);