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

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

SecurityModule: Facade infrastructure

Bug: 145638110
Test: Targets compile
Change-Id: I2cd9a366b861eb806099ec32798d49bbc92b5421
parent db1d4025
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ cc_binary {
        ":BluetoothFacade_hci_hal",
        ":BluetoothFacade_hci_layer",
        ":BluetoothFacade_l2cap_layer",
        ":BluetoothFacade_security_layer",
    ],
    generated_headers: [
        "BluetoothGeneratedPackets_h",
@@ -400,6 +401,7 @@ filegroup {
        "hci/facade.proto",
        "hci/facade/le_advertising_manager_facade.proto",
        "l2cap/classic/facade.proto",
        "security/facade.proto",
    ],
}

@@ -426,6 +428,8 @@ genrule {
        "hci/facade/le_advertising_manager_facade.pb.h",
        "l2cap/classic/facade.grpc.pb.h",
        "l2cap/classic/facade.pb.h",
        "security/facade.grpc.pb.h",
        "security/facade.pb.h",
    ],
}

@@ -452,6 +456,8 @@ genrule {
        "hci/facade/le_advertising_manager_facade.pb.cc",
        "l2cap/classic/facade.grpc.pb.cc",
        "l2cap/classic/facade.pb.cc",
        "security/facade.grpc.pb.cc",
        "security/facade.pb.cc",
    ],
}

+7 −0
Original line number Diff line number Diff line
@@ -26,3 +26,10 @@ filegroup {
        ":BluetoothSecurityPairingTestSources",
    ],
}

filegroup {
     name: "BluetoothFacade_security_layer",
     srcs: [
         "facade.cc",
     ],
}
+72 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "security/facade.h"
#include "hci/hci_layer.h"
#include "l2cap/classic/l2cap_classic_module.h"
#include "l2cap/le/l2cap_le_module.h"
#include "os/handler.h"
#include "security/facade.grpc.pb.h"
#include "security/security_module.h"

namespace bluetooth {
namespace security {

class SecurityModuleFacadeService : public SecurityModuleFacade::Service {
 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
  }

 private:
  SecurityModule* security_module_ __attribute__((unused));
  l2cap::le::L2capLeModule* l2cap_le_module_ __attribute__((unused));
  l2cap::classic::L2capClassicModule* l2cap_classic_module_ __attribute__((unused));
  ::bluetooth::os::Handler* security_handler_ __attribute__((unused));
};

void SecurityModuleFacadeModule::ListDependencies(ModuleList* list) {
  ::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list);
  list->add<SecurityModule>();
  list->add<l2cap::le::L2capLeModule>();
  list->add<l2cap::classic::L2capClassicModule>();
  list->add<hci::HciLayer>();
}

void SecurityModuleFacadeModule::Start() {
  ::bluetooth::grpc::GrpcFacadeModule::Start();
  service_ = new SecurityModuleFacadeService(GetDependency<SecurityModule>(), GetDependency<l2cap::le::L2capLeModule>(),
                                             GetDependency<l2cap::classic::L2capClassicModule>(),
                                             GetDependency<hci::HciLayer>(), GetHandler());
}

void SecurityModuleFacadeModule::Stop() {
  delete service_;
  ::bluetooth::grpc::GrpcFacadeModule::Stop();
}

::grpc::Service* SecurityModuleFacadeModule::GetService() const {
  return service_;
}

const ModuleFactory SecurityModuleFacadeModule::Factory =
    ::bluetooth::ModuleFactory([]() { return new SecurityModuleFacadeModule(); });

}  // namespace security
}  // namespace bluetooth
+41 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#include <grpc++/grpc++.h>

#include "grpc/grpc_module.h"

namespace bluetooth {
namespace security {

class SecurityModuleFacadeService;

class SecurityModuleFacadeModule : public ::bluetooth::grpc::GrpcFacadeModule {
 public:
  static const ModuleFactory Factory;

  void ListDependencies(ModuleList* list) override;
  void Start() override;
  void Stop() override;
  ::grpc::Service* GetService() const override;

 private:
  SecurityModuleFacadeService* service_;
};

}  // namespace security
}  // namespace bluetooth
+12 −0
Original line number Diff line number Diff line
syntax = "proto3";

package bluetooth.security;

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) {}
}