SecurityModule: Implement API, Add BluetoothAddressWithType

Bug: 145638110
Test: Targets compile
Change-Id: I2d101e9cc2a642a93e1c5af43301dc7ddb2f6864
diff --git a/gd/facade/common.proto b/gd/facade/common.proto
index 358db04..377de36 100644
--- a/gd/facade/common.proto
+++ b/gd/facade/common.proto
@@ -31,6 +31,11 @@
   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;
diff --git a/gd/security/facade.cc b/gd/security/facade.cc
index 39d4e52..2f772fa 100644
--- a/gd/security/facade.cc
+++ b/gd/security/facade.cc
@@ -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));
diff --git a/gd/security/facade.h b/gd/security/facade.h
index 8f060c2..fb655d1 100644
--- a/gd/security/facade.h
+++ b/gd/security/facade.h
@@ -18,6 +18,7 @@
 #include <grpc++/grpc++.h>
 
 #include "grpc/grpc_module.h"
+#include "hci/address_with_type.h"
 
 namespace bluetooth {
 namespace security {
diff --git a/gd/security/facade.proto b/gd/security/facade.proto
index 853180d..394c35b 100644
--- a/gd/security/facade.proto
+++ b/gd/security/facade.proto
@@ -6,7 +6,7 @@
 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) {}
 }