From fe6e575158212753e24d39405db573e71cfdb54e Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 3 Jun 2017 08:55:08 -0700 Subject: [PATCH] Add missing radiotap parsing fields --- include/tins/radiotap.h | 16 +++- include/tins/utils.h | 2 + include/tins/utils/radiotap_writer.h | 2 +- src/radiotap.cpp | 4 + src/utils/radiotap_parser.cpp | 2 + tests/src/radiotap_test.cpp | 126 ++++++++++++++++++++++++++- 6 files changed, 149 insertions(+), 3 deletions(-) diff --git a/include/tins/radiotap.h b/include/tins/radiotap.h index 98a8c7f..520456b 100644 --- a/include/tins/radiotap.h +++ b/include/tins/radiotap.h @@ -134,6 +134,11 @@ public: */ typedef PDUOption option; + /** + * The type used to store the options payload + */ + typedef std::vector options_payload_type; + /** * \brief Default constructor. */ @@ -407,6 +412,15 @@ public: */ void add_option(const option& opt); + /** + * \brief Gets the options payload + * + * Use Utils::RadioTapParser to iterate these options and extract fields manually, + * in case you want to have deeper access into the option types/values stored in + * a RadioTap frame. + */ + const options_payload_type& options_payload() const; + /** * \sa PDU::clone */ @@ -438,7 +452,7 @@ private: option do_find_option(PresentFlags type) const; radiotap_header header_; - std::vector options_payload_; + options_payload_type options_payload_; }; } diff --git a/include/tins/utils.h b/include/tins/utils.h index ea13730..a680966 100644 --- a/include/tins/utils.h +++ b/include/tins/utils.h @@ -35,6 +35,8 @@ #include "utils/routing_utils.h" #include "utils/resolve_utils.h" #include "utils/pdu_utils.h" +#include "utils/radiotap_parser.h" +#include "utils/radiotap_writer.h" namespace Tins { diff --git a/include/tins/utils/radiotap_writer.h b/include/tins/utils/radiotap_writer.h index eb1efd3..7d08326 100644 --- a/include/tins/utils/radiotap_writer.h +++ b/include/tins/utils/radiotap_writer.h @@ -32,7 +32,7 @@ #include #include -#include "radiotap.h" +#include "../radiotap.h" namespace Tins { namespace Utils { diff --git a/src/radiotap.cpp b/src/radiotap.cpp index a71bc8c..8d60266 100644 --- a/src/radiotap.cpp +++ b/src/radiotap.cpp @@ -217,6 +217,10 @@ void RadioTap::add_option(const option& opt) { writer.write_option(opt); } +const RadioTap::options_payload_type& RadioTap::options_payload() const { + return options_payload_; +} + // Getter for RadioTap fields uint8_t RadioTap::version() const { return header_.it_version; diff --git a/src/utils/radiotap_parser.cpp b/src/utils/radiotap_parser.cpp index 7655de2..0caa0ab 100644 --- a/src/utils/radiotap_parser.cpp +++ b/src/utils/radiotap_parser.cpp @@ -57,6 +57,8 @@ const RadioTapParser::FieldMetadata RadioTapParser::RADIOTAP_METADATA[] = { { 1, 1 }, // DATA_RETRIES { 8, 4 }, // CHANNEL_PLUS { 3, 1 }, // MCS + { 8, 4 }, // A-MPDU status + { 12, 2 } // VHT }; const uint32_t RadioTapParser::MAX_RADIOTAP_FIELD = sizeof(RADIOTAP_METADATA) / diff --git a/tests/src/radiotap_test.cpp b/tests/src/radiotap_test.cpp index f915f44..c5c0893 100644 --- a/tests/src/radiotap_test.cpp +++ b/tests/src/radiotap_test.cpp @@ -24,7 +24,8 @@ class RadioTapTest : public testing::Test { public: static const uint8_t expected_packet[], expected_packet1[], expected_packet2[], expected_packet3[], - expected_packet4[], expected_packet5[]; + expected_packet4[], expected_packet5[], + expected_packet6[]; }; const uint8_t RadioTapTest::expected_packet[] = { @@ -209,6 +210,120 @@ const uint8_t RadioTapTest::expected_packet5[] = { 232, 71, 84, 12, 235, 224, 159, 132, 178, 117, 5, 43, 177, 190, 152, 170 }; +const uint8_t RadioTapTest::expected_packet6[] = { + 0, 0, 32, 0, 42, 72, 24, 0, 0, 0, 158, 9, 128, 4, 183, 3, 0, 0, + 15, 0, 3, 0, 0, 0, 74, 26, 76, 0, 0, 0, 0, 0, 136, 66, 44, 0, 68, + 101, 13, 96, 131, 48, 232, 51, 129, 72, 93, 240, 232, 51, 129, + 72, 93, 240, 240, 5, 0, 0, 227, 36, 0, 32, 5, 0, 0, 0, 67, 145, + 79, 185, 3, 42, 82, 220, 135, 236, 253, 12, 46, 218, 76, 245, 52, + 70, 20, 63, 57, 19, 30, 95, 42, 2, 48, 16, 7, 57, 155, 82, 168, + 108, 24, 197, 107, 149, 155, 155, 175, 137, 188, 75, 174, 135, + 231, 101, 16, 79, 230, 97, 208, 237, 30, 15, 251, 194, 164, 60, + 38, 6, 168, 77, 26, 62, 129, 91, 58, 24, 195, 123, 137, 248, 141, + 234, 102, 171, 250, 106, 205, 210, 175, 203, 126, 245, 137, 127, + 13, 33, 55, 240, 49, 165, 14, 93, 112, 107, 165, 91, 94, 127, + 157, 81, 241, 9, 165, 165, 184, 127, 142, 209, 20, 208, 170, 105, + 102, 58, 225, 74, 196, 73, 193, 162, 169, 99, 4, 4, 53, 214, 224 + , 199, 183, 214, 207, 181, 191, 53, 64, 51, 20, 7, 245, 225, 249, + 227, 233, 76, 12, 55, 154, 210, 175, 89, 155, 0, 75, 41, 167, + 138, 23, 10, 66, 103, 133, 113, 238, 154, 255, 121, 210, 114, 57, + 101, 29, 4, 127, 62, 127, 138, 239, 213, 254, 128, 182, 193, 175 + , 26, 187, 52, 55, 134, 144, 46, 86, 84, 198, 65, 219, 115, 57, + 255, 231, 6, 167, 10, 159, 85, 70, 203, 139, 88, 94, 176, 211, + 245, 214, 47, 153, 8, 204, 17, 97, 121, 166, 137, 155, 171, 212, + 141, 160, 20, 63, 197, 201, 0, 165, 126, 161, 68, 64, 153, 255, + 53, 254, 1, 99, 152, 177, 12, 132, 212, 30, 170, 14, 190, 66, 215 + , 51, 155, 142, 65, 109, 177, 236, 104, 87, 150, 137, 72, 220, 67 + , 117, 136, 9, 234, 194, 50, 5, 2, 28, 15, 156, 159, 72, 20, 167, + 228, 6, 81, 207, 162, 200, 65, 32, 46, 10, 153, 191, 178, 5, 136 + , 20, 211, 198, 150, 12, 248, 217, 76, 74, 168, 95, 85, 129, 84, + 25, 92, 124, 160, 49, 223, 152, 169, 10, 231, 213, 1, 184, 240, + 19, 177, 3, 219, 222, 238, 223, 45, 229, 79, 125, 37, 112, 54, 39 + , 150, 70, 137, 174, 122, 34, 184, 176, 141, 30, 208, 66, 85, 63, + 2, 251, 19, 249, 148, 29, 41, 245, 239, 106, 222, 229, 55, 209, + 112, 157, 19, 126, 237, 94, 71, 215, 197, 117, 132, 248, 19, 0, + 134, 199, 41, 176, 38, 114, 18, 30, 228, 122, 105, 193, 171, 128, + 74, 212, 114, 21, 4, 109, 226, 11, 86, 109, 185, 0, 177, 1, 208, + 64, 41, 149, 106, 49, 2, 47, 165, 223, 220, 163, 35, 26, 100, 88 + , 63, 54, 115, 94, 60, 244, 170, 166, 237, 227, 30, 7, 254, 91, + 203, 132, 75, 135, 65, 79, 9, 60, 231, 38, 5, 183, 72, 92, 174, + 250, 192, 205, 96, 185, 65, 227, 217, 181, 228, 209, 218, 4, 184, + 163, 191, 122, 149, 127, 242, 232, 44, 223, 156, 25, 105, 141, + 240, 88, 236, 203, 169, 254, 41, 0, 247, 200, 12, 177, 97, 126, 5 + , 72, 227, 147, 98, 244, 221, 109, 204, 141, 57, 148, 9, 53, 66, + 175, 240, 168, 190, 84, 143, 120, 169, 234, 133, 37, 253, 164, + 202, 196, 235, 22, 12, 1, 35, 168, 255, 208, 244, 47, 99, 85, 98, + 221, 185, 253, 74, 137, 129, 81, 199, 51, 21, 85, 144, 44, 153, + 64, 254, 165, 86, 184, 176, 236, 2, 172, 54, 42, 26, 117, 10, 36, + 74, 158, 11, 57, 191, 221, 161, 151, 87, 186, 88, 135, 198, 168, + 152, 145, 129, 255, 110, 22, 16, 241, 64, 107, 216, 111, 159, + 133, 69, 189, 166, 45, 151, 120, 64, 221, 44, 68, 64, 189, 49, + 187, 106, 83, 99, 250, 138, 218, 21, 172, 73, 89, 155, 230, 223, + 242, 114, 13, 130, 110, 130, 144, 244, 165, 99, 201, 179, 205, 48 + , 250, 245, 181, 71, 95, 73, 78, 52, 42, 117, 189, 224, 242, 242, + 164, 66, 129, 78, 246, 219, 50, 148, 171, 93, 25, 229, 102, 13, + 102, 116, 234, 227, 211, 246, 31, 247, 41, 56, 47, 90, 155, 216, + 207, 58, 67, 163, 211, 48, 64, 155, 108, 151, 181, 109, 51, 11, + 213, 91, 74, 102, 158, 23, 248, 57, 203, 5, 229, 13, 117, 18, 186 + , 24, 89, 76, 143, 207, 173, 176, 158, 116, 85, 178, 148, 194, + 239, 206, 92, 23, 148, 16, 93, 80, 95, 25, 218, 69, 175, 227, 23, + 225, 52, 231, 52, 192, 50, 243, 110, 233, 248, 125, 45, 67, 20, + 198, 14, 235, 216, 91, 111, 37, 153, 198, 198, 30, 4, 28, 248, + 253, 174, 69, 14, 10, 171, 255, 146, 14, 61, 40, 81, 39, 191, 124 + , 130, 108, 183, 40, 111, 84, 253, 217, 91, 115, 250, 27, 91, 141 + , 35, 92, 20, 145, 114, 82, 43, 177, 137, 227, 234, 164, 125, 152 + , 23, 55, 155, 136, 200, 51, 81, 170, 181, 78, 191, 129, 70, 199, + 123, 117, 188, 91, 153, 96, 145, 114, 48, 172, 227, 4, 71, 192, + 30, 52, 25, 98, 201, 169, 28, 148, 35, 136, 6, 128, 24, 189, 153, + 219, 215, 21, 98, 209, 135, 118, 173, 16, 225, 79, 43, 158, 39, + 249, 142, 68, 233, 83, 225, 250, 40, 208, 131, 250, 191, 71, 110, + 26, 51, 7, 44, 113, 189, 250, 155, 109, 74, 39, 227, 208, 226, + 221, 136, 42, 244, 160, 104, 59, 228, 130, 57, 192, 194, 147, 199 + , 127, 161, 85, 102, 25, 176, 83, 222, 222, 139, 88, 217, 77, 89, + 223, 113, 38, 162, 233, 92, 199, 224, 209, 108, 90, 133, 81, 211 + , 103, 4, 50, 111, 241, 133, 97, 147, 194, 177, 160, 207, 200, 13 + , 13, 102, 57, 198, 61, 247, 117, 26, 89, 160, 94, 246, 232, 193, + 162, 69, 128, 250, 75, 125, 163, 27, 17, 169, 125, 79, 142, 15, + 20, 181, 58, 166, 191, 225, 30, 211, 237, 232, 24, 150, 169, 76, + 135, 67, 49, 44, 46, 183, 55, 201, 38, 151, 137, 26, 16, 243, 251 + , 54, 194, 114, 18, 122, 85, 103, 28, 204, 240, 29, 217, 42, 95, + 31, 95, 83, 233, 206, 13, 91, 8, 130, 87, 135, 47, 168, 42, 27, + 78, 187, 25, 213, 253, 129, 132, 253, 189, 199, 177, 83, 124, 184 + , 10, 130, 117, 98, 102, 242, 91, 196, 3, 17, 96, 35, 92, 57, 27, + 62, 177, 176, 188, 135, 202, 195, 145, 206, 196, 57, 27, 191, 27 + , 120, 1, 166, 216, 219, 3, 218, 238, 212, 197, 247, 6, 236, 196, + 34, 232, 157, 207, 241, 15, 175, 126, 77, 157, 43, 223, 0, 115, + 239, 142, 249, 10, 30, 0, 59, 134, 79, 41, 116, 195, 36, 41, 223, + 72, 245, 113, 136, 12, 51, 3, 164, 46, 59, 177, 101, 184, 161, + 133, 161, 138, 197, 52, 146, 106, 161, 124, 197, 83, 190, 79, 35, + 139, 233, 72, 178, 247, 181, 102, 12, 176, 199, 238, 229, 27, + 158, 169, 146, 143, 98, 57, 61, 83, 176, 127, 101, 197, 29, 15, + 86, 131, 13, 182, 103, 87, 245, 41, 148, 116, 188, 172, 5, 94, + 133, 45, 33, 125, 194, 44, 211, 157, 172, 44, 103, 198, 77, 93, + 169, 31, 200, 61, 101, 229, 228, 121, 129, 18, 238, 192, 222, 61, + 7, 247, 88, 70, 31, 206, 141, 252, 61, 252, 209, 40, 233, 151, + 183, 84, 140, 249, 67, 55, 207, 164, 168, 102, 165, 196, 132, 167 + , 40, 58, 119, 254, 126, 234, 57, 163, 189, 155, 9, 247, 71, 132, + 221, 51, 107, 230, 95, 57, 189, 36, 28, 102, 161, 39, 230, 168, + 72, 86, 99, 3, 11, 125, 49, 171, 199, 144, 231, 222, 170, 23, 164 + , 233, 33, 227, 212, 150, 227, 162, 192, 120, 4, 167, 189, 123, + 154, 229, 35, 142, 121, 247, 222, 123, 19, 20, 135, 13, 138, 135, + 3, 97, 43, 59, 133, 33, 9, 111, 236, 246, 41, 181, 162, 140, 254 + , 95, 177, 180, 8, 14, 124, 90, 171, 114, 74, 52, 149, 203, 74, + 254, 189, 219, 0, 239, 188, 185, 183, 136, 187, 78, 142, 54, 218, + 250, 217, 165, 101, 75, 67, 94, 204, 66, 12, 40, 159, 90, 158, + 50, 45, 144, 176, 127, 43, 62, 126, 102, 66, 99, 31, 142, 61, 33, + 202, 239, 243, 136, 173, 66, 14, 106, 189, 13, 231, 105, 208, 90 + , 192, 88, 191, 190, 8, 28, 207, 137, 100, 100, 253, 205, 187, 33 + , 201, 175, 14, 76, 27, 141, 80, 229, 142, 85, 143, 9, 224, 221, + 69, 64, 2, 217, 80, 234, 23, 226, 250, 152, 38, 177, 235, 110, + 121, 77, 47, 189, 97, 244, 37, 134, 124, 144, 81, 226, 219, 137, + 254, 164, 176, 78, 70, 118, 221, 197, 62, 137, 182, 83, 253, 91, + 181, 108, 244, 119, 133, 13, 154, 235, 123, 110, 127, 184, 123, + 150, 59, 105, 4, 187, 223, 16, 154, 244, 241, 253, 24, 35, 160, + 164, 143, 87, 89, 97, 79, 145, 16, 48, 248, 198, 140, 48 +}; + TEST_F(RadioTapTest, DefaultConstructor) { RadioTap radio; EXPECT_TRUE((radio.flags() & RadioTap::FCS) != 0); @@ -446,6 +561,15 @@ TEST_F(RadioTapTest, RadioTapParsing) { EXPECT_FALSE(parser.advance_field()); } +TEST_F(RadioTapTest, RadioTapParsingBroken1) { + vector buffer(expected_packet6+4, expected_packet6 + sizeof(expected_packet6)-4); + RadioTapParser parser(buffer); + while (parser.has_fields()) { + parser.advance_field(); + } + EXPECT_FALSE(parser.has_fields()); +} + TEST_F(RadioTapTest, RadioTapParsingMultipleNamespaces) { vector buffer(expected_packet4+4, expected_packet4 + sizeof(expected_packet4)-4); RadioTapParser parser(buffer);