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