blob: 99eda9f8f4d6c972ceb03fb1481d723e2b365811 [file] [log] [blame]
Myles Watson73ad0312017-03-07 04:28:51 -08001//
2// Copyright 2017 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
Myles Watson1a0a0da2019-10-17 11:36:33 -070019#include "os/log.h"
20
Jakub Pawlowskide6c0132019-11-12 16:14:32 +010021#include <android/hardware/bluetooth/1.1/IBluetoothHci.h>
Myles Watson73ad0312017-03-07 04:28:51 -080022
23#include <hidl/MQDescriptor.h>
24
25#include "hci_packetizer.h"
26
Myles Watsone22dde22019-01-18 11:42:33 -080027#include "model/controller/dual_mode_controller.h"
28#include "model/setup/async_manager.h"
29#include "model/setup/test_channel_transport.h"
30#include "model/setup/test_command_handler.h"
31#include "model/setup/test_model.h"
Myles Watson73ad0312017-03-07 04:28:51 -080032
33namespace android {
34namespace hardware {
35namespace bluetooth {
Jakub Pawlowskide6c0132019-11-12 16:14:32 +010036namespace V1_1 {
Myles Watson73ad0312017-03-07 04:28:51 -080037namespace sim {
38
39class BluetoothDeathRecipient;
40
41class BluetoothHci : public IBluetoothHci {
42 public:
43 BluetoothHci();
44
Jakub Pawlowskide6c0132019-11-12 16:14:32 +010045 ::android::hardware::Return<void> initialize(
46 const sp<V1_0::IBluetoothHciCallbacks>& cb) override;
47 ::android::hardware::Return<void> initialize_1_1(
48 const sp<V1_1::IBluetoothHciCallbacks>& cb) override;
Myles Watson73ad0312017-03-07 04:28:51 -080049
Myles Watsone22dde22019-01-18 11:42:33 -080050 ::android::hardware::Return<void> sendHciCommand(const ::android::hardware::hidl_vec<uint8_t>& packet) override;
Myles Watson73ad0312017-03-07 04:28:51 -080051
Myles Watsone22dde22019-01-18 11:42:33 -080052 ::android::hardware::Return<void> sendAclData(const ::android::hardware::hidl_vec<uint8_t>& packet) override;
Myles Watson73ad0312017-03-07 04:28:51 -080053
Myles Watsone22dde22019-01-18 11:42:33 -080054 ::android::hardware::Return<void> sendScoData(const ::android::hardware::hidl_vec<uint8_t>& packet) override;
Myles Watson73ad0312017-03-07 04:28:51 -080055
Jakub Pawlowskide6c0132019-11-12 16:14:32 +010056 ::android::hardware::Return<void> sendIsoData(
57 const ::android::hardware::hidl_vec<uint8_t>& packet) override;
58
Myles Watson73ad0312017-03-07 04:28:51 -080059 ::android::hardware::Return<void> close() override;
60
61 static void OnPacketReady();
62
63 static BluetoothHci* get();
64
65 private:
Jakub Pawlowskide6c0132019-11-12 16:14:32 +010066 ::android::hardware::Return<void> initialize_impl(
67 const sp<V1_0::IBluetoothHciCallbacks>& cb,
68 const sp<V1_1::IBluetoothHciCallbacks>& cb_1_1);
69
Myles Watson73ad0312017-03-07 04:28:51 -080070 sp<BluetoothDeathRecipient> death_recipient_;
71
72 std::function<void(sp<BluetoothDeathRecipient>&)> unlink_cb_;
73
74 void HandleIncomingPacket();
75
76 test_vendor_lib::AsyncManager async_manager_;
77
78 void SetUpTestChannel(int port);
Myles Watsone22dde22019-01-18 11:42:33 -080079 void SetUpHciServer(int port, const std::function<void(int)>& on_connect);
80 void SetUpLinkLayerServer(int port, const std::function<void(int)>& on_connect);
81 int ConnectToRemoteServer(const std::string& server, int port);
Myles Watson73ad0312017-03-07 04:28:51 -080082
Myles Watsone22dde22019-01-18 11:42:33 -080083 std::shared_ptr<test_vendor_lib::DualModeController> controller_;
Myles Watson73ad0312017-03-07 04:28:51 -080084
85 test_vendor_lib::TestChannelTransport test_channel_transport_;
Myles Watsone22dde22019-01-18 11:42:33 -080086 test_vendor_lib::TestChannelTransport remote_hci_transport_;
87 test_vendor_lib::TestChannelTransport remote_link_layer_transport_;
88
89 test_vendor_lib::TestModel test_model_{
90 [this](std::chrono::milliseconds delay, const test_vendor_lib::TaskCallback& task) {
91 return async_manager_.ExecAsync(delay, task);
92 },
93
94 [this](std::chrono::milliseconds delay, std::chrono::milliseconds period,
95 const test_vendor_lib::TaskCallback& task) {
96 return async_manager_.ExecAsyncPeriodically(delay, period, task);
97 },
98
99 [this](test_vendor_lib::AsyncTaskId task) { async_manager_.CancelAsyncTask(task); },
100
101 [this](const std::string& server, int port) { return ConnectToRemoteServer(server, port); }};
102
103 test_vendor_lib::TestCommandHandler test_channel_{test_model_};
Myles Watson73ad0312017-03-07 04:28:51 -0800104};
105
Myles Watson28eff182017-05-17 11:39:18 -0700106extern "C" IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* name);
107
Myles Watson73ad0312017-03-07 04:28:51 -0800108} // namespace sim
Jakub Pawlowskide6c0132019-11-12 16:14:32 +0100109} // namespace V1_1
Myles Watson73ad0312017-03-07 04:28:51 -0800110} // namespace bluetooth
111} // namespace hardware
112} // namespace android