blob: 2df39462b59db13d36f60aed73aec43829d1bd18 [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
xiaoshun.xu1adfae92022-09-14 20:39:16 +080025extern std::mutex initcb_mutex_;
26
Andre Eisenbach89ba5282016-10-13 15:45:02 -070027namespace android {
28namespace hardware {
29namespace bluetooth {
30namespace V1_0 {
31namespace implementation {
32
33using ::android::hardware::hidl_vec;
Andre Eisenbach9041d972017-01-17 18:23:12 -080034using InitializeCompleteCallback = std::function<void(bool success)>;
Zach Johnson917efb12017-02-26 23:46:05 -080035using PacketReadCallback = std::function<void(const hidl_vec<uint8_t>&)>;
Andre Eisenbach89ba5282016-10-13 15:45:02 -070036
Andre Eisenbach9041d972017-01-17 18:23:12 -080037class FirmwareStartupTimer;
38
Andre Eisenbach89ba5282016-10-13 15:45:02 -070039class VendorInterface {
40 public:
Andre Eisenbach9041d972017-01-17 18:23:12 -080041 static bool Initialize(InitializeCompleteCallback initialize_complete_cb,
Zach Johnson917efb12017-02-26 23:46:05 -080042 PacketReadCallback event_cb, PacketReadCallback acl_cb,
Jakub Pawlowski13b4d312019-11-05 12:27:29 +010043 PacketReadCallback sco_cb, PacketReadCallback iso_cb);
Andre Eisenbach89ba5282016-10-13 15:45:02 -070044 static void Shutdown();
Jack Hecaeab052018-10-23 18:13:51 -070045 static VendorInterface* get();
Andre Eisenbach89ba5282016-10-13 15:45:02 -070046
Jack Hecaeab052018-10-23 18:13:51 -070047 size_t Send(uint8_t type, const uint8_t* data, size_t length);
Andre Eisenbach89ba5282016-10-13 15:45:02 -070048
49 void OnFirmwareConfigured(uint8_t result);
Andre Eisenbach89ba5282016-10-13 15:45:02 -070050 virtual ~VendorInterface() = default;
51
xiaoshun.xu1adfae92022-09-14 20:39:16 +080052 private:
Myles Watsona7d33b32017-01-24 09:09:58 -080053 bool Open(InitializeCompleteCallback initialize_complete_cb,
Zach Johnson917efb12017-02-26 23:46:05 -080054 PacketReadCallback event_cb, PacketReadCallback acl_cb,
Jakub Pawlowski13b4d312019-11-05 12:27:29 +010055 PacketReadCallback sco_cb, PacketReadCallback iso_cb);
Andre Eisenbach89ba5282016-10-13 15:45:02 -070056 void Close();
57
Myles Watsonbeb13b42017-01-26 10:47:27 -080058 void OnTimeout();
59
Zach Johnson917efb12017-02-26 23:46:05 -080060 void HandleIncomingEvent(const hidl_vec<uint8_t>& hci_packet);
Andre Eisenbach89ba5282016-10-13 15:45:02 -070061
Joseph Pirozzoc1e10a32018-11-13 08:18:43 -080062 void* lib_handle_ = nullptr;
63 bt_vendor_interface_t* lib_interface_ = nullptr;
Myles Watsonbe6176d2017-02-21 13:27:01 -080064 async::AsyncFdWatcher fd_watcher_;
Andre Eisenbach9041d972017-01-17 18:23:12 -080065 InitializeCompleteCallback initialize_complete_cb_;
Joseph Pirozzoc1e10a32018-11-13 08:18:43 -080066 hci::HciProtocol* hci_ = nullptr;
Andre Eisenbach89ba5282016-10-13 15:45:02 -070067
Zach Johnson917efb12017-02-26 23:46:05 -080068 PacketReadCallback event_cb_;
Andre Eisenbach9041d972017-01-17 18:23:12 -080069
Joseph Pirozzoc1e10a32018-11-13 08:18:43 -080070 FirmwareStartupTimer* firmware_startup_timer_ = nullptr;
Andre Eisenbach89ba5282016-10-13 15:45:02 -070071};
72
Andre Eisenbach9041d972017-01-17 18:23:12 -080073} // namespace implementation
74} // namespace V1_0
75} // namespace bluetooth
76} // namespace hardware
77} // namespace android