blob: b1f7c66357a6e803da9eaae59ef91aba2050a015 [file] [log] [blame]
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +02001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Martin Brabham605d6f12019-03-29 12:02:30 -070017#define LOG_TAG "security"
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020018
19#include <memory>
20#include "module.h"
21#include "os/handler.h"
22#include "os/log.h"
23
Martin Brabham605d6f12019-03-29 12:02:30 -070024#include "hci/hci_layer.h"
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020025#include "l2cap/le/l2cap_le_module.h"
Martin Brabham605d6f12019-03-29 12:02:30 -070026#include "security/channel/security_manager_channel.h"
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020027#include "security/internal/security_manager_impl.h"
28#include "security/security_module.h"
29
30namespace bluetooth {
31namespace security {
32
33const ModuleFactory SecurityModule::Factory = ModuleFactory([]() { return new SecurityModule(); });
34
35struct SecurityModule::impl {
36 impl(os::Handler* security_handler, l2cap::le::L2capLeModule* l2cap_le_module,
Martin Brabham605d6f12019-03-29 12:02:30 -070037 l2cap::classic::L2capClassicModule* l2cap_classic_module, hci::HciLayer* hci_layer)
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020038 : security_handler_(security_handler), l2cap_le_module_(l2cap_le_module),
Martin Brabham605d6f12019-03-29 12:02:30 -070039 l2cap_classic_module_(l2cap_classic_module),
40 security_manager_channel_(new channel::SecurityManagerChannel(security_handler_, hci_layer)) {}
41
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020042 os::Handler* security_handler_;
43 l2cap::le::L2capLeModule* l2cap_le_module_;
44 l2cap::classic::L2capClassicModule* l2cap_classic_module_;
Martin Brabham605d6f12019-03-29 12:02:30 -070045 channel::SecurityManagerChannel* security_manager_channel_;
46 internal::SecurityManagerImpl security_manager_impl{security_handler_, l2cap_le_module_, l2cap_classic_module_,
47 security_manager_channel_};
Martin Brabham80854c22019-11-12 14:52:42 -080048 ~impl() {
49 delete security_manager_channel_;
50 }
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020051};
52
53void SecurityModule::ListDependencies(ModuleList* list) {
54 list->add<l2cap::le::L2capLeModule>();
55 list->add<l2cap::classic::L2capClassicModule>();
Martin Brabham605d6f12019-03-29 12:02:30 -070056 list->add<hci::HciLayer>();
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020057}
58
59void SecurityModule::Start() {
60 pimpl_ = std::make_unique<impl>(GetHandler(), GetDependency<l2cap::le::L2capLeModule>(),
Martin Brabham605d6f12019-03-29 12:02:30 -070061 GetDependency<l2cap::classic::L2capClassicModule>(), GetDependency<hci::HciLayer>());
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020062}
63
64void SecurityModule::Stop() {
65 pimpl_.reset();
66}
67
Zongheng Wang6fd349a2019-11-12 16:14:01 -080068std::string SecurityModule::ToString() const {
69 return "Security Module";
70}
71
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020072std::unique_ptr<SecurityManager> SecurityModule::GetSecurityManager() {
73 return std::unique_ptr<SecurityManager>(
74 new SecurityManager(pimpl_->security_handler_, &pimpl_->security_manager_impl));
75}
76
77} // namespace security
78} // namespace bluetooth