Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 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" |
Zach Johnson | 917efb1 | 2017-02-26 23:46:05 -0800 | [diff] [blame] | 23 | #include "hci_protocol.h" |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 24 | |
xiaoshun.xu | 1adfae9 | 2022-09-14 20:39:16 +0800 | [diff] [blame^] | 25 | extern std::mutex initcb_mutex_; |
| 26 | |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 27 | namespace android { |
| 28 | namespace hardware { |
| 29 | namespace bluetooth { |
| 30 | namespace V1_0 { |
| 31 | namespace implementation { |
| 32 | |
| 33 | using ::android::hardware::hidl_vec; |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 34 | using InitializeCompleteCallback = std::function<void(bool success)>; |
Zach Johnson | 917efb1 | 2017-02-26 23:46:05 -0800 | [diff] [blame] | 35 | using PacketReadCallback = std::function<void(const hidl_vec<uint8_t>&)>; |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 36 | |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 37 | class FirmwareStartupTimer; |
| 38 | |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 39 | class VendorInterface { |
| 40 | public: |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 41 | static bool Initialize(InitializeCompleteCallback initialize_complete_cb, |
Zach Johnson | 917efb1 | 2017-02-26 23:46:05 -0800 | [diff] [blame] | 42 | PacketReadCallback event_cb, PacketReadCallback acl_cb, |
Jakub Pawlowski | 13b4d31 | 2019-11-05 12:27:29 +0100 | [diff] [blame] | 43 | PacketReadCallback sco_cb, PacketReadCallback iso_cb); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 44 | static void Shutdown(); |
Jack He | caeab05 | 2018-10-23 18:13:51 -0700 | [diff] [blame] | 45 | static VendorInterface* get(); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 46 | |
Jack He | caeab05 | 2018-10-23 18:13:51 -0700 | [diff] [blame] | 47 | size_t Send(uint8_t type, const uint8_t* data, size_t length); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 48 | |
| 49 | void OnFirmwareConfigured(uint8_t result); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 50 | virtual ~VendorInterface() = default; |
| 51 | |
xiaoshun.xu | 1adfae9 | 2022-09-14 20:39:16 +0800 | [diff] [blame^] | 52 | private: |
Myles Watson | a7d33b3 | 2017-01-24 09:09:58 -0800 | [diff] [blame] | 53 | bool Open(InitializeCompleteCallback initialize_complete_cb, |
Zach Johnson | 917efb1 | 2017-02-26 23:46:05 -0800 | [diff] [blame] | 54 | PacketReadCallback event_cb, PacketReadCallback acl_cb, |
Jakub Pawlowski | 13b4d31 | 2019-11-05 12:27:29 +0100 | [diff] [blame] | 55 | PacketReadCallback sco_cb, PacketReadCallback iso_cb); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 56 | void Close(); |
| 57 | |
Myles Watson | beb13b4 | 2017-01-26 10:47:27 -0800 | [diff] [blame] | 58 | void OnTimeout(); |
| 59 | |
Zach Johnson | 917efb1 | 2017-02-26 23:46:05 -0800 | [diff] [blame] | 60 | void HandleIncomingEvent(const hidl_vec<uint8_t>& hci_packet); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 61 | |
Joseph Pirozzo | c1e10a3 | 2018-11-13 08:18:43 -0800 | [diff] [blame] | 62 | void* lib_handle_ = nullptr; |
| 63 | bt_vendor_interface_t* lib_interface_ = nullptr; |
Myles Watson | be6176d | 2017-02-21 13:27:01 -0800 | [diff] [blame] | 64 | async::AsyncFdWatcher fd_watcher_; |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 65 | InitializeCompleteCallback initialize_complete_cb_; |
Joseph Pirozzo | c1e10a3 | 2018-11-13 08:18:43 -0800 | [diff] [blame] | 66 | hci::HciProtocol* hci_ = nullptr; |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 67 | |
Zach Johnson | 917efb1 | 2017-02-26 23:46:05 -0800 | [diff] [blame] | 68 | PacketReadCallback event_cb_; |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 69 | |
Joseph Pirozzo | c1e10a3 | 2018-11-13 08:18:43 -0800 | [diff] [blame] | 70 | FirmwareStartupTimer* firmware_startup_timer_ = nullptr; |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 73 | } // namespace implementation |
| 74 | } // namespace V1_0 |
| 75 | } // namespace bluetooth |
| 76 | } // namespace hardware |
| 77 | } // namespace android |