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

Commit 314d434e authored by Chris Manton's avatar Chris Manton
Browse files

gd: Ensure all events are handled for new classic pairing manager

a new classic pairing manager never processes the initiating event.

Bug: 146086425
Test: bluetooth_test_gd

Change-Id: I3471bc5849315456d7429747e894cf80eda8b8cb
parent 52e86a5d
Loading
Loading
Loading
Loading
+17 −15
Original line number Diff line number Diff line
@@ -33,7 +33,8 @@ namespace bluetooth {
namespace security {
namespace internal {

void SecurityManagerImpl::DispatchPairingHandler(record::SecurityRecord& record, bool locally_initiated) {
void SecurityManagerImpl::DispatchPairingHandler(record::SecurityRecord& record, bool locally_initiated,
                                                 hci::AuthenticationRequirements authentication_requirements) {
  common::OnceCallback<void(hci::Address, PairingResultOrFailure)> callback =
      common::BindOnce(&SecurityManagerImpl::OnPairingHandlerComplete, common::Unretained(this));
  auto entry = pairing_handler_map_.find(record.GetPseudoAddress().GetAddress());
@@ -58,7 +59,7 @@ void SecurityManagerImpl::DispatchPairingHandler(record::SecurityRecord& record,
      record.GetPseudoAddress().GetAddress(), pairing_handler);
  pairing_handler_map_.insert(std::move(new_entry));
  pairing_handler->Initiate(locally_initiated, pairing::kDefaultIoCapability, pairing::kDefaultOobDataPresent,
                            pairing::kDefaultAuthenticationRequirements);
                            authentication_requirements);
}

void SecurityManagerImpl::Init() {
@@ -74,7 +75,7 @@ void SecurityManagerImpl::CreateBond(hci::AddressWithType device) {
    NotifyDeviceBonded(device);
  } else {
    // Dispatch pairing handler, if we are calling create we are the initiator
    DispatchPairingHandler(record, true);
    DispatchPairingHandler(record, true, pairing::kDefaultAuthenticationRequirements);
  }
}

@@ -162,26 +163,27 @@ template <class T>
void SecurityManagerImpl::HandleEvent(T packet) {
  ASSERT(packet.IsValid());
  auto entry = pairing_handler_map_.find(packet.GetBdAddr());
  if (entry != pairing_handler_map_.end()) {
    entry->second->OnReceive(packet);
  } else {

  if (entry == pairing_handler_map_.end()) {
    auto bd_addr = packet.GetBdAddr();
    auto event_code = packet.GetEventCode();
    auto event = hci::EventPacketView::Create(std::move(packet));
    ASSERT_LOG(event.IsValid(), "Received invalid packet");

    const hci::EventCode code = event.GetEventCode();
    auto record =
        security_database_.FindOrCreate(hci::AddressWithType{bd_addr, hci::AddressType::PUBLIC_DEVICE_ADDRESS});
    switch (code) {
      case hci::EventCode::LINK_KEY_REQUEST:
        DispatchPairingHandler(record, true);
        break;
      default:
    if (code != hci::EventCode::LINK_KEY_REQUEST) {
      LOG_ERROR("No classic pairing handler for device '%s' ready for command '%hhx' ", bd_addr.ToString().c_str(),
                event_code);
        break;
      return;
    }

    auto record =
        security_database_.FindOrCreate(hci::AddressWithType{bd_addr, hci::AddressType::PUBLIC_DEVICE_ADDRESS});
    auto authentication_requirements = hci::AuthenticationRequirements::NO_BONDING;
    DispatchPairingHandler(record, true, authentication_requirements);
    entry = pairing_handler_map_.find(packet.GetBdAddr());
  }
  entry->second->OnReceive(packet);
}

void SecurityManagerImpl::OnHciEventReceived(hci::EventPacketView packet) {
+2 −1
Original line number Diff line number Diff line
@@ -133,7 +133,8 @@ class SecurityManagerImpl : public channel::ISecurityManagerChannelListener {
  template <class T>
  void HandleEvent(T packet);

  void DispatchPairingHandler(record::SecurityRecord& record, bool locally_initiated);
  void DispatchPairingHandler(record::SecurityRecord& record, bool locally_initiated,
                              hci::AuthenticationRequirements authentication_requirements);
  void OnL2capRegistrationCompleteLe(l2cap::le::FixedChannelManager::RegistrationResult result,
                                     std::unique_ptr<l2cap::le::FixedChannelService> le_smp_service);
  void OnSmpCommandLe();