0x02, 0x01, 0x02, 0x11, 0x06, 0x66, 0x9a, 0x0c, 0x20, 0x00, 0x08,
0x37, 0xa8, 0xe5, 0x11, 0x81, 0x8b, 0xd0, 0xf0, 0xf0, 0xf0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- const std::vector<uint8_t> podo_scan_resp{
+ std::vector<uint8_t> podo_scan_resp{
0x03, 0x19, 0x00, 0x80, 0x09, 0x09, 0x50, 0x6f, 0x64, 0x6f, 0x51,
0x35, 0x56, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
AdvertiseDataParser::RemoveTrailingZeros(podo_ad_data);
+ AdvertiseDataParser::RemoveTrailingZeros(podo_scan_resp);
std::vector<uint8_t> glued(podo_ad_data);
- glued.insert(glued.end(), podo_ad_data.begin(), podo_ad_data.end());
+ glued.insert(glued.end(), podo_scan_resp.begin(), podo_scan_resp.end());
+
+ EXPECT_TRUE(AdvertiseDataParser::IsValid(glued));
+}
+
+// This test makes sure that RemoveTrailingZeros is removing all bytes after
+// first zero length field. It does run the RemoveTrailingZeros for data with
+// non-zero bytes after zero length field, then glue scan response at end of it,
+// and checks that the resulting data is good. Note: specification requires all
+// bytes after zero length field to be zero padding, but many legacy devices got
+// this wrong, causing us to have this workaround.
+TEST(AdvertiseDataParserTest, RemoveTrailingZerosMalformed) {
+ std::vector<uint8_t> ad_data{0x02, 0x01, 0x02, 0x11, 0x06, 0x66, 0x9a, 0x0c,
+ 0x20, 0x00, 0x08, 0x37, 0xa8, 0xe5, 0x11, 0x81,
+ 0x8b, 0xd0, 0xf0, 0xf0, 0xf0, 0x00, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+ std::vector<uint8_t> scan_resp{0x03, 0x19, 0x00, 0x80, 0x09, 0x09, 0x50, 0x6f,
+ 0x64, 0x6f, 0x51, 0x35, 0x56, 0x47, 0x00, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+
+ AdvertiseDataParser::RemoveTrailingZeros(ad_data);
+ AdvertiseDataParser::RemoveTrailingZeros(scan_resp);
+
+ std::vector<uint8_t> glued(ad_data);
+ glued.insert(glued.end(), scan_resp.begin(), scan_resp.end());
EXPECT_TRUE(AdvertiseDataParser::IsValid(glued));
}
\ No newline at end of file