blob: 81156405a08a7f76d4a1836b9d54fa48a9f93a3f [file] [log] [blame]
Andre Eisenbach89ba5282016-10-13 15:45:02 -07001//
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"
Myles Watson274a3812017-02-23 06:29:08 -080023#include "hci_packetizer.h"
Andre Eisenbach89ba5282016-10-13 15:45:02 -070024
25namespace android {
26namespace hardware {
27namespace bluetooth {
28namespace V1_0 {
29namespace implementation {
30
31using ::android::hardware::hidl_vec;
Andre Eisenbach9041d972017-01-17 18:23:12 -080032using InitializeCompleteCallback = std::function<void(bool success)>;
Myles Watson6a7d6222016-10-13 15:45:02 -070033using PacketReadCallback =
34 std::function<void(HciPacketType, const hidl_vec<uint8_t> &)>;
Andre Eisenbach89ba5282016-10-13 15:45:02 -070035
Andre Eisenbach9041d972017-01-17 18:23:12 -080036class FirmwareStartupTimer;
37
Andre Eisenbach89ba5282016-10-13 15:45:02 -070038class VendorInterface {
39 public:
Andre Eisenbach9041d972017-01-17 18:23:12 -080040 static bool Initialize(InitializeCompleteCallback initialize_complete_cb,
41 PacketReadCallback packet_read_cb);
Andre Eisenbach89ba5282016-10-13 15:45:02 -070042 static void Shutdown();
Andre Eisenbach9041d972017-01-17 18:23:12 -080043 static VendorInterface *get();
Andre Eisenbach89ba5282016-10-13 15:45:02 -070044
Myles Watsondf765ea2017-01-30 09:07:37 -080045 size_t Send(uint8_t type, const uint8_t *data, size_t length);
Andre Eisenbach89ba5282016-10-13 15:45:02 -070046
47 void OnFirmwareConfigured(uint8_t result);
48
Myles Watson274a3812017-02-23 06:29:08 -080049 static void OnPacketReady();
50
Andre Eisenbach89ba5282016-10-13 15:45:02 -070051 private:
Andre Eisenbach89ba5282016-10-13 15:45:02 -070052 virtual ~VendorInterface() = default;
53
Myles Watsona7d33b32017-01-24 09:09:58 -080054 bool Open(InitializeCompleteCallback initialize_complete_cb,
55 PacketReadCallback packet_read_cb);
Andre Eisenbach89ba5282016-10-13 15:45:02 -070056 void Close();
57
Myles Watsonbeb13b42017-01-26 10:47:27 -080058 void OnTimeout();
59
Myles Watson274a3812017-02-23 06:29:08 -080060 void HandleIncomingPacket();
Andre Eisenbach89ba5282016-10-13 15:45:02 -070061
Andre Eisenbach89ba5282016-10-13 15:45:02 -070062 void *lib_handle_;
63 bt_vendor_interface_t *lib_interface_;
Myles Watsonbe6176d2017-02-21 13:27:01 -080064 async::AsyncFdWatcher fd_watcher_;
Andre Eisenbach89ba5282016-10-13 15:45:02 -070065 int uart_fd_;
66 PacketReadCallback packet_read_cb_;
Andre Eisenbach9041d972017-01-17 18:23:12 -080067 InitializeCompleteCallback initialize_complete_cb_;
Andre Eisenbach89ba5282016-10-13 15:45:02 -070068
Myles Watson274a3812017-02-23 06:29:08 -080069 hci::HciPacketizer hci_packetizer_ {VendorInterface::OnPacketReady};
Andre Eisenbach9041d972017-01-17 18:23:12 -080070
71 FirmwareStartupTimer *firmware_startup_timer_;
Andre Eisenbach89ba5282016-10-13 15:45:02 -070072};
73
Andre Eisenbach9041d972017-01-17 18:23:12 -080074} // namespace implementation
75} // namespace V1_0
76} // namespace bluetooth
77} // namespace hardware
78} // namespace android