• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2021 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 #pragma once
18 
19 #include <android/hardware/bluetooth/1.1/IBluetoothHci.h>
20 
21 #include <android-base/logging.h>
22 #include <hidl/MQDescriptor.h>
23 #include <string>
24 #include "async_fd_watcher.h"
25 #include "model/devices/h4_packetizer.h"
26 
27 namespace android {
28 namespace hardware {
29 namespace bluetooth {
30 namespace V1_1 {
31 namespace remote {
32 
33 class BluetoothDeathRecipient;
34 
35 // This Bluetooth HAL implementation is connected with the root-canal process in
36 // the host side via virtio-console device(refer to dev_path_). It receives and
37 // deliver responses and requests from/to Bluetooth HAL.
38 class BluetoothHci : public IBluetoothHci {
39  public:
40   // virtio-console device connected with root-canal in the host side.
41   BluetoothHci(const std::string& dev_path = "/dev/hvc5");
42 
43   ::android::hardware::Return<void> initialize(
44       const sp<V1_0::IBluetoothHciCallbacks>& cb) override;
45   ::android::hardware::Return<void> initialize_1_1(
46       const sp<V1_1::IBluetoothHciCallbacks>& cb) override;
47 
48   ::android::hardware::Return<void> sendHciCommand(
49       const ::android::hardware::hidl_vec<uint8_t>& packet) override;
50 
51   ::android::hardware::Return<void> sendAclData(
52       const ::android::hardware::hidl_vec<uint8_t>& packet) override;
53 
54   ::android::hardware::Return<void> sendScoData(
55       const ::android::hardware::hidl_vec<uint8_t>& packet) override;
56 
57   ::android::hardware::Return<void> sendIsoData(
58       const ::android::hardware::hidl_vec<uint8_t>& packet) override;
59 
60   ::android::hardware::Return<void> close() override;
61 
62   static void OnPacketReady();
63 
64   static BluetoothHci* get();
65 
66  private:
67   int fd_{-1};
68   ::android::sp<V1_0::IBluetoothHciCallbacks> cb_ = nullptr;
69   ::android::sp<V1_1::IBluetoothHciCallbacks> cb_1_1_ = nullptr;
70 
71   test_vendor_lib::H4Packetizer h4_{fd_,
72                                     [](const std::vector<uint8_t>&) {},
73                                     [](const std::vector<uint8_t>&) {},
74                                     [](const std::vector<uint8_t>&) {},
75                                     [](const std::vector<uint8_t>&) {},
76                                     [](const std::vector<uint8_t>&) {},
77                                     [] {}};
78 
79   ::android::hardware::Return<void> initialize_impl(
80       const sp<V1_0::IBluetoothHciCallbacks>& cb,
81       const sp<V1_1::IBluetoothHciCallbacks>& cb_1_1);
82 
83   sp<BluetoothDeathRecipient> death_recipient_;
84 
85   const std::string dev_path_;
86 
87   std::function<void(sp<BluetoothDeathRecipient>&)> unlink_cb_;
88 
89   ::android::hardware::bluetooth::async::AsyncFdWatcher fd_watcher_;
90 
91   void send(test_vendor_lib::PacketType type,
92             const ::android::hardware::hidl_vec<uint8_t>& packet);
93 };
94 
95 extern "C" IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* name);
96 
97 }  // namespace remote
98 }  // namespace V1_1
99 }  // namespace bluetooth
100 }  // namespace hardware
101 }  // namespace android
102