nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /*
2 * Copyright (c) 2003, 2004 David Young. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of David Young may not be used to endorse or promote
13 * products derived from this software without specific prior
14 * written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
20 * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27 * OF SUCH DAMAGE.
28 */
29  
30 /*
31 * Modifications to fit into the linux IEEE 802.11 stack,
32 * Mike Kershaw (dragorn@kismetwireless.net)
33 */
34  
35 #ifndef IEEE80211RADIOTAP_H
36 #define IEEE80211RADIOTAP_H
37  
38 #include <types.h>
39  
40 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
41  
42 extern const struct ieee80211_radiotap_namespace radiotap_ns;
43  
44 /* Base version of the radiotap packet header data */
45 #define PKTHDR_RADIOTAP_VERSION 0
46  
47 struct tsf {
48 unsigned int tsf_l;
49 unsigned int tsf_h;
50 } __attribute__((packed));
51  
52 /* A generic radio capture format is desirable. There is one for
53 * Linux, but it is neither rigidly defined (there were not even
54 * units given for some fields) nor easily extensible.
55 *
56 * I suggest the following extensible radio capture format. It is
57 * based on a bitmap indicating which fields are present.
58 *
59 * I am trying to describe precisely what the application programmer
60 * should expect in the following, and for that reason I tell the
61 * units and origin of each measurement (where it applies), or else I
62 * use sufficiently weaselly language ("is a monotonically nondecreasing
63 * function of...") that I cannot set false expectations for lawyerly
64 * readers.
65 */
66  
67 /*
68 * The radio capture header precedes the 802.11 header.
69 * All data in the header is little endian on all platforms.
70 */
71 struct ieee80211_radiotap_header {
72 uint8 it_version; /* Version 0. Only increases
73 * for drastic changes,
74 * introduction of compatible
75 * new fields does not count.
76 */
77 uint8 it_pad;
78 uint16 it_len; /* length of the whole
79 * header in bytes, including
80 * it_version, it_pad,
81 * it_len, and data fields.
82 */
83 uint32 it_present; /* A bitmap telling which
84 * fields are present. Set bit 31
85 * (0x80000000) to extend the
86 * bitmap by another 32 bits.
87 * Additional extensions are made
88 * by setting bit 31.
89 */
90 } __packed;
91  
92 /* Name Data type Units
93 * ---- --------- -----
94 *
95 * IEEE80211_RADIOTAP_TSFT __le64 microseconds
96 *
97 * Value in microseconds of the MAC's 64-bit 802.11 Time
98 * Synchronization Function timer when the first bit of the
99 * MPDU arrived at the MAC. For received frames, only.
100 *
101 * IEEE80211_RADIOTAP_CHANNEL 2 x __le16 MHz, bitmap
102 *
103 * Tx/Rx frequency in MHz, followed by flags (see below).
104 *
105 * IEEE80211_RADIOTAP_FHSS __le16 see below
106 *
107 * For frequency-hopping radios, the hop set (first byte)
108 * and pattern (second byte).
109 *
110 * IEEE80211_RADIOTAP_RATE u8 500kb/s
111 *
112 * Tx/Rx data rate
113 *
114 * IEEE80211_RADIOTAP_DBM_ANTSIGNAL s8 decibels from
115 * one milliwatt (dBm)
116 *
117 * RF signal power at the antenna, decibel difference from
118 * one milliwatt.
119 *
120 * IEEE80211_RADIOTAP_DBM_ANTNOISE s8 decibels from
121 * one milliwatt (dBm)
122 *
123 * RF noise power at the antenna, decibel difference from one
124 * milliwatt.
125 *
126 * IEEE80211_RADIOTAP_DB_ANTSIGNAL u8 decibel (dB)
127 *
128 * RF signal power at the antenna, decibel difference from an
129 * arbitrary, fixed reference.
130 *
131 * IEEE80211_RADIOTAP_DB_ANTNOISE u8 decibel (dB)
132 *
133 * RF noise power at the antenna, decibel difference from an
134 * arbitrary, fixed reference point.
135 *
136 * IEEE80211_RADIOTAP_LOCK_QUALITY __le16 unitless
137 *
138 * Quality of Barker code lock. Unitless. Monotonically
139 * nondecreasing with "better" lock strength. Called "Signal
140 * Quality" in datasheets. (Is there a standard way to measure
141 * this?)
142 *
143 * IEEE80211_RADIOTAP_TX_ATTENUATION __le16 unitless
144 *
145 * Transmit power expressed as unitless distance from max
146 * power set at factory calibration. 0 is max power.
147 * Monotonically nondecreasing with lower power levels.
148 *
149 * IEEE80211_RADIOTAP_DB_TX_ATTENUATION __le16 decibels (dB)
150 *
151 * Transmit power expressed as decibel distance from max power
152 * set at factory calibration. 0 is max power. Monotonically
153 * nondecreasing with lower power levels.
154 *
155 * IEEE80211_RADIOTAP_DBM_TX_POWER s8 decibels from
156 * one milliwatt (dBm)
157 *
158 * Transmit power expressed as dBm (decibels from a 1 milliwatt
159 * reference). This is the absolute power level measured at
160 * the antenna port.
161 *
162 * IEEE80211_RADIOTAP_FLAGS u8 bitmap
163 *
164 * Properties of transmitted and received frames. See flags
165 * defined below.
166 *
167 * IEEE80211_RADIOTAP_ANTENNA u8 antenna index
168 *
169 * Unitless indication of the Rx/Tx antenna for this packet.
170 * The first antenna is antenna 0.
171 *
172 * IEEE80211_RADIOTAP_RX_FLAGS __le16 bitmap
173 *
174 * Properties of received frames. See flags defined below.
175 *
176 * IEEE80211_RADIOTAP_TX_FLAGS __le16 bitmap
177 *
178 * Properties of transmitted frames. See flags defined below.
179 *
180 * IEEE80211_RADIOTAP_RTS_RETRIES u8 data
181 *
182 * Number of rts retries a transmitted frame used.
183 *
184 * IEEE80211_RADIOTAP_DATA_RETRIES u8 data
185 *
186 * Number of unicast retries a transmitted frame used.
187 *
188 * IEEE80211_RADIOTAP_MCS u8, u8, u8 unitless
189 *
190 * Contains a bitmap of known fields/flags, the flags, and
191 * the MCS index.
192 *
193 * IEEE80211_RADIOTAP_AMPDU_STATUS u32, u16, u8, u8 unitless
194 *
195 * Contains the AMPDU information for the subframe.
196 *
197 * IEEE80211_RADIOTAP_VHT u16, u8, u8, u8[4], u8, u8, u16
198 *
199 * Contains VHT information about this frame.
200 *
201 * IEEE80211_RADIOTAP_TIMESTAMP u64, u16, u8, u8 variable
202 *
203 * Contains timestamp information for this frame.
204 */
205 enum ieee80211_radiotap_type {
206 IEEE80211_RADIOTAP_TSFT = 0,
207 IEEE80211_RADIOTAP_FLAGS = 1,
208 IEEE80211_RADIOTAP_RATE = 2,
209 IEEE80211_RADIOTAP_CHANNEL = 3,
210 IEEE80211_RADIOTAP_FHSS = 4,
211 IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
212 IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
213 IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
214 IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
215 IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
216 IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
217 IEEE80211_RADIOTAP_ANTENNA = 11,
218 IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
219 IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
220 IEEE80211_RADIOTAP_RX_FLAGS = 14,
221 IEEE80211_RADIOTAP_TX_FLAGS = 15,
222 IEEE80211_RADIOTAP_RTS_RETRIES = 16,
223 IEEE80211_RADIOTAP_DATA_RETRIES = 17,
224  
225 IEEE80211_RADIOTAP_MCS = 19,
226 IEEE80211_RADIOTAP_AMPDU_STATUS = 20,
227 IEEE80211_RADIOTAP_VHT = 21,
228 IEEE80211_RADIOTAP_TIMESTAMP = 22,
229  
230 /* valid in every it_present bitmap, even vendor namespaces */
231 IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE = 29,
232 IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30,
233 IEEE80211_RADIOTAP_EXT = 31
234 };
235  
236 /* Channel flags. */
237 #define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */
238 #define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */
239 #define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */
240 #define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */
241 #define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */
242 #define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */
243 #define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */
244 #define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */
245 #define IEEE80211_CHAN_GSM 0x1000 /* GSM (900 MHz) */
246 #define IEEE80211_CHAN_STURBO 0x2000 /* Static Turbo */
247 #define IEEE80211_CHAN_HALF 0x4000 /* Half channel (10 MHz wide) */
248 #define IEEE80211_CHAN_QUARTER 0x8000 /* Quarter channel (5 MHz wide) */
249  
250 /* For IEEE80211_RADIOTAP_FLAGS */
251 #define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
252 * during CFP
253 */
254 #define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
255 * with short
256 * preamble
257 */
258 #define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
259 * with WEP encryption
260 */
261 #define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
262 * with fragmentation
263 */
264 #define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
265 #define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
266 * 802.11 header and payload
267 * (to 32-bit boundary)
268 */
269 #define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* bad FCS */
270  
271 /* For IEEE80211_RADIOTAP_RX_FLAGS */
272 #define IEEE80211_RADIOTAP_F_RX_BADPLCP 0x0002 /* frame has bad PLCP */
273  
274 /* For IEEE80211_RADIOTAP_TX_FLAGS */
275 #define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive
276 * retries */
277 #define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */
278 #define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
279 #define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008 /* don't expect an ack */
280  
281  
282 /* For IEEE80211_RADIOTAP_MCS */
283 #define IEEE80211_RADIOTAP_MCS_HAVE_BW 0x01
284 #define IEEE80211_RADIOTAP_MCS_HAVE_MCS 0x02
285 #define IEEE80211_RADIOTAP_MCS_HAVE_GI 0x04
286 #define IEEE80211_RADIOTAP_MCS_HAVE_FMT 0x08
287 #define IEEE80211_RADIOTAP_MCS_HAVE_FEC 0x10
288 #define IEEE80211_RADIOTAP_MCS_HAVE_STBC 0x20
289  
290 #define IEEE80211_RADIOTAP_MCS_BW_MASK 0x03
291 #define IEEE80211_RADIOTAP_MCS_BW_20 0
292 #define IEEE80211_RADIOTAP_MCS_BW_40 1
293 #define IEEE80211_RADIOTAP_MCS_BW_20L 2
294 #define IEEE80211_RADIOTAP_MCS_BW_20U 3
295 #define IEEE80211_RADIOTAP_MCS_SGI 0x04
296 #define IEEE80211_RADIOTAP_MCS_FMT_GF 0x08
297 #define IEEE80211_RADIOTAP_MCS_FEC_LDPC 0x10
298 #define IEEE80211_RADIOTAP_MCS_STBC_MASK 0x60
299 #define IEEE80211_RADIOTAP_MCS_STBC_1 1
300 #define IEEE80211_RADIOTAP_MCS_STBC_2 2
301 #define IEEE80211_RADIOTAP_MCS_STBC_3 3
302  
303 #define IEEE80211_RADIOTAP_MCS_STBC_SHIFT 5
304  
305 /* For IEEE80211_RADIOTAP_AMPDU_STATUS */
306 #define IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN 0x0001
307 #define IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN 0x0002
308 #define IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN 0x0004
309 #define IEEE80211_RADIOTAP_AMPDU_IS_LAST 0x0008
310 #define IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR 0x0010
311 #define IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN 0x0020
312  
313 /* For IEEE80211_RADIOTAP_VHT */
314 #define IEEE80211_RADIOTAP_VHT_KNOWN_STBC 0x0001
315 #define IEEE80211_RADIOTAP_VHT_KNOWN_TXOP_PS_NA 0x0002
316 #define IEEE80211_RADIOTAP_VHT_KNOWN_GI 0x0004
317 #define IEEE80211_RADIOTAP_VHT_KNOWN_SGI_NSYM_DIS 0x0008
318 #define IEEE80211_RADIOTAP_VHT_KNOWN_LDPC_EXTRA_OFDM_SYM 0x0010
319 #define IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED 0x0020
320 #define IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH 0x0040
321 #define IEEE80211_RADIOTAP_VHT_KNOWN_GROUP_ID 0x0080
322 #define IEEE80211_RADIOTAP_VHT_KNOWN_PARTIAL_AID 0x0100
323  
324 #define IEEE80211_RADIOTAP_VHT_FLAG_STBC 0x01
325 #define IEEE80211_RADIOTAP_VHT_FLAG_TXOP_PS_NA 0x02
326 #define IEEE80211_RADIOTAP_VHT_FLAG_SGI 0x04
327 #define IEEE80211_RADIOTAP_VHT_FLAG_SGI_NSYM_M10_9 0x08
328 #define IEEE80211_RADIOTAP_VHT_FLAG_LDPC_EXTRA_OFDM_SYM 0x10
329 #define IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED 0x20
330  
331 #define IEEE80211_RADIOTAP_CODING_LDPC_USER0 0x01
332 #define IEEE80211_RADIOTAP_CODING_LDPC_USER1 0x02
333 #define IEEE80211_RADIOTAP_CODING_LDPC_USER2 0x04
334 #define IEEE80211_RADIOTAP_CODING_LDPC_USER3 0x08
335  
336 /* For IEEE80211_RADIOTAP_TIMESTAMP */
337 #define IEEE80211_RADIOTAP_TIMESTAMP_UNIT_MASK 0x000F
338 #define IEEE80211_RADIOTAP_TIMESTAMP_UNIT_MS 0x0000
339 #define IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US 0x0001
340 #define IEEE80211_RADIOTAP_TIMESTAMP_UNIT_NS 0x0003
341 #define IEEE80211_RADIOTAP_TIMESTAMP_SPOS_MASK 0x00F0
342 #define IEEE80211_RADIOTAP_TIMESTAMP_SPOS_BEGIN_MDPU 0x0000
343 #define IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ 0x0010
344 #define IEEE80211_RADIOTAP_TIMESTAMP_SPOS_EO_PPDU 0x0020
345 #define IEEE80211_RADIOTAP_TIMESTAMP_SPOS_EO_MPDU 0x0030
346 #define IEEE80211_RADIOTAP_TIMESTAMP_SPOS_UNKNOWN 0x00F0
347  
348 #define IEEE80211_RADIOTAP_TIMESTAMP_FLAG_64BIT 0x00
349 #define IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT 0x01
350 #define IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY 0x02
351  
352 /*
353 * Radiotap parsing functions -- for controlled injection support
354 *
355 * Implemented in net/wireless/radiotap.c
356 * Documentation in Documentation/networking/radiotap-headers.txt
357 */
358  
359 struct radiotap_align_size {
360 uint8_t align:4, size:4;
361 };
362  
363 struct ieee80211_radiotap_namespace {
364 const struct radiotap_align_size *align_size;
365 int n_bits;
366 uint32_t oui;
367 uint8_t subns;
368 };
369  
370 struct ieee80211_radiotap_vendor_namespaces {
371 const struct ieee80211_radiotap_namespace *ns;
372 int n_ns;
373 };
374  
375 /**
376 * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args
377 * @this_arg_index: index of current arg, valid after each successful call
378 * to ieee80211_radiotap_iterator_next()
379 * @this_arg: pointer to current radiotap arg; it is valid after each
380 * call to ieee80211_radiotap_iterator_next() but also after
381 * ieee80211_radiotap_iterator_init() where it will point to
382 * the beginning of the actual data portion
383 * @this_arg_size: length of the current arg, for convenience
384 * @current_namespace: pointer to the current namespace definition
385 * (or internally %NULL if the current namespace is unknown)
386 * @is_radiotap_ns: indicates whether the current namespace is the default
387 * radiotap namespace or not
388 *
389 * @_rtheader: pointer to the radiotap header we are walking through
390 * @_max_length: length of radiotap header in cpu byte ordering
391 * @_arg_index: next argument index
392 * @_arg: next argument pointer
393 * @_next_bitmap: internal pointer to next present u32
394 * @_bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present
395 * @_vns: vendor namespace definitions
396 * @_next_ns_data: beginning of the next namespace's data
397 * @_reset_on_ext: internal; reset the arg index to 0 when going to the
398 * next bitmap word
399 *
400 * Describes the radiotap parser state. Fields prefixed with an underscore
401 * must not be used by users of the parser, only by the parser internally.
402 */
403  
404 struct ieee80211_radiotap_iterator {
405 struct ieee80211_radiotap_header *_rtheader;
406 const struct ieee80211_radiotap_vendor_namespaces *_vns;
407 const struct ieee80211_radiotap_namespace *current_namespace;
408  
409 unsigned char *_arg, *_next_ns_data;
410 unsigned int *_next_bitmap;
411  
412 unsigned char *this_arg;
413 int this_arg_index;
414 int this_arg_size;
415  
416 int is_radiotap_ns;
417  
418 int _max_length;
419 int _arg_index;
420 uint32_t _bitmap_shifter;
421 int _reset_on_ext;
422 };
423  
424 struct nexmon_radiotap_header {
425 struct ieee80211_radiotap_header header;
426 struct tsf tsf;
427 char flags;
428 unsigned char data_rate;
429 unsigned short chan_freq;
430 unsigned short chan_flags;
431 char dbm_antsignal;
432 char dbm_antnoise;
433 #ifdef RADIOTAP_MCS
434 char mcs[3];
435 char PAD;
436 #endif
437 #ifdef RADIOTAP_VHT
438 unsigned short vht_known;
439 unsigned char vht_flags;
440 unsigned char vht_bandwidth;
441 unsigned char vht_mcs_nss[4];
442 unsigned char vht_coding;
443 unsigned char vht_group_id;
444 unsigned short vht_partial_aid;
445 #endif
446 #ifdef RADIOTAP_VENDOR
447 unsigned char vendor_oui[3];
448 unsigned char vendor_sub_namespace;
449 unsigned short vendor_skip_length;
450 #endif
451 } __attribute__((packed));
452  
453 extern int
454 ieee80211_radiotap_iterator_init(struct ieee80211_radiotap_iterator *iterator,
455 struct ieee80211_radiotap_header *radiotap_header,
456 int max_length,
457 const struct ieee80211_radiotap_vendor_namespaces *vns);
458  
459 extern int
460 ieee80211_radiotap_iterator_next(struct ieee80211_radiotap_iterator *iterator);
461  
462 #endif /* IEEE80211_RADIOTAP_H */