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

Commit 394c6807 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes from topic "sm-facade"

* changes:
  SecurityModule: Implement API, Add BluetoothAddressWithType
  SecurityModule: Facade infrastructure
parents bdc6000e e53d8a2e
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",
    ],
}

+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;
+7 −0
Original line number Diff line number Diff line
@@ -26,3 +26,10 @@ filegroup {
        ":BluetoothSecurityPairingTestSources",
    ],
}

filegroup {
     name: "BluetoothFacade_security_layer",
     srcs: [
         "facade.cc",
     ],
}
+105 −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 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) {
    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));
  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
+42 −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"
#include "hci/address_with_type.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
Loading