1 /*
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
17 #define LOG_TAG "security"
18
19 #include <memory>
20 #include "module.h"
21 #include "os/handler.h"
22 #include "os/log.h"
23
24 #include "hci/hci_layer.h"
25 #include "l2cap/le/l2cap_le_module.h"
26 #include "security/channel/security_manager_channel.h"
27 #include "security/internal/security_manager_impl.h"
28 #include "security/security_module.h"
29
30 namespace bluetooth {
31 namespace security {
32
__anon4973b6b50102() 33 const ModuleFactory SecurityModule::Factory = ModuleFactory([]() { return new SecurityModule(); });
34
35 struct SecurityModule::impl {
implbluetooth::security::SecurityModule::impl36 impl(os::Handler* security_handler, l2cap::le::L2capLeModule* l2cap_le_module,
37 l2cap::classic::L2capClassicModule* l2cap_classic_module, hci::HciLayer* hci_layer)
38 : security_handler_(security_handler), l2cap_le_module_(l2cap_le_module),
39 l2cap_classic_module_(l2cap_classic_module),
40 security_manager_channel_(new channel::SecurityManagerChannel(security_handler_, hci_layer)),
41 hci_layer_(hci_layer) {}
42
43 os::Handler* security_handler_;
44 l2cap::le::L2capLeModule* l2cap_le_module_;
45 l2cap::classic::L2capClassicModule* l2cap_classic_module_;
46 channel::SecurityManagerChannel* security_manager_channel_;
47 hci::HciLayer* hci_layer_;
48 internal::SecurityManagerImpl security_manager_impl{security_handler_, l2cap_le_module_, l2cap_classic_module_,
49 security_manager_channel_, hci_layer_};
~implbluetooth::security::SecurityModule::impl50 ~impl() {
51 delete security_manager_channel_;
52 }
53 };
54
ListDependencies(ModuleList * list)55 void SecurityModule::ListDependencies(ModuleList* list) {
56 list->add<l2cap::le::L2capLeModule>();
57 list->add<l2cap::classic::L2capClassicModule>();
58 list->add<hci::HciLayer>();
59 }
60
Start()61 void SecurityModule::Start() {
62 pimpl_ = std::make_unique<impl>(GetHandler(), GetDependency<l2cap::le::L2capLeModule>(),
63 GetDependency<l2cap::classic::L2capClassicModule>(), GetDependency<hci::HciLayer>());
64 }
65
Stop()66 void SecurityModule::Stop() {
67 pimpl_.reset();
68 }
69
ToString() const70 std::string SecurityModule::ToString() const {
71 return "Security Module";
72 }
73
GetSecurityManager()74 std::unique_ptr<SecurityManager> SecurityModule::GetSecurityManager() {
75 return std::unique_ptr<SecurityManager>(
76 new SecurityManager(pimpl_->security_handler_, &pimpl_->security_manager_impl));
77 }
78
79 } // namespace security
80 } // namespace bluetooth