Myles Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 1 | // |
| 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 Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 19 | #include "os/log.h" |
| 20 | |
Jakub Pawlowski | de6c013 | 2019-11-12 16:14:32 +0100 | [diff] [blame] | 21 | #include <android/hardware/bluetooth/1.1/IBluetoothHci.h> |
Myles Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 22 | |
| 23 | #include <hidl/MQDescriptor.h> |
| 24 | |
| 25 | #include "hci_packetizer.h" |
| 26 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 27 | #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 Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 32 | |
| 33 | namespace android { |
| 34 | namespace hardware { |
| 35 | namespace bluetooth { |
Jakub Pawlowski | de6c013 | 2019-11-12 16:14:32 +0100 | [diff] [blame] | 36 | namespace V1_1 { |
Myles Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 37 | namespace sim { |
| 38 | |
| 39 | class BluetoothDeathRecipient; |
| 40 | |
| 41 | class BluetoothHci : public IBluetoothHci { |
| 42 | public: |
| 43 | BluetoothHci(); |
| 44 | |
Jakub Pawlowski | de6c013 | 2019-11-12 16:14:32 +0100 | [diff] [blame] | 45 | ::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 Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 49 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 50 | ::android::hardware::Return<void> sendHciCommand(const ::android::hardware::hidl_vec<uint8_t>& packet) override; |
Myles Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 51 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 52 | ::android::hardware::Return<void> sendAclData(const ::android::hardware::hidl_vec<uint8_t>& packet) override; |
Myles Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 53 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 54 | ::android::hardware::Return<void> sendScoData(const ::android::hardware::hidl_vec<uint8_t>& packet) override; |
Myles Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 55 | |
Jakub Pawlowski | de6c013 | 2019-11-12 16:14:32 +0100 | [diff] [blame] | 56 | ::android::hardware::Return<void> sendIsoData( |
| 57 | const ::android::hardware::hidl_vec<uint8_t>& packet) override; |
| 58 | |
Myles Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 59 | ::android::hardware::Return<void> close() override; |
| 60 | |
| 61 | static void OnPacketReady(); |
| 62 | |
| 63 | static BluetoothHci* get(); |
| 64 | |
| 65 | private: |
Jakub Pawlowski | de6c013 | 2019-11-12 16:14:32 +0100 | [diff] [blame] | 66 | ::android::hardware::Return<void> initialize_impl( |
| 67 | const sp<V1_0::IBluetoothHciCallbacks>& cb, |
| 68 | const sp<V1_1::IBluetoothHciCallbacks>& cb_1_1); |
| 69 | |
Myles Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 70 | 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 Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 79 | 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 Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 82 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 83 | std::shared_ptr<test_vendor_lib::DualModeController> controller_; |
Myles Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 84 | |
| 85 | test_vendor_lib::TestChannelTransport test_channel_transport_; |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 86 | 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 Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 104 | }; |
| 105 | |
Myles Watson | 28eff18 | 2017-05-17 11:39:18 -0700 | [diff] [blame] | 106 | extern "C" IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* name); |
| 107 | |
Myles Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 108 | } // namespace sim |
Jakub Pawlowski | de6c013 | 2019-11-12 16:14:32 +0100 | [diff] [blame] | 109 | } // namespace V1_1 |
Myles Watson | 73ad031 | 2017-03-07 04:28:51 -0800 | [diff] [blame] | 110 | } // namespace bluetooth |
| 111 | } // namespace hardware |
| 112 | } // namespace android |