blob: 1d69040d90860798c934ec2d11f8dbcf993d159f [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"
Zach Johnson917efb12017-02-26 23:46:05 -080023#include "hci_protocol.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)>;
Zach Johnson917efb12017-02-26 23:46:05 -080033using PacketReadCallback = std::function<void(const hidl_vec<uint8_t>&)>;
Andre Eisenbach89ba5282016-10-13 15:45:02 -070034
Andre Eisenbach9041d972017-01-17 18:23:12 -080035class FirmwareStartupTimer;
36
Andre Eisenbach89ba5282016-10-13 15:45:02 -070037class VendorInterface {
38 public:
Andre Eisenbach9041d972017-01-17 18:23:12 -080039 static bool Initialize(InitializeCompleteCallback initialize_complete_cb,
Zach Johnson917efb12017-02-26 23:46:05 -080040 PacketReadCallback event_cb, PacketReadCallback acl_cb,
41 PacketReadCallback sco_cb);
Andre Eisenbach89ba5282016-10-13 15:45:02 -070042 static void Shutdown();
Jack Hecaeab052018-10-23 18:13:51 -070043 static VendorInterface* get();
Andre Eisenbach89ba5282016-10-13 15:45:02 -070044
Jack Hecaeab052018-10-23 18:13:51 -070045 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
Andre Eisenbach89ba5282016-10-13 15:45:02 -070049 private:
Andre Eisenbach89ba5282016-10-13 15:45:02 -070050 virtual ~VendorInterface() = default;
51
Myles Watsona7d33b32017-01-24 09:09:58 -080052 bool Open(InitializeCompleteCallback initialize_complete_cb,
Zach Johnson917efb12017-02-26 23:46:05 -080053 PacketReadCallback event_cb, PacketReadCallback acl_cb,
54 PacketReadCallback sco_cb);
Andre Eisenbach89ba5282016-10-13 15:45:02 -070055 void Close();
56
Myles Watsonbeb13b42017-01-26 10:47:27 -080057 void OnTimeout();
58
Zach Johnson917efb12017-02-26 23:46:05 -080059 void HandleIncomingEvent(const hidl_vec<uint8_t>& hci_packet);
Andre Eisenbach89ba5282016-10-13 15:45:02 -070060
Joseph Pirozzoc1e10a32018-11-13 08:18:43 -080061 void* lib_handle_ = nullptr;
62 bt_vendor_interface_t* lib_interface_ = nullptr;
Myles Watsonbe6176d2017-02-21 13:27:01 -080063 async::AsyncFdWatcher fd_watcher_;
Andre Eisenbach9041d972017-01-17 18:23:12 -080064 InitializeCompleteCallback initialize_complete_cb_;
Joseph Pirozzoc1e10a32018-11-13 08:18:43 -080065 hci::HciProtocol* hci_ = nullptr;
Andre Eisenbach89ba5282016-10-13 15:45:02 -070066
Zach Johnson917efb12017-02-26 23:46:05 -080067 PacketReadCallback event_cb_;
Andre Eisenbach9041d972017-01-17 18:23:12 -080068
Joseph Pirozzoc1e10a32018-11-13 08:18:43 -080069 FirmwareStartupTimer* firmware_startup_timer_ = nullptr;
Andre Eisenbach89ba5282016-10-13 15:45:02 -070070};
71
Andre Eisenbach9041d972017-01-17 18:23:12 -080072} // namespace implementation
73} // namespace V1_0
74} // namespace bluetooth
75} // namespace hardware
76} // namespace android