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

Commit cc7af64f authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Add a composite structure for address, address type and transport

Bug: 324119791
Test: mma packages/modules/Bluetooth
Flag: EXEMPT no logical change
Change-Id: If8377951a890243d23793e8ff37cfff966306152
parent 4ce1904b
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -67,6 +67,7 @@ cc_test {
    ],
    ],
    include_dirs: [
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/include",
    ],
    ],
    host_supported: true,
    host_supported: true,
    srcs: [
    srcs: [
+40 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,8 @@


#include <cstdint>
#include <cstdint>
#include <string>
#include <string>

#include "types/bt_transport.h"
#include "types/raw_address.h"
#include "types/raw_address.h"


#define BLE_ADDR_PUBLIC 0x00
#define BLE_ADDR_PUBLIC 0x00
@@ -149,4 +151,42 @@ struct std::hash<tBLE_BD_ADDR> {
  }
  }
};
};


struct tTypedAddressTransport {
  tBLE_BD_ADDR addrt;
  tBT_TRANSPORT transport;

  bool operator==(const tTypedAddressTransport rhs) const {
    if (rhs.addrt != addrt) return false;

    if (rhs.transport == BT_TRANSPORT_AUTO || transport == BT_TRANSPORT_AUTO) {
      return true;
    }

    return rhs.transport == transport;
  }

  bool operator!=(const tTypedAddressTransport rhs) const {
    return !(*this == rhs);
  }

  bool StrictlyEquals(const tTypedAddressTransport rhs) const {
    return rhs.addrt == addrt && rhs.transport == transport;
  }

  std::string ToString() const {
    return std::string(addrt.ToString() + "[" + bt_transport_text(transport) +
                       "]");
  }

  std::string ToStringForLogging() const {
    return addrt.ToStringForLogging() + "[" + bt_transport_text(transport) +
           "]";
  }

  std::string ToRedactedStringForLogging() const {
    return addrt.ToRedactedStringForLogging() + "[" +
           bt_transport_text(transport) + "]";
  }
};

#endif
#endif
+19 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,8 @@
#include "types/ble_address_with_type.h"
#include "types/ble_address_with_type.h"


#include <gtest/gtest.h>
#include <gtest/gtest.h>
static constexpr uint8_t RAW_ADDRESS_TEST1[6] = {0x01, 0x02, 0x03,
                                                 0x04, 0x05, 0x06};


TEST(BleAddressWithTypeTest, to_ble_addr_type) {
TEST(BleAddressWithTypeTest, to_ble_addr_type) {
  for (unsigned i = 0; i < 0xff + 1; i++) {
  for (unsigned i = 0; i < 0xff + 1; i++) {
@@ -97,6 +99,23 @@ TEST(BleAddressWithTypeTest, STREAM_TO_BLE_ADDR_TYPE) {
  }
  }
}
}


TEST(BleAddressWithTypeTest, TYPED_ADDRESS_TRANSPORT) {
  tTypedAddressTransport typedAddressTransportA = {
      {BLE_ADDR_PUBLIC, RAW_ADDRESS_TEST1}, BT_TRANSPORT_AUTO};
  tTypedAddressTransport typedAddressTransportB = {
      {BLE_ADDR_PUBLIC, RAW_ADDRESS_TEST1}, BT_TRANSPORT_BR_EDR};
  tTypedAddressTransport typedAddressTransportC = {
      {BLE_ADDR_PUBLIC, RAW_ADDRESS_TEST1}, BT_TRANSPORT_LE};

  ASSERT_EQ(typedAddressTransportA, typedAddressTransportB);
  ASSERT_EQ(typedAddressTransportA, typedAddressTransportC);
  ASSERT_NE(typedAddressTransportB, typedAddressTransportC);

  ASSERT_FALSE(typedAddressTransportA.StrictlyEquals(typedAddressTransportB));
  ASSERT_FALSE(typedAddressTransportA.StrictlyEquals(typedAddressTransportC));
  ASSERT_FALSE(typedAddressTransportB.StrictlyEquals(typedAddressTransportC));
}

TEST(BleAddressWithTypeTest, BLE_ADDR_TYPE_TO_STREAM) {
TEST(BleAddressWithTypeTest, BLE_ADDR_TYPE_TO_STREAM) {
  uint8_t buf[256] = {0};
  uint8_t buf[256] = {0};
  uint8_t* p = buf;
  uint8_t* p = buf;