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