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

Commit ead3086f authored by kuanyuhuang's avatar kuanyuhuang
Browse files

Interop checks range of addresses

Phonak hearing aid device has iop issue which BT address within
the range from 00:0F:59:50:00:00 to 00:0F:59:6F:FF:FF.
Add interop function and database type for checking range of BT
addresses.

Bug: 256744040
Test: atest net_test_device
Tag: #refactor
Change-Id: I17a7a8ec24dd423662f27e0aca085f8636654438
parent 577933fa
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -153,9 +153,6 @@ static const interop_addr_entry_t interop_addr_database[] = {
    // AirPods 2 - unacceptably loud volume
    {{{0x9c, 0x64, 0x8b, 0, 0, 0}}, 3, INTEROP_DISABLE_ABSOLUTE_VOLUME},

    // Phonak AG - volume level not change
    {{{0x00, 0x0f, 0x59, 0, 0, 0}}, 3, INTEROP_DISABLE_ABSOLUTE_VOLUME},

    // for skip name request,
    // because BR/EDR address and ADV random address are the same
    {{{0xd4, 0x7a, 0xe2, 0, 0, 0}}, 3, INTEROP_DISABLE_NAME_REQUEST},
@@ -195,6 +192,19 @@ static const interop_addr_entry_t interop_addr_database[] = {
    {{{0x00, 0x0a, 0x08, 0, 0, 0}}, 3, INTEROP_AVRCP_1_3_ONLY},
};

typedef struct {
  RawAddress addr_start;
  RawAddress addr_end;
  interop_feature_t feature;
} interop_addr_range_entry_t;

static const interop_addr_range_entry_t interop_addr_range_database[] = {
    // Phonak AG - volume level not change
    {{{0x00, 0x0f, 0x59, 0x50, 0x00, 0x00}},
     {{0x00, 0x0f, 0x59, 0x6f, 0xff, 0xff}},
     INTEROP_DISABLE_ABSOLUTE_VOLUME},
};

typedef struct {
  char name[20];
  size_t length;
+21 −1
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ static bool interop_match_fixed_(const interop_feature_t feature,
                                 const RawAddress* addr);
static bool interop_match_dynamic_(const interop_feature_t feature,
                                   const RawAddress* addr);
static bool interop_match_range_(const interop_feature_t feature,
                                 const RawAddress* addr);

// Interface functions

@@ -52,7 +54,8 @@ bool interop_match_addr(const interop_feature_t feature,
  CHECK(addr);

  if (interop_match_fixed_(feature, addr) ||
      interop_match_dynamic_(feature, addr)) {
      interop_match_dynamic_(feature, addr) ||
      interop_match_range_(feature, addr)) {
    LOG_INFO("%s() Device %s is a match for interop workaround %s.", __func__,
             addr->ToString().c_str(), interop_feature_string_(feature));
    return true;
@@ -190,3 +193,20 @@ static bool interop_match_fixed_(const interop_feature_t feature,

  return false;
}

static bool interop_match_range_(const interop_feature_t feature,
                                 const RawAddress* addr) {
  CHECK(addr);

  const size_t db_size =
      sizeof(interop_addr_range_database) / sizeof(interop_addr_range_entry_t);
  for (size_t i = 0; i != db_size; ++i) {
    if (feature == interop_addr_range_database[i].feature &&
        *addr >= interop_addr_range_database[i].addr_start &&
        *addr <= interop_addr_range_database[i].addr_end) {
      return true;
    }
  }

  return false;
}
+23 −0
Original line number Diff line number Diff line
@@ -82,3 +82,26 @@ TEST(InteropTest, test_name_miss) {
  EXPECT_FALSE(interop_match_name(INTEROP_DISABLE_AUTO_PAIRING, "audi"));
  EXPECT_FALSE(interop_match_name(INTEROP_AUTO_RETRY_PAIRING, "BMW M3"));
}

TEST(InteropTest, test_range_hit) {
  RawAddress test_address;
  RawAddress::FromString("00:0f:59:50:00:00", test_address);
  ASSERT_TRUE(
      interop_match_addr(INTEROP_DISABLE_ABSOLUTE_VOLUME, &test_address));
  RawAddress::FromString("00:0f:59:59:12:34", test_address);
  ASSERT_TRUE(
      interop_match_addr(INTEROP_DISABLE_ABSOLUTE_VOLUME, &test_address));
  RawAddress::FromString("00:0f:59:6f:ff:ff", test_address);
  ASSERT_TRUE(
      interop_match_addr(INTEROP_DISABLE_ABSOLUTE_VOLUME, &test_address));
}

TEST(InteropTest, test_range_miss) {
  RawAddress test_address;
  RawAddress::FromString("00:0f:59:49:12:34", test_address);
  ASSERT_FALSE(
      interop_match_addr(INTEROP_DISABLE_ABSOLUTE_VOLUME, &test_address));
  RawAddress::FromString("00:0f:59:70:12:34", test_address);
  ASSERT_FALSE(
      interop_match_addr(INTEROP_DISABLE_ABSOLUTE_VOLUME, &test_address));
}