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

Commit 970f0753 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Martin Brabham
Browse files

Security UI Callbacks wiring

Test: bluetooth_test_gd
Change-Id: I713e4efd923359a36fc943362d59ae619dd515ca
parent 46b93f77
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -68,12 +68,10 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, public
                                ::google::protobuf::Empty* response) override {
    switch (request->message_type()) {
      case UiCallbackType::PASSKEY:
        security_handler_->Post(
            common::BindOnce(std::move(user_passkey_callbacks_[request->unique_id()]), request->numeric_value()));
        // TODO: security_module_->GetSecurityManager()->OnPasskeyEntry();
        break;
      case UiCallbackType::YES_NO:
        security_handler_->Post(
            common::BindOnce(std::move(user_yes_no_callbacks_[request->unique_id()]), request->boolean()));
        // TODO: security_module_->GetSecurityManager()->OnConfirmYesNo(request->boolean());
        break;
      default:
        LOG_ERROR("Unknown UiCallbackType %d", static_cast<int>(request->message_type()));
+16 −0
Original line number Diff line number Diff line
@@ -254,6 +254,22 @@ void SecurityManagerImpl::OnHciLeEvent(hci::LeMetaEventView event) {
  LOG_ERROR("Unhandled HCI LE security event");
}

void SecurityManagerImpl::OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) {
  pending_le_pairing_.handler_->OnUiAction(PairingEvent::UI_ACTION_TYPE::PAIRING_ACCEPTED, confirmed);
}

void SecurityManagerImpl::OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) {
  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) {
  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);
  if (entry != pairing_handler_map_.end()) {
+7 −2
Original line number Diff line number Diff line
@@ -37,12 +37,12 @@ class ISecurityManagerListener;

namespace internal {

class SecurityManagerImpl : public channel::ISecurityManagerChannelListener {
class SecurityManagerImpl : public channel::ISecurityManagerChannelListener, public UICallbacks {
 public:
  explicit SecurityManagerImpl(os::Handler* security_handler, l2cap::le::L2capLeModule* l2cap_le_module,
                               l2cap::classic::L2capClassicModule* l2cap_classic_module,
                               channel::SecurityManagerChannel* security_manager_channel, hci::HciLayer* hci_layer);
  virtual ~SecurityManagerImpl() = default;
  ~SecurityManagerImpl() = default;

  // All APIs must be invoked in SM layer handler

@@ -120,6 +120,11 @@ class SecurityManagerImpl : public channel::ISecurityManagerChannelListener {
   */
  void OnPairingHandlerComplete(hci::Address address, PairingResultOrFailure status);

  // UICallbacks implementation
  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;

 protected:
  std::vector<std::pair<ISecurityManagerListener*, os::Handler*>> listeners_;
  UI* user_interface_ = nullptr;
+18 −1
Original line number Diff line number Diff line
@@ -19,7 +19,8 @@

#include "os/log.h"

using namespace bluetooth::security;
namespace bluetooth {
namespace security {

// Definition of Pure Virtual Destructor
ISecurityManagerListener::~ISecurityManagerListener() {}
@@ -67,3 +68,19 @@ void SecurityManager::UnregisterCallbackListener(ISecurityManagerListener* liste
  security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::UnregisterCallbackListener,
                                           common::Unretained(security_manager_impl_), listener));
}

void SecurityManager::OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) {
  security_handler_->Post(common::BindOnce(&internal::SecurityManagerImpl::OnPairingPromptAccepted,
                                           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,
                                           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,
                                           common::Unretained(security_manager_impl_), address, passkey));
}

}  // namespace security
}  // namespace bluetooth
+5 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ namespace security {
 * Manages the security attributes, pairing, bonding of devices, and the
 * encryption/decryption of communications.
 */
class SecurityManager {
class SecurityManager : public UICallbacks {
 public:
  friend class SecurityModule;

@@ -88,6 +88,10 @@ class SecurityManager {
   */
  void UnregisterCallbackListener(ISecurityManagerListener* listener);

  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;

 protected:
  SecurityManager(os::Handler* security_handler, internal::SecurityManagerImpl* security_manager_impl)
      : security_handler_(security_handler), security_manager_impl_(security_manager_impl) {}
Loading