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

Commit 3ae4d115 authored by Hansong Zhang's avatar Hansong Zhang
Browse files

L2cap LE Fixed channel shim layer

* Add the shim layer for LE Fixed channel to unblock testing
* Currently we use address type from advertising report or connection
  complete event. We need to use the address type from storage module in
  the future.
* So far GD ATT module is not implemented, and we always use legacy ATT
  cstack. We assign CID 4 to legacy ATT.

Tag: #gd-refactor
Test: nRF app
Bug: 158861440
Change-Id: I7c082201a481004f2340d22157beeb3808d1013a
parent 9974d914
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -52,8 +52,11 @@ struct AttModule::impl {
    // TODO: move that into a ATT manager, or other proper place
    std::unique_ptr<bluetooth::l2cap::le::FixedChannelManager> l2cap_manager_le_(
        l2cap_le_module_->GetFixedChannelManager());
    // TODO(b/161256497): CID 4 is taken by shim layer ATT module so far. When we migrate to GD ATT module, we use real
    // CID here.
    constexpr uint16_t kFakeLeAttributeCid = 50;
    l2cap_manager_le_->RegisterService(
        bluetooth::l2cap::kLeAttributeCid,
        kFakeLeAttributeCid,
        common::BindOnce(&OnAttRegistrationCompleteLe),
        common::Bind(&OnAttConnectionOpenLe),
        att_handler_);
+22 −1
Original line number Diff line number Diff line
@@ -141,6 +141,14 @@ std::string Btm::ReadRemoteName::AddressString() const {
  return raw_address_.ToString();
}

static std::unordered_map<RawAddress, tBLE_ADDR_TYPE> le_address_type_cache_;

static void store_le_address_type(RawAddress address, tBLE_ADDR_TYPE type) {
  if (le_address_type_cache_.count(address) == 0) {
    le_address_type_cache_[address] = type;
  }
}

void Btm::ScanningCallbacks::on_advertisements(
    std::vector<std::shared_ptr<hci::LeReport>> reports) {
  for (auto le_report : reports) {
@@ -209,6 +217,7 @@ void Btm::ScanningCallbacks::on_advertisements(
            kPhyConnectionNone, kAdvDataInfoNotPresent,
            kTxPowerInformationNotPresent, le_report->rssi_,
            kNotPeriodicAdvertisement, report_len, report_data);
        store_le_address_type(raw_address, address_type);
      } break;

      case hci::LeReport::ReportType::DIRECTED_ADVERTISING_EVENT:
@@ -237,7 +246,7 @@ void Btm::ScanningCallbacks::on_advertisements(
            kPhyConnectionNone, kAdvDataInfoNotPresent,
            kTxPowerInformationNotPresent, le_report->rssi_,
            kNotPeriodicAdvertisement, report_len, report_data);

        store_le_address_type(raw_address, address_type);
      } break;
    }
  }
@@ -788,6 +797,18 @@ uint16_t Btm::GetAclHandle(const RawAddress& remote_bda,
  }
}

tBLE_ADDR_TYPE Btm::GetAddressType(const RawAddress& bd_addr) {
  if (le_address_type_cache_.count(bd_addr) == 0) {
    LOG(ERROR) << "Unknown bd_addr. Use public address";
    return BLE_ADDR_PUBLIC;
  }
  return le_address_type_cache_[bd_addr];
}

void Btm::StoreAddressType(const RawAddress& bd_addr, tBLE_ADDR_TYPE type) {
  store_le_address_type(bd_addr, type);
}

}  // namespace shim

}  // namespace bluetooth
+7 −0
Original line number Diff line number Diff line
@@ -215,6 +215,13 @@ class Btm {

  uint16_t GetAclHandle(const RawAddress& remote_bda, tBT_TRANSPORT transport);

  static tBLE_ADDR_TYPE GetAddressType(const RawAddress& bd_addr);

  // Store the address type from advertising report or connection complete
  // packet.
  // TODO(b/161319293): Obtain from storage
  static void StoreAddressType(const RawAddress& bd_addr, tBLE_ADDR_TYPE type);

 private:
  os::Alarm scanning_timer_;
  os::Alarm observing_timer_;
+6 −0
Original line number Diff line number Diff line
@@ -81,6 +81,12 @@ L2cap* GetL2cap() {
  return Stack::GetInstance()->GetStackManager()->GetInstance<L2cap>();
}

bluetooth::l2cap::le::L2capLeModule* GetL2capLeModule() {
  return Stack::GetInstance()
      ->GetStackManager()
      ->GetInstance<bluetooth::l2cap::le::L2capLeModule>();
}

neighbor::NameModule* GetName() {
  return Stack::GetInstance()
      ->GetStackManager()
+7 −0
Original line number Diff line number Diff line
@@ -51,6 +51,12 @@ class LeAdvertisingManager;
class LeScanningManager;
}

namespace l2cap {
namespace le {
class L2capLeModule;
}  // namespace le
}  // namespace l2cap

namespace security {
class SecurityModule;
}
@@ -71,6 +77,7 @@ Dumpsys* GetDumpsys();
neighbor::InquiryModule* GetInquiry();
hci::HciLayer* GetHciLayer();
L2cap* GetL2cap();
l2cap::le::L2capLeModule* GetL2capLeModule();
neighbor::NameModule* GetName();
neighbor::PageModule* GetPage();
hci::LeScanningManager* GetScanning();
Loading