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 19 #include <android/hardware/bluetooth/1.0/IBluetoothHci.h> 20 21 #include <hidl/MQDescriptor.h> 22 23 #include "hci_packetizer.h" 24 25 #include "model/controller/dual_mode_controller.h" 26 #include "model/setup/async_manager.h" 27 #include "model/setup/test_channel_transport.h" 28 #include "model/setup/test_command_handler.h" 29 #include "model/setup/test_model.h" 30 31 namespace android { 32 namespace hardware { 33 namespace bluetooth { 34 namespace V1_0 { 35 namespace sim { 36 37 class BluetoothDeathRecipient; 38 39 class BluetoothHci : public IBluetoothHci { 40 public: 41 BluetoothHci(); 42 43 ::android::hardware::Return<void> initialize(const sp<IBluetoothHciCallbacks>& cb) override; 44 45 ::android::hardware::Return<void> sendHciCommand(const ::android::hardware::hidl_vec<uint8_t>& packet) override; 46 47 ::android::hardware::Return<void> sendAclData(const ::android::hardware::hidl_vec<uint8_t>& packet) override; 48 49 ::android::hardware::Return<void> sendScoData(const ::android::hardware::hidl_vec<uint8_t>& packet) override; 50 51 ::android::hardware::Return<void> close() override; 52 53 static void OnPacketReady(); 54 55 static BluetoothHci* get(); 56 57 private: 58 sp<BluetoothDeathRecipient> death_recipient_; 59 60 std::function<void(sp<BluetoothDeathRecipient>&)> unlink_cb_; 61 62 void HandleIncomingPacket(); 63 64 test_vendor_lib::AsyncManager async_manager_; 65 66 void SetUpTestChannel(int port); 67 void SetUpHciServer(int port, const std::function<void(int)>& on_connect); 68 void SetUpLinkLayerServer(int port, const std::function<void(int)>& on_connect); 69 int ConnectToRemoteServer(const std::string& server, int port); 70 71 std::shared_ptr<test_vendor_lib::DualModeController> controller_; 72 73 test_vendor_lib::TestChannelTransport test_channel_transport_; 74 test_vendor_lib::TestChannelTransport remote_hci_transport_; 75 test_vendor_lib::TestChannelTransport remote_link_layer_transport_; 76 77 test_vendor_lib::TestModel test_model_{ 78 [this](std::chrono::milliseconds delay, const test_vendor_lib::TaskCallback& task) { 79 return async_manager_.ExecAsync(delay, task); 80 }, 81 82 [this](std::chrono::milliseconds delay, std::chrono::milliseconds period, 83 const test_vendor_lib::TaskCallback& task) { 84 return async_manager_.ExecAsyncPeriodically(delay, period, task); 85 }, 86 87 [this](test_vendor_lib::AsyncTaskId task) { async_manager_.CancelAsyncTask(task); }, 88 89 [this](const std::string& server, int port) { return ConnectToRemoteServer(server, port); }}; 90 91 test_vendor_lib::TestCommandHandler test_channel_{test_model_}; 92 }; 93 94 extern "C" IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* name); 95 96 } // namespace sim 97 } // namespace V1_0 98 } // namespace bluetooth 99 } // namespace hardware 100 } // namespace android 101