1 /*
2  * Radiotap parser
3  *
4  * Copyright 2007		Andy Green <andy@warmcat.com>
5  * Copyright 2009		Johannes Berg <johannes@sipsolutions.net>
6  *
7  * SPDX-License-Identifier: (ISC OR GPL-2.0-only)
8  */
9 
10 #ifndef __RADIOTAP_ITER_H
11 #define __RADIOTAP_ITER_H
12 
13 #define RADIOTAP_SUPPORT_OVERRIDES
14 
15 #include <glib.h>
16 #include "packet-ieee80211-radiotap-defs.h"
17 
18 /* Radiotap header iteration
19  *   implemented in radiotap.c
20  */
21 
22 struct radiotap_override {
23 	guint8 field;
24 	guint align:4, size:4;
25 };
26 
27 struct radiotap_align_size {
28 	guint align:4, size:4;
29 };
30 
31 struct ieee80211_radiotap_namespace {
32 	const struct radiotap_align_size *align_size;
33 	int n_bits;
34 	guint32 oui;
35 	guint8 subns;
36 };
37 
38 struct ieee80211_radiotap_vendor_namespaces {
39 	const struct ieee80211_radiotap_namespace *ns;
40 	int n_ns;
41 };
42 
43 /**
44  * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args
45  *
46  * Describes the radiotap parser state. Fields prefixed with an underscore
47  * must not be used by users of the parser, only by the parser internally.
48  */
49 
50 struct ieee80211_radiotap_iterator {
51 	struct ieee80211_radiotap_header *_rtheader;				/**< pointer to the radiotap header we are walking through */
52 	const struct ieee80211_radiotap_vendor_namespaces *_vns;		/**< vendor namespace definitions*/
53 	const struct ieee80211_radiotap_namespace *current_namespace;		/**< pointer to the current namespace definition (or internally
54 											%NULL if the current namespace is unknown)*/
55 
56 	unsigned char *_arg, *_next_ns_data;					/**< beginning of the next namespace's data */
57 	guint32 *_next_bitmap;							/**< internal pointer to next present u32 */
58 
59 	unsigned char *this_arg;						/**< pointer to current radiotap arg; it is valid after each call
60 											to ieee80211_radiotap_iterator_next() but also after
61 											ieee80211_radiotap_iterator_init() where it will point to
62 											the beginning of the actual data portion */
63 #ifdef RADIOTAP_SUPPORT_OVERRIDES
64 	const struct radiotap_override *overrides;				/**< override standard radiotap fields */
65 	int n_overrides;							/**< number of overrides */
66 #endif
67 	int this_arg_index;							/**< index of current arg, valid after each successful call to
68 										ieee80211_radiotap_iterator_next() */
69 	int this_arg_size;							/**< length of the current arg, for convenience*/
70 
71 	int is_radiotap_ns;
72 	int tlv_mode;
73 
74 	int _max_length;							/**< length of radiotap header in cpu byte ordering */
75 	int _arg_index;								/**< next argument index */
76 	guint32 _bitmap_shifter;						/**< internal shifter for curr u32 bitmap, b0 set == arg present */
77 	int _reset_on_ext;							/**< internal; reset the arg index to 0 when going to the next bitmap word */
78 };
79 
80 extern int ieee80211_radiotap_iterator_init(
81 	struct ieee80211_radiotap_iterator *iterator,
82 	struct ieee80211_radiotap_header *radiotap_header,
83 	int max_length, const struct ieee80211_radiotap_vendor_namespaces *vns);
84 
85 extern int ieee80211_radiotap_iterator_next(
86 	struct ieee80211_radiotap_iterator *iterator);
87 
88 #endif /* __RADIOTAP_ITER_H */
89