1 // 2 // Copyright 2016 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 <hidl/HidlSupport.h> 20 21 #include "async_fd_watcher.h" 22 #include "bt_vendor_lib.h" 23 #include "hci_protocol.h" 24 25 extern std::mutex initcb_mutex_; 26 27 namespace android { 28 namespace hardware { 29 namespace bluetooth { 30 namespace V1_0 { 31 namespace implementation { 32 33 using ::android::hardware::hidl_vec; 34 using InitializeCompleteCallback = std::function<void(bool success)>; 35 using PacketReadCallback = std::function<void(const hidl_vec<uint8_t>&)>; 36 37 class FirmwareStartupTimer; 38 39 class VendorInterface { 40 public: 41 static bool Initialize(InitializeCompleteCallback initialize_complete_cb, 42 PacketReadCallback event_cb, PacketReadCallback acl_cb, 43 PacketReadCallback sco_cb, PacketReadCallback iso_cb); 44 static void Shutdown(); 45 static VendorInterface* get(); 46 47 size_t Send(uint8_t type, const uint8_t* data, size_t length); 48 49 void OnFirmwareConfigured(uint8_t result); 50 virtual ~VendorInterface() = default; 51 52 private: 53 bool Open(InitializeCompleteCallback initialize_complete_cb, 54 PacketReadCallback event_cb, PacketReadCallback acl_cb, 55 PacketReadCallback sco_cb, PacketReadCallback iso_cb); 56 void Close(); 57 58 void OnTimeout(); 59 60 void HandleIncomingEvent(const hidl_vec<uint8_t>& hci_packet); 61 62 void* lib_handle_ = nullptr; 63 bt_vendor_interface_t* lib_interface_ = nullptr; 64 async::AsyncFdWatcher fd_watcher_; 65 InitializeCompleteCallback initialize_complete_cb_; 66 hci::HciProtocol* hci_ = nullptr; 67 68 PacketReadCallback event_cb_; 69 70 FirmwareStartupTimer* firmware_startup_timer_ = nullptr; 71 }; 72 73 } // namespace implementation 74 } // namespace V1_0 75 } // namespace bluetooth 76 } // namespace hardware 77 } // namespace android 78