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

Commit caa58e62 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Automerger Merge Worker
Browse files

Add helper for converting between legacy and gd Address am: 80d7f12a

Change-Id: Ibfdd0b6ea326078510a5f1dc98bb42f9aa45c015
parents b362cc7c 80d7f12a
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -45,26 +45,33 @@ class ShimUi : public security::UI {
                           std::string name, uint32_t numeric_value) {
    bt_bdname_t legacy_name{0};
    memcpy(legacy_name.name, name.data(), name.length());
    callback_(RawAddress(address.GetAddress().address), legacy_name, ((0x1F) << 8) /* COD_UNCLASSIFIED*/ , BT_SSP_VARIANT_PASSKEY_CONFIRMATION, numeric_value);
    callback_(ToRawAddress(address.GetAddress()), legacy_name,
              ((0x1F) << 8) /* COD_UNCLASSIFIED*/,
              BT_SSP_VARIANT_PASSKEY_CONFIRMATION, numeric_value);
  }

  void DisplayYesNoDialog(const bluetooth::hci::AddressWithType& address,
                          std::string name) {
    bt_bdname_t legacy_name{0};
    memcpy(legacy_name.name, name.data(), name.length());
    callback_(RawAddress(address.GetAddress().address), legacy_name, ((0x1F) << 8) /* COD_UNCLASSIFIED*/ , BT_SSP_VARIANT_CONSENT, 0);
    callback_(ToRawAddress(address.GetAddress()), legacy_name,
              ((0x1F) << 8) /* COD_UNCLASSIFIED*/, BT_SSP_VARIANT_CONSENT, 0);
  }

  void DisplayEnterPasskeyDialog(const bluetooth::hci::AddressWithType& address, std::string name) {
    bt_bdname_t legacy_name{0};
    memcpy(legacy_name.name, name.data(), name.length());
    callback_(RawAddress(address.GetAddress().address), legacy_name, ((0x1F) << 8) /* COD_UNCLASSIFIED*/ , BT_SSP_VARIANT_PASSKEY_ENTRY, 0);
    callback_(ToRawAddress(address.GetAddress()), legacy_name,
              ((0x1F) << 8) /* COD_UNCLASSIFIED*/, BT_SSP_VARIANT_PASSKEY_ENTRY,
              0);
  }

  void DisplayPasskey(const bluetooth::hci::AddressWithType& address, std::string name, uint32_t passkey) {
    bt_bdname_t legacy_name{0};
    memcpy(legacy_name.name, name.data(), name.length());
    callback_(RawAddress(address.GetAddress().address), legacy_name, ((0x1F) << 8) /* COD_UNCLASSIFIED*/ , BT_SSP_VARIANT_PASSKEY_NOTIFICATION, passkey);
    callback_(ToRawAddress(address.GetAddress()), legacy_name,
              ((0x1F) << 8) /* COD_UNCLASSIFIED*/,
              BT_SSP_VARIANT_PASSKEY_NOTIFICATION, passkey);
  }

  void SetLegacyCallback(std::function<void(RawAddress, bt_bdname_t, uint32_t, bt_ssp_variant_t, uint32_t)> callback) {
@@ -99,15 +106,15 @@ class ShimBondListener : public security::ISecurityManagerListener {
    bond_state_none_cb_ = bond_state_none_cb;
  }
  void OnDeviceBonded(bluetooth::hci::AddressWithType device) {
    bond_state_bonded_cb_(RawAddress(device.GetAddress().address));
    bond_state_bonded_cb_(ToRawAddress(device.GetAddress()));
  }

  void OnDeviceUnbonded(bluetooth::hci::AddressWithType device) {
    bond_state_none_cb_(RawAddress(device.GetAddress().address));
    bond_state_none_cb_(ToRawAddress(device.GetAddress()));
  }

  void OnDeviceBondFailed(bluetooth::hci::AddressWithType device) {
    bond_state_none_cb_(RawAddress(device.GetAddress().address));
    bond_state_none_cb_(ToRawAddress(device.GetAddress()));
  }

  std::function<void(RawAddress)> bond_state_bonding_cb_;
+8 −9
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ void bluetooth::shim::Btm::OnInquiryResult(
    bluetooth::hci::InquiryResultView view) {
  for (auto& response : view.GetInquiryResults()) {
    btm_api_process_inquiry_result(
        RawAddress(response.bd_addr_.address),
        ToRawAddress(response.bd_addr_),
        static_cast<uint8_t>(response.page_scan_repetition_mode_),
        response.class_of_device_.cod, response.clock_offset_);
  }
@@ -117,7 +117,7 @@ void bluetooth::shim::Btm::OnInquiryResultWithRssi(
    bluetooth::hci::InquiryResultWithRssiView view) {
  for (auto& response : view.GetInquiryResults()) {
    btm_api_process_inquiry_result_with_rssi(
        RawAddress(response.address_.address),
        ToRawAddress(response.address_),
        static_cast<uint8_t>(response.page_scan_repetition_mode_),
        response.class_of_device_.cod, response.clock_offset_, response.rssi_);
  }
@@ -144,7 +144,7 @@ void bluetooth::shim::Btm::OnExtendedInquiryResult(
  }

  btm_api_process_extended_inquiry_result(
      RawAddress(view.GetAddress().address),
      ToRawAddress(view.GetAddress()),
      static_cast<uint8_t>(view.GetPageScanRepetitionMode()),
      view.GetClassOfDevice().cod, view.GetClockOffset(), view.GetRssi(), data,
      data_len);
@@ -486,14 +486,14 @@ bluetooth::shim::BtmStatus bluetooth::shim::Btm::ReadClassicRemoteDeviceName(
  LOG_DEBUG("%s Start read name from address:%s", __func__,
            raw_address.ToString().c_str());
  bluetooth::shim::GetName()->ReadRemoteNameRequest(
      hci::Address(raw_address.address), hci::PageScanRepetitionMode::R1,
      ToGdAddress(raw_address), hci::PageScanRepetitionMode::R1,
      0 /* clock_offset */, hci::ClockOffsetValid::INVALID,

      base::Bind(
          [](tBTM_CMPL_CB* callback, ReadRemoteName* classic_read_remote_name_,
             hci::ErrorCode status, hci::Address address,
             std::array<uint8_t, kRemoteDeviceNameLength> remote_name) {
            RawAddress raw_address(address.address);
            RawAddress raw_address = ToRawAddress(address);

            BtmRemoteDeviceName name{
                .status = (static_cast<uint8_t>(status) == 0)
@@ -719,7 +719,7 @@ class BtmScanningCallbacks : public bluetooth::hci::LeScanningManagerCallbacks {
              return;
          }

          RawAddress raw_address(le_report->address_.address);
          RawAddress raw_address = ToRawAddress(le_report->address_);

          btm_ble_process_adv_addr(raw_address, &address_type);
          btm_ble_process_adv_pkt_cont(
@@ -746,7 +746,7 @@ class BtmScanningCallbacks : public bluetooth::hci::LeScanningManagerCallbacks {
               .legacy = false,
               .continuing = !extended_le_report->complete_,
               .truncated = extended_le_report->truncated_});
          RawAddress raw_address(le_report->address_.address);
          RawAddress raw_address = ToRawAddress(le_report->address_);
          if (address_type != BLE_ADDR_ANONYMOUS) {
            btm_ble_process_adv_addr(raw_address, &address_type);
          }
@@ -794,8 +794,7 @@ tBTM_STATUS bluetooth::shim::Btm::CreateBond(const RawAddress& bd_addr,
      bluetooth::shim::GetSecurityModule()->GetSecurityManager();
  switch (transport) {
    case BT_TRANSPORT_BR_EDR:
      security_manager->CreateBond(
          ToAddressWithType(bd_addr.address, BLE_ADDR_PUBLIC));
      security_manager->CreateBond(ToAddressWithType(bd_addr, BLE_ADDR_PUBLIC));
      break;
    case BT_TRANSPORT_LE:
      security_manager->CreateBondLe(ToAddressWithType(bd_addr, addr_type));
+24 −3
Original line number Diff line number Diff line
@@ -21,10 +21,31 @@

namespace bluetooth {

inline RawAddress ToRawAddress(const hci::Address& address) {
  RawAddress ret;
  ret.address[0] = address.address[5];
  ret.address[1] = address.address[4];
  ret.address[2] = address.address[3];
  ret.address[3] = address.address[2];
  ret.address[4] = address.address[1];
  ret.address[5] = address.address[0];
  return ret;
}

inline hci::Address ToGdAddress(const RawAddress& address) {
  hci::Address ret;
  ret.address[0] = address.address[5];
  ret.address[1] = address.address[4];
  ret.address[2] = address.address[3];
  ret.address[3] = address.address[2];
  ret.address[4] = address.address[1];
  ret.address[5] = address.address[0];
  return ret;
}

inline hci::AddressWithType ToAddressWithType(const RawAddress& legacy_address,
                                       tBLE_ADDR_TYPE legacy_type) {
  // Address and RawAddress are binary equivalent;
  hci::Address address(legacy_address.address);
  hci::Address address = ToGdAddress(legacy_address);

  hci::AddressType type;
  if (legacy_type == BLE_ADDR_PUBLIC)