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 "bt_shim"
18
19 #include "main/shim/shim.h"
20
21 #include <bluetooth/log.h>
22
23 #include "main/shim/hci_layer.h"
24 #include "main/shim/stack.h"
25 #include "stack/include/btu_hcif.h"
26 #include "stack/include/main_thread.h"
27
28 static const hci_t* hci;
29
post_to_main_message_loop(BT_HDR * p_msg)30 static void post_to_main_message_loop(BT_HDR* p_msg) {
31 if (do_in_main_thread(base::Bind(&btu_hci_msg_process, p_msg)) != BT_STATUS_SUCCESS) {
32 bluetooth::log::error("do_in_main_thread failed");
33 }
34 }
35
ShimModuleStartUp()36 static future_t* ShimModuleStartUp() {
37 hci = bluetooth::shim::hci_layer_get_interface();
38 bluetooth::log::assert_that(hci, "could not get hci layer interface.");
39
40 hci->set_data_cb(base::Bind(&post_to_main_message_loop));
41
42 bluetooth::shim::Stack::GetInstance()->StartEverything();
43 return kReturnImmediate;
44 }
45
GeneralShutDown()46 static future_t* GeneralShutDown() {
47 bluetooth::shim::Stack::GetInstance()->Stop();
48 return kReturnImmediate;
49 }
50
51 EXPORT_SYMBOL extern const module_t gd_shim_module = {.name = GD_SHIM_MODULE,
52 .init = kUnusedModuleApi,
53 .start_up = ShimModuleStartUp,
54 .shut_down = GeneralShutDown,
55 .clean_up = kUnusedModuleApi,
56 .dependencies = {kUnusedModuleDependencies}};
57
is_gd_stack_started_up()58 bool bluetooth::shim::is_gd_stack_started_up() {
59 return bluetooth::shim::Stack::GetInstance()->IsRunning();
60 }
61