1 /*
2 * Copyright 2024 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_btif_sock_hal"
18
19 #include "btif/include/btif_sock_hal.h"
20
21 #include "btif/include/btif_sock_l2cap.h"
22 #include "lpp/lpp_offload_interface.h"
23 #include "main/shim/entry.h"
24 #include "stack/include/main_thread.h"
25
26 using namespace bluetooth;
27
28 class BtifSocketHalCallback : public hal::SocketHalCallback {
29 public:
SocketOpenedComplete(uint64_t socket_id,hal::SocketStatus status) const30 void SocketOpenedComplete(uint64_t socket_id, hal::SocketStatus status) const override {
31 log::info("socket_id: {}, status: {}", socket_id, static_cast<int>(status));
32 do_in_main_thread(base::BindOnce(on_btsocket_l2cap_opened_complete, socket_id,
33 (status == hal::SocketStatus::SUCCESS)));
34 }
35
SocketClose(uint64_t socket_id) const36 void SocketClose(uint64_t socket_id) const override {
37 log::info("socket_id: {}", socket_id);
38 do_in_main_thread(base::BindOnce(on_btsocket_l2cap_close, socket_id));
39 }
40 };
41
42 static BtifSocketHalCallback btif_socket_hal_cb;
43
btsock_hal_init()44 bt_status_t btsock_hal_init() {
45 log::info("");
46 auto lpp_offload_manager_interface = bluetooth::shim::GetLppOffloadManager();
47 if (lpp_offload_manager_interface == nullptr) {
48 log::warn("GetLppOffloadManager() returned nullptr!");
49 return BT_STATUS_FAIL;
50 }
51 if (!lpp_offload_manager_interface->RegisterSocketHalCallback(&btif_socket_hal_cb)) {
52 log::warn("RegisterSocketHalCallback() failed!");
53 return BT_STATUS_FAIL;
54 }
55 return BT_STATUS_SUCCESS;
56 }
57