Chris Manton | 1bb0e51 | 2019-09-09 21:11:59 -0700 | [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 | |
Chris Manton | 38d9596 | 2019-10-28 17:29:29 -0700 | [diff] [blame] | 17 | #define LOG_TAG "bt_gd_shim" |
Chris Manton | 1bb0e51 | 2019-09-09 21:11:59 -0700 | [diff] [blame] | 18 | |
| 19 | #include "shim/stack.h" |
Jakub Pawlowski | 3d6f404 | 2020-01-28 16:53:20 +0100 | [diff] [blame] | 20 | #include "att/att_module.h" |
Chris Manton | 1bb0e51 | 2019-09-09 21:11:59 -0700 | [diff] [blame] | 21 | #include "hal/hci_hal.h" |
| 22 | #include "hci/acl_manager.h" |
Jakub Pawlowski | d37537b | 2020-02-20 01:25:54 +0100 | [diff] [blame] | 23 | #include "hci/hci_layer.h" |
Chris Manton | 363df18 | 2019-11-15 16:17:36 -0800 | [diff] [blame] | 24 | #include "hci/le_advertising_manager.h" |
Chris Manton | c34a605 | 2019-11-15 18:10:17 -0800 | [diff] [blame] | 25 | #include "hci/le_scanning_manager.h" |
Jack He | ff38d89 | 2019-10-03 17:11:07 -0700 | [diff] [blame] | 26 | #include "l2cap/classic/l2cap_classic_module.h" |
| 27 | #include "l2cap/le/l2cap_le_module.h" |
Chris Manton | ee8c0a9 | 2019-10-17 10:56:37 -0700 | [diff] [blame] | 28 | #include "neighbor/connectability.h" |
| 29 | #include "neighbor/discoverability.h" |
| 30 | #include "neighbor/inquiry.h" |
Chris Manton | 20d735c | 2019-11-15 12:23:13 -0800 | [diff] [blame] | 31 | #include "neighbor/name.h" |
Chris Manton | 9d886fc | 2020-02-13 16:19:05 -0800 | [diff] [blame] | 32 | #include "neighbor/name_db.h" |
Chris Manton | ee8c0a9 | 2019-10-17 10:56:37 -0700 | [diff] [blame] | 33 | #include "neighbor/page.h" |
| 34 | #include "neighbor/scan.h" |
Chris Manton | 1bb0e51 | 2019-09-09 21:11:59 -0700 | [diff] [blame] | 35 | #include "os/log.h" |
| 36 | #include "os/thread.h" |
Jakub Pawlowski | fa057bd | 2019-10-10 14:36:29 +0200 | [diff] [blame] | 37 | #include "security/security_module.h" |
Chris Manton | 0cb19c8 | 2020-01-13 21:11:48 -0800 | [diff] [blame] | 38 | #include "shim/dumpsys.h" |
Chris Manton | 38d9596 | 2019-10-28 17:29:29 -0700 | [diff] [blame] | 39 | #include "shim/l2cap.h" |
Chris Manton | 1bb0e51 | 2019-09-09 21:11:59 -0700 | [diff] [blame] | 40 | #include "stack_manager.h" |
Chris Manton | 9743d20 | 2020-01-17 10:32:53 -0800 | [diff] [blame] | 41 | #include "storage/legacy.h" |
Chris Manton | 1bb0e51 | 2019-09-09 21:11:59 -0700 | [diff] [blame] | 42 | |
| 43 | using ::bluetooth::os::Thread; |
| 44 | |
| 45 | struct bluetooth::shim::Stack::impl { |
| 46 | void Start() { |
| 47 | if (is_running_) { |
| 48 | LOG_ERROR("%s Gd stack already running", __func__); |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | LOG_INFO("%s Starting Gd stack", __func__); |
| 53 | ModuleList modules; |
Jakub Pawlowski | 3d6f404 | 2020-01-28 16:53:20 +0100 | [diff] [blame] | 54 | modules.add<::bluetooth::att::AttModule>(); |
Chris Manton | 1bb0e51 | 2019-09-09 21:11:59 -0700 | [diff] [blame] | 55 | modules.add<::bluetooth::hal::HciHal>(); |
| 56 | modules.add<::bluetooth::hci::AclManager>(); |
Jakub Pawlowski | d37537b | 2020-02-20 01:25:54 +0100 | [diff] [blame] | 57 | modules.add<::bluetooth::hci::HciLayer>(); |
Chris Manton | 363df18 | 2019-11-15 16:17:36 -0800 | [diff] [blame] | 58 | modules.add<::bluetooth::hci::LeAdvertisingManager>(); |
Chris Manton | c34a605 | 2019-11-15 18:10:17 -0800 | [diff] [blame] | 59 | modules.add<::bluetooth::hci::LeScanningManager>(); |
Jack He | ff38d89 | 2019-10-03 17:11:07 -0700 | [diff] [blame] | 60 | modules.add<::bluetooth::l2cap::classic::L2capClassicModule>(); |
| 61 | modules.add<::bluetooth::l2cap::le::L2capLeModule>(); |
Chris Manton | ee8c0a9 | 2019-10-17 10:56:37 -0700 | [diff] [blame] | 62 | modules.add<::bluetooth::neighbor::ConnectabilityModule>(); |
| 63 | modules.add<::bluetooth::neighbor::DiscoverabilityModule>(); |
| 64 | modules.add<::bluetooth::neighbor::InquiryModule>(); |
Chris Manton | 20d735c | 2019-11-15 12:23:13 -0800 | [diff] [blame] | 65 | modules.add<::bluetooth::neighbor::NameModule>(); |
Chris Manton | 9d886fc | 2020-02-13 16:19:05 -0800 | [diff] [blame] | 66 | modules.add<::bluetooth::neighbor::NameDbModule>(); |
Chris Manton | ee8c0a9 | 2019-10-17 10:56:37 -0700 | [diff] [blame] | 67 | modules.add<::bluetooth::neighbor::PageModule>(); |
| 68 | modules.add<::bluetooth::neighbor::ScanModule>(); |
Jakub Pawlowski | fa057bd | 2019-10-10 14:36:29 +0200 | [diff] [blame] | 69 | modules.add<::bluetooth::security::SecurityModule>(); |
Chris Manton | 9743d20 | 2020-01-17 10:32:53 -0800 | [diff] [blame] | 70 | modules.add<::bluetooth::storage::LegacyModule>(); |
Chris Manton | 0cb19c8 | 2020-01-13 21:11:48 -0800 | [diff] [blame] | 71 | modules.add<::bluetooth::shim::Dumpsys>(); |
Chris Manton | 38d9596 | 2019-10-28 17:29:29 -0700 | [diff] [blame] | 72 | modules.add<::bluetooth::shim::L2cap>(); |
Chris Manton | 1bb0e51 | 2019-09-09 21:11:59 -0700 | [diff] [blame] | 73 | |
| 74 | stack_thread_ = new Thread("gd_stack_thread", Thread::Priority::NORMAL); |
| 75 | stack_manager_.StartUp(&modules, stack_thread_); |
| 76 | // TODO(cmanton) Gd stack has spun up another thread with no |
| 77 | // ability to ascertain the completion |
| 78 | is_running_ = true; |
| 79 | LOG_INFO("%s Successfully toggled Gd stack", __func__); |
| 80 | } |
| 81 | |
| 82 | void Stop() { |
| 83 | if (!is_running_) { |
| 84 | LOG_ERROR("%s Gd stack not running", __func__); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | stack_manager_.ShutDown(); |
| 89 | delete stack_thread_; |
| 90 | is_running_ = false; |
| 91 | LOG_INFO("%s Successfully shut down Gd stack", __func__); |
| 92 | } |
| 93 | |
Jakub Pawlowski | c73a895 | 2020-02-16 01:03:04 +0100 | [diff] [blame] | 94 | StackManager* GetStackManager() { |
Chris Manton | 1e40652 | 2020-01-06 15:17:17 -0800 | [diff] [blame] | 95 | ASSERT(is_running_); |
Jakub Pawlowski | c73a895 | 2020-02-16 01:03:04 +0100 | [diff] [blame] | 96 | return &stack_manager_; |
Chris Manton | eac8e51 | 2020-01-11 21:14:45 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Chris Manton | 1bb0e51 | 2019-09-09 21:11:59 -0700 | [diff] [blame] | 99 | private: |
| 100 | os::Thread* stack_thread_ = nullptr; |
| 101 | bool is_running_ = false; |
| 102 | StackManager stack_manager_; |
| 103 | }; |
| 104 | |
| 105 | bluetooth::shim::Stack::Stack() { |
| 106 | pimpl_ = std::make_unique<impl>(); |
| 107 | LOG_INFO("%s Created gd stack", __func__); |
| 108 | } |
| 109 | |
| 110 | void bluetooth::shim::Stack::Start() { |
| 111 | pimpl_->Start(); |
| 112 | } |
| 113 | |
| 114 | void bluetooth::shim::Stack::Stop() { |
| 115 | pimpl_->Stop(); |
| 116 | } |
| 117 | |
Jakub Pawlowski | c73a895 | 2020-02-16 01:03:04 +0100 | [diff] [blame] | 118 | bluetooth::StackManager* bluetooth::shim::Stack::GetStackManager() { |
| 119 | return pimpl_->GetStackManager(); |
Chris Manton | 363df18 | 2019-11-15 16:17:36 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Jakub Pawlowski | c73a895 | 2020-02-16 01:03:04 +0100 | [diff] [blame] | 122 | bluetooth::shim::Stack* bluetooth::shim::GetGabeldorscheStack() { |
| 123 | static Stack* instance = new Stack(); |
Chris Manton | 1bb0e51 | 2019-09-09 21:11:59 -0700 | [diff] [blame] | 124 | return instance; |
| 125 | } |