From 18c8bb01235ed88875247cd92e22fffc8c724494 Mon Sep 17 00:00:00 2001 From: David Duarte <licorne@google.com> Date: Mon, 7 Mar 2022 10:08:48 +0000 Subject: [PATCH] RootCanal: Move into tools/ Rename the namespace from test_vendor_lib to rootcanal Test: None Change-Id: I9cf72eef6c6100888faa0e6344ebd4c5b7ec716e --- system/test/gen_coverage.py | 8 +- system/test/rootcanal/bluetooth_hci.cc | 11 +- system/test/rootcanal/bluetooth_hci.h | 31 ++- system/vendor_libs/Android.bp | 1 - .../test_vendor_lib/model/devices/keyboard.cc | 89 ------- .../rootcanal}/Android.bp | 8 +- .../rootcanal}/data/Android.bp | 0 .../data/controller_properties.json | 0 .../rootcanal}/desktop/root_canal_main.cc | 5 +- .../rootcanal}/desktop/test_environment.cc | 4 +- .../rootcanal}/desktop/test_environment.h | 34 ++- .../rootcanal}/include/phy.h | 4 +- .../model/controller/acl_connection.cc | 4 +- .../model/controller/acl_connection.h | 4 +- .../controller/acl_connection_handler.cc | 44 ++-- .../model/controller/acl_connection_handler.h | 11 +- .../controller/connected_isochronous_group.h | 4 +- .../controller/connected_isochronous_stream.h | 4 +- .../model/controller/dual_mode_controller.cc | 140 +++++----- .../model/controller/dual_mode_controller.h | 26 +- .../isochronous_connection_handler.cc | 7 +- .../isochronous_connection_handler.h | 4 +- .../model/controller/le_advertiser.cc | 61 ++--- .../model/controller/le_advertiser.h | 8 +- .../model/controller/link_layer_controller.cc | 240 +++++++----------- .../model/controller/link_layer_controller.h | 63 ++--- .../model/controller/sco_connection.cc | 124 +++++---- .../model/controller/sco_connection.h | 23 +- .../model/controller/security_manager.cc | 70 ++--- .../model/controller/security_manager.h | 10 +- .../rootcanal}/model/devices/beacon.cc | 26 +- .../rootcanal}/model/devices/beacon.h | 8 +- .../rootcanal}/model/devices/beacon_swarm.cc | 10 +- .../rootcanal}/model/devices/beacon_swarm.h | 8 +- .../rootcanal}/model/devices/broken_adv.cc | 20 +- .../rootcanal}/model/devices/broken_adv.h | 8 +- .../rootcanal}/model/devices/car_kit.cc | 11 +- .../rootcanal}/model/devices/car_kit.h | 12 +- .../rootcanal}/model/devices/classic.cc | 11 +- .../rootcanal}/model/devices/classic.h | 8 +- .../rootcanal}/model/devices/device.cc | 15 +- .../rootcanal}/model/devices/device.h | 13 +- .../model/devices/device_properties.cc | 5 +- .../model/devices/device_properties.h | 124 +++------ .../devices/h4_data_channel_packetizer.cc | 9 +- .../devices/h4_data_channel_packetizer.h | 4 +- .../rootcanal}/model/devices/h4_packetizer.cc | 11 +- .../rootcanal}/model/devices/h4_packetizer.h | 4 +- .../rootcanal}/model/devices/h4_parser.cc | 7 +- .../rootcanal}/model/devices/h4_parser.h | 14 +- .../rootcanal}/model/devices/hci_protocol.cc | 4 +- .../rootcanal}/model/devices/hci_protocol.h | 4 +- .../model/devices/hci_socket_device.cc | 7 +- .../model/devices/hci_socket_device.h | 8 +- tools/rootcanal/model/devices/keyboard.cc | 89 +++++++ .../rootcanal}/model/devices/keyboard.h | 7 +- .../model/devices/link_layer_socket_device.cc | 15 +- .../model/devices/link_layer_socket_device.h | 4 +- .../rootcanal}/model/devices/loopback.cc | 17 +- .../rootcanal}/model/devices/loopback.h | 4 +- .../model/devices/remote_loopback_device.cc | 7 +- .../model/devices/remote_loopback_device.h | 4 +- .../model/devices/scripted_beacon.cc | 15 +- .../model/devices/scripted_beacon.h | 21 +- .../devices/scripted_beacon_ble_payload.proto | 2 +- .../rootcanal}/model/devices/sniffer.cc | 7 +- .../rootcanal}/model/devices/sniffer.h | 8 +- .../rootcanal}/model/setup/async_manager.cc | 44 ++-- .../rootcanal}/model/setup/async_manager.h | 18 +- .../rootcanal}/model/setup/device_boutique.cc | 19 +- .../rootcanal}/model/setup/device_boutique.h | 11 +- .../rootcanal}/model/setup/phy_layer.h | 13 +- .../model/setup/phy_layer_factory.cc | 20 +- .../model/setup/phy_layer_factory.h | 5 +- .../model/setup/test_channel_transport.cc | 4 +- .../model/setup/test_channel_transport.h | 4 +- .../model/setup/test_command_handler.cc | 61 +++-- .../model/setup/test_command_handler.h | 15 +- .../rootcanal}/model/setup/test_model.cc | 7 +- .../rootcanal}/model/setup/test_model.h | 9 +- .../rootcanal}/net/async_data_channel.h | 0 .../net/async_data_channel_connector.h | 0 .../net/async_data_channel_server.h | 0 .../net/posix/posix_async_socket.cc | 0 .../rootcanal}/net/posix/posix_async_socket.h | 6 +- .../net/posix/posix_async_socket_connector.cc | 3 +- .../net/posix/posix_async_socket_connector.h | 6 +- .../net/posix/posix_async_socket_server.cc | 5 +- .../net/posix/posix_async_socket_server.h | 6 +- .../rootcanal}/packets/link_layer_packets.pdl | 0 .../rootcanal}/scripts/build_and_run.sh | 0 .../rootcanal}/scripts/hci_socket.py | 0 .../rootcanal}/scripts/link_layer_socket.py | 0 .../scripts/scripted_beacon_test/Readme.txt | 0 .../scripts/scripted_beacon_test/add_beacons | 0 .../scripted_beacon_test/grant_permission.pb | 0 .../scripted_beacon_test/no_permission.pb | 0 .../scripts/scripted_beacon_test/run_test.sh | 0 .../scripts/scripted_beacon_test/start_scan | 0 .../scripted_beacon_test/test_events.pb | 0 .../scripts/send_simple_commands.py | 0 .../scripts/simple_link_layer_socket.py | 0 .../rootcanal}/scripts/simple_stack.py | 0 .../rootcanal}/scripts/test_channel.py | 0 .../rootcanal}/test/async_manager_unittest.cc | 4 +- .../rootcanal}/test/h4_parser_unittest.cc | 4 +- .../rootcanal}/test/posix_socket_unittest.cc | 0 .../test/security_manager_unittest.cc | 5 +- 108 files changed, 917 insertions(+), 945 deletions(-) delete mode 100644 system/vendor_libs/test_vendor_lib/model/devices/keyboard.cc rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/Android.bp (96%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/data/Android.bp (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/data/controller_properties.json (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/desktop/root_canal_main.cc (99%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/desktop/test_environment.cc (98%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/desktop/test_environment.h (79%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/include/phy.h (92%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/acl_connection.cc (95%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/acl_connection.h (95%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/acl_connection_handler.cc (92%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/acl_connection_handler.h (94%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/connected_isochronous_group.h (97%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/connected_isochronous_stream.h (95%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/dual_mode_controller.cc (96%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/dual_mode_controller.h (95%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/isochronous_connection_handler.cc (98%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/isochronous_connection_handler.h (96%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/le_advertiser.cc (85%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/le_advertiser.h (96%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/link_layer_controller.cc (96%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/link_layer_controller.h (93%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/sco_connection.cc (74%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/sco_connection.h (85%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/security_manager.cc (77%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/controller/security_manager.h (95%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/beacon.cc (81%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/beacon.h (90%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/beacon_swarm.cc (90%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/beacon_swarm.h (89%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/broken_adv.cc (88%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/broken_adv.h (91%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/car_kit.cc (92%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/car_kit.h (84%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/classic.cc (87%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/classic.h (88%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/device.cc (91%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/device.h (93%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/device_properties.cc (98%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/device_properties.h (84%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/h4_data_channel_packetizer.cc (95%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/h4_data_channel_packetizer.h (96%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/h4_packetizer.cc (94%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/h4_packetizer.h (95%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/h4_parser.cc (98%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/h4_parser.h (92%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/hci_protocol.cc (95%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/hci_protocol.h (95%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/hci_socket_device.cc (97%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/hci_socket_device.h (94%) create mode 100644 tools/rootcanal/model/devices/keyboard.cc rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/keyboard.h (95%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/link_layer_socket_device.cc (94%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/link_layer_socket_device.h (97%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/loopback.cc (85%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/loopback.h (96%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/remote_loopback_device.cc (91%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/remote_loopback_device.h (95%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/scripted_beacon.cc (96%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/scripted_beacon.h (80%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/scripted_beacon_ble_payload.proto (89%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/sniffer.cc (94%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/devices/sniffer.h (90%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/setup/async_manager.cc (94%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/setup/async_manager.h (96%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/setup/device_boutique.cc (74%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/setup/device_boutique.h (81%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/setup/phy_layer.h (91%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/setup/phy_layer_factory.cc (92%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/setup/phy_layer_factory.h (97%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/setup/test_channel_transport.cc (98%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/setup/test_channel_transport.h (97%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/setup/test_command_handler.cc (83%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/setup/test_command_handler.h (87%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/setup/test_model.cc (98%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/model/setup/test_model.h (95%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/net/async_data_channel.h (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/net/async_data_channel_connector.h (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/net/async_data_channel_server.h (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/net/posix/posix_async_socket.cc (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/net/posix/posix_async_socket.h (96%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/net/posix/posix_async_socket_connector.cc (98%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/net/posix/posix_async_socket_connector.h (95%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/net/posix/posix_async_socket_server.cc (97%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/net/posix/posix_async_socket_server.h (94%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/packets/link_layer_packets.pdl (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/build_and_run.sh (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/hci_socket.py (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/link_layer_socket.py (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/scripted_beacon_test/Readme.txt (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/scripted_beacon_test/add_beacons (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/scripted_beacon_test/grant_permission.pb (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/scripted_beacon_test/no_permission.pb (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/scripted_beacon_test/run_test.sh (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/scripted_beacon_test/start_scan (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/scripted_beacon_test/test_events.pb (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/send_simple_commands.py (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/simple_link_layer_socket.py (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/simple_stack.py (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/scripts/test_channel.py (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/test/async_manager_unittest.cc (99%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/test/h4_parser_unittest.cc (98%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/test/posix_socket_unittest.cc (100%) rename {system/vendor_libs/test_vendor_lib => tools/rootcanal}/test/security_manager_unittest.cc (98%) diff --git a/system/test/gen_coverage.py b/system/test/gen_coverage.py index 0ca3b733d60..fe29a3a5e7d 100755 --- a/system/test/gen_coverage.py +++ b/system/test/gen_coverage.py @@ -70,16 +70,16 @@ COVERAGE_TESTS = [ ], }, { - "test_name": "test-vendor_test_host", + "test_name": "rootcanal_test_host", "covered_files": [ - "packages/modules/Bluetooth/system/vendor_libs/test_vendor_lib/include", - "packages/modules/Bluetooth/system/vendor_libs/test_vendor_lib/src", + "packages/modules/Bluetooth/tools/rootcanal/include", + "packages/modules/Bluetooth/tools/rootcanal/src", ], }, { "test_name": "rootcanal-packets_test_host", "covered_files": [ - "packages/modules/Bluetooth/system/vendor_libs/test_vendor_lib/packets", + "packages/modules/Bluetooth/tools/rootcanal/packets", ], }, { diff --git a/system/test/rootcanal/bluetooth_hci.cc b/system/test/rootcanal/bluetooth_hci.cc index 705316cffb3..b5870fa71e9 100644 --- a/system/test/rootcanal/bluetooth_hci.cc +++ b/system/test/rootcanal/bluetooth_hci.cc @@ -33,9 +33,9 @@ namespace V1_1 { namespace sim { using android::hardware::hidl_vec; -using test_vendor_lib::AsyncTaskId; -using test_vendor_lib::DualModeController; -using test_vendor_lib::TaskCallback; +using rootcanal::AsyncTaskId; +using rootcanal::DualModeController; +using rootcanal::TaskCallback; namespace { @@ -177,9 +177,8 @@ Return<void> BluetoothHci::initialize_impl( // Add the controller as a device in the model. size_t controller_index = test_model_.Add(controller_); size_t low_energy_phy_index = - test_model_.AddPhy(test_vendor_lib::Phy::Type::LOW_ENERGY); - size_t classic_phy_index = - test_model_.AddPhy(test_vendor_lib::Phy::Type::BR_EDR); + test_model_.AddPhy(rootcanal::Phy::Type::LOW_ENERGY); + size_t classic_phy_index = test_model_.AddPhy(rootcanal::Phy::Type::BR_EDR); test_model_.AddDeviceToPhy(controller_index, low_energy_phy_index); test_model_.AddDeviceToPhy(controller_index, classic_phy_index); test_model_.SetTimerPeriod(std::chrono::milliseconds(10)); diff --git a/system/test/rootcanal/bluetooth_hci.h b/system/test/rootcanal/bluetooth_hci.h index 9b2aef89d50..44b47ddd611 100644 --- a/system/test/rootcanal/bluetooth_hci.h +++ b/system/test/rootcanal/bluetooth_hci.h @@ -84,7 +84,7 @@ class BluetoothHci : public IBluetoothHci { std::shared_ptr<AsyncDataChannelServer> hci_socket_server_; std::shared_ptr<AsyncDataChannelServer> link_socket_server_; std::shared_ptr<AsyncDataChannelConnector> connector_; - test_vendor_lib::AsyncManager async_manager_; + rootcanal::AsyncManager async_manager_; void SetUpTestChannel(); void SetUpHciServer(ConnectCallback on_connect); @@ -92,40 +92,39 @@ class BluetoothHci : public IBluetoothHci { std::shared_ptr<AsyncDataChannel> ConnectToRemoteServer( const std::string& server, int port); - std::shared_ptr<test_vendor_lib::DualModeController> controller_; + std::shared_ptr<rootcanal::DualModeController> controller_; - test_vendor_lib::TestChannelTransport test_channel_transport_; - test_vendor_lib::TestChannelTransport remote_hci_transport_; - test_vendor_lib::TestChannelTransport remote_link_layer_transport_; + rootcanal::TestChannelTransport test_channel_transport_; + rootcanal::TestChannelTransport remote_hci_transport_; + rootcanal::TestChannelTransport remote_link_layer_transport_; - test_vendor_lib::AsyncUserId user_id_ = async_manager_.GetNextUserId(); - test_vendor_lib::TestModel test_model_{ + rootcanal::AsyncUserId user_id_ = async_manager_.GetNextUserId(); + rootcanal::TestModel test_model_{ [this]() { return async_manager_.GetNextUserId(); }, - [this](test_vendor_lib::AsyncUserId user_id, - std::chrono::milliseconds delay, - const test_vendor_lib::TaskCallback& task) { + [this](rootcanal::AsyncUserId user_id, std::chrono::milliseconds delay, + const rootcanal::TaskCallback& task) { return async_manager_.ExecAsync(user_id, delay, task); }, - [this](test_vendor_lib::AsyncUserId user_id, - std::chrono::milliseconds delay, std::chrono::milliseconds period, - const test_vendor_lib::TaskCallback& task) { + [this](rootcanal::AsyncUserId user_id, std::chrono::milliseconds delay, + std::chrono::milliseconds period, + const rootcanal::TaskCallback& task) { return async_manager_.ExecAsyncPeriodically(user_id, delay, period, task); }, - [this](test_vendor_lib::AsyncUserId user) { + [this](rootcanal::AsyncUserId user) { async_manager_.CancelAsyncTasksFromUser(user); }, - [this](test_vendor_lib::AsyncTaskId task) { + [this](rootcanal::AsyncTaskId task) { async_manager_.CancelAsyncTask(task); }, [this](const std::string& server, int port) { return ConnectToRemoteServer(server, port); }}; - test_vendor_lib::TestCommandHandler test_channel_{test_model_}; + rootcanal::TestCommandHandler test_channel_{test_model_}; }; extern "C" IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* name); diff --git a/system/vendor_libs/Android.bp b/system/vendor_libs/Android.bp index 2763e9bf3f9..768fba25816 100644 --- a/system/vendor_libs/Android.bp +++ b/system/vendor_libs/Android.bp @@ -8,6 +8,5 @@ package { } subdirs = [ - "test_vendor_lib", "linux", ] diff --git a/system/vendor_libs/test_vendor_lib/model/devices/keyboard.cc b/system/vendor_libs/test_vendor_lib/model/devices/keyboard.cc deleted file mode 100644 index f0897043755..00000000000 --- a/system/vendor_libs/test_vendor_lib/model/devices/keyboard.cc +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "keyboard.h" - -#include "model/setup/device_boutique.h" - -using std::vector; - -namespace test_vendor_lib { -bool Keyboard::registered_ = DeviceBoutique::Register("keyboard", &Keyboard::Create); - -Keyboard::Keyboard() { - properties_.SetLeAdvertisementType(0x00 /* CONNECTABLE */); - properties_.SetLeAdvertisement({0x11, // Length - 0x09 /* TYPE_NAME_CMPL */, - 'g', - 'D', - 'e', - 'v', - 'i', - 'c', - 'e', - '-', - 'k', - 'e', - 'y', - 'b', - 'o', - 'a', - 'r', - 'd', - 0x03, // Length - 0x19, - 0xC1, - 0x03, - 0x03, // Length - 0x03, - 0x12, - 0x18, - 0x02, // Length - 0x01 /* TYPE_FLAGS */, - 0x04 /* BREDR_NOT_SPT */ | 0x02 /* GEN_DISC_FLAG */}); - - properties_.SetLeScanResponse({0x04, // Length - 0x08 /* TYPE_NAME_SHORT */, 'k', 'e', 'y'}); -} - -std::string Keyboard::GetTypeString() const { - return "keyboard"; -} - -void Keyboard::Initialize(const vector<std::string>& args) { - if (args.size() < 2) return; - - Address addr{}; - if (Address::FromString(args[1], addr)) properties_.SetLeAddress(addr); - - if (args.size() < 3) return; - - SetAdvertisementInterval(std::chrono::milliseconds(std::stoi(args[2]))); -} - -void Keyboard::TimerTick() { - if (!connected_) { - Beacon::TimerTick(); - } -} - -void Keyboard::IncomingPacket(model::packets::LinkLayerPacketView packet) { - if (!connected_) { - Beacon::IncomingPacket(packet); - } -} - -} // namespace test_vendor_lib diff --git a/system/vendor_libs/test_vendor_lib/Android.bp b/tools/rootcanal/Android.bp similarity index 96% rename from system/vendor_libs/test_vendor_lib/Android.bp rename to tools/rootcanal/Android.bp index 1c69551e1e7..9ed1dd1dd4e 100644 --- a/system/vendor_libs/test_vendor_lib/Android.bp +++ b/tools/rootcanal/Android.bp @@ -6,6 +6,10 @@ package { // to get the below license kinds: // SPDX-license-identifier-Apache-2.0 default_applicable_licenses: ["system_bt_license"], + default_visibility: [ + "//device:__subpackages__", + "//packages/modules/Bluetooth:__subpackages__", + ], } cc_library_static { @@ -101,7 +105,7 @@ cc_library_static { // test-vendor unit tests for host cc_test_host { - name: "test-vendor_test_host", + name: "rootcanal_test_host", defaults: [ "clang_file_coverage", "clang_coverage_bin", @@ -207,7 +211,7 @@ genrule { tools: [ "bluetooth_packetgen", ], - cmd: "$(location bluetooth_packetgen) --root_namespace=model --include=packages/modules/Bluetooth/system/vendor_libs/test_vendor_lib --out=$(genDir) $(in)", + cmd: "$(location bluetooth_packetgen) --root_namespace=model --include=packages/modules/Bluetooth/tools/rootcanal --out=$(genDir) $(in)", srcs: [ "packets/link_layer_packets.pdl", ], diff --git a/system/vendor_libs/test_vendor_lib/data/Android.bp b/tools/rootcanal/data/Android.bp similarity index 100% rename from system/vendor_libs/test_vendor_lib/data/Android.bp rename to tools/rootcanal/data/Android.bp diff --git a/system/vendor_libs/test_vendor_lib/data/controller_properties.json b/tools/rootcanal/data/controller_properties.json similarity index 100% rename from system/vendor_libs/test_vendor_lib/data/controller_properties.json rename to tools/rootcanal/data/controller_properties.json diff --git a/system/vendor_libs/test_vendor_lib/desktop/root_canal_main.cc b/tools/rootcanal/desktop/root_canal_main.cc similarity index 99% rename from system/vendor_libs/test_vendor_lib/desktop/root_canal_main.cc rename to tools/rootcanal/desktop/root_canal_main.cc index 53aa264187a..543a880eb49 100644 --- a/system/vendor_libs/test_vendor_lib/desktop/root_canal_main.cc +++ b/tools/rootcanal/desktop/root_canal_main.cc @@ -13,8 +13,6 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include "test_environment.h" - #include <backtrace/Backtrace.h> #include <backtrace/backtrace_constants.h> #include <client/linux/handler/exception_handler.h> @@ -26,11 +24,12 @@ #include "net/posix/posix_async_socket_connector.h" #include "net/posix/posix_async_socket_server.h" #include "os/log.h" +#include "test_environment.h" using ::android::bluetooth::root_canal::TestEnvironment; using ::android::net::PosixAsyncSocketConnector; using ::android::net::PosixAsyncSocketServer; -using test_vendor_lib::AsyncManager; +using rootcanal::AsyncManager; DEFINE_string(controller_properties_file, "", "controller_properties.json file path"); diff --git a/system/vendor_libs/test_vendor_lib/desktop/test_environment.cc b/tools/rootcanal/desktop/test_environment.cc similarity index 98% rename from system/vendor_libs/test_vendor_lib/desktop/test_environment.cc rename to tools/rootcanal/desktop/test_environment.cc index 73b2072178b..8aa01081c55 100644 --- a/system/vendor_libs/test_vendor_lib/desktop/test_environment.cc +++ b/tools/rootcanal/desktop/test_environment.cc @@ -27,8 +27,8 @@ namespace android { namespace bluetooth { namespace root_canal { -using test_vendor_lib::AsyncTaskId; -using test_vendor_lib::TaskCallback; +using rootcanal::AsyncTaskId; +using rootcanal::TaskCallback; void TestEnvironment::initialize(std::promise<void> barrier) { LOG_INFO("Initialized barrier"); diff --git a/system/vendor_libs/test_vendor_lib/desktop/test_environment.h b/tools/rootcanal/desktop/test_environment.h similarity index 79% rename from system/vendor_libs/test_vendor_lib/desktop/test_environment.h rename to tools/rootcanal/desktop/test_environment.h index baf00be273c..e2bc6482aaa 100644 --- a/system/vendor_libs/test_vendor_lib/desktop/test_environment.h +++ b/tools/rootcanal/desktop/test_environment.h @@ -59,7 +59,7 @@ class TestEnvironment { connector_(connector), controller_properties_file_(controller_properties_file), default_commands_file_(default_commands_file), - controller_(std::make_shared<test_vendor_lib::DualModeController>( + controller_(std::make_shared<rootcanal::DualModeController>( controller_properties_file)) {} void initialize(std::promise<void> barrier); @@ -67,7 +67,7 @@ class TestEnvironment { void close(); private: - test_vendor_lib::AsyncManager async_manager_; + rootcanal::AsyncManager async_manager_; std::shared_ptr<AsyncDataChannelServer> test_socket_server_; std::shared_ptr<AsyncDataChannelServer> hci_socket_server_; std::shared_ptr<AsyncDataChannelServer> link_socket_server_; @@ -78,7 +78,6 @@ class TestEnvironment { bool test_channel_open_{false}; std::promise<void> barrier_; - void SetUpTestChannel(); void SetUpHciServer(ConnectCallback on_connect); void SetUpLinkLayerServer(); @@ -86,33 +85,32 @@ class TestEnvironment { std::shared_ptr<AsyncDataChannel> ConnectToRemoteServer( const std::string& server, int port); - std::shared_ptr<test_vendor_lib::DualModeController> controller_; + std::shared_ptr<rootcanal::DualModeController> controller_; - test_vendor_lib::TestChannelTransport test_channel_transport_; - test_vendor_lib::TestChannelTransport remote_hci_transport_; - test_vendor_lib::TestChannelTransport remote_link_layer_transport_; - test_vendor_lib::TestChannelTransport remote_link_ble_layer_transport_; + rootcanal::TestChannelTransport test_channel_transport_; + rootcanal::TestChannelTransport remote_hci_transport_; + rootcanal::TestChannelTransport remote_link_layer_transport_; + rootcanal::TestChannelTransport remote_link_ble_layer_transport_; - test_vendor_lib::TestModel test_model_{ + rootcanal::TestModel test_model_{ [this]() { return async_manager_.GetNextUserId(); }, - [this](test_vendor_lib::AsyncUserId user_id, - std::chrono::milliseconds delay, - const test_vendor_lib::TaskCallback& task) { + [this](rootcanal::AsyncUserId user_id, std::chrono::milliseconds delay, + const rootcanal::TaskCallback& task) { return async_manager_.ExecAsync(user_id, delay, task); }, - [this](test_vendor_lib::AsyncUserId user_id, - std::chrono::milliseconds delay, std::chrono::milliseconds period, - const test_vendor_lib::TaskCallback& task) { + [this](rootcanal::AsyncUserId user_id, std::chrono::milliseconds delay, + std::chrono::milliseconds period, + const rootcanal::TaskCallback& task) { return async_manager_.ExecAsyncPeriodically(user_id, delay, period, task); }, - [this](test_vendor_lib::AsyncUserId user) { + [this](rootcanal::AsyncUserId user) { async_manager_.CancelAsyncTasksFromUser(user); }, - [this](test_vendor_lib::AsyncTaskId task) { + [this](rootcanal::AsyncTaskId task) { async_manager_.CancelAsyncTask(task); }, @@ -120,7 +118,7 @@ class TestEnvironment { return ConnectToRemoteServer(server, port); }}; - test_vendor_lib::TestCommandHandler test_channel_{test_model_}; + rootcanal::TestCommandHandler test_channel_{test_model_}; }; } // namespace root_canal } // namespace bluetooth diff --git a/system/vendor_libs/test_vendor_lib/include/phy.h b/tools/rootcanal/include/phy.h similarity index 92% rename from system/vendor_libs/test_vendor_lib/include/phy.h rename to tools/rootcanal/include/phy.h index da3673ca18e..1fa82743ab7 100644 --- a/system/vendor_libs/test_vendor_lib/include/phy.h +++ b/tools/rootcanal/include/phy.h @@ -16,7 +16,7 @@ #pragma once -namespace test_vendor_lib { +namespace rootcanal { class Phy { public: @@ -25,4 +25,4 @@ class Phy { BR_EDR, }; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/acl_connection.cc b/tools/rootcanal/model/controller/acl_connection.cc similarity index 95% rename from system/vendor_libs/test_vendor_lib/model/controller/acl_connection.cc rename to tools/rootcanal/model/controller/acl_connection.cc index 96f7a606c4b..db5c5e11c88 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/acl_connection.cc +++ b/tools/rootcanal/model/controller/acl_connection.cc @@ -16,7 +16,7 @@ #include "acl_connection.h" -namespace test_vendor_lib { +namespace rootcanal { AclConnection::AclConnection(AddressWithType addr, AddressWithType own_addr, Phy::Type phy_type) : address_(addr), own_address_(own_addr), type_(phy_type) {} @@ -37,4 +37,4 @@ void AclConnection::SetOwnAddress(AddressWithType own_addr) { Phy::Type AclConnection::GetPhyType() const { return type_; } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/acl_connection.h b/tools/rootcanal/model/controller/acl_connection.h similarity index 95% rename from system/vendor_libs/test_vendor_lib/model/controller/acl_connection.h rename to tools/rootcanal/model/controller/acl_connection.h index 12e1779ea88..80b35ada224 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/acl_connection.h +++ b/tools/rootcanal/model/controller/acl_connection.h @@ -21,7 +21,7 @@ #include "hci/address_with_type.h" #include "phy.h" -namespace test_vendor_lib { +namespace rootcanal { using ::bluetooth::hci::AddressWithType; @@ -56,4 +56,4 @@ class AclConnection { bool encrypted_{false}; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.cc b/tools/rootcanal/model/controller/acl_connection_handler.cc similarity index 92% rename from system/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.cc rename to tools/rootcanal/model/controller/acl_connection_handler.cc index 3f9b5b18fd1..8aafaf987c9 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.cc +++ b/tools/rootcanal/model/controller/acl_connection_handler.cc @@ -21,7 +21,7 @@ #include "hci/address.h" #include "os/log.h" -namespace test_vendor_lib { +namespace rootcanal { using ::bluetooth::hci::Address; using ::bluetooth::hci::AddressType; @@ -422,15 +422,15 @@ StreamParameters AclConnectionHandler::GetStreamParameters( } void AclConnectionHandler::CreateScoConnection( - bluetooth::hci::Address addr, ScoConnectionParameters const ¶meters, - ScoState state, bool legacy) { - + bluetooth::hci::Address addr, ScoConnectionParameters const& parameters, + ScoState state, bool legacy) { uint16_t sco_handle = GetUnusedHandle(); sco_connections_.emplace(sco_handle, - ScoConnection(addr, parameters, state, legacy)); + ScoConnection(addr, parameters, state, legacy)); } -bool AclConnectionHandler::HasPendingScoConnection(bluetooth::hci::Address addr) const { +bool AclConnectionHandler::HasPendingScoConnection( + bluetooth::hci::Address addr) const { for (const auto& pair : sco_connections_) { if (std::get<ScoConnection>(pair).GetAddress() == addr) { ScoState state = std::get<ScoConnection>(pair).GetState(); @@ -442,7 +442,8 @@ bool AclConnectionHandler::HasPendingScoConnection(bluetooth::hci::Address addr) return false; } -ScoState AclConnectionHandler::GetScoConnectionState(bluetooth::hci::Address addr) const { +ScoState AclConnectionHandler::GetScoConnectionState( + bluetooth::hci::Address addr) const { for (const auto& pair : sco_connections_) { if (std::get<ScoConnection>(pair).GetAddress() == addr) { return std::get<ScoConnection>(pair).GetState(); @@ -451,7 +452,8 @@ ScoState AclConnectionHandler::GetScoConnectionState(bluetooth::hci::Address add return SCO_STATE_CLOSED; } -bool AclConnectionHandler::IsLegacyScoConnection(bluetooth::hci::Address addr) const { +bool AclConnectionHandler::IsLegacyScoConnection( + bluetooth::hci::Address addr) const { for (const auto& pair : sco_connections_) { if (std::get<ScoConnection>(pair).GetAddress() == addr) { return std::get<ScoConnection>(pair).IsLegacy(); @@ -460,7 +462,8 @@ bool AclConnectionHandler::IsLegacyScoConnection(bluetooth::hci::Address addr) c return false; } -void AclConnectionHandler::CancelPendingScoConnection(bluetooth::hci::Address addr) { +void AclConnectionHandler::CancelPendingScoConnection( + bluetooth::hci::Address addr) { for (auto it = sco_connections_.begin(); it != sco_connections_.end(); it++) { if (std::get<ScoConnection>(*it).GetAddress() == addr) { sco_connections_.erase(it); @@ -469,8 +472,8 @@ void AclConnectionHandler::CancelPendingScoConnection(bluetooth::hci::Address ad } } -bool AclConnectionHandler::AcceptPendingScoConnection(bluetooth::hci::Address addr, - ScoLinkParameters const ¶meters) { +bool AclConnectionHandler::AcceptPendingScoConnection( + bluetooth::hci::Address addr, ScoLinkParameters const& parameters) { for (auto& pair : sco_connections_) { if (std::get<ScoConnection>(pair).GetAddress() == addr) { std::get<ScoConnection>(pair).SetLinkParameters(parameters); @@ -481,20 +484,22 @@ bool AclConnectionHandler::AcceptPendingScoConnection(bluetooth::hci::Address ad return false; } -bool AclConnectionHandler::AcceptPendingScoConnection(bluetooth::hci::Address addr, - ScoConnectionParameters const ¶meters) { +bool AclConnectionHandler::AcceptPendingScoConnection( + bluetooth::hci::Address addr, ScoConnectionParameters const& parameters) { for (auto& pair : sco_connections_) { if (std::get<ScoConnection>(pair).GetAddress() == addr) { - bool ok = std::get<ScoConnection>(pair).NegotiateLinkParameters(parameters); - std::get<ScoConnection>(pair).SetState( - ok ? ScoState::SCO_STATE_OPENED : ScoState::SCO_STATE_CLOSED); + bool ok = + std::get<ScoConnection>(pair).NegotiateLinkParameters(parameters); + std::get<ScoConnection>(pair).SetState(ok ? ScoState::SCO_STATE_OPENED + : ScoState::SCO_STATE_CLOSED); return ok; } } return false; } -uint16_t AclConnectionHandler::GetScoHandle(bluetooth::hci::Address addr) const { +uint16_t AclConnectionHandler::GetScoHandle( + bluetooth::hci::Address addr) const { for (const auto& pair : sco_connections_) { if (std::get<ScoConnection>(pair).GetAddress() == addr) { return std::get<0>(pair); @@ -513,7 +518,8 @@ ScoConnectionParameters AclConnectionHandler::GetScoConnectionParameters( return {}; } -ScoLinkParameters AclConnectionHandler::GetScoLinkParameters(bluetooth::hci::Address addr) const { +ScoLinkParameters AclConnectionHandler::GetScoLinkParameters( + bluetooth::hci::Address addr) const { for (const auto& pair : sco_connections_) { if (std::get<ScoConnection>(pair).GetAddress() == addr) { return std::get<ScoConnection>(pair).GetLinkParameters(); @@ -531,4 +537,4 @@ std::vector<uint16_t> AclConnectionHandler::GetAclHandles() const { return keys; } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.h b/tools/rootcanal/model/controller/acl_connection_handler.h similarity index 94% rename from system/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.h rename to tools/rootcanal/model/controller/acl_connection_handler.h index 008a2936c7d..7f8af70e3d5 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.h +++ b/tools/rootcanal/model/controller/acl_connection_handler.h @@ -27,7 +27,7 @@ #include "phy.h" #include "sco_connection.h" -namespace test_vendor_lib { +namespace rootcanal { static constexpr uint16_t kReservedHandle = 0xF00; class AclConnectionHandler { @@ -46,12 +46,13 @@ class AclConnectionHandler { ScoState GetScoConnectionState(bluetooth::hci::Address addr) const; bool IsLegacyScoConnection(bluetooth::hci::Address addr) const; void CreateScoConnection(bluetooth::hci::Address addr, - ScoConnectionParameters const ¶meters, ScoState state, bool legacy = false); + ScoConnectionParameters const& parameters, + ScoState state, bool legacy = false); void CancelPendingScoConnection(bluetooth::hci::Address addr); bool AcceptPendingScoConnection(bluetooth::hci::Address addr, - ScoLinkParameters const ¶meters); + ScoLinkParameters const& parameters); bool AcceptPendingScoConnection(bluetooth::hci::Address addr, - ScoConnectionParameters const ¶meters); + ScoConnectionParameters const& parameters); uint16_t GetScoHandle(bluetooth::hci::Address addr) const; ScoConnectionParameters GetScoConnectionParameters( bluetooth::hci::Address addr) const; @@ -147,4 +148,4 @@ class AclConnectionHandler { std::vector<CisHandles> pending_streams_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/connected_isochronous_group.h b/tools/rootcanal/model/controller/connected_isochronous_group.h similarity index 97% rename from system/vendor_libs/test_vendor_lib/model/controller/connected_isochronous_group.h rename to tools/rootcanal/model/controller/connected_isochronous_group.h index c3df80a661f..65dadc97c51 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/connected_isochronous_group.h +++ b/tools/rootcanal/model/controller/connected_isochronous_group.h @@ -21,7 +21,7 @@ #include "hci/hci_packets.h" #include "model/controller/connected_isochronous_stream.h" -namespace test_vendor_lib { +namespace rootcanal { class GroupParameters { public: @@ -73,4 +73,4 @@ class ConnectedIsochronousGroup { std::vector<ConnectedIsochronousStream> streams_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/connected_isochronous_stream.h b/tools/rootcanal/model/controller/connected_isochronous_stream.h similarity index 95% rename from system/vendor_libs/test_vendor_lib/model/controller/connected_isochronous_stream.h rename to tools/rootcanal/model/controller/connected_isochronous_stream.h index 49a839476ff..f599fc6e023 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/connected_isochronous_stream.h +++ b/tools/rootcanal/model/controller/connected_isochronous_stream.h @@ -20,7 +20,7 @@ #include "hci/hci_packets.h" -namespace test_vendor_lib { +namespace rootcanal { class StreamParameters { public: @@ -52,4 +52,4 @@ class ConnectedIsochronousStream { bool is_connected_{false}; StreamParameters config_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.cc b/tools/rootcanal/model/controller/dual_mode_controller.cc similarity index 96% rename from system/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.cc rename to tools/rootcanal/model/controller/dual_mode_controller.cc index f0a33a558b6..a27b9fa97cd 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.cc +++ b/tools/rootcanal/model/controller/dual_mode_controller.cc @@ -29,7 +29,7 @@ using gd_hci::LoopbackMode; using gd_hci::OpCode; using std::vector; -namespace test_vendor_lib { +namespace rootcanal { constexpr char DualModeController::kControllerPropertiesFile[]; constexpr uint16_t DualModeController::kSecurityManagerNumKeys; constexpr uint16_t kNumCommandPackets = 0x01; @@ -58,16 +58,15 @@ void DualModeController::IncomingPacket( link_layer_controller_.IncomingPacket(incoming); } -void DualModeController::TimerTick() { - link_layer_controller_.TimerTick(); -} +void DualModeController::TimerTick() { link_layer_controller_.TimerTick(); } void DualModeController::Close() { link_layer_controller_.Close(); Device::Close(); } -void DualModeController::SendCommandCompleteUnknownOpCodeEvent(uint16_t command_opcode) const { +void DualModeController::SendCommandCompleteUnknownOpCodeEvent( + uint16_t command_opcode) const { std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr = std::make_unique<bluetooth::packet::RawBuilder>(); raw_builder_ptr->AddOctets1(kNumCommandPackets); @@ -75,11 +74,12 @@ void DualModeController::SendCommandCompleteUnknownOpCodeEvent(uint16_t command_ raw_builder_ptr->AddOctets1( static_cast<uint8_t>(ErrorCode::UNKNOWN_HCI_COMMAND)); - send_event_(gd_hci::EventBuilder::Create( - gd_hci::EventCode::COMMAND_COMPLETE, std::move(raw_builder_ptr))); + send_event_(gd_hci::EventBuilder::Create(gd_hci::EventCode::COMMAND_COMPLETE, + std::move(raw_builder_ptr))); } -DualModeController::DualModeController(const std::string& properties_filename, uint16_t num_keys) +DualModeController::DualModeController(const std::string& properties_filename, + uint16_t num_keys) : Device(properties_filename), security_manager_(num_keys) { loopback_mode_ = LoopbackMode::NO_LOOPBACK; @@ -303,9 +303,12 @@ DualModeController::DualModeController(const std::string& properties_filename, u SET_SUPPORTED(READ_CONNECTION_ACCEPT_TIMEOUT, ReadConnectionAcceptTimeout); SET_SUPPORTED(WRITE_CONNECTION_ACCEPT_TIMEOUT, WriteConnectionAcceptTimeout); SET_SUPPORTED(LE_SET_ADDRESS_RESOLUTION_ENABLE, LeSetAddressResolutionEnable); - SET_SUPPORTED(LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT, LeSetResovalablePrivateAddressTimeout); - SET_SUPPORTED(READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE, ReadSynchronousFlowControlEnable); - SET_SUPPORTED(WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE, WriteSynchronousFlowControlEnable); + SET_SUPPORTED(LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT, + LeSetResovalablePrivateAddressTimeout); + SET_SUPPORTED(READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE, + ReadSynchronousFlowControlEnable); + SET_SUPPORTED(WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE, + WriteSynchronousFlowControlEnable); #undef SET_HANDLER #undef SET_SUPPORTED @@ -324,21 +327,25 @@ void DualModeController::SniffSubrating(CommandView command) { } void DualModeController::RegisterTaskScheduler( - std::function<AsyncTaskId(std::chrono::milliseconds, const TaskCallback&)> oneshot_scheduler) { + std::function<AsyncTaskId(std::chrono::milliseconds, const TaskCallback&)> + oneshot_scheduler) { link_layer_controller_.RegisterTaskScheduler(oneshot_scheduler); } void DualModeController::RegisterPeriodicTaskScheduler( - std::function<AsyncTaskId(std::chrono::milliseconds, std::chrono::milliseconds, const TaskCallback&)> + std::function<AsyncTaskId(std::chrono::milliseconds, + std::chrono::milliseconds, const TaskCallback&)> periodic_scheduler) { link_layer_controller_.RegisterPeriodicTaskScheduler(periodic_scheduler); } -void DualModeController::RegisterTaskCancel(std::function<void(AsyncTaskId)> task_cancel) { +void DualModeController::RegisterTaskCancel( + std::function<void(AsyncTaskId)> task_cancel) { link_layer_controller_.RegisterTaskCancel(task_cancel); } -void DualModeController::HandleAcl(std::shared_ptr<std::vector<uint8_t>> packet) { +void DualModeController::HandleAcl( + std::shared_ptr<std::vector<uint8_t>> packet) { bluetooth::hci::PacketView<bluetooth::hci::kLittleEndian> raw_packet(packet); auto acl_packet = bluetooth::hci::AclView::Create(raw_packet); ASSERT(acl_packet.IsValid()); @@ -358,7 +365,8 @@ void DualModeController::HandleAcl(std::shared_ptr<std::vector<uint8_t>> packet) link_layer_controller_.SendAclToRemote(acl_packet); } -void DualModeController::HandleSco(std::shared_ptr<std::vector<uint8_t>> packet) { +void DualModeController::HandleSco( + std::shared_ptr<std::vector<uint8_t>> packet) { bluetooth::hci::PacketView<bluetooth::hci::kLittleEndian> raw_packet(packet); auto sco_packet = bluetooth::hci::ScoView::Create(raw_packet); ASSERT(sco_packet.IsValid()); @@ -391,7 +399,8 @@ void DualModeController::HandleIso( link_layer_controller_.HandleIso(iso); } -void DualModeController::HandleCommand(std::shared_ptr<std::vector<uint8_t>> packet) { +void DualModeController::HandleCommand( + std::shared_ptr<std::vector<uint8_t>> packet) { bluetooth::hci::PacketView<bluetooth::hci::kLittleEndian> raw_packet(packet); auto command_packet = bluetooth::hci::CommandView::Create(raw_packet); ASSERT(command_packet.IsValid()); @@ -421,7 +430,8 @@ void DualModeController::HandleCommand(std::shared_ptr<std::vector<uint8_t>> pac } void DualModeController::RegisterEventChannel( - const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& callback) { + const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& + callback) { send_event_ = [callback](std::shared_ptr<bluetooth::hci::EventBuilder> event) { auto bytes = std::make_shared<std::vector<uint8_t>>(); @@ -434,7 +444,8 @@ void DualModeController::RegisterEventChannel( } void DualModeController::RegisterAclChannel( - const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& callback) { + const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& + callback) { send_acl_ = [callback](std::shared_ptr<bluetooth::hci::AclBuilder> acl_data) { auto bytes = std::make_shared<std::vector<uint8_t>>(); bluetooth::packet::BitInserter bit_inserter(*bytes); @@ -446,7 +457,8 @@ void DualModeController::RegisterAclChannel( } void DualModeController::RegisterScoChannel( - const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& callback) { + const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& + callback) { send_sco_ = [callback](std::shared_ptr<bluetooth::hci::ScoBuilder> sco_data) { auto bytes = std::make_shared<std::vector<uint8_t>>(); bluetooth::packet::BitInserter bit_inserter(*bytes); @@ -580,8 +592,7 @@ void DualModeController::ReadLocalSupportedCodecs(CommandView command) { auto command_view = gd_hci::ReadLocalSupportedCodecsV1View::Create(command); ASSERT(command_view.IsValid()); send_event_(bluetooth::hci::ReadLocalSupportedCodecsV1CompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - properties_.GetSupportedCodecs(), + kNumCommandPackets, ErrorCode::SUCCESS, properties_.GetSupportedCodecs(), properties_.GetVendorSpecificCodecs())); } @@ -590,11 +601,10 @@ void DualModeController::ReadLocalExtendedFeatures(CommandView command) { ASSERT(command_view.IsValid()); uint8_t page_number = command_view.GetPageNumber(); - send_event_( - bluetooth::hci::ReadLocalExtendedFeaturesCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, page_number, - properties_.GetExtendedFeaturesMaximumPageNumber(), - properties_.GetExtendedFeatures(page_number))); + send_event_(bluetooth::hci::ReadLocalExtendedFeaturesCompleteBuilder::Create( + kNumCommandPackets, ErrorCode::SUCCESS, page_number, + properties_.GetExtendedFeaturesMaximumPageNumber(), + properties_.GetExtendedFeatures(page_number))); } void DualModeController::ReadRemoteExtendedFeatures(CommandView command) { @@ -670,15 +680,15 @@ void DualModeController::AddScoConnection(CommandView command) { void DualModeController::SetupSynchronousConnection(CommandView command) { auto command_view = gd_hci::SetupSynchronousConnectionView::Create( - gd_hci::ScoConnectionCommandView::Create( - gd_hci::AclCommandView::Create(command))); + gd_hci::ScoConnectionCommandView::Create( + gd_hci::AclCommandView::Create(command))); ASSERT(command_view.IsValid()); auto status = link_layer_controller_.SetupSynchronousConnection( - command_view.GetConnectionHandle(), command_view.GetTransmitBandwidth(), - command_view.GetReceiveBandwidth(), command_view.GetMaxLatency(), - command_view.GetVoiceSetting(), command_view.GetRetransmissionEffort(), - command_view.GetPacketType()); + command_view.GetConnectionHandle(), command_view.GetTransmitBandwidth(), + command_view.GetReceiveBandwidth(), command_view.GetMaxLatency(), + command_view.GetVoiceSetting(), command_view.GetRetransmissionEffort(), + command_view.GetPacketType()); send_event_(bluetooth::hci::SetupSynchronousConnectionStatusBuilder::Create( status, kNumCommandPackets)); @@ -686,15 +696,15 @@ void DualModeController::SetupSynchronousConnection(CommandView command) { void DualModeController::AcceptSynchronousConnection(CommandView command) { auto command_view = gd_hci::AcceptSynchronousConnectionView::Create( - gd_hci::ScoConnectionCommandView::Create( - gd_hci::AclCommandView::Create(command))); + gd_hci::ScoConnectionCommandView::Create( + gd_hci::AclCommandView::Create(command))); ASSERT(command_view.IsValid()); auto status = link_layer_controller_.AcceptSynchronousConnection( - command_view.GetBdAddr(), command_view.GetTransmitBandwidth(), - command_view.GetReceiveBandwidth(), command_view.GetMaxLatency(), - command_view.GetVoiceSetting(), command_view.GetRetransmissionEffort(), - command_view.GetPacketType()); + command_view.GetBdAddr(), command_view.GetTransmitBandwidth(), + command_view.GetReceiveBandwidth(), command_view.GetMaxLatency(), + command_view.GetVoiceSetting(), command_view.GetRetransmissionEffort(), + command_view.GetPacketType()); send_event_(bluetooth::hci::AcceptSynchronousConnectionStatusBuilder::Create( status, kNumCommandPackets)); @@ -702,12 +712,12 @@ void DualModeController::AcceptSynchronousConnection(CommandView command) { void DualModeController::RejectSynchronousConnection(CommandView command) { auto command_view = gd_hci::RejectSynchronousConnectionView::Create( - gd_hci::ScoConnectionCommandView::Create( - gd_hci::AclCommandView::Create(command))); + gd_hci::ScoConnectionCommandView::Create( + gd_hci::AclCommandView::Create(command))); ASSERT(command_view.IsValid()); auto status = link_layer_controller_.RejectSynchronousConnection( - command_view.GetBdAddr(), (uint16_t)command_view.GetReason()); + command_view.GetBdAddr(), (uint16_t)command_view.GetReason()); send_event_(bluetooth::hci::RejectSynchronousConnectionStatusBuilder::Create( status, kNumCommandPackets)); @@ -1094,9 +1104,8 @@ void DualModeController::WriteAuthenticationEnable(CommandView command) { ASSERT(command_view.IsValid()); properties_.SetAuthenticationEnable( static_cast<uint8_t>(command_view.GetAuthenticationEnable())); - send_event_( - bluetooth::hci::WriteAuthenticationEnableCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::WriteAuthenticationEnableCompleteBuilder::Create( + kNumCommandPackets, ErrorCode::SUCCESS)); } void DualModeController::ReadAuthenticationEnable(CommandView command) { @@ -1435,13 +1444,12 @@ void DualModeController::WriteScanEnable(CommandView command) { bool inquiry_scan = scan_enable == gd_hci::ScanEnable::INQUIRY_AND_PAGE_SCAN || scan_enable == gd_hci::ScanEnable::INQUIRY_SCAN_ONLY; - bool page_scan = - scan_enable == gd_hci::ScanEnable::INQUIRY_AND_PAGE_SCAN || - scan_enable == gd_hci::ScanEnable::PAGE_SCAN_ONLY; + bool page_scan = scan_enable == gd_hci::ScanEnable::INQUIRY_AND_PAGE_SCAN || + scan_enable == gd_hci::ScanEnable::PAGE_SCAN_ONLY; LOG_INFO("%s | WriteScanEnable %s", - properties_.GetAddress().ToString().c_str(), - gd_hci::ScanEnableText(scan_enable).c_str()); + properties_.GetAddress().ToString().c_str(), + gd_hci::ScanEnableText(scan_enable).c_str()); link_layer_controller_.SetInquiryScanEnable(inquiry_scan); link_layer_controller_.SetPageScanEnable(page_scan); @@ -1462,7 +1470,8 @@ void DualModeController::ReadSynchronousFlowControlEnable(CommandView command) { kNumCommandPackets, ErrorCode::SUCCESS, enabled)); } -void DualModeController::WriteSynchronousFlowControlEnable(CommandView command) { +void DualModeController::WriteSynchronousFlowControlEnable( + CommandView command) { auto command_view = gd_hci::WriteSynchronousFlowControlEnableView::Create( gd_hci::DiscoveryCommandView::Create(command)); ASSERT(command_view.IsValid()); @@ -1495,8 +1504,8 @@ void DualModeController::Inquiry(CommandView command) { link_layer_controller_.SetInquiryMaxResponses(max_responses); link_layer_controller_.StartInquiry(std::chrono::milliseconds(length * 1280)); - send_event_(bluetooth::hci::InquiryStatusBuilder::Create( - ErrorCode::SUCCESS, kNumCommandPackets)); + send_event_(bluetooth::hci::InquiryStatusBuilder::Create(ErrorCode::SUCCESS, + kNumCommandPackets)); } void DualModeController::InquiryCancel(CommandView command) { @@ -1640,9 +1649,10 @@ void DualModeController::LeSetAddressResolutionEnable(CommandView command) { kNumCommandPackets, status)); } -void DualModeController::LeSetResovalablePrivateAddressTimeout(CommandView command) { - // NOP - auto payload = +void DualModeController::LeSetResovalablePrivateAddressTimeout( + CommandView command) { + // NOP + auto payload = std::make_unique<bluetooth::packet::RawBuilder>(std::vector<uint8_t>( {static_cast<uint8_t>(bluetooth::hci::ErrorCode::SUCCESS)})); send_event_(bluetooth::hci::CommandCompleteBuilder::Create( @@ -1685,9 +1695,8 @@ void DualModeController::LeSetAdvertisingParameters(CommandView command) { command_view.GetChannelMap(), static_cast<uint8_t>(command_view.GetFilterPolicy())); - send_event_( - bluetooth::hci::LeSetAdvertisingParametersCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::LeSetAdvertisingParametersCompleteBuilder::Create( + kNumCommandPackets, ErrorCode::SUCCESS)); } void DualModeController::LeReadAdvertisingPhysicalChannelTxPower( @@ -1734,8 +1743,8 @@ void DualModeController::LeSetAdvertisingEnable(CommandView command) { ASSERT(command_view.IsValid()); LOG_INFO("%s | LeSetAdvertisingEnable (%d)", - properties_.GetAddress().ToString().c_str(), - command_view.GetAdvertisingEnable() == gd_hci::Enable::ENABLED); + properties_.GetAddress().ToString().c_str(), + command_view.GetAdvertisingEnable() == gd_hci::Enable::ENABLED); auto status = link_layer_controller_.SetLeAdvertisingEnable( command_view.GetAdvertisingEnable() == gd_hci::Enable::ENABLED); @@ -1764,8 +1773,8 @@ void DualModeController::LeSetScanEnable(CommandView command) { ASSERT(command_view.IsValid()); LOG_INFO("%s | LeSetScanEnable (%d)", - properties_.GetAddress().ToString().c_str(), - command_view.GetLeScanEnable() == gd_hci::Enable::ENABLED); + properties_.GetAddress().ToString().c_str(), + command_view.GetLeScanEnable() == gd_hci::Enable::ENABLED); if (command_view.GetLeScanEnable() == gd_hci::Enable::ENABLED) { link_layer_controller_.SetLeScanEnable(gd_hci::OpCode::LE_SET_SCAN_ENABLE); @@ -2314,8 +2323,7 @@ void DualModeController::LeEncrypt(CommandView command) { ASSERT(command_view.IsValid()); auto encrypted_data = bluetooth::crypto_toolbox::aes_128( - command_view.GetKey(), - command_view.GetPlaintextData()); + command_view.GetKey(), command_view.GetPlaintextData()); send_event_(bluetooth::hci::LeEncryptCompleteBuilder::Create( kNumCommandPackets, ErrorCode::SUCCESS, encrypted_data)); @@ -2670,4 +2678,4 @@ void DualModeController::SetAddress(Address address) { properties_.SetAddress(address); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.h b/tools/rootcanal/model/controller/dual_mode_controller.h similarity index 95% rename from system/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.h rename to tools/rootcanal/model/controller/dual_mode_controller.h index 785bc041ccc..f9a4d282b6e 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.h +++ b/tools/rootcanal/model/controller/dual_mode_controller.h @@ -17,6 +17,7 @@ #pragma once #include <unistd.h> + #include <cstdint> #include <memory> #include <string> @@ -30,7 +31,7 @@ #include "model/setup/async_manager.h" #include "security_manager.h" -namespace test_vendor_lib { +namespace rootcanal { using ::bluetooth::hci::Address; using ::bluetooth::hci::CommandView; @@ -54,7 +55,8 @@ class DualModeController : public Device { public: // Sets all of the methods to be used as callbacks in the HciHandler. - DualModeController(const std::string& properties_filename = std::string(kControllerPropertiesFile), + DualModeController(const std::string& properties_filename = + std::string(kControllerPropertiesFile), uint16_t num_keys = kSecurityManagerNumKeys); ~DualModeController() = default; @@ -78,10 +80,13 @@ class DualModeController : public Device { void HandleIso(std::shared_ptr<std::vector<uint8_t>> iso_packet); // Set the callbacks for scheduling tasks. - void RegisterTaskScheduler(std::function<AsyncTaskId(std::chrono::milliseconds, const TaskCallback&)> evtScheduler); + void RegisterTaskScheduler( + std::function<AsyncTaskId(std::chrono::milliseconds, const TaskCallback&)> + evtScheduler); void RegisterPeriodicTaskScheduler( - std::function<AsyncTaskId(std::chrono::milliseconds, std::chrono::milliseconds, const TaskCallback&)> + std::function<AsyncTaskId(std::chrono::milliseconds, + std::chrono::milliseconds, const TaskCallback&)> periodicEvtScheduler); void RegisterTaskCancel(std::function<void(AsyncTaskId)> cancel); @@ -91,9 +96,13 @@ class DualModeController : public Device { const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_event); - void RegisterAclChannel(const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_acl); + void RegisterAclChannel( + const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& + send_acl); - void RegisterScoChannel(const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_sco); + void RegisterScoChannel( + const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& + send_sco); void RegisterIsoChannel( const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& @@ -605,7 +614,8 @@ class DualModeController : public Device { private: // Set a timer for a future action - void AddControllerEvent(std::chrono::milliseconds, const TaskCallback& callback); + void AddControllerEvent(std::chrono::milliseconds, + const TaskCallback& callback); void AddConnectionAction(const TaskCallback& callback, uint16_t handle); @@ -637,4 +647,4 @@ class DualModeController : public Device { DualModeController& operator=(const DualModeController& cmdPckt) = delete; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/isochronous_connection_handler.cc b/tools/rootcanal/model/controller/isochronous_connection_handler.cc similarity index 98% rename from system/vendor_libs/test_vendor_lib/model/controller/isochronous_connection_handler.cc rename to tools/rootcanal/model/controller/isochronous_connection_handler.cc index d4a27625070..0c1ebfcd571 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/isochronous_connection_handler.cc +++ b/tools/rootcanal/model/controller/isochronous_connection_handler.cc @@ -16,11 +16,10 @@ #include "model/controller/isochronous_connection_handler.h" -#include "os/log.h" - #include "hci/address.h" +#include "os/log.h" -namespace test_vendor_lib { +namespace rootcanal { using bluetooth::hci::ErrorCode; @@ -96,4 +95,4 @@ bool IsochronousConnectionHandler::GetStreamIsConnected(uint16_t handle) const { return groups_.at(cis_to_group_.at(handle)).StreamIsConnected(handle); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/isochronous_connection_handler.h b/tools/rootcanal/model/controller/isochronous_connection_handler.h similarity index 96% rename from system/vendor_libs/test_vendor_lib/model/controller/isochronous_connection_handler.h rename to tools/rootcanal/model/controller/isochronous_connection_handler.h index b0e6750c98e..5552fd536f7 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/isochronous_connection_handler.h +++ b/tools/rootcanal/model/controller/isochronous_connection_handler.h @@ -24,7 +24,7 @@ #include "model/controller/connected_isochronous_group.h" #include "model/controller/connected_isochronous_stream.h" -namespace test_vendor_lib { +namespace rootcanal { class IsochronousConnectionHandler { public: @@ -54,4 +54,4 @@ class IsochronousConnectionHandler { std::map<uint16_t, uint8_t> cis_to_group_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/le_advertiser.cc b/tools/rootcanal/model/controller/le_advertiser.cc similarity index 85% rename from system/vendor_libs/test_vendor_lib/model/controller/le_advertiser.cc rename to tools/rootcanal/model/controller/le_advertiser.cc index 661d7b76e3e..1d80931c1bc 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/le_advertiser.cc +++ b/tools/rootcanal/model/controller/le_advertiser.cc @@ -19,7 +19,7 @@ using namespace bluetooth::hci; using namespace std::literals; -namespace test_vendor_lib { +namespace rootcanal { void LeAdvertiser::Initialize(AddressWithType address, AddressWithType peer_address, LeScanningFilterPolicy filter_policy, @@ -38,14 +38,10 @@ void LeAdvertiser::Initialize(AddressWithType address, } void LeAdvertiser::InitializeExtended( - unsigned advertising_handle, - AddressType address_type, - AddressWithType peer_address, - LeScanningFilterPolicy filter_policy, + unsigned advertising_handle, AddressType address_type, + AddressWithType peer_address, LeScanningFilterPolicy filter_policy, model::packets::AdvertisementType type, - std::chrono::steady_clock::duration interval, - uint8_t tx_power) { - + std::chrono::steady_clock::duration interval, uint8_t tx_power) { advertising_handle_ = advertising_handle; address_ = AddressWithType(address_.GetAddress(), address_type); peer_address_ = peer_address; @@ -97,30 +93,30 @@ void LeAdvertiser::EnableExtended(std::chrono::milliseconds duration_ms) { using Duration = std::chrono::steady_clock::duration; using TimePoint = std::chrono::steady_clock::time_point; - Duration adv_direct_ind_timeout = 1280ms; // 1.28s - Duration adv_direct_ind_interval_low = 10000us; // 10ms - Duration adv_direct_ind_interval_high = 3750us; // 3.75ms + Duration adv_direct_ind_timeout = 1280ms; // 1.28s + Duration adv_direct_ind_interval_low = 10000us; // 10ms + Duration adv_direct_ind_interval_high = 3750us; // 3.75ms Duration duration = duration_ms; TimePoint now = std::chrono::steady_clock::now(); switch (type_) { - // [Vol 6] Part B. 4.4.2.4.3 High duty cycle connectable directed advertising - case model::packets::AdvertisementType::ADV_DIRECT_IND: - duration = duration == 0ms ? - adv_direct_ind_timeout : - std::min(duration, adv_direct_ind_timeout); - interval_ = adv_direct_ind_interval_high; - break; - - // [Vol 6] Part B. 4.4.2.4.2 Low duty cycle connectable directed advertising - case model::packets::AdvertisementType::SCAN_RESPONSE: - interval_ = adv_direct_ind_interval_low; - break; - - // Duration set to parameter, - // interval set by Initialize(). - default: - break; + // [Vol 6] Part B. 4.4.2.4.3 High duty cycle connectable directed + // advertising + case model::packets::AdvertisementType::ADV_DIRECT_IND: + duration = duration == 0ms ? adv_direct_ind_timeout + : std::min(duration, adv_direct_ind_timeout); + interval_ = adv_direct_ind_interval_high; + break; + + // [Vol 6] Part B. 4.4.2.4.2 Low duty cycle connectable directed advertising + case model::packets::AdvertisementType::SCAN_RESPONSE: + interval_ = adv_direct_ind_interval_low; + break; + + // Duration set to parameter, + // interval set by Initialize(). + default: + break; } last_le_advertisement_ = now - interval_; @@ -143,8 +139,8 @@ bool LeAdvertiser::IsConnectable() const { uint8_t LeAdvertiser::GetNumAdvertisingEvents() const { return num_events_; } -std::unique_ptr<bluetooth::hci::EventBuilder> -LeAdvertiser::GetEvent(std::chrono::steady_clock::time_point now) { +std::unique_ptr<bluetooth::hci::EventBuilder> LeAdvertiser::GetEvent( + std::chrono::steady_clock::time_point now) { // Advertiser disabled. if (!enabled_) { return nullptr; @@ -157,8 +153,7 @@ LeAdvertiser::GetEvent(std::chrono::steady_clock::time_point now) { LOG_INFO("Directed Advertising Timeout"); enabled_ = false; return bluetooth::hci::LeConnectionCompleteBuilder::Create( - ErrorCode::ADVERTISING_TIMEOUT, 0, - bluetooth::hci::Role::CENTRAL, + ErrorCode::ADVERTISING_TIMEOUT, 0, bluetooth::hci::Role::CENTRAL, bluetooth::hci::AddressType::PUBLIC_DEVICE_ADDRESS, bluetooth::hci::Address(), 0, 0, 0, bluetooth::hci::ClockAccuracy::PPM_500); @@ -239,4 +234,4 @@ LeAdvertiser::GetScanResponse(bluetooth::hci::Address scanned, } } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/le_advertiser.h b/tools/rootcanal/model/controller/le_advertiser.h similarity index 96% rename from system/vendor_libs/test_vendor_lib/model/controller/le_advertiser.h rename to tools/rootcanal/model/controller/le_advertiser.h index 37f7488b7c4..0b7a92b7916 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/le_advertiser.h +++ b/tools/rootcanal/model/controller/le_advertiser.h @@ -24,7 +24,7 @@ #include "hci/hci_packets.h" #include "packets/link_layer_packets.h" -namespace test_vendor_lib { +namespace rootcanal { // Track a single advertising instance class LeAdvertiser { @@ -79,7 +79,7 @@ class LeAdvertiser { uint8_t GetNumAdvertisingEvents() const; bluetooth::hci::AddressWithType GetAddress() const; -private: + private: bluetooth::hci::AddressWithType address_{}; bluetooth::hci::AddressWithType peer_address_{}; // For directed advertisements @@ -95,8 +95,8 @@ private: uint8_t num_events_{0}; bool extended_{false}; bool enabled_{false}; - bool limited_{false}; // Set if the advertising set has a timeout. + bool limited_{false}; // Set if the advertising set has a timeout. unsigned advertising_handle_{0}; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.cc b/tools/rootcanal/model/controller/link_layer_controller.cc similarity index 96% rename from system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.cc rename to tools/rootcanal/model/controller/link_layer_controller.cc index 2c703742028..e2018aa59c0 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.cc +++ b/tools/rootcanal/model/controller/link_layer_controller.cc @@ -33,7 +33,7 @@ using namespace model::packets; using model::packets::PacketType; using namespace std::literals; -namespace test_vendor_lib { +namespace rootcanal { constexpr uint16_t kNumCommandPackets = 0x01; @@ -208,7 +208,6 @@ ErrorCode LinkLayerController::SendAclToRemote( ErrorCode LinkLayerController::SendScoToRemote( bluetooth::hci::ScoView sco_packet) { - uint16_t handle = sco_packet.GetHandle(); if (!connections_.HasScoHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; @@ -222,7 +221,8 @@ ErrorCode LinkLayerController::SendScoToRemote( std::vector<uint8_t> sco_data_bytes(sco_data.begin(), sco_data.end()); SendLinkLayerPacket(model::packets::ScoBuilder::Create( - source, destination, std::make_unique<bluetooth::packet::RawBuilder>(sco_data_bytes))); + source, destination, + std::make_unique<bluetooth::packet::RawBuilder>(sco_data_bytes))); return ErrorCode::SUCCESS; } @@ -449,15 +449,13 @@ void LinkLayerController::IncomingPacketWithRssi( void LinkLayerController::IncomingAclPacket( model::packets::LinkLayerPacketView incoming) { - auto acl = model::packets::AclView::Create(incoming); ASSERT(acl.IsValid()); auto payload = acl.GetPayload(); std::shared_ptr<std::vector<uint8_t>> payload_bytes = std::make_shared<std::vector<uint8_t>>(payload.begin(), payload.end()); - LOG_INFO("Acl Packet [%d] %s -> %s", - static_cast<int>(payload_bytes->size()), + LOG_INFO("Acl Packet [%d] %s -> %s", static_cast<int>(payload_bytes->size()), incoming.GetSourceAddress().ToString().c_str(), incoming.GetDestinationAddress().ToString().c_str()); @@ -501,13 +499,11 @@ void LinkLayerController::IncomingAclPacket( void LinkLayerController::IncomingScoPacket( model::packets::LinkLayerPacketView incoming) { - - Address source = incoming.GetSourceAddress(); uint16_t sco_handle = connections_.GetScoHandle(source); if (!connections_.HasScoHandle(sco_handle)) { - LOG_INFO("Spurious SCO packet from %s", source.ToString().c_str()); - return; + LOG_INFO("Spurious SCO packet from %s", source.ToString().c_str()); + return; } auto sco = model::packets::ScoView::Create(incoming); @@ -515,8 +511,7 @@ void LinkLayerController::IncomingScoPacket( auto sco_data = sco.GetPayload(); std::vector<uint8_t> sco_data_bytes(sco_data.begin(), sco_data.end()); - LOG_INFO("Sco Packet [%d] %s -> %s", - static_cast<int>(sco_data_bytes.size()), + LOG_INFO("Sco Packet [%d] %s -> %s", static_cast<int>(sco_data_bytes.size()), incoming.GetSourceAddress().ToString().c_str(), incoming.GetDestinationAddress().ToString().c_str()); @@ -1441,7 +1436,6 @@ void LinkLayerController::IncomingLeAdvertisementPacket( void LinkLayerController::IncomingScoConnectionRequest( model::packets::LinkLayerPacketView incoming) { - Address address = incoming.GetSourceAddress(); auto request = model::packets::ScoConnectionRequestView::Create(incoming); ASSERT(request.IsValid()); @@ -1452,41 +1446,39 @@ void LinkLayerController::IncomingScoConnectionRequest( // Automatically reject if connection request was already sent // from the current device. if (connections_.HasPendingScoConnection(address)) { - LOG_INFO("Rejecting eSCO connection request from %s, " - "an eSCO connection already exist with this device", - address.ToString().c_str()); + LOG_INFO( + "Rejecting eSCO connection request from %s, " + "an eSCO connection already exist with this device", + address.ToString().c_str()); SendLinkLayerPacket(model::packets::ScoConnectionResponseBuilder::Create( properties_.GetAddress(), address, - (uint8_t)ErrorCode::SYNCHRONOUS_CONNECTION_LIMIT_EXCEEDED, - 0, 0, 0, 0, 0, 0)); + (uint8_t)ErrorCode::SYNCHRONOUS_CONNECTION_LIMIT_EXCEEDED, 0, 0, 0, 0, + 0, 0)); return; } // Create local connection context. ScoConnectionParameters connection_parameters = { - request.GetTransmitBandwidth(), request.GetReceiveBandwidth(), - request.GetMaxLatency(), request.GetVoiceSetting(), - request.GetRetransmissionEffort(), request.GetPacketType() - }; + request.GetTransmitBandwidth(), request.GetReceiveBandwidth(), + request.GetMaxLatency(), request.GetVoiceSetting(), + request.GetRetransmissionEffort(), request.GetPacketType()}; bool extended = connection_parameters.IsExtended(); - connections_.CreateScoConnection(address, connection_parameters, - extended ? - ScoState::SCO_STATE_SENT_ESCO_CONNECTION_REQUEST : - ScoState::SCO_STATE_SENT_SCO_CONNECTION_REQUEST); + connections_.CreateScoConnection( + address, connection_parameters, + extended ? ScoState::SCO_STATE_SENT_ESCO_CONNECTION_REQUEST + : ScoState::SCO_STATE_SENT_SCO_CONNECTION_REQUEST); // Send connection request event and wait for Accept or Reject command. send_event_(bluetooth::hci::ConnectionRequestBuilder::Create( address, ClassOfDevice(), - extended ? - bluetooth::hci::ConnectionRequestLinkType::ESCO : - bluetooth::hci::ConnectionRequestLinkType::SCO)); + extended ? bluetooth::hci::ConnectionRequestLinkType::ESCO + : bluetooth::hci::ConnectionRequestLinkType::SCO)); } void LinkLayerController::IncomingScoConnectionResponse( model::packets::LinkLayerPacketView incoming) { - Address address = incoming.GetSourceAddress(); auto response = model::packets::ScoConnectionResponseView::Create(incoming); ASSERT(response.IsValid()); @@ -1500,25 +1492,23 @@ void LinkLayerController::IncomingScoConnectionResponse( if (status == ErrorCode::SUCCESS) { bool extended = response.GetExtended(); ScoLinkParameters link_parameters = { - response.GetTransmissionInterval(), - response.GetRetransmissionWindow(), - response.GetRxPacketLength(), - response.GetTxPacketLength(), - response.GetAirMode(), - extended, + response.GetTransmissionInterval(), + response.GetRetransmissionWindow(), + response.GetRxPacketLength(), + response.GetTxPacketLength(), + response.GetAirMode(), + extended, }; connections_.AcceptPendingScoConnection(address, link_parameters); if (is_legacy) { send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( ErrorCode::SUCCESS, connections_.GetScoHandle(address), address, - bluetooth::hci::LinkType::SCO, - bluetooth::hci::Enable::DISABLED)); + bluetooth::hci::LinkType::SCO, bluetooth::hci::Enable::DISABLED)); } else { send_event_(bluetooth::hci::SynchronousConnectionCompleteBuilder::Create( ErrorCode::SUCCESS, connections_.GetScoHandle(address), address, - extended ? - bluetooth::hci::ScoLinkType::ESCO : - bluetooth::hci::ScoLinkType::SCO, + extended ? bluetooth::hci::ScoLinkType::ESCO + : bluetooth::hci::ScoLinkType::SCO, extended ? response.GetTransmissionInterval() : 0, extended ? response.GetRetransmissionWindow() : 0, extended ? response.GetRxPacketLength() : 0, @@ -1529,17 +1519,15 @@ void LinkLayerController::IncomingScoConnectionResponse( connections_.CancelPendingScoConnection(address); if (is_legacy) { send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( - status, 0, address, - bluetooth::hci::LinkType::SCO, + status, 0, address, bluetooth::hci::LinkType::SCO, bluetooth::hci::Enable::DISABLED)); } else { ScoConnectionParameters connection_parameters = connections_.GetScoConnectionParameters(address); send_event_(bluetooth::hci::SynchronousConnectionCompleteBuilder::Create( status, 0, address, - connection_parameters.IsExtended() ? - bluetooth::hci::ScoLinkType::ESCO : - bluetooth::hci::ScoLinkType::SCO, + connection_parameters.IsExtended() ? bluetooth::hci::ScoLinkType::ESCO + : bluetooth::hci::ScoLinkType::SCO, 0, 0, 0, 0, bluetooth::hci::ScoAirMode::TRANSPARENT)); } } @@ -1547,17 +1535,17 @@ void LinkLayerController::IncomingScoConnectionResponse( void LinkLayerController::IncomingScoDisconnect( model::packets::LinkLayerPacketView incoming) { - Address address = incoming.GetSourceAddress(); auto request = model::packets::ScoDisconnectView::Create(incoming); ASSERT(request.IsValid()); auto reason = request.GetReason(); uint16_t handle = connections_.GetScoHandle(address); - LOG_INFO("Received eSCO disconnection request with" - " reason 0x%02x from %s", - static_cast<unsigned>(reason), - incoming.GetSourceAddress().ToString().c_str()); + LOG_INFO( + "Received eSCO disconnection request with" + " reason 0x%02x from %s", + static_cast<unsigned>(reason), + incoming.GetSourceAddress().ToString().c_str()); if (handle != kReservedHandle) { connections_.Disconnect(handle); @@ -2087,7 +2075,6 @@ void LinkLayerController::Close() { void LinkLayerController::LeAdvertising() { steady_clock::time_point now = steady_clock::now(); for (auto& advertiser : advertisers_) { - auto event = advertiser.GetEvent(now); if (event != nullptr) { send_event_(std::move(event)); @@ -2633,8 +2620,8 @@ ErrorCode LinkLayerController::AcceptConnectionRequest(const Address& bd_addr, ScoConnectionParameters connection_parameters = connections_.GetScoConnectionParameters(bd_addr); - if (!connections_.AcceptPendingScoConnection( - bd_addr, connection_parameters)) { + if (!connections_.AcceptPendingScoConnection(bd_addr, + connection_parameters)) { connections_.CancelPendingScoConnection(bd_addr); status = ErrorCode::SCO_INTERVAL_REJECTED; // TODO: proper status code } else { @@ -2646,10 +2633,8 @@ ErrorCode LinkLayerController::AcceptConnectionRequest(const Address& bd_addr, SendLinkLayerPacket(model::packets::ScoConnectionResponseBuilder::Create( properties_.GetAddress(), bd_addr, (uint8_t)status, link_parameters.transmission_interval, - link_parameters.retransmission_window, - link_parameters.rx_packet_length, - link_parameters.tx_packet_length, - link_parameters.air_mode, + link_parameters.retransmission_window, link_parameters.rx_packet_length, + link_parameters.tx_packet_length, link_parameters.air_mode, link_parameters.extended)); // Schedule HCI Connection Complete event. @@ -2735,9 +2720,8 @@ ErrorCode LinkLayerController::CreateConnectionCancel(const Address& addr) { return ErrorCode::SUCCESS; } -void LinkLayerController::SendDisconnectionCompleteEvent( - uint16_t handle, uint8_t reason) -{ +void LinkLayerController::SendDisconnectionCompleteEvent(uint16_t handle, + uint8_t reason) { if (properties_.IsUnmasked(EventCode::DISCONNECTION_COMPLETE)) { ScheduleTask(kShortDelayMs, [this, handle, reason]() { send_event_(bluetooth::hci::DisconnectionCompleteBuilder::Create( @@ -2767,8 +2751,7 @@ ErrorCode LinkLayerController::Disconnect(uint16_t handle, uint8_t reason) { const AddressWithType remote = connections_.GetAddress(handle); if (connections_.GetPhyType(handle) == Phy::Type::BR_EDR) { - LOG_INFO("Disconnecting ACL connection with %s", - remote.ToString().c_str()); + LOG_INFO("Disconnecting ACL connection with %s", remote.ToString().c_str()); uint16_t sco_handle = connections_.GetScoHandle(remote.GetAddress()); if (sco_handle != kReservedHandle) { @@ -2783,8 +2766,7 @@ ErrorCode LinkLayerController::Disconnect(uint16_t handle, uint8_t reason) { properties_.GetAddress(), remote.GetAddress(), reason)); } else { - LOG_INFO("Disconnecting LE connection with %s", - remote.ToString().c_str()); + LOG_INFO("Disconnecting LE connection with %s", remote.ToString().c_str()); SendLeLinkLayerPacket(model::packets::DisconnectBuilder::Create( connections_.GetOwnAddress(handle).GetAddress(), remote.GetAddress(), @@ -3088,13 +3070,9 @@ ErrorCode LinkLayerController::SetLeExtendedAdvertisingParameters( break; } - advertisers_[set].InitializeExtended(set, - own_address_address_type, - peer_address, - scanning_filter_policy, - ad_type, - std::chrono::milliseconds(interval_ms), - tx_power); + advertisers_[set].InitializeExtended( + set, own_address_address_type, peer_address, scanning_filter_policy, + ad_type, std::chrono::milliseconds(interval_ms), tx_power); return ErrorCode::SUCCESS; } @@ -3555,7 +3533,6 @@ uint8_t LinkLayerController::LeReadNumberOfSupportedAdvertisingSets() { ErrorCode LinkLayerController::SetLeExtendedAdvertisingEnable( bluetooth::hci::Enable enable, const std::vector<bluetooth::hci::EnabledSet>& enabled_sets) { - for (const auto& set : enabled_sets) { if (set.advertising_handle_ > advertisers_.size()) { return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; @@ -3725,10 +3702,8 @@ void LinkLayerController::SetPageScanEnable(bool enable) { page_scans_enabled_ = enable; } -ErrorCode LinkLayerController::AddScoConnection( - uint16_t connection_handle, - uint16_t packet_type) -{ +ErrorCode LinkLayerController::AddScoConnection(uint16_t connection_handle, + uint16_t packet_type) { if (!connections_.HasHandle(connection_handle)) { return ErrorCode::UNKNOWN_CONNECTION; } @@ -3742,15 +3717,20 @@ ErrorCode LinkLayerController::AddScoConnection( // Save connection parameters. ScoConnectionParameters connection_parameters = { - 8000, 8000, 0xffff, 0x60 /* 16bit CVSD */, + 8000, + 8000, + 0xffff, + 0x60 /* 16bit CVSD */, (uint8_t)bluetooth::hci::RetransmissionEffort::NO_RETRANSMISSION, - (uint16_t)( - (uint16_t)((packet_type >> 5) & 0x7u) | - (uint16_t)bluetooth::hci::SynchronousPacketTypeBits::NO_2_EV3_ALLOWED | - (uint16_t)bluetooth::hci::SynchronousPacketTypeBits::NO_3_EV3_ALLOWED | - (uint16_t)bluetooth::hci::SynchronousPacketTypeBits::NO_2_EV5_ALLOWED | - (uint16_t)bluetooth::hci::SynchronousPacketTypeBits::NO_3_EV5_ALLOWED) - }; + (uint16_t)((uint16_t)((packet_type >> 5) & 0x7u) | + (uint16_t)bluetooth::hci::SynchronousPacketTypeBits:: + NO_2_EV3_ALLOWED | + (uint16_t)bluetooth::hci::SynchronousPacketTypeBits:: + NO_3_EV3_ALLOWED | + (uint16_t)bluetooth::hci::SynchronousPacketTypeBits:: + NO_2_EV5_ALLOWED | + (uint16_t)bluetooth::hci::SynchronousPacketTypeBits:: + NO_3_EV5_ALLOWED)}; connections_.CreateScoConnection( connections_.GetAddress(connection_handle).GetAddress(), connection_parameters, SCO_STATE_PENDING, true); @@ -3760,22 +3740,16 @@ ErrorCode LinkLayerController::AddScoConnection( properties_.GetAddress(), bd_addr, connection_parameters.transmit_bandwidth, connection_parameters.receive_bandwidth, - connection_parameters.max_latency, - connection_parameters.voice_setting, + connection_parameters.max_latency, connection_parameters.voice_setting, connection_parameters.retransmission_effort, connection_parameters.packet_type)); return ErrorCode::SUCCESS; } ErrorCode LinkLayerController::SetupSynchronousConnection( - uint16_t connection_handle, - uint32_t transmit_bandwidth, - uint32_t receive_bandwidth, - uint16_t max_latency, - uint16_t voice_setting, - uint8_t retransmission_effort, - uint16_t packet_types) -{ + uint16_t connection_handle, uint32_t transmit_bandwidth, + uint32_t receive_bandwidth, uint16_t max_latency, uint16_t voice_setting, + uint8_t retransmission_effort, uint16_t packet_types) { if (!connections_.HasHandle(connection_handle)) { return ErrorCode::UNKNOWN_CONNECTION; } @@ -3792,36 +3766,28 @@ ErrorCode LinkLayerController::SetupSynchronousConnection( // Save connection parameters. ScoConnectionParameters connection_parameters = { - transmit_bandwidth, receive_bandwidth, max_latency, - voice_setting, retransmission_effort, packet_types - }; + transmit_bandwidth, receive_bandwidth, max_latency, + voice_setting, retransmission_effort, packet_types}; connections_.CreateScoConnection( connections_.GetAddress(connection_handle).GetAddress(), connection_parameters, SCO_STATE_PENDING); // Send eSCO connection request to peer. SendLinkLayerPacket(model::packets::ScoConnectionRequestBuilder::Create( - properties_.GetAddress(), bd_addr, - transmit_bandwidth, receive_bandwidth, max_latency, - voice_setting, retransmission_effort, packet_types)); + properties_.GetAddress(), bd_addr, transmit_bandwidth, receive_bandwidth, + max_latency, voice_setting, retransmission_effort, packet_types)); return ErrorCode::SUCCESS; } ErrorCode LinkLayerController::AcceptSynchronousConnection( - Address bd_addr, - uint32_t transmit_bandwidth, - uint32_t receive_bandwidth, - uint16_t max_latency, - uint16_t voice_setting, - uint8_t retransmission_effort, + Address bd_addr, uint32_t transmit_bandwidth, uint32_t receive_bandwidth, + uint16_t max_latency, uint16_t voice_setting, uint8_t retransmission_effort, uint16_t packet_types) { - LOG_INFO("Accepting eSCO connection request from %s", bd_addr.ToString().c_str()); if (!connections_.HasPendingScoConnection(bd_addr)) { - LOG_INFO("No pending eSCO connection for %s", - bd_addr.ToString().c_str()); + LOG_INFO("No pending eSCO connection for %s", bd_addr.ToString().c_str()); return ErrorCode::COMMAND_DISALLOWED; } @@ -3829,11 +3795,11 @@ ErrorCode LinkLayerController::AcceptSynchronousConnection( uint16_t sco_handle = 0; ScoLinkParameters link_parameters = {}; ScoConnectionParameters connection_parameters = { - transmit_bandwidth, receive_bandwidth, max_latency, voice_setting, - retransmission_effort, packet_types - }; + transmit_bandwidth, receive_bandwidth, max_latency, + voice_setting, retransmission_effort, packet_types}; - if (!connections_.AcceptPendingScoConnection(bd_addr, connection_parameters)) { + if (!connections_.AcceptPendingScoConnection(bd_addr, + connection_parameters)) { connections_.CancelPendingScoConnection(bd_addr); status = ErrorCode::STATUS_UNKNOWN; // TODO: proper status code } else { @@ -3845,39 +3811,29 @@ ErrorCode LinkLayerController::AcceptSynchronousConnection( SendLinkLayerPacket(model::packets::ScoConnectionResponseBuilder::Create( properties_.GetAddress(), bd_addr, (uint8_t)status, link_parameters.transmission_interval, - link_parameters.retransmission_window, - link_parameters.rx_packet_length, - link_parameters.tx_packet_length, - link_parameters.air_mode, + link_parameters.retransmission_window, link_parameters.rx_packet_length, + link_parameters.tx_packet_length, link_parameters.air_mode, link_parameters.extended)); // Schedule HCI Synchronous Connection Complete event. - ScheduleTask(kShortDelayMs, - [this, status, sco_handle, bd_addr, link_parameters]() { - send_event_( - bluetooth::hci::SynchronousConnectionCompleteBuilder::Create( - ErrorCode(status), sco_handle, bd_addr, - link_parameters.extended ? - bluetooth::hci::ScoLinkType::ESCO : - bluetooth::hci::ScoLinkType::SCO, - link_parameters.extended ? - link_parameters.transmission_interval : 0, - link_parameters.extended ? - link_parameters.retransmission_window : 0, - link_parameters.extended ? - link_parameters.rx_packet_length : 0, - link_parameters.extended ? - link_parameters.tx_packet_length : 0, - bluetooth::hci::ScoAirMode(link_parameters.air_mode))); + ScheduleTask(kShortDelayMs, [this, status, sco_handle, bd_addr, + link_parameters]() { + send_event_(bluetooth::hci::SynchronousConnectionCompleteBuilder::Create( + ErrorCode(status), sco_handle, bd_addr, + link_parameters.extended ? bluetooth::hci::ScoLinkType::ESCO + : bluetooth::hci::ScoLinkType::SCO, + link_parameters.extended ? link_parameters.transmission_interval : 0, + link_parameters.extended ? link_parameters.retransmission_window : 0, + link_parameters.extended ? link_parameters.rx_packet_length : 0, + link_parameters.extended ? link_parameters.tx_packet_length : 0, + bluetooth::hci::ScoAirMode(link_parameters.air_mode))); }); return ErrorCode::SUCCESS; } -ErrorCode LinkLayerController::RejectSynchronousConnection( - Address bd_addr, - uint16_t reason) { - +ErrorCode LinkLayerController::RejectSynchronousConnection(Address bd_addr, + uint16_t reason) { LOG_INFO("Rejecting eSCO connection request from %s", bd_addr.ToString().c_str()); @@ -3897,11 +3853,11 @@ ErrorCode LinkLayerController::RejectSynchronousConnection( // Schedule HCI Synchronous Connection Complete event. ScheduleTask(kShortDelayMs, [this, reason, bd_addr]() { send_event_(bluetooth::hci::SynchronousConnectionCompleteBuilder::Create( - ErrorCode(reason), 0, bd_addr, bluetooth::hci::ScoLinkType::ESCO, - 0, 0, 0, 0, bluetooth::hci::ScoAirMode::TRANSPARENT)); + ErrorCode(reason), 0, bd_addr, bluetooth::hci::ScoLinkType::ESCO, 0, 0, + 0, 0, bluetooth::hci::ScoAirMode::TRANSPARENT)); }); return ErrorCode::SUCCESS; } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.h b/tools/rootcanal/model/controller/link_layer_controller.h similarity index 93% rename from system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.h rename to tools/rootcanal/model/controller/link_layer_controller.h index 7a9a10f2dfd..4bfc5e81ef5 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.h +++ b/tools/rootcanal/model/controller/link_layer_controller.h @@ -26,7 +26,7 @@ #include "packets/link_layer_packets.h" #include "security_manager.h" -namespace test_vendor_lib { +namespace rootcanal { using ::bluetooth::hci::Address; using ::bluetooth::hci::ErrorCode; @@ -36,7 +36,8 @@ class LinkLayerController { public: static constexpr size_t kIrkSize = 16; - LinkLayerController(const DeviceProperties& properties) : properties_(properties) {} + LinkLayerController(const DeviceProperties& properties) + : properties_(properties) {} ErrorCode SendCommandToRemoteByAddress( OpCode opcode, bluetooth::packet::PacketView<true> args, const Address& remote); @@ -48,7 +49,8 @@ class LinkLayerController { ErrorCode SendAclToRemote(bluetooth::hci::AclView acl_packet); void StartSimplePairing(const Address& address); - void AuthenticateRemoteStage1(const Address& address, PairingType pairing_type); + void AuthenticateRemoteStage1(const Address& address, + PairingType pairing_type); void AuthenticateRemoteStage2(const Address& address); void SaveKeyAndAuthenticate(uint8_t key_type, const Address& peer); ErrorCode LinkKeyRequestReply(const Address& address, @@ -78,7 +80,8 @@ class LinkLayerController { ErrorCode SendKeypressNotification( const Address& peer, bluetooth::hci::KeypressNotificationType notification_type); - void HandleSetConnectionEncryption(const Address& address, uint16_t handle, uint8_t encryption_enable); + void HandleSetConnectionEncryption(const Address& address, uint16_t handle, + uint8_t encryption_enable); ErrorCode SetConnectionEncryption(uint16_t handle, uint8_t encryption_enable); void HandleAuthenticationRequest(const Address& address, uint16_t handle); ErrorCode AuthenticationRequested(uint16_t handle); @@ -106,7 +109,8 @@ class LinkLayerController { void Close(); - AsyncTaskId ScheduleTask(std::chrono::milliseconds delay_ms, const TaskCallback& task); + AsyncTaskId ScheduleTask(std::chrono::milliseconds delay_ms, + const TaskCallback& task); void CancelScheduledTask(AsyncTaskId task); @@ -134,10 +138,12 @@ class LinkLayerController { // Set the callbacks for scheduling tasks. void RegisterTaskScheduler( - std::function<AsyncTaskId(std::chrono::milliseconds, const TaskCallback&)> event_scheduler); + std::function<AsyncTaskId(std::chrono::milliseconds, const TaskCallback&)> + event_scheduler); void RegisterPeriodicTaskScheduler( - std::function<AsyncTaskId(std::chrono::milliseconds, std::chrono::milliseconds, const TaskCallback&)> + std::function<AsyncTaskId(std::chrono::milliseconds, + std::chrono::milliseconds, const TaskCallback&)> periodic_event_scheduler); void RegisterTaskCancel(std::function<void(AsyncTaskId)> cancel); @@ -261,9 +267,7 @@ class LinkLayerController { void SetLeScanEnable(bluetooth::hci::OpCode enabling_opcode) { le_scan_enable_ = enabling_opcode; } - void SetLeScanType(uint8_t le_scan_type) { - le_scan_type_ = le_scan_type; - } + void SetLeScanType(uint8_t le_scan_type) { le_scan_type_ = le_scan_type; } void SetLeScanInterval(uint16_t le_scan_interval) { le_scan_interval_ = le_scan_interval; } @@ -352,28 +356,16 @@ class LinkLayerController { void ReadLocalOobData(); void ReadLocalOobExtendedData(); - ErrorCode AddScoConnection( - uint16_t connection_handle, - uint16_t packet_type); + ErrorCode AddScoConnection(uint16_t connection_handle, uint16_t packet_type); ErrorCode SetupSynchronousConnection( - uint16_t connection_handle, - uint32_t transmit_bandwidth, - uint32_t receive_bandwidth, - uint16_t max_latency, - uint16_t voice_setting, - uint8_t retransmission_effort, - uint16_t packet_types); + uint16_t connection_handle, uint32_t transmit_bandwidth, + uint32_t receive_bandwidth, uint16_t max_latency, uint16_t voice_setting, + uint8_t retransmission_effort, uint16_t packet_types); ErrorCode AcceptSynchronousConnection( - Address bd_addr, - uint32_t transmit_bandwidth, - uint32_t receive_bandwidth, - uint16_t max_latency, - uint16_t voice_setting, - uint8_t retransmission_effort, - uint16_t packet_types); - ErrorCode RejectSynchronousConnection( - Address bd_addr, - uint16_t reason); + Address bd_addr, uint32_t transmit_bandwidth, uint32_t receive_bandwidth, + uint16_t max_latency, uint16_t voice_setting, + uint8_t retransmission_effort, uint16_t packet_types); + ErrorCode RejectSynchronousConnection(Address bd_addr, uint16_t reason); void HandleIso(bluetooth::hci::IsoView iso); @@ -455,8 +447,7 @@ class LinkLayerController { void IncomingRemoteNameRequestResponse( model::packets::LinkLayerPacketView packet); - void IncomingScoConnectionRequest( - model::packets::LinkLayerPacketView packet); + void IncomingScoConnectionRequest(model::packets::LinkLayerPacketView packet); void IncomingScoConnectionResponse( model::packets::LinkLayerPacketView packet); void IncomingScoDisconnect(model::packets::LinkLayerPacketView packet); @@ -473,8 +464,10 @@ class LinkLayerController { std::chrono::milliseconds timer_period_ = std::chrono::milliseconds(100); // Callbacks to schedule tasks. - std::function<AsyncTaskId(std::chrono::milliseconds, const TaskCallback&)> schedule_task_; - std::function<AsyncTaskId(std::chrono::milliseconds, std::chrono::milliseconds, const TaskCallback&)> + std::function<AsyncTaskId(std::chrono::milliseconds, const TaskCallback&)> + schedule_task_; + std::function<AsyncTaskId(std::chrono::milliseconds, + std::chrono::milliseconds, const TaskCallback&)> schedule_periodic_task_; std::function<void(AsyncTaskId)> cancel_task_; @@ -545,4 +538,4 @@ class LinkLayerController { bool inquiry_scans_enabled_{false}; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/sco_connection.cc b/tools/rootcanal/model/controller/sco_connection.cc similarity index 74% rename from system/vendor_libs/test_vendor_lib/model/controller/sco_connection.cc rename to tools/rootcanal/model/controller/sco_connection.cc index 24a805ec41e..2b73b585095 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/sco_connection.cc +++ b/tools/rootcanal/model/controller/sco_connection.cc @@ -14,36 +14,34 @@ * limitations under the License. */ -#include <vector> +#include "sco_connection.h" #include <hci/hci_packets.h> #include <os/log.h> -#include "sco_connection.h" +#include <vector> -using namespace test_vendor_lib; +using namespace rootcanal; using namespace bluetooth::hci; bool ScoConnectionParameters::IsExtended() { - uint16_t legacy = - (uint16_t)SynchronousPacketTypeBits::HV1_ALLOWED | - (uint16_t)SynchronousPacketTypeBits::HV2_ALLOWED | - (uint16_t)SynchronousPacketTypeBits::HV3_ALLOWED; - uint16_t edr = - (uint16_t)SynchronousPacketTypeBits::NO_2_EV3_ALLOWED | - (uint16_t)SynchronousPacketTypeBits::NO_3_EV3_ALLOWED | - (uint16_t)SynchronousPacketTypeBits::NO_2_EV5_ALLOWED | - (uint16_t)SynchronousPacketTypeBits::NO_3_EV5_ALLOWED; + uint16_t legacy = (uint16_t)SynchronousPacketTypeBits::HV1_ALLOWED | + (uint16_t)SynchronousPacketTypeBits::HV2_ALLOWED | + (uint16_t)SynchronousPacketTypeBits::HV3_ALLOWED; + uint16_t edr = (uint16_t)SynchronousPacketTypeBits::NO_2_EV3_ALLOWED | + (uint16_t)SynchronousPacketTypeBits::NO_3_EV3_ALLOWED | + (uint16_t)SynchronousPacketTypeBits::NO_2_EV5_ALLOWED | + (uint16_t)SynchronousPacketTypeBits::NO_3_EV5_ALLOWED; return ((packet_type ^ edr) & ~legacy) != 0; } std::optional<ScoLinkParameters> ScoConnectionParameters::GetLinkParameters() { // Coding conversion. uint8_t air_coding_to_air_mode[] = { - 0x02, // CVSD - 0x00, // u-law - 0x01, // A-law - 0x03, // transparent data + 0x02, // CVSD + 0x00, // u-law + 0x01, // A-law + 0x03, // transparent data }; // Prioritize eSCO connections. @@ -56,7 +54,7 @@ std::optional<ScoLinkParameters> ScoConnectionParameters::GetLinkParameters() { }; std::vector<Packet> accepted_packets; - accepted_packets.push_back(Packet(0, 1)); // POLL/NULL + accepted_packets.push_back(Packet(0, 1)); // POLL/NULL if (packet_type & (uint16_t)SynchronousPacketTypeBits::EV3_ALLOWED) accepted_packets.push_back(Packet(30, 1)); @@ -64,13 +62,17 @@ std::optional<ScoLinkParameters> ScoConnectionParameters::GetLinkParameters() { accepted_packets.push_back(Packet(120, 3)); if (packet_type & (uint16_t)SynchronousPacketTypeBits::EV5_ALLOWED) accepted_packets.push_back(Packet(180, 3)); - if ((packet_type & (uint16_t)SynchronousPacketTypeBits::NO_2_EV3_ALLOWED) == 0) + if ((packet_type & (uint16_t)SynchronousPacketTypeBits::NO_2_EV3_ALLOWED) == + 0) accepted_packets.push_back(Packet(60, 1)); - if ((packet_type & (uint16_t)SynchronousPacketTypeBits::NO_3_EV3_ALLOWED) == 0) + if ((packet_type & (uint16_t)SynchronousPacketTypeBits::NO_3_EV3_ALLOWED) == + 0) accepted_packets.push_back(Packet(360, 3)); - if ((packet_type & (uint16_t)SynchronousPacketTypeBits::NO_2_EV5_ALLOWED) == 0) + if ((packet_type & (uint16_t)SynchronousPacketTypeBits::NO_2_EV5_ALLOWED) == + 0) accepted_packets.push_back(Packet(90, 1)); - if ((packet_type & (uint16_t)SynchronousPacketTypeBits::NO_3_EV5_ALLOWED) == 0) + if ((packet_type & (uint16_t)SynchronousPacketTypeBits::NO_3_EV5_ALLOWED) == + 0) accepted_packets.push_back(Packet(540, 3)); // Ignore empty bandwidths for now. @@ -86,22 +88,21 @@ std::optional<ScoLinkParameters> ScoConnectionParameters::GetLinkParameters() { // Explore all packet combinations, select the valid one // with smallest actual bandwidth usage. for (auto tx : accepted_packets) { - if (tx.length == 0) - continue; + if (tx.length == 0) continue; unsigned tx_max_interval = (1600 * tx.length) / transmit_bandwidth; for (auto rx : accepted_packets) { - if (rx.length == 0) - continue; + if (rx.length == 0) continue; - LOG_INFO("Testing combination %u/%u : %u/%u", - tx.length, tx.slots, rx.length, rx.slots); + LOG_INFO("Testing combination %u/%u : %u/%u", tx.length, tx.slots, + rx.length, rx.slots); unsigned rx_max_interval = (1600 * rx.length) / receive_bandwidth; // Choose the best interval satisfying both. - unsigned transmission_interval = std::min(tx_max_interval, rx_max_interval); + unsigned transmission_interval = + std::min(tx_max_interval, rx_max_interval); transmission_interval -= transmission_interval % 2; transmission_interval = std::min(transmission_interval, 254u); @@ -109,17 +110,22 @@ std::optional<ScoLinkParameters> ScoConnectionParameters::GetLinkParameters() { // Compute retransmission window. unsigned retransmission_window = - retransmission_effort == (uint8_t)RetransmissionEffort::NO_RETRANSMISSION ? 0 : - retransmission_effort == (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_POWER ? - rx.slots + tx.slots : - retransmission_effort == (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_LINK_QUALITY ? - 2 * (rx.slots + tx.slots) : 0; + retransmission_effort == + (uint8_t)RetransmissionEffort::NO_RETRANSMISSION + ? 0 + : retransmission_effort == + (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_POWER + ? rx.slots + tx.slots + : retransmission_effort == + (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_LINK_QUALITY + ? 2 * (rx.slots + tx.slots) + : 0; LOG_INFO("Retransmission window: %u slots", retransmission_window); // Compute transmission window and validate latency. - unsigned transmission_window = tx.slots + rx.slots + - retransmission_window; + unsigned transmission_window = + tx.slots + rx.slots + retransmission_window; // Validate window. if (transmission_window > transmission_interval) @@ -138,7 +144,7 @@ std::optional<ScoLinkParameters> ScoConnectionParameters::GetLinkParameters() { // We got a valid configuration. // Evaluate the actual bandwidth usage. double bandwidth_usage = - (double)transmission_window / (double)transmission_interval; + (double)transmission_window / (double)transmission_interval; if (bandwidth_usage <= best_bandwidth_usage) { LOG_INFO("Valid combination!"); @@ -153,7 +159,8 @@ std::optional<ScoLinkParameters> ScoConnectionParameters::GetLinkParameters() { best_parameters = { (uint8_t)transmission_interval, (uint8_t)retransmission_window, - rx_packet_length, tx_packet_length, + rx_packet_length, + tx_packet_length, air_coding_to_air_mode[air_coding], true, }; @@ -168,8 +175,10 @@ std::optional<ScoLinkParameters> ScoConnectionParameters::GetLinkParameters() { // Parameter negotiation for SCO connections: // Check packet types and validate bandwidth and latency requirements. - if (retransmission_effort == (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_POWER || - retransmission_effort == (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_LINK_QUALITY) { + if (retransmission_effort == + (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_POWER || + retransmission_effort == + (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_LINK_QUALITY) { LOG_WARN("SCO Retransmission effort must be None or Don't care"); return {}; } @@ -199,15 +208,18 @@ std::optional<ScoLinkParameters> ScoConnectionParameters::GetLinkParameters() { } best_parameters = { - transmission_interval, 0, packet_length, packet_length, + transmission_interval, + 0, + packet_length, + packet_length, air_coding_to_air_mode[air_coding], false, }; return best_parameters; } -bool ScoConnection::NegotiateLinkParameters(ScoConnectionParameters const &peer) { - +bool ScoConnection::NegotiateLinkParameters( + ScoConnectionParameters const& peer) { if (peer.transmit_bandwidth != 0xffff && peer.transmit_bandwidth != parameters_.receive_bandwidth) { LOG_WARN("Transmit bandwidth requirements cannot be met"); @@ -243,20 +255,25 @@ bool ScoConnection::NegotiateLinkParameters(ScoConnectionParameters const &peer) } uint16_t max_latency = - peer.max_latency == 0xffff ? parameters_.max_latency : - parameters_.max_latency == 0xffff ? peer.max_latency : - std::min(peer.max_latency, parameters_.max_latency); + peer.max_latency == 0xffff ? parameters_.max_latency + : parameters_.max_latency == 0xffff + ? peer.max_latency + : std::min(peer.max_latency, parameters_.max_latency); uint8_t retransmission_effort; if (state_ == SCO_STATE_SENT_SCO_CONNECTION_REQUEST) retransmission_effort = (uint8_t)RetransmissionEffort::NO_RETRANSMISSION; else if (peer.retransmission_effort == parameters_.retransmission_effort || - peer.retransmission_effort == (uint8_t)RetransmissionEffort::DO_NOT_CARE) + peer.retransmission_effort == + (uint8_t)RetransmissionEffort::DO_NOT_CARE) retransmission_effort = parameters_.retransmission_effort; - else if (parameters_.retransmission_effort == (uint8_t)RetransmissionEffort::DO_NOT_CARE) + else if (parameters_.retransmission_effort == + (uint8_t)RetransmissionEffort::DO_NOT_CARE) retransmission_effort = peer.retransmission_effort; - else if (peer.retransmission_effort == (uint8_t)RetransmissionEffort::NO_RETRANSMISSION || - parameters_.retransmission_effort == (uint8_t)RetransmissionEffort::NO_RETRANSMISSION) { + else if (peer.retransmission_effort == + (uint8_t)RetransmissionEffort::NO_RETRANSMISSION || + parameters_.retransmission_effort == + (uint8_t)RetransmissionEffort::NO_RETRANSMISSION) { LOG_WARN("Retransmission effort requirements cannot be met"); LOG_WARN("Remote retransmission effort: 0x%02x", static_cast<unsigned>(parameters_.retransmission_effort)); @@ -268,9 +285,12 @@ bool ScoConnection::NegotiateLinkParameters(ScoConnectionParameters const &peer) } ScoConnectionParameters negotiated_parameters = { - parameters_.transmit_bandwidth, parameters_.receive_bandwidth, - max_latency, parameters_.voice_setting, retransmission_effort, packet_type - }; + parameters_.transmit_bandwidth, + parameters_.receive_bandwidth, + max_latency, + parameters_.voice_setting, + retransmission_effort, + packet_type}; auto link_parameters = negotiated_parameters.GetLinkParameters(); if (link_parameters.has_value()) { diff --git a/system/vendor_libs/test_vendor_lib/model/controller/sco_connection.h b/tools/rootcanal/model/controller/sco_connection.h similarity index 85% rename from system/vendor_libs/test_vendor_lib/model/controller/sco_connection.h rename to tools/rootcanal/model/controller/sco_connection.h index 8f9de9b64a1..eae162999da 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/sco_connection.h +++ b/tools/rootcanal/model/controller/sco_connection.h @@ -21,7 +21,7 @@ #include "hci/address.h" -namespace test_vendor_lib { +namespace rootcanal { using ::bluetooth::hci::Address; @@ -53,7 +53,7 @@ struct ScoLinkParameters { struct ScoConnectionParameters { uint32_t transmit_bandwidth; uint32_t receive_bandwidth; - uint16_t max_latency; // 0-3 reserved, 0xFFFF = don't care + uint16_t max_latency; // 0-3 reserved, 0xFFFF = don't care uint16_t voice_setting; uint8_t retransmission_effort; uint16_t packet_type; @@ -76,10 +76,13 @@ enum ScoState { class ScoConnection { public: - ScoConnection(Address address, ScoConnectionParameters const ¶meters, + ScoConnection(Address address, ScoConnectionParameters const& parameters, ScoState state, bool legacy = false) - : address_(address), parameters_(parameters), link_parameters_(), - state_(state), legacy_(legacy) {} + : address_(address), + parameters_(parameters), + link_parameters_(), + state_(state), + legacy_(legacy) {} virtual ~ScoConnection() = default; @@ -91,17 +94,15 @@ class ScoConnection { ScoConnectionParameters GetConnectionParameters() const { return parameters_; } - ScoLinkParameters GetLinkParameters() const { - return link_parameters_; - } - void SetLinkParameters(ScoLinkParameters const ¶meters) { + ScoLinkParameters GetLinkParameters() const { return link_parameters_; } + void SetLinkParameters(ScoLinkParameters const& parameters) { link_parameters_ = parameters; } // Negotiate the connection parameters. // Update the local connection parameters with negotiated values. // Return true if the negotiation was successful, false otherwise. - bool NegotiateLinkParameters(ScoConnectionParameters const &peer); + bool NegotiateLinkParameters(ScoConnectionParameters const& peer); private: Address address_; @@ -115,4 +116,4 @@ class ScoConnection { bool legacy_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/security_manager.cc b/tools/rootcanal/model/controller/security_manager.cc similarity index 77% rename from system/vendor_libs/test_vendor_lib/model/controller/security_manager.cc rename to tools/rootcanal/model/controller/security_manager.cc index e3f89e1ea88..72ba38af38c 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/security_manager.cc +++ b/tools/rootcanal/model/controller/security_manager.cc @@ -20,7 +20,7 @@ using std::vector; -namespace test_vendor_lib { +namespace rootcanal { uint16_t SecurityManager::DeleteAllKeys() { uint16_t size = key_store_.size(); @@ -36,9 +36,7 @@ uint16_t SecurityManager::DeleteKey(const Address& addr) { return count; } -uint16_t SecurityManager::ReadAllKeys() const { - return key_store_.size(); -} +uint16_t SecurityManager::ReadAllKeys() const { return key_store_.size(); } uint16_t SecurityManager::ReadKey(const Address& addr) const { return key_store_.count(addr.ToString()); @@ -74,51 +72,55 @@ void SecurityManager::AuthenticationRequestFinished() { authenticating_ = false; } -bool SecurityManager::AuthenticationInProgress() { - return authenticating_; -} +bool SecurityManager::AuthenticationInProgress() { return authenticating_; } bool SecurityManager::IsInitiator() { return initiator_; } -uint16_t SecurityManager::GetAuthenticationHandle() { - return current_handle_; -} +uint16_t SecurityManager::GetAuthenticationHandle() { return current_handle_; } -Address SecurityManager::GetAuthenticationAddress() { - return peer_address_; -} +Address SecurityManager::GetAuthenticationAddress() { return peer_address_; } -void SecurityManager::SetPeerIoCapability(const Address& addr, uint8_t io_capability, uint8_t oob_present_flag, +void SecurityManager::SetPeerIoCapability(const Address& addr, + uint8_t io_capability, + uint8_t oob_present_flag, uint8_t authentication_requirements) { ASSERT(addr == peer_address_); peer_capabilities_valid_ = true; - if (io_capability <= static_cast<uint8_t>(IoCapabilityType::NO_INPUT_NO_OUTPUT)) { + if (io_capability <= + static_cast<uint8_t>(IoCapabilityType::NO_INPUT_NO_OUTPUT)) { peer_io_capability_ = static_cast<IoCapabilityType>(io_capability); } else { peer_io_capability_ = IoCapabilityType::INVALID; peer_capabilities_valid_ = false; } peer_oob_present_flag_ = oob_present_flag; - if (authentication_requirements <= static_cast<uint8_t>(AuthenticationType::GENERAL_BONDING_MITM)) { - peer_authentication_requirements_ = static_cast<AuthenticationType>(authentication_requirements); + if (authentication_requirements <= + static_cast<uint8_t>(AuthenticationType::GENERAL_BONDING_MITM)) { + peer_authentication_requirements_ = + static_cast<AuthenticationType>(authentication_requirements); } else { peer_authentication_requirements_ = AuthenticationType::INVALID; peer_capabilities_valid_ = false; } } -void SecurityManager::SetLocalIoCapability(const Address& peer, uint8_t io_capability, uint8_t oob_present_flag, - uint8_t authentication_requirements) { +void SecurityManager::SetLocalIoCapability( + const Address& peer, uint8_t io_capability, uint8_t oob_present_flag, + uint8_t authentication_requirements) { ASSERT(peer == peer_address_); - ASSERT_LOG(io_capability <= static_cast<uint8_t>(IoCapabilityType::NO_INPUT_NO_OUTPUT), "io_capability = %d", - static_cast<int>(io_capability)); + ASSERT_LOG(io_capability <= + static_cast<uint8_t>(IoCapabilityType::NO_INPUT_NO_OUTPUT), + "io_capability = %d", static_cast<int>(io_capability)); ASSERT_LOG(oob_present_flag <= 3, "oob_present_flag = %hhx ", oob_present_flag); - ASSERT_LOG(authentication_requirements <= static_cast<uint8_t>(AuthenticationType::GENERAL_BONDING_MITM), - "authentication_requirements = %d", static_cast<int>(authentication_requirements)); + ASSERT_LOG(authentication_requirements <= + static_cast<uint8_t>(AuthenticationType::GENERAL_BONDING_MITM), + "authentication_requirements = %d", + static_cast<int>(authentication_requirements)); host_io_capability_ = static_cast<IoCapabilityType>(io_capability); host_oob_present_flag_ = oob_present_flag; - host_authentication_requirements_ = static_cast<AuthenticationType>(authentication_requirements); + host_authentication_requirements_ = + static_cast<AuthenticationType>(authentication_requirements); host_capabilities_valid_ = true; } @@ -131,12 +133,18 @@ PairingType SecurityManager::GetSimplePairingType() { if (!host_capabilities_valid_ || !peer_capabilities_valid_) { return PairingType::INVALID; } - bool host_requires_mitm = (host_authentication_requirements_ == AuthenticationType::NO_BONDING_MITM) || - (host_authentication_requirements_ == AuthenticationType::DEDICATED_BONDING_MITM) || - (host_authentication_requirements_ == AuthenticationType::GENERAL_BONDING_MITM); - bool peer_requires_mitm = (peer_authentication_requirements_ == AuthenticationType::NO_BONDING_MITM) || - (peer_authentication_requirements_ == AuthenticationType::DEDICATED_BONDING_MITM) || - (peer_authentication_requirements_ == AuthenticationType::GENERAL_BONDING_MITM); + bool host_requires_mitm = (host_authentication_requirements_ == + AuthenticationType::NO_BONDING_MITM) || + (host_authentication_requirements_ == + AuthenticationType::DEDICATED_BONDING_MITM) || + (host_authentication_requirements_ == + AuthenticationType::GENERAL_BONDING_MITM); + bool peer_requires_mitm = (peer_authentication_requirements_ == + AuthenticationType::NO_BONDING_MITM) || + (peer_authentication_requirements_ == + AuthenticationType::DEDICATED_BONDING_MITM) || + (peer_authentication_requirements_ == + AuthenticationType::GENERAL_BONDING_MITM); if (peer_oob_present_flag_ != 0 || host_oob_present_flag_ != 0) { if (host_oob_present_flag_ == 0) { return PairingType::PEER_HAS_OUT_OF_BAND; @@ -232,4 +240,4 @@ bool SecurityManager::GetRemotePinResponseReceived(const Address& peer) { bool SecurityManager::PinCompare() { return host_pin_received_ && peer_pin_received_ && peer_pin_ == host_pin_; } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/controller/security_manager.h b/tools/rootcanal/model/controller/security_manager.h similarity index 95% rename from system/vendor_libs/test_vendor_lib/model/controller/security_manager.h rename to tools/rootcanal/model/controller/security_manager.h index 01328de18d4..2b6874423a4 100644 --- a/system/vendor_libs/test_vendor_lib/model/controller/security_manager.h +++ b/tools/rootcanal/model/controller/security_manager.h @@ -24,7 +24,7 @@ #include "hci/address.h" -namespace test_vendor_lib { +namespace rootcanal { using ::bluetooth::hci::Address; @@ -89,9 +89,11 @@ class SecurityManager { bool GetRemotePinResponseReceived(const Address& peer); bool PinCompare(); - void SetPeerIoCapability(const Address& addr, uint8_t io_capability, uint8_t oob_present_flag, + void SetPeerIoCapability(const Address& addr, uint8_t io_capability, + uint8_t oob_present_flag, uint8_t authentication_requirements); - void SetLocalIoCapability(const Address& peer, uint8_t io_capability, uint8_t oob_present_flag, + void SetLocalIoCapability(const Address& peer, uint8_t io_capability, + uint8_t oob_present_flag, uint8_t authentication_requirements); PairingType GetSimplePairingType(); @@ -125,4 +127,4 @@ class SecurityManager { bool initiator_{false}; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/beacon.cc b/tools/rootcanal/model/devices/beacon.cc similarity index 81% rename from system/vendor_libs/test_vendor_lib/model/devices/beacon.cc rename to tools/rootcanal/model/devices/beacon.cc index c4ac4bdb94a..e18a091821e 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/beacon.cc +++ b/tools/rootcanal/model/devices/beacon.cc @@ -20,29 +20,31 @@ using std::vector; -namespace test_vendor_lib { +namespace rootcanal { bool Beacon::registered_ = DeviceBoutique::Register("beacon", &Beacon::Create); Beacon::Beacon() { advertising_interval_ms_ = std::chrono::milliseconds(1280); properties_.SetLeAdvertisementType(0x03 /* NON_CONNECT */); - properties_.SetLeAdvertisement({0x0F, // Length - 0x09 /* TYPE_NAME_CMPL */, 'g', 'D', 'e', 'v', 'i', 'c', 'e', '-', 'b', 'e', 'a', 'c', - 'o', 'n', - 0x02, // Length - 0x01 /* TYPE_FLAG */, 0x4 /* BREDR_NOT_SPT */ | 0x2 /* GEN_DISC_FLAG */}); + properties_.SetLeAdvertisement( + {0x0F, // Length + 0x09 /* TYPE_NAME_CMPL */, 'g', 'D', 'e', 'v', 'i', 'c', 'e', '-', 'b', + 'e', 'a', 'c', 'o', 'n', + 0x02, // Length + 0x01 /* TYPE_FLAG */, + 0x4 /* BREDR_NOT_SPT */ | 0x2 /* GEN_DISC_FLAG */}); properties_.SetLeScanResponse({0x05, // Length - 0x08 /* TYPE_NAME_SHORT */, 'b', 'e', 'a', 'c'}); + 0x08 /* TYPE_NAME_SHORT */, 'b', 'e', 'a', + 'c'}); } -std::string Beacon::GetTypeString() const { - return "beacon"; -} +std::string Beacon::GetTypeString() const { return "beacon"; } std::string Beacon::ToString() const { - std::string dev = GetTypeString() + "@" + properties_.GetLeAddress().ToString(); + std::string dev = + GetTypeString() + "@" + properties_.GetLeAddress().ToString(); return dev; } @@ -89,4 +91,4 @@ void Beacon::IncomingPacket(model::packets::LinkLayerPacketView packet) { } } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/beacon.h b/tools/rootcanal/model/devices/beacon.h similarity index 90% rename from system/vendor_libs/test_vendor_lib/model/devices/beacon.h rename to tools/rootcanal/model/devices/beacon.h index 87bb2286162..c0fc4ed1dcf 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/beacon.h +++ b/tools/rootcanal/model/devices/beacon.h @@ -21,7 +21,7 @@ #include "device.h" -namespace test_vendor_lib { +namespace rootcanal { // A simple device that advertises periodically and is not connectable. class Beacon : public Device { @@ -29,9 +29,7 @@ class Beacon : public Device { Beacon(); virtual ~Beacon() = default; - static std::shared_ptr<Device> Create() { - return std::make_shared<Beacon>(); - } + static std::shared_ptr<Device> Create() { return std::make_shared<Beacon>(); } // Return a string representation of the type of device. virtual std::string GetTypeString() const override; @@ -51,4 +49,4 @@ class Beacon : public Device { static bool registered_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/beacon_swarm.cc b/tools/rootcanal/model/devices/beacon_swarm.cc similarity index 90% rename from system/vendor_libs/test_vendor_lib/model/devices/beacon_swarm.cc rename to tools/rootcanal/model/devices/beacon_swarm.cc index 17e62ad5437..ac2cea61e83 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/beacon_swarm.cc +++ b/tools/rootcanal/model/devices/beacon_swarm.cc @@ -20,8 +20,9 @@ using std::vector; -namespace test_vendor_lib { -bool BeaconSwarm::registered_ = DeviceBoutique::Register("beacon_swarm", &BeaconSwarm::Create); +namespace rootcanal { +bool BeaconSwarm::registered_ = + DeviceBoutique::Register("beacon_swarm", &BeaconSwarm::Create); BeaconSwarm::BeaconSwarm() { advertising_interval_ms_ = std::chrono::milliseconds(1280); @@ -55,7 +56,8 @@ BeaconSwarm::BeaconSwarm() { }); properties_.SetLeScanResponse({0x06, // Length - 0x08 /* TYPE_NAME_SHORT */, 'c', 'b', 'e', 'a', 'c'}); + 0x08 /* TYPE_NAME_SHORT */, 'c', 'b', 'e', 'a', + 'c'}); } void BeaconSwarm::Initialize(const vector<std::string>& args) { @@ -77,4 +79,4 @@ void BeaconSwarm::TimerTick() { Beacon::TimerTick(); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/beacon_swarm.h b/tools/rootcanal/model/devices/beacon_swarm.h similarity index 89% rename from system/vendor_libs/test_vendor_lib/model/devices/beacon_swarm.h rename to tools/rootcanal/model/devices/beacon_swarm.h index e1bfd759d4a..118e047c6c0 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/beacon_swarm.h +++ b/tools/rootcanal/model/devices/beacon_swarm.h @@ -21,7 +21,7 @@ #include "beacon.h" -namespace test_vendor_lib { +namespace rootcanal { // Pretend to be a lot of beacons by changing the advertising address. class BeaconSwarm : public Beacon { @@ -34,9 +34,7 @@ class BeaconSwarm : public Beacon { } // Return a string representation of the type of device. - virtual std::string GetTypeString() const override { - return "beacon_swarm"; - } + virtual std::string GetTypeString() const override { return "beacon_swarm"; } // Set the address and advertising interval from string args. virtual void Initialize(const std::vector<std::string>& args) override; @@ -47,4 +45,4 @@ class BeaconSwarm : public Beacon { static bool registered_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/broken_adv.cc b/tools/rootcanal/model/devices/broken_adv.cc similarity index 88% rename from system/vendor_libs/test_vendor_lib/model/devices/broken_adv.cc rename to tools/rootcanal/model/devices/broken_adv.cc index 27dc2d105d6..2de20170676 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/broken_adv.cc +++ b/tools/rootcanal/model/devices/broken_adv.cc @@ -20,9 +20,10 @@ using std::vector; -namespace test_vendor_lib { +namespace rootcanal { -bool BrokenAdv::registered_ = DeviceBoutique::Register("broken_adv", &BrokenAdv::Create); +bool BrokenAdv::registered_ = + DeviceBoutique::Register("broken_adv", &BrokenAdv::Create); BrokenAdv::BrokenAdv() { advertising_interval_ms_ = std::chrono::milliseconds(1280); @@ -33,13 +34,15 @@ BrokenAdv::BrokenAdv() { 0x4 | 0x2, // BREDR_NOT_SPT | GEN_DISC_FLAG 0x13, // Length 0x09, // TYPE_NAME_CMPL - 'g', 'D', 'e', 'v', 'i', 'c', 'e', '-', 'b', 'r', 'o', 'k', 'e', 'n', '_', 'a', 'd', 'v', + 'g', 'D', 'e', 'v', 'i', 'c', 'e', '-', 'b', + 'r', 'o', 'k', 'e', 'n', '_', 'a', 'd', 'v', }; properties_.SetLeAdvertisement(constant_adv_data_); properties_.SetLeScanResponse({0x0b, // Length 0x08, // TYPE_NAME_SHORT - 'b', 'r', 'o', 'k', 'e', 'n', 'n', 'e', 's', 's'}); + 'b', 'r', 'o', 'k', 'e', 'n', 'n', 'e', 's', + 's'}); properties_.SetExtendedInquiryData({0x07, // Length 0x09, // TYPE_NAME_COMPLETE @@ -120,7 +123,8 @@ static void RandomizeAdvertisement(vector<uint8_t>& ad, size_t max) { void BrokenAdv::UpdateAdvertisement() { std::vector<uint8_t> adv_data; - for (size_t i = 0; i < constant_adv_data_.size(); i++) adv_data.push_back(constant_adv_data_[i]); + for (size_t i = 0; i < constant_adv_data_.size(); i++) + adv_data.push_back(constant_adv_data_[i]); RandomizeAdvertisement(adv_data, 31 - adv_data.size()); properties_.SetLeAdvertisement(adv_data); @@ -136,8 +140,8 @@ void BrokenAdv::UpdateAdvertisement() { } std::string BrokenAdv::ToString() const { - std::string str = - Device::ToString() + std::string(": Interval = ") + std::to_string(advertising_interval_ms_.count()); + std::string str = Device::ToString() + std::string(": Interval = ") + + std::to_string(advertising_interval_ms_.count()); return str; } @@ -155,4 +159,4 @@ void BrokenAdv::TimerTick() { UpdateAdvertisement(); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/broken_adv.h b/tools/rootcanal/model/devices/broken_adv.h similarity index 91% rename from system/vendor_libs/test_vendor_lib/model/devices/broken_adv.h rename to tools/rootcanal/model/devices/broken_adv.h index 2431676c5dd..34c736900f7 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/broken_adv.h +++ b/tools/rootcanal/model/devices/broken_adv.h @@ -21,7 +21,7 @@ #include "device.h" -namespace test_vendor_lib { +namespace rootcanal { class BrokenAdv : public Device { public: @@ -36,9 +36,7 @@ class BrokenAdv : public Device { virtual void Initialize(const std::vector<std::string>& args) override; // Return a string representation of the type of device. - virtual std::string GetTypeString() const override { - return "broken_adv"; - } + virtual std::string GetTypeString() const override { return "broken_adv"; } // Return the string representation of the device. virtual std::string ToString() const override; @@ -58,4 +56,4 @@ class BrokenAdv : public Device { static bool registered_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/car_kit.cc b/tools/rootcanal/model/devices/car_kit.cc similarity index 92% rename from system/vendor_libs/test_vendor_lib/model/devices/car_kit.cc rename to tools/rootcanal/model/devices/car_kit.cc index 7a0be0d2765..ba2c43e07d3 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/car_kit.cc +++ b/tools/rootcanal/model/devices/car_kit.cc @@ -21,7 +21,7 @@ using std::vector; -namespace test_vendor_lib { +namespace rootcanal { bool CarKit::registered_ = DeviceBoutique::Register("car_kit", &CarKit::Create); const std::string kCarKitPropertiesFile = @@ -51,7 +51,8 @@ CarKit::CarKit() : Device(kCarKitPropertiesFile) { properties_.SetExtendedInquiryData({ 16, // length 9, // Type: Device Name - 'g', 'D', 'e', 'v', 'i', 'c', 'e', '-', 'c', 'a', 'r', '_', 'k', 'i', 't', + 'g', 'D', 'e', 'v', 'i', 'c', 'e', '-', + 'c', 'a', 'r', '_', 'k', 'i', 't', 7, // length 3, // Type: 16-bit UUIDs 0x0e, // AVRC @@ -92,13 +93,11 @@ void CarKit::Initialize(const vector<std::string>& args) { properties_.SetClockOffset(std::stoi(args[2])); } -void CarKit::TimerTick() { - link_layer_controller_.TimerTick(); -} +void CarKit::TimerTick() { link_layer_controller_.TimerTick(); } void CarKit::IncomingPacket(model::packets::LinkLayerPacketView packet) { LOG_WARN("Incoming Packet"); link_layer_controller_.IncomingPacket(packet); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/car_kit.h b/tools/rootcanal/model/devices/car_kit.h similarity index 84% rename from system/vendor_libs/test_vendor_lib/model/devices/car_kit.h rename to tools/rootcanal/model/devices/car_kit.h index 32fd4311dea..8b4295dc8d7 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/car_kit.h +++ b/tools/rootcanal/model/devices/car_kit.h @@ -23,24 +23,20 @@ #include "hci/hci_packets.h" #include "model/controller/link_layer_controller.h" -namespace test_vendor_lib { +namespace rootcanal { class CarKit : public Device { public: CarKit(); ~CarKit() = default; - static std::shared_ptr<CarKit> Create() { - return std::make_shared<CarKit>(); - } + static std::shared_ptr<CarKit> Create() { return std::make_shared<CarKit>(); } // Initialize the device based on the values of |args|. virtual void Initialize(const std::vector<std::string>& args) override; // Return a string representation of the type of device. - virtual std::string GetTypeString() const override { - return "car_kit"; - } + virtual std::string GetTypeString() const override { return "car_kit"; } virtual void IncomingPacket( model::packets::LinkLayerPacketView packet) override; @@ -52,4 +48,4 @@ class CarKit : public Device { static bool registered_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/classic.cc b/tools/rootcanal/model/devices/classic.cc similarity index 87% rename from system/vendor_libs/test_vendor_lib/model/devices/classic.cc rename to tools/rootcanal/model/devices/classic.cc index def9517cf75..732a8266f72 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/classic.cc +++ b/tools/rootcanal/model/devices/classic.cc @@ -15,13 +15,15 @@ */ #include "classic.h" + #include "model/setup/device_boutique.h" using std::vector; -namespace test_vendor_lib { +namespace rootcanal { -bool Classic::registered_ = DeviceBoutique::Register("classic", &Classic::Create); +bool Classic::registered_ = + DeviceBoutique::Register("classic", &Classic::Create); Classic::Classic() { advertising_interval_ms_ = std::chrono::milliseconds(0); @@ -29,7 +31,8 @@ Classic::Classic() { properties_.SetExtendedInquiryData({0x10, // Length 0x09, // TYPE_NAME_CMPL - 'g', 'D', 'e', 'v', 'i', 'c', 'e', '-', 'c', 'l', 'a', 's', 's', 'i', 'c', + 'g', 'D', 'e', 'v', 'i', 'c', 'e', '-', + 'c', 'l', 'a', 's', 's', 'i', 'c', '\0'}); // End of data properties_.SetPageScanRepetitionMode(0); properties_.SetExtendedFeatures(0x87593F9bFE8FFEFF, 0); @@ -48,4 +51,4 @@ void Classic::Initialize(const vector<std::string>& args) { properties_.SetClockOffset(std::stoi(args[2])); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/classic.h b/tools/rootcanal/model/devices/classic.h similarity index 88% rename from system/vendor_libs/test_vendor_lib/model/devices/classic.h rename to tools/rootcanal/model/devices/classic.h index 16b466b79d2..861c7cf8e40 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/classic.h +++ b/tools/rootcanal/model/devices/classic.h @@ -21,7 +21,7 @@ #include "device.h" -namespace test_vendor_lib { +namespace rootcanal { class Classic : public Device { public: @@ -36,12 +36,10 @@ class Classic : public Device { virtual void Initialize(const std::vector<std::string>& args) override; // Return a string representation of the type of device. - virtual std::string GetTypeString() const override { - return "classic"; - } + virtual std::string GetTypeString() const override { return "classic"; } private: static bool registered_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/device.cc b/tools/rootcanal/model/devices/device.cc similarity index 91% rename from system/vendor_libs/test_vendor_lib/model/devices/device.cc rename to tools/rootcanal/model/devices/device.cc index b39cc178edf..3bcf30b94f7 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/device.cc +++ b/tools/rootcanal/model/devices/device.cc @@ -14,11 +14,11 @@ * limitations under the License. */ -#include <vector> - #include "device.h" -namespace test_vendor_lib { +#include <vector> + +namespace rootcanal { std::string Device::ToString() const { std::string dev = GetTypeString() + "@" + properties_.GetAddress().ToString(); @@ -52,7 +52,8 @@ void Device::UnregisterPhyLayer(Phy::Type phy_type, uint32_t factory_id) { bool Device::IsAdvertisementAvailable() const { return (advertising_interval_ms_ > std::chrono::milliseconds(0)) && - (std::chrono::steady_clock::now() >= last_advertisement_ + advertising_interval_ms_); + (std::chrono::steady_clock::now() >= + last_advertisement_ + advertising_interval_ms_); } void Device::SendLinkLayerPacket( @@ -74,18 +75,18 @@ void Device::SendLinkLayerPacket(model::packets::LinkLayerPacketView to_send, } } -void Device::Close() { +void Device::Close() { if (close_callback_) { close_callback_(); } } void Device::RegisterCloseCallback(std::function<void()> close_callback) { - close_callback_ = close_callback; + close_callback_ = close_callback; } void Device::SetAddress(Address) { LOG_INFO("%s does not implement %s", GetTypeString().c_str(), __func__); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/device.h b/tools/rootcanal/model/devices/device.h similarity index 93% rename from system/vendor_libs/test_vendor_lib/model/devices/device.h rename to tools/rootcanal/model/devices/device.h index f75e7e6b86e..f57f11f9a43 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/device.h +++ b/tools/rootcanal/model/devices/device.h @@ -25,10 +25,9 @@ #include "hci/address.h" #include "model/devices/device_properties.h" #include "model/setup/phy_layer.h" - #include "packets/link_layer_packets.h" -namespace test_vendor_lib { +namespace rootcanal { using ::bluetooth::hci::Address; @@ -37,7 +36,8 @@ using ::bluetooth::hci::Address; class Device { public: Device(const std::string properties_filename = "") - : last_advertisement_(std::chrono::steady_clock::now()), properties_(properties_filename) {} + : last_advertisement_(std::chrono::steady_clock::now()), + properties_(properties_filename) {} virtual ~Device() = default; // Initialize the device based on the values of |args|. @@ -53,9 +53,7 @@ class Device { // May need to be extended to check peer address & type, and other // connection parameters. // Return true if the device accepts the connection request. - virtual bool LeConnect() { - return false; - } + virtual bool LeConnect() { return false; } // Set the device's Bluetooth address. virtual void SetAddress(Address address); @@ -85,7 +83,6 @@ class Device { virtual void SendLinkLayerPacket(model::packets::LinkLayerPacketView packet, Phy::Type phy_type); - virtual void Close(); void RegisterCloseCallback(std::function<void()>); @@ -108,4 +105,4 @@ class Device { std::function<void()> close_callback_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/device_properties.cc b/tools/rootcanal/model/devices/device_properties.cc similarity index 98% rename from system/vendor_libs/test_vendor_lib/model/devices/device_properties.cc rename to tools/rootcanal/model/devices/device_properties.cc index 7e92f896428..24acbb22c23 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/device_properties.cc +++ b/tools/rootcanal/model/devices/device_properties.cc @@ -19,7 +19,6 @@ #include <memory> #include "json/json.h" - #include "os/log.h" #include "osi/include/osi.h" @@ -45,7 +44,7 @@ static void ParseHex64(Json::Value value, uint64_t* field) { } } -namespace test_vendor_lib { +namespace rootcanal { DeviceProperties::DeviceProperties(const std::string& file_name) : acl_data_packet_size_(1024), @@ -123,4 +122,4 @@ DeviceProperties::DeviceProperties(const std::string& file_name) &le_resolving_list_ignore_reasons_); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/device_properties.h b/tools/rootcanal/model/devices/device_properties.h similarity index 84% rename from system/vendor_libs/test_vendor_lib/model/devices/device_properties.h rename to tools/rootcanal/model/devices/device_properties.h index 10b67e6fbe1..c1942cb2a77 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/device_properties.h +++ b/tools/rootcanal/model/devices/device_properties.h @@ -25,7 +25,7 @@ #include "hci/hci_packets.h" #include "os/log.h" -namespace test_vendor_lib { +namespace rootcanal { using ::bluetooth::hci::Address; using ::bluetooth::hci::ClassOfDevice; @@ -123,9 +123,7 @@ class DeviceProperties { } // Specification Version 4.2, Volume 2, Part E, Section 7.4.3 - uint64_t GetSupportedFeatures() const { - return extended_features_[0]; - } + uint64_t GetSupportedFeatures() const { return extended_features_[0]; } void SetExtendedFeatures(uint64_t features, uint8_t page_number) { ASSERT(page_number < extended_features_.size()); @@ -172,13 +170,9 @@ class DeviceProperties { } // Specification Version 4.2, Volume 2, Part E, Section 7.4.5 - uint16_t GetAclDataPacketSize() const { - return acl_data_packet_size_; - } + uint16_t GetAclDataPacketSize() const { return acl_data_packet_size_; } - uint8_t GetSynchronousDataPacketSize() const { - return sco_data_packet_size_; - } + uint8_t GetSynchronousDataPacketSize() const { return sco_data_packet_size_; } uint8_t GetEncryptionKeySize() const { return encryption_key_size_; } @@ -196,29 +190,21 @@ class DeviceProperties { connection_accept_timeout_ = connection_accept_timeout; } - uint16_t GetTotalNumAclDataPackets() const { - return num_acl_data_packets_; - } + uint16_t GetTotalNumAclDataPackets() const { return num_acl_data_packets_; } uint16_t GetTotalNumSynchronousDataPackets() const { return num_sco_data_packets_; } - bool GetSynchronousFlowControl() const { - return sco_flow_control_; - } + bool GetSynchronousFlowControl() const { return sco_flow_control_; } void SetSynchronousFlowControl(bool sco_flow_control) { sco_flow_control_ = sco_flow_control; } - const Address& GetAddress() const { - return address_; - } + const Address& GetAddress() const { return address_; } - void SetAddress(const Address& address) { - address_ = address; - } + void SetAddress(const Address& address) { address_ = address; } // Specification Version 4.2, Volume 2, Part E, Section 7.4.8 const std::vector<uint8_t>& GetSupportedCodecs() const { @@ -229,37 +215,23 @@ class DeviceProperties { return vendor_specific_codecs_; } - uint8_t GetVersion() const { - return version_; - } + uint8_t GetVersion() const { return version_; } - uint16_t GetRevision() const { - return revision_; - } + uint16_t GetRevision() const { return revision_; } - uint8_t GetLmpPalVersion() const { - return lmp_pal_version_; - } + uint8_t GetLmpPalVersion() const { return lmp_pal_version_; } - uint16_t GetLmpPalSubversion() const { - return lmp_pal_subversion_; - } + uint16_t GetLmpPalSubversion() const { return lmp_pal_subversion_; } - uint16_t GetManufacturerName() const { - return manufacturer_name_; - } + uint16_t GetManufacturerName() const { return manufacturer_name_; } - uint8_t GetAuthenticationEnable() const { - return authentication_enable_; - } + uint8_t GetAuthenticationEnable() const { return authentication_enable_; } void SetAuthenticationEnable(uint8_t enable) { authentication_enable_ = enable; } - ClassOfDevice GetClassOfDevice() const { - return class_of_device_; - } + ClassOfDevice GetClassOfDevice() const { return class_of_device_; } void SetClassOfDevice(uint8_t b0, uint8_t b1, uint8_t b2) { class_of_device_.cod[0] = b0; @@ -298,13 +270,9 @@ class DeviceProperties { page_scan_repetition_mode_ = mode; } - uint16_t GetClockOffset() const { - return clock_offset_; - } + uint16_t GetClockOffset() const { return clock_offset_; } - void SetClockOffset(uint16_t offset) { - clock_offset_ = offset; - } + void SetClockOffset(uint16_t offset) { clock_offset_ = offset; } uint64_t GetEventMask() const { return event_mask_; } @@ -316,25 +284,15 @@ class DeviceProperties { } // Low-Energy functions - const Address& GetLeAddress() const { - return le_address_; - } + const Address& GetLeAddress() const { return le_address_; } - void SetLeAddress(const Address& address) { - le_address_ = address; - } + void SetLeAddress(const Address& address) { le_address_ = address; } - uint8_t GetLeAddressType() const { - return le_address_type_; - } + uint8_t GetLeAddressType() const { return le_address_type_; } - void SetLeAddressType(uint8_t addr_type) { - le_address_type_ = addr_type; - } + void SetLeAddressType(uint8_t addr_type) { le_address_type_ = addr_type; } - uint8_t GetLeAdvertisementType() const { - return le_advertisement_type_; - } + uint8_t GetLeAdvertisementType() const { return le_advertisement_type_; } uint16_t GetLeAdvertisingIntervalMin() const { return le_advertising_interval_min_; @@ -364,9 +322,11 @@ class DeviceProperties { return le_advertising_filter_policy_; } - void SetLeAdvertisingParameters(uint16_t interval_min, uint16_t interval_max, uint8_t ad_type, - uint8_t own_address_type, uint8_t peer_address_type, Address peer_address, - uint8_t channel_map, uint8_t filter_policy) { + void SetLeAdvertisingParameters(uint16_t interval_min, uint16_t interval_max, + uint8_t ad_type, uint8_t own_address_type, + uint8_t peer_address_type, + Address peer_address, uint8_t channel_map, + uint8_t filter_policy) { le_advertisement_type_ = ad_type; le_advertising_interval_min_ = interval_min; le_advertising_interval_max_ = interval_max; @@ -398,26 +358,16 @@ class DeviceProperties { } // Specification Version 4.2, Volume 2, Part E, Section 7.8.2 - uint16_t GetLeDataPacketLength() const { - return le_data_packet_length_; - } + uint16_t GetLeDataPacketLength() const { return le_data_packet_length_; } - uint8_t GetTotalNumLeDataPackets() const { - return num_le_data_packets_; - } + uint8_t GetTotalNumLeDataPackets() const { return num_le_data_packets_; } - uint16_t GetIsoDataPacketLength() const { - return iso_data_packet_length_; - } + uint16_t GetIsoDataPacketLength() const { return iso_data_packet_length_; } - uint8_t GetTotalNumIsoDataPackets() const { - return num_iso_data_packets_; - } + uint8_t GetTotalNumIsoDataPackets() const { return num_iso_data_packets_; } // Specification Version 4.2, Volume 2, Part E, Section 7.8.3 - uint64_t GetLeSupportedFeatures() const { - return le_supported_features_; - } + uint64_t GetLeSupportedFeatures() const { return le_supported_features_; } // Specification Version 5.2, Volume 4, Part E, Section 7.8.6 int8_t GetLeAdvertisingPhysicalChannelTxPower() const { @@ -440,9 +390,7 @@ class DeviceProperties { uint8_t GetLeConnectListSize() const { return le_connect_list_size_; } // Specification Version 4.2, Volume 2, Part E, Section 7.8.27 - uint64_t GetLeSupportedStates() const { - return le_supported_states_; - } + uint64_t GetLeSupportedStates() const { return le_supported_states_; } // Specification Version 4.2, Volume 2, Part E, Section 7.8.41 uint8_t GetLeResolvingListSize() const { return le_resolving_list_size_; } @@ -460,9 +408,7 @@ class DeviceProperties { } // Vendor-specific commands - const std::vector<uint8_t>& GetLeVendorCap() const { - return le_vendor_cap_; - } + const std::vector<uint8_t>& GetLeVendorCap() const { return le_vendor_cap_; } private: // Classic @@ -527,4 +473,4 @@ class DeviceProperties { uint8_t num_iso_data_packets_{12}; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/h4_data_channel_packetizer.cc b/tools/rootcanal/model/devices/h4_data_channel_packetizer.cc similarity index 95% rename from system/vendor_libs/test_vendor_lib/model/devices/h4_data_channel_packetizer.cc rename to tools/rootcanal/model/devices/h4_data_channel_packetizer.cc index 8dee4b78c0d..f089b5d7d53 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/h4_data_channel_packetizer.cc +++ b/tools/rootcanal/model/devices/h4_data_channel_packetizer.cc @@ -16,8 +16,9 @@ #include "h4_data_channel_packetizer.h" -#include <string.h> // for strerror, size_t -#include <unistd.h> // for ssize_t +#include <string.h> // for strerror, size_t +#include <unistd.h> // for ssize_t + #include <cerrno> // for errno, EAGAIN, ECONNRESET #include <cstdint> // for uint8_t #include <functional> // for function @@ -30,7 +31,7 @@ #include "net/async_data_channel.h" // for AsyncDataChannel #include "os/log.h" // for LOG_ERROR, LOG_ALWAYS_FATAL -namespace test_vendor_lib { +namespace rootcanal { H4DataChannelPacketizer::H4DataChannelPacketizer( std::shared_ptr<AsyncDataChannel> socket, PacketReadCallback command_cb, @@ -91,4 +92,4 @@ void H4DataChannelPacketizer::OnDataReady( h4_parser_.Consume(buffer.data(), bytes_read); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/h4_data_channel_packetizer.h b/tools/rootcanal/model/devices/h4_data_channel_packetizer.h similarity index 96% rename from system/vendor_libs/test_vendor_lib/model/devices/h4_data_channel_packetizer.h rename to tools/rootcanal/model/devices/h4_data_channel_packetizer.h index d0f8edaea1d..819f037b1f1 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/h4_data_channel_packetizer.h +++ b/tools/rootcanal/model/devices/h4_data_channel_packetizer.h @@ -25,7 +25,7 @@ #include "hci_protocol.h" // for PacketReadCallback, AsyncDataChannel, HciProtocol #include "net/async_data_channel.h" // for AsyncDataChannel -namespace test_vendor_lib { +namespace rootcanal { using android::net::AsyncDataChannel; @@ -52,4 +52,4 @@ class H4DataChannelPacketizer : public HciProtocol { bool disconnected_{false}; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/h4_packetizer.cc b/tools/rootcanal/model/devices/h4_packetizer.cc similarity index 94% rename from system/vendor_libs/test_vendor_lib/model/devices/h4_packetizer.cc rename to tools/rootcanal/model/devices/h4_packetizer.cc index 7cdec69b702..0394d610020 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/h4_packetizer.cc +++ b/tools/rootcanal/model/devices/h4_packetizer.cc @@ -16,16 +16,17 @@ #include "h4_packetizer.h" -#include <cerrno> #include <dlfcn.h> #include <fcntl.h> #include <sys/uio.h> #include <unistd.h> +#include <cerrno> + #include "os/log.h" #include "osi/include/osi.h" -namespace test_vendor_lib { +namespace rootcanal { H4Packetizer::H4Packetizer(int fd, PacketReadCallback command_cb, PacketReadCallback event_cb, @@ -37,7 +38,8 @@ H4Packetizer::H4Packetizer(int fd, PacketReadCallback command_cb, disconnect_cb_(std::move(disconnect_cb)) {} size_t H4Packetizer::Send(uint8_t type, const uint8_t* data, size_t length) { - struct iovec iov[] = {{&type, sizeof(type)}, {const_cast<uint8_t*>(data), length}}; + struct iovec iov[] = {{&type, sizeof(type)}, + {const_cast<uint8_t*>(data), length}}; ssize_t ret = 0; do { OSI_NO_INTR(ret = writev(uart_fd_, iov, sizeof(iov) / sizeof(iov[0]))); @@ -52,7 +54,6 @@ size_t H4Packetizer::Send(uint8_t type, const uint8_t* data, size_t length) { return ret; } - void H4Packetizer::OnDataReady(int fd) { if (disconnected_) return; ssize_t bytes_to_read = h4_parser_.BytesRequested(); @@ -82,4 +83,4 @@ void H4Packetizer::OnDataReady(int fd) { h4_parser_.Consume(buffer.data(), bytes_read); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/h4_packetizer.h b/tools/rootcanal/model/devices/h4_packetizer.h similarity index 95% rename from system/vendor_libs/test_vendor_lib/model/devices/h4_packetizer.h rename to tools/rootcanal/model/devices/h4_packetizer.h index 440dcd3fb1c..9c65a666c29 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/h4_packetizer.h +++ b/tools/rootcanal/model/devices/h4_packetizer.h @@ -22,7 +22,7 @@ #include "h4_parser.h" #include "hci_protocol.h" -namespace test_vendor_lib { +namespace rootcanal { // A socket based H4Packetizer. Call OnDataReady whenever // data can be read from file descriptor fd. @@ -47,4 +47,4 @@ class H4Packetizer : public HciProtocol { bool disconnected_{false}; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/h4_parser.cc b/tools/rootcanal/model/devices/h4_parser.cc similarity index 98% rename from system/vendor_libs/test_vendor_lib/model/devices/h4_parser.cc rename to tools/rootcanal/model/devices/h4_parser.cc index 17b3b33ba10..fa9fecf04b3 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/h4_parser.cc +++ b/tools/rootcanal/model/devices/h4_parser.cc @@ -16,7 +16,8 @@ #include "model/devices/h4_parser.h" // for H4Parser, PacketType, H4Pars... -#include <stddef.h> // for size_t +#include <stddef.h> // for size_t + #include <cstdint> // for uint8_t, int32_t #include <functional> // for function #include <utility> // for move @@ -25,7 +26,7 @@ #include "model/devices/hci_protocol.h" // for PacketReadCallback #include "os/log.h" // for LOG_ALWAYS_FATAL, LOG_INFO -namespace test_vendor_lib { +namespace rootcanal { void H4Parser::Reset() { state_ = HCI_TYPE; @@ -170,4 +171,4 @@ bool H4Parser::Consume(uint8_t* buffer, int32_t bytes_read) { } return true; } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/h4_parser.h b/tools/rootcanal/model/devices/h4_parser.h similarity index 92% rename from system/vendor_libs/test_vendor_lib/model/devices/h4_parser.h rename to tools/rootcanal/model/devices/h4_parser.h index 6f2f79e3742..688692409fa 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/h4_parser.h +++ b/tools/rootcanal/model/devices/h4_parser.h @@ -16,7 +16,8 @@ #pragma once -#include <stddef.h> // for size_t +#include <stddef.h> // for size_t + #include <cstdint> // for uint8_t, int32_t #include <functional> // for function #include <ostream> // for operator<<, ostream @@ -24,7 +25,7 @@ #include "model/devices/hci_protocol.h" // for PacketReadCallback -namespace test_vendor_lib { +namespace rootcanal { using HciPacketReadyCallback = std::function<void(void)>; using ClientDisconnectCallback = std::function<void()>; @@ -112,11 +113,10 @@ class H4Parser { inline std::ostream& operator<<(std::ostream& os, H4Parser::State const& state_) { - os << (state_ == H4Parser::State::HCI_TYPE - ? "HCI_TYPE" - : state_ == H4Parser::State::HCI_PREAMBLE ? "HCI_PREAMBLE" - : "HCI_PAYLOAD"); + os << (state_ == H4Parser::State::HCI_TYPE ? "HCI_TYPE" + : state_ == H4Parser::State::HCI_PREAMBLE ? "HCI_PREAMBLE" + : "HCI_PAYLOAD"); return os; } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/hci_protocol.cc b/tools/rootcanal/model/devices/hci_protocol.cc similarity index 95% rename from system/vendor_libs/test_vendor_lib/model/devices/hci_protocol.cc rename to tools/rootcanal/model/devices/hci_protocol.cc index 89dc51a5730..6a9b4744c08 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/hci_protocol.cc +++ b/tools/rootcanal/model/devices/hci_protocol.cc @@ -23,7 +23,7 @@ #include "os/log.h" -namespace test_vendor_lib { +namespace rootcanal { size_t HciProtocol::WriteSafely(AsyncDataChannel* socket, const uint8_t* data, size_t length) { @@ -49,4 +49,4 @@ size_t HciProtocol::WriteSafely(AsyncDataChannel* socket, const uint8_t* data, return transmitted_length; } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/hci_protocol.h b/tools/rootcanal/model/devices/hci_protocol.h similarity index 95% rename from system/vendor_libs/test_vendor_lib/model/devices/hci_protocol.h rename to tools/rootcanal/model/devices/hci_protocol.h index 67402cc1284..b13f82069b7 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/hci_protocol.h +++ b/tools/rootcanal/model/devices/hci_protocol.h @@ -21,7 +21,7 @@ #include "net/async_data_channel.h" -namespace test_vendor_lib { +namespace rootcanal { using PacketReadCallback = std::function<void(const std::vector<uint8_t>&)>; using android::net::AsyncDataChannel; @@ -40,4 +40,4 @@ class HciProtocol { size_t length); }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/hci_socket_device.cc b/tools/rootcanal/model/devices/hci_socket_device.cc similarity index 97% rename from system/vendor_libs/test_vendor_lib/model/devices/hci_socket_device.cc rename to tools/rootcanal/model/devices/hci_socket_device.cc index 1a0bcb5031b..83bf5e2cae1 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/hci_socket_device.cc +++ b/tools/rootcanal/model/devices/hci_socket_device.cc @@ -24,7 +24,7 @@ using std::vector; -namespace test_vendor_lib { +namespace rootcanal { HciSocketDevice::HciSocketDevice(std::shared_ptr<AsyncDataChannel> socket, const std::string& properties_filename) @@ -133,12 +133,11 @@ void HciSocketDevice::SendHci( h4_.Send(type, packet->data(), packet->size()); } -void HciSocketDevice::Close() { +void HciSocketDevice::Close() { if (socket_) { socket_->Close(); } DualModeController::Close(); } - -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/hci_socket_device.h b/tools/rootcanal/model/devices/hci_socket_device.h similarity index 94% rename from system/vendor_libs/test_vendor_lib/model/devices/hci_socket_device.h rename to tools/rootcanal/model/devices/hci_socket_device.h index 81a37528b87..19324e8382e 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/hci_socket_device.h +++ b/tools/rootcanal/model/devices/hci_socket_device.h @@ -27,7 +27,7 @@ #include "model/devices/hci_protocol.h" // for PacketReadCallback #include "net/async_data_channel.h" // for AsyncDataChannel -namespace test_vendor_lib { +namespace rootcanal { using android::net::AsyncDataChannel; @@ -43,9 +43,7 @@ class HciSocketDevice : public DualModeController { return std::make_shared<HciSocketDevice>(socket, properties_filename); } - std::string GetTypeString() const override { - return "hci_socket_device"; - } + std::string GetTypeString() const override { return "hci_socket_device"; } void TimerTick() override; @@ -65,4 +63,4 @@ class HciSocketDevice : public DualModeController { [] {}}; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/tools/rootcanal/model/devices/keyboard.cc b/tools/rootcanal/model/devices/keyboard.cc new file mode 100644 index 00000000000..5c818a02779 --- /dev/null +++ b/tools/rootcanal/model/devices/keyboard.cc @@ -0,0 +1,89 @@ +/* + * Copyright 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "keyboard.h" + +#include "model/setup/device_boutique.h" + +using std::vector; + +namespace rootcanal { +bool Keyboard::registered_ = + DeviceBoutique::Register("keyboard", &Keyboard::Create); + +Keyboard::Keyboard() { + properties_.SetLeAdvertisementType(0x00 /* CONNECTABLE */); + properties_.SetLeAdvertisement( + {0x11, // Length + 0x09 /* TYPE_NAME_CMPL */, + 'g', + 'D', + 'e', + 'v', + 'i', + 'c', + 'e', + '-', + 'k', + 'e', + 'y', + 'b', + 'o', + 'a', + 'r', + 'd', + 0x03, // Length + 0x19, + 0xC1, + 0x03, + 0x03, // Length + 0x03, + 0x12, + 0x18, + 0x02, // Length + 0x01 /* TYPE_FLAGS */, + 0x04 /* BREDR_NOT_SPT */ | 0x02 /* GEN_DISC_FLAG */}); + + properties_.SetLeScanResponse({0x04, // Length + 0x08 /* TYPE_NAME_SHORT */, 'k', 'e', 'y'}); +} + +std::string Keyboard::GetTypeString() const { return "keyboard"; } + +void Keyboard::Initialize(const vector<std::string>& args) { + if (args.size() < 2) return; + + Address addr{}; + if (Address::FromString(args[1], addr)) properties_.SetLeAddress(addr); + + if (args.size() < 3) return; + + SetAdvertisementInterval(std::chrono::milliseconds(std::stoi(args[2]))); +} + +void Keyboard::TimerTick() { + if (!connected_) { + Beacon::TimerTick(); + } +} + +void Keyboard::IncomingPacket(model::packets::LinkLayerPacketView packet) { + if (!connected_) { + Beacon::IncomingPacket(packet); + } +} + +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/keyboard.h b/tools/rootcanal/model/devices/keyboard.h similarity index 95% rename from system/vendor_libs/test_vendor_lib/model/devices/keyboard.h rename to tools/rootcanal/model/devices/keyboard.h index cf00dfefffe..a97e3f976bc 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/keyboard.h +++ b/tools/rootcanal/model/devices/keyboard.h @@ -19,11 +19,10 @@ #include <cstdint> #include <vector> -#include "device.h" - #include "beacon.h" +#include "device.h" -namespace test_vendor_lib { +namespace rootcanal { class Keyboard : public Beacon { public: @@ -49,4 +48,4 @@ class Keyboard : public Beacon { bool connected_{false}; static bool registered_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.cc b/tools/rootcanal/model/devices/link_layer_socket_device.cc similarity index 94% rename from system/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.cc rename to tools/rootcanal/model/devices/link_layer_socket_device.cc index 0f6d4723fbf..0acf25b06f8 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.cc +++ b/tools/rootcanal/model/devices/link_layer_socket_device.cc @@ -28,7 +28,7 @@ using std::vector; -namespace test_vendor_lib { +namespace rootcanal { LinkLayerSocketDevice::LinkLayerSocketDevice( std::shared_ptr<AsyncDataChannel> socket_fd, Phy::Type phy_type) @@ -67,10 +67,10 @@ void LinkLayerSocketDevice::TimerTick() { socket_->Recv(received_->data() + offset_, bytes_left_); if (bytes_received <= 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { - // Nothing available yet. - // LOG_DEBUG("Nothing available yet..."); - return; - } + // Nothing available yet. + // LOG_DEBUG("Nothing available yet..."); + return; + } LOG_INFO("Closing socket, received: %zd, %s", bytes_received, strerror(errno)); Close(); @@ -91,8 +91,7 @@ void LinkLayerSocketDevice::TimerTick() { SendLinkLayerPacket(packet, phy_type_); } -void LinkLayerSocketDevice::Close() -{ +void LinkLayerSocketDevice::Close() { if (socket_) { socket_->Close(); } @@ -113,4 +112,4 @@ void LinkLayerSocketDevice::IncomingPacket( } } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.h b/tools/rootcanal/model/devices/link_layer_socket_device.h similarity index 97% rename from system/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.h rename to tools/rootcanal/model/devices/link_layer_socket_device.h index 0a0e6b9656b..8ad89bd8008 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.h +++ b/tools/rootcanal/model/devices/link_layer_socket_device.h @@ -28,7 +28,7 @@ #include "net/async_data_channel.h" // for AsyncDataChannel #include "packets/link_layer_packets.h" // for LinkLayerPacketView -namespace test_vendor_lib { +namespace rootcanal { using android::net::AsyncDataChannel; @@ -72,4 +72,4 @@ class LinkLayerSocketDevice : public Device { std::vector<model::packets::LinkLayerPacketView> packet_queue_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/loopback.cc b/tools/rootcanal/model/devices/loopback.cc similarity index 85% rename from system/vendor_libs/test_vendor_lib/model/devices/loopback.cc rename to tools/rootcanal/model/devices/loopback.cc index de1a3587716..bd4ecdf8200 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/loopback.cc +++ b/tools/rootcanal/model/devices/loopback.cc @@ -21,9 +21,10 @@ using std::vector; -namespace test_vendor_lib { +namespace rootcanal { -bool Loopback::registered_ = DeviceBoutique::Register("loopback", &Loopback::Create); +bool Loopback::registered_ = + DeviceBoutique::Register("loopback", &Loopback::Create); Loopback::Loopback() { advertising_interval_ms_ = std::chrono::milliseconds(1280); @@ -31,7 +32,8 @@ Loopback::Loopback() { properties_.SetLeAdvertisement({ 0x11, // Length 0x09, // NAME_CMPL - 'g', 'D', 'e', 'v', 'i', 'c', 'e', '-', 'l', 'o', 'o', 'p', 'b', 'a', 'c', 'k', + 'g', 'D', 'e', 'v', 'i', 'c', 'e', '-', + 'l', 'o', 'o', 'p', 'b', 'a', 'c', 'k', 0x02, // Length 0x01, // TYPE_FLAG 0x04 | 0x02, // BREDR_NOT_SPT | GEN_DISC @@ -42,12 +44,11 @@ Loopback::Loopback() { 'l', 'o', 'o', 'p'}); } -std::string Loopback::GetTypeString() const { - return "loopback"; -} +std::string Loopback::GetTypeString() const { return "loopback"; } std::string Loopback::ToString() const { - std::string dev = GetTypeString() + "@" + properties_.GetLeAddress().ToString(); + std::string dev = + GetTypeString() + "@" + properties_.GetLeAddress().ToString(); return dev; } @@ -83,4 +84,4 @@ void Loopback::IncomingPacket(model::packets::LinkLayerPacketView packet) { } } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/loopback.h b/tools/rootcanal/model/devices/loopback.h similarity index 96% rename from system/vendor_libs/test_vendor_lib/model/devices/loopback.h rename to tools/rootcanal/model/devices/loopback.h index dd5c06945ae..866a81d5bad 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/loopback.h +++ b/tools/rootcanal/model/devices/loopback.h @@ -21,7 +21,7 @@ #include "device.h" -namespace test_vendor_lib { +namespace rootcanal { // A simple device that advertises periodically and is not connectable. class Loopback : public Device { @@ -51,4 +51,4 @@ class Loopback : public Device { static bool registered_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.cc b/tools/rootcanal/model/devices/remote_loopback_device.cc similarity index 91% rename from system/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.cc rename to tools/rootcanal/model/devices/remote_loopback_device.cc index c699a7cb4e7..3d5ceff0297 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.cc +++ b/tools/rootcanal/model/devices/remote_loopback_device.cc @@ -21,12 +21,13 @@ using std::vector; -namespace test_vendor_lib { +namespace rootcanal { using model::packets::LinkLayerPacketView; using model::packets::PageResponseBuilder; -bool RemoteLoopbackDevice::registered_ = DeviceBoutique::Register("remote_loopback", &RemoteLoopbackDevice::Create); +bool RemoteLoopbackDevice::registered_ = + DeviceBoutique::Register("remote_loopback", &RemoteLoopbackDevice::Create); RemoteLoopbackDevice::RemoteLoopbackDevice() {} @@ -62,4 +63,4 @@ void RemoteLoopbackDevice::IncomingPacket( } } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.h b/tools/rootcanal/model/devices/remote_loopback_device.h similarity index 95% rename from system/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.h rename to tools/rootcanal/model/devices/remote_loopback_device.h index 98c9a835b4e..78c1ffbcb09 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.h +++ b/tools/rootcanal/model/devices/remote_loopback_device.h @@ -21,7 +21,7 @@ #include "device.h" -namespace test_vendor_lib { +namespace rootcanal { class RemoteLoopbackDevice : public Device { public: @@ -47,4 +47,4 @@ class RemoteLoopbackDevice : public Device { static bool registered_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/scripted_beacon.cc b/tools/rootcanal/model/devices/scripted_beacon.cc similarity index 96% rename from system/vendor_libs/test_vendor_lib/model/devices/scripted_beacon.cc rename to tools/rootcanal/model/devices/scripted_beacon.cc index 7eced5a6577..b13c5691d4d 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/scripted_beacon.cc +++ b/tools/rootcanal/model/devices/scripted_beacon.cc @@ -16,10 +16,11 @@ #include "scripted_beacon.h" -#include <fstream> -#include <cstdint> #include <unistd.h> +#include <cstdint> +#include <fstream> + #include "model/devices/scripted_beacon_ble_payload.pb.h" #include "model/setup/device_boutique.h" #include "os/log.h" @@ -33,7 +34,7 @@ using std::vector; using std::chrono::steady_clock; using std::chrono::system_clock; -namespace test_vendor_lib { +namespace rootcanal { bool ScriptedBeacon::registered_ = DeviceBoutique::Register("scripted_beacon", &ScriptedBeacon::Create); ScriptedBeacon::ScriptedBeacon() { @@ -101,7 +102,8 @@ void ScriptedBeacon::Initialize(const vector<std::string>& args) { set_state(PlaybackEvent::INITIALIZED); } -void ScriptedBeacon::populate_event(PlaybackEvent * event, PlaybackEvent::PlaybackEventType type) { +void ScriptedBeacon::populate_event(PlaybackEvent* event, + PlaybackEvent::PlaybackEventType type) { LOG_INFO("Adding event: %d", type); event->set_type(type); event->set_secs_since_epoch(system_clock::now().time_since_epoch().count()); @@ -113,7 +115,8 @@ void ScriptedBeacon::set_state(PlaybackEvent::PlaybackEventType state) { PlaybackEvent event; current_state_ = state; if (!events_ostream_.is_open()) { - events_ostream_.open(events_file_, std::ios::out | std::ios::binary | std::ios::trunc); + events_ostream_.open(events_file_, + std::ios::out | std::ios::binary | std::ios::trunc); if (!events_ostream_.is_open()) { LOG_INFO("Events file not opened yet, for event: %d", state); return; @@ -236,4 +239,4 @@ void ScriptedBeacon::get_next_advertisement() { steady_clock::duration(std::chrono::milliseconds(delay_before_send_ms)); packet_num_++; } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/scripted_beacon.h b/tools/rootcanal/model/devices/scripted_beacon.h similarity index 80% rename from system/vendor_libs/test_vendor_lib/model/devices/scripted_beacon.h rename to tools/rootcanal/model/devices/scripted_beacon.h index 05406d05eb4..333480a42a7 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/scripted_beacon.h +++ b/tools/rootcanal/model/devices/scripted_beacon.h @@ -17,15 +17,16 @@ #pragma once #include <cstdint> -#include <vector> #include <fstream> +#include <vector> -#include "model/devices/scripted_beacon_ble_payload.pb.h" #include "beacon.h" +#include "model/devices/scripted_beacon_ble_payload.pb.h" -using android::bluetooth::test_vendor_lib::model::devices::ScriptedBeaconBleAdProto::PlaybackEvent; +using android::bluetooth::rootcanal::model::devices::ScriptedBeaconBleAdProto:: + PlaybackEvent; -namespace test_vendor_lib { +namespace rootcanal { // Pretend to be a lot of beacons by advertising from a file. class ScriptedBeacon : public Beacon { public: @@ -63,18 +64,20 @@ class ScriptedBeacon : public Beacon { std::chrono::steady_clock::time_point ad_time; }; - void populate_event(PlaybackEvent * event, PlaybackEvent::PlaybackEventType type); + void populate_event(PlaybackEvent* event, + PlaybackEvent::PlaybackEventType type); void get_next_advertisement(); void set_state( - android::bluetooth::test_vendor_lib::model::devices:: - ScriptedBeaconBleAdProto::PlaybackEvent::PlaybackEventType type); + android::bluetooth::rootcanal::model::devices::ScriptedBeaconBleAdProto:: + PlaybackEvent::PlaybackEventType type); Advertisement next_ad_{}; int packet_num_{0}; PlaybackEvent::PlaybackEventType current_state_{PlaybackEvent::UNKNOWN}; std::chrono::steady_clock::time_point next_check_time_{}; - android::bluetooth::test_vendor_lib::model::devices::ScriptedBeaconBleAdProto::BleAdvertisementList ble_ad_list_; + android::bluetooth::rootcanal::model::devices::ScriptedBeaconBleAdProto:: + BleAdvertisementList ble_ad_list_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/scripted_beacon_ble_payload.proto b/tools/rootcanal/model/devices/scripted_beacon_ble_payload.proto similarity index 89% rename from system/vendor_libs/test_vendor_lib/model/devices/scripted_beacon_ble_payload.proto rename to tools/rootcanal/model/devices/scripted_beacon_ble_payload.proto index 588519ce4a5..6f66288d584 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/scripted_beacon_ble_payload.proto +++ b/tools/rootcanal/model/devices/scripted_beacon_ble_payload.proto @@ -1,6 +1,6 @@ syntax = "proto2"; -package android.bluetooth.test_vendor_lib.model.devices.ScriptedBeaconBleAdProto; +package android.bluetooth.rootcanal.model.devices.ScriptedBeaconBleAdProto; option optimize_for = LITE_RUNTIME; diff --git a/system/vendor_libs/test_vendor_lib/model/devices/sniffer.cc b/tools/rootcanal/model/devices/sniffer.cc similarity index 94% rename from system/vendor_libs/test_vendor_lib/model/devices/sniffer.cc rename to tools/rootcanal/model/devices/sniffer.cc index edeb22d152e..b57acd17c28 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/sniffer.cc +++ b/tools/rootcanal/model/devices/sniffer.cc @@ -21,9 +21,10 @@ using std::vector; -namespace test_vendor_lib { +namespace rootcanal { -bool Sniffer::registered_ = DeviceBoutique::Register("sniffer", &Sniffer::Create); +bool Sniffer::registered_ = + DeviceBoutique::Register("sniffer", &Sniffer::Create); Sniffer::Sniffer() {} @@ -71,4 +72,4 @@ void Sniffer::IncomingPacket(model::packets::LinkLayerPacketView packet) { } } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/devices/sniffer.h b/tools/rootcanal/model/devices/sniffer.h similarity index 90% rename from system/vendor_libs/test_vendor_lib/model/devices/sniffer.h rename to tools/rootcanal/model/devices/sniffer.h index 590b182fe80..f72b4f7d198 100644 --- a/system/vendor_libs/test_vendor_lib/model/devices/sniffer.h +++ b/tools/rootcanal/model/devices/sniffer.h @@ -23,7 +23,7 @@ #include "hci/address.h" #include "packets/link_layer_packets.h" -namespace test_vendor_lib { +namespace rootcanal { using ::bluetooth::hci::Address; @@ -40,9 +40,7 @@ class Sniffer : public Device { virtual void Initialize(const std::vector<std::string>& args) override; // Return a string representation of the type of device. - virtual std::string GetTypeString() const override { - return "sniffer"; - } + virtual std::string GetTypeString() const override { return "sniffer"; } virtual void IncomingPacket( model::packets::LinkLayerPacketView packet) override; @@ -54,4 +52,4 @@ class Sniffer : public Device { Address device_to_sniff_{}; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/setup/async_manager.cc b/tools/rootcanal/model/setup/async_manager.cc similarity index 94% rename from system/vendor_libs/test_vendor_lib/model/setup/async_manager.cc rename to tools/rootcanal/model/setup/async_manager.cc index f557f113c1a..01447ec466e 100644 --- a/system/vendor_libs/test_vendor_lib/model/setup/async_manager.cc +++ b/tools/rootcanal/model/setup/async_manager.cc @@ -28,7 +28,7 @@ #include "sys/select.h" #include "unistd.h" -namespace test_vendor_lib { +namespace rootcanal { // Implementation of AsyncManager is divided between two classes, three if // AsyncManager itself is taken into account, but its only responsability // besides being a proxy for the other two classes is to provide a global @@ -74,7 +74,8 @@ namespace test_vendor_lib { // This number also states the maximum number of scheduled tasks we can handle // at a given time -static const uint16_t kMaxTaskId = -1; /* 2^16 - 1, permisible ids are {1..2^16-1}*/ +static const uint16_t kMaxTaskId = + -1; /* 2^16 - 1, permisible ids are {1..2^16-1}*/ static inline AsyncTaskId NextAsyncTaskId(const AsyncTaskId id) { return (id == kMaxTaskId) ? 1 : id + 1; } @@ -93,7 +94,8 @@ static const int kNotificationBufferSize = 10; // Async File Descriptor Watcher Implementation: class AsyncManager::AsyncFdWatcher { public: - int WatchFdForNonBlockingReads(int file_descriptor, const ReadCallback& on_read_fd_ready_callback) { + int WatchFdForNonBlockingReads( + int file_descriptor, const ReadCallback& on_read_fd_ready_callback) { // add file descriptor and callback { std::unique_lock<std::recursive_mutex> guard(internal_mutex_); @@ -134,7 +136,8 @@ class AsyncManager::AsyncFdWatcher { if (std::this_thread::get_id() != thread_.get_id()) { thread_.join(); } else { - LOG_WARN("%s: Starting thread stop from inside the reading thread itself", __func__); + LOG_WARN("%s: Starting thread stop from inside the reading thread itself", + __func__); } { @@ -201,7 +204,8 @@ class AsyncManager::AsyncFdWatcher { bool consumeThreadNotifications(fd_set& read_fds) { if (FD_ISSET(notification_listen_fd_, &read_fds)) { char buffer[kNotificationBufferSize]; - while (TEMP_FAILURE_RETRY(read(notification_listen_fd_, buffer, kNotificationBufferSize)) == + while (TEMP_FAILURE_RETRY(read(notification_listen_fd_, buffer, + kNotificationBufferSize)) == kNotificationBufferSize) { } return true; @@ -320,7 +324,8 @@ class AsyncManager::AsyncTaskManager { if (std::this_thread::get_id() != thread_.get_id()) { thread_.join(); } else { - LOG_WARN("%s: Starting thread stop from inside the task thread itself", __func__); + LOG_WARN("%s: Starting thread stop from inside the task thread itself", + __func__); } return 0; } @@ -348,12 +353,11 @@ class AsyncManager::AsyncTaskManager { // Operators needed to be in a collection bool operator<(const Task& another) const { - return std::make_pair(time, task_id) < std::make_pair(another.time, another.task_id); + return std::make_pair(time, task_id) < + std::make_pair(another.time, another.task_id); } - bool isPeriodic() const { - return periodic; - } + bool isPeriodic() const { return periodic; } // These fields should no longer be public if the class ever becomes // public or gets more complex @@ -367,7 +371,8 @@ class AsyncManager::AsyncTaskManager { // A comparator class to put shared pointers to tasks in an ordered set struct task_p_comparator { - bool operator()(const std::shared_ptr<Task>& t1, const std::shared_ptr<Task>& t2) const { + bool operator()(const std::shared_ptr<Task>& t1, + const std::shared_ptr<Task>& t2) const { return *t1 < *t2; } }; @@ -481,13 +486,15 @@ class AsyncManager::AsyncTaskManager { AsyncTaskId lastTaskId_ = kInvalidTaskId; AsyncUserId lastUserId_{1}; - std::map<AsyncTaskId, std::shared_ptr<Task> > tasks_by_id_; + std::map<AsyncTaskId, std::shared_ptr<Task>> tasks_by_id_; std::map<AsyncUserId, std::set<AsyncTaskId>> tasks_by_user_id_; std::set<std::shared_ptr<Task>, task_p_comparator> task_queue_; }; // Async Manager Implementation: -AsyncManager::AsyncManager() : fdWatcher_p_(new AsyncFdWatcher()), taskManager_p_(new AsyncTaskManager()) {} +AsyncManager::AsyncManager() + : fdWatcher_p_(new AsyncFdWatcher()), + taskManager_p_(new AsyncTaskManager()) {} AsyncManager::~AsyncManager() { // Make sure the threads are stopped before destroying the object. @@ -500,8 +507,10 @@ AsyncManager::~AsyncManager() { taskManager_p_->stopThread(); } -int AsyncManager::WatchFdForNonBlockingReads(int file_descriptor, const ReadCallback& on_read_fd_ready_callback) { - return fdWatcher_p_->WatchFdForNonBlockingReads(file_descriptor, on_read_fd_ready_callback); +int AsyncManager::WatchFdForNonBlockingReads( + int file_descriptor, const ReadCallback& on_read_fd_ready_callback) { + return fdWatcher_p_->WatchFdForNonBlockingReads(file_descriptor, + on_read_fd_ready_callback); } void AsyncManager::StopWatchingFileDescriptor(int file_descriptor) { @@ -529,8 +538,7 @@ bool AsyncManager::CancelAsyncTask(AsyncTaskId async_task_id) { return taskManager_p_->CancelAsyncTask(async_task_id); } -bool AsyncManager::CancelAsyncTasksFromUser( - test_vendor_lib::AsyncUserId user_id) { +bool AsyncManager::CancelAsyncTasksFromUser(rootcanal::AsyncUserId user_id) { return taskManager_p_->CancelAsyncTasksFromUser(user_id); } @@ -538,4 +546,4 @@ void AsyncManager::Synchronize(const CriticalCallback& critical) { std::unique_lock<std::mutex> guard(synchronization_mutex_); critical(); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/setup/async_manager.h b/tools/rootcanal/model/setup/async_manager.h similarity index 96% rename from system/vendor_libs/test_vendor_lib/model/setup/async_manager.h rename to tools/rootcanal/model/setup/async_manager.h index 2bcbb69ad9c..f6603c49423 100644 --- a/system/vendor_libs/test_vendor_lib/model/setup/async_manager.h +++ b/tools/rootcanal/model/setup/async_manager.h @@ -2,19 +2,20 @@ #define TEST_VENDOR_LIB_ASYNC_MANAGER_H_ #include <time.h> -#include <cstdint> -#include <map> -#include <set> -#include "errno.h" -#include "stdio.h" #include <chrono> +#include <cstdint> #include <functional> +#include <map> #include <memory> #include <mutex> +#include <set> #include <utility> -namespace test_vendor_lib { +#include "errno.h" +#include "stdio.h" + +namespace rootcanal { using TaskCallback = std::function<void(void)>; using ReadCallback = std::function<void(int)>; @@ -53,7 +54,8 @@ class AsyncManager { // made about when in the future the callback will be called, in particular, // it is perfectly possible to have it called before this function returns. A // return of 0 means success, an error code is returned otherwise. - int WatchFdForNonBlockingReads(int file_descriptor, const ReadCallback& on_read_fd_ready_callback); + int WatchFdForNonBlockingReads(int file_descriptor, + const ReadCallback& on_read_fd_ready_callback); // If the fd was not being watched before the call will be ignored. void StopWatchingFileDescriptor(int file_descriptor); @@ -120,5 +122,5 @@ class AsyncManager { std::mutex synchronization_mutex_; }; -} // namespace test_vendor_lib +} // namespace rootcanal #endif // TEST_VENDOR_LIB_ASYNC_MANAGER_H_ diff --git a/system/vendor_libs/test_vendor_lib/model/setup/device_boutique.cc b/tools/rootcanal/model/setup/device_boutique.cc similarity index 74% rename from system/vendor_libs/test_vendor_lib/model/setup/device_boutique.cc rename to tools/rootcanal/model/setup/device_boutique.cc index de3b1ccea40..d95fe9d55ef 100644 --- a/system/vendor_libs/test_vendor_lib/model/setup/device_boutique.cc +++ b/tools/rootcanal/model/setup/device_boutique.cc @@ -20,22 +20,27 @@ using std::vector; -namespace test_vendor_lib { +namespace rootcanal { -std::unordered_map<std::string, std::function<std::shared_ptr<Device>()>>& DeviceBoutique::GetMap() { - static std::unordered_map<std::string, std::function<std::shared_ptr<Device>()>> impl; +std::unordered_map<std::string, std::function<std::shared_ptr<Device>()>>& +DeviceBoutique::GetMap() { + static std::unordered_map<std::string, + std::function<std::shared_ptr<Device>()>> + impl; return impl; } // Register a constructor for a device type. -bool DeviceBoutique::Register(const std::string& device_type, - const std::function<std::shared_ptr<Device>()> device_constructor) { +bool DeviceBoutique::Register( + const std::string& device_type, + const std::function<std::shared_ptr<Device>()> device_constructor) { LOG_INFO("Registering %s", device_type.c_str()); GetMap()[device_type] = device_constructor; return true; } -std::shared_ptr<Device> DeviceBoutique::Create(const vector<std::string>& args) { +std::shared_ptr<Device> DeviceBoutique::Create( + const vector<std::string>& args) { ASSERT(!args.empty()); if (GetMap().find(args[0]) == GetMap().end()) { @@ -49,4 +54,4 @@ std::shared_ptr<Device> DeviceBoutique::Create(const vector<std::string>& args) return new_device; } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/setup/device_boutique.h b/tools/rootcanal/model/setup/device_boutique.h similarity index 81% rename from system/vendor_libs/test_vendor_lib/model/setup/device_boutique.h rename to tools/rootcanal/model/setup/device_boutique.h index 95edb3d0d91..51965c5c8fc 100644 --- a/system/vendor_libs/test_vendor_lib/model/setup/device_boutique.h +++ b/tools/rootcanal/model/setup/device_boutique.h @@ -24,7 +24,7 @@ #include "model/devices/device.h" -namespace test_vendor_lib { +namespace rootcanal { // Create customized devices from a centralized shop. class DeviceBoutique { @@ -33,7 +33,8 @@ class DeviceBoutique { virtual ~DeviceBoutique() = default; // Register a constructor for a device type. - static bool Register(const std::string& device_type, const std::function<std::shared_ptr<Device>()> method); + static bool Register(const std::string& device_type, + const std::function<std::shared_ptr<Device>()> method); // Call the constructor that matches arg[0], then call dev->Initialize(args). static std::shared_ptr<Device> Create(const std::vector<std::string>& args); @@ -47,7 +48,9 @@ class DeviceBoutique { }; private: - static std::unordered_map<std::string, std::function<std::shared_ptr<Device>()>>& GetMap(); + static std::unordered_map<std::string, + std::function<std::shared_ptr<Device>()>>& + GetMap(); }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/setup/phy_layer.h b/tools/rootcanal/model/setup/phy_layer.h similarity index 91% rename from system/vendor_libs/test_vendor_lib/model/setup/phy_layer.h rename to tools/rootcanal/model/setup/phy_layer.h index 00a3067f226..9fc21f46e4a 100644 --- a/system/vendor_libs/test_vendor_lib/model/setup/phy_layer.h +++ b/tools/rootcanal/model/setup/phy_layer.h @@ -17,9 +17,8 @@ #pragma once #include "include/phy.h" - #include "packets/link_layer_packets.h" -namespace test_vendor_lib { +namespace rootcanal { class PhyLayer { public: @@ -44,13 +43,9 @@ class PhyLayer { virtual void Unregister() = 0; - Phy::Type GetType() { - return phy_type_; - } + Phy::Type GetType() { return phy_type_; } - uint32_t GetId() { - return id_; - } + uint32_t GetId() { return id_; } uint32_t GetDeviceId() { return device_id_; } @@ -66,4 +61,4 @@ class PhyLayer { transmit_to_device_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.cc b/tools/rootcanal/model/setup/phy_layer_factory.cc similarity index 92% rename from system/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.cc rename to tools/rootcanal/model/setup/phy_layer_factory.cc index 6fe54429b9d..5c76d8a36d9 100644 --- a/system/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.cc +++ b/tools/rootcanal/model/setup/phy_layer_factory.cc @@ -15,20 +15,17 @@ */ #include "phy_layer_factory.h" + #include <sstream> -namespace test_vendor_lib { +namespace rootcanal { PhyLayerFactory::PhyLayerFactory(Phy::Type phy_type, uint32_t factory_id) : phy_type_(phy_type), factory_id_(factory_id) {} -Phy::Type PhyLayerFactory::GetType() { - return phy_type_; -} +Phy::Type PhyLayerFactory::GetType() { return phy_type_; } -uint32_t PhyLayerFactory::GetFactoryId() { - return factory_id_; -} +uint32_t PhyLayerFactory::GetFactoryId() { return factory_id_; } std::shared_ptr<PhyLayer> PhyLayerFactory::GetPhyLayer( const std::function<void(model::packets::LinkLayerPacketView)>& @@ -117,8 +114,7 @@ PhyLayerImpl::PhyLayerImpl( uint32_t device_id, PhyLayerFactory* factory) : PhyLayer(phy_type, id, device_receive, device_id), factory_(factory) {} -PhyLayerImpl::~PhyLayerImpl() { -} +PhyLayerImpl::~PhyLayerImpl() {} void PhyLayerImpl::Send( const std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet) { @@ -129,9 +125,7 @@ void PhyLayerImpl::Send(model::packets::LinkLayerPacketView packet) { factory_->Send(packet, GetId()); } -void PhyLayerImpl::Unregister() { - factory_->UnregisterPhyLayer(GetId()); -} +void PhyLayerImpl::Unregister() { factory_->UnregisterPhyLayer(GetId()); } bool PhyLayerImpl::IsFactoryId(uint32_t id) { return factory_->GetFactoryId() == id; @@ -143,4 +137,4 @@ void PhyLayerImpl::Receive(model::packets::LinkLayerPacketView packet) { void PhyLayerImpl::TimerTick() {} -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.h b/tools/rootcanal/model/setup/phy_layer_factory.h similarity index 97% rename from system/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.h rename to tools/rootcanal/model/setup/phy_layer_factory.h index a19fdf1a893..1955bf25d35 100644 --- a/system/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.h +++ b/tools/rootcanal/model/setup/phy_layer_factory.h @@ -24,7 +24,7 @@ #include "packets/link_layer_packets.h" #include "phy_layer.h" -namespace test_vendor_lib { +namespace rootcanal { class PhyLayerFactory { friend class PhyLayerImpl; @@ -80,8 +80,7 @@ class PhyLayerImpl : public PhyLayer { bool IsFactoryId(uint32_t factory_id) override; void TimerTick() override; - private: PhyLayerFactory* factory_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/setup/test_channel_transport.cc b/tools/rootcanal/model/setup/test_channel_transport.cc similarity index 98% rename from system/vendor_libs/test_vendor_lib/model/setup/test_channel_transport.cc rename to tools/rootcanal/model/setup/test_channel_transport.cc index f08d32935d8..47a3a417876 100644 --- a/system/vendor_libs/test_vendor_lib/model/setup/test_channel_transport.cc +++ b/tools/rootcanal/model/setup/test_channel_transport.cc @@ -28,7 +28,7 @@ using std::vector; -namespace test_vendor_lib { +namespace rootcanal { bool TestChannelTransport::SetUp(std::shared_ptr<AsyncDataChannelServer> server, ConnectCallback connection_callback) { @@ -126,4 +126,4 @@ void TestChannelTransport::RegisterCommandHandler( command_handler_ = callback; } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/setup/test_channel_transport.h b/tools/rootcanal/model/setup/test_channel_transport.h similarity index 97% rename from system/vendor_libs/test_vendor_lib/model/setup/test_channel_transport.h rename to tools/rootcanal/model/setup/test_channel_transport.h index 0048a3d9077..807326148b6 100644 --- a/system/vendor_libs/test_vendor_lib/model/setup/test_channel_transport.h +++ b/tools/rootcanal/model/setup/test_channel_transport.h @@ -24,7 +24,7 @@ #include "net/async_data_channel.h" // for AsyncDataChannel #include "net/async_data_channel_server.h" // for AsyncDataChannelServer (ptr only), Con... -namespace test_vendor_lib { +namespace rootcanal { using android::net::AsyncDataChannel; using android::net::AsyncDataChannelServer; @@ -67,4 +67,4 @@ class TestChannelTransport { TestChannelTransport& operator=(const TestChannelTransport& cmdPckt) = delete; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/setup/test_command_handler.cc b/tools/rootcanal/model/setup/test_command_handler.cc similarity index 83% rename from system/vendor_libs/test_vendor_lib/model/setup/test_command_handler.cc rename to tools/rootcanal/model/setup/test_command_handler.cc index ad95cc32a83..5c959318220 100644 --- a/system/vendor_libs/test_vendor_lib/model/setup/test_command_handler.cc +++ b/tools/rootcanal/model/setup/test_command_handler.cc @@ -15,25 +15,28 @@ */ #include "test_command_handler.h" -#include "device_boutique.h" -#include "phy.h" + +#include <stdlib.h> #include <fstream> #include <memory> #include <regex> -#include <stdlib.h> - +#include "device_boutique.h" #include "os/log.h" #include "osi/include/osi.h" +#include "phy.h" using std::vector; -namespace test_vendor_lib { +namespace rootcanal { -TestCommandHandler::TestCommandHandler(TestModel& test_model) : model_(test_model) { -#define SET_HANDLER(command_name, method) \ - active_commands_[command_name] = [this](const vector<std::string>& param) { method(param); }; +TestCommandHandler::TestCommandHandler(TestModel& test_model) + : model_(test_model) { +#define SET_HANDLER(command_name, method) \ + active_commands_[command_name] = [this](const vector<std::string>& param) { \ + method(param); \ + }; SET_HANDLER("add", Add); SET_HANDLER("add_remote", AddRemote); SET_HANDLER("del", Del); @@ -85,7 +88,8 @@ void TestCommandHandler::AddDefaults() { StartTimer({}); } -void TestCommandHandler::HandleCommand(const std::string& name, const vector<std::string>& args) { +void TestCommandHandler::HandleCommand(const std::string& name, + const vector<std::string>& args) { if (active_commands_.count(name) == 0) { response_string_ = "Unhandled command: " + name; send_response_(response_string_); @@ -118,7 +122,8 @@ void TestCommandHandler::FromFile(const std::string& file_name) { } } -void TestCommandHandler::RegisterSendResponse(const std::function<void(const std::string&)> callback) { +void TestCommandHandler::RegisterSendResponse( + const std::function<void(const std::string&)> callback) { send_response_ = callback; send_response_("RegisterSendResponse called"); } @@ -140,13 +145,15 @@ void TestCommandHandler::Add(const vector<std::string>& args) { LOG_INFO("Add %s", new_dev->ToString().c_str()); size_t dev_index = model_.Add(new_dev); - response_string_ = std::to_string(dev_index) + std::string(":") + new_dev->ToString(); + response_string_ = + std::to_string(dev_index) + std::string(":") + new_dev->ToString(); send_response_(response_string_); } void TestCommandHandler::AddRemote(const vector<std::string>& args) { if (args.size() < 3) { - response_string_ = "TestCommandHandler usage: add_remote host port phy_type"; + response_string_ = + "TestCommandHandler usage: add_remote host port phy_type"; send_response_(response_string_); return; } @@ -175,7 +182,8 @@ void TestCommandHandler::Del(const vector<std::string>& args) { size_t dev_index = std::stoi(args[0]); model_.Del(dev_index); - response_string_ = "TestCommandHandler 'del' called with device at index " + std::to_string(dev_index); + response_string_ = "TestCommandHandler 'del' called with device at index " + + std::to_string(dev_index); send_response_(response_string_); } @@ -185,7 +193,8 @@ void TestCommandHandler::AddPhy(const vector<std::string>& args) { } else if (args[0] == "BR_EDR") { model_.AddPhy(Phy::Type::BR_EDR); } else { - response_string_ = "TestCommandHandler 'add_phy' with unrecognized type " + args[0]; + response_string_ = + "TestCommandHandler 'add_phy' with unrecognized type " + args[0]; send_response_(response_string_); } } @@ -194,36 +203,41 @@ void TestCommandHandler::DelPhy(const vector<std::string>& args) { size_t phy_index = std::stoi(args[0]); model_.DelPhy(phy_index); - response_string_ = "TestCommandHandler 'del_phy' called with phy at index " + std::to_string(phy_index); + response_string_ = "TestCommandHandler 'del_phy' called with phy at index " + + std::to_string(phy_index); send_response_(response_string_); } void TestCommandHandler::AddDeviceToPhy(const vector<std::string>& args) { if (args.size() != 2) { - response_string_ = "TestCommandHandler 'add_device_to_phy' takes two arguments"; + response_string_ = + "TestCommandHandler 'add_device_to_phy' takes two arguments"; send_response_(response_string_); return; } size_t dev_index = std::stoi(args[0]); size_t phy_index = std::stoi(args[1]); model_.AddDeviceToPhy(dev_index, phy_index); - response_string_ = "TestCommandHandler 'add_device_to_phy' called with device " + std::to_string(dev_index) + - " and phy " + std::to_string(phy_index); + response_string_ = + "TestCommandHandler 'add_device_to_phy' called with device " + + std::to_string(dev_index) + " and phy " + std::to_string(phy_index); send_response_(response_string_); return; } void TestCommandHandler::DelDeviceFromPhy(const vector<std::string>& args) { if (args.size() != 2) { - response_string_ = "TestCommandHandler 'del_device_from_phy' takes two arguments"; + response_string_ = + "TestCommandHandler 'del_device_from_phy' takes two arguments"; send_response_(response_string_); return; } size_t dev_index = std::stoi(args[0]); size_t phy_index = std::stoi(args[1]); model_.DelDeviceFromPhy(dev_index, phy_index); - response_string_ = "TestCommandHandler 'del_device_from_phy' called with device " + std::to_string(dev_index) + - " and phy " + std::to_string(phy_index); + response_string_ = + "TestCommandHandler 'del_device_from_phy' called with device " + + std::to_string(dev_index) + " and phy " + std::to_string(phy_index); send_response_(response_string_); return; } @@ -238,7 +252,8 @@ void TestCommandHandler::List(const vector<std::string>& args) { void TestCommandHandler::SetDeviceAddress(const vector<std::string>& args) { if (args.size() != 2) { - response_string_ = "TestCommandHandler 'set_device_address' takes two arguments"; + response_string_ = + "TestCommandHandler 'set_device_address' takes two arguments"; send_response_(response_string_); return; } @@ -295,4 +310,4 @@ void TestCommandHandler::Reset(const std::vector<std::string>& args) { send_response_(response_string_); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/setup/test_command_handler.h b/tools/rootcanal/model/setup/test_command_handler.h similarity index 87% rename from system/vendor_libs/test_vendor_lib/model/setup/test_command_handler.h rename to tools/rootcanal/model/setup/test_command_handler.h index e39ca0c5f4e..26d6cefd4a5 100644 --- a/system/vendor_libs/test_vendor_lib/model/setup/test_command_handler.h +++ b/tools/rootcanal/model/setup/test_command_handler.h @@ -17,6 +17,7 @@ #pragma once #include <unistd.h> + #include <cstdint> #include <memory> #include <string> @@ -28,7 +29,7 @@ #include "test_channel_transport.h" #include "test_model.h" -namespace test_vendor_lib { +namespace rootcanal { class TestCommandHandler { public: @@ -38,13 +39,15 @@ class TestCommandHandler { ~TestCommandHandler() = default; // Dispatches the action corresponding to the command specified by |name|. - void HandleCommand(const std::string& name, const std::vector<std::string>& args); + void HandleCommand(const std::string& name, + const std::vector<std::string>& args); // Dispatches the action from a file void FromFile(const std::string& file_name); // Dispatches the action corresponding to the command specified by |name|. - void RegisterSendResponse(const std::function<void(const std::string&)> callback); + void RegisterSendResponse( + const std::function<void(const std::string&)> callback); // Commands: @@ -92,7 +95,9 @@ class TestCommandHandler { std::string response_string_; - std::unordered_map<std::string, std::function<void(const std::vector<std::string>&)>> active_commands_; + std::unordered_map<std::string, + std::function<void(const std::vector<std::string>&)>> + active_commands_; std::function<void(const std::string&)> send_response_; @@ -100,4 +105,4 @@ class TestCommandHandler { TestCommandHandler& operator=(const TestCommandHandler& cmdPckt) = delete; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/setup/test_model.cc b/tools/rootcanal/model/setup/test_model.cc similarity index 98% rename from system/vendor_libs/test_vendor_lib/model/setup/test_model.cc rename to tools/rootcanal/model/setup/test_model.cc index 5ccc103fa60..5fe6ff9c0bc 100644 --- a/system/vendor_libs/test_vendor_lib/model/setup/test_model.cc +++ b/tools/rootcanal/model/setup/test_model.cc @@ -46,7 +46,7 @@ #include "os/log.h" // for LOG_WARN, LOG_INFO #include "packets/link_layer_packets.h" // for LinkLayerPacketView -namespace test_vendor_lib { +namespace rootcanal { class Device; TestModel::TestModel( @@ -192,7 +192,6 @@ void TestModel::AddLinkLayerConnection(std::shared_ptr<AsyncDataChannel> socket, OnConnectionClosed(socket, index, user_id); }); }); - } void TestModel::IncomingLinkLayerConnection( @@ -246,7 +245,7 @@ void TestModel::IncomingHciConnection(std::shared_ptr<AsyncDataChannel> socket, } void TestModel::OnConnectionClosed(std::shared_ptr<AsyncDataChannel> socket, - size_t index, AsyncUserId user_id) { + size_t index, AsyncUserId user_id) { if (index >= devices_.size() || devices_[index] == nullptr) { LOG_WARN("Unknown device %zu", index); return; @@ -306,4 +305,4 @@ void TestModel::Reset() { }); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/model/setup/test_model.h b/tools/rootcanal/model/setup/test_model.h similarity index 95% rename from system/vendor_libs/test_vendor_lib/model/setup/test_model.h rename to tools/rootcanal/model/setup/test_model.h index 11e68bb7028..91ff42abe61 100644 --- a/system/vendor_libs/test_vendor_lib/model/setup/test_model.h +++ b/tools/rootcanal/model/setup/test_model.h @@ -33,7 +33,7 @@ #include "phy_layer_factory.h" // for PhyLayerFactory #include "test_channel_transport.h" // for AsyncDataChannel -namespace test_vendor_lib { +namespace rootcanal { class Device; using android::net::AsyncDataChannel; @@ -82,13 +82,14 @@ class TestModel { void AddLinkLayerConnection(std::shared_ptr<AsyncDataChannel> socket_fd, Phy::Type phy_type); void IncomingLinkLayerConnection(std::shared_ptr<AsyncDataChannel> socket_fd); - void IncomingLinkBleLayerConnection(std::shared_ptr<AsyncDataChannel> socket_fd); + void IncomingLinkBleLayerConnection( + std::shared_ptr<AsyncDataChannel> socket_fd); void IncomingHciConnection(std::shared_ptr<AsyncDataChannel> socket_fd, std::string properties_filename = ""); // Handle closed remote connections (both hci & link layer) void OnConnectionClosed(std::shared_ptr<AsyncDataChannel> socket_fd, - size_t index, AsyncUserId user_id); + size_t index, AsyncUserId user_id); // Connect to a remote device void AddRemote(const std::string& server, int port, Phy::Type phy_type); @@ -134,4 +135,4 @@ class TestModel { std::shared_ptr<AsyncDataChannelConnector> socket_connector_; }; -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/net/async_data_channel.h b/tools/rootcanal/net/async_data_channel.h similarity index 100% rename from system/vendor_libs/test_vendor_lib/net/async_data_channel.h rename to tools/rootcanal/net/async_data_channel.h diff --git a/system/vendor_libs/test_vendor_lib/net/async_data_channel_connector.h b/tools/rootcanal/net/async_data_channel_connector.h similarity index 100% rename from system/vendor_libs/test_vendor_lib/net/async_data_channel_connector.h rename to tools/rootcanal/net/async_data_channel_connector.h diff --git a/system/vendor_libs/test_vendor_lib/net/async_data_channel_server.h b/tools/rootcanal/net/async_data_channel_server.h similarity index 100% rename from system/vendor_libs/test_vendor_lib/net/async_data_channel_server.h rename to tools/rootcanal/net/async_data_channel_server.h diff --git a/system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket.cc b/tools/rootcanal/net/posix/posix_async_socket.cc similarity index 100% rename from system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket.cc rename to tools/rootcanal/net/posix/posix_async_socket.cc diff --git a/system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket.h b/tools/rootcanal/net/posix/posix_async_socket.h similarity index 96% rename from system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket.h rename to tools/rootcanal/net/posix/posix_async_socket.h index 197e7710129..0dbc8789da8 100644 --- a/system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket.h +++ b/tools/rootcanal/net/posix/posix_async_socket.h @@ -19,14 +19,14 @@ #include "net/async_data_channel.h" // for AsyncDataChannel, ReadCallback -namespace test_vendor_lib { +namespace rootcanal { class AsyncManager; -} // namespace test_vendor_lib +} // namespace rootcanal namespace android { namespace net { -using test_vendor_lib::AsyncManager; +using rootcanal::AsyncManager; // A Posix compliant implementation of the AsyncDataChannel interface. // diff --git a/system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket_connector.cc b/tools/rootcanal/net/posix/posix_async_socket_connector.cc similarity index 98% rename from system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket_connector.cc rename to tools/rootcanal/net/posix/posix_async_socket_connector.cc index c24e8a52fa6..4e7531bccf4 100644 --- a/system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket_connector.cc +++ b/tools/rootcanal/net/posix/posix_async_socket_connector.cc @@ -21,7 +21,8 @@ #include <poll.h> // for poll, POLLHUP, POLLIN, POL... #include <string.h> // for strerror, NULL #include <sys/socket.h> // for connect, getpeername, gets... -#include <type_traits> // for remove_extent_t + +#include <type_traits> // for remove_extent_t #include "net/posix/posix_async_socket.h" // for PosixAsyncSocket #include "os/log.h" // for LOG_INFO diff --git a/system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket_connector.h b/tools/rootcanal/net/posix/posix_async_socket_connector.h similarity index 95% rename from system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket_connector.h rename to tools/rootcanal/net/posix/posix_async_socket_connector.h index 0f53678ebd1..1a318e1c9ca 100644 --- a/system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket_connector.h +++ b/tools/rootcanal/net/posix/posix_async_socket_connector.h @@ -25,11 +25,11 @@ class AsyncDataChannel; } // namespace net } // namespace android -namespace test_vendor_lib { +namespace rootcanal { class AsyncManager; -} // namespace test_vendor_lib +} // namespace rootcanal -using test_vendor_lib::AsyncManager; +using rootcanal::AsyncManager; namespace android { namespace net { diff --git a/system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket_server.cc b/tools/rootcanal/net/posix/posix_async_socket_server.cc similarity index 97% rename from system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket_server.cc rename to tools/rootcanal/net/posix/posix_async_socket_server.cc index 67ca71af7b4..0615fda5138 100644 --- a/system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket_server.cc +++ b/tools/rootcanal/net/posix/posix_async_socket_server.cc @@ -19,8 +19,9 @@ #include <string.h> // for strerror, NULL #include <sys/socket.h> // for accept, bind, getsockname #include <unistd.h> // for close -#include <functional> // for __base, function -#include <type_traits> // for remove_extent_t + +#include <functional> // for __base, function +#include <type_traits> // for remove_extent_t #include "net/posix/posix_async_socket.h" // for PosixAsyncSocket, AsyncMan... #include "os/log.h" // for LOG_INFO, LOG_ERROR diff --git a/system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket_server.h b/tools/rootcanal/net/posix/posix_async_socket_server.h similarity index 94% rename from system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket_server.h rename to tools/rootcanal/net/posix/posix_async_socket_server.h index c1453b5dbf0..e5d012b9baa 100644 --- a/system/vendor_libs/test_vendor_lib/net/posix/posix_async_socket_server.h +++ b/tools/rootcanal/net/posix/posix_async_socket_server.h @@ -19,11 +19,11 @@ #include "net/async_data_channel_server.h" // for AsyncDataChannelServer #include "net/posix/posix_async_socket.h" // for AsyncManager, PosixAsyncS... -namespace test_vendor_lib { +namespace rootcanal { class AsyncManager; -} // namespace test_vendor_lib +} // namespace rootcanal -using test_vendor_lib::AsyncManager; +using rootcanal::AsyncManager; namespace android { namespace net { diff --git a/system/vendor_libs/test_vendor_lib/packets/link_layer_packets.pdl b/tools/rootcanal/packets/link_layer_packets.pdl similarity index 100% rename from system/vendor_libs/test_vendor_lib/packets/link_layer_packets.pdl rename to tools/rootcanal/packets/link_layer_packets.pdl diff --git a/system/vendor_libs/test_vendor_lib/scripts/build_and_run.sh b/tools/rootcanal/scripts/build_and_run.sh similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/build_and_run.sh rename to tools/rootcanal/scripts/build_and_run.sh diff --git a/system/vendor_libs/test_vendor_lib/scripts/hci_socket.py b/tools/rootcanal/scripts/hci_socket.py similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/hci_socket.py rename to tools/rootcanal/scripts/hci_socket.py diff --git a/system/vendor_libs/test_vendor_lib/scripts/link_layer_socket.py b/tools/rootcanal/scripts/link_layer_socket.py similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/link_layer_socket.py rename to tools/rootcanal/scripts/link_layer_socket.py diff --git a/system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/Readme.txt b/tools/rootcanal/scripts/scripted_beacon_test/Readme.txt similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/Readme.txt rename to tools/rootcanal/scripts/scripted_beacon_test/Readme.txt diff --git a/system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/add_beacons b/tools/rootcanal/scripts/scripted_beacon_test/add_beacons similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/add_beacons rename to tools/rootcanal/scripts/scripted_beacon_test/add_beacons diff --git a/system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/grant_permission.pb b/tools/rootcanal/scripts/scripted_beacon_test/grant_permission.pb similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/grant_permission.pb rename to tools/rootcanal/scripts/scripted_beacon_test/grant_permission.pb diff --git a/system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/no_permission.pb b/tools/rootcanal/scripts/scripted_beacon_test/no_permission.pb similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/no_permission.pb rename to tools/rootcanal/scripts/scripted_beacon_test/no_permission.pb diff --git a/system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/run_test.sh b/tools/rootcanal/scripts/scripted_beacon_test/run_test.sh similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/run_test.sh rename to tools/rootcanal/scripts/scripted_beacon_test/run_test.sh diff --git a/system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/start_scan b/tools/rootcanal/scripts/scripted_beacon_test/start_scan similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/start_scan rename to tools/rootcanal/scripts/scripted_beacon_test/start_scan diff --git a/system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/test_events.pb b/tools/rootcanal/scripts/scripted_beacon_test/test_events.pb similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/scripted_beacon_test/test_events.pb rename to tools/rootcanal/scripts/scripted_beacon_test/test_events.pb diff --git a/system/vendor_libs/test_vendor_lib/scripts/send_simple_commands.py b/tools/rootcanal/scripts/send_simple_commands.py similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/send_simple_commands.py rename to tools/rootcanal/scripts/send_simple_commands.py diff --git a/system/vendor_libs/test_vendor_lib/scripts/simple_link_layer_socket.py b/tools/rootcanal/scripts/simple_link_layer_socket.py similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/simple_link_layer_socket.py rename to tools/rootcanal/scripts/simple_link_layer_socket.py diff --git a/system/vendor_libs/test_vendor_lib/scripts/simple_stack.py b/tools/rootcanal/scripts/simple_stack.py similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/simple_stack.py rename to tools/rootcanal/scripts/simple_stack.py diff --git a/system/vendor_libs/test_vendor_lib/scripts/test_channel.py b/tools/rootcanal/scripts/test_channel.py similarity index 100% rename from system/vendor_libs/test_vendor_lib/scripts/test_channel.py rename to tools/rootcanal/scripts/test_channel.py diff --git a/system/vendor_libs/test_vendor_lib/test/async_manager_unittest.cc b/tools/rootcanal/test/async_manager_unittest.cc similarity index 99% rename from system/vendor_libs/test_vendor_lib/test/async_manager_unittest.cc rename to tools/rootcanal/test/async_manager_unittest.cc index dba19abd20e..a0a33d4289a 100644 --- a/system/vendor_libs/test_vendor_lib/test/async_manager_unittest.cc +++ b/tools/rootcanal/test/async_manager_unittest.cc @@ -36,7 +36,7 @@ #include "osi/include/osi.h" // for OSI_NO_INTR -namespace test_vendor_lib { +namespace rootcanal { class Event { public: @@ -435,4 +435,4 @@ TEST_F(AsyncManagerTest, TestCancelAsyncTasksFromUser) { ASSERT_FALSE(async_manager_.CancelAsyncTask(task5_id)); } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/test/h4_parser_unittest.cc b/tools/rootcanal/test/h4_parser_unittest.cc similarity index 98% rename from system/vendor_libs/test_vendor_lib/test/h4_parser_unittest.cc rename to tools/rootcanal/test/h4_parser_unittest.cc index 316169684e1..02091176536 100644 --- a/system/vendor_libs/test_vendor_lib/test/h4_parser_unittest.cc +++ b/tools/rootcanal/test/h4_parser_unittest.cc @@ -20,7 +20,7 @@ #include "osi/include/osi.h" // for OSI_NO_INTR -namespace test_vendor_lib { +namespace rootcanal { using PacketData = std::vector<uint8_t>; class H4ParserTest : public ::testing::Test { @@ -141,4 +141,4 @@ TEST_F(H4ParserTest, CallsTheRightCallbacks) { } } -} // namespace test_vendor_lib +} // namespace rootcanal diff --git a/system/vendor_libs/test_vendor_lib/test/posix_socket_unittest.cc b/tools/rootcanal/test/posix_socket_unittest.cc similarity index 100% rename from system/vendor_libs/test_vendor_lib/test/posix_socket_unittest.cc rename to tools/rootcanal/test/posix_socket_unittest.cc diff --git a/system/vendor_libs/test_vendor_lib/test/security_manager_unittest.cc b/tools/rootcanal/test/security_manager_unittest.cc similarity index 98% rename from system/vendor_libs/test_vendor_lib/test/security_manager_unittest.cc rename to tools/rootcanal/test/security_manager_unittest.cc index 9c19c4fc238..a26d90fbb4a 100644 --- a/system/vendor_libs/test_vendor_lib/test/security_manager_unittest.cc +++ b/tools/rootcanal/test/security_manager_unittest.cc @@ -19,6 +19,7 @@ #include "model/controller/security_manager.h" #include <gtest/gtest.h> + #include <array> #include <string> @@ -32,7 +33,7 @@ const std::array<uint8_t, 16> kTestKey = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x0d, 0x0e, 0x0f, 0x10}; } // namespace -namespace test_vendor_lib { +namespace rootcanal { class SecurityManagerTest : public ::testing::Test { public: @@ -161,4 +162,4 @@ TEST_F(SecurityManagerTest, DeleteAllKeys) { EXPECT_EQ(0, sm.ReadAllKeys()); } -} // namespace test_vendor_lib +} // namespace rootcanal -- GitLab