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

Commit d052d5ee authored by Chris Manton's avatar Chris Manton Committed by Automerger Merge Worker
Browse files

gdx: Expand service uuid to include associated parameters am: da5dae7d

parents a27b1a3b da5dae7d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -506,6 +506,7 @@ cc_test {
        "libchrome",
        "libevent",
        "libflatbuffers-cpp",
        "libgmock",
        "libosi",
    ],
    shared_libs: [
+22 −7
Original line number Diff line number Diff line
@@ -135,10 +135,10 @@ bool EirData::GetUuidsIncomplete128(std::vector<hci::Uuid>& uuids) const {
  return !uuids.empty();
}

bool EirData::GetDeviceId(std::vector<uint8_t>& device_ids) const {
bool EirData::GetDeviceId(std::vector<std::vector<uint8_t>>& device_ids) const {
  for (const auto& gap_data : gap_data_) {
    if (gap_data.data_type_ == hci::GapDataType::DEVICE_ID) {
      if (gap_data.data_.size() == 1U) device_ids.push_back(gap_data.data_[0]);
      device_ids.push_back(gap_data.data_);
    }
  }
  return !device_ids.empty();
@@ -162,14 +162,29 @@ bool EirData::GetSecurityManagerOobFlags(std::vector<std::vector<uint8_t>>& flag
  return !flags.empty();
}

bool EirData::GetServiceUuuids32(std::vector<uint32_t>& uuids) const {
bool EirData::GetServiceUuuids16(std::vector<service_uuid16_t>& uuids) const {
  for (const auto& gap_data : gap_data_) {
    if (gap_data.data_type_ == hci::GapDataType::SERVICE_DATA_32_BIT_UUIDS) {
    if (gap_data.data_type_ == hci::GapDataType::SERVICE_DATA_16_BIT_UUIDS) {
      if (gap_data.data_.size() < Uuid::kNumBytes16) continue;
      auto it = gap_data.data_.begin();
      while (std::distance(it, gap_data.data_.end()) >= (signed)Uuid::kNumBytes32) {
        uuids.push_back(*it | *(it + 1) << 8 | *(it + 2) << 16 | *(it + 3) << 24);
        it += Uuid::kNumBytes32;
      uuids.push_back({
          .uuid = (uint16_t)(*it | *(it + 1) << 8),
          .data = std::vector<uint8_t>(it + Uuid::kNumBytes16, gap_data.data_.end()),
      });
    }
  }
  return !uuids.empty();
}

bool EirData::GetServiceUuuids32(std::vector<service_uuid32_t>& uuids) const {
  for (const auto& gap_data : gap_data_) {
    if (gap_data.data_type_ == hci::GapDataType::SERVICE_DATA_32_BIT_UUIDS) {
      if (gap_data.data_.size() < Uuid::kNumBytes32) continue;
      auto it = gap_data.data_.begin();
      uuids.push_back({
          .uuid = (uint32_t)(*it | *(it + 1) << 8 | *(it + 2) << 16 | *(it + 3) << 24),
          .data = std::vector<uint8_t>(it + Uuid::kNumBytes32, gap_data.data_.end()),
      });
    }
  }
  return !uuids.empty();
+13 −2
Original line number Diff line number Diff line
@@ -26,6 +26,16 @@ namespace bluetooth {
namespace discovery {
namespace device {

struct service_uuid16_t {
  uint16_t uuid;
  std::vector<uint8_t> data;
};

struct service_uuid32_t {
  uint32_t uuid;
  std::vector<uint8_t> data;
};

class EirData : public DataParser {
 public:
  EirData(const std::vector<uint8_t>& data);
@@ -40,12 +50,13 @@ class EirData : public DataParser {
  bool GetUuids128(std::vector<hci::Uuid>&) const;
  bool GetUuidsIncomplete128(std::vector<hci::Uuid>&) const;

  bool GetDeviceId(std::vector<uint8_t>&) const;
  bool GetDeviceId(std::vector<std::vector<uint8_t>>&) const;

  bool GetManufacturerSpecificData(std::vector<std::vector<uint8_t>>&) const;

  bool GetSecurityManagerOobFlags(std::vector<std::vector<uint8_t>>&) const;
  bool GetServiceUuuids32(std::vector<uint32_t>&) const;
  bool GetServiceUuuids16(std::vector<service_uuid16_t>&) const;
  bool GetServiceUuuids32(std::vector<service_uuid32_t>&) const;
  bool GetTxPowerLevel(std::vector<int8_t>&) const;
};

+62 −9
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "discovery/device/eir_data.h"

#include "discovery/device/eir_test_data_packets.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "hci/hci_packets.h"
#include "os/log.h"
@@ -30,6 +31,8 @@ constexpr uint8_t kPartialUuid16Data[] = {
constexpr uint8_t kOneUuid16Data[] = {
    0x3, static_cast<uint8_t>(hci::GapDataType::COMPLETE_LIST_16_BIT_UUIDS), 0x34, 0x12};
constexpr char kAudiMmi9962[] = "Audi_MMI_9962";
constexpr char kChromeBoxForMeetings[] = "Chromebox for Meetings";

}  // namespace

namespace debug {
@@ -68,8 +71,8 @@ TEST(EirDataTest, test_data_packets__data_type) {
  ASSERT_EQ(1U, selected_packets.count("pkt34639"));
  const auto& pkt = selected_packets["pkt34639"];
  const EirData eir_data(std::vector<uint8_t>(&pkt[kEirOffset], &pkt[kEirOffset] + kEirSize));
  std::vector<hci::GapDataType> gap_data_types = eir_data.GetDataTypes();

  std::vector<hci::GapDataType> gap_data_types = eir_data.GetDataTypes();
  ASSERT_EQ(6U, gap_data_types.size());
}

@@ -77,6 +80,7 @@ TEST(EirDataTest, test_data_packets__complete_name) {
  ASSERT_EQ(1U, selected_packets.count("pkt34639"));
  const auto& pkt = selected_packets["pkt34639"];
  const EirData eir_data(std::vector<uint8_t>(&pkt[kEirOffset], &pkt[kEirOffset] + kEirSize));

  std::vector<std::array<uint8_t, kEirSize>> names;
  ASSERT_TRUE(eir_data.GetCompleteNames(names));
  ASSERT_EQ(1U, names.size());
@@ -88,8 +92,8 @@ TEST(EirDataTest, test_data_packets__uuids16) {
  ASSERT_EQ(1U, selected_packets.count("pkt34639"));
  const auto& pkt = selected_packets["pkt34639"];
  const EirData eir_data(std::vector<uint8_t>(&pkt[kEirOffset], &pkt[kEirOffset] + kEirSize));
  std::vector<uint16_t> uuids16;

  std::vector<uint16_t> uuids16;
  ASSERT_TRUE(eir_data.GetUuids16(uuids16));
  ASSERT_EQ(14U, uuids16.size());
  ASSERT_EQ(0x112e, uuids16[0]);
@@ -109,17 +113,21 @@ TEST(EirDataTest, test_data_packets__uuids16_incomplete) {
}

TEST(EirDataTest, test_data_packets__device_id) {
  for (const auto& pkt : data_packets) {
  ASSERT_EQ(1U, selected_packets.count("pkt2062"));
  const auto& pkt = selected_packets["pkt2062"];
  const EirData eir_data(std::vector<uint8_t>(&pkt[kEirOffset], &pkt[kEirOffset] + kEirSize));
    std::vector<uint8_t> device_ids;
    ASSERT_FALSE(eir_data.GetDeviceId(device_ids));
  }

  std::vector<std::vector<uint8_t>> device_ids;
  ASSERT_TRUE(eir_data.GetDeviceId(device_ids));
  ASSERT_EQ(1U, device_ids.size());
  ASSERT_EQ(0x01, device_ids[0][0]);
}

TEST(EirDataTest, test_data_packets__manufacturer_data) {
  ASSERT_EQ(1U, selected_packets.count("pkt26171"));
  const auto& pkt = selected_packets["pkt26171"];
  const EirData eir_data(std::vector<uint8_t>(&pkt[kEirOffset], &pkt[kEirOffset] + kEirSize));

  std::vector<std::vector<uint8_t>> mfr_data;
  ASSERT_TRUE(eir_data.GetManufacturerSpecificData(mfr_data));
  ASSERT_EQ(1U, mfr_data.size());
@@ -137,11 +145,22 @@ TEST(EirDataTest, test_data_packets__security_manager_oob_flags) {
  ASSERT_EQ(0, oob_flags[0][0]);
}

TEST(EirDataTest, test_data_packets__service_uuids16) {
  ASSERT_EQ(1U, selected_packets.count("pktAsha"));
  const auto& pkt = selected_packets["pktAsha"];
  const EirData eir_data(std::vector<uint8_t>(&pkt[kEirOffset], &pkt[kEirOffset] + kEirSize));

  std::vector<discovery::device::service_uuid16_t> service_uuids16;
  ASSERT_TRUE(eir_data.GetServiceUuuids16(service_uuids16));
  ASSERT_EQ(1U, service_uuids16.size());
  ASSERT_EQ(0xfdf0, service_uuids16[0].uuid);
}

TEST(EirDataTest, test_data_packets__service_uuids32) {
  for (const auto& pkt : data_packets) {
    const EirData eir_data(std::vector<uint8_t>(&pkt[kEirOffset], &pkt[kEirOffset] + kEirSize));
    std::vector<uint32_t> uuids;
    ASSERT_FALSE(eir_data.GetServiceUuuids32(uuids));
    std::vector<discovery::device::service_uuid32_t> service_uuids32;
    ASSERT_FALSE(eir_data.GetServiceUuuids32(service_uuids32));
  }
}

@@ -156,6 +175,40 @@ TEST(EirDataTest, test_data_packets__tx_power_level) {
  ASSERT_EQ(4, levels[0]);
}

TEST(EirDataTest, test_select_packets__pktAsha) {
  ASSERT_EQ(1U, selected_packets.count("pktAsha"));
  const auto& pkt = selected_packets["pktAsha"];
  const EirData eir_data(std::vector<uint8_t>(&pkt[kEirOffset], &pkt[kEirOffset] + kEirSize));

  std::vector<std::array<uint8_t, kEirSize>> names;
  ASSERT_TRUE(eir_data.GetCompleteNames(names));
  std::string name(names[0].begin(), names[0].end());
  ASSERT_STREQ(kChromeBoxForMeetings, name.c_str());

  std::vector<int8_t> tx_power_level;
  ASSERT_TRUE(eir_data.GetTxPowerLevel(tx_power_level));
  ASSERT_EQ(10, tx_power_level[0]);

  const std::vector<uint8_t> v1 =
      std::vector<uint8_t>({0x01, 0x00, 0xe0, 0x00, 0x05, 0xc4, 0x6c, 0x00});
  std::vector<std::vector<uint8_t>> device_ids;
  ASSERT_TRUE(eir_data.GetDeviceId(device_ids));
  ASSERT_EQ(v1.size(), device_ids[0].size());
  ASSERT_THAT(v1, testing::ContainerEq(device_ids[0]));

  const std::vector<uint16_t> v2 =
      std::vector<uint16_t>({0x1800, 0x1801, 0x180a, 0x110e, 0x110c, 0x111f, 0x110a});
  std::vector<uint16_t> uuids16;
  ASSERT_TRUE(eir_data.GetUuids16(uuids16));
  ASSERT_EQ(v2.size(), uuids16.size());
  ASSERT_THAT(v2, testing::ContainerEq(uuids16));

  std::vector<discovery::device::service_uuid16_t> service_uuids16;
  ASSERT_TRUE(eir_data.GetServiceUuuids16(service_uuids16));
  ASSERT_EQ(1U, service_uuids16.size());
  ASSERT_EQ(0xfdf0, service_uuids16[0].uuid);
}

TEST(EirDataTest, test_select_packets__pkt34639) {
  ASSERT_EQ(1U, selected_packets.count("pkt34639"));
  const auto& pkt = selected_packets["pkt34639"];
+8 −6
Original line number Diff line number Diff line
@@ -13413,7 +13413,7 @@ static const unsigned char pkt7050[258] = {
};
// Frame (258 bytes)
static const unsigned char pkt7051[258] = {
static const unsigned char pktAsha[258] = {
    0x04, 0x2f, 0xff, 0x01, 0xdc, 0xd0, 0xf1, 0x2a,  // ./.....*
    0x9a, 0xb8, 0x01, 0x00, 0x04, 0x01, 0x48, 0x0c,  // ......H.
    0x0e, 0x7f, 0x17, 0x09, 0x43, 0x68, 0x72, 0x6f,  // ....Chro
@@ -13422,9 +13422,9 @@ static const unsigned char pkt7051[258] = {
    0x67, 0x73, 0x02, 0x0a, 0x0a, 0x09, 0x10, 0x01,  // gs......
    0x00, 0xe0, 0x00, 0x05, 0xc4, 0x6c, 0x00, 0x0f,  // .....l..
    0x03, 0x00, 0x18, 0x01, 0x18, 0x0a, 0x18, 0x0e,  // ........
    0x11, 0x0c, 0x11, 0x1f, 0x11, 0x0a, 0x11, 0x00,  // ........
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // ........
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // ........
    0x11, 0x0c, 0x11, 0x1f, 0x11, 0x0a, 0x11, 0x0c,  // ........
    0x16, 0xf0, 0xfd, 0x01, 0x02, 0x03, 0x04, 0x05,  // ........
    0x06, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,  // ........
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // ........
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // ........
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // ........
@@ -13450,9 +13450,11 @@ static const unsigned char pkt7051[258] = {
};
std::unordered_map<std::string, const unsigned char*> selected_packets = {
    {"pkt34639", pkt34639},
    {"pkt19200", pkt19200},
    {"pkt2062", pkt2062},
    {"pkt26171", pkt26171},
    {"pkt34639", pkt34639},
    {"pktAsha", pktAsha},
};
std::vector<const unsigned char*> data_packets = {
@@ -13496,5 +13498,5 @@ std::vector<const unsigned char*> data_packets = {
    pkt6434,  pkt6503,  pkt6504,  pkt6511,  pkt6512,  pkt6513,  pkt6518,  pkt6525,  pkt6540,
    pkt6567,  pkt6854,  pkt6867,  pkt6870,  pkt6871,  pkt6875,  pkt6876,  pkt6886,  pkt6895,
    pkt6900,  pkt6901,  pkt6907,  pkt6908,  pkt6935,  pkt7024,  pkt7030,  pkt7035,  pkt7038,
    pkt7049,  pkt7050,  pkt7051,
    pkt7049,  pkt7050,  pktAsha,
};