blob: 0ed0623e47140b766d158d153e18e0ef2a75f8a8 [file] [log] [blame]
Myles Watson6d5e7722022-09-30 06:22:43 -07001/*
2 * Copyright 2022 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 <aidl/android/hardware/bluetooth/BnBluetoothHci.h>
20#include <aidl/android/hardware/bluetooth/IBluetoothHciCallbacks.h>
21#include <log/log.h>
22
23#include <string>
24
25#include "async_fd_watcher.h"
26#include "h4_protocol.h"
27
28namespace aidl::android::hardware::bluetooth::impl {
29
30class BluetoothDeathRecipient;
31
32// This Bluetooth HAL implementation connects with a serial port at dev_path_.
33class BluetoothHci : public BnBluetoothHci {
34 public:
35 BluetoothHci(const std::string& dev_path = "/dev/hvc5");
36
37 ndk::ScopedAStatus initialize(
38 const std::shared_ptr<IBluetoothHciCallbacks>& cb) override;
39
40 ndk::ScopedAStatus sendHciCommand(
41 const std::vector<uint8_t>& packet) override;
42
43 ndk::ScopedAStatus sendAclData(const std::vector<uint8_t>& packet) override;
44
45 ndk::ScopedAStatus sendScoData(const std::vector<uint8_t>& packet) override;
46
47 ndk::ScopedAStatus sendIsoData(const std::vector<uint8_t>& packet) override;
48
49 ndk::ScopedAStatus close() override;
50
51 static void OnPacketReady();
52
53 static BluetoothHci* get();
54
55 private:
56 int mFd{-1};
57 std::shared_ptr<IBluetoothHciCallbacks> mCb = nullptr;
58
59 std::shared_ptr<::android::hardware::bluetooth::hci::H4Protocol> mH4;
60
61 std::shared_ptr<BluetoothDeathRecipient> mDeathRecipient;
62
63 std::string mDevPath;
64
65 ::android::hardware::bluetooth::async::AsyncFdWatcher mFdWatcher;
66
67 void send(::android::hardware::bluetooth::hci::PacketType type,
68 const std::vector<uint8_t>& packet);
69};
70
71} // namespace aidl::android::hardware::bluetooth::impl