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

Commit ee2119f5 authored by Martin Brabham's avatar Martin Brabham
Browse files

SM: Add UI Callbacks to CPH

Test: bluetooth_test_gd
Change-Id: I8b7b587f720a897e416ed3abea0fde6ad6788338
parent 970f0753
Loading
Loading
Loading
Loading
+22 −7
Original line number Diff line number Diff line
@@ -172,8 +172,8 @@ void SecurityManagerImpl::HandleEvent(T packet) {

    const hci::EventCode code = event.GetEventCode();
    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);
      LOG_ERROR("No classic pairing handler for device '%s' ready for command %s ", bd_addr.ToString().c_str(),
                hci::EventCodeText(event_code).c_str());
      return;
    }

@@ -255,20 +255,35 @@ void SecurityManagerImpl::OnHciLeEvent(hci::LeMetaEventView event) {
}

void SecurityManagerImpl::OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) {
  auto entry = pairing_handler_map_.find(address.GetAddress());
  if (entry != pairing_handler_map_.end()) {
    entry->second->OnPairingPromptAccepted(address, confirmed);
  } else {
    pending_le_pairing_.handler_->OnUiAction(PairingEvent::UI_ACTION_TYPE::PAIRING_ACCEPTED, confirmed);
  }
}

void SecurityManagerImpl::OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) {
  auto entry = pairing_handler_map_.find(address.GetAddress());
  if (entry != pairing_handler_map_.end()) {
    entry->second->OnConfirmYesNo(address, confirmed);
  } else {
    if (pending_le_pairing_.address_ == address) {
      pending_le_pairing_.handler_->OnUiAction(PairingEvent::UI_ACTION_TYPE::CONFIRM_YESNO, confirmed);
    }
  }
}

void SecurityManagerImpl::OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) {
  auto entry = pairing_handler_map_.find(address.GetAddress());
  if (entry != pairing_handler_map_.end()) {
    entry->second->OnPasskeyEntry(address, passkey);
  } else {
    if (pending_le_pairing_.address_ == address) {
      pending_le_pairing_.handler_->OnUiAction(PairingEvent::UI_ACTION_TYPE::PASSKEY, passkey);
    }
  }
}

void SecurityManagerImpl::OnPairingHandlerComplete(hci::Address address, PairingResultOrFailure status) {
  auto entry = pairing_handler_map_.find(address);
+14 −0
Original line number Diff line number Diff line
@@ -90,6 +90,20 @@ void ClassicPairingHandler::OnConnectionClose(hci::ErrorCode error_code) {
  Cancel();
}

void ClassicPairingHandler::OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) {
  LOG_WARN("TODO Not Implemented!");
}

void ClassicPairingHandler::OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) {
  LOG_WARN("TODO Not Implemented!");
  GetChannel()->SendCommand(
      hci::UserConfirmationRequestReplyBuilder::Create(GetRecord()->GetPseudoAddress().GetAddress()));
}

void ClassicPairingHandler::OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) {
  LOG_WARN("TODO Not Implemented!");
}

void ClassicPairingHandler::Initiate(bool locally_initiated, hci::IoCapability io_capability,
                                     hci::OobDataPresent oob_present,
                                     hci::AuthenticationRequirements auth_requirements) {
+4 −0
Original line number Diff line number Diff line
@@ -76,6 +76,10 @@ class ClassicPairingHandler : public PairingHandler {
  void OnReceive(hci::UserConfirmationRequestView packet) override;
  void OnReceive(hci::UserPasskeyRequestView packet) override;

  void OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) override;
  void OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) override;
  void OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) override;

 private:
  void OnRegistrationComplete(l2cap::classic::FixedChannelManager::RegistrationResult result,
                              std::unique_ptr<l2cap::classic::FixedChannelService> fixed_channel_service);
+6 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include "security/channel/security_manager_channel.h"
#include "security/record/security_record.h"
#include "security/smp_packets.h"
#include "security/ui.h"

namespace bluetooth {
namespace security {
@@ -34,7 +35,7 @@ namespace pairing {
 *
 * <p>Extend this class in order to implement a new style of pairing.
 */
class PairingHandler {
class PairingHandler : public UICallbacks {
 public:
  PairingHandler(channel::SecurityManagerChannel* security_manager_channel,
                 std::shared_ptr<record::SecurityRecord> record)
@@ -62,6 +63,10 @@ class PairingHandler {
  virtual void OnReceive(hci::UserConfirmationRequestView packet) = 0;
  virtual void OnReceive(hci::UserPasskeyRequestView packet) = 0;

  virtual void OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) = 0;
  virtual void OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) = 0;
  virtual void OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) = 0;

 protected:
  std::shared_ptr<record::SecurityRecord> GetRecord() {
    return record_;
+2 −2
Original line number Diff line number Diff line
@@ -74,11 +74,11 @@ void SecurityManager::OnPairingPromptAccepted(const bluetooth::hci::AddressWithT
                                           common::Unretained(security_manager_impl_), address, confirmed));
}
void SecurityManager::OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) {
  security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::OnPairingPromptAccepted,
  security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::OnConfirmYesNo,
                                           common::Unretained(security_manager_impl_), address, confirmed));
}
void SecurityManager::OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) {
  security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::OnPairingPromptAccepted,
  security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::OnPasskeyEntry,
                                           common::Unretained(security_manager_impl_), address, passkey));
}