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

Commit 809948c1 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

SecurityModule boilerplate code

This is boilerplate code for SecurityModule and SecurityManager

Bug: 142341141
Test: no test yet
Change-Id: Ie08c8ef7ee78e71a9c61dff6b45192ce0e1c3f1c
parent 85977b2b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ filegroup {
        "pairing_handler_le.cc",
        "pairing_handler_le_legacy.cc",
        "pairing_handler_le_secure_connections.cc",
        "security_module.cc",
    ]
}

+46 −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 "l2cap/classic/l2cap_classic_module.h"
#include "l2cap/le/l2cap_le_module.h"
#include "os/handler.h"

namespace bluetooth {
namespace security {
namespace internal {

class SecurityManagerImpl {
 public:
  explicit SecurityManagerImpl(os::Handler* security_handler, l2cap::le::L2capLeModule* l2cap_le_module,
                               l2cap::classic::L2capClassicModule* l2cap_classic_module)
      : security_handler_(security_handler), l2cap_le_module_(l2cap_le_module),
        l2cap_classic_module_(l2cap_classic_module) {}
  virtual ~SecurityManagerImpl() = default;

  // All APIs must be invoked in L2CAP layer handler

  // TODO: put all API methods here

 private:
  os::Handler* security_handler_ __attribute__((unused));
  l2cap::le::L2capLeModule* l2cap_le_module_ __attribute__((unused));
  l2cap::classic::L2capClassicModule* l2cap_classic_module_ __attribute__((unused));
};
}  // namespace internal
}  // 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 "security/internal/security_manager_impl.h"

namespace bluetooth {
namespace security {

class SecurityManager {
 public:
  // TODO: put SMP API methods here

  friend class SecurityModule;

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

  os::Handler* security_handler_ = nullptr;
  internal::SecurityManagerImpl* security_manager_impl_;
  DISALLOW_COPY_AND_ASSIGN(SecurityManager);
};

}  // namespace security
}  // namespace bluetooth
 No newline at end of file
+65 −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.
 */

#define LOG_TAG "smp"

#include <memory>
#include "module.h"
#include "os/handler.h"
#include "os/log.h"

#include "l2cap/classic/l2cap_classic_module.h"
#include "l2cap/le/l2cap_le_module.h"
#include "security/internal/security_manager_impl.h"
#include "security/security_module.h"

namespace bluetooth {
namespace security {

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

struct SecurityModule::impl {
  impl(os::Handler* security_handler, l2cap::le::L2capLeModule* l2cap_le_module,
       l2cap::classic::L2capClassicModule* l2cap_classic_module)
      : security_handler_(security_handler), l2cap_le_module_(l2cap_le_module),
        l2cap_classic_module_(l2cap_classic_module) {}
  os::Handler* security_handler_;
  l2cap::le::L2capLeModule* l2cap_le_module_;
  l2cap::classic::L2capClassicModule* l2cap_classic_module_;
  internal::SecurityManagerImpl security_manager_impl{security_handler_, l2cap_le_module_, l2cap_classic_module_};
};

void SecurityModule::ListDependencies(ModuleList* list) {
  list->add<l2cap::le::L2capLeModule>();
  list->add<l2cap::classic::L2capClassicModule>();
}

void SecurityModule::Start() {
  pimpl_ = std::make_unique<impl>(GetHandler(), GetDependency<l2cap::le::L2capLeModule>(),
                                  GetDependency<l2cap::classic::L2capClassicModule>());
}

void SecurityModule::Stop() {
  pimpl_.reset();
}

std::unique_ptr<SecurityManager> SecurityModule::GetSecurityManager() {
  return std::unique_ptr<SecurityManager>(
      new SecurityManager(pimpl_->security_handler_, &pimpl_->security_manager_impl));
}

}  // namespace security
}  // namespace bluetooth
 No newline at end of file
+52 −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 <memory>

#include "module.h"
#include "security/security_manager.h"

namespace bluetooth {
namespace security {

class SecurityModule : public bluetooth::Module {
 public:
  SecurityModule() = default;
  ~SecurityModule() = default;

  /**
   * Get the api to the SecurityManager
   */
  std::unique_ptr<SecurityManager> GetSecurityManager();

  static const ModuleFactory Factory;

 protected:
  void ListDependencies(ModuleList* list) override;

  void Start() override;

  void Stop() override;

 private:
  struct impl;
  std::unique_ptr<impl> pimpl_;
  DISALLOW_COPY_AND_ASSIGN(SecurityModule);
};

}  // namespace security
}  // namespace bluetooth
Loading