Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9984d31d authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Andre Eisenbach
Browse files

Workaround for Traxxas

Bug: 64252588
Test: net_test_stack_ad_parser
Change-Id: I1471e9e5f0f36ec931f8d86c927abbc1137e2b94
Merged-In: I1471e9e5f0f36ec931f8d86c927abbc1137e2b94
parent d3f8ff05
Loading
Loading
Loading
Loading
+24 −0
Original line number Original line Diff line number Diff line
@@ -18,9 +18,31 @@


#pragma once
#pragma once


#include <array>
#include <vector>
#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 {
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:
 public:
  /**
  /**
   * Return true if this |ad| represent properly formatted advertising data.
   * Return true if this |ad| represent properly formatted advertising data.
@@ -45,6 +67,8 @@ class AdvertiseDataParser {
      // If the length of the current field would exceed the total data length,
      // If the length of the current field would exceed the total data length,
      // then the data is badly formatted.
      // then the data is badly formatted.
      if (position + len >= ad_len) {
      if (position + len >= ad_len) {
        if (MalformedPacketQuirk(ad, position)) return true;

        return false;
        return false;
      }
      }


+27 −0
Original line number Original line Diff line number Diff line
@@ -76,6 +76,33 @@ TEST(AdvertiseDataParserTest, IsValidGood) {
      0xa,  0x32,  0x39, 0x3a, 0x65, 0x32, 0x05, 0x12, 0x50, 0x00, 0x50,
      0xa,  0x32,  0x39, 0x3a, 0x65, 0x32, 0x05, 0x12, 0x50, 0x00, 0x50,
      0x00, 0x02,  0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
      0x00, 0x02,  0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  EXPECT_TRUE(AdvertiseDataParser::IsValid(data3));
  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) {
TEST(AdvertiseDataParserTest, GetFieldByType) {