libtins  4.0
radiotap_parser.h
1 /*
2  * Copyright (c) 2017, Matias Fontanini
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #include <tins/config.h>
31 
32 #if !defined(TINS_RADIOTAP_PARSER_H) && defined(TINS_HAVE_DOT11)
33 #define TINS_RADIOTAP_PARSER_H
34 
35 #include <stdint.h>
36 #include <tins/macros.h>
37 #include <tins/radiotap.h>
38 #include <tins/pdu_option.h>
39 
40 namespace Tins {
41 namespace Utils {
42 
43 struct RadioTapFlags;
44 
53 public:
58  RADIOTAP_NS,
59  VENDOR_NS,
60  UNKNOWN_NS
61  };
62 
66  struct FieldMetadata {
67  uint32_t size;
68  uint32_t alignment;
69  };
70 
75 
79  static const uint32_t MAX_RADIOTAP_FIELD;
80 
92  RadioTapParser(const std::vector<uint8_t>& buffer);
93 
98 
104  uint32_t current_namespace_index() const;
105 
110 
115 
119  const uint8_t* current_option_ptr() const;
120 
129  bool advance_field();
130 
137  bool advance_namespace();
138 
143 
153 
157  bool has_fields() const;
158 
164  bool has_field(RadioTap::PresentFlags flag) const;
165 private:
166  const uint8_t* find_options_start() const;
167  bool advance_to_first_field();
168  bool advance_to_next_field();
169  bool skip_current_field();
170  bool advance_to_next_namespace();
171  const RadioTapFlags* get_flags_ptr() const;
172  void load_current_flags();
173  bool is_field_set(uint32_t bit, const RadioTapFlags* flags) const;
174 
175  const uint8_t* start_;
176  const uint8_t* end_;
177  const uint8_t* current_ptr_;
178  uint64_t current_bit_;
179  uint32_t current_flags_;
180  uint32_t namespace_index_;
181  NamespaceType current_namespace_;
182 };
183 
184 } // Utils
185 } // Tins
186 
187 #endif // TINS_RADIOTAP_PARSER_H
bool has_field(RadioTap::PresentFlags flag) const
Indicates whether the provided field is set.
Definition: radiotap_parser.cpp:239
NamespaceType
Definition: radiotap_parser.h:57
Definition: radiotap_parser.h:66
bool skip_to_field(RadioTap::PresentFlags flag)
Skips all fields until the provided one is found.
Definition: radiotap_parser.cpp:228
PresentFlags
Flags used in the present field.
Definition: radiotap.h:85
const uint8_t * current_option_ptr() const
Definition: radiotap_parser.cpp:188
RadioTap::PresentFlags current_field() const
Definition: radiotap_parser.cpp:176
Represents a PDU option field.
Definition: pdu_option.h:201
static const uint32_t MAX_RADIOTAP_FIELD
Definition: radiotap_parser.h:79
bool advance_namespace()
Advances to the next namespace.
Definition: radiotap_parser.cpp:215
static const FieldMetadata RADIOTAP_METADATA[]
Definition: radiotap_parser.h:74
bool advance_field()
Advances to the next option.
Definition: radiotap_parser.cpp:192
RadioTap::PresentFlags namespace_flags() const
Definition: radiotap_parser.cpp:222
RadioTapParser(const std::vector< uint8_t > &buffer)
Constructs a RadioTap parser around a payload.
Definition: radiotap_parser.cpp:145
The Tins namespace.
Definition: address_range.h:38
RadioTap::option current_option()
Definition: radiotap_parser.cpp:180
bool has_fields() const
Definition: radiotap_parser.cpp:235
NamespaceType current_namespace() const
Definition: radiotap_parser.cpp:168
uint32_t current_namespace_index() const
Gets a 0 index based namespace index.
Definition: radiotap_parser.cpp:172
Allows parsing RadioTap options.
Definition: radiotap_parser.h:52
Definition: radiotap_parser.cpp:103