libtins  4.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
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 #ifndef TINS_RADIOTAP_PARSER_H
31 #define TINS_RADIOTAP_PARSER_H
32 
33 #include <stdint.h>
34 #include "../macros.h"
35 #include "../radiotap.h"
36 #include "../pdu_option.h"
37 
38 namespace Tins {
39 namespace Utils {
40 
41 struct RadioTapFlags;
42 
51 public:
56  RADIOTAP_NS,
57  VENDOR_NS,
58  UNKNOWN_NS
59  };
60 
64  struct FieldMetadata {
65  uint32_t size;
66  uint32_t alignment;
67  };
68 
73 
77  static const uint32_t MAX_RADIOTAP_FIELD;
78 
90  RadioTapParser(const std::vector<uint8_t>& buffer);
91 
96 
102  uint32_t current_namespace_index() const;
103 
108 
113 
117  const uint8_t* current_option_ptr() const;
118 
127  bool advance_field();
128 
135  bool advance_namespace();
136 
141 
151 
155  bool has_fields() const;
156 
162  bool has_field(RadioTap::PresentFlags flag) const;
163 private:
164  const uint8_t* find_options_start() const;
165  bool advance_to_first_field();
166  bool advance_to_next_field();
167  bool skip_current_field();
168  bool advance_to_next_namespace();
169  const RadioTapFlags* get_flags_ptr() const;
170  void load_current_flags();
171  bool is_field_set(uint32_t bit, const RadioTapFlags* flags) const;
172 
173  const uint8_t* start_;
174  const uint8_t* end_;
175  const uint8_t* current_ptr_;
176  uint64_t current_bit_;
177  uint32_t current_flags_;
178  uint32_t namespace_index_;
179  NamespaceType current_namespace_;
180 };
181 
182 } // Utils
183 } // Tins
184 
185 #endif // TINS_RADIOTAP_PARSER_H
bool has_field(RadioTap::PresentFlags flag) const
Indicates whether the provided field is set.
Definition: radiotap_parser.cpp:233
NamespaceType
Definition: radiotap_parser.h:55
Definition: radiotap_parser.h:64
bool skip_to_field(RadioTap::PresentFlags flag)
Skips all fields until the provided one is found.
Definition: radiotap_parser.cpp:222
PresentFlags
Flags used in the present field.
Definition: radiotap.h:85
const uint8_t * current_option_ptr() const
Definition: radiotap_parser.cpp:182
RadioTap::PresentFlags current_field() const
Definition: radiotap_parser.cpp:170
Represents a PDU option field.
Definition: pdu_option.h:201
static const uint32_t MAX_RADIOTAP_FIELD
Definition: radiotap_parser.h:77
bool advance_namespace()
Advances to the next namespace.
Definition: radiotap_parser.cpp:209
static const FieldMetadata RADIOTAP_METADATA[]
Definition: radiotap_parser.h:72
bool advance_field()
Advances to the next option.
Definition: radiotap_parser.cpp:186
RadioTap::PresentFlags namespace_flags() const
Definition: radiotap_parser.cpp:216
RadioTapParser(const std::vector< uint8_t > &buffer)
Constructs a RadioTap parser around a payload.
Definition: radiotap_parser.cpp:142
RadioTap::option current_option()
Definition: radiotap_parser.cpp:174
bool has_fields() const
Definition: radiotap_parser.cpp:229
NamespaceType current_namespace() const
Definition: radiotap_parser.cpp:162
uint32_t current_namespace_index() const
Gets a 0 index based namespace index.
Definition: radiotap_parser.cpp:166
Allows parsing RadioTap options.
Definition: radiotap_parser.h:50
Definition: radiotap_parser.cpp:100