Loading system/stack/include/advertise_data_parser.h +24 −0 Original line number Diff line number Diff line Loading @@ -18,9 +18,31 @@ #pragma once #include <array> #include <vector> // Scan Response data from Traxxas static constexpr std::array<uint8_t, 18> trx_quirk{ {0x14, 0x09, 0x54, 0xFF, 0xFF, 0x20, 0x42, 0x4C, 0x45, 0x05, 0x12, 0xFF, 0x00, 0xE8, 0x03, 0x02, 0x0A, 0x00}}; class AdvertiseDataParser { // Return true if the packet is malformed, but should be considered valid for // compatibility with already existing devices static bool MalformedPacketQuirk(const std::vector<uint8_t>& ad, size_t position) { auto data_start = ad.begin() + position; // Traxxas - bad name length if (std::equal(data_start, data_start + 3, trx_quirk.begin()) && std::equal(data_start + 5, data_start + 11, trx_quirk.begin() + 5) && std::equal(data_start + 12, data_start + 18, trx_quirk.begin() + 12)) { return true; } return false; } public: /** * Return true if this |ad| represent properly formatted advertising data. Loading @@ -45,6 +67,8 @@ class AdvertiseDataParser { // If the length of the current field would exceed the total data length, // then the data is badly formatted. if (position + len >= ad_len) { if (MalformedPacketQuirk(ad, position)) return true; return false; } Loading system/stack/test/ad_parser_unittest.cc +27 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,33 @@ TEST(AdvertiseDataParserTest, IsValidGood) { 0xa, 0x32, 0x39, 0x3a, 0x65, 0x32, 0x05, 0x12, 0x50, 0x00, 0x50, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; EXPECT_TRUE(AdvertiseDataParser::IsValid(data3)); // Test Quirk for Traxxas (bad name length, should be 0x11 is 0x14) const std::vector<uint8_t> data4{0x14, 0x09, 0x54, 0x52, 0x58, 0x20, 0x42, 0x4C, 0x45, 0x05, 0x12, 0x60, 0x00, 0xE8, 0x03, 0x02, 0x0A, 0x00}; EXPECT_TRUE(AdvertiseDataParser::IsValid(data4)); // Test Quirk for Traxxas (bad name length, should be 0x11 is 0x14) const std::vector<uint8_t> data5{0x14, 0x09, 0x54, 0x51, 0x69, 0x20, 0x42, 0x4C, 0x45, 0x05, 0x12, 0x64, 0x00, 0xE8, 0x03, 0x02, 0x0A, 0x00}; EXPECT_TRUE(AdvertiseDataParser::IsValid(data5)); // Test Quirk for Traxxas (bad name length, should be 0x11 is 0x14) const std::vector<uint8_t> data6{0x14, 0x09, 0x54, 0x51, 0x69, 0x20, 0x42, 0x4C, 0x45, 0x05, 0x12, 0x60, 0x00, 0xE8, 0x03, 0x02, 0x0A, 0x00}; EXPECT_TRUE(AdvertiseDataParser::IsValid(data6)); // Test Quirk for Traxxas (bad length, should be 0x11 is 0x14) // scan response glued after advertise data const std::vector<uint8_t> data7{ 0x02, 0x01, 0x06, 0x11, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0xB1, 0x73, 0x41, 0xE7, 0xF3, 0xC4, 0xB4, 0x80, 0x08, 0x14, 0x09, 0x54, 0x51, 0x69, 0x20, 0x42, 0x4C, 0x45, 0x05, 0x12, 0x60, 0x00, 0xE8, 0x03, 0x02, 0x0A, 0x00}; EXPECT_TRUE(AdvertiseDataParser::IsValid(data7)); } TEST(AdvertiseDataParserTest, GetFieldByType) { Loading Loading
system/stack/include/advertise_data_parser.h +24 −0 Original line number Diff line number Diff line Loading @@ -18,9 +18,31 @@ #pragma once #include <array> #include <vector> // Scan Response data from Traxxas static constexpr std::array<uint8_t, 18> trx_quirk{ {0x14, 0x09, 0x54, 0xFF, 0xFF, 0x20, 0x42, 0x4C, 0x45, 0x05, 0x12, 0xFF, 0x00, 0xE8, 0x03, 0x02, 0x0A, 0x00}}; class AdvertiseDataParser { // Return true if the packet is malformed, but should be considered valid for // compatibility with already existing devices static bool MalformedPacketQuirk(const std::vector<uint8_t>& ad, size_t position) { auto data_start = ad.begin() + position; // Traxxas - bad name length if (std::equal(data_start, data_start + 3, trx_quirk.begin()) && std::equal(data_start + 5, data_start + 11, trx_quirk.begin() + 5) && std::equal(data_start + 12, data_start + 18, trx_quirk.begin() + 12)) { return true; } return false; } public: /** * Return true if this |ad| represent properly formatted advertising data. Loading @@ -45,6 +67,8 @@ class AdvertiseDataParser { // If the length of the current field would exceed the total data length, // then the data is badly formatted. if (position + len >= ad_len) { if (MalformedPacketQuirk(ad, position)) return true; return false; } Loading
system/stack/test/ad_parser_unittest.cc +27 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,33 @@ TEST(AdvertiseDataParserTest, IsValidGood) { 0xa, 0x32, 0x39, 0x3a, 0x65, 0x32, 0x05, 0x12, 0x50, 0x00, 0x50, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; EXPECT_TRUE(AdvertiseDataParser::IsValid(data3)); // Test Quirk for Traxxas (bad name length, should be 0x11 is 0x14) const std::vector<uint8_t> data4{0x14, 0x09, 0x54, 0x52, 0x58, 0x20, 0x42, 0x4C, 0x45, 0x05, 0x12, 0x60, 0x00, 0xE8, 0x03, 0x02, 0x0A, 0x00}; EXPECT_TRUE(AdvertiseDataParser::IsValid(data4)); // Test Quirk for Traxxas (bad name length, should be 0x11 is 0x14) const std::vector<uint8_t> data5{0x14, 0x09, 0x54, 0x51, 0x69, 0x20, 0x42, 0x4C, 0x45, 0x05, 0x12, 0x64, 0x00, 0xE8, 0x03, 0x02, 0x0A, 0x00}; EXPECT_TRUE(AdvertiseDataParser::IsValid(data5)); // Test Quirk for Traxxas (bad name length, should be 0x11 is 0x14) const std::vector<uint8_t> data6{0x14, 0x09, 0x54, 0x51, 0x69, 0x20, 0x42, 0x4C, 0x45, 0x05, 0x12, 0x60, 0x00, 0xE8, 0x03, 0x02, 0x0A, 0x00}; EXPECT_TRUE(AdvertiseDataParser::IsValid(data6)); // Test Quirk for Traxxas (bad length, should be 0x11 is 0x14) // scan response glued after advertise data const std::vector<uint8_t> data7{ 0x02, 0x01, 0x06, 0x11, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0xB1, 0x73, 0x41, 0xE7, 0xF3, 0xC4, 0xB4, 0x80, 0x08, 0x14, 0x09, 0x54, 0x51, 0x69, 0x20, 0x42, 0x4C, 0x45, 0x05, 0x12, 0x60, 0x00, 0xE8, 0x03, 0x02, 0x0A, 0x00}; EXPECT_TRUE(AdvertiseDataParser::IsValid(data7)); } TEST(AdvertiseDataParserTest, GetFieldByType) { Loading