• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/acl_manager.h"
25 #include "hci/hci_layer.h"
26 #include "l2cap/le/l2cap_le_module.h"
27 #include "neighbor/name_db.h"
28 #include "security/channel/security_manager_channel.h"
29 #include "security/facade_configuration_api.h"
30 #include "security/internal/security_manager_impl.h"
31 #include "security/l2cap_security_module_interface.h"
32 #include "security/security_module.h"
33 #include "storage/storage_module.h"
34 
35 namespace bluetooth {
36 namespace security {
37 
__anon04ad4f110102() 38 const ModuleFactory SecurityModule::Factory = ModuleFactory([]() { return new SecurityModule(); });
39 
40 struct SecurityModule::impl {
implbluetooth::security::SecurityModule::impl41   impl(
42       os::Handler* security_handler,
43       l2cap::le::L2capLeModule* l2cap_le_module,
44       l2cap::classic::L2capClassicModule* l2cap_classic_module,
45       hci::HciLayer* hci_layer,
46       hci::AclManager* acl_manager,
47       hci::Controller* controller,
48       storage::StorageModule* storage_module,
49       neighbor::NameDbModule* name_db_module)
50       : security_handler_(security_handler),
51         l2cap_classic_module_(l2cap_classic_module),
52         l2cap_le_module_(l2cap_le_module),
53         security_manager_channel_(new channel::SecurityManagerChannel(security_handler_, hci_layer)),
54         hci_layer_(hci_layer),
55         acl_manager_(acl_manager),
56         controller_(controller),
57         storage_module_(storage_module),
58         l2cap_security_interface_(&security_manager_impl, security_handler),
59         name_db_module_(name_db_module) {
60     l2cap_classic_module->InjectSecurityEnforcementInterface(&l2cap_security_interface_);
61     l2cap_le_module->InjectSecurityEnforcementInterface(&l2cap_security_interface_);
62     security_manager_channel_->SetSecurityInterface(
63         l2cap_classic_module->GetSecurityInterface(security_handler_, security_manager_channel_));
64   }
65 
66   os::Handler* security_handler_;
67   l2cap::classic::L2capClassicModule* l2cap_classic_module_;
68   l2cap::le::L2capLeModule* l2cap_le_module_;
69   channel::SecurityManagerChannel* security_manager_channel_;
70   hci::HciLayer* hci_layer_;
71   hci::AclManager* acl_manager_;
72   hci::Controller* controller_;
73   storage::StorageModule* storage_module_;
74   L2capSecurityModuleInterface l2cap_security_interface_;
75   neighbor::NameDbModule* name_db_module_;
76 
77   internal::SecurityManagerImpl security_manager_impl{security_handler_,
78                                                       l2cap_le_module_,
79                                                       security_manager_channel_,
80                                                       hci_layer_,
81                                                       acl_manager_,
82                                                       controller_,
83                                                       storage_module_,
84                                                       name_db_module_};
85 
~implbluetooth::security::SecurityModule::impl86   ~impl() {
87     delete security_manager_channel_;
88     l2cap_classic_module_->InjectSecurityEnforcementInterface(nullptr);
89     l2cap_le_module_->InjectSecurityEnforcementInterface(nullptr);
90   }
91 };
92 
ListDependencies(ModuleList * list)93 void SecurityModule::ListDependencies(ModuleList* list) {
94   list->add<l2cap::le::L2capLeModule>();
95   list->add<l2cap::classic::L2capClassicModule>();
96   list->add<hci::HciLayer>();
97   list->add<hci::AclManager>();
98   list->add<hci::Controller>();
99   list->add<storage::StorageModule>();
100   list->add<neighbor::NameDbModule>();
101 }
102 
Start()103 void SecurityModule::Start() {
104   pimpl_ = std::make_unique<impl>(
105       GetHandler(),
106       GetDependency<l2cap::le::L2capLeModule>(),
107       GetDependency<l2cap::classic::L2capClassicModule>(),
108       GetDependency<hci::HciLayer>(),
109       GetDependency<hci::AclManager>(),
110       GetDependency<hci::Controller>(),
111       GetDependency<storage::StorageModule>(),
112       GetDependency<neighbor::NameDbModule>());
113 
114   GetDependency<hci::AclManager>()->SetSecurityModule(this);
115 }
116 
Stop()117 void SecurityModule::Stop() {
118   pimpl_.reset();
119 }
120 
ToString() const121 std::string SecurityModule::ToString() const {
122   return "Security Module";
123 }
124 
GetSecurityManager()125 std::unique_ptr<SecurityManager> SecurityModule::GetSecurityManager() {
126   return std::unique_ptr<SecurityManager>(
127       new SecurityManager(pimpl_->security_handler_, &pimpl_->security_manager_impl));
128 }
129 
GetFacadeConfigurationApi()130 std::unique_ptr<FacadeConfigurationApi> SecurityModule::GetFacadeConfigurationApi() {
131   return std::unique_ptr<FacadeConfigurationApi>(
132       new FacadeConfigurationApi(pimpl_->security_handler_, &pimpl_->security_manager_impl));
133 }
134 
135 }  // namespace security
136 }  // namespace bluetooth