Jakub Pawlowski | fa057bd | 2019-10-10 14:36:29 +0200 | [diff] [blame] | 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 | |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 17 | #define LOG_TAG "security" |
Jakub Pawlowski | fa057bd | 2019-10-10 14:36:29 +0200 | [diff] [blame] | 18 | |
| 19 | #include <memory> |
| 20 | #include "module.h" |
| 21 | #include "os/handler.h" |
| 22 | #include "os/log.h" |
| 23 | |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 24 | #include "hci/hci_layer.h" |
Jakub Pawlowski | fa057bd | 2019-10-10 14:36:29 +0200 | [diff] [blame] | 25 | #include "l2cap/le/l2cap_le_module.h" |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 26 | #include "security/channel/security_manager_channel.h" |
Jakub Pawlowski | fa057bd | 2019-10-10 14:36:29 +0200 | [diff] [blame] | 27 | #include "security/internal/security_manager_impl.h" |
| 28 | #include "security/security_module.h" |
| 29 | |
| 30 | namespace bluetooth { |
| 31 | namespace security { |
| 32 | |
| 33 | const ModuleFactory SecurityModule::Factory = ModuleFactory([]() { return new SecurityModule(); }); |
| 34 | |
| 35 | struct SecurityModule::impl { |
| 36 | impl(os::Handler* security_handler, l2cap::le::L2capLeModule* l2cap_le_module, |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 37 | l2cap::classic::L2capClassicModule* l2cap_classic_module, hci::HciLayer* hci_layer) |
Jakub Pawlowski | fa057bd | 2019-10-10 14:36:29 +0200 | [diff] [blame] | 38 | : security_handler_(security_handler), l2cap_le_module_(l2cap_le_module), |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 39 | l2cap_classic_module_(l2cap_classic_module), |
| 40 | security_manager_channel_(new channel::SecurityManagerChannel(security_handler_, hci_layer)) {} |
| 41 | |
Jakub Pawlowski | fa057bd | 2019-10-10 14:36:29 +0200 | [diff] [blame] | 42 | os::Handler* security_handler_; |
| 43 | l2cap::le::L2capLeModule* l2cap_le_module_; |
| 44 | l2cap::classic::L2capClassicModule* l2cap_classic_module_; |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 45 | channel::SecurityManagerChannel* security_manager_channel_; |
| 46 | internal::SecurityManagerImpl security_manager_impl{security_handler_, l2cap_le_module_, l2cap_classic_module_, |
| 47 | security_manager_channel_}; |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 48 | ~impl() { |
| 49 | delete security_manager_channel_; |
| 50 | } |
Jakub Pawlowski | fa057bd | 2019-10-10 14:36:29 +0200 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | void SecurityModule::ListDependencies(ModuleList* list) { |
| 54 | list->add<l2cap::le::L2capLeModule>(); |
| 55 | list->add<l2cap::classic::L2capClassicModule>(); |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 56 | list->add<hci::HciLayer>(); |
Jakub Pawlowski | fa057bd | 2019-10-10 14:36:29 +0200 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void SecurityModule::Start() { |
| 60 | pimpl_ = std::make_unique<impl>(GetHandler(), GetDependency<l2cap::le::L2capLeModule>(), |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 61 | GetDependency<l2cap::classic::L2capClassicModule>(), GetDependency<hci::HciLayer>()); |
Jakub Pawlowski | fa057bd | 2019-10-10 14:36:29 +0200 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void SecurityModule::Stop() { |
| 65 | pimpl_.reset(); |
| 66 | } |
| 67 | |
Zongheng Wang | 6fd349a | 2019-11-12 16:14:01 -0800 | [diff] [blame] | 68 | std::string SecurityModule::ToString() const { |
| 69 | return "Security Module"; |
| 70 | } |
| 71 | |
Jakub Pawlowski | fa057bd | 2019-10-10 14:36:29 +0200 | [diff] [blame] | 72 | std::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 |