blob: 8b7ebfe691f05b945c749ee7ad24b753f203b7a4 [file] [log] [blame]
Chris Manton1bb0e512019-09-09 21:11:59 -07001/*
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 Manton38d95962019-10-28 17:29:29 -070017#define LOG_TAG "bt_gd_shim"
Chris Manton1bb0e512019-09-09 21:11:59 -070018
19#include "shim/stack.h"
Jakub Pawlowski3d6f4042020-01-28 16:53:20 +010020#include "att/att_module.h"
Chris Manton1bb0e512019-09-09 21:11:59 -070021#include "hal/hci_hal.h"
22#include "hci/acl_manager.h"
Jakub Pawlowskid37537b2020-02-20 01:25:54 +010023#include "hci/hci_layer.h"
Chris Manton363df182019-11-15 16:17:36 -080024#include "hci/le_advertising_manager.h"
Chris Mantonc34a6052019-11-15 18:10:17 -080025#include "hci/le_scanning_manager.h"
Jack Heff38d892019-10-03 17:11:07 -070026#include "l2cap/classic/l2cap_classic_module.h"
27#include "l2cap/le/l2cap_le_module.h"
Chris Mantonee8c0a92019-10-17 10:56:37 -070028#include "neighbor/connectability.h"
29#include "neighbor/discoverability.h"
30#include "neighbor/inquiry.h"
Chris Manton20d735c2019-11-15 12:23:13 -080031#include "neighbor/name.h"
Chris Manton9d886fc2020-02-13 16:19:05 -080032#include "neighbor/name_db.h"
Chris Mantonee8c0a92019-10-17 10:56:37 -070033#include "neighbor/page.h"
34#include "neighbor/scan.h"
Chris Manton1bb0e512019-09-09 21:11:59 -070035#include "os/log.h"
36#include "os/thread.h"
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020037#include "security/security_module.h"
Chris Manton0cb19c82020-01-13 21:11:48 -080038#include "shim/dumpsys.h"
Chris Manton38d95962019-10-28 17:29:29 -070039#include "shim/l2cap.h"
Chris Manton1bb0e512019-09-09 21:11:59 -070040#include "stack_manager.h"
Chris Manton9743d202020-01-17 10:32:53 -080041#include "storage/legacy.h"
Chris Manton1bb0e512019-09-09 21:11:59 -070042
43using ::bluetooth::os::Thread;
44
45struct 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 Pawlowski3d6f4042020-01-28 16:53:20 +010054 modules.add<::bluetooth::att::AttModule>();
Chris Manton1bb0e512019-09-09 21:11:59 -070055 modules.add<::bluetooth::hal::HciHal>();
56 modules.add<::bluetooth::hci::AclManager>();
Jakub Pawlowskid37537b2020-02-20 01:25:54 +010057 modules.add<::bluetooth::hci::HciLayer>();
Chris Manton363df182019-11-15 16:17:36 -080058 modules.add<::bluetooth::hci::LeAdvertisingManager>();
Chris Mantonc34a6052019-11-15 18:10:17 -080059 modules.add<::bluetooth::hci::LeScanningManager>();
Jack Heff38d892019-10-03 17:11:07 -070060 modules.add<::bluetooth::l2cap::classic::L2capClassicModule>();
61 modules.add<::bluetooth::l2cap::le::L2capLeModule>();
Chris Mantonee8c0a92019-10-17 10:56:37 -070062 modules.add<::bluetooth::neighbor::ConnectabilityModule>();
63 modules.add<::bluetooth::neighbor::DiscoverabilityModule>();
64 modules.add<::bluetooth::neighbor::InquiryModule>();
Chris Manton20d735c2019-11-15 12:23:13 -080065 modules.add<::bluetooth::neighbor::NameModule>();
Chris Manton9d886fc2020-02-13 16:19:05 -080066 modules.add<::bluetooth::neighbor::NameDbModule>();
Chris Mantonee8c0a92019-10-17 10:56:37 -070067 modules.add<::bluetooth::neighbor::PageModule>();
68 modules.add<::bluetooth::neighbor::ScanModule>();
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020069 modules.add<::bluetooth::security::SecurityModule>();
Chris Manton9743d202020-01-17 10:32:53 -080070 modules.add<::bluetooth::storage::LegacyModule>();
Chris Manton0cb19c82020-01-13 21:11:48 -080071 modules.add<::bluetooth::shim::Dumpsys>();
Chris Manton38d95962019-10-28 17:29:29 -070072 modules.add<::bluetooth::shim::L2cap>();
Chris Manton1bb0e512019-09-09 21:11:59 -070073
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 Pawlowskic73a8952020-02-16 01:03:04 +010094 StackManager* GetStackManager() {
Chris Manton1e406522020-01-06 15:17:17 -080095 ASSERT(is_running_);
Jakub Pawlowskic73a8952020-02-16 01:03:04 +010096 return &stack_manager_;
Chris Mantoneac8e512020-01-11 21:14:45 -080097 }
98
Chris Manton1bb0e512019-09-09 21:11:59 -070099 private:
100 os::Thread* stack_thread_ = nullptr;
101 bool is_running_ = false;
102 StackManager stack_manager_;
103};
104
105bluetooth::shim::Stack::Stack() {
106 pimpl_ = std::make_unique<impl>();
107 LOG_INFO("%s Created gd stack", __func__);
108}
109
110void bluetooth::shim::Stack::Start() {
111 pimpl_->Start();
112}
113
114void bluetooth::shim::Stack::Stop() {
115 pimpl_->Stop();
116}
117
Jakub Pawlowskic73a8952020-02-16 01:03:04 +0100118bluetooth::StackManager* bluetooth::shim::Stack::GetStackManager() {
119 return pimpl_->GetStackManager();
Chris Manton363df182019-11-15 16:17:36 -0800120}
121
Jakub Pawlowskic73a8952020-02-16 01:03:04 +0100122bluetooth::shim::Stack* bluetooth::shim::GetGabeldorscheStack() {
123 static Stack* instance = new Stack();
Chris Manton1bb0e512019-09-09 21:11:59 -0700124 return instance;
125}