libtins 4.5
Loading...
Searching...
No Matches
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
40namespace Tins {
41namespace Utils {
42
43struct RadioTapFlags;
44
53public:
58 RADIOTAP_NS,
59 VENDOR_NS,
60 UNKNOWN_NS
61 };
62
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
123 const uint8_t* current_option_ptr() const;
124
133 bool advance_field();
134
141 bool advance_namespace();
142
147
157
161 bool has_fields() const;
162
168 bool has_field(RadioTap::PresentFlags flag) const;
169private:
170 const uint8_t* find_options_start() const;
171 bool advance_to_first_field();
172 bool advance_to_next_field();
173 bool skip_current_field();
174 bool advance_to_next_namespace();
175 const RadioTapFlags* get_flags_ptr() const;
176 void load_current_flags();
177 bool is_field_set(uint32_t bit, const RadioTapFlags* flags) const;
178
179 const uint8_t* start_;
180 const uint8_t* end_;
181 const uint8_t* current_ptr_;
182 uint64_t current_bit_;
183 uint32_t current_flags_;
184 uint32_t namespace_index_;
185 NamespaceType current_namespace_;
186};
187
188} // Utils
189} // Tins
190
191#endif // TINS_RADIOTAP_PARSER_H
Represents a PDU option field.
Definition rsn_information.h:43
PresentFlags
Flags used in the present field.
Definition radiotap.h:85
Allows parsing RadioTap options.
Definition radiotap_parser.h:52
bool advance_field()
Advances to the next option.
Definition radiotap_parser.cpp:189
RadioTap::PresentFlags namespace_flags() const
Definition radiotap_parser.cpp:219
static const FieldMetadata RADIOTAP_METADATA[]
Definition radiotap_parser.h:74
bool has_field(RadioTap::PresentFlags flag) const
Indicates whether the provided field is set.
Definition radiotap_parser.cpp:236
RadioTap::PresentFlags current_field() const
Definition radiotap_parser.cpp:173
static const uint32_t MAX_RADIOTAP_FIELD
Definition radiotap_parser.h:79
uint32_t current_namespace_index() const
Gets a 0 index based namespace index.
Definition radiotap_parser.cpp:169
NamespaceType current_namespace() const
Definition radiotap_parser.cpp:165
NamespaceType
Definition radiotap_parser.h:57
const uint8_t * current_option_ptr() const
Gets the pointer at which the current option is located.
Definition radiotap_parser.cpp:185
RadioTapParser(const std::vector< uint8_t > &buffer)
Constructs a RadioTap parser around a payload.
Definition radiotap_parser.cpp:142
bool skip_to_field(RadioTap::PresentFlags flag)
Skips all fields until the provided one is found.
Definition radiotap_parser.cpp:225
bool advance_namespace()
Advances to the next namespace.
Definition radiotap_parser.cpp:212
bool has_fields() const
Definition radiotap_parser.cpp:232
RadioTap::option current_option()
Definition radiotap_parser.cpp:177
The Tins namespace.
Definition address_range.h:38
Definition radiotap_parser.cpp:103
Definition radiotap_parser.h:66