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

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

SecurityModule: Implement API, Add BluetoothAddressWithType

Bug: 145638110
Test: Targets compile
Change-Id: I2d101e9cc2a642a93e1c5af43301dc7ddb2f6864
parent a28f3d2d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -31,6 +31,11 @@ enum BluetoothAddressTypeEnum {
  RANDOM_IDENTITY_ADDRESS = 0x3;
}

message BluetoothAddressWithType {
  BluetoothAddress address = 1;
  BluetoothAddressTypeEnum type = 2;
}

enum BluetoothPeerAddressTypeEnum {
  PUBLIC_DEVICE_OR_IDENTITY_ADDRESS = 0x0;
  RANDOM_DEVICE_OR_IDENTITY_ADDRESS = 0x1;
+35 −2
Original line number Diff line number Diff line
@@ -24,16 +24,49 @@
namespace bluetooth {
namespace security {

class SecurityModuleFacadeService : public SecurityModuleFacade::Service {
class SecurityModuleFacadeService : public SecurityModuleFacade::Service, public ISecurityManagerListener {
 public:
  SecurityModuleFacadeService(SecurityModule* security_module, l2cap::le::L2capLeModule* l2cap_le_module,
                              l2cap::classic::L2capClassicModule* l2cap_classic_module, hci::HciLayer* hci_layer,
                              ::bluetooth::os::Handler* security_handler)
      : security_module_(security_module), l2cap_le_module_(l2cap_le_module),
        l2cap_classic_module_(l2cap_classic_module), security_handler_(security_handler) {
    // TODO(optedoblivion): Register callback listener
    security_module_->GetSecurityManager()->RegisterCallbackListener(this, security_handler_);
  }

  ::grpc::Status CreateBond(::grpc::ServerContext* context, const facade::BluetoothAddressWithType* request,
                            ::google::protobuf::Empty* response) override {
    hci::Address peer;
    ASSERT(hci::Address::FromString(request->address().address(), peer));
    hci::AddressType peer_type = hci::AddressType::PUBLIC_DEVICE_ADDRESS;
    security_module_->GetSecurityManager()->CreateBond(hci::AddressWithType(peer, peer_type));
    return ::grpc::Status::OK;
  }

  ::grpc::Status CancelBond(::grpc::ServerContext* context, const facade::BluetoothAddressWithType* request,
                            ::google::protobuf::Empty* response) override {
    hci::Address peer;
    ASSERT(hci::Address::FromString(request->address().address(), peer));
    hci::AddressType peer_type = hci::AddressType::PUBLIC_DEVICE_ADDRESS;
    security_module_->GetSecurityManager()->CancelBond(hci::AddressWithType(peer, peer_type));
    return ::grpc::Status::OK;
  }

  ::grpc::Status RemoveBond(::grpc::ServerContext* context, const facade::BluetoothAddressWithType* request,
                            ::google::protobuf::Empty* response) override {
    hci::Address peer;
    ASSERT(hci::Address::FromString(request->address().address(), peer));
    hci::AddressType peer_type = hci::AddressType::PUBLIC_DEVICE_ADDRESS;
    security_module_->GetSecurityManager()->RemoveBond(hci::AddressWithType(peer, peer_type));
    return ::grpc::Status::OK;
  }

  void OnDeviceBonded(hci::AddressWithType device) {}

  void OnDeviceUnbonded(hci::AddressWithType device) {}

  void OnDeviceBondFailed(hci::AddressWithType device) {}

 private:
  SecurityModule* security_module_ __attribute__((unused));
  l2cap::le::L2capLeModule* l2cap_le_module_ __attribute__((unused));
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <grpc++/grpc++.h>

#include "grpc/grpc_module.h"
#include "hci/address_with_type.h"

namespace bluetooth {
namespace security {
+3 −3
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import "google/protobuf/empty.proto";
import "facade/common.proto";

service SecurityModuleFacade {
  rpc CreateBond(facade.BluetoothAddress) returns (google.protobuf.Empty) {}
  rpc CancelBond(facade.BluetoothAddress) returns (google.protobuf.Empty) {}
  rpc RemoveBond(facade.BluetoothAddress) returns (google.protobuf.Empty) {}
  rpc CreateBond(facade.BluetoothAddressWithType) returns (google.protobuf.Empty) {}
  rpc CancelBond(facade.BluetoothAddressWithType) returns (google.protobuf.Empty) {}
  rpc RemoveBond(facade.BluetoothAddressWithType) returns (google.protobuf.Empty) {}
}