// // Copyright 2021 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #pragma once #include #include #include #include #include "async_fd_watcher.h" #include "model/hci/h4_packetizer.h" namespace android { namespace hardware { namespace bluetooth { namespace V1_1 { namespace remote { class BluetoothDeathRecipient; // This Bluetooth HAL implementation is connected with the root-canal process in // the host side via virtio-console device(refer to dev_path_). It receives and // deliver responses and requests from/to Bluetooth HAL. class BluetoothHci : public IBluetoothHci { public: // virtio-console device connected with root-canal in the host side. BluetoothHci(const std::string& dev_path = "/dev/hvc5"); ::android::hardware::Return initialize( const sp& cb) override; ::android::hardware::Return initialize_1_1( const sp& cb) override; ::android::hardware::Return sendHciCommand( const ::android::hardware::hidl_vec& packet) override; ::android::hardware::Return sendAclData( const ::android::hardware::hidl_vec& packet) override; ::android::hardware::Return sendScoData( const ::android::hardware::hidl_vec& packet) override; ::android::hardware::Return sendIsoData( const ::android::hardware::hidl_vec& packet) override; ::android::hardware::Return close() override; static void OnPacketReady(); static BluetoothHci* get(); private: int fd_{-1}; ::android::sp cb_ = nullptr; ::android::sp cb_1_1_ = nullptr; rootcanal::H4Packetizer h4_{fd_, [](const std::vector&) {}, [](const std::vector&) {}, [](const std::vector&) {}, [](const std::vector&) {}, [](const std::vector&) {}, [] {}}; ::android::hardware::Return initialize_impl( const sp& cb, const sp& cb_1_1); sp death_recipient_; const std::string dev_path_; std::function&)> unlink_cb_; ::android::hardware::bluetooth::async::AsyncFdWatcher fd_watcher_; void send(rootcanal::PacketType type, const ::android::hardware::hidl_vec& packet); }; extern "C" IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* name); } // namespace remote } // namespace V1_1 } // namespace bluetooth } // namespace hardware } // namespace android